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 __FBSDID("$FreeBSD$"); 57f11c7f63SJim Harris 58f11c7f63SJim Harris /** 59f11c7f63SJim Harris * @file 60f11c7f63SJim Harris * @brief This file contains all of the defintions for the SATI remote 61f11c7f63SJim Harris * device object. Some translations require information to be 62f11c7f63SJim Harris * remembered on a per device basis. This information is stored 63f11c7f63SJim Harris * in the object defined in this file. 64f11c7f63SJim Harris */ 65f11c7f63SJim Harris 66f11c7f63SJim Harris #include <dev/isci/scil/sati_device.h> 67f11c7f63SJim Harris #include <dev/isci/scil/sci_util.h> // Move this file. 68f11c7f63SJim Harris #include <dev/isci/scil/sati_unmap.h> 69f11c7f63SJim Harris #include <dev/isci/scil/intel_scsi.h> 70f11c7f63SJim Harris 71f11c7f63SJim Harris /** 72f11c7f63SJim Harris * @brief This method simply initializes the data members in the device 73f11c7f63SJim Harris * object to their appropriate values. 74f11c7f63SJim Harris * 75f11c7f63SJim Harris * @param[in] device This parameter specifies the device for which to 76f11c7f63SJim Harris * initialize the data members. 77f11c7f63SJim Harris * @param[in] is_ncq_enabled This parameter specifies if NCQ is to be 78f11c7f63SJim Harris * utilized for this particular SATI device. 79f11c7f63SJim Harris * @param[in] max_ncq_depth This parameter specifies the maximum desired 80f11c7f63SJim Harris * NCQ depth. Once this value is set it can never be increased. 81f11c7f63SJim Harris * @param[in] ignore_fua This parameter specifies FUA is to be ignored and not 82f11c7f63SJim Harris * sent to the end device. Some OS (Windows) has quirky behaviors with FUA 83f11c7f63SJim Harris * and recommend driver developers ignore the bit. 84f11c7f63SJim Harris * 85f11c7f63SJim Harris * @return none 86f11c7f63SJim Harris */ 87f11c7f63SJim Harris void sati_device_construct( 88f11c7f63SJim Harris SATI_DEVICE_T * device, 89f11c7f63SJim Harris BOOL is_ncq_enabled, 90f11c7f63SJim Harris U8 max_ncq_depth, 91f11c7f63SJim Harris BOOL ignore_fua 92f11c7f63SJim Harris ) 93f11c7f63SJim Harris { 94f11c7f63SJim Harris device->state = SATI_DEVICE_STATE_OPERATIONAL; 95f11c7f63SJim Harris device->capabilities = 0; 96f11c7f63SJim Harris device->descriptor_sense_enable = SCSI_MODE_PAGE_CONTROL_D_SENSE_DISABLE; 97f11c7f63SJim Harris 98f11c7f63SJim Harris // The user requested that NCQ be utilized if it is supported by 99f11c7f63SJim Harris // the device. 100f11c7f63SJim Harris if (is_ncq_enabled == TRUE) 101f11c7f63SJim Harris device->capabilities |= SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE; 102f11c7f63SJim Harris 103f11c7f63SJim Harris device->ncq_depth = max_ncq_depth; 104f11c7f63SJim Harris 105f11c7f63SJim Harris // The user requested that FUA is ignored (windows performance issue) 106f11c7f63SJim Harris if (ignore_fua == TRUE) 107f11c7f63SJim Harris device->capabilities |= SATI_DEVICE_CAP_IGNORE_FUA; 108f11c7f63SJim Harris 109f11c7f63SJim Harris } 110f11c7f63SJim Harris 111f11c7f63SJim Harris /** 112f11c7f63SJim Harris * @brief This method will update the SATI_DEVICE capabilities based on 113f11c7f63SJim Harris * the supplied ATA_IDENTIFY_DEVICE_DATA. 114f11c7f63SJim Harris * 115f11c7f63SJim Harris * @param[in] device This parameter specifies the device for which to update 116f11c7f63SJim Harris * the supported capabilities. 117f11c7f63SJim Harris * @param[in] identify This parameter specifies the ata identify device 118f11c7f63SJim Harris * information from which to extract the capabilities of the 119f11c7f63SJim Harris * device. 120f11c7f63SJim Harris * 121f11c7f63SJim Harris * @return none 122f11c7f63SJim Harris */ 123f11c7f63SJim Harris void sati_device_update_capabilities( 124f11c7f63SJim Harris SATI_DEVICE_T * device, 125f11c7f63SJim Harris ATA_IDENTIFY_DEVICE_DATA_T * identify 126f11c7f63SJim Harris ) 127f11c7f63SJim Harris { 128f11c7f63SJim Harris U16 capabilities = 0; 129f11c7f63SJim Harris 130f11c7f63SJim Harris if (identify->capabilities1 & ATA_IDENTIFY_CAPABILITIES1_NORMAL_DMA_ENABLE) 131f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_UDMA_ENABLE; 132f11c7f63SJim Harris 133f11c7f63SJim Harris if (identify->command_set_supported1 134f11c7f63SJim Harris & ATA_IDENTIFY_COMMAND_SET_SUPPORTED1_48BIT_ENABLE) 135f11c7f63SJim Harris { 136f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_48BIT_ENABLE; 137f11c7f63SJim Harris } 138f11c7f63SJim Harris 139f11c7f63SJim Harris if (identify->command_set_supported0 140f11c7f63SJim Harris & ATA_IDENTIFY_COMMAND_SET_SUPPORTED0_SMART_ENABLE) 141f11c7f63SJim Harris { 142f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_SMART_SUPPORT; 143f11c7f63SJim Harris } 144f11c7f63SJim Harris 145f11c7f63SJim Harris if (identify->command_set_enabled0 146f11c7f63SJim Harris & ATA_IDENTIFY_COMMAND_SET_SUPPORTED0_SMART_ENABLE) 147f11c7f63SJim Harris { 148f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_SMART_ENABLE; 149f11c7f63SJim Harris } 150f11c7f63SJim Harris 151f11c7f63SJim Harris // Save the NCQ related capabilities information. 152f11c7f63SJim Harris if (identify->serial_ata_capabilities 153f11c7f63SJim Harris & ATA_IDENTIFY_SATA_CAPABILITIES_NCQ_ENABLE) 154f11c7f63SJim Harris { 155f11c7f63SJim Harris if (device->capabilities & SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE) 156f11c7f63SJim Harris { 157f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_NCQ_REQUESTED_ENABLE; 158f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_NCQ_SUPPORTED_ENABLE; 159f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_DMA_FUA_ENABLE; 160f11c7f63SJim Harris device->ncq_depth = MIN( 161f11c7f63SJim Harris device->ncq_depth, 162f11c7f63SJim Harris (U8) (identify->queue_depth 163f11c7f63SJim Harris & ATA_IDENTIFY_NCQ_QUEUE_DEPTH_ENABLE) + 1 164f11c7f63SJim Harris ); 165f11c7f63SJim Harris } 166f11c7f63SJim Harris } 167f11c7f63SJim Harris 168f11c7f63SJim Harris // if the user requested that FUA is ignored; transfer it so we don't lose on update. 169f11c7f63SJim Harris if (device->capabilities & SATI_DEVICE_CAP_IGNORE_FUA) 170f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_IGNORE_FUA; 171f11c7f63SJim Harris 172f11c7f63SJim Harris if (identify->general_config_bits & ATA_IDENTIFY_REMOVABLE_MEDIA_ENABLE) 173f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_REMOVABLE_MEDIA; 174f11c7f63SJim Harris 175f11c7f63SJim Harris if(identify->command_set_supported2 & ATA_IDENTIFY_WRITE_UNCORRECTABLE_SUPPORT ) 176f11c7f63SJim Harris { 177f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_WRITE_UNCORRECTABLE_ENABLE; 178f11c7f63SJim Harris } 179f11c7f63SJim Harris 180f11c7f63SJim Harris if(identify->physical_logical_sector_info & 181f11c7f63SJim Harris ATA_IDENTIFY_LOGICAL_SECTOR_PER_PHYSICAL_SECTOR_ENABLE) 182f11c7f63SJim Harris { 183f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_MULTIPLE_SECTORS_PER_PHYSCIAL_SECTOR; 184f11c7f63SJim Harris } 185f11c7f63SJim Harris 186f11c7f63SJim Harris if(identify->command_set_supported_extention & 187f11c7f63SJim Harris ATA_IDENTIFY_COMMAND_SET_SMART_SELF_TEST_SUPPORTED) 188f11c7f63SJim Harris { 189f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_SMART_SELF_TEST_SUPPORT; 190f11c7f63SJim Harris } 191f11c7f63SJim Harris 192f11c7f63SJim Harris if (identify->nominal_media_rotation_rate == 1) 193f11c7f63SJim Harris { 194f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_SSD; 195f11c7f63SJim Harris } 196f11c7f63SJim Harris 197f11c7f63SJim Harris // Save off the logical block size reported by the drive 198f11c7f63SJim Harris // See if Word 106 is valid and reports a logical sector size 199f11c7f63SJim Harris if ((identify->physical_logical_sector_info & 0x5000) == 0x5000) 200f11c7f63SJim Harris { 201f11c7f63SJim Harris device->logical_block_size = (identify->words_per_logical_sector[3] << 24) | 202f11c7f63SJim Harris (identify->words_per_logical_sector[2] << 16) | 203f11c7f63SJim Harris (identify->words_per_logical_sector[1] << 8) | 204f11c7f63SJim Harris (identify->words_per_logical_sector[0]); 205f11c7f63SJim Harris } 206f11c7f63SJim Harris else 207f11c7f63SJim Harris { 208f11c7f63SJim Harris device->logical_block_size = 512; 209f11c7f63SJim Harris } 210f11c7f63SJim Harris 211f11c7f63SJim Harris // Determine DSM TRIM capabilities 212f11c7f63SJim Harris // Defend against SSDs which report TRIM support, but set 213f11c7f63SJim Harris // max_lba_range_entry_blocks to zero, by disabling TRIM for 214f11c7f63SJim Harris // those SSDs. 215f11c7f63SJim Harris if ( 216f11c7f63SJim Harris (identify->data_set_management & ATA_IDENTIFY_COMMAND_SET_DSM_TRIM_SUPPORTED) 217f11c7f63SJim Harris && (identify->max_lba_range_entry_blocks > 0) 218f11c7f63SJim Harris ) 219f11c7f63SJim Harris { 220f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_DSM_TRIM_SUPPORT; 221f11c7f63SJim Harris device->max_lba_range_entry_blocks = identify->max_lba_range_entry_blocks; 222f11c7f63SJim Harris } 223f11c7f63SJim Harris 224f11c7f63SJim Harris if (identify->additional_supported 225f11c7f63SJim Harris & ATA_IDENTIFY_COMMAND_ADDL_SUPPORTED_DETERMINISTIC_READ) 226f11c7f63SJim Harris { 227f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_DETERMINISTIC_READ_AFTER_TRIM; 228f11c7f63SJim Harris } 229f11c7f63SJim Harris 230f11c7f63SJim Harris if (identify->additional_supported 231f11c7f63SJim Harris & ATA_IDENTIFY_COMMAND_ADDL_SUPPORTED_READ_ZERO) 232f11c7f63SJim Harris { 233f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_READ_ZERO_AFTER_TRIM; 234f11c7f63SJim Harris } 235f11c7f63SJim Harris 236f11c7f63SJim Harris if (identify->capabilities1 237f11c7f63SJim Harris & ATA_IDENTIFY_CAPABILITIES1_STANDBY_ENABLE) 238f11c7f63SJim Harris { 239f11c7f63SJim Harris capabilities |= SATI_DEVICE_CAP_STANDBY_ENABLE; 240f11c7f63SJim Harris } 241f11c7f63SJim Harris 242f11c7f63SJim Harris device->min_blocks_per_microcode_command = identify->min_num_blocks_per_microcode; 243f11c7f63SJim Harris device->max_blocks_per_microcode_command = identify->max_num_blocks_per_microcode; 244f11c7f63SJim Harris 245f11c7f63SJim Harris device->capabilities = capabilities; 246f11c7f63SJim Harris } 247f11c7f63SJim Harris 248