Deleted Added
full compact
iir_ctrl.c (111745) iir_ctrl.c (111815)
1/* $FreeBSD: head/sys/dev/iir/iir_ctrl.c 111745 2003-03-02 16:44:46Z phk $ */
1/* $FreeBSD: head/sys/dev/iir/iir_ctrl.c 111815 2003-03-03 12:15:54Z phk $ */
2/*
3 * Copyright (c) 2000-01 Intel Corporation
4 * All Rights Reserved
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31/*
32 * iir_ctrl.c: Control functions and /dev entry points for /dev/iir*
33 *
34 * Written by: Achim Leubner <achim.leubner@intel.com>
35 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
36 *
37 * TODO:
38 */
39
40#ident "$Id: iir_ctrl.c 1.2 2001/07/18 11:17:22 achim Exp $"
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/endian.h>
45#include <sys/malloc.h>
46#include <sys/kernel.h>
47#include <sys/uio.h>
48#include <sys/conf.h>
49#include <sys/stat.h>
50#include <sys/ioccom.h>
51#include <machine/bus.h>
52#include <vm/vm.h>
53#include <vm/vm_kern.h>
54#include <vm/vm_extern.h>
55#include <vm/pmap.h>
56
57#include <dev/iir/iir.h>
58
59/* Entry points and other prototypes */
60static struct gdt_softc *gdt_minor2softc(int minor_no);
61
62static d_open_t iir_open;
63static d_close_t iir_close;
64static d_write_t iir_write;
65static d_read_t iir_read;
66static d_ioctl_t iir_ioctl;
67
68#define CDEV_MAJOR IIR_CDEV_MAJOR
69
70/* Normally, this is a static structure. But we need it in pci/iir_pci.c */
71static struct cdevsw iir_cdevsw = {
2/*
3 * Copyright (c) 2000-01 Intel Corporation
4 * All Rights Reserved
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31/*
32 * iir_ctrl.c: Control functions and /dev entry points for /dev/iir*
33 *
34 * Written by: Achim Leubner <achim.leubner@intel.com>
35 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
36 *
37 * TODO:
38 */
39
40#ident "$Id: iir_ctrl.c 1.2 2001/07/18 11:17:22 achim Exp $"
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/endian.h>
45#include <sys/malloc.h>
46#include <sys/kernel.h>
47#include <sys/uio.h>
48#include <sys/conf.h>
49#include <sys/stat.h>
50#include <sys/ioccom.h>
51#include <machine/bus.h>
52#include <vm/vm.h>
53#include <vm/vm_kern.h>
54#include <vm/vm_extern.h>
55#include <vm/pmap.h>
56
57#include <dev/iir/iir.h>
58
59/* Entry points and other prototypes */
60static struct gdt_softc *gdt_minor2softc(int minor_no);
61
62static d_open_t iir_open;
63static d_close_t iir_close;
64static d_write_t iir_write;
65static d_read_t iir_read;
66static d_ioctl_t iir_ioctl;
67
68#define CDEV_MAJOR IIR_CDEV_MAJOR
69
70/* Normally, this is a static structure. But we need it in pci/iir_pci.c */
71static struct cdevsw iir_cdevsw = {
72 /* open */ iir_open,
73 /* close */ iir_close,
74 /* read */ iir_read,
75 /* write */ iir_write,
76 /* ioctl */ iir_ioctl,
77 /* poll */ nopoll,
78 /* mmap */ nommap,
79 /* strategy */ nostrategy,
80 /* name */ "iir",
81 /* maj */ CDEV_MAJOR,
82 /* dump */ nodump,
83 /* psize */ nopsize,
84 /* flags */ 0,
85 /* kqfilter */ nokqfilter
72 .d_open = iir_open,
73 .d_close = iir_close,
74 .d_read = iir_read,
75 .d_write = iir_write,
76 .d_ioctl = iir_ioctl,
77 .d_name = "iir",
78 .d_maj = CDEV_MAJOR,
86};
87
88#ifndef SDEV_PER_HBA
89static int sdev_made = 0;
90#endif
91extern int gdt_cnt;
92extern char ostype[];
93extern char osrelease[];
94extern gdt_statist_t gdt_stat;
95
96/*
97 * Given a controller number,
98 * make a special device and return the dev_t
99 */
100dev_t
101gdt_make_dev(int unit)
102{
103 dev_t dev;
104
105#ifdef SDEV_PER_HBA
106 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
107 S_IRUSR | S_IWUSR | S_IRGRP, "iir%d", unit);
108#else
109 if (sdev_made)
110 return (0);
111 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
112 S_IRUSR | S_IWUSR | S_IRGRP, "iir");
113 sdev_made = 1;
114#endif
115 return (dev);
116}
117
118void
119gdt_destroy_dev(dev_t dev)
120{
121 if (dev != NULL)
122 destroy_dev(dev);
123}
124
125/*
126 * Given a minor device number,
127 * return the pointer to its softc structure
128 */
129static struct gdt_softc *
130gdt_minor2softc(int minor_no)
131{
132 struct gdt_softc *gdt;
133 int hanum;
134
135#ifdef SDEV_PER_HBA
136 hanum = minor2hba(minor_no);
137#else
138 hanum = minor_no;
139#endif
140
141 for (gdt = TAILQ_FIRST(&gdt_softcs);
142 gdt != NULL && gdt->sc_hanum != hanum;
143 gdt = TAILQ_NEXT(gdt, links));
144
145 return (gdt);
146}
147
148static int
149iir_open(dev_t dev, int flags, int fmt, d_thread_t * p)
150{
151 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
152
153#ifdef SDEV_PER_HBA
154 int minor_no;
155 struct gdt_softc *gdt;
156
157 minor_no = minor(dev);
158 gdt = gdt_minor2softc(minor_no);
159 if (gdt == NULL)
160 return (ENXIO);
161#endif
162
163 return (0);
164}
165
166static int
167iir_close(dev_t dev, int flags, int fmt, d_thread_t * p)
168{
169 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
170
171#ifdef SDEV_PER_HBA
172 int minor_no;
173 struct gdt_softc *gdt;
174
175 minor_no = minor(dev);
176 gdt = gdt_minor2softc(minor_no);
177 if (gdt == NULL)
178 return (ENXIO);
179#endif
180
181 return (0);
182}
183
184static int
185iir_write(dev_t dev, struct uio * uio, int ioflag)
186{
187 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
188
189#ifdef SDEV_PER_HBA
190 int minor_no;
191 struct gdt_softc *gdt;
192
193 minor_no = minor(dev);
194 gdt = gdt_minor2softc(minor_no);
195 if (gdt == NULL)
196 return (ENXIO);
197#endif
198
199 return (0);
200}
201
202static int
203iir_read(dev_t dev, struct uio * uio, int ioflag)
204{
205 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
206
207#ifdef SDEV_PER_HBA
208 int minor_no;
209 struct gdt_softc *gdt;
210
211 minor_no = minor(dev);
212 gdt = gdt_minor2softc(minor_no);
213 if (gdt == NULL)
214 return (ENXIO);
215#endif
216
217 return (0);
218}
219
220/**
221 * This is the control syscall interface.
222 * It should be binary compatible with UnixWare,
223 * if not totally syntatically so.
224 */
225
226static int
227iir_ioctl(dev_t dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
228{
229 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
230
231#ifdef SDEV_PER_HBA
232 int minor_no;
233 struct gdt_softc *gdt;
234
235 minor_no = minor(dev);
236 gdt = gdt_minor2softc(minor_no);
237 if (gdt == NULL)
238 return (ENXIO);
239#endif
240 ++gdt_stat.io_count_act;
241 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
242 gdt_stat.io_count_max = gdt_stat.io_count_act;
243
244 switch (cmd) {
245 case GDT_IOCTL_GENERAL:
246 {
247 gdt_ucmd_t *ucmd;
248 struct gdt_softc *gdt;
249 int lock;
250
251 ucmd = (gdt_ucmd_t *)cmdarg;
252 gdt = gdt_minor2softc(ucmd->io_node);
253 if (gdt == NULL)
254 return (ENXIO);
255 lock = splcam();
256 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
257 ucmd->complete_flag = FALSE;
258 splx(lock);
259 gdt_next(gdt);
260 if (!ucmd->complete_flag)
261 (void) tsleep((void *)ucmd, PCATCH | PRIBIO, "iirucw", 0);
262 break;
263 }
264
265 case GDT_IOCTL_DRVERS:
266 *(int *)cmdarg =
267 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
268 break;
269
270 case GDT_IOCTL_CTRTYPE:
271 {
272 gdt_ctrt_t *p;
273 struct gdt_softc *gdt;
274
275 p = (gdt_ctrt_t *)cmdarg;
276 gdt = gdt_minor2softc(p->io_node);
277 if (gdt == NULL)
278 return (ENXIO);
279 p->oem_id = 0x8000;
280 p->type = 0xfd;
281 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
282 p->ext_type = 0x6000 | gdt->sc_subdevice;
283 p->device_id = gdt->sc_device;
284 p->sub_device_id = gdt->sc_subdevice;
285 break;
286 }
287
288 case GDT_IOCTL_OSVERS:
289 {
290 gdt_osv_t *p;
291
292 p = (gdt_osv_t *)cmdarg;
293 p->oscode = 10;
294 p->version = osrelease[0] - '0';
295 if (osrelease[1] == '.')
296 p->subversion = osrelease[2] - '0';
297 else
298 p->subversion = 0;
299 if (osrelease[3] == '.')
300 p->revision = osrelease[4] - '0';
301 else
302 p->revision = 0;
303 strcpy(p->name, ostype);
304 break;
305 }
306
307 case GDT_IOCTL_CTRCNT:
308 *(int *)cmdarg = gdt_cnt;
309 break;
310
311 case GDT_IOCTL_EVENT:
312 {
313 gdt_event_t *p;
314 int lock;
315
316 p = (gdt_event_t *)cmdarg;
317 if (p->erase == 0xff) {
318 if (p->dvr.event_source == GDT_ES_TEST)
319 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
320 else if (p->dvr.event_source == GDT_ES_DRIVER)
321 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
322 else if (p->dvr.event_source == GDT_ES_SYNC)
323 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
324 else
325 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
326 lock = splcam();
327 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
328 &p->dvr.event_data);
329 splx(lock);
330 } else if (p->erase == 0xfe) {
331 lock = splcam();
332 gdt_clear_events();
333 splx(lock);
334 } else if (p->erase == 0) {
335 p->handle = gdt_read_event(p->handle, &p->dvr);
336 } else {
337 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
338 }
339 break;
340 }
341
342 case GDT_IOCTL_STATIST:
343 {
344 gdt_statist_t *p;
345
346 p = (gdt_statist_t *)cmdarg;
347 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
348 break;
349 }
350
351 default:
352 break;
353 }
354
355 --gdt_stat.io_count_act;
356 return (0);
357}
79};
80
81#ifndef SDEV_PER_HBA
82static int sdev_made = 0;
83#endif
84extern int gdt_cnt;
85extern char ostype[];
86extern char osrelease[];
87extern gdt_statist_t gdt_stat;
88
89/*
90 * Given a controller number,
91 * make a special device and return the dev_t
92 */
93dev_t
94gdt_make_dev(int unit)
95{
96 dev_t dev;
97
98#ifdef SDEV_PER_HBA
99 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
100 S_IRUSR | S_IWUSR | S_IRGRP, "iir%d", unit);
101#else
102 if (sdev_made)
103 return (0);
104 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
105 S_IRUSR | S_IWUSR | S_IRGRP, "iir");
106 sdev_made = 1;
107#endif
108 return (dev);
109}
110
111void
112gdt_destroy_dev(dev_t dev)
113{
114 if (dev != NULL)
115 destroy_dev(dev);
116}
117
118/*
119 * Given a minor device number,
120 * return the pointer to its softc structure
121 */
122static struct gdt_softc *
123gdt_minor2softc(int minor_no)
124{
125 struct gdt_softc *gdt;
126 int hanum;
127
128#ifdef SDEV_PER_HBA
129 hanum = minor2hba(minor_no);
130#else
131 hanum = minor_no;
132#endif
133
134 for (gdt = TAILQ_FIRST(&gdt_softcs);
135 gdt != NULL && gdt->sc_hanum != hanum;
136 gdt = TAILQ_NEXT(gdt, links));
137
138 return (gdt);
139}
140
141static int
142iir_open(dev_t dev, int flags, int fmt, d_thread_t * p)
143{
144 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
145
146#ifdef SDEV_PER_HBA
147 int minor_no;
148 struct gdt_softc *gdt;
149
150 minor_no = minor(dev);
151 gdt = gdt_minor2softc(minor_no);
152 if (gdt == NULL)
153 return (ENXIO);
154#endif
155
156 return (0);
157}
158
159static int
160iir_close(dev_t dev, int flags, int fmt, d_thread_t * p)
161{
162 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
163
164#ifdef SDEV_PER_HBA
165 int minor_no;
166 struct gdt_softc *gdt;
167
168 minor_no = minor(dev);
169 gdt = gdt_minor2softc(minor_no);
170 if (gdt == NULL)
171 return (ENXIO);
172#endif
173
174 return (0);
175}
176
177static int
178iir_write(dev_t dev, struct uio * uio, int ioflag)
179{
180 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
181
182#ifdef SDEV_PER_HBA
183 int minor_no;
184 struct gdt_softc *gdt;
185
186 minor_no = minor(dev);
187 gdt = gdt_minor2softc(minor_no);
188 if (gdt == NULL)
189 return (ENXIO);
190#endif
191
192 return (0);
193}
194
195static int
196iir_read(dev_t dev, struct uio * uio, int ioflag)
197{
198 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
199
200#ifdef SDEV_PER_HBA
201 int minor_no;
202 struct gdt_softc *gdt;
203
204 minor_no = minor(dev);
205 gdt = gdt_minor2softc(minor_no);
206 if (gdt == NULL)
207 return (ENXIO);
208#endif
209
210 return (0);
211}
212
213/**
214 * This is the control syscall interface.
215 * It should be binary compatible with UnixWare,
216 * if not totally syntatically so.
217 */
218
219static int
220iir_ioctl(dev_t dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
221{
222 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
223
224#ifdef SDEV_PER_HBA
225 int minor_no;
226 struct gdt_softc *gdt;
227
228 minor_no = minor(dev);
229 gdt = gdt_minor2softc(minor_no);
230 if (gdt == NULL)
231 return (ENXIO);
232#endif
233 ++gdt_stat.io_count_act;
234 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
235 gdt_stat.io_count_max = gdt_stat.io_count_act;
236
237 switch (cmd) {
238 case GDT_IOCTL_GENERAL:
239 {
240 gdt_ucmd_t *ucmd;
241 struct gdt_softc *gdt;
242 int lock;
243
244 ucmd = (gdt_ucmd_t *)cmdarg;
245 gdt = gdt_minor2softc(ucmd->io_node);
246 if (gdt == NULL)
247 return (ENXIO);
248 lock = splcam();
249 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
250 ucmd->complete_flag = FALSE;
251 splx(lock);
252 gdt_next(gdt);
253 if (!ucmd->complete_flag)
254 (void) tsleep((void *)ucmd, PCATCH | PRIBIO, "iirucw", 0);
255 break;
256 }
257
258 case GDT_IOCTL_DRVERS:
259 *(int *)cmdarg =
260 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
261 break;
262
263 case GDT_IOCTL_CTRTYPE:
264 {
265 gdt_ctrt_t *p;
266 struct gdt_softc *gdt;
267
268 p = (gdt_ctrt_t *)cmdarg;
269 gdt = gdt_minor2softc(p->io_node);
270 if (gdt == NULL)
271 return (ENXIO);
272 p->oem_id = 0x8000;
273 p->type = 0xfd;
274 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
275 p->ext_type = 0x6000 | gdt->sc_subdevice;
276 p->device_id = gdt->sc_device;
277 p->sub_device_id = gdt->sc_subdevice;
278 break;
279 }
280
281 case GDT_IOCTL_OSVERS:
282 {
283 gdt_osv_t *p;
284
285 p = (gdt_osv_t *)cmdarg;
286 p->oscode = 10;
287 p->version = osrelease[0] - '0';
288 if (osrelease[1] == '.')
289 p->subversion = osrelease[2] - '0';
290 else
291 p->subversion = 0;
292 if (osrelease[3] == '.')
293 p->revision = osrelease[4] - '0';
294 else
295 p->revision = 0;
296 strcpy(p->name, ostype);
297 break;
298 }
299
300 case GDT_IOCTL_CTRCNT:
301 *(int *)cmdarg = gdt_cnt;
302 break;
303
304 case GDT_IOCTL_EVENT:
305 {
306 gdt_event_t *p;
307 int lock;
308
309 p = (gdt_event_t *)cmdarg;
310 if (p->erase == 0xff) {
311 if (p->dvr.event_source == GDT_ES_TEST)
312 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
313 else if (p->dvr.event_source == GDT_ES_DRIVER)
314 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
315 else if (p->dvr.event_source == GDT_ES_SYNC)
316 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
317 else
318 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
319 lock = splcam();
320 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
321 &p->dvr.event_data);
322 splx(lock);
323 } else if (p->erase == 0xfe) {
324 lock = splcam();
325 gdt_clear_events();
326 splx(lock);
327 } else if (p->erase == 0) {
328 p->handle = gdt_read_event(p->handle, &p->dvr);
329 } else {
330 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
331 }
332 break;
333 }
334
335 case GDT_IOCTL_STATIST:
336 {
337 gdt_statist_t *p;
338
339 p = (gdt_statist_t *)cmdarg;
340 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
341 break;
342 }
343
344 default:
345 break;
346 }
347
348 --gdt_stat.io_count_act;
349 return (0);
350}