Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 13 | * Auvo Häkkinen (09/10/1999): |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Changes to i2o_cfg_reply(), ioctl_parms() |
| 15 | * Added ioct_validate() |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 16 | * Taneli Vähäkangas (09/30/1999): |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Fixed ioctl_swdl() |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 18 | * Taneli Vähäkangas (10/04/1999): |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel() |
| 20 | * Deepak Saxena (11/18/1999): |
| 21 | * Added event managmenet support |
Alan Cox | f1b11e5 | 2009-01-05 14:04:40 +0000 | [diff] [blame] | 22 | * Alan Cox <alan@lxorguk.ukuu.org.uk>: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * 2.4 rewrite ported to 2.5 |
| 24 | * Markus Lidel <Markus.Lidel@shadowconnect.com>: |
| 25 | * Added pass-thru support for Adaptec's raidutils |
| 26 | * |
| 27 | * This program is free software; you can redistribute it and/or |
| 28 | * modify it under the terms of the GNU General Public License |
| 29 | * as published by the Free Software Foundation; either version |
| 30 | * 2 of the License, or (at your option) any later version. |
| 31 | */ |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/miscdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/compat.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Adrian Bunk | e62c23c | 2006-07-10 04:45:40 -0700 | [diff] [blame] | 40 | #include "core.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Adrian Bunk | e62c23c | 2006-07-10 04:45:40 -0700 | [diff] [blame] | 42 | #define SG_TABLESIZE 30 |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 43 | |
Alan Cox | 5d9d6e4 | 2010-01-04 16:18:27 +0000 | [diff] [blame] | 44 | static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long); |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static spinlock_t i2o_config_lock; |
| 47 | |
| 48 | #define MODINC(x,y) ((x) = ((x) + 1) % (y)) |
| 49 | |
| 50 | struct sg_simple_element { |
| 51 | u32 flag_count; |
| 52 | u32 addr_bus; |
| 53 | }; |
| 54 | |
| 55 | struct 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 | }; |
| 66 | static struct i2o_cfg_info *open_files = NULL; |
| 67 | static ulong i2o_cfg_info_id = 0; |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static 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 | |
| 87 | static 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 | |
| 124 | static 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 | |
| 159 | static 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 Lawall | b81d67a | 2010-05-26 14:42:12 -0700 | [diff] [blame^] | 189 | ops = memdup_user(kcmd.opbuf, kcmd.oplen); |
| 190 | if (IS_ERR(ops)) |
| 191 | return PTR_ERR(ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 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. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 197 | res = kmalloc(65536, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | 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 | |
| 222 | static 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 Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 228 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | 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 Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 254 | msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); |
| 255 | if (IS_ERR(msg)) |
| 256 | return PTR_ERR(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 258 | if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) { |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 259 | i2o_msg_nop(c, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return -ENOMEM; |
| 261 | } |
| 262 | |
Randy Dunlap | 9d69b7d | 2006-12-06 20:38:23 -0800 | [diff] [blame] | 263 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 269 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize); |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 285 | status = i2o_msg_post_wait_mem(c, msg, 60, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 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 | |
| 300 | static 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 Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 306 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 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 Carpenter | b1ffdc8 | 2010-04-23 22:19:13 +0200 | [diff] [blame] | 312 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | if (get_user(swlen, kxfer.swlen) < 0) |
Dan Carpenter | b1ffdc8 | 2010-04-23 22:19:13 +0200 | [diff] [blame] | 315 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | if (get_user(maxfrag, kxfer.maxfrag) < 0) |
Dan Carpenter | b1ffdc8 | 2010-04-23 22:19:13 +0200 | [diff] [blame] | 318 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | if (get_user(curfrag, kxfer.curfrag) < 0) |
Dan Carpenter | b1ffdc8 | 2010-04-23 22:19:13 +0200 | [diff] [blame] | 321 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | if (curfrag == maxfrag) |
| 324 | fragsize = swlen - (maxfrag - 1) * 8192; |
| 325 | |
| 326 | if (!kxfer.buf) |
Dan Carpenter | b1ffdc8 | 2010-04-23 22:19:13 +0200 | [diff] [blame] | 327 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | c = i2o_find_iop(kxfer.iop); |
| 330 | if (!c) |
| 331 | return -ENXIO; |
| 332 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 333 | msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); |
| 334 | if (IS_ERR(msg)) |
| 335 | return PTR_ERR(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 337 | if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) { |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 338 | i2o_msg_nop(c, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return -ENOMEM; |
| 340 | } |
| 341 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 342 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize); |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 356 | status = i2o_msg_post_wait_mem(c, msg, 60, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return ret; |
Dan Carpenter | b1ffdc8 | 2010-04-23 22:19:13 +0200 | [diff] [blame] | 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | static 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 Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 379 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | 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 Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 393 | msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); |
| 394 | if (IS_ERR(msg)) |
| 395 | return PTR_ERR(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 397 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 407 | token = i2o_msg_post_wait(c, msg, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 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 | |
| 417 | static int i2o_cfg_validate(unsigned long arg) |
| 418 | { |
| 419 | int token; |
| 420 | int iop = (int)arg; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 421 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | struct i2o_controller *c; |
| 423 | |
| 424 | c = i2o_find_iop(iop); |
| 425 | if (!c) |
| 426 | return -ENXIO; |
| 427 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 428 | msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); |
| 429 | if (IS_ERR(msg)) |
| 430 | return PTR_ERR(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 432 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 438 | token = i2o_msg_post_wait(c, msg, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 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 | |
| 449 | static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp) |
| 450 | { |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 451 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | 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 Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 470 | msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); |
| 471 | if (IS_ERR(msg)) |
| 472 | return PTR_ERR(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 474 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 482 | i2o_msg_post(c, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static 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 Lidel | f33213e | 2005-06-23 22:02:23 -0700 | [diff] [blame] | 515 | static int i2o_cfg_passthru32(struct file *file, unsigned cmnd, |
| 516 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
| 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 530 | u32 sg_index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | i2o_status_block *sb; |
| 532 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | 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 Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 565 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | /* 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 Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 573 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | i2o_dump_message(msg); |
| 576 | |
| 577 | if (get_user(reply_size, &user_reply[0]) < 0) |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 578 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | reply_size >>= 16; |
| 581 | reply_size <<= 2; |
| 582 | |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 583 | rcode = -ENOMEM; |
Markus Lidel | f6ed39a | 2006-01-06 00:19:33 -0800 | [diff] [blame] | 584 | reply = kzalloc(reply_size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (!reply) { |
| 586 | printk(KERN_WARNING "%s: Could not allocate reply buffer\n", |
| 587 | c->name); |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 588 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | sg_offset = (msg->u.head[0] >> 4) & 0x0f; |
| 592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 609 | rcode = -EINVAL; |
| 610 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
| 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 Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 626 | p = &(sg_list[sg_index]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | /* Allocate memory for the transfer */ |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 628 | if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 633 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 635 | sg_index++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | /* 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 Lidel | f33213e | 2005-06-23 22:02:23 -0700 | [diff] [blame] | 641 | (p->virt, |
| 642 | (void __user *)(unsigned long)sg[i]. |
| 643 | addr_bus, sg_size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | printk(KERN_DEBUG |
| 645 | "%s: Could not copy SG buf %d FROM user\n", |
| 646 | c->name, i); |
| 647 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 648 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | //TODO 64bit fix |
| 652 | sg[i].addr_bus = (u32) p->phys; |
| 653 | } |
| 654 | } |
| 655 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 656 | rcode = i2o_msg_post_wait(c, msg, 60); |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 657 | msg = NULL; |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 658 | if (rcode) { |
| 659 | reply[4] = ((u32) rcode) << 24; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 660 | goto sg_list_cleanup; |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | if (sg_offset) { |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 664 | u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | /* 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 Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 672 | memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | // get user msg size in u32s |
| 674 | if (get_user(size, &user_msg[0])) { |
| 675 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 676 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | size = size >> 16; |
| 679 | size *= 4; |
| 680 | /* Copy in the user's I2O command */ |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 681 | if (copy_from_user(rmsg, user_msg, size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 683 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | sg_count = |
| 686 | (size - sg_offset * 4) / sizeof(struct sg_simple_element); |
| 687 | |
| 688 | // TODO 64bit fix |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 689 | sg = (struct sg_simple_element *)(rmsg + sg_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 705 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 711 | sg_list_cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | /* 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 727 | for (i = 0; i < sg_index; i++) |
| 728 | i2o_dma_free(&c->pdev->dev, &sg_list[i]); |
| 729 | |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 730 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | kfree(reply); |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 732 | out: |
| 733 | if (msg) |
| 734 | i2o_msg_nop(c, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return rcode; |
| 736 | } |
| 737 | |
Markus Lidel | f33213e | 2005-06-23 22:02:23 -0700 | [diff] [blame] | 738 | static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd, |
| 739 | unsigned long arg) |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 740 | { |
| 741 | int ret; |
Markus Lidel | f33213e | 2005-06-23 22:02:23 -0700 | [diff] [blame] | 742 | lock_kernel(); |
| 743 | switch (cmd) { |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 744 | case I2OGETIOPS: |
Alan Cox | 5d9d6e4 | 2010-01-04 16:18:27 +0000 | [diff] [blame] | 745 | ret = i2o_cfg_ioctl(file, cmd, arg); |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 746 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Randy Dunlap | f13a603 | 2006-12-06 20:38:24 -0800 | [diff] [blame] | 760 | #ifdef CONFIG_I2O_EXT_ADAPTEC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | static 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 Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 772 | struct i2o_dma sg_list[SG_TABLESIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | u32 sg_offset = 0; |
| 774 | u32 sg_count = 0; |
| 775 | int sg_index = 0; |
| 776 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | i2o_status_block *sb; |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 778 | struct i2o_message *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | 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 Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 805 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | /* Copy in the user's I2O command */ |
| 811 | if (copy_from_user(msg, user_msg, size)) |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 812 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
| 814 | if (get_user(reply_size, &user_reply[0]) < 0) |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 815 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | reply_size >>= 16; |
| 818 | reply_size <<= 2; |
| 819 | |
Markus Lidel | f6ed39a | 2006-01-06 00:19:33 -0800 | [diff] [blame] | 820 | reply = kzalloc(reply_size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | if (!reply) { |
| 822 | printk(KERN_WARNING "%s: Could not allocate reply buffer\n", |
| 823 | c->name); |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 824 | rcode = -ENOMEM; |
| 825 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
| 828 | sg_offset = (msg->u.head[0] >> 4) & 0x0f; |
| 829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE); |
| 831 | if (sg_offset) { |
| 832 | struct sg_simple_element *sg; |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 833 | struct i2o_dma *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 847 | rcode = -EINVAL; |
| 848 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
| 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 860 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | } |
| 862 | sg_size = sg[i].flag_count & 0xffffff; |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 863 | p = &(sg_list[sg_index]); |
| 864 | if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | /* Allocate memory for the transfer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 870 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 872 | sg_index++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | /* 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 Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 878 | (p->virt, (void __user *)sg[i].addr_bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 884 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 887 | sg[i].addr_bus = p->phys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 891 | rcode = i2o_msg_post_wait(c, msg, 60); |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 892 | msg = NULL; |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 893 | if (rcode) { |
| 894 | reply[4] = ((u32) rcode) << 24; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 895 | goto sg_list_cleanup; |
Markus Lidel | dcceafe | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | if (sg_offset) { |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 899 | u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | /* 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 Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 907 | memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | // get user msg size in u32s |
| 909 | if (get_user(size, &user_msg[0])) { |
| 910 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 911 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
| 913 | size = size >> 16; |
| 914 | size *= 4; |
| 915 | /* Copy in the user's I2O command */ |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 916 | if (copy_from_user(rmsg, user_msg, size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 918 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | sg_count = |
| 921 | (size - sg_offset * 4) / sizeof(struct sg_simple_element); |
| 922 | |
| 923 | // TODO 64bit fix |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 924 | sg = (struct sg_simple_element *)(rmsg + sg_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | 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 Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 933 | ((void __user *)sg[j].addr_bus, sg_list[j].virt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | sg_size)) { |
| 935 | printk(KERN_WARNING |
| 936 | "%s: Could not copy %p TO user %x\n", |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 937 | c->name, sg_list[j].virt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | sg[j].addr_bus); |
| 939 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 940 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 946 | sg_list_cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | /* 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 Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 963 | for (i = 0; i < sg_index; i++) |
Alan Cox | 9d793b0 | 2008-10-15 22:02:47 -0700 | [diff] [blame] | 964 | i2o_dma_free(&c->pdev->dev, &sg_list[i]); |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 965 | |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 966 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | kfree(reply); |
Vasily Averin | 1725d71 | 2007-07-17 04:04:24 -0700 | [diff] [blame] | 968 | out: |
| 969 | if (msg) |
| 970 | i2o_msg_nop(c, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | return rcode; |
| 972 | } |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 973 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | /* |
| 976 | * IOCTL Handler |
| 977 | */ |
Alan Cox | 5d9d6e4 | 2010-01-04 16:18:27 +0000 | [diff] [blame] | 978 | static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | { |
| 980 | int ret; |
| 981 | |
Alan Cox | 5d9d6e4 | 2010-01-04 16:18:27 +0000 | [diff] [blame] | 982 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | 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 Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 1028 | #ifdef CONFIG_I2O_EXT_ADAPTEC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | case I2OPASSTHRU: |
| 1030 | ret = i2o_cfg_passthru(arg); |
| 1031 | break; |
Markus Lidel | b2aaee3 | 2005-06-23 22:02:19 -0700 | [diff] [blame] | 1032 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
| 1034 | default: |
| 1035 | osm_debug("unknown ioctl called!\n"); |
| 1036 | ret = -EINVAL; |
| 1037 | } |
Alan Cox | 5d9d6e4 | 2010-01-04 16:18:27 +0000 | [diff] [blame] | 1038 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
| 1041 | |
| 1042 | static 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 Bergmann | b78032a | 2008-05-20 19:16:14 +0200 | [diff] [blame] | 1052 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | 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 Bergmann | b78032a | 2008-05-20 19:16:14 +0200 | [diff] [blame] | 1066 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static 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 Corbet | 743115e | 2008-06-19 15:44:57 -0600 | [diff] [blame] | 1075 | int ret = -EBADF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Jonathan Corbet | 743115e | 2008-06-19 15:44:57 -0600 | [diff] [blame] | 1077 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | for (p = open_files; p; p = p->next) |
| 1079 | if (p->q_id == id) |
| 1080 | break; |
| 1081 | |
Jonathan Corbet | 743115e | 2008-06-19 15:44:57 -0600 | [diff] [blame] | 1082 | if (p) |
| 1083 | ret = fasync_helper(fd, fp, on, &p->fasync); |
| 1084 | unlock_kernel(); |
| 1085 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | static int cfg_release(struct inode *inode, struct file *file) |
| 1089 | { |
| 1090 | ulong id = (ulong) file->private_data; |
Al Viro | 233e70f | 2008-10-31 23:28:30 +0000 | [diff] [blame] | 1091 | struct i2o_cfg_info *p, **q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | unsigned long flags; |
| 1093 | |
| 1094 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | spin_lock_irqsave(&i2o_config_lock, flags); |
Al Viro | 233e70f | 2008-10-31 23:28:30 +0000 | [diff] [blame] | 1096 | for (q = &open_files; (p = *q) != NULL; q = &p->next) { |
| 1097 | if (p->q_id == id) { |
| 1098 | *q = p->next; |
| 1099 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | break; |
| 1101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | spin_unlock_irqrestore(&i2o_config_lock, flags); |
| 1104 | unlock_kernel(); |
| 1105 | |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1109 | static const struct file_operations config_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | .owner = THIS_MODULE, |
| 1111 | .llseek = no_llseek, |
Alan Cox | 5d9d6e4 | 2010-01-04 16:18:27 +0000 | [diff] [blame] | 1112 | .unlocked_ioctl = i2o_cfg_ioctl, |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 1113 | #ifdef CONFIG_COMPAT |
| 1114 | .compat_ioctl = i2o_cfg_compat_ioctl, |
| 1115 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | .open = cfg_open, |
| 1117 | .release = cfg_release, |
| 1118 | .fasync = cfg_fasync, |
| 1119 | }; |
| 1120 | |
| 1121 | static struct miscdevice i2o_miscdev = { |
| 1122 | I2O_MINOR, |
| 1123 | "i2octl", |
| 1124 | &config_fops |
| 1125 | }; |
| 1126 | |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 1127 | static int __init i2o_config_old_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | 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 Lidel | f33213e | 2005-06-23 22:02:23 -0700 | [diff] [blame] | 1135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | return 0; |
| 1137 | } |
| 1138 | |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 1139 | static void i2o_config_old_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | misc_deregister(&i2o_miscdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | MODULE_AUTHOR("Red Hat Software"); |