blob: 685d7a4507209be2144a49c40bf095b4b488b6f6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * I2O Configuration Interface Driver
3 *
4 * (C) Copyright 1999-2002 Red Hat
5 *
6 * Written by Alan Cox, Building Number Three Ltd
7 *
8 * Fixes/additions:
9 * Deepak Saxena (04/20/1999):
10 * Added basic ioctl() support
11 * Deepak Saxena (06/07/1999):
12 * Added software download ioctl (still testing)
13 * Auvo Häkkinen (09/10/1999):
14 * Changes to i2o_cfg_reply(), ioctl_parms()
15 * Added ioct_validate()
16 * Taneli Vähäkangas (09/30/1999):
17 * Fixed ioctl_swdl()
18 * Taneli Vähäkangas (10/04/1999):
19 * Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel()
20 * Deepak Saxena (11/18/1999):
21 * Added event managmenet support
22 * Alan Cox <alan@redhat.com>:
23 * 2.4 rewrite ported to 2.5
24 * Markus Lidel <Markus.Lidel@shadowconnect.com>:
25 * Added pass-thru support for Adaptec's raidutils
26 *
27 * This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License
29 * as published by the Free Software Foundation; either version
30 * 2 of the License, or (at your option) any later version.
31 */
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/miscdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/smp_lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Adrian Bunke62c23c2006-07-10 04:45:40 -070039#include "core.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Adrian Bunke62c23c2006-07-10 04:45:40 -070041#define SG_TABLESIZE 30
Markus Lideldcceafe2006-01-06 00:19:32 -080042
43static int i2o_cfg_ioctl(struct inode *, struct file *, unsigned int,
44 unsigned long);
f4c2c152005-04-10 22:29:42 -050045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static spinlock_t i2o_config_lock;
47
48#define MODINC(x,y) ((x) = ((x) + 1) % (y))
49
50struct sg_simple_element {
51 u32 flag_count;
52 u32 addr_bus;
53};
54
55struct i2o_cfg_info {
56 struct file *fp;
57 struct fasync_struct *fasync;
58 struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
59 u16 q_in; // Queue head index
60 u16 q_out; // Queue tail index
61 u16 q_len; // Queue length
62 u16 q_lost; // Number of lost events
63 ulong q_id; // Event queue ID...used as tx_context
64 struct i2o_cfg_info *next;
65};
66static struct i2o_cfg_info *open_files = NULL;
67static ulong i2o_cfg_info_id = 0;
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int i2o_cfg_getiops(unsigned long arg)
70{
71 struct i2o_controller *c;
72 u8 __user *user_iop_table = (void __user *)arg;
73 u8 tmp[MAX_I2O_CONTROLLERS];
74 int ret = 0;
75
76 memset(tmp, 0, MAX_I2O_CONTROLLERS);
77
78 list_for_each_entry(c, &i2o_controllers, list)
79 tmp[c->unit] = 1;
80
81 if (copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS))
82 ret = -EFAULT;
83
84 return ret;
85};
86
87static int i2o_cfg_gethrt(unsigned long arg)
88{
89 struct i2o_controller *c;
90 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
91 struct i2o_cmd_hrtlct kcmd;
92 i2o_hrt *hrt;
93 int len;
94 u32 reslen;
95 int ret = 0;
96
97 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
98 return -EFAULT;
99
100 if (get_user(reslen, kcmd.reslen) < 0)
101 return -EFAULT;
102
103 if (kcmd.resbuf == NULL)
104 return -EFAULT;
105
106 c = i2o_find_iop(kcmd.iop);
107 if (!c)
108 return -ENXIO;
109
110 hrt = (i2o_hrt *) c->hrt.virt;
111
112 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
113
114 /* We did a get user...so assuming mem is ok...is this bad? */
115 put_user(len, kcmd.reslen);
116 if (len > reslen)
117 ret = -ENOBUFS;
118 if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
119 ret = -EFAULT;
120
121 return ret;
122};
123
124static int i2o_cfg_getlct(unsigned long arg)
125{
126 struct i2o_controller *c;
127 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
128 struct i2o_cmd_hrtlct kcmd;
129 i2o_lct *lct;
130 int len;
131 int ret = 0;
132 u32 reslen;
133
134 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
135 return -EFAULT;
136
137 if (get_user(reslen, kcmd.reslen) < 0)
138 return -EFAULT;
139
140 if (kcmd.resbuf == NULL)
141 return -EFAULT;
142
143 c = i2o_find_iop(kcmd.iop);
144 if (!c)
145 return -ENXIO;
146
147 lct = (i2o_lct *) c->lct;
148
149 len = (unsigned int)lct->table_size << 2;
150 put_user(len, kcmd.reslen);
151 if (len > reslen)
152 ret = -ENOBUFS;
153 else if (copy_to_user(kcmd.resbuf, lct, len))
154 ret = -EFAULT;
155
156 return ret;
157};
158
159static int i2o_cfg_parms(unsigned long arg, unsigned int type)
160{
161 int ret = 0;
162 struct i2o_controller *c;
163 struct i2o_device *dev;
164 struct i2o_cmd_psetget __user *cmd =
165 (struct i2o_cmd_psetget __user *)arg;
166 struct i2o_cmd_psetget kcmd;
167 u32 reslen;
168 u8 *ops;
169 u8 *res;
170 int len = 0;
171
172 u32 i2o_cmd = (type == I2OPARMGET ?
173 I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);
174
175 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
176 return -EFAULT;
177
178 if (get_user(reslen, kcmd.reslen))
179 return -EFAULT;
180
181 c = i2o_find_iop(kcmd.iop);
182 if (!c)
183 return -ENXIO;
184
185 dev = i2o_iop_find_device(c, kcmd.tid);
186 if (!dev)
187 return -ENXIO;
188
189 ops = (u8 *) kmalloc(kcmd.oplen, GFP_KERNEL);
190 if (!ops)
191 return -ENOMEM;
192
193 if (copy_from_user(ops, kcmd.opbuf, kcmd.oplen)) {
194 kfree(ops);
195 return -EFAULT;
196 }
197
198 /*
199 * It's possible to have a _very_ large table
200 * and that the user asks for all of it at once...
201 */
202 res = (u8 *) kmalloc(65536, GFP_KERNEL);
203 if (!res) {
204 kfree(ops);
205 return -ENOMEM;
206 }
207
208 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
209 kfree(ops);
210
211 if (len < 0) {
212 kfree(res);
213 return -EAGAIN;
214 }
215
216 put_user(len, kcmd.reslen);
217 if (len > reslen)
218 ret = -ENOBUFS;
219 else if (copy_to_user(kcmd.resbuf, res, len))
220 ret = -EFAULT;
221
222 kfree(res);
223
224 return ret;
225};
226
227static int i2o_cfg_swdl(unsigned long arg)
228{
229 struct i2o_sw_xfer kxfer;
230 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
231 unsigned char maxfrag = 0, curfrag = 1;
232 struct i2o_dma buffer;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800233 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 unsigned int status = 0, swlen = 0, fragsize = 8192;
235 struct i2o_controller *c;
236
237 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
238 return -EFAULT;
239
240 if (get_user(swlen, kxfer.swlen) < 0)
241 return -EFAULT;
242
243 if (get_user(maxfrag, kxfer.maxfrag) < 0)
244 return -EFAULT;
245
246 if (get_user(curfrag, kxfer.curfrag) < 0)
247 return -EFAULT;
248
249 if (curfrag == maxfrag)
250 fragsize = swlen - (maxfrag - 1) * 8192;
251
252 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
253 return -EFAULT;
254
255 c = i2o_find_iop(kxfer.iop);
256 if (!c)
257 return -ENXIO;
258
Markus Lidela1a5ea72006-01-06 00:19:29 -0800259 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
260 if (IS_ERR(msg))
261 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
Markus Lidela1a5ea72006-01-06 00:19:29 -0800264 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return -ENOMEM;
266 }
267
Randy Dunlap9d69b7d2006-12-06 20:38:23 -0800268 if (__copy_from_user(buffer.virt, kxfer.buf, fragsize)) {
269 i2o_msg_nop(c, msg);
270 i2o_dma_free(&c->pdev->dev, &buffer);
271 return -EFAULT;
272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Markus Lidela1a5ea72006-01-06 00:19:29 -0800274 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
275 msg->u.head[1] =
276 cpu_to_le32(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 |
277 ADAPTER_TID);
278 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
279 msg->u.head[3] = cpu_to_le32(0);
280 msg->body[0] =
281 cpu_to_le32((((u32) kxfer.flags) << 24) | (((u32) kxfer.
282 sw_type) << 16) |
283 (((u32) maxfrag) << 8) | (((u32) curfrag)));
284 msg->body[1] = cpu_to_le32(swlen);
285 msg->body[2] = cpu_to_le32(kxfer.sw_id);
286 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
287 msg->body[4] = cpu_to_le32(buffer.phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
Markus Lidela1a5ea72006-01-06 00:19:29 -0800290 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 if (status != -ETIMEDOUT)
293 i2o_dma_free(&c->pdev->dev, &buffer);
294
295 if (status != I2O_POST_WAIT_OK) {
296 // it fails if you try and send frags out of order
297 // and for some yet unknown reasons too
298 osm_info("swdl failed, DetailedStatus = %d\n", status);
299 return status;
300 }
301
302 return 0;
303};
304
305static int i2o_cfg_swul(unsigned long arg)
306{
307 struct i2o_sw_xfer kxfer;
308 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
309 unsigned char maxfrag = 0, curfrag = 1;
310 struct i2o_dma buffer;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800311 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 unsigned int status = 0, swlen = 0, fragsize = 8192;
313 struct i2o_controller *c;
314 int ret = 0;
315
316 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
317 goto return_fault;
318
319 if (get_user(swlen, kxfer.swlen) < 0)
320 goto return_fault;
321
322 if (get_user(maxfrag, kxfer.maxfrag) < 0)
323 goto return_fault;
324
325 if (get_user(curfrag, kxfer.curfrag) < 0)
326 goto return_fault;
327
328 if (curfrag == maxfrag)
329 fragsize = swlen - (maxfrag - 1) * 8192;
330
331 if (!kxfer.buf)
332 goto return_fault;
333
334 c = i2o_find_iop(kxfer.iop);
335 if (!c)
336 return -ENXIO;
337
Markus Lidela1a5ea72006-01-06 00:19:29 -0800338 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
339 if (IS_ERR(msg))
340 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
Markus Lidela1a5ea72006-01-06 00:19:29 -0800343 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return -ENOMEM;
345 }
346
Markus Lidela1a5ea72006-01-06 00:19:29 -0800347 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
348 msg->u.head[1] =
349 cpu_to_le32(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID);
350 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
351 msg->u.head[3] = cpu_to_le32(0);
352 msg->body[0] =
353 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.
354 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag);
355 msg->body[1] = cpu_to_le32(swlen);
356 msg->body[2] = cpu_to_le32(kxfer.sw_id);
357 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
358 msg->body[4] = cpu_to_le32(buffer.phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
Markus Lidela1a5ea72006-01-06 00:19:29 -0800361 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 if (status != I2O_POST_WAIT_OK) {
364 if (status != -ETIMEDOUT)
365 i2o_dma_free(&c->pdev->dev, &buffer);
366
367 osm_info("swul failed, DetailedStatus = %d\n", status);
368 return status;
369 }
370
371 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
372 ret = -EFAULT;
373
374 i2o_dma_free(&c->pdev->dev, &buffer);
375
Markus Lidelf33213e2005-06-23 22:02:23 -0700376 return_ret:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return ret;
Markus Lidelf33213e2005-06-23 22:02:23 -0700378 return_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 ret = -EFAULT;
380 goto return_ret;
381};
382
383static int i2o_cfg_swdel(unsigned long arg)
384{
385 struct i2o_controller *c;
386 struct i2o_sw_xfer kxfer;
387 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800388 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 unsigned int swlen;
390 int token;
391
392 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
393 return -EFAULT;
394
395 if (get_user(swlen, kxfer.swlen) < 0)
396 return -EFAULT;
397
398 c = i2o_find_iop(kxfer.iop);
399 if (!c)
400 return -ENXIO;
401
Markus Lidela1a5ea72006-01-06 00:19:29 -0800402 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
403 if (IS_ERR(msg))
404 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Markus Lidela1a5ea72006-01-06 00:19:29 -0800406 msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
407 msg->u.head[1] =
408 cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
409 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
410 msg->u.head[3] = cpu_to_le32(0);
411 msg->body[0] =
412 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
413 msg->body[1] = cpu_to_le32(swlen);
414 msg->body[2] = cpu_to_le32(kxfer.sw_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Markus Lidela1a5ea72006-01-06 00:19:29 -0800416 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 if (token != I2O_POST_WAIT_OK) {
419 osm_info("swdel failed, DetailedStatus = %d\n", token);
420 return -ETIMEDOUT;
421 }
422
423 return 0;
424};
425
426static int i2o_cfg_validate(unsigned long arg)
427{
428 int token;
429 int iop = (int)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800430 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 struct i2o_controller *c;
432
433 c = i2o_find_iop(iop);
434 if (!c)
435 return -ENXIO;
436
Markus Lidela1a5ea72006-01-06 00:19:29 -0800437 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
438 if (IS_ERR(msg))
439 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Markus Lidela1a5ea72006-01-06 00:19:29 -0800441 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
442 msg->u.head[1] =
443 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
444 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
445 msg->u.head[3] = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Markus Lidela1a5ea72006-01-06 00:19:29 -0800447 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 if (token != I2O_POST_WAIT_OK) {
450 osm_info("Can't validate configuration, ErrorStatus = %d\n",
451 token);
452 return -ETIMEDOUT;
453 }
454
455 return 0;
456};
457
458static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
459{
Markus Lidela1a5ea72006-01-06 00:19:29 -0800460 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
462 struct i2o_evt_id kdesc;
463 struct i2o_controller *c;
464 struct i2o_device *d;
465
466 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
467 return -EFAULT;
468
469 /* IOP exists? */
470 c = i2o_find_iop(kdesc.iop);
471 if (!c)
472 return -ENXIO;
473
474 /* Device exists? */
475 d = i2o_iop_find_device(c, kdesc.tid);
476 if (!d)
477 return -ENODEV;
478
Markus Lidela1a5ea72006-01-06 00:19:29 -0800479 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
480 if (IS_ERR(msg))
481 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Markus Lidela1a5ea72006-01-06 00:19:29 -0800483 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
484 msg->u.head[1] =
485 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
486 kdesc.tid);
487 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
488 msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
489 msg->body[0] = cpu_to_le32(kdesc.evt_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Markus Lidela1a5ea72006-01-06 00:19:29 -0800491 i2o_msg_post(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 return 0;
494}
495
496static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
497{
498 struct i2o_cfg_info *p = NULL;
499 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
500 struct i2o_evt_get kget;
501 unsigned long flags;
502
503 for (p = open_files; p; p = p->next)
504 if (p->q_id == (ulong) fp->private_data)
505 break;
506
507 if (!p->q_len)
508 return -ENOENT;
509
510 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
511 MODINC(p->q_out, I2O_EVT_Q_LEN);
512 spin_lock_irqsave(&i2o_config_lock, flags);
513 p->q_len--;
514 kget.pending = p->q_len;
515 kget.lost = p->q_lost;
516 spin_unlock_irqrestore(&i2o_config_lock, flags);
517
518 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
519 return -EFAULT;
520 return 0;
521}
522
Markus Lidelb2aaee32005-06-23 22:02:19 -0700523#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524#ifdef CONFIG_COMPAT
Markus Lidelf33213e2005-06-23 22:02:23 -0700525static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
526 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 struct i2o_cmd_passthru32 __user *cmd;
529 struct i2o_controller *c;
530 u32 __user *user_msg;
531 u32 *reply = NULL;
532 u32 __user *user_reply = NULL;
533 u32 size = 0;
534 u32 reply_size = 0;
535 u32 rcode = 0;
536 struct i2o_dma sg_list[SG_TABLESIZE];
537 u32 sg_offset = 0;
538 u32 sg_count = 0;
539 u32 i = 0;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700540 u32 sg_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 i2o_status_block *sb;
542 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 unsigned int iop;
544
545 cmd = (struct i2o_cmd_passthru32 __user *)arg;
546
547 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
548 return -EFAULT;
549
550 user_msg = compat_ptr(i);
551
552 c = i2o_find_iop(iop);
553 if (!c) {
554 osm_debug("controller %d not found\n", iop);
555 return -ENXIO;
556 }
557
Markus Lidela1a5ea72006-01-06 00:19:29 -0800558 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 sb = c->status_block.virt;
561
562 if (get_user(size, &user_msg[0])) {
563 osm_warn("unable to get size!\n");
564 return -EFAULT;
565 }
566 size = size >> 16;
567
568 if (size > sb->inbound_frame_size) {
569 osm_warn("size of message > inbound_frame_size");
570 return -EFAULT;
571 }
572
573 user_reply = &user_msg[size];
574
575 size <<= 2; // Convert to bytes
576
577 /* Copy in the user's I2O command */
578 if (copy_from_user(msg, user_msg, size)) {
579 osm_warn("unable to copy user message\n");
580 return -EFAULT;
581 }
582 i2o_dump_message(msg);
583
584 if (get_user(reply_size, &user_reply[0]) < 0)
585 return -EFAULT;
586
587 reply_size >>= 16;
588 reply_size <<= 2;
589
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800590 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (!reply) {
592 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
593 c->name);
594 return -ENOMEM;
595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
600 if (sg_offset) {
601 struct sg_simple_element *sg;
602
603 if (sg_offset * 4 >= size) {
604 rcode = -EFAULT;
605 goto cleanup;
606 }
607 // TODO 64bit fix
608 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
609 sg_offset);
610 sg_count =
611 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
612 if (sg_count > SG_TABLESIZE) {
613 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
614 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700615 rcode = -EINVAL;
616 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 }
618
619 for (i = 0; i < sg_count; i++) {
620 int sg_size;
621 struct i2o_dma *p;
622
623 if (!(sg[i].flag_count & 0x10000000
624 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
625 printk(KERN_DEBUG
626 "%s:Bad SG element %d - not simple (%x)\n",
627 c->name, i, sg[i].flag_count);
628 rcode = -EINVAL;
629 goto cleanup;
630 }
631 sg_size = sg[i].flag_count & 0xffffff;
Markus Lideldcceafe2006-01-06 00:19:32 -0800632 p = &(sg_list[sg_index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* Allocate memory for the transfer */
634 if (i2o_dma_alloc
635 (&c->pdev->dev, p, sg_size,
636 PCI_DMA_BIDIRECTIONAL)) {
637 printk(KERN_DEBUG
638 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
639 c->name, sg_size, i, sg_count);
640 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700641 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
Markus Lideldcceafe2006-01-06 00:19:32 -0800643 sg_index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 /* Copy in the user's SG buffer if necessary */
645 if (sg[i].
646 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
647 // TODO 64bit fix
648 if (copy_from_user
Markus Lidelf33213e2005-06-23 22:02:23 -0700649 (p->virt,
650 (void __user *)(unsigned long)sg[i].
651 addr_bus, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 printk(KERN_DEBUG
653 "%s: Could not copy SG buf %d FROM user\n",
654 c->name, i);
655 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700656 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
658 }
659 //TODO 64bit fix
660 sg[i].addr_bus = (u32) p->phys;
661 }
662 }
663
Markus Lidela1a5ea72006-01-06 00:19:29 -0800664 rcode = i2o_msg_post_wait(c, msg, 60);
Markus Lideldcceafe2006-01-06 00:19:32 -0800665 if (rcode) {
666 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700667 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 if (sg_offset) {
Markus Lidel9e875452005-06-23 22:02:21 -0700671 u32 msg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 /* Copy back the Scatter Gather buffers back to user space */
673 u32 j;
674 // TODO 64bit fix
675 struct sg_simple_element *sg;
676 int sg_size;
677
678 // re-acquire the original message to handle correctly the sg copy operation
Markus Lidel9e875452005-06-23 22:02:21 -0700679 memset(&msg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 // get user msg size in u32s
681 if (get_user(size, &user_msg[0])) {
682 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700683 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685 size = size >> 16;
686 size *= 4;
687 /* Copy in the user's I2O command */
688 if (copy_from_user(msg, user_msg, size)) {
689 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700690 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 }
692 sg_count =
693 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
694
695 // TODO 64bit fix
696 sg = (struct sg_simple_element *)(msg + sg_offset);
697 for (j = 0; j < sg_count; j++) {
698 /* Copy out the SG list to user's buffer if necessary */
699 if (!
700 (sg[j].
701 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
702 sg_size = sg[j].flag_count & 0xffffff;
703 // TODO 64bit fix
704 if (copy_to_user
705 ((void __user *)(u64) sg[j].addr_bus,
706 sg_list[j].virt, sg_size)) {
707 printk(KERN_WARNING
708 "%s: Could not copy %p TO user %x\n",
709 c->name, sg_list[j].virt,
710 sg[j].addr_bus);
711 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700712 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714 }
715 }
716 }
717
Markus Lideldcceafe2006-01-06 00:19:32 -0800718 sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 /* Copy back the reply to user space */
720 if (reply_size) {
721 // we wrote our own values for context - now restore the user supplied ones
722 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
723 printk(KERN_WARNING
724 "%s: Could not copy message context FROM user\n",
725 c->name);
726 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700727 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 }
729 if (copy_to_user(user_reply, reply, reply_size)) {
730 printk(KERN_WARNING
731 "%s: Could not copy reply TO user\n", c->name);
732 rcode = -EFAULT;
733 }
734 }
735
Markus Lidel61fbfa82005-06-23 22:02:11 -0700736 for (i = 0; i < sg_index; i++)
737 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 cleanup:
740 kfree(reply);
741 return rcode;
742}
743
Markus Lidelf33213e2005-06-23 22:02:23 -0700744static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
745 unsigned long arg)
f4c2c152005-04-10 22:29:42 -0500746{
747 int ret;
Markus Lidelf33213e2005-06-23 22:02:23 -0700748 lock_kernel();
749 switch (cmd) {
f4c2c152005-04-10 22:29:42 -0500750 case I2OGETIOPS:
751 ret = i2o_cfg_ioctl(NULL, file, cmd, arg);
752 break;
753 case I2OPASSTHRU32:
754 ret = i2o_cfg_passthru32(file, cmd, arg);
755 break;
756 default:
757 ret = -ENOIOCTLCMD;
758 break;
759 }
760 unlock_kernel();
761 return ret;
762}
763
764#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766static int i2o_cfg_passthru(unsigned long arg)
767{
768 struct i2o_cmd_passthru __user *cmd =
769 (struct i2o_cmd_passthru __user *)arg;
770 struct i2o_controller *c;
771 u32 __user *user_msg;
772 u32 *reply = NULL;
773 u32 __user *user_reply = NULL;
774 u32 size = 0;
775 u32 reply_size = 0;
776 u32 rcode = 0;
777 void *sg_list[SG_TABLESIZE];
778 u32 sg_offset = 0;
779 u32 sg_count = 0;
780 int sg_index = 0;
781 u32 i = 0;
782 void *p = NULL;
783 i2o_status_block *sb;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800784 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 unsigned int iop;
786
787 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
788 return -EFAULT;
789
790 c = i2o_find_iop(iop);
791 if (!c) {
792 osm_warn("controller %d not found\n", iop);
793 return -ENXIO;
794 }
795
Markus Lidela1a5ea72006-01-06 00:19:29 -0800796 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 sb = c->status_block.virt;
799
800 if (get_user(size, &user_msg[0]))
801 return -EFAULT;
802 size = size >> 16;
803
804 if (size > sb->inbound_frame_size) {
805 osm_warn("size of message > inbound_frame_size");
806 return -EFAULT;
807 }
808
809 user_reply = &user_msg[size];
810
811 size <<= 2; // Convert to bytes
812
813 /* Copy in the user's I2O command */
814 if (copy_from_user(msg, user_msg, size))
815 return -EFAULT;
816
817 if (get_user(reply_size, &user_reply[0]) < 0)
818 return -EFAULT;
819
820 reply_size >>= 16;
821 reply_size <<= 2;
822
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800823 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (!reply) {
825 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
826 c->name);
827 return -ENOMEM;
828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
833 if (sg_offset) {
834 struct sg_simple_element *sg;
835
836 if (sg_offset * 4 >= size) {
837 rcode = -EFAULT;
838 goto cleanup;
839 }
840 // TODO 64bit fix
841 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
842 sg_offset);
843 sg_count =
844 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
845 if (sg_count > SG_TABLESIZE) {
846 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
847 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700848 rcode = -EINVAL;
849 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851
852 for (i = 0; i < sg_count; i++) {
853 int sg_size;
854
855 if (!(sg[i].flag_count & 0x10000000
856 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
857 printk(KERN_DEBUG
858 "%s:Bad SG element %d - not simple (%x)\n",
859 c->name, i, sg[i].flag_count);
860 rcode = -EINVAL;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700861 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
863 sg_size = sg[i].flag_count & 0xffffff;
864 /* Allocate memory for the transfer */
865 p = kmalloc(sg_size, GFP_KERNEL);
866 if (!p) {
867 printk(KERN_DEBUG
868 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
869 c->name, sg_size, i, sg_count);
870 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700871 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
873 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame.
874 /* Copy in the user's SG buffer if necessary */
875 if (sg[i].
876 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
877 // TODO 64bit fix
878 if (copy_from_user
879 (p, (void __user *)sg[i].addr_bus,
880 sg_size)) {
881 printk(KERN_DEBUG
882 "%s: Could not copy SG buf %d FROM user\n",
883 c->name, i);
884 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700885 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 }
887 }
888 //TODO 64bit fix
889 sg[i].addr_bus = virt_to_bus(p);
890 }
891 }
892
Markus Lidela1a5ea72006-01-06 00:19:29 -0800893 rcode = i2o_msg_post_wait(c, msg, 60);
Markus Lideldcceafe2006-01-06 00:19:32 -0800894 if (rcode) {
895 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700896 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 if (sg_offset) {
900 u32 msg[128];
901 /* Copy back the Scatter Gather buffers back to user space */
902 u32 j;
903 // TODO 64bit fix
904 struct sg_simple_element *sg;
905 int sg_size;
906
907 // re-acquire the original message to handle correctly the sg copy operation
Markus Lidel9e875452005-06-23 22:02:21 -0700908 memset(&msg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 // get user msg size in u32s
910 if (get_user(size, &user_msg[0])) {
911 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700912 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 size = size >> 16;
915 size *= 4;
916 /* Copy in the user's I2O command */
917 if (copy_from_user(msg, user_msg, size)) {
918 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700919 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921 sg_count =
922 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
923
924 // TODO 64bit fix
925 sg = (struct sg_simple_element *)(msg + sg_offset);
926 for (j = 0; j < sg_count; j++) {
927 /* Copy out the SG list to user's buffer if necessary */
928 if (!
929 (sg[j].
930 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
931 sg_size = sg[j].flag_count & 0xffffff;
932 // TODO 64bit fix
933 if (copy_to_user
934 ((void __user *)sg[j].addr_bus, sg_list[j],
935 sg_size)) {
936 printk(KERN_WARNING
937 "%s: Could not copy %p TO user %x\n",
938 c->name, sg_list[j],
939 sg[j].addr_bus);
940 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700941 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 }
943 }
944 }
945 }
946
Markus Lideldcceafe2006-01-06 00:19:32 -0800947 sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 /* Copy back the reply to user space */
949 if (reply_size) {
950 // we wrote our own values for context - now restore the user supplied ones
951 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
952 printk(KERN_WARNING
953 "%s: Could not copy message context FROM user\n",
954 c->name);
955 rcode = -EFAULT;
956 }
957 if (copy_to_user(user_reply, reply, reply_size)) {
958 printk(KERN_WARNING
959 "%s: Could not copy reply TO user\n", c->name);
960 rcode = -EFAULT;
961 }
962 }
963
Markus Lidel61fbfa82005-06-23 22:02:11 -0700964 for (i = 0; i < sg_index; i++)
965 kfree(sg_list[i]);
966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 cleanup:
968 kfree(reply);
969 return rcode;
970}
Markus Lidelb2aaee32005-06-23 22:02:19 -0700971#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973/*
974 * IOCTL Handler
975 */
976static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
977 unsigned long arg)
978{
979 int ret;
980
981 switch (cmd) {
982 case I2OGETIOPS:
983 ret = i2o_cfg_getiops(arg);
984 break;
985
986 case I2OHRTGET:
987 ret = i2o_cfg_gethrt(arg);
988 break;
989
990 case I2OLCTGET:
991 ret = i2o_cfg_getlct(arg);
992 break;
993
994 case I2OPARMSET:
995 ret = i2o_cfg_parms(arg, I2OPARMSET);
996 break;
997
998 case I2OPARMGET:
999 ret = i2o_cfg_parms(arg, I2OPARMGET);
1000 break;
1001
1002 case I2OSWDL:
1003 ret = i2o_cfg_swdl(arg);
1004 break;
1005
1006 case I2OSWUL:
1007 ret = i2o_cfg_swul(arg);
1008 break;
1009
1010 case I2OSWDEL:
1011 ret = i2o_cfg_swdel(arg);
1012 break;
1013
1014 case I2OVALIDATE:
1015 ret = i2o_cfg_validate(arg);
1016 break;
1017
1018 case I2OEVTREG:
1019 ret = i2o_cfg_evt_reg(arg, fp);
1020 break;
1021
1022 case I2OEVTGET:
1023 ret = i2o_cfg_evt_get(arg, fp);
1024 break;
1025
Markus Lidelb2aaee32005-06-23 22:02:19 -07001026#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 case I2OPASSTHRU:
1028 ret = i2o_cfg_passthru(arg);
1029 break;
Markus Lidelb2aaee32005-06-23 22:02:19 -07001030#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 default:
1033 osm_debug("unknown ioctl called!\n");
1034 ret = -EINVAL;
1035 }
1036
1037 return ret;
1038}
1039
1040static int cfg_open(struct inode *inode, struct file *file)
1041{
1042 struct i2o_cfg_info *tmp =
1043 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1044 GFP_KERNEL);
1045 unsigned long flags;
1046
1047 if (!tmp)
1048 return -ENOMEM;
1049
1050 file->private_data = (void *)(i2o_cfg_info_id++);
1051 tmp->fp = file;
1052 tmp->fasync = NULL;
1053 tmp->q_id = (ulong) file->private_data;
1054 tmp->q_len = 0;
1055 tmp->q_in = 0;
1056 tmp->q_out = 0;
1057 tmp->q_lost = 0;
1058 tmp->next = open_files;
1059
1060 spin_lock_irqsave(&i2o_config_lock, flags);
1061 open_files = tmp;
1062 spin_unlock_irqrestore(&i2o_config_lock, flags);
1063
1064 return 0;
1065}
1066
1067static int cfg_fasync(int fd, struct file *fp, int on)
1068{
1069 ulong id = (ulong) fp->private_data;
1070 struct i2o_cfg_info *p;
1071
1072 for (p = open_files; p; p = p->next)
1073 if (p->q_id == id)
1074 break;
1075
1076 if (!p)
1077 return -EBADF;
1078
1079 return fasync_helper(fd, fp, on, &p->fasync);
1080}
1081
1082static int cfg_release(struct inode *inode, struct file *file)
1083{
1084 ulong id = (ulong) file->private_data;
1085 struct i2o_cfg_info *p1, *p2;
1086 unsigned long flags;
1087
1088 lock_kernel();
1089 p1 = p2 = NULL;
1090
1091 spin_lock_irqsave(&i2o_config_lock, flags);
1092 for (p1 = open_files; p1;) {
1093 if (p1->q_id == id) {
1094
1095 if (p1->fasync)
1096 cfg_fasync(-1, file, 0);
1097 if (p2)
1098 p2->next = p1->next;
1099 else
1100 open_files = p1->next;
1101
1102 kfree(p1);
1103 break;
1104 }
1105 p2 = p1;
1106 p1 = p1->next;
1107 }
1108 spin_unlock_irqrestore(&i2o_config_lock, flags);
1109 unlock_kernel();
1110
1111 return 0;
1112}
1113
1114static struct file_operations config_fops = {
1115 .owner = THIS_MODULE,
1116 .llseek = no_llseek,
1117 .ioctl = i2o_cfg_ioctl,
f4c2c152005-04-10 22:29:42 -05001118#ifdef CONFIG_COMPAT
1119 .compat_ioctl = i2o_cfg_compat_ioctl,
1120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 .open = cfg_open,
1122 .release = cfg_release,
1123 .fasync = cfg_fasync,
1124};
1125
1126static struct miscdevice i2o_miscdev = {
1127 I2O_MINOR,
1128 "i2octl",
1129 &config_fops
1130};
1131
Markus Lidelf10378f2005-06-23 22:02:16 -07001132static int __init i2o_config_old_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 spin_lock_init(&i2o_config_lock);
1135
1136 if (misc_register(&i2o_miscdev) < 0) {
1137 osm_err("can't register device.\n");
1138 return -EBUSY;
1139 }
Markus Lidelf33213e2005-06-23 22:02:23 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 return 0;
1142}
1143
Markus Lidelf10378f2005-06-23 22:02:16 -07001144static void i2o_config_old_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 misc_deregister(&i2o_miscdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
1149MODULE_AUTHOR("Red Hat Software");