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 6-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_6.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 6-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
92 U32 sati_mode_sense_6_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).
103 sati_set_data_byte(sequence, scsi_io, 0, (U8)mode_data_length-1);
105 // Medium Type is 0 for SBC devices
106 sati_set_data_byte(sequence, scsi_io, 1, SCSI_MODE_HEADER_MEDIUM_TYPE_SBC);
108 // Write Protect (WP), Rsvd, DPOFUA, Rsvd
109 if (sequence->device->capabilities & SATI_DEVICE_CAP_DMA_FUA_ENABLE)
110 sati_set_data_byte(sequence,scsi_io,2,SCSI_MODE_SENSE_HEADER_FUA_ENABLE);
112 sati_set_data_byte(sequence, scsi_io, 2, 0);
114 // Set the block descriptor length if block descriptors are utilized.
115 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_DBD_ENABLE)
116 sati_set_data_byte(sequence, scsi_io, 3, 0);
119 sequence, scsi_io, 3, SCSI_MODE_SENSE_STD_BLOCK_DESCRIPTOR_LENGTH
122 return SCSI_MODE_SENSE_6_HEADER_LENGTH;
126 * @brief This method perform the data translation common to all SCSI MODE
127 * SENSE 6 byte commands. This includes building the mode page
128 * header and block descriptor (if requested).
129 * For more information on the parameters passed to this method,
130 * please reference sati_translate_command().
132 * @param[in] identify This parameter specifies the remote device's IDENTIFY
133 * DEVICE data to be used during translation.
134 * @param[in] transfer_length This parameter specifies the size of the
135 * mode page (including header & block descriptor).
137 * @return This method returns the number of bytes written into the user's
138 * mode page data buffer.
141 U32 sati_mode_sense_6_translate_data(
142 SATI_TRANSLATOR_SEQUENCE_T * sequence,
143 ATA_IDENTIFY_DEVICE_DATA_T * identify,
148 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
151 offset = sati_mode_sense_6_build_header(
152 sequence, scsi_io, identify, transfer_length
155 // Determine if the caller disabled block descriptors (DBD). If not,
156 // then generate a block descriptor.
157 if ((sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_DBD_ENABLE) == 0)
158 offset += sati_mode_sense_build_std_block_descriptor(
159 sequence, scsi_io, identify, offset
165 //******************************************************************************
166 //* P R O T E C T E D M E T H O D S
167 //******************************************************************************
170 * @brief This method will translate the SCSI mode sense 6 byte command
171 * into corresponding ATA commands. If the command is well-formed,
172 * then the translation will result in an ATA IDENTIFY DEVICE
174 * For more information on the parameters passed to this method,
175 * please reference sati_translate_command().
177 * @return Indicate if the command translation succeeded.
178 * @retval SCI_SUCCESS This is returned if the command translation was
180 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
181 * sense data has been created as a result of something specified
184 SATI_STATUS sati_mode_sense_6_translate_command(
185 SATI_TRANSLATOR_SEQUENCE_T * sequence,
190 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
192 // Set the data length based on the allocation length field in the CDB.
193 sequence->allocation_length = sati_get_cdb_byte(cdb, 4);
195 return sati_mode_sense_translate_command(sequence, scsi_io, ata_io, 6);
199 * @brief This method will perform data translation from the supplied ATA
200 * input data (i.e. an ATA IDENTIFY DEVICE block) into a CACHING
201 * mode page format. The data will be written into the user's mode
202 * page data buffer. This function operates specifically for MODE
204 * For more information on the parameters passed to this method,
205 * please reference sati_translate_data().
209 void sati_mode_sense_6_caching_translate_data(
210 SATI_TRANSLATOR_SEQUENCE_T * sequence,
211 void * ata_input_data,
215 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
217 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
218 + SCSI_MODE_PAGE_08_LENGTH;
219 U32 page_offset = sati_mode_sense_6_translate_data(
220 sequence, identify, scsi_io, data_length
223 sati_mode_sense_caching_translate_data(
224 sequence, scsi_io, identify, page_offset
229 * @brief This method will perform data translation from the supplied ATA
230 * input data (i.e. an ATA IDENTIFY DEVICE block) into a INFORMATIONAL
231 * EXCEPTIONS CONTROL mode page format. The data will be written
232 * into the user's mode page data buffer. This function operates
233 * specifically for MODE SENSE 6 commands.
234 * For more information on the parameters passed to this method,
235 * please reference sati_translate_data().
239 void sati_mode_sense_6_informational_excp_control_translate_data(
240 SATI_TRANSLATOR_SEQUENCE_T * sequence,
241 void * ata_input_data,
245 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
247 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
248 + SCSI_MODE_PAGE_1C_LENGTH;
249 U32 page_offset = sati_mode_sense_6_translate_data(
250 sequence, identify, scsi_io, data_length
253 sati_mode_sense_informational_excp_control_translate_data(
254 sequence, scsi_io, identify, page_offset
259 * @brief This method will perform data translation from the supplied ATA
260 * input data (i.e. an ATA IDENTIFY DEVICE block) into a DISCONNECT
261 * RECONNECT mode page format. The data will be written
262 * into the user's mode page data buffer. This function operates
263 * specifically for MODE SENSE 6 commands.
264 * For more information on the parameters passed to this method,
265 * please reference sati_translate_data().
269 void sati_mode_sense_6_disconnect_reconnect_translate_data(
270 SATI_TRANSLATOR_SEQUENCE_T * sequence,
271 void * ata_input_data,
275 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
278 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
279 + SCSI_MODE_PAGE_02_LENGTH ;
281 U32 page_offset = sati_mode_sense_6_translate_data(
282 sequence, identify, scsi_io, data_length
285 sati_mode_sense_disconnect_reconnect_translate_data(
286 sequence, scsi_io, identify, page_offset
291 * @brief This method will perform data translation from the supplied ATA
292 * input data (i.e. an ATA IDENTIFY DEVICE block) into a READ WRITE ERROR
293 * mode page format. The data will be written
294 * into the user's mode page data buffer. This function operates
295 * specifically for MODE SENSE 6 commands.
296 * For more information on the parameters passed to this method,
297 * please reference sati_translate_data().
301 void sati_mode_sense_6_read_write_error_translate_data(
302 SATI_TRANSLATOR_SEQUENCE_T * sequence,
303 void * ata_input_data,
307 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
310 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
311 + SCSI_MODE_PAGE_01_LENGTH;
313 U32 page_offset = sati_mode_sense_6_translate_data(
314 sequence, identify, scsi_io, data_length
317 sati_mode_sense_read_write_error_translate_data(
318 sequence, scsi_io, identify, page_offset
323 * @brief This method will perform data translation from the supplied ATA
324 * input data (i.e. an ATA IDENTIFY DEVICE block) into a CONTROL
325 * mode page format. The data will be written
326 * into the user's mode page data buffer. This function operates
327 * specifically for MODE SENSE 6 commands.
328 * For more information on the parameters passed to this method,
329 * please reference sati_translate_data().
333 void sati_mode_sense_6_control_translate_data(
334 SATI_TRANSLATOR_SEQUENCE_T * sequence,
335 void * ata_input_data,
339 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
342 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
343 + SCSI_MODE_PAGE_0A_LENGTH;
345 U32 page_offset = sati_mode_sense_6_translate_data(
346 sequence, identify, scsi_io, data_length
349 sati_mode_sense_control_translate_data(
350 sequence, scsi_io, identify, page_offset
355 * @brief This method will perform data translation from the supplied ATA
356 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Power
357 * Condition mode page format. The data will be written
358 * into the user's mode page data buffer. This function operates
359 * specifically for MODE SENSE 6 commands.
360 * For more information on the parameters passed to this method,
361 * please reference sati_translate_data().
365 void sati_mode_sense_6_power_condition_translate_data(
366 SATI_TRANSLATOR_SEQUENCE_T * sequence,
367 void * ata_input_data,
371 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
377 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
378 + SCSI_MODE_PAGE_1A_LENGTH;
380 page_offset = sati_mode_sense_6_translate_data(
381 sequence, identify, scsi_io, data_length
384 sati_mode_sense_power_condition_translate_data(
385 sequence, scsi_io, identify, page_offset
392 * @brief This method will perform data translation from the supplied ATA
393 * input data (i.e. an ATA IDENTIFY DEVICE block) into an ALL
394 * PAGES mode page format. The ALL PAGES mode page is basically a
395 * conglomeration of all mode pages and sub-pages into a single
396 * page. The data will be written into the user's mode page
397 * data buffer. This function operates specifically for MODE
399 * For more information on the parameters passed to this method,
400 * please reference sati_translate_data().
404 void sati_mode_sense_6_all_pages_translate_data(
405 SATI_TRANSLATOR_SEQUENCE_T * sequence,
406 void * ata_input_data,
410 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
412 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 6)
413 + SCSI_MODE_PAGE_01_LENGTH
414 + SCSI_MODE_PAGE_02_LENGTH
415 + SCSI_MODE_PAGE_08_LENGTH
416 + SCSI_MODE_PAGE_0A_LENGTH
417 + SCSI_MODE_PAGE_1C_LENGTH;
419 U32 page_offset = sati_mode_sense_6_translate_data(
420 sequence, identify, scsi_io, data_length
423 sati_mode_sense_all_pages_translate_data(
424 sequence, scsi_io, identify, page_offset
428 #endif // !defined(DISABLE_SATI_MODE_SENSE)