1230557Sjimharris/*- 2230557Sjimharris * This file is provided under a dual BSD/GPLv2 license. When using or 3230557Sjimharris * redistributing this file, you may do so under either license. 4230557Sjimharris* 5230557Sjimharris* GPL LICENSE SUMMARY 6230557Sjimharris* 7230557Sjimharris* Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 8230557Sjimharris* 9230557Sjimharris* This program is free software; you can redistribute it and/or modify 10230557Sjimharris* it under the terms of version 2 of the GNU General Public License as 11230557Sjimharris* published by the Free Software Foundation. 12230557Sjimharris* 13230557Sjimharris* This program is distributed in the hope that it will be useful, but 14230557Sjimharris* WITHOUT ANY WARRANTY; without even the implied warranty of 15230557Sjimharris* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16230557Sjimharris* General Public License for more details. 17230557Sjimharris* 18230557Sjimharris* You should have received a copy of the GNU General Public License 19230557Sjimharris* along with this program; if not, write to the Free Software 20230557Sjimharris* Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 21230557Sjimharris* The full GNU General Public License is included in this distribution 22230557Sjimharris* in the file called LICENSE.GPL. 23230557Sjimharris* 24230557Sjimharris* BSD LICENSE 25230557Sjimharris* 26230557Sjimharris* Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 27230557Sjimharris* All rights reserved. 28230557Sjimharris* 29230557Sjimharris* Redistribution and use in source and binary forms, with or without 30230557Sjimharris* modification, are permitted provided that the following conditions 31230557Sjimharris* are met: 32230557Sjimharris* 33230557Sjimharris* * Redistributions of source code must retain the above copyright 34230557Sjimharris* notice, this list of conditions and the following disclaimer. 35230557Sjimharris* * Redistributions in binary form must reproduce the above copyright 36230557Sjimharris* notice, this list of conditions and the following disclaimer in 37230557Sjimharris* the documentation and/or other materials provided with the 38230557Sjimharris* distribution. 39230557Sjimharris* 40230557Sjimharris* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41230557Sjimharris* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42230557Sjimharris* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43230557Sjimharris* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44230557Sjimharris* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45230557Sjimharris* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46230557Sjimharris* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47230557Sjimharris* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48230557Sjimharris* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49230557Sjimharris* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50230557Sjimharris* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51230557Sjimharris */ 52230557Sjimharris 53230557Sjimharris#include <sys/cdefs.h> 54230557Sjimharris__FBSDID("$FreeBSD$"); 55230557Sjimharris 56230557Sjimharris/** 57230557Sjimharris* @file 58230557Sjimharris* @brief This file contains the implementation to translate 59230557Sjimharris* SCSI Read Buffer command based on the SAT spec. 60230557Sjimharris*/ 61230557Sjimharris 62230557Sjimharris#if !defined(DISABLE_SATI_READ_BUFFER) 63230557Sjimharris 64230557Sjimharris#include <dev/isci/scil/sati_read_buffer.h> 65230557Sjimharris#include <dev/isci/scil/sati_callbacks.h> 66230557Sjimharris#include <dev/isci/scil/sati_util.h> 67230557Sjimharris 68230557Sjimharris 69230557Sjimharris/** 70230557Sjimharris* @brief This method will translate the SCSI Read Buffer command 71230557Sjimharris* into a corresponding ATA Read Buffer command. 72230557Sjimharris* For more information on the parameters passed to this method, 73230557Sjimharris* please reference sati_translate_command(). 74230557Sjimharris* 75230557Sjimharris* @return Indicates if the command translation succeeded. 76230557Sjimharris* @retval SATI_SUCCESS indicates that the translation was supported and occurred 77230557Sjimharris* without error. 78230557Sjimharris* @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if 79230557Sjimharris* there is a translation failure. 80230557Sjimharris* @retval SATI_COMPLETE indicates that the translation was supported, occurred without 81230557Sjimharris* error, and no additional translation is necessary. 82230557Sjimharris*/ 83230557SjimharrisSATI_STATUS sati_read_buffer_translate_command( 84230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 85230557Sjimharris void * scsi_io, 86230557Sjimharris void * ata_io 87230557Sjimharris) 88230557Sjimharris{ 89230557Sjimharris U8 * cdb = sati_cb_get_cdb_address(scsi_io); 90230557Sjimharris SATI_STATUS status = SATI_FAILURE; 91230557Sjimharris U32 allocation_length; 92230557Sjimharris U32 buffer_offset; 93230557Sjimharris 94230557Sjimharris allocation_length = ((sati_get_cdb_byte(cdb, 6) << 16) | 95230557Sjimharris (sati_get_cdb_byte(cdb, 7) << 8) | 96230557Sjimharris (sati_get_cdb_byte(cdb, 8))); 97230557Sjimharris 98230557Sjimharris buffer_offset = ((sati_get_cdb_byte(cdb, 3) << 16) | 99230557Sjimharris (sati_get_cdb_byte(cdb, 4) << 8) | 100230557Sjimharris (sati_get_cdb_byte(cdb, 5))); 101230557Sjimharris 102230557Sjimharris sequence->allocation_length = allocation_length; 103230557Sjimharris 104230557Sjimharris switch(sati_get_cdb_byte(cdb, 1)) 105230557Sjimharris { 106230557Sjimharris case SATI_READ_BUFFER_MODE_DATA: 107230557Sjimharris if((allocation_length == 512) && (buffer_offset == 0) && 108230557Sjimharris (sati_get_cdb_byte(cdb, 2) == 0)) 109230557Sjimharris { 110230557Sjimharris sati_ata_read_buffer_construct(ata_io, sequence); 111230557Sjimharris sequence->type = SATI_SEQUENCE_READ_BUFFER; 112230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_AWAIT_RESPONSE; 113230557Sjimharris status = SATI_SUCCESS; 114230557Sjimharris } 115230557Sjimharris else 116230557Sjimharris { 117230557Sjimharris sati_scsi_sense_data_construct( 118230557Sjimharris sequence, 119230557Sjimharris scsi_io, 120230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 121230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 122230557Sjimharris SCSI_ASC_INVALID_FIELD_IN_CDB, 123230557Sjimharris SCSI_ASCQ_INVALID_FIELD_IN_CDB 124230557Sjimharris ); 125230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_FINAL; 126230557Sjimharris status = SATI_FAILURE_CHECK_RESPONSE_DATA; 127230557Sjimharris } 128230557Sjimharris break; 129230557Sjimharris 130230557Sjimharris case SATI_READ_BUFFER_MODE_DESCRIPTOR: 131230557Sjimharris 132230557Sjimharris //allocation legnth must be at least four to return translated data 133230557Sjimharris if(allocation_length < 4) 134230557Sjimharris { 135230557Sjimharris sati_scsi_sense_data_construct( 136230557Sjimharris sequence, 137230557Sjimharris scsi_io, 138230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 139230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 140230557Sjimharris SCSI_ASC_INVALID_FIELD_IN_CDB, 141230557Sjimharris SCSI_ASCQ_INVALID_FIELD_IN_CDB 142230557Sjimharris ); 143230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_FINAL; 144230557Sjimharris status = SATI_FAILURE_CHECK_RESPONSE_DATA; 145230557Sjimharris } 146230557Sjimharris else 147230557Sjimharris { 148230557Sjimharris //figure out if we support other buffer id's 149230557Sjimharris sati_set_data_byte(sequence, scsi_io, 0, 0x09); //offset boundary 150230557Sjimharris sati_set_data_byte(sequence, scsi_io, 1, 0x00); 151230557Sjimharris sati_set_data_byte(sequence, scsi_io, 2, 0x02); //buffer capacity 0x200 152230557Sjimharris sati_set_data_byte(sequence, scsi_io, 3, 0x00); 153230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_FINAL; 154230557Sjimharris status = SATI_COMPLETE; 155230557Sjimharris } 156230557Sjimharris break; 157230557Sjimharris 158230557Sjimharris default: 159230557Sjimharris //Unspecified sat2v7, returning invalid cdb 160230557Sjimharris sati_scsi_sense_data_construct( 161230557Sjimharris sequence, 162230557Sjimharris scsi_io, 163230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 164230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 165230557Sjimharris SCSI_ASC_INVALID_FIELD_IN_CDB, 166230557Sjimharris SCSI_ASCQ_INVALID_FIELD_IN_CDB 167230557Sjimharris ); 168230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_FINAL; 169230557Sjimharris status = SATI_FAILURE_CHECK_RESPONSE_DATA; 170230557Sjimharris } 171230557Sjimharris return status; 172230557Sjimharris} 173230557Sjimharris 174230557Sjimharris/** 175230557Sjimharris* @brief This method will complete the Read Buffer Translation by copying the 176230557Sjimharris ATA response data into the SCSI request DATA buffer. 177230557Sjimharris* For more information on the parameters passed to this method, 178230557Sjimharris* please reference sati_translate_command(). 179230557Sjimharris* 180230557Sjimharris* @return Indicates if the command translation succeeded. 181230557Sjimharris* @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if 182230557Sjimharris* there is a translation failure. 183230557Sjimharris* @retval SATI_COMPLETE indicates that the translation was supported, occurred without 184230557Sjimharris* error, and no additional translation is necessary. 185230557Sjimharris*/ 186230557SjimharrisSATI_STATUS sati_read_buffer_translate_response( 187230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 188230557Sjimharris void * scsi_io, 189230557Sjimharris void * ata_io 190230557Sjimharris) 191230557Sjimharris{ 192230557Sjimharris U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io); 193230557Sjimharris U8 ata_status = (U8) sati_get_ata_status(register_fis); 194230557Sjimharris SATI_STATUS status = SATI_COMPLETE; 195230557Sjimharris 196230557Sjimharris if (ata_status & ATA_STATUS_REG_ERROR_BIT) 197230557Sjimharris { 198230557Sjimharris sati_scsi_sense_data_construct( 199230557Sjimharris sequence, 200230557Sjimharris scsi_io, 201230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 202230557Sjimharris SCSI_SENSE_ABORTED_COMMAND, 203230557Sjimharris SCSI_ASC_NO_ADDITIONAL_SENSE, 204230557Sjimharris SCSI_ASCQ_NO_ADDITIONAL_SENSE 205230557Sjimharris ); 206230557Sjimharris 207230557Sjimharris status = SATI_FAILURE_CHECK_RESPONSE_DATA; 208230557Sjimharris } 209230557Sjimharris else 210230557Sjimharris { 211230557Sjimharris void * ata_data = sati_cb_get_ata_data_address(ata_io); 212230557Sjimharris 213230557Sjimharris if(ata_data == NULL) 214230557Sjimharris { 215230557Sjimharris status = SATI_FAILURE; 216230557Sjimharris } 217230557Sjimharris else 218230557Sjimharris { 219230557Sjimharris //copy ATA data into SCSI data buffer 220230557Sjimharris sati_copy_data( 221230557Sjimharris sequence, 222230557Sjimharris scsi_io, 223230557Sjimharris 0, 224230557Sjimharris ata_data, 225230557Sjimharris 512 226230557Sjimharris ); 227230557Sjimharris } 228230557Sjimharris } 229230557Sjimharris 230230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_FINAL; 231230557Sjimharris return status; 232230557Sjimharris} 233230557Sjimharris 234230557Sjimharris 235230557Sjimharris#endif //!defined(DISABLE_SATI_READ_BUFFER) 236