2 * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
33 #include "ddb/db_sym.h"
34 #include "ddb/db_lex.h"
36 #ifdef BXE_REG_NO_INLINE
39 * Debug versions of the 8/16/32 bit OS register read/write functions to
40 * capture/display values read/written from/to the controller.
44 bxe_reg_write8(struct bxe_softc *sc, bus_size_t offset, uint8_t val)
46 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%02x\n", offset, val);
47 bus_space_write_1(sc->bar[BAR0].tag,
54 bxe_reg_write16(struct bxe_softc *sc, bus_size_t offset, uint16_t val)
56 if ((offset % 2) != 0) {
57 BLOGD(sc, DBG_REGS, "Unaligned 16-bit write to 0x%08lx\n", offset);
60 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%04x\n", offset, val);
61 bus_space_write_2(sc->bar[BAR0].tag,
68 bxe_reg_write32(struct bxe_softc *sc, bus_size_t offset, uint32_t val)
70 if ((offset % 4) != 0) {
71 BLOGD(sc, DBG_REGS, "Unaligned 32-bit write to 0x%08lx\n", offset);
74 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
75 bus_space_write_4(sc->bar[BAR0].tag,
82 bxe_reg_read8(struct bxe_softc *sc, bus_size_t offset)
86 val = bus_space_read_1(sc->bar[BAR0].tag,
89 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%02x\n", offset, val);
95 bxe_reg_read16(struct bxe_softc *sc, bus_size_t offset)
99 if ((offset % 2) != 0) {
100 BLOGD(sc, DBG_REGS, "Unaligned 16-bit read from 0x%08lx\n", offset);
103 val = bus_space_read_2(sc->bar[BAR0].tag,
104 sc->bar[BAR0].handle,
106 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
112 bxe_reg_read32(struct bxe_softc *sc, bus_size_t offset)
116 if ((offset % 4) != 0) {
117 BLOGD(sc, DBG_REGS, "Unaligned 32-bit read from 0x%08lx\n", offset);
120 val = bus_space_read_4(sc->bar[BAR0].tag,
121 sc->bar[BAR0].handle,
123 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
128 #endif /* BXE_REG_NO_INLINE */
133 elink_cb_dbg(struct bxe_softc *sc,
137 if (__predict_false(sc->debug & DBG_PHY)) {
138 snprintf(buf, sizeof(buf), "ELINK: %s", fmt);
139 device_printf(sc->dev, "%s", buf);
144 elink_cb_dbg1(struct bxe_softc *sc,
148 char tmp[128], buf[128];
149 if (__predict_false(sc->debug & DBG_PHY)) {
150 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
151 snprintf(buf, sizeof(buf), tmp, arg1);
152 device_printf(sc->dev, "%s", buf);
157 elink_cb_dbg2(struct bxe_softc *sc,
162 char tmp[128], buf[128];
163 if (__predict_false(sc->debug & DBG_PHY)) {
164 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
165 snprintf(buf, sizeof(buf), tmp, arg1, arg2);
166 device_printf(sc->dev, "%s", buf);
171 elink_cb_dbg3(struct bxe_softc *sc,
177 char tmp[128], buf[128];
178 if (__predict_false(sc->debug & DBG_PHY)) {
179 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
180 snprintf(buf, sizeof(buf), tmp, arg1, arg2, arg3);
181 device_printf(sc->dev, "%s", buf);
185 #endif /* ELINK_DEBUG */
187 extern struct mtx bxe_prev_mtx;
190 bxe_dump_mem(struct bxe_softc *sc,
199 mtx_lock(&bxe_prev_mtx);
201 BLOGI(sc, "++++++++++++ %s\n", tag);
202 strcpy(buf, "** 000: ");
204 for (xx = 0; xx < len; xx++)
206 if ((xx != 0) && (xx % 16 == 0))
208 BLOGI(sc, "%s\n", buf);
210 snprintf(c, sizeof(c), "%03x", xx);
215 snprintf(c, sizeof(c), "%02x ", *mem);
221 BLOGI(sc, "%s\n", buf);
222 BLOGI(sc, "------------ %s\n", tag);
224 mtx_unlock(&bxe_prev_mtx);
228 bxe_dump_mbuf_data(struct bxe_softc *sc,
238 mtx_lock(&bxe_prev_mtx);
240 BLOGI(sc, "++++++++++++ %s\n", tag);
245 strcpy(buf, "** > ");
246 snprintf(c, sizeof(c), "%03x", xx);
252 for (i = 0; i < m->m_len; i++)
254 if ((xx != 0) && (xx % 16 == 0))
256 BLOGI(sc, "%s\n", buf);
258 snprintf(c, sizeof(c), "%03x", xx);
263 snprintf(c, sizeof(c), "%02x ", *memp);
272 snprintf(c, sizeof(c), "%d", m->m_len);
277 BLOGI(sc, "%s\n", buf);
281 BLOGI(sc, "------------ %s\n", tag);
283 mtx_unlock(&bxe_prev_mtx);
288 static void bxe_ddb_usage()
290 db_printf("Usage: bxe[/hpv] <instance> [<address>]\n");
293 static db_cmdfcn_t bxe_ddb;
294 _DB_SET(_cmd, bxe, bxe_ddb, db_cmd_table, CS_OWN, NULL);
296 static void bxe_ddb(db_expr_t blah1,
301 char if_xname[IFNAMSIZ];
302 struct ifnet *ifp = NULL;
303 struct bxe_softc *sc;
307 int mod_phys_addr = FALSE;
308 int mod_virt_addr = FALSE;
311 tok = db_read_token();
313 tok = db_read_token();
315 db_printf("ERROR: bad modifier\n");
319 if (strcmp(db_tok_string, "h") == 0) {
322 } else if (strcmp(db_tok_string, "p") == 0) {
323 mod_phys_addr = TRUE;
324 } else if (strcmp(db_tok_string, "v") == 0) {
325 mod_virt_addr = TRUE;
328 db_unread_token(tok);
331 if (!db_expression((db_expr_t *)&index)) {
332 db_printf("ERROR: bxe index missing\n");
337 snprintf(if_xname, sizeof(if_xname), "bxe%d", index);
338 if ((ifp = ifunit_ref(if_xname)) == NULL)
340 db_printf("ERROR: Invalid interface %s\n", if_xname);
344 sc = (struct bxe_softc *)ifp->if_softc;
345 db_printf("ifnet=%p (%s)\n", ifp, if_xname);
346 db_printf("softc=%p\n", sc);
347 db_printf(" dev=%p\n", sc->dev);
348 db_printf(" BDF=%d:%d:%d\n",
349 sc->pcie_bus, sc->pcie_device, sc->pcie_func);
351 if (mod_phys_addr || mod_virt_addr) {
352 if (!db_expression((db_addr_t *)&addr)) {
353 db_printf("ERROR: Invalid address\n");
358 db_printf("addr=%p", addr);
364 if (ifp) if_rele(ifp);