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
62 #include <sys/cdefs.h>
63 __FBSDID("$FreeBSD$");
65 #include "opt_compat.h"
67 /* TODO Move headers to mpsvar */
68 #include <sys/types.h>
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/kernel.h>
72 #include <sys/selinfo.h>
73 #include <sys/module.h>
77 #include <sys/malloc.h>
79 #include <sys/sysctl.h>
80 #include <sys/ioccom.h>
81 #include <sys/endian.h>
82 #include <sys/queue.h>
83 #include <sys/kthread.h>
84 #include <sys/taskqueue.h>
86 #include <sys/sysent.h>
88 #include <machine/bus.h>
89 #include <machine/resource.h>
93 #include <cam/scsi/scsi_all.h>
95 #include <dev/mps/mpi/mpi2_type.h>
96 #include <dev/mps/mpi/mpi2.h>
97 #include <dev/mps/mpi/mpi2_ioc.h>
98 #include <dev/mps/mpi/mpi2_cnfg.h>
99 #include <dev/mps/mpi/mpi2_init.h>
100 #include <dev/mps/mpi/mpi2_tool.h>
101 #include <dev/mps/mps_ioctl.h>
102 #include <dev/mps/mpsvar.h>
103 #include <dev/mps/mps_table.h>
104 #include <dev/mps/mps_sas.h>
105 #include <dev/pci/pcivar.h>
106 #include <dev/pci/pcireg.h>
108 static d_open_t mps_open;
109 static d_close_t mps_close;
110 static d_ioctl_t mps_ioctl_devsw;
112 static struct cdevsw mps_cdevsw = {
113 .d_version = D_VERSION,
116 .d_close = mps_close,
117 .d_ioctl = mps_ioctl_devsw,
121 typedef int (mps_user_f)(struct mps_command *, struct mps_usr_command *);
122 static mps_user_f mpi_pre_ioc_facts;
123 static mps_user_f mpi_pre_port_facts;
124 static mps_user_f mpi_pre_fw_download;
125 static mps_user_f mpi_pre_fw_upload;
126 static mps_user_f mpi_pre_sata_passthrough;
127 static mps_user_f mpi_pre_smp_passthrough;
128 static mps_user_f mpi_pre_config;
129 static mps_user_f mpi_pre_sas_io_unit_control;
131 static int mps_user_read_cfg_header(struct mps_softc *,
132 struct mps_cfg_page_req *);
133 static int mps_user_read_cfg_page(struct mps_softc *,
134 struct mps_cfg_page_req *, void *);
135 static int mps_user_read_extcfg_header(struct mps_softc *,
136 struct mps_ext_cfg_page_req *);
137 static int mps_user_read_extcfg_page(struct mps_softc *,
138 struct mps_ext_cfg_page_req *, void *);
139 static int mps_user_write_cfg_page(struct mps_softc *,
140 struct mps_cfg_page_req *, void *);
141 static int mps_user_setup_request(struct mps_command *,
142 struct mps_usr_command *);
143 static int mps_user_command(struct mps_softc *, struct mps_usr_command *);
145 static int mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data);
146 static void mps_user_get_adapter_data(struct mps_softc *sc,
147 mps_adapter_data_t *data);
148 static void mps_user_read_pci_info(struct mps_softc *sc,
149 mps_pci_info_t *data);
150 static uint8_t mps_get_fw_diag_buffer_number(struct mps_softc *sc,
152 static int mps_post_fw_diag_buffer(struct mps_softc *sc,
153 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code);
154 static int mps_release_fw_diag_buffer(struct mps_softc *sc,
155 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
157 static int mps_diag_register(struct mps_softc *sc,
158 mps_fw_diag_register_t *diag_register, uint32_t *return_code);
159 static int mps_diag_unregister(struct mps_softc *sc,
160 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code);
161 static int mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
162 uint32_t *return_code);
163 static int mps_diag_read_buffer(struct mps_softc *sc,
164 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
165 uint32_t *return_code);
166 static int mps_diag_release(struct mps_softc *sc,
167 mps_fw_diag_release_t *diag_release, uint32_t *return_code);
168 static int mps_do_diag_action(struct mps_softc *sc, uint32_t action,
169 uint8_t *diag_action, uint32_t length, uint32_t *return_code);
170 static int mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data);
171 static void mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data);
172 static void mps_user_event_enable(struct mps_softc *sc,
173 mps_event_enable_t *data);
174 static int mps_user_event_report(struct mps_softc *sc,
175 mps_event_report_t *data);
176 static int mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data);
177 static int mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data);
179 static MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
181 /* Macros from compat/freebsd32/freebsd32.h */
182 #define PTRIN(v) (void *)(uintptr_t)(v)
183 #define PTROUT(v) (uint32_t)(uintptr_t)(v)
185 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
186 #define PTRIN_CP(src,dst,fld) \
187 do { (dst).fld = PTRIN((src).fld); } while (0)
188 #define PTROUT_CP(src,dst,fld) \
189 do { (dst).fld = PTROUT((src).fld); } while (0)
192 mps_attach_user(struct mps_softc *sc)
196 unit = device_get_unit(sc->mps_dev);
197 sc->mps_cdev = make_dev(&mps_cdevsw, unit, UID_ROOT, GID_OPERATOR, 0640,
199 if (sc->mps_cdev == NULL) {
202 sc->mps_cdev->si_drv1 = sc;
207 mps_detach_user(struct mps_softc *sc)
210 /* XXX: do a purge of pending requests? */
211 destroy_dev(sc->mps_cdev);
216 mps_open(struct cdev *dev, int flags, int fmt, struct thread *td)
223 mps_close(struct cdev *dev, int flags, int fmt, struct thread *td)
230 mps_user_read_cfg_header(struct mps_softc *sc,
231 struct mps_cfg_page_req *page_req)
233 MPI2_CONFIG_PAGE_HEADER *hdr;
234 struct mps_config_params params;
237 hdr = ¶ms.hdr.Struct;
238 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
239 params.page_address = le32toh(page_req->page_address);
240 hdr->PageVersion = 0;
242 hdr->PageNumber = page_req->header.PageNumber;
243 hdr->PageType = page_req->header.PageType;
244 params.buffer = NULL;
246 params.callback = NULL;
248 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
250 * Leave the request. Without resetting the chip, it's
251 * still owned by it and we'll just get into trouble
252 * freeing it now. Mark it as abandoned so that if it
253 * shows up later it can be freed.
255 mps_printf(sc, "read_cfg_header timed out\n");
259 page_req->ioc_status = htole16(params.status);
260 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
261 MPI2_IOCSTATUS_SUCCESS) {
262 bcopy(hdr, &page_req->header, sizeof(page_req->header));
269 mps_user_read_cfg_page(struct mps_softc *sc, struct mps_cfg_page_req *page_req,
272 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
273 struct mps_config_params params;
277 hdr = ¶ms.hdr.Struct;
278 hdr->PageVersion = reqhdr->PageVersion;
279 hdr->PageLength = reqhdr->PageLength;
280 hdr->PageNumber = reqhdr->PageNumber;
281 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
282 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
283 params.page_address = le32toh(page_req->page_address);
285 params.length = le32toh(page_req->len);
286 params.callback = NULL;
288 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
289 mps_printf(sc, "mps_user_read_cfg_page timed out\n");
293 page_req->ioc_status = htole16(params.status);
298 mps_user_read_extcfg_header(struct mps_softc *sc,
299 struct mps_ext_cfg_page_req *ext_page_req)
301 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
302 struct mps_config_params params;
305 hdr = ¶ms.hdr.Ext;
306 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
307 hdr->PageVersion = ext_page_req->header.PageVersion;
308 hdr->ExtPageLength = 0;
309 hdr->PageNumber = ext_page_req->header.PageNumber;
310 hdr->ExtPageType = ext_page_req->header.ExtPageType;
311 params.page_address = le32toh(ext_page_req->page_address);
312 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
314 * Leave the request. Without resetting the chip, it's
315 * still owned by it and we'll just get into trouble
316 * freeing it now. Mark it as abandoned so that if it
317 * shows up later it can be freed.
319 mps_printf(sc, "mps_user_read_extcfg_header timed out\n");
323 ext_page_req->ioc_status = htole16(params.status);
324 if ((ext_page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
325 MPI2_IOCSTATUS_SUCCESS) {
326 ext_page_req->header.PageVersion = hdr->PageVersion;
327 ext_page_req->header.PageNumber = hdr->PageNumber;
328 ext_page_req->header.PageType = hdr->PageType;
329 ext_page_req->header.ExtPageLength = hdr->ExtPageLength;
330 ext_page_req->header.ExtPageType = hdr->ExtPageType;
337 mps_user_read_extcfg_page(struct mps_softc *sc,
338 struct mps_ext_cfg_page_req *ext_page_req, void *buf)
340 MPI2_CONFIG_EXTENDED_PAGE_HEADER *reqhdr, *hdr;
341 struct mps_config_params params;
345 hdr = ¶ms.hdr.Ext;
346 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
347 params.page_address = le32toh(ext_page_req->page_address);
348 hdr->PageVersion = reqhdr->PageVersion;
349 hdr->PageNumber = reqhdr->PageNumber;
350 hdr->ExtPageType = reqhdr->ExtPageType;
351 hdr->ExtPageLength = reqhdr->ExtPageLength;
353 params.length = le32toh(ext_page_req->len);
354 params.callback = NULL;
356 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
357 mps_printf(sc, "mps_user_read_extcfg_page timed out\n");
361 ext_page_req->ioc_status = htole16(params.status);
366 mps_user_write_cfg_page(struct mps_softc *sc,
367 struct mps_cfg_page_req *page_req, void *buf)
369 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
370 struct mps_config_params params;
375 hdr = ¶ms.hdr.Struct;
376 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
377 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
378 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
379 mps_printf(sc, "page type 0x%x not changeable\n",
380 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
385 * There isn't any point in restoring stripped out attributes
386 * if you then mask them going down to issue the request.
389 hdr->PageVersion = reqhdr->PageVersion;
390 hdr->PageLength = reqhdr->PageLength;
391 hdr->PageNumber = reqhdr->PageNumber;
392 hdr->PageType = reqhdr->PageType;
393 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
394 params.page_address = le32toh(page_req->page_address);
396 params.length = le32toh(page_req->len);
397 params.callback = NULL;
399 if ((error = mps_write_config_page(sc, ¶ms)) != 0) {
400 mps_printf(sc, "mps_write_cfg_page timed out\n");
404 page_req->ioc_status = htole16(params.status);
409 mpi_init_sge(struct mps_command *cm, void *req, void *sge)
413 space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
414 off = (uintptr_t)sge - (uintptr_t)req;
416 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
417 req, sge, off, space));
420 cm->cm_sglsize = space - off;
424 * Prepare the mps_command for an IOC_FACTS request.
427 mpi_pre_ioc_facts(struct mps_command *cm, struct mps_usr_command *cmd)
429 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
430 MPI2_IOC_FACTS_REPLY *rpl;
432 if (cmd->req_len != sizeof *req)
434 if (cmd->rpl_len != sizeof *rpl)
443 * Prepare the mps_command for a PORT_FACTS request.
446 mpi_pre_port_facts(struct mps_command *cm, struct mps_usr_command *cmd)
448 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
449 MPI2_PORT_FACTS_REPLY *rpl;
451 if (cmd->req_len != sizeof *req)
453 if (cmd->rpl_len != sizeof *rpl)
462 * Prepare the mps_command for a FW_DOWNLOAD request.
465 mpi_pre_fw_download(struct mps_command *cm, struct mps_usr_command *cmd)
467 MPI2_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
468 MPI2_FW_DOWNLOAD_REPLY *rpl;
469 MPI2_FW_DOWNLOAD_TCSGE tc;
473 * This code assumes there is room in the request's SGL for
474 * the TransactionContext plus at least a SGL chain element.
476 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
478 if (cmd->req_len != sizeof *req)
480 if (cmd->rpl_len != sizeof *rpl)
486 error = copyin(cmd->buf, cm->cm_data, cmd->len);
490 mpi_init_sge(cm, req, &req->SGL);
491 bzero(&tc, sizeof tc);
494 * For now, the F/W image must be provided in a single request.
496 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
498 if (req->TotalImageSize != cmd->len)
502 * The value of the first two elements is specified in the
503 * Fusion-MPT Message Passing Interface document.
506 tc.DetailsLength = 12;
508 tc.ImageSize = cmd->len;
510 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
512 return (mps_push_sge(cm, &tc, sizeof tc, 0));
516 * Prepare the mps_command for a FW_UPLOAD request.
519 mpi_pre_fw_upload(struct mps_command *cm, struct mps_usr_command *cmd)
521 MPI2_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
522 MPI2_FW_UPLOAD_REPLY *rpl;
523 MPI2_FW_UPLOAD_TCSGE tc;
526 * This code assumes there is room in the request's SGL for
527 * the TransactionContext plus at least a SGL chain element.
529 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
531 if (cmd->req_len != sizeof *req)
533 if (cmd->rpl_len != sizeof *rpl)
536 mpi_init_sge(cm, req, &req->SGL);
538 /* Perhaps just asking what the size of the fw is? */
542 bzero(&tc, sizeof tc);
545 * The value of the first two elements is specified in the
546 * Fusion-MPT Message Passing Interface document.
549 tc.DetailsLength = 12;
551 * XXX Is there any reason to fetch a partial image? I.e. to
552 * set ImageOffset to something other than 0?
555 tc.ImageSize = cmd->len;
557 return (mps_push_sge(cm, &tc, sizeof tc, 0));
561 * Prepare the mps_command for a SATA_PASSTHROUGH request.
564 mpi_pre_sata_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
566 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
567 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
569 if (cmd->req_len != sizeof *req)
571 if (cmd->rpl_len != sizeof *rpl)
574 mpi_init_sge(cm, req, &req->SGL);
579 * Prepare the mps_command for a SMP_PASSTHROUGH request.
582 mpi_pre_smp_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
584 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
585 MPI2_SMP_PASSTHROUGH_REPLY *rpl;
587 if (cmd->req_len != sizeof *req)
589 if (cmd->rpl_len != sizeof *rpl)
592 mpi_init_sge(cm, req, &req->SGL);
597 * Prepare the mps_command for a CONFIG request.
600 mpi_pre_config(struct mps_command *cm, struct mps_usr_command *cmd)
602 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
603 MPI2_CONFIG_REPLY *rpl;
605 if (cmd->req_len != sizeof *req)
607 if (cmd->rpl_len != sizeof *rpl)
610 mpi_init_sge(cm, req, &req->PageBufferSGE);
615 * Prepare the mps_command for a SAS_IO_UNIT_CONTROL request.
618 mpi_pre_sas_io_unit_control(struct mps_command *cm,
619 struct mps_usr_command *cmd)
628 * A set of functions to prepare an mps_command for the various
629 * supported requests.
631 struct mps_user_func {
634 } mps_user_func_list[] = {
635 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
636 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
637 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
638 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
639 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
640 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
641 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
642 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
643 { 0xFF, NULL } /* list end */
647 mps_user_setup_request(struct mps_command *cm, struct mps_usr_command *cmd)
649 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
650 struct mps_user_func *f;
652 for (f = mps_user_func_list; f->f_pre != NULL; f++) {
653 if (hdr->Function == f->Function)
654 return (f->f_pre(cm, cmd));
660 mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd)
662 MPI2_REQUEST_HEADER *hdr;
663 MPI2_DEFAULT_REPLY *rpl;
665 struct mps_command *cm = NULL;
670 cm = mps_alloc_command(sc);
673 mps_printf(sc, "mps_user_command: no mps requests\n");
679 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
681 mps_dprint(sc, MPS_INFO, "mps_user_command: req %p %d rpl %p %d\n",
682 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len );
684 if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
686 goto RetFreeUnlocked;
688 err = copyin(cmd->req, hdr, cmd->req_len);
690 goto RetFreeUnlocked;
692 mps_dprint(sc, MPS_INFO, "mps_user_command: Function %02X "
693 "MsgFlags %02X\n", hdr->Function, hdr->MsgFlags );
695 err = mps_user_setup_request(cm, cmd);
697 mps_printf(sc, "mps_user_command: unsupported function 0x%X\n",
699 goto RetFreeUnlocked;
703 buf = malloc(cmd->len, M_MPSUSER, M_WAITOK|M_ZERO);
705 cm->cm_length = cmd->len;
711 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
712 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
715 err = mps_wait_command(sc, cm, 30);
718 mps_printf(sc, "%s: invalid request: error %d\n",
723 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
724 sz = rpl->MsgLength * 4;
726 if (sz > cmd->rpl_len) {
728 "mps_user_command: reply buffer too small %d required %d\n",
735 copyout(rpl, cmd->rpl, sz);
737 copyout(buf, cmd->buf, cmd->len);
738 mps_dprint(sc, MPS_INFO, "mps_user_command: reply size %d\n", sz );
743 mps_free_command(sc, cm);
747 free(buf, M_MPSUSER);
752 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
754 MPI2_REQUEST_HEADER *hdr, tmphdr;
755 MPI2_DEFAULT_REPLY *rpl;
756 struct mps_command *cm = NULL;
757 int err = 0, dir = 0, sz;
758 uint8_t function = 0;
762 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
763 * bit to denote that a passthru is being processed.
766 if (sc->mps_flags & MPS_FLAGS_BUSY) {
767 mps_dprint(sc, MPS_INFO, "%s: Only one passthru command "
768 "allowed at a single time.", __func__);
772 sc->mps_flags |= MPS_FLAGS_BUSY;
776 * Do some validation on data direction. Valid cases are:
777 * 1) DataSize is 0 and direction is NONE
778 * 2) DataSize is non-zero and one of:
779 * a) direction is READ or
780 * b) direction is WRITE or
781 * c) direction is BOTH and DataOutSize is non-zero
782 * If valid and the direction is BOTH, change the direction to READ.
783 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
785 if (((data->DataSize == 0) &&
786 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
787 ((data->DataSize != 0) &&
788 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
789 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
790 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
791 (data->DataOutSize != 0))))) {
792 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
793 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
795 data->DataOutSize = 0;
799 mps_dprint(sc, MPS_INFO, "%s: req 0x%jx %d rpl 0x%jx %d "
800 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
801 data->PtrRequest, data->RequestSize, data->PtrReply,
802 data->ReplySize, data->PtrData, data->DataSize,
803 data->PtrDataOut, data->DataOutSize, data->DataDirection);
806 * copy in the header so we know what we're dealing with before we
807 * commit to allocating a command for it.
809 err = copyin(PTRIN(data->PtrRequest), &tmphdr, data->RequestSize);
811 goto RetFreeUnlocked;
813 if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
815 goto RetFreeUnlocked;
818 function = tmphdr.Function;
819 mps_dprint(sc, MPS_INFO, "%s: Function %02X MsgFlags %02X\n", __func__,
820 function, tmphdr.MsgFlags);
823 * Handle a passthru TM request.
825 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
826 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
829 cm = mpssas_alloc_tm(sc);
835 /* Copy the header in. Only a small fixup is needed. */
836 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
837 bcopy(&tmphdr, task, data->RequestSize);
838 task->TaskMID = cm->cm_desc.Default.SMID;
841 cm->cm_desc.HighPriority.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
842 cm->cm_complete = NULL;
843 cm->cm_complete_data = NULL;
845 err = mps_wait_command(sc, cm, 30);
849 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
853 * Copy the reply data and sense data to user space.
855 if (cm->cm_reply != NULL) {
856 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
857 sz = rpl->MsgLength * 4;
859 if (sz > data->ReplySize) {
860 mps_printf(sc, "%s: reply buffer too small: %d, "
861 "required: %d\n", __func__, data->ReplySize, sz);
865 copyout(cm->cm_reply, PTRIN(data->PtrReply),
870 mpssas_free_tm(sc, cm);
875 cm = mps_alloc_command(sc);
878 mps_printf(sc, "%s: no mps requests\n", __func__);
884 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
885 bcopy(&tmphdr, hdr, data->RequestSize);
888 * Do some checking to make sure the IOCTL request contains a valid
889 * request. Then set the SGL info.
891 mpi_init_sge(cm, hdr, (void *)((uint8_t *)hdr + data->RequestSize));
894 * Set up for read, write or both. From check above, DataOutSize will
895 * be 0 if direction is READ or WRITE, but it will have some non-zero
896 * value if the direction is BOTH. So, just use the biggest size to get
897 * the cm_data buffer size. If direction is BOTH, 2 SGLs need to be set
898 * up; the first is for the request and the second will contain the
899 * response data. cm_out_len needs to be set here and this will be used
900 * when the SGLs are set up.
903 cm->cm_length = MAX(data->DataSize, data->DataOutSize);
904 cm->cm_out_len = data->DataOutSize;
906 if (cm->cm_length != 0) {
907 cm->cm_data = malloc(cm->cm_length, M_MPSUSER, M_WAITOK |
909 if (cm->cm_data == NULL) {
910 mps_dprint(sc, MPS_FAULT, "%s: alloc failed for IOCTL "
911 "passthru length %d\n", __func__, cm->cm_length);
913 cm->cm_flags = MPS_CM_FLAGS_DATAIN;
914 if (data->DataOutSize) {
915 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
916 err = copyin(PTRIN(data->PtrDataOut),
917 cm->cm_data, data->DataOutSize);
918 } else if (data->DataDirection ==
919 MPS_PASS_THRU_DIRECTION_WRITE) {
920 cm->cm_flags = MPS_CM_FLAGS_DATAOUT;
921 err = copyin(PTRIN(data->PtrData),
922 cm->cm_data, data->DataSize);
925 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
926 "IOCTL data from user space\n", __func__);
929 cm->cm_flags |= MPS_CM_FLAGS_SGE_SIMPLE;
930 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
933 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
934 * uses SCSI IO descriptor.
936 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
937 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
938 MPI2_SCSI_IO_REQUEST *scsi_io_req;
940 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
942 * Put SGE for data and data_out buffer at the end of
943 * scsi_io_request message header (64 bytes in total).
944 * Following above SGEs, the residual space will be used by
947 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
949 scsi_io_req->SenseBufferLowAddress = cm->cm_sense_busaddr;
952 * Set SGLOffset0 value. This is the number of dwords that SGL
953 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
955 scsi_io_req->SGLOffset0 = 24;
958 * Setup descriptor info. RAID passthrough must use the
959 * default request descriptor which is already set, so if this
960 * is a SCSI IO request, change the descriptor to SCSI IO.
961 * Also, if this is a SCSI IO request, handle the reply in the
962 * mpssas_scsio_complete function.
964 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
965 cm->cm_desc.SCSIIO.RequestFlags =
966 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
967 cm->cm_desc.SCSIIO.DevHandle = scsi_io_req->DevHandle;
970 * Make sure the DevHandle is not 0 because this is a
973 if (scsi_io_req->DevHandle == 0) {
975 goto RetFreeUnlocked;
982 err = mps_wait_command(sc, cm, 30);
985 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
988 goto RetFreeUnlocked;
992 * Sync the DMA data, if any. Then copy the data to user space.
994 if (cm->cm_data != NULL) {
995 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN)
996 dir = BUS_DMASYNC_POSTREAD;
997 else if (cm->cm_flags & MPS_CM_FLAGS_DATAOUT)
998 dir = BUS_DMASYNC_POSTWRITE;;
999 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
1000 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
1002 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN) {
1004 err = copyout(cm->cm_data,
1005 PTRIN(data->PtrData), data->DataSize);
1008 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1009 "IOCTL data to user space\n", __func__);
1014 * Copy the reply data and sense data to user space.
1016 if (cm->cm_reply != NULL) {
1017 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1018 sz = rpl->MsgLength * 4;
1020 if (sz > data->ReplySize) {
1021 mps_printf(sc, "%s: reply buffer too small: %d, "
1022 "required: %d\n", __func__, data->ReplySize, sz);
1026 copyout(cm->cm_reply, PTRIN(data->PtrReply),
1031 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1032 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1033 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1034 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1036 MIN(((MPI2_SCSI_IO_REPLY *)rpl)->SenseCount,
1037 sizeof(struct scsi_sense_data));
1039 copyout(cm->cm_sense, cm->cm_req + 64, sense_len);
1051 free(cm->cm_data, M_MPSUSER);
1052 mps_free_command(sc, cm);
1055 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1062 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1064 Mpi2ConfigReply_t mpi_reply;
1065 Mpi2BiosPage3_t config_page;
1068 * Use the PCI interface functions to get the Bus, Device, and Function
1071 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1072 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1073 data->PciInformation.u.bits.FunctionNumber =
1074 pci_get_function(sc->mps_dev);
1077 * Get the FW version that should already be saved in IOC Facts.
1079 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1082 * General device info.
1084 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1085 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1086 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1087 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1088 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1089 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1090 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1093 * Get the driver version.
1095 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1098 * Need to get BIOS Config Page 3 for the BIOS Version.
1100 data->BiosVersion = 0;
1102 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1103 printf("%s: Error while retrieving BIOS Version\n", __func__);
1105 data->BiosVersion = config_page.BiosVersion;
1110 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1115 * Use the PCI interface functions to get the Bus, Device, and Function
1118 data->BusNumber = pci_get_bus(sc->mps_dev);
1119 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1120 data->FunctionNumber = pci_get_function(sc->mps_dev);
1123 * Now get the interrupt vector and the pci header. The vector can
1124 * only be 0 right now. The header is the first 256 bytes of config
1127 data->InterruptVector = 0;
1128 for (i = 0; i < sizeof (data->PciHeader); i++) {
1129 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1134 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1138 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1139 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1144 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1148 mps_post_fw_diag_buffer(struct mps_softc *sc,
1149 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1151 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1152 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1153 struct mps_command *cm = NULL;
1157 * If buffer is not enabled, just leave.
1159 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1160 if (!pBuffer->enabled) {
1161 return (MPS_DIAG_FAILURE);
1165 * Clear some flags initially.
1167 pBuffer->force_release = FALSE;
1168 pBuffer->valid_data = FALSE;
1169 pBuffer->owned_by_firmware = FALSE;
1174 cm = mps_alloc_command(sc);
1176 mps_printf(sc, "%s: no mps requests\n", __func__);
1177 return (MPS_DIAG_FAILURE);
1181 * Build the request for releasing the FW Diag Buffer and send it.
1183 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1184 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1185 req->BufferType = pBuffer->buffer_type;
1186 req->ExtendedType = pBuffer->extended_type;
1187 req->BufferLength = pBuffer->size;
1188 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1189 req->ProductSpecific[i] = pBuffer->product_specific[i];
1190 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1193 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1194 cm->cm_complete_data = NULL;
1197 * Send command synchronously.
1199 status = mps_wait_command(sc, cm, 30);
1201 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1203 status = MPS_DIAG_FAILURE;
1208 * Process POST reply.
1210 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1211 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1212 status = MPS_DIAG_FAILURE;
1213 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1214 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1215 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1216 reply->IOCLogInfo, reply->TransferLength);
1221 * Post was successful.
1223 pBuffer->valid_data = TRUE;
1224 pBuffer->owned_by_firmware = TRUE;
1225 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1226 status = MPS_DIAG_SUCCESS;
1229 mps_free_command(sc, cm);
1234 mps_release_fw_diag_buffer(struct mps_softc *sc,
1235 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1238 MPI2_DIAG_RELEASE_REQUEST *req;
1239 MPI2_DIAG_RELEASE_REPLY *reply;
1240 struct mps_command *cm = NULL;
1244 * If buffer is not enabled, just leave.
1246 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1247 if (!pBuffer->enabled) {
1248 mps_dprint(sc, MPS_INFO, "%s: This buffer type is not supported "
1249 "by the IOC", __func__);
1250 return (MPS_DIAG_FAILURE);
1254 * Clear some flags initially.
1256 pBuffer->force_release = FALSE;
1257 pBuffer->valid_data = FALSE;
1258 pBuffer->owned_by_firmware = FALSE;
1263 cm = mps_alloc_command(sc);
1265 mps_printf(sc, "%s: no mps requests\n", __func__);
1266 return (MPS_DIAG_FAILURE);
1270 * Build the request for releasing the FW Diag Buffer and send it.
1272 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1273 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1274 req->BufferType = pBuffer->buffer_type;
1277 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1278 cm->cm_complete_data = NULL;
1281 * Send command synchronously.
1283 status = mps_wait_command(sc, cm, 30);
1285 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1287 status = MPS_DIAG_FAILURE;
1292 * Process RELEASE reply.
1294 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1295 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1296 pBuffer->owned_by_firmware) {
1297 status = MPS_DIAG_FAILURE;
1298 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1299 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1300 __func__, reply->IOCStatus, reply->IOCLogInfo);
1305 * Release was successful.
1307 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1308 status = MPS_DIAG_SUCCESS;
1311 * If this was for an UNREGISTER diag type command, clear the unique ID.
1313 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1314 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1322 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1323 uint32_t *return_code)
1325 mps_fw_diagnostic_buffer_t *pBuffer;
1326 uint8_t extended_type, buffer_type, i;
1327 uint32_t buffer_size;
1331 extended_type = diag_register->ExtendedType;
1332 buffer_type = diag_register->BufferType;
1333 buffer_size = diag_register->RequestedBufferSize;
1334 unique_id = diag_register->UniqueId;
1337 * Check for valid buffer type
1339 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1340 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1341 return (MPS_DIAG_FAILURE);
1345 * Get the current buffer and look up the unique ID. The unique ID
1346 * should not be found. If it is, the ID is already in use.
1348 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1349 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1350 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1351 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1352 return (MPS_DIAG_FAILURE);
1356 * The buffer's unique ID should not be registered yet, and the given
1357 * unique ID cannot be 0.
1359 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1360 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1361 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1362 return (MPS_DIAG_FAILURE);
1366 * If this buffer is already posted as immediate, just change owner.
1368 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1369 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1370 pBuffer->immediate = FALSE;
1371 pBuffer->unique_id = unique_id;
1372 return (MPS_DIAG_SUCCESS);
1376 * Post a new buffer after checking if it's enabled. The DMA buffer
1377 * that is allocated will be contiguous (nsegments = 1).
1379 if (!pBuffer->enabled) {
1380 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1381 return (MPS_DIAG_FAILURE);
1383 if (bus_dma_tag_create( sc->mps_parent_dmat, /* parent */
1384 1, 0, /* algnmnt, boundary */
1385 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1386 BUS_SPACE_MAXADDR, /* highaddr */
1387 NULL, NULL, /* filter, filterarg */
1388 buffer_size, /* maxsize */
1390 buffer_size, /* maxsegsize */
1392 NULL, NULL, /* lockfunc, lockarg */
1393 &sc->fw_diag_dmat)) {
1394 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer DMA "
1398 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1399 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1400 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer "
1404 bzero(sc->fw_diag_buffer, buffer_size);
1405 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1406 buffer_size, mps_memaddr_cb, &sc->fw_diag_busaddr, 0);
1407 pBuffer->size = buffer_size;
1410 * Copy the given info to the diag buffer and post the buffer.
1412 pBuffer->buffer_type = buffer_type;
1413 pBuffer->immediate = FALSE;
1414 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1415 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1417 pBuffer->product_specific[i] =
1418 diag_register->ProductSpecific[i];
1421 pBuffer->extended_type = extended_type;
1422 pBuffer->unique_id = unique_id;
1423 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1426 * In case there was a failure, free the DMA buffer.
1428 if (status == MPS_DIAG_FAILURE) {
1429 if (sc->fw_diag_busaddr != 0)
1430 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1431 if (sc->fw_diag_buffer != NULL)
1432 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1434 if (sc->fw_diag_dmat != NULL)
1435 bus_dma_tag_destroy(sc->fw_diag_dmat);
1442 mps_diag_unregister(struct mps_softc *sc,
1443 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1445 mps_fw_diagnostic_buffer_t *pBuffer;
1450 unique_id = diag_unregister->UniqueId;
1453 * Get the current buffer and look up the unique ID. The unique ID
1456 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1457 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1458 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1459 return (MPS_DIAG_FAILURE);
1462 pBuffer = &sc->fw_diag_buffer_list[i];
1465 * Try to release the buffer from FW before freeing it. If release
1466 * fails, don't free the DMA buffer in case FW tries to access it
1467 * later. If buffer is not owned by firmware, can't release it.
1469 if (!pBuffer->owned_by_firmware) {
1470 status = MPS_DIAG_SUCCESS;
1472 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1473 MPS_FW_DIAG_TYPE_UNREGISTER);
1477 * At this point, return the current status no matter what happens with
1480 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1481 if (status == MPS_DIAG_SUCCESS) {
1482 if (sc->fw_diag_busaddr != 0)
1483 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1484 if (sc->fw_diag_buffer != NULL)
1485 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1487 if (sc->fw_diag_dmat != NULL)
1488 bus_dma_tag_destroy(sc->fw_diag_dmat);
1495 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1496 uint32_t *return_code)
1498 mps_fw_diagnostic_buffer_t *pBuffer;
1502 unique_id = diag_query->UniqueId;
1505 * If ID is valid, query on ID.
1506 * If ID is invalid, query on buffer type.
1508 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1509 i = diag_query->BufferType;
1510 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1511 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1512 return (MPS_DIAG_FAILURE);
1515 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1516 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1517 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1518 return (MPS_DIAG_FAILURE);
1523 * Fill query structure with the diag buffer info.
1525 pBuffer = &sc->fw_diag_buffer_list[i];
1526 diag_query->BufferType = pBuffer->buffer_type;
1527 diag_query->ExtendedType = pBuffer->extended_type;
1528 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1529 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1531 diag_query->ProductSpecific[i] =
1532 pBuffer->product_specific[i];
1535 diag_query->TotalBufferSize = pBuffer->size;
1536 diag_query->DriverAddedBufferSize = 0;
1537 diag_query->UniqueId = pBuffer->unique_id;
1538 diag_query->ApplicationFlags = 0;
1539 diag_query->DiagnosticFlags = 0;
1542 * Set/Clear application flags
1544 if (pBuffer->immediate) {
1545 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1547 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1549 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1550 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1552 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1554 if (pBuffer->owned_by_firmware) {
1555 diag_query->ApplicationFlags |=
1556 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1558 diag_query->ApplicationFlags &=
1559 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1562 return (MPS_DIAG_SUCCESS);
1566 mps_diag_read_buffer(struct mps_softc *sc,
1567 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1568 uint32_t *return_code)
1570 mps_fw_diagnostic_buffer_t *pBuffer;
1575 unique_id = diag_read_buffer->UniqueId;
1578 * Get the current buffer and look up the unique ID. The unique ID
1581 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1582 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1583 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1584 return (MPS_DIAG_FAILURE);
1587 pBuffer = &sc->fw_diag_buffer_list[i];
1590 * Make sure requested read is within limits
1592 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1594 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1595 return (MPS_DIAG_FAILURE);
1599 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1600 * buffer that was allocated is one contiguous buffer.
1602 pData = (uint8_t *)(sc->fw_diag_buffer +
1603 diag_read_buffer->StartingOffset);
1604 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1605 return (MPS_DIAG_FAILURE);
1606 diag_read_buffer->Status = 0;
1609 * Set or clear the Force Release flag.
1611 if (pBuffer->force_release) {
1612 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1614 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1618 * If buffer is to be reregistered, make sure it's not already owned by
1621 status = MPS_DIAG_SUCCESS;
1622 if (!pBuffer->owned_by_firmware) {
1623 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1624 status = mps_post_fw_diag_buffer(sc, pBuffer,
1633 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1634 uint32_t *return_code)
1636 mps_fw_diagnostic_buffer_t *pBuffer;
1641 unique_id = diag_release->UniqueId;
1644 * Get the current buffer and look up the unique ID. The unique ID
1647 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1648 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1649 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1650 return (MPS_DIAG_FAILURE);
1653 pBuffer = &sc->fw_diag_buffer_list[i];
1656 * If buffer is not owned by firmware, it's already been released.
1658 if (!pBuffer->owned_by_firmware) {
1659 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1660 return (MPS_DIAG_FAILURE);
1664 * Release the buffer.
1666 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1667 MPS_FW_DIAG_TYPE_RELEASE);
1672 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1673 uint32_t length, uint32_t *return_code)
1675 mps_fw_diag_register_t diag_register;
1676 mps_fw_diag_unregister_t diag_unregister;
1677 mps_fw_diag_query_t diag_query;
1678 mps_diag_read_buffer_t diag_read_buffer;
1679 mps_fw_diag_release_t diag_release;
1680 int status = MPS_DIAG_SUCCESS;
1681 uint32_t original_return_code;
1683 original_return_code = *return_code;
1684 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1687 case MPS_FW_DIAG_TYPE_REGISTER:
1690 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1691 status = MPS_DIAG_FAILURE;
1694 if (copyin(diag_action, &diag_register,
1695 sizeof(diag_register)) != 0)
1696 return (MPS_DIAG_FAILURE);
1697 status = mps_diag_register(sc, &diag_register,
1701 case MPS_FW_DIAG_TYPE_UNREGISTER:
1702 if (length < sizeof(diag_unregister)) {
1704 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1705 status = MPS_DIAG_FAILURE;
1708 if (copyin(diag_action, &diag_unregister,
1709 sizeof(diag_unregister)) != 0)
1710 return (MPS_DIAG_FAILURE);
1711 status = mps_diag_unregister(sc, &diag_unregister,
1715 case MPS_FW_DIAG_TYPE_QUERY:
1716 if (length < sizeof (diag_query)) {
1718 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1719 status = MPS_DIAG_FAILURE;
1722 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1724 return (MPS_DIAG_FAILURE);
1725 status = mps_diag_query(sc, &diag_query, return_code);
1726 if (status == MPS_DIAG_SUCCESS)
1727 if (copyout(&diag_query, diag_action,
1728 sizeof (diag_query)) != 0)
1729 return (MPS_DIAG_FAILURE);
1732 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1733 if (copyin(diag_action, &diag_read_buffer,
1734 sizeof(diag_read_buffer)) != 0)
1735 return (MPS_DIAG_FAILURE);
1736 if (length < diag_read_buffer.BytesToRead) {
1738 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1739 status = MPS_DIAG_FAILURE;
1742 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1743 PTRIN(diag_read_buffer.PtrDataBuffer),
1745 if (status == MPS_DIAG_SUCCESS) {
1746 if (copyout(&diag_read_buffer, diag_action,
1747 sizeof(diag_read_buffer) -
1748 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1750 return (MPS_DIAG_FAILURE);
1754 case MPS_FW_DIAG_TYPE_RELEASE:
1755 if (length < sizeof(diag_release)) {
1757 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1758 status = MPS_DIAG_FAILURE;
1761 if (copyin(diag_action, &diag_release,
1762 sizeof(diag_release)) != 0)
1763 return (MPS_DIAG_FAILURE);
1764 status = mps_diag_release(sc, &diag_release,
1769 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1770 status = MPS_DIAG_FAILURE;
1774 if ((status == MPS_DIAG_FAILURE) &&
1775 (original_return_code == MPS_FW_DIAG_NEW) &&
1776 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1777 status = MPS_DIAG_SUCCESS;
1783 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1788 * Only allow one diag action at one time.
1790 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1791 mps_dprint(sc, MPS_INFO, "%s: Only one FW diag command "
1792 "allowed at a single time.", __func__);
1795 sc->mps_flags |= MPS_FLAGS_BUSY;
1798 * Send diag action request
1800 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1801 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1802 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1803 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1804 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1805 status = mps_do_diag_action(sc, data->Action,
1806 PTRIN(data->PtrDiagAction), data->Length,
1811 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1816 * Copy the event recording mask and the event queue size out. For
1817 * clarification, the event recording mask (events_to_record) is not the same
1818 * thing as the event mask (event_mask). events_to_record has a bit set for
1819 * every event type that is to be recorded by the driver, and event_mask has a
1820 * bit cleared for every event that is allowed into the driver from the IOC.
1821 * They really have nothing to do with each other.
1824 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1829 data->Entries = MPS_EVENT_QUEUE_SIZE;
1831 for (i = 0; i < 4; i++) {
1832 data->Types[i] = sc->events_to_record[i];
1838 * Set the driver's event mask according to what's been given. See
1839 * mps_user_event_query for explanation of the event recording mask and the IOC
1840 * event mask. It's the app's responsibility to enable event logging by setting
1841 * the bits in events_to_record. Initially, no events will be logged.
1844 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1849 for (i = 0; i < 4; i++) {
1850 sc->events_to_record[i] = data->Types[i];
1856 * Copy out the events that have been recorded, up to the max events allowed.
1859 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1866 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1868 if (copyout((void *)sc->recorded_events,
1869 PTRIN(data->PtrEvents), size) != 0)
1874 * data->Size value is not large enough to copy event data.
1880 * Change size value to match the number of bytes that were copied.
1883 data->Size = sizeof(sc->recorded_events);
1890 * Record events into the driver from the IOC if they are not masked.
1893 mpssas_record_event(struct mps_softc *sc,
1894 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1898 uint16_t event_data_len;
1899 boolean_t sendAEN = FALSE;
1901 event = event_reply->Event;
1904 * Generate a system event to let anyone who cares know that a
1905 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1906 * event mask is set to.
1908 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1913 * Record the event only if its corresponding bit is set in
1914 * events_to_record. event_index is the index into recorded_events and
1915 * event_number is the overall number of an event being recorded since
1916 * start-of-day. event_index will roll over; event_number will never
1919 i = (uint8_t)(event / 32);
1920 j = (uint8_t)(event % 32);
1921 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1922 i = sc->event_index;
1923 sc->recorded_events[i].Type = event;
1924 sc->recorded_events[i].Number = ++sc->event_number;
1925 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
1927 event_data_len = event_reply->EventDataLength;
1929 if (event_data_len > 0) {
1931 * Limit data to size in m_event entry
1933 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
1934 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
1936 for (j = 0; j < event_data_len; j++) {
1937 sc->recorded_events[i].Data[j] =
1938 event_reply->EventData[j];
1942 * check for index wrap-around
1944 if (++i == MPS_EVENT_QUEUE_SIZE) {
1947 sc->event_index = (uint8_t)i;
1950 * Set flag to send the event.
1957 * Generate a system event if flag is set to let anyone who cares know
1958 * that an event has occurred.
1961 //SLM-how to send a system event (see kqueue, kevent)
1962 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
1963 // "SAS", NULL, NULL, DDI_NOSLEEP);
1968 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
1972 switch (data->Command) {
1974 * IO access is not supported.
1978 mps_dprint(sc, MPS_INFO, "IO access is not supported. "
1979 "Use memory access.");
1984 data->RegData = mps_regread(sc, data->RegOffset);
1988 mps_regwrite(sc, data->RegOffset, data->RegData);
2000 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
2002 uint8_t bt2dh = FALSE;
2003 uint8_t dh2bt = FALSE;
2004 uint16_t dev_handle, bus, target;
2007 target = data->TargetID;
2008 dev_handle = data->DevHandle;
2011 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2012 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2013 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2016 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2018 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2020 if (!dh2bt && !bt2dh)
2024 * Only handle bus of 0. Make sure target is within range.
2030 if (target > sc->max_devices) {
2031 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2032 "for Bus/Target to DevHandle mapping.");
2035 dev_handle = sc->mapping_table[target].dev_handle;
2037 data->DevHandle = dev_handle;
2040 target = mps_mapping_get_sas_id_from_handle(sc, dev_handle);
2042 data->TargetID = target;
2049 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2052 struct mps_softc *sc;
2053 struct mps_cfg_page_req *page_req;
2054 struct mps_ext_cfg_page_req *ext_page_req;
2056 int error, reset_loop;
2060 page_req = (void *)arg;
2061 ext_page_req = (void *)arg;
2064 case MPSIO_READ_CFG_HEADER:
2066 error = mps_user_read_cfg_header(sc, page_req);
2069 case MPSIO_READ_CFG_PAGE:
2070 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2071 error = copyin(page_req->buf, mps_page,
2072 sizeof(MPI2_CONFIG_PAGE_HEADER));
2076 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2080 error = copyout(mps_page, page_req->buf, page_req->len);
2082 case MPSIO_READ_EXT_CFG_HEADER:
2084 error = mps_user_read_extcfg_header(sc, ext_page_req);
2087 case MPSIO_READ_EXT_CFG_PAGE:
2088 mps_page = malloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2089 error = copyin(ext_page_req->buf, mps_page,
2090 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2094 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2098 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2100 case MPSIO_WRITE_CFG_PAGE:
2101 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2102 error = copyin(page_req->buf, mps_page, page_req->len);
2106 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2109 case MPSIO_MPS_COMMAND:
2110 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2112 case MPTIOCTL_PASS_THRU:
2114 * The user has requested to pass through a command to be
2115 * executed by the MPT firmware. Call our routine which does
2116 * this. Only allow one passthru IOCTL at one time.
2118 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2120 case MPTIOCTL_GET_ADAPTER_DATA:
2122 * The user has requested to read adapter data. Call our
2123 * routine which does this.
2126 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2128 case MPTIOCTL_GET_PCI_INFO:
2130 * The user has requested to read pci info. Call
2131 * our routine which does this.
2135 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2138 case MPTIOCTL_RESET_ADAPTER:
2140 sc->port_enable_complete = 0;
2141 error = mps_reinit(sc);
2144 * Wait no more than 5 minutes for Port Enable to complete
2146 for (reset_loop = 0; (reset_loop < MPS_DIAG_RESET_TIMEOUT) &&
2147 (!sc->port_enable_complete); reset_loop++) {
2150 if (reset_loop == MPS_DIAG_RESET_TIMEOUT) {
2151 printf("Port Enable did not complete after Diag "
2155 case MPTIOCTL_DIAG_ACTION:
2157 * The user has done a diag buffer action. Call our routine
2158 * which does this. Only allow one diag action at one time.
2161 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2164 case MPTIOCTL_EVENT_QUERY:
2166 * The user has done an event query. Call our routine which does
2170 mps_user_event_query(sc, (mps_event_query_t *)arg);
2172 case MPTIOCTL_EVENT_ENABLE:
2174 * The user has done an event enable. Call our routine which
2178 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2180 case MPTIOCTL_EVENT_REPORT:
2182 * The user has done an event report. Call our routine which
2185 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2187 case MPTIOCTL_REG_ACCESS:
2189 * The user has requested register access. Call our routine
2193 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2196 case MPTIOCTL_BTDH_MAPPING:
2198 * The user has requested to translate a bus/target to a
2199 * DevHandle or a DevHandle to a bus/target. Call our routine
2202 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2209 if (mps_page != NULL)
2210 free(mps_page, M_MPSUSER);
2215 #ifdef COMPAT_FREEBSD32
2217 struct mps_cfg_page_req32 {
2218 MPI2_CONFIG_PAGE_HEADER header;
2219 uint32_t page_address;
2222 uint16_t ioc_status;
2225 struct mps_ext_cfg_page_req32 {
2226 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2227 uint32_t page_address;
2230 uint16_t ioc_status;
2233 struct mps_raid_action32 {
2237 uint8_t phys_disk_num;
2238 uint32_t action_data_word;
2241 uint32_t volume_status;
2242 uint32_t action_data[4];
2243 uint16_t action_status;
2244 uint16_t ioc_status;
2248 struct mps_usr_command32 {
2258 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2259 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2260 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2261 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2262 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2263 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2264 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2267 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2270 struct mps_cfg_page_req32 *page32 = _arg;
2271 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2272 struct mps_raid_action32 *raid32 = _arg;
2273 struct mps_usr_command32 *user32 = _arg;
2275 struct mps_cfg_page_req page;
2276 struct mps_ext_cfg_page_req ext;
2277 struct mps_raid_action raid;
2278 struct mps_usr_command user;
2284 case MPSIO_READ_CFG_HEADER32:
2285 case MPSIO_READ_CFG_PAGE32:
2286 case MPSIO_WRITE_CFG_PAGE32:
2287 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2288 cmd = MPSIO_READ_CFG_HEADER;
2289 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2290 cmd = MPSIO_READ_CFG_PAGE;
2292 cmd = MPSIO_WRITE_CFG_PAGE;
2293 CP(*page32, arg.page, header);
2294 CP(*page32, arg.page, page_address);
2295 PTRIN_CP(*page32, arg.page, buf);
2296 CP(*page32, arg.page, len);
2297 CP(*page32, arg.page, ioc_status);
2300 case MPSIO_READ_EXT_CFG_HEADER32:
2301 case MPSIO_READ_EXT_CFG_PAGE32:
2302 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2303 cmd = MPSIO_READ_EXT_CFG_HEADER;
2305 cmd = MPSIO_READ_EXT_CFG_PAGE;
2306 CP(*ext32, arg.ext, header);
2307 CP(*ext32, arg.ext, page_address);
2308 PTRIN_CP(*ext32, arg.ext, buf);
2309 CP(*ext32, arg.ext, len);
2310 CP(*ext32, arg.ext, ioc_status);
2313 case MPSIO_RAID_ACTION32:
2314 cmd = MPSIO_RAID_ACTION;
2315 CP(*raid32, arg.raid, action);
2316 CP(*raid32, arg.raid, volume_bus);
2317 CP(*raid32, arg.raid, volume_id);
2318 CP(*raid32, arg.raid, phys_disk_num);
2319 CP(*raid32, arg.raid, action_data_word);
2320 PTRIN_CP(*raid32, arg.raid, buf);
2321 CP(*raid32, arg.raid, len);
2322 CP(*raid32, arg.raid, volume_status);
2323 bcopy(raid32->action_data, arg.raid.action_data,
2324 sizeof arg.raid.action_data);
2325 CP(*raid32, arg.raid, ioc_status);
2326 CP(*raid32, arg.raid, write);
2329 case MPSIO_MPS_COMMAND32:
2330 cmd = MPSIO_MPS_COMMAND;
2331 PTRIN_CP(*user32, arg.user, req);
2332 CP(*user32, arg.user, req_len);
2333 PTRIN_CP(*user32, arg.user, rpl);
2334 CP(*user32, arg.user, rpl_len);
2335 PTRIN_CP(*user32, arg.user, buf);
2336 CP(*user32, arg.user, len);
2337 CP(*user32, arg.user, flags);
2343 error = mps_ioctl(dev, cmd, &arg, flag, td);
2344 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2346 case MPSIO_READ_CFG_HEADER32:
2347 case MPSIO_READ_CFG_PAGE32:
2348 case MPSIO_WRITE_CFG_PAGE32:
2349 CP(arg.page, *page32, header);
2350 CP(arg.page, *page32, page_address);
2351 PTROUT_CP(arg.page, *page32, buf);
2352 CP(arg.page, *page32, len);
2353 CP(arg.page, *page32, ioc_status);
2356 case MPSIO_READ_EXT_CFG_HEADER32:
2357 case MPSIO_READ_EXT_CFG_PAGE32:
2358 CP(arg.ext, *ext32, header);
2359 CP(arg.ext, *ext32, page_address);
2360 PTROUT_CP(arg.ext, *ext32, buf);
2361 CP(arg.ext, *ext32, len);
2362 CP(arg.ext, *ext32, ioc_status);
2365 case MPSIO_RAID_ACTION32:
2366 CP(arg.raid, *raid32, action);
2367 CP(arg.raid, *raid32, volume_bus);
2368 CP(arg.raid, *raid32, volume_id);
2369 CP(arg.raid, *raid32, phys_disk_num);
2370 CP(arg.raid, *raid32, action_data_word);
2371 PTROUT_CP(arg.raid, *raid32, buf);
2372 CP(arg.raid, *raid32, len);
2373 CP(arg.raid, *raid32, volume_status);
2374 bcopy(arg.raid.action_data, raid32->action_data,
2375 sizeof arg.raid.action_data);
2376 CP(arg.raid, *raid32, ioc_status);
2377 CP(arg.raid, *raid32, write);
2380 case MPSIO_MPS_COMMAND32:
2381 PTROUT_CP(arg.user, *user32, req);
2382 CP(arg.user, *user32, req_len);
2383 PTROUT_CP(arg.user, *user32, rpl);
2384 CP(arg.user, *user32, rpl_len);
2385 PTROUT_CP(arg.user, *user32, buf);
2386 CP(arg.user, *user32, len);
2387 CP(arg.user, *user32, flags);
2394 #endif /* COMPAT_FREEBSD32 */
2397 mps_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2400 #ifdef COMPAT_FREEBSD32
2401 if (SV_CURPROC_FLAG(SV_ILP32))
2402 return (mps_ioctl32(dev, com, arg, flag, td));
2404 return (mps_ioctl(dev, com, arg, flag, td));