Fri Nov 19 23:46:55 2021 UTC ()
ahcisata(4): Introduce AHCI_QUIRK_EXTRA_DELAY quirk for devices that
need extra delays as done by AHCISATA_EXTRA_DELAY option.

Enable this quirk for "C600/X79 AHCI". Also add commented out quirk
entries for "Bay Trail SATA (AHCI)" and "Mobile AHCI SATA Controller",
for which non-reproducible failures worked around by extra delays have
been reported.

500 ms of delays inserted by these option/quirk may be too much. Add
AHCISATA_EXTRA_DELAY_MS option to adjust number of delays in ms, like:

----
options 	AHCISATA_EXTRA_DELAY_MS=200
----

Thanks prlw1@ and jun@ for testing!


(rin)
diff -r1.1289 -r1.1290 src/sys/conf/files
diff -r1.104 -r1.105 src/sys/dev/ic/ahcisata_core.c
diff -r1.26 -r1.27 src/sys/dev/ic/ahcisatavar.h
diff -r1.60 -r1.61 src/sys/dev/pci/ahcisata_pci.c

cvs diff -r1.1289 -r1.1290 src/sys/conf/files (expand / switch to unified diff)

--- src/sys/conf/files 2021/10/11 13:42:33 1.1289
+++ src/sys/conf/files 2021/11/19 23:46:54 1.1290
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files,v 1.1289 2021/10/11 13:42:33 jmcneill Exp $ 1# $NetBSD: files,v 1.1290 2021/11/19 23:46:54 rin Exp $
2# @(#)files.newconf 7.5 (Berkeley) 5/10/93 2# @(#)files.newconf 7.5 (Berkeley) 5/10/93
3 3
4version 20171118 4version 20171118
5 5
6# 6#
7# device classes 7# device classes
8# 8#
9devclass disk 9devclass disk
10devclass tape 10devclass tape
11devclass ifnet 11devclass ifnet
12devclass tty 12devclass tty
13devclass audiodev 13devclass audiodev
14devclass displaydev 14devclass displaydev
@@ -1026,26 +1026,27 @@ defparam opt_ata.h ATADEBUG_MASK @@ -1026,26 +1026,27 @@ defparam opt_ata.h ATADEBUG_MASK
1026defflag opt_wdc.h WDC_NO_IDS 1026defflag opt_wdc.h WDC_NO_IDS
1027 1027
1028device atabus: atapi,ata_hl 1028device atabus: atapi,ata_hl
1029attach atabus at ata 1029attach atabus at ata
1030# The strange expression is to dump ata_* definitions to ata_dma.h. 1030# The strange expression is to dump ata_* definitions to ata_dma.h.
1031file dev/ic/wdc.c (ata_dma | ata_udma | ata_piobm | atabus) & atabus & wdc_common needs-flag 1031file dev/ic/wdc.c (ata_dma | ata_udma | ata_piobm | atabus) & atabus & wdc_common needs-flag
1032 1032
1033# Workbit NinjaATA-32 IDE controllers 1033# Workbit NinjaATA-32 IDE controllers
1034device njata: ata, ata_piobm, wdc_common 1034device njata: ata, ata_piobm, wdc_common
1035file dev/ic/ninjaata32.c njata 1035file dev/ic/ninjaata32.c njata
1036 1036
1037# AHCI-compatible SATA controllers 1037# AHCI-compatible SATA controllers
1038defflag opt_ahcisata.h AHCISATA_EXTRA_DELAY 1038defflag opt_ahcisata.h AHCISATA_EXTRA_DELAY
 1039defparam opt_ahcisata.h AHCISATA_EXTRA_DELAY_MS
