2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 IronPort Systems
7 * Redistribution and use in source and binary forms, with or without
8 * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * 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 AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
43 #include <sys/mutex.h>
44 #include <sys/malloc.h>
45 #include <sys/selinfo.h>
46 #include <sys/sysctl.h>
47 #include <sys/taskqueue.h>
49 #include <machine/resource.h>
50 #include <machine/bus.h>
55 #include <dev/mfi/mfireg.h>
56 #include <dev/mfi/mfi_ioctl.h>
57 #include <dev/mfi/mfivar.h>
60 mfi_print_frame_flags(device_t dev, uint32_t flags)
62 device_printf(dev, "flags=%b\n", flags, MFI_FRAME_FMT);
66 mfi_print_sgl(struct mfi_frame_header *hdr, union mfi_sgl *sgl, int count)
71 for (i = 0; i < count; i++) {
72 if (hdr->flags & MFI_FRAME_IEEE_SGL) {
73 printf("0x%lx:%06d ", (u_long)sgl->sg_skinny[i].addr,
74 sgl->sg_skinny[i].len);
80 } else if (hdr->flags & MFI_FRAME_SGL64) {
81 printf("0x%lx:%06d ", (u_long)sgl->sg64[i].addr,
89 printf("0x%x:%06d ", sgl->sg32[i].addr,
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;
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);
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;
127 dcmd = &cm->cm_frame->dcmd;
130 switch (dcmd->opcode) {
131 case MFI_DCMD_CTRL_GETINFO:
132 opcode = "CTRL_GETINFO";
134 case MFI_DCMD_CTRL_FLUSHCACHE:
135 opcode = "CTRL_FLUSHCACHE";
137 case MFI_DCMD_CTRL_SHUTDOWN:
138 opcode = "CTRL_SHUTDOWN";
140 case MFI_DCMD_CTRL_EVENT_GETINFO:
141 opcode = "EVENT_GETINFO";
143 case MFI_DCMD_CTRL_EVENT_GET:
144 opcode = "EVENT_GET";
146 case MFI_DCMD_CTRL_EVENT_WAIT:
147 opcode = "EVENT_WAIT";
149 case MFI_DCMD_LD_GET_LIST:
150 opcode = "LD_GET_LIST";
152 case MFI_DCMD_LD_GET_INFO:
153 opcode = "LD_GET_INFO";
155 case MFI_DCMD_LD_GET_PROP:
156 opcode = "LD_GET_PROP";
158 case MFI_DCMD_LD_SET_PROP:
159 opcode = "LD_SET_PROP";
161 case MFI_DCMD_CLUSTER:
164 case MFI_DCMD_CLUSTER_RESET_ALL:
165 opcode = "CLUSTER_RESET_ALL";
167 case MFI_DCMD_CLUSTER_RESET_LD:
168 opcode = "CLUSTER_RESET_LD";
170 case MFI_DCMD_LD_MAP_GET_INFO:
171 opcode = "LD_MAP_GET_INFO";
173 case MFI_DCMD_BBU_START_LEARN:
174 opcode = "BBU_START_LEARN";
176 case MFI_DCMD_BBU_GET_PROP:
177 opcode = "BBU_GET_PROP";
179 case MFI_DCMD_BBU_SET_PROP:
180 opcode = "BBU_SET_PROP";
187 device_printf(dev, "cmd=MFI_CMD_DCMD opcode=%s data_len=%d\n",
188 opcode, hdr->data_len);
189 mfi_print_frame_flags(dev, hdr->flags);
190 mfi_print_sgl(hdr, &dcmd->sgl, hdr->sg_count);
195 mfi_print_generic_frame(struct mfi_softc *sc, struct mfi_command *cm)
197 hexdump(cm->cm_frame, cm->cm_total_frame_size, NULL, HD_OMIT_CHARS);
201 mfi_print_cmd(struct mfi_command *cm)
204 struct mfi_softc *sc;
209 device_printf(dev, "cm=%p index=%d total_frame_size=%d "
210 "extra_frames=%d\n", cm, cm->cm_index, cm->cm_total_frame_size,
211 cm->cm_extra_frames);
212 device_printf(dev, "flags=%b\n", cm->cm_flags, MFI_CMD_FLAGS_FMT);
214 switch (cm->cm_frame->header.cmd) {
216 mfi_print_dcmd(sc, dev, cm);
218 case MFI_CMD_LD_READ:
219 case MFI_CMD_LD_WRITE:
220 mfi_print_ldio(sc, dev, cm);
223 mfi_print_generic_frame(sc, cm);
231 mfi_dump_cmds(struct mfi_softc *sc)
235 for (i = 0; i < sc->mfi_max_fw_cmds; i++)
236 mfi_print_generic_frame(sc, &sc->mfi_commands[i]);
240 mfi_validate_sg(struct mfi_softc *sc, struct mfi_command *cm,
241 const char *function, int line)
243 struct mfi_frame_header *hdr;
245 uint32_t count = 0, data_len;
247 hdr = &cm->cm_frame->header;
249 for (i = 0; i < hdr->sg_count; i++) {
250 if (hdr->flags & MFI_FRAME_IEEE_SGL)
251 count += cm->cm_sg->sg_skinny[i].len;
252 else if (hdr->flags & MFI_FRAME_SGL64)
253 count += cm->cm_sg->sg64[i].len;
255 count += cm->cm_sg->sg32[i].len;
260 data_len = hdr->data_len;
262 case MFI_CMD_LD_READ:
263 case MFI_CMD_LD_WRITE:
264 data_len = data_len * 512;
266 if (count != data_len) {
267 device_printf(sc->mfi_dev,
268 "%s %d COMMAND %p S/G count bad %d %d %d 0x%jx\n",
269 function, line, cm, count, data_len, cm->cm_len,
270 (intmax_t)pmap_kextract((vm_offset_t)cm->cm_data));