From nobody@FreeBSD.org  Wed Feb 25 01:42:23 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B8520106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Feb 2009 01:42:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A58498FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Feb 2009 01:42:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n1P1gM7S085206
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Feb 2009 01:42:22 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n1P1gMWb085188;
	Wed, 25 Feb 2009 01:42:22 GMT
	(envelope-from nobody)
Message-Id: <200902250142.n1P1gMWb085188@www.freebsd.org>
Date: Wed, 25 Feb 2009 01:42:22 GMT
From: Dieter <freebsd@sopwith.solgatos.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [ patch ] ATA driver does not find PATA drives attached to JMB363 controller
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         132082
>Category:       kern
>Synopsis:       [ata] [patch] ATA driver does not find PATA drives attached to JMB363 controller
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    mav
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 25 01:50:01 UTC 2009
>Closed-Date:    Thu May 14 02:24:57 UTC 2009
>Last-Modified:  Thu May 14 02:24:57 UTC 2009
>Originator:     Dieter
>Release:        7.1 amd64
>Organization:
>Environment:
7.1-RELEASE amd64
>Description:
FreeBSD 7.1
amd64
nforce4-ultra (ad2 - ad10)
2 JMicron JMB363 controllers (ad12 and above)

7.1 kernel (without my patch)

# dmesg | grep 363
atapci4: <JMicron JMB363 SATA300 controller> port 0x5c00-0x5c07,0x5800-0x5803,0x
5400-0x5407,0x5000-0x5003,0x4c00-0x4c0f mem 0xfe3fe000-0xfe3fffff irq 12 at devi
ce 0.0 on pci6
# dmesg | grep ^ad
ad2: 305245MB <Seagate ST3320620A 3.AAC> at ata1-master UDMA100
ad4: 715404MB <Seagate ST3750640AS 3.AAE> at ata2-master SATA300
ad6: 715404MB <Seagate ST3750640AS 3.AAE> at ata3-master SATA300
ad8: 953869MB <Hitachi HDT721010SLA360 ST6OA31B> at ata4-master SATA300
ad10: 953869MB <SAMSUNG HD103UJ 1AA01113> at ata5-master SATA300
ad12: 238475MB <Seagate ST3250823AS 3.03> at ata6-master SATA150
ad14: 715404MB <Seagate ST3750330AS SD15> at ata7-master SATA300
ad16: 953869MB <WDC WD10EACS-00ZJB0 01.01B01> at ata8-master SATA300
#

The stock 7.1 kernel (7.0 was the same) does not see any PATA devices
connected to the JMicron JMB363 controllers.  It does see PATA and SATA
devices connected to the nforce4-ultra controller, and they work.  It does
see SATA devices connected to the JMicron JMB363 controllers and they
work.

I added a quick-and-dirty patch to ata-pci.c that tries ata_jmicron_ident()
before ata_ahci_ident().

# dmesg | grep 363
atapci3: <JMicron JMB363 SATA300 controller> at device 0.0 on pci3
atapci4: <JMicron JMB363 SATA300 controller> port 0x5c00-0x5c07,0x5800-0x5803,0x5400-0x5407,0x5000-0x5003,0x4c00-0x4c0f mem \
0xfe3fe000-0xfe3fffff irq 12 at device 0.0 on pci6
# dmesg | grep ^ad
ad2: 305245MB <Seagate ST3320620A 3.AAC> at ata1-master UDMA100
ad4: 715404MB <Seagate ST3750640AS 3.AAE> at ata2-master SATA300
ad6: 715404MB <Seagate ST3750640AS 3.AAE> at ata3-master SATA300
ad8: 953869MB <Hitachi HDT721010SLA360 ST6OA31B> at ata4-master SATA300
ad10: 953869MB <SAMSUNG HD103UJ 1AA01113> at ata5-master SATA300
ad12: 238475MB <Seagate ST3250823AS 3.03> at ata6-master SATA150
ad14: 715404MB <Seagate ST3750330AS SD15> at ata7-master SATA300
ad16: 305245MB <Seagate ST3320620A 3.AAC> at ata8-master UDMA100
ad18: 953869MB <WDC WD10EACS-00ZJB0 01.01B01> at ata9-master SATA300

With my patch, the kernel does see PATA devices (ad16) connected to the
JMicron JMB363 controllers.  The WDC SATA drive gets moved from
ad16 to ad18.