1039define ahcisata_core 1040define ahcisata_core
1040file dev/ic/ahcisata_core.c ahcisata_core 1041file dev/ic/ahcisata_core.c ahcisata_core
1041device ahcisata: ata, ata_dma, ata_udma, sata, sata_fis, sata_pmp, ahcisata_core 1042device ahcisata: ata, ata_dma, ata_udma, sata, sata_fis, sata_pmp, ahcisata_core
1042 1043
1043# Silicon Image SteelVine SATA-II controllers 1044# Silicon Image SteelVine SATA-II controllers
1044define siisata 1045define siisata
1045file dev/ic/siisata.c siisata 1046file dev/ic/siisata.c siisata
1046device siisata: ata, ata_dma, ata_udma, sata, sata_fis, sata_pmp, siisata 1047device siisata: ata, ata_dma, ata_udma, sata, sata_fis, sata_pmp, siisata
1047 1048
1048# Marvell Serial-ATA Host Controller 1049# Marvell Serial-ATA Host Controller
1049define mvsata 1050define mvsata
1050file dev/ic/mvsata.c mvsata 1051file dev/ic/mvsata.c mvsata
1051device mvsata: ata, ata_dma, ata_udma, wdc_common, sata, sata_fis, sata_pmp, mvsata 1052device mvsata: ata, ata_dma, ata_udma, wdc_common, sata, sata_fis, sata_pmp, mvsata

cvs diff -r1.104 -r1.105 src/sys/dev/ic/ahcisata_core.c (expand / switch to unified diff)

--- src/sys/dev/ic/ahcisata_core.c 2021/11/10 17:19:30 1.104
+++ src/sys/dev/ic/ahcisata_core.c 2021/11/19 23:46:55 1.105
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ahcisata_core.c,v 1.104 2021/11/10 17:19:30 msaitoh Exp $ */ 1/* $NetBSD: ahcisata_core.c,v 1.105 2021/11/19 23:46:55 rin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * 25 *
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.104 2021/11/10 17:19:30 msaitoh Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.105 2021/11/19 23:46:55 rin Exp $");
30 30
31#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/malloc.h> 32#include <sys/malloc.h>
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/kernel.h> 34#include <sys/kernel.h>
35#include <sys/systm.h> 35#include <sys/systm.h>
36#include <sys/disklabel.h> 36#include <sys/disklabel.h>
37#include <sys/proc.h> 37#include <sys/proc.h>
38#include <sys/buf.h> 38#include <sys/buf.h>
39 39
40#include <dev/ata/atareg.h> 40#include <dev/ata/atareg.h>
41#include <dev/ata/satavar.h> 41#include <dev/ata/satavar.h>
42#include <dev/ata/satareg.h> 42#include <dev/ata/satareg.h>
@@ -105,26 +105,41 @@ static const struct scsipi_bustype ahci_ @@ -105,26 +105,41 @@ static const struct scsipi_bustype ahci_
105 .bustype_type = SCSIPI_BUSTYPE_ATAPI, 105 .bustype_type = SCSIPI_BUSTYPE_ATAPI,
106 .bustype_cmd = atapi_scsipi_cmd, 106 .bustype_cmd = atapi_scsipi_cmd,
107 .bustype_interpret_sense = atapi_interpret_sense, 107 .bustype_interpret_sense = atapi_interpret_sense,
108 .bustype_printaddr = atapi_print_addr, 108 .bustype_printaddr = atapi_print_addr,
109 .bustype_kill_pending = ahci_atapi_kill_pending, 109 .bustype_kill_pending = ahci_atapi_kill_pending,
110 .bustype_async_event_xfer_mode = NULL, 110 .bustype_async_event_xfer_mode = NULL,
111}; 111};
112#endif /* NATAPIBUS */ 112#endif /* NATAPIBUS */
113 113
114#define ATA_DELAY 10000 /* 10s for a drive I/O */ 114#define ATA_DELAY 10000 /* 10s for a drive I/O */
115#define ATA_RESET_DELAY 31000 /* 31s for a drive reset */ 115#define ATA_RESET_DELAY 31000 /* 31s for a drive reset */
116#define AHCI_RST_WAIT (ATA_RESET_DELAY / 10) 116#define AHCI_RST_WAIT (ATA_RESET_DELAY / 10)
117 117
 118#ifndef AHCISATA_EXTRA_DELAY_MS
 119#define AHCISATA_EXTRA_DELAY_MS 500 /* XXX need to adjust */
 120#endif
 121
 122#ifdef AHCISATA_EXTRA_DELAY
 123#define AHCISATA_DO_EXTRA_DELAY(sc, chp, msg, flags) \
 124 ata_delay(chp, AHCISATA_EXTRA_DELAY_MS, msg, flags)
 125#else
 126#define AHCISATA_DO_EXTRA_DELAY(sc, chp, msg, flags) \
 127 do { \
 128 if ((sc)->sc_ahci_quirks & AHCI_QUIRK_EXTRA_DELAY) \
 129 ata_delay(chp, AHCISATA_EXTRA_DELAY_MS, msg, flags); \
 130 } while (0)
 131#endif
 132
