xref: /netbsd-src/sys/dev/raidframe/rf_raid4.c (revision 95d875fb90b1458e4f1de6950286ddcd6644bc61)
1 /*	$NetBSD: rf_raid4.c,v 1.3 1999/02/05 00:06:16 oster Exp $	*/
2 /*
3  * Copyright (c) 1995 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Rachad Youssef
7  *
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.
13  *
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.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie the
26  * rights to redistribute these changes.
27  */
28 
29 /***************************************
30  *
31  * rf_raid4.c -- implements RAID Level 4
32  *
33  ***************************************/
34 
35 #include "rf_raid.h"
36 #include "rf_dag.h"
37 #include "rf_dagutils.h"
38 #include "rf_dagfuncs.h"
39 #include "rf_dagffrd.h"
40 #include "rf_dagffwr.h"
41 #include "rf_dagdegrd.h"
42 #include "rf_dagdegwr.h"
43 #include "rf_threadid.h"
44 #include "rf_raid4.h"
45 #include "rf_general.h"
46 
47 typedef struct RF_Raid4ConfigInfo_s {
48 	RF_RowCol_t *stripeIdentifier;	/* filled in at config time & used by
49 					 * IdentifyStripe */
50 }       RF_Raid4ConfigInfo_t;
51 
52 
53 
54 int
55 rf_ConfigureRAID4(
56     RF_ShutdownList_t ** listp,
57     RF_Raid_t * raidPtr,
58     RF_Config_t * cfgPtr)
59 {
60 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
61 	RF_Raid4ConfigInfo_t *info;
62 	int     i;
63 
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;
69 
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;
76 
77 	RF_ASSERT(raidPtr->numRow == 1);
78 
79 	/* fill in the remaining layout parameters */
80 	layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
81 	layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
82 	layoutPtr->numDataCol = raidPtr->numCol - 1;
83 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
84 	layoutPtr->numParityCol = 1;
85 	raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
86 
87 	return (0);
88 }
89 
90 int
91 rf_GetDefaultNumFloatingReconBuffersRAID4(RF_Raid_t * raidPtr)
92 {
93 	return (20);
94 }
95 
96 RF_HeadSepLimit_t
97 rf_GetDefaultHeadSepLimitRAID4(RF_Raid_t * raidPtr)
98 {
99 	return (20);
100 }
101 
102 void
103 rf_MapSectorRAID4(
104     RF_Raid_t * raidPtr,
105     RF_RaidAddr_t raidSector,
106     RF_RowCol_t * row,
107     RF_RowCol_t * col,
108     RF_SectorNum_t * diskSector,
109     int remap)
110 {
111 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
112 	*row = 0;
113 	*col = SUID % raidPtr->Layout.numDataCol;
114 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
115 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
116 }
117 
118 void
119 rf_MapParityRAID4(
120     RF_Raid_t * raidPtr,
121     RF_RaidAddr_t raidSector,
122     RF_RowCol_t * row,
123     RF_RowCol_t * col,
124     RF_SectorNum_t * diskSector,
125     int remap)
126 {
127 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
128 
129 	*row = 0;
130 	*col = raidPtr->Layout.numDataCol;
131 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
132 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
133 }
134 
135 void
136 rf_IdentifyStripeRAID4(
137     RF_Raid_t * raidPtr,
138     RF_RaidAddr_t addr,
139     RF_RowCol_t ** diskids,
140     RF_RowCol_t * outRow)
141 {
142 	RF_Raid4ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
143 
144 	*outRow = 0;
145 	*diskids = info->stripeIdentifier;
146 }
147 
148 void
149 rf_MapSIDToPSIDRAID4(
150     RF_RaidLayout_t * layoutPtr,
151     RF_StripeNum_t stripeID,
152     RF_StripeNum_t * psID,
153     RF_ReconUnitNum_t * which_ru)
154 {
155 	*which_ru = 0;
156 	*psID = stripeID;
157 }
158