2 * Copyright (c) 2007-2013 Broadcom Corporation. All rights reserved.
4 * Eric Davis <edavis@broadcom.com>
5 * David Christensen <davidch@broadcom.com>
6 * Gary Zambrano <zambrano@broadcom.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Broadcom Corporation nor the name of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written consent.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
40 #include "ddb/db_sym.h"
41 #include "ddb/db_lex.h"
43 #ifdef BXE_REG_NO_INLINE
46 * Debug versions of the 8/16/32 bit OS register read/write functions to
47 * capture/display values read/written from/to the controller.
51 bxe_reg_write8(struct bxe_softc *sc, bus_size_t offset, uint8_t val)
53 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%02x\n", offset, val);
54 bus_space_write_1(sc->bar[BAR0].tag,
61 bxe_reg_write16(struct bxe_softc *sc, bus_size_t offset, uint16_t val)
63 if ((offset % 2) != 0) {
64 BLOGD(sc, DBG_REGS, "Unaligned 16-bit write to 0x%08lx\n", offset);
67 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%04x\n", offset, val);
68 bus_space_write_2(sc->bar[BAR0].tag,
75 bxe_reg_write32(struct bxe_softc *sc, bus_size_t offset, uint32_t val)
77 if ((offset % 4) != 0) {
78 BLOGD(sc, DBG_REGS, "Unaligned 32-bit write to 0x%08lx\n", offset);
81 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
82 bus_space_write_4(sc->bar[BAR0].tag,
89 bxe_reg_read8(struct bxe_softc *sc, bus_size_t offset)
93 val = bus_space_read_1(sc->bar[BAR0].tag,
96 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%02x\n", offset, val);
102 bxe_reg_read16(struct bxe_softc *sc, bus_size_t offset)
106 if ((offset % 2) != 0) {
107 BLOGD(sc, DBG_REGS, "Unaligned 16-bit read from 0x%08lx\n", offset);
110 val = bus_space_read_2(sc->bar[BAR0].tag,
111 sc->bar[BAR0].handle,
113 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
119 bxe_reg_read32(struct bxe_softc *sc, bus_size_t offset)
123 if ((offset % 4) != 0) {
124 BLOGD(sc, DBG_REGS, "Unaligned 32-bit read from 0x%08lx\n", offset);
127 val = bus_space_read_4(sc->bar[BAR0].tag,
128 sc->bar[BAR0].handle,
130 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
135 #endif /* BXE_REG_NO_INLINE */
140 elink_cb_dbg(struct bxe_softc *sc,
144 if (__predict_false(sc->debug & DBG_PHY)) {
145 snprintf(buf, sizeof(buf), "ELINK: %s", fmt);
146 device_printf(sc->dev, "%s", buf);
151 elink_cb_dbg1(struct bxe_softc *sc,
155 char tmp[128], buf[128];
156 if (__predict_false(sc->debug & DBG_PHY)) {
157 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
158 snprintf(buf, sizeof(buf), tmp, arg1);
159 device_printf(sc->dev, "%s", buf);
164 elink_cb_dbg2(struct bxe_softc *sc,
169 char tmp[128], buf[128];
170 if (__predict_false(sc->debug & DBG_PHY)) {
171 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
172 snprintf(buf, sizeof(buf), tmp, arg1, arg2);
173 device_printf(sc->dev, "%s", buf);
178 elink_cb_dbg3(struct bxe_softc *sc,
184 char tmp[128], buf[128];
185 if (__predict_false(sc->debug & DBG_PHY)) {
186 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
187 snprintf(buf, sizeof(buf), tmp, arg1, arg2, arg3);
188 device_printf(sc->dev, "%s", buf);
192 #endif /* ELINK_DEBUG */
194 extern struct mtx bxe_prev_mtx;
197 bxe_dump_mem(struct bxe_softc *sc,
206 mtx_lock(&bxe_prev_mtx);
208 BLOGI(sc, "++++++++++++ %s\n", tag);
209 strcpy(buf, "** 000: ");
211 for (xx = 0; xx < len; xx++)
213 if ((xx != 0) && (xx % 16 == 0))
215 BLOGI(sc, "%s\n", buf);
217 snprintf(c, sizeof(c), "%03x", xx);
222 snprintf(c, sizeof(c), "%02x ", *mem);
228 BLOGI(sc, "%s\n", buf);
229 BLOGI(sc, "------------ %s\n", tag);
231 mtx_unlock(&bxe_prev_mtx);
235 bxe_dump_mbuf_data(struct bxe_softc *sc,
245 mtx_lock(&bxe_prev_mtx);
247 BLOGI(sc, "++++++++++++ %s\n", tag);
252 strcpy(buf, "** > ");
253 snprintf(c, sizeof(c), "%03x", xx);
259 for (i = 0; i < m->m_len; i++)
261 if ((xx != 0) && (xx % 16 == 0))
263 BLOGI(sc, "%s\n", buf);
265 snprintf(c, sizeof(c), "%03x", xx);
270 snprintf(c, sizeof(c), "%02x ", *memp);
279 snprintf(c, sizeof(c), "%d", m->m_len);
284 BLOGI(sc, "%s\n", buf);
288 BLOGI(sc, "------------ %s\n", tag);
290 mtx_unlock(&bxe_prev_mtx);
295 static void bxe_ddb_usage()
297 db_printf("Usage: bxe[/hpv] <instance> [<address>]\n");
300 static db_cmdfcn_t bxe_ddb;
301 _DB_SET(_cmd, bxe, bxe_ddb, db_cmd_table, CS_OWN, NULL);
303 static void bxe_ddb(db_expr_t blah1,
308 char if_xname[IFNAMSIZ];
309 struct ifnet *ifp = NULL;
310 struct bxe_softc *sc;
314 int mod_phys_addr = FALSE;
315 int mod_virt_addr = FALSE;
318 tok = db_read_token();
320 tok = db_read_token();
322 db_printf("ERROR: bad modifier\n");
326 if (strcmp(db_tok_string, "h") == 0) {
329 } else if (strcmp(db_tok_string, "p") == 0) {
330 mod_phys_addr = TRUE;
331 } else if (strcmp(db_tok_string, "v") == 0) {
332 mod_virt_addr = TRUE;
335 db_unread_token(tok);
338 if (!db_expression((db_expr_t *)&index)) {
339 db_printf("ERROR: bxe index missing\n");
344 snprintf(if_xname, sizeof(if_xname), "bxe%d", index);
345 if ((ifp = ifunit_ref(if_xname)) == NULL)
347 db_printf("ERROR: Invalid interface %s\n", if_xname);
351 sc = (struct bxe_softc *)ifp->if_softc;
352 db_printf("ifnet=%p (%s)\n", ifp, if_xname);
353 db_printf("softc=%p\n", sc);
354 db_printf(" dev=%p\n", sc->dev);
355 db_printf(" BDF=%d:%d:%d\n",
356 sc->pcie_bus, sc->pcie_device, sc->pcie_func);
358 if (mod_phys_addr || mod_virt_addr) {
359 if (!db_expression((db_addr_t *)&addr)) {
360 db_printf("ERROR: Invalid address\n");
365 db_printf("addr=%p", addr);
371 if (ifp) if_rele(ifp);