118const struct ata_bustype ahci_ata_bustype = { 133const struct ata_bustype ahci_ata_bustype = {
119 .bustype_type = SCSIPI_BUSTYPE_ATA, 134 .bustype_type = SCSIPI_BUSTYPE_ATA,
120 .ata_bio = ahci_ata_bio, 135 .ata_bio = ahci_ata_bio,
121 .ata_reset_drive = ahci_reset_drive, 136 .ata_reset_drive = ahci_reset_drive,
122 .ata_reset_channel = ahci_reset_channel, 137 .ata_reset_channel = ahci_reset_channel,
123 .ata_exec_command = ahci_exec_command, 138 .ata_exec_command = ahci_exec_command,
124 .ata_get_params = ata_get_params, 139 .ata_get_params = ata_get_params,
125 .ata_addref = ahci_ata_addref, 140 .ata_addref = ahci_ata_addref,
126 .ata_delref = ahci_ata_delref, 141 .ata_delref = ahci_ata_delref,
127 .ata_killpending = ahci_killpending, 142 .ata_killpending = ahci_killpending,
128 .ata_recovery = ahci_channel_recover, 143 .ata_recovery = ahci_channel_recover,
129}; 144};
130 145
@@ -960,55 +975,51 @@ again: @@ -960,55 +975,51 @@ again:
960 AHCINAME(sc), sig); 975 AHCINAME(sc), sig);
961 goto end; 976 goto end;
962 } 977 }
963 AHCIDEBUG_PRINT(("%s: BSY took %d ms\n", AHCINAME(sc), i * 10), 978 AHCIDEBUG_PRINT(("%s: BSY took %d ms\n", AHCINAME(sc), i * 10),
964 DEBUG_PROBE); 979 DEBUG_PROBE);
965 sig = AHCI_READ(sc, AHCI_P_SIG(chp->ch_channel)); 980 sig = AHCI_READ(sc, AHCI_P_SIG(chp->ch_channel));
966 if (sigp) 981 if (sigp)
967 *sigp = sig; 982 *sigp = sig;
968 AHCIDEBUG_PRINT(("%s: port %d: sig=0x%x CMD=0x%x\n", 983 AHCIDEBUG_PRINT(("%s: port %d: sig=0x%x CMD=0x%x\n",
969 AHCINAME(sc), chp->ch_channel, sig, 984 AHCINAME(sc), chp->ch_channel, sig,
970 AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))), DEBUG_PROBE); 985 AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))), DEBUG_PROBE);
971end: 986end:
972 ahci_channel_stop(sc, chp, flags); 987 ahci_channel_stop(sc, chp, flags);
973#ifdef AHCISATA_EXTRA_DELAY 988 AHCISATA_DO_EXTRA_DELAY(sc, chp, "ahcirst", flags);
974 ata_delay(chp, 500, "ahcirst", flags); 
975#endif 
976 /* clear port interrupt register */ 989 /* clear port interrupt register */
977 AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0xffffffff); 990 AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0xffffffff);
978 ahci_channel_start(sc, chp, flags, 991 ahci_channel_start(sc, chp, flags,
979 (sc->sc_ahci_cap & AHCI_CAP_CLO) ? 1 : 0); 992 (sc->sc_ahci_cap & AHCI_CAP_CLO) ? 1 : 0);
980 return error; 993 return error;
981} 994}
982 995
983static void 996static void
984ahci_reset_channel(struct ata_channel *chp, int flags) 997ahci_reset_channel(struct ata_channel *chp, int flags)
985{ 998{
986 struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac; 999 struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
987 struct ahci_channel *achp = (struct ahci_channel *)chp; 1000 struct ahci_channel *achp = (struct ahci_channel *)chp;
988 int i, tfd; 1001 int i, tfd;
989 1002
990 ata_channel_lock_owned(chp); 1003 ata_channel_lock_owned(chp);
991 1004
992 ahci_channel_stop(sc, chp, flags); 1005 ahci_channel_stop(sc, chp, flags);
993 if (sata_reset_interface(chp, sc->sc_ahcit, achp->ahcic_scontrol, 1006 if (sata_reset_interface(chp, sc->sc_ahcit, achp->ahcic_scontrol,
994 achp->ahcic_sstatus, flags) != SStatus_DET_DEV) { 1007 achp->ahcic_sstatus, flags) != SStatus_DET_DEV) {
995 printf("%s: port %d reset failed\n", AHCINAME(sc), chp->ch_channel); 1008 printf("%s: port %d reset failed\n", AHCINAME(sc), chp->ch_channel);
996 /* XXX and then ? */ 1009 /* XXX and then ? */
997 } 1010 }
998 ata_kill_active(chp, KILL_RESET, flags); 1011 ata_kill_active(chp, KILL_RESET, flags);
999#ifdef AHCISATA_EXTRA_DELAY 1012 AHCISATA_DO_EXTRA_DELAY(sc, chp, "ahcirst", flags);
1000 ata_delay(chp, 500, "ahcirst", flags); 
1001#endif 
1002 /* clear port interrupt register */ 1013 /* clear port interrupt register */
1003 AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0xffffffff); 1014 AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0xffffffff);
1004 /* clear SErrors and start operations */ 1015 /* clear SErrors and start operations */
1005 ahci_channel_start(sc, chp, flags, 1016 ahci_channel_start(sc, chp, flags,
1006 (sc->sc_ahci_cap & AHCI_CAP_CLO) ? 1 : 0); 1017 (sc->sc_ahci_cap & AHCI_CAP_CLO) ? 1 : 0);
1007 /* wait 31s for BSY to clear */ 1018 /* wait 31s for BSY to clear */
1008 for (i = 0; i < AHCI_RST_WAIT; i++) { 1019 for (i = 0; i < AHCI_RST_WAIT; i++) {
1009 tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel)); 1020 tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
1010 if ((AHCI_TFD_ST(tfd) & WDCS_BSY) == 0) 1021 if ((AHCI_TFD_ST(tfd) & WDCS_BSY) == 0)
1011 break; 1022 break;
1012 ata_delay(chp, 10, "ahcid2h", flags); 1023 ata_delay(chp, 10, "ahcid2h", flags);
1013 } 1024 }
1014 if ((AHCI_TFD_ST(tfd) & WDCS_BSY) != 0) 1025 if ((AHCI_TFD_ST(tfd) & WDCS_BSY) != 0)
@@ -1058,29 +1069,27 @@ ahci_probe_drive(struct ata_channel *chp @@ -1058,29 +1069,27 @@ ahci_probe_drive(struct ata_channel *chp
1058 __func__, chp->ch_channel); 1069 __func__, chp->ch_channel);
1059 ata_channel_unlock(chp); 1070 ata_channel_unlock(chp);
1060 return; 1071 return;
1061 } 1072 }
1062 1073
1063 /* bring interface up, accept FISs, power up and spin up device */ 1074 /* bring interface up, accept FISs, power up and spin up device */
1064 AHCI_WRITE(sc, AHCI_P_CMD(chp->ch_channel), 1075 AHCI_WRITE(sc, AHCI_P_CMD(chp->ch_channel),
1065 AHCI_P_CMD_ICC_AC | AHCI_P_CMD_FRE | 1076 AHCI_P_CMD_ICC_AC | AHCI_P_CMD_FRE |
1066 AHCI_P_CMD_POD | AHCI_P_CMD_SUD); 1077 AHCI_P_CMD_POD | AHCI_P_CMD_SUD);
1067 /* reset the PHY and bring online */ 1078 /* reset the PHY and bring online */
1068 switch (sata_reset_interface(chp, sc->sc_ahcit, achp->ahcic_scontrol, 1079 switch (sata_reset_interface(chp, sc->sc_ahcit, achp->ahcic_scontrol,
1069 achp->ahcic_sstatus, AT_WAIT)) { 1080 achp->ahcic_sstatus, AT_WAIT)) {
1070 case SStatus_DET_DEV: 1081 case SStatus_DET_DEV:
1071#ifdef AHCISATA_EXTRA_DELAY 1082 AHCISATA_DO_EXTRA_DELAY(sc, chp, "ahcidv", AT_WAIT);
1072 ata_delay(chp, 500, "ahcidv", AT_WAIT); 
1073#endif 
1074 1083
1075 /* Initial value, used in case the soft reset fails */ 1084 /* Initial value, used in case the soft reset fails */
1076 sig = AHCI_READ(sc, AHCI_P_SIG(chp->ch_channel)); 1085 sig = AHCI_READ(sc, AHCI_P_SIG(chp->ch_channel));
1077 1086
1078 if (sc->sc_ahci_cap & AHCI_CAP_SPM) { 1087 if (sc->sc_ahci_cap & AHCI_CAP_SPM) {
1079 error = ahci_do_reset_drive(chp, PMP_PORT_CTL, AT_WAIT, 1088 error = ahci_do_reset_drive(chp, PMP_PORT_CTL, AT_WAIT,
1080 &sig, c_slot); 1089 &sig, c_slot);
1081 1090
1082 /* If probe for PMP failed, just fallback to drive 0 */ 1091 /* If probe for PMP failed, just fallback to drive 0 */
1083 if (error) { 1092 if (error) {
1084 aprint_error("%s port %d: drive %d reset " 1093 aprint_error("%s port %d: drive %d reset "
1085 "failed, disabling PMP\n", 1094 "failed, disabling PMP\n",
1086 AHCINAME(sc), chp->ch_channel, 1095 AHCINAME(sc), chp->ch_channel,
@@ -1099,30 +1108,31 @@ ahci_probe_drive(struct ata_channel *chp @@ -1099,30 +1108,31 @@ ahci_probe_drive(struct ata_channel *chp
1099 AHCI_WRITE(sc, AHCI_P_CMD(chp->ch_channel), 1108 AHCI_WRITE(sc, AHCI_P_CMD(chp->ch_channel),
1100 AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)) | 1109 AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)) |
1101 AHCI_P_CMD_PMA); 1110 AHCI_P_CMD_PMA);
1102 } 1111 }
1103 /* clear port interrupt register */ 1112 /* clear port interrupt register */
1104 AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0xffffffff); 1113 AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0xffffffff);
1105 1114
1106 /* and enable interrupts */ 1115 /* and enable interrupts */
1107 AHCI_WRITE(sc, AHCI_P_IE(chp->ch_channel), 1116 AHCI_WRITE(sc, AHCI_P_IE(chp->ch_channel),
1108 AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_HBDS | 1117 AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_HBDS |
1109 AHCI_P_IX_IFS | 1118 AHCI_P_IX_IFS |
1110 AHCI_P_IX_OFS | AHCI_P_IX_DPS | AHCI_P_IX_UFS | 1119 AHCI_P_IX_OFS | AHCI_P_IX_DPS | AHCI_P_IX_UFS |
1111 AHCI_P_IX_PSS | AHCI_P_IX_DHRS | AHCI_P_IX_SDBS); 1120 AHCI_P_IX_PSS | AHCI_P_IX_DHRS | AHCI_P_IX_SDBS);
1112#ifdef AHCISATA_EXTRA_DELAY 1121 /*
1113 /* wait 500ms before actually starting operations */ 1122 * optionally, wait AHCISATA_EXTRA_DELAY_MS msec before
1114 ata_delay(chp, 500, "ahciprb", AT_WAIT); 1123 * actually starting operations
1115#endif 1124 */
 1125 AHCISATA_DO_EXTRA_DELAY(sc, chp, "ahciprb", AT_WAIT);
1116 break; 1126 break;
1117 1127
1118 default: 1128 default:
1119 break; 1129 break;
1120 } 1130 }
1121 1131
1122 ata_queue_free_slot(chp, c_slot); 1132 ata_queue_free_slot(chp, c_slot);
1123 1133
1124 ata_channel_unlock(chp); 1134 ata_channel_unlock(chp);
1125} 1135}
1126 1136
1127static void 1137static void
1128ahci_setup_channel(struct ata_channel *chp) 1138ahci_setup_channel(struct ata_channel *chp)

