[Midnightbsd-cvs] src [12117] trunk: Introduce the ability to disable TRIM support on some drives with buggy firmwares.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Nov 9 13:25:12 EST 2018
Revision: 12117
http://svnweb.midnightbsd.org/src/?rev=12117
Author: laffer1
Date: 2018-11-09 13:25:11 -0500 (Fri, 09 Nov 2018)
Log Message:
-----------
Introduce the ability to disable TRIM support on some drives with buggy firmwares.
Modified Paths:
--------------
trunk/sbin/camcontrol/camcontrol.c
trunk/sys/cam/ata/ata_da.c
trunk/sys/cam/cam_ccb.h
trunk/sys/dev/ahci/ahci.c
trunk/sys/dev/ahci/ahci.h
trunk/sys/dev/ahci/ahci_pci.c
trunk/sys/dev/siis/siis.c
Modified: trunk/sbin/camcontrol/camcontrol.c
===================================================================
--- trunk/sbin/camcontrol/camcontrol.c 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sbin/camcontrol/camcontrol.c 2018-11-09 18:25:11 UTC (rev 12117)
@@ -5311,6 +5311,12 @@
fprintf(stdout, "%s ", adapter_str);
switch(i) {
+ case PIM_ATA_EXT:
+ str = "can understand ata_ext requests";
+ break;
+ case PIM_EXTLUNS:
+ str = "64bit extended LUNs supported";
+ break;
case PIM_SCANHILO:
str = "bus scans from high ID to low ID";
break;
@@ -5330,6 +5336,12 @@
case PIM_SEQSCAN:
str = "scan bus sequentially";
break;
+ case PIM_UNMAPPED:
+ str = "unmapped I/O supported";
+ break;
+ case PIM_NOSCAN:
+ str = "does its own scanning";
+ break;
default:
str = "unknown PIM bit set";
break;
Modified: trunk/sys/cam/ata/ata_da.c
===================================================================
--- trunk/sys/cam/ata/ata_da.c 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sys/cam/ata/ata_da.c 2018-11-09 18:25:11 UTC (rev 12117)
@@ -76,24 +76,35 @@
} ada_state;
typedef enum {
- ADA_FLAG_CAN_48BIT = 0x0002,
- ADA_FLAG_CAN_FLUSHCACHE = 0x0004,
- ADA_FLAG_CAN_NCQ = 0x0008,
- ADA_FLAG_CAN_DMA = 0x0010,
- ADA_FLAG_NEED_OTAG = 0x0020,
- ADA_FLAG_WAS_OTAG = 0x0040,
- ADA_FLAG_CAN_TRIM = 0x0080,
- ADA_FLAG_OPEN = 0x0100,
- ADA_FLAG_SCTX_INIT = 0x0200,
- ADA_FLAG_CAN_CFA = 0x0400,
- ADA_FLAG_CAN_POWERMGT = 0x0800,
- ADA_FLAG_CAN_DMA48 = 0x1000,
- ADA_FLAG_DIRTY = 0x2000
+ ADA_FLAG_CAN_48BIT = 0x00000002,
+ ADA_FLAG_CAN_FLUSHCACHE = 0x00000004,
+ ADA_FLAG_CAN_NCQ = 0x00000008,
+ ADA_FLAG_CAN_DMA = 0x00000010,
+ ADA_FLAG_NEED_OTAG = 0x00000020,
+ ADA_FLAG_WAS_OTAG = 0x00000040,
+ ADA_FLAG_CAN_TRIM = 0x00000080,
+ ADA_FLAG_OPEN = 0x00000100,
+ ADA_FLAG_SCTX_INIT = 0x00000200,
+ ADA_FLAG_CAN_CFA = 0x00000400,
+ ADA_FLAG_CAN_POWERMGT = 0x00000800,
+ ADA_FLAG_CAN_DMA48 = 0x00001000,
+ ADA_FLAG_CAN_LOG = 0x00002000,
+ ADA_FLAG_CAN_IDLOG = 0x00004000,
+ ADA_FLAG_CAN_SUPCAP = 0x00008000,
+ ADA_FLAG_CAN_ZONE = 0x00010000,
+ ADA_FLAG_CAN_WCACHE = 0x00020000,
+ ADA_FLAG_CAN_RAHEAD = 0x00040000,
+ ADA_FLAG_PROBED = 0x00080000,
+ ADA_FLAG_ANNOUNCED = 0x00100000,
+ ADA_FLAG_DIRTY = 0x00200000,
+ ADA_FLAG_CAN_NCQ_TRIM = 0x00400000, /* CAN_TRIM also set */
+ ADA_FLAG_PIM_ATA_EXT = 0x00800000
} ada_flags;
typedef enum {
ADA_Q_NONE = 0x00,
ADA_Q_4K = 0x01,
+ ADA_Q_NCQ_TRIM_BROKEN = 0x02,
} ada_quirks;
#define ADA_Q_BIT_STRING \
@@ -1192,18 +1203,30 @@
if ((cgd->ident_data.capabilities1 & ATA_SUPPORT_DMA) &&
(cgd->inq_flags & SID_DMA))
softc->flags |= ADA_FLAG_CAN_DMA;
+ else
+ softc->flags &= ~ADA_FLAG_CAN_DMA;
+
if (cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) {
softc->flags |= ADA_FLAG_CAN_48BIT;
if (cgd->inq_flags & SID_DMA48)
softc->flags |= ADA_FLAG_CAN_DMA48;
- }
+ else
+ softc->flags &= ~ADA_FLAG_CAN_DMA48;
+ } else
+ softc->flags &= ~(ADA_FLAG_CAN_48BIT | ADA_FLAG_CAN_DMA48);
if (cgd->ident_data.support.command2 & ATA_SUPPORT_FLUSHCACHE)
softc->flags |= ADA_FLAG_CAN_FLUSHCACHE;
+ else
+ softc->flags &= ~ADA_FLAG_CAN_FLUSHCACHE;
if (cgd->ident_data.support.command1 & ATA_SUPPORT_POWERMGT)
softc->flags |= ADA_FLAG_CAN_POWERMGT;
+ else
+ softc->flags &= ~ADA_FLAG_CAN_POWERMGT;
if ((cgd->ident_data.satacapabilities & ATA_SUPPORT_NCQ) &&
(cgd->inq_flags & SID_DMA) && (cgd->inq_flags & SID_CmdQue))
softc->flags |= ADA_FLAG_CAN_NCQ;
+ else
+ softc->flags &= ~ADA_FLAG_CAN_NCQ;
if ((cgd->ident_data.support_dsm & ATA_SUPPORT_DSM_TRIM) &&
(cgd->inq_flags & SID_DMA)) {
softc->flags |= ADA_FLAG_CAN_TRIM;
@@ -1213,9 +1236,27 @@
min(cgd->ident_data.max_dsm_blocks *
ATA_DSM_BLK_RANGES, softc->trim_max_ranges);
}
- }
+/*
+ * If we can do RCVSND_FPDMA_QUEUED commands, we may be able
+ * to do NCQ trims, if we support trims at all. We also need
+ * support from the SIM to do things properly. Perhaps we
+ * should look at log 13 dword 0 bit 0 and dword 1 bit 0 are
+ * set too...
+ */
+ if ((softc->quirks & ADA_Q_NCQ_TRIM_BROKEN) == 0 &&
+ (softc->flags & ADA_FLAG_PIM_ATA_EXT) != 0 &&
+ (cgd->ident_data.satacapabilities2 &
+ ATA_SUPPORT_RCVSND_FPDMA_QUEUED) != 0 &&
+ (softc->flags & ADA_FLAG_CAN_TRIM) != 0)
+ softc->flags |= ADA_FLAG_CAN_NCQ_TRIM;
+ else
+ softc->flags &= ~ADA_FLAG_CAN_NCQ_TRIM;
+ } else
+ softc->flags &= ~(ADA_FLAG_CAN_TRIM | ADA_FLAG_CAN_NCQ_TRIM);
if (cgd->ident_data.support.command2 & ATA_SUPPORT_CFA)
softc->flags |= ADA_FLAG_CAN_CFA;
+ else
+ softc->flags &= ~ADA_FLAG_CAN_CFA;
periph->softc = softc;
@@ -1305,6 +1346,8 @@
softc->disk->d_delmaxsize = maxio;
if ((cpi.hba_misc & PIM_UNMAPPED) != 0)
softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
+ if (cpi.hba_misc & PIM_ATA_EXT)
+ softc->flags |= ADA_FLAG_PIM_ATA_EXT;
strlcpy(softc->disk->d_descr, cgd->ident_data.model,
MIN(sizeof(softc->disk->d_descr), sizeof(cgd->ident_data.model)));
strlcpy(softc->disk->d_ident, cgd->ident_data.serial,
Modified: trunk/sys/cam/cam_ccb.h
===================================================================
--- trunk/sys/cam/cam_ccb.h 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sys/cam/cam_ccb.h 2018-11-09 18:25:11 UTC (rev 12117)
@@ -584,6 +584,7 @@
} pi_tmflag;
typedef enum {
+ PIM_ATA_EXT = 0x200,/* ATA requests can understand ata_ext requests */
PIM_EXTLUNS = 0x100,/* 64bit extended LUNs supported */
PIM_SCANHILO = 0x80, /* Bus scans from high ID to low ID */
PIM_NOREMOVE = 0x40, /* Removeable devices not included in scan */
Modified: trunk/sys/dev/ahci/ahci.c
===================================================================
--- trunk/sys/dev/ahci/ahci.c 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sys/dev/ahci/ahci.c 2018-11-09 18:25:11 UTC (rev 12117)
@@ -2629,6 +2629,8 @@
cpi->hba_inquiry |= PI_SATAPM;
cpi->target_sprt = 0;
cpi->hba_misc = PIM_SEQSCAN | PIM_UNMAPPED;
+ if ((ch->quirks & AHCI_Q_NOAUX) == 0)
+ cpi->hba_misc |= PIM_ATA_EXT;
cpi->hba_eng_cnt = 0;
if (ch->caps & AHCI_CAP_SPM)
cpi->max_target = 15;
@@ -2638,7 +2640,7 @@
cpi->initiator_id = 0;
cpi->bus_id = cam_sim_bus(sim);
cpi->base_transfer_speed = 150000;
- strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+ strlcpy(cpi->sim_vid, "MidnightBSD", SIM_IDLEN);
strlcpy(cpi->hba_vid, "AHCI", HBA_IDLEN);
strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
cpi->unit_number = cam_sim_unit(sim);
Modified: trunk/sys/dev/ahci/ahci.h
===================================================================
--- trunk/sys/dev/ahci/ahci.h 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sys/dev/ahci/ahci.h 2018-11-09 18:25:11 UTC (rev 12117)
@@ -575,7 +575,12 @@
#define AHCI_Q_SATA1_UNIT0 0x00008000 /* need better method for this */
#define AHCI_Q_ABAR0 0x00010000
#define AHCI_Q_1MSI 0x00020000
+#define AHCI_Q_FORCE_PI 0x00040000
+#define AHCI_Q_RESTORE_CAP 0x00080000
+#define AHCI_Q_NOMSIX 0x00100000
+#define AHCI_Q_MRVL_SR_DEL 0x00200000
#define AHCI_Q_NOCCS 0x00400000
+#define AHCI_Q_NOAUX 0x00800000
#define AHCI_Q_BIT_STRING \
"\020" \
@@ -597,7 +602,8 @@
"\020SATA1_UNIT0" \
"\021ABAR0" \
"\0221MSI" \
- "\027NOCCS"
+ "\027NOCCS" \
+ "\030NOAUX"
int ahci_attach(device_t dev);
int ahci_detach(device_t dev);
Modified: trunk/sys/dev/ahci/ahci_pci.c
===================================================================
--- trunk/sys/dev/ahci/ahci_pci.c 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sys/dev/ahci/ahci_pci.c 2018-11-09 18:25:11 UTC (rev 12117)
@@ -77,15 +77,15 @@
{0x78021022, 0x00, "AMD Hudson-2", 0},
{0x78031022, 0x00, "AMD Hudson-2", 0},
{0x78041022, 0x00, "AMD Hudson-2", 0},
- {0x06011b21, 0x00, "ASMedia ASM1060", AHCI_Q_NOCCS},
- {0x06021b21, 0x00, "ASMedia ASM1060", AHCI_Q_NOCCS},
- {0x06111b21, 0x00, "ASMedia ASM1061", AHCI_Q_NOCCS},
- {0x06121b21, 0x00, "ASMedia ASM1062", AHCI_Q_NOCCS},
- {0x06201b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS},
- {0x06211b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS},
- {0x06221b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS},
- {0x06241b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS},
- {0x06251b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS},
+ {0x06011b21, 0x00, "ASMedia ASM1060", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06021b21, 0x00, "ASMedia ASM1060", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06111b21, 0x00, "ASMedia ASM1061", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06121b21, 0x00, "ASMedia ASM1062", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06201b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06211b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06221b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06241b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
+ {0x06251b21, 0x00, "ASMedia ASM106x", AHCI_Q_NOCCS|AHCI_Q_NOAUX},
{0x26528086, 0x00, "Intel ICH6", AHCI_Q_NOFORCE},
{0x26538086, 0x00, "Intel ICH6M", AHCI_Q_NOFORCE},
{0x26818086, 0x00, "Intel ESB2", 0},
@@ -325,6 +325,8 @@
{0x11841039, 0x00, "SiS 966", 0},
{0x11851039, 0x00, "SiS 968", 0},
{0x01861039, 0x00, "SiS 968", 0},
+ {0x00311c36, 0x00, "Annapurna", AHCI_Q_FORCE_PI|AHCI_Q_RESTORE_CAP|AHCI_Q_NOMSIX},
+ {0x1600144d, 0x00, "Samsung", AHCI_Q_NOMSI},
{0xa01c177d, 0x00, "ThunderX", AHCI_Q_ABAR0|AHCI_Q_1MSI},
{0x00000000, 0x00, NULL, 0}
};
Modified: trunk/sys/dev/siis/siis.c
===================================================================
--- trunk/sys/dev/siis/siis.c 2018-11-04 20:51:49 UTC (rev 12116)
+++ trunk/sys/dev/siis/siis.c 2018-11-09 18:25:11 UTC (rev 12117)
@@ -1946,7 +1946,7 @@
cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE;
cpi->hba_inquiry |= PI_SATAPM;
cpi->target_sprt = 0;
- cpi->hba_misc = PIM_SEQSCAN | PIM_UNMAPPED;
+ cpi->hba_misc = PIM_SEQSCAN | PIM_UNMAPPED | PIM_ATA_EXT;
cpi->hba_eng_cnt = 0;
cpi->max_target = 15;
cpi->max_lun = 0;
@@ -1953,7 +1953,7 @@
cpi->initiator_id = 0;
cpi->bus_id = cam_sim_bus(sim);
cpi->base_transfer_speed = 150000;
- strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+ strlcpy(cpi->sim_vid, "MidnightBSD", SIM_IDLEN);
strlcpy(cpi->hba_vid, "SIIS", HBA_IDLEN);
strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
cpi->unit_number = cam_sim_unit(sim);
More information about the Midnightbsd-cvs
mailing list