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 Write Long 10 and 16 commands based on the SAT spec. 60230557Sjimharris */ 61230557Sjimharris 62230557Sjimharris#if !defined(DISABLE_SATI_WRITE_LONG) 63230557Sjimharris 64230557Sjimharris#include <dev/isci/scil/sati_write_long.h> 65230557Sjimharris#include <dev/isci/scil/sati_device.h> 66230557Sjimharris#include <dev/isci/scil/sati_util.h> 67230557Sjimharris#include <dev/isci/scil/intel_scsi.h> 68230557Sjimharris#include <dev/isci/scil/intel_ata.h> 69230557Sjimharris#include <dev/isci/scil/intel_sat.h> 70230557Sjimharris#include <dev/isci/scil/sati_callbacks.h> 71230557Sjimharris#include <dev/isci/scil/sati_move.h> 72230557Sjimharris 73230557Sjimharris#define LOGICAL_PER_PHYSICAL_SECTOR 0xF 74230557Sjimharris 75230557Sjimharris#define WR_UNCOR_BIT 0x02 76230557Sjimharris#define WR_UNCOR_PBLOCK_BIT 0x03 77230557Sjimharris#define COR_DIS_WR_UNCORR_BIT 0x06 78230557Sjimharris 79230557Sjimharris 80230557Sjimharris/** 81230557Sjimharris * @brief This method will translate the write long 10 & 16 SCSI commands into 82230557Sjimharris * ATA write uncorrectable commands. For more information on the 83230557Sjimharris * parameters passed to this method, please reference 84230557Sjimharris * sati_translate_command(). 85230557Sjimharris * 86230557Sjimharris * @return Indicate if the command translation succeeded. 87230557Sjimharris * @retval SCI_SUCCESS This is returned if the command translation was 88230557Sjimharris * successful. 89230557Sjimharris * @retval SATI_FAILURE_CHECK_RESPONSE_DATA is returned if there was 90230557Sjimharris * a problem with the translation of write long. 91230557Sjimharris * 92230557Sjimharris */ 93230557SjimharrisSATI_STATUS sati_write_long_translate_command( 94230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 95230557Sjimharris void * scsi_io, 96230557Sjimharris void * ata_io 97230557Sjimharris) 98230557Sjimharris{ 99230557Sjimharris U8 * cdb = sati_cb_get_cdb_address(scsi_io); 100230557Sjimharris SATI_STATUS status = SATI_FAILURE; 101230557Sjimharris U16 byte_transfer_length; 102230557Sjimharris U8 device_head = 0; 103230557Sjimharris 104230557Sjimharris if((sequence->device->capabilities & 105230557Sjimharris SATI_DEVICE_CAP_WRITE_UNCORRECTABLE_ENABLE) == 0) 106230557Sjimharris { 107230557Sjimharris sati_scsi_sense_data_construct( 108230557Sjimharris sequence, 109230557Sjimharris scsi_io, 110230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 111230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 112230557Sjimharris SCSI_ASC_INVALID_COMMAND_OPERATION_CODE, 113230557Sjimharris SCSI_ASCQ_INVALID_COMMAND_OPERATION_CODE 114230557Sjimharris ); 115230557Sjimharris return SATI_FAILURE_CHECK_RESPONSE_DATA; 116230557Sjimharris } 117230557Sjimharris 118230557Sjimharris //Write Long 10 119230557Sjimharris if(sati_get_cdb_byte(cdb, 0) == SCSI_WRITE_LONG_10) 120230557Sjimharris { 121230557Sjimharris byte_transfer_length = (sati_get_cdb_byte(cdb, 7) << 8) | 122230557Sjimharris (sati_get_cdb_byte(cdb, 8)); 123230557Sjimharris 124230557Sjimharris sati_move_translate_32_bit_lba(sequence, scsi_io, ata_io); 125230557Sjimharris } 126230557Sjimharris else //Write Long 16 127230557Sjimharris { 128230557Sjimharris byte_transfer_length = (sati_get_cdb_byte(cdb, 12) << 8) | 129230557Sjimharris (sati_get_cdb_byte(cdb, 13)); 130230557Sjimharris 131230557Sjimharris status = sati_move_translate_64_bit_lba(sequence, scsi_io, ata_io); 132230557Sjimharris 133230557Sjimharris if( status == SATI_FAILURE_CHECK_RESPONSE_DATA) 134230557Sjimharris { 135230557Sjimharris return status; 136230557Sjimharris } 137230557Sjimharris } 138230557Sjimharris 139230557Sjimharris 140230557Sjimharris sati_move_translate_command(sequence, scsi_io, ata_io, device_head); 141230557Sjimharris 142230557Sjimharris if( byte_transfer_length != 0 ) 143230557Sjimharris { 144230557Sjimharris sati_scsi_sense_data_construct( 145230557Sjimharris sequence, 146230557Sjimharris scsi_io, 147230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 148230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 149230557Sjimharris SCSI_ASC_INVALID_FIELD_IN_CDB, 150230557Sjimharris SCSI_ASCQ_INVALID_FIELD_IN_CDB 151230557Sjimharris ); 152230557Sjimharris return SATI_FAILURE_CHECK_RESPONSE_DATA; 153230557Sjimharris } 154230557Sjimharris 155230557Sjimharris switch(SATI_WRITE_LONG_GET_COR_WR_PB_BITS(cdb)) 156230557Sjimharris { 157230557Sjimharris case WR_UNCOR_BIT : 158230557Sjimharris 159230557Sjimharris if( (sequence->device->capabilities & 160230557Sjimharris SATI_DEVICE_CAP_MULTIPLE_SECTORS_PER_PHYSCIAL_SECTOR) != 0 ) 161230557Sjimharris { 162230557Sjimharris sati_scsi_sense_data_construct( 163230557Sjimharris sequence, 164230557Sjimharris scsi_io, 165230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 166230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 167230557Sjimharris SCSI_ASC_INVALID_FIELD_IN_CDB, 168230557Sjimharris SCSI_ASCQ_INVALID_FIELD_IN_CDB 169230557Sjimharris ); 170230557Sjimharris return SATI_FAILURE_CHECK_RESPONSE_DATA; 171230557Sjimharris } 172230557Sjimharris else 173230557Sjimharris { 174230557Sjimharris sati_ata_write_uncorrectable_construct( 175230557Sjimharris ata_io, 176230557Sjimharris sequence, 177230557Sjimharris ATA_WRITE_UNCORRECTABLE_PSUEDO 178230557Sjimharris ); 179230557Sjimharris sequence->type = SATI_SEQUENCE_WRITE_LONG; 180230557Sjimharris status = SATI_SUCCESS; 181230557Sjimharris } 182230557Sjimharris break; 183230557Sjimharris 184230557Sjimharris case WR_UNCOR_PBLOCK_BIT : 185230557Sjimharris 186230557Sjimharris sati_ata_write_uncorrectable_construct( 187230557Sjimharris ata_io, 188230557Sjimharris sequence, 189230557Sjimharris ATA_WRITE_UNCORRECTABLE_PSUEDO 190230557Sjimharris ); 191230557Sjimharris sequence->type = SATI_SEQUENCE_WRITE_LONG; 192230557Sjimharris status = SATI_SUCCESS; 193230557Sjimharris break; 194230557Sjimharris 195230557Sjimharris case COR_DIS_WR_UNCORR_BIT : 196230557Sjimharris 197230557Sjimharris sati_ata_write_uncorrectable_construct( 198230557Sjimharris ata_io, 199230557Sjimharris sequence, 200230557Sjimharris ATA_WRITE_UNCORRECTABLE_FLAGGED 201230557Sjimharris ); 202230557Sjimharris sequence->type = SATI_SEQUENCE_WRITE_LONG; 203230557Sjimharris status = SATI_SUCCESS; 204230557Sjimharris break; 205230557Sjimharris 206230557Sjimharris default : 207230557Sjimharris 208230557Sjimharris sati_scsi_sense_data_construct( 209230557Sjimharris sequence, 210230557Sjimharris scsi_io, 211230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 212230557Sjimharris SCSI_SENSE_ILLEGAL_REQUEST, 213230557Sjimharris SCSI_ASC_INVALID_FIELD_IN_CDB, 214230557Sjimharris SCSI_ASCQ_INVALID_FIELD_IN_CDB 215230557Sjimharris ); 216230557Sjimharris return SATI_FAILURE_CHECK_RESPONSE_DATA; 217230557Sjimharris break; 218230557Sjimharris } 219230557Sjimharris return status; 220230557Sjimharris} 221230557Sjimharris 222230557Sjimharris/** 223230557Sjimharris * @brief This method will translate the response to the SATI Write Long 224230557Sjimharris * translation. This response is only error checking the 225230557Sjimharris * ATA Write Uncorrectable command. 226230557Sjimharris * 227230557Sjimharris * @return SATI_STATUS Indicates if the response translation succeeded. 228230557Sjimharris * @retval SCI_COMPLETE This is returned if the command translation was 229230557Sjimharris * successful. 230230557Sjimharris * @retval SATI_FAILURE_CHECK_RESPONSE_DATA is returned if there was 231230557Sjimharris * a problem with the translation of write long. 232230557Sjimharris */ 233230557SjimharrisSATI_STATUS sati_write_long_translate_response( 234230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 235230557Sjimharris void * scsi_io, 236230557Sjimharris void * ata_io 237230557Sjimharris) 238230557Sjimharris{ 239230557Sjimharris U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io); 240230557Sjimharris 241230557Sjimharris if (sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT) 242230557Sjimharris { 243230557Sjimharris sati_scsi_sense_data_construct( 244230557Sjimharris sequence, 245230557Sjimharris scsi_io, 246230557Sjimharris SCSI_STATUS_CHECK_CONDITION, 247230557Sjimharris SCSI_SENSE_ABORTED_COMMAND, 248230557Sjimharris SCSI_ASC_COMMAND_SEQUENCE_ERROR, 249230557Sjimharris SCSI_ASCQ_NO_ADDITIONAL_SENSE 250230557Sjimharris ); 251230557Sjimharris return SATI_FAILURE_CHECK_RESPONSE_DATA; 252230557Sjimharris } 253230557Sjimharris else 254230557Sjimharris { 255230557Sjimharris return SATI_COMPLETE; 256230557Sjimharris } 257230557Sjimharris} 258230557Sjimharris 259230557Sjimharris#endif // !defined(DISABLE_SATI_WRITE_LONG) 260