2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
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.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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
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.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
60 * @brief This file contains all of the defintions for the SATI remote
61 * device object. Some translations require information to be
62 * remembered on a per device basis. This information is stored
63 * in the object defined in this file.
66 #include <dev/isci/scil/sati_device.h>
67 #include <dev/isci/scil/sci_util.h> // Move this file.
68 #include <dev/isci/scil/sati_unmap.h>
69 #include <dev/isci/scil/intel_scsi.h>
72 * @brief This method simply initializes the data members in the device
73 * object to their appropriate values.
75 * @param[in] device This parameter specifies the device for which to
76 * initialize the data members.
77 * @param[in] is_ncq_enabled This parameter specifies if NCQ is to be
78 * utilized for this particular SATI device.
79 * @param[in] max_ncq_depth This parameter specifies the maximum desired
80 * NCQ depth. Once this value is set it can never be increased.
81 * @param[in] ignore_fua This parameter specifies FUA is to be ignored and not
82 * sent to the end device. Some OS (Windows) has quirky behaviors with FUA
83 * and recommend driver developers ignore the bit.
87 void sati_device_construct(
88 SATI_DEVICE_T * device,
94 device->state = SATI_DEVICE_STATE_OPERATIONAL;
95 device->capabilities = 0;
96 device->descriptor_sense_enable = SCSI_MODE_PAGE_CONTROL_D_SENSE_DISABLE;
98 // The user requested that NCQ be utilized if it is supported by
100 if (is_ncq_enabled == TRUE)
101 device->capabilities |= SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE;
103 device->ncq_depth = max_ncq_depth;
105 // The user requested that FUA is ignored (windows performance issue)
106 if (ignore_fua == TRUE)
107 device->capabilities |= SATI_DEVICE_CAP_IGNORE_FUA;
112 * @brief This method will update the SATI_DEVICE capabilities based on
113 * the supplied ATA_IDENTIFY_DEVICE_DATA.
115 * @param[in] device This parameter specifies the device for which to update
116 * the supported capabilities.
117 * @param[in] identify This parameter specifies the ata identify device
118 * information from which to extract the capabilities of the
123 void sati_device_update_capabilities(
124 SATI_DEVICE_T * device,
125 ATA_IDENTIFY_DEVICE_DATA_T * identify
128 U16 capabilities = 0;
130 if (identify->capabilities1 & ATA_IDENTIFY_CAPABILITIES1_NORMAL_DMA_ENABLE)
131 capabilities |= SATI_DEVICE_CAP_UDMA_ENABLE;
133 if (identify->command_set_supported1
134 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED1_48BIT_ENABLE)
136 capabilities |= SATI_DEVICE_CAP_48BIT_ENABLE;
139 if (identify->command_set_supported0
140 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED0_SMART_ENABLE)
142 capabilities |= SATI_DEVICE_CAP_SMART_SUPPORT;
145 if (identify->command_set_enabled0
146 & ATA_IDENTIFY_COMMAND_SET_SUPPORTED0_SMART_ENABLE)
148 capabilities |= SATI_DEVICE_CAP_SMART_ENABLE;
151 // Save the NCQ related capabilities information.
152 if (identify->serial_ata_capabilities
153 & ATA_IDENTIFY_SATA_CAPABILITIES_NCQ_ENABLE)
155 if (device->capabilities & SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE)
157 capabilities |= SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE;
158 capabilities |= SATI_DEVICE_CAP_NCQ_SUPPORTED_ENABLE;
159 capabilities |= SATI_DEVICE_CAP_DMA_FUA_ENABLE;
160 device->ncq_depth = MIN(
162 (U8) (identify->queue_depth
163 & ATA_IDENTIFY_NCQ_QUEUE_DEPTH_ENABLE) + 1
168 // if the user requested that FUA is ignored; transfer it so we don't lose on update.
169 if (device->capabilities & SATI_DEVICE_CAP_IGNORE_FUA)
170 capabilities |= SATI_DEVICE_CAP_IGNORE_FUA;
172 if (identify->general_config_bits & ATA_IDENTIFY_REMOVABLE_MEDIA_ENABLE)
173 capabilities |= SATI_DEVICE_CAP_REMOVABLE_MEDIA;
175 if(identify->command_set_supported2 & ATA_IDENTIFY_WRITE_UNCORRECTABLE_SUPPORT )
177 capabilities |= SATI_DEVICE_CAP_WRITE_UNCORRECTABLE_ENABLE;
180 if(identify->physical_logical_sector_info &
181 ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_ENABLE)
183 capabilities |= SATI_DEVICE_CAP_MULTIPLE_SECTORS_PER_PHYSCIAL_SECTOR;
186 if(identify->command_set_supported_extention &
187 ATA_IDENTIFY_COMMAND_SET_SMART_SELF_TEST_SUPPORTED)
189 capabilities |= SATI_DEVICE_CAP_SMART_SELF_TEST_SUPPORT;
192 if (identify->nominal_media_rotation_rate == 1)
194 capabilities |= SATI_DEVICE_CAP_SSD;
197 // Save off the logical block size reported by the drive
198 // See if Word 106 is valid and reports a logical sector size
199 if ((identify->physical_logical_sector_info & 0x5000) == 0x5000)
201 device->logical_block_size = (identify->words_per_logical_sector[3] << 24) |
202 (identify->words_per_logical_sector[2] << 16) |
203 (identify->words_per_logical_sector[1] << 8) |
204 (identify->words_per_logical_sector[0]);
208 device->logical_block_size = 512;
211 // Determine DSM TRIM capabilities
212 // Defend against SSDs which report TRIM support, but set
213 // max_lba_range_entry_blocks to zero, by disabling TRIM for
216 (identify->data_set_management & ATA_IDENTIFY_COMMAND_SET_DSM_TRIM_SUPPORTED)
217 && (identify->max_lba_range_entry_blocks > 0)
220 capabilities |= SATI_DEVICE_CAP_DSM_TRIM_SUPPORT;
221 device->max_lba_range_entry_blocks = identify->max_lba_range_entry_blocks;
224 if (identify->additional_supported
225 & ATA_IDENTIFY_COMMAND_ADDL_SUPPORTED_DETERMINISTIC_READ)
227 capabilities |= SATI_DEVICE_CAP_DETERMINISTIC_READ_AFTER_TRIM;
230 if (identify->additional_supported
231 & ATA_IDENTIFY_COMMAND_ADDL_SUPPORTED_READ_ZERO)
233 capabilities |= SATI_DEVICE_CAP_READ_ZERO_AFTER_TRIM;
236 if (identify->capabilities1
237 & ATA_IDENTIFY_CAPABILITIES1_STANDBY_ENABLE)
239 capabilities |= SATI_DEVICE_CAP_STANDBY_ENABLE;
242 device->min_blocks_per_microcode_command = identify->min_num_blocks_per_microcode;
243 device->max_blocks_per_microcode_command = identify->max_num_blocks_per_microcode;
245 device->capabilities = capabilities;