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 method implementations to translate 59230557Sjimharris* SCSI Write and Verify command based of the SAT spec. 60230557Sjimharris*/ 61230557Sjimharris 62230557Sjimharris#if !defined(DISABLE_SATI_WRITE_AND_VERIFY) 63230557Sjimharris 64230557Sjimharris#include <dev/isci/scil/sati_write_and_verify.h> 65230557Sjimharris#include <dev/isci/scil/sati_write.h> 66230557Sjimharris#include <dev/isci/scil/sati_verify.h> 67230557Sjimharris#include <dev/isci/scil/sati_callbacks.h> 68230557Sjimharris#include <dev/isci/scil/sati_util.h> 69230557Sjimharris 70230557Sjimharris#include <dev/isci/scil/intel_ata.h> 71230557Sjimharris#include <dev/isci/scil/intel_scsi.h> 72230557Sjimharris 73230557Sjimharris/** 74230557Sjimharris* @brief This function translates a SCSI Write and Verify 10 command 75230557Sjimharris* into both ATA write and ATA read verify commands. This 76230557Sjimharris* happens by passing the SCSI IO, ATA IO, and Sequence pointers 77230557Sjimharris* to both the sati_write_10_translate_command and the 78230557Sjimharris* sati_verify_10_translate_command. 79230557Sjimharris* 80230557Sjimharris* @return Indicate if the command translation succeeded. 81230557Sjimharris* @retval SCI_SUCCESS This is returned if the command translation was 82230557Sjimharris* successful. 83230557Sjimharris* @retval SATI_FAILURE_CHECK_RESPONSE_DATA is returned if there was 84230557Sjimharris* a problem with the translation of write long. 85230557Sjimharris* @retval SATI_FAILURE is returned if there the sequence is out of 86230557Sjimharris* state for a sati_write_and_verify_10 translation. 87230557Sjimharris* 88230557Sjimharris*/ 89230557SjimharrisSATI_STATUS sati_write_and_verify_10_translate_command( 90230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 91230557Sjimharris void * scsi_io, 92230557Sjimharris void * ata_io 93230557Sjimharris) 94230557Sjimharris{ 95230557Sjimharris SATI_STATUS status; 96230557Sjimharris 97230557Sjimharris if(sequence->state == SATI_SEQUENCE_STATE_INITIAL) 98230557Sjimharris { 99230557Sjimharris status = sati_write_10_translate_command(sequence, scsi_io, ata_io); 100230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE; 101230557Sjimharris sequence->is_translate_response_required = TRUE; 102230557Sjimharris } 103230557Sjimharris else if(sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE) 104230557Sjimharris { 105230557Sjimharris status = sati_verify_10_translate_command(sequence, scsi_io, ata_io); 106230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_AWAIT_RESPONSE; 107230557Sjimharris } 108230557Sjimharris else 109230557Sjimharris { 110230557Sjimharris //SATI sequence is in the wrong state 111230557Sjimharris return SATI_FAILURE; 112230557Sjimharris } 113230557Sjimharris 114230557Sjimharris sequence->type = SATI_SEQUENCE_WRITE_AND_VERIFY; 115230557Sjimharris return status; 116230557Sjimharris} 117230557Sjimharris 118230557Sjimharris/** 119230557Sjimharris* @brief This function translates a SCSI Write and Verify 12 command 120230557Sjimharris* into both ATA write and ATA read verify commands. This 121230557Sjimharris* happens by passing the SCSI IO, ATA IO, and Sequence pointers 122230557Sjimharris* to both the sati_write_12_translate_command and the 123230557Sjimharris* sati_verify_12_translate_command. 124230557Sjimharris* 125230557Sjimharris* @return Indicate if the command translation succeeded. 126230557Sjimharris* @retval SCI_SUCCESS This is returned if the command translation was 127230557Sjimharris* successful. 128230557Sjimharris* @retval SATI_FAILURE_CHECK_RESPONSE_DATA is returned if there was 129230557Sjimharris* a problem with the translation of write long. 130230557Sjimharris* @retval SATI_FAILURE is returned if there the sequence is out of 131230557Sjimharris* state for a sati_write_and_verify_12 translation. 132230557Sjimharris* 133230557Sjimharris*/ 134230557SjimharrisSATI_STATUS sati_write_and_verify_12_translate_command( 135230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 136230557Sjimharris void * scsi_io, 137230557Sjimharris void * ata_io 138230557Sjimharris) 139230557Sjimharris{ 140230557Sjimharris SATI_STATUS status; 141230557Sjimharris 142230557Sjimharris if(sequence->state == SATI_SEQUENCE_STATE_INITIAL) 143230557Sjimharris { 144230557Sjimharris status = sati_write_12_translate_command(sequence, scsi_io, ata_io); 145230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE; 146230557Sjimharris sequence->is_translate_response_required = TRUE; 147230557Sjimharris } 148230557Sjimharris else if(sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE) 149230557Sjimharris { 150230557Sjimharris status = sati_verify_12_translate_command(sequence, scsi_io, ata_io); 151230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_AWAIT_RESPONSE; 152230557Sjimharris } 153230557Sjimharris else 154230557Sjimharris { 155230557Sjimharris //SATI sequence is in the wrong state 156230557Sjimharris return SATI_FAILURE; 157230557Sjimharris } 158230557Sjimharris 159230557Sjimharris sequence->type = SATI_SEQUENCE_WRITE_AND_VERIFY; 160230557Sjimharris return status; 161230557Sjimharris} 162230557Sjimharris 163230557Sjimharris/** 164230557Sjimharris* @brief This function translates a SCSI Write and Verify 16 command 165230557Sjimharris* into both ATA write and ATA read verify commands. This 166230557Sjimharris* happens by passing the SCSI IO, ATA IO, and Sequence pointers 167230557Sjimharris* to both the sati_write_16_translate_command and the 168230557Sjimharris* sati_verify_16_translate_command. 169230557Sjimharris* 170230557Sjimharris* @return Indicate if the command translation succeeded. 171230557Sjimharris* @retval SCI_SUCCESS This is returned if the command translation was 172230557Sjimharris* successful. 173230557Sjimharris* @retval SATI_FAILURE_CHECK_RESPONSE_DATA is returned if there was 174230557Sjimharris* a problem with the translation of write long. 175230557Sjimharris* @retval SATI_FAILURE is returned if there the sequence is out of 176230557Sjimharris* state for a sati_write_and_verify_16 translation. 177230557Sjimharris* 178230557Sjimharris*/ 179230557SjimharrisSATI_STATUS sati_write_and_verify_16_translate_command( 180230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 181230557Sjimharris void * scsi_io, 182230557Sjimharris void * ata_io 183230557Sjimharris) 184230557Sjimharris{ 185230557Sjimharris SATI_STATUS status; 186230557Sjimharris 187230557Sjimharris if(sequence->state == SATI_SEQUENCE_STATE_INITIAL) 188230557Sjimharris { 189230557Sjimharris status = sati_write_16_translate_command(sequence, scsi_io, ata_io); 190230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_INCOMPLETE; 191230557Sjimharris sequence->is_translate_response_required = TRUE; 192230557Sjimharris } 193230557Sjimharris else if(sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE) 194230557Sjimharris { 195230557Sjimharris status = sati_verify_16_translate_command(sequence, scsi_io, ata_io); 196230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_AWAIT_RESPONSE; 197230557Sjimharris } 198230557Sjimharris else 199230557Sjimharris { 200230557Sjimharris //SATI sequence is in the wrong state 201230557Sjimharris return SATI_FAILURE; 202230557Sjimharris } 203230557Sjimharris 204230557Sjimharris sequence->type = SATI_SEQUENCE_WRITE_AND_VERIFY; 205230557Sjimharris return status; 206230557Sjimharris} 207230557Sjimharris 208230557Sjimharris/** 209230557Sjimharris* @brief This function is the response to a sati_write_and_verify 210230557Sjimharris translation. Since no response translation is required 211230557Sjimharris this function will only check the sequence state and return 212230557Sjimharris status. 213230557Sjimharris* 214230557Sjimharris* @return Indicate if the command response translation succeeded. 215230557Sjimharris* @retval SCI_COMPLETE This is returned if the command translation 216230557Sjimharris is successful and requires no more work. 217230557Sjimharris* @retval SATI_SEQUENCE_INCOMPLETE This is returned if the command 218230557Sjimharris translation has finished sending the ATA Write command but 219230557Sjimharris still needs to complete the Verify portion. 220230557Sjimharris* @retval SATI_FAILURE is returned if there the sequence is out of 221230557Sjimharris* state for a sati_write_and_verify translation. 222230557Sjimharris* 223230557Sjimharris*/ 224230557SjimharrisSATI_STATUS sati_write_and_verify_translate_response( 225230557Sjimharris SATI_TRANSLATOR_SEQUENCE_T * sequence, 226230557Sjimharris void * scsi_io, 227230557Sjimharris void * ata_io 228230557Sjimharris) 229230557Sjimharris{ 230230557Sjimharris if(sequence->state == SATI_SEQUENCE_STATE_INCOMPLETE) 231230557Sjimharris { 232230557Sjimharris return SATI_SEQUENCE_INCOMPLETE; 233230557Sjimharris } 234230557Sjimharris else if(sequence->state == SATI_SEQUENCE_STATE_AWAIT_RESPONSE) 235230557Sjimharris { 236230557Sjimharris sequence->state = SATI_SEQUENCE_STATE_FINAL; 237230557Sjimharris return SATI_COMPLETE; 238230557Sjimharris } 239230557Sjimharris 240230557Sjimharris return SATI_FAILURE; 241230557Sjimharris} 242230557Sjimharris 243230557Sjimharris#endif //!defined(DISABLE_SATI_WRITE_AND_VERIFY) 244