1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
25 *
26 * BSD LICENSE
27 *
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 *
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
40 * distribution.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */
54
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
57
58 /**
59 * @file
60 * @brief This file contains the method implementations required to
61 * translate the SCSI mode sense 10-byte commands.
62 */
63
64 #if !defined(DISABLE_SATI_MODE_SENSE)
65
66 #include <dev/isci/scil/sati_mode_sense.h>
67 #include <dev/isci/scil/sati_mode_sense_10.h>
68 #include <dev/isci/scil/sati_mode_pages.h>
69 #include <dev/isci/scil/sati_callbacks.h>
70 #include <dev/isci/scil/sati_util.h>
71 #include <dev/isci/scil/intel_scsi.h>
72 #include <dev/isci/scil/intel_ata.h>
73
74 //******************************************************************************
75 //* P R I V A T E M E T H O D S
76 //******************************************************************************
77
78 /**
79 * @brief This method builds the mode parameter header for a 10-byte SCSI
80 * mode sense data response. The parameter header is 4 bytes in
81 * size.
82 * For more information on the parameters passed to this method,
83 * please reference sati_translate_command().
84 *
85 * @param[in] identify This parameter specifies the ATA remote device's
86 * received IDENTIFY DEVICE data.
87 * @param[in] mode_data_length This parameter specifies the amount of data
88 * to be returned as part of this mode sense request.
89 *
90 * @return This method returns the number of bytes written into the
91 * mode sense data buffer.
92 */
93 static
94 U32 sati_mode_sense_10_build_header(
95 SATI_TRANSLATOR_SEQUENCE_T * sequence,
96 void * scsi_io,
97 ATA_IDENTIFY_DEVICE_DATA_T * identify,
98 U16 mode_data_length
99 )
100 {
101 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
102
103 // Fill in the length of the mode parameter data returned (do not include
104 // the size of the mode data length field in the total). Adjust the
105 // mode data length to not include the mode data length fields itself
106 // (i.e. subtract 2).
107 mode_data_length -= 2;
108 sati_set_data_byte(sequence, scsi_io, 0, (U8)(mode_data_length >> 8) & 0xFF);
109 sati_set_data_byte(sequence, scsi_io, 1, (U8)(mode_data_length & 0xFF));
110
111 // Medium Type is 0 for SBC devices
112 sati_set_data_byte(sequence, scsi_io, 2, SCSI_MODE_HEADER_MEDIUM_TYPE_SBC);
113
114 // Write Protect (WP), Rsvd, DPOFUA, Rsvd
115 if (sequence->device->capabilities & SATI_DEVICE_CAP_DMA_FUA_ENABLE)
116 sati_set_data_byte(sequence,scsi_io,3,SCSI_MODE_SENSE_HEADER_FUA_ENABLE);
117 else
118 sati_set_data_byte(sequence, scsi_io, 3, 0);
119
120 // Set the reserved bytes to 0. The LONGLBA field in byte 4 is overridden
121 // later in this method if LLBAA is enabled.
122 sati_set_data_byte(sequence, scsi_io, 4, 0);
123 sati_set_data_byte(sequence, scsi_io, 5, 0);
124
125 // The MSB for the block descriptor length is never used since the
126 // largest block descriptor in this translator is 16-bytes in size.
127 sati_set_data_byte(sequence, scsi_io, 6, 0);
128
129 // Set the LSB block descriptor length if block descriptors are utilized.
130 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_DBD_ENABLE)
131 sati_set_data_byte(sequence, scsi_io, 7, 0);
132 else
133 {
134 // If Long Logical Block Address are allowed, then the block descriptor
135 // is larger (16 bytes total).
136 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_LLBAA_ENABLE)
137 {
138 sati_set_data_byte(sequence, scsi_io, 4, 1);
139 sati_set_data_byte(
140 sequence, scsi_io, 7, SCSI_MODE_SENSE_LLBA_BLOCK_DESCRIPTOR_LENGTH
141 );
142 }
143 else
144 {
145 sati_set_data_byte(
146 sequence, scsi_io, 7, SCSI_MODE_SENSE_STD_BLOCK_DESCRIPTOR_LENGTH
147 );
148 }
149 }
150
151 return SCSI_MODE_SENSE_10_HEADER_LENGTH;
152 }
153
154 static
155 U32 sati_mode_sense_10_build_llba_block_descriptor(
156 SATI_TRANSLATOR_SEQUENCE_T * sequence,
157 void * scsi_io,
158 ATA_IDENTIFY_DEVICE_DATA_T * identify,
159 U32 offset
160 )
161 {
162 U32 lba_low = 0;
163 U32 lba_high = 0;
164 U32 sector_size = 0;
165
166 // Extract the sector information (sector size, logical blocks) from
167 // the retrieved ATA identify device data.
168 sati_ata_identify_device_get_sector_info(
169 identify, &lba_low, &lba_high, §or_size
170 );
171
172 // Fill in the 8-byte logical block area
173 sati_set_data_byte(sequence, scsi_io, offset, (U8)((lba_high>>24) & 0xFF));
174 sati_set_data_byte(sequence, scsi_io, offset+1, (U8)((lba_high>>16) & 0xFF));
175 sati_set_data_byte(sequence, scsi_io, offset+2, (U8)((lba_high>>8) & 0xFF));
176 sati_set_data_byte(sequence, scsi_io, offset+3, (U8)(lba_high & 0xFF));
177 sati_set_data_byte(sequence, scsi_io, offset+4, (U8)((lba_low>>24) & 0xFF));
178 sati_set_data_byte(sequence, scsi_io, offset+5, (U8)((lba_low>>16) & 0xFF));
179 sati_set_data_byte(sequence, scsi_io, offset+6, (U8)((lba_low>>8) & 0xFF));
180 sati_set_data_byte(sequence, scsi_io, offset+7, (U8)(lba_low & 0xFF));
181
182 // Clear the reserved fields.
183 sati_set_data_byte(sequence, scsi_io, offset+8, 0);
184 sati_set_data_byte(sequence, scsi_io, offset+9, 0);
185 sati_set_data_byte(sequence, scsi_io, offset+10, 0);
186 sati_set_data_byte(sequence, scsi_io, offset+11, 0);
187
188 // Fill in the four byte Block Length field
189 sati_set_data_byte(sequence,scsi_io, offset+12, (U8)((sector_size>>24) & 0xFF));
190 sati_set_data_byte(sequence,scsi_io, offset+13, (U8)((sector_size>>16) & 0xFF));
191 sati_set_data_byte(sequence,scsi_io, offset+14, (U8)((sector_size>>8) & 0xFF));
192 sati_set_data_byte(sequence,scsi_io, offset+15, (U8)(sector_size & 0xFF));
193
194 return SCSI_MODE_SENSE_LLBA_BLOCK_DESCRIPTOR_LENGTH;
195 }
196
197 /**
198 * @brief This method perform the data translation common to all SCSI MODE
199 * SENSE 10 byte commands. This includes building the mode page
200 * header and block descriptor (if requested).
201 * For more information on the parameters passed to this method,
202 * please reference sati_translate_command().
203 *
204 * @param[in] identify This parameter specifies the remote device's IDENTIFY
205 * DEVICE data to be used during translation.
206 * @param[in] transfer_length This parameter specifies the size of the
207 * mode page (including header & block descriptor).
208 *
209 * @return This method returns the number of bytes written into the user's
210 * mode page data buffer.
211 */
212 static
213 U32 sati_mode_sense_10_translate_data(
214 SATI_TRANSLATOR_SEQUENCE_T * sequence,
215 ATA_IDENTIFY_DEVICE_DATA_T * identify,
216 void * scsi_io,
217 U16 transfer_length
218 )
219 {
220 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
221 U32 offset;
222
223 offset = sati_mode_sense_10_build_header(
224 sequence, scsi_io, identify, transfer_length
225 );
226
227 // Determine if the caller disabled block descriptors (DBD). If not,
228 // then generate a block descriptor.
229 if ((sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_DBD_ENABLE) == 0)
230 {
231 // If the user requested the Long LBA format descriptor, then build
232 // it
233 if (sati_get_cdb_byte(cdb, 1) & SCSI_MODE_SENSE_LLBAA_ENABLE)
234 offset += sati_mode_sense_10_build_llba_block_descriptor(
235 sequence, scsi_io, identify, offset
236 );
237 else
238 offset += sati_mode_sense_build_std_block_descriptor(
239 sequence, scsi_io, identify, offset
240 );
241 }
242
243 return offset;
244 }
245
246 //******************************************************************************
247 //* P R O T E C T E D M E T H O D S
248 //******************************************************************************
249
250 /**
251 * @brief This method will translate the SCSI mode sense 6 byte command
252 * into corresponding ATA commands. If the command is well-formed,
253 * then the translation will result in an ATA IDENTIFY DEVICE
254 * command.
255 * For more information on the parameters passed to this method,
256 * please reference sati_translate_command().
257 *
258 * @return Indicate if the command translation succeeded.
259 * @retval SCI_SUCCESS This is returned if the command translation was
260 * successful.
261 * @retval SATI_FAILURE_CHECK_RESPONSE_DATA This value is returned if
262 * sense data has been created as a result of something specified
263 * in the CDB.
264 */
265 SATI_STATUS sati_mode_sense_10_translate_command(
266 SATI_TRANSLATOR_SEQUENCE_T * sequence,
267 void * scsi_io,
268 void * ata_io
269 )
270 {
271 U8 * cdb = sati_cb_get_cdb_address(scsi_io);
272
273 sequence->command_specific_data.scratch = 0;
274
275 // Set the data length based on the allocation length field in the CDB.
276 sequence->allocation_length = (sati_get_cdb_byte(cdb, 7) << 8) |
277 (sati_get_cdb_byte(cdb, 8));
278
279 return sati_mode_sense_translate_command(sequence, scsi_io, ata_io, 10);
280 }
281
282 /**
283 * @brief This method will perform data translation from the supplied ATA
284 * input data (i.e. an ATA IDENTIFY DEVICE block) into a CACHING
285 * mode page format. The data will be written into the user's mode
286 * page data buffer. This function operates specifically for MODE
287 * SENSE 10 commands.
288 * For more information on the parameters passed to this method,
289 * please reference sati_translate_data().
290 *
291 * @return none.
292 */
293 void sati_mode_sense_10_caching_translate_data(
294 SATI_TRANSLATOR_SEQUENCE_T * sequence,
295 void * ata_input_data,
296 void * scsi_io
297 )
298 {
299 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
300 ata_input_data;
301 U16 data_length = sati_mode_sense_calculate_page_header(scsi_io, 10)
302 + SCSI_MODE_PAGE_08_LENGTH;
303 U32 page_offset = sati_mode_sense_10_translate_data(
304 sequence, identify, scsi_io, data_length
305 );
306
307 sati_mode_sense_caching_translate_data(
308 sequence, scsi_io, identify, page_offset
309 );
310 }
311
312 /**
313 * @brief This method will perform data translation from the supplied ATA
314 * input data (i.e. an ATA IDENTIFY DEVICE block) into a INFORMATIONAL
315 * EXCEPTIONS CONTROL mode page format. The data will be written
316 * into the user's mode page data buffer. This function operates
317 * specifically for MODE SENSE 10 commands.
318 * For more information on the parameters passed to this method,
319 * please reference sati_translate_data().
320 *
321 * @return none.
322 */
323 void sati_mode_sense_10_informational_excp_control_translate_data(
324 SATI_TRANSLATOR_SEQUENCE_T * sequence,
325 void * ata_input_data,
326 void * scsi_io
327 )
328 {
329 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
330 ata_input_data;
331 U16 data_length = sati_mode_sense_calculate_page_header(scsi_io, 10)
332 + SCSI_MODE_PAGE_1C_LENGTH;
333 U32 page_offset = sati_mode_sense_10_translate_data(
334 sequence, identify, scsi_io, data_length
335 );
336
337 sati_mode_sense_informational_excp_control_translate_data(
338 sequence, scsi_io, identify, page_offset
339 );
340 }
341
342 /**
343 * @brief This method will perform data translation from the supplied ATA
344 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Read Write Error
345 * mode page format. The data will be written
346 * into the user's mode page data buffer. This function operates
347 * specifically for MODE SENSE 10 commands.
348 * For more information on the parameters passed to this method,
349 * please reference sati_translate_data().
350 *
351 * @return none.
352 */
353 void sati_mode_sense_10_read_write_error_translate_data(
354 SATI_TRANSLATOR_SEQUENCE_T * sequence,
355 void * ata_input_data,
356 void * scsi_io
357 )
358 {
359 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
360 ata_input_data;
361
362 U16 data_length = sati_mode_sense_calculate_page_header(scsi_io, 10)
363 + SCSI_MODE_PAGE_01_LENGTH;
364
365 U32 page_offset = sati_mode_sense_10_translate_data(
366 sequence, identify, scsi_io, data_length
367 );
368
369 sati_mode_sense_read_write_error_translate_data(
370 sequence, scsi_io, identify, page_offset
371 );
372 }
373
374 /**
375 * @brief This method will perform data translation from the supplied ATA
376 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Disconnect
377 * Reconnect mode page format. The data will be written
378 * into the user's mode page data buffer. This function operates
379 * specifically for MODE SENSE 10 commands.
380 * For more information on the parameters passed to this method,
381 * please reference sati_translate_data().
382 *
383 * @return none.
384 */
385 void sati_mode_sense_10_disconnect_reconnect_translate_data(
386 SATI_TRANSLATOR_SEQUENCE_T * sequence,
387 void * ata_input_data,
388 void * scsi_io
389 )
390 {
391 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
392 ata_input_data;
393
394 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
395 + SCSI_MODE_PAGE_02_LENGTH;
396
397 U32 page_offset = sati_mode_sense_10_translate_data(
398 sequence, identify, scsi_io, data_length
399 );
400
401 sati_mode_sense_disconnect_reconnect_translate_data(
402 sequence, scsi_io, identify, page_offset
403 );
404 }
405
406 /**
407 * @brief This method will perform data translation from the supplied ATA
408 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Control
409 * mode page format. The data will be written
410 * into the user's mode page data buffer. This function operates
411 * specifically for MODE SENSE 10 commands.
412 * For more information on the parameters passed to this method,
413 * please reference sati_translate_data().
414 *
415 * @return none.
416 */
417 void sati_mode_sense_10_control_translate_data(
418 SATI_TRANSLATOR_SEQUENCE_T * sequence,
419 void * ata_input_data,
420 void * scsi_io
421 )
422 {
423 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
424 ata_input_data;
425
426 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
427 + SCSI_MODE_PAGE_0A_LENGTH;
428
429 U32 page_offset = sati_mode_sense_10_translate_data(
430 sequence, identify, scsi_io, data_length
431 );
432
433 sati_mode_sense_control_translate_data(
434 sequence, scsi_io, identify, page_offset
435 );
436 }
437
438 /**
439 * @brief This method will perform data translation from the supplied ATA
440 * input data (i.e. an ATA IDENTIFY DEVICE block) into a Power
441 * Condition mode page format. The data will be written
442 * into the user's mode page data buffer. This function operates
443 * specifically for MODE SENSE 10 commands.
444 * For more information on the parameters passed to this method,
445 * please reference sati_translate_data().
446 *
447 * @return none.
448 */
449 void sati_mode_sense_10_power_condition_translate_data(
450 SATI_TRANSLATOR_SEQUENCE_T * sequence,
451 void * ata_input_data,
452 void * scsi_io
453 )
454 {
455 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
456 ata_input_data;
457
458 U8 data_length;
459 U32 page_offset;
460
461 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
462 + SCSI_MODE_PAGE_1A_LENGTH;
463
464 page_offset = sati_mode_sense_10_translate_data(
465 sequence, identify, scsi_io, data_length
466 );
467
468 sati_mode_sense_power_condition_translate_data(
469 sequence, scsi_io, identify, page_offset
470 );
471 }
472
473
474 /**
475 * @brief This method will perform data translation from the supplied ATA
476 * input data (i.e. an ATA IDENTIFY DEVICE block) into an ALL
477 * PAGES mode page format. The ALL PAGES mode page is basically a
478 * conglomeration of all mode pages and sub-pages into a single
479 * page. The data will be written into the user's mode page
480 * data buffer. This function operates specifically for MODE
481 * SENSE 10 commands.
482 * For more information on the parameters passed to this method,
483 * please reference sati_translate_data().
484 *
485 * @return none.
486 */
487 void sati_mode_sense_10_all_pages_translate_data(
488 SATI_TRANSLATOR_SEQUENCE_T * sequence,
489 void * ata_input_data,
490 void * scsi_io
491 )
492 {
493 ATA_IDENTIFY_DEVICE_DATA_T * identify = (ATA_IDENTIFY_DEVICE_DATA_T*)
494 ata_input_data;
495 U8 data_length = (U8) sati_mode_sense_calculate_page_header(scsi_io, 10)
496 + SCSI_MODE_PAGE_01_LENGTH
497 + SCSI_MODE_PAGE_02_LENGTH
498 + SCSI_MODE_PAGE_08_LENGTH
499 + SCSI_MODE_PAGE_0A_LENGTH
500 + SCSI_MODE_PAGE_1C_LENGTH;
501 U32 page_offset = sati_mode_sense_10_translate_data(
502 sequence, identify, scsi_io, data_length
503 );
504
505 sati_mode_sense_all_pages_translate_data(
506 sequence, scsi_io, identify, page_offset
507 );
508 }
509
510 #endif // !defined(DISABLE_SATI_MODE_SENSE)
511
Cache object: 2ea4be033157ea1b64e32a9050375101
|