blob: c4b117f5fb70959df600a2153ac7d961a692488c [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
Julia Lawallb81d67a2010-05-26 14:42:12 -0700189 ops = memdup_user(kcmd.opbuf, kcmd.oplen);
190 if (IS_ERR(ops))
191 return PTR_ERR(ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /*
194 * It's possible to have a _very_ large table
195 * and that the user asks for all of it at once...
196 */
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800197 res = kmalloc(65536, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (!res) {
199 kfree(ops);
200 return -ENOMEM;
201 }
202
203 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
204 kfree(ops);
205
206 if (len < 0) {
207 kfree(res);
208 return -EAGAIN;
209 }
210
211 put_user(len, kcmd.reslen);
212 if (len > reslen)
213 ret = -ENOBUFS;
214 else if (copy_to_user(kcmd.resbuf, res, len))
215 ret = -EFAULT;
216
217 kfree(res);
218
219 return ret;
220};
221
222static int i2o_cfg_swdl(unsigned long arg)
223{
224 struct i2o_sw_xfer kxfer;
225 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
226 unsigned char maxfrag = 0, curfrag = 1;
227 struct i2o_dma buffer;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800228 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 unsigned int status = 0, swlen = 0, fragsize = 8192;
230 struct i2o_controller *c;
231
232 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
233 return -EFAULT;
234
235 if (get_user(swlen, kxfer.swlen) < 0)
236 return -EFAULT;
237
238 if (get_user(maxfrag, kxfer.maxfrag) < 0)
239 return -EFAULT;
240
241 if (get_user(curfrag, kxfer.curfrag) < 0)
242 return -EFAULT;
243
244 if (curfrag == maxfrag)
245 fragsize = swlen - (maxfrag - 1) * 8192;
246
247 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
248 return -EFAULT;
249
250 c = i2o_find_iop(kxfer.iop);
251 if (!c)
252 return -ENXIO;
253
Markus Lidela1a5ea72006-01-06 00:19:29 -0800254 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
255 if (IS_ERR(msg))
256 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Alan Cox9d793b02008-10-15 22:02:47 -0700258 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
Markus Lidela1a5ea72006-01-06 00:19:29 -0800259 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return -ENOMEM;
261 }
262
Randy Dunlap9d69b7d2006-12-06 20:38:23 -0800263 if (__copy_from_user(buffer.virt, kxfer.buf, fragsize)) {
264 i2o_msg_nop(c, msg);
265 i2o_dma_free(&c->pdev->dev, &buffer);
266 return -EFAULT;
267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Markus Lidela1a5ea72006-01-06 00:19:29 -0800269 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
270 msg->u.head[1] =
271 cpu_to_le32(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 |
272 ADAPTER_TID);
273 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
274 msg->u.head[3] = cpu_to_le32(0);
275 msg->body[0] =
276 cpu_to_le32((((u32) kxfer.flags) << 24) | (((u32) kxfer.
277 sw_type) << 16) |
278 (((u32) maxfrag) << 8) | (((u32) curfrag)));
279 msg->body[1] = cpu_to_le32(swlen);
280 msg->body[2] = cpu_to_le32(kxfer.sw_id);
281 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
282 msg->body[4] = cpu_to_le32(buffer.phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
Markus Lidela1a5ea72006-01-06 00:19:29 -0800285 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 if (status != -ETIMEDOUT)
288 i2o_dma_free(&c->pdev->dev, &buffer);
289
290 if (status != I2O_POST_WAIT_OK) {
291 // it fails if you try and send frags out of order
292 // and for some yet unknown reasons too
293 osm_info("swdl failed, DetailedStatus = %d\n", status);
294 return status;
295 }
296
297 return 0;
298};
299
300static int i2o_cfg_swul(unsigned long arg)
301{
302 struct i2o_sw_xfer kxfer;
303 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
304 unsigned char maxfrag = 0, curfrag = 1;
305 struct i2o_dma buffer;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800306 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 unsigned int status = 0, swlen = 0, fragsize = 8192;
308 struct i2o_controller *c;
309 int ret = 0;
310
311 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200312 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 if (get_user(swlen, kxfer.swlen) < 0)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200315 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 if (get_user(maxfrag, kxfer.maxfrag) < 0)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200318 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 if (get_user(curfrag, kxfer.curfrag) < 0)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200321 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 if (curfrag == maxfrag)
324 fragsize = swlen - (maxfrag - 1) * 8192;
325
326 if (!kxfer.buf)
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200327 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 c = i2o_find_iop(kxfer.iop);
330 if (!c)
331 return -ENXIO;
332
Markus Lidela1a5ea72006-01-06 00:19:29 -0800333 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
334 if (IS_ERR(msg))
335 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Alan Cox9d793b02008-10-15 22:02:47 -0700337 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
Markus Lidela1a5ea72006-01-06 00:19:29 -0800338 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 return -ENOMEM;
340 }
341
Markus Lidela1a5ea72006-01-06 00:19:29 -0800342 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
343 msg->u.head[1] =
344 cpu_to_le32(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID);
345 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
346 msg->u.head[3] = cpu_to_le32(0);
347 msg->body[0] =
348 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.
349 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag);
350 msg->body[1] = cpu_to_le32(swlen);
351 msg->body[2] = cpu_to_le32(kxfer.sw_id);
352 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
353 msg->body[4] = cpu_to_le32(buffer.phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
Markus Lidela1a5ea72006-01-06 00:19:29 -0800356 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 if (status != I2O_POST_WAIT_OK) {
359 if (status != -ETIMEDOUT)
360 i2o_dma_free(&c->pdev->dev, &buffer);
361
362 osm_info("swul failed, DetailedStatus = %d\n", status);
363 return status;
364 }
365
366 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
367 ret = -EFAULT;
368
369 i2o_dma_free(&c->pdev->dev, &buffer);
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return ret;
Dan Carpenterb1ffdc82010-04-23 22:19:13 +0200372}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374static int i2o_cfg_swdel(unsigned long arg)
375{
376 struct i2o_controller *c;
377 struct i2o_sw_xfer kxfer;
378 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800379 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 unsigned int swlen;
381 int token;
382
383 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
384 return -EFAULT;
385
386 if (get_user(swlen, kxfer.swlen) < 0)
387 return -EFAULT;
388
389 c = i2o_find_iop(kxfer.iop);
390 if (!c)
391 return -ENXIO;
392
Markus Lidela1a5ea72006-01-06 00:19:29 -0800393 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
394 if (IS_ERR(msg))
395 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Markus Lidela1a5ea72006-01-06 00:19:29 -0800397 msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
398 msg->u.head[1] =
399 cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
400 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
401 msg->u.head[3] = cpu_to_le32(0);
402 msg->body[0] =
403 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
404 msg->body[1] = cpu_to_le32(swlen);
405 msg->body[2] = cpu_to_le32(kxfer.sw_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Markus Lidela1a5ea72006-01-06 00:19:29 -0800407 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (token != I2O_POST_WAIT_OK) {
410 osm_info("swdel failed, DetailedStatus = %d\n", token);
411 return -ETIMEDOUT;
412 }
413
414 return 0;
415};
416
417static int i2o_cfg_validate(unsigned long arg)
418{
419 int token;
420 int iop = (int)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800421 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 struct i2o_controller *c;
423
424 c = i2o_find_iop(iop);
425 if (!c)
426 return -ENXIO;
427
Markus Lidela1a5ea72006-01-06 00:19:29 -0800428 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
429 if (IS_ERR(msg))
430 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Markus Lidela1a5ea72006-01-06 00:19:29 -0800432 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
433 msg->u.head[1] =
434 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
435 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
436 msg->u.head[3] = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Markus Lidela1a5ea72006-01-06 00:19:29 -0800438 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 if (token != I2O_POST_WAIT_OK) {
441 osm_info("Can't validate configuration, ErrorStatus = %d\n",
442 token);
443 return -ETIMEDOUT;
444 }
445
446 return 0;
447};
448
449static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
450{
Markus Lidela1a5ea72006-01-06 00:19:29 -0800451 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
453 struct i2o_evt_id kdesc;
454 struct i2o_controller *c;
455 struct i2o_device *d;
456
457 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
458 return -EFAULT;
459
460 /* IOP exists? */
461 c = i2o_find_iop(kdesc.iop);
462 if (!c)
463 return -ENXIO;
464
465 /* Device exists? */
466 d = i2o_iop_find_device(c, kdesc.tid);
467 if (!d)
468 return -ENODEV;
469
Markus Lidela1a5ea72006-01-06 00:19:29 -0800470 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
471 if (IS_ERR(msg))
472 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Markus Lidela1a5ea72006-01-06 00:19:29 -0800474 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
475 msg->u.head[1] =
476 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
477 kdesc.tid);
478 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
479 msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
480 msg->body[0] = cpu_to_le32(kdesc.evt_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Markus Lidela1a5ea72006-01-06 00:19:29 -0800482 i2o_msg_post(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 return 0;
485}
486
487static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
488{
489 struct i2o_cfg_info *p = NULL;
490 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
491 struct i2o_evt_get kget;
492 unsigned long flags;
493
494 for (p = open_files; p; p = p->next)
495 if (p->q_id == (ulong) fp->private_data)
496 break;
497
498 if (!p->q_len)
499 return -ENOENT;
500
501 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
502 MODINC(p->q_out, I2O_EVT_Q_LEN);
503 spin_lock_irqsave(&i2o_config_lock, flags);
504 p->q_len--;
505 kget.pending = p->q_len;
506 kget.lost = p->q_lost;
507 spin_unlock_irqrestore(&i2o_config_lock, flags);
508
509 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
510 return -EFAULT;
511 return 0;
512}
513
514#ifdef CONFIG_COMPAT
Markus Lidelf33213e2005-06-23 22:02:23 -0700515static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
516 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
518 struct i2o_cmd_passthru32 __user *cmd;
519 struct i2o_controller *c;
520 u32 __user *user_msg;
521 u32 *reply = NULL;
522 u32 __user *user_reply = NULL;
523 u32 size = 0;
524 u32 reply_size = 0;
525 u32 rcode = 0;
526 struct i2o_dma sg_list[SG_TABLESIZE];
527 u32 sg_offset = 0;
528 u32 sg_count = 0;
529 u32 i = 0;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700530 u32 sg_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 i2o_status_block *sb;
532 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 unsigned int iop;
534
535 cmd = (struct i2o_cmd_passthru32 __user *)arg;
536
537 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
538 return -EFAULT;
539
540 user_msg = compat_ptr(i);
541
542 c = i2o_find_iop(iop);
543 if (!c) {
544 osm_debug("controller %d not found\n", iop);
545 return -ENXIO;
546 }
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 sb = c->status_block.virt;
549
550 if (get_user(size, &user_msg[0])) {
551 osm_warn("unable to get size!\n");
552 return -EFAULT;
553 }
554 size = size >> 16;
555
556 if (size > sb->inbound_frame_size) {
557 osm_warn("size of message > inbound_frame_size");
558 return -EFAULT;
559 }
560
561 user_reply = &user_msg[size];
562
563 size <<= 2; // Convert to bytes
564
Vasily Averin1725d712007-07-17 04:04:24 -0700565 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
566 if (IS_ERR(msg))
567 return PTR_ERR(msg);
568
569 rcode = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* Copy in the user's I2O command */
571 if (copy_from_user(msg, user_msg, size)) {
572 osm_warn("unable to copy user message\n");
Vasily Averin1725d712007-07-17 04:04:24 -0700573 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575 i2o_dump_message(msg);
576
577 if (get_user(reply_size, &user_reply[0]) < 0)
Vasily Averin1725d712007-07-17 04:04:24 -0700578 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 reply_size >>= 16;
581 reply_size <<= 2;
582
Vasily Averin1725d712007-07-17 04:04:24 -0700583 rcode = -ENOMEM;
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800584 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 if (!reply) {
586 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
587 c->name);
Vasily Averin1725d712007-07-17 04:04:24 -0700588 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
594 if (sg_offset) {
595 struct sg_simple_element *sg;
596
597 if (sg_offset * 4 >= size) {
598 rcode = -EFAULT;
599 goto cleanup;
600 }
601 // TODO 64bit fix
602 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
603 sg_offset);
604 sg_count =
605 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
606 if (sg_count > SG_TABLESIZE) {
607 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
608 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700609 rcode = -EINVAL;
610 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612
613 for (i = 0; i < sg_count; i++) {
614 int sg_size;
615 struct i2o_dma *p;
616
617 if (!(sg[i].flag_count & 0x10000000
618 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
619 printk(KERN_DEBUG
620 "%s:Bad SG element %d - not simple (%x)\n",
621 c->name, i, sg[i].flag_count);
622 rcode = -EINVAL;
623 goto cleanup;
624 }
625 sg_size = sg[i].flag_count & 0xffffff;
Markus Lideldcceafe2006-01-06 00:19:32 -0800626 p = &(sg_list[sg_index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 /* Allocate memory for the transfer */
Alan Cox9d793b02008-10-15 22:02:47 -0700628 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 printk(KERN_DEBUG
630 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
631 c->name, sg_size, i, sg_count);
632 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700633 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
Markus Lideldcceafe2006-01-06 00:19:32 -0800635 sg_index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 /* Copy in the user's SG buffer if necessary */
637 if (sg[i].
638 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
639 // TODO 64bit fix
640 if (copy_from_user
Markus Lidelf33213e2005-06-23 22:02:23 -0700641 (p->virt,
642 (void __user *)(unsigned long)sg[i].
643 addr_bus, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 printk(KERN_DEBUG
645 "%s: Could not copy SG buf %d FROM user\n",
646 c->name, i);
647 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700648 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 }
651 //TODO 64bit fix
652 sg[i].addr_bus = (u32) p->phys;
653 }
654 }
655
Markus Lidela1a5ea72006-01-06 00:19:29 -0800656 rcode = i2o_msg_post_wait(c, msg, 60);
Vasily Averin1725d712007-07-17 04:04:24 -0700657 msg = NULL;
Markus Lideldcceafe2006-01-06 00:19:32 -0800658 if (rcode) {
659 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700660 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 if (sg_offset) {
Vasily Averin1725d712007-07-17 04:04:24 -0700664 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 /* Copy back the Scatter Gather buffers back to user space */
666 u32 j;
667 // TODO 64bit fix
668 struct sg_simple_element *sg;
669 int sg_size;
670
671 // re-acquire the original message to handle correctly the sg copy operation
Vasily Averin1725d712007-07-17 04:04:24 -0700672 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 // get user msg size in u32s
674 if (get_user(size, &user_msg[0])) {
675 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700676 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
678 size = size >> 16;
679 size *= 4;
680 /* Copy in the user's I2O command */
Vasily Averin1725d712007-07-17 04:04:24 -0700681 if (copy_from_user(rmsg, user_msg, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700683 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685 sg_count =
686 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
687
688 // TODO 64bit fix
Vasily Averin1725d712007-07-17 04:04:24 -0700689 sg = (struct sg_simple_element *)(rmsg + sg_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 for (j = 0; j < sg_count; j++) {
691 /* Copy out the SG list to user's buffer if necessary */
692 if (!
693 (sg[j].
694 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
695 sg_size = sg[j].flag_count & 0xffffff;
696 // TODO 64bit fix
697 if (copy_to_user
698 ((void __user *)(u64) sg[j].addr_bus,
699 sg_list[j].virt, sg_size)) {
700 printk(KERN_WARNING
701 "%s: Could not copy %p TO user %x\n",
702 c->name, sg_list[j].virt,
703 sg[j].addr_bus);
704 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700705 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
707 }
708 }
709 }
710
Vasily Averin1725d712007-07-17 04:04:24 -0700711sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* Copy back the reply to user space */
713 if (reply_size) {
714 // we wrote our own values for context - now restore the user supplied ones
715 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
716 printk(KERN_WARNING
717 "%s: Could not copy message context FROM user\n",
718 c->name);
719 rcode = -EFAULT;
720 }
721 if (copy_to_user(user_reply, reply, reply_size)) {
722 printk(KERN_WARNING
723 "%s: Could not copy reply TO user\n", c->name);
724 rcode = -EFAULT;
725 }
726 }
Markus Lidel61fbfa82005-06-23 22:02:11 -0700727 for (i = 0; i < sg_index; i++)
728 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
729
Vasily Averin1725d712007-07-17 04:04:24 -0700730cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 kfree(reply);
Vasily Averin1725d712007-07-17 04:04:24 -0700732out:
733 if (msg)
734 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return rcode;
736}
737
Markus Lidelf33213e2005-06-23 22:02:23 -0700738static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
739 unsigned long arg)
f4c2c152005-04-10 22:29:42 -0500740{
741 int ret;
Markus Lidelf33213e2005-06-23 22:02:23 -0700742 lock_kernel();
743 switch (cmd) {
f4c2c152005-04-10 22:29:42 -0500744 case I2OGETIOPS:
Alan Cox5d9d6e42010-01-04 16:18:27 +0000745 ret = i2o_cfg_ioctl(file, cmd, arg);
f4c2c152005-04-10 22:29:42 -0500746 break;
747 case I2OPASSTHRU32:
748 ret = i2o_cfg_passthru32(file, cmd, arg);
749 break;
750 default:
751 ret = -ENOIOCTLCMD;
752 break;
753 }
754 unlock_kernel();
755 return ret;
756}
757
758#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Randy Dunlapf13a6032006-12-06 20:38:24 -0800760#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761static int i2o_cfg_passthru(unsigned long arg)
762{
763 struct i2o_cmd_passthru __user *cmd =
764 (struct i2o_cmd_passthru __user *)arg;
765 struct i2o_controller *c;
766 u32 __user *user_msg;
767 u32 *reply = NULL;
768 u32 __user *user_reply = NULL;
769 u32 size = 0;
770 u32 reply_size = 0;
771 u32 rcode = 0;
Alan Cox9d793b02008-10-15 22:02:47 -0700772 struct i2o_dma sg_list[SG_TABLESIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 u32 sg_offset = 0;
774 u32 sg_count = 0;
775 int sg_index = 0;
776 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 i2o_status_block *sb;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800778 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 unsigned int iop;
780
781 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
782 return -EFAULT;
783
784 c = i2o_find_iop(iop);
785 if (!c) {
786 osm_warn("controller %d not found\n", iop);
787 return -ENXIO;
788 }
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 sb = c->status_block.virt;
791
792 if (get_user(size, &user_msg[0]))
793 return -EFAULT;
794 size = size >> 16;
795
796 if (size > sb->inbound_frame_size) {
797 osm_warn("size of message > inbound_frame_size");
798 return -EFAULT;
799 }
800
801 user_reply = &user_msg[size];
802
803 size <<= 2; // Convert to bytes
804
Vasily Averin1725d712007-07-17 04:04:24 -0700805 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
806 if (IS_ERR(msg))
807 return PTR_ERR(msg);
808
809 rcode = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 /* Copy in the user's I2O command */
811 if (copy_from_user(msg, user_msg, size))
Vasily Averin1725d712007-07-17 04:04:24 -0700812 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 if (get_user(reply_size, &user_reply[0]) < 0)
Vasily Averin1725d712007-07-17 04:04:24 -0700815 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 reply_size >>= 16;
818 reply_size <<= 2;
819
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800820 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (!reply) {
822 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
823 c->name);
Vasily Averin1725d712007-07-17 04:04:24 -0700824 rcode = -ENOMEM;
825 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
831 if (sg_offset) {
832 struct sg_simple_element *sg;
Alan Cox9d793b02008-10-15 22:02:47 -0700833 struct i2o_dma *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 if (sg_offset * 4 >= size) {
836 rcode = -EFAULT;
837 goto cleanup;
838 }
839 // TODO 64bit fix
840 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
841 sg_offset);
842 sg_count =
843 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
844 if (sg_count > SG_TABLESIZE) {
845 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
846 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700847 rcode = -EINVAL;
848 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
851 for (i = 0; i < sg_count; i++) {
852 int sg_size;
853
854 if (!(sg[i].flag_count & 0x10000000
855 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
856 printk(KERN_DEBUG
857 "%s:Bad SG element %d - not simple (%x)\n",
858 c->name, i, sg[i].flag_count);
859 rcode = -EINVAL;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700860 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862 sg_size = sg[i].flag_count & 0xffffff;
Alan Cox9d793b02008-10-15 22:02:47 -0700863 p = &(sg_list[sg_index]);
864 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 /* Allocate memory for the transfer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 printk(KERN_DEBUG
867 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
868 c->name, sg_size, i, sg_count);
869 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700870 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
Alan Cox9d793b02008-10-15 22:02:47 -0700872 sg_index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /* Copy in the user's SG buffer if necessary */
874 if (sg[i].
875 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
876 // TODO 64bit fix
877 if (copy_from_user
Alan Cox9d793b02008-10-15 22:02:47 -0700878 (p->virt, (void __user *)sg[i].addr_bus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 sg_size)) {
880 printk(KERN_DEBUG
881 "%s: Could not copy SG buf %d FROM user\n",
882 c->name, i);
883 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700884 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886 }
Alan Cox9d793b02008-10-15 22:02:47 -0700887 sg[i].addr_bus = p->phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 }
889 }
890
Markus Lidela1a5ea72006-01-06 00:19:29 -0800891 rcode = i2o_msg_post_wait(c, msg, 60);
Vasily Averin1725d712007-07-17 04:04:24 -0700892 msg = NULL;
Markus Lideldcceafe2006-01-06 00:19:32 -0800893 if (rcode) {
894 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700895 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800896 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898 if (sg_offset) {
Alan Cox9d793b02008-10-15 22:02:47 -0700899 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 /* Copy back the Scatter Gather buffers back to user space */
901 u32 j;
902 // TODO 64bit fix
903 struct sg_simple_element *sg;
904 int sg_size;
905
906 // re-acquire the original message to handle correctly the sg copy operation
Vasily Averin1725d712007-07-17 04:04:24 -0700907 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 // get user msg size in u32s
909 if (get_user(size, &user_msg[0])) {
910 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700911 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
913 size = size >> 16;
914 size *= 4;
915 /* Copy in the user's I2O command */
Vasily Averin1725d712007-07-17 04:04:24 -0700916 if (copy_from_user(rmsg, user_msg, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700918 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920 sg_count =
921 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
922
923 // TODO 64bit fix
Vasily Averin1725d712007-07-17 04:04:24 -0700924 sg = (struct sg_simple_element *)(rmsg + sg_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 for (j = 0; j < sg_count; j++) {
926 /* Copy out the SG list to user's buffer if necessary */
927 if (!
928 (sg[j].
929 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
930 sg_size = sg[j].flag_count & 0xffffff;
931 // TODO 64bit fix
932 if (copy_to_user
Alan Cox9d793b02008-10-15 22:02:47 -0700933 ((void __user *)sg[j].addr_bus, sg_list[j].virt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 sg_size)) {
935 printk(KERN_WARNING
936 "%s: Could not copy %p TO user %x\n",
Alan Cox9d793b02008-10-15 22:02:47 -0700937 c->name, sg_list[j].virt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 sg[j].addr_bus);
939 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700940 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
942 }
943 }
944 }
945
Vasily Averin1725d712007-07-17 04:04:24 -0700946sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 /* Copy back the reply to user space */
948 if (reply_size) {
949 // we wrote our own values for context - now restore the user supplied ones
950 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
951 printk(KERN_WARNING
952 "%s: Could not copy message context FROM user\n",
953 c->name);
954 rcode = -EFAULT;
955 }
956 if (copy_to_user(user_reply, reply, reply_size)) {
957 printk(KERN_WARNING
958 "%s: Could not copy reply TO user\n", c->name);
959 rcode = -EFAULT;
960 }
961 }
962
Markus Lidel61fbfa82005-06-23 22:02:11 -0700963 for (i = 0; i < sg_index; i++)
Alan Cox9d793b02008-10-15 22:02:47 -0700964 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700965
Vasily Averin1725d712007-07-17 04:04:24 -0700966cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 kfree(reply);
Vasily Averin1725d712007-07-17 04:04:24 -0700968out:
969 if (msg)
970 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 return rcode;
972}
Markus Lidelb2aaee32005-06-23 22:02:19 -0700973#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975/*
976 * IOCTL Handler
977 */
Alan Cox5d9d6e42010-01-04 16:18:27 +0000978static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
980 int ret;
981
Alan Cox5d9d6e42010-01-04 16:18:27 +0000982 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 switch (cmd) {
984 case I2OGETIOPS:
985 ret = i2o_cfg_getiops(arg);
986 break;
987
988 case I2OHRTGET:
989 ret = i2o_cfg_gethrt(arg);
990 break;
991
992 case I2OLCTGET:
993 ret = i2o_cfg_getlct(arg);
994 break;
995
996 case I2OPARMSET:
997 ret = i2o_cfg_parms(arg, I2OPARMSET);
998 break;
999
1000 case I2OPARMGET:
1001 ret = i2o_cfg_parms(arg, I2OPARMGET);
1002 break;
1003
1004 case I2OSWDL:
1005 ret = i2o_cfg_swdl(arg);
1006 break;
1007
1008 case I2OSWUL:
1009 ret = i2o_cfg_swul(arg);
1010 break;
1011
1012 case I2OSWDEL:
1013 ret = i2o_cfg_swdel(arg);
1014 break;
1015
1016 case I2OVALIDATE:
1017 ret = i2o_cfg_validate(arg);
1018 break;
1019
1020 case I2OEVTREG:
1021 ret = i2o_cfg_evt_reg(arg, fp);
1022 break;
1023
1024 case I2OEVTGET:
1025 ret = i2o_cfg_evt_get(arg, fp);
1026 break;
1027
Markus Lidelb2aaee32005-06-23 22:02:19 -07001028#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 case I2OPASSTHRU:
1030 ret = i2o_cfg_passthru(arg);
1031 break;
Markus Lidelb2aaee32005-06-23 22:02:19 -07001032#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 default:
1035 osm_debug("unknown ioctl called!\n");
1036 ret = -EINVAL;
1037 }
Alan Cox5d9d6e42010-01-04 16:18:27 +00001038 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 return ret;
1040}
1041
1042static int cfg_open(struct inode *inode, struct file *file)
1043{
1044 struct i2o_cfg_info *tmp =
1045 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1046 GFP_KERNEL);
1047 unsigned long flags;
1048
1049 if (!tmp)
1050 return -ENOMEM;
1051
Arnd Bergmannb78032a2008-05-20 19:16:14 +02001052 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 file->private_data = (void *)(i2o_cfg_info_id++);
1054 tmp->fp = file;
1055 tmp->fasync = NULL;
1056 tmp->q_id = (ulong) file->private_data;
1057 tmp->q_len = 0;
1058 tmp->q_in = 0;
1059 tmp->q_out = 0;
1060 tmp->q_lost = 0;
1061 tmp->next = open_files;
1062
1063 spin_lock_irqsave(&i2o_config_lock, flags);
1064 open_files = tmp;
1065 spin_unlock_irqrestore(&i2o_config_lock, flags);
Arnd Bergmannb78032a2008-05-20 19:16:14 +02001066 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 return 0;
1069}
1070
1071static int cfg_fasync(int fd, struct file *fp, int on)
1072{
1073 ulong id = (ulong) fp->private_data;
1074 struct i2o_cfg_info *p;
Jonathan Corbet743115e2008-06-19 15:44:57 -06001075 int ret = -EBADF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Jonathan Corbet743115e2008-06-19 15:44:57 -06001077 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 for (p = open_files; p; p = p->next)
1079 if (p->q_id == id)
1080 break;
1081
Jonathan Corbet743115e2008-06-19 15:44:57 -06001082 if (p)
1083 ret = fasync_helper(fd, fp, on, &p->fasync);
1084 unlock_kernel();
1085 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
1088static int cfg_release(struct inode *inode, struct file *file)
1089{
1090 ulong id = (ulong) file->private_data;
Al Viro233e70f2008-10-31 23:28:30 +00001091 struct i2o_cfg_info *p, **q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 unsigned long flags;
1093
1094 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 spin_lock_irqsave(&i2o_config_lock, flags);
Al Viro233e70f2008-10-31 23:28:30 +00001096 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1097 if (p->q_id == id) {
1098 *q = p->next;
1099 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 break;
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 }
1103 spin_unlock_irqrestore(&i2o_config_lock, flags);
1104 unlock_kernel();
1105
1106 return 0;
1107}
1108
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001109static const struct file_operations config_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .owner = THIS_MODULE,
1111 .llseek = no_llseek,
Alan Cox5d9d6e42010-01-04 16:18:27 +00001112 .unlocked_ioctl = i2o_cfg_ioctl,
f4c2c152005-04-10 22:29:42 -05001113#ifdef CONFIG_COMPAT
1114 .compat_ioctl = i2o_cfg_compat_ioctl,
1115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 .open = cfg_open,
1117 .release = cfg_release,
1118 .fasync = cfg_fasync,
1119};
1120
1121static struct miscdevice i2o_miscdev = {
1122 I2O_MINOR,
1123 "i2octl",
1124 &config_fops
1125};
1126
Markus Lidelf10378f2005-06-23 22:02:16 -07001127static int __init i2o_config_old_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 spin_lock_init(&i2o_config_lock);
1130
1131 if (misc_register(&i2o_miscdev) < 0) {
1132 osm_err("can't register device.\n");
1133 return -EBUSY;
1134 }
Markus Lidelf33213e2005-06-23 22:02:23 -07001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return 0;
1137}
1138
Markus Lidelf10378f2005-06-23 22:02:16 -07001139static void i2o_config_old_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 misc_deregister(&i2o_miscdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
1144MODULE_AUTHOR("Red Hat Software");