rf_compat32.c revision 1.2 1 1.2 pgoyette /* $NetBSD: rf_compat32.c,v 1.2 2019/02/03 08:02:24 pgoyette Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 2017 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg * 3. The name of the author may not be used to endorse or promote products
16 1.1 mrg * derived from this software without specific prior written permission.
17 1.1 mrg *
18 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 mrg * SUCH DAMAGE.
29 1.1 mrg */
30 1.1 mrg
31 1.1 mrg #include <sys/types.h>
32 1.1 mrg #include <sys/param.h>
33 1.1 mrg #include <sys/systm.h>
34 1.2 pgoyette #include <sys/module.h>
35 1.2 pgoyette #include <sys/compat_stub.h>
36 1.1 mrg
37 1.1 mrg #include <dev/raidframe/raidframeio.h>
38 1.1 mrg #include <dev/raidframe/raidframevar.h>
39 1.1 mrg
40 1.1 mrg #include "rf_raid.h"
41 1.1 mrg #include "rf_compat32.h"
42 1.1 mrg
43 1.1 mrg #include <compat/netbsd32/netbsd32.h>
44 1.1 mrg
45 1.1 mrg typedef netbsd32_int64 RF_SectorNum_t32;
46 1.1 mrg typedef netbsd32_int64 RF_StripeNum_t32;
47 1.1 mrg
48 1.1 mrg /* from <dev/raidframe/raidframevar.h> */
49 1.1 mrg typedef struct RF_Config_s32 {
50 1.1 mrg RF_RowCol_t numCol, numSpare; /* number of rows, columns,
51 1.1 mrg * and spare disks */
52 1.1 mrg dev_t devs[RF_MAXROW][RF_MAXCOL]; /* device numbers for disks
53 1.1 mrg * comprising array */
54 1.1 mrg char devnames[RF_MAXROW][RF_MAXCOL][50]; /* device names */
55 1.1 mrg dev_t spare_devs[RF_MAXSPARE]; /* device numbers for spare
56 1.1 mrg * disks */
57 1.1 mrg char spare_names[RF_MAXSPARE][50]; /* device names */
58 1.1 mrg RF_SectorNum_t32 sectPerSU; /* sectors per stripe unit */
59 1.1 mrg RF_StripeNum_t32 SUsPerPU;/* stripe units per parity unit */
60 1.1 mrg RF_StripeNum_t32 SUsPerRU;/* stripe units per reconstruction unit */
61 1.1 mrg RF_ParityConfig_t parityConfig; /* identifies the RAID architecture to
62 1.1 mrg * be used */
63 1.1 mrg RF_DiskQueueType_t diskQueueType; /* 'f' = fifo, 'c' = cvscan,
64 1.1 mrg * not used in kernel */
65 1.1 mrg char maxOutstandingDiskReqs; /* # concurrent reqs to be sent to a
66 1.1 mrg * disk. not used in kernel. */
67 1.1 mrg char debugVars[RF_MAXDBGV][50]; /* space for specifying debug
68 1.1 mrg * variables & their values */
69 1.1 mrg unsigned int layoutSpecificSize; /* size in bytes of
70 1.1 mrg * layout-specific info */
71 1.1 mrg netbsd32_pointer_t layoutSpecific; /* a pointer to a layout-specific structure to
72 1.1 mrg * be copied in */
73 1.1 mrg int force; /* if !0, ignore many fatal
74 1.1 mrg configuration conditions */
75 1.1 mrg /*
76 1.1 mrg "force" is used to override cases where the component labels would
77 1.1 mrg indicate that configuration should not proceed without user
78 1.1 mrg intervention
79 1.1 mrg */
80 1.1 mrg } RF_Config_t32 ;
81 1.1 mrg
82 1.1 mrg int
83 1.1 mrg rf_config_netbsd32(void *data, RF_Config_t *k_cfg)
84 1.1 mrg {
85 1.1 mrg RF_Config_t32 *u_cfg = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
86 1.1 mrg struct RF_Config_s32 *cfg32;
87 1.1 mrg int rv;
88 1.1 mrg
89 1.1 mrg RF_Malloc(cfg32, sizeof(RF_Config_t), (RF_Config_t32 *));
90 1.1 mrg if (cfg32 == NULL)
91 1.1 mrg return (ENOMEM);
92 1.1 mrg
93 1.1 mrg rv = copyin(u_cfg, cfg32, sizeof(RF_Config_t32));
94 1.1 mrg if (rv)
95 1.1 mrg goto out;
96 1.1 mrg
97 1.1 mrg k_cfg->numCol = cfg32->numCol;
98 1.1 mrg k_cfg->numSpare = cfg32->numSpare;
99 1.1 mrg memcpy(k_cfg->devs, cfg32->devs, sizeof(k_cfg->devs));
100 1.1 mrg memcpy(k_cfg->devnames, cfg32->devnames, sizeof(k_cfg->devnames));
101 1.1 mrg memcpy(k_cfg->spare_devs, cfg32->spare_devs, sizeof(k_cfg->spare_devs));
102 1.1 mrg memcpy(k_cfg->spare_names, cfg32->spare_names, sizeof(k_cfg->spare_names));
103 1.1 mrg k_cfg->sectPerSU = cfg32->sectPerSU;
104 1.1 mrg k_cfg->SUsPerPU = cfg32->SUsPerPU;
105 1.1 mrg k_cfg->SUsPerRU = cfg32->SUsPerRU;
106 1.1 mrg k_cfg->parityConfig = cfg32->parityConfig;
107 1.1 mrg memcpy(k_cfg->diskQueueType, cfg32->diskQueueType, sizeof(k_cfg->diskQueueType));
108 1.1 mrg k_cfg->maxOutstandingDiskReqs = cfg32->maxOutstandingDiskReqs;
109 1.1 mrg memcpy(k_cfg->debugVars, cfg32->debugVars, sizeof(k_cfg->debugVars));
110 1.1 mrg k_cfg->layoutSpecificSize = cfg32->layoutSpecificSize;
111 1.1 mrg k_cfg->layoutSpecific = NETBSD32PTR64(cfg32->layoutSpecific);
112 1.1 mrg k_cfg->force = cfg32->force;
113 1.1 mrg
114 1.1 mrg out:
115 1.1 mrg RF_Free(cfg32, sizeof(RF_Config_t32));
116 1.1 mrg return rv;
117 1.1 mrg }
118 1.2 pgoyette
119 1.2 pgoyette static void
120 1.2 pgoyette raidframe_netbsd32_init(void)
121 1.2 pgoyette {
122 1.2 pgoyette
123 1.2 pgoyette MODULE_SET_HOOK(raidframe_netbsd32_config_hook, "raid32",
124 1.2 pgoyette rf_config_netbsd32);
125 1.2 pgoyette }
126 1.2 pgoyette
127 1.2 pgoyette static void
128 1.2 pgoyette raidframe_netbsd32_fini(void)
129 1.2 pgoyette {
130 1.2 pgoyette
131 1.2 pgoyette MODULE_UNSET_HOOK(raidframe_netbsd32_config_hook);
132 1.2 pgoyette }
133 1.2 pgoyette
134 1.2 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_raid, "raid,compat_netbsd32");
135 1.2 pgoyette
136 1.2 pgoyette static int
137 1.2 pgoyette compat_netbsd32_raid_modcmd(modcmd_t cmd, void *arg)
138 1.2 pgoyette {
139 1.2 pgoyette
140 1.2 pgoyette switch (cmd) {
141 1.2 pgoyette case MODULE_CMD_INIT:
142 1.2 pgoyette raidframe_netbsd32_init();
143 1.2 pgoyette return 0;
144 1.2 pgoyette case MODULE_CMD_FINI:
145 1.2 pgoyette raidframe_netbsd32_fini();
146 1.2 pgoyette return 0;
147 1.2 pgoyette default:
148 1.2 pgoyette return ENOTTY;
149 1.2 pgoyette }
150 1.2 pgoyette }
151 1.2 pgoyette
152