2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
58 * @brief This file contains all of the defintions for the SATI remote
59 * device object. Some translations require information to be
60 * remembered on a per device basis. This information is stored
61 * in the object defined in this file.
64 #include <dev/isci/scil/sati_device.h>
65 #include <dev/isci/scil/sci_util.h> // Move this file.
66 #include <dev/isci/scil/sati_unmap.h>
67 #include <dev/isci/scil/intel_scsi.h>
70 * @brief This method simply initializes the data members in the device
71 * object to their appropriate values.
73 * @param[in] device This parameter specifies the device for which to
74 * initialize the data members.
75 * @param[in] is_ncq_enabled This parameter specifies if NCQ is to be
76 * utilized for this particular SATI device.
77 * @param[in] max_ncq_depth This parameter specifies the maximum desired
78 * NCQ depth. Once this value is set it can never be increased.
79 * @param[in] ignore_fua This parameter specifies FUA is to be ignored and not
80 * sent to the end device. Some OS (Windows) has quirky behaviors with FUA
81 * and recommend driver developers ignore the bit.
85 void sati_device_construct(
86 SATI_DEVICE_T * device,
92 device->state = SATI_DEVICE_STATE_OPERATIONAL;
93 device->capabilities = 0;
94 device->descriptor_sense_enable = SCSI_MODE_PAGE_CONTROL_D_SENSE_DISABLE;
96 // The user requested that NCQ be utilized if it is supported by
98 if (is_ncq_enabled == TRUE)
99 device->capabilities |= SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE;
101 device->ncq_depth = max_ncq_depth;
103 // The user requested that FUA is ignored (windows performance issue)
104 if (ignore_fua == TRUE)
105 device->capabilities |= SATI_DEVICE_CAP_IGNORE_FUA;
110 * @brief This method will update the SATI_DEVICE capabilities based on
111 * the supplied ATA_IDENTIFY_DEVICE_DATA.
113 * @param[in] device This parameter specifies the device for which to update
114 * the supported capabilities.
115 * @param[in] identify This parameter specifies the ata identify device
116 * information from which to extract the capabilities of the
121 void sati_device_update_capabilities(
122 SATI_DEVICE_T * device,
123 ATA_IDENTIFY_DEVICE_DATA_T * identify
126 U16 capabilities = 0;
128 if (identify->capabilities1 & ATA_IDENTIFY_CAPABILITIES1_NORMAL_DMA_ENABLE)
129 capabilities |= SATI_DEVICE_CAP_UDMA_ENABLE;
131 if (identify->command_set_supported1
132 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED1_48BIT_ENABLE)
134 capabilities |= SATI_DEVICE_CAP_48BIT_ENABLE;
137 if (identify->command_set_supported0
138 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED0_SMART_ENABLE)
140 capabilities |= SATI_DEVICE_CAP_SMART_SUPPORT;
143 if (identify->command_set_enabled0
144 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED0_SMART_ENABLE)
146 capabilities |= SATI_DEVICE_CAP_SMART_ENABLE;
149 // Save the NCQ related capabilities information.
150 if (identify->serial_ata_capabilities
151 & ATA_IDENTIFY_SATA_CAPABILITIES_NCQ_ENABLE)
153 if (device->capabilities & SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE)
155 capabilities |= SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE;
156 capabilities |= SATI_DEVICE_CAP_NCQ_SUPPORTED_ENABLE;
157 capabilities |= SATI_DEVICE_CAP_DMA_FUA_ENABLE;
158 device->ncq_depth = MIN(
160 (U8) (identify->queue_depth
161 & ATA_IDENTIFY_NCQ_QUEUE_DEPTH_ENABLE) + 1
166 // if the user requested that FUA is ignored; transfer it so we don't lose on update.
167 if (device->capabilities & SATI_DEVICE_CAP_IGNORE_FUA)
168 capabilities |= SATI_DEVICE_CAP_IGNORE_FUA;
170 if (identify->general_config_bits & ATA_IDENTIFY_REMOVABLE_MEDIA_ENABLE)
171 capabilities |= SATI_DEVICE_CAP_REMOVABLE_MEDIA;
173 if(identify->command_set_supported2 & ATA_IDENTIFY_WRITE_UNCORRECTABLE_SUPPORT )
175 capabilities |= SATI_DEVICE_CAP_WRITE_UNCORRECTABLE_ENABLE;
178 if(identify->physical_logical_sector_info &
179 ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_ENABLE)
181 capabilities |= SATI_DEVICE_CAP_MULTIPLE_SECTORS_PER_PHYSCIAL_SECTOR;
184 if(identify->command_set_supported_extention &
185 ATA_IDENTIFY_COMMAND_SET_SMART_SELF_TEST_SUPPORTED)
187 capabilities |= SATI_DEVICE_CAP_SMART_SELF_TEST_SUPPORT;
190 if (identify->nominal_media_rotation_rate == 1)
192 capabilities |= SATI_DEVICE_CAP_SSD;
195 // Save off the logical block size reported by the drive
196 // See if Word 106 is valid and reports a logical sector size
197 if ((identify->physical_logical_sector_info & 0x5000) == 0x5000)
199 device->logical_block_size = (identify->words_per_logical_sector[3] << 24) |
200 (identify->words_per_logical_sector[2] << 16) |
201 (identify->words_per_logical_sector[1] << 8) |
202 (identify->words_per_logical_sector[0]);
206 device->logical_block_size = 512;
209 // Determine DSM TRIM capabilities
210 // Defend against SSDs which report TRIM support, but set
211 // max_lba_range_entry_blocks to zero, by disabling TRIM for
214 (identify->data_set_management & ATA_IDENTIFY_COMMAND_SET_DSM_TRIM_SUPPORTED)
215 && (identify->max_lba_range_entry_blocks > 0)
218 capabilities |= SATI_DEVICE_CAP_DSM_TRIM_SUPPORT;
219 device->max_lba_range_entry_blocks = identify->max_lba_range_entry_blocks;
222 if (identify->additional_supported
223 & ATA_IDENTIFY_COMMAND_ADDL_SUPPORTED_DETERMINISTIC_READ)
225 capabilities |= SATI_DEVICE_CAP_DETERMINISTIC_READ_AFTER_TRIM;
228 if (identify->additional_supported
229 & ATA_IDENTIFY_COMMAND_ADDL_SUPPORTED_READ_ZERO)
231 capabilities |= SATI_DEVICE_CAP_READ_ZERO_AFTER_TRIM;
234 if (identify->capabilities1
235 & ATA_IDENTIFY_CAPABILITIES1_STANDBY_ENABLE)
237 capabilities |= SATI_DEVICE_CAP_STANDBY_ENABLE;
240 device->min_blocks_per_microcode_command = identify->min_num_blocks_per_microcode;
241 device->max_blocks_per_microcode_command = identify->max_num_blocks_per_microcode;
243 device->capabilities = capabilities;