No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / raidframe / rf_raid4.c
blobeebf68d213d918ad2c4d1ebde1740c1902c32d17
1 /* $NetBSD: rf_raid4.c,v 1.11 2006/10/12 01:31:52 christos Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
6 * Author: Rachad Youssef
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 /***************************************
31 * rf_raid4.c -- implements RAID Level 4
33 ***************************************/
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: rf_raid4.c,v 1.11 2006/10/12 01:31:52 christos Exp $");
38 #include "rf_raid.h"
39 #include "rf_dag.h"
40 #include "rf_dagutils.h"
41 #include "rf_dagfuncs.h"
42 #include "rf_dagffrd.h"
43 #include "rf_dagffwr.h"
44 #include "rf_dagdegrd.h"
45 #include "rf_dagdegwr.h"
46 #include "rf_raid4.h"
47 #include "rf_general.h"
49 typedef struct RF_Raid4ConfigInfo_s {
50 RF_RowCol_t *stripeIdentifier; /* filled in at config time & used by
51 * IdentifyStripe */
52 } RF_Raid4ConfigInfo_t;
56 int
57 rf_ConfigureRAID4(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
58 RF_Config_t *cfgPtr)
60 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
61 RF_Raid4ConfigInfo_t *info;
62 int i;
64 /* create a RAID level 4 configuration structure ... */
65 RF_MallocAndAdd(info, sizeof(RF_Raid4ConfigInfo_t), (RF_Raid4ConfigInfo_t *), raidPtr->cleanupList);
66 if (info == NULL)
67 return (ENOMEM);
68 layoutPtr->layoutSpecificInfo = (void *) info;
70 /* ... and fill it in. */
71 RF_MallocAndAdd(info->stripeIdentifier, raidPtr->numCol * sizeof(RF_RowCol_t), (RF_RowCol_t *), raidPtr->cleanupList);
72 if (info->stripeIdentifier == NULL)
73 return (ENOMEM);
74 for (i = 0; i < raidPtr->numCol; i++)
75 info->stripeIdentifier[i] = i;
77 /* fill in the remaining layout parameters */
78 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
79 layoutPtr->numDataCol = raidPtr->numCol - 1;
80 layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
81 layoutPtr->numParityCol = 1;
82 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
84 return (0);
87 int
88 rf_GetDefaultNumFloatingReconBuffersRAID4(RF_Raid_t *raidPtr)
90 return (20);
93 RF_HeadSepLimit_t
94 rf_GetDefaultHeadSepLimitRAID4(RF_Raid_t *raidPtr)
96 return (20);
99 void
100 rf_MapSectorRAID4(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
101 RF_RowCol_t *col, RF_SectorNum_t *diskSector,
102 int remap)
104 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
105 *col = SUID % raidPtr->Layout.numDataCol;
106 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
107 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
110 void
111 rf_MapParityRAID4(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
112 RF_RowCol_t *col, RF_SectorNum_t *diskSector,
113 int remap)
115 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
117 *col = raidPtr->Layout.numDataCol;
118 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
119 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
122 void
123 rf_IdentifyStripeRAID4(RF_Raid_t *raidPtr, RF_RaidAddr_t addr,
124 RF_RowCol_t **diskids)
126 RF_Raid4ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
128 *diskids = info->stripeIdentifier;
131 void
132 rf_MapSIDToPSIDRAID4(RF_RaidLayout_t *layoutPtr,
133 RF_StripeNum_t stripeID,
134 RF_StripeNum_t *psID, RF_ReconUnitNum_t *which_ru)
136 *which_ru = 0;
137 *psID = stripeID;