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 the method implementations required to
59 * translate the SCSI start stop unit command.
62 #if !defined(DISABLE_SATI_START_STOP_UNIT)
64 #include <dev/isci/scil/sati_start_stop_unit.h>
65 #include <dev/isci/scil/sati_util.h>
66 #include <dev/isci/scil/sati_callbacks.h>
67 #include <dev/isci/scil/intel_ata.h>
68 #include <dev/isci/scil/intel_scsi.h>
71 * @brief This method will translate the start stop unit SCSI command into
72 * various ATA commands depends on the value in POWER CONTIDTION, LOEJ
74 * For more information on the parameters passed to this method,
75 * please reference sati_translate_command().
77 * @return Indicate if the command translation succeeded.
78 * @retval SCI_SUCCESS This is returned if the command translation was
80 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA Please refer to spec.
83 SATI_STATUS sati_start_stop_unit_translate_command(
84 SATI_TRANSLATOR_SEQUENCE_T * sequence,
89 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
91 switch ( SATI_START_STOP_UNIT_POWER_CONDITION(cdb) )
93 case SCSI_START_STOP_UNIT_POWER_CONDITION_START_VALID:
94 if ( SATI_START_STOP_UNIT_START_BIT(cdb) == 0
95 && SATI_START_STOP_UNIT_LOEJ_BIT(cdb) == 0 )
97 if ( SATI_START_STOP_UNIT_NO_FLUSH_BIT(cdb) == 1 )
99 //directly send ATA STANDBY_IMMEDIATE
100 sati_ata_standby_immediate_construct(ata_io, sequence);
101 sequence->command_specific_data.translated_command = ATA_STANDBY_IMMED;
105 if ( sequence->state != SATI_SEQUENCE_STATE_INCOMPLETE )
107 //First, send ATA flush command.
108 sati_ata_flush_cache_construct(ata_io, sequence);
109 sequence->command_specific_data.translated_command = ATA_FLUSH_CACHE;
111 //remember there is next step.
112 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
116 //the first step, flush cache command, has completed.
117 //Send standby immediate now.
118 sati_ata_standby_immediate_construct(ata_io, sequence);
119 sequence->command_specific_data.translated_command = ATA_STANDBY_IMMED;
124 else if ( SATI_START_STOP_UNIT_START_BIT(cdb) == 0
125 && SATI_START_STOP_UNIT_LOEJ_BIT(cdb) == 1 )
127 //need to know whether the device supports removable medial feature set.
128 if (sequence->device->capabilities & SATI_DEVICE_CAP_REMOVABLE_MEDIA)
130 //send ATA MEDIA EJECT command.
131 sati_ata_media_eject_construct(ata_io, sequence);
132 sequence->command_specific_data.translated_command = ATA_MEDIA_EJECT;
136 sati_scsi_sense_data_construct(
139 SCSI_STATUS_CHECK_CONDITION,
140 SCSI_SENSE_ILLEGAL_REQUEST,
141 SCSI_ASC_INVALID_FIELD_IN_CDB,
142 SCSI_ASCQ_INVALID_FIELD_IN_CDB
144 return SATI_FAILURE_CHECK_RESPONSE_DATA;
147 else if ( SATI_START_STOP_UNIT_START_BIT(cdb) == 1
148 && SATI_START_STOP_UNIT_LOEJ_BIT(cdb) == 0 )
150 //send an ATA verify command
151 sati_ata_read_verify_sectors_construct(ata_io, sequence);
152 sequence->command_specific_data.translated_command = ATA_READ_VERIFY_SECTORS;
154 else if ( SATI_START_STOP_UNIT_START_BIT(cdb) == 1
155 && SATI_START_STOP_UNIT_LOEJ_BIT(cdb) == 1 )
157 sati_scsi_sense_data_construct(
160 SCSI_STATUS_CHECK_CONDITION,
161 SCSI_SENSE_ILLEGAL_REQUEST,
162 SCSI_ASC_INVALID_FIELD_IN_CDB,
163 SCSI_ASCQ_INVALID_FIELD_IN_CDB
165 return SATI_FAILURE_CHECK_RESPONSE_DATA;
169 //Power Condition Field is set to 0x01(Device to transition to Active state)
170 case SCSI_START_STOP_UNIT_POWER_CONDITION_ACTIVE:
172 if( sequence->state != SATI_SEQUENCE_STATE_INCOMPLETE )
174 sati_ata_idle_construct(ata_io, sequence);
175 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
176 sequence->command_specific_data.translated_command = ATA_IDLE;
180 sati_ata_read_verify_sectors_construct(ata_io, sequence);
181 sequence->command_specific_data.translated_command = ATA_READ_VERIFY_SECTORS;
185 //Power Condition Field is set to 0x02(Device to transition to Idle state)
186 case SCSI_START_STOP_UNIT_POWER_CONDITION_IDLE:
188 if( SATI_START_STOP_UNIT_NO_FLUSH_BIT(cdb) == 0 &&
189 sequence->state != SATI_SEQUENCE_STATE_INCOMPLETE )
191 sati_ata_flush_cache_construct(ata_io, sequence);
192 sequence->command_specific_data.translated_command = ATA_FLUSH_CACHE;
193 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
197 if( SATI_START_STOP_UNIT_POWER_CONDITION_MODIFIER(cdb) == 0 )
199 sati_ata_idle_immediate_construct(ata_io, sequence);
203 sati_ata_idle_immediate_unload_construct(ata_io, sequence);
205 sequence->command_specific_data.translated_command = ATA_IDLE_IMMED;
209 //Power Condition Field is set to 0x03(Device to transition to Standby state)
210 case SCSI_START_STOP_UNIT_POWER_CONDITION_STANDBY:
211 if( SATI_START_STOP_UNIT_NO_FLUSH_BIT(cdb) == 0 &&
212 sequence->state != SATI_SEQUENCE_STATE_INCOMPLETE )
214 sati_ata_flush_cache_construct(ata_io, sequence);
215 sequence->command_specific_data.translated_command = ATA_FLUSH_CACHE;
216 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
220 sati_ata_standby_immediate_construct(ata_io, sequence);
221 sequence->command_specific_data.translated_command = ATA_STANDBY_IMMED;
225 //Power Condition Field is set to 0xB(force Standby state)
226 case SCSI_START_STOP_UNIT_POWER_CONDITION_FORCE_S_CONTROL:
228 if( SATI_START_STOP_UNIT_NO_FLUSH_BIT(cdb) == 0 &&
229 sequence->state != SATI_SEQUENCE_STATE_INCOMPLETE )
231 sati_ata_flush_cache_construct(ata_io, sequence);
232 sequence->command_specific_data.translated_command = ATA_FLUSH_CACHE;
233 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
237 sati_ata_standby_construct(ata_io, sequence, 0);
238 sequence->command_specific_data.translated_command = ATA_STANDBY;
242 case SCSI_START_STOP_UNIT_POWER_CONDITION_LU_CONTROL:
244 sati_scsi_sense_data_construct(
247 SCSI_STATUS_CHECK_CONDITION,
248 SCSI_SENSE_ILLEGAL_REQUEST,
249 SCSI_ASC_INVALID_FIELD_IN_CDB,
250 SCSI_ASCQ_INVALID_FIELD_IN_CDB
252 return SATI_FAILURE_CHECK_RESPONSE_DATA;
256 if ( SATI_START_STOP_UNIT_IMMED_BIT(cdb) == 1 )
258 //@todo: return good status now.
261 sequence->type = SATI_SEQUENCE_START_STOP_UNIT;
267 * @brief This method will translate the ATA command register FIS
268 * response into an appropriate SCSI response for START STOP UNIT.
269 * For more information on the parameters passed to this method,
270 * please reference sati_translate_response().
272 * @return Indicate if the response translation succeeded.
273 * @retval SCI_SUCCESS This is returned if the data translation was
276 SATI_STATUS sati_start_stop_unit_translate_response(
277 SATI_TRANSLATOR_SEQUENCE_T * sequence,
282 U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
283 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
285 if (sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT)
287 switch ( sequence->command_specific_data.translated_command )
289 case ATA_FLUSH_CACHE:
290 case ATA_STANDBY_IMMED:
294 //Note: There is lack of reference in spec of the error handling for
295 //READ_VERIFY command.
296 case ATA_READ_VERIFY_SECTORS:
297 sati_scsi_sense_data_construct(
300 SCSI_STATUS_CHECK_CONDITION,
301 SCSI_SENSE_ABORTED_COMMAND,
302 SCSI_ASC_COMMAND_SEQUENCE_ERROR,
303 SCSI_ASCQ_NO_ADDITIONAL_SENSE
307 case ATA_MEDIA_EJECT:
308 sati_scsi_sense_data_construct(
311 SCSI_STATUS_CHECK_CONDITION,
312 SCSI_SENSE_ABORTED_COMMAND,
313 SCSI_ASC_MEDIA_LOAD_OR_EJECT_FAILED,
314 SCSI_ASCQ_NO_ADDITIONAL_SENSE
319 sati_scsi_sense_data_construct(
322 SCSI_STATUS_CHECK_CONDITION,
323 SCSI_SENSE_ILLEGAL_REQUEST,
324 SCSI_ASC_INVALID_FIELD_IN_CDB,
325 SCSI_ASCQ_INVALID_FIELD_IN_CDB
329 sequence->state = SATI_SEQUENCE_STATE_FINAL;
330 return SATI_FAILURE_CHECK_RESPONSE_DATA;
334 switch ( sequence->command_specific_data.translated_command )
336 case ATA_READ_VERIFY_SECTORS:
338 sati_scsi_sense_data_construct(
343 SCSI_ASC_NO_ADDITIONAL_SENSE,
344 SCSI_ASCQ_NO_ADDITIONAL_SENSE
346 //device state is now operational(active)
347 sequence->device->state = SATI_DEVICE_STATE_OPERATIONAL;
348 sequence->state = SATI_SEQUENCE_STATE_FINAL;
353 sati_scsi_sense_data_construct(
358 SCSI_ASC_NO_ADDITIONAL_SENSE,
359 SCSI_ASCQ_NO_ADDITIONAL_SENSE
361 sequence->device->state = SATI_DEVICE_STATE_IDLE;
362 sequence->state = SATI_SEQUENCE_STATE_FINAL;
365 //These three commands will be issued when the power condition is 0x00 or 0x03
366 case ATA_MEDIA_EJECT:
368 case ATA_STANDBY_IMMED:
370 sati_scsi_sense_data_construct(
375 SCSI_ASC_NO_ADDITIONAL_SENSE,
376 SCSI_ASCQ_NO_ADDITIONAL_SENSE
379 if( SATI_START_STOP_UNIT_POWER_CONDITION(cdb) == 0 )
381 sequence->device->state = SATI_DEVICE_STATE_STOPPED;
385 sequence->device->state = SATI_DEVICE_STATE_STANDBY;
387 sequence->state = SATI_SEQUENCE_STATE_FINAL;
391 //FLUSH Cache command does not require any success handling
395 if (sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE)
397 return SATI_SEQUENCE_INCOMPLETE;
400 return SATI_COMPLETE;
403 #endif // !defined(DISABLE_SATI_START_STOP_UNIT)