1f11c7f63SJim Harris /*-
2*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3*718cf2ccSPedro 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 passthru command.
60f11c7f63SJim Harris */
61f11c7f63SJim Harris
62f11c7f63SJim Harris #if !defined(DISABLE_SATI_PASSTHROUGH)
63f11c7f63SJim Harris
64f11c7f63SJim Harris #include <dev/isci/scil/sati.h>
65f11c7f63SJim Harris #include <dev/isci/scil/sati_passthrough.h>
66f11c7f63SJim Harris #include <dev/isci/scil/sati_util.h>
67f11c7f63SJim Harris #include <dev/isci/scil/sati_callbacks.h>
68f11c7f63SJim Harris #include <dev/isci/scil/intel_ata.h>
69f11c7f63SJim Harris
70f11c7f63SJim Harris #define PASSTHROUGH_CDB_PROTOCOL_MASK 0x1E
71f11c7f63SJim Harris #define PASSTHROUGH_CDB_EXTEND_MASK 0x1
72f11c7f63SJim Harris #define PASSTHROUGH_CDB_CK_COND_MASK 0x20
73f11c7f63SJim Harris #define PASSTHROUGH_CDB_T_DIR_MASK 0x8
74f11c7f63SJim Harris
75f11c7f63SJim Harris #define PASSTHROUGH_ISOLATE_BITS(cdb, index, mask, shift) (((sati_get_cdb_byte(cdb, index) & mask) >> shift))
76f11c7f63SJim Harris
77f11c7f63SJim Harris #define PASSTHROUGH_CDB_PROTOCOL(cdb) PASSTHROUGH_ISOLATE_BITS(cdb, 1, PASSTHROUGH_CDB_PROTOCOL_MASK, 1)
78f11c7f63SJim Harris #define PASSTHROUGH_CDB_EXTEND(cdb) PASSTHROUGH_ISOLATE_BITS(cdb, 1, PASSTHROUGH_CDB_EXTEND_MASK, 0)
79f11c7f63SJim Harris #define PASSTHROUGH_CDB_CK_COND(cdb) PASSTHROUGH_ISOLATE_BITS(cdb, 2, PASSTHROUGH_CDB_CK_COND_MASK, 5)
80f11c7f63SJim Harris #define PASSTHROUGH_CDB_T_DIR(cdb) PASSTHROUGH_ISOLATE_BITS(cdb, 2, PASSTHROUGH_CDB_T_DIR_MASK, 3)
81f11c7f63SJim Harris
82f11c7f63SJim Harris #define PASSTHROUGH_CDB_MULTIPLE_COUNT(cdb) (sati_get_cdb_byte(cdb, 1) >> 5)
83f11c7f63SJim Harris #define PASSTHROUGH_CDB_COMMAND(cdb, index) sati_get_cdb_byte(cdb, index)
84f11c7f63SJim Harris
85f11c7f63SJim Harris // Protocols
86f11c7f63SJim Harris #define PASSTHROUGH_PIO_DATA_IN 0x4
87f11c7f63SJim Harris #define PASSTHROUGH_PIO_DATA_OUT 0x5
88666b0fabSJim Harris #define PASSTHROUGH_DMA 0x6
89f11c7f63SJim Harris #define PASSTHROUGH_UDMA_DATA_IN 0xA
90f11c7f63SJim Harris #define PASSTHROUGH_UDMA_DATA_OUT 0xB
91f11c7f63SJim Harris #define PASSTHROUGH_RETURN_RESPONSE 0xF
92f11c7f63SJim Harris
93f11c7f63SJim Harris /**
94f11c7f63SJim Harris * @brief This function will check the multiple_count field in the SCSI CDB
95f11c7f63SJim Harris * and if multiple_count is nonzero the function will check the
96f11c7f63SJim Harris * ATA command code. Only Read and Write Multiple commands are allowed
97f11c7f63SJim Harris * when multiple_count is a nonzero value.
98f11c7f63SJim Harris *
99f11c7f63SJim Harris * @param[in] cdb The SCSI cdb for the ATA pass-through command
100f11c7f63SJim Harris *
101f11c7f63SJim Harris * @return BOOL
102f11c7f63SJim Harris @retval TRUE - multiple_count is nonzero with a unsupported command
103f11c7f63SJim Harris @retval FALSE - multiple_count is zero or the command supports a nonzero value
104f11c7f63SJim Harris */
105f11c7f63SJim Harris static
sati_passthrough_multiple_count_error(U8 * cdb)106f11c7f63SJim Harris BOOL sati_passthrough_multiple_count_error(
107f11c7f63SJim Harris U8 * cdb
108f11c7f63SJim Harris )
109f11c7f63SJim Harris {
110f11c7f63SJim Harris U8 ata_command_code;
111f11c7f63SJim Harris
112f11c7f63SJim Harris if(PASSTHROUGH_CDB_MULTIPLE_COUNT(cdb) > 0)
113f11c7f63SJim Harris {
114f11c7f63SJim Harris if(sati_get_cdb_byte(cdb, 0 ) == SCSI_ATA_PASSTHRU_12)
115f11c7f63SJim Harris {
116f11c7f63SJim Harris ata_command_code = PASSTHROUGH_CDB_COMMAND(cdb, 9);
117f11c7f63SJim Harris }
118f11c7f63SJim Harris else
119f11c7f63SJim Harris {
120f11c7f63SJim Harris ata_command_code = PASSTHROUGH_CDB_COMMAND(cdb, 14);
121f11c7f63SJim Harris }
122f11c7f63SJim Harris
123f11c7f63SJim Harris switch(ata_command_code)
124f11c7f63SJim Harris { //MULTICOUNT bit is supported
125f11c7f63SJim Harris case ATA_READ_MULTIPLE:
126f11c7f63SJim Harris case ATA_READ_MULTIPLE_EXT:
127f11c7f63SJim Harris case ATA_WRITE_MULTIPLE:
128f11c7f63SJim Harris case ATA_WRITE_MULTIPLE_EXT:
129f11c7f63SJim Harris case ATA_WRITE_MULTIPLE_FUA_EXT:
130f11c7f63SJim Harris return FALSE;
131f11c7f63SJim Harris break;
132f11c7f63SJim Harris
133f11c7f63SJim Harris default:
134f11c7f63SJim Harris return TRUE;
135f11c7f63SJim Harris }
136f11c7f63SJim Harris }
137f11c7f63SJim Harris //MULTICOUNT bit is not set
138f11c7f63SJim Harris return FALSE;
139f11c7f63SJim Harris }
140f11c7f63SJim Harris
141f11c7f63SJim Harris /**
142f11c7f63SJim Harris * @brief This method will construct the sense data buffer in the user's
143f11c7f63SJim Harris * sense data buffer location. Additionally, it will set the user's
144f11c7f63SJim Harris * SCSI status.
145f11c7f63SJim Harris *
146f11c7f63SJim Harris * @param[in] sequence This parameter specifies the translation sequence
147f11c7f63SJim Harris * for which to construct the sense data.
148f11c7f63SJim Harris * @param[in] register_fis This parameter specifies the fis from which
149f11c7f63SJim Harris * to get the data.
150f11c7f63SJim Harris * @param[in,out] scsi_io This parameter specifies the user's IO request
151f11c7f63SJim Harris * for which to construct the sense data.
152f11c7f63SJim Harris * @param[in] scsi_status This parameter specifies the SCSI status
153f11c7f63SJim Harris * value for the user's IO request.
154f11c7f63SJim Harris * @param[in] sense_key This parameter specifies the sense key to
155f11c7f63SJim Harris * be set for the user's IO request.
156f11c7f63SJim Harris * @param[in] additional_sense_code This parameter specifies the
157f11c7f63SJim Harris * additional sense code (ASC) key to be set for the user's
158f11c7f63SJim Harris * IO request.
159f11c7f63SJim Harris * @param[in] additional_sense_code_qualifier This parameter specifies
160f11c7f63SJim Harris * the additional sense code qualifier (ASCQ) key to be set
161f11c7f63SJim Harris * for the user's IO request.
162f11c7f63SJim Harris *
163f11c7f63SJim Harris * @return none
164f11c7f63SJim Harris */
165f11c7f63SJim Harris static
sati_passthrough_construct_sense(SATI_TRANSLATOR_SEQUENCE_T * sequence,U8 * register_fis,void * scsi_io,U8 scsi_status,U8 sense_key,U8 additional_sense_code,U8 additional_sense_code_qualifier)166f11c7f63SJim Harris void sati_passthrough_construct_sense(
167f11c7f63SJim Harris SATI_TRANSLATOR_SEQUENCE_T * sequence,
168f11c7f63SJim Harris U8 * register_fis,
169f11c7f63SJim Harris void * scsi_io,
170f11c7f63SJim Harris U8 scsi_status,
171f11c7f63SJim Harris U8 sense_key,
172f11c7f63SJim Harris U8 additional_sense_code,
173f11c7f63SJim Harris U8 additional_sense_code_qualifier
174f11c7f63SJim Harris )
175f11c7f63SJim Harris {
176f11c7f63SJim Harris U8 * sense_data;
177f11c7f63SJim Harris U32 sense_len;
178f11c7f63SJim Harris U8 * cdb;
179f11c7f63SJim Harris unsigned char sector_count_upper;
180f11c7f63SJim Harris unsigned char lba_upper;
181f11c7f63SJim Harris
182f11c7f63SJim Harris #ifdef SATI_TRANSPORT_SUPPORTS_SAS
183f11c7f63SJim Harris SCI_SSP_RESPONSE_IU_T * rsp_iu = (SCI_SSP_RESPONSE_IU_T*)
184f11c7f63SJim Harris sati_cb_get_response_iu_address(scsi_io);
185f11c7f63SJim Harris
186f11c7f63SJim Harris sati_scsi_common_response_iu_construct(
187f11c7f63SJim Harris rsp_iu,
188f11c7f63SJim Harris scsi_status,
189f11c7f63SJim Harris SCSI_FIXED_SENSE_DATA_BASE_LENGTH,
190f11c7f63SJim Harris SCSI_RESPONSE_DATA_PRES_SENSE_DATA
191f11c7f63SJim Harris );
192f11c7f63SJim Harris
193f11c7f63SJim Harris sense_data = (U8*) rsp_iu->data;
194f11c7f63SJim Harris sense_len = SSP_RESPONSE_IU_MAX_DATA * 4; // dwords to bytes
195f11c7f63SJim Harris #else
196f11c7f63SJim Harris sense_data = sati_cb_get_sense_data_address(scsi_io);
197f11c7f63SJim Harris sense_len = sati_cb_get_sense_data_length(scsi_io);
198f11c7f63SJim Harris #endif // SATI_TRANSPORT_SUPPORTS_SAS
199f11c7f63SJim Harris
200f11c7f63SJim Harris sati_scsi_sense_data_construct(
201f11c7f63SJim Harris sequence,
202f11c7f63SJim Harris scsi_io,
203f11c7f63SJim Harris scsi_status,
204f11c7f63SJim Harris sense_key,
205f11c7f63SJim Harris additional_sense_code,
206f11c7f63SJim Harris additional_sense_code_qualifier
207f11c7f63SJim Harris );
208f11c7f63SJim Harris
209f11c7f63SJim Harris cdb = sati_cb_get_cdb_address(scsi_io);
210f11c7f63SJim Harris
211f11c7f63SJim Harris if (sati_get_ata_sector_count_ext(register_fis) != 0) {
212f11c7f63SJim Harris sector_count_upper = 1;
213f11c7f63SJim Harris } else {
214f11c7f63SJim Harris sector_count_upper = 0;
215f11c7f63SJim Harris }
216f11c7f63SJim Harris
217f11c7f63SJim Harris if (sati_get_ata_lba_high_ext(register_fis) != 0 ||
218f11c7f63SJim Harris sati_get_ata_lba_mid_ext(register_fis) != 0 ||
219f11c7f63SJim Harris sati_get_ata_lba_low_ext(register_fis) != 0) {
220f11c7f63SJim Harris lba_upper = 1;
221f11c7f63SJim Harris } else {
222f11c7f63SJim Harris lba_upper = 0;
223f11c7f63SJim Harris }
224f11c7f63SJim Harris
225f11c7f63SJim Harris // Information section
226f11c7f63SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 3, (U8)sati_get_ata_error(register_fis));
227f11c7f63SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 4, (U8)sati_get_ata_status(register_fis));
228f11c7f63SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 5, sati_get_ata_device(register_fis));
229f11c7f63SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 6, sati_get_ata_sector_count(register_fis));
230f11c7f63SJim Harris
231f11c7f63SJim Harris // Command specific section
232f11c7f63SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 8, (PASSTHROUGH_CDB_EXTEND(cdb) << 7) | (sector_count_upper << 6) | (lba_upper << 5));
2338a0ddeb8SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 9, sati_get_ata_lba_low(register_fis));
234f11c7f63SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 10, sati_get_ata_lba_mid(register_fis));
2358a0ddeb8SJim Harris sati_set_sense_data_byte(sense_data, sense_len, 11, sati_get_ata_lba_high(register_fis));
236f11c7f63SJim Harris
237f11c7f63SJim Harris sequence->is_sense_response_set = TRUE;
238f11c7f63SJim Harris }
239f11c7f63SJim Harris
240f11c7f63SJim Harris /**
241f11c7f63SJim Harris * @brief This method will verify that the T_DIR bit matches the protocol bit.
242f11c7f63SJim Harris * It will additionally set the direction on the sequence.
243f11c7f63SJim Harris *
244f11c7f63SJim Harris * @param[in,out] sequence This parameter specifies the translation sequence
245f11c7f63SJim Harris * for which to construct the sense data.
246f11c7f63SJim Harris * @param[in] cdb The CDB containing the passthrough command
247f11c7f63SJim Harris *
248f11c7f63SJim Harris * @return none
249f11c7f63SJim Harris */
250f11c7f63SJim Harris static
sati_passthrough_check_direction(SATI_TRANSLATOR_SEQUENCE_T * sequence,U8 * cdb)251f11c7f63SJim Harris SATI_STATUS sati_passthrough_check_direction(
252f11c7f63SJim Harris SATI_TRANSLATOR_SEQUENCE_T * sequence,
253f11c7f63SJim Harris U8 * cdb
254f11c7f63SJim Harris )
255f11c7f63SJim Harris {
256666b0fabSJim Harris if ((sequence->protocol == PASSTHROUGH_PIO_DATA_IN) ||
257666b0fabSJim Harris (sequence->protocol == PASSTHROUGH_UDMA_DATA_IN))
258f11c7f63SJim Harris {
259f11c7f63SJim Harris if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x0)
260f11c7f63SJim Harris {
261f11c7f63SJim Harris return SATI_FAILURE;
262f11c7f63SJim Harris }
263f11c7f63SJim Harris else
264f11c7f63SJim Harris {
265f11c7f63SJim Harris sequence->data_direction = SATI_DATA_DIRECTION_IN;
266f11c7f63SJim Harris }
267f11c7f63SJim Harris }
268666b0fabSJim Harris else if ((sequence->protocol == PASSTHROUGH_PIO_DATA_OUT) ||
269666b0fabSJim Harris (sequence->protocol == PASSTHROUGH_UDMA_DATA_OUT))
270f11c7f63SJim Harris {
271f11c7f63SJim Harris if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x1)
272f11c7f63SJim Harris {
273f11c7f63SJim Harris return SATI_FAILURE;
274f11c7f63SJim Harris }
275f11c7f63SJim Harris else
276f11c7f63SJim Harris {
277f11c7f63SJim Harris sequence->data_direction = SATI_DATA_DIRECTION_OUT;
278f11c7f63SJim Harris }
279f11c7f63SJim Harris }
280f11c7f63SJim Harris else
281f11c7f63SJim Harris {
282f11c7f63SJim Harris sequence->data_direction = SATI_DATA_DIRECTION_NONE;
283f11c7f63SJim Harris }
284f11c7f63SJim Harris
285f11c7f63SJim Harris return SATI_COMPLETE;
286f11c7f63SJim Harris }
287f11c7f63SJim Harris
288f11c7f63SJim Harris //******************************************************************************
289f11c7f63SJim Harris //* P U B L I C M E T H O D S
290f11c7f63SJim Harris //******************************************************************************
291f11c7f63SJim Harris
292f11c7f63SJim Harris /**
293f11c7f63SJim Harris * @brief This method will translate the SCSI Passthrough command
294f11c7f63SJim Harris * into the corresponding ATA command.
295f11c7f63SJim Harris *
296f11c7f63SJim Harris * @return Indicate if the command translation succeeded.
297f11c7f63SJim Harris * @retval SATI_SUCCESS This is returned if the command translation was
298f11c7f63SJim Harris * successful.
299f11c7f63SJim Harris * @retval SATI_FAILURE This is returned if the command translation was
300f11c7f63SJim Harris * unsuccessful
301f11c7f63SJim Harris */
302f11c7f63SJim Harris
sati_passthrough_12_translate_command(SATI_TRANSLATOR_SEQUENCE_T * sequence,void * scsi_io,void * ata_io)303f11c7f63SJim Harris SATI_STATUS sati_passthrough_12_translate_command(
304f11c7f63SJim Harris SATI_TRANSLATOR_SEQUENCE_T * sequence,
305f11c7f63SJim Harris void * scsi_io,
306f11c7f63SJim Harris void * ata_io
307f11c7f63SJim Harris )
308f11c7f63SJim Harris {
309f11c7f63SJim Harris SATI_STATUS status;
310f11c7f63SJim Harris U8 * cdb;
311f11c7f63SJim Harris U8 * register_fis;
312f11c7f63SJim Harris
313f11c7f63SJim Harris status = SATI_FAILURE;
314f11c7f63SJim Harris
315f11c7f63SJim Harris sequence->type = SATI_SEQUENCE_ATA_PASSTHROUGH_12;
316f11c7f63SJim Harris sequence->state = SATI_SEQUENCE_STATE_TRANSLATE_DATA;
317f11c7f63SJim Harris
318f11c7f63SJim Harris cdb = sati_cb_get_cdb_address(scsi_io);
319f11c7f63SJim Harris sequence->protocol = PASSTHROUGH_CDB_PROTOCOL (cdb);
320f11c7f63SJim Harris register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
321f11c7f63SJim Harris
322666b0fabSJim Harris /*
323666b0fabSJim Harris * CAM will send passthrough commands with protocol set to multiword
324666b0fabSJim Harris * DMA even though no multiword DMA mode is selected on the device.
325666b0fabSJim Harris * This is because some controllers (LSI) will only accept
326666b0fabSJim Harris * ATA_PASSTHROUGH commands with DMA mode - not UDMA_IN/OUT.
327666b0fabSJim Harris *
328666b0fabSJim Harris * Since isci does not support multiword DMA, fix this up here.
329666b0fabSJim Harris */
330666b0fabSJim Harris if (sequence->protocol == PASSTHROUGH_DMA)
331666b0fabSJim Harris {
332666b0fabSJim Harris if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x1)
333666b0fabSJim Harris {
334666b0fabSJim Harris sequence->protocol = PASSTHROUGH_UDMA_DATA_IN;
335666b0fabSJim Harris }
336666b0fabSJim Harris else
337666b0fabSJim Harris {
338666b0fabSJim Harris sequence->protocol = PASSTHROUGH_UDMA_DATA_OUT;
339666b0fabSJim Harris }
340666b0fabSJim Harris }
341666b0fabSJim Harris
342f11c7f63SJim Harris if (sati_passthrough_check_direction(sequence, cdb) != SATI_COMPLETE
343f11c7f63SJim Harris || sati_passthrough_multiple_count_error(cdb)
344f11c7f63SJim Harris )
345f11c7f63SJim Harris {
346f11c7f63SJim Harris // Fail due to mismatch
347f11c7f63SJim Harris sati_scsi_sense_data_construct(
348f11c7f63SJim Harris sequence,
349f11c7f63SJim Harris scsi_io,
350f11c7f63SJim Harris SCSI_STATUS_CHECK_CONDITION,
351f11c7f63SJim Harris SCSI_SENSE_ILLEGAL_REQUEST,
352f11c7f63SJim Harris SCSI_ASC_INVALID_FIELD_IN_CDB,
353f11c7f63SJim Harris SCSI_ASCQ_INVALID_FIELD_IN_CDB
354f11c7f63SJim Harris );
355f11c7f63SJim Harris return SATI_FAILURE_CHECK_RESPONSE_DATA;
356f11c7f63SJim Harris }
357f11c7f63SJim Harris
358f11c7f63SJim Harris sati_set_ata_features(register_fis, sati_get_cdb_byte(cdb, 3));
359f11c7f63SJim Harris sati_set_ata_sector_count(register_fis, sati_get_cdb_byte(cdb, 4));
360f11c7f63SJim Harris sati_set_ata_lba_low(register_fis, sati_get_cdb_byte(cdb, 5));
361f11c7f63SJim Harris sati_set_ata_lba_mid(register_fis, sati_get_cdb_byte(cdb, 6));
362f11c7f63SJim Harris sati_set_ata_lba_high(register_fis, sati_get_cdb_byte(cdb, 7));
363f11c7f63SJim Harris sati_set_ata_device_head(register_fis, sati_get_cdb_byte(cdb, 8));
364f11c7f63SJim Harris sati_set_ata_command(register_fis, sati_get_cdb_byte(cdb, 9));
365f11c7f63SJim Harris
366f11c7f63SJim Harris sequence->state = SATI_SEQUENCE_STATE_AWAIT_RESPONSE;
367f11c7f63SJim Harris
368f11c7f63SJim Harris return SATI_SUCCESS;
369f11c7f63SJim Harris }
370f11c7f63SJim Harris
371f11c7f63SJim Harris /**
372f11c7f63SJim Harris * @brief This method will translate the SCSI Passthrough command
373f11c7f63SJim Harris * into the corresponding ATA command.
374f11c7f63SJim Harris *
375f11c7f63SJim Harris * @return Indicate if the command translation succeeded.
376f11c7f63SJim Harris * @retval SATI_SUCCESS This is returned if the command translation was
377f11c7f63SJim Harris * successful.
378f11c7f63SJim Harris * @retval SATI_FAILURE This is returned if the command translation was
379f11c7f63SJim Harris * unsuccessful
380f11c7f63SJim Harris */
sati_passthrough_16_translate_command(SATI_TRANSLATOR_SEQUENCE_T * sequence,void * scsi_io,void * ata_io)381f11c7f63SJim Harris SATI_STATUS sati_passthrough_16_translate_command(
382f11c7f63SJim Harris SATI_TRANSLATOR_SEQUENCE_T * sequence,
383f11c7f63SJim Harris void * scsi_io,
384f11c7f63SJim Harris void * ata_io
385f11c7f63SJim Harris )
386f11c7f63SJim Harris {
387f11c7f63SJim Harris SATI_STATUS status;
388f11c7f63SJim Harris U8 * cdb;
389f11c7f63SJim Harris U8 * register_fis;
390f11c7f63SJim Harris
391f11c7f63SJim Harris status = SATI_FAILURE;
392f11c7f63SJim Harris
393f11c7f63SJim Harris sequence->type = SATI_SEQUENCE_ATA_PASSTHROUGH_16;
394f11c7f63SJim Harris sequence->state = SATI_SEQUENCE_STATE_TRANSLATE_DATA;
395f11c7f63SJim Harris
396f11c7f63SJim Harris cdb = sati_cb_get_cdb_address(scsi_io);
397f11c7f63SJim Harris sequence->protocol = PASSTHROUGH_CDB_PROTOCOL(cdb);
398f11c7f63SJim Harris register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
399f11c7f63SJim Harris
400666b0fabSJim Harris /*
401666b0fabSJim Harris * CAM will send passthrough commands with protocol set to multiword
402666b0fabSJim Harris * DMA even though no multiword DMA mode is selected on the device.
403666b0fabSJim Harris * This is because some controllers (LSI) will only accept
404666b0fabSJim Harris * ATA_PASSTHROUGH commands with DMA mode - not UDMA_IN/OUT.
405666b0fabSJim Harris *
406666b0fabSJim Harris * Since isci does not support multiword DMA, fix this up here.
407666b0fabSJim Harris */
408666b0fabSJim Harris if (sequence->protocol == PASSTHROUGH_DMA)
409666b0fabSJim Harris {
410666b0fabSJim Harris if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x1)
411666b0fabSJim Harris {
412666b0fabSJim Harris sequence->protocol = PASSTHROUGH_UDMA_DATA_IN;
413666b0fabSJim Harris }
414666b0fabSJim Harris else
415666b0fabSJim Harris {
416666b0fabSJim Harris sequence->protocol = PASSTHROUGH_UDMA_DATA_OUT;
417666b0fabSJim Harris }
418666b0fabSJim Harris }
419666b0fabSJim Harris
420f11c7f63SJim Harris if (sati_passthrough_check_direction(sequence, cdb) != SATI_COMPLETE
421f11c7f63SJim Harris || sati_passthrough_multiple_count_error(cdb)
422f11c7f63SJim Harris )
423f11c7f63SJim Harris {
424f11c7f63SJim Harris // Fail due to mismatch
425f11c7f63SJim Harris sati_scsi_sense_data_construct(
426f11c7f63SJim Harris sequence,
427f11c7f63SJim Harris scsi_io,
428f11c7f63SJim Harris SCSI_STATUS_CHECK_CONDITION,
429f11c7f63SJim Harris SCSI_SENSE_ILLEGAL_REQUEST,
430f11c7f63SJim Harris SCSI_ASC_INVALID_FIELD_IN_CDB,
431f11c7f63SJim Harris SCSI_ASCQ_INVALID_FIELD_IN_CDB
432f11c7f63SJim Harris );
433f11c7f63SJim Harris return SATI_FAILURE_CHECK_RESPONSE_DATA;
434f11c7f63SJim Harris }
435f11c7f63SJim Harris
436f11c7f63SJim Harris if (PASSTHROUGH_CDB_EXTEND(cdb) == 1)
437f11c7f63SJim Harris {
438f11c7f63SJim Harris sati_set_ata_features_exp(register_fis, sati_get_cdb_byte(cdb, 3));
439f11c7f63SJim Harris sati_set_ata_sector_count_exp(register_fis, sati_get_cdb_byte(cdb, 5));
440f11c7f63SJim Harris sati_set_ata_lba_low_exp(register_fis, sati_get_cdb_byte(cdb, 7));
441f11c7f63SJim Harris sati_set_ata_lba_mid_exp(register_fis, sati_get_cdb_byte(cdb, 9));
442f11c7f63SJim Harris sati_set_ata_lba_high_exp(register_fis, sati_get_cdb_byte(cdb, 11));
443f11c7f63SJim Harris }
4445c300060SJim Harris
4455c300060SJim Harris if (PASSTHROUGH_CDB_CK_COND(cdb) ||
4465c300060SJim Harris PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_RETURN_RESPONSE)
4475c300060SJim Harris {
4485c300060SJim Harris sequence->is_translate_response_required = TRUE;
4495c300060SJim Harris }
4505c300060SJim Harris
451f11c7f63SJim Harris sati_set_ata_features(register_fis, sati_get_cdb_byte(cdb, 4));
452f11c7f63SJim Harris sati_set_ata_sector_count(register_fis, sati_get_cdb_byte(cdb, 6));
453f11c7f63SJim Harris sati_set_ata_lba_low(register_fis, sati_get_cdb_byte(cdb, 8));
454f11c7f63SJim Harris sati_set_ata_lba_mid(register_fis, sati_get_cdb_byte(cdb, 10));
455f11c7f63SJim Harris sati_set_ata_lba_high(register_fis, sati_get_cdb_byte(cdb, 12));
456f11c7f63SJim Harris sati_set_ata_device_head(register_fis, sati_get_cdb_byte(cdb, 13));
457f11c7f63SJim Harris sati_set_ata_command(register_fis, sati_get_cdb_byte(cdb, 14));
458f11c7f63SJim Harris
459f11c7f63SJim Harris sequence->state = SATI_SEQUENCE_STATE_AWAIT_RESPONSE;
460f11c7f63SJim Harris
461f11c7f63SJim Harris return SATI_SUCCESS;
462f11c7f63SJim Harris }
463f11c7f63SJim Harris
464f11c7f63SJim Harris /**
465f11c7f63SJim Harris * @brief This method will translate the ATA command
466f11c7f63SJim Harris * response
467f11c7f63SJim Harris *
468f11c7f63SJim Harris * @return Indicate if the command translation succeeded.
469f11c7f63SJim Harris * @retval SATI_COMPLETE This is returned if the command translation was
470f11c7f63SJim Harris * successful.
471f11c7f63SJim Harris * @retval SATI_FAILURE This is returned if the command translation was
472f11c7f63SJim Harris * unsuccessful
473f11c7f63SJim Harris */
sati_passthrough_translate_response(SATI_TRANSLATOR_SEQUENCE_T * sequence,void * scsi_io,void * ata_io)474f11c7f63SJim Harris SATI_STATUS sati_passthrough_translate_response(
475f11c7f63SJim Harris SATI_TRANSLATOR_SEQUENCE_T * sequence,
476f11c7f63SJim Harris void * scsi_io,
477f11c7f63SJim Harris void * ata_io
478f11c7f63SJim Harris )
479f11c7f63SJim Harris {
480f11c7f63SJim Harris U8 * cdb;
481f11c7f63SJim Harris U8 * register_fis;
482f11c7f63SJim Harris
483f11c7f63SJim Harris cdb = sati_cb_get_cdb_address(scsi_io);
484f11c7f63SJim Harris register_fis = sati_cb_get_d2h_register_fis_address(ata_io);
485f11c7f63SJim Harris
486f11c7f63SJim Harris // Check for device errors
487f11c7f63SJim Harris if (sati_get_ata_status(register_fis) & ATA_STATUS_REG_ERROR_BIT)
488f11c7f63SJim Harris {
489f11c7f63SJim Harris sati_translate_error(sequence, scsi_io, (U8)sati_get_ata_error(register_fis));
490f11c7f63SJim Harris return SATI_FAILURE_CHECK_RESPONSE_DATA;
491f11c7f63SJim Harris }
492f11c7f63SJim Harris
4935c300060SJim Harris sequence->state = SATI_SEQUENCE_STATE_FINAL;
4945c300060SJim Harris
495f11c7f63SJim Harris // If the user set the check condition bit, fill out the sense data
496f11c7f63SJim Harris if (PASSTHROUGH_CDB_CK_COND(cdb) ||
497f11c7f63SJim Harris PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_RETURN_RESPONSE)
498f11c7f63SJim Harris {
499f11c7f63SJim Harris sati_passthrough_construct_sense(
500f11c7f63SJim Harris sequence,
501f11c7f63SJim Harris register_fis,
502f11c7f63SJim Harris scsi_io,
503f11c7f63SJim Harris SCSI_STATUS_CHECK_CONDITION,
504f11c7f63SJim Harris SCSI_SENSE_RECOVERED_ERROR,
505f11c7f63SJim Harris SCSI_ASC_NO_ADDITIONAL_SENSE,
506f11c7f63SJim Harris SCSI_ASCQ_ATA_PASS_THROUGH_INFORMATION_AVAILABLE
507f11c7f63SJim Harris );
5085c300060SJim Harris return SATI_FAILURE_CHECK_RESPONSE_DATA;
509f11c7f63SJim Harris }
510f11c7f63SJim Harris
511f11c7f63SJim Harris return SATI_COMPLETE;
512f11c7f63SJim Harris }
513f11c7f63SJim Harris
514f11c7f63SJim Harris #endif // !defined(DISABLE_SATI_PASSTHROUGH)
515