2 * FreeBSD/CAM specific routines for LSI '909 FC adapters.
5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-3-Clause
7 * Copyright (c) 2000, 2001 by Greg Ansley
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice immediately at the beginning of the file, without modification,
14 * this list of conditions, and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 2002, 2006 by Matthew Jacob
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions are
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
40 * substantially similar to the "NO WARRANTY" disclaimer below
41 * ("Disclaimer") and any redistribution must be conditioned upon including
42 * a substantially similar Disclaimer requirement for further binary
44 * 3. Neither the names of the above listed copyright holders nor the names
45 * of any contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
52 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
58 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 * Support from Chris Ellsworth in order to make SAS adapters work
61 * is gratefully acknowledged.
63 * Support from LSI-Logic has also gone a great deal toward making this a
64 * workable subsystem and is gratefully acknowledged.
67 * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
68 * Copyright (c) 2005, WHEEL Sp. z o.o.
69 * Copyright (c) 2004, 2005 Justin T. Gibbs
70 * All rights reserved.
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions are
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
78 * substantially similar to the "NO WARRANTY" disclaimer below
79 * ("Disclaimer") and any redistribution must be conditioned upon including
80 * a substantially similar Disclaimer requirement for further binary
82 * 3. Neither the names of the above listed copyright holders nor the names
83 * of any contributors may be used to endorse or promote products derived
84 * from this software without specific prior written permission.
86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
90 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
91 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
92 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
93 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
94 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
95 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
96 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 #include <sys/cdefs.h>
99 __FBSDID("$FreeBSD$");
101 #include <dev/mpt/mpt.h>
102 #include <dev/mpt/mpt_cam.h>
103 #include <dev/mpt/mpt_raid.h>
105 #include "dev/mpt/mpilib/mpi_ioc.h" /* XXX Fix Event Handling!!! */
106 #include "dev/mpt/mpilib/mpi_init.h"
107 #include "dev/mpt/mpilib/mpi_targ.h"
108 #include "dev/mpt/mpilib/mpi_fc.h"
109 #include "dev/mpt/mpilib/mpi_sas.h"
111 #include <sys/callout.h>
112 #include <sys/kthread.h>
113 #include <sys/sysctl.h>
115 static void mpt_poll(struct cam_sim *);
116 static callout_func_t mpt_timeout;
117 static void mpt_action(struct cam_sim *, union ccb *);
119 mpt_get_spi_settings(struct mpt_softc *, struct ccb_trans_settings *);
120 static void mpt_setwidth(struct mpt_softc *, int, int);
121 static void mpt_setsync(struct mpt_softc *, int, int, int);
122 static int mpt_update_spi_config(struct mpt_softc *, int);
124 static mpt_reply_handler_t mpt_scsi_reply_handler;
125 static mpt_reply_handler_t mpt_scsi_tmf_reply_handler;
126 static mpt_reply_handler_t mpt_fc_els_reply_handler;
127 static int mpt_scsi_reply_frame_handler(struct mpt_softc *, request_t *,
128 MSG_DEFAULT_REPLY *);
129 static int mpt_bus_reset(struct mpt_softc *, target_id_t, lun_id_t, int);
130 static int mpt_fc_reset_link(struct mpt_softc *, int);
132 static int mpt_spawn_recovery_thread(struct mpt_softc *mpt);
133 static void mpt_terminate_recovery_thread(struct mpt_softc *mpt);
134 static void mpt_recovery_thread(void *arg);
135 static void mpt_recover_commands(struct mpt_softc *mpt);
137 static int mpt_scsi_send_tmf(struct mpt_softc *, u_int, u_int, u_int,
138 target_id_t, lun_id_t, u_int, int);
140 static void mpt_fc_post_els(struct mpt_softc *mpt, request_t *, int);
141 static void mpt_post_target_command(struct mpt_softc *, request_t *, int);
142 static int mpt_add_els_buffers(struct mpt_softc *mpt);
143 static int mpt_add_target_commands(struct mpt_softc *mpt);
144 static int mpt_enable_lun(struct mpt_softc *, target_id_t, lun_id_t);
145 static int mpt_disable_lun(struct mpt_softc *, target_id_t, lun_id_t);
146 static void mpt_target_start_io(struct mpt_softc *, union ccb *);
147 static cam_status mpt_abort_target_ccb(struct mpt_softc *, union ccb *);
148 static int mpt_abort_target_cmd(struct mpt_softc *, request_t *);
149 static void mpt_scsi_tgt_status(struct mpt_softc *, union ccb *, request_t *,
150 uint8_t, uint8_t const *, u_int);
152 mpt_scsi_tgt_tsk_mgmt(struct mpt_softc *, request_t *, mpt_task_mgmt_t,
153 tgt_resource_t *, int);
154 static void mpt_tgt_dump_tgt_state(struct mpt_softc *, request_t *);
155 static void mpt_tgt_dump_req_state(struct mpt_softc *, request_t *);
156 static mpt_reply_handler_t mpt_scsi_tgt_reply_handler;
157 static mpt_reply_handler_t mpt_sata_pass_reply_handler;
159 static uint32_t scsi_io_handler_id = MPT_HANDLER_ID_NONE;
160 static uint32_t scsi_tmf_handler_id = MPT_HANDLER_ID_NONE;
161 static uint32_t fc_els_handler_id = MPT_HANDLER_ID_NONE;
162 static uint32_t sata_pass_handler_id = MPT_HANDLER_ID_NONE;
164 static mpt_probe_handler_t mpt_cam_probe;
165 static mpt_attach_handler_t mpt_cam_attach;
166 static mpt_enable_handler_t mpt_cam_enable;
167 static mpt_ready_handler_t mpt_cam_ready;
168 static mpt_event_handler_t mpt_cam_event;
169 static mpt_reset_handler_t mpt_cam_ioc_reset;
170 static mpt_detach_handler_t mpt_cam_detach;
172 static struct mpt_personality mpt_cam_personality =
175 .probe = mpt_cam_probe,
176 .attach = mpt_cam_attach,
177 .enable = mpt_cam_enable,
178 .ready = mpt_cam_ready,
179 .event = mpt_cam_event,
180 .reset = mpt_cam_ioc_reset,
181 .detach = mpt_cam_detach,
184 DECLARE_MPT_PERSONALITY(mpt_cam, SI_ORDER_SECOND);
185 MODULE_DEPEND(mpt_cam, cam, 1, 1, 1);
187 int mpt_enable_sata_wc = -1;
188 TUNABLE_INT("hw.mpt.enable_sata_wc", &mpt_enable_sata_wc);
191 mpt_cam_probe(struct mpt_softc *mpt)
196 * Only attach to nodes that support the initiator or target role
197 * (or want to) or have RAID physical devices that need CAM pass-thru
200 if (mpt->do_cfg_role) {
201 role = mpt->cfg_role;
205 if ((role & (MPT_ROLE_TARGET|MPT_ROLE_INITIATOR)) != 0 ||
206 (mpt->ioc_page2 != NULL && mpt->ioc_page2->MaxPhysDisks != 0)) {
213 mpt_cam_attach(struct mpt_softc *mpt)
215 struct cam_devq *devq;
216 mpt_handler_t handler;
221 TAILQ_INIT(&mpt->request_timeout_list);
222 maxq = (mpt->ioc_facts.GlobalCredits < MPT_MAX_REQUESTS(mpt))?
223 mpt->ioc_facts.GlobalCredits : MPT_MAX_REQUESTS(mpt);
225 handler.reply_handler = mpt_scsi_reply_handler;
226 error = mpt_register_handler(mpt, MPT_HANDLER_REPLY, handler,
227 &scsi_io_handler_id);
233 handler.reply_handler = mpt_scsi_tmf_reply_handler;
234 error = mpt_register_handler(mpt, MPT_HANDLER_REPLY, handler,
235 &scsi_tmf_handler_id);
242 * If we're fibre channel and could support target mode, we register
243 * an ELS reply handler and give it resources.
245 if (mpt->is_fc && (mpt->role & MPT_ROLE_TARGET) != 0) {
246 handler.reply_handler = mpt_fc_els_reply_handler;
247 error = mpt_register_handler(mpt, MPT_HANDLER_REPLY, handler,
253 if (mpt_add_els_buffers(mpt) == FALSE) {
258 maxq -= mpt->els_cmds_allocated;
262 * If we support target mode, we register a reply handler for it,
263 * but don't add command resources until we actually enable target
266 if (mpt->is_fc && (mpt->role & MPT_ROLE_TARGET) != 0) {
267 handler.reply_handler = mpt_scsi_tgt_reply_handler;
268 error = mpt_register_handler(mpt, MPT_HANDLER_REPLY, handler,
269 &mpt->scsi_tgt_handler_id);
277 handler.reply_handler = mpt_sata_pass_reply_handler;
278 error = mpt_register_handler(mpt, MPT_HANDLER_REPLY, handler,
279 &sata_pass_handler_id);
287 * We keep one request reserved for timeout TMF requests.
289 mpt->tmf_req = mpt_get_request(mpt, FALSE);
290 if (mpt->tmf_req == NULL) {
291 mpt_prt(mpt, "Unable to allocate dedicated TMF request!\n");
298 * Mark the request as free even though not on the free list.
299 * There is only one TMF request allowed to be outstanding at
300 * a time and the TMF routines perform their own allocation
301 * tracking using the standard state flags.
303 mpt->tmf_req->state = REQ_STATE_FREE;
307 * The rest of this is CAM foo, for which we need to drop our lock
311 if (mpt_spawn_recovery_thread(mpt) != 0) {
312 mpt_prt(mpt, "Unable to spawn recovery thread!\n");
318 * Create the device queue for our SIM(s).
320 devq = cam_simq_alloc(maxq);
322 mpt_prt(mpt, "Unable to allocate CAM SIMQ!\n");
328 * Construct our SIM entry.
331 mpt_sim_alloc(mpt_action, mpt_poll, "mpt", mpt, 1, maxq, devq);
332 if (mpt->sim == NULL) {
333 mpt_prt(mpt, "Unable to allocate CAM SIM!\n");
340 * Register exactly this bus.
343 if (xpt_bus_register(mpt->sim, mpt->dev, 0) != CAM_SUCCESS) {
344 mpt_prt(mpt, "Bus registration Failed!\n");
350 if (xpt_create_path(&mpt->path, NULL, cam_sim_path(mpt->sim),
351 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
352 mpt_prt(mpt, "Unable to allocate Path!\n");
360 * Only register a second bus for RAID physical
361 * devices if the controller supports RAID.
363 if (mpt->ioc_page2 == NULL || mpt->ioc_page2->MaxPhysDisks == 0) {
368 * Create a "bus" to export all hidden disks to CAM.
371 mpt_sim_alloc(mpt_action, mpt_poll, "mpt", mpt, 1, maxq, devq);
372 if (mpt->phydisk_sim == NULL) {
373 mpt_prt(mpt, "Unable to allocate Physical Disk CAM SIM!\n");
382 if (xpt_bus_register(mpt->phydisk_sim, mpt->dev, 1) !=
384 mpt_prt(mpt, "Physical Disk Bus registration Failed!\n");
390 if (xpt_create_path(&mpt->phydisk_path, NULL,
391 cam_sim_path(mpt->phydisk_sim),
392 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
393 mpt_prt(mpt, "Unable to allocate Physical Disk Path!\n");
399 mpt_lprt(mpt, MPT_PRT_DEBUG, "attached cam\n");
408 * Read FC configuration information
411 mpt_read_config_info_fc(struct mpt_softc *mpt)
413 struct sysctl_ctx_list *ctx;
414 struct sysctl_oid *tree;
415 char *topology = NULL;
418 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_FC_PORT, 0,
419 0, &mpt->mpt_fcport_page0.Header, FALSE, 5000);
423 mpt_lprt(mpt, MPT_PRT_DEBUG, "FC Port Page 0 Header: %x %x %x %x\n",
424 mpt->mpt_fcport_page0.Header.PageVersion,
425 mpt->mpt_fcport_page0.Header.PageLength,
426 mpt->mpt_fcport_page0.Header.PageNumber,
427 mpt->mpt_fcport_page0.Header.PageType);
430 rv = mpt_read_cur_cfg_page(mpt, 0, &mpt->mpt_fcport_page0.Header,
431 sizeof(mpt->mpt_fcport_page0), FALSE, 5000);
433 mpt_prt(mpt, "failed to read FC Port Page 0\n");
436 mpt2host_config_page_fc_port_0(&mpt->mpt_fcport_page0);
438 switch (mpt->mpt_fcport_page0.CurrentSpeed) {
439 case MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT:
440 mpt->mpt_fcport_speed = 1;
442 case MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT:
443 mpt->mpt_fcport_speed = 2;
445 case MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT:
446 mpt->mpt_fcport_speed = 10;
448 case MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT:
449 mpt->mpt_fcport_speed = 4;
452 mpt->mpt_fcport_speed = 0;
456 switch (mpt->mpt_fcport_page0.Flags &
457 MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK) {
458 case MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT:
459 mpt->mpt_fcport_speed = 0;
460 topology = "<NO LOOP>";
462 case MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT:
465 case MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP:
466 topology = "NL-Port";
468 case MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT:
471 case MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP:
472 topology = "FL-Port";
475 mpt->mpt_fcport_speed = 0;
480 mpt->scinfo.fc.wwnn = ((uint64_t)mpt->mpt_fcport_page0.WWNN.High << 32)
481 | mpt->mpt_fcport_page0.WWNN.Low;
482 mpt->scinfo.fc.wwpn = ((uint64_t)mpt->mpt_fcport_page0.WWPN.High << 32)
483 | mpt->mpt_fcport_page0.WWPN.Low;
484 mpt->scinfo.fc.portid = mpt->mpt_fcport_page0.PortIdentifier;
486 mpt_lprt(mpt, MPT_PRT_INFO,
487 "FC Port Page 0: Topology <%s> WWNN 0x%16jx WWPN 0x%16jx "
488 "Speed %u-Gbit\n", topology,
489 (uintmax_t)mpt->scinfo.fc.wwnn, (uintmax_t)mpt->scinfo.fc.wwpn,
490 mpt->mpt_fcport_speed);
492 ctx = device_get_sysctl_ctx(mpt->dev);
493 tree = device_get_sysctl_tree(mpt->dev);
495 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
496 "wwnn", CTLFLAG_RD, &mpt->scinfo.fc.wwnn,
497 "World Wide Node Name");
499 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
500 "wwpn", CTLFLAG_RD, &mpt->scinfo.fc.wwpn,
501 "World Wide Port Name");
508 * Set FC configuration information.
511 mpt_set_initial_config_fc(struct mpt_softc *mpt)
513 CONFIG_PAGE_FC_PORT_1 fc;
518 r = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_FC_PORT, 1, 0,
519 &fc.Header, FALSE, 5000);
521 mpt_prt(mpt, "failed to read FC page 1 header\n");
522 return (mpt_fc_reset_link(mpt, 1));
525 r = mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_NVRAM, 0,
526 &fc.Header, sizeof (fc), FALSE, 5000);
528 mpt_prt(mpt, "failed to read FC page 1\n");
529 return (mpt_fc_reset_link(mpt, 1));
531 mpt2host_config_page_fc_port_1(&fc);
534 * Check our flags to make sure we support the role we want.
540 if (fl & MPI_FCPORTPAGE1_FLAGS_PROT_FCP_INIT) {
541 role |= MPT_ROLE_INITIATOR;
543 if (fl & MPI_FCPORTPAGE1_FLAGS_PROT_FCP_TARG) {
544 role |= MPT_ROLE_TARGET;
547 fl &= ~MPI_FCPORTPAGE1_FLAGS_PROT_MASK;
549 if (mpt->do_cfg_role == 0) {
550 role = mpt->cfg_role;
552 mpt->do_cfg_role = 0;
555 if (role != mpt->cfg_role) {
556 if (mpt->cfg_role & MPT_ROLE_INITIATOR) {
557 if ((role & MPT_ROLE_INITIATOR) == 0) {
558 mpt_prt(mpt, "adding initiator role\n");
559 fl |= MPI_FCPORTPAGE1_FLAGS_PROT_FCP_INIT;
562 mpt_prt(mpt, "keeping initiator role\n");
564 } else if (role & MPT_ROLE_INITIATOR) {
565 mpt_prt(mpt, "removing initiator role\n");
568 if (mpt->cfg_role & MPT_ROLE_TARGET) {
569 if ((role & MPT_ROLE_TARGET) == 0) {
570 mpt_prt(mpt, "adding target role\n");
571 fl |= MPI_FCPORTPAGE1_FLAGS_PROT_FCP_TARG;
574 mpt_prt(mpt, "keeping target role\n");
576 } else if (role & MPT_ROLE_TARGET) {
577 mpt_prt(mpt, "removing target role\n");
580 mpt->role = mpt->cfg_role;
583 if (fl & MPI_FCPORTPAGE1_FLAGS_PROT_FCP_TARG) {
584 if ((fl & MPI_FCPORTPAGE1_FLAGS_TARGET_MODE_OXID) == 0) {
585 mpt_prt(mpt, "adding OXID option\n");
586 fl |= MPI_FCPORTPAGE1_FLAGS_TARGET_MODE_OXID;
593 host2mpt_config_page_fc_port_1(&fc);
594 r = mpt_write_cfg_page(mpt,
595 MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM, 0, &fc.Header,
596 sizeof(fc), FALSE, 5000);
598 mpt_prt(mpt, "failed to update NVRAM with changes\n");
601 mpt_prt(mpt, "NOTE: NVRAM changes will not take "
602 "effect until next reboot or IOC reset\n");
608 mptsas_sas_io_unit_pg0(struct mpt_softc *mpt, struct mptsas_portinfo *portinfo)
610 ConfigExtendedPageHeader_t hdr;
611 struct mptsas_phyinfo *phyinfo;
612 SasIOUnitPage0_t *buffer;
615 error = mpt_read_extcfg_header(mpt, MPI_SASIOUNITPAGE0_PAGEVERSION,
616 0, 0, MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT,
620 if (hdr.ExtPageLength == 0) {
625 len = hdr.ExtPageLength * 4;
626 buffer = malloc(len, M_DEVBUF, M_NOWAIT|M_ZERO);
627 if (buffer == NULL) {
632 error = mpt_read_extcfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
633 0, &hdr, buffer, len, 0, 10000);
635 free(buffer, M_DEVBUF);
639 portinfo->num_phys = buffer->NumPhys;
640 portinfo->phy_info = malloc(sizeof(*portinfo->phy_info) *
641 portinfo->num_phys, M_DEVBUF, M_NOWAIT|M_ZERO);
642 if (portinfo->phy_info == NULL) {
643 free(buffer, M_DEVBUF);
648 for (i = 0; i < portinfo->num_phys; i++) {
649 phyinfo = &portinfo->phy_info[i];
650 phyinfo->phy_num = i;
651 phyinfo->port_id = buffer->PhyData[i].Port;
652 phyinfo->negotiated_link_rate =
653 buffer->PhyData[i].NegotiatedLinkRate;
655 le16toh(buffer->PhyData[i].ControllerDevHandle);
658 free(buffer, M_DEVBUF);
664 mptsas_sas_phy_pg0(struct mpt_softc *mpt, struct mptsas_phyinfo *phy_info,
665 uint32_t form, uint32_t form_specific)
667 ConfigExtendedPageHeader_t hdr;
668 SasPhyPage0_t *buffer;
671 error = mpt_read_extcfg_header(mpt, MPI_SASPHY0_PAGEVERSION, 0, 0,
672 MPI_CONFIG_EXTPAGETYPE_SAS_PHY, &hdr,
676 if (hdr.ExtPageLength == 0) {
681 buffer = malloc(sizeof(SasPhyPage0_t), M_DEVBUF, M_NOWAIT|M_ZERO);
682 if (buffer == NULL) {
687 error = mpt_read_extcfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
688 form + form_specific, &hdr, buffer,
689 sizeof(SasPhyPage0_t), 0, 10000);
691 free(buffer, M_DEVBUF);
695 phy_info->hw_link_rate = buffer->HwLinkRate;
696 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
697 phy_info->identify.dev_handle = le16toh(buffer->OwnerDevHandle);
698 phy_info->attached.dev_handle = le16toh(buffer->AttachedDevHandle);
700 free(buffer, M_DEVBUF);
706 mptsas_sas_device_pg0(struct mpt_softc *mpt, struct mptsas_devinfo *device_info,
707 uint32_t form, uint32_t form_specific)
709 ConfigExtendedPageHeader_t hdr;
710 SasDevicePage0_t *buffer;
711 uint64_t sas_address;
714 bzero(device_info, sizeof(*device_info));
715 error = mpt_read_extcfg_header(mpt, MPI_SASDEVICE0_PAGEVERSION, 0, 0,
716 MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE,
720 if (hdr.ExtPageLength == 0) {
725 buffer = malloc(sizeof(SasDevicePage0_t), M_DEVBUF, M_NOWAIT|M_ZERO);
726 if (buffer == NULL) {
731 error = mpt_read_extcfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
732 form + form_specific, &hdr, buffer,
733 sizeof(SasDevicePage0_t), 0, 10000);
735 free(buffer, M_DEVBUF);
739 device_info->dev_handle = le16toh(buffer->DevHandle);
740 device_info->parent_dev_handle = le16toh(buffer->ParentDevHandle);
741 device_info->enclosure_handle = le16toh(buffer->EnclosureHandle);
742 device_info->slot = le16toh(buffer->Slot);
743 device_info->phy_num = buffer->PhyNum;
744 device_info->physical_port = buffer->PhysicalPort;
745 device_info->target_id = buffer->TargetID;
746 device_info->bus = buffer->Bus;
747 bcopy(&buffer->SASAddress, &sas_address, sizeof(uint64_t));
748 device_info->sas_address = le64toh(sas_address);
749 device_info->device_info = le32toh(buffer->DeviceInfo);
751 free(buffer, M_DEVBUF);
757 * Read SAS configuration information. Nothing to do yet.
760 mpt_read_config_info_sas(struct mpt_softc *mpt)
762 struct mptsas_portinfo *portinfo;
763 struct mptsas_phyinfo *phyinfo;
766 portinfo = malloc(sizeof(*portinfo), M_DEVBUF, M_NOWAIT|M_ZERO);
767 if (portinfo == NULL)
770 error = mptsas_sas_io_unit_pg0(mpt, portinfo);
772 free(portinfo, M_DEVBUF);
776 for (i = 0; i < portinfo->num_phys; i++) {
777 phyinfo = &portinfo->phy_info[i];
778 error = mptsas_sas_phy_pg0(mpt, phyinfo,
779 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
780 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
783 error = mptsas_sas_device_pg0(mpt, &phyinfo->identify,
784 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
785 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
789 phyinfo->identify.phy_num = phyinfo->phy_num = i;
790 if (phyinfo->attached.dev_handle)
791 error = mptsas_sas_device_pg0(mpt,
793 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
794 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
795 phyinfo->attached.dev_handle);
799 mpt->sas_portinfo = portinfo;
804 mptsas_set_sata_wc(struct mpt_softc *mpt, struct mptsas_devinfo *devinfo,
807 SataPassthroughRequest_t *pass;
811 req = mpt_get_request(mpt, 0);
815 pass = req->req_vbuf;
816 bzero(pass, sizeof(SataPassthroughRequest_t));
817 pass->Function = MPI_FUNCTION_SATA_PASSTHROUGH;
818 pass->TargetID = devinfo->target_id;
819 pass->Bus = devinfo->bus;
820 pass->PassthroughFlags = 0;
821 pass->ConnectionRate = MPI_SATA_PT_REQ_CONNECT_RATE_NEGOTIATED;
822 pass->DataLength = 0;
823 pass->MsgContext = htole32(req->index | sata_pass_handler_id);
824 pass->CommandFIS[0] = 0x27;
825 pass->CommandFIS[1] = 0x80;
826 pass->CommandFIS[2] = 0xef;
827 pass->CommandFIS[3] = (enabled) ? 0x02 : 0x82;
828 pass->CommandFIS[7] = 0x40;
829 pass->CommandFIS[15] = 0x08;
831 mpt_check_doorbell(mpt);
832 mpt_send_cmd(mpt, req);
833 error = mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE, 0,
836 mpt_free_request(mpt, req);
837 printf("error %d sending passthrough\n", error);
841 status = le16toh(req->IOCStatus);
842 if (status != MPI_IOCSTATUS_SUCCESS) {
843 mpt_free_request(mpt, req);
844 printf("IOCSTATUS %d\n", status);
848 mpt_free_request(mpt, req);
852 * Set SAS configuration information. Nothing to do yet.
855 mpt_set_initial_config_sas(struct mpt_softc *mpt)
857 struct mptsas_phyinfo *phyinfo;
860 if ((mpt_enable_sata_wc != -1) && (mpt->sas_portinfo != NULL)) {
861 for (i = 0; i < mpt->sas_portinfo->num_phys; i++) {
862 phyinfo = &mpt->sas_portinfo->phy_info[i];
863 if (phyinfo->attached.dev_handle == 0)
865 if ((phyinfo->attached.device_info &
866 MPI_SAS_DEVICE_INFO_SATA_DEVICE) == 0)
869 device_printf(mpt->dev,
870 "%sabling SATA WC on phy %d\n",
871 (mpt_enable_sata_wc) ? "En" : "Dis", i);
872 mptsas_set_sata_wc(mpt, &phyinfo->attached,
881 mpt_sata_pass_reply_handler(struct mpt_softc *mpt, request_t *req,
882 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
886 if (reply_frame != NULL) {
887 req->IOCStatus = le16toh(reply_frame->IOCStatus);
889 req->state &= ~REQ_STATE_QUEUED;
890 req->state |= REQ_STATE_DONE;
891 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
892 if ((req->state & REQ_STATE_NEED_WAKEUP) != 0) {
894 } else if ((req->state & REQ_STATE_TIMEDOUT) != 0) {
896 * Whew- we can free this request (late completion)
898 mpt_free_request(mpt, req);
906 * Read SCSI configuration information
909 mpt_read_config_info_spi(struct mpt_softc *mpt)
913 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_SCSI_PORT, 0, 0,
914 &mpt->mpt_port_page0.Header, FALSE, 5000);
918 mpt_lprt(mpt, MPT_PRT_DEBUG, "SPI Port Page 0 Header: %x %x %x %x\n",
919 mpt->mpt_port_page0.Header.PageVersion,
920 mpt->mpt_port_page0.Header.PageLength,
921 mpt->mpt_port_page0.Header.PageNumber,
922 mpt->mpt_port_page0.Header.PageType);
924 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_SCSI_PORT, 1, 0,
925 &mpt->mpt_port_page1.Header, FALSE, 5000);
929 mpt_lprt(mpt, MPT_PRT_DEBUG, "SPI Port Page 1 Header: %x %x %x %x\n",
930 mpt->mpt_port_page1.Header.PageVersion,
931 mpt->mpt_port_page1.Header.PageLength,
932 mpt->mpt_port_page1.Header.PageNumber,
933 mpt->mpt_port_page1.Header.PageType);
935 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_SCSI_PORT, 2, 0,
936 &mpt->mpt_port_page2.Header, FALSE, 5000);
940 mpt_lprt(mpt, MPT_PRT_DEBUG, "SPI Port Page 2 Header: %x %x %x %x\n",
941 mpt->mpt_port_page2.Header.PageVersion,
942 mpt->mpt_port_page2.Header.PageLength,
943 mpt->mpt_port_page2.Header.PageNumber,
944 mpt->mpt_port_page2.Header.PageType);
946 for (i = 0; i < 16; i++) {
947 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_SCSI_DEVICE,
948 0, i, &mpt->mpt_dev_page0[i].Header, FALSE, 5000);
952 mpt_lprt(mpt, MPT_PRT_DEBUG,
953 "SPI Target %d Device Page 0 Header: %x %x %x %x\n", i,
954 mpt->mpt_dev_page0[i].Header.PageVersion,
955 mpt->mpt_dev_page0[i].Header.PageLength,
956 mpt->mpt_dev_page0[i].Header.PageNumber,
957 mpt->mpt_dev_page0[i].Header.PageType);
959 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_SCSI_DEVICE,
960 1, i, &mpt->mpt_dev_page1[i].Header, FALSE, 5000);
964 mpt_lprt(mpt, MPT_PRT_DEBUG,
965 "SPI Target %d Device Page 1 Header: %x %x %x %x\n", i,
966 mpt->mpt_dev_page1[i].Header.PageVersion,
967 mpt->mpt_dev_page1[i].Header.PageLength,
968 mpt->mpt_dev_page1[i].Header.PageNumber,
969 mpt->mpt_dev_page1[i].Header.PageType);
973 * At this point, we don't *have* to fail. As long as we have
974 * valid config header information, we can (barely) lurch
978 rv = mpt_read_cur_cfg_page(mpt, 0, &mpt->mpt_port_page0.Header,
979 sizeof(mpt->mpt_port_page0), FALSE, 5000);
981 mpt_prt(mpt, "failed to read SPI Port Page 0\n");
983 mpt2host_config_page_scsi_port_0(&mpt->mpt_port_page0);
984 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
985 "SPI Port Page 0: Capabilities %x PhysicalInterface %x\n",
986 mpt->mpt_port_page0.Capabilities,
987 mpt->mpt_port_page0.PhysicalInterface);
990 rv = mpt_read_cur_cfg_page(mpt, 0, &mpt->mpt_port_page1.Header,
991 sizeof(mpt->mpt_port_page1), FALSE, 5000);
993 mpt_prt(mpt, "failed to read SPI Port Page 1\n");
995 mpt2host_config_page_scsi_port_1(&mpt->mpt_port_page1);
996 mpt_lprt(mpt, MPT_PRT_DEBUG,
997 "SPI Port Page 1: Configuration %x OnBusTimerValue %x\n",
998 mpt->mpt_port_page1.Configuration,
999 mpt->mpt_port_page1.OnBusTimerValue);
1002 rv = mpt_read_cur_cfg_page(mpt, 0, &mpt->mpt_port_page2.Header,
1003 sizeof(mpt->mpt_port_page2), FALSE, 5000);
1005 mpt_prt(mpt, "failed to read SPI Port Page 2\n");
1007 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
1008 "Port Page 2: Flags %x Settings %x\n",
1009 mpt->mpt_port_page2.PortFlags,
1010 mpt->mpt_port_page2.PortSettings);
1011 mpt2host_config_page_scsi_port_2(&mpt->mpt_port_page2);
1012 for (i = 0; i < 16; i++) {
1013 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
1014 " Port Page 2 Tgt %d: timo %x SF %x Flags %x\n",
1015 i, mpt->mpt_port_page2.DeviceSettings[i].Timeout,
1016 mpt->mpt_port_page2.DeviceSettings[i].SyncFactor,
1017 mpt->mpt_port_page2.DeviceSettings[i].DeviceFlags);
1021 for (i = 0; i < 16; i++) {
1022 rv = mpt_read_cur_cfg_page(mpt, i,
1023 &mpt->mpt_dev_page0[i].Header, sizeof(*mpt->mpt_dev_page0),
1027 "cannot read SPI Target %d Device Page 0\n", i);
1030 mpt2host_config_page_scsi_device_0(&mpt->mpt_dev_page0[i]);
1031 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
1032 "target %d page 0: Negotiated Params %x Information %x\n",
1033 i, mpt->mpt_dev_page0[i].NegotiatedParameters,
1034 mpt->mpt_dev_page0[i].Information);
1036 rv = mpt_read_cur_cfg_page(mpt, i,
1037 &mpt->mpt_dev_page1[i].Header, sizeof(*mpt->mpt_dev_page1),
1041 "cannot read SPI Target %d Device Page 1\n", i);
1044 mpt2host_config_page_scsi_device_1(&mpt->mpt_dev_page1[i]);
1045 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
1046 "target %d page 1: Requested Params %x Configuration %x\n",
1047 i, mpt->mpt_dev_page1[i].RequestedParameters,
1048 mpt->mpt_dev_page1[i].Configuration);
1054 * Validate SPI configuration information.
1056 * In particular, validate SPI Port Page 1.
1059 mpt_set_initial_config_spi(struct mpt_softc *mpt)
1061 int error, i, pp1val;
1063 mpt->mpt_disc_enable = 0xff;
1064 mpt->mpt_tag_enable = 0;
1066 pp1val = ((1 << mpt->mpt_ini_id) <<
1067 MPI_SCSIPORTPAGE1_CFG_SHIFT_PORT_RESPONSE_ID) | mpt->mpt_ini_id;
1068 if (mpt->mpt_port_page1.Configuration != pp1val) {
1069 CONFIG_PAGE_SCSI_PORT_1 tmp;
1071 mpt_prt(mpt, "SPI Port Page 1 Config value bad (%x)- should "
1072 "be %x\n", mpt->mpt_port_page1.Configuration, pp1val);
1073 tmp = mpt->mpt_port_page1;
1074 tmp.Configuration = pp1val;
1075 host2mpt_config_page_scsi_port_1(&tmp);
1076 error = mpt_write_cur_cfg_page(mpt, 0,
1077 &tmp.Header, sizeof(tmp), FALSE, 5000);
1081 error = mpt_read_cur_cfg_page(mpt, 0,
1082 &tmp.Header, sizeof(tmp), FALSE, 5000);
1086 mpt2host_config_page_scsi_port_1(&tmp);
1087 if (tmp.Configuration != pp1val) {
1089 "failed to reset SPI Port Page 1 Config value\n");
1092 mpt->mpt_port_page1 = tmp;
1096 * The purpose of this exercise is to get
1097 * all targets back to async/narrow.
1099 * We skip this step if the BIOS has already negotiated
1100 * speeds with the targets.
1102 i = mpt->mpt_port_page2.PortSettings &
1103 MPI_SCSIPORTPAGE2_PORT_MASK_NEGO_MASTER_SETTINGS;
1104 if (i == MPI_SCSIPORTPAGE2_PORT_ALL_MASTER_SETTINGS) {
1105 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
1106 "honoring BIOS transfer negotiations\n");
1108 for (i = 0; i < 16; i++) {
1109 mpt->mpt_dev_page1[i].RequestedParameters = 0;
1110 mpt->mpt_dev_page1[i].Configuration = 0;
1111 (void) mpt_update_spi_config(mpt, i);
1118 mpt_cam_enable(struct mpt_softc *mpt)
1126 if (mpt_read_config_info_fc(mpt)) {
1129 if (mpt_set_initial_config_fc(mpt)) {
1132 } else if (mpt->is_sas) {
1133 if (mpt_read_config_info_sas(mpt)) {
1136 if (mpt_set_initial_config_sas(mpt)) {
1139 } else if (mpt->is_spi) {
1140 if (mpt_read_config_info_spi(mpt)) {
1143 if (mpt_set_initial_config_spi(mpt)) {
1155 mpt_cam_ready(struct mpt_softc *mpt)
1159 * If we're in target mode, hang out resources now
1160 * so we don't cause the world to hang talking to us.
1162 if (mpt->is_fc && (mpt->role & MPT_ROLE_TARGET)) {
1164 * Try to add some target command resources
1167 if (mpt_add_target_commands(mpt) == FALSE) {
1168 mpt_prt(mpt, "failed to add target commands\n");
1176 mpt_cam_detach(struct mpt_softc *mpt)
1178 mpt_handler_t handler;
1182 mpt_terminate_recovery_thread(mpt);
1184 handler.reply_handler = mpt_scsi_reply_handler;
1185 mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler,
1186 scsi_io_handler_id);
1187 handler.reply_handler = mpt_scsi_tmf_reply_handler;
1188 mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler,
1189 scsi_tmf_handler_id);
1190 handler.reply_handler = mpt_fc_els_reply_handler;
1191 mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler,
1193 handler.reply_handler = mpt_scsi_tgt_reply_handler;
1194 mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler,
1195 mpt->scsi_tgt_handler_id);
1196 handler.reply_handler = mpt_sata_pass_reply_handler;
1197 mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler,
1198 sata_pass_handler_id);
1200 if (mpt->tmf_req != NULL) {
1201 mpt->tmf_req->state = REQ_STATE_ALLOCATED;
1202 mpt_free_request(mpt, mpt->tmf_req);
1203 mpt->tmf_req = NULL;
1205 if (mpt->sas_portinfo != NULL) {
1206 free(mpt->sas_portinfo, M_DEVBUF);
1207 mpt->sas_portinfo = NULL;
1210 if (mpt->sim != NULL) {
1211 xpt_free_path(mpt->path);
1212 xpt_bus_deregister(cam_sim_path(mpt->sim));
1213 cam_sim_free(mpt->sim, TRUE);
1217 if (mpt->phydisk_sim != NULL) {
1218 xpt_free_path(mpt->phydisk_path);
1219 xpt_bus_deregister(cam_sim_path(mpt->phydisk_sim));
1220 cam_sim_free(mpt->phydisk_sim, TRUE);
1221 mpt->phydisk_sim = NULL;
1226 /* This routine is used after a system crash to dump core onto the swap device.
1229 mpt_poll(struct cam_sim *sim)
1231 struct mpt_softc *mpt;
1233 mpt = (struct mpt_softc *)cam_sim_softc(sim);
1238 * Watchdog timeout routine for SCSI requests.
1241 mpt_timeout(void *arg)
1244 struct mpt_softc *mpt;
1247 ccb = (union ccb *)arg;
1248 mpt = ccb->ccb_h.ccb_mpt_ptr;
1250 MPT_LOCK_ASSERT(mpt);
1251 req = ccb->ccb_h.ccb_req_ptr;
1252 mpt_prt(mpt, "request %p:%u timed out for ccb %p (req->ccb %p)\n", req,
1253 req->serno, ccb, req->ccb);
1254 /* XXX: WHAT ARE WE TRYING TO DO HERE? */
1255 if ((req->state & REQ_STATE_QUEUED) == REQ_STATE_QUEUED) {
1256 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
1257 TAILQ_INSERT_TAIL(&mpt->request_timeout_list, req, links);
1258 req->state |= REQ_STATE_TIMEDOUT;
1259 mpt_wakeup_recovery_thread(mpt);
1264 * Callback routine from bus_dmamap_load_ccb(9) or, in simple cases, called
1267 * Takes a list of physical segments and builds the SGL for SCSI IO command
1268 * and forwards the commard to the IOC after one last check that CAM has not
1269 * aborted the transaction.
1272 mpt_execute_req_a64(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1274 request_t *req, *trq;
1277 struct mpt_softc *mpt;
1278 bus_addr_t chain_list_addr;
1279 int first_lim, seg, this_seg_lim;
1280 uint32_t addr, cur_off, flags, nxt_off, tf;
1282 MSG_REQUEST_HEADER *hdrp;
1287 req = (request_t *)arg;
1290 mpt = ccb->ccb_h.ccb_mpt_ptr;
1291 req = ccb->ccb_h.ccb_req_ptr;
1293 hdrp = req->req_vbuf;
1294 mpt_off = req->req_vbuf;
1296 if (error == 0 && ((uint32_t)nseg) >= mpt->max_seg_cnt) {
1301 switch (hdrp->Function) {
1302 case MPI_FUNCTION_SCSI_IO_REQUEST:
1303 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1305 sglp = &((PTR_MSG_SCSI_IO_REQUEST)hdrp)->SGL;
1307 case MPI_FUNCTION_TARGET_ASSIST:
1309 sglp = &((PTR_MSG_TARGET_ASSIST_REQUEST)hdrp)->SGL;
1312 mpt_prt(mpt, "bad fct 0x%x in mpt_execute_req_a64\n",
1319 if (error == 0 && ((uint32_t)nseg) >= mpt->max_seg_cnt) {
1321 mpt_prt(mpt, "segment count %d too large (max %u)\n",
1322 nseg, mpt->max_seg_cnt);
1327 if (error != EFBIG && error != ENOMEM) {
1328 mpt_prt(mpt, "mpt_execute_req_a64: err %d\n", error);
1330 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
1332 mpt_freeze_ccb(ccb);
1333 if (error == EFBIG) {
1334 status = CAM_REQ_TOO_BIG;
1335 } else if (error == ENOMEM) {
1336 if (mpt->outofbeer == 0) {
1338 xpt_freeze_simq(mpt->sim, 1);
1339 mpt_lprt(mpt, MPT_PRT_DEBUG,
1342 status = CAM_REQUEUE_REQ;
1344 status = CAM_REQ_CMP_ERR;
1346 mpt_set_ccb_status(ccb, status);
1348 if (hdrp->Function == MPI_FUNCTION_TARGET_ASSIST) {
1349 request_t *cmd_req =
1350 MPT_TAG_2_REQ(mpt, ccb->csio.tag_id);
1351 MPT_TGT_STATE(mpt, cmd_req)->state = TGT_STATE_IN_CAM;
1352 MPT_TGT_STATE(mpt, cmd_req)->ccb = NULL;
1353 MPT_TGT_STATE(mpt, cmd_req)->req = NULL;
1355 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1356 KASSERT(ccb->ccb_h.status, ("zero ccb sts at %d", __LINE__));
1358 mpt_free_request(mpt, req);
1363 * No data to transfer?
1364 * Just make a single simple SGL with zero length.
1367 if (mpt->verbose >= MPT_PRT_DEBUG) {
1368 int tidx = ((char *)sglp) - mpt_off;
1369 memset(&mpt_off[tidx], 0xff, MPT_REQUEST_AREA - tidx);
1373 SGE_SIMPLE32 *se1 = (SGE_SIMPLE32 *) sglp;
1374 MPI_pSGE_SET_FLAGS(se1,
1375 (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
1376 MPI_SGE_FLAGS_SIMPLE_ELEMENT | MPI_SGE_FLAGS_END_OF_LIST));
1377 se1->FlagsLength = htole32(se1->FlagsLength);
1382 flags = MPI_SGE_FLAGS_SIMPLE_ELEMENT | MPI_SGE_FLAGS_64_BIT_ADDRESSING;
1384 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1385 flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
1388 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1389 flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
1393 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1394 bus_dmasync_op_t op;
1396 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1397 op = BUS_DMASYNC_PREREAD;
1399 op = BUS_DMASYNC_PREWRITE;
1402 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1403 op = BUS_DMASYNC_PREWRITE;
1405 op = BUS_DMASYNC_PREREAD;
1408 bus_dmamap_sync(mpt->buffer_dmat, req->dmap, op);
1412 * Okay, fill in what we can at the end of the command frame.
1413 * If we have up to MPT_NSGL_FIRST, we can fit them all into
1414 * the command frame.
1416 * Otherwise, we fill up through MPT_NSGL_FIRST less one
1417 * SIMPLE64 pointers and start doing CHAIN64 entries after
1421 if (nseg < MPT_NSGL_FIRST(mpt)) {
1425 * Leave room for CHAIN element
1427 first_lim = MPT_NSGL_FIRST(mpt) - 1;
1430 se = (SGE_SIMPLE64 *) sglp;
1431 for (seg = 0; seg < first_lim; seg++, se++, dm_segs++) {
1433 memset(se, 0, sizeof (*se));
1434 MPI_pSGE_SET_LENGTH(se, dm_segs->ds_len);
1435 se->Address.Low = htole32(dm_segs->ds_addr & 0xffffffff);
1436 if (sizeof(bus_addr_t) > 4) {
1437 addr = ((uint64_t)dm_segs->ds_addr) >> 32;
1438 /* SAS1078 36GB limitation WAR */
1439 if (mpt->is_1078 && (((uint64_t)dm_segs->ds_addr +
1440 MPI_SGE_LENGTH(se->FlagsLength)) >> 32) == 9) {
1442 tf |= MPI_SGE_FLAGS_LOCAL_ADDRESS;
1444 se->Address.High = htole32(addr);
1446 if (seg == first_lim - 1) {
1447 tf |= MPI_SGE_FLAGS_LAST_ELEMENT;
1449 if (seg == nseg - 1) {
1450 tf |= MPI_SGE_FLAGS_END_OF_LIST |
1451 MPI_SGE_FLAGS_END_OF_BUFFER;
1453 MPI_pSGE_SET_FLAGS(se, tf);
1454 se->FlagsLength = htole32(se->FlagsLength);
1462 * Tell the IOC where to find the first chain element.
1464 hdrp->ChainOffset = ((char *)se - (char *)hdrp) >> 2;
1465 nxt_off = MPT_RQSL(mpt);
1469 * Make up the rest of the data segments out of a chain element
1470 * (contained in the current request frame) which points to
1471 * SIMPLE64 elements in the next request frame, possibly ending
1472 * with *another* chain element (if there's more).
1474 while (seg < nseg) {
1476 * Point to the chain descriptor. Note that the chain
1477 * descriptor is at the end of the *previous* list (whether
1480 ce = (SGE_CHAIN64 *) se;
1483 * Before we change our current pointer, make sure we won't
1484 * overflow the request area with this frame. Note that we
1485 * test against 'greater than' here as it's okay in this case
1486 * to have next offset be just outside the request area.
1488 if ((nxt_off + MPT_RQSL(mpt)) > MPT_REQUEST_AREA) {
1489 nxt_off = MPT_REQUEST_AREA;
1494 * Set our SGE element pointer to the beginning of the chain
1495 * list and update our next chain list offset.
1497 se = (SGE_SIMPLE64 *) &mpt_off[nxt_off];
1499 nxt_off += MPT_RQSL(mpt);
1502 * Now initialize the chain descriptor.
1504 memset(ce, 0, sizeof (*ce));
1507 * Get the physical address of the chain list.
1509 chain_list_addr = trq->req_pbuf;
1510 chain_list_addr += cur_off;
1511 if (sizeof (bus_addr_t) > 4) {
1513 htole32(((uint64_t)chain_list_addr) >> 32);
1515 ce->Address.Low = htole32(chain_list_addr & 0xffffffff);
1516 ce->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT |
1517 MPI_SGE_FLAGS_64_BIT_ADDRESSING;
1520 * If we have more than a frame's worth of segments left,
1521 * set up the chain list to have the last element be another
1524 if ((nseg - seg) > MPT_NSGL(mpt)) {
1525 this_seg_lim = seg + MPT_NSGL(mpt) - 1;
1527 * The length of the chain is the length in bytes of the
1528 * number of segments plus the next chain element.
1530 * The next chain descriptor offset is the length,
1531 * in words, of the number of segments.
1533 ce->Length = (this_seg_lim - seg) *
1534 sizeof (SGE_SIMPLE64);
1535 ce->NextChainOffset = ce->Length >> 2;
1536 ce->Length += sizeof (SGE_CHAIN64);
1538 this_seg_lim = nseg;
1539 ce->Length = (this_seg_lim - seg) *
1540 sizeof (SGE_SIMPLE64);
1542 ce->Length = htole16(ce->Length);
1545 * Fill in the chain list SGE elements with our segment data.
1547 * If we're the last element in this chain list, set the last
1548 * element flag. If we're the completely last element period,
1549 * set the end of list and end of buffer flags.
1551 while (seg < this_seg_lim) {
1553 memset(se, 0, sizeof (*se));
1554 MPI_pSGE_SET_LENGTH(se, dm_segs->ds_len);
1555 se->Address.Low = htole32(dm_segs->ds_addr &
1557 if (sizeof (bus_addr_t) > 4) {
1558 addr = ((uint64_t)dm_segs->ds_addr) >> 32;
1559 /* SAS1078 36GB limitation WAR */
1561 (((uint64_t)dm_segs->ds_addr +
1562 MPI_SGE_LENGTH(se->FlagsLength)) >>
1565 tf |= MPI_SGE_FLAGS_LOCAL_ADDRESS;
1567 se->Address.High = htole32(addr);
1569 if (seg == this_seg_lim - 1) {
1570 tf |= MPI_SGE_FLAGS_LAST_ELEMENT;
1572 if (seg == nseg - 1) {
1573 tf |= MPI_SGE_FLAGS_END_OF_LIST |
1574 MPI_SGE_FLAGS_END_OF_BUFFER;
1576 MPI_pSGE_SET_FLAGS(se, tf);
1577 se->FlagsLength = htole32(se->FlagsLength);
1585 * If we have more segments to do and we've used up all of
1586 * the space in a request area, go allocate another one
1587 * and chain to that.
1589 if (seg < nseg && nxt_off >= MPT_REQUEST_AREA) {
1592 nrq = mpt_get_request(mpt, FALSE);
1600 * Append the new request area on the tail of our list.
1602 if ((trq = req->chain) == NULL) {
1605 while (trq->chain != NULL) {
1611 mpt_off = trq->req_vbuf;
1612 if (mpt->verbose >= MPT_PRT_DEBUG) {
1613 memset(mpt_off, 0xff, MPT_REQUEST_AREA);
1621 * Last time we need to check if this CCB needs to be aborted.
1623 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
1624 if (hdrp->Function == MPI_FUNCTION_TARGET_ASSIST) {
1625 request_t *cmd_req =
1626 MPT_TAG_2_REQ(mpt, ccb->csio.tag_id);
1627 MPT_TGT_STATE(mpt, cmd_req)->state = TGT_STATE_IN_CAM;
1628 MPT_TGT_STATE(mpt, cmd_req)->ccb = NULL;
1629 MPT_TGT_STATE(mpt, cmd_req)->req = NULL;
1632 "mpt_execute_req_a64: I/O cancelled (status 0x%x)\n",
1633 ccb->ccb_h.status & CAM_STATUS_MASK);
1635 bus_dmamap_unload(mpt->buffer_dmat, req->dmap);
1637 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1638 KASSERT(ccb->ccb_h.status, ("zero ccb sts at %d", __LINE__));
1640 mpt_free_request(mpt, req);
1644 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1645 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
1646 mpt_req_timeout(req, SBT_1MS * ccb->ccb_h.timeout,
1649 if (mpt->verbose > MPT_PRT_DEBUG) {
1651 mpt_print_request(req->req_vbuf);
1652 for (trq = req->chain; trq; trq = trq->chain) {
1653 printf(" Additional Chain Area %d\n", nc++);
1654 mpt_dump_sgl(trq->req_vbuf, 0);
1658 if (hdrp->Function == MPI_FUNCTION_TARGET_ASSIST) {
1659 request_t *cmd_req = MPT_TAG_2_REQ(mpt, ccb->csio.tag_id);
1660 mpt_tgt_state_t *tgt = MPT_TGT_STATE(mpt, cmd_req);
1661 #ifdef WE_TRUST_AUTO_GOOD_STATUS
1662 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) &&
1663 csio->scsi_status == SCSI_STATUS_OK && tgt->resid == 0) {
1664 tgt->state = TGT_STATE_MOVING_DATA_AND_STATUS;
1666 tgt->state = TGT_STATE_MOVING_DATA;
1669 tgt->state = TGT_STATE_MOVING_DATA;
1672 mpt_send_cmd(mpt, req);
1676 mpt_execute_req(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1678 request_t *req, *trq;
1681 struct mpt_softc *mpt;
1683 uint32_t flags, nxt_off;
1685 MSG_REQUEST_HEADER *hdrp;
1690 req = (request_t *)arg;
1693 mpt = ccb->ccb_h.ccb_mpt_ptr;
1694 req = ccb->ccb_h.ccb_req_ptr;
1696 hdrp = req->req_vbuf;
1697 mpt_off = req->req_vbuf;
1699 if (error == 0 && ((uint32_t)nseg) >= mpt->max_seg_cnt) {
1704 switch (hdrp->Function) {
1705 case MPI_FUNCTION_SCSI_IO_REQUEST:
1706 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1707 sglp = &((PTR_MSG_SCSI_IO_REQUEST)hdrp)->SGL;
1709 case MPI_FUNCTION_TARGET_ASSIST:
1711 sglp = &((PTR_MSG_TARGET_ASSIST_REQUEST)hdrp)->SGL;
1714 mpt_prt(mpt, "bad fct 0x%x in mpt_execute_req\n",
1721 if (error == 0 && ((uint32_t)nseg) >= mpt->max_seg_cnt) {
1723 mpt_prt(mpt, "segment count %d too large (max %u)\n",
1724 nseg, mpt->max_seg_cnt);
1729 if (error != EFBIG && error != ENOMEM) {
1730 mpt_prt(mpt, "mpt_execute_req: err %d\n", error);
1732 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
1734 mpt_freeze_ccb(ccb);
1735 if (error == EFBIG) {
1736 status = CAM_REQ_TOO_BIG;
1737 } else if (error == ENOMEM) {
1738 if (mpt->outofbeer == 0) {
1740 xpt_freeze_simq(mpt->sim, 1);
1741 mpt_lprt(mpt, MPT_PRT_DEBUG,
1744 status = CAM_REQUEUE_REQ;
1746 status = CAM_REQ_CMP_ERR;
1748 mpt_set_ccb_status(ccb, status);
1750 if (hdrp->Function == MPI_FUNCTION_TARGET_ASSIST) {
1751 request_t *cmd_req =
1752 MPT_TAG_2_REQ(mpt, ccb->csio.tag_id);
1753 MPT_TGT_STATE(mpt, cmd_req)->state = TGT_STATE_IN_CAM;
1754 MPT_TGT_STATE(mpt, cmd_req)->ccb = NULL;
1755 MPT_TGT_STATE(mpt, cmd_req)->req = NULL;
1757 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1758 KASSERT(ccb->ccb_h.status, ("zero ccb sts at %d", __LINE__));
1760 mpt_free_request(mpt, req);
1765 * No data to transfer?
1766 * Just make a single simple SGL with zero length.
1769 if (mpt->verbose >= MPT_PRT_DEBUG) {
1770 int tidx = ((char *)sglp) - mpt_off;
1771 memset(&mpt_off[tidx], 0xff, MPT_REQUEST_AREA - tidx);
1775 SGE_SIMPLE32 *se1 = (SGE_SIMPLE32 *) sglp;
1776 MPI_pSGE_SET_FLAGS(se1,
1777 (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
1778 MPI_SGE_FLAGS_SIMPLE_ELEMENT | MPI_SGE_FLAGS_END_OF_LIST));
1779 se1->FlagsLength = htole32(se1->FlagsLength);
1784 flags = MPI_SGE_FLAGS_SIMPLE_ELEMENT;
1786 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1787 flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
1790 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1791 flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
1795 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1796 bus_dmasync_op_t op;
1798 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1799 op = BUS_DMASYNC_PREREAD;
1801 op = BUS_DMASYNC_PREWRITE;
1804 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1805 op = BUS_DMASYNC_PREWRITE;
1807 op = BUS_DMASYNC_PREREAD;
1810 bus_dmamap_sync(mpt->buffer_dmat, req->dmap, op);
1814 * Okay, fill in what we can at the end of the command frame.
1815 * If we have up to MPT_NSGL_FIRST, we can fit them all into
1816 * the command frame.
1818 * Otherwise, we fill up through MPT_NSGL_FIRST less one
1819 * SIMPLE32 pointers and start doing CHAIN32 entries after
1823 if (nseg < MPT_NSGL_FIRST(mpt)) {
1827 * Leave room for CHAIN element
1829 first_lim = MPT_NSGL_FIRST(mpt) - 1;
1832 se = (SGE_SIMPLE32 *) sglp;
1833 for (seg = 0; seg < first_lim; seg++, se++, dm_segs++) {
1836 memset(se, 0,sizeof (*se));
1837 se->Address = htole32(dm_segs->ds_addr);
1839 MPI_pSGE_SET_LENGTH(se, dm_segs->ds_len);
1841 if (seg == first_lim - 1) {
1842 tf |= MPI_SGE_FLAGS_LAST_ELEMENT;
1844 if (seg == nseg - 1) {
1845 tf |= MPI_SGE_FLAGS_END_OF_LIST |
1846 MPI_SGE_FLAGS_END_OF_BUFFER;
1848 MPI_pSGE_SET_FLAGS(se, tf);
1849 se->FlagsLength = htole32(se->FlagsLength);
1857 * Tell the IOC where to find the first chain element.
1859 hdrp->ChainOffset = ((char *)se - (char *)hdrp) >> 2;
1860 nxt_off = MPT_RQSL(mpt);
1864 * Make up the rest of the data segments out of a chain element
1865 * (contained in the current request frame) which points to
1866 * SIMPLE32 elements in the next request frame, possibly ending
1867 * with *another* chain element (if there's more).
1869 while (seg < nseg) {
1871 uint32_t tf, cur_off;
1872 bus_addr_t chain_list_addr;
1875 * Point to the chain descriptor. Note that the chain
1876 * descriptor is at the end of the *previous* list (whether
1879 ce = (SGE_CHAIN32 *) se;
1882 * Before we change our current pointer, make sure we won't
1883 * overflow the request area with this frame. Note that we
1884 * test against 'greater than' here as it's okay in this case
1885 * to have next offset be just outside the request area.
1887 if ((nxt_off + MPT_RQSL(mpt)) > MPT_REQUEST_AREA) {
1888 nxt_off = MPT_REQUEST_AREA;
1893 * Set our SGE element pointer to the beginning of the chain
1894 * list and update our next chain list offset.
1896 se = (SGE_SIMPLE32 *) &mpt_off[nxt_off];
1898 nxt_off += MPT_RQSL(mpt);
1901 * Now initialize the chain descriptor.
1903 memset(ce, 0, sizeof (*ce));
1906 * Get the physical address of the chain list.
1908 chain_list_addr = trq->req_pbuf;
1909 chain_list_addr += cur_off;
1913 ce->Address = htole32(chain_list_addr);
1914 ce->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
1918 * If we have more than a frame's worth of segments left,
1919 * set up the chain list to have the last element be another
1922 if ((nseg - seg) > MPT_NSGL(mpt)) {
1923 this_seg_lim = seg + MPT_NSGL(mpt) - 1;
1925 * The length of the chain is the length in bytes of the
1926 * number of segments plus the next chain element.
1928 * The next chain descriptor offset is the length,
1929 * in words, of the number of segments.
1931 ce->Length = (this_seg_lim - seg) *
1932 sizeof (SGE_SIMPLE32);
1933 ce->NextChainOffset = ce->Length >> 2;
1934 ce->Length += sizeof (SGE_CHAIN32);
1936 this_seg_lim = nseg;
1937 ce->Length = (this_seg_lim - seg) *
1938 sizeof (SGE_SIMPLE32);
1940 ce->Length = htole16(ce->Length);
1943 * Fill in the chain list SGE elements with our segment data.
1945 * If we're the last element in this chain list, set the last
1946 * element flag. If we're the completely last element period,
1947 * set the end of list and end of buffer flags.
1949 while (seg < this_seg_lim) {
1950 memset(se, 0, sizeof (*se));
1951 se->Address = htole32(dm_segs->ds_addr);
1953 MPI_pSGE_SET_LENGTH(se, dm_segs->ds_len);
1955 if (seg == this_seg_lim - 1) {
1956 tf |= MPI_SGE_FLAGS_LAST_ELEMENT;
1958 if (seg == nseg - 1) {
1959 tf |= MPI_SGE_FLAGS_END_OF_LIST |
1960 MPI_SGE_FLAGS_END_OF_BUFFER;
1962 MPI_pSGE_SET_FLAGS(se, tf);
1963 se->FlagsLength = htole32(se->FlagsLength);
1971 * If we have more segments to do and we've used up all of
1972 * the space in a request area, go allocate another one
1973 * and chain to that.
1975 if (seg < nseg && nxt_off >= MPT_REQUEST_AREA) {
1978 nrq = mpt_get_request(mpt, FALSE);
1986 * Append the new request area on the tail of our list.
1988 if ((trq = req->chain) == NULL) {
1991 while (trq->chain != NULL) {
1997 mpt_off = trq->req_vbuf;
1998 if (mpt->verbose >= MPT_PRT_DEBUG) {
1999 memset(mpt_off, 0xff, MPT_REQUEST_AREA);
2007 * Last time we need to check if this CCB needs to be aborted.
2009 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
2010 if (hdrp->Function == MPI_FUNCTION_TARGET_ASSIST) {
2011 request_t *cmd_req =
2012 MPT_TAG_2_REQ(mpt, ccb->csio.tag_id);
2013 MPT_TGT_STATE(mpt, cmd_req)->state = TGT_STATE_IN_CAM;
2014 MPT_TGT_STATE(mpt, cmd_req)->ccb = NULL;
2015 MPT_TGT_STATE(mpt, cmd_req)->req = NULL;
2018 "mpt_execute_req: I/O cancelled (status 0x%x)\n",
2019 ccb->ccb_h.status & CAM_STATUS_MASK);
2021 bus_dmamap_unload(mpt->buffer_dmat, req->dmap);
2023 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2024 KASSERT(ccb->ccb_h.status, ("zero ccb sts at %d", __LINE__));
2026 mpt_free_request(mpt, req);
2030 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2031 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
2032 mpt_req_timeout(req, SBT_1MS * ccb->ccb_h.timeout,
2035 if (mpt->verbose > MPT_PRT_DEBUG) {
2037 mpt_print_request(req->req_vbuf);
2038 for (trq = req->chain; trq; trq = trq->chain) {
2039 printf(" Additional Chain Area %d\n", nc++);
2040 mpt_dump_sgl(trq->req_vbuf, 0);
2044 if (hdrp->Function == MPI_FUNCTION_TARGET_ASSIST) {
2045 request_t *cmd_req = MPT_TAG_2_REQ(mpt, ccb->csio.tag_id);
2046 mpt_tgt_state_t *tgt = MPT_TGT_STATE(mpt, cmd_req);
2047 #ifdef WE_TRUST_AUTO_GOOD_STATUS
2048 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) &&
2049 csio->scsi_status == SCSI_STATUS_OK && tgt->resid == 0) {
2050 tgt->state = TGT_STATE_MOVING_DATA_AND_STATUS;
2052 tgt->state = TGT_STATE_MOVING_DATA;
2055 tgt->state = TGT_STATE_MOVING_DATA;
2058 mpt_send_cmd(mpt, req);
2062 mpt_start(struct cam_sim *sim, union ccb *ccb)
2065 struct mpt_softc *mpt;
2066 MSG_SCSI_IO_REQUEST *mpt_req;
2067 struct ccb_scsiio *csio = &ccb->csio;
2068 struct ccb_hdr *ccbh = &ccb->ccb_h;
2069 bus_dmamap_callback_t *cb;
2074 /* Get the pointer for the physical addapter */
2075 mpt = ccb->ccb_h.ccb_mpt_ptr;
2076 raid_passthru = (sim == mpt->phydisk_sim);
2078 if ((req = mpt_get_request(mpt, FALSE)) == NULL) {
2079 if (mpt->outofbeer == 0) {
2081 xpt_freeze_simq(mpt->sim, 1);
2082 mpt_lprt(mpt, MPT_PRT_DEBUG, "FREEZEQ\n");
2084 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2085 mpt_set_ccb_status(ccb, CAM_REQUEUE_REQ);
2090 mpt_req_not_spcl(mpt, req, "mpt_start", __LINE__);
2093 if (sizeof (bus_addr_t) > 4) {
2094 cb = mpt_execute_req_a64;
2096 cb = mpt_execute_req;
2100 * Link the ccb and the request structure so we can find
2101 * the other knowing either the request or the ccb
2104 ccb->ccb_h.ccb_req_ptr = req;
2106 /* Now we build the command for the IOC */
2107 mpt_req = req->req_vbuf;
2108 memset(mpt_req, 0, sizeof (MSG_SCSI_IO_REQUEST));
2110 mpt_req->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
2111 if (raid_passthru) {
2112 mpt_req->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
2113 if (mpt_map_physdisk(mpt, ccb, &tgt) != 0) {
2114 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2115 mpt_set_ccb_status(ccb, CAM_DEV_NOT_THERE);
2119 mpt_req->Bus = 0; /* we never set bus here */
2121 tgt = ccb->ccb_h.target_id;
2122 mpt_req->Bus = 0; /* XXX */
2125 mpt_req->SenseBufferLength =
2126 (csio->sense_len < MPT_SENSE_SIZE) ?
2127 csio->sense_len : MPT_SENSE_SIZE;
2130 * We use the message context to find the request structure when we
2131 * Get the command completion interrupt from the IOC.
2133 mpt_req->MsgContext = htole32(req->index | scsi_io_handler_id);
2135 /* Which physical device to do the I/O on */
2136 mpt_req->TargetID = tgt;
2138 be64enc(mpt_req->LUN, CAM_EXTLUN_BYTE_SWIZZLE(ccb->ccb_h.target_lun));
2140 /* Set the direction of the transfer */
2141 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
2142 mpt_req->Control = MPI_SCSIIO_CONTROL_READ;
2143 } else if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
2144 mpt_req->Control = MPI_SCSIIO_CONTROL_WRITE;
2146 mpt_req->Control = MPI_SCSIIO_CONTROL_NODATATRANSFER;
2149 if ((ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0) {
2150 switch(ccb->csio.tag_action) {
2151 case MSG_HEAD_OF_Q_TAG:
2152 mpt_req->Control |= MPI_SCSIIO_CONTROL_HEADOFQ;
2155 mpt_req->Control |= MPI_SCSIIO_CONTROL_ACAQ;
2157 case MSG_ORDERED_Q_TAG:
2158 mpt_req->Control |= MPI_SCSIIO_CONTROL_ORDEREDQ;
2160 case MSG_SIMPLE_Q_TAG:
2162 mpt_req->Control |= MPI_SCSIIO_CONTROL_SIMPLEQ;
2166 if (mpt->is_fc || mpt->is_sas) {
2167 mpt_req->Control |= MPI_SCSIIO_CONTROL_SIMPLEQ;
2169 /* XXX No such thing for a target doing packetized. */
2170 mpt_req->Control |= MPI_SCSIIO_CONTROL_UNTAGGED;
2175 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
2176 mpt_req->Control |= MPI_SCSIIO_CONTROL_NO_DISCONNECT;
2179 mpt_req->Control = htole32(mpt_req->Control);
2181 /* Copy the scsi command block into place */
2182 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
2183 bcopy(csio->cdb_io.cdb_ptr, mpt_req->CDB, csio->cdb_len);
2185 bcopy(csio->cdb_io.cdb_bytes, mpt_req->CDB, csio->cdb_len);
2188 mpt_req->CDBLength = csio->cdb_len;
2189 mpt_req->DataLength = htole32(csio->dxfer_len);
2190 mpt_req->SenseBufferLowAddr = htole32(req->sense_pbuf);
2193 * Do a *short* print here if we're set to MPT_PRT_DEBUG
2195 if (mpt->verbose == MPT_PRT_DEBUG) {
2197 mpt_prt(mpt, "mpt_start: %s op 0x%x ",
2198 (mpt_req->Function == MPI_FUNCTION_SCSI_IO_REQUEST)?
2199 "SCSI_IO_REQUEST" : "SCSI_IO_PASSTHRU", mpt_req->CDB[0]);
2200 df = mpt_req->Control & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
2201 if (df != MPI_SCSIIO_CONTROL_NODATATRANSFER) {
2202 mpt_prtc(mpt, "(%s %u byte%s ",
2203 (df == MPI_SCSIIO_CONTROL_READ)?
2204 "read" : "write", csio->dxfer_len,
2205 (csio->dxfer_len == 1)? ")" : "s)");
2207 mpt_prtc(mpt, "tgt %u lun %jx req %p:%u\n", tgt,
2208 (uintmax_t)ccb->ccb_h.target_lun, req, req->serno);
2211 error = bus_dmamap_load_ccb(mpt->buffer_dmat, req->dmap, ccb, cb,
2213 if (error == EINPROGRESS) {
2215 * So as to maintain ordering, freeze the controller queue
2216 * until our mapping is returned.
2218 xpt_freeze_simq(mpt->sim, 1);
2219 ccbh->status |= CAM_RELEASE_SIMQ;
2224 mpt_bus_reset(struct mpt_softc *mpt, target_id_t tgt, lun_id_t lun,
2231 error = mpt_scsi_send_tmf(mpt,
2232 (tgt != CAM_TARGET_WILDCARD || lun != CAM_LUN_WILDCARD) ?
2233 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET :
2234 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
2235 mpt->is_fc ? MPI_SCSITASKMGMT_MSGFLAGS_LIP_RESET_OPTION : 0,
2236 0, /* XXX How do I get the channel ID? */
2237 tgt != CAM_TARGET_WILDCARD ? tgt : 0,
2238 lun != CAM_LUN_WILDCARD ? lun : 0,
2243 * mpt_scsi_send_tmf hard resets on failure, so no
2244 * need to do so here.
2247 "mpt_bus_reset: mpt_scsi_send_tmf returned %d\n", error);
2251 /* Wait for bus reset to be processed by the IOC. */
2252 error = mpt_wait_req(mpt, mpt->tmf_req, REQ_STATE_DONE,
2253 REQ_STATE_DONE, sleep_ok, 5000);
2255 status = le16toh(mpt->tmf_req->IOCStatus);
2256 response = mpt->tmf_req->ResponseCode;
2257 mpt->tmf_req->state = REQ_STATE_FREE;
2260 mpt_prt(mpt, "mpt_bus_reset: Reset timed-out. "
2261 "Resetting controller.\n");
2262 mpt_reset(mpt, TRUE);
2266 if ((status & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
2267 mpt_prt(mpt, "mpt_bus_reset: TMF IOC Status 0x%x. "
2268 "Resetting controller.\n", status);
2269 mpt_reset(mpt, TRUE);
2273 if (response != MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED &&
2274 response != MPI_SCSITASKMGMT_RSP_TM_COMPLETE) {
2275 mpt_prt(mpt, "mpt_bus_reset: TMF Response 0x%x. "
2276 "Resetting controller.\n", response);
2277 mpt_reset(mpt, TRUE);
2284 mpt_fc_reset_link(struct mpt_softc *mpt, int dowait)
2288 PTR_MSG_FC_PRIMITIVE_SEND_REQUEST fc;
2290 req = mpt_get_request(mpt, FALSE);
2295 memset(fc, 0, sizeof(*fc));
2296 fc->SendFlags = MPI_FC_PRIM_SEND_FLAGS_RESET_LINK;
2297 fc->Function = MPI_FUNCTION_FC_PRIMITIVE_SEND;
2298 fc->MsgContext = htole32(req->index | fc_els_handler_id);
2299 mpt_send_cmd(mpt, req);
2301 r = mpt_wait_req(mpt, req, REQ_STATE_DONE,
2302 REQ_STATE_DONE, FALSE, 60 * 1000);
2304 mpt_free_request(mpt, req);
2311 mpt_cam_event(struct mpt_softc *mpt, request_t *req,
2312 MSG_EVENT_NOTIFY_REPLY *msg)
2314 uint32_t data0, data1;
2316 data0 = le32toh(msg->Data[0]);
2317 data1 = le32toh(msg->Data[1]);
2318 switch(msg->Event & 0xFF) {
2319 case MPI_EVENT_UNIT_ATTENTION:
2320 mpt_prt(mpt, "UNIT ATTENTION: Bus: 0x%02x TargetID: 0x%02x\n",
2321 (data0 >> 8) & 0xff, data0 & 0xff);
2324 case MPI_EVENT_IOC_BUS_RESET:
2325 /* We generated a bus reset */
2326 mpt_prt(mpt, "IOC Generated Bus Reset Port: %d\n",
2327 (data0 >> 8) & 0xff);
2328 xpt_async(AC_BUS_RESET, mpt->path, NULL);
2331 case MPI_EVENT_EXT_BUS_RESET:
2332 /* Someone else generated a bus reset */
2333 mpt_prt(mpt, "External Bus Reset Detected\n");
2335 * These replies don't return EventData like the MPI
2338 xpt_async(AC_BUS_RESET, mpt->path, NULL);
2341 case MPI_EVENT_RESCAN:
2346 * In general this means a device has been added to the loop.
2348 mpt_prt(mpt, "Rescan Port: %d\n", (data0 >> 8) & 0xff);
2349 if (mpt->ready == 0) {
2352 if (mpt->phydisk_sim) {
2353 pathid = cam_sim_path(mpt->phydisk_sim);
2355 pathid = cam_sim_path(mpt->sim);
2358 * Allocate a CCB, create a wildcard path for this bus,
2359 * and schedule a rescan.
2361 ccb = xpt_alloc_ccb_nowait();
2363 mpt_prt(mpt, "unable to alloc CCB for rescan\n");
2367 if (xpt_create_path(&ccb->ccb_h.path, NULL, pathid,
2368 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
2369 mpt_prt(mpt, "unable to create path for rescan\n");
2377 case MPI_EVENT_LINK_STATUS_CHANGE:
2378 mpt_prt(mpt, "Port %d: LinkState: %s\n",
2379 (data1 >> 8) & 0xff,
2380 ((data0 & 0xff) == 0)? "Failed" : "Active");
2383 case MPI_EVENT_LOOP_STATE_CHANGE:
2384 switch ((data0 >> 16) & 0xff) {
2387 "Port 0x%x: FC LinkEvent: LIP(%02x,%02x) "
2388 "(Loop Initialization)\n",
2389 (data1 >> 8) & 0xff,
2390 (data0 >> 8) & 0xff,
2392 switch ((data0 >> 8) & 0xff) {
2394 if ((data0 & 0xff) == 0xF7) {
2395 mpt_prt(mpt, "Device needs AL_PA\n");
2397 mpt_prt(mpt, "Device %02x doesn't like "
2403 if ((data0 & 0xff) == 0xF7) {
2404 mpt_prt(mpt, "Device had loop failure "
2405 "at its receiver prior to acquiring"
2408 mpt_prt(mpt, "Device %02x detected loop"
2409 " failure at its receiver\n",
2414 mpt_prt(mpt, "Device %02x requests that device "
2415 "%02x reset itself\n",
2417 (data0 >> 8) & 0xFF);
2422 mpt_prt(mpt, "Port 0x%x: FC LinkEvent: "
2423 "LPE(%02x,%02x) (Loop Port Enable)\n",
2424 (data1 >> 8) & 0xff, /* Port */
2425 (data0 >> 8) & 0xff, /* Character 3 */
2426 (data0 ) & 0xff /* Character 4 */);
2429 mpt_prt(mpt, "Port 0x%x: FC LinkEvent: "
2430 "LPB(%02x,%02x) (Loop Port Bypass)\n",
2431 (data1 >> 8) & 0xff, /* Port */
2432 (data0 >> 8) & 0xff, /* Character 3 */
2433 (data0 ) & 0xff /* Character 4 */);
2436 mpt_prt(mpt, "Port 0x%x: FC LinkEvent: Unknown "
2437 "FC event (%02x %02x %02x)\n",
2438 (data1 >> 8) & 0xff, /* Port */
2439 (data0 >> 16) & 0xff, /* Event */
2440 (data0 >> 8) & 0xff, /* Character 3 */
2441 (data0 ) & 0xff /* Character 4 */);
2445 case MPI_EVENT_LOGOUT:
2446 mpt_prt(mpt, "FC Logout Port: %d N_PortID: %02x\n",
2447 (data1 >> 8) & 0xff, data0);
2449 case MPI_EVENT_QUEUE_FULL:
2451 struct cam_sim *sim;
2452 struct cam_path *tmppath;
2453 struct ccb_relsim crs;
2454 PTR_EVENT_DATA_QUEUE_FULL pqf;
2457 pqf = (PTR_EVENT_DATA_QUEUE_FULL)msg->Data;
2458 pqf->CurrentDepth = le16toh(pqf->CurrentDepth);
2460 mpt_prt(mpt, "QUEUE FULL EVENT: Bus 0x%02x Target 0x%02x "
2462 pqf->Bus, pqf->TargetID, pqf->CurrentDepth);
2464 if (mpt->phydisk_sim && mpt_is_raid_member(mpt,
2465 pqf->TargetID) != 0) {
2466 sim = mpt->phydisk_sim;
2470 for (lun_id = 0; lun_id < MPT_MAX_LUNS; lun_id++) {
2471 if (xpt_create_path(&tmppath, NULL, cam_sim_path(sim),
2472 pqf->TargetID, lun_id) != CAM_REQ_CMP) {
2473 mpt_prt(mpt, "unable to create a path to send "
2477 xpt_setup_ccb(&crs.ccb_h, tmppath, 5);
2478 crs.ccb_h.func_code = XPT_REL_SIMQ;
2479 crs.ccb_h.flags = CAM_DEV_QFREEZE;
2480 crs.release_flags = RELSIM_ADJUST_OPENINGS;
2481 crs.openings = pqf->CurrentDepth - 1;
2482 xpt_action((union ccb *)&crs);
2483 if (crs.ccb_h.status != CAM_REQ_CMP) {
2484 mpt_prt(mpt, "XPT_REL_SIMQ failed\n");
2486 xpt_free_path(tmppath);
2490 case MPI_EVENT_IR_RESYNC_UPDATE:
2491 mpt_prt(mpt, "IR resync update %d completed\n",
2492 (data0 >> 16) & 0xff);
2494 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2497 struct cam_sim *sim;
2498 struct cam_path *tmppath;
2499 PTR_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE psdsc;
2501 psdsc = (PTR_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE)msg->Data;
2502 if (mpt->phydisk_sim && mpt_is_raid_member(mpt,
2503 psdsc->TargetID) != 0)
2504 sim = mpt->phydisk_sim;
2507 switch(psdsc->ReasonCode) {
2508 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
2509 ccb = xpt_alloc_ccb_nowait();
2512 "unable to alloc CCB for rescan\n");
2515 if (xpt_create_path(&ccb->ccb_h.path, NULL,
2516 cam_sim_path(sim), psdsc->TargetID,
2517 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
2519 "unable to create path for rescan\n");
2525 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
2526 if (xpt_create_path(&tmppath, NULL, cam_sim_path(sim),
2527 psdsc->TargetID, CAM_LUN_WILDCARD) !=
2530 "unable to create path for async event");
2533 xpt_async(AC_LOST_DEVICE, tmppath, NULL);
2534 xpt_free_path(tmppath);
2536 case MPI_EVENT_SAS_DEV_STAT_RC_CMPL_INTERNAL_DEV_RESET:
2537 case MPI_EVENT_SAS_DEV_STAT_RC_CMPL_TASK_ABORT_INTERNAL:
2538 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
2541 mpt_lprt(mpt, MPT_PRT_WARN,
2542 "SAS device status change: Bus: 0x%02x TargetID: "
2543 "0x%02x ReasonCode: 0x%02x\n", psdsc->Bus,
2544 psdsc->TargetID, psdsc->ReasonCode);
2549 case MPI_EVENT_SAS_DISCOVERY_ERROR:
2551 PTR_EVENT_DATA_DISCOVERY_ERROR pde;
2553 pde = (PTR_EVENT_DATA_DISCOVERY_ERROR)msg->Data;
2554 pde->DiscoveryStatus = le32toh(pde->DiscoveryStatus);
2555 mpt_lprt(mpt, MPT_PRT_WARN,
2556 "SAS discovery error: Port: 0x%02x Status: 0x%08x\n",
2557 pde->Port, pde->DiscoveryStatus);
2560 case MPI_EVENT_EVENT_CHANGE:
2561 case MPI_EVENT_INTEGRATED_RAID:
2563 case MPI_EVENT_LOG_ENTRY_ADDED:
2564 case MPI_EVENT_SAS_DISCOVERY:
2565 case MPI_EVENT_SAS_PHY_LINK_STATUS:
2566 case MPI_EVENT_SAS_SES:
2569 mpt_lprt(mpt, MPT_PRT_WARN, "mpt_cam_event: 0x%x\n",
2577 * Reply path for all SCSI I/O requests, called from our
2578 * interrupt handler by extracting our handler index from
2579 * the MsgContext field of the reply from the IOC.
2581 * This routine is optimized for the common case of a
2582 * completion without error. All exception handling is
2583 * offloaded to non-inlined helper routines to minimize
2587 mpt_scsi_reply_handler(struct mpt_softc *mpt, request_t *req,
2588 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
2590 MSG_SCSI_IO_REQUEST *scsi_req;
2593 if (req->state == REQ_STATE_FREE) {
2594 mpt_prt(mpt, "mpt_scsi_reply_handler: req already free\n");
2598 scsi_req = (MSG_SCSI_IO_REQUEST *)req->req_vbuf;
2601 mpt_prt(mpt, "mpt_scsi_reply_handler: req %p:%u with no ccb\n",
2606 mpt_req_untimeout(req, mpt_timeout, ccb);
2607 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2609 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
2610 bus_dmasync_op_t op;
2612 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
2613 op = BUS_DMASYNC_POSTREAD;
2615 op = BUS_DMASYNC_POSTWRITE;
2616 bus_dmamap_sync(mpt->buffer_dmat, req->dmap, op);
2617 bus_dmamap_unload(mpt->buffer_dmat, req->dmap);
2620 if (reply_frame == NULL) {
2622 * Context only reply, completion without error status.
2624 ccb->csio.resid = 0;
2625 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
2626 ccb->csio.scsi_status = SCSI_STATUS_OK;
2628 mpt_scsi_reply_frame_handler(mpt, req, reply_frame);
2631 if (mpt->outofbeer) {
2632 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
2634 mpt_lprt(mpt, MPT_PRT_DEBUG, "THAWQ\n");
2636 if (scsi_req->CDB[0] == INQUIRY && (scsi_req->CDB[1] & SI_EVPD) == 0) {
2637 struct scsi_inquiry_data *iq =
2638 (struct scsi_inquiry_data *)ccb->csio.data_ptr;
2639 if (scsi_req->Function ==
2640 MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
2642 * Fake out the device type so that only the
2643 * pass-thru device will attach.
2645 iq->device &= ~0x1F;
2646 iq->device |= T_NODEVICE;
2649 if (mpt->verbose == MPT_PRT_DEBUG) {
2650 mpt_prt(mpt, "mpt_scsi_reply_handler: %p:%u complete\n",
2653 KASSERT(ccb->ccb_h.status, ("zero ccb sts at %d", __LINE__));
2655 if ((req->state & REQ_STATE_TIMEDOUT) == 0) {
2656 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
2658 mpt_prt(mpt, "completing timedout/aborted req %p:%u\n",
2660 TAILQ_REMOVE(&mpt->request_timeout_list, req, links);
2662 KASSERT((req->state & REQ_STATE_NEED_WAKEUP) == 0,
2663 ("CCB req needed wakeup"));
2665 mpt_req_not_spcl(mpt, req, "mpt_scsi_reply_handler", __LINE__);
2667 mpt_free_request(mpt, req);
2672 mpt_scsi_tmf_reply_handler(struct mpt_softc *mpt, request_t *req,
2673 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
2675 MSG_SCSI_TASK_MGMT_REPLY *tmf_reply;
2677 KASSERT(req == mpt->tmf_req, ("TMF Reply not using mpt->tmf_req"));
2679 mpt_req_not_spcl(mpt, req, "mpt_scsi_tmf_reply_handler", __LINE__);
2681 tmf_reply = (MSG_SCSI_TASK_MGMT_REPLY *)reply_frame;
2682 /* Record IOC Status and Response Code of TMF for any waiters. */
2683 req->IOCStatus = le16toh(tmf_reply->IOCStatus);
2684 req->ResponseCode = tmf_reply->ResponseCode;
2686 mpt_lprt(mpt, MPT_PRT_DEBUG, "TMF complete: req %p:%u status 0x%x\n",
2687 req, req->serno, le16toh(tmf_reply->IOCStatus));
2688 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
2689 if ((req->state & REQ_STATE_NEED_WAKEUP) != 0) {
2690 req->state |= REQ_STATE_DONE;
2693 mpt->tmf_req->state = REQ_STATE_FREE;
2699 * XXX: Move to definitions file
2717 mpt_fc_els_send_response(struct mpt_softc *mpt, request_t *req,
2718 PTR_MSG_LINK_SERVICE_BUFFER_POST_REPLY rp, U8 length)
2721 MSG_LINK_SERVICE_RSP_REQUEST tmp;
2722 PTR_MSG_LINK_SERVICE_RSP_REQUEST rsp;
2725 * We are going to reuse the ELS request to send this response back.
2728 memset(rsp, 0, sizeof(*rsp));
2730 #ifdef USE_IMMEDIATE_LINK_DATA
2732 * Apparently the IMMEDIATE stuff doesn't seem to work.
2734 rsp->RspFlags = LINK_SERVICE_RSP_FLAGS_IMMEDIATE;
2736 rsp->RspLength = length;
2737 rsp->Function = MPI_FUNCTION_FC_LINK_SRVC_RSP;
2738 rsp->MsgContext = htole32(req->index | fc_els_handler_id);
2741 * Copy over information from the original reply frame to
2742 * it's correct place in the response.
2744 memcpy((U8 *)rsp + 0x0c, (U8 *)rp + 0x1c, 24);
2747 * And now copy back the temporary area to the original frame.
2749 memcpy(req->req_vbuf, rsp, sizeof (MSG_LINK_SERVICE_RSP_REQUEST));
2750 rsp = req->req_vbuf;
2752 #ifdef USE_IMMEDIATE_LINK_DATA
2753 memcpy((U8 *)&rsp->SGL, &((U8 *)req->req_vbuf)[MPT_RQSL(mpt)], length);
2756 PTR_SGE_SIMPLE32 se = (PTR_SGE_SIMPLE32) &rsp->SGL;
2757 bus_addr_t paddr = req->req_pbuf;
2758 paddr += MPT_RQSL(mpt);
2761 MPI_SGE_FLAGS_HOST_TO_IOC |
2762 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2763 MPI_SGE_FLAGS_LAST_ELEMENT |
2764 MPI_SGE_FLAGS_END_OF_LIST |
2765 MPI_SGE_FLAGS_END_OF_BUFFER;
2766 fl <<= MPI_SGE_FLAGS_SHIFT;
2768 se->FlagsLength = htole32(fl);
2769 se->Address = htole32((uint32_t) paddr);
2776 mpt_send_cmd(mpt, req);
2780 mpt_fc_els_reply_handler(struct mpt_softc *mpt, request_t *req,
2781 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
2783 PTR_MSG_LINK_SERVICE_BUFFER_POST_REPLY rp =
2784 (PTR_MSG_LINK_SERVICE_BUFFER_POST_REPLY) reply_frame;
2788 U16 status = le16toh(reply_frame->IOCStatus);
2791 int do_refresh = TRUE;
2794 KASSERT(mpt_req_on_free_list(mpt, req) == 0,
2795 ("fc_els_reply_handler: req %p:%u for function %x on freelist!",
2796 req, req->serno, rp->Function));
2797 if (rp->Function != MPI_FUNCTION_FC_PRIMITIVE_SEND) {
2798 mpt_req_spcl(mpt, req, "fc_els_reply_handler", __LINE__);
2800 mpt_req_not_spcl(mpt, req, "fc_els_reply_handler", __LINE__);
2803 mpt_lprt(mpt, MPT_PRT_DEBUG,
2804 "FC_ELS Complete: req %p:%u, reply %p function %x\n",
2805 req, req->serno, reply_frame, reply_frame->Function);
2807 if (status != MPI_IOCSTATUS_SUCCESS) {
2808 mpt_prt(mpt, "ELS REPLY STATUS 0x%x for Function %x\n",
2809 status, reply_frame->Function);
2810 if (status == MPI_IOCSTATUS_INVALID_STATE) {
2812 * XXX: to get around shutdown issue
2821 * If the function of a link service response, we recycle the
2822 * response to be a refresh for a new link service request.
2824 * The request pointer is bogus in this case and we have to fetch
2825 * it based upon the TransactionContext.
2827 if (rp->Function == MPI_FUNCTION_FC_LINK_SRVC_RSP) {
2828 /* Freddie Uncle Charlie Katie */
2829 /* We don't get the IOINDEX as part of the Link Svc Rsp */
2830 for (ioindex = 0; ioindex < mpt->els_cmds_allocated; ioindex++)
2831 if (mpt->els_cmd_ptrs[ioindex] == req) {
2835 KASSERT(ioindex < mpt->els_cmds_allocated,
2836 ("can't find my mommie!"));
2838 /* remove from active list as we're going to re-post it */
2839 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
2840 req->state &= ~REQ_STATE_QUEUED;
2841 req->state |= REQ_STATE_DONE;
2842 mpt_fc_post_els(mpt, req, ioindex);
2846 if (rp->Function == MPI_FUNCTION_FC_PRIMITIVE_SEND) {
2847 /* remove from active list as we're done */
2848 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
2849 req->state &= ~REQ_STATE_QUEUED;
2850 req->state |= REQ_STATE_DONE;
2851 if (req->state & REQ_STATE_TIMEDOUT) {
2852 mpt_lprt(mpt, MPT_PRT_DEBUG,
2853 "Sync Primitive Send Completed After Timeout\n");
2854 mpt_free_request(mpt, req);
2855 } else if ((req->state & REQ_STATE_NEED_WAKEUP) == 0) {
2856 mpt_lprt(mpt, MPT_PRT_DEBUG,
2857 "Async Primitive Send Complete\n");
2858 mpt_free_request(mpt, req);
2860 mpt_lprt(mpt, MPT_PRT_DEBUG,
2861 "Sync Primitive Send Complete- Waking Waiter\n");
2867 if (rp->Function != MPI_FUNCTION_FC_LINK_SRVC_BUF_POST) {
2868 mpt_prt(mpt, "unexpected ELS_REPLY: Function 0x%x Flags %x "
2869 "Length %d Message Flags %x\n", rp->Function, rp->Flags,
2870 rp->MsgLength, rp->MsgFlags);
2874 if (rp->MsgLength <= 5) {
2876 * This is just a ack of an original ELS buffer post
2878 mpt_lprt(mpt, MPT_PRT_DEBUG,
2879 "RECV'd ACK of FC_ELS buf post %p:%u\n", req, req->serno);
2884 rctl = (le32toh(rp->Rctl_Did) & MPI_FC_RCTL_MASK) >> MPI_FC_RCTL_SHIFT;
2885 type = (le32toh(rp->Type_Fctl) & MPI_FC_TYPE_MASK) >> MPI_FC_TYPE_SHIFT;
2887 elsbuf = &((U32 *)req->req_vbuf)[MPT_RQSL(mpt)/sizeof (U32)];
2888 cmd = be32toh(elsbuf[0]) >> 24;
2890 if (rp->Flags & MPI_LS_BUF_POST_REPLY_FLAG_NO_RSP_NEEDED) {
2891 mpt_lprt(mpt, MPT_PRT_ALWAYS, "ELS_REPLY: response unneeded\n");
2895 ioindex = le32toh(rp->TransactionContext);
2896 req = mpt->els_cmd_ptrs[ioindex];
2898 if (rctl == ELS && type == 1) {
2902 * Send back a PRLI ACC
2904 mpt_prt(mpt, "PRLI from 0x%08x%08x\n",
2905 le32toh(rp->Wwn.PortNameHigh),
2906 le32toh(rp->Wwn.PortNameLow));
2907 elsbuf[0] = htobe32(0x02100014);
2908 elsbuf[1] |= htobe32(0x00000100);
2909 elsbuf[4] = htobe32(0x00000002);
2910 if (mpt->role & MPT_ROLE_TARGET)
2911 elsbuf[4] |= htobe32(0x00000010);
2912 if (mpt->role & MPT_ROLE_INITIATOR)
2913 elsbuf[4] |= htobe32(0x00000020);
2914 /* remove from active list as we're done */
2915 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
2916 req->state &= ~REQ_STATE_QUEUED;
2917 req->state |= REQ_STATE_DONE;
2918 mpt_fc_els_send_response(mpt, req, rp, 20);
2922 memset(elsbuf, 0, 5 * (sizeof (U32)));
2923 elsbuf[0] = htobe32(0x02100014);
2924 elsbuf[1] = htobe32(0x08000100);
2925 mpt_prt(mpt, "PRLO from 0x%08x%08x\n",
2926 le32toh(rp->Wwn.PortNameHigh),
2927 le32toh(rp->Wwn.PortNameLow));
2928 /* remove from active list as we're done */
2929 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
2930 req->state &= ~REQ_STATE_QUEUED;
2931 req->state |= REQ_STATE_DONE;
2932 mpt_fc_els_send_response(mpt, req, rp, 20);
2936 mpt_prt(mpt, "ELS TYPE 1 COMMAND: %x\n", cmd);
2939 } else if (rctl == ABTS && type == 0) {
2940 uint16_t rx_id = le16toh(rp->Rxid);
2941 uint16_t ox_id = le16toh(rp->Oxid);
2942 mpt_tgt_state_t *tgt;
2943 request_t *tgt_req = NULL;
2948 "ELS: ABTS OX_ID 0x%x RX_ID 0x%x from 0x%08x%08x\n",
2949 ox_id, rx_id, le32toh(rp->Wwn.PortNameHigh),
2950 le32toh(rp->Wwn.PortNameLow));
2951 if (rx_id >= mpt->mpt_max_tgtcmds) {
2952 mpt_prt(mpt, "Bad RX_ID 0x%x\n", rx_id);
2953 } else if (mpt->tgt_cmd_ptrs == NULL) {
2954 mpt_prt(mpt, "No TGT CMD PTRS\n");
2956 tgt_req = mpt->tgt_cmd_ptrs[rx_id];
2958 if (tgt_req == NULL) {
2959 mpt_prt(mpt, "no back pointer for RX_ID 0x%x\n", rx_id);
2962 tgt = MPT_TGT_STATE(mpt, tgt_req);
2964 /* Check to make sure we have the correct command. */
2965 ct_id = GET_IO_INDEX(tgt->reply_desc);
2966 if (ct_id != rx_id) {
2967 mpt_lprt(mpt, MPT_PRT_ERROR, "ABORT Mismatch: "
2968 "RX_ID received=0x%x, in cmd=0x%x\n", rx_id, ct_id);
2971 if (tgt->itag != ox_id) {
2972 mpt_lprt(mpt, MPT_PRT_ERROR, "ABORT Mismatch: "
2973 "OX_ID received=0x%x, in cmd=0x%x\n", ox_id, tgt->itag);
2977 if ((ccb = tgt->ccb) != NULL) {
2978 mpt_prt(mpt, "CCB (%p): lun %jx flags %x status %x\n",
2979 ccb, (uintmax_t)ccb->ccb_h.target_lun,
2980 ccb->ccb_h.flags, ccb->ccb_h.status);
2982 mpt_prt(mpt, "target state 0x%x resid %u xfrd %u rpwrd "
2983 "%x nxfers %x\n", tgt->state, tgt->resid,
2984 tgt->bytes_xfered, tgt->reply_desc, tgt->nxfers);
2985 if (mpt_abort_target_cmd(mpt, tgt_req))
2986 mpt_prt(mpt, "unable to start TargetAbort\n");
2989 memset(elsbuf, 0, 5 * (sizeof (U32)));
2990 elsbuf[0] = htobe32(0);
2991 elsbuf[1] = htobe32((ox_id << 16) | rx_id);
2992 elsbuf[2] = htobe32(0x000ffff);
2994 * Dork with the reply frame so that the response to it
2997 rp->Rctl_Did += ((BA_ACC - ABTS) << MPI_FC_RCTL_SHIFT);
2998 /* remove from active list as we're done */
2999 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
3000 req->state &= ~REQ_STATE_QUEUED;
3001 req->state |= REQ_STATE_DONE;
3002 mpt_fc_els_send_response(mpt, req, rp, 12);
3005 mpt_prt(mpt, "ELS: RCTL %x TYPE %x CMD %x\n", rctl, type, cmd);
3007 if (do_refresh == TRUE) {
3008 /* remove from active list as we're done */
3009 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
3010 req->state &= ~REQ_STATE_QUEUED;
3011 req->state |= REQ_STATE_DONE;
3012 mpt_fc_post_els(mpt, req, ioindex);
3018 * Clean up all SCSI Initiator personality state in response
3019 * to a controller reset.
3022 mpt_cam_ioc_reset(struct mpt_softc *mpt, int type)
3026 * The pending list is already run down by
3027 * the generic handler. Perform the same
3028 * operation on the timed out request list.
3030 mpt_complete_request_chain(mpt, &mpt->request_timeout_list,
3031 MPI_IOCSTATUS_INVALID_STATE);
3034 * XXX: We need to repost ELS and Target Command Buffers?
3038 * Inform the XPT that a bus reset has occurred.
3040 xpt_async(AC_BUS_RESET, mpt->path, NULL);
3044 * Parse additional completion information in the reply
3045 * frame for SCSI I/O requests.
3048 mpt_scsi_reply_frame_handler(struct mpt_softc *mpt, request_t *req,
3049 MSG_DEFAULT_REPLY *reply_frame)
3052 MSG_SCSI_IO_REPLY *scsi_io_reply;
3056 MPT_DUMP_REPLY_FRAME(mpt, reply_frame);
3057 KASSERT(reply_frame->Function == MPI_FUNCTION_SCSI_IO_REQUEST
3058 || reply_frame->Function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH,
3059 ("MPT SCSI I/O Handler called with incorrect reply type"));
3060 KASSERT((reply_frame->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) == 0,
3061 ("MPT SCSI I/O Handler called with continuation reply"));
3063 scsi_io_reply = (MSG_SCSI_IO_REPLY *)reply_frame;
3064 ioc_status = le16toh(scsi_io_reply->IOCStatus);
3065 ioc_status &= MPI_IOCSTATUS_MASK;
3066 sstate = scsi_io_reply->SCSIState;
3070 ccb->csio.dxfer_len - le32toh(scsi_io_reply->TransferCount);
3072 if ((sstate & MPI_SCSI_STATE_AUTOSENSE_VALID) != 0
3073 && (ccb->ccb_h.flags & (CAM_SENSE_PHYS | CAM_SENSE_PTR)) == 0) {
3074 uint32_t sense_returned;
3076 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
3078 sense_returned = le32toh(scsi_io_reply->SenseCount);
3079 if (sense_returned < ccb->csio.sense_len)
3080 ccb->csio.sense_resid = ccb->csio.sense_len -
3083 ccb->csio.sense_resid = 0;
3085 bzero(&ccb->csio.sense_data, sizeof(ccb->csio.sense_data));
3086 bcopy(req->sense_vbuf, &ccb->csio.sense_data,
3087 min(ccb->csio.sense_len, sense_returned));
3090 if ((sstate & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) != 0) {
3092 * Tag messages rejected, but non-tagged retry
3095 mpt_set_tags(mpt, devinfo, MPT_QUEUE_NONE);
3099 switch(ioc_status) {
3100 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3103 * Linux driver indicates that a zero
3104 * transfer length with this error code
3105 * indicates a CRC error.
3107 * No need to swap the bytes for checking
3110 if (scsi_io_reply->TransferCount == 0) {
3111 mpt_set_ccb_status(ccb, CAM_UNCOR_PARITY);
3115 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:
3116 case MPI_IOCSTATUS_SUCCESS:
3117 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:
3118 if ((sstate & MPI_SCSI_STATE_NO_SCSI_STATUS) != 0) {
3120 * Status was never returned for this transaction.
3122 mpt_set_ccb_status(ccb, CAM_UNEXP_BUSFREE);
3123 } else if (scsi_io_reply->SCSIStatus != SCSI_STATUS_OK) {
3124 ccb->csio.scsi_status = scsi_io_reply->SCSIStatus;
3125 mpt_set_ccb_status(ccb, CAM_SCSI_STATUS_ERROR);
3126 if ((sstate & MPI_SCSI_STATE_AUTOSENSE_FAILED) != 0)
3127 mpt_set_ccb_status(ccb, CAM_AUTOSENSE_FAIL);
3128 } else if ((sstate & MPI_SCSI_STATE_RESPONSE_INFO_VALID) != 0) {
3130 /* XXX Handle SPI-Packet and FCP-2 response info. */
3131 mpt_set_ccb_status(ccb, CAM_REQ_CMP_ERR);
3133 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3135 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:
3136 mpt_set_ccb_status(ccb, CAM_DATA_RUN_ERR);
3138 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:
3139 mpt_set_ccb_status(ccb, CAM_UNCOR_PARITY);
3141 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3143 * Since selection timeouts and "device really not
3144 * there" are grouped into this error code, report
3145 * selection timeout. Selection timeouts are
3146 * typically retried before giving up on the device
3147 * whereas "device not there" errors are considered
3150 mpt_set_ccb_status(ccb, CAM_SEL_TIMEOUT);
3152 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3153 mpt_set_ccb_status(ccb, CAM_SEQUENCE_FAIL);
3155 case MPI_IOCSTATUS_SCSI_INVALID_BUS:
3156 mpt_set_ccb_status(ccb, CAM_PATH_INVALID);
3158 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:
3159 mpt_set_ccb_status(ccb, CAM_TID_INVALID);
3161 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3162 ccb->ccb_h.status = CAM_UA_TERMIO;
3164 case MPI_IOCSTATUS_INVALID_STATE:
3166 * The IOC has been reset. Emulate a bus reset.
3169 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:
3170 ccb->ccb_h.status = CAM_SCSI_BUS_RESET;
3172 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:
3173 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:
3175 * Don't clobber any timeout status that has
3176 * already been set for this transaction. We
3177 * want the SCSI layer to be able to differentiate
3178 * between the command we aborted due to timeout
3179 * and any innocent bystanders.
3181 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG)
3183 mpt_set_ccb_status(ccb, CAM_REQ_TERMIO);
3186 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
3187 mpt_set_ccb_status(ccb, CAM_RESRC_UNAVAIL);
3189 case MPI_IOCSTATUS_BUSY:
3190 mpt_set_ccb_status(ccb, CAM_BUSY);
3192 case MPI_IOCSTATUS_INVALID_FUNCTION:
3193 case MPI_IOCSTATUS_INVALID_SGL:
3194 case MPI_IOCSTATUS_INTERNAL_ERROR:
3195 case MPI_IOCSTATUS_INVALID_FIELD:
3198 * Some of the above may need to kick
3199 * of a recovery action!!!!
3201 ccb->ccb_h.status = CAM_UNREC_HBA_ERROR;
3205 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3206 mpt_freeze_ccb(ccb);
3213 mpt_action(struct cam_sim *sim, union ccb *ccb)
3215 struct mpt_softc *mpt;
3216 struct ccb_trans_settings *cts;
3221 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("mpt_action\n"));
3223 mpt = (struct mpt_softc *)cam_sim_softc(sim);
3224 raid_passthru = (sim == mpt->phydisk_sim);
3225 MPT_LOCK_ASSERT(mpt);
3227 tgt = ccb->ccb_h.target_id;
3228 lun = ccb->ccb_h.target_lun;
3229 if (raid_passthru &&
3230 ccb->ccb_h.func_code != XPT_PATH_INQ &&
3231 ccb->ccb_h.func_code != XPT_RESET_BUS &&
3232 ccb->ccb_h.func_code != XPT_RESET_DEV) {
3233 if (mpt_map_physdisk(mpt, ccb, &tgt) != 0) {
3234 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3235 mpt_set_ccb_status(ccb, CAM_DEV_NOT_THERE);
3240 ccb->ccb_h.ccb_mpt_ptr = mpt;
3242 switch (ccb->ccb_h.func_code) {
3243 case XPT_SCSI_IO: /* Execute the requested I/O operation */
3245 * Do a couple of preliminary checks...
3247 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
3248 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
3249 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3250 mpt_set_ccb_status(ccb, CAM_REQ_INVALID);
3254 /* Max supported CDB length is 16 bytes */
3255 /* XXX Unless we implement the new 32byte message type */
3256 if (ccb->csio.cdb_len >
3257 sizeof (((PTR_MSG_SCSI_IO_REQUEST)0)->CDB)) {
3258 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3259 mpt_set_ccb_status(ccb, CAM_REQ_INVALID);
3262 #ifdef MPT_TEST_MULTIPATH
3263 if (mpt->failure_id == ccb->ccb_h.target_id) {
3264 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3265 mpt_set_ccb_status(ccb, CAM_SEL_TIMEOUT);
3269 ccb->csio.scsi_status = SCSI_STATUS_OK;
3270 mpt_start(sim, ccb);
3274 if (raid_passthru) {
3275 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3276 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3280 if (ccb->ccb_h.func_code == XPT_RESET_BUS) {
3282 xpt_print(ccb->ccb_h.path, "reset bus\n");
3285 xpt_print(ccb->ccb_h.path, "reset device\n");
3287 (void) mpt_bus_reset(mpt, tgt, lun, FALSE);
3290 * mpt_bus_reset is always successful in that it
3291 * will fall back to a hard reset should a bus
3292 * reset attempt fail.
3294 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3295 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3300 union ccb *accb = ccb->cab.abort_ccb;
3301 switch (accb->ccb_h.func_code) {
3302 case XPT_ACCEPT_TARGET_IO:
3303 case XPT_IMMEDIATE_NOTIFY:
3304 ccb->ccb_h.status = mpt_abort_target_ccb(mpt, ccb);
3306 case XPT_CONT_TARGET_IO:
3307 mpt_prt(mpt, "cannot abort active CTIOs yet\n");
3308 ccb->ccb_h.status = CAM_UA_ABORT;
3311 ccb->ccb_h.status = CAM_UA_ABORT;
3314 ccb->ccb_h.status = CAM_REQ_INVALID;
3320 #define IS_CURRENT_SETTINGS(c) ((c)->type == CTS_TYPE_CURRENT_SETTINGS)
3322 #define DP_DISC_ENABLE 0x1
3323 #define DP_DISC_DISABL 0x2
3324 #define DP_DISC (DP_DISC_ENABLE|DP_DISC_DISABL)
3326 #define DP_TQING_ENABLE 0x4
3327 #define DP_TQING_DISABL 0x8
3328 #define DP_TQING (DP_TQING_ENABLE|DP_TQING_DISABL)
3330 #define DP_WIDE 0x10
3331 #define DP_NARROW 0x20
3332 #define DP_WIDTH (DP_WIDE|DP_NARROW)
3334 #define DP_SYNC 0x40
3336 case XPT_SET_TRAN_SETTINGS: /* Nexus Settings */
3338 struct ccb_trans_settings_scsi *scsi;
3339 struct ccb_trans_settings_spi *spi;
3347 if (mpt->is_fc || mpt->is_sas) {
3348 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3352 scsi = &cts->proto_specific.scsi;
3353 spi = &cts->xport_specific.spi;
3356 * We can be called just to valid transport and proto versions
3358 if (scsi->valid == 0 && spi->valid == 0) {
3359 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3364 * Skip attempting settings on RAID volume disks.
3365 * Other devices on the bus get the normal treatment.
3367 if (mpt->phydisk_sim && raid_passthru == 0 &&
3368 mpt_is_raid_volume(mpt, tgt) != 0) {
3369 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
3370 "no transfer settings for RAID vols\n");
3371 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3375 i = mpt->mpt_port_page2.PortSettings &
3376 MPI_SCSIPORTPAGE2_PORT_MASK_NEGO_MASTER_SETTINGS;
3377 j = mpt->mpt_port_page2.PortFlags &
3378 MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
3379 if (i == MPI_SCSIPORTPAGE2_PORT_ALL_MASTER_SETTINGS &&
3380 j == MPI_SCSIPORTPAGE2_PORT_FLAGS_OFF_DV) {
3381 mpt_lprt(mpt, MPT_PRT_ALWAYS,
3382 "honoring BIOS transfer negotiations\n");
3383 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3391 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
3392 dval |= ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0) ?
3393 DP_DISC_ENABLE : DP_DISC_DISABL;
3396 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
3397 dval |= ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) ?
3398 DP_TQING_ENABLE : DP_TQING_DISABL;
3401 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
3402 dval |= (spi->bus_width == MSG_EXT_WDTR_BUS_16_BIT) ?
3403 DP_WIDE : DP_NARROW;
3406 if (spi->valid & CTS_SPI_VALID_SYNC_OFFSET) {
3408 offset = spi->sync_offset;
3410 PTR_CONFIG_PAGE_SCSI_DEVICE_1 ptr =
3411 &mpt->mpt_dev_page1[tgt];
3412 offset = ptr->RequestedParameters;
3413 offset &= MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;
3414 offset >>= MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET;
3416 if (spi->valid & CTS_SPI_VALID_SYNC_RATE) {
3418 period = spi->sync_period;
3420 PTR_CONFIG_PAGE_SCSI_DEVICE_1 ptr =
3421 &mpt->mpt_dev_page1[tgt];
3422 period = ptr->RequestedParameters;
3423 period &= MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
3424 period >>= MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD;
3427 if (dval & DP_DISC_ENABLE) {
3428 mpt->mpt_disc_enable |= (1 << tgt);
3429 } else if (dval & DP_DISC_DISABL) {
3430 mpt->mpt_disc_enable &= ~(1 << tgt);
3432 if (dval & DP_TQING_ENABLE) {
3433 mpt->mpt_tag_enable |= (1 << tgt);
3434 } else if (dval & DP_TQING_DISABL) {
3435 mpt->mpt_tag_enable &= ~(1 << tgt);
3437 if (dval & DP_WIDTH) {
3438 mpt_setwidth(mpt, tgt, 1);
3440 if (dval & DP_SYNC) {
3441 mpt_setsync(mpt, tgt, period, offset);
3444 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3447 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
3448 "set [%d]: 0x%x period 0x%x offset %d\n",
3449 tgt, dval, period, offset);
3450 if (mpt_update_spi_config(mpt, tgt)) {
3451 mpt_set_ccb_status(ccb, CAM_REQ_CMP_ERR);
3453 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3457 case XPT_GET_TRAN_SETTINGS:
3459 struct ccb_trans_settings_scsi *scsi;
3461 cts->protocol = PROTO_SCSI;
3463 struct ccb_trans_settings_fc *fc =
3464 &cts->xport_specific.fc;
3465 cts->protocol_version = SCSI_REV_SPC;
3466 cts->transport = XPORT_FC;
3467 cts->transport_version = 0;
3468 if (mpt->mpt_fcport_speed != 0) {
3469 fc->valid = CTS_FC_VALID_SPEED;
3470 fc->bitrate = 100000 * mpt->mpt_fcport_speed;
3472 } else if (mpt->is_sas) {
3473 struct ccb_trans_settings_sas *sas =
3474 &cts->xport_specific.sas;
3475 cts->protocol_version = SCSI_REV_SPC2;
3476 cts->transport = XPORT_SAS;
3477 cts->transport_version = 0;
3478 sas->valid = CTS_SAS_VALID_SPEED;
3479 sas->bitrate = 300000;
3481 cts->protocol_version = SCSI_REV_2;
3482 cts->transport = XPORT_SPI;
3483 cts->transport_version = 2;
3484 if (mpt_get_spi_settings(mpt, cts) != 0) {
3485 mpt_set_ccb_status(ccb, CAM_REQ_CMP_ERR);
3489 scsi = &cts->proto_specific.scsi;
3490 scsi->valid = CTS_SCSI_VALID_TQ;
3491 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
3492 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3495 case XPT_CALC_GEOMETRY:
3497 struct ccb_calc_geometry *ccg;
3500 if (ccg->block_size == 0) {
3501 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3502 mpt_set_ccb_status(ccb, CAM_REQ_INVALID);
3505 cam_calc_geometry(ccg, /* extended */ 1);
3506 KASSERT(ccb->ccb_h.status, ("zero ccb sts at %d", __LINE__));
3509 case XPT_GET_SIM_KNOB:
3511 struct ccb_sim_knob *kp = &ccb->knob;
3514 kp->xport_specific.fc.wwnn = mpt->scinfo.fc.wwnn;
3515 kp->xport_specific.fc.wwpn = mpt->scinfo.fc.wwpn;
3516 switch (mpt->role) {
3518 kp->xport_specific.fc.role = KNOB_ROLE_NONE;
3520 case MPT_ROLE_INITIATOR:
3521 kp->xport_specific.fc.role = KNOB_ROLE_INITIATOR;
3523 case MPT_ROLE_TARGET:
3524 kp->xport_specific.fc.role = KNOB_ROLE_TARGET;
3527 kp->xport_specific.fc.role = KNOB_ROLE_BOTH;
3530 kp->xport_specific.fc.valid =
3531 KNOB_VALID_ADDRESS | KNOB_VALID_ROLE;
3532 ccb->ccb_h.status = CAM_REQ_CMP;
3534 ccb->ccb_h.status = CAM_REQ_INVALID;
3539 case XPT_PATH_INQ: /* Path routing inquiry */
3541 struct ccb_pathinq *cpi = &ccb->cpi;
3543 cpi->version_num = 1;
3544 cpi->target_sprt = 0;
3545 cpi->hba_eng_cnt = 0;
3546 cpi->max_target = mpt->port_facts[0].MaxDevices - 1;
3547 cpi->maxio = (mpt->max_cam_seg_cnt - 1) * PAGE_SIZE;
3549 * FC cards report MAX_DEVICES of 512, but
3550 * the MSG_SCSI_IO_REQUEST target id field
3551 * is only 8 bits. Until we fix the driver
3552 * to support 'channels' for bus overflow,
3555 if (cpi->max_target > 255) {
3556 cpi->max_target = 255;
3560 * VMware ESX reports > 16 devices and then dies when we probe.
3562 if (mpt->is_spi && cpi->max_target > 15) {
3563 cpi->max_target = 15;
3568 cpi->max_lun = MPT_MAX_LUNS;
3569 cpi->initiator_id = mpt->mpt_ini_id;
3570 cpi->bus_id = cam_sim_bus(sim);
3573 * The base speed is the speed of the underlying connection.
3575 cpi->protocol = PROTO_SCSI;
3577 cpi->hba_misc = PIM_NOBUSRESET | PIM_UNMAPPED |
3579 cpi->base_transfer_speed = 100000;
3580 cpi->hba_inquiry = PI_TAG_ABLE;
3581 cpi->transport = XPORT_FC;
3582 cpi->transport_version = 0;
3583 cpi->protocol_version = SCSI_REV_SPC;
3584 cpi->xport_specific.fc.wwnn = mpt->scinfo.fc.wwnn;
3585 cpi->xport_specific.fc.wwpn = mpt->scinfo.fc.wwpn;
3586 cpi->xport_specific.fc.port = mpt->scinfo.fc.portid;
3587 cpi->xport_specific.fc.bitrate =
3588 100000 * mpt->mpt_fcport_speed;
3589 } else if (mpt->is_sas) {
3590 cpi->hba_misc = PIM_NOBUSRESET | PIM_UNMAPPED |
3592 cpi->base_transfer_speed = 300000;
3593 cpi->hba_inquiry = PI_TAG_ABLE;
3594 cpi->transport = XPORT_SAS;
3595 cpi->transport_version = 0;
3596 cpi->protocol_version = SCSI_REV_SPC2;
3598 cpi->hba_misc = PIM_SEQSCAN | PIM_UNMAPPED |
3600 cpi->base_transfer_speed = 3300;
3601 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
3602 cpi->transport = XPORT_SPI;
3603 cpi->transport_version = 2;
3604 cpi->protocol_version = SCSI_REV_2;
3608 * We give our fake RAID passhtru bus a width that is MaxVolumes
3609 * wide and restrict it to one lun.
3611 if (raid_passthru) {
3612 cpi->max_target = mpt->ioc_page2->MaxPhysDisks - 1;
3613 cpi->initiator_id = cpi->max_target + 1;
3617 if ((mpt->role & MPT_ROLE_INITIATOR) == 0) {
3618 cpi->hba_misc |= PIM_NOINITIATOR;
3620 if (mpt->is_fc && (mpt->role & MPT_ROLE_TARGET)) {
3622 PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO;
3624 cpi->target_sprt = 0;
3626 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
3627 strlcpy(cpi->hba_vid, "LSI", HBA_IDLEN);
3628 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
3629 cpi->unit_number = cam_sim_unit(sim);
3630 cpi->ccb_h.status = CAM_REQ_CMP;
3633 case XPT_EN_LUN: /* Enable LUN as a target */
3637 if (ccb->cel.enable)
3638 result = mpt_enable_lun(mpt,
3639 ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
3641 result = mpt_disable_lun(mpt,
3642 ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
3644 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3646 mpt_set_ccb_status(ccb, CAM_REQ_CMP_ERR);
3650 case XPT_IMMEDIATE_NOTIFY: /* Add Immediate Notify Resource */
3651 case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */
3653 tgt_resource_t *trtp;
3654 lun_id_t lun = ccb->ccb_h.target_lun;
3655 ccb->ccb_h.sim_priv.entries[0].field = 0;
3656 ccb->ccb_h.sim_priv.entries[1].ptr = mpt;
3658 if (lun == CAM_LUN_WILDCARD) {
3659 if (ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
3660 mpt_set_ccb_status(ccb, CAM_REQ_INVALID);
3663 trtp = &mpt->trt_wildcard;
3664 } else if (lun >= MPT_MAX_LUNS) {
3665 mpt_set_ccb_status(ccb, CAM_REQ_INVALID);
3668 trtp = &mpt->trt[lun];
3670 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
3671 mpt_lprt(mpt, MPT_PRT_DEBUG1,
3672 "Put FREE ATIO %p lun %jx\n", ccb, (uintmax_t)lun);
3673 STAILQ_INSERT_TAIL(&trtp->atios, &ccb->ccb_h,
3676 mpt_lprt(mpt, MPT_PRT_DEBUG1,
3677 "Put FREE INOT lun %jx\n", (uintmax_t)lun);
3678 STAILQ_INSERT_TAIL(&trtp->inots, &ccb->ccb_h,
3681 mpt_set_ccb_status(ccb, CAM_REQ_INPROG);
3684 case XPT_NOTIFY_ACKNOWLEDGE: /* Task management request done. */
3686 request_t *req = MPT_TAG_2_REQ(mpt, ccb->cna2.tag_id);
3688 mpt_lprt(mpt, MPT_PRT_DEBUG, "Got Notify ACK\n");
3689 mpt_scsi_tgt_status(mpt, NULL, req, 0, NULL, 0);
3690 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
3693 case XPT_CONT_TARGET_IO:
3694 mpt_target_start_io(mpt, ccb);
3698 ccb->ccb_h.status = CAM_REQ_INVALID;
3705 mpt_get_spi_settings(struct mpt_softc *mpt, struct ccb_trans_settings *cts)
3707 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi;
3708 struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi;
3710 uint32_t dval, pval, oval;
3713 if (IS_CURRENT_SETTINGS(cts) == 0) {
3714 tgt = cts->ccb_h.target_id;
3715 } else if (xpt_path_sim(cts->ccb_h.path) == mpt->phydisk_sim) {
3716 if (mpt_map_physdisk(mpt, (union ccb *)cts, &tgt)) {
3720 tgt = cts->ccb_h.target_id;
3724 * We aren't looking at Port Page 2 BIOS settings here-
3725 * sometimes these have been known to be bogus XXX.
3727 * For user settings, we pick the max from port page 0
3729 * For current settings we read the current settings out from
3730 * device page 0 for that target.
3732 if (IS_CURRENT_SETTINGS(cts)) {
3733 CONFIG_PAGE_SCSI_DEVICE_0 tmp;
3736 tmp = mpt->mpt_dev_page0[tgt];
3737 rv = mpt_read_cur_cfg_page(mpt, tgt, &tmp.Header,
3738 sizeof(tmp), FALSE, 5000);
3740 mpt_prt(mpt, "can't get tgt %d config page 0\n", tgt);
3743 mpt2host_config_page_scsi_device_0(&tmp);
3745 mpt_lprt(mpt, MPT_PRT_DEBUG,
3746 "mpt_get_spi_settings[%d]: current NP %x Info %x\n", tgt,
3747 tmp.NegotiatedParameters, tmp.Information);
3748 dval |= (tmp.NegotiatedParameters & MPI_SCSIDEVPAGE0_NP_WIDE) ?
3749 DP_WIDE : DP_NARROW;
3750 dval |= (mpt->mpt_disc_enable & (1 << tgt)) ?
3751 DP_DISC_ENABLE : DP_DISC_DISABL;
3752 dval |= (mpt->mpt_tag_enable & (1 << tgt)) ?
3753 DP_TQING_ENABLE : DP_TQING_DISABL;
3754 oval = tmp.NegotiatedParameters;
3755 oval &= MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK;
3756 oval >>= MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET;
3757 pval = tmp.NegotiatedParameters;
3758 pval &= MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK;
3759 pval >>= MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD;
3760 mpt->mpt_dev_page0[tgt] = tmp;
3762 dval = DP_WIDE|DP_DISC_ENABLE|DP_TQING_ENABLE|DP_SYNC;
3763 oval = mpt->mpt_port_page0.Capabilities;
3764 oval = MPI_SCSIPORTPAGE0_CAP_GET_MAX_SYNC_OFFSET(oval);
3765 pval = mpt->mpt_port_page0.Capabilities;
3766 pval = MPI_SCSIPORTPAGE0_CAP_GET_MIN_SYNC_PERIOD(pval);
3773 spi->sync_offset = oval;
3774 spi->sync_period = pval;
3775 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
3776 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
3777 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
3778 if (dval & DP_WIDE) {
3779 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
3781 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
3783 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
3784 scsi->valid = CTS_SCSI_VALID_TQ;
3785 if (dval & DP_TQING_ENABLE) {
3786 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
3788 spi->valid |= CTS_SPI_VALID_DISC;
3789 if (dval & DP_DISC_ENABLE) {
3790 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
3794 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
3795 "mpt_get_spi_settings[%d]: %s flags 0x%x per 0x%x off=%d\n", tgt,
3796 IS_CURRENT_SETTINGS(cts) ? "ACTIVE" : "NVRAM ", dval, pval, oval);
3801 mpt_setwidth(struct mpt_softc *mpt, int tgt, int onoff)
3803 PTR_CONFIG_PAGE_SCSI_DEVICE_1 ptr;
3805 ptr = &mpt->mpt_dev_page1[tgt];
3807 ptr->RequestedParameters |= MPI_SCSIDEVPAGE1_RP_WIDE;
3809 ptr->RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_WIDE;
3814 mpt_setsync(struct mpt_softc *mpt, int tgt, int period, int offset)
3816 PTR_CONFIG_PAGE_SCSI_DEVICE_1 ptr;
3818 ptr = &mpt->mpt_dev_page1[tgt];
3819 ptr->RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
3820 ptr->RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;
3821 ptr->RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_DT;
3822 ptr->RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_QAS;
3823 ptr->RequestedParameters &= ~MPI_SCSIDEVPAGE1_RP_IU;
3827 ptr->RequestedParameters |=
3828 period << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD;
3829 ptr->RequestedParameters |=
3830 offset << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET;
3832 ptr->RequestedParameters |= MPI_SCSIDEVPAGE1_RP_DT;
3835 ptr->RequestedParameters |= MPI_SCSIDEVPAGE1_RP_QAS;
3836 ptr->RequestedParameters |= MPI_SCSIDEVPAGE1_RP_IU;
3841 mpt_update_spi_config(struct mpt_softc *mpt, int tgt)
3843 CONFIG_PAGE_SCSI_DEVICE_1 tmp;
3846 mpt_lprt(mpt, MPT_PRT_NEGOTIATION,
3847 "mpt_update_spi_config[%d].page1: Requested Params 0x%08x\n",
3848 tgt, mpt->mpt_dev_page1[tgt].RequestedParameters);
3849 tmp = mpt->mpt_dev_page1[tgt];
3850 host2mpt_config_page_scsi_device_1(&tmp);
3851 rv = mpt_write_cur_cfg_page(mpt, tgt,
3852 &tmp.Header, sizeof(tmp), FALSE, 5000);
3854 mpt_prt(mpt, "mpt_update_spi_config: write cur page failed\n");
3860 /****************************** Timeout Recovery ******************************/
3862 mpt_spawn_recovery_thread(struct mpt_softc *mpt)
3866 error = kproc_create(mpt_recovery_thread, mpt,
3867 &mpt->recovery_thread, /*flags*/0,
3868 /*altstack*/0, "mpt_recovery%d", mpt->unit);
3873 mpt_terminate_recovery_thread(struct mpt_softc *mpt)
3876 if (mpt->recovery_thread == NULL) {
3879 mpt->shutdwn_recovery = 1;
3882 * Sleep on a slightly different location
3883 * for this interlock just for added safety.
3885 mpt_sleep(mpt, &mpt->recovery_thread, PUSER, "thtrm", 0);
3889 mpt_recovery_thread(void *arg)
3891 struct mpt_softc *mpt;
3893 mpt = (struct mpt_softc *)arg;
3896 if (TAILQ_EMPTY(&mpt->request_timeout_list) != 0) {
3897 if (mpt->shutdwn_recovery == 0) {
3898 mpt_sleep(mpt, mpt, PUSER, "idle", 0);
3901 if (mpt->shutdwn_recovery != 0) {
3904 mpt_recover_commands(mpt);
3906 mpt->recovery_thread = NULL;
3907 wakeup(&mpt->recovery_thread);
3913 mpt_scsi_send_tmf(struct mpt_softc *mpt, u_int type, u_int flags,
3914 u_int channel, target_id_t target, lun_id_t lun, u_int abort_ctx,
3917 MSG_SCSI_TASK_MGMT *tmf_req;
3921 * Wait for any current TMF request to complete.
3922 * We're only allowed to issue one TMF at a time.
3924 error = mpt_wait_req(mpt, mpt->tmf_req, REQ_STATE_FREE, REQ_STATE_FREE,
3925 sleep_ok, MPT_TMF_MAX_TIMEOUT);
3927 mpt_reset(mpt, TRUE);
3931 mpt_assign_serno(mpt, mpt->tmf_req);
3932 mpt->tmf_req->state = REQ_STATE_ALLOCATED|REQ_STATE_QUEUED;
3934 tmf_req = (MSG_SCSI_TASK_MGMT *)mpt->tmf_req->req_vbuf;
3935 memset(tmf_req, 0, sizeof(*tmf_req));
3936 tmf_req->TargetID = target;
3937 tmf_req->Bus = channel;
3938 tmf_req->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
3939 tmf_req->TaskType = type;
3940 tmf_req->MsgFlags = flags;
3941 tmf_req->MsgContext =
3942 htole32(mpt->tmf_req->index | scsi_tmf_handler_id);
3943 be64enc(tmf_req->LUN, CAM_EXTLUN_BYTE_SWIZZLE(lun));
3944 tmf_req->TaskMsgContext = abort_ctx;
3946 mpt_lprt(mpt, MPT_PRT_DEBUG,
3947 "Issuing TMF %p:%u with MsgContext of 0x%x\n", mpt->tmf_req,
3948 mpt->tmf_req->serno, tmf_req->MsgContext);
3949 if (mpt->verbose > MPT_PRT_DEBUG) {
3950 mpt_print_request(tmf_req);
3953 KASSERT(mpt_req_on_pending_list(mpt, mpt->tmf_req) == 0,
3954 ("mpt_scsi_send_tmf: tmf_req already on pending list"));
3955 TAILQ_INSERT_HEAD(&mpt->request_pending_list, mpt->tmf_req, links);
3956 error = mpt_send_handshake_cmd(mpt, sizeof(*tmf_req), tmf_req);
3957 if (error != MPT_OK) {
3958 TAILQ_REMOVE(&mpt->request_pending_list, mpt->tmf_req, links);
3959 mpt->tmf_req->state = REQ_STATE_FREE;
3960 mpt_reset(mpt, TRUE);
3966 * When a command times out, it is placed on the requeust_timeout_list
3967 * and we wake our recovery thread. The MPT-Fusion architecture supports
3968 * only a single TMF operation at a time, so we serially abort/bdr, etc,
3969 * the timedout transactions. The next TMF is issued either by the
3970 * completion handler of the current TMF waking our recovery thread,
3971 * or the TMF timeout handler causing a hard reset sequence.
3974 mpt_recover_commands(struct mpt_softc *mpt)
3980 if (TAILQ_EMPTY(&mpt->request_timeout_list) != 0) {
3982 * No work to do- leave.
3984 mpt_prt(mpt, "mpt_recover_commands: no requests.\n");
3989 * Flush any commands whose completion coincides with their timeout.
3993 if (TAILQ_EMPTY(&mpt->request_timeout_list) != 0) {
3995 * The timedout commands have already
3996 * completed. This typically means
3997 * that either the timeout value was on
3998 * the hairy edge of what the device
3999 * requires or - more likely - interrupts
4000 * are not happening.
4002 mpt_prt(mpt, "Timedout requests already complete. "
4003 "Interrupts may not be functioning.\n");
4004 mpt_enable_ints(mpt);
4009 * We have no visibility into the current state of the
4010 * controller, so attempt to abort the commands in the
4011 * order they timed-out. For initiator commands, we
4012 * depend on the reply handler pulling requests off
4015 while ((req = TAILQ_FIRST(&mpt->request_timeout_list)) != NULL) {
4018 MSG_REQUEST_HEADER *hdrp = req->req_vbuf;
4020 mpt_prt(mpt, "attempting to abort req %p:%u function %x\n",
4021 req, req->serno, hdrp->Function);
4024 mpt_prt(mpt, "null ccb in timed out request. "
4025 "Resetting Controller.\n");
4026 mpt_reset(mpt, TRUE);
4029 mpt_set_ccb_status(ccb, CAM_CMD_TIMEOUT);
4032 * Check to see if this is not an initiator command and
4033 * deal with it differently if it is.
4035 switch (hdrp->Function) {
4036 case MPI_FUNCTION_SCSI_IO_REQUEST:
4037 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
4041 * XXX: FIX ME: need to abort target assists...
4043 mpt_prt(mpt, "just putting it back on the pend q\n");
4044 TAILQ_REMOVE(&mpt->request_timeout_list, req, links);
4045 TAILQ_INSERT_HEAD(&mpt->request_pending_list, req,
4050 error = mpt_scsi_send_tmf(mpt,
4051 MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
4052 0, 0, ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
4053 htole32(req->index | scsi_io_handler_id), TRUE);
4057 * mpt_scsi_send_tmf hard resets on failure, so no
4058 * need to do so here. Our queue should be emptied
4059 * by the hard reset.
4064 error = mpt_wait_req(mpt, mpt->tmf_req, REQ_STATE_DONE,
4065 REQ_STATE_DONE, TRUE, 500);
4067 status = le16toh(mpt->tmf_req->IOCStatus);
4068 response = mpt->tmf_req->ResponseCode;
4069 mpt->tmf_req->state = REQ_STATE_FREE;
4073 * If we've errored out,, reset the controller.
4075 mpt_prt(mpt, "mpt_recover_commands: abort timed-out. "
4076 "Resetting controller\n");
4077 mpt_reset(mpt, TRUE);
4081 if ((status & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
4082 mpt_prt(mpt, "mpt_recover_commands: IOC Status 0x%x. "
4083 "Resetting controller.\n", status);
4084 mpt_reset(mpt, TRUE);
4088 if (response != MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED &&
4089 response != MPI_SCSITASKMGMT_RSP_TM_COMPLETE) {
4090 mpt_prt(mpt, "mpt_recover_commands: TMF Response 0x%x. "
4091 "Resetting controller.\n", response);
4092 mpt_reset(mpt, TRUE);
4095 mpt_prt(mpt, "abort of req %p:%u completed\n", req, req->serno);
4099 /************************ Target Mode Support ****************************/
4101 mpt_fc_post_els(struct mpt_softc *mpt, request_t *req, int ioindex)
4103 MSG_LINK_SERVICE_BUFFER_POST_REQUEST *fc;
4104 PTR_SGE_TRANSACTION32 tep;
4105 PTR_SGE_SIMPLE32 se;
4109 paddr = req->req_pbuf;
4110 paddr += MPT_RQSL(mpt);
4113 memset(fc, 0, MPT_REQUEST_AREA);
4114 fc->BufferCount = 1;
4115 fc->Function = MPI_FUNCTION_FC_LINK_SRVC_BUF_POST;
4116 fc->MsgContext = htole32(req->index | fc_els_handler_id);
4119 * Okay, set up ELS buffer pointers. ELS buffer pointers
4120 * consist of a TE SGL element (with details length of zero)
4121 * followed by a SIMPLE SGL element which holds the address
4125 tep = (PTR_SGE_TRANSACTION32) &fc->SGL;
4127 tep->ContextSize = 4;
4129 tep->TransactionContext[0] = htole32(ioindex);
4131 se = (PTR_SGE_SIMPLE32) &tep->TransactionDetails[0];
4133 MPI_SGE_FLAGS_HOST_TO_IOC |
4134 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
4135 MPI_SGE_FLAGS_LAST_ELEMENT |
4136 MPI_SGE_FLAGS_END_OF_LIST |
4137 MPI_SGE_FLAGS_END_OF_BUFFER;
4138 fl <<= MPI_SGE_FLAGS_SHIFT;
4139 fl |= (MPT_NRFM(mpt) - MPT_RQSL(mpt));
4140 se->FlagsLength = htole32(fl);
4141 se->Address = htole32((uint32_t) paddr);
4142 mpt_lprt(mpt, MPT_PRT_DEBUG,
4143 "add ELS index %d ioindex %d for %p:%u\n",
4144 req->index, ioindex, req, req->serno);
4145 KASSERT(((req->state & REQ_STATE_LOCKED) != 0),
4146 ("mpt_fc_post_els: request not locked"));
4147 mpt_send_cmd(mpt, req);
4151 mpt_post_target_command(struct mpt_softc *mpt, request_t *req, int ioindex)
4153 PTR_MSG_TARGET_CMD_BUFFER_POST_REQUEST fc;
4154 PTR_CMD_BUFFER_DESCRIPTOR cb;
4157 paddr = req->req_pbuf;
4158 paddr += MPT_RQSL(mpt);
4159 memset(req->req_vbuf, 0, MPT_REQUEST_AREA);
4160 MPT_TGT_STATE(mpt, req)->state = TGT_STATE_LOADING;
4163 fc->BufferCount = 1;
4164 fc->Function = MPI_FUNCTION_TARGET_CMD_BUFFER_POST;
4165 fc->BufferLength = MIN(MPT_REQUEST_AREA - MPT_RQSL(mpt), UINT8_MAX);
4166 fc->MsgContext = htole32(req->index | mpt->scsi_tgt_handler_id);
4168 cb = &fc->Buffer[0];
4169 cb->IoIndex = htole16(ioindex);
4170 cb->u.PhysicalAddress32 = htole32((U32) paddr);
4172 mpt_check_doorbell(mpt);
4173 mpt_send_cmd(mpt, req);
4177 mpt_add_els_buffers(struct mpt_softc *mpt)
4181 if (mpt->is_fc == 0) {
4185 if (mpt->els_cmds_allocated) {
4189 mpt->els_cmd_ptrs = malloc(MPT_MAX_ELS * sizeof (request_t *),
4190 M_DEVBUF, M_NOWAIT | M_ZERO);
4192 if (mpt->els_cmd_ptrs == NULL) {
4197 * Feed the chip some ELS buffer resources
4199 for (i = 0; i < MPT_MAX_ELS; i++) {
4200 request_t *req = mpt_get_request(mpt, FALSE);
4204 req->state |= REQ_STATE_LOCKED;
4205 mpt->els_cmd_ptrs[i] = req;
4206 mpt_fc_post_els(mpt, req, i);
4210 mpt_prt(mpt, "unable to add ELS buffer resources\n");
4211 free(mpt->els_cmd_ptrs, M_DEVBUF);
4212 mpt->els_cmd_ptrs = NULL;
4215 if (i != MPT_MAX_ELS) {
4216 mpt_lprt(mpt, MPT_PRT_INFO,
4217 "only added %d of %d ELS buffers\n", i, MPT_MAX_ELS);
4219 mpt->els_cmds_allocated = i;
4224 mpt_add_target_commands(struct mpt_softc *mpt)
4228 if (mpt->tgt_cmd_ptrs) {
4232 max = MPT_MAX_REQUESTS(mpt) >> 1;
4233 if (max > mpt->mpt_max_tgtcmds) {
4234 max = mpt->mpt_max_tgtcmds;
4237 malloc(max * sizeof (request_t *), M_DEVBUF, M_NOWAIT | M_ZERO);
4238 if (mpt->tgt_cmd_ptrs == NULL) {
4240 "mpt_add_target_commands: could not allocate cmd ptrs\n");
4244 for (i = 0; i < max; i++) {
4247 req = mpt_get_request(mpt, FALSE);
4251 req->state |= REQ_STATE_LOCKED;
4252 mpt->tgt_cmd_ptrs[i] = req;
4253 mpt_post_target_command(mpt, req, i);
4258 mpt_lprt(mpt, MPT_PRT_ERROR, "could not add any target bufs\n");
4259 free(mpt->tgt_cmd_ptrs, M_DEVBUF);
4260 mpt->tgt_cmd_ptrs = NULL;
4264 mpt->tgt_cmds_allocated = i;
4267 mpt_lprt(mpt, MPT_PRT_INFO,
4268 "added %d of %d target bufs\n", i, max);
4274 mpt_enable_lun(struct mpt_softc *mpt, target_id_t tgt, lun_id_t lun)
4277 if (tgt == CAM_TARGET_WILDCARD && lun == CAM_LUN_WILDCARD) {
4279 } else if (lun >= MPT_MAX_LUNS) {
4281 } else if (tgt != CAM_TARGET_WILDCARD && tgt != 0) {
4284 if (mpt->tenabled == 0) {
4286 (void) mpt_fc_reset_link(mpt, 0);
4290 if (lun == CAM_LUN_WILDCARD) {
4291 mpt->trt_wildcard.enabled = 1;
4293 mpt->trt[lun].enabled = 1;
4299 mpt_disable_lun(struct mpt_softc *mpt, target_id_t tgt, lun_id_t lun)
4303 if (tgt == CAM_TARGET_WILDCARD && lun == CAM_LUN_WILDCARD) {
4305 } else if (lun >= MPT_MAX_LUNS) {
4307 } else if (tgt != CAM_TARGET_WILDCARD && tgt != 0) {
4310 if (lun == CAM_LUN_WILDCARD) {
4311 mpt->trt_wildcard.enabled = 0;
4313 mpt->trt[lun].enabled = 0;
4315 for (i = 0; i < MPT_MAX_LUNS; i++) {
4316 if (mpt->trt[i].enabled) {
4320 if (i == MPT_MAX_LUNS && mpt->twildcard == 0) {
4322 (void) mpt_fc_reset_link(mpt, 0);
4330 * Called with MPT lock held
4333 mpt_target_start_io(struct mpt_softc *mpt, union ccb *ccb)
4335 struct ccb_scsiio *csio = &ccb->csio;
4336 request_t *cmd_req = MPT_TAG_2_REQ(mpt, csio->tag_id);
4337 mpt_tgt_state_t *tgt = MPT_TGT_STATE(mpt, cmd_req);
4339 switch (tgt->state) {
4340 case TGT_STATE_IN_CAM:
4342 case TGT_STATE_MOVING_DATA:
4343 mpt_set_ccb_status(ccb, CAM_REQUEUE_REQ);
4344 xpt_freeze_simq(mpt->sim, 1);
4345 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
4346 tgt->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
4350 mpt_prt(mpt, "ccb %p flags 0x%x tag 0x%08x had bad request "
4351 "starting I/O\n", ccb, csio->ccb_h.flags, csio->tag_id);
4352 mpt_tgt_dump_req_state(mpt, cmd_req);
4353 mpt_set_ccb_status(ccb, CAM_REQ_CMP_ERR);
4358 if (csio->dxfer_len) {
4359 bus_dmamap_callback_t *cb;
4360 PTR_MSG_TARGET_ASSIST_REQUEST ta;
4364 KASSERT((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE,
4365 ("dxfer_len %u but direction is NONE", csio->dxfer_len));
4367 if ((req = mpt_get_request(mpt, FALSE)) == NULL) {
4368 if (mpt->outofbeer == 0) {
4370 xpt_freeze_simq(mpt->sim, 1);
4371 mpt_lprt(mpt, MPT_PRT_DEBUG, "FREEZEQ\n");
4373 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
4374 mpt_set_ccb_status(ccb, CAM_REQUEUE_REQ);
4378 ccb->ccb_h.status = CAM_SIM_QUEUED | CAM_REQ_INPROG;
4379 if (sizeof (bus_addr_t) > 4) {
4380 cb = mpt_execute_req_a64;
4382 cb = mpt_execute_req;
4386 ccb->ccb_h.ccb_req_ptr = req;
4389 * Record the currently active ccb and the
4390 * request for it in our target state area.
4395 memset(req->req_vbuf, 0, MPT_RQSL(mpt));
4399 PTR_MPI_TARGET_SSP_CMD_BUFFER ssp =
4401 ta->QueueTag = ssp->InitiatorTag;
4402 } else if (mpt->is_spi) {
4403 PTR_MPI_TARGET_SCSI_SPI_CMD_BUFFER sp =
4405 ta->QueueTag = sp->Tag;
4407 ta->Function = MPI_FUNCTION_TARGET_ASSIST;
4408 ta->MsgContext = htole32(req->index | mpt->scsi_tgt_handler_id);
4409 ta->ReplyWord = htole32(tgt->reply_desc);
4410 be64enc(ta->LUN, CAM_EXTLUN_BYTE_SWIZZLE(csio->ccb_h.target_lun));
4412 ta->RelativeOffset = tgt->bytes_xfered;
4413 ta->DataLength = ccb->csio.dxfer_len;
4414 if (ta->DataLength > tgt->resid) {
4415 ta->DataLength = tgt->resid;
4419 * XXX Should be done after data transfer completes?
4421 csio->resid = csio->dxfer_len - ta->DataLength;
4422 tgt->resid -= csio->dxfer_len;
4423 tgt->bytes_xfered += csio->dxfer_len;
4425 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
4426 ta->TargetAssistFlags |=
4427 TARGET_ASSIST_FLAGS_DATA_DIRECTION;
4430 #ifdef WE_TRUST_AUTO_GOOD_STATUS
4431 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) &&
4432 csio->scsi_status == SCSI_STATUS_OK && tgt->resid == 0) {
4433 ta->TargetAssistFlags |=
4434 TARGET_ASSIST_FLAGS_AUTO_STATUS;
4437 tgt->state = TGT_STATE_SETTING_UP_FOR_DATA;
4439 mpt_lprt(mpt, MPT_PRT_DEBUG,
4440 "DATA_CCB %p tag %x %u bytes %u resid flg %x req %p:%u "
4441 "nxtstate=%d\n", csio, csio->tag_id, csio->dxfer_len,
4442 tgt->resid, ccb->ccb_h.flags, req, req->serno, tgt->state);
4444 error = bus_dmamap_load_ccb(mpt->buffer_dmat, req->dmap, ccb,
4446 if (error == EINPROGRESS) {
4447 xpt_freeze_simq(mpt->sim, 1);
4448 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
4452 * XXX: I don't know why this seems to happen, but
4453 * XXX: completing the CCB seems to make things happy.
4454 * XXX: This seems to happen if the initiator requests
4455 * XXX: enough data that we have to do multiple CTIOs.
4457 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
4458 mpt_lprt(mpt, MPT_PRT_DEBUG,
4459 "Meaningless STATUS CCB (%p): flags %x status %x "
4460 "resid %d bytes_xfered %u\n", ccb, ccb->ccb_h.flags,
4461 ccb->ccb_h.status, tgt->resid, tgt->bytes_xfered);
4462 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
4463 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
4467 mpt_scsi_tgt_status(mpt, ccb, cmd_req, csio->scsi_status,
4468 (void *)&csio->sense_data,
4469 (ccb->ccb_h.flags & CAM_SEND_SENSE) ?
4470 csio->sense_len : 0);
4475 mpt_scsi_tgt_local(struct mpt_softc *mpt, request_t *cmd_req,
4476 lun_id_t lun, int send, uint8_t *data, size_t length)
4478 mpt_tgt_state_t *tgt;
4479 PTR_MSG_TARGET_ASSIST_REQUEST ta;
4487 * We enter with resid set to the data load for the command.
4489 tgt = MPT_TGT_STATE(mpt, cmd_req);
4490 if (length == 0 || tgt->resid == 0) {
4492 mpt_scsi_tgt_status(mpt, NULL, cmd_req, 0, NULL, 0);
4496 if ((req = mpt_get_request(mpt, FALSE)) == NULL) {
4497 mpt_prt(mpt, "out of resources- dropping local response\n");
4503 memset(req->req_vbuf, 0, MPT_RQSL(mpt));
4507 PTR_MPI_TARGET_SSP_CMD_BUFFER ssp = cmd_req->req_vbuf;
4508 ta->QueueTag = ssp->InitiatorTag;
4509 } else if (mpt->is_spi) {
4510 PTR_MPI_TARGET_SCSI_SPI_CMD_BUFFER sp = cmd_req->req_vbuf;
4511 ta->QueueTag = sp->Tag;
4513 ta->Function = MPI_FUNCTION_TARGET_ASSIST;
4514 ta->MsgContext = htole32(req->index | mpt->scsi_tgt_handler_id);
4515 ta->ReplyWord = htole32(tgt->reply_desc);
4516 be64enc(ta->LUN, CAM_EXTLUN_BYTE_SWIZZLE(lun));
4517 ta->RelativeOffset = 0;
4518 ta->DataLength = length;
4520 dptr = req->req_vbuf;
4521 dptr += MPT_RQSL(mpt);
4522 pptr = req->req_pbuf;
4523 pptr += MPT_RQSL(mpt);
4524 memcpy(dptr, data, min(length, MPT_RQSL(mpt)));
4526 se = (SGE_SIMPLE32 *) &ta->SGL[0];
4527 memset(se, 0,sizeof (*se));
4529 flags = MPI_SGE_FLAGS_SIMPLE_ELEMENT;
4531 ta->TargetAssistFlags |= TARGET_ASSIST_FLAGS_DATA_DIRECTION;
4532 flags |= MPI_SGE_FLAGS_HOST_TO_IOC;
4535 MPI_pSGE_SET_LENGTH(se, length);
4536 flags |= MPI_SGE_FLAGS_LAST_ELEMENT;
4537 flags |= MPI_SGE_FLAGS_END_OF_LIST | MPI_SGE_FLAGS_END_OF_BUFFER;
4538 MPI_pSGE_SET_FLAGS(se, flags);
4542 tgt->resid -= length;
4543 tgt->bytes_xfered = length;
4544 #ifdef WE_TRUST_AUTO_GOOD_STATUS
4545 tgt->state = TGT_STATE_MOVING_DATA_AND_STATUS;
4547 tgt->state = TGT_STATE_MOVING_DATA;
4549 mpt_send_cmd(mpt, req);
4553 * Abort queued up CCBs
4556 mpt_abort_target_ccb(struct mpt_softc *mpt, union ccb *ccb)
4558 struct mpt_hdr_stailq *lp;
4559 struct ccb_hdr *srch;
4560 union ccb *accb = ccb->cab.abort_ccb;
4561 tgt_resource_t *trtp;
4562 mpt_tgt_state_t *tgt;
4566 mpt_lprt(mpt, MPT_PRT_DEBUG, "aborting ccb %p\n", accb);
4567 if (ccb->ccb_h.target_lun == CAM_LUN_WILDCARD)
4568 trtp = &mpt->trt_wildcard;
4570 trtp = &mpt->trt[ccb->ccb_h.target_lun];
4571 if (accb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
4573 tag = accb->atio.tag_id;
4576 tag = accb->cin1.tag_id;
4579 /* Search the CCB among queued. */
4580 STAILQ_FOREACH(srch, lp, sim_links.stqe) {
4581 if (srch != &accb->ccb_h)
4583 STAILQ_REMOVE(lp, srch, ccb_hdr, sim_links.stqe);
4584 accb->ccb_h.status = CAM_REQ_ABORTED;
4586 return (CAM_REQ_CMP);
4589 /* Search the CCB among running. */
4590 req = MPT_TAG_2_REQ(mpt, tag);
4591 tgt = MPT_TGT_STATE(mpt, req);
4592 if (tgt->tag_id == tag) {
4593 mpt_abort_target_cmd(mpt, req);
4594 return (CAM_REQ_CMP);
4597 return (CAM_UA_ABORT);
4601 * Ask the MPT to abort the current target command
4604 mpt_abort_target_cmd(struct mpt_softc *mpt, request_t *cmd_req)
4608 PTR_MSG_TARGET_MODE_ABORT abtp;
4610 req = mpt_get_request(mpt, FALSE);
4614 abtp = req->req_vbuf;
4615 memset(abtp, 0, sizeof (*abtp));
4617 abtp->MsgContext = htole32(req->index | mpt->scsi_tgt_handler_id);
4618 abtp->AbortType = TARGET_MODE_ABORT_TYPE_EXACT_IO;
4619 abtp->Function = MPI_FUNCTION_TARGET_MODE_ABORT;
4620 abtp->ReplyWord = htole32(MPT_TGT_STATE(mpt, cmd_req)->reply_desc);
4622 if (mpt->is_fc || mpt->is_sas) {
4623 mpt_send_cmd(mpt, req);
4625 error = mpt_send_handshake_cmd(mpt, sizeof(*req), req);
4631 * WE_TRUST_AUTO_GOOD_STATUS- I've found that setting
4632 * TARGET_STATUS_SEND_FLAGS_AUTO_GOOD_STATUS leads the
4633 * FC929 to set bogus FC_RSP fields (nonzero residuals
4634 * but w/o RESID fields set). This causes QLogic initiators
4635 * to think maybe that a frame was lost.
4637 * WE_CAN_USE_AUTO_REPOST- we can't use AUTO_REPOST because
4638 * we use allocated requests to do TARGET_ASSIST and we
4639 * need to know when to release them.
4643 mpt_scsi_tgt_status(struct mpt_softc *mpt, union ccb *ccb, request_t *cmd_req,
4644 uint8_t status, uint8_t const *sense_data, u_int sense_len)
4647 mpt_tgt_state_t *tgt;
4648 PTR_MSG_TARGET_STATUS_SEND_REQUEST tp;
4654 cmd_vbuf = cmd_req->req_vbuf;
4655 cmd_vbuf += MPT_RQSL(mpt);
4656 tgt = MPT_TGT_STATE(mpt, cmd_req);
4658 if ((req = mpt_get_request(mpt, FALSE)) == NULL) {
4659 if (mpt->outofbeer == 0) {
4661 xpt_freeze_simq(mpt->sim, 1);
4662 mpt_lprt(mpt, MPT_PRT_DEBUG, "FREEZEQ\n");
4665 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
4666 mpt_set_ccb_status(ccb, CAM_REQUEUE_REQ);
4670 "could not allocate status request- dropping\n");
4676 ccb->ccb_h.ccb_mpt_ptr = mpt;
4677 ccb->ccb_h.ccb_req_ptr = req;
4681 * Record the currently active ccb, if any, and the
4682 * request for it in our target state area.
4686 tgt->state = TGT_STATE_SENDING_STATUS;
4689 paddr = req->req_pbuf;
4690 paddr += MPT_RQSL(mpt);
4692 memset(tp, 0, sizeof (*tp));
4693 tp->StatusCode = status;
4694 tp->Function = MPI_FUNCTION_TARGET_STATUS_SEND;
4696 PTR_MPI_TARGET_FCP_CMD_BUFFER fc =
4697 (PTR_MPI_TARGET_FCP_CMD_BUFFER) cmd_vbuf;
4701 sts_vbuf = req->req_vbuf;
4702 sts_vbuf += MPT_RQSL(mpt);
4703 rsp = (uint32_t *) sts_vbuf;
4704 memcpy(tp->LUN, fc->FcpLun, sizeof (tp->LUN));
4707 * The MPI_TARGET_FCP_RSP_BUFFER define is unfortunate.
4708 * It has to be big-endian in memory and is organized
4709 * in 32 bit words, which are much easier to deal with
4710 * as words which are swizzled as needed.
4712 * All we're filling here is the FC_RSP payload.
4713 * We may just have the chip synthesize it if
4714 * we have no residual and an OK status.
4717 memset(rsp, 0, sizeof (MPI_TARGET_FCP_RSP_BUFFER));
4719 rsp[2] = htobe32(status);
4720 #define MIN_FCP_RESPONSE_SIZE 24
4721 #ifndef WE_TRUST_AUTO_GOOD_STATUS
4722 resplen = MIN_FCP_RESPONSE_SIZE;
4724 if (tgt->resid < 0) {
4725 rsp[2] |= htobe32(0x400); /* XXXX NEED MNEMONIC!!!! */
4726 rsp[3] = htobe32(-tgt->resid);
4727 resplen = MIN_FCP_RESPONSE_SIZE;
4728 } else if (tgt->resid > 0) {
4729 rsp[2] |= htobe32(0x800); /* XXXX NEED MNEMONIC!!!! */
4730 rsp[3] = htobe32(tgt->resid);
4731 resplen = MIN_FCP_RESPONSE_SIZE;
4733 if (sense_len > 0) {
4734 rsp[2] |= htobe32(0x200); /* XXXX NEED MNEMONIC!!!! */
4735 rsp[4] = htobe32(sense_len);
4736 memcpy(&rsp[6], sense_data, sense_len);
4737 resplen = MIN_FCP_RESPONSE_SIZE + sense_len;
4739 } else if (mpt->is_sas) {
4740 PTR_MPI_TARGET_SSP_CMD_BUFFER ssp =
4741 (PTR_MPI_TARGET_SSP_CMD_BUFFER) cmd_vbuf;
4742 memcpy(tp->LUN, ssp->LogicalUnitNumber, sizeof (tp->LUN));
4744 PTR_MPI_TARGET_SCSI_SPI_CMD_BUFFER sp =
4745 (PTR_MPI_TARGET_SCSI_SPI_CMD_BUFFER) cmd_vbuf;
4746 tp->QueueTag = htole16(sp->Tag);
4747 memcpy(tp->LUN, sp->LogicalUnitNumber, sizeof (tp->LUN));
4750 tp->ReplyWord = htole32(tgt->reply_desc);
4751 tp->MsgContext = htole32(req->index | mpt->scsi_tgt_handler_id);
4753 #ifdef WE_CAN_USE_AUTO_REPOST
4754 tp->MsgFlags = TARGET_STATUS_SEND_FLAGS_REPOST_CMD_BUFFER;
4756 if (status == SCSI_STATUS_OK && resplen == 0) {
4757 tp->MsgFlags |= TARGET_STATUS_SEND_FLAGS_AUTO_GOOD_STATUS;
4759 tp->StatusDataSGE.u.Address32 = htole32((uint32_t) paddr);
4760 fl = MPI_SGE_FLAGS_HOST_TO_IOC |
4761 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
4762 MPI_SGE_FLAGS_LAST_ELEMENT |
4763 MPI_SGE_FLAGS_END_OF_LIST |
4764 MPI_SGE_FLAGS_END_OF_BUFFER;
4765 fl <<= MPI_SGE_FLAGS_SHIFT;
4767 tp->StatusDataSGE.FlagsLength = htole32(fl);
4770 mpt_lprt(mpt, MPT_PRT_DEBUG,
4771 "STATUS_CCB %p (with%s sense) tag %x req %p:%u resid %u\n",
4772 ccb, sense_len > 0 ? "" : "out", tgt->tag_id,
4773 req, req->serno, tgt->resid);
4774 if (mpt->verbose > MPT_PRT_DEBUG)
4775 mpt_print_request(req->req_vbuf);
4777 ccb->ccb_h.status = CAM_SIM_QUEUED | CAM_REQ_INPROG;
4778 mpt_req_timeout(req, SBT_1S * 60, mpt_timeout, ccb);
4780 mpt_send_cmd(mpt, req);
4784 mpt_scsi_tgt_tsk_mgmt(struct mpt_softc *mpt, request_t *req, mpt_task_mgmt_t fc,
4785 tgt_resource_t *trtp, int init_id)
4787 struct ccb_immediate_notify *inot;
4788 mpt_tgt_state_t *tgt;
4790 tgt = MPT_TGT_STATE(mpt, req);
4791 inot = (struct ccb_immediate_notify *) STAILQ_FIRST(&trtp->inots);
4793 mpt_lprt(mpt, MPT_PRT_WARN, "no INOTSs- sending back BSY\n");
4794 mpt_scsi_tgt_status(mpt, NULL, req, SCSI_STATUS_BUSY, NULL, 0);
4797 STAILQ_REMOVE_HEAD(&trtp->inots, sim_links.stqe);
4798 mpt_lprt(mpt, MPT_PRT_DEBUG1,
4799 "Get FREE INOT %p lun %jx\n", inot,
4800 (uintmax_t)inot->ccb_h.target_lun);
4802 inot->initiator_id = init_id; /* XXX */
4803 inot->tag_id = tgt->tag_id;
4806 * This is a somewhat grotesque attempt to map from task management
4807 * to old style SCSI messages. God help us all.
4810 case MPT_QUERY_TASK_SET:
4811 inot->arg = MSG_QUERY_TASK_SET;
4813 case MPT_ABORT_TASK_SET:
4814 inot->arg = MSG_ABORT_TASK_SET;
4816 case MPT_CLEAR_TASK_SET:
4817 inot->arg = MSG_CLEAR_TASK_SET;
4819 case MPT_QUERY_ASYNC_EVENT:
4820 inot->arg = MSG_QUERY_ASYNC_EVENT;
4822 case MPT_LOGICAL_UNIT_RESET:
4823 inot->arg = MSG_LOGICAL_UNIT_RESET;
4825 case MPT_TARGET_RESET:
4826 inot->arg = MSG_TARGET_RESET;
4829 inot->arg = MSG_CLEAR_ACA;
4832 inot->arg = MSG_NOOP;
4835 tgt->ccb = (union ccb *) inot;
4836 inot->ccb_h.status = CAM_MESSAGE_RECV;
4837 xpt_done((union ccb *)inot);
4841 mpt_scsi_tgt_atio(struct mpt_softc *mpt, request_t *req, uint32_t reply_desc)
4843 static uint8_t null_iqd[SHORT_INQUIRY_LENGTH] = {
4844 0x7f, 0x00, 0x02, 0x02, 0x20, 0x00, 0x00, 0x32,
4845 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ',
4846 'L', 'S', 'I', '-', 'L', 'O', 'G', 'I',
4847 'C', ' ', 'N', 'U', 'L', 'D', 'E', 'V',
4850 struct ccb_accept_tio *atiop;
4853 mpt_tgt_state_t *tgt;
4854 tgt_resource_t *trtp = NULL;
4858 mpt_task_mgmt_t fct = MPT_NIL_TMT_VALUE;
4862 * Stash info for the current command where we can get at it later.
4864 vbuf = req->req_vbuf;
4865 vbuf += MPT_RQSL(mpt);
4866 if (mpt->verbose >= MPT_PRT_DEBUG) {
4867 mpt_dump_data(mpt, "mpt_scsi_tgt_atio response", vbuf,
4868 max(sizeof (MPI_TARGET_FCP_CMD_BUFFER),
4869 max(sizeof (MPI_TARGET_SSP_CMD_BUFFER),
4870 sizeof (MPI_TARGET_SCSI_SPI_CMD_BUFFER))));
4874 * Get our state pointer set up.
4876 tgt = MPT_TGT_STATE(mpt, req);
4877 if (tgt->state != TGT_STATE_LOADED) {
4878 mpt_tgt_dump_req_state(mpt, req);
4879 panic("bad target state in mpt_scsi_tgt_atio");
4881 memset(tgt, 0, sizeof (mpt_tgt_state_t));
4882 tgt->state = TGT_STATE_IN_CAM;
4883 tgt->reply_desc = reply_desc;
4884 ioindex = GET_IO_INDEX(reply_desc);
4887 * The tag we construct here allows us to find the
4888 * original request that the command came in with.
4890 * This way we don't have to depend on anything but the
4891 * tag to find things when CCBs show back up from CAM.
4893 tgt->tag_id = MPT_MAKE_TAGID(mpt, req, ioindex);
4896 PTR_MPI_TARGET_FCP_CMD_BUFFER fc;
4897 fc = (PTR_MPI_TARGET_FCP_CMD_BUFFER) vbuf;
4898 if (fc->FcpCntl[2]) {
4900 * Task Management Request
4902 switch (fc->FcpCntl[2]) {
4904 fct = MPT_QUERY_TASK_SET;
4907 fct = MPT_ABORT_TASK_SET;
4910 fct = MPT_CLEAR_TASK_SET;
4913 fct = MPT_QUERY_ASYNC_EVENT;
4916 fct = MPT_LOGICAL_UNIT_RESET;
4919 fct = MPT_TARGET_RESET;
4922 fct = MPT_CLEAR_ACA;
4925 mpt_prt(mpt, "CORRUPTED TASK MGMT BITS: 0x%x\n",
4927 mpt_scsi_tgt_status(mpt, NULL, req,
4928 SCSI_STATUS_OK, NULL, 0);
4932 switch (fc->FcpCntl[1]) {
4934 tag_action = MSG_SIMPLE_Q_TAG;
4937 tag_action = MSG_HEAD_OF_Q_TAG;
4940 tag_action = MSG_ORDERED_Q_TAG;
4944 * Bah. Ignore Untagged Queing and ACA
4946 tag_action = MSG_SIMPLE_Q_TAG;
4950 tgt->resid = be32toh(fc->FcpDl);
4952 lunptr = fc->FcpLun;
4953 tgt->itag = fc->OptionalOxid;
4954 } else if (mpt->is_sas) {
4955 PTR_MPI_TARGET_SSP_CMD_BUFFER ssp;
4956 ssp = (PTR_MPI_TARGET_SSP_CMD_BUFFER) vbuf;
4958 lunptr = ssp->LogicalUnitNumber;
4959 tgt->itag = ssp->InitiatorTag;
4961 PTR_MPI_TARGET_SCSI_SPI_CMD_BUFFER sp;
4962 sp = (PTR_MPI_TARGET_SCSI_SPI_CMD_BUFFER) vbuf;
4964 lunptr = sp->LogicalUnitNumber;
4965 tgt->itag = sp->Tag;
4968 lun = CAM_EXTLUN_BYTE_SWIZZLE(be64dec(lunptr));
4971 * Deal with non-enabled or bad luns here.
4973 if (lun >= MPT_MAX_LUNS || mpt->tenabled == 0 ||
4974 mpt->trt[lun].enabled == 0) {
4975 if (mpt->twildcard) {
4976 trtp = &mpt->trt_wildcard;
4977 } else if (fct == MPT_NIL_TMT_VALUE) {
4979 * In this case, we haven't got an upstream listener
4980 * for either a specific lun or wildcard luns. We
4981 * have to make some sensible response. For regular
4982 * inquiry, just return some NOT HERE inquiry data.
4983 * For VPD inquiry, report illegal field in cdb.
4984 * For REQUEST SENSE, just return NO SENSE data.
4985 * REPORT LUNS gets illegal command.
4986 * All other commands get 'no such device'.
4988 uint8_t sense[MPT_SENSE_SIZE];
4991 memset(sense, 0, sizeof(sense));
5004 len = min(tgt->resid, cdbp[4]);
5005 len = min(len, sizeof (null_iqd));
5006 mpt_lprt(mpt, MPT_PRT_DEBUG,
5007 "local inquiry %ld bytes\n", (long) len);
5008 mpt_scsi_tgt_local(mpt, req, lun, 1,
5015 len = min(tgt->resid, cdbp[4]);
5016 len = min(len, sizeof (sense));
5017 mpt_lprt(mpt, MPT_PRT_DEBUG,
5018 "local reqsense %ld bytes\n", (long) len);
5019 mpt_scsi_tgt_local(mpt, req, lun, 1,
5024 mpt_lprt(mpt, MPT_PRT_DEBUG, "REPORT LUNS\n");
5028 mpt_lprt(mpt, MPT_PRT_DEBUG,
5029 "CMD 0x%x to unmanaged lun %jx\n",
5030 cdbp[0], (uintmax_t)lun);
5034 mpt_scsi_tgt_status(mpt, NULL, req,
5035 SCSI_STATUS_CHECK_COND, sense, sizeof(sense));
5038 /* otherwise, leave trtp NULL */
5040 trtp = &mpt->trt[lun];
5044 * Deal with any task management
5046 if (fct != MPT_NIL_TMT_VALUE) {
5048 mpt_prt(mpt, "task mgmt function %x but no listener\n",
5050 mpt_scsi_tgt_status(mpt, NULL, req,
5051 SCSI_STATUS_OK, NULL, 0);
5053 mpt_scsi_tgt_tsk_mgmt(mpt, req, fct, trtp,
5054 GET_INITIATOR_INDEX(reply_desc));
5060 atiop = (struct ccb_accept_tio *) STAILQ_FIRST(&trtp->atios);
5061 if (atiop == NULL) {
5062 mpt_lprt(mpt, MPT_PRT_WARN,
5063 "no ATIOs for lun %jx- sending back %s\n", (uintmax_t)lun,
5064 mpt->tenabled? "QUEUE FULL" : "BUSY");
5065 mpt_scsi_tgt_status(mpt, NULL, req,
5066 mpt->tenabled? SCSI_STATUS_QUEUE_FULL : SCSI_STATUS_BUSY,
5070 STAILQ_REMOVE_HEAD(&trtp->atios, sim_links.stqe);
5071 mpt_lprt(mpt, MPT_PRT_DEBUG1,
5072 "Get FREE ATIO %p lun %jx\n", atiop,
5073 (uintmax_t)atiop->ccb_h.target_lun);
5074 atiop->ccb_h.ccb_mpt_ptr = mpt;
5075 atiop->ccb_h.status = CAM_CDB_RECVD;
5076 atiop->ccb_h.target_lun = lun;
5077 atiop->sense_len = 0;
5078 atiop->tag_id = tgt->tag_id;
5079 atiop->init_id = GET_INITIATOR_INDEX(reply_desc);
5080 atiop->cdb_len = 16;
5081 memcpy(atiop->cdb_io.cdb_bytes, cdbp, atiop->cdb_len);
5083 atiop->tag_action = tag_action;
5084 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
5086 if (mpt->verbose >= MPT_PRT_DEBUG) {
5088 mpt_prt(mpt, "START_CCB %p for lun %jx CDB=<", atiop,
5089 (uintmax_t)atiop->ccb_h.target_lun);
5090 for (i = 0; i < atiop->cdb_len; i++) {
5091 mpt_prtc(mpt, "%02x%c", cdbp[i] & 0xff,
5092 (i == (atiop->cdb_len - 1))? '>' : ' ');
5094 mpt_prtc(mpt, " itag %x tag %x rdesc %x dl=%u\n",
5095 tgt->itag, tgt->tag_id, tgt->reply_desc, tgt->resid);
5098 xpt_done((union ccb *)atiop);
5102 mpt_tgt_dump_tgt_state(struct mpt_softc *mpt, request_t *req)
5104 mpt_tgt_state_t *tgt = MPT_TGT_STATE(mpt, req);
5106 mpt_prt(mpt, "req %p:%u tgt:rdesc 0x%x resid %u xfrd %u ccb %p treq %p "
5107 "nx %d tag 0x%08x itag 0x%04x state=%d\n", req, req->serno,
5108 tgt->reply_desc, tgt->resid, tgt->bytes_xfered, tgt->ccb,
5109 tgt->req, tgt->nxfers, tgt->tag_id, tgt->itag, tgt->state);
5113 mpt_tgt_dump_req_state(struct mpt_softc *mpt, request_t *req)
5116 mpt_prt(mpt, "req %p:%u index %u (%x) state %x\n", req, req->serno,
5117 req->index, req->index, req->state);
5118 mpt_tgt_dump_tgt_state(mpt, req);
5122 mpt_scsi_tgt_reply_handler(struct mpt_softc *mpt, request_t *req,
5123 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
5129 if (reply_frame == NULL) {
5131 * Figure out what the state of the command is.
5133 mpt_tgt_state_t *tgt = MPT_TGT_STATE(mpt, req);
5136 mpt_req_spcl(mpt, req, "turbo scsi_tgt_reply", __LINE__);
5138 mpt_req_not_spcl(mpt, tgt->req,
5139 "turbo scsi_tgt_reply associated req", __LINE__);
5142 switch(tgt->state) {
5143 case TGT_STATE_LOADED:
5145 * This is a new command starting.
5147 mpt_scsi_tgt_atio(mpt, req, reply_desc);
5149 case TGT_STATE_MOVING_DATA:
5152 if (tgt->req == NULL) {
5153 panic("mpt: turbo target reply with null "
5154 "associated request moving data");
5158 if (tgt->is_local == 0) {
5159 panic("mpt: turbo target reply with "
5160 "null associated ccb moving data");
5163 mpt_lprt(mpt, MPT_PRT_DEBUG,
5164 "TARGET_ASSIST local done\n");
5165 TAILQ_REMOVE(&mpt->request_pending_list,
5167 mpt_free_request(mpt, tgt->req);
5169 mpt_scsi_tgt_status(mpt, NULL, req,
5175 mpt_req_untimeout(tgt->req, mpt_timeout, ccb);
5176 mpt_lprt(mpt, MPT_PRT_DEBUG,
5177 "TARGET_ASSIST %p (req %p:%u) done tag 0x%x\n",
5178 ccb, tgt->req, tgt->req->serno, ccb->csio.tag_id);
5180 * Free the Target Assist Request
5182 KASSERT(tgt->req->ccb == ccb,
5183 ("tgt->req %p:%u tgt->req->ccb %p", tgt->req,
5184 tgt->req->serno, tgt->req->ccb));
5185 TAILQ_REMOVE(&mpt->request_pending_list,
5187 mpt_free_request(mpt, tgt->req);
5191 * Do we need to send status now? That is, are
5192 * we done with all our data transfers?
5194 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
5195 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
5196 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
5197 KASSERT(ccb->ccb_h.status,
5198 ("zero ccb sts at %d", __LINE__));
5199 tgt->state = TGT_STATE_IN_CAM;
5200 if (mpt->outofbeer) {
5201 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
5203 mpt_lprt(mpt, MPT_PRT_DEBUG, "THAWQ\n");
5209 * Otherwise, send status (and sense)
5211 mpt_scsi_tgt_status(mpt, ccb, req,
5212 ccb->csio.scsi_status,
5213 (void *)&ccb->csio.sense_data,
5214 (ccb->ccb_h.flags & CAM_SEND_SENSE) ?
5215 ccb->csio.sense_len : 0);
5218 case TGT_STATE_SENDING_STATUS:
5219 case TGT_STATE_MOVING_DATA_AND_STATUS:
5224 if (tgt->req == NULL) {
5225 panic("mpt: turbo target reply with null "
5226 "associated request sending status");
5233 TGT_STATE_MOVING_DATA_AND_STATUS) {
5236 mpt_req_untimeout(tgt->req, mpt_timeout, ccb);
5237 if (ccb->ccb_h.flags & CAM_SEND_SENSE) {
5238 ccb->ccb_h.status |= CAM_SENT_SENSE;
5240 mpt_lprt(mpt, MPT_PRT_DEBUG,
5241 "TARGET_STATUS tag %x sts %x flgs %x req "
5242 "%p\n", ccb->csio.tag_id, ccb->ccb_h.status,
5243 ccb->ccb_h.flags, tgt->req);
5245 * Free the Target Send Status Request
5247 KASSERT(tgt->req->ccb == ccb,
5248 ("tgt->req %p:%u tgt->req->ccb %p",
5249 tgt->req, tgt->req->serno, tgt->req->ccb));
5251 * Notify CAM that we're done
5253 mpt_set_ccb_status(ccb, CAM_REQ_CMP);
5254 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
5255 KASSERT(ccb->ccb_h.status,
5256 ("ZERO ccb sts at %d", __LINE__));
5259 mpt_lprt(mpt, MPT_PRT_DEBUG,
5260 "TARGET_STATUS non-CAM for req %p:%u\n",
5261 tgt->req, tgt->req->serno);
5263 TAILQ_REMOVE(&mpt->request_pending_list,
5265 mpt_free_request(mpt, tgt->req);
5269 * And re-post the Command Buffer.
5270 * This will reset the state.
5272 ioindex = GET_IO_INDEX(reply_desc);
5273 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
5275 mpt_post_target_command(mpt, req, ioindex);
5278 * And post a done for anyone who cares
5281 if (mpt->outofbeer) {
5282 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
5284 mpt_lprt(mpt, MPT_PRT_DEBUG, "THAWQ\n");
5290 case TGT_STATE_NIL: /* XXX This Never Happens XXX */
5291 tgt->state = TGT_STATE_LOADED;
5294 mpt_prt(mpt, "Unknown Target State 0x%x in Context "
5295 "Reply Function\n", tgt->state);
5300 status = le16toh(reply_frame->IOCStatus);
5301 if (status != MPI_IOCSTATUS_SUCCESS) {
5302 dbg = MPT_PRT_ERROR;
5304 dbg = MPT_PRT_DEBUG1;
5308 "SCSI_TGT REPLY: req=%p:%u reply=%p func=%x IOCstatus 0x%x\n",
5309 req, req->serno, reply_frame, reply_frame->Function, status);
5311 switch (reply_frame->Function) {
5312 case MPI_FUNCTION_TARGET_CMD_BUFFER_POST:
5314 mpt_tgt_state_t *tgt;
5316 mpt_req_spcl(mpt, req, "tgt reply BUFFER POST", __LINE__);
5318 if (status != MPI_IOCSTATUS_SUCCESS) {
5324 tgt = MPT_TGT_STATE(mpt, req);
5325 KASSERT(tgt->state == TGT_STATE_LOADING,
5326 ("bad state 0x%x on reply to buffer post", tgt->state));
5327 mpt_assign_serno(mpt, req);
5328 tgt->state = TGT_STATE_LOADED;
5331 case MPI_FUNCTION_TARGET_ASSIST:
5333 mpt_req_not_spcl(mpt, req, "tgt reply TARGET ASSIST", __LINE__);
5335 mpt_prt(mpt, "target assist completion\n");
5336 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
5337 mpt_free_request(mpt, req);
5339 case MPI_FUNCTION_TARGET_STATUS_SEND:
5341 mpt_req_not_spcl(mpt, req, "tgt reply STATUS SEND", __LINE__);
5343 mpt_prt(mpt, "status send completion\n");
5344 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
5345 mpt_free_request(mpt, req);
5347 case MPI_FUNCTION_TARGET_MODE_ABORT:
5349 PTR_MSG_TARGET_MODE_ABORT_REPLY abtrp =
5350 (PTR_MSG_TARGET_MODE_ABORT_REPLY) reply_frame;
5351 PTR_MSG_TARGET_MODE_ABORT abtp =
5352 (PTR_MSG_TARGET_MODE_ABORT) req->req_vbuf;
5353 uint32_t cc = GET_IO_INDEX(le32toh(abtp->ReplyWord));
5355 mpt_req_not_spcl(mpt, req, "tgt reply TMODE ABORT", __LINE__);
5357 mpt_prt(mpt, "ABORT RX_ID 0x%x Complete; status 0x%x cnt %u\n",
5358 cc, le16toh(abtrp->IOCStatus), le32toh(abtrp->AbortCount));
5359 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
5360 mpt_free_request(mpt, req);
5364 mpt_prt(mpt, "Unknown Target Address Reply Function code: "
5365 "0x%x\n", reply_frame->Function);