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 /* PCI Device ID Table */
94 /* Used by bce_probe() to identify the devices supported by this driver. */
95 /****************************************************************************/
96 #define BCE_DEVDESC_MAX 64
98 static struct bce_type bce_devs[] = {
99 /* BCM5706C Controllers and OEM boards. */
100 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
101 "HP NC370T Multifunction Gigabit Server Adapter" },
102 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
103 "HP NC370i Multifunction Gigabit Server Adapter" },
104 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3070,
105 "HP NC380T PCIe DP Multifunc Gig Server Adapter" },
106 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x1709,
107 "HP NC371i Multifunction Gigabit Server Adapter" },
108 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
109 "Broadcom NetXtreme II BCM5706 1000Base-T" },
111 /* BCM5706S controllers and OEM boards. */
112 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
113 "HP NC370F Multifunction Gigabit Server Adapter" },
114 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
115 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
117 /* BCM5708C controllers and OEM boards. */
118 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7037,
119 "HP NC373T PCIe Multifunction Gig Server Adapter" },
120 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7038,
121 "HP NC373i Multifunction Gigabit Server Adapter" },
122 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7045,
123 "HP NC374m PCIe Multifunction Adapter" },
124 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
125 "Broadcom NetXtreme II BCM5708 1000Base-T" },
127 /* BCM5708S controllers and OEM boards. */
128 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x1706,
129 "HP NC373m Multifunction Gigabit Server Adapter" },
130 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703b,
131 "HP NC373i Multifunction Gigabit Server Adapter" },
132 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703d,
133 "HP NC373F PCIe Multifunc Giga Server Adapter" },
134 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
135 "Broadcom NetXtreme II BCM5708 1000Base-SX" },
137 /* BCM5709C controllers and OEM boards. */
138 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7055,
139 "HP NC382i DP Multifunction Gigabit Server Adapter" },
140 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7059,
141 "HP NC382T PCIe DP Multifunction Gigabit Server Adapter" },
142 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, PCI_ANY_ID, PCI_ANY_ID,
143 "Broadcom NetXtreme II BCM5709 1000Base-T" },
145 /* BCM5709S controllers and OEM boards. */
146 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x171d,
147 "HP NC382m DP 1GbE Multifunction BL-c Adapter" },
148 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x7056,
149 "HP NC382i DP Multifunction Gigabit Server Adapter" },
150 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, PCI_ANY_ID, PCI_ANY_ID,
151 "Broadcom NetXtreme II BCM5709 1000Base-SX" },
153 /* BCM5716 controllers and OEM boards. */
154 { BRCM_VENDORID, BRCM_DEVICEID_BCM5716, PCI_ANY_ID, PCI_ANY_ID,
155 "Broadcom NetXtreme II BCM5716 1000Base-T" },
161 /****************************************************************************/
162 /* Supported Flash NVRAM device data. */
163 /****************************************************************************/
164 static struct flash_spec flash_table[] =
166 #define BUFFERED_FLAGS (BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
167 #define NONBUFFERED_FLAGS (BCE_NV_WREN)
170 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
171 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
172 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
174 /* Expansion entry 0001 */
175 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
176 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
177 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
179 /* Saifun SA25F010 (non-buffered flash) */
180 /* strap, cfg1, & write1 need updates */
181 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
182 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
183 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
184 "Non-buffered flash (128kB)"},
185 /* Saifun SA25F020 (non-buffered flash) */
186 /* strap, cfg1, & write1 need updates */
187 {0x0c000003, 0x4f808201, 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*4,
190 "Non-buffered flash (256kB)"},
191 /* Expansion entry 0100 */
192 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
193 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
194 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
196 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
197 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
198 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
199 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
200 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
201 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
202 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
203 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
204 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
205 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
206 /* Saifun SA25F005 (non-buffered flash) */
207 /* strap, cfg1, & write1 need updates */
208 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
209 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
210 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
211 "Non-buffered flash (64kB)"},
213 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
214 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
215 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
217 /* Expansion entry 1001 */
218 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
219 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
220 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
222 /* Expansion entry 1010 */
223 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
224 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
225 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
227 /* ATMEL AT45DB011B (buffered flash) */
228 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
229 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
230 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
231 "Buffered flash (128kB)"},
232 /* Expansion entry 1100 */
233 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
234 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
235 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
237 /* Expansion entry 1101 */
238 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
239 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
240 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
242 /* Ateml Expansion entry 1110 */
243 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
244 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
245 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
246 "Entry 1110 (Atmel)"},
247 /* ATMEL AT45DB021B (buffered flash) */
248 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
249 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
250 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
251 "Buffered flash (256kB)"},
255 * The BCM5709 controllers transparently handle the
256 * differences between Atmel 264 byte pages and all
257 * flash devices which use 256 byte pages, so no
258 * logical-to-physical mapping is required in the
261 static struct flash_spec flash_5709 = {
262 .flags = BCE_NV_BUFFERED,
263 .page_bits = BCM5709_FLASH_PAGE_BITS,
264 .page_size = BCM5709_FLASH_PAGE_SIZE,
265 .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
266 .total_size = BUFFERED_FLASH_TOTAL_SIZE * 2,
267 .name = "5709/5716 buffered flash (256kB)",
271 /****************************************************************************/
272 /* FreeBSD device entry points. */
273 /****************************************************************************/
274 static int bce_probe (device_t);
275 static int bce_attach (device_t);
276 static int bce_detach (device_t);
277 static int bce_shutdown (device_t);
280 /****************************************************************************/
281 /* BCE Debug Data Structure Dump Routines */
282 /****************************************************************************/
284 static u32 bce_reg_rd (struct bce_softc *, u32);
285 static void bce_reg_wr (struct bce_softc *, u32, u32);
286 static void bce_reg_wr16 (struct bce_softc *, u32, u16);
287 static u32 bce_ctx_rd (struct bce_softc *, u32, u32);
288 static void bce_dump_enet (struct bce_softc *, struct mbuf *);
289 static void bce_dump_mbuf (struct bce_softc *, struct mbuf *);
290 static void bce_dump_tx_mbuf_chain (struct bce_softc *, u16, int);
291 static void bce_dump_rx_mbuf_chain (struct bce_softc *, u16, int);
292 static void bce_dump_pg_mbuf_chain (struct bce_softc *, u16, int);
293 static void bce_dump_txbd (struct bce_softc *,
294 int, struct tx_bd *);
295 static void bce_dump_rxbd (struct bce_softc *,
296 int, struct rx_bd *);
297 static void bce_dump_pgbd (struct bce_softc *,
298 int, struct rx_bd *);
299 static void bce_dump_l2fhdr (struct bce_softc *,
300 int, struct l2_fhdr *);
301 static void bce_dump_ctx (struct bce_softc *, u16);
302 static void bce_dump_ftqs (struct bce_softc *);
303 static void bce_dump_tx_chain (struct bce_softc *, u16, int);
304 static void bce_dump_rx_bd_chain (struct bce_softc *, u16, int);
305 static void bce_dump_pg_chain (struct bce_softc *, u16, int);
306 static void bce_dump_status_block (struct bce_softc *);
307 static void bce_dump_stats_block (struct bce_softc *);
308 static void bce_dump_driver_state (struct bce_softc *);
309 static void bce_dump_hw_state (struct bce_softc *);
310 static void bce_dump_shmem_state (struct bce_softc *);
311 static void bce_dump_mq_regs (struct bce_softc *);
312 static void bce_dump_bc_state (struct bce_softc *);
313 static void bce_dump_txp_state (struct bce_softc *, int);
314 static void bce_dump_rxp_state (struct bce_softc *, int);
315 static void bce_dump_tpat_state (struct bce_softc *, int);
316 static void bce_dump_cp_state (struct bce_softc *, int);
317 static void bce_dump_com_state (struct bce_softc *, int);
318 static void bce_dump_rv2p_state (struct bce_softc *);
319 static void bce_breakpoint (struct bce_softc *);
320 #endif /*BCE_DEBUG */
323 /****************************************************************************/
324 /* BCE Register/Memory Access Routines */
325 /****************************************************************************/
326 static u32 bce_reg_rd_ind (struct bce_softc *, u32);
327 static void bce_reg_wr_ind (struct bce_softc *, u32, u32);
328 static void bce_shmem_wr (struct bce_softc *, u32, u32);
329 static u32 bce_shmem_rd (struct bce_softc *, u32);
330 static void bce_ctx_wr (struct bce_softc *, u32, u32, u32);
331 static int bce_miibus_read_reg (device_t, int, int);
332 static int bce_miibus_write_reg (device_t, int, int, int);
333 static void bce_miibus_statchg (device_t);
336 static int bce_sysctl_nvram_dump(SYSCTL_HANDLER_ARGS);
337 #ifdef BCE_NVRAM_WRITE_SUPPORT
338 static int bce_sysctl_nvram_write(SYSCTL_HANDLER_ARGS);
342 /****************************************************************************/
343 /* BCE NVRAM Access Routines */
344 /****************************************************************************/
345 static int bce_acquire_nvram_lock (struct bce_softc *);
346 static int bce_release_nvram_lock (struct bce_softc *);
347 static void bce_enable_nvram_access(struct bce_softc *);
348 static void bce_disable_nvram_access(struct bce_softc *);
349 static int bce_nvram_read_dword (struct bce_softc *, u32, u8 *, u32);
350 static int bce_init_nvram (struct bce_softc *);
351 static int bce_nvram_read (struct bce_softc *, u32, u8 *, int);
352 static int bce_nvram_test (struct bce_softc *);
353 #ifdef BCE_NVRAM_WRITE_SUPPORT
354 static int bce_enable_nvram_write (struct bce_softc *);
355 static void bce_disable_nvram_write(struct bce_softc *);
356 static int bce_nvram_erase_page (struct bce_softc *, u32);
357 static int bce_nvram_write_dword (struct bce_softc *, u32, u8 *, u32);
358 static int bce_nvram_write (struct bce_softc *, u32, u8 *, int);
361 /****************************************************************************/
363 /****************************************************************************/
364 static void bce_get_rx_buffer_sizes(struct bce_softc *, int);
365 static void bce_get_media (struct bce_softc *);
366 static void bce_init_media (struct bce_softc *);
367 static void bce_dma_map_addr (void *, bus_dma_segment_t *, int, int);
368 static int bce_dma_alloc (device_t);
369 static void bce_dma_free (struct bce_softc *);
370 static void bce_release_resources (struct bce_softc *);
372 /****************************************************************************/
373 /* BCE Firmware Synchronization and Load */
374 /****************************************************************************/
375 static int bce_fw_sync (struct bce_softc *, u32);
376 static void bce_load_rv2p_fw (struct bce_softc *, u32 *, u32, u32);
377 static void bce_load_cpu_fw (struct bce_softc *,
378 struct cpu_reg *, struct fw_info *);
379 static void bce_start_cpu (struct bce_softc *, struct cpu_reg *);
380 static void bce_halt_cpu (struct bce_softc *, struct cpu_reg *);
381 static void bce_start_rxp_cpu (struct bce_softc *);
382 static void bce_init_rxp_cpu (struct bce_softc *);
383 static void bce_init_txp_cpu (struct bce_softc *);
384 static void bce_init_tpat_cpu (struct bce_softc *);
385 static void bce_init_cp_cpu (struct bce_softc *);
386 static void bce_init_com_cpu (struct bce_softc *);
387 static void bce_init_cpus (struct bce_softc *);
389 static void bce_print_adapter_info (struct bce_softc *);
390 static void bce_probe_pci_caps (device_t, struct bce_softc *);
391 static void bce_stop (struct bce_softc *);
392 static int bce_reset (struct bce_softc *, u32);
393 static int bce_chipinit (struct bce_softc *);
394 static int bce_blockinit (struct bce_softc *);
396 static int bce_init_tx_chain (struct bce_softc *);
397 static void bce_free_tx_chain (struct bce_softc *);
399 static int bce_get_rx_buf (struct bce_softc *,
400 struct mbuf *, u16 *, u16 *, u32 *);
401 static int bce_init_rx_chain (struct bce_softc *);
402 static void bce_fill_rx_chain (struct bce_softc *);
403 static void bce_free_rx_chain (struct bce_softc *);
405 static int bce_get_pg_buf (struct bce_softc *,
406 struct mbuf *, u16 *, u16 *);
407 static int bce_init_pg_chain (struct bce_softc *);
408 static void bce_fill_pg_chain (struct bce_softc *);
409 static void bce_free_pg_chain (struct bce_softc *);
411 static struct mbuf *bce_tso_setup (struct bce_softc *,
412 struct mbuf **, u16 *);
413 static int bce_tx_encap (struct bce_softc *, struct mbuf **);
414 static void bce_start_locked (struct ifnet *);
415 static void bce_start (struct ifnet *);
416 static int bce_ioctl (struct ifnet *, u_long, caddr_t);
417 static void bce_watchdog (struct bce_softc *);
418 static int bce_ifmedia_upd (struct ifnet *);
419 static int bce_ifmedia_upd_locked (struct ifnet *);
420 static void bce_ifmedia_sts (struct ifnet *, struct ifmediareq *);
421 static void bce_init_locked (struct bce_softc *);
422 static void bce_init (void *);
423 static void bce_mgmt_init_locked (struct bce_softc *sc);
425 static int bce_init_ctx (struct bce_softc *);
426 static void bce_get_mac_addr (struct bce_softc *);
427 static void bce_set_mac_addr (struct bce_softc *);
428 static void bce_phy_intr (struct bce_softc *);
429 static inline u16 bce_get_hw_rx_cons (struct bce_softc *);
430 static void bce_rx_intr (struct bce_softc *);
431 static void bce_tx_intr (struct bce_softc *);
432 static void bce_disable_intr (struct bce_softc *);
433 static void bce_enable_intr (struct bce_softc *, int);
435 static void bce_intr (void *);
436 static void bce_set_rx_mode (struct bce_softc *);
437 static void bce_stats_update (struct bce_softc *);
438 static void bce_tick (void *);
439 static void bce_pulse (void *);
440 static void bce_add_sysctls (struct bce_softc *);
443 /****************************************************************************/
444 /* FreeBSD device dispatch table. */
445 /****************************************************************************/
446 static device_method_t bce_methods[] = {
447 /* Device interface (device_if.h) */
448 DEVMETHOD(device_probe, bce_probe),
449 DEVMETHOD(device_attach, bce_attach),
450 DEVMETHOD(device_detach, bce_detach),
451 DEVMETHOD(device_shutdown, bce_shutdown),
452 /* Supported by device interface but not used here. */
453 /* DEVMETHOD(device_identify, bce_identify), */
454 /* DEVMETHOD(device_suspend, bce_suspend), */
455 /* DEVMETHOD(device_resume, bce_resume), */
456 /* DEVMETHOD(device_quiesce, bce_quiesce), */
458 /* Bus interface (bus_if.h) */
459 DEVMETHOD(bus_print_child, bus_generic_print_child),
460 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
462 /* MII interface (miibus_if.h) */
463 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
464 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
465 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
466 /* Supported by MII interface but not used here. */
467 /* DEVMETHOD(miibus_linkchg, bce_miibus_linkchg), */
468 /* DEVMETHOD(miibus_mediainit, bce_miibus_mediainit), */
473 static driver_t bce_driver = {
476 sizeof(struct bce_softc)
479 static devclass_t bce_devclass;
481 MODULE_DEPEND(bce, pci, 1, 1, 1);
482 MODULE_DEPEND(bce, ether, 1, 1, 1);
483 MODULE_DEPEND(bce, miibus, 1, 1, 1);
485 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
486 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
489 /****************************************************************************/
490 /* Tunable device values */
491 /****************************************************************************/
492 SYSCTL_NODE(_hw, OID_AUTO, bce, CTLFLAG_RD, 0, "bce driver parameters");
494 /* Allowable values are TRUE or FALSE */
495 static int bce_verbose = TRUE;
496 TUNABLE_INT("hw.bce.verbose", &bce_verbose);
497 SYSCTL_INT(_hw_bce, OID_AUTO, verbose, CTLFLAG_RDTUN, &bce_verbose, 0,
498 "Verbose output enable/disable");
500 /* Allowable values are TRUE or FALSE */
501 static int bce_tso_enable = TRUE;
502 TUNABLE_INT("hw.bce.tso_enable", &bce_tso_enable);
503 SYSCTL_INT(_hw_bce, OID_AUTO, tso_enable, CTLFLAG_RDTUN, &bce_tso_enable, 0,
504 "TSO Enable/Disable");
506 /* Allowable values are 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
507 /* ToDo: Add MSI-X support. */
508 static int bce_msi_enable = 1;
509 TUNABLE_INT("hw.bce.msi_enable", &bce_msi_enable);
510 SYSCTL_INT(_hw_bce, OID_AUTO, msi_enable, CTLFLAG_RDTUN, &bce_msi_enable, 0,
511 "MSI-X|MSI|INTx selector");
513 /* Allowable values are 1, 2, 4, 8. */
514 static int bce_rx_pages = DEFAULT_RX_PAGES;
515 TUNABLE_INT("hw.bce.rx_pages", &bce_rx_pages);
516 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_pages, CTLFLAG_RDTUN, &bce_rx_pages, 0,
517 "Receive buffer descriptor pages (1 page = 255 buffer descriptors)");
519 /* Allowable values are 1, 2, 4, 8. */
520 static int bce_tx_pages = DEFAULT_TX_PAGES;
521 TUNABLE_INT("hw.bce.tx_pages", &bce_tx_pages);
522 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_pages, CTLFLAG_RDTUN, &bce_tx_pages, 0,
523 "Transmit buffer descriptor pages (1 page = 255 buffer descriptors)");
525 /* Allowable values are TRUE or FALSE. */
526 static int bce_hdr_split = TRUE;
527 TUNABLE_INT("hw.bce.hdr_split", &bce_hdr_split);
528 SYSCTL_UINT(_hw_bce, OID_AUTO, hdr_split, CTLFLAG_RDTUN, &bce_hdr_split, 0,
529 "Frame header/payload splitting Enable/Disable");
531 /* Allowable values are TRUE or FALSE. */
532 static int bce_strict_rx_mtu = FALSE;
533 TUNABLE_INT("hw.bce.strict_rx_mtu", &bce_strict_rx_mtu);
534 SYSCTL_UINT(_hw_bce, OID_AUTO, loose_rx_mtu, CTLFLAG_RDTUN,
535 &bce_strict_rx_mtu, 0,
536 "Enable/Disable strict RX frame size checking");
538 /* Allowable values are 0 ... 100 */
540 /* Generate 1 interrupt for every transmit completion. */
541 static int bce_tx_quick_cons_trip_int = 1;
543 /* Generate 1 interrupt for every 20 transmit completions. */
544 static int bce_tx_quick_cons_trip_int = DEFAULT_TX_QUICK_CONS_TRIP_INT;
546 TUNABLE_INT("hw.bce.tx_quick_cons_trip_int", &bce_tx_quick_cons_trip_int);
547 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_quick_cons_trip_int, CTLFLAG_RDTUN,
548 &bce_tx_quick_cons_trip_int, 0,
549 "Transmit BD trip point during interrupts");
551 /* Allowable values are 0 ... 100 */
552 /* Generate 1 interrupt for every transmit completion. */
554 static int bce_tx_quick_cons_trip = 1;
556 /* Generate 1 interrupt for every 20 transmit completions. */
557 static int bce_tx_quick_cons_trip = DEFAULT_TX_QUICK_CONS_TRIP;
559 TUNABLE_INT("hw.bce.tx_quick_cons_trip", &bce_tx_quick_cons_trip);
560 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_quick_cons_trip, CTLFLAG_RDTUN,
561 &bce_tx_quick_cons_trip, 0,
562 "Transmit BD trip point");
564 /* Allowable values are 0 ... 100 */
566 /* Generate an interrupt if 0us have elapsed since the last TX completion. */
567 static int bce_tx_ticks_int = 0;
569 /* Generate an interrupt if 80us have elapsed since the last TX completion. */
570 static int bce_tx_ticks_int = DEFAULT_TX_TICKS_INT;
572 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
573 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_ticks_int, CTLFLAG_RDTUN,
574 &bce_tx_ticks_int, 0, "Transmit ticks count during interrupt");
576 /* Allowable values are 0 ... 100 */
578 /* Generate an interrupt if 0us have elapsed since the last TX completion. */
579 static int bce_tx_ticks = 0;
581 /* Generate an interrupt if 80us have elapsed since the last TX completion. */
582 static int bce_tx_ticks = DEFAULT_TX_TICKS;
584 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
585 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_ticks, CTLFLAG_RDTUN,
586 &bce_tx_ticks, 0, "Transmit ticks count");
588 /* Allowable values are 1 ... 100 */
590 /* Generate 1 interrupt for every received frame. */
591 static int bce_rx_quick_cons_trip_int = 1;
593 /* Generate 1 interrupt for every 6 received frames. */
594 static int bce_rx_quick_cons_trip_int = DEFAULT_RX_QUICK_CONS_TRIP_INT;
596 TUNABLE_INT("hw.bce.rx_quick_cons_trip_int", &bce_rx_quick_cons_trip_int);
597 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_quick_cons_trip_int, CTLFLAG_RDTUN,
598 &bce_rx_quick_cons_trip_int, 0,
599 "Receive BD trip point duirng interrupts");
601 /* Allowable values are 1 ... 100 */
603 /* Generate 1 interrupt for every received frame. */
604 static int bce_rx_quick_cons_trip = 1;
606 /* Generate 1 interrupt for every 6 received frames. */
607 static int bce_rx_quick_cons_trip = DEFAULT_RX_QUICK_CONS_TRIP;
609 TUNABLE_INT("hw.bce.rx_quick_cons_trip", &bce_rx_quick_cons_trip);
610 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_quick_cons_trip, CTLFLAG_RDTUN,
611 &bce_rx_quick_cons_trip, 0,
612 "Receive BD trip point");
614 /* Allowable values are 0 ... 100 */
616 /* Generate an int. if 0us have elapsed since the last received frame. */
617 static int bce_rx_ticks_int = 0;
619 /* Generate an int. if 18us have elapsed since the last received frame. */
620 static int bce_rx_ticks_int = DEFAULT_RX_TICKS_INT;
622 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
623 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_ticks_int, CTLFLAG_RDTUN,
624 &bce_rx_ticks_int, 0, "Receive ticks count during interrupt");
626 /* Allowable values are 0 ... 100 */
628 /* Generate an int. if 0us have elapsed since the last received frame. */
629 static int bce_rx_ticks = 0;
631 /* Generate an int. if 18us have elapsed since the last received frame. */
632 static int bce_rx_ticks = DEFAULT_RX_TICKS;
634 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
635 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_ticks, CTLFLAG_RDTUN,
636 &bce_rx_ticks, 0, "Receive ticks count");
639 /****************************************************************************/
640 /* Device probe function. */
642 /* Compares the device to the driver's list of supported devices and */
643 /* reports back to the OS whether this is the right driver for the device. */
646 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
647 /****************************************************************************/
649 bce_probe(device_t dev)
652 struct bce_softc *sc;
654 u16 vid = 0, did = 0, svid = 0, sdid = 0;
658 sc = device_get_softc(dev);
659 bzero(sc, sizeof(struct bce_softc));
660 sc->bce_unit = device_get_unit(dev);
663 /* Get the data for the device to be probed. */
664 vid = pci_get_vendor(dev);
665 did = pci_get_device(dev);
666 svid = pci_get_subvendor(dev);
667 sdid = pci_get_subdevice(dev);
669 DBPRINT(sc, BCE_EXTREME_LOAD,
670 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
671 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
673 /* Look through the list of known devices for a match. */
674 while(t->bce_name != NULL) {
676 if ((vid == t->bce_vid) && (did == t->bce_did) &&
677 ((svid == t->bce_svid) || (t->bce_svid == PCI_ANY_ID)) &&
678 ((sdid == t->bce_sdid) || (t->bce_sdid == PCI_ANY_ID))) {
680 descbuf = malloc(BCE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
685 /* Print out the device identity. */
686 snprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
687 t->bce_name, (((pci_read_config(dev,
688 PCIR_REVID, 4) & 0xf0) >> 4) + 'A'),
689 (pci_read_config(dev, PCIR_REVID, 4) & 0xf));
691 device_set_desc_copy(dev, descbuf);
692 free(descbuf, M_TEMP);
693 return(BUS_PROBE_DEFAULT);
702 /****************************************************************************/
703 /* PCI Capabilities Probe Function. */
705 /* Walks the PCI capabiites list for the device to find what features are */
710 /****************************************************************************/
712 bce_print_adapter_info(struct bce_softc *sc)
716 DBENTER(BCE_VERBOSE_LOAD);
718 if (bce_verbose || bootverbose) {
719 BCE_PRINTF("ASIC (0x%08X); ", sc->bce_chipid);
720 printf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >>
721 12) + 'A', ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
725 if (sc->bce_flags & BCE_PCIE_FLAG) {
726 printf("Bus (PCIe x%d, ", sc->link_width);
727 switch (sc->link_speed) {
728 case 1: printf("2.5Gbps); "); break;
729 case 2: printf("5Gbps); "); break;
730 default: printf("Unknown link speed); ");
733 printf("Bus (PCI%s, %s, %dMHz); ",
734 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
735 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
736 "32-bit" : "64-bit"), sc->bus_speed_mhz);
739 /* Firmware version and device features. */
740 printf("B/C (%s); Bufs (RX:%d;TX:%d;PG:%d); Flags (",
741 sc->bce_bc_ver, sc->rx_pages, sc->tx_pages,
742 (bce_hdr_split == TRUE ? sc->pg_pages: 0));
744 if (bce_hdr_split == TRUE) {
749 if (sc->bce_flags & BCE_USING_MSI_FLAG) {
750 if (i > 0) printf("|");
754 if (sc->bce_flags & BCE_USING_MSIX_FLAG) {
755 if (i > 0) printf("|");
756 printf("MSI-X"); i++;
759 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG) {
760 if (i > 0) printf("|");
764 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
765 if (i > 0) printf("|");
766 printf("MFW); MFW (%s)\n", sc->bce_mfw_ver);
771 printf("Coal (RX:%d,%d,%d,%d; TX:%d,%d,%d,%d)\n",
772 sc->bce_rx_quick_cons_trip_int,
773 sc->bce_rx_quick_cons_trip,
774 sc->bce_rx_ticks_int,
776 sc->bce_tx_quick_cons_trip_int,
777 sc->bce_tx_quick_cons_trip,
778 sc->bce_tx_ticks_int,
783 DBEXIT(BCE_VERBOSE_LOAD);
787 /****************************************************************************/
788 /* PCI Capabilities Probe Function. */
790 /* Walks the PCI capabiites list for the device to find what features are */
795 /****************************************************************************/
797 bce_probe_pci_caps(device_t dev, struct bce_softc *sc)
801 DBENTER(BCE_VERBOSE_LOAD);
803 /* Check if PCI-X capability is enabled. */
804 if (pci_find_cap(dev, PCIY_PCIX, ®) == 0) {
806 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
809 /* Check if PCIe capability is enabled. */
810 if (pci_find_cap(dev, PCIY_EXPRESS, ®) == 0) {
812 u16 link_status = pci_read_config(dev, reg + 0x12, 2);
813 DBPRINT(sc, BCE_INFO_LOAD, "PCIe link_status = "
814 "0x%08X\n", link_status);
815 sc->link_speed = link_status & 0xf;
816 sc->link_width = (link_status >> 4) & 0x3f;
817 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
818 sc->bce_flags |= BCE_PCIE_FLAG;
822 /* Check if MSI capability is enabled. */
823 if (pci_find_cap(dev, PCIY_MSI, ®) == 0) {
825 sc->bce_cap_flags |= BCE_MSI_CAPABLE_FLAG;
828 /* Check if MSI-X capability is enabled. */
829 if (pci_find_cap(dev, PCIY_MSIX, ®) == 0) {
831 sc->bce_cap_flags |= BCE_MSIX_CAPABLE_FLAG;
834 DBEXIT(BCE_VERBOSE_LOAD);
838 /****************************************************************************/
839 /* Load and validate user tunable settings. */
843 /****************************************************************************/
845 bce_set_tunables(struct bce_softc *sc)
847 /* Set sysctl values for RX page count. */
848 switch (bce_rx_pages) {
856 sc->rx_pages = bce_rx_pages;
859 sc->rx_pages = DEFAULT_RX_PAGES;
860 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
861 "hw.bce.rx_pages! Setting default of %d.\n",
862 __FILE__, __LINE__, bce_rx_pages, DEFAULT_RX_PAGES);
865 /* ToDo: Consider allowing user setting for pg_pages. */
866 sc->pg_pages = min((sc->rx_pages * 4), MAX_PG_PAGES);
868 /* Set sysctl values for TX page count. */
869 switch (bce_tx_pages) {
877 sc->tx_pages = bce_tx_pages;
880 sc->tx_pages = DEFAULT_TX_PAGES;
881 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
882 "hw.bce.tx_pages! Setting default of %d.\n",
883 __FILE__, __LINE__, bce_tx_pages, DEFAULT_TX_PAGES);
887 * Validate the TX trip point (i.e. the number of
888 * TX completions before a status block update is
889 * generated and an interrupt is asserted.
891 if (bce_tx_quick_cons_trip_int <= 100) {
892 sc->bce_tx_quick_cons_trip_int =
893 bce_tx_quick_cons_trip_int;
895 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
896 "hw.bce.tx_quick_cons_trip_int! Setting default of %d.\n",
897 __FILE__, __LINE__, bce_tx_quick_cons_trip_int,
898 DEFAULT_TX_QUICK_CONS_TRIP_INT);
899 sc->bce_tx_quick_cons_trip_int =
900 DEFAULT_TX_QUICK_CONS_TRIP_INT;
903 if (bce_tx_quick_cons_trip <= 100) {
904 sc->bce_tx_quick_cons_trip =
905 bce_tx_quick_cons_trip;
907 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
908 "hw.bce.tx_quick_cons_trip! Setting default of %d.\n",
909 __FILE__, __LINE__, bce_tx_quick_cons_trip,
910 DEFAULT_TX_QUICK_CONS_TRIP);
911 sc->bce_tx_quick_cons_trip =
912 DEFAULT_TX_QUICK_CONS_TRIP;
916 * Validate the TX ticks count (i.e. the maximum amount
917 * of time to wait after the last TX completion has
918 * occurred before a status block update is generated
919 * and an interrupt is asserted.
921 if (bce_tx_ticks_int <= 100) {
922 sc->bce_tx_ticks_int =
925 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
926 "hw.bce.tx_ticks_int! Setting default of %d.\n",
927 __FILE__, __LINE__, bce_tx_ticks_int,
928 DEFAULT_TX_TICKS_INT);
929 sc->bce_tx_ticks_int =
930 DEFAULT_TX_TICKS_INT;
933 if (bce_tx_ticks <= 100) {
937 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
938 "hw.bce.tx_ticks! Setting default of %d.\n",
939 __FILE__, __LINE__, bce_tx_ticks,
946 * Validate the RX trip point (i.e. the number of
947 * RX frames received before a status block update is
948 * generated and an interrupt is asserted.
950 if (bce_rx_quick_cons_trip_int <= 100) {
951 sc->bce_rx_quick_cons_trip_int =
952 bce_rx_quick_cons_trip_int;
954 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
955 "hw.bce.rx_quick_cons_trip_int! Setting default of %d.\n",
956 __FILE__, __LINE__, bce_rx_quick_cons_trip_int,
957 DEFAULT_RX_QUICK_CONS_TRIP_INT);
958 sc->bce_rx_quick_cons_trip_int =
959 DEFAULT_RX_QUICK_CONS_TRIP_INT;
962 if (bce_rx_quick_cons_trip <= 100) {
963 sc->bce_rx_quick_cons_trip =
964 bce_rx_quick_cons_trip;
966 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
967 "hw.bce.rx_quick_cons_trip! Setting default of %d.\n",
968 __FILE__, __LINE__, bce_rx_quick_cons_trip,
969 DEFAULT_RX_QUICK_CONS_TRIP);
970 sc->bce_rx_quick_cons_trip =
971 DEFAULT_RX_QUICK_CONS_TRIP;
975 * Validate the RX ticks count (i.e. the maximum amount
976 * of time to wait after the last RX frame has been
977 * received before a status block update is generated
978 * and an interrupt is asserted.
980 if (bce_rx_ticks_int <= 100) {
981 sc->bce_rx_ticks_int = bce_rx_ticks_int;
983 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
984 "hw.bce.rx_ticks_int! Setting default of %d.\n",
985 __FILE__, __LINE__, bce_rx_ticks_int,
986 DEFAULT_RX_TICKS_INT);
987 sc->bce_rx_ticks_int = DEFAULT_RX_TICKS_INT;
990 if (bce_rx_ticks <= 100) {
991 sc->bce_rx_ticks = bce_rx_ticks;
993 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
994 "hw.bce.rx_ticks! Setting default of %d.\n",
995 __FILE__, __LINE__, bce_rx_ticks,
997 sc->bce_rx_ticks = DEFAULT_RX_TICKS;
1000 /* Disabling both RX ticks and RX trips will prevent interrupts. */
1001 if ((bce_rx_quick_cons_trip == 0) && (bce_rx_ticks == 0)) {
1002 BCE_PRINTF("%s(%d): Cannot set both hw.bce.rx_ticks and "
1003 "hw.bce.rx_quick_cons_trip to 0. Setting default values.\n",
1004 __FILE__, __LINE__);
1005 sc->bce_rx_ticks = DEFAULT_RX_TICKS;
1006 sc->bce_rx_quick_cons_trip = DEFAULT_RX_QUICK_CONS_TRIP;
1009 /* Disabling both TX ticks and TX trips will prevent interrupts. */
1010 if ((bce_tx_quick_cons_trip == 0) && (bce_tx_ticks == 0)) {
1011 BCE_PRINTF("%s(%d): Cannot set both hw.bce.tx_ticks and "
1012 "hw.bce.tx_quick_cons_trip to 0. Setting default values.\n",
1013 __FILE__, __LINE__);
1014 sc->bce_tx_ticks = DEFAULT_TX_TICKS;
1015 sc->bce_tx_quick_cons_trip = DEFAULT_TX_QUICK_CONS_TRIP;
1021 /****************************************************************************/
1022 /* Device attach function. */
1024 /* Allocates device resources, performs secondary chip identification, */
1025 /* resets and initializes the hardware, and initializes driver instance */
1029 /* 0 on success, positive value on failure. */
1030 /****************************************************************************/
1032 bce_attach(device_t dev)
1034 struct bce_softc *sc;
1037 int error, rid, rc = 0;
1039 sc = device_get_softc(dev);
1042 DBENTER(BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
1044 sc->bce_unit = device_get_unit(dev);
1046 /* Set initial device and PHY flags */
1048 sc->bce_phy_flags = 0;
1050 bce_set_tunables(sc);
1052 pci_enable_busmaster(dev);
1054 /* Allocate PCI memory resources. */
1056 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1059 if (sc->bce_res_mem == NULL) {
1060 BCE_PRINTF("%s(%d): PCI memory allocation failed\n",
1061 __FILE__, __LINE__);
1063 goto bce_attach_fail;
1066 /* Get various resource handles. */
1067 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
1068 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
1069 sc->bce_vhandle = (vm_offset_t) rman_get_virtual(sc->bce_res_mem);
1071 bce_probe_pci_caps(dev, sc);
1075 /* Try allocating MSI-X interrupts. */
1076 if ((sc->bce_cap_flags & BCE_MSIX_CAPABLE_FLAG) &&
1077 (bce_msi_enable >= 2) &&
1078 ((sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1079 &rid, RF_ACTIVE)) != NULL)) {
1081 msi_needed = sc->bce_msi_count = 1;
1083 if (((error = pci_alloc_msix(dev, &sc->bce_msi_count)) != 0) ||
1084 (sc->bce_msi_count != msi_needed)) {
1085 BCE_PRINTF("%s(%d): MSI-X allocation failed! Requested = %d,"
1086 "Received = %d, error = %d\n", __FILE__, __LINE__,
1087 msi_needed, sc->bce_msi_count, error);
1088 sc->bce_msi_count = 0;
1089 pci_release_msi(dev);
1090 bus_release_resource(dev, SYS_RES_MEMORY, rid,
1092 sc->bce_res_irq = NULL;
1094 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI-X interrupt.\n",
1096 sc->bce_flags |= BCE_USING_MSIX_FLAG;
1097 sc->bce_intr = bce_intr;
1102 /* Try allocating a MSI interrupt. */
1103 if ((sc->bce_cap_flags & BCE_MSI_CAPABLE_FLAG) &&
1104 (bce_msi_enable >= 1) && (sc->bce_msi_count == 0)) {
1105 sc->bce_msi_count = 1;
1106 if ((error = pci_alloc_msi(dev, &sc->bce_msi_count)) != 0) {
1107 BCE_PRINTF("%s(%d): MSI allocation failed! "
1108 "error = %d\n", __FILE__, __LINE__, error);
1109 sc->bce_msi_count = 0;
1110 pci_release_msi(dev);
1112 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI "
1113 "interrupt.\n", __FUNCTION__);
1114 sc->bce_flags |= BCE_USING_MSI_FLAG;
1115 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
1116 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
1117 sc->bce_flags |= BCE_ONE_SHOT_MSI_FLAG;
1118 sc->bce_irq_rid = 1;
1119 sc->bce_intr = bce_intr;
1123 /* Try allocating a legacy interrupt. */
1124 if (sc->bce_msi_count == 0) {
1125 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using INTx interrupt.\n",
1128 sc->bce_intr = bce_intr;
1131 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
1132 &rid, RF_SHAREABLE | RF_ACTIVE);
1134 sc->bce_irq_rid = rid;
1136 /* Report any IRQ allocation errors. */
1137 if (sc->bce_res_irq == NULL) {
1138 BCE_PRINTF("%s(%d): PCI map interrupt failed!\n",
1139 __FILE__, __LINE__);
1141 goto bce_attach_fail;
1144 /* Initialize mutex for the current device instance. */
1145 BCE_LOCK_INIT(sc, device_get_nameunit(dev));
1148 * Configure byte swap and enable indirect register access.
1149 * Rely on CPU to do target byte swapping on big endian systems.
1150 * Access to registers outside of PCI configurtion space are not
1151 * valid until this is done.
1153 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
1154 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
1155 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
1157 /* Save ASIC revsion info. */
1158 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
1160 /* Weed out any non-production controller revisions. */
1161 switch(BCE_CHIP_ID(sc)) {
1162 case BCE_CHIP_ID_5706_A0:
1163 case BCE_CHIP_ID_5706_A1:
1164 case BCE_CHIP_ID_5708_A0:
1165 case BCE_CHIP_ID_5708_B0:
1166 case BCE_CHIP_ID_5709_A0:
1167 case BCE_CHIP_ID_5709_B0:
1168 case BCE_CHIP_ID_5709_B1:
1169 case BCE_CHIP_ID_5709_B2:
1170 BCE_PRINTF("%s(%d): Unsupported controller "
1171 "revision (%c%d)!\n", __FILE__, __LINE__,
1172 (((pci_read_config(dev, PCIR_REVID, 4) &
1173 0xf0) >> 4) + 'A'), (pci_read_config(dev,
1174 PCIR_REVID, 4) & 0xf));
1176 goto bce_attach_fail;
1180 * The embedded PCIe to PCI-X bridge (EPB)
1181 * in the 5708 cannot address memory above
1182 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
1184 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
1185 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
1187 sc->max_bus_addr = BUS_SPACE_MAXADDR;
1190 * Find the base address for shared memory access.
1191 * Newer versions of bootcode use a signature and offset
1192 * while older versions use a fixed address.
1194 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
1195 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
1196 /* Multi-port devices use different offsets in shared memory. */
1197 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0 +
1198 (pci_get_function(sc->bce_dev) << 2));
1200 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
1202 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): bce_shmem_base = 0x%08X\n",
1203 __FUNCTION__, sc->bce_shmem_base);
1205 /* Fetch the bootcode revision. */
1206 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
1207 for (int i = 0, j = 0; i < 3; i++) {
1210 num = (u8) (val >> (24 - (i * 8)));
1211 for (int k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
1212 if (num >= k || !skip0 || k == 1) {
1213 sc->bce_bc_ver[j++] = (num / k) + '0';
1219 sc->bce_bc_ver[j++] = '.';
1222 /* Check if any management firwmare is enabled. */
1223 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
1224 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
1225 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
1227 /* Allow time for firmware to enter the running state. */
1228 for (int i = 0; i < 30; i++) {
1229 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
1230 if (val & BCE_CONDITION_MFW_RUN_MASK)
1235 /* Check if management firmware is running. */
1236 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
1237 val &= BCE_CONDITION_MFW_RUN_MASK;
1238 if ((val != BCE_CONDITION_MFW_RUN_UNKNOWN) &&
1239 (val != BCE_CONDITION_MFW_RUN_NONE)) {
1240 u32 addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
1243 /* Read the management firmware version string. */
1244 for (int j = 0; j < 3; j++) {
1245 val = bce_reg_rd_ind(sc, addr + j * 4);
1247 memcpy(&sc->bce_mfw_ver[i], &val, 4);
1251 /* May cause firmware synchronization timeouts. */
1252 BCE_PRINTF("%s(%d): Management firmware enabled "
1253 "but not running!\n", __FILE__, __LINE__);
1254 strcpy(sc->bce_mfw_ver, "NOT RUNNING!");
1256 /* ToDo: Any action the driver should take? */
1260 /* Get PCI bus information (speed and type). */
1261 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
1262 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
1265 sc->bce_flags |= BCE_PCIX_FLAG;
1267 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS);
1269 clkreg &= BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
1271 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
1272 sc->bus_speed_mhz = 133;
1275 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
1276 sc->bus_speed_mhz = 100;
1279 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
1280 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
1281 sc->bus_speed_mhz = 66;
1284 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
1285 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
1286 sc->bus_speed_mhz = 50;
1289 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
1290 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
1291 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
1292 sc->bus_speed_mhz = 33;
1296 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
1297 sc->bus_speed_mhz = 66;
1299 sc->bus_speed_mhz = 33;
1302 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
1303 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
1305 /* Reset controller and announce to bootcode that driver is present. */
1306 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
1307 BCE_PRINTF("%s(%d): Controller reset failed!\n",
1308 __FILE__, __LINE__);
1310 goto bce_attach_fail;
1313 /* Initialize the controller. */
1314 if (bce_chipinit(sc)) {
1315 BCE_PRINTF("%s(%d): Controller initialization failed!\n",
1316 __FILE__, __LINE__);
1318 goto bce_attach_fail;
1321 /* Perform NVRAM test. */
1322 if (bce_nvram_test(sc)) {
1323 BCE_PRINTF("%s(%d): NVRAM test failed!\n",
1324 __FILE__, __LINE__);
1326 goto bce_attach_fail;
1329 /* Fetch the permanent Ethernet MAC address. */
1330 bce_get_mac_addr(sc);
1333 * Trip points control how many BDs
1334 * should be ready before generating an
1335 * interrupt while ticks control how long
1336 * a BD can sit in the chain before
1337 * generating an interrupt. Set the default
1338 * values for the RX and TX chains.
1341 /* Not used for L2. */
1342 sc->bce_comp_prod_trip_int = 0;
1343 sc->bce_comp_prod_trip = 0;
1344 sc->bce_com_ticks_int = 0;
1345 sc->bce_com_ticks = 0;
1346 sc->bce_cmd_ticks_int = 0;
1347 sc->bce_cmd_ticks = 0;
1349 /* Update statistics once every second. */
1350 sc->bce_stats_ticks = 1000000 & 0xffff00;
1352 /* Find the media type for the adapter. */
1355 /* Store data needed by PHY driver for backplane applications */
1356 sc->bce_shared_hw_cfg = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
1357 sc->bce_port_hw_cfg = bce_shmem_rd(sc, BCE_PORT_HW_CFG_CONFIG);
1359 /* Allocate DMA memory resources. */
1360 if (bce_dma_alloc(dev)) {
1361 BCE_PRINTF("%s(%d): DMA resource allocation failed!\n",
1362 __FILE__, __LINE__);
1364 goto bce_attach_fail;
1367 /* Allocate an ifnet structure. */
1368 ifp = sc->bce_ifp = if_alloc(IFT_ETHER);
1370 BCE_PRINTF("%s(%d): Interface allocation failed!\n",
1371 __FILE__, __LINE__);
1373 goto bce_attach_fail;
1376 /* Initialize the ifnet interface. */
1378 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1379 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1380 ifp->if_ioctl = bce_ioctl;
1381 ifp->if_start = bce_start;
1382 ifp->if_init = bce_init;
1383 ifp->if_mtu = ETHERMTU;
1385 if (bce_tso_enable) {
1386 ifp->if_hwassist = BCE_IF_HWASSIST | CSUM_TSO;
1387 ifp->if_capabilities = BCE_IF_CAPABILITIES | IFCAP_TSO4 |
1390 ifp->if_hwassist = BCE_IF_HWASSIST;
1391 ifp->if_capabilities = BCE_IF_CAPABILITIES;
1394 ifp->if_capenable = ifp->if_capabilities;
1397 * Assume standard mbuf sizes for buffer allocation.
1398 * This may change later if the MTU size is set to
1399 * something other than 1500.
1401 bce_get_rx_buffer_sizes(sc,
1402 (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN));
1404 /* Recalculate our buffer allocation sizes. */
1405 ifp->if_snd.ifq_drv_maxlen = USABLE_TX_BD_ALLOC;
1406 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
1407 IFQ_SET_READY(&ifp->if_snd);
1409 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
1410 ifp->if_baudrate = IF_Mbps(2500ULL);
1412 ifp->if_baudrate = IF_Mbps(1000);
1414 /* Handle any special PHY initialization for SerDes PHYs. */
1417 /* MII child bus by attaching the PHY. */
1418 rc = mii_attach(dev, &sc->bce_miibus, ifp, bce_ifmedia_upd,
1419 bce_ifmedia_sts, BMSR_DEFCAPMASK, sc->bce_phy_addr,
1420 MII_OFFSET_ANY, MIIF_DOPAUSE);
1422 BCE_PRINTF("%s(%d): attaching PHYs failed\n", __FILE__,
1424 goto bce_attach_fail;
1427 /* Attach to the Ethernet interface list. */
1428 ether_ifattach(ifp, sc->eaddr);
1430 #if __FreeBSD_version < 500000
1431 callout_init(&sc->bce_tick_callout);
1432 callout_init(&sc->bce_pulse_callout);
1434 callout_init_mtx(&sc->bce_tick_callout, &sc->bce_mtx, 0);
1435 callout_init_mtx(&sc->bce_pulse_callout, &sc->bce_mtx, 0);
1438 /* Hookup IRQ last. */
1439 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_TYPE_NET | INTR_MPSAFE,
1440 NULL, bce_intr, sc, &sc->bce_intrhand);
1443 BCE_PRINTF("%s(%d): Failed to setup IRQ!\n",
1444 __FILE__, __LINE__);
1446 goto bce_attach_exit;
1450 * At this point we've acquired all the resources
1451 * we need to run so there's no turning back, we're
1452 * cleared for launch.
1455 /* Print some important debugging info. */
1456 DBRUNMSG(BCE_INFO, bce_dump_driver_state(sc));
1458 /* Add the supported sysctls to the kernel. */
1459 bce_add_sysctls(sc);
1464 * The chip reset earlier notified the bootcode that
1465 * a driver is present. We now need to start our pulse
1466 * routine so that the bootcode is reminded that we're
1471 bce_mgmt_init_locked(sc);
1474 /* Finally, print some useful adapter info */
1475 bce_print_adapter_info(sc);
1476 DBPRINT(sc, BCE_FATAL, "%s(): sc = %p\n",
1479 goto bce_attach_exit;
1482 bce_release_resources(sc);
1486 DBEXIT(BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
1492 /****************************************************************************/
1493 /* Device detach function. */
1495 /* Stops the controller, resets the controller, and releases resources. */
1498 /* 0 on success, positive value on failure. */
1499 /****************************************************************************/
1501 bce_detach(device_t dev)
1503 struct bce_softc *sc = device_get_softc(dev);
1507 DBENTER(BCE_VERBOSE_UNLOAD | BCE_VERBOSE_RESET);
1511 /* Stop and reset the controller. */
1514 /* Stop the pulse so the bootcode can go to driver absent state. */
1515 callout_stop(&sc->bce_pulse_callout);
1518 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1519 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1521 msg = BCE_DRV_MSG_CODE_UNLOAD;
1526 ether_ifdetach(ifp);
1528 /* If we have a child device on the MII bus remove it too. */
1529 bus_generic_detach(dev);
1530 device_delete_child(dev, sc->bce_miibus);
1532 /* Release all remaining resources. */
1533 bce_release_resources(sc);
1535 DBEXIT(BCE_VERBOSE_UNLOAD | BCE_VERBOSE_RESET);
1541 /****************************************************************************/
1542 /* Device shutdown function. */
1544 /* Stops and resets the controller. */
1547 /* 0 on success, positive value on failure. */
1548 /****************************************************************************/
1550 bce_shutdown(device_t dev)
1552 struct bce_softc *sc = device_get_softc(dev);
1555 DBENTER(BCE_VERBOSE);
1559 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1560 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1562 msg = BCE_DRV_MSG_CODE_UNLOAD;
1566 DBEXIT(BCE_VERBOSE);
1573 /****************************************************************************/
1574 /* Register read. */
1577 /* The value of the register. */
1578 /****************************************************************************/
1580 bce_reg_rd(struct bce_softc *sc, u32 offset)
1582 u32 val = bus_space_read_4(sc->bce_btag, sc->bce_bhandle, offset);
1583 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1584 __FUNCTION__, offset, val);
1589 /****************************************************************************/
1590 /* Register write (16 bit). */
1594 /****************************************************************************/
1596 bce_reg_wr16(struct bce_softc *sc, u32 offset, u16 val)
1598 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%04X\n",
1599 __FUNCTION__, offset, val);
1600 bus_space_write_2(sc->bce_btag, sc->bce_bhandle, offset, val);
1604 /****************************************************************************/
1605 /* Register write. */
1609 /****************************************************************************/
1611 bce_reg_wr(struct bce_softc *sc, u32 offset, u32 val)
1613 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1614 __FUNCTION__, offset, val);
1615 bus_space_write_4(sc->bce_btag, sc->bce_bhandle, offset, val);
1619 /****************************************************************************/
1620 /* Indirect register read. */
1622 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1623 /* configuration space. Using this mechanism avoids issues with posted */
1624 /* reads but is much slower than memory-mapped I/O. */
1627 /* The value of the register. */
1628 /****************************************************************************/
1630 bce_reg_rd_ind(struct bce_softc *sc, u32 offset)
1635 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1639 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1640 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1641 __FUNCTION__, offset, val);
1645 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1650 /****************************************************************************/
1651 /* Indirect register write. */
1653 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1654 /* configuration space. Using this mechanism avoids issues with posted */
1655 /* writes but is muchh slower than memory-mapped I/O. */
1659 /****************************************************************************/
1661 bce_reg_wr_ind(struct bce_softc *sc, u32 offset, u32 val)
1666 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1667 __FUNCTION__, offset, val);
1669 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1670 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1674 /****************************************************************************/
1675 /* Shared memory write. */
1677 /* Writes NetXtreme II shared memory region. */
1681 /****************************************************************************/
1683 bce_shmem_wr(struct bce_softc *sc, u32 offset, u32 val)
1685 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): Writing 0x%08X to "
1686 "0x%08X\n", __FUNCTION__, val, offset);
1688 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1692 /****************************************************************************/
1693 /* Shared memory read. */
1695 /* Reads NetXtreme II shared memory region. */
1698 /* The 32 bit value read. */
1699 /****************************************************************************/
1701 bce_shmem_rd(struct bce_softc *sc, u32 offset)
1703 u32 val = bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1705 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): Reading 0x%08X from "
1706 "0x%08X\n", __FUNCTION__, val, offset);
1713 /****************************************************************************/
1714 /* Context memory read. */
1716 /* The NetXtreme II controller uses context memory to track connection */
1717 /* information for L2 and higher network protocols. */
1720 /* The requested 32 bit value of context memory. */
1721 /****************************************************************************/
1723 bce_ctx_rd(struct bce_softc *sc, u32 cid_addr, u32 ctx_offset)
1725 u32 idx, offset, retry_cnt = 5, val;
1727 DBRUNIF((cid_addr > MAX_CID_ADDR || ctx_offset & 0x3 ||
1728 cid_addr & CTX_MASK), BCE_PRINTF("%s(): Invalid CID "
1729 "address: 0x%08X.\n", __FUNCTION__, cid_addr));
1731 offset = ctx_offset + cid_addr;
1733 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
1734 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
1736 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_READ_REQ));
1738 for (idx = 0; idx < retry_cnt; idx++) {
1739 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1740 if ((val & BCE_CTX_CTX_CTRL_READ_REQ) == 0)
1745 if (val & BCE_CTX_CTX_CTRL_READ_REQ)
1746 BCE_PRINTF("%s(%d); Unable to read CTX memory: "
1747 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1748 __FILE__, __LINE__, cid_addr, ctx_offset);
1750 val = REG_RD(sc, BCE_CTX_CTX_DATA);
1752 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1753 val = REG_RD(sc, BCE_CTX_DATA);
1756 DBPRINT(sc, BCE_EXTREME_CTX, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
1757 "val = 0x%08X\n", __FUNCTION__, cid_addr, ctx_offset, val);
1764 /****************************************************************************/
1765 /* Context memory write. */
1767 /* The NetXtreme II controller uses context memory to track connection */
1768 /* information for L2 and higher network protocols. */
1772 /****************************************************************************/
1774 bce_ctx_wr(struct bce_softc *sc, u32 cid_addr, u32 ctx_offset, u32 ctx_val)
1776 u32 idx, offset = ctx_offset + cid_addr;
1777 u32 val, retry_cnt = 5;
1779 DBPRINT(sc, BCE_EXTREME_CTX, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
1780 "val = 0x%08X\n", __FUNCTION__, cid_addr, ctx_offset, ctx_val);
1782 DBRUNIF((cid_addr > MAX_CID_ADDR || ctx_offset & 0x3 || cid_addr & CTX_MASK),
1783 BCE_PRINTF("%s(): Invalid CID address: 0x%08X.\n",
1784 __FUNCTION__, cid_addr));
1786 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
1787 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
1789 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1790 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1792 for (idx = 0; idx < retry_cnt; idx++) {
1793 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1794 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1799 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ)
1800 BCE_PRINTF("%s(%d); Unable to write CTX memory: "
1801 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1802 __FILE__, __LINE__, cid_addr, ctx_offset);
1805 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1806 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1811 /****************************************************************************/
1812 /* PHY register read. */
1814 /* Implements register reads on the MII bus. */
1817 /* The value of the register. */
1818 /****************************************************************************/
1820 bce_miibus_read_reg(device_t dev, int phy, int reg)
1822 struct bce_softc *sc;
1826 sc = device_get_softc(dev);
1828 /* Make sure we are accessing the correct PHY address. */
1829 if (phy != sc->bce_phy_addr) {
1830 DBPRINT(sc, BCE_INSANE_PHY, "Invalid PHY address %d "
1831 "for PHY read!\n", phy);
1836 * The 5709S PHY is an IEEE Clause 45 PHY
1837 * with special mappings to work with IEEE
1838 * Clause 22 register accesses.
1840 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
1841 if (reg >= MII_BMCR && reg <= MII_ANLPRNP)
1845 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1846 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1847 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1849 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1850 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1856 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1857 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1858 BCE_EMAC_MDIO_COMM_START_BUSY;
1859 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1861 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1864 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1865 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1868 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1869 val &= BCE_EMAC_MDIO_COMM_DATA;
1875 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1876 BCE_PRINTF("%s(%d): Error: PHY read timeout! phy = %d, "
1877 "reg = 0x%04X\n", __FILE__, __LINE__, phy, reg);
1880 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1884 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1885 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1886 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1888 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1889 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1894 DB_PRINT_PHY_REG(reg, val);
1895 return (val & 0xffff);
1900 /****************************************************************************/
1901 /* PHY register write. */
1903 /* Implements register writes on the MII bus. */
1906 /* The value of the register. */
1907 /****************************************************************************/
1909 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1911 struct bce_softc *sc;
1915 sc = device_get_softc(dev);
1917 /* Make sure we are accessing the correct PHY address. */
1918 if (phy != sc->bce_phy_addr) {
1919 DBPRINT(sc, BCE_INSANE_PHY, "Invalid PHY address %d "
1920 "for PHY write!\n", phy);
1924 DB_PRINT_PHY_REG(reg, val);
1927 * The 5709S PHY is an IEEE Clause 45 PHY
1928 * with special mappings to work with IEEE
1929 * Clause 22 register accesses.
1931 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
1932 if (reg >= MII_BMCR && reg <= MII_ANLPRNP)
1936 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1937 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1938 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1940 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1941 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1946 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1947 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1948 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1949 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1951 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1954 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1955 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1961 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1962 BCE_PRINTF("%s(%d): PHY write timeout!\n",
1963 __FILE__, __LINE__);
1965 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1966 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1967 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1969 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1970 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1979 /****************************************************************************/
1980 /* MII bus status change. */
1982 /* Called by the MII bus driver when the PHY establishes link to set the */
1983 /* MAC interface registers. */
1987 /****************************************************************************/
1989 bce_miibus_statchg(device_t dev)
1991 struct bce_softc *sc;
1992 struct mii_data *mii;
1995 sc = device_get_softc(dev);
1997 DBENTER(BCE_VERBOSE_PHY);
1999 mii = device_get_softc(sc->bce_miibus);
2001 val = REG_RD(sc, BCE_EMAC_MODE);
2002 val &= ~(BCE_EMAC_MODE_PORT | BCE_EMAC_MODE_HALF_DUPLEX |
2003 BCE_EMAC_MODE_MAC_LOOP | BCE_EMAC_MODE_FORCE_LINK |
2006 /* Set MII or GMII interface based on the PHY speed. */
2007 switch (IFM_SUBTYPE(mii->mii_media_active)) {
2009 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
2010 DBPRINT(sc, BCE_INFO_PHY,
2011 "Enabling 10Mb interface.\n");
2012 val |= BCE_EMAC_MODE_PORT_MII_10;
2017 DBPRINT(sc, BCE_INFO_PHY, "Enabling MII interface.\n");
2018 val |= BCE_EMAC_MODE_PORT_MII;
2021 DBPRINT(sc, BCE_INFO_PHY, "Enabling 2.5G MAC mode.\n");
2022 val |= BCE_EMAC_MODE_25G;
2026 DBPRINT(sc, BCE_INFO_PHY, "Enabling GMII interface.\n");
2027 val |= BCE_EMAC_MODE_PORT_GMII;
2030 DBPRINT(sc, BCE_INFO_PHY, "Unknown link speed, enabling "
2031 "default GMII interface.\n");
2032 val |= BCE_EMAC_MODE_PORT_GMII;
2035 /* Set half or full duplex based on PHY settings. */
2036 if ((mii->mii_media_active & IFM_GMASK) == IFM_HDX) {
2037 DBPRINT(sc, BCE_INFO_PHY,
2038 "Setting Half-Duplex interface.\n");
2039 val |= BCE_EMAC_MODE_HALF_DUPLEX;
2041 DBPRINT(sc, BCE_INFO_PHY,
2042 "Setting Full-Duplex interface.\n");
2044 REG_WR(sc, BCE_EMAC_MODE, val);
2046 if ((mii->mii_media_active & IFM_ETH_RXPAUSE) != 0) {
2047 DBPRINT(sc, BCE_INFO_PHY,
2048 "%s(): Enabling RX flow control.\n", __FUNCTION__);
2049 BCE_SETBIT(sc, BCE_EMAC_RX_MODE, BCE_EMAC_RX_MODE_FLOW_EN);
2051 DBPRINT(sc, BCE_INFO_PHY,
2052 "%s(): Disabling RX flow control.\n", __FUNCTION__);
2053 BCE_CLRBIT(sc, BCE_EMAC_RX_MODE, BCE_EMAC_RX_MODE_FLOW_EN);
2056 if ((mii->mii_media_active & IFM_ETH_TXPAUSE) != 0) {
2057 DBPRINT(sc, BCE_INFO_PHY,
2058 "%s(): Enabling TX flow control.\n", __FUNCTION__);
2059 BCE_SETBIT(sc, BCE_EMAC_TX_MODE, BCE_EMAC_TX_MODE_FLOW_EN);
2060 sc->bce_flags |= BCE_USING_TX_FLOW_CONTROL;
2062 DBPRINT(sc, BCE_INFO_PHY,
2063 "%s(): Disabling TX flow control.\n", __FUNCTION__);
2064 BCE_CLRBIT(sc, BCE_EMAC_TX_MODE, BCE_EMAC_TX_MODE_FLOW_EN);
2065 sc->bce_flags &= ~BCE_USING_TX_FLOW_CONTROL;
2068 /* ToDo: Update watermarks in bce_init_rx_context(). */
2070 DBEXIT(BCE_VERBOSE_PHY);
2074 /****************************************************************************/
2075 /* Acquire NVRAM lock. */
2077 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
2078 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
2079 /* for use by the driver. */
2082 /* 0 on success, positive value on failure. */
2083 /****************************************************************************/
2085 bce_acquire_nvram_lock(struct bce_softc *sc)
2090 DBENTER(BCE_VERBOSE_NVRAM);
2092 /* Request access to the flash interface. */
2093 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
2094 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2095 val = REG_RD(sc, BCE_NVM_SW_ARB);
2096 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
2102 if (j >= NVRAM_TIMEOUT_COUNT) {
2103 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
2107 DBEXIT(BCE_VERBOSE_NVRAM);
2112 /****************************************************************************/
2113 /* Release NVRAM lock. */
2115 /* When the caller is finished accessing NVRAM the lock must be released. */
2116 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
2117 /* for use by the driver. */
2120 /* 0 on success, positive value on failure. */
2121 /****************************************************************************/
2123 bce_release_nvram_lock(struct bce_softc *sc)
2128 DBENTER(BCE_VERBOSE_NVRAM);
2131 * Relinquish nvram interface.
2133 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
2135 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2136 val = REG_RD(sc, BCE_NVM_SW_ARB);
2137 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
2143 if (j >= NVRAM_TIMEOUT_COUNT) {
2144 DBPRINT(sc, BCE_WARN, "Timeout releasing NVRAM lock!\n");
2148 DBEXIT(BCE_VERBOSE_NVRAM);
2153 #ifdef BCE_NVRAM_WRITE_SUPPORT
2154 /****************************************************************************/
2155 /* Enable NVRAM write access. */
2157 /* Before writing to NVRAM the caller must enable NVRAM writes. */
2160 /* 0 on success, positive value on failure. */
2161 /****************************************************************************/
2163 bce_enable_nvram_write(struct bce_softc *sc)
2168 DBENTER(BCE_VERBOSE_NVRAM);
2170 val = REG_RD(sc, BCE_MISC_CFG);
2171 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
2173 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2176 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2177 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
2179 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2182 val = REG_RD(sc, BCE_NVM_COMMAND);
2183 if (val & BCE_NVM_COMMAND_DONE)
2187 if (j >= NVRAM_TIMEOUT_COUNT) {
2188 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
2193 DBENTER(BCE_VERBOSE_NVRAM);
2198 /****************************************************************************/
2199 /* Disable NVRAM write access. */
2201 /* When the caller is finished writing to NVRAM write access must be */
2206 /****************************************************************************/
2208 bce_disable_nvram_write(struct bce_softc *sc)
2212 DBENTER(BCE_VERBOSE_NVRAM);
2214 val = REG_RD(sc, BCE_MISC_CFG);
2215 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
2217 DBEXIT(BCE_VERBOSE_NVRAM);
2223 /****************************************************************************/
2224 /* Enable NVRAM access. */
2226 /* Before accessing NVRAM for read or write operations the caller must */
2227 /* enabled NVRAM access. */
2231 /****************************************************************************/
2233 bce_enable_nvram_access(struct bce_softc *sc)
2237 DBENTER(BCE_VERBOSE_NVRAM);
2239 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
2240 /* Enable both bits, even on read. */
2241 REG_WR(sc, BCE_NVM_ACCESS_ENABLE, val |
2242 BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
2244 DBEXIT(BCE_VERBOSE_NVRAM);
2248 /****************************************************************************/
2249 /* Disable NVRAM access. */
2251 /* When the caller is finished accessing NVRAM access must be disabled. */
2255 /****************************************************************************/
2257 bce_disable_nvram_access(struct bce_softc *sc)
2261 DBENTER(BCE_VERBOSE_NVRAM);
2263 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
2265 /* Disable both bits, even after read. */
2266 REG_WR(sc, BCE_NVM_ACCESS_ENABLE, val &
2267 ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
2269 DBEXIT(BCE_VERBOSE_NVRAM);
2273 #ifdef BCE_NVRAM_WRITE_SUPPORT
2274 /****************************************************************************/
2275 /* Erase NVRAM page before writing. */
2277 /* Non-buffered flash parts require that a page be erased before it is */
2281 /* 0 on success, positive value on failure. */
2282 /****************************************************************************/
2284 bce_nvram_erase_page(struct bce_softc *sc, u32 offset)
2289 DBENTER(BCE_VERBOSE_NVRAM);
2291 /* Buffered flash doesn't require an erase. */
2292 if (sc->bce_flash_info->flags & BCE_NV_BUFFERED)
2293 goto bce_nvram_erase_page_exit;
2295 /* Build an erase command. */
2296 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
2297 BCE_NVM_COMMAND_DOIT;
2300 * Clear the DONE bit separately, set the NVRAM adress to erase,
2301 * and issue the erase command.
2303 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2304 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2305 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2307 /* Wait for completion. */
2308 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2313 val = REG_RD(sc, BCE_NVM_COMMAND);
2314 if (val & BCE_NVM_COMMAND_DONE)
2318 if (j >= NVRAM_TIMEOUT_COUNT) {
2319 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
2323 bce_nvram_erase_page_exit:
2324 DBEXIT(BCE_VERBOSE_NVRAM);
2327 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2330 /****************************************************************************/
2331 /* Read a dword (32 bits) from NVRAM. */
2333 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
2334 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
2337 /* 0 on success and the 32 bit value read, positive value on failure. */
2338 /****************************************************************************/
2340 bce_nvram_read_dword(struct bce_softc *sc,
2341 u32 offset, u8 *ret_val, u32 cmd_flags)
2346 DBENTER(BCE_EXTREME_NVRAM);
2348 /* Build the command word. */
2349 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
2351 /* Calculate the offset for buffered flash if translation is used. */
2352 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
2353 offset = ((offset / sc->bce_flash_info->page_size) <<
2354 sc->bce_flash_info->page_bits) +
2355 (offset % sc->bce_flash_info->page_size);
2359 * Clear the DONE bit separately, set the address to read,
2360 * and issue the read.
2362 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2363 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2364 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2366 /* Wait for completion. */
2367 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
2372 val = REG_RD(sc, BCE_NVM_COMMAND);
2373 if (val & BCE_NVM_COMMAND_DONE) {
2374 val = REG_RD(sc, BCE_NVM_READ);
2376 val = bce_be32toh(val);
2377 memcpy(ret_val, &val, 4);
2382 /* Check for errors. */
2383 if (i >= NVRAM_TIMEOUT_COUNT) {
2384 BCE_PRINTF("%s(%d): Timeout error reading NVRAM at "
2385 "offset 0x%08X!\n", __FILE__, __LINE__, offset);
2389 DBEXIT(BCE_EXTREME_NVRAM);
2394 #ifdef BCE_NVRAM_WRITE_SUPPORT
2395 /****************************************************************************/
2396 /* Write a dword (32 bits) to NVRAM. */
2398 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
2399 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
2400 /* enabled NVRAM write access. */
2403 /* 0 on success, positive value on failure. */
2404 /****************************************************************************/
2406 bce_nvram_write_dword(struct bce_softc *sc, u32 offset, u8 *val,
2412 DBENTER(BCE_VERBOSE_NVRAM);
2414 /* Build the command word. */
2415 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
2417 /* Calculate the offset for buffered flash if translation is used. */
2418 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
2419 offset = ((offset / sc->bce_flash_info->page_size) <<
2420 sc->bce_flash_info->page_bits) +
2421 (offset % sc->bce_flash_info->page_size);
2425 * Clear the DONE bit separately, convert NVRAM data to big-endian,
2426 * set the NVRAM address to write, and issue the write command
2428 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2429 memcpy(&val32, val, 4);
2430 val32 = htobe32(val32);
2431 REG_WR(sc, BCE_NVM_WRITE, val32);
2432 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2433 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2435 /* Wait for completion. */
2436 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2439 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
2442 if (j >= NVRAM_TIMEOUT_COUNT) {
2443 BCE_PRINTF("%s(%d): Timeout error writing NVRAM at "
2444 "offset 0x%08X\n", __FILE__, __LINE__, offset);
2448 DBEXIT(BCE_VERBOSE_NVRAM);
2451 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2454 /****************************************************************************/
2455 /* Initialize NVRAM access. */
2457 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
2458 /* access that device. */
2461 /* 0 on success, positive value on failure. */
2462 /****************************************************************************/
2464 bce_init_nvram(struct bce_softc *sc)
2467 int j, entry_count, rc = 0;
2468 struct flash_spec *flash;
2470 DBENTER(BCE_VERBOSE_NVRAM);
2472 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
2473 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
2474 sc->bce_flash_info = &flash_5709;
2475 goto bce_init_nvram_get_flash_size;
2478 /* Determine the selected interface. */
2479 val = REG_RD(sc, BCE_NVM_CFG1);
2481 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
2484 * Flash reconfiguration is required to support additional
2485 * NVRAM devices not directly supported in hardware.
2486 * Check if the flash interface was reconfigured
2490 if (val & 0x40000000) {
2491 /* Flash interface reconfigured by bootcode. */
2493 DBPRINT(sc,BCE_INFO_LOAD,
2494 "bce_init_nvram(): Flash WAS reconfigured.\n");
2496 for (j = 0, flash = &flash_table[0]; j < entry_count;
2498 if ((val & FLASH_BACKUP_STRAP_MASK) ==
2499 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
2500 sc->bce_flash_info = flash;
2505 /* Flash interface not yet reconfigured. */
2508 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Flash was NOT reconfigured.\n",
2511 if (val & (1 << 23))
2512 mask = FLASH_BACKUP_STRAP_MASK;
2514 mask = FLASH_STRAP_MASK;
2516 /* Look for the matching NVRAM device configuration data. */
2517 for (j = 0, flash = &flash_table[0]; j < entry_count; j++, flash++) {
2519 /* Check if the device matches any of the known devices. */
2520 if ((val & mask) == (flash->strapping & mask)) {
2521 /* Found a device match. */
2522 sc->bce_flash_info = flash;
2524 /* Request access to the flash interface. */
2525 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2528 /* Reconfigure the flash interface. */
2529 bce_enable_nvram_access(sc);
2530 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
2531 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
2532 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
2533 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
2534 bce_disable_nvram_access(sc);
2535 bce_release_nvram_lock(sc);
2542 /* Check if a matching device was found. */
2543 if (j == entry_count) {
2544 sc->bce_flash_info = NULL;
2545 BCE_PRINTF("%s(%d): Unknown Flash NVRAM found!\n",
2546 __FILE__, __LINE__);
2547 DBEXIT(BCE_VERBOSE_NVRAM);
2551 bce_init_nvram_get_flash_size:
2552 /* Write the flash config data to the shared memory interface. */
2553 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2);
2554 val &= BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
2556 sc->bce_flash_size = val;
2558 sc->bce_flash_size = sc->bce_flash_info->total_size;
2560 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Found %s, size = 0x%08X\n",
2561 __FUNCTION__, sc->bce_flash_info->name,
2562 sc->bce_flash_info->total_size);
2564 DBEXIT(BCE_VERBOSE_NVRAM);
2569 /****************************************************************************/
2570 /* Read an arbitrary range of data from NVRAM. */
2572 /* Prepares the NVRAM interface for access and reads the requested data */
2573 /* into the supplied buffer. */
2576 /* 0 on success and the data read, positive value on failure. */
2577 /****************************************************************************/
2579 bce_nvram_read(struct bce_softc *sc, u32 offset, u8 *ret_buf,
2583 u32 cmd_flags, offset32, len32, extra;
2585 DBENTER(BCE_VERBOSE_NVRAM);
2588 goto bce_nvram_read_exit;
2590 /* Request access to the flash interface. */
2591 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2592 goto bce_nvram_read_exit;
2594 /* Enable access to flash interface */
2595 bce_enable_nvram_access(sc);
2608 pre_len = 4 - (offset & 3);
2610 if (pre_len >= len32) {
2612 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
2615 cmd_flags = BCE_NVM_COMMAND_FIRST;
2618 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2623 memcpy(ret_buf, buf + (offset & 3), pre_len);
2631 extra = 4 - (len32 & 3);
2632 len32 = (len32 + 4) & ~3;
2639 cmd_flags = BCE_NVM_COMMAND_LAST;
2641 cmd_flags = BCE_NVM_COMMAND_FIRST |
2642 BCE_NVM_COMMAND_LAST;
2644 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2646 memcpy(ret_buf, buf, 4 - extra);
2648 else if (len32 > 0) {
2651 /* Read the first word. */
2655 cmd_flags = BCE_NVM_COMMAND_FIRST;
2657 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
2659 /* Advance to the next dword. */
2664 while (len32 > 4 && rc == 0) {
2665 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
2667 /* Advance to the next dword. */
2674 goto bce_nvram_read_locked_exit;
2676 cmd_flags = BCE_NVM_COMMAND_LAST;
2677 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2679 memcpy(ret_buf, buf, 4 - extra);
2682 bce_nvram_read_locked_exit:
2683 /* Disable access to flash interface and release the lock. */
2684 bce_disable_nvram_access(sc);
2685 bce_release_nvram_lock(sc);
2687 bce_nvram_read_exit:
2688 DBEXIT(BCE_VERBOSE_NVRAM);
2693 #ifdef BCE_NVRAM_WRITE_SUPPORT
2694 /****************************************************************************/
2695 /* Write an arbitrary range of data from NVRAM. */
2697 /* Prepares the NVRAM interface for write access and writes the requested */
2698 /* data from the supplied buffer. The caller is responsible for */
2699 /* calculating any appropriate CRCs. */
2702 /* 0 on success, positive value on failure. */
2703 /****************************************************************************/
2705 bce_nvram_write(struct bce_softc *sc, u32 offset, u8 *data_buf,
2708 u32 written, offset32, len32;
2709 u8 *buf, start[4], end[4];
2711 int align_start, align_end;
2713 DBENTER(BCE_VERBOSE_NVRAM);
2718 align_start = align_end = 0;
2720 if ((align_start = (offset32 & 3))) {
2722 len32 += align_start;
2723 if ((rc = bce_nvram_read(sc, offset32, start, 4)))
2724 goto bce_nvram_write_exit;
2728 if ((len32 > 4) || !align_start) {
2729 align_end = 4 - (len32 & 3);
2731 if ((rc = bce_nvram_read(sc, offset32 + len32 - 4,
2733 goto bce_nvram_write_exit;
2738 if (align_start || align_end) {
2739 buf = malloc(len32, M_DEVBUF, M_NOWAIT);
2742 goto bce_nvram_write_exit;
2746 memcpy(buf, start, 4);
2750 memcpy(buf + len32 - 4, end, 4);
2752 memcpy(buf + align_start, data_buf, buf_size);
2756 while ((written < len32) && (rc == 0)) {
2757 u32 page_start, page_end, data_start, data_end;
2758 u32 addr, cmd_flags;
2760 u8 flash_buffer[264];
2762 /* Find the page_start addr */
2763 page_start = offset32 + written;
2764 page_start -= (page_start % sc->bce_flash_info->page_size);
2765 /* Find the page_end addr */
2766 page_end = page_start + sc->bce_flash_info->page_size;
2767 /* Find the data_start addr */
2768 data_start = (written == 0) ? offset32 : page_start;
2769 /* Find the data_end addr */
2770 data_end = (page_end > offset32 + len32) ?
2771 (offset32 + len32) : page_end;
2773 /* Request access to the flash interface. */
2774 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2775 goto bce_nvram_write_exit;
2777 /* Enable access to flash interface */
2778 bce_enable_nvram_access(sc);
2780 cmd_flags = BCE_NVM_COMMAND_FIRST;
2781 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2784 /* Read the whole page into the buffer
2785 * (non-buffer flash only) */
2786 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
2787 if (j == (sc->bce_flash_info->page_size - 4)) {
2788 cmd_flags |= BCE_NVM_COMMAND_LAST;
2790 rc = bce_nvram_read_dword(sc,
2796 goto bce_nvram_write_locked_exit;
2802 /* Enable writes to flash interface (unlock write-protect) */
2803 if ((rc = bce_enable_nvram_write(sc)) != 0)
2804 goto bce_nvram_write_locked_exit;
2806 /* Erase the page */
2807 if ((rc = bce_nvram_erase_page(sc, page_start)) != 0)
2808 goto bce_nvram_write_locked_exit;
2810 /* Re-enable the write again for the actual write */
2811 bce_enable_nvram_write(sc);
2813 /* Loop to write back the buffer data from page_start to
2816 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2817 for (addr = page_start; addr < data_start;
2818 addr += 4, i += 4) {
2820 rc = bce_nvram_write_dword(sc, addr,
2821 &flash_buffer[i], cmd_flags);
2824 goto bce_nvram_write_locked_exit;
2830 /* Loop to write the new data from data_start to data_end */
2831 for (addr = data_start; addr < data_end; addr += 4, i++) {
2832 if ((addr == page_end - 4) ||
2833 ((sc->bce_flash_info->flags & BCE_NV_BUFFERED) &&
2834 (addr == data_end - 4))) {
2836 cmd_flags |= BCE_NVM_COMMAND_LAST;
2838 rc = bce_nvram_write_dword(sc, addr, buf,
2842 goto bce_nvram_write_locked_exit;
2848 /* Loop to write back the buffer data from data_end
2850 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2851 for (addr = data_end; addr < page_end;
2852 addr += 4, i += 4) {
2854 if (addr == page_end-4) {
2855 cmd_flags = BCE_NVM_COMMAND_LAST;
2857 rc = bce_nvram_write_dword(sc, addr,
2858 &flash_buffer[i], cmd_flags);
2861 goto bce_nvram_write_locked_exit;
2867 /* Disable writes to flash interface (lock write-protect) */
2868 bce_disable_nvram_write(sc);
2870 /* Disable access to flash interface */
2871 bce_disable_nvram_access(sc);
2872 bce_release_nvram_lock(sc);
2874 /* Increment written */
2875 written += data_end - data_start;
2878 goto bce_nvram_write_exit;
2880 bce_nvram_write_locked_exit:
2881 bce_disable_nvram_write(sc);
2882 bce_disable_nvram_access(sc);
2883 bce_release_nvram_lock(sc);
2885 bce_nvram_write_exit:
2886 if (align_start || align_end)
2887 free(buf, M_DEVBUF);
2889 DBEXIT(BCE_VERBOSE_NVRAM);
2892 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2895 /****************************************************************************/
2896 /* Verifies that NVRAM is accessible and contains valid data. */
2898 /* Reads the configuration data from NVRAM and verifies that the CRC is */
2902 /* 0 on success, positive value on failure. */
2903 /****************************************************************************/
2905 bce_nvram_test(struct bce_softc *sc)
2907 u32 buf[BCE_NVRAM_SIZE / 4];
2908 u8 *data = (u8 *) buf;
2912 DBENTER(BCE_VERBOSE_NVRAM | BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
2915 * Check that the device NVRAM is valid by reading
2916 * the magic value at offset 0.
2918 if ((rc = bce_nvram_read(sc, 0, data, 4)) != 0) {
2919 BCE_PRINTF("%s(%d): Unable to read NVRAM!\n",
2920 __FILE__, __LINE__);
2921 goto bce_nvram_test_exit;
2925 * Verify that offset 0 of the NVRAM contains
2926 * a valid magic number.
2928 magic = bce_be32toh(buf[0]);
2929 if (magic != BCE_NVRAM_MAGIC) {
2931 BCE_PRINTF("%s(%d): Invalid NVRAM magic value! "
2932 "Expected: 0x%08X, Found: 0x%08X\n",
2933 __FILE__, __LINE__, BCE_NVRAM_MAGIC, magic);
2934 goto bce_nvram_test_exit;
2938 * Verify that the device NVRAM includes valid
2939 * configuration data.
2941 if ((rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE)) != 0) {
2942 BCE_PRINTF("%s(%d): Unable to read manufacturing "
2943 "Information from NVRAM!\n", __FILE__, __LINE__);
2944 goto bce_nvram_test_exit;
2947 csum = ether_crc32_le(data, 0x100);
2948 if (csum != BCE_CRC32_RESIDUAL) {
2950 BCE_PRINTF("%s(%d): Invalid manufacturing information "
2951 "NVRAM CRC! Expected: 0x%08X, Found: 0x%08X\n",
2952 __FILE__, __LINE__, BCE_CRC32_RESIDUAL, csum);
2953 goto bce_nvram_test_exit;
2956 csum = ether_crc32_le(data + 0x100, 0x100);
2957 if (csum != BCE_CRC32_RESIDUAL) {
2959 BCE_PRINTF("%s(%d): Invalid feature configuration "
2960 "information NVRAM CRC! Expected: 0x%08X, "
2961 "Found: 08%08X\n", __FILE__, __LINE__,
2962 BCE_CRC32_RESIDUAL, csum);
2965 bce_nvram_test_exit:
2966 DBEXIT(BCE_VERBOSE_NVRAM | BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
2971 /****************************************************************************/
2972 /* Calculates the size of the buffers to allocate based on the MTU. */
2976 /****************************************************************************/
2978 bce_get_rx_buffer_sizes(struct bce_softc *sc, int mtu)
2980 DBENTER(BCE_VERBOSE_LOAD);
2982 /* Use a single allocation type when header splitting enabled. */
2983 if (bce_hdr_split == TRUE) {
2984 sc->rx_bd_mbuf_alloc_size = MHLEN;
2985 /* Make sure offset is 16 byte aligned for hardware. */
2986 sc->rx_bd_mbuf_align_pad =
2987 roundup2((MSIZE - MHLEN), 16) - (MSIZE - MHLEN);
2988 sc->rx_bd_mbuf_data_len = sc->rx_bd_mbuf_alloc_size -
2989 sc->rx_bd_mbuf_align_pad;
2990 sc->pg_bd_mbuf_alloc_size = MCLBYTES;
2992 if ((mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN +
2993 ETHER_CRC_LEN) > MCLBYTES) {
2994 /* Setup for jumbo RX buffer allocations. */
2995 sc->rx_bd_mbuf_alloc_size = MJUM9BYTES;
2996 sc->rx_bd_mbuf_align_pad =
2997 roundup2(MJUM9BYTES, 16) - MJUM9BYTES;
2998 sc->rx_bd_mbuf_data_len =
2999 sc->rx_bd_mbuf_alloc_size -
3000 sc->rx_bd_mbuf_align_pad;
3002 /* Setup for standard RX buffer allocations. */
3003 sc->rx_bd_mbuf_alloc_size = MCLBYTES;
3004 sc->rx_bd_mbuf_align_pad =
3005 roundup2(MCLBYTES, 16) - MCLBYTES;
3006 sc->rx_bd_mbuf_data_len =
3007 sc->rx_bd_mbuf_alloc_size -
3008 sc->rx_bd_mbuf_align_pad;
3012 // DBPRINT(sc, BCE_INFO_LOAD,
3013 DBPRINT(sc, BCE_WARN,
3014 "%s(): rx_bd_mbuf_alloc_size = %d, rx_bd_mbuf_data_len = %d, "
3015 "rx_bd_mbuf_align_pad = %d\n", __FUNCTION__,
3016 sc->rx_bd_mbuf_alloc_size, sc->rx_bd_mbuf_data_len,
3017 sc->rx_bd_mbuf_align_pad);
3019 DBEXIT(BCE_VERBOSE_LOAD);
3023 /****************************************************************************/
3024 /* Identifies the current media type of the controller and sets the PHY */
3029 /****************************************************************************/
3031 bce_get_media(struct bce_softc *sc)
3035 DBENTER(BCE_VERBOSE_PHY);
3037 /* Assume PHY address for copper controllers. */
3038 sc->bce_phy_addr = 1;
3040 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
3041 u32 val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
3042 u32 bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
3046 * The BCM5709S is software configurable
3047 * for Copper or SerDes operation.
3049 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
3050 DBPRINT(sc, BCE_INFO_LOAD, "5709 bonded "
3052 goto bce_get_media_exit;
3053 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
3054 DBPRINT(sc, BCE_INFO_LOAD, "5709 bonded "
3055 "for dual media.\n");
3056 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3057 goto bce_get_media_exit;
3060 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
3062 BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
3065 BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
3067 if (pci_get_function(sc->bce_dev) == 0) {
3072 DBPRINT(sc, BCE_INFO_LOAD,
3073 "BCM5709 s/w configured for SerDes.\n");
3074 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3077 DBPRINT(sc, BCE_INFO_LOAD,
3078 "BCM5709 s/w configured for Copper.\n");
3086 DBPRINT(sc, BCE_INFO_LOAD,
3087 "BCM5709 s/w configured for SerDes.\n");
3088 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3091 DBPRINT(sc, BCE_INFO_LOAD,
3092 "BCM5709 s/w configured for Copper.\n");
3097 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT)
3098 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3100 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
3102 sc->bce_flags |= BCE_NO_WOL_FLAG;
3104 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
3105 sc->bce_phy_flags |= BCE_PHY_IEEE_CLAUSE_45_FLAG;
3107 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
3108 /* 5708S/09S/16S use a separate PHY for SerDes. */
3109 sc->bce_phy_addr = 2;
3111 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
3112 if (val & BCE_SHARED_HW_CFG_PHY_2_5G) {
3113 sc->bce_phy_flags |=
3114 BCE_PHY_2_5G_CAPABLE_FLAG;
3115 DBPRINT(sc, BCE_INFO_LOAD, "Found 2.5Gb "
3116 "capable adapter\n");
3119 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
3120 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708))
3121 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
3124 DBPRINT(sc, (BCE_INFO_LOAD | BCE_INFO_PHY),
3125 "Using PHY address %d.\n", sc->bce_phy_addr);
3127 DBEXIT(BCE_VERBOSE_PHY);
3131 /****************************************************************************/
3132 /* Performs PHY initialization required before MII drivers access the */
3137 /****************************************************************************/
3139 bce_init_media(struct bce_softc *sc)
3141 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
3143 * Configure 5709S/5716S PHYs to use traditional IEEE
3144 * Clause 22 method. Otherwise we have no way to attach
3145 * the PHY in mii(4) layer. PHY specific configuration
3146 * is done in mii layer.
3149 /* Select auto-negotiation MMD of the PHY. */
3150 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
3151 BRGPHY_BLOCK_ADDR, BRGPHY_BLOCK_ADDR_ADDR_EXT);
3152 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
3153 BRGPHY_ADDR_EXT, BRGPHY_ADDR_EXT_AN_MMD);
3155 /* Set IEEE0 block of AN MMD (assumed in brgphy(4) code). */
3156 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
3157 BRGPHY_BLOCK_ADDR, BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
3162 /****************************************************************************/
3163 /* Free any DMA memory owned by the driver. */
3165 /* Scans through each data structre that requires DMA memory and frees */
3166 /* the memory if allocated. */
3170 /****************************************************************************/
3172 bce_dma_free(struct bce_softc *sc)
3176 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_UNLOAD | BCE_VERBOSE_CTX);
3178 /* Free, unmap, and destroy the status block. */
3179 if (sc->status_block != NULL) {
3184 sc->status_block = NULL;
3187 if (sc->status_map != NULL) {
3191 bus_dmamap_destroy(sc->status_tag,
3193 sc->status_map = NULL;
3196 if (sc->status_tag != NULL) {
3197 bus_dma_tag_destroy(sc->status_tag);
3198 sc->status_tag = NULL;
3202 /* Free, unmap, and destroy the statistics block. */
3203 if (sc->stats_block != NULL) {
3208 sc->stats_block = NULL;
3211 if (sc->stats_map != NULL) {
3215 bus_dmamap_destroy(sc->stats_tag,
3217 sc->stats_map = NULL;
3220 if (sc->stats_tag != NULL) {
3221 bus_dma_tag_destroy(sc->stats_tag);
3222 sc->stats_tag = NULL;
3226 /* Free, unmap and destroy all context memory pages. */
3227 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
3228 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
3229 for (i = 0; i < sc->ctx_pages; i++ ) {
3230 if (sc->ctx_block[i] != NULL) {
3235 sc->ctx_block[i] = NULL;
3238 if (sc->ctx_map[i] != NULL) {
3245 sc->ctx_map[i] = NULL;
3249 /* Destroy the context memory tag. */
3250 if (sc->ctx_tag != NULL) {
3251 bus_dma_tag_destroy(sc->ctx_tag);
3257 /* Free, unmap and destroy all TX buffer descriptor chain pages. */
3258 for (i = 0; i < sc->tx_pages; i++ ) {
3259 if (sc->tx_bd_chain[i] != NULL) {
3261 sc->tx_bd_chain_tag,
3263 sc->tx_bd_chain_map[i]);
3264 sc->tx_bd_chain[i] = NULL;
3267 if (sc->tx_bd_chain_map[i] != NULL) {
3269 sc->tx_bd_chain_tag,
3270 sc->tx_bd_chain_map[i]);
3272 sc->tx_bd_chain_tag,
3273 sc->tx_bd_chain_map[i]);
3274 sc->tx_bd_chain_map[i] = NULL;
3278 /* Destroy the TX buffer descriptor tag. */
3279 if (sc->tx_bd_chain_tag != NULL) {
3280 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
3281 sc->tx_bd_chain_tag = NULL;
3285 /* Free, unmap and destroy all RX buffer descriptor chain pages. */
3286 for (i = 0; i < sc->rx_pages; i++ ) {
3287 if (sc->rx_bd_chain[i] != NULL) {
3289 sc->rx_bd_chain_tag,
3291 sc->rx_bd_chain_map[i]);
3292 sc->rx_bd_chain[i] = NULL;
3295 if (sc->rx_bd_chain_map[i] != NULL) {
3297 sc->rx_bd_chain_tag,
3298 sc->rx_bd_chain_map[i]);
3300 sc->rx_bd_chain_tag,
3301 sc->rx_bd_chain_map[i]);
3302 sc->rx_bd_chain_map[i] = NULL;
3306 /* Destroy the RX buffer descriptor tag. */
3307 if (sc->rx_bd_chain_tag != NULL) {
3308 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
3309 sc->rx_bd_chain_tag = NULL;
3313 /* Free, unmap and destroy all page buffer descriptor chain pages. */
3314 if (bce_hdr_split == TRUE) {
3315 for (i = 0; i < sc->pg_pages; i++ ) {
3316 if (sc->pg_bd_chain[i] != NULL) {
3318 sc->pg_bd_chain_tag,
3320 sc->pg_bd_chain_map[i]);
3321 sc->pg_bd_chain[i] = NULL;
3324 if (sc->pg_bd_chain_map[i] != NULL) {
3326 sc->pg_bd_chain_tag,
3327 sc->pg_bd_chain_map[i]);
3329 sc->pg_bd_chain_tag,
3330 sc->pg_bd_chain_map[i]);
3331 sc->pg_bd_chain_map[i] = NULL;
3335 /* Destroy the page buffer descriptor tag. */
3336 if (sc->pg_bd_chain_tag != NULL) {
3337 bus_dma_tag_destroy(sc->pg_bd_chain_tag);
3338 sc->pg_bd_chain_tag = NULL;
3343 /* Unload and destroy the TX mbuf maps. */
3344 for (i = 0; i < MAX_TX_BD_AVAIL; i++) {
3345 if (sc->tx_mbuf_map[i] != NULL) {
3346 bus_dmamap_unload(sc->tx_mbuf_tag,
3347 sc->tx_mbuf_map[i]);
3348 bus_dmamap_destroy(sc->tx_mbuf_tag,
3349 sc->tx_mbuf_map[i]);
3350 sc->tx_mbuf_map[i] = NULL;
3354 /* Destroy the TX mbuf tag. */
3355 if (sc->tx_mbuf_tag != NULL) {
3356 bus_dma_tag_destroy(sc->tx_mbuf_tag);
3357 sc->tx_mbuf_tag = NULL;
3360 /* Unload and destroy the RX mbuf maps. */
3361 for (i = 0; i < MAX_RX_BD_AVAIL; i++) {
3362 if (sc->rx_mbuf_map[i] != NULL) {
3363 bus_dmamap_unload(sc->rx_mbuf_tag,
3364 sc->rx_mbuf_map[i]);
3365 bus_dmamap_destroy(sc->rx_mbuf_tag,
3366 sc->rx_mbuf_map[i]);
3367 sc->rx_mbuf_map[i] = NULL;
3371 /* Destroy the RX mbuf tag. */
3372 if (sc->rx_mbuf_tag != NULL) {
3373 bus_dma_tag_destroy(sc->rx_mbuf_tag);
3374 sc->rx_mbuf_tag = NULL;
3377 /* Unload and destroy the page mbuf maps. */
3378 if (bce_hdr_split == TRUE) {
3379 for (i = 0; i < MAX_PG_BD_AVAIL; i++) {
3380 if (sc->pg_mbuf_map[i] != NULL) {
3381 bus_dmamap_unload(sc->pg_mbuf_tag,
3382 sc->pg_mbuf_map[i]);
3383 bus_dmamap_destroy(sc->pg_mbuf_tag,
3384 sc->pg_mbuf_map[i]);
3385 sc->pg_mbuf_map[i] = NULL;
3389 /* Destroy the page mbuf tag. */
3390 if (sc->pg_mbuf_tag != NULL) {
3391 bus_dma_tag_destroy(sc->pg_mbuf_tag);
3392 sc->pg_mbuf_tag = NULL;
3396 /* Destroy the parent tag */
3397 if (sc->parent_tag != NULL) {
3398 bus_dma_tag_destroy(sc->parent_tag);
3399 sc->parent_tag = NULL;
3402 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_UNLOAD | BCE_VERBOSE_CTX);
3406 /****************************************************************************/
3407 /* Get DMA memory from the OS. */
3409 /* Validates that the OS has provided DMA buffers in response to a */
3410 /* bus_dmamap_load() call and saves the physical address of those buffers. */
3411 /* When the callback is used the OS will return 0 for the mapping function */
3412 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
3413 /* failures back to the caller. */
3417 /****************************************************************************/
3419 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
3421 bus_addr_t *busaddr = arg;
3423 KASSERT(nseg == 1, ("%s(): Too many segments returned (%d)!",
3424 __FUNCTION__, nseg));
3425 /* Simulate a mapping failure. */
3426 DBRUNIF(DB_RANDOMTRUE(dma_map_addr_failed_sim_control),
3429 /* ToDo: How to increment debug sim_count variable here? */
3431 /* Check for an error and signal the caller that an error occurred. */
3435 *busaddr = segs->ds_addr;
3442 /****************************************************************************/
3443 /* Allocate any DMA memory needed by the driver. */
3445 /* Allocates DMA memory needed for the various global structures needed by */
3448 /* Memory alignment requirements: */
3449 /* +-----------------+----------+----------+----------+----------+ */
3450 /* | | 5706 | 5708 | 5709 | 5716 | */
3451 /* +-----------------+----------+----------+----------+----------+ */
3452 /* |Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
3453 /* |Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
3454 /* |RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
3455 /* |PG Buffers | none | none | none | none | */
3456 /* |TX Buffers | none | none | none | none | */
3457 /* |Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
3458 /* |Context Memory | | | | | */
3459 /* +-----------------+----------+----------+----------+----------+ */
3461 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
3464 /* 0 for success, positive value for failure. */
3465 /****************************************************************************/
3467 bce_dma_alloc(device_t dev)
3469 struct bce_softc *sc;
3470 int i, error, rc = 0;
3471 bus_size_t max_size, max_seg_size;
3474 sc = device_get_softc(dev);
3476 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
3479 * Allocate the parent bus DMA tag appropriate for PCI.
3481 if (bus_dma_tag_create(bus_get_dma_tag(dev), 1, BCE_DMA_BOUNDARY,
3482 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3483 BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL,
3485 BCE_PRINTF("%s(%d): Could not allocate parent DMA tag!\n",
3486 __FILE__, __LINE__);
3488 goto bce_dma_alloc_exit;
3492 * Create a DMA tag for the status block, allocate and clear the
3493 * memory, map the memory into DMA space, and fetch the physical
3494 * address of the block.
3496 if (bus_dma_tag_create(sc->parent_tag, BCE_DMA_ALIGN,
3497 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3498 NULL, NULL, BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
3499 0, NULL, NULL, &sc->status_tag)) {
3500 BCE_PRINTF("%s(%d): Could not allocate status block "
3501 "DMA tag!\n", __FILE__, __LINE__);
3503 goto bce_dma_alloc_exit;
3506 if(bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
3507 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3509 BCE_PRINTF("%s(%d): Could not allocate status block "
3510 "DMA memory!\n", __FILE__, __LINE__);
3512 goto bce_dma_alloc_exit;
3515 error = bus_dmamap_load(sc->status_tag, sc->status_map,
3516 sc->status_block, BCE_STATUS_BLK_SZ, bce_dma_map_addr,
3517 &sc->status_block_paddr, BUS_DMA_NOWAIT);
3520 BCE_PRINTF("%s(%d): Could not map status block "
3521 "DMA memory!\n", __FILE__, __LINE__);
3523 goto bce_dma_alloc_exit;
3526 DBPRINT(sc, BCE_INFO_LOAD, "%s(): status_block_paddr = 0x%jX\n",
3527 __FUNCTION__, (uintmax_t) sc->status_block_paddr);
3530 * Create a DMA tag for the statistics block, allocate and clear the
3531 * memory, map the memory into DMA space, and fetch the physical
3532 * address of the block.
3534 if (bus_dma_tag_create(sc->parent_tag, BCE_DMA_ALIGN,
3535 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3536 NULL, NULL, BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
3537 0, NULL, NULL, &sc->stats_tag)) {
3538 BCE_PRINTF("%s(%d): Could not allocate statistics block "
3539 "DMA tag!\n", __FILE__, __LINE__);
3541 goto bce_dma_alloc_exit;
3544 if (bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
3545 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT, &sc->stats_map)) {
3546 BCE_PRINTF("%s(%d): Could not allocate statistics block "
3547 "DMA memory!\n", __FILE__, __LINE__);
3549 goto bce_dma_alloc_exit;
3552 error = bus_dmamap_load(sc->stats_tag, sc->stats_map,
3553 sc->stats_block, BCE_STATS_BLK_SZ, bce_dma_map_addr,
3554 &sc->stats_block_paddr, BUS_DMA_NOWAIT);
3557 BCE_PRINTF("%s(%d): Could not map statistics block "
3558 "DMA memory!\n", __FILE__, __LINE__);
3560 goto bce_dma_alloc_exit;
3563 DBPRINT(sc, BCE_INFO_LOAD, "%s(): stats_block_paddr = 0x%jX\n",
3564 __FUNCTION__, (uintmax_t) sc->stats_block_paddr);
3566 /* BCM5709 uses host memory as cache for context memory. */
3567 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
3568 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
3569 sc->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
3570 if (sc->ctx_pages == 0)
3573 DBRUNIF((sc->ctx_pages > 512),
3574 BCE_PRINTF("%s(%d): Too many CTX pages! %d > 512\n",
3575 __FILE__, __LINE__, sc->ctx_pages));
3578 * Create a DMA tag for the context pages,
3579 * allocate and clear the memory, map the
3580 * memory into DMA space, and fetch the
3581 * physical address of the block.
3583 if(bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3584 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3585 NULL, NULL, BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
3586 0, NULL, NULL, &sc->ctx_tag)) {
3587 BCE_PRINTF("%s(%d): Could not allocate CTX "
3588 "DMA tag!\n", __FILE__, __LINE__);
3590 goto bce_dma_alloc_exit;
3593 for (i = 0; i < sc->ctx_pages; i++) {
3595 if(bus_dmamem_alloc(sc->ctx_tag,
3596 (void **)&sc->ctx_block[i],
3597 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3599 BCE_PRINTF("%s(%d): Could not allocate CTX "
3600 "DMA memory!\n", __FILE__, __LINE__);
3602 goto bce_dma_alloc_exit;
3605 error = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
3606 sc->ctx_block[i], BCM_PAGE_SIZE, bce_dma_map_addr,
3607 &sc->ctx_paddr[i], BUS_DMA_NOWAIT);
3610 BCE_PRINTF("%s(%d): Could not map CTX "
3611 "DMA memory!\n", __FILE__, __LINE__);
3613 goto bce_dma_alloc_exit;
3616 DBPRINT(sc, BCE_INFO_LOAD, "%s(): ctx_paddr[%d] "
3617 "= 0x%jX\n", __FUNCTION__, i,
3618 (uintmax_t) sc->ctx_paddr[i]);
3623 * Create a DMA tag for the TX buffer descriptor chain,
3624 * allocate and clear the memory, and fetch the
3625 * physical address of the block.
3627 if(bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
3628 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3629 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ, 0,
3630 NULL, NULL, &sc->tx_bd_chain_tag)) {
3631 BCE_PRINTF("%s(%d): Could not allocate TX descriptor "
3632 "chain DMA tag!\n", __FILE__, __LINE__);
3634 goto bce_dma_alloc_exit;
3637 for (i = 0; i < sc->tx_pages; i++) {
3639 if(bus_dmamem_alloc(sc->tx_bd_chain_tag,
3640 (void **)&sc->tx_bd_chain[i],
3641 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3642 &sc->tx_bd_chain_map[i])) {
3643 BCE_PRINTF("%s(%d): Could not allocate TX descriptor "
3644 "chain DMA memory!\n", __FILE__, __LINE__);
3646 goto bce_dma_alloc_exit;
3649 error = bus_dmamap_load(sc->tx_bd_chain_tag,
3650 sc->tx_bd_chain_map[i], sc->tx_bd_chain[i],
3651 BCE_TX_CHAIN_PAGE_SZ, bce_dma_map_addr,
3652 &sc->tx_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3655 BCE_PRINTF("%s(%d): Could not map TX descriptor "
3656 "chain DMA memory!\n", __FILE__, __LINE__);
3658 goto bce_dma_alloc_exit;
3661 DBPRINT(sc, BCE_INFO_LOAD, "%s(): tx_bd_chain_paddr[%d] = "
3662 "0x%jX\n", __FUNCTION__, i,
3663 (uintmax_t) sc->tx_bd_chain_paddr[i]);
3666 /* Check the required size before mapping to conserve resources. */
3667 if (bce_tso_enable) {
3668 max_size = BCE_TSO_MAX_SIZE;
3669 max_segments = BCE_MAX_SEGMENTS;
3670 max_seg_size = BCE_TSO_MAX_SEG_SIZE;
3672 max_size = MCLBYTES * BCE_MAX_SEGMENTS;
3673 max_segments = BCE_MAX_SEGMENTS;
3674 max_seg_size = MCLBYTES;
3677 /* Create a DMA tag for TX mbufs. */
3678 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3679 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL, max_size,
3680 max_segments, max_seg_size, 0, NULL, NULL, &sc->tx_mbuf_tag)) {
3681 BCE_PRINTF("%s(%d): Could not allocate TX mbuf DMA tag!\n",
3682 __FILE__, __LINE__);
3684 goto bce_dma_alloc_exit;
3687 /* Create DMA maps for the TX mbufs clusters. */
3688 for (i = 0; i < TOTAL_TX_BD_ALLOC; i++) {
3689 if (bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_NOWAIT,
3690 &sc->tx_mbuf_map[i])) {
3691 BCE_PRINTF("%s(%d): Unable to create TX mbuf DMA "
3692 "map!\n", __FILE__, __LINE__);
3694 goto bce_dma_alloc_exit;
3699 * Create a DMA tag for the RX buffer descriptor chain,
3700 * allocate and clear the memory, and fetch the physical
3701 * address of the blocks.
3703 if (bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3704 BCE_DMA_BOUNDARY, BUS_SPACE_MAXADDR,
3705 sc->max_bus_addr, NULL, NULL,
3706 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
3707 0, NULL, NULL, &sc->rx_bd_chain_tag)) {
3708 BCE_PRINTF("%s(%d): Could not allocate RX descriptor chain "
3709 "DMA tag!\n", __FILE__, __LINE__);
3711 goto bce_dma_alloc_exit;
3714 for (i = 0; i < sc->rx_pages; i++) {
3716 if (bus_dmamem_alloc(sc->rx_bd_chain_tag,
3717 (void **)&sc->rx_bd_chain[i],
3718 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3719 &sc->rx_bd_chain_map[i])) {
3720 BCE_PRINTF("%s(%d): Could not allocate RX descriptor "
3721 "chain DMA memory!\n", __FILE__, __LINE__);
3723 goto bce_dma_alloc_exit;
3726 error = bus_dmamap_load(sc->rx_bd_chain_tag,
3727 sc->rx_bd_chain_map[i], sc->rx_bd_chain[i],
3728 BCE_RX_CHAIN_PAGE_SZ, bce_dma_map_addr,
3729 &sc->rx_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3732 BCE_PRINTF("%s(%d): Could not map RX descriptor "
3733 "chain DMA memory!\n", __FILE__, __LINE__);
3735 goto bce_dma_alloc_exit;
3738 DBPRINT(sc, BCE_INFO_LOAD, "%s(): rx_bd_chain_paddr[%d] = "
3739 "0x%jX\n", __FUNCTION__, i,
3740 (uintmax_t) sc->rx_bd_chain_paddr[i]);
3744 * Create a DMA tag for RX mbufs.
3746 if (bce_hdr_split == TRUE)
3747 max_size = max_seg_size = ((sc->rx_bd_mbuf_alloc_size < MCLBYTES) ?
3748 MCLBYTES : sc->rx_bd_mbuf_alloc_size);
3750 max_size = max_seg_size = MJUM9BYTES;
3753 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Creating rx_mbuf_tag "
3754 "(max size = 0x%jX max segments = %d, max segment "
3755 "size = 0x%jX)\n", __FUNCTION__, (uintmax_t) max_size,
3756 max_segments, (uintmax_t) max_seg_size);
3758 if (bus_dma_tag_create(sc->parent_tag, BCE_RX_BUF_ALIGN,
3759 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3760 max_size, max_segments, max_seg_size, 0, NULL, NULL,
3761 &sc->rx_mbuf_tag)) {
3762 BCE_PRINTF("%s(%d): Could not allocate RX mbuf DMA tag!\n",
3763 __FILE__, __LINE__);
3765 goto bce_dma_alloc_exit;
3768 /* Create DMA maps for the RX mbuf clusters. */
3769 for (i = 0; i < TOTAL_RX_BD_ALLOC; i++) {
3770 if (bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_NOWAIT,
3771 &sc->rx_mbuf_map[i])) {
3772 BCE_PRINTF("%s(%d): Unable to create RX mbuf "
3773 "DMA map!\n", __FILE__, __LINE__);
3775 goto bce_dma_alloc_exit;
3779 if (bce_hdr_split == TRUE) {
3781 * Create a DMA tag for the page buffer descriptor chain,
3782 * allocate and clear the memory, and fetch the physical
3783 * address of the blocks.
3785 if (bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3786 BCE_DMA_BOUNDARY, BUS_SPACE_MAXADDR, sc->max_bus_addr,
3787 NULL, NULL, BCE_PG_CHAIN_PAGE_SZ, 1, BCE_PG_CHAIN_PAGE_SZ,
3788 0, NULL, NULL, &sc->pg_bd_chain_tag)) {
3789 BCE_PRINTF("%s(%d): Could not allocate page descriptor "
3790 "chain DMA tag!\n", __FILE__, __LINE__);
3792 goto bce_dma_alloc_exit;
3795 for (i = 0; i < sc->pg_pages; i++) {
3796 if (bus_dmamem_alloc(sc->pg_bd_chain_tag,
3797 (void **)&sc->pg_bd_chain[i],
3798 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3799 &sc->pg_bd_chain_map[i])) {
3800 BCE_PRINTF("%s(%d): Could not allocate page "
3801 "descriptor chain DMA memory!\n",
3802 __FILE__, __LINE__);
3804 goto bce_dma_alloc_exit;
3807 error = bus_dmamap_load(sc->pg_bd_chain_tag,
3808 sc->pg_bd_chain_map[i], sc->pg_bd_chain[i],
3809 BCE_PG_CHAIN_PAGE_SZ, bce_dma_map_addr,
3810 &sc->pg_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3813 BCE_PRINTF("%s(%d): Could not map page descriptor "
3814 "chain DMA memory!\n", __FILE__, __LINE__);
3816 goto bce_dma_alloc_exit;
3819 DBPRINT(sc, BCE_INFO_LOAD, "%s(): pg_bd_chain_paddr[%d] = "
3820 "0x%jX\n", __FUNCTION__, i,
3821 (uintmax_t) sc->pg_bd_chain_paddr[i]);
3825 * Create a DMA tag for page mbufs.
3827 max_size = max_seg_size = ((sc->pg_bd_mbuf_alloc_size < MCLBYTES) ?
3828 MCLBYTES : sc->pg_bd_mbuf_alloc_size);
3830 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3831 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3832 max_size, 1, max_seg_size, 0, NULL, NULL, &sc->pg_mbuf_tag)) {
3833 BCE_PRINTF("%s(%d): Could not allocate page mbuf "
3834 "DMA tag!\n", __FILE__, __LINE__);
3836 goto bce_dma_alloc_exit;
3839 /* Create DMA maps for the page mbuf clusters. */
3840 for (i = 0; i < TOTAL_PG_BD_ALLOC; i++) {
3841 if (bus_dmamap_create(sc->pg_mbuf_tag, BUS_DMA_NOWAIT,
3842 &sc->pg_mbuf_map[i])) {
3843 BCE_PRINTF("%s(%d): Unable to create page mbuf "
3844 "DMA map!\n", __FILE__, __LINE__);
3846 goto bce_dma_alloc_exit;
3852 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
3857 /****************************************************************************/
3858 /* Release all resources used by the driver. */
3860 /* Releases all resources acquired by the driver including interrupts, */
3861 /* interrupt handler, interfaces, mutexes, and DMA memory. */
3865 /****************************************************************************/
3867 bce_release_resources(struct bce_softc *sc)
3871 DBENTER(BCE_VERBOSE_RESET);
3877 if (sc->bce_intrhand != NULL) {
3878 DBPRINT(sc, BCE_INFO_RESET, "Removing interrupt handler.\n");
3879 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
3882 if (sc->bce_res_irq != NULL) {
3883 DBPRINT(sc, BCE_INFO_RESET, "Releasing IRQ.\n");
3884 bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
3888 if (sc->bce_flags & (BCE_USING_MSI_FLAG | BCE_USING_MSIX_FLAG)) {
3889 DBPRINT(sc, BCE_INFO_RESET, "Releasing MSI/MSI-X vector.\n");
3890 pci_release_msi(dev);
3893 if (sc->bce_res_mem != NULL) {
3894 DBPRINT(sc, BCE_INFO_RESET, "Releasing PCI memory.\n");
3895 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
3899 if (sc->bce_ifp != NULL) {
3900 DBPRINT(sc, BCE_INFO_RESET, "Releasing IF.\n");
3901 if_free(sc->bce_ifp);
3904 if (mtx_initialized(&sc->bce_mtx))
3905 BCE_LOCK_DESTROY(sc);
3907 DBEXIT(BCE_VERBOSE_RESET);
3911 /****************************************************************************/
3912 /* Firmware synchronization. */
3914 /* Before performing certain events such as a chip reset, synchronize with */
3915 /* the firmware first. */
3918 /* 0 for success, positive value for failure. */
3919 /****************************************************************************/
3921 bce_fw_sync(struct bce_softc *sc, u32 msg_data)
3926 DBENTER(BCE_VERBOSE_RESET);
3928 /* Don't waste any time if we've timed out before. */
3929 if (sc->bce_fw_timed_out == TRUE) {
3931 goto bce_fw_sync_exit;
3934 /* Increment the message sequence number. */
3935 sc->bce_fw_wr_seq++;
3936 msg_data |= sc->bce_fw_wr_seq;
3938 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "bce_fw_sync(): msg_data = "
3939 "0x%08X\n", msg_data);
3941 /* Send the message to the bootcode driver mailbox. */
3942 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
3944 /* Wait for the bootcode to acknowledge the message. */
3945 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
3946 /* Check for a response in the bootcode firmware mailbox. */
3947 val = bce_shmem_rd(sc, BCE_FW_MB);
3948 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
3953 /* If we've timed out, tell bootcode that we've stopped waiting. */
3954 if (((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ)) &&
3955 ((msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0)) {
3957 BCE_PRINTF("%s(%d): Firmware synchronization timeout! "
3958 "msg_data = 0x%08X\n", __FILE__, __LINE__, msg_data);
3960 msg_data &= ~BCE_DRV_MSG_CODE;
3961 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
3963 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
3965 sc->bce_fw_timed_out = TRUE;
3970 DBEXIT(BCE_VERBOSE_RESET);
3975 /****************************************************************************/
3976 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
3980 /****************************************************************************/
3982 bce_load_rv2p_fw(struct bce_softc *sc, u32 *rv2p_code,
3983 u32 rv2p_code_len, u32 rv2p_proc)
3988 DBENTER(BCE_VERBOSE_RESET);
3990 /* Set the page size used by RV2P. */
3991 if (rv2p_proc == RV2P_PROC2) {
3992 BCE_RV2P_PROC2_CHG_MAX_BD_PAGE(USABLE_RX_BD_PER_PAGE);
3995 for (i = 0; i < rv2p_code_len; i += 8) {
3996 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
3998 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
4001 if (rv2p_proc == RV2P_PROC1) {
4002 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
4003 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
4006 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
4007 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
4011 /* Reset the processor, un-stall is done later. */
4012 if (rv2p_proc == RV2P_PROC1) {
4013 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
4016 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
4019 DBEXIT(BCE_VERBOSE_RESET);
4023 /****************************************************************************/
4024 /* Load RISC processor firmware. */
4026 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
4027 /* associated with a particular processor. */
4031 /****************************************************************************/
4033 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
4038 DBENTER(BCE_VERBOSE_RESET);
4040 bce_halt_cpu(sc, cpu_reg);
4042 /* Load the Text area. */
4043 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
4047 for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
4048 REG_WR_IND(sc, offset, fw->text[j]);
4052 /* Load the Data area. */
4053 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
4057 for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
4058 REG_WR_IND(sc, offset, fw->data[j]);
4062 /* Load the SBSS area. */
4063 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
4067 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
4068 REG_WR_IND(sc, offset, fw->sbss[j]);
4072 /* Load the BSS area. */
4073 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
4077 for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
4078 REG_WR_IND(sc, offset, fw->bss[j]);
4082 /* Load the Read-Only area. */
4083 offset = cpu_reg->spad_base +
4084 (fw->rodata_addr - cpu_reg->mips_view_base);
4088 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
4089 REG_WR_IND(sc, offset, fw->rodata[j]);
4093 /* Clear the pre-fetch instruction and set the FW start address. */
4094 REG_WR_IND(sc, cpu_reg->inst, 0);
4095 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
4097 DBEXIT(BCE_VERBOSE_RESET);
4101 /****************************************************************************/
4102 /* Starts the RISC processor. */
4104 /* Assumes the CPU starting address has already been set. */
4108 /****************************************************************************/
4110 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
4114 DBENTER(BCE_VERBOSE_RESET);
4116 /* Start the CPU. */
4117 val = REG_RD_IND(sc, cpu_reg->mode);
4118 val &= ~cpu_reg->mode_value_halt;
4119 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
4120 REG_WR_IND(sc, cpu_reg->mode, val);
4122 DBEXIT(BCE_VERBOSE_RESET);
4126 /****************************************************************************/
4127 /* Halts the RISC processor. */
4131 /****************************************************************************/
4133 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
4137 DBENTER(BCE_VERBOSE_RESET);
4140 val = REG_RD_IND(sc, cpu_reg->mode);
4141 val |= cpu_reg->mode_value_halt;
4142 REG_WR_IND(sc, cpu_reg->mode, val);
4143 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
4145 DBEXIT(BCE_VERBOSE_RESET);
4149 /****************************************************************************/
4150 /* Initialize the RX CPU. */
4154 /****************************************************************************/
4156 bce_start_rxp_cpu(struct bce_softc *sc)
4158 struct cpu_reg cpu_reg;
4160 DBENTER(BCE_VERBOSE_RESET);
4162 cpu_reg.mode = BCE_RXP_CPU_MODE;
4163 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
4164 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
4165 cpu_reg.state = BCE_RXP_CPU_STATE;
4166 cpu_reg.state_value_clear = 0xffffff;
4167 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
4168 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
4169 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
4170 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
4171 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
4172 cpu_reg.spad_base = BCE_RXP_SCRATCH;
4173 cpu_reg.mips_view_base = 0x8000000;
4175 DBPRINT(sc, BCE_INFO_RESET, "Starting RX firmware.\n");
4176 bce_start_cpu(sc, &cpu_reg);
4178 DBEXIT(BCE_VERBOSE_RESET);
4182 /****************************************************************************/
4183 /* Initialize the RX CPU. */
4187 /****************************************************************************/
4189 bce_init_rxp_cpu(struct bce_softc *sc)
4191 struct cpu_reg cpu_reg;
4194 DBENTER(BCE_VERBOSE_RESET);
4196 cpu_reg.mode = BCE_RXP_CPU_MODE;
4197 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
4198 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
4199 cpu_reg.state = BCE_RXP_CPU_STATE;
4200 cpu_reg.state_value_clear = 0xffffff;
4201 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
4202 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
4203 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
4204 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
4205 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
4206 cpu_reg.spad_base = BCE_RXP_SCRATCH;
4207 cpu_reg.mips_view_base = 0x8000000;
4209 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4210 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4211 fw.ver_major = bce_RXP_b09FwReleaseMajor;
4212 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
4213 fw.ver_fix = bce_RXP_b09FwReleaseFix;
4214 fw.start_addr = bce_RXP_b09FwStartAddr;
4216 fw.text_addr = bce_RXP_b09FwTextAddr;
4217 fw.text_len = bce_RXP_b09FwTextLen;
4219 fw.text = bce_RXP_b09FwText;
4221 fw.data_addr = bce_RXP_b09FwDataAddr;
4222 fw.data_len = bce_RXP_b09FwDataLen;
4224 fw.data = bce_RXP_b09FwData;
4226 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
4227 fw.sbss_len = bce_RXP_b09FwSbssLen;
4229 fw.sbss = bce_RXP_b09FwSbss;
4231 fw.bss_addr = bce_RXP_b09FwBssAddr;
4232 fw.bss_len = bce_RXP_b09FwBssLen;
4234 fw.bss = bce_RXP_b09FwBss;
4236 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
4237 fw.rodata_len = bce_RXP_b09FwRodataLen;
4238 fw.rodata_index = 0;
4239 fw.rodata = bce_RXP_b09FwRodata;
4241 fw.ver_major = bce_RXP_b06FwReleaseMajor;
4242 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
4243 fw.ver_fix = bce_RXP_b06FwReleaseFix;
4244 fw.start_addr = bce_RXP_b06FwStartAddr;
4246 fw.text_addr = bce_RXP_b06FwTextAddr;
4247 fw.text_len = bce_RXP_b06FwTextLen;
4249 fw.text = bce_RXP_b06FwText;
4251 fw.data_addr = bce_RXP_b06FwDataAddr;
4252 fw.data_len = bce_RXP_b06FwDataLen;
4254 fw.data = bce_RXP_b06FwData;
4256 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
4257 fw.sbss_len = bce_RXP_b06FwSbssLen;
4259 fw.sbss = bce_RXP_b06FwSbss;
4261 fw.bss_addr = bce_RXP_b06FwBssAddr;
4262 fw.bss_len = bce_RXP_b06FwBssLen;
4264 fw.bss = bce_RXP_b06FwBss;
4266 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
4267 fw.rodata_len = bce_RXP_b06FwRodataLen;
4268 fw.rodata_index = 0;
4269 fw.rodata = bce_RXP_b06FwRodata;
4272 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
4273 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4275 /* Delay RXP start until initialization is complete. */
4277 DBEXIT(BCE_VERBOSE_RESET);
4281 /****************************************************************************/
4282 /* Initialize the TX CPU. */
4286 /****************************************************************************/
4288 bce_init_txp_cpu(struct bce_softc *sc)
4290 struct cpu_reg cpu_reg;
4293 DBENTER(BCE_VERBOSE_RESET);
4295 cpu_reg.mode = BCE_TXP_CPU_MODE;
4296 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
4297 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
4298 cpu_reg.state = BCE_TXP_CPU_STATE;
4299 cpu_reg.state_value_clear = 0xffffff;
4300 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
4301 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
4302 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
4303 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
4304 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
4305 cpu_reg.spad_base = BCE_TXP_SCRATCH;
4306 cpu_reg.mips_view_base = 0x8000000;
4308 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4309 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4310 fw.ver_major = bce_TXP_b09FwReleaseMajor;
4311 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
4312 fw.ver_fix = bce_TXP_b09FwReleaseFix;
4313 fw.start_addr = bce_TXP_b09FwStartAddr;
4315 fw.text_addr = bce_TXP_b09FwTextAddr;
4316 fw.text_len = bce_TXP_b09FwTextLen;
4318 fw.text = bce_TXP_b09FwText;
4320 fw.data_addr = bce_TXP_b09FwDataAddr;
4321 fw.data_len = bce_TXP_b09FwDataLen;
4323 fw.data = bce_TXP_b09FwData;
4325 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
4326 fw.sbss_len = bce_TXP_b09FwSbssLen;
4328 fw.sbss = bce_TXP_b09FwSbss;
4330 fw.bss_addr = bce_TXP_b09FwBssAddr;
4331 fw.bss_len = bce_TXP_b09FwBssLen;
4333 fw.bss = bce_TXP_b09FwBss;
4335 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
4336 fw.rodata_len = bce_TXP_b09FwRodataLen;
4337 fw.rodata_index = 0;
4338 fw.rodata = bce_TXP_b09FwRodata;
4340 fw.ver_major = bce_TXP_b06FwReleaseMajor;
4341 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
4342 fw.ver_fix = bce_TXP_b06FwReleaseFix;
4343 fw.start_addr = bce_TXP_b06FwStartAddr;
4345 fw.text_addr = bce_TXP_b06FwTextAddr;
4346 fw.text_len = bce_TXP_b06FwTextLen;
4348 fw.text = bce_TXP_b06FwText;
4350 fw.data_addr = bce_TXP_b06FwDataAddr;
4351 fw.data_len = bce_TXP_b06FwDataLen;
4353 fw.data = bce_TXP_b06FwData;
4355 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
4356 fw.sbss_len = bce_TXP_b06FwSbssLen;
4358 fw.sbss = bce_TXP_b06FwSbss;
4360 fw.bss_addr = bce_TXP_b06FwBssAddr;
4361 fw.bss_len = bce_TXP_b06FwBssLen;
4363 fw.bss = bce_TXP_b06FwBss;
4365 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
4366 fw.rodata_len = bce_TXP_b06FwRodataLen;
4367 fw.rodata_index = 0;
4368 fw.rodata = bce_TXP_b06FwRodata;
4371 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
4372 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4373 bce_start_cpu(sc, &cpu_reg);
4375 DBEXIT(BCE_VERBOSE_RESET);
4379 /****************************************************************************/
4380 /* Initialize the TPAT CPU. */
4384 /****************************************************************************/
4386 bce_init_tpat_cpu(struct bce_softc *sc)
4388 struct cpu_reg cpu_reg;
4391 DBENTER(BCE_VERBOSE_RESET);
4393 cpu_reg.mode = BCE_TPAT_CPU_MODE;
4394 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
4395 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
4396 cpu_reg.state = BCE_TPAT_CPU_STATE;
4397 cpu_reg.state_value_clear = 0xffffff;
4398 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
4399 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
4400 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
4401 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
4402 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
4403 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
4404 cpu_reg.mips_view_base = 0x8000000;
4406 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4407 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4408 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
4409 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
4410 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
4411 fw.start_addr = bce_TPAT_b09FwStartAddr;
4413 fw.text_addr = bce_TPAT_b09FwTextAddr;
4414 fw.text_len = bce_TPAT_b09FwTextLen;
4416 fw.text = bce_TPAT_b09FwText;
4418 fw.data_addr = bce_TPAT_b09FwDataAddr;
4419 fw.data_len = bce_TPAT_b09FwDataLen;
4421 fw.data = bce_TPAT_b09FwData;
4423 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
4424 fw.sbss_len = bce_TPAT_b09FwSbssLen;
4426 fw.sbss = bce_TPAT_b09FwSbss;
4428 fw.bss_addr = bce_TPAT_b09FwBssAddr;
4429 fw.bss_len = bce_TPAT_b09FwBssLen;
4431 fw.bss = bce_TPAT_b09FwBss;
4433 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
4434 fw.rodata_len = bce_TPAT_b09FwRodataLen;
4435 fw.rodata_index = 0;
4436 fw.rodata = bce_TPAT_b09FwRodata;
4438 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
4439 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
4440 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
4441 fw.start_addr = bce_TPAT_b06FwStartAddr;
4443 fw.text_addr = bce_TPAT_b06FwTextAddr;
4444 fw.text_len = bce_TPAT_b06FwTextLen;
4446 fw.text = bce_TPAT_b06FwText;
4448 fw.data_addr = bce_TPAT_b06FwDataAddr;
4449 fw.data_len = bce_TPAT_b06FwDataLen;
4451 fw.data = bce_TPAT_b06FwData;
4453 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
4454 fw.sbss_len = bce_TPAT_b06FwSbssLen;
4456 fw.sbss = bce_TPAT_b06FwSbss;
4458 fw.bss_addr = bce_TPAT_b06FwBssAddr;
4459 fw.bss_len = bce_TPAT_b06FwBssLen;
4461 fw.bss = bce_TPAT_b06FwBss;
4463 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
4464 fw.rodata_len = bce_TPAT_b06FwRodataLen;
4465 fw.rodata_index = 0;
4466 fw.rodata = bce_TPAT_b06FwRodata;
4469 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
4470 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4471 bce_start_cpu(sc, &cpu_reg);
4473 DBEXIT(BCE_VERBOSE_RESET);
4477 /****************************************************************************/
4478 /* Initialize the CP CPU. */
4482 /****************************************************************************/
4484 bce_init_cp_cpu(struct bce_softc *sc)
4486 struct cpu_reg cpu_reg;
4489 DBENTER(BCE_VERBOSE_RESET);
4491 cpu_reg.mode = BCE_CP_CPU_MODE;
4492 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
4493 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
4494 cpu_reg.state = BCE_CP_CPU_STATE;
4495 cpu_reg.state_value_clear = 0xffffff;
4496 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
4497 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
4498 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
4499 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
4500 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
4501 cpu_reg.spad_base = BCE_CP_SCRATCH;
4502 cpu_reg.mips_view_base = 0x8000000;
4504 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4505 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4506 fw.ver_major = bce_CP_b09FwReleaseMajor;
4507 fw.ver_minor = bce_CP_b09FwReleaseMinor;
4508 fw.ver_fix = bce_CP_b09FwReleaseFix;
4509 fw.start_addr = bce_CP_b09FwStartAddr;
4511 fw.text_addr = bce_CP_b09FwTextAddr;
4512 fw.text_len = bce_CP_b09FwTextLen;
4514 fw.text = bce_CP_b09FwText;
4516 fw.data_addr = bce_CP_b09FwDataAddr;
4517 fw.data_len = bce_CP_b09FwDataLen;
4519 fw.data = bce_CP_b09FwData;
4521 fw.sbss_addr = bce_CP_b09FwSbssAddr;
4522 fw.sbss_len = bce_CP_b09FwSbssLen;
4524 fw.sbss = bce_CP_b09FwSbss;
4526 fw.bss_addr = bce_CP_b09FwBssAddr;
4527 fw.bss_len = bce_CP_b09FwBssLen;
4529 fw.bss = bce_CP_b09FwBss;
4531 fw.rodata_addr = bce_CP_b09FwRodataAddr;
4532 fw.rodata_len = bce_CP_b09FwRodataLen;
4533 fw.rodata_index = 0;
4534 fw.rodata = bce_CP_b09FwRodata;
4536 fw.ver_major = bce_CP_b06FwReleaseMajor;
4537 fw.ver_minor = bce_CP_b06FwReleaseMinor;
4538 fw.ver_fix = bce_CP_b06FwReleaseFix;
4539 fw.start_addr = bce_CP_b06FwStartAddr;
4541 fw.text_addr = bce_CP_b06FwTextAddr;
4542 fw.text_len = bce_CP_b06FwTextLen;
4544 fw.text = bce_CP_b06FwText;
4546 fw.data_addr = bce_CP_b06FwDataAddr;
4547 fw.data_len = bce_CP_b06FwDataLen;
4549 fw.data = bce_CP_b06FwData;
4551 fw.sbss_addr = bce_CP_b06FwSbssAddr;
4552 fw.sbss_len = bce_CP_b06FwSbssLen;
4554 fw.sbss = bce_CP_b06FwSbss;
4556 fw.bss_addr = bce_CP_b06FwBssAddr;
4557 fw.bss_len = bce_CP_b06FwBssLen;
4559 fw.bss = bce_CP_b06FwBss;
4561 fw.rodata_addr = bce_CP_b06FwRodataAddr;
4562 fw.rodata_len = bce_CP_b06FwRodataLen;
4563 fw.rodata_index = 0;
4564 fw.rodata = bce_CP_b06FwRodata;
4567 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
4568 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4569 bce_start_cpu(sc, &cpu_reg);
4571 DBEXIT(BCE_VERBOSE_RESET);
4575 /****************************************************************************/
4576 /* Initialize the COM CPU. */
4580 /****************************************************************************/
4582 bce_init_com_cpu(struct bce_softc *sc)
4584 struct cpu_reg cpu_reg;
4587 DBENTER(BCE_VERBOSE_RESET);
4589 cpu_reg.mode = BCE_COM_CPU_MODE;
4590 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
4591 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
4592 cpu_reg.state = BCE_COM_CPU_STATE;
4593 cpu_reg.state_value_clear = 0xffffff;
4594 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
4595 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
4596 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
4597 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
4598 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
4599 cpu_reg.spad_base = BCE_COM_SCRATCH;
4600 cpu_reg.mips_view_base = 0x8000000;
4602 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4603 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4604 fw.ver_major = bce_COM_b09FwReleaseMajor;
4605 fw.ver_minor = bce_COM_b09FwReleaseMinor;
4606 fw.ver_fix = bce_COM_b09FwReleaseFix;
4607 fw.start_addr = bce_COM_b09FwStartAddr;
4609 fw.text_addr = bce_COM_b09FwTextAddr;
4610 fw.text_len = bce_COM_b09FwTextLen;
4612 fw.text = bce_COM_b09FwText;
4614 fw.data_addr = bce_COM_b09FwDataAddr;
4615 fw.data_len = bce_COM_b09FwDataLen;
4617 fw.data = bce_COM_b09FwData;
4619 fw.sbss_addr = bce_COM_b09FwSbssAddr;
4620 fw.sbss_len = bce_COM_b09FwSbssLen;
4622 fw.sbss = bce_COM_b09FwSbss;
4624 fw.bss_addr = bce_COM_b09FwBssAddr;
4625 fw.bss_len = bce_COM_b09FwBssLen;
4627 fw.bss = bce_COM_b09FwBss;
4629 fw.rodata_addr = bce_COM_b09FwRodataAddr;
4630 fw.rodata_len = bce_COM_b09FwRodataLen;
4631 fw.rodata_index = 0;
4632 fw.rodata = bce_COM_b09FwRodata;
4634 fw.ver_major = bce_COM_b06FwReleaseMajor;
4635 fw.ver_minor = bce_COM_b06FwReleaseMinor;
4636 fw.ver_fix = bce_COM_b06FwReleaseFix;
4637 fw.start_addr = bce_COM_b06FwStartAddr;
4639 fw.text_addr = bce_COM_b06FwTextAddr;
4640 fw.text_len = bce_COM_b06FwTextLen;
4642 fw.text = bce_COM_b06FwText;
4644 fw.data_addr = bce_COM_b06FwDataAddr;
4645 fw.data_len = bce_COM_b06FwDataLen;
4647 fw.data = bce_COM_b06FwData;
4649 fw.sbss_addr = bce_COM_b06FwSbssAddr;
4650 fw.sbss_len = bce_COM_b06FwSbssLen;
4652 fw.sbss = bce_COM_b06FwSbss;
4654 fw.bss_addr = bce_COM_b06FwBssAddr;
4655 fw.bss_len = bce_COM_b06FwBssLen;
4657 fw.bss = bce_COM_b06FwBss;
4659 fw.rodata_addr = bce_COM_b06FwRodataAddr;
4660 fw.rodata_len = bce_COM_b06FwRodataLen;
4661 fw.rodata_index = 0;
4662 fw.rodata = bce_COM_b06FwRodata;
4665 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
4666 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4667 bce_start_cpu(sc, &cpu_reg);
4669 DBEXIT(BCE_VERBOSE_RESET);
4673 /****************************************************************************/
4674 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
4676 /* Loads the firmware for each CPU and starts the CPU. */
4680 /****************************************************************************/
4682 bce_init_cpus(struct bce_softc *sc)
4684 DBENTER(BCE_VERBOSE_RESET);
4686 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4687 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4689 if ((BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax)) {
4690 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
4691 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
4692 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
4693 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
4695 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
4696 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
4697 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
4698 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
4702 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
4703 sizeof(bce_rv2p_proc1), RV2P_PROC1);
4704 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
4705 sizeof(bce_rv2p_proc2), RV2P_PROC2);
4708 bce_init_rxp_cpu(sc);
4709 bce_init_txp_cpu(sc);
4710 bce_init_tpat_cpu(sc);
4711 bce_init_com_cpu(sc);
4712 bce_init_cp_cpu(sc);
4714 DBEXIT(BCE_VERBOSE_RESET);
4718 /****************************************************************************/
4719 /* Initialize context memory. */
4721 /* Clears the memory associated with each Context ID (CID). */
4725 /****************************************************************************/
4727 bce_init_ctx(struct bce_softc *sc)
4729 u32 offset, val, vcid_addr;
4730 int i, j, rc, retry_cnt;
4733 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
4735 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4736 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4737 retry_cnt = CTX_INIT_RETRY_COUNT;
4739 DBPRINT(sc, BCE_INFO_CTX, "Initializing 5709 context.\n");
4742 * BCM5709 context memory may be cached
4743 * in host memory so prepare the host memory
4746 val = BCE_CTX_COMMAND_ENABLED |
4747 BCE_CTX_COMMAND_MEM_INIT | (1 << 12);
4748 val |= (BCM_PAGE_BITS - 8) << 16;
4749 REG_WR(sc, BCE_CTX_COMMAND, val);
4751 /* Wait for mem init command to complete. */
4752 for (i = 0; i < retry_cnt; i++) {
4753 val = REG_RD(sc, BCE_CTX_COMMAND);
4754 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
4758 if ((val & BCE_CTX_COMMAND_MEM_INIT) != 0) {
4759 BCE_PRINTF("%s(): Context memory initialization failed!\n",
4765 for (i = 0; i < sc->ctx_pages; i++) {
4766 /* Set the physical address of the context memory. */
4767 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
4768 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
4769 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
4770 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
4771 BCE_ADDR_HI(sc->ctx_paddr[i]));
4772 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL, i |
4773 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
4775 /* Verify the context memory write was successful. */
4776 for (j = 0; j < retry_cnt; j++) {
4777 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
4779 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
4783 if ((val & BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) != 0) {
4784 BCE_PRINTF("%s(): Failed to initialize "
4785 "context page %d!\n", __FUNCTION__, i);
4792 DBPRINT(sc, BCE_INFO, "Initializing 5706/5708 context.\n");
4795 * For the 5706/5708, context memory is local to
4796 * the controller, so initialize the controller
4800 vcid_addr = GET_CID_ADDR(96);
4803 vcid_addr -= PHY_CTX_SIZE;
4805 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
4806 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
4808 for(offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
4809 CTX_WR(sc, 0x00, offset, 0);
4812 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
4813 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
4818 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
4823 /****************************************************************************/
4824 /* Fetch the permanent MAC address of the controller. */
4828 /****************************************************************************/
4830 bce_get_mac_addr(struct bce_softc *sc)
4832 u32 mac_lo = 0, mac_hi = 0;
4834 DBENTER(BCE_VERBOSE_RESET);
4837 * The NetXtreme II bootcode populates various NIC
4838 * power-on and runtime configuration items in a
4839 * shared memory area. The factory configured MAC
4840 * address is available from both NVRAM and the
4841 * shared memory area so we'll read the value from
4842 * shared memory for speed.
4845 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
4846 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
4848 if ((mac_lo == 0) && (mac_hi == 0)) {
4849 BCE_PRINTF("%s(%d): Invalid Ethernet address!\n",
4850 __FILE__, __LINE__);
4852 sc->eaddr[0] = (u_char)(mac_hi >> 8);
4853 sc->eaddr[1] = (u_char)(mac_hi >> 0);
4854 sc->eaddr[2] = (u_char)(mac_lo >> 24);
4855 sc->eaddr[3] = (u_char)(mac_lo >> 16);
4856 sc->eaddr[4] = (u_char)(mac_lo >> 8);
4857 sc->eaddr[5] = (u_char)(mac_lo >> 0);
4860 DBPRINT(sc, BCE_INFO_MISC, "Permanent Ethernet "
4861 "address = %6D\n", sc->eaddr, ":");
4862 DBEXIT(BCE_VERBOSE_RESET);
4866 /****************************************************************************/
4867 /* Program the MAC address. */
4871 /****************************************************************************/
4873 bce_set_mac_addr(struct bce_softc *sc)
4876 u8 *mac_addr = sc->eaddr;
4878 /* ToDo: Add support for setting multiple MAC addresses. */
4880 DBENTER(BCE_VERBOSE_RESET);
4881 DBPRINT(sc, BCE_INFO_MISC, "Setting Ethernet address = "
4882 "%6D\n", sc->eaddr, ":");
4884 val = (mac_addr[0] << 8) | mac_addr[1];
4886 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
4888 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
4889 (mac_addr[4] << 8) | mac_addr[5];
4891 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
4893 DBEXIT(BCE_VERBOSE_RESET);
4897 /****************************************************************************/
4898 /* Stop the controller. */
4902 /****************************************************************************/
4904 bce_stop(struct bce_softc *sc)
4908 DBENTER(BCE_VERBOSE_RESET);
4910 BCE_LOCK_ASSERT(sc);
4914 callout_stop(&sc->bce_tick_callout);
4916 /* Disable the transmit/receive blocks. */
4917 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
4918 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
4921 bce_disable_intr(sc);
4923 /* Free RX buffers. */
4924 if (bce_hdr_split == TRUE) {
4925 bce_free_pg_chain(sc);
4927 bce_free_rx_chain(sc);
4929 /* Free TX buffers. */
4930 bce_free_tx_chain(sc);
4932 sc->watchdog_timer = 0;
4934 sc->bce_link_up = FALSE;
4936 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
4938 DBEXIT(BCE_VERBOSE_RESET);
4943 bce_reset(struct bce_softc *sc, u32 reset_code)
4948 DBENTER(BCE_VERBOSE_RESET);
4950 DBPRINT(sc, BCE_VERBOSE_RESET, "%s(): reset_code = 0x%08X\n",
4951 __FUNCTION__, reset_code);
4953 /* Wait for pending PCI transactions to complete. */
4954 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
4955 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
4956 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
4957 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
4958 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
4959 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
4963 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4964 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4965 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
4966 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
4967 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
4970 /* Assume bootcode is running. */
4971 sc->bce_fw_timed_out = FALSE;
4972 sc->bce_drv_cardiac_arrest = FALSE;
4974 /* Give the firmware a chance to prepare for the reset. */
4975 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
4977 goto bce_reset_exit;
4979 /* Set a firmware reminder that this is a soft reset. */
4980 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE, BCE_DRV_RESET_SIGNATURE_MAGIC);
4982 /* Dummy read to force the chip to complete all current transactions. */
4983 val = REG_RD(sc, BCE_MISC_ID);
4986 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
4987 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
4988 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
4989 REG_RD(sc, BCE_MISC_COMMAND);
4992 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
4993 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
4995 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
4997 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
4998 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
4999 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
5000 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
5002 /* Allow up to 30us for reset to complete. */
5003 for (i = 0; i < 10; i++) {
5004 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
5005 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
5006 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
5012 /* Check that reset completed successfully. */
5013 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
5014 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
5015 BCE_PRINTF("%s(%d): Reset failed!\n",
5016 __FILE__, __LINE__);
5018 goto bce_reset_exit;
5022 /* Make sure byte swapping is properly configured. */
5023 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
5024 if (val != 0x01020304) {
5025 BCE_PRINTF("%s(%d): Byte swap is incorrect!\n",
5026 __FILE__, __LINE__);
5028 goto bce_reset_exit;
5031 /* Just completed a reset, assume that firmware is running again. */
5032 sc->bce_fw_timed_out = FALSE;
5033 sc->bce_drv_cardiac_arrest = FALSE;
5035 /* Wait for the firmware to finish its initialization. */
5036 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
5038 BCE_PRINTF("%s(%d): Firmware did not complete "
5039 "initialization!\n", __FILE__, __LINE__);
5042 DBEXIT(BCE_VERBOSE_RESET);
5048 bce_chipinit(struct bce_softc *sc)
5053 DBENTER(BCE_VERBOSE_RESET);
5055 bce_disable_intr(sc);
5058 * Initialize DMA byte/word swapping, configure the number of DMA
5059 * channels and PCI clock compensation delay.
5061 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
5062 BCE_DMA_CONFIG_DATA_WORD_SWAP |
5063 #if BYTE_ORDER == BIG_ENDIAN
5064 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
5066 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
5067 DMA_READ_CHANS << 12 |
5068 DMA_WRITE_CHANS << 16;
5070 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
5072 if ((sc->bce_flags & BCE_PCIX_FLAG) && (sc->bus_speed_mhz == 133))
5073 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
5076 * This setting resolves a problem observed on certain Intel PCI
5077 * chipsets that cannot handle multiple outstanding DMA operations.
5078 * See errata E9_5706A1_65.
5080 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5081 (BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0) &&
5082 !(sc->bce_flags & BCE_PCIX_FLAG))
5083 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
5085 REG_WR(sc, BCE_DMA_CONFIG, val);
5087 /* Enable the RX_V2P and Context state machines before access. */
5088 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
5089 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
5090 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
5091 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
5093 /* Initialize context mapping and zero out the quick contexts. */
5094 if ((rc = bce_init_ctx(sc)) != 0)
5095 goto bce_chipinit_exit;
5097 /* Initialize the on-boards CPUs */
5100 /* Enable management frames (NC-SI) to flow to the MCP. */
5101 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5102 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) | BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
5103 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
5106 /* Prepare NVRAM for access. */
5107 if ((rc = bce_init_nvram(sc)) != 0)
5108 goto bce_chipinit_exit;
5110 /* Set the kernel bypass block size */
5111 val = REG_RD(sc, BCE_MQ_CONFIG);
5112 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
5113 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
5115 /* Enable bins used on the 5709. */
5116 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5117 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5118 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
5119 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
5120 val |= BCE_MQ_CONFIG_HALT_DIS;
5123 REG_WR(sc, BCE_MQ_CONFIG, val);
5125 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
5126 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
5127 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
5129 /* Set the page size and clear the RV2P processor stall bits. */
5130 val = (BCM_PAGE_BITS - 8) << 24;
5131 REG_WR(sc, BCE_RV2P_CONFIG, val);
5133 /* Configure page size. */
5134 val = REG_RD(sc, BCE_TBDR_CONFIG);
5135 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
5136 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
5137 REG_WR(sc, BCE_TBDR_CONFIG, val);
5139 /* Set the perfect match control register to default. */
5140 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
5143 DBEXIT(BCE_VERBOSE_RESET);
5149 /****************************************************************************/
5150 /* Initialize the controller in preparation to send/receive traffic. */
5153 /* 0 for success, positive value for failure. */
5154 /****************************************************************************/
5156 bce_blockinit(struct bce_softc *sc)
5161 DBENTER(BCE_VERBOSE_RESET);
5163 /* Load the hardware default MAC address. */
5164 bce_set_mac_addr(sc);
5166 /* Set the Ethernet backoff seed value */
5167 val = sc->eaddr[0] + (sc->eaddr[1] << 8) +
5168 (sc->eaddr[2] << 16) + (sc->eaddr[3] ) +
5169 (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
5170 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
5172 sc->last_status_idx = 0;
5173 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
5175 /* Set up link change interrupt generation. */
5176 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
5178 /* Program the physical address of the status block. */
5179 REG_WR(sc, BCE_HC_STATUS_ADDR_L,
5180 BCE_ADDR_LO(sc->status_block_paddr));
5181 REG_WR(sc, BCE_HC_STATUS_ADDR_H,
5182 BCE_ADDR_HI(sc->status_block_paddr));
5184 /* Program the physical address of the statistics block. */
5185 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
5186 BCE_ADDR_LO(sc->stats_block_paddr));
5187 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
5188 BCE_ADDR_HI(sc->stats_block_paddr));
5190 /* Program various host coalescing parameters. */
5191 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5192 (sc->bce_tx_quick_cons_trip_int << 16) | sc->bce_tx_quick_cons_trip);
5193 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5194 (sc->bce_rx_quick_cons_trip_int << 16) | sc->bce_rx_quick_cons_trip);
5195 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
5196 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
5197 REG_WR(sc, BCE_HC_TX_TICKS,
5198 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
5199 REG_WR(sc, BCE_HC_RX_TICKS,
5200 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
5201 REG_WR(sc, BCE_HC_COM_TICKS,
5202 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
5203 REG_WR(sc, BCE_HC_CMD_TICKS,
5204 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
5205 REG_WR(sc, BCE_HC_STATS_TICKS,
5206 (sc->bce_stats_ticks & 0xffff00));
5207 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
5209 /* Configure the Host Coalescing block. */
5210 val = BCE_HC_CONFIG_RX_TMR_MODE | BCE_HC_CONFIG_TX_TMR_MODE |
5211 BCE_HC_CONFIG_COLLECT_STATS;
5214 /* ToDo: Add MSI-X support. */
5215 if (sc->bce_flags & BCE_USING_MSIX_FLAG) {
5216 u32 base = ((BCE_TX_VEC - 1) * BCE_HC_SB_CONFIG_SIZE) +
5219 REG_WR(sc, BCE_HC_MSIX_BIT_VECTOR, BCE_HC_MSIX_BIT_VECTOR_VAL);
5221 REG_WR(sc, base, BCE_HC_SB_CONFIG_1_TX_TMR_MODE |
5222 BCE_HC_SB_CONFIG_1_ONE_SHOT);
5224 REG_WR(sc, base + BCE_HC_TX_QUICK_CONS_TRIP_OFF,
5225 (sc->tx_quick_cons_trip_int << 16) |
5226 sc->tx_quick_cons_trip);
5228 REG_WR(sc, base + BCE_HC_TX_TICKS_OFF,
5229 (sc->tx_ticks_int << 16) | sc->tx_ticks);
5231 val |= BCE_HC_CONFIG_SB_ADDR_INC_128B;
5235 * Tell the HC block to automatically set the
5236 * INT_MASK bit after an MSI/MSI-X interrupt
5237 * is generated so the driver doesn't have to.
5239 if (sc->bce_flags & BCE_ONE_SHOT_MSI_FLAG)
5240 val |= BCE_HC_CONFIG_ONE_SHOT;
5242 /* Set the MSI-X status blocks to 128 byte boundaries. */
5243 if (sc->bce_flags & BCE_USING_MSIX_FLAG)
5244 val |= BCE_HC_CONFIG_SB_ADDR_INC_128B;
5247 REG_WR(sc, BCE_HC_CONFIG, val);
5249 /* Clear the internal statistics counters. */
5250 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
5252 /* Verify that bootcode is running. */
5253 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
5255 DBRUNIF(DB_RANDOMTRUE(bootcode_running_failure_sim_control),
5256 BCE_PRINTF("%s(%d): Simulating bootcode failure.\n",
5257 __FILE__, __LINE__);
5260 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
5261 BCE_DEV_INFO_SIGNATURE_MAGIC) {
5262 BCE_PRINTF("%s(%d): Bootcode not running! Found: 0x%08X, "
5263 "Expected: 08%08X\n", __FILE__, __LINE__,
5264 (reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK),
5265 BCE_DEV_INFO_SIGNATURE_MAGIC);
5267 goto bce_blockinit_exit;
5271 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5272 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5273 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
5274 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
5275 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
5278 /* Allow bootcode to apply additional fixes before enabling MAC. */
5279 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 |
5280 BCE_DRV_MSG_CODE_RESET);
5282 /* Enable link state change interrupt generation. */
5283 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
5285 /* Enable the RXP. */
5286 bce_start_rxp_cpu(sc);
5288 /* Disable management frames (NC-SI) from flowing to the MCP. */
5289 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5290 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
5291 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
5292 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
5295 /* Enable all remaining blocks in the MAC. */
5296 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5297 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
5298 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
5299 BCE_MISC_ENABLE_DEFAULT_XI);
5301 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
5302 BCE_MISC_ENABLE_DEFAULT);
5304 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
5307 /* Save the current host coalescing block settings. */
5308 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
5311 DBEXIT(BCE_VERBOSE_RESET);
5317 /****************************************************************************/
5318 /* Encapsulate an mbuf into the rx_bd chain. */
5321 /* 0 for success, positive value for failure. */
5322 /****************************************************************************/
5324 bce_get_rx_buf(struct bce_softc *sc, struct mbuf *m, u16 *prod,
5325 u16 *chain_prod, u32 *prod_bseq)
5328 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
5329 struct mbuf *m_new = NULL;
5331 int nsegs, error, rc = 0;
5333 u16 debug_chain_prod = *chain_prod;
5336 DBENTER(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5338 /* Make sure the inputs are valid. */
5339 DBRUNIF((*chain_prod > MAX_RX_BD_ALLOC),
5340 BCE_PRINTF("%s(%d): RX producer out of range: "
5341 "0x%04X > 0x%04X\n", __FILE__, __LINE__,
5342 *chain_prod, (u16) MAX_RX_BD_ALLOC));
5344 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): prod = 0x%04X, "
5345 "chain_prod = 0x%04X, prod_bseq = 0x%08X\n", __FUNCTION__,
5346 *prod, *chain_prod, *prod_bseq);
5348 /* Update some debug statistic counters */
5349 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
5350 sc->rx_low_watermark = sc->free_rx_bd);
5351 DBRUNIF((sc->free_rx_bd == sc->max_rx_bd),
5352 sc->rx_empty_count++);
5354 /* Check whether this is a new mbuf allocation. */
5357 /* Simulate an mbuf allocation failure. */
5358 DBRUNIF(DB_RANDOMTRUE(mbuf_alloc_failed_sim_control),
5359 sc->mbuf_alloc_failed_count++;
5360 sc->mbuf_alloc_failed_sim_count++;
5362 goto bce_get_rx_buf_exit);
5364 /* This is a new mbuf allocation. */
5365 if (bce_hdr_split == TRUE)
5366 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
5368 m_new = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR,
5369 sc->rx_bd_mbuf_alloc_size);
5371 if (m_new == NULL) {
5372 sc->mbuf_alloc_failed_count++;
5374 goto bce_get_rx_buf_exit;
5377 DBRUN(sc->debug_rx_mbuf_alloc++);
5379 /* Reuse an existing mbuf. */
5383 /* Make sure we have a valid packet header. */
5384 M_ASSERTPKTHDR(m_new);
5386 /* Initialize the mbuf size and pad if necessary for alignment. */
5387 m_new->m_pkthdr.len = m_new->m_len = sc->rx_bd_mbuf_alloc_size;
5388 m_adj(m_new, sc->rx_bd_mbuf_align_pad);
5390 /* ToDo: Consider calling m_fragment() to test error handling. */
5392 /* Map the mbuf cluster into device memory. */
5393 map = sc->rx_mbuf_map[*chain_prod];
5394 error = bus_dmamap_load_mbuf_sg(sc->rx_mbuf_tag, map, m_new,
5395 segs, &nsegs, BUS_DMA_NOWAIT);
5397 /* Handle any mapping errors. */
5399 BCE_PRINTF("%s(%d): Error mapping mbuf into RX "
5400 "chain (%d)!\n", __FILE__, __LINE__, error);
5402 sc->dma_map_addr_rx_failed_count++;
5405 DBRUN(sc->debug_rx_mbuf_alloc--);
5408 goto bce_get_rx_buf_exit;
5411 /* All mbufs must map to a single segment. */
5412 KASSERT(nsegs == 1, ("%s(): Too many segments returned (%d)!",
5413 __FUNCTION__, nsegs));
5415 /* Setup the rx_bd for the segment. */
5416 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
5418 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[0].ds_addr));
5419 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[0].ds_addr));
5420 rxbd->rx_bd_len = htole32(segs[0].ds_len);
5421 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START | RX_BD_FLAGS_END);
5422 *prod_bseq += segs[0].ds_len;
5424 /* Save the mbuf and update our counter. */
5425 sc->rx_mbuf_ptr[*chain_prod] = m_new;
5426 sc->free_rx_bd -= nsegs;
5428 DBRUNMSG(BCE_INSANE_RECV,
5429 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, nsegs));
5431 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): prod = 0x%04X, "
5432 "chain_prod = 0x%04X, prod_bseq = 0x%08X\n",
5433 __FUNCTION__, *prod, *chain_prod, *prod_bseq);
5435 bce_get_rx_buf_exit:
5436 DBEXIT(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5442 /****************************************************************************/
5443 /* Encapsulate an mbuf cluster into the page chain. */
5446 /* 0 for success, positive value for failure. */
5447 /****************************************************************************/
5449 bce_get_pg_buf(struct bce_softc *sc, struct mbuf *m, u16 *prod,
5454 struct mbuf *m_new = NULL;
5458 u16 debug_prod_idx = *prod_idx;
5461 DBENTER(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5463 /* Make sure the inputs are valid. */
5464 DBRUNIF((*prod_idx > MAX_PG_BD_ALLOC),
5465 BCE_PRINTF("%s(%d): page producer out of range: "
5466 "0x%04X > 0x%04X\n", __FILE__, __LINE__,
5467 *prod_idx, (u16) MAX_PG_BD_ALLOC));
5469 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): prod = 0x%04X, "
5470 "chain_prod = 0x%04X\n", __FUNCTION__, *prod, *prod_idx);
5472 /* Update counters if we've hit a new low or run out of pages. */
5473 DBRUNIF((sc->free_pg_bd < sc->pg_low_watermark),
5474 sc->pg_low_watermark = sc->free_pg_bd);
5475 DBRUNIF((sc->free_pg_bd == sc->max_pg_bd), sc->pg_empty_count++);
5477 /* Check whether this is a new mbuf allocation. */
5480 /* Simulate an mbuf allocation failure. */
5481 DBRUNIF(DB_RANDOMTRUE(mbuf_alloc_failed_sim_control),
5482 sc->mbuf_alloc_failed_count++;
5483 sc->mbuf_alloc_failed_sim_count++;
5485 goto bce_get_pg_buf_exit);
5487 /* This is a new mbuf allocation. */
5488 m_new = m_getcl(M_DONTWAIT, MT_DATA, 0);
5489 if (m_new == NULL) {
5490 sc->mbuf_alloc_failed_count++;
5492 goto bce_get_pg_buf_exit;
5495 DBRUN(sc->debug_pg_mbuf_alloc++);
5497 /* Reuse an existing mbuf. */
5499 m_new->m_data = m_new->m_ext.ext_buf;
5502 m_new->m_len = sc->pg_bd_mbuf_alloc_size;
5504 /* ToDo: Consider calling m_fragment() to test error handling. */
5506 /* Map the mbuf cluster into device memory. */
5507 map = sc->pg_mbuf_map[*prod_idx];
5508 error = bus_dmamap_load(sc->pg_mbuf_tag, map, mtod(m_new, void *),
5509 sc->pg_bd_mbuf_alloc_size, bce_dma_map_addr,
5510 &busaddr, BUS_DMA_NOWAIT);
5512 /* Handle any mapping errors. */
5514 BCE_PRINTF("%s(%d): Error mapping mbuf into page chain!\n",
5515 __FILE__, __LINE__);
5518 DBRUN(sc->debug_pg_mbuf_alloc--);
5521 goto bce_get_pg_buf_exit;
5524 /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREREAD) here? */
5527 * The page chain uses the same rx_bd data structure
5528 * as the receive chain but doesn't require a byte sequence (bseq).
5530 pgbd = &sc->pg_bd_chain[PG_PAGE(*prod_idx)][PG_IDX(*prod_idx)];
5532 pgbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(busaddr));
5533 pgbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(busaddr));
5534 pgbd->rx_bd_len = htole32(sc->pg_bd_mbuf_alloc_size);
5535 pgbd->rx_bd_flags = htole32(RX_BD_FLAGS_START | RX_BD_FLAGS_END);
5537 /* Save the mbuf and update our counter. */
5538 sc->pg_mbuf_ptr[*prod_idx] = m_new;
5541 DBRUNMSG(BCE_INSANE_RECV,
5542 bce_dump_pg_mbuf_chain(sc, debug_prod_idx, 1));
5544 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): prod = 0x%04X, "
5545 "prod_idx = 0x%04X\n", __FUNCTION__, *prod, *prod_idx);
5547 bce_get_pg_buf_exit:
5548 DBEXIT(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5554 /****************************************************************************/
5555 /* Initialize the TX context memory. */
5559 /****************************************************************************/
5561 bce_init_tx_context(struct bce_softc *sc)
5565 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
5567 /* Initialize the context ID for an L2 TX chain. */
5568 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5569 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5570 /* Set the CID type to support an L2 connection. */
5571 val = BCE_L2CTX_TX_TYPE_TYPE_L2_XI |
5572 BCE_L2CTX_TX_TYPE_SIZE_L2_XI;
5573 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
5574 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2_XI | (8 << 16);
5575 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5576 BCE_L2CTX_TX_CMD_TYPE_XI, val);
5578 /* Point the hardware to the first page in the chain. */
5579 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
5580 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5581 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
5582 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
5583 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5584 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
5586 /* Set the CID type to support an L2 connection. */
5587 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
5588 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
5589 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
5590 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
5592 /* Point the hardware to the first page in the chain. */
5593 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
5594 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5595 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
5596 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
5597 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5598 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
5601 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
5605 /****************************************************************************/
5606 /* Allocate memory and initialize the TX data structures. */
5609 /* 0 for success, positive value for failure. */
5610 /****************************************************************************/
5612 bce_init_tx_chain(struct bce_softc *sc)
5617 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_LOAD);
5619 /* Set the initial TX producer/consumer indices. */
5622 sc->tx_prod_bseq = 0;
5624 sc->max_tx_bd = USABLE_TX_BD_ALLOC;
5625 DBRUN(sc->tx_hi_watermark = 0);
5626 DBRUN(sc->tx_full_count = 0);
5629 * The NetXtreme II supports a linked-list structre called
5630 * a Buffer Descriptor Chain (or BD chain). A BD chain
5631 * consists of a series of 1 or more chain pages, each of which
5632 * consists of a fixed number of BD entries.
5633 * The last BD entry on each page is a pointer to the next page
5634 * in the chain, and the last pointer in the BD chain
5635 * points back to the beginning of the chain.
5638 /* Set the TX next pointer chain entries. */
5639 for (i = 0; i < sc->tx_pages; i++) {
5642 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
5644 /* Check if we've reached the last page. */
5645 if (i == (sc->tx_pages - 1))
5650 txbd->tx_bd_haddr_hi =
5651 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
5652 txbd->tx_bd_haddr_lo =
5653 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
5656 bce_init_tx_context(sc);
5658 DBRUNMSG(BCE_INSANE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD_ALLOC));
5659 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_LOAD);
5665 /****************************************************************************/
5666 /* Free memory and clear the TX data structures. */
5670 /****************************************************************************/
5672 bce_free_tx_chain(struct bce_softc *sc)
5676 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_UNLOAD);
5678 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
5679 for (i = 0; i < MAX_TX_BD_AVAIL; i++) {
5680 if (sc->tx_mbuf_ptr[i] != NULL) {
5681 if (sc->tx_mbuf_map[i] != NULL)
5682 bus_dmamap_sync(sc->tx_mbuf_tag,
5684 BUS_DMASYNC_POSTWRITE);
5685 m_freem(sc->tx_mbuf_ptr[i]);
5686 sc->tx_mbuf_ptr[i] = NULL;
5687 DBRUN(sc->debug_tx_mbuf_alloc--);
5691 /* Clear each TX chain page. */
5692 for (i = 0; i < sc->tx_pages; i++)
5693 bzero((char *)sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
5697 /* Check if we lost any mbufs in the process. */
5698 DBRUNIF((sc->debug_tx_mbuf_alloc),
5699 BCE_PRINTF("%s(%d): Memory leak! Lost %d mbufs "
5700 "from tx chain!\n", __FILE__, __LINE__,
5701 sc->debug_tx_mbuf_alloc));
5703 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_UNLOAD);
5707 /****************************************************************************/
5708 /* Initialize the RX context memory. */
5712 /****************************************************************************/
5714 bce_init_rx_context(struct bce_softc *sc)
5718 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_CTX);
5720 /* Init the type, size, and BD cache levels for the RX context. */
5721 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
5722 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 |
5723 (0x02 << BCE_L2CTX_RX_BD_PRE_READ_SHIFT);
5726 * Set the level for generating pause frames
5727 * when the number of available rx_bd's gets
5728 * too low (the low watermark) and the level
5729 * when pause frames can be stopped (the high
5732 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5733 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5734 u32 lo_water, hi_water;
5736 if (sc->bce_flags & BCE_USING_TX_FLOW_CONTROL) {
5737 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
5742 if (lo_water >= USABLE_RX_BD_ALLOC) {
5746 hi_water = USABLE_RX_BD_ALLOC / 4;
5748 if (hi_water <= lo_water) {
5752 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
5753 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
5757 else if (hi_water == 0)
5760 val |= (lo_water << BCE_L2CTX_RX_LO_WATER_MARK_SHIFT) |
5761 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
5764 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
5766 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
5767 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5768 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
5769 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
5770 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
5773 /* Point the hardware to the first page in the chain. */
5774 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
5775 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
5776 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
5777 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
5779 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_CTX);
5783 /****************************************************************************/
5784 /* Allocate memory and initialize the RX data structures. */
5787 /* 0 for success, positive value for failure. */
5788 /****************************************************************************/
5790 bce_init_rx_chain(struct bce_softc *sc)
5795 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5798 /* Initialize the RX producer and consumer indices. */
5801 sc->rx_prod_bseq = 0;
5802 sc->free_rx_bd = USABLE_RX_BD_ALLOC;
5803 sc->max_rx_bd = USABLE_RX_BD_ALLOC;
5805 /* Initialize the RX next pointer chain entries. */
5806 for (i = 0; i < sc->rx_pages; i++) {
5809 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
5811 /* Check if we've reached the last page. */
5812 if (i == (sc->rx_pages - 1))
5817 /* Setup the chain page pointers. */
5818 rxbd->rx_bd_haddr_hi =
5819 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
5820 rxbd->rx_bd_haddr_lo =
5821 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
5824 /* Fill up the RX chain. */
5825 bce_fill_rx_chain(sc);
5827 DBRUN(sc->rx_low_watermark = USABLE_RX_BD_ALLOC);
5828 DBRUN(sc->rx_empty_count = 0);
5829 for (i = 0; i < sc->rx_pages; i++) {
5830 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
5831 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
5834 bce_init_rx_context(sc);
5836 DBRUNMSG(BCE_EXTREME_RECV,
5837 bce_dump_rx_bd_chain(sc, 0, TOTAL_RX_BD_ALLOC));
5838 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5841 /* ToDo: Are there possible failure modes here? */
5847 /****************************************************************************/
5848 /* Add mbufs to the RX chain until its full or an mbuf allocation error */
5853 /****************************************************************************/
5855 bce_fill_rx_chain(struct bce_softc *sc)
5860 DBENTER(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5863 /* Get the RX chain producer indices. */
5865 prod_bseq = sc->rx_prod_bseq;
5867 /* Keep filling the RX chain until it's full. */
5868 while (sc->free_rx_bd > 0) {
5869 prod_idx = RX_CHAIN_IDX(prod);
5870 if (bce_get_rx_buf(sc, NULL, &prod, &prod_idx, &prod_bseq)) {
5871 /* Bail out if we can't add an mbuf to the chain. */
5874 prod = NEXT_RX_BD(prod);
5877 /* Save the RX chain producer indices. */
5879 sc->rx_prod_bseq = prod_bseq;
5881 /* We should never end up pointing to a next page pointer. */
5882 DBRUNIF(((prod & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE),
5883 BCE_PRINTF("%s(): Invalid rx_prod value: 0x%04X\n",
5884 __FUNCTION__, sc->rx_prod));
5886 /* Write the mailbox and tell the chip about the waiting rx_bd's. */
5887 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) +
5888 BCE_L2MQ_RX_HOST_BDIDX, sc->rx_prod);
5889 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) +
5890 BCE_L2MQ_RX_HOST_BSEQ, sc->rx_prod_bseq);
5892 DBEXIT(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5897 /****************************************************************************/
5898 /* Free memory and clear the RX data structures. */
5902 /****************************************************************************/
5904 bce_free_rx_chain(struct bce_softc *sc)
5908 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5910 /* Free any mbufs still in the RX mbuf chain. */
5911 for (i = 0; i < MAX_RX_BD_AVAIL; i++) {
5912 if (sc->rx_mbuf_ptr[i] != NULL) {
5913 if (sc->rx_mbuf_map[i] != NULL)
5914 bus_dmamap_sync(sc->rx_mbuf_tag,
5916 BUS_DMASYNC_POSTREAD);
5917 m_freem(sc->rx_mbuf_ptr[i]);
5918 sc->rx_mbuf_ptr[i] = NULL;
5919 DBRUN(sc->debug_rx_mbuf_alloc--);
5923 /* Clear each RX chain page. */
5924 for (i = 0; i < sc->rx_pages; i++)
5925 if (sc->rx_bd_chain[i] != NULL) {
5926 bzero((char *)sc->rx_bd_chain[i],
5927 BCE_RX_CHAIN_PAGE_SZ);
5930 sc->free_rx_bd = sc->max_rx_bd;
5932 /* Check if we lost any mbufs in the process. */
5933 DBRUNIF((sc->debug_rx_mbuf_alloc),
5934 BCE_PRINTF("%s(): Memory leak! Lost %d mbufs from rx chain!\n",
5935 __FUNCTION__, sc->debug_rx_mbuf_alloc));
5937 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5941 /****************************************************************************/
5942 /* Allocate memory and initialize the page data structures. */
5943 /* Assumes that bce_init_rx_chain() has not already been called. */
5946 /* 0 for success, positive value for failure. */
5947 /****************************************************************************/
5949 bce_init_pg_chain(struct bce_softc *sc)
5955 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5958 /* Initialize the page producer and consumer indices. */
5961 sc->free_pg_bd = USABLE_PG_BD_ALLOC;
5962 sc->max_pg_bd = USABLE_PG_BD_ALLOC;
5963 DBRUN(sc->pg_low_watermark = sc->max_pg_bd);
5964 DBRUN(sc->pg_empty_count = 0);
5966 /* Initialize the page next pointer chain entries. */
5967 for (i = 0; i < sc->pg_pages; i++) {
5970 pgbd = &sc->pg_bd_chain[i][USABLE_PG_BD_PER_PAGE];
5972 /* Check if we've reached the last page. */
5973 if (i == (sc->pg_pages - 1))
5978 /* Setup the chain page pointers. */
5979 pgbd->rx_bd_haddr_hi =
5980 htole32(BCE_ADDR_HI(sc->pg_bd_chain_paddr[j]));
5981 pgbd->rx_bd_haddr_lo =
5982 htole32(BCE_ADDR_LO(sc->pg_bd_chain_paddr[j]));
5985 /* Setup the MQ BIN mapping for host_pg_bidx. */
5986 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
5987 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
5988 REG_WR(sc, BCE_MQ_MAP_L2_3, BCE_MQ_MAP_L2_3_DEFAULT);
5990 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_PG_BUF_SIZE, 0);
5992 /* Configure the rx_bd and page chain mbuf cluster size. */
5993 val = (sc->rx_bd_mbuf_data_len << 16) | sc->pg_bd_mbuf_alloc_size;
5994 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_PG_BUF_SIZE, val);
5996 /* Configure the context reserved for jumbo support. */
5997 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_RBDC_KEY,
5998 BCE_L2CTX_RX_RBDC_JUMBO_KEY);
6000 /* Point the hardware to the first page in the page chain. */
6001 val = BCE_ADDR_HI(sc->pg_bd_chain_paddr[0]);
6002 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_PG_BDHADDR_HI, val);
6003 val = BCE_ADDR_LO(sc->pg_bd_chain_paddr[0]);
6004 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_PG_BDHADDR_LO, val);
6006 /* Fill up the page chain. */
6007 bce_fill_pg_chain(sc);
6009 for (i = 0; i < sc->pg_pages; i++) {
6010 bus_dmamap_sync(sc->pg_bd_chain_tag, sc->pg_bd_chain_map[i],
6011 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
6014 DBRUNMSG(BCE_EXTREME_RECV,
6015 bce_dump_pg_chain(sc, 0, TOTAL_PG_BD_ALLOC));
6016 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
6022 /****************************************************************************/
6023 /* Add mbufs to the page chain until its full or an mbuf allocation error */
6028 /****************************************************************************/
6030 bce_fill_pg_chain(struct bce_softc *sc)
6034 DBENTER(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
6037 /* Get the page chain prodcuer index. */
6040 /* Keep filling the page chain until it's full. */
6041 while (sc->free_pg_bd > 0) {
6042 prod_idx = PG_CHAIN_IDX(prod);
6043 if (bce_get_pg_buf(sc, NULL, &prod, &prod_idx)) {
6044 /* Bail out if we can't add an mbuf to the chain. */
6047 prod = NEXT_PG_BD(prod);
6050 /* Save the page chain producer index. */
6053 DBRUNIF(((prod & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE),
6054 BCE_PRINTF("%s(): Invalid pg_prod value: 0x%04X\n",
6055 __FUNCTION__, sc->pg_prod));
6058 * Write the mailbox and tell the chip about
6059 * the new rx_bd's in the page chain.
6061 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) +
6062 BCE_L2MQ_RX_HOST_PG_BDIDX, sc->pg_prod);
6064 DBEXIT(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
6069 /****************************************************************************/
6070 /* Free memory and clear the RX data structures. */
6074 /****************************************************************************/
6076 bce_free_pg_chain(struct bce_softc *sc)
6080 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
6082 /* Free any mbufs still in the mbuf page chain. */
6083 for (i = 0; i < MAX_PG_BD_AVAIL; i++) {
6084 if (sc->pg_mbuf_ptr[i] != NULL) {
6085 if (sc->pg_mbuf_map[i] != NULL)
6086 bus_dmamap_sync(sc->pg_mbuf_tag,
6088 BUS_DMASYNC_POSTREAD);
6089 m_freem(sc->pg_mbuf_ptr[i]);
6090 sc->pg_mbuf_ptr[i] = NULL;
6091 DBRUN(sc->debug_pg_mbuf_alloc--);
6095 /* Clear each page chain pages. */
6096 for (i = 0; i < sc->pg_pages; i++)
6097 bzero((char *)sc->pg_bd_chain[i], BCE_PG_CHAIN_PAGE_SZ);
6099 sc->free_pg_bd = sc->max_pg_bd;
6101 /* Check if we lost any mbufs in the process. */
6102 DBRUNIF((sc->debug_pg_mbuf_alloc),
6103 BCE_PRINTF("%s(): Memory leak! Lost %d mbufs from page chain!\n",
6104 __FUNCTION__, sc->debug_pg_mbuf_alloc));
6106 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
6110 /****************************************************************************/
6111 /* Set media options. */
6114 /* 0 for success, positive value for failure. */
6115 /****************************************************************************/
6117 bce_ifmedia_upd(struct ifnet *ifp)
6119 struct bce_softc *sc = ifp->if_softc;
6122 DBENTER(BCE_VERBOSE);
6125 error = bce_ifmedia_upd_locked(ifp);
6128 DBEXIT(BCE_VERBOSE);
6133 /****************************************************************************/
6134 /* Set media options. */
6138 /****************************************************************************/
6140 bce_ifmedia_upd_locked(struct ifnet *ifp)
6142 struct bce_softc *sc = ifp->if_softc;
6143 struct mii_data *mii;
6144 struct mii_softc *miisc;
6147 DBENTER(BCE_VERBOSE_PHY);
6150 BCE_LOCK_ASSERT(sc);
6152 mii = device_get_softc(sc->bce_miibus);
6154 /* Make sure the MII bus has been enumerated. */
6156 sc->bce_link_up = FALSE;
6157 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
6159 error = mii_mediachg(mii);
6162 DBEXIT(BCE_VERBOSE_PHY);
6167 /****************************************************************************/
6168 /* Reports current media status. */
6172 /****************************************************************************/
6174 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
6176 struct bce_softc *sc = ifp->if_softc;
6177 struct mii_data *mii;
6179 DBENTER(BCE_VERBOSE_PHY);
6183 if ((ifp->if_flags & IFF_UP) == 0) {
6187 mii = device_get_softc(sc->bce_miibus);
6190 ifmr->ifm_active = mii->mii_media_active;
6191 ifmr->ifm_status = mii->mii_media_status;
6195 DBEXIT(BCE_VERBOSE_PHY);
6199 /****************************************************************************/
6200 /* Handles PHY generated interrupt events. */
6204 /****************************************************************************/
6206 bce_phy_intr(struct bce_softc *sc)
6208 u32 new_link_state, old_link_state;
6210 DBENTER(BCE_VERBOSE_PHY | BCE_VERBOSE_INTR);
6212 DBRUN(sc->phy_interrupts++);
6214 new_link_state = sc->status_block->status_attn_bits &
6215 STATUS_ATTN_BITS_LINK_STATE;
6216 old_link_state = sc->status_block->status_attn_bits_ack &
6217 STATUS_ATTN_BITS_LINK_STATE;
6219 /* Handle any changes if the link state has changed. */
6220 if (new_link_state != old_link_state) {
6222 /* Update the status_attn_bits_ack field. */
6223 if (new_link_state) {
6224 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
6225 STATUS_ATTN_BITS_LINK_STATE);
6226 DBPRINT(sc, BCE_INFO_PHY, "%s(): Link is now UP.\n",
6230 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
6231 STATUS_ATTN_BITS_LINK_STATE);
6232 DBPRINT(sc, BCE_INFO_PHY, "%s(): Link is now DOWN.\n",
6237 * Assume link is down and allow
6238 * tick routine to update the state
6239 * based on the actual media state.
6241 sc->bce_link_up = FALSE;
6242 callout_stop(&sc->bce_tick_callout);
6246 /* Acknowledge the link change interrupt. */
6247 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
6249 DBEXIT(BCE_VERBOSE_PHY | BCE_VERBOSE_INTR);
6253 /****************************************************************************/
6254 /* Reads the receive consumer value from the status block (skipping over */
6255 /* chain page pointer if necessary). */
6259 /****************************************************************************/
6261 bce_get_hw_rx_cons(struct bce_softc *sc)
6266 hw_cons = sc->status_block->status_rx_quick_consumer_index0;
6267 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
6273 /****************************************************************************/
6274 /* Handles received frame interrupt events. */
6278 /****************************************************************************/
6280 bce_rx_intr(struct bce_softc *sc)
6282 struct ifnet *ifp = sc->bce_ifp;
6283 struct l2_fhdr *l2fhdr;
6284 struct ether_vlan_header *vh;
6285 unsigned int pkt_len;
6286 u16 sw_rx_cons, sw_rx_cons_idx, hw_rx_cons;
6288 unsigned int rem_len;
6289 u16 sw_pg_cons, sw_pg_cons_idx;
6291 DBENTER(BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
6292 DBRUN(sc->interrupts_rx++);
6293 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): rx_prod = 0x%04X, "
6294 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
6295 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
6297 /* Prepare the RX chain pages to be accessed by the host CPU. */
6298 for (int i = 0; i < sc->rx_pages; i++)
6299 bus_dmamap_sync(sc->rx_bd_chain_tag,
6300 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
6302 /* Prepare the page chain pages to be accessed by the host CPU. */
6303 if (bce_hdr_split == TRUE) {
6304 for (int i = 0; i < sc->pg_pages; i++)
6305 bus_dmamap_sync(sc->pg_bd_chain_tag,
6306 sc->pg_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
6309 /* Get the hardware's view of the RX consumer index. */
6310 hw_rx_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
6312 /* Get working copies of the driver's view of the consumer indices. */
6313 sw_rx_cons = sc->rx_cons;
6314 sw_pg_cons = sc->pg_cons;
6316 /* Update some debug statistics counters */
6317 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
6318 sc->rx_low_watermark = sc->free_rx_bd);
6319 DBRUNIF((sc->free_rx_bd == sc->max_rx_bd),
6320 sc->rx_empty_count++);
6322 /* Scan through the receive chain as long as there is work to do */
6323 /* ToDo: Consider setting a limit on the number of packets processed. */
6325 while (sw_rx_cons != hw_rx_cons) {
6328 /* Convert the producer/consumer indices to an actual rx_bd index. */
6329 sw_rx_cons_idx = RX_CHAIN_IDX(sw_rx_cons);
6331 /* Unmap the mbuf from DMA space. */
6332 bus_dmamap_sync(sc->rx_mbuf_tag,
6333 sc->rx_mbuf_map[sw_rx_cons_idx],
6334 BUS_DMASYNC_POSTREAD);
6335 bus_dmamap_unload(sc->rx_mbuf_tag,
6336 sc->rx_mbuf_map[sw_rx_cons_idx]);
6338 /* Remove the mbuf from the RX chain. */
6339 m0 = sc->rx_mbuf_ptr[sw_rx_cons_idx];
6340 sc->rx_mbuf_ptr[sw_rx_cons_idx] = NULL;
6341 DBRUN(sc->debug_rx_mbuf_alloc--);
6345 DBPRINT(sc, BCE_EXTREME_RECV,
6346 "%s(): Oops! Empty mbuf pointer "
6347 "found in sc->rx_mbuf_ptr[0x%04X]!\n",
6348 __FUNCTION__, sw_rx_cons_idx);
6349 goto bce_rx_int_next_rx;
6353 * Frames received on the NetXteme II are prepended
6354 * with an l2_fhdr structure which provides status
6355 * information about the received frame (including
6356 * VLAN tags and checksum info). The frames are
6357 * also automatically adjusted to word align the IP
6358 * header (i.e. two null bytes are inserted before
6359 * the Ethernet header). As a result the data
6360 * DMA'd by the controller into the mbuf looks
6363 * +---------+-----+---------------------+-----+
6364 * | l2_fhdr | pad | packet data | FCS |
6365 * +---------+-----+---------------------+-----+
6367 * The l2_fhdr needs to be checked and skipped and
6368 * the FCS needs to be stripped before sending the
6369 * packet up the stack.
6371 l2fhdr = mtod(m0, struct l2_fhdr *);
6373 /* Get the packet data + FCS length and the status. */
6374 pkt_len = l2fhdr->l2_fhdr_pkt_len;
6375 status = l2fhdr->l2_fhdr_status;
6378 * Skip over the l2_fhdr and pad, resulting in the
6379 * following data in the mbuf:
6380 * +---------------------+-----+
6381 * | packet data | FCS |
6382 * +---------------------+-----+
6384 m_adj(m0, sizeof(struct l2_fhdr) + ETHER_ALIGN);
6387 * When split header mode is used, an ethernet frame
6388 * may be split across the receive chain and the
6389 * page chain. If that occurs an mbuf cluster must be
6390 * reassembled from the individual mbuf pieces.
6392 if (bce_hdr_split == TRUE) {
6394 * Check whether the received frame fits in a single
6395 * mbuf or not (i.e. packet data + FCS <=
6396 * sc->rx_bd_mbuf_data_len bytes).
6398 if (pkt_len > m0->m_len) {
6400 * The received frame is larger than a single mbuf.
6401 * If the frame was a TCP frame then only the TCP
6402 * header is placed in the mbuf, the remaining
6403 * payload (including FCS) is placed in the page
6404 * chain, the SPLIT flag is set, and the header
6405 * length is placed in the IP checksum field.
6406 * If the frame is not a TCP frame then the mbuf
6407 * is filled and the remaining bytes are placed
6408 * in the page chain.
6411 DBPRINT(sc, BCE_INFO_RECV, "%s(): Found a large "
6412 "packet.\n", __FUNCTION__);
6413 DBRUN(sc->split_header_frames_rcvd++);
6416 * When the page chain is enabled and the TCP
6417 * header has been split from the TCP payload,
6418 * the ip_xsum structure will reflect the length
6419 * of the TCP header, not the IP checksum. Set
6420 * the packet length of the mbuf accordingly.
6422 if (status & L2_FHDR_STATUS_SPLIT) {
6423 m0->m_len = l2fhdr->l2_fhdr_ip_xsum;
6424 DBRUN(sc->split_header_tcp_frames_rcvd++);
6427 rem_len = pkt_len - m0->m_len;
6429 /* Pull mbufs off the page chain for any remaining data. */
6430 while (rem_len > 0) {
6433 sw_pg_cons_idx = PG_CHAIN_IDX(sw_pg_cons);
6435 /* Remove the mbuf from the page chain. */
6436 m_pg = sc->pg_mbuf_ptr[sw_pg_cons_idx];
6437 sc->pg_mbuf_ptr[sw_pg_cons_idx] = NULL;
6438 DBRUN(sc->debug_pg_mbuf_alloc--);
6441 /* Unmap the page chain mbuf from DMA space. */
6442 bus_dmamap_sync(sc->pg_mbuf_tag,
6443 sc->pg_mbuf_map[sw_pg_cons_idx],
6444 BUS_DMASYNC_POSTREAD);
6445 bus_dmamap_unload(sc->pg_mbuf_tag,
6446 sc->pg_mbuf_map[sw_pg_cons_idx]);
6448 /* Adjust the mbuf length. */
6449 if (rem_len < m_pg->m_len) {
6450 /* The mbuf chain is complete. */
6451 m_pg->m_len = rem_len;
6454 /* More packet data is waiting. */
6455 rem_len -= m_pg->m_len;
6458 /* Concatenate the mbuf cluster to the mbuf. */
6461 sw_pg_cons = NEXT_PG_BD(sw_pg_cons);
6464 /* Set the total packet length. */
6465 m0->m_pkthdr.len = pkt_len;
6469 * The received packet is small and fits in a
6470 * single mbuf (i.e. the l2_fhdr + pad + packet +
6471 * FCS <= MHLEN). In other words, the packet is
6472 * 154 bytes or less in size.
6475 DBPRINT(sc, BCE_INFO_RECV, "%s(): Found a small "
6476 "packet.\n", __FUNCTION__);
6478 /* Set the total packet length. */
6479 m0->m_pkthdr.len = m0->m_len = pkt_len;
6482 /* Set the total packet length. */
6483 m0->m_pkthdr.len = m0->m_len = pkt_len;
6485 /* Remove the trailing Ethernet FCS. */
6486 m_adj(m0, -ETHER_CRC_LEN);
6488 /* Check that the resulting mbuf chain is valid. */
6489 DBRUN(m_sanity(m0, FALSE));
6490 DBRUNIF(((m0->m_len < ETHER_HDR_LEN) |
6491 (m0->m_pkthdr.len > BCE_MAX_JUMBO_ETHER_MTU_VLAN)),
6492 BCE_PRINTF("Invalid Ethernet frame size!\n");
6495 DBRUNIF(DB_RANDOMTRUE(l2fhdr_error_sim_control),
6496 sc->l2fhdr_error_sim_count++;
6497 status = status | L2_FHDR_ERRORS_PHY_DECODE);
6499 /* Check the received frame for errors. */
6500 if (status & (L2_FHDR_ERRORS_BAD_CRC |
6501 L2_FHDR_ERRORS_PHY_DECODE | L2_FHDR_ERRORS_ALIGNMENT |
6502 L2_FHDR_ERRORS_TOO_SHORT | L2_FHDR_ERRORS_GIANT_FRAME)) {
6504 /* Log the error and release the mbuf. */
6506 sc->l2fhdr_error_count++;
6510 goto bce_rx_int_next_rx;
6513 /* Send the packet to the appropriate interface. */
6514 m0->m_pkthdr.rcvif = ifp;
6516 /* Assume no hardware checksum. */
6517 m0->m_pkthdr.csum_flags = 0;
6519 /* Validate the checksum if offload enabled. */
6520 if (ifp->if_capenable & IFCAP_RXCSUM) {
6522 /* Check for an IP datagram. */
6523 if (!(status & L2_FHDR_STATUS_SPLIT) &&
6524 (status & L2_FHDR_STATUS_IP_DATAGRAM)) {
6525 m0->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
6526 DBRUN(sc->csum_offload_ip++);
6527 /* Check if the IP checksum is valid. */
6528 if ((l2fhdr->l2_fhdr_ip_xsum ^ 0xffff) == 0)
6529 m0->m_pkthdr.csum_flags |=
6533 /* Check for a valid TCP/UDP frame. */
6534 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
6535 L2_FHDR_STATUS_UDP_DATAGRAM)) {
6537 /* Check for a good TCP/UDP checksum. */
6538 if ((status & (L2_FHDR_ERRORS_TCP_XSUM |
6539 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
6540 DBRUN(sc->csum_offload_tcp_udp++);
6541 m0->m_pkthdr.csum_data =
6542 l2fhdr->l2_fhdr_tcp_udp_xsum;
6543 m0->m_pkthdr.csum_flags |=
6550 /* Attach the VLAN tag. */
6551 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
6552 DBRUN(sc->vlan_tagged_frames_rcvd++);
6553 if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) {
6554 DBRUN(sc->vlan_tagged_frames_stripped++);
6555 #if __FreeBSD_version < 700000
6556 VLAN_INPUT_TAG(ifp, m0,
6557 l2fhdr->l2_fhdr_vlan_tag, continue);
6559 m0->m_pkthdr.ether_vtag =
6560 l2fhdr->l2_fhdr_vlan_tag;
6561 m0->m_flags |= M_VLANTAG;
6565 * bce(4) controllers can't disable VLAN
6566 * tag stripping if management firmware
6567 * (ASF/IPMI/UMP) is running. So we always
6568 * strip VLAN tag and manually reconstruct
6569 * the VLAN frame by appending stripped
6570 * VLAN tag in driver if VLAN tag stripping
6573 * TODO: LLC SNAP handling.
6575 bcopy(mtod(m0, uint8_t *),
6576 mtod(m0, uint8_t *) - ETHER_VLAN_ENCAP_LEN,
6577 ETHER_ADDR_LEN * 2);
6578 m0->m_data -= ETHER_VLAN_ENCAP_LEN;
6579 vh = mtod(m0, struct ether_vlan_header *);
6580 vh->evl_encap_proto = htons(ETHERTYPE_VLAN);
6581 vh->evl_tag = htons(l2fhdr->l2_fhdr_vlan_tag);
6582 m0->m_pkthdr.len += ETHER_VLAN_ENCAP_LEN;
6583 m0->m_len += ETHER_VLAN_ENCAP_LEN;
6587 /* Increment received packet statistics. */
6591 sw_rx_cons = NEXT_RX_BD(sw_rx_cons);
6593 /* If we have a packet, pass it up the stack */
6595 /* Make sure we don't lose our place when we release the lock. */
6596 sc->rx_cons = sw_rx_cons;
6597 sc->pg_cons = sw_pg_cons;
6600 (*ifp->if_input)(ifp, m0);
6603 /* Recover our place. */
6604 sw_rx_cons = sc->rx_cons;
6605 sw_pg_cons = sc->pg_cons;
6608 /* Refresh hw_cons to see if there's new work */
6609 if (sw_rx_cons == hw_rx_cons)
6610 hw_rx_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
6613 /* No new packets. Refill the page chain. */
6614 if (bce_hdr_split == TRUE) {
6615 sc->pg_cons = sw_pg_cons;
6616 bce_fill_pg_chain(sc);
6619 /* No new packets. Refill the RX chain. */
6620 sc->rx_cons = sw_rx_cons;
6621 bce_fill_rx_chain(sc);
6623 /* Prepare the page chain pages to be accessed by the NIC. */
6624 for (int i = 0; i < sc->rx_pages; i++)
6625 bus_dmamap_sync(sc->rx_bd_chain_tag,
6626 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
6628 if (bce_hdr_split == TRUE) {
6629 for (int i = 0; i < sc->pg_pages; i++)
6630 bus_dmamap_sync(sc->pg_bd_chain_tag,
6631 sc->pg_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
6634 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): rx_prod = 0x%04X, "
6635 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
6636 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
6637 DBEXIT(BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
6641 /****************************************************************************/
6642 /* Reads the transmit consumer value from the status block (skipping over */
6643 /* chain page pointer if necessary). */
6647 /****************************************************************************/
6649 bce_get_hw_tx_cons(struct bce_softc *sc)
6654 hw_cons = sc->status_block->status_tx_quick_consumer_index0;
6655 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
6662 /****************************************************************************/
6663 /* Handles transmit completion interrupt events. */
6667 /****************************************************************************/
6669 bce_tx_intr(struct bce_softc *sc)
6671 struct ifnet *ifp = sc->bce_ifp;
6672 u16 hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
6674 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_INTR);
6675 DBRUN(sc->interrupts_tx++);
6676 DBPRINT(sc, BCE_EXTREME_SEND, "%s(enter): tx_prod = 0x%04X, "
6677 "tx_cons = 0x%04X, tx_prod_bseq = 0x%08X\n",
6678 __FUNCTION__, sc->tx_prod, sc->tx_cons, sc->tx_prod_bseq);
6680 BCE_LOCK_ASSERT(sc);
6682 /* Get the hardware's view of the TX consumer index. */
6683 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
6684 sw_tx_cons = sc->tx_cons;
6686 /* Prevent speculative reads of the status block. */
6687 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
6688 BUS_SPACE_BARRIER_READ);
6690 /* Cycle through any completed TX chain page entries. */
6691 while (sw_tx_cons != hw_tx_cons) {
6693 struct tx_bd *txbd = NULL;
6695 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
6697 DBPRINT(sc, BCE_INFO_SEND,
6698 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
6699 "sw_tx_chain_cons = 0x%04X\n",
6700 __FUNCTION__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
6702 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD_ALLOC),
6703 BCE_PRINTF("%s(%d): TX chain consumer out of range! "
6704 " 0x%04X > 0x%04X\n", __FILE__, __LINE__, sw_tx_chain_cons,
6705 (int) MAX_TX_BD_ALLOC);
6706 bce_breakpoint(sc));
6708 DBRUN(txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
6709 [TX_IDX(sw_tx_chain_cons)]);
6711 DBRUNIF((txbd == NULL),
6712 BCE_PRINTF("%s(%d): Unexpected NULL tx_bd[0x%04X]!\n",
6713 __FILE__, __LINE__, sw_tx_chain_cons);
6714 bce_breakpoint(sc));
6716 DBRUNMSG(BCE_INFO_SEND, BCE_PRINTF("%s(): ", __FUNCTION__);
6717 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
6720 * Free the associated mbuf. Remember
6721 * that only the last tx_bd of a packet
6722 * has an mbuf pointer and DMA map.
6724 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
6726 /* Validate that this is the last tx_bd. */
6727 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
6728 BCE_PRINTF("%s(%d): tx_bd END flag not set but "
6729 "txmbuf == NULL!\n", __FILE__, __LINE__);
6730 bce_breakpoint(sc));
6732 DBRUNMSG(BCE_INFO_SEND,
6733 BCE_PRINTF("%s(): Unloading map/freeing mbuf "
6734 "from tx_bd[0x%04X]\n", __FUNCTION__,
6737 /* Unmap the mbuf. */
6738 bus_dmamap_unload(sc->tx_mbuf_tag,
6739 sc->tx_mbuf_map[sw_tx_chain_cons]);
6741 /* Free the mbuf. */
6742 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
6743 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
6744 DBRUN(sc->debug_tx_mbuf_alloc--);
6750 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
6752 /* Refresh hw_cons to see if there's new work. */
6753 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
6755 /* Prevent speculative reads of the status block. */
6756 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
6757 BUS_SPACE_BARRIER_READ);
6760 /* Clear the TX timeout timer. */
6761 sc->watchdog_timer = 0;
6763 /* Clear the tx hardware queue full flag. */
6764 if (sc->used_tx_bd < sc->max_tx_bd) {
6765 DBRUNIF((ifp->if_drv_flags & IFF_DRV_OACTIVE),
6766 DBPRINT(sc, BCE_INFO_SEND,
6767 "%s(): Open TX chain! %d/%d (used/total)\n",
6768 __FUNCTION__, sc->used_tx_bd, sc->max_tx_bd));
6769 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
6772 sc->tx_cons = sw_tx_cons;
6774 DBPRINT(sc, BCE_EXTREME_SEND, "%s(exit): tx_prod = 0x%04X, "
6775 "tx_cons = 0x%04X, tx_prod_bseq = 0x%08X\n",
6776 __FUNCTION__, sc->tx_prod, sc->tx_cons, sc->tx_prod_bseq);
6777 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_INTR);
6781 /****************************************************************************/
6782 /* Disables interrupt generation. */
6786 /****************************************************************************/
6788 bce_disable_intr(struct bce_softc *sc)
6790 DBENTER(BCE_VERBOSE_INTR);
6792 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
6793 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
6795 DBEXIT(BCE_VERBOSE_INTR);
6799 /****************************************************************************/
6800 /* Enables interrupt generation. */
6804 /****************************************************************************/
6806 bce_enable_intr(struct bce_softc *sc, int coal_now)
6808 DBENTER(BCE_VERBOSE_INTR);
6810 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
6811 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
6812 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
6814 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
6815 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
6817 /* Force an immediate interrupt (whether there is new data or not). */
6819 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
6821 DBEXIT(BCE_VERBOSE_INTR);
6825 /****************************************************************************/
6826 /* Handles controller initialization. */
6830 /****************************************************************************/
6832 bce_init_locked(struct bce_softc *sc)
6837 DBENTER(BCE_VERBOSE_RESET);
6839 BCE_LOCK_ASSERT(sc);
6843 /* Check if the driver is still running and bail out if it is. */
6844 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
6845 goto bce_init_locked_exit;
6849 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
6850 BCE_PRINTF("%s(%d): Controller reset failed!\n",
6851 __FILE__, __LINE__);
6852 goto bce_init_locked_exit;
6855 if (bce_chipinit(sc)) {
6856 BCE_PRINTF("%s(%d): Controller initialization failed!\n",
6857 __FILE__, __LINE__);
6858 goto bce_init_locked_exit;
6861 if (bce_blockinit(sc)) {
6862 BCE_PRINTF("%s(%d): Block initialization failed!\n",
6863 __FILE__, __LINE__);
6864 goto bce_init_locked_exit;
6867 /* Load our MAC address. */
6868 bcopy(IF_LLADDR(sc->bce_ifp), sc->eaddr, ETHER_ADDR_LEN);
6869 bce_set_mac_addr(sc);
6872 * Calculate and program the hardware Ethernet MTU
6873 * size. Be generous on the receive if we have room
6874 * and allowed by the user.
6876 if (bce_strict_rx_mtu == TRUE)
6877 ether_mtu = ifp->if_mtu;
6879 if (bce_hdr_split == TRUE) {
6880 if (ifp->if_mtu <= (sc->rx_bd_mbuf_data_len +
6881 sc->pg_bd_mbuf_alloc_size))
6882 ether_mtu = sc->rx_bd_mbuf_data_len +
6883 sc->pg_bd_mbuf_alloc_size;
6885 ether_mtu = ifp->if_mtu;
6887 if (ifp->if_mtu <= sc->rx_bd_mbuf_data_len)
6888 ether_mtu = sc->rx_bd_mbuf_data_len;
6890 ether_mtu = ifp->if_mtu;
6894 ether_mtu += ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + ETHER_CRC_LEN;
6896 DBPRINT(sc, BCE_INFO_MISC, "%s(): setting h/w mtu = %d\n",
6897 __FUNCTION__, ether_mtu);
6899 /* Program the mtu, enabling jumbo frame support if necessary. */
6900 if (ether_mtu > (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN))
6901 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
6902 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
6903 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
6905 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
6907 /* Program appropriate promiscuous/multicast filtering. */
6908 bce_set_rx_mode(sc);
6910 if (bce_hdr_split == TRUE) {
6911 DBPRINT(sc, BCE_INFO_LOAD, "%s(): pg_bd_mbuf_alloc_size = %d\n",
6912 __FUNCTION__, sc->pg_bd_mbuf_alloc_size);
6914 /* Init page buffer descriptor chain. */
6915 bce_init_pg_chain(sc);
6918 /* Init RX buffer descriptor chain. */
6919 bce_init_rx_chain(sc);
6921 /* Init TX buffer descriptor chain. */
6922 bce_init_tx_chain(sc);
6924 /* Enable host interrupts. */
6925 bce_enable_intr(sc, 1);
6927 bce_ifmedia_upd_locked(ifp);
6929 /* Let the OS know the driver is up and running. */
6930 ifp->if_drv_flags |= IFF_DRV_RUNNING;
6931 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
6933 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
6935 bce_init_locked_exit:
6936 DBEXIT(BCE_VERBOSE_RESET);
6940 /****************************************************************************/
6941 /* Initialize the controller just enough so that any management firmware */
6942 /* running on the device will continue to operate correctly. */
6946 /****************************************************************************/
6948 bce_mgmt_init_locked(struct bce_softc *sc)
6952 DBENTER(BCE_VERBOSE_RESET);
6954 BCE_LOCK_ASSERT(sc);
6956 /* Bail out if management firmware is not running. */
6957 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)) {
6958 DBPRINT(sc, BCE_VERBOSE_SPECIAL,
6959 "No management firmware running...\n");
6960 goto bce_mgmt_init_locked_exit;
6965 /* Enable all critical blocks in the MAC. */
6966 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
6967 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
6970 bce_ifmedia_upd_locked(ifp);
6972 bce_mgmt_init_locked_exit:
6973 DBEXIT(BCE_VERBOSE_RESET);
6977 /****************************************************************************/
6978 /* Handles controller initialization when called from an unlocked routine. */
6982 /****************************************************************************/
6986 struct bce_softc *sc = xsc;
6988 DBENTER(BCE_VERBOSE_RESET);
6991 bce_init_locked(sc);
6994 DBEXIT(BCE_VERBOSE_RESET);
6998 /****************************************************************************/
6999 /* Modifies an mbuf for TSO on the hardware. */
7002 /* Pointer to a modified mbuf. */
7003 /****************************************************************************/
7004 static struct mbuf *
7005 bce_tso_setup(struct bce_softc *sc, struct mbuf **m_head, u16 *flags)
7008 struct ether_header *eh;
7012 int hdr_len, ip_hlen = 0, tcp_hlen = 0, ip_len = 0;
7014 DBRUN(sc->tso_frames_requested++);
7016 /* Controller may modify mbuf chains. */
7017 if (M_WRITABLE(*m_head) == 0) {
7018 m = m_dup(*m_head, M_DONTWAIT);
7021 sc->mbuf_alloc_failed_count++;
7029 * For TSO the controller needs two pieces of info,
7030 * the MSS and the IP+TCP options length.
7032 m = m_pullup(*m_head, sizeof(struct ether_header) + sizeof(struct ip));
7037 eh = mtod(m, struct ether_header *);
7038 etype = ntohs(eh->ether_type);
7040 /* Check for supported TSO Ethernet types (only IPv4 for now) */
7043 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
7044 /* TSO only supported for TCP protocol. */
7045 if (ip->ip_p != IPPROTO_TCP) {
7046 BCE_PRINTF("%s(%d): TSO enabled for non-TCP frame!.\n",
7047 __FILE__, __LINE__);
7053 /* Get IP header length in bytes (min 20) */
7054 ip_hlen = ip->ip_hl << 2;
7055 m = m_pullup(*m_head, sizeof(struct ether_header) + ip_hlen +
7056 sizeof(struct tcphdr));
7062 /* Get the TCP header length in bytes (min 20) */
7063 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
7064 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
7065 tcp_hlen = (th->th_off << 2);
7067 /* Make sure all IP/TCP options live in the same buffer. */
7068 m = m_pullup(*m_head, sizeof(struct ether_header)+ ip_hlen +
7075 /* Clear IP header length and checksum, will be calc'd by h/w. */
7076 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
7077 ip_len = ip->ip_len;
7081 case ETHERTYPE_IPV6:
7082 BCE_PRINTF("%s(%d): TSO over IPv6 not supported!.\n",
7083 __FILE__, __LINE__);
7089 BCE_PRINTF("%s(%d): TSO enabled for unsupported protocol!.\n",
7090 __FILE__, __LINE__);
7096 hdr_len = sizeof(struct ether_header) + ip_hlen + tcp_hlen;
7098 DBPRINT(sc, BCE_EXTREME_SEND, "%s(): hdr_len = %d, e_hlen = %d, "
7099 "ip_hlen = %d, tcp_hlen = %d, ip_len = %d\n",
7100 __FUNCTION__, hdr_len, (int) sizeof(struct ether_header), ip_hlen,
7103 /* Set the LSO flag in the TX BD */
7104 *flags |= TX_BD_FLAGS_SW_LSO;
7106 /* Set the length of IP + TCP options (in 32 bit words) */
7107 *flags |= (((ip_hlen + tcp_hlen - sizeof(struct ip) -
7108 sizeof(struct tcphdr)) >> 2) << 8);
7110 DBRUN(sc->tso_frames_completed++);
7115 /****************************************************************************/
7116 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
7117 /* memory visible to the controller. */
7120 /* 0 for success, positive value for failure. */
7122 /* m_head: May be set to NULL if MBUF is excessively fragmented. */
7123 /****************************************************************************/
7125 bce_tx_encap(struct bce_softc *sc, struct mbuf **m_head)
7127 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
7129 struct tx_bd *txbd = NULL;
7131 u16 prod, chain_prod, mss = 0, vlan_tag = 0, flags = 0;
7138 int i, error, nsegs, rc = 0;
7140 DBENTER(BCE_VERBOSE_SEND);
7142 /* Make sure we have room in the TX chain. */
7143 if (sc->used_tx_bd >= sc->max_tx_bd)
7144 goto bce_tx_encap_exit;
7146 /* Transfer any checksum offload flags to the bd. */
7148 if (m0->m_pkthdr.csum_flags) {
7149 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
7150 m0 = bce_tso_setup(sc, m_head, &flags);
7152 DBRUN(sc->tso_frames_failed++);
7153 goto bce_tx_encap_exit;
7155 mss = htole16(m0->m_pkthdr.tso_segsz);
7157 if (m0->m_pkthdr.csum_flags & CSUM_IP)
7158 flags |= TX_BD_FLAGS_IP_CKSUM;
7159 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
7160 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
7164 /* Transfer any VLAN tags to the bd. */
7165 if (m0->m_flags & M_VLANTAG) {
7166 flags |= TX_BD_FLAGS_VLAN_TAG;
7167 vlan_tag = m0->m_pkthdr.ether_vtag;
7170 /* Map the mbuf into DMAable memory. */
7172 chain_prod = TX_CHAIN_IDX(prod);
7173 map = sc->tx_mbuf_map[chain_prod];
7175 /* Map the mbuf into our DMA address space. */
7176 error = bus_dmamap_load_mbuf_sg(sc->tx_mbuf_tag, map, m0,
7177 segs, &nsegs, BUS_DMA_NOWAIT);
7179 /* Check if the DMA mapping was successful */
7180 if (error == EFBIG) {
7181 sc->mbuf_frag_count++;
7183 /* Try to defrag the mbuf. */
7184 m0 = m_collapse(*m_head, M_DONTWAIT, BCE_MAX_SEGMENTS);
7186 /* Defrag was unsuccessful */
7189 sc->mbuf_alloc_failed_count++;
7191 goto bce_tx_encap_exit;
7194 /* Defrag was successful, try mapping again */
7196 error = bus_dmamap_load_mbuf_sg(sc->tx_mbuf_tag,
7197 map, m0, segs, &nsegs, BUS_DMA_NOWAIT);
7199 /* Still getting an error after a defrag. */
7200 if (error == ENOMEM) {
7201 /* Insufficient DMA buffers available. */
7202 sc->dma_map_addr_tx_failed_count++;
7204 goto bce_tx_encap_exit;
7205 } else if (error != 0) {
7206 /* Release it and return an error. */
7207 BCE_PRINTF("%s(%d): Unknown error mapping mbuf into "
7208 "TX chain!\n", __FILE__, __LINE__);
7211 sc->dma_map_addr_tx_failed_count++;
7213 goto bce_tx_encap_exit;
7215 } else if (error == ENOMEM) {
7216 /* Insufficient DMA buffers available. */
7217 sc->dma_map_addr_tx_failed_count++;
7219 goto bce_tx_encap_exit;
7220 } else if (error != 0) {
7223 sc->dma_map_addr_tx_failed_count++;
7225 goto bce_tx_encap_exit;
7228 /* Make sure there's room in the chain */
7229 if (nsegs > (sc->max_tx_bd - sc->used_tx_bd)) {
7230 bus_dmamap_unload(sc->tx_mbuf_tag, map);
7232 goto bce_tx_encap_exit;
7235 /* prod points to an empty tx_bd at this point. */
7236 prod_bseq = sc->tx_prod_bseq;
7239 debug_prod = chain_prod;
7242 DBPRINT(sc, BCE_INFO_SEND,
7243 "%s(start): prod = 0x%04X, chain_prod = 0x%04X, "
7244 "prod_bseq = 0x%08X\n",
7245 __FUNCTION__, prod, chain_prod, prod_bseq);
7248 * Cycle through each mbuf segment that makes up
7249 * the outgoing frame, gathering the mapping info
7250 * for that segment and creating a tx_bd for
7253 for (i = 0; i < nsegs ; i++) {
7255 chain_prod = TX_CHAIN_IDX(prod);
7256 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)]
7257 [TX_IDX(chain_prod)];
7259 txbd->tx_bd_haddr_lo =
7260 htole32(BCE_ADDR_LO(segs[i].ds_addr));
7261 txbd->tx_bd_haddr_hi =
7262 htole32(BCE_ADDR_HI(segs[i].ds_addr));
7263 txbd->tx_bd_mss_nbytes = htole32(mss << 16) |
7264 htole16(segs[i].ds_len);
7265 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
7266 txbd->tx_bd_flags = htole16(flags);
7267 prod_bseq += segs[i].ds_len;
7269 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
7270 prod = NEXT_TX_BD(prod);
7273 /* Set the END flag on the last TX buffer descriptor. */
7274 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
7276 DBRUNMSG(BCE_EXTREME_SEND,
7277 bce_dump_tx_chain(sc, debug_prod, nsegs));
7280 * Ensure that the mbuf pointer for this transmission
7281 * is placed at the array index of the last
7282 * descriptor in this chain. This is done
7283 * because a single map is used for all
7284 * segments of the mbuf and we don't want to
7285 * unload the map before all of the segments
7288 sc->tx_mbuf_ptr[chain_prod] = m0;
7289 sc->used_tx_bd += nsegs;
7291 /* Update some debug statistic counters */
7292 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
7293 sc->tx_hi_watermark = sc->used_tx_bd);
7294 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
7295 DBRUNIF(sc->debug_tx_mbuf_alloc++);
7297 DBRUNMSG(BCE_EXTREME_SEND, bce_dump_tx_mbuf_chain(sc, chain_prod, 1));
7299 /* prod points to the next free tx_bd at this point. */
7301 sc->tx_prod_bseq = prod_bseq;
7303 /* Tell the chip about the waiting TX frames. */
7304 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) +
7305 BCE_L2MQ_TX_HOST_BIDX, sc->tx_prod);
7306 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) +
7307 BCE_L2MQ_TX_HOST_BSEQ, sc->tx_prod_bseq);
7310 DBEXIT(BCE_VERBOSE_SEND);
7315 /****************************************************************************/
7316 /* Main transmit routine when called from another routine with a lock. */
7320 /****************************************************************************/
7322 bce_start_locked(struct ifnet *ifp)
7324 struct bce_softc *sc = ifp->if_softc;
7325 struct mbuf *m_head = NULL;
7327 u16 tx_prod, tx_chain_prod;
7329 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
7331 BCE_LOCK_ASSERT(sc);
7333 /* prod points to the next free tx_bd. */
7334 tx_prod = sc->tx_prod;
7335 tx_chain_prod = TX_CHAIN_IDX(tx_prod);
7337 DBPRINT(sc, BCE_INFO_SEND,
7338 "%s(enter): tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
7339 "tx_prod_bseq = 0x%08X\n",
7340 __FUNCTION__, tx_prod, tx_chain_prod, sc->tx_prod_bseq);
7342 /* If there's no link or the transmit queue is empty then just exit. */
7343 if (sc->bce_link_up == FALSE) {
7344 DBPRINT(sc, BCE_INFO_SEND, "%s(): No link.\n",
7346 goto bce_start_locked_exit;
7349 if (IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
7350 DBPRINT(sc, BCE_INFO_SEND, "%s(): Transmit queue empty.\n",
7352 goto bce_start_locked_exit;
7356 * Keep adding entries while there is space in the ring.
7358 while (sc->used_tx_bd < sc->max_tx_bd) {
7360 /* Check for any frames to send. */
7361 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
7363 /* Stop when the transmit queue is empty. */
7368 * Pack the data into the transmit ring. If we
7369 * don't have room, place the mbuf back at the
7370 * head of the queue and set the OACTIVE flag
7371 * to wait for the NIC to drain the chain.
7373 if (bce_tx_encap(sc, &m_head)) {
7375 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
7376 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
7377 DBPRINT(sc, BCE_INFO_SEND,
7378 "TX chain is closed for business! Total "
7379 "tx_bd used = %d\n", sc->used_tx_bd);
7385 /* Send a copy of the frame to any BPF listeners. */
7386 ETHER_BPF_MTAP(ifp, m_head);
7389 /* Exit if no packets were dequeued. */
7391 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): No packets were "
7392 "dequeued\n", __FUNCTION__);
7393 goto bce_start_locked_exit;
7396 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): Inserted %d frames into "
7397 "send queue.\n", __FUNCTION__, count);
7399 /* Set the tx timeout. */
7400 sc->watchdog_timer = BCE_TX_TIMEOUT;
7402 DBRUNMSG(BCE_VERBOSE_SEND, bce_dump_ctx(sc, TX_CID));
7403 DBRUNMSG(BCE_VERBOSE_SEND, bce_dump_mq_regs(sc));
7405 bce_start_locked_exit:
7406 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
7411 /****************************************************************************/
7412 /* Main transmit routine when called from another routine without a lock. */
7416 /****************************************************************************/
7418 bce_start(struct ifnet *ifp)
7420 struct bce_softc *sc = ifp->if_softc;
7422 DBENTER(BCE_VERBOSE_SEND);
7425 bce_start_locked(ifp);
7428 DBEXIT(BCE_VERBOSE_SEND);
7432 /****************************************************************************/
7433 /* Handles any IOCTL calls from the operating system. */
7436 /* 0 for success, positive value for failure. */
7437 /****************************************************************************/
7439 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
7441 struct bce_softc *sc = ifp->if_softc;
7442 struct ifreq *ifr = (struct ifreq *) data;
7443 struct mii_data *mii;
7444 int mask, error = 0;
7446 DBENTER(BCE_VERBOSE_MISC);
7450 /* Set the interface MTU. */
7452 /* Check that the MTU setting is supported. */
7453 if ((ifr->ifr_mtu < BCE_MIN_MTU) ||
7454 (ifr->ifr_mtu > BCE_MAX_JUMBO_MTU)) {
7459 DBPRINT(sc, BCE_INFO_MISC,
7460 "SIOCSIFMTU: Changing MTU from %d to %d\n",
7461 (int) ifp->if_mtu, (int) ifr->ifr_mtu);
7464 ifp->if_mtu = ifr->ifr_mtu;
7466 if (bce_hdr_split == FALSE) {
7467 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7469 * Because allocation size is used in RX
7470 * buffer allocation, stop controller if
7471 * it is already running.
7476 bce_get_rx_buffer_sizes(sc, ifp->if_mtu);
7478 bce_init_locked(sc);
7484 /* Set interface flags. */
7486 DBPRINT(sc, BCE_VERBOSE_SPECIAL, "Received SIOCSIFFLAGS\n");
7490 /* Check if the interface is up. */
7491 if (ifp->if_flags & IFF_UP) {
7492 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7493 /* Change promiscuous/multicast flags as necessary. */
7494 bce_set_rx_mode(sc);
7497 bce_init_locked(sc);
7500 /* The interface is down, check if driver is running. */
7501 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7504 /* If MFW is running, restart the controller a bit. */
7505 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
7506 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
7508 bce_mgmt_init_locked(sc);
7516 /* Add/Delete multicast address */
7519 DBPRINT(sc, BCE_VERBOSE_MISC,
7520 "Received SIOCADDMULTI/SIOCDELMULTI\n");
7523 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
7524 bce_set_rx_mode(sc);
7529 /* Set/Get Interface media */
7532 DBPRINT(sc, BCE_VERBOSE_MISC,
7533 "Received SIOCSIFMEDIA/SIOCGIFMEDIA\n");
7535 mii = device_get_softc(sc->bce_miibus);
7536 error = ifmedia_ioctl(ifp, ifr,
7537 &mii->mii_media, command);
7540 /* Set interface capability */
7542 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
7543 DBPRINT(sc, BCE_INFO_MISC,
7544 "Received SIOCSIFCAP = 0x%08X\n", (u32) mask);
7546 /* Toggle the TX checksum capabilities enable flag. */
7547 if (mask & IFCAP_TXCSUM &&
7548 ifp->if_capabilities & IFCAP_TXCSUM) {
7549 ifp->if_capenable ^= IFCAP_TXCSUM;
7550 if (IFCAP_TXCSUM & ifp->if_capenable)
7551 ifp->if_hwassist |= BCE_IF_HWASSIST;
7553 ifp->if_hwassist &= ~BCE_IF_HWASSIST;
7556 /* Toggle the RX checksum capabilities enable flag. */
7557 if (mask & IFCAP_RXCSUM &&
7558 ifp->if_capabilities & IFCAP_RXCSUM)
7559 ifp->if_capenable ^= IFCAP_RXCSUM;
7561 /* Toggle the TSO capabilities enable flag. */
7562 if (bce_tso_enable && (mask & IFCAP_TSO4) &&
7563 ifp->if_capabilities & IFCAP_TSO4) {
7564 ifp->if_capenable ^= IFCAP_TSO4;
7565 if (IFCAP_TSO4 & ifp->if_capenable)
7566 ifp->if_hwassist |= CSUM_TSO;
7568 ifp->if_hwassist &= ~CSUM_TSO;
7571 if (mask & IFCAP_VLAN_HWCSUM &&
7572 ifp->if_capabilities & IFCAP_VLAN_HWCSUM)
7573 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
7575 if ((mask & IFCAP_VLAN_HWTSO) != 0 &&
7576 (ifp->if_capabilities & IFCAP_VLAN_HWTSO) != 0)
7577 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
7579 * Don't actually disable VLAN tag stripping as
7580 * management firmware (ASF/IPMI/UMP) requires the
7581 * feature. If VLAN tag stripping is disabled driver
7582 * will manually reconstruct the VLAN frame by
7583 * appending stripped VLAN tag.
7585 if ((mask & IFCAP_VLAN_HWTAGGING) != 0 &&
7586 (ifp->if_capabilities & IFCAP_VLAN_HWTAGGING)) {
7587 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
7588 if ((ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
7590 ifp->if_capenable &= ~IFCAP_VLAN_HWTSO;
7592 VLAN_CAPABILITIES(ifp);
7595 /* We don't know how to handle the IOCTL, pass it on. */
7596 error = ether_ioctl(ifp, command, data);
7600 DBEXIT(BCE_VERBOSE_MISC);
7605 /****************************************************************************/
7606 /* Transmit timeout handler. */
7610 /****************************************************************************/
7612 bce_watchdog(struct bce_softc *sc)
7614 DBENTER(BCE_EXTREME_SEND);
7616 BCE_LOCK_ASSERT(sc);
7618 /* If the watchdog timer hasn't expired then just exit. */
7619 if (sc->watchdog_timer == 0 || --sc->watchdog_timer)
7620 goto bce_watchdog_exit;
7622 /* If pause frames are active then don't reset the hardware. */
7623 /* ToDo: Should we reset the timer here? */
7624 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
7625 goto bce_watchdog_exit;
7627 BCE_PRINTF("%s(%d): Watchdog timeout occurred, resetting!\n",
7628 __FILE__, __LINE__);
7631 bce_dump_driver_state(sc);
7632 bce_dump_status_block(sc);
7633 bce_dump_stats_block(sc);
7635 bce_dump_txp_state(sc, 0);
7636 bce_dump_rxp_state(sc, 0);
7637 bce_dump_tpat_state(sc, 0);
7638 bce_dump_cp_state(sc, 0);
7639 bce_dump_com_state(sc, 0));
7641 DBRUN(bce_breakpoint(sc));
7643 sc->bce_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
7645 bce_init_locked(sc);
7646 sc->bce_ifp->if_oerrors++;
7649 DBEXIT(BCE_EXTREME_SEND);
7654 * Interrupt handler.
7656 /****************************************************************************/
7657 /* Main interrupt entry point. Verifies that the controller generated the */
7658 /* interrupt and then calls a separate routine for handle the various */
7659 /* interrupt causes (PHY, TX, RX). */
7662 /* 0 for success, positive value for failure. */
7663 /****************************************************************************/
7667 struct bce_softc *sc;
7669 u32 status_attn_bits;
7670 u16 hw_rx_cons, hw_tx_cons;
7675 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
7676 DBRUNMSG(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
7677 DBRUNMSG(BCE_VERBOSE_INTR, bce_dump_stats_block(sc));
7681 DBRUN(sc->interrupts_generated++);
7683 /* Synchnorize before we read from interface's status block */
7684 bus_dmamap_sync(sc->status_tag, sc->status_map,
7685 BUS_DMASYNC_POSTREAD);
7688 * If the hardware status block index
7689 * matches the last value read by the
7690 * driver and we haven't asserted our
7691 * interrupt then there's nothing to do.
7693 if ((sc->status_block->status_idx == sc->last_status_idx) &&
7694 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
7695 BCE_PCICFG_MISC_STATUS_INTA_VALUE)) {
7696 DBPRINT(sc, BCE_VERBOSE_INTR, "%s(): Spurious interrupt.\n",
7701 /* Ack the interrupt and stop others from occuring. */
7702 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
7703 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
7704 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
7706 /* Check if the hardware has finished any work. */
7707 hw_rx_cons = bce_get_hw_rx_cons(sc);
7708 hw_tx_cons = bce_get_hw_tx_cons(sc);
7710 /* Keep processing data as long as there is work to do. */
7713 status_attn_bits = sc->status_block->status_attn_bits;
7715 DBRUNIF(DB_RANDOMTRUE(unexpected_attention_sim_control),
7716 BCE_PRINTF("Simulating unexpected status attention "
7718 sc->unexpected_attention_sim_count++;
7719 status_attn_bits = status_attn_bits |
7720 STATUS_ATTN_BITS_PARITY_ERROR);
7722 /* Was it a link change interrupt? */
7723 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
7724 (sc->status_block->status_attn_bits_ack &
7725 STATUS_ATTN_BITS_LINK_STATE)) {
7728 /* Clear transient updates during link state change. */
7729 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command |
7730 BCE_HC_COMMAND_COAL_NOW_WO_INT);
7731 REG_RD(sc, BCE_HC_COMMAND);
7734 /* If any other attention is asserted, the chip is toast. */
7735 if (((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
7736 (sc->status_block->status_attn_bits_ack &
7737 ~STATUS_ATTN_BITS_LINK_STATE))) {
7739 sc->unexpected_attention_count++;
7741 BCE_PRINTF("%s(%d): Fatal attention detected: "
7742 "0x%08X\n", __FILE__, __LINE__,
7743 sc->status_block->status_attn_bits);
7746 if (unexpected_attention_sim_control == 0)
7747 bce_breakpoint(sc));
7749 bce_init_locked(sc);
7753 /* Check for any completed RX frames. */
7754 if (hw_rx_cons != sc->hw_rx_cons)
7757 /* Check for any completed TX frames. */
7758 if (hw_tx_cons != sc->hw_tx_cons)
7761 /* Save status block index value for the next interrupt. */
7762 sc->last_status_idx = sc->status_block->status_idx;
7765 * Prevent speculative reads from getting
7766 * ahead of the status block.
7768 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
7769 BUS_SPACE_BARRIER_READ);
7772 * If there's no work left then exit the
7773 * interrupt service routine.
7775 hw_rx_cons = bce_get_hw_rx_cons(sc);
7776 hw_tx_cons = bce_get_hw_tx_cons(sc);
7778 if ((hw_rx_cons == sc->hw_rx_cons) &&
7779 (hw_tx_cons == sc->hw_tx_cons))
7784 bus_dmamap_sync(sc->status_tag, sc->status_map,
7785 BUS_DMASYNC_PREREAD);
7787 /* Re-enable interrupts. */
7788 bce_enable_intr(sc, 0);
7790 /* Handle any frames that arrived while handling the interrupt. */
7791 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
7792 !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
7793 bce_start_locked(ifp);
7798 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
7802 /****************************************************************************/
7803 /* Programs the various packet receive modes (broadcast and multicast). */
7807 /****************************************************************************/
7809 bce_set_rx_mode(struct bce_softc *sc)
7812 struct ifmultiaddr *ifma;
7813 u32 hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
7814 u32 rx_mode, sort_mode;
7817 DBENTER(BCE_VERBOSE_MISC);
7819 BCE_LOCK_ASSERT(sc);
7823 /* Initialize receive mode default settings. */
7824 rx_mode = sc->rx_mode & ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
7825 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
7826 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
7829 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
7832 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
7833 (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)))
7834 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
7837 * Check for promiscuous, all multicast, or selected
7838 * multicast address filtering.
7840 if (ifp->if_flags & IFF_PROMISC) {
7841 DBPRINT(sc, BCE_INFO_MISC, "Enabling promiscuous mode.\n");
7843 /* Enable promiscuous mode. */
7844 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
7845 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
7846 } else if (ifp->if_flags & IFF_ALLMULTI) {
7847 DBPRINT(sc, BCE_INFO_MISC, "Enabling all multicast mode.\n");
7849 /* Enable all multicast addresses. */
7850 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
7851 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), 0xffffffff);
7853 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
7855 /* Accept one or more multicast(s). */
7856 DBPRINT(sc, BCE_INFO_MISC, "Enabling selective multicast mode.\n");
7858 if_maddr_rlock(ifp);
7859 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
7860 if (ifma->ifma_addr->sa_family != AF_LINK)
7862 h = ether_crc32_le(LLADDR((struct sockaddr_dl *)
7863 ifma->ifma_addr), ETHER_ADDR_LEN) & 0xFF;
7864 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
7866 if_maddr_runlock(ifp);
7868 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++)
7869 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), hashes[i]);
7871 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
7874 /* Only make changes if the recive mode has actually changed. */
7875 if (rx_mode != sc->rx_mode) {
7876 DBPRINT(sc, BCE_VERBOSE_MISC, "Enabling new receive mode: "
7877 "0x%08X\n", rx_mode);
7879 sc->rx_mode = rx_mode;
7880 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
7883 /* Disable and clear the exisitng sort before enabling a new sort. */
7884 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
7885 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
7886 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
7888 DBEXIT(BCE_VERBOSE_MISC);
7892 /****************************************************************************/
7893 /* Called periodically to updates statistics from the controllers */
7894 /* statistics block. */
7898 /****************************************************************************/
7900 bce_stats_update(struct bce_softc *sc)
7903 struct statistics_block *stats;
7905 DBENTER(BCE_EXTREME_MISC);
7909 stats = (struct statistics_block *) sc->stats_block;
7912 * Certain controllers don't report
7913 * carrier sense errors correctly.
7914 * See errata E11_5708CA0_1165.
7916 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
7917 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0))
7919 (u_long) stats->stat_Dot3StatsCarrierSenseErrors;
7922 * Update the sysctl statistics from the
7923 * hardware statistics.
7925 sc->stat_IfHCInOctets =
7926 ((u64) stats->stat_IfHCInOctets_hi << 32) +
7927 (u64) stats->stat_IfHCInOctets_lo;
7929 sc->stat_IfHCInBadOctets =
7930 ((u64) stats->stat_IfHCInBadOctets_hi << 32) +
7931 (u64) stats->stat_IfHCInBadOctets_lo;
7933 sc->stat_IfHCOutOctets =
7934 ((u64) stats->stat_IfHCOutOctets_hi << 32) +
7935 (u64) stats->stat_IfHCOutOctets_lo;
7937 sc->stat_IfHCOutBadOctets =
7938 ((u64) stats->stat_IfHCOutBadOctets_hi << 32) +
7939 (u64) stats->stat_IfHCOutBadOctets_lo;
7941 sc->stat_IfHCInUcastPkts =
7942 ((u64) stats->stat_IfHCInUcastPkts_hi << 32) +
7943 (u64) stats->stat_IfHCInUcastPkts_lo;
7945 sc->stat_IfHCInMulticastPkts =
7946 ((u64) stats->stat_IfHCInMulticastPkts_hi << 32) +
7947 (u64) stats->stat_IfHCInMulticastPkts_lo;
7949 sc->stat_IfHCInBroadcastPkts =
7950 ((u64) stats->stat_IfHCInBroadcastPkts_hi << 32) +
7951 (u64) stats->stat_IfHCInBroadcastPkts_lo;
7953 sc->stat_IfHCOutUcastPkts =
7954 ((u64) stats->stat_IfHCOutUcastPkts_hi << 32) +
7955 (u64) stats->stat_IfHCOutUcastPkts_lo;
7957 sc->stat_IfHCOutMulticastPkts =
7958 ((u64) stats->stat_IfHCOutMulticastPkts_hi << 32) +
7959 (u64) stats->stat_IfHCOutMulticastPkts_lo;
7961 sc->stat_IfHCOutBroadcastPkts =
7962 ((u64) stats->stat_IfHCOutBroadcastPkts_hi << 32) +
7963 (u64) stats->stat_IfHCOutBroadcastPkts_lo;
7965 /* ToDo: Preserve counters beyond 32 bits? */
7966 /* ToDo: Read the statistics from auto-clear regs? */
7968 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
7969 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
7971 sc->stat_Dot3StatsCarrierSenseErrors =
7972 stats->stat_Dot3StatsCarrierSenseErrors;
7974 sc->stat_Dot3StatsFCSErrors =
7975 stats->stat_Dot3StatsFCSErrors;
7977 sc->stat_Dot3StatsAlignmentErrors =
7978 stats->stat_Dot3StatsAlignmentErrors;
7980 sc->stat_Dot3StatsSingleCollisionFrames =
7981 stats->stat_Dot3StatsSingleCollisionFrames;
7983 sc->stat_Dot3StatsMultipleCollisionFrames =
7984 stats->stat_Dot3StatsMultipleCollisionFrames;
7986 sc->stat_Dot3StatsDeferredTransmissions =
7987 stats->stat_Dot3StatsDeferredTransmissions;
7989 sc->stat_Dot3StatsExcessiveCollisions =
7990 stats->stat_Dot3StatsExcessiveCollisions;
7992 sc->stat_Dot3StatsLateCollisions =
7993 stats->stat_Dot3StatsLateCollisions;
7995 sc->stat_EtherStatsCollisions =
7996 stats->stat_EtherStatsCollisions;
7998 sc->stat_EtherStatsFragments =
7999 stats->stat_EtherStatsFragments;
8001 sc->stat_EtherStatsJabbers =
8002 stats->stat_EtherStatsJabbers;
8004 sc->stat_EtherStatsUndersizePkts =
8005 stats->stat_EtherStatsUndersizePkts;
8007 sc->stat_EtherStatsOversizePkts =
8008 stats->stat_EtherStatsOversizePkts;
8010 sc->stat_EtherStatsPktsRx64Octets =
8011 stats->stat_EtherStatsPktsRx64Octets;
8013 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
8014 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
8016 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
8017 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
8019 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
8020 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
8022 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
8023 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
8025 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
8026 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
8028 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
8029 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
8031 sc->stat_EtherStatsPktsTx64Octets =
8032 stats->stat_EtherStatsPktsTx64Octets;
8034 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
8035 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
8037 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
8038 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
8040 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
8041 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
8043 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
8044 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
8046 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
8047 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
8049 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
8050 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
8052 sc->stat_XonPauseFramesReceived =
8053 stats->stat_XonPauseFramesReceived;
8055 sc->stat_XoffPauseFramesReceived =
8056 stats->stat_XoffPauseFramesReceived;
8058 sc->stat_OutXonSent =
8059 stats->stat_OutXonSent;
8061 sc->stat_OutXoffSent =
8062 stats->stat_OutXoffSent;
8064 sc->stat_FlowControlDone =
8065 stats->stat_FlowControlDone;
8067 sc->stat_MacControlFramesReceived =
8068 stats->stat_MacControlFramesReceived;
8070 sc->stat_XoffStateEntered =
8071 stats->stat_XoffStateEntered;
8073 sc->stat_IfInFramesL2FilterDiscards =
8074 stats->stat_IfInFramesL2FilterDiscards;
8076 sc->stat_IfInRuleCheckerDiscards =
8077 stats->stat_IfInRuleCheckerDiscards;
8079 sc->stat_IfInFTQDiscards =
8080 stats->stat_IfInFTQDiscards;
8082 sc->stat_IfInMBUFDiscards =
8083 stats->stat_IfInMBUFDiscards;
8085 sc->stat_IfInRuleCheckerP4Hit =
8086 stats->stat_IfInRuleCheckerP4Hit;
8088 sc->stat_CatchupInRuleCheckerDiscards =
8089 stats->stat_CatchupInRuleCheckerDiscards;
8091 sc->stat_CatchupInFTQDiscards =
8092 stats->stat_CatchupInFTQDiscards;
8094 sc->stat_CatchupInMBUFDiscards =
8095 stats->stat_CatchupInMBUFDiscards;
8097 sc->stat_CatchupInRuleCheckerP4Hit =
8098 stats->stat_CatchupInRuleCheckerP4Hit;
8100 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
8103 * Update the interface statistics from the
8104 * hardware statistics.
8106 ifp->if_collisions =
8107 (u_long) sc->stat_EtherStatsCollisions;
8109 /* ToDo: This method loses soft errors. */
8111 (u_long) sc->stat_EtherStatsUndersizePkts +
8112 (u_long) sc->stat_EtherStatsOversizePkts +
8113 (u_long) sc->stat_IfInMBUFDiscards +
8114 (u_long) sc->stat_Dot3StatsAlignmentErrors +
8115 (u_long) sc->stat_Dot3StatsFCSErrors +
8116 (u_long) sc->stat_IfInRuleCheckerDiscards +
8117 (u_long) sc->stat_IfInFTQDiscards +
8118 (u_long) sc->com_no_buffers;
8120 /* ToDo: This method loses soft errors. */
8122 (u_long) sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
8123 (u_long) sc->stat_Dot3StatsExcessiveCollisions +
8124 (u_long) sc->stat_Dot3StatsLateCollisions;
8126 /* ToDo: Add additional statistics? */
8128 DBEXIT(BCE_EXTREME_MISC);
8132 /****************************************************************************/
8133 /* Periodic function to notify the bootcode that the driver is still */
8138 /****************************************************************************/
8140 bce_pulse(void *xsc)
8142 struct bce_softc *sc = xsc;
8145 DBENTER(BCE_EXTREME_MISC);
8147 BCE_LOCK_ASSERT(sc);
8149 /* Tell the firmware that the driver is still running. */
8150 msg = (u32) ++sc->bce_fw_drv_pulse_wr_seq;
8151 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
8153 /* Update the bootcode condition. */
8154 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
8156 /* Report whether the bootcode still knows the driver is running. */
8157 if (bce_verbose || bootverbose) {
8158 if (sc->bce_drv_cardiac_arrest == FALSE) {
8159 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
8160 sc->bce_drv_cardiac_arrest = TRUE;
8161 BCE_PRINTF("%s(): Warning: bootcode "
8162 "thinks driver is absent! "
8163 "(bc_state = 0x%08X)\n",
8164 __FUNCTION__, sc->bc_state);
8168 * Not supported by all bootcode versions.
8169 * (v5.0.11+ and v5.2.1+) Older bootcode
8170 * will require the driver to reset the
8171 * controller to clear this condition.
8173 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
8174 sc->bce_drv_cardiac_arrest = FALSE;
8175 BCE_PRINTF("%s(): Bootcode found the "
8176 "driver pulse! (bc_state = 0x%08X)\n",
8177 __FUNCTION__, sc->bc_state);
8183 /* Schedule the next pulse. */
8184 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
8186 DBEXIT(BCE_EXTREME_MISC);
8190 /****************************************************************************/
8191 /* Periodic function to perform maintenance tasks. */
8195 /****************************************************************************/
8199 struct bce_softc *sc = xsc;
8200 struct mii_data *mii;
8205 DBENTER(BCE_EXTREME_MISC);
8207 BCE_LOCK_ASSERT(sc);
8209 /* Schedule the next tick. */
8210 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
8212 /* Update the statistics from the hardware statistics block. */
8213 bce_stats_update(sc);
8216 * ToDo: This is a safety measure. Need to re-evaluate
8217 * high level processing logic and eliminate this code.
8219 /* Top off the receive and page chains. */
8220 if (bce_hdr_split == TRUE)
8221 bce_fill_pg_chain(sc);
8222 bce_fill_rx_chain(sc);
8224 /* Check that chip hasn't hung. */
8227 /* If link is up already up then we're done. */
8228 if (sc->bce_link_up == TRUE)
8231 /* Link is down. Check what the PHY's doing. */
8232 mii = device_get_softc(sc->bce_miibus);
8235 /* Check if the link has come up. */
8236 if ((mii->mii_media_status & IFM_ACTIVE) &&
8237 (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)) {
8238 DBPRINT(sc, BCE_VERBOSE_MISC,
8239 "%s(): Link up!\n", __FUNCTION__);
8240 sc->bce_link_up = TRUE;
8241 if ((IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
8242 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX ||
8243 IFM_SUBTYPE(mii->mii_media_active) == IFM_2500_SX) &&
8244 (bce_verbose || bootverbose))
8245 BCE_PRINTF("Gigabit link up!\n");
8247 /* Now that link is up, handle any outstanding TX traffic. */
8248 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
8249 DBPRINT(sc, BCE_VERBOSE_MISC, "%s(): Found "
8250 "pending TX traffic.\n", __FUNCTION__);
8251 bce_start_locked(ifp);
8256 DBEXIT(BCE_EXTREME_MISC);
8261 /****************************************************************************/
8262 /* Allows the driver state to be dumped through the sysctl interface. */
8265 /* 0 for success, positive value for failure. */
8266 /****************************************************************************/
8268 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
8272 struct bce_softc *sc;
8275 error = sysctl_handle_int(oidp, &result, 0, req);
8277 if (error || !req->newptr)
8281 sc = (struct bce_softc *)arg1;
8282 bce_dump_driver_state(sc);
8289 /****************************************************************************/
8290 /* Allows the hardware state to be dumped through the sysctl interface. */
8293 /* 0 for success, positive value for failure. */
8294 /****************************************************************************/
8296 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
8300 struct bce_softc *sc;
8303 error = sysctl_handle_int(oidp, &result, 0, req);
8305 if (error || !req->newptr)
8309 sc = (struct bce_softc *)arg1;
8310 bce_dump_hw_state(sc);
8317 /****************************************************************************/
8318 /* Allows the status block to be dumped through the sysctl interface. */
8321 /* 0 for success, positive value for failure. */
8322 /****************************************************************************/
8324 bce_sysctl_status_block(SYSCTL_HANDLER_ARGS)
8328 struct bce_softc *sc;
8331 error = sysctl_handle_int(oidp, &result, 0, req);
8333 if (error || !req->newptr)
8337 sc = (struct bce_softc *)arg1;
8338 bce_dump_status_block(sc);
8345 /****************************************************************************/
8346 /* Allows the stats block to be dumped through the sysctl interface. */
8349 /* 0 for success, positive value for failure. */
8350 /****************************************************************************/
8352 bce_sysctl_stats_block(SYSCTL_HANDLER_ARGS)
8356 struct bce_softc *sc;
8359 error = sysctl_handle_int(oidp, &result, 0, req);
8361 if (error || !req->newptr)
8365 sc = (struct bce_softc *)arg1;
8366 bce_dump_stats_block(sc);
8373 /****************************************************************************/
8374 /* Allows the stat counters to be cleared without unloading/reloading the */
8378 /* 0 for success, positive value for failure. */
8379 /****************************************************************************/
8381 bce_sysctl_stats_clear(SYSCTL_HANDLER_ARGS)
8385 struct bce_softc *sc;
8388 error = sysctl_handle_int(oidp, &result, 0, req);
8390 if (error || !req->newptr)
8394 sc = (struct bce_softc *)arg1;
8395 struct statistics_block *stats;
8397 stats = (struct statistics_block *) sc->stats_block;
8398 bzero(stats, sizeof(struct statistics_block));
8400 /* Clear the internal H/W statistics counters. */
8401 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
8403 /* Reset the driver maintained statistics. */
8405 sc->interrupts_tx = 0;
8406 sc->tso_frames_requested =
8407 sc->tso_frames_completed =
8408 sc->tso_frames_failed = 0;
8409 sc->rx_empty_count =
8410 sc->tx_full_count = 0;
8411 sc->rx_low_watermark = USABLE_RX_BD_ALLOC;
8412 sc->tx_hi_watermark = 0;
8413 sc->l2fhdr_error_count =
8414 sc->l2fhdr_error_sim_count = 0;
8415 sc->mbuf_alloc_failed_count =
8416 sc->mbuf_alloc_failed_sim_count = 0;
8417 sc->dma_map_addr_rx_failed_count =
8418 sc->dma_map_addr_tx_failed_count = 0;
8419 sc->mbuf_frag_count = 0;
8420 sc->csum_offload_tcp_udp =
8421 sc->csum_offload_ip = 0;
8422 sc->vlan_tagged_frames_rcvd =
8423 sc->vlan_tagged_frames_stripped = 0;
8424 sc->split_header_frames_rcvd =
8425 sc->split_header_tcp_frames_rcvd = 0;
8427 /* Clear firmware maintained statistics. */
8428 REG_WR_IND(sc, 0x120084, 0);
8435 /****************************************************************************/
8436 /* Allows the shared memory contents to be dumped through the sysctl . */
8440 /* 0 for success, positive value for failure. */
8441 /****************************************************************************/
8443 bce_sysctl_shmem_state(SYSCTL_HANDLER_ARGS)
8447 struct bce_softc *sc;
8450 error = sysctl_handle_int(oidp, &result, 0, req);
8452 if (error || !req->newptr)
8456 sc = (struct bce_softc *)arg1;
8457 bce_dump_shmem_state(sc);
8464 /****************************************************************************/
8465 /* Allows the bootcode state to be dumped through the sysctl interface. */
8468 /* 0 for success, positive value for failure. */
8469 /****************************************************************************/
8471 bce_sysctl_bc_state(SYSCTL_HANDLER_ARGS)
8475 struct bce_softc *sc;
8478 error = sysctl_handle_int(oidp, &result, 0, req);
8480 if (error || !req->newptr)
8484 sc = (struct bce_softc *)arg1;
8485 bce_dump_bc_state(sc);
8492 /****************************************************************************/
8493 /* Provides a sysctl interface to allow dumping the RX BD chain. */
8496 /* 0 for success, positive value for failure. */
8497 /****************************************************************************/
8499 bce_sysctl_dump_rx_bd_chain(SYSCTL_HANDLER_ARGS)
8503 struct bce_softc *sc;
8506 error = sysctl_handle_int(oidp, &result, 0, req);
8508 if (error || !req->newptr)
8512 sc = (struct bce_softc *)arg1;
8513 bce_dump_rx_bd_chain(sc, 0, TOTAL_RX_BD_ALLOC);
8520 /****************************************************************************/
8521 /* Provides a sysctl interface to allow dumping the RX MBUF chain. */
8524 /* 0 for success, positive value for failure. */
8525 /****************************************************************************/
8527 bce_sysctl_dump_rx_mbuf_chain(SYSCTL_HANDLER_ARGS)
8531 struct bce_softc *sc;
8534 error = sysctl_handle_int(oidp, &result, 0, req);
8536 if (error || !req->newptr)
8540 sc = (struct bce_softc *)arg1;
8541 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD_ALLOC);
8548 /****************************************************************************/
8549 /* Provides a sysctl interface to allow dumping the TX chain. */
8552 /* 0 for success, positive value for failure. */
8553 /****************************************************************************/
8555 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
8559 struct bce_softc *sc;
8562 error = sysctl_handle_int(oidp, &result, 0, req);
8564 if (error || !req->newptr)
8568 sc = (struct bce_softc *)arg1;
8569 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD_ALLOC);
8576 /****************************************************************************/
8577 /* Provides a sysctl interface to allow dumping the page chain. */
8580 /* 0 for success, positive value for failure. */
8581 /****************************************************************************/
8583 bce_sysctl_dump_pg_chain(SYSCTL_HANDLER_ARGS)
8587 struct bce_softc *sc;
8590 error = sysctl_handle_int(oidp, &result, 0, req);
8592 if (error || !req->newptr)
8596 sc = (struct bce_softc *)arg1;
8597 bce_dump_pg_chain(sc, 0, TOTAL_PG_BD_ALLOC);
8603 /****************************************************************************/
8604 /* Provides a sysctl interface to allow reading arbitrary NVRAM offsets in */
8605 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8608 /* 0 for success, positive value for failure. */
8609 /****************************************************************************/
8611 bce_sysctl_nvram_read(SYSCTL_HANDLER_ARGS)
8613 struct bce_softc *sc = (struct bce_softc *)arg1;
8617 u8 *data = (u8 *) val;
8620 error = sysctl_handle_int(oidp, &result, 0, req);
8621 if (error || (req->newptr == NULL))
8624 error = bce_nvram_read(sc, result, data, 4);
8626 BCE_PRINTF("offset 0x%08X = 0x%08X\n", result, bce_be32toh(val[0]));
8632 /****************************************************************************/
8633 /* Provides a sysctl interface to allow reading arbitrary registers in the */
8634 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8637 /* 0 for success, positive value for failure. */
8638 /****************************************************************************/
8640 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
8642 struct bce_softc *sc = (struct bce_softc *)arg1;
8647 error = sysctl_handle_int(oidp, &result, 0, req);
8648 if (error || (req->newptr == NULL))
8651 /* Make sure the register is accessible. */
8652 if (result < 0x8000) {
8653 val = REG_RD(sc, result);
8654 BCE_PRINTF("reg 0x%08X = 0x%08X\n", result, val);
8655 } else if (result < 0x0280000) {
8656 val = REG_RD_IND(sc, result);
8657 BCE_PRINTF("reg 0x%08X = 0x%08X\n", result, val);
8664 /****************************************************************************/
8665 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
8666 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8669 /* 0 for success, positive value for failure. */
8670 /****************************************************************************/
8672 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
8674 struct bce_softc *sc;
8680 error = sysctl_handle_int(oidp, &result, 0, req);
8681 if (error || (req->newptr == NULL))
8684 /* Make sure the register is accessible. */
8685 if (result < 0x20) {
8686 sc = (struct bce_softc *)arg1;
8688 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
8689 BCE_PRINTF("phy 0x%02X = 0x%04X\n", result, val);
8695 /****************************************************************************/
8696 /* Provides a sysctl interface for dumping the nvram contents. */
8697 /* DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8700 /* 0 for success, positive errno for failure. */
8701 /****************************************************************************/
8703 bce_sysctl_nvram_dump(SYSCTL_HANDLER_ARGS)
8705 struct bce_softc *sc = (struct bce_softc *)arg1;
8708 if (sc->nvram_buf == NULL)
8709 sc->nvram_buf = malloc(sc->bce_flash_size,
8710 M_TEMP, M_ZERO | M_WAITOK);
8713 if (req->oldlen == sc->bce_flash_size) {
8714 for (i = 0; i < sc->bce_flash_size && error == 0; i++)
8715 error = bce_nvram_read(sc, i, &sc->nvram_buf[i], 1);
8719 error = SYSCTL_OUT(req, sc->nvram_buf, sc->bce_flash_size);
8724 #ifdef BCE_NVRAM_WRITE_SUPPORT
8725 /****************************************************************************/
8726 /* Provides a sysctl interface for writing to nvram. */
8727 /* DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8730 /* 0 for success, positive errno for failure. */
8731 /****************************************************************************/
8733 bce_sysctl_nvram_write(SYSCTL_HANDLER_ARGS)
8735 struct bce_softc *sc = (struct bce_softc *)arg1;
8738 if (sc->nvram_buf == NULL)
8739 sc->nvram_buf = malloc(sc->bce_flash_size,
8740 M_TEMP, M_ZERO | M_WAITOK);
8742 bzero(sc->nvram_buf, sc->bce_flash_size);
8744 error = SYSCTL_IN(req, sc->nvram_buf, sc->bce_flash_size);
8748 if (req->newlen == sc->bce_flash_size)
8749 error = bce_nvram_write(sc, 0, sc->nvram_buf,
8750 sc->bce_flash_size);
8758 /****************************************************************************/
8759 /* Provides a sysctl interface to allow reading a CID. */
8762 /* 0 for success, positive value for failure. */
8763 /****************************************************************************/
8765 bce_sysctl_dump_ctx(SYSCTL_HANDLER_ARGS)
8767 struct bce_softc *sc;
8771 error = sysctl_handle_int(oidp, &result, 0, req);
8772 if (error || (req->newptr == NULL))
8775 /* Make sure the register is accessible. */
8776 if (result <= TX_CID) {
8777 sc = (struct bce_softc *)arg1;
8778 bce_dump_ctx(sc, result);
8785 /****************************************************************************/
8786 /* Provides a sysctl interface to forcing the driver to dump state and */
8787 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8790 /* 0 for success, positive value for failure. */
8791 /****************************************************************************/
8793 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
8797 struct bce_softc *sc;
8800 error = sysctl_handle_int(oidp, &result, 0, req);
8802 if (error || !req->newptr)
8806 sc = (struct bce_softc *)arg1;
8814 /****************************************************************************/
8815 /* Adds any sysctl parameters for tuning or debugging purposes. */
8818 /* 0 for success, positive value for failure. */
8819 /****************************************************************************/
8821 bce_add_sysctls(struct bce_softc *sc)
8823 struct sysctl_ctx_list *ctx;
8824 struct sysctl_oid_list *children;
8826 DBENTER(BCE_VERBOSE_MISC);
8828 ctx = device_get_sysctl_ctx(sc->bce_dev);
8829 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->bce_dev));
8832 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8833 "l2fhdr_error_sim_control",
8834 CTLFLAG_RW, &l2fhdr_error_sim_control,
8835 0, "Debug control to force l2fhdr errors");
8837 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8838 "l2fhdr_error_sim_count",
8839 CTLFLAG_RD, &sc->l2fhdr_error_sim_count,
8840 0, "Number of simulated l2_fhdr errors");
8843 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8844 "l2fhdr_error_count",
8845 CTLFLAG_RD, &sc->l2fhdr_error_count,
8846 0, "Number of l2_fhdr errors");
8849 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8850 "mbuf_alloc_failed_sim_control",
8851 CTLFLAG_RW, &mbuf_alloc_failed_sim_control,
8852 0, "Debug control to force mbuf allocation failures");
8854 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8855 "mbuf_alloc_failed_sim_count",
8856 CTLFLAG_RD, &sc->mbuf_alloc_failed_sim_count,
8857 0, "Number of simulated mbuf cluster allocation failures");
8860 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8861 "mbuf_alloc_failed_count",
8862 CTLFLAG_RD, &sc->mbuf_alloc_failed_count,
8863 0, "Number of mbuf allocation failures");
8865 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8867 CTLFLAG_RD, &sc->mbuf_frag_count,
8868 0, "Number of fragmented mbufs");
8871 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8872 "dma_map_addr_failed_sim_control",
8873 CTLFLAG_RW, &dma_map_addr_failed_sim_control,
8874 0, "Debug control to force DMA mapping failures");
8876 /* ToDo: Figure out how to update this value in bce_dma_map_addr(). */
8877 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8878 "dma_map_addr_failed_sim_count",
8879 CTLFLAG_RD, &sc->dma_map_addr_failed_sim_count,
8880 0, "Number of simulated DMA mapping failures");
8884 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8885 "dma_map_addr_rx_failed_count",
8886 CTLFLAG_RD, &sc->dma_map_addr_rx_failed_count,
8887 0, "Number of RX DMA mapping failures");
8889 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8890 "dma_map_addr_tx_failed_count",
8891 CTLFLAG_RD, &sc->dma_map_addr_tx_failed_count,
8892 0, "Number of TX DMA mapping failures");
8895 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8896 "unexpected_attention_sim_control",
8897 CTLFLAG_RW, &unexpected_attention_sim_control,
8898 0, "Debug control to simulate unexpected attentions");
8900 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8901 "unexpected_attention_sim_count",
8902 CTLFLAG_RW, &sc->unexpected_attention_sim_count,
8903 0, "Number of simulated unexpected attentions");
8906 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
8907 "unexpected_attention_count",
8908 CTLFLAG_RW, &sc->unexpected_attention_count,
8909 0, "Number of unexpected attentions");
8912 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8913 "debug_bootcode_running_failure",
8914 CTLFLAG_RW, &bootcode_running_failure_sim_control,
8915 0, "Debug control to force bootcode running failures");
8917 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8919 CTLFLAG_RD, &sc->rx_low_watermark,
8920 0, "Lowest level of free rx_bd's");
8922 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8924 CTLFLAG_RD, &sc->rx_empty_count,
8925 "Number of times the RX chain was empty");
8927 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
8929 CTLFLAG_RD, &sc->tx_hi_watermark,
8930 0, "Highest level of used tx_bd's");
8932 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8934 CTLFLAG_RD, &sc->tx_full_count,
8935 "Number of times the TX chain was full");
8937 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8938 "tso_frames_requested",
8939 CTLFLAG_RD, &sc->tso_frames_requested,
8940 "Number of TSO frames requested");
8942 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8943 "tso_frames_completed",
8944 CTLFLAG_RD, &sc->tso_frames_completed,
8945 "Number of TSO frames completed");
8947 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8948 "tso_frames_failed",
8949 CTLFLAG_RD, &sc->tso_frames_failed,
8950 "Number of TSO frames failed");
8952 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8954 CTLFLAG_RD, &sc->csum_offload_ip,
8955 "Number of IP checksum offload frames");
8957 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8958 "csum_offload_tcp_udp",
8959 CTLFLAG_RD, &sc->csum_offload_tcp_udp,
8960 "Number of TCP/UDP checksum offload frames");
8962 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8963 "vlan_tagged_frames_rcvd",
8964 CTLFLAG_RD, &sc->vlan_tagged_frames_rcvd,
8965 "Number of VLAN tagged frames received");
8967 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8968 "vlan_tagged_frames_stripped",
8969 CTLFLAG_RD, &sc->vlan_tagged_frames_stripped,
8970 "Number of VLAN tagged frames stripped");
8972 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8974 CTLFLAG_RD, &sc->interrupts_rx,
8975 "Number of RX interrupts");
8977 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8979 CTLFLAG_RD, &sc->interrupts_tx,
8980 "Number of TX interrupts");
8982 if (bce_hdr_split == TRUE) {
8983 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8984 "split_header_frames_rcvd",
8985 CTLFLAG_RD, &sc->split_header_frames_rcvd,
8986 "Number of split header frames received");
8988 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
8989 "split_header_tcp_frames_rcvd",
8990 CTLFLAG_RD, &sc->split_header_tcp_frames_rcvd,
8991 "Number of split header TCP frames received");
8994 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
8995 "nvram_dump", CTLTYPE_OPAQUE | CTLFLAG_RD,
8997 bce_sysctl_nvram_dump, "S", "");
8999 #ifdef BCE_NVRAM_WRITE_SUPPORT
9000 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9001 "nvram_write", CTLTYPE_OPAQUE | CTLFLAG_WR,
9003 bce_sysctl_nvram_write, "S", "");
9005 #endif /* BCE_DEBUG */
9007 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9008 "stat_IfHcInOctets",
9009 CTLFLAG_RD, &sc->stat_IfHCInOctets,
9012 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9013 "stat_IfHCInBadOctets",
9014 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
9015 "Bad bytes received");
9017 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9018 "stat_IfHCOutOctets",
9019 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
9022 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9023 "stat_IfHCOutBadOctets",
9024 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
9027 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9028 "stat_IfHCInUcastPkts",
9029 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
9030 "Unicast packets received");
9032 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9033 "stat_IfHCInMulticastPkts",
9034 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
9035 "Multicast packets received");
9037 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9038 "stat_IfHCInBroadcastPkts",
9039 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
9040 "Broadcast packets received");
9042 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9043 "stat_IfHCOutUcastPkts",
9044 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
9045 "Unicast packets sent");
9047 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9048 "stat_IfHCOutMulticastPkts",
9049 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
9050 "Multicast packets sent");
9052 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9053 "stat_IfHCOutBroadcastPkts",
9054 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
9055 "Broadcast packets sent");
9057 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9058 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
9059 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
9060 0, "Internal MAC transmit errors");
9062 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9063 "stat_Dot3StatsCarrierSenseErrors",
9064 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
9065 0, "Carrier sense errors");
9067 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9068 "stat_Dot3StatsFCSErrors",
9069 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
9070 0, "Frame check sequence errors");
9072 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9073 "stat_Dot3StatsAlignmentErrors",
9074 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
9075 0, "Alignment errors");
9077 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9078 "stat_Dot3StatsSingleCollisionFrames",
9079 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
9080 0, "Single Collision Frames");
9082 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9083 "stat_Dot3StatsMultipleCollisionFrames",
9084 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
9085 0, "Multiple Collision Frames");
9087 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9088 "stat_Dot3StatsDeferredTransmissions",
9089 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
9090 0, "Deferred Transmissions");
9092 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9093 "stat_Dot3StatsExcessiveCollisions",
9094 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
9095 0, "Excessive Collisions");
9097 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9098 "stat_Dot3StatsLateCollisions",
9099 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
9100 0, "Late Collisions");
9102 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9103 "stat_EtherStatsCollisions",
9104 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
9107 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9108 "stat_EtherStatsFragments",
9109 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
9112 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9113 "stat_EtherStatsJabbers",
9114 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
9117 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9118 "stat_EtherStatsUndersizePkts",
9119 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
9120 0, "Undersize packets");
9122 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9123 "stat_EtherStatsOversizePkts",
9124 CTLFLAG_RD, &sc->stat_EtherStatsOversizePkts,
9125 0, "stat_EtherStatsOversizePkts");
9127 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9128 "stat_EtherStatsPktsRx64Octets",
9129 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
9130 0, "Bytes received in 64 byte packets");
9132 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9133 "stat_EtherStatsPktsRx65Octetsto127Octets",
9134 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
9135 0, "Bytes received in 65 to 127 byte packets");
9137 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9138 "stat_EtherStatsPktsRx128Octetsto255Octets",
9139 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
9140 0, "Bytes received in 128 to 255 byte packets");
9142 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9143 "stat_EtherStatsPktsRx256Octetsto511Octets",
9144 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
9145 0, "Bytes received in 256 to 511 byte packets");
9147 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9148 "stat_EtherStatsPktsRx512Octetsto1023Octets",
9149 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
9150 0, "Bytes received in 512 to 1023 byte packets");
9152 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9153 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
9154 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
9155 0, "Bytes received in 1024 t0 1522 byte packets");
9157 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9158 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
9159 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
9160 0, "Bytes received in 1523 to 9022 byte packets");
9162 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9163 "stat_EtherStatsPktsTx64Octets",
9164 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
9165 0, "Bytes sent in 64 byte packets");
9167 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9168 "stat_EtherStatsPktsTx65Octetsto127Octets",
9169 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
9170 0, "Bytes sent in 65 to 127 byte packets");
9172 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9173 "stat_EtherStatsPktsTx128Octetsto255Octets",
9174 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
9175 0, "Bytes sent in 128 to 255 byte packets");
9177 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9178 "stat_EtherStatsPktsTx256Octetsto511Octets",
9179 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
9180 0, "Bytes sent in 256 to 511 byte packets");
9182 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9183 "stat_EtherStatsPktsTx512Octetsto1023Octets",
9184 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
9185 0, "Bytes sent in 512 to 1023 byte packets");
9187 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9188 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
9189 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
9190 0, "Bytes sent in 1024 to 1522 byte packets");
9192 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9193 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
9194 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
9195 0, "Bytes sent in 1523 to 9022 byte packets");
9197 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9198 "stat_XonPauseFramesReceived",
9199 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
9200 0, "XON pause frames receved");
9202 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9203 "stat_XoffPauseFramesReceived",
9204 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
9205 0, "XOFF pause frames received");
9207 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9209 CTLFLAG_RD, &sc->stat_OutXonSent,
9210 0, "XON pause frames sent");
9212 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9214 CTLFLAG_RD, &sc->stat_OutXoffSent,
9215 0, "XOFF pause frames sent");
9217 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9218 "stat_FlowControlDone",
9219 CTLFLAG_RD, &sc->stat_FlowControlDone,
9220 0, "Flow control done");
9222 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9223 "stat_MacControlFramesReceived",
9224 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
9225 0, "MAC control frames received");
9227 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9228 "stat_XoffStateEntered",
9229 CTLFLAG_RD, &sc->stat_XoffStateEntered,
9230 0, "XOFF state entered");
9232 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9233 "stat_IfInFramesL2FilterDiscards",
9234 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
9235 0, "Received L2 packets discarded");
9237 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9238 "stat_IfInRuleCheckerDiscards",
9239 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
9240 0, "Received packets discarded by rule");
9242 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9243 "stat_IfInFTQDiscards",
9244 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
9245 0, "Received packet FTQ discards");
9247 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9248 "stat_IfInMBUFDiscards",
9249 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
9250 0, "Received packets discarded due to lack "
9251 "of controller buffer memory");
9253 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9254 "stat_IfInRuleCheckerP4Hit",
9255 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
9256 0, "Received packets rule checker hits");
9258 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9259 "stat_CatchupInRuleCheckerDiscards",
9260 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
9261 0, "Received packets discarded in Catchup path");
9263 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9264 "stat_CatchupInFTQDiscards",
9265 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
9266 0, "Received packets discarded in FTQ in Catchup path");
9268 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9269 "stat_CatchupInMBUFDiscards",
9270 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
9271 0, "Received packets discarded in controller "
9272 "buffer memory in Catchup path");
9274 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9275 "stat_CatchupInRuleCheckerP4Hit",
9276 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
9277 0, "Received packets rule checker hits in Catchup path");
9279 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9281 CTLFLAG_RD, &sc->com_no_buffers,
9282 0, "Valid packets received but no RX buffers available");
9285 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9286 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
9288 bce_sysctl_driver_state, "I", "Drive state information");
9290 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9291 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
9293 bce_sysctl_hw_state, "I", "Hardware state information");
9295 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9296 "status_block", CTLTYPE_INT | CTLFLAG_RW,
9298 bce_sysctl_status_block, "I", "Dump status block");
9300 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9301 "stats_block", CTLTYPE_INT | CTLFLAG_RW,
9303 bce_sysctl_stats_block, "I", "Dump statistics block");
9305 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9306 "stats_clear", CTLTYPE_INT | CTLFLAG_RW,
9308 bce_sysctl_stats_clear, "I", "Clear statistics block");
9310 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9311 "shmem_state", CTLTYPE_INT | CTLFLAG_RW,
9313 bce_sysctl_shmem_state, "I", "Shared memory state information");
9315 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9316 "bc_state", CTLTYPE_INT | CTLFLAG_RW,
9318 bce_sysctl_bc_state, "I", "Bootcode state information");
9320 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9321 "dump_rx_bd_chain", CTLTYPE_INT | CTLFLAG_RW,
9323 bce_sysctl_dump_rx_bd_chain, "I", "Dump RX BD chain");
9325 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9326 "dump_rx_mbuf_chain", CTLTYPE_INT | CTLFLAG_RW,
9328 bce_sysctl_dump_rx_mbuf_chain, "I", "Dump RX MBUF chain");
9330 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9331 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
9333 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
9335 if (bce_hdr_split == TRUE) {
9336 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9337 "dump_pg_chain", CTLTYPE_INT | CTLFLAG_RW,
9339 bce_sysctl_dump_pg_chain, "I", "Dump page chain");
9342 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9343 "dump_ctx", CTLTYPE_INT | CTLFLAG_RW,
9345 bce_sysctl_dump_ctx, "I", "Dump context memory");
9347 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9348 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
9350 bce_sysctl_breakpoint, "I", "Driver breakpoint");
9352 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9353 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
9355 bce_sysctl_reg_read, "I", "Register read");
9357 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9358 "nvram_read", CTLTYPE_INT | CTLFLAG_RW,
9360 bce_sysctl_nvram_read, "I", "NVRAM read");
9362 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9363 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
9365 bce_sysctl_phy_read, "I", "PHY register read");
9369 DBEXIT(BCE_VERBOSE_MISC);
9373 /****************************************************************************/
9374 /* BCE Debug Routines */
9375 /****************************************************************************/
9378 /****************************************************************************/
9379 /* Freezes the controller to allow for a cohesive state dump. */
9383 /****************************************************************************/
9384 static __attribute__ ((noinline)) void
9385 bce_freeze_controller(struct bce_softc *sc)
9388 val = REG_RD(sc, BCE_MISC_COMMAND);
9389 val |= BCE_MISC_COMMAND_DISABLE_ALL;
9390 REG_WR(sc, BCE_MISC_COMMAND, val);
9394 /****************************************************************************/
9395 /* Unfreezes the controller after a freeze operation. This may not always */
9396 /* work and the controller will require a reset! */
9400 /****************************************************************************/
9401 static __attribute__ ((noinline)) void
9402 bce_unfreeze_controller(struct bce_softc *sc)
9405 val = REG_RD(sc, BCE_MISC_COMMAND);
9406 val |= BCE_MISC_COMMAND_ENABLE_ALL;
9407 REG_WR(sc, BCE_MISC_COMMAND, val);
9411 /****************************************************************************/
9412 /* Prints out Ethernet frame information from an mbuf. */
9414 /* Partially decode an Ethernet frame to look at some important headers. */
9418 /****************************************************************************/
9419 static __attribute__ ((noinline)) void
9420 bce_dump_enet(struct bce_softc *sc, struct mbuf *m)
9422 struct ether_vlan_header *eh;
9431 "-----------------------------"
9433 "-----------------------------\n");
9435 eh = mtod(m, struct ether_vlan_header *);
9437 /* Handle VLAN encapsulation if present. */
9438 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
9439 etype = ntohs(eh->evl_proto);
9440 ehlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
9442 etype = ntohs(eh->evl_encap_proto);
9443 ehlen = ETHER_HDR_LEN;
9446 /* ToDo: Add VLAN output. */
9447 BCE_PRINTF("enet: dest = %6D, src = %6D, type = 0x%04X, hlen = %d\n",
9448 eh->evl_dhost, ":", eh->evl_shost, ":", etype, ehlen);
9452 ip = (struct ip *)(m->m_data + ehlen);
9453 BCE_PRINTF("--ip: dest = 0x%08X , src = 0x%08X, "
9454 "len = %d bytes, protocol = 0x%02X, xsum = 0x%04X\n",
9455 ntohl(ip->ip_dst.s_addr), ntohl(ip->ip_src.s_addr),
9456 ntohs(ip->ip_len), ip->ip_p, ntohs(ip->ip_sum));
9460 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
9461 BCE_PRINTF("-tcp: dest = %d, src = %d, hlen = "
9462 "%d bytes, flags = 0x%b, csum = 0x%04X\n",
9463 ntohs(th->th_dport), ntohs(th->th_sport),
9464 (th->th_off << 2), th->th_flags,
9465 "\20\10CWR\07ECE\06URG\05ACK\04PSH\03RST"
9466 "\02SYN\01FIN", ntohs(th->th_sum));
9469 uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
9470 BCE_PRINTF("-udp: dest = %d, src = %d, len = %d "
9471 "bytes, csum = 0x%04X\n", ntohs(uh->uh_dport),
9472 ntohs(uh->uh_sport), ntohs(uh->uh_ulen),
9476 BCE_PRINTF("icmp:\n");
9479 BCE_PRINTF("----: Other IP protocol.\n");
9482 case ETHERTYPE_IPV6:
9483 BCE_PRINTF("ipv6: No decode supported.\n");
9486 BCE_PRINTF("-arp: ");
9487 ah = (struct arphdr *) (m->m_data + ehlen);
9488 switch (ntohs(ah->ar_op)) {
9489 case ARPOP_REVREQUEST:
9490 printf("reverse ARP request\n");
9492 case ARPOP_REVREPLY:
9493 printf("reverse ARP reply\n");
9496 printf("ARP request\n");
9499 printf("ARP reply\n");
9502 printf("other ARP operation\n");
9506 BCE_PRINTF("----: Other protocol.\n");
9510 "-----------------------------"
9512 "-----------------------------\n");
9516 /****************************************************************************/
9517 /* Prints out information about an mbuf. */
9521 /****************************************************************************/
9522 static __attribute__ ((noinline)) void
9523 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
9525 struct mbuf *mp = m;
9528 BCE_PRINTF("mbuf: null pointer\n");
9533 BCE_PRINTF("mbuf: %p, m_len = %d, m_flags = 0x%b, "
9534 "m_data = %p\n", mp, mp->m_len, mp->m_flags,
9535 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", mp->m_data);
9537 if (mp->m_flags & M_PKTHDR) {
9538 BCE_PRINTF("- m_pkthdr: len = %d, flags = 0x%b, "
9539 "csum_flags = %b\n", mp->m_pkthdr.len,
9540 mp->m_flags, "\20\12M_BCAST\13M_MCAST\14M_FRAG"
9541 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
9542 "\22M_PROMISC\23M_NOFREE",
9543 mp->m_pkthdr.csum_flags,
9544 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
9545 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
9546 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
9547 "\14CSUM_PSEUDO_HDR");
9550 if (mp->m_flags & M_EXT) {
9551 BCE_PRINTF("- m_ext: %p, ext_size = %d, type = ",
9552 mp->m_ext.ext_buf, mp->m_ext.ext_size);
9553 switch (mp->m_ext.ext_type) {
9555 printf("EXT_CLUSTER\n"); break;
9557 printf("EXT_SFBUF\n"); break;
9559 printf("EXT_JUMBO9\n"); break;
9561 printf("EXT_JUMBO16\n"); break;
9563 printf("EXT_PACKET\n"); break;
9565 printf("EXT_MBUF\n"); break;
9567 printf("EXT_NET_DRV\n"); break;
9569 printf("EXT_MDD_TYPE\n"); break;
9570 case EXT_DISPOSABLE:
9571 printf("EXT_DISPOSABLE\n"); break;
9573 printf("EXT_EXTREF\n"); break;
9575 printf("UNKNOWN\n");
9584 /****************************************************************************/
9585 /* Prints out the mbufs in the TX mbuf chain. */
9589 /****************************************************************************/
9590 static __attribute__ ((noinline)) void
9591 bce_dump_tx_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9596 "----------------------------"
9598 "----------------------------\n");
9600 for (int i = 0; i < count; i++) {
9601 m = sc->tx_mbuf_ptr[chain_prod];
9602 BCE_PRINTF("txmbuf[0x%04X]\n", chain_prod);
9603 bce_dump_mbuf(sc, m);
9604 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
9608 "----------------------------"
9610 "----------------------------\n");
9614 /****************************************************************************/
9615 /* Prints out the mbufs in the RX mbuf chain. */
9619 /****************************************************************************/
9620 static __attribute__ ((noinline)) void
9621 bce_dump_rx_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9626 "----------------------------"
9628 "----------------------------\n");
9630 for (int i = 0; i < count; i++) {
9631 m = sc->rx_mbuf_ptr[chain_prod];
9632 BCE_PRINTF("rxmbuf[0x%04X]\n", chain_prod);
9633 bce_dump_mbuf(sc, m);
9634 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
9639 "----------------------------"
9641 "----------------------------\n");
9645 /****************************************************************************/
9646 /* Prints out the mbufs in the mbuf page chain. */
9650 /****************************************************************************/
9651 static __attribute__ ((noinline)) void
9652 bce_dump_pg_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9657 "----------------------------"
9659 "----------------------------\n");
9661 for (int i = 0; i < count; i++) {
9662 m = sc->pg_mbuf_ptr[chain_prod];
9663 BCE_PRINTF("pgmbuf[0x%04X]\n", chain_prod);
9664 bce_dump_mbuf(sc, m);
9665 chain_prod = PG_CHAIN_IDX(NEXT_PG_BD(chain_prod));
9670 "----------------------------"
9672 "----------------------------\n");
9676 /****************************************************************************/
9677 /* Prints out a tx_bd structure. */
9681 /****************************************************************************/
9682 static __attribute__ ((noinline)) void
9683 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
9687 if (idx > MAX_TX_BD_ALLOC)
9688 /* Index out of range. */
9689 BCE_PRINTF("tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
9690 else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
9691 /* TX Chain page pointer. */
9692 BCE_PRINTF("tx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
9693 "pointer\n", idx, txbd->tx_bd_haddr_hi,
9694 txbd->tx_bd_haddr_lo);
9696 /* Normal tx_bd entry. */
9697 BCE_PRINTF("tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
9698 "mss_nbytes = 0x%08X, vlan tag = 0x%04X, flags = "
9699 "0x%04X (", idx, txbd->tx_bd_haddr_hi,
9700 txbd->tx_bd_haddr_lo, txbd->tx_bd_mss_nbytes,
9701 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
9703 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT) {
9706 printf("CONN_FAULT");
9710 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM) {
9713 printf("TCP_UDP_CKSUM");
9717 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM) {
9724 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG) {
9731 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW) {
9738 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC) {
9741 printf("DONT_GEN_CRC");
9745 if (txbd->tx_bd_flags & TX_BD_FLAGS_START) {
9752 if (txbd->tx_bd_flags & TX_BD_FLAGS_END) {
9759 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO) {
9766 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD) {
9769 printf("SW_OPTION=%d", ((txbd->tx_bd_flags &
9770 TX_BD_FLAGS_SW_OPTION_WORD) >> 8)); i++;
9773 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS) {
9780 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP) {
9791 /****************************************************************************/
9792 /* Prints out a rx_bd structure. */
9796 /****************************************************************************/
9797 static __attribute__ ((noinline)) void
9798 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
9800 if (idx > MAX_RX_BD_ALLOC)
9801 /* Index out of range. */
9802 BCE_PRINTF("rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
9803 else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
9804 /* RX Chain page pointer. */
9805 BCE_PRINTF("rx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
9806 "pointer\n", idx, rxbd->rx_bd_haddr_hi,
9807 rxbd->rx_bd_haddr_lo);
9809 /* Normal rx_bd entry. */
9810 BCE_PRINTF("rx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = "
9811 "0x%08X, flags = 0x%08X\n", idx, rxbd->rx_bd_haddr_hi,
9812 rxbd->rx_bd_haddr_lo, rxbd->rx_bd_len,
9817 /****************************************************************************/
9818 /* Prints out a rx_bd structure in the page chain. */
9822 /****************************************************************************/
9823 static __attribute__ ((noinline)) void
9824 bce_dump_pgbd(struct bce_softc *sc, int idx, struct rx_bd *pgbd)
9826 if (idx > MAX_PG_BD_ALLOC)
9827 /* Index out of range. */
9828 BCE_PRINTF("pg_bd[0x%04X]: Invalid pg_bd index!\n", idx);
9829 else if ((idx & USABLE_PG_BD_PER_PAGE) == USABLE_PG_BD_PER_PAGE)
9830 /* Page Chain page pointer. */
9831 BCE_PRINTF("px_bd[0x%04X]: haddr = 0x%08X:%08X, chain page pointer\n",
9832 idx, pgbd->rx_bd_haddr_hi, pgbd->rx_bd_haddr_lo);
9834 /* Normal rx_bd entry. */
9835 BCE_PRINTF("pg_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = 0x%08X, "
9836 "flags = 0x%08X\n", idx,
9837 pgbd->rx_bd_haddr_hi, pgbd->rx_bd_haddr_lo,
9838 pgbd->rx_bd_len, pgbd->rx_bd_flags);
9842 /****************************************************************************/
9843 /* Prints out a l2_fhdr structure. */
9847 /****************************************************************************/
9848 static __attribute__ ((noinline)) void
9849 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
9851 BCE_PRINTF("l2_fhdr[0x%04X]: status = 0x%b, "
9852 "pkt_len = %d, vlan = 0x%04x, ip_xsum/hdr_len = 0x%04X, "
9853 "tcp_udp_xsum = 0x%04X\n", idx,
9854 l2fhdr->l2_fhdr_status, BCE_L2FHDR_PRINTFB,
9855 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
9856 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
9860 /****************************************************************************/
9861 /* Prints out context memory info. (Only useful for CID 0 to 16.) */
9865 /****************************************************************************/
9866 static __attribute__ ((noinline)) void
9867 bce_dump_ctx(struct bce_softc *sc, u16 cid)
9870 BCE_PRINTF(" Unknown CID\n");
9875 "----------------------------"
9877 "----------------------------\n");
9879 BCE_PRINTF(" 0x%04X - (CID) Context ID\n", cid);
9881 if (cid == RX_CID) {
9882 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_BDIDX) host rx "
9884 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_HOST_BDIDX));
9885 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_BSEQ) host "
9886 "byte sequence\n", CTX_RD(sc, GET_CID_ADDR(cid),
9887 BCE_L2CTX_RX_HOST_BSEQ));
9888 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BSEQ) h/w byte sequence\n",
9889 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BSEQ));
9890 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDHADDR_HI) h/w buffer "
9891 "descriptor address\n",
9892 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BDHADDR_HI));
9893 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDHADDR_LO) h/w buffer "
9894 "descriptor address\n",
9895 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BDHADDR_LO));
9896 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDIDX) h/w rx consumer "
9897 "index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9898 BCE_L2CTX_RX_NX_BDIDX));
9899 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_PG_BDIDX) host page "
9900 "producer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9901 BCE_L2CTX_RX_HOST_PG_BDIDX));
9902 BCE_PRINTF(" 0x%08X - (L2CTX_RX_PG_BUF_SIZE) host rx_bd/page "
9903 "buffer size\n", CTX_RD(sc, GET_CID_ADDR(cid),
9904 BCE_L2CTX_RX_PG_BUF_SIZE));
9905 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDHADDR_HI) h/w page "
9906 "chain address\n", CTX_RD(sc, GET_CID_ADDR(cid),
9907 BCE_L2CTX_RX_NX_PG_BDHADDR_HI));
9908 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDHADDR_LO) h/w page "
9909 "chain address\n", CTX_RD(sc, GET_CID_ADDR(cid),
9910 BCE_L2CTX_RX_NX_PG_BDHADDR_LO));
9911 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDIDX) h/w page "
9912 "consumer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9913 BCE_L2CTX_RX_NX_PG_BDIDX));
9914 } else if (cid == TX_CID) {
9915 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
9916 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
9917 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TYPE_XI) ctx type\n",
9918 CTX_RD(sc, GET_CID_ADDR(cid),
9919 BCE_L2CTX_TX_TYPE_XI));
9920 BCE_PRINTF(" 0x%08X - (L2CTX_CMD_TX_TYPE_XI) ctx "
9921 "cmd\n", CTX_RD(sc, GET_CID_ADDR(cid),
9922 BCE_L2CTX_TX_CMD_TYPE_XI));
9923 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BDHADDR_HI_XI) "
9924 "h/w buffer descriptor address\n",
9925 CTX_RD(sc, GET_CID_ADDR(cid),
9926 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI));
9927 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BHADDR_LO_XI) "
9928 "h/w buffer descriptor address\n",
9929 CTX_RD(sc, GET_CID_ADDR(cid),
9930 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI));
9931 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BIDX_XI) "
9932 "host producer index\n",
9933 CTX_RD(sc, GET_CID_ADDR(cid),
9934 BCE_L2CTX_TX_HOST_BIDX_XI));
9935 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BSEQ_XI) "
9936 "host byte sequence\n",
9937 CTX_RD(sc, GET_CID_ADDR(cid),
9938 BCE_L2CTX_TX_HOST_BSEQ_XI));
9940 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TYPE) ctx type\n",
9941 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_TX_TYPE));
9942 BCE_PRINTF(" 0x%08X - (L2CTX_TX_CMD_TYPE) ctx cmd\n",
9943 CTX_RD(sc, GET_CID_ADDR(cid),
9944 BCE_L2CTX_TX_CMD_TYPE));
9945 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BDHADDR_HI) "
9946 "h/w buffer descriptor address\n",
9947 CTX_RD(sc, GET_CID_ADDR(cid),
9948 BCE_L2CTX_TX_TBDR_BHADDR_HI));
9949 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BHADDR_LO) "
9950 "h/w buffer descriptor address\n",
9951 CTX_RD(sc, GET_CID_ADDR(cid),
9952 BCE_L2CTX_TX_TBDR_BHADDR_LO));
9953 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BIDX) host "
9954 "producer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
9955 BCE_L2CTX_TX_HOST_BIDX));
9956 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BSEQ) host byte "
9957 "sequence\n", CTX_RD(sc, GET_CID_ADDR(cid),
9958 BCE_L2CTX_TX_HOST_BSEQ));
9963 "----------------------------"
9965 "----------------------------\n");
9967 for (int i = 0x0; i < 0x300; i += 0x10) {
9968 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
9969 CTX_RD(sc, GET_CID_ADDR(cid), i),
9970 CTX_RD(sc, GET_CID_ADDR(cid), i + 0x4),
9971 CTX_RD(sc, GET_CID_ADDR(cid), i + 0x8),
9972 CTX_RD(sc, GET_CID_ADDR(cid), i + 0xc));
9977 "----------------------------"
9979 "----------------------------\n");
9983 /****************************************************************************/
9984 /* Prints out the FTQ data. */
9988 /****************************************************************************/
9989 static __attribute__ ((noinline)) void
9990 bce_dump_ftqs(struct bce_softc *sc)
9992 u32 cmd, ctl, cur_depth, max_depth, valid_cnt, val;
9995 "----------------------------"
9997 "----------------------------\n");
9999 BCE_PRINTF(" FTQ Command Control Depth_Now "
10000 "Max_Depth Valid_Cnt \n");
10001 BCE_PRINTF(" ------- ---------- ---------- ---------- "
10002 "---------- ----------\n");
10004 /* Setup the generic statistic counters for the FTQ valid count. */
10005 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PPQ_VALID_CNT << 24) |
10006 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RXPCQ_VALID_CNT << 16) |
10007 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RXPQ_VALID_CNT << 8) |
10008 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RLUPQ_VALID_CNT);
10009 REG_WR(sc, BCE_HC_STAT_GEN_SEL_0, val);
10011 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TSCHQ_VALID_CNT << 24) |
10012 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RDMAQ_VALID_CNT << 16) |
10013 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PTQ_VALID_CNT << 8) |
10014 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PMQ_VALID_CNT);
10015 REG_WR(sc, BCE_HC_STAT_GEN_SEL_1, val);
10017 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TPATQ_VALID_CNT << 24) |
10018 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TDMAQ_VALID_CNT << 16) |
10019 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TXPQ_VALID_CNT << 8) |
10020 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TBDRQ_VALID_CNT);
10021 REG_WR(sc, BCE_HC_STAT_GEN_SEL_2, val);
10023 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMQ_VALID_CNT << 24) |
10024 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMTQ_VALID_CNT << 16) |
10025 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMXQ_VALID_CNT << 8) |
10026 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TASQ_VALID_CNT);
10027 REG_WR(sc, BCE_HC_STAT_GEN_SEL_3, val);
10029 /* Input queue to the Receive Lookup state machine */
10030 cmd = REG_RD(sc, BCE_RLUP_FTQ_CMD);
10031 ctl = REG_RD(sc, BCE_RLUP_FTQ_CTL);
10032 cur_depth = (ctl & BCE_RLUP_FTQ_CTL_CUR_DEPTH) >> 22;
10033 max_depth = (ctl & BCE_RLUP_FTQ_CTL_MAX_DEPTH) >> 12;
10034 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT0);
10035 BCE_PRINTF(" RLUP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10036 cmd, ctl, cur_depth, max_depth, valid_cnt);
10038 /* Input queue to the Receive Processor */
10039 cmd = REG_RD_IND(sc, BCE_RXP_FTQ_CMD);
10040 ctl = REG_RD_IND(sc, BCE_RXP_FTQ_CTL);
10041 cur_depth = (ctl & BCE_RXP_FTQ_CTL_CUR_DEPTH) >> 22;
10042 max_depth = (ctl & BCE_RXP_FTQ_CTL_MAX_DEPTH) >> 12;
10043 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT1);
10044 BCE_PRINTF(" RXP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10045 cmd, ctl, cur_depth, max_depth, valid_cnt);
10047 /* Input queue to the Recevie Processor */
10048 cmd = REG_RD_IND(sc, BCE_RXP_CFTQ_CMD);
10049 ctl = REG_RD_IND(sc, BCE_RXP_CFTQ_CTL);
10050 cur_depth = (ctl & BCE_RXP_CFTQ_CTL_CUR_DEPTH) >> 22;
10051 max_depth = (ctl & BCE_RXP_CFTQ_CTL_MAX_DEPTH) >> 12;
10052 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT2);
10053 BCE_PRINTF(" RXPC 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10054 cmd, ctl, cur_depth, max_depth, valid_cnt);
10056 /* Input queue to the Receive Virtual to Physical state machine */
10057 cmd = REG_RD(sc, BCE_RV2P_PFTQ_CMD);
10058 ctl = REG_RD(sc, BCE_RV2P_PFTQ_CTL);
10059 cur_depth = (ctl & BCE_RV2P_PFTQ_CTL_CUR_DEPTH) >> 22;
10060 max_depth = (ctl & BCE_RV2P_PFTQ_CTL_MAX_DEPTH) >> 12;
10061 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT3);
10062 BCE_PRINTF(" RV2PP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10063 cmd, ctl, cur_depth, max_depth, valid_cnt);
10065 /* Input queue to the Recevie Virtual to Physical state machine */
10066 cmd = REG_RD(sc, BCE_RV2P_MFTQ_CMD);
10067 ctl = REG_RD(sc, BCE_RV2P_MFTQ_CTL);
10068 cur_depth = (ctl & BCE_RV2P_MFTQ_CTL_CUR_DEPTH) >> 22;
10069 max_depth = (ctl & BCE_RV2P_MFTQ_CTL_MAX_DEPTH) >> 12;
10070 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT4);
10071 BCE_PRINTF(" RV2PM 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10072 cmd, ctl, cur_depth, max_depth, valid_cnt);
10074 /* Input queue to the Receive Virtual to Physical state machine */
10075 cmd = REG_RD(sc, BCE_RV2P_TFTQ_CMD);
10076 ctl = REG_RD(sc, BCE_RV2P_TFTQ_CTL);
10077 cur_depth = (ctl & BCE_RV2P_TFTQ_CTL_CUR_DEPTH) >> 22;
10078 max_depth = (ctl & BCE_RV2P_TFTQ_CTL_MAX_DEPTH) >> 12;
10079 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT5);
10080 BCE_PRINTF(" RV2PT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10081 cmd, ctl, cur_depth, max_depth, valid_cnt);
10083 /* Input queue to the Receive DMA state machine */
10084 cmd = REG_RD(sc, BCE_RDMA_FTQ_CMD);
10085 ctl = REG_RD(sc, BCE_RDMA_FTQ_CTL);
10086 cur_depth = (ctl & BCE_RDMA_FTQ_CTL_CUR_DEPTH) >> 22;
10087 max_depth = (ctl & BCE_RDMA_FTQ_CTL_MAX_DEPTH) >> 12;
10088 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT6);
10089 BCE_PRINTF(" RDMA 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10090 cmd, ctl, cur_depth, max_depth, valid_cnt);
10092 /* Input queue to the Transmit Scheduler state machine */
10093 cmd = REG_RD(sc, BCE_TSCH_FTQ_CMD);
10094 ctl = REG_RD(sc, BCE_TSCH_FTQ_CTL);
10095 cur_depth = (ctl & BCE_TSCH_FTQ_CTL_CUR_DEPTH) >> 22;
10096 max_depth = (ctl & BCE_TSCH_FTQ_CTL_MAX_DEPTH) >> 12;
10097 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT7);
10098 BCE_PRINTF(" TSCH 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10099 cmd, ctl, cur_depth, max_depth, valid_cnt);
10101 /* Input queue to the Transmit Buffer Descriptor state machine */
10102 cmd = REG_RD(sc, BCE_TBDR_FTQ_CMD);
10103 ctl = REG_RD(sc, BCE_TBDR_FTQ_CTL);
10104 cur_depth = (ctl & BCE_TBDR_FTQ_CTL_CUR_DEPTH) >> 22;
10105 max_depth = (ctl & BCE_TBDR_FTQ_CTL_MAX_DEPTH) >> 12;
10106 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT8);
10107 BCE_PRINTF(" TBDR 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10108 cmd, ctl, cur_depth, max_depth, valid_cnt);
10110 /* Input queue to the Transmit Processor */
10111 cmd = REG_RD_IND(sc, BCE_TXP_FTQ_CMD);
10112 ctl = REG_RD_IND(sc, BCE_TXP_FTQ_CTL);
10113 cur_depth = (ctl & BCE_TXP_FTQ_CTL_CUR_DEPTH) >> 22;
10114 max_depth = (ctl & BCE_TXP_FTQ_CTL_MAX_DEPTH) >> 12;
10115 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT9);
10116 BCE_PRINTF(" TXP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10117 cmd, ctl, cur_depth, max_depth, valid_cnt);
10119 /* Input queue to the Transmit DMA state machine */
10120 cmd = REG_RD(sc, BCE_TDMA_FTQ_CMD);
10121 ctl = REG_RD(sc, BCE_TDMA_FTQ_CTL);
10122 cur_depth = (ctl & BCE_TDMA_FTQ_CTL_CUR_DEPTH) >> 22;
10123 max_depth = (ctl & BCE_TDMA_FTQ_CTL_MAX_DEPTH) >> 12;
10124 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT10);
10125 BCE_PRINTF(" TDMA 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10126 cmd, ctl, cur_depth, max_depth, valid_cnt);
10128 /* Input queue to the Transmit Patch-Up Processor */
10129 cmd = REG_RD_IND(sc, BCE_TPAT_FTQ_CMD);
10130 ctl = REG_RD_IND(sc, BCE_TPAT_FTQ_CTL);
10131 cur_depth = (ctl & BCE_TPAT_FTQ_CTL_CUR_DEPTH) >> 22;
10132 max_depth = (ctl & BCE_TPAT_FTQ_CTL_MAX_DEPTH) >> 12;
10133 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT11);
10134 BCE_PRINTF(" TPAT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10135 cmd, ctl, cur_depth, max_depth, valid_cnt);
10137 /* Input queue to the Transmit Assembler state machine */
10138 cmd = REG_RD_IND(sc, BCE_TAS_FTQ_CMD);
10139 ctl = REG_RD_IND(sc, BCE_TAS_FTQ_CTL);
10140 cur_depth = (ctl & BCE_TAS_FTQ_CTL_CUR_DEPTH) >> 22;
10141 max_depth = (ctl & BCE_TAS_FTQ_CTL_MAX_DEPTH) >> 12;
10142 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT12);
10143 BCE_PRINTF(" TAS 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10144 cmd, ctl, cur_depth, max_depth, valid_cnt);
10146 /* Input queue to the Completion Processor */
10147 cmd = REG_RD_IND(sc, BCE_COM_COMXQ_FTQ_CMD);
10148 ctl = REG_RD_IND(sc, BCE_COM_COMXQ_FTQ_CTL);
10149 cur_depth = (ctl & BCE_COM_COMXQ_FTQ_CTL_CUR_DEPTH) >> 22;
10150 max_depth = (ctl & BCE_COM_COMXQ_FTQ_CTL_MAX_DEPTH) >> 12;
10151 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT13);
10152 BCE_PRINTF(" COMX 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10153 cmd, ctl, cur_depth, max_depth, valid_cnt);
10155 /* Input queue to the Completion Processor */
10156 cmd = REG_RD_IND(sc, BCE_COM_COMTQ_FTQ_CMD);
10157 ctl = REG_RD_IND(sc, BCE_COM_COMTQ_FTQ_CTL);
10158 cur_depth = (ctl & BCE_COM_COMTQ_FTQ_CTL_CUR_DEPTH) >> 22;
10159 max_depth = (ctl & BCE_COM_COMTQ_FTQ_CTL_MAX_DEPTH) >> 12;
10160 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT14);
10161 BCE_PRINTF(" COMT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10162 cmd, ctl, cur_depth, max_depth, valid_cnt);
10164 /* Input queue to the Completion Processor */
10165 cmd = REG_RD_IND(sc, BCE_COM_COMQ_FTQ_CMD);
10166 ctl = REG_RD_IND(sc, BCE_COM_COMQ_FTQ_CTL);
10167 cur_depth = (ctl & BCE_COM_COMQ_FTQ_CTL_CUR_DEPTH) >> 22;
10168 max_depth = (ctl & BCE_COM_COMQ_FTQ_CTL_MAX_DEPTH) >> 12;
10169 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT15);
10170 BCE_PRINTF(" COMX 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10171 cmd, ctl, cur_depth, max_depth, valid_cnt);
10173 /* Setup the generic statistic counters for the FTQ valid count. */
10174 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_CSQ_VALID_CNT << 16) |
10175 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_CPQ_VALID_CNT << 8) |
10176 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_MGMQ_VALID_CNT);
10178 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
10179 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716))
10181 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PCSQ_VALID_CNT_XI <<
10183 REG_WR(sc, BCE_HC_STAT_GEN_SEL_0, val);
10185 /* Input queue to the Management Control Processor */
10186 cmd = REG_RD_IND(sc, BCE_MCP_MCPQ_FTQ_CMD);
10187 ctl = REG_RD_IND(sc, BCE_MCP_MCPQ_FTQ_CTL);
10188 cur_depth = (ctl & BCE_MCP_MCPQ_FTQ_CTL_CUR_DEPTH) >> 22;
10189 max_depth = (ctl & BCE_MCP_MCPQ_FTQ_CTL_MAX_DEPTH) >> 12;
10190 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT0);
10191 BCE_PRINTF(" MCP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10192 cmd, ctl, cur_depth, max_depth, valid_cnt);
10194 /* Input queue to the Command Processor */
10195 cmd = REG_RD_IND(sc, BCE_CP_CPQ_FTQ_CMD);
10196 ctl = REG_RD_IND(sc, BCE_CP_CPQ_FTQ_CTL);
10197 cur_depth = (ctl & BCE_CP_CPQ_FTQ_CTL_CUR_DEPTH) >> 22;
10198 max_depth = (ctl & BCE_CP_CPQ_FTQ_CTL_MAX_DEPTH) >> 12;
10199 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT1);
10200 BCE_PRINTF(" CP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10201 cmd, ctl, cur_depth, max_depth, valid_cnt);
10203 /* Input queue to the Completion Scheduler state machine */
10204 cmd = REG_RD(sc, BCE_CSCH_CH_FTQ_CMD);
10205 ctl = REG_RD(sc, BCE_CSCH_CH_FTQ_CTL);
10206 cur_depth = (ctl & BCE_CSCH_CH_FTQ_CTL_CUR_DEPTH) >> 22;
10207 max_depth = (ctl & BCE_CSCH_CH_FTQ_CTL_MAX_DEPTH) >> 12;
10208 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT2);
10209 BCE_PRINTF(" CS 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10210 cmd, ctl, cur_depth, max_depth, valid_cnt);
10212 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) ||
10213 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716)) {
10214 /* Input queue to the RV2P Command Scheduler */
10215 cmd = REG_RD(sc, BCE_RV2PCSR_FTQ_CMD);
10216 ctl = REG_RD(sc, BCE_RV2PCSR_FTQ_CTL);
10217 cur_depth = (ctl & 0xFFC00000) >> 22;
10218 max_depth = (ctl & 0x003FF000) >> 12;
10219 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT3);
10220 BCE_PRINTF(" RV2PCSR 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10221 cmd, ctl, cur_depth, max_depth, valid_cnt);
10225 "----------------------------"
10227 "----------------------------\n");
10231 /****************************************************************************/
10232 /* Prints out the TX chain. */
10236 /****************************************************************************/
10237 static __attribute__ ((noinline)) void
10238 bce_dump_tx_chain(struct bce_softc *sc, u16 tx_prod, int count)
10240 struct tx_bd *txbd;
10242 /* First some info about the tx_bd chain structure. */
10244 "----------------------------"
10246 "----------------------------\n");
10248 BCE_PRINTF("page size = 0x%08X, tx chain pages = 0x%08X\n",
10249 (u32) BCM_PAGE_SIZE, (u32) sc->tx_pages);
10250 BCE_PRINTF("tx_bd per page = 0x%08X, usable tx_bd per page = 0x%08X\n",
10251 (u32) TOTAL_TX_BD_PER_PAGE, (u32) USABLE_TX_BD_PER_PAGE);
10252 BCE_PRINTF("total tx_bd = 0x%08X\n", (u32) TOTAL_TX_BD_ALLOC);
10255 "----------------------------"
10257 "----------------------------\n");
10259 /* Now print out a decoded list of TX buffer descriptors. */
10260 for (int i = 0; i < count; i++) {
10261 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
10262 bce_dump_txbd(sc, tx_prod, txbd);
10267 "----------------------------"
10269 "----------------------------\n");
10273 /****************************************************************************/
10274 /* Prints out the RX chain. */
10278 /****************************************************************************/
10279 static __attribute__ ((noinline)) void
10280 bce_dump_rx_bd_chain(struct bce_softc *sc, u16 rx_prod, int count)
10282 struct rx_bd *rxbd;
10284 /* First some info about the rx_bd chain structure. */
10286 "----------------------------"
10288 "----------------------------\n");
10290 BCE_PRINTF("page size = 0x%08X, rx chain pages = 0x%08X\n",
10291 (u32) BCM_PAGE_SIZE, (u32) sc->rx_pages);
10293 BCE_PRINTF("rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
10294 (u32) TOTAL_RX_BD_PER_PAGE, (u32) USABLE_RX_BD_PER_PAGE);
10296 BCE_PRINTF("total rx_bd = 0x%08X\n", (u32) TOTAL_RX_BD_ALLOC);
10299 "----------------------------"
10301 "----------------------------\n");
10303 /* Now print out the rx_bd's themselves. */
10304 for (int i = 0; i < count; i++) {
10305 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
10306 bce_dump_rxbd(sc, rx_prod, rxbd);
10307 rx_prod = RX_CHAIN_IDX(rx_prod + 1);
10311 "----------------------------"
10313 "----------------------------\n");
10317 /****************************************************************************/
10318 /* Prints out the page chain. */
10322 /****************************************************************************/
10323 static __attribute__ ((noinline)) void
10324 bce_dump_pg_chain(struct bce_softc *sc, u16 pg_prod, int count)
10326 struct rx_bd *pgbd;
10328 /* First some info about the page chain structure. */
10330 "----------------------------"
10332 "----------------------------\n");
10334 BCE_PRINTF("page size = 0x%08X, pg chain pages = 0x%08X\n",
10335 (u32) BCM_PAGE_SIZE, (u32) sc->pg_pages);
10337 BCE_PRINTF("rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
10338 (u32) TOTAL_PG_BD_PER_PAGE, (u32) USABLE_PG_BD_PER_PAGE);
10340 BCE_PRINTF("total pg_bd = 0x%08X\n", (u32) TOTAL_PG_BD_ALLOC);
10343 "----------------------------"
10345 "----------------------------\n");
10347 /* Now print out the rx_bd's themselves. */
10348 for (int i = 0; i < count; i++) {
10349 pgbd = &sc->pg_bd_chain[PG_PAGE(pg_prod)][PG_IDX(pg_prod)];
10350 bce_dump_pgbd(sc, pg_prod, pgbd);
10351 pg_prod = PG_CHAIN_IDX(pg_prod + 1);
10355 "----------------------------"
10357 "----------------------------\n");
10361 #define BCE_PRINT_RX_CONS(arg) \
10362 if (sblk->status_rx_quick_consumer_index##arg) \
10363 BCE_PRINTF("0x%04X(0x%04X) - rx_quick_consumer_index%d\n", \
10364 sblk->status_rx_quick_consumer_index##arg, (u16) \
10365 RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index##arg), \
10369 #define BCE_PRINT_TX_CONS(arg) \
10370 if (sblk->status_tx_quick_consumer_index##arg) \
10371 BCE_PRINTF("0x%04X(0x%04X) - tx_quick_consumer_index%d\n", \
10372 sblk->status_tx_quick_consumer_index##arg, (u16) \
10373 TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index##arg), \
10376 /****************************************************************************/
10377 /* Prints out the status block from host memory. */
10381 /****************************************************************************/
10382 static __attribute__ ((noinline)) void
10383 bce_dump_status_block(struct bce_softc *sc)
10385 struct status_block *sblk;
10387 sblk = sc->status_block;
10390 "----------------------------"
10392 "----------------------------\n");
10394 /* Theses indices are used for normal L2 drivers. */
10395 BCE_PRINTF(" 0x%08X - attn_bits\n",
10396 sblk->status_attn_bits);
10398 BCE_PRINTF(" 0x%08X - attn_bits_ack\n",
10399 sblk->status_attn_bits_ack);
10401 BCE_PRINT_RX_CONS(0);
10402 BCE_PRINT_TX_CONS(0)
10404 BCE_PRINTF(" 0x%04X - status_idx\n", sblk->status_idx);
10406 /* Theses indices are not used for normal L2 drivers. */
10407 BCE_PRINT_RX_CONS(1); BCE_PRINT_RX_CONS(2); BCE_PRINT_RX_CONS(3);
10408 BCE_PRINT_RX_CONS(4); BCE_PRINT_RX_CONS(5); BCE_PRINT_RX_CONS(6);
10409 BCE_PRINT_RX_CONS(7); BCE_PRINT_RX_CONS(8); BCE_PRINT_RX_CONS(9);
10410 BCE_PRINT_RX_CONS(10); BCE_PRINT_RX_CONS(11); BCE_PRINT_RX_CONS(12);
10411 BCE_PRINT_RX_CONS(13); BCE_PRINT_RX_CONS(14); BCE_PRINT_RX_CONS(15);
10413 BCE_PRINT_TX_CONS(1); BCE_PRINT_TX_CONS(2); BCE_PRINT_TX_CONS(3);
10415 if (sblk->status_completion_producer_index ||
10416 sblk->status_cmd_consumer_index)
10417 BCE_PRINTF("com_prod = 0x%08X, cmd_cons = 0x%08X\n",
10418 sblk->status_completion_producer_index,
10419 sblk->status_cmd_consumer_index);
10422 "----------------------------"
10424 "----------------------------\n");
10428 #define BCE_PRINT_64BIT_STAT(arg) \
10429 if (sblk->arg##_lo || sblk->arg##_hi) \
10430 BCE_PRINTF("0x%08X:%08X : %s\n", sblk->arg##_hi, \
10431 sblk->arg##_lo, #arg);
10433 #define BCE_PRINT_32BIT_STAT(arg) \
10435 BCE_PRINTF(" 0x%08X : %s\n", \
10438 /****************************************************************************/
10439 /* Prints out the statistics block from host memory. */
10443 /****************************************************************************/
10444 static __attribute__ ((noinline)) void
10445 bce_dump_stats_block(struct bce_softc *sc)
10447 struct statistics_block *sblk;
10449 sblk = sc->stats_block;
10453 " Stats Block (All Stats Not Shown Are 0) "
10454 "---------------\n");
10456 BCE_PRINT_64BIT_STAT(stat_IfHCInOctets);
10457 BCE_PRINT_64BIT_STAT(stat_IfHCInBadOctets);
10458 BCE_PRINT_64BIT_STAT(stat_IfHCOutOctets);
10459 BCE_PRINT_64BIT_STAT(stat_IfHCOutBadOctets);
10460 BCE_PRINT_64BIT_STAT(stat_IfHCInUcastPkts);
10461 BCE_PRINT_64BIT_STAT(stat_IfHCInBroadcastPkts);
10462 BCE_PRINT_64BIT_STAT(stat_IfHCInMulticastPkts);
10463 BCE_PRINT_64BIT_STAT(stat_IfHCOutUcastPkts);
10464 BCE_PRINT_64BIT_STAT(stat_IfHCOutBroadcastPkts);
10465 BCE_PRINT_64BIT_STAT(stat_IfHCOutMulticastPkts);
10466 BCE_PRINT_32BIT_STAT(
10467 stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
10468 BCE_PRINT_32BIT_STAT(stat_Dot3StatsCarrierSenseErrors);
10469 BCE_PRINT_32BIT_STAT(stat_Dot3StatsFCSErrors);
10470 BCE_PRINT_32BIT_STAT(stat_Dot3StatsAlignmentErrors);
10471 BCE_PRINT_32BIT_STAT(stat_Dot3StatsSingleCollisionFrames);
10472 BCE_PRINT_32BIT_STAT(stat_Dot3StatsMultipleCollisionFrames);
10473 BCE_PRINT_32BIT_STAT(stat_Dot3StatsDeferredTransmissions);
10474 BCE_PRINT_32BIT_STAT(stat_Dot3StatsExcessiveCollisions);
10475 BCE_PRINT_32BIT_STAT(stat_Dot3StatsLateCollisions);
10476 BCE_PRINT_32BIT_STAT(stat_EtherStatsCollisions);
10477 BCE_PRINT_32BIT_STAT(stat_EtherStatsFragments);
10478 BCE_PRINT_32BIT_STAT(stat_EtherStatsJabbers);
10479 BCE_PRINT_32BIT_STAT(stat_EtherStatsUndersizePkts);
10480 BCE_PRINT_32BIT_STAT(stat_EtherStatsOversizePkts);
10481 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx64Octets);
10482 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx65Octetsto127Octets);
10483 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx128Octetsto255Octets);
10484 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx256Octetsto511Octets);
10485 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx512Octetsto1023Octets);
10486 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx1024Octetsto1522Octets);
10487 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx1523Octetsto9022Octets);
10488 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx64Octets);
10489 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx65Octetsto127Octets);
10490 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx128Octetsto255Octets);
10491 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx256Octetsto511Octets);
10492 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx512Octetsto1023Octets);
10493 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx1024Octetsto1522Octets);
10494 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx1523Octetsto9022Octets);
10495 BCE_PRINT_32BIT_STAT(stat_XonPauseFramesReceived);
10496 BCE_PRINT_32BIT_STAT(stat_XoffPauseFramesReceived);
10497 BCE_PRINT_32BIT_STAT(stat_OutXonSent);
10498 BCE_PRINT_32BIT_STAT(stat_OutXoffSent);
10499 BCE_PRINT_32BIT_STAT(stat_FlowControlDone);
10500 BCE_PRINT_32BIT_STAT(stat_MacControlFramesReceived);
10501 BCE_PRINT_32BIT_STAT(stat_XoffStateEntered);
10502 BCE_PRINT_32BIT_STAT(stat_IfInFramesL2FilterDiscards);
10503 BCE_PRINT_32BIT_STAT(stat_IfInRuleCheckerDiscards);
10504 BCE_PRINT_32BIT_STAT(stat_IfInFTQDiscards);
10505 BCE_PRINT_32BIT_STAT(stat_IfInMBUFDiscards);
10506 BCE_PRINT_32BIT_STAT(stat_IfInRuleCheckerP4Hit);
10507 BCE_PRINT_32BIT_STAT(stat_CatchupInRuleCheckerDiscards);
10508 BCE_PRINT_32BIT_STAT(stat_CatchupInFTQDiscards);
10509 BCE_PRINT_32BIT_STAT(stat_CatchupInMBUFDiscards);
10510 BCE_PRINT_32BIT_STAT(stat_CatchupInRuleCheckerP4Hit);
10513 "----------------------------"
10515 "----------------------------\n");
10519 /****************************************************************************/
10520 /* Prints out a summary of the driver state. */
10524 /****************************************************************************/
10525 static __attribute__ ((noinline)) void
10526 bce_dump_driver_state(struct bce_softc *sc)
10528 u32 val_hi, val_lo;
10531 "-----------------------------"
10533 "-----------------------------\n");
10535 val_hi = BCE_ADDR_HI(sc);
10536 val_lo = BCE_ADDR_LO(sc);
10537 BCE_PRINTF("0x%08X:%08X - (sc) driver softc structure virtual "
10538 "address\n", val_hi, val_lo);
10540 val_hi = BCE_ADDR_HI(sc->bce_vhandle);
10541 val_lo = BCE_ADDR_LO(sc->bce_vhandle);
10542 BCE_PRINTF("0x%08X:%08X - (sc->bce_vhandle) PCI BAR virtual "
10543 "address\n", val_hi, val_lo);
10545 val_hi = BCE_ADDR_HI(sc->status_block);
10546 val_lo = BCE_ADDR_LO(sc->status_block);
10547 BCE_PRINTF("0x%08X:%08X - (sc->status_block) status block "
10548 "virtual address\n", val_hi, val_lo);
10550 val_hi = BCE_ADDR_HI(sc->stats_block);
10551 val_lo = BCE_ADDR_LO(sc->stats_block);
10552 BCE_PRINTF("0x%08X:%08X - (sc->stats_block) statistics block "
10553 "virtual address\n", val_hi, val_lo);
10555 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
10556 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
10557 BCE_PRINTF("0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
10558 "virtual adddress\n", val_hi, val_lo);
10560 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
10561 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
10562 BCE_PRINTF("0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
10563 "virtual address\n", val_hi, val_lo);
10565 if (bce_hdr_split == TRUE) {
10566 val_hi = BCE_ADDR_HI(sc->pg_bd_chain);
10567 val_lo = BCE_ADDR_LO(sc->pg_bd_chain);
10568 BCE_PRINTF("0x%08X:%08X - (sc->pg_bd_chain) page chain "
10569 "virtual address\n", val_hi, val_lo);
10572 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
10573 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
10574 BCE_PRINTF("0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
10575 "virtual address\n", val_hi, val_lo);
10577 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
10578 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
10579 BCE_PRINTF("0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
10580 "virtual address\n", val_hi, val_lo);
10582 if (bce_hdr_split == TRUE) {
10583 val_hi = BCE_ADDR_HI(sc->pg_mbuf_ptr);
10584 val_lo = BCE_ADDR_LO(sc->pg_mbuf_ptr);
10585 BCE_PRINTF("0x%08X:%08X - (sc->pg_mbuf_ptr) page mbuf chain "
10586 "virtual address\n", val_hi, val_lo);
10589 BCE_PRINTF(" 0x%016llX - (sc->interrupts_generated) "
10591 (long long unsigned int) sc->interrupts_generated);
10593 BCE_PRINTF(" 0x%016llX - (sc->interrupts_rx) "
10594 "rx interrupts handled\n",
10595 (long long unsigned int) sc->interrupts_rx);
10597 BCE_PRINTF(" 0x%016llX - (sc->interrupts_tx) "
10598 "tx interrupts handled\n",
10599 (long long unsigned int) sc->interrupts_tx);
10601 BCE_PRINTF(" 0x%016llX - (sc->phy_interrupts) "
10602 "phy interrupts handled\n",
10603 (long long unsigned int) sc->phy_interrupts);
10605 BCE_PRINTF(" 0x%08X - (sc->last_status_idx) "
10606 "status block index\n", sc->last_status_idx);
10608 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->tx_prod) tx producer "
10609 "index\n", sc->tx_prod, (u16) TX_CHAIN_IDX(sc->tx_prod));
10611 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->tx_cons) tx consumer "
10612 "index\n", sc->tx_cons, (u16) TX_CHAIN_IDX(sc->tx_cons));
10614 BCE_PRINTF(" 0x%08X - (sc->tx_prod_bseq) tx producer "
10615 "byte seq index\n", sc->tx_prod_bseq);
10617 BCE_PRINTF(" 0x%08X - (sc->debug_tx_mbuf_alloc) tx "
10618 "mbufs allocated\n", sc->debug_tx_mbuf_alloc);
10620 BCE_PRINTF(" 0x%08X - (sc->used_tx_bd) used "
10621 "tx_bd's\n", sc->used_tx_bd);
10623 BCE_PRINTF(" 0x%04X/0x%04X - (sc->tx_hi_watermark)/"
10624 "(sc->max_tx_bd)\n", sc->tx_hi_watermark, sc->max_tx_bd);
10626 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->rx_prod) rx producer "
10627 "index\n", sc->rx_prod, (u16) RX_CHAIN_IDX(sc->rx_prod));
10629 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->rx_cons) rx consumer "
10630 "index\n", sc->rx_cons, (u16) RX_CHAIN_IDX(sc->rx_cons));
10632 BCE_PRINTF(" 0x%08X - (sc->rx_prod_bseq) rx producer "
10633 "byte seq index\n", sc->rx_prod_bseq);
10635 BCE_PRINTF(" 0x%04X/0x%04X - (sc->rx_low_watermark)/"
10636 "(sc->max_rx_bd)\n", sc->rx_low_watermark, sc->max_rx_bd);
10638 BCE_PRINTF(" 0x%08X - (sc->debug_rx_mbuf_alloc) rx "
10639 "mbufs allocated\n", sc->debug_rx_mbuf_alloc);
10641 BCE_PRINTF(" 0x%08X - (sc->free_rx_bd) free "
10642 "rx_bd's\n", sc->free_rx_bd);
10644 if (bce_hdr_split == TRUE) {
10645 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->pg_prod) page producer "
10646 "index\n", sc->pg_prod, (u16) PG_CHAIN_IDX(sc->pg_prod));
10648 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->pg_cons) page consumer "
10649 "index\n", sc->pg_cons, (u16) PG_CHAIN_IDX(sc->pg_cons));
10651 BCE_PRINTF(" 0x%08X - (sc->debug_pg_mbuf_alloc) page "
10652 "mbufs allocated\n", sc->debug_pg_mbuf_alloc);
10655 BCE_PRINTF(" 0x%08X - (sc->free_pg_bd) free page "
10656 "rx_bd's\n", sc->free_pg_bd);
10658 BCE_PRINTF(" 0x%04X/0x%04X - (sc->pg_low_watermark)/"
10659 "(sc->max_pg_bd)\n", sc->pg_low_watermark, sc->max_pg_bd);
10661 BCE_PRINTF(" 0x%08X - (sc->mbuf_alloc_failed_count) "
10662 "mbuf alloc failures\n", sc->mbuf_alloc_failed_count);
10664 BCE_PRINTF(" 0x%08X - (sc->bce_flags) "
10665 "bce mac flags\n", sc->bce_flags);
10667 BCE_PRINTF(" 0x%08X - (sc->bce_phy_flags) "
10668 "bce phy flags\n", sc->bce_phy_flags);
10671 "----------------------------"
10673 "----------------------------\n");
10677 /****************************************************************************/
10678 /* Prints out the hardware state through a summary of important register, */
10679 /* followed by a complete register dump. */
10683 /****************************************************************************/
10684 static __attribute__ ((noinline)) void
10685 bce_dump_hw_state(struct bce_softc *sc)
10690 "----------------------------"
10692 "----------------------------\n");
10694 BCE_PRINTF("%s - bootcode version\n", sc->bce_bc_ver);
10696 val = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
10697 BCE_PRINTF("0x%08X - (0x%06X) misc_enable_status_bits\n",
10698 val, BCE_MISC_ENABLE_STATUS_BITS);
10700 val = REG_RD(sc, BCE_DMA_STATUS);
10701 BCE_PRINTF("0x%08X - (0x%06X) dma_status\n",
10702 val, BCE_DMA_STATUS);
10704 val = REG_RD(sc, BCE_CTX_STATUS);
10705 BCE_PRINTF("0x%08X - (0x%06X) ctx_status\n",
10706 val, BCE_CTX_STATUS);
10708 val = REG_RD(sc, BCE_EMAC_STATUS);
10709 BCE_PRINTF("0x%08X - (0x%06X) emac_status\n",
10710 val, BCE_EMAC_STATUS);
10712 val = REG_RD(sc, BCE_RPM_STATUS);
10713 BCE_PRINTF("0x%08X - (0x%06X) rpm_status\n",
10714 val, BCE_RPM_STATUS);
10716 /* ToDo: Create a #define for this constant. */
10717 val = REG_RD(sc, 0x2004);
10718 BCE_PRINTF("0x%08X - (0x%06X) rlup_status\n",
10721 val = REG_RD(sc, BCE_RV2P_STATUS);
10722 BCE_PRINTF("0x%08X - (0x%06X) rv2p_status\n",
10723 val, BCE_RV2P_STATUS);
10725 /* ToDo: Create a #define for this constant. */
10726 val = REG_RD(sc, 0x2c04);
10727 BCE_PRINTF("0x%08X - (0x%06X) rdma_status\n",
10730 val = REG_RD(sc, BCE_TBDR_STATUS);
10731 BCE_PRINTF("0x%08X - (0x%06X) tbdr_status\n",
10732 val, BCE_TBDR_STATUS);
10734 val = REG_RD(sc, BCE_TDMA_STATUS);
10735 BCE_PRINTF("0x%08X - (0x%06X) tdma_status\n",
10736 val, BCE_TDMA_STATUS);
10738 val = REG_RD(sc, BCE_HC_STATUS);
10739 BCE_PRINTF("0x%08X - (0x%06X) hc_status\n",
10740 val, BCE_HC_STATUS);
10742 val = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
10743 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_state\n",
10744 val, BCE_TXP_CPU_STATE);
10746 val = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
10747 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_state\n",
10748 val, BCE_TPAT_CPU_STATE);
10750 val = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
10751 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_state\n",
10752 val, BCE_RXP_CPU_STATE);
10754 val = REG_RD_IND(sc, BCE_COM_CPU_STATE);
10755 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_state\n",
10756 val, BCE_COM_CPU_STATE);
10758 val = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
10759 BCE_PRINTF("0x%08X - (0x%06X) mcp_cpu_state\n",
10760 val, BCE_MCP_CPU_STATE);
10762 val = REG_RD_IND(sc, BCE_CP_CPU_STATE);
10763 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_state\n",
10764 val, BCE_CP_CPU_STATE);
10767 "----------------------------"
10769 "----------------------------\n");
10772 "----------------------------"
10774 "----------------------------\n");
10776 for (int i = 0x400; i < 0x8000; i += 0x10) {
10777 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
10778 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
10779 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
10783 "----------------------------"
10785 "----------------------------\n");
10789 /****************************************************************************/
10790 /* Prints out the contentst of shared memory which is used for host driver */
10791 /* to bootcode firmware communication. */
10795 /****************************************************************************/
10796 static __attribute__ ((noinline)) void
10797 bce_dump_shmem_state(struct bce_softc *sc)
10800 "----------------------------"
10802 "----------------------------\n");
10804 BCE_PRINTF("0x%08X - Shared memory base address\n",
10805 sc->bce_shmem_base);
10806 BCE_PRINTF("%s - bootcode version\n",
10810 "----------------------------"
10812 "----------------------------\n");
10814 for (int i = 0x0; i < 0x200; i += 0x10) {
10815 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
10816 i, bce_shmem_rd(sc, i), bce_shmem_rd(sc, i + 0x4),
10817 bce_shmem_rd(sc, i + 0x8), bce_shmem_rd(sc, i + 0xC));
10821 "----------------------------"
10823 "----------------------------\n");
10827 /****************************************************************************/
10828 /* Prints out the mailbox queue registers. */
10832 /****************************************************************************/
10833 static __attribute__ ((noinline)) void
10834 bce_dump_mq_regs(struct bce_softc *sc)
10837 "----------------------------"
10839 "----------------------------\n");
10842 "----------------------------"
10844 "----------------------------\n");
10846 for (int i = 0x3c00; i < 0x4000; i += 0x10) {
10847 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
10848 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
10849 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
10853 "----------------------------"
10855 "----------------------------\n");
10859 /****************************************************************************/
10860 /* Prints out the bootcode state. */
10864 /****************************************************************************/
10865 static __attribute__ ((noinline)) void
10866 bce_dump_bc_state(struct bce_softc *sc)
10871 "----------------------------"
10873 "----------------------------\n");
10875 BCE_PRINTF("%s - bootcode version\n", sc->bce_bc_ver);
10877 val = bce_shmem_rd(sc, BCE_BC_RESET_TYPE);
10878 BCE_PRINTF("0x%08X - (0x%06X) reset_type\n",
10879 val, BCE_BC_RESET_TYPE);
10881 val = bce_shmem_rd(sc, BCE_BC_STATE);
10882 BCE_PRINTF("0x%08X - (0x%06X) state\n",
10883 val, BCE_BC_STATE);
10885 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
10886 BCE_PRINTF("0x%08X - (0x%06X) condition\n",
10887 val, BCE_BC_STATE_CONDITION);
10889 val = bce_shmem_rd(sc, BCE_BC_STATE_DEBUG_CMD);
10890 BCE_PRINTF("0x%08X - (0x%06X) debug_cmd\n",
10891 val, BCE_BC_STATE_DEBUG_CMD);
10894 "----------------------------"
10896 "----------------------------\n");
10900 /****************************************************************************/
10901 /* Prints out the TXP processor state. */
10905 /****************************************************************************/
10906 static __attribute__ ((noinline)) void
10907 bce_dump_txp_state(struct bce_softc *sc, int regs)
10913 "----------------------------"
10915 "----------------------------\n");
10917 for (int i = 0; i < 3; i++)
10918 fw_version[i] = htonl(REG_RD_IND(sc,
10919 (BCE_TXP_SCRATCH + 0x10 + i * 4)));
10920 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10922 val = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
10923 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_mode\n",
10924 val, BCE_TXP_CPU_MODE);
10926 val = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
10927 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_state\n",
10928 val, BCE_TXP_CPU_STATE);
10930 val = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
10931 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_event_mask\n",
10932 val, BCE_TXP_CPU_EVENT_MASK);
10936 "----------------------------"
10938 "----------------------------\n");
10940 for (int i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
10941 /* Skip the big blank spaces */
10942 if (i < 0x454000 && i > 0x5ffff)
10943 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
10944 "0x%08X 0x%08X\n", i,
10946 REG_RD_IND(sc, i + 0x4),
10947 REG_RD_IND(sc, i + 0x8),
10948 REG_RD_IND(sc, i + 0xC));
10953 "----------------------------"
10955 "----------------------------\n");
10959 /****************************************************************************/
10960 /* Prints out the RXP processor state. */
10964 /****************************************************************************/
10965 static __attribute__ ((noinline)) void
10966 bce_dump_rxp_state(struct bce_softc *sc, int regs)
10972 "----------------------------"
10974 "----------------------------\n");
10976 for (int i = 0; i < 3; i++)
10977 fw_version[i] = htonl(REG_RD_IND(sc,
10978 (BCE_RXP_SCRATCH + 0x10 + i * 4)));
10980 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
10982 val = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
10983 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_mode\n",
10984 val, BCE_RXP_CPU_MODE);
10986 val = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
10987 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_state\n",
10988 val, BCE_RXP_CPU_STATE);
10990 val = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
10991 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_event_mask\n",
10992 val, BCE_RXP_CPU_EVENT_MASK);
10996 "----------------------------"
10998 "----------------------------\n");
11000 for (int i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
11001 /* Skip the big blank sapces */
11002 if (i < 0xc5400 && i > 0xdffff)
11003 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11004 "0x%08X 0x%08X\n", i,
11006 REG_RD_IND(sc, i + 0x4),
11007 REG_RD_IND(sc, i + 0x8),
11008 REG_RD_IND(sc, i + 0xC));
11013 "----------------------------"
11015 "----------------------------\n");
11019 /****************************************************************************/
11020 /* Prints out the TPAT processor state. */
11024 /****************************************************************************/
11025 static __attribute__ ((noinline)) void
11026 bce_dump_tpat_state(struct bce_softc *sc, int regs)
11032 "----------------------------"
11034 "----------------------------\n");
11036 for (int i = 0; i < 3; i++)
11037 fw_version[i] = htonl(REG_RD_IND(sc,
11038 (BCE_TPAT_SCRATCH + 0x410 + i * 4)));
11040 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11042 val = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
11043 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_mode\n",
11044 val, BCE_TPAT_CPU_MODE);
11046 val = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
11047 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_state\n",
11048 val, BCE_TPAT_CPU_STATE);
11050 val = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
11051 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_event_mask\n",
11052 val, BCE_TPAT_CPU_EVENT_MASK);
11056 "----------------------------"
11058 "----------------------------\n");
11060 for (int i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
11061 /* Skip the big blank spaces */
11062 if (i < 0x854000 && i > 0x9ffff)
11063 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11064 "0x%08X 0x%08X\n", i,
11066 REG_RD_IND(sc, i + 0x4),
11067 REG_RD_IND(sc, i + 0x8),
11068 REG_RD_IND(sc, i + 0xC));
11073 "----------------------------"
11075 "----------------------------\n");
11079 /****************************************************************************/
11080 /* Prints out the Command Procesor (CP) state. */
11084 /****************************************************************************/
11085 static __attribute__ ((noinline)) void
11086 bce_dump_cp_state(struct bce_softc *sc, int regs)
11092 "----------------------------"
11094 "----------------------------\n");
11096 for (int i = 0; i < 3; i++)
11097 fw_version[i] = htonl(REG_RD_IND(sc,
11098 (BCE_CP_SCRATCH + 0x10 + i * 4)));
11100 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11102 val = REG_RD_IND(sc, BCE_CP_CPU_MODE);
11103 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_mode\n",
11104 val, BCE_CP_CPU_MODE);
11106 val = REG_RD_IND(sc, BCE_CP_CPU_STATE);
11107 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_state\n",
11108 val, BCE_CP_CPU_STATE);
11110 val = REG_RD_IND(sc, BCE_CP_CPU_EVENT_MASK);
11111 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_event_mask\n", val,
11112 BCE_CP_CPU_EVENT_MASK);
11116 "----------------------------"
11118 "----------------------------\n");
11120 for (int i = BCE_CP_CPU_MODE; i < 0x1aa000; i += 0x10) {
11121 /* Skip the big blank spaces */
11122 if (i < 0x185400 && i > 0x19ffff)
11123 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11124 "0x%08X 0x%08X\n", i,
11126 REG_RD_IND(sc, i + 0x4),
11127 REG_RD_IND(sc, i + 0x8),
11128 REG_RD_IND(sc, i + 0xC));
11133 "----------------------------"
11135 "----------------------------\n");
11139 /****************************************************************************/
11140 /* Prints out the Completion Procesor (COM) state. */
11144 /****************************************************************************/
11145 static __attribute__ ((noinline)) void
11146 bce_dump_com_state(struct bce_softc *sc, int regs)
11152 "----------------------------"
11154 "----------------------------\n");
11156 for (int i = 0; i < 3; i++)
11157 fw_version[i] = htonl(REG_RD_IND(sc,
11158 (BCE_COM_SCRATCH + 0x10 + i * 4)));
11160 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11162 val = REG_RD_IND(sc, BCE_COM_CPU_MODE);
11163 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_mode\n",
11164 val, BCE_COM_CPU_MODE);
11166 val = REG_RD_IND(sc, BCE_COM_CPU_STATE);
11167 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_state\n",
11168 val, BCE_COM_CPU_STATE);
11170 val = REG_RD_IND(sc, BCE_COM_CPU_EVENT_MASK);
11171 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_event_mask\n", val,
11172 BCE_COM_CPU_EVENT_MASK);
11176 "----------------------------"
11178 "----------------------------\n");
11180 for (int i = BCE_COM_CPU_MODE; i < 0x1053e8; i += 0x10) {
11181 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11182 "0x%08X 0x%08X\n", i,
11184 REG_RD_IND(sc, i + 0x4),
11185 REG_RD_IND(sc, i + 0x8),
11186 REG_RD_IND(sc, i + 0xC));
11191 "----------------------------"
11193 "----------------------------\n");
11197 /****************************************************************************/
11198 /* Prints out the Receive Virtual 2 Physical (RV2P) state. */
11202 /****************************************************************************/
11203 static __attribute__ ((noinline)) void
11204 bce_dump_rv2p_state(struct bce_softc *sc)
11206 u32 val, pc1, pc2, fw_ver_high, fw_ver_low;
11209 "----------------------------"
11211 "----------------------------\n");
11213 /* Stall the RV2P processors. */
11214 val = REG_RD_IND(sc, BCE_RV2P_CONFIG);
11215 val |= BCE_RV2P_CONFIG_STALL_PROC1 | BCE_RV2P_CONFIG_STALL_PROC2;
11216 REG_WR_IND(sc, BCE_RV2P_CONFIG, val);
11218 /* Read the firmware version. */
11220 REG_WR_IND(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
11221 fw_ver_low = REG_RD_IND(sc, BCE_RV2P_INSTR_LOW);
11222 fw_ver_high = REG_RD_IND(sc, BCE_RV2P_INSTR_HIGH) &
11223 BCE_RV2P_INSTR_HIGH_HIGH;
11224 BCE_PRINTF("RV2P1 Firmware version - 0x%08X:0x%08X\n",
11225 fw_ver_high, fw_ver_low);
11228 REG_WR_IND(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
11229 fw_ver_low = REG_RD_IND(sc, BCE_RV2P_INSTR_LOW);
11230 fw_ver_high = REG_RD_IND(sc, BCE_RV2P_INSTR_HIGH) &
11231 BCE_RV2P_INSTR_HIGH_HIGH;
11232 BCE_PRINTF("RV2P2 Firmware version - 0x%08X:0x%08X\n",
11233 fw_ver_high, fw_ver_low);
11235 /* Resume the RV2P processors. */
11236 val = REG_RD_IND(sc, BCE_RV2P_CONFIG);
11237 val &= ~(BCE_RV2P_CONFIG_STALL_PROC1 | BCE_RV2P_CONFIG_STALL_PROC2);
11238 REG_WR_IND(sc, BCE_RV2P_CONFIG, val);
11240 /* Fetch the program counter value. */
11242 REG_WR_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK, val);
11243 val = REG_RD_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK);
11244 pc1 = (val & BCE_RV2P_DEBUG_VECT_PEEK_1_VALUE);
11245 pc2 = (val & BCE_RV2P_DEBUG_VECT_PEEK_2_VALUE) >> 16;
11246 BCE_PRINTF("0x%08X - RV2P1 program counter (1st read)\n", pc1);
11247 BCE_PRINTF("0x%08X - RV2P2 program counter (1st read)\n", pc2);
11249 /* Fetch the program counter value again to see if it is advancing. */
11251 REG_WR_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK, val);
11252 val = REG_RD_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK);
11253 pc1 = (val & BCE_RV2P_DEBUG_VECT_PEEK_1_VALUE);
11254 pc2 = (val & BCE_RV2P_DEBUG_VECT_PEEK_2_VALUE) >> 16;
11255 BCE_PRINTF("0x%08X - RV2P1 program counter (2nd read)\n", pc1);
11256 BCE_PRINTF("0x%08X - RV2P2 program counter (2nd read)\n", pc2);
11259 "----------------------------"
11261 "----------------------------\n");
11265 /****************************************************************************/
11266 /* Prints out the driver state and then enters the debugger. */
11270 /****************************************************************************/
11271 static __attribute__ ((noinline)) void
11272 bce_breakpoint(struct bce_softc *sc)
11276 * Unreachable code to silence compiler warnings
11277 * about unused functions.
11280 bce_freeze_controller(sc);
11281 bce_unfreeze_controller(sc);
11282 bce_dump_enet(sc, NULL);
11283 bce_dump_txbd(sc, 0, NULL);
11284 bce_dump_rxbd(sc, 0, NULL);
11285 bce_dump_tx_mbuf_chain(sc, 0, USABLE_TX_BD_ALLOC);
11286 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD_ALLOC);
11287 bce_dump_pg_mbuf_chain(sc, 0, USABLE_PG_BD_ALLOC);
11288 bce_dump_l2fhdr(sc, 0, NULL);
11289 bce_dump_ctx(sc, RX_CID);
11291 bce_dump_tx_chain(sc, 0, USABLE_TX_BD_ALLOC);
11292 bce_dump_rx_bd_chain(sc, 0, USABLE_RX_BD_ALLOC);
11293 bce_dump_pg_chain(sc, 0, USABLE_PG_BD_ALLOC);
11294 bce_dump_status_block(sc);
11295 bce_dump_stats_block(sc);
11296 bce_dump_driver_state(sc);
11297 bce_dump_hw_state(sc);
11298 bce_dump_bc_state(sc);
11299 bce_dump_txp_state(sc, 0);
11300 bce_dump_rxp_state(sc, 0);
11301 bce_dump_tpat_state(sc, 0);
11302 bce_dump_cp_state(sc, 0);
11303 bce_dump_com_state(sc, 0);
11304 bce_dump_rv2p_state(sc);
11305 bce_dump_pgbd(sc, 0, NULL);
11308 bce_dump_status_block(sc);
11309 bce_dump_driver_state(sc);
11311 /* Call the debugger. */