cvs diff -r1.26 -r1.27 src/sys/dev/ic/ahcisatavar.h (expand / switch to unified diff)

--- src/sys/dev/ic/ahcisatavar.h 2020/12/28 14:08:42 1.26
+++ src/sys/dev/ic/ahcisatavar.h 2021/11/19 23:46:55 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ahcisatavar.h,v 1.26 2020/12/28 14:08:42 jmcneill Exp $ */ 1/* $NetBSD: ahcisatavar.h,v 1.27 2021/11/19 23:46:55 rin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -49,26 +49,27 @@ struct ahci_softc { @@ -49,26 +49,27 @@ struct ahci_softc {
49 bus_space_handle_t sc_ahcih; 49 bus_space_handle_t sc_ahcih;
50 bus_size_t sc_ahcis; 50 bus_size_t sc_ahcis;
51 bus_dma_tag_t sc_dmat; /* DMA memory mappings: */ 51 bus_dma_tag_t sc_dmat; /* DMA memory mappings: */
52 void *sc_cmd_hdr; /* command tables and received FIS */ 52 void *sc_cmd_hdr; /* command tables and received FIS */
53 bus_dmamap_t sc_cmd_hdrd; 53 bus_dmamap_t sc_cmd_hdrd;
54 bus_dma_segment_t sc_cmd_hdr_seg; 54 bus_dma_segment_t sc_cmd_hdr_seg;
55 int sc_cmd_hdr_nseg; 55 int sc_cmd_hdr_nseg;
56 int sc_atac_capflags; 56 int sc_atac_capflags;
57 int sc_ahci_quirks; 57 int sc_ahci_quirks;
58#define AHCI_PCI_QUIRK_FORCE __BIT(0) /* force attach */ 58#define AHCI_PCI_QUIRK_FORCE __BIT(0) /* force attach */
59#define AHCI_PCI_QUIRK_BAD64 __BIT(1) /* broken 64-bit DMA */ 59#define AHCI_PCI_QUIRK_BAD64 __BIT(1) /* broken 64-bit DMA */
60#define AHCI_QUIRK_BADPMP __BIT(2) /* broken PMP support, ignore */ 60#define AHCI_QUIRK_BADPMP __BIT(2) /* broken PMP support, ignore */
61#define AHCI_QUIRK_BADNCQ __BIT(3) /* possibly broken NCQ support, ignore */ 61#define AHCI_QUIRK_BADNCQ __BIT(3) /* possibly broken NCQ support, ignore */
 62#define AHCI_QUIRK_EXTRA_DELAY __BIT(4) /* needs extra delay */
