rf_compat32.c revision 1.6 1 1.6 pgoyette /* $NetBSD: rf_compat32.c,v 1.6 2019/03/01 11:06:56 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.3 christos #include "rf_kintf.h"
42 1.1 mrg #include "rf_compat32.h"
43 1.1 mrg
44 1.1 mrg #include <compat/netbsd32/netbsd32.h>
45 1.1 mrg
46 1.1 mrg typedef netbsd32_int64 RF_SectorNum_t32;
47 1.1 mrg typedef netbsd32_int64 RF_StripeNum_t32;
48 1.1 mrg
49 1.1 mrg /* from <dev/raidframe/raidframevar.h> */
50 1.1 mrg typedef struct RF_Config_s32 {
51 1.1 mrg RF_RowCol_t numCol, numSpare; /* number of rows, columns,
52 1.1 mrg * and spare disks */
53 1.1 mrg dev_t devs[RF_MAXROW][RF_MAXCOL]; /* device numbers for disks
54 1.1 mrg * comprising array */
55 1.1 mrg char devnames[RF_MAXROW][RF_MAXCOL][50]; /* device names */
56 1.1 mrg dev_t spare_devs[RF_MAXSPARE]; /* device numbers for spare
57 1.1 mrg * disks */
58 1.1 mrg char spare_names[RF_MAXSPARE][50]; /* device names */
59 1.1 mrg RF_SectorNum_t32 sectPerSU; /* sectors per stripe unit */
60 1.1 mrg RF_StripeNum_t32 SUsPerPU;/* stripe units per parity unit */
61 1.1 mrg RF_StripeNum_t32 SUsPerRU;/* stripe units per reconstruction unit */
62 1.1 mrg RF_ParityConfig_t parityConfig; /* identifies the RAID architecture to
63 1.1 mrg * be used */
64 1.1 mrg RF_DiskQueueType_t diskQueueType; /* 'f' = fifo, 'c' = cvscan,
65 1.1 mrg * not used in kernel */
66 1.1 mrg char maxOutstandingDiskReqs; /* # concurrent reqs to be sent to a
67 1.1 mrg * disk. not used in kernel. */
68 1.1 mrg char debugVars[RF_MAXDBGV][50]; /* space for specifying debug
69 1.1 mrg * variables & their values */
70 1.1 mrg unsigned int layoutSpecificSize; /* size in bytes of
71 1.1 mrg * layout-specific info */
72 1.1 mrg netbsd32_pointer_t layoutSpecific; /* a pointer to a layout-specific structure to
73 1.1 mrg * be copied in */
74 1.1 mrg int force; /* if !0, ignore many fatal
75 1.1 mrg configuration conditions */
76 1.1 mrg /*
77 1.1 mrg "force" is used to override cases where the component labels would
78 1.1 mrg indicate that configuration should not proceed without user
79 1.1 mrg intervention
80 1.1 mrg */
81 1.3 christos } RF_Config_t32;
82 1.1 mrg
83 1.3 christos static int
84 1.3 christos rf_config_netbsd32(struct raid_softc *rs, void *data)
85 1.1 mrg {
86 1.3 christos RF_Config_t32 *u_cfg32 = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
87 1.3 christos RF_Config_t *k_cfg;
88 1.3 christos RF_Config_t32 *k_cfg32;
89 1.1 mrg int rv;
90 1.1 mrg
91 1.5 christos k_cfg32 = RF_Malloc(sizeof(*k_cfg32));
92 1.3 christos if (k_cfg32 == NULL)
93 1.3 christos return ENOMEM;
94 1.3 christos
95 1.3 christos rv = copyin(u_cfg32, k_cfg32, sizeof(RF_Config_t32));
96 1.3 christos if (rv) {
97 1.3 christos RF_Free(k_cfg32, sizeof(RF_Config_t32));
98 1.3 christos return ENOMEM;
99 1.3 christos }
100 1.3 christos
101 1.5 christos k_cfg = RF_Malloc(sizeof(*k_cfg));
102 1.3 christos if (k_cfg == NULL) {
103 1.3 christos RF_Free(k_cfg32, sizeof(RF_Config_t32));
104 1.3 christos RF_Free(k_cfg, sizeof(RF_Config_t));
105 1.3 christos }
106 1.3 christos k_cfg->numCol = k_cfg32->numCol;
107 1.3 christos k_cfg->numSpare = k_cfg32->numSpare;
108 1.3 christos memcpy(k_cfg->devs, k_cfg32->devs, sizeof(k_cfg->devs));
109 1.3 christos memcpy(k_cfg->devnames, k_cfg32->devnames, sizeof(k_cfg->devnames));
110 1.3 christos memcpy(k_cfg->spare_devs, k_cfg32->spare_devs,
111 1.3 christos sizeof(k_cfg->spare_devs));
112 1.3 christos memcpy(k_cfg->spare_names, k_cfg32->spare_names,
113 1.3 christos sizeof(k_cfg->spare_names));
114 1.3 christos k_cfg->sectPerSU = k_cfg32->sectPerSU;
115 1.3 christos k_cfg->SUsPerPU = k_cfg32->SUsPerPU;
116 1.3 christos k_cfg->SUsPerRU = k_cfg32->SUsPerRU;
117 1.3 christos k_cfg->parityConfig = k_cfg32->parityConfig;
118 1.3 christos memcpy(k_cfg->diskQueueType, k_cfg32->diskQueueType,
119 1.3 christos sizeof(k_cfg->diskQueueType));
120 1.3 christos k_cfg->maxOutstandingDiskReqs = k_cfg32->maxOutstandingDiskReqs;
121 1.3 christos memcpy(k_cfg->debugVars, k_cfg32->debugVars, sizeof(k_cfg->debugVars));
122 1.3 christos k_cfg->layoutSpecificSize = k_cfg32->layoutSpecificSize;
123 1.3 christos k_cfg->layoutSpecific = NETBSD32PTR64(k_cfg32->layoutSpecific);
124 1.3 christos k_cfg->force = k_cfg32->force;
125 1.3 christos
126 1.3 christos return rf_construct(rs, k_cfg);
127 1.3 christos }
128 1.3 christos
129 1.3 christos static int
130 1.3 christos rf_get_info_netbsd32(RF_Raid_t *raidPtr, void *data)
131 1.3 christos {
132 1.3 christos int retcode;
133 1.3 christos void *ucfgp = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
134 1.3 christos
135 1.5 christos RF_DeviceConfig_t *d_cfg = RF_Malloc(sizeof(*d_cfg));
136 1.3 christos if (d_cfg == NULL)
137 1.3 christos return ENOMEM;
138 1.3 christos
139 1.3 christos retcode = rf_get_info(raidPtr, d_cfg);
140 1.3 christos if (retcode == 0) {
141 1.3 christos retcode = copyout(d_cfg, ucfgp, sizeof(*d_cfg));
142 1.3 christos }
143 1.3 christos RF_Free(d_cfg, sizeof(RF_DeviceConfig_t));
144 1.3 christos return retcode;
145 1.3 christos }
146 1.3 christos
147 1.3 christos static int
148 1.3 christos raidframe_netbsd32_ioctl(struct raid_softc *rs, u_long cmd, void *data)
149 1.3 christos {
150 1.3 christos RF_Raid_t *raidPtr = rf_get_raid(rs);
151 1.3 christos
152 1.3 christos switch (cmd) {
153 1.3 christos case RAIDFRAME_GET_INFO32:
154 1.4 christos if (!rf_inited(rs))
155 1.3 christos return ENXIO;
156 1.3 christos return rf_get_info_netbsd32(raidPtr, data);
157 1.3 christos case RAIDFRAME_CONFIGURE32:
158 1.3 christos return rf_config_netbsd32(rs, data);
159 1.3 christos default:
160 1.3 christos return EPASSTHROUGH;
161 1.3 christos }
162 1.1 mrg }
163 1.2 pgoyette
164 1.3 christos
165 1.2 pgoyette static void
166 1.2 pgoyette raidframe_netbsd32_init(void)
167 1.2 pgoyette {
168 1.2 pgoyette
169 1.6 pgoyette MODULE_HOOK_SET(raidframe_netbsd32_ioctl_hook, "raid32",
170 1.3 christos raidframe_netbsd32_ioctl);
171 1.2 pgoyette }
172 1.2 pgoyette
173 1.2 pgoyette static void
174 1.2 pgoyette raidframe_netbsd32_fini(void)
175 1.2 pgoyette {
176 1.2 pgoyette
177 1.6 pgoyette MODULE_HOOK_UNSET(raidframe_netbsd32_ioctl_hook);
178 1.2 pgoyette }
179 1.2 pgoyette
180 1.2 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_raid, "raid,compat_netbsd32");
181 1.2 pgoyette
182 1.2 pgoyette static int
183 1.2 pgoyette compat_netbsd32_raid_modcmd(modcmd_t cmd, void *arg)
184 1.2 pgoyette {
185 1.2 pgoyette
186 1.2 pgoyette switch (cmd) {
187 1.2 pgoyette case MODULE_CMD_INIT:
188 1.2 pgoyette raidframe_netbsd32_init();
189 1.2 pgoyette return 0;
190 1.2 pgoyette case MODULE_CMD_FINI:
191 1.2 pgoyette raidframe_netbsd32_fini();
192 1.2 pgoyette return 0;
193 1.2 pgoyette default:
194 1.2 pgoyette return ENOTTY;
195 1.2 pgoyette }
196 1.2 pgoyette }
197 1.2 pgoyette
198