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/pci/pcivar.h>
105 #include <dev/pci/pcireg.h>
107 static d_open_t mps_open;
108 static d_close_t mps_close;
109 static d_ioctl_t mps_ioctl_devsw;
111 static struct cdevsw mps_cdevsw = {
112 .d_version = D_VERSION,
115 .d_close = mps_close,
116 .d_ioctl = mps_ioctl_devsw,
120 typedef int (mps_user_f)(struct mps_command *, struct mps_usr_command *);
121 static mps_user_f mpi_pre_ioc_facts;
122 static mps_user_f mpi_pre_port_facts;
123 static mps_user_f mpi_pre_fw_download;
124 static mps_user_f mpi_pre_fw_upload;
125 static mps_user_f mpi_pre_sata_passthrough;
126 static mps_user_f mpi_pre_smp_passthrough;
127 static mps_user_f mpi_pre_config;
128 static mps_user_f mpi_pre_sas_io_unit_control;
130 static int mps_user_read_cfg_header(struct mps_softc *,
131 struct mps_cfg_page_req *);
132 static int mps_user_read_cfg_page(struct mps_softc *,
133 struct mps_cfg_page_req *, void *);
134 static int mps_user_read_extcfg_header(struct mps_softc *,
135 struct mps_ext_cfg_page_req *);
136 static int mps_user_read_extcfg_page(struct mps_softc *,
137 struct mps_ext_cfg_page_req *, void *);
138 static int mps_user_write_cfg_page(struct mps_softc *,
139 struct mps_cfg_page_req *, void *);
140 static int mps_user_setup_request(struct mps_command *,
141 struct mps_usr_command *);
142 static int mps_user_command(struct mps_softc *, struct mps_usr_command *);
144 static int mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data);
145 static void mps_user_get_adapter_data(struct mps_softc *sc,
146 mps_adapter_data_t *data);
147 static void mps_user_read_pci_info(struct mps_softc *sc,
148 mps_pci_info_t *data);
149 static uint8_t mps_get_fw_diag_buffer_number(struct mps_softc *sc,
151 static int mps_post_fw_diag_buffer(struct mps_softc *sc,
152 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code);
153 static int mps_release_fw_diag_buffer(struct mps_softc *sc,
154 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
156 static int mps_diag_register(struct mps_softc *sc,
157 mps_fw_diag_register_t *diag_register, uint32_t *return_code);
158 static int mps_diag_unregister(struct mps_softc *sc,
159 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code);
160 static int mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
161 uint32_t *return_code);
162 static int mps_diag_read_buffer(struct mps_softc *sc,
163 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
164 uint32_t *return_code);
165 static int mps_diag_release(struct mps_softc *sc,
166 mps_fw_diag_release_t *diag_release, uint32_t *return_code);
167 static int mps_do_diag_action(struct mps_softc *sc, uint32_t action,
168 uint8_t *diag_action, uint32_t length, uint32_t *return_code);
169 static int mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data);
170 static void mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data);
171 static void mps_user_event_enable(struct mps_softc *sc,
172 mps_event_enable_t *data);
173 static int mps_user_event_report(struct mps_softc *sc,
174 mps_event_report_t *data);
175 static int mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data);
176 static int mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data);
178 static MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
180 /* Macros from compat/freebsd32/freebsd32.h */
181 #define PTRIN(v) (void *)(uintptr_t)(v)
182 #define PTROUT(v) (uint32_t)(uintptr_t)(v)
184 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
185 #define PTRIN_CP(src,dst,fld) \
186 do { (dst).fld = PTRIN((src).fld); } while (0)
187 #define PTROUT_CP(src,dst,fld) \
188 do { (dst).fld = PTROUT((src).fld); } while (0)
191 mps_attach_user(struct mps_softc *sc)
195 unit = device_get_unit(sc->mps_dev);
196 sc->mps_cdev = make_dev(&mps_cdevsw, unit, UID_ROOT, GID_OPERATOR, 0640,
198 if (sc->mps_cdev == NULL) {
201 sc->mps_cdev->si_drv1 = sc;
206 mps_detach_user(struct mps_softc *sc)
209 /* XXX: do a purge of pending requests? */
210 if (sc->mps_cdev != NULL)
211 destroy_dev(sc->mps_cdev);
215 mps_open(struct cdev *dev, int flags, int fmt, struct thread *td)
222 mps_close(struct cdev *dev, int flags, int fmt, struct thread *td)
229 mps_user_read_cfg_header(struct mps_softc *sc,
230 struct mps_cfg_page_req *page_req)
232 MPI2_CONFIG_PAGE_HEADER *hdr;
233 struct mps_config_params params;
236 hdr = ¶ms.hdr.Struct;
237 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
238 params.page_address = le32toh(page_req->page_address);
239 hdr->PageVersion = 0;
241 hdr->PageNumber = page_req->header.PageNumber;
242 hdr->PageType = page_req->header.PageType;
243 params.buffer = NULL;
245 params.callback = NULL;
247 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
249 * Leave the request. Without resetting the chip, it's
250 * still owned by it and we'll just get into trouble
251 * freeing it now. Mark it as abandoned so that if it
252 * shows up later it can be freed.
254 mps_printf(sc, "read_cfg_header timed out\n");
258 page_req->ioc_status = htole16(params.status);
259 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
260 MPI2_IOCSTATUS_SUCCESS) {
261 bcopy(hdr, &page_req->header, sizeof(page_req->header));
268 mps_user_read_cfg_page(struct mps_softc *sc, struct mps_cfg_page_req *page_req,
271 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
272 struct mps_config_params params;
276 hdr = ¶ms.hdr.Struct;
277 hdr->PageVersion = reqhdr->PageVersion;
278 hdr->PageLength = reqhdr->PageLength;
279 hdr->PageNumber = reqhdr->PageNumber;
280 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
281 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
282 params.page_address = le32toh(page_req->page_address);
284 params.length = le32toh(page_req->len);
285 params.callback = NULL;
287 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
288 mps_printf(sc, "mps_user_read_cfg_page timed out\n");
292 page_req->ioc_status = htole16(params.status);
297 mps_user_read_extcfg_header(struct mps_softc *sc,
298 struct mps_ext_cfg_page_req *ext_page_req)
300 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
301 struct mps_config_params params;
304 hdr = ¶ms.hdr.Ext;
305 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
306 hdr->PageVersion = ext_page_req->header.PageVersion;
307 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
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->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
350 hdr->PageNumber = reqhdr->PageNumber;
351 hdr->ExtPageType = reqhdr->ExtPageType;
352 hdr->ExtPageLength = reqhdr->ExtPageLength;
354 params.length = le32toh(ext_page_req->len);
355 params.callback = NULL;
357 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
358 mps_printf(sc, "mps_user_read_extcfg_page timed out\n");
362 ext_page_req->ioc_status = htole16(params.status);
367 mps_user_write_cfg_page(struct mps_softc *sc,
368 struct mps_cfg_page_req *page_req, void *buf)
370 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
371 struct mps_config_params params;
376 hdr = ¶ms.hdr.Struct;
377 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
378 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
379 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
380 mps_printf(sc, "page type 0x%x not changeable\n",
381 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
386 * There isn't any point in restoring stripped out attributes
387 * if you then mask them going down to issue the request.
390 hdr->PageVersion = reqhdr->PageVersion;
391 hdr->PageLength = reqhdr->PageLength;
392 hdr->PageNumber = reqhdr->PageNumber;
393 hdr->PageType = reqhdr->PageType;
394 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
395 params.page_address = le32toh(page_req->page_address);
397 params.length = le32toh(page_req->len);
398 params.callback = NULL;
400 if ((error = mps_write_config_page(sc, ¶ms)) != 0) {
401 mps_printf(sc, "mps_write_cfg_page timed out\n");
405 page_req->ioc_status = htole16(params.status);
410 mpi_init_sge(struct mps_command *cm, void *req, void *sge)
414 space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
415 off = (uintptr_t)sge - (uintptr_t)req;
417 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
418 req, sge, off, space));
421 cm->cm_sglsize = space - off;
425 * Prepare the mps_command for an IOC_FACTS request.
428 mpi_pre_ioc_facts(struct mps_command *cm, struct mps_usr_command *cmd)
430 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
431 MPI2_IOC_FACTS_REPLY *rpl;
433 if (cmd->req_len != sizeof *req)
435 if (cmd->rpl_len != sizeof *rpl)
444 * Prepare the mps_command for a PORT_FACTS request.
447 mpi_pre_port_facts(struct mps_command *cm, struct mps_usr_command *cmd)
449 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
450 MPI2_PORT_FACTS_REPLY *rpl;
452 if (cmd->req_len != sizeof *req)
454 if (cmd->rpl_len != sizeof *rpl)
463 * Prepare the mps_command for a FW_DOWNLOAD request.
466 mpi_pre_fw_download(struct mps_command *cm, struct mps_usr_command *cmd)
468 MPI2_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
469 MPI2_FW_DOWNLOAD_REPLY *rpl;
470 MPI2_FW_DOWNLOAD_TCSGE tc;
474 * This code assumes there is room in the request's SGL for
475 * the TransactionContext plus at least a SGL chain element.
477 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
479 if (cmd->req_len != sizeof *req)
481 if (cmd->rpl_len != sizeof *rpl)
487 error = copyin(cmd->buf, cm->cm_data, cmd->len);
491 mpi_init_sge(cm, req, &req->SGL);
492 bzero(&tc, sizeof tc);
495 * For now, the F/W image must be provided in a single request.
497 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
499 if (req->TotalImageSize != cmd->len)
503 * The value of the first two elements is specified in the
504 * Fusion-MPT Message Passing Interface document.
507 tc.DetailsLength = 12;
509 tc.ImageSize = cmd->len;
511 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
513 return (mps_push_sge(cm, &tc, sizeof tc, 0));
517 * Prepare the mps_command for a FW_UPLOAD request.
520 mpi_pre_fw_upload(struct mps_command *cm, struct mps_usr_command *cmd)
522 MPI2_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
523 MPI2_FW_UPLOAD_REPLY *rpl;
524 MPI2_FW_UPLOAD_TCSGE tc;
527 * This code assumes there is room in the request's SGL for
528 * the TransactionContext plus at least a SGL chain element.
530 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
532 if (cmd->req_len != sizeof *req)
534 if (cmd->rpl_len != sizeof *rpl)
537 mpi_init_sge(cm, req, &req->SGL);
538 bzero(&tc, sizeof tc);
541 * The value of the first two elements is specified in the
542 * Fusion-MPT Message Passing Interface document.
545 tc.DetailsLength = 12;
547 * XXX Is there any reason to fetch a partial image? I.e. to
548 * set ImageOffset to something other than 0?
551 tc.ImageSize = cmd->len;
553 cm->cm_flags |= MPS_CM_FLAGS_DATAIN;
555 return (mps_push_sge(cm, &tc, sizeof tc, 0));
559 * Prepare the mps_command for a SATA_PASSTHROUGH request.
562 mpi_pre_sata_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
564 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
565 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
567 if (cmd->req_len != sizeof *req)
569 if (cmd->rpl_len != sizeof *rpl)
572 mpi_init_sge(cm, req, &req->SGL);
577 * Prepare the mps_command for a SMP_PASSTHROUGH request.
580 mpi_pre_smp_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
582 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
583 MPI2_SMP_PASSTHROUGH_REPLY *rpl;
585 if (cmd->req_len != sizeof *req)
587 if (cmd->rpl_len != sizeof *rpl)
590 mpi_init_sge(cm, req, &req->SGL);
595 * Prepare the mps_command for a CONFIG request.
598 mpi_pre_config(struct mps_command *cm, struct mps_usr_command *cmd)
600 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
601 MPI2_CONFIG_REPLY *rpl;
603 if (cmd->req_len != sizeof *req)
605 if (cmd->rpl_len != sizeof *rpl)
608 mpi_init_sge(cm, req, &req->PageBufferSGE);
613 * Prepare the mps_command for a SAS_IO_UNIT_CONTROL request.
616 mpi_pre_sas_io_unit_control(struct mps_command *cm,
617 struct mps_usr_command *cmd)
626 * A set of functions to prepare an mps_command for the various
627 * supported requests.
629 struct mps_user_func {
632 } mps_user_func_list[] = {
633 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
634 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
635 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
636 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
637 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
638 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
639 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
640 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
641 { 0xFF, NULL } /* list end */
645 mps_user_setup_request(struct mps_command *cm, struct mps_usr_command *cmd)
647 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
648 struct mps_user_func *f;
650 for (f = mps_user_func_list; f->f_pre != NULL; f++) {
651 if (hdr->Function == f->Function)
652 return (f->f_pre(cm, cmd));
658 mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd)
660 MPI2_REQUEST_HEADER *hdr;
661 MPI2_DEFAULT_REPLY *rpl;
663 struct mps_command *cm = NULL;
668 cm = mps_alloc_command(sc);
671 mps_printf(sc, "%s: no mps requests\n", __func__);
677 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
679 mps_dprint(sc, MPS_USER, "%s: req %p %d rpl %p %d\n", __func__,
680 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len);
682 if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
684 goto RetFreeUnlocked;
686 err = copyin(cmd->req, hdr, cmd->req_len);
688 goto RetFreeUnlocked;
690 mps_dprint(sc, MPS_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
691 hdr->Function, hdr->MsgFlags);
694 buf = malloc(cmd->len, M_MPSUSER, M_WAITOK|M_ZERO);
696 mps_printf(sc, "Cannot allocate memory %s %d\n",
701 cm->cm_length = cmd->len;
707 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
708 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
710 err = mps_user_setup_request(cm, cmd);
712 mps_printf(sc, "%s: unsupported parameter or unsupported "
713 "function in request (function = 0x%X)\n", __func__,
717 goto RetFreeUnlocked;
720 err = mps_wait_command(sc, cm, 60, CAN_SLEEP);
723 mps_printf(sc, "%s: invalid request: error %d\n",
728 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
730 sz = rpl->MsgLength * 4;
734 if (sz > cmd->rpl_len) {
735 mps_printf(sc, "%s: user reply buffer (%d) smaller than "
736 "returned buffer (%d)\n", __func__, cmd->rpl_len, sz);
741 copyout(rpl, cmd->rpl, sz);
743 copyout(buf, cmd->buf, cmd->len);
744 mps_dprint(sc, MPS_USER, "%s: reply size %d\n", __func__, sz);
749 mps_free_command(sc, cm);
753 free(buf, M_MPSUSER);
758 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
760 MPI2_REQUEST_HEADER *hdr, tmphdr;
761 MPI2_DEFAULT_REPLY *rpl;
762 struct mps_command *cm = NULL;
763 int err = 0, dir = 0, sz;
764 uint8_t function = 0;
768 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
769 * bit to denote that a passthru is being processed.
772 if (sc->mps_flags & MPS_FLAGS_BUSY) {
773 mps_dprint(sc, MPS_USER, "%s: Only one passthru command "
774 "allowed at a single time.", __func__);
778 sc->mps_flags |= MPS_FLAGS_BUSY;
782 * Do some validation on data direction. Valid cases are:
783 * 1) DataSize is 0 and direction is NONE
784 * 2) DataSize is non-zero and one of:
785 * a) direction is READ or
786 * b) direction is WRITE or
787 * c) direction is BOTH and DataOutSize is non-zero
788 * If valid and the direction is BOTH, change the direction to READ.
789 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
791 if (((data->DataSize == 0) &&
792 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
793 ((data->DataSize != 0) &&
794 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
795 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
796 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
797 (data->DataOutSize != 0))))) {
798 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
799 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
801 data->DataOutSize = 0;
805 mps_dprint(sc, MPS_USER, "%s: req 0x%jx %d rpl 0x%jx %d "
806 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
807 data->PtrRequest, data->RequestSize, data->PtrReply,
808 data->ReplySize, data->PtrData, data->DataSize,
809 data->PtrDataOut, data->DataOutSize, data->DataDirection);
812 * copy in the header so we know what we're dealing with before we
813 * commit to allocating a command for it.
815 err = copyin(PTRIN(data->PtrRequest), &tmphdr, data->RequestSize);
817 goto RetFreeUnlocked;
819 if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
821 goto RetFreeUnlocked;
824 function = tmphdr.Function;
825 mps_dprint(sc, MPS_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
826 function, tmphdr.MsgFlags);
829 * Handle a passthru TM request.
831 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
832 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
835 cm = mpssas_alloc_tm(sc);
841 /* Copy the header in. Only a small fixup is needed. */
842 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
843 bcopy(&tmphdr, task, data->RequestSize);
844 task->TaskMID = cm->cm_desc.Default.SMID;
847 cm->cm_desc.HighPriority.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
848 cm->cm_complete = NULL;
849 cm->cm_complete_data = NULL;
851 err = mps_wait_command(sc, cm, 30, CAN_SLEEP);
855 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
859 * Copy the reply data and sense data to user space.
861 if (cm->cm_reply != NULL) {
862 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
863 sz = rpl->MsgLength * 4;
865 if (sz > data->ReplySize) {
866 mps_printf(sc, "%s: user reply buffer (%d) "
867 "smaller than returned buffer (%d)\n",
868 __func__, data->ReplySize, sz);
871 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, CAN_SLEEP);
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: user reply buffer (%d) smaller "
1027 "than returned buffer (%d)\n", __func__,
1028 data->ReplySize, sz);
1031 copyout(cm->cm_reply, PTRIN(data->PtrReply), data->ReplySize);
1034 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1035 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1036 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1037 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1039 MIN((le32toh(((MPI2_SCSI_IO_REPLY *)rpl)->SenseCount)),
1040 sizeof(struct scsi_sense_data));
1042 copyout(cm->cm_sense, cm->cm_req + 64, sense_len);
1054 free(cm->cm_data, M_MPSUSER);
1055 mps_free_command(sc, cm);
1058 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1065 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1067 Mpi2ConfigReply_t mpi_reply;
1068 Mpi2BiosPage3_t config_page;
1071 * Use the PCI interface functions to get the Bus, Device, and Function
1074 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1075 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1076 data->PciInformation.u.bits.FunctionNumber =
1077 pci_get_function(sc->mps_dev);
1080 * Get the FW version that should already be saved in IOC Facts.
1082 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1085 * General device info.
1087 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1088 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1089 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1090 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1091 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1092 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1093 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1096 * Get the driver version.
1098 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1101 * Need to get BIOS Config Page 3 for the BIOS Version.
1103 data->BiosVersion = 0;
1105 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1106 printf("%s: Error while retrieving BIOS Version\n", __func__);
1108 data->BiosVersion = config_page.BiosVersion;
1113 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1118 * Use the PCI interface functions to get the Bus, Device, and Function
1121 data->BusNumber = pci_get_bus(sc->mps_dev);
1122 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1123 data->FunctionNumber = pci_get_function(sc->mps_dev);
1126 * Now get the interrupt vector and the pci header. The vector can
1127 * only be 0 right now. The header is the first 256 bytes of config
1130 data->InterruptVector = 0;
1131 for (i = 0; i < sizeof (data->PciHeader); i++) {
1132 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1137 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1141 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1142 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1147 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1151 mps_post_fw_diag_buffer(struct mps_softc *sc,
1152 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1154 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1155 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1156 struct mps_command *cm = NULL;
1160 * If buffer is not enabled, just leave.
1162 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1163 if (!pBuffer->enabled) {
1164 return (MPS_DIAG_FAILURE);
1168 * Clear some flags initially.
1170 pBuffer->force_release = FALSE;
1171 pBuffer->valid_data = FALSE;
1172 pBuffer->owned_by_firmware = FALSE;
1177 cm = mps_alloc_command(sc);
1179 mps_printf(sc, "%s: no mps requests\n", __func__);
1180 return (MPS_DIAG_FAILURE);
1184 * Build the request for releasing the FW Diag Buffer and send it.
1186 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1187 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1188 req->BufferType = pBuffer->buffer_type;
1189 req->ExtendedType = pBuffer->extended_type;
1190 req->BufferLength = pBuffer->size;
1191 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1192 req->ProductSpecific[i] = pBuffer->product_specific[i];
1193 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1196 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1197 cm->cm_complete_data = NULL;
1200 * Send command synchronously.
1202 status = mps_wait_command(sc, cm, 30, CAN_SLEEP);
1204 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1206 status = MPS_DIAG_FAILURE;
1211 * Process POST reply.
1213 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1214 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1215 status = MPS_DIAG_FAILURE;
1216 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1217 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1218 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1219 reply->IOCLogInfo, reply->TransferLength);
1224 * Post was successful.
1226 pBuffer->valid_data = TRUE;
1227 pBuffer->owned_by_firmware = TRUE;
1228 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1229 status = MPS_DIAG_SUCCESS;
1232 mps_free_command(sc, cm);
1237 mps_release_fw_diag_buffer(struct mps_softc *sc,
1238 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1241 MPI2_DIAG_RELEASE_REQUEST *req;
1242 MPI2_DIAG_RELEASE_REPLY *reply;
1243 struct mps_command *cm = NULL;
1247 * If buffer is not enabled, just leave.
1249 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1250 if (!pBuffer->enabled) {
1251 mps_dprint(sc, MPS_USER, "%s: This buffer type is not "
1252 "supported by the IOC", __func__);
1253 return (MPS_DIAG_FAILURE);
1257 * Clear some flags initially.
1259 pBuffer->force_release = FALSE;
1260 pBuffer->valid_data = FALSE;
1261 pBuffer->owned_by_firmware = FALSE;
1266 cm = mps_alloc_command(sc);
1268 mps_printf(sc, "%s: no mps requests\n", __func__);
1269 return (MPS_DIAG_FAILURE);
1273 * Build the request for releasing the FW Diag Buffer and send it.
1275 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1276 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1277 req->BufferType = pBuffer->buffer_type;
1280 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1281 cm->cm_complete_data = NULL;
1284 * Send command synchronously.
1286 status = mps_wait_command(sc, cm, 30, CAN_SLEEP);
1288 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1290 status = MPS_DIAG_FAILURE;
1295 * Process RELEASE reply.
1297 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1298 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1299 pBuffer->owned_by_firmware) {
1300 status = MPS_DIAG_FAILURE;
1301 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1302 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1303 __func__, reply->IOCStatus, reply->IOCLogInfo);
1308 * Release was successful.
1310 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1311 status = MPS_DIAG_SUCCESS;
1314 * If this was for an UNREGISTER diag type command, clear the unique ID.
1316 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1317 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1325 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1326 uint32_t *return_code)
1328 mps_fw_diagnostic_buffer_t *pBuffer;
1329 uint8_t extended_type, buffer_type, i;
1330 uint32_t buffer_size;
1334 extended_type = diag_register->ExtendedType;
1335 buffer_type = diag_register->BufferType;
1336 buffer_size = diag_register->RequestedBufferSize;
1337 unique_id = diag_register->UniqueId;
1340 * Check for valid buffer type
1342 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1343 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1344 return (MPS_DIAG_FAILURE);
1348 * Get the current buffer and look up the unique ID. The unique ID
1349 * should not be found. If it is, the ID is already in use.
1351 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1352 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1353 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1354 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1355 return (MPS_DIAG_FAILURE);
1359 * The buffer's unique ID should not be registered yet, and the given
1360 * unique ID cannot be 0.
1362 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1363 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1364 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1365 return (MPS_DIAG_FAILURE);
1369 * If this buffer is already posted as immediate, just change owner.
1371 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1372 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1373 pBuffer->immediate = FALSE;
1374 pBuffer->unique_id = unique_id;
1375 return (MPS_DIAG_SUCCESS);
1379 * Post a new buffer after checking if it's enabled. The DMA buffer
1380 * that is allocated will be contiguous (nsegments = 1).
1382 if (!pBuffer->enabled) {
1383 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1384 return (MPS_DIAG_FAILURE);
1386 if (bus_dma_tag_create( sc->mps_parent_dmat, /* parent */
1387 1, 0, /* algnmnt, boundary */
1388 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1389 BUS_SPACE_MAXADDR, /* highaddr */
1390 NULL, NULL, /* filter, filterarg */
1391 buffer_size, /* maxsize */
1393 buffer_size, /* maxsegsize */
1395 NULL, NULL, /* lockfunc, lockarg */
1396 &sc->fw_diag_dmat)) {
1397 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer DMA "
1401 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1402 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1403 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer "
1407 bzero(sc->fw_diag_buffer, buffer_size);
1408 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1409 buffer_size, mps_memaddr_cb, &sc->fw_diag_busaddr, 0);
1410 pBuffer->size = buffer_size;
1413 * Copy the given info to the diag buffer and post the buffer.
1415 pBuffer->buffer_type = buffer_type;
1416 pBuffer->immediate = FALSE;
1417 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1418 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1420 pBuffer->product_specific[i] =
1421 diag_register->ProductSpecific[i];
1424 pBuffer->extended_type = extended_type;
1425 pBuffer->unique_id = unique_id;
1426 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1429 * In case there was a failure, free the DMA buffer.
1431 if (status == MPS_DIAG_FAILURE) {
1432 if (sc->fw_diag_busaddr != 0)
1433 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1434 if (sc->fw_diag_buffer != NULL)
1435 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1437 if (sc->fw_diag_dmat != NULL)
1438 bus_dma_tag_destroy(sc->fw_diag_dmat);
1445 mps_diag_unregister(struct mps_softc *sc,
1446 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1448 mps_fw_diagnostic_buffer_t *pBuffer;
1453 unique_id = diag_unregister->UniqueId;
1456 * Get the current buffer and look up the unique ID. The unique ID
1459 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1460 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1461 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1462 return (MPS_DIAG_FAILURE);
1465 pBuffer = &sc->fw_diag_buffer_list[i];
1468 * Try to release the buffer from FW before freeing it. If release
1469 * fails, don't free the DMA buffer in case FW tries to access it
1470 * later. If buffer is not owned by firmware, can't release it.
1472 if (!pBuffer->owned_by_firmware) {
1473 status = MPS_DIAG_SUCCESS;
1475 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1476 MPS_FW_DIAG_TYPE_UNREGISTER);
1480 * At this point, return the current status no matter what happens with
1483 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1484 if (status == MPS_DIAG_SUCCESS) {
1485 if (sc->fw_diag_busaddr != 0)
1486 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1487 if (sc->fw_diag_buffer != NULL)
1488 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1490 if (sc->fw_diag_dmat != NULL)
1491 bus_dma_tag_destroy(sc->fw_diag_dmat);
1498 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1499 uint32_t *return_code)
1501 mps_fw_diagnostic_buffer_t *pBuffer;
1505 unique_id = diag_query->UniqueId;
1508 * If ID is valid, query on ID.
1509 * If ID is invalid, query on buffer type.
1511 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1512 i = diag_query->BufferType;
1513 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1514 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1515 return (MPS_DIAG_FAILURE);
1518 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1519 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1520 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1521 return (MPS_DIAG_FAILURE);
1526 * Fill query structure with the diag buffer info.
1528 pBuffer = &sc->fw_diag_buffer_list[i];
1529 diag_query->BufferType = pBuffer->buffer_type;
1530 diag_query->ExtendedType = pBuffer->extended_type;
1531 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1532 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1534 diag_query->ProductSpecific[i] =
1535 pBuffer->product_specific[i];
1538 diag_query->TotalBufferSize = pBuffer->size;
1539 diag_query->DriverAddedBufferSize = 0;
1540 diag_query->UniqueId = pBuffer->unique_id;
1541 diag_query->ApplicationFlags = 0;
1542 diag_query->DiagnosticFlags = 0;
1545 * Set/Clear application flags
1547 if (pBuffer->immediate) {
1548 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1550 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1552 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1553 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1555 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1557 if (pBuffer->owned_by_firmware) {
1558 diag_query->ApplicationFlags |=
1559 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1561 diag_query->ApplicationFlags &=
1562 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1565 return (MPS_DIAG_SUCCESS);
1569 mps_diag_read_buffer(struct mps_softc *sc,
1570 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1571 uint32_t *return_code)
1573 mps_fw_diagnostic_buffer_t *pBuffer;
1578 unique_id = diag_read_buffer->UniqueId;
1581 * Get the current buffer and look up the unique ID. The unique ID
1584 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1585 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1586 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1587 return (MPS_DIAG_FAILURE);
1590 pBuffer = &sc->fw_diag_buffer_list[i];
1593 * Make sure requested read is within limits
1595 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1597 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1598 return (MPS_DIAG_FAILURE);
1602 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1603 * buffer that was allocated is one contiguous buffer.
1605 pData = (uint8_t *)(sc->fw_diag_buffer +
1606 diag_read_buffer->StartingOffset);
1607 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1608 return (MPS_DIAG_FAILURE);
1609 diag_read_buffer->Status = 0;
1612 * Set or clear the Force Release flag.
1614 if (pBuffer->force_release) {
1615 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1617 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1621 * If buffer is to be reregistered, make sure it's not already owned by
1624 status = MPS_DIAG_SUCCESS;
1625 if (!pBuffer->owned_by_firmware) {
1626 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1627 status = mps_post_fw_diag_buffer(sc, pBuffer,
1636 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1637 uint32_t *return_code)
1639 mps_fw_diagnostic_buffer_t *pBuffer;
1644 unique_id = diag_release->UniqueId;
1647 * Get the current buffer and look up the unique ID. The unique ID
1650 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1651 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1652 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1653 return (MPS_DIAG_FAILURE);
1656 pBuffer = &sc->fw_diag_buffer_list[i];
1659 * If buffer is not owned by firmware, it's already been released.
1661 if (!pBuffer->owned_by_firmware) {
1662 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1663 return (MPS_DIAG_FAILURE);
1667 * Release the buffer.
1669 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1670 MPS_FW_DIAG_TYPE_RELEASE);
1675 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1676 uint32_t length, uint32_t *return_code)
1678 mps_fw_diag_register_t diag_register;
1679 mps_fw_diag_unregister_t diag_unregister;
1680 mps_fw_diag_query_t diag_query;
1681 mps_diag_read_buffer_t diag_read_buffer;
1682 mps_fw_diag_release_t diag_release;
1683 int status = MPS_DIAG_SUCCESS;
1684 uint32_t original_return_code;
1686 original_return_code = *return_code;
1687 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1690 case MPS_FW_DIAG_TYPE_REGISTER:
1693 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1694 status = MPS_DIAG_FAILURE;
1697 if (copyin(diag_action, &diag_register,
1698 sizeof(diag_register)) != 0)
1699 return (MPS_DIAG_FAILURE);
1700 status = mps_diag_register(sc, &diag_register,
1704 case MPS_FW_DIAG_TYPE_UNREGISTER:
1705 if (length < sizeof(diag_unregister)) {
1707 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1708 status = MPS_DIAG_FAILURE;
1711 if (copyin(diag_action, &diag_unregister,
1712 sizeof(diag_unregister)) != 0)
1713 return (MPS_DIAG_FAILURE);
1714 status = mps_diag_unregister(sc, &diag_unregister,
1718 case MPS_FW_DIAG_TYPE_QUERY:
1719 if (length < sizeof (diag_query)) {
1721 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1722 status = MPS_DIAG_FAILURE;
1725 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1727 return (MPS_DIAG_FAILURE);
1728 status = mps_diag_query(sc, &diag_query, return_code);
1729 if (status == MPS_DIAG_SUCCESS)
1730 if (copyout(&diag_query, diag_action,
1731 sizeof (diag_query)) != 0)
1732 return (MPS_DIAG_FAILURE);
1735 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1736 if (copyin(diag_action, &diag_read_buffer,
1737 sizeof(diag_read_buffer)) != 0)
1738 return (MPS_DIAG_FAILURE);
1739 if (length < diag_read_buffer.BytesToRead) {
1741 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1742 status = MPS_DIAG_FAILURE;
1745 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1746 PTRIN(diag_read_buffer.PtrDataBuffer),
1748 if (status == MPS_DIAG_SUCCESS) {
1749 if (copyout(&diag_read_buffer, diag_action,
1750 sizeof(diag_read_buffer) -
1751 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1753 return (MPS_DIAG_FAILURE);
1757 case MPS_FW_DIAG_TYPE_RELEASE:
1758 if (length < sizeof(diag_release)) {
1760 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1761 status = MPS_DIAG_FAILURE;
1764 if (copyin(diag_action, &diag_release,
1765 sizeof(diag_release)) != 0)
1766 return (MPS_DIAG_FAILURE);
1767 status = mps_diag_release(sc, &diag_release,
1772 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1773 status = MPS_DIAG_FAILURE;
1777 if ((status == MPS_DIAG_FAILURE) &&
1778 (original_return_code == MPS_FW_DIAG_NEW) &&
1779 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1780 status = MPS_DIAG_SUCCESS;
1786 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1791 * Only allow one diag action at one time.
1793 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1794 mps_dprint(sc, MPS_USER, "%s: Only one FW diag command "
1795 "allowed at a single time.", __func__);
1798 sc->mps_flags |= MPS_FLAGS_BUSY;
1801 * Send diag action request
1803 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1804 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1805 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1806 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1807 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1808 status = mps_do_diag_action(sc, data->Action,
1809 PTRIN(data->PtrDiagAction), data->Length,
1814 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1819 * Copy the event recording mask and the event queue size out. For
1820 * clarification, the event recording mask (events_to_record) is not the same
1821 * thing as the event mask (event_mask). events_to_record has a bit set for
1822 * every event type that is to be recorded by the driver, and event_mask has a
1823 * bit cleared for every event that is allowed into the driver from the IOC.
1824 * They really have nothing to do with each other.
1827 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1832 data->Entries = MPS_EVENT_QUEUE_SIZE;
1834 for (i = 0; i < 4; i++) {
1835 data->Types[i] = sc->events_to_record[i];
1841 * Set the driver's event mask according to what's been given. See
1842 * mps_user_event_query for explanation of the event recording mask and the IOC
1843 * event mask. It's the app's responsibility to enable event logging by setting
1844 * the bits in events_to_record. Initially, no events will be logged.
1847 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1852 for (i = 0; i < 4; i++) {
1853 sc->events_to_record[i] = data->Types[i];
1859 * Copy out the events that have been recorded, up to the max events allowed.
1862 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1869 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1871 if (copyout((void *)sc->recorded_events,
1872 PTRIN(data->PtrEvents), size) != 0)
1877 * data->Size value is not large enough to copy event data.
1883 * Change size value to match the number of bytes that were copied.
1886 data->Size = sizeof(sc->recorded_events);
1893 * Record events into the driver from the IOC if they are not masked.
1896 mpssas_record_event(struct mps_softc *sc,
1897 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1901 uint16_t event_data_len;
1902 boolean_t sendAEN = FALSE;
1904 event = event_reply->Event;
1907 * Generate a system event to let anyone who cares know that a
1908 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1909 * event mask is set to.
1911 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1916 * Record the event only if its corresponding bit is set in
1917 * events_to_record. event_index is the index into recorded_events and
1918 * event_number is the overall number of an event being recorded since
1919 * start-of-day. event_index will roll over; event_number will never
1922 i = (uint8_t)(event / 32);
1923 j = (uint8_t)(event % 32);
1924 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1925 i = sc->event_index;
1926 sc->recorded_events[i].Type = event;
1927 sc->recorded_events[i].Number = ++sc->event_number;
1928 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
1930 event_data_len = event_reply->EventDataLength;
1932 if (event_data_len > 0) {
1934 * Limit data to size in m_event entry
1936 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
1937 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
1939 for (j = 0; j < event_data_len; j++) {
1940 sc->recorded_events[i].Data[j] =
1941 event_reply->EventData[j];
1945 * check for index wrap-around
1947 if (++i == MPS_EVENT_QUEUE_SIZE) {
1950 sc->event_index = (uint8_t)i;
1953 * Set flag to send the event.
1960 * Generate a system event if flag is set to let anyone who cares know
1961 * that an event has occurred.
1964 //SLM-how to send a system event (see kqueue, kevent)
1965 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
1966 // "SAS", NULL, NULL, DDI_NOSLEEP);
1971 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
1975 switch (data->Command) {
1977 * IO access is not supported.
1981 mps_dprint(sc, MPS_USER, "IO access is not supported. "
1982 "Use memory access.");
1987 data->RegData = mps_regread(sc, data->RegOffset);
1991 mps_regwrite(sc, data->RegOffset, data->RegData);
2003 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
2005 uint8_t bt2dh = FALSE;
2006 uint8_t dh2bt = FALSE;
2007 uint16_t dev_handle, bus, target;
2010 target = data->TargetID;
2011 dev_handle = data->DevHandle;
2014 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2015 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2016 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2019 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2021 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2023 if (!dh2bt && !bt2dh)
2027 * Only handle bus of 0. Make sure target is within range.
2033 if (target > sc->max_devices) {
2034 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2035 "for Bus/Target to DevHandle mapping.");
2038 dev_handle = sc->mapping_table[target].dev_handle;
2040 data->DevHandle = dev_handle;
2043 target = mps_mapping_get_sas_id_from_handle(sc, dev_handle);
2045 data->TargetID = target;
2052 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2055 struct mps_softc *sc;
2056 struct mps_cfg_page_req *page_req;
2057 struct mps_ext_cfg_page_req *ext_page_req;
2059 int error, msleep_ret;
2063 page_req = (void *)arg;
2064 ext_page_req = (void *)arg;
2067 case MPSIO_READ_CFG_HEADER:
2069 error = mps_user_read_cfg_header(sc, page_req);
2072 case MPSIO_READ_CFG_PAGE:
2073 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2075 mps_printf(sc, "Cannot allocate memory %s %d\n",
2076 __func__, __LINE__);
2079 error = copyin(page_req->buf, mps_page,
2080 sizeof(MPI2_CONFIG_PAGE_HEADER));
2084 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2088 error = copyout(mps_page, page_req->buf, page_req->len);
2090 case MPSIO_READ_EXT_CFG_HEADER:
2092 error = mps_user_read_extcfg_header(sc, ext_page_req);
2095 case MPSIO_READ_EXT_CFG_PAGE:
2096 mps_page = malloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2098 mps_printf(sc, "Cannot allocate memory %s %d\n",
2099 __func__, __LINE__);
2102 error = copyin(ext_page_req->buf, mps_page,
2103 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2107 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2111 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2113 case MPSIO_WRITE_CFG_PAGE:
2114 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2116 mps_printf(sc, "Cannot allocate memory %s %d\n",
2117 __func__, __LINE__);
2120 error = copyin(page_req->buf, mps_page, page_req->len);
2124 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2127 case MPSIO_MPS_COMMAND:
2128 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2130 case MPTIOCTL_PASS_THRU:
2132 * The user has requested to pass through a command to be
2133 * executed by the MPT firmware. Call our routine which does
2134 * this. Only allow one passthru IOCTL at one time.
2136 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2138 case MPTIOCTL_GET_ADAPTER_DATA:
2140 * The user has requested to read adapter data. Call our
2141 * routine which does this.
2144 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2146 case MPTIOCTL_GET_PCI_INFO:
2148 * The user has requested to read pci info. Call
2149 * our routine which does this.
2153 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2156 case MPTIOCTL_RESET_ADAPTER:
2158 sc->port_enable_complete = 0;
2159 uint32_t reinit_start = time_uptime;
2160 error = mps_reinit(sc);
2161 /* Sleep for 300 second. */
2162 msleep_ret = msleep(&sc->port_enable_complete, &sc->mps_mtx, PRIBIO,
2163 "mps_porten", 300 * hz);
2166 printf("Port Enable did not complete after Diag "
2167 "Reset msleep error %d.\n", msleep_ret);
2169 mps_dprint(sc, MPS_USER,
2170 "Hard Reset with Port Enable completed in %d seconds.\n",
2171 (uint32_t) (time_uptime - reinit_start));
2173 case MPTIOCTL_DIAG_ACTION:
2175 * The user has done a diag buffer action. Call our routine
2176 * which does this. Only allow one diag action at one time.
2179 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2182 case MPTIOCTL_EVENT_QUERY:
2184 * The user has done an event query. Call our routine which does
2188 mps_user_event_query(sc, (mps_event_query_t *)arg);
2190 case MPTIOCTL_EVENT_ENABLE:
2192 * The user has done an event enable. Call our routine which
2196 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2198 case MPTIOCTL_EVENT_REPORT:
2200 * The user has done an event report. Call our routine which
2203 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2205 case MPTIOCTL_REG_ACCESS:
2207 * The user has requested register access. Call our routine
2211 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2214 case MPTIOCTL_BTDH_MAPPING:
2216 * The user has requested to translate a bus/target to a
2217 * DevHandle or a DevHandle to a bus/target. Call our routine
2220 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2227 if (mps_page != NULL)
2228 free(mps_page, M_MPSUSER);
2233 #ifdef COMPAT_FREEBSD32
2235 struct mps_cfg_page_req32 {
2236 MPI2_CONFIG_PAGE_HEADER header;
2237 uint32_t page_address;
2240 uint16_t ioc_status;
2243 struct mps_ext_cfg_page_req32 {
2244 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2245 uint32_t page_address;
2248 uint16_t ioc_status;
2251 struct mps_raid_action32 {
2255 uint8_t phys_disk_num;
2256 uint32_t action_data_word;
2259 uint32_t volume_status;
2260 uint32_t action_data[4];
2261 uint16_t action_status;
2262 uint16_t ioc_status;
2266 struct mps_usr_command32 {
2276 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2277 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2278 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2279 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2280 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2281 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2282 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2285 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2288 struct mps_cfg_page_req32 *page32 = _arg;
2289 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2290 struct mps_raid_action32 *raid32 = _arg;
2291 struct mps_usr_command32 *user32 = _arg;
2293 struct mps_cfg_page_req page;
2294 struct mps_ext_cfg_page_req ext;
2295 struct mps_raid_action raid;
2296 struct mps_usr_command user;
2302 case MPSIO_READ_CFG_HEADER32:
2303 case MPSIO_READ_CFG_PAGE32:
2304 case MPSIO_WRITE_CFG_PAGE32:
2305 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2306 cmd = MPSIO_READ_CFG_HEADER;
2307 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2308 cmd = MPSIO_READ_CFG_PAGE;
2310 cmd = MPSIO_WRITE_CFG_PAGE;
2311 CP(*page32, arg.page, header);
2312 CP(*page32, arg.page, page_address);
2313 PTRIN_CP(*page32, arg.page, buf);
2314 CP(*page32, arg.page, len);
2315 CP(*page32, arg.page, ioc_status);
2318 case MPSIO_READ_EXT_CFG_HEADER32:
2319 case MPSIO_READ_EXT_CFG_PAGE32:
2320 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2321 cmd = MPSIO_READ_EXT_CFG_HEADER;
2323 cmd = MPSIO_READ_EXT_CFG_PAGE;
2324 CP(*ext32, arg.ext, header);
2325 CP(*ext32, arg.ext, page_address);
2326 PTRIN_CP(*ext32, arg.ext, buf);
2327 CP(*ext32, arg.ext, len);
2328 CP(*ext32, arg.ext, ioc_status);
2331 case MPSIO_RAID_ACTION32:
2332 cmd = MPSIO_RAID_ACTION;
2333 CP(*raid32, arg.raid, action);
2334 CP(*raid32, arg.raid, volume_bus);
2335 CP(*raid32, arg.raid, volume_id);
2336 CP(*raid32, arg.raid, phys_disk_num);
2337 CP(*raid32, arg.raid, action_data_word);
2338 PTRIN_CP(*raid32, arg.raid, buf);
2339 CP(*raid32, arg.raid, len);
2340 CP(*raid32, arg.raid, volume_status);
2341 bcopy(raid32->action_data, arg.raid.action_data,
2342 sizeof arg.raid.action_data);
2343 CP(*raid32, arg.raid, ioc_status);
2344 CP(*raid32, arg.raid, write);
2347 case MPSIO_MPS_COMMAND32:
2348 cmd = MPSIO_MPS_COMMAND;
2349 PTRIN_CP(*user32, arg.user, req);
2350 CP(*user32, arg.user, req_len);
2351 PTRIN_CP(*user32, arg.user, rpl);
2352 CP(*user32, arg.user, rpl_len);
2353 PTRIN_CP(*user32, arg.user, buf);
2354 CP(*user32, arg.user, len);
2355 CP(*user32, arg.user, flags);
2361 error = mps_ioctl(dev, cmd, &arg, flag, td);
2362 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2364 case MPSIO_READ_CFG_HEADER32:
2365 case MPSIO_READ_CFG_PAGE32:
2366 case MPSIO_WRITE_CFG_PAGE32:
2367 CP(arg.page, *page32, header);
2368 CP(arg.page, *page32, page_address);
2369 PTROUT_CP(arg.page, *page32, buf);
2370 CP(arg.page, *page32, len);
2371 CP(arg.page, *page32, ioc_status);
2374 case MPSIO_READ_EXT_CFG_HEADER32:
2375 case MPSIO_READ_EXT_CFG_PAGE32:
2376 CP(arg.ext, *ext32, header);
2377 CP(arg.ext, *ext32, page_address);
2378 PTROUT_CP(arg.ext, *ext32, buf);
2379 CP(arg.ext, *ext32, len);
2380 CP(arg.ext, *ext32, ioc_status);
2383 case MPSIO_RAID_ACTION32:
2384 CP(arg.raid, *raid32, action);
2385 CP(arg.raid, *raid32, volume_bus);
2386 CP(arg.raid, *raid32, volume_id);
2387 CP(arg.raid, *raid32, phys_disk_num);
2388 CP(arg.raid, *raid32, action_data_word);
2389 PTROUT_CP(arg.raid, *raid32, buf);
2390 CP(arg.raid, *raid32, len);
2391 CP(arg.raid, *raid32, volume_status);
2392 bcopy(arg.raid.action_data, raid32->action_data,
2393 sizeof arg.raid.action_data);
2394 CP(arg.raid, *raid32, ioc_status);
2395 CP(arg.raid, *raid32, write);
2398 case MPSIO_MPS_COMMAND32:
2399 PTROUT_CP(arg.user, *user32, req);
2400 CP(arg.user, *user32, req_len);
2401 PTROUT_CP(arg.user, *user32, rpl);
2402 CP(arg.user, *user32, rpl_len);
2403 PTROUT_CP(arg.user, *user32, buf);
2404 CP(arg.user, *user32, len);
2405 CP(arg.user, *user32, flags);
2412 #endif /* COMPAT_FREEBSD32 */
2415 mps_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2418 #ifdef COMPAT_FREEBSD32
2419 if (SV_CURPROC_FLAG(SV_ILP32))
2420 return (mps_ioctl32(dev, com, arg, flag, td));
2422 return (mps_ioctl(dev, com, arg, flag, td));