2 * Copyright (c) 2006 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:
39 * The following controllers are not supported by this driver:
40 * (These are not "Production" versions of the controller.)
43 * BCM5706S A0, A1, A2, A3
50 #include <dev/bce/if_bcereg.h>
51 #include <dev/bce/if_bcefw.h>
53 /****************************************************************************/
54 /* BCE Driver Version */
55 /****************************************************************************/
56 char bce_driver_version[] = "v0.9.5";
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 bce_debug_l2fhdr_status_check = 0;
78 /* Controls how often the unexpected attention check will fail. */
79 int bce_debug_unexpected_attention = 0;
81 /* Controls how often to simulate an mbuf allocation failure. */
82 int bce_debug_mbuf_allocation_failure = 0;
84 /* Controls how often to simulate a DMA mapping failure. */
85 int bce_debug_dma_map_addr_failure = 0;
87 /* Controls how often to simulate a bootcode failure. */
88 int bce_debug_bootcode_running_failure = 0;
92 /****************************************************************************/
93 /* PCI Device ID Table */
95 /* Used by bce_probe() to identify the devices supported by this driver. */
96 /****************************************************************************/
97 #define BCE_DEVDESC_MAX 64
99 static struct bce_type bce_devs[] = {
100 /* BCM5706C Controllers and OEM boards. */
101 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
102 "HP NC370T Multifunction Gigabit Server Adapter" },
103 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
104 "HP NC370i Multifunction Gigabit Server Adapter" },
105 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
106 "Broadcom NetXtreme II BCM5706 1000Base-T" },
108 /* BCM5706S controllers and OEM boards. */
109 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
110 "HP NC370F Multifunction Gigabit Server Adapter" },
111 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
112 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
114 /* BCM5708C controllers and OEM boards. */
115 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
116 "Broadcom NetXtreme II BCM5708 1000Base-T" },
118 /* BCM5708S controllers and OEM boards. */
119 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
120 "Broadcom NetXtreme II BCM5708 1000Base-T" },
125 /****************************************************************************/
126 /* Supported Flash NVRAM device data. */
127 /****************************************************************************/
128 static struct flash_spec flash_table[] =
131 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
132 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
133 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
135 /* Expansion entry 0001 */
136 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
137 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
138 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
140 /* Saifun SA25F010 (non-buffered flash) */
141 /* strap, cfg1, & write1 need updates */
142 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
143 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
144 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
145 "Non-buffered flash (128kB)"},
146 /* Saifun SA25F020 (non-buffered flash) */
147 /* strap, cfg1, & write1 need updates */
148 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
149 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
150 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
151 "Non-buffered flash (256kB)"},
152 /* Expansion entry 0100 */
153 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
154 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
155 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
157 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
158 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
159 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
160 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
161 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
162 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
163 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
164 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
165 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
166 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
167 /* Saifun SA25F005 (non-buffered flash) */
168 /* strap, cfg1, & write1 need updates */
169 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
170 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
171 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
172 "Non-buffered flash (64kB)"},
174 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
175 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
176 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
178 /* Expansion entry 1001 */
179 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
180 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
181 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
183 /* Expansion entry 1010 */
184 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
185 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
186 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
188 /* ATMEL AT45DB011B (buffered flash) */
189 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
190 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
191 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
192 "Buffered flash (128kB)"},
193 /* Expansion entry 1100 */
194 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
195 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
196 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
198 /* Expansion entry 1101 */
199 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
200 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
201 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
203 /* Ateml Expansion entry 1110 */
204 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
205 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
206 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
207 "Entry 1110 (Atmel)"},
208 /* ATMEL AT45DB021B (buffered flash) */
209 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
210 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
211 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
212 "Buffered flash (256kB)"},
216 /****************************************************************************/
217 /* FreeBSD device entry points. */
218 /****************************************************************************/
219 static int bce_probe (device_t);
220 static int bce_attach (device_t);
221 static int bce_detach (device_t);
222 static void bce_shutdown (device_t);
225 /****************************************************************************/
226 /* BCE Debug Data Structure Dump Routines */
227 /****************************************************************************/
229 static void bce_dump_mbuf (struct bce_softc *, struct mbuf *);
230 static void bce_dump_tx_mbuf_chain (struct bce_softc *, int, int);
231 static void bce_dump_rx_mbuf_chain (struct bce_softc *, int, int);
232 static void bce_dump_txbd (struct bce_softc *, int, struct tx_bd *);
233 static void bce_dump_rxbd (struct bce_softc *, int, struct rx_bd *);
234 static void bce_dump_l2fhdr (struct bce_softc *, int, struct l2_fhdr *);
235 static void bce_dump_tx_chain (struct bce_softc *, int, int);
236 static void bce_dump_rx_chain (struct bce_softc *, int, int);
237 static void bce_dump_status_block (struct bce_softc *);
238 static void bce_dump_stats_block (struct bce_softc *);
239 static void bce_dump_driver_state (struct bce_softc *);
240 static void bce_dump_hw_state (struct bce_softc *);
241 static void bce_breakpoint (struct bce_softc *);
245 /****************************************************************************/
246 /* BCE Register/Memory Access Routines */
247 /****************************************************************************/
248 static u32 bce_reg_rd_ind (struct bce_softc *, u32);
249 static void bce_reg_wr_ind (struct bce_softc *, u32, u32);
250 static void bce_ctx_wr (struct bce_softc *, u32, u32, u32);
251 static int bce_miibus_read_reg (device_t, int, int);
252 static int bce_miibus_write_reg (device_t, int, int, int);
253 static void bce_miibus_statchg (device_t);
256 /****************************************************************************/
257 /* BCE NVRAM Access Routines */
258 /****************************************************************************/
259 static int bce_acquire_nvram_lock (struct bce_softc *);
260 static int bce_release_nvram_lock (struct bce_softc *);
261 static void bce_enable_nvram_access (struct bce_softc *);
262 static void bce_disable_nvram_access(struct bce_softc *);
263 static int bce_nvram_read_dword (struct bce_softc *, u32, u8 *, u32);
264 static int bce_init_nvram (struct bce_softc *);
265 static int bce_nvram_read (struct bce_softc *, u32, u8 *, int);
266 static int bce_nvram_test (struct bce_softc *);
267 #ifdef BCE_NVRAM_WRITE_SUPPORT
268 static int bce_enable_nvram_write (struct bce_softc *);
269 static void bce_disable_nvram_write (struct bce_softc *);
270 static int bce_nvram_erase_page (struct bce_softc *, u32);
271 static int bce_nvram_write_dword (struct bce_softc *, u32, u8 *, u32);
272 static int bce_nvram_write (struct bce_softc *, u32, u8 *, int);
275 /****************************************************************************/
277 /****************************************************************************/
278 static void bce_dma_map_addr (void *, bus_dma_segment_t *, int, int);
279 static void bce_dma_map_tx_desc (void *, bus_dma_segment_t *, int, bus_size_t, int);
280 static int bce_dma_alloc (device_t);
281 static void bce_dma_free (struct bce_softc *);
282 static void bce_release_resources (struct bce_softc *);
284 /****************************************************************************/
285 /* BCE Firmware Synchronization and Load */
286 /****************************************************************************/
287 static int bce_fw_sync (struct bce_softc *, u32);
288 static void bce_load_rv2p_fw (struct bce_softc *, u32 *, u32, u32);
289 static void bce_load_cpu_fw (struct bce_softc *, struct cpu_reg *, struct fw_info *);
290 static void bce_init_cpus (struct bce_softc *);
292 static void bce_stop (struct bce_softc *);
293 static int bce_reset (struct bce_softc *, u32);
294 static int bce_chipinit (struct bce_softc *);
295 static int bce_blockinit (struct bce_softc *);
296 static int bce_get_buf (struct bce_softc *, struct mbuf *, u16 *, u16 *, u32 *);
298 static int bce_init_tx_chain (struct bce_softc *);
299 static int bce_init_rx_chain (struct bce_softc *);
300 static void bce_free_rx_chain (struct bce_softc *);
301 static void bce_free_tx_chain (struct bce_softc *);
303 static int bce_tx_encap (struct bce_softc *, struct mbuf *, u16 *, u16 *, u32 *);
304 static void bce_start_locked (struct ifnet *);
305 static void bce_start (struct ifnet *);
306 static int bce_ioctl (struct ifnet *, u_long, caddr_t);
307 static void bce_watchdog (struct ifnet *);
308 static int bce_ifmedia_upd (struct ifnet *);
309 static void bce_ifmedia_sts (struct ifnet *, struct ifmediareq *);
310 static void bce_init_locked (struct bce_softc *);
311 static void bce_init (void *);
313 static void bce_init_context (struct bce_softc *);
314 static void bce_get_mac_addr (struct bce_softc *);
315 static void bce_set_mac_addr (struct bce_softc *);
316 static void bce_phy_intr (struct bce_softc *);
317 static void bce_rx_intr (struct bce_softc *);
318 static void bce_tx_intr (struct bce_softc *);
319 static void bce_disable_intr (struct bce_softc *);
320 static void bce_enable_intr (struct bce_softc *);
322 #ifdef DEVICE_POLLING
323 static void bce_poll_locked (struct ifnet *, enum poll_cmd, int);
324 static void bce_poll (struct ifnet *, enum poll_cmd, int);
326 static void bce_intr (void *);
327 static void bce_set_rx_mode (struct bce_softc *);
328 static void bce_stats_update (struct bce_softc *);
329 static void bce_tick_locked (struct bce_softc *);
330 static void bce_tick (void *);
331 static void bce_add_sysctls (struct bce_softc *);
334 /****************************************************************************/
335 /* FreeBSD device dispatch table. */
336 /****************************************************************************/
337 static device_method_t bce_methods[] = {
338 /* Device interface */
339 DEVMETHOD(device_probe, bce_probe),
340 DEVMETHOD(device_attach, bce_attach),
341 DEVMETHOD(device_detach, bce_detach),
342 DEVMETHOD(device_shutdown, bce_shutdown),
345 DEVMETHOD(bus_print_child, bus_generic_print_child),
346 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
349 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
350 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
351 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
356 static driver_t bce_driver = {
359 sizeof(struct bce_softc)
362 static devclass_t bce_devclass;
364 MODULE_DEPEND(bce, pci, 1, 1, 1);
365 MODULE_DEPEND(bce, ether, 1, 1, 1);
366 MODULE_DEPEND(bce, miibus, 1, 1, 1);
368 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
369 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
372 /****************************************************************************/
373 /* Device probe function. */
375 /* Compares the device to the driver's list of supported devices and */
376 /* reports back to the OS whether this is the right driver for the device. */
379 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
380 /****************************************************************************/
382 bce_probe(device_t dev)
385 struct bce_softc *sc;
387 u16 vid = 0, did = 0, svid = 0, sdid = 0;
391 sc = device_get_softc(dev);
392 bzero(sc, sizeof(struct bce_softc));
393 sc->bce_unit = device_get_unit(dev);
396 /* Get the data for the device to be probed. */
397 vid = pci_get_vendor(dev);
398 did = pci_get_device(dev);
399 svid = pci_get_subvendor(dev);
400 sdid = pci_get_subdevice(dev);
402 DBPRINT(sc, BCE_VERBOSE_LOAD,
403 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
404 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
406 /* Look through the list of known devices for a match. */
407 while(t->bce_name != NULL) {
409 if ((vid == t->bce_vid) && (did == t->bce_did) &&
410 ((svid == t->bce_svid) || (t->bce_svid == PCI_ANY_ID)) &&
411 ((sdid == t->bce_sdid) || (t->bce_sdid == PCI_ANY_ID))) {
413 descbuf = malloc(BCE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
418 /* Print out the device identity. */
419 snprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d), %s",
421 (((pci_read_config(dev, PCIR_REVID, 4) & 0xf0) >> 4) + 'A'),
422 (pci_read_config(dev, PCIR_REVID, 4) & 0xf),
425 device_set_desc_copy(dev, descbuf);
426 free(descbuf, M_TEMP);
427 return(BUS_PROBE_DEFAULT);
432 DBPRINT(sc, BCE_VERBOSE_LOAD, "%s(%d): No IOCTL match found!\n",
439 /****************************************************************************/
440 /* Device attach function. */
442 /* Allocates device resources, performs secondary chip identification, */
443 /* resets and initializes the hardware, and initializes driver instance */
447 /* 0 on success, positive value on failure. */
448 /****************************************************************************/
450 bce_attach(device_t dev)
452 struct bce_softc *sc;
455 int mbuf, rid, rc = 0;
457 sc = device_get_softc(dev);
460 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
462 mbuf = device_get_unit(dev);
465 pci_enable_busmaster(dev);
467 /* Allocate PCI memory resources. */
469 sc->bce_res = bus_alloc_resource_any(
471 SYS_RES_MEMORY, /* type */
473 RF_ACTIVE | PCI_RF_DENSE); /* flags */
475 if (sc->bce_res == NULL) {
476 BCE_PRINTF(sc, "%s(%d): PCI memory allocation failed\n",
479 goto bce_attach_fail;
482 /* Get various resource handles. */
483 sc->bce_btag = rman_get_bustag(sc->bce_res);
484 sc->bce_bhandle = rman_get_bushandle(sc->bce_res);
485 sc->bce_vhandle = (vm_offset_t) rman_get_virtual(sc->bce_res);
487 /* Allocate PCI IRQ resources. */
489 sc->bce_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
490 RF_SHAREABLE | RF_ACTIVE);
492 if (sc->bce_irq == NULL) {
493 BCE_PRINTF(sc, "%s(%d): PCI map interrupt failed\n",
496 goto bce_attach_fail;
499 /* Initialize mutex for the current device instance. */
500 BCE_LOCK_INIT(sc, device_get_nameunit(dev));
503 * Configure byte swap and enable indirect register access.
504 * Rely on CPU to do target byte swapping on big endian systems.
505 * Access to registers outside of PCI configurtion space are not
506 * valid until this is done.
508 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
509 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
510 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
512 /* Save ASIC revsion info. */
513 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
515 /* Weed out any non-production controller revisions. */
516 switch(BCE_CHIP_ID(sc)) {
517 case BCE_CHIP_ID_5706_A0:
518 case BCE_CHIP_ID_5706_A1:
519 case BCE_CHIP_ID_5708_A0:
520 case BCE_CHIP_ID_5708_B0:
521 BCE_PRINTF(sc, "%s(%d): Unsupported controller revision (%c%d)!\n",
523 (((pci_read_config(dev, PCIR_REVID, 4) & 0xf0) >> 4) + 'A'),
524 (pci_read_config(dev, PCIR_REVID, 4) & 0xf));
526 goto bce_attach_fail;
529 if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
530 BCE_PRINTF(sc, "%s(%d): SerDes controllers are not supported!\n",
533 goto bce_attach_fail;
537 * The embedded PCIe to PCI-X bridge (EPB)
538 * in the 5708 cannot address memory above
539 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
541 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
542 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
544 sc->max_bus_addr = BUS_SPACE_MAXADDR;
547 * Find the base address for shared memory access.
548 * Newer versions of bootcode use a signature and offset
549 * while older versions use a fixed address.
551 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
552 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
553 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0);
555 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
557 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
559 /* Set initial device and PHY flags */
561 sc->bce_phy_flags = 0;
563 /* Get PCI bus information (speed and type). */
564 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
565 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
568 sc->bce_flags |= BCE_PCIX_FLAG;
570 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS);
572 clkreg &= BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
574 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
575 sc->bus_speed_mhz = 133;
578 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
579 sc->bus_speed_mhz = 100;
582 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
583 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
584 sc->bus_speed_mhz = 66;
587 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
588 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
589 sc->bus_speed_mhz = 50;
592 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
593 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
594 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
595 sc->bus_speed_mhz = 33;
599 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
600 sc->bus_speed_mhz = 66;
602 sc->bus_speed_mhz = 33;
605 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
606 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
608 BCE_PRINTF(sc, "ASIC ID 0x%08X; Revision (%c%d); PCI%s %s %dMHz\n",
610 ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
611 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4),
612 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
613 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
616 /* Reset the controller. */
617 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
619 goto bce_attach_fail;
622 /* Initialize the controller. */
623 if (bce_chipinit(sc)) {
624 BCE_PRINTF(sc, "%s(%d): Controller initialization failed!\n",
627 goto bce_attach_fail;
630 /* Perform NVRAM test. */
631 if (bce_nvram_test(sc)) {
632 BCE_PRINTF(sc, "%s(%d): NVRAM test failed!\n",
635 goto bce_attach_fail;
638 /* Fetch the permanent Ethernet MAC address. */
639 bce_get_mac_addr(sc);
642 * Trip points control how many BDs
643 * should be ready before generating an
644 * interrupt while ticks control how long
645 * a BD can sit in the chain before
646 * generating an interrupt. Set the default
647 * values for the RX and TX rings.
651 /* Force more frequent interrupts. */
652 sc->bce_tx_quick_cons_trip_int = 1;
653 sc->bce_tx_quick_cons_trip = 1;
654 sc->bce_tx_ticks_int = 0;
655 sc->bce_tx_ticks = 0;
657 sc->bce_rx_quick_cons_trip_int = 1;
658 sc->bce_rx_quick_cons_trip = 1;
659 sc->bce_rx_ticks_int = 0;
660 sc->bce_rx_ticks = 0;
662 sc->bce_tx_quick_cons_trip_int = 20;
663 sc->bce_tx_quick_cons_trip = 20;
664 sc->bce_tx_ticks_int = 80;
665 sc->bce_tx_ticks = 80;
667 sc->bce_rx_quick_cons_trip_int = 6;
668 sc->bce_rx_quick_cons_trip = 6;
669 sc->bce_rx_ticks_int = 18;
670 sc->bce_rx_ticks = 18;
673 /* Update statistics once every second. */
674 sc->bce_stats_ticks = 1000000 & 0xffff00;
677 * The copper based NetXtreme II controllers
678 * use an integrated PHY at address 1 while
679 * the SerDes controllers use a PHY at
682 sc->bce_phy_addr = 1;
684 if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
685 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
686 sc->bce_flags |= BCE_NO_WOL_FLAG;
687 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708) {
688 sc->bce_phy_addr = 2;
689 val = REG_RD_IND(sc, sc->bce_shmem_base +
690 BCE_SHARED_HW_CFG_CONFIG);
691 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
692 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
696 /* Allocate DMA memory resources. */
697 if (bce_dma_alloc(dev)) {
698 BCE_PRINTF(sc, "%s(%d): DMA resource allocation failed!\n",
701 goto bce_attach_fail;
704 /* Allocate an ifnet structure. */
705 ifp = sc->bce_ifp = if_alloc(IFT_ETHER);
707 BCE_PRINTF(sc, "%s(%d): Interface allocation failed!\n",
710 goto bce_attach_fail;
713 /* Initialize the ifnet interface. */
715 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
716 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
717 ifp->if_ioctl = bce_ioctl;
718 ifp->if_start = bce_start;
720 ifp->if_watchdog = bce_watchdog;
721 ifp->if_init = bce_init;
722 ifp->if_mtu = ETHERMTU;
723 ifp->if_hwassist = BCE_IF_HWASSIST;
724 ifp->if_capabilities = BCE_IF_CAPABILITIES;
725 ifp->if_capenable = ifp->if_capabilities;
727 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
728 sc->mbuf_alloc_size = MCLBYTES;
729 #ifdef DEVICE_POLLING
730 ifp->if_capabilities |= IFCAP_POLLING;
733 ifp->if_snd.ifq_drv_maxlen = USABLE_TX_BD;
734 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
735 ifp->if_baudrate = IF_Gbps(2.5);
737 ifp->if_baudrate = IF_Gbps(1);
739 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
740 IFQ_SET_READY(&ifp->if_snd);
742 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
743 BCE_PRINTF(sc, "%s(%d): SerDes is not supported by this driver!\n",
746 goto bce_attach_fail;
748 /* Look for our PHY. */
749 if (mii_phy_probe(dev, &sc->bce_miibus, bce_ifmedia_upd,
751 BCE_PRINTF(sc, "%s(%d): PHY probe failed!\n",
754 goto bce_attach_fail;
758 /* Attach to the Ethernet interface list. */
759 ether_ifattach(ifp, sc->eaddr);
761 #if __FreeBSD_version < 500000
762 callout_init(&sc->bce_stat_ch);
764 callout_init(&sc->bce_stat_ch, CALLOUT_MPSAFE);
767 /* Hookup IRQ last. */
768 rc = bus_setup_intr(dev, sc->bce_irq, INTR_TYPE_NET | INTR_MPSAFE,
769 bce_intr, sc, &sc->bce_intrhand);
772 BCE_PRINTF(sc, "%s(%d): Failed to setup IRQ!\n",
775 goto bce_attach_exit;
778 /* Print some important debugging info. */
779 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
781 /* Add the supported sysctls to the kernel. */
784 goto bce_attach_exit;
787 bce_release_resources(sc);
791 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
797 /****************************************************************************/
798 /* Device detach function. */
800 /* Stops the controller, resets the controller, and releases resources. */
803 /* 0 on success, positive value on failure. */
804 /****************************************************************************/
806 bce_detach(device_t dev)
808 struct bce_softc *sc;
811 sc = device_get_softc(dev);
813 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
817 #ifdef DEVICE_POLLING
818 if (ifp->if_capenable & IFCAP_POLLING)
819 ether_poll_deregister(ifp);
822 /* Stop and reset the controller. */
825 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
830 /* If we have a child device on the MII bus remove it too. */
831 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
832 ifmedia_removeall(&sc->bce_ifmedia);
834 bus_generic_detach(dev);
835 device_delete_child(dev, sc->bce_miibus);
838 /* Release all remaining resources. */
839 bce_release_resources(sc);
841 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
847 /****************************************************************************/
848 /* Device shutdown function. */
850 /* Stops and resets the controller. */
854 /****************************************************************************/
856 bce_shutdown(device_t dev)
858 struct bce_softc *sc = device_get_softc(dev);
862 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
867 /****************************************************************************/
868 /* Indirect register read. */
870 /* Reads NetXtreme II registers using an index/data register pair in PCI */
871 /* configuration space. Using this mechanism avoids issues with posted */
872 /* reads but is much slower than memory-mapped I/O. */
875 /* The value of the register. */
876 /****************************************************************************/
878 bce_reg_rd_ind(struct bce_softc *sc, u32 offset)
883 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
887 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
888 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
889 __FUNCTION__, offset, val);
893 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
898 /****************************************************************************/
899 /* Indirect register write. */
901 /* Writes NetXtreme II registers using an index/data register pair in PCI */
902 /* configuration space. Using this mechanism avoids issues with posted */
903 /* writes but is muchh slower than memory-mapped I/O. */
907 /****************************************************************************/
909 bce_reg_wr_ind(struct bce_softc *sc, u32 offset, u32 val)
914 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
915 __FUNCTION__, offset, val);
917 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
918 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
922 /****************************************************************************/
923 /* Context memory write. */
925 /* The NetXtreme II controller uses context memory to track connection */
926 /* information for L2 and higher network protocols. */
930 /****************************************************************************/
932 bce_ctx_wr(struct bce_softc *sc, u32 cid_addr, u32 offset, u32 val)
935 DBPRINT(sc, BCE_EXCESSIVE, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
936 "val = 0x%08X\n", __FUNCTION__, cid_addr, offset, val);
939 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
940 REG_WR(sc, BCE_CTX_DATA, val);
944 /****************************************************************************/
945 /* PHY register read. */
947 /* Implements register reads on the MII bus. */
950 /* The value of the register. */
951 /****************************************************************************/
953 bce_miibus_read_reg(device_t dev, int phy, int reg)
955 struct bce_softc *sc;
959 sc = device_get_softc(dev);
961 /* Make sure we are accessing the correct PHY address. */
962 if (phy != sc->bce_phy_addr) {
963 DBPRINT(sc, BCE_VERBOSE, "Invalid PHY address %d for PHY read!\n", phy);
967 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
968 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
969 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
971 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
972 REG_RD(sc, BCE_EMAC_MDIO_MODE);
977 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
978 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
979 BCE_EMAC_MDIO_COMM_START_BUSY;
980 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
982 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
985 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
986 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
989 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
990 val &= BCE_EMAC_MDIO_COMM_DATA;
996 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
997 BCE_PRINTF(sc, "%s(%d): Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
998 __FILE__, __LINE__, phy, reg);
1001 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1004 DBPRINT(sc, BCE_EXCESSIVE, "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1005 __FUNCTION__, phy, (u16) reg & 0xffff, (u16) val & 0xffff);
1007 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1008 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1009 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1011 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1012 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1017 return (val & 0xffff);
1022 /****************************************************************************/
1023 /* PHY register write. */
1025 /* Implements register writes on the MII bus. */
1028 /* The value of the register. */
1029 /****************************************************************************/
1031 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1033 struct bce_softc *sc;
1037 sc = device_get_softc(dev);
1039 /* Make sure we are accessing the correct PHY address. */
1040 if (phy != sc->bce_phy_addr) {
1041 DBPRINT(sc, BCE_WARN, "Invalid PHY address %d for PHY write!\n", phy);
1045 DBPRINT(sc, BCE_EXCESSIVE, "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1046 __FUNCTION__, phy, (u16) reg & 0xffff, (u16) val & 0xffff);
1048 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1049 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1050 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1052 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1053 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1058 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1059 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1060 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1061 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1063 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1066 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1067 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1073 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1074 BCE_PRINTF(sc, "%s(%d): PHY write timeout!\n",
1075 __FILE__, __LINE__);
1077 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1078 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1079 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1081 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1082 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1091 /****************************************************************************/
1092 /* MII bus status change. */
1094 /* Called by the MII bus driver when the PHY establishes link to set the */
1095 /* MAC interface registers. */
1099 /****************************************************************************/
1101 bce_miibus_statchg(device_t dev)
1103 struct bce_softc *sc;
1104 struct mii_data *mii;
1106 sc = device_get_softc(dev);
1108 mii = device_get_softc(sc->bce_miibus);
1110 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1112 /* Set MII or GMII inerface based on the speed negotiated by the PHY. */
1113 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) {
1114 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1115 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1117 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1118 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1121 /* Set half or full duplex based on the duplicity negotiated by the PHY. */
1122 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1123 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1124 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1126 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1127 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1132 /****************************************************************************/
1133 /* Acquire NVRAM lock. */
1135 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1136 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1137 /* for use by the driver. */
1140 /* 0 on success, positive value on failure. */
1141 /****************************************************************************/
1143 bce_acquire_nvram_lock(struct bce_softc *sc)
1148 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1150 /* Request access to the flash interface. */
1151 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1152 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1153 val = REG_RD(sc, BCE_NVM_SW_ARB);
1154 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1160 if (j >= NVRAM_TIMEOUT_COUNT) {
1161 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1169 /****************************************************************************/
1170 /* Release NVRAM lock. */
1172 /* When the caller is finished accessing NVRAM the lock must be released. */
1173 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1174 /* for use by the driver. */
1177 /* 0 on success, positive value on failure. */
1178 /****************************************************************************/
1180 bce_release_nvram_lock(struct bce_softc *sc)
1185 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1188 * Relinquish nvram interface.
1190 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1192 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1193 val = REG_RD(sc, BCE_NVM_SW_ARB);
1194 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1200 if (j >= NVRAM_TIMEOUT_COUNT) {
1201 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1209 #ifdef BCE_NVRAM_WRITE_SUPPORT
1210 /****************************************************************************/
1211 /* Enable NVRAM write access. */
1213 /* Before writing to NVRAM the caller must enable NVRAM writes. */
1216 /* 0 on success, positive value on failure. */
1217 /****************************************************************************/
1219 bce_enable_nvram_write(struct bce_softc *sc)
1223 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM write.\n");
1225 val = REG_RD(sc, BCE_MISC_CFG);
1226 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
1228 if (!sc->bce_flash_info->buffered) {
1231 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1232 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
1234 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1237 val = REG_RD(sc, BCE_NVM_COMMAND);
1238 if (val & BCE_NVM_COMMAND_DONE)
1242 if (j >= NVRAM_TIMEOUT_COUNT) {
1243 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
1251 /****************************************************************************/
1252 /* Disable NVRAM write access. */
1254 /* When the caller is finished writing to NVRAM write access must be */
1259 /****************************************************************************/
1261 bce_disable_nvram_write(struct bce_softc *sc)
1265 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM write.\n");
1267 val = REG_RD(sc, BCE_MISC_CFG);
1268 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
1273 /****************************************************************************/
1274 /* Enable NVRAM access. */
1276 /* Before accessing NVRAM for read or write operations the caller must */
1277 /* enabled NVRAM access. */
1281 /****************************************************************************/
1283 bce_enable_nvram_access(struct bce_softc *sc)
1287 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1289 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1290 /* Enable both bits, even on read. */
1291 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1292 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1296 /****************************************************************************/
1297 /* Disable NVRAM access. */
1299 /* When the caller is finished accessing NVRAM access must be disabled. */
1303 /****************************************************************************/
1305 bce_disable_nvram_access(struct bce_softc *sc)
1309 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1311 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1313 /* Disable both bits, even after read. */
1314 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1315 val & ~(BCE_NVM_ACCESS_ENABLE_EN |
1316 BCE_NVM_ACCESS_ENABLE_WR_EN));
1320 #ifdef BCE_NVRAM_WRITE_SUPPORT
1321 /****************************************************************************/
1322 /* Erase NVRAM page before writing. */
1324 /* Non-buffered flash parts require that a page be erased before it is */
1328 /* 0 on success, positive value on failure. */
1329 /****************************************************************************/
1331 bce_nvram_erase_page(struct bce_softc *sc, u32 offset)
1336 /* Buffered flash doesn't require an erase. */
1337 if (sc->bce_flash_info->buffered)
1340 DBPRINT(sc, BCE_VERBOSE, "Erasing NVRAM page.\n");
1342 /* Build an erase command. */
1343 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
1344 BCE_NVM_COMMAND_DOIT;
1347 * Clear the DONE bit separately, set the NVRAM adress to erase,
1348 * and issue the erase command.
1350 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1351 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1352 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1354 /* Wait for completion. */
1356 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1361 val = REG_RD(sc, BCE_NVM_COMMAND);
1362 if (val & BCE_NVM_COMMAND_DONE)
1366 if (j >= NVRAM_TIMEOUT_COUNT) {
1367 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
1373 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1376 /****************************************************************************/
1377 /* Read a dword (32 bits) from NVRAM. */
1379 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1380 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1383 /* 0 on success and the 32 bit value read, positive value on failure. */
1384 /****************************************************************************/
1386 bce_nvram_read_dword(struct bce_softc *sc, u32 offset, u8 *ret_val,
1392 /* Build the command word. */
1393 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1395 /* Calculate the offset for buffered flash. */
1396 if (sc->bce_flash_info->buffered) {
1397 offset = ((offset / sc->bce_flash_info->page_size) <<
1398 sc->bce_flash_info->page_bits) +
1399 (offset % sc->bce_flash_info->page_size);
1403 * Clear the DONE bit separately, set the address to read,
1404 * and issue the read.
1406 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1407 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1408 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1410 /* Wait for completion. */
1411 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1416 val = REG_RD(sc, BCE_NVM_COMMAND);
1417 if (val & BCE_NVM_COMMAND_DONE) {
1418 val = REG_RD(sc, BCE_NVM_READ);
1420 val = bce_be32toh(val);
1421 memcpy(ret_val, &val, 4);
1426 /* Check for errors. */
1427 if (i >= NVRAM_TIMEOUT_COUNT) {
1428 BCE_PRINTF(sc, "%s(%d): Timeout error reading NVRAM at offset 0x%08X!\n",
1429 __FILE__, __LINE__, offset);
1437 #ifdef BCE_NVRAM_WRITE_SUPPORT
1438 /****************************************************************************/
1439 /* Write a dword (32 bits) to NVRAM. */
1441 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
1442 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
1443 /* enabled NVRAM write access. */
1446 /* 0 on success, positive value on failure. */
1447 /****************************************************************************/
1449 bce_nvram_write_dword(struct bce_softc *sc, u32 offset, u8 *val,
1455 /* Build the command word. */
1456 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
1458 /* Calculate the offset for buffered flash. */
1459 if (sc->bce_flash_info->buffered) {
1460 offset = ((offset / sc->bce_flash_info->page_size) <<
1461 sc->bce_flash_info->page_bits) +
1462 (offset % sc->bce_flash_info->page_size);
1466 * Clear the DONE bit separately, convert NVRAM data to big-endian,
1467 * set the NVRAM address to write, and issue the write command
1469 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1470 memcpy(&val32, val, 4);
1471 val32 = htobe32(val32);
1472 REG_WR(sc, BCE_NVM_WRITE, val32);
1473 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1474 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1476 /* Wait for completion. */
1477 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1480 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
1483 if (j >= NVRAM_TIMEOUT_COUNT) {
1484 BCE_PRINTF(sc, "%s(%d): Timeout error writing NVRAM at offset 0x%08X\n",
1485 __FILE__, __LINE__, offset);
1491 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1494 /****************************************************************************/
1495 /* Initialize NVRAM access. */
1497 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1498 /* access that device. */
1501 /* 0 on success, positive value on failure. */
1502 /****************************************************************************/
1504 bce_init_nvram(struct bce_softc *sc)
1507 int j, entry_count, rc;
1508 struct flash_spec *flash;
1510 DBPRINT(sc,BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
1512 /* Determine the selected interface. */
1513 val = REG_RD(sc, BCE_NVM_CFG1);
1515 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1520 * Flash reconfiguration is required to support additional
1521 * NVRAM devices not directly supported in hardware.
1522 * Check if the flash interface was reconfigured
1526 if (val & 0x40000000) {
1527 /* Flash interface reconfigured by bootcode. */
1529 DBPRINT(sc,BCE_INFO_LOAD,
1530 "bce_init_nvram(): Flash WAS reconfigured.\n");
1532 for (j = 0, flash = &flash_table[0]; j < entry_count;
1534 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1535 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1536 sc->bce_flash_info = flash;
1541 /* Flash interface not yet reconfigured. */
1544 DBPRINT(sc,BCE_INFO_LOAD,
1545 "bce_init_nvram(): Flash was NOT reconfigured.\n");
1547 if (val & (1 << 23))
1548 mask = FLASH_BACKUP_STRAP_MASK;
1550 mask = FLASH_STRAP_MASK;
1552 /* Look for the matching NVRAM device configuration data. */
1553 for (j = 0, flash = &flash_table[0]; j < entry_count; j++, flash++) {
1555 /* Check if the device matches any of the known devices. */
1556 if ((val & mask) == (flash->strapping & mask)) {
1557 /* Found a device match. */
1558 sc->bce_flash_info = flash;
1560 /* Request access to the flash interface. */
1561 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
1564 /* Reconfigure the flash interface. */
1565 bce_enable_nvram_access(sc);
1566 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1567 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1568 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1569 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1570 bce_disable_nvram_access(sc);
1571 bce_release_nvram_lock(sc);
1578 /* Check if a matching device was found. */
1579 if (j == entry_count) {
1580 sc->bce_flash_info = NULL;
1581 BCE_PRINTF(sc, "%s(%d): Unknown Flash NVRAM found!\n",
1582 __FILE__, __LINE__);
1586 /* Write the flash config data to the shared memory interface. */
1587 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_SHARED_HW_CFG_CONFIG2);
1588 val &= BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1590 sc->bce_flash_size = val;
1592 sc->bce_flash_size = sc->bce_flash_info->total_size;
1594 DBPRINT(sc, BCE_INFO_LOAD, "bce_init_nvram() flash->total_size = 0x%08X\n",
1595 sc->bce_flash_info->total_size);
1597 DBPRINT(sc,BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
1603 /****************************************************************************/
1604 /* Read an arbitrary range of data from NVRAM. */
1606 /* Prepares the NVRAM interface for access and reads the requested data */
1607 /* into the supplied buffer. */
1610 /* 0 on success and the data read, positive value on failure. */
1611 /****************************************************************************/
1613 bce_nvram_read(struct bce_softc *sc, u32 offset, u8 *ret_buf,
1617 u32 cmd_flags, offset32, len32, extra;
1622 /* Request access to the flash interface. */
1623 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
1626 /* Enable access to flash interface */
1627 bce_enable_nvram_access(sc);
1640 pre_len = 4 - (offset & 3);
1642 if (pre_len >= len32) {
1644 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1647 cmd_flags = BCE_NVM_COMMAND_FIRST;
1650 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1655 memcpy(ret_buf, buf + (offset & 3), pre_len);
1663 extra = 4 - (len32 & 3);
1664 len32 = (len32 + 4) & ~3;
1671 cmd_flags = BCE_NVM_COMMAND_LAST;
1673 cmd_flags = BCE_NVM_COMMAND_FIRST |
1674 BCE_NVM_COMMAND_LAST;
1676 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1678 memcpy(ret_buf, buf, 4 - extra);
1680 else if (len32 > 0) {
1683 /* Read the first word. */
1687 cmd_flags = BCE_NVM_COMMAND_FIRST;
1689 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1691 /* Advance to the next dword. */
1696 while (len32 > 4 && rc == 0) {
1697 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1699 /* Advance to the next dword. */
1708 cmd_flags = BCE_NVM_COMMAND_LAST;
1709 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1711 memcpy(ret_buf, buf, 4 - extra);
1714 /* Disable access to flash interface and release the lock. */
1715 bce_disable_nvram_access(sc);
1716 bce_release_nvram_lock(sc);
1722 #ifdef BCE_NVRAM_WRITE_SUPPORT
1723 /****************************************************************************/
1724 /* Write an arbitrary range of data from NVRAM. */
1726 /* Prepares the NVRAM interface for write access and writes the requested */
1727 /* data from the supplied buffer. The caller is responsible for */
1728 /* calculating any appropriate CRCs. */
1731 /* 0 on success, positive value on failure. */
1732 /****************************************************************************/
1734 bce_nvram_write(struct bce_softc *sc, u32 offset, u8 *data_buf,
1737 u32 written, offset32, len32;
1738 u8 *buf, start[4], end[4];
1740 int align_start, align_end;
1745 align_start = align_end = 0;
1747 if ((align_start = (offset32 & 3))) {
1749 len32 += align_start;
1750 if ((rc = bce_nvram_read(sc, offset32, start, 4)))
1755 if ((len32 > 4) || !align_start) {
1756 align_end = 4 - (len32 & 3);
1758 if ((rc = bce_nvram_read(sc, offset32 + len32 - 4,
1765 if (align_start || align_end) {
1766 buf = malloc(len32, M_DEVBUF, M_NOWAIT);
1770 memcpy(buf, start, 4);
1773 memcpy(buf + len32 - 4, end, 4);
1775 memcpy(buf + align_start, data_buf, buf_size);
1779 while ((written < len32) && (rc == 0)) {
1780 u32 page_start, page_end, data_start, data_end;
1781 u32 addr, cmd_flags;
1783 u8 flash_buffer[264];
1785 /* Find the page_start addr */
1786 page_start = offset32 + written;
1787 page_start -= (page_start % sc->bce_flash_info->page_size);
1788 /* Find the page_end addr */
1789 page_end = page_start + sc->bce_flash_info->page_size;
1790 /* Find the data_start addr */
1791 data_start = (written == 0) ? offset32 : page_start;
1792 /* Find the data_end addr */
1793 data_end = (page_end > offset32 + len32) ?
1794 (offset32 + len32) : page_end;
1796 /* Request access to the flash interface. */
1797 if ((rc = bce_acquire_nvram_lock(sc)) != 0)
1798 goto nvram_write_end;
1800 /* Enable access to flash interface */
1801 bce_enable_nvram_access(sc);
1803 cmd_flags = BCE_NVM_COMMAND_FIRST;
1804 if (sc->bce_flash_info->buffered == 0) {
1807 /* Read the whole page into the buffer
1808 * (non-buffer flash only) */
1809 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
1810 if (j == (sc->bce_flash_info->page_size - 4)) {
1811 cmd_flags |= BCE_NVM_COMMAND_LAST;
1813 rc = bce_nvram_read_dword(sc,
1819 goto nvram_write_end;
1825 /* Enable writes to flash interface (unlock write-protect) */
1826 if ((rc = bce_enable_nvram_write(sc)) != 0)
1827 goto nvram_write_end;
1829 /* Erase the page */
1830 if ((rc = bce_nvram_erase_page(sc, page_start)) != 0)
1831 goto nvram_write_end;
1833 /* Re-enable the write again for the actual write */
1834 bce_enable_nvram_write(sc);
1836 /* Loop to write back the buffer data from page_start to
1839 if (sc->bce_flash_info->buffered == 0) {
1840 for (addr = page_start; addr < data_start;
1841 addr += 4, i += 4) {
1843 rc = bce_nvram_write_dword(sc, addr,
1844 &flash_buffer[i], cmd_flags);
1847 goto nvram_write_end;
1853 /* Loop to write the new data from data_start to data_end */
1854 for (addr = data_start; addr < data_end; addr += 4, i++) {
1855 if ((addr == page_end - 4) ||
1856 ((sc->bce_flash_info->buffered) &&
1857 (addr == data_end - 4))) {
1859 cmd_flags |= BCE_NVM_COMMAND_LAST;
1861 rc = bce_nvram_write_dword(sc, addr, buf,
1865 goto nvram_write_end;
1871 /* Loop to write back the buffer data from data_end
1873 if (sc->bce_flash_info->buffered == 0) {
1874 for (addr = data_end; addr < page_end;
1875 addr += 4, i += 4) {
1877 if (addr == page_end-4) {
1878 cmd_flags = BCE_NVM_COMMAND_LAST;
1880 rc = bce_nvram_write_dword(sc, addr,
1881 &flash_buffer[i], cmd_flags);
1884 goto nvram_write_end;
1890 /* Disable writes to flash interface (lock write-protect) */
1891 bce_disable_nvram_write(sc);
1893 /* Disable access to flash interface */
1894 bce_disable_nvram_access(sc);
1895 bce_release_nvram_lock(sc);
1897 /* Increment written */
1898 written += data_end - data_start;
1902 if (align_start || align_end)
1903 free(buf, M_DEVBUF);
1907 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1910 /****************************************************************************/
1911 /* Verifies that NVRAM is accessible and contains valid data. */
1913 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1917 /* 0 on success, positive value on failure. */
1918 /****************************************************************************/
1920 bce_nvram_test(struct bce_softc *sc)
1922 u32 buf[BCE_NVRAM_SIZE / 4];
1923 u8 *data = (u8 *) buf;
1929 * Check that the device NVRAM is valid by reading
1930 * the magic value at offset 0.
1932 if ((rc = bce_nvram_read(sc, 0, data, 4)) != 0)
1933 goto bce_nvram_test_done;
1936 magic = bce_be32toh(buf[0]);
1937 if (magic != BCE_NVRAM_MAGIC) {
1939 BCE_PRINTF(sc, "%s(%d): Invalid NVRAM magic value! Expected: 0x%08X, "
1941 __FILE__, __LINE__, BCE_NVRAM_MAGIC, magic);
1942 goto bce_nvram_test_done;
1946 * Verify that the device NVRAM includes valid
1947 * configuration data.
1949 if ((rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE)) != 0)
1950 goto bce_nvram_test_done;
1952 csum = ether_crc32_le(data, 0x100);
1953 if (csum != BCE_CRC32_RESIDUAL) {
1955 BCE_PRINTF(sc, "%s(%d): Invalid Manufacturing Information NVRAM CRC! "
1956 "Expected: 0x%08X, Found: 0x%08X\n",
1957 __FILE__, __LINE__, BCE_CRC32_RESIDUAL, csum);
1958 goto bce_nvram_test_done;
1961 csum = ether_crc32_le(data + 0x100, 0x100);
1962 if (csum != BCE_CRC32_RESIDUAL) {
1963 BCE_PRINTF(sc, "%s(%d): Invalid Feature Configuration Information "
1964 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1965 __FILE__, __LINE__, BCE_CRC32_RESIDUAL, csum);
1969 bce_nvram_test_done:
1974 /****************************************************************************/
1975 /* Free any DMA memory owned by the driver. */
1977 /* Scans through each data structre that requires DMA memory and frees */
1978 /* the memory if allocated. */
1982 /****************************************************************************/
1984 bce_dma_free(struct bce_softc *sc)
1988 DBPRINT(sc,BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
1990 /* Destroy the status block. */
1991 if (sc->status_block != NULL)
1997 if (sc->status_map != NULL) {
2001 bus_dmamap_destroy(sc->status_tag,
2005 if (sc->status_tag != NULL)
2006 bus_dma_tag_destroy(sc->status_tag);
2009 /* Destroy the statistics block. */
2010 if (sc->stats_block != NULL)
2016 if (sc->stats_map != NULL) {
2020 bus_dmamap_destroy(sc->stats_tag,
2024 if (sc->stats_tag != NULL)
2025 bus_dma_tag_destroy(sc->stats_tag);
2028 /* Free, unmap and destroy all TX buffer descriptor chain pages. */
2029 for (i = 0; i < TX_PAGES; i++ ) {
2030 if (sc->tx_bd_chain[i] != NULL)
2032 sc->tx_bd_chain_tag,
2034 sc->tx_bd_chain_map[i]);
2036 if (sc->tx_bd_chain_map[i] != NULL) {
2038 sc->tx_bd_chain_tag,
2039 sc->tx_bd_chain_map[i]);
2041 sc->tx_bd_chain_tag,
2042 sc->tx_bd_chain_map[i]);
2047 /* Destroy the TX buffer descriptor tag. */
2048 if (sc->tx_bd_chain_tag != NULL)
2049 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2052 /* Free, unmap and destroy all RX buffer descriptor chain pages. */
2053 for (i = 0; i < RX_PAGES; i++ ) {
2054 if (sc->rx_bd_chain[i] != NULL)
2056 sc->rx_bd_chain_tag,
2058 sc->rx_bd_chain_map[i]);
2060 if (sc->rx_bd_chain_map[i] != NULL) {
2062 sc->rx_bd_chain_tag,
2063 sc->rx_bd_chain_map[i]);
2065 sc->rx_bd_chain_tag,
2066 sc->rx_bd_chain_map[i]);
2070 /* Destroy the RX buffer descriptor tag. */
2071 if (sc->rx_bd_chain_tag != NULL)
2072 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2075 /* Unload and destroy the TX mbuf maps. */
2076 for (i = 0; i < TOTAL_TX_BD; i++) {
2077 if (sc->tx_mbuf_map[i] != NULL) {
2078 bus_dmamap_unload(sc->tx_mbuf_tag,
2079 sc->tx_mbuf_map[i]);
2080 bus_dmamap_destroy(sc->tx_mbuf_tag,
2081 sc->tx_mbuf_map[i]);
2085 /* Destroy the TX mbuf tag. */
2086 if (sc->tx_mbuf_tag != NULL)
2087 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2090 /* Unload and destroy the RX mbuf maps. */
2091 for (i = 0; i < TOTAL_RX_BD; i++) {
2092 if (sc->rx_mbuf_map[i] != NULL) {
2093 bus_dmamap_unload(sc->rx_mbuf_tag,
2094 sc->rx_mbuf_map[i]);
2095 bus_dmamap_destroy(sc->rx_mbuf_tag,
2096 sc->rx_mbuf_map[i]);
2100 /* Destroy the RX mbuf tag. */
2101 if (sc->rx_mbuf_tag != NULL)
2102 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2105 /* Destroy the parent tag */
2106 if (sc->parent_tag != NULL)
2107 bus_dma_tag_destroy(sc->parent_tag);
2109 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
2114 /****************************************************************************/
2115 /* Get DMA memory from the OS. */
2117 /* Validates that the OS has provided DMA buffers in response to a */
2118 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2119 /* When the callback is used the OS will return 0 for the mapping function */
2120 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2121 /* failures back to the caller. */
2125 /****************************************************************************/
2127 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2129 struct bce_dmamap_arg *map_arg = arg;
2130 struct bce_softc *sc = map_arg->sc;
2132 /* Simulate a mapping failure. */
2133 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2134 BCE_PRINTF(sc, "%s(%d): Simulating DMA mapping error.\n",
2135 __FILE__, __LINE__);
2138 /* Check for an error and signal the caller that an error occurred. */
2139 if (error || (nseg > map_arg->maxsegs)) {
2140 BCE_PRINTF(sc, "%s(%d): DMA mapping error! error = %d, "
2141 "nseg = %d, maxsegs = %d\n",
2142 __FILE__, __LINE__, error, nseg, map_arg->maxsegs);
2143 map_arg->maxsegs = 0;
2144 goto bce_dma_map_addr_exit;
2147 map_arg->busaddr = segs->ds_addr;
2149 bce_dma_map_addr_exit:
2154 /****************************************************************************/
2155 /* Map TX buffers into TX buffer descriptors. */
2157 /* Given a series of DMA memory containting an outgoing frame, map the */
2158 /* segments into the tx_bd structure used by the hardware. */
2162 /****************************************************************************/
2164 bce_dma_map_tx_desc(void *arg, bus_dma_segment_t *segs,
2165 int nseg, bus_size_t mapsize, int error)
2167 struct bce_dmamap_arg *map_arg;
2168 struct bce_softc *sc;
2169 struct tx_bd *txbd = NULL;
2171 u16 prod, chain_prod;
2181 DBPRINT(sc, BCE_WARN, "%s(): Called with error = %d\n",
2182 __FUNCTION__, error);
2186 /* Signal error to caller if there's too many segments */
2187 if (nseg > map_arg->maxsegs) {
2188 DBPRINT(sc, BCE_WARN,
2189 "%s(): Mapped TX descriptors: max segs = %d, "
2190 "actual segs = %d\n",
2191 __FUNCTION__, map_arg->maxsegs, nseg);
2193 map_arg->maxsegs = 0;
2197 /* prod points to an empty tx_bd at this point. */
2198 prod = map_arg->prod;
2199 chain_prod = map_arg->chain_prod;
2200 prod_bseq = map_arg->prod_bseq;
2203 debug_prod = chain_prod;
2206 DBPRINT(sc, BCE_INFO_SEND,
2207 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
2208 "prod_bseq = 0x%08X\n",
2209 __FUNCTION__, prod, chain_prod, prod_bseq);
2212 * Cycle through each mbuf segment that makes up
2213 * the outgoing frame, gathering the mapping info
2214 * for that segment and creating a tx_bd to for
2218 txbd = &map_arg->tx_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
2220 /* Setup the first tx_bd for the first segment. */
2221 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
2222 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
2223 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
2224 txbd->tx_bd_vlan_tag_flags = htole16(map_arg->tx_flags |
2226 prod_bseq += segs[i].ds_len;
2228 /* Setup any remaing segments. */
2229 for (i = 1; i < nseg; i++) {
2230 prod = NEXT_TX_BD(prod);
2231 chain_prod = TX_CHAIN_IDX(prod);
2233 txbd = &map_arg->tx_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
2235 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
2236 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
2237 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
2238 txbd->tx_bd_vlan_tag_flags = htole16(map_arg->tx_flags);
2240 prod_bseq += segs[i].ds_len;
2243 /* Set the END flag on the last TX buffer descriptor. */
2244 txbd->tx_bd_vlan_tag_flags |= htole16(TX_BD_FLAGS_END);
2246 DBRUN(BCE_INFO_SEND, bce_dump_tx_chain(sc, debug_prod, nseg));
2248 DBPRINT(sc, BCE_INFO_SEND,
2249 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
2250 "prod_bseq = 0x%08X\n",
2251 __FUNCTION__, prod, chain_prod, prod_bseq);
2253 /* prod points to the last tx_bd at this point. */
2254 map_arg->maxsegs = nseg;
2255 map_arg->prod = prod;
2256 map_arg->chain_prod = chain_prod;
2257 map_arg->prod_bseq = prod_bseq;
2261 /****************************************************************************/
2262 /* Allocate any DMA memory needed by the driver. */
2264 /* Allocates DMA memory needed for the various global structures needed by */
2268 /* 0 for success, positive value for failure. */
2269 /****************************************************************************/
2271 bce_dma_alloc(device_t dev)
2273 struct bce_softc *sc;
2274 int i, error, rc = 0;
2275 struct bce_dmamap_arg map_arg;
2277 sc = device_get_softc(dev);
2279 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
2282 * Allocate the parent bus DMA tag appropriate for PCI.
2284 if (bus_dma_tag_create(NULL, /* parent */
2285 BCE_DMA_ALIGN, /* alignment */
2286 BCE_DMA_BOUNDARY, /* boundary */
2287 sc->max_bus_addr, /* lowaddr */
2288 BUS_SPACE_MAXADDR, /* highaddr */
2289 NULL, /* filterfunc */
2290 NULL, /* filterarg */
2291 MAXBSIZE, /* maxsize */
2292 BUS_SPACE_UNRESTRICTED, /* nsegments */
2293 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
2298 BCE_PRINTF(sc, "%s(%d): Could not allocate parent DMA tag!\n",
2299 __FILE__, __LINE__);
2301 goto bce_dma_alloc_exit;
2305 * Create a DMA tag for the status block, allocate and clear the
2306 * memory, map the memory into DMA space, and fetch the physical
2307 * address of the block.
2309 if (bus_dma_tag_create(
2310 sc->parent_tag, /* parent */
2311 BCE_DMA_ALIGN, /* alignment */
2312 BCE_DMA_BOUNDARY, /* boundary */
2313 sc->max_bus_addr, /* lowaddr */
2314 BUS_SPACE_MAXADDR, /* highaddr */
2315 NULL, /* filterfunc */
2316 NULL, /* filterarg */
2317 BCE_STATUS_BLK_SZ, /* maxsize */
2319 BCE_STATUS_BLK_SZ, /* maxsegsize */
2321 NULL, /* lockfunc */
2324 BCE_PRINTF(sc, "%s(%d): Could not allocate status block DMA tag!\n",
2325 __FILE__, __LINE__);
2327 goto bce_dma_alloc_exit;
2330 if(bus_dmamem_alloc(
2331 sc->status_tag, /* dmat */
2332 (void **)&sc->status_block, /* vaddr */
2333 BUS_DMA_NOWAIT, /* flags */
2335 BCE_PRINTF(sc, "%s(%d): Could not allocate status block DMA memory!\n",
2336 __FILE__, __LINE__);
2338 goto bce_dma_alloc_exit;
2341 bzero((char *)sc->status_block, BCE_STATUS_BLK_SZ);
2344 map_arg.maxsegs = 1;
2346 error = bus_dmamap_load(
2347 sc->status_tag, /* dmat */
2348 sc->status_map, /* map */
2349 sc->status_block, /* buf */
2350 BCE_STATUS_BLK_SZ, /* buflen */
2351 bce_dma_map_addr, /* callback */
2352 &map_arg, /* callbackarg */
2353 BUS_DMA_NOWAIT); /* flags */
2355 if(error || (map_arg.maxsegs == 0)) {
2356 BCE_PRINTF(sc, "%s(%d): Could not map status block DMA memory!\n",
2357 __FILE__, __LINE__);
2359 goto bce_dma_alloc_exit;
2362 sc->status_block_paddr = map_arg.busaddr;
2363 /* DRC - Fix for 64 bit addresses. */
2364 DBPRINT(sc, BCE_INFO, "status_block_paddr = 0x%08X\n",
2365 (u32) sc->status_block_paddr);
2368 * Create a DMA tag for the statistics block, allocate and clear the
2369 * memory, map the memory into DMA space, and fetch the physical
2370 * address of the block.
2372 if (bus_dma_tag_create(
2373 sc->parent_tag, /* parent */
2374 BCE_DMA_ALIGN, /* alignment */
2375 BCE_DMA_BOUNDARY, /* boundary */
2376 sc->max_bus_addr, /* lowaddr */
2377 BUS_SPACE_MAXADDR, /* highaddr */
2378 NULL, /* filterfunc */
2379 NULL, /* filterarg */
2380 BCE_STATS_BLK_SZ, /* maxsize */
2382 BCE_STATS_BLK_SZ, /* maxsegsize */
2384 NULL, /* lockfunc */
2387 BCE_PRINTF(sc, "%s(%d): Could not allocate statistics block DMA tag!\n",
2388 __FILE__, __LINE__);
2390 goto bce_dma_alloc_exit;
2393 if (bus_dmamem_alloc(
2394 sc->stats_tag, /* dmat */
2395 (void **)&sc->stats_block, /* vaddr */
2396 BUS_DMA_NOWAIT, /* flags */
2398 BCE_PRINTF(sc, "%s(%d): Could not allocate statistics block DMA memory!\n",
2399 __FILE__, __LINE__);
2401 goto bce_dma_alloc_exit;
2404 bzero((char *)sc->stats_block, BCE_STATS_BLK_SZ);
2407 map_arg.maxsegs = 1;
2409 error = bus_dmamap_load(
2410 sc->stats_tag, /* dmat */
2411 sc->stats_map, /* map */
2412 sc->stats_block, /* buf */
2413 BCE_STATS_BLK_SZ, /* buflen */
2414 bce_dma_map_addr, /* callback */
2415 &map_arg, /* callbackarg */
2416 BUS_DMA_NOWAIT); /* flags */
2418 if(error || (map_arg.maxsegs == 0)) {
2419 BCE_PRINTF(sc, "%s(%d): Could not map statistics block DMA memory!\n",
2420 __FILE__, __LINE__);
2422 goto bce_dma_alloc_exit;
2425 sc->stats_block_paddr = map_arg.busaddr;
2426 /* DRC - Fix for 64 bit address. */
2427 DBPRINT(sc,BCE_INFO, "stats_block_paddr = 0x%08X\n",
2428 (u32) sc->stats_block_paddr);
2431 * Create a DMA tag for the TX buffer descriptor chain,
2432 * allocate and clear the memory, and fetch the
2433 * physical address of the block.
2435 if(bus_dma_tag_create(
2436 sc->parent_tag, /* parent */
2437 BCM_PAGE_SIZE, /* alignment */
2438 BCE_DMA_BOUNDARY, /* boundary */
2439 sc->max_bus_addr, /* lowaddr */
2440 BUS_SPACE_MAXADDR, /* highaddr */
2441 NULL, /* filterfunc */
2442 NULL, /* filterarg */
2443 BCE_TX_CHAIN_PAGE_SZ, /* maxsize */
2445 BCE_TX_CHAIN_PAGE_SZ, /* maxsegsize */
2447 NULL, /* lockfunc */
2449 &sc->tx_bd_chain_tag)) {
2450 BCE_PRINTF(sc, "%s(%d): Could not allocate TX descriptor chain DMA tag!\n",
2451 __FILE__, __LINE__);
2453 goto bce_dma_alloc_exit;
2456 for (i = 0; i < TX_PAGES; i++) {
2458 if(bus_dmamem_alloc(
2459 sc->tx_bd_chain_tag, /* tag */
2460 (void **)&sc->tx_bd_chain[i], /* vaddr */
2461 BUS_DMA_NOWAIT, /* flags */
2462 &sc->tx_bd_chain_map[i])) {
2463 BCE_PRINTF(sc, "%s(%d): Could not allocate TX descriptor "
2464 "chain DMA memory!\n", __FILE__, __LINE__);
2466 goto bce_dma_alloc_exit;
2469 map_arg.maxsegs = 1;
2472 error = bus_dmamap_load(
2473 sc->tx_bd_chain_tag, /* dmat */
2474 sc->tx_bd_chain_map[i], /* map */
2475 sc->tx_bd_chain[i], /* buf */
2476 BCE_TX_CHAIN_PAGE_SZ, /* buflen */
2477 bce_dma_map_addr, /* callback */
2478 &map_arg, /* callbackarg */
2479 BUS_DMA_NOWAIT); /* flags */
2481 if(error || (map_arg.maxsegs == 0)) {
2482 BCE_PRINTF(sc, "%s(%d): Could not map TX descriptor chain DMA memory!\n",
2483 __FILE__, __LINE__);
2485 goto bce_dma_alloc_exit;
2488 sc->tx_bd_chain_paddr[i] = map_arg.busaddr;
2489 /* DRC - Fix for 64 bit systems. */
2490 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2491 i, (u32) sc->tx_bd_chain_paddr[i]);
2494 /* Create a DMA tag for TX mbufs. */
2495 if (bus_dma_tag_create(
2496 sc->parent_tag, /* parent */
2497 BCE_DMA_ALIGN, /* alignment */
2498 BCE_DMA_BOUNDARY, /* boundary */
2499 sc->max_bus_addr, /* lowaddr */
2500 BUS_SPACE_MAXADDR, /* highaddr */
2501 NULL, /* filterfunc */
2502 NULL, /* filterarg */
2503 MCLBYTES * BCE_MAX_SEGMENTS, /* maxsize */
2504 BCE_MAX_SEGMENTS, /* nsegments */
2505 MCLBYTES, /* maxsegsize */
2507 NULL, /* lockfunc */
2509 &sc->tx_mbuf_tag)) {
2510 BCE_PRINTF(sc, "%s(%d): Could not allocate TX mbuf DMA tag!\n",
2511 __FILE__, __LINE__);
2513 goto bce_dma_alloc_exit;
2516 /* Create DMA maps for the TX mbufs clusters. */
2517 for (i = 0; i < TOTAL_TX_BD; i++) {
2518 if (bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_NOWAIT,
2519 &sc->tx_mbuf_map[i])) {
2520 BCE_PRINTF(sc, "%s(%d): Unable to create TX mbuf DMA map!\n",
2521 __FILE__, __LINE__);
2523 goto bce_dma_alloc_exit;
2528 * Create a DMA tag for the RX buffer descriptor chain,
2529 * allocate and clear the memory, and fetch the physical
2530 * address of the blocks.
2532 if (bus_dma_tag_create(
2533 sc->parent_tag, /* parent */
2534 BCM_PAGE_SIZE, /* alignment */
2535 BCE_DMA_BOUNDARY, /* boundary */
2536 BUS_SPACE_MAXADDR, /* lowaddr */
2537 sc->max_bus_addr, /* lowaddr */
2539 NULL, /* filterarg */
2540 BCE_RX_CHAIN_PAGE_SZ, /* maxsize */
2542 BCE_RX_CHAIN_PAGE_SZ, /* maxsegsize */
2544 NULL, /* lockfunc */
2546 &sc->rx_bd_chain_tag)) {
2547 BCE_PRINTF(sc, "%s(%d): Could not allocate RX descriptor chain DMA tag!\n",
2548 __FILE__, __LINE__);
2550 goto bce_dma_alloc_exit;
2553 for (i = 0; i < RX_PAGES; i++) {
2555 if (bus_dmamem_alloc(
2556 sc->rx_bd_chain_tag, /* tag */
2557 (void **)&sc->rx_bd_chain[i], /* vaddr */
2558 BUS_DMA_NOWAIT, /* flags */
2559 &sc->rx_bd_chain_map[i])) {
2560 BCE_PRINTF(sc, "%s(%d): Could not allocate RX descriptor chain "
2561 "DMA memory!\n", __FILE__, __LINE__);
2563 goto bce_dma_alloc_exit;
2566 bzero((char *)sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
2568 map_arg.maxsegs = 1;
2571 error = bus_dmamap_load(
2572 sc->rx_bd_chain_tag, /* dmat */
2573 sc->rx_bd_chain_map[i], /* map */
2574 sc->rx_bd_chain[i], /* buf */
2575 BCE_RX_CHAIN_PAGE_SZ, /* buflen */
2576 bce_dma_map_addr, /* callback */
2577 &map_arg, /* callbackarg */
2578 BUS_DMA_NOWAIT); /* flags */
2580 if(error || (map_arg.maxsegs == 0)) {
2581 BCE_PRINTF(sc, "%s(%d): Could not map RX descriptor chain DMA memory!\n",
2582 __FILE__, __LINE__);
2584 goto bce_dma_alloc_exit;
2587 sc->rx_bd_chain_paddr[i] = map_arg.busaddr;
2588 /* DRC - Fix for 64 bit systems. */
2589 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2590 i, (u32) sc->rx_bd_chain_paddr[i]);
2594 * Create a DMA tag for RX mbufs.
2596 if (bus_dma_tag_create(
2597 sc->parent_tag, /* parent */
2598 BCE_DMA_ALIGN, /* alignment */
2599 BCE_DMA_BOUNDARY, /* boundary */
2600 sc->max_bus_addr, /* lowaddr */
2601 BUS_SPACE_MAXADDR, /* highaddr */
2602 NULL, /* filterfunc */
2603 NULL, /* filterarg */
2604 MJUM9BYTES, /* maxsize */
2605 BCE_MAX_SEGMENTS, /* nsegments */
2606 MJUM9BYTES, /* maxsegsize */
2608 NULL, /* lockfunc */
2610 &sc->rx_mbuf_tag)) {
2611 BCE_PRINTF(sc, "%s(%d): Could not allocate RX mbuf DMA tag!\n",
2612 __FILE__, __LINE__);
2614 goto bce_dma_alloc_exit;
2617 /* Create DMA maps for the RX mbuf clusters. */
2618 for (i = 0; i < TOTAL_RX_BD; i++) {
2619 if (bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_NOWAIT,
2620 &sc->rx_mbuf_map[i])) {
2621 BCE_PRINTF(sc, "%s(%d): Unable to create RX mbuf DMA map!\n",
2622 __FILE__, __LINE__);
2624 goto bce_dma_alloc_exit;
2629 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
2635 /****************************************************************************/
2636 /* Release all resources used by the driver. */
2638 /* Releases all resources acquired by the driver including interrupts, */
2639 /* interrupt handler, interfaces, mutexes, and DMA memory. */
2643 /****************************************************************************/
2645 bce_release_resources(struct bce_softc *sc)
2649 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
2655 if (sc->bce_intrhand != NULL)
2656 bus_teardown_intr(dev, sc->bce_irq, sc->bce_intrhand);
2658 if (sc->bce_irq != NULL)
2659 bus_release_resource(dev,
2664 if (sc->bce_res != NULL)
2665 bus_release_resource(dev,
2670 if (sc->bce_ifp != NULL)
2671 if_free(sc->bce_ifp);
2674 if (mtx_initialized(&sc->bce_mtx))
2675 BCE_LOCK_DESTROY(sc);
2677 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
2682 /****************************************************************************/
2683 /* Firmware synchronization. */
2685 /* Before performing certain events such as a chip reset, synchronize with */
2686 /* the firmware first. */
2689 /* 0 for success, positive value for failure. */
2690 /****************************************************************************/
2692 bce_fw_sync(struct bce_softc *sc, u32 msg_data)
2697 /* Don't waste any time if we've timed out before. */
2698 if (sc->bce_fw_timed_out) {
2700 goto bce_fw_sync_exit;
2703 /* Increment the message sequence number. */
2704 sc->bce_fw_wr_seq++;
2705 msg_data |= sc->bce_fw_wr_seq;
2707 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2709 /* Send the message to the bootcode driver mailbox. */
2710 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2712 /* Wait for the bootcode to acknowledge the message. */
2713 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2714 /* Check for a response in the bootcode firmware mailbox. */
2715 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_FW_MB);
2716 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2721 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2722 if (((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ)) &&
2723 ((msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0)) {
2725 BCE_PRINTF(sc, "%s(%d): Firmware synchronization timeout! "
2726 "msg_data = 0x%08X\n",
2727 __FILE__, __LINE__, msg_data);
2729 msg_data &= ~BCE_DRV_MSG_CODE;
2730 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2732 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2734 sc->bce_fw_timed_out = 1;
2743 /****************************************************************************/
2744 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2748 /****************************************************************************/
2750 bce_load_rv2p_fw(struct bce_softc *sc, u32 *rv2p_code,
2751 u32 rv2p_code_len, u32 rv2p_proc)
2756 for (i = 0; i < rv2p_code_len; i += 8) {
2757 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2759 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2762 if (rv2p_proc == RV2P_PROC1) {
2763 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2764 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2767 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2768 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2772 /* Reset the processor, un-stall is done later. */
2773 if (rv2p_proc == RV2P_PROC1) {
2774 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2777 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2782 /****************************************************************************/
2783 /* Load RISC processor firmware. */
2785 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2786 /* associated with a particular processor. */
2790 /****************************************************************************/
2792 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2799 val = REG_RD_IND(sc, cpu_reg->mode);
2800 val |= cpu_reg->mode_value_halt;
2801 REG_WR_IND(sc, cpu_reg->mode, val);
2802 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2804 /* Load the Text area. */
2805 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2809 for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
2810 REG_WR_IND(sc, offset, fw->text[j]);
2814 /* Load the Data area. */
2815 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2819 for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
2820 REG_WR_IND(sc, offset, fw->data[j]);
2824 /* Load the SBSS area. */
2825 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2829 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
2830 REG_WR_IND(sc, offset, fw->sbss[j]);
2834 /* Load the BSS area. */
2835 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2839 for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
2840 REG_WR_IND(sc, offset, fw->bss[j]);
2844 /* Load the Read-Only area. */
2845 offset = cpu_reg->spad_base +
2846 (fw->rodata_addr - cpu_reg->mips_view_base);
2850 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
2851 REG_WR_IND(sc, offset, fw->rodata[j]);
2855 /* Clear the pre-fetch instruction. */
2856 REG_WR_IND(sc, cpu_reg->inst, 0);
2857 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2859 /* Start the CPU. */
2860 val = REG_RD_IND(sc, cpu_reg->mode);
2861 val &= ~cpu_reg->mode_value_halt;
2862 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2863 REG_WR_IND(sc, cpu_reg->mode, val);
2867 /****************************************************************************/
2868 /* Initialize the RV2P, RX, TX, TPAT, and COM CPUs. */
2870 /* Loads the firmware for each CPU and starts the CPU. */
2874 /****************************************************************************/
2876 bce_init_cpus(struct bce_softc *sc)
2878 struct cpu_reg cpu_reg;
2881 /* Initialize the RV2P processor. */
2882 bce_load_rv2p_fw(sc, bce_rv2p_proc1, sizeof(bce_rv2p_proc1), RV2P_PROC1);
2883 bce_load_rv2p_fw(sc, bce_rv2p_proc2, sizeof(bce_rv2p_proc2), RV2P_PROC2);
2885 /* Initialize the RX Processor. */
2886 cpu_reg.mode = BCE_RXP_CPU_MODE;
2887 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2888 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2889 cpu_reg.state = BCE_RXP_CPU_STATE;
2890 cpu_reg.state_value_clear = 0xffffff;
2891 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2892 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2893 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2894 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2895 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2896 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2897 cpu_reg.mips_view_base = 0x8000000;
2899 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2900 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2901 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2902 fw.start_addr = bce_RXP_b06FwStartAddr;
2904 fw.text_addr = bce_RXP_b06FwTextAddr;
2905 fw.text_len = bce_RXP_b06FwTextLen;
2907 fw.text = bce_RXP_b06FwText;
2909 fw.data_addr = bce_RXP_b06FwDataAddr;
2910 fw.data_len = bce_RXP_b06FwDataLen;
2912 fw.data = bce_RXP_b06FwData;
2914 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2915 fw.sbss_len = bce_RXP_b06FwSbssLen;
2917 fw.sbss = bce_RXP_b06FwSbss;
2919 fw.bss_addr = bce_RXP_b06FwBssAddr;
2920 fw.bss_len = bce_RXP_b06FwBssLen;
2922 fw.bss = bce_RXP_b06FwBss;
2924 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2925 fw.rodata_len = bce_RXP_b06FwRodataLen;
2926 fw.rodata_index = 0;
2927 fw.rodata = bce_RXP_b06FwRodata;
2929 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2930 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2932 /* Initialize the TX Processor. */
2933 cpu_reg.mode = BCE_TXP_CPU_MODE;
2934 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2935 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2936 cpu_reg.state = BCE_TXP_CPU_STATE;
2937 cpu_reg.state_value_clear = 0xffffff;
2938 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2939 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2940 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2941 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2942 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2943 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2944 cpu_reg.mips_view_base = 0x8000000;
2946 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2947 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2948 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2949 fw.start_addr = bce_TXP_b06FwStartAddr;
2951 fw.text_addr = bce_TXP_b06FwTextAddr;
2952 fw.text_len = bce_TXP_b06FwTextLen;
2954 fw.text = bce_TXP_b06FwText;
2956 fw.data_addr = bce_TXP_b06FwDataAddr;
2957 fw.data_len = bce_TXP_b06FwDataLen;
2959 fw.data = bce_TXP_b06FwData;
2961 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2962 fw.sbss_len = bce_TXP_b06FwSbssLen;
2964 fw.sbss = bce_TXP_b06FwSbss;
2966 fw.bss_addr = bce_TXP_b06FwBssAddr;
2967 fw.bss_len = bce_TXP_b06FwBssLen;
2969 fw.bss = bce_TXP_b06FwBss;
2971 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2972 fw.rodata_len = bce_TXP_b06FwRodataLen;
2973 fw.rodata_index = 0;
2974 fw.rodata = bce_TXP_b06FwRodata;
2976 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2977 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2979 /* Initialize the TX Patch-up Processor. */
2980 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2981 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2982 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2983 cpu_reg.state = BCE_TPAT_CPU_STATE;
2984 cpu_reg.state_value_clear = 0xffffff;
2985 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2986 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2987 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2988 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2989 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2990 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2991 cpu_reg.mips_view_base = 0x8000000;
2993 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2994 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2995 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2996 fw.start_addr = bce_TPAT_b06FwStartAddr;
2998 fw.text_addr = bce_TPAT_b06FwTextAddr;
2999 fw.text_len = bce_TPAT_b06FwTextLen;
3001 fw.text = bce_TPAT_b06FwText;
3003 fw.data_addr = bce_TPAT_b06FwDataAddr;
3004 fw.data_len = bce_TPAT_b06FwDataLen;
3006 fw.data = bce_TPAT_b06FwData;
3008 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
3009 fw.sbss_len = bce_TPAT_b06FwSbssLen;
3011 fw.sbss = bce_TPAT_b06FwSbss;
3013 fw.bss_addr = bce_TPAT_b06FwBssAddr;
3014 fw.bss_len = bce_TPAT_b06FwBssLen;
3016 fw.bss = bce_TPAT_b06FwBss;
3018 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
3019 fw.rodata_len = bce_TPAT_b06FwRodataLen;
3020 fw.rodata_index = 0;
3021 fw.rodata = bce_TPAT_b06FwRodata;
3023 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
3024 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3026 /* Initialize the Completion Processor. */
3027 cpu_reg.mode = BCE_COM_CPU_MODE;
3028 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3029 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3030 cpu_reg.state = BCE_COM_CPU_STATE;
3031 cpu_reg.state_value_clear = 0xffffff;
3032 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3033 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3034 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3035 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3036 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3037 cpu_reg.spad_base = BCE_COM_SCRATCH;
3038 cpu_reg.mips_view_base = 0x8000000;
3040 fw.ver_major = bce_COM_b06FwReleaseMajor;
3041 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3042 fw.ver_fix = bce_COM_b06FwReleaseFix;
3043 fw.start_addr = bce_COM_b06FwStartAddr;
3045 fw.text_addr = bce_COM_b06FwTextAddr;
3046 fw.text_len = bce_COM_b06FwTextLen;
3048 fw.text = bce_COM_b06FwText;
3050 fw.data_addr = bce_COM_b06FwDataAddr;
3051 fw.data_len = bce_COM_b06FwDataLen;
3053 fw.data = bce_COM_b06FwData;
3055 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3056 fw.sbss_len = bce_COM_b06FwSbssLen;
3058 fw.sbss = bce_COM_b06FwSbss;
3060 fw.bss_addr = bce_COM_b06FwBssAddr;
3061 fw.bss_len = bce_COM_b06FwBssLen;
3063 fw.bss = bce_COM_b06FwBss;
3065 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3066 fw.rodata_len = bce_COM_b06FwRodataLen;
3067 fw.rodata_index = 0;
3068 fw.rodata = bce_COM_b06FwRodata;
3070 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3071 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3075 /****************************************************************************/
3076 /* Initialize context memory. */
3078 /* Clears the memory associated with each Context ID (CID). */
3082 /****************************************************************************/
3084 bce_init_context(struct bce_softc *sc)
3090 u32 vcid_addr, pcid_addr, offset;
3094 vcid_addr = GET_CID_ADDR(vcid);
3095 pcid_addr = vcid_addr;
3097 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0x00);
3098 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
3100 /* Zero out the context. */
3101 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
3102 CTX_WR(sc, 0x00, offset, 0);
3105 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3106 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
3111 /****************************************************************************/
3112 /* Fetch the permanent MAC address of the controller. */
3116 /****************************************************************************/
3118 bce_get_mac_addr(struct bce_softc *sc)
3120 u32 mac_lo = 0, mac_hi = 0;
3123 * The NetXtreme II bootcode populates various NIC
3124 * power-on and runtime configuration items in a
3125 * shared memory area. The factory configured MAC
3126 * address is available from both NVRAM and the
3127 * shared memory area so we'll read the value from
3128 * shared memory for speed.
3131 mac_hi = REG_RD_IND(sc, sc->bce_shmem_base +
3132 BCE_PORT_HW_CFG_MAC_UPPER);
3133 mac_lo = REG_RD_IND(sc, sc->bce_shmem_base +
3134 BCE_PORT_HW_CFG_MAC_LOWER);
3136 if ((mac_lo == 0) && (mac_hi == 0)) {
3137 BCE_PRINTF(sc, "%s(%d): Invalid Ethernet address!\n",
3138 __FILE__, __LINE__);
3140 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3141 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3142 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3143 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3144 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3145 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3148 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3152 /****************************************************************************/
3153 /* Program the MAC address. */
3157 /****************************************************************************/
3159 bce_set_mac_addr(struct bce_softc *sc)
3162 u8 *mac_addr = sc->eaddr;
3164 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n", sc->eaddr, ":");
3166 val = (mac_addr[0] << 8) | mac_addr[1];
3168 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3170 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
3171 (mac_addr[4] << 8) | mac_addr[5];
3173 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3177 /****************************************************************************/
3178 /* Stop the controller. */
3182 /****************************************************************************/
3184 bce_stop(struct bce_softc *sc)
3187 struct ifmedia_entry *ifm;
3188 struct mii_data *mii = NULL;
3191 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3193 BCE_LOCK_ASSERT(sc);
3197 mii = device_get_softc(sc->bce_miibus);
3199 callout_stop(&sc->bce_stat_ch);
3201 /* Disable the transmit/receive blocks. */
3202 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, 0x5ffffff);
3203 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3206 bce_disable_intr(sc);
3208 /* Tell firmware that the driver is going away. */
3209 bce_reset(sc, BCE_DRV_MSG_CODE_SUSPEND_NO_WOL);
3211 /* Free the RX lists. */
3212 bce_free_rx_chain(sc);
3214 /* Free TX buffers. */
3215 bce_free_tx_chain(sc);
3218 * Isolate/power down the PHY, but leave the media selection
3219 * unchanged so that things will be put back to normal when
3220 * we bring the interface back up.
3223 itmp = ifp->if_flags;
3224 ifp->if_flags |= IFF_UP;
3226 * If we are called from bce_detach(), mii is already NULL.
3229 ifm = mii->mii_media.ifm_cur;
3230 mtmp = ifm->ifm_media;
3231 ifm->ifm_media = IFM_ETHER | IFM_NONE;
3233 ifm->ifm_media = mtmp;
3236 ifp->if_flags = itmp;
3241 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
3243 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3249 bce_reset(struct bce_softc *sc, u32 reset_code)
3254 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3256 /* Wait for pending PCI transactions to complete. */
3257 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3258 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3259 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3260 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3261 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3262 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3265 /* Assume bootcode is running. */
3266 sc->bce_fw_timed_out = 0;
3268 /* Give the firmware a chance to prepare for the reset. */
3269 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3271 goto bce_reset_exit;
3273 /* Set a firmware reminder that this is a soft reset. */
3274 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_RESET_SIGNATURE,
3275 BCE_DRV_RESET_SIGNATURE_MAGIC);
3277 /* Dummy read to force the chip to complete all current transactions. */
3278 val = REG_RD(sc, BCE_MISC_ID);
3281 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3282 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3283 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3284 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3286 /* Allow up to 30us for reset to complete. */
3287 for (i = 0; i < 10; i++) {
3288 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3289 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3290 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
3296 /* Check that reset completed successfully. */
3297 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3298 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3299 BCE_PRINTF(sc, "%s(%d): Reset failed!\n",
3300 __FILE__, __LINE__);
3302 goto bce_reset_exit;
3305 /* Make sure byte swapping is properly configured. */
3306 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3307 if (val != 0x01020304) {
3308 BCE_PRINTF(sc, "%s(%d): Byte swap is incorrect!\n",
3309 __FILE__, __LINE__);
3311 goto bce_reset_exit;
3314 /* Just completed a reset, assume that firmware is running again. */
3315 sc->bce_fw_timed_out = 0;
3317 /* Wait for the firmware to finish its initialization. */
3318 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3320 BCE_PRINTF(sc, "%s(%d): Firmware did not complete initialization!\n",
3321 __FILE__, __LINE__);
3324 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3331 bce_chipinit(struct bce_softc *sc)
3336 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3338 /* Make sure the interrupt is not active. */
3339 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3341 /* Initialize DMA byte/word swapping, configure the number of DMA */
3342 /* channels and PCI clock compensation delay. */
3343 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3344 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3345 #if BYTE_ORDER == BIG_ENDIAN
3346 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3348 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3349 DMA_READ_CHANS << 12 |
3350 DMA_WRITE_CHANS << 16;
3352 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3354 if ((sc->bce_flags & BCE_PCIX_FLAG) && (sc->bus_speed_mhz == 133))
3355 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3358 * This setting resolves a problem observed on certain Intel PCI
3359 * chipsets that cannot handle multiple outstanding DMA operations.
3360 * See errata E9_5706A1_65.
3362 if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
3363 (BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0) &&
3364 !(sc->bce_flags & BCE_PCIX_FLAG))
3365 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3367 REG_WR(sc, BCE_DMA_CONFIG, val);
3369 /* Clear the PCI-X relaxed ordering bit. See errata E3_5708CA0_570. */
3370 if (sc->bce_flags & BCE_PCIX_FLAG) {
3373 val = pci_read_config(sc->bce_dev, BCE_PCI_PCIX_CMD, 2);
3374 pci_write_config(sc->bce_dev, BCE_PCI_PCIX_CMD, val & ~0x2, 2);
3377 /* Enable the RX_V2P and Context state machines before access. */
3378 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3379 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3380 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3381 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3383 /* Initialize context mapping and zero out the quick contexts. */
3384 bce_init_context(sc);
3386 /* Initialize the on-boards CPUs */
3389 /* Prepare NVRAM for access. */
3390 if (bce_init_nvram(sc)) {
3392 goto bce_chipinit_exit;
3395 /* Set the kernel bypass block size */
3396 val = REG_RD(sc, BCE_MQ_CONFIG);
3397 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3398 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3399 REG_WR(sc, BCE_MQ_CONFIG, val);
3401 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3402 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3403 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3405 val = (BCM_PAGE_BITS - 8) << 24;
3406 REG_WR(sc, BCE_RV2P_CONFIG, val);
3408 /* Configure page size. */
3409 val = REG_RD(sc, BCE_TBDR_CONFIG);
3410 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3411 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3412 REG_WR(sc, BCE_TBDR_CONFIG, val);
3415 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3421 /****************************************************************************/
3422 /* Initialize the controller in preparation to send/receive traffic. */
3425 /* 0 for success, positive value for failure. */
3426 /****************************************************************************/
3428 bce_blockinit(struct bce_softc *sc)
3433 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3435 /* Load the hardware default MAC address. */
3436 bce_set_mac_addr(sc);
3438 /* Set the Ethernet backoff seed value */
3439 val = sc->eaddr[0] + (sc->eaddr[1] << 8) +
3440 (sc->eaddr[2] << 16) + (sc->eaddr[3] ) +
3441 (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3442 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3444 sc->last_status_idx = 0;
3445 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3447 /* Set up link change interrupt generation. */
3448 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3450 /* Program the physical address of the status block. */
3451 REG_WR(sc, BCE_HC_STATUS_ADDR_L,
3452 BCE_ADDR_LO(sc->status_block_paddr));
3453 REG_WR(sc, BCE_HC_STATUS_ADDR_H,
3454 BCE_ADDR_HI(sc->status_block_paddr));
3456 /* Program the physical address of the statistics block. */
3457 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3458 BCE_ADDR_LO(sc->stats_block_paddr));
3459 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3460 BCE_ADDR_HI(sc->stats_block_paddr));
3462 /* Program various host coalescing parameters. */
3463 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3464 (sc->bce_tx_quick_cons_trip_int << 16) | sc->bce_tx_quick_cons_trip);
3465 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3466 (sc->bce_rx_quick_cons_trip_int << 16) | sc->bce_rx_quick_cons_trip);
3467 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3468 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3469 REG_WR(sc, BCE_HC_TX_TICKS,
3470 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3471 REG_WR(sc, BCE_HC_RX_TICKS,
3472 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3473 REG_WR(sc, BCE_HC_COM_TICKS,
3474 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3475 REG_WR(sc, BCE_HC_CMD_TICKS,
3476 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3477 REG_WR(sc, BCE_HC_STATS_TICKS,
3478 (sc->bce_stats_ticks & 0xffff00));
3479 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS,
3481 REG_WR(sc, BCE_HC_CONFIG,
3482 (BCE_HC_CONFIG_RX_TMR_MODE | BCE_HC_CONFIG_TX_TMR_MODE |
3483 BCE_HC_CONFIG_COLLECT_STATS));
3485 /* Clear the internal statistics counters. */
3486 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3488 /* Verify that bootcode is running. */
3489 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_SIGNATURE);
3491 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3492 BCE_PRINTF(sc, "%s(%d): Simulating bootcode failure.\n",
3493 __FILE__, __LINE__);
3496 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3497 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3498 BCE_PRINTF(sc, "%s(%d): Bootcode not running! Found: 0x%08X, "
3499 "Expected: 08%08X\n", __FILE__, __LINE__,
3500 (reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK),
3501 BCE_DEV_INFO_SIGNATURE_MAGIC);
3503 goto bce_blockinit_exit;
3506 /* Check if any management firmware is running. */
3507 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_FEATURE);
3508 if (reg & (BCE_PORT_FEATURE_ASF_ENABLED | BCE_PORT_FEATURE_IMD_ENABLED)) {
3509 DBPRINT(sc, BCE_INFO, "Management F/W Enabled.\n");
3510 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
3513 sc->bce_fw_ver = REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_BC_REV);
3514 DBPRINT(sc, BCE_INFO, "bootcode rev = 0x%08X\n", sc->bce_fw_ver);
3516 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3517 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3519 /* Enable link state change interrupt generation. */
3520 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3522 /* Enable all remaining blocks in the MAC. */
3523 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, 0x5ffffff);
3524 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3528 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3534 /****************************************************************************/
3535 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3537 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3538 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3542 /* 0 for success, positive value for failure. */
3543 /****************************************************************************/
3545 bce_get_buf(struct bce_softc *sc, struct mbuf *m, u16 *prod, u16 *chain_prod,
3549 bus_dma_segment_t segs[4];
3550 struct mbuf *m_new = NULL;
3552 int i, nsegs, error, rc = 0;
3554 u16 debug_chain_prod = *chain_prod;
3557 DBPRINT(sc, (BCE_VERBOSE_RESET | BCE_VERBOSE_RECV), "Entering %s()\n",
3560 /* Make sure the inputs are valid. */
3561 DBRUNIF((*chain_prod > MAX_RX_BD),
3562 BCE_PRINTF(sc, "%s(%d): RX producer out of range: 0x%04X > 0x%04X\n",
3563 __FILE__, __LINE__, *chain_prod, (u16) MAX_RX_BD));
3565 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3566 "prod_bseq = 0x%08X\n", __FUNCTION__, *prod, *chain_prod, *prod_bseq);
3570 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3571 BCE_PRINTF(sc, "%s(%d): Simulating mbuf allocation failure.\n",
3572 __FILE__, __LINE__);
3573 sc->mbuf_alloc_failed++;
3575 goto bce_get_buf_exit);
3577 /* This is a new mbuf allocation. */
3578 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
3579 if (m_new == NULL) {
3581 DBPRINT(sc, BCE_WARN, "%s(%d): RX mbuf header allocation failed!\n",
3582 __FILE__, __LINE__);
3584 DBRUNIF(1, sc->mbuf_alloc_failed++);
3587 goto bce_get_buf_exit;
3590 DBRUNIF(1, sc->rx_mbuf_alloc++);
3591 m_cljget(m_new, M_DONTWAIT, sc->mbuf_alloc_size);
3592 if (!(m_new->m_flags & M_EXT)) {
3594 DBPRINT(sc, BCE_WARN, "%s(%d): RX mbuf chain allocation failed!\n",
3595 __FILE__, __LINE__);
3599 DBRUNIF(1, sc->rx_mbuf_alloc--);
3600 DBRUNIF(1, sc->mbuf_alloc_failed++);
3603 goto bce_get_buf_exit;
3606 m_new->m_len = m_new->m_pkthdr.len = sc->mbuf_alloc_size;
3609 m_new->m_len = m_new->m_pkthdr.len = sc->mbuf_alloc_size;
3610 m_new->m_data = m_new->m_ext.ext_buf;
3613 /* Map the mbuf cluster into device memory. */
3614 map = sc->rx_mbuf_map[*chain_prod];
3615 error = bus_dmamap_load_mbuf_sg(sc->rx_mbuf_tag, map, m_new,
3616 segs, &nsegs, BUS_DMA_NOWAIT);
3619 BCE_PRINTF(sc, "%s(%d): Error mapping mbuf into RX chain!\n",
3620 __FILE__, __LINE__);
3624 DBRUNIF(1, sc->rx_mbuf_alloc--);
3627 goto bce_get_buf_exit;
3630 /* Watch for overflow. */
3631 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3632 BCE_PRINTF(sc, "%s(%d): Too many free rx_bd (0x%04X > 0x%04X)!\n",
3633 __FILE__, __LINE__, sc->free_rx_bd, (u16) USABLE_RX_BD));
3635 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3636 sc->rx_low_watermark = sc->free_rx_bd);
3638 /* Setup the rx_bd for the first segment. */
3639 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
3641 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[0].ds_addr));
3642 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[0].ds_addr));
3643 rxbd->rx_bd_len = htole32(segs[0].ds_len);
3644 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3645 *prod_bseq += segs[0].ds_len;
3647 for (i = 1; i < nsegs; i++) {
3649 *prod = NEXT_RX_BD(*prod);
3650 *chain_prod = RX_CHAIN_IDX(*prod);
3652 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
3654 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
3655 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
3656 rxbd->rx_bd_len = htole32(segs[i].ds_len);
3657 rxbd->rx_bd_flags = 0;
3658 *prod_bseq += segs[i].ds_len;
3661 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3663 /* Save the mbuf and update our counter. */
3664 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3665 sc->free_rx_bd -= nsegs;
3667 DBRUN(BCE_VERBOSE_RECV, bce_dump_rx_mbuf_chain(sc, debug_chain_prod,
3670 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3671 "prod_bseq = 0x%08X\n", __FUNCTION__, *prod, *chain_prod, *prod_bseq);
3674 DBPRINT(sc, (BCE_VERBOSE_RESET | BCE_VERBOSE_RECV), "Exiting %s()\n",
3681 /****************************************************************************/
3682 /* Allocate memory and initialize the TX data structures. */
3685 /* 0 for success, positive value for failure. */
3686 /****************************************************************************/
3688 bce_init_tx_chain(struct bce_softc *sc)
3694 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3696 /* Set the initial TX producer/consumer indices. */
3699 sc->tx_prod_bseq = 0;
3701 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3704 * The NetXtreme II supports a linked-list structre called
3705 * a Buffer Descriptor Chain (or BD chain). A BD chain
3706 * consists of a series of 1 or more chain pages, each of which
3707 * consists of a fixed number of BD entries.
3708 * The last BD entry on each page is a pointer to the next page
3709 * in the chain, and the last pointer in the BD chain
3710 * points back to the beginning of the chain.
3713 /* Set the TX next pointer chain entries. */
3714 for (i = 0; i < TX_PAGES; i++) {
3717 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3719 /* Check if we've reached the last page. */
3720 if (i == (TX_PAGES - 1))
3725 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3726 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3730 * Initialize the context ID for an L2 TX chain.
3732 val = BCE_L2CTX_TYPE_TYPE_L2;
3733 val |= BCE_L2CTX_TYPE_SIZE_L2;
3734 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TYPE, val);
3736 val = BCE_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
3737 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_CMD_TYPE, val);
3739 /* Point the hardware to the first page in the chain. */
3740 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3741 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_HI, val);
3742 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3743 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_LO, val);
3745 DBRUN(BCE_VERBOSE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD));
3747 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3753 /****************************************************************************/
3754 /* Free memory and clear the TX data structures. */
3758 /****************************************************************************/
3760 bce_free_tx_chain(struct bce_softc *sc)
3764 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3766 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3767 for (i = 0; i < TOTAL_TX_BD; i++) {
3768 if (sc->tx_mbuf_ptr[i] != NULL) {
3769 if (sc->tx_mbuf_map != NULL)
3770 bus_dmamap_sync(sc->tx_mbuf_tag, sc->tx_mbuf_map[i],
3771 BUS_DMASYNC_POSTWRITE);
3772 m_freem(sc->tx_mbuf_ptr[i]);
3773 sc->tx_mbuf_ptr[i] = NULL;
3774 DBRUNIF(1, sc->tx_mbuf_alloc--);
3778 /* Clear each TX chain page. */
3779 for (i = 0; i < TX_PAGES; i++)
3780 bzero((char *)sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3782 /* Check if we lost any mbufs in the process. */
3783 DBRUNIF((sc->tx_mbuf_alloc),
3784 BCE_PRINTF(sc, "%s(%d): Memory leak! Lost %d mbufs "
3786 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3788 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3792 /****************************************************************************/
3793 /* Allocate memory and initialize the RX data structures. */
3796 /* 0 for success, positive value for failure. */
3797 /****************************************************************************/
3799 bce_init_rx_chain(struct bce_softc *sc)
3803 u16 prod, chain_prod;
3806 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3808 /* Initialize the RX producer and consumer indices. */
3811 sc->rx_prod_bseq = 0;
3812 sc->free_rx_bd = BCE_RX_SLACK_SPACE;
3813 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
3815 /* Initialize the RX next pointer chain entries. */
3816 for (i = 0; i < RX_PAGES; i++) {
3819 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
3821 /* Check if we've reached the last page. */
3822 if (i == (RX_PAGES - 1))
3827 /* Setup the chain page pointers. */
3828 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
3829 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
3832 /* Initialize the context ID for an L2 RX chain. */
3833 val = BCE_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
3834 val |= BCE_L2CTX_CTX_TYPE_SIZE_L2;
3836 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_CTX_TYPE, val);
3838 /* Point the hardware to the first page in the chain. */
3839 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
3840 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_HI, val);
3841 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
3842 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_LO, val);
3844 /* Allocate mbuf clusters for the rx_bd chain. */
3845 prod = prod_bseq = 0;
3846 while (prod < BCE_RX_SLACK_SPACE) {
3847 chain_prod = RX_CHAIN_IDX(prod);
3848 if (bce_get_buf(sc, NULL, &prod, &chain_prod, &prod_bseq)) {
3849 BCE_PRINTF(sc, "%s(%d): Error filling RX chain: rx_bd[0x%04X]!\n",
3850 __FILE__, __LINE__, chain_prod);
3854 prod = NEXT_RX_BD(prod);
3857 /* Save the RX chain producer index. */
3859 sc->rx_prod_bseq = prod_bseq;
3861 for (i = 0; i < RX_PAGES; i++) {
3863 sc->rx_bd_chain_tag,
3864 sc->rx_bd_chain_map[i],
3865 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3868 /* Tell the chip about the waiting rx_bd's. */
3869 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3870 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3872 DBRUN(BCE_VERBOSE_RECV, bce_dump_rx_chain(sc, 0, TOTAL_RX_BD));
3874 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3880 /****************************************************************************/
3881 /* Free memory and clear the RX data structures. */
3885 /****************************************************************************/
3887 bce_free_rx_chain(struct bce_softc *sc)
3891 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
3893 /* Free any mbufs still in the RX mbuf chain. */
3894 for (i = 0; i < TOTAL_RX_BD; i++) {
3895 if (sc->rx_mbuf_ptr[i] != NULL) {
3896 if (sc->rx_mbuf_map[i] != NULL)
3897 bus_dmamap_sync(sc->rx_mbuf_tag, sc->rx_mbuf_map[i],
3898 BUS_DMASYNC_POSTREAD);
3899 m_freem(sc->rx_mbuf_ptr[i]);
3900 sc->rx_mbuf_ptr[i] = NULL;
3901 DBRUNIF(1, sc->rx_mbuf_alloc--);
3905 /* Clear each RX chain page. */
3906 for (i = 0; i < RX_PAGES; i++)
3907 bzero((char *)sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
3909 /* Check if we lost any mbufs in the process. */
3910 DBRUNIF((sc->rx_mbuf_alloc),
3911 BCE_PRINTF(sc, "%s(%d): Memory leak! Lost %d mbufs from rx chain!\n",
3912 __FILE__, __LINE__, sc->rx_mbuf_alloc));
3914 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
3918 /****************************************************************************/
3919 /* Set media options. */
3922 /* 0 for success, positive value for failure. */
3923 /****************************************************************************/
3925 bce_ifmedia_upd(struct ifnet *ifp)
3927 struct bce_softc *sc;
3928 struct mii_data *mii;
3929 struct ifmedia *ifm;
3933 ifm = &sc->bce_ifmedia;
3935 /* DRC - ToDo: Add SerDes support. */
3937 mii = device_get_softc(sc->bce_miibus);
3939 if (mii->mii_instance) {
3940 struct mii_softc *miisc;
3941 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
3942 miisc = LIST_NEXT(miisc, mii_list))
3943 mii_phy_reset(miisc);
3951 /****************************************************************************/
3952 /* Reports current media status. */
3956 /****************************************************************************/
3958 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3960 struct bce_softc *sc;
3961 struct mii_data *mii;
3967 mii = device_get_softc(sc->bce_miibus);
3969 /* DRC - ToDo: Add SerDes support. */
3972 ifmr->ifm_active = mii->mii_media_active;
3973 ifmr->ifm_status = mii->mii_media_status;
3979 /****************************************************************************/
3980 /* Handles PHY generated interrupt events. */
3984 /****************************************************************************/
3986 bce_phy_intr(struct bce_softc *sc)
3988 u32 new_link_state, old_link_state;
3990 new_link_state = sc->status_block->status_attn_bits &
3991 STATUS_ATTN_BITS_LINK_STATE;
3992 old_link_state = sc->status_block->status_attn_bits_ack &
3993 STATUS_ATTN_BITS_LINK_STATE;
3995 /* Handle any changes if the link state has changed. */
3996 if (new_link_state != old_link_state) {
3998 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
4001 callout_stop(&sc->bce_stat_ch);
4002 bce_tick_locked(sc);
4004 /* Update the status_attn_bits_ack field in the status block. */
4005 if (new_link_state) {
4006 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
4007 STATUS_ATTN_BITS_LINK_STATE);
4008 DBPRINT(sc, BCE_INFO, "Link is now UP.\n");
4011 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
4012 STATUS_ATTN_BITS_LINK_STATE);
4013 DBPRINT(sc, BCE_INFO, "Link is now DOWN.\n");
4018 /* Acknowledge the link change interrupt. */
4019 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
4023 /****************************************************************************/
4024 /* Handles received frame interrupt events. */
4028 /****************************************************************************/
4030 bce_rx_intr(struct bce_softc *sc)
4032 struct status_block *sblk = sc->status_block;
4033 struct ifnet *ifp = sc->bce_ifp;
4034 u16 hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
4036 struct l2_fhdr *l2fhdr;
4038 DBRUNIF(1, sc->rx_interrupts++);
4040 /* Prepare the RX chain pages to be accessed by the host CPU. */
4041 for (int i = 0; i < RX_PAGES; i++)
4042 bus_dmamap_sync(sc->rx_bd_chain_tag,
4043 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTWRITE);
4045 /* Get the hardware's view of the RX consumer index. */
4046 hw_cons = sc->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
4047 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4050 /* Get working copies of the driver's view of the RX indices. */
4051 sw_cons = sc->rx_cons;
4052 sw_prod = sc->rx_prod;
4053 sw_prod_bseq = sc->rx_prod_bseq;
4055 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
4056 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
4057 __FUNCTION__, sw_prod, sw_cons,
4060 /* Prevent speculative reads from getting ahead of the status block. */
4061 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4062 BUS_SPACE_BARRIER_READ);
4064 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
4065 sc->rx_low_watermark = sc->free_rx_bd);
4068 * Scan through the receive chain as long
4069 * as there is work to do.
4071 while (sw_cons != hw_cons) {
4077 /* Convert the producer/consumer indices to an actual rx_bd index. */
4078 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
4079 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
4081 /* Get the used rx_bd. */
4082 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)][RX_IDX(sw_chain_cons)];
4085 DBRUN(BCE_VERBOSE_RECV,
4086 BCE_PRINTF(sc, "%s(): ", __FUNCTION__);
4087 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
4089 #ifdef DEVICE_POLLING
4090 if (ifp->if_capenable & IFCAP_POLLING) {
4091 if (sc->bce_rxcycles <= 0)
4097 /* The mbuf is stored with the last rx_bd entry of a packet. */
4098 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
4100 /* Validate that this is the last rx_bd. */
4101 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
4102 BCE_PRINTF(sc, "%s(%d): Unexpected mbuf found in rx_bd[0x%04X]!\n",
4103 __FILE__, __LINE__, sw_chain_cons);
4104 bce_breakpoint(sc));
4106 /* DRC - ToDo: If the received packet is small, say less */
4107 /* than 128 bytes, allocate a new mbuf here, */
4108 /* copy the data to that mbuf, and recycle */
4109 /* the mapped jumbo frame. */
4111 /* Unmap the mbuf from DMA space. */
4112 bus_dmamap_sync(sc->rx_mbuf_tag,
4113 sc->rx_mbuf_map[sw_chain_cons],
4114 BUS_DMASYNC_POSTREAD);
4115 bus_dmamap_unload(sc->rx_mbuf_tag,
4116 sc->rx_mbuf_map[sw_chain_cons]);
4118 /* Remove the mbuf from the driver's chain. */
4119 m = sc->rx_mbuf_ptr[sw_chain_cons];
4120 sc->rx_mbuf_ptr[sw_chain_cons] = NULL;
4123 * Frames received on the NetXteme II are prepended
4124 * with the l2_fhdr structure which provides status
4125 * information about the received frame (including
4126 * VLAN tags and checksum info) and are also
4127 * automatically adjusted to align the IP header
4128 * (i.e. two null bytes are inserted before the
4131 l2fhdr = mtod(m, struct l2_fhdr *);
4133 len = l2fhdr->l2_fhdr_pkt_len;
4134 status = l2fhdr->l2_fhdr_status;
4136 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
4137 BCE_PRINTF(sc, "Simulating l2_fhdr status error.\n");
4138 status = status | L2_FHDR_ERRORS_PHY_DECODE);
4140 /* Watch for unusual sized frames. */
4141 DBRUNIF(((len < BCE_MIN_MTU) || (len > BCE_MAX_JUMBO_ETHER_MTU_VLAN)),
4142 BCE_PRINTF(sc, "%s(%d): Unusual frame size found. "
4143 "Min(%d), Actual(%d), Max(%d)\n",
4144 __FILE__, __LINE__, (int) BCE_MIN_MTU,
4145 len, (int) BCE_MAX_JUMBO_ETHER_MTU_VLAN);
4146 bce_dump_mbuf(sc, m);
4147 bce_breakpoint(sc));
4149 len -= ETHER_CRC_LEN;
4151 /* Check the received frame for errors. */
4152 if (status & (L2_FHDR_ERRORS_BAD_CRC |
4153 L2_FHDR_ERRORS_PHY_DECODE | L2_FHDR_ERRORS_ALIGNMENT |
4154 L2_FHDR_ERRORS_TOO_SHORT | L2_FHDR_ERRORS_GIANT_FRAME)) {
4157 DBRUNIF(1, sc->l2fhdr_status_errors++);
4159 /* Reuse the mbuf for a new frame. */
4160 if (bce_get_buf(sc, m, &sw_prod, &sw_chain_prod, &sw_prod_bseq)) {
4162 DBRUNIF(1, bce_breakpoint(sc));
4163 panic("bce%d: Can't reuse RX mbuf!\n", sc->bce_unit);
4166 goto bce_rx_int_next_rx;
4170 * Get a new mbuf for the rx_bd. If no new
4171 * mbufs are available then reuse the current mbuf,
4172 * log an ierror on the interface, and generate
4173 * an error in the system log.
4175 if (bce_get_buf(sc, NULL, &sw_prod, &sw_chain_prod, &sw_prod_bseq)) {
4178 BCE_PRINTF(sc, "%s(%d): Failed to allocate "
4179 "new mbuf, incoming frame dropped!\n",
4180 __FILE__, __LINE__));
4184 /* Try and reuse the exisitng mbuf. */
4185 if (bce_get_buf(sc, m, &sw_prod, &sw_chain_prod, &sw_prod_bseq)) {
4187 DBRUNIF(1, bce_breakpoint(sc));
4188 panic("bce%d: Double mbuf allocation failure!", sc->bce_unit);
4191 goto bce_rx_int_next_rx;
4194 /* Skip over the l2_fhdr when passing the data up the stack. */
4195 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
4197 /* Adjust the packet length to match the received data. */
4198 m->m_pkthdr.len = m->m_len = len;
4200 /* Send the packet to the appropriate interface. */
4201 m->m_pkthdr.rcvif = ifp;
4203 DBRUN(BCE_VERBOSE_RECV,
4204 struct ether_header *eh;
4205 eh = mtod(m, struct ether_header *);
4206 BCE_PRINTF(sc, "%s(): to: %6D, from: %6D, type: 0x%04X\n",
4207 __FUNCTION__, eh->ether_dhost, ":",
4208 eh->ether_shost, ":", htons(eh->ether_type)));
4210 /* Validate the checksum if offload enabled. */
4211 if (ifp->if_capenable & IFCAP_RXCSUM) {
4213 /* Check for an IP datagram. */
4214 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
4215 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
4217 /* Check if the IP checksum is valid. */
4218 if ((l2fhdr->l2_fhdr_ip_xsum ^ 0xffff) == 0)
4219 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4221 DBPRINT(sc, BCE_WARN_SEND,
4222 "%s(): Invalid IP checksum = 0x%04X!\n",
4223 __FUNCTION__, l2fhdr->l2_fhdr_ip_xsum);
4226 /* Check for a valid TCP/UDP frame. */
4227 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
4228 L2_FHDR_STATUS_UDP_DATAGRAM)) {
4230 /* Check for a good TCP/UDP checksum. */
4231 if ((status & (L2_FHDR_ERRORS_TCP_XSUM |
4232 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
4233 m->m_pkthdr.csum_data =
4234 l2fhdr->l2_fhdr_tcp_udp_xsum;
4235 m->m_pkthdr.csum_flags |= (CSUM_DATA_VALID
4238 DBPRINT(sc, BCE_WARN_SEND,
4239 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
4240 __FUNCTION__, l2fhdr->l2_fhdr_tcp_udp_xsum);
4246 * If we received a packet with a vlan tag,
4247 * attach that information to the packet.
4249 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
4250 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): VLAN tag = 0x%04X\n",
4251 __FUNCTION__, l2fhdr->l2_fhdr_vlan_tag);
4252 #if __FreeBSD_version < 700000
4253 VLAN_INPUT_TAG(ifp, m, l2fhdr->l2_fhdr_vlan_tag, continue);
4255 VLAN_INPUT_TAG(ifp, m, l2fhdr->l2_fhdr_vlan_tag);
4261 /* Pass the mbuf off to the upper layers. */
4263 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(): Passing received frame up.\n",
4266 (*ifp->if_input)(ifp, m);
4267 DBRUNIF(1, sc->rx_mbuf_alloc--);
4271 sw_prod = NEXT_RX_BD(sw_prod);
4274 sw_cons = NEXT_RX_BD(sw_cons);
4276 /* Refresh hw_cons to see if there's new work */
4277 if (sw_cons == hw_cons) {
4278 hw_cons = sc->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
4279 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4283 /* Prevent speculative reads from getting ahead of the status block. */
4284 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4285 BUS_SPACE_BARRIER_READ);
4288 for (int i = 0; i < RX_PAGES; i++)
4289 bus_dmamap_sync(sc->rx_bd_chain_tag,
4290 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
4292 sc->rx_cons = sw_cons;
4293 sc->rx_prod = sw_prod;
4294 sc->rx_prod_bseq = sw_prod_bseq;
4296 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
4297 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
4299 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
4300 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
4301 __FUNCTION__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
4305 /****************************************************************************/
4306 /* Handles transmit completion interrupt events. */
4310 /****************************************************************************/
4312 bce_tx_intr(struct bce_softc *sc)
4314 struct status_block *sblk = sc->status_block;
4315 struct ifnet *ifp = sc->bce_ifp;
4316 u16 hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
4318 BCE_LOCK_ASSERT(sc);
4320 DBRUNIF(1, sc->tx_interrupts++);
4322 /* Get the hardware's view of the TX consumer index. */
4323 hw_tx_cons = sc->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
4325 /* Skip to the next entry if this is a chain page pointer. */
4326 if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4329 sw_tx_cons = sc->tx_cons;
4331 /* Prevent speculative reads from getting ahead of the status block. */
4332 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4333 BUS_SPACE_BARRIER_READ);
4335 /* Cycle through any completed TX chain page entries. */
4336 while (sw_tx_cons != hw_tx_cons) {
4338 struct tx_bd *txbd = NULL;
4340 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4342 DBPRINT(sc, BCE_INFO_SEND,
4343 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4344 "sw_tx_chain_cons = 0x%04X\n",
4345 __FUNCTION__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4347 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4348 BCE_PRINTF(sc, "%s(%d): TX chain consumer out of range! "
4349 " 0x%04X > 0x%04X\n",
4350 __FILE__, __LINE__, sw_tx_chain_cons,
4352 bce_breakpoint(sc));
4355 txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4356 [TX_IDX(sw_tx_chain_cons)]);
4358 DBRUNIF((txbd == NULL),
4359 BCE_PRINTF(sc, "%s(%d): Unexpected NULL tx_bd[0x%04X]!\n",
4360 __FILE__, __LINE__, sw_tx_chain_cons);
4361 bce_breakpoint(sc));
4363 DBRUN(BCE_INFO_SEND,
4364 BCE_PRINTF(sc, "%s(): ", __FUNCTION__);
4365 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4368 * Free the associated mbuf. Remember
4369 * that only the last tx_bd of a packet
4370 * has an mbuf pointer and DMA map.
4372 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4374 /* Validate that this is the last tx_bd. */
4375 DBRUNIF((!(txbd->tx_bd_vlan_tag_flags & TX_BD_FLAGS_END)),
4376 BCE_PRINTF(sc, "%s(%d): tx_bd END flag not set but "
4377 "txmbuf == NULL!\n", __FILE__, __LINE__);
4378 bce_breakpoint(sc));
4380 DBRUN(BCE_INFO_SEND,
4381 BCE_PRINTF(sc, "%s(): Unloading map/freeing mbuf "
4382 "from tx_bd[0x%04X]\n", __FUNCTION__, sw_tx_chain_cons));
4384 /* Unmap the mbuf. */
4385 bus_dmamap_unload(sc->tx_mbuf_tag,
4386 sc->tx_mbuf_map[sw_tx_chain_cons]);
4388 /* Free the mbuf. */
4389 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4390 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4391 DBRUNIF(1, sc->tx_mbuf_alloc--);
4397 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4399 /* Refresh hw_cons to see if there's new work. */
4400 hw_tx_cons = sc->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
4401 if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4404 /* Prevent speculative reads from getting ahead of the status block. */
4405 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4406 BUS_SPACE_BARRIER_READ);
4409 /* Clear the TX timeout timer. */
4412 /* Clear the tx hardware queue full flag. */
4413 if ((sc->used_tx_bd + BCE_TX_SLACK_SPACE) < USABLE_TX_BD) {
4414 DBRUNIF((ifp->if_drv_flags & IFF_DRV_OACTIVE),
4415 BCE_PRINTF(sc, "%s(): TX chain is open for business! Used tx_bd = %d\n",
4416 __FUNCTION__, sc->used_tx_bd));
4417 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
4420 sc->tx_cons = sw_tx_cons;
4424 /****************************************************************************/
4425 /* Disables interrupt generation. */
4429 /****************************************************************************/
4431 bce_disable_intr(struct bce_softc *sc)
4433 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4434 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4435 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4439 /****************************************************************************/
4440 /* Enables interrupt generation. */
4444 /****************************************************************************/
4446 bce_enable_intr(struct bce_softc *sc)
4450 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4451 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4452 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4454 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4455 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4457 val = REG_RD(sc, BCE_HC_COMMAND);
4458 REG_WR(sc, BCE_HC_COMMAND, val | BCE_HC_COMMAND_COAL_NOW);
4462 /****************************************************************************/
4463 /* Handles controller initialization. */
4465 /* Must be called from a locked routine. */
4469 /****************************************************************************/
4471 bce_init_locked(struct bce_softc *sc)
4476 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
4478 BCE_LOCK_ASSERT(sc);
4482 /* Check if the driver is still running and bail out if it is. */
4483 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4484 goto bce_init_locked_exit;
4488 if (bce_reset(sc, BCE_DRV_MSG_CODE_RESET)) {
4489 BCE_PRINTF(sc, "%s(%d): Controller reset failed!\n",
4490 __FILE__, __LINE__);
4491 goto bce_init_locked_exit;
4494 if (bce_chipinit(sc)) {
4495 BCE_PRINTF(sc, "%s(%d): Controller initialization failed!\n",
4496 __FILE__, __LINE__);
4497 goto bce_init_locked_exit;
4500 if (bce_blockinit(sc)) {
4501 BCE_PRINTF(sc, "%s(%d): Block initialization failed!\n",
4502 __FILE__, __LINE__);
4503 goto bce_init_locked_exit;
4506 /* Load our MAC address. */
4507 bcopy(IF_LLADDR(sc->bce_ifp), sc->eaddr, ETHER_ADDR_LEN);
4508 bce_set_mac_addr(sc);
4510 /* Calculate and program the Ethernet MTU size. */
4511 ether_mtu = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + ifp->if_mtu +
4514 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n",__FUNCTION__, ether_mtu);
4517 * Program the mtu, enabling jumbo frame
4518 * support if necessary. Also set the mbuf
4519 * allocation count for RX frames.
4521 if (ether_mtu > ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN) {
4522 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu |
4523 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4524 sc->mbuf_alloc_size = MJUM9BYTES;
4526 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4527 sc->mbuf_alloc_size = MCLBYTES;
4530 /* Calculate the RX Ethernet frame size for rx_bd's. */
4531 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4533 DBPRINT(sc, BCE_INFO,
4534 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4535 "max_frame_size = %d\n",
4536 __FUNCTION__, (int) MCLBYTES, sc->mbuf_alloc_size, sc->max_frame_size);
4538 /* Program appropriate promiscuous/multicast filtering. */
4539 bce_set_rx_mode(sc);
4541 /* Init RX buffer descriptor chain. */
4542 bce_init_rx_chain(sc);
4544 /* Init TX buffer descriptor chain. */
4545 bce_init_tx_chain(sc);
4547 #ifdef DEVICE_POLLING
4548 /* Disable interrupts if we are polling. */
4549 if (ifp->if_capenable & IFCAP_POLLING) {
4550 bce_disable_intr(sc);
4552 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4553 (1 << 16) | sc->bce_rx_quick_cons_trip);
4554 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4555 (1 << 16) | sc->bce_tx_quick_cons_trip);
4558 /* Enable host interrupts. */
4559 bce_enable_intr(sc);
4561 bce_ifmedia_upd(ifp);
4563 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4564 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
4566 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
4568 bce_init_locked_exit:
4569 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
4575 /****************************************************************************/
4576 /* Handles controller initialization when called from an unlocked routine. */
4580 /****************************************************************************/
4584 struct bce_softc *sc = xsc;
4587 bce_init_locked(sc);
4592 /****************************************************************************/
4593 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4594 /* memory visible to the controller. */
4597 /* 0 for success, positive value for failure. */
4598 /****************************************************************************/
4600 bce_tx_encap(struct bce_softc *sc, struct mbuf *m_head, u16 *prod,
4601 u16 *chain_prod, u32 *prod_bseq)
4603 u32 vlan_tag_flags = 0;
4605 struct bce_dmamap_arg map_arg;
4607 int i, error, rc = 0;
4609 /* Transfer any checksum offload flags to the bd. */
4610 if (m_head->m_pkthdr.csum_flags) {
4611 if (m_head->m_pkthdr.csum_flags & CSUM_IP)
4612 vlan_tag_flags |= TX_BD_FLAGS_IP_CKSUM;
4613 if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4614 vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4617 /* Transfer any VLAN tags to the bd. */
4618 mtag = VLAN_OUTPUT_TAG(sc->bce_ifp, m_head);
4620 vlan_tag_flags |= (TX_BD_FLAGS_VLAN_TAG |
4621 (VLAN_TAG_VALUE(mtag) << 16));
4623 /* Map the mbuf into DMAable memory. */
4624 map = sc->tx_mbuf_map[*chain_prod];
4626 map_arg.prod = *prod;
4627 map_arg.chain_prod = *chain_prod;
4628 map_arg.prod_bseq = *prod_bseq;
4629 map_arg.tx_flags = vlan_tag_flags;
4630 map_arg.maxsegs = USABLE_TX_BD - sc->used_tx_bd -
4633 KASSERT(map_arg.maxsegs > 0, ("Invalid TX maxsegs value!"));
4635 for (i = 0; i < TX_PAGES; i++)
4636 map_arg.tx_chain[i] = sc->tx_bd_chain[i];
4638 /* Map the mbuf into our DMA address space. */
4639 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m_head,
4640 bce_dma_map_tx_desc, &map_arg, BUS_DMA_NOWAIT);
4642 if (error || map_arg.maxsegs == 0) {
4643 BCE_PRINTF(sc, "%s(%d): Error mapping mbuf into TX chain!\n",
4644 __FILE__, __LINE__);
4646 goto bce_tx_encap_exit;
4650 * Ensure that the map for this transmission
4651 * is placed at the array index of the last
4652 * descriptor in this chain. This is done
4653 * because a single map is used for all
4654 * segments of the mbuf and we don't want to
4655 * delete the map before all of the segments
4658 sc->tx_mbuf_map[*chain_prod] =
4659 sc->tx_mbuf_map[map_arg.chain_prod];
4660 sc->tx_mbuf_map[map_arg.chain_prod] = map;
4661 sc->tx_mbuf_ptr[map_arg.chain_prod] = m_head;
4662 sc->used_tx_bd += map_arg.maxsegs;
4664 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
4665 sc->tx_hi_watermark = sc->used_tx_bd);
4667 DBRUNIF(1, sc->tx_mbuf_alloc++);
4669 DBRUN(BCE_VERBOSE_SEND, bce_dump_tx_mbuf_chain(sc, *chain_prod,
4672 /* prod still points the last used tx_bd at this point. */
4673 *prod = map_arg.prod;
4674 *chain_prod = map_arg.chain_prod;
4675 *prod_bseq = map_arg.prod_bseq;
4683 /****************************************************************************/
4684 /* Main transmit routine when called from another routine with a lock. */
4688 /****************************************************************************/
4690 bce_start_locked(struct ifnet *ifp)
4692 struct bce_softc *sc = ifp->if_softc;
4693 struct mbuf *m_head = NULL;
4695 u16 tx_prod, tx_chain_prod;
4698 /* If there's no link or the transmit queue is empty then just exit. */
4699 if (!sc->bce_link || IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
4700 DBPRINT(sc, BCE_INFO_SEND, "%s(): No link or transmit queue empty.\n",
4702 goto bce_start_locked_exit;
4705 /* prod points to the next free tx_bd. */
4706 tx_prod = sc->tx_prod;
4707 tx_chain_prod = TX_CHAIN_IDX(tx_prod);
4708 tx_prod_bseq = sc->tx_prod_bseq;
4710 DBPRINT(sc, BCE_INFO_SEND,
4711 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04X, "
4712 "tx_prod_bseq = 0x%08X\n",
4713 __FUNCTION__, tx_prod, tx_chain_prod, tx_prod_bseq);
4715 /* Keep adding entries while there is space in the ring. */
4716 while(sc->tx_mbuf_ptr[tx_chain_prod] == NULL) {
4718 /* Check for any frames to send. */
4719 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
4724 * Pack the data into the transmit ring. If we
4725 * don't have room, place the mbuf back at the
4726 * head of the queue and set the OACTIVE flag
4727 * to wait for the NIC to drain the chain.
4729 if (bce_tx_encap(sc, m_head, &tx_prod, &tx_chain_prod, &tx_prod_bseq)) {
4730 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
4731 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
4732 DBPRINT(sc, BCE_INFO_SEND,
4733 "TX chain is closed for business! Total tx_bd used = %d\n",
4740 /* Send a copy of the frame to any BPF listeners. */
4741 BPF_MTAP(ifp, m_head);
4743 tx_prod = NEXT_TX_BD(tx_prod);
4744 tx_chain_prod = TX_CHAIN_IDX(tx_prod);
4748 /* no packets were dequeued */
4749 DBPRINT(sc, BCE_VERBOSE_SEND, "%s(): No packets were dequeued\n",
4751 goto bce_start_locked_exit;
4754 /* Update the driver's counters. */
4755 sc->tx_prod = tx_prod;
4756 sc->tx_prod_bseq = tx_prod_bseq;
4758 DBPRINT(sc, BCE_INFO_SEND,
4759 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
4760 "tx_prod_bseq = 0x%08X\n",
4761 __FUNCTION__, tx_prod, tx_chain_prod, tx_prod_bseq);
4763 /* Start the transmit. */
4764 REG_WR16(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
4765 REG_WR(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
4767 /* Set the tx timeout. */
4768 ifp->if_timer = BCE_TX_TIMEOUT;
4770 bce_start_locked_exit:
4775 /****************************************************************************/
4776 /* Main transmit routine when called from another routine without a lock. */
4780 /****************************************************************************/
4782 bce_start(struct ifnet *ifp)
4784 struct bce_softc *sc = ifp->if_softc;
4787 bce_start_locked(ifp);
4792 /****************************************************************************/
4793 /* Handles any IOCTL calls from the operating system. */
4796 /* 0 for success, positive value for failure. */
4797 /****************************************************************************/
4799 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
4801 struct bce_softc *sc = ifp->if_softc;
4802 struct ifreq *ifr = (struct ifreq *) data;
4803 struct mii_data *mii;
4804 int mask, error = 0;
4806 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __FUNCTION__);
4812 /* Check that the MTU setting is supported. */
4813 if ((ifr->ifr_mtu < BCE_MIN_MTU) ||
4814 (ifr->ifr_mtu > BCE_MAX_JUMBO_MTU)) {
4819 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
4821 ifp->if_mtu = ifr->ifr_mtu;
4822 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
4826 /* Set interface. */
4828 DBPRINT(sc, BCE_VERBOSE, "Received SIOCSIFFLAGS\n");
4832 /* Check if the interface is up. */
4833 if (ifp->if_flags & IFF_UP) {
4834 /* Change the promiscuous/multicast flags as necessary. */
4835 bce_set_rx_mode(sc);
4837 /* The interface is down. Check if the driver is running. */
4838 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4848 /* Add/Delete multicast address */
4851 DBPRINT(sc, BCE_VERBOSE, "Received SIOCADDMULTI/SIOCDELMULTI\n");
4853 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4855 bce_set_rx_mode(sc);
4862 /* Set/Get Interface media */
4865 DBPRINT(sc, BCE_VERBOSE, "Received SIOCSIFMEDIA/SIOCGIFMEDIA\n");
4867 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
4870 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
4871 DBPRINT(sc, BCE_VERBOSE, "SerDes media set/get\n");
4873 error = ifmedia_ioctl(ifp, ifr,
4874 &sc->bce_ifmedia, command);
4876 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
4877 mii = device_get_softc(sc->bce_miibus);
4878 error = ifmedia_ioctl(ifp, ifr,
4879 &mii->mii_media, command);
4883 /* Set interface capability */
4885 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
4886 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n", (u32) mask);
4888 #ifdef DEVICE_POLLING
4889 if (mask & IFCAP_POLLING) {
4890 if (ifr->ifr_reqcap & IFCAP_POLLING) {
4892 /* Setup the poll routine to call. */
4893 error = ether_poll_register(bce_poll, ifp);
4895 BCE_PRINTF(sc, "%s(%d): Error registering poll function!\n",
4896 __FILE__, __LINE__);
4897 goto bce_ioctl_exit;
4900 /* Clear the interrupt. */
4902 bce_disable_intr(sc);
4904 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4905 (1 << 16) | sc->bce_rx_quick_cons_trip);
4906 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4907 (1 << 16) | sc->bce_tx_quick_cons_trip);
4909 ifp->if_capenable |= IFCAP_POLLING;
4912 /* Clear the poll routine. */
4913 error = ether_poll_deregister(ifp);
4915 /* Enable interrupt even in error case */
4917 bce_enable_intr(sc);
4919 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4920 (sc->bce_tx_quick_cons_trip_int << 16) |
4921 sc->bce_tx_quick_cons_trip);
4922 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4923 (sc->bce_rx_quick_cons_trip_int << 16) |
4924 sc->bce_rx_quick_cons_trip);
4926 ifp->if_capenable &= ~IFCAP_POLLING;
4930 #endif /*DEVICE_POLLING */
4932 /* Toggle the TX checksum capabilites enable flag. */
4933 if (mask & IFCAP_TXCSUM) {
4934 ifp->if_capenable ^= IFCAP_TXCSUM;
4935 if (IFCAP_TXCSUM & ifp->if_capenable)
4936 ifp->if_hwassist = BCE_IF_HWASSIST;
4938 ifp->if_hwassist = 0;
4941 /* Toggle the RX checksum capabilities enable flag. */
4942 if (mask & IFCAP_RXCSUM) {
4943 ifp->if_capenable ^= IFCAP_RXCSUM;
4944 if (IFCAP_RXCSUM & ifp->if_capenable)
4945 ifp->if_hwassist = BCE_IF_HWASSIST;
4947 ifp->if_hwassist = 0;
4950 /* Toggle VLAN_MTU capabilities enable flag. */
4951 if (mask & IFCAP_VLAN_MTU) {
4952 BCE_PRINTF(sc, "%s(%d): Changing VLAN_MTU not supported.\n",
4953 __FILE__, __LINE__);
4956 /* Toggle VLANHWTAG capabilities enabled flag. */
4957 if (mask & IFCAP_VLAN_HWTAGGING) {
4958 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
4959 BCE_PRINTF(sc, "%s(%d): Cannot change VLAN_HWTAGGING while "
4960 "management firmware (ASF/IPMI/UMP) is running!\n",
4961 __FILE__, __LINE__);
4963 BCE_PRINTF(sc, "%s(%d): Changing VLAN_HWTAGGING not supported!\n",
4964 __FILE__, __LINE__);
4969 DBPRINT(sc, BCE_INFO, "Received unsupported IOCTL: 0x%08X\n",
4972 /* We don't know how to handle the IOCTL, pass it on. */
4973 error = ether_ioctl(ifp, command, data);
4977 #ifdef DEVICE_POLLING
4981 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __FUNCTION__);
4987 /****************************************************************************/
4988 /* Transmit timeout handler. */
4992 /****************************************************************************/
4994 bce_watchdog(struct ifnet *ifp)
4996 struct bce_softc *sc = ifp->if_softc;
4998 DBRUN(BCE_WARN_SEND,
4999 bce_dump_driver_state(sc);
5000 bce_dump_status_block(sc));
5002 BCE_PRINTF(sc, "%s(%d): Watchdog timeout occurred, resetting!\n",
5003 __FILE__, __LINE__);
5005 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
5007 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
5015 #ifdef DEVICE_POLLING
5017 bce_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count)
5019 struct bce_softc *sc = ifp->if_softc;
5021 BCE_LOCK_ASSERT(sc);
5023 sc->bce_rxcycles = count;
5025 bus_dmamap_sync(sc->status_tag, sc->status_map,
5026 BUS_DMASYNC_POSTWRITE);
5028 /* Check for any completed RX frames. */
5029 if (sc->status_block->status_rx_quick_consumer_index0 !=
5033 /* Check for any completed TX frames. */
5034 if (sc->status_block->status_tx_quick_consumer_index0 !=
5038 /* Check for new frames to transmit. */
5039 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
5040 bce_start_locked(ifp);
5046 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
5048 struct bce_softc *sc = ifp->if_softc;
5051 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
5052 bce_poll_locked(ifp, cmd, count);
5055 #endif /* DEVICE_POLLING */
5060 bce_has_work(struct bce_softc *sc)
5062 struct status_block *stat = sc->status_block;
5064 if ((stat->status_rx_quick_consumer_index0 != sc->hw_rx_cons) ||
5065 (stat->status_tx_quick_consumer_index0 != sc->hw_tx_cons))
5068 if (((stat->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) != 0) !=
5078 * Interrupt handler.
5080 /****************************************************************************/
5081 /* Main interrupt entry point. Verifies that the controller generated the */
5082 /* interrupt and then calls a separate routine for handle the various */
5083 /* interrupt causes (PHY, TX, RX). */
5086 /* 0 for success, positive value for failure. */
5087 /****************************************************************************/
5091 struct bce_softc *sc;
5093 u32 status_attn_bits;
5100 DBRUNIF(1, sc->interrupts_generated++);
5102 #ifdef DEVICE_POLLING
5103 if (ifp->if_capenable & IFCAP_POLLING) {
5104 DBPRINT(sc, BCE_INFO, "Polling enabled!\n");
5109 bus_dmamap_sync(sc->status_tag, sc->status_map,
5110 BUS_DMASYNC_POSTWRITE);
5113 * If the hardware status block index
5114 * matches the last value read by the
5115 * driver and we haven't asserted our
5116 * interrupt then there's nothing to do.
5118 if ((sc->status_block->status_idx == sc->last_status_idx) &&
5119 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) & BCE_PCICFG_MISC_STATUS_INTA_VALUE))
5122 /* Ack the interrupt and stop others from occuring. */
5123 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5124 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5125 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5127 /* Keep processing data as long as there is work to do. */
5130 status_attn_bits = sc->status_block->status_attn_bits;
5132 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
5133 BCE_PRINTF(sc, "Simulating unexpected status attention bit set.");
5134 status_attn_bits = status_attn_bits | STATUS_ATTN_BITS_PARITY_ERROR);
5136 /* Was it a link change interrupt? */
5137 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5138 (sc->status_block->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
5141 /* If any other attention is asserted then the chip is toast. */
5142 if (((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5143 (sc->status_block->status_attn_bits_ack &
5144 ~STATUS_ATTN_BITS_LINK_STATE))) {
5146 DBRUN(1, sc->unexpected_attentions++);
5148 BCE_PRINTF(sc, "%s(%d): Fatal attention detected: 0x%08X\n",
5149 __FILE__, __LINE__, sc->status_block->status_attn_bits);
5152 if (bce_debug_unexpected_attention == 0)
5153 bce_breakpoint(sc));
5155 bce_init_locked(sc);
5159 /* Check for any completed RX frames. */
5160 if (sc->status_block->status_rx_quick_consumer_index0 != sc->hw_rx_cons)
5163 /* Check for any completed TX frames. */
5164 if (sc->status_block->status_tx_quick_consumer_index0 != sc->hw_tx_cons)
5167 /* Save the status block index value for use during the next interrupt. */
5168 sc->last_status_idx = sc->status_block->status_idx;
5170 /* Prevent speculative reads from getting ahead of the status block. */
5171 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
5172 BUS_SPACE_BARRIER_READ);
5174 /* If there's no work left then exit the interrupt service routine. */
5175 if ((sc->status_block->status_rx_quick_consumer_index0 == sc->hw_rx_cons) &&
5176 (sc->status_block->status_tx_quick_consumer_index0 == sc->hw_tx_cons))
5181 bus_dmamap_sync(sc->status_tag, sc->status_map,
5182 BUS_DMASYNC_PREWRITE);
5184 /* Re-enable interrupts. */
5185 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5186 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx |
5187 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5188 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5189 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
5191 /* Handle any frames that arrived while handling the interrupt. */
5192 if (ifp->if_drv_flags & IFF_DRV_RUNNING && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
5193 bce_start_locked(ifp);
5200 /****************************************************************************/
5201 /* Programs the various packet receive modes (broadcast and multicast). */
5205 /****************************************************************************/
5207 bce_set_rx_mode(struct bce_softc *sc)
5210 struct ifmultiaddr *ifma;
5211 u32 hashes[4] = { 0, 0, 0, 0 };
5212 u32 rx_mode, sort_mode;
5215 BCE_LOCK_ASSERT(sc);
5219 /* Initialize receive mode default settings. */
5220 rx_mode = sc->rx_mode & ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
5221 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
5222 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
5225 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5228 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5229 (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG)))
5230 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5233 * Check for promiscuous, all multicast, or selected
5234 * multicast address filtering.
5236 if (ifp->if_flags & IFF_PROMISC) {
5237 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5239 /* Enable promiscuous mode. */
5240 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5241 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5242 } else if (ifp->if_flags & IFF_ALLMULTI) {
5243 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5245 /* Enable all multicast addresses. */
5246 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5247 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), 0xffffffff);
5249 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5251 /* Accept one or more multicast(s). */
5252 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5255 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5256 if (ifma->ifma_addr->sa_family != AF_LINK)
5258 h = ether_crc32_le(LLADDR((struct sockaddr_dl *)
5259 ifma->ifma_addr), ETHER_ADDR_LEN) & 0x7F;
5260 hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F);
5262 IF_ADDR_UNLOCK(ifp);
5264 for (i = 0; i < 4; i++)
5265 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4), hashes[i]);
5267 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5270 /* Only make changes if the recive mode has actually changed. */
5271 if (rx_mode != sc->rx_mode) {
5272 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5275 sc->rx_mode = rx_mode;
5276 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5279 /* Disable and clear the exisitng sort before enabling a new sort. */
5280 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5281 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5282 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5286 /****************************************************************************/
5287 /* Called periodically to updates statistics from the controllers */
5288 /* statistics block. */
5292 /****************************************************************************/
5294 bce_stats_update(struct bce_softc *sc)
5297 struct statistics_block *stats;
5299 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __FUNCTION__);
5303 stats = (struct statistics_block *) sc->stats_block;
5306 * Update the interface statistics from the
5307 * hardware statistics.
5309 ifp->if_collisions = (u_long) stats->stat_EtherStatsCollisions;
5311 ifp->if_ibytes = BCE_STATS(IfHCInOctets);
5313 ifp->if_obytes = BCE_STATS(IfHCOutOctets);
5315 ifp->if_imcasts = BCE_STATS(IfHCInMulticastPkts);
5317 ifp->if_omcasts = BCE_STATS(IfHCOutMulticastPkts);
5319 ifp->if_ierrors = (u_long) stats->stat_EtherStatsUndersizePkts +
5320 (u_long) stats->stat_EtherStatsOverrsizePkts +
5321 (u_long) stats->stat_IfInMBUFDiscards +
5322 (u_long) stats->stat_Dot3StatsAlignmentErrors +
5323 (u_long) stats->stat_Dot3StatsFCSErrors;
5325 ifp->if_oerrors = (u_long) stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5326 (u_long) stats->stat_Dot3StatsExcessiveCollisions +
5327 (u_long) stats->stat_Dot3StatsLateCollisions;
5330 * Certain controllers don't report
5331 * carrier sense errors correctly.
5332 * See errata E11_5708CA0_1165.
5334 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5335 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0))
5336 ifp->if_oerrors += (u_long) stats->stat_Dot3StatsCarrierSenseErrors;
5339 * Update the sysctl statistics from the
5340 * hardware statistics.
5342 sc->stat_IfHCInOctets =
5343 ((u64) stats->stat_IfHCInOctets_hi << 32) +
5344 (u64) stats->stat_IfHCInOctets_lo;
5346 sc->stat_IfHCInBadOctets =
5347 ((u64) stats->stat_IfHCInBadOctets_hi << 32) +
5348 (u64) stats->stat_IfHCInBadOctets_lo;
5350 sc->stat_IfHCOutOctets =
5351 ((u64) stats->stat_IfHCOutOctets_hi << 32) +
5352 (u64) stats->stat_IfHCOutOctets_lo;
5354 sc->stat_IfHCOutBadOctets =
5355 ((u64) stats->stat_IfHCOutBadOctets_hi << 32) +
5356 (u64) stats->stat_IfHCOutBadOctets_lo;
5358 sc->stat_IfHCInUcastPkts =
5359 ((u64) stats->stat_IfHCInUcastPkts_hi << 32) +
5360 (u64) stats->stat_IfHCInUcastPkts_lo;
5362 sc->stat_IfHCInMulticastPkts =
5363 ((u64) stats->stat_IfHCInMulticastPkts_hi << 32) +
5364 (u64) stats->stat_IfHCInMulticastPkts_lo;
5366 sc->stat_IfHCInBroadcastPkts =
5367 ((u64) stats->stat_IfHCInBroadcastPkts_hi << 32) +
5368 (u64) stats->stat_IfHCInBroadcastPkts_lo;
5370 sc->stat_IfHCOutUcastPkts =
5371 ((u64) stats->stat_IfHCOutUcastPkts_hi << 32) +
5372 (u64) stats->stat_IfHCOutUcastPkts_lo;
5374 sc->stat_IfHCOutMulticastPkts =
5375 ((u64) stats->stat_IfHCOutMulticastPkts_hi << 32) +
5376 (u64) stats->stat_IfHCOutMulticastPkts_lo;
5378 sc->stat_IfHCOutBroadcastPkts =
5379 ((u64) stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5380 (u64) stats->stat_IfHCOutBroadcastPkts_lo;
5382 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5383 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5385 sc->stat_Dot3StatsCarrierSenseErrors =
5386 stats->stat_Dot3StatsCarrierSenseErrors;
5388 sc->stat_Dot3StatsFCSErrors =
5389 stats->stat_Dot3StatsFCSErrors;
5391 sc->stat_Dot3StatsAlignmentErrors =
5392 stats->stat_Dot3StatsAlignmentErrors;
5394 sc->stat_Dot3StatsSingleCollisionFrames =
5395 stats->stat_Dot3StatsSingleCollisionFrames;
5397 sc->stat_Dot3StatsMultipleCollisionFrames =
5398 stats->stat_Dot3StatsMultipleCollisionFrames;
5400 sc->stat_Dot3StatsDeferredTransmissions =
5401 stats->stat_Dot3StatsDeferredTransmissions;
5403 sc->stat_Dot3StatsExcessiveCollisions =
5404 stats->stat_Dot3StatsExcessiveCollisions;
5406 sc->stat_Dot3StatsLateCollisions =
5407 stats->stat_Dot3StatsLateCollisions;
5409 sc->stat_EtherStatsCollisions =
5410 stats->stat_EtherStatsCollisions;
5412 sc->stat_EtherStatsFragments =
5413 stats->stat_EtherStatsFragments;
5415 sc->stat_EtherStatsJabbers =
5416 stats->stat_EtherStatsJabbers;
5418 sc->stat_EtherStatsUndersizePkts =
5419 stats->stat_EtherStatsUndersizePkts;
5421 sc->stat_EtherStatsOverrsizePkts =
5422 stats->stat_EtherStatsOverrsizePkts;
5424 sc->stat_EtherStatsPktsRx64Octets =
5425 stats->stat_EtherStatsPktsRx64Octets;
5427 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5428 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5430 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5431 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5433 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5434 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5436 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5437 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5439 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5440 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5442 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5443 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5445 sc->stat_EtherStatsPktsTx64Octets =
5446 stats->stat_EtherStatsPktsTx64Octets;
5448 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5449 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5451 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5452 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5454 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5455 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5457 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5458 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5460 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5461 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5463 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5464 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5466 sc->stat_XonPauseFramesReceived =
5467 stats->stat_XonPauseFramesReceived;
5469 sc->stat_XoffPauseFramesReceived =
5470 stats->stat_XoffPauseFramesReceived;
5472 sc->stat_OutXonSent =
5473 stats->stat_OutXonSent;
5475 sc->stat_OutXoffSent =
5476 stats->stat_OutXoffSent;
5478 sc->stat_FlowControlDone =
5479 stats->stat_FlowControlDone;
5481 sc->stat_MacControlFramesReceived =
5482 stats->stat_MacControlFramesReceived;
5484 sc->stat_XoffStateEntered =
5485 stats->stat_XoffStateEntered;
5487 sc->stat_IfInFramesL2FilterDiscards =
5488 stats->stat_IfInFramesL2FilterDiscards;
5490 sc->stat_IfInRuleCheckerDiscards =
5491 stats->stat_IfInRuleCheckerDiscards;
5493 sc->stat_IfInFTQDiscards =
5494 stats->stat_IfInFTQDiscards;
5496 sc->stat_IfInMBUFDiscards =
5497 stats->stat_IfInMBUFDiscards;
5499 sc->stat_IfInRuleCheckerP4Hit =
5500 stats->stat_IfInRuleCheckerP4Hit;
5502 sc->stat_CatchupInRuleCheckerDiscards =
5503 stats->stat_CatchupInRuleCheckerDiscards;
5505 sc->stat_CatchupInFTQDiscards =
5506 stats->stat_CatchupInFTQDiscards;
5508 sc->stat_CatchupInMBUFDiscards =
5509 stats->stat_CatchupInMBUFDiscards;
5511 sc->stat_CatchupInRuleCheckerP4Hit =
5512 stats->stat_CatchupInRuleCheckerP4Hit;
5514 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __FUNCTION__);
5519 bce_tick_locked(struct bce_softc *sc)
5521 struct mii_data *mii = NULL;
5527 BCE_LOCK_ASSERT(sc);
5529 /* Tell the firmware that the driver is still running. */
5531 msg = (u32) BCE_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE;
5533 msg = (u32) ++sc->bce_fw_drv_pulse_wr_seq;
5535 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_PULSE_MB, msg);
5537 /* Update the statistics from the hardware statistics block. */
5538 bce_stats_update(sc);
5540 /* Schedule the next tick. */
5542 &sc->bce_stat_ch, /* callout */
5544 bce_tick, /* function */
5545 sc); /* function argument */
5547 /* If link is up already up then we're done. */
5549 goto bce_tick_locked_exit;
5551 /* DRC - ToDo: Add SerDes support and check SerDes link here. */
5553 mii = device_get_softc(sc->bce_miibus);
5556 /* Check if the link has come up. */
5557 if (!sc->bce_link && mii->mii_media_status & IFM_ACTIVE &&
5558 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5560 if ((IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
5561 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) &&
5563 BCE_PRINTF(sc, "Gigabit link up\n");
5564 /* Now that link is up, handle any outstanding TX traffic. */
5565 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
5566 bce_start_locked(ifp);
5569 bce_tick_locked_exit:
5577 struct bce_softc *sc;
5582 bce_tick_locked(sc);
5588 /****************************************************************************/
5589 /* Allows the driver state to be dumped through the sysctl interface. */
5592 /* 0 for success, positive value for failure. */
5593 /****************************************************************************/
5595 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5599 struct bce_softc *sc;
5602 error = sysctl_handle_int(oidp, &result, 0, req);
5604 if (error || !req->newptr)
5608 sc = (struct bce_softc *)arg1;
5609 bce_dump_driver_state(sc);
5616 /****************************************************************************/
5617 /* Allows the hardware state to be dumped through the sysctl interface. */
5620 /* 0 for success, positive value for failure. */
5621 /****************************************************************************/
5623 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5627 struct bce_softc *sc;
5630 error = sysctl_handle_int(oidp, &result, 0, req);
5632 if (error || !req->newptr)
5636 sc = (struct bce_softc *)arg1;
5637 bce_dump_hw_state(sc);
5644 /****************************************************************************/
5648 /* 0 for success, positive value for failure. */
5649 /****************************************************************************/
5651 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5655 struct bce_softc *sc;
5658 error = sysctl_handle_int(oidp, &result, 0, req);
5660 if (error || !req->newptr)
5664 sc = (struct bce_softc *)arg1;
5665 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
5672 /****************************************************************************/
5676 /* 0 for success, positive value for failure. */
5677 /****************************************************************************/
5679 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
5683 struct bce_softc *sc;
5686 error = sysctl_handle_int(oidp, &result, 0, req);
5688 if (error || !req->newptr)
5692 sc = (struct bce_softc *)arg1;
5701 /****************************************************************************/
5702 /* Adds any sysctl parameters for tuning or debugging purposes. */
5705 /* 0 for success, positive value for failure. */
5706 /****************************************************************************/
5708 bce_add_sysctls(struct bce_softc *sc)
5710 struct sysctl_ctx_list *ctx;
5711 struct sysctl_oid_list *children;
5713 ctx = device_get_sysctl_ctx(sc->bce_dev);
5714 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->bce_dev));
5716 SYSCTL_ADD_STRING(ctx, children, OID_AUTO,
5718 CTLFLAG_RD, &bce_driver_version,
5719 0, "bce driver version");
5722 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5724 CTLFLAG_RD, &sc->rx_low_watermark,
5725 0, "Lowest level of free rx_bd's");
5727 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5729 CTLFLAG_RD, &sc->tx_hi_watermark,
5730 0, "Highest level of used tx_bd's");
5732 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5733 "l2fhdr_status_errors",
5734 CTLFLAG_RD, &sc->l2fhdr_status_errors,
5735 0, "l2_fhdr status errors");
5737 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5738 "unexpected_attentions",
5739 CTLFLAG_RD, &sc->unexpected_attentions,
5740 0, "unexpected attentions");
5742 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5743 "lost_status_block_updates",
5744 CTLFLAG_RD, &sc->lost_status_block_updates,
5745 0, "lost status block updates");
5747 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5748 "mbuf_alloc_failed",
5749 CTLFLAG_RD, &sc->mbuf_alloc_failed,
5750 0, "mbuf cluster allocation failures");
5753 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5754 "stat_IfHcInOctets",
5755 CTLFLAG_RD, &sc->stat_IfHCInOctets,
5758 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5759 "stat_IfHCInBadOctets",
5760 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
5761 "Bad bytes received");
5763 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5764 "stat_IfHCOutOctets",
5765 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
5768 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5769 "stat_IfHCOutBadOctets",
5770 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
5773 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5774 "stat_IfHCInUcastPkts",
5775 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
5776 "Unicast packets received");
5778 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5779 "stat_IfHCInMulticastPkts",
5780 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
5781 "Multicast packets received");
5783 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5784 "stat_IfHCInBroadcastPkts",
5785 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
5786 "Broadcast packets received");
5788 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5789 "stat_IfHCOutUcastPkts",
5790 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
5791 "Unicast packets sent");
5793 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5794 "stat_IfHCOutMulticastPkts",
5795 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
5796 "Multicast packets sent");
5798 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5799 "stat_IfHCOutBroadcastPkts",
5800 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
5801 "Broadcast packets sent");
5803 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5804 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
5805 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
5806 0, "Internal MAC transmit errors");
5808 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5809 "stat_Dot3StatsCarrierSenseErrors",
5810 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
5811 0, "Carrier sense errors");
5813 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5814 "stat_Dot3StatsFCSErrors",
5815 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
5816 0, "Frame check sequence errors");
5818 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5819 "stat_Dot3StatsAlignmentErrors",
5820 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
5821 0, "Alignment errors");
5823 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5824 "stat_Dot3StatsSingleCollisionFrames",
5825 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
5826 0, "Single Collision Frames");
5828 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5829 "stat_Dot3StatsMultipleCollisionFrames",
5830 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
5831 0, "Multiple Collision Frames");
5833 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5834 "stat_Dot3StatsDeferredTransmissions",
5835 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
5836 0, "Deferred Transmissions");
5838 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5839 "stat_Dot3StatsExcessiveCollisions",
5840 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
5841 0, "Excessive Collisions");
5843 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5844 "stat_Dot3StatsLateCollisions",
5845 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
5846 0, "Late Collisions");
5848 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5849 "stat_EtherStatsCollisions",
5850 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
5853 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5854 "stat_EtherStatsFragments",
5855 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
5858 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5859 "stat_EtherStatsJabbers",
5860 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
5863 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5864 "stat_EtherStatsUndersizePkts",
5865 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
5866 0, "Undersize packets");
5868 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5869 "stat_EtherStatsOverrsizePkts",
5870 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
5871 0, "stat_EtherStatsOverrsizePkts");
5873 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5874 "stat_EtherStatsPktsRx64Octets",
5875 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
5876 0, "Bytes received in 64 byte packets");
5878 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5879 "stat_EtherStatsPktsRx65Octetsto127Octets",
5880 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
5881 0, "Bytes received in 65 to 127 byte packets");
5883 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5884 "stat_EtherStatsPktsRx128Octetsto255Octets",
5885 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
5886 0, "Bytes received in 128 to 255 byte packets");
5888 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5889 "stat_EtherStatsPktsRx256Octetsto511Octets",
5890 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
5891 0, "Bytes received in 256 to 511 byte packets");
5893 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5894 "stat_EtherStatsPktsRx512Octetsto1023Octets",
5895 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
5896 0, "Bytes received in 512 to 1023 byte packets");
5898 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5899 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
5900 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
5901 0, "Bytes received in 1024 t0 1522 byte packets");
5903 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5904 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
5905 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
5906 0, "Bytes received in 1523 to 9022 byte packets");
5908 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5909 "stat_EtherStatsPktsTx64Octets",
5910 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
5911 0, "Bytes sent in 64 byte packets");
5913 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5914 "stat_EtherStatsPktsTx65Octetsto127Octets",
5915 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
5916 0, "Bytes sent in 65 to 127 byte packets");
5918 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5919 "stat_EtherStatsPktsTx128Octetsto255Octets",
5920 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
5921 0, "Bytes sent in 128 to 255 byte packets");
5923 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5924 "stat_EtherStatsPktsTx256Octetsto511Octets",
5925 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
5926 0, "Bytes sent in 256 to 511 byte packets");
5928 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5929 "stat_EtherStatsPktsTx512Octetsto1023Octets",
5930 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
5931 0, "Bytes sent in 512 to 1023 byte packets");
5933 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5934 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
5935 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
5936 0, "Bytes sent in 1024 to 1522 byte packets");
5938 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5939 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
5940 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
5941 0, "Bytes sent in 1523 to 9022 byte packets");
5943 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5944 "stat_XonPauseFramesReceived",
5945 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
5946 0, "XON pause frames receved");
5948 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5949 "stat_XoffPauseFramesReceived",
5950 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
5951 0, "XOFF pause frames received");
5953 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5955 CTLFLAG_RD, &sc->stat_OutXonSent,
5956 0, "XON pause frames sent");
5958 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5960 CTLFLAG_RD, &sc->stat_OutXoffSent,
5961 0, "XOFF pause frames sent");
5963 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5964 "stat_FlowControlDone",
5965 CTLFLAG_RD, &sc->stat_FlowControlDone,
5966 0, "Flow control done");
5968 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5969 "stat_MacControlFramesReceived",
5970 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
5971 0, "MAC control frames received");
5973 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5974 "stat_XoffStateEntered",
5975 CTLFLAG_RD, &sc->stat_XoffStateEntered,
5976 0, "XOFF state entered");
5978 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5979 "stat_IfInFramesL2FilterDiscards",
5980 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
5981 0, "Received L2 packets discarded");
5983 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5984 "stat_IfInRuleCheckerDiscards",
5985 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
5986 0, "Received packets discarded by rule");
5988 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5989 "stat_IfInFTQDiscards",
5990 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
5991 0, "Received packet FTQ discards");
5993 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5994 "stat_IfInMBUFDiscards",
5995 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
5996 0, "Received packets discarded due to lack of controller buffer memory");
5998 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5999 "stat_IfInRuleCheckerP4Hit",
6000 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
6001 0, "Received packets rule checker hits");
6003 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6004 "stat_CatchupInRuleCheckerDiscards",
6005 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
6006 0, "Received packets discarded in Catchup path");
6008 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6009 "stat_CatchupInFTQDiscards",
6010 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
6011 0, "Received packets discarded in FTQ in Catchup path");
6013 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6014 "stat_CatchupInMBUFDiscards",
6015 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
6016 0, "Received packets discarded in controller buffer memory in Catchup path");
6018 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6019 "stat_CatchupInRuleCheckerP4Hit",
6020 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
6021 0, "Received packets rule checker hits in Catchup path");
6024 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6025 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
6027 bce_sysctl_driver_state, "I", "Drive state information");
6029 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6030 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
6032 bce_sysctl_hw_state, "I", "Hardware state information");
6034 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6035 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
6037 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
6039 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6040 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
6042 bce_sysctl_breakpoint, "I", "Driver breakpoint");
6048 /****************************************************************************/
6049 /* BCE Debug Routines */
6050 /****************************************************************************/
6053 /****************************************************************************/
6054 /* Prints out information about an mbuf. */
6058 /****************************************************************************/
6060 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6063 struct mbuf *mp = m;
6066 /* Index out of range. */
6067 printf("mbuf ptr is null!\n");
6072 val_hi = BCE_ADDR_HI(mp);
6073 val_lo = BCE_ADDR_LO(mp);
6074 BCE_PRINTF(sc, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, m_flags = ",
6075 val_hi, val_lo, mp->m_len);
6077 if (mp->m_flags & M_EXT)
6079 if (mp->m_flags & M_PKTHDR)
6080 printf("M_PKTHDR ");
6083 if (mp->m_flags & M_EXT) {
6084 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6085 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6086 BCE_PRINTF(sc, "- m_ext: vaddr = 0x%08X:%08X, ext_size = 0x%04X\n",
6087 val_hi, val_lo, mp->m_ext.ext_size);
6097 /****************************************************************************/
6098 /* Prints out the mbufs in the TX mbuf chain. */
6102 /****************************************************************************/
6104 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6109 "----------------------------"
6111 "----------------------------\n");
6113 for (int i = 0; i < count; i++) {
6114 m = sc->tx_mbuf_ptr[chain_prod];
6115 BCE_PRINTF(sc, "txmbuf[%d]\n", chain_prod);
6116 bce_dump_mbuf(sc, m);
6117 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6121 "----------------------------"
6123 "----------------------------\n");
6128 * This routine prints the RX mbuf chain.
6131 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6136 "----------------------------"
6138 "----------------------------\n");
6140 for (int i = 0; i < count; i++) {
6141 m = sc->rx_mbuf_ptr[chain_prod];
6142 BCE_PRINTF(sc, "rxmbuf[0x%04X]\n", chain_prod);
6143 bce_dump_mbuf(sc, m);
6144 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6149 "----------------------------"
6151 "----------------------------\n");
6156 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6158 if (idx > MAX_TX_BD)
6159 /* Index out of range. */
6160 BCE_PRINTF(sc, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6161 else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
6162 /* TX Chain page pointer. */
6163 BCE_PRINTF(sc, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page pointer\n",
6164 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6166 /* Normal tx_bd entry. */
6167 BCE_PRINTF(sc, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = 0x%08X, "
6168 "flags = 0x%08X\n", idx,
6169 txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6170 txbd->tx_bd_mss_nbytes, txbd->tx_bd_vlan_tag_flags);
6175 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6177 if (idx > MAX_RX_BD)
6178 /* Index out of range. */
6179 BCE_PRINTF(sc, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6180 else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
6181 /* TX Chain page pointer. */
6182 BCE_PRINTF(sc, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page pointer\n",
6183 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6185 /* Normal tx_bd entry. */
6186 BCE_PRINTF(sc, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = 0x%08X, "
6187 "flags = 0x%08X\n", idx,
6188 rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6189 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6194 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6196 BCE_PRINTF(sc, "l2_fhdr[0x%04X]: status = 0x%08X, "
6197 "pkt_len = 0x%04X, vlan = 0x%04x, ip_xsum = 0x%04X, "
6198 "tcp_udp_xsum = 0x%04X\n", idx,
6199 l2fhdr->l2_fhdr_status, l2fhdr->l2_fhdr_pkt_len,
6200 l2fhdr->l2_fhdr_vlan_tag, l2fhdr->l2_fhdr_ip_xsum,
6201 l2fhdr->l2_fhdr_tcp_udp_xsum);
6206 * This routine prints the TX chain.
6209 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6213 /* First some info about the tx_bd chain structure. */
6215 "----------------------------"
6217 "----------------------------\n");
6219 BCE_PRINTF(sc, "page size = 0x%08X, tx chain pages = 0x%08X\n",
6220 (u32) BCM_PAGE_SIZE, (u32) TX_PAGES);
6222 BCE_PRINTF(sc, "tx_bd per page = 0x%08X, usable tx_bd per page = 0x%08X\n",
6223 (u32) TOTAL_TX_BD_PER_PAGE, (u32) USABLE_TX_BD_PER_PAGE);
6225 BCE_PRINTF(sc, "total tx_bd = 0x%08X\n", (u32) TOTAL_TX_BD);
6228 "-----------------------------"
6230 "-----------------------------\n");
6232 /* Now print out the tx_bd's themselves. */
6233 for (int i = 0; i < count; i++) {
6234 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6235 bce_dump_txbd(sc, tx_prod, txbd);
6236 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6240 "-----------------------------"
6242 "-----------------------------\n");
6247 * This routine prints the RX chain.
6250 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6254 /* First some info about the tx_bd chain structure. */
6256 "----------------------------"
6258 "----------------------------\n");
6260 BCE_PRINTF(sc, "----- RX_BD Chain -----\n");
6262 BCE_PRINTF(sc, "page size = 0x%08X, rx chain pages = 0x%08X\n",
6263 (u32) BCM_PAGE_SIZE, (u32) RX_PAGES);
6265 BCE_PRINTF(sc, "rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
6266 (u32) TOTAL_RX_BD_PER_PAGE, (u32) USABLE_RX_BD_PER_PAGE);
6268 BCE_PRINTF(sc, "total rx_bd = 0x%08X\n", (u32) TOTAL_RX_BD);
6271 "----------------------------"
6273 "----------------------------\n");
6275 /* Now print out the rx_bd's themselves. */
6276 for (int i = 0; i < count; i++) {
6277 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6278 bce_dump_rxbd(sc, rx_prod, rxbd);
6279 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6283 "----------------------------"
6285 "----------------------------\n");
6290 * This routine prints the status block.
6293 bce_dump_status_block(struct bce_softc *sc)
6295 struct status_block *sblk;
6297 sblk = sc->status_block;
6299 BCE_PRINTF(sc, "----------------------------- Status Block "
6300 "-----------------------------\n");
6302 BCE_PRINTF(sc, "attn_bits = 0x%08X, attn_bits_ack = 0x%08X, index = 0x%04X\n",
6303 sblk->status_attn_bits, sblk->status_attn_bits_ack,
6306 BCE_PRINTF(sc, "rx_cons0 = 0x%08X, tx_cons0 = 0x%08X\n",
6307 sblk->status_rx_quick_consumer_index0,
6308 sblk->status_tx_quick_consumer_index0);
6310 BCE_PRINTF(sc, "status_idx = 0x%04X\n", sblk->status_idx);
6312 /* Theses indices are not used for normal L2 drivers. */
6313 if (sblk->status_rx_quick_consumer_index1 ||
6314 sblk->status_tx_quick_consumer_index1)
6315 BCE_PRINTF(sc, "rx_cons1 = 0x%08X, tx_cons1 = 0x%08X\n",
6316 sblk->status_rx_quick_consumer_index1,
6317 sblk->status_tx_quick_consumer_index1);
6319 if (sblk->status_rx_quick_consumer_index2 ||
6320 sblk->status_tx_quick_consumer_index2)
6321 BCE_PRINTF(sc, "rx_cons2 = 0x%08X, tx_cons2 = 0x%08X\n",
6322 sblk->status_rx_quick_consumer_index2,
6323 sblk->status_tx_quick_consumer_index2);
6325 if (sblk->status_rx_quick_consumer_index3 ||
6326 sblk->status_tx_quick_consumer_index3)
6327 BCE_PRINTF(sc, "rx_cons3 = 0x%08X, tx_cons3 = 0x%08X\n",
6328 sblk->status_rx_quick_consumer_index3,
6329 sblk->status_tx_quick_consumer_index3);
6331 if (sblk->status_rx_quick_consumer_index4 ||
6332 sblk->status_rx_quick_consumer_index5)
6333 BCE_PRINTF(sc, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6334 sblk->status_rx_quick_consumer_index4,
6335 sblk->status_rx_quick_consumer_index5);
6337 if (sblk->status_rx_quick_consumer_index6 ||
6338 sblk->status_rx_quick_consumer_index7)
6339 BCE_PRINTF(sc, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6340 sblk->status_rx_quick_consumer_index6,
6341 sblk->status_rx_quick_consumer_index7);
6343 if (sblk->status_rx_quick_consumer_index8 ||
6344 sblk->status_rx_quick_consumer_index9)
6345 BCE_PRINTF(sc, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6346 sblk->status_rx_quick_consumer_index8,
6347 sblk->status_rx_quick_consumer_index9);
6349 if (sblk->status_rx_quick_consumer_index10 ||
6350 sblk->status_rx_quick_consumer_index11)
6351 BCE_PRINTF(sc, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6352 sblk->status_rx_quick_consumer_index10,
6353 sblk->status_rx_quick_consumer_index11);
6355 if (sblk->status_rx_quick_consumer_index12 ||
6356 sblk->status_rx_quick_consumer_index13)
6357 BCE_PRINTF(sc, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6358 sblk->status_rx_quick_consumer_index12,
6359 sblk->status_rx_quick_consumer_index13);
6361 if (sblk->status_rx_quick_consumer_index14 ||
6362 sblk->status_rx_quick_consumer_index15)
6363 BCE_PRINTF(sc, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6364 sblk->status_rx_quick_consumer_index14,
6365 sblk->status_rx_quick_consumer_index15);
6367 if (sblk->status_completion_producer_index ||
6368 sblk->status_cmd_consumer_index)
6369 BCE_PRINTF(sc, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6370 sblk->status_completion_producer_index,
6371 sblk->status_cmd_consumer_index);
6373 BCE_PRINTF(sc, "-------------------------------------------"
6374 "-----------------------------\n");
6379 * This routine prints the statistics block.
6382 bce_dump_stats_block(struct bce_softc *sc)
6384 struct statistics_block *sblk;
6386 sblk = sc->stats_block;
6389 "-----------------------------"
6391 "-----------------------------\n");
6393 BCE_PRINTF(sc, "IfHcInOctets = 0x%08X:%08X, "
6394 "IfHcInBadOctets = 0x%08X:%08X\n",
6395 sblk->stat_IfHCInOctets_hi, sblk->stat_IfHCInOctets_lo,
6396 sblk->stat_IfHCInBadOctets_hi, sblk->stat_IfHCInBadOctets_lo);
6398 BCE_PRINTF(sc, "IfHcOutOctets = 0x%08X:%08X, "
6399 "IfHcOutBadOctets = 0x%08X:%08X\n",
6400 sblk->stat_IfHCOutOctets_hi, sblk->stat_IfHCOutOctets_lo,
6401 sblk->stat_IfHCOutBadOctets_hi, sblk->stat_IfHCOutBadOctets_lo);
6403 BCE_PRINTF(sc, "IfHcInUcastPkts = 0x%08X:%08X, "
6404 "IfHcInMulticastPkts = 0x%08X:%08X\n",
6405 sblk->stat_IfHCInUcastPkts_hi, sblk->stat_IfHCInUcastPkts_lo,
6406 sblk->stat_IfHCInMulticastPkts_hi, sblk->stat_IfHCInMulticastPkts_lo);
6408 BCE_PRINTF(sc, "IfHcInBroadcastPkts = 0x%08X:%08X, "
6409 "IfHcOutUcastPkts = 0x%08X:%08X\n",
6410 sblk->stat_IfHCInBroadcastPkts_hi, sblk->stat_IfHCInBroadcastPkts_lo,
6411 sblk->stat_IfHCOutUcastPkts_hi, sblk->stat_IfHCOutUcastPkts_lo);
6413 BCE_PRINTF(sc, "IfHcOutMulticastPkts = 0x%08X:%08X, IfHcOutBroadcastPkts = 0x%08X:%08X\n",
6414 sblk->stat_IfHCOutMulticastPkts_hi, sblk->stat_IfHCOutMulticastPkts_lo,
6415 sblk->stat_IfHCOutBroadcastPkts_hi, sblk->stat_IfHCOutBroadcastPkts_lo);
6417 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors)
6418 BCE_PRINTF(sc, "0x%08X : "
6419 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
6420 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
6422 if (sblk->stat_Dot3StatsCarrierSenseErrors)
6423 BCE_PRINTF(sc, "0x%08X : Dot3StatsCarrierSenseErrors\n",
6424 sblk->stat_Dot3StatsCarrierSenseErrors);
6426 if (sblk->stat_Dot3StatsFCSErrors)
6427 BCE_PRINTF(sc, "0x%08X : Dot3StatsFCSErrors\n",
6428 sblk->stat_Dot3StatsFCSErrors);
6430 if (sblk->stat_Dot3StatsAlignmentErrors)
6431 BCE_PRINTF(sc, "0x%08X : Dot3StatsAlignmentErrors\n",
6432 sblk->stat_Dot3StatsAlignmentErrors);
6434 if (sblk->stat_Dot3StatsSingleCollisionFrames)
6435 BCE_PRINTF(sc, "0x%08X : Dot3StatsSingleCollisionFrames\n",
6436 sblk->stat_Dot3StatsSingleCollisionFrames);
6438 if (sblk->stat_Dot3StatsMultipleCollisionFrames)
6439 BCE_PRINTF(sc, "0x%08X : Dot3StatsMultipleCollisionFrames\n",
6440 sblk->stat_Dot3StatsMultipleCollisionFrames);
6442 if (sblk->stat_Dot3StatsDeferredTransmissions)
6443 BCE_PRINTF(sc, "0x%08X : Dot3StatsDeferredTransmissions\n",
6444 sblk->stat_Dot3StatsDeferredTransmissions);
6446 if (sblk->stat_Dot3StatsExcessiveCollisions)
6447 BCE_PRINTF(sc, "0x%08X : Dot3StatsExcessiveCollisions\n",
6448 sblk->stat_Dot3StatsExcessiveCollisions);
6450 if (sblk->stat_Dot3StatsLateCollisions)
6451 BCE_PRINTF(sc, "0x%08X : Dot3StatsLateCollisions\n",
6452 sblk->stat_Dot3StatsLateCollisions);
6454 if (sblk->stat_EtherStatsCollisions)
6455 BCE_PRINTF(sc, "0x%08X : EtherStatsCollisions\n",
6456 sblk->stat_EtherStatsCollisions);
6458 if (sblk->stat_EtherStatsFragments)
6459 BCE_PRINTF(sc, "0x%08X : EtherStatsFragments\n",
6460 sblk->stat_EtherStatsFragments);
6462 if (sblk->stat_EtherStatsJabbers)
6463 BCE_PRINTF(sc, "0x%08X : EtherStatsJabbers\n",
6464 sblk->stat_EtherStatsJabbers);
6466 if (sblk->stat_EtherStatsUndersizePkts)
6467 BCE_PRINTF(sc, "0x%08X : EtherStatsUndersizePkts\n",
6468 sblk->stat_EtherStatsUndersizePkts);
6470 if (sblk->stat_EtherStatsOverrsizePkts)
6471 BCE_PRINTF(sc, "0x%08X : EtherStatsOverrsizePkts\n",
6472 sblk->stat_EtherStatsOverrsizePkts);
6474 if (sblk->stat_EtherStatsPktsRx64Octets)
6475 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx64Octets\n",
6476 sblk->stat_EtherStatsPktsRx64Octets);
6478 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets)
6479 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx65Octetsto127Octets\n",
6480 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
6482 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets)
6483 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx128Octetsto255Octets\n",
6484 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
6486 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets)
6487 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx256Octetsto511Octets\n",
6488 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
6490 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets)
6491 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx512Octetsto1023Octets\n",
6492 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
6494 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets)
6495 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx1024Octetsto1522Octets\n",
6496 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
6498 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets)
6499 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsRx1523Octetsto9022Octets\n",
6500 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
6502 if (sblk->stat_EtherStatsPktsTx64Octets)
6503 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx64Octets\n",
6504 sblk->stat_EtherStatsPktsTx64Octets);
6506 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets)
6507 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx65Octetsto127Octets\n",
6508 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
6510 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets)
6511 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx128Octetsto255Octets\n",
6512 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
6514 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets)
6515 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx256Octetsto511Octets\n",
6516 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
6518 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets)
6519 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx512Octetsto1023Octets\n",
6520 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
6522 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets)
6523 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx1024Octetsto1522Octets\n",
6524 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
6526 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets)
6527 BCE_PRINTF(sc, "0x%08X : EtherStatsPktsTx1523Octetsto9022Octets\n",
6528 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
6530 if (sblk->stat_XonPauseFramesReceived)
6531 BCE_PRINTF(sc, "0x%08X : XonPauseFramesReceived\n",
6532 sblk->stat_XonPauseFramesReceived);
6534 if (sblk->stat_XoffPauseFramesReceived)
6535 BCE_PRINTF(sc, "0x%08X : XoffPauseFramesReceived\n",
6536 sblk->stat_XoffPauseFramesReceived);
6538 if (sblk->stat_OutXonSent)
6539 BCE_PRINTF(sc, "0x%08X : OutXonSent\n",
6540 sblk->stat_OutXonSent);
6542 if (sblk->stat_OutXoffSent)
6543 BCE_PRINTF(sc, "0x%08X : OutXoffSent\n",
6544 sblk->stat_OutXoffSent);
6546 if (sblk->stat_FlowControlDone)
6547 BCE_PRINTF(sc, "0x%08X : FlowControlDone\n",
6548 sblk->stat_FlowControlDone);
6550 if (sblk->stat_MacControlFramesReceived)
6551 BCE_PRINTF(sc, "0x%08X : MacControlFramesReceived\n",
6552 sblk->stat_MacControlFramesReceived);
6554 if (sblk->stat_XoffStateEntered)
6555 BCE_PRINTF(sc, "0x%08X : XoffStateEntered\n",
6556 sblk->stat_XoffStateEntered);
6558 if (sblk->stat_IfInFramesL2FilterDiscards)
6559 BCE_PRINTF(sc, "0x%08X : IfInFramesL2FilterDiscards\n",
6560 sblk->stat_IfInFramesL2FilterDiscards);
6562 if (sblk->stat_IfInRuleCheckerDiscards)
6563 BCE_PRINTF(sc, "0x%08X : IfInRuleCheckerDiscards\n",
6564 sblk->stat_IfInRuleCheckerDiscards);
6566 if (sblk->stat_IfInFTQDiscards)
6567 BCE_PRINTF(sc, "0x%08X : IfInFTQDiscards\n",
6568 sblk->stat_IfInFTQDiscards);
6570 if (sblk->stat_IfInMBUFDiscards)
6571 BCE_PRINTF(sc, "0x%08X : IfInMBUFDiscards\n",
6572 sblk->stat_IfInMBUFDiscards);
6574 if (sblk->stat_IfInRuleCheckerP4Hit)
6575 BCE_PRINTF(sc, "0x%08X : IfInRuleCheckerP4Hit\n",
6576 sblk->stat_IfInRuleCheckerP4Hit);
6578 if (sblk->stat_CatchupInRuleCheckerDiscards)
6579 BCE_PRINTF(sc, "0x%08X : CatchupInRuleCheckerDiscards\n",
6580 sblk->stat_CatchupInRuleCheckerDiscards);
6582 if (sblk->stat_CatchupInFTQDiscards)
6583 BCE_PRINTF(sc, "0x%08X : CatchupInFTQDiscards\n",
6584 sblk->stat_CatchupInFTQDiscards);
6586 if (sblk->stat_CatchupInMBUFDiscards)
6587 BCE_PRINTF(sc, "0x%08X : CatchupInMBUFDiscards\n",
6588 sblk->stat_CatchupInMBUFDiscards);
6590 if (sblk->stat_CatchupInRuleCheckerP4Hit)
6591 BCE_PRINTF(sc, "0x%08X : CatchupInRuleCheckerP4Hit\n",
6592 sblk->stat_CatchupInRuleCheckerP4Hit);
6595 "-----------------------------"
6597 "-----------------------------\n");
6602 bce_dump_driver_state(struct bce_softc *sc)
6607 "-----------------------------"
6609 "-----------------------------\n");
6611 val_hi = BCE_ADDR_HI(sc);
6612 val_lo = BCE_ADDR_LO(sc);
6613 BCE_PRINTF(sc, "0x%08X:%08X - (sc) driver softc structure virtual address\n",
6616 val_hi = BCE_ADDR_HI(sc->bce_vhandle);
6617 val_lo = BCE_ADDR_LO(sc->bce_vhandle);
6618 BCE_PRINTF(sc, "0x%08X:%08X - (sc->bce_vhandle) PCI BAR virtual address\n",
6621 val_hi = BCE_ADDR_HI(sc->status_block);
6622 val_lo = BCE_ADDR_LO(sc->status_block);
6623 BCE_PRINTF(sc, "0x%08X:%08X - (sc->status_block) status block virtual address\n",
6626 val_hi = BCE_ADDR_HI(sc->stats_block);
6627 val_lo = BCE_ADDR_LO(sc->stats_block);
6628 BCE_PRINTF(sc, "0x%08X:%08X - (sc->stats_block) statistics block virtual address\n",
6631 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
6632 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
6634 "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain virtual adddress\n",
6637 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
6638 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
6640 "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain virtual address\n",
6643 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
6644 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
6646 "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain virtual address\n",
6649 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
6650 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
6652 "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain virtual address\n",
6655 BCE_PRINTF(sc, " 0x%08X - (sc->interrupts_generated) h/w intrs\n",
6656 sc->interrupts_generated);
6658 BCE_PRINTF(sc, " 0x%08X - (sc->rx_interrupts) rx interrupts handled\n",
6661 BCE_PRINTF(sc, " 0x%08X - (sc->tx_interrupts) tx interrupts handled\n",
6664 BCE_PRINTF(sc, " 0x%08X - (sc->last_status_idx) status block index\n",
6665 sc->last_status_idx);
6667 BCE_PRINTF(sc, " 0x%08X - (sc->tx_prod) tx producer index\n",
6670 BCE_PRINTF(sc, " 0x%08X - (sc->tx_cons) tx consumer index\n",
6673 BCE_PRINTF(sc, " 0x%08X - (sc->tx_prod_bseq) tx producer bseq index\n",
6676 BCE_PRINTF(sc, " 0x%08X - (sc->rx_prod) rx producer index\n",
6679 BCE_PRINTF(sc, " 0x%08X - (sc->rx_cons) rx consumer index\n",
6682 BCE_PRINTF(sc, " 0x%08X - (sc->rx_prod_bseq) rx producer bseq index\n",
6685 BCE_PRINTF(sc, " 0x%08X - (sc->rx_mbuf_alloc) rx mbufs allocated\n",
6688 BCE_PRINTF(sc, " 0x%08X - (sc->free_rx_bd) free rx_bd's\n",
6691 BCE_PRINTF(sc, "0x%08X/%08X - (sc->rx_low_watermark) rx low watermark\n",
6692 sc->rx_low_watermark, (u32) USABLE_RX_BD);
6694 BCE_PRINTF(sc, " 0x%08X - (sc->txmbuf_alloc) tx mbufs allocated\n",
6697 BCE_PRINTF(sc, " 0x%08X - (sc->rx_mbuf_alloc) rx mbufs allocated\n",
6700 BCE_PRINTF(sc, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
6703 BCE_PRINTF(sc, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
6704 sc->tx_hi_watermark, (u32) USABLE_TX_BD);
6706 BCE_PRINTF(sc, " 0x%08X - (sc->mbuf_alloc_failed) failed mbuf alloc\n",
6707 sc->mbuf_alloc_failed);
6710 "-----------------------------"
6712 "-----------------------------\n");
6717 bce_dump_hw_state(struct bce_softc *sc)
6722 "----------------------------"
6724 "----------------------------\n");
6726 BCE_PRINTF(sc, "0x%08X : bootcode version\n", sc->bce_fw_ver);
6728 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
6729 BCE_PRINTF(sc, "0x%08X : (0x%04X) misc_enable_status_bits\n",
6730 val1, BCE_MISC_ENABLE_STATUS_BITS);
6732 val1 = REG_RD(sc, BCE_DMA_STATUS);
6733 BCE_PRINTF(sc, "0x%08X : (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
6735 val1 = REG_RD(sc, BCE_CTX_STATUS);
6736 BCE_PRINTF(sc, "0x%08X : (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
6738 val1 = REG_RD(sc, BCE_EMAC_STATUS);
6739 BCE_PRINTF(sc, "0x%08X : (0x%04X) emac_status\n", val1, BCE_EMAC_STATUS);
6741 val1 = REG_RD(sc, BCE_RPM_STATUS);
6742 BCE_PRINTF(sc, "0x%08X : (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
6744 val1 = REG_RD(sc, BCE_TBDR_STATUS);
6745 BCE_PRINTF(sc, "0x%08X : (0x%04X) tbdr_status\n", val1, BCE_TBDR_STATUS);
6747 val1 = REG_RD(sc, BCE_TDMA_STATUS);
6748 BCE_PRINTF(sc, "0x%08X : (0x%04X) tdma_status\n", val1, BCE_TDMA_STATUS);
6750 val1 = REG_RD(sc, BCE_HC_STATUS);
6751 BCE_PRINTF(sc, "0x%08X : (0x%04X) hc_status\n", val1, BCE_HC_STATUS);
6754 "----------------------------"
6756 "----------------------------\n");
6759 "----------------------------"
6761 "----------------------------\n");
6763 for (int i = 0x400; i < 0x8000; i += 0x10)
6764 BCE_PRINTF(sc, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
6765 i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
6766 REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
6769 "----------------------------"
6771 "----------------------------\n");
6776 bce_breakpoint(struct bce_softc *sc)
6779 /* Unreachable code to shut the compiler up about unused functions. */
6781 bce_dump_txbd(sc, 0, NULL);
6782 bce_dump_rxbd(sc, 0, NULL);
6783 bce_dump_tx_mbuf_chain(sc, 0, USABLE_TX_BD);
6784 bce_dump_rx_mbuf_chain(sc, 0, USABLE_RX_BD);
6785 bce_dump_l2fhdr(sc, 0, NULL);
6786 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
6787 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
6788 bce_dump_status_block(sc);
6789 bce_dump_stats_block(sc);
6790 bce_dump_driver_state(sc);
6791 bce_dump_hw_state(sc);
6794 bce_dump_driver_state(sc);
6795 /* Print the important status block fields. */
6796 bce_dump_status_block(sc);
6798 /* Call the debugger. */