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, 0);
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, 0);
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, 0);
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;
1101 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1102 printf("%s: Error while retrieving BIOS Version\n", __func__);
1104 data->BiosVersion = config_page.BiosVersion;
1108 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1113 * Use the PCI interface functions to get the Bus, Device, and Function
1116 data->BusNumber = pci_get_bus(sc->mps_dev);
1117 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1118 data->FunctionNumber = pci_get_function(sc->mps_dev);
1121 * Now get the interrupt vector and the pci header. The vector can
1122 * only be 0 right now. The header is the first 256 bytes of config
1125 data->InterruptVector = 0;
1126 for (i = 0; i < sizeof (data->PciHeader); i++) {
1127 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1132 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1136 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1137 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1142 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1146 mps_post_fw_diag_buffer(struct mps_softc *sc,
1147 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1149 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1150 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1151 struct mps_command *cm = NULL;
1155 * If buffer is not enabled, just leave.
1157 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1158 if (!pBuffer->enabled) {
1159 return (MPS_DIAG_FAILURE);
1163 * Clear some flags initially.
1165 pBuffer->force_release = FALSE;
1166 pBuffer->valid_data = FALSE;
1167 pBuffer->owned_by_firmware = FALSE;
1172 cm = mps_alloc_command(sc);
1174 mps_printf(sc, "%s: no mps requests\n", __func__);
1175 return (MPS_DIAG_FAILURE);
1179 * Build the request for releasing the FW Diag Buffer and send it.
1181 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1182 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1183 req->BufferType = pBuffer->buffer_type;
1184 req->ExtendedType = pBuffer->extended_type;
1185 req->BufferLength = pBuffer->size;
1186 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1187 req->ProductSpecific[i] = pBuffer->product_specific[i];
1188 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1191 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1192 cm->cm_complete_data = NULL;
1195 * Send command synchronously.
1197 status = mps_wait_command(sc, cm, 0);
1199 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1201 status = MPS_DIAG_FAILURE;
1206 * Process POST reply.
1208 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1209 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1210 status = MPS_DIAG_FAILURE;
1211 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1212 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1213 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1214 reply->IOCLogInfo, reply->TransferLength);
1219 * Post was successful.
1221 pBuffer->valid_data = TRUE;
1222 pBuffer->owned_by_firmware = TRUE;
1223 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1224 status = MPS_DIAG_SUCCESS;
1227 mps_free_command(sc, cm);
1232 mps_release_fw_diag_buffer(struct mps_softc *sc,
1233 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1236 MPI2_DIAG_RELEASE_REQUEST *req;
1237 MPI2_DIAG_RELEASE_REPLY *reply;
1238 struct mps_command *cm = NULL;
1242 * If buffer is not enabled, just leave.
1244 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1245 if (!pBuffer->enabled) {
1246 mps_dprint(sc, MPS_INFO, "%s: This buffer type is not supported "
1247 "by the IOC", __func__);
1248 return (MPS_DIAG_FAILURE);
1252 * Clear some flags initially.
1254 pBuffer->force_release = FALSE;
1255 pBuffer->valid_data = FALSE;
1256 pBuffer->owned_by_firmware = FALSE;
1261 cm = mps_alloc_command(sc);
1263 mps_printf(sc, "%s: no mps requests\n", __func__);
1264 return (MPS_DIAG_FAILURE);
1268 * Build the request for releasing the FW Diag Buffer and send it.
1270 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1271 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1272 req->BufferType = pBuffer->buffer_type;
1275 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1276 cm->cm_complete_data = NULL;
1279 * Send command synchronously.
1281 status = mps_wait_command(sc, cm, 0);
1283 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1285 status = MPS_DIAG_FAILURE;
1290 * Process RELEASE reply.
1292 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1293 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1294 pBuffer->owned_by_firmware) {
1295 status = MPS_DIAG_FAILURE;
1296 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1297 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1298 __func__, reply->IOCStatus, reply->IOCLogInfo);
1303 * Release was successful.
1305 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1306 status = MPS_DIAG_SUCCESS;
1309 * If this was for an UNREGISTER diag type command, clear the unique ID.
1311 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1312 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1320 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1321 uint32_t *return_code)
1323 mps_fw_diagnostic_buffer_t *pBuffer;
1324 uint8_t extended_type, buffer_type, i;
1325 uint32_t buffer_size;
1329 extended_type = diag_register->ExtendedType;
1330 buffer_type = diag_register->BufferType;
1331 buffer_size = diag_register->RequestedBufferSize;
1332 unique_id = diag_register->UniqueId;
1335 * Check for valid buffer type
1337 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1338 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1339 return (MPS_DIAG_FAILURE);
1343 * Get the current buffer and look up the unique ID. The unique ID
1344 * should not be found. If it is, the ID is already in use.
1346 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1347 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1348 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1349 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1350 return (MPS_DIAG_FAILURE);
1354 * The buffer's unique ID should not be registered yet, and the given
1355 * unique ID cannot be 0.
1357 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1358 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1359 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1360 return (MPS_DIAG_FAILURE);
1364 * If this buffer is already posted as immediate, just change owner.
1366 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1367 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1368 pBuffer->immediate = FALSE;
1369 pBuffer->unique_id = unique_id;
1370 return (MPS_DIAG_SUCCESS);
1374 * Post a new buffer after checking if it's enabled. The DMA buffer
1375 * that is allocated will be contiguous (nsegments = 1).
1377 if (!pBuffer->enabled) {
1378 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1379 return (MPS_DIAG_FAILURE);
1381 if (bus_dma_tag_create( sc->mps_parent_dmat, /* parent */
1382 1, 0, /* algnmnt, boundary */
1383 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1384 BUS_SPACE_MAXADDR, /* highaddr */
1385 NULL, NULL, /* filter, filterarg */
1386 buffer_size, /* maxsize */
1388 buffer_size, /* maxsegsize */
1390 NULL, NULL, /* lockfunc, lockarg */
1391 &sc->fw_diag_dmat)) {
1392 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer DMA "
1396 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1397 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1398 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer "
1402 bzero(sc->fw_diag_buffer, buffer_size);
1403 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1404 buffer_size, mps_memaddr_cb, &sc->fw_diag_busaddr, 0);
1405 pBuffer->size = buffer_size;
1408 * Copy the given info to the diag buffer and post the buffer.
1410 pBuffer->buffer_type = buffer_type;
1411 pBuffer->immediate = FALSE;
1412 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1413 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1415 pBuffer->product_specific[i] =
1416 diag_register->ProductSpecific[i];
1419 pBuffer->extended_type = extended_type;
1420 pBuffer->unique_id = unique_id;
1421 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1424 * In case there was a failure, free the DMA buffer.
1426 if (status == MPS_DIAG_FAILURE) {
1427 if (sc->fw_diag_busaddr != 0)
1428 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1429 if (sc->fw_diag_buffer != NULL)
1430 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1432 if (sc->fw_diag_dmat != NULL)
1433 bus_dma_tag_destroy(sc->fw_diag_dmat);
1440 mps_diag_unregister(struct mps_softc *sc,
1441 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1443 mps_fw_diagnostic_buffer_t *pBuffer;
1448 unique_id = diag_unregister->UniqueId;
1451 * Get the current buffer and look up the unique ID. The unique ID
1454 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1455 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1456 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1457 return (MPS_DIAG_FAILURE);
1460 pBuffer = &sc->fw_diag_buffer_list[i];
1463 * Try to release the buffer from FW before freeing it. If release
1464 * fails, don't free the DMA buffer in case FW tries to access it
1465 * later. If buffer is not owned by firmware, can't release it.
1467 if (!pBuffer->owned_by_firmware) {
1468 status = MPS_DIAG_SUCCESS;
1470 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1471 MPS_FW_DIAG_TYPE_UNREGISTER);
1475 * At this point, return the current status no matter what happens with
1478 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1479 if (status == MPS_DIAG_SUCCESS) {
1480 if (sc->fw_diag_busaddr != 0)
1481 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1482 if (sc->fw_diag_buffer != NULL)
1483 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1485 if (sc->fw_diag_dmat != NULL)
1486 bus_dma_tag_destroy(sc->fw_diag_dmat);
1493 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1494 uint32_t *return_code)
1496 mps_fw_diagnostic_buffer_t *pBuffer;
1500 unique_id = diag_query->UniqueId;
1503 * If ID is valid, query on ID.
1504 * If ID is invalid, query on buffer type.
1506 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1507 i = diag_query->BufferType;
1508 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1509 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1510 return (MPS_DIAG_FAILURE);
1513 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1514 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1515 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1516 return (MPS_DIAG_FAILURE);
1521 * Fill query structure with the diag buffer info.
1523 pBuffer = &sc->fw_diag_buffer_list[i];
1524 diag_query->BufferType = pBuffer->buffer_type;
1525 diag_query->ExtendedType = pBuffer->extended_type;
1526 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1527 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1529 diag_query->ProductSpecific[i] =
1530 pBuffer->product_specific[i];
1533 diag_query->TotalBufferSize = pBuffer->size;
1534 diag_query->DriverAddedBufferSize = 0;
1535 diag_query->UniqueId = pBuffer->unique_id;
1536 diag_query->ApplicationFlags = 0;
1537 diag_query->DiagnosticFlags = 0;
1540 * Set/Clear application flags
1542 if (pBuffer->immediate) {
1543 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1545 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1547 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1548 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1550 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1552 if (pBuffer->owned_by_firmware) {
1553 diag_query->ApplicationFlags |=
1554 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1556 diag_query->ApplicationFlags &=
1557 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1560 return (MPS_DIAG_SUCCESS);
1564 mps_diag_read_buffer(struct mps_softc *sc,
1565 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1566 uint32_t *return_code)
1568 mps_fw_diagnostic_buffer_t *pBuffer;
1573 unique_id = diag_read_buffer->UniqueId;
1576 * Get the current buffer and look up the unique ID. The unique ID
1579 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1580 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1581 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1582 return (MPS_DIAG_FAILURE);
1585 pBuffer = &sc->fw_diag_buffer_list[i];
1588 * Make sure requested read is within limits
1590 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1592 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1593 return (MPS_DIAG_FAILURE);
1597 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1598 * buffer that was allocated is one contiguous buffer.
1600 pData = (uint8_t *)(sc->fw_diag_buffer +
1601 diag_read_buffer->StartingOffset);
1602 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1603 return (MPS_DIAG_FAILURE);
1604 diag_read_buffer->Status = 0;
1607 * Set or clear the Force Release flag.
1609 if (pBuffer->force_release) {
1610 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1612 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1616 * If buffer is to be reregistered, make sure it's not already owned by
1619 status = MPS_DIAG_SUCCESS;
1620 if (!pBuffer->owned_by_firmware) {
1621 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1622 status = mps_post_fw_diag_buffer(sc, pBuffer,
1631 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1632 uint32_t *return_code)
1634 mps_fw_diagnostic_buffer_t *pBuffer;
1639 unique_id = diag_release->UniqueId;
1642 * Get the current buffer and look up the unique ID. The unique ID
1645 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1646 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1647 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1648 return (MPS_DIAG_FAILURE);
1651 pBuffer = &sc->fw_diag_buffer_list[i];
1654 * If buffer is not owned by firmware, it's already been released.
1656 if (!pBuffer->owned_by_firmware) {
1657 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1658 return (MPS_DIAG_FAILURE);
1662 * Release the buffer.
1664 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1665 MPS_FW_DIAG_TYPE_RELEASE);
1670 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1671 uint32_t length, uint32_t *return_code)
1673 mps_fw_diag_register_t diag_register;
1674 mps_fw_diag_unregister_t diag_unregister;
1675 mps_fw_diag_query_t diag_query;
1676 mps_diag_read_buffer_t diag_read_buffer;
1677 mps_fw_diag_release_t diag_release;
1678 int status = MPS_DIAG_SUCCESS;
1679 uint32_t original_return_code;
1681 original_return_code = *return_code;
1682 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1685 case MPS_FW_DIAG_TYPE_REGISTER:
1688 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1689 status = MPS_DIAG_FAILURE;
1692 if (copyin(diag_action, &diag_register,
1693 sizeof(diag_register)) != 0)
1694 return (MPS_DIAG_FAILURE);
1695 status = mps_diag_register(sc, &diag_register,
1699 case MPS_FW_DIAG_TYPE_UNREGISTER:
1700 if (length < sizeof(diag_unregister)) {
1702 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1703 status = MPS_DIAG_FAILURE;
1706 if (copyin(diag_action, &diag_unregister,
1707 sizeof(diag_unregister)) != 0)
1708 return (MPS_DIAG_FAILURE);
1709 status = mps_diag_unregister(sc, &diag_unregister,
1713 case MPS_FW_DIAG_TYPE_QUERY:
1714 if (length < sizeof (diag_query)) {
1716 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1717 status = MPS_DIAG_FAILURE;
1720 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1722 return (MPS_DIAG_FAILURE);
1723 status = mps_diag_query(sc, &diag_query, return_code);
1724 if (status == MPS_DIAG_SUCCESS)
1725 if (copyout(&diag_query, diag_action,
1726 sizeof (diag_query)) != 0)
1727 return (MPS_DIAG_FAILURE);
1730 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1731 if (copyin(diag_action, &diag_read_buffer,
1732 sizeof(diag_read_buffer)) != 0)
1733 return (MPS_DIAG_FAILURE);
1734 if (length < diag_read_buffer.BytesToRead) {
1736 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1737 status = MPS_DIAG_FAILURE;
1740 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1741 PTRIN(diag_read_buffer.PtrDataBuffer),
1743 if (status == MPS_DIAG_SUCCESS) {
1744 if (copyout(&diag_read_buffer, diag_action,
1745 sizeof(diag_read_buffer) -
1746 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1748 return (MPS_DIAG_FAILURE);
1752 case MPS_FW_DIAG_TYPE_RELEASE:
1753 if (length < sizeof(diag_release)) {
1755 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1756 status = MPS_DIAG_FAILURE;
1759 if (copyin(diag_action, &diag_release,
1760 sizeof(diag_release)) != 0)
1761 return (MPS_DIAG_FAILURE);
1762 status = mps_diag_release(sc, &diag_release,
1767 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1768 status = MPS_DIAG_FAILURE;
1772 if ((status == MPS_DIAG_FAILURE) &&
1773 (original_return_code == MPS_FW_DIAG_NEW) &&
1774 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1775 status = MPS_DIAG_SUCCESS;
1781 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1786 * Only allow one diag action at one time.
1788 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1789 mps_dprint(sc, MPS_INFO, "%s: Only one FW diag command "
1790 "allowed at a single time.", __func__);
1793 sc->mps_flags |= MPS_FLAGS_BUSY;
1796 * Send diag action request
1798 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1799 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1800 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1801 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1802 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1803 status = mps_do_diag_action(sc, data->Action,
1804 PTRIN(data->PtrDiagAction), data->Length,
1809 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1814 * Copy the event recording mask and the event queue size out. For
1815 * clarification, the event recording mask (events_to_record) is not the same
1816 * thing as the event mask (event_mask). events_to_record has a bit set for
1817 * every event type that is to be recorded by the driver, and event_mask has a
1818 * bit cleared for every event that is allowed into the driver from the IOC.
1819 * They really have nothing to do with each other.
1822 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1827 data->Entries = MPS_EVENT_QUEUE_SIZE;
1829 for (i = 0; i < 4; i++) {
1830 data->Types[i] = sc->events_to_record[i];
1836 * Set the driver's event mask according to what's been given. See
1837 * mps_user_event_query for explanation of the event recording mask and the IOC
1838 * event mask. It's the app's responsibility to enable event logging by setting
1839 * the bits in events_to_record. Initially, no events will be logged.
1842 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1847 for (i = 0; i < 4; i++) {
1848 sc->events_to_record[i] = data->Types[i];
1854 * Copy out the events that have been recorded, up to the max events allowed.
1857 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1864 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1866 if (copyout((void *)sc->recorded_events,
1867 PTRIN(data->PtrEvents), size) != 0)
1872 * data->Size value is not large enough to copy event data.
1878 * Change size value to match the number of bytes that were copied.
1881 data->Size = sizeof(sc->recorded_events);
1888 * Record events into the driver from the IOC if they are not masked.
1891 mpssas_record_event(struct mps_softc *sc,
1892 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1896 uint16_t event_data_len;
1897 boolean_t sendAEN = FALSE;
1899 event = event_reply->Event;
1902 * Generate a system event to let anyone who cares know that a
1903 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1904 * event mask is set to.
1906 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1911 * Record the event only if its corresponding bit is set in
1912 * events_to_record. event_index is the index into recorded_events and
1913 * event_number is the overall number of an event being recorded since
1914 * start-of-day. event_index will roll over; event_number will never
1917 i = (uint8_t)(event / 32);
1918 j = (uint8_t)(event % 32);
1919 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1920 i = sc->event_index;
1921 sc->recorded_events[i].Type = event;
1922 sc->recorded_events[i].Number = ++sc->event_number;
1923 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
1925 event_data_len = event_reply->EventDataLength;
1927 if (event_data_len > 0) {
1929 * Limit data to size in m_event entry
1931 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
1932 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
1934 for (j = 0; j < event_data_len; j++) {
1935 sc->recorded_events[i].Data[j] =
1936 event_reply->EventData[j];
1940 * check for index wrap-around
1942 if (++i == MPS_EVENT_QUEUE_SIZE) {
1945 sc->event_index = (uint8_t)i;
1948 * Set flag to send the event.
1955 * Generate a system event if flag is set to let anyone who cares know
1956 * that an event has occurred.
1959 //SLM-how to send a system event (see kqueue, kevent)
1960 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
1961 // "SAS", NULL, NULL, DDI_NOSLEEP);
1966 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
1970 switch (data->Command) {
1972 * IO access is not supported.
1976 mps_dprint(sc, MPS_INFO, "IO access is not supported. "
1977 "Use memory access.");
1982 data->RegData = mps_regread(sc, data->RegOffset);
1986 mps_regwrite(sc, data->RegOffset, data->RegData);
1998 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
2000 uint8_t bt2dh = FALSE;
2001 uint8_t dh2bt = FALSE;
2002 uint16_t dev_handle, bus, target;
2005 target = data->TargetID;
2006 dev_handle = data->DevHandle;
2009 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2010 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2011 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2014 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2016 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2018 if (!dh2bt && !bt2dh)
2022 * Only handle bus of 0. Make sure target is within range.
2028 if (target > sc->max_devices) {
2029 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2030 "for Bus/Target to DevHandle mapping.");
2033 dev_handle = sc->mapping_table[target].dev_handle;
2035 data->DevHandle = dev_handle;
2038 target = mps_mapping_get_sas_id_from_handle(sc, dev_handle);
2040 data->TargetID = target;
2047 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2050 struct mps_softc *sc;
2051 struct mps_cfg_page_req *page_req;
2052 struct mps_ext_cfg_page_req *ext_page_req;
2054 int error, reset_loop;
2058 page_req = (void *)arg;
2059 ext_page_req = (void *)arg;
2062 case MPSIO_READ_CFG_HEADER:
2064 error = mps_user_read_cfg_header(sc, page_req);
2067 case MPSIO_READ_CFG_PAGE:
2068 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2069 error = copyin(page_req->buf, mps_page,
2070 sizeof(MPI2_CONFIG_PAGE_HEADER));
2074 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2078 error = copyout(mps_page, page_req->buf, page_req->len);
2080 case MPSIO_READ_EXT_CFG_HEADER:
2082 error = mps_user_read_extcfg_header(sc, ext_page_req);
2085 case MPSIO_READ_EXT_CFG_PAGE:
2086 mps_page = malloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2087 error = copyin(ext_page_req->buf, mps_page,
2088 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2092 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2096 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2098 case MPSIO_WRITE_CFG_PAGE:
2099 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2100 error = copyin(page_req->buf, mps_page, page_req->len);
2104 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2107 case MPSIO_MPS_COMMAND:
2108 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2110 case MPTIOCTL_PASS_THRU:
2112 * The user has requested to pass through a command to be
2113 * executed by the MPT firmware. Call our routine which does
2114 * this. Only allow one passthru IOCTL at one time.
2116 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2118 case MPTIOCTL_GET_ADAPTER_DATA:
2120 * The user has requested to read adapter data. Call our
2121 * routine which does this.
2124 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2126 case MPTIOCTL_GET_PCI_INFO:
2128 * The user has requested to read pci info. Call
2129 * our routine which does this.
2133 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2136 case MPTIOCTL_RESET_ADAPTER:
2138 sc->port_enable_complete = 0;
2139 error = mps_reinit(sc);
2142 * Wait no more than 5 minutes for Port Enable to complete
2144 for (reset_loop = 0; (reset_loop < MPS_DIAG_RESET_TIMEOUT) &&
2145 (!sc->port_enable_complete); reset_loop++) {
2148 if (reset_loop == MPS_DIAG_RESET_TIMEOUT) {
2149 printf("Port Enable did not complete after Diag "
2153 case MPTIOCTL_DIAG_ACTION:
2155 * The user has done a diag buffer action. Call our routine
2156 * which does this. Only allow one diag action at one time.
2159 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2162 case MPTIOCTL_EVENT_QUERY:
2164 * The user has done an event query. Call our routine which does
2168 mps_user_event_query(sc, (mps_event_query_t *)arg);
2170 case MPTIOCTL_EVENT_ENABLE:
2172 * The user has done an event enable. Call our routine which
2176 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2178 case MPTIOCTL_EVENT_REPORT:
2180 * The user has done an event report. Call our routine which
2183 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2185 case MPTIOCTL_REG_ACCESS:
2187 * The user has requested register access. Call our routine
2191 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2194 case MPTIOCTL_BTDH_MAPPING:
2196 * The user has requested to translate a bus/target to a
2197 * DevHandle or a DevHandle to a bus/target. Call our routine
2200 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2207 if (mps_page != NULL)
2208 free(mps_page, M_MPSUSER);
2213 #ifdef COMPAT_FREEBSD32
2215 struct mps_cfg_page_req32 {
2216 MPI2_CONFIG_PAGE_HEADER header;
2217 uint32_t page_address;
2220 uint16_t ioc_status;
2223 struct mps_ext_cfg_page_req32 {
2224 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2225 uint32_t page_address;
2228 uint16_t ioc_status;
2231 struct mps_raid_action32 {
2235 uint8_t phys_disk_num;
2236 uint32_t action_data_word;
2239 uint32_t volume_status;
2240 uint32_t action_data[4];
2241 uint16_t action_status;
2242 uint16_t ioc_status;
2246 struct mps_usr_command32 {
2256 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2257 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2258 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2259 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2260 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2261 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2262 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2265 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2268 struct mps_cfg_page_req32 *page32 = _arg;
2269 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2270 struct mps_raid_action32 *raid32 = _arg;
2271 struct mps_usr_command32 *user32 = _arg;
2273 struct mps_cfg_page_req page;
2274 struct mps_ext_cfg_page_req ext;
2275 struct mps_raid_action raid;
2276 struct mps_usr_command user;
2282 case MPSIO_READ_CFG_HEADER32:
2283 case MPSIO_READ_CFG_PAGE32:
2284 case MPSIO_WRITE_CFG_PAGE32:
2285 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2286 cmd = MPSIO_READ_CFG_HEADER;
2287 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2288 cmd = MPSIO_READ_CFG_PAGE;
2290 cmd = MPSIO_WRITE_CFG_PAGE;
2291 CP(*page32, arg.page, header);
2292 CP(*page32, arg.page, page_address);
2293 PTRIN_CP(*page32, arg.page, buf);
2294 CP(*page32, arg.page, len);
2295 CP(*page32, arg.page, ioc_status);
2298 case MPSIO_READ_EXT_CFG_HEADER32:
2299 case MPSIO_READ_EXT_CFG_PAGE32:
2300 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2301 cmd = MPSIO_READ_EXT_CFG_HEADER;
2303 cmd = MPSIO_READ_EXT_CFG_PAGE;
2304 CP(*ext32, arg.ext, header);
2305 CP(*ext32, arg.ext, page_address);
2306 PTRIN_CP(*ext32, arg.ext, buf);
2307 CP(*ext32, arg.ext, len);
2308 CP(*ext32, arg.ext, ioc_status);
2311 case MPSIO_RAID_ACTION32:
2312 cmd = MPSIO_RAID_ACTION;
2313 CP(*raid32, arg.raid, action);
2314 CP(*raid32, arg.raid, volume_bus);
2315 CP(*raid32, arg.raid, volume_id);
2316 CP(*raid32, arg.raid, phys_disk_num);
2317 CP(*raid32, arg.raid, action_data_word);
2318 PTRIN_CP(*raid32, arg.raid, buf);
2319 CP(*raid32, arg.raid, len);
2320 CP(*raid32, arg.raid, volume_status);
2321 bcopy(raid32->action_data, arg.raid.action_data,
2322 sizeof arg.raid.action_data);
2323 CP(*raid32, arg.raid, ioc_status);
2324 CP(*raid32, arg.raid, write);
2327 case MPSIO_MPS_COMMAND32:
2328 cmd = MPSIO_MPS_COMMAND;
2329 PTRIN_CP(*user32, arg.user, req);
2330 CP(*user32, arg.user, req_len);
2331 PTRIN_CP(*user32, arg.user, rpl);
2332 CP(*user32, arg.user, rpl_len);
2333 PTRIN_CP(*user32, arg.user, buf);
2334 CP(*user32, arg.user, len);
2335 CP(*user32, arg.user, flags);
2341 error = mps_ioctl(dev, cmd, &arg, flag, td);
2342 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2344 case MPSIO_READ_CFG_HEADER32:
2345 case MPSIO_READ_CFG_PAGE32:
2346 case MPSIO_WRITE_CFG_PAGE32:
2347 CP(arg.page, *page32, header);
2348 CP(arg.page, *page32, page_address);
2349 PTROUT_CP(arg.page, *page32, buf);
2350 CP(arg.page, *page32, len);
2351 CP(arg.page, *page32, ioc_status);
2354 case MPSIO_READ_EXT_CFG_HEADER32:
2355 case MPSIO_READ_EXT_CFG_PAGE32:
2356 CP(arg.ext, *ext32, header);
2357 CP(arg.ext, *ext32, page_address);
2358 PTROUT_CP(arg.ext, *ext32, buf);
2359 CP(arg.ext, *ext32, len);
2360 CP(arg.ext, *ext32, ioc_status);
2363 case MPSIO_RAID_ACTION32:
2364 CP(arg.raid, *raid32, action);
2365 CP(arg.raid, *raid32, volume_bus);
2366 CP(arg.raid, *raid32, volume_id);
2367 CP(arg.raid, *raid32, phys_disk_num);
2368 CP(arg.raid, *raid32, action_data_word);
2369 PTROUT_CP(arg.raid, *raid32, buf);
2370 CP(arg.raid, *raid32, len);
2371 CP(arg.raid, *raid32, volume_status);
2372 bcopy(arg.raid.action_data, raid32->action_data,
2373 sizeof arg.raid.action_data);
2374 CP(arg.raid, *raid32, ioc_status);
2375 CP(arg.raid, *raid32, write);
2378 case MPSIO_MPS_COMMAND32:
2379 PTROUT_CP(arg.user, *user32, req);
2380 CP(arg.user, *user32, req_len);
2381 PTROUT_CP(arg.user, *user32, rpl);
2382 CP(arg.user, *user32, rpl_len);
2383 PTROUT_CP(arg.user, *user32, buf);
2384 CP(arg.user, *user32, len);
2385 CP(arg.user, *user32, flags);
2392 #endif /* COMPAT_FREEBSD32 */
2395 mps_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2398 #ifdef COMPAT_FREEBSD32
2399 if (SV_CURPROC_FLAG(SV_ILP32))
2400 return (mps_ioctl32(dev, com, arg, flag, td));
2402 return (mps_ioctl(dev, com, arg, flag, td));