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 mode select (6 and 10-byte) commands with 5
62 * supported mode parameter pages (0x01, 0x02, 0x08, 0x0A, 0x1C).
65 #if !defined(DISABLE_SATI_MODE_SELECT)
67 #include <dev/isci/scil/sati_mode_select.h>
68 #include <dev/isci/scil/sati_mode_pages.h>
69 #include <dev/isci/scil/sati_callbacks.h>
70 #include <dev/isci/scil/sci_object.h>
71 #include <dev/isci/scil/sati_translator_sequence.h>
72 #include <dev/isci/scil/sati_util.h>
74 //******************************************************************************
75 //* P R I V A T E M E T H O D S
76 //******************************************************************************
79 * @brief This method will get medium type parameter field per CDB size.
81 * @param[in] scsi_io This parameter specifies the user's SCSI IO object
82 * for which to calculate the mode page header.
83 * @param[in] cdb_size This parameter specifies the number of bytes
84 * associated with the CDB for which to calculate the header.
86 * @return This method returns the medium type for the mode page header.
89 U8 sati_mode_select_get_medium_type(
95 SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_6_T * mode_parameters_6;
96 SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_10_T * mode_parameters_10;
100 mode_parameters_6 = (SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_6_T *) mode_parameters;
101 medium_type = mode_parameters_6->medium_type;
103 else if(cdb_size == 10)
105 mode_parameters_10 = (SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_10_T *) mode_parameters;
106 medium_type = mode_parameters_10->medium_type;
113 * @brief This method will retrieve Block Descriptor Length.
115 * @param[in] mode_parameters This parameter contains the address to the mode parameters.
116 * @param[in] cdb_size This parameter specifies the number of bytes
117 * associated with the CDB for which to process the block descriptor.
119 * @return This method returns the size, in bytes, for the mode parameter block descriptor.
122 U32 sati_mode_select_get_mode_block_descriptor_length(
123 U8 * mode_parameters,
127 U32 mode_block_descriptor_length = 0;
128 SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_6_T * mode_parameters_6;
129 SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_10_T * mode_parameters_10;
133 mode_parameters_6 = (SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_6_T *) mode_parameters;
134 mode_block_descriptor_length = mode_parameters_6->block_descriptor_length;
136 else if(cdb_size == 10)
138 mode_parameters_10 = (SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_10_T *) mode_parameters;
139 //Long LBA bit is the bit0 of the byte
140 //Spec says another way to get the block descriptor length to multiply the block number
141 // with block length (8 or 16), but we can get it directly.
142 mode_block_descriptor_length =(((U16)mode_parameters_10->block_descriptor_length[0]) << 8) +
143 mode_parameters_10->block_descriptor_length[1];
147 return mode_block_descriptor_length;
152 * @brief This method will find the starting byte location for a page.
154 * @param[in] block_descriptor_length This parameter passes in the length of
156 * @param[in] cdb_size This parameter specifies the number of bytes
157 * associated with the CDB for which to calculate the header.
159 * @return This method returns the offset, for the mode page.
162 U32 sati_mode_select_get_mode_page_offset(
163 U32 block_descriptor_length,
167 U32 mode_page_offset;
171 mode_page_offset = sizeof(SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_6_T) + block_descriptor_length;
173 else if(cdb_size == 10)
175 mode_page_offset = sizeof(SCSI_MODE_SELECT_MODE_PARAMETER_HEADER_10_T) + block_descriptor_length;
179 mode_page_offset = 0;
182 return mode_page_offset;
186 * @brief This method will set the initial Mode Select processing state.
189 void sati_mode_select_initialize_mode_sel_processing_state(
190 SATI_TRANSLATOR_SEQUENCE_T * sequence,
193 U32 data_transfer_length,
197 sequence->command_specific_data.process_state.ata_command_sent_for_cmp = 0;
198 sequence->command_specific_data.process_state.mode_page_offset=mode_page_offset;
199 sequence->command_specific_data.process_state.mode_pages_size = data_transfer_length - mode_page_offset;
200 sequence->command_specific_data.process_state.size_of_data_processed = 0;
201 sequence->command_specific_data.process_state.current_mode_page_processed = FALSE;
205 * @brief This method will get mode page size.
207 * @param[in] page_code This parameter contains page code for the current mode page.
209 * @return This method returns the size of current mode page.
212 U32 sati_mode_select_get_mode_page_size(
220 case SCSI_MODE_PAGE_READ_WRITE_ERROR:
221 page_size=SCSI_MODE_PAGE_01_LENGTH;
224 case SCSI_MODE_PAGE_DISCONNECT_RECONNECT:
225 page_size=SCSI_MODE_PAGE_02_LENGTH;
228 case SCSI_MODE_PAGE_CACHING:
229 page_size=SCSI_MODE_PAGE_08_LENGTH;
232 case SCSI_MODE_PAGE_CONTROL:
233 page_size=SCSI_MODE_PAGE_0A_LENGTH;
236 case SCSI_MODE_PAGE_INFORMATIONAL_EXCP_CONTROL:
237 page_size=SCSI_MODE_PAGE_1C_LENGTH;
240 case SCSI_MODE_PAGE_POWER_CONDITION:
241 page_size=SCSI_MODE_PAGE_1A_LENGTH;
252 * @brief This method will check the validity of parameter data of Read Write Error Recovery
253 * page and further processing the page data if necessary.
255 * @param[in] page_size This parameter specifies page size of current mode page.
257 * @return Indicate if the translation was successful.
258 * @retval SATI_SUCCESS
259 * @retval SATI_COMPLETE
260 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
263 SATI_STATUS sati_mode_select_process_mode_page_read_write_error_recovery(
264 SATI_TRANSLATOR_SEQUENCE_T* sequence,
269 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
271 U8 current_mode_page[SCSI_MODE_PAGE_01_LENGTH]={0,0,0,0,0,0,0,0,0,0,0,0};
272 U32 mode_page_offset;
274 mode_page_offset = sequence->command_specific_data.process_state.mode_page_offset;
276 //Check all the defined bits for this page
277 //SPF(0b); Page length 0x0A;AWRE 1; ARRE 0; Error recovery bits 0; RC 0;
278 //Recovery time limit last two bytes 0
280 sati_get_data_byte(sequence, scsi_io, mode_page_offset, ¤t_mode_page[0]);
281 sati_get_data_byte(sequence, scsi_io, mode_page_offset+1, ¤t_mode_page[1]);
282 sati_get_data_byte(sequence, scsi_io, mode_page_offset+2, ¤t_mode_page[2]);
283 sati_get_data_byte(sequence, scsi_io, mode_page_offset+10, ¤t_mode_page[10]);
284 sati_get_data_byte(sequence, scsi_io, mode_page_offset+11, ¤t_mode_page[11]);
286 if ( ((current_mode_page[0] & SCSI_MODE_SELECT_MODE_PAGE_SPF_MASK)!= 0) ||
287 (current_mode_page[1] != (SCSI_MODE_PAGE_01_LENGTH - 2)) ||
288 ((current_mode_page[2] & SCSI_MODE_SELECT_MODE_PAGE_01_AWRE_MASK) == 0) ||
289 ((current_mode_page[2] & SCSI_MODE_SELECT_MODE_PAGE_01_ARRE_MASK) != 0) ||
290 ((current_mode_page[2] & SCSI_MODE_SELECT_MODE_PAGE_01_RC_ERBITS_MASK) != 0) ||
291 (current_mode_page[10] != 0 ) ||
292 (current_mode_page[11] != 0 ) )
294 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
298 //no need to send any command
300 sequence->command_specific_data.process_state.size_of_data_processed += page_size;
301 sequence->command_specific_data.process_state.mode_page_offset += page_size;
302 sequence->command_specific_data.process_state.current_mode_page_processed = TRUE;
305 status = SATI_COMPLETE;
311 * @brief This method will check the validity of parameter data of Disconnect Reconnect mode
312 * page and further processing the page data if necessary.
314 * @param[in] page_size This parameter specifies page size of current mode page.
316 * @return Indicate if the translation was successful.
317 * @retval SATI_SUCCESS
318 * @retval SATI_COMPLETE
319 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
322 SATI_STATUS sati_mode_select_process_mode_page_disconnect_reconnect(
323 SATI_MODE_SELECT_PROCESSING_STATE_T * mode_select_process_state,
327 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
329 // No need to check data for valid or invalid this page (undefined)
330 // No ata command to send
332 mode_select_process_state->size_of_data_processed += page_size;
333 mode_select_process_state->mode_page_offset += page_size;
334 mode_select_process_state->current_mode_page_processed = TRUE;
337 // No further interaction with remote devices
338 status = SATI_COMPLETE;
344 * @brief This method will check the validity of parameter data of Caching mode
345 * page and issue multiple ATA set feature commands to complete the translation.
347 * @param[in] page_size This parameter specifies page size of current mode page.
349 * @return Indicate if the translation was successful.
350 * @retval SATI_SUCCESS
351 * @retval SATI_COMPLETE
352 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
355 SATI_STATUS sati_mode_select_process_mode_page_caching(
356 SATI_TRANSLATOR_SEQUENCE_T * sequence,
362 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
364 //SCSI_MODE_PAGE_08_LENGTH 0x14= 20
365 U8 current_mode_page[SCSI_MODE_PAGE_08_LENGTH] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
366 U32 mode_page_offset;
369 mode_page_offset = sequence->command_specific_data.process_state.mode_page_offset;
370 sequence->type = SATI_SEQUENCE_MODE_SELECT_MODE_PAGE_CACHING;
372 for(index = 0; index < SCSI_MODE_PAGE_08_LENGTH; index++)
374 sati_get_data_byte(sequence, scsi_io, mode_page_offset+index, ¤t_mode_page[index]);
377 //Check for data validity
378 //SPF(0b); Page length 0x12;Byte2 to Byte15 all 0 with exception DRA and WCE changeable
380 if (((current_mode_page[0] & SCSI_MODE_SELECT_MODE_PAGE_SPF_MASK)!= 0) ||
381 (current_mode_page[1] != (SCSI_MODE_PAGE_08_LENGTH-2)) ||
382 ((current_mode_page[2] | SCSI_MODE_PAGE_CACHE_PAGE_WCE_BIT)!=SCSI_MODE_PAGE_CACHE_PAGE_WCE_BIT) ||
383 (current_mode_page[3] != 0 ) ||
384 (current_mode_page[4] != 0 ) ||
385 (current_mode_page[5] != 0 ) ||
386 (current_mode_page[6] != 0 ) ||
387 (current_mode_page[7] != 0 ) ||
388 (current_mode_page[8] != 0 ) ||
389 (current_mode_page[9] != 0 ) ||
390 (current_mode_page[10] != 0 ) ||
391 (current_mode_page[11] != 0 ) ||
392 ((current_mode_page[12] & SCSI_MODE_SELECT_MODE_PAGE_08_FSW_LBCSS_NVDIS) != 0) ||
393 (current_mode_page[13] != 0 ) ||
394 (current_mode_page[14] != 0 ) ||
395 (current_mode_page[15] != 0 ))
397 //parameter data passed in containing data that doesn't meet the SAT-2 requirement
398 return SATI_FAILURE_CHECK_RESPONSE_DATA;
401 if(sequence->command_specific_data.process_state.ata_command_sent_for_cmp == 0)
403 //byte2 bit2 WCE==0 disable write cache WCE==1 enable write cache
404 //SCSI_MODE_PAGE_CACHE_PAGE_WCE_BIT ==0x4,
406 if ( (current_mode_page[2] & SCSI_MODE_PAGE_CACHE_PAGE_WCE_BIT) == 0)
407 sati_ata_set_features_construct(ata_io, sequence, ATA_SET_FEATURES_SUB_CMD_DISABLE_CACHE);
409 sati_ata_set_features_construct(ata_io, sequence, ATA_SET_FEATURES_SUB_CMD_ENABLE_CACHE);
412 else if(sequence->command_specific_data.process_state.ata_command_sent_for_cmp == 1)
414 // DRA bit is set to 0, enable Read look ahead AAh;
415 // DRA bit is set to 1, disable with set feature command 55h
416 // SCSI_MODE_PAGE_CACHE_PAGE_DRA_BIT== 0x20
418 if ( (current_mode_page[12] & SCSI_MODE_PAGE_CACHE_PAGE_DRA_BIT) == 0)
419 sati_ata_set_features_construct(ata_io, sequence,ATA_SET_FEATURES_SUB_CMD_ENABLE_READ_AHEAD);
421 sati_ata_set_features_construct(ata_io, sequence,ATA_SET_FEATURES_SUB_CMD_DISABLE_READ_AHEAD);
423 sequence->command_specific_data.process_state.size_of_data_processed += page_size;
424 sequence->command_specific_data.process_state.mode_page_offset += page_size;
425 sequence->command_specific_data.process_state.current_mode_page_processed = TRUE;
429 // No more ata commands to send
431 sequence->command_specific_data.process_state.ata_command_sent_for_cmp++;
433 status = SATI_SUCCESS;
439 * @brief This method will check the validity of parameter data of Control mode
440 * page and further processing the page data if necessary.
442 * @param[in] mode_select_process_state This parameter points to the processing state fields
443 * of current mode page.
444 * @param[in] page_size This parameter specifies page size of current mode page.
446 * @return Indicate if the translation was successful.
447 * @retval SATI_SUCCESS
448 * @retval SATI_COMPLETE
449 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
452 SATI_STATUS sati_mode_select_process_mode_page_control(
453 SATI_TRANSLATOR_SEQUENCE_T* sequence,
459 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
461 //SCSI_MODE_PAGE_0A_LENGTH 12
462 U8 current_mode_page[SCSI_MODE_PAGE_0A_LENGTH]={0,0,0,0,0,0,0,0,0,0};
463 U32 mode_page_offset;
466 mode_page_offset = sequence->command_specific_data.process_state.mode_page_offset;
468 for(index = 0; index < SCSI_MODE_PAGE_0A_LENGTH; index++)
470 sati_get_data_byte(sequence, scsi_io, mode_page_offset+index, ¤t_mode_page[index]);
473 //bit 1 and 2 of byte3 Qerr full task management model etc. then both bits 0
474 //byte 8 and 9 busy time out period variable if not ffff setable?
475 //check for page data validity
476 //Byte2: 0000???0b Byte3: Queued Algorithm Modifier should be set to 1 QErr?
477 //Byte4: ??000??? Byte5: ?0???000
479 if (((current_mode_page[0] & SCSI_MODE_SELECT_MODE_PAGE_SPF_MASK)!= 0) ||
480 (current_mode_page[1] != (SCSI_MODE_PAGE_0A_LENGTH - 2)) ||
481 ((current_mode_page[2] & SCSI_MODE_SELECT_MODE_PAGE_0A_TST_TMF_RLEC) != 0) ||
482 ((current_mode_page[3] & SCSI_MODE_SELECT_MODE_PAGE_0A_MODIFIER) != 0) ||
483 ((current_mode_page[4] & SCSI_MODE_SELECT_MODE_PAGE_0A_UA_SWP ) != 0) ||
484 ((current_mode_page[5] & SCSI_MODE_SELECT_MODE_PAGE_0A_TAS_AUTO ) != 0 ) )
486 return SATI_FAILURE_CHECK_RESPONSE_DATA;
489 if ((current_mode_page[2] & SCSI_MODE_SELECT_MODE_PAGE_D_SENSE) != 0)
490 sequence->device->descriptor_sense_enable = SCSI_MODE_PAGE_CONTROL_D_SENSE_ENABLE;
492 sequence->device->descriptor_sense_enable = SCSI_MODE_PAGE_CONTROL_D_SENSE_DISABLE;
494 // no ata command need to be comfirmed
496 sequence->command_specific_data.process_state.size_of_data_processed += page_size;
497 sequence->command_specific_data.process_state.mode_page_offset += page_size;
498 sequence->command_specific_data.process_state.current_mode_page_processed = TRUE;
501 status = SATI_COMPLETE;
507 * @brief This method will check the validity of parameter data of Information Exception Control
508 * mode page and further processing the page data if necessary.
510 * @param[in] page_size This parameter specifies page size of current mode page.
512 * @return Indicate if the translation was successful.
513 * @retval SATI_SUCCESS
514 * @retval SATI_COMPLETE
515 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
518 SATI_STATUS sati_mode_select_process_mode_page_informational_exception_control(
519 SATI_TRANSLATOR_SEQUENCE_T * sequence,
525 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
527 //SCSI_MODE_PAGE_1C_LENGTH 12
528 U8 current_mode_page[SCSI_MODE_PAGE_1C_LENGTH]={0,0,0,0,0,0,0,0,0,0,0,0};
529 U32 mode_page_offset;
532 mode_page_offset = sequence->command_specific_data.process_state.mode_page_offset;
533 sequence->type = SATI_SEQUENCE_MODE_SELECT_MODE_INFORMATION_EXCEPT_CONTROL;
535 for(index = 0; index < 4; index++)
537 sati_get_data_byte(sequence, scsi_io, mode_page_offset+index, ¤t_mode_page[index]);
540 //Check for data validity
541 //SPF(0b); Page length 0x0A; Byte2 0????0?? Byte3: ????1100
542 //SCSI_MODE_SELECT_MODE_PAGE_MRIE_BYTE same as REPORT_INFO_EXCEPTION_CONDITION_ON_REQUEST 0x6
543 //SCSI_MODE_PAGE_DEXCPT_ENABLE
545 if (((current_mode_page[0] & SCSI_MODE_SELECT_MODE_PAGE_SPF_MASK)!= 0) ||
546 (current_mode_page[1] != (SCSI_MODE_PAGE_1C_LENGTH - 2)) ||
547 ((current_mode_page[2] & SCSI_MODE_SELECT_MODE_PAGE_1C_PERF_TEST)!= 0 ) ||
548 ((current_mode_page[3] & SCSI_MODE_SELECT_MODE_PAGE_MRIE_MASK) !=
549 SCSI_MODE_SELECT_MODE_PAGE_MRIE_BYTE ))
551 return SATI_FAILURE_CHECK_RESPONSE_DATA;
554 // DEXCPT bit is set to 0, enable SMART reporting D8h;
555 // DEXCPT bit is set to 1, disable SMART reporting D9h
556 // SCSI_MODE_PAGE_DEXCPT_ENABLE== 0x08
558 if ( (current_mode_page[2] & SCSI_MODE_PAGE_DEXCPT_ENABLE) == 0)
559 sati_ata_smart_return_status_construct(ata_io, sequence, ATA_SMART_SUB_CMD_ENABLE);
561 sati_ata_smart_return_status_construct(ata_io, sequence, ATA_SMART_SUB_CMD_DISABLE);
563 sequence->command_specific_data.process_state.size_of_data_processed += page_size;
564 sequence->command_specific_data.process_state.mode_page_offset += page_size;
565 sequence->command_specific_data.process_state.current_mode_page_processed = TRUE;
566 // No more ata commands to send
568 status = SATI_SUCCESS;
574 * @brief This method will check the validity of parameter data of Power Condition mode
575 * page and issue multiple ATA set feature commands to complete the translation.
577 * @param[in] mode_select_process_state This parameter points to the processing state fields
578 * of current mode page.
579 * @param[in] page_size This parameter specifies page size of current mode page.
581 * @return Indicate if the translation was successful.
582 * @retval SATI_SUCCESS
583 * @retval SATI_COMPLETE
584 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
587 SATI_STATUS sati_mode_select_process_mode_page_power_condition(
588 SATI_TRANSLATOR_SEQUENCE_T * sequence,
594 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
596 //SCSI_MODE_PAGE_1A_LENGTH 10
597 U8 current_mode_page[SCSI_MODE_PAGE_1A_LENGTH] = {0,0,0,0,0,0,0,0,0,0};
598 U32 mode_page_offset;
604 mode_page_offset = sequence->command_specific_data.process_state.mode_page_offset;
606 sequence->type = SATI_SEQUENCE_MODE_SELECT_MODE_POWER_CONDITION;
608 for(index = 0; index < SCSI_MODE_PAGE_1A_LENGTH; index++)
610 sati_get_data_byte(sequence, scsi_io, mode_page_offset+index, ¤t_mode_page[index]);
613 //Check for data validity
614 //SPF(0b); Page length 0x0A;
616 if (((current_mode_page[0] & SCSI_MODE_SELECT_MODE_PAGE_SPF_MASK)!= 0) ||
617 (current_mode_page[1] != (SCSI_MODE_PAGE_1A_LENGTH - 2) ) ||
618 ((current_mode_page[3] & SCSI_MODE_PAGE_POWER_CONDITION_IDLE)!= 0)
621 //parameter data passed in containing data that doesn't meet the SAT-2 requirement
622 return SATI_FAILURE_CHECK_RESPONSE_DATA;
625 // STANDBY bit is set to 0, do nothing since the standby timer can't be set;
626 // STANDBY bit is set to 1, translate the standby timer
627 // SCSI_MODE_PAGE_POWER_CONDITION_STANDBY== 0x01
628 if (current_mode_page[3] & SCSI_MODE_PAGE_POWER_CONDITION_STANDBY)
630 timer = (current_mode_page[8]<<24) + (current_mode_page[9]<<16) + (current_mode_page[10]<<8) + current_mode_page[11];
632 //If the ATA IDENTIFY DEVICE data word 49, bit 13 is set to one,
633 if (sequence->device->capabilities & SATI_DEVICE_CAP_STANDBY_ENABLE)
637 //TPV=0 send ATA STANDBY_IMMEDIATE
638 sati_ata_standby_immediate_construct(ata_io, sequence);
639 sequence->command_specific_data.translated_command = ATA_STANDBY_IMMED;
641 else if ((timer > 0) && (timer <= 12000))
643 //1 to 12 000 INT((z - 1) / 50) + 1
644 count = (U16)((timer -1) / 50) + 1;
645 sati_ata_standby_construct(ata_io, sequence, count);
647 else if ((timer > 12000) && (timer <= 12600))
649 //12 001 to 12 600 FCh
650 sati_ata_standby_construct(ata_io, sequence, 0xFC);
652 else if ((timer > 12600) && (timer <= 12750))
654 //12 601 to 12 750 FFh
655 sati_ata_standby_construct(ata_io, sequence, 0xFF);
657 else if ((timer > 12750) && (timer < 18000))
659 //12 751 to 17 999 F1h
660 sati_ata_standby_construct(ata_io, sequence, 0xF1);
662 else if ((timer >= 18000) && (timer <= 198000))
664 //18 000 to 198 000 INT(z / 18 000) + 240
665 count = (U16)(timer / 18000) + 240;
666 sati_ata_standby_construct(ata_io, sequence, count);
670 //All other values FDh
671 sati_ata_standby_construct(ata_io, sequence, 0xFD);
673 status = SATI_SUCCESS ;
677 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
678 //If the ATA IDENTIFY DEVICE data word 49, bit 13 is set to 0
683 status = SATI_COMPLETE;
686 sequence->command_specific_data.process_state.size_of_data_processed += page_size;
687 sequence->command_specific_data.process_state.mode_page_offset += page_size;
688 sequence->command_specific_data.process_state.current_mode_page_processed = TRUE;
694 * @brief This method will process the mode page.
697 * @return Indicate if the translation was successful.
698 * @retval SATI_SUCCESS
699 * @retval SATI_COMPLETE
700 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA
703 SATI_STATUS sati_mode_select_process_mode_page(
704 SATI_TRANSLATOR_SEQUENCE_T* sequence,
709 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
712 U32 page_size = 0; // in bytes
713 U32 size_of_data_to_be_processed;
716 U32 mode_page_offset;
718 mode_page_offset = sequence->command_specific_data.process_state.mode_page_offset;
720 sati_get_data_byte(sequence, scsi_io, mode_page_offset, &page_code_byte);
723 if(sequence->command_specific_data.process_state.mode_pages_size >
724 sequence->command_specific_data.process_state.size_of_data_processed)
726 //SCSI_MODE_SENSE_PAGE_CODE_ENABLE==0x3f same for Mode Select
727 page_code = page_code_byte & SCSI_MODE_SENSE_PAGE_CODE_ENABLE;
728 page_size = sati_mode_select_get_mode_page_size(page_code);
729 size_of_data_to_be_processed = sequence->command_specific_data.process_state.mode_pages_size
730 - sequence->command_specific_data.process_state.size_of_data_processed;
734 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
741 case SCSI_MODE_PAGE_READ_WRITE_ERROR:
742 status = sati_mode_select_process_mode_page_read_write_error_recovery(
749 case SCSI_MODE_PAGE_DISCONNECT_RECONNECT:
750 status = sati_mode_select_process_mode_page_disconnect_reconnect(
751 &sequence->command_specific_data.process_state,
756 case SCSI_MODE_PAGE_CACHING:
757 status = sati_mode_select_process_mode_page_caching(
765 case SCSI_MODE_PAGE_CONTROL:
766 status = sati_mode_select_process_mode_page_control(
774 case SCSI_MODE_PAGE_INFORMATIONAL_EXCP_CONTROL:
775 status = sati_mode_select_process_mode_page_informational_exception_control(
783 case SCSI_MODE_PAGE_POWER_CONDITION:
784 status = sati_mode_select_process_mode_page_power_condition(
803 //******************************************************************************
804 //* P U B L I C M E T H O D S
805 //******************************************************************************
808 * @brief This method will translate the SCSI Mode Select 6 byte or 10 byte command
809 * into corresponding ATA commands. Depending upon the capabilities
810 * supported by the target different ATA commands can be selected.
811 * Additionally, in some cases more than a single ATA command may
814 * @return Indicate if the command translation succeeded.
815 * @retval SCI_SUCCESS This is returned if the command translation was
817 * @retval SCI_COMPLETE This is returned if the command translation was
818 * successful and no ATA commands need to be set.
819 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
820 * sense data has been created as a result of something specified
821 * in the parameter data fields.
824 SATI_STATUS sati_mode_select_translate_command(
825 SATI_TRANSLATOR_SEQUENCE_T * sequence,
831 SATI_STATUS status = SATI_FAILURE_CHECK_RESPONSE_DATA;
832 U32 mode_page_offset;
833 U32 block_descriptor_length;
835 U16 data_transfer_length;
836 U8 current_mode_parameters[8]={0,0,0,0,0,0,0,0};
837 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
839 // cdb_size must be 6 or 10
840 if(FALSE == (cdb_size == 6 || cdb_size == 10))
845 if(sequence->state == SATI_SEQUENCE_STATE_INITIAL)
847 sequence->command_specific_data.process_state.ata_command_sent_for_cmp = 0;
848 sequence->state = SATI_SEQUENCE_STATE_TRANSLATE_DATA;
851 //First, initializes mode_sel_processing_state
852 if ( sequence->command_specific_data.process_state.ata_command_sent_for_cmp == 0 )
856 //CDB byte 4 is the parameter length
857 data_transfer_length = sati_get_cdb_byte(cdb, 4);
861 //CDB byte 7 and 8 for Mode Select 10
862 data_transfer_length = (sati_get_cdb_byte(cdb, 7) << 8) + sati_get_cdb_byte(cdb, 8);
865 sequence->allocation_length = data_transfer_length;
867 //Get 8 bytes for headers (4 bytes for Mode Select 6 and 8 bytes for Mode Select 10)
868 for( index = 0; index < 8; index++ )
870 sati_get_data_byte(sequence, scsi_io, index, ¤t_mode_parameters[index]);
873 //medium type should be 0
874 if ( sati_mode_select_get_medium_type(current_mode_parameters, cdb_size) != 0 )
876 sati_scsi_sense_data_construct(
879 SCSI_STATUS_CHECK_CONDITION,
880 SCSI_SENSE_ILLEGAL_REQUEST,
881 SCSI_ASC_INVALID_FIELD_IN_PARM_LIST,
882 SCSI_ASCQ_INVALID_FIELD_IN_PARM_LIST
887 block_descriptor_length = sati_mode_select_get_mode_block_descriptor_length(
888 current_mode_parameters,
892 mode_page_offset = sati_mode_select_get_mode_page_offset(
893 block_descriptor_length,
897 if(mode_page_offset > data_transfer_length)
899 sequence->state = SATI_SEQUENCE_STATE_FINAL;
900 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
904 sati_mode_select_initialize_mode_sel_processing_state(
908 data_transfer_length,
915 // move to next mode page
916 if(sequence->command_specific_data.process_state.current_mode_page_processed)
918 sequence->command_specific_data.process_state.ata_command_sent_for_cmp = 0;
919 sequence->command_specific_data.process_state.current_mode_page_processed = FALSE;
922 status = sati_mode_select_process_mode_page(sequence, scsi_io, ata_io);
924 if(sequence->command_specific_data.process_state.current_mode_page_processed != FALSE)
927 sequence->state = SATI_SEQUENCE_STATE_FINAL;
931 sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE;
934 if(status == SATI_FAILURE_CHECK_RESPONSE_DATA)
936 sequence->state = SATI_SEQUENCE_STATE_FINAL;
937 sati_scsi_sense_data_construct(
940 SCSI_STATUS_CHECK_CONDITION,
941 SCSI_SENSE_ILLEGAL_REQUEST,
942 SCSI_ASC_INVALID_FIELD_IN_PARM_LIST,
943 SCSI_ASCQ_INVALID_FIELD_IN_PARM_LIST
951 * @brief This method will call Mode Select 6 Translation command
952 * For more information on the parameters passed to this method,
953 * please reference sati_translate_command().
955 * @return Indicate if the command translation succeeded.
956 * @retval SCI_SUCCESS This is returned if the command translation was
958 * @retval SCI_COMPLETE This is returned if the command translation was
959 * successful and no ATA commands need to be set.
960 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
961 * sense data has been created as a result of something specified
962 * in the parameter data fields.
964 SATI_STATUS sati_mode_select_6_translate_command(
965 SATI_TRANSLATOR_SEQUENCE_T * sequence,
970 SATI_STATUS status=SATI_FAILURE;
971 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
973 //PF bit needs to be 1 byte1 bit ???1????
974 if ((sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SELECT_PF_MASK) == !SCSI_MODE_SELECT_PF_BIT)
976 sati_scsi_sense_data_construct(
979 SCSI_STATUS_CHECK_CONDITION,
980 SCSI_SENSE_ILLEGAL_REQUEST,
981 SCSI_ASC_INVALID_FIELD_IN_CDB,
982 SCSI_ASCQ_INVALID_FIELD_IN_CDB
984 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
988 status=sati_mode_select_translate_command(
995 if(status == SATI_FAILURE_CHECK_RESPONSE_DATA)
997 sati_scsi_sense_data_construct(
1000 SCSI_STATUS_CHECK_CONDITION,
1001 SCSI_SENSE_ILLEGAL_REQUEST,
1002 SCSI_ASC_INVALID_FIELD_IN_PARM_LIST,
1003 SCSI_ASCQ_INVALID_FIELD_IN_PARM_LIST
1011 * @brief This method will call Mode Select 10 translation command
1012 * For more information on the parameters passed to this method,
1013 * please reference sati_translate_command().
1015 * @return Indicate if the command translation succeeded.
1016 * @retval SCI_SUCCESS This is returned if the command translation was
1018 * @retval SCI_COMPLETE This is returned if the command translation was
1019 * successful and no ATA commands need to be set.
1020 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
1021 * sense data has been created as a result of something specified
1022 * in the parameter data fields.
1024 SATI_STATUS sati_mode_select_10_translate_command(
1025 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1030 SATI_STATUS status=SATI_FAILURE;
1031 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
1033 //PF bit needs to be 1 byte1 bit ???1????
1034 if ((sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SELECT_PF_MASK) == !SCSI_MODE_SELECT_PF_BIT)
1036 sati_scsi_sense_data_construct(
1039 SCSI_STATUS_CHECK_CONDITION,
1040 SCSI_SENSE_ILLEGAL_REQUEST,
1041 SCSI_ASC_INVALID_FIELD_IN_CDB,
1042 SCSI_ASCQ_INVALID_FIELD_IN_CDB
1044 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
1048 status=sati_mode_select_translate_command(
1055 if(status == SATI_FAILURE_CHECK_RESPONSE_DATA)
1057 sati_scsi_sense_data_construct(
1060 SCSI_STATUS_CHECK_CONDITION,
1061 SCSI_SENSE_ILLEGAL_REQUEST,
1062 SCSI_ASC_INVALID_FIELD_IN_PARM_LIST,
1063 SCSI_ASCQ_INVALID_FIELD_IN_PARM_LIST
1070 * @brief This method will conduct error handling for the ATA Set Features command
1071 * that is issued during a Mode Select translation for the Caching Mode
1075 * @return Indicate if the command translation succeeded.
1077 * @retval SCI_COMPLETE This is returned if the command translation was
1078 * successful and no additional ATA commands need to be set.
1079 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
1080 * sense data has been created as a result of an error returned
1082 SATI_STATUS sati_mode_select_translate_response(
1083 SATI_TRANSLATOR_SEQUENCE_T * sequence,
1088 U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
1089 SATI_STATUS status = SATI_FAILURE;
1091 if(sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT)
1093 sati_scsi_sense_data_construct(
1096 SCSI_STATUS_CHECK_CONDITION,
1097 SCSI_SENSE_ABORTED_COMMAND,
1098 SCSI_ASC_NO_ADDITIONAL_SENSE,
1099 SCSI_ASCQ_NO_ADDITIONAL_SENSE
1101 status = SATI_FAILURE_CHECK_RESPONSE_DATA;
1105 if (sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE)
1107 status = SATI_SEQUENCE_INCOMPLETE;
1111 status = SATI_COMPLETE;
1117 #endif // !defined(DISABLE_SATI_MODE_SELECT)