Perhaps unrelated, the Seagate PATA drive connects at UDMA100.
Reading works fine, but writing consistantly fails:

ad16: WARNING - WRITE_DMA UDMA ICRC error (retrying request) LBA=191
ad16: WARNING - WRITE_DMA UDMA ICRC error (retrying request) LBA=191
ad16: FAILURE - WRITE_DMA status=51<READY,DSC,ERROR> error=84<ICRC,ABORTED> LBA=191

I downgraded it from 100 to 66
# atacontrol mode ad16 UDMA66

and at 66 writing works ok.  The same disk works fine at 100
with other controllers.  Standard 80 wire flat ribbon cable,
not round or extra long or anything wierd.

My patch might not be the best way to fix this problem.  For all
I know it might even break something on other systems.  All I
can say is it works for me.  :-)

>How-To-Repeat:
Connect a PATA device to a JMB363 controller.  Boot 7.0 or 7.1 and observe
that the kernel does not find the drive.

>Fix:
My patch works for me.


Patch attached with submission follows:

--- ata-pci.c	2008/04/21 23:14:03	1.1
+++ ata-pci.c	2008/04/21 23:15:41
@@ -76,6 +76,13 @@
     if (pci_get_class(dev) != PCIC_STORAGE)
 	return ENXIO;
 
+    if ( pci_get_vendor(dev) == ATA_JMICRON_ID )
+      {
+	printf("DEBUG ata-pci.c ata_pci_probe() trying ata_jmicron_ident() before ata_ahci_ident()\n");
+	if (!ata_jmicron_ident(dev))
+	    return ATA_PROBE_OK;
+      }
+
     /* if this is an AHCI chipset grab it */
     if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 	if (!ata_ahci_ident(dev))


>Release-Note:
>Audit-Trail:

From: Alexander Motin <mav@FreeBSD.org>
To: bug-followup@FreeBSD.org, freebsd@sopwith.solgatos.com
Cc:  
Subject: Re: kern/132082: [ata] [patch] ATA driver does not find PATA drives
 attached to JMB363 controller
