2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
35 #include "ddb/db_sym.h"
36 #include "ddb/db_lex.h"
38 #ifdef BXE_REG_NO_INLINE
41 * Debug versions of the 8/16/32 bit OS register read/write functions to
42 * capture/display values read/written from/to the controller.
46 bxe_reg_write8(struct bxe_softc *sc, bus_size_t offset, uint8_t val)
48 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%02x\n", offset, val);
49 bus_space_write_1(sc->bar[BAR0].tag,
56 bxe_reg_write16(struct bxe_softc *sc, bus_size_t offset, uint16_t val)
58 if ((offset % 2) != 0) {
59 BLOGD(sc, DBG_REGS, "Unaligned 16-bit write to 0x%08lx\n", offset);
62 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%04x\n", offset, val);
63 bus_space_write_2(sc->bar[BAR0].tag,
70 bxe_reg_write32(struct bxe_softc *sc, bus_size_t offset, uint32_t val)
72 if ((offset % 4) != 0) {
73 BLOGD(sc, DBG_REGS, "Unaligned 32-bit write to 0x%08lx\n", offset);
76 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
77 bus_space_write_4(sc->bar[BAR0].tag,
84 bxe_reg_read8(struct bxe_softc *sc, bus_size_t offset)
88 val = bus_space_read_1(sc->bar[BAR0].tag,
91 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%02x\n", offset, val);
97 bxe_reg_read16(struct bxe_softc *sc, bus_size_t offset)
101 if ((offset % 2) != 0) {
102 BLOGD(sc, DBG_REGS, "Unaligned 16-bit read from 0x%08lx\n", offset);
105 val = bus_space_read_2(sc->bar[BAR0].tag,
106 sc->bar[BAR0].handle,
108 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
114 bxe_reg_read32(struct bxe_softc *sc, bus_size_t offset)
118 if ((offset % 4) != 0) {
119 BLOGD(sc, DBG_REGS, "Unaligned 32-bit read from 0x%08lx\n", offset);
122 val = bus_space_read_4(sc->bar[BAR0].tag,
123 sc->bar[BAR0].handle,
125 BLOGD(sc, DBG_REGS, "offset=0x%08lx val=0x%08x\n", offset, val);
130 #endif /* BXE_REG_NO_INLINE */
135 elink_cb_dbg(struct bxe_softc *sc,
139 if (__predict_false(sc->debug & DBG_PHY)) {
140 snprintf(buf, sizeof(buf), "ELINK: %s", fmt);
141 device_printf(sc->dev, "%s", buf);
146 elink_cb_dbg1(struct bxe_softc *sc,
150 char tmp[128], buf[128];
151 if (__predict_false(sc->debug & DBG_PHY)) {
152 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
153 snprintf(buf, sizeof(buf), tmp, arg1);
154 device_printf(sc->dev, "%s", buf);
159 elink_cb_dbg2(struct bxe_softc *sc,
164 char tmp[128], buf[128];
165 if (__predict_false(sc->debug & DBG_PHY)) {
166 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
167 snprintf(buf, sizeof(buf), tmp, arg1, arg2);
168 device_printf(sc->dev, "%s", buf);
173 elink_cb_dbg3(struct bxe_softc *sc,
179 char tmp[128], buf[128];
180 if (__predict_false(sc->debug & DBG_PHY)) {
181 snprintf(tmp, sizeof(tmp), "ELINK: %s", fmt);
182 snprintf(buf, sizeof(buf), tmp, arg1, arg2, arg3);
183 device_printf(sc->dev, "%s", buf);
187 #endif /* ELINK_DEBUG */
189 extern struct mtx bxe_prev_mtx;
192 bxe_dump_mem(struct bxe_softc *sc,
201 mtx_lock(&bxe_prev_mtx);
203 BLOGI(sc, "++++++++++++ %s\n", tag);
204 strcpy(buf, "** 000: ");
206 for (xx = 0; xx < len; xx++)
208 if ((xx != 0) && (xx % 16 == 0))
210 BLOGI(sc, "%s\n", buf);
212 snprintf(c, sizeof(c), "%03x", xx);
217 snprintf(c, sizeof(c), "%02x ", *mem);
223 BLOGI(sc, "%s\n", buf);
224 BLOGI(sc, "------------ %s\n", tag);
226 mtx_unlock(&bxe_prev_mtx);
230 bxe_dump_mbuf_data(struct bxe_softc *sc,
240 mtx_lock(&bxe_prev_mtx);
242 BLOGI(sc, "++++++++++++ %s\n", tag);
247 strcpy(buf, "** > ");
248 snprintf(c, sizeof(c), "%03x", xx);
254 for (i = 0; i < m->m_len; i++)
256 if ((xx != 0) && (xx % 16 == 0))
258 BLOGI(sc, "%s\n", buf);
260 snprintf(c, sizeof(c), "%03x", xx);
265 snprintf(c, sizeof(c), "%02x ", *memp);
274 snprintf(c, sizeof(c), "%d", m->m_len);
279 BLOGI(sc, "%s\n", buf);
283 BLOGI(sc, "------------ %s\n", tag);
285 mtx_unlock(&bxe_prev_mtx);
290 static void bxe_ddb_usage()
292 db_printf("Usage: bxe[/hpv] <instance> [<address>]\n");
295 static db_cmdfcn_t bxe_ddb;
296 _DB_SET(_cmd, bxe, bxe_ddb, db_cmd_table, CS_OWN, NULL);
298 static void bxe_ddb(db_expr_t blah1,
303 char if_xname[IFNAMSIZ];
305 struct bxe_softc *sc;
309 int mod_phys_addr = FALSE;
310 int mod_virt_addr = FALSE;
313 tok = db_read_token();
315 tok = db_read_token();
317 db_printf("ERROR: bad modifier\n");
321 if (strcmp(db_tok_string, "h") == 0) {
324 } else if (strcmp(db_tok_string, "p") == 0) {
325 mod_phys_addr = TRUE;
326 } else if (strcmp(db_tok_string, "v") == 0) {
327 mod_virt_addr = TRUE;
330 db_unread_token(tok);
333 if (!db_expression((db_expr_t *)&index)) {
334 db_printf("ERROR: bxe index missing\n");
339 snprintf(if_xname, sizeof(if_xname), "bxe%d", index);
340 if ((ifp = ifunit_ref(if_xname)) == NULL) /* XXX */
342 db_printf("ERROR: Invalid interface %s\n", if_xname);
346 sc = (struct bxe_softc *)if_getsoftc(ifp);
347 db_printf("ifnet=%p (%s)\n", ifp, if_xname);
348 db_printf("softc=%p\n", sc);
349 db_printf(" dev=%p\n", sc->dev);
350 db_printf(" BDF=%d:%d:%d\n",
351 sc->pcie_bus, sc->pcie_device, sc->pcie_func);
353 if (mod_phys_addr || mod_virt_addr) {
354 if (!db_expression((db_addr_t *)&addr)) {
355 db_printf("ERROR: Invalid address\n");
360 db_printf("addr=%p", addr);
366 if (ifp) if_rele(ifp);