1991554f2SKenneth D. Merry /*-
2a2c14879SStephen McConnell * Copyright (c) 2011-2015 LSI Corp.
37a2a6a1aSStephen McConnell * Copyright (c) 2013-2016 Avago Technologies
446b23587SKashyap D Desai * Copyright 2000-2020 Broadcom Inc.
5991554f2SKenneth D. Merry * All rights reserved.
6991554f2SKenneth D. Merry *
7991554f2SKenneth D. Merry * Redistribution and use in source and binary forms, with or without
8991554f2SKenneth D. Merry * modification, are permitted provided that the following conditions
9991554f2SKenneth D. Merry * are met:
10991554f2SKenneth D. Merry * 1. Redistributions of source code must retain the above copyright
11991554f2SKenneth D. Merry * notice, this list of conditions and the following disclaimer.
12991554f2SKenneth D. Merry * 2. Redistributions in binary form must reproduce the above copyright
13991554f2SKenneth D. Merry * notice, this list of conditions and the following disclaimer in the
14991554f2SKenneth D. Merry * documentation and/or other materials provided with the distribution.
15991554f2SKenneth D. Merry *
16991554f2SKenneth D. Merry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17991554f2SKenneth D. Merry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18991554f2SKenneth D. Merry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19991554f2SKenneth D. Merry * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20991554f2SKenneth D. Merry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21991554f2SKenneth D. Merry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22991554f2SKenneth D. Merry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23991554f2SKenneth D. Merry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24991554f2SKenneth D. Merry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25991554f2SKenneth D. Merry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26991554f2SKenneth D. Merry * SUCH DAMAGE.
27991554f2SKenneth D. Merry *
2846b23587SKashyap D Desai * Broadcom Inc. (LSI) MPT-Fusion Host Adapter FreeBSD
29991554f2SKenneth D. Merry */
30991554f2SKenneth D. Merry
31991554f2SKenneth D. Merry #include <sys/cdefs.h>
327a2a6a1aSStephen McConnell /* Communications core for Avago Technologies (LSI) MPT3 */
33991554f2SKenneth D. Merry
34991554f2SKenneth D. Merry /* TODO Move headers to mprvar */
35991554f2SKenneth D. Merry #include <sys/types.h>
36991554f2SKenneth D. Merry #include <sys/param.h>
37991554f2SKenneth D. Merry #include <sys/systm.h>
38991554f2SKenneth D. Merry #include <sys/kernel.h>
39991554f2SKenneth D. Merry #include <sys/selinfo.h>
40991554f2SKenneth D. Merry #include <sys/module.h>
41991554f2SKenneth D. Merry #include <sys/bus.h>
42991554f2SKenneth D. Merry #include <sys/conf.h>
43991554f2SKenneth D. Merry #include <sys/bio.h>
44991554f2SKenneth D. Merry #include <sys/malloc.h>
45991554f2SKenneth D. Merry #include <sys/uio.h>
46991554f2SKenneth D. Merry #include <sys/sysctl.h>
47991554f2SKenneth D. Merry #include <sys/endian.h>
48acc173a6SWarner Losh #include <sys/proc.h>
49991554f2SKenneth D. Merry #include <sys/queue.h>
50991554f2SKenneth D. Merry #include <sys/kthread.h>
51991554f2SKenneth D. Merry #include <sys/taskqueue.h>
52991554f2SKenneth D. Merry #include <sys/sbuf.h>
53acc173a6SWarner Losh #include <sys/reboot.h>
54991554f2SKenneth D. Merry
55991554f2SKenneth D. Merry #include <machine/bus.h>
56991554f2SKenneth D. Merry #include <machine/resource.h>
57991554f2SKenneth D. Merry #include <sys/rman.h>
58991554f2SKenneth D. Merry
59991554f2SKenneth D. Merry #include <machine/stdarg.h>
60991554f2SKenneth D. Merry
61991554f2SKenneth D. Merry #include <cam/cam.h>
62991554f2SKenneth D. Merry #include <cam/cam_ccb.h>
63991554f2SKenneth D. Merry #include <cam/cam_debug.h>
64991554f2SKenneth D. Merry #include <cam/cam_sim.h>
65991554f2SKenneth D. Merry #include <cam/cam_xpt_sim.h>
66991554f2SKenneth D. Merry #include <cam/cam_xpt_periph.h>
67991554f2SKenneth D. Merry #include <cam/cam_periph.h>
68991554f2SKenneth D. Merry #include <cam/scsi/scsi_all.h>
69991554f2SKenneth D. Merry #include <cam/scsi/scsi_message.h>
70991554f2SKenneth D. Merry
71991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_type.h>
72991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2.h>
73991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_ioc.h>
74991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_sas.h>
7567feec50SStephen McConnell #include <dev/mpr/mpi/mpi2_pci.h>
76991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_cnfg.h>
77991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_init.h>
78991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_raid.h>
79991554f2SKenneth D. Merry #include <dev/mpr/mpi/mpi2_tool.h>
80991554f2SKenneth D. Merry #include <dev/mpr/mpr_ioctl.h>
81991554f2SKenneth D. Merry #include <dev/mpr/mprvar.h>
82991554f2SKenneth D. Merry #include <dev/mpr/mpr_table.h>
83991554f2SKenneth D. Merry #include <dev/mpr/mpr_sas.h>
84991554f2SKenneth D. Merry
85991554f2SKenneth D. Merry /* For Hashed SAS Address creation for SATA Drives */
86991554f2SKenneth D. Merry #define MPT2SAS_SN_LEN 20
87991554f2SKenneth D. Merry #define MPT2SAS_MN_LEN 40
88991554f2SKenneth D. Merry
89991554f2SKenneth D. Merry struct mpr_fw_event_work {
90991554f2SKenneth D. Merry u16 event;
91991554f2SKenneth D. Merry void *event_data;
92991554f2SKenneth D. Merry TAILQ_ENTRY(mpr_fw_event_work) ev_link;
93991554f2SKenneth D. Merry };
94991554f2SKenneth D. Merry
95991554f2SKenneth D. Merry union _sata_sas_address {
96991554f2SKenneth D. Merry u8 wwid[8];
97991554f2SKenneth D. Merry struct {
98991554f2SKenneth D. Merry u32 high;
99991554f2SKenneth D. Merry u32 low;
100991554f2SKenneth D. Merry } word;
101991554f2SKenneth D. Merry };
102991554f2SKenneth D. Merry
103991554f2SKenneth D. Merry /*
104991554f2SKenneth D. Merry * define the IDENTIFY DEVICE structure
105991554f2SKenneth D. Merry */
106991554f2SKenneth D. Merry struct _ata_identify_device_data {
107991554f2SKenneth D. Merry u16 reserved1[10]; /* 0-9 */
108991554f2SKenneth D. Merry u16 serial_number[10]; /* 10-19 */
109991554f2SKenneth D. Merry u16 reserved2[7]; /* 20-26 */
110991554f2SKenneth D. Merry u16 model_number[20]; /* 27-46*/
111a2c14879SStephen McConnell u16 reserved3[170]; /* 47-216 */
112a2c14879SStephen McConnell u16 rotational_speed; /* 217 */
113a2c14879SStephen McConnell u16 reserved4[38]; /* 218-255 */
114991554f2SKenneth D. Merry };
115991554f2SKenneth D. Merry static u32 event_count;
116991554f2SKenneth D. Merry static void mprsas_fw_work(struct mpr_softc *sc,
117991554f2SKenneth D. Merry struct mpr_fw_event_work *fw_event);
118991554f2SKenneth D. Merry static void mprsas_fw_event_free(struct mpr_softc *,
119991554f2SKenneth D. Merry struct mpr_fw_event_work *);
120991554f2SKenneth D. Merry static int mprsas_add_device(struct mpr_softc *sc, u16 handle, u8 linkrate);
12167feec50SStephen McConnell static int mprsas_add_pcie_device(struct mpr_softc *sc, u16 handle,
12267feec50SStephen McConnell u8 linkrate);
123991554f2SKenneth D. Merry static int mprsas_get_sata_identify(struct mpr_softc *sc, u16 handle,
124991554f2SKenneth D. Merry Mpi2SataPassthroughReply_t *mpi_reply, char *id_buffer, int sz,
125991554f2SKenneth D. Merry u32 devinfo);
126175ad3d0SKenneth D. Merry static void mprsas_ata_id_complete(struct mpr_softc *, struct mpr_command *);
12786312e46SConrad Meyer static void mprsas_ata_id_timeout(struct mpr_softc *, struct mpr_command *);
128991554f2SKenneth D. Merry int mprsas_get_sas_address_for_sata_disk(struct mpr_softc *sc,
129a2c14879SStephen McConnell u64 *sas_address, u16 handle, u32 device_info, u8 *is_SATA_SSD);
130991554f2SKenneth D. Merry static int mprsas_volume_add(struct mpr_softc *sc,
131991554f2SKenneth D. Merry u16 handle);
132acc173a6SWarner Losh static void mprsas_SSU_to_SATA_devices(struct mpr_softc *sc, int howto);
133991554f2SKenneth D. Merry static void mprsas_stop_unit_done(struct cam_periph *periph,
134991554f2SKenneth D. Merry union ccb *done_ccb);
135991554f2SKenneth D. Merry
136991554f2SKenneth D. Merry void
mprsas_evt_handler(struct mpr_softc * sc,uintptr_t data,MPI2_EVENT_NOTIFICATION_REPLY * event)137991554f2SKenneth D. Merry mprsas_evt_handler(struct mpr_softc *sc, uintptr_t data,
138991554f2SKenneth D. Merry MPI2_EVENT_NOTIFICATION_REPLY *event)
139991554f2SKenneth D. Merry {
140991554f2SKenneth D. Merry struct mpr_fw_event_work *fw_event;
141991554f2SKenneth D. Merry u16 sz;
142991554f2SKenneth D. Merry
143991554f2SKenneth D. Merry mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
144055e2653SScott Long MPR_DPRINT_EVENT(sc, sas, event);
145991554f2SKenneth D. Merry mprsas_record_event(sc, event);
146991554f2SKenneth D. Merry
147991554f2SKenneth D. Merry fw_event = malloc(sizeof(struct mpr_fw_event_work), M_MPR,
148991554f2SKenneth D. Merry M_ZERO|M_NOWAIT);
149991554f2SKenneth D. Merry if (!fw_event) {
150991554f2SKenneth D. Merry printf("%s: allocate failed for fw_event\n", __func__);
151991554f2SKenneth D. Merry return;
152991554f2SKenneth D. Merry }
153991554f2SKenneth D. Merry sz = le16toh(event->EventDataLength) * 4;
154991554f2SKenneth D. Merry fw_event->event_data = malloc(sz, M_MPR, M_ZERO|M_NOWAIT);
155991554f2SKenneth D. Merry if (!fw_event->event_data) {
156991554f2SKenneth D. Merry printf("%s: allocate failed for event_data\n", __func__);
157991554f2SKenneth D. Merry free(fw_event, M_MPR);
158991554f2SKenneth D. Merry return;
159991554f2SKenneth D. Merry }
160991554f2SKenneth D. Merry
161991554f2SKenneth D. Merry bcopy(event->EventData, fw_event->event_data, sz);
16271900a79SAlfredo Dal'Ava Junior fw_event->event = le16toh(event->Event);
16371900a79SAlfredo Dal'Ava Junior if ((fw_event->event == MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
16471900a79SAlfredo Dal'Ava Junior fw_event->event == MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
16571900a79SAlfredo Dal'Ava Junior fw_event->event == MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE ||
16671900a79SAlfredo Dal'Ava Junior fw_event->event == MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST) &&
167991554f2SKenneth D. Merry sc->track_mapping_events)
168991554f2SKenneth D. Merry sc->pending_map_events++;
169991554f2SKenneth D. Merry
170991554f2SKenneth D. Merry /*
171991554f2SKenneth D. Merry * When wait_for_port_enable flag is set, make sure that all the events
172991554f2SKenneth D. Merry * are processed. Increment the startup_refcount and decrement it after
173991554f2SKenneth D. Merry * events are processed.
174991554f2SKenneth D. Merry */
17571900a79SAlfredo Dal'Ava Junior if ((fw_event->event == MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
17671900a79SAlfredo Dal'Ava Junior fw_event->event == MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
17771900a79SAlfredo Dal'Ava Junior fw_event->event == MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST) &&
178991554f2SKenneth D. Merry sc->wait_for_port_enable)
179991554f2SKenneth D. Merry mprsas_startup_increment(sc->sassc);
180991554f2SKenneth D. Merry
181991554f2SKenneth D. Merry TAILQ_INSERT_TAIL(&sc->sassc->ev_queue, fw_event, ev_link);
182991554f2SKenneth D. Merry taskqueue_enqueue(sc->sassc->ev_tq, &sc->sassc->ev_task);
183991554f2SKenneth D. Merry }
184991554f2SKenneth D. Merry
185991554f2SKenneth D. Merry static void
mprsas_fw_event_free(struct mpr_softc * sc,struct mpr_fw_event_work * fw_event)186991554f2SKenneth D. Merry mprsas_fw_event_free(struct mpr_softc *sc, struct mpr_fw_event_work *fw_event)
187991554f2SKenneth D. Merry {
188991554f2SKenneth D. Merry
189991554f2SKenneth D. Merry free(fw_event->event_data, M_MPR);
190991554f2SKenneth D. Merry free(fw_event, M_MPR);
191991554f2SKenneth D. Merry }
192991554f2SKenneth D. Merry
193991554f2SKenneth D. Merry /**
194991554f2SKenneth D. Merry * _mpr_fw_work - delayed task for processing firmware events
195991554f2SKenneth D. Merry * @sc: per adapter object
196991554f2SKenneth D. Merry * @fw_event: The fw_event_work object
197991554f2SKenneth D. Merry * Context: user.
198991554f2SKenneth D. Merry *
199991554f2SKenneth D. Merry * Return nothing.
200991554f2SKenneth D. Merry */
201991554f2SKenneth D. Merry static void
mprsas_fw_work(struct mpr_softc * sc,struct mpr_fw_event_work * fw_event)202991554f2SKenneth D. Merry mprsas_fw_work(struct mpr_softc *sc, struct mpr_fw_event_work *fw_event)
203991554f2SKenneth D. Merry {
204991554f2SKenneth D. Merry struct mprsas_softc *sassc;
205991554f2SKenneth D. Merry sassc = sc->sassc;
206991554f2SKenneth D. Merry
207991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, "(%d)->(%s) Working on Event: [%x]\n",
208991554f2SKenneth D. Merry event_count++, __func__, fw_event->event);
209991554f2SKenneth D. Merry switch (fw_event->event) {
210991554f2SKenneth D. Merry case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
211991554f2SKenneth D. Merry {
212991554f2SKenneth D. Merry MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *data;
213991554f2SKenneth D. Merry MPI2_EVENT_SAS_TOPO_PHY_ENTRY *phy;
21467feec50SStephen McConnell uint8_t i;
215991554f2SKenneth D. Merry
216991554f2SKenneth D. Merry data = (MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST *)
217991554f2SKenneth D. Merry fw_event->event_data;
218991554f2SKenneth D. Merry
219991554f2SKenneth D. Merry mpr_mapping_topology_change_event(sc, fw_event->event_data);
220991554f2SKenneth D. Merry
221991554f2SKenneth D. Merry for (i = 0; i < data->NumEntries; i++) {
222991554f2SKenneth D. Merry phy = &data->PHY[i];
223991554f2SKenneth D. Merry switch (phy->PhyStatus & MPI2_EVENT_SAS_TOPO_RC_MASK) {
224991554f2SKenneth D. Merry case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
225991554f2SKenneth D. Merry if (mprsas_add_device(sc,
226991554f2SKenneth D. Merry le16toh(phy->AttachedDevHandle),
227991554f2SKenneth D. Merry phy->LinkRate)) {
228327f2e6cSStephen McConnell mpr_dprint(sc, MPR_ERROR, "%s: "
229327f2e6cSStephen McConnell "failed to add device with handle "
230327f2e6cSStephen McConnell "0x%x\n", __func__,
231991554f2SKenneth D. Merry le16toh(phy->AttachedDevHandle));
232991554f2SKenneth D. Merry mprsas_prepare_remove(sassc, le16toh(
233991554f2SKenneth D. Merry phy->AttachedDevHandle));
234991554f2SKenneth D. Merry }
235991554f2SKenneth D. Merry break;
236991554f2SKenneth D. Merry case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
237991554f2SKenneth D. Merry mprsas_prepare_remove(sassc, le16toh(
238991554f2SKenneth D. Merry phy->AttachedDevHandle));
239991554f2SKenneth D. Merry break;
240991554f2SKenneth D. Merry case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
241991554f2SKenneth D. Merry case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
242991554f2SKenneth D. Merry case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
243991554f2SKenneth D. Merry default:
244991554f2SKenneth D. Merry break;
245991554f2SKenneth D. Merry }
246991554f2SKenneth D. Merry }
247991554f2SKenneth D. Merry /*
248991554f2SKenneth D. Merry * refcount was incremented for this event in
249991554f2SKenneth D. Merry * mprsas_evt_handler. Decrement it here because the event has
250991554f2SKenneth D. Merry * been processed.
251991554f2SKenneth D. Merry */
252991554f2SKenneth D. Merry mprsas_startup_decrement(sassc);
253991554f2SKenneth D. Merry break;
254991554f2SKenneth D. Merry }
255991554f2SKenneth D. Merry case MPI2_EVENT_SAS_DISCOVERY:
256991554f2SKenneth D. Merry {
257991554f2SKenneth D. Merry MPI2_EVENT_DATA_SAS_DISCOVERY *data;
258991554f2SKenneth D. Merry
259991554f2SKenneth D. Merry data = (MPI2_EVENT_DATA_SAS_DISCOVERY *)fw_event->event_data;
260991554f2SKenneth D. Merry
261991554f2SKenneth D. Merry if (data->ReasonCode & MPI2_EVENT_SAS_DISC_RC_STARTED)
2627a2a6a1aSStephen McConnell mpr_dprint(sc, MPR_TRACE,"SAS discovery start event\n");
263991554f2SKenneth D. Merry if (data->ReasonCode & MPI2_EVENT_SAS_DISC_RC_COMPLETED) {
264991554f2SKenneth D. Merry mpr_dprint(sc, MPR_TRACE,"SAS discovery stop event\n");
265991554f2SKenneth D. Merry sassc->flags &= ~MPRSAS_IN_DISCOVERY;
266991554f2SKenneth D. Merry mprsas_discovery_end(sassc);
267991554f2SKenneth D. Merry }
268991554f2SKenneth D. Merry break;
269991554f2SKenneth D. Merry }
270991554f2SKenneth D. Merry case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
271991554f2SKenneth D. Merry {
272991554f2SKenneth D. Merry mpr_mapping_enclosure_dev_status_change_event(sc,
273991554f2SKenneth D. Merry fw_event->event_data);
274991554f2SKenneth D. Merry break;
275991554f2SKenneth D. Merry }
276991554f2SKenneth D. Merry case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
277991554f2SKenneth D. Merry {
278991554f2SKenneth D. Merry Mpi2EventIrConfigElement_t *element;
279991554f2SKenneth D. Merry int i;
280991554f2SKenneth D. Merry u8 foreign_config, reason;
281991554f2SKenneth D. Merry u16 elementType;
282991554f2SKenneth D. Merry Mpi2EventDataIrConfigChangeList_t *event_data;
283991554f2SKenneth D. Merry struct mprsas_target *targ;
284991554f2SKenneth D. Merry unsigned int id;
285991554f2SKenneth D. Merry
286991554f2SKenneth D. Merry event_data = fw_event->event_data;
287991554f2SKenneth D. Merry foreign_config = (le32toh(event_data->Flags) &
288991554f2SKenneth D. Merry MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
289991554f2SKenneth D. Merry
290991554f2SKenneth D. Merry element =
291991554f2SKenneth D. Merry (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
292327f2e6cSStephen McConnell id = mpr_mapping_get_raid_tid_from_handle(sc,
293991554f2SKenneth D. Merry element->VolDevHandle);
294991554f2SKenneth D. Merry
295991554f2SKenneth D. Merry mpr_mapping_ir_config_change_event(sc, event_data);
296991554f2SKenneth D. Merry for (i = 0; i < event_data->NumElements; i++, element++) {
297991554f2SKenneth D. Merry reason = element->ReasonCode;
298991554f2SKenneth D. Merry elementType = le16toh(element->ElementFlags) &
299991554f2SKenneth D. Merry MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
300991554f2SKenneth D. Merry /*
301991554f2SKenneth D. Merry * check for element type of Phys Disk or Hot Spare
302991554f2SKenneth D. Merry */
303991554f2SKenneth D. Merry if ((elementType !=
304991554f2SKenneth D. Merry MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT)
305991554f2SKenneth D. Merry && (elementType !=
306991554f2SKenneth D. Merry MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT))
307991554f2SKenneth D. Merry // do next element
308991554f2SKenneth D. Merry goto skip_fp_send;
309991554f2SKenneth D. Merry
310991554f2SKenneth D. Merry /*
311991554f2SKenneth D. Merry * check for reason of Hide, Unhide, PD Created, or PD
312991554f2SKenneth D. Merry * Deleted
313991554f2SKenneth D. Merry */
314991554f2SKenneth D. Merry if ((reason != MPI2_EVENT_IR_CHANGE_RC_HIDE) &&
315991554f2SKenneth D. Merry (reason != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) &&
316991554f2SKenneth D. Merry (reason != MPI2_EVENT_IR_CHANGE_RC_PD_CREATED) &&
317991554f2SKenneth D. Merry (reason != MPI2_EVENT_IR_CHANGE_RC_PD_DELETED))
318991554f2SKenneth D. Merry goto skip_fp_send;
319991554f2SKenneth D. Merry
320991554f2SKenneth D. Merry // check for a reason of Hide or PD Created
321991554f2SKenneth D. Merry if ((reason == MPI2_EVENT_IR_CHANGE_RC_HIDE) ||
322991554f2SKenneth D. Merry (reason == MPI2_EVENT_IR_CHANGE_RC_PD_CREATED))
323991554f2SKenneth D. Merry {
324991554f2SKenneth D. Merry // build RAID Action message
325991554f2SKenneth D. Merry Mpi2RaidActionRequest_t *action;
3266d4ffcb4SKenneth D. Merry Mpi2RaidActionReply_t *reply = NULL;
327991554f2SKenneth D. Merry struct mpr_command *cm;
328991554f2SKenneth D. Merry int error = 0;
329991554f2SKenneth D. Merry if ((cm = mpr_alloc_command(sc)) == NULL) {
330991554f2SKenneth D. Merry printf("%s: command alloc failed\n",
331991554f2SKenneth D. Merry __func__);
332991554f2SKenneth D. Merry return;
333991554f2SKenneth D. Merry }
334991554f2SKenneth D. Merry
335a2c14879SStephen McConnell mpr_dprint(sc, MPR_EVENT, "Sending FP action "
336991554f2SKenneth D. Merry "from "
337991554f2SKenneth D. Merry "MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST "
338991554f2SKenneth D. Merry ":\n");
339991554f2SKenneth D. Merry action = (MPI2_RAID_ACTION_REQUEST *)cm->cm_req;
340991554f2SKenneth D. Merry action->Function = MPI2_FUNCTION_RAID_ACTION;
341991554f2SKenneth D. Merry action->Action =
342991554f2SKenneth D. Merry MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
343991554f2SKenneth D. Merry action->PhysDiskNum = element->PhysDiskNum;
344991554f2SKenneth D. Merry cm->cm_desc.Default.RequestFlags =
345991554f2SKenneth D. Merry MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
3466d4ffcb4SKenneth D. Merry error = mpr_request_polled(sc, &cm);
3476d4ffcb4SKenneth D. Merry if (cm != NULL)
3486d4ffcb4SKenneth D. Merry reply = (Mpi2RaidActionReply_t *)
3496d4ffcb4SKenneth D. Merry cm->cm_reply;
350991554f2SKenneth D. Merry if (error || (reply == NULL)) {
351991554f2SKenneth D. Merry /* FIXME */
352991554f2SKenneth D. Merry /*
353991554f2SKenneth D. Merry * If the poll returns error then we
354991554f2SKenneth D. Merry * need to do diag reset
355991554f2SKenneth D. Merry */
356991554f2SKenneth D. Merry printf("%s: poll for page completed "
357*074bed4fSAlexander Motin "with error %d\n", __func__, error);
358991554f2SKenneth D. Merry }
359991554f2SKenneth D. Merry if (reply && (le16toh(reply->IOCStatus) &
360991554f2SKenneth D. Merry MPI2_IOCSTATUS_MASK) !=
361991554f2SKenneth D. Merry MPI2_IOCSTATUS_SUCCESS) {
362a2c14879SStephen McConnell mpr_dprint(sc, MPR_ERROR, "%s: error "
363a2c14879SStephen McConnell "sending RaidActionPage; "
364a2c14879SStephen McConnell "iocstatus = 0x%x\n", __func__,
365991554f2SKenneth D. Merry le16toh(reply->IOCStatus));
366991554f2SKenneth D. Merry }
367991554f2SKenneth D. Merry
368991554f2SKenneth D. Merry if (cm)
369991554f2SKenneth D. Merry mpr_free_command(sc, cm);
370991554f2SKenneth D. Merry }
371991554f2SKenneth D. Merry skip_fp_send:
372a2c14879SStephen McConnell mpr_dprint(sc, MPR_EVENT, "Received "
373991554f2SKenneth D. Merry "MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST Reason "
374991554f2SKenneth D. Merry "code %x:\n", element->ReasonCode);
375991554f2SKenneth D. Merry switch (element->ReasonCode) {
376991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
377991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_ADDED:
378991554f2SKenneth D. Merry if (!foreign_config) {
379991554f2SKenneth D. Merry if (mprsas_volume_add(sc,
380991554f2SKenneth D. Merry le16toh(element->VolDevHandle))) {
381991554f2SKenneth D. Merry printf("%s: failed to add RAID "
382991554f2SKenneth D. Merry "volume with handle 0x%x\n",
383991554f2SKenneth D. Merry __func__, le16toh(element->
384991554f2SKenneth D. Merry VolDevHandle));
385991554f2SKenneth D. Merry }
386991554f2SKenneth D. Merry }
387991554f2SKenneth D. Merry break;
388991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
389991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
390991554f2SKenneth D. Merry /*
391991554f2SKenneth D. Merry * Rescan after volume is deleted or removed.
392991554f2SKenneth D. Merry */
393991554f2SKenneth D. Merry if (!foreign_config) {
394991554f2SKenneth D. Merry if (id == MPR_MAP_BAD_ID) {
395991554f2SKenneth D. Merry printf("%s: could not get ID "
396991554f2SKenneth D. Merry "for volume with handle "
397991554f2SKenneth D. Merry "0x%04x\n", __func__,
398991554f2SKenneth D. Merry le16toh(element->
399991554f2SKenneth D. Merry VolDevHandle));
400991554f2SKenneth D. Merry break;
401991554f2SKenneth D. Merry }
402991554f2SKenneth D. Merry
403991554f2SKenneth D. Merry targ = &sassc->targets[id];
404991554f2SKenneth D. Merry targ->handle = 0x0;
405991554f2SKenneth D. Merry targ->encl_slot = 0x0;
406991554f2SKenneth D. Merry targ->encl_handle = 0x0;
407991554f2SKenneth D. Merry targ->encl_level_valid = 0x0;
408991554f2SKenneth D. Merry targ->encl_level = 0x0;
409991554f2SKenneth D. Merry targ->connector_name[0] = ' ';
410991554f2SKenneth D. Merry targ->connector_name[1] = ' ';
411991554f2SKenneth D. Merry targ->connector_name[2] = ' ';
412991554f2SKenneth D. Merry targ->connector_name[3] = ' ';
413991554f2SKenneth D. Merry targ->exp_dev_handle = 0x0;
414991554f2SKenneth D. Merry targ->phy_num = 0x0;
415991554f2SKenneth D. Merry targ->linkrate = 0x0;
416991554f2SKenneth D. Merry mprsas_rescan_target(sc, targ);
417991554f2SKenneth D. Merry printf("RAID target id 0x%x removed\n",
418991554f2SKenneth D. Merry targ->tid);
419991554f2SKenneth D. Merry }
420991554f2SKenneth D. Merry break;
421991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
422991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_HIDE:
423991554f2SKenneth D. Merry /*
424991554f2SKenneth D. Merry * Phys Disk of a volume has been created. Hide
425991554f2SKenneth D. Merry * it from the OS.
426991554f2SKenneth D. Merry */
427991554f2SKenneth D. Merry targ = mprsas_find_target_by_handle(sassc, 0,
428991554f2SKenneth D. Merry element->PhysDiskDevHandle);
429991554f2SKenneth D. Merry if (targ == NULL)
430991554f2SKenneth D. Merry break;
431991554f2SKenneth D. Merry targ->flags |= MPR_TARGET_FLAGS_RAID_COMPONENT;
432991554f2SKenneth D. Merry mprsas_rescan_target(sc, targ);
433991554f2SKenneth D. Merry break;
434991554f2SKenneth D. Merry case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
435991554f2SKenneth D. Merry /*
436991554f2SKenneth D. Merry * Phys Disk of a volume has been deleted.
437991554f2SKenneth D. Merry * Expose it to the OS.
438991554f2SKenneth D. Merry */
439991554f2SKenneth D. Merry if (mprsas_add_device(sc,
440991554f2SKenneth D. Merry le16toh(element->PhysDiskDevHandle), 0)) {
441991554f2SKenneth D. Merry printf("%s: failed to add device with "
442991554f2SKenneth D. Merry "handle 0x%x\n", __func__,
443991554f2SKenneth D. Merry le16toh(element->
444991554f2SKenneth D. Merry PhysDiskDevHandle));
445991554f2SKenneth D. Merry mprsas_prepare_remove(sassc,
446991554f2SKenneth D. Merry le16toh(element->
447991554f2SKenneth D. Merry PhysDiskDevHandle));
448991554f2SKenneth D. Merry }
449991554f2SKenneth D. Merry break;
450991554f2SKenneth D. Merry }
451991554f2SKenneth D. Merry }
452991554f2SKenneth D. Merry /*
453991554f2SKenneth D. Merry * refcount was incremented for this event in
454991554f2SKenneth D. Merry * mprsas_evt_handler. Decrement it here because the event has
455991554f2SKenneth D. Merry * been processed.
456991554f2SKenneth D. Merry */
457991554f2SKenneth D. Merry mprsas_startup_decrement(sassc);
458991554f2SKenneth D. Merry break;
459991554f2SKenneth D. Merry }
460991554f2SKenneth D. Merry case MPI2_EVENT_IR_VOLUME:
461991554f2SKenneth D. Merry {
462991554f2SKenneth D. Merry Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
463991554f2SKenneth D. Merry
464991554f2SKenneth D. Merry /*
465991554f2SKenneth D. Merry * Informational only.
466991554f2SKenneth D. Merry */
467991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, "Received IR Volume event:\n");
468991554f2SKenneth D. Merry switch (event_data->ReasonCode) {
469991554f2SKenneth D. Merry case MPI2_EVENT_IR_VOLUME_RC_SETTINGS_CHANGED:
470991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " Volume Settings "
471991554f2SKenneth D. Merry "changed from 0x%x to 0x%x for Volome with "
472991554f2SKenneth D. Merry "handle 0x%x", le32toh(event_data->PreviousValue),
473991554f2SKenneth D. Merry le32toh(event_data->NewValue),
474991554f2SKenneth D. Merry le16toh(event_data->VolDevHandle));
475991554f2SKenneth D. Merry break;
476991554f2SKenneth D. Merry case MPI2_EVENT_IR_VOLUME_RC_STATUS_FLAGS_CHANGED:
477991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " Volume Status "
478991554f2SKenneth D. Merry "changed from 0x%x to 0x%x for Volome with "
479991554f2SKenneth D. Merry "handle 0x%x", le32toh(event_data->PreviousValue),
480991554f2SKenneth D. Merry le32toh(event_data->NewValue),
481991554f2SKenneth D. Merry le16toh(event_data->VolDevHandle));
482991554f2SKenneth D. Merry break;
483991554f2SKenneth D. Merry case MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED:
484991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " Volume State "
485991554f2SKenneth D. Merry "changed from 0x%x to 0x%x for Volome with "
486991554f2SKenneth D. Merry "handle 0x%x", le32toh(event_data->PreviousValue),
487991554f2SKenneth D. Merry le32toh(event_data->NewValue),
488991554f2SKenneth D. Merry le16toh(event_data->VolDevHandle));
489991554f2SKenneth D. Merry u32 state;
490991554f2SKenneth D. Merry struct mprsas_target *targ;
491991554f2SKenneth D. Merry state = le32toh(event_data->NewValue);
492991554f2SKenneth D. Merry switch (state) {
493991554f2SKenneth D. Merry case MPI2_RAID_VOL_STATE_MISSING:
494991554f2SKenneth D. Merry case MPI2_RAID_VOL_STATE_FAILED:
495991554f2SKenneth D. Merry mprsas_prepare_volume_remove(sassc,
496991554f2SKenneth D. Merry event_data->VolDevHandle);
497991554f2SKenneth D. Merry break;
498991554f2SKenneth D. Merry
499991554f2SKenneth D. Merry case MPI2_RAID_VOL_STATE_ONLINE:
500991554f2SKenneth D. Merry case MPI2_RAID_VOL_STATE_DEGRADED:
501991554f2SKenneth D. Merry case MPI2_RAID_VOL_STATE_OPTIMAL:
502991554f2SKenneth D. Merry targ =
503991554f2SKenneth D. Merry mprsas_find_target_by_handle(sassc,
504991554f2SKenneth D. Merry 0, event_data->VolDevHandle);
505991554f2SKenneth D. Merry if (targ) {
506991554f2SKenneth D. Merry printf("%s %d: Volume handle "
507991554f2SKenneth D. Merry "0x%x is already added \n",
508991554f2SKenneth D. Merry __func__, __LINE__,
509991554f2SKenneth D. Merry event_data->VolDevHandle);
510991554f2SKenneth D. Merry break;
511991554f2SKenneth D. Merry }
512991554f2SKenneth D. Merry if (mprsas_volume_add(sc,
513991554f2SKenneth D. Merry le16toh(event_data->
514991554f2SKenneth D. Merry VolDevHandle))) {
515991554f2SKenneth D. Merry printf("%s: failed to add RAID "
516991554f2SKenneth D. Merry "volume with handle 0x%x\n",
517991554f2SKenneth D. Merry __func__, le16toh(
518991554f2SKenneth D. Merry event_data->VolDevHandle));
519991554f2SKenneth D. Merry }
520991554f2SKenneth D. Merry break;
521991554f2SKenneth D. Merry default:
522991554f2SKenneth D. Merry break;
523991554f2SKenneth D. Merry }
524991554f2SKenneth D. Merry break;
525991554f2SKenneth D. Merry default:
526991554f2SKenneth D. Merry break;
527991554f2SKenneth D. Merry }
528991554f2SKenneth D. Merry break;
529991554f2SKenneth D. Merry }
530991554f2SKenneth D. Merry case MPI2_EVENT_IR_PHYSICAL_DISK:
531991554f2SKenneth D. Merry {
532991554f2SKenneth D. Merry Mpi2EventDataIrPhysicalDisk_t *event_data =
533991554f2SKenneth D. Merry fw_event->event_data;
534991554f2SKenneth D. Merry struct mprsas_target *targ;
535991554f2SKenneth D. Merry
536991554f2SKenneth D. Merry /*
537991554f2SKenneth D. Merry * Informational only.
538991554f2SKenneth D. Merry */
539991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, "Received IR Phys Disk event:\n");
540991554f2SKenneth D. Merry switch (event_data->ReasonCode) {
541991554f2SKenneth D. Merry case MPI2_EVENT_IR_PHYSDISK_RC_SETTINGS_CHANGED:
542991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " Phys Disk Settings "
543991554f2SKenneth D. Merry "changed from 0x%x to 0x%x for Phys Disk Number "
544991554f2SKenneth D. Merry "%d and handle 0x%x at Enclosure handle 0x%x, Slot "
545991554f2SKenneth D. Merry "%d", le32toh(event_data->PreviousValue),
546991554f2SKenneth D. Merry le32toh(event_data->NewValue),
547991554f2SKenneth D. Merry event_data->PhysDiskNum,
548991554f2SKenneth D. Merry le16toh(event_data->PhysDiskDevHandle),
549991554f2SKenneth D. Merry le16toh(event_data->EnclosureHandle),
550991554f2SKenneth D. Merry le16toh(event_data->Slot));
551991554f2SKenneth D. Merry break;
552991554f2SKenneth D. Merry case MPI2_EVENT_IR_PHYSDISK_RC_STATUS_FLAGS_CHANGED:
553991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " Phys Disk Status changed "
554991554f2SKenneth D. Merry "from 0x%x to 0x%x for Phys Disk Number %d and "
555991554f2SKenneth D. Merry "handle 0x%x at Enclosure handle 0x%x, Slot %d",
556991554f2SKenneth D. Merry le32toh(event_data->PreviousValue),
557991554f2SKenneth D. Merry le32toh(event_data->NewValue),
558991554f2SKenneth D. Merry event_data->PhysDiskNum,
559991554f2SKenneth D. Merry le16toh(event_data->PhysDiskDevHandle),
560991554f2SKenneth D. Merry le16toh(event_data->EnclosureHandle),
561991554f2SKenneth D. Merry le16toh(event_data->Slot));
562991554f2SKenneth D. Merry break;
563991554f2SKenneth D. Merry case MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED:
564991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " Phys Disk State changed "
565991554f2SKenneth D. Merry "from 0x%x to 0x%x for Phys Disk Number %d and "
566991554f2SKenneth D. Merry "handle 0x%x at Enclosure handle 0x%x, Slot %d",
567991554f2SKenneth D. Merry le32toh(event_data->PreviousValue),
568991554f2SKenneth D. Merry le32toh(event_data->NewValue),
569991554f2SKenneth D. Merry event_data->PhysDiskNum,
570991554f2SKenneth D. Merry le16toh(event_data->PhysDiskDevHandle),
571991554f2SKenneth D. Merry le16toh(event_data->EnclosureHandle),
572991554f2SKenneth D. Merry le16toh(event_data->Slot));
573991554f2SKenneth D. Merry switch (event_data->NewValue) {
574991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_ONLINE:
575991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_DEGRADED:
576991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_REBUILDING:
577991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_OPTIMAL:
578991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_HOT_SPARE:
579991554f2SKenneth D. Merry targ = mprsas_find_target_by_handle(
580991554f2SKenneth D. Merry sassc, 0,
581991554f2SKenneth D. Merry event_data->PhysDiskDevHandle);
582991554f2SKenneth D. Merry if (targ) {
583991554f2SKenneth D. Merry targ->flags |=
584991554f2SKenneth D. Merry MPR_TARGET_FLAGS_RAID_COMPONENT;
585991554f2SKenneth D. Merry printf("%s %d: Found Target "
586991554f2SKenneth D. Merry "for handle 0x%x.\n",
587991554f2SKenneth D. Merry __func__, __LINE__ ,
588991554f2SKenneth D. Merry event_data->
589991554f2SKenneth D. Merry PhysDiskDevHandle);
590991554f2SKenneth D. Merry }
591991554f2SKenneth D. Merry break;
592991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_OFFLINE:
593991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
594991554f2SKenneth D. Merry case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
595991554f2SKenneth D. Merry default:
596991554f2SKenneth D. Merry targ = mprsas_find_target_by_handle(
597991554f2SKenneth D. Merry sassc, 0,
598991554f2SKenneth D. Merry event_data->PhysDiskDevHandle);
599991554f2SKenneth D. Merry if (targ) {
600991554f2SKenneth D. Merry targ->flags |=
601991554f2SKenneth D. Merry ~MPR_TARGET_FLAGS_RAID_COMPONENT;
602991554f2SKenneth D. Merry printf("%s %d: Found Target "
603991554f2SKenneth D. Merry "for handle 0x%x. \n",
604991554f2SKenneth D. Merry __func__, __LINE__ ,
605991554f2SKenneth D. Merry event_data->
606991554f2SKenneth D. Merry PhysDiskDevHandle);
607991554f2SKenneth D. Merry }
608991554f2SKenneth D. Merry break;
609991554f2SKenneth D. Merry }
610991554f2SKenneth D. Merry default:
611991554f2SKenneth D. Merry break;
612991554f2SKenneth D. Merry }
613991554f2SKenneth D. Merry break;
614991554f2SKenneth D. Merry }
615991554f2SKenneth D. Merry case MPI2_EVENT_IR_OPERATION_STATUS:
616991554f2SKenneth D. Merry {
617991554f2SKenneth D. Merry Mpi2EventDataIrOperationStatus_t *event_data =
618991554f2SKenneth D. Merry fw_event->event_data;
619991554f2SKenneth D. Merry
620991554f2SKenneth D. Merry /*
621991554f2SKenneth D. Merry * Informational only.
622991554f2SKenneth D. Merry */
623991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, "Received IR Op Status event:\n");
624991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, " RAID Operation of %d is %d "
625991554f2SKenneth D. Merry "percent complete for Volume with handle 0x%x",
626991554f2SKenneth D. Merry event_data->RAIDOperation, event_data->PercentComplete,
627991554f2SKenneth D. Merry le16toh(event_data->VolDevHandle));
628991554f2SKenneth D. Merry break;
629991554f2SKenneth D. Merry }
630991554f2SKenneth D. Merry case MPI2_EVENT_TEMP_THRESHOLD:
631991554f2SKenneth D. Merry {
632991554f2SKenneth D. Merry pMpi2EventDataTemperature_t temp_event;
633991554f2SKenneth D. Merry
634991554f2SKenneth D. Merry temp_event = (pMpi2EventDataTemperature_t)fw_event->event_data;
635991554f2SKenneth D. Merry
636991554f2SKenneth D. Merry /*
637991554f2SKenneth D. Merry * The Temp Sensor Count must be greater than the event's Sensor
638991554f2SKenneth D. Merry * Num to be valid. If valid, print the temp thresholds that
639991554f2SKenneth D. Merry * have been exceeded.
640991554f2SKenneth D. Merry */
641991554f2SKenneth D. Merry if (sc->iounit_pg8.NumSensors > temp_event->SensorNum) {
642991554f2SKenneth D. Merry mpr_dprint(sc, MPR_FAULT, "Temperature Threshold flags "
643991554f2SKenneth D. Merry "%s %s %s %s exceeded for Sensor: %d !!!\n",
644991554f2SKenneth D. Merry ((temp_event->Status & 0x01) == 1) ? "0 " : " ",
645991554f2SKenneth D. Merry ((temp_event->Status & 0x02) == 2) ? "1 " : " ",
646991554f2SKenneth D. Merry ((temp_event->Status & 0x04) == 4) ? "2 " : " ",
647991554f2SKenneth D. Merry ((temp_event->Status & 0x08) == 8) ? "3 " : " ",
648991554f2SKenneth D. Merry temp_event->SensorNum);
649991554f2SKenneth D. Merry mpr_dprint(sc, MPR_FAULT, "Current Temp in Celsius: "
650991554f2SKenneth D. Merry "%d\n", temp_event->CurrentTemperature);
651991554f2SKenneth D. Merry }
652991554f2SKenneth D. Merry break;
653991554f2SKenneth D. Merry }
6542bbc5fcbSStephen McConnell case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
6552bbc5fcbSStephen McConnell {
6562bbc5fcbSStephen McConnell pMpi26EventDataActiveCableExcept_t ace_event_data;
6572bbc5fcbSStephen McConnell ace_event_data =
6582bbc5fcbSStephen McConnell (pMpi26EventDataActiveCableExcept_t)fw_event->event_data;
6592bbc5fcbSStephen McConnell
6600656476aSAlexander Motin switch(ace_event_data->ReasonCode) {
6610656476aSAlexander Motin case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
6620656476aSAlexander Motin {
6630656476aSAlexander Motin mpr_printf(sc, "Currently a cable with "
6642bbc5fcbSStephen McConnell "ReceptacleID %d cannot be powered and device "
6652bbc5fcbSStephen McConnell "connected to this active cable will not be seen. "
6662bbc5fcbSStephen McConnell "This active cable requires %d mW of power.\n",
6672bbc5fcbSStephen McConnell ace_event_data->ReceptacleID,
6682bbc5fcbSStephen McConnell ace_event_data->ActiveCablePowerRequirement);
6690656476aSAlexander Motin break;
6700656476aSAlexander Motin }
6710656476aSAlexander Motin case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
6720656476aSAlexander Motin {
6730656476aSAlexander Motin mpr_printf(sc, "Currently a cable with "
6740656476aSAlexander Motin "ReceptacleID %d is not running at optimal speed "
6750656476aSAlexander Motin "(12 Gb/s rate)\n", ace_event_data->ReceptacleID);
6760656476aSAlexander Motin break;
6770656476aSAlexander Motin }
6780656476aSAlexander Motin default:
6790656476aSAlexander Motin break;
6802bbc5fcbSStephen McConnell }
6812bbc5fcbSStephen McConnell break;
6822bbc5fcbSStephen McConnell }
68389d1c21fSKashyap D Desai case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
68489d1c21fSKashyap D Desai {
68589d1c21fSKashyap D Desai pMpi26EventDataPCIeDeviceStatusChange_t pcie_status_event_data;
68689d1c21fSKashyap D Desai pcie_status_event_data =
68789d1c21fSKashyap D Desai (pMpi26EventDataPCIeDeviceStatusChange_t)fw_event->event_data;
68889d1c21fSKashyap D Desai
68989d1c21fSKashyap D Desai switch (pcie_status_event_data->ReasonCode) {
69089d1c21fSKashyap D Desai case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED:
69189d1c21fSKashyap D Desai {
69289d1c21fSKashyap D Desai mpr_printf(sc, "PCIe Host Reset failed on DevHandle "
69389d1c21fSKashyap D Desai "0x%x\n", pcie_status_event_data->DevHandle);
69489d1c21fSKashyap D Desai break;
69589d1c21fSKashyap D Desai }
69689d1c21fSKashyap D Desai default:
69789d1c21fSKashyap D Desai break;
69889d1c21fSKashyap D Desai }
69989d1c21fSKashyap D Desai break;
70089d1c21fSKashyap D Desai }
7015f5baf0eSAlexander Motin case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
7025f5baf0eSAlexander Motin {
7035f5baf0eSAlexander Motin pMpi25EventDataSasDeviceDiscoveryError_t discovery_error_data;
7045f5baf0eSAlexander Motin uint64_t sas_address;
7055f5baf0eSAlexander Motin
7065f5baf0eSAlexander Motin discovery_error_data =
7075f5baf0eSAlexander Motin (pMpi25EventDataSasDeviceDiscoveryError_t)
7085f5baf0eSAlexander Motin fw_event->event_data;
7095f5baf0eSAlexander Motin
7105f5baf0eSAlexander Motin sas_address = discovery_error_data->SASAddress.High;
7115f5baf0eSAlexander Motin sas_address = (sas_address << 32) |
7125f5baf0eSAlexander Motin discovery_error_data->SASAddress.Low;
7135f5baf0eSAlexander Motin
7145f5baf0eSAlexander Motin switch(discovery_error_data->ReasonCode) {
7155f5baf0eSAlexander Motin case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED:
7165f5baf0eSAlexander Motin {
7175f5baf0eSAlexander Motin mpr_printf(sc, "SMP command failed during discovery "
7185f5baf0eSAlexander Motin "for expander with SAS Address %jx and "
7195f5baf0eSAlexander Motin "handle 0x%x.\n", sas_address,
7205f5baf0eSAlexander Motin discovery_error_data->DevHandle);
7215f5baf0eSAlexander Motin break;
7225f5baf0eSAlexander Motin }
7235f5baf0eSAlexander Motin case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT:
7245f5baf0eSAlexander Motin {
7255f5baf0eSAlexander Motin mpr_printf(sc, "SMP command timed out during "
7265f5baf0eSAlexander Motin "discovery for expander with SAS Address %jx and "
7275f5baf0eSAlexander Motin "handle 0x%x.\n", sas_address,
7285f5baf0eSAlexander Motin discovery_error_data->DevHandle);
7295f5baf0eSAlexander Motin break;
7305f5baf0eSAlexander Motin }
7315f5baf0eSAlexander Motin default:
7325f5baf0eSAlexander Motin break;
7335f5baf0eSAlexander Motin }
7345f5baf0eSAlexander Motin break;
7355f5baf0eSAlexander Motin }
73667feec50SStephen McConnell case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
73767feec50SStephen McConnell {
73867feec50SStephen McConnell MPI26_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST *data;
73967feec50SStephen McConnell MPI26_EVENT_PCIE_TOPO_PORT_ENTRY *port_entry;
74067feec50SStephen McConnell uint8_t i, link_rate;
74167feec50SStephen McConnell uint16_t handle;
74267feec50SStephen McConnell
74367feec50SStephen McConnell data = (MPI26_EVENT_DATA_PCIE_TOPOLOGY_CHANGE_LIST *)
74467feec50SStephen McConnell fw_event->event_data;
74567feec50SStephen McConnell
74667feec50SStephen McConnell mpr_mapping_pcie_topology_change_event(sc,
74767feec50SStephen McConnell fw_event->event_data);
74867feec50SStephen McConnell
74967feec50SStephen McConnell for (i = 0; i < data->NumEntries; i++) {
75067feec50SStephen McConnell port_entry = &data->PortEntry[i];
75167feec50SStephen McConnell handle = le16toh(port_entry->AttachedDevHandle);
75267feec50SStephen McConnell link_rate = port_entry->CurrentPortInfo &
75367feec50SStephen McConnell MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
75467feec50SStephen McConnell switch (port_entry->PortStatus) {
75567feec50SStephen McConnell case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
75667feec50SStephen McConnell if (link_rate <
75767feec50SStephen McConnell MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) {
75867feec50SStephen McConnell mpr_dprint(sc, MPR_ERROR, "%s: Cannot "
75967feec50SStephen McConnell "add PCIe device with handle 0x%x "
76067feec50SStephen McConnell "with unknown link rate.\n",
76167feec50SStephen McConnell __func__, handle);
76267feec50SStephen McConnell break;
76367feec50SStephen McConnell }
76467feec50SStephen McConnell if (mprsas_add_pcie_device(sc, handle,
76567feec50SStephen McConnell link_rate)) {
76667feec50SStephen McConnell mpr_dprint(sc, MPR_ERROR, "%s: failed "
76767feec50SStephen McConnell "to add PCIe device with handle "
76867feec50SStephen McConnell "0x%x\n", __func__, handle);
76967feec50SStephen McConnell mprsas_prepare_remove(sassc, handle);
77067feec50SStephen McConnell }
77167feec50SStephen McConnell break;
77267feec50SStephen McConnell case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
77367feec50SStephen McConnell mprsas_prepare_remove(sassc, handle);
77467feec50SStephen McConnell break;
77567feec50SStephen McConnell case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
77667feec50SStephen McConnell case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE:
77767feec50SStephen McConnell case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
77867feec50SStephen McConnell default:
77967feec50SStephen McConnell break;
78067feec50SStephen McConnell }
78167feec50SStephen McConnell }
78267feec50SStephen McConnell /*
78367feec50SStephen McConnell * refcount was incremented for this event in
78467feec50SStephen McConnell * mprsas_evt_handler. Decrement it here because the event has
78567feec50SStephen McConnell * been processed.
78667feec50SStephen McConnell */
78767feec50SStephen McConnell mprsas_startup_decrement(sassc);
78867feec50SStephen McConnell break;
78967feec50SStephen McConnell }
790991554f2SKenneth D. Merry case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
791991554f2SKenneth D. Merry case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
792991554f2SKenneth D. Merry default:
793991554f2SKenneth D. Merry mpr_dprint(sc, MPR_TRACE,"Unhandled event 0x%0X\n",
794991554f2SKenneth D. Merry fw_event->event);
795991554f2SKenneth D. Merry break;
796991554f2SKenneth D. Merry }
797991554f2SKenneth D. Merry mpr_dprint(sc, MPR_EVENT, "(%d)->(%s) Event Free: [%x]\n", event_count,
798991554f2SKenneth D. Merry __func__, fw_event->event);
799991554f2SKenneth D. Merry mprsas_fw_event_free(sc, fw_event);
800991554f2SKenneth D. Merry }
801991554f2SKenneth D. Merry
802991554f2SKenneth D. Merry void
mprsas_firmware_event_work(void * arg,int pending)803991554f2SKenneth D. Merry mprsas_firmware_event_work(void *arg, int pending)
804991554f2SKenneth D. Merry {
805991554f2SKenneth D. Merry struct mpr_fw_event_work *fw_event;
806991554f2SKenneth D. Merry struct mpr_softc *sc;
807991554f2SKenneth D. Merry
808991554f2SKenneth D. Merry sc = (struct mpr_softc *)arg;
809991554f2SKenneth D. Merry mpr_lock(sc);
810991554f2SKenneth D. Merry while ((fw_event = TAILQ_FIRST(&sc->sassc->ev_queue)) != NULL) {
811991554f2SKenneth D. Merry TAILQ_REMOVE(&sc->sassc->ev_queue, fw_event, ev_link);
812991554f2SKenneth D. Merry mprsas_fw_work(sc, fw_event);
813991554f2SKenneth D. Merry }
814991554f2SKenneth D. Merry mpr_unlock(sc);
815991554f2SKenneth D. Merry }
816991554f2SKenneth D. Merry
817991554f2SKenneth D. Merry static int
mprsas_add_device(struct mpr_softc * sc,u16 handle,u8 linkrate)81867feec50SStephen McConnell mprsas_add_device(struct mpr_softc *sc, u16 handle, u8 linkrate)
81967feec50SStephen McConnell {
820991554f2SKenneth D. Merry char devstring[80];
821991554f2SKenneth D. Merry struct mprsas_softc *sassc;
822991554f2SKenneth D. Merry struct mprsas_target *targ;
823991554f2SKenneth D. Merry Mpi2ConfigReply_t mpi_reply;
824991554f2SKenneth D. Merry Mpi2SasDevicePage0_t config_page;
825a2c14879SStephen McConnell uint64_t sas_address, parent_sas_address = 0;
826991554f2SKenneth D. Merry u32 device_info, parent_devinfo = 0;
827991554f2SKenneth D. Merry unsigned int id;
828a2c14879SStephen McConnell int ret = 1, error = 0, i;
829991554f2SKenneth D. Merry struct mprsas_lun *lun;
830a2c14879SStephen McConnell u8 is_SATA_SSD = 0;
831a2c14879SStephen McConnell struct mpr_command *cm;
832991554f2SKenneth D. Merry
833991554f2SKenneth D. Merry sassc = sc->sassc;
834991554f2SKenneth D. Merry mprsas_startup_increment(sassc);
835aeb9ac0dSScott Long if (mpr_config_get_sas_device_pg0(sc, &mpi_reply, &config_page,
836aeb9ac0dSScott Long MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle) != 0) {
837aeb9ac0dSScott Long mpr_dprint(sc, MPR_INFO|MPR_MAPPING|MPR_FAULT,
838aeb9ac0dSScott Long "Error reading SAS device %#x page0, iocstatus= 0x%x\n",
839aeb9ac0dSScott Long handle, mpi_reply.IOCStatus);
840991554f2SKenneth D. Merry error = ENXIO;
841991554f2SKenneth D. Merry goto out;
842991554f2SKenneth D. Merry }
843991554f2SKenneth D. Merry
844991554f2SKenneth D. Merry device_info = le32toh(config_page.DeviceInfo);
845991554f2SKenneth D. Merry
846991554f2SKenneth D. Merry if (((device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET) == 0)
847991554f2SKenneth D. Merry && (le16toh(config_page.ParentDevHandle) != 0)) {
848991554f2SKenneth D. Merry Mpi2ConfigReply_t tmp_mpi_reply;
849991554f2SKenneth D. Merry Mpi2SasDevicePage0_t parent_config_page;
850991554f2SKenneth D. Merry
851aeb9ac0dSScott Long if (mpr_config_get_sas_device_pg0(sc, &tmp_mpi_reply,
852991554f2SKenneth D. Merry &parent_config_page, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
853aeb9ac0dSScott Long le16toh(config_page.ParentDevHandle)) != 0) {
854757ff642SScott Long mpr_dprint(sc, MPR_MAPPING|MPR_FAULT,
855aeb9ac0dSScott Long "Error reading parent SAS device %#x page0, "
856aeb9ac0dSScott Long "iocstatus= 0x%x\n",
857aeb9ac0dSScott Long le16toh(config_page.ParentDevHandle),
858aeb9ac0dSScott Long tmp_mpi_reply.IOCStatus);
859991554f2SKenneth D. Merry } else {
860991554f2SKenneth D. Merry parent_sas_address = parent_config_page.SASAddress.High;
861991554f2SKenneth D. Merry parent_sas_address = (parent_sas_address << 32) |
862991554f2SKenneth D. Merry parent_config_page.SASAddress.Low;
863991554f2SKenneth D. Merry parent_devinfo = le32toh(parent_config_page.DeviceInfo);
864991554f2SKenneth D. Merry }
865991554f2SKenneth D. Merry }
86671900a79SAlfredo Dal'Ava Junior sas_address = htole32(config_page.SASAddress.High);
86771900a79SAlfredo Dal'Ava Junior sas_address = (sas_address << 32) | htole32(config_page.SASAddress.Low);
868757ff642SScott Long mpr_dprint(sc, MPR_MAPPING, "Handle 0x%04x SAS Address from SAS device "
869757ff642SScott Long "page0 = %jx\n", handle, sas_address);
870991554f2SKenneth D. Merry
871a2c14879SStephen McConnell /*
872a2c14879SStephen McConnell * Always get SATA Identify information because this is used to
873a2c14879SStephen McConnell * determine if Start/Stop Unit should be sent to the drive when the
874a2c14879SStephen McConnell * system is shutdown.
875a2c14879SStephen McConnell */
876991554f2SKenneth D. Merry if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) {
877a2c14879SStephen McConnell ret = mprsas_get_sas_address_for_sata_disk(sc, &sas_address,
878a2c14879SStephen McConnell handle, device_info, &is_SATA_SSD);
879a2c14879SStephen McConnell if (ret) {
880757ff642SScott Long mpr_dprint(sc, MPR_MAPPING|MPR_ERROR,
881757ff642SScott Long "%s: failed to get disk type (SSD or HDD) for SATA "
882757ff642SScott Long "device with handle 0x%04x\n",
883a2c14879SStephen McConnell __func__, handle);
884a2c14879SStephen McConnell } else {
885757ff642SScott Long mpr_dprint(sc, MPR_MAPPING, "Handle 0x%04x SAS Address "
886757ff642SScott Long "from SATA device = %jx\n", handle, sas_address);
887a2c14879SStephen McConnell }
888a2c14879SStephen McConnell }
889c91d307fSStephen McConnell
8904ab1cdc5SScott Long /*
8914ab1cdc5SScott Long * use_phynum:
8924ab1cdc5SScott Long * 1 - use the PhyNum field as a fallback to the mapping logic
8934ab1cdc5SScott Long * 0 - never use the PhyNum field
8944ab1cdc5SScott Long * -1 - only use the PhyNum field
895327f2e6cSStephen McConnell *
896327f2e6cSStephen McConnell * Note that using the Phy number to map a device can cause device adds
897327f2e6cSStephen McConnell * to fail if multiple enclosures/expanders are in the topology. For
898327f2e6cSStephen McConnell * example, if two devices are in the same slot number in two different
899327f2e6cSStephen McConnell * enclosures within the topology, only one of those devices will be
900327f2e6cSStephen McConnell * added. PhyNum mapping should not be used if multiple enclosures are
901327f2e6cSStephen McConnell * in the topology.
9024ab1cdc5SScott Long */
9034ab1cdc5SScott Long id = MPR_MAP_BAD_ID;
9044ab1cdc5SScott Long if (sc->use_phynum != -1)
905327f2e6cSStephen McConnell id = mpr_mapping_get_tid(sc, sas_address, handle);
906991554f2SKenneth D. Merry if (id == MPR_MAP_BAD_ID) {
90767feec50SStephen McConnell if ((sc->use_phynum == 0) ||
90867feec50SStephen McConnell ((id = config_page.PhyNum) > sassc->maxtargets)) {
9094ab1cdc5SScott Long mpr_dprint(sc, MPR_INFO, "failure at %s:%d/%s()! "
9104ab1cdc5SScott Long "Could not get ID for device with handle 0x%04x\n",
9114ab1cdc5SScott Long __FILE__, __LINE__, __func__, handle);
912991554f2SKenneth D. Merry error = ENXIO;
913991554f2SKenneth D. Merry goto out;
914991554f2SKenneth D. Merry }
9154ab1cdc5SScott Long }
916327f2e6cSStephen McConnell mpr_dprint(sc, MPR_MAPPING, "%s: Target ID for added device is %d.\n",
917327f2e6cSStephen McConnell __func__, id);
918991554f2SKenneth D. Merry
919327f2e6cSStephen McConnell /*
920327f2e6cSStephen McConnell * Only do the ID check and reuse check if the target is not from a
921327f2e6cSStephen McConnell * RAID Component. For Physical Disks of a Volume, the ID will be reused
922327f2e6cSStephen McConnell * when a volume is deleted because the mapping entry for the PD will
923327f2e6cSStephen McConnell * still be in the mapping table. The ID check should not be done here
924327f2e6cSStephen McConnell * either since this PD is already being used.
925327f2e6cSStephen McConnell */
926327f2e6cSStephen McConnell targ = &sassc->targets[id];
927327f2e6cSStephen McConnell if (!(targ->flags & MPR_TARGET_FLAGS_RAID_COMPONENT)) {
928991554f2SKenneth D. Merry if (mprsas_check_id(sassc, id) != 0) {
929757ff642SScott Long mpr_dprint(sc, MPR_MAPPING|MPR_INFO,
930757ff642SScott Long "Excluding target id %d\n", id);
931991554f2SKenneth D. Merry error = ENXIO;
932991554f2SKenneth D. Merry goto out;
933991554f2SKenneth D. Merry }
934991554f2SKenneth D. Merry
9354ab1cdc5SScott Long if (targ->handle != 0x0) {
936327f2e6cSStephen McConnell mpr_dprint(sc, MPR_MAPPING, "Attempting to reuse "
937327f2e6cSStephen McConnell "target id %d handle 0x%04x\n", id, targ->handle);
9384ab1cdc5SScott Long error = ENXIO;
9394ab1cdc5SScott Long goto out;
9404ab1cdc5SScott Long }
941327f2e6cSStephen McConnell }
9424ab1cdc5SScott Long
943991554f2SKenneth D. Merry targ->devinfo = device_info;
944991554f2SKenneth D. Merry targ->devname = le32toh(config_page.DeviceName.High);
945991554f2SKenneth D. Merry targ->devname = (targ->devname << 32) |
946991554f2SKenneth D. Merry le32toh(config_page.DeviceName.Low);
947991554f2SKenneth D. Merry targ->encl_handle = le16toh(config_page.EnclosureHandle);
948991554f2SKenneth D. Merry targ->encl_slot = le16toh(config_page.Slot);
949991554f2SKenneth D. Merry targ->encl_level = config_page.EnclosureLevel;
950991554f2SKenneth D. Merry targ->connector_name[0] = config_page.ConnectorName[0];
951991554f2SKenneth D. Merry targ->connector_name[1] = config_page.ConnectorName[1];
952991554f2SKenneth D. Merry targ->connector_name[2] = config_page.ConnectorName[2];
953991554f2SKenneth D. Merry targ->connector_name[3] = config_page.ConnectorName[3];
954991554f2SKenneth D. Merry targ->handle = handle;
955991554f2SKenneth D. Merry targ->parent_handle = le16toh(config_page.ParentDevHandle);
956991554f2SKenneth D. Merry targ->sasaddr = mpr_to_u64(&config_page.SASAddress);
957991554f2SKenneth D. Merry targ->parent_sasaddr = le64toh(parent_sas_address);
958991554f2SKenneth D. Merry targ->parent_devinfo = parent_devinfo;
959991554f2SKenneth D. Merry targ->tid = id;
960991554f2SKenneth D. Merry targ->linkrate = (linkrate>>4);
961991554f2SKenneth D. Merry targ->flags = 0;
962a2c14879SStephen McConnell if (is_SATA_SSD) {
963a2c14879SStephen McConnell targ->flags = MPR_TARGET_IS_SATA_SSD;
964a2c14879SStephen McConnell }
96567feec50SStephen McConnell if ((le16toh(config_page.Flags) &
96667feec50SStephen McConnell MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&
96767feec50SStephen McConnell (le16toh(config_page.Flags) &
96867feec50SStephen McConnell MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE)) {
969991554f2SKenneth D. Merry targ->scsi_req_desc_type =
970991554f2SKenneth D. Merry MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO;
971991554f2SKenneth D. Merry }
972991554f2SKenneth D. Merry if (le16toh(config_page.Flags) &
973991554f2SKenneth D. Merry MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
974991554f2SKenneth D. Merry targ->encl_level_valid = TRUE;
975991554f2SKenneth D. Merry }
976991554f2SKenneth D. Merry TAILQ_INIT(&targ->commands);
977991554f2SKenneth D. Merry TAILQ_INIT(&targ->timedout_commands);
978991554f2SKenneth D. Merry while (!SLIST_EMPTY(&targ->luns)) {
979991554f2SKenneth D. Merry lun = SLIST_FIRST(&targ->luns);
980991554f2SKenneth D. Merry SLIST_REMOVE_HEAD(&targ->luns, lun_link);
981991554f2SKenneth D. Merry free(lun, M_MPR);
982991554f2SKenneth D. Merry }
983991554f2SKenneth D. Merry SLIST_INIT(&targ->luns);
984991554f2SKenneth D. Merry
985991554f2SKenneth D. Merry mpr_describe_devinfo(targ->devinfo, devstring, 80);
986a2c14879SStephen McConnell mpr_dprint(sc, (MPR_INFO|MPR_MAPPING), "Found device <%s> <%s> "
987991554f2SKenneth D. Merry "handle<0x%04x> enclosureHandle<0x%04x> slot %d\n", devstring,
988991554f2SKenneth D. Merry mpr_describe_table(mpr_linkrate_names, targ->linkrate),
989991554f2SKenneth D. Merry targ->handle, targ->encl_handle, targ->encl_slot);
990991554f2SKenneth D. Merry if (targ->encl_level_valid) {
991a2c14879SStephen McConnell mpr_dprint(sc, (MPR_INFO|MPR_MAPPING), "At enclosure level %d "
992991554f2SKenneth D. Merry "and connector name (%4s)\n", targ->encl_level,
993991554f2SKenneth D. Merry targ->connector_name);
994991554f2SKenneth D. Merry }
995991554f2SKenneth D. Merry mprsas_rescan_target(sc, targ);
996991554f2SKenneth D. Merry mpr_dprint(sc, MPR_MAPPING, "Target id 0x%x added\n", targ->tid);
997a2c14879SStephen McConnell
998a2c14879SStephen McConnell /*
999a2c14879SStephen McConnell * Check all commands to see if the SATA_ID_TIMEOUT flag has been set.
1000a2c14879SStephen McConnell * If so, send a Target Reset TM to the target that was just created.
1001a2c14879SStephen McConnell * An Abort Task TM should be used instead of a Target Reset, but that
1002a2c14879SStephen McConnell * would be much more difficult because targets have not been fully
1003a2c14879SStephen McConnell * discovered yet, and LUN's haven't been setup. So, just reset the
1004175ad3d0SKenneth D. Merry * target instead of the LUN. The commands should complete once
1005175ad3d0SKenneth D. Merry * the target has been reset.
1006a2c14879SStephen McConnell */
1007a2c14879SStephen McConnell for (i = 1; i < sc->num_reqs; i++) {
1008a2c14879SStephen McConnell cm = &sc->commands[i];
1009a2c14879SStephen McConnell if (cm->cm_flags & MPR_CM_FLAGS_SATA_ID_TIMEOUT) {
1010a2c14879SStephen McConnell targ->timeouts++;
10118fe7bf06SWarner Losh cm->cm_flags |= MPR_CM_FLAGS_TIMEDOUT;
1012a2c14879SStephen McConnell
1013a2c14879SStephen McConnell if ((targ->tm = mprsas_alloc_tm(sc)) != NULL) {
1014a2c14879SStephen McConnell mpr_dprint(sc, MPR_INFO, "%s: sending Target "
1015a2c14879SStephen McConnell "Reset for stuck SATA identify command "
1016a2c14879SStephen McConnell "(cm = %p)\n", __func__, cm);
1017a2c14879SStephen McConnell targ->tm->cm_targ = targ;
1018a2c14879SStephen McConnell mprsas_send_reset(sc, targ->tm,
1019a2c14879SStephen McConnell MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET);
1020a2c14879SStephen McConnell } else {
1021a2c14879SStephen McConnell mpr_dprint(sc, MPR_ERROR, "Failed to allocate "
10227a2a6a1aSStephen McConnell "tm for Target Reset after SATA ID command "
10237a2a6a1aSStephen McConnell "timed out (cm %p)\n", cm);
1024a2c14879SStephen McConnell }
1025a2c14879SStephen McConnell /*
1026a2c14879SStephen McConnell * No need to check for more since the target is
1027a2c14879SStephen McConnell * already being reset.
1028a2c14879SStephen McConnell */
1029a2c14879SStephen McConnell break;
1030a2c14879SStephen McConnell }
1031a2c14879SStephen McConnell }
1032991554f2SKenneth D. Merry out:
1033991554f2SKenneth D. Merry mprsas_startup_decrement(sassc);
1034991554f2SKenneth D. Merry return (error);
1035991554f2SKenneth D. Merry }
1036991554f2SKenneth D. Merry
1037991554f2SKenneth D. Merry int
mprsas_get_sas_address_for_sata_disk(struct mpr_softc * sc,u64 * sas_address,u16 handle,u32 device_info,u8 * is_SATA_SSD)1038991554f2SKenneth D. Merry mprsas_get_sas_address_for_sata_disk(struct mpr_softc *sc,
1039a2c14879SStephen McConnell u64 *sas_address, u16 handle, u32 device_info, u8 *is_SATA_SSD)
1040991554f2SKenneth D. Merry {
1041991554f2SKenneth D. Merry Mpi2SataPassthroughReply_t mpi_reply;
1042991554f2SKenneth D. Merry int i, rc, try_count;
1043991554f2SKenneth D. Merry u32 *bufferptr;
1044991554f2SKenneth D. Merry union _sata_sas_address hash_address;
1045991554f2SKenneth D. Merry struct _ata_identify_device_data ata_identify;
1046991554f2SKenneth D. Merry u8 buffer[MPT2SAS_MN_LEN + MPT2SAS_SN_LEN];
1047991554f2SKenneth D. Merry u32 ioc_status;
1048991554f2SKenneth D. Merry u8 sas_status;
1049991554f2SKenneth D. Merry
1050991554f2SKenneth D. Merry memset(&ata_identify, 0, sizeof(ata_identify));
10514e02badbSAlan Somers memset(&mpi_reply, 0, sizeof(mpi_reply));
1052991554f2SKenneth D. Merry try_count = 0;
1053991554f2SKenneth D. Merry do {
1054991554f2SKenneth D. Merry rc = mprsas_get_sata_identify(sc, handle, &mpi_reply,
1055991554f2SKenneth D. Merry (char *)&ata_identify, sizeof(ata_identify), device_info);
1056991554f2SKenneth D. Merry try_count++;
1057991554f2SKenneth D. Merry ioc_status = le16toh(mpi_reply.IOCStatus)
1058991554f2SKenneth D. Merry & MPI2_IOCSTATUS_MASK;
1059991554f2SKenneth D. Merry sas_status = mpi_reply.SASStatus;
1060a92fe027SAlan Somers switch (ioc_status) {
1061a92fe027SAlan Somers case MPI2_IOCSTATUS_SUCCESS:
1062a92fe027SAlan Somers break;
1063a92fe027SAlan Somers case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
1064a92fe027SAlan Somers /* No sense sleeping. this error won't get better */
1065a92fe027SAlan Somers break;
1066a92fe027SAlan Somers default:
1067a2c14879SStephen McConnell if (sc->spinup_wait_time > 0) {
1068a2c14879SStephen McConnell mpr_dprint(sc, MPR_INFO, "Sleeping %d seconds "
1069a2c14879SStephen McConnell "after SATA ID error to wait for spinup\n",
1070a2c14879SStephen McConnell sc->spinup_wait_time);
1071a2c14879SStephen McConnell msleep(&sc->msleep_fake_chan, &sc->mpr_mtx, 0,
1072a2c14879SStephen McConnell "mprid", sc->spinup_wait_time * hz);
1073a2c14879SStephen McConnell }
1074a2c14879SStephen McConnell }
1075a92fe027SAlan Somers } while (((rc && (rc != EWOULDBLOCK)) ||
10767a2a6a1aSStephen McConnell (ioc_status && (ioc_status != MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR))
1077a92fe027SAlan Somers || sas_status) && (try_count < 5));
1078991554f2SKenneth D. Merry
1079991554f2SKenneth D. Merry if (rc == 0 && !ioc_status && !sas_status) {
1080991554f2SKenneth D. Merry mpr_dprint(sc, MPR_MAPPING, "%s: got SATA identify "
1081991554f2SKenneth D. Merry "successfully for handle = 0x%x with try_count = %d\n",
1082991554f2SKenneth D. Merry __func__, handle, try_count);
1083991554f2SKenneth D. Merry } else {
1084991554f2SKenneth D. Merry mpr_dprint(sc, MPR_MAPPING, "%s: handle = 0x%x failed\n",
1085991554f2SKenneth D. Merry __func__, handle);
1086991554f2SKenneth D. Merry return -1;
1087991554f2SKenneth D. Merry }
1088991554f2SKenneth D. Merry /* Copy & byteswap the 40 byte model number to a buffer */
1089991554f2SKenneth D. Merry for (i = 0; i < MPT2SAS_MN_LEN; i += 2) {
1090991554f2SKenneth D. Merry buffer[i] = ((u8 *)ata_identify.model_number)[i + 1];
1091991554f2SKenneth D. Merry buffer[i + 1] = ((u8 *)ata_identify.model_number)[i];
1092991554f2SKenneth D. Merry }
1093991554f2SKenneth D. Merry /* Copy & byteswap the 20 byte serial number to a buffer */
1094991554f2SKenneth D. Merry for (i = 0; i < MPT2SAS_SN_LEN; i += 2) {
1095991554f2SKenneth D. Merry buffer[MPT2SAS_MN_LEN + i] =
1096991554f2SKenneth D. Merry ((u8 *)ata_identify.serial_number)[i + 1];
1097991554f2SKenneth D. Merry buffer[MPT2SAS_MN_LEN + i + 1] =
1098991554f2SKenneth D. Merry ((u8 *)ata_identify.serial_number)[i];
1099991554f2SKenneth D. Merry }
1100991554f2SKenneth D. Merry bufferptr = (u32 *)buffer;
1101991554f2SKenneth D. Merry /* There are 60 bytes to hash down to 8. 60 isn't divisible by 8,
1102991554f2SKenneth D. Merry * so loop through the first 56 bytes (7*8),
1103991554f2SKenneth D. Merry * and then add in the last dword.
1104991554f2SKenneth D. Merry */
1105991554f2SKenneth D. Merry hash_address.word.low = 0;
1106991554f2SKenneth D. Merry hash_address.word.high = 0;
1107991554f2SKenneth D. Merry for (i = 0; (i < ((MPT2SAS_MN_LEN+MPT2SAS_SN_LEN)/8)); i++) {
1108991554f2SKenneth D. Merry hash_address.word.low += *bufferptr;
1109991554f2SKenneth D. Merry bufferptr++;
1110991554f2SKenneth D. Merry hash_address.word.high += *bufferptr;
1111991554f2SKenneth D. Merry bufferptr++;
1112991554f2SKenneth D. Merry }
1113991554f2SKenneth D. Merry /* Add the last dword */
1114991554f2SKenneth D. Merry hash_address.word.low += *bufferptr;
1115991554f2SKenneth D. Merry /* Make sure the hash doesn't start with 5, because it could clash
1116991554f2SKenneth D. Merry * with a SAS address. Change 5 to a D.
1117991554f2SKenneth D. Merry */
1118991554f2SKenneth D. Merry if ((hash_address.word.high & 0x000000F0) == (0x00000050))
1119991554f2SKenneth D. Merry hash_address.word.high |= 0x00000080;
1120991554f2SKenneth D. Merry *sas_address = (u64)hash_address.wwid[0] << 56 |
1121991554f2SKenneth D. Merry (u64)hash_address.wwid[1] << 48 | (u64)hash_address.wwid[2] << 40 |
1122991554f2SKenneth D. Merry (u64)hash_address.wwid[3] << 32 | (u64)hash_address.wwid[4] << 24 |
1123991554f2SKenneth D. Merry (u64)hash_address.wwid[5] << 16 | (u64)hash_address.wwid[6] << 8 |
1124991554f2SKenneth D. Merry (u64)hash_address.wwid[7];
1125a2c14879SStephen McConnell if (ata_identify.rotational_speed == 1) {
1126a2c14879SStephen McConnell *is_SATA_SSD = 1;
1127a2c14879SStephen McConnell }
1128a2c14879SStephen McConnell
1129991554f2SKenneth D. Merry return 0;
1130991554f2SKenneth D. Merry }
1131991554f2SKenneth D. Merry
1132991554f2SKenneth D. Merry static int
mprsas_get_sata_identify(struct mpr_softc * sc,u16 handle,Mpi2SataPassthroughReply_t * mpi_reply,char * id_buffer,int sz,u32 devinfo)1133991554f2SKenneth D. Merry mprsas_get_sata_identify(struct mpr_softc *sc, u16 handle,
1134991554f2SKenneth D. Merry Mpi2SataPassthroughReply_t *mpi_reply, char *id_buffer, int sz, u32 devinfo)
1135991554f2SKenneth D. Merry {
1136991554f2SKenneth D. Merry Mpi2SataPassthroughRequest_t *mpi_request;
1137991554f2SKenneth D. Merry Mpi2SataPassthroughReply_t *reply;
1138991554f2SKenneth D. Merry struct mpr_command *cm;
1139991554f2SKenneth D. Merry char *buffer;
1140991554f2SKenneth D. Merry int error = 0;
1141991554f2SKenneth D. Merry
1142991554f2SKenneth D. Merry buffer = malloc( sz, M_MPR, M_NOWAIT | M_ZERO);
1143991554f2SKenneth D. Merry if (!buffer)
1144991554f2SKenneth D. Merry return ENOMEM;
1145991554f2SKenneth D. Merry
1146991554f2SKenneth D. Merry if ((cm = mpr_alloc_command(sc)) == NULL) {
1147991554f2SKenneth D. Merry free(buffer, M_MPR);
1148991554f2SKenneth D. Merry return (EBUSY);
1149991554f2SKenneth D. Merry }
1150991554f2SKenneth D. Merry mpi_request = (MPI2_SATA_PASSTHROUGH_REQUEST *)cm->cm_req;
1151991554f2SKenneth D. Merry bzero(mpi_request,sizeof(MPI2_SATA_PASSTHROUGH_REQUEST));
1152991554f2SKenneth D. Merry mpi_request->Function = MPI2_FUNCTION_SATA_PASSTHROUGH;
1153991554f2SKenneth D. Merry mpi_request->VF_ID = 0;
1154991554f2SKenneth D. Merry mpi_request->DevHandle = htole16(handle);
1155991554f2SKenneth D. Merry mpi_request->PassthroughFlags = (MPI2_SATA_PT_REQ_PT_FLAGS_PIO |
1156991554f2SKenneth D. Merry MPI2_SATA_PT_REQ_PT_FLAGS_READ);
1157991554f2SKenneth D. Merry mpi_request->DataLength = htole32(sz);
1158991554f2SKenneth D. Merry mpi_request->CommandFIS[0] = 0x27;
1159991554f2SKenneth D. Merry mpi_request->CommandFIS[1] = 0x80;
1160991554f2SKenneth D. Merry mpi_request->CommandFIS[2] = (devinfo &
1161991554f2SKenneth D. Merry MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? 0xA1 : 0xEC;
1162991554f2SKenneth D. Merry cm->cm_sge = &mpi_request->SGL;
1163991554f2SKenneth D. Merry cm->cm_sglsize = sizeof(MPI2_SGE_IO_UNION);
1164991554f2SKenneth D. Merry cm->cm_flags = MPR_CM_FLAGS_DATAIN;
1165991554f2SKenneth D. Merry cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1166991554f2SKenneth D. Merry cm->cm_data = buffer;
1167991554f2SKenneth D. Merry cm->cm_length = htole32(sz);
1168a2c14879SStephen McConnell
1169a2c14879SStephen McConnell /*
117086312e46SConrad Meyer * Use a custom handler to avoid reinit'ing the controller on timeout.
117186312e46SConrad Meyer * This fixes a problem where the FW does not send a reply sometimes
1172a2c14879SStephen McConnell * when a bad disk is in the topology. So, this is used to timeout the
1173a2c14879SStephen McConnell * command so that processing can continue normally.
1174a2c14879SStephen McConnell */
117586312e46SConrad Meyer cm->cm_timeout_handler = mprsas_ata_id_timeout;
1176a2c14879SStephen McConnell
117786312e46SConrad Meyer error = mpr_wait_command(sc, &cm, MPR_ATA_ID_TIMEOUT, CAN_SLEEP);
117886312e46SConrad Meyer
117986312e46SConrad Meyer /* mprsas_ata_id_timeout does not reset controller */
118086312e46SConrad Meyer KASSERT(cm != NULL, ("%s: surprise command freed", __func__));
118186312e46SConrad Meyer
1182991554f2SKenneth D. Merry reply = (Mpi2SataPassthroughReply_t *)cm->cm_reply;
1183991554f2SKenneth D. Merry if (error || (reply == NULL)) {
1184991554f2SKenneth D. Merry /* FIXME */
1185991554f2SKenneth D. Merry /*
1186991554f2SKenneth D. Merry * If the request returns an error then we need to do a diag
1187991554f2SKenneth D. Merry * reset
1188991554f2SKenneth D. Merry */
1189aeb9ac0dSScott Long mpr_dprint(sc, MPR_INFO|MPR_FAULT|MPR_MAPPING,
1190e7ef108cSWarner Losh "Request for SATA PASSTHROUGH page completed with error %d\n",
1191aeb9ac0dSScott Long error);
1192991554f2SKenneth D. Merry error = ENXIO;
1193991554f2SKenneth D. Merry goto out;
1194991554f2SKenneth D. Merry }
1195991554f2SKenneth D. Merry bcopy(buffer, id_buffer, sz);
1196991554f2SKenneth D. Merry bcopy(reply, mpi_reply, sizeof(Mpi2SataPassthroughReply_t));
1197991554f2SKenneth D. Merry if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) !=
1198991554f2SKenneth D. Merry MPI2_IOCSTATUS_SUCCESS) {
1199aeb9ac0dSScott Long mpr_dprint(sc, MPR_INFO|MPR_MAPPING|MPR_FAULT,
1200aeb9ac0dSScott Long "Error reading device %#x SATA PASSTHRU; iocstatus= 0x%x\n",
1201aeb9ac0dSScott Long handle, reply->IOCStatus);
1202991554f2SKenneth D. Merry error = ENXIO;
1203991554f2SKenneth D. Merry goto out;
1204991554f2SKenneth D. Merry }
1205991554f2SKenneth D. Merry out:
1206a2c14879SStephen McConnell /*
1207a2c14879SStephen McConnell * If the SATA_ID_TIMEOUT flag has been set for this command, don't free
1208175ad3d0SKenneth D. Merry * it. The command and buffer will be freed after we send a Target
1209175ad3d0SKenneth D. Merry * Reset TM and the command comes back from the controller.
1210a2c14879SStephen McConnell */
12118277ce2bSConrad Meyer if ((cm->cm_flags & MPR_CM_FLAGS_SATA_ID_TIMEOUT) == 0) {
1212991554f2SKenneth D. Merry mpr_free_command(sc, cm);
1213991554f2SKenneth D. Merry free(buffer, M_MPR);
121486312e46SConrad Meyer }
1215991554f2SKenneth D. Merry return (error);
1216991554f2SKenneth D. Merry }
1217991554f2SKenneth D. Merry
1218175ad3d0SKenneth D. Merry /*
1219175ad3d0SKenneth D. Merry * This is completion handler to make sure that commands and allocated
1220175ad3d0SKenneth D. Merry * buffers get freed when timed out SATA ID commands finally complete after
1221175ad3d0SKenneth D. Merry * we've reset the target. In the normal case, we wait for the command to
1222175ad3d0SKenneth D. Merry * complete.
1223175ad3d0SKenneth D. Merry */
1224175ad3d0SKenneth D. Merry static void
mprsas_ata_id_complete(struct mpr_softc * sc,struct mpr_command * cm)1225175ad3d0SKenneth D. Merry mprsas_ata_id_complete(struct mpr_softc *sc, struct mpr_command *cm)
1226175ad3d0SKenneth D. Merry {
1227175ad3d0SKenneth D. Merry mpr_dprint(sc, MPR_INFO, "%s ATA ID completed late cm %p sc %p\n",
1228175ad3d0SKenneth D. Merry __func__, cm, sc);
1229175ad3d0SKenneth D. Merry
1230175ad3d0SKenneth D. Merry free(cm->cm_data, M_MPR);
1231175ad3d0SKenneth D. Merry mpr_free_command(sc, cm);
1232175ad3d0SKenneth D. Merry }
1233175ad3d0SKenneth D. Merry
1234a2c14879SStephen McConnell static void
mprsas_ata_id_timeout(struct mpr_softc * sc,struct mpr_command * cm)123586312e46SConrad Meyer mprsas_ata_id_timeout(struct mpr_softc *sc, struct mpr_command *cm)
1236a2c14879SStephen McConnell {
1237a2c14879SStephen McConnell
123886312e46SConrad Meyer mpr_dprint(sc, MPR_INFO, "%s ATA ID command timeout cm %p sc %p\n",
1239a2c14879SStephen McConnell __func__, cm, sc);
1240a2c14879SStephen McConnell
1241a2c14879SStephen McConnell /*
124286312e46SConrad Meyer * The Abort Task cannot be sent from here because the driver has not
124386312e46SConrad Meyer * completed setting up targets. Instead, the command is flagged so
12448fe7bf06SWarner Losh * that special handling will be used to send the abort. Now that
12458fe7bf06SWarner Losh * this command has timed out, it's no longer in the queue.
1246a2c14879SStephen McConnell */
1247a2c14879SStephen McConnell cm->cm_flags |= MPR_CM_FLAGS_SATA_ID_TIMEOUT;
1248175ad3d0SKenneth D. Merry
1249175ad3d0SKenneth D. Merry /*
1250175ad3d0SKenneth D. Merry * Since we will no longer be waiting for the command to complete,
1251175ad3d0SKenneth D. Merry * set a completion handler to make sure we free all resources.
1252175ad3d0SKenneth D. Merry */
1253175ad3d0SKenneth D. Merry cm->cm_complete = mprsas_ata_id_complete;
1254a2c14879SStephen McConnell }
1255a2c14879SStephen McConnell
1256991554f2SKenneth D. Merry static int
mprsas_add_pcie_device(struct mpr_softc * sc,u16 handle,u8 linkrate)125767feec50SStephen McConnell mprsas_add_pcie_device(struct mpr_softc *sc, u16 handle, u8 linkrate)
125867feec50SStephen McConnell {
125967feec50SStephen McConnell char devstring[80];
126067feec50SStephen McConnell struct mprsas_softc *sassc;
126167feec50SStephen McConnell struct mprsas_target *targ;
126267feec50SStephen McConnell Mpi2ConfigReply_t mpi_reply;
126367feec50SStephen McConnell Mpi26PCIeDevicePage0_t config_page;
126467feec50SStephen McConnell Mpi26PCIeDevicePage2_t config_page2;
126567feec50SStephen McConnell uint64_t pcie_wwid, parent_wwid = 0;
126667feec50SStephen McConnell u32 device_info, parent_devinfo = 0;
126767feec50SStephen McConnell unsigned int id;
126867feec50SStephen McConnell int error = 0;
126967feec50SStephen McConnell struct mprsas_lun *lun;
127067feec50SStephen McConnell
127167feec50SStephen McConnell sassc = sc->sassc;
127267feec50SStephen McConnell mprsas_startup_increment(sassc);
127367feec50SStephen McConnell if ((mpr_config_get_pcie_device_pg0(sc, &mpi_reply, &config_page,
127467feec50SStephen McConnell MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
127567feec50SStephen McConnell printf("%s: error reading PCIe device page0\n", __func__);
127667feec50SStephen McConnell error = ENXIO;
127767feec50SStephen McConnell goto out;
127867feec50SStephen McConnell }
127967feec50SStephen McConnell
128067feec50SStephen McConnell device_info = le32toh(config_page.DeviceInfo);
128167feec50SStephen McConnell
128267feec50SStephen McConnell if (((device_info & MPI26_PCIE_DEVINFO_PCI_SWITCH) == 0)
128367feec50SStephen McConnell && (le16toh(config_page.ParentDevHandle) != 0)) {
128467feec50SStephen McConnell Mpi2ConfigReply_t tmp_mpi_reply;
128567feec50SStephen McConnell Mpi26PCIeDevicePage0_t parent_config_page;
128667feec50SStephen McConnell
128767feec50SStephen McConnell if ((mpr_config_get_pcie_device_pg0(sc, &tmp_mpi_reply,
128867feec50SStephen McConnell &parent_config_page, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE,
128967feec50SStephen McConnell le16toh(config_page.ParentDevHandle)))) {
129067feec50SStephen McConnell printf("%s: error reading PCIe device %#x page0\n",
129167feec50SStephen McConnell __func__, le16toh(config_page.ParentDevHandle));
129267feec50SStephen McConnell } else {
129367feec50SStephen McConnell parent_wwid = parent_config_page.WWID.High;
129467feec50SStephen McConnell parent_wwid = (parent_wwid << 32) |
129567feec50SStephen McConnell parent_config_page.WWID.Low;
129667feec50SStephen McConnell parent_devinfo = le32toh(parent_config_page.DeviceInfo);
129767feec50SStephen McConnell }
129867feec50SStephen McConnell }
129967feec50SStephen McConnell /* TODO Check proper endianness */
130067feec50SStephen McConnell pcie_wwid = config_page.WWID.High;
130167feec50SStephen McConnell pcie_wwid = (pcie_wwid << 32) | config_page.WWID.Low;
130267feec50SStephen McConnell mpr_dprint(sc, MPR_INFO, "PCIe WWID from PCIe device page0 = %jx\n",
130367feec50SStephen McConnell pcie_wwid);
130467feec50SStephen McConnell
130567feec50SStephen McConnell if ((mpr_config_get_pcie_device_pg2(sc, &mpi_reply, &config_page2,
130667feec50SStephen McConnell MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
130767feec50SStephen McConnell printf("%s: error reading PCIe device page2\n", __func__);
130867feec50SStephen McConnell error = ENXIO;
130967feec50SStephen McConnell goto out;
131067feec50SStephen McConnell }
131167feec50SStephen McConnell
1312327f2e6cSStephen McConnell id = mpr_mapping_get_tid(sc, pcie_wwid, handle);
131367feec50SStephen McConnell if (id == MPR_MAP_BAD_ID) {
1314327f2e6cSStephen McConnell mpr_dprint(sc, MPR_ERROR | MPR_INFO, "failure at %s:%d/%s()! "
1315327f2e6cSStephen McConnell "Could not get ID for device with handle 0x%04x\n",
1316327f2e6cSStephen McConnell __FILE__, __LINE__, __func__, handle);
131767feec50SStephen McConnell error = ENXIO;
131867feec50SStephen McConnell goto out;
131967feec50SStephen McConnell }
1320327f2e6cSStephen McConnell mpr_dprint(sc, MPR_MAPPING, "%s: Target ID for added device is %d.\n",
1321327f2e6cSStephen McConnell __func__, id);
132267feec50SStephen McConnell
132367feec50SStephen McConnell if (mprsas_check_id(sassc, id) != 0) {
1324757ff642SScott Long mpr_dprint(sc, MPR_MAPPING|MPR_INFO,
1325757ff642SScott Long "Excluding target id %d\n", id);
132667feec50SStephen McConnell error = ENXIO;
132767feec50SStephen McConnell goto out;
132867feec50SStephen McConnell }
132967feec50SStephen McConnell
133067feec50SStephen McConnell mpr_dprint(sc, MPR_MAPPING, "WWID from PCIe device page0 = %jx\n",
133167feec50SStephen McConnell pcie_wwid);
133267feec50SStephen McConnell targ = &sassc->targets[id];
133367feec50SStephen McConnell targ->devinfo = device_info;
133467feec50SStephen McConnell targ->encl_handle = le16toh(config_page.EnclosureHandle);
133567feec50SStephen McConnell targ->encl_slot = le16toh(config_page.Slot);
133667feec50SStephen McConnell targ->encl_level = config_page.EnclosureLevel;
133767feec50SStephen McConnell targ->connector_name[0] = ((char *)&config_page.ConnectorName)[0];
133867feec50SStephen McConnell targ->connector_name[1] = ((char *)&config_page.ConnectorName)[1];
133967feec50SStephen McConnell targ->connector_name[2] = ((char *)&config_page.ConnectorName)[2];
134067feec50SStephen McConnell targ->connector_name[3] = ((char *)&config_page.ConnectorName)[3];
134167feec50SStephen McConnell targ->is_nvme = device_info & MPI26_PCIE_DEVINFO_NVME;
134267feec50SStephen McConnell targ->MDTS = config_page2.MaximumDataTransferSize;
134389d1c21fSKashyap D Desai if (targ->is_nvme)
134489d1c21fSKashyap D Desai targ->controller_reset_timeout = config_page2.ControllerResetTO;
134567feec50SStephen McConnell /*
134667feec50SStephen McConnell * Assume always TRUE for encl_level_valid because there is no valid
134767feec50SStephen McConnell * flag for PCIe.
134867feec50SStephen McConnell */
134967feec50SStephen McConnell targ->encl_level_valid = TRUE;
135067feec50SStephen McConnell targ->handle = handle;
135167feec50SStephen McConnell targ->parent_handle = le16toh(config_page.ParentDevHandle);
135267feec50SStephen McConnell targ->sasaddr = mpr_to_u64(&config_page.WWID);
135367feec50SStephen McConnell targ->parent_sasaddr = le64toh(parent_wwid);
135467feec50SStephen McConnell targ->parent_devinfo = parent_devinfo;
135567feec50SStephen McConnell targ->tid = id;
135667feec50SStephen McConnell targ->linkrate = linkrate;
135767feec50SStephen McConnell targ->flags = 0;
135867feec50SStephen McConnell if ((le16toh(config_page.Flags) &
135967feec50SStephen McConnell MPI26_PCIEDEV0_FLAGS_ENABLED_FAST_PATH) &&
136067feec50SStephen McConnell (le16toh(config_page.Flags) &
136167feec50SStephen McConnell MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE)) {
136267feec50SStephen McConnell targ->scsi_req_desc_type =
136367feec50SStephen McConnell MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO;
136467feec50SStephen McConnell }
136567feec50SStephen McConnell TAILQ_INIT(&targ->commands);
136667feec50SStephen McConnell TAILQ_INIT(&targ->timedout_commands);
136767feec50SStephen McConnell while (!SLIST_EMPTY(&targ->luns)) {
136867feec50SStephen McConnell lun = SLIST_FIRST(&targ->luns);
136967feec50SStephen McConnell SLIST_REMOVE_HEAD(&targ->luns, lun_link);
137067feec50SStephen McConnell free(lun, M_MPR);
137167feec50SStephen McConnell }
137267feec50SStephen McConnell SLIST_INIT(&targ->luns);
137367feec50SStephen McConnell
137467feec50SStephen McConnell mpr_describe_devinfo(targ->devinfo, devstring, 80);
137567feec50SStephen McConnell mpr_dprint(sc, (MPR_INFO|MPR_MAPPING), "Found PCIe device <%s> <%s> "
137667feec50SStephen McConnell "handle<0x%04x> enclosureHandle<0x%04x> slot %d\n", devstring,
137767feec50SStephen McConnell mpr_describe_table(mpr_pcie_linkrate_names, targ->linkrate),
137867feec50SStephen McConnell targ->handle, targ->encl_handle, targ->encl_slot);
137967feec50SStephen McConnell if (targ->encl_level_valid) {
138067feec50SStephen McConnell mpr_dprint(sc, (MPR_INFO|MPR_MAPPING), "At enclosure level %d "
138167feec50SStephen McConnell "and connector name (%4s)\n", targ->encl_level,
138267feec50SStephen McConnell targ->connector_name);
138367feec50SStephen McConnell }
138467feec50SStephen McConnell mprsas_rescan_target(sc, targ);
138567feec50SStephen McConnell mpr_dprint(sc, MPR_MAPPING, "Target id 0x%x added\n", targ->tid);
138667feec50SStephen McConnell
138767feec50SStephen McConnell out:
138867feec50SStephen McConnell mprsas_startup_decrement(sassc);
138967feec50SStephen McConnell return (error);
139067feec50SStephen McConnell }
139167feec50SStephen McConnell
139267feec50SStephen McConnell static int
mprsas_volume_add(struct mpr_softc * sc,u16 handle)1393991554f2SKenneth D. Merry mprsas_volume_add(struct mpr_softc *sc, u16 handle)
1394991554f2SKenneth D. Merry {
1395991554f2SKenneth D. Merry struct mprsas_softc *sassc;
1396991554f2SKenneth D. Merry struct mprsas_target *targ;
1397991554f2SKenneth D. Merry u64 wwid;
1398991554f2SKenneth D. Merry unsigned int id;
1399991554f2SKenneth D. Merry int error = 0;
1400991554f2SKenneth D. Merry struct mprsas_lun *lun;
1401991554f2SKenneth D. Merry
1402991554f2SKenneth D. Merry sassc = sc->sassc;
1403991554f2SKenneth D. Merry mprsas_startup_increment(sassc);
1404991554f2SKenneth D. Merry /* wwid is endian safe */
1405991554f2SKenneth D. Merry mpr_config_get_volume_wwid(sc, handle, &wwid);
1406991554f2SKenneth D. Merry if (!wwid) {
1407991554f2SKenneth D. Merry printf("%s: invalid WWID; cannot add volume to mapping table\n",
1408991554f2SKenneth D. Merry __func__);
1409991554f2SKenneth D. Merry error = ENXIO;
1410991554f2SKenneth D. Merry goto out;
1411991554f2SKenneth D. Merry }
1412991554f2SKenneth D. Merry
1413327f2e6cSStephen McConnell id = mpr_mapping_get_raid_tid(sc, wwid, handle);
1414991554f2SKenneth D. Merry if (id == MPR_MAP_BAD_ID) {
1415991554f2SKenneth D. Merry printf("%s: could not get ID for volume with handle 0x%04x and "
1416991554f2SKenneth D. Merry "WWID 0x%016llx\n", __func__, handle,
1417991554f2SKenneth D. Merry (unsigned long long)wwid);
1418991554f2SKenneth D. Merry error = ENXIO;
1419991554f2SKenneth D. Merry goto out;
1420991554f2SKenneth D. Merry }
1421991554f2SKenneth D. Merry
1422991554f2SKenneth D. Merry targ = &sassc->targets[id];
1423991554f2SKenneth D. Merry targ->tid = id;
1424991554f2SKenneth D. Merry targ->handle = handle;
1425991554f2SKenneth D. Merry targ->devname = wwid;
1426e3c5965cSAlexander Motin targ->flags = MPR_TARGET_FLAGS_VOLUME;
1427991554f2SKenneth D. Merry TAILQ_INIT(&targ->commands);
1428991554f2SKenneth D. Merry TAILQ_INIT(&targ->timedout_commands);
1429991554f2SKenneth D. Merry while (!SLIST_EMPTY(&targ->luns)) {
1430991554f2SKenneth D. Merry lun = SLIST_FIRST(&targ->luns);
1431991554f2SKenneth D. Merry SLIST_REMOVE_HEAD(&targ->luns, lun_link);
1432991554f2SKenneth D. Merry free(lun, M_MPR);
1433991554f2SKenneth D. Merry }
1434991554f2SKenneth D. Merry SLIST_INIT(&targ->luns);
1435991554f2SKenneth D. Merry mprsas_rescan_target(sc, targ);
1436991554f2SKenneth D. Merry mpr_dprint(sc, MPR_MAPPING, "RAID target id %d added (WWID = 0x%jx)\n",
1437991554f2SKenneth D. Merry targ->tid, wwid);
1438991554f2SKenneth D. Merry out:
1439991554f2SKenneth D. Merry mprsas_startup_decrement(sassc);
1440991554f2SKenneth D. Merry return (error);
1441991554f2SKenneth D. Merry }
1442991554f2SKenneth D. Merry
1443991554f2SKenneth D. Merry /**
1444991554f2SKenneth D. Merry * mprsas_SSU_to_SATA_devices
1445991554f2SKenneth D. Merry * @sc: per adapter object
1446991554f2SKenneth D. Merry *
1447991554f2SKenneth D. Merry * Looks through the target list and issues a StartStopUnit SCSI command to each
1448991554f2SKenneth D. Merry * SATA direct-access device. This helps to ensure that data corruption is
1449991554f2SKenneth D. Merry * avoided when the system is being shut down. This must be called after the IR
1450991554f2SKenneth D. Merry * System Shutdown RAID Action is sent if in IR mode.
1451991554f2SKenneth D. Merry *
1452991554f2SKenneth D. Merry * Return nothing.
1453991554f2SKenneth D. Merry */
1454991554f2SKenneth D. Merry static void
mprsas_SSU_to_SATA_devices(struct mpr_softc * sc,int howto)1455acc173a6SWarner Losh mprsas_SSU_to_SATA_devices(struct mpr_softc *sc, int howto)
1456991554f2SKenneth D. Merry {
1457991554f2SKenneth D. Merry struct mprsas_softc *sassc = sc->sassc;
1458991554f2SKenneth D. Merry union ccb *ccb;
1459991554f2SKenneth D. Merry path_id_t pathid = cam_sim_path(sassc->sim);
1460991554f2SKenneth D. Merry target_id_t targetid;
1461991554f2SKenneth D. Merry struct mprsas_target *target;
1462991554f2SKenneth D. Merry char path_str[64];
1463acc173a6SWarner Losh int timeout;
1464991554f2SKenneth D. Merry
146563941e98SKenneth D. Merry mpr_lock(sc);
146663941e98SKenneth D. Merry
1467991554f2SKenneth D. Merry /*
1468a2c14879SStephen McConnell * For each target, issue a StartStopUnit command to stop the device.
1469991554f2SKenneth D. Merry */
1470991554f2SKenneth D. Merry sc->SSU_started = TRUE;
1471991554f2SKenneth D. Merry sc->SSU_refcount = 0;
1472327f2e6cSStephen McConnell for (targetid = 0; targetid < sc->max_devices; targetid++) {
1473991554f2SKenneth D. Merry target = &sassc->targets[targetid];
1474991554f2SKenneth D. Merry if (target->handle == 0x0) {
1475991554f2SKenneth D. Merry continue;
1476991554f2SKenneth D. Merry }
1477991554f2SKenneth D. Merry
1478fa699bb2SAlan Somers /*
1479fa699bb2SAlan Somers * The stop_at_shutdown flag will be set if this device is
1480fa699bb2SAlan Somers * a SATA direct-access end device.
1481fa699bb2SAlan Somers */
1482fa699bb2SAlan Somers if (target->stop_at_shutdown) {
1483991554f2SKenneth D. Merry ccb = xpt_alloc_ccb_nowait();
1484991554f2SKenneth D. Merry if (ccb == NULL) {
148567feec50SStephen McConnell mpr_dprint(sc, MPR_FAULT, "Unable to alloc CCB "
148667feec50SStephen McConnell "to stop unit.\n");
1487991554f2SKenneth D. Merry return;
1488991554f2SKenneth D. Merry }
1489991554f2SKenneth D. Merry
1490a2c14879SStephen McConnell if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
1491a2c14879SStephen McConnell pathid, targetid, CAM_LUN_WILDCARD) !=
1492a2c14879SStephen McConnell CAM_REQ_CMP) {
1493a2c14879SStephen McConnell mpr_dprint(sc, MPR_ERROR, "Unable to create "
1494a2c14879SStephen McConnell "path to stop unit.\n");
1495991554f2SKenneth D. Merry xpt_free_ccb(ccb);
1496991554f2SKenneth D. Merry return;
1497991554f2SKenneth D. Merry }
1498991554f2SKenneth D. Merry xpt_path_string(ccb->ccb_h.path, path_str,
1499991554f2SKenneth D. Merry sizeof(path_str));
1500991554f2SKenneth D. Merry
1501a2c14879SStephen McConnell mpr_dprint(sc, MPR_INFO, "Sending StopUnit: path %s "
1502a2c14879SStephen McConnell "handle %d\n", path_str, target->handle);
1503991554f2SKenneth D. Merry
1504991554f2SKenneth D. Merry /*
1505a2c14879SStephen McConnell * Issue a START STOP UNIT command for the target.
1506a2c14879SStephen McConnell * Increment the SSU counter to be used to count the
1507a2c14879SStephen McConnell * number of required replies.
1508991554f2SKenneth D. Merry */
1509a2c14879SStephen McConnell mpr_dprint(sc, MPR_INFO, "Incrementing SSU count\n");
1510991554f2SKenneth D. Merry sc->SSU_refcount++;
1511991554f2SKenneth D. Merry ccb->ccb_h.target_id =
1512991554f2SKenneth D. Merry xpt_path_target_id(ccb->ccb_h.path);
1513991554f2SKenneth D. Merry ccb->ccb_h.ppriv_ptr1 = sassc;
1514991554f2SKenneth D. Merry scsi_start_stop(&ccb->csio,
1515991554f2SKenneth D. Merry /*retries*/0,
1516991554f2SKenneth D. Merry mprsas_stop_unit_done,
1517991554f2SKenneth D. Merry MSG_SIMPLE_Q_TAG,
1518991554f2SKenneth D. Merry /*start*/FALSE,
1519991554f2SKenneth D. Merry /*load/eject*/0,
1520991554f2SKenneth D. Merry /*immediate*/FALSE,
1521991554f2SKenneth D. Merry MPR_SENSE_LEN,
1522991554f2SKenneth D. Merry /*timeout*/10000);
1523991554f2SKenneth D. Merry xpt_action(ccb);
1524991554f2SKenneth D. Merry }
1525991554f2SKenneth D. Merry }
1526991554f2SKenneth D. Merry
152763941e98SKenneth D. Merry mpr_unlock(sc);
152863941e98SKenneth D. Merry
1529991554f2SKenneth D. Merry /*
1530acc173a6SWarner Losh * Timeout after 60 seconds by default or 10 seconds if howto has
1531acc173a6SWarner Losh * RB_NOSYNC set which indicates we're likely handling a panic.
1532991554f2SKenneth D. Merry */
1533acc173a6SWarner Losh timeout = 600;
1534acc173a6SWarner Losh if (howto & RB_NOSYNC)
1535acc173a6SWarner Losh timeout = 100;
1536991554f2SKenneth D. Merry
1537acc173a6SWarner Losh /*
1538acc173a6SWarner Losh * Wait until all of the SSU commands have completed or time
1539acc173a6SWarner Losh * has expired. Pause for 100ms each time through. If any
1540acc173a6SWarner Losh * command times out, the target will be reset in the SCSI
1541acc173a6SWarner Losh * command timeout routine.
1542acc173a6SWarner Losh */
1543acc173a6SWarner Losh while (sc->SSU_refcount > 0) {
1544acc173a6SWarner Losh pause("mprwait", hz/10);
1545acc173a6SWarner Losh if (SCHEDULER_STOPPED())
1546acc173a6SWarner Losh xpt_sim_poll(sassc->sim);
1547acc173a6SWarner Losh
1548acc173a6SWarner Losh if (--timeout == 0) {
1549a2c14879SStephen McConnell mpr_dprint(sc, MPR_ERROR, "Time has expired waiting "
1550991554f2SKenneth D. Merry "for SSU commands to complete.\n");
1551991554f2SKenneth D. Merry break;
1552991554f2SKenneth D. Merry }
1553991554f2SKenneth D. Merry }
1554991554f2SKenneth D. Merry }
1555991554f2SKenneth D. Merry
1556991554f2SKenneth D. Merry static void
mprsas_stop_unit_done(struct cam_periph * periph,union ccb * done_ccb)1557991554f2SKenneth D. Merry mprsas_stop_unit_done(struct cam_periph *periph, union ccb *done_ccb)
1558991554f2SKenneth D. Merry {
1559991554f2SKenneth D. Merry struct mprsas_softc *sassc;
1560991554f2SKenneth D. Merry char path_str[64];
1561991554f2SKenneth D. Merry
15625d21655fSStephen McConnell if (done_ccb == NULL)
15635d21655fSStephen McConnell return;
15645d21655fSStephen McConnell
1565991554f2SKenneth D. Merry sassc = (struct mprsas_softc *)done_ccb->ccb_h.ppriv_ptr1;
1566991554f2SKenneth D. Merry
1567991554f2SKenneth D. Merry xpt_path_string(done_ccb->ccb_h.path, path_str, sizeof(path_str));
1568991554f2SKenneth D. Merry mpr_dprint(sassc->sc, MPR_INFO, "Completing stop unit for %s\n",
1569991554f2SKenneth D. Merry path_str);
1570991554f2SKenneth D. Merry
1571991554f2SKenneth D. Merry /*
1572991554f2SKenneth D. Merry * Nothing more to do except free the CCB and path. If the command
1573991554f2SKenneth D. Merry * timed out, an abort reset, then target reset will be issued during
1574991554f2SKenneth D. Merry * the SCSI Command process.
1575991554f2SKenneth D. Merry */
1576991554f2SKenneth D. Merry xpt_free_path(done_ccb->ccb_h.path);
1577991554f2SKenneth D. Merry xpt_free_ccb(done_ccb);
1578991554f2SKenneth D. Merry }
1579991554f2SKenneth D. Merry
1580991554f2SKenneth D. Merry /**
1581991554f2SKenneth D. Merry * mprsas_ir_shutdown - IR shutdown notification
1582991554f2SKenneth D. Merry * @sc: per adapter object
1583991554f2SKenneth D. Merry *
1584991554f2SKenneth D. Merry * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
1585991554f2SKenneth D. Merry * the host system is shutting down.
1586991554f2SKenneth D. Merry *
1587991554f2SKenneth D. Merry * Return nothing.
1588991554f2SKenneth D. Merry */
1589991554f2SKenneth D. Merry void
mprsas_ir_shutdown(struct mpr_softc * sc,int howto)1590acc173a6SWarner Losh mprsas_ir_shutdown(struct mpr_softc *sc, int howto)
1591991554f2SKenneth D. Merry {
1592991554f2SKenneth D. Merry u16 volume_mapping_flags;
1593991554f2SKenneth D. Merry u16 ioc_pg8_flags = le16toh(sc->ioc_pg8.Flags);
1594991554f2SKenneth D. Merry struct dev_mapping_table *mt_entry;
1595991554f2SKenneth D. Merry u32 start_idx, end_idx;
1596991554f2SKenneth D. Merry unsigned int id, found_volume = 0;
1597991554f2SKenneth D. Merry struct mpr_command *cm;
1598991554f2SKenneth D. Merry Mpi2RaidActionRequest_t *action;
1599a2c14879SStephen McConnell target_id_t targetid;
1600a2c14879SStephen McConnell struct mprsas_target *target;
1601991554f2SKenneth D. Merry
1602991554f2SKenneth D. Merry mpr_dprint(sc, MPR_TRACE, "%s\n", __func__);
1603991554f2SKenneth D. Merry
1604991554f2SKenneth D. Merry /* is IR firmware build loaded? */
1605991554f2SKenneth D. Merry if (!sc->ir_firmware)
1606991554f2SKenneth D. Merry goto out;
1607991554f2SKenneth D. Merry
1608991554f2SKenneth D. Merry /* are there any volumes? Look at IR target IDs. */
1609991554f2SKenneth D. Merry // TODO-later, this should be looked up in the RAID config structure
1610991554f2SKenneth D. Merry // when it is implemented.
1611991554f2SKenneth D. Merry volume_mapping_flags = le16toh(sc->ioc_pg8.IRVolumeMappingFlags) &
1612991554f2SKenneth D. Merry MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
1613991554f2SKenneth D. Merry if (volume_mapping_flags == MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
1614991554f2SKenneth D. Merry start_idx = 0;
1615991554f2SKenneth D. Merry if (ioc_pg8_flags & MPI2_IOCPAGE8_FLAGS_RESERVED_TARGETID_0)
1616991554f2SKenneth D. Merry start_idx = 1;
1617991554f2SKenneth D. Merry } else
1618991554f2SKenneth D. Merry start_idx = sc->max_devices - sc->max_volumes;
1619991554f2SKenneth D. Merry end_idx = start_idx + sc->max_volumes - 1;
1620991554f2SKenneth D. Merry
1621991554f2SKenneth D. Merry for (id = start_idx; id < end_idx; id++) {
1622991554f2SKenneth D. Merry mt_entry = &sc->mapping_table[id];
1623991554f2SKenneth D. Merry if ((mt_entry->physical_id != 0) &&
1624991554f2SKenneth D. Merry (mt_entry->missing_count == 0)) {
1625991554f2SKenneth D. Merry found_volume = 1;
1626991554f2SKenneth D. Merry break;
1627991554f2SKenneth D. Merry }
1628991554f2SKenneth D. Merry }
1629991554f2SKenneth D. Merry
1630991554f2SKenneth D. Merry if (!found_volume)
1631991554f2SKenneth D. Merry goto out;
1632991554f2SKenneth D. Merry
1633991554f2SKenneth D. Merry if ((cm = mpr_alloc_command(sc)) == NULL) {
1634991554f2SKenneth D. Merry printf("%s: command alloc failed\n", __func__);
1635991554f2SKenneth D. Merry goto out;
1636991554f2SKenneth D. Merry }
1637991554f2SKenneth D. Merry
1638991554f2SKenneth D. Merry action = (MPI2_RAID_ACTION_REQUEST *)cm->cm_req;
1639991554f2SKenneth D. Merry action->Function = MPI2_FUNCTION_RAID_ACTION;
1640991554f2SKenneth D. Merry action->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
1641991554f2SKenneth D. Merry cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1642991554f2SKenneth D. Merry mpr_lock(sc);
16436d4ffcb4SKenneth D. Merry mpr_wait_command(sc, &cm, 5, CAN_SLEEP);
1644991554f2SKenneth D. Merry mpr_unlock(sc);
1645991554f2SKenneth D. Merry
1646991554f2SKenneth D. Merry /*
1647991554f2SKenneth D. Merry * Don't check for reply, just leave.
1648991554f2SKenneth D. Merry */
1649991554f2SKenneth D. Merry if (cm)
1650991554f2SKenneth D. Merry mpr_free_command(sc, cm);
1651991554f2SKenneth D. Merry
1652991554f2SKenneth D. Merry out:
1653a2c14879SStephen McConnell /*
1654a2c14879SStephen McConnell * All of the targets must have the correct value set for
1655a2c14879SStephen McConnell * 'stop_at_shutdown' for the current 'enable_ssu' sysctl variable.
1656a2c14879SStephen McConnell *
1657a2c14879SStephen McConnell * The possible values for the 'enable_ssu' variable are:
1658a2c14879SStephen McConnell * 0: disable to SSD and HDD
1659a2c14879SStephen McConnell * 1: disable only to HDD (default)
1660a2c14879SStephen McConnell * 2: disable only to SSD
1661a2c14879SStephen McConnell * 3: enable to SSD and HDD
1662a2c14879SStephen McConnell * anything else will default to 1.
1663a2c14879SStephen McConnell */
1664327f2e6cSStephen McConnell for (targetid = 0; targetid < sc->max_devices; targetid++) {
1665a2c14879SStephen McConnell target = &sc->sassc->targets[targetid];
1666a2c14879SStephen McConnell if (target->handle == 0x0) {
1667a2c14879SStephen McConnell continue;
1668a2c14879SStephen McConnell }
1669a2c14879SStephen McConnell
1670a2c14879SStephen McConnell if (target->supports_SSU) {
1671a2c14879SStephen McConnell switch (sc->enable_ssu) {
1672a2c14879SStephen McConnell case MPR_SSU_DISABLE_SSD_DISABLE_HDD:
1673a2c14879SStephen McConnell target->stop_at_shutdown = FALSE;
1674a2c14879SStephen McConnell break;
1675a2c14879SStephen McConnell case MPR_SSU_DISABLE_SSD_ENABLE_HDD:
1676a2c14879SStephen McConnell target->stop_at_shutdown = TRUE;
1677a2c14879SStephen McConnell if (target->flags & MPR_TARGET_IS_SATA_SSD) {
1678a2c14879SStephen McConnell target->stop_at_shutdown = FALSE;
1679a2c14879SStephen McConnell }
1680a2c14879SStephen McConnell break;
1681a2c14879SStephen McConnell case MPR_SSU_ENABLE_SSD_ENABLE_HDD:
1682a2c14879SStephen McConnell target->stop_at_shutdown = TRUE;
1683a2c14879SStephen McConnell break;
1684a2c14879SStephen McConnell case MPR_SSU_ENABLE_SSD_DISABLE_HDD:
1685a2c14879SStephen McConnell default:
1686a2c14879SStephen McConnell target->stop_at_shutdown = TRUE;
1687a2c14879SStephen McConnell if ((target->flags &
1688a2c14879SStephen McConnell MPR_TARGET_IS_SATA_SSD) == 0) {
1689a2c14879SStephen McConnell target->stop_at_shutdown = FALSE;
1690a2c14879SStephen McConnell }
1691a2c14879SStephen McConnell break;
1692a2c14879SStephen McConnell }
1693a2c14879SStephen McConnell }
1694a2c14879SStephen McConnell }
1695acc173a6SWarner Losh mprsas_SSU_to_SATA_devices(sc, howto);
1696991554f2SKenneth D. Merry }
1697