svn commit: r312767 - head/sys/dev/ahci

Alexander Motin mav at FreeBSD.org
Wed Jan 25 18:16:18 UTC 2017


Author: mav
Date: Wed Jan 25 18:16:17 2017
New Revision: 312767
URL: https://svnweb.freebsd.org/changeset/base/312767

Log:
  Partially workaround ASMedia HBA error recovery.
  
  Taking closer look on my ASM1062 I found that it has bunch of issues around
  error recovery: reported wrong CCS, failed commands reported as completed,
  READ LOG EXT times out after NCQ error.  This patch workarounds first two
  problems, that were making ATAPI devices close to unusable on these HBAs.
  
  MFC after:	2 weeks

Modified:
  head/sys/dev/ahci/ahci.c
  head/sys/dev/ahci/ahci.h
  head/sys/dev/ahci/ahci_pci.c

Modified: head/sys/dev/ahci/ahci.c
==============================================================================
--- head/sys/dev/ahci/ahci.c	Wed Jan 25 18:07:27 2017	(r312766)
+++ head/sys/dev/ahci/ahci.c	Wed Jan 25 18:16:17 2017	(r312767)
@@ -758,7 +758,7 @@ ahci_ch_attach(device_t dev)
 	/* Construct SIM entry */
 	ch->sim = cam_sim_alloc(ahciaction, ahcipoll, "ahcich", ch,
 	    device_get_unit(dev), (struct mtx *)&ch->mtx,
-	    min(2, ch->numslots),
+	    (ch->quirks & AHCI_Q_NOCCS) ? 1 : min(2, ch->numslots),
 	    (ch->caps & AHCI_CAP_SNCQ) ? ch->numslots : 0,
 	    devq);
 	if (ch->sim == NULL) {
@@ -1271,8 +1271,19 @@ ahci_ch_intr_main(struct ahci_channel *c
 	/* Process command errors */
 	if (istatus & (AHCI_P_IX_OF | AHCI_P_IX_IF |
 	    AHCI_P_IX_HBD | AHCI_P_IX_HBF | AHCI_P_IX_TFE)) {
-		ccs = (ATA_INL(ch->r_mem, AHCI_P_CMD) & AHCI_P_CMD_CCS_MASK)
-		    >> AHCI_P_CMD_CCS_SHIFT;
+		if (ch->quirks & AHCI_Q_NOCCS) {
+			/*
+			 * ASMedia chips sometimes report failed commands as
+			 * completed.  Count all running commands as failed.
+			 */
+			cstatus |= ch->rslots;
+
+			/* They also report wrong CCS, so try to guess one. */
+			ccs = powerof2(cstatus) ? ffs(cstatus) - 1 : -1;
+		} else {
+			ccs = (ATA_INL(ch->r_mem, AHCI_P_CMD) &
+			    AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
+		}
 //device_printf(dev, "%s ERROR is %08x cs %08x ss %08x rs %08x tfd %02x serr %08x fbs %08x ccs %d\n",
 //    __func__, istatus, cstatus, sstatus, ch->rslots, ATA_INL(ch->r_mem, AHCI_P_TFD),
 //    serr, ATA_INL(ch->r_mem, AHCI_P_FBS), ccs);

Modified: head/sys/dev/ahci/ahci.h
==============================================================================
--- head/sys/dev/ahci/ahci.h	Wed Jan 25 18:07:27 2017	(r312766)
+++ head/sys/dev/ahci/ahci.h	Wed Jan 25 18:16:17 2017	(r312767)
@@ -599,6 +599,7 @@ enum ahci_err_type {
 #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_BIT_STRING	\
 	"\020"			\
@@ -623,7 +624,8 @@ enum ahci_err_type {
 	"\023FORCE_PI"          \
 	"\024RESTORE_CAP"	\
 	"\025NOMSIX"		\
-	"\026MRVL_SR_DEL"
+	"\026MRVL_SR_DEL"	\
+	"\027NOCCS"
 
 int ahci_attach(device_t dev);
 int ahci_detach(device_t dev);

Modified: head/sys/dev/ahci/ahci_pci.c
==============================================================================
--- head/sys/dev/ahci/ahci_pci.c	Wed Jan 25 18:07:27 2017	(r312766)
+++ head/sys/dev/ahci/ahci_pci.c	Wed Jan 25 18:16:17 2017	(r312767)
@@ -73,15 +73,15 @@ static const struct {
 	{0x78021022, 0x00, "AMD Hudson-2",	0},
 	{0x78031022, 0x00, "AMD Hudson-2",	0},
 	{0x78041022, 0x00, "AMD Hudson-2",	0},
-	{0x06011b21, 0x00, "ASMedia ASM1060",	0},
-	{0x06021b21, 0x00, "ASMedia ASM1060",	0},
-	{0x06111b21, 0x00, "ASMedia ASM1061",	0},
-	{0x06121b21, 0x00, "ASMedia ASM1062",	0},
-	{0x06201b21, 0x00, "ASMedia ASM106x",	0},
-	{0x06211b21, 0x00, "ASMedia ASM106x",	0},
-	{0x06221b21, 0x00, "ASMedia ASM106x",	0},
-	{0x06241b21, 0x00, "ASMedia ASM106x",	0},
-	{0x06251b21, 0x00, "ASMedia ASM106x",	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},
 	{0x26528086, 0x00, "Intel ICH6",	AHCI_Q_NOFORCE},
 	{0x26538086, 0x00, "Intel ICH6M",	AHCI_Q_NOFORCE},
 	{0x26818086, 0x00, "Intel ESB2",	0},


More information about the svn-src-all mailing list