1 /* $NetBSD: rf_callback.c,v 1.26 2026/10/24 00:20:23 tls Exp $ */ 2 /* 3 * Copyright (c) 1995 Carnegie-Mellon University. 4 * All rights reserved. 5 * 6 * Author: Jim Zelenka 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 (at) 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 * callback.c -- code to manipulate callback descriptor 32 * 33 ****************************************************************************/ 34 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: rf_callback.c,v 1.26 2026/10/24 00:20:23 tls Exp $"); 38 39 #include <dev/raidframe/raidframevar.h> 40 #include <sys/pool.h> 41 42 #include "rf_archs.h" 43 #include "rf_threadstuff.h" 44 #include "rf_callback.h" 45 #include "rf_debugMem.h" 46 #include "rf_general.h" 47 #include "rf_shutdown.h" 48 #include "rf_netbsd.h" 49 #include "rf_raid.h" 50 51 static void rf_ShutdownCallback(void *); 52 static void 53 rf_ShutdownCallback(void *arg) 54 { 55 RF_Raid_t *raidPtr; 56 57 raidPtr = (RF_Raid_t *) arg; 58 59 pool_destroy(&raidPtr->pools.callbackf); 60 pool_destroy(&raidPtr->pools.callbackv); 61 } 62 63 int 64 rf_ConfigureCallback(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr, 65 RF_Config_t *cfgPtr) 66 { 67 size_t stripe_data_bytes, min_cbf, max_cbf, min_cbv, max_cbv; 68 u_int max_stripes_per_bp, c; 69 70 c = raidPtr->numCol; 71 stripe_data_bytes = (size_t)raidPtr->Layout.dataSectorsPerStripe << 72 raidPtr->logBytesPerSector; 73 max_stripes_per_bp = howmany(MAXPHYS, stripe_data_bytes) + 1; 74 75 /* Up to 2 callbacks (stripe lock + forced recon) per active stripe. */ 76 min_cbf = 2 * (raidPtr->openings * max_stripes_per_bp + 1); 77 max_cbf = 2 * min_cbf; 78 79 /* Up to 3 recon wait lists (head-sep, blocked, buffer) per disk. */ 80 min_cbv = (raidPtr->Layout.map->SubmitReconBuffer == NULL) ? 81 0 : 3 * (c - 1); 82 max_cbv = 2 * min_cbv; 83 84 rf_pool_init(raidPtr, raidPtr->poolNames.callbackf, &raidPtr->pools.callbackf, sizeof(RF_CallbackFuncDesc_t), 85 "callbackf", min_cbf, max_cbf); 86 rf_pool_init(raidPtr, raidPtr->poolNames.callbackv, &raidPtr->pools.callbackv, sizeof(RF_CallbackValueDesc_t), 87 "callbackv", min_cbv, max_cbv); 88 rf_ShutdownCreate(listp, rf_ShutdownCallback, raidPtr); 89 90 return (0); 91 } 92 93 RF_CallbackFuncDesc_t * 94 rf_AllocCallbackFuncDesc(RF_Raid_t *raidPtr) 95 { 96 return pool_get(&raidPtr->pools.callbackf, PR_WAITOK); 97 } 98 99 void 100 rf_FreeCallbackFuncDesc(RF_Raid_t *raidPtr, RF_CallbackFuncDesc_t *p) 101 { 102 pool_put(&raidPtr->pools.callbackf, p); 103 } 104 105 RF_CallbackValueDesc_t * 106 rf_AllocCallbackValueDesc(RF_Raid_t *raidPtr) 107 { 108 return pool_get(&raidPtr->pools.callbackv, PR_WAITOK); 109 } 110 111 void 112 rf_FreeCallbackValueDesc(RF_Raid_t *raidPtr, RF_CallbackValueDesc_t *p) 113 { 114 pool_put(&raidPtr->pools.callbackv, p); 115 } 116