From nobody@FreeBSD.org  Fri Nov 30 22:16:50 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 1B95A37B405
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Nov 2001 22:16:50 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id fB16Go932585;
	Fri, 30 Nov 2001 22:16:50 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200112010616.fB16Go932585@freefall.freebsd.org>
Date: Fri, 30 Nov 2001 22:16:50 -0800 (PST)
From: "John L. Utz III" <john@utzweb.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: patch to support ATA66 Mode (UDMA4) on SiS 630 chipset
X-Send-Pr-Version: www-1.0

>Number:         32421
>Category:       kern
>Synopsis:       patch to support ATA66 Mode (UDMA4) on SiS 630 chipset
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    sos
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 30 22:20:01 PST 2001
>Closed-Date:    Mon Jan 7 11:18:21 PST 2002
>Last-Modified:  Mon Jan 07 11:19:20 PST 2002
>Originator:     John L. Utz III
>Release:        4.4-RELEASE
>Organization:
>Environment:
FreeBSD john.utzweb.net 4.4-RELEASE FreeBSD 4.4-RELEASE #11: Fri Nov 30 21:02:08 PST 2001     spaz@john.utzweb.net:/usr/src/sys/compile/JOHN  i386
b
>Description:
The SiS 630 integrated chipset contains an ATA66 controller that is currently recognized as an older SiS 5591 ATA33 device.

This is suboptimal because we like our disks to be read/written to as quickly as possible.
>How-To-Repeat:
boot 4.4-RELEASE kernel on a SiS630 based computer
>Fix:
following patches to ata-all.c and ata-dma.c
*** ata-all44R.c        Fri Nov 30 21:14:04 2001
--- ata-all.c   Fri Nov 30 21:15:25 2001
***************
*** 291,297 ****
        return "VIA Apollo ATA controller";
  
      case 0x55131039:
!       return "SiS 5591 ATA33 controller";
  
      case 0x06491095:
        return "CMD 649 ATA100 controller";
--- 291,298 ----
        return "VIA Apollo ATA controller";
  
      case 0x55131039:
!         if(pci_get_revid(dev)==0xd0) return "SiS 630  ATA66 controller";
!       else                         return "SiS 5591 ATA33 controller";
  
      case 0x06491095:
        return "CMD 649 ATA100 controller";

*** ata-dma44R.c        Fri Nov 30 21:14:05 2001
--- ata-dma.c   Fri Nov 30 21:15:32 2001
***************
*** 514,521 ****
        /* we could set PIO mode timings, but we assume the BIOS did that */
        break;
  
!     case 0x55131039:  /* SiS 5591 */
!       if (udmamode >= 2 && pci_get_revid(parent) > 0xc1) {
            error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
                                ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
            if (bootverbose)
--- 514,521 ----
        /* we could set PIO mode timings, but we assume the BIOS did that */
        break;
  
!     case 0x55131039:  /* SiS 5591,630 */
!         if (udmamode >= 2 && pci_get_revid(parent) > 0xc1) { /* 5591 */
            error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
                                ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
            if (bootverbose)
***************
*** 528,533 ****
--- 528,547 ----
                return;
            }
        }
          if (udmamode >= 2 && pci_get_revid(parent) >= 0xd0) { /* 630 */
            error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
                                ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
            if (bootverbose)
                ata_printf(scp, device,
                           "%s setting UDMA2 on SiS chip\n",
                           (error) ? "failed" : "success");
            if (!error) {
                pci_write_config(parent, 0x40   (devno << 1), 0xa301, 2);
                scp->mode[ATA_DEV(device)] = ATA_UDMA2;
                return;
            }
        }
  
        if (wdmamode >=2 && apiomode >= 4) {
            error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
                                ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);

>Release-Note:
>Audit-Trail:

From: Tamotsu HATTORI <hattori@kta.att.ne.jp>
To: freebsd-gnats-submit@FreeBSD.org, john@utzweb.net
Cc: athlete@kta.att.ne.jp
Subject: Re: kern/32421: patch to support ATA66 Mode (UDMA4) on SiS 630
 chips
