2 * Copyright (c) 2006 IronPort Systems
5 * Redistribution and use in source and binary forms, with or without
6 * 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 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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
41 #include <sys/mutex.h>
42 #include <sys/malloc.h>
43 #include <sys/selinfo.h>
44 #include <sys/sysctl.h>
45 #include <sys/taskqueue.h>
47 #include <machine/resource.h>
48 #include <machine/bus.h>
53 #include <dev/mfi/mfireg.h>
54 #include <dev/mfi/mfi_ioctl.h>
55 #include <dev/mfi/mfivar.h>
58 mfi_print_frame_flags(device_t dev, uint32_t flags)
60 device_printf(dev, "flags=%b\n", flags,
71 mfi_print_sgl(struct mfi_frame_header *hdr, union mfi_sgl *sgl, int count)
76 for (i = 0; i < count; i++) {
77 if (hdr->flags & MFI_FRAME_IEEE_SGL) {
78 printf("0x%lx:%06d ", (u_long)sgl->sg_skinny[i].addr,
79 sgl->sg_skinny[i].len);
85 } else if (hdr->flags & MFI_FRAME_SGL64) {
86 printf("0x%lx:%06d ", (u_long)sgl->sg64[i].addr,
94 printf("0x%x:%06d ", sgl->sg32[i].addr,
109 mfi_print_ldio(struct mfi_softc *sc, device_t dev, struct mfi_command *cm)
111 struct mfi_io_frame *io;
112 struct mfi_frame_header *hdr;
114 io = &cm->cm_frame->io;
117 device_printf(dev, "cmd=%s target_id=%d sg_count=%d data_len=%d "
118 "lba=%d\n", (hdr->cmd == MFI_CMD_LD_READ) ? "LD_READ":"LD_WRITE",
119 hdr->target_id, hdr->sg_count, hdr->data_len, io->lba_lo);
120 mfi_print_frame_flags(dev, hdr->flags);
121 mfi_print_sgl(hdr, &io->sgl, hdr->sg_count);
126 mfi_print_dcmd(struct mfi_softc *sc, device_t dev, struct mfi_command *cm)
128 struct mfi_dcmd_frame *dcmd;
129 struct mfi_frame_header *hdr;
132 dcmd = &cm->cm_frame->dcmd;
135 switch (dcmd->opcode) {
136 case MFI_DCMD_CTRL_GETINFO:
137 opcode = "CTRL_GETINFO";
139 case MFI_DCMD_CTRL_FLUSHCACHE:
140 opcode = "CTRL_FLUSHCACHE";
142 case MFI_DCMD_CTRL_SHUTDOWN:
143 opcode = "CTRL_SHUTDOWN";
145 case MFI_DCMD_CTRL_EVENT_GETINFO:
146 opcode = "EVENT_GETINFO";
148 case MFI_DCMD_CTRL_EVENT_GET:
149 opcode = "EVENT_GET";
151 case MFI_DCMD_CTRL_EVENT_WAIT:
152 opcode = "EVENT_WAIT";
154 case MFI_DCMD_LD_GET_LIST:
155 opcode = "LD_GET_LIST";
157 case MFI_DCMD_LD_GET_INFO:
158 opcode = "LD_GET_INFO";
160 case MFI_DCMD_LD_GET_PROP:
161 opcode = "LD_GET_PROP";
163 case MFI_DCMD_LD_SET_PROP:
164 opcode = "LD_SET_PROP";
166 case MFI_DCMD_CLUSTER:
169 case MFI_DCMD_CLUSTER_RESET_ALL:
170 opcode = "CLUSTER_RESET_ALL";
172 case MFI_DCMD_CLUSTER_RESET_LD:
173 opcode = "CLUSTER_RESET_LD";
175 case MFI_DCMD_LD_MAP_GET_INFO:
176 opcode = "LD_MAP_GET_INFO";
183 device_printf(dev, "cmd=MFI_CMD_DCMD opcode=%s data_len=%d\n",
184 opcode, hdr->data_len);
185 mfi_print_frame_flags(dev, hdr->flags);
186 mfi_print_sgl(hdr, &dcmd->sgl, hdr->sg_count);
191 mfi_print_generic_frame(struct mfi_softc *sc, struct mfi_command *cm)
193 hexdump(cm->cm_frame, cm->cm_total_frame_size, NULL, HD_OMIT_CHARS);
197 mfi_print_cmd(struct mfi_command *cm)
200 struct mfi_softc *sc;
205 device_printf(dev, "cm=%p index=%d total_frame_size=%d "
206 "extra_frames=%d\n", cm, cm->cm_index, cm->cm_total_frame_size,
207 cm->cm_extra_frames);
208 device_printf(dev, "flags=%b\n", cm->cm_flags,
219 switch (cm->cm_frame->header.cmd) {
221 mfi_print_dcmd(sc, dev, cm);
223 case MFI_CMD_LD_READ:
224 case MFI_CMD_LD_WRITE:
225 mfi_print_ldio(sc, dev, cm);
228 mfi_print_generic_frame(sc, cm);
236 mfi_dump_cmds(struct mfi_softc *sc)
240 for (i = 0; i < sc->mfi_total_cmds; i++)
241 mfi_print_generic_frame(sc, &sc->mfi_commands[i]);
245 mfi_validate_sg(struct mfi_softc *sc, struct mfi_command *cm,
246 const char *function, int line)
248 struct mfi_frame_header *hdr;
250 uint32_t count = 0, data_len;
252 hdr = &cm->cm_frame->header;
254 for (i = 0; i < hdr->sg_count; i++) {
255 if (hdr->flags & MFI_FRAME_IEEE_SGL)
256 count += cm->cm_sg->sg_skinny[i].len;
257 else if (hdr->flags & MFI_FRAME_SGL64)
258 count += cm->cm_sg->sg64[i].len;
260 count += cm->cm_sg->sg32[i].len;
265 data_len = hdr->data_len;
267 case MFI_CMD_LD_READ:
268 case MFI_CMD_LD_WRITE:
269 data_len = data_len * 512;
271 if (count != data_len) {
272 device_printf(sc->mfi_dev,
273 "%s %d COMMAND %p S/G count bad %d %d %d 0x%jx\n",
274 function, line, cm, count, data_len, cm->cm_len,
275 (intmax_t)pmap_kextract((vm_offset_t)cm->cm_data));