xref: /freebsd/sys/dev/isci/scil/sati_test_unit_ready.c (revision 00bc86a9a653e5a731e1ac093bb56bf49745951d)
1f11c7f63SJim Harris /*-
2718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3718cf2ccSPedro F. Giffuni  *
4f11c7f63SJim Harris  * This file is provided under a dual BSD/GPLv2 license.  When using or
5f11c7f63SJim Harris  * redistributing this file, you may do so under either license.
6f11c7f63SJim Harris  *
7f11c7f63SJim Harris  * GPL LICENSE SUMMARY
8f11c7f63SJim Harris  *
9f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10f11c7f63SJim Harris  *
11f11c7f63SJim Harris  * This program is free software; you can redistribute it and/or modify
12f11c7f63SJim Harris  * it under the terms of version 2 of the GNU General Public License as
13f11c7f63SJim Harris  * published by the Free Software Foundation.
14f11c7f63SJim Harris  *
15f11c7f63SJim Harris  * This program is distributed in the hope that it will be useful, but
16f11c7f63SJim Harris  * WITHOUT ANY WARRANTY; without even the implied warranty of
17f11c7f63SJim Harris  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18f11c7f63SJim Harris  * General Public License for more details.
19f11c7f63SJim Harris  *
20f11c7f63SJim Harris  * You should have received a copy of the GNU General Public License
21f11c7f63SJim Harris  * along with this program; if not, write to the Free Software
22f11c7f63SJim Harris  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23f11c7f63SJim Harris  * The full GNU General Public License is included in this distribution
24f11c7f63SJim Harris  * in the file called LICENSE.GPL.
25f11c7f63SJim Harris  *
26f11c7f63SJim Harris  * BSD LICENSE
27f11c7f63SJim Harris  *
28f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29f11c7f63SJim Harris  * All rights reserved.
30f11c7f63SJim Harris  *
31f11c7f63SJim Harris  * Redistribution and use in source and binary forms, with or without
32f11c7f63SJim Harris  * modification, are permitted provided that the following conditions
33f11c7f63SJim Harris  * are met:
34f11c7f63SJim Harris  *
35f11c7f63SJim Harris  *   * Redistributions of source code must retain the above copyright
36f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer.
37f11c7f63SJim Harris  *   * Redistributions in binary form must reproduce the above copyright
38f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer in
39f11c7f63SJim Harris  *     the documentation and/or other materials provided with the
40f11c7f63SJim Harris  *     distribution.
41f11c7f63SJim Harris  *
42f11c7f63SJim Harris  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43f11c7f63SJim Harris  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44f11c7f63SJim Harris  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45f11c7f63SJim Harris  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46f11c7f63SJim Harris  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47f11c7f63SJim Harris  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48f11c7f63SJim Harris  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49f11c7f63SJim Harris  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50f11c7f63SJim Harris  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51f11c7f63SJim Harris  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52f11c7f63SJim Harris  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53f11c7f63SJim Harris  */
54f11c7f63SJim Harris 
55f11c7f63SJim Harris #include <sys/cdefs.h>
56f11c7f63SJim Harris /**
57f11c7f63SJim Harris  * @file
58f11c7f63SJim Harris  * @brief This file contains the method implementations required to
59f11c7f63SJim Harris  *        translate the SCSI test unit ready command.
60f11c7f63SJim Harris  */
61f11c7f63SJim Harris 
62f11c7f63SJim Harris #if !defined(DISABLE_SATI_TEST_UNIT_READY)
63f11c7f63SJim Harris 
64f11c7f63SJim Harris #include <dev/isci/scil/sati_test_unit_ready.h>
65f11c7f63SJim Harris #include <dev/isci/scil/sati_util.h>
66f11c7f63SJim Harris #include <dev/isci/scil/sati_callbacks.h>
67f11c7f63SJim Harris #include <dev/isci/scil/intel_ata.h>
68f11c7f63SJim Harris #include <dev/isci/scil/intel_scsi.h>
69f11c7f63SJim Harris 
70f11c7f63SJim Harris /**
71f11c7f63SJim Harris  * @brief This method will translate the test unit ready SCSI command into
72f11c7f63SJim Harris  *        an ATA CHECK POWER MODE command.
73f11c7f63SJim Harris  *        For more information on the parameters passed to this method,
74f11c7f63SJim Harris  *        please reference sati_translate_command().
75f11c7f63SJim Harris  *
76f11c7f63SJim Harris  * @return Indicate if the command translation succeeded.
77f11c7f63SJim Harris  * @retval SCI_SUCCESS This is returned if the command translation was
78f11c7f63SJim Harris  *         successful.
79f11c7f63SJim Harris  * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if the
80f11c7f63SJim Harris  *         LBA field is not 0, the PMI bit is not 0.
81f11c7f63SJim Harris  */
sati_test_unit_ready_translate_command(SATI_TRANSLATOR_SEQUENCE_T * sequence,void * scsi_io,void * ata_io)82f11c7f63SJim Harris SATI_STATUS sati_test_unit_ready_translate_command(
83f11c7f63SJim Harris    SATI_TRANSLATOR_SEQUENCE_T * sequence,
84f11c7f63SJim Harris    void                       * scsi_io,
85f11c7f63SJim Harris    void                       * ata_io
86f11c7f63SJim Harris )
87f11c7f63SJim Harris {
88f11c7f63SJim Harris    /**
89f11c7f63SJim Harris     * SAT dictates:
90f11c7f63SJim Harris     * - the device should be in a state to receive commands
91f11c7f63SJim Harris     * - a stopped device should cause sense data.
92*00bc86a9SJose Luis Duran     * - a format unit in progress should cause sense data.
93f11c7f63SJim Harris     * - a self-test in progress should cause sense data.
94f11c7f63SJim Harris     * - a device fault occurred on previous request should cause sense data.
95f11c7f63SJim Harris     * - handling the removable media feature set isn't supported according to
96f11c7f63SJim Harris     *   SAT specifications.
97f11c7f63SJim Harris     */
98f11c7f63SJim Harris    if (sequence->device->state == SATI_DEVICE_STATE_STOPPED)
99f11c7f63SJim Harris    {
100f11c7f63SJim Harris       sati_scsi_sense_data_construct(
101f11c7f63SJim Harris          sequence,
102f11c7f63SJim Harris          scsi_io,
103f11c7f63SJim Harris          SCSI_STATUS_CHECK_CONDITION,
104f11c7f63SJim Harris          SCSI_SENSE_NOT_READY,
105f11c7f63SJim Harris          SCSI_ASC_INITIALIZING_COMMAND_REQUIRED,
106f11c7f63SJim Harris          SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED
107f11c7f63SJim Harris       );
108f11c7f63SJim Harris       return SATI_FAILURE_CHECK_RESPONSE_DATA;
109f11c7f63SJim Harris    }
110f11c7f63SJim Harris    else if (sequence->device->state
111f11c7f63SJim Harris             == SATI_DEVICE_STATE_SELF_TEST_IN_PROGRESS)
112f11c7f63SJim Harris    {
113f11c7f63SJim Harris       sati_scsi_sense_data_construct(
114f11c7f63SJim Harris          sequence,
115f11c7f63SJim Harris          scsi_io,
116f11c7f63SJim Harris          SCSI_STATUS_CHECK_CONDITION,
117f11c7f63SJim Harris          SCSI_SENSE_NOT_READY,
118f11c7f63SJim Harris          SCSI_ASC_LUN_SELF_TEST_IN_PROGRESS,
119f11c7f63SJim Harris          SCSI_ASCQ_LUN_SELF_TEST_IN_PROGRESS
120f11c7f63SJim Harris       );
121f11c7f63SJim Harris       return SATI_FAILURE_CHECK_RESPONSE_DATA;
122f11c7f63SJim Harris    }
123f11c7f63SJim Harris    else if (sequence->device->state
124f11c7f63SJim Harris             == SATI_DEVICE_STATE_FORMAT_UNIT_IN_PROGRESS)
125f11c7f63SJim Harris    {
126f11c7f63SJim Harris       sati_scsi_sense_data_construct(
127f11c7f63SJim Harris          sequence,
128f11c7f63SJim Harris          scsi_io,
129f11c7f63SJim Harris          SCSI_STATUS_CHECK_CONDITION,
130f11c7f63SJim Harris          SCSI_SENSE_NOT_READY,
131f11c7f63SJim Harris          SCSI_ASC_LUN_FORMAT_IN_PROGRESS,
132f11c7f63SJim Harris          SCSI_ASCQ_LUN_FORMAT_IN_PROGRESS
133f11c7f63SJim Harris       );
134f11c7f63SJim Harris       return SATI_FAILURE_CHECK_RESPONSE_DATA;
135f11c7f63SJim Harris    }
136f11c7f63SJim Harris 
137f11c7f63SJim Harris    // The CDB is properly formed and the device is ready.
138f11c7f63SJim Harris    sequence->type = SATI_SEQUENCE_TEST_UNIT_READY;
139f11c7f63SJim Harris 
140f11c7f63SJim Harris    sati_ata_check_power_mode_construct(ata_io, sequence);
141f11c7f63SJim Harris    return SATI_SUCCESS;
142f11c7f63SJim Harris }
143f11c7f63SJim Harris 
144f11c7f63SJim Harris /**
145f11c7f63SJim Harris  * @brief This method will translate the ATA CHECK POWER MODE register FIS
146f11c7f63SJim Harris  *        response into an appropriate SCSI response.
147f11c7f63SJim Harris  *        For more information on the parameters passed to this method,
148f11c7f63SJim Harris  *        please reference sati_translate_response().
149f11c7f63SJim Harris  *
150f11c7f63SJim Harris  * @return Indicate if the response translation succeeded.
151f11c7f63SJim Harris  * @retval SCI_SUCCESS This is returned if the data translation was
152f11c7f63SJim Harris  *         successful.
153f11c7f63SJim Harris  */
sati_test_unit_ready_translate_response(SATI_TRANSLATOR_SEQUENCE_T * sequence,void * scsi_io,void * ata_io)154f11c7f63SJim Harris SATI_STATUS sati_test_unit_ready_translate_response(
155f11c7f63SJim Harris    SATI_TRANSLATOR_SEQUENCE_T * sequence,
156f11c7f63SJim Harris    void                       * scsi_io,
157f11c7f63SJim Harris    void                       * ata_io
158f11c7f63SJim Harris )
159f11c7f63SJim Harris {
160f11c7f63SJim Harris    U8 * register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
161f11c7f63SJim Harris 
162f11c7f63SJim Harris    /**
163f11c7f63SJim Harris     * SAT dictates:
164f11c7f63SJim Harris     * - If the ATA CHECK POWER MODE command returns an error, then
165f11c7f63SJim Harris     *   return sense data indicating the LOGICAL UNIT DOES NOT RESPONSE
166f11c7f63SJim Harris     *   TO SELECTION.
167f11c7f63SJim Harris     * - All other cases are considered successful.
168f11c7f63SJim Harris     */
169f11c7f63SJim Harris    if (sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT)
170f11c7f63SJim Harris    {
171f11c7f63SJim Harris       sati_scsi_sense_data_construct(
172f11c7f63SJim Harris          sequence,
173f11c7f63SJim Harris          scsi_io,
174f11c7f63SJim Harris          SCSI_STATUS_CHECK_CONDITION,
175f11c7f63SJim Harris          SCSI_SENSE_NOT_READY,
176f11c7f63SJim Harris          SCSI_ASC_LUN_NOT_RESPOND_TO_SELECTION,
177f11c7f63SJim Harris          SCSI_ASCQ_LUN_NOT_RESPOND_TO_SELECTION
178f11c7f63SJim Harris       );
179f11c7f63SJim Harris       return SATI_FAILURE_CHECK_RESPONSE_DATA;
180f11c7f63SJim Harris    }
181f11c7f63SJim Harris 
182f11c7f63SJim Harris    return SATI_COMPLETE;
183f11c7f63SJim Harris }
184f11c7f63SJim Harris 
185f11c7f63SJim Harris #endif // !defined(DISABLE_SATI_TEST_UNIT_READY)
186f11c7f63SJim Harris 
187