Date: Sat, 01 Dec 2001 17:13:25 +0900

 I have another patch to ata-all.c and ata-dma.c.
 
 This patch supports ATA100 mode on SiS630S/633/635/730/733/735 chipsets.
 
 --- ata-all.c.orig	Wed Aug 29 02:56:14 2001
 +++ ata-all.c	Sat Nov 10 12:47:09 2001
 @@ -228,8 +228,7 @@
  	child = children[i];
  
  	/* check that it's on the same silicon and the device we want */
 -	if (pci_get_slot(dev) == pci_get_slot(child) &&
 -	    pci_get_vendor(child) == (type & 0xffff) &&
 +	if (pci_get_vendor(child) == (type & 0xffff) &&
  	    pci_get_device(child) == ((type & 0xffff0000) >> 16) &&
  	    pci_get_revid(child) >= revid) {
  	    free(children, M_TEMP);
 @@ -291,6 +290,18 @@
  	return "VIA Apollo ATA controller";
  
      case 0x55131039:
 +	if (ata_find_dev(dev, 0x06301039, 0x30) ||
 +	    ata_find_dev(dev, 0x06331039, 0x00) ||
 +	    ata_find_dev(dev, 0x06351039, 0x00) ||
 +	    ata_find_dev(dev, 0x07301039, 0x00) ||
 +	    ata_find_dev(dev, 0x07331039, 0x00) ||
 +	    ata_find_dev(dev, 0x07351039, 0x00))
 +	    return "SiS 5591 ATA100 controller";
 +	if (ata_find_dev(dev, 0x05301039, 0x00) ||
 +	    ata_find_dev(dev, 0x05401039, 0x00) ||
 +	    ata_find_dev(dev, 0x06201039, 0x00) ||
 +	    ata_find_dev(dev, 0x06301039, 0x00))
 +	    return "SiS 5591 ATA66 controller";
  	return "SiS 5591 ATA33 controller";
  
      case 0x06491095:
 --- ata-dma.c.orig	Wed Aug 29 02:56:14 2001
 +++ ata-dma.c	Sat Nov 10 12:57:54 2001
 @@ -514,18 +514,107 @@
  	/* we could set PIO mode timings, but we assume the BIOS did that */
  	break;
  
 -    case 0x55131039:	/* SiS 5591 */
 -	if (udmamode >= 2 && pci_get_revid(parent) > 0xc1) {
 -	    error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 -				ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 -	    if (bootverbose)
 -		ata_printf(scp, device,
 -			   "%s setting UDMA2 on SiS chip\n",
 -			   (error) ? "failed" : "success");
 -	    if (!error) {
 -		pci_write_config(parent, 0x40 + (devno << 1), 0xa301, 2);
 -		scp->mode[ATA_DEV(device)] = ATA_UDMA2;
 -		return;
 +    case 0x55131039:	/* SiS 5591, 530/540, 620/630/633/635, 730/733/735 */
 +	if (ata_find_dev(parent, 0x06301039, 0x30) || 	/* SiS630S */
 +	    ata_find_dev(parent, 0x06331039, 0x00) || 	/* SiS633 */
 +	    ata_find_dev(parent, 0x06351039, 0x00) || 	/* SiS635 */
 +	    ata_find_dev(parent, 0x07301039, 0x00) || 	/* SiS730 */
 +	    ata_find_dev(parent, 0x07331039, 0x00) || 	/* SiS733 */
 +	    ata_find_dev(parent, 0x07351039, 0x00)) { 	/* SiS735 */
 + 	    int16_t reg = 0;
 +	    if (udmamode >= 5) {
 +		error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 +				    ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
 +		if (bootverbose)
 +		    ata_printf(scp, device, 
 +			       "%s setting UDMA5 on SiS chip\n",
 +			       (error) ? "failed" : "success");
 +		if (!error) {
 +		    reg = pci_read_config(parent, 0x40 + (devno << 1), 2);
 +		    reg &= 0x0fff;
 +		    pci_write_config(parent, 0x40 + (devno << 1), reg|0x8000, 2);
 +		    scp->mode[ATA_DEV(device)] = ATA_UDMA5;
 +		    return;
 +		}
 +	    }
 +	    if (udmamode >= 4) {
 +		error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 +				    ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
 +		if (bootverbose)
 +		    ata_printf(scp, device, 
 +			       "%s setting UDMA4 on SiS chip\n",
 +			       (error) ? "failed" : "success");
 +		if (!error) {
 +		    reg = pci_read_config(parent, 0x40 + (devno << 1), 2);
 +		    reg &= 0x0fff;
 +		    pci_write_config(parent, 0x40 + (devno << 1), reg|0x9000, 2);
 +		    scp->mode[ATA_DEV(device)] = ATA_UDMA4;
 +		    return;
 +		}
 +	    }
 +	    if (udmamode >= 2) {
 +		error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 +				    ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 +		if (bootverbose)
 +		    ata_printf(scp, device,
 +			       "%s setting UDMA2 on SiS chip\n",
 +			       (error) ? "failed" : "success");
 +		if (!error) {
 +		    reg = pci_read_config(parent, 0x40 + (devno << 1), 2);
 +		    reg &= 0x0fff;
 +		    pci_write_config(parent, 0x40 + (devno << 1), reg|0xb000, 2);
 +		    scp->mode[ATA_DEV(device)] = ATA_UDMA2;
 +		    return;
 +		}
 +	    }
 +	} else if (ata_find_dev(parent, 0x05301039, 0) || /* SiS530 */
 +		   ata_find_dev(parent, 0x05401039, 0) || /* SiS540 */
 +		   ata_find_dev(parent, 0x06201039, 0) || /* SiS620 */
 +		   ata_find_dev(parent, 0x06301039, 0)) { /* SiS630/E */
 + 	    int16_t reg = 0;
 +	    if (udmamode >= 4) {
 +		error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 +				    ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
 +		if (bootverbose)
 +		    ata_printf(scp, device, 
 +			       "%s setting UDMA4 on SiS chip\n",
 +			       (error) ? "failed" : "success");
 +		if (!error) {
 +		    reg = pci_read_config(parent, 0x40 + (devno << 1), 2);
 +		    reg &= 0x0fff;
 +		    pci_write_config(parent, 0x40 + (devno << 1), reg|0xa000, 2);
 +		    scp->mode[ATA_DEV(device)] = ATA_UDMA4;
 +		    return;
 +		}
 +	    }
 +	    if (udmamode >= 2) {
 +		error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 +				    ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 +		if (bootverbose)
 +		    ata_printf(scp, device,
 +			       "%s setting UDMA2 on SiS chip\n",
 +			       (error) ? "failed" : "success");
 +		if (!error) {
 +		    reg = pci_read_config(parent, 0x40 + (devno << 1), 2);
 +		    reg &= 0x0fff;
 +		    pci_write_config(parent, 0x40 + (devno << 1), reg|0xb000, 2);
 +		    scp->mode[ATA_DEV(device)] = ATA_UDMA2;
 +		    return;
 +		}
 +	    }
 +	} else {
 + 	    if (udmamode >= 2 && pci_get_revid(parent) > 0xc1) {
 +		error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
 +				    ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 +		if (bootverbose)
 +		    ata_printf(scp, device,
 +			       "%s setting UDMA2 on SiS chip\n",
 +			       (error) ? "failed" : "success");
 +		if (!error) {
 +		    pci_write_config(parent, 0x40 + (devno << 1), 0xa301, 2);
 +		    scp->mode[ATA_DEV(device)] = ATA_UDMA2;
 +		    return;
 +		}
  	    }
  	}
  	if (wdmamode >=2 && apiomode >= 4) {
Responsible-Changed-From-To: freebsd-bugs->sos 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Sat Dec 1 00:51:32 PST 2001 
Responsible-Changed-Why:  
ATA PR with patches. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32421 
State-Changed-From-To: open->analyzed 
State-Changed-By: sos 
State-Changed-When: Mon Dec 3 04:14:47 PST 2001 
State-Changed-Why:  

Support for the new SiS chipsets has been committed to -current, 
the support is based on docs from SiS, and the timing params 
used are different from those in these patches. 
Please test the support in -current, and let me know if it 
works since I dont have any SiS HW here to test on. 


http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32421 
State-Changed-From-To: analyzed->closed 
State-Changed-By: sos 
State-Changed-When: Mon Jan 7 11:18:21 PST 2002 
State-Changed-Why:  
Support for even more SiS chipsets than in these patches 
has been added to 4.5 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32421 
>Unformatted:
