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 mode sense 10-byte commands.
62 #if !defined(DISABLE_SATI_MODE_SENSE)
64 #include <dev/isci/scil/sati_mode_sense.h>
65 #include <dev/isci/scil/sati_mode_sense_10.h>
66 #include <dev/isci/scil/sati_mode_pages.h>
67 #include <dev/isci/scil/sati_callbacks.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>
72 //******************************************************************************
73 //* P R I V A T E M E T H O D S
74 //******************************************************************************
77 * @brief This method builds the mode parameter header for a 10-byte SCSI
78 * mode sense data response. The parameter header is 4 bytes in
80 * For more information on the parameters passed to this method,
81 * please reference sati_translate_command().
83 * @param[in] identify This parameter specifies the ATA remote device's
84 * received IDENTIFY DEVICE data.
85 * @param[in] mode_data_length This parameter specifies the amount of data
86 * to be returned as part of this mode sense request.
88 * @return This method returns the number of bytes written into the
89 * mode sense data buffer.
92 U32 sati_mode_sense_10_build_header(
93 SATI_TRANSLATOR_SEQUENCE_T * sequence,
95 ATA_IDENTIFY_DEVICE_DATA_T * identify,
99 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
101 // Fill in the length of the mode parameter data returned (do not include
102 // the size of the mode data length field in the total). Adjust the
103 // mode data length to not include the mode data length fields itself
104 // (i.e. subtract 2).
105 mode_data_length -= 2;
106 sati_set_data_byte(sequence, scsi_io, 0, (U8)(mode_data_length >> 8) & 0xFF);
107 sati_set_data_byte(sequence, scsi_io, 1, (U8)(mode_data_length & 0xFF));
109 // Medium Type is 0 for SBC devices
110 sati_set_data_byte(sequence, scsi_io, 2, SCSI_MODE_HEADER_MEDIUM_TYPE_SBC);
112 // Write Protect (WP), Rsvd, DPOFUA, Rsvd
113 if (sequence->device->capabilities & SATI_DEVICE_CAP_DMA_FUA_ENABLE)
114 sati_set_data_byte(sequence,scsi_io,3,SCSI_MODE_SENSE_HEADER_FUA_ENABLE);
116 sati_set_data_byte(sequence, scsi_io, 3, 0);
118 // Set the reserved bytes to 0. The LONGLBA field in byte 4 is overridden
119 // later in this method if LLBAA is enabled.
120 sati_set_data_byte(sequence, scsi_io, 4, 0);
121 sati_set_data_byte(sequence, scsi_io, 5, 0);
123 // The MSB for the block descriptor length is never used since the
124 // largest block descriptor in this translator is 16-bytes in size.
125 sati_set_data_byte(sequence, scsi_io, 6, 0);
127 // Set the LSB block descriptor length if block descriptors are utilized.
128 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_DBD_ENABLE)
129 sati_set_data_byte(sequence, scsi_io, 7, 0);
132 // If Long Logical Block Address are allowed, then the block descriptor
133 // is larger (16 bytes total).
134 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_LLBAA_ENABLE)
136 sati_set_data_byte(sequence, scsi_io, 4, 1);
138 sequence, scsi_io, 7, SCSI_MODE_SENSE_LLBA_BLOCK_DESCRIPTOR_LENGTH
144 sequence, scsi_io, 7, SCSI_MODE_SENSE_STD_BLOCK_DESCRIPTOR_LENGTH
149 return SCSI_MODE_SENSE_10_HEADER_LENGTH;
153 U32 sati_mode_sense_10_build_llba_block_descriptor(
154 SATI_TRANSLATOR_SEQUENCE_T * sequence,
156 ATA_IDENTIFY_DEVICE_DATA_T * identify,
164 // Extract the sector information (sector size, logical blocks) from
165 // the retrieved ATA identify device data.
166 sati_ata_identify_device_get_sector_info(
167 identify, &lba_low, &lba_high, §or_size
170 // Fill in the 8-byte logical block area
171 sati_set_data_byte(sequence, scsi_io, offset, (U8)((lba_high>>24) & 0xFF));
172 sati_set_data_byte(sequence, scsi_io, offset+1, (U8)((lba_high>>16) & 0xFF));
173 sati_set_data_byte(sequence, scsi_io, offset+2, (U8)((lba_high>>8) & 0xFF));
174 sati_set_data_byte(sequence, scsi_io, offset+3, (U8)(lba_high & 0xFF));
175 sati_set_data_byte(sequence, scsi_io, offset+4, (U8)((lba_low>>24) & 0xFF));
176 sati_set_data_byte(sequence, scsi_io, offset+5, (U8)((lba_low>>16) & 0xFF));
177 sati_set_data_byte(sequence, scsi_io, offset+6, (U8)((lba_low>>8) & 0xFF));
178 sati_set_data_byte(sequence, scsi_io, offset+7, (U8)(lba_low & 0xFF));
180 // Clear the reserved fields.
181 sati_set_data_byte(sequence, scsi_io, offset+8, 0);
182 sati_set_data_byte(sequence, scsi_io, offset+9, 0);
183 sati_set_data_byte(sequence, scsi_io, offset+10, 0);
184 sati_set_data_byte(sequence, scsi_io, offset+11, 0);
186 // Fill in the four byte Block Length field
187 sati_set_data_byte(sequence,scsi_io, offset+12, (U8)((sector_size>>24) & 0xFF));
188 sati_set_data_byte(sequence,scsi_io, offset+13, (U8)((sector_size>>16) & 0xFF));
189 sati_set_data_byte(sequence,scsi_io, offset+14, (U8)((sector_size>>8) & 0xFF));
190 sati_set_data_byte(sequence,scsi_io, offset+15, (U8)(sector_size & 0xFF));
192 return SCSI_MODE_SENSE_LLBA_BLOCK_DESCRIPTOR_LENGTH;
196 * @brief This method perform the data translation common to all SCSI MODE
197 * SENSE 10 byte commands. This includes building the mode page
198 * header and block descriptor (if requested).
199 * For more information on the parameters passed to this method,
200 * please reference sati_translate_command().
202 * @param[in] identify This parameter specifies the remote device's IDENTIFY
203 * DEVICE data to be used during translation.
204 * @param[in] transfer_length This parameter specifies the size of the
205 * mode page (including header & block descriptor).
207 * @return This method returns the number of bytes written into the user's
208 * mode page data buffer.
211 U32 sati_mode_sense_10_translate_data(
212 SATI_TRANSLATOR_SEQUENCE_T * sequence,
213 ATA_IDENTIFY_DEVICE_DATA_T * identify,
218 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
221 offset = sati_mode_sense_10_build_header(
222 sequence, scsi_io, identify, transfer_length
225 // Determine if the caller disabled block descriptors (DBD). If not,
226 // then generate a block descriptor.
227 if ((sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_DBD_ENABLE) == 0)
229 // If the user requested the Long LBA format descriptor, then build
231 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_LLBAA_ENABLE)
232 offset += sati_mode_sense_10_build_llba_block_descriptor(
233 sequence, scsi_io, identify, offset
236 offset += sati_mode_sense_build_std_block_descriptor(
237 sequence, scsi_io, identify, offset
244 //******************************************************************************
245 //* P R O T E C T E D M E T H O D S
246 //******************************************************************************
249 * @brief This method will translate the SCSI mode sense 6 byte command
250 * into corresponding ATA commands. If the command is well-formed,
251 * then the translation will result in an ATA IDENTIFY DEVICE
253 * For more information on the parameters passed to this method,
254 * please reference sati_translate_command().
256 * @return Indicate if the command translation succeeded.
257 * @retval SCI_SUCCESS This is returned if the command translation was
259 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
260 * sense data has been created as a result of something specified
263 SATI_STATUS sati_mode_sense_10_translate_command(
264 SATI_TRANSLATOR_SEQUENCE_T * sequence,
269 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
271 sequence->command_specific_data.scratch = 0;
273 // Set the data length based on the allocation length field in the CDB.
274 sequence->allocation_length = (sati_get_cdb_byte(cdb, 7) << 8) |
275 (sati_get_cdb_byte(cdb, 8));
277 return sati_mode_sense_translate_command(sequence, scsi_io, ata_io, 10);
281 * @brief This method will perform data translation from the supplied ATA
282 * input data (i.e. an ATA IDENTIFY DEVICE block) into a CACHING
283 * mode page format. The data will be written into the user's mode
284 * page data buffer. This function operates specifically for MODE
286 * For more information on the parameters passed to this method,
287 * please reference sati_translate_data().
291 void sati_mode_sense_10_caching_translate_data(
292 SATI_TRANSLATOR_SEQUENCE_T * sequence,
293 void * ata_input_data,
297 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
299 U16 data_length = sati_mode_sense_calculate_page_header(scsi_io, 10)
300 + SCSI_MODE_PAGE_08_LENGTH;
301 U32 page_offset = sati_mode_sense_10_translate_data(
302 sequence, identify, scsi_io, data_length
305 sati_mode_sense_caching_translate_data(
306 sequence, scsi_io, identify, page_offset
311 * @brief This method will perform data translation from the supplied ATA
312 * input data (i.e. an ATA IDENTIFY DEVICE block) into a INFORMATIONAL
313 * EXCEPTIONS CONTROL mode page format. The data will be written
314 * into the user's mode page data buffer. This function operates
315 * specifically for MODE SENSE 10 commands.
316 * For more information on the parameters passed to this method,
317 * please reference sati_translate_data().
321 void sati_mode_sense_10_informational_excp_control_translate_data(
322 SATI_TRANSLATOR_SEQUENCE_T * sequence,
323 void * ata_input_data,
327 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
329 U16 data_length = sati_mode_sense_calculate_page_header(scsi_io, 10)
330 + SCSI_MODE_PAGE_1C_LENGTH;
331 U32 page_offset = sati_mode_sense_10_translate_data(
332 sequence, identify, scsi_io, data_length
335 sati_mode_sense_informational_excp_control_translate_data(
336 sequence, scsi_io, identify, page_offset
341 * @brief This method will perform data translation from the supplied ATA
342 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Read Write Error
343 * mode page format. The data will be written
344 * into the user's mode page data buffer. This function operates
345 * specifically for MODE SENSE 10 commands.
346 * For more information on the parameters passed to this method,
347 * please reference sati_translate_data().
351 void sati_mode_sense_10_read_write_error_translate_data(
352 SATI_TRANSLATOR_SEQUENCE_T * sequence,
353 void * ata_input_data,
357 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
360 U16 data_length = sati_mode_sense_calculate_page_header(scsi_io, 10)
361 + SCSI_MODE_PAGE_01_LENGTH;
363 U32 page_offset = sati_mode_sense_10_translate_data(
364 sequence, identify, scsi_io, data_length
367 sati_mode_sense_read_write_error_translate_data(
368 sequence, scsi_io, identify, page_offset
373 * @brief This method will perform data translation from the supplied ATA
374 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Disconnect
375 * Reconnect mode page format. The data will be written
376 * into the user's mode page data buffer. This function operates
377 * specifically for MODE SENSE 10 commands.
378 * For more information on the parameters passed to this method,
379 * please reference sati_translate_data().
383 void sati_mode_sense_10_disconnect_reconnect_translate_data(
384 SATI_TRANSLATOR_SEQUENCE_T * sequence,
385 void * ata_input_data,
389 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
392 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
393 + SCSI_MODE_PAGE_02_LENGTH;
395 U32 page_offset = sati_mode_sense_10_translate_data(
396 sequence, identify, scsi_io, data_length
399 sati_mode_sense_disconnect_reconnect_translate_data(
400 sequence, scsi_io, identify, page_offset
405 * @brief This method will perform data translation from the supplied ATA
406 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Control
407 * mode page format. The data will be written
408 * into the user's mode page data buffer. This function operates
409 * specifically for MODE SENSE 10 commands.
410 * For more information on the parameters passed to this method,
411 * please reference sati_translate_data().
415 void sati_mode_sense_10_control_translate_data(
416 SATI_TRANSLATOR_SEQUENCE_T * sequence,
417 void * ata_input_data,
421 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
424 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
425 + SCSI_MODE_PAGE_0A_LENGTH;
427 U32 page_offset = sati_mode_sense_10_translate_data(
428 sequence, identify, scsi_io, data_length
431 sati_mode_sense_control_translate_data(
432 sequence, scsi_io, identify, page_offset
437 * @brief This method will perform data translation from the supplied ATA
438 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Power
439 * Condition mode page format. The data will be written
440 * into the user's mode page data buffer. This function operates
441 * specifically for MODE SENSE 10 commands.
442 * For more information on the parameters passed to this method,
443 * please reference sati_translate_data().
447 void sati_mode_sense_10_power_condition_translate_data(
448 SATI_TRANSLATOR_SEQUENCE_T * sequence,
449 void * ata_input_data,
453 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
459 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
460 + SCSI_MODE_PAGE_1A_LENGTH;
462 page_offset = sati_mode_sense_10_translate_data(
463 sequence, identify, scsi_io, data_length
466 sati_mode_sense_power_condition_translate_data(
467 sequence, scsi_io, identify, page_offset
473 * @brief This method will perform data translation from the supplied ATA
474 * input data (i.e. an ATA IDENTIFY DEVICE block) into an ALL
475 * PAGES mode page format. The ALL PAGES mode page is basically a
476 * conglomeration of all mode pages and sub-pages into a single
477 * page. The data will be written into the user's mode page
478 * data buffer. This function operates specifically for MODE
480 * For more information on the parameters passed to this method,
481 * please reference sati_translate_data().
485 void sati_mode_sense_10_all_pages_translate_data(
486 SATI_TRANSLATOR_SEQUENCE_T * sequence,
487 void * ata_input_data,
491 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
493 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
494 + SCSI_MODE_PAGE_01_LENGTH
495 + SCSI_MODE_PAGE_02_LENGTH
496 + SCSI_MODE_PAGE_08_LENGTH
497 + SCSI_MODE_PAGE_0A_LENGTH
498 + SCSI_MODE_PAGE_1C_LENGTH;
499 U32 page_offset = sati_mode_sense_10_translate_data(
500 sequence, identify, scsi_io, data_length
503 sati_mode_sense_all_pages_translate_data(
504 sequence, scsi_io, identify, page_offset
508 #endif // !defined(DISABLE_SATI_MODE_SENSE)