Home | History | Annotate | Line # | Download | only in raidframe
rf_dagfuncs.c revision 1.21
      1  1.21     oster /*	$NetBSD: rf_dagfuncs.c,v 1.21 2005/02/12 03:27:33 oster Exp $	*/
      2   1.1     oster /*
      3   1.1     oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4   1.1     oster  * All rights reserved.
      5   1.1     oster  *
      6   1.1     oster  * Author: Mark Holland, William V. Courtright II
      7   1.1     oster  *
      8   1.1     oster  * Permission to use, copy, modify and distribute this software and
      9   1.1     oster  * its documentation is hereby granted, provided that both the copyright
     10   1.1     oster  * notice and this permission notice appear in all copies of the
     11   1.1     oster  * software, derivative works or modified versions, and any portions
     12   1.1     oster  * thereof, and that both notices appear in supporting documentation.
     13   1.1     oster  *
     14   1.1     oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15   1.1     oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16   1.1     oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17   1.1     oster  *
     18   1.1     oster  * Carnegie Mellon requests users of this software to return to
     19   1.1     oster  *
     20   1.1     oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21   1.1     oster  *  School of Computer Science
     22   1.1     oster  *  Carnegie Mellon University
     23   1.1     oster  *  Pittsburgh PA 15213-3890
     24   1.1     oster  *
     25   1.1     oster  * any improvements or extensions that they make and grant Carnegie the
     26   1.1     oster  * rights to redistribute these changes.
     27   1.1     oster  */
     28   1.1     oster 
     29   1.1     oster /*
     30   1.1     oster  * dagfuncs.c -- DAG node execution routines
     31   1.1     oster  *
     32   1.1     oster  * Rules:
     33   1.1     oster  * 1. Every DAG execution function must eventually cause node->status to
     34   1.1     oster  *    get set to "good" or "bad", and "FinishNode" to be called. In the
     35   1.1     oster  *    case of nodes that complete immediately (xor, NullNodeFunc, etc),
     36   1.1     oster  *    the node execution function can do these two things directly. In
     37   1.1     oster  *    the case of nodes that have to wait for some event (a disk read to
     38   1.1     oster  *    complete, a lock to be released, etc) to occur before they can
     39   1.1     oster  *    complete, this is typically achieved by having whatever module
     40   1.1     oster  *    is doing the operation call GenericWakeupFunc upon completion.
     41   1.1     oster  * 2. DAG execution functions should check the status in the DAG header
     42   1.1     oster  *    and NOP out their operations if the status is not "enable". However,
     43   1.1     oster  *    execution functions that release resources must be sure to release
     44   1.1     oster  *    them even when they NOP out the function that would use them.
     45   1.1     oster  *    Functions that acquire resources should go ahead and acquire them
     46   1.1     oster  *    even when they NOP, so that a downstream release node will not have
     47   1.1     oster  *    to check to find out whether or not the acquire was suppressed.
     48   1.1     oster  */
     49   1.8     lukem 
     50   1.8     lukem #include <sys/cdefs.h>
     51  1.21     oster __KERNEL_RCSID(0, "$NetBSD: rf_dagfuncs.c,v 1.21 2005/02/12 03:27:33 oster Exp $");
     52   1.1     oster 
     53   1.7       mrg #include <sys/param.h>
     54   1.1     oster #include <sys/ioctl.h>
     55   1.1     oster 
     56   1.1     oster #include "rf_archs.h"
     57   1.1     oster #include "rf_raid.h"
     58   1.1     oster #include "rf_dag.h"
     59   1.1     oster #include "rf_layout.h"
     60   1.1     oster #include "rf_etimer.h"
     61   1.1     oster #include "rf_acctrace.h"
     62   1.1     oster #include "rf_diskqueue.h"
     63   1.1     oster #include "rf_dagfuncs.h"
     64   1.1     oster #include "rf_general.h"
     65   1.1     oster #include "rf_engine.h"
     66   1.1     oster #include "rf_dagutils.h"
     67   1.1     oster 
     68   1.1     oster #include "rf_kintf.h"
     69   1.1     oster 
     70   1.1     oster #if RF_INCLUDE_PARITYLOGGING > 0
     71   1.1     oster #include "rf_paritylog.h"
     72   1.3     oster #endif				/* RF_INCLUDE_PARITYLOGGING > 0 */
     73   1.1     oster 
     74   1.3     oster int     (*rf_DiskReadFunc) (RF_DagNode_t *);
     75   1.3     oster int     (*rf_DiskWriteFunc) (RF_DagNode_t *);
     76   1.3     oster int     (*rf_DiskReadUndoFunc) (RF_DagNode_t *);
     77   1.3     oster int     (*rf_DiskWriteUndoFunc) (RF_DagNode_t *);
     78   1.3     oster int     (*rf_DiskUnlockFunc) (RF_DagNode_t *);
     79   1.3     oster int     (*rf_DiskUnlockUndoFunc) (RF_DagNode_t *);
     80   1.3     oster int     (*rf_RegularXorUndoFunc) (RF_DagNode_t *);
     81   1.3     oster int     (*rf_SimpleXorUndoFunc) (RF_DagNode_t *);
     82   1.3     oster int     (*rf_RecoveryXorUndoFunc) (RF_DagNode_t *);
     83   1.1     oster 
     84  1.14     oster /*****************************************************************************
     85   1.1     oster  * main (only) configuration routine for this module
     86  1.14     oster  ****************************************************************************/
     87   1.3     oster int
     88  1.15     oster rf_ConfigureDAGFuncs(RF_ShutdownList_t **listp)
     89   1.3     oster {
     90  1.14     oster 	RF_ASSERT(((sizeof(long) == 8) && RF_LONGSHIFT == 3) ||
     91  1.14     oster 		  ((sizeof(long) == 4) && RF_LONGSHIFT == 2));
     92   1.3     oster 	rf_DiskReadFunc = rf_DiskReadFuncForThreads;
     93   1.3     oster 	rf_DiskReadUndoFunc = rf_DiskUndoFunc;
     94   1.3     oster 	rf_DiskWriteFunc = rf_DiskWriteFuncForThreads;
     95   1.3     oster 	rf_DiskWriteUndoFunc = rf_DiskUndoFunc;
     96   1.3     oster 	rf_DiskUnlockFunc = rf_DiskUnlockFuncForThreads;
     97   1.3     oster 	rf_DiskUnlockUndoFunc = rf_NullNodeUndoFunc;
     98   1.3     oster 	rf_RegularXorUndoFunc = rf_NullNodeUndoFunc;
     99   1.3     oster 	rf_SimpleXorUndoFunc = rf_NullNodeUndoFunc;
    100   1.3     oster 	rf_RecoveryXorUndoFunc = rf_NullNodeUndoFunc;
    101   1.3     oster 	return (0);
    102   1.1     oster }
    103   1.1     oster 
    104   1.1     oster 
    105   1.1     oster 
    106  1.14     oster /*****************************************************************************
    107   1.1     oster  * the execution function associated with a terminate node
    108  1.14     oster  ****************************************************************************/
    109   1.3     oster int
    110  1.15     oster rf_TerminateFunc(RF_DagNode_t *node)
    111   1.1     oster {
    112   1.3     oster 	RF_ASSERT(node->dagHdr->numCommits == node->dagHdr->numCommitNodes);
    113   1.3     oster 	node->status = rf_good;
    114   1.3     oster 	return (rf_FinishNode(node, RF_THREAD_CONTEXT));
    115   1.1     oster }
    116   1.1     oster 
    117   1.3     oster int
    118  1.15     oster rf_TerminateUndoFunc(RF_DagNode_t *node)
    119   1.1     oster {
    120   1.3     oster 	return (0);
    121   1.1     oster }
    122   1.1     oster 
    123   1.1     oster 
    124  1.15     oster /*****************************************************************************
    125   1.1     oster  * execution functions associated with a mirror node
    126   1.1     oster  *
    127   1.1     oster  * parameters:
    128   1.1     oster  *
    129   1.1     oster  * 0 - physical disk addres of data
    130   1.1     oster  * 1 - buffer for holding read data
    131   1.1     oster  * 2 - parity stripe ID
    132   1.1     oster  * 3 - flags
    133   1.1     oster  * 4 - physical disk address of mirror (parity)
    134   1.1     oster  *
    135  1.15     oster  ****************************************************************************/
    136   1.1     oster 
    137   1.3     oster int
    138  1.15     oster rf_DiskReadMirrorIdleFunc(RF_DagNode_t *node)
    139   1.1     oster {
    140   1.3     oster 	/* select the mirror copy with the shortest queue and fill in node
    141   1.3     oster 	 * parameters with physical disk address */
    142   1.1     oster 
    143   1.3     oster 	rf_SelectMirrorDiskIdle(node);
    144   1.3     oster 	return (rf_DiskReadFunc(node));
    145   1.1     oster }
    146   1.1     oster 
    147  1.11     oster #if (RF_INCLUDE_CHAINDECLUSTER > 0) || (RF_INCLUDE_INTERDECLUSTER > 0) || (RF_DEBUG_VALIDATE_DAG > 0)
    148   1.3     oster int
    149  1.15     oster rf_DiskReadMirrorPartitionFunc(RF_DagNode_t *node)
    150   1.1     oster {
    151   1.3     oster 	/* select the mirror copy with the shortest queue and fill in node
    152   1.3     oster 	 * parameters with physical disk address */
    153   1.1     oster 
    154   1.3     oster 	rf_SelectMirrorDiskPartition(node);
    155   1.3     oster 	return (rf_DiskReadFunc(node));
    156   1.1     oster }
    157  1.11     oster #endif
    158   1.1     oster 
    159   1.3     oster int
    160  1.15     oster rf_DiskReadMirrorUndoFunc(RF_DagNode_t *node)
    161   1.1     oster {
    162   1.3     oster 	return (0);
    163   1.1     oster }
    164   1.1     oster 
    165   1.1     oster 
    166   1.1     oster 
    167   1.1     oster #if RF_INCLUDE_PARITYLOGGING > 0
    168  1.14     oster /*****************************************************************************
    169   1.1     oster  * the execution function associated with a parity log update node
    170  1.14     oster  ****************************************************************************/
    171   1.3     oster int
    172  1.15     oster rf_ParityLogUpdateFunc(RF_DagNode_t *node)
    173   1.3     oster {
    174   1.3     oster 	RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
    175   1.3     oster 	caddr_t buf = (caddr_t) node->params[1].p;
    176   1.3     oster 	RF_ParityLogData_t *logData;
    177  1.19     oster #if RF_ACC_TRACE > 0
    178   1.3     oster 	RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
    179   1.3     oster 	RF_Etimer_t timer;
    180  1.19     oster #endif
    181   1.3     oster 
    182   1.3     oster 	if (node->dagHdr->status == rf_enable) {
    183  1.19     oster #if RF_ACC_TRACE > 0
    184   1.3     oster 		RF_ETIMER_START(timer);
    185  1.19     oster #endif
    186   1.3     oster 		logData = rf_CreateParityLogData(RF_UPDATE, pda, buf,
    187   1.3     oster 		    (RF_Raid_t *) (node->dagHdr->raidPtr),
    188   1.3     oster 		    node->wakeFunc, (void *) node,
    189   1.3     oster 		    node->dagHdr->tracerec, timer);
    190   1.3     oster 		if (logData)
    191   1.3     oster 			rf_ParityLogAppend(logData, RF_FALSE, NULL, RF_FALSE);
    192   1.3     oster 		else {
    193  1.19     oster #if RF_ACC_TRACE > 0
    194   1.3     oster 			RF_ETIMER_STOP(timer);
    195   1.3     oster 			RF_ETIMER_EVAL(timer);
    196   1.3     oster 			tracerec->plog_us += RF_ETIMER_VAL_US(timer);
    197  1.19     oster #endif
    198   1.3     oster 			(node->wakeFunc) (node, ENOMEM);
    199   1.3     oster 		}
    200   1.1     oster 	}
    201   1.3     oster 	return (0);
    202   1.1     oster }
    203   1.1     oster 
    204   1.1     oster 
    205  1.15     oster /*****************************************************************************
    206   1.1     oster  * the execution function associated with a parity log overwrite node
    207  1.15     oster  ****************************************************************************/
    208   1.3     oster int
    209  1.15     oster rf_ParityLogOverwriteFunc(RF_DagNode_t *node)
    210   1.3     oster {
    211   1.3     oster 	RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
    212   1.3     oster 	caddr_t buf = (caddr_t) node->params[1].p;
    213   1.3     oster 	RF_ParityLogData_t *logData;
    214  1.19     oster #if RF_ACC_TRACE > 0
    215   1.3     oster 	RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
    216   1.3     oster 	RF_Etimer_t timer;
    217  1.19     oster #endif
    218   1.3     oster 
    219   1.3     oster 	if (node->dagHdr->status == rf_enable) {
    220  1.19     oster #if RF_ACC_TRACE > 0
    221   1.3     oster 		RF_ETIMER_START(timer);
    222  1.19     oster #endif
    223  1.14     oster 		logData = rf_CreateParityLogData(RF_OVERWRITE, pda, buf,
    224  1.14     oster (RF_Raid_t *) (node->dagHdr->raidPtr),
    225   1.3     oster 		    node->wakeFunc, (void *) node, node->dagHdr->tracerec, timer);
    226   1.3     oster 		if (logData)
    227   1.3     oster 			rf_ParityLogAppend(logData, RF_FALSE, NULL, RF_FALSE);
    228   1.3     oster 		else {
    229  1.19     oster #if RF_ACC_TRACE > 0
    230   1.3     oster 			RF_ETIMER_STOP(timer);
    231   1.3     oster 			RF_ETIMER_EVAL(timer);
    232   1.3     oster 			tracerec->plog_us += RF_ETIMER_VAL_US(timer);
    233  1.19     oster #endif
    234   1.3     oster 			(node->wakeFunc) (node, ENOMEM);
    235   1.3     oster 		}
    236   1.1     oster 	}
    237   1.3     oster 	return (0);
    238   1.1     oster }
    239   1.1     oster 
    240   1.3     oster int
    241  1.15     oster rf_ParityLogUpdateUndoFunc(RF_DagNode_t *node)
    242   1.1     oster {
    243   1.3     oster 	return (0);
    244   1.1     oster }
    245   1.1     oster 
    246   1.3     oster int
    247  1.15     oster rf_ParityLogOverwriteUndoFunc(RF_DagNode_t *node)
    248   1.1     oster {
    249   1.3     oster 	return (0);
    250   1.1     oster }
    251  1.10     oster #endif				/* RF_INCLUDE_PARITYLOGGING > 0 */
    252  1.10     oster 
    253  1.14     oster /*****************************************************************************
    254   1.1     oster  * the execution function associated with a NOP node
    255  1.14     oster  ****************************************************************************/
    256   1.3     oster int
    257  1.15     oster rf_NullNodeFunc(RF_DagNode_t *node)
    258   1.1     oster {
    259   1.3     oster 	node->status = rf_good;
    260   1.3     oster 	return (rf_FinishNode(node, RF_THREAD_CONTEXT));
    261   1.1     oster }
    262   1.1     oster 
    263   1.3     oster int
    264  1.15     oster rf_NullNodeUndoFunc(RF_DagNode_t *node)
    265   1.1     oster {
    266   1.3     oster 	node->status = rf_undone;
    267   1.3     oster 	return (rf_FinishNode(node, RF_THREAD_CONTEXT));
    268   1.1     oster }
    269   1.1     oster 
    270   1.1     oster 
    271  1.14     oster /*****************************************************************************
    272   1.1     oster  * the execution function associated with a disk-read node
    273  1.14     oster  ****************************************************************************/
    274   1.3     oster int
    275  1.15     oster rf_DiskReadFuncForThreads(RF_DagNode_t *node)
    276   1.3     oster {
    277   1.3     oster 	RF_DiskQueueData_t *req;
    278   1.3     oster 	RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
    279   1.3     oster 	caddr_t buf = (caddr_t) node->params[1].p;
    280   1.3     oster 	RF_StripeNum_t parityStripeID = (RF_StripeNum_t) node->params[2].v;
    281   1.3     oster 	unsigned priority = RF_EXTRACT_PRIORITY(node->params[3].v);
    282   1.3     oster 	unsigned which_ru = RF_EXTRACT_RU(node->params[3].v);
    283   1.3     oster 	RF_IoType_t iotype = (node->dagHdr->status == rf_enable) ? RF_IO_TYPE_READ : RF_IO_TYPE_NOP;
    284  1.13     oster 	RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
    285   1.3     oster 	void   *b_proc = NULL;
    286   1.1     oster 
    287   1.3     oster 	if (node->dagHdr->bp)
    288   1.3     oster 		b_proc = (void *) ((struct buf *) node->dagHdr->bp)->b_proc;
    289   1.1     oster 
    290   1.3     oster 	req = rf_CreateDiskQueueData(iotype, pda->startSector, pda->numSector,
    291   1.3     oster 	    buf, parityStripeID, which_ru,
    292   1.3     oster 	    (int (*) (void *, int)) node->wakeFunc,
    293  1.19     oster 	    node, NULL,
    294  1.19     oster #if RF_ACC_TRACE > 0
    295  1.19     oster 	     node->dagHdr->tracerec,
    296  1.19     oster #else
    297  1.19     oster              NULL,
    298  1.19     oster #endif
    299  1.21     oster 	    (void *) (node->dagHdr->raidPtr), 0, b_proc, PR_NOWAIT);
    300   1.3     oster 	if (!req) {
    301   1.3     oster 		(node->wakeFunc) (node, ENOMEM);
    302   1.3     oster 	} else {
    303   1.3     oster 		node->dagFuncData = (void *) req;
    304  1.13     oster 		rf_DiskIOEnqueue(&(dqs[pda->col]), req, priority);
    305   1.3     oster 	}
    306   1.3     oster 	return (0);
    307   1.1     oster }
    308   1.1     oster 
    309   1.1     oster 
    310  1.14     oster /*****************************************************************************
    311   1.1     oster  * the execution function associated with a disk-write node
    312  1.14     oster  ****************************************************************************/
    313   1.3     oster int
    314  1.15     oster rf_DiskWriteFuncForThreads(RF_DagNode_t *node)
    315   1.3     oster {
    316   1.3     oster 	RF_DiskQueueData_t *req;
    317   1.3     oster 	RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
    318   1.3     oster 	caddr_t buf = (caddr_t) node->params[1].p;
    319   1.3     oster 	RF_StripeNum_t parityStripeID = (RF_StripeNum_t) node->params[2].v;
    320   1.3     oster 	unsigned priority = RF_EXTRACT_PRIORITY(node->params[3].v);
    321   1.3     oster 	unsigned which_ru = RF_EXTRACT_RU(node->params[3].v);
    322   1.3     oster 	RF_IoType_t iotype = (node->dagHdr->status == rf_enable) ? RF_IO_TYPE_WRITE : RF_IO_TYPE_NOP;
    323  1.13     oster 	RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
    324   1.3     oster 	void   *b_proc = NULL;
    325   1.1     oster 
    326   1.3     oster 	if (node->dagHdr->bp)
    327   1.3     oster 		b_proc = (void *) ((struct buf *) node->dagHdr->bp)->b_proc;
    328   1.1     oster 
    329   1.3     oster 	/* normal processing (rollaway or forward recovery) begins here */
    330   1.3     oster 	req = rf_CreateDiskQueueData(iotype, pda->startSector, pda->numSector,
    331   1.3     oster 	    buf, parityStripeID, which_ru,
    332   1.3     oster 	    (int (*) (void *, int)) node->wakeFunc,
    333   1.3     oster 	    (void *) node, NULL,
    334  1.19     oster #if RF_ACC_TRACE > 0
    335   1.3     oster 	    node->dagHdr->tracerec,
    336  1.19     oster #else
    337  1.19     oster 	    NULL,
    338  1.19     oster #endif
    339   1.3     oster 	    (void *) (node->dagHdr->raidPtr),
    340  1.21     oster 	    0, b_proc, PR_NOWAIT);
    341   1.3     oster 
    342   1.3     oster 	if (!req) {
    343   1.3     oster 		(node->wakeFunc) (node, ENOMEM);
    344   1.3     oster 	} else {
    345   1.3     oster 		node->dagFuncData = (void *) req;
    346  1.13     oster 		rf_DiskIOEnqueue(&(dqs[pda->col]), req, priority);
    347   1.3     oster 	}
    348   1.3     oster 
    349   1.3     oster 	return (0);
    350   1.1     oster }
    351  1.14     oster /*****************************************************************************
    352   1.1     oster  * the undo function for disk nodes
    353   1.1     oster  * Note:  this is not a proper undo of a write node, only locks are released.
    354   1.1     oster  *        old data is not restored to disk!
    355  1.14     oster  ****************************************************************************/
    356   1.3     oster int
    357  1.15     oster rf_DiskUndoFunc(RF_DagNode_t *node)
    358   1.3     oster {
    359   1.3     oster 	RF_DiskQueueData_t *req;
    360   1.3     oster 	RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
    361  1.13     oster 	RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
    362   1.3     oster 
    363   1.3     oster 	req = rf_CreateDiskQueueData(RF_IO_TYPE_NOP,
    364   1.3     oster 	    0L, 0, NULL, 0L, 0,
    365   1.3     oster 	    (int (*) (void *, int)) node->wakeFunc,
    366   1.3     oster 	    (void *) node,
    367  1.19     oster 	    NULL,
    368  1.19     oster #if RF_ACC_TRACE > 0
    369  1.19     oster 	     node->dagHdr->tracerec,
    370  1.19     oster #else
    371  1.19     oster 	     NULL,
    372  1.19     oster #endif
    373   1.3     oster 	    (void *) (node->dagHdr->raidPtr),
    374  1.21     oster 	    RF_UNLOCK_DISK_QUEUE, NULL, PR_NOWAIT);
    375   1.3     oster 	if (!req)
    376   1.3     oster 		(node->wakeFunc) (node, ENOMEM);
    377   1.3     oster 	else {
    378   1.3     oster 		node->dagFuncData = (void *) req;
    379  1.13     oster 		rf_DiskIOEnqueue(&(dqs[pda->col]), req, RF_IO_NORMAL_PRIORITY);
    380   1.3     oster 	}
    381   1.1     oster 
    382   1.3     oster 	return (0);
    383   1.1     oster }
    384  1.14     oster /*****************************************************************************
    385   1.1     oster  * the execution function associated with an "unlock disk queue" node
    386  1.14     oster  ****************************************************************************/
    387   1.3     oster int
    388  1.15     oster rf_DiskUnlockFuncForThreads(RF_DagNode_t *node)
    389   1.3     oster {
    390   1.3     oster 	RF_DiskQueueData_t *req;
    391   1.3     oster 	RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
    392  1.13     oster 	RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
    393   1.3     oster 
    394   1.3     oster 	req = rf_CreateDiskQueueData(RF_IO_TYPE_NOP,
    395   1.3     oster 	    0L, 0, NULL, 0L, 0,
    396   1.3     oster 	    (int (*) (void *, int)) node->wakeFunc,
    397   1.3     oster 	    (void *) node,
    398  1.19     oster 	    NULL,
    399  1.19     oster #if RF_ACC_TRACE > 0
    400  1.19     oster 	    node->dagHdr->tracerec,
    401  1.19     oster #else
    402  1.19     oster 	    NULL,
    403  1.19     oster #endif
    404   1.3     oster 	    (void *) (node->dagHdr->raidPtr),
    405  1.21     oster 	    RF_UNLOCK_DISK_QUEUE, NULL, PR_NOWAIT);
    406   1.3     oster 	if (!req)
    407   1.3     oster 		(node->wakeFunc) (node, ENOMEM);
    408   1.3     oster 	else {
    409   1.3     oster 		node->dagFuncData = (void *) req;
    410  1.13     oster 		rf_DiskIOEnqueue(&(dqs[pda->col]), req, RF_IO_NORMAL_PRIORITY);
    411   1.3     oster 	}
    412   1.1     oster 
    413   1.3     oster 	return (0);
    414   1.1     oster }
    415  1.14     oster /*****************************************************************************
    416  1.14     oster  * Callback routine for DiskRead and DiskWrite nodes.  When the disk
    417  1.14     oster  * op completes, the routine is called to set the node status and
    418  1.14     oster  * inform the execution engine that the node has fired.
    419  1.14     oster  ****************************************************************************/
    420   1.3     oster int
    421  1.15     oster rf_GenericWakeupFunc(RF_DagNode_t *node, int status)
    422   1.3     oster {
    423  1.15     oster 
    424   1.3     oster 	switch (node->status) {
    425   1.3     oster 	case rf_fired:
    426   1.3     oster 		if (status)
    427   1.3     oster 			node->status = rf_bad;
    428   1.3     oster 		else
    429   1.3     oster 			node->status = rf_good;
    430   1.3     oster 		break;
    431   1.3     oster 	case rf_recover:
    432   1.3     oster 		/* probably should never reach this case */
    433   1.3     oster 		if (status)
    434   1.3     oster 			node->status = rf_panic;
    435   1.3     oster 		else
    436   1.3     oster 			node->status = rf_undone;
    437   1.3     oster 		break;
    438   1.3     oster 	default:
    439   1.4     oster 		printf("rf_GenericWakeupFunc:");
    440   1.4     oster 		printf("node->status is %d,", node->status);
    441   1.4     oster 		printf("status is %d \n", status);
    442   1.3     oster 		RF_PANIC();
    443   1.3     oster 		break;
    444   1.3     oster 	}
    445   1.3     oster 	if (node->dagFuncData)
    446   1.3     oster 		rf_FreeDiskQueueData((RF_DiskQueueData_t *) node->dagFuncData);
    447   1.3     oster 	return (rf_FinishNode(node, RF_INTR_CONTEXT));
    448   1.1     oster }
    449   1.1     oster 
    450   1.1     oster 
    451  1.14     oster /*****************************************************************************
    452  1.14     oster  * there are three distinct types of xor nodes:
    453  1.14     oster 
    454  1.14     oster  * A "regular xor" is used in the fault-free case where the access
    455  1.14     oster  * spans a complete stripe unit.  It assumes that the result buffer is
    456  1.14     oster  * one full stripe unit in size, and uses the stripe-unit-offset
    457  1.14     oster  * values that it computes from the PDAs to determine where within the
    458  1.14     oster  * stripe unit to XOR each argument buffer.
    459  1.14     oster  *
    460  1.14     oster  * A "simple xor" is used in the fault-free case where the access
    461  1.14     oster  * touches only a portion of one (or two, in some cases) stripe
    462  1.14     oster  * unit(s).  It assumes that all the argument buffers are of the same
    463  1.14     oster  * size and have the same stripe unit offset.
    464  1.14     oster  *
    465  1.14     oster  * A "recovery xor" is used in the degraded-mode case.  It's similar
    466  1.14     oster  * to the regular xor function except that it takes the failed PDA as
    467  1.14     oster  * an additional parameter, and uses it to determine what portions of
    468  1.14     oster  * the argument buffers need to be xor'd into the result buffer, and
    469  1.14     oster  * where in the result buffer they should go.
    470  1.14     oster  ****************************************************************************/
    471   1.1     oster 
    472   1.1     oster /* xor the params together and store the result in the result field.
    473  1.14     oster  * assume the result field points to a buffer that is the size of one
    474  1.14     oster  * SU, and use the pda params to determine where within the buffer to
    475  1.14     oster  * XOR the input buffers.  */
    476   1.3     oster int
    477  1.15     oster rf_RegularXorFunc(RF_DagNode_t *node)
    478   1.3     oster {
    479   1.3     oster 	RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
    480  1.19     oster #if RF_ACC_TRACE > 0
    481   1.3     oster 	RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
    482   1.3     oster 	RF_Etimer_t timer;
    483  1.19     oster #endif
    484   1.3     oster 	int     i, retcode;
    485   1.1     oster 
    486   1.3     oster 	retcode = 0;
    487   1.3     oster 	if (node->dagHdr->status == rf_enable) {
    488   1.3     oster 		/* don't do the XOR if the input is the same as the output */
    489  1.19     oster #if RF_ACC_TRACE > 0
    490   1.3     oster 		RF_ETIMER_START(timer);
    491  1.19     oster #endif
    492   1.3     oster 		for (i = 0; i < node->numParams - 1; i += 2)
    493   1.3     oster 			if (node->params[i + 1].p != node->results[0]) {
    494   1.3     oster 				retcode = rf_XorIntoBuffer(raidPtr, (RF_PhysDiskAddr_t *) node->params[i].p,
    495  1.17     oster 							   (char *) node->params[i + 1].p, (char *) node->results[0]);
    496   1.3     oster 			}
    497  1.19     oster #if RF_ACC_TRACE > 0
    498   1.3     oster 		RF_ETIMER_STOP(timer);
    499   1.3     oster 		RF_ETIMER_EVAL(timer);
    500   1.3     oster 		tracerec->xor_us += RF_ETIMER_VAL_US(timer);
    501  1.19     oster #endif
    502   1.3     oster 	}
    503   1.3     oster 	return (rf_GenericWakeupFunc(node, retcode));	/* call wake func
    504   1.3     oster 							 * explicitly since no
    505   1.3     oster 							 * I/O in this node */
    506   1.1     oster }
    507   1.1     oster /* xor the inputs into the result buffer, ignoring placement issues */
    508   1.3     oster int
    509  1.15     oster rf_SimpleXorFunc(RF_DagNode_t *node)
    510   1.3     oster {
    511   1.3     oster 	RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
    512   1.3     oster 	int     i, retcode = 0;
    513  1.19     oster #if RF_ACC_TRACE > 0
    514   1.3     oster 	RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
    515   1.3     oster 	RF_Etimer_t timer;
    516  1.19     oster #endif
    517   1.1     oster 
    518   1.3     oster 	if (node->dagHdr->status == rf_enable) {
    519  1.19     oster #if RF_ACC_TRACE > 0
    520   1.3     oster 		RF_ETIMER_START(timer);
    521  1.19     oster #endif
    522   1.3     oster 		/* don't do the XOR if the input is the same as the output */
    523   1.3     oster 		for (i = 0; i < node->numParams - 1; i += 2)
    524   1.3     oster 			if (node->params[i + 1].p != node->results[0]) {
    525   1.3     oster 				retcode = rf_bxor((char *) node->params[i + 1].p, (char *) node->results[0],
    526  1.17     oster 				    rf_RaidAddressToByte(raidPtr, ((RF_PhysDiskAddr_t *) node->params[i].p)->numSector));
    527   1.3     oster 			}
    528  1.19     oster #if RF_ACC_TRACE > 0
    529   1.3     oster 		RF_ETIMER_STOP(timer);
    530   1.3     oster 		RF_ETIMER_EVAL(timer);
    531   1.3     oster 		tracerec->xor_us += RF_ETIMER_VAL_US(timer);
    532  1.19     oster #endif
    533   1.3     oster 	}
    534   1.3     oster 	return (rf_GenericWakeupFunc(node, retcode));	/* call wake func
    535   1.3     oster 							 * explicitly since no
    536   1.3     oster 							 * I/O in this node */
    537   1.1     oster }
    538  1.14     oster /* this xor is used by the degraded-mode dag functions to recover lost
    539  1.14     oster  * data.  the second-to-last parameter is the PDA for the failed
    540  1.14     oster  * portion of the access.  the code here looks at this PDA and assumes
    541  1.14     oster  * that the xor target buffer is equal in size to the number of
    542  1.14     oster  * sectors in the failed PDA.  It then uses the other PDAs in the
    543  1.14     oster  * parameter list to determine where within the target buffer the
    544  1.14     oster  * corresponding data should be xored.  */
    545   1.3     oster int
    546  1.15     oster rf_RecoveryXorFunc(RF_DagNode_t *node)
    547   1.3     oster {
    548   1.3     oster 	RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
    549   1.3     oster 	RF_RaidLayout_t *layoutPtr = (RF_RaidLayout_t *) & raidPtr->Layout;
    550   1.3     oster 	RF_PhysDiskAddr_t *failedPDA = (RF_PhysDiskAddr_t *) node->params[node->numParams - 2].p;
    551   1.3     oster 	int     i, retcode = 0;
    552   1.3     oster 	RF_PhysDiskAddr_t *pda;
    553   1.3     oster 	int     suoffset, failedSUOffset = rf_StripeUnitOffset(layoutPtr, failedPDA->startSector);
    554   1.3     oster 	char   *srcbuf, *destbuf;
    555  1.19     oster #if RF_ACC_TRACE > 0
    556   1.3     oster 	RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
    557   1.3     oster 	RF_Etimer_t timer;
    558  1.19     oster #endif
    559   1.1     oster 
    560   1.3     oster 	if (node->dagHdr->status == rf_enable) {
    561  1.19     oster #if RF_ACC_TRACE > 0
    562   1.3     oster 		RF_ETIMER_START(timer);
    563  1.19     oster #endif
    564   1.3     oster 		for (i = 0; i < node->numParams - 2; i += 2)
    565   1.3     oster 			if (node->params[i + 1].p != node->results[0]) {
    566   1.3     oster 				pda = (RF_PhysDiskAddr_t *) node->params[i].p;
    567   1.3     oster 				srcbuf = (char *) node->params[i + 1].p;
    568   1.3     oster 				suoffset = rf_StripeUnitOffset(layoutPtr, pda->startSector);
    569   1.3     oster 				destbuf = ((char *) node->results[0]) + rf_RaidAddressToByte(raidPtr, suoffset - failedSUOffset);
    570  1.17     oster 				retcode = rf_bxor(srcbuf, destbuf, rf_RaidAddressToByte(raidPtr, pda->numSector));
    571   1.3     oster 			}
    572  1.19     oster #if RF_ACC_TRACE > 0
    573   1.3     oster 		RF_ETIMER_STOP(timer);
    574   1.3     oster 		RF_ETIMER_EVAL(timer);
    575   1.3     oster 		tracerec->xor_us += RF_ETIMER_VAL_US(timer);
    576  1.19     oster #endif
    577   1.3     oster 	}
    578   1.3     oster 	return (rf_GenericWakeupFunc(node, retcode));
    579   1.1     oster }
    580  1.14     oster /*****************************************************************************
    581  1.14     oster  * The next three functions are utilities used by the above
    582  1.14     oster  * xor-execution functions.
    583  1.14     oster  ****************************************************************************/
    584   1.1     oster 
    585   1.1     oster 
    586   1.1     oster /*
    587  1.14     oster  * this is just a glorified buffer xor.  targbuf points to a buffer
    588  1.14     oster  * that is one full stripe unit in size.  srcbuf points to a buffer
    589  1.14     oster  * that may be less than 1 SU, but never more.  When the access
    590  1.14     oster  * described by pda is one SU in size (which by implication means it's
    591  1.14     oster  * SU-aligned), all that happens is (targbuf) <- (srcbuf ^ targbuf).
    592  1.14     oster  * When the access is less than one SU in size the XOR occurs on only
    593  1.14     oster  * the portion of targbuf identified in the pda.  */
    594   1.1     oster 
    595   1.3     oster int
    596  1.15     oster rf_XorIntoBuffer(RF_Raid_t *raidPtr, RF_PhysDiskAddr_t *pda,
    597  1.17     oster 		 char *srcbuf, char *targbuf)
    598   1.3     oster {
    599   1.3     oster 	char   *targptr;
    600   1.3     oster 	int     sectPerSU = raidPtr->Layout.sectorsPerStripeUnit;
    601   1.3     oster 	int     SUOffset = pda->startSector % sectPerSU;
    602   1.3     oster 	int     length, retcode = 0;
    603   1.3     oster 
    604   1.3     oster 	RF_ASSERT(pda->numSector <= sectPerSU);
    605   1.3     oster 
    606   1.3     oster 	targptr = targbuf + rf_RaidAddressToByte(raidPtr, SUOffset);
    607   1.3     oster 	length = rf_RaidAddressToByte(raidPtr, pda->numSector);
    608  1.17     oster 	retcode = rf_bxor(srcbuf, targptr, length);
    609   1.3     oster 	return (retcode);
    610   1.1     oster }
    611  1.14     oster /* it really should be the case that the buffer pointers (returned by
    612  1.14     oster  * malloc) are aligned to the natural word size of the machine, so
    613  1.14     oster  * this is the only case we optimize for.  The length should always be
    614  1.14     oster  * a multiple of the sector size, so there should be no problem with
    615  1.14     oster  * leftover bytes at the end.  */
    616   1.3     oster int
    617  1.17     oster rf_bxor(char *src, char *dest, int len)
    618   1.3     oster {
    619   1.3     oster 	unsigned mask = sizeof(long) - 1, retcode = 0;
    620   1.3     oster 
    621  1.14     oster 	if (!(((unsigned long) src) & mask) &&
    622  1.14     oster 	    !(((unsigned long) dest) & mask) && !(len & mask)) {
    623  1.14     oster 		retcode = rf_longword_bxor((unsigned long *) src,
    624  1.14     oster 					   (unsigned long *) dest,
    625  1.17     oster 					   len >> RF_LONGSHIFT);
    626   1.3     oster 	} else {
    627   1.3     oster 		RF_ASSERT(0);
    628   1.3     oster 	}
    629   1.3     oster 	return (retcode);
    630   1.1     oster }
    631   1.1     oster 
    632  1.14     oster /* When XORing in kernel mode, we need to map each user page to kernel
    633  1.14     oster  * space before we can access it.  We don't want to assume anything
    634  1.14     oster  * about which input buffers are in kernel/user space, nor about their
    635  1.14     oster  * alignment, so in each loop we compute the maximum number of bytes
    636  1.14     oster  * that we can xor without crossing any page boundaries, and do only
    637  1.15     oster  * this many bytes before the next remap.
    638  1.15     oster  *
    639  1.15     oster  * len - is in longwords
    640  1.15     oster  */
    641   1.3     oster int
    642  1.17     oster rf_longword_bxor(unsigned long *src, unsigned long *dest, int len)
    643   1.3     oster {
    644   1.6  augustss 	unsigned long *end = src + len;
    645   1.6  augustss 	unsigned long d0, d1, d2, d3, s0, s1, s2, s3;	/* temps */
    646  1.14     oster 	unsigned long *pg_src, *pg_dest;   /* per-page source/dest pointers */
    647   1.3     oster 	int     longs_this_time;/* # longwords to xor in the current iteration */
    648   1.3     oster 
    649  1.16     oster 	pg_src = src;
    650  1.16     oster 	pg_dest = dest;
    651   1.3     oster 	if (!pg_src || !pg_dest)
    652   1.3     oster 		return (EFAULT);
    653   1.3     oster 
    654   1.3     oster 	while (len >= 4) {
    655   1.3     oster 		longs_this_time = RF_MIN(len, RF_MIN(RF_BLIP(pg_src), RF_BLIP(pg_dest)) >> RF_LONGSHIFT);	/* note len in longwords */
    656   1.3     oster 		src += longs_this_time;
    657   1.3     oster 		dest += longs_this_time;
    658   1.3     oster 		len -= longs_this_time;
    659   1.3     oster 		while (longs_this_time >= 4) {
    660   1.3     oster 			d0 = pg_dest[0];
    661   1.3     oster 			d1 = pg_dest[1];
    662   1.3     oster 			d2 = pg_dest[2];
    663   1.3     oster 			d3 = pg_dest[3];
    664   1.3     oster 			s0 = pg_src[0];
    665   1.3     oster 			s1 = pg_src[1];
    666   1.3     oster 			s2 = pg_src[2];
    667   1.3     oster 			s3 = pg_src[3];
    668   1.3     oster 			pg_dest[0] = d0 ^ s0;
    669   1.3     oster 			pg_dest[1] = d1 ^ s1;
    670   1.3     oster 			pg_dest[2] = d2 ^ s2;
    671   1.3     oster 			pg_dest[3] = d3 ^ s3;
    672   1.3     oster 			pg_src += 4;
    673   1.3     oster 			pg_dest += 4;
    674   1.3     oster 			longs_this_time -= 4;
    675   1.3     oster 		}
    676   1.3     oster 		while (longs_this_time > 0) {	/* cannot cross any page
    677   1.3     oster 						 * boundaries here */
    678   1.3     oster 			*pg_dest++ ^= *pg_src++;
    679   1.3     oster 			longs_this_time--;
    680   1.3     oster 		}
    681   1.3     oster 
    682   1.3     oster 		/* either we're done, or we've reached a page boundary on one
    683   1.3     oster 		 * (or possibly both) of the pointers */
    684   1.3     oster 		if (len) {
    685   1.3     oster 			if (RF_PAGE_ALIGNED(src))
    686  1.16     oster 				pg_src = src;
    687   1.3     oster 			if (RF_PAGE_ALIGNED(dest))
    688  1.16     oster 				pg_dest = dest;
    689   1.3     oster 			if (!pg_src || !pg_dest)
    690   1.3     oster 				return (EFAULT);
    691   1.3     oster 		}
    692   1.3     oster 	}
    693   1.3     oster 	while (src < end) {
    694   1.3     oster 		*pg_dest++ ^= *pg_src++;
    695   1.3     oster 		src++;
    696   1.3     oster 		dest++;
    697   1.3     oster 		len--;
    698   1.3     oster 		if (RF_PAGE_ALIGNED(src))
    699  1.16     oster 			pg_src = src;
    700   1.3     oster 		if (RF_PAGE_ALIGNED(dest))
    701  1.16     oster 			pg_dest = dest;
    702   1.3     oster 	}
    703   1.3     oster 	RF_ASSERT(len == 0);
    704   1.3     oster 	return (0);
    705   1.1     oster }
    706   1.1     oster 
    707   1.9     oster #if 0
    708   1.1     oster /*
    709   1.1     oster    dst = a ^ b ^ c;
    710   1.1     oster    a may equal dst
    711   1.1     oster    see comment above longword_bxor
    712  1.15     oster    len is length in longwords
    713   1.1     oster */
    714   1.3     oster int
    715  1.15     oster rf_longword_bxor3(unsigned long *dst, unsigned long *a, unsigned long *b,
    716  1.15     oster 		  unsigned long *c, int len, void *bp)
    717   1.3     oster {
    718   1.3     oster 	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;
    719   1.6  augustss 	unsigned long *pg_a, *pg_b, *pg_c, *pg_dst;	/* per-page source/dest
    720   1.3     oster 								 * pointers */
    721   1.3     oster 	int     longs_this_time;/* # longs to xor in the current iteration */
    722   1.3     oster 	char    dst_is_a = 0;
    723   1.3     oster 
    724  1.16     oster 	pg_a = a;
    725  1.16     oster 	pg_b = b;
    726  1.16     oster 	pg_c = c;
    727   1.3     oster 	if (a == dst) {
    728   1.3     oster 		pg_dst = pg_a;
    729   1.3     oster 		dst_is_a = 1;
    730   1.3     oster 	} else {
    731  1.16     oster 		pg_dst = dst;
    732   1.3     oster 	}
    733   1.3     oster 
    734   1.3     oster 	/* align dest to cache line.  Can't cross a pg boundary on dst here. */
    735   1.3     oster 	while ((((unsigned long) pg_dst) & 0x1f)) {
    736   1.3     oster 		*pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;
    737   1.3     oster 		dst++;
    738   1.3     oster 		a++;
    739   1.3     oster 		b++;
    740   1.3     oster 		c++;
    741   1.3     oster 		if (RF_PAGE_ALIGNED(a)) {
    742  1.16     oster 			pg_a = a;
    743   1.3     oster 			if (!pg_a)
    744   1.3     oster 				return (EFAULT);
    745   1.3     oster 		}
    746   1.3     oster 		if (RF_PAGE_ALIGNED(b)) {
    747  1.16     oster 			pg_b = a;
    748   1.3     oster 			if (!pg_b)
    749   1.3     oster 				return (EFAULT);
    750   1.3     oster 		}
    751   1.3     oster 		if (RF_PAGE_ALIGNED(c)) {
    752  1.16     oster 			pg_c = a;
    753   1.3     oster 			if (!pg_c)
    754   1.3     oster 				return (EFAULT);
    755   1.3     oster 		}
    756   1.3     oster 		len--;
    757   1.3     oster 	}
    758   1.3     oster 
    759   1.3     oster 	while (len > 4) {
    760   1.3     oster 		longs_this_time = RF_MIN(len, RF_MIN(RF_BLIP(a), RF_MIN(RF_BLIP(b), RF_MIN(RF_BLIP(c), RF_BLIP(dst)))) >> RF_LONGSHIFT);
    761   1.3     oster 		a += longs_this_time;
    762   1.3     oster 		b += longs_this_time;
    763   1.3     oster 		c += longs_this_time;
    764   1.3     oster 		dst += longs_this_time;
    765   1.3     oster 		len -= longs_this_time;
    766   1.3     oster 		while (longs_this_time >= 4) {
    767   1.3     oster 			a0 = pg_a[0];
    768   1.3     oster 			longs_this_time -= 4;
    769   1.3     oster 
    770   1.3     oster 			a1 = pg_a[1];
    771   1.3     oster 			a2 = pg_a[2];
    772   1.3     oster 
    773   1.3     oster 			a3 = pg_a[3];
    774   1.3     oster 			pg_a += 4;
    775   1.3     oster 
    776   1.3     oster 			b0 = pg_b[0];
    777   1.3     oster 			b1 = pg_b[1];
    778   1.3     oster 
    779   1.3     oster 			b2 = pg_b[2];
    780   1.3     oster 			b3 = pg_b[3];
    781   1.3     oster 			/* start dual issue */
    782   1.3     oster 			a0 ^= b0;
    783   1.3     oster 			b0 = pg_c[0];
    784   1.3     oster 
    785   1.3     oster 			pg_b += 4;
    786   1.3     oster 			a1 ^= b1;
    787   1.3     oster 
    788   1.3     oster 			a2 ^= b2;
    789   1.3     oster 			a3 ^= b3;
    790   1.3     oster 
    791   1.3     oster 			b1 = pg_c[1];
    792   1.3     oster 			a0 ^= b0;
    793   1.3     oster 
    794   1.3     oster 			b2 = pg_c[2];
    795   1.3     oster 			a1 ^= b1;
    796   1.3     oster 
    797   1.3     oster 			b3 = pg_c[3];
    798   1.3     oster 			a2 ^= b2;
    799   1.3     oster 
    800   1.3     oster 			pg_dst[0] = a0;
    801   1.3     oster 			a3 ^= b3;
    802   1.3     oster 			pg_dst[1] = a1;
    803   1.3     oster 			pg_c += 4;
    804   1.3     oster 			pg_dst[2] = a2;
    805   1.3     oster 			pg_dst[3] = a3;
    806   1.3     oster 			pg_dst += 4;
    807   1.3     oster 		}
    808   1.3     oster 		while (longs_this_time > 0) {	/* cannot cross any page
    809   1.3     oster 						 * boundaries here */
    810   1.3     oster 			*pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;
    811   1.3     oster 			longs_this_time--;
    812   1.3     oster 		}
    813   1.3     oster 
    814   1.3     oster 		if (len) {
    815   1.3     oster 			if (RF_PAGE_ALIGNED(a)) {
    816  1.16     oster 				pg_a = a;
    817   1.3     oster 				if (!pg_a)
    818   1.3     oster 					return (EFAULT);
    819   1.3     oster 				if (dst_is_a)
    820   1.3     oster 					pg_dst = pg_a;
    821   1.3     oster 			}
    822   1.3     oster 			if (RF_PAGE_ALIGNED(b)) {
    823  1.16     oster 				pg_b = b;
    824   1.3     oster 				if (!pg_b)
    825   1.3     oster 					return (EFAULT);
    826   1.3     oster 			}
    827   1.3     oster 			if (RF_PAGE_ALIGNED(c)) {
    828  1.16     oster 				pg_c = c;
    829   1.3     oster 				if (!pg_c)
    830   1.3     oster 					return (EFAULT);
    831   1.3     oster 			}
    832   1.3     oster 			if (!dst_is_a)
    833   1.3     oster 				if (RF_PAGE_ALIGNED(dst)) {
    834  1.16     oster 					pg_dst = dst;
    835   1.3     oster 					if (!pg_dst)
    836   1.3     oster 						return (EFAULT);
    837   1.3     oster 				}
    838   1.3     oster 		}
    839   1.3     oster 	}
    840   1.3     oster 	while (len) {
    841   1.3     oster 		*pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;
    842   1.3     oster 		dst++;
    843   1.3     oster 		a++;
    844   1.3     oster 		b++;
    845   1.3     oster 		c++;
    846   1.3     oster 		if (RF_PAGE_ALIGNED(a)) {
    847  1.16     oster 			pg_a = a;
    848   1.3     oster 			if (!pg_a)
    849   1.3     oster 				return (EFAULT);
    850   1.3     oster 			if (dst_is_a)
    851   1.3     oster 				pg_dst = pg_a;
    852   1.3     oster 		}
    853   1.3     oster 		if (RF_PAGE_ALIGNED(b)) {
    854  1.16     oster 			pg_b = b;
    855   1.3     oster 			if (!pg_b)
    856   1.3     oster 				return (EFAULT);
    857   1.3     oster 		}
    858   1.3     oster 		if (RF_PAGE_ALIGNED(c)) {
    859  1.16     oster 			pg_c = c;
    860   1.3     oster 			if (!pg_c)
    861   1.3     oster 				return (EFAULT);
    862   1.3     oster 		}
    863   1.3     oster 		if (!dst_is_a)
    864   1.3     oster 			if (RF_PAGE_ALIGNED(dst)) {
    865  1.16     oster 				pg_dst = dst;
    866   1.3     oster 				if (!pg_dst)
    867   1.3     oster 					return (EFAULT);
    868   1.3     oster 			}
    869   1.3     oster 		len--;
    870   1.3     oster 	}
    871   1.3     oster 	return (0);
    872   1.3     oster }
    873   1.3     oster 
    874   1.3     oster int
    875  1.15     oster rf_bxor3(unsigned char *dst, unsigned char *a, unsigned char *b,
    876  1.15     oster 	 unsigned char *c, unsigned long len, void *bp)
    877   1.1     oster {
    878   1.3     oster 	RF_ASSERT(((RF_UL(dst) | RF_UL(a) | RF_UL(b) | RF_UL(c) | len) & 0x7) == 0);
    879   1.1     oster 
    880   1.3     oster 	return (rf_longword_bxor3((unsigned long *) dst, (unsigned long *) a,
    881   1.3     oster 		(unsigned long *) b, (unsigned long *) c, len >> RF_LONGSHIFT, bp));
    882   1.1     oster }
    883   1.9     oster #endif
    884