2 * Copyright (c) 2006-2010 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.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 * The following controllers are supported by this driver:
45 * The following controllers are not supported by this driver:
46 * BCM5706C A0, A1 (pre-production)
47 * BCM5706S A0, A1 (pre-production)
48 * BCM5708C A0, B0 (pre-production)
49 * BCM5708S A0, B0 (pre-production)
50 * BCM5709C A0 B0, B1, B2 (pre-production)
51 * BCM5709S A0, B0, B1, B2 (pre-production)
56 #include <dev/bce/if_bcereg.h>
57 #include <dev/bce/if_bcefw.h>
59 /****************************************************************************/
60 /* BCE Debug Options */
61 /****************************************************************************/
63 u32 bce_debug = BCE_WARN;
66 /* 1 = 1 in 2,147,483,648 */
67 /* 256 = 1 in 8,388,608 */
68 /* 2048 = 1 in 1,048,576 */
69 /* 65536 = 1 in 32,768 */
70 /* 1048576 = 1 in 2,048 */
71 /* 268435456 = 1 in 8 */
72 /* 536870912 = 1 in 4 */
73 /* 1073741824 = 1 in 2 */
75 /* Controls how often the l2_fhdr frame error check will fail. */
76 int l2fhdr_error_sim_control = 0;
78 /* Controls how often the unexpected attention check will fail. */
79 int unexpected_attention_sim_control = 0;
81 /* Controls how often to simulate an mbuf allocation failure. */
82 int mbuf_alloc_failed_sim_control = 0;
84 /* Controls how often to simulate a DMA mapping failure. */
85 int dma_map_addr_failed_sim_control = 0;
87 /* Controls how often to simulate a bootcode failure. */
88 int bootcode_running_failure_sim_control = 0;
91 /****************************************************************************/
92 /* BCE Build Time Options */
93 /****************************************************************************/
94 /* #define BCE_NVRAM_WRITE_SUPPORT 1 */
97 /****************************************************************************/
98 /* PCI Device ID Table */
100 /* Used by bce_probe() to identify the devices supported by this driver. */
101 /****************************************************************************/
102 #define BCE_DEVDESC_MAX 64
104 static struct bce_type bce_devs[] = {
105 /* BCM5706C Controllers and OEM boards. */
106 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
107 "HP NC370T Multifunction Gigabit Server Adapter" },
108 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
109 "HP NC370i Multifunction Gigabit Server Adapter" },
110 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3070,
111 "HP NC380T PCIe DP Multifunc Gig Server Adapter" },
112 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x1709,
113 "HP NC371i Multifunction Gigabit Server Adapter" },
114 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
115 "Broadcom NetXtreme II BCM5706 1000Base-T" },
117 /* BCM5706S controllers and OEM boards. */
118 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
119 "HP NC370F Multifunction Gigabit Server Adapter" },
120 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
121 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
123 /* BCM5708C controllers and OEM boards. */
124 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7037,
125 "HP NC373T PCIe Multifunction Gig Server Adapter" },
126 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7038,
127 "HP NC373i Multifunction Gigabit Server Adapter" },
128 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7045,
129 "HP NC374m PCIe Multifunction Adapter" },
130 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
131 "Broadcom NetXtreme II BCM5708 1000Base-T" },
133 /* BCM5708S controllers and OEM boards. */
134 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x1706,
135 "HP NC373m Multifunction Gigabit Server Adapter" },
136 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703b,
137 "HP NC373i Multifunction Gigabit Server Adapter" },
138 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703d,
139 "HP NC373F PCIe Multifunc Giga Server Adapter" },
140 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
141 "Broadcom NetXtreme II BCM5708 1000Base-SX" },
143 /* BCM5709C controllers and OEM boards. */
144 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7055,
145 "HP NC382i DP Multifunction Gigabit Server Adapter" },
146 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7059,
147 "HP NC382T PCIe DP Multifunction Gigabit Server Adapter" },
148 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, PCI_ANY_ID, PCI_ANY_ID,
149 "Broadcom NetXtreme II BCM5709 1000Base-T" },
151 /* BCM5709S controllers and OEM boards. */
152 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x171d,
153 "HP NC382m DP 1GbE Multifunction BL-c Adapter" },
154 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x7056,
155 "HP NC382i DP Multifunction Gigabit Server Adapter" },
156 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, PCI_ANY_ID, PCI_ANY_ID,
157 "Broadcom NetXtreme II BCM5709 1000Base-SX" },
159 /* BCM5716 controllers and OEM boards. */
160 { BRCM_VENDORID, BRCM_DEVICEID_BCM5716, PCI_ANY_ID, PCI_ANY_ID,
161 "Broadcom NetXtreme II BCM5716 1000Base-T" },
167 /****************************************************************************/
168 /* Supported Flash NVRAM device data. */
169 /****************************************************************************/
170 static struct flash_spec flash_table[] =
172 #define BUFFERED_FLAGS (BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
173 #define NONBUFFERED_FLAGS (BCE_NV_WREN)
176 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
177 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
178 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
180 /* Expansion entry 0001 */
181 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
182 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
183 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
185 /* Saifun SA25F010 (non-buffered flash) */
186 /* strap, cfg1, & write1 need updates */
187 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
188 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
189 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
190 "Non-buffered flash (128kB)"},
191 /* Saifun SA25F020 (non-buffered flash) */
192 /* strap, cfg1, & write1 need updates */
193 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
194 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
195 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
196 "Non-buffered flash (256kB)"},
197 /* Expansion entry 0100 */
198 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
199 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
200 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
202 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
203 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
204 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
205 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
206 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
207 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
208 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
209 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
210 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
211 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
212 /* Saifun SA25F005 (non-buffered flash) */
213 /* strap, cfg1, & write1 need updates */
214 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
215 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
216 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
217 "Non-buffered flash (64kB)"},
219 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
220 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
221 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
223 /* Expansion entry 1001 */
224 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
225 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
226 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
228 /* Expansion entry 1010 */
229 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
230 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
231 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
233 /* ATMEL AT45DB011B (buffered flash) */
234 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
235 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
236 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
237 "Buffered flash (128kB)"},
238 /* Expansion entry 1100 */
239 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
240 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
241 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
243 /* Expansion entry 1101 */
244 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
245 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
246 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
248 /* Ateml Expansion entry 1110 */
249 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
250 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
251 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
252 "Entry 1110 (Atmel)"},
253 /* ATMEL AT45DB021B (buffered flash) */
254 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
255 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
256 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
257 "Buffered flash (256kB)"},
261 * The BCM5709 controllers transparently handle the
262 * differences between Atmel 264 byte pages and all
263 * flash devices which use 256 byte pages, so no
264 * logical-to-physical mapping is required in the
267 static struct flash_spec flash_5709 = {
268 .flags = BCE_NV_BUFFERED,
269 .page_bits = BCM5709_FLASH_PAGE_BITS,
270 .page_size = BCM5709_FLASH_PAGE_SIZE,
271 .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
272 .total_size = BUFFERED_FLASH_TOTAL_SIZE * 2,
273 .name = "5709/5716 buffered flash (256kB)",
277 /****************************************************************************/
278 /* FreeBSD device entry points. */
279 /****************************************************************************/
280 static int bce_probe (device_t);
281 static int bce_attach (device_t);
282 static int bce_detach (device_t);
283 static int bce_shutdown (device_t);
286 /****************************************************************************/
287 /* BCE Debug Data Structure Dump Routines */
288 /****************************************************************************/
290 static u32 bce_reg_rd (struct bce_softc *, u32);
291 static void bce_reg_wr (struct bce_softc *, u32, u32);
292 static void bce_reg_wr16 (struct bce_softc *, u32, u16);
293 static u32 bce_ctx_rd (struct bce_softc *, u32, u32);
294 static void bce_dump_enet (struct bce_softc *, struct mbuf *);
295 static void bce_dump_mbuf (struct bce_softc *, struct mbuf *);
296 static void bce_dump_tx_mbuf_chain (struct bce_softc *, u16, int);
297 static void bce_dump_rx_mbuf_chain (struct bce_softc *, u16, int);
298 #ifdef BCE_JUMBO_HDRSPLIT
299 static void bce_dump_pg_mbuf_chain (struct bce_softc *, u16, int);
301 static void bce_dump_txbd (struct bce_softc *,
302 int, struct tx_bd *);
303 static void bce_dump_rxbd (struct bce_softc *,
304 int, struct rx_bd *);
305 #ifdef BCE_JUMBO_HDRSPLIT
306 static void bce_dump_pgbd (struct bce_softc *,
307 int, struct rx_bd *);
309 static void bce_dump_l2fhdr (struct bce_softc *,
310 int, struct l2_fhdr *);
311 static void bce_dump_ctx (struct bce_softc *, u16);
312 static void bce_dump_ftqs (struct bce_softc *);
313 static void bce_dump_tx_chain (struct bce_softc *, u16, int);
314 static void bce_dump_rx_bd_chain (struct bce_softc *, u16, int);
315 #ifdef BCE_JUMBO_HDRSPLIT
316 static void bce_dump_pg_chain (struct bce_softc *, u16, int);
318 static void bce_dump_status_block (struct bce_softc *);
319 static void bce_dump_stats_block (struct bce_softc *);
320 static void bce_dump_driver_state (struct bce_softc *);
321 static void bce_dump_hw_state (struct bce_softc *);
322 static void bce_dump_mq_regs (struct bce_softc *);
323 static void bce_dump_bc_state (struct bce_softc *);
324 static void bce_dump_txp_state (struct bce_softc *, int);
325 static void bce_dump_rxp_state (struct bce_softc *, int);
326 static void bce_dump_tpat_state (struct bce_softc *, int);
327 static void bce_dump_cp_state (struct bce_softc *, int);
328 static void bce_dump_com_state (struct bce_softc *, int);
329 static void bce_dump_rv2p_state (struct bce_softc *);
330 static void bce_breakpoint (struct bce_softc *);
334 /****************************************************************************/
335 /* BCE Register/Memory Access Routines */
336 /****************************************************************************/
337 static u32 bce_reg_rd_ind (struct bce_softc *, u32);
338 static void bce_reg_wr_ind (struct bce_softc *, u32, u32);
339 static void bce_shmem_wr (struct bce_softc *, u32, u32);
340 static u32 bce_shmem_rd (struct bce_softc *, u32);
341 static void bce_ctx_wr (struct bce_softc *, u32, u32, u32);
342 static int bce_miibus_read_reg (device_t, int, int);
343 static int bce_miibus_write_reg (device_t, int, int, int);
344 static void bce_miibus_statchg (device_t);
347 /****************************************************************************/
348 /* BCE NVRAM Access Routines */
349 /****************************************************************************/
350 static int bce_acquire_nvram_lock (struct bce_softc *);
351 static int bce_release_nvram_lock (struct bce_softc *);
352 static void bce_enable_nvram_access (struct bce_softc *);
353 static void bce_disable_nvram_access (struct bce_softc *);
354 static int bce_nvram_read_dword (struct bce_softc *, u32, u8 *, u32);
355 static int bce_init_nvram (struct bce_softc *);
356 static int bce_nvram_read (struct bce_softc *, u32, u8 *, int);
357 static int bce_nvram_test (struct bce_softc *);
358 #ifdef BCE_NVRAM_WRITE_SUPPORT
359 static int bce_enable_nvram_write (struct bce_softc *);
360 static void bce_disable_nvram_write (struct bce_softc *);
361 static int bce_nvram_erase_page (struct bce_softc *, u32);
362 static int bce_nvram_write_dword (struct bce_softc *, u32, u8 *, u32);
363 static int bce_nvram_write (struct bce_softc *, u32, u8 *, int);
366 /****************************************************************************/
368 /****************************************************************************/
369 static void bce_get_media (struct bce_softc *);
370 static void bce_init_media (struct bce_softc *);
371 static void bce_dma_map_addr (void *,
372 bus_dma_segment_t *, int, int);
373 static int bce_dma_alloc (device_t);
374 static void bce_dma_free (struct bce_softc *);
375 static void bce_release_resources (struct bce_softc *);
377 /****************************************************************************/
378 /* BCE Firmware Synchronization and Load */
379 /****************************************************************************/
380 static int bce_fw_sync (struct bce_softc *, u32);
381 static void bce_load_rv2p_fw (struct bce_softc *, u32 *, u32, u32);
382 static void bce_load_cpu_fw (struct bce_softc *,
383 struct cpu_reg *, struct fw_info *);
384 static void bce_start_cpu (struct bce_softc *, struct cpu_reg *);
385 static void bce_halt_cpu (struct bce_softc *, struct cpu_reg *);
386 static void bce_start_rxp_cpu (struct bce_softc *);
387 static void bce_init_rxp_cpu (struct bce_softc *);
388 static void bce_init_txp_cpu (struct bce_softc *);
389 static void bce_init_tpat_cpu (struct bce_softc *);
390 static void bce_init_cp_cpu (struct bce_softc *);
391 static void bce_init_com_cpu (struct bce_softc *);
392 static void bce_init_cpus (struct bce_softc *);
394 static void bce_print_adapter_info (struct bce_softc *);
395 static void bce_probe_pci_caps (device_t, struct bce_softc *);
396 static void bce_stop (struct bce_softc *);
397 static int bce_reset (struct bce_softc *, u32);
398 static int bce_chipinit (struct bce_softc *);
399 static int bce_blockinit (struct bce_softc *);
401 static int bce_init_tx_chain (struct bce_softc *);
402 static void bce_free_tx_chain (struct bce_softc *);
404 static int bce_get_rx_buf (struct bce_softc *,
405 struct mbuf *, u16 *, u16 *, u32 *);
406 static int bce_init_rx_chain (struct bce_softc *);
407 static void bce_fill_rx_chain (struct bce_softc *);
408 static void bce_free_rx_chain (struct bce_softc *);
410 #ifdef BCE_JUMBO_HDRSPLIT
411 static int bce_get_pg_buf (struct bce_softc *,
412 struct mbuf *, u16 *, u16 *);
413 static int bce_init_pg_chain (struct bce_softc *);
414 static void bce_fill_pg_chain (struct bce_softc *);
415 static void bce_free_pg_chain (struct bce_softc *);
418 static struct mbuf *bce_tso_setup (struct bce_softc *,
419 struct mbuf **, u16 *);
420 static int bce_tx_encap (struct bce_softc *, struct mbuf **);
421 static void bce_start_locked (struct ifnet *);
422 static void bce_start (struct ifnet *);
423 static int bce_ioctl (struct ifnet *, u_long, caddr_t);
424 static void bce_watchdog (struct bce_softc *);
425 static int bce_ifmedia_upd (struct ifnet *);
426 static int bce_ifmedia_upd_locked (struct ifnet *);
427 static void bce_ifmedia_sts (struct ifnet *, struct ifmediareq *);
428 static void bce_init_locked (struct bce_softc *);
429 static void bce_init (void *);
430 static void bce_mgmt_init_locked (struct bce_softc *sc);
432 static int bce_init_ctx (struct bce_softc *);
433 static void bce_get_mac_addr (struct bce_softc *);
434 static void bce_set_mac_addr (struct bce_softc *);
435 static void bce_phy_intr (struct bce_softc *);
436 static inline u16 bce_get_hw_rx_cons (struct bce_softc *);
437 static void bce_rx_intr (struct bce_softc *);
438 static void bce_tx_intr (struct bce_softc *);
439 static void bce_disable_intr (struct bce_softc *);
440 static void bce_enable_intr (struct bce_softc *, int);
442 static void bce_intr (void *);
443 static void bce_set_rx_mode (struct bce_softc *);
444 static void bce_stats_update (struct bce_softc *);
445 static void bce_tick (void *);
446 static void bce_pulse (void *);
447 static void bce_add_sysctls (struct bce_softc *);
450 /****************************************************************************/
451 /* FreeBSD device dispatch table. */
452 /****************************************************************************/
453 static device_method_t bce_methods[] = {
454 /* Device interface (device_if.h) */
455 DEVMETHOD(device_probe, bce_probe),
456 DEVMETHOD(device_attach, bce_attach),
457 DEVMETHOD(device_detach, bce_detach),
458 DEVMETHOD(device_shutdown, bce_shutdown),
459 /* Supported by device interface but not used here. */
460 /* DEVMETHOD(device_identify, bce_identify), */
461 /* DEVMETHOD(device_suspend, bce_suspend), */
462 /* DEVMETHOD(device_resume, bce_resume), */
463 /* DEVMETHOD(device_quiesce, bce_quiesce), */
465 /* Bus interface (bus_if.h) */
466 DEVMETHOD(bus_print_child, bus_generic_print_child),
467 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
469 /* MII interface (miibus_if.h) */
470 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
471 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
472 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
473 /* Supported by MII interface but not used here. */
474 /* DEVMETHOD(miibus_linkchg, bce_miibus_linkchg), */
475 /* DEVMETHOD(miibus_mediainit, bce_miibus_mediainit), */
480 static driver_t bce_driver = {
483 sizeof(struct bce_softc)
486 static devclass_t bce_devclass;
488 MODULE_DEPEND(bce, pci, 1, 1, 1);
489 MODULE_DEPEND(bce, ether, 1, 1, 1);
490 MODULE_DEPEND(bce, miibus, 1, 1, 1);
492 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
493 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
496 /****************************************************************************/
497 /* Tunable device values */
498 /****************************************************************************/
499 SYSCTL_NODE(_hw, OID_AUTO, bce, CTLFLAG_RD, 0, "bce driver parameters");
501 /* Allowable values are TRUE or FALSE */
502 static int bce_tso_enable = TRUE;
503 TUNABLE_INT("hw.bce.tso_enable", &bce_tso_enable);
504 SYSCTL_UINT(_hw_bce, OID_AUTO, tso_enable, CTLFLAG_RDTUN, &bce_tso_enable, 0,
505 "TSO Enable/Disable");
507 /* Allowable values are 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
508 /* ToDo: Add MSI-X support. */
509 static int bce_msi_enable = 1;
510 TUNABLE_INT("hw.bce.msi_enable", &bce_msi_enable);
511 SYSCTL_UINT(_hw_bce, OID_AUTO, msi_enable, CTLFLAG_RDTUN, &bce_msi_enable, 0,
512 "MSI-X|MSI|INTx selector");
514 /* ToDo: Add tunable to enable/disable strict MTU handling. */
515 /* Currently allows "loose" RX MTU checking (i.e. sets the */
516 /* H/W RX MTU to the size of the largest receive buffer, or */
517 /* 2048 bytes). This will cause a UNH failure but is more */
518 /* desireable from a functional perspective. */
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 struct bce_softc *sc;
536 u16 vid = 0, did = 0, svid = 0, sdid = 0;
540 sc = device_get_softc(dev);
541 bzero(sc, sizeof(struct bce_softc));
542 sc->bce_unit = device_get_unit(dev);
545 /* Get the data for the device to be probed. */
546 vid = pci_get_vendor(dev);
547 did = pci_get_device(dev);
548 svid = pci_get_subvendor(dev);
549 sdid = pci_get_subdevice(dev);
551 DBPRINT(sc, BCE_EXTREME_LOAD,
552 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
553 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
555 /* Look through the list of known devices for a match. */
556 while(t->bce_name != NULL) {
558 if ((vid == t->bce_vid) && (did == t->bce_did) &&
559 ((svid == t->bce_svid) || (t->bce_svid == PCI_ANY_ID)) &&
560 ((sdid == t->bce_sdid) || (t->bce_sdid == PCI_ANY_ID))) {
562 descbuf = malloc(BCE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
567 /* Print out the device identity. */
568 snprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
569 t->bce_name, (((pci_read_config(dev,
570 PCIR_REVID, 4) & 0xf0) >> 4) + 'A'),
571 (pci_read_config(dev, PCIR_REVID, 4) & 0xf));
573 device_set_desc_copy(dev, descbuf);
574 free(descbuf, M_TEMP);
575 return(BUS_PROBE_DEFAULT);
584 /****************************************************************************/
585 /* PCI Capabilities Probe Function. */
587 /* Walks the PCI capabiites list for the device to find what features are */
592 /****************************************************************************/
594 bce_print_adapter_info(struct bce_softc *sc)
598 DBENTER(BCE_VERBOSE_LOAD);
601 BCE_PRINTF("ASIC (0x%08X); ", sc->bce_chipid);
602 printf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >>
603 12) + 'A', ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
607 if (sc->bce_flags & BCE_PCIE_FLAG) {
608 printf("Bus (PCIe x%d, ", sc->link_width);
609 switch (sc->link_speed) {
610 case 1: printf("2.5Gbps); "); break;
611 case 2: printf("5Gbps); "); break;
612 default: printf("Unknown link speed); ");
615 printf("Bus (PCI%s, %s, %dMHz); ",
616 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
617 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
618 "32-bit" : "64-bit"), sc->bus_speed_mhz);
621 /* Firmware version and device features. */
622 printf("B/C (%s); Flags (", sc->bce_bc_ver);
624 #ifdef BCE_JUMBO_HDRSPLIT
629 if (sc->bce_flags & BCE_USING_MSI_FLAG) {
630 if (i > 0) printf("|");
634 if (sc->bce_flags & BCE_USING_MSIX_FLAG) {
635 if (i > 0) printf("|");
636 printf("MSI-X"); i++;
639 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG) {
640 if (i > 0) printf("|");
644 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
645 if (i > 0) printf("|");
646 printf("MFW); MFW (%s)\n", sc->bce_mfw_ver);
652 DBEXIT(BCE_VERBOSE_LOAD);
656 /****************************************************************************/
657 /* PCI Capabilities Probe Function. */
659 /* Walks the PCI capabiites list for the device to find what features are */
664 /****************************************************************************/
666 bce_probe_pci_caps(device_t dev, struct bce_softc *sc)
670 DBENTER(BCE_VERBOSE_LOAD);
672 /* Check if PCI-X capability is enabled. */
673 if (pci_find_extcap(dev, PCIY_PCIX, ®) == 0) {
675 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
678 /* Check if PCIe capability is enabled. */
679 if (pci_find_extcap(dev, PCIY_EXPRESS, ®) == 0) {
681 u16 link_status = pci_read_config(dev, reg + 0x12, 2);
682 DBPRINT(sc, BCE_INFO_LOAD, "PCIe link_status = "
683 "0x%08X\n", link_status);
684 sc->link_speed = link_status & 0xf;
685 sc->link_width = (link_status >> 4) & 0x3f;
686 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
687 sc->bce_flags |= BCE_PCIE_FLAG;
691 /* Check if MSI capability is enabled. */
692 if (pci_find_extcap(dev, PCIY_MSI, ®) == 0) {
694 sc->bce_cap_flags |= BCE_MSI_CAPABLE_FLAG;
697 /* Check if MSI-X capability is enabled. */
698 if (pci_find_extcap(dev, PCIY_MSIX, ®) == 0) {
700 sc->bce_cap_flags |= BCE_MSIX_CAPABLE_FLAG;
703 DBEXIT(BCE_VERBOSE_LOAD);
707 /****************************************************************************/
708 /* Device attach function. */
710 /* Allocates device resources, performs secondary chip identification, */
711 /* resets and initializes the hardware, and initializes driver instance */
715 /* 0 on success, positive value on failure. */
716 /****************************************************************************/
718 bce_attach(device_t dev)
720 struct bce_softc *sc;
723 int error, rid, rc = 0;
725 sc = device_get_softc(dev);
728 DBENTER(BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
730 sc->bce_unit = device_get_unit(dev);
732 /* Set initial device and PHY flags */
734 sc->bce_phy_flags = 0;
736 pci_enable_busmaster(dev);
738 /* Allocate PCI memory resources. */
740 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
743 if (sc->bce_res_mem == NULL) {
744 BCE_PRINTF("%s(%d): PCI memory allocation failed\n",
747 goto bce_attach_fail;
750 /* Get various resource handles. */
751 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
752 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
753 sc->bce_vhandle = (vm_offset_t) rman_get_virtual(sc->bce_res_mem);
755 bce_probe_pci_caps(dev, sc);
759 /* Try allocating MSI-X interrupts. */
760 if ((sc->bce_cap_flags & BCE_MSIX_CAPABLE_FLAG) &&
761 (bce_msi_enable >= 2) &&
762 ((sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
763 &rid, RF_ACTIVE)) != NULL)) {
765 msi_needed = sc->bce_msi_count = 1;
767 if (((error = pci_alloc_msix(dev, &sc->bce_msi_count)) != 0) ||
768 (sc->bce_msi_count != msi_needed)) {
769 BCE_PRINTF("%s(%d): MSI-X allocation failed! Requested = %d,"
770 "Received = %d, error = %d\n", __FILE__, __LINE__,
771 msi_needed, sc->bce_msi_count, error);
772 sc->bce_msi_count = 0;
773 pci_release_msi(dev);
774 bus_release_resource(dev, SYS_RES_MEMORY, rid,
776 sc->bce_res_irq = NULL;
778 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI-X interrupt.\n",
780 sc->bce_flags |= BCE_USING_MSIX_FLAG;
781 sc->bce_intr = bce_intr;
786 /* Try allocating a MSI interrupt. */
787 if ((sc->bce_cap_flags & BCE_MSI_CAPABLE_FLAG) &&
788 (bce_msi_enable >= 1) && (sc->bce_msi_count == 0)) {
789 sc->bce_msi_count = 1;
790 if ((error = pci_alloc_msi(dev, &sc->bce_msi_count)) != 0) {
791 BCE_PRINTF("%s(%d): MSI allocation failed! "
792 "error = %d\n", __FILE__, __LINE__, error);
793 sc->bce_msi_count = 0;
794 pci_release_msi(dev);
796 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI "
797 "interrupt.\n", __FUNCTION__);
798 sc->bce_flags |= BCE_USING_MSI_FLAG;
799 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
800 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
801 sc->bce_flags |= BCE_ONE_SHOT_MSI_FLAG;
803 sc->bce_intr = bce_intr;
807 /* Try allocating a legacy interrupt. */
808 if (sc->bce_msi_count == 0) {
809 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using INTx interrupt.\n",
812 sc->bce_intr = bce_intr;
815 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
816 &rid, RF_SHAREABLE | RF_ACTIVE);
818 sc->bce_irq_rid = rid;
820 /* Report any IRQ allocation errors. */
821 if (sc->bce_res_irq == NULL) {
822 BCE_PRINTF("%s(%d): PCI map interrupt failed!\n",
825 goto bce_attach_fail;
828 /* Initialize mutex for the current device instance. */
829 BCE_LOCK_INIT(sc, device_get_nameunit(dev));
832 * Configure byte swap and enable indirect register access.
833 * Rely on CPU to do target byte swapping on big endian systems.
834 * Access to registers outside of PCI configurtion space are not
835 * valid until this is done.
837 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
838 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
839 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
841 /* Save ASIC revsion info. */
842 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
844 /* Weed out any non-production controller revisions. */
845 switch(BCE_CHIP_ID(sc)) {
846 case BCE_CHIP_ID_5706_A0:
847 case BCE_CHIP_ID_5706_A1:
848 case BCE_CHIP_ID_5708_A0:
849 case BCE_CHIP_ID_5708_B0:
850 case BCE_CHIP_ID_5709_A0:
851 case BCE_CHIP_ID_5709_B0:
852 case BCE_CHIP_ID_5709_B1:
853 case BCE_CHIP_ID_5709_B2:
854 BCE_PRINTF("%s(%d): Unsupported controller "
855 "revision (%c%d)!\n", __FILE__, __LINE__,
856 (((pci_read_config(dev, PCIR_REVID, 4) &
857 0xf0) >> 4) + 'A'), (pci_read_config(dev,
858 PCIR_REVID, 4) & 0xf));
860 goto bce_attach_fail;
864 * The embedded PCIe to PCI-X bridge (EPB)
865 * in the 5708 cannot address memory above
866 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
868 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
869 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
871 sc->max_bus_addr = BUS_SPACE_MAXADDR;
874 * Find the base address for shared memory access.
875 * Newer versions of bootcode use a signature and offset
876 * while older versions use a fixed address.
878 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
879 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
880 /* Multi-port devices use different offsets in shared memory. */
881 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0 +
882 (pci_get_function(sc->bce_dev) << 2));
884 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
886 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): bce_shmem_base = 0x%08X\n",
887 __FUNCTION__, sc->bce_shmem_base);
889 /* Fetch the bootcode revision. */
890 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
891 for (int i = 0, j = 0; i < 3; i++) {
894 num = (u8) (val >> (24 - (i * 8)));
895 for (int k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
896 if (num >= k || !skip0 || k == 1) {
897 sc->bce_bc_ver[j++] = (num / k) + '0';
903 sc->bce_bc_ver[j++] = '.';
906 /* Check if any management firwmare is enabled. */
907 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
908 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
909 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
911 /* Allow time for firmware to enter the running state. */
912 for (int i = 0; i < 30; i++) {
913 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
914 if (val & BCE_CONDITION_MFW_RUN_MASK)
919 /* Check if management firmware is running. */
920 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
921 val &= BCE_CONDITION_MFW_RUN_MASK;
922 if ((val != BCE_CONDITION_MFW_RUN_UNKNOWN) &&
923 (val != BCE_CONDITION_MFW_RUN_NONE)) {
924 u32 addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
927 /* Read the management firmware version string. */
928 for (int j = 0; j < 3; j++) {
929 val = bce_reg_rd_ind(sc, addr + j * 4);
931 memcpy(&sc->bce_mfw_ver[i], &val, 4);
935 /* May cause firmware synchronization timeouts. */
936 BCE_PRINTF("%s(%d): Management firmware enabled "
937 "but not running!\n", __FILE__, __LINE__);
938 strcpy(sc->bce_mfw_ver, "NOT RUNNING!");
940 /* ToDo: Any action the driver should take? */
944 /* Get PCI bus information (speed and type). */
945 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
946 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
949 sc->bce_flags |= BCE_PCIX_FLAG;
951 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS);
953 clkreg &= BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
955 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
956 sc->bus_speed_mhz = 133;
959 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
960 sc->bus_speed_mhz = 100;
963 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
964 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
965 sc->bus_speed_mhz = 66;
968 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
969 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
970 sc->bus_speed_mhz = 50;
973 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
974 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
975 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
976 sc->bus_speed_mhz = 33;
980 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
981 sc->bus_speed_mhz = 66;
983 sc->bus_speed_mhz = 33;
986 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
987 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
989 /* Reset controller and announce to bootcode that driver is present. */
990 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
991 BCE_PRINTF("%s(%d): Controller reset failed!\n",
994 goto bce_attach_fail;
997 /* Initialize the controller. */
998 if (bce_chipinit(sc)) {
999 BCE_PRINTF("%s(%d): Controller initialization failed!\n",
1000 __FILE__, __LINE__);
1002 goto bce_attach_fail;
1005 /* Perform NVRAM test. */
1006 if (bce_nvram_test(sc)) {
1007 BCE_PRINTF("%s(%d): NVRAM test failed!\n",
1008 __FILE__, __LINE__);
1010 goto bce_attach_fail;
1013 /* Fetch the permanent Ethernet MAC address. */
1014 bce_get_mac_addr(sc);
1017 * Trip points control how many BDs
1018 * should be ready before generating an
1019 * interrupt while ticks control how long
1020 * a BD can sit in the chain before
1021 * generating an interrupt. Set the default
1022 * values for the RX and TX chains.
1026 /* Force more frequent interrupts. */
1027 sc->bce_tx_quick_cons_trip_int = 1;
1028 sc->bce_tx_quick_cons_trip = 1;
1029 sc->bce_tx_ticks_int = 0;
1030 sc->bce_tx_ticks = 0;
1032 sc->bce_rx_quick_cons_trip_int = 1;
1033 sc->bce_rx_quick_cons_trip = 1;
1034 sc->bce_rx_ticks_int = 0;
1035 sc->bce_rx_ticks = 0;
1037 /* Improve throughput at the expense of increased latency. */
1038 sc->bce_tx_quick_cons_trip_int = 20;
1039 sc->bce_tx_quick_cons_trip = 20;
1040 sc->bce_tx_ticks_int = 80;
1041 sc->bce_tx_ticks = 80;
1043 sc->bce_rx_quick_cons_trip_int = 6;
1044 sc->bce_rx_quick_cons_trip = 6;
1045 sc->bce_rx_ticks_int = 18;
1046 sc->bce_rx_ticks = 18;
1049 /* Not used for L2. */
1050 sc->bce_comp_prod_trip_int = 0;
1051 sc->bce_comp_prod_trip = 0;
1052 sc->bce_com_ticks_int = 0;
1053 sc->bce_com_ticks = 0;
1054 sc->bce_cmd_ticks_int = 0;
1055 sc->bce_cmd_ticks = 0;
1057 /* Update statistics once every second. */
1058 sc->bce_stats_ticks = 1000000 & 0xffff00;
1060 /* Find the media type for the adapter. */
1063 /* Store data needed by PHY driver for backplane applications */
1064 sc->bce_shared_hw_cfg = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
1065 sc->bce_port_hw_cfg = bce_shmem_rd(sc, BCE_PORT_HW_CFG_CONFIG);
1067 /* Allocate DMA memory resources. */
1068 if (bce_dma_alloc(dev)) {
1069 BCE_PRINTF("%s(%d): DMA resource allocation failed!\n",
1070 __FILE__, __LINE__);
1072 goto bce_attach_fail;
1075 /* Allocate an ifnet structure. */
1076 ifp = sc->bce_ifp = if_alloc(IFT_ETHER);
1078 BCE_PRINTF("%s(%d): Interface allocation failed!\n",
1079 __FILE__, __LINE__);
1081 goto bce_attach_fail;
1084 /* Initialize the ifnet interface. */
1086 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1087 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1088 ifp->if_ioctl = bce_ioctl;
1089 ifp->if_start = bce_start;
1090 ifp->if_init = bce_init;
1091 ifp->if_mtu = ETHERMTU;
1093 if (bce_tso_enable) {
1094 ifp->if_hwassist = BCE_IF_HWASSIST | CSUM_TSO;
1095 ifp->if_capabilities = BCE_IF_CAPABILITIES | IFCAP_TSO4 |
1098 ifp->if_hwassist = BCE_IF_HWASSIST;
1099 ifp->if_capabilities = BCE_IF_CAPABILITIES;
1102 ifp->if_capenable = ifp->if_capabilities;
1105 * Assume standard mbuf sizes for buffer allocation.
1106 * This may change later if the MTU size is set to
1107 * something other than 1500.
1109 #ifdef BCE_JUMBO_HDRSPLIT
1110 sc->rx_bd_mbuf_alloc_size = MHLEN;
1111 /* Make sure offset is 16 byte aligned for hardware. */
1112 sc->rx_bd_mbuf_align_pad =
1113 roundup2((MSIZE - MHLEN), 16) - (MSIZE - MHLEN);
1114 sc->rx_bd_mbuf_data_len = sc->rx_bd_mbuf_alloc_size -
1115 sc->rx_bd_mbuf_align_pad;
1116 sc->pg_bd_mbuf_alloc_size = MCLBYTES;
1118 sc->rx_bd_mbuf_alloc_size = MCLBYTES;
1119 sc->rx_bd_mbuf_align_pad =
1120 roundup2(MCLBYTES, 16) - MCLBYTES;
1121 sc->rx_bd_mbuf_data_len = sc->rx_bd_mbuf_alloc_size -
1122 sc->rx_bd_mbuf_align_pad;
1125 ifp->if_snd.ifq_drv_maxlen = USABLE_TX_BD;
1126 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
1127 IFQ_SET_READY(&ifp->if_snd);
1129 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
1130 ifp->if_baudrate = IF_Mbps(2500ULL);
1132 ifp->if_baudrate = IF_Mbps(1000);
1134 /* Handle any special PHY initialization for SerDes PHYs. */
1137 /* MII child bus by probing the PHY. */
1138 if (mii_phy_probe(dev, &sc->bce_miibus, bce_ifmedia_upd,
1140 BCE_PRINTF("%s(%d): No PHY found on child MII bus!\n",
1141 __FILE__, __LINE__);
1143 goto bce_attach_fail;
1146 /* Attach to the Ethernet interface list. */
1147 ether_ifattach(ifp, sc->eaddr);
1149 #if __FreeBSD_version < 500000
1150 callout_init(&sc->bce_tick_callout);
1151 callout_init(&sc->bce_pulse_callout);
1153 callout_init_mtx(&sc->bce_tick_callout, &sc->bce_mtx, 0);
1154 callout_init_mtx(&sc->bce_pulse_callout, &sc->bce_mtx, 0);
1157 /* Hookup IRQ last. */
1158 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_TYPE_NET | INTR_MPSAFE,
1159 NULL, bce_intr, sc, &sc->bce_intrhand);
1162 BCE_PRINTF("%s(%d): Failed to setup IRQ!\n",
1163 __FILE__, __LINE__);
1165 goto bce_attach_exit;
1169 * At this point we've acquired all the resources
1170 * we need to run so there's no turning back, we're
1171 * cleared for launch.
1174 /* Print some important debugging info. */
1175 DBRUNMSG(BCE_INFO, bce_dump_driver_state(sc));
1177 /* Add the supported sysctls to the kernel. */
1178 bce_add_sysctls(sc);
1183 * The chip reset earlier notified the bootcode that
1184 * a driver is present. We now need to start our pulse
1185 * routine so that the bootcode is reminded that we're
1190 bce_mgmt_init_locked(sc);
1193 /* Finally, print some useful adapter info */
1194 bce_print_adapter_info(sc);
1195 DBPRINT(sc, BCE_FATAL, "%s(): sc = %p\n",
1198 goto bce_attach_exit;
1201 bce_release_resources(sc);
1205 DBEXIT(BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
1211 /****************************************************************************/
1212 /* Device detach function. */
1214 /* Stops the controller, resets the controller, and releases resources. */
1217 /* 0 on success, positive value on failure. */
1218 /****************************************************************************/
1220 bce_detach(device_t dev)
1222 struct bce_softc *sc = device_get_softc(dev);
1226 DBENTER(BCE_VERBOSE_UNLOAD | BCE_VERBOSE_RESET);
1230 /* Stop and reset the controller. */
1233 /* Stop the pulse so the bootcode can go to driver absent state. */
1234 callout_stop(&sc->bce_pulse_callout);
1237 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1238 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1240 msg = BCE_DRV_MSG_CODE_UNLOAD;
1245 ether_ifdetach(ifp);
1247 /* If we have a child device on the MII bus remove it too. */
1248 bus_generic_detach(dev);
1249 device_delete_child(dev, sc->bce_miibus);
1251 /* Release all remaining resources. */
1252 bce_release_resources(sc);
1254 DBEXIT(BCE_VERBOSE_UNLOAD | BCE_VERBOSE_RESET);
1260 /****************************************************************************/
1261 /* Device shutdown function. */
1263 /* Stops and resets the controller. */
1266 /* 0 on success, positive value on failure. */
1267 /****************************************************************************/
1269 bce_shutdown(device_t dev)
1271 struct bce_softc *sc = device_get_softc(dev);
1274 DBENTER(BCE_VERBOSE);
1278 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1279 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1281 msg = BCE_DRV_MSG_CODE_UNLOAD;
1285 DBEXIT(BCE_VERBOSE);
1292 /****************************************************************************/
1293 /* Register read. */
1296 /* The value of the register. */
1297 /****************************************************************************/
1299 bce_reg_rd(struct bce_softc *sc, u32 offset)
1301 u32 val = bus_space_read_4(sc->bce_btag, sc->bce_bhandle, offset);
1302 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1303 __FUNCTION__, offset, val);
1308 /****************************************************************************/
1309 /* Register write (16 bit). */
1313 /****************************************************************************/
1315 bce_reg_wr16(struct bce_softc *sc, u32 offset, u16 val)
1317 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%04X\n",
1318 __FUNCTION__, offset, val);
1319 bus_space_write_2(sc->bce_btag, sc->bce_bhandle, offset, val);
1323 /****************************************************************************/
1324 /* Register write. */
1328 /****************************************************************************/
1330 bce_reg_wr(struct bce_softc *sc, u32 offset, u32 val)
1332 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1333 __FUNCTION__, offset, val);
1334 bus_space_write_4(sc->bce_btag, sc->bce_bhandle, offset, val);
1338 /****************************************************************************/
1339 /* Indirect register read. */
1341 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1342 /* configuration space. Using this mechanism avoids issues with posted */
1343 /* reads but is much slower than memory-mapped I/O. */
1346 /* The value of the register. */
1347 /****************************************************************************/
1349 bce_reg_rd_ind(struct bce_softc *sc, u32 offset)
1354 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1358 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1359 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1360 __FUNCTION__, offset, val);
1364 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1369 /****************************************************************************/
1370 /* Indirect register write. */
1372 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1373 /* configuration space. Using this mechanism avoids issues with posted */
1374 /* writes but is muchh slower than memory-mapped I/O. */
1378 /****************************************************************************/
1380 bce_reg_wr_ind(struct bce_softc *sc, u32 offset, u32 val)
1385 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1386 __FUNCTION__, offset, val);
1388 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1389 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1393 /****************************************************************************/
1394 /* Shared memory write. */
1396 /* Writes NetXtreme II shared memory region. */
1400 /****************************************************************************/
1402 bce_shmem_wr(struct bce_softc *sc, u32 offset, u32 val)
1404 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): Writing 0x%08X to "
1405 "0x%08X\n", __FUNCTION__, val, offset);
1407 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1411 /****************************************************************************/
1412 /* Shared memory read. */
1414 /* Reads NetXtreme II shared memory region. */
1417 /* The 32 bit value read. */
1418 /****************************************************************************/
1420 bce_shmem_rd(struct bce_softc *sc, u32 offset)
1422 u32 val = bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1424 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): Reading 0x%08X from "
1425 "0x%08X\n", __FUNCTION__, val, offset);
1432 /****************************************************************************/
1433 /* Context memory read. */
1435 /* The NetXtreme II controller uses context memory to track connection */
1436 /* information for L2 and higher network protocols. */
1439 /* The requested 32 bit value of context memory. */
1440 /****************************************************************************/
1442 bce_ctx_rd(struct bce_softc *sc, u32 cid_addr, u32 ctx_offset)
1444 u32 idx, offset, retry_cnt = 5, val;
1446 DBRUNIF((cid_addr > MAX_CID_ADDR || ctx_offset & 0x3 ||
1447 cid_addr & CTX_MASK), BCE_PRINTF("%s(): Invalid CID "
1448 "address: 0x%08X.\n", __FUNCTION__, cid_addr));
1450 offset = ctx_offset + cid_addr;
1452 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
1453 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
1455 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_READ_REQ));
1457 for (idx = 0; idx < retry_cnt; idx++) {
1458 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1459 if ((val & BCE_CTX_CTX_CTRL_READ_REQ) == 0)
1464 if (val & BCE_CTX_CTX_CTRL_READ_REQ)
1465 BCE_PRINTF("%s(%d); Unable to read CTX memory: "
1466 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1467 __FILE__, __LINE__, cid_addr, ctx_offset);
1469 val = REG_RD(sc, BCE_CTX_CTX_DATA);
1471 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1472 val = REG_RD(sc, BCE_CTX_DATA);
1475 DBPRINT(sc, BCE_EXTREME_CTX, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
1476 "val = 0x%08X\n", __FUNCTION__, cid_addr, ctx_offset, val);
1483 /****************************************************************************/
1484 /* Context memory write. */
1486 /* The NetXtreme II controller uses context memory to track connection */
1487 /* information for L2 and higher network protocols. */
1491 /****************************************************************************/
1493 bce_ctx_wr(struct bce_softc *sc, u32 cid_addr, u32 ctx_offset, u32 ctx_val)
1495 u32 idx, offset = ctx_offset + cid_addr;
1496 u32 val, retry_cnt = 5;
1498 DBPRINT(sc, BCE_EXTREME_CTX, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
1499 "val = 0x%08X\n", __FUNCTION__, cid_addr, ctx_offset, ctx_val);
1501 DBRUNIF((cid_addr > MAX_CID_ADDR || ctx_offset & 0x3 || cid_addr & CTX_MASK),
1502 BCE_PRINTF("%s(): Invalid CID address: 0x%08X.\n",
1503 __FUNCTION__, cid_addr));
1505 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
1506 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
1508 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1509 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1511 for (idx = 0; idx < retry_cnt; idx++) {
1512 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1513 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1518 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ)
1519 BCE_PRINTF("%s(%d); Unable to write CTX memory: "
1520 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1521 __FILE__, __LINE__, cid_addr, ctx_offset);
1524 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1525 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1530 /****************************************************************************/
1531 /* PHY register read. */
1533 /* Implements register reads on the MII bus. */
1536 /* The value of the register. */
1537 /****************************************************************************/
1539 bce_miibus_read_reg(device_t dev, int phy, int reg)
1541 struct bce_softc *sc;
1545 sc = device_get_softc(dev);
1547 /* Make sure we are accessing the correct PHY address. */
1548 if (phy != sc->bce_phy_addr) {
1549 DBPRINT(sc, BCE_INSANE_PHY, "Invalid PHY address %d "
1550 "for PHY read!\n", phy);
1555 * The 5709S PHY is an IEEE Clause 45 PHY
1556 * with special mappings to work with IEEE
1557 * Clause 22 register accesses.
1559 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
1560 if (reg >= MII_BMCR && reg <= MII_ANLPRNP)
1564 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1565 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1566 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1568 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1569 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1575 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1576 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1577 BCE_EMAC_MDIO_COMM_START_BUSY;
1578 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1580 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1583 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1584 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1587 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1588 val &= BCE_EMAC_MDIO_COMM_DATA;
1594 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1595 BCE_PRINTF("%s(%d): Error: PHY read timeout! phy = %d, "
1596 "reg = 0x%04X\n", __FILE__, __LINE__, phy, reg);
1599 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1603 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1604 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1605 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1607 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1608 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1613 DB_PRINT_PHY_REG(reg, val);
1614 return (val & 0xffff);
1619 /****************************************************************************/
1620 /* PHY register write. */
1622 /* Implements register writes on the MII bus. */
1625 /* The value of the register. */
1626 /****************************************************************************/
1628 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1630 struct bce_softc *sc;
1634 sc = device_get_softc(dev);
1636 /* Make sure we are accessing the correct PHY address. */
1637 if (phy != sc->bce_phy_addr) {
1638 DBPRINT(sc, BCE_INSANE_PHY, "Invalid PHY address %d "
1639 "for PHY write!\n", phy);
1643 DB_PRINT_PHY_REG(reg, val);
1646 * The 5709S PHY is an IEEE Clause 45 PHY
1647 * with special mappings to work with IEEE
1648 * Clause 22 register accesses.
1650 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
1651 if (reg >= MII_BMCR && reg <= MII_ANLPRNP)
1655 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1656 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1657 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1659 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1660 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1665 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1666 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1667 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1668 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1670 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1673 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1674 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1680 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1681 BCE_PRINTF("%s(%d): PHY write timeout!\n",
1682 __FILE__, __LINE__);
1684 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1685 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1686 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1688 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1689 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1698 /****************************************************************************/
1699 /* MII bus status change. */
1701 /* Called by the MII bus driver when the PHY establishes link to set the */
1702 /* MAC interface registers. */
1706 /****************************************************************************/
1708 bce_miibus_statchg(device_t dev)
1710 struct bce_softc *sc;
1711 struct mii_data *mii;
1714 sc = device_get_softc(dev);
1716 DBENTER(BCE_VERBOSE_PHY);
1718 mii = device_get_softc(sc->bce_miibus);
1720 val = REG_RD(sc, BCE_EMAC_MODE);
1721 val &= ~(BCE_EMAC_MODE_PORT | BCE_EMAC_MODE_HALF_DUPLEX |
1722 BCE_EMAC_MODE_MAC_LOOP | BCE_EMAC_MODE_FORCE_LINK |
1725 /* Set MII or GMII interface based on the PHY speed. */
1726 switch (IFM_SUBTYPE(mii->mii_media_active)) {
1728 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
1729 DBPRINT(sc, BCE_INFO_PHY,
1730 "Enabling 10Mb interface.\n");
1731 val |= BCE_EMAC_MODE_PORT_MII_10;
1736 DBPRINT(sc, BCE_INFO_PHY, "Enabling MII interface.\n");
1737 val |= BCE_EMAC_MODE_PORT_MII;
1740 DBPRINT(sc, BCE_INFO_PHY, "Enabling 2.5G MAC mode.\n");
1741 val |= BCE_EMAC_MODE_25G;
1745 DBPRINT(sc, BCE_INFO_PHY, "Enabling GMII interface.\n");
1746 val |= BCE_EMAC_MODE_PORT_GMII;
1749 DBPRINT(sc, BCE_INFO_PHY, "Unknown link speed, enabling "
1750 "default GMII interface.\n");
1751 val |= BCE_EMAC_MODE_PORT_GMII;
1754 /* Set half or full duplex based on PHY settings. */
1755 if ((mii->mii_media_active & IFM_GMASK) == IFM_HDX) {
1756 DBPRINT(sc, BCE_INFO_PHY,
1757 "Setting Half-Duplex interface.\n");
1758 val |= BCE_EMAC_MODE_HALF_DUPLEX;
1760 DBPRINT(sc, BCE_INFO_PHY,
1761 "Setting Full-Duplex interface.\n");
1763 REG_WR(sc, BCE_EMAC_MODE, val);
1765 /* FLAG0 is set if RX is enabled and FLAG1 if TX is enabled */
1766 if (mii->mii_media_active & IFM_FLAG0) {
1767 DBPRINT(sc, BCE_INFO_PHY,
1768 "%s(): Enabling RX flow control.\n", __FUNCTION__);
1769 BCE_SETBIT(sc, BCE_EMAC_RX_MODE, BCE_EMAC_RX_MODE_FLOW_EN);
1771 DBPRINT(sc, BCE_INFO_PHY,
1772 "%s(): Disabling RX flow control.\n", __FUNCTION__);
1773 BCE_CLRBIT(sc, BCE_EMAC_RX_MODE, BCE_EMAC_RX_MODE_FLOW_EN);
1776 if (mii->mii_media_active & IFM_FLAG1) {
1777 DBPRINT(sc, BCE_INFO_PHY,
1778 "%s(): Enabling TX flow control.\n", __FUNCTION__);
1779 BCE_SETBIT(sc, BCE_EMAC_TX_MODE, BCE_EMAC_TX_MODE_FLOW_EN);
1780 sc->bce_flags |= BCE_USING_TX_FLOW_CONTROL;
1782 DBPRINT(sc, BCE_INFO_PHY,
1783 "%s(): Disabling TX flow control.\n", __FUNCTION__);
1784 BCE_CLRBIT(sc, BCE_EMAC_TX_MODE, BCE_EMAC_TX_MODE_FLOW_EN);
1785 sc->bce_flags &= ~BCE_USING_TX_FLOW_CONTROL;
1788 /* ToDo: Update watermarks in bce_init_rx_context(). */
1790 DBEXIT(BCE_VERBOSE_PHY);
1794 /****************************************************************************/
1795 /* Acquire NVRAM lock. */
1797 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1798 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1799 /* for use by the driver. */
1802 /* 0 on success, positive value on failure. */
1803 /****************************************************************************/
1805 bce_acquire_nvram_lock(struct bce_softc *sc)
1810 DBENTER(BCE_VERBOSE_NVRAM);
1812 /* Request access to the flash interface. */
1813 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1814 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1815 val = REG_RD(sc, BCE_NVM_SW_ARB);
1816 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1822 if (j >= NVRAM_TIMEOUT_COUNT) {
1823 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1827 DBEXIT(BCE_VERBOSE_NVRAM);
1832 /****************************************************************************/
1833 /* Release NVRAM lock. */
1835 /* When the caller is finished accessing NVRAM the lock must be released. */
1836 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1837 /* for use by the driver. */
1840 /* 0 on success, positive value on failure. */
1841 /****************************************************************************/
1843 bce_release_nvram_lock(struct bce_softc *sc)
1848 DBENTER(BCE_VERBOSE_NVRAM);
1851 * Relinquish nvram interface.
1853 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1855 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1856 val = REG_RD(sc, BCE_NVM_SW_ARB);
1857 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1863 if (j >= NVRAM_TIMEOUT_COUNT) {
1864 DBPRINT(sc, BCE_WARN, "Timeout releasing NVRAM lock!\n");
1868 DBEXIT(BCE_VERBOSE_NVRAM);
1873 #ifdef BCE_NVRAM_WRITE_SUPPORT
1874 /****************************************************************************/
1875 /* Enable NVRAM write access. */
1877 /* Before writing to NVRAM the caller must enable NVRAM writes. */
1880 /* 0 on success, positive value on failure. */
1881 /****************************************************************************/
1883 bce_enable_nvram_write(struct bce_softc *sc)
1888 DBENTER(BCE_VERBOSE_NVRAM);
1890 val = REG_RD(sc, BCE_MISC_CFG);
1891 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
1893 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
1896 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1897 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
1899 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1902 val = REG_RD(sc, BCE_NVM_COMMAND);
1903 if (val & BCE_NVM_COMMAND_DONE)
1907 if (j >= NVRAM_TIMEOUT_COUNT) {
1908 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
1913 DBENTER(BCE_VERBOSE_NVRAM);
1918 /****************************************************************************/
1919 /* Disable NVRAM write access. */
1921 /* When the caller is finished writing to NVRAM write access must be */
1926 /****************************************************************************/
1928 bce_disable_nvram_write(struct bce_softc *sc)
1932 DBENTER(BCE_VERBOSE_NVRAM);
1934 val = REG_RD(sc, BCE_MISC_CFG);
1935 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
1937 DBEXIT(BCE_VERBOSE_NVRAM);
1943 /****************************************************************************/
1944 /* Enable NVRAM access. */
1946 /* Before accessing NVRAM for read or write operations the caller must */
1947 /* enabled NVRAM access. */
1951 /****************************************************************************/
1953 bce_enable_nvram_access(struct bce_softc *sc)
1957 DBENTER(BCE_VERBOSE_NVRAM);
1959 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1960 /* Enable both bits, even on read. */
1961 REG_WR(sc, BCE_NVM_ACCESS_ENABLE, val |
1962 BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1964 DBEXIT(BCE_VERBOSE_NVRAM);
1968 /****************************************************************************/
1969 /* Disable NVRAM access. */
1971 /* When the caller is finished accessing NVRAM access must be disabled. */
1975 /****************************************************************************/
1977 bce_disable_nvram_access(struct bce_softc *sc)
1981 DBENTER(BCE_VERBOSE_NVRAM);
1983 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1985 /* Disable both bits, even after read. */
1986 REG_WR(sc, BCE_NVM_ACCESS_ENABLE, val &
1987 ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1989 DBEXIT(BCE_VERBOSE_NVRAM);
1993 #ifdef BCE_NVRAM_WRITE_SUPPORT
1994 /****************************************************************************/
1995 /* Erase NVRAM page before writing. */
1997 /* Non-buffered flash parts require that a page be erased before it is */
2001 /* 0 on success, positive value on failure. */
2002 /****************************************************************************/
2004 bce_nvram_erase_page(struct bce_softc *sc, u32 offset)
2009 DBENTER(BCE_VERBOSE_NVRAM);
2011 /* Buffered flash doesn't require an erase. */
2012 if (sc->bce_flash_info->flags & BCE_NV_BUFFERED)
2013 goto bce_nvram_erase_page_exit;
2015 /* Build an erase command. */
2016 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
2017 BCE_NVM_COMMAND_DOIT;
2020 * Clear the DONE bit separately, set the NVRAM adress to erase,
2021 * and issue the erase command.
2023 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2024 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2025 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2027 /* Wait for completion. */
2028 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2033 val = REG_RD(sc, BCE_NVM_COMMAND);
2034 if (val & BCE_NVM_COMMAND_DONE)
2038 if (j >= NVRAM_TIMEOUT_COUNT) {
2039 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
2043 bce_nvram_erase_page_exit:
2044 DBEXIT(BCE_VERBOSE_NVRAM);
2047 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2050 /****************************************************************************/
2051 /* Read a dword (32 bits) from NVRAM. */
2053 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
2054 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
2057 /* 0 on success and the 32 bit value read, positive value on failure. */
2058 /****************************************************************************/
2060 bce_nvram_read_dword(struct bce_softc *sc,
2061 u32 offset, u8 *ret_val, u32 cmd_flags)
2066 DBENTER(BCE_EXTREME_NVRAM);
2068 /* Build the command word. */
2069 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
2071 /* Calculate the offset for buffered flash if translation is used. */
2072 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
2073 offset = ((offset / sc->bce_flash_info->page_size) <<
2074 sc->bce_flash_info->page_bits) +
2075 (offset % sc->bce_flash_info->page_size);
2079 * Clear the DONE bit separately, set the address to read,
2080 * and issue the read.
2082 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2083 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2084 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2086 /* Wait for completion. */
2087 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
2092 val = REG_RD(sc, BCE_NVM_COMMAND);
2093 if (val & BCE_NVM_COMMAND_DONE) {
2094 val = REG_RD(sc, BCE_NVM_READ);
2096 val = bce_be32toh(val);
2097 memcpy(ret_val, &val, 4);
2102 /* Check for errors. */
2103 if (i >= NVRAM_TIMEOUT_COUNT) {
2104 BCE_PRINTF("%s(%d): Timeout error reading NVRAM at "
2105 "offset 0x%08X!\n", __FILE__, __LINE__, offset);
2109 DBEXIT(BCE_EXTREME_NVRAM);
2114 #ifdef BCE_NVRAM_WRITE_SUPPORT
2115 /****************************************************************************/
2116 /* Write a dword (32 bits) to NVRAM. */
2118 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
2119 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
2120 /* enabled NVRAM write access. */
2123 /* 0 on success, positive value on failure. */
2124 /****************************************************************************/
2126 bce_nvram_write_dword(struct bce_softc *sc, u32 offset, u8 *val,
2132 DBENTER(BCE_VERBOSE_NVRAM);
2134 /* Build the command word. */
2135 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
2137 /* Calculate the offset for buffered flash if translation is used. */
2138 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
2139 offset = ((offset / sc->bce_flash_info->page_size) <<
2140 sc->bce_flash_info->page_bits) +
2141 (offset % sc->bce_flash_info->page_size);
2145 * Clear the DONE bit separately, convert NVRAM data to big-endian,
2146 * set the NVRAM address to write, and issue the write command
2148 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2149 memcpy(&val32, val, 4);
2150 val32 = htobe32(val32);
2151 REG_WR(sc, BCE_NVM_WRITE, val32);
2152 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2153 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2155 /* Wait for completion. */
2156 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2159 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
2162 if (j >= NVRAM_TIMEOUT_COUNT) {
2163 BCE_PRINTF("%s(%d): Timeout error writing NVRAM at "
2164 "offset 0x%08X\n", __FILE__, __LINE__, offset);
2168 DBEXIT(BCE_VERBOSE_NVRAM);
2171 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2174 /****************************************************************************/
2175 /* Initialize NVRAM access. */
2177 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
2178 /* access that device. */
2181 /* 0 on success, positive value on failure. */
2182 /****************************************************************************/
2184 bce_init_nvram(struct bce_softc *sc)
2187 int j, entry_count, rc = 0;
2188 struct flash_spec *flash;
2190 DBENTER(BCE_VERBOSE_NVRAM);
2192 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
2193 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
2194 sc->bce_flash_info = &flash_5709;
2195 goto bce_init_nvram_get_flash_size;
2198 /* Determine the selected interface. */
2199 val = REG_RD(sc, BCE_NVM_CFG1);
2201 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
2204 * Flash reconfiguration is required to support additional
2205 * NVRAM devices not directly supported in hardware.
2206 * Check if the flash interface was reconfigured
2210 if (val & 0x40000000) {
2211 /* Flash interface reconfigured by bootcode. */
2213 DBPRINT(sc,BCE_INFO_LOAD,
2214 "bce_init_nvram(): Flash WAS reconfigured.\n");
2216 for (j = 0, flash = &flash_table[0]; j < entry_count;
2218 if ((val & FLASH_BACKUP_STRAP_MASK) ==
2219 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
2220 sc->bce_flash_info = flash;
2225 /* Flash interface not yet reconfigured. */
2228 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Flash was NOT reconfigured.\n",
2231 if (val & (1 << 23))
2232 mask = FLASH_BACKUP_STRAP_MASK;
2234 mask = FLASH_STRAP_MASK;
2236 /* Look for the matching NVRAM device configuration data. */
2237 for (j = 0, flash = &flash_table[0]; j < entry_count; j++, flash++) {
2239 /* Check if the device matches any of the known devices. */
2240 if ((val & mask) == (flash->strapping & mask)) {
2241 /* Found a device match. */
2242 sc->bce_flash_info = flash;
2244 /* Request access to the flash interface. */
2245 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2248 /* Reconfigure the flash interface. */
2249 bce_enable_nvram_access(sc);
2250 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
2251 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
2252 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
2253 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
2254 bce_disable_nvram_access(sc);
2255 bce_release_nvram_lock(sc);
2262 /* Check if a matching device was found. */
2263 if (j == entry_count) {
2264 sc->bce_flash_info = NULL;
2265 BCE_PRINTF("%s(%d): Unknown Flash NVRAM found!\n",
2266 __FILE__, __LINE__);
2267 DBEXIT(BCE_VERBOSE_NVRAM);
2271 bce_init_nvram_get_flash_size:
2272 /* Write the flash config data to the shared memory interface. */
2273 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2);
2274 val &= BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
2276 sc->bce_flash_size = val;
2278 sc->bce_flash_size = sc->bce_flash_info->total_size;
2280 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Found %s, size = 0x%08X\n",
2281 __FUNCTION__, sc->bce_flash_info->name,
2282 sc->bce_flash_info->total_size);
2284 DBEXIT(BCE_VERBOSE_NVRAM);
2289 /****************************************************************************/
2290 /* Read an arbitrary range of data from NVRAM. */
2292 /* Prepares the NVRAM interface for access and reads the requested data */
2293 /* into the supplied buffer. */
2296 /* 0 on success and the data read, positive value on failure. */
2297 /****************************************************************************/
2299 bce_nvram_read(struct bce_softc *sc, u32 offset, u8 *ret_buf,
2303 u32 cmd_flags, offset32, len32, extra;
2305 DBENTER(BCE_VERBOSE_NVRAM);
2308 goto bce_nvram_read_exit;
2310 /* Request access to the flash interface. */
2311 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2312 goto bce_nvram_read_exit;
2314 /* Enable access to flash interface */
2315 bce_enable_nvram_access(sc);
2328 pre_len = 4 - (offset & 3);
2330 if (pre_len >= len32) {
2332 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
2335 cmd_flags = BCE_NVM_COMMAND_FIRST;
2338 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2343 memcpy(ret_buf, buf + (offset & 3), pre_len);
2351 extra = 4 - (len32 & 3);
2352 len32 = (len32 + 4) & ~3;
2359 cmd_flags = BCE_NVM_COMMAND_LAST;
2361 cmd_flags = BCE_NVM_COMMAND_FIRST |
2362 BCE_NVM_COMMAND_LAST;
2364 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2366 memcpy(ret_buf, buf, 4 - extra);
2368 else if (len32 > 0) {
2371 /* Read the first word. */
2375 cmd_flags = BCE_NVM_COMMAND_FIRST;
2377 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
2379 /* Advance to the next dword. */
2384 while (len32 > 4 && rc == 0) {
2385 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
2387 /* Advance to the next dword. */
2394 goto bce_nvram_read_locked_exit;
2396 cmd_flags = BCE_NVM_COMMAND_LAST;
2397 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2399 memcpy(ret_buf, buf, 4 - extra);
2402 bce_nvram_read_locked_exit:
2403 /* Disable access to flash interface and release the lock. */
2404 bce_disable_nvram_access(sc);
2405 bce_release_nvram_lock(sc);
2407 bce_nvram_read_exit:
2408 DBEXIT(BCE_VERBOSE_NVRAM);
2413 #ifdef BCE_NVRAM_WRITE_SUPPORT
2414 /****************************************************************************/
2415 /* Write an arbitrary range of data from NVRAM. */
2417 /* Prepares the NVRAM interface for write access and writes the requested */
2418 /* data from the supplied buffer. The caller is responsible for */
2419 /* calculating any appropriate CRCs. */
2422 /* 0 on success, positive value on failure. */
2423 /****************************************************************************/
2425 bce_nvram_write(struct bce_softc *sc, u32 offset, u8 *data_buf,
2428 u32 written, offset32, len32;
2429 u8 *buf, start[4], end[4];
2431 int align_start, align_end;
2433 DBENTER(BCE_VERBOSE_NVRAM);
2438 align_start = align_end = 0;
2440 if ((align_start = (offset32 & 3))) {
2442 len32 += align_start;
2443 if ((rc = bce_nvram_read(sc, offset32, start, 4)))
2444 goto bce_nvram_write_exit;
2448 if ((len32 > 4) || !align_start) {
2449 align_end = 4 - (len32 & 3);
2451 if ((rc = bce_nvram_read(sc, offset32 + len32 - 4,
2453 goto bce_nvram_write_exit;
2458 if (align_start || align_end) {
2459 buf = malloc(len32, M_DEVBUF, M_NOWAIT);
2462 goto bce_nvram_write_exit;
2466 memcpy(buf, start, 4);
2470 memcpy(buf + len32 - 4, end, 4);
2472 memcpy(buf + align_start, data_buf, buf_size);
2476 while ((written < len32) && (rc == 0)) {
2477 u32 page_start, page_end, data_start, data_end;
2478 u32 addr, cmd_flags;
2480 u8 flash_buffer[264];
2482 /* Find the page_start addr */
2483 page_start = offset32 + written;
2484 page_start -= (page_start % sc->bce_flash_info->page_size);
2485 /* Find the page_end addr */
2486 page_end = page_start + sc->bce_flash_info->page_size;
2487 /* Find the data_start addr */
2488 data_start = (written == 0) ? offset32 : page_start;
2489 /* Find the data_end addr */
2490 data_end = (page_end > offset32 + len32) ?
2491 (offset32 + len32) : page_end;
2493 /* Request access to the flash interface. */
2494 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2495 goto bce_nvram_write_exit;
2497 /* Enable access to flash interface */
2498 bce_enable_nvram_access(sc);
2500 cmd_flags = BCE_NVM_COMMAND_FIRST;
2501 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2504 /* Read the whole page into the buffer
2505 * (non-buffer flash only) */
2506 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
2507 if (j == (sc->bce_flash_info->page_size - 4)) {
2508 cmd_flags |= BCE_NVM_COMMAND_LAST;
2510 rc = bce_nvram_read_dword(sc,
2516 goto bce_nvram_write_locked_exit;
2522 /* Enable writes to flash interface (unlock write-protect) */
2523 if ((rc = bce_enable_nvram_write(sc)) != 0)
2524 goto bce_nvram_write_locked_exit;
2526 /* Erase the page */
2527 if ((rc = bce_nvram_erase_page(sc, page_start)) != 0)
2528 goto bce_nvram_write_locked_exit;
2530 /* Re-enable the write again for the actual write */
2531 bce_enable_nvram_write(sc);
2533 /* Loop to write back the buffer data from page_start to
2536 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2537 for (addr = page_start; addr < data_start;
2538 addr += 4, i += 4) {
2540 rc = bce_nvram_write_dword(sc, addr,
2541 &flash_buffer[i], cmd_flags);
2544 goto bce_nvram_write_locked_exit;
2550 /* Loop to write the new data from data_start to data_end */
2551 for (addr = data_start; addr < data_end; addr += 4, i++) {
2552 if ((addr == page_end - 4) ||
2553 ((sc->bce_flash_info->flags & BCE_NV_BUFFERED) &&
2554 (addr == data_end - 4))) {
2556 cmd_flags |= BCE_NVM_COMMAND_LAST;
2558 rc = bce_nvram_write_dword(sc, addr, buf,
2562 goto bce_nvram_write_locked_exit;
2568 /* Loop to write back the buffer data from data_end
2570 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2571 for (addr = data_end; addr < page_end;
2572 addr += 4, i += 4) {
2574 if (addr == page_end-4) {
2575 cmd_flags = BCE_NVM_COMMAND_LAST;
2577 rc = bce_nvram_write_dword(sc, addr,
2578 &flash_buffer[i], cmd_flags);
2581 goto bce_nvram_write_locked_exit;
2587 /* Disable writes to flash interface (lock write-protect) */
2588 bce_disable_nvram_write(sc);
2590 /* Disable access to flash interface */
2591 bce_disable_nvram_access(sc);
2592 bce_release_nvram_lock(sc);
2594 /* Increment written */
2595 written += data_end - data_start;
2598 goto bce_nvram_write_exit;
2600 bce_nvram_write_locked_exit:
2601 bce_disable_nvram_write(sc);
2602 bce_disable_nvram_access(sc);
2603 bce_release_nvram_lock(sc);
2605 bce_nvram_write_exit:
2606 if (align_start || align_end)
2607 free(buf, M_DEVBUF);
2609 DBEXIT(BCE_VERBOSE_NVRAM);
2612 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2615 /****************************************************************************/
2616 /* Verifies that NVRAM is accessible and contains valid data. */
2618 /* Reads the configuration data from NVRAM and verifies that the CRC is */
2622 /* 0 on success, positive value on failure. */
2623 /****************************************************************************/
2625 bce_nvram_test(struct bce_softc *sc)
2627 u32 buf[BCE_NVRAM_SIZE / 4];
2628 u8 *data = (u8 *) buf;
2632 DBENTER(BCE_VERBOSE_NVRAM | BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
2635 * Check that the device NVRAM is valid by reading
2636 * the magic value at offset 0.
2638 if ((rc = bce_nvram_read(sc, 0, data, 4)) != 0) {
2639 BCE_PRINTF("%s(%d): Unable to read NVRAM!\n",
2640 __FILE__, __LINE__);
2641 goto bce_nvram_test_exit;
2645 * Verify that offset 0 of the NVRAM contains
2646 * a valid magic number.
2648 magic = bce_be32toh(buf[0]);
2649 if (magic != BCE_NVRAM_MAGIC) {
2651 BCE_PRINTF("%s(%d): Invalid NVRAM magic value! "
2652 "Expected: 0x%08X, Found: 0x%08X\n",
2653 __FILE__, __LINE__, BCE_NVRAM_MAGIC, magic);
2654 goto bce_nvram_test_exit;
2658 * Verify that the device NVRAM includes valid
2659 * configuration data.
2661 if ((rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE)) != 0) {
2662 BCE_PRINTF("%s(%d): Unable to read manufacturing "
2663 "Information from NVRAM!\n", __FILE__, __LINE__);
2664 goto bce_nvram_test_exit;
2667 csum = ether_crc32_le(data, 0x100);
2668 if (csum != BCE_CRC32_RESIDUAL) {
2670 BCE_PRINTF("%s(%d): Invalid manufacturing information "
2671 "NVRAM CRC! Expected: 0x%08X, Found: 0x%08X\n",
2672 __FILE__, __LINE__, BCE_CRC32_RESIDUAL, csum);
2673 goto bce_nvram_test_exit;
2676 csum = ether_crc32_le(data + 0x100, 0x100);
2677 if (csum != BCE_CRC32_RESIDUAL) {
2679 BCE_PRINTF("%s(%d): Invalid feature configuration "
2680 "information NVRAM CRC! Expected: 0x%08X, "
2681 "Found: 08%08X\n", __FILE__, __LINE__,
2682 BCE_CRC32_RESIDUAL, csum);
2685 bce_nvram_test_exit:
2686 DBEXIT(BCE_VERBOSE_NVRAM | BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
2691 /****************************************************************************/
2692 /* Identifies the current media type of the controller and sets the PHY */
2697 /****************************************************************************/
2699 bce_get_media(struct bce_softc *sc)
2703 DBENTER(BCE_VERBOSE_PHY);
2705 /* Assume PHY address for copper controllers. */
2706 sc->bce_phy_addr = 1;
2708 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
2709 u32 val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
2710 u32 bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
2714 * The BCM5709S is software configurable
2715 * for Copper or SerDes operation.
2717 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
2718 DBPRINT(sc, BCE_INFO_LOAD, "5709 bonded "
2720 goto bce_get_media_exit;
2721 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
2722 DBPRINT(sc, BCE_INFO_LOAD, "5709 bonded "
2723 "for dual media.\n");
2724 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2725 goto bce_get_media_exit;
2728 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
2730 BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
2733 BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
2735 if (pci_get_function(sc->bce_dev) == 0) {
2740 DBPRINT(sc, BCE_INFO_LOAD,
2741 "BCM5709 s/w configured for SerDes.\n");
2742 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2745 DBPRINT(sc, BCE_INFO_LOAD,
2746 "BCM5709 s/w configured for Copper.\n");
2754 DBPRINT(sc, BCE_INFO_LOAD,
2755 "BCM5709 s/w configured for SerDes.\n");
2756 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2759 DBPRINT(sc, BCE_INFO_LOAD,
2760 "BCM5709 s/w configured for Copper.\n");
2765 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT)
2766 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2768 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
2770 sc->bce_flags |= BCE_NO_WOL_FLAG;
2772 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
2773 sc->bce_phy_flags |= BCE_PHY_IEEE_CLAUSE_45_FLAG;
2775 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
2776 /* 5708S/09S/16S use a separate PHY for SerDes. */
2777 sc->bce_phy_addr = 2;
2779 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
2780 if (val & BCE_SHARED_HW_CFG_PHY_2_5G) {
2781 sc->bce_phy_flags |=
2782 BCE_PHY_2_5G_CAPABLE_FLAG;
2783 DBPRINT(sc, BCE_INFO_LOAD, "Found 2.5Gb "
2784 "capable adapter\n");
2787 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
2788 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708))
2789 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
2792 DBPRINT(sc, (BCE_INFO_LOAD | BCE_INFO_PHY),
2793 "Using PHY address %d.\n", sc->bce_phy_addr);
2795 DBEXIT(BCE_VERBOSE_PHY);
2799 /****************************************************************************/
2800 /* Performs PHY initialization required before MII drivers access the */
2805 /****************************************************************************/
2807 bce_init_media(struct bce_softc *sc)
2809 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
2811 * Configure 5709S/5716S PHYs to use traditional IEEE
2812 * Clause 22 method. Otherwise we have no way to attach
2813 * the PHY in mii(4) layer. PHY specific configuration
2814 * is done in mii layer.
2817 /* Select auto-negotiation MMD of the PHY. */
2818 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
2819 BRGPHY_BLOCK_ADDR, BRGPHY_BLOCK_ADDR_ADDR_EXT);
2820 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
2821 BRGPHY_ADDR_EXT, BRGPHY_ADDR_EXT_AN_MMD);
2823 /* Set IEEE0 block of AN MMD (assumed in brgphy(4) code). */
2824 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
2825 BRGPHY_BLOCK_ADDR, BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
2830 /****************************************************************************/
2831 /* Free any DMA memory owned by the driver. */
2833 /* Scans through each data structre that requires DMA memory and frees */
2834 /* the memory if allocated. */
2838 /****************************************************************************/
2840 bce_dma_free(struct bce_softc *sc)
2844 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_UNLOAD | BCE_VERBOSE_CTX);
2846 /* Free, unmap, and destroy the status block. */
2847 if (sc->status_block != NULL) {
2852 sc->status_block = NULL;
2855 if (sc->status_map != NULL) {
2859 bus_dmamap_destroy(sc->status_tag,
2861 sc->status_map = NULL;
2864 if (sc->status_tag != NULL) {
2865 bus_dma_tag_destroy(sc->status_tag);
2866 sc->status_tag = NULL;
2870 /* Free, unmap, and destroy the statistics block. */
2871 if (sc->stats_block != NULL) {
2876 sc->stats_block = NULL;
2879 if (sc->stats_map != NULL) {
2883 bus_dmamap_destroy(sc->stats_tag,
2885 sc->stats_map = NULL;
2888 if (sc->stats_tag != NULL) {
2889 bus_dma_tag_destroy(sc->stats_tag);
2890 sc->stats_tag = NULL;
2894 /* Free, unmap and destroy all context memory pages. */
2895 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
2896 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
2897 for (i = 0; i < sc->ctx_pages; i++ ) {
2898 if (sc->ctx_block[i] != NULL) {
2903 sc->ctx_block[i] = NULL;
2906 if (sc->ctx_map[i] != NULL) {
2913 sc->ctx_map[i] = NULL;
2917 /* Destroy the context memory tag. */
2918 if (sc->ctx_tag != NULL) {
2919 bus_dma_tag_destroy(sc->ctx_tag);
2925 /* Free, unmap and destroy all TX buffer descriptor chain pages. */
2926 for (i = 0; i < TX_PAGES; i++ ) {
2927 if (sc->tx_bd_chain[i] != NULL) {
2929 sc->tx_bd_chain_tag,
2931 sc->tx_bd_chain_map[i]);
2932 sc->tx_bd_chain[i] = NULL;
2935 if (sc->tx_bd_chain_map[i] != NULL) {
2937 sc->tx_bd_chain_tag,
2938 sc->tx_bd_chain_map[i]);
2940 sc->tx_bd_chain_tag,
2941 sc->tx_bd_chain_map[i]);
2942 sc->tx_bd_chain_map[i] = NULL;
2946 /* Destroy the TX buffer descriptor tag. */
2947 if (sc->tx_bd_chain_tag != NULL) {
2948 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2949 sc->tx_bd_chain_tag = NULL;
2953 /* Free, unmap and destroy all RX buffer descriptor chain pages. */
2954 for (i = 0; i < RX_PAGES; i++ ) {
2955 if (sc->rx_bd_chain[i] != NULL) {
2957 sc->rx_bd_chain_tag,
2959 sc->rx_bd_chain_map[i]);
2960 sc->rx_bd_chain[i] = NULL;
2963 if (sc->rx_bd_chain_map[i] != NULL) {
2965 sc->rx_bd_chain_tag,
2966 sc->rx_bd_chain_map[i]);
2968 sc->rx_bd_chain_tag,
2969 sc->rx_bd_chain_map[i]);
2970 sc->rx_bd_chain_map[i] = NULL;
2974 /* Destroy the RX buffer descriptor tag. */
2975 if (sc->rx_bd_chain_tag != NULL) {
2976 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2977 sc->rx_bd_chain_tag = NULL;
2981 #ifdef BCE_JUMBO_HDRSPLIT
2982 /* Free, unmap and destroy all page buffer descriptor chain pages. */
2983 for (i = 0; i < PG_PAGES; i++ ) {
2984 if (sc->pg_bd_chain[i] != NULL) {
2986 sc->pg_bd_chain_tag,
2988 sc->pg_bd_chain_map[i]);
2989 sc->pg_bd_chain[i] = NULL;
2992 if (sc->pg_bd_chain_map[i] != NULL) {
2994 sc->pg_bd_chain_tag,
2995 sc->pg_bd_chain_map[i]);
2997 sc->pg_bd_chain_tag,
2998 sc->pg_bd_chain_map[i]);
2999 sc->pg_bd_chain_map[i] = NULL;
3003 /* Destroy the page buffer descriptor tag. */
3004 if (sc->pg_bd_chain_tag != NULL) {
3005 bus_dma_tag_destroy(sc->pg_bd_chain_tag);
3006 sc->pg_bd_chain_tag = NULL;
3011 /* Unload and destroy the TX mbuf maps. */
3012 for (i = 0; i < TOTAL_TX_BD; i++) {
3013 if (sc->tx_mbuf_map[i] != NULL) {
3014 bus_dmamap_unload(sc->tx_mbuf_tag,
3015 sc->tx_mbuf_map[i]);
3016 bus_dmamap_destroy(sc->tx_mbuf_tag,
3017 sc->tx_mbuf_map[i]);
3018 sc->tx_mbuf_map[i] = NULL;
3022 /* Destroy the TX mbuf tag. */
3023 if (sc->tx_mbuf_tag != NULL) {
3024 bus_dma_tag_destroy(sc->tx_mbuf_tag);
3025 sc->tx_mbuf_tag = NULL;
3028 /* Unload and destroy the RX mbuf maps. */
3029 for (i = 0; i < TOTAL_RX_BD; i++) {
3030 if (sc->rx_mbuf_map[i] != NULL) {
3031 bus_dmamap_unload(sc->rx_mbuf_tag,
3032 sc->rx_mbuf_map[i]);
3033 bus_dmamap_destroy(sc->rx_mbuf_tag,
3034 sc->rx_mbuf_map[i]);
3035 sc->rx_mbuf_map[i] = NULL;
3039 /* Destroy the RX mbuf tag. */
3040 if (sc->rx_mbuf_tag != NULL) {
3041 bus_dma_tag_destroy(sc->rx_mbuf_tag);
3042 sc->rx_mbuf_tag = NULL;
3045 #ifdef BCE_JUMBO_HDRSPLIT
3046 /* Unload and destroy the page mbuf maps. */
3047 for (i = 0; i < TOTAL_PG_BD; i++) {
3048 if (sc->pg_mbuf_map[i] != NULL) {
3049 bus_dmamap_unload(sc->pg_mbuf_tag,
3050 sc->pg_mbuf_map[i]);
3051 bus_dmamap_destroy(sc->pg_mbuf_tag,
3052 sc->pg_mbuf_map[i]);
3053 sc->pg_mbuf_map[i] = NULL;
3057 /* Destroy the page mbuf tag. */
3058 if (sc->pg_mbuf_tag != NULL) {
3059 bus_dma_tag_destroy(sc->pg_mbuf_tag);
3060 sc->pg_mbuf_tag = NULL;
3064 /* Destroy the parent tag */
3065 if (sc->parent_tag != NULL) {
3066 bus_dma_tag_destroy(sc->parent_tag);
3067 sc->parent_tag = NULL;
3070 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_UNLOAD | BCE_VERBOSE_CTX);
3074 /****************************************************************************/
3075 /* Get DMA memory from the OS. */
3077 /* Validates that the OS has provided DMA buffers in response to a */
3078 /* bus_dmamap_load() call and saves the physical address of those buffers. */
3079 /* When the callback is used the OS will return 0 for the mapping function */
3080 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
3081 /* failures back to the caller. */
3085 /****************************************************************************/
3087 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
3089 bus_addr_t *busaddr = arg;
3091 /* Simulate a mapping failure. */
3092 DBRUNIF(DB_RANDOMTRUE(dma_map_addr_failed_sim_control),
3095 /* ToDo: How to increment debug sim_count variable here? */
3097 /* Check for an error and signal the caller that an error occurred. */
3101 *busaddr = segs->ds_addr;
3108 /****************************************************************************/
3109 /* Allocate any DMA memory needed by the driver. */
3111 /* Allocates DMA memory needed for the various global structures needed by */
3114 /* Memory alignment requirements: */
3115 /* +-----------------+----------+----------+----------+----------+ */
3116 /* | | 5706 | 5708 | 5709 | 5716 | */
3117 /* +-----------------+----------+----------+----------+----------+ */
3118 /* |Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
3119 /* |Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
3120 /* |RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
3121 /* |PG Buffers | none | none | none | none | */
3122 /* |TX Buffers | none | none | none | none | */
3123 /* |Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
3124 /* |Context Memory | | | | | */
3125 /* +-----------------+----------+----------+----------+----------+ */
3127 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
3130 /* 0 for success, positive value for failure. */
3131 /****************************************************************************/
3133 bce_dma_alloc(device_t dev)
3135 struct bce_softc *sc;
3136 int i, error, rc = 0;
3137 bus_size_t max_size, max_seg_size;
3140 sc = device_get_softc(dev);
3142 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
3145 * Allocate the parent bus DMA tag appropriate for PCI.
3147 if (bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
3148 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3149 MAXBSIZE, BUS_SPACE_UNRESTRICTED, BUS_SPACE_MAXSIZE_32BIT,
3150 0, NULL, NULL, &sc->parent_tag)) {
3151 BCE_PRINTF("%s(%d): Could not allocate parent DMA tag!\n",
3152 __FILE__, __LINE__);
3154 goto bce_dma_alloc_exit;
3158 * Create a DMA tag for the status block, allocate and clear the
3159 * memory, map the memory into DMA space, and fetch the physical
3160 * address of the block.
3162 if (bus_dma_tag_create(sc->parent_tag, BCE_DMA_ALIGN,
3163 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3164 NULL, NULL, BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
3165 0, NULL, NULL, &sc->status_tag)) {
3166 BCE_PRINTF("%s(%d): Could not allocate status block "
3167 "DMA tag!\n", __FILE__, __LINE__);
3169 goto bce_dma_alloc_exit;
3172 if(bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
3173 BUS_DMA_NOWAIT, &sc->status_map)) {
3174 BCE_PRINTF("%s(%d): Could not allocate status block "
3175 "DMA memory!\n", __FILE__, __LINE__);
3177 goto bce_dma_alloc_exit;
3180 bzero((char *)sc->status_block, BCE_STATUS_BLK_SZ);
3182 error = bus_dmamap_load(sc->status_tag, sc->status_map,
3183 sc->status_block, BCE_STATUS_BLK_SZ, bce_dma_map_addr,
3184 &sc->status_block_paddr, BUS_DMA_NOWAIT);
3187 BCE_PRINTF("%s(%d): Could not map status block "
3188 "DMA memory!\n", __FILE__, __LINE__);
3190 goto bce_dma_alloc_exit;
3193 DBPRINT(sc, BCE_INFO_LOAD, "%s(): status_block_paddr = 0x%jX\n",
3194 __FUNCTION__, (uintmax_t) sc->status_block_paddr);
3197 * Create a DMA tag for the statistics block, allocate and clear the
3198 * memory, map the memory into DMA space, and fetch the physical
3199 * address of the block.
3201 if (bus_dma_tag_create(sc->parent_tag, BCE_DMA_ALIGN,
3202 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3203 NULL, NULL, BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
3204 0, NULL, NULL, &sc->stats_tag)) {
3205 BCE_PRINTF("%s(%d): Could not allocate statistics block "
3206 "DMA tag!\n", __FILE__, __LINE__);
3208 goto bce_dma_alloc_exit;
3211 if (bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
3212 BUS_DMA_NOWAIT, &sc->stats_map)) {
3213 BCE_PRINTF("%s(%d): Could not allocate statistics block "
3214 "DMA memory!\n", __FILE__, __LINE__);
3216 goto bce_dma_alloc_exit;
3219 bzero((char *)sc->stats_block, BCE_STATS_BLK_SZ);
3221 error = bus_dmamap_load(sc->stats_tag, sc->stats_map,
3222 sc->stats_block, BCE_STATS_BLK_SZ, bce_dma_map_addr,
3223 &sc->stats_block_paddr, BUS_DMA_NOWAIT);
3226 BCE_PRINTF("%s(%d): Could not map statistics block "
3227 "DMA memory!\n", __FILE__, __LINE__);
3229 goto bce_dma_alloc_exit;
3232 DBPRINT(sc, BCE_INFO_LOAD, "%s(): stats_block_paddr = 0x%jX\n",
3233 __FUNCTION__, (uintmax_t) sc->stats_block_paddr);
3235 /* BCM5709 uses host memory as cache for context memory. */
3236 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
3237 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
3238 sc->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
3239 if (sc->ctx_pages == 0)
3242 DBRUNIF((sc->ctx_pages > 512),
3243 BCE_PRINTF("%s(%d): Too many CTX pages! %d > 512\n",
3244 __FILE__, __LINE__, sc->ctx_pages));
3247 * Create a DMA tag for the context pages,
3248 * allocate and clear the memory, map the
3249 * memory into DMA space, and fetch the
3250 * physical address of the block.
3252 if(bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3253 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3254 NULL, NULL, BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
3255 0, NULL, NULL, &sc->ctx_tag)) {
3256 BCE_PRINTF("%s(%d): Could not allocate CTX "
3257 "DMA tag!\n", __FILE__, __LINE__);
3259 goto bce_dma_alloc_exit;
3262 for (i = 0; i < sc->ctx_pages; i++) {
3264 if(bus_dmamem_alloc(sc->ctx_tag,
3265 (void **)&sc->ctx_block[i],
3268 BCE_PRINTF("%s(%d): Could not allocate CTX "
3269 "DMA memory!\n", __FILE__, __LINE__);
3271 goto bce_dma_alloc_exit;
3274 bzero((char *)sc->ctx_block[i], BCM_PAGE_SIZE);
3276 error = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
3277 sc->ctx_block[i], BCM_PAGE_SIZE, bce_dma_map_addr,
3278 &sc->ctx_paddr[i], BUS_DMA_NOWAIT);
3281 BCE_PRINTF("%s(%d): Could not map CTX "
3282 "DMA memory!\n", __FILE__, __LINE__);
3284 goto bce_dma_alloc_exit;
3287 DBPRINT(sc, BCE_INFO_LOAD, "%s(): ctx_paddr[%d] "
3288 "= 0x%jX\n", __FUNCTION__, i,
3289 (uintmax_t) sc->ctx_paddr[i]);
3294 * Create a DMA tag for the TX buffer descriptor chain,
3295 * allocate and clear the memory, and fetch the
3296 * physical address of the block.
3298 if(bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
3299 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3300 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ, 0,
3301 NULL, NULL, &sc->tx_bd_chain_tag)) {
3302 BCE_PRINTF("%s(%d): Could not allocate TX descriptor "
3303 "chain DMA tag!\n", __FILE__, __LINE__);
3305 goto bce_dma_alloc_exit;
3308 for (i = 0; i < TX_PAGES; i++) {
3310 if(bus_dmamem_alloc(sc->tx_bd_chain_tag,
3311 (void **)&sc->tx_bd_chain[i], BUS_DMA_NOWAIT,
3312 &sc->tx_bd_chain_map[i])) {
3313 BCE_PRINTF("%s(%d): Could not allocate TX descriptor "
3314 "chain DMA memory!\n", __FILE__, __LINE__);
3316 goto bce_dma_alloc_exit;
3319 error = bus_dmamap_load(sc->tx_bd_chain_tag,
3320 sc->tx_bd_chain_map[i], sc->tx_bd_chain[i],
3321 BCE_TX_CHAIN_PAGE_SZ, bce_dma_map_addr,
3322 &sc->tx_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3325 BCE_PRINTF("%s(%d): Could not map TX descriptor "
3326 "chain DMA memory!\n", __FILE__, __LINE__);
3328 goto bce_dma_alloc_exit;
3331 DBPRINT(sc, BCE_INFO_LOAD, "%s(): tx_bd_chain_paddr[%d] = "
3332 "0x%jX\n", __FUNCTION__, i,
3333 (uintmax_t) sc->tx_bd_chain_paddr[i]);
3336 /* Check the required size before mapping to conserve resources. */
3337 if (bce_tso_enable) {
3338 max_size = BCE_TSO_MAX_SIZE;
3339 max_segments = BCE_MAX_SEGMENTS;
3340 max_seg_size = BCE_TSO_MAX_SEG_SIZE;
3342 max_size = MCLBYTES * BCE_MAX_SEGMENTS;
3343 max_segments = BCE_MAX_SEGMENTS;
3344 max_seg_size = MCLBYTES;
3347 /* Create a DMA tag for TX mbufs. */
3348 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3349 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL, max_size,
3350 max_segments, max_seg_size, 0, NULL, NULL, &sc->tx_mbuf_tag)) {
3351 BCE_PRINTF("%s(%d): Could not allocate TX mbuf DMA tag!\n",
3352 __FILE__, __LINE__);
3354 goto bce_dma_alloc_exit;
3357 /* Create DMA maps for the TX mbufs clusters. */
3358 for (i = 0; i < TOTAL_TX_BD; i++) {
3359 if (bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_NOWAIT,
3360 &sc->tx_mbuf_map[i])) {
3361 BCE_PRINTF("%s(%d): Unable to create TX mbuf DMA "
3362 "map!\n", __FILE__, __LINE__);
3364 goto bce_dma_alloc_exit;
3369 * Create a DMA tag for the RX buffer descriptor chain,
3370 * allocate and clear the memory, and fetch the physical
3371 * address of the blocks.
3373 if (bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3374 BCE_DMA_BOUNDARY, BUS_SPACE_MAXADDR,
3375 sc->max_bus_addr, NULL, NULL,
3376 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
3377 0, NULL, NULL, &sc->rx_bd_chain_tag)) {
3378 BCE_PRINTF("%s(%d): Could not allocate RX descriptor chain "
3379 "DMA tag!\n", __FILE__, __LINE__);
3381 goto bce_dma_alloc_exit;
3384 for (i = 0; i < RX_PAGES; i++) {
3386 if (bus_dmamem_alloc(sc->rx_bd_chain_tag,
3387 (void **)&sc->rx_bd_chain[i], BUS_DMA_NOWAIT,
3388 &sc->rx_bd_chain_map[i])) {
3389 BCE_PRINTF("%s(%d): Could not allocate RX descriptor "
3390 "chain DMA memory!\n", __FILE__, __LINE__);
3392 goto bce_dma_alloc_exit;
3395 bzero((char *)sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
3397 error = bus_dmamap_load(sc->rx_bd_chain_tag,
3398 sc->rx_bd_chain_map[i], sc->rx_bd_chain[i],
3399 BCE_RX_CHAIN_PAGE_SZ, bce_dma_map_addr,
3400 &sc->rx_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3403 BCE_PRINTF("%s(%d): Could not map RX descriptor "
3404 "chain DMA memory!\n", __FILE__, __LINE__);
3406 goto bce_dma_alloc_exit;
3409 DBPRINT(sc, BCE_INFO_LOAD, "%s(): rx_bd_chain_paddr[%d] = "
3410 "0x%jX\n", __FUNCTION__, i,
3411 (uintmax_t) sc->rx_bd_chain_paddr[i]);
3415 * Create a DMA tag for RX mbufs.
3417 #ifdef BCE_JUMBO_HDRSPLIT
3418 max_size = max_seg_size = ((sc->rx_bd_mbuf_alloc_size < MCLBYTES) ?
3419 MCLBYTES : sc->rx_bd_mbuf_alloc_size);
3421 max_size = max_seg_size = MJUM9BYTES;
3425 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Creating rx_mbuf_tag "
3426 "(max size = 0x%jX max segments = %d, max segment "
3427 "size = 0x%jX)\n", __FUNCTION__, (uintmax_t) max_size,
3428 max_segments, (uintmax_t) max_seg_size);
3430 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3431 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL, max_size,
3432 max_segments, max_seg_size, 0, NULL, NULL, &sc->rx_mbuf_tag)) {
3433 BCE_PRINTF("%s(%d): Could not allocate RX mbuf DMA tag!\n",
3434 __FILE__, __LINE__);
3436 goto bce_dma_alloc_exit;
3439 /* Create DMA maps for the RX mbuf clusters. */
3440 for (i = 0; i < TOTAL_RX_BD; i++) {
3441 if (bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_NOWAIT,
3442 &sc->rx_mbuf_map[i])) {
3443 BCE_PRINTF("%s(%d): Unable to create RX mbuf "
3444 "DMA map!\n", __FILE__, __LINE__);
3446 goto bce_dma_alloc_exit;
3450 #ifdef BCE_JUMBO_HDRSPLIT
3452 * Create a DMA tag for the page buffer descriptor chain,
3453 * allocate and clear the memory, and fetch the physical
3454 * address of the blocks.
3456 if (bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3457 BCE_DMA_BOUNDARY, BUS_SPACE_MAXADDR, sc->max_bus_addr,
3458 NULL, NULL, BCE_PG_CHAIN_PAGE_SZ, 1, BCE_PG_CHAIN_PAGE_SZ,
3459 0, NULL, NULL, &sc->pg_bd_chain_tag)) {
3460 BCE_PRINTF("%s(%d): Could not allocate page descriptor "
3461 "chain DMA tag!\n", __FILE__, __LINE__);
3463 goto bce_dma_alloc_exit;
3466 for (i = 0; i < PG_PAGES; i++) {
3468 if (bus_dmamem_alloc(sc->pg_bd_chain_tag,
3469 (void **)&sc->pg_bd_chain[i], BUS_DMA_NOWAIT,
3470 &sc->pg_bd_chain_map[i])) {
3471 BCE_PRINTF("%s(%d): Could not allocate page "
3472 "descriptor chain DMA memory!\n",
3473 __FILE__, __LINE__);
3475 goto bce_dma_alloc_exit;
3478 bzero((char *)sc->pg_bd_chain[i], BCE_PG_CHAIN_PAGE_SZ);
3480 error = bus_dmamap_load(sc->pg_bd_chain_tag,
3481 sc->pg_bd_chain_map[i], sc->pg_bd_chain[i],
3482 BCE_PG_CHAIN_PAGE_SZ, bce_dma_map_addr,
3483 &sc->pg_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3486 BCE_PRINTF("%s(%d): Could not map page descriptor "
3487 "chain DMA memory!\n", __FILE__, __LINE__);
3489 goto bce_dma_alloc_exit;
3492 DBPRINT(sc, BCE_INFO_LOAD, "%s(): pg_bd_chain_paddr[%d] = "
3493 "0x%jX\n", __FUNCTION__, i,
3494 (uintmax_t) sc->pg_bd_chain_paddr[i]);
3498 * Create a DMA tag for page mbufs.
3500 max_size = max_seg_size = ((sc->pg_bd_mbuf_alloc_size < MCLBYTES) ?
3501 MCLBYTES : sc->pg_bd_mbuf_alloc_size);
3503 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3504 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3505 max_size, 1, max_seg_size, 0, NULL, NULL, &sc->pg_mbuf_tag)) {
3506 BCE_PRINTF("%s(%d): Could not allocate page mbuf "
3507 "DMA tag!\n", __FILE__, __LINE__);
3509 goto bce_dma_alloc_exit;
3512 /* Create DMA maps for the page mbuf clusters. */
3513 for (i = 0; i < TOTAL_PG_BD; i++) {
3514 if (bus_dmamap_create(sc->pg_mbuf_tag, BUS_DMA_NOWAIT,
3515 &sc->pg_mbuf_map[i])) {
3516 BCE_PRINTF("%s(%d): Unable to create page mbuf "
3517 "DMA map!\n", __FILE__, __LINE__);
3519 goto bce_dma_alloc_exit;
3525 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
3530 /****************************************************************************/
3531 /* Release all resources used by the driver. */
3533 /* Releases all resources acquired by the driver including interrupts, */
3534 /* interrupt handler, interfaces, mutexes, and DMA memory. */
3538 /****************************************************************************/
3540 bce_release_resources(struct bce_softc *sc)
3544 DBENTER(BCE_VERBOSE_RESET);
3550 if (sc->bce_intrhand != NULL) {
3551 DBPRINT(sc, BCE_INFO_RESET, "Removing interrupt handler.\n");
3552 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
3555 if (sc->bce_res_irq != NULL) {
3556 DBPRINT(sc, BCE_INFO_RESET, "Releasing IRQ.\n");
3557 bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
3561 if (sc->bce_flags & (BCE_USING_MSI_FLAG | BCE_USING_MSIX_FLAG)) {
3562 DBPRINT(sc, BCE_INFO_RESET, "Releasing MSI/MSI-X vector.\n");
3563 pci_release_msi(dev);
3566 if (sc->bce_res_mem != NULL) {
3567 DBPRINT(sc, BCE_INFO_RESET, "Releasing PCI memory.\n");
3568 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
3572 if (sc->bce_ifp != NULL) {
3573 DBPRINT(sc, BCE_INFO_RESET, "Releasing IF.\n");
3574 if_free(sc->bce_ifp);
3577 if (mtx_initialized(&sc->bce_mtx))
3578 BCE_LOCK_DESTROY(sc);
3580 DBEXIT(BCE_VERBOSE_RESET);
3584 /****************************************************************************/
3585 /* Firmware synchronization. */
3587 /* Before performing certain events such as a chip reset, synchronize with */
3588 /* the firmware first. */
3591 /* 0 for success, positive value for failure. */
3592 /****************************************************************************/
3594 bce_fw_sync(struct bce_softc *sc, u32 msg_data)
3599 DBENTER(BCE_VERBOSE_RESET);
3601 /* Don't waste any time if we've timed out before. */
3602 if (sc->bce_fw_timed_out == TRUE) {
3604 goto bce_fw_sync_exit;
3607 /* Increment the message sequence number. */
3608 sc->bce_fw_wr_seq++;
3609 msg_data |= sc->bce_fw_wr_seq;
3611 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "bce_fw_sync(): msg_data = "
3612 "0x%08X\n", msg_data);
3614 /* Send the message to the bootcode driver mailbox. */
3615 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
3617 /* Wait for the bootcode to acknowledge the message. */
3618 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
3619 /* Check for a response in the bootcode firmware mailbox. */
3620 val = bce_shmem_rd(sc, BCE_FW_MB);
3621 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
3626 /* If we've timed out, tell bootcode that we've stopped waiting. */
3627 if (((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ)) &&
3628 ((msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0)) {
3630 BCE_PRINTF("%s(%d): Firmware synchronization timeout! "
3631 "msg_data = 0x%08X\n", __FILE__, __LINE__, msg_data);
3633 msg_data &= ~BCE_DRV_MSG_CODE;
3634 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
3636 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
3638 sc->bce_fw_timed_out = TRUE;
3643 DBEXIT(BCE_VERBOSE_RESET);
3648 /****************************************************************************/
3649 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
3653 /****************************************************************************/
3655 bce_load_rv2p_fw(struct bce_softc *sc, u32 *rv2p_code,
3656 u32 rv2p_code_len, u32 rv2p_proc)
3661 DBENTER(BCE_VERBOSE_RESET);
3663 /* Set the page size used by RV2P. */
3664 if (rv2p_proc == RV2P_PROC2) {
3665 BCE_RV2P_PROC2_CHG_MAX_BD_PAGE(USABLE_RX_BD_PER_PAGE);
3668 for (i = 0; i < rv2p_code_len; i += 8) {
3669 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
3671 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
3674 if (rv2p_proc == RV2P_PROC1) {
3675 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
3676 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
3679 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
3680 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
3684 /* Reset the processor, un-stall is done later. */
3685 if (rv2p_proc == RV2P_PROC1) {
3686 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
3689 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
3692 DBEXIT(BCE_VERBOSE_RESET);
3696 /****************************************************************************/
3697 /* Load RISC processor firmware. */
3699 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
3700 /* associated with a particular processor. */
3704 /****************************************************************************/
3706 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
3711 DBENTER(BCE_VERBOSE_RESET);
3713 bce_halt_cpu(sc, cpu_reg);
3715 /* Load the Text area. */
3716 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
3720 for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
3721 REG_WR_IND(sc, offset, fw->text[j]);
3725 /* Load the Data area. */
3726 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
3730 for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
3731 REG_WR_IND(sc, offset, fw->data[j]);
3735 /* Load the SBSS area. */
3736 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
3740 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
3741 REG_WR_IND(sc, offset, fw->sbss[j]);
3745 /* Load the BSS area. */
3746 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
3750 for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
3751 REG_WR_IND(sc, offset, fw->bss[j]);
3755 /* Load the Read-Only area. */
3756 offset = cpu_reg->spad_base +
3757 (fw->rodata_addr - cpu_reg->mips_view_base);
3761 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
3762 REG_WR_IND(sc, offset, fw->rodata[j]);
3766 /* Clear the pre-fetch instruction and set the FW start address. */
3767 REG_WR_IND(sc, cpu_reg->inst, 0);
3768 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
3770 DBEXIT(BCE_VERBOSE_RESET);
3774 /****************************************************************************/
3775 /* Starts the RISC processor. */
3777 /* Assumes the CPU starting address has already been set. */
3781 /****************************************************************************/
3783 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
3787 DBENTER(BCE_VERBOSE_RESET);
3789 /* Start the CPU. */
3790 val = REG_RD_IND(sc, cpu_reg->mode);
3791 val &= ~cpu_reg->mode_value_halt;
3792 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
3793 REG_WR_IND(sc, cpu_reg->mode, val);
3795 DBEXIT(BCE_VERBOSE_RESET);
3799 /****************************************************************************/
3800 /* Halts the RISC processor. */
3804 /****************************************************************************/
3806 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
3810 DBENTER(BCE_VERBOSE_RESET);
3813 val = REG_RD_IND(sc, cpu_reg->mode);
3814 val |= cpu_reg->mode_value_halt;
3815 REG_WR_IND(sc, cpu_reg->mode, val);
3816 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
3818 DBEXIT(BCE_VERBOSE_RESET);
3822 /****************************************************************************/
3823 /* Initialize the RX CPU. */
3827 /****************************************************************************/
3829 bce_start_rxp_cpu(struct bce_softc *sc)
3831 struct cpu_reg cpu_reg;
3833 DBENTER(BCE_VERBOSE_RESET);
3835 cpu_reg.mode = BCE_RXP_CPU_MODE;
3836 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
3837 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
3838 cpu_reg.state = BCE_RXP_CPU_STATE;
3839 cpu_reg.state_value_clear = 0xffffff;
3840 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
3841 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
3842 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
3843 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
3844 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
3845 cpu_reg.spad_base = BCE_RXP_SCRATCH;
3846 cpu_reg.mips_view_base = 0x8000000;
3848 DBPRINT(sc, BCE_INFO_RESET, "Starting RX firmware.\n");
3849 bce_start_cpu(sc, &cpu_reg);
3851 DBEXIT(BCE_VERBOSE_RESET);
3855 /****************************************************************************/
3856 /* Initialize the RX CPU. */
3860 /****************************************************************************/
3862 bce_init_rxp_cpu(struct bce_softc *sc)
3864 struct cpu_reg cpu_reg;
3867 DBENTER(BCE_VERBOSE_RESET);
3869 cpu_reg.mode = BCE_RXP_CPU_MODE;
3870 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
3871 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
3872 cpu_reg.state = BCE_RXP_CPU_STATE;
3873 cpu_reg.state_value_clear = 0xffffff;
3874 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
3875 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
3876 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
3877 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
3878 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
3879 cpu_reg.spad_base = BCE_RXP_SCRATCH;
3880 cpu_reg.mips_view_base = 0x8000000;
3882 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
3883 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
3884 fw.ver_major = bce_RXP_b09FwReleaseMajor;
3885 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
3886 fw.ver_fix = bce_RXP_b09FwReleaseFix;
3887 fw.start_addr = bce_RXP_b09FwStartAddr;
3889 fw.text_addr = bce_RXP_b09FwTextAddr;
3890 fw.text_len = bce_RXP_b09FwTextLen;
3892 fw.text = bce_RXP_b09FwText;
3894 fw.data_addr = bce_RXP_b09FwDataAddr;
3895 fw.data_len = bce_RXP_b09FwDataLen;
3897 fw.data = bce_RXP_b09FwData;
3899 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
3900 fw.sbss_len = bce_RXP_b09FwSbssLen;
3902 fw.sbss = bce_RXP_b09FwSbss;
3904 fw.bss_addr = bce_RXP_b09FwBssAddr;
3905 fw.bss_len = bce_RXP_b09FwBssLen;
3907 fw.bss = bce_RXP_b09FwBss;
3909 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
3910 fw.rodata_len = bce_RXP_b09FwRodataLen;
3911 fw.rodata_index = 0;
3912 fw.rodata = bce_RXP_b09FwRodata;
3914 fw.ver_major = bce_RXP_b06FwReleaseMajor;
3915 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
3916 fw.ver_fix = bce_RXP_b06FwReleaseFix;
3917 fw.start_addr = bce_RXP_b06FwStartAddr;
3919 fw.text_addr = bce_RXP_b06FwTextAddr;
3920 fw.text_len = bce_RXP_b06FwTextLen;
3922 fw.text = bce_RXP_b06FwText;
3924 fw.data_addr = bce_RXP_b06FwDataAddr;
3925 fw.data_len = bce_RXP_b06FwDataLen;
3927 fw.data = bce_RXP_b06FwData;
3929 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
3930 fw.sbss_len = bce_RXP_b06FwSbssLen;
3932 fw.sbss = bce_RXP_b06FwSbss;
3934 fw.bss_addr = bce_RXP_b06FwBssAddr;
3935 fw.bss_len = bce_RXP_b06FwBssLen;
3937 fw.bss = bce_RXP_b06FwBss;
3939 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
3940 fw.rodata_len = bce_RXP_b06FwRodataLen;
3941 fw.rodata_index = 0;
3942 fw.rodata = bce_RXP_b06FwRodata;
3945 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
3946 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3948 /* Delay RXP start until initialization is complete. */
3950 DBEXIT(BCE_VERBOSE_RESET);
3954 /****************************************************************************/
3955 /* Initialize the TX CPU. */
3959 /****************************************************************************/
3961 bce_init_txp_cpu(struct bce_softc *sc)
3963 struct cpu_reg cpu_reg;
3966 DBENTER(BCE_VERBOSE_RESET);
3968 cpu_reg.mode = BCE_TXP_CPU_MODE;
3969 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
3970 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
3971 cpu_reg.state = BCE_TXP_CPU_STATE;
3972 cpu_reg.state_value_clear = 0xffffff;
3973 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
3974 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
3975 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
3976 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
3977 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
3978 cpu_reg.spad_base = BCE_TXP_SCRATCH;
3979 cpu_reg.mips_view_base = 0x8000000;
3981 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
3982 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
3983 fw.ver_major = bce_TXP_b09FwReleaseMajor;
3984 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
3985 fw.ver_fix = bce_TXP_b09FwReleaseFix;
3986 fw.start_addr = bce_TXP_b09FwStartAddr;
3988 fw.text_addr = bce_TXP_b09FwTextAddr;
3989 fw.text_len = bce_TXP_b09FwTextLen;
3991 fw.text = bce_TXP_b09FwText;
3993 fw.data_addr = bce_TXP_b09FwDataAddr;
3994 fw.data_len = bce_TXP_b09FwDataLen;
3996 fw.data = bce_TXP_b09FwData;
3998 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
3999 fw.sbss_len = bce_TXP_b09FwSbssLen;
4001 fw.sbss = bce_TXP_b09FwSbss;
4003 fw.bss_addr = bce_TXP_b09FwBssAddr;
4004 fw.bss_len = bce_TXP_b09FwBssLen;
4006 fw.bss = bce_TXP_b09FwBss;
4008 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
4009 fw.rodata_len = bce_TXP_b09FwRodataLen;
4010 fw.rodata_index = 0;
4011 fw.rodata = bce_TXP_b09FwRodata;
4013 fw.ver_major = bce_TXP_b06FwReleaseMajor;
4014 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
4015 fw.ver_fix = bce_TXP_b06FwReleaseFix;
4016 fw.start_addr = bce_TXP_b06FwStartAddr;
4018 fw.text_addr = bce_TXP_b06FwTextAddr;
4019 fw.text_len = bce_TXP_b06FwTextLen;
4021 fw.text = bce_TXP_b06FwText;
4023 fw.data_addr = bce_TXP_b06FwDataAddr;
4024 fw.data_len = bce_TXP_b06FwDataLen;
4026 fw.data = bce_TXP_b06FwData;
4028 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
4029 fw.sbss_len = bce_TXP_b06FwSbssLen;
4031 fw.sbss = bce_TXP_b06FwSbss;
4033 fw.bss_addr = bce_TXP_b06FwBssAddr;
4034 fw.bss_len = bce_TXP_b06FwBssLen;
4036 fw.bss = bce_TXP_b06FwBss;
4038 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
4039 fw.rodata_len = bce_TXP_b06FwRodataLen;
4040 fw.rodata_index = 0;
4041 fw.rodata = bce_TXP_b06FwRodata;
4044 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
4045 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4046 bce_start_cpu(sc, &cpu_reg);
4048 DBEXIT(BCE_VERBOSE_RESET);
4052 /****************************************************************************/
4053 /* Initialize the TPAT CPU. */
4057 /****************************************************************************/
4059 bce_init_tpat_cpu(struct bce_softc *sc)
4061 struct cpu_reg cpu_reg;
4064 DBENTER(BCE_VERBOSE_RESET);
4066 cpu_reg.mode = BCE_TPAT_CPU_MODE;
4067 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
4068 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
4069 cpu_reg.state = BCE_TPAT_CPU_STATE;
4070 cpu_reg.state_value_clear = 0xffffff;
4071 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
4072 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
4073 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
4074 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
4075 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
4076 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
4077 cpu_reg.mips_view_base = 0x8000000;
4079 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4080 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4081 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
4082 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
4083 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
4084 fw.start_addr = bce_TPAT_b09FwStartAddr;
4086 fw.text_addr = bce_TPAT_b09FwTextAddr;
4087 fw.text_len = bce_TPAT_b09FwTextLen;
4089 fw.text = bce_TPAT_b09FwText;
4091 fw.data_addr = bce_TPAT_b09FwDataAddr;
4092 fw.data_len = bce_TPAT_b09FwDataLen;
4094 fw.data = bce_TPAT_b09FwData;
4096 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
4097 fw.sbss_len = bce_TPAT_b09FwSbssLen;
4099 fw.sbss = bce_TPAT_b09FwSbss;
4101 fw.bss_addr = bce_TPAT_b09FwBssAddr;
4102 fw.bss_len = bce_TPAT_b09FwBssLen;
4104 fw.bss = bce_TPAT_b09FwBss;
4106 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
4107 fw.rodata_len = bce_TPAT_b09FwRodataLen;
4108 fw.rodata_index = 0;
4109 fw.rodata = bce_TPAT_b09FwRodata;
4111 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
4112 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
4113 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
4114 fw.start_addr = bce_TPAT_b06FwStartAddr;
4116 fw.text_addr = bce_TPAT_b06FwTextAddr;
4117 fw.text_len = bce_TPAT_b06FwTextLen;
4119 fw.text = bce_TPAT_b06FwText;
4121 fw.data_addr = bce_TPAT_b06FwDataAddr;
4122 fw.data_len = bce_TPAT_b06FwDataLen;
4124 fw.data = bce_TPAT_b06FwData;
4126 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
4127 fw.sbss_len = bce_TPAT_b06FwSbssLen;
4129 fw.sbss = bce_TPAT_b06FwSbss;
4131 fw.bss_addr = bce_TPAT_b06FwBssAddr;
4132 fw.bss_len = bce_TPAT_b06FwBssLen;
4134 fw.bss = bce_TPAT_b06FwBss;
4136 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
4137 fw.rodata_len = bce_TPAT_b06FwRodataLen;
4138 fw.rodata_index = 0;
4139 fw.rodata = bce_TPAT_b06FwRodata;
4142 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
4143 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4144 bce_start_cpu(sc, &cpu_reg);
4146 DBEXIT(BCE_VERBOSE_RESET);
4150 /****************************************************************************/
4151 /* Initialize the CP CPU. */
4155 /****************************************************************************/
4157 bce_init_cp_cpu(struct bce_softc *sc)
4159 struct cpu_reg cpu_reg;
4162 DBENTER(BCE_VERBOSE_RESET);
4164 cpu_reg.mode = BCE_CP_CPU_MODE;
4165 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
4166 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
4167 cpu_reg.state = BCE_CP_CPU_STATE;
4168 cpu_reg.state_value_clear = 0xffffff;
4169 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
4170 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
4171 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
4172 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
4173 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
4174 cpu_reg.spad_base = BCE_CP_SCRATCH;
4175 cpu_reg.mips_view_base = 0x8000000;
4177 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4178 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4179 fw.ver_major = bce_CP_b09FwReleaseMajor;
4180 fw.ver_minor = bce_CP_b09FwReleaseMinor;
4181 fw.ver_fix = bce_CP_b09FwReleaseFix;
4182 fw.start_addr = bce_CP_b09FwStartAddr;
4184 fw.text_addr = bce_CP_b09FwTextAddr;
4185 fw.text_len = bce_CP_b09FwTextLen;
4187 fw.text = bce_CP_b09FwText;
4189 fw.data_addr = bce_CP_b09FwDataAddr;
4190 fw.data_len = bce_CP_b09FwDataLen;
4192 fw.data = bce_CP_b09FwData;
4194 fw.sbss_addr = bce_CP_b09FwSbssAddr;
4195 fw.sbss_len = bce_CP_b09FwSbssLen;
4197 fw.sbss = bce_CP_b09FwSbss;
4199 fw.bss_addr = bce_CP_b09FwBssAddr;
4200 fw.bss_len = bce_CP_b09FwBssLen;
4202 fw.bss = bce_CP_b09FwBss;
4204 fw.rodata_addr = bce_CP_b09FwRodataAddr;
4205 fw.rodata_len = bce_CP_b09FwRodataLen;
4206 fw.rodata_index = 0;
4207 fw.rodata = bce_CP_b09FwRodata;
4209 fw.ver_major = bce_CP_b06FwReleaseMajor;
4210 fw.ver_minor = bce_CP_b06FwReleaseMinor;
4211 fw.ver_fix = bce_CP_b06FwReleaseFix;
4212 fw.start_addr = bce_CP_b06FwStartAddr;
4214 fw.text_addr = bce_CP_b06FwTextAddr;
4215 fw.text_len = bce_CP_b06FwTextLen;
4217 fw.text = bce_CP_b06FwText;
4219 fw.data_addr = bce_CP_b06FwDataAddr;
4220 fw.data_len = bce_CP_b06FwDataLen;
4222 fw.data = bce_CP_b06FwData;
4224 fw.sbss_addr = bce_CP_b06FwSbssAddr;
4225 fw.sbss_len = bce_CP_b06FwSbssLen;
4227 fw.sbss = bce_CP_b06FwSbss;
4229 fw.bss_addr = bce_CP_b06FwBssAddr;
4230 fw.bss_len = bce_CP_b06FwBssLen;
4232 fw.bss = bce_CP_b06FwBss;
4234 fw.rodata_addr = bce_CP_b06FwRodataAddr;
4235 fw.rodata_len = bce_CP_b06FwRodataLen;
4236 fw.rodata_index = 0;
4237 fw.rodata = bce_CP_b06FwRodata;
4240 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
4241 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4242 bce_start_cpu(sc, &cpu_reg);
4244 DBEXIT(BCE_VERBOSE_RESET);
4248 /****************************************************************************/
4249 /* Initialize the COM CPU. */
4253 /****************************************************************************/
4255 bce_init_com_cpu(struct bce_softc *sc)
4257 struct cpu_reg cpu_reg;
4260 DBENTER(BCE_VERBOSE_RESET);
4262 cpu_reg.mode = BCE_COM_CPU_MODE;
4263 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
4264 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
4265 cpu_reg.state = BCE_COM_CPU_STATE;
4266 cpu_reg.state_value_clear = 0xffffff;
4267 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
4268 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
4269 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
4270 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
4271 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
4272 cpu_reg.spad_base = BCE_COM_SCRATCH;
4273 cpu_reg.mips_view_base = 0x8000000;
4275 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4276 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4277 fw.ver_major = bce_COM_b09FwReleaseMajor;
4278 fw.ver_minor = bce_COM_b09FwReleaseMinor;
4279 fw.ver_fix = bce_COM_b09FwReleaseFix;
4280 fw.start_addr = bce_COM_b09FwStartAddr;
4282 fw.text_addr = bce_COM_b09FwTextAddr;
4283 fw.text_len = bce_COM_b09FwTextLen;
4285 fw.text = bce_COM_b09FwText;
4287 fw.data_addr = bce_COM_b09FwDataAddr;
4288 fw.data_len = bce_COM_b09FwDataLen;
4290 fw.data = bce_COM_b09FwData;
4292 fw.sbss_addr = bce_COM_b09FwSbssAddr;
4293 fw.sbss_len = bce_COM_b09FwSbssLen;
4295 fw.sbss = bce_COM_b09FwSbss;
4297 fw.bss_addr = bce_COM_b09FwBssAddr;
4298 fw.bss_len = bce_COM_b09FwBssLen;
4300 fw.bss = bce_COM_b09FwBss;
4302 fw.rodata_addr = bce_COM_b09FwRodataAddr;
4303 fw.rodata_len = bce_COM_b09FwRodataLen;
4304 fw.rodata_index = 0;
4305 fw.rodata = bce_COM_b09FwRodata;
4307 fw.ver_major = bce_COM_b06FwReleaseMajor;
4308 fw.ver_minor = bce_COM_b06FwReleaseMinor;
4309 fw.ver_fix = bce_COM_b06FwReleaseFix;
4310 fw.start_addr = bce_COM_b06FwStartAddr;
4312 fw.text_addr = bce_COM_b06FwTextAddr;
4313 fw.text_len = bce_COM_b06FwTextLen;
4315 fw.text = bce_COM_b06FwText;
4317 fw.data_addr = bce_COM_b06FwDataAddr;
4318 fw.data_len = bce_COM_b06FwDataLen;
4320 fw.data = bce_COM_b06FwData;
4322 fw.sbss_addr = bce_COM_b06FwSbssAddr;
4323 fw.sbss_len = bce_COM_b06FwSbssLen;
4325 fw.sbss = bce_COM_b06FwSbss;
4327 fw.bss_addr = bce_COM_b06FwBssAddr;
4328 fw.bss_len = bce_COM_b06FwBssLen;
4330 fw.bss = bce_COM_b06FwBss;
4332 fw.rodata_addr = bce_COM_b06FwRodataAddr;
4333 fw.rodata_len = bce_COM_b06FwRodataLen;
4334 fw.rodata_index = 0;
4335 fw.rodata = bce_COM_b06FwRodata;
4338 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
4339 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4340 bce_start_cpu(sc, &cpu_reg);
4342 DBEXIT(BCE_VERBOSE_RESET);
4346 /****************************************************************************/
4347 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
4349 /* Loads the firmware for each CPU and starts the CPU. */
4353 /****************************************************************************/
4355 bce_init_cpus(struct bce_softc *sc)
4357 DBENTER(BCE_VERBOSE_RESET);
4359 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4360 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4362 if ((BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax)) {
4363 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
4364 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
4365 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
4366 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
4368 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
4369 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
4370 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
4371 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
4375 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
4376 sizeof(bce_rv2p_proc1), RV2P_PROC1);
4377 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
4378 sizeof(bce_rv2p_proc2), RV2P_PROC2);
4381 bce_init_rxp_cpu(sc);
4382 bce_init_txp_cpu(sc);
4383 bce_init_tpat_cpu(sc);
4384 bce_init_com_cpu(sc);
4385 bce_init_cp_cpu(sc);
4387 DBEXIT(BCE_VERBOSE_RESET);
4391 /****************************************************************************/
4392 /* Initialize context memory. */
4394 /* Clears the memory associated with each Context ID (CID). */
4398 /****************************************************************************/
4400 bce_init_ctx(struct bce_softc *sc)
4402 u32 offset, val, vcid_addr;
4403 int i, j, rc, retry_cnt;
4406 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
4408 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4409 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4410 retry_cnt = CTX_INIT_RETRY_COUNT;
4412 DBPRINT(sc, BCE_INFO_CTX, "Initializing 5709 context.\n");
4415 * BCM5709 context memory may be cached
4416 * in host memory so prepare the host memory
4419 val = BCE_CTX_COMMAND_ENABLED |
4420 BCE_CTX_COMMAND_MEM_INIT | (1 << 12);
4421 val |= (BCM_PAGE_BITS - 8) << 16;
4422 REG_WR(sc, BCE_CTX_COMMAND, val);
4424 /* Wait for mem init command to complete. */
4425 for (i = 0; i < retry_cnt; i++) {
4426 val = REG_RD(sc, BCE_CTX_COMMAND);
4427 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
4431 if ((val & BCE_CTX_COMMAND_MEM_INIT) != 0) {
4432 BCE_PRINTF("%s(): Context memory initialization failed!\n",
4438 for (i = 0; i < sc->ctx_pages; i++) {
4439 /* Set the physical address of the context memory. */
4440 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
4441 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
4442 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
4443 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
4444 BCE_ADDR_HI(sc->ctx_paddr[i]));
4445 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL, i |
4446 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
4448 /* Verify the context memory write was successful. */
4449 for (j = 0; j < retry_cnt; j++) {
4450 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
4452 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
4456 if ((val & BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) != 0) {
4457 BCE_PRINTF("%s(): Failed to initialize "
4458 "context page %d!\n", __FUNCTION__, i);
4465 DBPRINT(sc, BCE_INFO, "Initializing 5706/5708 context.\n");
4468 * For the 5706/5708, context memory is local to
4469 * the controller, so initialize the controller
4473 vcid_addr = GET_CID_ADDR(96);
4476 vcid_addr -= PHY_CTX_SIZE;
4478 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
4479 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
4481 for(offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
4482 CTX_WR(sc, 0x00, offset, 0);
4485 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
4486 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
4491 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
4496 /****************************************************************************/
4497 /* Fetch the permanent MAC address of the controller. */
4501 /****************************************************************************/
4503 bce_get_mac_addr(struct bce_softc *sc)
4505 u32 mac_lo = 0, mac_hi = 0;
4507 DBENTER(BCE_VERBOSE_RESET);
4510 * The NetXtreme II bootcode populates various NIC
4511 * power-on and runtime configuration items in a
4512 * shared memory area. The factory configured MAC
4513 * address is available from both NVRAM and the
4514 * shared memory area so we'll read the value from
4515 * shared memory for speed.
4518 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
4519 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
4521 if ((mac_lo == 0) && (mac_hi == 0)) {
4522 BCE_PRINTF("%s(%d): Invalid Ethernet address!\n",
4523 __FILE__, __LINE__);
4525 sc->eaddr[0] = (u_char)(mac_hi >> 8);
4526 sc->eaddr[1] = (u_char)(mac_hi >> 0);
4527 sc->eaddr[2] = (u_char)(mac_lo >> 24);
4528 sc->eaddr[3] = (u_char)(mac_lo >> 16);
4529 sc->eaddr[4] = (u_char)(mac_lo >> 8);
4530 sc->eaddr[5] = (u_char)(mac_lo >> 0);
4533 DBPRINT(sc, BCE_INFO_MISC, "Permanent Ethernet "
4534 "address = %6D\n", sc->eaddr, ":");
4535 DBEXIT(BCE_VERBOSE_RESET);
4539 /****************************************************************************/
4540 /* Program the MAC address. */
4544 /****************************************************************************/
4546 bce_set_mac_addr(struct bce_softc *sc)
4549 u8 *mac_addr = sc->eaddr;
4551 /* ToDo: Add support for setting multiple MAC addresses. */
4553 DBENTER(BCE_VERBOSE_RESET);
4554 DBPRINT(sc, BCE_INFO_MISC, "Setting Ethernet address = "
4555 "%6D\n", sc->eaddr, ":");
4557 val = (mac_addr[0] << 8) | mac_addr[1];
4559 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
4561 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
4562 (mac_addr[4] << 8) | mac_addr[5];
4564 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
4566 DBEXIT(BCE_VERBOSE_RESET);
4570 /****************************************************************************/
4571 /* Stop the controller. */
4575 /****************************************************************************/
4577 bce_stop(struct bce_softc *sc)
4581 DBENTER(BCE_VERBOSE_RESET);
4583 BCE_LOCK_ASSERT(sc);
4587 callout_stop(&sc->bce_tick_callout);
4589 /* Disable the transmit/receive blocks. */
4590 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
4591 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
4594 bce_disable_intr(sc);
4596 /* Free RX buffers. */
4597 #ifdef BCE_JUMBO_HDRSPLIT
4598 bce_free_pg_chain(sc);
4600 bce_free_rx_chain(sc);
4602 /* Free TX buffers. */
4603 bce_free_tx_chain(sc);
4605 sc->watchdog_timer = 0;
4607 sc->bce_link_up = FALSE;
4609 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
4611 DBEXIT(BCE_VERBOSE_RESET);
4616 bce_reset(struct bce_softc *sc, u32 reset_code)
4621 DBENTER(BCE_VERBOSE_RESET);
4623 DBPRINT(sc, BCE_VERBOSE_RESET, "%s(): reset_code = 0x%08X\n",
4624 __FUNCTION__, reset_code);
4626 /* Wait for pending PCI transactions to complete. */
4627 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
4628 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
4629 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
4630 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
4631 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
4632 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
4636 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4637 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4638 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
4639 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
4640 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
4643 /* Assume bootcode is running. */
4644 sc->bce_fw_timed_out = FALSE;
4645 sc->bce_drv_cardiac_arrest = FALSE;
4647 /* Give the firmware a chance to prepare for the reset. */
4648 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
4650 goto bce_reset_exit;
4652 /* Set a firmware reminder that this is a soft reset. */
4653 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE, BCE_DRV_RESET_SIGNATURE_MAGIC);
4655 /* Dummy read to force the chip to complete all current transactions. */
4656 val = REG_RD(sc, BCE_MISC_ID);
4659 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4660 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4661 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
4662 REG_RD(sc, BCE_MISC_COMMAND);
4665 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
4666 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
4668 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
4670 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
4671 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
4672 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
4673 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
4675 /* Allow up to 30us for reset to complete. */
4676 for (i = 0; i < 10; i++) {
4677 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
4678 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
4679 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
4685 /* Check that reset completed successfully. */
4686 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
4687 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
4688 BCE_PRINTF("%s(%d): Reset failed!\n",
4689 __FILE__, __LINE__);
4691 goto bce_reset_exit;
4695 /* Make sure byte swapping is properly configured. */
4696 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
4697 if (val != 0x01020304) {
4698 BCE_PRINTF("%s(%d): Byte swap is incorrect!\n",
4699 __FILE__, __LINE__);
4701 goto bce_reset_exit;
4704 /* Just completed a reset, assume that firmware is running again. */
4705 sc->bce_fw_timed_out = FALSE;
4706 sc->bce_drv_cardiac_arrest = FALSE;
4708 /* Wait for the firmware to finish its initialization. */
4709 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
4711 BCE_PRINTF("%s(%d): Firmware did not complete "
4712 "initialization!\n", __FILE__, __LINE__);
4715 DBEXIT(BCE_VERBOSE_RESET);
4721 bce_chipinit(struct bce_softc *sc)
4726 DBENTER(BCE_VERBOSE_RESET);
4728 bce_disable_intr(sc);
4731 * Initialize DMA byte/word swapping, configure the number of DMA
4732 * channels and PCI clock compensation delay.
4734 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
4735 BCE_DMA_CONFIG_DATA_WORD_SWAP |
4736 #if BYTE_ORDER == BIG_ENDIAN
4737 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
4739 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
4740 DMA_READ_CHANS << 12 |
4741 DMA_WRITE_CHANS << 16;
4743 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
4745 if ((sc->bce_flags & BCE_PCIX_FLAG) && (sc->bus_speed_mhz == 133))
4746 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
4749 * This setting resolves a problem observed on certain Intel PCI
4750 * chipsets that cannot handle multiple outstanding DMA operations.
4751 * See errata E9_5706A1_65.
4753 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
4754 (BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0) &&
4755 !(sc->bce_flags & BCE_PCIX_FLAG))
4756 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
4758 REG_WR(sc, BCE_DMA_CONFIG, val);
4760 /* Enable the RX_V2P and Context state machines before access. */
4761 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4762 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
4763 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
4764 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
4766 /* Initialize context mapping and zero out the quick contexts. */
4767 if ((rc = bce_init_ctx(sc)) != 0)
4768 goto bce_chipinit_exit;
4770 /* Initialize the on-boards CPUs */
4773 /* Enable management frames (NC-SI) to flow to the MCP. */
4774 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
4775 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) | BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
4776 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
4779 /* Prepare NVRAM for access. */
4780 if ((rc = bce_init_nvram(sc)) != 0)
4781 goto bce_chipinit_exit;
4783 /* Set the kernel bypass block size */
4784 val = REG_RD(sc, BCE_MQ_CONFIG);
4785 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
4786 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
4788 /* Enable bins used on the 5709. */
4789 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4790 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4791 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
4792 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
4793 val |= BCE_MQ_CONFIG_HALT_DIS;
4796 REG_WR(sc, BCE_MQ_CONFIG, val);
4798 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
4799 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
4800 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
4802 /* Set the page size and clear the RV2P processor stall bits. */
4803 val = (BCM_PAGE_BITS - 8) << 24;
4804 REG_WR(sc, BCE_RV2P_CONFIG, val);
4806 /* Configure page size. */
4807 val = REG_RD(sc, BCE_TBDR_CONFIG);
4808 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
4809 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
4810 REG_WR(sc, BCE_TBDR_CONFIG, val);
4812 /* Set the perfect match control register to default. */
4813 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
4816 DBEXIT(BCE_VERBOSE_RESET);
4822 /****************************************************************************/
4823 /* Initialize the controller in preparation to send/receive traffic. */
4826 /* 0 for success, positive value for failure. */
4827 /****************************************************************************/
4829 bce_blockinit(struct bce_softc *sc)
4834 DBENTER(BCE_VERBOSE_RESET);
4836 /* Load the hardware default MAC address. */
4837 bce_set_mac_addr(sc);
4839 /* Set the Ethernet backoff seed value */
4840 val = sc->eaddr[0] + (sc->eaddr[1] << 8) +
4841 (sc->eaddr[2] << 16) + (sc->eaddr[3] ) +
4842 (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
4843 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
4845 sc->last_status_idx = 0;
4846 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
4848 /* Set up link change interrupt generation. */
4849 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
4851 /* Program the physical address of the status block. */
4852 REG_WR(sc, BCE_HC_STATUS_ADDR_L,
4853 BCE_ADDR_LO(sc->status_block_paddr));
4854 REG_WR(sc, BCE_HC_STATUS_ADDR_H,
4855 BCE_ADDR_HI(sc->status_block_paddr));
4857 /* Program the physical address of the statistics block. */
4858 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
4859 BCE_ADDR_LO(sc->stats_block_paddr));
4860 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
4861 BCE_ADDR_HI(sc->stats_block_paddr));
4863 /* Program various host coalescing parameters. */
4864 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4865 (sc->bce_tx_quick_cons_trip_int << 16) | sc->bce_tx_quick_cons_trip);
4866 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4867 (sc->bce_rx_quick_cons_trip_int << 16) | sc->bce_rx_quick_cons_trip);
4868 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
4869 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
4870 REG_WR(sc, BCE_HC_TX_TICKS,
4871 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
4872 REG_WR(sc, BCE_HC_RX_TICKS,
4873 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
4874 REG_WR(sc, BCE_HC_COM_TICKS,
4875 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
4876 REG_WR(sc, BCE_HC_CMD_TICKS,
4877 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
4878 REG_WR(sc, BCE_HC_STATS_TICKS,
4879 (sc->bce_stats_ticks & 0xffff00));
4880 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
4882 /* Configure the Host Coalescing block. */
4883 val = BCE_HC_CONFIG_RX_TMR_MODE | BCE_HC_CONFIG_TX_TMR_MODE |
4884 BCE_HC_CONFIG_COLLECT_STATS;
4887 /* ToDo: Add MSI-X support. */
4888 if (sc->bce_flags & BCE_USING_MSIX_FLAG) {
4889 u32 base = ((BCE_TX_VEC - 1) * BCE_HC_SB_CONFIG_SIZE) +
4892 REG_WR(sc, BCE_HC_MSIX_BIT_VECTOR, BCE_HC_MSIX_BIT_VECTOR_VAL);
4894 REG_WR(sc, base, BCE_HC_SB_CONFIG_1_TX_TMR_MODE |
4895 BCE_HC_SB_CONFIG_1_ONE_SHOT);
4897 REG_WR(sc, base + BCE_HC_TX_QUICK_CONS_TRIP_OFF,
4898 (sc->tx_quick_cons_trip_int << 16) |
4899 sc->tx_quick_cons_trip);
4901 REG_WR(sc, base + BCE_HC_TX_TICKS_OFF,
4902 (sc->tx_ticks_int << 16) | sc->tx_ticks);
4904 val |= BCE_HC_CONFIG_SB_ADDR_INC_128B;
4908 * Tell the HC block to automatically set the
4909 * INT_MASK bit after an MSI/MSI-X interrupt
4910 * is generated so the driver doesn't have to.
4912 if (sc->bce_flags & BCE_ONE_SHOT_MSI_FLAG)
4913 val |= BCE_HC_CONFIG_ONE_SHOT;
4915 /* Set the MSI-X status blocks to 128 byte boundaries. */
4916 if (sc->bce_flags & BCE_USING_MSIX_FLAG)
4917 val |= BCE_HC_CONFIG_SB_ADDR_INC_128B;
4920 REG_WR(sc, BCE_HC_CONFIG, val);
4922 /* Clear the internal statistics counters. */
4923 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
4925 /* Verify that bootcode is running. */
4926 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
4928 DBRUNIF(DB_RANDOMTRUE(bootcode_running_failure_sim_control),
4929 BCE_PRINTF("%s(%d): Simulating bootcode failure.\n",
4930 __FILE__, __LINE__);
4933 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
4934 BCE_DEV_INFO_SIGNATURE_MAGIC) {
4935 BCE_PRINTF("%s(%d): Bootcode not running! Found: 0x%08X, "
4936 "Expected: 08%08X\n", __FILE__, __LINE__,
4937 (reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK),
4938 BCE_DEV_INFO_SIGNATURE_MAGIC);
4940 goto bce_blockinit_exit;
4944 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4945 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4946 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
4947 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
4948 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
4951 /* Allow bootcode to apply additional fixes before enabling MAC. */
4952 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 |
4953 BCE_DRV_MSG_CODE_RESET);
4955 /* Enable link state change interrupt generation. */
4956 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
4958 /* Enable the RXP. */
4959 bce_start_rxp_cpu(sc);
4961 /* Disable management frames (NC-SI) from flowing to the MCP. */
4962 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
4963 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
4964 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
4965 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
4968 /* Enable all remaining blocks in the MAC. */
4969 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4970 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
4971 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4972 BCE_MISC_ENABLE_DEFAULT_XI);
4974 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4975 BCE_MISC_ENABLE_DEFAULT);
4977 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4980 /* Save the current host coalescing block settings. */
4981 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
4984 DBEXIT(BCE_VERBOSE_RESET);
4990 /****************************************************************************/
4991 /* Encapsulate an mbuf into the rx_bd chain. */
4994 /* 0 for success, positive value for failure. */
4995 /****************************************************************************/
4997 bce_get_rx_buf(struct bce_softc *sc, struct mbuf *m, u16 *prod,
4998 u16 *chain_prod, u32 *prod_bseq)
5001 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
5002 struct mbuf *m_new = NULL;
5004 int nsegs, error, rc = 0;
5006 u16 debug_chain_prod = *chain_prod;
5009 DBENTER(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5011 /* Make sure the inputs are valid. */
5012 DBRUNIF((*chain_prod > MAX_RX_BD),
5013 BCE_PRINTF("%s(%d): RX producer out of range: "
5014 "0x%04X > 0x%04X\n", __FILE__, __LINE__,
5015 *chain_prod, (u16) MAX_RX_BD));
5017 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): prod = 0x%04X, "
5018 "chain_prod = 0x%04X, prod_bseq = 0x%08X\n", __FUNCTION__,
5019 *prod, *chain_prod, *prod_bseq);
5021 /* Update some debug statistic counters */
5022 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
5023 sc->rx_low_watermark = sc->free_rx_bd);
5024 DBRUNIF((sc->free_rx_bd == sc->max_rx_bd),
5025 sc->rx_empty_count++);
5027 /* Check whether this is a new mbuf allocation. */
5030 /* Simulate an mbuf allocation failure. */
5031 DBRUNIF(DB_RANDOMTRUE(mbuf_alloc_failed_sim_control),
5032 sc->mbuf_alloc_failed_count++;
5033 sc->mbuf_alloc_failed_sim_count++;
5035 goto bce_get_rx_buf_exit);
5037 /* This is a new mbuf allocation. */
5038 #ifdef BCE_JUMBO_HDRSPLIT
5039 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
5041 if (sc->rx_bd_mbuf_alloc_size <= MCLBYTES)
5042 m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
5044 m_new = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR,
5045 sc->rx_bd_mbuf_alloc_size);
5048 if (m_new == NULL) {
5049 sc->mbuf_alloc_failed_count++;
5051 goto bce_get_rx_buf_exit;
5054 DBRUN(sc->debug_rx_mbuf_alloc++);
5056 /* Reuse an existing mbuf. */
5060 /* Make sure we have a valid packet header. */
5061 M_ASSERTPKTHDR(m_new);
5063 /* Initialize the mbuf size and pad if necessary for alignment. */
5064 m_new->m_pkthdr.len = m_new->m_len = sc->rx_bd_mbuf_alloc_size;
5065 m_adj(m_new, sc->rx_bd_mbuf_align_pad);
5067 /* ToDo: Consider calling m_fragment() to test error handling. */
5069 /* Map the mbuf cluster into device memory. */
5070 map = sc->rx_mbuf_map[*chain_prod];
5071 error = bus_dmamap_load_mbuf_sg(sc->rx_mbuf_tag, map, m_new,
5072 segs, &nsegs, BUS_DMA_NOWAIT);
5074 /* Handle any mapping errors. */
5076 BCE_PRINTF("%s(%d): Error mapping mbuf into RX "
5077 "chain (%d)!\n", __FILE__, __LINE__, error);
5079 sc->dma_map_addr_rx_failed_count++;
5082 DBRUN(sc->debug_rx_mbuf_alloc--);
5085 goto bce_get_rx_buf_exit;
5088 /* All mbufs must map to a single segment. */
5089 KASSERT(nsegs == 1, ("%s(): Too many segments returned (%d)!",
5090 __FUNCTION__, nsegs));
5092 /* Setup the rx_bd for the segment. */
5093 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
5095 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[0].ds_addr));
5096 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[0].ds_addr));
5097 rxbd->rx_bd_len = htole32(segs[0].ds_len);
5098 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START | RX_BD_FLAGS_END);
5099 *prod_bseq += segs[0].ds_len;
5101 /* Save the mbuf and update our counter. */
5102 sc->rx_mbuf_ptr[*chain_prod] = m_new;
5103 sc->free_rx_bd -= nsegs;
5105 DBRUNMSG(BCE_INSANE_RECV,
5106 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, nsegs));
5108 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): prod = 0x%04X, "
5109 "chain_prod = 0x%04X, prod_bseq = 0x%08X\n",
5110 __FUNCTION__, *prod, *chain_prod, *prod_bseq);
5112 bce_get_rx_buf_exit:
5113 DBEXIT(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5119 #ifdef BCE_JUMBO_HDRSPLIT
5120 /****************************************************************************/
5121 /* Encapsulate an mbuf cluster into the page chain. */
5124 /* 0 for success, positive value for failure. */
5125 /****************************************************************************/
5127 bce_get_pg_buf(struct bce_softc *sc, struct mbuf *m, u16 *prod,
5132 struct mbuf *m_new = NULL;
5136 u16 debug_prod_idx = *prod_idx;
5139 DBENTER(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5141 /* Make sure the inputs are valid. */
5142 DBRUNIF((*prod_idx > MAX_PG_BD),
5143 BCE_PRINTF("%s(%d): page producer out of range: "
5144 "0x%04X > 0x%04X\n", __FILE__, __LINE__,
5145 *prod_idx, (u16) MAX_PG_BD));
5147 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): prod = 0x%04X, "
5148 "chain_prod = 0x%04X\n", __FUNCTION__, *prod, *prod_idx);
5150 /* Update counters if we've hit a new low or run out of pages. */
5151 DBRUNIF((sc->free_pg_bd < sc->pg_low_watermark),
5152 sc->pg_low_watermark = sc->free_pg_bd);
5153 DBRUNIF((sc->free_pg_bd == sc->max_pg_bd), sc->pg_empty_count++);
5155 /* Check whether this is a new mbuf allocation. */
5158 /* Simulate an mbuf allocation failure. */
5159 DBRUNIF(DB_RANDOMTRUE(mbuf_alloc_failed_sim_control),
5160 sc->mbuf_alloc_failed_count++;
5161 sc->mbuf_alloc_failed_sim_count++;
5163 goto bce_get_pg_buf_exit);
5165 /* This is a new mbuf allocation. */
5166 m_new = m_getcl(M_DONTWAIT, MT_DATA, 0);
5167 if (m_new == NULL) {
5168 sc->mbuf_alloc_failed_count++;
5170 goto bce_get_pg_buf_exit;
5173 DBRUN(sc->debug_pg_mbuf_alloc++);
5175 /* Reuse an existing mbuf. */
5177 m_new->m_data = m_new->m_ext.ext_buf;
5180 m_new->m_len = sc->pg_bd_mbuf_alloc_size;
5182 /* ToDo: Consider calling m_fragment() to test error handling. */
5184 /* Map the mbuf cluster into device memory. */
5185 map = sc->pg_mbuf_map[*prod_idx];
5186 error = bus_dmamap_load(sc->pg_mbuf_tag, map, mtod(m_new, void *),
5187 sc->pg_bd_mbuf_alloc_size, bce_dma_map_addr,
5188 &busaddr, BUS_DMA_NOWAIT);
5190 /* Handle any mapping errors. */
5192 BCE_PRINTF("%s(%d): Error mapping mbuf into page chain!\n",
5193 __FILE__, __LINE__);
5196 DBRUN(sc->debug_pg_mbuf_alloc--);
5199 goto bce_get_pg_buf_exit;
5202 /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREREAD) here? */
5205 * The page chain uses the same rx_bd data structure
5206 * as the receive chain but doesn't require a byte sequence (bseq).
5208 pgbd = &sc->pg_bd_chain[PG_PAGE(*prod_idx)][PG_IDX(*prod_idx)];
5210 pgbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(busaddr));
5211 pgbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(busaddr));
5212 pgbd->rx_bd_len = htole32(sc->pg_bd_mbuf_alloc_size);
5213 pgbd->rx_bd_flags = htole32(RX_BD_FLAGS_START | RX_BD_FLAGS_END);
5215 /* Save the mbuf and update our counter. */
5216 sc->pg_mbuf_ptr[*prod_idx] = m_new;
5219 DBRUNMSG(BCE_INSANE_RECV,
5220 bce_dump_pg_mbuf_chain(sc, debug_prod_idx, 1));
5222 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): prod = 0x%04X, "
5223 "prod_idx = 0x%04X\n", __FUNCTION__, *prod, *prod_idx);
5225 bce_get_pg_buf_exit:
5226 DBEXIT(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5230 #endif /* BCE_JUMBO_HDRSPLIT */
5233 /****************************************************************************/
5234 /* Initialize the TX context memory. */
5238 /****************************************************************************/
5240 bce_init_tx_context(struct bce_softc *sc)
5244 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
5246 /* Initialize the context ID for an L2 TX chain. */
5247 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5248 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5249 /* Set the CID type to support an L2 connection. */
5250 val = BCE_L2CTX_TX_TYPE_TYPE_L2_XI |
5251 BCE_L2CTX_TX_TYPE_SIZE_L2_XI;
5252 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
5253 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2_XI | (8 << 16);
5254 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5255 BCE_L2CTX_TX_CMD_TYPE_XI, val);
5257 /* Point the hardware to the first page in the chain. */
5258 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
5259 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5260 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
5261 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
5262 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5263 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
5265 /* Set the CID type to support an L2 connection. */
5266 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
5267 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
5268 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
5269 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
5271 /* Point the hardware to the first page in the chain. */
5272 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
5273 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5274 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
5275 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
5276 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5277 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
5280 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
5284 /****************************************************************************/
5285 /* Allocate memory and initialize the TX data structures. */
5288 /* 0 for success, positive value for failure. */
5289 /****************************************************************************/
5291 bce_init_tx_chain(struct bce_softc *sc)
5296 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_LOAD);
5298 /* Set the initial TX producer/consumer indices. */
5301 sc->tx_prod_bseq = 0;
5303 sc->max_tx_bd = USABLE_TX_BD;
5304 DBRUN(sc->tx_hi_watermark = 0);
5305 DBRUN(sc->tx_full_count = 0);
5308 * The NetXtreme II supports a linked-list structre called
5309 * a Buffer Descriptor Chain (or BD chain). A BD chain
5310 * consists of a series of 1 or more chain pages, each of which
5311 * consists of a fixed number of BD entries.
5312 * The last BD entry on each page is a pointer to the next page
5313 * in the chain, and the last pointer in the BD chain
5314 * points back to the beginning of the chain.
5317 /* Set the TX next pointer chain entries. */
5318 for (i = 0; i < TX_PAGES; i++) {
5321 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
5323 /* Check if we've reached the last page. */
5324 if (i == (TX_PAGES - 1))
5329 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
5330 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
5333 bce_init_tx_context(sc);
5335 DBRUNMSG(BCE_INSANE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD));
5336 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_LOAD);
5342 /****************************************************************************/
5343 /* Free memory and clear the TX data structures. */
5347 /****************************************************************************/
5349 bce_free_tx_chain(struct bce_softc *sc)
5353 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_UNLOAD);
5355 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
5356 for (i = 0; i < TOTAL_TX_BD; i++) {
5357 if (sc->tx_mbuf_ptr[i] != NULL) {
5358 if (sc->tx_mbuf_map[i] != NULL)
5359 bus_dmamap_sync(sc->tx_mbuf_tag,
5361 BUS_DMASYNC_POSTWRITE);
5362 m_freem(sc->tx_mbuf_ptr[i]);
5363 sc->tx_mbuf_ptr[i] = NULL;
5364 DBRUN(sc->debug_tx_mbuf_alloc--);
5368 /* Clear each TX chain page. */
5369 for (i = 0; i < TX_PAGES; i++)
5370 bzero((char *)sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
5374 /* Check if we lost any mbufs in the process. */
5375 DBRUNIF((sc->debug_tx_mbuf_alloc),
5376 BCE_PRINTF("%s(%d): Memory leak! Lost %d mbufs "
5377 "from tx chain!\n", __FILE__, __LINE__,
5378 sc->debug_tx_mbuf_alloc));
5380 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_UNLOAD);
5384 /****************************************************************************/
5385 /* Initialize the RX context memory. */
5389 /****************************************************************************/
5391 bce_init_rx_context(struct bce_softc *sc)
5395 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_CTX);
5397 /* Init the type, size, and BD cache levels for the RX context. */
5398 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
5399 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 |
5400 (0x02 << BCE_L2CTX_RX_BD_PRE_READ_SHIFT);
5403 * Set the level for generating pause frames
5404 * when the number of available rx_bd's gets
5405 * too low (the low watermark) and the level
5406 * when pause frames can be stopped (the high
5409 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5410 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5411 u32 lo_water, hi_water;
5413 if (sc->bce_flags && BCE_USING_TX_FLOW_CONTROL) {
5414 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
5419 if (lo_water >= USABLE_RX_BD) {
5423 hi_water = USABLE_RX_BD / 4;
5425 if (hi_water <= lo_water) {
5429 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
5430 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
5434 else if (hi_water == 0)
5437 val |= (lo_water << BCE_L2CTX_RX_LO_WATER_MARK_SHIFT) |
5438 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
5441 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
5443 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
5444 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5445 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5446 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
5447 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
5450 /* Point the hardware to the first page in the chain. */
5451 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
5452 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
5453 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
5454 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
5456 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_CTX);
5460 /****************************************************************************/
5461 /* Allocate memory and initialize the RX data structures. */
5464 /* 0 for success, positive value for failure. */
5465 /****************************************************************************/
5467 bce_init_rx_chain(struct bce_softc *sc)
5472 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5475 /* Initialize the RX producer and consumer indices. */
5478 sc->rx_prod_bseq = 0;
5479 sc->free_rx_bd = USABLE_RX_BD;
5480 sc->max_rx_bd = USABLE_RX_BD;
5482 /* Initialize the RX next pointer chain entries. */
5483 for (i = 0; i < RX_PAGES; i++) {
5486 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
5488 /* Check if we've reached the last page. */
5489 if (i == (RX_PAGES - 1))
5494 /* Setup the chain page pointers. */
5495 rxbd->rx_bd_haddr_hi =
5496 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
5497 rxbd->rx_bd_haddr_lo =
5498 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
5501 /* Fill up the RX chain. */
5502 bce_fill_rx_chain(sc);
5504 DBRUN(sc->rx_low_watermark = USABLE_RX_BD);
5505 DBRUN(sc->rx_empty_count = 0);
5506 for (i = 0; i < RX_PAGES; i++) {
5507 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
5508 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
5511 bce_init_rx_context(sc);
5513 DBRUNMSG(BCE_EXTREME_RECV, bce_dump_rx_bd_chain(sc, 0, TOTAL_RX_BD));
5514 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5517 /* ToDo: Are there possible failure modes here? */
5523 /****************************************************************************/
5524 /* Add mbufs to the RX chain until its full or an mbuf allocation error */
5529 /****************************************************************************/
5531 bce_fill_rx_chain(struct bce_softc *sc)
5536 DBENTER(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5539 /* Get the RX chain producer indices. */
5541 prod_bseq = sc->rx_prod_bseq;
5543 /* Keep filling the RX chain until it's full. */
5544 while (sc->free_rx_bd > 0) {
5545 prod_idx = RX_CHAIN_IDX(prod);
5546 if (bce_get_rx_buf(sc, NULL, &prod, &prod_idx, &prod_bseq)) {
5547 /* Bail out if we can't add an mbuf to the chain. */
5550 prod = NEXT_RX_BD(prod);
5553 /* Save the RX chain producer indices. */
5555 sc->rx_prod_bseq = prod_bseq;
5557 /* We should never end up pointing to a next page pointer. */
5558 DBRUNIF(((prod & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE),
5559 BCE_PRINTF("%s(): Invalid rx_prod value: 0x%04X\n",
5560 __FUNCTION__, sc->rx_prod));
5562 /* Write the mailbox and tell the chip about the waiting rx_bd's. */
5563 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) +
5564 BCE_L2MQ_RX_HOST_BDIDX, sc->rx_prod);
5565 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) +
5566 BCE_L2MQ_RX_HOST_BSEQ, sc->rx_prod_bseq);
5568 DBEXIT(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5573 /****************************************************************************/
5574 /* Free memory and clear the RX data structures. */
5578 /****************************************************************************/
5580 bce_free_rx_chain(struct bce_softc *sc)
5584 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5586 /* Free any mbufs still in the RX mbuf chain. */
5587 for (i = 0; i < TOTAL_RX_BD; i++) {
5588 if (sc->rx_mbuf_ptr[i] != NULL) {
5589 if (sc->rx_mbuf_map[i] != NULL)
5590 bus_dmamap_sync(sc->rx_mbuf_tag,
5592 BUS_DMASYNC_POSTREAD);
5593 m_freem(sc->rx_mbuf_ptr[i]);
5594 sc->rx_mbuf_ptr[i] = NULL;
5595 DBRUN(sc->debug_rx_mbuf_alloc--);
5599 /* Clear each RX chain page. */
5600 for (i = 0; i < RX_PAGES; i++)
5601 if (sc->rx_bd_chain[i] != NULL) {
5602 bzero((char *)sc->rx_bd_chain[i],
5603 BCE_RX_CHAIN_PAGE_SZ);
5606 sc->free_rx_bd = sc->max_rx_bd;
5608 /* Check if we lost any mbufs in the process. */
5609 DBRUNIF((sc->debug_rx_mbuf_alloc),
5610 BCE_PRINTF("%s(): Memory leak! Lost %d mbufs from rx chain!\n",
5611 __FUNCTION__, sc->debug_rx_mbuf_alloc));
5613 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5617 #ifdef BCE_JUMBO_HDRSPLIT
5618 /****************************************************************************/
5619 /* Allocate memory and initialize the page data structures. */
5620 /* Assumes that bce_init_rx_chain() has not already been called. */
5623 /* 0 for success, positive value for failure. */
5624 /****************************************************************************/
5626 bce_init_pg_chain(struct bce_softc *sc)
5632 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5635 /* Initialize the page producer and consumer indices. */
5638 sc->free_pg_bd = USABLE_PG_BD;
5639 sc->max_pg_bd = USABLE_PG_BD;
5640 DBRUN(sc->pg_low_watermark = sc->max_pg_bd);
5641 DBRUN(sc->pg_empty_count = 0);
5643 /* Initialize the page next pointer chain entries. */
5644 for (i = 0; i < PG_PAGES; i++) {
5647 pgbd = &sc->pg_bd_chain[i][USABLE_PG_BD_PER_PAGE];
5649 /* Check if we've reached the last page. */
5650 if (i == (PG_PAGES - 1))
5655 /* Setup the chain page pointers. */
5656 pgbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(sc->pg_bd_chain_paddr[j]));
5657 pgbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(sc->pg_bd_chain_paddr[j]));
5660 /* Setup the MQ BIN mapping for host_pg_bidx. */
5661 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5662 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
5663 REG_WR(sc, BCE_MQ_MAP_L2_3, BCE_MQ_MAP_L2_3_DEFAULT);
5665 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_PG_BUF_SIZE, 0);
5667 /* Configure the rx_bd and page chain mbuf cluster size. */
5668 val = (sc->rx_bd_mbuf_data_len << 16) | sc->pg_bd_mbuf_alloc_size;
5669 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_PG_BUF_SIZE, val);
5671 /* Configure the context reserved for jumbo support. */
5672 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_RBDC_KEY,
5673 BCE_L2CTX_RX_RBDC_JUMBO_KEY);
5675 /* Point the hardware to the first page in the page chain. */
5676 val = BCE_ADDR_HI(sc->pg_bd_chain_paddr[0]);
5677 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_PG_BDHADDR_HI, val);
5678 val = BCE_ADDR_LO(sc->pg_bd_chain_paddr[0]);
5679 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_PG_BDHADDR_LO, val);
5681 /* Fill up the page chain. */
5682 bce_fill_pg_chain(sc);
5684 for (i = 0; i < PG_PAGES; i++) {
5685 bus_dmamap_sync(sc->pg_bd_chain_tag, sc->pg_bd_chain_map[i],
5686 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
5689 DBRUNMSG(BCE_EXTREME_RECV, bce_dump_pg_chain(sc, 0, TOTAL_PG_BD));
5690 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5696 /****************************************************************************/
5697 /* Add mbufs to the page chain until its full or an mbuf allocation error */
5702 /****************************************************************************/
5704 bce_fill_pg_chain(struct bce_softc *sc)
5708 DBENTER(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5711 /* Get the page chain prodcuer index. */
5714 /* Keep filling the page chain until it's full. */
5715 while (sc->free_pg_bd > 0) {
5716 prod_idx = PG_CHAIN_IDX(prod);
5717 if (bce_get_pg_buf(sc, NULL, &prod, &prod_idx)) {
5718 /* Bail out if we can't add an mbuf to the chain. */
5721 prod = NEXT_PG_BD(prod);
5724 /* Save the page chain producer index. */
5727 DBRUNIF(((prod & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE),
5728 BCE_PRINTF("%s(): Invalid pg_prod value: 0x%04X\n",
5729 __FUNCTION__, sc->pg_prod));
5732 * Write the mailbox and tell the chip about
5733 * the new rx_bd's in the page chain.
5735 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) +
5736 BCE_L2MQ_RX_HOST_PG_BDIDX, sc->pg_prod);
5738 DBEXIT(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5743 /****************************************************************************/
5744 /* Free memory and clear the RX data structures. */
5748 /****************************************************************************/
5750 bce_free_pg_chain(struct bce_softc *sc)
5754 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5756 /* Free any mbufs still in the mbuf page chain. */
5757 for (i = 0; i < TOTAL_PG_BD; i++) {
5758 if (sc->pg_mbuf_ptr[i] != NULL) {
5759 if (sc->pg_mbuf_map[i] != NULL)
5760 bus_dmamap_sync(sc->pg_mbuf_tag,
5762 BUS_DMASYNC_POSTREAD);
5763 m_freem(sc->pg_mbuf_ptr[i]);
5764 sc->pg_mbuf_ptr[i] = NULL;
5765 DBRUN(sc->debug_pg_mbuf_alloc--);
5769 /* Clear each page chain pages. */
5770 for (i = 0; i < PG_PAGES; i++)
5771 bzero((char *)sc->pg_bd_chain[i], BCE_PG_CHAIN_PAGE_SZ);
5773 sc->free_pg_bd = sc->max_pg_bd;
5775 /* Check if we lost any mbufs in the process. */
5776 DBRUNIF((sc->debug_pg_mbuf_alloc),
5777 BCE_PRINTF("%s(): Memory leak! Lost %d mbufs from page chain!\n",
5778 __FUNCTION__, sc->debug_pg_mbuf_alloc));
5780 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5782 #endif /* BCE_JUMBO_HDRSPLIT */
5785 /****************************************************************************/
5786 /* Set media options. */
5789 /* 0 for success, positive value for failure. */
5790 /****************************************************************************/
5792 bce_ifmedia_upd(struct ifnet *ifp)
5794 struct bce_softc *sc = ifp->if_softc;
5797 DBENTER(BCE_VERBOSE);
5800 error = bce_ifmedia_upd_locked(ifp);
5803 DBEXIT(BCE_VERBOSE);
5808 /****************************************************************************/
5809 /* Set media options. */
5813 /****************************************************************************/
5815 bce_ifmedia_upd_locked(struct ifnet *ifp)
5817 struct bce_softc *sc = ifp->if_softc;
5818 struct mii_data *mii;
5821 DBENTER(BCE_VERBOSE_PHY);
5824 BCE_LOCK_ASSERT(sc);
5826 mii = device_get_softc(sc->bce_miibus);
5828 /* Make sure the MII bus has been enumerated. */
5830 sc->bce_link_up = FALSE;
5831 if (mii->mii_instance) {
5832 struct mii_softc *miisc;
5834 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
5835 mii_phy_reset(miisc);
5837 error = mii_mediachg(mii);
5840 DBEXIT(BCE_VERBOSE_PHY);
5845 /****************************************************************************/
5846 /* Reports current media status. */
5850 /****************************************************************************/
5852 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
5854 struct bce_softc *sc = ifp->if_softc;
5855 struct mii_data *mii;
5857 DBENTER(BCE_VERBOSE_PHY);
5861 mii = device_get_softc(sc->bce_miibus);
5864 ifmr->ifm_active = mii->mii_media_active;
5865 ifmr->ifm_status = mii->mii_media_status;
5869 DBEXIT(BCE_VERBOSE_PHY);
5873 /****************************************************************************/
5874 /* Handles PHY generated interrupt events. */
5878 /****************************************************************************/
5880 bce_phy_intr(struct bce_softc *sc)
5882 u32 new_link_state, old_link_state;
5884 DBENTER(BCE_VERBOSE_PHY | BCE_VERBOSE_INTR);
5886 DBRUN(sc->phy_interrupts++);
5888 new_link_state = sc->status_block->status_attn_bits &
5889 STATUS_ATTN_BITS_LINK_STATE;
5890 old_link_state = sc->status_block->status_attn_bits_ack &
5891 STATUS_ATTN_BITS_LINK_STATE;
5893 /* Handle any changes if the link state has changed. */
5894 if (new_link_state != old_link_state) {
5896 /* Update the status_attn_bits_ack field. */
5897 if (new_link_state) {
5898 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
5899 STATUS_ATTN_BITS_LINK_STATE);
5900 DBPRINT(sc, BCE_INFO_PHY, "%s(): Link is now UP.\n",
5904 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
5905 STATUS_ATTN_BITS_LINK_STATE);
5906 DBPRINT(sc, BCE_INFO_PHY, "%s(): Link is now DOWN.\n",
5911 * Assume link is down and allow
5912 * tick routine to update the state
5913 * based on the actual media state.
5915 sc->bce_link_up = FALSE;
5916 callout_stop(&sc->bce_tick_callout);
5920 /* Acknowledge the link change interrupt. */
5921 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
5923 DBEXIT(BCE_VERBOSE_PHY | BCE_VERBOSE_INTR);
5927 /****************************************************************************/
5928 /* Reads the receive consumer value from the status block (skipping over */
5929 /* chain page pointer if necessary). */
5933 /****************************************************************************/
5935 bce_get_hw_rx_cons(struct bce_softc *sc)
5940 hw_cons = sc->status_block->status_rx_quick_consumer_index0;
5941 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
5947 /****************************************************************************/
5948 /* Handles received frame interrupt events. */
5952 /****************************************************************************/
5954 bce_rx_intr(struct bce_softc *sc)
5956 struct ifnet *ifp = sc->bce_ifp;
5957 struct l2_fhdr *l2fhdr;
5958 struct ether_vlan_header *vh;
5959 unsigned int pkt_len;
5960 u16 sw_rx_cons, sw_rx_cons_idx, hw_rx_cons;
5962 #ifdef BCE_JUMBO_HDRSPLIT
5963 unsigned int rem_len;
5964 u16 sw_pg_cons, sw_pg_cons_idx;
5967 DBENTER(BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
5968 DBRUN(sc->interrupts_rx++);
5969 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): rx_prod = 0x%04X, "
5970 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
5971 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
5973 /* Prepare the RX chain pages to be accessed by the host CPU. */
5974 for (int i = 0; i < RX_PAGES; i++)
5975 bus_dmamap_sync(sc->rx_bd_chain_tag,
5976 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
5978 #ifdef BCE_JUMBO_HDRSPLIT
5979 /* Prepare the page chain pages to be accessed by the host CPU. */
5980 for (int i = 0; i < PG_PAGES; i++)
5981 bus_dmamap_sync(sc->pg_bd_chain_tag,
5982 sc->pg_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
5985 /* Get the hardware's view of the RX consumer index. */
5986 hw_rx_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
5988 /* Get working copies of the driver's view of the consumer indices. */
5989 sw_rx_cons = sc->rx_cons;
5991 #ifdef BCE_JUMBO_HDRSPLIT
5992 sw_pg_cons = sc->pg_cons;
5995 /* Update some debug statistics counters */
5996 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
5997 sc->rx_low_watermark = sc->free_rx_bd);
5998 DBRUNIF((sc->free_rx_bd == sc->max_rx_bd),
5999 sc->rx_empty_count++);
6001 /* Scan through the receive chain as long as there is work to do */
6002 /* ToDo: Consider setting a limit on the number of packets processed. */
6004 while (sw_rx_cons != hw_rx_cons) {
6007 /* Convert the producer/consumer indices to an actual rx_bd index. */
6008 sw_rx_cons_idx = RX_CHAIN_IDX(sw_rx_cons);
6010 /* Unmap the mbuf from DMA space. */
6011 bus_dmamap_sync(sc->rx_mbuf_tag,
6012 sc->rx_mbuf_map[sw_rx_cons_idx],
6013 BUS_DMASYNC_POSTREAD);
6014 bus_dmamap_unload(sc->rx_mbuf_tag,
6015 sc->rx_mbuf_map[sw_rx_cons_idx]);
6017 /* Remove the mbuf from the RX chain. */
6018 m0 = sc->rx_mbuf_ptr[sw_rx_cons_idx];
6019 sc->rx_mbuf_ptr[sw_rx_cons_idx] = NULL;
6020 DBRUN(sc->debug_rx_mbuf_alloc--);
6024 DBPRINT(sc, BCE_EXTREME_RECV,
6025 "%s(): Oops! Empty mbuf pointer "
6026 "found in sc->rx_mbuf_ptr[0x%04X]!\n",
6027 __FUNCTION__, sw_rx_cons_idx);
6028 goto bce_rx_int_next_rx;
6032 * Frames received on the NetXteme II are prepended
6033 * with an l2_fhdr structure which provides status
6034 * information about the received frame (including
6035 * VLAN tags and checksum info). The frames are
6036 * also automatically adjusted to align the IP
6037 * header (i.e. two null bytes are inserted before
6038 * the Ethernet header). As a result the data
6039 * DMA'd by the controller into the mbuf looks
6042 * +---------+-----+---------------------+-----+
6043 * | l2_fhdr | pad | packet data | FCS |
6044 * +---------+-----+---------------------+-----+
6046 * The l2_fhdr needs to be checked and skipped and
6047 * the FCS needs to be stripped before sending the
6048 * packet up the stack.
6050 l2fhdr = mtod(m0, struct l2_fhdr *);
6052 /* Get the packet data + FCS length and the status. */
6053 pkt_len = l2fhdr->l2_fhdr_pkt_len;
6054 status = l2fhdr->l2_fhdr_status;
6057 * Skip over the l2_fhdr and pad, resulting in the
6058 * following data in the mbuf:
6059 * +---------------------+-----+
6060 * | packet data | FCS |
6061 * +---------------------+-----+
6063 m_adj(m0, sizeof(struct l2_fhdr) + ETHER_ALIGN);
6065 #ifdef BCE_JUMBO_HDRSPLIT
6067 * Check whether the received frame fits in a single
6068 * mbuf or not (i.e. packet data + FCS <=
6069 * sc->rx_bd_mbuf_data_len bytes).
6071 if (pkt_len > m0->m_len) {
6073 * The received frame is larger than a single mbuf.
6074 * If the frame was a TCP frame then only the TCP
6075 * header is placed in the mbuf, the remaining
6076 * payload (including FCS) is placed in the page
6077 * chain, the SPLIT flag is set, and the header
6078 * length is placed in the IP checksum field.
6079 * If the frame is not a TCP frame then the mbuf
6080 * is filled and the remaining bytes are placed
6081 * in the page chain.
6084 DBPRINT(sc, BCE_INFO_RECV, "%s(): Found a large "
6085 "packet.\n", __FUNCTION__);
6088 * When the page chain is enabled and the TCP
6089 * header has been split from the TCP payload,
6090 * the ip_xsum structure will reflect the length
6091 * of the TCP header, not the IP checksum. Set
6092 * the packet length of the mbuf accordingly.
6094 if (status & L2_FHDR_STATUS_SPLIT)
6095 m0->m_len = l2fhdr->l2_fhdr_ip_xsum;
6097 rem_len = pkt_len - m0->m_len;
6099 /* Pull mbufs off the page chain for the remaining data. */
6100 while (rem_len > 0) {
6103 sw_pg_cons_idx = PG_CHAIN_IDX(sw_pg_cons);
6105 /* Remove the mbuf from the page chain. */
6106 m_pg = sc->pg_mbuf_ptr[sw_pg_cons_idx];
6107 sc->pg_mbuf_ptr[sw_pg_cons_idx] = NULL;
6108 DBRUN(sc->debug_pg_mbuf_alloc--);
6111 /* Unmap the page chain mbuf from DMA space. */
6112 bus_dmamap_sync(sc->pg_mbuf_tag,
6113 sc->pg_mbuf_map[sw_pg_cons_idx],
6114 BUS_DMASYNC_POSTREAD);
6115 bus_dmamap_unload(sc->pg_mbuf_tag,
6116 sc->pg_mbuf_map[sw_pg_cons_idx]);
6118 /* Adjust the mbuf length. */
6119 if (rem_len < m_pg->m_len) {
6120 /* The mbuf chain is complete. */
6121 m_pg->m_len = rem_len;
6124 /* More packet data is waiting. */
6125 rem_len -= m_pg->m_len;
6128 /* Concatenate the mbuf cluster to the mbuf. */
6131 sw_pg_cons = NEXT_PG_BD(sw_pg_cons);
6134 /* Set the total packet length. */
6135 m0->m_pkthdr.len = pkt_len;
6139 * The received packet is small and fits in a
6140 * single mbuf (i.e. the l2_fhdr + pad + packet +
6141 * FCS <= MHLEN). In other words, the packet is
6142 * 154 bytes or less in size.
6145 DBPRINT(sc, BCE_INFO_RECV, "%s(): Found a small "
6146 "packet.\n", __FUNCTION__);
6148 /* Set the total packet length. */
6149 m0->m_pkthdr.len = m0->m_len = pkt_len;
6152 /* Set the total packet length. */
6153 m0->m_pkthdr.len = m0->m_len = pkt_len;
6156 /* Remove the trailing Ethernet FCS. */
6157 m_adj(m0, -ETHER_CRC_LEN);
6159 /* Check that the resulting mbuf chain is valid. */
6160 DBRUN(m_sanity(m0, FALSE));
6161 DBRUNIF(((m0->m_len < ETHER_HDR_LEN) |
6162 (m0->m_pkthdr.len > BCE_MAX_JUMBO_ETHER_MTU_VLAN)),
6163 BCE_PRINTF("Invalid Ethernet frame size!\n");
6166 DBRUNIF(DB_RANDOMTRUE(l2fhdr_error_sim_control),
6167 sc->l2fhdr_error_sim_count++;
6168 status = status | L2_FHDR_ERRORS_PHY_DECODE);
6170 /* Check the received frame for errors. */
6171 if (status & (L2_FHDR_ERRORS_BAD_CRC |
6172 L2_FHDR_ERRORS_PHY_DECODE | L2_FHDR_ERRORS_ALIGNMENT |
6173 L2_FHDR_ERRORS_TOO_SHORT | L2_FHDR_ERRORS_GIANT_FRAME)) {
6175 /* Log the error and release the mbuf. */
6177 sc->l2fhdr_error_count++;
6181 goto bce_rx_int_next_rx;
6184 /* Send the packet to the appropriate interface. */
6185 m0->m_pkthdr.rcvif = ifp;
6187 /* Assume no hardware checksum. */
6188 m0->m_pkthdr.csum_flags = 0;
6190 /* Validate the checksum if offload enabled. */
6191 if (ifp->if_capenable & IFCAP_RXCSUM) {
6193 /* Check for an IP datagram. */
6194 if (!(status & L2_FHDR_STATUS_SPLIT) &&
6195 (status & L2_FHDR_STATUS_IP_DATAGRAM)) {
6196 m0->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
6197 DBRUN(sc->csum_offload_ip++);
6198 /* Check if the IP checksum is valid. */
6199 if ((l2fhdr->l2_fhdr_ip_xsum ^ 0xffff) == 0)
6200 m0->m_pkthdr.csum_flags |=
6204 /* Check for a valid TCP/UDP frame. */
6205 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
6206 L2_FHDR_STATUS_UDP_DATAGRAM)) {
6208 /* Check for a good TCP/UDP checksum. */
6209 if ((status & (L2_FHDR_ERRORS_TCP_XSUM |
6210 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
6211 DBRUN(sc->csum_offload_tcp_udp++);
6212 m0->m_pkthdr.csum_data =
6213 l2fhdr->l2_fhdr_tcp_udp_xsum;
6214 m0->m_pkthdr.csum_flags |=
6221 /* Attach the VLAN tag. */
6222 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
6223 if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) {
6224 #if __FreeBSD_version < 700000
6225 VLAN_INPUT_TAG(ifp, m0,
6226 l2fhdr->l2_fhdr_vlan_tag, continue);
6228 m0->m_pkthdr.ether_vtag =
6229 l2fhdr->l2_fhdr_vlan_tag;
6230 m0->m_flags |= M_VLANTAG;
6234 * bce(4) controllers can't disable VLAN
6235 * tag stripping if management firmware
6236 * (ASF/IPMI/UMP) is running. So we always
6237 * strip VLAN tag and manually reconstruct
6238 * the VLAN frame by appending stripped
6239 * VLAN tag in driver if VLAN tag stripping
6242 * TODO: LLC SNAP handling.
6244 bcopy(mtod(m0, uint8_t *),
6245 mtod(m0, uint8_t *) - ETHER_VLAN_ENCAP_LEN,
6246 ETHER_ADDR_LEN * 2);
6247 m0->m_data -= ETHER_VLAN_ENCAP_LEN;
6248 vh = mtod(m0, struct ether_vlan_header *);
6249 vh->evl_encap_proto = htons(ETHERTYPE_VLAN);
6250 vh->evl_tag = htons(l2fhdr->l2_fhdr_vlan_tag);
6251 m0->m_pkthdr.len += ETHER_VLAN_ENCAP_LEN;
6252 m0->m_len += ETHER_VLAN_ENCAP_LEN;
6256 /* Increment received packet statistics. */
6260 sw_rx_cons = NEXT_RX_BD(sw_rx_cons);
6262 /* If we have a packet, pass it up the stack */
6264 /* Make sure we don't lose our place when we release the lock. */
6265 sc->rx_cons = sw_rx_cons;
6266 #ifdef BCE_JUMBO_HDRSPLIT
6267 sc->pg_cons = sw_pg_cons;
6271 (*ifp->if_input)(ifp, m0);
6274 /* Recover our place. */
6275 sw_rx_cons = sc->rx_cons;
6276 #ifdef BCE_JUMBO_HDRSPLIT
6277 sw_pg_cons = sc->pg_cons;
6281 /* Refresh hw_cons to see if there's new work */
6282 if (sw_rx_cons == hw_rx_cons)
6283 hw_rx_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
6286 #ifdef BCE_JUMBO_HDRSPLIT
6287 /* No new packets. Refill the page chain. */
6288 sc->pg_cons = sw_pg_cons;
6289 bce_fill_pg_chain(sc);
6292 /* No new packets. Refill the RX chain. */
6293 sc->rx_cons = sw_rx_cons;
6294 bce_fill_rx_chain(sc);
6296 /* Prepare the page chain pages to be accessed by the NIC. */
6297 for (int i = 0; i < RX_PAGES; i++)
6298 bus_dmamap_sync(sc->rx_bd_chain_tag,
6299 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
6301 #ifdef BCE_JUMBO_HDRSPLIT
6302 for (int i = 0; i < PG_PAGES; i++)
6303 bus_dmamap_sync(sc->pg_bd_chain_tag,
6304 sc->pg_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
6307 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): rx_prod = 0x%04X, "
6308 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
6309 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
6310 DBEXIT(BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
6314 /****************************************************************************/
6315 /* Reads the transmit consumer value from the status block (skipping over */
6316 /* chain page pointer if necessary). */
6320 /****************************************************************************/
6322 bce_get_hw_tx_cons(struct bce_softc *sc)
6327 hw_cons = sc->status_block->status_tx_quick_consumer_index0;
6328 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
6335 /****************************************************************************/
6336 /* Handles transmit completion interrupt events. */
6340 /****************************************************************************/
6342 bce_tx_intr(struct bce_softc *sc)
6344 struct ifnet *ifp = sc->bce_ifp;
6345 u16 hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
6347 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_INTR);
6348 DBRUN(sc->interrupts_tx++);
6349 DBPRINT(sc, BCE_EXTREME_SEND, "%s(enter): tx_prod = 0x%04X, "
6350 "tx_cons = 0x%04X, tx_prod_bseq = 0x%08X\n",
6351 __FUNCTION__, sc->tx_prod, sc->tx_cons, sc->tx_prod_bseq);
6353 BCE_LOCK_ASSERT(sc);
6355 /* Get the hardware's view of the TX consumer index. */
6356 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
6357 sw_tx_cons = sc->tx_cons;
6359 /* Prevent speculative reads of the status block. */
6360 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
6361 BUS_SPACE_BARRIER_READ);
6363 /* Cycle through any completed TX chain page entries. */
6364 while (sw_tx_cons != hw_tx_cons) {
6366 struct tx_bd *txbd = NULL;
6368 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
6370 DBPRINT(sc, BCE_INFO_SEND,
6371 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
6372 "sw_tx_chain_cons = 0x%04X\n",
6373 __FUNCTION__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
6375 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
6376 BCE_PRINTF("%s(%d): TX chain consumer out of range! "
6377 " 0x%04X > 0x%04X\n", __FILE__, __LINE__, sw_tx_chain_cons,
6379 bce_breakpoint(sc));
6381 DBRUN(txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
6382 [TX_IDX(sw_tx_chain_cons)]);
6384 DBRUNIF((txbd == NULL),
6385 BCE_PRINTF("%s(%d): Unexpected NULL tx_bd[0x%04X]!\n",
6386 __FILE__, __LINE__, sw_tx_chain_cons);
6387 bce_breakpoint(sc));
6389 DBRUNMSG(BCE_INFO_SEND, BCE_PRINTF("%s(): ", __FUNCTION__);
6390 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
6393 * Free the associated mbuf. Remember
6394 * that only the last tx_bd of a packet
6395 * has an mbuf pointer and DMA map.
6397 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
6399 /* Validate that this is the last tx_bd. */
6400 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
6401 BCE_PRINTF("%s(%d): tx_bd END flag not set but "
6402 "txmbuf == NULL!\n", __FILE__, __LINE__);
6403 bce_breakpoint(sc));
6405 DBRUNMSG(BCE_INFO_SEND,
6406 BCE_PRINTF("%s(): Unloading map/freeing mbuf "
6407 "from tx_bd[0x%04X]\n", __FUNCTION__,
6410 /* Unmap the mbuf. */
6411 bus_dmamap_unload(sc->tx_mbuf_tag,
6412 sc->tx_mbuf_map[sw_tx_chain_cons]);
6414 /* Free the mbuf. */
6415 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
6416 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
6417 DBRUN(sc->debug_tx_mbuf_alloc--);
6423 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
6425 /* Refresh hw_cons to see if there's new work. */
6426 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
6428 /* Prevent speculative reads of the status block. */
6429 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
6430 BUS_SPACE_BARRIER_READ);
6433 /* Clear the TX timeout timer. */
6434 sc->watchdog_timer = 0;
6436 /* Clear the tx hardware queue full flag. */
6437 if (sc->used_tx_bd < sc->max_tx_bd) {
6438 DBRUNIF((ifp->if_drv_flags & IFF_DRV_OACTIVE),
6439 DBPRINT(sc, BCE_INFO_SEND,
6440 "%s(): Open TX chain! %d/%d (used/total)\n",
6441 __FUNCTION__, sc->used_tx_bd, sc->max_tx_bd));
6442 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
6445 sc->tx_cons = sw_tx_cons;
6447 DBPRINT(sc, BCE_EXTREME_SEND, "%s(exit): tx_prod = 0x%04X, "
6448 "tx_cons = 0x%04X, tx_prod_bseq = 0x%08X\n",
6449 __FUNCTION__, sc->tx_prod, sc->tx_cons, sc->tx_prod_bseq);
6450 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_INTR);
6454 /****************************************************************************/
6455 /* Disables interrupt generation. */
6459 /****************************************************************************/
6461 bce_disable_intr(struct bce_softc *sc)
6463 DBENTER(BCE_VERBOSE_INTR);
6465 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
6466 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
6468 DBEXIT(BCE_VERBOSE_INTR);
6472 /****************************************************************************/
6473 /* Enables interrupt generation. */
6477 /****************************************************************************/
6479 bce_enable_intr(struct bce_softc *sc, int coal_now)
6481 DBENTER(BCE_VERBOSE_INTR);
6483 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
6484 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
6485 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
6487 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
6488 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
6490 /* Force an immediate interrupt (whether there is new data or not). */
6492 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
6494 DBEXIT(BCE_VERBOSE_INTR);
6498 /****************************************************************************/
6499 /* Handles controller initialization. */
6503 /****************************************************************************/
6505 bce_init_locked(struct bce_softc *sc)
6510 DBENTER(BCE_VERBOSE_RESET);
6512 BCE_LOCK_ASSERT(sc);
6516 /* Check if the driver is still running and bail out if it is. */
6517 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
6518 goto bce_init_locked_exit;
6522 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
6523 BCE_PRINTF("%s(%d): Controller reset failed!\n",
6524 __FILE__, __LINE__);
6525 goto bce_init_locked_exit;
6528 if (bce_chipinit(sc)) {
6529 BCE_PRINTF("%s(%d): Controller initialization failed!\n",
6530 __FILE__, __LINE__);
6531 goto bce_init_locked_exit;
6534 if (bce_blockinit(sc)) {
6535 BCE_PRINTF("%s(%d): Block initialization failed!\n",
6536 __FILE__, __LINE__);
6537 goto bce_init_locked_exit;
6540 /* Load our MAC address. */
6541 bcopy(IF_LLADDR(sc->bce_ifp), sc->eaddr, ETHER_ADDR_LEN);
6542 bce_set_mac_addr(sc);
6545 * Calculate and program the hardware Ethernet MTU
6546 * size. Be generous on the receive if we have room.
6548 #ifdef BCE_JUMBO_HDRSPLIT
6549 if (ifp->if_mtu <= (sc->rx_bd_mbuf_data_len +
6550 sc->pg_bd_mbuf_alloc_size))
6551 ether_mtu = sc->rx_bd_mbuf_data_len +
6552 sc->pg_bd_mbuf_alloc_size;
6554 if (ifp->if_mtu <= sc->rx_bd_mbuf_data_len)
6555 ether_mtu = sc->rx_bd_mbuf_data_len;
6558 ether_mtu = ifp->if_mtu;
6560 ether_mtu += ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + ETHER_CRC_LEN;
6562 DBPRINT(sc, BCE_INFO_MISC, "%s(): setting h/w mtu = %d\n",
6563 __FUNCTION__, ether_mtu);
6565 /* Program the mtu, enabling jumbo frame support if necessary. */
6566 if (ether_mtu > (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN))
6567 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
6568 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
6569 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
6571 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
6573 DBPRINT(sc, BCE_INFO_LOAD,
6574 "%s(): rx_bd_mbuf_alloc_size = %d, rx_bce_mbuf_data_len = %d, "
6575 "rx_bd_mbuf_align_pad = %d\n", __FUNCTION__,
6576 sc->rx_bd_mbuf_alloc_size, sc->rx_bd_mbuf_data_len,
6577 sc->rx_bd_mbuf_align_pad);
6579 /* Program appropriate promiscuous/multicast filtering. */
6580 bce_set_rx_mode(sc);
6582 #ifdef BCE_JUMBO_HDRSPLIT
6583 DBPRINT(sc, BCE_INFO_LOAD, "%s(): pg_bd_mbuf_alloc_size = %d\n",
6584 __FUNCTION__, sc->pg_bd_mbuf_alloc_size);
6586 /* Init page buffer descriptor chain. */
6587 bce_init_pg_chain(sc);
6590 /* Init RX buffer descriptor chain. */
6591 bce_init_rx_chain(sc);
6593 /* Init TX buffer descriptor chain. */
6594 bce_init_tx_chain(sc);
6596 /* Enable host interrupts. */
6597 bce_enable_intr(sc, 1);
6599 bce_ifmedia_upd_locked(ifp);
6601 /* Let the OS know the driver is up and running. */
6602 ifp->if_drv_flags |= IFF_DRV_RUNNING;
6603 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
6605 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
6607 bce_init_locked_exit:
6608 DBEXIT(BCE_VERBOSE_RESET);
6612 /****************************************************************************/
6613 /* Initialize the controller just enough so that any management firmware */
6614 /* running on the device will continue to operate correctly. */
6618 /****************************************************************************/
6620 bce_mgmt_init_locked(struct bce_softc *sc)
6624 DBENTER(BCE_VERBOSE_RESET);
6626 BCE_LOCK_ASSERT(sc);
6628 /* Bail out if management firmware is not running. */
6629 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)) {
6630 DBPRINT(sc, BCE_VERBOSE_SPECIAL,
6631 "No management firmware running...\n");
6632 goto bce_mgmt_init_locked_exit;
6637 /* Enable all critical blocks in the MAC. */
6638 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
6639 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
6642 bce_ifmedia_upd_locked(ifp);
6644 bce_mgmt_init_locked_exit:
6645 DBEXIT(BCE_VERBOSE_RESET);
6649 /****************************************************************************/
6650 /* Handles controller initialization when called from an unlocked routine. */
6654 /****************************************************************************/
6658 struct bce_softc *sc = xsc;
6660 DBENTER(BCE_VERBOSE_RESET);
6663 bce_init_locked(sc);
6666 DBEXIT(BCE_VERBOSE_RESET);
6670 /****************************************************************************/
6671 /* Modifies an mbuf for TSO on the hardware. */
6674 /* Pointer to a modified mbuf. */
6675 /****************************************************************************/
6676 static struct mbuf *
6677 bce_tso_setup(struct bce_softc *sc, struct mbuf **m_head, u16 *flags)
6680 struct ether_header *eh;
6684 int hdr_len, ip_hlen = 0, tcp_hlen = 0, ip_len = 0;
6686 DBRUN(sc->tso_frames_requested++);
6688 /* Controller may modify mbuf chains. */
6689 if (M_WRITABLE(*m_head) == 0) {
6690 m = m_dup(*m_head, M_DONTWAIT);
6693 sc->mbuf_alloc_failed_count++;
6701 * For TSO the controller needs two pieces of info,
6702 * the MSS and the IP+TCP options length.
6704 m = m_pullup(*m_head, sizeof(struct ether_header) + sizeof(struct ip));
6709 eh = mtod(m, struct ether_header *);
6710 etype = ntohs(eh->ether_type);
6712 /* Check for supported TSO Ethernet types (only IPv4 for now) */
6715 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
6716 /* TSO only supported for TCP protocol. */
6717 if (ip->ip_p != IPPROTO_TCP) {
6718 BCE_PRINTF("%s(%d): TSO enabled for non-TCP frame!.\n",
6719 __FILE__, __LINE__);
6725 /* Get IP header length in bytes (min 20) */
6726 ip_hlen = ip->ip_hl << 2;
6727 m = m_pullup(*m_head, sizeof(struct ether_header) + ip_hlen +
6728 sizeof(struct tcphdr));
6734 /* Get the TCP header length in bytes (min 20) */
6735 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
6736 tcp_hlen = (th->th_off << 2);
6738 /* Make sure all IP/TCP options live in the same buffer. */
6739 m = m_pullup(*m_head, sizeof(struct ether_header)+ ip_hlen +
6746 /* IP header length and checksum will be calc'd by hardware */
6747 ip_len = ip->ip_len;
6751 case ETHERTYPE_IPV6:
6752 BCE_PRINTF("%s(%d): TSO over IPv6 not supported!.\n",
6753 __FILE__, __LINE__);
6759 BCE_PRINTF("%s(%d): TSO enabled for unsupported protocol!.\n",
6760 __FILE__, __LINE__);
6766 hdr_len = sizeof(struct ether_header) + ip_hlen + tcp_hlen;
6768 DBPRINT(sc, BCE_EXTREME_SEND, "%s(): hdr_len = %d, e_hlen = %d, "
6769 "ip_hlen = %d, tcp_hlen = %d, ip_len = %d\n",
6770 __FUNCTION__, hdr_len, (int) sizeof(struct ether_header), ip_hlen,
6773 /* Set the LSO flag in the TX BD */
6774 *flags |= TX_BD_FLAGS_SW_LSO;
6776 /* Set the length of IP + TCP options (in 32 bit words) */
6777 *flags |= (((ip_hlen + tcp_hlen - sizeof(struct ip) -
6778 sizeof(struct tcphdr)) >> 2) << 8);
6780 DBRUN(sc->tso_frames_completed++);
6785 /****************************************************************************/
6786 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
6787 /* memory visible to the controller. */
6790 /* 0 for success, positive value for failure. */
6792 /* m_head: May be set to NULL if MBUF is excessively fragmented. */
6793 /****************************************************************************/
6795 bce_tx_encap(struct bce_softc *sc, struct mbuf **m_head)
6797 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
6799 struct tx_bd *txbd = NULL;
6801 u16 prod, chain_prod, mss = 0, vlan_tag = 0, flags = 0;
6808 int i, error, nsegs, rc = 0;
6810 DBENTER(BCE_VERBOSE_SEND);
6812 /* Make sure we have room in the TX chain. */
6813 if (sc->used_tx_bd >= sc->max_tx_bd)
6814 goto bce_tx_encap_exit;
6816 /* Transfer any checksum offload flags to the bd. */
6818 if (m0->m_pkthdr.csum_flags) {
6819 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
6820 m0 = bce_tso_setup(sc, m_head, &flags);
6822 DBRUN(sc->tso_frames_failed++);
6823 goto bce_tx_encap_exit;
6825 mss = htole16(m0->m_pkthdr.tso_segsz);
6827 if (m0->m_pkthdr.csum_flags & CSUM_IP)
6828 flags |= TX_BD_FLAGS_IP_CKSUM;
6829 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
6830 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
6834 /* Transfer any VLAN tags to the bd. */
6835 if (m0->m_flags & M_VLANTAG) {
6836 flags |= TX_BD_FLAGS_VLAN_TAG;
6837 vlan_tag = m0->m_pkthdr.ether_vtag;
6840 /* Map the mbuf into DMAable memory. */
6842 chain_prod = TX_CHAIN_IDX(prod);
6843 map = sc->tx_mbuf_map[chain_prod];
6845 /* Map the mbuf into our DMA address space. */
6846 error = bus_dmamap_load_mbuf_sg(sc->tx_mbuf_tag, map, m0,
6847 segs, &nsegs, BUS_DMA_NOWAIT);
6849 /* Check if the DMA mapping was successful */
6850 if (error == EFBIG) {
6851 sc->mbuf_frag_count++;
6853 /* Try to defrag the mbuf. */
6854 m0 = m_collapse(*m_head, M_DONTWAIT, BCE_MAX_SEGMENTS);
6856 /* Defrag was unsuccessful */
6859 sc->mbuf_alloc_failed_count++;
6861 goto bce_tx_encap_exit;
6864 /* Defrag was successful, try mapping again */
6866 error = bus_dmamap_load_mbuf_sg(sc->tx_mbuf_tag,
6867 map, m0, segs, &nsegs, BUS_DMA_NOWAIT);
6869 /* Still getting an error after a defrag. */
6870 if (error == ENOMEM) {
6871 /* Insufficient DMA buffers available. */
6872 sc->dma_map_addr_tx_failed_count++;
6874 goto bce_tx_encap_exit;
6875 } else if (error != 0) {
6876 /* Release it and return an error. */
6877 BCE_PRINTF("%s(%d): Unknown error mapping mbuf into "
6878 "TX chain!\n", __FILE__, __LINE__);
6881 sc->dma_map_addr_tx_failed_count++;
6883 goto bce_tx_encap_exit;
6885 } else if (error == ENOMEM) {
6886 /* Insufficient DMA buffers available. */
6887 sc->dma_map_addr_tx_failed_count++;
6889 goto bce_tx_encap_exit;
6890 } else if (error != 0) {
6893 sc->dma_map_addr_tx_failed_count++;
6895 goto bce_tx_encap_exit;
6898 /* Make sure there's room in the chain */
6899 if (nsegs > (sc->max_tx_bd - sc->used_tx_bd)) {
6900 bus_dmamap_unload(sc->tx_mbuf_tag, map);
6902 goto bce_tx_encap_exit;
6905 /* prod points to an empty tx_bd at this point. */
6906 prod_bseq = sc->tx_prod_bseq;
6909 debug_prod = chain_prod;
6912 DBPRINT(sc, BCE_INFO_SEND,
6913 "%s(start): prod = 0x%04X, chain_prod = 0x%04X, "
6914 "prod_bseq = 0x%08X\n",
6915 __FUNCTION__, prod, chain_prod, prod_bseq);
6918 * Cycle through each mbuf segment that makes up
6919 * the outgoing frame, gathering the mapping info
6920 * for that segment and creating a tx_bd for
6923 for (i = 0; i < nsegs ; i++) {
6925 chain_prod = TX_CHAIN_IDX(prod);
6926 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)]
6927 [TX_IDX(chain_prod)];
6929 txbd->tx_bd_haddr_lo =
6930 htole32(BCE_ADDR_LO(segs[i].ds_addr));
6931 txbd->tx_bd_haddr_hi =
6932 htole32(BCE_ADDR_HI(segs[i].ds_addr));
6933 txbd->tx_bd_mss_nbytes = htole32(mss << 16) |
6934 htole16(segs[i].ds_len);
6935 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
6936 txbd->tx_bd_flags = htole16(flags);
6937 prod_bseq += segs[i].ds_len;
6939 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
6940 prod = NEXT_TX_BD(prod);
6943 /* Set the END flag on the last TX buffer descriptor. */
6944 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
6946 DBRUNMSG(BCE_EXTREME_SEND,
6947 bce_dump_tx_chain(sc, debug_prod, nsegs));
6950 * Ensure that the mbuf pointer for this transmission
6951 * is placed at the array index of the last
6952 * descriptor in this chain. This is done
6953 * because a single map is used for all
6954 * segments of the mbuf and we don't want to
6955 * unload the map before all of the segments
6958 sc->tx_mbuf_ptr[chain_prod] = m0;
6959 sc->used_tx_bd += nsegs;
6961 /* Update some debug statistic counters */
6962 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
6963 sc->tx_hi_watermark = sc->used_tx_bd);
6964 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
6965 DBRUNIF(sc->debug_tx_mbuf_alloc++);
6967 DBRUNMSG(BCE_EXTREME_SEND, bce_dump_tx_mbuf_chain(sc, chain_prod, 1));
6969 /* prod points to the next free tx_bd at this point. */
6971 sc->tx_prod_bseq = prod_bseq;
6973 /* Tell the chip about the waiting TX frames. */
6974 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) +
6975 BCE_L2MQ_TX_HOST_BIDX, sc->tx_prod);
6976 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) +
6977 BCE_L2MQ_TX_HOST_BSEQ, sc->tx_prod_bseq);
6980 DBEXIT(BCE_VERBOSE_SEND);
6985 /****************************************************************************/
6986 /* Main transmit routine when called from another routine with a lock. */
6990 /****************************************************************************/
6992 bce_start_locked(struct ifnet *ifp)
6994 struct bce_softc *sc = ifp->if_softc;
6995 struct mbuf *m_head = NULL;
6997 u16 tx_prod, tx_chain_prod;
6999 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
7001 BCE_LOCK_ASSERT(sc);
7003 /* prod points to the next free tx_bd. */
7004 tx_prod = sc->tx_prod;
7005 tx_chain_prod = TX_CHAIN_IDX(tx_prod);
7007 DBPRINT(sc, BCE_INFO_SEND,
7008 "%s(enter): tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
7009 "tx_prod_bseq = 0x%08X\n",
7010 __FUNCTION__, tx_prod, tx_chain_prod, sc->tx_prod_bseq);
7012 /* If there's no link or the transmit queue is empty then just exit. */
7013 if (sc->bce_link_up == FALSE) {
7014 DBPRINT(sc, BCE_INFO_SEND, "%s(): No link.\n",
7016 goto bce_start_locked_exit;
7019 if (IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
7020 DBPRINT(sc, BCE_INFO_SEND, "%s(): Transmit queue empty.\n",
7022 goto bce_start_locked_exit;
7026 * Keep adding entries while there is space in the ring.
7028 while (sc->used_tx_bd < sc->max_tx_bd) {
7030 /* Check for any frames to send. */
7031 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
7033 /* Stop when the transmit queue is empty. */
7038 * Pack the data into the transmit ring. If we
7039 * don't have room, place the mbuf back at the
7040 * head of the queue and set the OACTIVE flag
7041 * to wait for the NIC to drain the chain.
7043 if (bce_tx_encap(sc, &m_head)) {
7045 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
7046 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
7047 DBPRINT(sc, BCE_INFO_SEND,
7048 "TX chain is closed for business! Total "
7049 "tx_bd used = %d\n", sc->used_tx_bd);
7055 /* Send a copy of the frame to any BPF listeners. */
7056 ETHER_BPF_MTAP(ifp, m_head);
7059 /* Exit if no packets were dequeued. */
7061 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): No packets were "
7062 "dequeued\n", __FUNCTION__);
7063 goto bce_start_locked_exit;
7066 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): Inserted %d frames into "
7067 "send queue.\n", __FUNCTION__, count);
7069 /* Set the tx timeout. */
7070 sc->watchdog_timer = BCE_TX_TIMEOUT;
7072 DBRUNMSG(BCE_VERBOSE_SEND, bce_dump_ctx(sc, TX_CID));
7073 DBRUNMSG(BCE_VERBOSE_SEND, bce_dump_mq_regs(sc));
7075 bce_start_locked_exit:
7076 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
7081 /****************************************************************************/
7082 /* Main transmit routine when called from another routine without a lock. */
7086 /****************************************************************************/
7088 bce_start(struct ifnet *ifp)
7090 struct bce_softc *sc = ifp->if_softc;
7092 DBENTER(BCE_VERBOSE_SEND);
7095 bce_start_locked(ifp);
7098 DBEXIT(BCE_VERBOSE_SEND);
7102 /****************************************************************************/
7103 /* Handles any IOCTL calls from the operating system. */
7106 /* 0 for success, positive value for failure. */
7107 /****************************************************************************/
7109 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
7111 struct bce_softc *sc = ifp->if_softc;
7112 struct ifreq *ifr = (struct ifreq *) data;
7113 struct mii_data *mii;
7114 int mask, error = 0, reinit;
7116 DBENTER(BCE_VERBOSE_MISC);
7120 /* Set the interface MTU. */
7122 /* Check that the MTU setting is supported. */
7123 if ((ifr->ifr_mtu < BCE_MIN_MTU) ||
7124 (ifr->ifr_mtu > BCE_MAX_JUMBO_MTU)) {
7129 DBPRINT(sc, BCE_INFO_MISC,
7130 "SIOCSIFMTU: Changing MTU from %d to %d\n",
7131 (int) ifp->if_mtu, (int) ifr->ifr_mtu);
7134 ifp->if_mtu = ifr->ifr_mtu;
7136 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7138 * Because allocation size is used in RX
7139 * buffer allocation, stop controller if
7140 * it is already running.
7145 #ifdef BCE_JUMBO_HDRSPLIT
7146 /* No buffer allocation size changes are necessary. */
7148 /* Recalculate our buffer allocation sizes. */
7149 if ((ifp->if_mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN +
7150 ETHER_CRC_LEN) > MCLBYTES) {
7151 sc->rx_bd_mbuf_alloc_size = MJUM9BYTES;
7152 sc->rx_bd_mbuf_align_pad =
7153 roundup2(MJUM9BYTES, 16) - MJUM9BYTES;
7154 sc->rx_bd_mbuf_data_len =
7155 sc->rx_bd_mbuf_alloc_size -
7156 sc->rx_bd_mbuf_align_pad;
7158 sc->rx_bd_mbuf_alloc_size = MCLBYTES;
7159 sc->rx_bd_mbuf_align_pad =
7160 roundup2(MCLBYTES, 16) - MCLBYTES;
7161 sc->rx_bd_mbuf_data_len =
7162 sc->rx_bd_mbuf_alloc_size -
7163 sc->rx_bd_mbuf_align_pad;
7168 bce_init_locked(sc);
7172 /* Set interface flags. */
7174 DBPRINT(sc, BCE_VERBOSE_SPECIAL, "Received SIOCSIFFLAGS\n");
7178 /* Check if the interface is up. */
7179 if (ifp->if_flags & IFF_UP) {
7180 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7181 /* Change promiscuous/multicast flags as necessary. */
7182 bce_set_rx_mode(sc);
7185 bce_init_locked(sc);
7188 /* The interface is down, check if driver is running. */
7189 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7192 /* If MFW is running, restart the controller a bit. */
7193 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
7194 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
7196 bce_mgmt_init_locked(sc);
7204 /* Add/Delete multicast address */
7207 DBPRINT(sc, BCE_VERBOSE_MISC,
7208 "Received SIOCADDMULTI/SIOCDELMULTI\n");
7211 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
7212 bce_set_rx_mode(sc);
7217 /* Set/Get Interface media */
7220 DBPRINT(sc, BCE_VERBOSE_MISC,
7221 "Received SIOCSIFMEDIA/SIOCGIFMEDIA\n");
7223 mii = device_get_softc(sc->bce_miibus);
7224 error = ifmedia_ioctl(ifp, ifr,
7225 &mii->mii_media, command);
7228 /* Set interface capability */
7230 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
7231 DBPRINT(sc, BCE_INFO_MISC,
7232 "Received SIOCSIFCAP = 0x%08X\n", (u32) mask);
7234 /* Toggle the TX checksum capabilities enable flag. */
7235 if (mask & IFCAP_TXCSUM &&
7236 ifp->if_capabilities & IFCAP_TXCSUM) {
7237 ifp->if_capenable ^= IFCAP_TXCSUM;
7238 if (IFCAP_TXCSUM & ifp->if_capenable)
7239 ifp->if_hwassist |= BCE_IF_HWASSIST;
7241 ifp->if_hwassist &= ~BCE_IF_HWASSIST;
7244 /* Toggle the RX checksum capabilities enable flag. */
7245 if (mask & IFCAP_RXCSUM &&
7246 ifp->if_capabilities & IFCAP_RXCSUM)
7247 ifp->if_capenable ^= IFCAP_RXCSUM;
7249 /* Toggle the TSO capabilities enable flag. */
7250 if (bce_tso_enable && (mask & IFCAP_TSO4) &&
7251 ifp->if_capabilities & IFCAP_TSO4) {
7252 ifp->if_capenable ^= IFCAP_TSO4;
7253 if (IFCAP_TSO4 & ifp->if_capenable)
7254 ifp->if_hwassist |= CSUM_TSO;
7256 ifp->if_hwassist &= ~CSUM_TSO;
7259 if (mask & IFCAP_VLAN_HWCSUM &&
7260 ifp->if_capabilities & IFCAP_VLAN_HWCSUM)
7261 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
7263 if ((mask & IFCAP_VLAN_HWTSO) != 0 &&
7264 (ifp->if_capabilities & IFCAP_VLAN_HWTSO) != 0)
7265 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
7267 * Don't actually disable VLAN tag stripping as
7268 * management firmware (ASF/IPMI/UMP) requires the
7269 * feature. If VLAN tag stripping is disabled driver
7270 * will manually reconstruct the VLAN frame by
7271 * appending stripped VLAN tag.
7273 if ((mask & IFCAP_VLAN_HWTAGGING) != 0 &&
7274 (ifp->if_capabilities & IFCAP_VLAN_HWTAGGING)) {
7275 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
7276 if ((ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
7278 ifp->if_capenable &= ~IFCAP_VLAN_HWTSO;
7280 VLAN_CAPABILITIES(ifp);
7283 /* We don't know how to handle the IOCTL, pass it on. */
7284 error = ether_ioctl(ifp, command, data);
7288 DBEXIT(BCE_VERBOSE_MISC);
7293 /****************************************************************************/
7294 /* Transmit timeout handler. */
7298 /****************************************************************************/
7300 bce_watchdog(struct bce_softc *sc)
7302 DBENTER(BCE_EXTREME_SEND);
7304 BCE_LOCK_ASSERT(sc);
7306 /* If the watchdog timer hasn't expired then just exit. */
7307 if (sc->watchdog_timer == 0 || --sc->watchdog_timer)
7308 goto bce_watchdog_exit;
7310 /* If pause frames are active then don't reset the hardware. */
7311 /* ToDo: Should we reset the timer here? */
7312 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
7313 goto bce_watchdog_exit;
7315 BCE_PRINTF("%s(%d): Watchdog timeout occurred, resetting!\n",
7316 __FILE__, __LINE__);
7319 bce_dump_driver_state(sc);
7320 bce_dump_status_block(sc);
7321 bce_dump_stats_block(sc);
7323 bce_dump_txp_state(sc, 0);
7324 bce_dump_rxp_state(sc, 0);
7325 bce_dump_tpat_state(sc, 0);
7326 bce_dump_cp_state(sc, 0);
7327 bce_dump_com_state(sc, 0));
7329 DBRUN(bce_breakpoint(sc));
7331 sc->bce_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
7333 bce_init_locked(sc);
7334 sc->bce_ifp->if_oerrors++;
7337 DBEXIT(BCE_EXTREME_SEND);
7342 * Interrupt handler.
7344 /****************************************************************************/
7345 /* Main interrupt entry point. Verifies that the controller generated the */
7346 /* interrupt and then calls a separate routine for handle the various */
7347 /* interrupt causes (PHY, TX, RX). */
7350 /* 0 for success, positive value for failure. */
7351 /****************************************************************************/
7355 struct bce_softc *sc;
7357 u32 status_attn_bits;
7358 u16 hw_rx_cons, hw_tx_cons;
7363 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
7364 DBRUNMSG(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
7365 DBRUNMSG(BCE_VERBOSE_INTR, bce_dump_stats_block(sc));
7369 DBRUN(sc->interrupts_generated++);
7371 /* Synchnorize before we read from interface's status block */
7372 bus_dmamap_sync(sc->status_tag, sc->status_map,
7373 BUS_DMASYNC_POSTREAD);
7376 * If the hardware status block index
7377 * matches the last value read by the
7378 * driver and we haven't asserted our
7379 * interrupt then there's nothing to do.
7381 if ((sc->status_block->status_idx == sc->last_status_idx) &&
7382 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
7383 BCE_PCICFG_MISC_STATUS_INTA_VALUE)) {
7384 DBPRINT(sc, BCE_VERBOSE_INTR, "%s(): Spurious interrupt.\n",
7389 /* Ack the interrupt and stop others from occuring. */
7390 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
7391 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
7392 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
7394 /* Check if the hardware has finished any work. */
7395 hw_rx_cons = bce_get_hw_rx_cons(sc);
7396 hw_tx_cons = bce_get_hw_tx_cons(sc);
7398 /* Keep processing data as long as there is work to do. */
7401 status_attn_bits = sc->status_block->status_attn_bits;
7403 DBRUNIF(DB_RANDOMTRUE(unexpected_attention_sim_control),
7404 BCE_PRINTF("Simulating unexpected status attention "
7406 sc->unexpected_attention_sim_count++;
7407 status_attn_bits = status_attn_bits |
7408 STATUS_ATTN_BITS_PARITY_ERROR);
7410 /* Was it a link change interrupt? */
7411 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
7412 (sc->status_block->status_attn_bits_ack &
7413 STATUS_ATTN_BITS_LINK_STATE)) {
7416 /* Clear transient updates during link state change. */
7417 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command |
7418 BCE_HC_COMMAND_COAL_NOW_WO_INT);
7419 REG_RD(sc, BCE_HC_COMMAND);
7422 /* If any other attention is asserted, the chip is toast. */
7423 if (((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
7424 (sc->status_block->status_attn_bits_ack &
7425 ~STATUS_ATTN_BITS_LINK_STATE))) {
7427 sc->unexpected_attention_count++;
7429 BCE_PRINTF("%s(%d): Fatal attention detected: "
7430 "0x%08X\n", __FILE__, __LINE__,
7431 sc->status_block->status_attn_bits);
7434 if (unexpected_attention_sim_control == 0)
7435 bce_breakpoint(sc));
7437 bce_init_locked(sc);
7441 /* Check for any completed RX frames. */
7442 if (hw_rx_cons != sc->hw_rx_cons)
7445 /* Check for any completed TX frames. */
7446 if (hw_tx_cons != sc->hw_tx_cons)
7449 /* Save status block index value for the next interrupt. */
7450 sc->last_status_idx = sc->status_block->status_idx;
7453 * Prevent speculative reads from getting
7454 * ahead of the status block.
7456 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
7457 BUS_SPACE_BARRIER_READ);
7460 * If there's no work left then exit the
7461 * interrupt service routine.
7463 hw_rx_cons = bce_get_hw_rx_cons(sc);
7464 hw_tx_cons = bce_get_hw_tx_cons(sc);
7466 if ((hw_rx_cons == sc->hw_rx_cons) &&
7467 (hw_tx_cons == sc->hw_tx_cons))
7472 bus_dmamap_sync(sc->status_tag, sc->status_map,
7473 BUS_DMASYNC_PREREAD);
7475 /* Re-enable interrupts. */
7476 bce_enable_intr(sc, 0);
7478 /* Handle any frames that arrived while handling the interrupt. */
7479 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
7480 !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
7481 bce_start_locked(ifp);
7486 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
7490 /****************************************************************************/
7491 /* Programs the various packet receive modes (broadcast and multicast). */
7495 /****************************************************************************/
7497 bce_set_rx_mode(struct bce_softc *sc)
7500 struct ifmultiaddr *ifma;
7501 u32 hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
7502 u32 rx_mode, sort_mode;
7505 DBENTER(BCE_VERBOSE_MISC);
7507 BCE_LOCK_ASSERT(sc);
7511 /* Initialize receive mode default settings. */
7512 rx_mode = sc->rx_mode & ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
7513 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
7514 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
7517 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
7520 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
7521 (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)))
7522 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
7525 * Check for promiscuous, all multicast, or selected
7526 * multicast address filtering.
7528 if (ifp->if_flags & IFF_PROMISC) {
7529 DBPRINT(sc, BCE_INFO_MISC, "Enabling promiscuous mode.\n");
7531 /* Enable promiscuous mode. */
7532 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
7533 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
7534 } else if (ifp->if_flags & IFF_ALLMULTI) {
7535 DBPRINT(sc, BCE_INFO_MISC, "Enabling all multicast mode.\n");
7537 /* Enable all multicast addresses. */
7538 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
7539 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), 0xffffffff);
7541 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
7543 /* Accept one or more multicast(s). */
7544 DBPRINT(sc, BCE_INFO_MISC, "Enabling selective multicast mode.\n");
7546 if_maddr_rlock(ifp);
7547 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
7548 if (ifma->ifma_addr->sa_family != AF_LINK)
7550 h = ether_crc32_le(LLADDR((struct sockaddr_dl *)
7551 ifma->ifma_addr), ETHER_ADDR_LEN) & 0xFF;
7552 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
7554 if_maddr_runlock(ifp);
7556 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++)
7557 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), hashes[i]);
7559 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
7562 /* Only make changes if the recive mode has actually changed. */
7563 if (rx_mode != sc->rx_mode) {
7564 DBPRINT(sc, BCE_VERBOSE_MISC, "Enabling new receive mode: "
7565 "0x%08X\n", rx_mode);
7567 sc->rx_mode = rx_mode;
7568 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
7571 /* Disable and clear the exisitng sort before enabling a new sort. */
7572 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
7573 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
7574 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
7576 DBEXIT(BCE_VERBOSE_MISC);
7580 /****************************************************************************/
7581 /* Called periodically to updates statistics from the controllers */
7582 /* statistics block. */
7586 /****************************************************************************/
7588 bce_stats_update(struct bce_softc *sc)
7591 struct statistics_block *stats;
7593 DBENTER(BCE_EXTREME_MISC);
7597 stats = (struct statistics_block *) sc->stats_block;
7600 * Certain controllers don't report
7601 * carrier sense errors correctly.
7602 * See errata E11_5708CA0_1165.
7604 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
7605 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0))
7607 (u_long) stats->stat_Dot3StatsCarrierSenseErrors;
7610 * Update the sysctl statistics from the
7611 * hardware statistics.
7613 sc->stat_IfHCInOctets =
7614 ((u64) stats->stat_IfHCInOctets_hi << 32) +
7615 (u64) stats->stat_IfHCInOctets_lo;
7617 sc->stat_IfHCInBadOctets =
7618 ((u64) stats->stat_IfHCInBadOctets_hi << 32) +
7619 (u64) stats->stat_IfHCInBadOctets_lo;
7621 sc->stat_IfHCOutOctets =
7622 ((u64) stats->stat_IfHCOutOctets_hi << 32) +
7623 (u64) stats->stat_IfHCOutOctets_lo;
7625 sc->stat_IfHCOutBadOctets =
7626 ((u64) stats->stat_IfHCOutBadOctets_hi << 32) +
7627 (u64) stats->stat_IfHCOutBadOctets_lo;
7629 sc->stat_IfHCInUcastPkts =
7630 ((u64) stats->stat_IfHCInUcastPkts_hi << 32) +
7631 (u64) stats->stat_IfHCInUcastPkts_lo;
7633 sc->stat_IfHCInMulticastPkts =
7634 ((u64) stats->stat_IfHCInMulticastPkts_hi << 32) +
7635 (u64) stats->stat_IfHCInMulticastPkts_lo;
7637 sc->stat_IfHCInBroadcastPkts =
7638 ((u64) stats->stat_IfHCInBroadcastPkts_hi << 32) +
7639 (u64) stats->stat_IfHCInBroadcastPkts_lo;
7641 sc->stat_IfHCOutUcastPkts =
7642 ((u64) stats->stat_IfHCOutUcastPkts_hi << 32) +
7643 (u64) stats->stat_IfHCOutUcastPkts_lo;
7645 sc->stat_IfHCOutMulticastPkts =
7646 ((u64) stats->stat_IfHCOutMulticastPkts_hi << 32) +
7647 (u64) stats->stat_IfHCOutMulticastPkts_lo;
7649 sc->stat_IfHCOutBroadcastPkts =
7650 ((u64) stats->stat_IfHCOutBroadcastPkts_hi << 32) +
7651 (u64) stats->stat_IfHCOutBroadcastPkts_lo;
7653 /* ToDo: Preserve counters beyond 32 bits? */
7654 /* ToDo: Read the statistics from auto-clear regs? */
7656 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
7657 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
7659 sc->stat_Dot3StatsCarrierSenseErrors =
7660 stats->stat_Dot3StatsCarrierSenseErrors;
7662 sc->stat_Dot3StatsFCSErrors =
7663 stats->stat_Dot3StatsFCSErrors;
7665 sc->stat_Dot3StatsAlignmentErrors =
7666 stats->stat_Dot3StatsAlignmentErrors;
7668 sc->stat_Dot3StatsSingleCollisionFrames =
7669 stats->stat_Dot3StatsSingleCollisionFrames;
7671 sc->stat_Dot3StatsMultipleCollisionFrames =
7672 stats->stat_Dot3StatsMultipleCollisionFrames;
7674 sc->stat_Dot3StatsDeferredTransmissions =
7675 stats->stat_Dot3StatsDeferredTransmissions;
7677 sc->stat_Dot3StatsExcessiveCollisions =
7678 stats->stat_Dot3StatsExcessiveCollisions;
7680 sc->stat_Dot3StatsLateCollisions =
7681 stats->stat_Dot3StatsLateCollisions;
7683 sc->stat_EtherStatsCollisions =
7684 stats->stat_EtherStatsCollisions;
7686 sc->stat_EtherStatsFragments =
7687 stats->stat_EtherStatsFragments;
7689 sc->stat_EtherStatsJabbers =
7690 stats->stat_EtherStatsJabbers;
7692 sc->stat_EtherStatsUndersizePkts =
7693 stats->stat_EtherStatsUndersizePkts;
7695 sc->stat_EtherStatsOversizePkts =
7696 stats->stat_EtherStatsOversizePkts;
7698 sc->stat_EtherStatsPktsRx64Octets =
7699 stats->stat_EtherStatsPktsRx64Octets;
7701 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
7702 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
7704 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
7705 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
7707 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
7708 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
7710 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
7711 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
7713 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
7714 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
7716 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
7717 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
7719 sc->stat_EtherStatsPktsTx64Octets =
7720 stats->stat_EtherStatsPktsTx64Octets;
7722 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
7723 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
7725 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
7726 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
7728 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
7729 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
7731 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
7732 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
7734 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
7735 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
7737 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
7738 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
7740 sc->stat_XonPauseFramesReceived =
7741 stats->stat_XonPauseFramesReceived;
7743 sc->stat_XoffPauseFramesReceived =
7744 stats->stat_XoffPauseFramesReceived;
7746 sc->stat_OutXonSent =
7747 stats->stat_OutXonSent;
7749 sc->stat_OutXoffSent =
7750 stats->stat_OutXoffSent;
7752 sc->stat_FlowControlDone =
7753 stats->stat_FlowControlDone;
7755 sc->stat_MacControlFramesReceived =
7756 stats->stat_MacControlFramesReceived;
7758 sc->stat_XoffStateEntered =
7759 stats->stat_XoffStateEntered;
7761 sc->stat_IfInFramesL2FilterDiscards =
7762 stats->stat_IfInFramesL2FilterDiscards;
7764 sc->stat_IfInRuleCheckerDiscards =
7765 stats->stat_IfInRuleCheckerDiscards;
7767 sc->stat_IfInFTQDiscards =
7768 stats->stat_IfInFTQDiscards;
7770 sc->stat_IfInMBUFDiscards =
7771 stats->stat_IfInMBUFDiscards;
7773 sc->stat_IfInRuleCheckerP4Hit =
7774 stats->stat_IfInRuleCheckerP4Hit;
7776 sc->stat_CatchupInRuleCheckerDiscards =
7777 stats->stat_CatchupInRuleCheckerDiscards;
7779 sc->stat_CatchupInFTQDiscards =
7780 stats->stat_CatchupInFTQDiscards;
7782 sc->stat_CatchupInMBUFDiscards =
7783 stats->stat_CatchupInMBUFDiscards;
7785 sc->stat_CatchupInRuleCheckerP4Hit =
7786 stats->stat_CatchupInRuleCheckerP4Hit;
7788 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
7791 * Update the interface statistics from the
7792 * hardware statistics.
7794 ifp->if_collisions =
7795 (u_long) sc->stat_EtherStatsCollisions;
7797 /* ToDo: This method loses soft errors. */
7799 (u_long) sc->stat_EtherStatsUndersizePkts +
7800 (u_long) sc->stat_EtherStatsOversizePkts +
7801 (u_long) sc->stat_IfInMBUFDiscards +
7802 (u_long) sc->stat_Dot3StatsAlignmentErrors +
7803 (u_long) sc->stat_Dot3StatsFCSErrors +
7804 (u_long) sc->stat_IfInRuleCheckerDiscards +
7805 (u_long) sc->stat_IfInFTQDiscards +
7806 (u_long) sc->com_no_buffers;
7808 /* ToDo: This method loses soft errors. */
7810 (u_long) sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
7811 (u_long) sc->stat_Dot3StatsExcessiveCollisions +
7812 (u_long) sc->stat_Dot3StatsLateCollisions;
7814 /* ToDo: Add additional statistics? */
7816 DBEXIT(BCE_EXTREME_MISC);
7820 /****************************************************************************/
7821 /* Periodic function to notify the bootcode that the driver is still */
7826 /****************************************************************************/
7828 bce_pulse(void *xsc)
7830 struct bce_softc *sc = xsc;
7833 DBENTER(BCE_EXTREME_MISC);
7835 BCE_LOCK_ASSERT(sc);
7837 /* Tell the firmware that the driver is still running. */
7838 msg = (u32) ++sc->bce_fw_drv_pulse_wr_seq;
7839 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
7841 /* Update the bootcode condition. */
7842 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
7844 /* Report whether the bootcode still knows the driver is running. */
7846 if (sc->bce_drv_cardiac_arrest == FALSE) {
7847 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
7848 sc->bce_drv_cardiac_arrest = TRUE;
7849 BCE_PRINTF("%s(): Warning: bootcode "
7850 "thinks driver is absent! "
7851 "(bc_state = 0x%08X)\n",
7852 __FUNCTION__, sc->bc_state);
7856 * Not supported by all bootcode versions.
7857 * (v5.0.11+ and v5.2.1+) Older bootcode
7858 * will require the driver to reset the
7859 * controller to clear this condition.
7861 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
7862 sc->bce_drv_cardiac_arrest = FALSE;
7863 BCE_PRINTF("%s(): Bootcode found the "
7864 "driver pulse! (bc_state = 0x%08X)\n",
7865 __FUNCTION__, sc->bc_state);
7871 /* Schedule the next pulse. */
7872 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
7874 DBEXIT(BCE_EXTREME_MISC);
7878 /****************************************************************************/
7879 /* Periodic function to perform maintenance tasks. */
7883 /****************************************************************************/
7887 struct bce_softc *sc = xsc;
7888 struct mii_data *mii;
7893 DBENTER(BCE_EXTREME_MISC);
7895 BCE_LOCK_ASSERT(sc);
7897 /* Schedule the next tick. */
7898 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
7900 /* Update the statistics from the hardware statistics block. */
7901 bce_stats_update(sc);
7903 /* Top off the receive and page chains. */
7904 #ifdef BCE_JUMBO_HDRSPLIT
7905 bce_fill_pg_chain(sc);
7907 bce_fill_rx_chain(sc);
7909 /* Check that chip hasn't hung. */
7912 /* If link is up already up then we're done. */
7913 if (sc->bce_link_up == TRUE)
7916 /* Link is down. Check what the PHY's doing. */
7917 mii = device_get_softc(sc->bce_miibus);
7920 /* Check if the link has come up. */
7921 if ((mii->mii_media_status & IFM_ACTIVE) &&
7922 (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)) {
7923 DBPRINT(sc, BCE_VERBOSE_MISC,
7924 "%s(): Link up!\n", __FUNCTION__);
7925 sc->bce_link_up = TRUE;
7926 if ((IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
7927 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX ||
7928 IFM_SUBTYPE(mii->mii_media_active) == IFM_2500_SX) &&
7930 BCE_PRINTF("Gigabit link up!\n");
7932 /* Now that link is up, handle any outstanding TX traffic. */
7933 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
7934 DBPRINT(sc, BCE_VERBOSE_MISC, "%s(): Found "
7935 "pending TX traffic.\n", __FUNCTION__);
7936 bce_start_locked(ifp);
7941 DBEXIT(BCE_EXTREME_MISC);
7947 /****************************************************************************/
7948 /* Allows the driver state to be dumped through the sysctl interface. */
7951 /* 0 for success, positive value for failure. */
7952 /****************************************************************************/
7954 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
7958 struct bce_softc *sc;
7961 error = sysctl_handle_int(oidp, &result, 0, req);
7963 if (error || !req->newptr)
7967 sc = (struct bce_softc *)arg1;
7968 bce_dump_driver_state(sc);
7975 /****************************************************************************/
7976 /* Allows the hardware state to be dumped through the sysctl interface. */
7979 /* 0 for success, positive value for failure. */
7980 /****************************************************************************/
7982 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
7986 struct bce_softc *sc;
7989 error = sysctl_handle_int(oidp, &result, 0, req);
7991 if (error || !req->newptr)
7995 sc = (struct bce_softc *)arg1;
7996 bce_dump_hw_state(sc);
8003 /****************************************************************************/
8004 /* Allows the status block to be dumped through the sysctl interface. */
8007 /* 0 for success, positive value for failure. */
8008 /****************************************************************************/
8010 bce_sysctl_status_block(SYSCTL_HANDLER_ARGS)
8014 struct bce_softc *sc;
8017 error = sysctl_handle_int(oidp, &result, 0, req);
8019 if (error || !req->newptr)
8023 sc = (struct bce_softc *)arg1;
8024 bce_dump_status_block(sc);
8031 /****************************************************************************/
8032 /* Allows the stats block to be dumped through the sysctl interface. */
8035 /* 0 for success, positive value for failure. */
8036 /****************************************************************************/
8038 bce_sysctl_stats_block(SYSCTL_HANDLER_ARGS)
8042 struct bce_softc *sc;
8045 error = sysctl_handle_int(oidp, &result, 0, req);
8047 if (error || !req->newptr)
8051 sc = (struct bce_softc *)arg1;
8052 bce_dump_stats_block(sc);
8059 /****************************************************************************/
8060 /* Allows the stat counters to be cleared without unloading/reloading the */
8064 /* 0 for success, positive value for failure. */
8065 /****************************************************************************/
8067 bce_sysctl_stats_clear(SYSCTL_HANDLER_ARGS)
8071 struct bce_softc *sc;
8074 error = sysctl_handle_int(oidp, &result, 0, req);
8076 if (error || !req->newptr)
8080 sc = (struct bce_softc *)arg1;
8082 /* Clear the internal H/W statistics counters. */
8083 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
8085 /* Reset the driver maintained statistics. */
8087 sc->interrupts_tx = 0;
8088 sc->tso_frames_requested =
8089 sc->tso_frames_completed =
8090 sc->tso_frames_failed = 0;
8091 sc->rx_empty_count =
8092 sc->tx_full_count = 0;
8093 sc->rx_low_watermark = USABLE_RX_BD;
8094 sc->tx_hi_watermark = 0;
8095 sc->l2fhdr_error_count =
8096 sc->l2fhdr_error_sim_count = 0;
8097 sc->mbuf_alloc_failed_count =
8098 sc->mbuf_alloc_failed_sim_count = 0;
8099 sc->dma_map_addr_rx_failed_count =
8100 sc->dma_map_addr_tx_failed_count = 0;
8101 sc->mbuf_frag_count = 0;
8102 sc->csum_offload_tcp_udp =
8103 sc->csum_offload_ip = 0;
8104 sc->vlan_tagged_frames_rcvd =
8105 sc->vlan_tagged_frames_stripped = 0;
8107 /* Clear firmware maintained statistics. */
8108 REG_WR_IND(sc, 0x120084, 0);
8115 /****************************************************************************/
8116 /* Allows the bootcode state to be dumped through the sysctl interface. */
8119 /* 0 for success, positive value for failure. */
8120 /****************************************************************************/
8122 bce_sysctl_bc_state(SYSCTL_HANDLER_ARGS)
8126 struct bce_softc *sc;
8129 error = sysctl_handle_int(oidp, &result, 0, req);
8131 if (error || !req->newptr)
8135 sc = (struct bce_softc *)arg1;
8136 bce_dump_bc_state(sc);
8143 /****************************************************************************/
8144 /* Provides a sysctl interface to allow dumping the RX BD chain. */
8147 /* 0 for success, positive value for failure. */
8148 /****************************************************************************/
8150 bce_sysctl_dump_rx_bd_chain(SYSCTL_HANDLER_ARGS)
8154 struct bce_softc *sc;
8157 error = sysctl_handle_int(oidp, &result, 0, req);
8159 if (error || !req->newptr)
8163 sc = (struct bce_softc *)arg1;
8164 bce_dump_rx_bd_chain(sc, 0, TOTAL_RX_BD);
8171 /****************************************************************************/
8172 /* Provides a sysctl interface to allow dumping the RX MBUF chain. */
8175 /* 0 for success, positive value for failure. */
8176 /****************************************************************************/
8178 bce_sysctl_dump_rx_mbuf_chain(SYSCTL_HANDLER_ARGS)
8182 struct bce_softc *sc;
8185 error = sysctl_handle_int(oidp, &result, 0, req);
8187 if (error || !req->newptr)
8191 sc = (struct bce_softc *)arg1;
8192 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD);
8199 /****************************************************************************/
8200 /* Provides a sysctl interface to allow dumping the TX chain. */
8203 /* 0 for success, positive value for failure. */
8204 /****************************************************************************/
8206 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
8210 struct bce_softc *sc;
8213 error = sysctl_handle_int(oidp, &result, 0, req);
8215 if (error || !req->newptr)
8219 sc = (struct bce_softc *)arg1;
8220 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
8227 #ifdef BCE_JUMBO_HDRSPLIT
8228 /****************************************************************************/
8229 /* Provides a sysctl interface to allow dumping the page chain. */
8232 /* 0 for success, positive value for failure. */
8233 /****************************************************************************/
8235 bce_sysctl_dump_pg_chain(SYSCTL_HANDLER_ARGS)
8239 struct bce_softc *sc;
8242 error = sysctl_handle_int(oidp, &result, 0, req);
8244 if (error || !req->newptr)
8248 sc = (struct bce_softc *)arg1;
8249 bce_dump_pg_chain(sc, 0, TOTAL_PG_BD);
8256 /****************************************************************************/
8257 /* Provides a sysctl interface to allow reading arbitrary NVRAM offsets in */
8258 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8261 /* 0 for success, positive value for failure. */
8262 /****************************************************************************/
8264 bce_sysctl_nvram_read(SYSCTL_HANDLER_ARGS)
8266 struct bce_softc *sc = (struct bce_softc *)arg1;
8270 u8 *data = (u8 *) val;
8273 error = sysctl_handle_int(oidp, &result, 0, req);
8274 if (error || (req->newptr == NULL))
8277 bce_nvram_read(sc, result, data, 4);
8278 BCE_PRINTF("offset 0x%08X = 0x%08X\n", result, bce_be32toh(val[0]));
8284 /****************************************************************************/
8285 /* Provides a sysctl interface to allow reading arbitrary registers in the */
8286 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8289 /* 0 for success, positive value for failure. */
8290 /****************************************************************************/
8292 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
8294 struct bce_softc *sc = (struct bce_softc *)arg1;
8299 error = sysctl_handle_int(oidp, &result, 0, req);
8300 if (error || (req->newptr == NULL))
8303 /* Make sure the register is accessible. */
8304 if (result < 0x8000) {
8305 val = REG_RD(sc, result);
8306 BCE_PRINTF("reg 0x%08X = 0x%08X\n", result, val);
8307 } else if (result < 0x0280000) {
8308 val = REG_RD_IND(sc, result);
8309 BCE_PRINTF("reg 0x%08X = 0x%08X\n", result, val);
8316 /****************************************************************************/
8317 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
8318 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8321 /* 0 for success, positive value for failure. */
8322 /****************************************************************************/
8324 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
8326 struct bce_softc *sc;
8332 error = sysctl_handle_int(oidp, &result, 0, req);
8333 if (error || (req->newptr == NULL))
8336 /* Make sure the register is accessible. */
8337 if (result < 0x20) {
8338 sc = (struct bce_softc *)arg1;
8340 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
8341 BCE_PRINTF("phy 0x%02X = 0x%04X\n", result, val);
8347 /****************************************************************************/
8348 /* Provides a sysctl interface to allow reading a CID. */
8351 /* 0 for success, positive value for failure. */
8352 /****************************************************************************/
8354 bce_sysctl_dump_ctx(SYSCTL_HANDLER_ARGS)
8356 struct bce_softc *sc;
8360 error = sysctl_handle_int(oidp, &result, 0, req);
8361 if (error || (req->newptr == NULL))
8364 /* Make sure the register is accessible. */
8365 if (result <= TX_CID) {
8366 sc = (struct bce_softc *)arg1;
8367 bce_dump_ctx(sc, result);
8374 /****************************************************************************/
8375 /* Provides a sysctl interface to forcing the driver to dump state and */
8376 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8379 /* 0 for success, positive value for failure. */
8380 /****************************************************************************/
8382 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
8386 struct bce_softc *sc;
8389 error = sysctl_handle_int(oidp, &result, 0, req);
8391 if (error || !req->newptr)
8395 sc = (struct bce_softc *)arg1;
8404 /****************************************************************************/
8405 /* Adds any sysctl parameters for tuning or debugging purposes. */
8408 /* 0 for success, positive value for failure. */
8409 /****************************************************************************/
8411 bce_add_sysctls(struct bce_softc *sc)
8413 struct sysctl_ctx_list *ctx;
8414 struct sysctl_oid_list *children;
8416 DBENTER(BCE_VERBOSE_MISC);
8418 ctx = device_get_sysctl_ctx(sc->bce_dev);
8419 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->bce_dev));
8422 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8423 "l2fhdr_error_sim_control",
8424 CTLFLAG_RW, &l2fhdr_error_sim_control,
8425 0, "Debug control to force l2fhdr errors");
8427 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8428 "l2fhdr_error_sim_count",
8429 CTLFLAG_RD, &sc->l2fhdr_error_sim_count,
8430 0, "Number of simulated l2_fhdr errors");
8433 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8434 "l2fhdr_error_count",
8435 CTLFLAG_RD, &sc->l2fhdr_error_count,
8436 0, "Number of l2_fhdr errors");
8439 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8440 "mbuf_alloc_failed_sim_control",
8441 CTLFLAG_RW, &mbuf_alloc_failed_sim_control,
8442 0, "Debug control to force mbuf allocation failures");
8444 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8445 "mbuf_alloc_failed_sim_count",
8446 CTLFLAG_RD, &sc->mbuf_alloc_failed_sim_count,
8447 0, "Number of simulated mbuf cluster allocation failures");
8450 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8451 "mbuf_alloc_failed_count",
8452 CTLFLAG_RD, &sc->mbuf_alloc_failed_count,
8453 0, "Number of mbuf allocation failures");
8455 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8457 CTLFLAG_RD, &sc->mbuf_frag_count,
8458 0, "Number of fragmented mbufs");
8461 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8462 "dma_map_addr_failed_sim_control",
8463 CTLFLAG_RW, &dma_map_addr_failed_sim_control,
8464 0, "Debug control to force DMA mapping failures");
8466 /* ToDo: Figure out how to update this value in bce_dma_map_addr(). */
8467 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8468 "dma_map_addr_failed_sim_count",
8469 CTLFLAG_RD, &sc->dma_map_addr_failed_sim_count,
8470 0, "Number of simulated DMA mapping failures");
8474 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8475 "dma_map_addr_rx_failed_count",
8476 CTLFLAG_RD, &sc->dma_map_addr_rx_failed_count,
8477 0, "Number of RX DMA mapping failures");
8479 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8480 "dma_map_addr_tx_failed_count",
8481 CTLFLAG_RD, &sc->dma_map_addr_tx_failed_count,
8482 0, "Number of TX DMA mapping failures");
8485 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8486 "unexpected_attention_sim_control",
8487 CTLFLAG_RW, &unexpected_attention_sim_control,
8488 0, "Debug control to simulate unexpected attentions");
8490 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8491 "unexpected_attention_sim_count",
8492 CTLFLAG_RW, &sc->unexpected_attention_sim_count,
8493 0, "Number of simulated unexpected attentions");
8496 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8497 "unexpected_attention_count",
8498 CTLFLAG_RW, &sc->unexpected_attention_count,
8499 0, "Number of unexpected attentions");
8502 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8503 "debug_bootcode_running_failure",
8504 CTLFLAG_RW, &bootcode_running_failure_sim_control,
8505 0, "Debug control to force bootcode running failures");
8507 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8509 CTLFLAG_RD, &sc->rx_low_watermark,
8510 0, "Lowest level of free rx_bd's");
8512 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8514 CTLFLAG_RD, &sc->rx_empty_count,
8515 0, "Number of times the RX chain was empty");
8517 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8519 CTLFLAG_RD, &sc->tx_hi_watermark,
8520 0, "Highest level of used tx_bd's");
8522 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8524 CTLFLAG_RD, &sc->tx_full_count,
8525 0, "Number of times the TX chain was full");
8527 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8528 "tso_frames_requested",
8529 CTLFLAG_RD, &sc->tso_frames_requested,
8530 0, "Number of TSO frames requested");
8532 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8533 "tso_frames_completed",
8534 CTLFLAG_RD, &sc->tso_frames_completed,
8535 0, "Number of TSO frames completed");
8537 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8538 "tso_frames_failed",
8539 CTLFLAG_RD, &sc->tso_frames_failed,
8540 0, "Number of TSO frames failed");
8542 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8544 CTLFLAG_RD, &sc->csum_offload_ip,
8545 0, "Number of IP checksum offload frames");
8547 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8548 "csum_offload_tcp_udp",
8549 CTLFLAG_RD, &sc->csum_offload_tcp_udp,
8550 0, "Number of TCP/UDP checksum offload frames");
8552 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8553 "vlan_tagged_frames_rcvd",
8554 CTLFLAG_RD, &sc->vlan_tagged_frames_rcvd,
8555 0, "Number of VLAN tagged frames received");
8557 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8558 "vlan_tagged_frames_stripped",
8559 CTLFLAG_RD, &sc->vlan_tagged_frames_stripped,
8560 0, "Number of VLAN tagged frames stripped");
8562 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8564 CTLFLAG_RD, &sc->interrupts_rx,
8565 0, "Number of RX interrupts");
8567 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8569 CTLFLAG_RD, &sc->interrupts_tx,
8570 0, "Number of TX interrupts");
8573 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8574 "stat_IfHcInOctets",
8575 CTLFLAG_RD, &sc->stat_IfHCInOctets,
8578 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8579 "stat_IfHCInBadOctets",
8580 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
8581 "Bad bytes received");
8583 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8584 "stat_IfHCOutOctets",
8585 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
8588 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8589 "stat_IfHCOutBadOctets",
8590 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
8593 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8594 "stat_IfHCInUcastPkts",
8595 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
8596 "Unicast packets received");
8598 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8599 "stat_IfHCInMulticastPkts",
8600 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
8601 "Multicast packets received");
8603 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8604 "stat_IfHCInBroadcastPkts",
8605 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
8606 "Broadcast packets received");
8608 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8609 "stat_IfHCOutUcastPkts",
8610 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
8611 "Unicast packets sent");
8613 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8614 "stat_IfHCOutMulticastPkts",
8615 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
8616 "Multicast packets sent");
8618 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
8619 "stat_IfHCOutBroadcastPkts",
8620 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
8621 "Broadcast packets sent");
8623 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8624 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
8625 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
8626 0, "Internal MAC transmit errors");
8628 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8629 "stat_Dot3StatsCarrierSenseErrors",
8630 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
8631 0, "Carrier sense errors");
8633 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8634 "stat_Dot3StatsFCSErrors",
8635 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
8636 0, "Frame check sequence errors");
8638 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8639 "stat_Dot3StatsAlignmentErrors",
8640 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
8641 0, "Alignment errors");
8643 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8644 "stat_Dot3StatsSingleCollisionFrames",
8645 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
8646 0, "Single Collision Frames");
8648 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8649 "stat_Dot3StatsMultipleCollisionFrames",
8650 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
8651 0, "Multiple Collision Frames");
8653 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8654 "stat_Dot3StatsDeferredTransmissions",
8655 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
8656 0, "Deferred Transmissions");
8658 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8659 "stat_Dot3StatsExcessiveCollisions",
8660 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
8661 0, "Excessive Collisions");
8663 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8664 "stat_Dot3StatsLateCollisions",
8665 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
8666 0, "Late Collisions");
8668 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8669 "stat_EtherStatsCollisions",
8670 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
8673 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8674 "stat_EtherStatsFragments",
8675 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
8678 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8679 "stat_EtherStatsJabbers",
8680 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
8683 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8684 "stat_EtherStatsUndersizePkts",
8685 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
8686 0, "Undersize packets");
8688 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8689 "stat_EtherStatsOversizePkts",
8690 CTLFLAG_RD, &sc->stat_EtherStatsOversizePkts,
8691 0, "stat_EtherStatsOversizePkts");
8693 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8694 "stat_EtherStatsPktsRx64Octets",
8695 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
8696 0, "Bytes received in 64 byte packets");
8698 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8699 "stat_EtherStatsPktsRx65Octetsto127Octets",
8700 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
8701 0, "Bytes received in 65 to 127 byte packets");
8703 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8704 "stat_EtherStatsPktsRx128Octetsto255Octets",
8705 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
8706 0, "Bytes received in 128 to 255 byte packets");
8708 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8709 "stat_EtherStatsPktsRx256Octetsto511Octets",
8710 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
8711 0, "Bytes received in 256 to 511 byte packets");
8713 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8714 "stat_EtherStatsPktsRx512Octetsto1023Octets",
8715 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
8716 0, "Bytes received in 512 to 1023 byte packets");
8718 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8719 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
8720 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
8721 0, "Bytes received in 1024 t0 1522 byte packets");
8723 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8724 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
8725 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
8726 0, "Bytes received in 1523 to 9022 byte packets");
8728 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8729 "stat_EtherStatsPktsTx64Octets",
8730 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
8731 0, "Bytes sent in 64 byte packets");
8733 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8734 "stat_EtherStatsPktsTx65Octetsto127Octets",
8735 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
8736 0, "Bytes sent in 65 to 127 byte packets");
8738 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8739 "stat_EtherStatsPktsTx128Octetsto255Octets",
8740 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
8741 0, "Bytes sent in 128 to 255 byte packets");
8743 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8744 "stat_EtherStatsPktsTx256Octetsto511Octets",
8745 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
8746 0, "Bytes sent in 256 to 511 byte packets");
8748 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8749 "stat_EtherStatsPktsTx512Octetsto1023Octets",
8750 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
8751 0, "Bytes sent in 512 to 1023 byte packets");
8753 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8754 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
8755 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
8756 0, "Bytes sent in 1024 to 1522 byte packets");
8758 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8759 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
8760 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
8761 0, "Bytes sent in 1523 to 9022 byte packets");
8763 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8764 "stat_XonPauseFramesReceived",
8765 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
8766 0, "XON pause frames receved");
8768 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8769 "stat_XoffPauseFramesReceived",
8770 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
8771 0, "XOFF pause frames received");
8773 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8775 CTLFLAG_RD, &sc->stat_OutXonSent,
8776 0, "XON pause frames sent");
8778 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8780 CTLFLAG_RD, &sc->stat_OutXoffSent,
8781 0, "XOFF pause frames sent");
8783 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8784 "stat_FlowControlDone",
8785 CTLFLAG_RD, &sc->stat_FlowControlDone,
8786 0, "Flow control done");
8788 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8789 "stat_MacControlFramesReceived",
8790 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
8791 0, "MAC control frames received");
8793 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8794 "stat_XoffStateEntered",
8795 CTLFLAG_RD, &sc->stat_XoffStateEntered,
8796 0, "XOFF state entered");
8798 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8799 "stat_IfInFramesL2FilterDiscards",
8800 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
8801 0, "Received L2 packets discarded");
8803 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8804 "stat_IfInRuleCheckerDiscards",
8805 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
8806 0, "Received packets discarded by rule");
8808 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8809 "stat_IfInFTQDiscards",
8810 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
8811 0, "Received packet FTQ discards");
8813 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8814 "stat_IfInMBUFDiscards",
8815 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
8816 0, "Received packets discarded due to lack "
8817 "of controller buffer memory");
8819 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8820 "stat_IfInRuleCheckerP4Hit",
8821 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
8822 0, "Received packets rule checker hits");
8824 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8825 "stat_CatchupInRuleCheckerDiscards",
8826 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
8827 0, "Received packets discarded in Catchup path");
8829 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8830 "stat_CatchupInFTQDiscards",
8831 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
8832 0, "Received packets discarded in FTQ in Catchup path");
8834 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8835 "stat_CatchupInMBUFDiscards",
8836 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
8837 0, "Received packets discarded in controller "
8838 "buffer memory in Catchup path");
8840 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8841 "stat_CatchupInRuleCheckerP4Hit",
8842 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
8843 0, "Received packets rule checker hits in Catchup path");
8845 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8847 CTLFLAG_RD, &sc->com_no_buffers,
8848 0, "Valid packets received but no RX buffers available");
8851 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8852 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
8854 bce_sysctl_driver_state, "I", "Drive state information");
8856 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8857 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
8859 bce_sysctl_hw_state, "I", "Hardware state information");
8861 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8862 "status_block", CTLTYPE_INT | CTLFLAG_RW,
8864 bce_sysctl_status_block, "I", "Dump status block");
8866 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8867 "stats_block", CTLTYPE_INT | CTLFLAG_RW,
8869 bce_sysctl_stats_block, "I", "Dump statistics block");
8871 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8872 "stats_clear", CTLTYPE_INT | CTLFLAG_RW,
8874 bce_sysctl_stats_clear, "I", "Clear statistics block");
8876 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8877 "bc_state", CTLTYPE_INT | CTLFLAG_RW,
8879 bce_sysctl_bc_state, "I", "Bootcode state information");
8881 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8882 "dump_rx_bd_chain", CTLTYPE_INT | CTLFLAG_RW,
8884 bce_sysctl_dump_rx_bd_chain, "I", "Dump RX BD chain");
8886 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8887 "dump_rx_mbuf_chain", CTLTYPE_INT | CTLFLAG_RW,
8889 bce_sysctl_dump_rx_mbuf_chain, "I", "Dump RX MBUF chain");
8891 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8892 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
8894 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
8896 #ifdef BCE_JUMBO_HDRSPLIT
8897 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8898 "dump_pg_chain", CTLTYPE_INT | CTLFLAG_RW,
8900 bce_sysctl_dump_pg_chain, "I", "Dump page chain");
8902 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8903 "dump_ctx", CTLTYPE_INT | CTLFLAG_RW,
8905 bce_sysctl_dump_ctx, "I", "Dump context memory");
8907 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8908 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
8910 bce_sysctl_breakpoint, "I", "Driver breakpoint");
8912 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8913 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
8915 bce_sysctl_reg_read, "I", "Register read");
8917 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8918 "nvram_read", CTLTYPE_INT | CTLFLAG_RW,
8920 bce_sysctl_nvram_read, "I", "NVRAM read");
8922 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8923 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
8925 bce_sysctl_phy_read, "I", "PHY register read");
8929 DBEXIT(BCE_VERBOSE_MISC);
8933 /****************************************************************************/
8934 /* BCE Debug Routines */
8935 /****************************************************************************/
8938 /****************************************************************************/
8939 /* Freezes the controller to allow for a cohesive state dump. */
8943 /****************************************************************************/
8944 static __attribute__ ((noinline)) void
8945 bce_freeze_controller(struct bce_softc *sc)
8948 val = REG_RD(sc, BCE_MISC_COMMAND);
8949 val |= BCE_MISC_COMMAND_DISABLE_ALL;
8950 REG_WR(sc, BCE_MISC_COMMAND, val);
8954 /****************************************************************************/
8955 /* Unfreezes the controller after a freeze operation. This may not always */
8956 /* work and the controller will require a reset! */
8960 /****************************************************************************/
8961 static __attribute__ ((noinline)) void
8962 bce_unfreeze_controller(struct bce_softc *sc)
8965 val = REG_RD(sc, BCE_MISC_COMMAND);
8966 val |= BCE_MISC_COMMAND_ENABLE_ALL;
8967 REG_WR(sc, BCE_MISC_COMMAND, val);
8971 /****************************************************************************/
8972 /* Prints out Ethernet frame information from an mbuf. */
8974 /* Partially decode an Ethernet frame to look at some important headers. */
8978 /****************************************************************************/
8979 static __attribute__ ((noinline)) void
8980 bce_dump_enet(struct bce_softc *sc, struct mbuf *m)
8982 struct ether_vlan_header *eh;
8991 "-----------------------------"
8993 "-----------------------------\n");
8995 eh = mtod(m, struct ether_vlan_header *);
8997 /* Handle VLAN encapsulation if present. */
8998 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
8999 etype = ntohs(eh->evl_proto);
9000 ehlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
9002 etype = ntohs(eh->evl_encap_proto);
9003 ehlen = ETHER_HDR_LEN;
9006 /* ToDo: Add VLAN output. */
9007 BCE_PRINTF("enet: dest = %6D, src = %6D, type = 0x%04X, hlen = %d\n",
9008 eh->evl_dhost, ":", eh->evl_shost, ":", etype, ehlen);
9012 ip = (struct ip *)(m->m_data + ehlen);
9013 BCE_PRINTF("--ip: dest = 0x%08X , src = 0x%08X, "
9014 "len = %d bytes, protocol = 0x%02X, xsum = 0x%04X\n",
9015 ntohl(ip->ip_dst.s_addr), ntohl(ip->ip_src.s_addr),
9016 ntohs(ip->ip_len), ip->ip_p, ntohs(ip->ip_sum));
9020 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
9021 BCE_PRINTF("-tcp: dest = %d, src = %d, hlen = "
9022 "%d bytes, flags = 0x%b, csum = 0x%04X\n",
9023 ntohs(th->th_dport), ntohs(th->th_sport),
9024 (th->th_off << 2), th->th_flags,
9025 "\20\10CWR\07ECE\06URG\05ACK\04PSH\03RST"
9026 "\02SYN\01FIN", ntohs(th->th_sum));
9029 uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
9030 BCE_PRINTF("-udp: dest = %d, src = %d, len = %d "
9031 "bytes, csum = 0x%04X\n", ntohs(uh->uh_dport),
9032 ntohs(uh->uh_sport), ntohs(uh->uh_ulen),
9036 BCE_PRINTF("icmp:\n");
9039 BCE_PRINTF("----: Other IP protocol.\n");
9042 case ETHERTYPE_IPV6:
9043 BCE_PRINTF("ipv6: No decode supported.\n");
9046 BCE_PRINTF("-arp: ");
9047 ah = (struct arphdr *) (m->m_data + ehlen);
9048 switch (ntohs(ah->ar_op)) {
9049 case ARPOP_REVREQUEST:
9050 printf("reverse ARP request\n");
9052 case ARPOP_REVREPLY:
9053 printf("reverse ARP reply\n");
9056 printf("ARP request\n");
9059 printf("ARP reply\n");
9062 printf("other ARP operation\n");
9066 BCE_PRINTF("----: Other protocol.\n");
9070 "-----------------------------"
9072 "-----------------------------\n");
9076 /****************************************************************************/
9077 /* Prints out information about an mbuf. */
9081 /****************************************************************************/
9082 static __attribute__ ((noinline)) void
9083 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
9085 struct mbuf *mp = m;
9088 BCE_PRINTF("mbuf: null pointer\n");
9093 BCE_PRINTF("mbuf: %p, m_len = %d, m_flags = 0x%b, "
9094 "m_data = %p\n", mp, mp->m_len, mp->m_flags,
9095 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", mp->m_data);
9097 if (mp->m_flags & M_PKTHDR) {
9098 BCE_PRINTF("- m_pkthdr: len = %d, flags = 0x%b, "
9099 "csum_flags = %b\n", mp->m_pkthdr.len,
9100 mp->m_flags, "\20\12M_BCAST\13M_MCAST\14M_FRAG"
9101 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
9102 "\22M_PROMISC\23M_NOFREE",
9103 mp->m_pkthdr.csum_flags,
9104 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
9105 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
9106 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
9107 "\14CSUM_PSEUDO_HDR");
9110 if (mp->m_flags & M_EXT) {
9111 BCE_PRINTF("- m_ext: %p, ext_size = %d, type = ",
9112 mp->m_ext.ext_buf, mp->m_ext.ext_size);
9113 switch (mp->m_ext.ext_type) {
9115 printf("EXT_CLUSTER\n"); break;
9117 printf("EXT_SFBUF\n"); break;
9119 printf("EXT_JUMBO9\n"); break;
9121 printf("EXT_JUMBO16\n"); break;
9123 printf("EXT_PACKET\n"); break;
9125 printf("EXT_MBUF\n"); break;
9127 printf("EXT_NET_DRV\n"); break;
9129 printf("EXT_MDD_TYPE\n"); break;
9130 case EXT_DISPOSABLE:
9131 printf("EXT_DISPOSABLE\n"); break;
9133 printf("EXT_EXTREF\n"); break;
9135 printf("UNKNOWN\n");
9144 /****************************************************************************/
9145 /* Prints out the mbufs in the TX mbuf chain. */
9149 /****************************************************************************/
9150 static __attribute__ ((noinline)) void
9151 bce_dump_tx_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9156 "----------------------------"
9158 "----------------------------\n");
9160 for (int i = 0; i < count; i++) {
9161 m = sc->tx_mbuf_ptr[chain_prod];
9162 BCE_PRINTF("txmbuf[0x%04X]\n", chain_prod);
9163 bce_dump_mbuf(sc, m);
9164 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
9168 "----------------------------"
9170 "----------------------------\n");
9174 /****************************************************************************/
9175 /* Prints out the mbufs in the RX mbuf chain. */
9179 /****************************************************************************/
9180 static __attribute__ ((noinline)) void
9181 bce_dump_rx_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9186 "----------------------------"
9188 "----------------------------\n");
9190 for (int i = 0; i < count; i++) {
9191 m = sc->rx_mbuf_ptr[chain_prod];
9192 BCE_PRINTF("rxmbuf[0x%04X]\n", chain_prod);
9193 bce_dump_mbuf(sc, m);
9194 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
9199 "----------------------------"
9201 "----------------------------\n");
9205 #ifdef BCE_JUMBO_HDRSPLIT
9206 /****************************************************************************/
9207 /* Prints out the mbufs in the mbuf page chain. */
9211 /****************************************************************************/
9212 static __attribute__ ((noinline)) void
9213 bce_dump_pg_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9218 "----------------------------"
9220 "----------------------------\n");
9222 for (int i = 0; i < count; i++) {
9223 m = sc->pg_mbuf_ptr[chain_prod];
9224 BCE_PRINTF("pgmbuf[0x%04X]\n", chain_prod);
9225 bce_dump_mbuf(sc, m);
9226 chain_prod = PG_CHAIN_IDX(NEXT_PG_BD(chain_prod));
9231 "----------------------------"
9233 "----------------------------\n");
9238 /****************************************************************************/
9239 /* Prints out a tx_bd structure. */
9243 /****************************************************************************/
9244 static __attribute__ ((noinline)) void
9245 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
9249 if (idx > MAX_TX_BD)
9250 /* Index out of range. */
9251 BCE_PRINTF("tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
9252 else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
9253 /* TX Chain page pointer. */
9254 BCE_PRINTF("tx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
9255 "pointer\n", idx, txbd->tx_bd_haddr_hi,
9256 txbd->tx_bd_haddr_lo);
9258 /* Normal tx_bd entry. */
9259 BCE_PRINTF("tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
9260 "mss_nbytes = 0x%08X, vlan tag = 0x%04X, flags = "
9261 "0x%04X (", idx, txbd->tx_bd_haddr_hi,
9262 txbd->tx_bd_haddr_lo, txbd->tx_bd_mss_nbytes,
9263 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
9265 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT) {
9268 printf("CONN_FAULT");
9272 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM) {
9275 printf("TCP_UDP_CKSUM");
9279 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM) {
9286 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG) {
9293 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW) {
9300 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC) {
9303 printf("DONT_GEN_CRC");
9307 if (txbd->tx_bd_flags & TX_BD_FLAGS_START) {
9314 if (txbd->tx_bd_flags & TX_BD_FLAGS_END) {
9321 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO) {
9328 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD) {
9331 printf("SW_OPTION=%d", ((txbd->tx_bd_flags &
9332 TX_BD_FLAGS_SW_OPTION_WORD) >> 8)); i++;
9335 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS) {
9342 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP) {
9353 /****************************************************************************/
9354 /* Prints out a rx_bd structure. */
9358 /****************************************************************************/
9359 static __attribute__ ((noinline)) void
9360 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
9362 if (idx > MAX_RX_BD)
9363 /* Index out of range. */
9364 BCE_PRINTF("rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
9365 else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
9366 /* RX Chain page pointer. */
9367 BCE_PRINTF("rx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
9368 "pointer\n", idx, rxbd->rx_bd_haddr_hi,
9369 rxbd->rx_bd_haddr_lo);
9371 /* Normal rx_bd entry. */
9372 BCE_PRINTF("rx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = "
9373 "0x%08X, flags = 0x%08X\n", idx, rxbd->rx_bd_haddr_hi,
9374 rxbd->rx_bd_haddr_lo, rxbd->rx_bd_len,
9379 #ifdef BCE_JUMBO_HDRSPLIT
9380 /****************************************************************************/
9381 /* Prints out a rx_bd structure in the page chain. */
9385 /****************************************************************************/
9386 static __attribute__ ((noinline)) void
9387 bce_dump_pgbd(struct bce_softc *sc, int idx, struct rx_bd *pgbd)
9389 if (idx > MAX_PG_BD)
9390 /* Index out of range. */
9391 BCE_PRINTF("pg_bd[0x%04X]: Invalid pg_bd index!\n", idx);
9392 else if ((idx & USABLE_PG_BD_PER_PAGE) == USABLE_PG_BD_PER_PAGE)
9393 /* Page Chain page pointer. */
9394 BCE_PRINTF("px_bd[0x%04X]: haddr = 0x%08X:%08X, chain page pointer\n",
9395 idx, pgbd->rx_bd_haddr_hi, pgbd->rx_bd_haddr_lo);
9397 /* Normal rx_bd entry. */
9398 BCE_PRINTF("pg_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = 0x%08X, "
9399 "flags = 0x%08X\n", idx,
9400 pgbd->rx_bd_haddr_hi, pgbd->rx_bd_haddr_lo,
9401 pgbd->rx_bd_len, pgbd->rx_bd_flags);
9406 /****************************************************************************/
9407 /* Prints out a l2_fhdr structure. */
9411 /****************************************************************************/
9412 static __attribute__ ((noinline)) void
9413 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
9415 BCE_PRINTF("l2_fhdr[0x%04X]: status = 0x%b, "
9416 "pkt_len = %d, vlan = 0x%04x, ip_xsum/hdr_len = 0x%04X, "
9417 "tcp_udp_xsum = 0x%04X\n", idx,
9418 l2fhdr->l2_fhdr_status, BCE_L2FHDR_PRINTFB,
9419 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
9420 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
9424 /****************************************************************************/
9425 /* Prints out context memory info. (Only useful for CID 0 to 16.) */
9429 /****************************************************************************/
9430 static __attribute__ ((noinline)) void
9431 bce_dump_ctx(struct bce_softc *sc, u16 cid)
9434 BCE_PRINTF(" Unknown CID\n");
9439 "----------------------------"
9441 "----------------------------\n");
9443 BCE_PRINTF(" 0x%04X - (CID) Context ID\n", cid);
9445 if (cid == RX_CID) {
9446 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_BDIDX) host rx "
9448 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_HOST_BDIDX));
9449 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_BSEQ) host "
9450 "byte sequence\n", CTX_RD(sc, GET_CID_ADDR(cid),
9451 BCE_L2CTX_RX_HOST_BSEQ));
9452 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BSEQ) h/w byte sequence\n",
9453 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BSEQ));
9454 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDHADDR_HI) h/w buffer "
9455 "descriptor address\n",
9456 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BDHADDR_HI));
9457 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDHADDR_LO) h/w buffer "
9458 "descriptor address\n",
9459 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BDHADDR_LO));
9460 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDIDX) h/w rx consumer "
9461 "index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9462 BCE_L2CTX_RX_NX_BDIDX));
9463 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_PG_BDIDX) host page "
9464 "producer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9465 BCE_L2CTX_RX_HOST_PG_BDIDX));
9466 BCE_PRINTF(" 0x%08X - (L2CTX_RX_PG_BUF_SIZE) host rx_bd/page "
9467 "buffer size\n", CTX_RD(sc, GET_CID_ADDR(cid),
9468 BCE_L2CTX_RX_PG_BUF_SIZE));
9469 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDHADDR_HI) h/w page "
9470 "chain address\n", CTX_RD(sc, GET_CID_ADDR(cid),
9471 BCE_L2CTX_RX_NX_PG_BDHADDR_HI));
9472 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDHADDR_LO) h/w page "
9473 "chain address\n", CTX_RD(sc, GET_CID_ADDR(cid),
9474 BCE_L2CTX_RX_NX_PG_BDHADDR_LO));
9475 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDIDX) h/w page "
9476 "consumer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9477 BCE_L2CTX_RX_NX_PG_BDIDX));
9478 } else if (cid == TX_CID) {
9479 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
9480 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
9481 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TYPE_XI) ctx type\n",
9482 CTX_RD(sc, GET_CID_ADDR(cid),
9483 BCE_L2CTX_TX_TYPE_XI));
9484 BCE_PRINTF(" 0x%08X - (L2CTX_CMD_TX_TYPE_XI) ctx "
9485 "cmd\n", CTX_RD(sc, GET_CID_ADDR(cid),
9486 BCE_L2CTX_TX_CMD_TYPE_XI));
9487 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BDHADDR_HI_XI) "
9488 "h/w buffer descriptor address\n",
9489 CTX_RD(sc, GET_CID_ADDR(cid),
9490 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI));
9491 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BHADDR_LO_XI) "
9492 "h/w buffer descriptor address\n",
9493 CTX_RD(sc, GET_CID_ADDR(cid),
9494 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI));
9495 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BIDX_XI) "
9496 "host producer index\n",
9497 CTX_RD(sc, GET_CID_ADDR(cid),
9498 BCE_L2CTX_TX_HOST_BIDX_XI));
9499 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BSEQ_XI) "
9500 "host byte sequence\n",
9501 CTX_RD(sc, GET_CID_ADDR(cid),
9502 BCE_L2CTX_TX_HOST_BSEQ_XI));
9504 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TYPE) ctx type\n",
9505 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_TX_TYPE));
9506 BCE_PRINTF(" 0x%08X - (L2CTX_TX_CMD_TYPE) ctx cmd\n",
9507 CTX_RD(sc, GET_CID_ADDR(cid),
9508 BCE_L2CTX_TX_CMD_TYPE));
9509 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BDHADDR_HI) "
9510 "h/w buffer descriptor address\n",
9511 CTX_RD(sc, GET_CID_ADDR(cid),
9512 BCE_L2CTX_TX_TBDR_BHADDR_HI));
9513 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BHADDR_LO) "
9514 "h/w buffer descriptor address\n",
9515 CTX_RD(sc, GET_CID_ADDR(cid),
9516 BCE_L2CTX_TX_TBDR_BHADDR_LO));
9517 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BIDX) host "
9518 "producer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9519 BCE_L2CTX_TX_HOST_BIDX));
9520 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BSEQ) host byte "
9521 "sequence\n", CTX_RD(sc, GET_CID_ADDR(cid),
9522 BCE_L2CTX_TX_HOST_BSEQ));
9527 "----------------------------"
9529 "----------------------------\n");
9531 for (int i = 0x0; i < 0x300; i += 0x10) {
9532 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
9533 CTX_RD(sc, GET_CID_ADDR(cid), i),
9534 CTX_RD(sc, GET_CID_ADDR(cid), i + 0x4),
9535 CTX_RD(sc, GET_CID_ADDR(cid), i + 0x8),
9536 CTX_RD(sc, GET_CID_ADDR(cid), i + 0xc));
9541 "----------------------------"
9543 "----------------------------\n");
9547 /****************************************************************************/
9548 /* Prints out the FTQ data. */
9552 /****************************************************************************/
9553 static __attribute__ ((noinline)) void
9554 bce_dump_ftqs(struct bce_softc *sc)
9556 u32 cmd, ctl, cur_depth, max_depth, valid_cnt, val;
9559 "----------------------------"
9561 "----------------------------\n");
9563 BCE_PRINTF(" FTQ Command Control Depth_Now "
9564 "Max_Depth Valid_Cnt \n");
9565 BCE_PRINTF(" ------- ---------- ---------- ---------- "
9566 "---------- ----------\n");
9568 /* Setup the generic statistic counters for the FTQ valid count. */
9569 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PPQ_VALID_CNT << 24) |
9570 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RXPCQ_VALID_CNT << 16) |
9571 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RXPQ_VALID_CNT << 8) |
9572 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RLUPQ_VALID_CNT);
9573 REG_WR(sc, BCE_HC_STAT_GEN_SEL_0, val);
9575 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TSCHQ_VALID_CNT << 24) |
9576 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RDMAQ_VALID_CNT << 16) |
9577 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PTQ_VALID_CNT << 8) |
9578 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PMQ_VALID_CNT);
9579 REG_WR(sc, BCE_HC_STAT_GEN_SEL_1, val);
9581 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TPATQ_VALID_CNT << 24) |
9582 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TDMAQ_VALID_CNT << 16) |
9583 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TXPQ_VALID_CNT << 8) |
9584 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TBDRQ_VALID_CNT);
9585 REG_WR(sc, BCE_HC_STAT_GEN_SEL_2, val);
9587 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMQ_VALID_CNT << 24) |
9588 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMTQ_VALID_CNT << 16) |
9589 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMXQ_VALID_CNT << 8) |
9590 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TASQ_VALID_CNT);
9591 REG_WR(sc, BCE_HC_STAT_GEN_SEL_3, val);
9593 /* Input queue to the Receive Lookup state machine */
9594 cmd = REG_RD(sc, BCE_RLUP_FTQ_CMD);
9595 ctl = REG_RD(sc, BCE_RLUP_FTQ_CTL);
9596 cur_depth = (ctl & BCE_RLUP_FTQ_CTL_CUR_DEPTH) >> 22;
9597 max_depth = (ctl & BCE_RLUP_FTQ_CTL_MAX_DEPTH) >> 12;
9598 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT0);
9599 BCE_PRINTF(" RLUP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9600 cmd, ctl, cur_depth, max_depth, valid_cnt);
9602 /* Input queue to the Receive Processor */
9603 cmd = REG_RD_IND(sc, BCE_RXP_FTQ_CMD);
9604 ctl = REG_RD_IND(sc, BCE_RXP_FTQ_CTL);
9605 cur_depth = (ctl & BCE_RXP_FTQ_CTL_CUR_DEPTH) >> 22;
9606 max_depth = (ctl & BCE_RXP_FTQ_CTL_MAX_DEPTH) >> 12;
9607 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT1);
9608 BCE_PRINTF(" RXP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9609 cmd, ctl, cur_depth, max_depth, valid_cnt);
9611 /* Input queue to the Recevie Processor */
9612 cmd = REG_RD_IND(sc, BCE_RXP_CFTQ_CMD);
9613 ctl = REG_RD_IND(sc, BCE_RXP_CFTQ_CTL);
9614 cur_depth = (ctl & BCE_RXP_CFTQ_CTL_CUR_DEPTH) >> 22;
9615 max_depth = (ctl & BCE_RXP_CFTQ_CTL_MAX_DEPTH) >> 12;
9616 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT2);
9617 BCE_PRINTF(" RXPC 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9618 cmd, ctl, cur_depth, max_depth, valid_cnt);
9620 /* Input queue to the Receive Virtual to Physical state machine */
9621 cmd = REG_RD(sc, BCE_RV2P_PFTQ_CMD);
9622 ctl = REG_RD(sc, BCE_RV2P_PFTQ_CTL);
9623 cur_depth = (ctl & BCE_RV2P_PFTQ_CTL_CUR_DEPTH) >> 22;
9624 max_depth = (ctl & BCE_RV2P_PFTQ_CTL_MAX_DEPTH) >> 12;
9625 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT3);
9626 BCE_PRINTF(" RV2PP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9627 cmd, ctl, cur_depth, max_depth, valid_cnt);
9629 /* Input queue to the Recevie Virtual to Physical state machine */
9630 cmd = REG_RD(sc, BCE_RV2P_MFTQ_CMD);
9631 ctl = REG_RD(sc, BCE_RV2P_MFTQ_CTL);
9632 cur_depth = (ctl & BCE_RV2P_MFTQ_CTL_CUR_DEPTH) >> 22;
9633 max_depth = (ctl & BCE_RV2P_MFTQ_CTL_MAX_DEPTH) >> 12;
9634 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT4);
9635 BCE_PRINTF(" RV2PM 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9636 cmd, ctl, cur_depth, max_depth, valid_cnt);
9638 /* Input queue to the Receive Virtual to Physical state machine */
9639 cmd = REG_RD(sc, BCE_RV2P_TFTQ_CMD);
9640 ctl = REG_RD(sc, BCE_RV2P_TFTQ_CTL);
9641 cur_depth = (ctl & BCE_RV2P_TFTQ_CTL_CUR_DEPTH) >> 22;
9642 max_depth = (ctl & BCE_RV2P_TFTQ_CTL_MAX_DEPTH) >> 12;
9643 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT5);
9644 BCE_PRINTF(" RV2PT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9645 cmd, ctl, cur_depth, max_depth, valid_cnt);
9647 /* Input queue to the Receive DMA state machine */
9648 cmd = REG_RD(sc, BCE_RDMA_FTQ_CMD);
9649 ctl = REG_RD(sc, BCE_RDMA_FTQ_CTL);
9650 cur_depth = (ctl & BCE_RDMA_FTQ_CTL_CUR_DEPTH) >> 22;
9651 max_depth = (ctl & BCE_RDMA_FTQ_CTL_MAX_DEPTH) >> 12;
9652 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT6);
9653 BCE_PRINTF(" RDMA 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9654 cmd, ctl, cur_depth, max_depth, valid_cnt);
9656 /* Input queue to the Transmit Scheduler state machine */
9657 cmd = REG_RD(sc, BCE_TSCH_FTQ_CMD);
9658 ctl = REG_RD(sc, BCE_TSCH_FTQ_CTL);
9659 cur_depth = (ctl & BCE_TSCH_FTQ_CTL_CUR_DEPTH) >> 22;
9660 max_depth = (ctl & BCE_TSCH_FTQ_CTL_MAX_DEPTH) >> 12;
9661 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT7);
9662 BCE_PRINTF(" TSCH 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9663 cmd, ctl, cur_depth, max_depth, valid_cnt);
9665 /* Input queue to the Transmit Buffer Descriptor state machine */
9666 cmd = REG_RD(sc, BCE_TBDR_FTQ_CMD);
9667 ctl = REG_RD(sc, BCE_TBDR_FTQ_CTL);
9668 cur_depth = (ctl & BCE_TBDR_FTQ_CTL_CUR_DEPTH) >> 22;
9669 max_depth = (ctl & BCE_TBDR_FTQ_CTL_MAX_DEPTH) >> 12;
9670 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT8);
9671 BCE_PRINTF(" TBDR 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9672 cmd, ctl, cur_depth, max_depth, valid_cnt);
9674 /* Input queue to the Transmit Processor */
9675 cmd = REG_RD_IND(sc, BCE_TXP_FTQ_CMD);
9676 ctl = REG_RD_IND(sc, BCE_TXP_FTQ_CTL);
9677 cur_depth = (ctl & BCE_TXP_FTQ_CTL_CUR_DEPTH) >> 22;
9678 max_depth = (ctl & BCE_TXP_FTQ_CTL_MAX_DEPTH) >> 12;
9679 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT9);
9680 BCE_PRINTF(" TXP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9681 cmd, ctl, cur_depth, max_depth, valid_cnt);
9683 /* Input queue to the Transmit DMA state machine */
9684 cmd = REG_RD(sc, BCE_TDMA_FTQ_CMD);
9685 ctl = REG_RD(sc, BCE_TDMA_FTQ_CTL);
9686 cur_depth = (ctl & BCE_TDMA_FTQ_CTL_CUR_DEPTH) >> 22;
9687 max_depth = (ctl & BCE_TDMA_FTQ_CTL_MAX_DEPTH) >> 12;
9688 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT10);
9689 BCE_PRINTF(" TDMA 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9690 cmd, ctl, cur_depth, max_depth, valid_cnt);
9692 /* Input queue to the Transmit Patch-Up Processor */
9693 cmd = REG_RD_IND(sc, BCE_TPAT_FTQ_CMD);
9694 ctl = REG_RD_IND(sc, BCE_TPAT_FTQ_CTL);
9695 cur_depth = (ctl & BCE_TPAT_FTQ_CTL_CUR_DEPTH) >> 22;
9696 max_depth = (ctl & BCE_TPAT_FTQ_CTL_MAX_DEPTH) >> 12;
9697 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT11);
9698 BCE_PRINTF(" TPAT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9699 cmd, ctl, cur_depth, max_depth, valid_cnt);
9701 /* Input queue to the Transmit Assembler state machine */
9702 cmd = REG_RD_IND(sc, BCE_TAS_FTQ_CMD);
9703 ctl = REG_RD_IND(sc, BCE_TAS_FTQ_CTL);
9704 cur_depth = (ctl & BCE_TAS_FTQ_CTL_CUR_DEPTH) >> 22;
9705 max_depth = (ctl & BCE_TAS_FTQ_CTL_MAX_DEPTH) >> 12;
9706 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT12);
9707 BCE_PRINTF(" TAS 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9708 cmd, ctl, cur_depth, max_depth, valid_cnt);
9710 /* Input queue to the Completion Processor */
9711 cmd = REG_RD_IND(sc, BCE_COM_COMXQ_FTQ_CMD);
9712 ctl = REG_RD_IND(sc, BCE_COM_COMXQ_FTQ_CTL);
9713 cur_depth = (ctl & BCE_COM_COMXQ_FTQ_CTL_CUR_DEPTH) >> 22;
9714 max_depth = (ctl & BCE_COM_COMXQ_FTQ_CTL_MAX_DEPTH) >> 12;
9715 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT13);
9716 BCE_PRINTF(" COMX 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9717 cmd, ctl, cur_depth, max_depth, valid_cnt);
9719 /* Input queue to the Completion Processor */
9720 cmd = REG_RD_IND(sc, BCE_COM_COMTQ_FTQ_CMD);
9721 ctl = REG_RD_IND(sc, BCE_COM_COMTQ_FTQ_CTL);
9722 cur_depth = (ctl & BCE_COM_COMTQ_FTQ_CTL_CUR_DEPTH) >> 22;
9723 max_depth = (ctl & BCE_COM_COMTQ_FTQ_CTL_MAX_DEPTH) >> 12;
9724 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT14);
9725 BCE_PRINTF(" COMT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9726 cmd, ctl, cur_depth, max_depth, valid_cnt);
9728 /* Input queue to the Completion Processor */
9729 cmd = REG_RD_IND(sc, BCE_COM_COMQ_FTQ_CMD);
9730 ctl = REG_RD_IND(sc, BCE_COM_COMQ_FTQ_CTL);
9731 cur_depth = (ctl & BCE_COM_COMQ_FTQ_CTL_CUR_DEPTH) >> 22;
9732 max_depth = (ctl & BCE_COM_COMQ_FTQ_CTL_MAX_DEPTH) >> 12;
9733 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT15);
9734 BCE_PRINTF(" COMX 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9735 cmd, ctl, cur_depth, max_depth, valid_cnt);
9737 /* Setup the generic statistic counters for the FTQ valid count. */
9738 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_CSQ_VALID_CNT << 16) |
9739 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_CPQ_VALID_CNT << 8) |
9740 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_MGMQ_VALID_CNT);
9742 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
9743 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
9745 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PCSQ_VALID_CNT_XI <<
9747 REG_WR(sc, BCE_HC_STAT_GEN_SEL_0, val);
9749 /* Input queue to the Management Control Processor */
9750 cmd = REG_RD_IND(sc, BCE_MCP_MCPQ_FTQ_CMD);
9751 ctl = REG_RD_IND(sc, BCE_MCP_MCPQ_FTQ_CTL);
9752 cur_depth = (ctl & BCE_MCP_MCPQ_FTQ_CTL_CUR_DEPTH) >> 22;
9753 max_depth = (ctl & BCE_MCP_MCPQ_FTQ_CTL_MAX_DEPTH) >> 12;
9754 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT0);
9755 BCE_PRINTF(" MCP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9756 cmd, ctl, cur_depth, max_depth, valid_cnt);
9758 /* Input queue to the Command Processor */
9759 cmd = REG_RD_IND(sc, BCE_CP_CPQ_FTQ_CMD);
9760 ctl = REG_RD_IND(sc, BCE_CP_CPQ_FTQ_CTL);
9761 cur_depth = (ctl & BCE_CP_CPQ_FTQ_CTL_CUR_DEPTH) >> 22;
9762 max_depth = (ctl & BCE_CP_CPQ_FTQ_CTL_MAX_DEPTH) >> 12;
9763 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT1);
9764 BCE_PRINTF(" CP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9765 cmd, ctl, cur_depth, max_depth, valid_cnt);
9767 /* Input queue to the Completion Scheduler state machine */
9768 cmd = REG_RD(sc, BCE_CSCH_CH_FTQ_CMD);
9769 ctl = REG_RD(sc, BCE_CSCH_CH_FTQ_CTL);
9770 cur_depth = (ctl & BCE_CSCH_CH_FTQ_CTL_CUR_DEPTH) >> 22;
9771 max_depth = (ctl & BCE_CSCH_CH_FTQ_CTL_MAX_DEPTH) >> 12;
9772 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT2);
9773 BCE_PRINTF(" CS 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9774 cmd, ctl, cur_depth, max_depth, valid_cnt);
9776 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
9777 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
9778 /* Input queue to the RV2P Command Scheduler */
9779 cmd = REG_RD(sc, BCE_RV2PCSR_FTQ_CMD);
9780 ctl = REG_RD(sc, BCE_RV2PCSR_FTQ_CTL);
9781 cur_depth = (ctl & 0xFFC00000) >> 22;
9782 max_depth = (ctl & 0x003FF000) >> 12;
9783 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT3);
9784 BCE_PRINTF(" RV2PCSR 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
9785 cmd, ctl, cur_depth, max_depth, valid_cnt);
9789 "----------------------------"
9791 "----------------------------\n");
9795 /****************************************************************************/
9796 /* Prints out the TX chain. */
9800 /****************************************************************************/
9801 static __attribute__ ((noinline)) void
9802 bce_dump_tx_chain(struct bce_softc *sc, u16 tx_prod, int count)
9806 /* First some info about the tx_bd chain structure. */
9808 "----------------------------"
9810 "----------------------------\n");
9812 BCE_PRINTF("page size = 0x%08X, tx chain pages = 0x%08X\n",
9813 (u32) BCM_PAGE_SIZE, (u32) TX_PAGES);
9814 BCE_PRINTF("tx_bd per page = 0x%08X, usable tx_bd per page = 0x%08X\n",
9815 (u32) TOTAL_TX_BD_PER_PAGE, (u32) USABLE_TX_BD_PER_PAGE);
9816 BCE_PRINTF("total tx_bd = 0x%08X\n", (u32) TOTAL_TX_BD);
9819 "----------------------------"
9821 "----------------------------\n");
9823 /* Now print out a decoded list of TX buffer descriptors. */
9824 for (int i = 0; i < count; i++) {
9825 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
9826 bce_dump_txbd(sc, tx_prod, txbd);
9831 "----------------------------"
9833 "----------------------------\n");
9837 /****************************************************************************/
9838 /* Prints out the RX chain. */
9842 /****************************************************************************/
9843 static __attribute__ ((noinline)) void
9844 bce_dump_rx_bd_chain(struct bce_softc *sc, u16 rx_prod, int count)
9848 /* First some info about the rx_bd chain structure. */
9850 "----------------------------"
9852 "----------------------------\n");
9854 BCE_PRINTF("page size = 0x%08X, rx chain pages = 0x%08X\n",
9855 (u32) BCM_PAGE_SIZE, (u32) RX_PAGES);
9857 BCE_PRINTF("rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
9858 (u32) TOTAL_RX_BD_PER_PAGE, (u32) USABLE_RX_BD_PER_PAGE);
9860 BCE_PRINTF("total rx_bd = 0x%08X\n", (u32) TOTAL_RX_BD);
9863 "----------------------------"
9865 "----------------------------\n");
9867 /* Now print out the rx_bd's themselves. */
9868 for (int i = 0; i < count; i++) {
9869 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
9870 bce_dump_rxbd(sc, rx_prod, rxbd);
9871 rx_prod = RX_CHAIN_IDX(rx_prod + 1);
9875 "----------------------------"
9877 "----------------------------\n");
9881 #ifdef BCE_JUMBO_HDRSPLIT
9882 /****************************************************************************/
9883 /* Prints out the page chain. */
9887 /****************************************************************************/
9888 static __attribute__ ((noinline)) void
9889 bce_dump_pg_chain(struct bce_softc *sc, u16 pg_prod, int count)
9893 /* First some info about the page chain structure. */
9895 "----------------------------"
9897 "----------------------------\n");
9899 BCE_PRINTF("page size = 0x%08X, pg chain pages = 0x%08X\n",
9900 (u32) BCM_PAGE_SIZE, (u32) PG_PAGES);
9902 BCE_PRINTF("rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
9903 (u32) TOTAL_PG_BD_PER_PAGE, (u32) USABLE_PG_BD_PER_PAGE);
9905 BCE_PRINTF("total rx_bd = 0x%08X, max_pg_bd = 0x%08X\n",
9906 (u32) TOTAL_PG_BD, (u32) MAX_PG_BD);
9909 "----------------------------"
9911 "----------------------------\n");
9913 /* Now print out the rx_bd's themselves. */
9914 for (int i = 0; i < count; i++) {
9915 pgbd = &sc->pg_bd_chain[PG_PAGE(pg_prod)][PG_IDX(pg_prod)];
9916 bce_dump_pgbd(sc, pg_prod, pgbd);
9917 pg_prod = PG_CHAIN_IDX(pg_prod + 1);
9921 "----------------------------"
9923 "----------------------------\n");
9928 #define BCE_PRINT_RX_CONS(arg) \
9929 if (sblk->status_rx_quick_consumer_index##arg) \
9930 BCE_PRINTF("0x%04X(0x%04X) - rx_quick_consumer_index%d\n", \
9931 sblk->status_rx_quick_consumer_index##arg, (u16) \
9932 RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index##arg), \
9936 #define BCE_PRINT_TX_CONS(arg) \
9937 if (sblk->status_tx_quick_consumer_index##arg) \
9938 BCE_PRINTF("0x%04X(0x%04X) - tx_quick_consumer_index%d\n", \
9939 sblk->status_tx_quick_consumer_index##arg, (u16) \
9940 TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index##arg), \
9943 /****************************************************************************/
9944 /* Prints out the status block from host memory. */
9948 /****************************************************************************/
9949 static __attribute__ ((noinline)) void
9950 bce_dump_status_block(struct bce_softc *sc)
9952 struct status_block *sblk;
9954 sblk = sc->status_block;
9957 "----------------------------"
9959 "----------------------------\n");
9961 /* Theses indices are used for normal L2 drivers. */
9962 BCE_PRINTF(" 0x%08X - attn_bits\n",
9963 sblk->status_attn_bits);
9965 BCE_PRINTF(" 0x%08X - attn_bits_ack\n",
9966 sblk->status_attn_bits_ack);
9968 BCE_PRINT_RX_CONS(0);
9969 BCE_PRINT_TX_CONS(0)
9971 BCE_PRINTF(" 0x%04X - status_idx\n", sblk->status_idx);
9973 /* Theses indices are not used for normal L2 drivers. */
9974 BCE_PRINT_RX_CONS(1); BCE_PRINT_RX_CONS(2); BCE_PRINT_RX_CONS(3);
9975 BCE_PRINT_RX_CONS(4); BCE_PRINT_RX_CONS(5); BCE_PRINT_RX_CONS(6);
9976 BCE_PRINT_RX_CONS(7); BCE_PRINT_RX_CONS(8); BCE_PRINT_RX_CONS(9);
9977 BCE_PRINT_RX_CONS(10); BCE_PRINT_RX_CONS(11); BCE_PRINT_RX_CONS(12);
9978 BCE_PRINT_RX_CONS(13); BCE_PRINT_RX_CONS(14); BCE_PRINT_RX_CONS(15);
9980 BCE_PRINT_TX_CONS(1); BCE_PRINT_TX_CONS(2); BCE_PRINT_TX_CONS(3);
9982 if (sblk->status_completion_producer_index ||
9983 sblk->status_cmd_consumer_index)
9984 BCE_PRINTF("com_prod = 0x%08X, cmd_cons = 0x%08X\n",
9985 sblk->status_completion_producer_index,
9986 sblk->status_cmd_consumer_index);
9989 "----------------------------"
9991 "----------------------------\n");
9995 #define BCE_PRINT_64BIT_STAT(arg) \
9996 if (sblk->arg##_lo || sblk->arg##_hi) \
9997 BCE_PRINTF("0x%08X:%08X : %s\n", sblk->arg##_hi, \
9998 sblk->arg##_lo, #arg);
10000 #define BCE_PRINT_32BIT_STAT(arg) \
10002 BCE_PRINTF(" 0x%08X : %s\n", \
10005 /****************************************************************************/
10006 /* Prints out the statistics block from host memory. */
10010 /****************************************************************************/
10011 static __attribute__ ((noinline)) void
10012 bce_dump_stats_block(struct bce_softc *sc)
10014 struct statistics_block *sblk;
10016 sblk = sc->stats_block;
10020 " Stats Block (All Stats Not Shown Are 0) "
10021 "---------------\n");
10023 BCE_PRINT_64BIT_STAT(stat_IfHCInOctets);
10024 BCE_PRINT_64BIT_STAT(stat_IfHCInBadOctets);
10025 BCE_PRINT_64BIT_STAT(stat_IfHCOutOctets);
10026 BCE_PRINT_64BIT_STAT(stat_IfHCOutBadOctets);
10027 BCE_PRINT_64BIT_STAT(stat_IfHCInUcastPkts);
10028 BCE_PRINT_64BIT_STAT(stat_IfHCInBroadcastPkts);
10029 BCE_PRINT_64BIT_STAT(stat_IfHCInMulticastPkts);
10030 BCE_PRINT_64BIT_STAT(stat_IfHCOutUcastPkts);
10031 BCE_PRINT_64BIT_STAT(stat_IfHCOutBroadcastPkts);
10032 BCE_PRINT_64BIT_STAT(stat_IfHCOutMulticastPkts);
10033 BCE_PRINT_32BIT_STAT(
10034 stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
10035 BCE_PRINT_32BIT_STAT(stat_Dot3StatsCarrierSenseErrors);
10036 BCE_PRINT_32BIT_STAT(stat_Dot3StatsFCSErrors);
10037 BCE_PRINT_32BIT_STAT(stat_Dot3StatsAlignmentErrors);
10038 BCE_PRINT_32BIT_STAT(stat_Dot3StatsSingleCollisionFrames);
10039 BCE_PRINT_32BIT_STAT(stat_Dot3StatsMultipleCollisionFrames);
10040 BCE_PRINT_32BIT_STAT(stat_Dot3StatsDeferredTransmissions);
10041 BCE_PRINT_32BIT_STAT(stat_Dot3StatsExcessiveCollisions);
10042 BCE_PRINT_32BIT_STAT(stat_Dot3StatsLateCollisions);
10043 BCE_PRINT_32BIT_STAT(stat_EtherStatsCollisions);
10044 BCE_PRINT_32BIT_STAT(stat_EtherStatsFragments);
10045 BCE_PRINT_32BIT_STAT(stat_EtherStatsJabbers);
10046 BCE_PRINT_32BIT_STAT(stat_EtherStatsUndersizePkts);
10047 BCE_PRINT_32BIT_STAT(stat_EtherStatsOversizePkts);
10048 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx64Octets);
10049 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx65Octetsto127Octets);
10050 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx128Octetsto255Octets);
10051 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx256Octetsto511Octets);
10052 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx512Octetsto1023Octets);
10053 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx1024Octetsto1522Octets);
10054 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx1523Octetsto9022Octets);
10055 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx64Octets);
10056 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx65Octetsto127Octets);
10057 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx128Octetsto255Octets);
10058 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx256Octetsto511Octets);
10059 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx512Octetsto1023Octets);
10060 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx1024Octetsto1522Octets);
10061 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx1523Octetsto9022Octets);
10062 BCE_PRINT_32BIT_STAT(stat_XonPauseFramesReceived);
10063 BCE_PRINT_32BIT_STAT(stat_XoffPauseFramesReceived);
10064 BCE_PRINT_32BIT_STAT(stat_OutXonSent);
10065 BCE_PRINT_32BIT_STAT(stat_OutXoffSent);
10066 BCE_PRINT_32BIT_STAT(stat_FlowControlDone);
10067 BCE_PRINT_32BIT_STAT(stat_MacControlFramesReceived);
10068 BCE_PRINT_32BIT_STAT(stat_XoffStateEntered);
10069 BCE_PRINT_32BIT_STAT(stat_IfInFramesL2FilterDiscards);
10070 BCE_PRINT_32BIT_STAT(stat_IfInRuleCheckerDiscards);
10071 BCE_PRINT_32BIT_STAT(stat_IfInFTQDiscards);
10072 BCE_PRINT_32BIT_STAT(stat_IfInMBUFDiscards);
10073 BCE_PRINT_32BIT_STAT(stat_IfInRuleCheckerP4Hit);
10074 BCE_PRINT_32BIT_STAT(stat_CatchupInRuleCheckerDiscards);
10075 BCE_PRINT_32BIT_STAT(stat_CatchupInFTQDiscards);
10076 BCE_PRINT_32BIT_STAT(stat_CatchupInMBUFDiscards);
10077 BCE_PRINT_32BIT_STAT(stat_CatchupInRuleCheckerP4Hit);
10080 "----------------------------"
10082 "----------------------------\n");
10086 /****************************************************************************/
10087 /* Prints out a summary of the driver state. */
10091 /****************************************************************************/
10092 static __attribute__ ((noinline)) void
10093 bce_dump_driver_state(struct bce_softc *sc)
10095 u32 val_hi, val_lo;
10098 "-----------------------------"
10100 "-----------------------------\n");
10102 val_hi = BCE_ADDR_HI(sc);
10103 val_lo = BCE_ADDR_LO(sc);
10104 BCE_PRINTF("0x%08X:%08X - (sc) driver softc structure virtual "
10105 "address\n", val_hi, val_lo);
10107 val_hi = BCE_ADDR_HI(sc->bce_vhandle);
10108 val_lo = BCE_ADDR_LO(sc->bce_vhandle);
10109 BCE_PRINTF("0x%08X:%08X - (sc->bce_vhandle) PCI BAR virtual "
10110 "address\n", val_hi, val_lo);
10112 val_hi = BCE_ADDR_HI(sc->status_block);
10113 val_lo = BCE_ADDR_LO(sc->status_block);
10114 BCE_PRINTF("0x%08X:%08X - (sc->status_block) status block "
10115 "virtual address\n", val_hi, val_lo);
10117 val_hi = BCE_ADDR_HI(sc->stats_block);
10118 val_lo = BCE_ADDR_LO(sc->stats_block);
10119 BCE_PRINTF("0x%08X:%08X - (sc->stats_block) statistics block "
10120 "virtual address\n", val_hi, val_lo);
10122 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
10123 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
10124 BCE_PRINTF("0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
10125 "virtual adddress\n", val_hi, val_lo);
10127 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
10128 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
10129 BCE_PRINTF("0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
10130 "virtual address\n", val_hi, val_lo);
10132 #ifdef BCE_JUMBO_HDRSPLIT
10133 val_hi = BCE_ADDR_HI(sc->pg_bd_chain);
10134 val_lo = BCE_ADDR_LO(sc->pg_bd_chain);
10135 BCE_PRINTF("0x%08X:%08X - (sc->pg_bd_chain) page chain "
10136 "virtual address\n", val_hi, val_lo);
10139 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
10140 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
10141 BCE_PRINTF("0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
10142 "virtual address\n", val_hi, val_lo);
10144 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
10145 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
10146 BCE_PRINTF("0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
10147 "virtual address\n", val_hi, val_lo);
10149 #ifdef BCE_JUMBO_HDRSPLIT
10150 val_hi = BCE_ADDR_HI(sc->pg_mbuf_ptr);
10151 val_lo = BCE_ADDR_LO(sc->pg_mbuf_ptr);
10152 BCE_PRINTF("0x%08X:%08X - (sc->pg_mbuf_ptr) page mbuf chain "
10153 "virtual address\n", val_hi, val_lo);
10156 BCE_PRINTF(" 0x%08X - (sc->interrupts_generated) "
10157 "h/w intrs\n", sc->interrupts_generated);
10159 BCE_PRINTF(" 0x%08X - (sc->interrupts_rx) "
10160 "rx interrupts handled\n", sc->interrupts_rx);
10162 BCE_PRINTF(" 0x%08X - (sc->interrupts_tx) "
10163 "tx interrupts handled\n", sc->interrupts_tx);
10165 BCE_PRINTF(" 0x%08X - (sc->phy_interrupts) "
10166 "phy interrupts handled\n", sc->phy_interrupts);
10168 BCE_PRINTF(" 0x%08X - (sc->last_status_idx) "
10169 "status block index\n", sc->last_status_idx);
10171 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->tx_prod) tx producer "
10172 "index\n", sc->tx_prod, (u16) TX_CHAIN_IDX(sc->tx_prod));
10174 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->tx_cons) tx consumer "
10175 "index\n", sc->tx_cons, (u16) TX_CHAIN_IDX(sc->tx_cons));
10177 BCE_PRINTF(" 0x%08X - (sc->tx_prod_bseq) tx producer "
10178 "byte seq index\n", sc->tx_prod_bseq);
10180 BCE_PRINTF(" 0x%08X - (sc->debug_tx_mbuf_alloc) tx "
10181 "mbufs allocated\n", sc->debug_tx_mbuf_alloc);
10183 BCE_PRINTF(" 0x%08X - (sc->used_tx_bd) used "
10184 "tx_bd's\n", sc->used_tx_bd);
10186 BCE_PRINTF("0x%08X/%08X - (sc->tx_hi_watermark) tx hi "
10187 "watermark\n", sc->tx_hi_watermark, sc->max_tx_bd);
10189 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->rx_prod) rx producer "
10190 "index\n", sc->rx_prod, (u16) RX_CHAIN_IDX(sc->rx_prod));
10192 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->rx_cons) rx consumer "
10193 "index\n", sc->rx_cons, (u16) RX_CHAIN_IDX(sc->rx_cons));
10195 BCE_PRINTF(" 0x%08X - (sc->rx_prod_bseq) rx producer "
10196 "byte seq index\n", sc->rx_prod_bseq);
10198 BCE_PRINTF(" 0x%08X - (sc->debug_rx_mbuf_alloc) rx "
10199 "mbufs allocated\n", sc->debug_rx_mbuf_alloc);
10201 BCE_PRINTF(" 0x%08X - (sc->free_rx_bd) free "
10202 "rx_bd's\n", sc->free_rx_bd);
10204 #ifdef BCE_JUMBO_HDRSPLIT
10205 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->pg_prod) page producer "
10206 "index\n", sc->pg_prod, (u16) PG_CHAIN_IDX(sc->pg_prod));
10208 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->pg_cons) page consumer "
10209 "index\n", sc->pg_cons, (u16) PG_CHAIN_IDX(sc->pg_cons));
10211 BCE_PRINTF(" 0x%08X - (sc->debug_pg_mbuf_alloc) page "
10212 "mbufs allocated\n", sc->debug_pg_mbuf_alloc);
10214 BCE_PRINTF(" 0x%08X - (sc->free_pg_bd) free page "
10215 "rx_bd's\n", sc->free_pg_bd);
10217 BCE_PRINTF("0x%08X/%08X - (sc->pg_low_watermark) page low "
10218 "watermark\n", sc->pg_low_watermark, sc->max_pg_bd);
10221 BCE_PRINTF(" 0x%08X - (sc->mbuf_alloc_failed_count) "
10222 "mbuf alloc failures\n", sc->mbuf_alloc_failed_count);
10224 BCE_PRINTF(" 0x%08X - (sc->bce_flags) "
10225 "bce mac flags\n", sc->bce_flags);
10227 BCE_PRINTF(" 0x%08X - (sc->bce_phy_flags) "
10228 "bce phy flags\n", sc->bce_phy_flags);
10231 "----------------------------"
10233 "----------------------------\n");
10237 /****************************************************************************/
10238 /* Prints out the hardware state through a summary of important register, */
10239 /* followed by a complete register dump. */
10243 /****************************************************************************/
10244 static __attribute__ ((noinline)) void
10245 bce_dump_hw_state(struct bce_softc *sc)
10250 "----------------------------"
10252 "----------------------------\n");
10254 BCE_PRINTF("%s - bootcode version\n", sc->bce_bc_ver);
10256 val = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
10257 BCE_PRINTF("0x%08X - (0x%06X) misc_enable_status_bits\n",
10258 val, BCE_MISC_ENABLE_STATUS_BITS);
10260 val = REG_RD(sc, BCE_DMA_STATUS);
10261 BCE_PRINTF("0x%08X - (0x%06X) dma_status\n",
10262 val, BCE_DMA_STATUS);
10264 val = REG_RD(sc, BCE_CTX_STATUS);
10265 BCE_PRINTF("0x%08X - (0x%06X) ctx_status\n",
10266 val, BCE_CTX_STATUS);
10268 val = REG_RD(sc, BCE_EMAC_STATUS);
10269 BCE_PRINTF("0x%08X - (0x%06X) emac_status\n",
10270 val, BCE_EMAC_STATUS);
10272 val = REG_RD(sc, BCE_RPM_STATUS);
10273 BCE_PRINTF("0x%08X - (0x%06X) rpm_status\n",
10274 val, BCE_RPM_STATUS);
10276 /* ToDo: Create a #define for this constant. */
10277 val = REG_RD(sc, 0x2004);
10278 BCE_PRINTF("0x%08X - (0x%06X) rlup_status\n",
10281 val = REG_RD(sc, BCE_RV2P_STATUS);
10282 BCE_PRINTF("0x%08X - (0x%06X) rv2p_status\n",
10283 val, BCE_RV2P_STATUS);
10285 /* ToDo: Create a #define for this constant. */
10286 val = REG_RD(sc, 0x2c04);
10287 BCE_PRINTF("0x%08X - (0x%06X) rdma_status\n",
10290 val = REG_RD(sc, BCE_TBDR_STATUS);
10291 BCE_PRINTF("0x%08X - (0x%06X) tbdr_status\n",
10292 val, BCE_TBDR_STATUS);
10294 val = REG_RD(sc, BCE_TDMA_STATUS);
10295 BCE_PRINTF("0x%08X - (0x%06X) tdma_status\n",
10296 val, BCE_TDMA_STATUS);
10298 val = REG_RD(sc, BCE_HC_STATUS);
10299 BCE_PRINTF("0x%08X - (0x%06X) hc_status\n",
10300 val, BCE_HC_STATUS);
10302 val = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
10303 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_state\n",
10304 val, BCE_TXP_CPU_STATE);
10306 val = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
10307 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_state\n",
10308 val, BCE_TPAT_CPU_STATE);
10310 val = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
10311 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_state\n",
10312 val, BCE_RXP_CPU_STATE);
10314 val = REG_RD_IND(sc, BCE_COM_CPU_STATE);
10315 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_state\n",
10316 val, BCE_COM_CPU_STATE);
10318 val = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
10319 BCE_PRINTF("0x%08X - (0x%06X) mcp_cpu_state\n",
10320 val, BCE_MCP_CPU_STATE);
10322 val = REG_RD_IND(sc, BCE_CP_CPU_STATE);
10323 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_state\n",
10324 val, BCE_CP_CPU_STATE);
10327 "----------------------------"
10329 "----------------------------\n");
10332 "----------------------------"
10334 "----------------------------\n");
10336 for (int i = 0x400; i < 0x8000; i += 0x10) {
10337 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
10338 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
10339 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
10343 "----------------------------"
10345 "----------------------------\n");
10349 /****************************************************************************/
10350 /* Prints out the mailbox queue registers. */
10354 /****************************************************************************/
10355 static __attribute__ ((noinline)) void
10356 bce_dump_mq_regs(struct bce_softc *sc)
10359 "----------------------------"
10361 "----------------------------\n");
10364 "----------------------------"
10366 "----------------------------\n");
10368 for (int i = 0x3c00; i < 0x4000; i += 0x10) {
10369 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
10370 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
10371 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
10375 "----------------------------"
10377 "----------------------------\n");
10381 /****************************************************************************/
10382 /* Prints out the bootcode state. */
10386 /****************************************************************************/
10387 static __attribute__ ((noinline)) void
10388 bce_dump_bc_state(struct bce_softc *sc)
10393 "----------------------------"
10395 "----------------------------\n");
10397 BCE_PRINTF("%s - bootcode version\n", sc->bce_bc_ver);
10399 val = bce_shmem_rd(sc, BCE_BC_RESET_TYPE);
10400 BCE_PRINTF("0x%08X - (0x%06X) reset_type\n",
10401 val, BCE_BC_RESET_TYPE);
10403 val = bce_shmem_rd(sc, BCE_BC_STATE);
10404 BCE_PRINTF("0x%08X - (0x%06X) state\n",
10405 val, BCE_BC_STATE);
10407 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
10408 BCE_PRINTF("0x%08X - (0x%06X) condition\n",
10409 val, BCE_BC_STATE_CONDITION);
10411 val = bce_shmem_rd(sc, BCE_BC_STATE_DEBUG_CMD);
10412 BCE_PRINTF("0x%08X - (0x%06X) debug_cmd\n",
10413 val, BCE_BC_STATE_DEBUG_CMD);
10416 "----------------------------"
10418 "----------------------------\n");
10422 /****************************************************************************/
10423 /* Prints out the TXP processor state. */
10427 /****************************************************************************/
10428 static __attribute__ ((noinline)) void
10429 bce_dump_txp_state(struct bce_softc *sc, int regs)
10435 "----------------------------"
10437 "----------------------------\n");
10439 for (int i = 0; i < 3; i++)
10440 fw_version[i] = htonl(REG_RD_IND(sc,
10441 (BCE_TXP_SCRATCH + 0x10 + i * 4)));
10442 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10444 val = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
10445 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_mode\n",
10446 val, BCE_TXP_CPU_MODE);
10448 val = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
10449 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_state\n",
10450 val, BCE_TXP_CPU_STATE);
10452 val = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
10453 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_event_mask\n",
10454 val, BCE_TXP_CPU_EVENT_MASK);
10458 "----------------------------"
10460 "----------------------------\n");
10462 for (int i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
10463 /* Skip the big blank spaces */
10464 if (i < 0x454000 && i > 0x5ffff)
10465 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
10466 "0x%08X 0x%08X\n", i,
10468 REG_RD_IND(sc, i + 0x4),
10469 REG_RD_IND(sc, i + 0x8),
10470 REG_RD_IND(sc, i + 0xC));
10475 "----------------------------"
10477 "----------------------------\n");
10481 /****************************************************************************/
10482 /* Prints out the RXP processor state. */
10486 /****************************************************************************/
10487 static __attribute__ ((noinline)) void
10488 bce_dump_rxp_state(struct bce_softc *sc, int regs)
10494 "----------------------------"
10496 "----------------------------\n");
10498 for (int i = 0; i < 3; i++)
10499 fw_version[i] = htonl(REG_RD_IND(sc,
10500 (BCE_RXP_SCRATCH + 0x10 + i * 4)));
10502 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10504 val = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
10505 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_mode\n",
10506 val, BCE_RXP_CPU_MODE);
10508 val = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
10509 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_state\n",
10510 val, BCE_RXP_CPU_STATE);
10512 val = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
10513 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_event_mask\n",
10514 val, BCE_RXP_CPU_EVENT_MASK);
10518 "----------------------------"
10520 "----------------------------\n");
10522 for (int i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
10523 /* Skip the big blank sapces */
10524 if (i < 0xc5400 && i > 0xdffff)
10525 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
10526 "0x%08X 0x%08X\n", i,
10528 REG_RD_IND(sc, i + 0x4),
10529 REG_RD_IND(sc, i + 0x8),
10530 REG_RD_IND(sc, i + 0xC));
10535 "----------------------------"
10537 "----------------------------\n");
10541 /****************************************************************************/
10542 /* Prints out the TPAT processor state. */
10546 /****************************************************************************/
10547 static __attribute__ ((noinline)) void
10548 bce_dump_tpat_state(struct bce_softc *sc, int regs)
10554 "----------------------------"
10556 "----------------------------\n");
10558 for (int i = 0; i < 3; i++)
10559 fw_version[i] = htonl(REG_RD_IND(sc,
10560 (BCE_TPAT_SCRATCH + 0x410 + i * 4)));
10562 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10564 val = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
10565 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_mode\n",
10566 val, BCE_TPAT_CPU_MODE);
10568 val = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
10569 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_state\n",
10570 val, BCE_TPAT_CPU_STATE);
10572 val = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
10573 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_event_mask\n",
10574 val, BCE_TPAT_CPU_EVENT_MASK);
10578 "----------------------------"
10580 "----------------------------\n");
10582 for (int i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
10583 /* Skip the big blank spaces */
10584 if (i < 0x854000 && i > 0x9ffff)
10585 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
10586 "0x%08X 0x%08X\n", i,
10588 REG_RD_IND(sc, i + 0x4),
10589 REG_RD_IND(sc, i + 0x8),
10590 REG_RD_IND(sc, i + 0xC));
10595 "----------------------------"
10597 "----------------------------\n");
10601 /****************************************************************************/
10602 /* Prints out the Command Procesor (CP) state. */
10606 /****************************************************************************/
10607 static __attribute__ ((noinline)) void
10608 bce_dump_cp_state(struct bce_softc *sc, int regs)
10614 "----------------------------"
10616 "----------------------------\n");
10618 for (int i = 0; i < 3; i++)
10619 fw_version[i] = htonl(REG_RD_IND(sc,
10620 (BCE_CP_SCRATCH + 0x10 + i * 4)));
10622 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10624 val = REG_RD_IND(sc, BCE_CP_CPU_MODE);
10625 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_mode\n",
10626 val, BCE_CP_CPU_MODE);
10628 val = REG_RD_IND(sc, BCE_CP_CPU_STATE);
10629 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_state\n",
10630 val, BCE_CP_CPU_STATE);
10632 val = REG_RD_IND(sc, BCE_CP_CPU_EVENT_MASK);
10633 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_event_mask\n", val,
10634 BCE_CP_CPU_EVENT_MASK);
10638 "----------------------------"
10640 "----------------------------\n");
10642 for (int i = BCE_CP_CPU_MODE; i < 0x1aa000; i += 0x10) {
10643 /* Skip the big blank spaces */
10644 if (i < 0x185400 && i > 0x19ffff)
10645 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
10646 "0x%08X 0x%08X\n", i,
10648 REG_RD_IND(sc, i + 0x4),
10649 REG_RD_IND(sc, i + 0x8),
10650 REG_RD_IND(sc, i + 0xC));
10655 "----------------------------"
10657 "----------------------------\n");
10661 /****************************************************************************/
10662 /* Prints out the Completion Procesor (COM) state. */
10666 /****************************************************************************/
10667 static __attribute__ ((noinline)) void
10668 bce_dump_com_state(struct bce_softc *sc, int regs)
10674 "----------------------------"
10676 "----------------------------\n");
10678 for (int i = 0; i < 3; i++)
10679 fw_version[i] = htonl(REG_RD_IND(sc,
10680 (BCE_COM_SCRATCH + 0x10 + i * 4)));
10682 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10684 val = REG_RD_IND(sc, BCE_COM_CPU_MODE);
10685 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_mode\n",
10686 val, BCE_COM_CPU_MODE);
10688 val = REG_RD_IND(sc, BCE_COM_CPU_STATE);
10689 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_state\n",
10690 val, BCE_COM_CPU_STATE);
10692 val = REG_RD_IND(sc, BCE_COM_CPU_EVENT_MASK);
10693 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_event_mask\n", val,
10694 BCE_COM_CPU_EVENT_MASK);
10698 "----------------------------"
10700 "----------------------------\n");
10702 for (int i = BCE_COM_CPU_MODE; i < 0x1053e8; i += 0x10) {
10703 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
10704 "0x%08X 0x%08X\n", i,
10706 REG_RD_IND(sc, i + 0x4),
10707 REG_RD_IND(sc, i + 0x8),
10708 REG_RD_IND(sc, i + 0xC));
10713 "----------------------------"
10715 "----------------------------\n");
10719 /****************************************************************************/
10720 /* Prints out the Receive Virtual 2 Physical (RV2P) state. */
10724 /****************************************************************************/
10725 static __attribute__ ((noinline)) void
10726 bce_dump_rv2p_state(struct bce_softc *sc)
10728 u32 val, pc1, pc2, fw_ver_high, fw_ver_low;
10731 "----------------------------"
10733 "----------------------------\n");
10735 /* Stall the RV2P processors. */
10736 val = REG_RD_IND(sc, BCE_RV2P_CONFIG);
10737 val |= BCE_RV2P_CONFIG_STALL_PROC1 | BCE_RV2P_CONFIG_STALL_PROC2;
10738 REG_WR_IND(sc, BCE_RV2P_CONFIG, val);
10740 /* Read the firmware version. */
10742 REG_WR_IND(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
10743 fw_ver_low = REG_RD_IND(sc, BCE_RV2P_INSTR_LOW);
10744 fw_ver_high = REG_RD_IND(sc, BCE_RV2P_INSTR_HIGH) &
10745 BCE_RV2P_INSTR_HIGH_HIGH;
10746 BCE_PRINTF("RV2P1 Firmware version - 0x%08X:0x%08X\n",
10747 fw_ver_high, fw_ver_low);
10750 REG_WR_IND(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
10751 fw_ver_low = REG_RD_IND(sc, BCE_RV2P_INSTR_LOW);
10752 fw_ver_high = REG_RD_IND(sc, BCE_RV2P_INSTR_HIGH) &
10753 BCE_RV2P_INSTR_HIGH_HIGH;
10754 BCE_PRINTF("RV2P2 Firmware version - 0x%08X:0x%08X\n",
10755 fw_ver_high, fw_ver_low);
10757 /* Resume the RV2P processors. */
10758 val = REG_RD_IND(sc, BCE_RV2P_CONFIG);
10759 val &= ~(BCE_RV2P_CONFIG_STALL_PROC1 | BCE_RV2P_CONFIG_STALL_PROC2);
10760 REG_WR_IND(sc, BCE_RV2P_CONFIG, val);
10762 /* Fetch the program counter value. */
10764 REG_WR_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK, val);
10765 val = REG_RD_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK);
10766 pc1 = (val & BCE_RV2P_DEBUG_VECT_PEEK_1_VALUE);
10767 pc2 = (val & BCE_RV2P_DEBUG_VECT_PEEK_2_VALUE) >> 16;
10768 BCE_PRINTF("0x%08X - RV2P1 program counter (1st read)\n", pc1);
10769 BCE_PRINTF("0x%08X - RV2P2 program counter (1st read)\n", pc2);
10771 /* Fetch the program counter value again to see if it is advancing. */
10773 REG_WR_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK, val);
10774 val = REG_RD_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK);
10775 pc1 = (val & BCE_RV2P_DEBUG_VECT_PEEK_1_VALUE);
10776 pc2 = (val & BCE_RV2P_DEBUG_VECT_PEEK_2_VALUE) >> 16;
10777 BCE_PRINTF("0x%08X - RV2P1 program counter (2nd read)\n", pc1);
10778 BCE_PRINTF("0x%08X - RV2P2 program counter (2nd read)\n", pc2);
10781 "----------------------------"
10783 "----------------------------\n");
10787 /****************************************************************************/
10788 /* Prints out the driver state and then enters the debugger. */
10792 /****************************************************************************/
10793 static __attribute__ ((noinline)) void
10794 bce_breakpoint(struct bce_softc *sc)
10798 * Unreachable code to silence compiler warnings
10799 * about unused functions.
10802 bce_freeze_controller(sc);
10803 bce_unfreeze_controller(sc);
10804 bce_dump_enet(sc, NULL);
10805 bce_dump_txbd(sc, 0, NULL);
10806 bce_dump_rxbd(sc, 0, NULL);
10807 bce_dump_tx_mbuf_chain(sc, 0, USABLE_TX_BD);
10808 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD);
10809 bce_dump_l2fhdr(sc, 0, NULL);
10810 bce_dump_ctx(sc, RX_CID);
10812 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
10813 bce_dump_rx_bd_chain(sc, 0, USABLE_RX_BD);
10814 bce_dump_status_block(sc);
10815 bce_dump_stats_block(sc);
10816 bce_dump_driver_state(sc);
10817 bce_dump_hw_state(sc);
10818 bce_dump_bc_state(sc);
10819 bce_dump_txp_state(sc, 0);
10820 bce_dump_rxp_state(sc, 0);
10821 bce_dump_tpat_state(sc, 0);
10822 bce_dump_cp_state(sc, 0);
10823 bce_dump_com_state(sc, 0);
10824 bce_dump_rv2p_state(sc);
10826 #ifdef BCE_JUMBO_HDRSPLIT
10827 bce_dump_pgbd(sc, 0, NULL);
10828 bce_dump_pg_mbuf_chain(sc, 0, USABLE_PG_BD);
10829 bce_dump_pg_chain(sc, 0, USABLE_PG_BD);
10833 bce_dump_status_block(sc);
10834 bce_dump_driver_state(sc);
10836 /* Call the debugger. */