62 63
63 uint32_t sc_ahci_cap; /* copy of AHCI_CAP */ 64 uint32_t sc_ahci_cap; /* copy of AHCI_CAP */
64 int sc_ncmds; /* number of command slots */ 65 int sc_ncmds; /* number of command slots */
65 uint32_t sc_ahci_ports; 66 uint32_t sc_ahci_ports;
66 struct ata_channel *sc_chanarray[AHCI_MAX_PORTS]; 67 struct ata_channel *sc_chanarray[AHCI_MAX_PORTS];
67 struct ahci_channel { 68 struct ahci_channel {
68 struct ata_channel ata_channel; /* generic part */ 69 struct ata_channel ata_channel; /* generic part */
69 bus_space_handle_t ahcic_scontrol; 70 bus_space_handle_t ahcic_scontrol;
70 bus_space_handle_t ahcic_sstatus; 71 bus_space_handle_t ahcic_sstatus;
71 bus_space_handle_t ahcic_serror; 72 bus_space_handle_t ahcic_serror;
72 /* pointers allocated from sc_cmd_hdrd */ 73 /* pointers allocated from sc_cmd_hdrd */
73 struct ahci_r_fis *ahcic_rfis; /* received FIS */ 74 struct ahci_r_fis *ahcic_rfis; /* received FIS */
74 bus_addr_t ahcic_bus_rfis; 75 bus_addr_t ahcic_bus_rfis;

cvs diff -r1.60 -r1.61 src/sys/dev/pci/ahcisata_pci.c (expand / switch to unified diff)

--- src/sys/dev/pci/ahcisata_pci.c 2021/11/12 07:06:06 1.60
+++ src/sys/dev/pci/ahcisata_pci.c 2021/11/19 23:46:55 1.61
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ahcisata_pci.c,v 1.60 2021/11/12 07:06:06 skrll Exp $ */ 1/* $NetBSD: ahcisata_pci.c,v 1.61 2021/11/19 23:46:55 rin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * 25 *
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: ahcisata_pci.c,v 1.60 2021/11/12 07:06:06 skrll Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: ahcisata_pci.c,v 1.61 2021/11/19 23:46:55 rin Exp $");
30 30
31#ifdef _KERNEL_OPT 31#ifdef _KERNEL_OPT
32#include "opt_ahcisata_pci.h" 32#include "opt_ahcisata_pci.h"
33#endif 33#endif
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/kmem.h> 36#include <sys/kmem.h>
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/kernel.h> 38#include <sys/kernel.h>
39#include <sys/systm.h> 39#include <sys/systm.h>
40#include <sys/disklabel.h> 40#include <sys/disklabel.h>
41#include <sys/pmf.h> 41#include <sys/pmf.h>
42 42
@@ -194,26 +194,45 @@ static const struct ahci_pci_quirk ahci_ @@ -194,26 +194,45 @@ static const struct ahci_pci_quirk ahci_
194 AHCI_PCI_QUIRK_FORCE }, 194 AHCI_PCI_QUIRK_FORCE },
195 { PCI_VENDOR_ASMEDIA, PCI_PRODUCT_ASMEDIA_ASM1061_02, 195 { PCI_VENDOR_ASMEDIA, PCI_PRODUCT_ASMEDIA_ASM1061_02,
196 AHCI_PCI_QUIRK_FORCE }, 196 AHCI_PCI_QUIRK_FORCE },
197 { PCI_VENDOR_ASMEDIA, PCI_PRODUCT_ASMEDIA_ASM1061_11, 197 { PCI_VENDOR_ASMEDIA, PCI_PRODUCT_ASMEDIA_ASM1061_11,
198 AHCI_PCI_QUIRK_FORCE }, 198 AHCI_PCI_QUIRK_FORCE },
199 { PCI_VENDOR_ASMEDIA, PCI_PRODUCT_ASMEDIA_ASM1061_12, 199 { PCI_VENDOR_ASMEDIA, PCI_PRODUCT_ASMEDIA_ASM1061_12,
200 AHCI_PCI_QUIRK_FORCE }, 200 AHCI_PCI_QUIRK_FORCE },
201 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_HUDSON_SATA, 201 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_HUDSON_SATA,
202 AHCI_PCI_QUIRK_FORCE }, 202 AHCI_PCI_QUIRK_FORCE },
203 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_HUDSON_SATA_AHCI, 203 { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_HUDSON_SATA_AHCI,
204 AHCI_QUIRK_BADPMP }, 204 AHCI_QUIRK_BADPMP },
205 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801JI_SATA_AHCI, 205 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801JI_SATA_AHCI,
206 AHCI_QUIRK_BADPMP }, 206 AHCI_QUIRK_BADPMP },
 207 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_C600_AHCI,
 208 AHCI_QUIRK_EXTRA_DELAY },
 209#if 0
 210 /*
 211 * XXX Non-reproducible failures reported. May need extra-delay quirk.
 212 */
 213 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_BAYTRAIL_SATA_AHCI_0,
 214 AHCI_QUIRK_EXTRA_DELAY },
 215 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_BAYTRAIL_SATA_AHCI_1,
 216 AHCI_QUIRK_EXTRA_DELAY },
 217 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801I_SATA_4,
 218 AHCI_QUIRK_EXTRA_DELAY },
 219 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801I_SATA_5,
 220 AHCI_QUIRK_EXTRA_DELAY },
 221 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801I_SATA_6,
 222 AHCI_QUIRK_EXTRA_DELAY },
 223 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801I_SATA_7,
 224 AHCI_QUIRK_EXTRA_DELAY },
 225#endif
207}; 226};
208 227
209struct ahci_pci_softc { 228struct ahci_pci_softc {
210 struct ahci_softc ah_sc; 229 struct ahci_softc ah_sc;
211 pci_chipset_tag_t sc_pc; 230 pci_chipset_tag_t sc_pc;
212 pcitag_t sc_pcitag; 231 pcitag_t sc_pcitag;
213 pci_intr_handle_t *sc_pihp; 232 pci_intr_handle_t *sc_pihp;
214 int sc_nintr; 233 int sc_nintr;
215 void **sc_ih; 234 void **sc_ih;
216}; 235};
217 236
218static int ahci_pci_has_quirk(pci_vendor_id_t, pci_product_id_t); 237static int ahci_pci_has_quirk(pci_vendor_id_t, pci_product_id_t);
219static int ahci_pci_match(device_t, cfdata_t, void *); 238static int ahci_pci_match(device_t, cfdata_t, void *);