2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
58 * @brief This file contains all of the method implementations that
59 * can be utilized by a user to perform SCSI-to-ATA Translation.
60 * SATI adheres to the www.t10.org SAT specification.
62 * For situations where compliance is not observed, the SATI will
63 * return an error indication (most likely INVALID FIELD IN CDB sense data).
66 #include <dev/isci/scil/sati.h>
67 #include <dev/isci/scil/sati_util.h>
68 #include <dev/isci/scil/sati_atapi.h>
69 #include <dev/isci/scil/sati_callbacks.h>
70 #include <dev/isci/scil/intel_ata.h>
71 #include <dev/isci/scil/intel_scsi.h>
72 #include <dev/isci/scil/intel_sat.h>
73 #include <dev/isci/scil/sati_report_luns.h>
76 //******************************************************************************
77 //* P U B L I C M E T H O D S
78 //******************************************************************************
80 SATI_STATUS sati_atapi_translate_command(
81 SATI_TRANSLATOR_SEQUENCE_T * sequence,
82 SATI_DEVICE_T * sati_device,
88 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
90 SATA_FIS_REG_H2D_T * register_fis =
91 (SATA_FIS_REG_H2D_T *)sati_cb_get_h2d_register_fis_address(atapi_io);
93 U8 io_direction = SATI_DATA_DIRECTION_IN;
95 //No sense response has been set for the translation sequence yet
96 sequence->is_sense_response_set = FALSE;
97 // Default to no translation response required
98 sequence->is_translate_response_required = FALSE;
100 sequence->number_data_bytes_set = 0;
101 sequence->device = sati_device;
102 sequence->command_specific_data.scratch = 0;
104 sati_cb_get_data_direction(scsi_io, &io_direction);
107 if (io_direction == SATI_DATA_DIRECTION_NONE)
108 sequence->protocol = SAT_PROTOCOL_PACKET_NON_DATA;
109 else if (io_direction == SATI_DATA_DIRECTION_IN)
110 sequence->protocol = SAT_PROTOCOL_PACKET_DMA_DATA_IN;
111 else if (io_direction == SATI_DATA_DIRECTION_OUT)
112 sequence->protocol = SAT_PROTOCOL_PACKET_DMA_DATA_OUT;
114 // We don't send Report Luns command out.
115 if (sati_get_cdb_byte(cdb, 0) == SCSI_REPORT_LUNS)
117 status = sati_report_luns_translate_command(
118 sequence, scsi_io, atapi_io
121 else if (sati_cb_get_lun(scsi_io) != 0)
123 sati_scsi_sense_data_construct(
126 SCSI_STATUS_CHECK_CONDITION,
127 SCSI_SENSE_ILLEGAL_REQUEST,
128 SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED,
131 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
135 if (sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE)
136 { //Request Sense command is required.
137 U8 request_sense_cdb[SATI_ATAPI_REQUEST_SENSE_CDB_LENGTH] =
138 {0x3, 0x0, 0x0, 0x0, 0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
140 //set the sequence->protocol to DATA_IN anyway;
141 sequence->protocol = SAT_PROTOCOL_PACKET_DMA_DATA_IN;
143 //set the cdb for Request Sense using command_specific_data field.
144 memcpy(sequence->command_specific_data.sati_atapi_data.request_sense_cdb,
146 SATI_ATAPI_REQUEST_SENSE_CDB_LENGTH
150 //build Packet Fis for any other command translation.
151 register_fis->command = ATA_PACKET;
152 register_fis->features |= ATA_PACKET_FEATURE_DMA;
154 register_fis->fis_type = SATA_FIS_TYPE_REGH2D;
155 register_fis->command_flag = 1;
157 status = SATI_SUCCESS;
164 SATI_STATUS sati_atapi_translate_command_response(
165 SATI_TRANSLATOR_SEQUENCE_T * sequence,
170 SATI_STATUS status = SATI_COMPLETE;
171 U8 * register_fis = sati_cb_get_d2h_register_fis_address(atapi_io);
175 * If the device fault bit is set in the status register, then
176 * set the sense data and return.
178 ata_status = (U8) sati_get_ata_status(register_fis);
179 if (ata_status & ATA_STATUS_REG_DEVICE_FAULT_BIT)
181 sati_scsi_sense_data_construct(
184 SCSI_STATUS_CHECK_CONDITION,
185 SCSI_SENSE_HARDWARE_ERROR,
186 SCSI_ASC_INTERNAL_TARGET_FAILURE,
187 SCSI_ASCQ_INTERNAL_TARGET_FAILURE
190 sequence->device->state = SATI_DEVICE_STATE_DEVICE_FAULT_OCCURRED;
192 return SATI_FAILURE_CHECK_RESPONSE_DATA;
194 else if (ata_status & ATA_STATUS_REG_ERROR_BIT)
196 //reset the register_fis.
197 memset(register_fis, 0, sizeof(SATA_FIS_REG_D2H_T));
199 //Internal Request Sense command is needed.
200 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
201 return SATI_SEQUENCE_INCOMPLETE;
207 void sati_atapi_translate_request_sense_response(
208 SATI_TRANSLATOR_SEQUENCE_T * sequence,
213 //sense data is already in place.
214 SCI_SSP_RESPONSE_IU_T * rsp_iu = (SCI_SSP_RESPONSE_IU_T*)
215 sati_cb_get_response_iu_address(scsi_io);
217 sati_scsi_common_response_iu_construct(
219 SCSI_STATUS_CHECK_CONDITION,
220 sati_scsi_get_sense_data_length(sequence, scsi_io),
221 SCSI_RESPONSE_DATA_PRES_SENSE_DATA
224 sequence->is_sense_response_set = TRUE;
226 sequence->state = SATI_SEQUENCE_STATE_FINAL;
230 U32 sati_atapi_translate_number_of_bytes_transferred(
231 SATI_TRANSLATOR_SEQUENCE_T * sequence,
236 U8* cdb = sati_cb_get_cdb_address(scsi_io);
242 case SCSI_MODE_SENSE_10:
243 sati_cb_get_data_byte(scsi_io, 1, &response_data);
244 data_length = response_data+2;
247 case 0x51: //READ DISC INFORMATION
248 sati_cb_get_data_byte(scsi_io, 1, &response_data);
249 data_length = response_data+2;