Date: Thu, 07 May 2009 03:22:45 +0300

 This is a multi-part message in MIME format.
 --------------070709020706000907030706
 Content-Type: text/plain; charset=KOI8-R; format=flowed
 Content-Transfer-Encoding: 7bit
 
 AHCI driver priority was already reduced on 8-CURRENT, but in other, 
 inapplicable here, fashion. For 7.X, try attached patch.
 
 -- 
 Alexander Motin
 
 --------------070709020706000907030706
 Content-Type: text/plain;
  name="ahci.prio.7.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="ahci.prio.7.patch"
 
 --- ata-pci.c.prev	2007-11-21 23:15:00.000000000 +0200
 +++ ata-pci.c	2009-05-07 03:08:44.000000000 +0300
 @@ -76,12 +76,6 @@ ata_pci_probe(device_t dev)
      if (pci_get_class(dev) != PCIC_STORAGE)
  	return ENXIO;
  
 -    /* if this is an AHCI chipset grab it */
 -    if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 -	if (!ata_ahci_ident(dev))
 -	    return ATA_PROBE_OK;
 -    }
 -
      /* run through the vendor specific drivers */
      switch (pci_get_vendor(dev)) {
      case ATA_ACARD_ID: 
 @@ -178,6 +172,12 @@ ata_pci_probe(device_t dev)
  	break;
      }
  
 +    /* if this is an AHCI chipset grab it */
 +    if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 +	if (!ata_ahci_ident(dev))
 +	    return ATA_PROBE_OK;
 +    }
 +
      /* unknown chipset, try generic DMA if it seems possible */
      if (pci_get_subclass(dev) == PCIS_STORAGE_IDE) {
  	if (!ata_generic_ident(dev))
 
 --------------070709020706000907030706--
State-Changed-From-To: open->patched 
State-Changed-By: mav 
State-Changed-When: Thu May 7 17:40:54 UTC 2009 
State-Changed-Why:  
Problem should already be fixed for 8-CURRENT. 
Patch for 7-STABLE is quite simple and can be committed after 
some check. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=132082 
Responsible-Changed-From-To: freebsd-bugs->mav 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu May 7 18:12:02 UTC 2009 
Responsible-Changed-Why:  
Over to committer as MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=132082 

From: Dieter <freebsd@sopwith.solgatos.com>
To: Alexander Motin <mav@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/132082: [ata] [patch] ATA driver does not find PATA drives attached to JMB363 controller 
Date: Sun, 10 May 2009 11:31:07 +0100

 > AHCI driver priority was already reduced on 8-CURRENT, but in other, 
 > inapplicable here, fashion. For 7.X, try attached patch.
 > 
 > -- 
 > Alexander Motin
 > 
 > --------------070709020706000907030706
 > Content-Type: text/plain;
 >  name="ahci.prio.7.patch"
 > Content-Transfer-Encoding: 7bit
 > Content-Disposition: inline;
 >  filename="ahci.prio.7.patch"
 > 
 > --- ata-pci.c.prev	2007-11-21 23:15:00.000000000 +0200
 > +++ ata-pci.c	2009-05-07 03:08:44.000000000 +0300
 > @@ -76,12 +76,6 @@ ata_pci_probe(device_t dev)
 >      if (pci_get_class(dev) != PCIC_STORAGE)
 >  	return ENXIO;
 >  
 > -    /* if this is an AHCI chipset grab it */
 > -    if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 > -	if (!ata_ahci_ident(dev))
 > -	    return ATA_PROBE_OK;
 > -    }
 > -
 >      /* run through the vendor specific drivers */
 >      switch (pci_get_vendor(dev)) {
 >      case ATA_ACARD_ID: 
 > @@ -178,6 +172,12 @@ ata_pci_probe(device_t dev)
 >  	break;
 >      }
 >  
 > +    /* if this is an AHCI chipset grab it */
 > +    if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 > +	if (!ata_ahci_ident(dev))
 > +	    return ATA_PROBE_OK;
 > +    }
 > +
 >      /* unknown chipset, try generic DMA if it seems possible */
 >      if (pci_get_subclass(dev) == PCIS_STORAGE_IDE) {
 >  	if (!ata_generic_ident(dev))
 > 
 > --------------070709020706000907030706--
 
 I replaced my patch with the patch above, and it works for me. (7.1)
 Thanks.

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/132082: commit references a PR
Date: Wed, 13 May 2009 02:55:36 +0000 (UTC)

 Author: mav
 Date: Wed May 13 02:55:21 2009
 New Revision: 192033
 URL: http://svn.freebsd.org/changeset/base/192033
 
 Log:
   Make vendor-specific drivers prefered over the generic AHCI one.
   This fixes some controllers, like JMicron ones, which provide also PATA via
   PCI function that declared as AHCI controller.
   
   This is not an MFC, but the same was already done in 8-CURRENT in other way.
   
   PR:		kern/132082
 
 Modified:
   stable/7/sys/dev/ata/ata-pci.c
 
 Modified: stable/7/sys/dev/ata/ata-pci.c
 ==============================================================================
 --- stable/7/sys/dev/ata/ata-pci.c	Wed May 13 02:26:34 2009	(r192032)
 +++ stable/7/sys/dev/ata/ata-pci.c	Wed May 13 02:55:21 2009	(r192033)
 @@ -76,12 +76,6 @@ ata_pci_probe(device_t dev)
      if (pci_get_class(dev) != PCIC_STORAGE)
  	return ENXIO;
  
 -    /* if this is an AHCI chipset grab it */
 -    if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 -	if (!ata_ahci_ident(dev))
 -	    return ATA_PROBE_OK;
 -    }
 -
      /* run through the vendor specific drivers */
      switch (pci_get_vendor(dev)) {
      case ATA_ACARD_ID: 
 @@ -178,6 +172,12 @@ ata_pci_probe(device_t dev)
  	break;
      }
  
 +    /* if this is an AHCI chipset grab it */
 +    if (pci_get_subclass(dev) == PCIS_STORAGE_SATA) {
 +	if (!ata_ahci_ident(dev))
 +	    return ATA_PROBE_OK;
 +    }
 +
      /* unknown chipset, try generic DMA if it seems possible */
      if (pci_get_subclass(dev) == PCIS_STORAGE_IDE) {
  	if (!ata_generic_ident(dev))
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: mav 
State-Changed-When: Thu May 14 02:24:15 UTC 2009 
State-Changed-Why:  
Patch was committed to 7-STABLE. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=132082 
>Unformatted:
