2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2008 Yahoo!, Inc.
6 * Written by: John Baldwin <jhb@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD userland interface
35 * Copyright (c) 2011-2015 LSI Corp.
36 * Copyright (c) 2013-2015 Avago Technologies
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
48 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
65 #include <sys/cdefs.h>
66 __FBSDID("$FreeBSD$");
68 /* TODO Move headers to mpsvar */
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/abi_compat.h>
79 #include <sys/malloc.h>
81 #include <sys/sysctl.h>
82 #include <sys/ioccom.h>
83 #include <sys/endian.h>
84 #include <sys/queue.h>
85 #include <sys/kthread.h>
86 #include <sys/taskqueue.h>
88 #include <sys/sysent.h>
90 #include <machine/bus.h>
91 #include <machine/resource.h>
95 #include <cam/cam_ccb.h>
96 #include <cam/scsi/scsi_all.h>
98 #include <dev/mps/mpi/mpi2_type.h>
99 #include <dev/mps/mpi/mpi2.h>
100 #include <dev/mps/mpi/mpi2_ioc.h>
101 #include <dev/mps/mpi/mpi2_cnfg.h>
102 #include <dev/mps/mpi/mpi2_init.h>
103 #include <dev/mps/mpi/mpi2_tool.h>
104 #include <dev/mps/mps_ioctl.h>
105 #include <dev/mps/mpsvar.h>
106 #include <dev/mps/mps_table.h>
107 #include <dev/mps/mps_sas.h>
108 #include <dev/pci/pcivar.h>
109 #include <dev/pci/pcireg.h>
111 static d_open_t mps_open;
112 static d_close_t mps_close;
113 static d_ioctl_t mps_ioctl_devsw;
115 static struct cdevsw mps_cdevsw = {
116 .d_version = D_VERSION,
119 .d_close = mps_close,
120 .d_ioctl = mps_ioctl_devsw,
124 typedef int (mps_user_f)(struct mps_command *, struct mps_usr_command *);
125 static mps_user_f mpi_pre_ioc_facts;
126 static mps_user_f mpi_pre_port_facts;
127 static mps_user_f mpi_pre_fw_download;
128 static mps_user_f mpi_pre_fw_upload;
129 static mps_user_f mpi_pre_sata_passthrough;
130 static mps_user_f mpi_pre_smp_passthrough;
131 static mps_user_f mpi_pre_config;
132 static mps_user_f mpi_pre_sas_io_unit_control;
134 static int mps_user_read_cfg_header(struct mps_softc *,
135 struct mps_cfg_page_req *);
136 static int mps_user_read_cfg_page(struct mps_softc *,
137 struct mps_cfg_page_req *, void *);
138 static int mps_user_read_extcfg_header(struct mps_softc *,
139 struct mps_ext_cfg_page_req *);
140 static int mps_user_read_extcfg_page(struct mps_softc *,
141 struct mps_ext_cfg_page_req *, void *);
142 static int mps_user_write_cfg_page(struct mps_softc *,
143 struct mps_cfg_page_req *, void *);
144 static int mps_user_setup_request(struct mps_command *,
145 struct mps_usr_command *);
146 static int mps_user_command(struct mps_softc *, struct mps_usr_command *);
148 static int mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data);
149 static void mps_user_get_adapter_data(struct mps_softc *sc,
150 mps_adapter_data_t *data);
151 static void mps_user_read_pci_info(struct mps_softc *sc,
152 mps_pci_info_t *data);
153 static uint8_t mps_get_fw_diag_buffer_number(struct mps_softc *sc,
155 static int mps_post_fw_diag_buffer(struct mps_softc *sc,
156 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code);
157 static int mps_release_fw_diag_buffer(struct mps_softc *sc,
158 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
160 static int mps_diag_register(struct mps_softc *sc,
161 mps_fw_diag_register_t *diag_register, uint32_t *return_code);
162 static int mps_diag_unregister(struct mps_softc *sc,
163 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code);
164 static int mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
165 uint32_t *return_code);
166 static int mps_diag_read_buffer(struct mps_softc *sc,
167 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
168 uint32_t *return_code);
169 static int mps_diag_release(struct mps_softc *sc,
170 mps_fw_diag_release_t *diag_release, uint32_t *return_code);
171 static int mps_do_diag_action(struct mps_softc *sc, uint32_t action,
172 uint8_t *diag_action, uint32_t length, uint32_t *return_code);
173 static int mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data);
174 static void mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data);
175 static void mps_user_event_enable(struct mps_softc *sc,
176 mps_event_enable_t *data);
177 static int mps_user_event_report(struct mps_softc *sc,
178 mps_event_report_t *data);
179 static int mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data);
180 static int mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data);
182 MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
185 mps_attach_user(struct mps_softc *sc)
189 unit = device_get_unit(sc->mps_dev);
190 sc->mps_cdev = make_dev(&mps_cdevsw, unit, UID_ROOT, GID_OPERATOR, 0640,
192 if (sc->mps_cdev == NULL) {
195 sc->mps_cdev->si_drv1 = sc;
200 mps_detach_user(struct mps_softc *sc)
203 /* XXX: do a purge of pending requests? */
204 if (sc->mps_cdev != NULL)
205 destroy_dev(sc->mps_cdev);
209 mps_open(struct cdev *dev, int flags, int fmt, struct thread *td)
216 mps_close(struct cdev *dev, int flags, int fmt, struct thread *td)
223 mps_user_read_cfg_header(struct mps_softc *sc,
224 struct mps_cfg_page_req *page_req)
226 MPI2_CONFIG_PAGE_HEADER *hdr;
227 struct mps_config_params params;
230 hdr = ¶ms.hdr.Struct;
231 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
232 params.page_address = le32toh(page_req->page_address);
233 hdr->PageVersion = 0;
235 hdr->PageNumber = page_req->header.PageNumber;
236 hdr->PageType = page_req->header.PageType;
237 params.buffer = NULL;
239 params.callback = NULL;
241 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
243 * Leave the request. Without resetting the chip, it's
244 * still owned by it and we'll just get into trouble
245 * freeing it now. Mark it as abandoned so that if it
246 * shows up later it can be freed.
248 mps_printf(sc, "read_cfg_header timed out\n");
252 page_req->ioc_status = htole16(params.status);
253 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
254 MPI2_IOCSTATUS_SUCCESS) {
255 bcopy(hdr, &page_req->header, sizeof(page_req->header));
262 mps_user_read_cfg_page(struct mps_softc *sc, struct mps_cfg_page_req *page_req,
265 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
266 struct mps_config_params params;
270 hdr = ¶ms.hdr.Struct;
271 hdr->PageVersion = reqhdr->PageVersion;
272 hdr->PageLength = reqhdr->PageLength;
273 hdr->PageNumber = reqhdr->PageNumber;
274 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
275 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
276 params.page_address = le32toh(page_req->page_address);
278 params.length = le32toh(page_req->len);
279 params.callback = NULL;
281 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
282 mps_printf(sc, "mps_user_read_cfg_page timed out\n");
286 page_req->ioc_status = htole16(params.status);
291 mps_user_read_extcfg_header(struct mps_softc *sc,
292 struct mps_ext_cfg_page_req *ext_page_req)
294 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
295 struct mps_config_params params;
298 hdr = ¶ms.hdr.Ext;
299 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
300 hdr->PageVersion = ext_page_req->header.PageVersion;
301 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
302 hdr->ExtPageLength = 0;
303 hdr->PageNumber = ext_page_req->header.PageNumber;
304 hdr->ExtPageType = ext_page_req->header.ExtPageType;
305 params.page_address = le32toh(ext_page_req->page_address);
306 params.buffer = NULL;
308 params.callback = NULL;
310 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
312 * Leave the request. Without resetting the chip, it's
313 * still owned by it and we'll just get into trouble
314 * freeing it now. Mark it as abandoned so that if it
315 * shows up later it can be freed.
317 mps_printf(sc, "mps_user_read_extcfg_header timed out\n");
321 ext_page_req->ioc_status = htole16(params.status);
322 if ((ext_page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
323 MPI2_IOCSTATUS_SUCCESS) {
324 ext_page_req->header.PageVersion = hdr->PageVersion;
325 ext_page_req->header.PageNumber = hdr->PageNumber;
326 ext_page_req->header.PageType = hdr->PageType;
327 ext_page_req->header.ExtPageLength = hdr->ExtPageLength;
328 ext_page_req->header.ExtPageType = hdr->ExtPageType;
335 mps_user_read_extcfg_page(struct mps_softc *sc,
336 struct mps_ext_cfg_page_req *ext_page_req, void *buf)
338 MPI2_CONFIG_EXTENDED_PAGE_HEADER *reqhdr, *hdr;
339 struct mps_config_params params;
343 hdr = ¶ms.hdr.Ext;
344 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
345 params.page_address = le32toh(ext_page_req->page_address);
346 hdr->PageVersion = reqhdr->PageVersion;
347 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
348 hdr->PageNumber = reqhdr->PageNumber;
349 hdr->ExtPageType = reqhdr->ExtPageType;
350 hdr->ExtPageLength = reqhdr->ExtPageLength;
352 params.length = le32toh(ext_page_req->len);
353 params.callback = NULL;
355 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
356 mps_printf(sc, "mps_user_read_extcfg_page timed out\n");
360 ext_page_req->ioc_status = htole16(params.status);
365 mps_user_write_cfg_page(struct mps_softc *sc,
366 struct mps_cfg_page_req *page_req, void *buf)
368 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
369 struct mps_config_params params;
374 hdr = ¶ms.hdr.Struct;
375 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
376 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
377 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
378 mps_printf(sc, "page type 0x%x not changeable\n",
379 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
384 * There isn't any point in restoring stripped out attributes
385 * if you then mask them going down to issue the request.
388 hdr->PageVersion = reqhdr->PageVersion;
389 hdr->PageLength = reqhdr->PageLength;
390 hdr->PageNumber = reqhdr->PageNumber;
391 hdr->PageType = reqhdr->PageType;
392 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
393 params.page_address = le32toh(page_req->page_address);
395 params.length = le32toh(page_req->len);
396 params.callback = NULL;
398 if ((error = mps_write_config_page(sc, ¶ms)) != 0) {
399 mps_printf(sc, "mps_write_cfg_page timed out\n");
403 page_req->ioc_status = htole16(params.status);
408 mpi_init_sge(struct mps_command *cm, void *req, void *sge)
412 space = (int)cm->cm_sc->reqframesz;
413 off = (uintptr_t)sge - (uintptr_t)req;
415 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
416 req, sge, off, space));
419 cm->cm_sglsize = space - off;
423 * Prepare the mps_command for an IOC_FACTS request.
426 mpi_pre_ioc_facts(struct mps_command *cm, struct mps_usr_command *cmd)
428 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
429 MPI2_IOC_FACTS_REPLY *rpl;
431 if (cmd->req_len != sizeof *req)
433 if (cmd->rpl_len != sizeof *rpl)
442 * Prepare the mps_command for a PORT_FACTS request.
445 mpi_pre_port_facts(struct mps_command *cm, struct mps_usr_command *cmd)
447 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
448 MPI2_PORT_FACTS_REPLY *rpl;
450 if (cmd->req_len != sizeof *req)
452 if (cmd->rpl_len != sizeof *rpl)
461 * Prepare the mps_command for a FW_DOWNLOAD request.
464 mpi_pre_fw_download(struct mps_command *cm, struct mps_usr_command *cmd)
466 MPI2_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
467 MPI2_FW_DOWNLOAD_REPLY *rpl;
468 MPI2_FW_DOWNLOAD_TCSGE tc;
472 * This code assumes there is room in the request's SGL for
473 * the TransactionContext plus at least a SGL chain element.
475 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
477 if (cmd->req_len != sizeof *req)
479 if (cmd->rpl_len != sizeof *rpl)
485 error = copyin(cmd->buf, cm->cm_data, cmd->len);
489 mpi_init_sge(cm, req, &req->SGL);
490 bzero(&tc, sizeof tc);
493 * For now, the F/W image must be provided in a single request.
495 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
497 if (req->TotalImageSize != cmd->len)
501 * The value of the first two elements is specified in the
502 * Fusion-MPT Message Passing Interface document.
505 tc.DetailsLength = 12;
507 tc.ImageSize = cmd->len;
509 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
511 return (mps_push_sge(cm, &tc, sizeof tc, 0));
515 * Prepare the mps_command for a FW_UPLOAD request.
518 mpi_pre_fw_upload(struct mps_command *cm, struct mps_usr_command *cmd)
520 MPI2_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
521 MPI2_FW_UPLOAD_REPLY *rpl;
522 MPI2_FW_UPLOAD_TCSGE tc;
525 * This code assumes there is room in the request's SGL for
526 * the TransactionContext plus at least a SGL chain element.
528 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
530 if (cmd->req_len != sizeof *req)
532 if (cmd->rpl_len != sizeof *rpl)
535 mpi_init_sge(cm, req, &req->SGL);
536 bzero(&tc, sizeof tc);
539 * The value of the first two elements is specified in the
540 * Fusion-MPT Message Passing Interface document.
543 tc.DetailsLength = 12;
545 * XXX Is there any reason to fetch a partial image? I.e. to
546 * set ImageOffset to something other than 0?
549 tc.ImageSize = cmd->len;
551 cm->cm_flags |= MPS_CM_FLAGS_DATAIN;
553 return (mps_push_sge(cm, &tc, sizeof tc, 0));
557 * Prepare the mps_command for a SATA_PASSTHROUGH request.
560 mpi_pre_sata_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
562 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
563 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
565 if (cmd->req_len != sizeof *req)
567 if (cmd->rpl_len != sizeof *rpl)
570 mpi_init_sge(cm, req, &req->SGL);
575 * Prepare the mps_command for a SMP_PASSTHROUGH request.
578 mpi_pre_smp_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
580 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
581 MPI2_SMP_PASSTHROUGH_REPLY *rpl;
583 if (cmd->req_len != sizeof *req)
585 if (cmd->rpl_len != sizeof *rpl)
588 mpi_init_sge(cm, req, &req->SGL);
593 * Prepare the mps_command for a CONFIG request.
596 mpi_pre_config(struct mps_command *cm, struct mps_usr_command *cmd)
598 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
599 MPI2_CONFIG_REPLY *rpl;
601 if (cmd->req_len != sizeof *req)
603 if (cmd->rpl_len != sizeof *rpl)
606 mpi_init_sge(cm, req, &req->PageBufferSGE);
611 * Prepare the mps_command for a SAS_IO_UNIT_CONTROL request.
614 mpi_pre_sas_io_unit_control(struct mps_command *cm,
615 struct mps_usr_command *cmd)
624 * A set of functions to prepare an mps_command for the various
625 * supported requests.
627 struct mps_user_func {
630 } mps_user_func_list[] = {
631 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
632 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
633 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
634 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
635 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
636 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
637 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
638 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
639 { 0xFF, NULL } /* list end */
643 mps_user_setup_request(struct mps_command *cm, struct mps_usr_command *cmd)
645 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
646 struct mps_user_func *f;
648 for (f = mps_user_func_list; f->f_pre != NULL; f++) {
649 if (hdr->Function == f->Function)
650 return (f->f_pre(cm, cmd));
656 mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd)
658 MPI2_REQUEST_HEADER *hdr;
659 MPI2_DEFAULT_REPLY *rpl;
661 struct mps_command *cm = NULL;
666 cm = mps_alloc_command(sc);
669 mps_printf(sc, "%s: no mps requests\n", __func__);
675 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
677 mps_dprint(sc, MPS_USER, "%s: req %p %d rpl %p %d\n", __func__,
678 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len);
680 if (cmd->req_len > sc->reqframesz) {
682 goto RetFreeUnlocked;
684 err = copyin(cmd->req, hdr, cmd->req_len);
686 goto RetFreeUnlocked;
688 mps_dprint(sc, MPS_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
689 hdr->Function, hdr->MsgFlags);
692 buf = malloc(cmd->len, M_MPSUSER, M_WAITOK|M_ZERO);
694 cm->cm_length = cmd->len;
700 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
701 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
703 err = mps_user_setup_request(cm, cmd);
705 mps_printf(sc, "%s: unsupported parameter or unsupported "
706 "function in request (function = 0x%X)\n", __func__,
710 goto RetFreeUnlocked;
713 err = mps_wait_command(sc, &cm, 60, CAN_SLEEP);
715 if (err || (cm == NULL)) {
716 mps_printf(sc, "%s: invalid request: error %d\n",
721 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
723 sz = rpl->MsgLength * 4;
727 if (sz > cmd->rpl_len) {
728 mps_printf(sc, "%s: user reply buffer (%d) smaller than "
729 "returned buffer (%d)\n", __func__, cmd->rpl_len, sz);
734 copyout(rpl, cmd->rpl, sz);
736 copyout(buf, cmd->buf, cmd->len);
737 mps_dprint(sc, MPS_USER, "%s: reply size %d\n", __func__, sz);
743 mps_free_command(sc, cm);
746 free(buf, M_MPSUSER);
751 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
753 MPI2_REQUEST_HEADER *hdr, *tmphdr;
754 MPI2_DEFAULT_REPLY *rpl = NULL;
755 struct mps_command *cm = NULL;
757 int err = 0, dir = 0, sz;
758 uint8_t function = 0;
760 struct mpssas_target *targ = NULL;
763 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
764 * bit to denote that a passthru is being processed.
767 if (sc->mps_flags & MPS_FLAGS_BUSY) {
768 mps_dprint(sc, MPS_USER, "%s: Only one passthru command "
769 "allowed at a single time.", __func__);
773 sc->mps_flags |= MPS_FLAGS_BUSY;
777 * Do some validation on data direction. Valid cases are:
778 * 1) DataSize is 0 and direction is NONE
779 * 2) DataSize is non-zero and one of:
780 * a) direction is READ or
781 * b) direction is WRITE or
782 * c) direction is BOTH and DataOutSize is non-zero
783 * If valid and the direction is BOTH, change the direction to READ.
784 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
786 if (((data->DataSize == 0) &&
787 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
788 ((data->DataSize != 0) &&
789 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
790 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
791 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
792 (data->DataOutSize != 0))))) {
793 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
794 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
796 data->DataOutSize = 0;
799 goto RetFreeUnlocked;
802 mps_dprint(sc, MPS_USER, "%s: req 0x%jx %d rpl 0x%jx %d "
803 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
804 data->PtrRequest, data->RequestSize, data->PtrReply,
805 data->ReplySize, data->PtrData, data->DataSize,
806 data->PtrDataOut, data->DataOutSize, data->DataDirection);
808 if (data->RequestSize > sc->reqframesz) {
810 goto RetFreeUnlocked;
813 req = malloc(data->RequestSize, M_MPSUSER, M_WAITOK | M_ZERO);
814 tmphdr = (MPI2_REQUEST_HEADER *)req;
816 err = copyin(PTRIN(data->PtrRequest), req, data->RequestSize);
818 goto RetFreeUnlocked;
820 function = tmphdr->Function;
821 mps_dprint(sc, MPS_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 = mpssas_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 memcpy(task, req, data->RequestSize);
840 task->TaskMID = cm->cm_desc.Default.SMID;
843 cm->cm_complete = NULL;
844 cm->cm_complete_data = NULL;
846 targ = mpssas_find_target_by_handle(sc->sassc, 0,
849 mps_dprint(sc, MPS_INFO,
850 "%s %d : invalid handle for requested TM 0x%x \n",
851 __func__, __LINE__, task->DevHandle);
854 mpssas_prepare_for_tm(sc, cm, targ, CAM_LUN_WILDCARD);
855 err = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
860 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
864 * Copy the reply data and sense data to user space.
866 if ((cm != NULL) && (cm->cm_reply != NULL)) {
867 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
868 sz = rpl->MsgLength * 4;
870 if (sz > data->ReplySize) {
871 mps_printf(sc, "%s: user reply buffer (%d) "
872 "smaller than returned buffer (%d)\n",
873 __func__, data->ReplySize, sz);
876 copyout(cm->cm_reply, PTRIN(data->PtrReply),
880 mpssas_free_tm(sc, cm);
885 cm = mps_alloc_command(sc);
887 mps_printf(sc, "%s: no mps requests\n", __func__);
893 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
894 memcpy(hdr, req, data->RequestSize);
897 * Do some checking to make sure the IOCTL request contains a valid
898 * request. Then set the SGL info.
900 mpi_init_sge(cm, hdr, (void *)((uint8_t *)hdr + data->RequestSize));
903 * Set up for read, write or both. From check above, DataOutSize will
904 * be 0 if direction is READ or WRITE, but it will have some non-zero
905 * value if the direction is BOTH. So, just use the biggest size to get
906 * the cm_data buffer size. If direction is BOTH, 2 SGLs need to be set
907 * up; the first is for the request and the second will contain the
908 * response data. cm_out_len needs to be set here and this will be used
909 * when the SGLs are set up.
912 cm->cm_length = MAX(data->DataSize, data->DataOutSize);
913 cm->cm_out_len = data->DataOutSize;
915 if (cm->cm_length != 0) {
916 cm->cm_data = malloc(cm->cm_length, M_MPSUSER, M_WAITOK |
918 cm->cm_flags = MPS_CM_FLAGS_DATAIN;
919 if (data->DataOutSize) {
920 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
921 err = copyin(PTRIN(data->PtrDataOut),
922 cm->cm_data, data->DataOutSize);
923 } else if (data->DataDirection ==
924 MPS_PASS_THRU_DIRECTION_WRITE) {
925 cm->cm_flags = MPS_CM_FLAGS_DATAOUT;
926 err = copyin(PTRIN(data->PtrData),
927 cm->cm_data, data->DataSize);
930 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
931 "IOCTL data from user space\n", __func__);
933 cm->cm_flags |= MPS_CM_FLAGS_SGE_SIMPLE;
934 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
937 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
938 * uses SCSI IO descriptor.
940 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
941 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
942 MPI2_SCSI_IO_REQUEST *scsi_io_req;
944 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
946 * Put SGE for data and data_out buffer at the end of
947 * scsi_io_request message header (64 bytes in total).
948 * Following above SGEs, the residual space will be used by
951 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
953 scsi_io_req->SenseBufferLowAddress = htole32(cm->cm_sense_busaddr);
956 * Set SGLOffset0 value. This is the number of dwords that SGL
957 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
959 scsi_io_req->SGLOffset0 = 24;
962 * Setup descriptor info. RAID passthrough must use the
963 * default request descriptor which is already set, so if this
964 * is a SCSI IO request, change the descriptor to SCSI IO.
965 * Also, if this is a SCSI IO request, handle the reply in the
966 * mpssas_scsio_complete function.
968 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
969 cm->cm_desc.SCSIIO.RequestFlags =
970 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
971 cm->cm_desc.SCSIIO.DevHandle = scsi_io_req->DevHandle;
974 * Make sure the DevHandle is not 0 because this is a
977 if (scsi_io_req->DevHandle == 0) {
979 goto RetFreeUnlocked;
986 err = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
988 if (err || (cm == NULL)) {
989 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
992 goto RetFreeUnlocked;
996 * Sync the DMA data, if any. Then copy the data to user space.
998 if (cm->cm_data != NULL) {
999 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN)
1000 dir = BUS_DMASYNC_POSTREAD;
1001 else if (cm->cm_flags & MPS_CM_FLAGS_DATAOUT)
1002 dir = BUS_DMASYNC_POSTWRITE;
1003 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
1004 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
1006 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN) {
1008 err = copyout(cm->cm_data,
1009 PTRIN(data->PtrData), data->DataSize);
1012 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1013 "IOCTL data to user space\n", __func__);
1018 * Copy the reply data and sense data to user space.
1020 if (cm->cm_reply != NULL) {
1021 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1022 sz = rpl->MsgLength * 4;
1024 if (sz > data->ReplySize) {
1025 mps_printf(sc, "%s: user reply buffer (%d) smaller "
1026 "than returned buffer (%d)\n", __func__,
1027 data->ReplySize, sz);
1030 copyout(cm->cm_reply, PTRIN(data->PtrReply), data->ReplySize);
1033 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1034 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1035 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1036 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1038 MIN((le32toh(((MPI2_SCSI_IO_REPLY *)rpl)->
1039 SenseCount)), sizeof(struct
1042 copyout(cm->cm_sense, (PTRIN(data->PtrReply +
1043 sizeof(MPI2_SCSI_IO_REPLY))), sense_len);
1055 free(cm->cm_data, M_MPSUSER);
1056 mps_free_command(sc, cm);
1059 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1061 free(req, M_MPSUSER);
1067 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1069 Mpi2ConfigReply_t mpi_reply;
1070 Mpi2BiosPage3_t config_page;
1073 * Use the PCI interface functions to get the Bus, Device, and Function
1076 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1077 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1078 data->PciInformation.u.bits.FunctionNumber =
1079 pci_get_function(sc->mps_dev);
1082 * Get the FW version that should already be saved in IOC Facts.
1084 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1087 * General device info.
1089 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1090 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1091 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1092 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1093 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1094 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1095 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1098 * Get the driver version.
1100 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1103 * Need to get BIOS Config Page 3 for the BIOS Version.
1105 data->BiosVersion = 0;
1107 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1108 printf("%s: Error while retrieving BIOS Version\n", __func__);
1110 data->BiosVersion = config_page.BiosVersion;
1115 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1120 * Use the PCI interface functions to get the Bus, Device, and Function
1123 data->BusNumber = pci_get_bus(sc->mps_dev);
1124 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1125 data->FunctionNumber = pci_get_function(sc->mps_dev);
1128 * Now get the interrupt vector and the pci header. The vector can
1129 * only be 0 right now. The header is the first 256 bytes of config
1132 data->InterruptVector = 0;
1133 for (i = 0; i < sizeof (data->PciHeader); i++) {
1134 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1139 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1143 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1144 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1149 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1153 mps_post_fw_diag_buffer(struct mps_softc *sc,
1154 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1156 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1157 MPI2_DIAG_BUFFER_POST_REPLY *reply = NULL;
1158 struct mps_command *cm = NULL;
1162 * If buffer is not enabled, just leave.
1164 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1165 if (!pBuffer->enabled) {
1166 return (MPS_DIAG_FAILURE);
1170 * Clear some flags initially.
1172 pBuffer->force_release = FALSE;
1173 pBuffer->valid_data = FALSE;
1174 pBuffer->owned_by_firmware = FALSE;
1179 cm = mps_alloc_command(sc);
1181 mps_printf(sc, "%s: no mps requests\n", __func__);
1182 return (MPS_DIAG_FAILURE);
1186 * Build the request for releasing the FW Diag Buffer and send it.
1188 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1189 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1190 req->BufferType = pBuffer->buffer_type;
1191 req->ExtendedType = pBuffer->extended_type;
1192 req->BufferLength = pBuffer->size;
1193 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1194 req->ProductSpecific[i] = pBuffer->product_specific[i];
1195 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1198 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1199 cm->cm_complete_data = NULL;
1202 * Send command synchronously.
1204 status = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
1205 if (status || (cm == NULL)) {
1206 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1208 status = MPS_DIAG_FAILURE;
1213 * Process POST reply.
1215 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1216 if (reply == NULL) {
1217 mps_printf(sc, "%s: reply is NULL, probably due to "
1218 "reinitialization\n", __func__);
1219 status = MPS_DIAG_FAILURE;
1222 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) !=
1223 MPI2_IOCSTATUS_SUCCESS) {
1224 status = MPS_DIAG_FAILURE;
1225 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1226 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1227 "TransferLength = 0x%x\n", __func__,
1228 le16toh(reply->IOCStatus), le32toh(reply->IOCLogInfo),
1229 le32toh(reply->TransferLength));
1234 * Post was successful.
1236 pBuffer->valid_data = TRUE;
1237 pBuffer->owned_by_firmware = TRUE;
1238 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1239 status = MPS_DIAG_SUCCESS;
1243 mps_free_command(sc, cm);
1248 mps_release_fw_diag_buffer(struct mps_softc *sc,
1249 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1252 MPI2_DIAG_RELEASE_REQUEST *req;
1253 MPI2_DIAG_RELEASE_REPLY *reply = NULL;
1254 struct mps_command *cm = NULL;
1258 * If buffer is not enabled, just leave.
1260 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1261 if (!pBuffer->enabled) {
1262 mps_dprint(sc, MPS_USER, "%s: This buffer type is not "
1263 "supported by the IOC", __func__);
1264 return (MPS_DIAG_FAILURE);
1268 * Clear some flags initially.
1270 pBuffer->force_release = FALSE;
1271 pBuffer->valid_data = FALSE;
1272 pBuffer->owned_by_firmware = FALSE;
1277 cm = mps_alloc_command(sc);
1279 mps_printf(sc, "%s: no mps requests\n", __func__);
1280 return (MPS_DIAG_FAILURE);
1284 * Build the request for releasing the FW Diag Buffer and send it.
1286 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1287 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1288 req->BufferType = pBuffer->buffer_type;
1291 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1292 cm->cm_complete_data = NULL;
1295 * Send command synchronously.
1297 status = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
1298 if (status || (cm == NULL)) {
1299 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1301 status = MPS_DIAG_FAILURE;
1306 * Process RELEASE reply.
1308 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1309 if (reply == NULL) {
1310 mps_printf(sc, "%s: reply is NULL, probably due to "
1311 "reinitialization\n", __func__);
1312 status = MPS_DIAG_FAILURE;
1315 if (((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) !=
1316 MPI2_IOCSTATUS_SUCCESS) || pBuffer->owned_by_firmware) {
1317 status = MPS_DIAG_FAILURE;
1318 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1319 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1320 __func__, le16toh(reply->IOCStatus),
1321 le32toh(reply->IOCLogInfo));
1326 * Release was successful.
1328 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1329 status = MPS_DIAG_SUCCESS;
1332 * If this was for an UNREGISTER diag type command, clear the unique ID.
1334 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1335 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1340 mps_free_command(sc, cm);
1346 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1347 uint32_t *return_code)
1349 bus_dma_template_t t;
1350 mps_fw_diagnostic_buffer_t *pBuffer;
1351 struct mps_busdma_context *ctx;
1352 uint8_t extended_type, buffer_type, i;
1353 uint32_t buffer_size;
1358 extended_type = diag_register->ExtendedType;
1359 buffer_type = diag_register->BufferType;
1360 buffer_size = diag_register->RequestedBufferSize;
1361 unique_id = diag_register->UniqueId;
1366 * Check for valid buffer type
1368 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1369 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1370 return (MPS_DIAG_FAILURE);
1374 * Get the current buffer and look up the unique ID. The unique ID
1375 * should not be found. If it is, the ID is already in use.
1377 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1378 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1379 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1380 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1381 return (MPS_DIAG_FAILURE);
1385 * The buffer's unique ID should not be registered yet, and the given
1386 * unique ID cannot be 0.
1388 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1389 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1390 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1391 return (MPS_DIAG_FAILURE);
1395 * If this buffer is already posted as immediate, just change owner.
1397 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1398 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1399 pBuffer->immediate = FALSE;
1400 pBuffer->unique_id = unique_id;
1401 return (MPS_DIAG_SUCCESS);
1405 * Post a new buffer after checking if it's enabled. The DMA buffer
1406 * that is allocated will be contiguous (nsegments = 1).
1408 if (!pBuffer->enabled) {
1409 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1410 return (MPS_DIAG_FAILURE);
1412 bus_dma_template_init(&t, sc->mps_parent_dmat);
1413 BUS_DMA_TEMPLATE_FILL(&t, BD_NSEGMENTS(1), BD_MAXSIZE(buffer_size),
1414 BD_MAXSEGSIZE(buffer_size), BD_LOWADDR(BUS_SPACE_MAXADDR_32BIT));
1415 if (bus_dma_template_tag(&t, &sc->fw_diag_dmat)) {
1416 mps_dprint(sc, MPS_ERROR,
1417 "Cannot allocate FW diag buffer DMA tag\n");
1418 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1419 status = MPS_DIAG_FAILURE;
1422 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1423 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1424 mps_dprint(sc, MPS_ERROR,
1425 "Cannot allocate FW diag buffer memory\n");
1426 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1427 status = MPS_DIAG_FAILURE;
1430 bzero(sc->fw_diag_buffer, buffer_size);
1432 ctx = malloc(sizeof(*ctx), M_MPSUSER, M_WAITOK | M_ZERO);
1433 ctx->addr = &sc->fw_diag_busaddr;
1434 ctx->buffer_dmat = sc->fw_diag_dmat;
1435 ctx->buffer_dmamap = sc->fw_diag_map;
1437 error = bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map,
1438 sc->fw_diag_buffer, buffer_size, mps_memaddr_wait_cb,
1441 if (error == EINPROGRESS) {
1443 device_printf(sc->mps_dev, "%s: Deferred bus_dmamap_load\n",
1446 * Wait for the load to complete. If we're interrupted,
1450 if (ctx->completed == 0) {
1451 error = msleep(ctx, &sc->mps_mtx, PCATCH, "mpswait", 0);
1454 * We got an error from msleep(9). This is
1455 * most likely due to a signal. Tell
1456 * mpr_memaddr_wait_cb() that we've abandoned
1457 * the context, so it needs to clean up when
1462 /* The callback will free this memory */
1466 device_printf(sc->mps_dev, "Cannot "
1467 "bus_dmamap_load FW diag buffer, error = "
1468 "%d returned from msleep\n", error);
1469 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1470 status = MPS_DIAG_FAILURE;
1477 if ((error != 0) || (ctx->error != 0)) {
1478 device_printf(sc->mps_dev, "Cannot bus_dmamap_load FW diag "
1479 "buffer, %serror = %d\n", error ? "" : "callback ",
1480 error ? error : ctx->error);
1481 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1482 status = MPS_DIAG_FAILURE;
1486 bus_dmamap_sync(sc->fw_diag_dmat, sc->fw_diag_map, BUS_DMASYNC_PREREAD);
1488 pBuffer->size = buffer_size;
1491 * Copy the given info to the diag buffer and post the buffer.
1493 pBuffer->buffer_type = buffer_type;
1494 pBuffer->immediate = FALSE;
1495 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1496 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1498 pBuffer->product_specific[i] =
1499 diag_register->ProductSpecific[i];
1502 pBuffer->extended_type = extended_type;
1503 pBuffer->unique_id = unique_id;
1504 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1508 * In case there was a failure, free the DMA buffer.
1510 if (status == MPS_DIAG_FAILURE) {
1511 if (sc->fw_diag_busaddr != 0) {
1512 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1513 sc->fw_diag_busaddr = 0;
1515 if (sc->fw_diag_buffer != NULL) {
1516 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1518 sc->fw_diag_buffer = NULL;
1520 if (sc->fw_diag_dmat != NULL) {
1521 bus_dma_tag_destroy(sc->fw_diag_dmat);
1522 sc->fw_diag_dmat = NULL;
1527 free(ctx, M_MPSUSER);
1533 mps_diag_unregister(struct mps_softc *sc,
1534 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1536 mps_fw_diagnostic_buffer_t *pBuffer;
1541 unique_id = diag_unregister->UniqueId;
1544 * Get the current buffer and look up the unique ID. The unique ID
1547 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1548 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1549 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1550 return (MPS_DIAG_FAILURE);
1553 pBuffer = &sc->fw_diag_buffer_list[i];
1556 * Try to release the buffer from FW before freeing it. If release
1557 * fails, don't free the DMA buffer in case FW tries to access it
1558 * later. If buffer is not owned by firmware, can't release it.
1560 if (!pBuffer->owned_by_firmware) {
1561 status = MPS_DIAG_SUCCESS;
1563 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1564 MPS_FW_DIAG_TYPE_UNREGISTER);
1568 * At this point, return the current status no matter what happens with
1571 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1572 if (status == MPS_DIAG_SUCCESS) {
1573 if (sc->fw_diag_busaddr != 0) {
1574 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1575 sc->fw_diag_busaddr = 0;
1577 if (sc->fw_diag_buffer != NULL) {
1578 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1580 sc->fw_diag_buffer = NULL;
1582 if (sc->fw_diag_dmat != NULL) {
1583 bus_dma_tag_destroy(sc->fw_diag_dmat);
1584 sc->fw_diag_dmat = NULL;
1592 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1593 uint32_t *return_code)
1595 mps_fw_diagnostic_buffer_t *pBuffer;
1599 unique_id = diag_query->UniqueId;
1602 * If ID is valid, query on ID.
1603 * If ID is invalid, query on buffer type.
1605 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1606 i = diag_query->BufferType;
1607 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1608 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1609 return (MPS_DIAG_FAILURE);
1612 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1613 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1614 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1615 return (MPS_DIAG_FAILURE);
1620 * Fill query structure with the diag buffer info.
1622 pBuffer = &sc->fw_diag_buffer_list[i];
1623 diag_query->BufferType = pBuffer->buffer_type;
1624 diag_query->ExtendedType = pBuffer->extended_type;
1625 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1626 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1628 diag_query->ProductSpecific[i] =
1629 pBuffer->product_specific[i];
1632 diag_query->TotalBufferSize = pBuffer->size;
1633 diag_query->DriverAddedBufferSize = 0;
1634 diag_query->UniqueId = pBuffer->unique_id;
1635 diag_query->ApplicationFlags = 0;
1636 diag_query->DiagnosticFlags = 0;
1639 * Set/Clear application flags
1641 if (pBuffer->immediate) {
1642 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1644 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1646 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1647 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1649 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1651 if (pBuffer->owned_by_firmware) {
1652 diag_query->ApplicationFlags |=
1653 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1655 diag_query->ApplicationFlags &=
1656 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1659 return (MPS_DIAG_SUCCESS);
1663 mps_diag_read_buffer(struct mps_softc *sc,
1664 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1665 uint32_t *return_code)
1667 mps_fw_diagnostic_buffer_t *pBuffer;
1672 unique_id = diag_read_buffer->UniqueId;
1675 * Get the current buffer and look up the unique ID. The unique ID
1678 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1679 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1680 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1681 return (MPS_DIAG_FAILURE);
1684 pBuffer = &sc->fw_diag_buffer_list[i];
1687 * Make sure requested read is within limits
1689 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1691 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1692 return (MPS_DIAG_FAILURE);
1695 /* Sync the DMA map before we copy to userland. */
1696 bus_dmamap_sync(sc->fw_diag_dmat, sc->fw_diag_map,
1697 BUS_DMASYNC_POSTREAD);
1700 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1701 * buffer that was allocated is one contiguous buffer.
1703 pData = (uint8_t *)(sc->fw_diag_buffer +
1704 diag_read_buffer->StartingOffset);
1705 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1706 return (MPS_DIAG_FAILURE);
1707 diag_read_buffer->Status = 0;
1710 * Set or clear the Force Release flag.
1712 if (pBuffer->force_release) {
1713 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1715 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1719 * If buffer is to be reregistered, make sure it's not already owned by
1722 status = MPS_DIAG_SUCCESS;
1723 if (!pBuffer->owned_by_firmware) {
1724 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1725 status = mps_post_fw_diag_buffer(sc, pBuffer,
1734 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1735 uint32_t *return_code)
1737 mps_fw_diagnostic_buffer_t *pBuffer;
1742 unique_id = diag_release->UniqueId;
1745 * Get the current buffer and look up the unique ID. The unique ID
1748 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1749 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1750 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1751 return (MPS_DIAG_FAILURE);
1754 pBuffer = &sc->fw_diag_buffer_list[i];
1757 * If buffer is not owned by firmware, it's already been released.
1759 if (!pBuffer->owned_by_firmware) {
1760 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1761 return (MPS_DIAG_FAILURE);
1765 * Release the buffer.
1767 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1768 MPS_FW_DIAG_TYPE_RELEASE);
1773 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1774 uint32_t length, uint32_t *return_code)
1776 mps_fw_diag_register_t diag_register;
1777 mps_fw_diag_unregister_t diag_unregister;
1778 mps_fw_diag_query_t diag_query;
1779 mps_diag_read_buffer_t diag_read_buffer;
1780 mps_fw_diag_release_t diag_release;
1781 int status = MPS_DIAG_SUCCESS;
1782 uint32_t original_return_code;
1784 original_return_code = *return_code;
1785 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1788 case MPS_FW_DIAG_TYPE_REGISTER:
1791 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1792 status = MPS_DIAG_FAILURE;
1795 if (copyin(diag_action, &diag_register,
1796 sizeof(diag_register)) != 0)
1797 return (MPS_DIAG_FAILURE);
1798 status = mps_diag_register(sc, &diag_register,
1802 case MPS_FW_DIAG_TYPE_UNREGISTER:
1803 if (length < sizeof(diag_unregister)) {
1805 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1806 status = MPS_DIAG_FAILURE;
1809 if (copyin(diag_action, &diag_unregister,
1810 sizeof(diag_unregister)) != 0)
1811 return (MPS_DIAG_FAILURE);
1812 status = mps_diag_unregister(sc, &diag_unregister,
1816 case MPS_FW_DIAG_TYPE_QUERY:
1817 if (length < sizeof (diag_query)) {
1819 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1820 status = MPS_DIAG_FAILURE;
1823 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1825 return (MPS_DIAG_FAILURE);
1826 status = mps_diag_query(sc, &diag_query, return_code);
1827 if (status == MPS_DIAG_SUCCESS)
1828 if (copyout(&diag_query, diag_action,
1829 sizeof (diag_query)) != 0)
1830 return (MPS_DIAG_FAILURE);
1833 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1834 if (copyin(diag_action, &diag_read_buffer,
1835 sizeof(diag_read_buffer)) != 0)
1836 return (MPS_DIAG_FAILURE);
1837 if (length < diag_read_buffer.BytesToRead) {
1839 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1840 status = MPS_DIAG_FAILURE;
1843 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1844 PTRIN(diag_read_buffer.PtrDataBuffer),
1846 if (status == MPS_DIAG_SUCCESS) {
1847 if (copyout(&diag_read_buffer, diag_action,
1848 sizeof(diag_read_buffer) -
1849 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1851 return (MPS_DIAG_FAILURE);
1855 case MPS_FW_DIAG_TYPE_RELEASE:
1856 if (length < sizeof(diag_release)) {
1858 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1859 status = MPS_DIAG_FAILURE;
1862 if (copyin(diag_action, &diag_release,
1863 sizeof(diag_release)) != 0)
1864 return (MPS_DIAG_FAILURE);
1865 status = mps_diag_release(sc, &diag_release,
1870 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1871 status = MPS_DIAG_FAILURE;
1875 if ((status == MPS_DIAG_FAILURE) &&
1876 (original_return_code == MPS_FW_DIAG_NEW) &&
1877 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1878 status = MPS_DIAG_SUCCESS;
1884 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1889 * Only allow one diag action at one time.
1891 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1892 mps_dprint(sc, MPS_USER, "%s: Only one FW diag command "
1893 "allowed at a single time.", __func__);
1896 sc->mps_flags |= MPS_FLAGS_BUSY;
1899 * Send diag action request
1901 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1902 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1903 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1904 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1905 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1906 status = mps_do_diag_action(sc, data->Action,
1907 PTRIN(data->PtrDiagAction), data->Length,
1912 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1917 * Copy the event recording mask and the event queue size out. For
1918 * clarification, the event recording mask (events_to_record) is not the same
1919 * thing as the event mask (event_mask). events_to_record has a bit set for
1920 * every event type that is to be recorded by the driver, and event_mask has a
1921 * bit cleared for every event that is allowed into the driver from the IOC.
1922 * They really have nothing to do with each other.
1925 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1930 data->Entries = MPS_EVENT_QUEUE_SIZE;
1932 for (i = 0; i < 4; i++) {
1933 data->Types[i] = sc->events_to_record[i];
1939 * Set the driver's event mask according to what's been given. See
1940 * mps_user_event_query for explanation of the event recording mask and the IOC
1941 * event mask. It's the app's responsibility to enable event logging by setting
1942 * the bits in events_to_record. Initially, no events will be logged.
1945 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1950 for (i = 0; i < 4; i++) {
1951 sc->events_to_record[i] = data->Types[i];
1957 * Copy out the events that have been recorded, up to the max events allowed.
1960 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1967 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1969 if (copyout((void *)sc->recorded_events,
1970 PTRIN(data->PtrEvents), size) != 0)
1975 * data->Size value is not large enough to copy event data.
1981 * Change size value to match the number of bytes that were copied.
1984 data->Size = sizeof(sc->recorded_events);
1991 * Record events into the driver from the IOC if they are not masked.
1994 mpssas_record_event(struct mps_softc *sc,
1995 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1999 uint16_t event_data_len;
2000 boolean_t sendAEN = FALSE;
2002 event = event_reply->Event;
2005 * Generate a system event to let anyone who cares know that a
2006 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
2007 * event mask is set to.
2009 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
2014 * Record the event only if its corresponding bit is set in
2015 * events_to_record. event_index is the index into recorded_events and
2016 * event_number is the overall number of an event being recorded since
2017 * start-of-day. event_index will roll over; event_number will never
2020 i = (uint8_t)(event / 32);
2021 j = (uint8_t)(event % 32);
2022 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
2023 i = sc->event_index;
2024 sc->recorded_events[i].Type = event;
2025 sc->recorded_events[i].Number = ++sc->event_number;
2026 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
2028 event_data_len = event_reply->EventDataLength;
2030 if (event_data_len > 0) {
2032 * Limit data to size in m_event entry
2034 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
2035 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
2037 for (j = 0; j < event_data_len; j++) {
2038 sc->recorded_events[i].Data[j] =
2039 event_reply->EventData[j];
2043 * check for index wrap-around
2045 if (++i == MPS_EVENT_QUEUE_SIZE) {
2048 sc->event_index = (uint8_t)i;
2051 * Set flag to send the event.
2058 * Generate a system event if flag is set to let anyone who cares know
2059 * that an event has occurred.
2062 //SLM-how to send a system event (see kqueue, kevent)
2063 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
2064 // "SAS", NULL, NULL, DDI_NOSLEEP);
2069 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
2073 switch (data->Command) {
2075 * IO access is not supported.
2079 mps_dprint(sc, MPS_USER, "IO access is not supported. "
2080 "Use memory access.");
2085 data->RegData = mps_regread(sc, data->RegOffset);
2089 mps_regwrite(sc, data->RegOffset, data->RegData);
2101 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
2103 uint8_t bt2dh = FALSE;
2104 uint8_t dh2bt = FALSE;
2105 uint16_t dev_handle, bus, target;
2108 target = data->TargetID;
2109 dev_handle = data->DevHandle;
2112 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2113 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2114 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2117 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2119 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2121 if (!dh2bt && !bt2dh)
2125 * Only handle bus of 0. Make sure target is within range.
2131 if (target >= sc->max_devices) {
2132 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2133 "for Bus/Target to DevHandle mapping.");
2136 dev_handle = sc->mapping_table[target].dev_handle;
2138 data->DevHandle = dev_handle;
2141 target = mps_mapping_get_tid_from_handle(sc, dev_handle);
2143 data->TargetID = target;
2150 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2153 struct mps_softc *sc;
2154 struct mps_cfg_page_req *page_req;
2155 struct mps_ext_cfg_page_req *ext_page_req;
2157 int error, msleep_ret;
2161 page_req = (void *)arg;
2162 ext_page_req = (void *)arg;
2165 case MPSIO_READ_CFG_HEADER:
2167 error = mps_user_read_cfg_header(sc, page_req);
2170 case MPSIO_READ_CFG_PAGE:
2171 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2172 error = copyin(page_req->buf, mps_page,
2173 sizeof(MPI2_CONFIG_PAGE_HEADER));
2177 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2181 error = copyout(mps_page, page_req->buf, page_req->len);
2183 case MPSIO_READ_EXT_CFG_HEADER:
2185 error = mps_user_read_extcfg_header(sc, ext_page_req);
2188 case MPSIO_READ_EXT_CFG_PAGE:
2189 mps_page = malloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2190 error = copyin(ext_page_req->buf, mps_page,
2191 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2195 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2199 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2201 case MPSIO_WRITE_CFG_PAGE:
2202 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2203 error = copyin(page_req->buf, mps_page, page_req->len);
2207 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2210 case MPSIO_MPS_COMMAND:
2211 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2213 case MPTIOCTL_PASS_THRU:
2215 * The user has requested to pass through a command to be
2216 * executed by the MPT firmware. Call our routine which does
2217 * this. Only allow one passthru IOCTL at one time.
2219 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2221 case MPTIOCTL_GET_ADAPTER_DATA:
2223 * The user has requested to read adapter data. Call our
2224 * routine which does this.
2227 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2229 case MPTIOCTL_GET_PCI_INFO:
2231 * The user has requested to read pci info. Call
2232 * our routine which does this.
2236 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2239 case MPTIOCTL_RESET_ADAPTER:
2241 sc->port_enable_complete = 0;
2242 uint32_t reinit_start = time_uptime;
2243 error = mps_reinit(sc);
2244 /* Sleep for 300 second. */
2245 msleep_ret = msleep(&sc->port_enable_complete, &sc->mps_mtx, PRIBIO,
2246 "mps_porten", 300 * hz);
2249 printf("Port Enable did not complete after Diag "
2250 "Reset msleep error %d.\n", msleep_ret);
2252 mps_dprint(sc, MPS_USER,
2253 "Hard Reset with Port Enable completed in %d seconds.\n",
2254 (uint32_t) (time_uptime - reinit_start));
2256 case MPTIOCTL_DIAG_ACTION:
2258 * The user has done a diag buffer action. Call our routine
2259 * which does this. Only allow one diag action at one time.
2262 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2265 case MPTIOCTL_EVENT_QUERY:
2267 * The user has done an event query. Call our routine which does
2271 mps_user_event_query(sc, (mps_event_query_t *)arg);
2273 case MPTIOCTL_EVENT_ENABLE:
2275 * The user has done an event enable. Call our routine which
2279 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2281 case MPTIOCTL_EVENT_REPORT:
2283 * The user has done an event report. Call our routine which
2286 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2288 case MPTIOCTL_REG_ACCESS:
2290 * The user has requested register access. Call our routine
2294 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2297 case MPTIOCTL_BTDH_MAPPING:
2299 * The user has requested to translate a bus/target to a
2300 * DevHandle or a DevHandle to a bus/target. Call our routine
2303 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2310 if (mps_page != NULL)
2311 free(mps_page, M_MPSUSER);
2316 #ifdef COMPAT_FREEBSD32
2318 struct mps_cfg_page_req32 {
2319 MPI2_CONFIG_PAGE_HEADER header;
2320 uint32_t page_address;
2323 uint16_t ioc_status;
2326 struct mps_ext_cfg_page_req32 {
2327 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2328 uint32_t page_address;
2331 uint16_t ioc_status;
2334 struct mps_raid_action32 {
2338 uint8_t phys_disk_num;
2339 uint32_t action_data_word;
2342 uint32_t volume_status;
2343 uint32_t action_data[4];
2344 uint16_t action_status;
2345 uint16_t ioc_status;
2349 struct mps_usr_command32 {
2359 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2360 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2361 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2362 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2363 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2364 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2365 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2368 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2371 struct mps_cfg_page_req32 *page32 = _arg;
2372 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2373 struct mps_raid_action32 *raid32 = _arg;
2374 struct mps_usr_command32 *user32 = _arg;
2376 struct mps_cfg_page_req page;
2377 struct mps_ext_cfg_page_req ext;
2378 struct mps_raid_action raid;
2379 struct mps_usr_command user;
2385 case MPSIO_READ_CFG_HEADER32:
2386 case MPSIO_READ_CFG_PAGE32:
2387 case MPSIO_WRITE_CFG_PAGE32:
2388 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2389 cmd = MPSIO_READ_CFG_HEADER;
2390 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2391 cmd = MPSIO_READ_CFG_PAGE;
2393 cmd = MPSIO_WRITE_CFG_PAGE;
2394 CP(*page32, arg.page, header);
2395 CP(*page32, arg.page, page_address);
2396 PTRIN_CP(*page32, arg.page, buf);
2397 CP(*page32, arg.page, len);
2398 CP(*page32, arg.page, ioc_status);
2401 case MPSIO_READ_EXT_CFG_HEADER32:
2402 case MPSIO_READ_EXT_CFG_PAGE32:
2403 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2404 cmd = MPSIO_READ_EXT_CFG_HEADER;
2406 cmd = MPSIO_READ_EXT_CFG_PAGE;
2407 CP(*ext32, arg.ext, header);
2408 CP(*ext32, arg.ext, page_address);
2409 PTRIN_CP(*ext32, arg.ext, buf);
2410 CP(*ext32, arg.ext, len);
2411 CP(*ext32, arg.ext, ioc_status);
2414 case MPSIO_RAID_ACTION32:
2415 cmd = MPSIO_RAID_ACTION;
2416 CP(*raid32, arg.raid, action);
2417 CP(*raid32, arg.raid, volume_bus);
2418 CP(*raid32, arg.raid, volume_id);
2419 CP(*raid32, arg.raid, phys_disk_num);
2420 CP(*raid32, arg.raid, action_data_word);
2421 PTRIN_CP(*raid32, arg.raid, buf);
2422 CP(*raid32, arg.raid, len);
2423 CP(*raid32, arg.raid, volume_status);
2424 bcopy(raid32->action_data, arg.raid.action_data,
2425 sizeof arg.raid.action_data);
2426 CP(*raid32, arg.raid, ioc_status);
2427 CP(*raid32, arg.raid, write);
2430 case MPSIO_MPS_COMMAND32:
2431 cmd = MPSIO_MPS_COMMAND;
2432 PTRIN_CP(*user32, arg.user, req);
2433 CP(*user32, arg.user, req_len);
2434 PTRIN_CP(*user32, arg.user, rpl);
2435 CP(*user32, arg.user, rpl_len);
2436 PTRIN_CP(*user32, arg.user, buf);
2437 CP(*user32, arg.user, len);
2438 CP(*user32, arg.user, flags);
2444 error = mps_ioctl(dev, cmd, &arg, flag, td);
2445 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2447 case MPSIO_READ_CFG_HEADER32:
2448 case MPSIO_READ_CFG_PAGE32:
2449 case MPSIO_WRITE_CFG_PAGE32:
2450 CP(arg.page, *page32, header);
2451 CP(arg.page, *page32, page_address);
2452 PTROUT_CP(arg.page, *page32, buf);
2453 CP(arg.page, *page32, len);
2454 CP(arg.page, *page32, ioc_status);
2457 case MPSIO_READ_EXT_CFG_HEADER32:
2458 case MPSIO_READ_EXT_CFG_PAGE32:
2459 CP(arg.ext, *ext32, header);
2460 CP(arg.ext, *ext32, page_address);
2461 PTROUT_CP(arg.ext, *ext32, buf);
2462 CP(arg.ext, *ext32, len);
2463 CP(arg.ext, *ext32, ioc_status);
2466 case MPSIO_RAID_ACTION32:
2467 CP(arg.raid, *raid32, action);
2468 CP(arg.raid, *raid32, volume_bus);
2469 CP(arg.raid, *raid32, volume_id);
2470 CP(arg.raid, *raid32, phys_disk_num);
2471 CP(arg.raid, *raid32, action_data_word);
2472 PTROUT_CP(arg.raid, *raid32, buf);
2473 CP(arg.raid, *raid32, len);
2474 CP(arg.raid, *raid32, volume_status);
2475 bcopy(arg.raid.action_data, raid32->action_data,
2476 sizeof arg.raid.action_data);
2477 CP(arg.raid, *raid32, ioc_status);
2478 CP(arg.raid, *raid32, write);
2481 case MPSIO_MPS_COMMAND32:
2482 PTROUT_CP(arg.user, *user32, req);
2483 CP(arg.user, *user32, req_len);
2484 PTROUT_CP(arg.user, *user32, rpl);
2485 CP(arg.user, *user32, rpl_len);
2486 PTROUT_CP(arg.user, *user32, buf);
2487 CP(arg.user, *user32, len);
2488 CP(arg.user, *user32, flags);
2495 #endif /* COMPAT_FREEBSD32 */
2498 mps_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2501 #ifdef COMPAT_FREEBSD32
2502 if (SV_CURPROC_FLAG(SV_ILP32))
2503 return (mps_ioctl32(dev, com, arg, flag, td));
2505 return (mps_ioctl(dev, com, arg, flag, td));