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, 2012 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 mps_printf(sc, "Cannot allocate memory %s %d\n",
710 cm->cm_length = cmd->len;
716 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
717 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
720 err = mps_wait_command(sc, cm, 30);
723 mps_printf(sc, "%s: invalid request: error %d\n",
728 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
729 sz = rpl->MsgLength * 4;
731 if (sz > cmd->rpl_len) {
733 "mps_user_command: reply buffer too small %d required %d\n",
740 copyout(rpl, cmd->rpl, sz);
742 copyout(buf, cmd->buf, cmd->len);
743 mps_dprint(sc, MPS_INFO, "mps_user_command: reply size %d\n", sz );
748 mps_free_command(sc, cm);
752 free(buf, M_MPSUSER);
757 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
759 MPI2_REQUEST_HEADER *hdr, tmphdr;
760 MPI2_DEFAULT_REPLY *rpl;
761 struct mps_command *cm = NULL;
762 int err = 0, dir = 0, sz;
763 uint8_t function = 0;
767 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
768 * bit to denote that a passthru is being processed.
771 if (sc->mps_flags & MPS_FLAGS_BUSY) {
772 mps_dprint(sc, MPS_INFO, "%s: Only one passthru command "
773 "allowed at a single time.", __func__);
777 sc->mps_flags |= MPS_FLAGS_BUSY;
781 * Do some validation on data direction. Valid cases are:
782 * 1) DataSize is 0 and direction is NONE
783 * 2) DataSize is non-zero and one of:
784 * a) direction is READ or
785 * b) direction is WRITE or
786 * c) direction is BOTH and DataOutSize is non-zero
787 * If valid and the direction is BOTH, change the direction to READ.
788 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
790 if (((data->DataSize == 0) &&
791 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
792 ((data->DataSize != 0) &&
793 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
794 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
795 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
796 (data->DataOutSize != 0))))) {
797 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
798 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
800 data->DataOutSize = 0;
804 mps_dprint(sc, MPS_INFO, "%s: req 0x%jx %d rpl 0x%jx %d "
805 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
806 data->PtrRequest, data->RequestSize, data->PtrReply,
807 data->ReplySize, data->PtrData, data->DataSize,
808 data->PtrDataOut, data->DataOutSize, data->DataDirection);
811 * copy in the header so we know what we're dealing with before we
812 * commit to allocating a command for it.
814 err = copyin(PTRIN(data->PtrRequest), &tmphdr, data->RequestSize);
816 goto RetFreeUnlocked;
818 if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
820 goto RetFreeUnlocked;
823 function = tmphdr.Function;
824 mps_dprint(sc, MPS_INFO, "%s: Function %02X MsgFlags %02X\n", __func__,
825 function, tmphdr.MsgFlags);
828 * Handle a passthru TM request.
830 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
831 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
834 cm = mpssas_alloc_tm(sc);
840 /* Copy the header in. Only a small fixup is needed. */
841 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
842 bcopy(&tmphdr, task, data->RequestSize);
843 task->TaskMID = cm->cm_desc.Default.SMID;
846 cm->cm_desc.HighPriority.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
847 cm->cm_complete = NULL;
848 cm->cm_complete_data = NULL;
850 err = mps_wait_command(sc, cm, 30);
854 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
858 * Copy the reply data and sense data to user space.
860 if (cm->cm_reply != NULL) {
861 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
862 sz = rpl->MsgLength * 4;
864 if (sz > data->ReplySize) {
865 mps_printf(sc, "%s: reply buffer too small: %d, "
866 "required: %d\n", __func__, data->ReplySize, sz);
870 copyout(cm->cm_reply, PTRIN(data->PtrReply),
875 mpssas_free_tm(sc, cm);
880 cm = mps_alloc_command(sc);
883 mps_printf(sc, "%s: no mps requests\n", __func__);
889 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
890 bcopy(&tmphdr, hdr, data->RequestSize);
893 * Do some checking to make sure the IOCTL request contains a valid
894 * request. Then set the SGL info.
896 mpi_init_sge(cm, hdr, (void *)((uint8_t *)hdr + data->RequestSize));
899 * Set up for read, write or both. From check above, DataOutSize will
900 * be 0 if direction is READ or WRITE, but it will have some non-zero
901 * value if the direction is BOTH. So, just use the biggest size to get
902 * the cm_data buffer size. If direction is BOTH, 2 SGLs need to be set
903 * up; the first is for the request and the second will contain the
904 * response data. cm_out_len needs to be set here and this will be used
905 * when the SGLs are set up.
908 cm->cm_length = MAX(data->DataSize, data->DataOutSize);
909 cm->cm_out_len = data->DataOutSize;
911 if (cm->cm_length != 0) {
912 cm->cm_data = malloc(cm->cm_length, M_MPSUSER, M_WAITOK |
914 if (cm->cm_data == NULL) {
915 mps_dprint(sc, MPS_FAULT, "%s: alloc failed for IOCTL "
916 "passthru length %d\n", __func__, cm->cm_length);
918 cm->cm_flags = MPS_CM_FLAGS_DATAIN;
919 if (data->DataOutSize) {
920 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
921 err = copyin(PTRIN(data->PtrDataOut),
922 cm->cm_data, data->DataOutSize);
923 } else if (data->DataDirection ==
924 MPS_PASS_THRU_DIRECTION_WRITE) {
925 cm->cm_flags = MPS_CM_FLAGS_DATAOUT;
926 err = copyin(PTRIN(data->PtrData),
927 cm->cm_data, data->DataSize);
930 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
931 "IOCTL data from user space\n", __func__);
934 cm->cm_flags |= MPS_CM_FLAGS_SGE_SIMPLE;
935 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
938 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
939 * uses SCSI IO descriptor.
941 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
942 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
943 MPI2_SCSI_IO_REQUEST *scsi_io_req;
945 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
947 * Put SGE for data and data_out buffer at the end of
948 * scsi_io_request message header (64 bytes in total).
949 * Following above SGEs, the residual space will be used by
952 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
954 scsi_io_req->SenseBufferLowAddress = htole32(cm->cm_sense_busaddr);
957 * Set SGLOffset0 value. This is the number of dwords that SGL
958 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
960 scsi_io_req->SGLOffset0 = 24;
963 * Setup descriptor info. RAID passthrough must use the
964 * default request descriptor which is already set, so if this
965 * is a SCSI IO request, change the descriptor to SCSI IO.
966 * Also, if this is a SCSI IO request, handle the reply in the
967 * mpssas_scsio_complete function.
969 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
970 cm->cm_desc.SCSIIO.RequestFlags =
971 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
972 cm->cm_desc.SCSIIO.DevHandle = scsi_io_req->DevHandle;
975 * Make sure the DevHandle is not 0 because this is a
978 if (scsi_io_req->DevHandle == 0) {
980 goto RetFreeUnlocked;
987 err = mps_wait_command(sc, cm, 30);
990 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
993 goto RetFreeUnlocked;
997 * Sync the DMA data, if any. Then copy the data to user space.
999 if (cm->cm_data != NULL) {
1000 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN)
1001 dir = BUS_DMASYNC_POSTREAD;
1002 else if (cm->cm_flags & MPS_CM_FLAGS_DATAOUT)
1003 dir = BUS_DMASYNC_POSTWRITE;;
1004 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
1005 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
1007 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN) {
1009 err = copyout(cm->cm_data,
1010 PTRIN(data->PtrData), data->DataSize);
1013 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1014 "IOCTL data to user space\n", __func__);
1019 * Copy the reply data and sense data to user space.
1021 if (cm->cm_reply != NULL) {
1022 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1023 sz = rpl->MsgLength * 4;
1025 if (sz > data->ReplySize) {
1026 mps_printf(sc, "%s: reply buffer too small: %d, "
1027 "required: %d\n", __func__, data->ReplySize, sz);
1031 copyout(cm->cm_reply, PTRIN(data->PtrReply),
1036 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1037 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1038 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1039 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1041 MIN((le32toh(((MPI2_SCSI_IO_REPLY *)rpl)->SenseCount)),
1042 sizeof(struct scsi_sense_data));
1044 copyout(cm->cm_sense, cm->cm_req + 64, sense_len);
1056 free(cm->cm_data, M_MPSUSER);
1057 mps_free_command(sc, cm);
1060 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1067 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1069 Mpi2ConfigReply_t mpi_reply;
1070 Mpi2BiosPage3_t config_page;
1073 * Use the PCI interface functions to get the Bus, Device, and Function
1076 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1077 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1078 data->PciInformation.u.bits.FunctionNumber =
1079 pci_get_function(sc->mps_dev);
1082 * Get the FW version that should already be saved in IOC Facts.
1084 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1087 * General device info.
1089 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1090 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1091 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1092 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1093 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1094 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1095 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1098 * Get the driver version.
1100 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1103 * Need to get BIOS Config Page 3 for the BIOS Version.
1105 data->BiosVersion = 0;
1107 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1108 printf("%s: Error while retrieving BIOS Version\n", __func__);
1110 data->BiosVersion = config_page.BiosVersion;
1115 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1120 * Use the PCI interface functions to get the Bus, Device, and Function
1123 data->BusNumber = pci_get_bus(sc->mps_dev);
1124 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1125 data->FunctionNumber = pci_get_function(sc->mps_dev);
1128 * Now get the interrupt vector and the pci header. The vector can
1129 * only be 0 right now. The header is the first 256 bytes of config
1132 data->InterruptVector = 0;
1133 for (i = 0; i < sizeof (data->PciHeader); i++) {
1134 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1139 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1143 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1144 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1149 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1153 mps_post_fw_diag_buffer(struct mps_softc *sc,
1154 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1156 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1157 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1158 struct mps_command *cm = NULL;
1162 * If buffer is not enabled, just leave.
1164 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1165 if (!pBuffer->enabled) {
1166 return (MPS_DIAG_FAILURE);
1170 * Clear some flags initially.
1172 pBuffer->force_release = FALSE;
1173 pBuffer->valid_data = FALSE;
1174 pBuffer->owned_by_firmware = FALSE;
1179 cm = mps_alloc_command(sc);
1181 mps_printf(sc, "%s: no mps requests\n", __func__);
1182 return (MPS_DIAG_FAILURE);
1186 * Build the request for releasing the FW Diag Buffer and send it.
1188 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1189 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1190 req->BufferType = pBuffer->buffer_type;
1191 req->ExtendedType = pBuffer->extended_type;
1192 req->BufferLength = pBuffer->size;
1193 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1194 req->ProductSpecific[i] = pBuffer->product_specific[i];
1195 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1198 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1199 cm->cm_complete_data = NULL;
1202 * Send command synchronously.
1204 status = mps_wait_command(sc, cm, 30);
1206 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1208 status = MPS_DIAG_FAILURE;
1213 * Process POST reply.
1215 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1216 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1217 status = MPS_DIAG_FAILURE;
1218 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1219 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1220 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1221 reply->IOCLogInfo, reply->TransferLength);
1226 * Post was successful.
1228 pBuffer->valid_data = TRUE;
1229 pBuffer->owned_by_firmware = TRUE;
1230 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1231 status = MPS_DIAG_SUCCESS;
1234 mps_free_command(sc, cm);
1239 mps_release_fw_diag_buffer(struct mps_softc *sc,
1240 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1243 MPI2_DIAG_RELEASE_REQUEST *req;
1244 MPI2_DIAG_RELEASE_REPLY *reply;
1245 struct mps_command *cm = NULL;
1249 * If buffer is not enabled, just leave.
1251 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1252 if (!pBuffer->enabled) {
1253 mps_dprint(sc, MPS_INFO, "%s: This buffer type is not supported "
1254 "by the IOC", __func__);
1255 return (MPS_DIAG_FAILURE);
1259 * Clear some flags initially.
1261 pBuffer->force_release = FALSE;
1262 pBuffer->valid_data = FALSE;
1263 pBuffer->owned_by_firmware = FALSE;
1268 cm = mps_alloc_command(sc);
1270 mps_printf(sc, "%s: no mps requests\n", __func__);
1271 return (MPS_DIAG_FAILURE);
1275 * Build the request for releasing the FW Diag Buffer and send it.
1277 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1278 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1279 req->BufferType = pBuffer->buffer_type;
1282 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1283 cm->cm_complete_data = NULL;
1286 * Send command synchronously.
1288 status = mps_wait_command(sc, cm, 30);
1290 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1292 status = MPS_DIAG_FAILURE;
1297 * Process RELEASE reply.
1299 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1300 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1301 pBuffer->owned_by_firmware) {
1302 status = MPS_DIAG_FAILURE;
1303 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1304 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1305 __func__, reply->IOCStatus, reply->IOCLogInfo);
1310 * Release was successful.
1312 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1313 status = MPS_DIAG_SUCCESS;
1316 * If this was for an UNREGISTER diag type command, clear the unique ID.
1318 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1319 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1327 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1328 uint32_t *return_code)
1330 mps_fw_diagnostic_buffer_t *pBuffer;
1331 uint8_t extended_type, buffer_type, i;
1332 uint32_t buffer_size;
1336 extended_type = diag_register->ExtendedType;
1337 buffer_type = diag_register->BufferType;
1338 buffer_size = diag_register->RequestedBufferSize;
1339 unique_id = diag_register->UniqueId;
1342 * Check for valid buffer type
1344 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1345 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1346 return (MPS_DIAG_FAILURE);
1350 * Get the current buffer and look up the unique ID. The unique ID
1351 * should not be found. If it is, the ID is already in use.
1353 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1354 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1355 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1356 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1357 return (MPS_DIAG_FAILURE);
1361 * The buffer's unique ID should not be registered yet, and the given
1362 * unique ID cannot be 0.
1364 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1365 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1366 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1367 return (MPS_DIAG_FAILURE);
1371 * If this buffer is already posted as immediate, just change owner.
1373 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1374 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1375 pBuffer->immediate = FALSE;
1376 pBuffer->unique_id = unique_id;
1377 return (MPS_DIAG_SUCCESS);
1381 * Post a new buffer after checking if it's enabled. The DMA buffer
1382 * that is allocated will be contiguous (nsegments = 1).
1384 if (!pBuffer->enabled) {
1385 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1386 return (MPS_DIAG_FAILURE);
1388 if (bus_dma_tag_create( sc->mps_parent_dmat, /* parent */
1389 1, 0, /* algnmnt, boundary */
1390 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1391 BUS_SPACE_MAXADDR, /* highaddr */
1392 NULL, NULL, /* filter, filterarg */
1393 buffer_size, /* maxsize */
1395 buffer_size, /* maxsegsize */
1397 NULL, NULL, /* lockfunc, lockarg */
1398 &sc->fw_diag_dmat)) {
1399 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer DMA "
1403 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1404 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1405 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer "
1409 bzero(sc->fw_diag_buffer, buffer_size);
1410 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1411 buffer_size, mps_memaddr_cb, &sc->fw_diag_busaddr, 0);
1412 pBuffer->size = buffer_size;
1415 * Copy the given info to the diag buffer and post the buffer.
1417 pBuffer->buffer_type = buffer_type;
1418 pBuffer->immediate = FALSE;
1419 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1420 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1422 pBuffer->product_specific[i] =
1423 diag_register->ProductSpecific[i];
1426 pBuffer->extended_type = extended_type;
1427 pBuffer->unique_id = unique_id;
1428 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1431 * In case there was a failure, free the DMA buffer.
1433 if (status == MPS_DIAG_FAILURE) {
1434 if (sc->fw_diag_busaddr != 0)
1435 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1436 if (sc->fw_diag_buffer != NULL)
1437 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1439 if (sc->fw_diag_dmat != NULL)
1440 bus_dma_tag_destroy(sc->fw_diag_dmat);
1447 mps_diag_unregister(struct mps_softc *sc,
1448 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1450 mps_fw_diagnostic_buffer_t *pBuffer;
1455 unique_id = diag_unregister->UniqueId;
1458 * Get the current buffer and look up the unique ID. The unique ID
1461 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1462 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1463 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1464 return (MPS_DIAG_FAILURE);
1467 pBuffer = &sc->fw_diag_buffer_list[i];
1470 * Try to release the buffer from FW before freeing it. If release
1471 * fails, don't free the DMA buffer in case FW tries to access it
1472 * later. If buffer is not owned by firmware, can't release it.
1474 if (!pBuffer->owned_by_firmware) {
1475 status = MPS_DIAG_SUCCESS;
1477 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1478 MPS_FW_DIAG_TYPE_UNREGISTER);
1482 * At this point, return the current status no matter what happens with
1485 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1486 if (status == MPS_DIAG_SUCCESS) {
1487 if (sc->fw_diag_busaddr != 0)
1488 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1489 if (sc->fw_diag_buffer != NULL)
1490 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1492 if (sc->fw_diag_dmat != NULL)
1493 bus_dma_tag_destroy(sc->fw_diag_dmat);
1500 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1501 uint32_t *return_code)
1503 mps_fw_diagnostic_buffer_t *pBuffer;
1507 unique_id = diag_query->UniqueId;
1510 * If ID is valid, query on ID.
1511 * If ID is invalid, query on buffer type.
1513 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1514 i = diag_query->BufferType;
1515 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1516 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1517 return (MPS_DIAG_FAILURE);
1520 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1521 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1522 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1523 return (MPS_DIAG_FAILURE);
1528 * Fill query structure with the diag buffer info.
1530 pBuffer = &sc->fw_diag_buffer_list[i];
1531 diag_query->BufferType = pBuffer->buffer_type;
1532 diag_query->ExtendedType = pBuffer->extended_type;
1533 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1534 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1536 diag_query->ProductSpecific[i] =
1537 pBuffer->product_specific[i];
1540 diag_query->TotalBufferSize = pBuffer->size;
1541 diag_query->DriverAddedBufferSize = 0;
1542 diag_query->UniqueId = pBuffer->unique_id;
1543 diag_query->ApplicationFlags = 0;
1544 diag_query->DiagnosticFlags = 0;
1547 * Set/Clear application flags
1549 if (pBuffer->immediate) {
1550 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1552 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1554 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1555 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1557 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1559 if (pBuffer->owned_by_firmware) {
1560 diag_query->ApplicationFlags |=
1561 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1563 diag_query->ApplicationFlags &=
1564 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1567 return (MPS_DIAG_SUCCESS);
1571 mps_diag_read_buffer(struct mps_softc *sc,
1572 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1573 uint32_t *return_code)
1575 mps_fw_diagnostic_buffer_t *pBuffer;
1580 unique_id = diag_read_buffer->UniqueId;
1583 * Get the current buffer and look up the unique ID. The unique ID
1586 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1587 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1588 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1589 return (MPS_DIAG_FAILURE);
1592 pBuffer = &sc->fw_diag_buffer_list[i];
1595 * Make sure requested read is within limits
1597 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1599 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1600 return (MPS_DIAG_FAILURE);
1604 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1605 * buffer that was allocated is one contiguous buffer.
1607 pData = (uint8_t *)(sc->fw_diag_buffer +
1608 diag_read_buffer->StartingOffset);
1609 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1610 return (MPS_DIAG_FAILURE);
1611 diag_read_buffer->Status = 0;
1614 * Set or clear the Force Release flag.
1616 if (pBuffer->force_release) {
1617 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1619 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1623 * If buffer is to be reregistered, make sure it's not already owned by
1626 status = MPS_DIAG_SUCCESS;
1627 if (!pBuffer->owned_by_firmware) {
1628 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1629 status = mps_post_fw_diag_buffer(sc, pBuffer,
1638 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1639 uint32_t *return_code)
1641 mps_fw_diagnostic_buffer_t *pBuffer;
1646 unique_id = diag_release->UniqueId;
1649 * Get the current buffer and look up the unique ID. The unique ID
1652 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1653 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1654 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1655 return (MPS_DIAG_FAILURE);
1658 pBuffer = &sc->fw_diag_buffer_list[i];
1661 * If buffer is not owned by firmware, it's already been released.
1663 if (!pBuffer->owned_by_firmware) {
1664 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1665 return (MPS_DIAG_FAILURE);
1669 * Release the buffer.
1671 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1672 MPS_FW_DIAG_TYPE_RELEASE);
1677 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1678 uint32_t length, uint32_t *return_code)
1680 mps_fw_diag_register_t diag_register;
1681 mps_fw_diag_unregister_t diag_unregister;
1682 mps_fw_diag_query_t diag_query;
1683 mps_diag_read_buffer_t diag_read_buffer;
1684 mps_fw_diag_release_t diag_release;
1685 int status = MPS_DIAG_SUCCESS;
1686 uint32_t original_return_code;
1688 original_return_code = *return_code;
1689 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1692 case MPS_FW_DIAG_TYPE_REGISTER:
1695 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1696 status = MPS_DIAG_FAILURE;
1699 if (copyin(diag_action, &diag_register,
1700 sizeof(diag_register)) != 0)
1701 return (MPS_DIAG_FAILURE);
1702 status = mps_diag_register(sc, &diag_register,
1706 case MPS_FW_DIAG_TYPE_UNREGISTER:
1707 if (length < sizeof(diag_unregister)) {
1709 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1710 status = MPS_DIAG_FAILURE;
1713 if (copyin(diag_action, &diag_unregister,
1714 sizeof(diag_unregister)) != 0)
1715 return (MPS_DIAG_FAILURE);
1716 status = mps_diag_unregister(sc, &diag_unregister,
1720 case MPS_FW_DIAG_TYPE_QUERY:
1721 if (length < sizeof (diag_query)) {
1723 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1724 status = MPS_DIAG_FAILURE;
1727 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1729 return (MPS_DIAG_FAILURE);
1730 status = mps_diag_query(sc, &diag_query, return_code);
1731 if (status == MPS_DIAG_SUCCESS)
1732 if (copyout(&diag_query, diag_action,
1733 sizeof (diag_query)) != 0)
1734 return (MPS_DIAG_FAILURE);
1737 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1738 if (copyin(diag_action, &diag_read_buffer,
1739 sizeof(diag_read_buffer)) != 0)
1740 return (MPS_DIAG_FAILURE);
1741 if (length < diag_read_buffer.BytesToRead) {
1743 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1744 status = MPS_DIAG_FAILURE;
1747 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1748 PTRIN(diag_read_buffer.PtrDataBuffer),
1750 if (status == MPS_DIAG_SUCCESS) {
1751 if (copyout(&diag_read_buffer, diag_action,
1752 sizeof(diag_read_buffer) -
1753 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1755 return (MPS_DIAG_FAILURE);
1759 case MPS_FW_DIAG_TYPE_RELEASE:
1760 if (length < sizeof(diag_release)) {
1762 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1763 status = MPS_DIAG_FAILURE;
1766 if (copyin(diag_action, &diag_release,
1767 sizeof(diag_release)) != 0)
1768 return (MPS_DIAG_FAILURE);
1769 status = mps_diag_release(sc, &diag_release,
1774 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1775 status = MPS_DIAG_FAILURE;
1779 if ((status == MPS_DIAG_FAILURE) &&
1780 (original_return_code == MPS_FW_DIAG_NEW) &&
1781 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1782 status = MPS_DIAG_SUCCESS;
1788 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1793 * Only allow one diag action at one time.
1795 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1796 mps_dprint(sc, MPS_INFO, "%s: Only one FW diag command "
1797 "allowed at a single time.", __func__);
1800 sc->mps_flags |= MPS_FLAGS_BUSY;
1803 * Send diag action request
1805 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1806 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1807 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1808 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1809 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1810 status = mps_do_diag_action(sc, data->Action,
1811 PTRIN(data->PtrDiagAction), data->Length,
1816 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1821 * Copy the event recording mask and the event queue size out. For
1822 * clarification, the event recording mask (events_to_record) is not the same
1823 * thing as the event mask (event_mask). events_to_record has a bit set for
1824 * every event type that is to be recorded by the driver, and event_mask has a
1825 * bit cleared for every event that is allowed into the driver from the IOC.
1826 * They really have nothing to do with each other.
1829 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1834 data->Entries = MPS_EVENT_QUEUE_SIZE;
1836 for (i = 0; i < 4; i++) {
1837 data->Types[i] = sc->events_to_record[i];
1843 * Set the driver's event mask according to what's been given. See
1844 * mps_user_event_query for explanation of the event recording mask and the IOC
1845 * event mask. It's the app's responsibility to enable event logging by setting
1846 * the bits in events_to_record. Initially, no events will be logged.
1849 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1854 for (i = 0; i < 4; i++) {
1855 sc->events_to_record[i] = data->Types[i];
1861 * Copy out the events that have been recorded, up to the max events allowed.
1864 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1871 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1873 if (copyout((void *)sc->recorded_events,
1874 PTRIN(data->PtrEvents), size) != 0)
1879 * data->Size value is not large enough to copy event data.
1885 * Change size value to match the number of bytes that were copied.
1888 data->Size = sizeof(sc->recorded_events);
1895 * Record events into the driver from the IOC if they are not masked.
1898 mpssas_record_event(struct mps_softc *sc,
1899 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1903 uint16_t event_data_len;
1904 boolean_t sendAEN = FALSE;
1906 event = event_reply->Event;
1909 * Generate a system event to let anyone who cares know that a
1910 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1911 * event mask is set to.
1913 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1918 * Record the event only if its corresponding bit is set in
1919 * events_to_record. event_index is the index into recorded_events and
1920 * event_number is the overall number of an event being recorded since
1921 * start-of-day. event_index will roll over; event_number will never
1924 i = (uint8_t)(event / 32);
1925 j = (uint8_t)(event % 32);
1926 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1927 i = sc->event_index;
1928 sc->recorded_events[i].Type = event;
1929 sc->recorded_events[i].Number = ++sc->event_number;
1930 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
1932 event_data_len = event_reply->EventDataLength;
1934 if (event_data_len > 0) {
1936 * Limit data to size in m_event entry
1938 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
1939 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
1941 for (j = 0; j < event_data_len; j++) {
1942 sc->recorded_events[i].Data[j] =
1943 event_reply->EventData[j];
1947 * check for index wrap-around
1949 if (++i == MPS_EVENT_QUEUE_SIZE) {
1952 sc->event_index = (uint8_t)i;
1955 * Set flag to send the event.
1962 * Generate a system event if flag is set to let anyone who cares know
1963 * that an event has occurred.
1966 //SLM-how to send a system event (see kqueue, kevent)
1967 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
1968 // "SAS", NULL, NULL, DDI_NOSLEEP);
1973 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
1977 switch (data->Command) {
1979 * IO access is not supported.
1983 mps_dprint(sc, MPS_INFO, "IO access is not supported. "
1984 "Use memory access.");
1989 data->RegData = mps_regread(sc, data->RegOffset);
1993 mps_regwrite(sc, data->RegOffset, data->RegData);
2005 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
2007 uint8_t bt2dh = FALSE;
2008 uint8_t dh2bt = FALSE;
2009 uint16_t dev_handle, bus, target;
2012 target = data->TargetID;
2013 dev_handle = data->DevHandle;
2016 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2017 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2018 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2021 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2023 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2025 if (!dh2bt && !bt2dh)
2029 * Only handle bus of 0. Make sure target is within range.
2035 if (target > sc->max_devices) {
2036 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2037 "for Bus/Target to DevHandle mapping.");
2040 dev_handle = sc->mapping_table[target].dev_handle;
2042 data->DevHandle = dev_handle;
2045 target = mps_mapping_get_sas_id_from_handle(sc, dev_handle);
2047 data->TargetID = target;
2054 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2057 struct mps_softc *sc;
2058 struct mps_cfg_page_req *page_req;
2059 struct mps_ext_cfg_page_req *ext_page_req;
2061 int error, msleep_ret;
2065 page_req = (void *)arg;
2066 ext_page_req = (void *)arg;
2069 case MPSIO_READ_CFG_HEADER:
2071 error = mps_user_read_cfg_header(sc, page_req);
2074 case MPSIO_READ_CFG_PAGE:
2075 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2077 mps_printf(sc, "Cannot allocate memory %s %d\n",
2078 __func__, __LINE__);
2081 error = copyin(page_req->buf, mps_page,
2082 sizeof(MPI2_CONFIG_PAGE_HEADER));
2086 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2090 error = copyout(mps_page, page_req->buf, page_req->len);
2092 case MPSIO_READ_EXT_CFG_HEADER:
2094 error = mps_user_read_extcfg_header(sc, ext_page_req);
2097 case MPSIO_READ_EXT_CFG_PAGE:
2098 mps_page = malloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2100 mps_printf(sc, "Cannot allocate memory %s %d\n",
2101 __func__, __LINE__);
2104 error = copyin(ext_page_req->buf, mps_page,
2105 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2109 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2113 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2115 case MPSIO_WRITE_CFG_PAGE:
2116 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2118 mps_printf(sc, "Cannot allocate memory %s %d\n",
2119 __func__, __LINE__);
2122 error = copyin(page_req->buf, mps_page, page_req->len);
2126 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2129 case MPSIO_MPS_COMMAND:
2130 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2132 case MPTIOCTL_PASS_THRU:
2134 * The user has requested to pass through a command to be
2135 * executed by the MPT firmware. Call our routine which does
2136 * this. Only allow one passthru IOCTL at one time.
2138 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2140 case MPTIOCTL_GET_ADAPTER_DATA:
2142 * The user has requested to read adapter data. Call our
2143 * routine which does this.
2146 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2148 case MPTIOCTL_GET_PCI_INFO:
2150 * The user has requested to read pci info. Call
2151 * our routine which does this.
2155 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2158 case MPTIOCTL_RESET_ADAPTER:
2160 sc->port_enable_complete = 0;
2161 uint32_t reinit_start = time_uptime;
2162 error = mps_reinit(sc);
2163 /* Sleep for 300 second. */
2164 msleep_ret = msleep(&sc->port_enable_complete, &sc->mps_mtx, PRIBIO,
2165 "mps_porten", 300 * hz);
2168 printf("Port Enable did not complete after Diag "
2169 "Reset msleep error %d.\n", msleep_ret);
2171 mps_dprint(sc, MPS_INFO,
2172 "Hard Reset with Port Enable completed in %d seconds.\n",
2173 (uint32_t) (time_uptime - reinit_start));
2175 case MPTIOCTL_DIAG_ACTION:
2177 * The user has done a diag buffer action. Call our routine
2178 * which does this. Only allow one diag action at one time.
2181 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2184 case MPTIOCTL_EVENT_QUERY:
2186 * The user has done an event query. Call our routine which does
2190 mps_user_event_query(sc, (mps_event_query_t *)arg);
2192 case MPTIOCTL_EVENT_ENABLE:
2194 * The user has done an event enable. Call our routine which
2198 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2200 case MPTIOCTL_EVENT_REPORT:
2202 * The user has done an event report. Call our routine which
2205 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2207 case MPTIOCTL_REG_ACCESS:
2209 * The user has requested register access. Call our routine
2213 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2216 case MPTIOCTL_BTDH_MAPPING:
2218 * The user has requested to translate a bus/target to a
2219 * DevHandle or a DevHandle to a bus/target. Call our routine
2222 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2229 if (mps_page != NULL)
2230 free(mps_page, M_MPSUSER);
2235 #ifdef COMPAT_FREEBSD32
2237 struct mps_cfg_page_req32 {
2238 MPI2_CONFIG_PAGE_HEADER header;
2239 uint32_t page_address;
2242 uint16_t ioc_status;
2245 struct mps_ext_cfg_page_req32 {
2246 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2247 uint32_t page_address;
2250 uint16_t ioc_status;
2253 struct mps_raid_action32 {
2257 uint8_t phys_disk_num;
2258 uint32_t action_data_word;
2261 uint32_t volume_status;
2262 uint32_t action_data[4];
2263 uint16_t action_status;
2264 uint16_t ioc_status;
2268 struct mps_usr_command32 {
2278 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2279 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2280 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2281 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2282 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2283 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2284 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2287 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2290 struct mps_cfg_page_req32 *page32 = _arg;
2291 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2292 struct mps_raid_action32 *raid32 = _arg;
2293 struct mps_usr_command32 *user32 = _arg;
2295 struct mps_cfg_page_req page;
2296 struct mps_ext_cfg_page_req ext;
2297 struct mps_raid_action raid;
2298 struct mps_usr_command user;
2304 case MPSIO_READ_CFG_HEADER32:
2305 case MPSIO_READ_CFG_PAGE32:
2306 case MPSIO_WRITE_CFG_PAGE32:
2307 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2308 cmd = MPSIO_READ_CFG_HEADER;
2309 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2310 cmd = MPSIO_READ_CFG_PAGE;
2312 cmd = MPSIO_WRITE_CFG_PAGE;
2313 CP(*page32, arg.page, header);
2314 CP(*page32, arg.page, page_address);
2315 PTRIN_CP(*page32, arg.page, buf);
2316 CP(*page32, arg.page, len);
2317 CP(*page32, arg.page, ioc_status);
2320 case MPSIO_READ_EXT_CFG_HEADER32:
2321 case MPSIO_READ_EXT_CFG_PAGE32:
2322 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2323 cmd = MPSIO_READ_EXT_CFG_HEADER;
2325 cmd = MPSIO_READ_EXT_CFG_PAGE;
2326 CP(*ext32, arg.ext, header);
2327 CP(*ext32, arg.ext, page_address);
2328 PTRIN_CP(*ext32, arg.ext, buf);
2329 CP(*ext32, arg.ext, len);
2330 CP(*ext32, arg.ext, ioc_status);
2333 case MPSIO_RAID_ACTION32:
2334 cmd = MPSIO_RAID_ACTION;
2335 CP(*raid32, arg.raid, action);
2336 CP(*raid32, arg.raid, volume_bus);
2337 CP(*raid32, arg.raid, volume_id);
2338 CP(*raid32, arg.raid, phys_disk_num);
2339 CP(*raid32, arg.raid, action_data_word);
2340 PTRIN_CP(*raid32, arg.raid, buf);
2341 CP(*raid32, arg.raid, len);
2342 CP(*raid32, arg.raid, volume_status);
2343 bcopy(raid32->action_data, arg.raid.action_data,
2344 sizeof arg.raid.action_data);
2345 CP(*raid32, arg.raid, ioc_status);
2346 CP(*raid32, arg.raid, write);
2349 case MPSIO_MPS_COMMAND32:
2350 cmd = MPSIO_MPS_COMMAND;
2351 PTRIN_CP(*user32, arg.user, req);
2352 CP(*user32, arg.user, req_len);
2353 PTRIN_CP(*user32, arg.user, rpl);
2354 CP(*user32, arg.user, rpl_len);
2355 PTRIN_CP(*user32, arg.user, buf);
2356 CP(*user32, arg.user, len);
2357 CP(*user32, arg.user, flags);
2363 error = mps_ioctl(dev, cmd, &arg, flag, td);
2364 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2366 case MPSIO_READ_CFG_HEADER32:
2367 case MPSIO_READ_CFG_PAGE32:
2368 case MPSIO_WRITE_CFG_PAGE32:
2369 CP(arg.page, *page32, header);
2370 CP(arg.page, *page32, page_address);
2371 PTROUT_CP(arg.page, *page32, buf);
2372 CP(arg.page, *page32, len);
2373 CP(arg.page, *page32, ioc_status);
2376 case MPSIO_READ_EXT_CFG_HEADER32:
2377 case MPSIO_READ_EXT_CFG_PAGE32:
2378 CP(arg.ext, *ext32, header);
2379 CP(arg.ext, *ext32, page_address);
2380 PTROUT_CP(arg.ext, *ext32, buf);
2381 CP(arg.ext, *ext32, len);
2382 CP(arg.ext, *ext32, ioc_status);
2385 case MPSIO_RAID_ACTION32:
2386 CP(arg.raid, *raid32, action);
2387 CP(arg.raid, *raid32, volume_bus);
2388 CP(arg.raid, *raid32, volume_id);
2389 CP(arg.raid, *raid32, phys_disk_num);
2390 CP(arg.raid, *raid32, action_data_word);
2391 PTROUT_CP(arg.raid, *raid32, buf);
2392 CP(arg.raid, *raid32, len);
2393 CP(arg.raid, *raid32, volume_status);
2394 bcopy(arg.raid.action_data, raid32->action_data,
2395 sizeof arg.raid.action_data);
2396 CP(arg.raid, *raid32, ioc_status);
2397 CP(arg.raid, *raid32, write);
2400 case MPSIO_MPS_COMMAND32:
2401 PTROUT_CP(arg.user, *user32, req);
2402 CP(arg.user, *user32, req_len);
2403 PTROUT_CP(arg.user, *user32, rpl);
2404 CP(arg.user, *user32, rpl_len);
2405 PTROUT_CP(arg.user, *user32, buf);
2406 CP(arg.user, *user32, len);
2407 CP(arg.user, *user32, flags);
2414 #endif /* COMPAT_FREEBSD32 */
2417 mps_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2420 #ifdef COMPAT_FREEBSD32
2421 if (SV_CURPROC_FLAG(SV_ILP32))
2422 return (mps_ioctl32(dev, com, arg, flag, td));
2424 return (mps_ioctl(dev, com, arg, flag, td));