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 * LSI MPT-Fusion Host Adapter FreeBSD userland interface
33 * Copyright (c) 2011 LSI Corp.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * LSI MPT-Fusion Host Adapter FreeBSD
59 * $FreeBSD: src/sys/dev/mps/mps_user.c,v 1.10 2012/01/26 18:17:21 ken Exp $
62 #include "opt_compat.h"
64 /* TODO Move headers to mpsvar */
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
69 #include <sys/module.h>
72 #include <sys/eventhandler.h>
74 #include <sys/malloc.h>
76 #include <sys/sysctl.h>
77 #include <sys/ioccom.h>
78 #include <sys/endian.h>
79 #include <sys/queue.h>
80 #include <sys/kthread.h>
81 #include <sys/taskqueue.h>
83 #include <sys/sysent.h>
86 #include <sys/device.h>
88 #include <bus/cam/cam.h>
89 #include <bus/cam/scsi/scsi_all.h>
91 #include <dev/raid/mps/mpi/mpi2_type.h>
92 #include <dev/raid/mps/mpi/mpi2.h>
93 #include <dev/raid/mps/mpi/mpi2_ioc.h>
94 #include <dev/raid/mps/mpi/mpi2_cnfg.h>
95 #include <dev/raid/mps/mpi/mpi2_init.h>
96 #include <dev/raid/mps/mpi/mpi2_tool.h>
97 #include <dev/raid/mps/mps_ioctl.h>
98 #include <dev/raid/mps/mpsvar.h>
99 #include <dev/raid/mps/mps_table.h>
100 #include <dev/raid/mps/mps_sas.h>
101 #include <bus/pci/pcivar.h>
102 #include <bus/pci/pcireg.h>
104 static d_open_t mps_open;
105 static d_close_t mps_close;
106 static d_ioctl_t mps_ioctl_devsw;
108 static struct dev_ops mps_ops = {
111 .d_close = mps_close,
112 .d_ioctl = mps_ioctl_devsw,
115 typedef int (mps_user_f)(struct mps_command *, struct mps_usr_command *);
116 static mps_user_f mpi_pre_ioc_facts;
117 static mps_user_f mpi_pre_port_facts;
118 static mps_user_f mpi_pre_fw_download;
119 static mps_user_f mpi_pre_fw_upload;
120 static mps_user_f mpi_pre_sata_passthrough;
121 static mps_user_f mpi_pre_smp_passthrough;
122 static mps_user_f mpi_pre_config;
123 static mps_user_f mpi_pre_sas_io_unit_control;
125 static int mps_user_read_cfg_header(struct mps_softc *,
126 struct mps_cfg_page_req *);
127 static int mps_user_read_cfg_page(struct mps_softc *,
128 struct mps_cfg_page_req *, void *);
129 static int mps_user_read_extcfg_header(struct mps_softc *,
130 struct mps_ext_cfg_page_req *);
131 static int mps_user_read_extcfg_page(struct mps_softc *,
132 struct mps_ext_cfg_page_req *, void *);
133 static int mps_user_write_cfg_page(struct mps_softc *,
134 struct mps_cfg_page_req *, void *);
135 static int mps_user_setup_request(struct mps_command *,
136 struct mps_usr_command *);
137 static int mps_user_command(struct mps_softc *, struct mps_usr_command *);
139 static int mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data);
140 static void mps_user_get_adapter_data(struct mps_softc *sc,
141 mps_adapter_data_t *data);
142 static void mps_user_read_pci_info(struct mps_softc *sc,
143 mps_pci_info_t *data);
144 static uint8_t mps_get_fw_diag_buffer_number(struct mps_softc *sc,
146 static int mps_post_fw_diag_buffer(struct mps_softc *sc,
147 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code);
148 static int mps_release_fw_diag_buffer(struct mps_softc *sc,
149 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
151 static int mps_diag_register(struct mps_softc *sc,
152 mps_fw_diag_register_t *diag_register, uint32_t *return_code);
153 static int mps_diag_unregister(struct mps_softc *sc,
154 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code);
155 static int mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
156 uint32_t *return_code);
157 static int mps_diag_read_buffer(struct mps_softc *sc,
158 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
159 uint32_t *return_code);
160 static int mps_diag_release(struct mps_softc *sc,
161 mps_fw_diag_release_t *diag_release, uint32_t *return_code);
162 static int mps_do_diag_action(struct mps_softc *sc, uint32_t action,
163 uint8_t *diag_action, uint32_t length, uint32_t *return_code);
164 static int mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data);
165 static void mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data);
166 static void mps_user_event_enable(struct mps_softc *sc,
167 mps_event_enable_t *data);
168 static int mps_user_event_report(struct mps_softc *sc,
169 mps_event_report_t *data);
170 static int mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data);
171 static int mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data);
173 static MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
175 /* Macros from compat/freebsd32/freebsd32.h */
176 #define PTRIN(v) (void *)(uintptr_t)(v)
177 #define PTROUT(v) (uint32_t)(uintptr_t)(v)
179 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
180 #define PTRIN_CP(src,dst,fld) \
181 do { (dst).fld = PTRIN((src).fld); } while (0)
182 #define PTROUT_CP(src,dst,fld) \
183 do { (dst).fld = PTROUT((src).fld); } while (0)
186 mps_attach_user(struct mps_softc *sc)
190 unit = device_get_unit(sc->mps_dev);
191 sc->mps_cdev = make_dev(&mps_ops, unit, UID_ROOT, GID_OPERATOR, 0640,
193 if (sc->mps_cdev == NULL) {
196 sc->mps_cdev->si_drv1 = sc;
201 mps_detach_user(struct mps_softc *sc)
204 /* XXX: do a purge of pending requests? */
205 destroy_dev(sc->mps_cdev);
210 mps_open(struct dev_open_args *ap)
217 mps_close(struct dev_close_args *ap)
224 mps_user_read_cfg_header(struct mps_softc *sc,
225 struct mps_cfg_page_req *page_req)
227 MPI2_CONFIG_PAGE_HEADER *hdr;
228 struct mps_config_params params;
231 hdr = ¶ms.hdr.Struct;
232 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
233 params.page_address = le32toh(page_req->page_address);
234 hdr->PageVersion = 0;
236 hdr->PageNumber = page_req->header.PageNumber;
237 hdr->PageType = page_req->header.PageType;
238 params.buffer = NULL;
240 params.callback = NULL;
242 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
244 * Leave the request. Without resetting the chip, it's
245 * still owned by it and we'll just get into trouble
246 * freeing it now. Mark it as abandoned so that if it
247 * shows up later it can be freed.
249 mps_printf(sc, "read_cfg_header timed out\n");
253 page_req->ioc_status = htole16(params.status);
254 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
255 MPI2_IOCSTATUS_SUCCESS) {
256 bcopy(hdr, &page_req->header, sizeof(page_req->header));
263 mps_user_read_cfg_page(struct mps_softc *sc, struct mps_cfg_page_req *page_req,
266 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
267 struct mps_config_params params;
271 hdr = ¶ms.hdr.Struct;
272 hdr->PageVersion = reqhdr->PageVersion;
273 hdr->PageLength = reqhdr->PageLength;
274 hdr->PageNumber = reqhdr->PageNumber;
275 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
276 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
277 params.page_address = le32toh(page_req->page_address);
279 params.length = le32toh(page_req->len);
280 params.callback = NULL;
282 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
283 mps_printf(sc, "mps_user_read_cfg_page timed out\n");
287 page_req->ioc_status = htole16(params.status);
292 mps_user_read_extcfg_header(struct mps_softc *sc,
293 struct mps_ext_cfg_page_req *ext_page_req)
295 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
296 struct mps_config_params params;
299 hdr = ¶ms.hdr.Ext;
300 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
301 hdr->PageVersion = ext_page_req->header.PageVersion;
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 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
308 * Leave the request. Without resetting the chip, it's
309 * still owned by it and we'll just get into trouble
310 * freeing it now. Mark it as abandoned so that if it
311 * shows up later it can be freed.
313 mps_printf(sc, "mps_user_read_extcfg_header timed out\n");
317 ext_page_req->ioc_status = htole16(params.status);
318 if ((ext_page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
319 MPI2_IOCSTATUS_SUCCESS) {
320 ext_page_req->header.PageVersion = hdr->PageVersion;
321 ext_page_req->header.PageNumber = hdr->PageNumber;
322 ext_page_req->header.PageType = hdr->PageType;
323 ext_page_req->header.ExtPageLength = hdr->ExtPageLength;
324 ext_page_req->header.ExtPageType = hdr->ExtPageType;
331 mps_user_read_extcfg_page(struct mps_softc *sc,
332 struct mps_ext_cfg_page_req *ext_page_req, void *buf)
334 MPI2_CONFIG_EXTENDED_PAGE_HEADER *reqhdr, *hdr;
335 struct mps_config_params params;
339 hdr = ¶ms.hdr.Ext;
340 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
341 params.page_address = le32toh(ext_page_req->page_address);
342 hdr->PageVersion = reqhdr->PageVersion;
343 hdr->PageNumber = reqhdr->PageNumber;
344 hdr->ExtPageType = reqhdr->ExtPageType;
345 hdr->ExtPageLength = reqhdr->ExtPageLength;
347 params.length = le32toh(ext_page_req->len);
348 params.callback = NULL;
350 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
351 mps_printf(sc, "mps_user_read_extcfg_page timed out\n");
355 ext_page_req->ioc_status = htole16(params.status);
360 mps_user_write_cfg_page(struct mps_softc *sc,
361 struct mps_cfg_page_req *page_req, void *buf)
363 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
364 struct mps_config_params params;
369 hdr = ¶ms.hdr.Struct;
370 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
371 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
372 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
373 mps_printf(sc, "page type 0x%x not changeable\n",
374 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
379 * There isn't any point in restoring stripped out attributes
380 * if you then mask them going down to issue the request.
383 hdr->PageVersion = reqhdr->PageVersion;
384 hdr->PageLength = reqhdr->PageLength;
385 hdr->PageNumber = reqhdr->PageNumber;
386 hdr->PageType = reqhdr->PageType;
387 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
388 params.page_address = le32toh(page_req->page_address);
390 params.length = le32toh(page_req->len);
391 params.callback = NULL;
393 if ((error = mps_write_config_page(sc, ¶ms)) != 0) {
394 mps_printf(sc, "mps_write_cfg_page timed out\n");
398 page_req->ioc_status = htole16(params.status);
403 mpi_init_sge(struct mps_command *cm, void *req, void *sge)
407 space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
408 off = (uintptr_t)sge - (uintptr_t)req;
410 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
411 req, sge, off, space));
414 cm->cm_sglsize = space - off;
418 * Prepare the mps_command for an IOC_FACTS request.
421 mpi_pre_ioc_facts(struct mps_command *cm, struct mps_usr_command *cmd)
423 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
424 MPI2_IOC_FACTS_REPLY *rpl;
426 if (cmd->req_len != sizeof *req)
428 if (cmd->rpl_len != sizeof *rpl)
437 * Prepare the mps_command for a PORT_FACTS request.
440 mpi_pre_port_facts(struct mps_command *cm, struct mps_usr_command *cmd)
442 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
443 MPI2_PORT_FACTS_REPLY *rpl;
445 if (cmd->req_len != sizeof *req)
447 if (cmd->rpl_len != sizeof *rpl)
456 * Prepare the mps_command for a FW_DOWNLOAD request.
459 mpi_pre_fw_download(struct mps_command *cm, struct mps_usr_command *cmd)
461 MPI2_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
462 MPI2_FW_DOWNLOAD_REPLY *rpl;
463 MPI2_FW_DOWNLOAD_TCSGE tc;
467 * This code assumes there is room in the request's SGL for
468 * the TransactionContext plus at least a SGL chain element.
470 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
472 if (cmd->req_len != sizeof *req)
474 if (cmd->rpl_len != sizeof *rpl)
480 error = copyin(cmd->buf, cm->cm_data, cmd->len);
484 mpi_init_sge(cm, req, &req->SGL);
485 bzero(&tc, sizeof tc);
488 * For now, the F/W image must be provided in a single request.
490 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
492 if (req->TotalImageSize != cmd->len)
496 * The value of the first two elements is specified in the
497 * Fusion-MPT Message Passing Interface document.
500 tc.DetailsLength = 12;
502 tc.ImageSize = cmd->len;
504 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
506 return (mps_push_sge(cm, &tc, sizeof tc, 0));
510 * Prepare the mps_command for a FW_UPLOAD request.
513 mpi_pre_fw_upload(struct mps_command *cm, struct mps_usr_command *cmd)
515 MPI2_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
516 MPI2_FW_UPLOAD_REPLY *rpl;
517 MPI2_FW_UPLOAD_TCSGE tc;
520 * This code assumes there is room in the request's SGL for
521 * the TransactionContext plus at least a SGL chain element.
523 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
525 if (cmd->req_len != sizeof *req)
527 if (cmd->rpl_len != sizeof *rpl)
530 mpi_init_sge(cm, req, &req->SGL);
532 /* Perhaps just asking what the size of the fw is? */
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 return (mps_push_sge(cm, &tc, sizeof tc, 0));
555 * Prepare the mps_command for a SATA_PASSTHROUGH request.
558 mpi_pre_sata_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
560 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
561 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
563 if (cmd->req_len != sizeof *req)
565 if (cmd->rpl_len != sizeof *rpl)
568 mpi_init_sge(cm, req, &req->SGL);
573 * Prepare the mps_command for a SMP_PASSTHROUGH request.
576 mpi_pre_smp_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
578 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
579 MPI2_SMP_PASSTHROUGH_REPLY *rpl;
581 if (cmd->req_len != sizeof *req)
583 if (cmd->rpl_len != sizeof *rpl)
586 mpi_init_sge(cm, req, &req->SGL);
591 * Prepare the mps_command for a CONFIG request.
594 mpi_pre_config(struct mps_command *cm, struct mps_usr_command *cmd)
596 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
597 MPI2_CONFIG_REPLY *rpl;
599 if (cmd->req_len != sizeof *req)
601 if (cmd->rpl_len != sizeof *rpl)
604 mpi_init_sge(cm, req, &req->PageBufferSGE);
609 * Prepare the mps_command for a SAS_IO_UNIT_CONTROL request.
612 mpi_pre_sas_io_unit_control(struct mps_command *cm,
613 struct mps_usr_command *cmd)
622 * A set of functions to prepare an mps_command for the various
623 * supported requests.
625 struct mps_user_func {
628 } mps_user_func_list[] = {
629 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
630 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
631 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
632 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
633 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
634 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
635 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
636 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
637 { 0xFF, NULL } /* list end */
641 mps_user_setup_request(struct mps_command *cm, struct mps_usr_command *cmd)
643 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
644 struct mps_user_func *f;
646 for (f = mps_user_func_list; f->f_pre != NULL; f++) {
647 if (hdr->Function == f->Function)
648 return (f->f_pre(cm, cmd));
654 mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd)
656 MPI2_REQUEST_HEADER *hdr;
657 MPI2_DEFAULT_REPLY *rpl;
659 struct mps_command *cm = NULL;
664 cm = mps_alloc_command(sc);
667 mps_printf(sc, "mps_user_command: no mps requests\n");
673 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
675 mps_dprint(sc, MPS_INFO, "mps_user_command: req %p %d rpl %p %d\n",
676 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len );
678 if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
680 goto RetFreeUnlocked;
682 err = copyin(cmd->req, hdr, cmd->req_len);
684 goto RetFreeUnlocked;
686 mps_dprint(sc, MPS_INFO, "mps_user_command: Function %02X "
687 "MsgFlags %02X\n", hdr->Function, hdr->MsgFlags );
689 err = mps_user_setup_request(cm, cmd);
691 mps_printf(sc, "mps_user_command: unsupported function 0x%X\n",
693 goto RetFreeUnlocked;
697 buf = kmalloc(cmd->len, M_MPSUSER, M_WAITOK|M_ZERO);
699 cm->cm_length = cmd->len;
705 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
706 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
709 err = mps_wait_command(sc, cm, 0);
712 mps_printf(sc, "%s: invalid request: error %d\n",
717 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
718 sz = rpl->MsgLength * 4;
720 if (sz > cmd->rpl_len) {
722 "mps_user_command: reply buffer too small %d required %d\n",
729 copyout(rpl, cmd->rpl, sz);
731 copyout(buf, cmd->buf, cmd->len);
732 mps_dprint(sc, MPS_INFO, "mps_user_command: reply size %d\n", sz );
737 mps_free_command(sc, cm);
741 kfree(buf, M_MPSUSER);
746 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
748 MPI2_REQUEST_HEADER *hdr, tmphdr;
749 MPI2_DEFAULT_REPLY *rpl;
750 struct mps_command *cm = NULL;
751 int err = 0, dir = 0, sz;
752 uint8_t function = 0;
756 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
757 * bit to denote that a passthru is being processed.
760 if (sc->mps_flags & MPS_FLAGS_BUSY) {
761 mps_dprint(sc, MPS_INFO, "%s: Only one passthru command "
762 "allowed at a single time.", __func__);
766 sc->mps_flags |= MPS_FLAGS_BUSY;
770 * Do some validation on data direction. Valid cases are:
771 * 1) DataSize is 0 and direction is NONE
772 * 2) DataSize is non-zero and one of:
773 * a) direction is READ or
774 * b) direction is WRITE or
775 * c) direction is BOTH and DataOutSize is non-zero
776 * If valid and the direction is BOTH, change the direction to READ.
777 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
779 if (((data->DataSize == 0) &&
780 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
781 ((data->DataSize != 0) &&
782 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
783 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
784 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
785 (data->DataOutSize != 0))))) {
786 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
787 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
789 data->DataOutSize = 0;
793 mps_dprint(sc, MPS_INFO, "%s: req 0x%jx %d rpl 0x%jx %d "
794 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
795 data->PtrRequest, data->RequestSize, data->PtrReply,
796 data->ReplySize, data->PtrData, data->DataSize,
797 data->PtrDataOut, data->DataOutSize, data->DataDirection);
800 * copy in the header so we know what we're dealing with before we
801 * commit to allocating a command for it.
803 err = copyin(PTRIN(data->PtrRequest), &tmphdr, data->RequestSize);
805 goto RetFreeUnlocked;
807 if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
809 goto RetFreeUnlocked;
812 function = tmphdr.Function;
813 mps_dprint(sc, MPS_INFO, "%s: Function %02X MsgFlags %02X\n", __func__,
814 function, tmphdr.MsgFlags);
817 * Handle a passthru TM request.
819 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
820 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
823 cm = mpssas_alloc_tm(sc);
829 /* Copy the header in. Only a small fixup is needed. */
830 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
831 bcopy(&tmphdr, task, data->RequestSize);
832 task->TaskMID = cm->cm_desc.Default.SMID;
835 cm->cm_desc.HighPriority.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
836 cm->cm_complete = NULL;
837 cm->cm_complete_data = NULL;
839 err = mps_wait_command(sc, cm, 0);
843 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
847 * Copy the reply data and sense data to user space.
849 if (cm->cm_reply != NULL) {
850 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
851 sz = rpl->MsgLength * 4;
853 if (sz > data->ReplySize) {
854 mps_printf(sc, "%s: reply buffer too small: %d, "
855 "required: %d\n", __func__, data->ReplySize, sz);
859 copyout(cm->cm_reply, PTRIN(data->PtrReply),
864 mpssas_free_tm(sc, cm);
869 cm = mps_alloc_command(sc);
872 mps_printf(sc, "%s: no mps requests\n", __func__);
878 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
879 bcopy(&tmphdr, hdr, data->RequestSize);
882 * Do some checking to make sure the IOCTL request contains a valid
883 * request. Then set the SGL info.
885 mpi_init_sge(cm, hdr, (void *)((uint8_t *)hdr + data->RequestSize));
888 * Set up for read, write or both. From check above, DataOutSize will
889 * be 0 if direction is READ or WRITE, but it will have some non-zero
890 * value if the direction is BOTH. So, just use the biggest size to get
891 * the cm_data buffer size. If direction is BOTH, 2 SGLs need to be set
892 * up; the first is for the request and the second will contain the
893 * response data. cm_out_len needs to be set here and this will be used
894 * when the SGLs are set up.
897 cm->cm_length = MAX(data->DataSize, data->DataOutSize);
898 cm->cm_out_len = data->DataOutSize;
900 if (cm->cm_length != 0) {
901 cm->cm_data = kmalloc(cm->cm_length, M_MPSUSER, M_WAITOK |
903 if (cm->cm_data == NULL) {
904 mps_dprint(sc, MPS_FAULT, "%s: alloc failed for IOCTL "
905 "passthru length %d\n", __func__, cm->cm_length);
907 cm->cm_flags = MPS_CM_FLAGS_DATAIN;
908 if (data->DataOutSize) {
909 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
910 err = copyin(PTRIN(data->PtrDataOut),
911 cm->cm_data, data->DataOutSize);
912 } else if (data->DataDirection ==
913 MPS_PASS_THRU_DIRECTION_WRITE) {
914 cm->cm_flags = MPS_CM_FLAGS_DATAOUT;
915 err = copyin(PTRIN(data->PtrData),
916 cm->cm_data, data->DataSize);
919 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
920 "IOCTL data from user space\n", __func__);
923 cm->cm_flags |= MPS_CM_FLAGS_SGE_SIMPLE;
924 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
927 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
928 * uses SCSI IO descriptor.
930 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
931 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
932 MPI2_SCSI_IO_REQUEST *scsi_io_req;
934 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
936 * Put SGE for data and data_out buffer at the end of
937 * scsi_io_request message header (64 bytes in total).
938 * Following above SGEs, the residual space will be used by
941 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
943 scsi_io_req->SenseBufferLowAddress = cm->cm_sense_busaddr;
946 * Set SGLOffset0 value. This is the number of dwords that SGL
947 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
949 scsi_io_req->SGLOffset0 = 24;
952 * Setup descriptor info. RAID passthrough must use the
953 * default request descriptor which is already set, so if this
954 * is a SCSI IO request, change the descriptor to SCSI IO.
955 * Also, if this is a SCSI IO request, handle the reply in the
956 * mpssas_scsio_complete function.
958 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
959 cm->cm_desc.SCSIIO.RequestFlags =
960 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
961 cm->cm_desc.SCSIIO.DevHandle = scsi_io_req->DevHandle;
964 * Make sure the DevHandle is not 0 because this is a
967 if (scsi_io_req->DevHandle == 0) {
969 goto RetFreeUnlocked;
976 err = mps_wait_command(sc, cm, 0);
979 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
982 goto RetFreeUnlocked;
986 * Sync the DMA data, if any. Then copy the data to user space.
988 if (cm->cm_data != NULL) {
989 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN)
990 dir = BUS_DMASYNC_POSTREAD;
991 else if (cm->cm_flags & MPS_CM_FLAGS_DATAOUT)
992 dir = BUS_DMASYNC_POSTWRITE;;
993 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
994 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
996 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN) {
998 err = copyout(cm->cm_data,
999 PTRIN(data->PtrData), data->DataSize);
1002 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1003 "IOCTL data to user space\n", __func__);
1008 * Copy the reply data and sense data to user space.
1010 if (cm->cm_reply != NULL) {
1011 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1012 sz = rpl->MsgLength * 4;
1014 if (sz > data->ReplySize) {
1015 mps_printf(sc, "%s: reply buffer too small: %d, "
1016 "required: %d\n", __func__, data->ReplySize, sz);
1020 copyout(cm->cm_reply, PTRIN(data->PtrReply),
1025 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1026 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1027 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1028 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1030 MIN(((MPI2_SCSI_IO_REPLY *)rpl)->SenseCount,
1031 sizeof(struct scsi_sense_data));
1033 copyout(cm->cm_sense, cm->cm_req + 64, sense_len);
1045 kfree(cm->cm_data, M_MPSUSER);
1046 mps_free_command(sc, cm);
1049 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1056 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1058 Mpi2ConfigReply_t mpi_reply;
1059 Mpi2BiosPage3_t config_page;
1062 * Use the PCI interface functions to get the Bus, Device, and Function
1065 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1066 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1067 data->PciInformation.u.bits.FunctionNumber =
1068 pci_get_function(sc->mps_dev);
1071 * Get the FW version that should already be saved in IOC Facts.
1073 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1076 * General device info.
1078 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1079 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1080 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1081 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1082 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1083 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1084 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1087 * Get the driver version.
1089 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1092 * Need to get BIOS Config Page 3 for the BIOS Version.
1094 data->BiosVersion = 0;
1095 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1096 kprintf("%s: Error while retrieving BIOS Version\n", __func__);
1098 data->BiosVersion = config_page.BiosVersion;
1102 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1107 * Use the PCI interface functions to get the Bus, Device, and Function
1110 data->BusNumber = pci_get_bus(sc->mps_dev);
1111 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1112 data->FunctionNumber = pci_get_function(sc->mps_dev);
1115 * Now get the interrupt vector and the pci header. The vector can
1116 * only be 0 right now. The header is the first 256 bytes of config
1119 data->InterruptVector = 0;
1120 for (i = 0; i < sizeof (data->PciHeader); i++) {
1121 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1126 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1130 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1131 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1136 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1140 mps_post_fw_diag_buffer(struct mps_softc *sc,
1141 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1143 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1144 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1145 struct mps_command *cm = NULL;
1149 * If buffer is not enabled, just leave.
1151 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1152 if (!pBuffer->enabled) {
1153 return (MPS_DIAG_FAILURE);
1157 * Clear some flags initially.
1159 pBuffer->force_release = FALSE;
1160 pBuffer->valid_data = FALSE;
1161 pBuffer->owned_by_firmware = FALSE;
1166 cm = mps_alloc_command(sc);
1168 mps_printf(sc, "%s: no mps requests\n", __func__);
1169 return (MPS_DIAG_FAILURE);
1173 * Build the request for releasing the FW Diag Buffer and send it.
1175 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1176 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1177 req->BufferType = pBuffer->buffer_type;
1178 req->ExtendedType = pBuffer->extended_type;
1179 req->BufferLength = pBuffer->size;
1180 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1181 req->ProductSpecific[i] = pBuffer->product_specific[i];
1182 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1185 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1186 cm->cm_complete_data = NULL;
1189 * Send command synchronously.
1191 status = mps_wait_command(sc, cm, 0);
1193 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1195 status = MPS_DIAG_FAILURE;
1200 * Process POST reply.
1202 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1203 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1204 status = MPS_DIAG_FAILURE;
1205 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1206 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1207 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1208 reply->IOCLogInfo, reply->TransferLength);
1213 * Post was successful.
1215 pBuffer->valid_data = TRUE;
1216 pBuffer->owned_by_firmware = TRUE;
1217 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1218 status = MPS_DIAG_SUCCESS;
1221 mps_free_command(sc, cm);
1226 mps_release_fw_diag_buffer(struct mps_softc *sc,
1227 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1230 MPI2_DIAG_RELEASE_REQUEST *req;
1231 MPI2_DIAG_RELEASE_REPLY *reply;
1232 struct mps_command *cm = NULL;
1236 * If buffer is not enabled, just leave.
1238 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1239 if (!pBuffer->enabled) {
1240 mps_dprint(sc, MPS_INFO, "%s: This buffer type is not supported "
1241 "by the IOC", __func__);
1242 return (MPS_DIAG_FAILURE);
1246 * Clear some flags initially.
1248 pBuffer->force_release = FALSE;
1249 pBuffer->valid_data = FALSE;
1250 pBuffer->owned_by_firmware = FALSE;
1255 cm = mps_alloc_command(sc);
1257 mps_printf(sc, "%s: no mps requests\n", __func__);
1258 return (MPS_DIAG_FAILURE);
1262 * Build the request for releasing the FW Diag Buffer and send it.
1264 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1265 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1266 req->BufferType = pBuffer->buffer_type;
1269 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1270 cm->cm_complete_data = NULL;
1273 * Send command synchronously.
1275 status = mps_wait_command(sc, cm, 0);
1277 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1279 status = MPS_DIAG_FAILURE;
1284 * Process RELEASE reply.
1286 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1287 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1288 pBuffer->owned_by_firmware) {
1289 status = MPS_DIAG_FAILURE;
1290 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1291 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1292 __func__, reply->IOCStatus, reply->IOCLogInfo);
1297 * Release was successful.
1299 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1300 status = MPS_DIAG_SUCCESS;
1303 * If this was for an UNREGISTER diag type command, clear the unique ID.
1305 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1306 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1314 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1315 uint32_t *return_code)
1317 mps_fw_diagnostic_buffer_t *pBuffer;
1318 uint8_t extended_type, buffer_type, i;
1319 uint32_t buffer_size;
1323 extended_type = diag_register->ExtendedType;
1324 buffer_type = diag_register->BufferType;
1325 buffer_size = diag_register->RequestedBufferSize;
1326 unique_id = diag_register->UniqueId;
1329 * Check for valid buffer type
1331 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1332 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1333 return (MPS_DIAG_FAILURE);
1337 * Get the current buffer and look up the unique ID. The unique ID
1338 * should not be found. If it is, the ID is already in use.
1340 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1341 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1342 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1343 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1344 return (MPS_DIAG_FAILURE);
1348 * The buffer's unique ID should not be registered yet, and the given
1349 * unique ID cannot be 0.
1351 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1352 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1353 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1354 return (MPS_DIAG_FAILURE);
1358 * If this buffer is already posted as immediate, just change owner.
1360 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1361 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1362 pBuffer->immediate = FALSE;
1363 pBuffer->unique_id = unique_id;
1364 return (MPS_DIAG_SUCCESS);
1368 * Post a new buffer after checking if it's enabled. The DMA buffer
1369 * that is allocated will be contiguous (nsegments = 1).
1371 if (!pBuffer->enabled) {
1372 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1373 return (MPS_DIAG_FAILURE);
1375 if (bus_dma_tag_create( sc->mps_parent_dmat, /* parent */
1376 1, 0, /* algnmnt, boundary */
1377 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1378 BUS_SPACE_MAXADDR, /* highaddr */
1379 NULL, NULL, /* filter, filterarg */
1380 buffer_size, /* maxsize */
1382 buffer_size, /* maxsegsize */
1384 &sc->fw_diag_dmat)) {
1385 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer DMA "
1389 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1390 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1391 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer "
1395 bzero(sc->fw_diag_buffer, buffer_size);
1396 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1397 buffer_size, mps_memaddr_cb, &sc->fw_diag_busaddr, 0);
1398 pBuffer->size = buffer_size;
1401 * Copy the given info to the diag buffer and post the buffer.
1403 pBuffer->buffer_type = buffer_type;
1404 pBuffer->immediate = FALSE;
1405 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1406 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1408 pBuffer->product_specific[i] =
1409 diag_register->ProductSpecific[i];
1412 pBuffer->extended_type = extended_type;
1413 pBuffer->unique_id = unique_id;
1414 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1417 * In case there was a failure, free the DMA buffer.
1419 if (status == MPS_DIAG_FAILURE) {
1420 if (sc->fw_diag_busaddr != 0)
1421 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1422 if (sc->fw_diag_buffer != NULL)
1423 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1425 if (sc->fw_diag_dmat != NULL)
1426 bus_dma_tag_destroy(sc->fw_diag_dmat);
1433 mps_diag_unregister(struct mps_softc *sc,
1434 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1436 mps_fw_diagnostic_buffer_t *pBuffer;
1441 unique_id = diag_unregister->UniqueId;
1444 * Get the current buffer and look up the unique ID. The unique ID
1447 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1448 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1449 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1450 return (MPS_DIAG_FAILURE);
1453 pBuffer = &sc->fw_diag_buffer_list[i];
1456 * Try to release the buffer from FW before freeing it. If release
1457 * fails, don't free the DMA buffer in case FW tries to access it
1458 * later. If buffer is not owned by firmware, can't release it.
1460 if (!pBuffer->owned_by_firmware) {
1461 status = MPS_DIAG_SUCCESS;
1463 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1464 MPS_FW_DIAG_TYPE_UNREGISTER);
1468 * At this point, return the current status no matter what happens with
1471 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1472 if (status == MPS_DIAG_SUCCESS) {
1473 if (sc->fw_diag_busaddr != 0)
1474 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1475 if (sc->fw_diag_buffer != NULL)
1476 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1478 if (sc->fw_diag_dmat != NULL)
1479 bus_dma_tag_destroy(sc->fw_diag_dmat);
1486 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1487 uint32_t *return_code)
1489 mps_fw_diagnostic_buffer_t *pBuffer;
1493 unique_id = diag_query->UniqueId;
1496 * If ID is valid, query on ID.
1497 * If ID is invalid, query on buffer type.
1499 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1500 i = diag_query->BufferType;
1501 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1502 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1503 return (MPS_DIAG_FAILURE);
1506 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1507 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1508 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1509 return (MPS_DIAG_FAILURE);
1514 * Fill query structure with the diag buffer info.
1516 pBuffer = &sc->fw_diag_buffer_list[i];
1517 diag_query->BufferType = pBuffer->buffer_type;
1518 diag_query->ExtendedType = pBuffer->extended_type;
1519 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1520 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1522 diag_query->ProductSpecific[i] =
1523 pBuffer->product_specific[i];
1526 diag_query->TotalBufferSize = pBuffer->size;
1527 diag_query->DriverAddedBufferSize = 0;
1528 diag_query->UniqueId = pBuffer->unique_id;
1529 diag_query->ApplicationFlags = 0;
1530 diag_query->DiagnosticFlags = 0;
1533 * Set/Clear application flags
1535 if (pBuffer->immediate) {
1536 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1538 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1540 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1541 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1543 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1545 if (pBuffer->owned_by_firmware) {
1546 diag_query->ApplicationFlags |=
1547 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1549 diag_query->ApplicationFlags &=
1550 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1553 return (MPS_DIAG_SUCCESS);
1557 mps_diag_read_buffer(struct mps_softc *sc,
1558 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1559 uint32_t *return_code)
1561 mps_fw_diagnostic_buffer_t *pBuffer;
1566 unique_id = diag_read_buffer->UniqueId;
1569 * Get the current buffer and look up the unique ID. The unique ID
1572 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1573 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1574 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1575 return (MPS_DIAG_FAILURE);
1578 pBuffer = &sc->fw_diag_buffer_list[i];
1581 * Make sure requested read is within limits
1583 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1585 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1586 return (MPS_DIAG_FAILURE);
1590 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1591 * buffer that was allocated is one contiguous buffer.
1593 pData = (uint8_t *)(sc->fw_diag_buffer +
1594 diag_read_buffer->StartingOffset);
1595 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1596 return (MPS_DIAG_FAILURE);
1597 diag_read_buffer->Status = 0;
1600 * Set or clear the Force Release flag.
1602 if (pBuffer->force_release) {
1603 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1605 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1609 * If buffer is to be reregistered, make sure it's not already owned by
1612 status = MPS_DIAG_SUCCESS;
1613 if (!pBuffer->owned_by_firmware) {
1614 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1615 status = mps_post_fw_diag_buffer(sc, pBuffer,
1624 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1625 uint32_t *return_code)
1627 mps_fw_diagnostic_buffer_t *pBuffer;
1632 unique_id = diag_release->UniqueId;
1635 * Get the current buffer and look up the unique ID. The unique ID
1638 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1639 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1640 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1641 return (MPS_DIAG_FAILURE);
1644 pBuffer = &sc->fw_diag_buffer_list[i];
1647 * If buffer is not owned by firmware, it's already been released.
1649 if (!pBuffer->owned_by_firmware) {
1650 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1651 return (MPS_DIAG_FAILURE);
1655 * Release the buffer.
1657 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1658 MPS_FW_DIAG_TYPE_RELEASE);
1663 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1664 uint32_t length, uint32_t *return_code)
1666 mps_fw_diag_register_t diag_register;
1667 mps_fw_diag_unregister_t diag_unregister;
1668 mps_fw_diag_query_t diag_query;
1669 mps_diag_read_buffer_t diag_read_buffer;
1670 mps_fw_diag_release_t diag_release;
1671 int status = MPS_DIAG_SUCCESS;
1672 uint32_t original_return_code;
1674 original_return_code = *return_code;
1675 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1678 case MPS_FW_DIAG_TYPE_REGISTER:
1681 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1682 status = MPS_DIAG_FAILURE;
1685 if (copyin(diag_action, &diag_register,
1686 sizeof(diag_register)) != 0)
1687 return (MPS_DIAG_FAILURE);
1688 status = mps_diag_register(sc, &diag_register,
1692 case MPS_FW_DIAG_TYPE_UNREGISTER:
1693 if (length < sizeof(diag_unregister)) {
1695 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1696 status = MPS_DIAG_FAILURE;
1699 if (copyin(diag_action, &diag_unregister,
1700 sizeof(diag_unregister)) != 0)
1701 return (MPS_DIAG_FAILURE);
1702 status = mps_diag_unregister(sc, &diag_unregister,
1706 case MPS_FW_DIAG_TYPE_QUERY:
1707 if (length < sizeof (diag_query)) {
1709 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1710 status = MPS_DIAG_FAILURE;
1713 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1715 return (MPS_DIAG_FAILURE);
1716 status = mps_diag_query(sc, &diag_query, return_code);
1717 if (status == MPS_DIAG_SUCCESS)
1718 if (copyout(&diag_query, diag_action,
1719 sizeof (diag_query)) != 0)
1720 return (MPS_DIAG_FAILURE);
1723 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1724 if (copyin(diag_action, &diag_read_buffer,
1725 sizeof(diag_read_buffer)) != 0)
1726 return (MPS_DIAG_FAILURE);
1727 if (length < diag_read_buffer.BytesToRead) {
1729 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1730 status = MPS_DIAG_FAILURE;
1733 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1734 PTRIN(diag_read_buffer.PtrDataBuffer),
1736 if (status == MPS_DIAG_SUCCESS) {
1737 if (copyout(&diag_read_buffer, diag_action,
1738 sizeof(diag_read_buffer) -
1739 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1741 return (MPS_DIAG_FAILURE);
1745 case MPS_FW_DIAG_TYPE_RELEASE:
1746 if (length < sizeof(diag_release)) {
1748 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1749 status = MPS_DIAG_FAILURE;
1752 if (copyin(diag_action, &diag_release,
1753 sizeof(diag_release)) != 0)
1754 return (MPS_DIAG_FAILURE);
1755 status = mps_diag_release(sc, &diag_release,
1760 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1761 status = MPS_DIAG_FAILURE;
1765 if ((status == MPS_DIAG_FAILURE) &&
1766 (original_return_code == MPS_FW_DIAG_NEW) &&
1767 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1768 status = MPS_DIAG_SUCCESS;
1774 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1779 * Only allow one diag action at one time.
1781 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1782 mps_dprint(sc, MPS_INFO, "%s: Only one FW diag command "
1783 "allowed at a single time.", __func__);
1786 sc->mps_flags |= MPS_FLAGS_BUSY;
1789 * Send diag action request
1791 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1792 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1793 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1794 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1795 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1796 status = mps_do_diag_action(sc, data->Action,
1797 PTRIN(data->PtrDiagAction), data->Length,
1802 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1807 * Copy the event recording mask and the event queue size out. For
1808 * clarification, the event recording mask (events_to_record) is not the same
1809 * thing as the event mask (event_mask). events_to_record has a bit set for
1810 * every event type that is to be recorded by the driver, and event_mask has a
1811 * bit cleared for every event that is allowed into the driver from the IOC.
1812 * They really have nothing to do with each other.
1815 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1820 data->Entries = MPS_EVENT_QUEUE_SIZE;
1822 for (i = 0; i < 4; i++) {
1823 data->Types[i] = sc->events_to_record[i];
1829 * Set the driver's event mask according to what's been given. See
1830 * mps_user_event_query for explanation of the event recording mask and the IOC
1831 * event mask. It's the app's responsibility to enable event logging by setting
1832 * the bits in events_to_record. Initially, no events will be logged.
1835 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1840 for (i = 0; i < 4; i++) {
1841 sc->events_to_record[i] = data->Types[i];
1847 * Copy out the events that have been recorded, up to the max events allowed.
1850 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1857 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1859 if (copyout((void *)sc->recorded_events,
1860 PTRIN(data->PtrEvents), size) != 0)
1865 * data->Size value is not large enough to copy event data.
1871 * Change size value to match the number of bytes that were copied.
1874 data->Size = sizeof(sc->recorded_events);
1881 * Record events into the driver from the IOC if they are not masked.
1884 mpssas_record_event(struct mps_softc *sc,
1885 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1889 uint16_t event_data_len;
1890 boolean_t sendAEN = FALSE;
1892 event = event_reply->Event;
1895 * Generate a system event to let anyone who cares know that a
1896 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1897 * event mask is set to.
1899 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1904 * Record the event only if its corresponding bit is set in
1905 * events_to_record. event_index is the index into recorded_events and
1906 * event_number is the overall number of an event being recorded since
1907 * start-of-day. event_index will roll over; event_number will never
1910 i = (uint8_t)(event / 32);
1911 j = (uint8_t)(event % 32);
1912 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1913 i = sc->event_index;
1914 sc->recorded_events[i].Type = event;
1915 sc->recorded_events[i].Number = ++sc->event_number;
1916 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
1918 event_data_len = event_reply->EventDataLength;
1920 if (event_data_len > 0) {
1922 * Limit data to size in m_event entry
1924 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
1925 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
1927 for (j = 0; j < event_data_len; j++) {
1928 sc->recorded_events[i].Data[j] =
1929 event_reply->EventData[j];
1933 * check for index wrap-around
1935 if (++i == MPS_EVENT_QUEUE_SIZE) {
1938 sc->event_index = (uint8_t)i;
1941 * Set flag to send the event.
1948 * Generate a system event if flag is set to let anyone who cares know
1949 * that an event has occurred.
1952 //SLM-how to send a system event (see kqueue, kevent)
1953 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
1954 // "SAS", NULL, NULL, DDI_NOSLEEP);
1959 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
1963 switch (data->Command) {
1965 * IO access is not supported.
1969 mps_dprint(sc, MPS_INFO, "IO access is not supported. "
1970 "Use memory access.");
1975 data->RegData = mps_regread(sc, data->RegOffset);
1979 mps_regwrite(sc, data->RegOffset, data->RegData);
1991 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
1993 uint8_t bt2dh = FALSE;
1994 uint8_t dh2bt = FALSE;
1995 uint16_t dev_handle, bus, target;
1998 target = data->TargetID;
1999 dev_handle = data->DevHandle;
2002 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2003 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2004 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2007 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2009 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2011 if (!dh2bt && !bt2dh)
2015 * Only handle bus of 0. Make sure target is within range.
2021 if (target > sc->max_devices) {
2022 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2023 "for Bus/Target to DevHandle mapping.");
2026 dev_handle = sc->mapping_table[target].dev_handle;
2028 data->DevHandle = dev_handle;
2031 target = mps_mapping_get_sas_id_from_handle(sc, dev_handle);
2033 data->TargetID = target;
2040 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag)
2042 struct mps_softc *sc;
2043 struct mps_cfg_page_req *page_req;
2044 struct mps_ext_cfg_page_req *ext_page_req;
2046 int error, reset_loop;
2054 case MPSIO_READ_CFG_HEADER:
2056 error = mps_user_read_cfg_header(sc, page_req);
2059 case MPSIO_READ_CFG_PAGE:
2060 mps_page = kmalloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2061 error = copyin(page_req->buf, mps_page,
2062 sizeof(MPI2_CONFIG_PAGE_HEADER));
2066 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2070 error = copyout(mps_page, page_req->buf, page_req->len);
2072 case MPSIO_READ_EXT_CFG_HEADER:
2074 error = mps_user_read_extcfg_header(sc, ext_page_req);
2077 case MPSIO_READ_EXT_CFG_PAGE:
2078 mps_page = kmalloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2079 error = copyin(ext_page_req->buf, mps_page,
2080 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2084 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2088 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2090 case MPSIO_WRITE_CFG_PAGE:
2091 mps_page = kmalloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2092 error = copyin(page_req->buf, mps_page, page_req->len);
2096 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2099 case MPSIO_MPS_COMMAND:
2100 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2102 case MPTIOCTL_PASS_THRU:
2104 * The user has requested to pass through a command to be
2105 * executed by the MPT firmware. Call our routine which does
2106 * this. Only allow one passthru IOCTL at one time.
2108 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2110 case MPTIOCTL_GET_ADAPTER_DATA:
2112 * The user has requested to read adapter data. Call our
2113 * routine which does this.
2116 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2118 case MPTIOCTL_GET_PCI_INFO:
2120 * The user has requested to read pci info. Call
2121 * our routine which does this.
2125 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2128 case MPTIOCTL_RESET_ADAPTER:
2130 sc->port_enable_complete = 0;
2131 error = mps_reinit(sc);
2134 * Wait no more than 5 minutes for Port Enable to complete
2136 for (reset_loop = 0; (reset_loop < MPS_DIAG_RESET_TIMEOUT) &&
2137 (!sc->port_enable_complete); reset_loop++) {
2140 if (reset_loop == MPS_DIAG_RESET_TIMEOUT) {
2141 kprintf("Port Enable did not complete after Diag "
2145 case MPTIOCTL_DIAG_ACTION:
2147 * The user has done a diag buffer action. Call our routine
2148 * which does this. Only allow one diag action at one time.
2151 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2154 case MPTIOCTL_EVENT_QUERY:
2156 * The user has done an event query. Call our routine which does
2160 mps_user_event_query(sc, (mps_event_query_t *)arg);
2162 case MPTIOCTL_EVENT_ENABLE:
2164 * The user has done an event enable. Call our routine which
2168 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2170 case MPTIOCTL_EVENT_REPORT:
2172 * The user has done an event report. Call our routine which
2175 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2177 case MPTIOCTL_REG_ACCESS:
2179 * The user has requested register access. Call our routine
2183 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2186 case MPTIOCTL_BTDH_MAPPING:
2188 * The user has requested to translate a bus/target to a
2189 * DevHandle or a DevHandle to a bus/target. Call our routine
2192 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2199 if (mps_page != NULL)
2200 kfree(mps_page, M_MPSUSER);
2205 #ifdef COMPAT_FREEBSD32
2207 struct mps_cfg_page_req32 {
2208 MPI2_CONFIG_PAGE_HEADER header;
2209 uint32_t page_address;
2212 uint16_t ioc_status;
2215 struct mps_ext_cfg_page_req32 {
2216 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2217 uint32_t page_address;
2220 uint16_t ioc_status;
2223 struct mps_raid_action32 {
2227 uint8_t phys_disk_num;
2228 uint32_t action_data_word;
2231 uint32_t volume_status;
2232 uint32_t action_data[4];
2233 uint16_t action_status;
2234 uint16_t ioc_status;
2238 struct mps_usr_command32 {
2248 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2249 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2250 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2251 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2252 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2253 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2254 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2257 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2260 struct mps_cfg_page_req32 *page32 = _arg;
2261 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2262 struct mps_raid_action32 *raid32 = _arg;
2263 struct mps_usr_command32 *user32 = _arg;
2265 struct mps_cfg_page_req page;
2266 struct mps_ext_cfg_page_req ext;
2267 struct mps_raid_action raid;
2268 struct mps_usr_command user;
2274 case MPSIO_READ_CFG_HEADER32:
2275 case MPSIO_READ_CFG_PAGE32:
2276 case MPSIO_WRITE_CFG_PAGE32:
2277 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2278 cmd = MPSIO_READ_CFG_HEADER;
2279 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2280 cmd = MPSIO_READ_CFG_PAGE;
2282 cmd = MPSIO_WRITE_CFG_PAGE;
2283 CP(*page32, arg.page, header);
2284 CP(*page32, arg.page, page_address);
2285 PTRIN_CP(*page32, arg.page, buf);
2286 CP(*page32, arg.page, len);
2287 CP(*page32, arg.page, ioc_status);
2290 case MPSIO_READ_EXT_CFG_HEADER32:
2291 case MPSIO_READ_EXT_CFG_PAGE32:
2292 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2293 cmd = MPSIO_READ_EXT_CFG_HEADER;
2295 cmd = MPSIO_READ_EXT_CFG_PAGE;
2296 CP(*ext32, arg.ext, header);
2297 CP(*ext32, arg.ext, page_address);
2298 PTRIN_CP(*ext32, arg.ext, buf);
2299 CP(*ext32, arg.ext, len);
2300 CP(*ext32, arg.ext, ioc_status);
2303 case MPSIO_RAID_ACTION32:
2304 cmd = MPSIO_RAID_ACTION;
2305 CP(*raid32, arg.raid, action);
2306 CP(*raid32, arg.raid, volume_bus);
2307 CP(*raid32, arg.raid, volume_id);
2308 CP(*raid32, arg.raid, phys_disk_num);
2309 CP(*raid32, arg.raid, action_data_word);
2310 PTRIN_CP(*raid32, arg.raid, buf);
2311 CP(*raid32, arg.raid, len);
2312 CP(*raid32, arg.raid, volume_status);
2313 bcopy(raid32->action_data, arg.raid.action_data,
2314 sizeof arg.raid.action_data);
2315 CP(*raid32, arg.raid, ioc_status);
2316 CP(*raid32, arg.raid, write);
2319 case MPSIO_MPS_COMMAND32:
2320 cmd = MPSIO_MPS_COMMAND;
2321 PTRIN_CP(*user32, arg.user, req);
2322 CP(*user32, arg.user, req_len);
2323 PTRIN_CP(*user32, arg.user, rpl);
2324 CP(*user32, arg.user, rpl_len);
2325 PTRIN_CP(*user32, arg.user, buf);
2326 CP(*user32, arg.user, len);
2327 CP(*user32, arg.user, flags);
2333 error = mps_ioctl(dev, cmd, &arg, flag, td);
2334 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2336 case MPSIO_READ_CFG_HEADER32:
2337 case MPSIO_READ_CFG_PAGE32:
2338 case MPSIO_WRITE_CFG_PAGE32:
2339 CP(arg.page, *page32, header);
2340 CP(arg.page, *page32, page_address);
2341 PTROUT_CP(arg.page, *page32, buf);
2342 CP(arg.page, *page32, len);
2343 CP(arg.page, *page32, ioc_status);
2346 case MPSIO_READ_EXT_CFG_HEADER32:
2347 case MPSIO_READ_EXT_CFG_PAGE32:
2348 CP(arg.ext, *ext32, header);
2349 CP(arg.ext, *ext32, page_address);
2350 PTROUT_CP(arg.ext, *ext32, buf);
2351 CP(arg.ext, *ext32, len);
2352 CP(arg.ext, *ext32, ioc_status);
2355 case MPSIO_RAID_ACTION32:
2356 CP(arg.raid, *raid32, action);
2357 CP(arg.raid, *raid32, volume_bus);
2358 CP(arg.raid, *raid32, volume_id);
2359 CP(arg.raid, *raid32, phys_disk_num);
2360 CP(arg.raid, *raid32, action_data_word);
2361 PTROUT_CP(arg.raid, *raid32, buf);
2362 CP(arg.raid, *raid32, len);
2363 CP(arg.raid, *raid32, volume_status);
2364 bcopy(arg.raid.action_data, raid32->action_data,
2365 sizeof arg.raid.action_data);
2366 CP(arg.raid, *raid32, ioc_status);
2367 CP(arg.raid, *raid32, write);
2370 case MPSIO_MPS_COMMAND32:
2371 PTROUT_CP(arg.user, *user32, req);
2372 CP(arg.user, *user32, req_len);
2373 PTROUT_CP(arg.user, *user32, rpl);
2374 CP(arg.user, *user32, rpl_len);
2375 PTROUT_CP(arg.user, *user32, buf);
2376 CP(arg.user, *user32, len);
2377 CP(arg.user, *user32, flags);
2384 #endif /* COMPAT_FREEBSD32 */
2387 mps_ioctl_devsw(struct dev_ioctl_args *ap)
2389 cdev_t dev = ap->a_head.a_dev;
2390 u_long com = ap->a_cmd;
2391 caddr_t arg = ap->a_data;
2392 int flag = ap->a_fflag;
2394 #ifdef COMPAT_FREEBSD32
2395 if (SV_CURPROC_FLAG(SV_ILP32))
2396 return (mps_ioctl32(dev, com, arg, flag, td));
2398 return (mps_ioctl(dev, com, arg, flag));