2 * Copyright (c) 2008 Yahoo!, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * LSI MPT-Fusion Host Adapter FreeBSD userland interface
33 * Copyright (c) 2011 LSI Corp.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * LSI MPT-Fusion Host Adapter FreeBSD
59 * $FreeBSD: src/sys/dev/mps/mps_user.c,v 1.10 2012/01/26 18:17:21 ken Exp $
62 #include "opt_compat.h"
64 /* TODO Move headers to mpsvar */
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
69 #include <sys/module.h>
72 #include <sys/eventhandler.h>
74 #include <sys/malloc.h>
76 #include <sys/sysctl.h>
77 #include <sys/ioccom.h>
78 #include <sys/endian.h>
79 #include <sys/queue.h>
80 #include <sys/kthread.h>
81 #include <sys/taskqueue.h>
83 #include <sys/sysent.h>
86 #include <sys/device.h>
88 #include <bus/cam/cam.h>
89 #include <bus/cam/scsi/scsi_all.h>
91 #include <dev/raid/mps/mpi/mpi2_type.h>
92 #include <dev/raid/mps/mpi/mpi2.h>
93 #include <dev/raid/mps/mpi/mpi2_ioc.h>
94 #include <dev/raid/mps/mpi/mpi2_cnfg.h>
95 #include <dev/raid/mps/mpi/mpi2_init.h>
96 #include <dev/raid/mps/mpi/mpi2_tool.h>
97 #include <dev/raid/mps/mps_ioctl.h>
98 #include <dev/raid/mps/mpsvar.h>
99 #include <dev/raid/mps/mps_table.h>
100 #include <dev/raid/mps/mps_sas.h>
101 #include <bus/pci/pcivar.h>
102 #include <bus/pci/pcireg.h>
104 static d_open_t mps_open;
105 static d_close_t mps_close;
106 static d_ioctl_t mps_ioctl_devsw;
108 static struct dev_ops mps_ops = {
109 { "mps", 0, D_MPSAFE },
111 .d_close = mps_close,
112 .d_ioctl = mps_ioctl_devsw,
115 typedef int (mps_user_f)(struct mps_command *, struct mps_usr_command *);
116 static mps_user_f mpi_pre_ioc_facts;
117 static mps_user_f mpi_pre_port_facts;
118 static mps_user_f mpi_pre_fw_download;
119 static mps_user_f mpi_pre_fw_upload;
120 static mps_user_f mpi_pre_sata_passthrough;
121 static mps_user_f mpi_pre_smp_passthrough;
122 static mps_user_f mpi_pre_config;
123 static mps_user_f mpi_pre_sas_io_unit_control;
125 static int mps_user_read_cfg_header(struct mps_softc *,
126 struct mps_cfg_page_req *);
127 static int mps_user_read_cfg_page(struct mps_softc *,
128 struct mps_cfg_page_req *, void *);
129 static int mps_user_read_extcfg_header(struct mps_softc *,
130 struct mps_ext_cfg_page_req *);
131 static int mps_user_read_extcfg_page(struct mps_softc *,
132 struct mps_ext_cfg_page_req *, void *);
133 static int mps_user_write_cfg_page(struct mps_softc *,
134 struct mps_cfg_page_req *, void *);
135 static int mps_user_setup_request(struct mps_command *,
136 struct mps_usr_command *);
137 static int mps_user_command(struct mps_softc *, struct mps_usr_command *);
139 static int mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data);
140 static void mps_user_get_adapter_data(struct mps_softc *sc,
141 mps_adapter_data_t *data);
142 static void mps_user_read_pci_info(struct mps_softc *sc,
143 mps_pci_info_t *data);
144 static uint8_t mps_get_fw_diag_buffer_number(struct mps_softc *sc,
146 static int mps_post_fw_diag_buffer(struct mps_softc *sc,
147 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code);
148 static int mps_release_fw_diag_buffer(struct mps_softc *sc,
149 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
151 static int mps_diag_register(struct mps_softc *sc,
152 mps_fw_diag_register_t *diag_register, uint32_t *return_code);
153 static int mps_diag_unregister(struct mps_softc *sc,
154 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code);
155 static int mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
156 uint32_t *return_code);
157 static int mps_diag_read_buffer(struct mps_softc *sc,
158 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
159 uint32_t *return_code);
160 static int mps_diag_release(struct mps_softc *sc,
161 mps_fw_diag_release_t *diag_release, uint32_t *return_code);
162 static int mps_do_diag_action(struct mps_softc *sc, uint32_t action,
163 uint8_t *diag_action, uint32_t length, uint32_t *return_code);
164 static int mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data);
165 static void mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data);
166 static void mps_user_event_enable(struct mps_softc *sc,
167 mps_event_enable_t *data);
168 static int mps_user_event_report(struct mps_softc *sc,
169 mps_event_report_t *data);
170 static int mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data);
171 static int mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data);
173 static MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
175 /* Macros from compat/freebsd32/freebsd32.h */
176 #define PTRIN(v) (void *)(uintptr_t)(v)
177 #define PTROUT(v) (uint32_t)(uintptr_t)(v)
179 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
180 #define PTRIN_CP(src,dst,fld) \
181 do { (dst).fld = PTRIN((src).fld); } while (0)
182 #define PTROUT_CP(src,dst,fld) \
183 do { (dst).fld = PTROUT((src).fld); } while (0)
186 mps_attach_user(struct mps_softc *sc)
190 unit = device_get_unit(sc->mps_dev);
191 sc->mps_cdev = make_dev(&mps_ops, unit, UID_ROOT, GID_OPERATOR, 0640,
193 if (sc->mps_cdev == NULL) {
196 sc->mps_cdev->si_drv1 = sc;
201 mps_detach_user(struct mps_softc *sc)
204 /* XXX: do a purge of pending requests? */
205 if (sc->mps_cdev != NULL)
206 destroy_dev(sc->mps_cdev);
210 mps_open(struct dev_open_args *ap)
217 mps_close(struct dev_close_args *ap)
224 mps_user_read_cfg_header(struct mps_softc *sc,
225 struct mps_cfg_page_req *page_req)
227 MPI2_CONFIG_PAGE_HEADER *hdr;
228 struct mps_config_params params;
231 hdr = ¶ms.hdr.Struct;
232 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
233 params.page_address = le32toh(page_req->page_address);
234 hdr->PageVersion = 0;
236 hdr->PageNumber = page_req->header.PageNumber;
237 hdr->PageType = page_req->header.PageType;
238 params.buffer = NULL;
240 params.callback = NULL;
242 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
244 * Leave the request. Without resetting the chip, it's
245 * still owned by it and we'll just get into trouble
246 * freeing it now. Mark it as abandoned so that if it
247 * shows up later it can be freed.
249 mps_printf(sc, "read_cfg_header timed out\n");
253 page_req->ioc_status = htole16(params.status);
254 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
255 MPI2_IOCSTATUS_SUCCESS) {
256 bcopy(hdr, &page_req->header, sizeof(page_req->header));
263 mps_user_read_cfg_page(struct mps_softc *sc, struct mps_cfg_page_req *page_req,
266 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
267 struct mps_config_params params;
271 hdr = ¶ms.hdr.Struct;
272 hdr->PageVersion = reqhdr->PageVersion;
273 hdr->PageLength = reqhdr->PageLength;
274 hdr->PageNumber = reqhdr->PageNumber;
275 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
276 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
277 params.page_address = le32toh(page_req->page_address);
279 params.length = le32toh(page_req->len);
280 params.callback = NULL;
282 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
283 mps_printf(sc, "mps_user_read_cfg_page timed out\n");
287 page_req->ioc_status = htole16(params.status);
292 mps_user_read_extcfg_header(struct mps_softc *sc,
293 struct mps_ext_cfg_page_req *ext_page_req)
295 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
296 struct mps_config_params params;
299 hdr = ¶ms.hdr.Ext;
300 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
301 hdr->PageVersion = ext_page_req->header.PageVersion;
302 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
303 hdr->ExtPageLength = 0;
304 hdr->PageNumber = ext_page_req->header.PageNumber;
305 hdr->ExtPageType = ext_page_req->header.ExtPageType;
306 params.page_address = le32toh(ext_page_req->page_address);
307 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
309 * Leave the request. Without resetting the chip, it's
310 * still owned by it and we'll just get into trouble
311 * freeing it now. Mark it as abandoned so that if it
312 * shows up later it can be freed.
314 mps_printf(sc, "mps_user_read_extcfg_header timed out\n");
318 ext_page_req->ioc_status = htole16(params.status);
319 if ((ext_page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
320 MPI2_IOCSTATUS_SUCCESS) {
321 ext_page_req->header.PageVersion = hdr->PageVersion;
322 ext_page_req->header.PageNumber = hdr->PageNumber;
323 ext_page_req->header.PageType = hdr->PageType;
324 ext_page_req->header.ExtPageLength = hdr->ExtPageLength;
325 ext_page_req->header.ExtPageType = hdr->ExtPageType;
332 mps_user_read_extcfg_page(struct mps_softc *sc,
333 struct mps_ext_cfg_page_req *ext_page_req, void *buf)
335 MPI2_CONFIG_EXTENDED_PAGE_HEADER *reqhdr, *hdr;
336 struct mps_config_params params;
340 hdr = ¶ms.hdr.Ext;
341 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
342 params.page_address = le32toh(ext_page_req->page_address);
343 hdr->PageVersion = reqhdr->PageVersion;
344 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
345 hdr->PageNumber = reqhdr->PageNumber;
346 hdr->ExtPageType = reqhdr->ExtPageType;
347 hdr->ExtPageLength = reqhdr->ExtPageLength;
349 params.length = le32toh(ext_page_req->len);
350 params.callback = NULL;
352 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
353 mps_printf(sc, "mps_user_read_extcfg_page timed out\n");
357 ext_page_req->ioc_status = htole16(params.status);
362 mps_user_write_cfg_page(struct mps_softc *sc,
363 struct mps_cfg_page_req *page_req, void *buf)
365 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
366 struct mps_config_params params;
371 hdr = ¶ms.hdr.Struct;
372 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
373 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
374 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
375 mps_printf(sc, "page type 0x%x not changeable\n",
376 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
381 * There isn't any point in restoring stripped out attributes
382 * if you then mask them going down to issue the request.
385 hdr->PageVersion = reqhdr->PageVersion;
386 hdr->PageLength = reqhdr->PageLength;
387 hdr->PageNumber = reqhdr->PageNumber;
388 hdr->PageType = reqhdr->PageType;
389 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
390 params.page_address = le32toh(page_req->page_address);
392 params.length = le32toh(page_req->len);
393 params.callback = NULL;
395 if ((error = mps_write_config_page(sc, ¶ms)) != 0) {
396 mps_printf(sc, "mps_write_cfg_page timed out\n");
400 page_req->ioc_status = htole16(params.status);
405 mpi_init_sge(struct mps_command *cm, void *req, void *sge)
409 space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
410 off = (uintptr_t)sge - (uintptr_t)req;
412 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
413 req, sge, off, space));
416 cm->cm_sglsize = space - off;
420 * Prepare the mps_command for an IOC_FACTS request.
423 mpi_pre_ioc_facts(struct mps_command *cm, struct mps_usr_command *cmd)
425 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
426 MPI2_IOC_FACTS_REPLY *rpl;
428 if (cmd->req_len != sizeof *req)
430 if (cmd->rpl_len != sizeof *rpl)
439 * Prepare the mps_command for a PORT_FACTS request.
442 mpi_pre_port_facts(struct mps_command *cm, struct mps_usr_command *cmd)
444 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
445 MPI2_PORT_FACTS_REPLY *rpl;
447 if (cmd->req_len != sizeof *req)
449 if (cmd->rpl_len != sizeof *rpl)
458 * Prepare the mps_command for a FW_DOWNLOAD request.
461 mpi_pre_fw_download(struct mps_command *cm, struct mps_usr_command *cmd)
463 MPI2_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
464 MPI2_FW_DOWNLOAD_REPLY *rpl;
465 MPI2_FW_DOWNLOAD_TCSGE tc;
469 * This code assumes there is room in the request's SGL for
470 * the TransactionContext plus at least a SGL chain element.
472 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
474 if (cmd->req_len != sizeof *req)
476 if (cmd->rpl_len != sizeof *rpl)
482 error = copyin(cmd->buf, cm->cm_data, cmd->len);
486 mpi_init_sge(cm, req, &req->SGL);
487 bzero(&tc, sizeof tc);
490 * For now, the F/W image must be provided in a single request.
492 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
494 if (req->TotalImageSize != cmd->len)
498 * The value of the first two elements is specified in the
499 * Fusion-MPT Message Passing Interface document.
502 tc.DetailsLength = 12;
504 tc.ImageSize = cmd->len;
506 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
508 return (mps_push_sge(cm, &tc, sizeof tc, 0));
512 * Prepare the mps_command for a FW_UPLOAD request.
515 mpi_pre_fw_upload(struct mps_command *cm, struct mps_usr_command *cmd)
517 MPI2_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
518 MPI2_FW_UPLOAD_REPLY *rpl;
519 MPI2_FW_UPLOAD_TCSGE tc;
522 * This code assumes there is room in the request's SGL for
523 * the TransactionContext plus at least a SGL chain element.
525 CTASSERT(sizeof req->SGL >= sizeof tc + MPS_SGC_SIZE);
527 if (cmd->req_len != sizeof *req)
529 if (cmd->rpl_len != sizeof *rpl)
532 mpi_init_sge(cm, req, &req->SGL);
533 bzero(&tc, sizeof tc);
536 * The value of the first two elements is specified in the
537 * Fusion-MPT Message Passing Interface document.
540 tc.DetailsLength = 12;
542 * XXX Is there any reason to fetch a partial image? I.e. to
543 * set ImageOffset to something other than 0?
546 tc.ImageSize = cmd->len;
548 cm->cm_flags |= MPS_CM_FLAGS_DATAIN;
550 return (mps_push_sge(cm, &tc, sizeof tc, 0));
554 * Prepare the mps_command for a SATA_PASSTHROUGH request.
557 mpi_pre_sata_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
559 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
560 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
562 if (cmd->req_len != sizeof *req)
564 if (cmd->rpl_len != sizeof *rpl)
567 mpi_init_sge(cm, req, &req->SGL);
572 * Prepare the mps_command for a SMP_PASSTHROUGH request.
575 mpi_pre_smp_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
577 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
578 MPI2_SMP_PASSTHROUGH_REPLY *rpl;
580 if (cmd->req_len != sizeof *req)
582 if (cmd->rpl_len != sizeof *rpl)
585 mpi_init_sge(cm, req, &req->SGL);
590 * Prepare the mps_command for a CONFIG request.
593 mpi_pre_config(struct mps_command *cm, struct mps_usr_command *cmd)
595 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
596 MPI2_CONFIG_REPLY *rpl;
598 if (cmd->req_len != sizeof *req)
600 if (cmd->rpl_len != sizeof *rpl)
603 mpi_init_sge(cm, req, &req->PageBufferSGE);
608 * Prepare the mps_command for a SAS_IO_UNIT_CONTROL request.
611 mpi_pre_sas_io_unit_control(struct mps_command *cm,
612 struct mps_usr_command *cmd)
621 * A set of functions to prepare an mps_command for the various
622 * supported requests.
624 struct mps_user_func {
627 } mps_user_func_list[] = {
628 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
629 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
630 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
631 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
632 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
633 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
634 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
635 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
636 { 0xFF, NULL } /* list end */
640 mps_user_setup_request(struct mps_command *cm, struct mps_usr_command *cmd)
642 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
643 struct mps_user_func *f;
645 for (f = mps_user_func_list; f->f_pre != NULL; f++) {
646 if (hdr->Function == f->Function)
647 return (f->f_pre(cm, cmd));
653 mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd)
655 MPI2_REQUEST_HEADER *hdr;
656 MPI2_DEFAULT_REPLY *rpl;
658 struct mps_command *cm = NULL;
663 cm = mps_alloc_command(sc);
666 mps_printf(sc, "mps_user_command: no mps requests\n");
672 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
674 mps_dprint(sc, MPS_INFO, "mps_user_command: req %p %d rpl %p %d\n",
675 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len );
677 if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
679 goto RetFreeUnlocked;
681 err = copyin(cmd->req, hdr, cmd->req_len);
683 goto RetFreeUnlocked;
685 mps_dprint(sc, MPS_INFO, "mps_user_command: Function %02X "
686 "MsgFlags %02X\n", hdr->Function, hdr->MsgFlags );
689 buf = kmalloc(cmd->len, M_MPSUSER, M_WAITOK|M_ZERO);
691 cm->cm_length = cmd->len;
697 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
698 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
700 err = mps_user_setup_request(cm, cmd);
702 mps_printf(sc, "mps_user_command: unsupported function 0x%X\n",
704 goto RetFreeUnlocked;
708 err = mps_wait_command(sc, cm, 60);
711 mps_printf(sc, "%s: invalid request: error %d\n",
716 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
718 sz = rpl->MsgLength * 4;
722 if (sz > cmd->rpl_len) {
724 "mps_user_command: reply buffer too small %d required %d\n",
731 copyout(rpl, cmd->rpl, sz);
733 copyout(buf, cmd->buf, cmd->len);
734 mps_dprint(sc, MPS_INFO, "mps_user_command: reply size %d\n", sz );
739 mps_free_command(sc, cm);
743 kfree(buf, M_MPSUSER);
748 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
750 MPI2_REQUEST_HEADER *hdr, tmphdr;
751 MPI2_DEFAULT_REPLY *rpl;
752 struct mps_command *cm = NULL;
753 int err = 0, dir = 0, sz;
754 uint8_t function = 0;
758 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
759 * bit to denote that a passthru is being processed.
762 if (sc->mps_flags & MPS_FLAGS_BUSY) {
763 mps_dprint(sc, MPS_INFO, "%s: Only one passthru command "
764 "allowed at a single time.", __func__);
768 sc->mps_flags |= MPS_FLAGS_BUSY;
772 * Do some validation on data direction. Valid cases are:
773 * 1) DataSize is 0 and direction is NONE
774 * 2) DataSize is non-zero and one of:
775 * a) direction is READ or
776 * b) direction is WRITE or
777 * c) direction is BOTH and DataOutSize is non-zero
778 * If valid and the direction is BOTH, change the direction to READ.
779 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
781 if (((data->DataSize == 0) &&
782 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
783 ((data->DataSize != 0) &&
784 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
785 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
786 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
787 (data->DataOutSize != 0))))) {
788 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
789 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
791 data->DataOutSize = 0;
795 mps_dprint(sc, MPS_INFO, "%s: req 0x%jx %d rpl 0x%jx %d "
796 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
797 data->PtrRequest, data->RequestSize, data->PtrReply,
798 data->ReplySize, data->PtrData, data->DataSize,
799 data->PtrDataOut, data->DataOutSize, data->DataDirection);
802 * copy in the header so we know what we're dealing with before we
803 * commit to allocating a command for it.
805 err = copyin(PTRIN(data->PtrRequest), &tmphdr, data->RequestSize);
807 goto RetFreeUnlocked;
809 if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
811 goto RetFreeUnlocked;
814 function = tmphdr.Function;
815 mps_dprint(sc, MPS_INFO, "%s: Function %02X MsgFlags %02X\n", __func__,
816 function, tmphdr.MsgFlags);
819 * Handle a passthru TM request.
821 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
822 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
825 cm = mpssas_alloc_tm(sc);
831 /* Copy the header in. Only a small fixup is needed. */
832 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
833 bcopy(&tmphdr, task, data->RequestSize);
834 task->TaskMID = cm->cm_desc.Default.SMID;
837 cm->cm_desc.HighPriority.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
838 cm->cm_complete = NULL;
839 cm->cm_complete_data = NULL;
841 err = mps_wait_command(sc, cm, 30);
845 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
849 * Copy the reply data and sense data to user space.
851 if (cm->cm_reply != NULL) {
852 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
853 sz = rpl->MsgLength * 4;
855 if (sz > data->ReplySize) {
856 mps_printf(sc, "%s: reply buffer too small: %d, "
857 "required: %d\n", __func__, data->ReplySize, sz);
861 copyout(cm->cm_reply, PTRIN(data->PtrReply),
866 mpssas_free_tm(sc, cm);
871 cm = mps_alloc_command(sc);
874 mps_printf(sc, "%s: no mps requests\n", __func__);
880 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
881 bcopy(&tmphdr, hdr, data->RequestSize);
884 * Do some checking to make sure the IOCTL request contains a valid
885 * request. Then set the SGL info.
887 mpi_init_sge(cm, hdr, (void *)((uint8_t *)hdr + data->RequestSize));
890 * Set up for read, write or both. From check above, DataOutSize will
891 * be 0 if direction is READ or WRITE, but it will have some non-zero
892 * value if the direction is BOTH. So, just use the biggest size to get
893 * the cm_data buffer size. If direction is BOTH, 2 SGLs need to be set
894 * up; the first is for the request and the second will contain the
895 * response data. cm_out_len needs to be set here and this will be used
896 * when the SGLs are set up.
899 cm->cm_length = MAX(data->DataSize, data->DataOutSize);
900 cm->cm_out_len = data->DataOutSize;
902 if (cm->cm_length != 0) {
903 cm->cm_data = kmalloc(cm->cm_length, M_MPSUSER, M_WAITOK |
905 if (cm->cm_data == NULL) {
906 mps_dprint(sc, MPS_FAULT, "%s: alloc failed for IOCTL "
907 "passthru length %d\n", __func__, cm->cm_length);
909 cm->cm_flags = MPS_CM_FLAGS_DATAIN;
910 if (data->DataOutSize) {
911 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
912 err = copyin(PTRIN(data->PtrDataOut),
913 cm->cm_data, data->DataOutSize);
914 } else if (data->DataDirection ==
915 MPS_PASS_THRU_DIRECTION_WRITE) {
916 cm->cm_flags = MPS_CM_FLAGS_DATAOUT;
917 err = copyin(PTRIN(data->PtrData),
918 cm->cm_data, data->DataSize);
921 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
922 "IOCTL data from user space\n", __func__);
925 cm->cm_flags |= MPS_CM_FLAGS_SGE_SIMPLE;
926 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
929 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
930 * uses SCSI IO descriptor.
932 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
933 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
934 MPI2_SCSI_IO_REQUEST *scsi_io_req;
936 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
938 * Put SGE for data and data_out buffer at the end of
939 * scsi_io_request message header (64 bytes in total).
940 * Following above SGEs, the residual space will be used by
943 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
945 scsi_io_req->SenseBufferLowAddress = cm->cm_sense_busaddr;
948 * Set SGLOffset0 value. This is the number of dwords that SGL
949 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
951 scsi_io_req->SGLOffset0 = 24;
954 * Setup descriptor info. RAID passthrough must use the
955 * default request descriptor which is already set, so if this
956 * is a SCSI IO request, change the descriptor to SCSI IO.
957 * Also, if this is a SCSI IO request, handle the reply in the
958 * mpssas_scsio_complete function.
960 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
961 cm->cm_desc.SCSIIO.RequestFlags =
962 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
963 cm->cm_desc.SCSIIO.DevHandle = scsi_io_req->DevHandle;
966 * Make sure the DevHandle is not 0 because this is a
969 if (scsi_io_req->DevHandle == 0) {
971 goto RetFreeUnlocked;
978 err = mps_wait_command(sc, cm, 30);
981 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
984 goto RetFreeUnlocked;
988 * Sync the DMA data, if any. Then copy the data to user space.
990 if (cm->cm_data != NULL) {
991 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN)
992 dir = BUS_DMASYNC_POSTREAD;
993 else if (cm->cm_flags & MPS_CM_FLAGS_DATAOUT)
994 dir = BUS_DMASYNC_POSTWRITE;
995 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
996 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
998 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN) {
1000 err = copyout(cm->cm_data,
1001 PTRIN(data->PtrData), data->DataSize);
1004 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1005 "IOCTL data to user space\n", __func__);
1010 * Copy the reply data and sense data to user space.
1012 if (cm->cm_reply != NULL) {
1013 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1014 sz = rpl->MsgLength * 4;
1016 if (sz > data->ReplySize) {
1017 mps_printf(sc, "%s: reply buffer too small: %d, "
1018 "required: %d\n", __func__, data->ReplySize, sz);
1022 copyout(cm->cm_reply, PTRIN(data->PtrReply),
1027 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
1028 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1029 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1030 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1032 MIN(((MPI2_SCSI_IO_REPLY *)rpl)->SenseCount,
1033 sizeof(struct scsi_sense_data));
1035 copyout(cm->cm_sense, cm->cm_req + 64, sense_len);
1047 kfree(cm->cm_data, M_MPSUSER);
1048 mps_free_command(sc, cm);
1051 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1058 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1060 Mpi2ConfigReply_t mpi_reply;
1061 Mpi2BiosPage3_t config_page;
1064 * Use the PCI interface functions to get the Bus, Device, and Function
1067 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1068 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1069 data->PciInformation.u.bits.FunctionNumber =
1070 pci_get_function(sc->mps_dev);
1073 * Get the FW version that should already be saved in IOC Facts.
1075 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1078 * General device info.
1080 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1081 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1082 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1083 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1084 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1085 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1086 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1089 * Get the driver version.
1091 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1094 * Need to get BIOS Config Page 3 for the BIOS Version.
1096 data->BiosVersion = 0;
1098 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1099 kprintf("%s: Error while retrieving BIOS Version\n", __func__);
1101 data->BiosVersion = config_page.BiosVersion;
1106 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1111 * Use the PCI interface functions to get the Bus, Device, and Function
1114 data->BusNumber = pci_get_bus(sc->mps_dev);
1115 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1116 data->FunctionNumber = pci_get_function(sc->mps_dev);
1119 * Now get the interrupt vector and the pci header. The vector can
1120 * only be 0 right now. The header is the first 256 bytes of config
1123 data->InterruptVector = 0;
1124 for (i = 0; i < sizeof (data->PciHeader); i++) {
1125 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1130 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1134 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1135 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1140 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1144 mps_post_fw_diag_buffer(struct mps_softc *sc,
1145 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1147 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1148 MPI2_DIAG_BUFFER_POST_REPLY *reply;
1149 struct mps_command *cm = NULL;
1153 * If buffer is not enabled, just leave.
1155 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1156 if (!pBuffer->enabled) {
1157 return (MPS_DIAG_FAILURE);
1161 * Clear some flags initially.
1163 pBuffer->force_release = FALSE;
1164 pBuffer->valid_data = FALSE;
1165 pBuffer->owned_by_firmware = FALSE;
1170 cm = mps_alloc_command(sc);
1172 mps_printf(sc, "%s: no mps requests\n", __func__);
1173 return (MPS_DIAG_FAILURE);
1177 * Build the request for releasing the FW Diag Buffer and send it.
1179 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1180 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1181 req->BufferType = pBuffer->buffer_type;
1182 req->ExtendedType = pBuffer->extended_type;
1183 req->BufferLength = pBuffer->size;
1184 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1185 req->ProductSpecific[i] = pBuffer->product_specific[i];
1186 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1189 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1190 cm->cm_complete_data = NULL;
1193 * Send command synchronously.
1195 status = mps_wait_command(sc, cm, 30);
1197 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1199 status = MPS_DIAG_FAILURE;
1204 * Process POST reply.
1206 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1207 if (reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) {
1208 status = MPS_DIAG_FAILURE;
1209 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1210 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1211 "TransferLength = 0x%x\n", __func__, reply->IOCStatus,
1212 reply->IOCLogInfo, reply->TransferLength);
1217 * Post was successful.
1219 pBuffer->valid_data = TRUE;
1220 pBuffer->owned_by_firmware = TRUE;
1221 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1222 status = MPS_DIAG_SUCCESS;
1225 mps_free_command(sc, cm);
1230 mps_release_fw_diag_buffer(struct mps_softc *sc,
1231 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1234 MPI2_DIAG_RELEASE_REQUEST *req;
1235 MPI2_DIAG_RELEASE_REPLY *reply;
1236 struct mps_command *cm = NULL;
1240 * If buffer is not enabled, just leave.
1242 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1243 if (!pBuffer->enabled) {
1244 mps_dprint(sc, MPS_INFO, "%s: This buffer type is not supported "
1245 "by the IOC", __func__);
1246 return (MPS_DIAG_FAILURE);
1250 * Clear some flags initially.
1252 pBuffer->force_release = FALSE;
1253 pBuffer->valid_data = FALSE;
1254 pBuffer->owned_by_firmware = FALSE;
1259 cm = mps_alloc_command(sc);
1261 mps_printf(sc, "%s: no mps requests\n", __func__);
1262 return (MPS_DIAG_FAILURE);
1266 * Build the request for releasing the FW Diag Buffer and send it.
1268 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1269 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1270 req->BufferType = pBuffer->buffer_type;
1273 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1274 cm->cm_complete_data = NULL;
1277 * Send command synchronously.
1279 status = mps_wait_command(sc, cm, 30);
1281 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1283 status = MPS_DIAG_FAILURE;
1288 * Process RELEASE reply.
1290 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1291 if ((reply->IOCStatus != MPI2_IOCSTATUS_SUCCESS) ||
1292 pBuffer->owned_by_firmware) {
1293 status = MPS_DIAG_FAILURE;
1294 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1295 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1296 __func__, reply->IOCStatus, reply->IOCLogInfo);
1301 * Release was successful.
1303 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1304 status = MPS_DIAG_SUCCESS;
1307 * If this was for an UNREGISTER diag type command, clear the unique ID.
1309 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1310 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1318 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1319 uint32_t *return_code)
1321 mps_fw_diagnostic_buffer_t *pBuffer;
1322 uint8_t extended_type, buffer_type, i;
1323 uint32_t buffer_size;
1327 extended_type = diag_register->ExtendedType;
1328 buffer_type = diag_register->BufferType;
1329 buffer_size = diag_register->RequestedBufferSize;
1330 unique_id = diag_register->UniqueId;
1333 * Check for valid buffer type
1335 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1336 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1337 return (MPS_DIAG_FAILURE);
1341 * Get the current buffer and look up the unique ID. The unique ID
1342 * should not be found. If it is, the ID is already in use.
1344 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1345 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1346 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1347 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1348 return (MPS_DIAG_FAILURE);
1352 * The buffer's unique ID should not be registered yet, and the given
1353 * unique ID cannot be 0.
1355 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1356 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1357 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1358 return (MPS_DIAG_FAILURE);
1362 * If this buffer is already posted as immediate, just change owner.
1364 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1365 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1366 pBuffer->immediate = FALSE;
1367 pBuffer->unique_id = unique_id;
1368 return (MPS_DIAG_SUCCESS);
1372 * Post a new buffer after checking if it's enabled. The DMA buffer
1373 * that is allocated will be contiguous (nsegments = 1).
1375 if (!pBuffer->enabled) {
1376 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1377 return (MPS_DIAG_FAILURE);
1379 if (bus_dma_tag_create( sc->mps_parent_dmat, /* parent */
1380 1, 0, /* algnmnt, boundary */
1381 BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
1382 BUS_SPACE_MAXADDR, /* highaddr */
1383 NULL, NULL, /* filter, filterarg */
1384 buffer_size, /* maxsize */
1386 buffer_size, /* maxsegsize */
1388 &sc->fw_diag_dmat)) {
1389 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer DMA "
1393 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1394 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1395 device_printf(sc->mps_dev, "Cannot allocate FW diag buffer "
1399 bzero(sc->fw_diag_buffer, buffer_size);
1400 bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map, sc->fw_diag_buffer,
1401 buffer_size, mps_memaddr_cb, &sc->fw_diag_busaddr, 0);
1402 pBuffer->size = buffer_size;
1405 * Copy the given info to the diag buffer and post the buffer.
1407 pBuffer->buffer_type = buffer_type;
1408 pBuffer->immediate = FALSE;
1409 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1410 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1412 pBuffer->product_specific[i] =
1413 diag_register->ProductSpecific[i];
1416 pBuffer->extended_type = extended_type;
1417 pBuffer->unique_id = unique_id;
1418 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1421 * In case there was a failure, free the DMA buffer.
1423 if (status == MPS_DIAG_FAILURE) {
1424 if (sc->fw_diag_busaddr != 0)
1425 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1426 if (sc->fw_diag_buffer != NULL)
1427 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1429 if (sc->fw_diag_dmat != NULL)
1430 bus_dma_tag_destroy(sc->fw_diag_dmat);
1437 mps_diag_unregister(struct mps_softc *sc,
1438 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1440 mps_fw_diagnostic_buffer_t *pBuffer;
1445 unique_id = diag_unregister->UniqueId;
1448 * Get the current buffer and look up the unique ID. The unique ID
1451 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1452 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1453 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1454 return (MPS_DIAG_FAILURE);
1457 pBuffer = &sc->fw_diag_buffer_list[i];
1460 * Try to release the buffer from FW before freeing it. If release
1461 * fails, don't free the DMA buffer in case FW tries to access it
1462 * later. If buffer is not owned by firmware, can't release it.
1464 if (!pBuffer->owned_by_firmware) {
1465 status = MPS_DIAG_SUCCESS;
1467 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1468 MPS_FW_DIAG_TYPE_UNREGISTER);
1472 * At this point, return the current status no matter what happens with
1475 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1476 if (status == MPS_DIAG_SUCCESS) {
1477 if (sc->fw_diag_busaddr != 0)
1478 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1479 if (sc->fw_diag_buffer != NULL)
1480 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1482 if (sc->fw_diag_dmat != NULL)
1483 bus_dma_tag_destroy(sc->fw_diag_dmat);
1490 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1491 uint32_t *return_code)
1493 mps_fw_diagnostic_buffer_t *pBuffer;
1497 unique_id = diag_query->UniqueId;
1500 * If ID is valid, query on ID.
1501 * If ID is invalid, query on buffer type.
1503 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1504 i = diag_query->BufferType;
1505 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1506 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1507 return (MPS_DIAG_FAILURE);
1510 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1511 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1512 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1513 return (MPS_DIAG_FAILURE);
1518 * Fill query structure with the diag buffer info.
1520 pBuffer = &sc->fw_diag_buffer_list[i];
1521 diag_query->BufferType = pBuffer->buffer_type;
1522 diag_query->ExtendedType = pBuffer->extended_type;
1523 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1524 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1526 diag_query->ProductSpecific[i] =
1527 pBuffer->product_specific[i];
1530 diag_query->TotalBufferSize = pBuffer->size;
1531 diag_query->DriverAddedBufferSize = 0;
1532 diag_query->UniqueId = pBuffer->unique_id;
1533 diag_query->ApplicationFlags = 0;
1534 diag_query->DiagnosticFlags = 0;
1537 * Set/Clear application flags
1539 if (pBuffer->immediate) {
1540 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1542 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1544 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1545 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1547 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1549 if (pBuffer->owned_by_firmware) {
1550 diag_query->ApplicationFlags |=
1551 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1553 diag_query->ApplicationFlags &=
1554 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1557 return (MPS_DIAG_SUCCESS);
1561 mps_diag_read_buffer(struct mps_softc *sc,
1562 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1563 uint32_t *return_code)
1565 mps_fw_diagnostic_buffer_t *pBuffer;
1570 unique_id = diag_read_buffer->UniqueId;
1573 * Get the current buffer and look up the unique ID. The unique ID
1576 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1577 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1578 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1579 return (MPS_DIAG_FAILURE);
1582 pBuffer = &sc->fw_diag_buffer_list[i];
1585 * Make sure requested read is within limits
1587 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1589 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1590 return (MPS_DIAG_FAILURE);
1594 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1595 * buffer that was allocated is one contiguous buffer.
1597 pData = (uint8_t *)(sc->fw_diag_buffer +
1598 diag_read_buffer->StartingOffset);
1599 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1600 return (MPS_DIAG_FAILURE);
1601 diag_read_buffer->Status = 0;
1604 * Set or clear the Force Release flag.
1606 if (pBuffer->force_release) {
1607 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1609 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1613 * If buffer is to be reregistered, make sure it's not already owned by
1616 status = MPS_DIAG_SUCCESS;
1617 if (!pBuffer->owned_by_firmware) {
1618 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1619 status = mps_post_fw_diag_buffer(sc, pBuffer,
1628 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1629 uint32_t *return_code)
1631 mps_fw_diagnostic_buffer_t *pBuffer;
1636 unique_id = diag_release->UniqueId;
1639 * Get the current buffer and look up the unique ID. The unique ID
1642 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1643 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1644 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1645 return (MPS_DIAG_FAILURE);
1648 pBuffer = &sc->fw_diag_buffer_list[i];
1651 * If buffer is not owned by firmware, it's already been released.
1653 if (!pBuffer->owned_by_firmware) {
1654 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1655 return (MPS_DIAG_FAILURE);
1659 * Release the buffer.
1661 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1662 MPS_FW_DIAG_TYPE_RELEASE);
1667 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1668 uint32_t length, uint32_t *return_code)
1670 mps_fw_diag_register_t diag_register;
1671 mps_fw_diag_unregister_t diag_unregister;
1672 mps_fw_diag_query_t diag_query;
1673 mps_diag_read_buffer_t diag_read_buffer;
1674 mps_fw_diag_release_t diag_release;
1675 int status = MPS_DIAG_SUCCESS;
1676 uint32_t original_return_code;
1678 original_return_code = *return_code;
1679 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1682 case MPS_FW_DIAG_TYPE_REGISTER:
1685 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1686 status = MPS_DIAG_FAILURE;
1689 if (copyin(diag_action, &diag_register,
1690 sizeof(diag_register)) != 0)
1691 return (MPS_DIAG_FAILURE);
1692 status = mps_diag_register(sc, &diag_register,
1696 case MPS_FW_DIAG_TYPE_UNREGISTER:
1697 if (length < sizeof(diag_unregister)) {
1699 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1700 status = MPS_DIAG_FAILURE;
1703 if (copyin(diag_action, &diag_unregister,
1704 sizeof(diag_unregister)) != 0)
1705 return (MPS_DIAG_FAILURE);
1706 status = mps_diag_unregister(sc, &diag_unregister,
1710 case MPS_FW_DIAG_TYPE_QUERY:
1711 if (length < sizeof (diag_query)) {
1713 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1714 status = MPS_DIAG_FAILURE;
1717 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1719 return (MPS_DIAG_FAILURE);
1720 status = mps_diag_query(sc, &diag_query, return_code);
1721 if (status == MPS_DIAG_SUCCESS)
1722 if (copyout(&diag_query, diag_action,
1723 sizeof (diag_query)) != 0)
1724 return (MPS_DIAG_FAILURE);
1727 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1728 if (copyin(diag_action, &diag_read_buffer,
1729 sizeof(diag_read_buffer)) != 0)
1730 return (MPS_DIAG_FAILURE);
1731 if (length < diag_read_buffer.BytesToRead) {
1733 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1734 status = MPS_DIAG_FAILURE;
1737 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1738 PTRIN(diag_read_buffer.PtrDataBuffer),
1740 if (status == MPS_DIAG_SUCCESS) {
1741 if (copyout(&diag_read_buffer, diag_action,
1742 sizeof(diag_read_buffer) -
1743 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1745 return (MPS_DIAG_FAILURE);
1749 case MPS_FW_DIAG_TYPE_RELEASE:
1750 if (length < sizeof(diag_release)) {
1752 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1753 status = MPS_DIAG_FAILURE;
1756 if (copyin(diag_action, &diag_release,
1757 sizeof(diag_release)) != 0)
1758 return (MPS_DIAG_FAILURE);
1759 status = mps_diag_release(sc, &diag_release,
1764 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1765 status = MPS_DIAG_FAILURE;
1769 if ((status == MPS_DIAG_FAILURE) &&
1770 (original_return_code == MPS_FW_DIAG_NEW) &&
1771 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1772 status = MPS_DIAG_SUCCESS;
1778 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1783 * Only allow one diag action at one time.
1785 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1786 mps_dprint(sc, MPS_INFO, "%s: Only one FW diag command "
1787 "allowed at a single time.", __func__);
1790 sc->mps_flags |= MPS_FLAGS_BUSY;
1793 * Send diag action request
1795 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1796 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1797 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1798 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1799 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1800 status = mps_do_diag_action(sc, data->Action,
1801 PTRIN(data->PtrDiagAction), data->Length,
1806 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1811 * Copy the event recording mask and the event queue size out. For
1812 * clarification, the event recording mask (events_to_record) is not the same
1813 * thing as the event mask (event_mask). events_to_record has a bit set for
1814 * every event type that is to be recorded by the driver, and event_mask has a
1815 * bit cleared for every event that is allowed into the driver from the IOC.
1816 * They really have nothing to do with each other.
1819 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1824 data->Entries = MPS_EVENT_QUEUE_SIZE;
1826 for (i = 0; i < 4; i++) {
1827 data->Types[i] = sc->events_to_record[i];
1833 * Set the driver's event mask according to what's been given. See
1834 * mps_user_event_query for explanation of the event recording mask and the IOC
1835 * event mask. It's the app's responsibility to enable event logging by setting
1836 * the bits in events_to_record. Initially, no events will be logged.
1839 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1844 for (i = 0; i < 4; i++) {
1845 sc->events_to_record[i] = data->Types[i];
1851 * Copy out the events that have been recorded, up to the max events allowed.
1854 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1861 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1863 if (copyout((void *)sc->recorded_events,
1864 PTRIN(data->PtrEvents), size) != 0)
1869 * data->Size value is not large enough to copy event data.
1875 * Change size value to match the number of bytes that were copied.
1878 data->Size = sizeof(sc->recorded_events);
1885 * Record events into the driver from the IOC if they are not masked.
1888 mpssas_record_event(struct mps_softc *sc,
1889 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1893 uint16_t event_data_len;
1894 boolean_t sendAEN = FALSE;
1896 event = event_reply->Event;
1899 * Generate a system event to let anyone who cares know that a
1900 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
1901 * event mask is set to.
1903 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
1908 * Record the event only if its corresponding bit is set in
1909 * events_to_record. event_index is the index into recorded_events and
1910 * event_number is the overall number of an event being recorded since
1911 * start-of-day. event_index will roll over; event_number will never
1914 i = (uint8_t)(event / 32);
1915 j = (uint8_t)(event % 32);
1916 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
1917 i = sc->event_index;
1918 sc->recorded_events[i].Type = event;
1919 sc->recorded_events[i].Number = ++sc->event_number;
1920 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
1922 event_data_len = event_reply->EventDataLength;
1924 if (event_data_len > 0) {
1926 * Limit data to size in m_event entry
1928 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
1929 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
1931 for (j = 0; j < event_data_len; j++) {
1932 sc->recorded_events[i].Data[j] =
1933 event_reply->EventData[j];
1937 * check for index wrap-around
1939 if (++i == MPS_EVENT_QUEUE_SIZE) {
1942 sc->event_index = (uint8_t)i;
1945 * Set flag to send the event.
1952 * Generate a system event if flag is set to let anyone who cares know
1953 * that an event has occurred.
1956 //SLM-how to send a system event (see kqueue, kevent)
1957 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
1958 // "SAS", NULL, NULL, DDI_NOSLEEP);
1963 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
1967 switch (data->Command) {
1969 * IO access is not supported.
1973 mps_dprint(sc, MPS_INFO, "IO access is not supported. "
1974 "Use memory access.");
1979 data->RegData = mps_regread(sc, data->RegOffset);
1983 mps_regwrite(sc, data->RegOffset, data->RegData);
1995 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
1997 uint8_t bt2dh = FALSE;
1998 uint8_t dh2bt = FALSE;
1999 uint16_t dev_handle, bus, target;
2002 target = data->TargetID;
2003 dev_handle = data->DevHandle;
2006 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2007 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2008 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2011 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2013 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2015 if (!dh2bt && !bt2dh)
2019 * Only handle bus of 0. Make sure target is within range.
2025 if (target > sc->max_devices) {
2026 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2027 "for Bus/Target to DevHandle mapping.");
2030 dev_handle = sc->mapping_table[target].dev_handle;
2032 data->DevHandle = dev_handle;
2035 target = mps_mapping_get_sas_id_from_handle(sc, dev_handle);
2037 data->TargetID = target;
2044 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag)
2046 struct mps_softc *sc;
2047 struct mps_cfg_page_req *page_req;
2048 struct mps_ext_cfg_page_req *ext_page_req;
2050 int error, reset_loop;
2058 case MPSIO_READ_CFG_HEADER:
2060 error = mps_user_read_cfg_header(sc, page_req);
2063 case MPSIO_READ_CFG_PAGE:
2064 mps_page = kmalloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2065 error = copyin(page_req->buf, mps_page,
2066 sizeof(MPI2_CONFIG_PAGE_HEADER));
2070 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2074 error = copyout(mps_page, page_req->buf, page_req->len);
2076 case MPSIO_READ_EXT_CFG_HEADER:
2078 error = mps_user_read_extcfg_header(sc, ext_page_req);
2081 case MPSIO_READ_EXT_CFG_PAGE:
2082 mps_page = kmalloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2083 error = copyin(ext_page_req->buf, mps_page,
2084 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2088 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2092 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2094 case MPSIO_WRITE_CFG_PAGE:
2095 mps_page = kmalloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2096 error = copyin(page_req->buf, mps_page, page_req->len);
2100 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2103 case MPSIO_MPS_COMMAND:
2104 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2106 case MPTIOCTL_PASS_THRU:
2108 * The user has requested to pass through a command to be
2109 * executed by the MPT firmware. Call our routine which does
2110 * this. Only allow one passthru IOCTL at one time.
2112 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2114 case MPTIOCTL_GET_ADAPTER_DATA:
2116 * The user has requested to read adapter data. Call our
2117 * routine which does this.
2120 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2122 case MPTIOCTL_GET_PCI_INFO:
2124 * The user has requested to read pci info. Call
2125 * our routine which does this.
2129 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2132 case MPTIOCTL_RESET_ADAPTER:
2134 sc->port_enable_complete = 0;
2135 error = mps_reinit(sc);
2138 * Wait no more than 5 minutes for Port Enable to complete
2140 for (reset_loop = 0; (reset_loop < MPS_DIAG_RESET_TIMEOUT) &&
2141 (!sc->port_enable_complete); reset_loop++) {
2144 if (reset_loop == MPS_DIAG_RESET_TIMEOUT) {
2145 kprintf("Port Enable did not complete after Diag "
2149 case MPTIOCTL_DIAG_ACTION:
2151 * The user has done a diag buffer action. Call our routine
2152 * which does this. Only allow one diag action at one time.
2155 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2158 case MPTIOCTL_EVENT_QUERY:
2160 * The user has done an event query. Call our routine which does
2164 mps_user_event_query(sc, (mps_event_query_t *)arg);
2166 case MPTIOCTL_EVENT_ENABLE:
2168 * The user has done an event enable. Call our routine which
2172 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2174 case MPTIOCTL_EVENT_REPORT:
2176 * The user has done an event report. Call our routine which
2179 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2181 case MPTIOCTL_REG_ACCESS:
2183 * The user has requested register access. Call our routine
2187 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2190 case MPTIOCTL_BTDH_MAPPING:
2192 * The user has requested to translate a bus/target to a
2193 * DevHandle or a DevHandle to a bus/target. Call our routine
2196 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2203 if (mps_page != NULL)
2204 kfree(mps_page, M_MPSUSER);
2209 #ifdef COMPAT_FREEBSD32
2211 struct mps_cfg_page_req32 {
2212 MPI2_CONFIG_PAGE_HEADER header;
2213 uint32_t page_address;
2216 uint16_t ioc_status;
2219 struct mps_ext_cfg_page_req32 {
2220 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2221 uint32_t page_address;
2224 uint16_t ioc_status;
2227 struct mps_raid_action32 {
2231 uint8_t phys_disk_num;
2232 uint32_t action_data_word;
2235 uint32_t volume_status;
2236 uint32_t action_data[4];
2237 uint16_t action_status;
2238 uint16_t ioc_status;
2242 struct mps_usr_command32 {
2252 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2253 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2254 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2255 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2256 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2257 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2258 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2261 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2264 struct mps_cfg_page_req32 *page32 = _arg;
2265 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2266 struct mps_raid_action32 *raid32 = _arg;
2267 struct mps_usr_command32 *user32 = _arg;
2269 struct mps_cfg_page_req page;
2270 struct mps_ext_cfg_page_req ext;
2271 struct mps_raid_action raid;
2272 struct mps_usr_command user;
2278 case MPSIO_READ_CFG_HEADER32:
2279 case MPSIO_READ_CFG_PAGE32:
2280 case MPSIO_WRITE_CFG_PAGE32:
2281 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2282 cmd = MPSIO_READ_CFG_HEADER;
2283 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2284 cmd = MPSIO_READ_CFG_PAGE;
2286 cmd = MPSIO_WRITE_CFG_PAGE;
2287 CP(*page32, arg.page, header);
2288 CP(*page32, arg.page, page_address);
2289 PTRIN_CP(*page32, arg.page, buf);
2290 CP(*page32, arg.page, len);
2291 CP(*page32, arg.page, ioc_status);
2294 case MPSIO_READ_EXT_CFG_HEADER32:
2295 case MPSIO_READ_EXT_CFG_PAGE32:
2296 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2297 cmd = MPSIO_READ_EXT_CFG_HEADER;
2299 cmd = MPSIO_READ_EXT_CFG_PAGE;
2300 CP(*ext32, arg.ext, header);
2301 CP(*ext32, arg.ext, page_address);
2302 PTRIN_CP(*ext32, arg.ext, buf);
2303 CP(*ext32, arg.ext, len);
2304 CP(*ext32, arg.ext, ioc_status);
2307 case MPSIO_RAID_ACTION32:
2308 cmd = MPSIO_RAID_ACTION;
2309 CP(*raid32, arg.raid, action);
2310 CP(*raid32, arg.raid, volume_bus);
2311 CP(*raid32, arg.raid, volume_id);
2312 CP(*raid32, arg.raid, phys_disk_num);
2313 CP(*raid32, arg.raid, action_data_word);
2314 PTRIN_CP(*raid32, arg.raid, buf);
2315 CP(*raid32, arg.raid, len);
2316 CP(*raid32, arg.raid, volume_status);
2317 bcopy(raid32->action_data, arg.raid.action_data,
2318 sizeof arg.raid.action_data);
2319 CP(*raid32, arg.raid, ioc_status);
2320 CP(*raid32, arg.raid, write);
2323 case MPSIO_MPS_COMMAND32:
2324 cmd = MPSIO_MPS_COMMAND;
2325 PTRIN_CP(*user32, arg.user, req);
2326 CP(*user32, arg.user, req_len);
2327 PTRIN_CP(*user32, arg.user, rpl);
2328 CP(*user32, arg.user, rpl_len);
2329 PTRIN_CP(*user32, arg.user, buf);
2330 CP(*user32, arg.user, len);
2331 CP(*user32, arg.user, flags);
2337 error = mps_ioctl(dev, cmd, &arg, flag, td);
2338 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2340 case MPSIO_READ_CFG_HEADER32:
2341 case MPSIO_READ_CFG_PAGE32:
2342 case MPSIO_WRITE_CFG_PAGE32:
2343 CP(arg.page, *page32, header);
2344 CP(arg.page, *page32, page_address);
2345 PTROUT_CP(arg.page, *page32, buf);
2346 CP(arg.page, *page32, len);
2347 CP(arg.page, *page32, ioc_status);
2350 case MPSIO_READ_EXT_CFG_HEADER32:
2351 case MPSIO_READ_EXT_CFG_PAGE32:
2352 CP(arg.ext, *ext32, header);
2353 CP(arg.ext, *ext32, page_address);
2354 PTROUT_CP(arg.ext, *ext32, buf);
2355 CP(arg.ext, *ext32, len);
2356 CP(arg.ext, *ext32, ioc_status);
2359 case MPSIO_RAID_ACTION32:
2360 CP(arg.raid, *raid32, action);
2361 CP(arg.raid, *raid32, volume_bus);
2362 CP(arg.raid, *raid32, volume_id);
2363 CP(arg.raid, *raid32, phys_disk_num);
2364 CP(arg.raid, *raid32, action_data_word);
2365 PTROUT_CP(arg.raid, *raid32, buf);
2366 CP(arg.raid, *raid32, len);
2367 CP(arg.raid, *raid32, volume_status);
2368 bcopy(arg.raid.action_data, raid32->action_data,
2369 sizeof arg.raid.action_data);
2370 CP(arg.raid, *raid32, ioc_status);
2371 CP(arg.raid, *raid32, write);
2374 case MPSIO_MPS_COMMAND32:
2375 PTROUT_CP(arg.user, *user32, req);
2376 CP(arg.user, *user32, req_len);
2377 PTROUT_CP(arg.user, *user32, rpl);
2378 CP(arg.user, *user32, rpl_len);
2379 PTROUT_CP(arg.user, *user32, buf);
2380 CP(arg.user, *user32, len);
2381 CP(arg.user, *user32, flags);
2388 #endif /* COMPAT_FREEBSD32 */
2391 mps_ioctl_devsw(struct dev_ioctl_args *ap)
2393 cdev_t dev = ap->a_head.a_dev;
2394 u_long com = ap->a_cmd;
2395 caddr_t arg = ap->a_data;
2396 int flag = ap->a_fflag;
2398 #ifdef COMPAT_FREEBSD32
2399 if (SV_CURPROC_FLAG(SV_ILP32))
2400 return (mps_ioctl32(dev, com, arg, flag, td));
2402 return (mps_ioctl(dev, com, arg, flag));