blob: d33693c133689522e5ca74e8de41c8aaa7c42066 [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)
Jan Engelhardt96de0e22007-10-19 23:21:04 +020013 * Auvo Häkkinen (09/10/1999):
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * Changes to i2o_cfg_reply(), ioctl_parms()
15 * Added ioct_validate()
Jan Engelhardt96de0e22007-10-19 23:21:04 +020016 * Taneli Vähäkangas (09/30/1999):
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * Fixed ioctl_swdl()
Jan Engelhardt96de0e22007-10-19 23:21:04 +020018 * Taneli Vähäkangas (10/04/1999):
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel()
20 * Deepak Saxena (11/18/1999):
21 * Added event managmenet support
Alan Coxf1b11e52009-01-05 14:04:40 +000022 * Alan Cox <alan@lxorguk.ukuu.org.uk>:
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Adrian Bunke62c23c2006-07-10 04:45:40 -070040#include "core.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Adrian Bunke62c23c2006-07-10 04:45:40 -070042#define SG_TABLESIZE 30
Markus Lideldcceafe2006-01-06 00:19:32 -080043
Alan Cox5d9d6e42010-01-04 16:18:27 +000044static long i2o_cfg_ioctl(struct file *, unsigned int, 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
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800189 ops = kmalloc(kcmd.oplen, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 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 */
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800202 res = kmalloc(65536, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 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
Alan Cox9d793b02008-10-15 22:02:47 -0700263 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
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)))
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200317 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 if (get_user(swlen, kxfer.swlen) < 0)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200320 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 if (get_user(maxfrag, kxfer.maxfrag) < 0)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200323 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 if (get_user(curfrag, kxfer.curfrag) < 0)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200326 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 if (curfrag == maxfrag)
329 fragsize = swlen - (maxfrag - 1) * 8192;
330
331 if (!kxfer.buf)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200332 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
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
Alan Cox9d793b02008-10-15 22:02:47 -0700342 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return ret;
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200377}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379static int i2o_cfg_swdel(unsigned long arg)
380{
381 struct i2o_controller *c;
382 struct i2o_sw_xfer kxfer;
383 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800384 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 unsigned int swlen;
386 int token;
387
388 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
389 return -EFAULT;
390
391 if (get_user(swlen, kxfer.swlen) < 0)
392 return -EFAULT;
393
394 c = i2o_find_iop(kxfer.iop);
395 if (!c)
396 return -ENXIO;
397
Markus Lidela1a5ea72006-01-06 00:19:29 -0800398 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
399 if (IS_ERR(msg))
400 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Markus Lidela1a5ea72006-01-06 00:19:29 -0800402 msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
403 msg->u.head[1] =
404 cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
405 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
406 msg->u.head[3] = cpu_to_le32(0);
407 msg->body[0] =
408 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
409 msg->body[1] = cpu_to_le32(swlen);
410 msg->body[2] = cpu_to_le32(kxfer.sw_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Markus Lidela1a5ea72006-01-06 00:19:29 -0800412 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 if (token != I2O_POST_WAIT_OK) {
415 osm_info("swdel failed, DetailedStatus = %d\n", token);
416 return -ETIMEDOUT;
417 }
418
419 return 0;
420};
421
422static int i2o_cfg_validate(unsigned long arg)
423{
424 int token;
425 int iop = (int)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800426 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 struct i2o_controller *c;
428
429 c = i2o_find_iop(iop);
430 if (!c)
431 return -ENXIO;
432
Markus Lidela1a5ea72006-01-06 00:19:29 -0800433 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
434 if (IS_ERR(msg))
435 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Markus Lidela1a5ea72006-01-06 00:19:29 -0800437 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
438 msg->u.head[1] =
439 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
440 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
441 msg->u.head[3] = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Markus Lidela1a5ea72006-01-06 00:19:29 -0800443 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 if (token != I2O_POST_WAIT_OK) {
446 osm_info("Can't validate configuration, ErrorStatus = %d\n",
447 token);
448 return -ETIMEDOUT;
449 }
450
451 return 0;
452};
453
454static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
455{
Markus Lidela1a5ea72006-01-06 00:19:29 -0800456 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
458 struct i2o_evt_id kdesc;
459 struct i2o_controller *c;
460 struct i2o_device *d;
461
462 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
463 return -EFAULT;
464
465 /* IOP exists? */
466 c = i2o_find_iop(kdesc.iop);
467 if (!c)
468 return -ENXIO;
469
470 /* Device exists? */
471 d = i2o_iop_find_device(c, kdesc.tid);
472 if (!d)
473 return -ENODEV;
474
Markus Lidela1a5ea72006-01-06 00:19:29 -0800475 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
476 if (IS_ERR(msg))
477 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Markus Lidela1a5ea72006-01-06 00:19:29 -0800479 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
480 msg->u.head[1] =
481 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
482 kdesc.tid);
483 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
484 msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
485 msg->body[0] = cpu_to_le32(kdesc.evt_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Markus Lidela1a5ea72006-01-06 00:19:29 -0800487 i2o_msg_post(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 return 0;
490}
491
492static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
493{
494 struct i2o_cfg_info *p = NULL;
495 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
496 struct i2o_evt_get kget;
497 unsigned long flags;
498
499 for (p = open_files; p; p = p->next)
500 if (p->q_id == (ulong) fp->private_data)
501 break;
502
503 if (!p->q_len)
504 return -ENOENT;
505
506 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
507 MODINC(p->q_out, I2O_EVT_Q_LEN);
508 spin_lock_irqsave(&i2o_config_lock, flags);
509 p->q_len--;
510 kget.pending = p->q_len;
511 kget.lost = p->q_lost;
512 spin_unlock_irqrestore(&i2o_config_lock, flags);
513
514 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
515 return -EFAULT;
516 return 0;
517}
518
519#ifdef CONFIG_COMPAT
Markus Lidelf33213e2005-06-23 22:02:23 -0700520static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
521 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 struct i2o_cmd_passthru32 __user *cmd;
524 struct i2o_controller *c;
525 u32 __user *user_msg;
526 u32 *reply = NULL;
527 u32 __user *user_reply = NULL;
528 u32 size = 0;
529 u32 reply_size = 0;
530 u32 rcode = 0;
531 struct i2o_dma sg_list[SG_TABLESIZE];
532 u32 sg_offset = 0;
533 u32 sg_count = 0;
534 u32 i = 0;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700535 u32 sg_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 i2o_status_block *sb;
537 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 unsigned int iop;
539
540 cmd = (struct i2o_cmd_passthru32 __user *)arg;
541
542 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
543 return -EFAULT;
544
545 user_msg = compat_ptr(i);
546
547 c = i2o_find_iop(iop);
548 if (!c) {
549 osm_debug("controller %d not found\n", iop);
550 return -ENXIO;
551 }
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 sb = c->status_block.virt;
554
555 if (get_user(size, &user_msg[0])) {
556 osm_warn("unable to get size!\n");
557 return -EFAULT;
558 }
559 size = size >> 16;
560
561 if (size > sb->inbound_frame_size) {
562 osm_warn("size of message > inbound_frame_size");
563 return -EFAULT;
564 }
565
566 user_reply = &user_msg[size];
567
568 size <<= 2; // Convert to bytes
569
Vasily Averin1725d712007-07-17 04:04:24 -0700570 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
571 if (IS_ERR(msg))
572 return PTR_ERR(msg);
573
574 rcode = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /* Copy in the user's I2O command */
576 if (copy_from_user(msg, user_msg, size)) {
577 osm_warn("unable to copy user message\n");
Vasily Averin1725d712007-07-17 04:04:24 -0700578 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580 i2o_dump_message(msg);
581
582 if (get_user(reply_size, &user_reply[0]) < 0)
Vasily Averin1725d712007-07-17 04:04:24 -0700583 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 reply_size >>= 16;
586 reply_size <<= 2;
587
Vasily Averin1725d712007-07-17 04:04:24 -0700588 rcode = -ENOMEM;
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800589 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (!reply) {
591 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
592 c->name);
Vasily Averin1725d712007-07-17 04:04:24 -0700593 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
599 if (sg_offset) {
600 struct sg_simple_element *sg;
601
602 if (sg_offset * 4 >= size) {
603 rcode = -EFAULT;
604 goto cleanup;
605 }
606 // TODO 64bit fix
607 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
608 sg_offset);
609 sg_count =
610 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
611 if (sg_count > SG_TABLESIZE) {
612 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
613 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700614 rcode = -EINVAL;
615 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
617
618 for (i = 0; i < sg_count; i++) {
619 int sg_size;
620 struct i2o_dma *p;
621
622 if (!(sg[i].flag_count & 0x10000000
623 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
624 printk(KERN_DEBUG
625 "%s:Bad SG element %d - not simple (%x)\n",
626 c->name, i, sg[i].flag_count);
627 rcode = -EINVAL;
628 goto cleanup;
629 }
630 sg_size = sg[i].flag_count & 0xffffff;
Markus Lideldcceafe2006-01-06 00:19:32 -0800631 p = &(sg_list[sg_index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 /* Allocate memory for the transfer */
Alan Cox9d793b02008-10-15 22:02:47 -0700633 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 printk(KERN_DEBUG
635 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
636 c->name, sg_size, i, sg_count);
637 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700638 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
Markus Lideldcceafe2006-01-06 00:19:32 -0800640 sg_index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* Copy in the user's SG buffer if necessary */
642 if (sg[i].
643 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
644 // TODO 64bit fix
645 if (copy_from_user
Markus Lidelf33213e2005-06-23 22:02:23 -0700646 (p->virt,
647 (void __user *)(unsigned long)sg[i].
648 addr_bus, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 printk(KERN_DEBUG
650 "%s: Could not copy SG buf %d FROM user\n",
651 c->name, i);
652 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700653 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655 }
656 //TODO 64bit fix
657 sg[i].addr_bus = (u32) p->phys;
658 }
659 }
660
Markus Lidela1a5ea72006-01-06 00:19:29 -0800661 rcode = i2o_msg_post_wait(c, msg, 60);
Vasily Averin1725d712007-07-17 04:04:24 -0700662 msg = NULL;
Markus Lideldcceafe2006-01-06 00:19:32 -0800663 if (rcode) {
664 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700665 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 if (sg_offset) {
Vasily Averin1725d712007-07-17 04:04:24 -0700669 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* Copy back the Scatter Gather buffers back to user space */
671 u32 j;
672 // TODO 64bit fix
673 struct sg_simple_element *sg;
674 int sg_size;
675
676 // re-acquire the original message to handle correctly the sg copy operation
Vasily Averin1725d712007-07-17 04:04:24 -0700677 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 // get user msg size in u32s
679 if (get_user(size, &user_msg[0])) {
680 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700681 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683 size = size >> 16;
684 size *= 4;
685 /* Copy in the user's I2O command */
Vasily Averin1725d712007-07-17 04:04:24 -0700686 if (copy_from_user(rmsg, user_msg, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700688 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690 sg_count =
691 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
692
693 // TODO 64bit fix
Vasily Averin1725d712007-07-17 04:04:24 -0700694 sg = (struct sg_simple_element *)(rmsg + sg_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 for (j = 0; j < sg_count; j++) {
696 /* Copy out the SG list to user's buffer if necessary */
697 if (!
698 (sg[j].
699 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
700 sg_size = sg[j].flag_count & 0xffffff;
701 // TODO 64bit fix
702 if (copy_to_user
703 ((void __user *)(u64) sg[j].addr_bus,
704 sg_list[j].virt, sg_size)) {
705 printk(KERN_WARNING
706 "%s: Could not copy %p TO user %x\n",
707 c->name, sg_list[j].virt,
708 sg[j].addr_bus);
709 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700710 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
712 }
713 }
714 }
715
Vasily Averin1725d712007-07-17 04:04:24 -0700716sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 /* Copy back the reply to user space */
718 if (reply_size) {
719 // we wrote our own values for context - now restore the user supplied ones
720 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
721 printk(KERN_WARNING
722 "%s: Could not copy message context FROM user\n",
723 c->name);
724 rcode = -EFAULT;
725 }
726 if (copy_to_user(user_reply, reply, reply_size)) {
727 printk(KERN_WARNING
728 "%s: Could not copy reply TO user\n", c->name);
729 rcode = -EFAULT;
730 }
731 }
Markus Lidel61fbfa82005-06-23 22:02:11 -0700732 for (i = 0; i < sg_index; i++)
733 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
734
Vasily Averin1725d712007-07-17 04:04:24 -0700735cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 kfree(reply);
Vasily Averin1725d712007-07-17 04:04:24 -0700737out:
738 if (msg)
739 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return rcode;
741}
742
Markus Lidelf33213e2005-06-23 22:02:23 -0700743static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
744 unsigned long arg)
f4c2c152005-04-10 22:29:42 -0500745{
746 int ret;
Markus Lidelf33213e2005-06-23 22:02:23 -0700747 lock_kernel();
748 switch (cmd) {
f4c2c152005-04-10 22:29:42 -0500749 case I2OGETIOPS:
Alan Cox5d9d6e42010-01-04 16:18:27 +0000750 ret = i2o_cfg_ioctl(file, cmd, arg);
f4c2c152005-04-10 22:29:42 -0500751 break;
752 case I2OPASSTHRU32:
753 ret = i2o_cfg_passthru32(file, cmd, arg);
754 break;
755 default:
756 ret = -ENOIOCTLCMD;
757 break;
758 }
759 unlock_kernel();
760 return ret;
761}
762
763#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Randy Dunlapf13a6032006-12-06 20:38:24 -0800765#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766static 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;
Alan Cox9d793b02008-10-15 22:02:47 -0700777 struct i2o_dma sg_list[SG_TABLESIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 u32 sg_offset = 0;
779 u32 sg_count = 0;
780 int sg_index = 0;
781 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 i2o_status_block *sb;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800783 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 unsigned int iop;
785
786 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
787 return -EFAULT;
788
789 c = i2o_find_iop(iop);
790 if (!c) {
791 osm_warn("controller %d not found\n", iop);
792 return -ENXIO;
793 }
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 sb = c->status_block.virt;
796
797 if (get_user(size, &user_msg[0]))
798 return -EFAULT;
799 size = size >> 16;
800
801 if (size > sb->inbound_frame_size) {
802 osm_warn("size of message > inbound_frame_size");
803 return -EFAULT;
804 }
805
806 user_reply = &user_msg[size];
807
808 size <<= 2; // Convert to bytes
809
Vasily Averin1725d712007-07-17 04:04:24 -0700810 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
811 if (IS_ERR(msg))
812 return PTR_ERR(msg);
813
814 rcode = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 /* Copy in the user's I2O command */
816 if (copy_from_user(msg, user_msg, size))
Vasily Averin1725d712007-07-17 04:04:24 -0700817 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 if (get_user(reply_size, &user_reply[0]) < 0)
Vasily Averin1725d712007-07-17 04:04:24 -0700820 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 reply_size >>= 16;
823 reply_size <<= 2;
824
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800825 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (!reply) {
827 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
828 c->name);
Vasily Averin1725d712007-07-17 04:04:24 -0700829 rcode = -ENOMEM;
830 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
836 if (sg_offset) {
837 struct sg_simple_element *sg;
Alan Cox9d793b02008-10-15 22:02:47 -0700838 struct i2o_dma *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (sg_offset * 4 >= size) {
841 rcode = -EFAULT;
842 goto cleanup;
843 }
844 // TODO 64bit fix
845 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
846 sg_offset);
847 sg_count =
848 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
849 if (sg_count > SG_TABLESIZE) {
850 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
851 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700852 rcode = -EINVAL;
853 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
855
856 for (i = 0; i < sg_count; i++) {
857 int sg_size;
858
859 if (!(sg[i].flag_count & 0x10000000
860 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
861 printk(KERN_DEBUG
862 "%s:Bad SG element %d - not simple (%x)\n",
863 c->name, i, sg[i].flag_count);
864 rcode = -EINVAL;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700865 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867 sg_size = sg[i].flag_count & 0xffffff;
Alan Cox9d793b02008-10-15 22:02:47 -0700868 p = &(sg_list[sg_index]);
869 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 /* Allocate memory for the transfer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 printk(KERN_DEBUG
872 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
873 c->name, sg_size, i, sg_count);
874 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700875 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 }
Alan Cox9d793b02008-10-15 22:02:47 -0700877 sg_index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /* Copy in the user's SG buffer if necessary */
879 if (sg[i].
880 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
881 // TODO 64bit fix
882 if (copy_from_user
Alan Cox9d793b02008-10-15 22:02:47 -0700883 (p->virt, (void __user *)sg[i].addr_bus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 sg_size)) {
885 printk(KERN_DEBUG
886 "%s: Could not copy SG buf %d FROM user\n",
887 c->name, i);
888 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700889 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 }
891 }
Alan Cox9d793b02008-10-15 22:02:47 -0700892 sg[i].addr_bus = p->phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 }
894 }
895
Markus Lidela1a5ea72006-01-06 00:19:29 -0800896 rcode = i2o_msg_post_wait(c, msg, 60);
Vasily Averin1725d712007-07-17 04:04:24 -0700897 msg = NULL;
Markus Lideldcceafe2006-01-06 00:19:32 -0800898 if (rcode) {
899 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700900 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 if (sg_offset) {
Alan Cox9d793b02008-10-15 22:02:47 -0700904 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 /* Copy back the Scatter Gather buffers back to user space */
906 u32 j;
907 // TODO 64bit fix
908 struct sg_simple_element *sg;
909 int sg_size;
910
911 // re-acquire the original message to handle correctly the sg copy operation
Vasily Averin1725d712007-07-17 04:04:24 -0700912 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 // get user msg size in u32s
914 if (get_user(size, &user_msg[0])) {
915 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700916 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918 size = size >> 16;
919 size *= 4;
920 /* Copy in the user's I2O command */
Vasily Averin1725d712007-07-17 04:04:24 -0700921 if (copy_from_user(rmsg, user_msg, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700923 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925 sg_count =
926 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
927
928 // TODO 64bit fix
Vasily Averin1725d712007-07-17 04:04:24 -0700929 sg = (struct sg_simple_element *)(rmsg + sg_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 for (j = 0; j < sg_count; j++) {
931 /* Copy out the SG list to user's buffer if necessary */
932 if (!
933 (sg[j].
934 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
935 sg_size = sg[j].flag_count & 0xffffff;
936 // TODO 64bit fix
937 if (copy_to_user
Alan Cox9d793b02008-10-15 22:02:47 -0700938 ((void __user *)sg[j].addr_bus, sg_list[j].virt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 sg_size)) {
940 printk(KERN_WARNING
941 "%s: Could not copy %p TO user %x\n",
Alan Cox9d793b02008-10-15 22:02:47 -0700942 c->name, sg_list[j].virt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 sg[j].addr_bus);
944 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700945 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 }
947 }
948 }
949 }
950
Vasily Averin1725d712007-07-17 04:04:24 -0700951sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 /* Copy back the reply to user space */
953 if (reply_size) {
954 // we wrote our own values for context - now restore the user supplied ones
955 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
956 printk(KERN_WARNING
957 "%s: Could not copy message context FROM user\n",
958 c->name);
959 rcode = -EFAULT;
960 }
961 if (copy_to_user(user_reply, reply, reply_size)) {
962 printk(KERN_WARNING
963 "%s: Could not copy reply TO user\n", c->name);
964 rcode = -EFAULT;
965 }
966 }
967
Markus Lidel61fbfa82005-06-23 22:02:11 -0700968 for (i = 0; i < sg_index; i++)
Alan Cox9d793b02008-10-15 22:02:47 -0700969 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700970
Vasily Averin1725d712007-07-17 04:04:24 -0700971cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 kfree(reply);
Vasily Averin1725d712007-07-17 04:04:24 -0700973out:
974 if (msg)
975 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 return rcode;
977}
Markus Lidelb2aaee32005-06-23 22:02:19 -0700978#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980/*
981 * IOCTL Handler
982 */
Alan Cox5d9d6e42010-01-04 16:18:27 +0000983static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
985 int ret;
986
Alan Cox5d9d6e42010-01-04 16:18:27 +0000987 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 switch (cmd) {
989 case I2OGETIOPS:
990 ret = i2o_cfg_getiops(arg);
991 break;
992
993 case I2OHRTGET:
994 ret = i2o_cfg_gethrt(arg);
995 break;
996
997 case I2OLCTGET:
998 ret = i2o_cfg_getlct(arg);
999 break;
1000
1001 case I2OPARMSET:
1002 ret = i2o_cfg_parms(arg, I2OPARMSET);
1003 break;
1004
1005 case I2OPARMGET:
1006 ret = i2o_cfg_parms(arg, I2OPARMGET);
1007 break;
1008
1009 case I2OSWDL:
1010 ret = i2o_cfg_swdl(arg);
1011 break;
1012
1013 case I2OSWUL:
1014 ret = i2o_cfg_swul(arg);
1015 break;
1016
1017 case I2OSWDEL:
1018 ret = i2o_cfg_swdel(arg);
1019 break;
1020
1021 case I2OVALIDATE:
1022 ret = i2o_cfg_validate(arg);
1023 break;
1024
1025 case I2OEVTREG:
1026 ret = i2o_cfg_evt_reg(arg, fp);
1027 break;
1028
1029 case I2OEVTGET:
1030 ret = i2o_cfg_evt_get(arg, fp);
1031 break;
1032
Markus Lidelb2aaee32005-06-23 22:02:19 -07001033#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 case I2OPASSTHRU:
1035 ret = i2o_cfg_passthru(arg);
1036 break;
Markus Lidelb2aaee32005-06-23 22:02:19 -07001037#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 default:
1040 osm_debug("unknown ioctl called!\n");
1041 ret = -EINVAL;
1042 }
Alan Cox5d9d6e42010-01-04 16:18:27 +00001043 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return ret;
1045}
1046
1047static int cfg_open(struct inode *inode, struct file *file)
1048{
1049 struct i2o_cfg_info *tmp =
1050 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1051 GFP_KERNEL);
1052 unsigned long flags;
1053
1054 if (!tmp)
1055 return -ENOMEM;
1056
Arnd Bergmannb78032a2008-05-20 19:16:14 +02001057 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 file->private_data = (void *)(i2o_cfg_info_id++);
1059 tmp->fp = file;
1060 tmp->fasync = NULL;
1061 tmp->q_id = (ulong) file->private_data;
1062 tmp->q_len = 0;
1063 tmp->q_in = 0;
1064 tmp->q_out = 0;
1065 tmp->q_lost = 0;
1066 tmp->next = open_files;
1067
1068 spin_lock_irqsave(&i2o_config_lock, flags);
1069 open_files = tmp;
1070 spin_unlock_irqrestore(&i2o_config_lock, flags);
Arnd Bergmannb78032a2008-05-20 19:16:14 +02001071 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 return 0;
1074}
1075
1076static int cfg_fasync(int fd, struct file *fp, int on)
1077{
1078 ulong id = (ulong) fp->private_data;
1079 struct i2o_cfg_info *p;
Jonathan Corbet743115e2008-06-19 15:44:57 -06001080 int ret = -EBADF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Jonathan Corbet743115e2008-06-19 15:44:57 -06001082 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 for (p = open_files; p; p = p->next)
1084 if (p->q_id == id)
1085 break;
1086
Jonathan Corbet743115e2008-06-19 15:44:57 -06001087 if (p)
1088 ret = fasync_helper(fd, fp, on, &p->fasync);
1089 unlock_kernel();
1090 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
1093static int cfg_release(struct inode *inode, struct file *file)
1094{
1095 ulong id = (ulong) file->private_data;
Al Viro233e70f2008-10-31 23:28:30 +00001096 struct i2o_cfg_info *p, **q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 unsigned long flags;
1098
1099 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 spin_lock_irqsave(&i2o_config_lock, flags);
Al Viro233e70f2008-10-31 23:28:30 +00001101 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1102 if (p->q_id == id) {
1103 *q = p->next;
1104 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 break;
1106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 }
1108 spin_unlock_irqrestore(&i2o_config_lock, flags);
1109 unlock_kernel();
1110
1111 return 0;
1112}
1113
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001114static const struct file_operations config_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 .owner = THIS_MODULE,
1116 .llseek = no_llseek,
Alan Cox5d9d6e42010-01-04 16:18:27 +00001117 .unlocked_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");