blob: 3d5f40cd69df2e70d5d1ffee42b91e31d36473e4 [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>
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
Alan Cox5d9d6e42010-01-04 16:18:27 +000043static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long);
f4c2c152005-04-10 22:29:42 -050044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static spinlock_t i2o_config_lock;
46
47#define MODINC(x,y) ((x) = ((x) + 1) % (y))
48
49struct sg_simple_element {
50 u32 flag_count;
51 u32 addr_bus;
52};
53
54struct i2o_cfg_info {
55 struct file *fp;
56 struct fasync_struct *fasync;
57 struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
58 u16 q_in; // Queue head index
59 u16 q_out; // Queue tail index
60 u16 q_len; // Queue length
61 u16 q_lost; // Number of lost events
62 ulong q_id; // Event queue ID...used as tx_context
63 struct i2o_cfg_info *next;
64};
65static struct i2o_cfg_info *open_files = NULL;
66static ulong i2o_cfg_info_id = 0;
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int i2o_cfg_getiops(unsigned long arg)
69{
70 struct i2o_controller *c;
71 u8 __user *user_iop_table = (void __user *)arg;
72 u8 tmp[MAX_I2O_CONTROLLERS];
73 int ret = 0;
74
75 memset(tmp, 0, MAX_I2O_CONTROLLERS);
76
77 list_for_each_entry(c, &i2o_controllers, list)
78 tmp[c->unit] = 1;
79
80 if (copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS))
81 ret = -EFAULT;
82
83 return ret;
84};
85
86static int i2o_cfg_gethrt(unsigned long arg)
87{
88 struct i2o_controller *c;
89 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
90 struct i2o_cmd_hrtlct kcmd;
91 i2o_hrt *hrt;
92 int len;
93 u32 reslen;
94 int ret = 0;
95
96 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
97 return -EFAULT;
98
99 if (get_user(reslen, kcmd.reslen) < 0)
100 return -EFAULT;
101
102 if (kcmd.resbuf == NULL)
103 return -EFAULT;
104
105 c = i2o_find_iop(kcmd.iop);
106 if (!c)
107 return -ENXIO;
108
109 hrt = (i2o_hrt *) c->hrt.virt;
110
111 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
112
113 /* We did a get user...so assuming mem is ok...is this bad? */
114 put_user(len, kcmd.reslen);
115 if (len > reslen)
116 ret = -ENOBUFS;
117 if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
118 ret = -EFAULT;
119
120 return ret;
121};
122
123static int i2o_cfg_getlct(unsigned long arg)
124{
125 struct i2o_controller *c;
126 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
127 struct i2o_cmd_hrtlct kcmd;
128 i2o_lct *lct;
129 int len;
130 int ret = 0;
131 u32 reslen;
132
133 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
134 return -EFAULT;
135
136 if (get_user(reslen, kcmd.reslen) < 0)
137 return -EFAULT;
138
139 if (kcmd.resbuf == NULL)
140 return -EFAULT;
141
142 c = i2o_find_iop(kcmd.iop);
143 if (!c)
144 return -ENXIO;
145
146 lct = (i2o_lct *) c->lct;
147
148 len = (unsigned int)lct->table_size << 2;
149 put_user(len, kcmd.reslen);
150 if (len > reslen)
151 ret = -ENOBUFS;
152 else if (copy_to_user(kcmd.resbuf, lct, len))
153 ret = -EFAULT;
154
155 return ret;
156};
157
158static int i2o_cfg_parms(unsigned long arg, unsigned int type)
159{
160 int ret = 0;
161 struct i2o_controller *c;
162 struct i2o_device *dev;
163 struct i2o_cmd_psetget __user *cmd =
164 (struct i2o_cmd_psetget __user *)arg;
165 struct i2o_cmd_psetget kcmd;
166 u32 reslen;
167 u8 *ops;
168 u8 *res;
169 int len = 0;
170
171 u32 i2o_cmd = (type == I2OPARMGET ?
172 I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);
173
174 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
175 return -EFAULT;
176
177 if (get_user(reslen, kcmd.reslen))
178 return -EFAULT;
179
180 c = i2o_find_iop(kcmd.iop);
181 if (!c)
182 return -ENXIO;
183
184 dev = i2o_iop_find_device(c, kcmd.tid);
185 if (!dev)
186 return -ENXIO;
187
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800188 ops = kmalloc(kcmd.oplen, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (!ops)
190 return -ENOMEM;
191
192 if (copy_from_user(ops, kcmd.opbuf, kcmd.oplen)) {
193 kfree(ops);
194 return -EFAULT;
195 }
196
197 /*
198 * It's possible to have a _very_ large table
199 * and that the user asks for all of it at once...
200 */
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800201 res = kmalloc(65536, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (!res) {
203 kfree(ops);
204 return -ENOMEM;
205 }
206
207 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
208 kfree(ops);
209
210 if (len < 0) {
211 kfree(res);
212 return -EAGAIN;
213 }
214
215 put_user(len, kcmd.reslen);
216 if (len > reslen)
217 ret = -ENOBUFS;
218 else if (copy_to_user(kcmd.resbuf, res, len))
219 ret = -EFAULT;
220
221 kfree(res);
222
223 return ret;
224};
225
226static int i2o_cfg_swdl(unsigned long arg)
227{
228 struct i2o_sw_xfer kxfer;
229 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
230 unsigned char maxfrag = 0, curfrag = 1;
231 struct i2o_dma buffer;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800232 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 unsigned int status = 0, swlen = 0, fragsize = 8192;
234 struct i2o_controller *c;
235
236 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
237 return -EFAULT;
238
239 if (get_user(swlen, kxfer.swlen) < 0)
240 return -EFAULT;
241
242 if (get_user(maxfrag, kxfer.maxfrag) < 0)
243 return -EFAULT;
244
245 if (get_user(curfrag, kxfer.curfrag) < 0)
246 return -EFAULT;
247
248 if (curfrag == maxfrag)
249 fragsize = swlen - (maxfrag - 1) * 8192;
250
251 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
252 return -EFAULT;
253
254 c = i2o_find_iop(kxfer.iop);
255 if (!c)
256 return -ENXIO;
257
Markus Lidela1a5ea72006-01-06 00:19:29 -0800258 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
259 if (IS_ERR(msg))
260 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Alan Cox9d793b02008-10-15 22:02:47 -0700262 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
Markus Lidela1a5ea72006-01-06 00:19:29 -0800263 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return -ENOMEM;
265 }
266
Randy Dunlap9d69b7d2006-12-06 20:38:23 -0800267 if (__copy_from_user(buffer.virt, kxfer.buf, fragsize)) {
268 i2o_msg_nop(c, msg);
269 i2o_dma_free(&c->pdev->dev, &buffer);
270 return -EFAULT;
271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Markus Lidela1a5ea72006-01-06 00:19:29 -0800273 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
274 msg->u.head[1] =
275 cpu_to_le32(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 |
276 ADAPTER_TID);
277 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
278 msg->u.head[3] = cpu_to_le32(0);
279 msg->body[0] =
280 cpu_to_le32((((u32) kxfer.flags) << 24) | (((u32) kxfer.
281 sw_type) << 16) |
282 (((u32) maxfrag) << 8) | (((u32) curfrag)));
283 msg->body[1] = cpu_to_le32(swlen);
284 msg->body[2] = cpu_to_le32(kxfer.sw_id);
285 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
286 msg->body[4] = cpu_to_le32(buffer.phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
Markus Lidela1a5ea72006-01-06 00:19:29 -0800289 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 if (status != -ETIMEDOUT)
292 i2o_dma_free(&c->pdev->dev, &buffer);
293
294 if (status != I2O_POST_WAIT_OK) {
295 // it fails if you try and send frags out of order
296 // and for some yet unknown reasons too
297 osm_info("swdl failed, DetailedStatus = %d\n", status);
298 return status;
299 }
300
301 return 0;
302};
303
304static int i2o_cfg_swul(unsigned long arg)
305{
306 struct i2o_sw_xfer kxfer;
307 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
308 unsigned char maxfrag = 0, curfrag = 1;
309 struct i2o_dma buffer;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800310 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 unsigned int status = 0, swlen = 0, fragsize = 8192;
312 struct i2o_controller *c;
313 int ret = 0;
314
315 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
316 goto return_fault;
317
318 if (get_user(swlen, kxfer.swlen) < 0)
319 goto return_fault;
320
321 if (get_user(maxfrag, kxfer.maxfrag) < 0)
322 goto return_fault;
323
324 if (get_user(curfrag, kxfer.curfrag) < 0)
325 goto return_fault;
326
327 if (curfrag == maxfrag)
328 fragsize = swlen - (maxfrag - 1) * 8192;
329
330 if (!kxfer.buf)
331 goto return_fault;
332
333 c = i2o_find_iop(kxfer.iop);
334 if (!c)
335 return -ENXIO;
336
Markus Lidela1a5ea72006-01-06 00:19:29 -0800337 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
338 if (IS_ERR(msg))
339 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Alan Cox9d793b02008-10-15 22:02:47 -0700341 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
Markus Lidela1a5ea72006-01-06 00:19:29 -0800342 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return -ENOMEM;
344 }
345
Markus Lidela1a5ea72006-01-06 00:19:29 -0800346 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
347 msg->u.head[1] =
348 cpu_to_le32(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID);
349 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
350 msg->u.head[3] = cpu_to_le32(0);
351 msg->body[0] =
352 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.
353 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag);
354 msg->body[1] = cpu_to_le32(swlen);
355 msg->body[2] = cpu_to_le32(kxfer.sw_id);
356 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
357 msg->body[4] = cpu_to_le32(buffer.phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
Markus Lidela1a5ea72006-01-06 00:19:29 -0800360 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 if (status != I2O_POST_WAIT_OK) {
363 if (status != -ETIMEDOUT)
364 i2o_dma_free(&c->pdev->dev, &buffer);
365
366 osm_info("swul failed, DetailedStatus = %d\n", status);
367 return status;
368 }
369
370 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
371 ret = -EFAULT;
372
373 i2o_dma_free(&c->pdev->dev, &buffer);
374
Markus Lidelf33213e2005-06-23 22:02:23 -0700375 return_ret:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return ret;
Markus Lidelf33213e2005-06-23 22:02:23 -0700377 return_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 ret = -EFAULT;
379 goto return_ret;
380};
381
382static int i2o_cfg_swdel(unsigned long arg)
383{
384 struct i2o_controller *c;
385 struct i2o_sw_xfer kxfer;
386 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800387 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 unsigned int swlen;
389 int token;
390
391 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
392 return -EFAULT;
393
394 if (get_user(swlen, kxfer.swlen) < 0)
395 return -EFAULT;
396
397 c = i2o_find_iop(kxfer.iop);
398 if (!c)
399 return -ENXIO;
400
Markus Lidela1a5ea72006-01-06 00:19:29 -0800401 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
402 if (IS_ERR(msg))
403 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Markus Lidela1a5ea72006-01-06 00:19:29 -0800405 msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
406 msg->u.head[1] =
407 cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
408 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
409 msg->u.head[3] = cpu_to_le32(0);
410 msg->body[0] =
411 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
412 msg->body[1] = cpu_to_le32(swlen);
413 msg->body[2] = cpu_to_le32(kxfer.sw_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Markus Lidela1a5ea72006-01-06 00:19:29 -0800415 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 if (token != I2O_POST_WAIT_OK) {
418 osm_info("swdel failed, DetailedStatus = %d\n", token);
419 return -ETIMEDOUT;
420 }
421
422 return 0;
423};
424
425static int i2o_cfg_validate(unsigned long arg)
426{
427 int token;
428 int iop = (int)arg;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800429 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 struct i2o_controller *c;
431
432 c = i2o_find_iop(iop);
433 if (!c)
434 return -ENXIO;
435
Markus Lidela1a5ea72006-01-06 00:19:29 -0800436 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
437 if (IS_ERR(msg))
438 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Markus Lidela1a5ea72006-01-06 00:19:29 -0800440 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
441 msg->u.head[1] =
442 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
443 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
444 msg->u.head[3] = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Markus Lidela1a5ea72006-01-06 00:19:29 -0800446 token = i2o_msg_post_wait(c, msg, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 if (token != I2O_POST_WAIT_OK) {
449 osm_info("Can't validate configuration, ErrorStatus = %d\n",
450 token);
451 return -ETIMEDOUT;
452 }
453
454 return 0;
455};
456
457static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
458{
Markus Lidela1a5ea72006-01-06 00:19:29 -0800459 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
461 struct i2o_evt_id kdesc;
462 struct i2o_controller *c;
463 struct i2o_device *d;
464
465 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
466 return -EFAULT;
467
468 /* IOP exists? */
469 c = i2o_find_iop(kdesc.iop);
470 if (!c)
471 return -ENXIO;
472
473 /* Device exists? */
474 d = i2o_iop_find_device(c, kdesc.tid);
475 if (!d)
476 return -ENODEV;
477
Markus Lidela1a5ea72006-01-06 00:19:29 -0800478 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
479 if (IS_ERR(msg))
480 return PTR_ERR(msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Markus Lidela1a5ea72006-01-06 00:19:29 -0800482 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
483 msg->u.head[1] =
484 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
485 kdesc.tid);
486 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
487 msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
488 msg->body[0] = cpu_to_le32(kdesc.evt_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Markus Lidela1a5ea72006-01-06 00:19:29 -0800490 i2o_msg_post(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 return 0;
493}
494
495static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
496{
497 struct i2o_cfg_info *p = NULL;
498 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
499 struct i2o_evt_get kget;
500 unsigned long flags;
501
502 for (p = open_files; p; p = p->next)
503 if (p->q_id == (ulong) fp->private_data)
504 break;
505
506 if (!p->q_len)
507 return -ENOENT;
508
509 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
510 MODINC(p->q_out, I2O_EVT_Q_LEN);
511 spin_lock_irqsave(&i2o_config_lock, flags);
512 p->q_len--;
513 kget.pending = p->q_len;
514 kget.lost = p->q_lost;
515 spin_unlock_irqrestore(&i2o_config_lock, flags);
516
517 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
518 return -EFAULT;
519 return 0;
520}
521
522#ifdef CONFIG_COMPAT
Markus Lidelf33213e2005-06-23 22:02:23 -0700523static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
524 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 struct i2o_cmd_passthru32 __user *cmd;
527 struct i2o_controller *c;
528 u32 __user *user_msg;
529 u32 *reply = NULL;
530 u32 __user *user_reply = NULL;
531 u32 size = 0;
532 u32 reply_size = 0;
533 u32 rcode = 0;
534 struct i2o_dma sg_list[SG_TABLESIZE];
535 u32 sg_offset = 0;
536 u32 sg_count = 0;
537 u32 i = 0;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700538 u32 sg_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 i2o_status_block *sb;
540 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 unsigned int iop;
542
543 cmd = (struct i2o_cmd_passthru32 __user *)arg;
544
545 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
546 return -EFAULT;
547
548 user_msg = compat_ptr(i);
549
550 c = i2o_find_iop(iop);
551 if (!c) {
552 osm_debug("controller %d not found\n", iop);
553 return -ENXIO;
554 }
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 sb = c->status_block.virt;
557
558 if (get_user(size, &user_msg[0])) {
559 osm_warn("unable to get size!\n");
560 return -EFAULT;
561 }
562 size = size >> 16;
563
564 if (size > sb->inbound_frame_size) {
565 osm_warn("size of message > inbound_frame_size");
566 return -EFAULT;
567 }
568
569 user_reply = &user_msg[size];
570
571 size <<= 2; // Convert to bytes
572
Vasily Averin1725d712007-07-17 04:04:24 -0700573 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
574 if (IS_ERR(msg))
575 return PTR_ERR(msg);
576
577 rcode = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 /* Copy in the user's I2O command */
579 if (copy_from_user(msg, user_msg, size)) {
580 osm_warn("unable to copy user message\n");
Vasily Averin1725d712007-07-17 04:04:24 -0700581 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583 i2o_dump_message(msg);
584
585 if (get_user(reply_size, &user_reply[0]) < 0)
Vasily Averin1725d712007-07-17 04:04:24 -0700586 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 reply_size >>= 16;
589 reply_size <<= 2;
590
Vasily Averin1725d712007-07-17 04:04:24 -0700591 rcode = -ENOMEM;
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800592 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (!reply) {
594 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
595 c->name);
Vasily Averin1725d712007-07-17 04:04:24 -0700596 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
602 if (sg_offset) {
603 struct sg_simple_element *sg;
604
605 if (sg_offset * 4 >= size) {
606 rcode = -EFAULT;
607 goto cleanup;
608 }
609 // TODO 64bit fix
610 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
611 sg_offset);
612 sg_count =
613 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
614 if (sg_count > SG_TABLESIZE) {
615 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
616 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700617 rcode = -EINVAL;
618 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
621 for (i = 0; i < sg_count; i++) {
622 int sg_size;
623 struct i2o_dma *p;
624
625 if (!(sg[i].flag_count & 0x10000000
626 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
627 printk(KERN_DEBUG
628 "%s:Bad SG element %d - not simple (%x)\n",
629 c->name, i, sg[i].flag_count);
630 rcode = -EINVAL;
631 goto cleanup;
632 }
633 sg_size = sg[i].flag_count & 0xffffff;
Markus Lideldcceafe2006-01-06 00:19:32 -0800634 p = &(sg_list[sg_index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* Allocate memory for the transfer */
Alan Cox9d793b02008-10-15 22:02:47 -0700636 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 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);
Vasily Averin1725d712007-07-17 04:04:24 -0700665 msg = NULL;
Markus Lideldcceafe2006-01-06 00:19:32 -0800666 if (rcode) {
667 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700668 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 if (sg_offset) {
Vasily Averin1725d712007-07-17 04:04:24 -0700672 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 /* Copy back the Scatter Gather buffers back to user space */
674 u32 j;
675 // TODO 64bit fix
676 struct sg_simple_element *sg;
677 int sg_size;
678
679 // re-acquire the original message to handle correctly the sg copy operation
Vasily Averin1725d712007-07-17 04:04:24 -0700680 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 // get user msg size in u32s
682 if (get_user(size, &user_msg[0])) {
683 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700684 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
686 size = size >> 16;
687 size *= 4;
688 /* Copy in the user's I2O command */
Vasily Averin1725d712007-07-17 04:04:24 -0700689 if (copy_from_user(rmsg, user_msg, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700691 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693 sg_count =
694 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
695
696 // TODO 64bit fix
Vasily Averin1725d712007-07-17 04:04:24 -0700697 sg = (struct sg_simple_element *)(rmsg + sg_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 for (j = 0; j < sg_count; j++) {
699 /* Copy out the SG list to user's buffer if necessary */
700 if (!
701 (sg[j].
702 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
703 sg_size = sg[j].flag_count & 0xffffff;
704 // TODO 64bit fix
705 if (copy_to_user
706 ((void __user *)(u64) sg[j].addr_bus,
707 sg_list[j].virt, sg_size)) {
708 printk(KERN_WARNING
709 "%s: Could not copy %p TO user %x\n",
710 c->name, sg_list[j].virt,
711 sg[j].addr_bus);
712 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700713 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715 }
716 }
717 }
718
Vasily Averin1725d712007-07-17 04:04:24 -0700719sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 /* Copy back the reply to user space */
721 if (reply_size) {
722 // we wrote our own values for context - now restore the user supplied ones
723 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
724 printk(KERN_WARNING
725 "%s: Could not copy message context FROM user\n",
726 c->name);
727 rcode = -EFAULT;
728 }
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 }
Markus Lidel61fbfa82005-06-23 22:02:11 -0700735 for (i = 0; i < sg_index; i++)
736 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
737
Vasily Averin1725d712007-07-17 04:04:24 -0700738cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 kfree(reply);
Vasily Averin1725d712007-07-17 04:04:24 -0700740out:
741 if (msg)
742 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 return rcode;
744}
745
Markus Lidelf33213e2005-06-23 22:02:23 -0700746static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
747 unsigned long arg)
f4c2c152005-04-10 22:29:42 -0500748{
749 int ret;
Markus Lidelf33213e2005-06-23 22:02:23 -0700750 lock_kernel();
751 switch (cmd) {
f4c2c152005-04-10 22:29:42 -0500752 case I2OGETIOPS:
Alan Cox5d9d6e42010-01-04 16:18:27 +0000753 ret = i2o_cfg_ioctl(file, cmd, arg);
f4c2c152005-04-10 22:29:42 -0500754 break;
755 case I2OPASSTHRU32:
756 ret = i2o_cfg_passthru32(file, cmd, arg);
757 break;
758 default:
759 ret = -ENOIOCTLCMD;
760 break;
761 }
762 unlock_kernel();
763 return ret;
764}
765
766#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Randy Dunlapf13a6032006-12-06 20:38:24 -0800768#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769static int i2o_cfg_passthru(unsigned long arg)
770{
771 struct i2o_cmd_passthru __user *cmd =
772 (struct i2o_cmd_passthru __user *)arg;
773 struct i2o_controller *c;
774 u32 __user *user_msg;
775 u32 *reply = NULL;
776 u32 __user *user_reply = NULL;
777 u32 size = 0;
778 u32 reply_size = 0;
779 u32 rcode = 0;
Alan Cox9d793b02008-10-15 22:02:47 -0700780 struct i2o_dma sg_list[SG_TABLESIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 u32 sg_offset = 0;
782 u32 sg_count = 0;
783 int sg_index = 0;
784 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 i2o_status_block *sb;
Markus Lidela1a5ea72006-01-06 00:19:29 -0800786 struct i2o_message *msg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 unsigned int iop;
788
789 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
790 return -EFAULT;
791
792 c = i2o_find_iop(iop);
793 if (!c) {
794 osm_warn("controller %d not found\n", iop);
795 return -ENXIO;
796 }
797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 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
Vasily Averin1725d712007-07-17 04:04:24 -0700813 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
814 if (IS_ERR(msg))
815 return PTR_ERR(msg);
816
817 rcode = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 /* Copy in the user's I2O command */
819 if (copy_from_user(msg, user_msg, size))
Vasily Averin1725d712007-07-17 04:04:24 -0700820 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 if (get_user(reply_size, &user_reply[0]) < 0)
Vasily Averin1725d712007-07-17 04:04:24 -0700823 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 reply_size >>= 16;
826 reply_size <<= 2;
827
Markus Lidelf6ed39a2006-01-06 00:19:33 -0800828 reply = kzalloc(reply_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 if (!reply) {
830 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
831 c->name);
Vasily Averin1725d712007-07-17 04:04:24 -0700832 rcode = -ENOMEM;
833 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
839 if (sg_offset) {
840 struct sg_simple_element *sg;
Alan Cox9d793b02008-10-15 22:02:47 -0700841 struct i2o_dma *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 if (sg_offset * 4 >= size) {
844 rcode = -EFAULT;
845 goto cleanup;
846 }
847 // TODO 64bit fix
848 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
849 sg_offset);
850 sg_count =
851 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
852 if (sg_count > SG_TABLESIZE) {
853 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
854 c->name, sg_count);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700855 rcode = -EINVAL;
856 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858
859 for (i = 0; i < sg_count; i++) {
860 int sg_size;
861
862 if (!(sg[i].flag_count & 0x10000000
863 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
864 printk(KERN_DEBUG
865 "%s:Bad SG element %d - not simple (%x)\n",
866 c->name, i, sg[i].flag_count);
867 rcode = -EINVAL;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700868 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870 sg_size = sg[i].flag_count & 0xffffff;
Alan Cox9d793b02008-10-15 22:02:47 -0700871 p = &(sg_list[sg_index]);
872 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /* Allocate memory for the transfer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 printk(KERN_DEBUG
875 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
876 c->name, sg_size, i, sg_count);
877 rcode = -ENOMEM;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700878 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
Alan Cox9d793b02008-10-15 22:02:47 -0700880 sg_index++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 /* Copy in the user's SG buffer if necessary */
882 if (sg[i].
883 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
884 // TODO 64bit fix
885 if (copy_from_user
Alan Cox9d793b02008-10-15 22:02:47 -0700886 (p->virt, (void __user *)sg[i].addr_bus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 sg_size)) {
888 printk(KERN_DEBUG
889 "%s: Could not copy SG buf %d FROM user\n",
890 c->name, i);
891 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700892 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 }
894 }
Alan Cox9d793b02008-10-15 22:02:47 -0700895 sg[i].addr_bus = p->phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
897 }
898
Markus Lidela1a5ea72006-01-06 00:19:29 -0800899 rcode = i2o_msg_post_wait(c, msg, 60);
Vasily Averin1725d712007-07-17 04:04:24 -0700900 msg = NULL;
Markus Lideldcceafe2006-01-06 00:19:32 -0800901 if (rcode) {
902 reply[4] = ((u32) rcode) << 24;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700903 goto sg_list_cleanup;
Markus Lideldcceafe2006-01-06 00:19:32 -0800904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 if (sg_offset) {
Alan Cox9d793b02008-10-15 22:02:47 -0700907 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 /* Copy back the Scatter Gather buffers back to user space */
909 u32 j;
910 // TODO 64bit fix
911 struct sg_simple_element *sg;
912 int sg_size;
913
914 // re-acquire the original message to handle correctly the sg copy operation
Vasily Averin1725d712007-07-17 04:04:24 -0700915 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 // get user msg size in u32s
917 if (get_user(size, &user_msg[0])) {
918 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700919 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921 size = size >> 16;
922 size *= 4;
923 /* Copy in the user's I2O command */
Vasily Averin1725d712007-07-17 04:04:24 -0700924 if (copy_from_user(rmsg, user_msg, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700926 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928 sg_count =
929 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
930
931 // TODO 64bit fix
Vasily Averin1725d712007-07-17 04:04:24 -0700932 sg = (struct sg_simple_element *)(rmsg + sg_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 for (j = 0; j < sg_count; j++) {
934 /* Copy out the SG list to user's buffer if necessary */
935 if (!
936 (sg[j].
937 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
938 sg_size = sg[j].flag_count & 0xffffff;
939 // TODO 64bit fix
940 if (copy_to_user
Alan Cox9d793b02008-10-15 22:02:47 -0700941 ((void __user *)sg[j].addr_bus, sg_list[j].virt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 sg_size)) {
943 printk(KERN_WARNING
944 "%s: Could not copy %p TO user %x\n",
Alan Cox9d793b02008-10-15 22:02:47 -0700945 c->name, sg_list[j].virt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 sg[j].addr_bus);
947 rcode = -EFAULT;
Markus Lidel61fbfa82005-06-23 22:02:11 -0700948 goto sg_list_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950 }
951 }
952 }
953
Vasily Averin1725d712007-07-17 04:04:24 -0700954sg_list_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 /* Copy back the reply to user space */
956 if (reply_size) {
957 // we wrote our own values for context - now restore the user supplied ones
958 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
959 printk(KERN_WARNING
960 "%s: Could not copy message context FROM user\n",
961 c->name);
962 rcode = -EFAULT;
963 }
964 if (copy_to_user(user_reply, reply, reply_size)) {
965 printk(KERN_WARNING
966 "%s: Could not copy reply TO user\n", c->name);
967 rcode = -EFAULT;
968 }
969 }
970
Markus Lidel61fbfa82005-06-23 22:02:11 -0700971 for (i = 0; i < sg_index; i++)
Alan Cox9d793b02008-10-15 22:02:47 -0700972 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
Markus Lidel61fbfa82005-06-23 22:02:11 -0700973
Vasily Averin1725d712007-07-17 04:04:24 -0700974cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 kfree(reply);
Vasily Averin1725d712007-07-17 04:04:24 -0700976out:
977 if (msg)
978 i2o_msg_nop(c, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 return rcode;
980}
Markus Lidelb2aaee32005-06-23 22:02:19 -0700981#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983/*
984 * IOCTL Handler
985 */
Alan Cox5d9d6e42010-01-04 16:18:27 +0000986static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
988 int ret;
989
Alan Cox5d9d6e42010-01-04 16:18:27 +0000990 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 switch (cmd) {
992 case I2OGETIOPS:
993 ret = i2o_cfg_getiops(arg);
994 break;
995
996 case I2OHRTGET:
997 ret = i2o_cfg_gethrt(arg);
998 break;
999
1000 case I2OLCTGET:
1001 ret = i2o_cfg_getlct(arg);
1002 break;
1003
1004 case I2OPARMSET:
1005 ret = i2o_cfg_parms(arg, I2OPARMSET);
1006 break;
1007
1008 case I2OPARMGET:
1009 ret = i2o_cfg_parms(arg, I2OPARMGET);
1010 break;
1011
1012 case I2OSWDL:
1013 ret = i2o_cfg_swdl(arg);
1014 break;
1015
1016 case I2OSWUL:
1017 ret = i2o_cfg_swul(arg);
1018 break;
1019
1020 case I2OSWDEL:
1021 ret = i2o_cfg_swdel(arg);
1022 break;
1023
1024 case I2OVALIDATE:
1025 ret = i2o_cfg_validate(arg);
1026 break;
1027
1028 case I2OEVTREG:
1029 ret = i2o_cfg_evt_reg(arg, fp);
1030 break;
1031
1032 case I2OEVTGET:
1033 ret = i2o_cfg_evt_get(arg, fp);
1034 break;
1035
Markus Lidelb2aaee32005-06-23 22:02:19 -07001036#ifdef CONFIG_I2O_EXT_ADAPTEC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 case I2OPASSTHRU:
1038 ret = i2o_cfg_passthru(arg);
1039 break;
Markus Lidelb2aaee32005-06-23 22:02:19 -07001040#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042 default:
1043 osm_debug("unknown ioctl called!\n");
1044 ret = -EINVAL;
1045 }
Alan Cox5d9d6e42010-01-04 16:18:27 +00001046 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 return ret;
1048}
1049
1050static int cfg_open(struct inode *inode, struct file *file)
1051{
1052 struct i2o_cfg_info *tmp =
1053 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1054 GFP_KERNEL);
1055 unsigned long flags;
1056
1057 if (!tmp)
1058 return -ENOMEM;
1059
Arnd Bergmannb78032a2008-05-20 19:16:14 +02001060 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 file->private_data = (void *)(i2o_cfg_info_id++);
1062 tmp->fp = file;
1063 tmp->fasync = NULL;
1064 tmp->q_id = (ulong) file->private_data;
1065 tmp->q_len = 0;
1066 tmp->q_in = 0;
1067 tmp->q_out = 0;
1068 tmp->q_lost = 0;
1069 tmp->next = open_files;
1070
1071 spin_lock_irqsave(&i2o_config_lock, flags);
1072 open_files = tmp;
1073 spin_unlock_irqrestore(&i2o_config_lock, flags);
Arnd Bergmannb78032a2008-05-20 19:16:14 +02001074 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 return 0;
1077}
1078
1079static int cfg_fasync(int fd, struct file *fp, int on)
1080{
1081 ulong id = (ulong) fp->private_data;
1082 struct i2o_cfg_info *p;
Jonathan Corbet743115e2008-06-19 15:44:57 -06001083 int ret = -EBADF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Jonathan Corbet743115e2008-06-19 15:44:57 -06001085 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 for (p = open_files; p; p = p->next)
1087 if (p->q_id == id)
1088 break;
1089
Jonathan Corbet743115e2008-06-19 15:44:57 -06001090 if (p)
1091 ret = fasync_helper(fd, fp, on, &p->fasync);
1092 unlock_kernel();
1093 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
1096static int cfg_release(struct inode *inode, struct file *file)
1097{
1098 ulong id = (ulong) file->private_data;
Al Viro233e70f2008-10-31 23:28:30 +00001099 struct i2o_cfg_info *p, **q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 unsigned long flags;
1101
1102 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 spin_lock_irqsave(&i2o_config_lock, flags);
Al Viro233e70f2008-10-31 23:28:30 +00001104 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1105 if (p->q_id == id) {
1106 *q = p->next;
1107 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 break;
1109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111 spin_unlock_irqrestore(&i2o_config_lock, flags);
1112 unlock_kernel();
1113
1114 return 0;
1115}
1116
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001117static const struct file_operations config_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 .owner = THIS_MODULE,
1119 .llseek = no_llseek,
Alan Cox5d9d6e42010-01-04 16:18:27 +00001120 .unlocked_ioctl = i2o_cfg_ioctl,
f4c2c152005-04-10 22:29:42 -05001121#ifdef CONFIG_COMPAT
1122 .compat_ioctl = i2o_cfg_compat_ioctl,
1123#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 .open = cfg_open,
1125 .release = cfg_release,
1126 .fasync = cfg_fasync,
1127};
1128
1129static struct miscdevice i2o_miscdev = {
1130 I2O_MINOR,
1131 "i2octl",
1132 &config_fops
1133};
1134
Markus Lidelf10378f2005-06-23 22:02:16 -07001135static int __init i2o_config_old_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 spin_lock_init(&i2o_config_lock);
1138
1139 if (misc_register(&i2o_miscdev) < 0) {
1140 osm_err("can't register device.\n");
1141 return -EBUSY;
1142 }
Markus Lidelf33213e2005-06-23 22:02:23 -07001143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 return 0;
1145}
1146
Markus Lidelf10378f2005-06-23 22:02:16 -07001147static void i2o_config_old_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 misc_deregister(&i2o_miscdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
1152MODULE_AUTHOR("Red Hat Software");