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 read capacity (10 byte) command.
62 #if !defined(DISABLE_SATI_READ_CAPACITY)
64 #include <dev/isci/scil/sati_read_capacity.h>
65 #include <dev/isci/scil/sati_callbacks.h>
66 #include <dev/isci/scil/sati_util.h>
67 #include <dev/isci/scil/intel_ata.h>
68 #include <dev/isci/scil/intel_scsi.h>
71 * @brief This method will translate the read capacity 10 SCSI command into
72 * an ATA IDENTIFY DEVICE command.
73 * For more information on the parameters passed to this method,
74 * please reference sati_translate_command().
76 * @return Indicate if the command translation succeeded.
77 * @retval SCI_SUCCESS This is returned if the command translation was
79 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if the
80 * LBA field is not 0, the PMI bit is not 0.
82 SATI_STATUS sati_read_capacity_10_translate_command(
83 SATI_TRANSLATOR_SEQUENCE_T * sequence,
88 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
92 * - the LBA field must be 0
93 * - the PMI bit must be 0
97 (sati_get_cdb_byte(cdb, 2) != 0)
98 || (sati_get_cdb_byte(cdb, 3) != 0)
99 || (sati_get_cdb_byte(cdb, 4) != 0)
100 || (sati_get_cdb_byte(cdb, 5) != 0)
102 || ((sati_get_cdb_byte(cdb, 8) & SCSI_READ_CAPACITY_PMI_BIT_ENABLE)
106 sati_scsi_sense_data_construct(
109 SCSI_STATUS_CHECK_CONDITION,
110 SCSI_SENSE_ILLEGAL_REQUEST,
111 SCSI_ASC_INVALID_FIELD_IN_CDB,
112 SCSI_ASCQ_INVALID_FIELD_IN_CDB
114 return SATI_FAILURE_CHECK_RESPONSE_DATA;
117 // The CDB is properly formed.
118 sequence->allocation_length = SCSI_READ_CAPACITY_10_DATA_LENGTH;
119 sequence->type = SATI_SEQUENCE_READ_CAPACITY_10;
121 sati_ata_identify_device_construct(ata_io, sequence);
128 * @brief This method will translate the read capacity 16 SCSI command into
129 * an ATA IDENTIFY DEVICE command.
130 * For more information on the parameters passed to this method,
131 * please reference sati_translate_command().
133 * @return Indicate if the command translation succeeded.
134 * @retval SCI_SUCCESS This is returned if the command translation was
136 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if the
137 * LBA field is not 0, the PMI bit is not 0.
139 SATI_STATUS sati_read_capacity_16_translate_command(
140 SATI_TRANSLATOR_SEQUENCE_T * sequence,
145 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
149 * - the LBA field must be 0
150 * - the PMI bit must be 0
154 (sati_get_cdb_byte(cdb, 2) != 0)
155 || (sati_get_cdb_byte(cdb, 3) != 0)
156 || (sati_get_cdb_byte(cdb, 4) != 0)
157 || (sati_get_cdb_byte(cdb, 5) != 0)
158 || (sati_get_cdb_byte(cdb, 6) != 0)
159 || (sati_get_cdb_byte(cdb, 7) != 0)
160 || (sati_get_cdb_byte(cdb, 8) != 0)
161 || (sati_get_cdb_byte(cdb, 9) != 0)
163 || ((sati_get_cdb_byte(cdb, 14) & SCSI_READ_CAPACITY_PMI_BIT_ENABLE)
167 sati_scsi_sense_data_construct(
170 SCSI_STATUS_CHECK_CONDITION,
171 SCSI_SENSE_ILLEGAL_REQUEST,
172 SCSI_ASC_INVALID_FIELD_IN_CDB,
173 SCSI_ASCQ_INVALID_FIELD_IN_CDB
175 return SATI_FAILURE_CHECK_RESPONSE_DATA;
178 // The CDB is properly formed.
179 sequence->allocation_length = (sati_get_cdb_byte(cdb, 10) << 24) |
180 (sati_get_cdb_byte(cdb, 11) << 16) |
181 (sati_get_cdb_byte(cdb, 12) << 8) |
182 (sati_get_cdb_byte(cdb, 13));
184 sequence->type = SATI_SEQUENCE_READ_CAPACITY_16;
186 sati_ata_identify_device_construct(ata_io, sequence);
191 * @brief This method will translate the ATA Identify Device data into
192 * SCSI read capacity 10 data.
193 * For more information on the parameters passed to this method,
194 * please reference sati_translate_data().
198 void sati_read_capacity_10_translate_data(
199 SATI_TRANSLATOR_SEQUENCE_T * sequence,
200 void * ata_input_data,
208 // Extract the sector information (sector size, logical blocks) from
209 // the retrieved ATA identify device data.
210 sati_ata_identify_device_get_sector_info(
211 (ATA_IDENTIFY_DEVICE_DATA_T*)ata_input_data,
217 // SATA drives report a value that is one LBA larger than the last LBA.
218 // SCSI wants the last LBA. Make the correction here. lba_low is
219 // always decremented since it is an unsigned long the value 0 will
220 // wrap to 0xFFFFFFFF.
221 if ((lba_low == 0) && (lba_high == 0))
227 sati_set_data_byte(sequence, scsi_io, 0, 0xFF);
228 sati_set_data_byte(sequence, scsi_io, 1, 0xFF);
229 sati_set_data_byte(sequence, scsi_io, 2, 0xFF);
230 sati_set_data_byte(sequence, scsi_io, 3, 0xFF);
234 // Build CDB for Read Capacity 10
235 // Fill in the Logical Block Address bytes.
236 sati_set_data_byte(sequence, scsi_io, 0, (U8)((lba_low >> 24) & 0xFF));
237 sati_set_data_byte(sequence, scsi_io, 1, (U8)((lba_low >> 16) & 0xFF));
238 sati_set_data_byte(sequence, scsi_io, 2, (U8)((lba_low >> 8) & 0xFF));
239 sati_set_data_byte(sequence, scsi_io, 3, (U8)(lba_low & 0xFF));
241 // Fill in the sector size field.
242 sati_set_data_byte(sequence, scsi_io, 4, (U8)((sector_size >> 24) & 0xFF));
243 sati_set_data_byte(sequence, scsi_io, 5, (U8)((sector_size >> 16) & 0xFF));
244 sati_set_data_byte(sequence, scsi_io, 6, (U8)((sector_size >> 8) & 0xFF));
245 sati_set_data_byte(sequence, scsi_io, 7, (U8)(sector_size & 0xFF));
249 * @brief This method will translate the ATA Identify Device data into
250 * SCSI read capacity 16 data.
251 * For more information on the parameters passed to this method,
252 * please reference sati_translate_data().
256 void sati_read_capacity_16_translate_data(
257 SATI_TRANSLATOR_SEQUENCE_T * sequence,
258 void * ata_input_data,
265 ATA_IDENTIFY_DEVICE_DATA_T * identify_device_data;
266 U16 physical_per_logical_enable_bit = 0;
267 U8 physical_per_logical_sector_exponent = 0;
268 U16 physical_per_logical_sector = 0;
269 U16 logical_sector_alignment = 0;
270 U16 scsi_logical_sector_alignment = 0;
273 //A number of data fields need to be extracted from ATA identify device data
274 identify_device_data = (ATA_IDENTIFY_DEVICE_DATA_T*)ata_input_data;
276 // Extract the sector information (sector size, logical blocks) from
277 // the retrieved ATA identify device data.
278 sati_ata_identify_device_get_sector_info(
279 (ATA_IDENTIFY_DEVICE_DATA_T*)ata_input_data,
285 // SATA drives report a value that is one LBA larger than the last LBA.
286 // SCSI wants the last LBA. Make the correction here. lba_low is
287 // always decremented since it is an unsigned long the value 0 will
288 // wrap to 0xFFFFFFFF.
289 if ((lba_low == 0) && (lba_high == 0))
293 // Build the CDB for Read Capacity 16
294 // Fill in the Logical Block Address bytes.
295 sati_set_data_byte(sequence, scsi_io, 0, (U8)((lba_high >> 24) & 0xFF));
296 sati_set_data_byte(sequence, scsi_io, 1, (U8)((lba_high >> 16) & 0xFF));
297 sati_set_data_byte(sequence, scsi_io, 2, (U8)((lba_high >> 8) & 0xFF));
298 sati_set_data_byte(sequence, scsi_io, 3, (U8)(lba_high & 0xFF));
300 sati_set_data_byte(sequence, scsi_io, 4, (U8)((lba_low >> 24) & 0xFF));
301 sati_set_data_byte(sequence, scsi_io, 5, (U8)((lba_low >> 16) & 0xFF));
302 sati_set_data_byte(sequence, scsi_io, 6, (U8)((lba_low >> 8) & 0xFF));
303 sati_set_data_byte(sequence, scsi_io, 7, (U8)(lba_low & 0xFF));
305 //Fill in the sector size field.
306 sati_set_data_byte(sequence, scsi_io, 8, (U8)((sector_size >> 24) & 0xFF));
307 sati_set_data_byte(sequence, scsi_io, 9, (U8)((sector_size >> 16) & 0xFF));
308 sati_set_data_byte(sequence, scsi_io, 10, (U8)((sector_size >> 8) & 0xFF));
309 sati_set_data_byte(sequence, scsi_io, 11, (U8)(sector_size & 0xFF));
311 //Explicitly set byte 12 to 0. SATI requires that all bytes in the data
312 //response be explicitly set to some value.
313 sati_set_data_byte(sequence, scsi_io, 12, 0);
315 //Check Bit 13 of ATA_IDENTIFY_DEVICE_DATA physical_logical_sector_info
316 //(Word 106) is enabled
317 physical_per_logical_enable_bit = (identify_device_data->physical_logical_sector_info
318 & ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_ENABLE);
320 //Extract the Physical per logical sector exponent field and calculate
321 //Physical per logical sector value
322 physical_per_logical_sector_exponent = (U8) (identify_device_data->physical_logical_sector_info
323 & ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_MASK);
324 physical_per_logical_sector = 1 << (physical_per_logical_sector_exponent);
326 //If the data is valid, fill in the logical blocks per physical block exponent field.
327 //Else set logical blocks per physical block exponent to 1
328 if (physical_per_logical_enable_bit != 0)
333 (U8)(physical_per_logical_sector_exponent & 0xFF)
336 sati_set_data_byte(sequence, scsi_io, 13, 0);
338 //Fill in the lowest aligned logical block address field.
339 logical_sector_alignment = identify_device_data->logical_sector_alignment;
340 if (logical_sector_alignment == 0)
341 scsi_logical_sector_alignment = 0;
343 scsi_logical_sector_alignment = (physical_per_logical_sector - logical_sector_alignment)
344 % physical_per_logical_sector;
346 //Follow SAT for reporting tprz and tpe
347 if ((sequence->device->capabilities & SATI_DEVICE_CAP_DSM_TRIM_SUPPORT) &&
348 (sequence->device->capabilities & SATI_DEVICE_CAP_DETERMINISTIC_READ_AFTER_TRIM))
353 if (sequence->device->capabilities & SATI_DEVICE_CAP_READ_ZERO_AFTER_TRIM)
360 (U8)(((scsi_logical_sector_alignment >>8) & 0x3F) | byte14));
366 (U8)(scsi_logical_sector_alignment & 0xFF));
369 #endif // !defined(DISABLE_SATI_READ_CAPACITY)