kernel/disk: Remove use of "%b" format.
[dragonfly.git] / sys / dev / raid / mfi / mfi_debug.c
blobdea84caa883b10a2f88c49fc7be785196172bdff
1 /*-
2 * Copyright (c) 2006 IronPort Systems
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * 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 AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/mfi/mfi_debug.c,v 1.3 2006/10/16 04:18:38 scottl Exp $
27 * FreeBSD projects/head_mfi/ r228320
30 #include "opt_mfi.h"
32 #ifdef MFI_DEBUG
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/conf.h>
38 #include <sys/bus.h>
39 #include <sys/buf2.h>
40 #include <sys/lock.h>
41 #include <sys/malloc.h>
42 #include <sys/taskqueue.h>
43 #include <sys/uio.h>
45 #include <vm/vm.h>
46 #include <vm/pmap.h>
48 #include <dev/raid/mfi/mfireg.h>
49 #include <dev/raid/mfi/mfi_ioctl.h>
50 #include <dev/raid/mfi/mfivar.h>
52 static void
53 mfi_print_frame_flags(device_t dev, uint32_t flags)
55 device_printf(dev, "flags=%pb%i\n",
56 "\20"
57 "\1NOPOST"
58 "\2SGL64"
59 "\3SENSE64"
60 "\4WRITE"
61 "\5READ"
62 "\6IEEESGL", flags);
65 static void
66 mfi_print_sgl(struct mfi_frame_header *hdr, union mfi_sgl *sgl, int count)
68 int i, columns = 0;
70 kprintf("SG List:\n");
71 for (i = 0; i < count; i++) {
72 if (hdr->flags & MFI_FRAME_IEEE_SGL) {
73 kprintf("0x%lx:%06d ", (u_long)sgl->sg_skinny[i].addr,
74 sgl->sg_skinny[i].len);
75 columns += 26;
76 if (columns > 77) {
77 kprintf("\n");
78 columns = 0;
80 } else if (hdr->flags & MFI_FRAME_SGL64) {
81 kprintf("0x%lx:%06d ", (u_long)sgl->sg64[i].addr,
82 sgl->sg64[i].len);
83 columns += 26;
84 if (columns > 77) {
85 kprintf("\n");
86 columns = 0;
88 } else {
89 kprintf("0x%x:%06d ", sgl->sg32[i].addr,
90 sgl->sg32[i].len);
91 columns += 18;
92 if (columns > 71) {
93 kprintf("\n");
94 columns = 0;
98 if (columns != 0)
99 kprintf("\n");
103 static void
104 mfi_print_ldio(struct mfi_softc *sc, device_t dev, struct mfi_command *cm)
106 struct mfi_io_frame *io;
107 struct mfi_frame_header *hdr;
109 io = &cm->cm_frame->io;
110 hdr = &io->header;
112 device_printf(dev, "cmd=%s target_id=%d sg_count=%d data_len=%d "
113 "lba=%d\n", (hdr->cmd == MFI_CMD_LD_READ) ? "LD_READ":"LD_WRITE",
114 hdr->target_id, hdr->sg_count, hdr->data_len, io->lba_lo);
115 mfi_print_frame_flags(dev, hdr->flags);
116 mfi_print_sgl(hdr, &io->sgl, hdr->sg_count);
120 static void
121 mfi_print_dcmd(struct mfi_softc *sc, device_t dev, struct mfi_command *cm)
123 struct mfi_dcmd_frame *dcmd;
124 struct mfi_frame_header *hdr;
125 const char *opcode;
127 dcmd = &cm->cm_frame->dcmd;
128 hdr = &dcmd->header;
130 switch (dcmd->opcode) {
131 case MFI_DCMD_CTRL_GETINFO:
132 opcode = "CTRL_GETINFO";
133 break;
134 case MFI_DCMD_CTRL_FLUSHCACHE:
135 opcode = "CTRL_FLUSHCACHE";
136 break;
137 case MFI_DCMD_CTRL_SHUTDOWN:
138 opcode = "CTRL_SHUTDOWN";
139 break;
140 case MFI_DCMD_CTRL_EVENT_GETINFO:
141 opcode = "EVENT_GETINFO";
142 break;
143 case MFI_DCMD_CTRL_EVENT_GET:
144 opcode = "EVENT_GET";
145 break;
146 case MFI_DCMD_CTRL_EVENT_WAIT:
147 opcode = "EVENT_WAIT";
148 break;
149 case MFI_DCMD_LD_GET_LIST:
150 opcode = "LD_GET_LIST";
151 break;
152 case MFI_DCMD_LD_GET_INFO:
153 opcode = "LD_GET_INFO";
154 break;
155 case MFI_DCMD_LD_GET_PROP:
156 opcode = "LD_GET_PROP";
157 break;
158 case MFI_DCMD_LD_SET_PROP:
159 opcode = "LD_SET_PROP";
160 break;
161 case MFI_DCMD_CLUSTER:
162 opcode = "CLUSTER";
163 break;
164 case MFI_DCMD_CLUSTER_RESET_ALL:
165 opcode = "CLUSTER_RESET_ALL";
166 break;
167 case MFI_DCMD_CLUSTER_RESET_LD:
168 opcode = "CLUSTER_RESET_LD";
169 break;
170 default:
171 opcode = "UNKNOWN";
172 break;
175 device_printf(dev, "cmd=MFI_CMD_DCMD opcode=%s data_len=%d\n",
176 opcode, hdr->data_len);
177 mfi_print_frame_flags(dev, hdr->flags);
178 mfi_print_sgl(hdr, &dcmd->sgl, hdr->sg_count);
182 static void
183 mfi_print_generic_frame(struct mfi_softc *sc, struct mfi_command *cm)
185 hexdump(cm->cm_frame, cm->cm_total_frame_size, NULL, HD_OMIT_CHARS);
188 void
189 mfi_print_cmd(struct mfi_command *cm)
191 device_t dev;
192 struct mfi_softc *sc;
194 sc = cm->cm_sc;
195 dev = sc->mfi_dev;
197 device_printf(dev, "cm=%p index=%d total_frame_size=%d "
198 "extra_frames=%d\n", cm, cm->cm_index, cm->cm_total_frame_size,
199 cm->cm_extra_frames);
200 device_printf(dev, "flags=%pb%i\n",
201 "\20"
202 "\1MAPPED"
203 "\2DATAIN"
204 "\3DATAOUT"
205 "\4COMPLETED"
206 "\5POLLED"
207 "\6Q_FREE"
208 "\7Q_READY"
209 "\10Q_BUSY", cm->cm_flags);
211 switch (cm->cm_frame->header.cmd) {
212 case MFI_CMD_DCMD:
213 mfi_print_dcmd(sc, dev, cm);
214 break;
215 case MFI_CMD_LD_READ:
216 case MFI_CMD_LD_WRITE:
217 mfi_print_ldio(sc, dev, cm);
218 break;
219 default:
220 mfi_print_generic_frame(sc, cm);
221 break;
224 return;
227 void
228 mfi_dump_cmds(struct mfi_softc *sc)
230 int i;
232 for (i = 0; i < sc->mfi_total_cmds; i++)
233 mfi_print_generic_frame(sc, &sc->mfi_commands[i]);
236 void
237 mfi_validate_sg(struct mfi_softc *sc, struct mfi_command *cm,
238 const char *function, int line)
240 struct mfi_frame_header *hdr;
241 int i;
242 uint32_t count = 0, data_len;
244 hdr = &cm->cm_frame->header;
245 count = 0;
246 for (i = 0; i < hdr->sg_count; i++) {
247 if (hdr->flags & MFI_FRAME_IEEE_SGL)
248 count += cm->cm_sg->sg_skinny[i].len;
249 else if (hdr->flags & MFI_FRAME_SGL64)
250 count += cm->cm_sg->sg64[i].len;
251 else
252 count += cm->cm_sg->sg32[i].len;
255 count++;
257 data_len = hdr->data_len;
258 switch (hdr->cmd) {
259 case MFI_CMD_LD_READ:
260 case MFI_CMD_LD_WRITE:
261 data_len = data_len * 512;
262 case MFI_CMD_DCMD:
263 if (count != data_len) {
264 device_printf(sc->mfi_dev,
265 "%s %d COMMAND %p S/G count bad %d %d %d 0x%jx\n",
266 function, line, cm, count, data_len, cm->cm_len,
267 (intmax_t)pmap_kextract((vm_offset_t)cm->cm_data));
268 MFI_PRINT_CMD(cm);
273 #endif