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 all of the method implementations that
61 * provide generic support for SATI. Some methods can be utilized
62 * by a user to construct ATA/ATAPI commands, copy ATA device
63 * structure data, fill in sense data, etc.
66 #include <dev/isci/scil/sati_util.h>
67 #include <dev/isci/scil/sati_callbacks.h>
68 #include <dev/isci/scil/intel_scsi.h>
69 #include <dev/isci/scil/intel_ata.h>
70 #include <dev/isci/scil/intel_sat.h>
71 #include <dev/isci/scil/intel_sas.h>
74 * @brief This method will set the data direction, protocol, and transfer
75 * kength for an ATA non-data command.
77 * @pre It is expected that the user will use this method for setting these
78 * values in a non-data ATA command constuct.
80 * @param[out] ata_io This parameter specifies the ATA IO request structure
81 * for which to build the IDENTIFY DEVICE command.
82 * @param[in] sequence This parameter specifies the translator sequence
83 * for which the command is being constructed.
87 void sati_ata_non_data_command(
89 SATI_TRANSLATOR_SEQUENCE_T * sequence
92 sequence->data_direction = SATI_DATA_DIRECTION_NONE;
93 sequence->protocol = SAT_PROTOCOL_NON_DATA;
94 sequence->ata_transfer_length = 0;
98 * @brief This method will construct the ATA identify device command.
100 * @pre It is expected that the user has properly set the current contents
101 * of the register FIS to 0.
103 * @param[out] ata_io This parameter specifies the ATA IO request structure
104 * for which to build the IDENTIFY DEVICE command.
105 * @param[in] sequence This parameter specifies the translator sequence
106 * for which the command is being constructed.
110 void sati_ata_identify_device_construct(
112 SATI_TRANSLATOR_SEQUENCE_T * sequence
115 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
117 sati_set_ata_command(register_fis, ATA_IDENTIFY_DEVICE);
118 sequence->data_direction = SATI_DATA_DIRECTION_IN;
119 sequence->protocol = SAT_PROTOCOL_PIO_DATA_IN;
120 sequence->ata_transfer_length = sizeof(ATA_IDENTIFY_DEVICE_DATA_T);
124 * @brief This method will construct the ATA Execute Device Diagnostic command.
126 * @param[out] ata_io This parameter specifies the ATA IO request structure
127 * for which to build the IDENTIFY DEVICE command.
128 * @param[in] sequence This parameter specifies the translator sequence
129 * for which the command is being constructed.
133 void sati_ata_execute_device_diagnostic_construct(
135 SATI_TRANSLATOR_SEQUENCE_T * sequence
138 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
140 sati_set_ata_command(register_fis, ATA_EXECUTE_DEVICE_DIAG);
142 sequence->data_direction = SATI_DATA_DIRECTION_IN;
143 sequence->protocol = SAT_PROTOCOL_DEVICE_DIAGNOSTIC;
144 sequence->ata_transfer_length = 16;
148 * @brief This method will set data bytes in the user data area. If the
149 * caller requests it, the data written will be forced to ascii
150 * printable characters if it isn't already a printable character.
151 * A printable character is considered to be >= 0x20 and <= 0x70.
153 * @param[in] sequence This parameter specifies the translation sequence
154 * for which to copy and swap the data.
155 * @param[out] destination_scsi_io This parameter specifies the SCSI IO
156 * request containing the destination buffer into which to copy.
157 * @param[in] destination_offset This parameter specifies the offset into
158 * the data buffer where the information will be copied to.
159 * @param[in] source_value This parameter specifies the value retrieved
160 * from the source buffer that is to be copied into the user
162 * @param[in] use_printable_chars This parameter indicates if the copy should
163 * ensure that the value copied is considered an ASCII printable
164 * character (e.g. A, B, " ", etc.). These characters reside
165 * in the 0x20 - 0x7E ASCII range.
170 void sati_set_ascii_data_byte(
171 SATI_TRANSLATOR_SEQUENCE_T * sequence,
172 void * destination_scsi_io,
173 U32 destination_offset,
175 BOOL use_printable_chars
178 // if the user requests that the copied data be ascii printable, then
179 // default to " " (i.e. 0x20) for all non-ascii printable characters.
180 if((use_printable_chars == TRUE)
181 && ((source_value < 0x20) || (source_value > 0x7E)))
187 sequence, destination_scsi_io, destination_offset, source_value
192 * @brief This method performs a copy operation using an offset into the
193 * source buffer, an offset into the destination buffer, and a length.
194 * It will perform the byte swap from the 16-bit identify field
195 * into the network byte order SCSI location.
197 * @param[in] sequence This parameter specifies the translation sequence
198 * for which to copy and swap the data.
199 * @param[out] destination_scsi_io This parameter specifies the SCSI IO
200 * request containing the destination buffer into which to copy.
201 * @param[in] destination_offset This parameter specifies the offset into
202 * the data buffer where the information will be copied to.
203 * @param[in] source_buffer This parameter specifies the source buffer from
204 * which the data will be copied.
205 * @param[in] source_offset This parameter specifies the offset into the
206 * source buffer where the copy shall begin.
207 * @param[in] length This parameter specifies the number of bytes to copy
208 * during this operation.
209 * @param[in] use_printable_chars This parameter indicates if the copy should
210 * ensure that the value copied is considered an ASCII printable
211 * character (e.g. A, B, " ", etc.). These characters reside
212 * in the 0x20 - 0x7E ASCII range.
216 void sati_ata_identify_device_copy_data(
217 SATI_TRANSLATOR_SEQUENCE_T * sequence,
218 void * destination_scsi_io,
219 U32 destination_offset,
223 BOOL use_printable_chars
226 source_buffer += source_offset;
229 sati_set_ascii_data_byte(
237 sati_set_ascii_data_byte(
240 destination_offset+1,
245 destination_offset += 2;
252 * @brief This method performs a copy operation using a source buffer,
253 * an offset into the destination buffer, and a length.
255 * @param[in] sequence This parameter specifies the translation sequence
256 * for which to copy and swap the data.
257 * @param[out] destination_scsi_io This parameter specifies the SCSI IO
258 * request containing the destination buffer into which to copy.
259 * @param[in] destination_offset This parameter specifies the offset into
260 * the data buffer where the information will be copied to.
261 * @param[in] source_buffer This parameter specifies the source buffer from
262 * which the data will be copied.
263 * @param[in] length This parameter specifies the number of bytes to copy
264 * during this operation.
269 SATI_TRANSLATOR_SEQUENCE_T * sequence,
270 void * destination_scsi_io,
271 U32 destination_offset,
279 sequence, destination_scsi_io, destination_offset, *source_buffer
282 destination_offset++;
289 * @brief This method extracts the Logical Block Address high and low 32-bit
290 * values and the sector count 32-bit value from the ATA identify
293 * @param[in] identify This parameter specifies the ATA_IDENTIFY_DEVICE_DATA
294 * from which to extract the sector information.
295 * @param[out] lba_high This parameter specifies the upper 32 bits for the
296 * number of logical block addresses for the device. The upper
297 * 16-bits should always be 0, since 48-bits of LBA is the most
298 * supported by an ATA device.
299 * @param[out] lba_low This parameter specifies the lower 32 bits for the
300 * number of logical block addresses for the device.
301 * @param[out] sector_size This parameter specifies the 32-bits of sector
302 * size. If the ATA device doesn't support reporting it's
303 * sector size, then 512 bytes is utilized as the default value.
307 void sati_ata_identify_device_get_sector_info(
308 ATA_IDENTIFY_DEVICE_DATA_T * identify,
314 // Calculate the values to be returned
315 // Calculation will be different if the SATA device supports
316 // 48-bit addressing. Bit 10 of Word 86 of ATA Identify
317 if (identify->command_set_enabled1
318 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED1_48BIT_ENABLE)
320 // This drive supports 48-bit addressing
322 *lba_high = identify->max_48bit_lba[7] << 24;
323 *lba_high |= identify->max_48bit_lba[6] << 16;
324 *lba_high |= identify->max_48bit_lba[5] << 8;
325 *lba_high |= identify->max_48bit_lba[4];
327 *lba_low = identify->max_48bit_lba[3] << 24;
328 *lba_low |= identify->max_48bit_lba[2] << 16;
329 *lba_low |= identify->max_48bit_lba[1] << 8;
330 *lba_low |= identify->max_48bit_lba[0];
334 // This device doesn't support 48-bit addressing
335 // Pull out the largest LBA from words 60 and 61.
337 *lba_low = identify->total_num_sectors[3] << 24;
338 *lba_low |= identify->total_num_sectors[2] << 16;
339 *lba_low |= identify->total_num_sectors[1] << 8;
340 *lba_low |= identify->total_num_sectors[0];
343 // If the ATA device reports its sector size (bit 12 of Word 106),
344 // then use that instead.
345 if (identify->physical_logical_sector_info
346 & ATA_IDENTIFY_SECTOR_LARGER_THEN_512_ENABLE)
348 *sector_size = identify->words_per_logical_sector[3] << 24;
349 *sector_size |= identify->words_per_logical_sector[2] << 16;
350 *sector_size |= identify->words_per_logical_sector[1] << 8;
351 *sector_size |= identify->words_per_logical_sector[0];
355 // Default the sector size to 512 bytes
361 * @brief This method will construct the ATA check power mode command.
363 * @pre It is expected that the user has properly set the current contents
364 * of the register FIS to 0.
366 * @param[out] ata_io This parameter specifies the ATA IO request structure
367 * for which to build the CHECK POWER MODE command.
368 * @param[in] sequence This parameter specifies the translator sequence
369 * for which the command is being constructed.
373 void sati_ata_check_power_mode_construct(
375 SATI_TRANSLATOR_SEQUENCE_T * sequence
378 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
380 sati_set_ata_command(register_fis, ATA_CHECK_POWER_MODE);
381 sati_ata_non_data_command(ata_io, sequence);
385 * @brief This method is utilized to set a specific byte in the sense
386 * data area. It will ensure that the supplied byte offset
387 * isn't larger then the length of the requested sense data.
389 * @param[in] scsi_io This parameter specifies the user SCSI IO request
390 * for which to set the sense data byte.
391 * @param[in] byte_offset This parameter specifies the byte offset into
392 * the sense data buffer where the data should be written.
393 * @param[in] value This parameter specifies the 8-bit value to be written
394 * into the sense data area.
398 void sati_set_sense_data_byte(
400 U32 max_sense_data_len,
405 // Ensure that we don't attempt to write past the end of the sense
407 if (byte_offset < max_sense_data_len)
408 sense_data[byte_offset] = value;
412 * @brief This method will construct the common response IU in the user
413 * request's response IU location.
415 * @param[out] rsp_iu This parameter specifies the user request's
416 * response IU to be constructed.
417 * @param[in] scsi_status This parameter specifies the SCSI status
418 * value for the user's IO request.
419 * @param[in] sense_data_length This parameter specifies the sense data
420 * length for response IU.
421 * @param[in] data_present The parameter specifies the specific
422 * data present value for response IU.
426 void sati_scsi_common_response_iu_construct(
427 SCI_SSP_RESPONSE_IU_T * rsp_iu,
429 U8 sense_data_length,
433 rsp_iu->sense_data_length[3] = sense_data_length;
434 rsp_iu->sense_data_length[2] = 0;
435 rsp_iu->sense_data_length[1] = 0;
436 rsp_iu->sense_data_length[0] = 0;
437 rsp_iu->status = scsi_status;
438 rsp_iu->data_present = data_present;
442 * @brief This method will construct the buffer for sense data
443 * sense data buffer location. Additionally, it will set the user's
446 * @param[in,out] scsi_io This parameter specifies the user's IO request
447 * for which to construct the buffer for sense data.
448 * @param[in] scsi_status This parameter specifies the SCSI status
449 * value for the user's IO request.
450 * @param[out] sense_data This paramater
455 void sati_scsi_get_sense_data_buffer(
456 SATI_TRANSLATOR_SEQUENCE_T * sequence,
462 #ifdef SATI_TRANSPORT_SUPPORTS_SAS
463 SCI_SSP_RESPONSE_IU_T * rsp_iu = (SCI_SSP_RESPONSE_IU_T*)
464 sati_cb_get_response_iu_address(scsi_io);
466 sati_scsi_common_response_iu_construct(
469 sati_scsi_get_sense_data_length(sequence, scsi_io),
470 SCSI_RESPONSE_DATA_PRES_SENSE_DATA
473 *sense_data = (U8*) rsp_iu->data;
474 *sense_len = SSP_RESPONSE_IU_MAX_DATA * 4; // dwords to bytes
476 *sense_data = sati_cb_get_sense_data_address(scsi_io);
477 *sense_len = sati_cb_get_sense_data_length(scsi_io);
478 sati_cb_set_scsi_status(scsi_io, scsi_status);
479 #endif // SATI_TRANSPORT_SUPPORTS_SAS
483 * @brief This method extract response code based on on device settings.
485 * @return response code
488 U8 sati_scsi_get_sense_data_response_code(SATI_TRANSLATOR_SEQUENCE_T * sequence)
490 if (sequence->device->descriptor_sense_enable)
492 return SCSI_DESCRIPTOR_CURRENT_RESPONSE_CODE;
496 return SCSI_FIXED_CURRENT_RESPONSE_CODE;
501 * @brief This method will return length of descriptor sense data for executed command.
503 * @return sense data length
506 U8 sati_scsi_get_descriptor_sense_data_length(SATI_TRANSLATOR_SEQUENCE_T * sequence,
509 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
510 //Initial value is descriptor header length
513 switch (sati_get_cdb_byte(cdb, 0))
515 #if !defined(DISABLE_SATI_WRITE_LONG)
516 case SCSI_WRITE_LONG_10:
517 case SCSI_WRITE_LONG_16:
518 length += SCSI_BLOCK_DESCRIPTOR_LENGTH +
519 SCSI_INFORMATION_DESCRIPTOR_LENGTH;
521 #endif // !defined(DISABLE_SATI_WRITE_LONG)
522 #if !defined(DISABLE_SATI_REASSIGN_BLOCKS)
523 case SCSI_REASSIGN_BLOCKS:
524 length += SCSI_CMD_SPECIFIC_DESCRIPTOR_LENGTH +
525 SCSI_INFORMATION_DESCRIPTOR_LENGTH;
527 #endif // !defined(DISABLE_SATI_REASSIGN_BLOCKS)
536 #if !defined(DISABLE_SATI_VERIFY)
540 #endif // !defined(DISABLE_SATI_VERIFY)
541 #if !defined(DISABLE_SATI_WRITE_AND_VERIFY) \
542 && !defined(DISABLE_SATI_VERIFY) \
543 && !defined(DISABLE_SATI_WRITE)
545 case SCSI_WRITE_AND_VERIFY_10:
546 case SCSI_WRITE_AND_VERIFY_12:
547 case SCSI_WRITE_AND_VERIFY_16:
548 #endif // !defined(DISABLE_SATI_WRITE_AND_VERIFY)
549 // && !defined(DISABLE_SATI_VERIFY)
550 // && !defined(DISABLE_SATI_WRITE)
551 length += SCSI_INFORMATION_DESCRIPTOR_LENGTH;
559 * @brief This method will return length of sense data.
561 * @return sense data length
563 U8 sati_scsi_get_sense_data_length(SATI_TRANSLATOR_SEQUENCE_T * sequence, void * scsi_io)
567 response_code = sati_scsi_get_sense_data_response_code(sequence);
569 switch (response_code)
571 case SCSI_FIXED_CURRENT_RESPONSE_CODE:
572 case SCSI_FIXED_DEFERRED_RESPONSE_CODE:
573 return SCSI_FIXED_SENSE_DATA_BASE_LENGTH;
575 case SCSI_DESCRIPTOR_CURRENT_RESPONSE_CODE:
576 case SCSI_DESCRIPTOR_DEFERRED_RESPONSE_CODE:
577 return sati_scsi_get_descriptor_sense_data_length(sequence, scsi_io);
581 return SCSI_FIXED_SENSE_DATA_BASE_LENGTH;
585 * @brief This method will construct the sense data buffer in the user's
586 * sense data buffer location. Additionally, it will set the user's
589 * @param[in] sequence This parameter specifies the translation sequence
590 * for which to construct the sense data.
591 * @param[in,out] scsi_io This parameter specifies the user's IO request
592 * for which to construct the sense data.
593 * @param[in] scsi_status This parameter specifies the SCSI status
594 * value for the user's IO request.
595 * @param[in] sense_key This parameter specifies the sense key to
596 * be set for the user's IO request.
597 * @param[in] additional_sense_code This parameter specifies the
598 * additional sense code (ASC) key to be set for the user's
600 * @param[in] additional_sense_code_qualifier This parameter specifies
601 * the additional sense code qualifier (ASCQ) key to be set
602 * for the user's IO request.
606 void sati_scsi_sense_data_construct(
607 SATI_TRANSLATOR_SEQUENCE_T * sequence,
611 U8 additional_sense_code,
612 U8 additional_sense_code_qualifier
617 response_code = sati_scsi_get_sense_data_response_code(sequence);
619 switch (response_code)
621 case SCSI_FIXED_CURRENT_RESPONSE_CODE:
622 case SCSI_FIXED_DEFERRED_RESPONSE_CODE:
623 sati_scsi_fixed_sense_data_construct(sequence, scsi_io, scsi_status, response_code,
624 sense_key, additional_sense_code, additional_sense_code_qualifier);
626 case SCSI_DESCRIPTOR_CURRENT_RESPONSE_CODE:
627 case SCSI_DESCRIPTOR_DEFERRED_RESPONSE_CODE:
628 sati_scsi_descriptor_sense_data_construct(sequence, scsi_io, scsi_status, response_code,
629 sense_key, additional_sense_code, additional_sense_code_qualifier);
633 sequence->is_sense_response_set = TRUE;
637 * @brief This method will construct the block descriptor in the user's descriptor
638 * sense data buffer location.
640 * @param[in] sense_data This parameter specifies the user SCSI IO request
641 * for which to set the sense data byte.
642 * @param[in] sense_len This parameter specifies length of the sense data
643 * to be returned by SATI.
644 * @param[out] descriptor_len This parameter returns the length of constructed
650 void sati_scsi_block_descriptor_construct(
656 sati_set_sense_data_byte(sense_data, sense_len, 0, SCSI_BLOCK_DESCRIPTOR_TYPE);
657 sati_set_sense_data_byte(sense_data, sense_len, 1, SCSI_BLOCK_DESCRIPTOR_ADDITIONAL_LENGTH);
658 sati_set_sense_data_byte(sense_data, sense_len, 2, 0);
659 sati_set_sense_data_byte(sense_data, sense_len, 3, (ili << 5));
663 * @brief This method will construct the command-specific descriptor for
664 * the descriptor sense data buffer in the user's sense data buffer
667 * @param[in] sense_data This parameter specifies the user SCSI IO request
668 * for which to set the sense data byte.
669 * @param[in] sense_len This parameter specifies length of the sense data
670 * to be returned by SATI.
671 * @param[out] descriptor_len This parameter returns the length of constructed
673 * @param[in] information_buff This parameter specifies the address for which
674 * to set the command-specific information buffer.
679 void sati_scsi_command_specific_descriptor_construct(
682 U8 * information_buff)
686 sati_set_sense_data_byte(sense_data, sense_len, 0, SCSI_CMD_SPECIFIC_DESCRIPTOR_TYPE);
687 sati_set_sense_data_byte(sense_data, sense_len, 1, SCSI_CMD_SPECIFIC_DESCRIPTOR_ADDITIONAL_LENGTH);
688 sati_set_sense_data_byte(sense_data, sense_len, 2, 0);
689 sati_set_sense_data_byte(sense_data, sense_len, 3, 0);
691 // fill information buffer
692 // SBC 5.20.1 REASSIGN BLOCKS command overview
693 // If information about the first LBA not reassigned is not available
694 // COMMAND-SPECIFIC INFORMATION field shall be set to FFFF_FFFF_FFFF_FFFFh
696 sati_set_sense_data_byte(sense_data, sense_len, 4 + i, information_buff==NULL?0xFF:information_buff[i]);
700 * @brief This method will construct the information descriptor for
701 * the descriptor sense data buffer in the user's sense data buffer
704 * @param[in] sense_data This parameter specifies the user SCSI IO request
705 * for which to set the sense data byte.
706 * @param[in] sense_len This parameter specifies length of the sense data
707 * to be returned by SATI.
708 * @param[out] descriptor_len This parameter returns the length of constructed
710 * @param[in] information_buff This parameter specifies the address for which
711 * to set the information buffer.
716 void sati_scsi_information_descriptor_construct(
719 U8 * information_buff)
724 sati_set_sense_data_byte(sense_data, sense_len, 0, SCSI_INFORMATION_DESCRIPTOR_TYPE);
725 sati_set_sense_data_byte(sense_data, sense_len, 1, SCSI_INFORMATION_DESCRIPTOR_ADDITIONAL_LENGTH);
726 sati_set_sense_data_byte(sense_data, sense_len, 2, (valid << 7));
727 sati_set_sense_data_byte(sense_data, sense_len, 3, 0);
729 // fill information buffer
731 sati_set_sense_data_byte(sense_data, sense_len, 4 + i, information_buff==NULL?0:information_buff[i]);
735 * @brief This method will construct the descriptors in the user's descriptor
736 * sense data buffer location.
738 * @param[in,out] scsi_io This parameter specifies the user's IO request
739 * for which to construct the sense data.
740 * @param[in] sense_data This parameter specifies the user SCSI IO request
741 * for which to set the sense data byte.
742 * @param[in] sense_len This parameter specifies length of the sense data
743 * to be returned by SATI.
744 * @param[out] descriptor_len This parameter returns the length of constructed
746 * @param[in] information_buff This parameter specifies the address for which
747 * to set the information buffer.
752 void sati_scsi_common_descriptors_construct(
756 U8 * information_buff)
758 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
761 switch (sati_get_cdb_byte(cdb, 0))
763 #if !defined(DISABLE_SATI_WRITE_LONG)
764 case SCSI_WRITE_LONG_10:
765 case SCSI_WRITE_LONG_16:
766 sati_scsi_block_descriptor_construct(
770 offset += SCSI_BLOCK_DESCRIPTOR_LENGTH;
771 sati_scsi_information_descriptor_construct(
776 offset += SCSI_INFORMATION_DESCRIPTOR_LENGTH;
778 #endif // !defined(DISABLE_SATI_WRITE_LONG)
779 #if !defined(DISABLE_SATI_REASSIGN_BLOCKS)
780 case SCSI_REASSIGN_BLOCKS:
781 sati_scsi_command_specific_descriptor_construct(
786 offset += SCSI_CMD_SPECIFIC_DESCRIPTOR_LENGTH;
787 sati_scsi_information_descriptor_construct(
792 offset += SCSI_INFORMATION_DESCRIPTOR_LENGTH;
794 #endif // !defined(DISABLE_SATI_REASSIGN_BLOCKS)
803 #if !defined(DISABLE_SATI_VERIFY)
807 #endif // !defined(DISABLE_SATI_VERIFY)
808 #if !defined(DISABLE_SATI_WRITE_AND_VERIFY) \
809 && !defined(DISABLE_SATI_VERIFY) \
810 && !defined(DISABLE_SATI_WRITE)
812 case SCSI_WRITE_AND_VERIFY_10:
813 case SCSI_WRITE_AND_VERIFY_12:
814 case SCSI_WRITE_AND_VERIFY_16:
815 #endif // !defined(DISABLE_SATI_WRITE_AND_VERIFY)
816 // && !defined(DISABLE_SATI_VERIFY)
817 // && !defined(DISABLE_SATI_WRITE)
818 sati_scsi_information_descriptor_construct(
823 offset += SCSI_INFORMATION_DESCRIPTOR_LENGTH;
829 * @brief This method will construct the descriptor sense data buffer in
830 * the user's sense data buffer location. Additionally, it will set
831 * the user's SCSI status.
833 * @param[in] sequence This parameter specifies the translation sequence
834 * for which to construct the sense data.
835 * @param[in,out] scsi_io This parameter specifies the user's IO request
836 * for which to construct the sense data.
837 * @param[in] scsi_status This parameter specifies the SCSI status
838 * value for the user's IO request.
839 * @param[in] sense_key This parameter specifies the sense key to
840 * be set for the user's IO request.
841 * @param[in] additional_sense_code This parameter specifies the
842 * additional sense code (ASC) key to be set for the user's
844 * @param[in] additional_sense_code_qualifier This parameter specifies
845 * the additional sense code qualifier (ASCQ) key to be set
846 * for the user's IO request.
850 void sati_scsi_descriptor_sense_data_construct(
851 SATI_TRANSLATOR_SEQUENCE_T * sequence,
856 U8 additional_sense_code,
857 U8 additional_sense_code_qualifier
863 sati_scsi_get_sense_data_buffer(sequence, scsi_io, scsi_status, &sense_data, &sense_len);
865 sati_set_sense_data_byte(
872 sati_set_sense_data_byte(sense_data, sense_len, 1, sense_key);
873 sati_set_sense_data_byte(sense_data, sense_len, 2, additional_sense_code);
874 sati_set_sense_data_byte(sense_data, sense_len, 3, additional_sense_code_qualifier);
875 sati_set_sense_data_byte(sense_data, sense_len, 4, 0);
876 sati_set_sense_data_byte(sense_data, sense_len, 5, 0);
877 sati_set_sense_data_byte(sense_data, sense_len, 6, 0);
879 sati_scsi_common_descriptors_construct(scsi_io, sense_data + 8, sense_len, NULL);
881 sati_set_sense_data_byte(sense_data, sense_len, 7, sati_scsi_get_descriptor_sense_data_length(sequence, scsi_io) - 8);
885 * @brief This method will construct the fixed format sense data buffer
886 * in the user's sense data buffer location. Additionally, it will
887 * set the user's SCSI status.
889 * @param[in] sequence This parameter specifies the translation sequence
890 * for which to construct the sense data.
891 * @param[in,out] scsi_io This parameter specifies the user's IO request
892 * for which to construct the sense data.
893 * @param[in] scsi_status This parameter specifies the SCSI status
894 * value for the user's IO request.
895 * @param[in] sense_key This parameter specifies the sense key to
896 * be set for the user's IO request.
897 * @param[in] additional_sense_code This parameter specifies the
898 * additional sense code (ASC) key to be set for the user's
900 * @param[in] additional_sense_code_qualifier This parameter specifies
901 * the additional sense code qualifier (ASCQ) key to be set
902 * for the user's IO request.
906 void sati_scsi_fixed_sense_data_construct(
907 SATI_TRANSLATOR_SEQUENCE_T * sequence,
912 U8 additional_sense_code,
913 U8 additional_sense_code_qualifier
919 sati_scsi_get_sense_data_buffer(sequence, scsi_io, scsi_status, &sense_data, &sense_len);
921 // Write out the sense data format per SPC-4.
922 // We utilize the fixed format sense data format.
924 sati_set_sense_data_byte(
928 response_code | SCSI_FIXED_SENSE_DATA_VALID_BIT
931 sati_set_sense_data_byte(sense_data, sense_len, 1, 0);
932 sati_set_sense_data_byte(sense_data, sense_len, 2, sense_key);
933 sati_set_sense_data_byte(sense_data, sense_len, 3, 0);
934 sati_set_sense_data_byte(sense_data, sense_len, 4, 0);
935 sati_set_sense_data_byte(sense_data, sense_len, 5, 0);
936 sati_set_sense_data_byte(sense_data, sense_len, 6, 0);
937 sati_set_sense_data_byte(sense_data, sense_len, 7, (sense_len < 18 ? sense_len - 1 : 17) - 7);
938 sati_set_sense_data_byte(sense_data, sense_len, 8, 0);
939 sati_set_sense_data_byte(sense_data, sense_len, 9, 0);
940 sati_set_sense_data_byte(sense_data, sense_len, 10, 0);
941 sati_set_sense_data_byte(sense_data, sense_len, 11, 0);
942 sati_set_sense_data_byte(sense_data, sense_len, 12, additional_sense_code);
943 sati_set_sense_data_byte(sense_data, sense_len, 13, additional_sense_code_qualifier);
944 sati_set_sense_data_byte(sense_data, sense_len, 14, 0);
945 sati_set_sense_data_byte(sense_data, sense_len, 15, 0);
946 sati_set_sense_data_byte(sense_data, sense_len, 16, 0);
947 sati_set_sense_data_byte(sense_data, sense_len, 17, 0);
951 * @brief This method will construct common sense data that will be identical in
952 * both read error sense construct functions.
953 * sati_scsi_read_ncq_error_sense_construct,
954 * sati_scsi_read_error_sense_construct
956 * @param[in] sense_data This parameter specifies the user SCSI IO request
957 * for which to set the sense data byte.
958 * @param[in] sense_len This parameter specifies length of the sense data
959 * to be returned by SATI.
960 * @param[in] sense_key This parameter specifies the sense key to
961 * be set for the user's IO request.
962 * @param[in] additional_sense_code This parameter specifies the
963 * additional sense code (ASC) key to be set for the user's
965 * @param[in] additional_sense_code_qualifier This parameter specifies
966 * the additional sense code qualifier (ASCQ) key to be set
967 * for the user's IO request.
972 void sati_scsi_common_fixed_sense_construct(
976 U8 additional_sense_code,
977 U8 additional_sense_code_qualifier
981 sati_set_sense_data_byte(sense_data, sense_len, 1, 0);
982 sati_set_sense_data_byte(sense_data, sense_len, 2, sense_key);
984 //Bytes 3, 4, 5, 6 are set in read_error_sense_construct functions
986 sati_set_sense_data_byte(sense_data, sense_len, 7, (sense_len < 18 ? sense_len - 1 : 17) - 7);
987 sati_set_sense_data_byte(sense_data, sense_len, 8, 0);
988 sati_set_sense_data_byte(sense_data, sense_len, 9, 0);
989 sati_set_sense_data_byte(sense_data, sense_len, 10, 0);
990 sati_set_sense_data_byte(sense_data, sense_len, 11, 0);
991 sati_set_sense_data_byte(sense_data, sense_len, 12, additional_sense_code);
992 sati_set_sense_data_byte(sense_data, sense_len, 13, additional_sense_code_qualifier);
993 sati_set_sense_data_byte(sense_data, sense_len, 14, 0);
994 sati_set_sense_data_byte(sense_data, sense_len, 15, 0x80);
995 sati_set_sense_data_byte(sense_data, sense_len, 16, 0);
996 sati_set_sense_data_byte(sense_data, sense_len, 17, 0);
1000 * @brief This method will construct the descriptor sense data buffer in
1001 * the user's sense data buffer location. Additionally, it will set
1002 * the user's SCSI status.
1004 * @param[in] sequence This parameter specifies the translation sequence
1005 * for which to construct the sense data.
1006 * @param[in,out] scsi_io This parameter specifies the user's IO request
1007 * for which to construct the sense data.
1008 * @param[in] scsi_status This parameter specifies the SCSI status
1009 * value for the user's IO request.
1010 * @param[in] sense_key This parameter specifies the sense key to
1011 * be set for the user's IO request.
1012 * @param[in] additional_sense_code This parameter specifies the
1013 * additional sense code (ASC) key to be set for the user's
1015 * @param[in] additional_sense_code_qualifier This parameter specifies
1016 * the additional sense code qualifier (ASCQ) key to be set
1017 * for the user's IO request.
1022 void sati_scsi_common_descriptor_sense_construct(
1023 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1028 U8 additional_sense_code,
1029 U8 additional_sense_code_qualifier,
1030 U8 * information_buff
1033 sati_set_sense_data_byte(sense_data, sense_len, 1, sense_key);
1034 sati_set_sense_data_byte(sense_data, sense_len, 2, additional_sense_code);
1035 sati_set_sense_data_byte(sense_data, sense_len, 3, additional_sense_code_qualifier);
1036 sati_set_sense_data_byte(sense_data, sense_len, 4, 0);
1037 sati_set_sense_data_byte(sense_data, sense_len, 5, 0);
1038 sati_set_sense_data_byte(sense_data, sense_len, 6, 0);
1040 sati_scsi_common_descriptors_construct(scsi_io, sense_data + 8, sense_len, information_buff);
1042 sati_set_sense_data_byte(sense_data, sense_len, 7, sati_scsi_get_descriptor_sense_data_length(sequence, scsi_io) - 8);
1046 * @brief This method will construct the sense data buffer in the user's
1047 * descriptor sense data buffer location. Additionally, it will set
1048 * the user's SCSI status. This is only used for NCQ uncorrectable
1051 * @param[in] sequence This parameter specifies the translation sequence
1052 * for which to construct the sense data.
1053 * @param[in,out] scsi_io This parameter specifies the user's IO request
1054 * for which to construct the sense data.
1055 * @param[in] ata_input_data This parameter specifies the user's ATA IO
1056 * response from a Read Log Ext command.
1057 * @param[in] scsi_status This parameter specifies the SCSI status
1058 * value for the user's IO request.
1059 * @param[in] sense_key This parameter specifies the sense key to
1060 * be set for the user's IO request.
1061 * @param[in] additional_sense_code This parameter specifies the
1062 * additional sense code (ASC) key to be set for the user's
1064 * @param[in] additional_sense_code_qualifier This parameter specifies
1065 * the additional sense code qualifier (ASCQ) key to be set
1066 * for the user's IO request.
1071 void sati_scsi_read_ncq_error_descriptor_sense_construct(
1072 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1074 void * ata_input_data,
1078 U8 additional_sense_code,
1079 U8 additional_sense_code_qualifier
1085 U8 information_buff[8] = {0};
1087 ATA_NCQ_COMMAND_ERROR_LOG_T * ncq_log = (ATA_NCQ_COMMAND_ERROR_LOG_T *) ata_input_data;
1089 sati_scsi_get_sense_data_buffer(sequence, scsi_io, scsi_status, &sense_data, &sense_len);
1091 sati_set_sense_data_byte(
1098 information_buff[2] = ncq_log->lba_47_40;
1099 information_buff[3] = ncq_log->lba_39_32;
1100 information_buff[4] = ncq_log->lba_31_24;
1101 information_buff[5] = ncq_log->lba_23_16;
1102 information_buff[6] = ncq_log->lba_15_8;
1103 information_buff[7] = ncq_log->lba_7_0;
1105 sati_scsi_common_descriptor_sense_construct(
1111 additional_sense_code,
1112 additional_sense_code_qualifier,
1118 * @brief This method will construct the sense data buffer in the user's
1119 * sense data buffer location. Additionally, it will set the user's
1120 * SCSI status. This is only used for NCQ uncorrectable read errors
1122 * @param[in] sequence This parameter specifies the translation sequence
1123 * for which to construct the sense data.
1124 * @param[in,out] scsi_io This parameter specifies the user's IO request
1125 * for which to construct the sense data.
1126 * @param[in] ata_input_data This parameter specifies the user's ATA IO
1127 * response from a Read Log Ext command.
1128 * @param[in] scsi_status This parameter specifies the SCSI status
1129 * value for the user's IO request.
1130 * @param[in] sense_key This parameter specifies the sense key to
1131 * be set for the user's IO request.
1132 * @param[in] additional_sense_code This parameter specifies the
1133 * additional sense code (ASC) key to be set for the user's
1135 * @param[in] additional_sense_code_qualifier This parameter specifies
1136 * the additional sense code qualifier (ASCQ) key to be set
1137 * for the user's IO request.
1142 void sati_scsi_read_ncq_error_fixed_sense_construct(
1143 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1145 void * ata_input_data,
1149 U8 additional_sense_code,
1150 U8 additional_sense_code_qualifier
1157 ATA_NCQ_COMMAND_ERROR_LOG_T * ncq_log = (ATA_NCQ_COMMAND_ERROR_LOG_T *) ata_input_data;
1159 sati_scsi_get_sense_data_buffer(sequence, scsi_io, scsi_status, &sense_data, &sense_len);
1161 if(ncq_log->lba_39_32 > 0)
1166 sati_set_sense_data_byte(
1170 (valid << 7) | response_code
1173 sati_set_sense_data_byte(sense_data, sense_len, 3, ncq_log->lba_31_24);
1174 sati_set_sense_data_byte(sense_data, sense_len, 4, ncq_log->lba_23_16);
1175 sati_set_sense_data_byte(sense_data, sense_len, 5, ncq_log->lba_15_8);
1176 sati_set_sense_data_byte(sense_data, sense_len, 6, ncq_log->lba_7_0);
1178 sati_scsi_common_fixed_sense_construct(
1182 additional_sense_code,
1183 additional_sense_code_qualifier
1187 void sati_scsi_read_ncq_error_sense_construct(
1188 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1190 void * ata_input_data,
1193 U8 additional_sense_code,
1194 U8 additional_sense_code_qualifier
1199 response_code = sati_scsi_get_sense_data_response_code(sequence);
1201 switch (response_code)
1203 case SCSI_FIXED_CURRENT_RESPONSE_CODE:
1204 case SCSI_FIXED_DEFERRED_RESPONSE_CODE:
1205 sati_scsi_read_ncq_error_fixed_sense_construct(sequence, scsi_io, ata_input_data, scsi_status,
1206 response_code, sense_key, additional_sense_code, additional_sense_code_qualifier);
1208 case SCSI_DESCRIPTOR_CURRENT_RESPONSE_CODE:
1209 case SCSI_DESCRIPTOR_DEFERRED_RESPONSE_CODE:
1210 sati_scsi_read_ncq_error_descriptor_sense_construct(sequence, scsi_io, ata_input_data, scsi_status,
1211 response_code, sense_key, additional_sense_code, additional_sense_code_qualifier);
1215 sequence->is_sense_response_set = TRUE;
1219 * @brief This method will construct the sense data buffer in the user's
1220 * sense data buffer location. Additionally, it will set the user's
1221 * SCSI status. This is used for uncorrectable read errors.
1223 * @param[in] sequence This parameter specifies the translation sequence
1224 * for which to construct the sense data.
1225 * @param[in,out] scsi_io This parameter specifies the user's IO request
1226 * for which to construct the sense data.
1227 * @param[in] ata_io This parameter is a pointer to the ATA IO data used
1228 * to get the ATA register fis.
1229 * @param[in] scsi_status This parameter specifies the SCSI status
1230 * value for the user's IO request.
1231 * @param[in] sense_key This parameter specifies the sense key to
1232 * be set for the user's IO request.
1233 * @param[in] additional_sense_code This parameter specifies the
1234 * additional sense code (ASC) key to be set for the user's
1236 * @param[in] additional_sense_code_qualifier This parameter specifies
1237 * the additional sense code qualifier (ASCQ) key to be set
1238 * for the user's IO request.
1243 void sati_scsi_read_error_descriptor_sense_construct(
1244 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1250 U8 additional_sense_code,
1251 U8 additional_sense_code_qualifier
1256 U8 information_buff[8] = {0};
1258 U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
1260 sati_scsi_get_sense_data_buffer(sequence, scsi_io, scsi_status, &sense_data, &sense_len);
1262 information_buff[2] = sati_get_ata_lba_high_ext(register_fis);
1263 information_buff[3] = sati_get_ata_lba_mid_ext(register_fis);
1264 information_buff[4] = sati_get_ata_lba_low_ext(register_fis);
1265 information_buff[5] = sati_get_ata_lba_high(register_fis);
1266 information_buff[6] = sati_get_ata_lba_mid(register_fis);
1267 information_buff[7] = sati_get_ata_lba_low(register_fis);
1269 sati_set_sense_data_byte(
1273 SCSI_DESCRIPTOR_CURRENT_RESPONSE_CODE
1276 sati_scsi_common_descriptor_sense_construct(
1282 additional_sense_code,
1283 additional_sense_code_qualifier,
1289 * @brief This method will construct the sense data buffer in the user's
1290 * sense data buffer location. Additionally, it will set the user's
1291 * SCSI status. This is used for uncorrectable read errors.
1293 * @param[in] sequence This parameter specifies the translation sequence
1294 * for which to construct the sense data.
1295 * @param[in,out] scsi_io This parameter specifies the user's IO request
1296 * for which to construct the sense data.
1297 * @param[in] ata_io This parameter is a pointer to the ATA IO data used
1298 * to get the ATA register fis.
1299 * @param[in] scsi_status This parameter specifies the SCSI status
1300 * value for the user's IO request.
1301 * @param[in] sense_key This parameter specifies the sense key to
1302 * be set for the user's IO request.
1303 * @param[in] additional_sense_code This parameter specifies the
1304 * additional sense code (ASC) key to be set for the user's
1306 * @param[in] additional_sense_code_qualifier This parameter specifies
1307 * the additional sense code qualifier (ASCQ) key to be set
1308 * for the user's IO request.
1313 void sati_scsi_read_error_fixed_sense_construct(
1314 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1320 U8 additional_sense_code,
1321 U8 additional_sense_code_qualifier
1328 U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
1330 sati_scsi_get_sense_data_buffer(sequence, scsi_io, scsi_status, &sense_data, &sense_len);
1332 if(sati_get_ata_lba_mid_ext(register_fis) > 0)
1337 sati_set_sense_data_byte(sense_data, sense_len, 3, sati_get_ata_lba_low_ext(register_fis));
1338 sati_set_sense_data_byte(sense_data, sense_len, 4, sati_get_ata_lba_high(register_fis));
1339 sati_set_sense_data_byte(sense_data, sense_len, 5, sati_get_ata_lba_mid(register_fis));
1340 sati_set_sense_data_byte(sense_data, sense_len, 6, sati_get_ata_lba_low(register_fis));
1343 sati_set_sense_data_byte(
1347 (valid << 7) | SCSI_FIXED_CURRENT_RESPONSE_CODE
1350 sati_scsi_common_fixed_sense_construct(
1354 additional_sense_code,
1355 additional_sense_code_qualifier
1359 void sati_scsi_read_error_sense_construct(
1360 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1362 void * ata_input_data,
1365 U8 additional_sense_code,
1366 U8 additional_sense_code_qualifier
1371 response_code = sati_scsi_get_sense_data_response_code(sequence);
1373 switch (response_code)
1375 case SCSI_FIXED_CURRENT_RESPONSE_CODE:
1376 case SCSI_FIXED_DEFERRED_RESPONSE_CODE:
1377 sati_scsi_read_error_fixed_sense_construct(sequence, scsi_io, ata_input_data, scsi_status,
1378 response_code, sense_key, additional_sense_code, additional_sense_code_qualifier);
1380 case SCSI_DESCRIPTOR_CURRENT_RESPONSE_CODE:
1381 case SCSI_DESCRIPTOR_DEFERRED_RESPONSE_CODE:
1382 sati_scsi_read_error_descriptor_sense_construct(sequence, scsi_io, ata_input_data, scsi_status,
1383 response_code, sense_key, additional_sense_code, additional_sense_code_qualifier);
1387 sequence->is_sense_response_set = TRUE;
1391 * @brief This method builds the scsi response data for a sata task management
1394 * @param[in] sequence This parameter specifies the translation sequence
1395 * for which to construct the sense data.
1396 * @param[in,out] scsi_io This parameter specifies the user's IO request
1397 * for which to construct the sense data.
1398 * @param[in] response_data The response status for the task management
1401 void sati_scsi_response_data_construct(
1402 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1407 #ifdef SATI_TRANSPORT_SUPPORTS_SAS
1408 SCI_SSP_RESPONSE_IU_T * rsp_iu = (SCI_SSP_RESPONSE_IU_T*)
1409 sati_cb_get_response_iu_address(scsi_io);
1410 rsp_iu->data_present = 0x01;
1411 rsp_iu->response_data_length[3] = sizeof(U32);
1413 ((U8 *)rsp_iu->data)[3] = response_data;
1415 #endif // SATI_TRANSPORT_SUPPORTS_SAS
1419 * @brief This method checks to make sure that the translation isn't
1420 * exceeding the allocation length specified in the CDB prior
1421 * to retrieving the payload data byte from the user's buffer.
1423 * @param[in,out] scsi_io This parameter specifies the user's IO request
1424 * for which to set the user payload data byte.
1425 * @param[in] byte_offset This parameter specifies the offset into
1426 * the user's payload buffer at which to write the supplied
1428 * @param[in] value This parameter specifies the memory location into
1429 * which to read the value from the user's payload buffer.
1433 void sati_get_data_byte(
1434 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1440 if (byte_offset < sequence->allocation_length)
1441 sati_cb_get_data_byte(scsi_io, byte_offset, value);
1445 * @brief This method checks to make sure that the translation isn't
1446 * exceeding the allocation length specified in the CDB while
1447 * translating payload data into the user's buffer.
1449 * @param[in] sequence This parameter specifies the translation sequence
1450 * for which to set the user payload data byte.
1451 * @param[in,out] scsi_io This parameter specifies the user's IO request
1452 * for which to set the user payload data byte.
1453 * @param[in] byte_offset This parameter specifies the offset into
1454 * the user's payload buffer at which to write the supplied
1456 * @param[in] value This parameter specifies the new value to be
1457 * written out into the user's payload buffer.
1461 void sati_set_data_byte(
1462 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1468 if (byte_offset < sequence->allocation_length)
1470 sequence->number_data_bytes_set++;
1471 sati_cb_set_data_byte(scsi_io, byte_offset, value);
1476 * @brief This method checks to make sure that the translation isn't
1477 * exceeding the allocation length specified in the CDB while
1478 * translating payload data into the user's buffer.
1480 * @param[in] sequence This parameter specifies the translation sequence
1481 * for which to set the user payload data dword.
1482 * @param[in,out] scsi_io This parameter specifies the user's IO request
1483 * for which to set the user payload data dword.
1484 * @param[in] byte_offset This parameter specifies the offset into
1485 * the user's payload buffer at which to write the supplied
1487 * @param[in] value This parameter specifies the new value to be
1488 * written out into the user's payload buffer.
1492 void sati_set_data_dword(
1493 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1499 /// @todo Check to ensure that the bytes appear correctly (SAS Address).
1501 sati_set_data_byte(sequence, scsi_io, byte_offset, (U8)value & 0xFF);
1503 sati_set_data_byte(sequence, scsi_io, byte_offset, (U8)(value >> 8) & 0xFF);
1505 sati_set_data_byte(sequence, scsi_io, byte_offset, (U8)(value >> 16) & 0xFF);
1507 sati_set_data_byte(sequence, scsi_io, byte_offset, (U8)(value >> 24) & 0xFF);
1511 * @brief This method will construct the ATA flush cache command.
1513 * @pre It is expected that the user has properly set the current contents
1514 * of the register FIS to 0.
1516 * @param[out] ata_io This parameter specifies the ATA IO request structure
1517 * for which to build the FLUSH CACHE command.
1518 * @param[in] sequence This parameter specifies the translator sequence
1519 * for which the command is being constructed.
1523 void sati_ata_flush_cache_construct(
1525 SATI_TRANSLATOR_SEQUENCE_T * sequence
1528 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1530 sati_set_ata_command(register_fis, ATA_FLUSH_CACHE);
1531 sati_ata_non_data_command(ata_io, sequence);
1535 * @brief This method will construct the ATA standby immediate command.
1537 * @pre It is expected that the user has properly set the current contents
1538 * of the register FIS to 0.
1540 * @param[out] ata_io This parameter specifies the ATA IO request structure
1541 * for which to build the STANDBY IMMEDIATE command.
1542 * @param[in] sequence This parameter specifies the translator sequence
1543 * for which the command is being constructed.
1545 * @param[in] count This parameter specifies the time period programmed
1546 * into the Standby Timer. See ATA8 spec for more details
1549 void sati_ata_standby_construct(
1551 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1555 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1557 sati_set_ata_command(register_fis, ATA_STANDBY);
1558 sati_set_ata_sector_count(register_fis, count);
1560 sequence->device->ata_standby_timer = (U8) count;
1562 sati_ata_non_data_command(ata_io, sequence);
1566 * @brief This method will construct the ATA standby immediate command.
1568 * @pre It is expected that the user has properly set the current contents
1569 * of the register FIS to 0.
1571 * @param[out] ata_io This parameter specifies the ATA IO request structure
1572 * for which to build the STANDBY IMMEDIATE command.
1573 * @param[in] sequence This parameter specifies the translator sequence
1574 * for which the command is being constructed.
1578 void sati_ata_standby_immediate_construct(
1580 SATI_TRANSLATOR_SEQUENCE_T * sequence
1583 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1585 sati_set_ata_command(register_fis, ATA_STANDBY_IMMED);
1586 sati_ata_non_data_command(ata_io, sequence);
1590 * @brief This method will construct the ATA idle immediate command.
1592 * @pre It is expected that the user has properly set the current contents
1593 * of the register FIS to 0.
1595 * @param[out] ata_io This parameter specifies the ATA IO request structure
1596 * for which to build the IDLE IMMEDIATE command.
1597 * @param[in] sequence This parameter specifies the translator sequence
1598 * for which the command is being constructed.
1602 void sati_ata_idle_immediate_construct(
1604 SATI_TRANSLATOR_SEQUENCE_T * sequence
1607 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1609 sati_set_ata_command(register_fis, ATA_IDLE_IMMED);
1610 sati_set_ata_features(register_fis, 0x00);
1611 sati_set_ata_sector_count(register_fis, 0x00);
1612 sati_set_ata_lba_high(register_fis, 0x00);
1613 sati_set_ata_lba_mid(register_fis, 0x00);
1614 sati_set_ata_lba_low(register_fis, 0x00);
1615 sati_ata_non_data_command(ata_io, sequence);
1619 * @brief This method will construct the ATA idle immediate command
1620 for Unload Features.
1622 * @pre It is expected that the user has properly set the current contents
1623 * of the register FIS to 0.
1625 * @param[out] ata_io This parameter specifies the ATA IO request structure
1626 * for which to build the IDLE IMMEDIATE command.
1627 * @param[in] sequence This parameter specifies the translator sequence
1628 * for which the command is being constructed.
1632 void sati_ata_idle_immediate_unload_construct(
1634 SATI_TRANSLATOR_SEQUENCE_T * sequence
1637 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1639 sati_set_ata_command(register_fis, ATA_IDLE_IMMED);
1640 sati_set_ata_features(register_fis, 0x44);
1641 sati_set_ata_sector_count(register_fis, 0x00);
1642 sati_set_ata_lba_high(register_fis, 0x55);
1643 sati_set_ata_lba_mid(register_fis, 0x4E);
1644 sati_set_ata_lba_low(register_fis, 0x4C);
1645 sati_ata_non_data_command(ata_io, sequence);
1649 * @brief This method will construct the ATA IDLE command.\
1651 * @pre It is expected that the user has properly set the current contents
1652 * of the register FIS to 0.
1654 * @param[out] ata_io This parameter specifies the ATA IO request structure
1655 * for which to build the ATA IDLE command.
1656 * @param[in] sequence This parameter specifies the translator sequence
1657 * for which the command is being constructed.
1661 void sati_ata_idle_construct(
1663 SATI_TRANSLATOR_SEQUENCE_T * sequence
1666 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1668 sati_set_ata_command(register_fis, ATA_IDLE);
1669 sati_set_ata_features(register_fis, 0x00);
1670 sati_set_ata_sector_count(register_fis, 0x00);
1672 sequence->device->ata_standby_timer = 0x00;
1674 sati_set_ata_lba_high(register_fis, 0x00);
1675 sati_set_ata_lba_mid(register_fis, 0x00);
1676 sati_set_ata_lba_low(register_fis, 0x00);
1677 sati_ata_non_data_command(ata_io, sequence);
1681 * @brief This method will construct the ATA MEDIA EJECT command.
1683 * @pre It is expected that the user has properly set the current contents
1684 * of the register FIS to 0.
1686 * @param[out] ata_io This parameter specifies the ATA IO request structure
1687 * for which to build the MEDIA EJCT command.
1688 * @param[in] sequence This parameter specifies the translator sequence
1689 * for which the command is being constructed.
1693 void sati_ata_media_eject_construct(
1695 SATI_TRANSLATOR_SEQUENCE_T * sequence
1698 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1700 sati_set_ata_command(register_fis, ATA_MEDIA_EJECT);
1701 sati_ata_non_data_command(ata_io, sequence);
1706 * @brief This method will construct the ATA read verify sector(s) command.
1708 * @pre It is expected that the user has properly set the current contents
1709 * of the register FIS to 0.
1711 * @param[out] ata_io This parameter specifies the ATA IO request structure
1712 * for which to build the ATA READ VERIFY SECTOR(S) command.
1713 * @param[in] sequence This parameter specifies the translator sequence
1714 * for which the command is being constructed.
1718 void sati_ata_read_verify_sectors_construct(
1720 SATI_TRANSLATOR_SEQUENCE_T * sequence
1723 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1725 sati_set_ata_command(register_fis, ATA_READ_VERIFY_SECTORS);
1727 //According to SAT-2 (v7) 9.11.3
1728 sati_set_ata_sector_count(register_fis, 1);
1730 //According to SAT-2 (v7) 9.11.3, set LBA to a value between zero and the
1731 //maximum LBA supported by the ATA device in its current configuration.
1732 //From the unit test, it seems we have to set LBA to a non-zero value.
1733 sati_set_ata_lba_low(register_fis, 1);
1735 sati_ata_non_data_command(ata_io, sequence);
1739 * @brief This method will construct a ATA SMART Return Status command so the
1740 * status of the ATA device can be returned. The status of the SMART
1741 * threshold will be returned by this command.
1746 void sati_ata_smart_return_status_construct(
1748 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1752 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1754 sati_set_ata_command(register_fis, ATA_SMART);
1756 sati_set_ata_features(register_fis, feature_value);
1758 sati_set_ata_lba_high(register_fis, 0xC2);
1759 sati_set_ata_lba_mid(register_fis, 0x4F);
1761 sati_ata_non_data_command(ata_io, sequence);
1765 * @brief This method will construct a ATA SMART Return Status command so the
1766 * status of the ATA device can be returned. The status of the SMART
1767 * threshold will be returned by this command.
1772 void sati_ata_smart_read_log_construct(
1774 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1779 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1781 sati_set_ata_command(register_fis, ATA_SMART);
1782 sati_set_ata_features(register_fis, ATA_SMART_SUB_CMD_READ_LOG);
1784 sati_set_ata_lba_high(register_fis, 0xC2);
1785 sati_set_ata_lba_mid(register_fis, 0x4F);
1786 sati_set_ata_lba_low(register_fis, log_address);
1788 sequence->data_direction = SATI_DATA_DIRECTION_IN;
1789 sequence->protocol = SAT_PROTOCOL_PIO_DATA_IN;
1790 sequence->ata_transfer_length = transfer_length;
1794 * @brief This method will construct a Write Uncorrectable ATA command that
1795 * will write one sector with a pseudo or flagged error. The type of
1796 * error is specified by the feature value.
1801 void sati_ata_write_uncorrectable_construct(
1803 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1807 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1809 sati_set_ata_command(register_fis, ATA_WRITE_UNCORRECTABLE);
1810 sati_set_ata_features(register_fis, feature_value);
1811 sati_set_ata_sector_count(register_fis, 0x0001);
1812 sati_ata_non_data_command(ata_io, sequence);
1816 * @brief This method will construct a Mode Select ATA SET FEATURES command
1817 * For example, Enable/Disable Write Cache, Enable/Disable Read Ahead
1822 void sati_ata_set_features_construct(
1824 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1828 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1830 sati_set_ata_command(register_fis, ATA_SET_FEATURES);
1831 sati_set_ata_features(register_fis, feature);
1832 sati_ata_non_data_command(ata_io, sequence);
1838 * @brief This method will construct a Read Log ext ATA command that
1839 * will request a log page based on the log_address.
1841 * @param[in] log_address This parameter specifies the log page
1842 * to be returned from Read Log Ext.
1844 * @param[in] transfer_length This parameter specifies the size of the
1845 * log page response returned by Read Log Ext.
1850 void sati_ata_read_log_ext_construct(
1852 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1857 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1859 sati_set_ata_command(register_fis, ATA_READ_LOG_EXT);
1861 sati_set_ata_lba_low(register_fis, log_address);
1862 sati_set_ata_lba_mid(register_fis, 0x00);
1863 sati_set_ata_lba_mid_exp(register_fis, 0x00);
1865 sati_set_ata_sector_count(register_fis, 0x01);
1867 sequence->data_direction = SATI_DATA_DIRECTION_IN;
1868 sequence->protocol = SAT_PROTOCOL_PIO_DATA_IN;
1869 sequence->ata_transfer_length = transfer_length;
1874 * @brief This method will check if the ATA device is in the stopped power
1875 * state. This is used for all medium access commands for SAT
1876 * compliance. See SAT2r07 section 9.11.1
1878 * @param[in] sequence - SATI sequence data with the device state.
1880 * @return TRUE If device is stopped
1883 BOOL sati_device_state_stopped(
1884 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1888 if(sequence->device->state == SATI_DEVICE_STATE_STOPPED)
1890 sati_scsi_sense_data_construct(
1893 SCSI_STATUS_CHECK_CONDITION,
1894 SCSI_SENSE_NOT_READY ,
1895 SCSI_ASC_INITIALIZING_COMMAND_REQUIRED,
1896 SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED
1904 * @brief This method will construct a ATA Read Buffer command that
1905 * will request PIO in data containing the target device's buffer.
1907 * @param[out] ata_io This parameter specifies the ATA IO request structure
1908 * for which to build the ATA READ VERIFY SECTOR(S) command.
1909 * @param[in] sequence This parameter specifies the translator sequence
1910 * for which the command is being constructed.
1914 void sati_ata_read_buffer_construct(
1916 SATI_TRANSLATOR_SEQUENCE_T * sequence
1919 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1921 sati_set_ata_command(register_fis, ATA_READ_BUFFER);
1922 sequence->data_direction = SATI_DATA_DIRECTION_IN;
1923 sequence->protocol = SAT_PROTOCOL_PIO_DATA_IN;
1924 sequence->ata_transfer_length = 512;
1929 * @brief This method will construct a ATA Write Buffer command that
1930 * will send PIO out data to the target device's buffer.
1932 * @param[out] ata_io This parameter specifies the ATA IO request structure
1933 * for which to build the ATA READ VERIFY SECTOR(S) command.
1934 * @param[in] sequence This parameter specifies the translator sequence
1935 * for which the command is being constructed.
1939 void sati_ata_write_buffer_construct(
1941 SATI_TRANSLATOR_SEQUENCE_T * sequence
1944 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1946 sati_set_ata_command(register_fis, ATA_WRITE_BUFFER);
1948 sequence->data_direction = SATI_DATA_DIRECTION_OUT;
1949 sequence->protocol = SAT_PROTOCOL_PIO_DATA_OUT;
1950 sequence->ata_transfer_length = 512;
1955 * @brief This method will construct a ATA Download Microcode command that
1956 * will send PIO out data containing new firmware for the target drive.
1958 * @param[out] ata_io This parameter specifies the ATA IO request structure
1959 * for which to build the ATA READ VERIFY SECTOR(S) command.
1960 * @param[in] sequence This parameter specifies the translator sequence
1961 * for which the command is being constructed.
1962 * @param[in] mode This parameter specifies the download microcode sub-command
1964 * @param[in] allocation_length This parameter specifies the number of bytes
1965 * being sent to the target device.
1966 * @param[in] buffer_offset This parameter specifies the buffer offset for the
1967 * data sent to the target device.
1972 void sati_ata_download_microcode_construct(
1974 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1976 U32 allocation_length,
1980 U8 * register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
1981 U32 allocation_blocks = allocation_length >> 9;
1982 U32 buffer_blkoffset = buffer_offset >> 9;
1984 sati_set_ata_command(register_fis, ATA_DOWNLOAD_MICROCODE);
1985 sati_set_ata_features(register_fis, mode);
1987 if(mode == ATA_MICROCODE_DOWNLOAD_SAVE)
1989 sati_set_ata_sector_count(register_fis, (U8) (allocation_length >> 9));
1990 sati_set_ata_lba_low(register_fis, (U8) (allocation_length >> 17));
1994 sati_set_ata_sector_count(register_fis, (U8) (allocation_blocks & 0xff));
1995 sati_set_ata_lba_low(register_fis, (U8) ((allocation_blocks >> 8) & 0xff));
1996 sati_set_ata_lba_mid(register_fis, (U8) (buffer_blkoffset & 0xff));
1997 sati_set_ata_lba_high(register_fis, (U8) ((buffer_blkoffset >> 8) & 0xff));
2000 if((allocation_length == 0) && (buffer_offset == 0))
2002 sati_ata_non_data_command(ata_io, sequence);
2006 sequence->data_direction = SATI_DATA_DIRECTION_OUT;
2007 sequence->protocol = SAT_PROTOCOL_PIO_DATA_OUT;
2008 sequence->ata_transfer_length = allocation_length;