2 * Copyright (c) 2011-2015 LSI Corp.
3 * Copyright (c) 2013-2015 Avago Technologies
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 /* TODO Move headers to mprvar */
34 #include <sys/types.h>
35 #include <sys/param.h>
37 #include <sys/mutex.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/kthread.h>
42 #include <sys/taskqueue.h>
44 #include <sys/endian.h>
45 #include <sys/sysctl.h>
46 #include <sys/eventhandler.h>
48 #include <machine/bus.h>
49 #include <machine/resource.h>
50 #include <dev/mpr/mpi/mpi2_type.h>
51 #include <dev/mpr/mpi/mpi2.h>
52 #include <dev/mpr/mpi/mpi2_ioc.h>
53 #include <dev/mpr/mpi/mpi2_sas.h>
54 #include <dev/mpr/mpi/mpi2_cnfg.h>
55 #include <dev/mpr/mpi/mpi2_init.h>
56 #include <dev/mpr/mpi/mpi2_tool.h>
57 #include <dev/mpr/mpr_ioctl.h>
58 #include <dev/mpr/mprvar.h>
61 * mpr_config_get_ioc_pg8 - obtain ioc page 8
62 * @sc: per adapter object
63 * @mpi_reply: reply mf payload returned from firmware
64 * @config_page: contents of the config page
67 * Returns 0 for success, non-zero for failure.
70 mpr_config_get_ioc_pg8(struct mpr_softc *sc, Mpi2ConfigReply_t *mpi_reply,
71 Mpi2IOCPage8_t *config_page)
73 MPI2_CONFIG_REQUEST *request;
74 MPI2_CONFIG_REPLY *reply;
75 struct mpr_command *cm;
76 MPI2_CONFIG_PAGE_IOC_8 *page = NULL;
80 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
82 if ((cm = mpr_alloc_command(sc)) == NULL) {
83 printf("%s: command alloc failed @ line %d\n", __func__,
88 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
89 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
90 request->Function = MPI2_FUNCTION_CONFIG;
91 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
92 request->Header.PageType = MPI2_CONFIG_PAGETYPE_IOC;
93 request->Header.PageNumber = 8;
94 request->Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
95 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
97 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
98 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
99 if (error || (reply == NULL)) {
102 * If the request returns an error then we need to do a diag
105 printf("%s: request for header completed with error %d",
110 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
111 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
112 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
115 * If the request returns an error then we need to do a diag
118 printf("%s: header read with error; iocstatus = 0x%x\n",
119 __func__, ioc_status);
123 /* We have to do free and alloc for the reply-free and reply-post
124 * counters to match - Need to review the reply FIFO handling.
126 mpr_free_command(sc, cm);
128 if ((cm = mpr_alloc_command(sc)) == NULL) {
129 printf("%s: command alloc failed @ line %d\n", __func__,
134 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
135 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
136 request->Function = MPI2_FUNCTION_CONFIG;
137 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
138 request->Header.PageType = MPI2_CONFIG_PAGETYPE_IOC;
139 request->Header.PageNumber = 8;
140 request->Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
141 request->Header.PageLength = mpi_reply->Header.PageLength;
142 cm->cm_length = le16toh(mpi_reply->Header.PageLength) * 4;
143 cm->cm_sge = &request->PageBufferSGE;
144 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
145 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
146 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
147 page = malloc((cm->cm_length), M_MPR, M_ZERO | M_NOWAIT);
149 printf("%s: page alloc failed\n", __func__);
155 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
156 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
157 if (error || (reply == NULL)) {
160 * If the request returns an error then we need to do a diag
163 printf("%s: request for page completed with error %d",
168 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
169 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
170 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
173 * If the request returns an error then we need to do a diag
176 printf("%s: page read with error; iocstatus = 0x%x\n",
177 __func__, ioc_status);
181 bcopy(page, config_page, MIN(cm->cm_length, (sizeof(Mpi2IOCPage8_t))));
186 mpr_free_command(sc, cm);
191 * mpr_config_get_iounit_pg8 - obtain iounit page 8
192 * @sc: per adapter object
193 * @mpi_reply: reply mf payload returned from firmware
194 * @config_page: contents of the config page
197 * Returns 0 for success, non-zero for failure.
200 mpr_config_get_iounit_pg8(struct mpr_softc *sc, Mpi2ConfigReply_t *mpi_reply,
201 Mpi2IOUnitPage8_t *config_page)
203 MPI2_CONFIG_REQUEST *request;
204 MPI2_CONFIG_REPLY *reply;
205 struct mpr_command *cm;
206 MPI2_CONFIG_PAGE_IO_UNIT_8 *page = NULL;
210 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
212 if ((cm = mpr_alloc_command(sc)) == NULL) {
213 printf("%s: command alloc failed @ line %d\n", __func__,
218 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
219 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
220 request->Function = MPI2_FUNCTION_CONFIG;
221 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
222 request->Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
223 request->Header.PageNumber = 8;
224 request->Header.PageVersion = MPI2_IOUNITPAGE8_PAGEVERSION;
225 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
227 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
228 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
229 if (error || (reply == NULL)) {
232 * If the request returns an error then we need to do a diag
235 printf("%s: request for header completed with error %d",
240 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
241 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
242 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
245 * If the request returns an error then we need to do a diag
248 printf("%s: header read with error; iocstatus = 0x%x\n",
249 __func__, ioc_status);
253 /* We have to do free and alloc for the reply-free and reply-post
254 * counters to match - Need to review the reply FIFO handling.
256 mpr_free_command(sc, cm);
258 if ((cm = mpr_alloc_command(sc)) == NULL) {
259 printf("%s: command alloc failed @ line %d\n", __func__,
264 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
265 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
266 request->Function = MPI2_FUNCTION_CONFIG;
267 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
268 request->Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
269 request->Header.PageNumber = 8;
270 request->Header.PageVersion = MPI2_IOUNITPAGE8_PAGEVERSION;
271 request->Header.PageLength = mpi_reply->Header.PageLength;
272 cm->cm_length = le16toh(mpi_reply->Header.PageLength) * 4;
273 cm->cm_sge = &request->PageBufferSGE;
274 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
275 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
276 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
277 page = malloc((cm->cm_length), M_MPR, M_ZERO | M_NOWAIT);
279 printf("%s: page alloc failed\n", __func__);
285 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
286 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
287 if (error || (reply == NULL)) {
290 * If the request returns an error then we need to do a diag
293 printf("%s: request for page completed with error %d",
298 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
299 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
300 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
303 * If the request returns an error then we need to do a diag
306 printf("%s: page read with error; iocstatus = 0x%x\n",
307 __func__, ioc_status);
311 bcopy(page, config_page, MIN(cm->cm_length,
312 (sizeof(Mpi2IOUnitPage8_t))));
317 mpr_free_command(sc, cm);
322 * mpr_base_static_config_pages - static start of day config pages.
323 * @sc: per adapter object
328 mpr_base_static_config_pages(struct mpr_softc *sc)
330 Mpi2ConfigReply_t mpi_reply;
334 while (mpr_config_get_ioc_pg8(sc, &mpi_reply, &sc->ioc_pg8)) {
337 /* We need to Handle this situation */
343 while (mpr_config_get_iounit_pg8(sc, &mpi_reply, &sc->iounit_pg8)) {
346 /* We need to Handle this situation */
354 * mpr_config_get_dpm_pg0 - obtain driver persistent mapping page0
355 * @sc: per adapter object
356 * @mpi_reply: reply mf payload returned from firmware
357 * @config_page: contents of the config page
358 * @sz: size of buffer passed in config_page
361 * Returns 0 for success, non-zero for failure.
364 mpr_config_get_dpm_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t *mpi_reply,
365 Mpi2DriverMappingPage0_t *config_page, u16 sz)
367 MPI2_CONFIG_REQUEST *request;
368 MPI2_CONFIG_REPLY *reply;
369 struct mpr_command *cm;
370 Mpi2DriverMappingPage0_t *page = NULL;
374 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
376 memset(config_page, 0, sz);
377 if ((cm = mpr_alloc_command(sc)) == NULL) {
378 printf("%s: command alloc failed @ line %d\n", __func__,
383 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
384 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
385 request->Function = MPI2_FUNCTION_CONFIG;
386 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
387 request->Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
388 request->ExtPageType = MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING;
389 request->Header.PageNumber = 0;
390 request->Header.PageVersion = MPI2_DRIVERMAPPING0_PAGEVERSION;
391 request->PageAddress = sc->max_dpm_entries <<
392 MPI2_DPM_PGAD_ENTRY_COUNT_SHIFT;
393 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
395 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
396 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
397 if (error || (reply == NULL)) {
400 * If the request returns an error then we need to do a diag
403 printf("%s: request for header completed with error %d",
408 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
409 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
410 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
413 * If the request returns an error then we need to do a diag
416 printf("%s: header read with error; iocstatus = 0x%x\n",
417 __func__, ioc_status);
421 /* We have to do free and alloc for the reply-free and reply-post
422 * counters to match - Need to review the reply FIFO handling.
424 mpr_free_command(sc, cm);
426 if ((cm = mpr_alloc_command(sc)) == NULL) {
427 printf("%s: command alloc failed @ line %d\n", __func__,
432 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
433 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
434 request->Function = MPI2_FUNCTION_CONFIG;
435 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_NVRAM;
436 request->Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
437 request->ExtPageType = MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING;
438 request->Header.PageNumber = 0;
439 request->Header.PageVersion = MPI2_DRIVERMAPPING0_PAGEVERSION;
440 request->PageAddress = sc->max_dpm_entries <<
441 MPI2_DPM_PGAD_ENTRY_COUNT_SHIFT;
442 request->ExtPageLength = mpi_reply->ExtPageLength;
443 cm->cm_length = le16toh(request->ExtPageLength) * 4;
444 cm->cm_sge = &request->PageBufferSGE;
445 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
446 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
447 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
448 page = malloc(cm->cm_length, M_MPR, M_ZERO|M_NOWAIT);
450 printf("%s: page alloc failed\n", __func__);
455 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
456 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
457 if (error || (reply == NULL)) {
460 * If the request returns an error then we need to do a diag
463 printf("%s: request for page completed with error %d",
468 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
469 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
470 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
473 * If the request returns an error then we need to do a diag
476 printf("%s: page read with error; iocstatus = 0x%x\n",
477 __func__, ioc_status);
481 bcopy(page, config_page, MIN(cm->cm_length, sz));
485 mpr_free_command(sc, cm);
490 * mpr_config_set_dpm_pg0 - write an entry in driver persistent mapping page0
491 * @sc: per adapter object
492 * @mpi_reply: reply mf payload returned from firmware
493 * @config_page: contents of the config page
494 * @entry_idx: entry index in DPM Page0 to be modified
497 * Returns 0 for success, non-zero for failure.
500 int mpr_config_set_dpm_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t *mpi_reply,
501 Mpi2DriverMappingPage0_t *config_page, u16 entry_idx)
503 MPI2_CONFIG_REQUEST *request;
504 MPI2_CONFIG_REPLY *reply;
505 struct mpr_command *cm;
506 MPI2_CONFIG_PAGE_DRIVER_MAPPING_0 *page = NULL;
510 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
512 if ((cm = mpr_alloc_command(sc)) == NULL) {
513 printf("%s: command alloc failed @ line %d\n", __func__,
518 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
519 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
520 request->Function = MPI2_FUNCTION_CONFIG;
521 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
522 request->Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
523 request->ExtPageType = MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING;
524 request->Header.PageNumber = 0;
525 request->Header.PageVersion = MPI2_DRIVERMAPPING0_PAGEVERSION;
526 /* We can remove below two lines ????*/
527 request->PageAddress = 1 << MPI2_DPM_PGAD_ENTRY_COUNT_SHIFT;
528 request->PageAddress |= htole16(entry_idx);
529 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
531 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
532 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
533 if (error || (reply == NULL)) {
536 * If the request returns an error then we need to do a diag
539 printf("%s: request for header completed with error %d",
544 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
545 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
546 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
549 * If the request returns an error then we need to do a diag
552 printf("%s: header read with error; iocstatus = 0x%x\n",
553 __func__, ioc_status);
557 /* We have to do free and alloc for the reply-free and reply-post
558 * counters to match - Need to review the reply FIFO handling.
560 mpr_free_command(sc, cm);
562 if ((cm = mpr_alloc_command(sc)) == NULL) {
563 printf("%s: command alloc failed @ line %d\n", __func__,
568 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
569 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
570 request->Function = MPI2_FUNCTION_CONFIG;
571 request->Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
572 request->Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
573 request->ExtPageType = MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING;
574 request->Header.PageNumber = 0;
575 request->Header.PageVersion = MPI2_DRIVERMAPPING0_PAGEVERSION;
576 request->ExtPageLength = mpi_reply->ExtPageLength;
577 request->PageAddress = 1 << MPI2_DPM_PGAD_ENTRY_COUNT_SHIFT;
578 request->PageAddress |= htole16(entry_idx);
579 cm->cm_length = le16toh(mpi_reply->ExtPageLength) * 4;
580 cm->cm_sge = &request->PageBufferSGE;
581 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
582 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAOUT;
583 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
584 page = malloc(cm->cm_length, M_MPR, M_ZERO | M_NOWAIT);
586 printf("%s: page alloc failed\n", __func__);
590 bcopy(config_page, page, MIN(cm->cm_length,
591 (sizeof(Mpi2DriverMappingPage0_t))));
593 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
594 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
595 if (error || (reply == NULL)) {
598 * If the request returns an error then we need to do a diag
601 printf("%s: request to write page completed with error %d",
606 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
607 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
608 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
611 * If the request returns an error then we need to do a diag
614 printf("%s: page written with error; iocstatus = 0x%x\n",
615 __func__, ioc_status);
622 mpr_free_command(sc, cm);
627 * mpr_config_get_sas_device_pg0 - obtain sas device page 0
628 * @sc: per adapter object
629 * @mpi_reply: reply mf payload returned from firmware
630 * @config_page: contents of the config page
631 * @form: GET_NEXT_HANDLE or HANDLE
632 * @handle: device handle
635 * Returns 0 for success, non-zero for failure.
638 mpr_config_get_sas_device_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t
639 *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u16 handle)
641 MPI2_CONFIG_REQUEST *request;
642 MPI2_CONFIG_REPLY *reply;
643 struct mpr_command *cm;
644 Mpi2SasDevicePage0_t *page = NULL;
648 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
650 if ((cm = mpr_alloc_command(sc)) == NULL) {
651 printf("%s: command alloc failed @ line %d\n", __func__,
656 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
657 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
658 request->Function = MPI2_FUNCTION_CONFIG;
659 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
660 request->Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
661 request->ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE;
662 request->Header.PageNumber = 0;
663 request->Header.PageVersion = MPI2_SASDEVICE0_PAGEVERSION;
664 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
666 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
667 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
668 if (error || (reply == NULL)) {
671 * If the request returns an error then we need to do a diag
674 printf("%s: request for header completed with error %d",
679 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
680 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
681 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
684 * If the request returns an error then we need to do a diag
687 printf("%s: header read with error; iocstatus = 0x%x\n",
688 __func__, ioc_status);
692 /* We have to do free and alloc for the reply-free and reply-post
693 * counters to match - Need to review the reply FIFO handling.
695 mpr_free_command(sc, cm);
697 if ((cm = mpr_alloc_command(sc)) == NULL) {
698 printf("%s: command alloc failed @ line %d\n", __func__,
703 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
704 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
705 request->Function = MPI2_FUNCTION_CONFIG;
706 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
707 request->Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
708 request->ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE;
709 request->Header.PageNumber = 0;
710 request->Header.PageVersion = MPI2_SASDEVICE0_PAGEVERSION;
711 request->ExtPageLength = mpi_reply->ExtPageLength;
712 request->PageAddress = htole32(form | handle);
713 cm->cm_length = le16toh(mpi_reply->ExtPageLength) * 4;
714 cm->cm_sge = &request->PageBufferSGE;
715 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
716 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
717 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
718 page = malloc(cm->cm_length, M_MPR, M_ZERO | M_NOWAIT);
720 printf("%s: page alloc failed\n", __func__);
726 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
727 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
728 if (error || (reply == NULL)) {
731 * If the request returns an error then we need to do a diag
734 printf("%s: request for page completed with error %d",
739 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
740 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
741 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
744 * If the request returns an error then we need to do a diag
747 printf("%s: page read with error; iocstatus = 0x%x\n",
748 __func__, ioc_status);
752 bcopy(page, config_page, MIN(cm->cm_length,
753 sizeof(Mpi2SasDevicePage0_t)));
757 mpr_free_command(sc, cm);
762 * mpr_config_get_bios_pg3 - obtain BIOS page 3
763 * @sc: per adapter object
764 * @mpi_reply: reply mf payload returned from firmware
765 * @config_page: contents of the config page
768 * Returns 0 for success, non-zero for failure.
771 mpr_config_get_bios_pg3(struct mpr_softc *sc, Mpi2ConfigReply_t *mpi_reply,
772 Mpi2BiosPage3_t *config_page)
774 MPI2_CONFIG_REQUEST *request;
775 MPI2_CONFIG_REPLY *reply;
776 struct mpr_command *cm;
777 Mpi2BiosPage3_t *page = NULL;
781 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
783 if ((cm = mpr_alloc_command(sc)) == NULL) {
784 printf("%s: command alloc failed @ line %d\n", __func__,
789 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
790 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
791 request->Function = MPI2_FUNCTION_CONFIG;
792 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
793 request->Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS;
794 request->Header.PageNumber = 3;
795 request->Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION;
796 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
798 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
799 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
800 if (error || (reply == NULL)) {
803 * If the request returns an error then we need to do a diag
806 printf("%s: request for header completed with error %d",
811 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
812 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
813 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
816 * If the request returns an error then we need to do a diag
819 printf("%s: header read with error; iocstatus = 0x%x\n",
820 __func__, ioc_status);
824 /* We have to do free and alloc for the reply-free and reply-post
825 * counters to match - Need to review the reply FIFO handling.
827 mpr_free_command(sc, cm);
829 if ((cm = mpr_alloc_command(sc)) == NULL) {
830 printf("%s: command alloc failed @ line %d\n", __func__,
835 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
836 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
837 request->Function = MPI2_FUNCTION_CONFIG;
838 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
839 request->Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS;
840 request->Header.PageNumber = 3;
841 request->Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION;
842 request->Header.PageLength = mpi_reply->Header.PageLength;
843 cm->cm_length = le16toh(mpi_reply->Header.PageLength) * 4;
844 cm->cm_sge = &request->PageBufferSGE;
845 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
846 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
847 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
848 page = malloc(cm->cm_length, M_MPR, M_ZERO | M_NOWAIT);
850 printf("%s: page alloc failed\n", __func__);
856 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
857 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
858 if (error || (reply == NULL)) {
861 * If the request returns an error then we need to do a diag
864 printf("%s: request for page completed with error %d",
869 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
870 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
871 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
874 * If the request returns an error then we need to do a diag
877 printf("%s: page read with error; iocstatus = 0x%x\n",
878 __func__, ioc_status);
882 bcopy(page, config_page, MIN(cm->cm_length, sizeof(Mpi2BiosPage3_t)));
886 mpr_free_command(sc, cm);
891 * mpr_config_get_raid_volume_pg0 - obtain raid volume page 0
892 * @sc: per adapter object
893 * @mpi_reply: reply mf payload returned from firmware
894 * @config_page: contents of the config page
895 * @page_address: form and handle value used to get page
898 * Returns 0 for success, non-zero for failure.
901 mpr_config_get_raid_volume_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t
902 *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 page_address)
904 MPI2_CONFIG_REQUEST *request;
905 MPI2_CONFIG_REPLY *reply;
906 struct mpr_command *cm;
907 Mpi2RaidVolPage0_t *page = NULL;
911 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
913 if ((cm = mpr_alloc_command(sc)) == NULL) {
914 printf("%s: command alloc failed @ line %d\n", __func__,
919 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
920 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
921 request->Function = MPI2_FUNCTION_CONFIG;
922 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
923 request->Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
924 request->Header.PageNumber = 0;
925 request->Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION;
926 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
930 * This page must be polled because the IOC isn't ready yet when this
933 error = mpr_request_polled(sc, cm);
934 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
935 if (error || (reply == NULL)) {
937 /* If the poll returns error then we need to do diag reset */
938 printf("%s: poll for header completed with error %d",
943 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
944 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
945 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
947 /* If the poll returns error then we need to do diag reset */
948 printf("%s: header read with error; iocstatus = 0x%x\n",
949 __func__, ioc_status);
953 /* We have to do free and alloc for the reply-free and reply-post
954 * counters to match - Need to review the reply FIFO handling.
956 mpr_free_command(sc, cm);
958 if ((cm = mpr_alloc_command(sc)) == NULL) {
959 printf("%s: command alloc failed @ line %d\n", __func__,
964 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
965 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
966 request->Function = MPI2_FUNCTION_CONFIG;
967 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
968 request->Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
969 request->Header.PageNumber = 0;
970 request->Header.PageLength = mpi_reply->Header.PageLength;
971 request->Header.PageVersion = mpi_reply->Header.PageVersion;
972 request->PageAddress = page_address;
973 cm->cm_length = le16toh(mpi_reply->Header.PageLength) * 4;
974 cm->cm_sge = &request->PageBufferSGE;
975 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
976 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
977 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
978 page = malloc(cm->cm_length, M_MPR, M_ZERO | M_NOWAIT);
980 printf("%s: page alloc failed\n", __func__);
987 * This page must be polled because the IOC isn't ready yet when this
990 error = mpr_request_polled(sc, cm);
991 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
992 if (error || (reply == NULL)) {
994 /* If the poll returns error then we need to do diag reset */
995 printf("%s: poll for page completed with error %d",
1000 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1001 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
1002 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1004 /* If the poll returns error then we need to do diag reset */
1005 printf("%s: page read with error; iocstatus = 0x%x\n",
1006 __func__, ioc_status);
1010 bcopy(page, config_page, cm->cm_length);
1014 mpr_free_command(sc, cm);
1019 * mpr_config_get_raid_volume_pg1 - obtain raid volume page 1
1020 * @sc: per adapter object
1021 * @mpi_reply: reply mf payload returned from firmware
1022 * @config_page: contents of the config page
1023 * @form: GET_NEXT_HANDLE or HANDLE
1024 * @handle: volume handle
1027 * Returns 0 for success, non-zero for failure.
1030 mpr_config_get_raid_volume_pg1(struct mpr_softc *sc, Mpi2ConfigReply_t
1031 *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u16 handle)
1033 MPI2_CONFIG_REQUEST *request;
1034 MPI2_CONFIG_REPLY *reply;
1035 struct mpr_command *cm;
1036 Mpi2RaidVolPage1_t *page = NULL;
1040 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
1042 if ((cm = mpr_alloc_command(sc)) == NULL) {
1043 printf("%s: command alloc failed @ line %d\n", __func__,
1048 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
1049 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
1050 request->Function = MPI2_FUNCTION_CONFIG;
1051 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
1052 request->Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
1053 request->Header.PageNumber = 1;
1054 request->Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION;
1055 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1057 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
1058 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
1059 if (error || (reply == NULL)) {
1062 * If the request returns an error then we need to do a diag
1065 printf("%s: request for header completed with error %d",
1070 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1071 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
1072 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1075 * If the request returns an error then we need to do a diag
1078 printf("%s: header read with error; iocstatus = 0x%x\n",
1079 __func__, ioc_status);
1083 /* We have to do free and alloc for the reply-free and reply-post
1084 * counters to match - Need to review the reply FIFO handling.
1086 mpr_free_command(sc, cm);
1088 if ((cm = mpr_alloc_command(sc)) == NULL) {
1089 printf("%s: command alloc failed @ line %d\n", __func__,
1094 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
1095 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
1096 request->Function = MPI2_FUNCTION_CONFIG;
1097 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1098 request->Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME;
1099 request->Header.PageNumber = 1;
1100 request->Header.PageLength = mpi_reply->Header.PageLength;
1101 request->Header.PageVersion = mpi_reply->Header.PageVersion;
1102 request->PageAddress = htole32(form | handle);
1103 cm->cm_length = le16toh(mpi_reply->Header.PageLength) * 4;
1104 cm->cm_sge = &request->PageBufferSGE;
1105 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
1106 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
1107 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1108 page = malloc(cm->cm_length, M_MPR, M_ZERO | M_NOWAIT);
1110 printf("%s: page alloc failed\n", __func__);
1116 error = mpr_wait_command(sc, cm, 60, CAN_SLEEP);
1117 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
1118 if (error || (reply == NULL)) {
1121 * If the request returns an error then we need to do a diag
1124 printf("%s: request for page completed with error %d",
1129 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1130 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
1131 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1134 * If the request returns an error then we need to do a diag
1137 printf("%s: page read with error; iocstatus = 0x%x\n",
1138 __func__, ioc_status);
1142 bcopy(page, config_page, MIN(cm->cm_length,
1143 sizeof(Mpi2RaidVolPage1_t)));
1147 mpr_free_command(sc, cm);
1152 * mpr_config_get_volume_wwid - returns wwid given the volume handle
1153 * @sc: per adapter object
1154 * @volume_handle: volume handle
1155 * @wwid: volume wwid
1158 * Returns 0 for success, non-zero for failure.
1161 mpr_config_get_volume_wwid(struct mpr_softc *sc, u16 volume_handle, u64 *wwid)
1163 Mpi2ConfigReply_t mpi_reply;
1164 Mpi2RaidVolPage1_t raid_vol_pg1;
1167 if (!(mpr_config_get_raid_volume_pg1(sc, &mpi_reply, &raid_vol_pg1,
1168 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, volume_handle))) {
1169 *wwid = le64toh((u64)raid_vol_pg1.WWID.High << 32 |
1170 raid_vol_pg1.WWID.Low);
1177 * mpr_config_get_pd_pg0 - obtain raid phys disk page 0
1178 * @sc: per adapter object
1179 * @mpi_reply: reply mf payload returned from firmware
1180 * @config_page: contents of the config page
1181 * @page_address: form and handle value used to get page
1184 * Returns 0 for success, non-zero for failure.
1187 mpr_config_get_raid_pd_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t *mpi_reply,
1188 Mpi2RaidPhysDiskPage0_t *config_page, u32 page_address)
1190 MPI2_CONFIG_REQUEST *request;
1191 MPI2_CONFIG_REPLY *reply;
1192 struct mpr_command *cm;
1193 Mpi2RaidPhysDiskPage0_t *page = NULL;
1197 mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
1199 if ((cm = mpr_alloc_command(sc)) == NULL) {
1200 printf("%s: command alloc failed @ line %d\n", __func__,
1205 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
1206 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
1207 request->Function = MPI2_FUNCTION_CONFIG;
1208 request->Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
1209 request->Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK;
1210 request->Header.PageNumber = 0;
1211 request->Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION;
1212 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1216 * This page must be polled because the IOC isn't ready yet when this
1219 error = mpr_request_polled(sc, cm);
1220 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
1221 if (error || (reply == NULL)) {
1223 /* If the poll returns error then we need to do diag reset */
1224 printf("%s: poll for header completed with error %d",
1229 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1230 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
1231 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1233 /* If the poll returns error then we need to do diag reset */
1234 printf("%s: header read with error; iocstatus = 0x%x\n",
1235 __func__, ioc_status);
1239 /* We have to do free and alloc for the reply-free and reply-post
1240 * counters to match - Need to review the reply FIFO handling.
1242 mpr_free_command(sc, cm);
1244 if ((cm = mpr_alloc_command(sc)) == NULL) {
1245 printf("%s: command alloc failed @ line %d\n", __func__,
1250 request = (MPI2_CONFIG_REQUEST *)cm->cm_req;
1251 bzero(request, sizeof(MPI2_CONFIG_REQUEST));
1252 request->Function = MPI2_FUNCTION_CONFIG;
1253 request->Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1254 request->Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK;
1255 request->Header.PageNumber = 0;
1256 request->Header.PageLength = mpi_reply->Header.PageLength;
1257 request->Header.PageVersion = mpi_reply->Header.PageVersion;
1258 request->PageAddress = page_address;
1259 cm->cm_length = le16toh(mpi_reply->Header.PageLength) * 4;
1260 cm->cm_sge = &request->PageBufferSGE;
1261 cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
1262 cm->cm_flags = MPR_CM_FLAGS_SGE_SIMPLE | MPR_CM_FLAGS_DATAIN;
1263 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1264 page = malloc(cm->cm_length, M_MPR, M_ZERO | M_NOWAIT);
1266 printf("%s: page alloc failed\n", __func__);
1273 * This page must be polled because the IOC isn't ready yet when this
1276 error = mpr_request_polled(sc, cm);
1277 reply = (MPI2_CONFIG_REPLY *)cm->cm_reply;
1278 if (error || (reply == NULL)) {
1280 /* If the poll returns error then we need to do diag reset */
1281 printf("%s: poll for page completed with error %d",
1286 ioc_status = le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1287 bcopy(reply, mpi_reply, sizeof(MPI2_CONFIG_REPLY));
1288 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1290 /* If the poll returns error then we need to do diag reset */
1291 printf("%s: page read with error; iocstatus = 0x%x\n",
1292 __func__, ioc_status);
1296 bcopy(page, config_page, MIN(cm->cm_length,
1297 sizeof(Mpi2RaidPhysDiskPage0_t)));
1301 mpr_free_command(sc, cm);