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 method implementations required to
61 * translate the SCSI read capacity (10 byte) command.
64 #if !defined(DISABLE_SATI_READ_CAPACITY)
66 #include <dev/isci/scil/sati_read_capacity.h>
67 #include <dev/isci/scil/sati_callbacks.h>
68 #include <dev/isci/scil/sati_util.h>
69 #include <dev/isci/scil/intel_ata.h>
70 #include <dev/isci/scil/intel_scsi.h>
73 * @brief This method will translate the read capacity 10 SCSI command into
74 * an ATA IDENTIFY DEVICE command.
75 * For more information on the parameters passed to this method,
76 * please reference sati_translate_command().
78 * @return Indicate if the command translation succeeded.
79 * @retval SCI_SUCCESS This is returned if the command translation was
81 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if the
82 * LBA field is not 0, the PMI bit is not 0.
84 SATI_STATUS sati_read_capacity_10_translate_command(
85 SATI_TRANSLATOR_SEQUENCE_T * sequence,
90 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
94 * - the LBA field must be 0
95 * - the PMI bit must be 0
99 (sati_get_cdb_byte(cdb, 2) != 0)
100 || (sati_get_cdb_byte(cdb, 3) != 0)
101 || (sati_get_cdb_byte(cdb, 4) != 0)
102 || (sati_get_cdb_byte(cdb, 5) != 0)
104 || ((sati_get_cdb_byte(cdb, 8) & SCSI_READ_CAPACITY_PMI_BIT_ENABLE)
108 sati_scsi_sense_data_construct(
111 SCSI_STATUS_CHECK_CONDITION,
112 SCSI_SENSE_ILLEGAL_REQUEST,
113 SCSI_ASC_INVALID_FIELD_IN_CDB,
114 SCSI_ASCQ_INVALID_FIELD_IN_CDB
116 return SATI_FAILURE_CHECK_RESPONSE_DATA;
119 // The CDB is properly formed.
120 sequence->allocation_length = SCSI_READ_CAPACITY_10_DATA_LENGTH;
121 sequence->type = SATI_SEQUENCE_READ_CAPACITY_10;
123 sati_ata_identify_device_construct(ata_io, sequence);
130 * @brief This method will translate the read capacity 16 SCSI command into
131 * an ATA IDENTIFY DEVICE command.
132 * For more information on the parameters passed to this method,
133 * please reference sati_translate_command().
135 * @return Indicate if the command translation succeeded.
136 * @retval SCI_SUCCESS This is returned if the command translation was
138 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if the
139 * LBA field is not 0, the PMI bit is not 0.
141 SATI_STATUS sati_read_capacity_16_translate_command(
142 SATI_TRANSLATOR_SEQUENCE_T * sequence,
147 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
151 * - the LBA field must be 0
152 * - the PMI bit must be 0
156 (sati_get_cdb_byte(cdb, 2) != 0)
157 || (sati_get_cdb_byte(cdb, 3) != 0)
158 || (sati_get_cdb_byte(cdb, 4) != 0)
159 || (sati_get_cdb_byte(cdb, 5) != 0)
160 || (sati_get_cdb_byte(cdb, 6) != 0)
161 || (sati_get_cdb_byte(cdb, 7) != 0)
162 || (sati_get_cdb_byte(cdb, 8) != 0)
163 || (sati_get_cdb_byte(cdb, 9) != 0)
165 || ((sati_get_cdb_byte(cdb, 14) & SCSI_READ_CAPACITY_PMI_BIT_ENABLE)
169 sati_scsi_sense_data_construct(
172 SCSI_STATUS_CHECK_CONDITION,
173 SCSI_SENSE_ILLEGAL_REQUEST,
174 SCSI_ASC_INVALID_FIELD_IN_CDB,
175 SCSI_ASCQ_INVALID_FIELD_IN_CDB
177 return SATI_FAILURE_CHECK_RESPONSE_DATA;
180 // The CDB is properly formed.
181 sequence->allocation_length = (sati_get_cdb_byte(cdb, 10) << 24) |
182 (sati_get_cdb_byte(cdb, 11) << 16) |
183 (sati_get_cdb_byte(cdb, 12) << 8) |
184 (sati_get_cdb_byte(cdb, 13));
186 sequence->type = SATI_SEQUENCE_READ_CAPACITY_16;
188 sati_ata_identify_device_construct(ata_io, sequence);
193 * @brief This method will translate the ATA Identify Device data into
194 * SCSI read capacity 10 data.
195 * For more information on the parameters passed to this method,
196 * please reference sati_translate_data().
200 void sati_read_capacity_10_translate_data(
201 SATI_TRANSLATOR_SEQUENCE_T * sequence,
202 void * ata_input_data,
210 // Extract the sector information (sector size, logical blocks) from
211 // the retrieved ATA identify device data.
212 sati_ata_identify_device_get_sector_info(
213 (ATA_IDENTIFY_DEVICE_DATA_T*)ata_input_data,
219 // SATA drives report a value that is one LBA larger than the last LBA.
220 // SCSI wants the last LBA. Make the correction here. lba_low is
221 // always decremented since it is an unsigned long the value 0 will
222 // wrap to 0xFFFFFFFF.
223 if ((lba_low == 0) && (lba_high == 0))
229 sati_set_data_byte(sequence, scsi_io, 0, 0xFF);
230 sati_set_data_byte(sequence, scsi_io, 1, 0xFF);
231 sati_set_data_byte(sequence, scsi_io, 2, 0xFF);
232 sati_set_data_byte(sequence, scsi_io, 3, 0xFF);
236 // Build CDB for Read Capacity 10
237 // Fill in the Logical Block Address bytes.
238 sati_set_data_byte(sequence, scsi_io, 0, (U8)((lba_low >> 24) & 0xFF));
239 sati_set_data_byte(sequence, scsi_io, 1, (U8)((lba_low >> 16) & 0xFF));
240 sati_set_data_byte(sequence, scsi_io, 2, (U8)((lba_low >> 8) & 0xFF));
241 sati_set_data_byte(sequence, scsi_io, 3, (U8)(lba_low & 0xFF));
243 // Fill in the sector size field.
244 sati_set_data_byte(sequence, scsi_io, 4, (U8)((sector_size >> 24) & 0xFF));
245 sati_set_data_byte(sequence, scsi_io, 5, (U8)((sector_size >> 16) & 0xFF));
246 sati_set_data_byte(sequence, scsi_io, 6, (U8)((sector_size >> 8) & 0xFF));
247 sati_set_data_byte(sequence, scsi_io, 7, (U8)(sector_size & 0xFF));
251 * @brief This method will translate the ATA Identify Device data into
252 * SCSI read capacity 16 data.
253 * For more information on the parameters passed to this method,
254 * please reference sati_translate_data().
258 void sati_read_capacity_16_translate_data(
259 SATI_TRANSLATOR_SEQUENCE_T * sequence,
260 void * ata_input_data,
267 ATA_IDENTIFY_DEVICE_DATA_T * identify_device_data;
268 U16 physical_per_logical_enable_bit = 0;
269 U8 physical_per_logical_sector_exponent = 0;
270 U16 physical_per_logical_sector = 0;
271 U16 logical_sector_alignment = 0;
272 U16 scsi_logical_sector_alignment = 0;
275 //A number of data fields need to be extracted from ATA identify device data
276 identify_device_data = (ATA_IDENTIFY_DEVICE_DATA_T*)ata_input_data;
278 // Extract the sector information (sector size, logical blocks) from
279 // the retrieved ATA identify device data.
280 sati_ata_identify_device_get_sector_info(
281 (ATA_IDENTIFY_DEVICE_DATA_T*)ata_input_data,
287 // SATA drives report a value that is one LBA larger than the last LBA.
288 // SCSI wants the last LBA. Make the correction here. lba_low is
289 // always decremented since it is an unsigned long the value 0 will
290 // wrap to 0xFFFFFFFF.
291 if ((lba_low == 0) && (lba_high == 0))
295 // Build the CDB for Read Capacity 16
296 // Fill in the Logical Block Address bytes.
297 sati_set_data_byte(sequence, scsi_io, 0, (U8)((lba_high >> 24) & 0xFF));
298 sati_set_data_byte(sequence, scsi_io, 1, (U8)((lba_high >> 16) & 0xFF));
299 sati_set_data_byte(sequence, scsi_io, 2, (U8)((lba_high >> 8) & 0xFF));
300 sati_set_data_byte(sequence, scsi_io, 3, (U8)(lba_high & 0xFF));
302 sati_set_data_byte(sequence, scsi_io, 4, (U8)((lba_low >> 24) & 0xFF));
303 sati_set_data_byte(sequence, scsi_io, 5, (U8)((lba_low >> 16) & 0xFF));
304 sati_set_data_byte(sequence, scsi_io, 6, (U8)((lba_low >> 8) & 0xFF));
305 sati_set_data_byte(sequence, scsi_io, 7, (U8)(lba_low & 0xFF));
307 //Fill in the sector size field.
308 sati_set_data_byte(sequence, scsi_io, 8, (U8)((sector_size >> 24) & 0xFF));
309 sati_set_data_byte(sequence, scsi_io, 9, (U8)((sector_size >> 16) & 0xFF));
310 sati_set_data_byte(sequence, scsi_io, 10, (U8)((sector_size >> 8) & 0xFF));
311 sati_set_data_byte(sequence, scsi_io, 11, (U8)(sector_size & 0xFF));
313 //Explicitly set byte 12 to 0. SATI requires that all bytes in the data
314 //response be explicitly set to some value.
315 sati_set_data_byte(sequence, scsi_io, 12, 0);
317 //Check Bit 13 of ATA_IDENTIFY_DEVICE_DATA physical_logical_sector_info
318 //(Word 106) is enabled
319 physical_per_logical_enable_bit = (identify_device_data->physical_logical_sector_info
320 & ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_ENABLE);
322 //Extract the Physical per logical sector exponent field and calculate
323 //Physical per logical sector value
324 physical_per_logical_sector_exponent = (U8) (identify_device_data->physical_logical_sector_info
325 & ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_MASK);
326 physical_per_logical_sector = 1 << (physical_per_logical_sector_exponent);
328 //If the data is valid, fill in the logical blocks per physical block exponent field.
329 //Else set logical blocks per physical block exponent to 1
330 if (physical_per_logical_enable_bit != 0)
335 (U8)(physical_per_logical_sector_exponent & 0xFF)
338 sati_set_data_byte(sequence, scsi_io, 13, 0);
340 //Fill in the lowest aligned logical block address field.
341 logical_sector_alignment = identify_device_data->logical_sector_alignment;
342 if (logical_sector_alignment == 0)
343 scsi_logical_sector_alignment = 0;
345 scsi_logical_sector_alignment = (physical_per_logical_sector - logical_sector_alignment)
346 % physical_per_logical_sector;
348 //Follow SAT for reporting tprz and tpe
349 if ((sequence->device->capabilities & SATI_DEVICE_CAP_DSM_TRIM_SUPPORT) &&
350 (sequence->device->capabilities & SATI_DEVICE_CAP_DETERMINISTIC_READ_AFTER_TRIM))
355 if (sequence->device->capabilities & SATI_DEVICE_CAP_READ_ZERO_AFTER_TRIM)
362 (U8)(((scsi_logical_sector_alignment >>8) & 0x3F) | byte14));
368 (U8)(scsi_logical_sector_alignment & 0xFF));
371 #endif // !defined(DISABLE_SATI_READ_CAPACITY)