2 * Copyright (c) 2008 Yahoo!, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD userland interface
33 * Copyright (c) 2011-2015 LSI Corp.
34 * Copyright (c) 2013-2015 Avago Technologies
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
63 #include <sys/cdefs.h>
64 __FBSDID("$FreeBSD$");
66 #include "opt_compat.h"
68 /* TODO Move headers to mprvar */
69 #include <sys/types.h>
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/kernel.h>
73 #include <sys/selinfo.h>
74 #include <sys/module.h>
78 #include <sys/malloc.h>
80 #include <sys/sysctl.h>
81 #include <sys/ioccom.h>
82 #include <sys/endian.h>
83 #include <sys/queue.h>
84 #include <sys/kthread.h>
85 #include <sys/taskqueue.h>
87 #include <sys/sysent.h>
89 #include <machine/bus.h>
90 #include <machine/resource.h>
94 #include <cam/cam_ccb.h>
96 #include <dev/mpr/mpi/mpi2_type.h>
97 #include <dev/mpr/mpi/mpi2.h>
98 #include <dev/mpr/mpi/mpi2_ioc.h>
99 #include <dev/mpr/mpi/mpi2_cnfg.h>
100 #include <dev/mpr/mpi/mpi2_init.h>
101 #include <dev/mpr/mpi/mpi2_tool.h>
102 #include <dev/mpr/mpr_ioctl.h>
103 #include <dev/mpr/mprvar.h>
104 #include <dev/mpr/mpr_table.h>
105 #include <dev/mpr/mpr_sas.h>
106 #include <dev/pci/pcivar.h>
107 #include <dev/pci/pcireg.h>
109 static d_open_t mpr_open;
110 static d_close_t mpr_close;
111 static d_ioctl_t mpr_ioctl_devsw;
113 static struct cdevsw mpr_cdevsw = {
114 .d_version = D_VERSION,
117 .d_close = mpr_close,
118 .d_ioctl = mpr_ioctl_devsw,
122 typedef int (mpr_user_f)(struct mpr_command *, struct mpr_usr_command *);
123 static mpr_user_f mpi_pre_ioc_facts;
124 static mpr_user_f mpi_pre_port_facts;
125 static mpr_user_f mpi_pre_fw_download;
126 static mpr_user_f mpi_pre_fw_upload;
127 static mpr_user_f mpi_pre_sata_passthrough;
128 static mpr_user_f mpi_pre_smp_passthrough;
129 static mpr_user_f mpi_pre_config;
130 static mpr_user_f mpi_pre_sas_io_unit_control;
132 static int mpr_user_read_cfg_header(struct mpr_softc *,
133 struct mpr_cfg_page_req *);
134 static int mpr_user_read_cfg_page(struct mpr_softc *,
135 struct mpr_cfg_page_req *, void *);
136 static int mpr_user_read_extcfg_header(struct mpr_softc *,
137 struct mpr_ext_cfg_page_req *);
138 static int mpr_user_read_extcfg_page(struct mpr_softc *,
139 struct mpr_ext_cfg_page_req *, void *);
140 static int mpr_user_write_cfg_page(struct mpr_softc *,
141 struct mpr_cfg_page_req *, void *);
142 static int mpr_user_setup_request(struct mpr_command *,
143 struct mpr_usr_command *);
144 static int mpr_user_command(struct mpr_softc *, struct mpr_usr_command *);
146 static int mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru_t *data);
147 static void mpr_user_get_adapter_data(struct mpr_softc *sc,
148 mpr_adapter_data_t *data);
149 static void mpr_user_read_pci_info(struct mpr_softc *sc,
150 mpr_pci_info_t *data);
151 static uint8_t mpr_get_fw_diag_buffer_number(struct mpr_softc *sc,
153 static int mpr_post_fw_diag_buffer(struct mpr_softc *sc,
154 mpr_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code);
155 static int mpr_release_fw_diag_buffer(struct mpr_softc *sc,
156 mpr_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
158 static int mpr_diag_register(struct mpr_softc *sc,
159 mpr_fw_diag_register_t *diag_register, uint32_t *return_code);
160 static int mpr_diag_unregister(struct mpr_softc *sc,
161 mpr_fw_diag_unregister_t *diag_unregister, uint32_t *return_code);
162 static int mpr_diag_query(struct mpr_softc *sc,
163 mpr_fw_diag_query_t *diag_query, uint32_t *return_code);
164 static int mpr_diag_read_buffer(struct mpr_softc *sc,
165 mpr_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
166 uint32_t *return_code);
167 static int mpr_diag_release(struct mpr_softc *sc,
168 mpr_fw_diag_release_t *diag_release, uint32_t *return_code);
169 static int mpr_do_diag_action(struct mpr_softc *sc, uint32_t action,
170 uint8_t *diag_action, uint32_t length, uint32_t *return_code);
171 static int mpr_user_diag_action(struct mpr_softc *sc,
172 mpr_diag_action_t *data);
173 static void mpr_user_event_query(struct mpr_softc *sc,
174 mpr_event_query_t *data);
175 static void mpr_user_event_enable(struct mpr_softc *sc,
176 mpr_event_enable_t *data);
177 static int mpr_user_event_report(struct mpr_softc *sc,
178 mpr_event_report_t *data);
179 static int mpr_user_reg_access(struct mpr_softc *sc, mpr_reg_access_t *data);
180 static int mpr_user_btdh(struct mpr_softc *sc, mpr_btdh_mapping_t *data);
182 static MALLOC_DEFINE(M_MPRUSER, "mpr_user", "Buffers for mpr(4) ioctls");
184 /* Macros from compat/freebsd32/freebsd32.h */
185 #define PTRIN(v) (void *)(uintptr_t)(v)
186 #define PTROUT(v) (uint32_t)(uintptr_t)(v)
188 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
189 #define PTRIN_CP(src,dst,fld) \
190 do { (dst).fld = PTRIN((src).fld); } while (0)
191 #define PTROUT_CP(src,dst,fld) \
192 do { (dst).fld = PTROUT((src).fld); } while (0)
195 * MPI functions that support IEEE SGLs for SAS3.
197 static uint8_t ieee_sgl_func_list[] = {
198 MPI2_FUNCTION_SCSI_IO_REQUEST,
199 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH,
200 MPI2_FUNCTION_SMP_PASSTHROUGH,
201 MPI2_FUNCTION_SATA_PASSTHROUGH,
202 MPI2_FUNCTION_FW_UPLOAD,
203 MPI2_FUNCTION_FW_DOWNLOAD,
204 MPI2_FUNCTION_TARGET_ASSIST,
205 MPI2_FUNCTION_TARGET_STATUS_SEND,
206 MPI2_FUNCTION_TOOLBOX
210 mpr_attach_user(struct mpr_softc *sc)
214 unit = device_get_unit(sc->mpr_dev);
215 sc->mpr_cdev = make_dev(&mpr_cdevsw, unit, UID_ROOT, GID_OPERATOR,
216 0640, "mpr%d", unit);
217 if (sc->mpr_cdev == NULL) {
220 sc->mpr_cdev->si_drv1 = sc;
225 mpr_detach_user(struct mpr_softc *sc)
228 /* XXX: do a purge of pending requests? */
229 if (sc->mpr_cdev != NULL)
230 destroy_dev(sc->mpr_cdev);
234 mpr_open(struct cdev *dev, int flags, int fmt, struct thread *td)
241 mpr_close(struct cdev *dev, int flags, int fmt, struct thread *td)
248 mpr_user_read_cfg_header(struct mpr_softc *sc,
249 struct mpr_cfg_page_req *page_req)
251 MPI2_CONFIG_PAGE_HEADER *hdr;
252 struct mpr_config_params params;
255 hdr = ¶ms.hdr.Struct;
256 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
257 params.page_address = le32toh(page_req->page_address);
258 hdr->PageVersion = 0;
260 hdr->PageNumber = page_req->header.PageNumber;
261 hdr->PageType = page_req->header.PageType;
262 params.buffer = NULL;
264 params.callback = NULL;
266 if ((error = mpr_read_config_page(sc, ¶ms)) != 0) {
268 * Leave the request. Without resetting the chip, it's
269 * still owned by it and we'll just get into trouble
270 * freeing it now. Mark it as abandoned so that if it
271 * shows up later it can be freed.
273 mpr_printf(sc, "read_cfg_header timed out\n");
277 page_req->ioc_status = htole16(params.status);
278 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
279 MPI2_IOCSTATUS_SUCCESS) {
280 bcopy(hdr, &page_req->header, sizeof(page_req->header));
287 mpr_user_read_cfg_page(struct mpr_softc *sc,
288 struct mpr_cfg_page_req *page_req, void *buf)
290 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
291 struct mpr_config_params params;
295 hdr = ¶ms.hdr.Struct;
296 hdr->PageVersion = reqhdr->PageVersion;
297 hdr->PageLength = reqhdr->PageLength;
298 hdr->PageNumber = reqhdr->PageNumber;
299 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
300 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
301 params.page_address = le32toh(page_req->page_address);
303 params.length = le32toh(page_req->len);
304 params.callback = NULL;
306 if ((error = mpr_read_config_page(sc, ¶ms)) != 0) {
307 mpr_printf(sc, "mpr_user_read_cfg_page timed out\n");
311 page_req->ioc_status = htole16(params.status);
316 mpr_user_read_extcfg_header(struct mpr_softc *sc,
317 struct mpr_ext_cfg_page_req *ext_page_req)
319 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
320 struct mpr_config_params params;
323 hdr = ¶ms.hdr.Ext;
324 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
325 hdr->PageVersion = ext_page_req->header.PageVersion;
326 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
327 hdr->ExtPageLength = 0;
328 hdr->PageNumber = ext_page_req->header.PageNumber;
329 hdr->ExtPageType = ext_page_req->header.ExtPageType;
330 params.page_address = le32toh(ext_page_req->page_address);
331 params.buffer = NULL;
333 params.callback = NULL;
335 if ((error = mpr_read_config_page(sc, ¶ms)) != 0) {
337 * Leave the request. Without resetting the chip, it's
338 * still owned by it and we'll just get into trouble
339 * freeing it now. Mark it as abandoned so that if it
340 * shows up later it can be freed.
342 mpr_printf(sc, "mpr_user_read_extcfg_header timed out\n");
346 ext_page_req->ioc_status = htole16(params.status);
347 if ((ext_page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
348 MPI2_IOCSTATUS_SUCCESS) {
349 ext_page_req->header.PageVersion = hdr->PageVersion;
350 ext_page_req->header.PageNumber = hdr->PageNumber;
351 ext_page_req->header.PageType = hdr->PageType;
352 ext_page_req->header.ExtPageLength = hdr->ExtPageLength;
353 ext_page_req->header.ExtPageType = hdr->ExtPageType;
360 mpr_user_read_extcfg_page(struct mpr_softc *sc,
361 struct mpr_ext_cfg_page_req *ext_page_req, void *buf)
363 MPI2_CONFIG_EXTENDED_PAGE_HEADER *reqhdr, *hdr;
364 struct mpr_config_params params;
368 hdr = ¶ms.hdr.Ext;
369 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
370 params.page_address = le32toh(ext_page_req->page_address);
371 hdr->PageVersion = reqhdr->PageVersion;
372 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
373 hdr->PageNumber = reqhdr->PageNumber;
374 hdr->ExtPageType = reqhdr->ExtPageType;
375 hdr->ExtPageLength = reqhdr->ExtPageLength;
377 params.length = le32toh(ext_page_req->len);
378 params.callback = NULL;
380 if ((error = mpr_read_config_page(sc, ¶ms)) != 0) {
381 mpr_printf(sc, "mpr_user_read_extcfg_page timed out\n");
385 ext_page_req->ioc_status = htole16(params.status);
390 mpr_user_write_cfg_page(struct mpr_softc *sc,
391 struct mpr_cfg_page_req *page_req, void *buf)
393 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
394 struct mpr_config_params params;
399 hdr = ¶ms.hdr.Struct;
400 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
401 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
402 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
403 mpr_printf(sc, "page type 0x%x not changeable\n",
404 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
409 * There isn't any point in restoring stripped out attributes
410 * if you then mask them going down to issue the request.
413 hdr->PageVersion = reqhdr->PageVersion;
414 hdr->PageLength = reqhdr->PageLength;
415 hdr->PageNumber = reqhdr->PageNumber;
416 hdr->PageType = reqhdr->PageType;
417 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
418 params.page_address = le32toh(page_req->page_address);
420 params.length = le32toh(page_req->len);
421 params.callback = NULL;
423 if ((error = mpr_write_config_page(sc, ¶ms)) != 0) {
424 mpr_printf(sc, "mpr_write_cfg_page timed out\n");
428 page_req->ioc_status = htole16(params.status);
433 mpr_init_sge(struct mpr_command *cm, void *req, void *sge)
437 space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
438 off = (uintptr_t)sge - (uintptr_t)req;
440 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
441 req, sge, off, space));
444 cm->cm_sglsize = space - off;
448 * Prepare the mpr_command for an IOC_FACTS request.
451 mpi_pre_ioc_facts(struct mpr_command *cm, struct mpr_usr_command *cmd)
453 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
454 MPI2_IOC_FACTS_REPLY *rpl;
456 if (cmd->req_len != sizeof *req)
458 if (cmd->rpl_len != sizeof *rpl)
467 * Prepare the mpr_command for a PORT_FACTS request.
470 mpi_pre_port_facts(struct mpr_command *cm, struct mpr_usr_command *cmd)
472 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
473 MPI2_PORT_FACTS_REPLY *rpl;
475 if (cmd->req_len != sizeof *req)
477 if (cmd->rpl_len != sizeof *rpl)
486 * Prepare the mpr_command for a FW_DOWNLOAD request.
489 mpi_pre_fw_download(struct mpr_command *cm, struct mpr_usr_command *cmd)
491 MPI25_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
492 MPI2_FW_DOWNLOAD_REPLY *rpl;
495 if (cmd->req_len != sizeof *req)
497 if (cmd->rpl_len != sizeof *rpl)
503 error = copyin(cmd->buf, cm->cm_data, cmd->len);
507 mpr_init_sge(cm, req, &req->SGL);
510 * For now, the F/W image must be provided in a single request.
512 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
514 if (req->TotalImageSize != cmd->len)
517 req->ImageOffset = 0;
518 req->ImageSize = cmd->len;
520 cm->cm_flags |= MPR_CM_FLAGS_DATAOUT;
522 return (mpr_push_ieee_sge(cm, &req->SGL, 0));
526 * Prepare the mpr_command for a FW_UPLOAD request.
529 mpi_pre_fw_upload(struct mpr_command *cm, struct mpr_usr_command *cmd)
531 MPI25_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
532 MPI2_FW_UPLOAD_REPLY *rpl;
534 if (cmd->req_len != sizeof *req)
536 if (cmd->rpl_len != sizeof *rpl)
539 mpr_init_sge(cm, req, &req->SGL);
541 /* Perhaps just asking what the size of the fw is? */
545 req->ImageOffset = 0;
546 req->ImageSize = cmd->len;
548 cm->cm_flags |= MPR_CM_FLAGS_DATAIN;
550 return (mpr_push_ieee_sge(cm, &req->SGL, 0));
554 * Prepare the mpr_command for a SATA_PASSTHROUGH request.
557 mpi_pre_sata_passthrough(struct mpr_command *cm, struct mpr_usr_command *cmd)
559 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
560 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
562 if (cmd->req_len != sizeof *req)
564 if (cmd->rpl_len != sizeof *rpl)
567 mpr_init_sge(cm, req, &req->SGL);
572 * Prepare the mpr_command for a SMP_PASSTHROUGH request.
575 mpi_pre_smp_passthrough(struct mpr_command *cm, struct mpr_usr_command *cmd)
577 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
578 MPI2_SMP_PASSTHROUGH_REPLY *rpl;
580 if (cmd->req_len != sizeof *req)
582 if (cmd->rpl_len != sizeof *rpl)
585 mpr_init_sge(cm, req, &req->SGL);
590 * Prepare the mpr_command for a CONFIG request.
593 mpi_pre_config(struct mpr_command *cm, struct mpr_usr_command *cmd)
595 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
596 MPI2_CONFIG_REPLY *rpl;
598 if (cmd->req_len != sizeof *req)
600 if (cmd->rpl_len != sizeof *rpl)
603 mpr_init_sge(cm, req, &req->PageBufferSGE);
608 * Prepare the mpr_command for a SAS_IO_UNIT_CONTROL request.
611 mpi_pre_sas_io_unit_control(struct mpr_command *cm,
612 struct mpr_usr_command *cmd)
621 * A set of functions to prepare an mpr_command for the various
622 * supported requests.
624 struct mpr_user_func {
627 } mpr_user_func_list[] = {
628 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
629 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
630 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
631 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
632 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
633 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
634 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
635 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
636 { 0xFF, NULL } /* list end */
640 mpr_user_setup_request(struct mpr_command *cm, struct mpr_usr_command *cmd)
642 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
643 struct mpr_user_func *f;
645 for (f = mpr_user_func_list; f->f_pre != NULL; f++) {
646 if (hdr->Function == f->Function)
647 return (f->f_pre(cm, cmd));
653 mpr_user_command(struct mpr_softc *sc, struct mpr_usr_command *cmd)
655 MPI2_REQUEST_HEADER *hdr;
656 MPI2_DEFAULT_REPLY *rpl;
658 struct mpr_command *cm = NULL;
663 cm = mpr_alloc_command(sc);
666 mpr_printf(sc, "%s: no mpr requests\n", __func__);
672 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
674 mpr_dprint(sc, MPR_USER, "%s: req %p %d rpl %p %d\n", __func__,
675 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len);
677 if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
679 goto RetFreeUnlocked;
681 err = copyin(cmd->req, hdr, cmd->req_len);
683 goto RetFreeUnlocked;
685 mpr_dprint(sc, MPR_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
686 hdr->Function, hdr->MsgFlags);
689 buf = malloc(cmd->len, M_MPRUSER, M_WAITOK|M_ZERO);
691 mpr_printf(sc, "Cannot allocate memory %s %d\n",
696 cm->cm_length = cmd->len;
702 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE;
703 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
705 err = mpr_user_setup_request(cm, cmd);
707 mpr_printf(sc, "%s: unsupported parameter or unsupported "
708 "function in request (function = 0x%X)\n", __func__,
712 goto RetFreeUnlocked;
715 err = mpr_wait_command(sc, cm, 30, CAN_SLEEP);
718 mpr_printf(sc, "%s: invalid request: error %d\n",
723 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
725 sz = rpl->MsgLength * 4;
729 if (sz > cmd->rpl_len) {
730 mpr_printf(sc, "%s: user reply buffer (%d) smaller than "
731 "returned buffer (%d)\n", __func__, cmd->rpl_len, sz);
736 copyout(rpl, cmd->rpl, sz);
738 copyout(buf, cmd->buf, cmd->len);
739 mpr_dprint(sc, MPR_USER, "%s: reply size %d\n", __func__, sz);
744 mpr_free_command(sc, cm);
748 free(buf, M_MPRUSER);
753 mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru_t *data)
755 MPI2_REQUEST_HEADER *hdr, tmphdr;
756 MPI2_DEFAULT_REPLY *rpl;
757 struct mpr_command *cm = NULL;
758 int i, err = 0, dir = 0, sz;
759 uint8_t tool, function = 0;
761 struct mprsas_target *targ = NULL;
764 * Only allow one passthru command at a time. Use the MPR_FLAGS_BUSY
765 * bit to denote that a passthru is being processed.
768 if (sc->mpr_flags & MPR_FLAGS_BUSY) {
769 mpr_dprint(sc, MPR_USER, "%s: Only one passthru command "
770 "allowed at a single time.", __func__);
774 sc->mpr_flags |= MPR_FLAGS_BUSY;
778 * Do some validation on data direction. Valid cases are:
779 * 1) DataSize is 0 and direction is NONE
780 * 2) DataSize is non-zero and one of:
781 * a) direction is READ or
782 * b) direction is WRITE or
783 * c) direction is BOTH and DataOutSize is non-zero
784 * If valid and the direction is BOTH, change the direction to READ.
785 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
787 if (((data->DataSize == 0) &&
788 (data->DataDirection == MPR_PASS_THRU_DIRECTION_NONE)) ||
789 ((data->DataSize != 0) &&
790 ((data->DataDirection == MPR_PASS_THRU_DIRECTION_READ) ||
791 (data->DataDirection == MPR_PASS_THRU_DIRECTION_WRITE) ||
792 ((data->DataDirection == MPR_PASS_THRU_DIRECTION_BOTH) &&
793 (data->DataOutSize != 0))))) {
794 if (data->DataDirection == MPR_PASS_THRU_DIRECTION_BOTH)
795 data->DataDirection = MPR_PASS_THRU_DIRECTION_READ;
797 data->DataOutSize = 0;
801 mpr_dprint(sc, MPR_USER, "%s: req 0x%jx %d rpl 0x%jx %d "
802 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
803 data->PtrRequest, data->RequestSize, data->PtrReply,
804 data->ReplySize, data->PtrData, data->DataSize,
805 data->PtrDataOut, data->DataOutSize, data->DataDirection);
808 * copy in the header so we know what we're dealing with before we
809 * commit to allocating a command for it.
811 err = copyin(PTRIN(data->PtrRequest), &tmphdr, data->RequestSize);
813 goto RetFreeUnlocked;
815 if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
817 goto RetFreeUnlocked;
820 function = tmphdr.Function;
821 mpr_dprint(sc, MPR_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
822 function, tmphdr.MsgFlags);
825 * Handle a passthru TM request.
827 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
828 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
831 cm = mprsas_alloc_tm(sc);
837 /* Copy the header in. Only a small fixup is needed. */
838 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
839 bcopy(&tmphdr, task, data->RequestSize);
840 task->TaskMID = cm->cm_desc.Default.SMID;
843 cm->cm_desc.HighPriority.RequestFlags =
844 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
845 cm->cm_complete = NULL;
846 cm->cm_complete_data = NULL;
848 targ = mprsas_find_target_by_handle(sc->sassc, 0,
851 mpr_dprint(sc, MPR_INFO,
852 "%s %d : invalid handle for requested TM 0x%x \n",
853 __func__, __LINE__, task->DevHandle);
856 mprsas_prepare_for_tm(sc, cm, targ, CAM_LUN_WILDCARD);
857 err = mpr_wait_command(sc, cm, 30, CAN_SLEEP);
862 mpr_dprint(sc, MPR_FAULT, "%s: task management failed",
866 * Copy the reply data and sense data to user space.
868 if (cm->cm_reply != NULL) {
869 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
870 sz = rpl->MsgLength * 4;
872 if (sz > data->ReplySize) {
873 mpr_printf(sc, "%s: user reply buffer (%d) "
874 "smaller than returned buffer (%d)\n",
875 __func__, data->ReplySize, sz);
878 copyout(cm->cm_reply, PTRIN(data->PtrReply),
882 mprsas_free_tm(sc, cm);
887 cm = mpr_alloc_command(sc);
890 mpr_printf(sc, "%s: no mpr requests\n", __func__);
896 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
897 bcopy(&tmphdr, hdr, data->RequestSize);
900 * Do some checking to make sure the IOCTL request contains a valid
901 * request. Then set the SGL info.
903 mpr_init_sge(cm, hdr, (void *)((uint8_t *)hdr + data->RequestSize));
906 * Set up for read, write or both. From check above, DataOutSize will
907 * be 0 if direction is READ or WRITE, but it will have some non-zero
908 * value if the direction is BOTH. So, just use the biggest size to get
909 * the cm_data buffer size. If direction is BOTH, 2 SGLs need to be set
910 * up; the first is for the request and the second will contain the
911 * response data. cm_out_len needs to be set here and this will be used
912 * when the SGLs are set up.
915 cm->cm_length = MAX(data->DataSize, data->DataOutSize);
916 cm->cm_out_len = data->DataOutSize;
918 if (cm->cm_length != 0) {
919 cm->cm_data = malloc(cm->cm_length, M_MPRUSER, M_WAITOK |
921 if (cm->cm_data == NULL) {
922 mpr_dprint(sc, MPR_FAULT, "%s: alloc failed for IOCTL "
923 "passthru length %d\n", __func__, cm->cm_length);
925 cm->cm_flags = MPR_CM_FLAGS_DATAIN;
926 if (data->DataOutSize) {
927 cm->cm_flags |= MPR_CM_FLAGS_DATAOUT;
928 err = copyin(PTRIN(data->PtrDataOut),
929 cm->cm_data, data->DataOutSize);
930 } else if (data->DataDirection ==
931 MPR_PASS_THRU_DIRECTION_WRITE) {
932 cm->cm_flags = MPR_CM_FLAGS_DATAOUT;
933 err = copyin(PTRIN(data->PtrData),
934 cm->cm_data, data->DataSize);
937 mpr_dprint(sc, MPR_FAULT, "%s: failed to copy "
938 "IOCTL data from user space\n", __func__);
942 * Set this flag only if processing a command that does not need an
943 * IEEE SGL. The CLI Tool within the Toolbox uses IEEE SGLs, so clear
944 * the flag only for that tool if processing a Toolbox function.
946 cm->cm_flags |= MPR_CM_FLAGS_SGE_SIMPLE;
947 for (i = 0; i < sizeof (ieee_sgl_func_list); i++) {
948 if (function == ieee_sgl_func_list[i]) {
949 if (function == MPI2_FUNCTION_TOOLBOX)
951 tool = (uint8_t)hdr->FunctionDependent1;
952 if (tool != MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL)
955 cm->cm_flags &= ~MPR_CM_FLAGS_SGE_SIMPLE;
959 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
962 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
963 * uses SCSI IO or Fast Path SCSI IO descriptor.
965 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
966 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
967 MPI2_SCSI_IO_REQUEST *scsi_io_req;
969 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
971 * Put SGE for data and data_out buffer at the end of
972 * scsi_io_request message header (64 bytes in total).
973 * Following above SGEs, the residual space will be used by
976 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
978 scsi_io_req->SenseBufferLowAddress =
979 htole32(cm->cm_sense_busaddr);
982 * Set SGLOffset0 value. This is the number of dwords that SGL
983 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
985 scsi_io_req->SGLOffset0 = 24;
988 * Setup descriptor info. RAID passthrough must use the
989 * default request descriptor which is already set, so if this
990 * is a SCSI IO request, change the descriptor to SCSI IO or
991 * Fast Path SCSI IO. Also, if this is a SCSI IO request,
992 * handle the reply in the mprsas_scsio_complete function.
994 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
995 targ = mprsas_find_target_by_handle(sc->sassc, 0,
996 scsi_io_req->DevHandle);
999 printf("No Target found for handle %d\n",
1000 scsi_io_req->DevHandle);
1002 goto RetFreeUnlocked;
1005 if (targ->scsi_req_desc_type ==
1006 MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO) {
1007 cm->cm_desc.FastPathSCSIIO.RequestFlags =
1008 MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO;
1009 cm->cm_desc.FastPathSCSIIO.DevHandle =
1010 scsi_io_req->DevHandle;
1011 scsi_io_req->IoFlags |=
1012 MPI25_SCSIIO_IOFLAGS_FAST_PATH;
1014 cm->cm_desc.SCSIIO.RequestFlags =
1015 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
1016 cm->cm_desc.SCSIIO.DevHandle =
1017 scsi_io_req->DevHandle;
1021 * Make sure the DevHandle is not 0 because this is a
1024 if (scsi_io_req->DevHandle == 0) {
1026 goto RetFreeUnlocked;
1033 err = mpr_wait_command(sc, cm, 30, CAN_SLEEP);
1036 mpr_printf(sc, "%s: invalid request: error %d\n", __func__,
1039 goto RetFreeUnlocked;
1043 * Sync the DMA data, if any. Then copy the data to user space.
1045 if (cm->cm_data != NULL) {
1046 if (cm->cm_flags & MPR_CM_FLAGS_DATAIN)
1047 dir = BUS_DMASYNC_POSTREAD;
1048 else if (cm->cm_flags & MPR_CM_FLAGS_DATAOUT)
1049 dir = BUS_DMASYNC_POSTWRITE;
1050 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
1051 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
1053 if (cm->cm_flags & MPR_CM_FLAGS_DATAIN) {
1055 err = copyout(cm->cm_data,
1056 PTRIN(data->PtrData), data->DataSize);
1059 mpr_dprint(sc, MPR_FAULT, "%s: failed to copy "
1060 "IOCTL data to user space\n", __func__);
1065 * Copy the reply data and sense data to user space.
1067 if (cm->cm_reply != NULL) {
1068 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1069 sz = rpl->MsgLength * 4;
1071 if (sz > data->ReplySize) {
1072 mpr_printf(sc, "%s: user reply buffer (%d) smaller "
1073 "than returned buffer (%d)\n", __func__,
1074 data->ReplySize, sz);
1077 copyout(cm->cm_reply, PTRIN(data->PtrReply), data->ReplySize);
1080 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1081 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1082 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1083 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1085 MIN((le32toh(((MPI2_SCSI_IO_REPLY *)rpl)->
1086 SenseCount)), sizeof(struct
1089 copyout(cm->cm_sense, cm->cm_req + 64,
1102 free(cm->cm_data, M_MPRUSER);
1103 mpr_free_command(sc, cm);
1106 sc->mpr_flags &= ~MPR_FLAGS_BUSY;
1113 mpr_user_get_adapter_data(struct mpr_softc *sc, mpr_adapter_data_t *data)
1115 Mpi2ConfigReply_t mpi_reply;
1116 Mpi2BiosPage3_t config_page;
1119 * Use the PCI interface functions to get the Bus, Device, and Function
1122 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mpr_dev);
1123 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mpr_dev);
1124 data->PciInformation.u.bits.FunctionNumber =
1125 pci_get_function(sc->mpr_dev);
1128 * Get the FW version that should already be saved in IOC Facts.
1130 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1133 * General device info.
1135 data->AdapterType = MPRIOCTL_ADAPTER_TYPE_SAS3;
1136 data->PCIDeviceHwId = pci_get_device(sc->mpr_dev);
1137 data->PCIDeviceHwRev = pci_read_config(sc->mpr_dev, PCIR_REVID, 1);
1138 data->SubSystemId = pci_get_subdevice(sc->mpr_dev);
1139 data->SubsystemVendorId = pci_get_subvendor(sc->mpr_dev);
1142 * Get the driver version.
1144 strcpy((char *)&data->DriverVersion[0], MPR_DRIVER_VERSION);
1147 * Need to get BIOS Config Page 3 for the BIOS Version.
1149 data->BiosVersion = 0;
1151 if (mpr_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1152 printf("%s: Error while retrieving BIOS Version\n", __func__);
1154 data->BiosVersion = config_page.BiosVersion;
1159 mpr_user_read_pci_info(struct mpr_softc *sc, mpr_pci_info_t *data)
1164 * Use the PCI interface functions to get the Bus, Device, and Function
1167 data->BusNumber = pci_get_bus(sc->mpr_dev);
1168 data->DeviceNumber = pci_get_slot(sc->mpr_dev);
1169 data->FunctionNumber = pci_get_function(sc->mpr_dev);
1172 * Now get the interrupt vector and the pci header. The vector can
1173 * only be 0 right now. The header is the first 256 bytes of config
1176 data->InterruptVector = 0;
1177 for (i = 0; i < sizeof (data->PciHeader); i++) {
1178 data->PciHeader[i] = pci_read_config(sc->mpr_dev, i, 1);
1183 mpr_get_fw_diag_buffer_number(struct mpr_softc *sc, uint32_t unique_id)
1187 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1188 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1193 return (MPR_FW_DIAGNOSTIC_UID_NOT_FOUND);
1197 mpr_post_fw_diag_buffer(struct mpr_softc *sc,
1198 mpr_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1200 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1201 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1202 struct mpr_command *cm = NULL;
1206 * If buffer is not enabled, just leave.
1208 *return_code = MPR_FW_DIAG_ERROR_POST_FAILED;
1209 if (!pBuffer->enabled) {
1210 return (MPR_DIAG_FAILURE);
1214 * Clear some flags initially.
1216 pBuffer->force_release = FALSE;
1217 pBuffer->valid_data = FALSE;
1218 pBuffer->owned_by_firmware = FALSE;
1223 cm = mpr_alloc_command(sc);
1225 mpr_printf(sc, "%s: no mpr requests\n", __func__);
1226 return (MPR_DIAG_FAILURE);
1230 * Build the request for releasing the FW Diag Buffer and send it.
1232 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1233 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1234 req->BufferType = pBuffer->buffer_type;
1235 req->ExtendedType = pBuffer->extended_type;
1236 req->BufferLength = pBuffer->size;
1237 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1238 req->ProductSpecific[i] = pBuffer->product_specific[i];
1239 mpr_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1242 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1243 cm->cm_complete_data = NULL;
1246 * Send command synchronously.
1248 status = mpr_wait_command(sc, cm, 30, CAN_SLEEP);
1250 mpr_printf(sc, "%s: invalid request: error %d\n", __func__,
1252 status = MPR_DIAG_FAILURE;
1257 * Process POST reply.
1259 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1260 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1261 status = MPR_DIAG_FAILURE;
1262 mpr_dprint(sc, MPR_FAULT, "%s: post of FW Diag Buffer failed "
1263 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1264 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1265 reply->IOCLogInfo, reply->TransferLength);
1270 * Post was successful.
1272 pBuffer->valid_data = TRUE;
1273 pBuffer->owned_by_firmware = TRUE;
1274 *return_code = MPR_FW_DIAG_ERROR_SUCCESS;
1275 status = MPR_DIAG_SUCCESS;
1278 mpr_free_command(sc, cm);
1283 mpr_release_fw_diag_buffer(struct mpr_softc *sc,
1284 mpr_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1287 MPI2_DIAG_RELEASE_REQUEST *req;
1288 MPI2_DIAG_RELEASE_REPLY *reply;
1289 struct mpr_command *cm = NULL;
1293 * If buffer is not enabled, just leave.
1295 *return_code = MPR_FW_DIAG_ERROR_RELEASE_FAILED;
1296 if (!pBuffer->enabled) {
1297 mpr_dprint(sc, MPR_USER, "%s: This buffer type is not "
1298 "supported by the IOC", __func__);
1299 return (MPR_DIAG_FAILURE);
1303 * Clear some flags initially.
1305 pBuffer->force_release = FALSE;
1306 pBuffer->valid_data = FALSE;
1307 pBuffer->owned_by_firmware = FALSE;
1312 cm = mpr_alloc_command(sc);
1314 mpr_printf(sc, "%s: no mpr requests\n", __func__);
1315 return (MPR_DIAG_FAILURE);
1319 * Build the request for releasing the FW Diag Buffer and send it.
1321 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1322 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1323 req->BufferType = pBuffer->buffer_type;
1326 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1327 cm->cm_complete_data = NULL;
1330 * Send command synchronously.
1332 status = mpr_wait_command(sc, cm, 30, CAN_SLEEP);
1334 mpr_printf(sc, "%s: invalid request: error %d\n", __func__,
1336 status = MPR_DIAG_FAILURE;
1341 * Process RELEASE reply.
1343 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1344 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1345 pBuffer->owned_by_firmware) {
1346 status = MPR_DIAG_FAILURE;
1347 mpr_dprint(sc, MPR_FAULT, "%s: release of FW Diag Buffer "
1348 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1349 __func__, reply->IOCStatus, reply->IOCLogInfo);
1354 * Release was successful.
1356 *return_code = MPR_FW_DIAG_ERROR_SUCCESS;
1357 status = MPR_DIAG_SUCCESS;
1360 * If this was for an UNREGISTER diag type command, clear the unique ID.
1362 if (diag_type == MPR_FW_DIAG_TYPE_UNREGISTER) {
1363 pBuffer->unique_id = MPR_FW_DIAG_INVALID_UID;
1371 mpr_diag_register(struct mpr_softc *sc, mpr_fw_diag_register_t *diag_register,
1372 uint32_t *return_code)
1374 mpr_fw_diagnostic_buffer_t *pBuffer;
1375 uint8_t extended_type, buffer_type, i;
1376 uint32_t buffer_size;
1380 extended_type = diag_register->ExtendedType;
1381 buffer_type = diag_register->BufferType;
1382 buffer_size = diag_register->RequestedBufferSize;
1383 unique_id = diag_register->UniqueId;
1386 * Check for valid buffer type
1388 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1389 *return_code = MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1390 return (MPR_DIAG_FAILURE);
1394 * Get the current buffer and look up the unique ID. The unique ID
1395 * should not be found. If it is, the ID is already in use.
1397 i = mpr_get_fw_diag_buffer_number(sc, unique_id);
1398 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1399 if (i != MPR_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1400 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1401 return (MPR_DIAG_FAILURE);
1405 * The buffer's unique ID should not be registered yet, and the given
1406 * unique ID cannot be 0.
1408 if ((pBuffer->unique_id != MPR_FW_DIAG_INVALID_UID) ||
1409 (unique_id == MPR_FW_DIAG_INVALID_UID)) {
1410 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1411 return (MPR_DIAG_FAILURE);
1415 * If this buffer is already posted as immediate, just change owner.
1417 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1418 (pBuffer->unique_id == MPR_FW_DIAG_INVALID_UID)) {
1419 pBuffer->immediate = FALSE;
1420 pBuffer->unique_id = unique_id;
1421 return (MPR_DIAG_SUCCESS);
1425 * Post a new buffer after checking if it's enabled. The DMA buffer
1426 * that is allocated will be contiguous (nsegments = 1).
1428 if (!pBuffer->enabled) {
1429 *return_code = MPR_FW_DIAG_ERROR_NO_BUFFER;
1430 return (MPR_DIAG_FAILURE);
1432 if (bus_dma_tag_create( sc->mpr_parent_dmat, /* parent */
1433 1, 0, /* algnmnt, boundary */
1434 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1435 BUS_SPACE_MAXADDR, /* highaddr */
1436 NULL, NULL, /* filter, filterarg */
1437 buffer_size, /* maxsize */
1439 buffer_size, /* maxsegsize */
1441 NULL, NULL, /* lockfunc, lockarg */
1442 &sc->fw_diag_dmat)) {
1443 device_printf(sc->mpr_dev, "Cannot allocate FW diag buffer DMA "
1447 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1448 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1449 device_printf(sc->mpr_dev, "Cannot allocate FW diag buffer "
1453 bzero(sc->fw_diag_buffer, buffer_size);
1454 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1455 buffer_size, mpr_memaddr_cb, &sc->fw_diag_busaddr, 0);
1456 pBuffer->size = buffer_size;
1459 * Copy the given info to the diag buffer and post the buffer.
1461 pBuffer->buffer_type = buffer_type;
1462 pBuffer->immediate = FALSE;
1463 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1464 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1466 pBuffer->product_specific[i] =
1467 diag_register->ProductSpecific[i];
1470 pBuffer->extended_type = extended_type;
1471 pBuffer->unique_id = unique_id;
1472 status = mpr_post_fw_diag_buffer(sc, pBuffer, return_code);
1475 * In case there was a failure, free the DMA buffer.
1477 if (status == MPR_DIAG_FAILURE) {
1478 if (sc->fw_diag_busaddr != 0)
1479 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1480 if (sc->fw_diag_buffer != NULL)
1481 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1483 if (sc->fw_diag_dmat != NULL)
1484 bus_dma_tag_destroy(sc->fw_diag_dmat);
1491 mpr_diag_unregister(struct mpr_softc *sc,
1492 mpr_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1494 mpr_fw_diagnostic_buffer_t *pBuffer;
1499 unique_id = diag_unregister->UniqueId;
1502 * Get the current buffer and look up the unique ID. The unique ID
1505 i = mpr_get_fw_diag_buffer_number(sc, unique_id);
1506 if (i == MPR_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1507 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1508 return (MPR_DIAG_FAILURE);
1511 pBuffer = &sc->fw_diag_buffer_list[i];
1514 * Try to release the buffer from FW before freeing it. If release
1515 * fails, don't free the DMA buffer in case FW tries to access it
1516 * later. If buffer is not owned by firmware, can't release it.
1518 if (!pBuffer->owned_by_firmware) {
1519 status = MPR_DIAG_SUCCESS;
1521 status = mpr_release_fw_diag_buffer(sc, pBuffer, return_code,
1522 MPR_FW_DIAG_TYPE_UNREGISTER);
1526 * At this point, return the current status no matter what happens with
1529 pBuffer->unique_id = MPR_FW_DIAG_INVALID_UID;
1530 if (status == MPR_DIAG_SUCCESS) {
1531 if (sc->fw_diag_busaddr != 0)
1532 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1533 if (sc->fw_diag_buffer != NULL)
1534 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1536 if (sc->fw_diag_dmat != NULL)
1537 bus_dma_tag_destroy(sc->fw_diag_dmat);
1544 mpr_diag_query(struct mpr_softc *sc, mpr_fw_diag_query_t *diag_query,
1545 uint32_t *return_code)
1547 mpr_fw_diagnostic_buffer_t *pBuffer;
1551 unique_id = diag_query->UniqueId;
1554 * If ID is valid, query on ID.
1555 * If ID is invalid, query on buffer type.
1557 if (unique_id == MPR_FW_DIAG_INVALID_UID) {
1558 i = diag_query->BufferType;
1559 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1560 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1561 return (MPR_DIAG_FAILURE);
1564 i = mpr_get_fw_diag_buffer_number(sc, unique_id);
1565 if (i == MPR_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1566 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1567 return (MPR_DIAG_FAILURE);
1572 * Fill query structure with the diag buffer info.
1574 pBuffer = &sc->fw_diag_buffer_list[i];
1575 diag_query->BufferType = pBuffer->buffer_type;
1576 diag_query->ExtendedType = pBuffer->extended_type;
1577 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1578 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1580 diag_query->ProductSpecific[i] =
1581 pBuffer->product_specific[i];
1584 diag_query->TotalBufferSize = pBuffer->size;
1585 diag_query->DriverAddedBufferSize = 0;
1586 diag_query->UniqueId = pBuffer->unique_id;
1587 diag_query->ApplicationFlags = 0;
1588 diag_query->DiagnosticFlags = 0;
1591 * Set/Clear application flags
1593 if (pBuffer->immediate) {
1594 diag_query->ApplicationFlags &= ~MPR_FW_DIAG_FLAG_APP_OWNED;
1596 diag_query->ApplicationFlags |= MPR_FW_DIAG_FLAG_APP_OWNED;
1598 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1599 diag_query->ApplicationFlags |= MPR_FW_DIAG_FLAG_BUFFER_VALID;
1601 diag_query->ApplicationFlags &= ~MPR_FW_DIAG_FLAG_BUFFER_VALID;
1603 if (pBuffer->owned_by_firmware) {
1604 diag_query->ApplicationFlags |=
1605 MPR_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1607 diag_query->ApplicationFlags &=
1608 ~MPR_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1611 return (MPR_DIAG_SUCCESS);
1615 mpr_diag_read_buffer(struct mpr_softc *sc,
1616 mpr_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1617 uint32_t *return_code)
1619 mpr_fw_diagnostic_buffer_t *pBuffer;
1624 unique_id = diag_read_buffer->UniqueId;
1627 * Get the current buffer and look up the unique ID. The unique ID
1630 i = mpr_get_fw_diag_buffer_number(sc, unique_id);
1631 if (i == MPR_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1632 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1633 return (MPR_DIAG_FAILURE);
1636 pBuffer = &sc->fw_diag_buffer_list[i];
1639 * Make sure requested read is within limits
1641 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1643 *return_code = MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1644 return (MPR_DIAG_FAILURE);
1648 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1649 * buffer that was allocated is one contiguous buffer.
1651 pData = (uint8_t *)(sc->fw_diag_buffer +
1652 diag_read_buffer->StartingOffset);
1653 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1654 return (MPR_DIAG_FAILURE);
1655 diag_read_buffer->Status = 0;
1658 * Set or clear the Force Release flag.
1660 if (pBuffer->force_release) {
1661 diag_read_buffer->Flags |= MPR_FW_DIAG_FLAG_FORCE_RELEASE;
1663 diag_read_buffer->Flags &= ~MPR_FW_DIAG_FLAG_FORCE_RELEASE;
1667 * If buffer is to be reregistered, make sure it's not already owned by
1670 status = MPR_DIAG_SUCCESS;
1671 if (!pBuffer->owned_by_firmware) {
1672 if (diag_read_buffer->Flags & MPR_FW_DIAG_FLAG_REREGISTER) {
1673 status = mpr_post_fw_diag_buffer(sc, pBuffer,
1682 mpr_diag_release(struct mpr_softc *sc, mpr_fw_diag_release_t *diag_release,
1683 uint32_t *return_code)
1685 mpr_fw_diagnostic_buffer_t *pBuffer;
1690 unique_id = diag_release->UniqueId;
1693 * Get the current buffer and look up the unique ID. The unique ID
1696 i = mpr_get_fw_diag_buffer_number(sc, unique_id);
1697 if (i == MPR_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1698 *return_code = MPR_FW_DIAG_ERROR_INVALID_UID;
1699 return (MPR_DIAG_FAILURE);
1702 pBuffer = &sc->fw_diag_buffer_list[i];
1705 * If buffer is not owned by firmware, it's already been released.
1707 if (!pBuffer->owned_by_firmware) {
1708 *return_code = MPR_FW_DIAG_ERROR_ALREADY_RELEASED;
1709 return (MPR_DIAG_FAILURE);
1713 * Release the buffer.
1715 status = mpr_release_fw_diag_buffer(sc, pBuffer, return_code,
1716 MPR_FW_DIAG_TYPE_RELEASE);
1721 mpr_do_diag_action(struct mpr_softc *sc, uint32_t action,
1722 uint8_t *diag_action, uint32_t length, uint32_t *return_code)
1724 mpr_fw_diag_register_t diag_register;
1725 mpr_fw_diag_unregister_t diag_unregister;
1726 mpr_fw_diag_query_t diag_query;
1727 mpr_diag_read_buffer_t diag_read_buffer;
1728 mpr_fw_diag_release_t diag_release;
1729 int status = MPR_DIAG_SUCCESS;
1730 uint32_t original_return_code;
1732 original_return_code = *return_code;
1733 *return_code = MPR_FW_DIAG_ERROR_SUCCESS;
1736 case MPR_FW_DIAG_TYPE_REGISTER:
1739 MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1740 status = MPR_DIAG_FAILURE;
1743 if (copyin(diag_action, &diag_register,
1744 sizeof(diag_register)) != 0)
1745 return (MPR_DIAG_FAILURE);
1746 status = mpr_diag_register(sc, &diag_register,
1750 case MPR_FW_DIAG_TYPE_UNREGISTER:
1751 if (length < sizeof(diag_unregister)) {
1753 MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1754 status = MPR_DIAG_FAILURE;
1757 if (copyin(diag_action, &diag_unregister,
1758 sizeof(diag_unregister)) != 0)
1759 return (MPR_DIAG_FAILURE);
1760 status = mpr_diag_unregister(sc, &diag_unregister,
1764 case MPR_FW_DIAG_TYPE_QUERY:
1765 if (length < sizeof (diag_query)) {
1767 MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1768 status = MPR_DIAG_FAILURE;
1771 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1773 return (MPR_DIAG_FAILURE);
1774 status = mpr_diag_query(sc, &diag_query, return_code);
1775 if (status == MPR_DIAG_SUCCESS)
1776 if (copyout(&diag_query, diag_action,
1777 sizeof (diag_query)) != 0)
1778 return (MPR_DIAG_FAILURE);
1781 case MPR_FW_DIAG_TYPE_READ_BUFFER:
1782 if (copyin(diag_action, &diag_read_buffer,
1783 sizeof(diag_read_buffer)) != 0)
1784 return (MPR_DIAG_FAILURE);
1785 if (length < diag_read_buffer.BytesToRead) {
1787 MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1788 status = MPR_DIAG_FAILURE;
1791 status = mpr_diag_read_buffer(sc, &diag_read_buffer,
1792 PTRIN(diag_read_buffer.PtrDataBuffer),
1794 if (status == MPR_DIAG_SUCCESS) {
1795 if (copyout(&diag_read_buffer, diag_action,
1796 sizeof(diag_read_buffer) -
1797 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1799 return (MPR_DIAG_FAILURE);
1803 case MPR_FW_DIAG_TYPE_RELEASE:
1804 if (length < sizeof(diag_release)) {
1806 MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1807 status = MPR_DIAG_FAILURE;
1810 if (copyin(diag_action, &diag_release,
1811 sizeof(diag_release)) != 0)
1812 return (MPR_DIAG_FAILURE);
1813 status = mpr_diag_release(sc, &diag_release,
1818 *return_code = MPR_FW_DIAG_ERROR_INVALID_PARAMETER;
1819 status = MPR_DIAG_FAILURE;
1823 if ((status == MPR_DIAG_FAILURE) &&
1824 (original_return_code == MPR_FW_DIAG_NEW) &&
1825 (*return_code != MPR_FW_DIAG_ERROR_SUCCESS))
1826 status = MPR_DIAG_SUCCESS;
1832 mpr_user_diag_action(struct mpr_softc *sc, mpr_diag_action_t *data)
1837 * Only allow one diag action at one time.
1839 if (sc->mpr_flags & MPR_FLAGS_BUSY) {
1840 mpr_dprint(sc, MPR_USER, "%s: Only one FW diag command "
1841 "allowed at a single time.", __func__);
1844 sc->mpr_flags |= MPR_FLAGS_BUSY;
1847 * Send diag action request
1849 if (data->Action == MPR_FW_DIAG_TYPE_REGISTER ||
1850 data->Action == MPR_FW_DIAG_TYPE_UNREGISTER ||
1851 data->Action == MPR_FW_DIAG_TYPE_QUERY ||
1852 data->Action == MPR_FW_DIAG_TYPE_READ_BUFFER ||
1853 data->Action == MPR_FW_DIAG_TYPE_RELEASE) {
1854 status = mpr_do_diag_action(sc, data->Action,
1855 PTRIN(data->PtrDiagAction), data->Length,
1860 sc->mpr_flags &= ~MPR_FLAGS_BUSY;
1865 * Copy the event recording mask and the event queue size out. For
1866 * clarification, the event recording mask (events_to_record) is not the same
1867 * thing as the event mask (event_mask). events_to_record has a bit set for
1868 * every event type that is to be recorded by the driver, and event_mask has a
1869 * bit cleared for every event that is allowed into the driver from the IOC.
1870 * They really have nothing to do with each other.
1873 mpr_user_event_query(struct mpr_softc *sc, mpr_event_query_t *data)
1878 data->Entries = MPR_EVENT_QUEUE_SIZE;
1880 for (i = 0; i < 4; i++) {
1881 data->Types[i] = sc->events_to_record[i];
1887 * Set the driver's event mask according to what's been given. See
1888 * mpr_user_event_query for explanation of the event recording mask and the IOC
1889 * event mask. It's the app's responsibility to enable event logging by setting
1890 * the bits in events_to_record. Initially, no events will be logged.
1893 mpr_user_event_enable(struct mpr_softc *sc, mpr_event_enable_t *data)
1898 for (i = 0; i < 4; i++) {
1899 sc->events_to_record[i] = data->Types[i];
1905 * Copy out the events that have been recorded, up to the max events allowed.
1908 mpr_user_event_report(struct mpr_softc *sc, mpr_event_report_t *data)
1915 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1917 if (copyout((void *)sc->recorded_events,
1918 PTRIN(data->PtrEvents), size) != 0)
1923 * data->Size value is not large enough to copy event data.
1929 * Change size value to match the number of bytes that were copied.
1932 data->Size = sizeof(sc->recorded_events);
1939 * Record events into the driver from the IOC if they are not masked.
1942 mprsas_record_event(struct mpr_softc *sc,
1943 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1947 uint16_t event_data_len;
1948 boolean_t sendAEN = FALSE;
1950 event = event_reply->Event;
1953 * Generate a system event to let anyone who cares know that a
1954 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1955 * event mask is set to.
1957 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1962 * Record the event only if its corresponding bit is set in
1963 * events_to_record. event_index is the index into recorded_events and
1964 * event_number is the overall number of an event being recorded since
1965 * start-of-day. event_index will roll over; event_number will never
1968 i = (uint8_t)(event / 32);
1969 j = (uint8_t)(event % 32);
1970 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1971 i = sc->event_index;
1972 sc->recorded_events[i].Type = event;
1973 sc->recorded_events[i].Number = ++sc->event_number;
1974 bzero(sc->recorded_events[i].Data, MPR_MAX_EVENT_DATA_LENGTH *
1976 event_data_len = event_reply->EventDataLength;
1978 if (event_data_len > 0) {
1980 * Limit data to size in m_event entry
1982 if (event_data_len > MPR_MAX_EVENT_DATA_LENGTH) {
1983 event_data_len = MPR_MAX_EVENT_DATA_LENGTH;
1985 for (j = 0; j < event_data_len; j++) {
1986 sc->recorded_events[i].Data[j] =
1987 event_reply->EventData[j];
1991 * check for index wrap-around
1993 if (++i == MPR_EVENT_QUEUE_SIZE) {
1996 sc->event_index = (uint8_t)i;
1999 * Set flag to send the event.
2006 * Generate a system event if flag is set to let anyone who cares know
2007 * that an event has occurred.
2010 //SLM-how to send a system event (see kqueue, kevent)
2011 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
2012 // "SAS", NULL, NULL, DDI_NOSLEEP);
2017 mpr_user_reg_access(struct mpr_softc *sc, mpr_reg_access_t *data)
2021 switch (data->Command) {
2023 * IO access is not supported.
2027 mpr_dprint(sc, MPR_USER, "IO access is not supported. "
2028 "Use memory access.");
2033 data->RegData = mpr_regread(sc, data->RegOffset);
2037 mpr_regwrite(sc, data->RegOffset, data->RegData);
2049 mpr_user_btdh(struct mpr_softc *sc, mpr_btdh_mapping_t *data)
2051 uint8_t bt2dh = FALSE;
2052 uint8_t dh2bt = FALSE;
2053 uint16_t dev_handle, bus, target;
2056 target = data->TargetID;
2057 dev_handle = data->DevHandle;
2060 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2061 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2062 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2065 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2067 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2069 if (!dh2bt && !bt2dh)
2073 * Only handle bus of 0. Make sure target is within range.
2079 if (target > sc->max_devices) {
2080 mpr_dprint(sc, MPR_FAULT, "Target ID is out of range "
2081 "for Bus/Target to DevHandle mapping.");
2084 dev_handle = sc->mapping_table[target].dev_handle;
2086 data->DevHandle = dev_handle;
2089 target = mpr_mapping_get_sas_id_from_handle(sc, dev_handle);
2091 data->TargetID = target;
2098 mpr_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2101 struct mpr_softc *sc;
2102 struct mpr_cfg_page_req *page_req;
2103 struct mpr_ext_cfg_page_req *ext_page_req;
2105 int error, msleep_ret;
2109 page_req = (void *)arg;
2110 ext_page_req = (void *)arg;
2113 case MPRIO_READ_CFG_HEADER:
2115 error = mpr_user_read_cfg_header(sc, page_req);
2118 case MPRIO_READ_CFG_PAGE:
2119 mpr_page = malloc(page_req->len, M_MPRUSER, M_WAITOK | M_ZERO);
2121 mpr_printf(sc, "Cannot allocate memory %s %d\n",
2122 __func__, __LINE__);
2125 error = copyin(page_req->buf, mpr_page,
2126 sizeof(MPI2_CONFIG_PAGE_HEADER));
2130 error = mpr_user_read_cfg_page(sc, page_req, mpr_page);
2134 error = copyout(mpr_page, page_req->buf, page_req->len);
2136 case MPRIO_READ_EXT_CFG_HEADER:
2138 error = mpr_user_read_extcfg_header(sc, ext_page_req);
2141 case MPRIO_READ_EXT_CFG_PAGE:
2142 mpr_page = malloc(ext_page_req->len, M_MPRUSER,
2145 mpr_printf(sc, "Cannot allocate memory %s %d\n",
2146 __func__, __LINE__);
2149 error = copyin(ext_page_req->buf, mpr_page,
2150 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2154 error = mpr_user_read_extcfg_page(sc, ext_page_req, mpr_page);
2158 error = copyout(mpr_page, ext_page_req->buf, ext_page_req->len);
2160 case MPRIO_WRITE_CFG_PAGE:
2161 mpr_page = malloc(page_req->len, M_MPRUSER, M_WAITOK|M_ZERO);
2163 mpr_printf(sc, "Cannot allocate memory %s %d\n",
2164 __func__, __LINE__);
2167 error = copyin(page_req->buf, mpr_page, page_req->len);
2171 error = mpr_user_write_cfg_page(sc, page_req, mpr_page);
2174 case MPRIO_MPR_COMMAND:
2175 error = mpr_user_command(sc, (struct mpr_usr_command *)arg);
2177 case MPTIOCTL_PASS_THRU:
2179 * The user has requested to pass through a command to be
2180 * executed by the MPT firmware. Call our routine which does
2181 * this. Only allow one passthru IOCTL at one time.
2183 error = mpr_user_pass_thru(sc, (mpr_pass_thru_t *)arg);
2185 case MPTIOCTL_GET_ADAPTER_DATA:
2187 * The user has requested to read adapter data. Call our
2188 * routine which does this.
2191 mpr_user_get_adapter_data(sc, (mpr_adapter_data_t *)arg);
2193 case MPTIOCTL_GET_PCI_INFO:
2195 * The user has requested to read pci info. Call
2196 * our routine which does this.
2200 mpr_user_read_pci_info(sc, (mpr_pci_info_t *)arg);
2203 case MPTIOCTL_RESET_ADAPTER:
2205 sc->port_enable_complete = 0;
2206 uint32_t reinit_start = time_uptime;
2207 error = mpr_reinit(sc);
2208 /* Sleep for 300 second. */
2209 msleep_ret = msleep(&sc->port_enable_complete, &sc->mpr_mtx,
2210 PRIBIO, "mpr_porten", 300 * hz);
2213 printf("Port Enable did not complete after Diag "
2214 "Reset msleep error %d.\n", msleep_ret);
2216 mpr_dprint(sc, MPR_USER, "Hard Reset with Port Enable "
2217 "completed in %d seconds.\n",
2218 (uint32_t)(time_uptime - reinit_start));
2220 case MPTIOCTL_DIAG_ACTION:
2222 * The user has done a diag buffer action. Call our routine
2223 * which does this. Only allow one diag action at one time.
2226 error = mpr_user_diag_action(sc, (mpr_diag_action_t *)arg);
2229 case MPTIOCTL_EVENT_QUERY:
2231 * The user has done an event query. Call our routine which does
2235 mpr_user_event_query(sc, (mpr_event_query_t *)arg);
2237 case MPTIOCTL_EVENT_ENABLE:
2239 * The user has done an event enable. Call our routine which
2243 mpr_user_event_enable(sc, (mpr_event_enable_t *)arg);
2245 case MPTIOCTL_EVENT_REPORT:
2247 * The user has done an event report. Call our routine which
2250 error = mpr_user_event_report(sc, (mpr_event_report_t *)arg);
2252 case MPTIOCTL_REG_ACCESS:
2254 * The user has requested register access. Call our routine
2258 error = mpr_user_reg_access(sc, (mpr_reg_access_t *)arg);
2261 case MPTIOCTL_BTDH_MAPPING:
2263 * The user has requested to translate a bus/target to a
2264 * DevHandle or a DevHandle to a bus/target. Call our routine
2267 error = mpr_user_btdh(sc, (mpr_btdh_mapping_t *)arg);
2274 if (mpr_page != NULL)
2275 free(mpr_page, M_MPRUSER);
2280 #ifdef COMPAT_FREEBSD32
2282 struct mpr_cfg_page_req32 {
2283 MPI2_CONFIG_PAGE_HEADER header;
2284 uint32_t page_address;
2287 uint16_t ioc_status;
2290 struct mpr_ext_cfg_page_req32 {
2291 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2292 uint32_t page_address;
2295 uint16_t ioc_status;
2298 struct mpr_raid_action32 {
2302 uint8_t phys_disk_num;
2303 uint32_t action_data_word;
2306 uint32_t volume_status;
2307 uint32_t action_data[4];
2308 uint16_t action_status;
2309 uint16_t ioc_status;
2313 struct mpr_usr_command32 {
2323 #define MPRIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mpr_cfg_page_req32)
2324 #define MPRIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mpr_cfg_page_req32)
2325 #define MPRIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mpr_ext_cfg_page_req32)
2326 #define MPRIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mpr_ext_cfg_page_req32)
2327 #define MPRIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mpr_cfg_page_req32)
2328 #define MPRIO_RAID_ACTION32 _IOWR('M', 205, struct mpr_raid_action32)
2329 #define MPRIO_MPR_COMMAND32 _IOWR('M', 210, struct mpr_usr_command32)
2332 mpr_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2335 struct mpr_cfg_page_req32 *page32 = _arg;
2336 struct mpr_ext_cfg_page_req32 *ext32 = _arg;
2337 struct mpr_raid_action32 *raid32 = _arg;
2338 struct mpr_usr_command32 *user32 = _arg;
2340 struct mpr_cfg_page_req page;
2341 struct mpr_ext_cfg_page_req ext;
2342 struct mpr_raid_action raid;
2343 struct mpr_usr_command user;
2349 case MPRIO_READ_CFG_HEADER32:
2350 case MPRIO_READ_CFG_PAGE32:
2351 case MPRIO_WRITE_CFG_PAGE32:
2352 if (cmd32 == MPRIO_READ_CFG_HEADER32)
2353 cmd = MPRIO_READ_CFG_HEADER;
2354 else if (cmd32 == MPRIO_READ_CFG_PAGE32)
2355 cmd = MPRIO_READ_CFG_PAGE;
2357 cmd = MPRIO_WRITE_CFG_PAGE;
2358 CP(*page32, arg.page, header);
2359 CP(*page32, arg.page, page_address);
2360 PTRIN_CP(*page32, arg.page, buf);
2361 CP(*page32, arg.page, len);
2362 CP(*page32, arg.page, ioc_status);
2365 case MPRIO_READ_EXT_CFG_HEADER32:
2366 case MPRIO_READ_EXT_CFG_PAGE32:
2367 if (cmd32 == MPRIO_READ_EXT_CFG_HEADER32)
2368 cmd = MPRIO_READ_EXT_CFG_HEADER;
2370 cmd = MPRIO_READ_EXT_CFG_PAGE;
2371 CP(*ext32, arg.ext, header);
2372 CP(*ext32, arg.ext, page_address);
2373 PTRIN_CP(*ext32, arg.ext, buf);
2374 CP(*ext32, arg.ext, len);
2375 CP(*ext32, arg.ext, ioc_status);
2378 case MPRIO_RAID_ACTION32:
2379 cmd = MPRIO_RAID_ACTION;
2380 CP(*raid32, arg.raid, action);
2381 CP(*raid32, arg.raid, volume_bus);
2382 CP(*raid32, arg.raid, volume_id);
2383 CP(*raid32, arg.raid, phys_disk_num);
2384 CP(*raid32, arg.raid, action_data_word);
2385 PTRIN_CP(*raid32, arg.raid, buf);
2386 CP(*raid32, arg.raid, len);
2387 CP(*raid32, arg.raid, volume_status);
2388 bcopy(raid32->action_data, arg.raid.action_data,
2389 sizeof arg.raid.action_data);
2390 CP(*raid32, arg.raid, ioc_status);
2391 CP(*raid32, arg.raid, write);
2394 case MPRIO_MPR_COMMAND32:
2395 cmd = MPRIO_MPR_COMMAND;
2396 PTRIN_CP(*user32, arg.user, req);
2397 CP(*user32, arg.user, req_len);
2398 PTRIN_CP(*user32, arg.user, rpl);
2399 CP(*user32, arg.user, rpl_len);
2400 PTRIN_CP(*user32, arg.user, buf);
2401 CP(*user32, arg.user, len);
2402 CP(*user32, arg.user, flags);
2408 error = mpr_ioctl(dev, cmd, &arg, flag, td);
2409 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2411 case MPRIO_READ_CFG_HEADER32:
2412 case MPRIO_READ_CFG_PAGE32:
2413 case MPRIO_WRITE_CFG_PAGE32:
2414 CP(arg.page, *page32, header);
2415 CP(arg.page, *page32, page_address);
2416 PTROUT_CP(arg.page, *page32, buf);
2417 CP(arg.page, *page32, len);
2418 CP(arg.page, *page32, ioc_status);
2421 case MPRIO_READ_EXT_CFG_HEADER32:
2422 case MPRIO_READ_EXT_CFG_PAGE32:
2423 CP(arg.ext, *ext32, header);
2424 CP(arg.ext, *ext32, page_address);
2425 PTROUT_CP(arg.ext, *ext32, buf);
2426 CP(arg.ext, *ext32, len);
2427 CP(arg.ext, *ext32, ioc_status);
2430 case MPRIO_RAID_ACTION32:
2431 CP(arg.raid, *raid32, action);
2432 CP(arg.raid, *raid32, volume_bus);
2433 CP(arg.raid, *raid32, volume_id);
2434 CP(arg.raid, *raid32, phys_disk_num);
2435 CP(arg.raid, *raid32, action_data_word);
2436 PTROUT_CP(arg.raid, *raid32, buf);
2437 CP(arg.raid, *raid32, len);
2438 CP(arg.raid, *raid32, volume_status);
2439 bcopy(arg.raid.action_data, raid32->action_data,
2440 sizeof arg.raid.action_data);
2441 CP(arg.raid, *raid32, ioc_status);
2442 CP(arg.raid, *raid32, write);
2445 case MPRIO_MPR_COMMAND32:
2446 PTROUT_CP(arg.user, *user32, req);
2447 CP(arg.user, *user32, req_len);
2448 PTROUT_CP(arg.user, *user32, rpl);
2449 CP(arg.user, *user32, rpl_len);
2450 PTROUT_CP(arg.user, *user32, buf);
2451 CP(arg.user, *user32, len);
2452 CP(arg.user, *user32, flags);
2459 #endif /* COMPAT_FREEBSD32 */
2462 mpr_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2465 #ifdef COMPAT_FREEBSD32
2466 if (SV_CURPROC_FLAG(SV_ILP32))
2467 return (mpr_ioctl32(dev, com, arg, flag, td));
2469 return (mpr_ioctl(dev, com, arg, flag, td));