2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2008 Yahoo!, Inc.
6 * Written by: John Baldwin <jhb@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD userland interface
35 * Copyright (c) 2011-2015 LSI Corp.
36 * Copyright (c) 2013-2015 Avago Technologies
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
48 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
63 #include <sys/cdefs.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/selinfo.h>
70 #include <sys/module.h>
74 #include <sys/abi_compat.h>
75 #include <sys/malloc.h>
77 #include <sys/sysctl.h>
78 #include <sys/ioccom.h>
79 #include <sys/endian.h>
80 #include <sys/queue.h>
81 #include <sys/kthread.h>
82 #include <sys/taskqueue.h>
84 #include <sys/sysent.h>
86 #include <machine/bus.h>
87 #include <machine/resource.h>
91 #include <cam/cam_ccb.h>
92 #include <cam/scsi/scsi_all.h>
94 #include <dev/mps/mpi/mpi2_type.h>
95 #include <dev/mps/mpi/mpi2.h>
96 #include <dev/mps/mpi/mpi2_ioc.h>
97 #include <dev/mps/mpi/mpi2_cnfg.h>
98 #include <dev/mps/mpi/mpi2_init.h>
99 #include <dev/mps/mpi/mpi2_tool.h>
100 #include <dev/mps/mps_ioctl.h>
101 #include <dev/mps/mpsvar.h>
102 #include <dev/mps/mps_table.h>
103 #include <dev/mps/mps_sas.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 MALLOC_DEFINE(M_MPSUSER, "mps_user", "Buffers for mps(4) ioctls");
181 mps_attach_user(struct mps_softc *sc)
185 unit = device_get_unit(sc->mps_dev);
186 sc->mps_cdev = make_dev(&mps_cdevsw, unit, UID_ROOT, GID_OPERATOR, 0640,
188 if (sc->mps_cdev == NULL) {
191 sc->mps_cdev->si_drv1 = sc;
196 mps_detach_user(struct mps_softc *sc)
199 /* XXX: do a purge of pending requests? */
200 if (sc->mps_cdev != NULL)
201 destroy_dev(sc->mps_cdev);
205 mps_open(struct cdev *dev, int flags, int fmt, struct thread *td)
212 mps_close(struct cdev *dev, int flags, int fmt, struct thread *td)
219 mps_user_read_cfg_header(struct mps_softc *sc,
220 struct mps_cfg_page_req *page_req)
222 MPI2_CONFIG_PAGE_HEADER *hdr;
223 struct mps_config_params params;
226 hdr = ¶ms.hdr.Struct;
227 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
228 params.page_address = le32toh(page_req->page_address);
229 hdr->PageVersion = 0;
231 hdr->PageNumber = page_req->header.PageNumber;
232 hdr->PageType = page_req->header.PageType;
233 params.buffer = NULL;
235 params.callback = NULL;
237 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
239 * Leave the request. Without resetting the chip, it's
240 * still owned by it and we'll just get into trouble
241 * freeing it now. Mark it as abandoned so that if it
242 * shows up later it can be freed.
244 mps_printf(sc, "read_cfg_header timed out\n");
248 page_req->ioc_status = htole16(params.status);
249 if ((page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
250 MPI2_IOCSTATUS_SUCCESS) {
251 bcopy(hdr, &page_req->header, sizeof(page_req->header));
258 mps_user_read_cfg_page(struct mps_softc *sc, struct mps_cfg_page_req *page_req,
261 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
262 struct mps_config_params params;
266 hdr = ¶ms.hdr.Struct;
267 hdr->PageVersion = reqhdr->PageVersion;
268 hdr->PageLength = reqhdr->PageLength;
269 hdr->PageNumber = reqhdr->PageNumber;
270 hdr->PageType = reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK;
271 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
272 params.page_address = le32toh(page_req->page_address);
274 params.length = le32toh(page_req->len);
275 params.callback = NULL;
277 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
278 mps_printf(sc, "mps_user_read_cfg_page timed out\n");
282 page_req->ioc_status = htole16(params.status);
287 mps_user_read_extcfg_header(struct mps_softc *sc,
288 struct mps_ext_cfg_page_req *ext_page_req)
290 MPI2_CONFIG_EXTENDED_PAGE_HEADER *hdr;
291 struct mps_config_params params;
294 hdr = ¶ms.hdr.Ext;
295 params.action = MPI2_CONFIG_ACTION_PAGE_HEADER;
296 hdr->PageVersion = ext_page_req->header.PageVersion;
297 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
298 hdr->ExtPageLength = 0;
299 hdr->PageNumber = ext_page_req->header.PageNumber;
300 hdr->ExtPageType = ext_page_req->header.ExtPageType;
301 params.page_address = le32toh(ext_page_req->page_address);
302 params.buffer = NULL;
304 params.callback = NULL;
306 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
308 * Leave the request. Without resetting the chip, it's
309 * still owned by it and we'll just get into trouble
310 * freeing it now. Mark it as abandoned so that if it
311 * shows up later it can be freed.
313 mps_printf(sc, "mps_user_read_extcfg_header timed out\n");
317 ext_page_req->ioc_status = htole16(params.status);
318 if ((ext_page_req->ioc_status & MPI2_IOCSTATUS_MASK) ==
319 MPI2_IOCSTATUS_SUCCESS) {
320 ext_page_req->header.PageVersion = hdr->PageVersion;
321 ext_page_req->header.PageNumber = hdr->PageNumber;
322 ext_page_req->header.PageType = hdr->PageType;
323 ext_page_req->header.ExtPageLength = hdr->ExtPageLength;
324 ext_page_req->header.ExtPageType = hdr->ExtPageType;
331 mps_user_read_extcfg_page(struct mps_softc *sc,
332 struct mps_ext_cfg_page_req *ext_page_req, void *buf)
334 MPI2_CONFIG_EXTENDED_PAGE_HEADER *reqhdr, *hdr;
335 struct mps_config_params params;
339 hdr = ¶ms.hdr.Ext;
340 params.action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
341 params.page_address = le32toh(ext_page_req->page_address);
342 hdr->PageVersion = reqhdr->PageVersion;
343 hdr->PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
344 hdr->PageNumber = reqhdr->PageNumber;
345 hdr->ExtPageType = reqhdr->ExtPageType;
346 hdr->ExtPageLength = reqhdr->ExtPageLength;
348 params.length = le32toh(ext_page_req->len);
349 params.callback = NULL;
351 if ((error = mps_read_config_page(sc, ¶ms)) != 0) {
352 mps_printf(sc, "mps_user_read_extcfg_page timed out\n");
356 ext_page_req->ioc_status = htole16(params.status);
361 mps_user_write_cfg_page(struct mps_softc *sc,
362 struct mps_cfg_page_req *page_req, void *buf)
364 MPI2_CONFIG_PAGE_HEADER *reqhdr, *hdr;
365 struct mps_config_params params;
370 hdr = ¶ms.hdr.Struct;
371 hdr_attr = reqhdr->PageType & MPI2_CONFIG_PAGEATTR_MASK;
372 if (hdr_attr != MPI2_CONFIG_PAGEATTR_CHANGEABLE &&
373 hdr_attr != MPI2_CONFIG_PAGEATTR_PERSISTENT) {
374 mps_printf(sc, "page type 0x%x not changeable\n",
375 reqhdr->PageType & MPI2_CONFIG_PAGETYPE_MASK);
380 * There isn't any point in restoring stripped out attributes
381 * if you then mask them going down to issue the request.
384 hdr->PageVersion = reqhdr->PageVersion;
385 hdr->PageLength = reqhdr->PageLength;
386 hdr->PageNumber = reqhdr->PageNumber;
387 hdr->PageType = reqhdr->PageType;
388 params.action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
389 params.page_address = le32toh(page_req->page_address);
391 params.length = le32toh(page_req->len);
392 params.callback = NULL;
394 if ((error = mps_write_config_page(sc, ¶ms)) != 0) {
395 mps_printf(sc, "mps_write_cfg_page timed out\n");
399 page_req->ioc_status = htole16(params.status);
404 mpi_init_sge(struct mps_command *cm, void *req, void *sge)
408 space = (int)cm->cm_sc->reqframesz;
409 off = (uintptr_t)sge - (uintptr_t)req;
411 KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
412 req, sge, off, space));
415 cm->cm_sglsize = space - off;
419 * Prepare the mps_command for an IOC_FACTS request.
422 mpi_pre_ioc_facts(struct mps_command *cm, struct mps_usr_command *cmd)
424 MPI2_IOC_FACTS_REQUEST *req = (void *)cm->cm_req;
425 MPI2_IOC_FACTS_REPLY *rpl;
427 if (cmd->req_len != sizeof *req)
429 if (cmd->rpl_len != sizeof *rpl)
438 * Prepare the mps_command for a PORT_FACTS request.
441 mpi_pre_port_facts(struct mps_command *cm, struct mps_usr_command *cmd)
443 MPI2_PORT_FACTS_REQUEST *req = (void *)cm->cm_req;
444 MPI2_PORT_FACTS_REPLY *rpl;
446 if (cmd->req_len != sizeof *req)
448 if (cmd->rpl_len != sizeof *rpl)
457 * Prepare the mps_command for a FW_DOWNLOAD request.
460 mpi_pre_fw_download(struct mps_command *cm, struct mps_usr_command *cmd)
462 MPI2_FW_DOWNLOAD_REQUEST *req = (void *)cm->cm_req;
463 MPI2_FW_DOWNLOAD_REPLY *rpl;
464 MPI2_FW_DOWNLOAD_TCSGE tc;
467 if (cmd->req_len != sizeof *req)
469 if (cmd->rpl_len != sizeof *rpl)
475 error = copyin(cmd->buf, cm->cm_data, cmd->len);
479 mpi_init_sge(cm, req, &req->SGL);
480 bzero(&tc, sizeof tc);
483 * For now, the F/W image must be provided in a single request.
485 if ((req->MsgFlags & MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT) == 0)
487 if (req->TotalImageSize != cmd->len)
491 * The value of the first two elements is specified in the
492 * Fusion-MPT Message Passing Interface document.
495 tc.DetailsLength = 12;
497 tc.ImageSize = cmd->len;
499 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
501 return (mps_push_sge(cm, &tc, sizeof tc, 0));
505 * Prepare the mps_command for a FW_UPLOAD request.
508 mpi_pre_fw_upload(struct mps_command *cm, struct mps_usr_command *cmd)
510 MPI2_FW_UPLOAD_REQUEST *req = (void *)cm->cm_req;
511 MPI2_FW_UPLOAD_REPLY *rpl;
512 MPI2_FW_UPLOAD_TCSGE tc;
514 if (cmd->req_len != sizeof *req)
516 if (cmd->rpl_len != sizeof *rpl)
519 mpi_init_sge(cm, req, &req->SGL);
520 bzero(&tc, sizeof tc);
523 * The value of the first two elements is specified in the
524 * Fusion-MPT Message Passing Interface document.
527 tc.DetailsLength = 12;
529 * XXX Is there any reason to fetch a partial image? I.e. to
530 * set ImageOffset to something other than 0?
533 tc.ImageSize = cmd->len;
535 cm->cm_flags |= MPS_CM_FLAGS_DATAIN;
537 return (mps_push_sge(cm, &tc, sizeof tc, 0));
541 * Prepare the mps_command for a SATA_PASSTHROUGH request.
544 mpi_pre_sata_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
546 MPI2_SATA_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
547 MPI2_SATA_PASSTHROUGH_REPLY *rpl;
549 if (cmd->req_len != sizeof *req)
551 if (cmd->rpl_len != sizeof *rpl)
554 mpi_init_sge(cm, req, &req->SGL);
559 * Prepare the mps_command for a SMP_PASSTHROUGH request.
562 mpi_pre_smp_passthrough(struct mps_command *cm, struct mps_usr_command *cmd)
564 MPI2_SMP_PASSTHROUGH_REQUEST *req = (void *)cm->cm_req;
565 MPI2_SMP_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 CONFIG request.
580 mpi_pre_config(struct mps_command *cm, struct mps_usr_command *cmd)
582 MPI2_CONFIG_REQUEST *req = (void *)cm->cm_req;
583 MPI2_CONFIG_REPLY *rpl;
585 if (cmd->req_len != sizeof *req)
587 if (cmd->rpl_len != sizeof *rpl)
590 mpi_init_sge(cm, req, &req->PageBufferSGE);
595 * Prepare the mps_command for a SAS_IO_UNIT_CONTROL request.
598 mpi_pre_sas_io_unit_control(struct mps_command *cm,
599 struct mps_usr_command *cmd)
608 * A set of functions to prepare an mps_command for the various
609 * supported requests.
611 struct mps_user_func {
614 } mps_user_func_list[] = {
615 { MPI2_FUNCTION_IOC_FACTS, mpi_pre_ioc_facts },
616 { MPI2_FUNCTION_PORT_FACTS, mpi_pre_port_facts },
617 { MPI2_FUNCTION_FW_DOWNLOAD, mpi_pre_fw_download },
618 { MPI2_FUNCTION_FW_UPLOAD, mpi_pre_fw_upload },
619 { MPI2_FUNCTION_SATA_PASSTHROUGH, mpi_pre_sata_passthrough },
620 { MPI2_FUNCTION_SMP_PASSTHROUGH, mpi_pre_smp_passthrough},
621 { MPI2_FUNCTION_CONFIG, mpi_pre_config},
622 { MPI2_FUNCTION_SAS_IO_UNIT_CONTROL, mpi_pre_sas_io_unit_control },
623 { 0xFF, NULL } /* list end */
627 mps_user_setup_request(struct mps_command *cm, struct mps_usr_command *cmd)
629 MPI2_REQUEST_HEADER *hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
630 struct mps_user_func *f;
632 for (f = mps_user_func_list; f->f_pre != NULL; f++) {
633 if (hdr->Function == f->Function)
634 return (f->f_pre(cm, cmd));
640 mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd)
642 MPI2_REQUEST_HEADER *hdr;
643 MPI2_DEFAULT_REPLY *rpl;
645 struct mps_command *cm = NULL;
650 cm = mps_alloc_command(sc);
653 mps_printf(sc, "%s: no mps requests\n", __func__);
659 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
661 mps_dprint(sc, MPS_USER, "%s: req %p %d rpl %p %d\n", __func__,
662 cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len);
664 if (cmd->req_len > sc->reqframesz) {
666 goto RetFreeUnlocked;
668 err = copyin(cmd->req, hdr, cmd->req_len);
670 goto RetFreeUnlocked;
672 mps_dprint(sc, MPS_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
673 hdr->Function, hdr->MsgFlags);
676 buf = malloc(cmd->len, M_MPSUSER, M_WAITOK|M_ZERO);
678 cm->cm_length = cmd->len;
684 cm->cm_flags = MPS_CM_FLAGS_SGE_SIMPLE;
685 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
687 err = mps_user_setup_request(cm, cmd);
689 mps_printf(sc, "%s: unsupported parameter or unsupported "
690 "function in request (function = 0x%X)\n", __func__,
694 goto RetFreeUnlocked;
697 err = mps_wait_command(sc, &cm, 60, CAN_SLEEP);
699 if (err || (cm == NULL)) {
700 mps_printf(sc, "%s: invalid request: error %d\n",
705 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
707 sz = rpl->MsgLength * 4;
711 if (sz > cmd->rpl_len) {
712 mps_printf(sc, "%s: user reply buffer (%d) smaller than "
713 "returned buffer (%d)\n", __func__, cmd->rpl_len, sz);
718 err = copyout(rpl, cmd->rpl, sz);
719 if (buf != NULL && err == 0)
720 err = copyout(buf, cmd->buf, cmd->len);
721 mps_dprint(sc, MPS_USER, "%s: reply size %d\n", __func__, sz);
727 mps_free_command(sc, cm);
730 free(buf, M_MPSUSER);
735 mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
737 MPI2_REQUEST_HEADER *hdr, *tmphdr;
738 MPI2_DEFAULT_REPLY *rpl = NULL;
739 struct mps_command *cm = NULL;
741 int err = 0, dir = 0, sz;
742 uint8_t function = 0;
744 struct mpssas_target *targ = NULL;
747 * Only allow one passthru command at a time. Use the MPS_FLAGS_BUSY
748 * bit to denote that a passthru is being processed.
751 if (sc->mps_flags & MPS_FLAGS_BUSY) {
752 mps_dprint(sc, MPS_USER, "%s: Only one passthru command "
753 "allowed at a single time.", __func__);
757 sc->mps_flags |= MPS_FLAGS_BUSY;
761 * Do some validation on data direction. Valid cases are:
762 * 1) DataSize is 0 and direction is NONE
763 * 2) DataSize is non-zero and one of:
764 * a) direction is READ or
765 * b) direction is WRITE or
766 * c) direction is BOTH and DataOutSize is non-zero
767 * If valid and the direction is BOTH, change the direction to READ.
768 * if valid and the direction is not BOTH, make sure DataOutSize is 0.
770 if (((data->DataSize == 0) &&
771 (data->DataDirection == MPS_PASS_THRU_DIRECTION_NONE)) ||
772 ((data->DataSize != 0) &&
773 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_READ) ||
774 (data->DataDirection == MPS_PASS_THRU_DIRECTION_WRITE) ||
775 ((data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH) &&
776 (data->DataOutSize != 0))))) {
777 if (data->DataDirection == MPS_PASS_THRU_DIRECTION_BOTH)
778 data->DataDirection = MPS_PASS_THRU_DIRECTION_READ;
780 data->DataOutSize = 0;
783 goto RetFreeUnlocked;
786 mps_dprint(sc, MPS_USER, "%s: req 0x%jx %d rpl 0x%jx %d "
787 "data in 0x%jx %d data out 0x%jx %d data dir %d\n", __func__,
788 data->PtrRequest, data->RequestSize, data->PtrReply,
789 data->ReplySize, data->PtrData, data->DataSize,
790 data->PtrDataOut, data->DataOutSize, data->DataDirection);
792 if (data->RequestSize > sc->reqframesz) {
794 goto RetFreeUnlocked;
797 req = malloc(data->RequestSize, M_MPSUSER, M_WAITOK | M_ZERO);
798 tmphdr = (MPI2_REQUEST_HEADER *)req;
800 err = copyin(PTRIN(data->PtrRequest), req, data->RequestSize);
802 goto RetFreeUnlocked;
804 function = tmphdr->Function;
805 mps_dprint(sc, MPS_USER, "%s: Function %02X MsgFlags %02X\n", __func__,
806 function, tmphdr->MsgFlags);
809 * Handle a passthru TM request.
811 if (function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
812 MPI2_SCSI_TASK_MANAGE_REQUEST *task;
815 cm = mpssas_alloc_tm(sc);
821 /* Copy the header in. Only a small fixup is needed. */
822 task = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req;
823 memcpy(task, req, data->RequestSize);
824 task->TaskMID = cm->cm_desc.Default.SMID;
827 cm->cm_complete = NULL;
828 cm->cm_complete_data = NULL;
830 targ = mpssas_find_target_by_handle(sc->sassc, 0,
833 mps_dprint(sc, MPS_INFO,
834 "%s %d : invalid handle for requested TM 0x%x \n",
835 __func__, __LINE__, task->DevHandle);
838 mpssas_prepare_for_tm(sc, cm, targ, CAM_LUN_WILDCARD);
839 err = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
844 mps_dprint(sc, MPS_FAULT, "%s: task management failed",
848 * Copy the reply data and sense data to user space.
850 if (err == 0 && cm != NULL && cm->cm_reply != NULL) {
851 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
852 sz = rpl->MsgLength * 4;
854 if (bootverbose && sz > data->ReplySize) {
855 mps_printf(sc, "%s: user reply buffer (%d) "
856 "smaller than returned buffer (%d)\n",
857 __func__, data->ReplySize, sz);
860 err = copyout(cm->cm_reply, PTRIN(data->PtrReply),
861 MIN(sz, data->ReplySize));
863 mps_dprint(sc, MPS_FAULT,
864 "%s: copyout failed\n", __func__);
867 mpssas_free_tm(sc, cm);
872 cm = mps_alloc_command(sc);
874 mps_printf(sc, "%s: no mps requests\n", __func__);
880 hdr = (MPI2_REQUEST_HEADER *)cm->cm_req;
881 memcpy(hdr, req, 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 = malloc(cm->cm_length, M_MPSUSER, M_WAITOK |
905 cm->cm_flags = MPS_CM_FLAGS_DATAIN;
906 if (data->DataOutSize) {
907 cm->cm_flags |= MPS_CM_FLAGS_DATAOUT;
908 err = copyin(PTRIN(data->PtrDataOut),
909 cm->cm_data, data->DataOutSize);
910 } else if (data->DataDirection ==
911 MPS_PASS_THRU_DIRECTION_WRITE) {
912 cm->cm_flags = MPS_CM_FLAGS_DATAOUT;
913 err = copyin(PTRIN(data->PtrData),
914 cm->cm_data, data->DataSize);
917 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
918 "IOCTL data from user space\n", __func__);
920 cm->cm_flags |= MPS_CM_FLAGS_SGE_SIMPLE;
921 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
924 * Set up Sense buffer and SGL offset for IO passthru. SCSI IO request
925 * uses SCSI IO descriptor.
927 if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) ||
928 (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
929 MPI2_SCSI_IO_REQUEST *scsi_io_req;
931 scsi_io_req = (MPI2_SCSI_IO_REQUEST *)hdr;
933 * Put SGE for data and data_out buffer at the end of
934 * scsi_io_request message header (64 bytes in total).
935 * Following above SGEs, the residual space will be used by
938 scsi_io_req->SenseBufferLength = (uint8_t)(data->RequestSize -
940 scsi_io_req->SenseBufferLowAddress = htole32(cm->cm_sense_busaddr);
943 * Set SGLOffset0 value. This is the number of dwords that SGL
944 * is offset from the beginning of MPI2_SCSI_IO_REQUEST struct.
946 scsi_io_req->SGLOffset0 = 24;
949 * Setup descriptor info. RAID passthrough must use the
950 * default request descriptor which is already set, so if this
951 * is a SCSI IO request, change the descriptor to SCSI IO.
952 * Also, if this is a SCSI IO request, handle the reply in the
953 * mpssas_scsio_complete function.
955 if (function == MPI2_FUNCTION_SCSI_IO_REQUEST) {
956 cm->cm_desc.SCSIIO.RequestFlags =
957 MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
958 cm->cm_desc.SCSIIO.DevHandle = scsi_io_req->DevHandle;
961 * Make sure the DevHandle is not 0 because this is a
964 if (scsi_io_req->DevHandle == 0) {
966 goto RetFreeUnlocked;
973 err = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
975 if (err || (cm == NULL)) {
976 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
979 goto RetFreeUnlocked;
983 * Sync the DMA data, if any. Then copy the data to user space.
985 if (cm->cm_data != NULL) {
986 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN)
987 dir = BUS_DMASYNC_POSTREAD;
988 else if (cm->cm_flags & MPS_CM_FLAGS_DATAOUT)
989 dir = BUS_DMASYNC_POSTWRITE;
990 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir);
991 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap);
993 if (cm->cm_flags & MPS_CM_FLAGS_DATAIN) {
995 err = copyout(cm->cm_data,
996 PTRIN(data->PtrData), data->DataSize);
999 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1000 "IOCTL data to user space\n", __func__);
1005 * Copy the reply data and sense data to user space.
1007 if (err == 0 && cm->cm_reply != NULL) {
1008 rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
1009 sz = rpl->MsgLength * 4;
1011 if (bootverbose && sz > data->ReplySize) {
1012 mps_printf(sc, "%s: user reply buffer (%d) smaller "
1013 "than returned buffer (%d)\n", __func__,
1014 data->ReplySize, sz);
1017 err = copyout(cm->cm_reply, PTRIN(data->PtrReply),
1018 MIN(sz, data->ReplySize));
1021 mps_dprint(sc, MPS_FAULT, "%s: failed to copy "
1022 "IOCTL data to user space\n", __func__);
1025 (function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
1026 function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
1027 if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState &
1028 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
1030 MIN((le32toh(((MPI2_SCSI_IO_REPLY *)rpl)->
1031 SenseCount)), sizeof(struct
1034 err = copyout(cm->cm_sense, (PTRIN(data->PtrReply +
1035 sizeof(MPI2_SCSI_IO_REPLY))), sense_len);
1038 mps_dprint(sc, MPS_FAULT,
1039 "%s: failed to copy IOCTL data to "
1040 "user space\n", __func__);
1051 free(cm->cm_data, M_MPSUSER);
1052 mps_free_command(sc, cm);
1055 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1057 free(req, M_MPSUSER);
1063 mps_user_get_adapter_data(struct mps_softc *sc, mps_adapter_data_t *data)
1065 Mpi2ConfigReply_t mpi_reply;
1066 Mpi2BiosPage3_t config_page;
1069 * Use the PCI interface functions to get the Bus, Device, and Function
1072 data->PciInformation.u.bits.BusNumber = pci_get_bus(sc->mps_dev);
1073 data->PciInformation.u.bits.DeviceNumber = pci_get_slot(sc->mps_dev);
1074 data->PciInformation.u.bits.FunctionNumber =
1075 pci_get_function(sc->mps_dev);
1078 * Get the FW version that should already be saved in IOC Facts.
1080 data->MpiFirmwareVersion = sc->facts->FWVersion.Word;
1083 * General device info.
1085 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2;
1086 if (sc->mps_flags & MPS_FLAGS_WD_AVAILABLE)
1087 data->AdapterType = MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200;
1088 data->PCIDeviceHwId = pci_get_device(sc->mps_dev);
1089 data->PCIDeviceHwRev = pci_read_config(sc->mps_dev, PCIR_REVID, 1);
1090 data->SubSystemId = pci_get_subdevice(sc->mps_dev);
1091 data->SubsystemVendorId = pci_get_subvendor(sc->mps_dev);
1094 * Get the driver version.
1096 strcpy((char *)&data->DriverVersion[0], MPS_DRIVER_VERSION);
1099 * Need to get BIOS Config Page 3 for the BIOS Version.
1101 data->BiosVersion = 0;
1103 if (mps_config_get_bios_pg3(sc, &mpi_reply, &config_page))
1104 printf("%s: Error while retrieving BIOS Version\n", __func__);
1106 data->BiosVersion = config_page.BiosVersion;
1111 mps_user_read_pci_info(struct mps_softc *sc, mps_pci_info_t *data)
1116 * Use the PCI interface functions to get the Bus, Device, and Function
1119 data->BusNumber = pci_get_bus(sc->mps_dev);
1120 data->DeviceNumber = pci_get_slot(sc->mps_dev);
1121 data->FunctionNumber = pci_get_function(sc->mps_dev);
1124 * Now get the interrupt vector and the pci header. The vector can
1125 * only be 0 right now. The header is the first 256 bytes of config
1128 data->InterruptVector = 0;
1129 for (i = 0; i < sizeof (data->PciHeader); i++) {
1130 data->PciHeader[i] = pci_read_config(sc->mps_dev, i, 1);
1135 mps_get_fw_diag_buffer_number(struct mps_softc *sc, uint32_t unique_id)
1139 for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1140 if (sc->fw_diag_buffer_list[index].unique_id == unique_id) {
1145 return (MPS_FW_DIAGNOSTIC_UID_NOT_FOUND);
1149 mps_post_fw_diag_buffer(struct mps_softc *sc,
1150 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code)
1152 MPI2_DIAG_BUFFER_POST_REQUEST *req;
1153 MPI2_DIAG_BUFFER_POST_REPLY *reply = NULL;
1154 struct mps_command *cm = NULL;
1158 * If buffer is not enabled, just leave.
1160 *return_code = MPS_FW_DIAG_ERROR_POST_FAILED;
1161 if (!pBuffer->enabled) {
1162 return (MPS_DIAG_FAILURE);
1166 * Clear some flags initially.
1168 pBuffer->force_release = FALSE;
1169 pBuffer->valid_data = FALSE;
1170 pBuffer->owned_by_firmware = FALSE;
1175 cm = mps_alloc_command(sc);
1177 mps_printf(sc, "%s: no mps requests\n", __func__);
1178 return (MPS_DIAG_FAILURE);
1182 * Build the request for releasing the FW Diag Buffer and send it.
1184 req = (MPI2_DIAG_BUFFER_POST_REQUEST *)cm->cm_req;
1185 req->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1186 req->BufferType = pBuffer->buffer_type;
1187 req->ExtendedType = pBuffer->extended_type;
1188 req->BufferLength = pBuffer->size;
1189 for (i = 0; i < (sizeof(req->ProductSpecific) / 4); i++)
1190 req->ProductSpecific[i] = pBuffer->product_specific[i];
1191 mps_from_u64(sc->fw_diag_busaddr, &req->BufferAddress);
1194 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1195 cm->cm_complete_data = NULL;
1198 * Send command synchronously.
1200 status = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
1201 if (status || (cm == NULL)) {
1202 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1204 status = MPS_DIAG_FAILURE;
1209 * Process POST reply.
1211 reply = (MPI2_DIAG_BUFFER_POST_REPLY *)cm->cm_reply;
1212 if (reply == NULL) {
1213 mps_printf(sc, "%s: reply is NULL, probably due to "
1214 "reinitialization\n", __func__);
1215 status = MPS_DIAG_FAILURE;
1218 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) !=
1219 MPI2_IOCSTATUS_SUCCESS) {
1220 status = MPS_DIAG_FAILURE;
1221 mps_dprint(sc, MPS_FAULT, "%s: post of FW Diag Buffer failed "
1222 "with IOCStatus = 0x%x, IOCLogInfo = 0x%x and "
1223 "TransferLength = 0x%x\n", __func__,
1224 le16toh(reply->IOCStatus), le32toh(reply->IOCLogInfo),
1225 le32toh(reply->TransferLength));
1230 * Post was successful.
1232 pBuffer->valid_data = TRUE;
1233 pBuffer->owned_by_firmware = TRUE;
1234 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1235 status = MPS_DIAG_SUCCESS;
1239 mps_free_command(sc, cm);
1244 mps_release_fw_diag_buffer(struct mps_softc *sc,
1245 mps_fw_diagnostic_buffer_t *pBuffer, uint32_t *return_code,
1248 MPI2_DIAG_RELEASE_REQUEST *req;
1249 MPI2_DIAG_RELEASE_REPLY *reply = NULL;
1250 struct mps_command *cm = NULL;
1254 * If buffer is not enabled, just leave.
1256 *return_code = MPS_FW_DIAG_ERROR_RELEASE_FAILED;
1257 if (!pBuffer->enabled) {
1258 mps_dprint(sc, MPS_USER, "%s: This buffer type is not "
1259 "supported by the IOC", __func__);
1260 return (MPS_DIAG_FAILURE);
1264 * Clear some flags initially.
1266 pBuffer->force_release = FALSE;
1267 pBuffer->valid_data = FALSE;
1268 pBuffer->owned_by_firmware = FALSE;
1273 cm = mps_alloc_command(sc);
1275 mps_printf(sc, "%s: no mps requests\n", __func__);
1276 return (MPS_DIAG_FAILURE);
1280 * Build the request for releasing the FW Diag Buffer and send it.
1282 req = (MPI2_DIAG_RELEASE_REQUEST *)cm->cm_req;
1283 req->Function = MPI2_FUNCTION_DIAG_RELEASE;
1284 req->BufferType = pBuffer->buffer_type;
1287 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1288 cm->cm_complete_data = NULL;
1291 * Send command synchronously.
1293 status = mps_wait_command(sc, &cm, 30, CAN_SLEEP);
1294 if (status || (cm == NULL)) {
1295 mps_printf(sc, "%s: invalid request: error %d\n", __func__,
1297 status = MPS_DIAG_FAILURE;
1302 * Process RELEASE reply.
1304 reply = (MPI2_DIAG_RELEASE_REPLY *)cm->cm_reply;
1305 if (reply == NULL) {
1306 mps_printf(sc, "%s: reply is NULL, probably due to "
1307 "reinitialization\n", __func__);
1308 status = MPS_DIAG_FAILURE;
1311 if (((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) !=
1312 MPI2_IOCSTATUS_SUCCESS) || pBuffer->owned_by_firmware) {
1313 status = MPS_DIAG_FAILURE;
1314 mps_dprint(sc, MPS_FAULT, "%s: release of FW Diag Buffer "
1315 "failed with IOCStatus = 0x%x and IOCLogInfo = 0x%x\n",
1316 __func__, le16toh(reply->IOCStatus),
1317 le32toh(reply->IOCLogInfo));
1322 * Release was successful.
1324 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1325 status = MPS_DIAG_SUCCESS;
1328 * If this was for an UNREGISTER diag type command, clear the unique ID.
1330 if (diag_type == MPS_FW_DIAG_TYPE_UNREGISTER) {
1331 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1336 mps_free_command(sc, cm);
1342 mps_diag_register(struct mps_softc *sc, mps_fw_diag_register_t *diag_register,
1343 uint32_t *return_code)
1345 bus_dma_template_t t;
1346 mps_fw_diagnostic_buffer_t *pBuffer;
1347 struct mps_busdma_context *ctx;
1348 uint8_t extended_type, buffer_type, i;
1349 uint32_t buffer_size;
1354 extended_type = diag_register->ExtendedType;
1355 buffer_type = diag_register->BufferType;
1356 buffer_size = diag_register->RequestedBufferSize;
1357 unique_id = diag_register->UniqueId;
1362 * Check for valid buffer type
1364 if (buffer_type >= MPI2_DIAG_BUF_TYPE_COUNT) {
1365 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1366 return (MPS_DIAG_FAILURE);
1370 * Get the current buffer and look up the unique ID. The unique ID
1371 * should not be found. If it is, the ID is already in use.
1373 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1374 pBuffer = &sc->fw_diag_buffer_list[buffer_type];
1375 if (i != MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1376 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1377 return (MPS_DIAG_FAILURE);
1381 * The buffer's unique ID should not be registered yet, and the given
1382 * unique ID cannot be 0.
1384 if ((pBuffer->unique_id != MPS_FW_DIAG_INVALID_UID) ||
1385 (unique_id == MPS_FW_DIAG_INVALID_UID)) {
1386 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1387 return (MPS_DIAG_FAILURE);
1391 * If this buffer is already posted as immediate, just change owner.
1393 if (pBuffer->immediate && pBuffer->owned_by_firmware &&
1394 (pBuffer->unique_id == MPS_FW_DIAG_INVALID_UID)) {
1395 pBuffer->immediate = FALSE;
1396 pBuffer->unique_id = unique_id;
1397 return (MPS_DIAG_SUCCESS);
1401 * Post a new buffer after checking if it's enabled. The DMA buffer
1402 * that is allocated will be contiguous (nsegments = 1).
1404 if (!pBuffer->enabled) {
1405 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1406 return (MPS_DIAG_FAILURE);
1408 bus_dma_template_init(&t, sc->mps_parent_dmat);
1409 BUS_DMA_TEMPLATE_FILL(&t, BD_NSEGMENTS(1), BD_MAXSIZE(buffer_size),
1410 BD_MAXSEGSIZE(buffer_size), BD_LOWADDR(BUS_SPACE_MAXADDR_32BIT));
1411 if (bus_dma_template_tag(&t, &sc->fw_diag_dmat)) {
1412 mps_dprint(sc, MPS_ERROR,
1413 "Cannot allocate FW diag buffer DMA tag\n");
1414 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1415 status = MPS_DIAG_FAILURE;
1418 if (bus_dmamem_alloc(sc->fw_diag_dmat, (void **)&sc->fw_diag_buffer,
1419 BUS_DMA_NOWAIT, &sc->fw_diag_map)) {
1420 mps_dprint(sc, MPS_ERROR,
1421 "Cannot allocate FW diag buffer memory\n");
1422 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1423 status = MPS_DIAG_FAILURE;
1426 bzero(sc->fw_diag_buffer, buffer_size);
1428 ctx = malloc(sizeof(*ctx), M_MPSUSER, M_WAITOK | M_ZERO);
1429 ctx->addr = &sc->fw_diag_busaddr;
1430 ctx->buffer_dmat = sc->fw_diag_dmat;
1431 ctx->buffer_dmamap = sc->fw_diag_map;
1433 error = bus_dmamap_load(sc->fw_diag_dmat, sc->fw_diag_map,
1434 sc->fw_diag_buffer, buffer_size, mps_memaddr_wait_cb,
1437 if (error == EINPROGRESS) {
1439 device_printf(sc->mps_dev, "%s: Deferred bus_dmamap_load\n",
1442 * Wait for the load to complete. If we're interrupted,
1446 if (ctx->completed == 0) {
1447 error = msleep(ctx, &sc->mps_mtx, PCATCH, "mpswait", 0);
1450 * We got an error from msleep(9). This is
1451 * most likely due to a signal. Tell
1452 * mpr_memaddr_wait_cb() that we've abandoned
1453 * the context, so it needs to clean up when
1458 /* The callback will free this memory */
1462 device_printf(sc->mps_dev, "Cannot "
1463 "bus_dmamap_load FW diag buffer, error = "
1464 "%d returned from msleep\n", error);
1465 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1466 status = MPS_DIAG_FAILURE;
1473 if ((error != 0) || (ctx->error != 0)) {
1474 device_printf(sc->mps_dev, "Cannot bus_dmamap_load FW diag "
1475 "buffer, %serror = %d\n", error ? "" : "callback ",
1476 error ? error : ctx->error);
1477 *return_code = MPS_FW_DIAG_ERROR_NO_BUFFER;
1478 status = MPS_DIAG_FAILURE;
1482 bus_dmamap_sync(sc->fw_diag_dmat, sc->fw_diag_map, BUS_DMASYNC_PREREAD);
1484 pBuffer->size = buffer_size;
1487 * Copy the given info to the diag buffer and post the buffer.
1489 pBuffer->buffer_type = buffer_type;
1490 pBuffer->immediate = FALSE;
1491 if (buffer_type == MPI2_DIAG_BUF_TYPE_TRACE) {
1492 for (i = 0; i < (sizeof (pBuffer->product_specific) / 4);
1494 pBuffer->product_specific[i] =
1495 diag_register->ProductSpecific[i];
1498 pBuffer->extended_type = extended_type;
1499 pBuffer->unique_id = unique_id;
1500 status = mps_post_fw_diag_buffer(sc, pBuffer, return_code);
1504 * In case there was a failure, free the DMA buffer.
1506 if (status == MPS_DIAG_FAILURE) {
1507 if (sc->fw_diag_busaddr != 0) {
1508 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1509 sc->fw_diag_busaddr = 0;
1511 if (sc->fw_diag_buffer != NULL) {
1512 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1514 sc->fw_diag_buffer = NULL;
1516 if (sc->fw_diag_dmat != NULL) {
1517 bus_dma_tag_destroy(sc->fw_diag_dmat);
1518 sc->fw_diag_dmat = NULL;
1523 free(ctx, M_MPSUSER);
1529 mps_diag_unregister(struct mps_softc *sc,
1530 mps_fw_diag_unregister_t *diag_unregister, uint32_t *return_code)
1532 mps_fw_diagnostic_buffer_t *pBuffer;
1537 unique_id = diag_unregister->UniqueId;
1540 * Get the current buffer and look up the unique ID. The unique ID
1543 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1544 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1545 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1546 return (MPS_DIAG_FAILURE);
1549 pBuffer = &sc->fw_diag_buffer_list[i];
1552 * Try to release the buffer from FW before freeing it. If release
1553 * fails, don't free the DMA buffer in case FW tries to access it
1554 * later. If buffer is not owned by firmware, can't release it.
1556 if (!pBuffer->owned_by_firmware) {
1557 status = MPS_DIAG_SUCCESS;
1559 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1560 MPS_FW_DIAG_TYPE_UNREGISTER);
1564 * At this point, return the current status no matter what happens with
1567 pBuffer->unique_id = MPS_FW_DIAG_INVALID_UID;
1568 if (status == MPS_DIAG_SUCCESS) {
1569 if (sc->fw_diag_busaddr != 0) {
1570 bus_dmamap_unload(sc->fw_diag_dmat, sc->fw_diag_map);
1571 sc->fw_diag_busaddr = 0;
1573 if (sc->fw_diag_buffer != NULL) {
1574 bus_dmamem_free(sc->fw_diag_dmat, sc->fw_diag_buffer,
1576 sc->fw_diag_buffer = NULL;
1578 if (sc->fw_diag_dmat != NULL) {
1579 bus_dma_tag_destroy(sc->fw_diag_dmat);
1580 sc->fw_diag_dmat = NULL;
1588 mps_diag_query(struct mps_softc *sc, mps_fw_diag_query_t *diag_query,
1589 uint32_t *return_code)
1591 mps_fw_diagnostic_buffer_t *pBuffer;
1595 unique_id = diag_query->UniqueId;
1598 * If ID is valid, query on ID.
1599 * If ID is invalid, query on buffer type.
1601 if (unique_id == MPS_FW_DIAG_INVALID_UID) {
1602 i = diag_query->BufferType;
1603 if (i >= MPI2_DIAG_BUF_TYPE_COUNT) {
1604 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1605 return (MPS_DIAG_FAILURE);
1608 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1609 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1610 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1611 return (MPS_DIAG_FAILURE);
1616 * Fill query structure with the diag buffer info.
1618 pBuffer = &sc->fw_diag_buffer_list[i];
1619 diag_query->BufferType = pBuffer->buffer_type;
1620 diag_query->ExtendedType = pBuffer->extended_type;
1621 if (diag_query->BufferType == MPI2_DIAG_BUF_TYPE_TRACE) {
1622 for (i = 0; i < (sizeof(diag_query->ProductSpecific) / 4);
1624 diag_query->ProductSpecific[i] =
1625 pBuffer->product_specific[i];
1628 diag_query->TotalBufferSize = pBuffer->size;
1629 diag_query->DriverAddedBufferSize = 0;
1630 diag_query->UniqueId = pBuffer->unique_id;
1631 diag_query->ApplicationFlags = 0;
1632 diag_query->DiagnosticFlags = 0;
1635 * Set/Clear application flags
1637 if (pBuffer->immediate) {
1638 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_APP_OWNED;
1640 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_APP_OWNED;
1642 if (pBuffer->valid_data || pBuffer->owned_by_firmware) {
1643 diag_query->ApplicationFlags |= MPS_FW_DIAG_FLAG_BUFFER_VALID;
1645 diag_query->ApplicationFlags &= ~MPS_FW_DIAG_FLAG_BUFFER_VALID;
1647 if (pBuffer->owned_by_firmware) {
1648 diag_query->ApplicationFlags |=
1649 MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1651 diag_query->ApplicationFlags &=
1652 ~MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS;
1655 return (MPS_DIAG_SUCCESS);
1659 mps_diag_read_buffer(struct mps_softc *sc,
1660 mps_diag_read_buffer_t *diag_read_buffer, uint8_t *ioctl_buf,
1661 uint32_t *return_code)
1663 mps_fw_diagnostic_buffer_t *pBuffer;
1668 unique_id = diag_read_buffer->UniqueId;
1671 * Get the current buffer and look up the unique ID. The unique ID
1674 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1675 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1676 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1677 return (MPS_DIAG_FAILURE);
1680 pBuffer = &sc->fw_diag_buffer_list[i];
1683 * Make sure requested read is within limits
1685 if (diag_read_buffer->StartingOffset + diag_read_buffer->BytesToRead >
1687 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1688 return (MPS_DIAG_FAILURE);
1691 /* Sync the DMA map before we copy to userland. */
1692 bus_dmamap_sync(sc->fw_diag_dmat, sc->fw_diag_map,
1693 BUS_DMASYNC_POSTREAD);
1696 * Copy the requested data from DMA to the diag_read_buffer. The DMA
1697 * buffer that was allocated is one contiguous buffer.
1699 pData = (uint8_t *)(sc->fw_diag_buffer +
1700 diag_read_buffer->StartingOffset);
1701 if (copyout(pData, ioctl_buf, diag_read_buffer->BytesToRead) != 0)
1702 return (MPS_DIAG_FAILURE);
1703 diag_read_buffer->Status = 0;
1706 * Set or clear the Force Release flag.
1708 if (pBuffer->force_release) {
1709 diag_read_buffer->Flags |= MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1711 diag_read_buffer->Flags &= ~MPS_FW_DIAG_FLAG_FORCE_RELEASE;
1715 * If buffer is to be reregistered, make sure it's not already owned by
1718 status = MPS_DIAG_SUCCESS;
1719 if (!pBuffer->owned_by_firmware) {
1720 if (diag_read_buffer->Flags & MPS_FW_DIAG_FLAG_REREGISTER) {
1721 status = mps_post_fw_diag_buffer(sc, pBuffer,
1730 mps_diag_release(struct mps_softc *sc, mps_fw_diag_release_t *diag_release,
1731 uint32_t *return_code)
1733 mps_fw_diagnostic_buffer_t *pBuffer;
1738 unique_id = diag_release->UniqueId;
1741 * Get the current buffer and look up the unique ID. The unique ID
1744 i = mps_get_fw_diag_buffer_number(sc, unique_id);
1745 if (i == MPS_FW_DIAGNOSTIC_UID_NOT_FOUND) {
1746 *return_code = MPS_FW_DIAG_ERROR_INVALID_UID;
1747 return (MPS_DIAG_FAILURE);
1750 pBuffer = &sc->fw_diag_buffer_list[i];
1753 * If buffer is not owned by firmware, it's already been released.
1755 if (!pBuffer->owned_by_firmware) {
1756 *return_code = MPS_FW_DIAG_ERROR_ALREADY_RELEASED;
1757 return (MPS_DIAG_FAILURE);
1761 * Release the buffer.
1763 status = mps_release_fw_diag_buffer(sc, pBuffer, return_code,
1764 MPS_FW_DIAG_TYPE_RELEASE);
1769 mps_do_diag_action(struct mps_softc *sc, uint32_t action, uint8_t *diag_action,
1770 uint32_t length, uint32_t *return_code)
1772 mps_fw_diag_register_t diag_register;
1773 mps_fw_diag_unregister_t diag_unregister;
1774 mps_fw_diag_query_t diag_query;
1775 mps_diag_read_buffer_t diag_read_buffer;
1776 mps_fw_diag_release_t diag_release;
1777 int status = MPS_DIAG_SUCCESS;
1778 uint32_t original_return_code;
1780 original_return_code = *return_code;
1781 *return_code = MPS_FW_DIAG_ERROR_SUCCESS;
1784 case MPS_FW_DIAG_TYPE_REGISTER:
1787 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1788 status = MPS_DIAG_FAILURE;
1791 if (copyin(diag_action, &diag_register,
1792 sizeof(diag_register)) != 0)
1793 return (MPS_DIAG_FAILURE);
1794 status = mps_diag_register(sc, &diag_register,
1798 case MPS_FW_DIAG_TYPE_UNREGISTER:
1799 if (length < sizeof(diag_unregister)) {
1801 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1802 status = MPS_DIAG_FAILURE;
1805 if (copyin(diag_action, &diag_unregister,
1806 sizeof(diag_unregister)) != 0)
1807 return (MPS_DIAG_FAILURE);
1808 status = mps_diag_unregister(sc, &diag_unregister,
1812 case MPS_FW_DIAG_TYPE_QUERY:
1813 if (length < sizeof (diag_query)) {
1815 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1816 status = MPS_DIAG_FAILURE;
1819 if (copyin(diag_action, &diag_query, sizeof(diag_query))
1821 return (MPS_DIAG_FAILURE);
1822 status = mps_diag_query(sc, &diag_query, return_code);
1823 if (status == MPS_DIAG_SUCCESS)
1824 if (copyout(&diag_query, diag_action,
1825 sizeof (diag_query)) != 0)
1826 return (MPS_DIAG_FAILURE);
1829 case MPS_FW_DIAG_TYPE_READ_BUFFER:
1830 if (copyin(diag_action, &diag_read_buffer,
1831 sizeof(diag_read_buffer)) != 0)
1832 return (MPS_DIAG_FAILURE);
1833 if (length < diag_read_buffer.BytesToRead) {
1835 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1836 status = MPS_DIAG_FAILURE;
1839 status = mps_diag_read_buffer(sc, &diag_read_buffer,
1840 PTRIN(diag_read_buffer.PtrDataBuffer),
1842 if (status == MPS_DIAG_SUCCESS) {
1843 if (copyout(&diag_read_buffer, diag_action,
1844 sizeof(diag_read_buffer) -
1845 sizeof(diag_read_buffer.PtrDataBuffer)) !=
1847 return (MPS_DIAG_FAILURE);
1851 case MPS_FW_DIAG_TYPE_RELEASE:
1852 if (length < sizeof(diag_release)) {
1854 MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1855 status = MPS_DIAG_FAILURE;
1858 if (copyin(diag_action, &diag_release,
1859 sizeof(diag_release)) != 0)
1860 return (MPS_DIAG_FAILURE);
1861 status = mps_diag_release(sc, &diag_release,
1866 *return_code = MPS_FW_DIAG_ERROR_INVALID_PARAMETER;
1867 status = MPS_DIAG_FAILURE;
1871 if ((status == MPS_DIAG_FAILURE) &&
1872 (original_return_code == MPS_FW_DIAG_NEW) &&
1873 (*return_code != MPS_FW_DIAG_ERROR_SUCCESS))
1874 status = MPS_DIAG_SUCCESS;
1880 mps_user_diag_action(struct mps_softc *sc, mps_diag_action_t *data)
1885 * Only allow one diag action at one time.
1887 if (sc->mps_flags & MPS_FLAGS_BUSY) {
1888 mps_dprint(sc, MPS_USER, "%s: Only one FW diag command "
1889 "allowed at a single time.", __func__);
1892 sc->mps_flags |= MPS_FLAGS_BUSY;
1895 * Send diag action request
1897 if (data->Action == MPS_FW_DIAG_TYPE_REGISTER ||
1898 data->Action == MPS_FW_DIAG_TYPE_UNREGISTER ||
1899 data->Action == MPS_FW_DIAG_TYPE_QUERY ||
1900 data->Action == MPS_FW_DIAG_TYPE_READ_BUFFER ||
1901 data->Action == MPS_FW_DIAG_TYPE_RELEASE) {
1902 status = mps_do_diag_action(sc, data->Action,
1903 PTRIN(data->PtrDiagAction), data->Length,
1908 sc->mps_flags &= ~MPS_FLAGS_BUSY;
1913 * Copy the event recording mask and the event queue size out. For
1914 * clarification, the event recording mask (events_to_record) is not the same
1915 * thing as the event mask (event_mask). events_to_record has a bit set for
1916 * every event type that is to be recorded by the driver, and event_mask has a
1917 * bit cleared for every event that is allowed into the driver from the IOC.
1918 * They really have nothing to do with each other.
1921 mps_user_event_query(struct mps_softc *sc, mps_event_query_t *data)
1926 data->Entries = MPS_EVENT_QUEUE_SIZE;
1928 for (i = 0; i < 4; i++) {
1929 data->Types[i] = sc->events_to_record[i];
1935 * Set the driver's event mask according to what's been given. See
1936 * mps_user_event_query for explanation of the event recording mask and the IOC
1937 * event mask. It's the app's responsibility to enable event logging by setting
1938 * the bits in events_to_record. Initially, no events will be logged.
1941 mps_user_event_enable(struct mps_softc *sc, mps_event_enable_t *data)
1946 for (i = 0; i < 4; i++) {
1947 sc->events_to_record[i] = data->Types[i];
1953 * Copy out the events that have been recorded, up to the max events allowed.
1956 mps_user_event_report(struct mps_softc *sc, mps_event_report_t *data)
1963 if ((size >= sizeof(sc->recorded_events)) && (status == 0)) {
1965 if (copyout((void *)sc->recorded_events,
1966 PTRIN(data->PtrEvents), sizeof(sc->recorded_events)) != 0)
1971 * data->Size value is not large enough to copy event data.
1977 * Change size value to match the number of bytes that were copied.
1980 data->Size = sizeof(sc->recorded_events);
1987 * Record events into the driver from the IOC if they are not masked.
1990 mpssas_record_event(struct mps_softc *sc,
1991 MPI2_EVENT_NOTIFICATION_REPLY *event_reply)
1995 uint16_t event_data_len;
1996 boolean_t sendAEN = FALSE;
1998 event = event_reply->Event;
2001 * Generate a system event to let anyone who cares know that a
2002 * LOG_ENTRY_ADDED event has occurred. This is sent no matter what the
2003 * event mask is set to.
2005 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
2010 * Record the event only if its corresponding bit is set in
2011 * events_to_record. event_index is the index into recorded_events and
2012 * event_number is the overall number of an event being recorded since
2013 * start-of-day. event_index will roll over; event_number will never
2016 i = (uint8_t)(event / 32);
2017 j = (uint8_t)(event % 32);
2018 if ((i < 4) && ((1 << j) & sc->events_to_record[i])) {
2019 i = sc->event_index;
2020 sc->recorded_events[i].Type = event;
2021 sc->recorded_events[i].Number = ++sc->event_number;
2022 bzero(sc->recorded_events[i].Data, MPS_MAX_EVENT_DATA_LENGTH *
2024 event_data_len = event_reply->EventDataLength;
2026 if (event_data_len > 0) {
2028 * Limit data to size in m_event entry
2030 if (event_data_len > MPS_MAX_EVENT_DATA_LENGTH) {
2031 event_data_len = MPS_MAX_EVENT_DATA_LENGTH;
2033 for (j = 0; j < event_data_len; j++) {
2034 sc->recorded_events[i].Data[j] =
2035 event_reply->EventData[j];
2039 * check for index wrap-around
2041 if (++i == MPS_EVENT_QUEUE_SIZE) {
2044 sc->event_index = (uint8_t)i;
2047 * Set flag to send the event.
2054 * Generate a system event if flag is set to let anyone who cares know
2055 * that an event has occurred.
2058 //SLM-how to send a system event (see kqueue, kevent)
2059 // (void) ddi_log_sysevent(mpt->m_dip, DDI_VENDOR_LSI, "MPT_SAS",
2060 // "SAS", NULL, NULL, DDI_NOSLEEP);
2065 mps_user_reg_access(struct mps_softc *sc, mps_reg_access_t *data)
2069 switch (data->Command) {
2071 * IO access is not supported.
2075 mps_dprint(sc, MPS_USER, "IO access is not supported. "
2076 "Use memory access.");
2081 data->RegData = mps_regread(sc, data->RegOffset);
2085 mps_regwrite(sc, data->RegOffset, data->RegData);
2097 mps_user_btdh(struct mps_softc *sc, mps_btdh_mapping_t *data)
2099 uint8_t bt2dh = FALSE;
2100 uint8_t dh2bt = FALSE;
2101 uint16_t dev_handle, bus, target;
2104 target = data->TargetID;
2105 dev_handle = data->DevHandle;
2108 * When DevHandle is 0xFFFF and Bus/Target are not 0xFFFF, use Bus/
2109 * Target to get DevHandle. When Bus/Target are 0xFFFF and DevHandle is
2110 * not 0xFFFF, use DevHandle to get Bus/Target. Anything else is
2113 if ((bus == 0xFFFF) && (target == 0xFFFF) && (dev_handle != 0xFFFF))
2115 if ((dev_handle == 0xFFFF) && (bus != 0xFFFF) && (target != 0xFFFF))
2117 if (!dh2bt && !bt2dh)
2121 * Only handle bus of 0. Make sure target is within range.
2127 if (target >= sc->max_devices) {
2128 mps_dprint(sc, MPS_FAULT, "Target ID is out of range "
2129 "for Bus/Target to DevHandle mapping.");
2132 dev_handle = sc->mapping_table[target].dev_handle;
2134 data->DevHandle = dev_handle;
2137 target = mps_mapping_get_tid_from_handle(sc, dev_handle);
2139 data->TargetID = target;
2146 mps_ioctl(struct cdev *dev, u_long cmd, void *arg, int flag,
2149 struct mps_softc *sc;
2150 struct mps_cfg_page_req *page_req;
2151 struct mps_ext_cfg_page_req *ext_page_req;
2153 int error, msleep_ret;
2157 page_req = (void *)arg;
2158 ext_page_req = (void *)arg;
2161 case MPSIO_READ_CFG_HEADER:
2163 error = mps_user_read_cfg_header(sc, page_req);
2166 case MPSIO_READ_CFG_PAGE:
2167 if (page_req->len < (int)sizeof(MPI2_CONFIG_PAGE_HEADER)) {
2171 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK | M_ZERO);
2172 error = copyin(page_req->buf, mps_page,
2173 sizeof(MPI2_CONFIG_PAGE_HEADER));
2177 error = mps_user_read_cfg_page(sc, page_req, mps_page);
2181 error = copyout(mps_page, page_req->buf, page_req->len);
2183 case MPSIO_READ_EXT_CFG_HEADER:
2185 error = mps_user_read_extcfg_header(sc, ext_page_req);
2188 case MPSIO_READ_EXT_CFG_PAGE:
2189 if (ext_page_req->len <
2190 (int)sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER)) {
2194 mps_page = malloc(ext_page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2195 error = copyin(ext_page_req->buf, mps_page,
2196 sizeof(MPI2_CONFIG_EXTENDED_PAGE_HEADER));
2200 error = mps_user_read_extcfg_page(sc, ext_page_req, mps_page);
2204 error = copyout(mps_page, ext_page_req->buf, ext_page_req->len);
2206 case MPSIO_WRITE_CFG_PAGE:
2207 if (page_req->len < (int)sizeof(MPI2_CONFIG_PAGE_HEADER)) {
2211 mps_page = malloc(page_req->len, M_MPSUSER, M_WAITOK|M_ZERO);
2212 error = copyin(page_req->buf, mps_page, page_req->len);
2216 error = mps_user_write_cfg_page(sc, page_req, mps_page);
2219 case MPSIO_MPS_COMMAND:
2220 error = mps_user_command(sc, (struct mps_usr_command *)arg);
2222 case MPTIOCTL_PASS_THRU:
2224 * The user has requested to pass through a command to be
2225 * executed by the MPT firmware. Call our routine which does
2226 * this. Only allow one passthru IOCTL at one time.
2228 error = mps_user_pass_thru(sc, (mps_pass_thru_t *)arg);
2230 case MPTIOCTL_GET_ADAPTER_DATA:
2232 * The user has requested to read adapter data. Call our
2233 * routine which does this.
2236 mps_user_get_adapter_data(sc, (mps_adapter_data_t *)arg);
2238 case MPTIOCTL_GET_PCI_INFO:
2240 * The user has requested to read pci info. Call
2241 * our routine which does this.
2245 mps_user_read_pci_info(sc, (mps_pci_info_t *)arg);
2248 case MPTIOCTL_RESET_ADAPTER:
2250 sc->port_enable_complete = 0;
2251 uint32_t reinit_start = time_uptime;
2252 error = mps_reinit(sc);
2253 /* Sleep for 300 second. */
2254 msleep_ret = msleep(&sc->port_enable_complete, &sc->mps_mtx, PRIBIO,
2255 "mps_porten", 300 * hz);
2258 printf("Port Enable did not complete after Diag "
2259 "Reset msleep error %d.\n", msleep_ret);
2261 mps_dprint(sc, MPS_USER,
2262 "Hard Reset with Port Enable completed in %d seconds.\n",
2263 (uint32_t) (time_uptime - reinit_start));
2265 case MPTIOCTL_DIAG_ACTION:
2267 * The user has done a diag buffer action. Call our routine
2268 * which does this. Only allow one diag action at one time.
2271 error = mps_user_diag_action(sc, (mps_diag_action_t *)arg);
2274 case MPTIOCTL_EVENT_QUERY:
2276 * The user has done an event query. Call our routine which does
2280 mps_user_event_query(sc, (mps_event_query_t *)arg);
2282 case MPTIOCTL_EVENT_ENABLE:
2284 * The user has done an event enable. Call our routine which
2288 mps_user_event_enable(sc, (mps_event_enable_t *)arg);
2290 case MPTIOCTL_EVENT_REPORT:
2292 * The user has done an event report. Call our routine which
2295 error = mps_user_event_report(sc, (mps_event_report_t *)arg);
2297 case MPTIOCTL_REG_ACCESS:
2299 * The user has requested register access. Call our routine
2303 error = mps_user_reg_access(sc, (mps_reg_access_t *)arg);
2306 case MPTIOCTL_BTDH_MAPPING:
2308 * The user has requested to translate a bus/target to a
2309 * DevHandle or a DevHandle to a bus/target. Call our routine
2312 error = mps_user_btdh(sc, (mps_btdh_mapping_t *)arg);
2319 if (mps_page != NULL)
2320 free(mps_page, M_MPSUSER);
2325 #ifdef COMPAT_FREEBSD32
2327 struct mps_cfg_page_req32 {
2328 MPI2_CONFIG_PAGE_HEADER header;
2329 uint32_t page_address;
2332 uint16_t ioc_status;
2335 struct mps_ext_cfg_page_req32 {
2336 MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
2337 uint32_t page_address;
2340 uint16_t ioc_status;
2343 struct mps_raid_action32 {
2347 uint8_t phys_disk_num;
2348 uint32_t action_data_word;
2351 uint32_t volume_status;
2352 uint32_t action_data[4];
2353 uint16_t action_status;
2354 uint16_t ioc_status;
2358 struct mps_usr_command32 {
2368 #define MPSIO_READ_CFG_HEADER32 _IOWR('M', 200, struct mps_cfg_page_req32)
2369 #define MPSIO_READ_CFG_PAGE32 _IOWR('M', 201, struct mps_cfg_page_req32)
2370 #define MPSIO_READ_EXT_CFG_HEADER32 _IOWR('M', 202, struct mps_ext_cfg_page_req32)
2371 #define MPSIO_READ_EXT_CFG_PAGE32 _IOWR('M', 203, struct mps_ext_cfg_page_req32)
2372 #define MPSIO_WRITE_CFG_PAGE32 _IOWR('M', 204, struct mps_cfg_page_req32)
2373 #define MPSIO_RAID_ACTION32 _IOWR('M', 205, struct mps_raid_action32)
2374 #define MPSIO_MPS_COMMAND32 _IOWR('M', 210, struct mps_usr_command32)
2377 mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag,
2380 struct mps_cfg_page_req32 *page32 = _arg;
2381 struct mps_ext_cfg_page_req32 *ext32 = _arg;
2382 struct mps_raid_action32 *raid32 = _arg;
2383 struct mps_usr_command32 *user32 = _arg;
2385 struct mps_cfg_page_req page;
2386 struct mps_ext_cfg_page_req ext;
2387 struct mps_raid_action raid;
2388 struct mps_usr_command user;
2394 case MPSIO_READ_CFG_HEADER32:
2395 case MPSIO_READ_CFG_PAGE32:
2396 case MPSIO_WRITE_CFG_PAGE32:
2397 if (cmd32 == MPSIO_READ_CFG_HEADER32)
2398 cmd = MPSIO_READ_CFG_HEADER;
2399 else if (cmd32 == MPSIO_READ_CFG_PAGE32)
2400 cmd = MPSIO_READ_CFG_PAGE;
2402 cmd = MPSIO_WRITE_CFG_PAGE;
2403 CP(*page32, arg.page, header);
2404 CP(*page32, arg.page, page_address);
2405 PTRIN_CP(*page32, arg.page, buf);
2406 CP(*page32, arg.page, len);
2407 CP(*page32, arg.page, ioc_status);
2410 case MPSIO_READ_EXT_CFG_HEADER32:
2411 case MPSIO_READ_EXT_CFG_PAGE32:
2412 if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32)
2413 cmd = MPSIO_READ_EXT_CFG_HEADER;
2415 cmd = MPSIO_READ_EXT_CFG_PAGE;
2416 CP(*ext32, arg.ext, header);
2417 CP(*ext32, arg.ext, page_address);
2418 PTRIN_CP(*ext32, arg.ext, buf);
2419 CP(*ext32, arg.ext, len);
2420 CP(*ext32, arg.ext, ioc_status);
2423 case MPSIO_RAID_ACTION32:
2424 cmd = MPSIO_RAID_ACTION;
2425 CP(*raid32, arg.raid, action);
2426 CP(*raid32, arg.raid, volume_bus);
2427 CP(*raid32, arg.raid, volume_id);
2428 CP(*raid32, arg.raid, phys_disk_num);
2429 CP(*raid32, arg.raid, action_data_word);
2430 PTRIN_CP(*raid32, arg.raid, buf);
2431 CP(*raid32, arg.raid, len);
2432 CP(*raid32, arg.raid, volume_status);
2433 bcopy(raid32->action_data, arg.raid.action_data,
2434 sizeof arg.raid.action_data);
2435 CP(*raid32, arg.raid, ioc_status);
2436 CP(*raid32, arg.raid, write);
2439 case MPSIO_MPS_COMMAND32:
2440 cmd = MPSIO_MPS_COMMAND;
2441 PTRIN_CP(*user32, arg.user, req);
2442 CP(*user32, arg.user, req_len);
2443 PTRIN_CP(*user32, arg.user, rpl);
2444 CP(*user32, arg.user, rpl_len);
2445 PTRIN_CP(*user32, arg.user, buf);
2446 CP(*user32, arg.user, len);
2447 CP(*user32, arg.user, flags);
2453 error = mps_ioctl(dev, cmd, &arg, flag, td);
2454 if (error == 0 && (cmd32 & IOC_OUT) != 0) {
2456 case MPSIO_READ_CFG_HEADER32:
2457 case MPSIO_READ_CFG_PAGE32:
2458 case MPSIO_WRITE_CFG_PAGE32:
2459 CP(arg.page, *page32, header);
2460 CP(arg.page, *page32, page_address);
2461 PTROUT_CP(arg.page, *page32, buf);
2462 CP(arg.page, *page32, len);
2463 CP(arg.page, *page32, ioc_status);
2466 case MPSIO_READ_EXT_CFG_HEADER32:
2467 case MPSIO_READ_EXT_CFG_PAGE32:
2468 CP(arg.ext, *ext32, header);
2469 CP(arg.ext, *ext32, page_address);
2470 PTROUT_CP(arg.ext, *ext32, buf);
2471 CP(arg.ext, *ext32, len);
2472 CP(arg.ext, *ext32, ioc_status);
2475 case MPSIO_RAID_ACTION32:
2476 CP(arg.raid, *raid32, action);
2477 CP(arg.raid, *raid32, volume_bus);
2478 CP(arg.raid, *raid32, volume_id);
2479 CP(arg.raid, *raid32, phys_disk_num);
2480 CP(arg.raid, *raid32, action_data_word);
2481 PTROUT_CP(arg.raid, *raid32, buf);
2482 CP(arg.raid, *raid32, len);
2483 CP(arg.raid, *raid32, volume_status);
2484 bcopy(arg.raid.action_data, raid32->action_data,
2485 sizeof arg.raid.action_data);
2486 CP(arg.raid, *raid32, ioc_status);
2487 CP(arg.raid, *raid32, write);
2490 case MPSIO_MPS_COMMAND32:
2491 PTROUT_CP(arg.user, *user32, req);
2492 CP(arg.user, *user32, req_len);
2493 PTROUT_CP(arg.user, *user32, rpl);
2494 CP(arg.user, *user32, rpl_len);
2495 PTROUT_CP(arg.user, *user32, buf);
2496 CP(arg.user, *user32, len);
2497 CP(arg.user, *user32, flags);
2504 #endif /* COMPAT_FREEBSD32 */
2507 mps_ioctl_devsw(struct cdev *dev, u_long com, caddr_t arg, int flag,
2510 #ifdef COMPAT_FREEBSD32
2511 if (SV_CURPROC_FLAG(SV_ILP32))
2512 return (mps_ioctl32(dev, com, arg, flag, td));
2514 return (mps_ioctl(dev, com, arg, flag, td));