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 required to
59230557Sjimharris *        translate the SCSI test unit ready command.
60230557Sjimharris */
61230557Sjimharris
62230557Sjimharris#if !defined(DISABLE_SATI_TEST_UNIT_READY)
63230557Sjimharris
64230557Sjimharris#include <dev/isci/scil/sati_test_unit_ready.h>
65230557Sjimharris#include <dev/isci/scil/sati_util.h>
66230557Sjimharris#include <dev/isci/scil/sati_callbacks.h>
67230557Sjimharris#include <dev/isci/scil/intel_ata.h>
68230557Sjimharris#include <dev/isci/scil/intel_scsi.h>
69230557Sjimharris
70230557Sjimharris/**
71230557Sjimharris * @brief This method will translate the test unit ready SCSI command into
72230557Sjimharris *        an ATA CHECK POWER MODE command.
73230557Sjimharris *        For more information on the parameters passed to this method,
74230557Sjimharris *        please reference sati_translate_command().
75230557Sjimharris *
76230557Sjimharris * @return Indicate if the command translation succeeded.
77230557Sjimharris * @retval SCI_SUCCESS This is returned if the command translation was
78230557Sjimharris *         successful.
79230557Sjimharris * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if the
80230557Sjimharris *         LBA field is not 0, the PMI bit is not 0.
81230557Sjimharris */
82230557SjimharrisSATI_STATUS sati_test_unit_ready_translate_command(
83230557Sjimharris   SATI_TRANSLATOR_SEQUENCE_T * sequence,
84230557Sjimharris   void                       * scsi_io,
85230557Sjimharris   void                       * ata_io
86230557Sjimharris)
87230557Sjimharris{
88230557Sjimharris   /**
89230557Sjimharris    * SAT dictates:
90230557Sjimharris    * - the device should be in a state to receive commands
91230557Sjimharris    * - a stopped device should cause sense data.
92230557Sjimharris    * - a format unit in progresss should cause sense data.
93230557Sjimharris    * - a self-test in progress should cause sense data.
94230557Sjimharris    * - a device fault occurred on previous request should cause sense data.
95230557Sjimharris    * - handling the removable media feature set isn't supported according to
96230557Sjimharris    *   SAT specifications.
97230557Sjimharris    */
98230557Sjimharris   if (sequence->device->state == SATI_DEVICE_STATE_STOPPED)
99230557Sjimharris   {
100230557Sjimharris      sati_scsi_sense_data_construct(
101230557Sjimharris         sequence,
102230557Sjimharris         scsi_io,
103230557Sjimharris         SCSI_STATUS_CHECK_CONDITION,
104230557Sjimharris         SCSI_SENSE_NOT_READY,
105230557Sjimharris         SCSI_ASC_INITIALIZING_COMMAND_REQUIRED,
106230557Sjimharris         SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED
107230557Sjimharris      );
108230557Sjimharris      return SATI_FAILURE_CHECK_RESPONSE_DATA;
109230557Sjimharris   }
110230557Sjimharris   else if (sequence->device->state
111230557Sjimharris            == SATI_DEVICE_STATE_SELF_TEST_IN_PROGRESS)
112230557Sjimharris   {
113230557Sjimharris      sati_scsi_sense_data_construct(
114230557Sjimharris         sequence,
115230557Sjimharris         scsi_io,
116230557Sjimharris         SCSI_STATUS_CHECK_CONDITION,
117230557Sjimharris         SCSI_SENSE_NOT_READY,
118230557Sjimharris         SCSI_ASC_LUN_SELF_TEST_IN_PROGRESS,
119230557Sjimharris         SCSI_ASCQ_LUN_SELF_TEST_IN_PROGRESS
120230557Sjimharris      );
121230557Sjimharris      return SATI_FAILURE_CHECK_RESPONSE_DATA;
122230557Sjimharris   }
123230557Sjimharris   else if (sequence->device->state
124230557Sjimharris            == SATI_DEVICE_STATE_FORMAT_UNIT_IN_PROGRESS)
125230557Sjimharris   {
126230557Sjimharris      sati_scsi_sense_data_construct(
127230557Sjimharris         sequence,
128230557Sjimharris         scsi_io,
129230557Sjimharris         SCSI_STATUS_CHECK_CONDITION,
130230557Sjimharris         SCSI_SENSE_NOT_READY,
131230557Sjimharris         SCSI_ASC_LUN_FORMAT_IN_PROGRESS,
132230557Sjimharris         SCSI_ASCQ_LUN_FORMAT_IN_PROGRESS
133230557Sjimharris      );
134230557Sjimharris      return SATI_FAILURE_CHECK_RESPONSE_DATA;
135230557Sjimharris   }
136230557Sjimharris
137230557Sjimharris   // The CDB is properly formed and the device is ready.
138230557Sjimharris   sequence->type = SATI_SEQUENCE_TEST_UNIT_READY;
139230557Sjimharris
140230557Sjimharris   sati_ata_check_power_mode_construct(ata_io, sequence);
141230557Sjimharris   return SATI_SUCCESS;
142230557Sjimharris}
143230557Sjimharris
144230557Sjimharris/**
145230557Sjimharris * @brief This method will translate the ATA CHECK POWER MODE register FIS
146230557Sjimharris *        response into an appropriate SCSI response.
147230557Sjimharris *        For more information on the parameters passed to this method,
148230557Sjimharris *        please reference sati_translate_response().
149230557Sjimharris *
150230557Sjimharris * @return Indicate if the response translation succeeded.
151230557Sjimharris * @retval SCI_SUCCESS This is returned if the data translation was
152230557Sjimharris *         successful.
153230557Sjimharris */
154230557SjimharrisSATI_STATUS sati_test_unit_ready_translate_response(
155230557Sjimharris   SATI_TRANSLATOR_SEQUENCE_T * sequence,
156230557Sjimharris   void                       * scsi_io,
157230557Sjimharris   void                       * ata_io
158230557Sjimharris)
159230557Sjimharris{
160230557Sjimharris   U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
161230557Sjimharris
162230557Sjimharris   /**
163230557Sjimharris    * SAT dictates:
164230557Sjimharris    * - If the ATA CHECK POWER MODE command returns an error, then
165230557Sjimharris    *   return sense data indicating the LOGICAL UNIT DOES NOT RESPONSE
166230557Sjimharris    *   TO SELECTION.
167230557Sjimharris    * - All other cases are considered successful.
168230557Sjimharris    */
169230557Sjimharris   if (sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT)
170230557Sjimharris   {
171230557Sjimharris      sati_scsi_sense_data_construct(
172230557Sjimharris         sequence,
173230557Sjimharris         scsi_io,
174230557Sjimharris         SCSI_STATUS_CHECK_CONDITION,
175230557Sjimharris         SCSI_SENSE_NOT_READY,
176230557Sjimharris         SCSI_ASC_LUN_NOT_RESPOND_TO_SELECTION,
177230557Sjimharris         SCSI_ASCQ_LUN_NOT_RESPOND_TO_SELECTION
178230557Sjimharris      );
179230557Sjimharris      return SATI_FAILURE_CHECK_RESPONSE_DATA;
180230557Sjimharris   }
181230557Sjimharris
182230557Sjimharris   return SATI_COMPLETE;
183230557Sjimharris}
184230557Sjimharris
185230557Sjimharris#endif // !defined(DISABLE_SATI_TEST_UNIT_READY)
186230557Sjimharris
187