ata-raid.c (153416) | ata-raid.c (153446) |
---|---|
1/*- 2 * Copyright (c) 2000 - 2005 S�ren Schmidt <sos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000 - 2005 S�ren Schmidt <sos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/ata/ata-raid.c 153416 2005-12-14 13:07:49Z sos $"); | 30__FBSDID("$FreeBSD: head/sys/dev/ata/ata-raid.c 153446 2005-12-15 13:30:23Z sos $"); |
31 32#include "opt_ata.h" 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/ata.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> --- 21 unchanged lines hidden (view full) --- 60static void ata_raid_config_changed(struct ar_softc *rdp, int writeback); 61static int ata_raid_status(struct ata_ioc_raid_config *config); 62static int ata_raid_create(struct ata_ioc_raid_config *config); 63static int ata_raid_delete(int array); 64static int ata_raid_addspare(struct ata_ioc_raid_config *config); 65static int ata_raid_rebuild(int array); 66static int ata_raid_read_metadata(device_t subdisk); 67static int ata_raid_write_metadata(struct ar_softc *rdp); | 31 32#include "opt_ata.h" 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/ata.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> --- 21 unchanged lines hidden (view full) --- 60static void ata_raid_config_changed(struct ar_softc *rdp, int writeback); 61static int ata_raid_status(struct ata_ioc_raid_config *config); 62static int ata_raid_create(struct ata_ioc_raid_config *config); 63static int ata_raid_delete(int array); 64static int ata_raid_addspare(struct ata_ioc_raid_config *config); 65static int ata_raid_rebuild(int array); 66static int ata_raid_read_metadata(device_t subdisk); 67static int ata_raid_write_metadata(struct ar_softc *rdp); |
68static int ata_raid_wipe_metadata(struct ar_softc *rdp); |
|
68static int ata_raid_adaptec_read_meta(device_t dev, struct ar_softc **raidp); 69static int ata_raid_hptv2_read_meta(device_t dev, struct ar_softc **raidp); 70static int ata_raid_hptv2_write_meta(struct ar_softc *rdp); 71static int ata_raid_hptv3_read_meta(device_t dev, struct ar_softc **raidp); 72static int ata_raid_intel_read_meta(device_t dev, struct ar_softc **raidp); 73static int ata_raid_intel_write_meta(struct ar_softc *rdp); 74static int ata_raid_ite_read_meta(device_t dev, struct ar_softc **raidp); 75static int ata_raid_lsiv2_read_meta(device_t dev, struct ar_softc **raidp); 76static int ata_raid_lsiv3_read_meta(device_t dev, struct ar_softc **raidp); 77static int ata_raid_nvidia_read_meta(device_t dev, struct ar_softc **raidp); 78static int ata_raid_promise_read_meta(device_t dev, struct ar_softc **raidp, int native); 79static int ata_raid_promise_write_meta(struct ar_softc *rdp); 80static int ata_raid_sii_read_meta(device_t dev, struct ar_softc **raidp); 81static int ata_raid_sis_read_meta(device_t dev, struct ar_softc **raidp); 82static int ata_raid_sis_write_meta(struct ar_softc *rdp); 83static int ata_raid_via_read_meta(device_t dev, struct ar_softc **raidp); | 69static int ata_raid_adaptec_read_meta(device_t dev, struct ar_softc **raidp); 70static int ata_raid_hptv2_read_meta(device_t dev, struct ar_softc **raidp); 71static int ata_raid_hptv2_write_meta(struct ar_softc *rdp); 72static int ata_raid_hptv3_read_meta(device_t dev, struct ar_softc **raidp); 73static int ata_raid_intel_read_meta(device_t dev, struct ar_softc **raidp); 74static int ata_raid_intel_write_meta(struct ar_softc *rdp); 75static int ata_raid_ite_read_meta(device_t dev, struct ar_softc **raidp); 76static int ata_raid_lsiv2_read_meta(device_t dev, struct ar_softc **raidp); 77static int ata_raid_lsiv3_read_meta(device_t dev, struct ar_softc **raidp); 78static int ata_raid_nvidia_read_meta(device_t dev, struct ar_softc **raidp); 79static int ata_raid_promise_read_meta(device_t dev, struct ar_softc **raidp, int native); 80static int ata_raid_promise_write_meta(struct ar_softc *rdp); 81static int ata_raid_sii_read_meta(device_t dev, struct ar_softc **raidp); 82static int ata_raid_sis_read_meta(device_t dev, struct ar_softc **raidp); 83static int ata_raid_sis_write_meta(struct ar_softc *rdp); 84static int ata_raid_via_read_meta(device_t dev, struct ar_softc **raidp); |
85static int ata_raid_via_write_meta(struct ar_softc *rdp); |
|
84static struct ata_request *ata_raid_init_request(struct ar_softc *rdp, struct bio *bio); 85static int ata_raid_send_request(struct ata_request *request); 86static int ata_raid_rw(device_t dev, u_int64_t lba, void *data, u_int bcount, int flags); 87static char * ata_raid_format(struct ar_softc *rdp); 88static char * ata_raid_type(struct ar_softc *rdp); 89static char * ata_raid_flags(struct ar_softc *rdp); 90 91/* debugging only */ --- 811 unchanged lines hidden (view full) --- 903 case ATA_ITE_ID: 904 ctlr = AR_F_ITE_RAID; 905 rdp->disks[disk].sectors = ITE_LBA(rdp->disks[disk].dev); 906 break; 907 908 case 0: /* XXX SOS cover up for bug in our PCI code */ 909 case ATA_PROMISE_ID: 910 ctlr = AR_F_PROMISE_RAID; | 86static struct ata_request *ata_raid_init_request(struct ar_softc *rdp, struct bio *bio); 87static int ata_raid_send_request(struct ata_request *request); 88static int ata_raid_rw(device_t dev, u_int64_t lba, void *data, u_int bcount, int flags); 89static char * ata_raid_format(struct ar_softc *rdp); 90static char * ata_raid_type(struct ar_softc *rdp); 91static char * ata_raid_flags(struct ar_softc *rdp); 92 93/* debugging only */ --- 811 unchanged lines hidden (view full) --- 905 case ATA_ITE_ID: 906 ctlr = AR_F_ITE_RAID; 907 rdp->disks[disk].sectors = ITE_LBA(rdp->disks[disk].dev); 908 break; 909 910 case 0: /* XXX SOS cover up for bug in our PCI code */ 911 case ATA_PROMISE_ID: 912 ctlr = AR_F_PROMISE_RAID; |
911 rdp->disks[disk].sectors = PR_LBA(rdp->disks[disk].dev); | 913 rdp->disks[disk].sectors = PROMISE_LBA(rdp->disks[disk].dev); |
912 break; 913 914 case ATA_SIS_ID: 915 ctlr = AR_F_SIS_RAID; 916 rdp->disks[disk].sectors = SIS_LBA(rdp->disks[disk].dev); 917 break; 918 919 case ATA_ATI_ID: --- 13 unchanged lines hidden (view full) --- 933 * setup the RAID from there, in that case we pickup the 934 * metadata format from the disks (if we support it). 935 */ 936 printf("WARNING!! - not able to determine metadata format\n" 937 "WARNING!! - Using FreeBSD PsuedoRAID metadata\n" 938 "If that is not what you want, use the BIOS to " 939 "create the array\n"); 940 ctlr = AR_F_FREEBSD_RAID; | 914 break; 915 916 case ATA_SIS_ID: 917 ctlr = AR_F_SIS_RAID; 918 rdp->disks[disk].sectors = SIS_LBA(rdp->disks[disk].dev); 919 break; 920 921 case ATA_ATI_ID: --- 13 unchanged lines hidden (view full) --- 935 * setup the RAID from there, in that case we pickup the 936 * metadata format from the disks (if we support it). 937 */ 938 printf("WARNING!! - not able to determine metadata format\n" 939 "WARNING!! - Using FreeBSD PsuedoRAID metadata\n" 940 "If that is not what you want, use the BIOS to " 941 "create the array\n"); 942 ctlr = AR_F_FREEBSD_RAID; |
941 rdp->disks[disk].sectors = PR_LBA(rdp->disks[disk].dev); | 943 rdp->disks[disk].sectors = PROMISE_LBA(rdp->disks[disk].dev); |
942 break; 943 } 944 945 /* we need all disks to be of the same format */ 946 if ((rdp->format & AR_F_FORMAT_MASK) && 947 (rdp->format & AR_F_FORMAT_MASK) != (ctlr & AR_F_FORMAT_MASK)) { 948 free(rdp, M_AR); 949 return EXDEV; --- 164 unchanged lines hidden (view full) --- 1114 if (ars->disk_number[rdp->volume] != disk) /* XXX SOS */ 1115 device_printf(subdisk, "DOH! this disk number is wrong\n"); 1116 ars->raid[rdp->volume] = NULL; 1117 ars->disk_number[rdp->volume] = -1; 1118 } 1119 rdp->disks[disk].flags = 0; 1120 } 1121 } | 944 break; 945 } 946 947 /* we need all disks to be of the same format */ 948 if ((rdp->format & AR_F_FORMAT_MASK) && 949 (rdp->format & AR_F_FORMAT_MASK) != (ctlr & AR_F_FORMAT_MASK)) { 950 free(rdp, M_AR); 951 return EXDEV; --- 164 unchanged lines hidden (view full) --- 1116 if (ars->disk_number[rdp->volume] != disk) /* XXX SOS */ 1117 device_printf(subdisk, "DOH! this disk number is wrong\n"); 1118 ars->raid[rdp->volume] = NULL; 1119 ars->disk_number[rdp->volume] = -1; 1120 } 1121 rdp->disks[disk].flags = 0; 1122 } 1123 } |
1122 ata_raid_write_metadata(rdp); /* XXX SOS wipe metadata instead? */ | 1124 ata_raid_wipe_metadata(rdp); |
1123 ata_raid_arrays[array] = NULL; 1124 free(rdp, M_AR); 1125 return 0; 1126} 1127 1128static int 1129ata_raid_addspare(struct ata_ioc_raid_config *config) 1130{ --- 172 unchanged lines hidden (view full) --- 1303 */ 1304 return ata_raid_hptv2_write_meta(rdp); 1305 1306 case AR_F_INTEL_RAID: 1307 return ata_raid_intel_write_meta(rdp); 1308 1309 case AR_F_SIS_RAID: 1310 return ata_raid_sis_write_meta(rdp); | 1125 ata_raid_arrays[array] = NULL; 1126 free(rdp, M_AR); 1127 return 0; 1128} 1129 1130static int 1131ata_raid_addspare(struct ata_ioc_raid_config *config) 1132{ --- 172 unchanged lines hidden (view full) --- 1305 */ 1306 return ata_raid_hptv2_write_meta(rdp); 1307 1308 case AR_F_INTEL_RAID: 1309 return ata_raid_intel_write_meta(rdp); 1310 1311 case AR_F_SIS_RAID: 1312 return ata_raid_sis_write_meta(rdp); |
1313 1314 case AR_F_VIA_RAID: 1315 return ata_raid_via_write_meta(rdp); |
|
1311#if 0 1312 case AR_F_HPTV3_RAID: 1313 return ata_raid_hptv3_write_meta(rdp); 1314 1315 case AR_F_ADAPTEC_RAID: 1316 return ata_raid_adaptec_write_meta(rdp); 1317 1318 case AR_F_ITE_RAID: --- 6 unchanged lines hidden (view full) --- 1325 return ata_raid_lsiv3_write_meta(rdp); 1326 1327 case AR_F_NVIDIA_RAID: 1328 return ata_raid_nvidia_write_meta(rdp); 1329 1330 case AR_F_SII_RAID: 1331 return ata_raid_sii_write_meta(rdp); 1332 | 1316#if 0 1317 case AR_F_HPTV3_RAID: 1318 return ata_raid_hptv3_write_meta(rdp); 1319 1320 case AR_F_ADAPTEC_RAID: 1321 return ata_raid_adaptec_write_meta(rdp); 1322 1323 case AR_F_ITE_RAID: --- 6 unchanged lines hidden (view full) --- 1330 return ata_raid_lsiv3_write_meta(rdp); 1331 1332 case AR_F_NVIDIA_RAID: 1333 return ata_raid_nvidia_write_meta(rdp); 1334 1335 case AR_F_SII_RAID: 1336 return ata_raid_sii_write_meta(rdp); 1337 |
1333 case AR_F_VIA_RAID: 1334 return ata_raid_via_write_meta(rdp); | |
1335#endif 1336 default: 1337 printf("ar%d: writing of %s metadata is NOT supported yet\n", 1338 rdp->lun, ata_raid_format(rdp)); 1339 } 1340 return -1; 1341} 1342 | 1338#endif 1339 default: 1340 printf("ar%d: writing of %s metadata is NOT supported yet\n", 1341 rdp->lun, ata_raid_format(rdp)); 1342 } 1343 return -1; 1344} 1345 |
1346static int 1347ata_raid_wipe_metadata(struct ar_softc *rdp) 1348{ 1349 int disk, error = 0; 1350 u_int64_t lba; 1351 u_int32_t size; 1352 u_int8_t *meta; 1353 1354 for (disk = 0; disk < rdp->total_disks; disk++) { 1355 if (rdp->disks[disk].dev) { 1356 switch (rdp->format) { 1357 case AR_F_ADAPTEC_RAID: 1358 lba = ADP_LBA(rdp->disks[disk].dev); 1359 size = sizeof(struct adaptec_raid_conf); 1360 break; 1361 1362 case AR_F_HPTV2_RAID: 1363 lba = HPTV2_LBA(rdp->disks[disk].dev); 1364 size = sizeof(struct hptv2_raid_conf); 1365 break; 1366 1367 case AR_F_HPTV3_RAID: 1368 lba = HPTV3_LBA(rdp->disks[disk].dev); 1369 size = sizeof(struct hptv3_raid_conf); 1370 break; 1371 1372 case AR_F_INTEL_RAID: 1373 lba = INTEL_LBA(rdp->disks[disk].dev); 1374 size = 3 * 512; /* XXX SOS */ 1375 break; 1376 1377 case AR_F_ITE_RAID: 1378 lba = ITE_LBA(rdp->disks[disk].dev); 1379 size = sizeof(struct ite_raid_conf); 1380 break; 1381 1382 case AR_F_LSIV2_RAID: 1383 lba = LSIV2_LBA(rdp->disks[disk].dev); 1384 size = sizeof(struct lsiv2_raid_conf); 1385 break; 1386 1387 case AR_F_LSIV3_RAID: 1388 lba = LSIV3_LBA(rdp->disks[disk].dev); 1389 size = sizeof(struct lsiv3_raid_conf); 1390 break; 1391 1392 case AR_F_NVIDIA_RAID: 1393 lba = NVIDIA_LBA(rdp->disks[disk].dev); 1394 size = sizeof(struct nvidia_raid_conf); 1395 break; 1396 1397 case AR_F_FREEBSD_RAID: 1398 case AR_F_PROMISE_RAID: 1399 lba = PROMISE_LBA(rdp->disks[disk].dev); 1400 size = sizeof(struct promise_raid_conf); 1401 break; 1402 1403 case AR_F_SII_RAID: 1404 lba = SII_LBA(rdp->disks[disk].dev); 1405 size = sizeof(struct sii_raid_conf); 1406 break; 1407 1408 case AR_F_SIS_RAID: 1409 lba = SIS_LBA(rdp->disks[disk].dev); 1410 size = sizeof(struct sis_raid_conf); 1411 break; 1412 1413 case AR_F_VIA_RAID: 1414 lba = VIA_LBA(rdp->disks[disk].dev); 1415 size = sizeof(struct via_raid_conf); 1416 break; 1417 1418 default: 1419 printf("ar%d: wiping of %s metadata is NOT supported yet\n", 1420 rdp->lun, ata_raid_format(rdp)); 1421 return ENXIO; 1422 } 1423 if (!(meta = malloc(size, M_AR, M_NOWAIT | M_ZERO))) 1424 return ENOMEM; 1425 if (ata_raid_rw(rdp->disks[disk].dev, lba, meta, size, 1426 ATA_R_WRITE | ATA_R_DIRECT)) { 1427 device_printf(rdp->disks[disk].dev, "wipe metadata failed\n"); 1428 error = EIO; 1429 } 1430 free(meta, M_AR); 1431 } 1432 } 1433 return error; 1434} 1435 |
|
1343/* Adaptec HostRAID Metadata */ 1344static int 1345ata_raid_adaptec_read_meta(device_t dev, struct ar_softc **raidp) 1346{ 1347 struct ata_raid_subdisk *ars = device_get_softc(dev); 1348 device_t parent = device_get_parent(dev); 1349 struct adaptec_raid_conf *meta; 1350 struct ar_softc *raid; --- 1308 unchanged lines hidden (view full) --- 2659 struct ar_softc *raid; 2660 u_int32_t checksum, *ptr; 2661 int array, count, disk, disksum = 0, retval = 0; 2662 2663 if (!(meta = (struct promise_raid_conf *) 2664 malloc(sizeof(struct promise_raid_conf), M_AR, M_NOWAIT | M_ZERO))) 2665 return ENOMEM; 2666 | 1436/* Adaptec HostRAID Metadata */ 1437static int 1438ata_raid_adaptec_read_meta(device_t dev, struct ar_softc **raidp) 1439{ 1440 struct ata_raid_subdisk *ars = device_get_softc(dev); 1441 device_t parent = device_get_parent(dev); 1442 struct adaptec_raid_conf *meta; 1443 struct ar_softc *raid; --- 1308 unchanged lines hidden (view full) --- 2752 struct ar_softc *raid; 2753 u_int32_t checksum, *ptr; 2754 int array, count, disk, disksum = 0, retval = 0; 2755 2756 if (!(meta = (struct promise_raid_conf *) 2757 malloc(sizeof(struct promise_raid_conf), M_AR, M_NOWAIT | M_ZERO))) 2758 return ENOMEM; 2759 |
2667 if (ata_raid_rw(parent, PR_LBA(parent), | 2760 if (ata_raid_rw(parent, PROMISE_LBA(parent), |
2668 meta, sizeof(struct promise_raid_conf), ATA_R_READ)) { 2669 if (testing || bootverbose) 2670 device_printf(parent, "%s read metadata failed\n", 2671 native ? "FreeBSD" : "Promise"); 2672 goto promise_out; 2673 } 2674 2675 /* check the signature */ --- 292 unchanged lines hidden (view full) --- 2968 } 2969 else 2970 bzero(meta->promise_id, sizeof(meta->promise_id)); 2971 meta->checksum = 0; 2972 for (ckptr = (int32_t *)meta, count = 0; count < 511; count++) 2973 meta->checksum += *ckptr++; 2974 if (testing || bootverbose) 2975 ata_raid_promise_print_meta(meta); | 2761 meta, sizeof(struct promise_raid_conf), ATA_R_READ)) { 2762 if (testing || bootverbose) 2763 device_printf(parent, "%s read metadata failed\n", 2764 native ? "FreeBSD" : "Promise"); 2765 goto promise_out; 2766 } 2767 2768 /* check the signature */ --- 292 unchanged lines hidden (view full) --- 3061 } 3062 else 3063 bzero(meta->promise_id, sizeof(meta->promise_id)); 3064 meta->checksum = 0; 3065 for (ckptr = (int32_t *)meta, count = 0; count < 511; count++) 3066 meta->checksum += *ckptr++; 3067 if (testing || bootverbose) 3068 ata_raid_promise_print_meta(meta); |
2976 if (ata_raid_rw(rdp->disks[disk].dev, PR_LBA(rdp->disks[disk].dev), | 3069 if (ata_raid_rw(rdp->disks[disk].dev, 3070 PROMISE_LBA(rdp->disks[disk].dev), |
2977 meta, sizeof(struct promise_raid_conf), 2978 ATA_R_WRITE | ATA_R_DIRECT)) { 2979 device_printf(rdp->disks[disk].dev, "write metadata failed\n"); 2980 error = EIO; 2981 } 2982 } 2983 } 2984 free(meta, M_AR); --- 372 unchanged lines hidden (view full) --- 3357 3358 /* check if this is a VIA RAID struct */ 3359 if (meta->magic != VIA_MAGIC) { 3360 if (testing || bootverbose) 3361 device_printf(parent, "VIA check1 failed\n"); 3362 goto via_out; 3363 } 3364 | 3071 meta, sizeof(struct promise_raid_conf), 3072 ATA_R_WRITE | ATA_R_DIRECT)) { 3073 device_printf(rdp->disks[disk].dev, "write metadata failed\n"); 3074 error = EIO; 3075 } 3076 } 3077 } 3078 free(meta, M_AR); --- 372 unchanged lines hidden (view full) --- 3451 3452 /* check if this is a VIA RAID struct */ 3453 if (meta->magic != VIA_MAGIC) { 3454 if (testing || bootverbose) 3455 device_printf(parent, "VIA check1 failed\n"); 3456 goto via_out; 3457 } 3458 |
3365 /* calc the checksum and compare for valid */ | 3459 /* calculate checksum and compare for valid */ |
3366 for (checksum = 0, ptr = (u_int8_t *)meta, count = 0; count < 50; count++) 3367 checksum += *ptr++; 3368 if (checksum != meta->checksum) { 3369 if (testing || bootverbose) 3370 device_printf(parent, "VIA check2 failed\n"); 3371 goto via_out; 3372 } 3373 --- 16 unchanged lines hidden (view full) --- 3390 continue; 3391 3392 if (raid->format == AR_F_VIA_RAID && (raid->magic_0 != meta->disks[0])) 3393 continue; 3394 3395 switch (meta->type & VIA_T_MASK) { 3396 case VIA_T_RAID0: 3397 raid->type = AR_T_RAID0; | 3460 for (checksum = 0, ptr = (u_int8_t *)meta, count = 0; count < 50; count++) 3461 checksum += *ptr++; 3462 if (checksum != meta->checksum) { 3463 if (testing || bootverbose) 3464 device_printf(parent, "VIA check2 failed\n"); 3465 goto via_out; 3466 } 3467 --- 16 unchanged lines hidden (view full) --- 3484 continue; 3485 3486 if (raid->format == AR_F_VIA_RAID && (raid->magic_0 != meta->disks[0])) 3487 continue; 3488 3489 switch (meta->type & VIA_T_MASK) { 3490 case VIA_T_RAID0: 3491 raid->type = AR_T_RAID0; |
3398 raid->width = meta->stripe_layout & VIA_L_MASK; | 3492 raid->width = meta->stripe_layout & VIA_L_DISKS; |
3399 if (!raid->total_sectors || 3400 (raid->total_sectors > (raid->width * meta->disk_sectors))) 3401 raid->total_sectors = raid->width * meta->disk_sectors; 3402 break; 3403 3404 case VIA_T_RAID1: 3405 raid->type = AR_T_RAID1; 3406 raid->width = 1; 3407 raid->total_sectors = meta->disk_sectors; 3408 break; 3409 3410 case VIA_T_RAID01: 3411 raid->type = AR_T_RAID01; | 3493 if (!raid->total_sectors || 3494 (raid->total_sectors > (raid->width * meta->disk_sectors))) 3495 raid->total_sectors = raid->width * meta->disk_sectors; 3496 break; 3497 3498 case VIA_T_RAID1: 3499 raid->type = AR_T_RAID1; 3500 raid->width = 1; 3501 raid->total_sectors = meta->disk_sectors; 3502 break; 3503 3504 case VIA_T_RAID01: 3505 raid->type = AR_T_RAID01; |
3412 raid->width = meta->stripe_layout & VIA_L_MASK; | 3506 raid->width = meta->stripe_layout & VIA_L_DISKS; |
3413 if (!raid->total_sectors || 3414 (raid->total_sectors > (raid->width * meta->disk_sectors))) 3415 raid->total_sectors = raid->width * meta->disk_sectors; 3416 break; 3417 3418 case VIA_T_RAID5: 3419 raid->type = AR_T_RAID5; | 3507 if (!raid->total_sectors || 3508 (raid->total_sectors > (raid->width * meta->disk_sectors))) 3509 raid->total_sectors = raid->width * meta->disk_sectors; 3510 break; 3511 3512 case VIA_T_RAID5: 3513 raid->type = AR_T_RAID5; |
3420 raid->width = meta->stripe_layout & VIA_L_MASK; | 3514 raid->width = meta->stripe_layout & VIA_L_DISKS; |
3421 if (!raid->total_sectors || 3422 (raid->total_sectors > ((raid->width - 1)*meta->disk_sectors))) 3423 raid->total_sectors = (raid->width - 1) * meta->disk_sectors; 3424 break; 3425 3426 case VIA_T_SPAN: 3427 raid->type = AR_T_SPAN; 3428 raid->width = 1; --- 4 unchanged lines hidden (view full) --- 3433 device_printf(parent,"VIA unknown RAID type 0x%02x\n", meta->type); 3434 free(raidp[array], M_AR); 3435 raidp[array] = NULL; 3436 goto via_out; 3437 } 3438 raid->magic_0 = meta->disks[0]; 3439 raid->format = AR_F_VIA_RAID; 3440 raid->generation = 0; | 3515 if (!raid->total_sectors || 3516 (raid->total_sectors > ((raid->width - 1)*meta->disk_sectors))) 3517 raid->total_sectors = (raid->width - 1) * meta->disk_sectors; 3518 break; 3519 3520 case VIA_T_SPAN: 3521 raid->type = AR_T_SPAN; 3522 raid->width = 1; --- 4 unchanged lines hidden (view full) --- 3527 device_printf(parent,"VIA unknown RAID type 0x%02x\n", meta->type); 3528 free(raidp[array], M_AR); 3529 raidp[array] = NULL; 3530 goto via_out; 3531 } 3532 raid->magic_0 = meta->disks[0]; 3533 raid->format = AR_F_VIA_RAID; 3534 raid->generation = 0; |
3441 raid->interleave = 0x08 << (meta->stripe_layout >> VIA_L_SHIFT); | 3535 raid->interleave = 3536 0x08 << ((meta->stripe_layout & VIA_L_MASK) >> VIA_L_SHIFT); |
3442 for (count = 0, disk = 0; disk < 8; disk++) 3443 if (meta->disks[disk]) 3444 count++; 3445 raid->total_disks = count; 3446 raid->heads = 255; 3447 raid->sectors = 63; 3448 raid->cylinders = raid->total_sectors / (63 * 255); 3449 raid->offset_sectors = 0; 3450 raid->rebuild_lba = 0; 3451 raid->lun = array; 3452 | 3537 for (count = 0, disk = 0; disk < 8; disk++) 3538 if (meta->disks[disk]) 3539 count++; 3540 raid->total_disks = count; 3541 raid->heads = 255; 3542 raid->sectors = 63; 3543 raid->cylinders = raid->total_sectors / (63 * 255); 3544 raid->offset_sectors = 0; 3545 raid->rebuild_lba = 0; 3546 raid->lun = array; 3547 |
3453 for (disk = 0; disk < 8; disk++) { | 3548 for (disk = 0; disk < raid->total_disks; disk++) { |
3454 if (meta->disks[disk] == meta->disk_id) { 3455 raid->disks[disk].dev = parent; | 3549 if (meta->disks[disk] == meta->disk_id) { 3550 raid->disks[disk].dev = parent; |
3551 bcopy(&meta->disk_id, raid->disks[disk].serial, 3552 sizeof(u_int32_t)); |
|
3456 raid->disks[disk].sectors = meta->disk_sectors; 3457 raid->disks[disk].flags = 3458 (AR_DF_ONLINE | AR_DF_PRESENT | AR_DF_ASSIGNED); 3459 ars->raid[raid->volume] = raid; 3460 ars->disk_number[raid->volume] = disk; 3461 retval = 1; 3462 break; 3463 } 3464 } 3465 break; 3466 } 3467 3468via_out: 3469 free(meta, M_AR); 3470 return retval; 3471} | 3553 raid->disks[disk].sectors = meta->disk_sectors; 3554 raid->disks[disk].flags = 3555 (AR_DF_ONLINE | AR_DF_PRESENT | AR_DF_ASSIGNED); 3556 ars->raid[raid->volume] = raid; 3557 ars->disk_number[raid->volume] = disk; 3558 retval = 1; 3559 break; 3560 } 3561 } 3562 break; 3563 } 3564 3565via_out: 3566 free(meta, M_AR); 3567 return retval; 3568} |
3569static int 3570ata_raid_via_write_meta(struct ar_softc *rdp) 3571{ 3572 struct via_raid_conf *meta; 3573 int disk, error = 0; |
|
3472 | 3574 |
3575 if (!(meta = (struct via_raid_conf *) 3576 malloc(sizeof(struct via_raid_conf), M_AR, M_NOWAIT | M_ZERO))) { 3577 printf("ar%d: failed to allocate metadata storage\n", rdp->lun); 3578 return ENOMEM; 3579 } 3580 3581 rdp->generation++; 3582 3583 meta->magic = VIA_MAGIC; 3584 meta->dummy_0 = 0x02; 3585 switch (rdp->type) { 3586 case AR_T_SPAN: 3587 meta->type = VIA_T_SPAN; 3588 meta->stripe_layout = (rdp->total_disks & VIA_L_DISKS); 3589 break; 3590 3591 case AR_T_RAID0: 3592 meta->type = VIA_T_RAID0; 3593 meta->stripe_layout = ((rdp->interleave >> 1) & VIA_L_MASK); 3594 meta->stripe_layout |= (rdp->total_disks & VIA_L_DISKS); 3595 break; 3596 3597 case AR_T_RAID1: 3598 meta->type = VIA_T_RAID1; 3599 meta->stripe_layout = (rdp->total_disks & VIA_L_DISKS); 3600 break; 3601 3602 case AR_T_RAID5: 3603 meta->type = VIA_T_RAID5; 3604 meta->stripe_layout = ((rdp->interleave >> 1) & VIA_L_MASK); 3605 meta->stripe_layout |= (rdp->total_disks & VIA_L_DISKS); 3606 break; 3607 3608 case AR_T_RAID01: 3609 meta->type = VIA_T_RAID01; 3610 meta->stripe_layout = ((rdp->interleave >> 1) & VIA_L_MASK); 3611 meta->stripe_layout |= (rdp->width & VIA_L_DISKS); 3612 break; 3613 3614 default: 3615 free(meta, M_AR); 3616 return ENODEV; 3617 } 3618 meta->type |= VIA_T_BOOTABLE; /* XXX SOS */ 3619 meta->disk_sectors = 3620 rdp->total_sectors / (rdp->width - (rdp->type == AR_RAID5)); 3621 for (disk = 0; disk < rdp->total_disks; disk++) 3622 meta->disks[disk] = (u_int32_t)rdp->disks[disk].dev; 3623 3624 for (disk = 0; disk < rdp->total_disks; disk++) { 3625 if (rdp->disks[disk].dev) { 3626 u_int8_t *ptr; 3627 int count; 3628 3629 meta->disk_index = disk * sizeof(u_int32_t); 3630 if (rdp->type == AR_T_RAID01) 3631 meta->disk_index = ((meta->disk_index & 0x08) << 2) | 3632 (meta->disk_index & ~0x08); 3633 meta->disk_id = meta->disks[disk]; 3634 meta->checksum = 0; 3635 for (ptr = (u_int8_t *)meta, count = 0; count < 50; count++) 3636 meta->checksum += *ptr++; 3637 3638 if (testing || bootverbose) 3639 ata_raid_via_print_meta(meta); 3640 3641 if (ata_raid_rw(rdp->disks[disk].dev, 3642 VIA_LBA(rdp->disks[disk].dev), 3643 meta, sizeof(struct via_raid_conf), 3644 ATA_R_WRITE | ATA_R_DIRECT)) { 3645 device_printf(rdp->disks[disk].dev, "write metadata failed\n"); 3646 error = EIO; 3647 } 3648 } 3649 } 3650 free(meta, M_AR); 3651 return error; 3652} 3653 |
|
3473static struct ata_request * 3474ata_raid_init_request(struct ar_softc *rdp, struct bio *bio) 3475{ 3476 struct ata_request *request; 3477 3478 if (!(request = ata_alloc_request())) { 3479 printf("FAILURE - out of memory in ata_raid_init_request\n"); 3480 return NULL; --- 943 unchanged lines hidden (view full) --- 4424 printf("*************** ATA VIA Metadata ****************\n"); 4425 printf("magic 0x%02x\n", meta->magic); 4426 printf("dummy_0 0x%02x\n", meta->dummy_0); 4427 printf("type %s\n", 4428 ata_raid_via_type(meta->type & VIA_T_MASK)); 4429 printf("bootable %d\n", meta->type & VIA_T_BOOTABLE); 4430 printf("unknown %d\n", meta->type & VIA_T_UNKNOWN); 4431 printf("disk_index 0x%02x\n", meta->disk_index); | 3654static struct ata_request * 3655ata_raid_init_request(struct ar_softc *rdp, struct bio *bio) 3656{ 3657 struct ata_request *request; 3658 3659 if (!(request = ata_alloc_request())) { 3660 printf("FAILURE - out of memory in ata_raid_init_request\n"); 3661 return NULL; --- 943 unchanged lines hidden (view full) --- 4605 printf("*************** ATA VIA Metadata ****************\n"); 4606 printf("magic 0x%02x\n", meta->magic); 4607 printf("dummy_0 0x%02x\n", meta->dummy_0); 4608 printf("type %s\n", 4609 ata_raid_via_type(meta->type & VIA_T_MASK)); 4610 printf("bootable %d\n", meta->type & VIA_T_BOOTABLE); 4611 printf("unknown %d\n", meta->type & VIA_T_UNKNOWN); 4612 printf("disk_index 0x%02x\n", meta->disk_index); |
4432 printf("stripe_disks %d\n", meta->stripe_layout & VIA_L_MASK); 4433 printf("stripe_sectors %d\n", 4434 0x08 << (meta->stripe_layout >> VIA_L_SHIFT)); | 4613 printf("stripe_layout 0x%02x\n", meta->stripe_layout); 4614 printf(" stripe_disks %d\n", meta->stripe_layout & VIA_L_DISKS); 4615 printf(" stripe_sectors %d\n", 4616 0x08 << ((meta->stripe_layout & VIA_L_MASK) >> VIA_L_SHIFT)); |
4435 printf("disk_sectors %llu\n", 4436 (unsigned long long)meta->disk_sectors); 4437 printf("disk_id 0x%08x\n", meta->disk_id); 4438 printf("DISK# disk_id\n"); 4439 for (i = 0; i < 8; i++) { 4440 if (meta->disks[i]) 4441 printf(" %d 0x%08x\n", i, meta->disks[i]); 4442 } 4443 printf("checksum 0x%02x\n", meta->checksum); 4444 printf("=================================================\n"); 4445} | 4617 printf("disk_sectors %llu\n", 4618 (unsigned long long)meta->disk_sectors); 4619 printf("disk_id 0x%08x\n", meta->disk_id); 4620 printf("DISK# disk_id\n"); 4621 for (i = 0; i < 8; i++) { 4622 if (meta->disks[i]) 4623 printf(" %d 0x%08x\n", i, meta->disks[i]); 4624 } 4625 printf("checksum 0x%02x\n", meta->checksum); 4626 printf("=================================================\n"); 4627} |