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 const 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 const 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 const 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 u32 bce_get_rphy_link (struct bce_softc *);
368 static void bce_dma_map_addr (void *, bus_dma_segment_t *, int, int);
369 static int bce_dma_alloc (device_t);
370 static void bce_dma_free (struct bce_softc *);
371 static void bce_release_resources (struct bce_softc *);
373 /****************************************************************************/
374 /* BCE Firmware Synchronization and Load */
375 /****************************************************************************/
376 static void bce_fw_cap_init (struct bce_softc *);
377 static int bce_fw_sync (struct bce_softc *, u32);
378 static void bce_load_rv2p_fw (struct bce_softc *, const u32 *, u32,
380 static void bce_load_cpu_fw (struct bce_softc *,
381 struct cpu_reg *, struct fw_info *);
382 static void bce_start_cpu (struct bce_softc *, struct cpu_reg *);
383 static void bce_halt_cpu (struct bce_softc *, struct cpu_reg *);
384 static void bce_start_rxp_cpu (struct bce_softc *);
385 static void bce_init_rxp_cpu (struct bce_softc *);
386 static void bce_init_txp_cpu (struct bce_softc *);
387 static void bce_init_tpat_cpu (struct bce_softc *);
388 static void bce_init_cp_cpu (struct bce_softc *);
389 static void bce_init_com_cpu (struct bce_softc *);
390 static void bce_init_cpus (struct bce_softc *);
392 static void bce_print_adapter_info (struct bce_softc *);
393 static void bce_probe_pci_caps (device_t, struct bce_softc *);
394 static void bce_stop (struct bce_softc *);
395 static int bce_reset (struct bce_softc *, u32);
396 static int bce_chipinit (struct bce_softc *);
397 static int bce_blockinit (struct bce_softc *);
399 static int bce_init_tx_chain (struct bce_softc *);
400 static void bce_free_tx_chain (struct bce_softc *);
402 static int bce_get_rx_buf (struct bce_softc *, u16, u16, u32 *);
403 static int bce_init_rx_chain (struct bce_softc *);
404 static void bce_fill_rx_chain (struct bce_softc *);
405 static void bce_free_rx_chain (struct bce_softc *);
407 static int bce_get_pg_buf (struct bce_softc *, u16, u16);
408 static int bce_init_pg_chain (struct bce_softc *);
409 static void bce_fill_pg_chain (struct bce_softc *);
410 static void bce_free_pg_chain (struct bce_softc *);
412 static struct mbuf *bce_tso_setup (struct bce_softc *,
413 struct mbuf **, u16 *);
414 static int bce_tx_encap (struct bce_softc *, struct mbuf **);
415 static void bce_start_locked (struct ifnet *);
416 static void bce_start (struct ifnet *);
417 static int bce_ioctl (struct ifnet *, u_long, caddr_t);
418 static void bce_watchdog (struct bce_softc *);
419 static int bce_ifmedia_upd (struct ifnet *);
420 static int bce_ifmedia_upd_locked (struct ifnet *);
421 static void bce_ifmedia_sts (struct ifnet *, struct ifmediareq *);
422 static void bce_ifmedia_sts_rphy (struct bce_softc *, struct ifmediareq *);
423 static void bce_init_locked (struct bce_softc *);
424 static void bce_init (void *);
425 static void bce_mgmt_init_locked (struct bce_softc *sc);
427 static int bce_init_ctx (struct bce_softc *);
428 static void bce_get_mac_addr (struct bce_softc *);
429 static void bce_set_mac_addr (struct bce_softc *);
430 static void bce_phy_intr (struct bce_softc *);
431 static inline u16 bce_get_hw_rx_cons (struct bce_softc *);
432 static void bce_rx_intr (struct bce_softc *);
433 static void bce_tx_intr (struct bce_softc *);
434 static void bce_disable_intr (struct bce_softc *);
435 static void bce_enable_intr (struct bce_softc *, int);
437 static void bce_intr (void *);
438 static void bce_set_rx_mode (struct bce_softc *);
439 static void bce_stats_update (struct bce_softc *);
440 static void bce_tick (void *);
441 static void bce_pulse (void *);
442 static void bce_add_sysctls (struct bce_softc *);
445 /****************************************************************************/
446 /* FreeBSD device dispatch table. */
447 /****************************************************************************/
448 static device_method_t bce_methods[] = {
449 /* Device interface (device_if.h) */
450 DEVMETHOD(device_probe, bce_probe),
451 DEVMETHOD(device_attach, bce_attach),
452 DEVMETHOD(device_detach, bce_detach),
453 DEVMETHOD(device_shutdown, bce_shutdown),
454 /* Supported by device interface but not used here. */
455 /* DEVMETHOD(device_identify, bce_identify), */
456 /* DEVMETHOD(device_suspend, bce_suspend), */
457 /* DEVMETHOD(device_resume, bce_resume), */
458 /* DEVMETHOD(device_quiesce, bce_quiesce), */
460 /* MII interface (miibus_if.h) */
461 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
462 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
463 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
464 /* Supported by MII interface but not used here. */
465 /* DEVMETHOD(miibus_linkchg, bce_miibus_linkchg), */
466 /* DEVMETHOD(miibus_mediainit, bce_miibus_mediainit), */
471 static driver_t bce_driver = {
474 sizeof(struct bce_softc)
477 static devclass_t bce_devclass;
479 MODULE_DEPEND(bce, pci, 1, 1, 1);
480 MODULE_DEPEND(bce, ether, 1, 1, 1);
481 MODULE_DEPEND(bce, miibus, 1, 1, 1);
483 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, NULL, NULL);
484 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
487 /****************************************************************************/
488 /* Tunable device values */
489 /****************************************************************************/
490 static SYSCTL_NODE(_hw, OID_AUTO, bce, CTLFLAG_RD, 0, "bce driver parameters");
492 /* Allowable values are TRUE or FALSE */
493 static int bce_verbose = TRUE;
494 TUNABLE_INT("hw.bce.verbose", &bce_verbose);
495 SYSCTL_INT(_hw_bce, OID_AUTO, verbose, CTLFLAG_RDTUN, &bce_verbose, 0,
496 "Verbose output enable/disable");
498 /* Allowable values are TRUE or FALSE */
499 static int bce_tso_enable = TRUE;
500 TUNABLE_INT("hw.bce.tso_enable", &bce_tso_enable);
501 SYSCTL_INT(_hw_bce, OID_AUTO, tso_enable, CTLFLAG_RDTUN, &bce_tso_enable, 0,
502 "TSO Enable/Disable");
504 /* Allowable values are 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
505 /* ToDo: Add MSI-X support. */
506 static int bce_msi_enable = 1;
507 TUNABLE_INT("hw.bce.msi_enable", &bce_msi_enable);
508 SYSCTL_INT(_hw_bce, OID_AUTO, msi_enable, CTLFLAG_RDTUN, &bce_msi_enable, 0,
509 "MSI-X|MSI|INTx selector");
511 /* Allowable values are 1, 2, 4, 8. */
512 static int bce_rx_pages = DEFAULT_RX_PAGES;
513 TUNABLE_INT("hw.bce.rx_pages", &bce_rx_pages);
514 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_pages, CTLFLAG_RDTUN, &bce_rx_pages, 0,
515 "Receive buffer descriptor pages (1 page = 255 buffer descriptors)");
517 /* Allowable values are 1, 2, 4, 8. */
518 static int bce_tx_pages = DEFAULT_TX_PAGES;
519 TUNABLE_INT("hw.bce.tx_pages", &bce_tx_pages);
520 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_pages, CTLFLAG_RDTUN, &bce_tx_pages, 0,
521 "Transmit buffer descriptor pages (1 page = 255 buffer descriptors)");
523 /* Allowable values are TRUE or FALSE. */
524 static int bce_hdr_split = TRUE;
525 TUNABLE_INT("hw.bce.hdr_split", &bce_hdr_split);
526 SYSCTL_UINT(_hw_bce, OID_AUTO, hdr_split, CTLFLAG_RDTUN, &bce_hdr_split, 0,
527 "Frame header/payload splitting Enable/Disable");
529 /* Allowable values are TRUE or FALSE. */
530 static int bce_strict_rx_mtu = FALSE;
531 TUNABLE_INT("hw.bce.strict_rx_mtu", &bce_strict_rx_mtu);
532 SYSCTL_UINT(_hw_bce, OID_AUTO, loose_rx_mtu, CTLFLAG_RDTUN,
533 &bce_strict_rx_mtu, 0,
534 "Enable/Disable strict RX frame size checking");
536 /* Allowable values are 0 ... 100 */
538 /* Generate 1 interrupt for every transmit completion. */
539 static int bce_tx_quick_cons_trip_int = 1;
541 /* Generate 1 interrupt for every 20 transmit completions. */
542 static int bce_tx_quick_cons_trip_int = DEFAULT_TX_QUICK_CONS_TRIP_INT;
544 TUNABLE_INT("hw.bce.tx_quick_cons_trip_int", &bce_tx_quick_cons_trip_int);
545 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_quick_cons_trip_int, CTLFLAG_RDTUN,
546 &bce_tx_quick_cons_trip_int, 0,
547 "Transmit BD trip point during interrupts");
549 /* Allowable values are 0 ... 100 */
550 /* Generate 1 interrupt for every transmit completion. */
552 static int bce_tx_quick_cons_trip = 1;
554 /* Generate 1 interrupt for every 20 transmit completions. */
555 static int bce_tx_quick_cons_trip = DEFAULT_TX_QUICK_CONS_TRIP;
557 TUNABLE_INT("hw.bce.tx_quick_cons_trip", &bce_tx_quick_cons_trip);
558 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_quick_cons_trip, CTLFLAG_RDTUN,
559 &bce_tx_quick_cons_trip, 0,
560 "Transmit BD trip point");
562 /* Allowable values are 0 ... 100 */
564 /* Generate an interrupt if 0us have elapsed since the last TX completion. */
565 static int bce_tx_ticks_int = 0;
567 /* Generate an interrupt if 80us have elapsed since the last TX completion. */
568 static int bce_tx_ticks_int = DEFAULT_TX_TICKS_INT;
570 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
571 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_ticks_int, CTLFLAG_RDTUN,
572 &bce_tx_ticks_int, 0, "Transmit ticks count during interrupt");
574 /* Allowable values are 0 ... 100 */
576 /* Generate an interrupt if 0us have elapsed since the last TX completion. */
577 static int bce_tx_ticks = 0;
579 /* Generate an interrupt if 80us have elapsed since the last TX completion. */
580 static int bce_tx_ticks = DEFAULT_TX_TICKS;
582 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
583 SYSCTL_UINT(_hw_bce, OID_AUTO, tx_ticks, CTLFLAG_RDTUN,
584 &bce_tx_ticks, 0, "Transmit ticks count");
586 /* Allowable values are 1 ... 100 */
588 /* Generate 1 interrupt for every received frame. */
589 static int bce_rx_quick_cons_trip_int = 1;
591 /* Generate 1 interrupt for every 6 received frames. */
592 static int bce_rx_quick_cons_trip_int = DEFAULT_RX_QUICK_CONS_TRIP_INT;
594 TUNABLE_INT("hw.bce.rx_quick_cons_trip_int", &bce_rx_quick_cons_trip_int);
595 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_quick_cons_trip_int, CTLFLAG_RDTUN,
596 &bce_rx_quick_cons_trip_int, 0,
597 "Receive BD trip point duirng interrupts");
599 /* Allowable values are 1 ... 100 */
601 /* Generate 1 interrupt for every received frame. */
602 static int bce_rx_quick_cons_trip = 1;
604 /* Generate 1 interrupt for every 6 received frames. */
605 static int bce_rx_quick_cons_trip = DEFAULT_RX_QUICK_CONS_TRIP;
607 TUNABLE_INT("hw.bce.rx_quick_cons_trip", &bce_rx_quick_cons_trip);
608 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_quick_cons_trip, CTLFLAG_RDTUN,
609 &bce_rx_quick_cons_trip, 0,
610 "Receive BD trip point");
612 /* Allowable values are 0 ... 100 */
614 /* Generate an int. if 0us have elapsed since the last received frame. */
615 static int bce_rx_ticks_int = 0;
617 /* Generate an int. if 18us have elapsed since the last received frame. */
618 static int bce_rx_ticks_int = DEFAULT_RX_TICKS_INT;
620 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
621 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_ticks_int, CTLFLAG_RDTUN,
622 &bce_rx_ticks_int, 0, "Receive ticks count during interrupt");
624 /* Allowable values are 0 ... 100 */
626 /* Generate an int. if 0us have elapsed since the last received frame. */
627 static int bce_rx_ticks = 0;
629 /* Generate an int. if 18us have elapsed since the last received frame. */
630 static int bce_rx_ticks = DEFAULT_RX_TICKS;
632 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
633 SYSCTL_UINT(_hw_bce, OID_AUTO, rx_ticks, CTLFLAG_RDTUN,
634 &bce_rx_ticks, 0, "Receive ticks count");
637 /****************************************************************************/
638 /* Device probe function. */
640 /* Compares the device to the driver's list of supported devices and */
641 /* reports back to the OS whether this is the right driver for the device. */
644 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
645 /****************************************************************************/
647 bce_probe(device_t dev)
649 const struct bce_type *t;
650 struct bce_softc *sc;
652 u16 vid = 0, did = 0, svid = 0, sdid = 0;
656 sc = device_get_softc(dev);
657 sc->bce_unit = device_get_unit(dev);
660 /* Get the data for the device to be probed. */
661 vid = pci_get_vendor(dev);
662 did = pci_get_device(dev);
663 svid = pci_get_subvendor(dev);
664 sdid = pci_get_subdevice(dev);
666 DBPRINT(sc, BCE_EXTREME_LOAD,
667 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
668 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
670 /* Look through the list of known devices for a match. */
671 while(t->bce_name != NULL) {
673 if ((vid == t->bce_vid) && (did == t->bce_did) &&
674 ((svid == t->bce_svid) || (t->bce_svid == PCI_ANY_ID)) &&
675 ((sdid == t->bce_sdid) || (t->bce_sdid == PCI_ANY_ID))) {
677 descbuf = malloc(BCE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
682 /* Print out the device identity. */
683 snprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
684 t->bce_name, (((pci_read_config(dev,
685 PCIR_REVID, 4) & 0xf0) >> 4) + 'A'),
686 (pci_read_config(dev, PCIR_REVID, 4) & 0xf));
688 device_set_desc_copy(dev, descbuf);
689 free(descbuf, M_TEMP);
690 return(BUS_PROBE_DEFAULT);
699 /****************************************************************************/
700 /* PCI Capabilities Probe Function. */
702 /* Walks the PCI capabiites list for the device to find what features are */
707 /****************************************************************************/
709 bce_print_adapter_info(struct bce_softc *sc)
713 DBENTER(BCE_VERBOSE_LOAD);
715 if (bce_verbose || bootverbose) {
716 BCE_PRINTF("ASIC (0x%08X); ", sc->bce_chipid);
717 printf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >>
718 12) + 'A', ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
722 if (sc->bce_flags & BCE_PCIE_FLAG) {
723 printf("Bus (PCIe x%d, ", sc->link_width);
724 switch (sc->link_speed) {
725 case 1: printf("2.5Gbps); "); break;
726 case 2: printf("5Gbps); "); break;
727 default: printf("Unknown link speed); ");
730 printf("Bus (PCI%s, %s, %dMHz); ",
731 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
732 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
733 "32-bit" : "64-bit"), sc->bus_speed_mhz);
736 /* Firmware version and device features. */
737 printf("B/C (%s); Bufs (RX:%d;TX:%d;PG:%d); Flags (",
738 sc->bce_bc_ver, sc->rx_pages, sc->tx_pages,
739 (bce_hdr_split == TRUE ? sc->pg_pages: 0));
741 if (bce_hdr_split == TRUE) {
746 if (sc->bce_flags & BCE_USING_MSI_FLAG) {
747 if (i > 0) printf("|");
751 if (sc->bce_flags & BCE_USING_MSIX_FLAG) {
752 if (i > 0) printf("|");
753 printf("MSI-X"); i++;
756 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG) {
757 if (i > 0) printf("|");
761 if (sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) {
762 if (i > 0) printf("|");
763 printf("Remote PHY(%s)",
764 sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG ?
765 "FIBER" : "TP"); i++;
768 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
769 if (i > 0) printf("|");
770 printf("MFW); MFW (%s)\n", sc->bce_mfw_ver);
775 printf("Coal (RX:%d,%d,%d,%d; TX:%d,%d,%d,%d)\n",
776 sc->bce_rx_quick_cons_trip_int,
777 sc->bce_rx_quick_cons_trip,
778 sc->bce_rx_ticks_int,
780 sc->bce_tx_quick_cons_trip_int,
781 sc->bce_tx_quick_cons_trip,
782 sc->bce_tx_ticks_int,
787 DBEXIT(BCE_VERBOSE_LOAD);
791 /****************************************************************************/
792 /* PCI Capabilities Probe Function. */
794 /* Walks the PCI capabiites list for the device to find what features are */
799 /****************************************************************************/
801 bce_probe_pci_caps(device_t dev, struct bce_softc *sc)
805 DBENTER(BCE_VERBOSE_LOAD);
807 /* Check if PCI-X capability is enabled. */
808 if (pci_find_cap(dev, PCIY_PCIX, ®) == 0) {
810 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
813 /* Check if PCIe capability is enabled. */
814 if (pci_find_cap(dev, PCIY_EXPRESS, ®) == 0) {
816 u16 link_status = pci_read_config(dev, reg + 0x12, 2);
817 DBPRINT(sc, BCE_INFO_LOAD, "PCIe link_status = "
818 "0x%08X\n", link_status);
819 sc->link_speed = link_status & 0xf;
820 sc->link_width = (link_status >> 4) & 0x3f;
821 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
822 sc->bce_flags |= BCE_PCIE_FLAG;
826 /* Check if MSI capability is enabled. */
827 if (pci_find_cap(dev, PCIY_MSI, ®) == 0) {
829 sc->bce_cap_flags |= BCE_MSI_CAPABLE_FLAG;
832 /* Check if MSI-X capability is enabled. */
833 if (pci_find_cap(dev, PCIY_MSIX, ®) == 0) {
835 sc->bce_cap_flags |= BCE_MSIX_CAPABLE_FLAG;
838 DBEXIT(BCE_VERBOSE_LOAD);
842 /****************************************************************************/
843 /* Load and validate user tunable settings. */
847 /****************************************************************************/
849 bce_set_tunables(struct bce_softc *sc)
851 /* Set sysctl values for RX page count. */
852 switch (bce_rx_pages) {
860 sc->rx_pages = bce_rx_pages;
863 sc->rx_pages = DEFAULT_RX_PAGES;
864 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
865 "hw.bce.rx_pages! Setting default of %d.\n",
866 __FILE__, __LINE__, bce_rx_pages, DEFAULT_RX_PAGES);
869 /* ToDo: Consider allowing user setting for pg_pages. */
870 sc->pg_pages = min((sc->rx_pages * 4), MAX_PG_PAGES);
872 /* Set sysctl values for TX page count. */
873 switch (bce_tx_pages) {
881 sc->tx_pages = bce_tx_pages;
884 sc->tx_pages = DEFAULT_TX_PAGES;
885 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
886 "hw.bce.tx_pages! Setting default of %d.\n",
887 __FILE__, __LINE__, bce_tx_pages, DEFAULT_TX_PAGES);
891 * Validate the TX trip point (i.e. the number of
892 * TX completions before a status block update is
893 * generated and an interrupt is asserted.
895 if (bce_tx_quick_cons_trip_int <= 100) {
896 sc->bce_tx_quick_cons_trip_int =
897 bce_tx_quick_cons_trip_int;
899 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
900 "hw.bce.tx_quick_cons_trip_int! Setting default of %d.\n",
901 __FILE__, __LINE__, bce_tx_quick_cons_trip_int,
902 DEFAULT_TX_QUICK_CONS_TRIP_INT);
903 sc->bce_tx_quick_cons_trip_int =
904 DEFAULT_TX_QUICK_CONS_TRIP_INT;
907 if (bce_tx_quick_cons_trip <= 100) {
908 sc->bce_tx_quick_cons_trip =
909 bce_tx_quick_cons_trip;
911 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
912 "hw.bce.tx_quick_cons_trip! Setting default of %d.\n",
913 __FILE__, __LINE__, bce_tx_quick_cons_trip,
914 DEFAULT_TX_QUICK_CONS_TRIP);
915 sc->bce_tx_quick_cons_trip =
916 DEFAULT_TX_QUICK_CONS_TRIP;
920 * Validate the TX ticks count (i.e. the maximum amount
921 * of time to wait after the last TX completion has
922 * occurred before a status block update is generated
923 * and an interrupt is asserted.
925 if (bce_tx_ticks_int <= 100) {
926 sc->bce_tx_ticks_int =
929 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
930 "hw.bce.tx_ticks_int! Setting default of %d.\n",
931 __FILE__, __LINE__, bce_tx_ticks_int,
932 DEFAULT_TX_TICKS_INT);
933 sc->bce_tx_ticks_int =
934 DEFAULT_TX_TICKS_INT;
937 if (bce_tx_ticks <= 100) {
941 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
942 "hw.bce.tx_ticks! Setting default of %d.\n",
943 __FILE__, __LINE__, bce_tx_ticks,
950 * Validate the RX trip point (i.e. the number of
951 * RX frames received before a status block update is
952 * generated and an interrupt is asserted.
954 if (bce_rx_quick_cons_trip_int <= 100) {
955 sc->bce_rx_quick_cons_trip_int =
956 bce_rx_quick_cons_trip_int;
958 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
959 "hw.bce.rx_quick_cons_trip_int! Setting default of %d.\n",
960 __FILE__, __LINE__, bce_rx_quick_cons_trip_int,
961 DEFAULT_RX_QUICK_CONS_TRIP_INT);
962 sc->bce_rx_quick_cons_trip_int =
963 DEFAULT_RX_QUICK_CONS_TRIP_INT;
966 if (bce_rx_quick_cons_trip <= 100) {
967 sc->bce_rx_quick_cons_trip =
968 bce_rx_quick_cons_trip;
970 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
971 "hw.bce.rx_quick_cons_trip! Setting default of %d.\n",
972 __FILE__, __LINE__, bce_rx_quick_cons_trip,
973 DEFAULT_RX_QUICK_CONS_TRIP);
974 sc->bce_rx_quick_cons_trip =
975 DEFAULT_RX_QUICK_CONS_TRIP;
979 * Validate the RX ticks count (i.e. the maximum amount
980 * of time to wait after the last RX frame has been
981 * received before a status block update is generated
982 * and an interrupt is asserted.
984 if (bce_rx_ticks_int <= 100) {
985 sc->bce_rx_ticks_int = bce_rx_ticks_int;
987 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
988 "hw.bce.rx_ticks_int! Setting default of %d.\n",
989 __FILE__, __LINE__, bce_rx_ticks_int,
990 DEFAULT_RX_TICKS_INT);
991 sc->bce_rx_ticks_int = DEFAULT_RX_TICKS_INT;
994 if (bce_rx_ticks <= 100) {
995 sc->bce_rx_ticks = bce_rx_ticks;
997 BCE_PRINTF("%s(%d): Illegal value (%d) specified for "
998 "hw.bce.rx_ticks! Setting default of %d.\n",
999 __FILE__, __LINE__, bce_rx_ticks,
1001 sc->bce_rx_ticks = DEFAULT_RX_TICKS;
1004 /* Disabling both RX ticks and RX trips will prevent interrupts. */
1005 if ((bce_rx_quick_cons_trip == 0) && (bce_rx_ticks == 0)) {
1006 BCE_PRINTF("%s(%d): Cannot set both hw.bce.rx_ticks and "
1007 "hw.bce.rx_quick_cons_trip to 0. Setting default values.\n",
1008 __FILE__, __LINE__);
1009 sc->bce_rx_ticks = DEFAULT_RX_TICKS;
1010 sc->bce_rx_quick_cons_trip = DEFAULT_RX_QUICK_CONS_TRIP;
1013 /* Disabling both TX ticks and TX trips will prevent interrupts. */
1014 if ((bce_tx_quick_cons_trip == 0) && (bce_tx_ticks == 0)) {
1015 BCE_PRINTF("%s(%d): Cannot set both hw.bce.tx_ticks and "
1016 "hw.bce.tx_quick_cons_trip to 0. Setting default values.\n",
1017 __FILE__, __LINE__);
1018 sc->bce_tx_ticks = DEFAULT_TX_TICKS;
1019 sc->bce_tx_quick_cons_trip = DEFAULT_TX_QUICK_CONS_TRIP;
1024 /****************************************************************************/
1025 /* Device attach function. */
1027 /* Allocates device resources, performs secondary chip identification, */
1028 /* resets and initializes the hardware, and initializes driver instance */
1032 /* 0 on success, positive value on failure. */
1033 /****************************************************************************/
1035 bce_attach(device_t dev)
1037 struct bce_softc *sc;
1040 int count, error, rc = 0, rid;
1042 sc = device_get_softc(dev);
1045 DBENTER(BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
1047 sc->bce_unit = device_get_unit(dev);
1049 /* Set initial device and PHY flags */
1051 sc->bce_phy_flags = 0;
1053 bce_set_tunables(sc);
1055 pci_enable_busmaster(dev);
1057 /* Allocate PCI memory resources. */
1059 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1062 if (sc->bce_res_mem == NULL) {
1063 BCE_PRINTF("%s(%d): PCI memory allocation failed\n",
1064 __FILE__, __LINE__);
1066 goto bce_attach_fail;
1069 /* Get various resource handles. */
1070 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
1071 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
1072 sc->bce_vhandle = (vm_offset_t) rman_get_virtual(sc->bce_res_mem);
1074 bce_probe_pci_caps(dev, sc);
1079 /* Try allocating MSI-X interrupts. */
1080 if ((sc->bce_cap_flags & BCE_MSIX_CAPABLE_FLAG) &&
1081 (bce_msi_enable >= 2) &&
1082 ((sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1083 &rid, RF_ACTIVE)) != NULL)) {
1085 msi_needed = count = 1;
1087 if (((error = pci_alloc_msix(dev, &count)) != 0) ||
1088 (count != msi_needed)) {
1089 BCE_PRINTF("%s(%d): MSI-X allocation failed! Requested = %d,"
1090 "Received = %d, error = %d\n", __FILE__, __LINE__,
1091 msi_needed, count, error);
1093 pci_release_msi(dev);
1094 bus_release_resource(dev, SYS_RES_MEMORY, rid,
1096 sc->bce_res_irq = NULL;
1098 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI-X interrupt.\n",
1100 sc->bce_flags |= BCE_USING_MSIX_FLAG;
1105 /* Try allocating a MSI interrupt. */
1106 if ((sc->bce_cap_flags & BCE_MSI_CAPABLE_FLAG) &&
1107 (bce_msi_enable >= 1) && (count == 0)) {
1109 if ((error = pci_alloc_msi(dev, &count)) != 0) {
1110 BCE_PRINTF("%s(%d): MSI allocation failed! "
1111 "error = %d\n", __FILE__, __LINE__, error);
1113 pci_release_msi(dev);
1115 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI "
1116 "interrupt.\n", __FUNCTION__);
1117 sc->bce_flags |= BCE_USING_MSI_FLAG;
1118 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
1119 sc->bce_flags |= BCE_ONE_SHOT_MSI_FLAG;
1124 /* Try allocating a legacy interrupt. */
1126 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using INTx interrupt.\n",
1131 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
1132 &rid, RF_ACTIVE | (count != 0 ? 0 : RF_SHAREABLE));
1134 /* Report any IRQ allocation errors. */
1135 if (sc->bce_res_irq == NULL) {
1136 BCE_PRINTF("%s(%d): PCI map interrupt failed!\n",
1137 __FILE__, __LINE__);
1139 goto bce_attach_fail;
1142 /* Initialize mutex for the current device instance. */
1143 BCE_LOCK_INIT(sc, device_get_nameunit(dev));
1146 * Configure byte swap and enable indirect register access.
1147 * Rely on CPU to do target byte swapping on big endian systems.
1148 * Access to registers outside of PCI configurtion space are not
1149 * valid until this is done.
1151 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
1152 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
1153 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
1155 /* Save ASIC revsion info. */
1156 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
1158 /* Weed out any non-production controller revisions. */
1159 switch(BCE_CHIP_ID(sc)) {
1160 case BCE_CHIP_ID_5706_A0:
1161 case BCE_CHIP_ID_5706_A1:
1162 case BCE_CHIP_ID_5708_A0:
1163 case BCE_CHIP_ID_5708_B0:
1164 case BCE_CHIP_ID_5709_A0:
1165 case BCE_CHIP_ID_5709_B0:
1166 case BCE_CHIP_ID_5709_B1:
1167 case BCE_CHIP_ID_5709_B2:
1168 BCE_PRINTF("%s(%d): Unsupported controller "
1169 "revision (%c%d)!\n", __FILE__, __LINE__,
1170 (((pci_read_config(dev, PCIR_REVID, 4) &
1171 0xf0) >> 4) + 'A'), (pci_read_config(dev,
1172 PCIR_REVID, 4) & 0xf));
1174 goto bce_attach_fail;
1178 * The embedded PCIe to PCI-X bridge (EPB)
1179 * in the 5708 cannot address memory above
1180 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
1182 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
1183 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
1185 sc->max_bus_addr = BUS_SPACE_MAXADDR;
1188 * Find the base address for shared memory access.
1189 * Newer versions of bootcode use a signature and offset
1190 * while older versions use a fixed address.
1192 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
1193 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
1194 /* Multi-port devices use different offsets in shared memory. */
1195 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0 +
1196 (pci_get_function(sc->bce_dev) << 2));
1198 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
1200 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): bce_shmem_base = 0x%08X\n",
1201 __FUNCTION__, sc->bce_shmem_base);
1203 /* Fetch the bootcode revision. */
1204 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
1205 for (int i = 0, j = 0; i < 3; i++) {
1208 num = (u8) (val >> (24 - (i * 8)));
1209 for (int k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
1210 if (num >= k || !skip0 || k == 1) {
1211 sc->bce_bc_ver[j++] = (num / k) + '0';
1217 sc->bce_bc_ver[j++] = '.';
1220 /* Check if any management firwmare is enabled. */
1221 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
1222 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
1223 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
1225 /* Allow time for firmware to enter the running state. */
1226 for (int i = 0; i < 30; i++) {
1227 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
1228 if (val & BCE_CONDITION_MFW_RUN_MASK)
1233 /* Check if management firmware is running. */
1234 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
1235 val &= BCE_CONDITION_MFW_RUN_MASK;
1236 if ((val != BCE_CONDITION_MFW_RUN_UNKNOWN) &&
1237 (val != BCE_CONDITION_MFW_RUN_NONE)) {
1238 u32 addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
1241 /* Read the management firmware version string. */
1242 for (int j = 0; j < 3; j++) {
1243 val = bce_reg_rd_ind(sc, addr + j * 4);
1245 memcpy(&sc->bce_mfw_ver[i], &val, 4);
1249 /* May cause firmware synchronization timeouts. */
1250 BCE_PRINTF("%s(%d): Management firmware enabled "
1251 "but not running!\n", __FILE__, __LINE__);
1252 strcpy(sc->bce_mfw_ver, "NOT RUNNING!");
1254 /* ToDo: Any action the driver should take? */
1258 /* Get PCI bus information (speed and type). */
1259 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
1260 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
1263 sc->bce_flags |= BCE_PCIX_FLAG;
1265 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS);
1267 clkreg &= BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
1269 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
1270 sc->bus_speed_mhz = 133;
1273 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
1274 sc->bus_speed_mhz = 100;
1277 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
1278 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
1279 sc->bus_speed_mhz = 66;
1282 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
1283 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
1284 sc->bus_speed_mhz = 50;
1287 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
1288 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
1289 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
1290 sc->bus_speed_mhz = 33;
1294 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
1295 sc->bus_speed_mhz = 66;
1297 sc->bus_speed_mhz = 33;
1300 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
1301 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
1303 /* Find the media type for the adapter. */
1306 /* Reset controller and announce to bootcode that driver is present. */
1307 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
1308 BCE_PRINTF("%s(%d): Controller reset failed!\n",
1309 __FILE__, __LINE__);
1311 goto bce_attach_fail;
1314 /* Initialize the controller. */
1315 if (bce_chipinit(sc)) {
1316 BCE_PRINTF("%s(%d): Controller initialization failed!\n",
1317 __FILE__, __LINE__);
1319 goto bce_attach_fail;
1322 /* Perform NVRAM test. */
1323 if (bce_nvram_test(sc)) {
1324 BCE_PRINTF("%s(%d): NVRAM test failed!\n",
1325 __FILE__, __LINE__);
1327 goto bce_attach_fail;
1330 /* Fetch the permanent Ethernet MAC address. */
1331 bce_get_mac_addr(sc);
1333 /* Update statistics once every second. */
1334 sc->bce_stats_ticks = 1000000 & 0xffff00;
1336 /* Store data needed by PHY driver for backplane applications */
1337 sc->bce_shared_hw_cfg = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
1338 sc->bce_port_hw_cfg = bce_shmem_rd(sc, BCE_PORT_HW_CFG_CONFIG);
1340 /* Allocate DMA memory resources. */
1341 if (bce_dma_alloc(dev)) {
1342 BCE_PRINTF("%s(%d): DMA resource allocation failed!\n",
1343 __FILE__, __LINE__);
1345 goto bce_attach_fail;
1348 /* Allocate an ifnet structure. */
1349 ifp = sc->bce_ifp = if_alloc(IFT_ETHER);
1351 BCE_PRINTF("%s(%d): Interface allocation failed!\n",
1352 __FILE__, __LINE__);
1354 goto bce_attach_fail;
1357 /* Initialize the ifnet interface. */
1359 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1360 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1361 ifp->if_ioctl = bce_ioctl;
1362 ifp->if_start = bce_start;
1363 ifp->if_init = bce_init;
1364 ifp->if_mtu = ETHERMTU;
1366 if (bce_tso_enable) {
1367 ifp->if_hwassist = BCE_IF_HWASSIST | CSUM_TSO;
1368 ifp->if_capabilities = BCE_IF_CAPABILITIES | IFCAP_TSO4 |
1371 ifp->if_hwassist = BCE_IF_HWASSIST;
1372 ifp->if_capabilities = BCE_IF_CAPABILITIES;
1375 #if __FreeBSD_version >= 800505
1377 * Introducing IFCAP_LINKSTATE didn't bump __FreeBSD_version
1378 * so it's approximate value.
1380 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0)
1381 ifp->if_capabilities |= IFCAP_LINKSTATE;
1384 ifp->if_capenable = ifp->if_capabilities;
1387 * Assume standard mbuf sizes for buffer allocation.
1388 * This may change later if the MTU size is set to
1389 * something other than 1500.
1391 bce_get_rx_buffer_sizes(sc,
1392 (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN));
1394 /* Recalculate our buffer allocation sizes. */
1395 ifp->if_snd.ifq_drv_maxlen = USABLE_TX_BD_ALLOC;
1396 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
1397 IFQ_SET_READY(&ifp->if_snd);
1399 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
1400 ifp->if_baudrate = IF_Mbps(2500ULL);
1402 ifp->if_baudrate = IF_Mbps(1000);
1404 /* Handle any special PHY initialization for SerDes PHYs. */
1407 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0) {
1408 ifmedia_init(&sc->bce_ifmedia, IFM_IMASK, bce_ifmedia_upd,
1411 * We can't manually override remote PHY's link and assume
1412 * PHY port configuration(Fiber or TP) is not changed after
1413 * device attach. This may not be correct though.
1415 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) != 0) {
1416 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG) {
1417 ifmedia_add(&sc->bce_ifmedia,
1418 IFM_ETHER | IFM_2500_SX, 0, NULL);
1419 ifmedia_add(&sc->bce_ifmedia,
1420 IFM_ETHER | IFM_2500_SX | IFM_FDX, 0, NULL);
1422 ifmedia_add(&sc->bce_ifmedia,
1423 IFM_ETHER | IFM_1000_SX, 0, NULL);
1424 ifmedia_add(&sc->bce_ifmedia,
1425 IFM_ETHER | IFM_1000_SX | IFM_FDX, 0, NULL);
1427 ifmedia_add(&sc->bce_ifmedia,
1428 IFM_ETHER | IFM_10_T, 0, NULL);
1429 ifmedia_add(&sc->bce_ifmedia,
1430 IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL);
1431 ifmedia_add(&sc->bce_ifmedia,
1432 IFM_ETHER | IFM_100_TX, 0, NULL);
1433 ifmedia_add(&sc->bce_ifmedia,
1434 IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL);
1435 ifmedia_add(&sc->bce_ifmedia,
1436 IFM_ETHER | IFM_1000_T, 0, NULL);
1437 ifmedia_add(&sc->bce_ifmedia,
1438 IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
1440 ifmedia_add(&sc->bce_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL);
1441 ifmedia_set(&sc->bce_ifmedia, IFM_ETHER | IFM_AUTO);
1442 sc->bce_ifmedia.ifm_media = sc->bce_ifmedia.ifm_cur->ifm_media;
1444 /* MII child bus by attaching the PHY. */
1445 rc = mii_attach(dev, &sc->bce_miibus, ifp, bce_ifmedia_upd,
1446 bce_ifmedia_sts, BMSR_DEFCAPMASK, sc->bce_phy_addr,
1447 MII_OFFSET_ANY, MIIF_DOPAUSE);
1449 BCE_PRINTF("%s(%d): attaching PHYs failed\n", __FILE__,
1451 goto bce_attach_fail;
1455 /* Attach to the Ethernet interface list. */
1456 ether_ifattach(ifp, sc->eaddr);
1458 #if __FreeBSD_version < 500000
1459 callout_init(&sc->bce_tick_callout);
1460 callout_init(&sc->bce_pulse_callout);
1462 callout_init_mtx(&sc->bce_tick_callout, &sc->bce_mtx, 0);
1463 callout_init_mtx(&sc->bce_pulse_callout, &sc->bce_mtx, 0);
1466 /* Hookup IRQ last. */
1467 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_TYPE_NET | INTR_MPSAFE,
1468 NULL, bce_intr, sc, &sc->bce_intrhand);
1471 BCE_PRINTF("%s(%d): Failed to setup IRQ!\n",
1472 __FILE__, __LINE__);
1474 goto bce_attach_exit;
1478 * At this point we've acquired all the resources
1479 * we need to run so there's no turning back, we're
1480 * cleared for launch.
1483 /* Print some important debugging info. */
1484 DBRUNMSG(BCE_INFO, bce_dump_driver_state(sc));
1486 /* Add the supported sysctls to the kernel. */
1487 bce_add_sysctls(sc);
1492 * The chip reset earlier notified the bootcode that
1493 * a driver is present. We now need to start our pulse
1494 * routine so that the bootcode is reminded that we're
1499 bce_mgmt_init_locked(sc);
1502 /* Finally, print some useful adapter info */
1503 bce_print_adapter_info(sc);
1504 DBPRINT(sc, BCE_FATAL, "%s(): sc = %p\n",
1507 goto bce_attach_exit;
1510 bce_release_resources(sc);
1514 DBEXIT(BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
1520 /****************************************************************************/
1521 /* Device detach function. */
1523 /* Stops the controller, resets the controller, and releases resources. */
1526 /* 0 on success, positive value on failure. */
1527 /****************************************************************************/
1529 bce_detach(device_t dev)
1531 struct bce_softc *sc = device_get_softc(dev);
1535 DBENTER(BCE_VERBOSE_UNLOAD | BCE_VERBOSE_RESET);
1539 /* Stop and reset the controller. */
1542 /* Stop the pulse so the bootcode can go to driver absent state. */
1543 callout_stop(&sc->bce_pulse_callout);
1546 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1547 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1549 msg = BCE_DRV_MSG_CODE_UNLOAD;
1554 ether_ifdetach(ifp);
1556 /* If we have a child device on the MII bus remove it too. */
1557 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0)
1558 ifmedia_removeall(&sc->bce_ifmedia);
1560 bus_generic_detach(dev);
1561 device_delete_child(dev, sc->bce_miibus);
1564 /* Release all remaining resources. */
1565 bce_release_resources(sc);
1567 DBEXIT(BCE_VERBOSE_UNLOAD | BCE_VERBOSE_RESET);
1573 /****************************************************************************/
1574 /* Device shutdown function. */
1576 /* Stops and resets the controller. */
1579 /* 0 on success, positive value on failure. */
1580 /****************************************************************************/
1582 bce_shutdown(device_t dev)
1584 struct bce_softc *sc = device_get_softc(dev);
1587 DBENTER(BCE_VERBOSE);
1591 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1592 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1594 msg = BCE_DRV_MSG_CODE_UNLOAD;
1598 DBEXIT(BCE_VERBOSE);
1605 /****************************************************************************/
1606 /* Register read. */
1609 /* The value of the register. */
1610 /****************************************************************************/
1612 bce_reg_rd(struct bce_softc *sc, u32 offset)
1614 u32 val = REG_RD(sc, offset);
1615 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1616 __FUNCTION__, offset, val);
1621 /****************************************************************************/
1622 /* Register write (16 bit). */
1626 /****************************************************************************/
1628 bce_reg_wr16(struct bce_softc *sc, u32 offset, u16 val)
1630 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%04X\n",
1631 __FUNCTION__, offset, val);
1632 REG_WR16(sc, offset, val);
1636 /****************************************************************************/
1637 /* Register write. */
1641 /****************************************************************************/
1643 bce_reg_wr(struct bce_softc *sc, u32 offset, u32 val)
1645 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1646 __FUNCTION__, offset, val);
1647 REG_WR(sc, offset, val);
1651 /****************************************************************************/
1652 /* Indirect register read. */
1654 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1655 /* configuration space. Using this mechanism avoids issues with posted */
1656 /* reads but is much slower than memory-mapped I/O. */
1659 /* The value of the register. */
1660 /****************************************************************************/
1662 bce_reg_rd_ind(struct bce_softc *sc, u32 offset)
1667 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1671 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1672 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1673 __FUNCTION__, offset, val);
1677 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1682 /****************************************************************************/
1683 /* Indirect register write. */
1685 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1686 /* configuration space. Using this mechanism avoids issues with posted */
1687 /* writes but is muchh slower than memory-mapped I/O. */
1691 /****************************************************************************/
1693 bce_reg_wr_ind(struct bce_softc *sc, u32 offset, u32 val)
1698 DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
1699 __FUNCTION__, offset, val);
1701 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1702 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1706 /****************************************************************************/
1707 /* Shared memory write. */
1709 /* Writes NetXtreme II shared memory region. */
1713 /****************************************************************************/
1715 bce_shmem_wr(struct bce_softc *sc, u32 offset, u32 val)
1717 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): Writing 0x%08X to "
1718 "0x%08X\n", __FUNCTION__, val, offset);
1720 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1724 /****************************************************************************/
1725 /* Shared memory read. */
1727 /* Reads NetXtreme II shared memory region. */
1730 /* The 32 bit value read. */
1731 /****************************************************************************/
1733 bce_shmem_rd(struct bce_softc *sc, u32 offset)
1735 u32 val = bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1737 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "%s(): Reading 0x%08X from "
1738 "0x%08X\n", __FUNCTION__, val, offset);
1745 /****************************************************************************/
1746 /* Context memory read. */
1748 /* The NetXtreme II controller uses context memory to track connection */
1749 /* information for L2 and higher network protocols. */
1752 /* The requested 32 bit value of context memory. */
1753 /****************************************************************************/
1755 bce_ctx_rd(struct bce_softc *sc, u32 cid_addr, u32 ctx_offset)
1757 u32 idx, offset, retry_cnt = 5, val;
1759 DBRUNIF((cid_addr > MAX_CID_ADDR || ctx_offset & 0x3 ||
1760 cid_addr & CTX_MASK), BCE_PRINTF("%s(): Invalid CID "
1761 "address: 0x%08X.\n", __FUNCTION__, cid_addr));
1763 offset = ctx_offset + cid_addr;
1765 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
1767 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_READ_REQ));
1769 for (idx = 0; idx < retry_cnt; idx++) {
1770 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1771 if ((val & BCE_CTX_CTX_CTRL_READ_REQ) == 0)
1776 if (val & BCE_CTX_CTX_CTRL_READ_REQ)
1777 BCE_PRINTF("%s(%d); Unable to read CTX memory: "
1778 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1779 __FILE__, __LINE__, cid_addr, ctx_offset);
1781 val = REG_RD(sc, BCE_CTX_CTX_DATA);
1783 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1784 val = REG_RD(sc, BCE_CTX_DATA);
1787 DBPRINT(sc, BCE_EXTREME_CTX, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
1788 "val = 0x%08X\n", __FUNCTION__, cid_addr, ctx_offset, val);
1795 /****************************************************************************/
1796 /* Context memory write. */
1798 /* The NetXtreme II controller uses context memory to track connection */
1799 /* information for L2 and higher network protocols. */
1803 /****************************************************************************/
1805 bce_ctx_wr(struct bce_softc *sc, u32 cid_addr, u32 ctx_offset, u32 ctx_val)
1807 u32 idx, offset = ctx_offset + cid_addr;
1808 u32 val, retry_cnt = 5;
1810 DBPRINT(sc, BCE_EXTREME_CTX, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
1811 "val = 0x%08X\n", __FUNCTION__, cid_addr, ctx_offset, ctx_val);
1813 DBRUNIF((cid_addr > MAX_CID_ADDR || ctx_offset & 0x3 || cid_addr & CTX_MASK),
1814 BCE_PRINTF("%s(): Invalid CID address: 0x%08X.\n",
1815 __FUNCTION__, cid_addr));
1817 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
1819 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1820 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1822 for (idx = 0; idx < retry_cnt; idx++) {
1823 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1824 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1829 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ)
1830 BCE_PRINTF("%s(%d); Unable to write CTX memory: "
1831 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1832 __FILE__, __LINE__, cid_addr, ctx_offset);
1835 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1836 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1841 /****************************************************************************/
1842 /* PHY register read. */
1844 /* Implements register reads on the MII bus. */
1847 /* The value of the register. */
1848 /****************************************************************************/
1850 bce_miibus_read_reg(device_t dev, int phy, int reg)
1852 struct bce_softc *sc;
1856 sc = device_get_softc(dev);
1859 * The 5709S PHY is an IEEE Clause 45 PHY
1860 * with special mappings to work with IEEE
1861 * Clause 22 register accesses.
1863 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
1864 if (reg >= MII_BMCR && reg <= MII_ANLPRNP)
1868 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1869 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1870 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1872 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1873 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1879 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1880 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1881 BCE_EMAC_MDIO_COMM_START_BUSY;
1882 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1884 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1887 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1888 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1891 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1892 val &= BCE_EMAC_MDIO_COMM_DATA;
1898 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1899 BCE_PRINTF("%s(%d): Error: PHY read timeout! phy = %d, "
1900 "reg = 0x%04X\n", __FILE__, __LINE__, phy, reg);
1903 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1907 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1908 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1909 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1911 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1912 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1917 DB_PRINT_PHY_REG(reg, val);
1918 return (val & 0xffff);
1922 /****************************************************************************/
1923 /* PHY register write. */
1925 /* Implements register writes on the MII bus. */
1928 /* The value of the register. */
1929 /****************************************************************************/
1931 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1933 struct bce_softc *sc;
1937 sc = device_get_softc(dev);
1939 DB_PRINT_PHY_REG(reg, val);
1942 * The 5709S PHY is an IEEE Clause 45 PHY
1943 * with special mappings to work with IEEE
1944 * Clause 22 register accesses.
1946 if ((sc->bce_phy_flags & BCE_PHY_IEEE_CLAUSE_45_FLAG) != 0) {
1947 if (reg >= MII_BMCR && reg <= MII_ANLPRNP)
1951 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1952 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1953 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1955 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1956 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1961 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1962 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1963 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1964 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1966 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1969 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1970 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1976 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1977 BCE_PRINTF("%s(%d): PHY write timeout!\n",
1978 __FILE__, __LINE__);
1980 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1981 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1982 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1984 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1985 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1994 /****************************************************************************/
1995 /* MII bus status change. */
1997 /* Called by the MII bus driver when the PHY establishes link to set the */
1998 /* MAC interface registers. */
2002 /****************************************************************************/
2004 bce_miibus_statchg(device_t dev)
2006 struct bce_softc *sc;
2007 struct mii_data *mii;
2008 struct ifmediareq ifmr;
2009 int media_active, media_status, val;
2011 sc = device_get_softc(dev);
2013 DBENTER(BCE_VERBOSE_PHY);
2015 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0) {
2016 bzero(&ifmr, sizeof(ifmr));
2017 bce_ifmedia_sts_rphy(sc, &ifmr);
2018 media_active = ifmr.ifm_active;
2019 media_status = ifmr.ifm_status;
2021 mii = device_get_softc(sc->bce_miibus);
2022 media_active = mii->mii_media_active;
2023 media_status = mii->mii_media_status;
2026 /* Ignore invalid media status. */
2027 if ((media_status & (IFM_ACTIVE | IFM_AVALID)) !=
2028 (IFM_ACTIVE | IFM_AVALID))
2029 goto bce_miibus_statchg_exit;
2031 val = REG_RD(sc, BCE_EMAC_MODE);
2032 val &= ~(BCE_EMAC_MODE_PORT | BCE_EMAC_MODE_HALF_DUPLEX |
2033 BCE_EMAC_MODE_MAC_LOOP | BCE_EMAC_MODE_FORCE_LINK |
2036 /* Set MII or GMII interface based on the PHY speed. */
2037 switch (IFM_SUBTYPE(media_active)) {
2039 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
2040 DBPRINT(sc, BCE_INFO_PHY,
2041 "Enabling 10Mb interface.\n");
2042 val |= BCE_EMAC_MODE_PORT_MII_10;
2047 DBPRINT(sc, BCE_INFO_PHY, "Enabling MII interface.\n");
2048 val |= BCE_EMAC_MODE_PORT_MII;
2051 DBPRINT(sc, BCE_INFO_PHY, "Enabling 2.5G MAC mode.\n");
2052 val |= BCE_EMAC_MODE_25G;
2056 DBPRINT(sc, BCE_INFO_PHY, "Enabling GMII interface.\n");
2057 val |= BCE_EMAC_MODE_PORT_GMII;
2060 DBPRINT(sc, BCE_INFO_PHY, "Unknown link speed, enabling "
2061 "default GMII interface.\n");
2062 val |= BCE_EMAC_MODE_PORT_GMII;
2065 /* Set half or full duplex based on PHY settings. */
2066 if ((IFM_OPTIONS(media_active) & IFM_FDX) == 0) {
2067 DBPRINT(sc, BCE_INFO_PHY,
2068 "Setting Half-Duplex interface.\n");
2069 val |= BCE_EMAC_MODE_HALF_DUPLEX;
2071 DBPRINT(sc, BCE_INFO_PHY,
2072 "Setting Full-Duplex interface.\n");
2074 REG_WR(sc, BCE_EMAC_MODE, val);
2076 if ((IFM_OPTIONS(media_active) & IFM_ETH_RXPAUSE) != 0) {
2077 DBPRINT(sc, BCE_INFO_PHY,
2078 "%s(): Enabling RX flow control.\n", __FUNCTION__);
2079 BCE_SETBIT(sc, BCE_EMAC_RX_MODE, BCE_EMAC_RX_MODE_FLOW_EN);
2081 DBPRINT(sc, BCE_INFO_PHY,
2082 "%s(): Disabling RX flow control.\n", __FUNCTION__);
2083 BCE_CLRBIT(sc, BCE_EMAC_RX_MODE, BCE_EMAC_RX_MODE_FLOW_EN);
2086 if ((IFM_OPTIONS(media_active) & IFM_ETH_TXPAUSE) != 0) {
2087 DBPRINT(sc, BCE_INFO_PHY,
2088 "%s(): Enabling TX flow control.\n", __FUNCTION__);
2089 BCE_SETBIT(sc, BCE_EMAC_TX_MODE, BCE_EMAC_TX_MODE_FLOW_EN);
2090 sc->bce_flags |= BCE_USING_TX_FLOW_CONTROL;
2092 DBPRINT(sc, BCE_INFO_PHY,
2093 "%s(): Disabling TX flow control.\n", __FUNCTION__);
2094 BCE_CLRBIT(sc, BCE_EMAC_TX_MODE, BCE_EMAC_TX_MODE_FLOW_EN);
2095 sc->bce_flags &= ~BCE_USING_TX_FLOW_CONTROL;
2098 /* ToDo: Update watermarks in bce_init_rx_context(). */
2100 bce_miibus_statchg_exit:
2101 DBEXIT(BCE_VERBOSE_PHY);
2105 /****************************************************************************/
2106 /* Acquire NVRAM lock. */
2108 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
2109 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
2110 /* for use by the driver. */
2113 /* 0 on success, positive value on failure. */
2114 /****************************************************************************/
2116 bce_acquire_nvram_lock(struct bce_softc *sc)
2121 DBENTER(BCE_VERBOSE_NVRAM);
2123 /* Request access to the flash interface. */
2124 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
2125 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2126 val = REG_RD(sc, BCE_NVM_SW_ARB);
2127 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
2133 if (j >= NVRAM_TIMEOUT_COUNT) {
2134 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
2138 DBEXIT(BCE_VERBOSE_NVRAM);
2143 /****************************************************************************/
2144 /* Release NVRAM lock. */
2146 /* When the caller is finished accessing NVRAM the lock must be released. */
2147 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
2148 /* for use by the driver. */
2151 /* 0 on success, positive value on failure. */
2152 /****************************************************************************/
2154 bce_release_nvram_lock(struct bce_softc *sc)
2159 DBENTER(BCE_VERBOSE_NVRAM);
2162 * Relinquish nvram interface.
2164 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
2166 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2167 val = REG_RD(sc, BCE_NVM_SW_ARB);
2168 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
2174 if (j >= NVRAM_TIMEOUT_COUNT) {
2175 DBPRINT(sc, BCE_WARN, "Timeout releasing NVRAM lock!\n");
2179 DBEXIT(BCE_VERBOSE_NVRAM);
2184 #ifdef BCE_NVRAM_WRITE_SUPPORT
2185 /****************************************************************************/
2186 /* Enable NVRAM write access. */
2188 /* Before writing to NVRAM the caller must enable NVRAM writes. */
2191 /* 0 on success, positive value on failure. */
2192 /****************************************************************************/
2194 bce_enable_nvram_write(struct bce_softc *sc)
2199 DBENTER(BCE_VERBOSE_NVRAM);
2201 val = REG_RD(sc, BCE_MISC_CFG);
2202 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
2204 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2207 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2208 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
2210 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2213 val = REG_RD(sc, BCE_NVM_COMMAND);
2214 if (val & BCE_NVM_COMMAND_DONE)
2218 if (j >= NVRAM_TIMEOUT_COUNT) {
2219 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
2224 DBENTER(BCE_VERBOSE_NVRAM);
2229 /****************************************************************************/
2230 /* Disable NVRAM write access. */
2232 /* When the caller is finished writing to NVRAM write access must be */
2237 /****************************************************************************/
2239 bce_disable_nvram_write(struct bce_softc *sc)
2243 DBENTER(BCE_VERBOSE_NVRAM);
2245 val = REG_RD(sc, BCE_MISC_CFG);
2246 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
2248 DBEXIT(BCE_VERBOSE_NVRAM);
2254 /****************************************************************************/
2255 /* Enable NVRAM access. */
2257 /* Before accessing NVRAM for read or write operations the caller must */
2258 /* enabled NVRAM access. */
2262 /****************************************************************************/
2264 bce_enable_nvram_access(struct bce_softc *sc)
2268 DBENTER(BCE_VERBOSE_NVRAM);
2270 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
2271 /* Enable both bits, even on read. */
2272 REG_WR(sc, BCE_NVM_ACCESS_ENABLE, val |
2273 BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
2275 DBEXIT(BCE_VERBOSE_NVRAM);
2279 /****************************************************************************/
2280 /* Disable NVRAM access. */
2282 /* When the caller is finished accessing NVRAM access must be disabled. */
2286 /****************************************************************************/
2288 bce_disable_nvram_access(struct bce_softc *sc)
2292 DBENTER(BCE_VERBOSE_NVRAM);
2294 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
2296 /* Disable both bits, even after read. */
2297 REG_WR(sc, BCE_NVM_ACCESS_ENABLE, val &
2298 ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
2300 DBEXIT(BCE_VERBOSE_NVRAM);
2304 #ifdef BCE_NVRAM_WRITE_SUPPORT
2305 /****************************************************************************/
2306 /* Erase NVRAM page before writing. */
2308 /* Non-buffered flash parts require that a page be erased before it is */
2312 /* 0 on success, positive value on failure. */
2313 /****************************************************************************/
2315 bce_nvram_erase_page(struct bce_softc *sc, u32 offset)
2320 DBENTER(BCE_VERBOSE_NVRAM);
2322 /* Buffered flash doesn't require an erase. */
2323 if (sc->bce_flash_info->flags & BCE_NV_BUFFERED)
2324 goto bce_nvram_erase_page_exit;
2326 /* Build an erase command. */
2327 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
2328 BCE_NVM_COMMAND_DOIT;
2331 * Clear the DONE bit separately, set the NVRAM adress to erase,
2332 * and issue the erase command.
2334 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2335 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2336 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2338 /* Wait for completion. */
2339 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2344 val = REG_RD(sc, BCE_NVM_COMMAND);
2345 if (val & BCE_NVM_COMMAND_DONE)
2349 if (j >= NVRAM_TIMEOUT_COUNT) {
2350 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
2354 bce_nvram_erase_page_exit:
2355 DBEXIT(BCE_VERBOSE_NVRAM);
2358 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2361 /****************************************************************************/
2362 /* Read a dword (32 bits) from NVRAM. */
2364 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
2365 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
2368 /* 0 on success and the 32 bit value read, positive value on failure. */
2369 /****************************************************************************/
2371 bce_nvram_read_dword(struct bce_softc *sc,
2372 u32 offset, u8 *ret_val, u32 cmd_flags)
2377 DBENTER(BCE_EXTREME_NVRAM);
2379 /* Build the command word. */
2380 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
2382 /* Calculate the offset for buffered flash if translation is used. */
2383 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
2384 offset = ((offset / sc->bce_flash_info->page_size) <<
2385 sc->bce_flash_info->page_bits) +
2386 (offset % sc->bce_flash_info->page_size);
2390 * Clear the DONE bit separately, set the address to read,
2391 * and issue the read.
2393 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2394 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2395 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2397 /* Wait for completion. */
2398 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
2403 val = REG_RD(sc, BCE_NVM_COMMAND);
2404 if (val & BCE_NVM_COMMAND_DONE) {
2405 val = REG_RD(sc, BCE_NVM_READ);
2407 val = bce_be32toh(val);
2408 memcpy(ret_val, &val, 4);
2413 /* Check for errors. */
2414 if (i >= NVRAM_TIMEOUT_COUNT) {
2415 BCE_PRINTF("%s(%d): Timeout error reading NVRAM at "
2416 "offset 0x%08X!\n", __FILE__, __LINE__, offset);
2420 DBEXIT(BCE_EXTREME_NVRAM);
2425 #ifdef BCE_NVRAM_WRITE_SUPPORT
2426 /****************************************************************************/
2427 /* Write a dword (32 bits) to NVRAM. */
2429 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
2430 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
2431 /* enabled NVRAM write access. */
2434 /* 0 on success, positive value on failure. */
2435 /****************************************************************************/
2437 bce_nvram_write_dword(struct bce_softc *sc, u32 offset, u8 *val,
2443 DBENTER(BCE_VERBOSE_NVRAM);
2445 /* Build the command word. */
2446 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
2448 /* Calculate the offset for buffered flash if translation is used. */
2449 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
2450 offset = ((offset / sc->bce_flash_info->page_size) <<
2451 sc->bce_flash_info->page_bits) +
2452 (offset % sc->bce_flash_info->page_size);
2456 * Clear the DONE bit separately, convert NVRAM data to big-endian,
2457 * set the NVRAM address to write, and issue the write command
2459 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
2460 memcpy(&val32, val, 4);
2461 val32 = htobe32(val32);
2462 REG_WR(sc, BCE_NVM_WRITE, val32);
2463 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
2464 REG_WR(sc, BCE_NVM_COMMAND, cmd);
2466 /* Wait for completion. */
2467 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
2470 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
2473 if (j >= NVRAM_TIMEOUT_COUNT) {
2474 BCE_PRINTF("%s(%d): Timeout error writing NVRAM at "
2475 "offset 0x%08X\n", __FILE__, __LINE__, offset);
2479 DBEXIT(BCE_VERBOSE_NVRAM);
2482 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2485 /****************************************************************************/
2486 /* Initialize NVRAM access. */
2488 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
2489 /* access that device. */
2492 /* 0 on success, positive value on failure. */
2493 /****************************************************************************/
2495 bce_init_nvram(struct bce_softc *sc)
2498 int j, entry_count, rc = 0;
2499 const struct flash_spec *flash;
2501 DBENTER(BCE_VERBOSE_NVRAM);
2503 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
2504 sc->bce_flash_info = &flash_5709;
2505 goto bce_init_nvram_get_flash_size;
2508 /* Determine the selected interface. */
2509 val = REG_RD(sc, BCE_NVM_CFG1);
2511 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
2514 * Flash reconfiguration is required to support additional
2515 * NVRAM devices not directly supported in hardware.
2516 * Check if the flash interface was reconfigured
2520 if (val & 0x40000000) {
2521 /* Flash interface reconfigured by bootcode. */
2523 DBPRINT(sc,BCE_INFO_LOAD,
2524 "bce_init_nvram(): Flash WAS reconfigured.\n");
2526 for (j = 0, flash = &flash_table[0]; j < entry_count;
2528 if ((val & FLASH_BACKUP_STRAP_MASK) ==
2529 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
2530 sc->bce_flash_info = flash;
2535 /* Flash interface not yet reconfigured. */
2538 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Flash was NOT reconfigured.\n",
2541 if (val & (1 << 23))
2542 mask = FLASH_BACKUP_STRAP_MASK;
2544 mask = FLASH_STRAP_MASK;
2546 /* Look for the matching NVRAM device configuration data. */
2547 for (j = 0, flash = &flash_table[0]; j < entry_count; j++, flash++) {
2549 /* Check if the device matches any of the known devices. */
2550 if ((val & mask) == (flash->strapping & mask)) {
2551 /* Found a device match. */
2552 sc->bce_flash_info = flash;
2554 /* Request access to the flash interface. */
2555 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2558 /* Reconfigure the flash interface. */
2559 bce_enable_nvram_access(sc);
2560 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
2561 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
2562 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
2563 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
2564 bce_disable_nvram_access(sc);
2565 bce_release_nvram_lock(sc);
2572 /* Check if a matching device was found. */
2573 if (j == entry_count) {
2574 sc->bce_flash_info = NULL;
2575 BCE_PRINTF("%s(%d): Unknown Flash NVRAM found!\n",
2576 __FILE__, __LINE__);
2577 DBEXIT(BCE_VERBOSE_NVRAM);
2581 bce_init_nvram_get_flash_size:
2582 /* Write the flash config data to the shared memory interface. */
2583 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2);
2584 val &= BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
2586 sc->bce_flash_size = val;
2588 sc->bce_flash_size = sc->bce_flash_info->total_size;
2590 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Found %s, size = 0x%08X\n",
2591 __FUNCTION__, sc->bce_flash_info->name,
2592 sc->bce_flash_info->total_size);
2594 DBEXIT(BCE_VERBOSE_NVRAM);
2599 /****************************************************************************/
2600 /* Read an arbitrary range of data from NVRAM. */
2602 /* Prepares the NVRAM interface for access and reads the requested data */
2603 /* into the supplied buffer. */
2606 /* 0 on success and the data read, positive value on failure. */
2607 /****************************************************************************/
2609 bce_nvram_read(struct bce_softc *sc, u32 offset, u8 *ret_buf,
2613 u32 cmd_flags, offset32, len32, extra;
2615 DBENTER(BCE_VERBOSE_NVRAM);
2618 goto bce_nvram_read_exit;
2620 /* Request access to the flash interface. */
2621 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2622 goto bce_nvram_read_exit;
2624 /* Enable access to flash interface */
2625 bce_enable_nvram_access(sc);
2638 pre_len = 4 - (offset & 3);
2640 if (pre_len >= len32) {
2642 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
2645 cmd_flags = BCE_NVM_COMMAND_FIRST;
2648 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2653 memcpy(ret_buf, buf + (offset & 3), pre_len);
2661 extra = 4 - (len32 & 3);
2662 len32 = (len32 + 4) & ~3;
2669 cmd_flags = BCE_NVM_COMMAND_LAST;
2671 cmd_flags = BCE_NVM_COMMAND_FIRST |
2672 BCE_NVM_COMMAND_LAST;
2674 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2676 memcpy(ret_buf, buf, 4 - extra);
2678 else if (len32 > 0) {
2681 /* Read the first word. */
2685 cmd_flags = BCE_NVM_COMMAND_FIRST;
2687 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
2689 /* Advance to the next dword. */
2694 while (len32 > 4 && rc == 0) {
2695 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
2697 /* Advance to the next dword. */
2704 goto bce_nvram_read_locked_exit;
2706 cmd_flags = BCE_NVM_COMMAND_LAST;
2707 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
2709 memcpy(ret_buf, buf, 4 - extra);
2712 bce_nvram_read_locked_exit:
2713 /* Disable access to flash interface and release the lock. */
2714 bce_disable_nvram_access(sc);
2715 bce_release_nvram_lock(sc);
2717 bce_nvram_read_exit:
2718 DBEXIT(BCE_VERBOSE_NVRAM);
2723 #ifdef BCE_NVRAM_WRITE_SUPPORT
2724 /****************************************************************************/
2725 /* Write an arbitrary range of data from NVRAM. */
2727 /* Prepares the NVRAM interface for write access and writes the requested */
2728 /* data from the supplied buffer. The caller is responsible for */
2729 /* calculating any appropriate CRCs. */
2732 /* 0 on success, positive value on failure. */
2733 /****************************************************************************/
2735 bce_nvram_write(struct bce_softc *sc, u32 offset, u8 *data_buf,
2738 u32 written, offset32, len32;
2739 u8 *buf, start[4], end[4];
2741 int align_start, align_end;
2743 DBENTER(BCE_VERBOSE_NVRAM);
2748 align_start = align_end = 0;
2750 if ((align_start = (offset32 & 3))) {
2752 len32 += align_start;
2753 if ((rc = bce_nvram_read(sc, offset32, start, 4)))
2754 goto bce_nvram_write_exit;
2758 if ((len32 > 4) || !align_start) {
2759 align_end = 4 - (len32 & 3);
2761 if ((rc = bce_nvram_read(sc, offset32 + len32 - 4,
2763 goto bce_nvram_write_exit;
2768 if (align_start || align_end) {
2769 buf = malloc(len32, M_DEVBUF, M_NOWAIT);
2772 goto bce_nvram_write_exit;
2776 memcpy(buf, start, 4);
2780 memcpy(buf + len32 - 4, end, 4);
2782 memcpy(buf + align_start, data_buf, buf_size);
2786 while ((written < len32) && (rc == 0)) {
2787 u32 page_start, page_end, data_start, data_end;
2788 u32 addr, cmd_flags;
2790 u8 flash_buffer[264];
2792 /* Find the page_start addr */
2793 page_start = offset32 + written;
2794 page_start -= (page_start % sc->bce_flash_info->page_size);
2795 /* Find the page_end addr */
2796 page_end = page_start + sc->bce_flash_info->page_size;
2797 /* Find the data_start addr */
2798 data_start = (written == 0) ? offset32 : page_start;
2799 /* Find the data_end addr */
2800 data_end = (page_end > offset32 + len32) ?
2801 (offset32 + len32) : page_end;
2803 /* Request access to the flash interface. */
2804 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
2805 goto bce_nvram_write_exit;
2807 /* Enable access to flash interface */
2808 bce_enable_nvram_access(sc);
2810 cmd_flags = BCE_NVM_COMMAND_FIRST;
2811 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2814 /* Read the whole page into the buffer
2815 * (non-buffer flash only) */
2816 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
2817 if (j == (sc->bce_flash_info->page_size - 4)) {
2818 cmd_flags |= BCE_NVM_COMMAND_LAST;
2820 rc = bce_nvram_read_dword(sc,
2826 goto bce_nvram_write_locked_exit;
2832 /* Enable writes to flash interface (unlock write-protect) */
2833 if ((rc = bce_enable_nvram_write(sc)) != 0)
2834 goto bce_nvram_write_locked_exit;
2836 /* Erase the page */
2837 if ((rc = bce_nvram_erase_page(sc, page_start)) != 0)
2838 goto bce_nvram_write_locked_exit;
2840 /* Re-enable the write again for the actual write */
2841 bce_enable_nvram_write(sc);
2843 /* Loop to write back the buffer data from page_start to
2846 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2847 for (addr = page_start; addr < data_start;
2848 addr += 4, i += 4) {
2850 rc = bce_nvram_write_dword(sc, addr,
2851 &flash_buffer[i], cmd_flags);
2854 goto bce_nvram_write_locked_exit;
2860 /* Loop to write the new data from data_start to data_end */
2861 for (addr = data_start; addr < data_end; addr += 4, i++) {
2862 if ((addr == page_end - 4) ||
2863 ((sc->bce_flash_info->flags & BCE_NV_BUFFERED) &&
2864 (addr == data_end - 4))) {
2866 cmd_flags |= BCE_NVM_COMMAND_LAST;
2868 rc = bce_nvram_write_dword(sc, addr, buf,
2872 goto bce_nvram_write_locked_exit;
2878 /* Loop to write back the buffer data from data_end
2880 if (!(sc->bce_flash_info->flags & BCE_NV_BUFFERED)) {
2881 for (addr = data_end; addr < page_end;
2882 addr += 4, i += 4) {
2884 if (addr == page_end-4) {
2885 cmd_flags = BCE_NVM_COMMAND_LAST;
2887 rc = bce_nvram_write_dword(sc, addr,
2888 &flash_buffer[i], cmd_flags);
2891 goto bce_nvram_write_locked_exit;
2897 /* Disable writes to flash interface (lock write-protect) */
2898 bce_disable_nvram_write(sc);
2900 /* Disable access to flash interface */
2901 bce_disable_nvram_access(sc);
2902 bce_release_nvram_lock(sc);
2904 /* Increment written */
2905 written += data_end - data_start;
2908 goto bce_nvram_write_exit;
2910 bce_nvram_write_locked_exit:
2911 bce_disable_nvram_write(sc);
2912 bce_disable_nvram_access(sc);
2913 bce_release_nvram_lock(sc);
2915 bce_nvram_write_exit:
2916 if (align_start || align_end)
2917 free(buf, M_DEVBUF);
2919 DBEXIT(BCE_VERBOSE_NVRAM);
2922 #endif /* BCE_NVRAM_WRITE_SUPPORT */
2925 /****************************************************************************/
2926 /* Verifies that NVRAM is accessible and contains valid data. */
2928 /* Reads the configuration data from NVRAM and verifies that the CRC is */
2932 /* 0 on success, positive value on failure. */
2933 /****************************************************************************/
2935 bce_nvram_test(struct bce_softc *sc)
2937 u32 buf[BCE_NVRAM_SIZE / 4];
2938 u8 *data = (u8 *) buf;
2942 DBENTER(BCE_VERBOSE_NVRAM | BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
2945 * Check that the device NVRAM is valid by reading
2946 * the magic value at offset 0.
2948 if ((rc = bce_nvram_read(sc, 0, data, 4)) != 0) {
2949 BCE_PRINTF("%s(%d): Unable to read NVRAM!\n",
2950 __FILE__, __LINE__);
2951 goto bce_nvram_test_exit;
2955 * Verify that offset 0 of the NVRAM contains
2956 * a valid magic number.
2958 magic = bce_be32toh(buf[0]);
2959 if (magic != BCE_NVRAM_MAGIC) {
2961 BCE_PRINTF("%s(%d): Invalid NVRAM magic value! "
2962 "Expected: 0x%08X, Found: 0x%08X\n",
2963 __FILE__, __LINE__, BCE_NVRAM_MAGIC, magic);
2964 goto bce_nvram_test_exit;
2968 * Verify that the device NVRAM includes valid
2969 * configuration data.
2971 if ((rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE)) != 0) {
2972 BCE_PRINTF("%s(%d): Unable to read manufacturing "
2973 "Information from NVRAM!\n", __FILE__, __LINE__);
2974 goto bce_nvram_test_exit;
2977 csum = ether_crc32_le(data, 0x100);
2978 if (csum != BCE_CRC32_RESIDUAL) {
2980 BCE_PRINTF("%s(%d): Invalid manufacturing information "
2981 "NVRAM CRC! Expected: 0x%08X, Found: 0x%08X\n",
2982 __FILE__, __LINE__, BCE_CRC32_RESIDUAL, csum);
2983 goto bce_nvram_test_exit;
2986 csum = ether_crc32_le(data + 0x100, 0x100);
2987 if (csum != BCE_CRC32_RESIDUAL) {
2989 BCE_PRINTF("%s(%d): Invalid feature configuration "
2990 "information NVRAM CRC! Expected: 0x%08X, "
2991 "Found: 08%08X\n", __FILE__, __LINE__,
2992 BCE_CRC32_RESIDUAL, csum);
2995 bce_nvram_test_exit:
2996 DBEXIT(BCE_VERBOSE_NVRAM | BCE_VERBOSE_LOAD | BCE_VERBOSE_RESET);
3001 /****************************************************************************/
3002 /* Calculates the size of the buffers to allocate based on the MTU. */
3006 /****************************************************************************/
3008 bce_get_rx_buffer_sizes(struct bce_softc *sc, int mtu)
3010 DBENTER(BCE_VERBOSE_LOAD);
3012 /* Use a single allocation type when header splitting enabled. */
3013 if (bce_hdr_split == TRUE) {
3014 sc->rx_bd_mbuf_alloc_size = MHLEN;
3015 /* Make sure offset is 16 byte aligned for hardware. */
3016 sc->rx_bd_mbuf_align_pad =
3017 roundup2((MSIZE - MHLEN), 16) - (MSIZE - MHLEN);
3018 sc->rx_bd_mbuf_data_len = sc->rx_bd_mbuf_alloc_size -
3019 sc->rx_bd_mbuf_align_pad;
3021 if ((mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN +
3022 ETHER_CRC_LEN) > MCLBYTES) {
3023 /* Setup for jumbo RX buffer allocations. */
3024 sc->rx_bd_mbuf_alloc_size = MJUM9BYTES;
3025 sc->rx_bd_mbuf_align_pad =
3026 roundup2(MJUM9BYTES, 16) - MJUM9BYTES;
3027 sc->rx_bd_mbuf_data_len =
3028 sc->rx_bd_mbuf_alloc_size -
3029 sc->rx_bd_mbuf_align_pad;
3031 /* Setup for standard RX buffer allocations. */
3032 sc->rx_bd_mbuf_alloc_size = MCLBYTES;
3033 sc->rx_bd_mbuf_align_pad =
3034 roundup2(MCLBYTES, 16) - MCLBYTES;
3035 sc->rx_bd_mbuf_data_len =
3036 sc->rx_bd_mbuf_alloc_size -
3037 sc->rx_bd_mbuf_align_pad;
3041 // DBPRINT(sc, BCE_INFO_LOAD,
3042 DBPRINT(sc, BCE_WARN,
3043 "%s(): rx_bd_mbuf_alloc_size = %d, rx_bd_mbuf_data_len = %d, "
3044 "rx_bd_mbuf_align_pad = %d\n", __FUNCTION__,
3045 sc->rx_bd_mbuf_alloc_size, sc->rx_bd_mbuf_data_len,
3046 sc->rx_bd_mbuf_align_pad);
3048 DBEXIT(BCE_VERBOSE_LOAD);
3051 /****************************************************************************/
3052 /* Identifies the current media type of the controller and sets the PHY */
3057 /****************************************************************************/
3059 bce_get_media(struct bce_softc *sc)
3063 DBENTER(BCE_VERBOSE_PHY);
3065 /* Assume PHY address for copper controllers. */
3066 sc->bce_phy_addr = 1;
3068 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
3069 u32 val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
3070 u32 bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
3074 * The BCM5709S is software configurable
3075 * for Copper or SerDes operation.
3077 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
3078 DBPRINT(sc, BCE_INFO_LOAD, "5709 bonded "
3080 goto bce_get_media_exit;
3081 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
3082 DBPRINT(sc, BCE_INFO_LOAD, "5709 bonded "
3083 "for dual media.\n");
3084 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3085 goto bce_get_media_exit;
3088 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
3090 BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
3093 BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
3095 if (pci_get_function(sc->bce_dev) == 0) {
3100 DBPRINT(sc, BCE_INFO_LOAD,
3101 "BCM5709 s/w configured for SerDes.\n");
3102 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3105 DBPRINT(sc, BCE_INFO_LOAD,
3106 "BCM5709 s/w configured for Copper.\n");
3114 DBPRINT(sc, BCE_INFO_LOAD,
3115 "BCM5709 s/w configured for SerDes.\n");
3116 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3119 DBPRINT(sc, BCE_INFO_LOAD,
3120 "BCM5709 s/w configured for Copper.\n");
3125 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT)
3126 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
3128 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
3130 sc->bce_flags |= BCE_NO_WOL_FLAG;
3132 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
3133 sc->bce_phy_flags |= BCE_PHY_IEEE_CLAUSE_45_FLAG;
3135 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
3136 /* 5708S/09S/16S use a separate PHY for SerDes. */
3137 sc->bce_phy_addr = 2;
3139 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
3140 if (val & BCE_SHARED_HW_CFG_PHY_2_5G) {
3141 sc->bce_phy_flags |=
3142 BCE_PHY_2_5G_CAPABLE_FLAG;
3143 DBPRINT(sc, BCE_INFO_LOAD, "Found 2.5Gb "
3144 "capable adapter\n");
3147 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
3148 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708))
3149 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
3152 DBPRINT(sc, (BCE_INFO_LOAD | BCE_INFO_PHY),
3153 "Using PHY address %d.\n", sc->bce_phy_addr);
3155 DBEXIT(BCE_VERBOSE_PHY);
3159 /****************************************************************************/
3160 /* Performs PHY initialization required before MII drivers access the */
3165 /****************************************************************************/
3167 bce_init_media(struct bce_softc *sc)
3169 if ((sc->bce_phy_flags & (BCE_PHY_IEEE_CLAUSE_45_FLAG |
3170 BCE_PHY_REMOTE_CAP_FLAG)) == BCE_PHY_IEEE_CLAUSE_45_FLAG) {
3172 * Configure 5709S/5716S PHYs to use traditional IEEE
3173 * Clause 22 method. Otherwise we have no way to attach
3174 * the PHY in mii(4) layer. PHY specific configuration
3175 * is done in mii layer.
3178 /* Select auto-negotiation MMD of the PHY. */
3179 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
3180 BRGPHY_BLOCK_ADDR, BRGPHY_BLOCK_ADDR_ADDR_EXT);
3181 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
3182 BRGPHY_ADDR_EXT, BRGPHY_ADDR_EXT_AN_MMD);
3184 /* Set IEEE0 block of AN MMD (assumed in brgphy(4) code). */
3185 bce_miibus_write_reg(sc->bce_dev, sc->bce_phy_addr,
3186 BRGPHY_BLOCK_ADDR, BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
3191 /****************************************************************************/
3192 /* Free any DMA memory owned by the driver. */
3194 /* Scans through each data structre that requires DMA memory and frees */
3195 /* the memory if allocated. */
3199 /****************************************************************************/
3201 bce_dma_free(struct bce_softc *sc)
3205 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_UNLOAD | BCE_VERBOSE_CTX);
3207 /* Free, unmap, and destroy the status block. */
3208 if (sc->status_block != NULL) {
3213 sc->status_block = NULL;
3216 if (sc->status_map != NULL) {
3220 bus_dmamap_destroy(sc->status_tag,
3222 sc->status_map = NULL;
3225 if (sc->status_tag != NULL) {
3226 bus_dma_tag_destroy(sc->status_tag);
3227 sc->status_tag = NULL;
3231 /* Free, unmap, and destroy the statistics block. */
3232 if (sc->stats_block != NULL) {
3237 sc->stats_block = NULL;
3240 if (sc->stats_map != NULL) {
3244 bus_dmamap_destroy(sc->stats_tag,
3246 sc->stats_map = NULL;
3249 if (sc->stats_tag != NULL) {
3250 bus_dma_tag_destroy(sc->stats_tag);
3251 sc->stats_tag = NULL;
3255 /* Free, unmap and destroy all context memory pages. */
3256 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
3257 for (i = 0; i < sc->ctx_pages; i++ ) {
3258 if (sc->ctx_block[i] != NULL) {
3263 sc->ctx_block[i] = NULL;
3266 if (sc->ctx_map[i] != NULL) {
3273 sc->ctx_map[i] = NULL;
3277 /* Destroy the context memory tag. */
3278 if (sc->ctx_tag != NULL) {
3279 bus_dma_tag_destroy(sc->ctx_tag);
3285 /* Free, unmap and destroy all TX buffer descriptor chain pages. */
3286 for (i = 0; i < sc->tx_pages; i++ ) {
3287 if (sc->tx_bd_chain[i] != NULL) {
3289 sc->tx_bd_chain_tag,
3291 sc->tx_bd_chain_map[i]);
3292 sc->tx_bd_chain[i] = NULL;
3295 if (sc->tx_bd_chain_map[i] != NULL) {
3297 sc->tx_bd_chain_tag,
3298 sc->tx_bd_chain_map[i]);
3300 sc->tx_bd_chain_tag,
3301 sc->tx_bd_chain_map[i]);
3302 sc->tx_bd_chain_map[i] = NULL;
3306 /* Destroy the TX buffer descriptor tag. */
3307 if (sc->tx_bd_chain_tag != NULL) {
3308 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
3309 sc->tx_bd_chain_tag = NULL;
3313 /* Free, unmap and destroy all RX buffer descriptor chain pages. */
3314 for (i = 0; i < sc->rx_pages; i++ ) {
3315 if (sc->rx_bd_chain[i] != NULL) {
3317 sc->rx_bd_chain_tag,
3319 sc->rx_bd_chain_map[i]);
3320 sc->rx_bd_chain[i] = NULL;
3323 if (sc->rx_bd_chain_map[i] != NULL) {
3325 sc->rx_bd_chain_tag,
3326 sc->rx_bd_chain_map[i]);
3328 sc->rx_bd_chain_tag,
3329 sc->rx_bd_chain_map[i]);
3330 sc->rx_bd_chain_map[i] = NULL;
3334 /* Destroy the RX buffer descriptor tag. */
3335 if (sc->rx_bd_chain_tag != NULL) {
3336 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
3337 sc->rx_bd_chain_tag = NULL;
3341 /* Free, unmap and destroy all page buffer descriptor chain pages. */
3342 if (bce_hdr_split == TRUE) {
3343 for (i = 0; i < sc->pg_pages; i++ ) {
3344 if (sc->pg_bd_chain[i] != NULL) {
3346 sc->pg_bd_chain_tag,
3348 sc->pg_bd_chain_map[i]);
3349 sc->pg_bd_chain[i] = NULL;
3352 if (sc->pg_bd_chain_map[i] != NULL) {
3354 sc->pg_bd_chain_tag,
3355 sc->pg_bd_chain_map[i]);
3357 sc->pg_bd_chain_tag,
3358 sc->pg_bd_chain_map[i]);
3359 sc->pg_bd_chain_map[i] = NULL;
3363 /* Destroy the page buffer descriptor tag. */
3364 if (sc->pg_bd_chain_tag != NULL) {
3365 bus_dma_tag_destroy(sc->pg_bd_chain_tag);
3366 sc->pg_bd_chain_tag = NULL;
3371 /* Unload and destroy the TX mbuf maps. */
3372 for (i = 0; i < MAX_TX_BD_AVAIL; i++) {
3373 if (sc->tx_mbuf_map[i] != NULL) {
3374 bus_dmamap_unload(sc->tx_mbuf_tag,
3375 sc->tx_mbuf_map[i]);
3376 bus_dmamap_destroy(sc->tx_mbuf_tag,
3377 sc->tx_mbuf_map[i]);
3378 sc->tx_mbuf_map[i] = NULL;
3382 /* Destroy the TX mbuf tag. */
3383 if (sc->tx_mbuf_tag != NULL) {
3384 bus_dma_tag_destroy(sc->tx_mbuf_tag);
3385 sc->tx_mbuf_tag = NULL;
3388 /* Unload and destroy the RX mbuf maps. */
3389 for (i = 0; i < MAX_RX_BD_AVAIL; i++) {
3390 if (sc->rx_mbuf_map[i] != NULL) {
3391 bus_dmamap_unload(sc->rx_mbuf_tag,
3392 sc->rx_mbuf_map[i]);
3393 bus_dmamap_destroy(sc->rx_mbuf_tag,
3394 sc->rx_mbuf_map[i]);
3395 sc->rx_mbuf_map[i] = NULL;
3399 /* Destroy the RX mbuf tag. */
3400 if (sc->rx_mbuf_tag != NULL) {
3401 bus_dma_tag_destroy(sc->rx_mbuf_tag);
3402 sc->rx_mbuf_tag = NULL;
3405 /* Unload and destroy the page mbuf maps. */
3406 if (bce_hdr_split == TRUE) {
3407 for (i = 0; i < MAX_PG_BD_AVAIL; i++) {
3408 if (sc->pg_mbuf_map[i] != NULL) {
3409 bus_dmamap_unload(sc->pg_mbuf_tag,
3410 sc->pg_mbuf_map[i]);
3411 bus_dmamap_destroy(sc->pg_mbuf_tag,
3412 sc->pg_mbuf_map[i]);
3413 sc->pg_mbuf_map[i] = NULL;
3417 /* Destroy the page mbuf tag. */
3418 if (sc->pg_mbuf_tag != NULL) {
3419 bus_dma_tag_destroy(sc->pg_mbuf_tag);
3420 sc->pg_mbuf_tag = NULL;
3424 /* Destroy the parent tag */
3425 if (sc->parent_tag != NULL) {
3426 bus_dma_tag_destroy(sc->parent_tag);
3427 sc->parent_tag = NULL;
3430 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_UNLOAD | BCE_VERBOSE_CTX);
3434 /****************************************************************************/
3435 /* Get DMA memory from the OS. */
3437 /* Validates that the OS has provided DMA buffers in response to a */
3438 /* bus_dmamap_load() call and saves the physical address of those buffers. */
3439 /* When the callback is used the OS will return 0 for the mapping function */
3440 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
3441 /* failures back to the caller. */
3445 /****************************************************************************/
3447 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
3449 bus_addr_t *busaddr = arg;
3451 KASSERT(nseg == 1, ("%s(): Too many segments returned (%d)!",
3452 __FUNCTION__, nseg));
3453 /* Simulate a mapping failure. */
3454 DBRUNIF(DB_RANDOMTRUE(dma_map_addr_failed_sim_control),
3457 /* ToDo: How to increment debug sim_count variable here? */
3459 /* Check for an error and signal the caller that an error occurred. */
3463 *busaddr = segs->ds_addr;
3468 /****************************************************************************/
3469 /* Allocate any DMA memory needed by the driver. */
3471 /* Allocates DMA memory needed for the various global structures needed by */
3474 /* Memory alignment requirements: */
3475 /* +-----------------+----------+----------+----------+----------+ */
3476 /* | | 5706 | 5708 | 5709 | 5716 | */
3477 /* +-----------------+----------+----------+----------+----------+ */
3478 /* |Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
3479 /* |Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
3480 /* |RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
3481 /* |PG Buffers | none | none | none | none | */
3482 /* |TX Buffers | none | none | none | none | */
3483 /* |Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
3484 /* |Context Memory | | | | | */
3485 /* +-----------------+----------+----------+----------+----------+ */
3487 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
3490 /* 0 for success, positive value for failure. */
3491 /****************************************************************************/
3493 bce_dma_alloc(device_t dev)
3495 struct bce_softc *sc;
3496 int i, error, rc = 0;
3497 bus_size_t max_size, max_seg_size;
3500 sc = device_get_softc(dev);
3502 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
3505 * Allocate the parent bus DMA tag appropriate for PCI.
3507 if (bus_dma_tag_create(bus_get_dma_tag(dev), 1, BCE_DMA_BOUNDARY,
3508 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3509 BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL,
3511 BCE_PRINTF("%s(%d): Could not allocate parent DMA tag!\n",
3512 __FILE__, __LINE__);
3514 goto bce_dma_alloc_exit;
3518 * Create a DMA tag for the status block, allocate and clear the
3519 * memory, map the memory into DMA space, and fetch the physical
3520 * address of the block.
3522 if (bus_dma_tag_create(sc->parent_tag, BCE_DMA_ALIGN,
3523 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3524 NULL, NULL, BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
3525 0, NULL, NULL, &sc->status_tag)) {
3526 BCE_PRINTF("%s(%d): Could not allocate status block "
3527 "DMA tag!\n", __FILE__, __LINE__);
3529 goto bce_dma_alloc_exit;
3532 if(bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
3533 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3535 BCE_PRINTF("%s(%d): Could not allocate status block "
3536 "DMA memory!\n", __FILE__, __LINE__);
3538 goto bce_dma_alloc_exit;
3541 error = bus_dmamap_load(sc->status_tag, sc->status_map,
3542 sc->status_block, BCE_STATUS_BLK_SZ, bce_dma_map_addr,
3543 &sc->status_block_paddr, BUS_DMA_NOWAIT);
3545 if (error || sc->status_block_paddr == 0) {
3546 BCE_PRINTF("%s(%d): Could not map status block "
3547 "DMA memory!\n", __FILE__, __LINE__);
3549 goto bce_dma_alloc_exit;
3552 DBPRINT(sc, BCE_INFO_LOAD, "%s(): status_block_paddr = 0x%jX\n",
3553 __FUNCTION__, (uintmax_t) sc->status_block_paddr);
3556 * Create a DMA tag for the statistics block, allocate and clear the
3557 * memory, map the memory into DMA space, and fetch the physical
3558 * address of the block.
3560 if (bus_dma_tag_create(sc->parent_tag, BCE_DMA_ALIGN,
3561 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3562 NULL, NULL, BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
3563 0, NULL, NULL, &sc->stats_tag)) {
3564 BCE_PRINTF("%s(%d): Could not allocate statistics block "
3565 "DMA tag!\n", __FILE__, __LINE__);
3567 goto bce_dma_alloc_exit;
3570 if (bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
3571 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT, &sc->stats_map)) {
3572 BCE_PRINTF("%s(%d): Could not allocate statistics block "
3573 "DMA memory!\n", __FILE__, __LINE__);
3575 goto bce_dma_alloc_exit;
3578 error = bus_dmamap_load(sc->stats_tag, sc->stats_map,
3579 sc->stats_block, BCE_STATS_BLK_SZ, bce_dma_map_addr,
3580 &sc->stats_block_paddr, BUS_DMA_NOWAIT);
3582 if (error || sc->stats_block_paddr == 0) {
3583 BCE_PRINTF("%s(%d): Could not map statistics block "
3584 "DMA memory!\n", __FILE__, __LINE__);
3586 goto bce_dma_alloc_exit;
3589 DBPRINT(sc, BCE_INFO_LOAD, "%s(): stats_block_paddr = 0x%jX\n",
3590 __FUNCTION__, (uintmax_t) sc->stats_block_paddr);
3592 /* BCM5709 uses host memory as cache for context memory. */
3593 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
3594 sc->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
3595 if (sc->ctx_pages == 0)
3598 DBRUNIF((sc->ctx_pages > 512),
3599 BCE_PRINTF("%s(%d): Too many CTX pages! %d > 512\n",
3600 __FILE__, __LINE__, sc->ctx_pages));
3603 * Create a DMA tag for the context pages,
3604 * allocate and clear the memory, map the
3605 * memory into DMA space, and fetch the
3606 * physical address of the block.
3608 if(bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3609 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR,
3610 NULL, NULL, BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
3611 0, NULL, NULL, &sc->ctx_tag)) {
3612 BCE_PRINTF("%s(%d): Could not allocate CTX "
3613 "DMA tag!\n", __FILE__, __LINE__);
3615 goto bce_dma_alloc_exit;
3618 for (i = 0; i < sc->ctx_pages; i++) {
3620 if(bus_dmamem_alloc(sc->ctx_tag,
3621 (void **)&sc->ctx_block[i],
3622 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3624 BCE_PRINTF("%s(%d): Could not allocate CTX "
3625 "DMA memory!\n", __FILE__, __LINE__);
3627 goto bce_dma_alloc_exit;
3630 error = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
3631 sc->ctx_block[i], BCM_PAGE_SIZE, bce_dma_map_addr,
3632 &sc->ctx_paddr[i], BUS_DMA_NOWAIT);
3634 if (error || sc->ctx_paddr[i] == 0) {
3635 BCE_PRINTF("%s(%d): Could not map CTX "
3636 "DMA memory!\n", __FILE__, __LINE__);
3638 goto bce_dma_alloc_exit;
3641 DBPRINT(sc, BCE_INFO_LOAD, "%s(): ctx_paddr[%d] "
3642 "= 0x%jX\n", __FUNCTION__, i,
3643 (uintmax_t) sc->ctx_paddr[i]);
3648 * Create a DMA tag for the TX buffer descriptor chain,
3649 * allocate and clear the memory, and fetch the
3650 * physical address of the block.
3652 if(bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
3653 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3654 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ, 0,
3655 NULL, NULL, &sc->tx_bd_chain_tag)) {
3656 BCE_PRINTF("%s(%d): Could not allocate TX descriptor "
3657 "chain DMA tag!\n", __FILE__, __LINE__);
3659 goto bce_dma_alloc_exit;
3662 for (i = 0; i < sc->tx_pages; i++) {
3664 if(bus_dmamem_alloc(sc->tx_bd_chain_tag,
3665 (void **)&sc->tx_bd_chain[i],
3666 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3667 &sc->tx_bd_chain_map[i])) {
3668 BCE_PRINTF("%s(%d): Could not allocate TX descriptor "
3669 "chain DMA memory!\n", __FILE__, __LINE__);
3671 goto bce_dma_alloc_exit;
3674 error = bus_dmamap_load(sc->tx_bd_chain_tag,
3675 sc->tx_bd_chain_map[i], sc->tx_bd_chain[i],
3676 BCE_TX_CHAIN_PAGE_SZ, bce_dma_map_addr,
3677 &sc->tx_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3679 if (error || sc->tx_bd_chain_paddr[i] == 0) {
3680 BCE_PRINTF("%s(%d): Could not map TX descriptor "
3681 "chain DMA memory!\n", __FILE__, __LINE__);
3683 goto bce_dma_alloc_exit;
3686 DBPRINT(sc, BCE_INFO_LOAD, "%s(): tx_bd_chain_paddr[%d] = "
3687 "0x%jX\n", __FUNCTION__, i,
3688 (uintmax_t) sc->tx_bd_chain_paddr[i]);
3691 /* Check the required size before mapping to conserve resources. */
3692 if (bce_tso_enable) {
3693 max_size = BCE_TSO_MAX_SIZE;
3694 max_segments = BCE_MAX_SEGMENTS;
3695 max_seg_size = BCE_TSO_MAX_SEG_SIZE;
3697 max_size = MCLBYTES * BCE_MAX_SEGMENTS;
3698 max_segments = BCE_MAX_SEGMENTS;
3699 max_seg_size = MCLBYTES;
3702 /* Create a DMA tag for TX mbufs. */
3703 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3704 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL, max_size,
3705 max_segments, max_seg_size, 0, NULL, NULL, &sc->tx_mbuf_tag)) {
3706 BCE_PRINTF("%s(%d): Could not allocate TX mbuf DMA tag!\n",
3707 __FILE__, __LINE__);
3709 goto bce_dma_alloc_exit;
3712 /* Create DMA maps for the TX mbufs clusters. */
3713 for (i = 0; i < TOTAL_TX_BD_ALLOC; i++) {
3714 if (bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_NOWAIT,
3715 &sc->tx_mbuf_map[i])) {
3716 BCE_PRINTF("%s(%d): Unable to create TX mbuf DMA "
3717 "map!\n", __FILE__, __LINE__);
3719 goto bce_dma_alloc_exit;
3724 * Create a DMA tag for the RX buffer descriptor chain,
3725 * allocate and clear the memory, and fetch the physical
3726 * address of the blocks.
3728 if (bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3729 BCE_DMA_BOUNDARY, BUS_SPACE_MAXADDR,
3730 sc->max_bus_addr, NULL, NULL,
3731 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
3732 0, NULL, NULL, &sc->rx_bd_chain_tag)) {
3733 BCE_PRINTF("%s(%d): Could not allocate RX descriptor chain "
3734 "DMA tag!\n", __FILE__, __LINE__);
3736 goto bce_dma_alloc_exit;
3739 for (i = 0; i < sc->rx_pages; i++) {
3741 if (bus_dmamem_alloc(sc->rx_bd_chain_tag,
3742 (void **)&sc->rx_bd_chain[i],
3743 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3744 &sc->rx_bd_chain_map[i])) {
3745 BCE_PRINTF("%s(%d): Could not allocate RX descriptor "
3746 "chain DMA memory!\n", __FILE__, __LINE__);
3748 goto bce_dma_alloc_exit;
3751 error = bus_dmamap_load(sc->rx_bd_chain_tag,
3752 sc->rx_bd_chain_map[i], sc->rx_bd_chain[i],
3753 BCE_RX_CHAIN_PAGE_SZ, bce_dma_map_addr,
3754 &sc->rx_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3756 if (error || sc->rx_bd_chain_paddr[i] == 0) {
3757 BCE_PRINTF("%s(%d): Could not map RX descriptor "
3758 "chain DMA memory!\n", __FILE__, __LINE__);
3760 goto bce_dma_alloc_exit;
3763 DBPRINT(sc, BCE_INFO_LOAD, "%s(): rx_bd_chain_paddr[%d] = "
3764 "0x%jX\n", __FUNCTION__, i,
3765 (uintmax_t) sc->rx_bd_chain_paddr[i]);
3769 * Create a DMA tag for RX mbufs.
3771 if (bce_hdr_split == TRUE)
3772 max_size = ((sc->rx_bd_mbuf_alloc_size < MCLBYTES) ?
3773 MCLBYTES : sc->rx_bd_mbuf_alloc_size);
3775 max_size = MJUM9BYTES;
3777 DBPRINT(sc, BCE_INFO_LOAD, "%s(): Creating rx_mbuf_tag "
3778 "(max size = 0x%jX)\n", __FUNCTION__, (uintmax_t)max_size);
3780 if (bus_dma_tag_create(sc->parent_tag, BCE_RX_BUF_ALIGN,
3781 BCE_DMA_BOUNDARY, sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL,
3782 max_size, 1, max_size, 0, NULL, NULL, &sc->rx_mbuf_tag)) {
3783 BCE_PRINTF("%s(%d): Could not allocate RX mbuf DMA tag!\n",
3784 __FILE__, __LINE__);
3786 goto bce_dma_alloc_exit;
3789 /* Create DMA maps for the RX mbuf clusters. */
3790 for (i = 0; i < TOTAL_RX_BD_ALLOC; i++) {
3791 if (bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_NOWAIT,
3792 &sc->rx_mbuf_map[i])) {
3793 BCE_PRINTF("%s(%d): Unable to create RX mbuf "
3794 "DMA map!\n", __FILE__, __LINE__);
3796 goto bce_dma_alloc_exit;
3800 if (bce_hdr_split == TRUE) {
3802 * Create a DMA tag for the page buffer descriptor chain,
3803 * allocate and clear the memory, and fetch the physical
3804 * address of the blocks.
3806 if (bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE,
3807 BCE_DMA_BOUNDARY, BUS_SPACE_MAXADDR, sc->max_bus_addr,
3808 NULL, NULL, BCE_PG_CHAIN_PAGE_SZ, 1, BCE_PG_CHAIN_PAGE_SZ,
3809 0, NULL, NULL, &sc->pg_bd_chain_tag)) {
3810 BCE_PRINTF("%s(%d): Could not allocate page descriptor "
3811 "chain DMA tag!\n", __FILE__, __LINE__);
3813 goto bce_dma_alloc_exit;
3816 for (i = 0; i < sc->pg_pages; i++) {
3817 if (bus_dmamem_alloc(sc->pg_bd_chain_tag,
3818 (void **)&sc->pg_bd_chain[i],
3819 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT,
3820 &sc->pg_bd_chain_map[i])) {
3821 BCE_PRINTF("%s(%d): Could not allocate page "
3822 "descriptor chain DMA memory!\n",
3823 __FILE__, __LINE__);
3825 goto bce_dma_alloc_exit;
3828 error = bus_dmamap_load(sc->pg_bd_chain_tag,
3829 sc->pg_bd_chain_map[i], sc->pg_bd_chain[i],
3830 BCE_PG_CHAIN_PAGE_SZ, bce_dma_map_addr,
3831 &sc->pg_bd_chain_paddr[i], BUS_DMA_NOWAIT);
3833 if (error || sc->pg_bd_chain_paddr[i] == 0) {
3834 BCE_PRINTF("%s(%d): Could not map page descriptor "
3835 "chain DMA memory!\n", __FILE__, __LINE__);
3837 goto bce_dma_alloc_exit;
3840 DBPRINT(sc, BCE_INFO_LOAD, "%s(): pg_bd_chain_paddr[%d] = "
3841 "0x%jX\n", __FUNCTION__, i,
3842 (uintmax_t) sc->pg_bd_chain_paddr[i]);
3846 * Create a DMA tag for page mbufs.
3848 if (bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
3849 sc->max_bus_addr, BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES,
3850 1, MCLBYTES, 0, NULL, NULL, &sc->pg_mbuf_tag)) {
3851 BCE_PRINTF("%s(%d): Could not allocate page mbuf "
3852 "DMA tag!\n", __FILE__, __LINE__);
3854 goto bce_dma_alloc_exit;
3857 /* Create DMA maps for the page mbuf clusters. */
3858 for (i = 0; i < TOTAL_PG_BD_ALLOC; i++) {
3859 if (bus_dmamap_create(sc->pg_mbuf_tag, BUS_DMA_NOWAIT,
3860 &sc->pg_mbuf_map[i])) {
3861 BCE_PRINTF("%s(%d): Unable to create page mbuf "
3862 "DMA map!\n", __FILE__, __LINE__);
3864 goto bce_dma_alloc_exit;
3870 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
3875 /****************************************************************************/
3876 /* Release all resources used by the driver. */
3878 /* Releases all resources acquired by the driver including interrupts, */
3879 /* interrupt handler, interfaces, mutexes, and DMA memory. */
3883 /****************************************************************************/
3885 bce_release_resources(struct bce_softc *sc)
3889 DBENTER(BCE_VERBOSE_RESET);
3895 if (sc->bce_intrhand != NULL) {
3896 DBPRINT(sc, BCE_INFO_RESET, "Removing interrupt handler.\n");
3897 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
3900 if (sc->bce_res_irq != NULL) {
3901 DBPRINT(sc, BCE_INFO_RESET, "Releasing IRQ.\n");
3902 bus_release_resource(dev, SYS_RES_IRQ,
3903 rman_get_rid(sc->bce_res_irq), sc->bce_res_irq);
3906 if (sc->bce_flags & (BCE_USING_MSI_FLAG | BCE_USING_MSIX_FLAG)) {
3907 DBPRINT(sc, BCE_INFO_RESET, "Releasing MSI/MSI-X vector.\n");
3908 pci_release_msi(dev);
3911 if (sc->bce_res_mem != NULL) {
3912 DBPRINT(sc, BCE_INFO_RESET, "Releasing PCI memory.\n");
3913 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
3917 if (sc->bce_ifp != NULL) {
3918 DBPRINT(sc, BCE_INFO_RESET, "Releasing IF.\n");
3919 if_free(sc->bce_ifp);
3922 if (mtx_initialized(&sc->bce_mtx))
3923 BCE_LOCK_DESTROY(sc);
3925 DBEXIT(BCE_VERBOSE_RESET);
3929 /****************************************************************************/
3930 /* Firmware synchronization. */
3932 /* Before performing certain events such as a chip reset, synchronize with */
3933 /* the firmware first. */
3936 /* 0 for success, positive value for failure. */
3937 /****************************************************************************/
3939 bce_fw_sync(struct bce_softc *sc, u32 msg_data)
3944 DBENTER(BCE_VERBOSE_RESET);
3946 /* Don't waste any time if we've timed out before. */
3947 if (sc->bce_fw_timed_out == TRUE) {
3949 goto bce_fw_sync_exit;
3952 /* Increment the message sequence number. */
3953 sc->bce_fw_wr_seq++;
3954 msg_data |= sc->bce_fw_wr_seq;
3956 DBPRINT(sc, BCE_VERBOSE_FIRMWARE, "bce_fw_sync(): msg_data = "
3957 "0x%08X\n", msg_data);
3959 /* Send the message to the bootcode driver mailbox. */
3960 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
3962 /* Wait for the bootcode to acknowledge the message. */
3963 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
3964 /* Check for a response in the bootcode firmware mailbox. */
3965 val = bce_shmem_rd(sc, BCE_FW_MB);
3966 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
3971 /* If we've timed out, tell bootcode that we've stopped waiting. */
3972 if (((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ)) &&
3973 ((msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0)) {
3975 BCE_PRINTF("%s(%d): Firmware synchronization timeout! "
3976 "msg_data = 0x%08X\n", __FILE__, __LINE__, msg_data);
3978 msg_data &= ~BCE_DRV_MSG_CODE;
3979 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
3981 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
3983 sc->bce_fw_timed_out = TRUE;
3988 DBEXIT(BCE_VERBOSE_RESET);
3993 /****************************************************************************/
3994 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
3998 /****************************************************************************/
4000 bce_load_rv2p_fw(struct bce_softc *sc, const u32 *rv2p_code,
4001 u32 rv2p_code_len, u32 rv2p_proc)
4006 DBENTER(BCE_VERBOSE_RESET);
4008 /* Set the page size used by RV2P. */
4009 if (rv2p_proc == RV2P_PROC2) {
4010 BCE_RV2P_PROC2_CHG_MAX_BD_PAGE(USABLE_RX_BD_PER_PAGE);
4013 for (i = 0; i < rv2p_code_len; i += 8) {
4014 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
4016 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
4019 if (rv2p_proc == RV2P_PROC1) {
4020 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
4021 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
4024 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
4025 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
4029 /* Reset the processor, un-stall is done later. */
4030 if (rv2p_proc == RV2P_PROC1) {
4031 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
4034 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
4037 DBEXIT(BCE_VERBOSE_RESET);
4041 /****************************************************************************/
4042 /* Load RISC processor firmware. */
4044 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
4045 /* associated with a particular processor. */
4049 /****************************************************************************/
4051 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
4056 DBENTER(BCE_VERBOSE_RESET);
4058 bce_halt_cpu(sc, cpu_reg);
4060 /* Load the Text area. */
4061 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
4065 for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
4066 REG_WR_IND(sc, offset, fw->text[j]);
4070 /* Load the Data area. */
4071 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
4075 for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
4076 REG_WR_IND(sc, offset, fw->data[j]);
4080 /* Load the SBSS area. */
4081 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
4085 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
4086 REG_WR_IND(sc, offset, fw->sbss[j]);
4090 /* Load the BSS area. */
4091 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
4095 for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
4096 REG_WR_IND(sc, offset, fw->bss[j]);
4100 /* Load the Read-Only area. */
4101 offset = cpu_reg->spad_base +
4102 (fw->rodata_addr - cpu_reg->mips_view_base);
4106 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
4107 REG_WR_IND(sc, offset, fw->rodata[j]);
4111 /* Clear the pre-fetch instruction and set the FW start address. */
4112 REG_WR_IND(sc, cpu_reg->inst, 0);
4113 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
4115 DBEXIT(BCE_VERBOSE_RESET);
4119 /****************************************************************************/
4120 /* Starts the RISC processor. */
4122 /* Assumes the CPU starting address has already been set. */
4126 /****************************************************************************/
4128 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
4132 DBENTER(BCE_VERBOSE_RESET);
4134 /* Start the CPU. */
4135 val = REG_RD_IND(sc, cpu_reg->mode);
4136 val &= ~cpu_reg->mode_value_halt;
4137 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
4138 REG_WR_IND(sc, cpu_reg->mode, val);
4140 DBEXIT(BCE_VERBOSE_RESET);
4144 /****************************************************************************/
4145 /* Halts the RISC processor. */
4149 /****************************************************************************/
4151 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
4155 DBENTER(BCE_VERBOSE_RESET);
4158 val = REG_RD_IND(sc, cpu_reg->mode);
4159 val |= cpu_reg->mode_value_halt;
4160 REG_WR_IND(sc, cpu_reg->mode, val);
4161 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
4163 DBEXIT(BCE_VERBOSE_RESET);
4167 /****************************************************************************/
4168 /* Initialize the RX CPU. */
4172 /****************************************************************************/
4174 bce_start_rxp_cpu(struct bce_softc *sc)
4176 struct cpu_reg cpu_reg;
4178 DBENTER(BCE_VERBOSE_RESET);
4180 cpu_reg.mode = BCE_RXP_CPU_MODE;
4181 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
4182 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
4183 cpu_reg.state = BCE_RXP_CPU_STATE;
4184 cpu_reg.state_value_clear = 0xffffff;
4185 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
4186 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
4187 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
4188 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
4189 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
4190 cpu_reg.spad_base = BCE_RXP_SCRATCH;
4191 cpu_reg.mips_view_base = 0x8000000;
4193 DBPRINT(sc, BCE_INFO_RESET, "Starting RX firmware.\n");
4194 bce_start_cpu(sc, &cpu_reg);
4196 DBEXIT(BCE_VERBOSE_RESET);
4200 /****************************************************************************/
4201 /* Initialize the RX CPU. */
4205 /****************************************************************************/
4207 bce_init_rxp_cpu(struct bce_softc *sc)
4209 struct cpu_reg cpu_reg;
4212 DBENTER(BCE_VERBOSE_RESET);
4214 cpu_reg.mode = BCE_RXP_CPU_MODE;
4215 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
4216 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
4217 cpu_reg.state = BCE_RXP_CPU_STATE;
4218 cpu_reg.state_value_clear = 0xffffff;
4219 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
4220 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
4221 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
4222 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
4223 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
4224 cpu_reg.spad_base = BCE_RXP_SCRATCH;
4225 cpu_reg.mips_view_base = 0x8000000;
4227 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4228 fw.ver_major = bce_RXP_b09FwReleaseMajor;
4229 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
4230 fw.ver_fix = bce_RXP_b09FwReleaseFix;
4231 fw.start_addr = bce_RXP_b09FwStartAddr;
4233 fw.text_addr = bce_RXP_b09FwTextAddr;
4234 fw.text_len = bce_RXP_b09FwTextLen;
4236 fw.text = bce_RXP_b09FwText;
4238 fw.data_addr = bce_RXP_b09FwDataAddr;
4239 fw.data_len = bce_RXP_b09FwDataLen;
4241 fw.data = bce_RXP_b09FwData;
4243 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
4244 fw.sbss_len = bce_RXP_b09FwSbssLen;
4246 fw.sbss = bce_RXP_b09FwSbss;
4248 fw.bss_addr = bce_RXP_b09FwBssAddr;
4249 fw.bss_len = bce_RXP_b09FwBssLen;
4251 fw.bss = bce_RXP_b09FwBss;
4253 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
4254 fw.rodata_len = bce_RXP_b09FwRodataLen;
4255 fw.rodata_index = 0;
4256 fw.rodata = bce_RXP_b09FwRodata;
4258 fw.ver_major = bce_RXP_b06FwReleaseMajor;
4259 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
4260 fw.ver_fix = bce_RXP_b06FwReleaseFix;
4261 fw.start_addr = bce_RXP_b06FwStartAddr;
4263 fw.text_addr = bce_RXP_b06FwTextAddr;
4264 fw.text_len = bce_RXP_b06FwTextLen;
4266 fw.text = bce_RXP_b06FwText;
4268 fw.data_addr = bce_RXP_b06FwDataAddr;
4269 fw.data_len = bce_RXP_b06FwDataLen;
4271 fw.data = bce_RXP_b06FwData;
4273 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
4274 fw.sbss_len = bce_RXP_b06FwSbssLen;
4276 fw.sbss = bce_RXP_b06FwSbss;
4278 fw.bss_addr = bce_RXP_b06FwBssAddr;
4279 fw.bss_len = bce_RXP_b06FwBssLen;
4281 fw.bss = bce_RXP_b06FwBss;
4283 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
4284 fw.rodata_len = bce_RXP_b06FwRodataLen;
4285 fw.rodata_index = 0;
4286 fw.rodata = bce_RXP_b06FwRodata;
4289 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
4290 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4292 /* Delay RXP start until initialization is complete. */
4294 DBEXIT(BCE_VERBOSE_RESET);
4298 /****************************************************************************/
4299 /* Initialize the TX CPU. */
4303 /****************************************************************************/
4305 bce_init_txp_cpu(struct bce_softc *sc)
4307 struct cpu_reg cpu_reg;
4310 DBENTER(BCE_VERBOSE_RESET);
4312 cpu_reg.mode = BCE_TXP_CPU_MODE;
4313 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
4314 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
4315 cpu_reg.state = BCE_TXP_CPU_STATE;
4316 cpu_reg.state_value_clear = 0xffffff;
4317 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
4318 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
4319 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
4320 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
4321 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
4322 cpu_reg.spad_base = BCE_TXP_SCRATCH;
4323 cpu_reg.mips_view_base = 0x8000000;
4325 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4326 fw.ver_major = bce_TXP_b09FwReleaseMajor;
4327 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
4328 fw.ver_fix = bce_TXP_b09FwReleaseFix;
4329 fw.start_addr = bce_TXP_b09FwStartAddr;
4331 fw.text_addr = bce_TXP_b09FwTextAddr;
4332 fw.text_len = bce_TXP_b09FwTextLen;
4334 fw.text = bce_TXP_b09FwText;
4336 fw.data_addr = bce_TXP_b09FwDataAddr;
4337 fw.data_len = bce_TXP_b09FwDataLen;
4339 fw.data = bce_TXP_b09FwData;
4341 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
4342 fw.sbss_len = bce_TXP_b09FwSbssLen;
4344 fw.sbss = bce_TXP_b09FwSbss;
4346 fw.bss_addr = bce_TXP_b09FwBssAddr;
4347 fw.bss_len = bce_TXP_b09FwBssLen;
4349 fw.bss = bce_TXP_b09FwBss;
4351 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
4352 fw.rodata_len = bce_TXP_b09FwRodataLen;
4353 fw.rodata_index = 0;
4354 fw.rodata = bce_TXP_b09FwRodata;
4356 fw.ver_major = bce_TXP_b06FwReleaseMajor;
4357 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
4358 fw.ver_fix = bce_TXP_b06FwReleaseFix;
4359 fw.start_addr = bce_TXP_b06FwStartAddr;
4361 fw.text_addr = bce_TXP_b06FwTextAddr;
4362 fw.text_len = bce_TXP_b06FwTextLen;
4364 fw.text = bce_TXP_b06FwText;
4366 fw.data_addr = bce_TXP_b06FwDataAddr;
4367 fw.data_len = bce_TXP_b06FwDataLen;
4369 fw.data = bce_TXP_b06FwData;
4371 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
4372 fw.sbss_len = bce_TXP_b06FwSbssLen;
4374 fw.sbss = bce_TXP_b06FwSbss;
4376 fw.bss_addr = bce_TXP_b06FwBssAddr;
4377 fw.bss_len = bce_TXP_b06FwBssLen;
4379 fw.bss = bce_TXP_b06FwBss;
4381 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
4382 fw.rodata_len = bce_TXP_b06FwRodataLen;
4383 fw.rodata_index = 0;
4384 fw.rodata = bce_TXP_b06FwRodata;
4387 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
4388 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4389 bce_start_cpu(sc, &cpu_reg);
4391 DBEXIT(BCE_VERBOSE_RESET);
4395 /****************************************************************************/
4396 /* Initialize the TPAT CPU. */
4400 /****************************************************************************/
4402 bce_init_tpat_cpu(struct bce_softc *sc)
4404 struct cpu_reg cpu_reg;
4407 DBENTER(BCE_VERBOSE_RESET);
4409 cpu_reg.mode = BCE_TPAT_CPU_MODE;
4410 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
4411 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
4412 cpu_reg.state = BCE_TPAT_CPU_STATE;
4413 cpu_reg.state_value_clear = 0xffffff;
4414 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
4415 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
4416 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
4417 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
4418 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
4419 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
4420 cpu_reg.mips_view_base = 0x8000000;
4422 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4423 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
4424 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
4425 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
4426 fw.start_addr = bce_TPAT_b09FwStartAddr;
4428 fw.text_addr = bce_TPAT_b09FwTextAddr;
4429 fw.text_len = bce_TPAT_b09FwTextLen;
4431 fw.text = bce_TPAT_b09FwText;
4433 fw.data_addr = bce_TPAT_b09FwDataAddr;
4434 fw.data_len = bce_TPAT_b09FwDataLen;
4436 fw.data = bce_TPAT_b09FwData;
4438 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
4439 fw.sbss_len = bce_TPAT_b09FwSbssLen;
4441 fw.sbss = bce_TPAT_b09FwSbss;
4443 fw.bss_addr = bce_TPAT_b09FwBssAddr;
4444 fw.bss_len = bce_TPAT_b09FwBssLen;
4446 fw.bss = bce_TPAT_b09FwBss;
4448 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
4449 fw.rodata_len = bce_TPAT_b09FwRodataLen;
4450 fw.rodata_index = 0;
4451 fw.rodata = bce_TPAT_b09FwRodata;
4453 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
4454 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
4455 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
4456 fw.start_addr = bce_TPAT_b06FwStartAddr;
4458 fw.text_addr = bce_TPAT_b06FwTextAddr;
4459 fw.text_len = bce_TPAT_b06FwTextLen;
4461 fw.text = bce_TPAT_b06FwText;
4463 fw.data_addr = bce_TPAT_b06FwDataAddr;
4464 fw.data_len = bce_TPAT_b06FwDataLen;
4466 fw.data = bce_TPAT_b06FwData;
4468 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
4469 fw.sbss_len = bce_TPAT_b06FwSbssLen;
4471 fw.sbss = bce_TPAT_b06FwSbss;
4473 fw.bss_addr = bce_TPAT_b06FwBssAddr;
4474 fw.bss_len = bce_TPAT_b06FwBssLen;
4476 fw.bss = bce_TPAT_b06FwBss;
4478 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
4479 fw.rodata_len = bce_TPAT_b06FwRodataLen;
4480 fw.rodata_index = 0;
4481 fw.rodata = bce_TPAT_b06FwRodata;
4484 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
4485 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4486 bce_start_cpu(sc, &cpu_reg);
4488 DBEXIT(BCE_VERBOSE_RESET);
4492 /****************************************************************************/
4493 /* Initialize the CP CPU. */
4497 /****************************************************************************/
4499 bce_init_cp_cpu(struct bce_softc *sc)
4501 struct cpu_reg cpu_reg;
4504 DBENTER(BCE_VERBOSE_RESET);
4506 cpu_reg.mode = BCE_CP_CPU_MODE;
4507 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
4508 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
4509 cpu_reg.state = BCE_CP_CPU_STATE;
4510 cpu_reg.state_value_clear = 0xffffff;
4511 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
4512 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
4513 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
4514 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
4515 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
4516 cpu_reg.spad_base = BCE_CP_SCRATCH;
4517 cpu_reg.mips_view_base = 0x8000000;
4519 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4520 fw.ver_major = bce_CP_b09FwReleaseMajor;
4521 fw.ver_minor = bce_CP_b09FwReleaseMinor;
4522 fw.ver_fix = bce_CP_b09FwReleaseFix;
4523 fw.start_addr = bce_CP_b09FwStartAddr;
4525 fw.text_addr = bce_CP_b09FwTextAddr;
4526 fw.text_len = bce_CP_b09FwTextLen;
4528 fw.text = bce_CP_b09FwText;
4530 fw.data_addr = bce_CP_b09FwDataAddr;
4531 fw.data_len = bce_CP_b09FwDataLen;
4533 fw.data = bce_CP_b09FwData;
4535 fw.sbss_addr = bce_CP_b09FwSbssAddr;
4536 fw.sbss_len = bce_CP_b09FwSbssLen;
4538 fw.sbss = bce_CP_b09FwSbss;
4540 fw.bss_addr = bce_CP_b09FwBssAddr;
4541 fw.bss_len = bce_CP_b09FwBssLen;
4543 fw.bss = bce_CP_b09FwBss;
4545 fw.rodata_addr = bce_CP_b09FwRodataAddr;
4546 fw.rodata_len = bce_CP_b09FwRodataLen;
4547 fw.rodata_index = 0;
4548 fw.rodata = bce_CP_b09FwRodata;
4550 fw.ver_major = bce_CP_b06FwReleaseMajor;
4551 fw.ver_minor = bce_CP_b06FwReleaseMinor;
4552 fw.ver_fix = bce_CP_b06FwReleaseFix;
4553 fw.start_addr = bce_CP_b06FwStartAddr;
4555 fw.text_addr = bce_CP_b06FwTextAddr;
4556 fw.text_len = bce_CP_b06FwTextLen;
4558 fw.text = bce_CP_b06FwText;
4560 fw.data_addr = bce_CP_b06FwDataAddr;
4561 fw.data_len = bce_CP_b06FwDataLen;
4563 fw.data = bce_CP_b06FwData;
4565 fw.sbss_addr = bce_CP_b06FwSbssAddr;
4566 fw.sbss_len = bce_CP_b06FwSbssLen;
4568 fw.sbss = bce_CP_b06FwSbss;
4570 fw.bss_addr = bce_CP_b06FwBssAddr;
4571 fw.bss_len = bce_CP_b06FwBssLen;
4573 fw.bss = bce_CP_b06FwBss;
4575 fw.rodata_addr = bce_CP_b06FwRodataAddr;
4576 fw.rodata_len = bce_CP_b06FwRodataLen;
4577 fw.rodata_index = 0;
4578 fw.rodata = bce_CP_b06FwRodata;
4581 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
4582 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4583 bce_start_cpu(sc, &cpu_reg);
4585 DBEXIT(BCE_VERBOSE_RESET);
4589 /****************************************************************************/
4590 /* Initialize the COM CPU. */
4594 /****************************************************************************/
4596 bce_init_com_cpu(struct bce_softc *sc)
4598 struct cpu_reg cpu_reg;
4601 DBENTER(BCE_VERBOSE_RESET);
4603 cpu_reg.mode = BCE_COM_CPU_MODE;
4604 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
4605 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
4606 cpu_reg.state = BCE_COM_CPU_STATE;
4607 cpu_reg.state_value_clear = 0xffffff;
4608 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
4609 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
4610 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
4611 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
4612 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
4613 cpu_reg.spad_base = BCE_COM_SCRATCH;
4614 cpu_reg.mips_view_base = 0x8000000;
4616 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4617 fw.ver_major = bce_COM_b09FwReleaseMajor;
4618 fw.ver_minor = bce_COM_b09FwReleaseMinor;
4619 fw.ver_fix = bce_COM_b09FwReleaseFix;
4620 fw.start_addr = bce_COM_b09FwStartAddr;
4622 fw.text_addr = bce_COM_b09FwTextAddr;
4623 fw.text_len = bce_COM_b09FwTextLen;
4625 fw.text = bce_COM_b09FwText;
4627 fw.data_addr = bce_COM_b09FwDataAddr;
4628 fw.data_len = bce_COM_b09FwDataLen;
4630 fw.data = bce_COM_b09FwData;
4632 fw.sbss_addr = bce_COM_b09FwSbssAddr;
4633 fw.sbss_len = bce_COM_b09FwSbssLen;
4635 fw.sbss = bce_COM_b09FwSbss;
4637 fw.bss_addr = bce_COM_b09FwBssAddr;
4638 fw.bss_len = bce_COM_b09FwBssLen;
4640 fw.bss = bce_COM_b09FwBss;
4642 fw.rodata_addr = bce_COM_b09FwRodataAddr;
4643 fw.rodata_len = bce_COM_b09FwRodataLen;
4644 fw.rodata_index = 0;
4645 fw.rodata = bce_COM_b09FwRodata;
4647 fw.ver_major = bce_COM_b06FwReleaseMajor;
4648 fw.ver_minor = bce_COM_b06FwReleaseMinor;
4649 fw.ver_fix = bce_COM_b06FwReleaseFix;
4650 fw.start_addr = bce_COM_b06FwStartAddr;
4652 fw.text_addr = bce_COM_b06FwTextAddr;
4653 fw.text_len = bce_COM_b06FwTextLen;
4655 fw.text = bce_COM_b06FwText;
4657 fw.data_addr = bce_COM_b06FwDataAddr;
4658 fw.data_len = bce_COM_b06FwDataLen;
4660 fw.data = bce_COM_b06FwData;
4662 fw.sbss_addr = bce_COM_b06FwSbssAddr;
4663 fw.sbss_len = bce_COM_b06FwSbssLen;
4665 fw.sbss = bce_COM_b06FwSbss;
4667 fw.bss_addr = bce_COM_b06FwBssAddr;
4668 fw.bss_len = bce_COM_b06FwBssLen;
4670 fw.bss = bce_COM_b06FwBss;
4672 fw.rodata_addr = bce_COM_b06FwRodataAddr;
4673 fw.rodata_len = bce_COM_b06FwRodataLen;
4674 fw.rodata_index = 0;
4675 fw.rodata = bce_COM_b06FwRodata;
4678 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
4679 bce_load_cpu_fw(sc, &cpu_reg, &fw);
4680 bce_start_cpu(sc, &cpu_reg);
4682 DBEXIT(BCE_VERBOSE_RESET);
4686 /****************************************************************************/
4687 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
4689 /* Loads the firmware for each CPU and starts the CPU. */
4693 /****************************************************************************/
4695 bce_init_cpus(struct bce_softc *sc)
4697 DBENTER(BCE_VERBOSE_RESET);
4699 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4701 if ((BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax)) {
4702 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
4703 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
4704 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
4705 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
4707 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
4708 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
4709 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
4710 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
4714 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
4715 sizeof(bce_rv2p_proc1), RV2P_PROC1);
4716 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
4717 sizeof(bce_rv2p_proc2), RV2P_PROC2);
4720 bce_init_rxp_cpu(sc);
4721 bce_init_txp_cpu(sc);
4722 bce_init_tpat_cpu(sc);
4723 bce_init_com_cpu(sc);
4724 bce_init_cp_cpu(sc);
4726 DBEXIT(BCE_VERBOSE_RESET);
4730 /****************************************************************************/
4731 /* Initialize context memory. */
4733 /* Clears the memory associated with each Context ID (CID). */
4737 /****************************************************************************/
4739 bce_init_ctx(struct bce_softc *sc)
4741 u32 offset, val, vcid_addr;
4742 int i, j, rc, retry_cnt;
4745 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
4747 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4748 retry_cnt = CTX_INIT_RETRY_COUNT;
4750 DBPRINT(sc, BCE_INFO_CTX, "Initializing 5709 context.\n");
4753 * BCM5709 context memory may be cached
4754 * in host memory so prepare the host memory
4757 val = BCE_CTX_COMMAND_ENABLED |
4758 BCE_CTX_COMMAND_MEM_INIT | (1 << 12);
4759 val |= (BCM_PAGE_BITS - 8) << 16;
4760 REG_WR(sc, BCE_CTX_COMMAND, val);
4762 /* Wait for mem init command to complete. */
4763 for (i = 0; i < retry_cnt; i++) {
4764 val = REG_RD(sc, BCE_CTX_COMMAND);
4765 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
4769 if ((val & BCE_CTX_COMMAND_MEM_INIT) != 0) {
4770 BCE_PRINTF("%s(): Context memory initialization failed!\n",
4776 for (i = 0; i < sc->ctx_pages; i++) {
4777 /* Set the physical address of the context memory. */
4778 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
4779 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
4780 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
4781 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
4782 BCE_ADDR_HI(sc->ctx_paddr[i]));
4783 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL, i |
4784 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
4786 /* Verify the context memory write was successful. */
4787 for (j = 0; j < retry_cnt; j++) {
4788 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
4790 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
4794 if ((val & BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) != 0) {
4795 BCE_PRINTF("%s(): Failed to initialize "
4796 "context page %d!\n", __FUNCTION__, i);
4803 DBPRINT(sc, BCE_INFO, "Initializing 5706/5708 context.\n");
4806 * For the 5706/5708, context memory is local to
4807 * the controller, so initialize the controller
4811 vcid_addr = GET_CID_ADDR(96);
4814 vcid_addr -= PHY_CTX_SIZE;
4816 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
4817 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
4819 for(offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
4820 CTX_WR(sc, 0x00, offset, 0);
4823 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
4824 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
4829 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_CTX);
4834 /****************************************************************************/
4835 /* Fetch the permanent MAC address of the controller. */
4839 /****************************************************************************/
4841 bce_get_mac_addr(struct bce_softc *sc)
4843 u32 mac_lo = 0, mac_hi = 0;
4845 DBENTER(BCE_VERBOSE_RESET);
4848 * The NetXtreme II bootcode populates various NIC
4849 * power-on and runtime configuration items in a
4850 * shared memory area. The factory configured MAC
4851 * address is available from both NVRAM and the
4852 * shared memory area so we'll read the value from
4853 * shared memory for speed.
4856 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
4857 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
4859 if ((mac_lo == 0) && (mac_hi == 0)) {
4860 BCE_PRINTF("%s(%d): Invalid Ethernet address!\n",
4861 __FILE__, __LINE__);
4863 sc->eaddr[0] = (u_char)(mac_hi >> 8);
4864 sc->eaddr[1] = (u_char)(mac_hi >> 0);
4865 sc->eaddr[2] = (u_char)(mac_lo >> 24);
4866 sc->eaddr[3] = (u_char)(mac_lo >> 16);
4867 sc->eaddr[4] = (u_char)(mac_lo >> 8);
4868 sc->eaddr[5] = (u_char)(mac_lo >> 0);
4871 DBPRINT(sc, BCE_INFO_MISC, "Permanent Ethernet "
4872 "address = %6D\n", sc->eaddr, ":");
4873 DBEXIT(BCE_VERBOSE_RESET);
4877 /****************************************************************************/
4878 /* Program the MAC address. */
4882 /****************************************************************************/
4884 bce_set_mac_addr(struct bce_softc *sc)
4887 u8 *mac_addr = sc->eaddr;
4889 /* ToDo: Add support for setting multiple MAC addresses. */
4891 DBENTER(BCE_VERBOSE_RESET);
4892 DBPRINT(sc, BCE_INFO_MISC, "Setting Ethernet address = "
4893 "%6D\n", sc->eaddr, ":");
4895 val = (mac_addr[0] << 8) | mac_addr[1];
4897 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
4899 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
4900 (mac_addr[4] << 8) | mac_addr[5];
4902 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
4904 DBEXIT(BCE_VERBOSE_RESET);
4908 /****************************************************************************/
4909 /* Stop the controller. */
4913 /****************************************************************************/
4915 bce_stop(struct bce_softc *sc)
4919 DBENTER(BCE_VERBOSE_RESET);
4921 BCE_LOCK_ASSERT(sc);
4925 callout_stop(&sc->bce_tick_callout);
4927 /* Disable the transmit/receive blocks. */
4928 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
4929 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
4932 bce_disable_intr(sc);
4934 /* Free RX buffers. */
4935 if (bce_hdr_split == TRUE) {
4936 bce_free_pg_chain(sc);
4938 bce_free_rx_chain(sc);
4940 /* Free TX buffers. */
4941 bce_free_tx_chain(sc);
4943 sc->watchdog_timer = 0;
4945 sc->bce_link_up = FALSE;
4947 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
4949 DBEXIT(BCE_VERBOSE_RESET);
4954 bce_reset(struct bce_softc *sc, u32 reset_code)
4956 u32 emac_mode_save, val;
4958 static const u32 emac_mode_mask = BCE_EMAC_MODE_PORT |
4959 BCE_EMAC_MODE_HALF_DUPLEX | BCE_EMAC_MODE_25G;
4961 DBENTER(BCE_VERBOSE_RESET);
4963 DBPRINT(sc, BCE_VERBOSE_RESET, "%s(): reset_code = 0x%08X\n",
4964 __FUNCTION__, reset_code);
4967 * If ASF/IPMI is operational, then the EMAC Mode register already
4968 * contains appropriate values for the link settings that have
4969 * been auto-negotiated. Resetting the chip will clobber those
4970 * values. Save the important bits so we can restore them after
4973 emac_mode_save = REG_RD(sc, BCE_EMAC_MODE) & emac_mode_mask;
4975 /* Wait for pending PCI transactions to complete. */
4976 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
4977 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
4978 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
4979 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
4980 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
4981 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
4985 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
4986 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
4987 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
4988 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
4991 /* Assume bootcode is running. */
4992 sc->bce_fw_timed_out = FALSE;
4993 sc->bce_drv_cardiac_arrest = FALSE;
4995 /* Give the firmware a chance to prepare for the reset. */
4996 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
4998 goto bce_reset_exit;
5000 /* Set a firmware reminder that this is a soft reset. */
5001 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE, BCE_DRV_RESET_SIGNATURE_MAGIC);
5003 /* Dummy read to force the chip to complete all current transactions. */
5004 val = REG_RD(sc, BCE_MISC_ID);
5007 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
5008 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
5009 REG_RD(sc, BCE_MISC_COMMAND);
5012 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
5013 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
5015 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
5017 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
5018 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
5019 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
5020 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
5022 /* Allow up to 30us for reset to complete. */
5023 for (i = 0; i < 10; i++) {
5024 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
5025 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
5026 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
5032 /* Check that reset completed successfully. */
5033 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
5034 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
5035 BCE_PRINTF("%s(%d): Reset failed!\n",
5036 __FILE__, __LINE__);
5038 goto bce_reset_exit;
5042 /* Make sure byte swapping is properly configured. */
5043 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
5044 if (val != 0x01020304) {
5045 BCE_PRINTF("%s(%d): Byte swap is incorrect!\n",
5046 __FILE__, __LINE__);
5048 goto bce_reset_exit;
5051 /* Just completed a reset, assume that firmware is running again. */
5052 sc->bce_fw_timed_out = FALSE;
5053 sc->bce_drv_cardiac_arrest = FALSE;
5055 /* Wait for the firmware to finish its initialization. */
5056 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
5058 BCE_PRINTF("%s(%d): Firmware did not complete "
5059 "initialization!\n", __FILE__, __LINE__);
5060 /* Get firmware capabilities. */
5061 bce_fw_cap_init(sc);
5064 /* Restore EMAC Mode bits needed to keep ASF/IPMI running. */
5065 val = REG_RD(sc, BCE_EMAC_MODE);
5066 val = (val & ~emac_mode_mask) | emac_mode_save;
5067 REG_WR(sc, BCE_EMAC_MODE, val);
5069 DBEXIT(BCE_VERBOSE_RESET);
5075 bce_chipinit(struct bce_softc *sc)
5080 DBENTER(BCE_VERBOSE_RESET);
5082 bce_disable_intr(sc);
5085 * Initialize DMA byte/word swapping, configure the number of DMA
5086 * channels and PCI clock compensation delay.
5088 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
5089 BCE_DMA_CONFIG_DATA_WORD_SWAP |
5090 #if BYTE_ORDER == BIG_ENDIAN
5091 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
5093 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
5094 DMA_READ_CHANS << 12 |
5095 DMA_WRITE_CHANS << 16;
5097 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
5099 if ((sc->bce_flags & BCE_PCIX_FLAG) && (sc->bus_speed_mhz == 133))
5100 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
5103 * This setting resolves a problem observed on certain Intel PCI
5104 * chipsets that cannot handle multiple outstanding DMA operations.
5105 * See errata E9_5706A1_65.
5107 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5108 (BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0) &&
5109 !(sc->bce_flags & BCE_PCIX_FLAG))
5110 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
5112 REG_WR(sc, BCE_DMA_CONFIG, val);
5114 /* Enable the RX_V2P and Context state machines before access. */
5115 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
5116 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
5117 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
5118 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
5120 /* Initialize context mapping and zero out the quick contexts. */
5121 if ((rc = bce_init_ctx(sc)) != 0)
5122 goto bce_chipinit_exit;
5124 /* Initialize the on-boards CPUs */
5127 /* Enable management frames (NC-SI) to flow to the MCP. */
5128 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5129 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) | BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
5130 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
5133 /* Prepare NVRAM for access. */
5134 if ((rc = bce_init_nvram(sc)) != 0)
5135 goto bce_chipinit_exit;
5137 /* Set the kernel bypass block size */
5138 val = REG_RD(sc, BCE_MQ_CONFIG);
5139 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
5140 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
5142 /* Enable bins used on the 5709. */
5143 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
5144 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
5145 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
5146 val |= BCE_MQ_CONFIG_HALT_DIS;
5149 REG_WR(sc, BCE_MQ_CONFIG, val);
5151 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
5152 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
5153 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
5155 /* Set the page size and clear the RV2P processor stall bits. */
5156 val = (BCM_PAGE_BITS - 8) << 24;
5157 REG_WR(sc, BCE_RV2P_CONFIG, val);
5159 /* Configure page size. */
5160 val = REG_RD(sc, BCE_TBDR_CONFIG);
5161 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
5162 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
5163 REG_WR(sc, BCE_TBDR_CONFIG, val);
5165 /* Set the perfect match control register to default. */
5166 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
5169 DBEXIT(BCE_VERBOSE_RESET);
5175 /****************************************************************************/
5176 /* Initialize the controller in preparation to send/receive traffic. */
5179 /* 0 for success, positive value for failure. */
5180 /****************************************************************************/
5182 bce_blockinit(struct bce_softc *sc)
5187 DBENTER(BCE_VERBOSE_RESET);
5189 /* Load the hardware default MAC address. */
5190 bce_set_mac_addr(sc);
5192 /* Set the Ethernet backoff seed value */
5193 val = sc->eaddr[0] + (sc->eaddr[1] << 8) +
5194 (sc->eaddr[2] << 16) + (sc->eaddr[3] ) +
5195 (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
5196 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
5198 sc->last_status_idx = 0;
5199 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
5201 /* Set up link change interrupt generation. */
5202 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
5204 /* Program the physical address of the status block. */
5205 REG_WR(sc, BCE_HC_STATUS_ADDR_L,
5206 BCE_ADDR_LO(sc->status_block_paddr));
5207 REG_WR(sc, BCE_HC_STATUS_ADDR_H,
5208 BCE_ADDR_HI(sc->status_block_paddr));
5210 /* Program the physical address of the statistics block. */
5211 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
5212 BCE_ADDR_LO(sc->stats_block_paddr));
5213 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
5214 BCE_ADDR_HI(sc->stats_block_paddr));
5217 * Program various host coalescing parameters.
5218 * Trip points control how many BDs should be ready before generating
5219 * an interrupt while ticks control how long a BD can sit in the chain
5220 * before generating an interrupt.
5222 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5223 (sc->bce_tx_quick_cons_trip_int << 16) |
5224 sc->bce_tx_quick_cons_trip);
5225 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5226 (sc->bce_rx_quick_cons_trip_int << 16) |
5227 sc->bce_rx_quick_cons_trip);
5228 REG_WR(sc, BCE_HC_TX_TICKS,
5229 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
5230 REG_WR(sc, BCE_HC_RX_TICKS,
5231 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
5232 REG_WR(sc, BCE_HC_STATS_TICKS, sc->bce_stats_ticks & 0xffff00);
5233 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
5234 /* Not used for L2. */
5235 REG_WR(sc, BCE_HC_COMP_PROD_TRIP, 0);
5236 REG_WR(sc, BCE_HC_COM_TICKS, 0);
5237 REG_WR(sc, BCE_HC_CMD_TICKS, 0);
5239 /* Configure the Host Coalescing block. */
5240 val = BCE_HC_CONFIG_RX_TMR_MODE | BCE_HC_CONFIG_TX_TMR_MODE |
5241 BCE_HC_CONFIG_COLLECT_STATS;
5244 /* ToDo: Add MSI-X support. */
5245 if (sc->bce_flags & BCE_USING_MSIX_FLAG) {
5246 u32 base = ((BCE_TX_VEC - 1) * BCE_HC_SB_CONFIG_SIZE) +
5249 REG_WR(sc, BCE_HC_MSIX_BIT_VECTOR, BCE_HC_MSIX_BIT_VECTOR_VAL);
5251 REG_WR(sc, base, BCE_HC_SB_CONFIG_1_TX_TMR_MODE |
5252 BCE_HC_SB_CONFIG_1_ONE_SHOT);
5254 REG_WR(sc, base + BCE_HC_TX_QUICK_CONS_TRIP_OFF,
5255 (sc->tx_quick_cons_trip_int << 16) |
5256 sc->tx_quick_cons_trip);
5258 REG_WR(sc, base + BCE_HC_TX_TICKS_OFF,
5259 (sc->tx_ticks_int << 16) | sc->tx_ticks);
5261 val |= BCE_HC_CONFIG_SB_ADDR_INC_128B;
5265 * Tell the HC block to automatically set the
5266 * INT_MASK bit after an MSI/MSI-X interrupt
5267 * is generated so the driver doesn't have to.
5269 if (sc->bce_flags & BCE_ONE_SHOT_MSI_FLAG)
5270 val |= BCE_HC_CONFIG_ONE_SHOT;
5272 /* Set the MSI-X status blocks to 128 byte boundaries. */
5273 if (sc->bce_flags & BCE_USING_MSIX_FLAG)
5274 val |= BCE_HC_CONFIG_SB_ADDR_INC_128B;
5277 REG_WR(sc, BCE_HC_CONFIG, val);
5279 /* Clear the internal statistics counters. */
5280 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
5282 /* Verify that bootcode is running. */
5283 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
5285 DBRUNIF(DB_RANDOMTRUE(bootcode_running_failure_sim_control),
5286 BCE_PRINTF("%s(%d): Simulating bootcode failure.\n",
5287 __FILE__, __LINE__);
5290 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
5291 BCE_DEV_INFO_SIGNATURE_MAGIC) {
5292 BCE_PRINTF("%s(%d): Bootcode not running! Found: 0x%08X, "
5293 "Expected: 08%08X\n", __FILE__, __LINE__,
5294 (reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK),
5295 BCE_DEV_INFO_SIGNATURE_MAGIC);
5297 goto bce_blockinit_exit;
5301 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
5302 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
5303 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
5304 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
5307 /* Allow bootcode to apply additional fixes before enabling MAC. */
5308 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 |
5309 BCE_DRV_MSG_CODE_RESET);
5311 /* Enable link state change interrupt generation. */
5312 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
5314 /* Enable the RXP. */
5315 bce_start_rxp_cpu(sc);
5317 /* Disable management frames (NC-SI) from flowing to the MCP. */
5318 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5319 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
5320 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
5321 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
5324 /* Enable all remaining blocks in the MAC. */
5325 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
5326 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
5327 BCE_MISC_ENABLE_DEFAULT_XI);
5329 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
5330 BCE_MISC_ENABLE_DEFAULT);
5332 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
5335 /* Save the current host coalescing block settings. */
5336 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
5339 DBEXIT(BCE_VERBOSE_RESET);
5345 /****************************************************************************/
5346 /* Encapsulate an mbuf into the rx_bd chain. */
5349 /* 0 for success, positive value for failure. */
5350 /****************************************************************************/
5352 bce_get_rx_buf(struct bce_softc *sc, u16 prod, u16 chain_prod, u32 *prod_bseq)
5354 bus_dma_segment_t segs[1];
5355 struct mbuf *m_new = NULL;
5357 int nsegs, error, rc = 0;
5359 u16 debug_chain_prod = chain_prod;
5362 DBENTER(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5364 /* Make sure the inputs are valid. */
5365 DBRUNIF((chain_prod > MAX_RX_BD_ALLOC),
5366 BCE_PRINTF("%s(%d): RX producer out of range: "
5367 "0x%04X > 0x%04X\n", __FILE__, __LINE__,
5368 chain_prod, (u16)MAX_RX_BD_ALLOC));
5370 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): prod = 0x%04X, "
5371 "chain_prod = 0x%04X, prod_bseq = 0x%08X\n", __FUNCTION__,
5372 prod, chain_prod, *prod_bseq);
5374 /* Update some debug statistic counters */
5375 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
5376 sc->rx_low_watermark = sc->free_rx_bd);
5377 DBRUNIF((sc->free_rx_bd == sc->max_rx_bd),
5378 sc->rx_empty_count++);
5380 /* Simulate an mbuf allocation failure. */
5381 DBRUNIF(DB_RANDOMTRUE(mbuf_alloc_failed_sim_control),
5382 sc->mbuf_alloc_failed_count++;
5383 sc->mbuf_alloc_failed_sim_count++;
5385 goto bce_get_rx_buf_exit);
5387 /* This is a new mbuf allocation. */
5388 if (bce_hdr_split == TRUE)
5389 MGETHDR(m_new, M_NOWAIT, MT_DATA);
5391 m_new = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR,
5392 sc->rx_bd_mbuf_alloc_size);
5394 if (m_new == NULL) {
5395 sc->mbuf_alloc_failed_count++;
5397 goto bce_get_rx_buf_exit;
5400 DBRUN(sc->debug_rx_mbuf_alloc++);
5402 /* Make sure we have a valid packet header. */
5403 M_ASSERTPKTHDR(m_new);
5405 /* Initialize the mbuf size and pad if necessary for alignment. */
5406 m_new->m_pkthdr.len = m_new->m_len = sc->rx_bd_mbuf_alloc_size;
5407 m_adj(m_new, sc->rx_bd_mbuf_align_pad);
5409 /* ToDo: Consider calling m_fragment() to test error handling. */
5411 /* Map the mbuf cluster into device memory. */
5412 error = bus_dmamap_load_mbuf_sg(sc->rx_mbuf_tag,
5413 sc->rx_mbuf_map[chain_prod], m_new, segs, &nsegs, BUS_DMA_NOWAIT);
5415 /* Handle any mapping errors. */
5417 BCE_PRINTF("%s(%d): Error mapping mbuf into RX "
5418 "chain (%d)!\n", __FILE__, __LINE__, error);
5420 sc->dma_map_addr_rx_failed_count++;
5423 DBRUN(sc->debug_rx_mbuf_alloc--);
5426 goto bce_get_rx_buf_exit;
5429 /* All mbufs must map to a single segment. */
5430 KASSERT(nsegs == 1, ("%s(): Too many segments returned (%d)!",
5431 __FUNCTION__, nsegs));
5433 /* Setup the rx_bd for the segment. */
5434 rxbd = &sc->rx_bd_chain[RX_PAGE(chain_prod)][RX_IDX(chain_prod)];
5436 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[0].ds_addr));
5437 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[0].ds_addr));
5438 rxbd->rx_bd_len = htole32(segs[0].ds_len);
5439 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START | RX_BD_FLAGS_END);
5440 *prod_bseq += segs[0].ds_len;
5442 /* Save the mbuf and update our counter. */
5443 sc->rx_mbuf_ptr[chain_prod] = m_new;
5444 sc->free_rx_bd -= nsegs;
5446 DBRUNMSG(BCE_INSANE_RECV,
5447 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, nsegs));
5449 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): prod = 0x%04X, "
5450 "chain_prod = 0x%04X, prod_bseq = 0x%08X\n", __FUNCTION__, prod,
5451 chain_prod, *prod_bseq);
5453 bce_get_rx_buf_exit:
5454 DBEXIT(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5460 /****************************************************************************/
5461 /* Encapsulate an mbuf cluster into the page chain. */
5464 /* 0 for success, positive value for failure. */
5465 /****************************************************************************/
5467 bce_get_pg_buf(struct bce_softc *sc, u16 prod, u16 prod_idx)
5470 struct mbuf *m_new = NULL;
5474 u16 debug_prod_idx = prod_idx;
5477 DBENTER(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5479 /* Make sure the inputs are valid. */
5480 DBRUNIF((prod_idx > MAX_PG_BD_ALLOC),
5481 BCE_PRINTF("%s(%d): page producer out of range: "
5482 "0x%04X > 0x%04X\n", __FILE__, __LINE__,
5483 prod_idx, (u16)MAX_PG_BD_ALLOC));
5485 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): prod = 0x%04X, "
5486 "chain_prod = 0x%04X\n", __FUNCTION__, prod, prod_idx);
5488 /* Update counters if we've hit a new low or run out of pages. */
5489 DBRUNIF((sc->free_pg_bd < sc->pg_low_watermark),
5490 sc->pg_low_watermark = sc->free_pg_bd);
5491 DBRUNIF((sc->free_pg_bd == sc->max_pg_bd), sc->pg_empty_count++);
5493 /* Simulate an mbuf allocation failure. */
5494 DBRUNIF(DB_RANDOMTRUE(mbuf_alloc_failed_sim_control),
5495 sc->mbuf_alloc_failed_count++;
5496 sc->mbuf_alloc_failed_sim_count++;
5498 goto bce_get_pg_buf_exit);
5500 /* This is a new mbuf allocation. */
5501 m_new = m_getcl(M_NOWAIT, MT_DATA, 0);
5502 if (m_new == NULL) {
5503 sc->mbuf_alloc_failed_count++;
5505 goto bce_get_pg_buf_exit;
5508 DBRUN(sc->debug_pg_mbuf_alloc++);
5510 m_new->m_len = MCLBYTES;
5512 /* ToDo: Consider calling m_fragment() to test error handling. */
5514 /* Map the mbuf cluster into device memory. */
5515 error = bus_dmamap_load(sc->pg_mbuf_tag, sc->pg_mbuf_map[prod_idx],
5516 mtod(m_new, void *), MCLBYTES, bce_dma_map_addr, &busaddr,
5519 /* Handle any mapping errors. */
5520 if (error || busaddr == 0) {
5521 BCE_PRINTF("%s(%d): Error mapping mbuf into page chain!\n",
5522 __FILE__, __LINE__);
5525 DBRUN(sc->debug_pg_mbuf_alloc--);
5528 goto bce_get_pg_buf_exit;
5531 /* ToDo: Do we need bus_dmamap_sync(,,BUS_DMASYNC_PREREAD) here? */
5534 * The page chain uses the same rx_bd data structure
5535 * as the receive chain but doesn't require a byte sequence (bseq).
5537 pgbd = &sc->pg_bd_chain[PG_PAGE(prod_idx)][PG_IDX(prod_idx)];
5539 pgbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(busaddr));
5540 pgbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(busaddr));
5541 pgbd->rx_bd_len = htole32(MCLBYTES);
5542 pgbd->rx_bd_flags = htole32(RX_BD_FLAGS_START | RX_BD_FLAGS_END);
5544 /* Save the mbuf and update our counter. */
5545 sc->pg_mbuf_ptr[prod_idx] = m_new;
5548 DBRUNMSG(BCE_INSANE_RECV,
5549 bce_dump_pg_mbuf_chain(sc, debug_prod_idx, 1));
5551 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): prod = 0x%04X, "
5552 "prod_idx = 0x%04X\n", __FUNCTION__, prod, prod_idx);
5554 bce_get_pg_buf_exit:
5555 DBEXIT(BCE_EXTREME_RESET | BCE_EXTREME_RECV | BCE_EXTREME_LOAD);
5561 /****************************************************************************/
5562 /* Initialize the TX context memory. */
5566 /****************************************************************************/
5568 bce_init_tx_context(struct bce_softc *sc)
5572 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
5574 /* Initialize the context ID for an L2 TX chain. */
5575 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
5576 /* Set the CID type to support an L2 connection. */
5577 val = BCE_L2CTX_TX_TYPE_TYPE_L2_XI |
5578 BCE_L2CTX_TX_TYPE_SIZE_L2_XI;
5579 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
5580 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2_XI | (8 << 16);
5581 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5582 BCE_L2CTX_TX_CMD_TYPE_XI, val);
5584 /* Point the hardware to the first page in the chain. */
5585 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
5586 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5587 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
5588 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
5589 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5590 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
5592 /* Set the CID type to support an L2 connection. */
5593 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
5594 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
5595 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
5596 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
5598 /* Point the hardware to the first page in the chain. */
5599 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
5600 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5601 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
5602 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
5603 CTX_WR(sc, GET_CID_ADDR(TX_CID),
5604 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
5607 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
5611 /****************************************************************************/
5612 /* Allocate memory and initialize the TX data structures. */
5615 /* 0 for success, positive value for failure. */
5616 /****************************************************************************/
5618 bce_init_tx_chain(struct bce_softc *sc)
5623 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_LOAD);
5625 /* Set the initial TX producer/consumer indices. */
5628 sc->tx_prod_bseq = 0;
5630 sc->max_tx_bd = USABLE_TX_BD_ALLOC;
5631 DBRUN(sc->tx_hi_watermark = 0);
5632 DBRUN(sc->tx_full_count = 0);
5635 * The NetXtreme II supports a linked-list structre called
5636 * a Buffer Descriptor Chain (or BD chain). A BD chain
5637 * consists of a series of 1 or more chain pages, each of which
5638 * consists of a fixed number of BD entries.
5639 * The last BD entry on each page is a pointer to the next page
5640 * in the chain, and the last pointer in the BD chain
5641 * points back to the beginning of the chain.
5644 /* Set the TX next pointer chain entries. */
5645 for (i = 0; i < sc->tx_pages; i++) {
5648 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
5650 /* Check if we've reached the last page. */
5651 if (i == (sc->tx_pages - 1))
5656 txbd->tx_bd_haddr_hi =
5657 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
5658 txbd->tx_bd_haddr_lo =
5659 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
5662 bce_init_tx_context(sc);
5664 DBRUNMSG(BCE_INSANE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD_ALLOC));
5665 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_LOAD);
5671 /****************************************************************************/
5672 /* Free memory and clear the TX data structures. */
5676 /****************************************************************************/
5678 bce_free_tx_chain(struct bce_softc *sc)
5682 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_UNLOAD);
5684 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
5685 for (i = 0; i < MAX_TX_BD_AVAIL; i++) {
5686 if (sc->tx_mbuf_ptr[i] != NULL) {
5687 if (sc->tx_mbuf_map[i] != NULL)
5688 bus_dmamap_sync(sc->tx_mbuf_tag,
5690 BUS_DMASYNC_POSTWRITE);
5691 m_freem(sc->tx_mbuf_ptr[i]);
5692 sc->tx_mbuf_ptr[i] = NULL;
5693 DBRUN(sc->debug_tx_mbuf_alloc--);
5697 /* Clear each TX chain page. */
5698 for (i = 0; i < sc->tx_pages; i++)
5699 bzero((char *)sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
5703 /* Check if we lost any mbufs in the process. */
5704 DBRUNIF((sc->debug_tx_mbuf_alloc),
5705 BCE_PRINTF("%s(%d): Memory leak! Lost %d mbufs "
5706 "from tx chain!\n", __FILE__, __LINE__,
5707 sc->debug_tx_mbuf_alloc));
5709 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_SEND | BCE_VERBOSE_UNLOAD);
5713 /****************************************************************************/
5714 /* Initialize the RX context memory. */
5718 /****************************************************************************/
5720 bce_init_rx_context(struct bce_softc *sc)
5724 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_CTX);
5726 /* Init the type, size, and BD cache levels for the RX context. */
5727 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
5728 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 |
5729 (0x02 << BCE_L2CTX_RX_BD_PRE_READ_SHIFT);
5732 * Set the level for generating pause frames
5733 * when the number of available rx_bd's gets
5734 * too low (the low watermark) and the level
5735 * when pause frames can be stopped (the high
5738 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
5739 u32 lo_water, hi_water;
5741 if (sc->bce_flags & BCE_USING_TX_FLOW_CONTROL) {
5742 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
5747 if (lo_water >= USABLE_RX_BD_ALLOC) {
5751 hi_water = USABLE_RX_BD_ALLOC / 4;
5753 if (hi_water <= lo_water) {
5757 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
5758 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
5762 else if (hi_water == 0)
5765 val |= (lo_water << BCE_L2CTX_RX_LO_WATER_MARK_SHIFT) |
5766 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
5769 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
5771 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
5772 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
5773 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
5774 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
5777 /* Point the hardware to the first page in the chain. */
5778 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
5779 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
5780 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
5781 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
5783 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_CTX);
5787 /****************************************************************************/
5788 /* Allocate memory and initialize the RX data structures. */
5791 /* 0 for success, positive value for failure. */
5792 /****************************************************************************/
5794 bce_init_rx_chain(struct bce_softc *sc)
5799 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5802 /* Initialize the RX producer and consumer indices. */
5805 sc->rx_prod_bseq = 0;
5806 sc->free_rx_bd = USABLE_RX_BD_ALLOC;
5807 sc->max_rx_bd = USABLE_RX_BD_ALLOC;
5809 /* Initialize the RX next pointer chain entries. */
5810 for (i = 0; i < sc->rx_pages; i++) {
5813 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
5815 /* Check if we've reached the last page. */
5816 if (i == (sc->rx_pages - 1))
5821 /* Setup the chain page pointers. */
5822 rxbd->rx_bd_haddr_hi =
5823 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
5824 rxbd->rx_bd_haddr_lo =
5825 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
5828 /* Fill up the RX chain. */
5829 bce_fill_rx_chain(sc);
5831 DBRUN(sc->rx_low_watermark = USABLE_RX_BD_ALLOC);
5832 DBRUN(sc->rx_empty_count = 0);
5833 for (i = 0; i < sc->rx_pages; i++) {
5834 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
5835 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
5838 bce_init_rx_context(sc);
5840 DBRUNMSG(BCE_EXTREME_RECV,
5841 bce_dump_rx_bd_chain(sc, 0, TOTAL_RX_BD_ALLOC));
5842 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5845 /* ToDo: Are there possible failure modes here? */
5851 /****************************************************************************/
5852 /* Add mbufs to the RX chain until its full or an mbuf allocation error */
5857 /****************************************************************************/
5859 bce_fill_rx_chain(struct bce_softc *sc)
5864 DBENTER(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5867 /* Get the RX chain producer indices. */
5869 prod_bseq = sc->rx_prod_bseq;
5871 /* Keep filling the RX chain until it's full. */
5872 while (sc->free_rx_bd > 0) {
5873 prod_idx = RX_CHAIN_IDX(prod);
5874 if (bce_get_rx_buf(sc, prod, prod_idx, &prod_bseq)) {
5875 /* Bail out if we can't add an mbuf to the chain. */
5878 prod = NEXT_RX_BD(prod);
5881 /* Save the RX chain producer indices. */
5883 sc->rx_prod_bseq = prod_bseq;
5885 /* We should never end up pointing to a next page pointer. */
5886 DBRUNIF(((prod & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE),
5887 BCE_PRINTF("%s(): Invalid rx_prod value: 0x%04X\n",
5888 __FUNCTION__, rx_prod));
5890 /* Write the mailbox and tell the chip about the waiting rx_bd's. */
5891 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX, prod);
5892 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ, prod_bseq);
5894 DBEXIT(BCE_VERBOSE_RESET | BCE_EXTREME_RECV | BCE_VERBOSE_LOAD |
5899 /****************************************************************************/
5900 /* Free memory and clear the RX data structures. */
5904 /****************************************************************************/
5906 bce_free_rx_chain(struct bce_softc *sc)
5910 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5912 /* Free any mbufs still in the RX mbuf chain. */
5913 for (i = 0; i < MAX_RX_BD_AVAIL; i++) {
5914 if (sc->rx_mbuf_ptr[i] != NULL) {
5915 if (sc->rx_mbuf_map[i] != NULL)
5916 bus_dmamap_sync(sc->rx_mbuf_tag,
5918 BUS_DMASYNC_POSTREAD);
5919 m_freem(sc->rx_mbuf_ptr[i]);
5920 sc->rx_mbuf_ptr[i] = NULL;
5921 DBRUN(sc->debug_rx_mbuf_alloc--);
5925 /* Clear each RX chain page. */
5926 for (i = 0; i < sc->rx_pages; i++)
5927 if (sc->rx_bd_chain[i] != NULL)
5928 bzero((char *)sc->rx_bd_chain[i],
5929 BCE_RX_CHAIN_PAGE_SZ);
5931 sc->free_rx_bd = sc->max_rx_bd;
5933 /* Check if we lost any mbufs in the process. */
5934 DBRUNIF((sc->debug_rx_mbuf_alloc),
5935 BCE_PRINTF("%s(): Memory leak! Lost %d mbufs from rx chain!\n",
5936 __FUNCTION__, sc->debug_rx_mbuf_alloc));
5938 DBEXIT(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_UNLOAD);
5942 /****************************************************************************/
5943 /* Allocate memory and initialize the page data structures. */
5944 /* Assumes that bce_init_rx_chain() has not already been called. */
5947 /* 0 for success, positive value for failure. */
5948 /****************************************************************************/
5950 bce_init_pg_chain(struct bce_softc *sc)
5956 DBENTER(BCE_VERBOSE_RESET | BCE_VERBOSE_RECV | BCE_VERBOSE_LOAD |
5959 /* Initialize the page producer and consumer indices. */
5962 sc->free_pg_bd = USABLE_PG_BD_ALLOC;
5963 sc->max_pg_bd = USABLE_PG_BD_ALLOC;
5964 DBRUN(sc->pg_low_watermark = sc->max_pg_bd);
5965 DBRUN(sc->pg_empty_count = 0);
5967 /* Initialize the page next pointer chain entries. */
5968 for (i = 0; i < sc->pg_pages; i++) {
5971 pgbd = &sc->pg_bd_chain[i][USABLE_PG_BD_PER_PAGE];
5973 /* Check if we've reached the last page. */
5974 if (i == (sc->pg_pages - 1))
5979 /* Setup the chain page pointers. */
5980 pgbd->rx_bd_haddr_hi =
5981 htole32(BCE_ADDR_HI(sc->pg_bd_chain_paddr[j]));
5982 pgbd->rx_bd_haddr_lo =
5983 htole32(BCE_ADDR_LO(sc->pg_bd_chain_paddr[j]));
5986 /* Setup the MQ BIN mapping for host_pg_bidx. */
5987 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
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) | MCLBYTES;
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, 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__, 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) + BCE_L2MQ_RX_HOST_PG_BDIDX,
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);
6111 bce_get_rphy_link(struct bce_softc *sc)
6113 u32 advertise, link;
6118 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) != 0)
6119 link = bce_shmem_rd(sc, BCE_RPHY_SERDES_LINK);
6121 link = bce_shmem_rd(sc, BCE_RPHY_COPPER_LINK);
6122 if (link & BCE_NETLINK_ANEG_ENB)
6123 advertise |= BCE_NETLINK_ANEG_ENB;
6124 if (link & BCE_NETLINK_SPEED_10HALF)
6125 advertise |= BCE_NETLINK_SPEED_10HALF;
6126 if (link & BCE_NETLINK_SPEED_10FULL) {
6127 advertise |= BCE_NETLINK_SPEED_10FULL;
6130 if (link & BCE_NETLINK_SPEED_100HALF)
6131 advertise |= BCE_NETLINK_SPEED_100HALF;
6132 if (link & BCE_NETLINK_SPEED_100FULL) {
6133 advertise |= BCE_NETLINK_SPEED_100FULL;
6136 if (link & BCE_NETLINK_SPEED_1000HALF)
6137 advertise |= BCE_NETLINK_SPEED_1000HALF;
6138 if (link & BCE_NETLINK_SPEED_1000FULL) {
6139 advertise |= BCE_NETLINK_SPEED_1000FULL;
6142 if (link & BCE_NETLINK_SPEED_2500HALF)
6143 advertise |= BCE_NETLINK_SPEED_2500HALF;
6144 if (link & BCE_NETLINK_SPEED_2500FULL) {
6145 advertise |= BCE_NETLINK_SPEED_2500FULL;
6149 advertise |= BCE_NETLINK_FC_PAUSE_SYM |
6150 BCE_NETLINK_FC_PAUSE_ASYM;
6151 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0)
6152 advertise |= BCE_NETLINK_PHY_APP_REMOTE |
6153 BCE_NETLINK_ETH_AT_WIRESPEED;
6159 /****************************************************************************/
6160 /* Set media options. */
6163 /* 0 for success, positive value for failure. */
6164 /****************************************************************************/
6166 bce_ifmedia_upd(struct ifnet *ifp)
6168 struct bce_softc *sc = ifp->if_softc;
6171 DBENTER(BCE_VERBOSE);
6174 error = bce_ifmedia_upd_locked(ifp);
6177 DBEXIT(BCE_VERBOSE);
6182 /****************************************************************************/
6183 /* Set media options. */
6187 /****************************************************************************/
6189 bce_ifmedia_upd_locked(struct ifnet *ifp)
6191 struct bce_softc *sc = ifp->if_softc;
6192 struct mii_data *mii;
6193 struct mii_softc *miisc;
6194 struct ifmedia *ifm;
6198 DBENTER(BCE_VERBOSE_PHY);
6201 BCE_LOCK_ASSERT(sc);
6203 sc->bce_link_up = FALSE;
6204 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0) {
6205 ifm = &sc->bce_ifmedia;
6206 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
6209 fdx = IFM_OPTIONS(ifm->ifm_media) & IFM_FDX;
6210 switch(IFM_SUBTYPE(ifm->ifm_media)) {
6213 * Check advertised link of remote PHY by reading
6214 * BCE_RPHY_SERDES_LINK or BCE_RPHY_COPPER_LINK.
6215 * Always use the same link type of remote PHY.
6217 link = bce_get_rphy_link(sc);
6220 if ((sc->bce_phy_flags &
6221 (BCE_PHY_REMOTE_PORT_FIBER_FLAG |
6222 BCE_PHY_2_5G_CAPABLE_FLAG)) == 0)
6226 * Have to enable forced 2.5Gbps configuration.
6229 link |= BCE_NETLINK_SPEED_2500FULL;
6231 link |= BCE_NETLINK_SPEED_2500HALF;
6234 if ((sc->bce_phy_flags &
6235 BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0)
6239 * Have to disable 2.5Gbps configuration.
6242 link = BCE_NETLINK_SPEED_1000FULL;
6244 link = BCE_NETLINK_SPEED_1000HALF;
6247 if (sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG)
6250 link = BCE_NETLINK_SPEED_1000FULL;
6252 link = BCE_NETLINK_SPEED_1000HALF;
6255 if (sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG)
6258 link = BCE_NETLINK_SPEED_100FULL;
6260 link = BCE_NETLINK_SPEED_100HALF;
6263 if (sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG)
6266 link = BCE_NETLINK_SPEED_10FULL;
6268 link = BCE_NETLINK_SPEED_10HALF;
6273 if (IFM_SUBTYPE(ifm->ifm_media) != IFM_AUTO) {
6276 * Advertise pause capability for full-duplex media.
6279 link |= BCE_NETLINK_FC_PAUSE_SYM |
6280 BCE_NETLINK_FC_PAUSE_ASYM;
6281 if ((sc->bce_phy_flags &
6282 BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0)
6283 link |= BCE_NETLINK_PHY_APP_REMOTE |
6284 BCE_NETLINK_ETH_AT_WIRESPEED;
6287 bce_shmem_wr(sc, BCE_MB_ARGS_0, link);
6288 error = bce_fw_sync(sc, BCE_DRV_MSG_CODE_CMD_SET_LINK);
6290 mii = device_get_softc(sc->bce_miibus);
6292 /* Make sure the MII bus has been enumerated. */
6294 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
6296 error = mii_mediachg(mii);
6300 DBEXIT(BCE_VERBOSE_PHY);
6306 bce_ifmedia_sts_rphy(struct bce_softc *sc, struct ifmediareq *ifmr)
6312 BCE_LOCK_ASSERT(sc);
6314 ifmr->ifm_status = IFM_AVALID;
6315 ifmr->ifm_active = IFM_ETHER;
6316 link = bce_shmem_rd(sc, BCE_LINK_STATUS);
6317 /* XXX Handle heart beat status? */
6318 if ((link & BCE_LINK_STATUS_LINK_UP) != 0)
6319 ifmr->ifm_status |= IFM_ACTIVE;
6321 ifmr->ifm_active |= IFM_NONE;
6322 ifp->if_baudrate = 0;
6325 switch (link & BCE_LINK_STATUS_SPEED_MASK) {
6326 case BCE_LINK_STATUS_10HALF:
6327 ifmr->ifm_active |= IFM_10_T | IFM_HDX;
6328 ifp->if_baudrate = IF_Mbps(10UL);
6330 case BCE_LINK_STATUS_10FULL:
6331 ifmr->ifm_active |= IFM_10_T | IFM_FDX;
6332 ifp->if_baudrate = IF_Mbps(10UL);
6334 case BCE_LINK_STATUS_100HALF:
6335 ifmr->ifm_active |= IFM_100_TX | IFM_HDX;
6336 ifp->if_baudrate = IF_Mbps(100UL);
6338 case BCE_LINK_STATUS_100FULL:
6339 ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
6340 ifp->if_baudrate = IF_Mbps(100UL);
6342 case BCE_LINK_STATUS_1000HALF:
6343 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0)
6344 ifmr->ifm_active |= IFM_1000_T | IFM_HDX;
6346 ifmr->ifm_active |= IFM_1000_SX | IFM_HDX;
6347 ifp->if_baudrate = IF_Mbps(1000UL);
6349 case BCE_LINK_STATUS_1000FULL:
6350 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0)
6351 ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
6353 ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
6354 ifp->if_baudrate = IF_Mbps(1000UL);
6356 case BCE_LINK_STATUS_2500HALF:
6357 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0) {
6358 ifmr->ifm_active |= IFM_NONE;
6361 ifmr->ifm_active |= IFM_2500_SX | IFM_HDX;
6362 ifp->if_baudrate = IF_Mbps(2500UL);
6364 case BCE_LINK_STATUS_2500FULL:
6365 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_PORT_FIBER_FLAG) == 0) {
6366 ifmr->ifm_active |= IFM_NONE;
6369 ifmr->ifm_active |= IFM_2500_SX | IFM_FDX;
6370 ifp->if_baudrate = IF_Mbps(2500UL);
6373 ifmr->ifm_active |= IFM_NONE;
6377 if ((link & BCE_LINK_STATUS_RX_FC_ENABLED) != 0)
6378 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
6379 if ((link & BCE_LINK_STATUS_TX_FC_ENABLED) != 0)
6380 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
6384 /****************************************************************************/
6385 /* Reports current media status. */
6389 /****************************************************************************/
6391 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
6393 struct bce_softc *sc = ifp->if_softc;
6394 struct mii_data *mii;
6396 DBENTER(BCE_VERBOSE_PHY);
6400 if ((ifp->if_flags & IFF_UP) == 0) {
6405 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0)
6406 bce_ifmedia_sts_rphy(sc, ifmr);
6408 mii = device_get_softc(sc->bce_miibus);
6410 ifmr->ifm_active = mii->mii_media_active;
6411 ifmr->ifm_status = mii->mii_media_status;
6416 DBEXIT(BCE_VERBOSE_PHY);
6420 /****************************************************************************/
6421 /* Handles PHY generated interrupt events. */
6425 /****************************************************************************/
6427 bce_phy_intr(struct bce_softc *sc)
6429 u32 new_link_state, old_link_state;
6431 DBENTER(BCE_VERBOSE_PHY | BCE_VERBOSE_INTR);
6433 DBRUN(sc->phy_interrupts++);
6435 new_link_state = sc->status_block->status_attn_bits &
6436 STATUS_ATTN_BITS_LINK_STATE;
6437 old_link_state = sc->status_block->status_attn_bits_ack &
6438 STATUS_ATTN_BITS_LINK_STATE;
6440 /* Handle any changes if the link state has changed. */
6441 if (new_link_state != old_link_state) {
6443 /* Update the status_attn_bits_ack field. */
6444 if (new_link_state) {
6445 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
6446 STATUS_ATTN_BITS_LINK_STATE);
6447 DBPRINT(sc, BCE_INFO_PHY, "%s(): Link is now UP.\n",
6450 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
6451 STATUS_ATTN_BITS_LINK_STATE);
6452 DBPRINT(sc, BCE_INFO_PHY, "%s(): Link is now DOWN.\n",
6456 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0) {
6457 if (new_link_state) {
6459 if_printf(sc->bce_ifp, "link UP\n");
6460 if_link_state_change(sc->bce_ifp,
6464 if_printf(sc->bce_ifp, "link DOWN\n");
6465 if_link_state_change(sc->bce_ifp,
6470 * Assume link is down and allow
6471 * tick routine to update the state
6472 * based on the actual media state.
6474 sc->bce_link_up = FALSE;
6475 callout_stop(&sc->bce_tick_callout);
6479 /* Acknowledge the link change interrupt. */
6480 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
6482 DBEXIT(BCE_VERBOSE_PHY | BCE_VERBOSE_INTR);
6486 /****************************************************************************/
6487 /* Reads the receive consumer value from the status block (skipping over */
6488 /* chain page pointer if necessary). */
6492 /****************************************************************************/
6494 bce_get_hw_rx_cons(struct bce_softc *sc)
6499 hw_cons = sc->status_block->status_rx_quick_consumer_index0;
6500 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
6506 /****************************************************************************/
6507 /* Handles received frame interrupt events. */
6511 /****************************************************************************/
6513 bce_rx_intr(struct bce_softc *sc)
6515 struct ifnet *ifp = sc->bce_ifp;
6516 struct l2_fhdr *l2fhdr;
6517 struct ether_vlan_header *vh;
6518 unsigned int pkt_len;
6519 u16 sw_rx_cons, sw_rx_cons_idx, hw_rx_cons;
6521 unsigned int rem_len;
6522 u16 sw_pg_cons, sw_pg_cons_idx;
6524 DBENTER(BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
6525 DBRUN(sc->interrupts_rx++);
6526 DBPRINT(sc, BCE_EXTREME_RECV, "%s(enter): rx_prod = 0x%04X, "
6527 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
6528 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
6530 /* Prepare the RX chain pages to be accessed by the host CPU. */
6531 for (int i = 0; i < sc->rx_pages; i++)
6532 bus_dmamap_sync(sc->rx_bd_chain_tag,
6533 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
6535 /* Prepare the page chain pages to be accessed by the host CPU. */
6536 if (bce_hdr_split == TRUE) {
6537 for (int i = 0; i < sc->pg_pages; i++)
6538 bus_dmamap_sync(sc->pg_bd_chain_tag,
6539 sc->pg_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
6542 /* Get the hardware's view of the RX consumer index. */
6543 hw_rx_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
6545 /* Get working copies of the driver's view of the consumer indices. */
6546 sw_rx_cons = sc->rx_cons;
6547 sw_pg_cons = sc->pg_cons;
6549 /* Update some debug statistics counters */
6550 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
6551 sc->rx_low_watermark = sc->free_rx_bd);
6552 DBRUNIF((sc->free_rx_bd == sc->max_rx_bd),
6553 sc->rx_empty_count++);
6555 /* Scan through the receive chain as long as there is work to do */
6556 /* ToDo: Consider setting a limit on the number of packets processed. */
6558 while (sw_rx_cons != hw_rx_cons) {
6561 /* Convert the producer/consumer indices to an actual rx_bd index. */
6562 sw_rx_cons_idx = RX_CHAIN_IDX(sw_rx_cons);
6564 /* Unmap the mbuf from DMA space. */
6565 bus_dmamap_sync(sc->rx_mbuf_tag,
6566 sc->rx_mbuf_map[sw_rx_cons_idx],
6567 BUS_DMASYNC_POSTREAD);
6568 bus_dmamap_unload(sc->rx_mbuf_tag,
6569 sc->rx_mbuf_map[sw_rx_cons_idx]);
6571 /* Remove the mbuf from the RX chain. */
6572 m0 = sc->rx_mbuf_ptr[sw_rx_cons_idx];
6573 sc->rx_mbuf_ptr[sw_rx_cons_idx] = NULL;
6574 DBRUN(sc->debug_rx_mbuf_alloc--);
6578 * Frames received on the NetXteme II are prepended
6579 * with an l2_fhdr structure which provides status
6580 * information about the received frame (including
6581 * VLAN tags and checksum info). The frames are
6582 * also automatically adjusted to word align the IP
6583 * header (i.e. two null bytes are inserted before
6584 * the Ethernet header). As a result the data
6585 * DMA'd by the controller into the mbuf looks
6588 * +---------+-----+---------------------+-----+
6589 * | l2_fhdr | pad | packet data | FCS |
6590 * +---------+-----+---------------------+-----+
6592 * The l2_fhdr needs to be checked and skipped and
6593 * the FCS needs to be stripped before sending the
6594 * packet up the stack.
6596 l2fhdr = mtod(m0, struct l2_fhdr *);
6598 /* Get the packet data + FCS length and the status. */
6599 pkt_len = l2fhdr->l2_fhdr_pkt_len;
6600 status = l2fhdr->l2_fhdr_status;
6603 * Skip over the l2_fhdr and pad, resulting in the
6604 * following data in the mbuf:
6605 * +---------------------+-----+
6606 * | packet data | FCS |
6607 * +---------------------+-----+
6609 m_adj(m0, sizeof(struct l2_fhdr) + ETHER_ALIGN);
6612 * When split header mode is used, an ethernet frame
6613 * may be split across the receive chain and the
6614 * page chain. If that occurs an mbuf cluster must be
6615 * reassembled from the individual mbuf pieces.
6617 if (bce_hdr_split == TRUE) {
6619 * Check whether the received frame fits in a single
6620 * mbuf or not (i.e. packet data + FCS <=
6621 * sc->rx_bd_mbuf_data_len bytes).
6623 if (pkt_len > m0->m_len) {
6625 * The received frame is larger than a single mbuf.
6626 * If the frame was a TCP frame then only the TCP
6627 * header is placed in the mbuf, the remaining
6628 * payload (including FCS) is placed in the page
6629 * chain, the SPLIT flag is set, and the header
6630 * length is placed in the IP checksum field.
6631 * If the frame is not a TCP frame then the mbuf
6632 * is filled and the remaining bytes are placed
6633 * in the page chain.
6636 DBPRINT(sc, BCE_INFO_RECV, "%s(): Found a large "
6637 "packet.\n", __FUNCTION__);
6638 DBRUN(sc->split_header_frames_rcvd++);
6641 * When the page chain is enabled and the TCP
6642 * header has been split from the TCP payload,
6643 * the ip_xsum structure will reflect the length
6644 * of the TCP header, not the IP checksum. Set
6645 * the packet length of the mbuf accordingly.
6647 if (status & L2_FHDR_STATUS_SPLIT) {
6648 m0->m_len = l2fhdr->l2_fhdr_ip_xsum;
6649 DBRUN(sc->split_header_tcp_frames_rcvd++);
6652 rem_len = pkt_len - m0->m_len;
6654 /* Pull mbufs off the page chain for any remaining data. */
6655 while (rem_len > 0) {
6658 sw_pg_cons_idx = PG_CHAIN_IDX(sw_pg_cons);
6660 /* Remove the mbuf from the page chain. */
6661 m_pg = sc->pg_mbuf_ptr[sw_pg_cons_idx];
6662 sc->pg_mbuf_ptr[sw_pg_cons_idx] = NULL;
6663 DBRUN(sc->debug_pg_mbuf_alloc--);
6666 /* Unmap the page chain mbuf from DMA space. */
6667 bus_dmamap_sync(sc->pg_mbuf_tag,
6668 sc->pg_mbuf_map[sw_pg_cons_idx],
6669 BUS_DMASYNC_POSTREAD);
6670 bus_dmamap_unload(sc->pg_mbuf_tag,
6671 sc->pg_mbuf_map[sw_pg_cons_idx]);
6673 /* Adjust the mbuf length. */
6674 if (rem_len < m_pg->m_len) {
6675 /* The mbuf chain is complete. */
6676 m_pg->m_len = rem_len;
6679 /* More packet data is waiting. */
6680 rem_len -= m_pg->m_len;
6683 /* Concatenate the mbuf cluster to the mbuf. */
6686 sw_pg_cons = NEXT_PG_BD(sw_pg_cons);
6689 /* Set the total packet length. */
6690 m0->m_pkthdr.len = pkt_len;
6694 * The received packet is small and fits in a
6695 * single mbuf (i.e. the l2_fhdr + pad + packet +
6696 * FCS <= MHLEN). In other words, the packet is
6697 * 154 bytes or less in size.
6700 DBPRINT(sc, BCE_INFO_RECV, "%s(): Found a small "
6701 "packet.\n", __FUNCTION__);
6703 /* Set the total packet length. */
6704 m0->m_pkthdr.len = m0->m_len = pkt_len;
6707 /* Set the total packet length. */
6708 m0->m_pkthdr.len = m0->m_len = pkt_len;
6710 /* Remove the trailing Ethernet FCS. */
6711 m_adj(m0, -ETHER_CRC_LEN);
6713 /* Check that the resulting mbuf chain is valid. */
6714 DBRUN(m_sanity(m0, FALSE));
6715 DBRUNIF(((m0->m_len < ETHER_HDR_LEN) |
6716 (m0->m_pkthdr.len > BCE_MAX_JUMBO_ETHER_MTU_VLAN)),
6717 BCE_PRINTF("Invalid Ethernet frame size!\n");
6720 DBRUNIF(DB_RANDOMTRUE(l2fhdr_error_sim_control),
6721 sc->l2fhdr_error_sim_count++;
6722 status = status | L2_FHDR_ERRORS_PHY_DECODE);
6724 /* Check the received frame for errors. */
6725 if (status & (L2_FHDR_ERRORS_BAD_CRC |
6726 L2_FHDR_ERRORS_PHY_DECODE | L2_FHDR_ERRORS_ALIGNMENT |
6727 L2_FHDR_ERRORS_TOO_SHORT | L2_FHDR_ERRORS_GIANT_FRAME)) {
6729 /* Log the error and release the mbuf. */
6731 sc->l2fhdr_error_count++;
6735 goto bce_rx_intr_next_rx;
6738 /* Send the packet to the appropriate interface. */
6739 m0->m_pkthdr.rcvif = ifp;
6741 /* Assume no hardware checksum. */
6742 m0->m_pkthdr.csum_flags = 0;
6744 /* Validate the checksum if offload enabled. */
6745 if (ifp->if_capenable & IFCAP_RXCSUM) {
6746 /* Check for an IP datagram. */
6747 if (!(status & L2_FHDR_STATUS_SPLIT) &&
6748 (status & L2_FHDR_STATUS_IP_DATAGRAM)) {
6749 m0->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
6750 DBRUN(sc->csum_offload_ip++);
6751 /* Check if the IP checksum is valid. */
6752 if ((l2fhdr->l2_fhdr_ip_xsum ^ 0xffff) == 0)
6753 m0->m_pkthdr.csum_flags |=
6757 /* Check for a valid TCP/UDP frame. */
6758 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
6759 L2_FHDR_STATUS_UDP_DATAGRAM)) {
6761 /* Check for a good TCP/UDP checksum. */
6762 if ((status & (L2_FHDR_ERRORS_TCP_XSUM |
6763 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
6764 DBRUN(sc->csum_offload_tcp_udp++);
6765 m0->m_pkthdr.csum_data =
6766 l2fhdr->l2_fhdr_tcp_udp_xsum;
6767 m0->m_pkthdr.csum_flags |=
6774 /* Attach the VLAN tag. */
6775 if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) &&
6776 !(sc->rx_mode & BCE_EMAC_RX_MODE_KEEP_VLAN_TAG)) {
6777 DBRUN(sc->vlan_tagged_frames_rcvd++);
6778 if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) {
6779 DBRUN(sc->vlan_tagged_frames_stripped++);
6780 #if __FreeBSD_version < 700000
6781 VLAN_INPUT_TAG(ifp, m0,
6782 l2fhdr->l2_fhdr_vlan_tag, continue);
6784 m0->m_pkthdr.ether_vtag =
6785 l2fhdr->l2_fhdr_vlan_tag;
6786 m0->m_flags |= M_VLANTAG;
6790 * bce(4) controllers can't disable VLAN
6791 * tag stripping if management firmware
6792 * (ASF/IPMI/UMP) is running. So we always
6793 * strip VLAN tag and manually reconstruct
6794 * the VLAN frame by appending stripped
6795 * VLAN tag in driver if VLAN tag stripping
6798 * TODO: LLC SNAP handling.
6800 bcopy(mtod(m0, uint8_t *),
6801 mtod(m0, uint8_t *) - ETHER_VLAN_ENCAP_LEN,
6802 ETHER_ADDR_LEN * 2);
6803 m0->m_data -= ETHER_VLAN_ENCAP_LEN;
6804 vh = mtod(m0, struct ether_vlan_header *);
6805 vh->evl_encap_proto = htons(ETHERTYPE_VLAN);
6806 vh->evl_tag = htons(l2fhdr->l2_fhdr_vlan_tag);
6807 m0->m_pkthdr.len += ETHER_VLAN_ENCAP_LEN;
6808 m0->m_len += ETHER_VLAN_ENCAP_LEN;
6812 /* Increment received packet statistics. */
6815 bce_rx_intr_next_rx:
6816 sw_rx_cons = NEXT_RX_BD(sw_rx_cons);
6818 /* If we have a packet, pass it up the stack */
6820 /* Make sure we don't lose our place when we release the lock. */
6821 sc->rx_cons = sw_rx_cons;
6822 sc->pg_cons = sw_pg_cons;
6825 (*ifp->if_input)(ifp, m0);
6828 /* Recover our place. */
6829 sw_rx_cons = sc->rx_cons;
6830 sw_pg_cons = sc->pg_cons;
6833 /* Refresh hw_cons to see if there's new work */
6834 if (sw_rx_cons == hw_rx_cons)
6835 hw_rx_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
6838 /* No new packets. Refill the page chain. */
6839 if (bce_hdr_split == TRUE) {
6840 sc->pg_cons = sw_pg_cons;
6841 bce_fill_pg_chain(sc);
6844 /* No new packets. Refill the RX chain. */
6845 sc->rx_cons = sw_rx_cons;
6846 bce_fill_rx_chain(sc);
6848 /* Prepare the page chain pages to be accessed by the NIC. */
6849 for (int i = 0; i < sc->rx_pages; i++)
6850 bus_dmamap_sync(sc->rx_bd_chain_tag,
6851 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
6853 if (bce_hdr_split == TRUE) {
6854 for (int i = 0; i < sc->pg_pages; i++)
6855 bus_dmamap_sync(sc->pg_bd_chain_tag,
6856 sc->pg_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
6859 DBPRINT(sc, BCE_EXTREME_RECV, "%s(exit): rx_prod = 0x%04X, "
6860 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
6861 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
6862 DBEXIT(BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
6866 /****************************************************************************/
6867 /* Reads the transmit consumer value from the status block (skipping over */
6868 /* chain page pointer if necessary). */
6872 /****************************************************************************/
6874 bce_get_hw_tx_cons(struct bce_softc *sc)
6879 hw_cons = sc->status_block->status_tx_quick_consumer_index0;
6880 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
6887 /****************************************************************************/
6888 /* Handles transmit completion interrupt events. */
6892 /****************************************************************************/
6894 bce_tx_intr(struct bce_softc *sc)
6896 struct ifnet *ifp = sc->bce_ifp;
6897 u16 hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
6899 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_INTR);
6900 DBRUN(sc->interrupts_tx++);
6901 DBPRINT(sc, BCE_EXTREME_SEND, "%s(enter): tx_prod = 0x%04X, "
6902 "tx_cons = 0x%04X, tx_prod_bseq = 0x%08X\n",
6903 __FUNCTION__, sc->tx_prod, sc->tx_cons, sc->tx_prod_bseq);
6905 BCE_LOCK_ASSERT(sc);
6907 /* Get the hardware's view of the TX consumer index. */
6908 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
6909 sw_tx_cons = sc->tx_cons;
6911 /* Prevent speculative reads of the status block. */
6912 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
6913 BUS_SPACE_BARRIER_READ);
6915 /* Cycle through any completed TX chain page entries. */
6916 while (sw_tx_cons != hw_tx_cons) {
6918 struct tx_bd *txbd = NULL;
6920 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
6922 DBPRINT(sc, BCE_INFO_SEND,
6923 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
6924 "sw_tx_chain_cons = 0x%04X\n",
6925 __FUNCTION__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
6927 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD_ALLOC),
6928 BCE_PRINTF("%s(%d): TX chain consumer out of range! "
6929 " 0x%04X > 0x%04X\n", __FILE__, __LINE__, sw_tx_chain_cons,
6930 (int) MAX_TX_BD_ALLOC);
6931 bce_breakpoint(sc));
6933 DBRUN(txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
6934 [TX_IDX(sw_tx_chain_cons)]);
6936 DBRUNIF((txbd == NULL),
6937 BCE_PRINTF("%s(%d): Unexpected NULL tx_bd[0x%04X]!\n",
6938 __FILE__, __LINE__, sw_tx_chain_cons);
6939 bce_breakpoint(sc));
6941 DBRUNMSG(BCE_INFO_SEND, BCE_PRINTF("%s(): ", __FUNCTION__);
6942 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
6945 * Free the associated mbuf. Remember
6946 * that only the last tx_bd of a packet
6947 * has an mbuf pointer and DMA map.
6949 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
6951 /* Validate that this is the last tx_bd. */
6952 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
6953 BCE_PRINTF("%s(%d): tx_bd END flag not set but "
6954 "txmbuf == NULL!\n", __FILE__, __LINE__);
6955 bce_breakpoint(sc));
6957 DBRUNMSG(BCE_INFO_SEND,
6958 BCE_PRINTF("%s(): Unloading map/freeing mbuf "
6959 "from tx_bd[0x%04X]\n", __FUNCTION__,
6962 /* Unmap the mbuf. */
6963 bus_dmamap_unload(sc->tx_mbuf_tag,
6964 sc->tx_mbuf_map[sw_tx_chain_cons]);
6966 /* Free the mbuf. */
6967 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
6968 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
6969 DBRUN(sc->debug_tx_mbuf_alloc--);
6975 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
6977 /* Refresh hw_cons to see if there's new work. */
6978 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
6980 /* Prevent speculative reads of the status block. */
6981 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
6982 BUS_SPACE_BARRIER_READ);
6985 /* Clear the TX timeout timer. */
6986 sc->watchdog_timer = 0;
6988 /* Clear the tx hardware queue full flag. */
6989 if (sc->used_tx_bd < sc->max_tx_bd) {
6990 DBRUNIF((ifp->if_drv_flags & IFF_DRV_OACTIVE),
6991 DBPRINT(sc, BCE_INFO_SEND,
6992 "%s(): Open TX chain! %d/%d (used/total)\n",
6993 __FUNCTION__, sc->used_tx_bd, sc->max_tx_bd));
6994 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
6997 sc->tx_cons = sw_tx_cons;
6999 DBPRINT(sc, BCE_EXTREME_SEND, "%s(exit): tx_prod = 0x%04X, "
7000 "tx_cons = 0x%04X, tx_prod_bseq = 0x%08X\n",
7001 __FUNCTION__, sc->tx_prod, sc->tx_cons, sc->tx_prod_bseq);
7002 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_INTR);
7006 /****************************************************************************/
7007 /* Disables interrupt generation. */
7011 /****************************************************************************/
7013 bce_disable_intr(struct bce_softc *sc)
7015 DBENTER(BCE_VERBOSE_INTR);
7017 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
7018 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
7020 DBEXIT(BCE_VERBOSE_INTR);
7024 /****************************************************************************/
7025 /* Enables interrupt generation. */
7029 /****************************************************************************/
7031 bce_enable_intr(struct bce_softc *sc, int coal_now)
7033 DBENTER(BCE_VERBOSE_INTR);
7035 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
7036 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
7037 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
7039 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
7040 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
7042 /* Force an immediate interrupt (whether there is new data or not). */
7044 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
7046 DBEXIT(BCE_VERBOSE_INTR);
7050 /****************************************************************************/
7051 /* Handles controller initialization. */
7055 /****************************************************************************/
7057 bce_init_locked(struct bce_softc *sc)
7062 DBENTER(BCE_VERBOSE_RESET);
7064 BCE_LOCK_ASSERT(sc);
7068 /* Check if the driver is still running and bail out if it is. */
7069 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
7070 goto bce_init_locked_exit;
7074 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
7075 BCE_PRINTF("%s(%d): Controller reset failed!\n",
7076 __FILE__, __LINE__);
7077 goto bce_init_locked_exit;
7080 if (bce_chipinit(sc)) {
7081 BCE_PRINTF("%s(%d): Controller initialization failed!\n",
7082 __FILE__, __LINE__);
7083 goto bce_init_locked_exit;
7086 if (bce_blockinit(sc)) {
7087 BCE_PRINTF("%s(%d): Block initialization failed!\n",
7088 __FILE__, __LINE__);
7089 goto bce_init_locked_exit;
7092 /* Load our MAC address. */
7093 bcopy(IF_LLADDR(sc->bce_ifp), sc->eaddr, ETHER_ADDR_LEN);
7094 bce_set_mac_addr(sc);
7096 if (bce_hdr_split == FALSE)
7097 bce_get_rx_buffer_sizes(sc, ifp->if_mtu);
7099 * Calculate and program the hardware Ethernet MTU
7100 * size. Be generous on the receive if we have room
7101 * and allowed by the user.
7103 if (bce_strict_rx_mtu == TRUE)
7104 ether_mtu = ifp->if_mtu;
7106 if (bce_hdr_split == TRUE) {
7107 if (ifp->if_mtu <= sc->rx_bd_mbuf_data_len + MCLBYTES)
7108 ether_mtu = sc->rx_bd_mbuf_data_len +
7111 ether_mtu = ifp->if_mtu;
7113 if (ifp->if_mtu <= sc->rx_bd_mbuf_data_len)
7114 ether_mtu = sc->rx_bd_mbuf_data_len;
7116 ether_mtu = ifp->if_mtu;
7120 ether_mtu += ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + ETHER_CRC_LEN;
7122 DBPRINT(sc, BCE_INFO_MISC, "%s(): setting h/w mtu = %d\n",
7123 __FUNCTION__, ether_mtu);
7125 /* Program the mtu, enabling jumbo frame support if necessary. */
7126 if (ether_mtu > (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN))
7127 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
7128 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
7129 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
7131 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
7133 /* Program appropriate promiscuous/multicast filtering. */
7134 bce_set_rx_mode(sc);
7136 if (bce_hdr_split == TRUE) {
7137 /* Init page buffer descriptor chain. */
7138 bce_init_pg_chain(sc);
7141 /* Init RX buffer descriptor chain. */
7142 bce_init_rx_chain(sc);
7144 /* Init TX buffer descriptor chain. */
7145 bce_init_tx_chain(sc);
7147 /* Enable host interrupts. */
7148 bce_enable_intr(sc, 1);
7150 bce_ifmedia_upd_locked(ifp);
7152 /* Let the OS know the driver is up and running. */
7153 ifp->if_drv_flags |= IFF_DRV_RUNNING;
7154 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
7156 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
7158 bce_init_locked_exit:
7159 DBEXIT(BCE_VERBOSE_RESET);
7163 /****************************************************************************/
7164 /* Initialize the controller just enough so that any management firmware */
7165 /* running on the device will continue to operate correctly. */
7169 /****************************************************************************/
7171 bce_mgmt_init_locked(struct bce_softc *sc)
7175 DBENTER(BCE_VERBOSE_RESET);
7177 BCE_LOCK_ASSERT(sc);
7179 /* Bail out if management firmware is not running. */
7180 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)) {
7181 DBPRINT(sc, BCE_VERBOSE_SPECIAL,
7182 "No management firmware running...\n");
7183 goto bce_mgmt_init_locked_exit;
7188 /* Enable all critical blocks in the MAC. */
7189 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
7190 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
7193 bce_ifmedia_upd_locked(ifp);
7195 bce_mgmt_init_locked_exit:
7196 DBEXIT(BCE_VERBOSE_RESET);
7200 /****************************************************************************/
7201 /* Handles controller initialization when called from an unlocked routine. */
7205 /****************************************************************************/
7209 struct bce_softc *sc = xsc;
7211 DBENTER(BCE_VERBOSE_RESET);
7214 bce_init_locked(sc);
7217 DBEXIT(BCE_VERBOSE_RESET);
7221 /****************************************************************************/
7222 /* Modifies an mbuf for TSO on the hardware. */
7225 /* Pointer to a modified mbuf. */
7226 /****************************************************************************/
7227 static struct mbuf *
7228 bce_tso_setup(struct bce_softc *sc, struct mbuf **m_head, u16 *flags)
7231 struct ether_header *eh;
7235 int hdr_len, ip_hlen = 0, tcp_hlen = 0, ip_len = 0;
7237 DBRUN(sc->tso_frames_requested++);
7239 /* Controller may modify mbuf chains. */
7240 if (M_WRITABLE(*m_head) == 0) {
7241 m = m_dup(*m_head, M_NOWAIT);
7244 sc->mbuf_alloc_failed_count++;
7252 * For TSO the controller needs two pieces of info,
7253 * the MSS and the IP+TCP options length.
7255 m = m_pullup(*m_head, sizeof(struct ether_header) + sizeof(struct ip));
7260 eh = mtod(m, struct ether_header *);
7261 etype = ntohs(eh->ether_type);
7263 /* Check for supported TSO Ethernet types (only IPv4 for now) */
7266 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
7267 /* TSO only supported for TCP protocol. */
7268 if (ip->ip_p != IPPROTO_TCP) {
7269 BCE_PRINTF("%s(%d): TSO enabled for non-TCP frame!.\n",
7270 __FILE__, __LINE__);
7276 /* Get IP header length in bytes (min 20) */
7277 ip_hlen = ip->ip_hl << 2;
7278 m = m_pullup(*m_head, sizeof(struct ether_header) + ip_hlen +
7279 sizeof(struct tcphdr));
7285 /* Get the TCP header length in bytes (min 20) */
7286 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
7287 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
7288 tcp_hlen = (th->th_off << 2);
7290 /* Make sure all IP/TCP options live in the same buffer. */
7291 m = m_pullup(*m_head, sizeof(struct ether_header)+ ip_hlen +
7298 /* Clear IP header length and checksum, will be calc'd by h/w. */
7299 ip = (struct ip *)(m->m_data + sizeof(struct ether_header));
7300 ip_len = ip->ip_len;
7304 case ETHERTYPE_IPV6:
7305 BCE_PRINTF("%s(%d): TSO over IPv6 not supported!.\n",
7306 __FILE__, __LINE__);
7312 BCE_PRINTF("%s(%d): TSO enabled for unsupported protocol!.\n",
7313 __FILE__, __LINE__);
7319 hdr_len = sizeof(struct ether_header) + ip_hlen + tcp_hlen;
7321 DBPRINT(sc, BCE_EXTREME_SEND, "%s(): hdr_len = %d, e_hlen = %d, "
7322 "ip_hlen = %d, tcp_hlen = %d, ip_len = %d\n",
7323 __FUNCTION__, hdr_len, (int) sizeof(struct ether_header), ip_hlen,
7326 /* Set the LSO flag in the TX BD */
7327 *flags |= TX_BD_FLAGS_SW_LSO;
7329 /* Set the length of IP + TCP options (in 32 bit words) */
7330 *flags |= (((ip_hlen + tcp_hlen - sizeof(struct ip) -
7331 sizeof(struct tcphdr)) >> 2) << 8);
7333 DBRUN(sc->tso_frames_completed++);
7338 /****************************************************************************/
7339 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
7340 /* memory visible to the controller. */
7343 /* 0 for success, positive value for failure. */
7345 /* m_head: May be set to NULL if MBUF is excessively fragmented. */
7346 /****************************************************************************/
7348 bce_tx_encap(struct bce_softc *sc, struct mbuf **m_head)
7350 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
7352 struct tx_bd *txbd = NULL;
7354 u16 prod, chain_prod, mss = 0, vlan_tag = 0, flags = 0;
7361 int i, error, nsegs, rc = 0;
7363 DBENTER(BCE_VERBOSE_SEND);
7365 /* Make sure we have room in the TX chain. */
7366 if (sc->used_tx_bd >= sc->max_tx_bd)
7367 goto bce_tx_encap_exit;
7369 /* Transfer any checksum offload flags to the bd. */
7371 if (m0->m_pkthdr.csum_flags) {
7372 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
7373 m0 = bce_tso_setup(sc, m_head, &flags);
7375 DBRUN(sc->tso_frames_failed++);
7376 goto bce_tx_encap_exit;
7378 mss = htole16(m0->m_pkthdr.tso_segsz);
7380 if (m0->m_pkthdr.csum_flags & CSUM_IP)
7381 flags |= TX_BD_FLAGS_IP_CKSUM;
7382 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
7383 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
7387 /* Transfer any VLAN tags to the bd. */
7388 if (m0->m_flags & M_VLANTAG) {
7389 flags |= TX_BD_FLAGS_VLAN_TAG;
7390 vlan_tag = m0->m_pkthdr.ether_vtag;
7393 /* Map the mbuf into DMAable memory. */
7395 chain_prod = TX_CHAIN_IDX(prod);
7396 map = sc->tx_mbuf_map[chain_prod];
7398 /* Map the mbuf into our DMA address space. */
7399 error = bus_dmamap_load_mbuf_sg(sc->tx_mbuf_tag, map, m0,
7400 segs, &nsegs, BUS_DMA_NOWAIT);
7402 /* Check if the DMA mapping was successful */
7403 if (error == EFBIG) {
7404 sc->mbuf_frag_count++;
7406 /* Try to defrag the mbuf. */
7407 m0 = m_collapse(*m_head, M_NOWAIT, BCE_MAX_SEGMENTS);
7409 /* Defrag was unsuccessful */
7412 sc->mbuf_alloc_failed_count++;
7414 goto bce_tx_encap_exit;
7417 /* Defrag was successful, try mapping again */
7419 error = bus_dmamap_load_mbuf_sg(sc->tx_mbuf_tag,
7420 map, m0, segs, &nsegs, BUS_DMA_NOWAIT);
7422 /* Still getting an error after a defrag. */
7423 if (error == ENOMEM) {
7424 /* Insufficient DMA buffers available. */
7425 sc->dma_map_addr_tx_failed_count++;
7427 goto bce_tx_encap_exit;
7428 } else if (error != 0) {
7429 /* Release it and return an error. */
7430 BCE_PRINTF("%s(%d): Unknown error mapping mbuf into "
7431 "TX chain!\n", __FILE__, __LINE__);
7434 sc->dma_map_addr_tx_failed_count++;
7436 goto bce_tx_encap_exit;
7438 } else if (error == ENOMEM) {
7439 /* Insufficient DMA buffers available. */
7440 sc->dma_map_addr_tx_failed_count++;
7442 goto bce_tx_encap_exit;
7443 } else if (error != 0) {
7446 sc->dma_map_addr_tx_failed_count++;
7448 goto bce_tx_encap_exit;
7451 /* Make sure there's room in the chain */
7452 if (nsegs > (sc->max_tx_bd - sc->used_tx_bd)) {
7453 bus_dmamap_unload(sc->tx_mbuf_tag, map);
7455 goto bce_tx_encap_exit;
7458 /* prod points to an empty tx_bd at this point. */
7459 prod_bseq = sc->tx_prod_bseq;
7462 debug_prod = chain_prod;
7465 DBPRINT(sc, BCE_INFO_SEND,
7466 "%s(start): prod = 0x%04X, chain_prod = 0x%04X, "
7467 "prod_bseq = 0x%08X\n",
7468 __FUNCTION__, prod, chain_prod, prod_bseq);
7471 * Cycle through each mbuf segment that makes up
7472 * the outgoing frame, gathering the mapping info
7473 * for that segment and creating a tx_bd for
7476 for (i = 0; i < nsegs ; i++) {
7478 chain_prod = TX_CHAIN_IDX(prod);
7479 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)]
7480 [TX_IDX(chain_prod)];
7482 txbd->tx_bd_haddr_lo =
7483 htole32(BCE_ADDR_LO(segs[i].ds_addr));
7484 txbd->tx_bd_haddr_hi =
7485 htole32(BCE_ADDR_HI(segs[i].ds_addr));
7486 txbd->tx_bd_mss_nbytes = htole32(mss << 16) |
7487 htole16(segs[i].ds_len);
7488 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
7489 txbd->tx_bd_flags = htole16(flags);
7490 prod_bseq += segs[i].ds_len;
7492 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
7493 prod = NEXT_TX_BD(prod);
7496 /* Set the END flag on the last TX buffer descriptor. */
7497 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
7499 DBRUNMSG(BCE_EXTREME_SEND,
7500 bce_dump_tx_chain(sc, debug_prod, nsegs));
7503 * Ensure that the mbuf pointer for this transmission
7504 * is placed at the array index of the last
7505 * descriptor in this chain. This is done
7506 * because a single map is used for all
7507 * segments of the mbuf and we don't want to
7508 * unload the map before all of the segments
7511 sc->tx_mbuf_ptr[chain_prod] = m0;
7512 sc->used_tx_bd += nsegs;
7514 /* Update some debug statistic counters */
7515 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
7516 sc->tx_hi_watermark = sc->used_tx_bd);
7517 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
7518 DBRUNIF(sc->debug_tx_mbuf_alloc++);
7520 DBRUNMSG(BCE_EXTREME_SEND, bce_dump_tx_mbuf_chain(sc, chain_prod, 1));
7522 /* prod points to the next free tx_bd at this point. */
7524 sc->tx_prod_bseq = prod_bseq;
7526 /* Tell the chip about the waiting TX frames. */
7527 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) +
7528 BCE_L2MQ_TX_HOST_BIDX, sc->tx_prod);
7529 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) +
7530 BCE_L2MQ_TX_HOST_BSEQ, sc->tx_prod_bseq);
7533 DBEXIT(BCE_VERBOSE_SEND);
7538 /****************************************************************************/
7539 /* Main transmit routine when called from another routine with a lock. */
7543 /****************************************************************************/
7545 bce_start_locked(struct ifnet *ifp)
7547 struct bce_softc *sc = ifp->if_softc;
7548 struct mbuf *m_head = NULL;
7550 u16 tx_prod, tx_chain_prod;
7552 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
7554 BCE_LOCK_ASSERT(sc);
7556 /* prod points to the next free tx_bd. */
7557 tx_prod = sc->tx_prod;
7558 tx_chain_prod = TX_CHAIN_IDX(tx_prod);
7560 DBPRINT(sc, BCE_INFO_SEND,
7561 "%s(enter): tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
7562 "tx_prod_bseq = 0x%08X\n",
7563 __FUNCTION__, tx_prod, tx_chain_prod, sc->tx_prod_bseq);
7565 /* If there's no link or the transmit queue is empty then just exit. */
7566 if (sc->bce_link_up == FALSE) {
7567 DBPRINT(sc, BCE_INFO_SEND, "%s(): No link.\n",
7569 goto bce_start_locked_exit;
7572 if (IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
7573 DBPRINT(sc, BCE_INFO_SEND, "%s(): Transmit queue empty.\n",
7575 goto bce_start_locked_exit;
7579 * Keep adding entries while there is space in the ring.
7581 while (sc->used_tx_bd < sc->max_tx_bd) {
7583 /* Check for any frames to send. */
7584 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
7586 /* Stop when the transmit queue is empty. */
7591 * Pack the data into the transmit ring. If we
7592 * don't have room, place the mbuf back at the
7593 * head of the queue and set the OACTIVE flag
7594 * to wait for the NIC to drain the chain.
7596 if (bce_tx_encap(sc, &m_head)) {
7598 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
7599 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
7600 DBPRINT(sc, BCE_INFO_SEND,
7601 "TX chain is closed for business! Total "
7602 "tx_bd used = %d\n", sc->used_tx_bd);
7608 /* Send a copy of the frame to any BPF listeners. */
7609 ETHER_BPF_MTAP(ifp, m_head);
7612 /* Exit if no packets were dequeued. */
7614 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): No packets were "
7615 "dequeued\n", __FUNCTION__);
7616 goto bce_start_locked_exit;
7619 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): Inserted %d frames into "
7620 "send queue.\n", __FUNCTION__, count);
7622 /* Set the tx timeout. */
7623 sc->watchdog_timer = BCE_TX_TIMEOUT;
7625 DBRUNMSG(BCE_VERBOSE_SEND, bce_dump_ctx(sc, TX_CID));
7626 DBRUNMSG(BCE_VERBOSE_SEND, bce_dump_mq_regs(sc));
7628 bce_start_locked_exit:
7629 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_CTX);
7633 /****************************************************************************/
7634 /* Main transmit routine when called from another routine without a lock. */
7638 /****************************************************************************/
7640 bce_start(struct ifnet *ifp)
7642 struct bce_softc *sc = ifp->if_softc;
7644 DBENTER(BCE_VERBOSE_SEND);
7647 bce_start_locked(ifp);
7650 DBEXIT(BCE_VERBOSE_SEND);
7654 /****************************************************************************/
7655 /* Handles any IOCTL calls from the operating system. */
7658 /* 0 for success, positive value for failure. */
7659 /****************************************************************************/
7661 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
7663 struct bce_softc *sc = ifp->if_softc;
7664 struct ifreq *ifr = (struct ifreq *) data;
7665 struct mii_data *mii;
7666 int mask, error = 0;
7668 DBENTER(BCE_VERBOSE_MISC);
7672 /* Set the interface MTU. */
7674 /* Check that the MTU setting is supported. */
7675 if ((ifr->ifr_mtu < BCE_MIN_MTU) ||
7676 (ifr->ifr_mtu > BCE_MAX_JUMBO_MTU)) {
7681 DBPRINT(sc, BCE_INFO_MISC,
7682 "SIOCSIFMTU: Changing MTU from %d to %d\n",
7683 (int) ifp->if_mtu, (int) ifr->ifr_mtu);
7686 ifp->if_mtu = ifr->ifr_mtu;
7687 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7688 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
7689 bce_init_locked(sc);
7694 /* Set interface flags. */
7696 DBPRINT(sc, BCE_VERBOSE_SPECIAL, "Received SIOCSIFFLAGS\n");
7700 /* Check if the interface is up. */
7701 if (ifp->if_flags & IFF_UP) {
7702 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7703 /* Change promiscuous/multicast flags as necessary. */
7704 bce_set_rx_mode(sc);
7707 bce_init_locked(sc);
7710 /* The interface is down, check if driver is running. */
7711 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
7714 /* If MFW is running, restart the controller a bit. */
7715 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
7716 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
7718 bce_mgmt_init_locked(sc);
7726 /* Add/Delete multicast address */
7729 DBPRINT(sc, BCE_VERBOSE_MISC,
7730 "Received SIOCADDMULTI/SIOCDELMULTI\n");
7733 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
7734 bce_set_rx_mode(sc);
7739 /* Set/Get Interface media */
7742 DBPRINT(sc, BCE_VERBOSE_MISC,
7743 "Received SIOCSIFMEDIA/SIOCGIFMEDIA\n");
7744 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0)
7745 error = ifmedia_ioctl(ifp, ifr, &sc->bce_ifmedia,
7748 mii = device_get_softc(sc->bce_miibus);
7749 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media,
7754 /* Set interface capability */
7756 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
7757 DBPRINT(sc, BCE_INFO_MISC,
7758 "Received SIOCSIFCAP = 0x%08X\n", (u32) mask);
7760 /* Toggle the TX checksum capabilities enable flag. */
7761 if (mask & IFCAP_TXCSUM &&
7762 ifp->if_capabilities & IFCAP_TXCSUM) {
7763 ifp->if_capenable ^= IFCAP_TXCSUM;
7764 if (IFCAP_TXCSUM & ifp->if_capenable)
7765 ifp->if_hwassist |= BCE_IF_HWASSIST;
7767 ifp->if_hwassist &= ~BCE_IF_HWASSIST;
7770 /* Toggle the RX checksum capabilities enable flag. */
7771 if (mask & IFCAP_RXCSUM &&
7772 ifp->if_capabilities & IFCAP_RXCSUM)
7773 ifp->if_capenable ^= IFCAP_RXCSUM;
7775 /* Toggle the TSO capabilities enable flag. */
7776 if (bce_tso_enable && (mask & IFCAP_TSO4) &&
7777 ifp->if_capabilities & IFCAP_TSO4) {
7778 ifp->if_capenable ^= IFCAP_TSO4;
7779 if (IFCAP_TSO4 & ifp->if_capenable)
7780 ifp->if_hwassist |= CSUM_TSO;
7782 ifp->if_hwassist &= ~CSUM_TSO;
7785 if (mask & IFCAP_VLAN_HWCSUM &&
7786 ifp->if_capabilities & IFCAP_VLAN_HWCSUM)
7787 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
7789 if ((mask & IFCAP_VLAN_HWTSO) != 0 &&
7790 (ifp->if_capabilities & IFCAP_VLAN_HWTSO) != 0)
7791 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
7793 * Don't actually disable VLAN tag stripping as
7794 * management firmware (ASF/IPMI/UMP) requires the
7795 * feature. If VLAN tag stripping is disabled driver
7796 * will manually reconstruct the VLAN frame by
7797 * appending stripped VLAN tag.
7799 if ((mask & IFCAP_VLAN_HWTAGGING) != 0 &&
7800 (ifp->if_capabilities & IFCAP_VLAN_HWTAGGING)) {
7801 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
7802 if ((ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
7804 ifp->if_capenable &= ~IFCAP_VLAN_HWTSO;
7806 VLAN_CAPABILITIES(ifp);
7809 /* We don't know how to handle the IOCTL, pass it on. */
7810 error = ether_ioctl(ifp, command, data);
7814 DBEXIT(BCE_VERBOSE_MISC);
7819 /****************************************************************************/
7820 /* Transmit timeout handler. */
7824 /****************************************************************************/
7826 bce_watchdog(struct bce_softc *sc)
7828 DBENTER(BCE_EXTREME_SEND);
7830 BCE_LOCK_ASSERT(sc);
7832 /* If the watchdog timer hasn't expired then just exit. */
7833 if (sc->watchdog_timer == 0 || --sc->watchdog_timer)
7834 goto bce_watchdog_exit;
7836 /* If pause frames are active then don't reset the hardware. */
7837 /* ToDo: Should we reset the timer here? */
7838 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
7839 goto bce_watchdog_exit;
7841 BCE_PRINTF("%s(%d): Watchdog timeout occurred, resetting!\n",
7842 __FILE__, __LINE__);
7845 bce_dump_driver_state(sc);
7846 bce_dump_status_block(sc);
7847 bce_dump_stats_block(sc);
7849 bce_dump_txp_state(sc, 0);
7850 bce_dump_rxp_state(sc, 0);
7851 bce_dump_tpat_state(sc, 0);
7852 bce_dump_cp_state(sc, 0);
7853 bce_dump_com_state(sc, 0));
7855 DBRUN(bce_breakpoint(sc));
7857 sc->bce_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
7859 bce_init_locked(sc);
7860 sc->bce_ifp->if_oerrors++;
7863 DBEXIT(BCE_EXTREME_SEND);
7868 * Interrupt handler.
7870 /****************************************************************************/
7871 /* Main interrupt entry point. Verifies that the controller generated the */
7872 /* interrupt and then calls a separate routine for handle the various */
7873 /* interrupt causes (PHY, TX, RX). */
7877 /****************************************************************************/
7881 struct bce_softc *sc;
7883 u32 status_attn_bits;
7884 u16 hw_rx_cons, hw_tx_cons;
7889 DBENTER(BCE_VERBOSE_SEND | BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
7890 DBRUNMSG(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
7891 DBRUNMSG(BCE_VERBOSE_INTR, bce_dump_stats_block(sc));
7895 DBRUN(sc->interrupts_generated++);
7897 /* Synchnorize before we read from interface's status block */
7898 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
7901 * If the hardware status block index matches the last value read
7902 * by the driver and we haven't asserted our interrupt then there's
7903 * nothing to do. This may only happen in case of INTx due to the
7904 * interrupt arriving at the CPU before the status block is updated.
7906 if ((sc->bce_flags & (BCE_USING_MSI_FLAG | BCE_USING_MSIX_FLAG)) == 0 &&
7907 sc->status_block->status_idx == sc->last_status_idx &&
7908 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
7909 BCE_PCICFG_MISC_STATUS_INTA_VALUE)) {
7910 DBPRINT(sc, BCE_VERBOSE_INTR, "%s(): Spurious interrupt.\n",
7915 /* Ack the interrupt and stop others from occuring. */
7916 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
7917 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
7918 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
7920 /* Check if the hardware has finished any work. */
7921 hw_rx_cons = bce_get_hw_rx_cons(sc);
7922 hw_tx_cons = bce_get_hw_tx_cons(sc);
7924 /* Keep processing data as long as there is work to do. */
7927 status_attn_bits = sc->status_block->status_attn_bits;
7929 DBRUNIF(DB_RANDOMTRUE(unexpected_attention_sim_control),
7930 BCE_PRINTF("Simulating unexpected status attention "
7932 sc->unexpected_attention_sim_count++;
7933 status_attn_bits = status_attn_bits |
7934 STATUS_ATTN_BITS_PARITY_ERROR);
7936 /* Was it a link change interrupt? */
7937 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
7938 (sc->status_block->status_attn_bits_ack &
7939 STATUS_ATTN_BITS_LINK_STATE)) {
7942 /* Clear transient updates during link state change. */
7943 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command |
7944 BCE_HC_COMMAND_COAL_NOW_WO_INT);
7945 REG_RD(sc, BCE_HC_COMMAND);
7948 /* If any other attention is asserted, the chip is toast. */
7949 if (((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
7950 (sc->status_block->status_attn_bits_ack &
7951 ~STATUS_ATTN_BITS_LINK_STATE))) {
7953 sc->unexpected_attention_count++;
7955 BCE_PRINTF("%s(%d): Fatal attention detected: "
7956 "0x%08X\n", __FILE__, __LINE__,
7957 sc->status_block->status_attn_bits);
7960 if (unexpected_attention_sim_control == 0)
7961 bce_breakpoint(sc));
7963 bce_init_locked(sc);
7967 /* Check for any completed RX frames. */
7968 if (hw_rx_cons != sc->hw_rx_cons)
7971 /* Check for any completed TX frames. */
7972 if (hw_tx_cons != sc->hw_tx_cons)
7975 /* Save status block index value for the next interrupt. */
7976 sc->last_status_idx = sc->status_block->status_idx;
7979 * Prevent speculative reads from getting
7980 * ahead of the status block.
7982 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
7983 BUS_SPACE_BARRIER_READ);
7986 * If there's no work left then exit the
7987 * interrupt service routine.
7989 hw_rx_cons = bce_get_hw_rx_cons(sc);
7990 hw_tx_cons = bce_get_hw_tx_cons(sc);
7992 if ((hw_rx_cons == sc->hw_rx_cons) &&
7993 (hw_tx_cons == sc->hw_tx_cons))
7997 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREREAD);
7999 /* Re-enable interrupts. */
8000 bce_enable_intr(sc, 0);
8002 /* Handle any frames that arrived while handling the interrupt. */
8003 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
8004 !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
8005 bce_start_locked(ifp);
8010 DBEXIT(BCE_VERBOSE_SEND | BCE_VERBOSE_RECV | BCE_VERBOSE_INTR);
8014 /****************************************************************************/
8015 /* Programs the various packet receive modes (broadcast and multicast). */
8019 /****************************************************************************/
8021 bce_set_rx_mode(struct bce_softc *sc)
8024 struct ifmultiaddr *ifma;
8025 u32 hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
8026 u32 rx_mode, sort_mode;
8029 DBENTER(BCE_VERBOSE_MISC);
8031 BCE_LOCK_ASSERT(sc);
8035 /* Initialize receive mode default settings. */
8036 rx_mode = sc->rx_mode & ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
8037 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
8038 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
8041 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
8044 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
8045 (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)))
8046 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
8049 * Check for promiscuous, all multicast, or selected
8050 * multicast address filtering.
8052 if (ifp->if_flags & IFF_PROMISC) {
8053 DBPRINT(sc, BCE_INFO_MISC, "Enabling promiscuous mode.\n");
8055 /* Enable promiscuous mode. */
8056 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
8057 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
8058 } else if (ifp->if_flags & IFF_ALLMULTI) {
8059 DBPRINT(sc, BCE_INFO_MISC, "Enabling all multicast mode.\n");
8061 /* Enable all multicast addresses. */
8062 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
8063 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
8066 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
8068 /* Accept one or more multicast(s). */
8069 DBPRINT(sc, BCE_INFO_MISC, "Enabling selective multicast mode.\n");
8071 if_maddr_rlock(ifp);
8072 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
8073 if (ifma->ifma_addr->sa_family != AF_LINK)
8075 h = ether_crc32_le(LLADDR((struct sockaddr_dl *)
8076 ifma->ifma_addr), ETHER_ADDR_LEN) & 0xFF;
8077 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
8079 if_maddr_runlock(ifp);
8081 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++)
8082 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), hashes[i]);
8084 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
8087 /* Only make changes if the recive mode has actually changed. */
8088 if (rx_mode != sc->rx_mode) {
8089 DBPRINT(sc, BCE_VERBOSE_MISC, "Enabling new receive mode: "
8090 "0x%08X\n", rx_mode);
8092 sc->rx_mode = rx_mode;
8093 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
8096 /* Disable and clear the exisitng sort before enabling a new sort. */
8097 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
8098 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
8099 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
8101 DBEXIT(BCE_VERBOSE_MISC);
8105 /****************************************************************************/
8106 /* Called periodically to updates statistics from the controllers */
8107 /* statistics block. */
8111 /****************************************************************************/
8113 bce_stats_update(struct bce_softc *sc)
8116 struct statistics_block *stats;
8118 DBENTER(BCE_EXTREME_MISC);
8122 bus_dmamap_sync(sc->stats_tag, sc->stats_map, BUS_DMASYNC_POSTREAD);
8124 stats = (struct statistics_block *) sc->stats_block;
8127 * Certain controllers don't report
8128 * carrier sense errors correctly.
8129 * See errata E11_5708CA0_1165.
8131 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
8132 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0))
8134 (u_long) stats->stat_Dot3StatsCarrierSenseErrors;
8137 * Update the sysctl statistics from the
8138 * hardware statistics.
8140 sc->stat_IfHCInOctets =
8141 ((u64) stats->stat_IfHCInOctets_hi << 32) +
8142 (u64) stats->stat_IfHCInOctets_lo;
8144 sc->stat_IfHCInBadOctets =
8145 ((u64) stats->stat_IfHCInBadOctets_hi << 32) +
8146 (u64) stats->stat_IfHCInBadOctets_lo;
8148 sc->stat_IfHCOutOctets =
8149 ((u64) stats->stat_IfHCOutOctets_hi << 32) +
8150 (u64) stats->stat_IfHCOutOctets_lo;
8152 sc->stat_IfHCOutBadOctets =
8153 ((u64) stats->stat_IfHCOutBadOctets_hi << 32) +
8154 (u64) stats->stat_IfHCOutBadOctets_lo;
8156 sc->stat_IfHCInUcastPkts =
8157 ((u64) stats->stat_IfHCInUcastPkts_hi << 32) +
8158 (u64) stats->stat_IfHCInUcastPkts_lo;
8160 sc->stat_IfHCInMulticastPkts =
8161 ((u64) stats->stat_IfHCInMulticastPkts_hi << 32) +
8162 (u64) stats->stat_IfHCInMulticastPkts_lo;
8164 sc->stat_IfHCInBroadcastPkts =
8165 ((u64) stats->stat_IfHCInBroadcastPkts_hi << 32) +
8166 (u64) stats->stat_IfHCInBroadcastPkts_lo;
8168 sc->stat_IfHCOutUcastPkts =
8169 ((u64) stats->stat_IfHCOutUcastPkts_hi << 32) +
8170 (u64) stats->stat_IfHCOutUcastPkts_lo;
8172 sc->stat_IfHCOutMulticastPkts =
8173 ((u64) stats->stat_IfHCOutMulticastPkts_hi << 32) +
8174 (u64) stats->stat_IfHCOutMulticastPkts_lo;
8176 sc->stat_IfHCOutBroadcastPkts =
8177 ((u64) stats->stat_IfHCOutBroadcastPkts_hi << 32) +
8178 (u64) stats->stat_IfHCOutBroadcastPkts_lo;
8180 /* ToDo: Preserve counters beyond 32 bits? */
8181 /* ToDo: Read the statistics from auto-clear regs? */
8183 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
8184 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
8186 sc->stat_Dot3StatsCarrierSenseErrors =
8187 stats->stat_Dot3StatsCarrierSenseErrors;
8189 sc->stat_Dot3StatsFCSErrors =
8190 stats->stat_Dot3StatsFCSErrors;
8192 sc->stat_Dot3StatsAlignmentErrors =
8193 stats->stat_Dot3StatsAlignmentErrors;
8195 sc->stat_Dot3StatsSingleCollisionFrames =
8196 stats->stat_Dot3StatsSingleCollisionFrames;
8198 sc->stat_Dot3StatsMultipleCollisionFrames =
8199 stats->stat_Dot3StatsMultipleCollisionFrames;
8201 sc->stat_Dot3StatsDeferredTransmissions =
8202 stats->stat_Dot3StatsDeferredTransmissions;
8204 sc->stat_Dot3StatsExcessiveCollisions =
8205 stats->stat_Dot3StatsExcessiveCollisions;
8207 sc->stat_Dot3StatsLateCollisions =
8208 stats->stat_Dot3StatsLateCollisions;
8210 sc->stat_EtherStatsCollisions =
8211 stats->stat_EtherStatsCollisions;
8213 sc->stat_EtherStatsFragments =
8214 stats->stat_EtherStatsFragments;
8216 sc->stat_EtherStatsJabbers =
8217 stats->stat_EtherStatsJabbers;
8219 sc->stat_EtherStatsUndersizePkts =
8220 stats->stat_EtherStatsUndersizePkts;
8222 sc->stat_EtherStatsOversizePkts =
8223 stats->stat_EtherStatsOversizePkts;
8225 sc->stat_EtherStatsPktsRx64Octets =
8226 stats->stat_EtherStatsPktsRx64Octets;
8228 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
8229 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
8231 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
8232 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
8234 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
8235 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
8237 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
8238 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
8240 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
8241 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
8243 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
8244 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
8246 sc->stat_EtherStatsPktsTx64Octets =
8247 stats->stat_EtherStatsPktsTx64Octets;
8249 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
8250 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
8252 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
8253 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
8255 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
8256 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
8258 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
8259 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
8261 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
8262 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
8264 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
8265 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
8267 sc->stat_XonPauseFramesReceived =
8268 stats->stat_XonPauseFramesReceived;
8270 sc->stat_XoffPauseFramesReceived =
8271 stats->stat_XoffPauseFramesReceived;
8273 sc->stat_OutXonSent =
8274 stats->stat_OutXonSent;
8276 sc->stat_OutXoffSent =
8277 stats->stat_OutXoffSent;
8279 sc->stat_FlowControlDone =
8280 stats->stat_FlowControlDone;
8282 sc->stat_MacControlFramesReceived =
8283 stats->stat_MacControlFramesReceived;
8285 sc->stat_XoffStateEntered =
8286 stats->stat_XoffStateEntered;
8288 sc->stat_IfInFramesL2FilterDiscards =
8289 stats->stat_IfInFramesL2FilterDiscards;
8291 sc->stat_IfInRuleCheckerDiscards =
8292 stats->stat_IfInRuleCheckerDiscards;
8294 sc->stat_IfInFTQDiscards =
8295 stats->stat_IfInFTQDiscards;
8297 sc->stat_IfInMBUFDiscards =
8298 stats->stat_IfInMBUFDiscards;
8300 sc->stat_IfInRuleCheckerP4Hit =
8301 stats->stat_IfInRuleCheckerP4Hit;
8303 sc->stat_CatchupInRuleCheckerDiscards =
8304 stats->stat_CatchupInRuleCheckerDiscards;
8306 sc->stat_CatchupInFTQDiscards =
8307 stats->stat_CatchupInFTQDiscards;
8309 sc->stat_CatchupInMBUFDiscards =
8310 stats->stat_CatchupInMBUFDiscards;
8312 sc->stat_CatchupInRuleCheckerP4Hit =
8313 stats->stat_CatchupInRuleCheckerP4Hit;
8315 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
8318 * Update the interface statistics from the
8319 * hardware statistics.
8321 ifp->if_collisions =
8322 (u_long) sc->stat_EtherStatsCollisions;
8324 /* ToDo: This method loses soft errors. */
8326 (u_long) sc->stat_EtherStatsUndersizePkts +
8327 (u_long) sc->stat_EtherStatsOversizePkts +
8328 (u_long) sc->stat_IfInMBUFDiscards +
8329 (u_long) sc->stat_Dot3StatsAlignmentErrors +
8330 (u_long) sc->stat_Dot3StatsFCSErrors +
8331 (u_long) sc->stat_IfInRuleCheckerDiscards +
8332 (u_long) sc->stat_IfInFTQDiscards +
8333 (u_long) sc->com_no_buffers;
8335 /* ToDo: This method loses soft errors. */
8337 (u_long) sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
8338 (u_long) sc->stat_Dot3StatsExcessiveCollisions +
8339 (u_long) sc->stat_Dot3StatsLateCollisions;
8341 /* ToDo: Add additional statistics? */
8343 DBEXIT(BCE_EXTREME_MISC);
8347 /****************************************************************************/
8348 /* Periodic function to notify the bootcode that the driver is still */
8353 /****************************************************************************/
8355 bce_pulse(void *xsc)
8357 struct bce_softc *sc = xsc;
8360 DBENTER(BCE_EXTREME_MISC);
8362 BCE_LOCK_ASSERT(sc);
8364 /* Tell the firmware that the driver is still running. */
8365 msg = (u32) ++sc->bce_fw_drv_pulse_wr_seq;
8366 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
8368 /* Update the bootcode condition. */
8369 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
8371 /* Report whether the bootcode still knows the driver is running. */
8372 if (bce_verbose || bootverbose) {
8373 if (sc->bce_drv_cardiac_arrest == FALSE) {
8374 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
8375 sc->bce_drv_cardiac_arrest = TRUE;
8376 BCE_PRINTF("%s(): Warning: bootcode "
8377 "thinks driver is absent! "
8378 "(bc_state = 0x%08X)\n",
8379 __FUNCTION__, sc->bc_state);
8383 * Not supported by all bootcode versions.
8384 * (v5.0.11+ and v5.2.1+) Older bootcode
8385 * will require the driver to reset the
8386 * controller to clear this condition.
8388 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
8389 sc->bce_drv_cardiac_arrest = FALSE;
8390 BCE_PRINTF("%s(): Bootcode found the "
8391 "driver pulse! (bc_state = 0x%08X)\n",
8392 __FUNCTION__, sc->bc_state);
8398 /* Schedule the next pulse. */
8399 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
8401 DBEXIT(BCE_EXTREME_MISC);
8405 /****************************************************************************/
8406 /* Periodic function to perform maintenance tasks. */
8410 /****************************************************************************/
8414 struct bce_softc *sc = xsc;
8415 struct mii_data *mii;
8417 struct ifmediareq ifmr;
8421 DBENTER(BCE_EXTREME_MISC);
8423 BCE_LOCK_ASSERT(sc);
8425 /* Schedule the next tick. */
8426 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
8428 /* Update the statistics from the hardware statistics block. */
8429 bce_stats_update(sc);
8431 /* Ensure page and RX chains get refilled in low-memory situations. */
8432 if (bce_hdr_split == TRUE)
8433 bce_fill_pg_chain(sc);
8434 bce_fill_rx_chain(sc);
8436 /* Check that chip hasn't hung. */
8439 /* If link is up already up then we're done. */
8440 if (sc->bce_link_up == TRUE)
8443 /* Link is down. Check what the PHY's doing. */
8444 if ((sc->bce_phy_flags & BCE_PHY_REMOTE_CAP_FLAG) != 0) {
8445 bzero(&ifmr, sizeof(ifmr));
8446 bce_ifmedia_sts_rphy(sc, &ifmr);
8447 if ((ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) ==
8448 (IFM_ACTIVE | IFM_AVALID)) {
8449 sc->bce_link_up = TRUE;
8450 bce_miibus_statchg(sc->bce_dev);
8453 mii = device_get_softc(sc->bce_miibus);
8455 /* Check if the link has come up. */
8456 if ((mii->mii_media_status & IFM_ACTIVE) &&
8457 (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)) {
8458 DBPRINT(sc, BCE_VERBOSE_MISC, "%s(): Link up!\n",
8460 sc->bce_link_up = TRUE;
8461 if ((IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
8462 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX ||
8463 IFM_SUBTYPE(mii->mii_media_active) == IFM_2500_SX) &&
8464 (bce_verbose || bootverbose))
8465 BCE_PRINTF("Gigabit link up!\n");
8469 if (sc->bce_link_up == TRUE) {
8470 /* Now that link is up, handle any outstanding TX traffic. */
8471 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
8472 DBPRINT(sc, BCE_VERBOSE_MISC, "%s(): Found "
8473 "pending TX traffic.\n", __FUNCTION__);
8474 bce_start_locked(ifp);
8479 DBEXIT(BCE_EXTREME_MISC);
8483 bce_fw_cap_init(struct bce_softc *sc)
8488 cap = bce_shmem_rd(sc, BCE_FW_CAP_MB);
8489 if ((cap & BCE_FW_CAP_SIGNATURE_MAGIC_MASK) !=
8490 BCE_FW_CAP_SIGNATURE_MAGIC)
8492 if ((cap & (BCE_FW_CAP_MFW_KEEP_VLAN | BCE_FW_CAP_BC_KEEP_VLAN)) ==
8493 (BCE_FW_CAP_MFW_KEEP_VLAN | BCE_FW_CAP_BC_KEEP_VLAN))
8494 ack |= BCE_DRV_ACK_CAP_SIGNATURE_MAGIC |
8495 BCE_FW_CAP_MFW_KEEP_VLAN | BCE_FW_CAP_BC_KEEP_VLAN;
8496 if ((sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) != 0 &&
8497 (cap & BCE_FW_CAP_REMOTE_PHY_CAP) != 0) {
8498 sc->bce_phy_flags &= ~BCE_PHY_REMOTE_PORT_FIBER_FLAG;
8499 sc->bce_phy_flags |= BCE_PHY_REMOTE_CAP_FLAG;
8500 link = bce_shmem_rd(sc, BCE_LINK_STATUS);
8501 if ((link & BCE_LINK_STATUS_SERDES_LINK) != 0)
8502 sc->bce_phy_flags |= BCE_PHY_REMOTE_PORT_FIBER_FLAG;
8503 ack |= BCE_DRV_ACK_CAP_SIGNATURE_MAGIC |
8504 BCE_FW_CAP_REMOTE_PHY_CAP;
8508 bce_shmem_wr(sc, BCE_DRV_ACK_CAP_MB, ack);
8513 /****************************************************************************/
8514 /* Allows the driver state to be dumped through the sysctl interface. */
8517 /* 0 for success, positive value for failure. */
8518 /****************************************************************************/
8520 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
8524 struct bce_softc *sc;
8527 error = sysctl_handle_int(oidp, &result, 0, req);
8529 if (error || !req->newptr)
8533 sc = (struct bce_softc *)arg1;
8534 bce_dump_driver_state(sc);
8541 /****************************************************************************/
8542 /* Allows the hardware state to be dumped through the sysctl interface. */
8545 /* 0 for success, positive value for failure. */
8546 /****************************************************************************/
8548 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
8552 struct bce_softc *sc;
8555 error = sysctl_handle_int(oidp, &result, 0, req);
8557 if (error || !req->newptr)
8561 sc = (struct bce_softc *)arg1;
8562 bce_dump_hw_state(sc);
8569 /****************************************************************************/
8570 /* Allows the status block to be dumped through the sysctl interface. */
8573 /* 0 for success, positive value for failure. */
8574 /****************************************************************************/
8576 bce_sysctl_status_block(SYSCTL_HANDLER_ARGS)
8580 struct bce_softc *sc;
8583 error = sysctl_handle_int(oidp, &result, 0, req);
8585 if (error || !req->newptr)
8589 sc = (struct bce_softc *)arg1;
8590 bce_dump_status_block(sc);
8597 /****************************************************************************/
8598 /* Allows the stats block to be dumped through the sysctl interface. */
8601 /* 0 for success, positive value for failure. */
8602 /****************************************************************************/
8604 bce_sysctl_stats_block(SYSCTL_HANDLER_ARGS)
8608 struct bce_softc *sc;
8611 error = sysctl_handle_int(oidp, &result, 0, req);
8613 if (error || !req->newptr)
8617 sc = (struct bce_softc *)arg1;
8618 bce_dump_stats_block(sc);
8625 /****************************************************************************/
8626 /* Allows the stat counters to be cleared without unloading/reloading the */
8630 /* 0 for success, positive value for failure. */
8631 /****************************************************************************/
8633 bce_sysctl_stats_clear(SYSCTL_HANDLER_ARGS)
8637 struct bce_softc *sc;
8640 error = sysctl_handle_int(oidp, &result, 0, req);
8642 if (error || !req->newptr)
8646 sc = (struct bce_softc *)arg1;
8647 struct statistics_block *stats;
8649 stats = (struct statistics_block *) sc->stats_block;
8650 bzero(stats, sizeof(struct statistics_block));
8651 bus_dmamap_sync(sc->stats_tag, sc->stats_map,
8652 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
8654 /* Clear the internal H/W statistics counters. */
8655 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
8657 /* Reset the driver maintained statistics. */
8659 sc->interrupts_tx = 0;
8660 sc->tso_frames_requested =
8661 sc->tso_frames_completed =
8662 sc->tso_frames_failed = 0;
8663 sc->rx_empty_count =
8664 sc->tx_full_count = 0;
8665 sc->rx_low_watermark = USABLE_RX_BD_ALLOC;
8666 sc->tx_hi_watermark = 0;
8667 sc->l2fhdr_error_count =
8668 sc->l2fhdr_error_sim_count = 0;
8669 sc->mbuf_alloc_failed_count =
8670 sc->mbuf_alloc_failed_sim_count = 0;
8671 sc->dma_map_addr_rx_failed_count =
8672 sc->dma_map_addr_tx_failed_count = 0;
8673 sc->mbuf_frag_count = 0;
8674 sc->csum_offload_tcp_udp =
8675 sc->csum_offload_ip = 0;
8676 sc->vlan_tagged_frames_rcvd =
8677 sc->vlan_tagged_frames_stripped = 0;
8678 sc->split_header_frames_rcvd =
8679 sc->split_header_tcp_frames_rcvd = 0;
8681 /* Clear firmware maintained statistics. */
8682 REG_WR_IND(sc, 0x120084, 0);
8689 /****************************************************************************/
8690 /* Allows the shared memory contents to be dumped through the sysctl . */
8694 /* 0 for success, positive value for failure. */
8695 /****************************************************************************/
8697 bce_sysctl_shmem_state(SYSCTL_HANDLER_ARGS)
8701 struct bce_softc *sc;
8704 error = sysctl_handle_int(oidp, &result, 0, req);
8706 if (error || !req->newptr)
8710 sc = (struct bce_softc *)arg1;
8711 bce_dump_shmem_state(sc);
8718 /****************************************************************************/
8719 /* Allows the bootcode state to be dumped through the sysctl interface. */
8722 /* 0 for success, positive value for failure. */
8723 /****************************************************************************/
8725 bce_sysctl_bc_state(SYSCTL_HANDLER_ARGS)
8729 struct bce_softc *sc;
8732 error = sysctl_handle_int(oidp, &result, 0, req);
8734 if (error || !req->newptr)
8738 sc = (struct bce_softc *)arg1;
8739 bce_dump_bc_state(sc);
8746 /****************************************************************************/
8747 /* Provides a sysctl interface to allow dumping the RX BD chain. */
8750 /* 0 for success, positive value for failure. */
8751 /****************************************************************************/
8753 bce_sysctl_dump_rx_bd_chain(SYSCTL_HANDLER_ARGS)
8757 struct bce_softc *sc;
8760 error = sysctl_handle_int(oidp, &result, 0, req);
8762 if (error || !req->newptr)
8766 sc = (struct bce_softc *)arg1;
8767 bce_dump_rx_bd_chain(sc, 0, TOTAL_RX_BD_ALLOC);
8774 /****************************************************************************/
8775 /* Provides a sysctl interface to allow dumping the RX MBUF chain. */
8778 /* 0 for success, positive value for failure. */
8779 /****************************************************************************/
8781 bce_sysctl_dump_rx_mbuf_chain(SYSCTL_HANDLER_ARGS)
8785 struct bce_softc *sc;
8788 error = sysctl_handle_int(oidp, &result, 0, req);
8790 if (error || !req->newptr)
8794 sc = (struct bce_softc *)arg1;
8795 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD_ALLOC);
8802 /****************************************************************************/
8803 /* Provides a sysctl interface to allow dumping the TX chain. */
8806 /* 0 for success, positive value for failure. */
8807 /****************************************************************************/
8809 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
8813 struct bce_softc *sc;
8816 error = sysctl_handle_int(oidp, &result, 0, req);
8818 if (error || !req->newptr)
8822 sc = (struct bce_softc *)arg1;
8823 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD_ALLOC);
8830 /****************************************************************************/
8831 /* Provides a sysctl interface to allow dumping the page chain. */
8834 /* 0 for success, positive value for failure. */
8835 /****************************************************************************/
8837 bce_sysctl_dump_pg_chain(SYSCTL_HANDLER_ARGS)
8841 struct bce_softc *sc;
8844 error = sysctl_handle_int(oidp, &result, 0, req);
8846 if (error || !req->newptr)
8850 sc = (struct bce_softc *)arg1;
8851 bce_dump_pg_chain(sc, 0, TOTAL_PG_BD_ALLOC);
8857 /****************************************************************************/
8858 /* Provides a sysctl interface to allow reading arbitrary NVRAM offsets in */
8859 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8862 /* 0 for success, positive value for failure. */
8863 /****************************************************************************/
8865 bce_sysctl_nvram_read(SYSCTL_HANDLER_ARGS)
8867 struct bce_softc *sc = (struct bce_softc *)arg1;
8871 u8 *data = (u8 *) val;
8874 error = sysctl_handle_int(oidp, &result, 0, req);
8875 if (error || (req->newptr == NULL))
8878 error = bce_nvram_read(sc, result, data, 4);
8880 BCE_PRINTF("offset 0x%08X = 0x%08X\n", result, bce_be32toh(val[0]));
8886 /****************************************************************************/
8887 /* Provides a sysctl interface to allow reading arbitrary registers in the */
8888 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8891 /* 0 for success, positive value for failure. */
8892 /****************************************************************************/
8894 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
8896 struct bce_softc *sc = (struct bce_softc *)arg1;
8901 error = sysctl_handle_int(oidp, &result, 0, req);
8902 if (error || (req->newptr == NULL))
8905 /* Make sure the register is accessible. */
8906 if (result < 0x8000) {
8907 val = REG_RD(sc, result);
8908 BCE_PRINTF("reg 0x%08X = 0x%08X\n", result, val);
8909 } else if (result < 0x0280000) {
8910 val = REG_RD_IND(sc, result);
8911 BCE_PRINTF("reg 0x%08X = 0x%08X\n", result, val);
8918 /****************************************************************************/
8919 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
8920 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8923 /* 0 for success, positive value for failure. */
8924 /****************************************************************************/
8926 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
8928 struct bce_softc *sc;
8934 error = sysctl_handle_int(oidp, &result, 0, req);
8935 if (error || (req->newptr == NULL))
8938 /* Make sure the register is accessible. */
8939 if (result < 0x20) {
8940 sc = (struct bce_softc *)arg1;
8942 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
8943 BCE_PRINTF("phy 0x%02X = 0x%04X\n", result, val);
8949 /****************************************************************************/
8950 /* Provides a sysctl interface for dumping the nvram contents. */
8951 /* DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8954 /* 0 for success, positive errno for failure. */
8955 /****************************************************************************/
8957 bce_sysctl_nvram_dump(SYSCTL_HANDLER_ARGS)
8959 struct bce_softc *sc = (struct bce_softc *)arg1;
8962 if (sc->nvram_buf == NULL)
8963 sc->nvram_buf = malloc(sc->bce_flash_size,
8964 M_TEMP, M_ZERO | M_WAITOK);
8967 if (req->oldlen == sc->bce_flash_size) {
8968 for (i = 0; i < sc->bce_flash_size && error == 0; i++)
8969 error = bce_nvram_read(sc, i, &sc->nvram_buf[i], 1);
8973 error = SYSCTL_OUT(req, sc->nvram_buf, sc->bce_flash_size);
8978 #ifdef BCE_NVRAM_WRITE_SUPPORT
8979 /****************************************************************************/
8980 /* Provides a sysctl interface for writing to nvram. */
8981 /* DO NOT ENABLE ON PRODUCTION SYSTEMS! */
8984 /* 0 for success, positive errno for failure. */
8985 /****************************************************************************/
8987 bce_sysctl_nvram_write(SYSCTL_HANDLER_ARGS)
8989 struct bce_softc *sc = (struct bce_softc *)arg1;
8992 if (sc->nvram_buf == NULL)
8993 sc->nvram_buf = malloc(sc->bce_flash_size,
8994 M_TEMP, M_ZERO | M_WAITOK);
8996 bzero(sc->nvram_buf, sc->bce_flash_size);
8998 error = SYSCTL_IN(req, sc->nvram_buf, sc->bce_flash_size);
9002 if (req->newlen == sc->bce_flash_size)
9003 error = bce_nvram_write(sc, 0, sc->nvram_buf,
9004 sc->bce_flash_size);
9012 /****************************************************************************/
9013 /* Provides a sysctl interface to allow reading a CID. */
9016 /* 0 for success, positive value for failure. */
9017 /****************************************************************************/
9019 bce_sysctl_dump_ctx(SYSCTL_HANDLER_ARGS)
9021 struct bce_softc *sc;
9025 error = sysctl_handle_int(oidp, &result, 0, req);
9026 if (error || (req->newptr == NULL))
9029 /* Make sure the register is accessible. */
9030 if (result <= TX_CID) {
9031 sc = (struct bce_softc *)arg1;
9032 bce_dump_ctx(sc, result);
9039 /****************************************************************************/
9040 /* Provides a sysctl interface to forcing the driver to dump state and */
9041 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
9044 /* 0 for success, positive value for failure. */
9045 /****************************************************************************/
9047 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
9051 struct bce_softc *sc;
9054 error = sysctl_handle_int(oidp, &result, 0, req);
9056 if (error || !req->newptr)
9060 sc = (struct bce_softc *)arg1;
9068 /****************************************************************************/
9069 /* Adds any sysctl parameters for tuning or debugging purposes. */
9072 /* 0 for success, positive value for failure. */
9073 /****************************************************************************/
9075 bce_add_sysctls(struct bce_softc *sc)
9077 struct sysctl_ctx_list *ctx;
9078 struct sysctl_oid_list *children;
9080 DBENTER(BCE_VERBOSE_MISC);
9082 ctx = device_get_sysctl_ctx(sc->bce_dev);
9083 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->bce_dev));
9086 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9087 "l2fhdr_error_sim_control",
9088 CTLFLAG_RW, &l2fhdr_error_sim_control,
9089 0, "Debug control to force l2fhdr errors");
9091 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9092 "l2fhdr_error_sim_count",
9093 CTLFLAG_RD, &sc->l2fhdr_error_sim_count,
9094 0, "Number of simulated l2_fhdr errors");
9097 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9098 "l2fhdr_error_count",
9099 CTLFLAG_RD, &sc->l2fhdr_error_count,
9100 0, "Number of l2_fhdr errors");
9103 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9104 "mbuf_alloc_failed_sim_control",
9105 CTLFLAG_RW, &mbuf_alloc_failed_sim_control,
9106 0, "Debug control to force mbuf allocation failures");
9108 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9109 "mbuf_alloc_failed_sim_count",
9110 CTLFLAG_RD, &sc->mbuf_alloc_failed_sim_count,
9111 0, "Number of simulated mbuf cluster allocation failures");
9114 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9115 "mbuf_alloc_failed_count",
9116 CTLFLAG_RD, &sc->mbuf_alloc_failed_count,
9117 0, "Number of mbuf allocation failures");
9119 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9121 CTLFLAG_RD, &sc->mbuf_frag_count,
9122 0, "Number of fragmented mbufs");
9125 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9126 "dma_map_addr_failed_sim_control",
9127 CTLFLAG_RW, &dma_map_addr_failed_sim_control,
9128 0, "Debug control to force DMA mapping failures");
9130 /* ToDo: Figure out how to update this value in bce_dma_map_addr(). */
9131 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9132 "dma_map_addr_failed_sim_count",
9133 CTLFLAG_RD, &sc->dma_map_addr_failed_sim_count,
9134 0, "Number of simulated DMA mapping failures");
9138 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9139 "dma_map_addr_rx_failed_count",
9140 CTLFLAG_RD, &sc->dma_map_addr_rx_failed_count,
9141 0, "Number of RX DMA mapping failures");
9143 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9144 "dma_map_addr_tx_failed_count",
9145 CTLFLAG_RD, &sc->dma_map_addr_tx_failed_count,
9146 0, "Number of TX DMA mapping failures");
9149 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9150 "unexpected_attention_sim_control",
9151 CTLFLAG_RW, &unexpected_attention_sim_control,
9152 0, "Debug control to simulate unexpected attentions");
9154 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9155 "unexpected_attention_sim_count",
9156 CTLFLAG_RW, &sc->unexpected_attention_sim_count,
9157 0, "Number of simulated unexpected attentions");
9160 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9161 "unexpected_attention_count",
9162 CTLFLAG_RW, &sc->unexpected_attention_count,
9163 0, "Number of unexpected attentions");
9166 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9167 "debug_bootcode_running_failure",
9168 CTLFLAG_RW, &bootcode_running_failure_sim_control,
9169 0, "Debug control to force bootcode running failures");
9171 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9173 CTLFLAG_RD, &sc->rx_low_watermark,
9174 0, "Lowest level of free rx_bd's");
9176 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9178 CTLFLAG_RD, &sc->rx_empty_count,
9179 "Number of times the RX chain was empty");
9181 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
9183 CTLFLAG_RD, &sc->tx_hi_watermark,
9184 0, "Highest level of used tx_bd's");
9186 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9188 CTLFLAG_RD, &sc->tx_full_count,
9189 "Number of times the TX chain was full");
9191 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9192 "tso_frames_requested",
9193 CTLFLAG_RD, &sc->tso_frames_requested,
9194 "Number of TSO frames requested");
9196 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9197 "tso_frames_completed",
9198 CTLFLAG_RD, &sc->tso_frames_completed,
9199 "Number of TSO frames completed");
9201 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9202 "tso_frames_failed",
9203 CTLFLAG_RD, &sc->tso_frames_failed,
9204 "Number of TSO frames failed");
9206 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9208 CTLFLAG_RD, &sc->csum_offload_ip,
9209 "Number of IP checksum offload frames");
9211 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9212 "csum_offload_tcp_udp",
9213 CTLFLAG_RD, &sc->csum_offload_tcp_udp,
9214 "Number of TCP/UDP checksum offload frames");
9216 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9217 "vlan_tagged_frames_rcvd",
9218 CTLFLAG_RD, &sc->vlan_tagged_frames_rcvd,
9219 "Number of VLAN tagged frames received");
9221 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9222 "vlan_tagged_frames_stripped",
9223 CTLFLAG_RD, &sc->vlan_tagged_frames_stripped,
9224 "Number of VLAN tagged frames stripped");
9226 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9228 CTLFLAG_RD, &sc->interrupts_rx,
9229 "Number of RX interrupts");
9231 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9233 CTLFLAG_RD, &sc->interrupts_tx,
9234 "Number of TX interrupts");
9236 if (bce_hdr_split == TRUE) {
9237 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9238 "split_header_frames_rcvd",
9239 CTLFLAG_RD, &sc->split_header_frames_rcvd,
9240 "Number of split header frames received");
9242 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9243 "split_header_tcp_frames_rcvd",
9244 CTLFLAG_RD, &sc->split_header_tcp_frames_rcvd,
9245 "Number of split header TCP frames received");
9248 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9249 "nvram_dump", CTLTYPE_OPAQUE | CTLFLAG_RD,
9251 bce_sysctl_nvram_dump, "S", "");
9253 #ifdef BCE_NVRAM_WRITE_SUPPORT
9254 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9255 "nvram_write", CTLTYPE_OPAQUE | CTLFLAG_WR,
9257 bce_sysctl_nvram_write, "S", "");
9259 #endif /* BCE_DEBUG */
9261 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9262 "stat_IfHcInOctets",
9263 CTLFLAG_RD, &sc->stat_IfHCInOctets,
9266 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9267 "stat_IfHCInBadOctets",
9268 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
9269 "Bad bytes received");
9271 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9272 "stat_IfHCOutOctets",
9273 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
9276 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9277 "stat_IfHCOutBadOctets",
9278 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
9281 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9282 "stat_IfHCInUcastPkts",
9283 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
9284 "Unicast packets received");
9286 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9287 "stat_IfHCInMulticastPkts",
9288 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
9289 "Multicast packets received");
9291 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9292 "stat_IfHCInBroadcastPkts",
9293 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
9294 "Broadcast packets received");
9296 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9297 "stat_IfHCOutUcastPkts",
9298 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
9299 "Unicast packets sent");
9301 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9302 "stat_IfHCOutMulticastPkts",
9303 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
9304 "Multicast packets sent");
9306 SYSCTL_ADD_QUAD(ctx, children, OID_AUTO,
9307 "stat_IfHCOutBroadcastPkts",
9308 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
9309 "Broadcast packets sent");
9311 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9312 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
9313 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
9314 0, "Internal MAC transmit errors");
9316 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9317 "stat_Dot3StatsCarrierSenseErrors",
9318 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
9319 0, "Carrier sense errors");
9321 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9322 "stat_Dot3StatsFCSErrors",
9323 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
9324 0, "Frame check sequence errors");
9326 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9327 "stat_Dot3StatsAlignmentErrors",
9328 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
9329 0, "Alignment errors");
9331 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9332 "stat_Dot3StatsSingleCollisionFrames",
9333 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
9334 0, "Single Collision Frames");
9336 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9337 "stat_Dot3StatsMultipleCollisionFrames",
9338 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
9339 0, "Multiple Collision Frames");
9341 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9342 "stat_Dot3StatsDeferredTransmissions",
9343 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
9344 0, "Deferred Transmissions");
9346 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9347 "stat_Dot3StatsExcessiveCollisions",
9348 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
9349 0, "Excessive Collisions");
9351 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9352 "stat_Dot3StatsLateCollisions",
9353 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
9354 0, "Late Collisions");
9356 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9357 "stat_EtherStatsCollisions",
9358 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
9361 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9362 "stat_EtherStatsFragments",
9363 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
9366 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9367 "stat_EtherStatsJabbers",
9368 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
9371 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9372 "stat_EtherStatsUndersizePkts",
9373 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
9374 0, "Undersize packets");
9376 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9377 "stat_EtherStatsOversizePkts",
9378 CTLFLAG_RD, &sc->stat_EtherStatsOversizePkts,
9379 0, "stat_EtherStatsOversizePkts");
9381 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9382 "stat_EtherStatsPktsRx64Octets",
9383 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
9384 0, "Bytes received in 64 byte packets");
9386 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9387 "stat_EtherStatsPktsRx65Octetsto127Octets",
9388 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
9389 0, "Bytes received in 65 to 127 byte packets");
9391 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9392 "stat_EtherStatsPktsRx128Octetsto255Octets",
9393 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
9394 0, "Bytes received in 128 to 255 byte packets");
9396 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9397 "stat_EtherStatsPktsRx256Octetsto511Octets",
9398 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
9399 0, "Bytes received in 256 to 511 byte packets");
9401 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9402 "stat_EtherStatsPktsRx512Octetsto1023Octets",
9403 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
9404 0, "Bytes received in 512 to 1023 byte packets");
9406 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9407 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
9408 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
9409 0, "Bytes received in 1024 t0 1522 byte packets");
9411 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9412 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
9413 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
9414 0, "Bytes received in 1523 to 9022 byte packets");
9416 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9417 "stat_EtherStatsPktsTx64Octets",
9418 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
9419 0, "Bytes sent in 64 byte packets");
9421 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9422 "stat_EtherStatsPktsTx65Octetsto127Octets",
9423 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
9424 0, "Bytes sent in 65 to 127 byte packets");
9426 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9427 "stat_EtherStatsPktsTx128Octetsto255Octets",
9428 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
9429 0, "Bytes sent in 128 to 255 byte packets");
9431 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9432 "stat_EtherStatsPktsTx256Octetsto511Octets",
9433 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
9434 0, "Bytes sent in 256 to 511 byte packets");
9436 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9437 "stat_EtherStatsPktsTx512Octetsto1023Octets",
9438 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
9439 0, "Bytes sent in 512 to 1023 byte packets");
9441 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9442 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
9443 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
9444 0, "Bytes sent in 1024 to 1522 byte packets");
9446 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9447 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
9448 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
9449 0, "Bytes sent in 1523 to 9022 byte packets");
9451 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9452 "stat_XonPauseFramesReceived",
9453 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
9454 0, "XON pause frames receved");
9456 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9457 "stat_XoffPauseFramesReceived",
9458 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
9459 0, "XOFF pause frames received");
9461 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9463 CTLFLAG_RD, &sc->stat_OutXonSent,
9464 0, "XON pause frames sent");
9466 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9468 CTLFLAG_RD, &sc->stat_OutXoffSent,
9469 0, "XOFF pause frames sent");
9471 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9472 "stat_FlowControlDone",
9473 CTLFLAG_RD, &sc->stat_FlowControlDone,
9474 0, "Flow control done");
9476 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9477 "stat_MacControlFramesReceived",
9478 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
9479 0, "MAC control frames received");
9481 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9482 "stat_XoffStateEntered",
9483 CTLFLAG_RD, &sc->stat_XoffStateEntered,
9484 0, "XOFF state entered");
9486 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9487 "stat_IfInFramesL2FilterDiscards",
9488 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
9489 0, "Received L2 packets discarded");
9491 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9492 "stat_IfInRuleCheckerDiscards",
9493 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
9494 0, "Received packets discarded by rule");
9496 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9497 "stat_IfInFTQDiscards",
9498 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
9499 0, "Received packet FTQ discards");
9501 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9502 "stat_IfInMBUFDiscards",
9503 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
9504 0, "Received packets discarded due to lack "
9505 "of controller buffer memory");
9507 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9508 "stat_IfInRuleCheckerP4Hit",
9509 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
9510 0, "Received packets rule checker hits");
9512 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9513 "stat_CatchupInRuleCheckerDiscards",
9514 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
9515 0, "Received packets discarded in Catchup path");
9517 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9518 "stat_CatchupInFTQDiscards",
9519 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
9520 0, "Received packets discarded in FTQ in Catchup path");
9522 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9523 "stat_CatchupInMBUFDiscards",
9524 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
9525 0, "Received packets discarded in controller "
9526 "buffer memory in Catchup path");
9528 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9529 "stat_CatchupInRuleCheckerP4Hit",
9530 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
9531 0, "Received packets rule checker hits in Catchup path");
9533 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
9535 CTLFLAG_RD, &sc->com_no_buffers,
9536 0, "Valid packets received but no RX buffers available");
9539 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9540 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
9542 bce_sysctl_driver_state, "I", "Drive state information");
9544 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9545 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
9547 bce_sysctl_hw_state, "I", "Hardware state information");
9549 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9550 "status_block", CTLTYPE_INT | CTLFLAG_RW,
9552 bce_sysctl_status_block, "I", "Dump status block");
9554 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9555 "stats_block", CTLTYPE_INT | CTLFLAG_RW,
9557 bce_sysctl_stats_block, "I", "Dump statistics block");
9559 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9560 "stats_clear", CTLTYPE_INT | CTLFLAG_RW,
9562 bce_sysctl_stats_clear, "I", "Clear statistics block");
9564 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9565 "shmem_state", CTLTYPE_INT | CTLFLAG_RW,
9567 bce_sysctl_shmem_state, "I", "Shared memory state information");
9569 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9570 "bc_state", CTLTYPE_INT | CTLFLAG_RW,
9572 bce_sysctl_bc_state, "I", "Bootcode state information");
9574 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9575 "dump_rx_bd_chain", CTLTYPE_INT | CTLFLAG_RW,
9577 bce_sysctl_dump_rx_bd_chain, "I", "Dump RX BD chain");
9579 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9580 "dump_rx_mbuf_chain", CTLTYPE_INT | CTLFLAG_RW,
9582 bce_sysctl_dump_rx_mbuf_chain, "I", "Dump RX MBUF chain");
9584 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9585 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
9587 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
9589 if (bce_hdr_split == TRUE) {
9590 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9591 "dump_pg_chain", CTLTYPE_INT | CTLFLAG_RW,
9593 bce_sysctl_dump_pg_chain, "I", "Dump page chain");
9596 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9597 "dump_ctx", CTLTYPE_INT | CTLFLAG_RW,
9599 bce_sysctl_dump_ctx, "I", "Dump context memory");
9601 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9602 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
9604 bce_sysctl_breakpoint, "I", "Driver breakpoint");
9606 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9607 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
9609 bce_sysctl_reg_read, "I", "Register read");
9611 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9612 "nvram_read", CTLTYPE_INT | CTLFLAG_RW,
9614 bce_sysctl_nvram_read, "I", "NVRAM read");
9616 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
9617 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
9619 bce_sysctl_phy_read, "I", "PHY register read");
9623 DBEXIT(BCE_VERBOSE_MISC);
9627 /****************************************************************************/
9628 /* BCE Debug Routines */
9629 /****************************************************************************/
9632 /****************************************************************************/
9633 /* Freezes the controller to allow for a cohesive state dump. */
9637 /****************************************************************************/
9638 static __attribute__ ((noinline)) void
9639 bce_freeze_controller(struct bce_softc *sc)
9642 val = REG_RD(sc, BCE_MISC_COMMAND);
9643 val |= BCE_MISC_COMMAND_DISABLE_ALL;
9644 REG_WR(sc, BCE_MISC_COMMAND, val);
9648 /****************************************************************************/
9649 /* Unfreezes the controller after a freeze operation. This may not always */
9650 /* work and the controller will require a reset! */
9654 /****************************************************************************/
9655 static __attribute__ ((noinline)) void
9656 bce_unfreeze_controller(struct bce_softc *sc)
9659 val = REG_RD(sc, BCE_MISC_COMMAND);
9660 val |= BCE_MISC_COMMAND_ENABLE_ALL;
9661 REG_WR(sc, BCE_MISC_COMMAND, val);
9665 /****************************************************************************/
9666 /* Prints out Ethernet frame information from an mbuf. */
9668 /* Partially decode an Ethernet frame to look at some important headers. */
9672 /****************************************************************************/
9673 static __attribute__ ((noinline)) void
9674 bce_dump_enet(struct bce_softc *sc, struct mbuf *m)
9676 struct ether_vlan_header *eh;
9685 "-----------------------------"
9687 "-----------------------------\n");
9689 eh = mtod(m, struct ether_vlan_header *);
9691 /* Handle VLAN encapsulation if present. */
9692 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
9693 etype = ntohs(eh->evl_proto);
9694 ehlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
9696 etype = ntohs(eh->evl_encap_proto);
9697 ehlen = ETHER_HDR_LEN;
9700 /* ToDo: Add VLAN output. */
9701 BCE_PRINTF("enet: dest = %6D, src = %6D, type = 0x%04X, hlen = %d\n",
9702 eh->evl_dhost, ":", eh->evl_shost, ":", etype, ehlen);
9706 ip = (struct ip *)(m->m_data + ehlen);
9707 BCE_PRINTF("--ip: dest = 0x%08X , src = 0x%08X, "
9708 "len = %d bytes, protocol = 0x%02X, xsum = 0x%04X\n",
9709 ntohl(ip->ip_dst.s_addr), ntohl(ip->ip_src.s_addr),
9710 ntohs(ip->ip_len), ip->ip_p, ntohs(ip->ip_sum));
9714 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
9715 BCE_PRINTF("-tcp: dest = %d, src = %d, hlen = "
9716 "%d bytes, flags = 0x%b, csum = 0x%04X\n",
9717 ntohs(th->th_dport), ntohs(th->th_sport),
9718 (th->th_off << 2), th->th_flags,
9719 "\20\10CWR\07ECE\06URG\05ACK\04PSH\03RST"
9720 "\02SYN\01FIN", ntohs(th->th_sum));
9723 uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
9724 BCE_PRINTF("-udp: dest = %d, src = %d, len = %d "
9725 "bytes, csum = 0x%04X\n", ntohs(uh->uh_dport),
9726 ntohs(uh->uh_sport), ntohs(uh->uh_ulen),
9730 BCE_PRINTF("icmp:\n");
9733 BCE_PRINTF("----: Other IP protocol.\n");
9736 case ETHERTYPE_IPV6:
9737 BCE_PRINTF("ipv6: No decode supported.\n");
9740 BCE_PRINTF("-arp: ");
9741 ah = (struct arphdr *) (m->m_data + ehlen);
9742 switch (ntohs(ah->ar_op)) {
9743 case ARPOP_REVREQUEST:
9744 printf("reverse ARP request\n");
9746 case ARPOP_REVREPLY:
9747 printf("reverse ARP reply\n");
9750 printf("ARP request\n");
9753 printf("ARP reply\n");
9756 printf("other ARP operation\n");
9760 BCE_PRINTF("----: Other protocol.\n");
9764 "-----------------------------"
9766 "-----------------------------\n");
9770 /****************************************************************************/
9771 /* Prints out information about an mbuf. */
9775 /****************************************************************************/
9776 static __attribute__ ((noinline)) void
9777 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
9779 struct mbuf *mp = m;
9782 BCE_PRINTF("mbuf: null pointer\n");
9787 BCE_PRINTF("mbuf: %p, m_len = %d, m_flags = 0x%b, "
9788 "m_data = %p\n", mp, mp->m_len, mp->m_flags,
9789 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", mp->m_data);
9791 if (mp->m_flags & M_PKTHDR) {
9792 BCE_PRINTF("- m_pkthdr: len = %d, flags = 0x%b, "
9793 "csum_flags = %b\n", mp->m_pkthdr.len,
9794 mp->m_flags, "\20\12M_BCAST\13M_MCAST\14M_FRAG"
9795 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
9796 "\22M_PROMISC\23M_NOFREE",
9797 mp->m_pkthdr.csum_flags,
9798 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
9799 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
9800 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
9801 "\14CSUM_PSEUDO_HDR");
9804 if (mp->m_flags & M_EXT) {
9805 BCE_PRINTF("- m_ext: %p, ext_size = %d, type = ",
9806 mp->m_ext.ext_buf, mp->m_ext.ext_size);
9807 switch (mp->m_ext.ext_type) {
9809 printf("EXT_CLUSTER\n"); break;
9811 printf("EXT_SFBUF\n"); break;
9813 printf("EXT_JUMBO9\n"); break;
9815 printf("EXT_JUMBO16\n"); break;
9817 printf("EXT_PACKET\n"); break;
9819 printf("EXT_MBUF\n"); break;
9821 printf("EXT_NET_DRV\n"); break;
9823 printf("EXT_MDD_TYPE\n"); break;
9824 case EXT_DISPOSABLE:
9825 printf("EXT_DISPOSABLE\n"); break;
9827 printf("EXT_EXTREF\n"); break;
9829 printf("UNKNOWN\n");
9838 /****************************************************************************/
9839 /* Prints out the mbufs in the TX mbuf chain. */
9843 /****************************************************************************/
9844 static __attribute__ ((noinline)) void
9845 bce_dump_tx_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9850 "----------------------------"
9852 "----------------------------\n");
9854 for (int i = 0; i < count; i++) {
9855 m = sc->tx_mbuf_ptr[chain_prod];
9856 BCE_PRINTF("txmbuf[0x%04X]\n", chain_prod);
9857 bce_dump_mbuf(sc, m);
9858 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
9862 "----------------------------"
9864 "----------------------------\n");
9868 /****************************************************************************/
9869 /* Prints out the mbufs in the RX mbuf chain. */
9873 /****************************************************************************/
9874 static __attribute__ ((noinline)) void
9875 bce_dump_rx_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9880 "----------------------------"
9882 "----------------------------\n");
9884 for (int i = 0; i < count; i++) {
9885 m = sc->rx_mbuf_ptr[chain_prod];
9886 BCE_PRINTF("rxmbuf[0x%04X]\n", chain_prod);
9887 bce_dump_mbuf(sc, m);
9888 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
9893 "----------------------------"
9895 "----------------------------\n");
9899 /****************************************************************************/
9900 /* Prints out the mbufs in the mbuf page chain. */
9904 /****************************************************************************/
9905 static __attribute__ ((noinline)) void
9906 bce_dump_pg_mbuf_chain(struct bce_softc *sc, u16 chain_prod, int count)
9911 "----------------------------"
9913 "----------------------------\n");
9915 for (int i = 0; i < count; i++) {
9916 m = sc->pg_mbuf_ptr[chain_prod];
9917 BCE_PRINTF("pgmbuf[0x%04X]\n", chain_prod);
9918 bce_dump_mbuf(sc, m);
9919 chain_prod = PG_CHAIN_IDX(NEXT_PG_BD(chain_prod));
9924 "----------------------------"
9926 "----------------------------\n");
9930 /****************************************************************************/
9931 /* Prints out a tx_bd structure. */
9935 /****************************************************************************/
9936 static __attribute__ ((noinline)) void
9937 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
9941 if (idx > MAX_TX_BD_ALLOC)
9942 /* Index out of range. */
9943 BCE_PRINTF("tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
9944 else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
9945 /* TX Chain page pointer. */
9946 BCE_PRINTF("tx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
9947 "pointer\n", idx, txbd->tx_bd_haddr_hi,
9948 txbd->tx_bd_haddr_lo);
9950 /* Normal tx_bd entry. */
9951 BCE_PRINTF("tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
9952 "mss_nbytes = 0x%08X, vlan tag = 0x%04X, flags = "
9953 "0x%04X (", idx, txbd->tx_bd_haddr_hi,
9954 txbd->tx_bd_haddr_lo, txbd->tx_bd_mss_nbytes,
9955 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
9957 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT) {
9960 printf("CONN_FAULT");
9964 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM) {
9967 printf("TCP_UDP_CKSUM");
9971 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM) {
9978 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG) {
9985 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW) {
9992 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC) {
9995 printf("DONT_GEN_CRC");
9999 if (txbd->tx_bd_flags & TX_BD_FLAGS_START) {
10006 if (txbd->tx_bd_flags & TX_BD_FLAGS_END) {
10013 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO) {
10020 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD) {
10023 printf("SW_OPTION=%d", ((txbd->tx_bd_flags &
10024 TX_BD_FLAGS_SW_OPTION_WORD) >> 8)); i++;
10027 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS) {
10030 printf("SW_FLAGS");
10034 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP) {
10045 /****************************************************************************/
10046 /* Prints out a rx_bd structure. */
10050 /****************************************************************************/
10051 static __attribute__ ((noinline)) void
10052 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
10054 if (idx > MAX_RX_BD_ALLOC)
10055 /* Index out of range. */
10056 BCE_PRINTF("rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
10057 else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
10058 /* RX Chain page pointer. */
10059 BCE_PRINTF("rx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
10060 "pointer\n", idx, rxbd->rx_bd_haddr_hi,
10061 rxbd->rx_bd_haddr_lo);
10063 /* Normal rx_bd entry. */
10064 BCE_PRINTF("rx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = "
10065 "0x%08X, flags = 0x%08X\n", idx, rxbd->rx_bd_haddr_hi,
10066 rxbd->rx_bd_haddr_lo, rxbd->rx_bd_len,
10067 rxbd->rx_bd_flags);
10071 /****************************************************************************/
10072 /* Prints out a rx_bd structure in the page chain. */
10076 /****************************************************************************/
10077 static __attribute__ ((noinline)) void
10078 bce_dump_pgbd(struct bce_softc *sc, int idx, struct rx_bd *pgbd)
10080 if (idx > MAX_PG_BD_ALLOC)
10081 /* Index out of range. */
10082 BCE_PRINTF("pg_bd[0x%04X]: Invalid pg_bd index!\n", idx);
10083 else if ((idx & USABLE_PG_BD_PER_PAGE) == USABLE_PG_BD_PER_PAGE)
10084 /* Page Chain page pointer. */
10085 BCE_PRINTF("px_bd[0x%04X]: haddr = 0x%08X:%08X, chain page pointer\n",
10086 idx, pgbd->rx_bd_haddr_hi, pgbd->rx_bd_haddr_lo);
10088 /* Normal rx_bd entry. */
10089 BCE_PRINTF("pg_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = 0x%08X, "
10090 "flags = 0x%08X\n", idx,
10091 pgbd->rx_bd_haddr_hi, pgbd->rx_bd_haddr_lo,
10092 pgbd->rx_bd_len, pgbd->rx_bd_flags);
10096 /****************************************************************************/
10097 /* Prints out a l2_fhdr structure. */
10101 /****************************************************************************/
10102 static __attribute__ ((noinline)) void
10103 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
10105 BCE_PRINTF("l2_fhdr[0x%04X]: status = 0x%b, "
10106 "pkt_len = %d, vlan = 0x%04x, ip_xsum/hdr_len = 0x%04X, "
10107 "tcp_udp_xsum = 0x%04X\n", idx,
10108 l2fhdr->l2_fhdr_status, BCE_L2FHDR_PRINTFB,
10109 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
10110 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
10114 /****************************************************************************/
10115 /* Prints out context memory info. (Only useful for CID 0 to 16.) */
10119 /****************************************************************************/
10120 static __attribute__ ((noinline)) void
10121 bce_dump_ctx(struct bce_softc *sc, u16 cid)
10123 if (cid > TX_CID) {
10124 BCE_PRINTF(" Unknown CID\n");
10129 "----------------------------"
10131 "----------------------------\n");
10133 BCE_PRINTF(" 0x%04X - (CID) Context ID\n", cid);
10135 if (cid == RX_CID) {
10136 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_BDIDX) host rx "
10137 "producer index\n",
10138 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_HOST_BDIDX));
10139 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_BSEQ) host "
10140 "byte sequence\n", CTX_RD(sc, GET_CID_ADDR(cid),
10141 BCE_L2CTX_RX_HOST_BSEQ));
10142 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BSEQ) h/w byte sequence\n",
10143 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BSEQ));
10144 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDHADDR_HI) h/w buffer "
10145 "descriptor address\n",
10146 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BDHADDR_HI));
10147 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDHADDR_LO) h/w buffer "
10148 "descriptor address\n",
10149 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_RX_NX_BDHADDR_LO));
10150 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_BDIDX) h/w rx consumer "
10151 "index\n", CTX_RD(sc, GET_CID_ADDR(cid),
10152 BCE_L2CTX_RX_NX_BDIDX));
10153 BCE_PRINTF(" 0x%08X - (L2CTX_RX_HOST_PG_BDIDX) host page "
10154 "producer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
10155 BCE_L2CTX_RX_HOST_PG_BDIDX));
10156 BCE_PRINTF(" 0x%08X - (L2CTX_RX_PG_BUF_SIZE) host rx_bd/page "
10157 "buffer size\n", CTX_RD(sc, GET_CID_ADDR(cid),
10158 BCE_L2CTX_RX_PG_BUF_SIZE));
10159 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDHADDR_HI) h/w page "
10160 "chain address\n", CTX_RD(sc, GET_CID_ADDR(cid),
10161 BCE_L2CTX_RX_NX_PG_BDHADDR_HI));
10162 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDHADDR_LO) h/w page "
10163 "chain address\n", CTX_RD(sc, GET_CID_ADDR(cid),
10164 BCE_L2CTX_RX_NX_PG_BDHADDR_LO));
10165 BCE_PRINTF(" 0x%08X - (L2CTX_RX_NX_PG_BDIDX) h/w page "
10166 "consumer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
10167 BCE_L2CTX_RX_NX_PG_BDIDX));
10168 } else if (cid == TX_CID) {
10169 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
10170 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TYPE_XI) ctx type\n",
10171 CTX_RD(sc, GET_CID_ADDR(cid),
10172 BCE_L2CTX_TX_TYPE_XI));
10173 BCE_PRINTF(" 0x%08X - (L2CTX_CMD_TX_TYPE_XI) ctx "
10174 "cmd\n", CTX_RD(sc, GET_CID_ADDR(cid),
10175 BCE_L2CTX_TX_CMD_TYPE_XI));
10176 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BDHADDR_HI_XI) "
10177 "h/w buffer descriptor address\n",
10178 CTX_RD(sc, GET_CID_ADDR(cid),
10179 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI));
10180 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BHADDR_LO_XI) "
10181 "h/w buffer descriptor address\n",
10182 CTX_RD(sc, GET_CID_ADDR(cid),
10183 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI));
10184 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BIDX_XI) "
10185 "host producer index\n",
10186 CTX_RD(sc, GET_CID_ADDR(cid),
10187 BCE_L2CTX_TX_HOST_BIDX_XI));
10188 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BSEQ_XI) "
10189 "host byte sequence\n",
10190 CTX_RD(sc, GET_CID_ADDR(cid),
10191 BCE_L2CTX_TX_HOST_BSEQ_XI));
10193 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TYPE) ctx type\n",
10194 CTX_RD(sc, GET_CID_ADDR(cid), BCE_L2CTX_TX_TYPE));
10195 BCE_PRINTF(" 0x%08X - (L2CTX_TX_CMD_TYPE) ctx cmd\n",
10196 CTX_RD(sc, GET_CID_ADDR(cid),
10197 BCE_L2CTX_TX_CMD_TYPE));
10198 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BDHADDR_HI) "
10199 "h/w buffer descriptor address\n",
10200 CTX_RD(sc, GET_CID_ADDR(cid),
10201 BCE_L2CTX_TX_TBDR_BHADDR_HI));
10202 BCE_PRINTF(" 0x%08X - (L2CTX_TX_TBDR_BHADDR_LO) "
10203 "h/w buffer descriptor address\n",
10204 CTX_RD(sc, GET_CID_ADDR(cid),
10205 BCE_L2CTX_TX_TBDR_BHADDR_LO));
10206 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BIDX) host "
10207 "producer index\n", CTX_RD(sc, GET_CID_ADDR(cid),
10208 BCE_L2CTX_TX_HOST_BIDX));
10209 BCE_PRINTF(" 0x%08X - (L2CTX_TX_HOST_BSEQ) host byte "
10210 "sequence\n", CTX_RD(sc, GET_CID_ADDR(cid),
10211 BCE_L2CTX_TX_HOST_BSEQ));
10216 "----------------------------"
10218 "----------------------------\n");
10220 for (int i = 0x0; i < 0x300; i += 0x10) {
10221 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
10222 CTX_RD(sc, GET_CID_ADDR(cid), i),
10223 CTX_RD(sc, GET_CID_ADDR(cid), i + 0x4),
10224 CTX_RD(sc, GET_CID_ADDR(cid), i + 0x8),
10225 CTX_RD(sc, GET_CID_ADDR(cid), i + 0xc));
10230 "----------------------------"
10232 "----------------------------\n");
10236 /****************************************************************************/
10237 /* Prints out the FTQ data. */
10241 /****************************************************************************/
10242 static __attribute__ ((noinline)) void
10243 bce_dump_ftqs(struct bce_softc *sc)
10245 u32 cmd, ctl, cur_depth, max_depth, valid_cnt, val;
10248 "----------------------------"
10250 "----------------------------\n");
10252 BCE_PRINTF(" FTQ Command Control Depth_Now "
10253 "Max_Depth Valid_Cnt \n");
10254 BCE_PRINTF(" ------- ---------- ---------- ---------- "
10255 "---------- ----------\n");
10257 /* Setup the generic statistic counters for the FTQ valid count. */
10258 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PPQ_VALID_CNT << 24) |
10259 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RXPCQ_VALID_CNT << 16) |
10260 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RXPQ_VALID_CNT << 8) |
10261 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RLUPQ_VALID_CNT);
10262 REG_WR(sc, BCE_HC_STAT_GEN_SEL_0, val);
10264 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TSCHQ_VALID_CNT << 24) |
10265 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RDMAQ_VALID_CNT << 16) |
10266 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PTQ_VALID_CNT << 8) |
10267 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PMQ_VALID_CNT);
10268 REG_WR(sc, BCE_HC_STAT_GEN_SEL_1, val);
10270 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TPATQ_VALID_CNT << 24) |
10271 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TDMAQ_VALID_CNT << 16) |
10272 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TXPQ_VALID_CNT << 8) |
10273 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TBDRQ_VALID_CNT);
10274 REG_WR(sc, BCE_HC_STAT_GEN_SEL_2, val);
10276 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMQ_VALID_CNT << 24) |
10277 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMTQ_VALID_CNT << 16) |
10278 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_COMXQ_VALID_CNT << 8) |
10279 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_TASQ_VALID_CNT);
10280 REG_WR(sc, BCE_HC_STAT_GEN_SEL_3, val);
10282 /* Input queue to the Receive Lookup state machine */
10283 cmd = REG_RD(sc, BCE_RLUP_FTQ_CMD);
10284 ctl = REG_RD(sc, BCE_RLUP_FTQ_CTL);
10285 cur_depth = (ctl & BCE_RLUP_FTQ_CTL_CUR_DEPTH) >> 22;
10286 max_depth = (ctl & BCE_RLUP_FTQ_CTL_MAX_DEPTH) >> 12;
10287 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT0);
10288 BCE_PRINTF(" RLUP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10289 cmd, ctl, cur_depth, max_depth, valid_cnt);
10291 /* Input queue to the Receive Processor */
10292 cmd = REG_RD_IND(sc, BCE_RXP_FTQ_CMD);
10293 ctl = REG_RD_IND(sc, BCE_RXP_FTQ_CTL);
10294 cur_depth = (ctl & BCE_RXP_FTQ_CTL_CUR_DEPTH) >> 22;
10295 max_depth = (ctl & BCE_RXP_FTQ_CTL_MAX_DEPTH) >> 12;
10296 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT1);
10297 BCE_PRINTF(" RXP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10298 cmd, ctl, cur_depth, max_depth, valid_cnt);
10300 /* Input queue to the Recevie Processor */
10301 cmd = REG_RD_IND(sc, BCE_RXP_CFTQ_CMD);
10302 ctl = REG_RD_IND(sc, BCE_RXP_CFTQ_CTL);
10303 cur_depth = (ctl & BCE_RXP_CFTQ_CTL_CUR_DEPTH) >> 22;
10304 max_depth = (ctl & BCE_RXP_CFTQ_CTL_MAX_DEPTH) >> 12;
10305 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT2);
10306 BCE_PRINTF(" RXPC 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10307 cmd, ctl, cur_depth, max_depth, valid_cnt);
10309 /* Input queue to the Receive Virtual to Physical state machine */
10310 cmd = REG_RD(sc, BCE_RV2P_PFTQ_CMD);
10311 ctl = REG_RD(sc, BCE_RV2P_PFTQ_CTL);
10312 cur_depth = (ctl & BCE_RV2P_PFTQ_CTL_CUR_DEPTH) >> 22;
10313 max_depth = (ctl & BCE_RV2P_PFTQ_CTL_MAX_DEPTH) >> 12;
10314 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT3);
10315 BCE_PRINTF(" RV2PP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10316 cmd, ctl, cur_depth, max_depth, valid_cnt);
10318 /* Input queue to the Recevie Virtual to Physical state machine */
10319 cmd = REG_RD(sc, BCE_RV2P_MFTQ_CMD);
10320 ctl = REG_RD(sc, BCE_RV2P_MFTQ_CTL);
10321 cur_depth = (ctl & BCE_RV2P_MFTQ_CTL_CUR_DEPTH) >> 22;
10322 max_depth = (ctl & BCE_RV2P_MFTQ_CTL_MAX_DEPTH) >> 12;
10323 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT4);
10324 BCE_PRINTF(" RV2PM 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10325 cmd, ctl, cur_depth, max_depth, valid_cnt);
10327 /* Input queue to the Receive Virtual to Physical state machine */
10328 cmd = REG_RD(sc, BCE_RV2P_TFTQ_CMD);
10329 ctl = REG_RD(sc, BCE_RV2P_TFTQ_CTL);
10330 cur_depth = (ctl & BCE_RV2P_TFTQ_CTL_CUR_DEPTH) >> 22;
10331 max_depth = (ctl & BCE_RV2P_TFTQ_CTL_MAX_DEPTH) >> 12;
10332 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT5);
10333 BCE_PRINTF(" RV2PT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10334 cmd, ctl, cur_depth, max_depth, valid_cnt);
10336 /* Input queue to the Receive DMA state machine */
10337 cmd = REG_RD(sc, BCE_RDMA_FTQ_CMD);
10338 ctl = REG_RD(sc, BCE_RDMA_FTQ_CTL);
10339 cur_depth = (ctl & BCE_RDMA_FTQ_CTL_CUR_DEPTH) >> 22;
10340 max_depth = (ctl & BCE_RDMA_FTQ_CTL_MAX_DEPTH) >> 12;
10341 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT6);
10342 BCE_PRINTF(" RDMA 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10343 cmd, ctl, cur_depth, max_depth, valid_cnt);
10345 /* Input queue to the Transmit Scheduler state machine */
10346 cmd = REG_RD(sc, BCE_TSCH_FTQ_CMD);
10347 ctl = REG_RD(sc, BCE_TSCH_FTQ_CTL);
10348 cur_depth = (ctl & BCE_TSCH_FTQ_CTL_CUR_DEPTH) >> 22;
10349 max_depth = (ctl & BCE_TSCH_FTQ_CTL_MAX_DEPTH) >> 12;
10350 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT7);
10351 BCE_PRINTF(" TSCH 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10352 cmd, ctl, cur_depth, max_depth, valid_cnt);
10354 /* Input queue to the Transmit Buffer Descriptor state machine */
10355 cmd = REG_RD(sc, BCE_TBDR_FTQ_CMD);
10356 ctl = REG_RD(sc, BCE_TBDR_FTQ_CTL);
10357 cur_depth = (ctl & BCE_TBDR_FTQ_CTL_CUR_DEPTH) >> 22;
10358 max_depth = (ctl & BCE_TBDR_FTQ_CTL_MAX_DEPTH) >> 12;
10359 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT8);
10360 BCE_PRINTF(" TBDR 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10361 cmd, ctl, cur_depth, max_depth, valid_cnt);
10363 /* Input queue to the Transmit Processor */
10364 cmd = REG_RD_IND(sc, BCE_TXP_FTQ_CMD);
10365 ctl = REG_RD_IND(sc, BCE_TXP_FTQ_CTL);
10366 cur_depth = (ctl & BCE_TXP_FTQ_CTL_CUR_DEPTH) >> 22;
10367 max_depth = (ctl & BCE_TXP_FTQ_CTL_MAX_DEPTH) >> 12;
10368 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT9);
10369 BCE_PRINTF(" TXP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10370 cmd, ctl, cur_depth, max_depth, valid_cnt);
10372 /* Input queue to the Transmit DMA state machine */
10373 cmd = REG_RD(sc, BCE_TDMA_FTQ_CMD);
10374 ctl = REG_RD(sc, BCE_TDMA_FTQ_CTL);
10375 cur_depth = (ctl & BCE_TDMA_FTQ_CTL_CUR_DEPTH) >> 22;
10376 max_depth = (ctl & BCE_TDMA_FTQ_CTL_MAX_DEPTH) >> 12;
10377 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT10);
10378 BCE_PRINTF(" TDMA 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10379 cmd, ctl, cur_depth, max_depth, valid_cnt);
10381 /* Input queue to the Transmit Patch-Up Processor */
10382 cmd = REG_RD_IND(sc, BCE_TPAT_FTQ_CMD);
10383 ctl = REG_RD_IND(sc, BCE_TPAT_FTQ_CTL);
10384 cur_depth = (ctl & BCE_TPAT_FTQ_CTL_CUR_DEPTH) >> 22;
10385 max_depth = (ctl & BCE_TPAT_FTQ_CTL_MAX_DEPTH) >> 12;
10386 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT11);
10387 BCE_PRINTF(" TPAT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10388 cmd, ctl, cur_depth, max_depth, valid_cnt);
10390 /* Input queue to the Transmit Assembler state machine */
10391 cmd = REG_RD_IND(sc, BCE_TAS_FTQ_CMD);
10392 ctl = REG_RD_IND(sc, BCE_TAS_FTQ_CTL);
10393 cur_depth = (ctl & BCE_TAS_FTQ_CTL_CUR_DEPTH) >> 22;
10394 max_depth = (ctl & BCE_TAS_FTQ_CTL_MAX_DEPTH) >> 12;
10395 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT12);
10396 BCE_PRINTF(" TAS 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10397 cmd, ctl, cur_depth, max_depth, valid_cnt);
10399 /* Input queue to the Completion Processor */
10400 cmd = REG_RD_IND(sc, BCE_COM_COMXQ_FTQ_CMD);
10401 ctl = REG_RD_IND(sc, BCE_COM_COMXQ_FTQ_CTL);
10402 cur_depth = (ctl & BCE_COM_COMXQ_FTQ_CTL_CUR_DEPTH) >> 22;
10403 max_depth = (ctl & BCE_COM_COMXQ_FTQ_CTL_MAX_DEPTH) >> 12;
10404 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT13);
10405 BCE_PRINTF(" COMX 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10406 cmd, ctl, cur_depth, max_depth, valid_cnt);
10408 /* Input queue to the Completion Processor */
10409 cmd = REG_RD_IND(sc, BCE_COM_COMTQ_FTQ_CMD);
10410 ctl = REG_RD_IND(sc, BCE_COM_COMTQ_FTQ_CTL);
10411 cur_depth = (ctl & BCE_COM_COMTQ_FTQ_CTL_CUR_DEPTH) >> 22;
10412 max_depth = (ctl & BCE_COM_COMTQ_FTQ_CTL_MAX_DEPTH) >> 12;
10413 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT14);
10414 BCE_PRINTF(" COMT 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10415 cmd, ctl, cur_depth, max_depth, valid_cnt);
10417 /* Input queue to the Completion Processor */
10418 cmd = REG_RD_IND(sc, BCE_COM_COMQ_FTQ_CMD);
10419 ctl = REG_RD_IND(sc, BCE_COM_COMQ_FTQ_CTL);
10420 cur_depth = (ctl & BCE_COM_COMQ_FTQ_CTL_CUR_DEPTH) >> 22;
10421 max_depth = (ctl & BCE_COM_COMQ_FTQ_CTL_MAX_DEPTH) >> 12;
10422 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT15);
10423 BCE_PRINTF(" COMX 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10424 cmd, ctl, cur_depth, max_depth, valid_cnt);
10426 /* Setup the generic statistic counters for the FTQ valid count. */
10427 val = (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_CSQ_VALID_CNT << 16) |
10428 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_CPQ_VALID_CNT << 8) |
10429 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_MGMQ_VALID_CNT);
10431 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
10433 (BCE_HC_STAT_GEN_SEL_0_GEN_SEL_0_RV2PCSQ_VALID_CNT_XI <<
10435 REG_WR(sc, BCE_HC_STAT_GEN_SEL_0, val);
10437 /* Input queue to the Management Control Processor */
10438 cmd = REG_RD_IND(sc, BCE_MCP_MCPQ_FTQ_CMD);
10439 ctl = REG_RD_IND(sc, BCE_MCP_MCPQ_FTQ_CTL);
10440 cur_depth = (ctl & BCE_MCP_MCPQ_FTQ_CTL_CUR_DEPTH) >> 22;
10441 max_depth = (ctl & BCE_MCP_MCPQ_FTQ_CTL_MAX_DEPTH) >> 12;
10442 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT0);
10443 BCE_PRINTF(" MCP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10444 cmd, ctl, cur_depth, max_depth, valid_cnt);
10446 /* Input queue to the Command Processor */
10447 cmd = REG_RD_IND(sc, BCE_CP_CPQ_FTQ_CMD);
10448 ctl = REG_RD_IND(sc, BCE_CP_CPQ_FTQ_CTL);
10449 cur_depth = (ctl & BCE_CP_CPQ_FTQ_CTL_CUR_DEPTH) >> 22;
10450 max_depth = (ctl & BCE_CP_CPQ_FTQ_CTL_MAX_DEPTH) >> 12;
10451 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT1);
10452 BCE_PRINTF(" CP 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10453 cmd, ctl, cur_depth, max_depth, valid_cnt);
10455 /* Input queue to the Completion Scheduler state machine */
10456 cmd = REG_RD(sc, BCE_CSCH_CH_FTQ_CMD);
10457 ctl = REG_RD(sc, BCE_CSCH_CH_FTQ_CTL);
10458 cur_depth = (ctl & BCE_CSCH_CH_FTQ_CTL_CUR_DEPTH) >> 22;
10459 max_depth = (ctl & BCE_CSCH_CH_FTQ_CTL_MAX_DEPTH) >> 12;
10460 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT2);
10461 BCE_PRINTF(" CS 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10462 cmd, ctl, cur_depth, max_depth, valid_cnt);
10464 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
10465 /* Input queue to the RV2P Command Scheduler */
10466 cmd = REG_RD(sc, BCE_RV2PCSR_FTQ_CMD);
10467 ctl = REG_RD(sc, BCE_RV2PCSR_FTQ_CTL);
10468 cur_depth = (ctl & 0xFFC00000) >> 22;
10469 max_depth = (ctl & 0x003FF000) >> 12;
10470 valid_cnt = REG_RD(sc, BCE_HC_STAT_GEN_STAT3);
10471 BCE_PRINTF(" RV2PCSR 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
10472 cmd, ctl, cur_depth, max_depth, valid_cnt);
10476 "----------------------------"
10478 "----------------------------\n");
10482 /****************************************************************************/
10483 /* Prints out the TX chain. */
10487 /****************************************************************************/
10488 static __attribute__ ((noinline)) void
10489 bce_dump_tx_chain(struct bce_softc *sc, u16 tx_prod, int count)
10491 struct tx_bd *txbd;
10493 /* First some info about the tx_bd chain structure. */
10495 "----------------------------"
10497 "----------------------------\n");
10499 BCE_PRINTF("page size = 0x%08X, tx chain pages = 0x%08X\n",
10500 (u32) BCM_PAGE_SIZE, (u32) sc->tx_pages);
10501 BCE_PRINTF("tx_bd per page = 0x%08X, usable tx_bd per page = 0x%08X\n",
10502 (u32) TOTAL_TX_BD_PER_PAGE, (u32) USABLE_TX_BD_PER_PAGE);
10503 BCE_PRINTF("total tx_bd = 0x%08X\n", (u32) TOTAL_TX_BD_ALLOC);
10506 "----------------------------"
10508 "----------------------------\n");
10510 /* Now print out a decoded list of TX buffer descriptors. */
10511 for (int i = 0; i < count; i++) {
10512 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
10513 bce_dump_txbd(sc, tx_prod, txbd);
10518 "----------------------------"
10520 "----------------------------\n");
10524 /****************************************************************************/
10525 /* Prints out the RX chain. */
10529 /****************************************************************************/
10530 static __attribute__ ((noinline)) void
10531 bce_dump_rx_bd_chain(struct bce_softc *sc, u16 rx_prod, int count)
10533 struct rx_bd *rxbd;
10535 /* First some info about the rx_bd chain structure. */
10537 "----------------------------"
10539 "----------------------------\n");
10541 BCE_PRINTF("page size = 0x%08X, rx chain pages = 0x%08X\n",
10542 (u32) BCM_PAGE_SIZE, (u32) sc->rx_pages);
10544 BCE_PRINTF("rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
10545 (u32) TOTAL_RX_BD_PER_PAGE, (u32) USABLE_RX_BD_PER_PAGE);
10547 BCE_PRINTF("total rx_bd = 0x%08X\n", (u32) TOTAL_RX_BD_ALLOC);
10550 "----------------------------"
10552 "----------------------------\n");
10554 /* Now print out the rx_bd's themselves. */
10555 for (int i = 0; i < count; i++) {
10556 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
10557 bce_dump_rxbd(sc, rx_prod, rxbd);
10558 rx_prod = RX_CHAIN_IDX(rx_prod + 1);
10562 "----------------------------"
10564 "----------------------------\n");
10568 /****************************************************************************/
10569 /* Prints out the page chain. */
10573 /****************************************************************************/
10574 static __attribute__ ((noinline)) void
10575 bce_dump_pg_chain(struct bce_softc *sc, u16 pg_prod, int count)
10577 struct rx_bd *pgbd;
10579 /* First some info about the page chain structure. */
10581 "----------------------------"
10583 "----------------------------\n");
10585 BCE_PRINTF("page size = 0x%08X, pg chain pages = 0x%08X\n",
10586 (u32) BCM_PAGE_SIZE, (u32) sc->pg_pages);
10588 BCE_PRINTF("rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
10589 (u32) TOTAL_PG_BD_PER_PAGE, (u32) USABLE_PG_BD_PER_PAGE);
10591 BCE_PRINTF("total pg_bd = 0x%08X\n", (u32) TOTAL_PG_BD_ALLOC);
10594 "----------------------------"
10596 "----------------------------\n");
10598 /* Now print out the rx_bd's themselves. */
10599 for (int i = 0; i < count; i++) {
10600 pgbd = &sc->pg_bd_chain[PG_PAGE(pg_prod)][PG_IDX(pg_prod)];
10601 bce_dump_pgbd(sc, pg_prod, pgbd);
10602 pg_prod = PG_CHAIN_IDX(pg_prod + 1);
10606 "----------------------------"
10608 "----------------------------\n");
10612 #define BCE_PRINT_RX_CONS(arg) \
10613 if (sblk->status_rx_quick_consumer_index##arg) \
10614 BCE_PRINTF("0x%04X(0x%04X) - rx_quick_consumer_index%d\n", \
10615 sblk->status_rx_quick_consumer_index##arg, (u16) \
10616 RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index##arg), \
10620 #define BCE_PRINT_TX_CONS(arg) \
10621 if (sblk->status_tx_quick_consumer_index##arg) \
10622 BCE_PRINTF("0x%04X(0x%04X) - tx_quick_consumer_index%d\n", \
10623 sblk->status_tx_quick_consumer_index##arg, (u16) \
10624 TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index##arg), \
10627 /****************************************************************************/
10628 /* Prints out the status block from host memory. */
10632 /****************************************************************************/
10633 static __attribute__ ((noinline)) void
10634 bce_dump_status_block(struct bce_softc *sc)
10636 struct status_block *sblk;
10638 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
10640 sblk = sc->status_block;
10643 "----------------------------"
10645 "----------------------------\n");
10647 /* Theses indices are used for normal L2 drivers. */
10648 BCE_PRINTF(" 0x%08X - attn_bits\n",
10649 sblk->status_attn_bits);
10651 BCE_PRINTF(" 0x%08X - attn_bits_ack\n",
10652 sblk->status_attn_bits_ack);
10654 BCE_PRINT_RX_CONS(0);
10655 BCE_PRINT_TX_CONS(0)
10657 BCE_PRINTF(" 0x%04X - status_idx\n", sblk->status_idx);
10659 /* Theses indices are not used for normal L2 drivers. */
10660 BCE_PRINT_RX_CONS(1); BCE_PRINT_RX_CONS(2); BCE_PRINT_RX_CONS(3);
10661 BCE_PRINT_RX_CONS(4); BCE_PRINT_RX_CONS(5); BCE_PRINT_RX_CONS(6);
10662 BCE_PRINT_RX_CONS(7); BCE_PRINT_RX_CONS(8); BCE_PRINT_RX_CONS(9);
10663 BCE_PRINT_RX_CONS(10); BCE_PRINT_RX_CONS(11); BCE_PRINT_RX_CONS(12);
10664 BCE_PRINT_RX_CONS(13); BCE_PRINT_RX_CONS(14); BCE_PRINT_RX_CONS(15);
10666 BCE_PRINT_TX_CONS(1); BCE_PRINT_TX_CONS(2); BCE_PRINT_TX_CONS(3);
10668 if (sblk->status_completion_producer_index ||
10669 sblk->status_cmd_consumer_index)
10670 BCE_PRINTF("com_prod = 0x%08X, cmd_cons = 0x%08X\n",
10671 sblk->status_completion_producer_index,
10672 sblk->status_cmd_consumer_index);
10675 "----------------------------"
10677 "----------------------------\n");
10681 #define BCE_PRINT_64BIT_STAT(arg) \
10682 if (sblk->arg##_lo || sblk->arg##_hi) \
10683 BCE_PRINTF("0x%08X:%08X : %s\n", sblk->arg##_hi, \
10684 sblk->arg##_lo, #arg);
10686 #define BCE_PRINT_32BIT_STAT(arg) \
10688 BCE_PRINTF(" 0x%08X : %s\n", \
10691 /****************************************************************************/
10692 /* Prints out the statistics block from host memory. */
10696 /****************************************************************************/
10697 static __attribute__ ((noinline)) void
10698 bce_dump_stats_block(struct bce_softc *sc)
10700 struct statistics_block *sblk;
10702 bus_dmamap_sync(sc->stats_tag, sc->stats_map, BUS_DMASYNC_POSTREAD);
10704 sblk = sc->stats_block;
10708 " Stats Block (All Stats Not Shown Are 0) "
10709 "---------------\n");
10711 BCE_PRINT_64BIT_STAT(stat_IfHCInOctets);
10712 BCE_PRINT_64BIT_STAT(stat_IfHCInBadOctets);
10713 BCE_PRINT_64BIT_STAT(stat_IfHCOutOctets);
10714 BCE_PRINT_64BIT_STAT(stat_IfHCOutBadOctets);
10715 BCE_PRINT_64BIT_STAT(stat_IfHCInUcastPkts);
10716 BCE_PRINT_64BIT_STAT(stat_IfHCInBroadcastPkts);
10717 BCE_PRINT_64BIT_STAT(stat_IfHCInMulticastPkts);
10718 BCE_PRINT_64BIT_STAT(stat_IfHCOutUcastPkts);
10719 BCE_PRINT_64BIT_STAT(stat_IfHCOutBroadcastPkts);
10720 BCE_PRINT_64BIT_STAT(stat_IfHCOutMulticastPkts);
10721 BCE_PRINT_32BIT_STAT(
10722 stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
10723 BCE_PRINT_32BIT_STAT(stat_Dot3StatsCarrierSenseErrors);
10724 BCE_PRINT_32BIT_STAT(stat_Dot3StatsFCSErrors);
10725 BCE_PRINT_32BIT_STAT(stat_Dot3StatsAlignmentErrors);
10726 BCE_PRINT_32BIT_STAT(stat_Dot3StatsSingleCollisionFrames);
10727 BCE_PRINT_32BIT_STAT(stat_Dot3StatsMultipleCollisionFrames);
10728 BCE_PRINT_32BIT_STAT(stat_Dot3StatsDeferredTransmissions);
10729 BCE_PRINT_32BIT_STAT(stat_Dot3StatsExcessiveCollisions);
10730 BCE_PRINT_32BIT_STAT(stat_Dot3StatsLateCollisions);
10731 BCE_PRINT_32BIT_STAT(stat_EtherStatsCollisions);
10732 BCE_PRINT_32BIT_STAT(stat_EtherStatsFragments);
10733 BCE_PRINT_32BIT_STAT(stat_EtherStatsJabbers);
10734 BCE_PRINT_32BIT_STAT(stat_EtherStatsUndersizePkts);
10735 BCE_PRINT_32BIT_STAT(stat_EtherStatsOversizePkts);
10736 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx64Octets);
10737 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx65Octetsto127Octets);
10738 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx128Octetsto255Octets);
10739 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx256Octetsto511Octets);
10740 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx512Octetsto1023Octets);
10741 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx1024Octetsto1522Octets);
10742 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsRx1523Octetsto9022Octets);
10743 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx64Octets);
10744 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx65Octetsto127Octets);
10745 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx128Octetsto255Octets);
10746 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx256Octetsto511Octets);
10747 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx512Octetsto1023Octets);
10748 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx1024Octetsto1522Octets);
10749 BCE_PRINT_32BIT_STAT(stat_EtherStatsPktsTx1523Octetsto9022Octets);
10750 BCE_PRINT_32BIT_STAT(stat_XonPauseFramesReceived);
10751 BCE_PRINT_32BIT_STAT(stat_XoffPauseFramesReceived);
10752 BCE_PRINT_32BIT_STAT(stat_OutXonSent);
10753 BCE_PRINT_32BIT_STAT(stat_OutXoffSent);
10754 BCE_PRINT_32BIT_STAT(stat_FlowControlDone);
10755 BCE_PRINT_32BIT_STAT(stat_MacControlFramesReceived);
10756 BCE_PRINT_32BIT_STAT(stat_XoffStateEntered);
10757 BCE_PRINT_32BIT_STAT(stat_IfInFramesL2FilterDiscards);
10758 BCE_PRINT_32BIT_STAT(stat_IfInRuleCheckerDiscards);
10759 BCE_PRINT_32BIT_STAT(stat_IfInFTQDiscards);
10760 BCE_PRINT_32BIT_STAT(stat_IfInMBUFDiscards);
10761 BCE_PRINT_32BIT_STAT(stat_IfInRuleCheckerP4Hit);
10762 BCE_PRINT_32BIT_STAT(stat_CatchupInRuleCheckerDiscards);
10763 BCE_PRINT_32BIT_STAT(stat_CatchupInFTQDiscards);
10764 BCE_PRINT_32BIT_STAT(stat_CatchupInMBUFDiscards);
10765 BCE_PRINT_32BIT_STAT(stat_CatchupInRuleCheckerP4Hit);
10768 "----------------------------"
10770 "----------------------------\n");
10774 /****************************************************************************/
10775 /* Prints out a summary of the driver state. */
10779 /****************************************************************************/
10780 static __attribute__ ((noinline)) void
10781 bce_dump_driver_state(struct bce_softc *sc)
10783 u32 val_hi, val_lo;
10786 "-----------------------------"
10788 "-----------------------------\n");
10790 val_hi = BCE_ADDR_HI(sc);
10791 val_lo = BCE_ADDR_LO(sc);
10792 BCE_PRINTF("0x%08X:%08X - (sc) driver softc structure virtual "
10793 "address\n", val_hi, val_lo);
10795 val_hi = BCE_ADDR_HI(sc->bce_vhandle);
10796 val_lo = BCE_ADDR_LO(sc->bce_vhandle);
10797 BCE_PRINTF("0x%08X:%08X - (sc->bce_vhandle) PCI BAR virtual "
10798 "address\n", val_hi, val_lo);
10800 val_hi = BCE_ADDR_HI(sc->status_block);
10801 val_lo = BCE_ADDR_LO(sc->status_block);
10802 BCE_PRINTF("0x%08X:%08X - (sc->status_block) status block "
10803 "virtual address\n", val_hi, val_lo);
10805 val_hi = BCE_ADDR_HI(sc->stats_block);
10806 val_lo = BCE_ADDR_LO(sc->stats_block);
10807 BCE_PRINTF("0x%08X:%08X - (sc->stats_block) statistics block "
10808 "virtual address\n", val_hi, val_lo);
10810 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
10811 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
10812 BCE_PRINTF("0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
10813 "virtual adddress\n", val_hi, val_lo);
10815 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
10816 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
10817 BCE_PRINTF("0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
10818 "virtual address\n", val_hi, val_lo);
10820 if (bce_hdr_split == TRUE) {
10821 val_hi = BCE_ADDR_HI(sc->pg_bd_chain);
10822 val_lo = BCE_ADDR_LO(sc->pg_bd_chain);
10823 BCE_PRINTF("0x%08X:%08X - (sc->pg_bd_chain) page chain "
10824 "virtual address\n", val_hi, val_lo);
10827 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
10828 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
10829 BCE_PRINTF("0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
10830 "virtual address\n", val_hi, val_lo);
10832 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
10833 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
10834 BCE_PRINTF("0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
10835 "virtual address\n", val_hi, val_lo);
10837 if (bce_hdr_split == TRUE) {
10838 val_hi = BCE_ADDR_HI(sc->pg_mbuf_ptr);
10839 val_lo = BCE_ADDR_LO(sc->pg_mbuf_ptr);
10840 BCE_PRINTF("0x%08X:%08X - (sc->pg_mbuf_ptr) page mbuf chain "
10841 "virtual address\n", val_hi, val_lo);
10844 BCE_PRINTF(" 0x%016llX - (sc->interrupts_generated) "
10846 (long long unsigned int) sc->interrupts_generated);
10848 BCE_PRINTF(" 0x%016llX - (sc->interrupts_rx) "
10849 "rx interrupts handled\n",
10850 (long long unsigned int) sc->interrupts_rx);
10852 BCE_PRINTF(" 0x%016llX - (sc->interrupts_tx) "
10853 "tx interrupts handled\n",
10854 (long long unsigned int) sc->interrupts_tx);
10856 BCE_PRINTF(" 0x%016llX - (sc->phy_interrupts) "
10857 "phy interrupts handled\n",
10858 (long long unsigned int) sc->phy_interrupts);
10860 BCE_PRINTF(" 0x%08X - (sc->last_status_idx) "
10861 "status block index\n", sc->last_status_idx);
10863 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->tx_prod) tx producer "
10864 "index\n", sc->tx_prod, (u16) TX_CHAIN_IDX(sc->tx_prod));
10866 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->tx_cons) tx consumer "
10867 "index\n", sc->tx_cons, (u16) TX_CHAIN_IDX(sc->tx_cons));
10869 BCE_PRINTF(" 0x%08X - (sc->tx_prod_bseq) tx producer "
10870 "byte seq index\n", sc->tx_prod_bseq);
10872 BCE_PRINTF(" 0x%08X - (sc->debug_tx_mbuf_alloc) tx "
10873 "mbufs allocated\n", sc->debug_tx_mbuf_alloc);
10875 BCE_PRINTF(" 0x%08X - (sc->used_tx_bd) used "
10876 "tx_bd's\n", sc->used_tx_bd);
10878 BCE_PRINTF(" 0x%04X/0x%04X - (sc->tx_hi_watermark)/"
10879 "(sc->max_tx_bd)\n", sc->tx_hi_watermark, sc->max_tx_bd);
10881 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->rx_prod) rx producer "
10882 "index\n", sc->rx_prod, (u16) RX_CHAIN_IDX(sc->rx_prod));
10884 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->rx_cons) rx consumer "
10885 "index\n", sc->rx_cons, (u16) RX_CHAIN_IDX(sc->rx_cons));
10887 BCE_PRINTF(" 0x%08X - (sc->rx_prod_bseq) rx producer "
10888 "byte seq index\n", sc->rx_prod_bseq);
10890 BCE_PRINTF(" 0x%04X/0x%04X - (sc->rx_low_watermark)/"
10891 "(sc->max_rx_bd)\n", sc->rx_low_watermark, sc->max_rx_bd);
10893 BCE_PRINTF(" 0x%08X - (sc->debug_rx_mbuf_alloc) rx "
10894 "mbufs allocated\n", sc->debug_rx_mbuf_alloc);
10896 BCE_PRINTF(" 0x%08X - (sc->free_rx_bd) free "
10897 "rx_bd's\n", sc->free_rx_bd);
10899 if (bce_hdr_split == TRUE) {
10900 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->pg_prod) page producer "
10901 "index\n", sc->pg_prod, (u16) PG_CHAIN_IDX(sc->pg_prod));
10903 BCE_PRINTF(" 0x%04X(0x%04X) - (sc->pg_cons) page consumer "
10904 "index\n", sc->pg_cons, (u16) PG_CHAIN_IDX(sc->pg_cons));
10906 BCE_PRINTF(" 0x%08X - (sc->debug_pg_mbuf_alloc) page "
10907 "mbufs allocated\n", sc->debug_pg_mbuf_alloc);
10910 BCE_PRINTF(" 0x%08X - (sc->free_pg_bd) free page "
10911 "rx_bd's\n", sc->free_pg_bd);
10913 BCE_PRINTF(" 0x%04X/0x%04X - (sc->pg_low_watermark)/"
10914 "(sc->max_pg_bd)\n", sc->pg_low_watermark, sc->max_pg_bd);
10916 BCE_PRINTF(" 0x%08X - (sc->mbuf_alloc_failed_count) "
10917 "mbuf alloc failures\n", sc->mbuf_alloc_failed_count);
10919 BCE_PRINTF(" 0x%08X - (sc->bce_flags) "
10920 "bce mac flags\n", sc->bce_flags);
10922 BCE_PRINTF(" 0x%08X - (sc->bce_phy_flags) "
10923 "bce phy flags\n", sc->bce_phy_flags);
10926 "----------------------------"
10928 "----------------------------\n");
10932 /****************************************************************************/
10933 /* Prints out the hardware state through a summary of important register, */
10934 /* followed by a complete register dump. */
10938 /****************************************************************************/
10939 static __attribute__ ((noinline)) void
10940 bce_dump_hw_state(struct bce_softc *sc)
10945 "----------------------------"
10947 "----------------------------\n");
10949 BCE_PRINTF("%s - bootcode version\n", sc->bce_bc_ver);
10951 val = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
10952 BCE_PRINTF("0x%08X - (0x%06X) misc_enable_status_bits\n",
10953 val, BCE_MISC_ENABLE_STATUS_BITS);
10955 val = REG_RD(sc, BCE_DMA_STATUS);
10956 BCE_PRINTF("0x%08X - (0x%06X) dma_status\n",
10957 val, BCE_DMA_STATUS);
10959 val = REG_RD(sc, BCE_CTX_STATUS);
10960 BCE_PRINTF("0x%08X - (0x%06X) ctx_status\n",
10961 val, BCE_CTX_STATUS);
10963 val = REG_RD(sc, BCE_EMAC_STATUS);
10964 BCE_PRINTF("0x%08X - (0x%06X) emac_status\n",
10965 val, BCE_EMAC_STATUS);
10967 val = REG_RD(sc, BCE_RPM_STATUS);
10968 BCE_PRINTF("0x%08X - (0x%06X) rpm_status\n",
10969 val, BCE_RPM_STATUS);
10971 /* ToDo: Create a #define for this constant. */
10972 val = REG_RD(sc, 0x2004);
10973 BCE_PRINTF("0x%08X - (0x%06X) rlup_status\n",
10976 val = REG_RD(sc, BCE_RV2P_STATUS);
10977 BCE_PRINTF("0x%08X - (0x%06X) rv2p_status\n",
10978 val, BCE_RV2P_STATUS);
10980 /* ToDo: Create a #define for this constant. */
10981 val = REG_RD(sc, 0x2c04);
10982 BCE_PRINTF("0x%08X - (0x%06X) rdma_status\n",
10985 val = REG_RD(sc, BCE_TBDR_STATUS);
10986 BCE_PRINTF("0x%08X - (0x%06X) tbdr_status\n",
10987 val, BCE_TBDR_STATUS);
10989 val = REG_RD(sc, BCE_TDMA_STATUS);
10990 BCE_PRINTF("0x%08X - (0x%06X) tdma_status\n",
10991 val, BCE_TDMA_STATUS);
10993 val = REG_RD(sc, BCE_HC_STATUS);
10994 BCE_PRINTF("0x%08X - (0x%06X) hc_status\n",
10995 val, BCE_HC_STATUS);
10997 val = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
10998 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_state\n",
10999 val, BCE_TXP_CPU_STATE);
11001 val = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
11002 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_state\n",
11003 val, BCE_TPAT_CPU_STATE);
11005 val = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
11006 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_state\n",
11007 val, BCE_RXP_CPU_STATE);
11009 val = REG_RD_IND(sc, BCE_COM_CPU_STATE);
11010 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_state\n",
11011 val, BCE_COM_CPU_STATE);
11013 val = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
11014 BCE_PRINTF("0x%08X - (0x%06X) mcp_cpu_state\n",
11015 val, BCE_MCP_CPU_STATE);
11017 val = REG_RD_IND(sc, BCE_CP_CPU_STATE);
11018 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_state\n",
11019 val, BCE_CP_CPU_STATE);
11022 "----------------------------"
11024 "----------------------------\n");
11027 "----------------------------"
11029 "----------------------------\n");
11031 for (int i = 0x400; i < 0x8000; i += 0x10) {
11032 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
11033 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
11034 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
11038 "----------------------------"
11040 "----------------------------\n");
11044 /****************************************************************************/
11045 /* Prints out the contentst of shared memory which is used for host driver */
11046 /* to bootcode firmware communication. */
11050 /****************************************************************************/
11051 static __attribute__ ((noinline)) void
11052 bce_dump_shmem_state(struct bce_softc *sc)
11055 "----------------------------"
11057 "----------------------------\n");
11059 BCE_PRINTF("0x%08X - Shared memory base address\n",
11060 sc->bce_shmem_base);
11061 BCE_PRINTF("%s - bootcode version\n",
11065 "----------------------------"
11067 "----------------------------\n");
11069 for (int i = 0x0; i < 0x200; i += 0x10) {
11070 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
11071 i, bce_shmem_rd(sc, i), bce_shmem_rd(sc, i + 0x4),
11072 bce_shmem_rd(sc, i + 0x8), bce_shmem_rd(sc, i + 0xC));
11076 "----------------------------"
11078 "----------------------------\n");
11082 /****************************************************************************/
11083 /* Prints out the mailbox queue registers. */
11087 /****************************************************************************/
11088 static __attribute__ ((noinline)) void
11089 bce_dump_mq_regs(struct bce_softc *sc)
11092 "----------------------------"
11094 "----------------------------\n");
11097 "----------------------------"
11099 "----------------------------\n");
11101 for (int i = 0x3c00; i < 0x4000; i += 0x10) {
11102 BCE_PRINTF("0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
11103 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
11104 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
11108 "----------------------------"
11110 "----------------------------\n");
11114 /****************************************************************************/
11115 /* Prints out the bootcode state. */
11119 /****************************************************************************/
11120 static __attribute__ ((noinline)) void
11121 bce_dump_bc_state(struct bce_softc *sc)
11126 "----------------------------"
11128 "----------------------------\n");
11130 BCE_PRINTF("%s - bootcode version\n", sc->bce_bc_ver);
11132 val = bce_shmem_rd(sc, BCE_BC_RESET_TYPE);
11133 BCE_PRINTF("0x%08X - (0x%06X) reset_type\n",
11134 val, BCE_BC_RESET_TYPE);
11136 val = bce_shmem_rd(sc, BCE_BC_STATE);
11137 BCE_PRINTF("0x%08X - (0x%06X) state\n",
11138 val, BCE_BC_STATE);
11140 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
11141 BCE_PRINTF("0x%08X - (0x%06X) condition\n",
11142 val, BCE_BC_STATE_CONDITION);
11144 val = bce_shmem_rd(sc, BCE_BC_STATE_DEBUG_CMD);
11145 BCE_PRINTF("0x%08X - (0x%06X) debug_cmd\n",
11146 val, BCE_BC_STATE_DEBUG_CMD);
11149 "----------------------------"
11151 "----------------------------\n");
11155 /****************************************************************************/
11156 /* Prints out the TXP processor state. */
11160 /****************************************************************************/
11161 static __attribute__ ((noinline)) void
11162 bce_dump_txp_state(struct bce_softc *sc, int regs)
11168 "----------------------------"
11170 "----------------------------\n");
11172 for (int i = 0; i < 3; i++)
11173 fw_version[i] = htonl(REG_RD_IND(sc,
11174 (BCE_TXP_SCRATCH + 0x10 + i * 4)));
11175 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11177 val = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
11178 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_mode\n",
11179 val, BCE_TXP_CPU_MODE);
11181 val = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
11182 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_state\n",
11183 val, BCE_TXP_CPU_STATE);
11185 val = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
11186 BCE_PRINTF("0x%08X - (0x%06X) txp_cpu_event_mask\n",
11187 val, BCE_TXP_CPU_EVENT_MASK);
11191 "----------------------------"
11193 "----------------------------\n");
11195 for (int i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
11196 /* Skip the big blank spaces */
11197 if (i < 0x454000 && i > 0x5ffff)
11198 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11199 "0x%08X 0x%08X\n", i,
11201 REG_RD_IND(sc, i + 0x4),
11202 REG_RD_IND(sc, i + 0x8),
11203 REG_RD_IND(sc, i + 0xC));
11208 "----------------------------"
11210 "----------------------------\n");
11214 /****************************************************************************/
11215 /* Prints out the RXP processor state. */
11219 /****************************************************************************/
11220 static __attribute__ ((noinline)) void
11221 bce_dump_rxp_state(struct bce_softc *sc, int regs)
11227 "----------------------------"
11229 "----------------------------\n");
11231 for (int i = 0; i < 3; i++)
11232 fw_version[i] = htonl(REG_RD_IND(sc,
11233 (BCE_RXP_SCRATCH + 0x10 + i * 4)));
11235 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11237 val = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
11238 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_mode\n",
11239 val, BCE_RXP_CPU_MODE);
11241 val = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
11242 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_state\n",
11243 val, BCE_RXP_CPU_STATE);
11245 val = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
11246 BCE_PRINTF("0x%08X - (0x%06X) rxp_cpu_event_mask\n",
11247 val, BCE_RXP_CPU_EVENT_MASK);
11251 "----------------------------"
11253 "----------------------------\n");
11255 for (int i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
11256 /* Skip the big blank sapces */
11257 if (i < 0xc5400 && i > 0xdffff)
11258 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11259 "0x%08X 0x%08X\n", i,
11261 REG_RD_IND(sc, i + 0x4),
11262 REG_RD_IND(sc, i + 0x8),
11263 REG_RD_IND(sc, i + 0xC));
11268 "----------------------------"
11270 "----------------------------\n");
11274 /****************************************************************************/
11275 /* Prints out the TPAT processor state. */
11279 /****************************************************************************/
11280 static __attribute__ ((noinline)) void
11281 bce_dump_tpat_state(struct bce_softc *sc, int regs)
11287 "----------------------------"
11289 "----------------------------\n");
11291 for (int i = 0; i < 3; i++)
11292 fw_version[i] = htonl(REG_RD_IND(sc,
11293 (BCE_TPAT_SCRATCH + 0x410 + i * 4)));
11295 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11297 val = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
11298 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_mode\n",
11299 val, BCE_TPAT_CPU_MODE);
11301 val = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
11302 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_state\n",
11303 val, BCE_TPAT_CPU_STATE);
11305 val = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
11306 BCE_PRINTF("0x%08X - (0x%06X) tpat_cpu_event_mask\n",
11307 val, BCE_TPAT_CPU_EVENT_MASK);
11311 "----------------------------"
11313 "----------------------------\n");
11315 for (int i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
11316 /* Skip the big blank spaces */
11317 if (i < 0x854000 && i > 0x9ffff)
11318 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11319 "0x%08X 0x%08X\n", i,
11321 REG_RD_IND(sc, i + 0x4),
11322 REG_RD_IND(sc, i + 0x8),
11323 REG_RD_IND(sc, i + 0xC));
11328 "----------------------------"
11330 "----------------------------\n");
11334 /****************************************************************************/
11335 /* Prints out the Command Procesor (CP) state. */
11339 /****************************************************************************/
11340 static __attribute__ ((noinline)) void
11341 bce_dump_cp_state(struct bce_softc *sc, int regs)
11347 "----------------------------"
11349 "----------------------------\n");
11351 for (int i = 0; i < 3; i++)
11352 fw_version[i] = htonl(REG_RD_IND(sc,
11353 (BCE_CP_SCRATCH + 0x10 + i * 4)));
11355 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11357 val = REG_RD_IND(sc, BCE_CP_CPU_MODE);
11358 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_mode\n",
11359 val, BCE_CP_CPU_MODE);
11361 val = REG_RD_IND(sc, BCE_CP_CPU_STATE);
11362 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_state\n",
11363 val, BCE_CP_CPU_STATE);
11365 val = REG_RD_IND(sc, BCE_CP_CPU_EVENT_MASK);
11366 BCE_PRINTF("0x%08X - (0x%06X) cp_cpu_event_mask\n", val,
11367 BCE_CP_CPU_EVENT_MASK);
11371 "----------------------------"
11373 "----------------------------\n");
11375 for (int i = BCE_CP_CPU_MODE; i < 0x1aa000; i += 0x10) {
11376 /* Skip the big blank spaces */
11377 if (i < 0x185400 && i > 0x19ffff)
11378 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11379 "0x%08X 0x%08X\n", i,
11381 REG_RD_IND(sc, i + 0x4),
11382 REG_RD_IND(sc, i + 0x8),
11383 REG_RD_IND(sc, i + 0xC));
11388 "----------------------------"
11390 "----------------------------\n");
11394 /****************************************************************************/
11395 /* Prints out the Completion Procesor (COM) state. */
11399 /****************************************************************************/
11400 static __attribute__ ((noinline)) void
11401 bce_dump_com_state(struct bce_softc *sc, int regs)
11407 "----------------------------"
11409 "----------------------------\n");
11411 for (int i = 0; i < 3; i++)
11412 fw_version[i] = htonl(REG_RD_IND(sc,
11413 (BCE_COM_SCRATCH + 0x10 + i * 4)));
11415 BCE_PRINTF("Firmware version - %s\n", (char *) fw_version);
11417 val = REG_RD_IND(sc, BCE_COM_CPU_MODE);
11418 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_mode\n",
11419 val, BCE_COM_CPU_MODE);
11421 val = REG_RD_IND(sc, BCE_COM_CPU_STATE);
11422 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_state\n",
11423 val, BCE_COM_CPU_STATE);
11425 val = REG_RD_IND(sc, BCE_COM_CPU_EVENT_MASK);
11426 BCE_PRINTF("0x%08X - (0x%06X) com_cpu_event_mask\n", val,
11427 BCE_COM_CPU_EVENT_MASK);
11431 "----------------------------"
11433 "----------------------------\n");
11435 for (int i = BCE_COM_CPU_MODE; i < 0x1053e8; i += 0x10) {
11436 BCE_PRINTF("0x%04X: 0x%08X 0x%08X "
11437 "0x%08X 0x%08X\n", i,
11439 REG_RD_IND(sc, i + 0x4),
11440 REG_RD_IND(sc, i + 0x8),
11441 REG_RD_IND(sc, i + 0xC));
11446 "----------------------------"
11448 "----------------------------\n");
11452 /****************************************************************************/
11453 /* Prints out the Receive Virtual 2 Physical (RV2P) state. */
11457 /****************************************************************************/
11458 static __attribute__ ((noinline)) void
11459 bce_dump_rv2p_state(struct bce_softc *sc)
11461 u32 val, pc1, pc2, fw_ver_high, fw_ver_low;
11464 "----------------------------"
11466 "----------------------------\n");
11468 /* Stall the RV2P processors. */
11469 val = REG_RD_IND(sc, BCE_RV2P_CONFIG);
11470 val |= BCE_RV2P_CONFIG_STALL_PROC1 | BCE_RV2P_CONFIG_STALL_PROC2;
11471 REG_WR_IND(sc, BCE_RV2P_CONFIG, val);
11473 /* Read the firmware version. */
11475 REG_WR_IND(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
11476 fw_ver_low = REG_RD_IND(sc, BCE_RV2P_INSTR_LOW);
11477 fw_ver_high = REG_RD_IND(sc, BCE_RV2P_INSTR_HIGH) &
11478 BCE_RV2P_INSTR_HIGH_HIGH;
11479 BCE_PRINTF("RV2P1 Firmware version - 0x%08X:0x%08X\n",
11480 fw_ver_high, fw_ver_low);
11483 REG_WR_IND(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
11484 fw_ver_low = REG_RD_IND(sc, BCE_RV2P_INSTR_LOW);
11485 fw_ver_high = REG_RD_IND(sc, BCE_RV2P_INSTR_HIGH) &
11486 BCE_RV2P_INSTR_HIGH_HIGH;
11487 BCE_PRINTF("RV2P2 Firmware version - 0x%08X:0x%08X\n",
11488 fw_ver_high, fw_ver_low);
11490 /* Resume the RV2P processors. */
11491 val = REG_RD_IND(sc, BCE_RV2P_CONFIG);
11492 val &= ~(BCE_RV2P_CONFIG_STALL_PROC1 | BCE_RV2P_CONFIG_STALL_PROC2);
11493 REG_WR_IND(sc, BCE_RV2P_CONFIG, val);
11495 /* Fetch the program counter value. */
11497 REG_WR_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK, val);
11498 val = REG_RD_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK);
11499 pc1 = (val & BCE_RV2P_DEBUG_VECT_PEEK_1_VALUE);
11500 pc2 = (val & BCE_RV2P_DEBUG_VECT_PEEK_2_VALUE) >> 16;
11501 BCE_PRINTF("0x%08X - RV2P1 program counter (1st read)\n", pc1);
11502 BCE_PRINTF("0x%08X - RV2P2 program counter (1st read)\n", pc2);
11504 /* Fetch the program counter value again to see if it is advancing. */
11506 REG_WR_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK, val);
11507 val = REG_RD_IND(sc, BCE_RV2P_DEBUG_VECT_PEEK);
11508 pc1 = (val & BCE_RV2P_DEBUG_VECT_PEEK_1_VALUE);
11509 pc2 = (val & BCE_RV2P_DEBUG_VECT_PEEK_2_VALUE) >> 16;
11510 BCE_PRINTF("0x%08X - RV2P1 program counter (2nd read)\n", pc1);
11511 BCE_PRINTF("0x%08X - RV2P2 program counter (2nd read)\n", pc2);
11514 "----------------------------"
11516 "----------------------------\n");
11520 /****************************************************************************/
11521 /* Prints out the driver state and then enters the debugger. */
11525 /****************************************************************************/
11526 static __attribute__ ((noinline)) void
11527 bce_breakpoint(struct bce_softc *sc)
11531 * Unreachable code to silence compiler warnings
11532 * about unused functions.
11535 bce_freeze_controller(sc);
11536 bce_unfreeze_controller(sc);
11537 bce_dump_enet(sc, NULL);
11538 bce_dump_txbd(sc, 0, NULL);
11539 bce_dump_rxbd(sc, 0, NULL);
11540 bce_dump_tx_mbuf_chain(sc, 0, USABLE_TX_BD_ALLOC);
11541 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD_ALLOC);
11542 bce_dump_pg_mbuf_chain(sc, 0, USABLE_PG_BD_ALLOC);
11543 bce_dump_l2fhdr(sc, 0, NULL);
11544 bce_dump_ctx(sc, RX_CID);
11546 bce_dump_tx_chain(sc, 0, USABLE_TX_BD_ALLOC);
11547 bce_dump_rx_bd_chain(sc, 0, USABLE_RX_BD_ALLOC);
11548 bce_dump_pg_chain(sc, 0, USABLE_PG_BD_ALLOC);
11549 bce_dump_status_block(sc);
11550 bce_dump_stats_block(sc);
11551 bce_dump_driver_state(sc);
11552 bce_dump_hw_state(sc);
11553 bce_dump_bc_state(sc);
11554 bce_dump_txp_state(sc, 0);
11555 bce_dump_rxp_state(sc, 0);
11556 bce_dump_tpat_state(sc, 0);
11557 bce_dump_cp_state(sc, 0);
11558 bce_dump_com_state(sc, 0);
11559 bce_dump_rv2p_state(sc);
11560 bce_dump_pgbd(sc, 0, NULL);
11563 bce_dump_status_block(sc);
11564 bce_dump_driver_state(sc);
11566 /* Call the debugger. */