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) |
| 13 | * Auvo Häkkinen (09/10/1999): |
| 14 | * Changes to i2o_cfg_reply(), ioctl_parms() |
| 15 | * Added ioct_validate() |
| 16 | * Taneli Vähäkangas (09/30/1999): |
| 17 | * Fixed ioctl_swdl() |
| 18 | * Taneli Vähäkangas (10/04/1999): |
| 19 | * Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel() |
| 20 | * Deepak Saxena (11/18/1999): |
| 21 | * Added event managmenet support |
| 22 | * Alan Cox <alan@redhat.com>: |
| 23 | * 2.4 rewrite ported to 2.5 |
| 24 | * Markus Lidel <Markus.Lidel@shadowconnect.com>: |
| 25 | * Added pass-thru support for Adaptec's raidutils |
| 26 | * |
| 27 | * This program is free software; you can redistribute it and/or |
| 28 | * modify it under the terms of the GNU General Public License |
| 29 | * as published by the Free Software Foundation; either version |
| 30 | * 2 of the License, or (at your option) any later version. |
| 31 | */ |
| 32 | |
Linus 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | extern int i2o_parm_issue(struct i2o_device *, int, void *, int, void *, int); |
| 40 | |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 41 | static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd, |
| 42 | unsigned long arg); |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static spinlock_t i2o_config_lock; |
| 45 | |
| 46 | #define MODINC(x,y) ((x) = ((x) + 1) % (y)) |
| 47 | |
| 48 | struct sg_simple_element { |
| 49 | u32 flag_count; |
| 50 | u32 addr_bus; |
| 51 | }; |
| 52 | |
| 53 | struct i2o_cfg_info { |
| 54 | struct file *fp; |
| 55 | struct fasync_struct *fasync; |
| 56 | struct i2o_evt_info event_q[I2O_EVT_Q_LEN]; |
| 57 | u16 q_in; // Queue head index |
| 58 | u16 q_out; // Queue tail index |
| 59 | u16 q_len; // Queue length |
| 60 | u16 q_lost; // Number of lost events |
| 61 | ulong q_id; // Event queue ID...used as tx_context |
| 62 | struct i2o_cfg_info *next; |
| 63 | }; |
| 64 | static struct i2o_cfg_info *open_files = NULL; |
| 65 | static ulong i2o_cfg_info_id = 0; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static int i2o_cfg_getiops(unsigned long arg) |
| 68 | { |
| 69 | struct i2o_controller *c; |
| 70 | u8 __user *user_iop_table = (void __user *)arg; |
| 71 | u8 tmp[MAX_I2O_CONTROLLERS]; |
| 72 | int ret = 0; |
| 73 | |
| 74 | memset(tmp, 0, MAX_I2O_CONTROLLERS); |
| 75 | |
| 76 | list_for_each_entry(c, &i2o_controllers, list) |
| 77 | tmp[c->unit] = 1; |
| 78 | |
| 79 | if (copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS)) |
| 80 | ret = -EFAULT; |
| 81 | |
| 82 | return ret; |
| 83 | }; |
| 84 | |
| 85 | static int i2o_cfg_gethrt(unsigned long arg) |
| 86 | { |
| 87 | struct i2o_controller *c; |
| 88 | struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg; |
| 89 | struct i2o_cmd_hrtlct kcmd; |
| 90 | i2o_hrt *hrt; |
| 91 | int len; |
| 92 | u32 reslen; |
| 93 | int ret = 0; |
| 94 | |
| 95 | if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct))) |
| 96 | return -EFAULT; |
| 97 | |
| 98 | if (get_user(reslen, kcmd.reslen) < 0) |
| 99 | return -EFAULT; |
| 100 | |
| 101 | if (kcmd.resbuf == NULL) |
| 102 | return -EFAULT; |
| 103 | |
| 104 | c = i2o_find_iop(kcmd.iop); |
| 105 | if (!c) |
| 106 | return -ENXIO; |
| 107 | |
| 108 | hrt = (i2o_hrt *) c->hrt.virt; |
| 109 | |
| 110 | len = 8 + ((hrt->entry_len * hrt->num_entries) << 2); |
| 111 | |
| 112 | /* We did a get user...so assuming mem is ok...is this bad? */ |
| 113 | put_user(len, kcmd.reslen); |
| 114 | if (len > reslen) |
| 115 | ret = -ENOBUFS; |
| 116 | if (copy_to_user(kcmd.resbuf, (void *)hrt, len)) |
| 117 | ret = -EFAULT; |
| 118 | |
| 119 | return ret; |
| 120 | }; |
| 121 | |
| 122 | static int i2o_cfg_getlct(unsigned long arg) |
| 123 | { |
| 124 | struct i2o_controller *c; |
| 125 | struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg; |
| 126 | struct i2o_cmd_hrtlct kcmd; |
| 127 | i2o_lct *lct; |
| 128 | int len; |
| 129 | int ret = 0; |
| 130 | u32 reslen; |
| 131 | |
| 132 | if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct))) |
| 133 | return -EFAULT; |
| 134 | |
| 135 | if (get_user(reslen, kcmd.reslen) < 0) |
| 136 | return -EFAULT; |
| 137 | |
| 138 | if (kcmd.resbuf == NULL) |
| 139 | return -EFAULT; |
| 140 | |
| 141 | c = i2o_find_iop(kcmd.iop); |
| 142 | if (!c) |
| 143 | return -ENXIO; |
| 144 | |
| 145 | lct = (i2o_lct *) c->lct; |
| 146 | |
| 147 | len = (unsigned int)lct->table_size << 2; |
| 148 | put_user(len, kcmd.reslen); |
| 149 | if (len > reslen) |
| 150 | ret = -ENOBUFS; |
| 151 | else if (copy_to_user(kcmd.resbuf, lct, len)) |
| 152 | ret = -EFAULT; |
| 153 | |
| 154 | return ret; |
| 155 | }; |
| 156 | |
| 157 | static int i2o_cfg_parms(unsigned long arg, unsigned int type) |
| 158 | { |
| 159 | int ret = 0; |
| 160 | struct i2o_controller *c; |
| 161 | struct i2o_device *dev; |
| 162 | struct i2o_cmd_psetget __user *cmd = |
| 163 | (struct i2o_cmd_psetget __user *)arg; |
| 164 | struct i2o_cmd_psetget kcmd; |
| 165 | u32 reslen; |
| 166 | u8 *ops; |
| 167 | u8 *res; |
| 168 | int len = 0; |
| 169 | |
| 170 | u32 i2o_cmd = (type == I2OPARMGET ? |
| 171 | I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET); |
| 172 | |
| 173 | if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget))) |
| 174 | return -EFAULT; |
| 175 | |
| 176 | if (get_user(reslen, kcmd.reslen)) |
| 177 | return -EFAULT; |
| 178 | |
| 179 | c = i2o_find_iop(kcmd.iop); |
| 180 | if (!c) |
| 181 | return -ENXIO; |
| 182 | |
| 183 | dev = i2o_iop_find_device(c, kcmd.tid); |
| 184 | if (!dev) |
| 185 | return -ENXIO; |
| 186 | |
| 187 | ops = (u8 *) kmalloc(kcmd.oplen, GFP_KERNEL); |
| 188 | if (!ops) |
| 189 | return -ENOMEM; |
| 190 | |
| 191 | if (copy_from_user(ops, kcmd.opbuf, kcmd.oplen)) { |
| 192 | kfree(ops); |
| 193 | return -EFAULT; |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * It's possible to have a _very_ large table |
| 198 | * and that the user asks for all of it at once... |
| 199 | */ |
| 200 | res = (u8 *) kmalloc(65536, GFP_KERNEL); |
| 201 | if (!res) { |
| 202 | kfree(ops); |
| 203 | return -ENOMEM; |
| 204 | } |
| 205 | |
| 206 | len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536); |
| 207 | kfree(ops); |
| 208 | |
| 209 | if (len < 0) { |
| 210 | kfree(res); |
| 211 | return -EAGAIN; |
| 212 | } |
| 213 | |
| 214 | put_user(len, kcmd.reslen); |
| 215 | if (len > reslen) |
| 216 | ret = -ENOBUFS; |
| 217 | else if (copy_to_user(kcmd.resbuf, res, len)) |
| 218 | ret = -EFAULT; |
| 219 | |
| 220 | kfree(res); |
| 221 | |
| 222 | return ret; |
| 223 | }; |
| 224 | |
| 225 | static int i2o_cfg_swdl(unsigned long arg) |
| 226 | { |
| 227 | struct i2o_sw_xfer kxfer; |
| 228 | struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg; |
| 229 | unsigned char maxfrag = 0, curfrag = 1; |
| 230 | struct i2o_dma buffer; |
| 231 | struct i2o_message __iomem *msg; |
| 232 | u32 m; |
| 233 | 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 | |
| 258 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 259 | if (m == I2O_QUEUE_EMPTY) |
| 260 | return -EBUSY; |
| 261 | |
| 262 | if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) { |
| 263 | i2o_msg_nop(c, m); |
| 264 | return -ENOMEM; |
| 265 | } |
| 266 | |
| 267 | __copy_from_user(buffer.virt, kxfer.buf, fragsize); |
| 268 | |
| 269 | writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]); |
| 270 | writel(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 | ADAPTER_TID, |
| 271 | &msg->u.head[1]); |
| 272 | writel(i2o_config_driver.context, &msg->u.head[2]); |
| 273 | writel(0, &msg->u.head[3]); |
| 274 | writel((((u32) kxfer.flags) << 24) | (((u32) kxfer.sw_type) << 16) | |
| 275 | (((u32) maxfrag) << 8) | (((u32) curfrag)), &msg->body[0]); |
| 276 | writel(swlen, &msg->body[1]); |
| 277 | writel(kxfer.sw_id, &msg->body[2]); |
| 278 | writel(0xD0000000 | fragsize, &msg->body[3]); |
| 279 | writel(buffer.phys, &msg->body[4]); |
| 280 | |
| 281 | osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize); |
| 282 | status = i2o_msg_post_wait_mem(c, m, 60, &buffer); |
| 283 | |
| 284 | if (status != -ETIMEDOUT) |
| 285 | i2o_dma_free(&c->pdev->dev, &buffer); |
| 286 | |
| 287 | if (status != I2O_POST_WAIT_OK) { |
| 288 | // it fails if you try and send frags out of order |
| 289 | // and for some yet unknown reasons too |
| 290 | osm_info("swdl failed, DetailedStatus = %d\n", status); |
| 291 | return status; |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | }; |
| 296 | |
| 297 | static int i2o_cfg_swul(unsigned long arg) |
| 298 | { |
| 299 | struct i2o_sw_xfer kxfer; |
| 300 | struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg; |
| 301 | unsigned char maxfrag = 0, curfrag = 1; |
| 302 | struct i2o_dma buffer; |
| 303 | struct i2o_message __iomem *msg; |
| 304 | u32 m; |
| 305 | unsigned int status = 0, swlen = 0, fragsize = 8192; |
| 306 | struct i2o_controller *c; |
| 307 | int ret = 0; |
| 308 | |
| 309 | if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer))) |
| 310 | goto return_fault; |
| 311 | |
| 312 | if (get_user(swlen, kxfer.swlen) < 0) |
| 313 | goto return_fault; |
| 314 | |
| 315 | if (get_user(maxfrag, kxfer.maxfrag) < 0) |
| 316 | goto return_fault; |
| 317 | |
| 318 | if (get_user(curfrag, kxfer.curfrag) < 0) |
| 319 | goto return_fault; |
| 320 | |
| 321 | if (curfrag == maxfrag) |
| 322 | fragsize = swlen - (maxfrag - 1) * 8192; |
| 323 | |
| 324 | if (!kxfer.buf) |
| 325 | goto return_fault; |
| 326 | |
| 327 | c = i2o_find_iop(kxfer.iop); |
| 328 | if (!c) |
| 329 | return -ENXIO; |
| 330 | |
| 331 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 332 | if (m == I2O_QUEUE_EMPTY) |
| 333 | return -EBUSY; |
| 334 | |
| 335 | if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) { |
| 336 | i2o_msg_nop(c, m); |
| 337 | return -ENOMEM; |
| 338 | } |
| 339 | |
| 340 | writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]); |
| 341 | writel(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID, |
| 342 | &msg->u.head[1]); |
| 343 | writel(i2o_config_driver.context, &msg->u.head[2]); |
| 344 | writel(0, &msg->u.head[3]); |
| 345 | writel((u32) kxfer.flags << 24 | (u32) kxfer. |
| 346 | sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag, |
| 347 | &msg->body[0]); |
| 348 | writel(swlen, &msg->body[1]); |
| 349 | writel(kxfer.sw_id, &msg->body[2]); |
| 350 | writel(0xD0000000 | fragsize, &msg->body[3]); |
| 351 | writel(buffer.phys, &msg->body[4]); |
| 352 | |
| 353 | osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize); |
| 354 | status = i2o_msg_post_wait_mem(c, m, 60, &buffer); |
| 355 | |
| 356 | if (status != I2O_POST_WAIT_OK) { |
| 357 | if (status != -ETIMEDOUT) |
| 358 | i2o_dma_free(&c->pdev->dev, &buffer); |
| 359 | |
| 360 | osm_info("swul failed, DetailedStatus = %d\n", status); |
| 361 | return status; |
| 362 | } |
| 363 | |
| 364 | if (copy_to_user(kxfer.buf, buffer.virt, fragsize)) |
| 365 | ret = -EFAULT; |
| 366 | |
| 367 | i2o_dma_free(&c->pdev->dev, &buffer); |
| 368 | |
| 369 | return_ret: |
| 370 | return ret; |
| 371 | return_fault: |
| 372 | ret = -EFAULT; |
| 373 | goto return_ret; |
| 374 | }; |
| 375 | |
| 376 | static int i2o_cfg_swdel(unsigned long arg) |
| 377 | { |
| 378 | struct i2o_controller *c; |
| 379 | struct i2o_sw_xfer kxfer; |
| 380 | struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg; |
| 381 | struct i2o_message __iomem *msg; |
| 382 | u32 m; |
| 383 | unsigned int swlen; |
| 384 | int token; |
| 385 | |
| 386 | if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer))) |
| 387 | return -EFAULT; |
| 388 | |
| 389 | if (get_user(swlen, kxfer.swlen) < 0) |
| 390 | return -EFAULT; |
| 391 | |
| 392 | c = i2o_find_iop(kxfer.iop); |
| 393 | if (!c) |
| 394 | return -ENXIO; |
| 395 | |
| 396 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 397 | if (m == I2O_QUEUE_EMPTY) |
| 398 | return -EBUSY; |
| 399 | |
| 400 | writel(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]); |
| 401 | writel(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID, |
| 402 | &msg->u.head[1]); |
| 403 | writel(i2o_config_driver.context, &msg->u.head[2]); |
| 404 | writel(0, &msg->u.head[3]); |
| 405 | writel((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16, |
| 406 | &msg->body[0]); |
| 407 | writel(swlen, &msg->body[1]); |
| 408 | writel(kxfer.sw_id, &msg->body[2]); |
| 409 | |
| 410 | token = i2o_msg_post_wait(c, m, 10); |
| 411 | |
| 412 | if (token != I2O_POST_WAIT_OK) { |
| 413 | osm_info("swdel failed, DetailedStatus = %d\n", token); |
| 414 | return -ETIMEDOUT; |
| 415 | } |
| 416 | |
| 417 | return 0; |
| 418 | }; |
| 419 | |
| 420 | static int i2o_cfg_validate(unsigned long arg) |
| 421 | { |
| 422 | int token; |
| 423 | int iop = (int)arg; |
| 424 | struct i2o_message __iomem *msg; |
| 425 | u32 m; |
| 426 | struct i2o_controller *c; |
| 427 | |
| 428 | c = i2o_find_iop(iop); |
| 429 | if (!c) |
| 430 | return -ENXIO; |
| 431 | |
| 432 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 433 | if (m == I2O_QUEUE_EMPTY) |
| 434 | return -EBUSY; |
| 435 | |
| 436 | writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]); |
| 437 | writel(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop, |
| 438 | &msg->u.head[1]); |
| 439 | writel(i2o_config_driver.context, &msg->u.head[2]); |
| 440 | writel(0, &msg->u.head[3]); |
| 441 | |
| 442 | token = i2o_msg_post_wait(c, m, 10); |
| 443 | |
| 444 | if (token != I2O_POST_WAIT_OK) { |
| 445 | osm_info("Can't validate configuration, ErrorStatus = %d\n", |
| 446 | token); |
| 447 | return -ETIMEDOUT; |
| 448 | } |
| 449 | |
| 450 | return 0; |
| 451 | }; |
| 452 | |
| 453 | static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp) |
| 454 | { |
| 455 | struct i2o_message __iomem *msg; |
| 456 | u32 m; |
| 457 | struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg; |
| 458 | struct i2o_evt_id kdesc; |
| 459 | struct i2o_controller *c; |
| 460 | struct i2o_device *d; |
| 461 | |
| 462 | if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id))) |
| 463 | return -EFAULT; |
| 464 | |
| 465 | /* IOP exists? */ |
| 466 | c = i2o_find_iop(kdesc.iop); |
| 467 | if (!c) |
| 468 | return -ENXIO; |
| 469 | |
| 470 | /* Device exists? */ |
| 471 | d = i2o_iop_find_device(c, kdesc.tid); |
| 472 | if (!d) |
| 473 | return -ENODEV; |
| 474 | |
| 475 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 476 | if (m == I2O_QUEUE_EMPTY) |
| 477 | return -EBUSY; |
| 478 | |
| 479 | writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]); |
| 480 | writel(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | kdesc.tid, |
| 481 | &msg->u.head[1]); |
| 482 | writel(i2o_config_driver.context, &msg->u.head[2]); |
| 483 | writel(i2o_cntxt_list_add(c, fp->private_data), &msg->u.head[3]); |
| 484 | writel(kdesc.evt_mask, &msg->body[0]); |
| 485 | |
| 486 | i2o_msg_post(c, m); |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static int i2o_cfg_evt_get(unsigned long arg, struct file *fp) |
| 492 | { |
| 493 | struct i2o_cfg_info *p = NULL; |
| 494 | struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg; |
| 495 | struct i2o_evt_get kget; |
| 496 | unsigned long flags; |
| 497 | |
| 498 | for (p = open_files; p; p = p->next) |
| 499 | if (p->q_id == (ulong) fp->private_data) |
| 500 | break; |
| 501 | |
| 502 | if (!p->q_len) |
| 503 | return -ENOENT; |
| 504 | |
| 505 | memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info)); |
| 506 | MODINC(p->q_out, I2O_EVT_Q_LEN); |
| 507 | spin_lock_irqsave(&i2o_config_lock, flags); |
| 508 | p->q_len--; |
| 509 | kget.pending = p->q_len; |
| 510 | kget.lost = p->q_lost; |
| 511 | spin_unlock_irqrestore(&i2o_config_lock, flags); |
| 512 | |
| 513 | if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get))) |
| 514 | return -EFAULT; |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | #ifdef CONFIG_COMPAT |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 519 | static int i2o_cfg_passthru32(struct file *file, unsigned cmnd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
| 521 | struct i2o_cmd_passthru32 __user *cmd; |
| 522 | struct i2o_controller *c; |
| 523 | u32 __user *user_msg; |
| 524 | u32 *reply = NULL; |
| 525 | u32 __user *user_reply = NULL; |
| 526 | u32 size = 0; |
| 527 | u32 reply_size = 0; |
| 528 | u32 rcode = 0; |
| 529 | struct i2o_dma sg_list[SG_TABLESIZE]; |
| 530 | u32 sg_offset = 0; |
| 531 | u32 sg_count = 0; |
| 532 | u32 i = 0; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 533 | u32 sg_index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | i2o_status_block *sb; |
| 535 | struct i2o_message *msg; |
| 536 | u32 m; |
| 537 | unsigned int iop; |
| 538 | |
| 539 | cmd = (struct i2o_cmd_passthru32 __user *)arg; |
| 540 | |
| 541 | if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg)) |
| 542 | return -EFAULT; |
| 543 | |
| 544 | user_msg = compat_ptr(i); |
| 545 | |
| 546 | c = i2o_find_iop(iop); |
| 547 | if (!c) { |
| 548 | osm_debug("controller %d not found\n", iop); |
| 549 | return -ENXIO; |
| 550 | } |
| 551 | |
| 552 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 553 | |
| 554 | sb = c->status_block.virt; |
| 555 | |
| 556 | if (get_user(size, &user_msg[0])) { |
| 557 | osm_warn("unable to get size!\n"); |
| 558 | return -EFAULT; |
| 559 | } |
| 560 | size = size >> 16; |
| 561 | |
| 562 | if (size > sb->inbound_frame_size) { |
| 563 | osm_warn("size of message > inbound_frame_size"); |
| 564 | return -EFAULT; |
| 565 | } |
| 566 | |
| 567 | user_reply = &user_msg[size]; |
| 568 | |
| 569 | size <<= 2; // Convert to bytes |
| 570 | |
| 571 | /* Copy in the user's I2O command */ |
| 572 | if (copy_from_user(msg, user_msg, size)) { |
| 573 | osm_warn("unable to copy user message\n"); |
| 574 | return -EFAULT; |
| 575 | } |
| 576 | i2o_dump_message(msg); |
| 577 | |
| 578 | if (get_user(reply_size, &user_reply[0]) < 0) |
| 579 | return -EFAULT; |
| 580 | |
| 581 | reply_size >>= 16; |
| 582 | reply_size <<= 2; |
| 583 | |
| 584 | reply = kmalloc(reply_size, GFP_KERNEL); |
| 585 | if (!reply) { |
| 586 | printk(KERN_WARNING "%s: Could not allocate reply buffer\n", |
| 587 | c->name); |
| 588 | return -ENOMEM; |
| 589 | } |
| 590 | memset(reply, 0, reply_size); |
| 591 | |
| 592 | sg_offset = (msg->u.head[0] >> 4) & 0x0f; |
| 593 | |
| 594 | writel(i2o_config_driver.context, &msg->u.s.icntxt); |
| 595 | writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt); |
| 596 | |
| 597 | memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE); |
| 598 | if (sg_offset) { |
| 599 | struct sg_simple_element *sg; |
| 600 | |
| 601 | if (sg_offset * 4 >= size) { |
| 602 | rcode = -EFAULT; |
| 603 | goto cleanup; |
| 604 | } |
| 605 | // TODO 64bit fix |
| 606 | sg = (struct sg_simple_element *)((&msg->u.head[0]) + |
| 607 | sg_offset); |
| 608 | sg_count = |
| 609 | (size - sg_offset * 4) / sizeof(struct sg_simple_element); |
| 610 | if (sg_count > SG_TABLESIZE) { |
| 611 | printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n", |
| 612 | c->name, sg_count); |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 613 | rcode = -EINVAL; |
| 614 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | for (i = 0; i < sg_count; i++) { |
| 618 | int sg_size; |
| 619 | struct i2o_dma *p; |
| 620 | |
| 621 | if (!(sg[i].flag_count & 0x10000000 |
| 622 | /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) { |
| 623 | printk(KERN_DEBUG |
| 624 | "%s:Bad SG element %d - not simple (%x)\n", |
| 625 | c->name, i, sg[i].flag_count); |
| 626 | rcode = -EINVAL; |
| 627 | goto cleanup; |
| 628 | } |
| 629 | sg_size = sg[i].flag_count & 0xffffff; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 630 | p = &(sg_list[sg_index++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | /* Allocate memory for the transfer */ |
| 632 | if (i2o_dma_alloc |
| 633 | (&c->pdev->dev, p, sg_size, |
| 634 | PCI_DMA_BIDIRECTIONAL)) { |
| 635 | printk(KERN_DEBUG |
| 636 | "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n", |
| 637 | c->name, sg_size, i, sg_count); |
| 638 | rcode = -ENOMEM; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 639 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } |
| 641 | /* Copy in the user's SG buffer if necessary */ |
| 642 | if (sg[i]. |
| 643 | flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) { |
| 644 | // TODO 64bit fix |
| 645 | if (copy_from_user |
| 646 | (p->virt, (void __user *)(unsigned long)sg[i].addr_bus, |
| 647 | sg_size)) { |
| 648 | printk(KERN_DEBUG |
| 649 | "%s: Could not copy SG buf %d FROM user\n", |
| 650 | c->name, i); |
| 651 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 652 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | //TODO 64bit fix |
| 656 | sg[i].addr_bus = (u32) p->phys; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | rcode = i2o_msg_post_wait(c, m, 60); |
| 661 | if (rcode) |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 662 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
| 664 | if (sg_offset) { |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 665 | u32 msg[MSG_FRAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | /* Copy back the Scatter Gather buffers back to user space */ |
| 667 | u32 j; |
| 668 | // TODO 64bit fix |
| 669 | struct sg_simple_element *sg; |
| 670 | int sg_size; |
| 671 | |
| 672 | // re-acquire the original message to handle correctly the sg copy operation |
| 673 | memset(&msg, 0, MSG_FRAME_SIZE * 4); |
| 674 | // get user msg size in u32s |
| 675 | if (get_user(size, &user_msg[0])) { |
| 676 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 677 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | size = size >> 16; |
| 680 | size *= 4; |
| 681 | /* Copy in the user's I2O command */ |
| 682 | if (copy_from_user(msg, user_msg, size)) { |
| 683 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 684 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
| 686 | sg_count = |
| 687 | (size - sg_offset * 4) / sizeof(struct sg_simple_element); |
| 688 | |
| 689 | // TODO 64bit fix |
| 690 | sg = (struct sg_simple_element *)(msg + sg_offset); |
| 691 | for (j = 0; j < sg_count; j++) { |
| 692 | /* Copy out the SG list to user's buffer if necessary */ |
| 693 | if (! |
| 694 | (sg[j]. |
| 695 | flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) { |
| 696 | sg_size = sg[j].flag_count & 0xffffff; |
| 697 | // TODO 64bit fix |
| 698 | if (copy_to_user |
| 699 | ((void __user *)(u64) sg[j].addr_bus, |
| 700 | sg_list[j].virt, sg_size)) { |
| 701 | printk(KERN_WARNING |
| 702 | "%s: Could not copy %p TO user %x\n", |
| 703 | c->name, sg_list[j].virt, |
| 704 | sg[j].addr_bus); |
| 705 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 706 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | |
| 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; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 720 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | if (copy_to_user(user_reply, reply, reply_size)) { |
| 723 | printk(KERN_WARNING |
| 724 | "%s: Could not copy reply TO user\n", c->name); |
| 725 | rcode = -EFAULT; |
| 726 | } |
| 727 | } |
| 728 | |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 729 | sg_list_cleanup: |
| 730 | for (i = 0; i < sg_index; i++) |
| 731 | i2o_dma_free(&c->pdev->dev, &sg_list[i]); |
| 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | cleanup: |
| 734 | kfree(reply); |
| 735 | return rcode; |
| 736 | } |
| 737 | |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 738 | static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg) |
| 739 | { |
| 740 | int ret; |
| 741 | lock_kernel(); |
| 742 | switch (cmd) { |
| 743 | case I2OGETIOPS: |
| 744 | ret = i2o_cfg_ioctl(NULL, file, cmd, arg); |
| 745 | break; |
| 746 | case I2OPASSTHRU32: |
| 747 | ret = i2o_cfg_passthru32(file, cmd, arg); |
| 748 | break; |
| 749 | default: |
| 750 | ret = -ENOIOCTLCMD; |
| 751 | break; |
| 752 | } |
| 753 | unlock_kernel(); |
| 754 | return ret; |
| 755 | } |
| 756 | |
| 757 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | static int i2o_cfg_passthru(unsigned long arg) |
| 760 | { |
| 761 | struct i2o_cmd_passthru __user *cmd = |
| 762 | (struct i2o_cmd_passthru __user *)arg; |
| 763 | struct i2o_controller *c; |
| 764 | u32 __user *user_msg; |
| 765 | u32 *reply = NULL; |
| 766 | u32 __user *user_reply = NULL; |
| 767 | u32 size = 0; |
| 768 | u32 reply_size = 0; |
| 769 | u32 rcode = 0; |
| 770 | void *sg_list[SG_TABLESIZE]; |
| 771 | u32 sg_offset = 0; |
| 772 | u32 sg_count = 0; |
| 773 | int sg_index = 0; |
| 774 | u32 i = 0; |
| 775 | void *p = NULL; |
| 776 | i2o_status_block *sb; |
| 777 | struct i2o_message __iomem *msg; |
| 778 | u32 m; |
| 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 | |
| 790 | m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); |
| 791 | |
| 792 | sb = c->status_block.virt; |
| 793 | |
| 794 | if (get_user(size, &user_msg[0])) |
| 795 | return -EFAULT; |
| 796 | size = size >> 16; |
| 797 | |
| 798 | if (size > sb->inbound_frame_size) { |
| 799 | osm_warn("size of message > inbound_frame_size"); |
| 800 | return -EFAULT; |
| 801 | } |
| 802 | |
| 803 | user_reply = &user_msg[size]; |
| 804 | |
| 805 | size <<= 2; // Convert to bytes |
| 806 | |
| 807 | /* Copy in the user's I2O command */ |
| 808 | if (copy_from_user(msg, user_msg, size)) |
| 809 | return -EFAULT; |
| 810 | |
| 811 | if (get_user(reply_size, &user_reply[0]) < 0) |
| 812 | return -EFAULT; |
| 813 | |
| 814 | reply_size >>= 16; |
| 815 | reply_size <<= 2; |
| 816 | |
| 817 | reply = kmalloc(reply_size, GFP_KERNEL); |
| 818 | if (!reply) { |
| 819 | printk(KERN_WARNING "%s: Could not allocate reply buffer\n", |
| 820 | c->name); |
| 821 | return -ENOMEM; |
| 822 | } |
| 823 | memset(reply, 0, reply_size); |
| 824 | |
| 825 | sg_offset = (msg->u.head[0] >> 4) & 0x0f; |
| 826 | |
| 827 | writel(i2o_config_driver.context, &msg->u.s.icntxt); |
| 828 | writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt); |
| 829 | |
| 830 | memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE); |
| 831 | if (sg_offset) { |
| 832 | struct sg_simple_element *sg; |
| 833 | |
| 834 | if (sg_offset * 4 >= size) { |
| 835 | rcode = -EFAULT; |
| 836 | goto cleanup; |
| 837 | } |
| 838 | // TODO 64bit fix |
| 839 | sg = (struct sg_simple_element *)((&msg->u.head[0]) + |
| 840 | sg_offset); |
| 841 | sg_count = |
| 842 | (size - sg_offset * 4) / sizeof(struct sg_simple_element); |
| 843 | if (sg_count > SG_TABLESIZE) { |
| 844 | printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n", |
| 845 | c->name, sg_count); |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 846 | rcode = -EINVAL; |
| 847 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | for (i = 0; i < sg_count; i++) { |
| 851 | int sg_size; |
| 852 | |
| 853 | if (!(sg[i].flag_count & 0x10000000 |
| 854 | /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) { |
| 855 | printk(KERN_DEBUG |
| 856 | "%s:Bad SG element %d - not simple (%x)\n", |
| 857 | c->name, i, sg[i].flag_count); |
| 858 | rcode = -EINVAL; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 859 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
| 861 | sg_size = sg[i].flag_count & 0xffffff; |
| 862 | /* Allocate memory for the transfer */ |
| 863 | p = kmalloc(sg_size, GFP_KERNEL); |
| 864 | if (!p) { |
| 865 | printk(KERN_DEBUG |
| 866 | "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n", |
| 867 | c->name, sg_size, i, sg_count); |
| 868 | rcode = -ENOMEM; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 869 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
| 871 | sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame. |
| 872 | /* Copy in the user's SG buffer if necessary */ |
| 873 | if (sg[i]. |
| 874 | flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) { |
| 875 | // TODO 64bit fix |
| 876 | if (copy_from_user |
| 877 | (p, (void __user *)sg[i].addr_bus, |
| 878 | sg_size)) { |
| 879 | printk(KERN_DEBUG |
| 880 | "%s: Could not copy SG buf %d FROM user\n", |
| 881 | c->name, i); |
| 882 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 883 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | //TODO 64bit fix |
| 887 | sg[i].addr_bus = virt_to_bus(p); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | rcode = i2o_msg_post_wait(c, m, 60); |
| 892 | if (rcode) |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 893 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | if (sg_offset) { |
| 896 | u32 msg[128]; |
| 897 | /* Copy back the Scatter Gather buffers back to user space */ |
| 898 | u32 j; |
| 899 | // TODO 64bit fix |
| 900 | struct sg_simple_element *sg; |
| 901 | int sg_size; |
| 902 | |
| 903 | // re-acquire the original message to handle correctly the sg copy operation |
| 904 | memset(&msg, 0, MSG_FRAME_SIZE * 4); |
| 905 | // get user msg size in u32s |
| 906 | if (get_user(size, &user_msg[0])) { |
| 907 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 908 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } |
| 910 | size = size >> 16; |
| 911 | size *= 4; |
| 912 | /* Copy in the user's I2O command */ |
| 913 | if (copy_from_user(msg, user_msg, size)) { |
| 914 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 915 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } |
| 917 | sg_count = |
| 918 | (size - sg_offset * 4) / sizeof(struct sg_simple_element); |
| 919 | |
| 920 | // TODO 64bit fix |
| 921 | sg = (struct sg_simple_element *)(msg + sg_offset); |
| 922 | for (j = 0; j < sg_count; j++) { |
| 923 | /* Copy out the SG list to user's buffer if necessary */ |
| 924 | if (! |
| 925 | (sg[j]. |
| 926 | flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) { |
| 927 | sg_size = sg[j].flag_count & 0xffffff; |
| 928 | // TODO 64bit fix |
| 929 | if (copy_to_user |
| 930 | ((void __user *)sg[j].addr_bus, sg_list[j], |
| 931 | sg_size)) { |
| 932 | printk(KERN_WARNING |
| 933 | "%s: Could not copy %p TO user %x\n", |
| 934 | c->name, sg_list[j], |
| 935 | sg[j].addr_bus); |
| 936 | rcode = -EFAULT; |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 937 | goto sg_list_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /* Copy back the reply to user space */ |
| 944 | if (reply_size) { |
| 945 | // we wrote our own values for context - now restore the user supplied ones |
| 946 | if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) { |
| 947 | printk(KERN_WARNING |
| 948 | "%s: Could not copy message context FROM user\n", |
| 949 | c->name); |
| 950 | rcode = -EFAULT; |
| 951 | } |
| 952 | if (copy_to_user(user_reply, reply, reply_size)) { |
| 953 | printk(KERN_WARNING |
| 954 | "%s: Could not copy reply TO user\n", c->name); |
| 955 | rcode = -EFAULT; |
| 956 | } |
| 957 | } |
| 958 | |
Markus Lidel | 61fbfa8 | 2005-06-23 22:02:11 -0700 | [diff] [blame] | 959 | sg_list_cleanup: |
| 960 | for (i = 0; i < sg_index; i++) |
| 961 | kfree(sg_list[i]); |
| 962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | cleanup: |
| 964 | kfree(reply); |
| 965 | return rcode; |
| 966 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
| 968 | /* |
| 969 | * IOCTL Handler |
| 970 | */ |
| 971 | static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd, |
| 972 | unsigned long arg) |
| 973 | { |
| 974 | int ret; |
| 975 | |
| 976 | switch (cmd) { |
| 977 | case I2OGETIOPS: |
| 978 | ret = i2o_cfg_getiops(arg); |
| 979 | break; |
| 980 | |
| 981 | case I2OHRTGET: |
| 982 | ret = i2o_cfg_gethrt(arg); |
| 983 | break; |
| 984 | |
| 985 | case I2OLCTGET: |
| 986 | ret = i2o_cfg_getlct(arg); |
| 987 | break; |
| 988 | |
| 989 | case I2OPARMSET: |
| 990 | ret = i2o_cfg_parms(arg, I2OPARMSET); |
| 991 | break; |
| 992 | |
| 993 | case I2OPARMGET: |
| 994 | ret = i2o_cfg_parms(arg, I2OPARMGET); |
| 995 | break; |
| 996 | |
| 997 | case I2OSWDL: |
| 998 | ret = i2o_cfg_swdl(arg); |
| 999 | break; |
| 1000 | |
| 1001 | case I2OSWUL: |
| 1002 | ret = i2o_cfg_swul(arg); |
| 1003 | break; |
| 1004 | |
| 1005 | case I2OSWDEL: |
| 1006 | ret = i2o_cfg_swdel(arg); |
| 1007 | break; |
| 1008 | |
| 1009 | case I2OVALIDATE: |
| 1010 | ret = i2o_cfg_validate(arg); |
| 1011 | break; |
| 1012 | |
| 1013 | case I2OEVTREG: |
| 1014 | ret = i2o_cfg_evt_reg(arg, fp); |
| 1015 | break; |
| 1016 | |
| 1017 | case I2OEVTGET: |
| 1018 | ret = i2o_cfg_evt_get(arg, fp); |
| 1019 | break; |
| 1020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | case I2OPASSTHRU: |
| 1022 | ret = i2o_cfg_passthru(arg); |
| 1023 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | default: |
| 1026 | osm_debug("unknown ioctl called!\n"); |
| 1027 | ret = -EINVAL; |
| 1028 | } |
| 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | static int cfg_open(struct inode *inode, struct file *file) |
| 1034 | { |
| 1035 | struct i2o_cfg_info *tmp = |
| 1036 | (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info), |
| 1037 | GFP_KERNEL); |
| 1038 | unsigned long flags; |
| 1039 | |
| 1040 | if (!tmp) |
| 1041 | return -ENOMEM; |
| 1042 | |
| 1043 | file->private_data = (void *)(i2o_cfg_info_id++); |
| 1044 | tmp->fp = file; |
| 1045 | tmp->fasync = NULL; |
| 1046 | tmp->q_id = (ulong) file->private_data; |
| 1047 | tmp->q_len = 0; |
| 1048 | tmp->q_in = 0; |
| 1049 | tmp->q_out = 0; |
| 1050 | tmp->q_lost = 0; |
| 1051 | tmp->next = open_files; |
| 1052 | |
| 1053 | spin_lock_irqsave(&i2o_config_lock, flags); |
| 1054 | open_files = tmp; |
| 1055 | spin_unlock_irqrestore(&i2o_config_lock, flags); |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | static int cfg_fasync(int fd, struct file *fp, int on) |
| 1061 | { |
| 1062 | ulong id = (ulong) fp->private_data; |
| 1063 | struct i2o_cfg_info *p; |
| 1064 | |
| 1065 | for (p = open_files; p; p = p->next) |
| 1066 | if (p->q_id == id) |
| 1067 | break; |
| 1068 | |
| 1069 | if (!p) |
| 1070 | return -EBADF; |
| 1071 | |
| 1072 | return fasync_helper(fd, fp, on, &p->fasync); |
| 1073 | } |
| 1074 | |
| 1075 | static int cfg_release(struct inode *inode, struct file *file) |
| 1076 | { |
| 1077 | ulong id = (ulong) file->private_data; |
| 1078 | struct i2o_cfg_info *p1, *p2; |
| 1079 | unsigned long flags; |
| 1080 | |
| 1081 | lock_kernel(); |
| 1082 | p1 = p2 = NULL; |
| 1083 | |
| 1084 | spin_lock_irqsave(&i2o_config_lock, flags); |
| 1085 | for (p1 = open_files; p1;) { |
| 1086 | if (p1->q_id == id) { |
| 1087 | |
| 1088 | if (p1->fasync) |
| 1089 | cfg_fasync(-1, file, 0); |
| 1090 | if (p2) |
| 1091 | p2->next = p1->next; |
| 1092 | else |
| 1093 | open_files = p1->next; |
| 1094 | |
| 1095 | kfree(p1); |
| 1096 | break; |
| 1097 | } |
| 1098 | p2 = p1; |
| 1099 | p1 = p1->next; |
| 1100 | } |
| 1101 | spin_unlock_irqrestore(&i2o_config_lock, flags); |
| 1102 | unlock_kernel(); |
| 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static struct file_operations config_fops = { |
| 1108 | .owner = THIS_MODULE, |
| 1109 | .llseek = no_llseek, |
| 1110 | .ioctl = i2o_cfg_ioctl, |
| f4c2c15 | 2005-04-10 22:29:42 -0500 | [diff] [blame] | 1111 | #ifdef CONFIG_COMPAT |
| 1112 | .compat_ioctl = i2o_cfg_compat_ioctl, |
| 1113 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | .open = cfg_open, |
| 1115 | .release = cfg_release, |
| 1116 | .fasync = cfg_fasync, |
| 1117 | }; |
| 1118 | |
| 1119 | static struct miscdevice i2o_miscdev = { |
| 1120 | I2O_MINOR, |
| 1121 | "i2octl", |
| 1122 | &config_fops |
| 1123 | }; |
| 1124 | |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame^] | 1125 | static int __init i2o_config_old_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | spin_lock_init(&i2o_config_lock); |
| 1128 | |
| 1129 | if (misc_register(&i2o_miscdev) < 0) { |
| 1130 | osm_err("can't register device.\n"); |
| 1131 | return -EBUSY; |
| 1132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | return 0; |
| 1134 | } |
| 1135 | |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame^] | 1136 | static void i2o_config_old_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | misc_deregister(&i2o_miscdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | MODULE_AUTHOR("Red Hat Software"); |