From fukui@fanet.net  Sun Aug 10 17:21:34 2008
Return-Path: <fukui@fanet.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C350D1065675
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 10 Aug 2008 17:21:34 +0000 (UTC)
	(envelope-from fukui@fanet.net)
Received: from mail.fanet.net (home.fanet.net [202.229.191.26])
	by mx1.freebsd.org (Postfix) with ESMTP id 28AB88FC13
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 10 Aug 2008 17:21:33 +0000 (UTC)
	(envelope-from fukui@fanet.net)
Received: from home.fanet.net
	by mail.fanet.net (8.14.3+3.5Wbeta/8.14.3) with ESMTP id m7AH9YQP092651
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 11 Aug 2008 02:09:34 +0900 (JST)
	(envelope-from fukui@fanet.net)
Received: (from fukui@localhost)
	by home.fanet.net (8.14.3+3.5Wbeta/8.14.3/Submit) id m7AH9XjW092650;
	Mon, 11 Aug 2008 02:09:33 +0900 (JST)
	(envelope-from fukui)
Message-Id: <200808101709.m7AH9XjW092650@home.fanet.net>
Date: Mon, 11 Aug 2008 02:09:33 +0900 (JST)
From: Masayuki FUKUI <fukui.FreeBSD@fanet.net>
Reply-To: Masayuki FUKUI <fukui.FreeBSD@fanet.net>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [ata] Fails to boot from RAID10 volume under the Intel ICH9R
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         126419
>Category:       kern
>Synopsis:       [ar] Fails to boot from RAID10 volume under the Intel ICH9R
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 10 17:30:00 UTC 2008
>Closed-Date:    
>Last-Modified:  Thu Feb 19 22:23:42 UTC 2009
>Originator:     Masayuki FUKUI
>Release:        FreeBSD 7.0-STABLE-200807 (amd64)
>Organization:
>Environment:
Machine: ASUS P5K-E (P35 + ICH9R)
OS     : FreeBSD 7.0-STABLE-200807 (amd64) snapshots
HDD    : RAID10 / Seagate ST3500320NS (500GB) * 4

>Description:
	Fails to boot from RAID10 volume under the Intel ICH9R RAID controller.

	Causes:
	In FreeBSD ATA RAID driver, RAID10 HDD pairing is wrong.

	   Attached HDDs          : ad4, ad6, ad8, ad10

	   FreeBSD RAID10 pairing : (Master: striping ad4 + ad6) & (Mirror: striping ad8 + ad10)
	   Windows RAID10 pairing : (Master: striping ad4 + ad8) & (Mirror: striping ad6 + ad10)
	   BIOS RAID10 pairing    : (Master: striping ad4 + ad8) & (Mirror: striping ad6 + ad10)

	Boot fails because FreeBSD and BIOS are mismatched.
	(Boot code is not installed on ad6)

	When ad6 and ad8 were mutually copied, it was possible to boot it.
	(But naturally afterwards, kernel paniced)

>How-To-Repeat:
	Install FreeBSD on ICH9R & RAID10 volume
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-i386->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Aug 18 01:05:59 UTC 2008 
Responsible-Changed-Why:  
Probably not i386-specific. 

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

From: Hideki Sakamoto <hsakamt@tsnr.com>
To: bug-followup@FreeBSD.org, fukui.FreeBSD@fanet.net
Cc:  
Subject: Re: kern/126419: [ata] Fails to boot from RAID10 volume under the
 Intel ICH9R
Date: Tue, 09 Sep 2008 15:35:50 +0900

 Hi,
 
 I think one simple solution is to swap disk order in metadata at read/write
 timing from/to BIOS.
 
 I attach a patch for 7.1-PRERELEASE. It can apply properly on 6.4-PRERELEASE
 with offset warning. I aim to work a sytem more than 4 disks but just test it
 with 4 disks machine.
 
 You must install FreeBSD with patched kernel. ISO image of bootonly installer
 is available at:
 http://www.tsnr.com/FreeBSD/7.0-bootonly_patched.iso
 MD5 (7.0-bootonly_patched.iso) = 27d9aff696be335143a781b3ece24e94
 
 Please don't forget to change "Release Name" of install option to "7.0-RELEASE"
 or so. Go Alt+F4 console and copy patched kernel in installer CD-ROM to ar0 /
 partition before rebooting the installed system, or it will panic.
 
 Thanks,
 Hideki Sakamoto
 
 ==============================
 *** ata-raid.c.orig	Tue Sep  9 14:10:26 2008
 --- ata-raid.c	Tue Sep  9 14:15:15 2008
 ***************
 *** 2146,2152 ****
   		break;
 
   	    case INTEL_T_RAID1:
 ! 		if (map->total_disks == 4)
   		    raid->type = AR_T_RAID01;
   		else
   		    raid->type = AR_T_RAID1;
 --- 2146,2152 ----
   		break;
 
   	    case INTEL_T_RAID1:
 ! 		if (map->total_disks >= 4)
   		    raid->type = AR_T_RAID01;
   		else
   		    raid->type = AR_T_RAID1;
 ***************
 *** 2214,2219 ****
 --- 2214,2234 ----
   		if (meta->disk[map->disk_idx[disk]].flags & INTEL_F_DOWN)
   		    raid->disks[disk].flags &= ~AR_DF_ONLINE;
   	    }
 + 	    if (raid->type == AR_T_RAID01) {
 + 		/* swap disk info */
 + 		char *tmp1;
 + 		int i;
 + 		int sz = sizeof(raid->disks[1]);
 + 		int pair_num = raid->total_disks / 2;
 +
 + 		tmp1 = (char *)malloc(sz * (raid->total_disks - 2), M_AR, M_NOWAIT | M_ZERO);
 + 		for (i = 0; i < pair_num - 1; i++) {
 + 		    bcopy(&raid->disks[2 * (i + 1)], tmp1 + sz * i, sz);
 + 		    bcopy(&raid->disks[2 * i + 1], tmp1 + sz * (i + pair_num - 1), sz);
 + 		}
 + 		bcopy(tmp1, &raid->disks[1], sz * (raid->total_disks - 2));
 + 		free(tmp1, M_AR);
 + 	    }
   	}
   	if (meta->generation >= raid->generation) {
   	    for (disk = 0; disk < raid->total_disks; disk++) {
 ***************
 *** 2325,2330 ****
 --- 2340,2361 ----
   	break;
       case AR_T_RAID01:
   	map->type = INTEL_T_RAID1;
 + 	{
 + 	    /* swap disk info */
 + 	    char *tmp1;
 + 	    int i;
 + 	    int sz = sizeof(meta->disk[1]);
 + 	    int buflen = sz * (meta->total_disks - 2);
 + 	    int pair_num = meta->total_disks / 2;
 +
 + 	    tmp1 = (char *)malloc(buflen, M_AR, M_NOWAIT | M_ZERO);
 + 	    for (i = 0; i < pair_num - 1; i++) {
 + 		bcopy(&meta->disk[i+1], tmp1 + sz * (2 * i + 1), sz);
 + 		bcopy(&meta->disk[i+pair_num], tmp1 + sz * 2 * i, sz);
 + 	    }
 + 	    bcopy(tmp1, &meta->disk[1], buflen);
 + 	    free(tmp1, M_AR);
 + 	}
   	break;
       case AR_T_RAID5:
   	map->type = INTEL_T_RAID5;
>Unformatted:
