2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
60 * @brief This file contains the implementation to translate
61 * SCSI Request Sense command based of the SAT spec.
64 #if !defined(DISABLE_SATI_REQUEST_SENSE)
66 #include <dev/isci/scil/sati_request_sense.h>
67 #include <dev/isci/scil/sati_device.h>
68 #include <dev/isci/scil/sati_util.h>
69 #include <dev/isci/scil/intel_scsi.h>
70 #include <dev/isci/scil/intel_ata.h>
71 #include <dev/isci/scil/intel_sat.h>
72 #include <dev/isci/scil/sati_callbacks.h>
73 #include <dev/isci/scil/sati_mode_pages.h>
79 * @brief This method will translate the SCSI request sense command
80 * into corresponding ATA commands. Depending on supported and enabled
81 * capabilities like SMART, different ATA commands can be selected.
82 * For more information on the parameters passed to this method,
83 * please reference sati_translate_command().
85 * @return Indicates if the command translation succeeded.
86 * @retval SATI_SUCCESS indicates that the translation was supported and occurred
88 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
89 * the SATII is processing a format unit commmand.
90 * @retval SATI_COMPLETE indicates that the translation was supported, occurred without
91 * error, and no additional translation is necessary.
93 SATI_STATUS sati_request_sense_translate_command(
94 SATI_TRANSLATOR_SEQUENCE_T * sequence,
99 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
101 //check if SATI is processing format unit command
102 switch(sequence->device->state)
104 case SATI_DEVICE_STATE_FORMAT_UNIT_IN_PROGRESS:
105 sati_scsi_sense_data_construct(
109 SCSI_SENSE_NOT_READY,
110 SCSI_ASC_LUN_FORMAT_IN_PROGRESS,
111 SCSI_ASCQ_LUN_FORMAT_IN_PROGRESS
113 return SATI_COMPLETE;
116 case SATI_DEVICE_STATE_UNIT_ATTENTION_CONDITION:
117 sati_scsi_sense_data_construct(
121 SCSI_SENSE_UNIT_ATTENTION,
122 sequence->device->unit_attention_asc,
123 sequence->device->unit_attention_ascq
125 return SATI_COMPLETE;
127 //sending sense data status Idle, this is set by start_stop_unit
128 case SATI_DEVICE_STATE_IDLE:
129 sati_scsi_sense_data_construct(
134 SCSI_ASC_POWER_STATE_CHANGE,
135 SCSI_ASCQ_IDLE_CONDITION_ACTIVATE_BY_COMMAND
137 return SATI_COMPLETE;
139 //sending sense data status Standby, this is set by start_stop_unit
140 case SATI_DEVICE_STATE_STANDBY:
141 sati_scsi_sense_data_construct(
146 SCSI_ASC_POWER_STATE_CHANGE,
147 SCSI_ASCQ_STANDBY_CONDITION_ACTIVATE_BY_COMMAND
149 return SATI_COMPLETE;
152 case SATI_DEVICE_STATE_STOPPED:
153 sati_scsi_sense_data_construct(
158 SCSI_ASC_NO_ADDITIONAL_SENSE,
159 SCSI_ASCQ_NO_ADDITIONAL_SENSE
161 return SATI_COMPLETE;
168 sequence->allocation_length = sati_get_cdb_byte(cdb, 4);
170 //Check if the device has SMART support & SMART enabled
171 if(sequence->device->capabilities & SATI_DEVICE_CAP_SMART_SUPPORT)
173 if(sequence->device->capabilities & SATI_DEVICE_CAP_SMART_ENABLE)
175 sati_ata_smart_return_status_construct(
178 ATA_SMART_SUB_CMD_RETURN_STATUS
181 sequence->type = SATI_SEQUENCE_REQUEST_SENSE_SMART_RETURN_STATUS;
185 sati_ata_check_power_mode_construct(ata_io, sequence);
186 sequence->type = SATI_SEQUENCE_REQUEST_SENSE_CHECK_POWER_MODE;
191 * @brief This method will translate the response to the SATI Request Sense
192 * translation. ATA_Check_Power_Mode and ATA_SMART_Return_Status will
193 * be translated into a SCSI sense data response.
195 * @return SATI_STATUS Indicates if the response translation succeeded.
198 SATI_STATUS sati_request_sense_translate_response(
199 SATI_TRANSLATOR_SEQUENCE_T * sequence,
204 U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
208 SATI_STATUS status = SATI_FAILURE;
210 if(sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT)
212 sati_scsi_sense_data_construct(
215 SCSI_STATUS_CHECK_CONDITION,
216 SCSI_SENSE_ABORTED_COMMAND,
217 SCSI_ASC_NO_ADDITIONAL_SENSE ,
218 SCSI_ASCQ_NO_ADDITIONAL_SENSE
220 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
224 switch(sequence->type)
226 case SATI_SEQUENCE_REQUEST_SENSE_SMART_RETURN_STATUS:
228 mid_register = sati_get_ata_lba_mid(register_fis);
229 high_register = sati_get_ata_lba_high(register_fis);
230 if(mid_register == ATA_MID_REGISTER_THRESHOLD_EXCEEDED
231 && high_register == ATA_HIGH_REGISTER_THRESHOLD_EXCEEDED)
233 sati_request_sense_data_response_construct(
237 SCSI_ASC_HARDWARE_IMPENDING_FAILURE,
238 SCSI_ASCQ_GENERAL_HARD_DRIVE_FAILURE
240 status = SATI_COMPLETE;
244 sati_request_sense_data_response_construct(
248 SCSI_ASC_NO_ADDITIONAL_SENSE,
249 SCSI_ASCQ_NO_ADDITIONAL_SENSE
251 status = SATI_COMPLETE;
255 case SATI_SEQUENCE_REQUEST_SENSE_CHECK_POWER_MODE:
257 sector_count = sati_get_ata_sector_count(register_fis);
261 case ATA_STANDBY_POWER_MODE:
262 sati_request_sense_data_response_construct(
266 SCSI_ASC_POWER_STATE_CHANGE,
267 SCSI_ASCQ_POWER_STATE_CHANGE_TO_STANDBY
269 status = SATI_COMPLETE;
272 case ATA_IDLE_POWER_MODE:
273 sati_request_sense_data_response_construct(
277 SCSI_ASC_POWER_STATE_CHANGE,
278 SCSI_ASCQ_POWER_STATE_CHANGE_TO_IDLE
280 status = SATI_COMPLETE;
283 case ATA_ACTIVE_POWER_MODE:
284 sati_request_sense_data_response_construct(
288 SCSI_ASC_NO_ADDITIONAL_SENSE,
289 SCSI_ASCQ_NO_ADDITIONAL_SENSE
291 status = SATI_COMPLETE;
300 sati_request_sense_data_response_construct(
304 SCSI_ASC_NO_ADDITIONAL_SENSE,
305 SCSI_ASCQ_NO_ADDITIONAL_SENSE
307 status = SATI_COMPLETE;
315 * @brief This method will construct a response for the sati_request_sense
316 * translation. The response will be returned in the data buffer instead
317 * of the response buffer, using sense data format described in SPC-4.
320 void sati_request_sense_data_response_construct(
321 SATI_TRANSLATOR_SEQUENCE_T * sequence,
324 U8 additional_sense_code,
325 U8 additional_sense_code_qualifier
332 SCSI_FIXED_CURRENT_RESPONSE_CODE | SCSI_FIXED_SENSE_DATA_VALID_BIT
335 sati_set_data_byte(sequence, scsi_io, 1, 0);
336 sati_set_data_byte(sequence, scsi_io, 2, sense_key);
337 sati_set_data_byte(sequence, scsi_io, 3, 0);
338 sati_set_data_byte(sequence, scsi_io, 4, 0);
339 sati_set_data_byte(sequence, scsi_io, 5, 0);
340 sati_set_data_byte(sequence, scsi_io, 6, 0);
341 sati_set_data_byte(sequence, scsi_io, 7, 0);
342 sati_set_data_byte(sequence, scsi_io, 8, 0);
343 sati_set_data_byte(sequence, scsi_io, 9, 0);
344 sati_set_data_byte(sequence, scsi_io, 10, 0);
345 sati_set_data_byte(sequence, scsi_io, 11, 0);
346 sati_set_data_byte(sequence, scsi_io, 12, additional_sense_code);
347 sati_set_data_byte(sequence, scsi_io, 13, additional_sense_code_qualifier);
348 sati_set_data_byte(sequence, scsi_io, 14, 0);
349 sati_set_data_byte(sequence, scsi_io, 15, 0);
350 sati_set_data_byte(sequence, scsi_io, 16, 0);
351 sati_set_data_byte(sequence, scsi_io, 17, 0);
354 #endif // !defined(DISABLE_SATI_REQUEST_SENSE)