i2o_config.c 26.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * I2O Configuration Interface Driver
 *
 * (C) Copyright 1999-2002  Red Hat
 *
 * Written by Alan Cox, Building Number Three Ltd
 *
 * Fixes/additions:
 *	Deepak Saxena (04/20/1999):
 *		Added basic ioctl() support
 *	Deepak Saxena (06/07/1999):
 *		Added software download ioctl (still testing)
13
 *	Auvo Häkkinen (09/10/1999):
L
Linus Torvalds 已提交
14 15
 *		Changes to i2o_cfg_reply(), ioctl_parms()
 *		Added ioct_validate()
16
 *	Taneli Vähäkangas (09/30/1999):
L
Linus Torvalds 已提交
17
 *		Fixed ioctl_swdl()
18
 *	Taneli Vähäkangas (10/04/1999):
L
Linus Torvalds 已提交
19 20 21
 *		Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel()
 *	Deepak Saxena (11/18/1999):
 *		Added event managmenet support
A
Alan Cox 已提交
22
 *	Alan Cox <alan@lxorguk.ukuu.org.uk>:
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31 32 33
 *		2.4 rewrite ported to 2.5
 *	Markus Lidel <Markus.Lidel@shadowconnect.com>:
 *		Added pass-thru support for Adaptec's raidutils
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/miscdevice.h>
34
#include <linux/mutex.h>
L
Linus Torvalds 已提交
35
#include <linux/compat.h>
36
#include <linux/slab.h>
L
Linus Torvalds 已提交
37 38 39

#include <asm/uaccess.h>

40
#include "core.h"
L
Linus Torvalds 已提交
41

42
#define SG_TABLESIZE		30
M
Markus Lidel 已提交
43

44
static DEFINE_MUTEX(i2o_cfg_mutex);
45
static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long);
已提交
46

L
Linus Torvalds 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
static spinlock_t i2o_config_lock;

#define MODINC(x,y) ((x) = ((x) + 1) % (y))

struct sg_simple_element {
	u32 flag_count;
	u32 addr_bus;
};

struct i2o_cfg_info {
	struct file *fp;
	struct fasync_struct *fasync;
	struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
	u16 q_in;		// Queue head index
	u16 q_out;		// Queue tail index
	u16 q_len;		// Queue length
	u16 q_lost;		// Number of lost events
	ulong q_id;		// Event queue ID...used as tx_context
	struct i2o_cfg_info *next;
};
static struct i2o_cfg_info *open_files = NULL;
static ulong i2o_cfg_info_id = 0;

static int i2o_cfg_getiops(unsigned long arg)
{
	struct i2o_controller *c;
	u8 __user *user_iop_table = (void __user *)arg;
	u8 tmp[MAX_I2O_CONTROLLERS];
	int ret = 0;

	memset(tmp, 0, MAX_I2O_CONTROLLERS);

	list_for_each_entry(c, &i2o_controllers, list)
	    tmp[c->unit] = 1;

	if (copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS))
		ret = -EFAULT;

	return ret;
};

static int i2o_cfg_gethrt(unsigned long arg)
{
	struct i2o_controller *c;
	struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
	struct i2o_cmd_hrtlct kcmd;
	i2o_hrt *hrt;
	int len;
	u32 reslen;
	int ret = 0;

	if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
		return -EFAULT;

	if (get_user(reslen, kcmd.reslen) < 0)
		return -EFAULT;

	if (kcmd.resbuf == NULL)
		return -EFAULT;

	c = i2o_find_iop(kcmd.iop);
	if (!c)
		return -ENXIO;

	hrt = (i2o_hrt *) c->hrt.virt;

	len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);

115 116 117
	if (put_user(len, kcmd.reslen))
		ret = -EFAULT;
	else if (len > reslen)
L
Linus Torvalds 已提交
118
		ret = -ENOBUFS;
119
	else if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
L
Linus Torvalds 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
		ret = -EFAULT;

	return ret;
};

static int i2o_cfg_getlct(unsigned long arg)
{
	struct i2o_controller *c;
	struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
	struct i2o_cmd_hrtlct kcmd;
	i2o_lct *lct;
	int len;
	int ret = 0;
	u32 reslen;

	if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
		return -EFAULT;

	if (get_user(reslen, kcmd.reslen) < 0)
		return -EFAULT;

	if (kcmd.resbuf == NULL)
		return -EFAULT;

	c = i2o_find_iop(kcmd.iop);
	if (!c)
		return -ENXIO;

	lct = (i2o_lct *) c->lct;

	len = (unsigned int)lct->table_size << 2;
151 152 153
	if (put_user(len, kcmd.reslen))
		ret = -EFAULT;
	else if (len > reslen)
L
Linus Torvalds 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
		ret = -ENOBUFS;
	else if (copy_to_user(kcmd.resbuf, lct, len))
		ret = -EFAULT;

	return ret;
};

static int i2o_cfg_parms(unsigned long arg, unsigned int type)
{
	int ret = 0;
	struct i2o_controller *c;
	struct i2o_device *dev;
	struct i2o_cmd_psetget __user *cmd =
	    (struct i2o_cmd_psetget __user *)arg;
	struct i2o_cmd_psetget kcmd;
	u32 reslen;
	u8 *ops;
	u8 *res;
	int len = 0;

	u32 i2o_cmd = (type == I2OPARMGET ?
		       I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);

	if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
		return -EFAULT;

	if (get_user(reslen, kcmd.reslen))
		return -EFAULT;

	c = i2o_find_iop(kcmd.iop);
	if (!c)
		return -ENXIO;

	dev = i2o_iop_find_device(c, kcmd.tid);
	if (!dev)
		return -ENXIO;

191
	/*
192
	 * Stop users being able to try and allocate arbitrary amounts
193 194 195 196 197
	 * of DMA space. 64K is way more than sufficient for this.
	 */
	if (kcmd.oplen > 65536)
		return -EMSGSIZE;

198 199 200
	ops = memdup_user(kcmd.opbuf, kcmd.oplen);
	if (IS_ERR(ops))
		return PTR_ERR(ops);
L
Linus Torvalds 已提交
201 202 203 204 205

	/*
	 * It's possible to have a _very_ large table
	 * and that the user asks for all of it at once...
	 */
206
	res = kmalloc(65536, GFP_KERNEL);
L
Linus Torvalds 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219
	if (!res) {
		kfree(ops);
		return -ENOMEM;
	}

	len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
	kfree(ops);

	if (len < 0) {
		kfree(res);
		return -EAGAIN;
	}

220 221 222
	if (put_user(len, kcmd.reslen))
		ret = -EFAULT;
	else if (len > reslen)
L
Linus Torvalds 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
		ret = -ENOBUFS;
	else if (copy_to_user(kcmd.resbuf, res, len))
		ret = -EFAULT;

	kfree(res);

	return ret;
};

static int i2o_cfg_swdl(unsigned long arg)
{
	struct i2o_sw_xfer kxfer;
	struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
	unsigned char maxfrag = 0, curfrag = 1;
	struct i2o_dma buffer;
238
	struct i2o_message *msg;
L
Linus Torvalds 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
	unsigned int status = 0, swlen = 0, fragsize = 8192;
	struct i2o_controller *c;

	if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
		return -EFAULT;

	if (get_user(swlen, kxfer.swlen) < 0)
		return -EFAULT;

	if (get_user(maxfrag, kxfer.maxfrag) < 0)
		return -EFAULT;

	if (get_user(curfrag, kxfer.curfrag) < 0)
		return -EFAULT;

	if (curfrag == maxfrag)
		fragsize = swlen - (maxfrag - 1) * 8192;

	if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
		return -EFAULT;

	c = i2o_find_iop(kxfer.iop);
	if (!c)
		return -ENXIO;

264 265 266
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);
L
Linus Torvalds 已提交
267

A
Alan Cox 已提交
268
	if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
269
		i2o_msg_nop(c, msg);
L
Linus Torvalds 已提交
270 271 272
		return -ENOMEM;
	}

273 274 275 276 277
	if (__copy_from_user(buffer.virt, kxfer.buf, fragsize)) {
		i2o_msg_nop(c, msg);
		i2o_dma_free(&c->pdev->dev, &buffer);
		return -EFAULT;
	}
L
Linus Torvalds 已提交
278

279 280 281 282 283 284 285 286 287 288 289 290 291 292
	msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
	msg->u.head[1] =
	    cpu_to_le32(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 |
			ADAPTER_TID);
	msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
	msg->u.head[3] = cpu_to_le32(0);
	msg->body[0] =
	    cpu_to_le32((((u32) kxfer.flags) << 24) | (((u32) kxfer.
							sw_type) << 16) |
			(((u32) maxfrag) << 8) | (((u32) curfrag)));
	msg->body[1] = cpu_to_le32(swlen);
	msg->body[2] = cpu_to_le32(kxfer.sw_id);
	msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
	msg->body[4] = cpu_to_le32(buffer.phys);
L
Linus Torvalds 已提交
293 294

	osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
295
	status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
L
Linus Torvalds 已提交
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315

	if (status != -ETIMEDOUT)
		i2o_dma_free(&c->pdev->dev, &buffer);

	if (status != I2O_POST_WAIT_OK) {
		// it fails if you try and send frags out of order
		// and for some yet unknown reasons too
		osm_info("swdl failed, DetailedStatus = %d\n", status);
		return status;
	}

	return 0;
};

static int i2o_cfg_swul(unsigned long arg)
{
	struct i2o_sw_xfer kxfer;
	struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
	unsigned char maxfrag = 0, curfrag = 1;
	struct i2o_dma buffer;
316
	struct i2o_message *msg;
L
Linus Torvalds 已提交
317 318 319 320 321
	unsigned int status = 0, swlen = 0, fragsize = 8192;
	struct i2o_controller *c;
	int ret = 0;

	if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
D
Dan Carpenter 已提交
322
		return -EFAULT;
L
Linus Torvalds 已提交
323 324

	if (get_user(swlen, kxfer.swlen) < 0)
D
Dan Carpenter 已提交
325
		return -EFAULT;
L
Linus Torvalds 已提交
326 327

	if (get_user(maxfrag, kxfer.maxfrag) < 0)
D
Dan Carpenter 已提交
328
		return -EFAULT;
L
Linus Torvalds 已提交
329 330

	if (get_user(curfrag, kxfer.curfrag) < 0)
D
Dan Carpenter 已提交
331
		return -EFAULT;
L
Linus Torvalds 已提交
332 333 334 335 336

	if (curfrag == maxfrag)
		fragsize = swlen - (maxfrag - 1) * 8192;

	if (!kxfer.buf)
D
Dan Carpenter 已提交
337
		return -EFAULT;
L
Linus Torvalds 已提交
338 339 340 341 342

	c = i2o_find_iop(kxfer.iop);
	if (!c)
		return -ENXIO;

343 344 345
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);
L
Linus Torvalds 已提交
346

A
Alan Cox 已提交
347
	if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
348
		i2o_msg_nop(c, msg);
L
Linus Torvalds 已提交
349 350 351
		return -ENOMEM;
	}

352 353 354 355 356 357 358 359 360 361 362 363
	msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
	msg->u.head[1] =
	    cpu_to_le32(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID);
	msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
	msg->u.head[3] = cpu_to_le32(0);
	msg->body[0] =
	    cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.
			sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag);
	msg->body[1] = cpu_to_le32(swlen);
	msg->body[2] = cpu_to_le32(kxfer.sw_id);
	msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
	msg->body[4] = cpu_to_le32(buffer.phys);
L
Linus Torvalds 已提交
364 365

	osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
366
	status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
L
Linus Torvalds 已提交
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381

	if (status != I2O_POST_WAIT_OK) {
		if (status != -ETIMEDOUT)
			i2o_dma_free(&c->pdev->dev, &buffer);

		osm_info("swul failed, DetailedStatus = %d\n", status);
		return status;
	}

	if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
		ret = -EFAULT;

	i2o_dma_free(&c->pdev->dev, &buffer);

	return ret;
D
Dan Carpenter 已提交
382
}
L
Linus Torvalds 已提交
383 384 385 386 387 388

static int i2o_cfg_swdel(unsigned long arg)
{
	struct i2o_controller *c;
	struct i2o_sw_xfer kxfer;
	struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
389
	struct i2o_message *msg;
L
Linus Torvalds 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402
	unsigned int swlen;
	int token;

	if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
		return -EFAULT;

	if (get_user(swlen, kxfer.swlen) < 0)
		return -EFAULT;

	c = i2o_find_iop(kxfer.iop);
	if (!c)
		return -ENXIO;

403 404 405
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);
L
Linus Torvalds 已提交
406

407 408 409 410 411 412 413 414 415
	msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
	msg->u.head[1] =
	    cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
	msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
	msg->u.head[3] = cpu_to_le32(0);
	msg->body[0] =
	    cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
	msg->body[1] = cpu_to_le32(swlen);
	msg->body[2] = cpu_to_le32(kxfer.sw_id);
L
Linus Torvalds 已提交
416

417
	token = i2o_msg_post_wait(c, msg, 10);
L
Linus Torvalds 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430

	if (token != I2O_POST_WAIT_OK) {
		osm_info("swdel failed, DetailedStatus = %d\n", token);
		return -ETIMEDOUT;
	}

	return 0;
};

static int i2o_cfg_validate(unsigned long arg)
{
	int token;
	int iop = (int)arg;
431
	struct i2o_message *msg;
L
Linus Torvalds 已提交
432 433 434 435 436 437
	struct i2o_controller *c;

	c = i2o_find_iop(iop);
	if (!c)
		return -ENXIO;

438 439 440
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);
L
Linus Torvalds 已提交
441

442 443 444 445 446
	msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
	msg->u.head[1] =
	    cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
	msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
	msg->u.head[3] = cpu_to_le32(0);
L
Linus Torvalds 已提交
447

448
	token = i2o_msg_post_wait(c, msg, 10);
L
Linus Torvalds 已提交
449 450 451 452 453 454 455 456 457 458 459 460

	if (token != I2O_POST_WAIT_OK) {
		osm_info("Can't validate configuration, ErrorStatus = %d\n",
			 token);
		return -ETIMEDOUT;
	}

	return 0;
};

static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
{
461
	struct i2o_message *msg;
L
Linus Torvalds 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
	struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
	struct i2o_evt_id kdesc;
	struct i2o_controller *c;
	struct i2o_device *d;

	if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
		return -EFAULT;

	/* IOP exists? */
	c = i2o_find_iop(kdesc.iop);
	if (!c)
		return -ENXIO;

	/* Device exists? */
	d = i2o_iop_find_device(c, kdesc.tid);
	if (!d)
		return -ENODEV;

480 481 482
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);
L
Linus Torvalds 已提交
483

484 485 486 487 488 489 490
	msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
	msg->u.head[1] =
	    cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
			kdesc.tid);
	msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
	msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
	msg->body[0] = cpu_to_le32(kdesc.evt_mask);
L
Linus Torvalds 已提交
491

492
	i2o_msg_post(c, msg);
L
Linus Torvalds 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524

	return 0;
}

static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
{
	struct i2o_cfg_info *p = NULL;
	struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
	struct i2o_evt_get kget;
	unsigned long flags;

	for (p = open_files; p; p = p->next)
		if (p->q_id == (ulong) fp->private_data)
			break;

	if (!p->q_len)
		return -ENOENT;

	memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
	MODINC(p->q_out, I2O_EVT_Q_LEN);
	spin_lock_irqsave(&i2o_config_lock, flags);
	p->q_len--;
	kget.pending = p->q_len;
	kget.lost = p->q_lost;
	spin_unlock_irqrestore(&i2o_config_lock, flags);

	if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
		return -EFAULT;
	return 0;
}

#ifdef CONFIG_COMPAT
525 526
static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
			      unsigned long arg)
L
Linus Torvalds 已提交
527 528 529 530 531 532 533 534 535 536 537 538 539
{
	struct i2o_cmd_passthru32 __user *cmd;
	struct i2o_controller *c;
	u32 __user *user_msg;
	u32 *reply = NULL;
	u32 __user *user_reply = NULL;
	u32 size = 0;
	u32 reply_size = 0;
	u32 rcode = 0;
	struct i2o_dma sg_list[SG_TABLESIZE];
	u32 sg_offset = 0;
	u32 sg_count = 0;
	u32 i = 0;
540
	u32 sg_index = 0;
L
Linus Torvalds 已提交
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
	i2o_status_block *sb;
	struct i2o_message *msg;
	unsigned int iop;

	cmd = (struct i2o_cmd_passthru32 __user *)arg;

	if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
		return -EFAULT;

	user_msg = compat_ptr(i);

	c = i2o_find_iop(iop);
	if (!c) {
		osm_debug("controller %d not found\n", iop);
		return -ENXIO;
	}

	sb = c->status_block.virt;

	if (get_user(size, &user_msg[0])) {
		osm_warn("unable to get size!\n");
		return -EFAULT;
	}
	size = size >> 16;

	if (size > sb->inbound_frame_size) {
		osm_warn("size of message > inbound_frame_size");
		return -EFAULT;
	}

	user_reply = &user_msg[size];

	size <<= 2;		// Convert to bytes

V
Vasily Averin 已提交
575 576 577 578 579
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);

	rcode = -EFAULT;
L
Linus Torvalds 已提交
580 581 582
	/* Copy in the user's I2O command */
	if (copy_from_user(msg, user_msg, size)) {
		osm_warn("unable to copy user message\n");
V
Vasily Averin 已提交
583
		goto out;
L
Linus Torvalds 已提交
584 585 586 587
	}
	i2o_dump_message(msg);

	if (get_user(reply_size, &user_reply[0]) < 0)
V
Vasily Averin 已提交
588
		goto out;
L
Linus Torvalds 已提交
589 590 591 592

	reply_size >>= 16;
	reply_size <<= 2;

V
Vasily Averin 已提交
593
	rcode = -ENOMEM;
M
Markus Lidel 已提交
594
	reply = kzalloc(reply_size, GFP_KERNEL);
L
Linus Torvalds 已提交
595 596 597
	if (!reply) {
		printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
		       c->name);
V
Vasily Averin 已提交
598
		goto out;
L
Linus Torvalds 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
	}

	sg_offset = (msg->u.head[0] >> 4) & 0x0f;

	memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
	if (sg_offset) {
		struct sg_simple_element *sg;

		if (sg_offset * 4 >= size) {
			rcode = -EFAULT;
			goto cleanup;
		}
		// TODO 64bit fix
		sg = (struct sg_simple_element *)((&msg->u.head[0]) +
						  sg_offset);
		sg_count =
		    (size - sg_offset * 4) / sizeof(struct sg_simple_element);
		if (sg_count > SG_TABLESIZE) {
			printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
			       c->name, sg_count);
619 620
			rcode = -EINVAL;
			goto cleanup;
L
Linus Torvalds 已提交
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
		}

		for (i = 0; i < sg_count; i++) {
			int sg_size;
			struct i2o_dma *p;

			if (!(sg[i].flag_count & 0x10000000
			      /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
				printk(KERN_DEBUG
				       "%s:Bad SG element %d - not simple (%x)\n",
				       c->name, i, sg[i].flag_count);
				rcode = -EINVAL;
				goto cleanup;
			}
			sg_size = sg[i].flag_count & 0xffffff;
M
Markus Lidel 已提交
636
			p = &(sg_list[sg_index]);
L
Linus Torvalds 已提交
637
			/* Allocate memory for the transfer */
A
Alan Cox 已提交
638
			if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
L
Linus Torvalds 已提交
639 640 641 642
				printk(KERN_DEBUG
				       "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
				       c->name, sg_size, i, sg_count);
				rcode = -ENOMEM;
643
				goto sg_list_cleanup;
L
Linus Torvalds 已提交
644
			}
M
Markus Lidel 已提交
645
			sg_index++;
L
Linus Torvalds 已提交
646 647 648 649 650
			/* Copy in the user's SG buffer if necessary */
			if (sg[i].
			    flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
				// TODO 64bit fix
				if (copy_from_user
651 652 653
				    (p->virt,
				     (void __user *)(unsigned long)sg[i].
				     addr_bus, sg_size)) {
L
Linus Torvalds 已提交
654 655 656 657
					printk(KERN_DEBUG
					       "%s: Could not copy SG buf %d FROM user\n",
					       c->name, i);
					rcode = -EFAULT;
658
					goto sg_list_cleanup;
L
Linus Torvalds 已提交
659 660 661 662 663 664 665
				}
			}
			//TODO 64bit fix
			sg[i].addr_bus = (u32) p->phys;
		}
	}

666
	rcode = i2o_msg_post_wait(c, msg, 60);
V
Vasily Averin 已提交
667
	msg = NULL;
M
Markus Lidel 已提交
668 669
	if (rcode) {
		reply[4] = ((u32) rcode) << 24;
670
		goto sg_list_cleanup;
M
Markus Lidel 已提交
671
	}
L
Linus Torvalds 已提交
672 673

	if (sg_offset) {
V
Vasily Averin 已提交
674
		u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
L
Linus Torvalds 已提交
675 676 677 678 679 680 681
		/* Copy back the Scatter Gather buffers back to user space */
		u32 j;
		// TODO 64bit fix
		struct sg_simple_element *sg;
		int sg_size;

		// re-acquire the original message to handle correctly the sg copy operation
V
Vasily Averin 已提交
682
		memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
L
Linus Torvalds 已提交
683 684 685
		// get user msg size in u32s
		if (get_user(size, &user_msg[0])) {
			rcode = -EFAULT;
686
			goto sg_list_cleanup;
L
Linus Torvalds 已提交
687 688 689
		}
		size = size >> 16;
		size *= 4;
690 691 692 693 694
		if (size > sizeof(rmsg)) {
			rcode = -EINVAL;
			goto sg_list_cleanup;
		}

L
Linus Torvalds 已提交
695
		/* Copy in the user's I2O command */
V
Vasily Averin 已提交
696
		if (copy_from_user(rmsg, user_msg, size)) {
L
Linus Torvalds 已提交
697
			rcode = -EFAULT;
698
			goto sg_list_cleanup;
L
Linus Torvalds 已提交
699 700 701 702 703
		}
		sg_count =
		    (size - sg_offset * 4) / sizeof(struct sg_simple_element);

		// TODO 64bit fix
V
Vasily Averin 已提交
704
		sg = (struct sg_simple_element *)(rmsg + sg_offset);
L
Linus Torvalds 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
		for (j = 0; j < sg_count; j++) {
			/* Copy out the SG list to user's buffer if necessary */
			if (!
			    (sg[j].
			     flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
				sg_size = sg[j].flag_count & 0xffffff;
				// TODO 64bit fix
				if (copy_to_user
				    ((void __user *)(u64) sg[j].addr_bus,
				     sg_list[j].virt, sg_size)) {
					printk(KERN_WARNING
					       "%s: Could not copy %p TO user %x\n",
					       c->name, sg_list[j].virt,
					       sg[j].addr_bus);
					rcode = -EFAULT;
720
					goto sg_list_cleanup;
L
Linus Torvalds 已提交
721 722 723 724 725
				}
			}
		}
	}

V
Vasily Averin 已提交
726
sg_list_cleanup:
L
Linus Torvalds 已提交
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
	/* Copy back the reply to user space */
	if (reply_size) {
		// we wrote our own values for context - now restore the user supplied ones
		if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
			printk(KERN_WARNING
			       "%s: Could not copy message context FROM user\n",
			       c->name);
			rcode = -EFAULT;
		}
		if (copy_to_user(user_reply, reply, reply_size)) {
			printk(KERN_WARNING
			       "%s: Could not copy reply TO user\n", c->name);
			rcode = -EFAULT;
		}
	}
742 743 744
	for (i = 0; i < sg_index; i++)
		i2o_dma_free(&c->pdev->dev, &sg_list[i]);

V
Vasily Averin 已提交
745
cleanup:
L
Linus Torvalds 已提交
746
	kfree(reply);
V
Vasily Averin 已提交
747 748 749
out:
	if (msg)
		i2o_msg_nop(c, msg);
L
Linus Torvalds 已提交
750 751 752
	return rcode;
}

753 754
static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
				 unsigned long arg)
已提交
755 756
{
	int ret;
757
	mutex_lock(&i2o_cfg_mutex);
758
	switch (cmd) {
已提交
759
	case I2OGETIOPS:
760
		ret = i2o_cfg_ioctl(file, cmd, arg);
已提交
761 762 763 764 765 766 767 768
		break;
	case I2OPASSTHRU32:
		ret = i2o_cfg_passthru32(file, cmd, arg);
		break;
	default:
		ret = -ENOIOCTLCMD;
		break;
	}
769
	mutex_unlock(&i2o_cfg_mutex);
已提交
770 771 772 773
	return ret;
}

#endif
L
Linus Torvalds 已提交
774

775
#ifdef CONFIG_I2O_EXT_ADAPTEC
L
Linus Torvalds 已提交
776 777 778 779 780 781 782 783 784 785 786
static int i2o_cfg_passthru(unsigned long arg)
{
	struct i2o_cmd_passthru __user *cmd =
	    (struct i2o_cmd_passthru __user *)arg;
	struct i2o_controller *c;
	u32 __user *user_msg;
	u32 *reply = NULL;
	u32 __user *user_reply = NULL;
	u32 size = 0;
	u32 reply_size = 0;
	u32 rcode = 0;
A
Alan Cox 已提交
787
	struct i2o_dma sg_list[SG_TABLESIZE];
L
Linus Torvalds 已提交
788 789 790 791 792
	u32 sg_offset = 0;
	u32 sg_count = 0;
	int sg_index = 0;
	u32 i = 0;
	i2o_status_block *sb;
793
	struct i2o_message *msg;
L
Linus Torvalds 已提交
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
	unsigned int iop;

	if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
		return -EFAULT;

	c = i2o_find_iop(iop);
	if (!c) {
		osm_warn("controller %d not found\n", iop);
		return -ENXIO;
	}

	sb = c->status_block.virt;

	if (get_user(size, &user_msg[0]))
		return -EFAULT;
	size = size >> 16;

	if (size > sb->inbound_frame_size) {
		osm_warn("size of message > inbound_frame_size");
		return -EFAULT;
	}

	user_reply = &user_msg[size];

	size <<= 2;		// Convert to bytes

V
Vasily Averin 已提交
820 821 822 823 824
	msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
	if (IS_ERR(msg))
		return PTR_ERR(msg);

	rcode = -EFAULT;
L
Linus Torvalds 已提交
825 826
	/* Copy in the user's I2O command */
	if (copy_from_user(msg, user_msg, size))
V
Vasily Averin 已提交
827
		goto out;
L
Linus Torvalds 已提交
828 829

	if (get_user(reply_size, &user_reply[0]) < 0)
V
Vasily Averin 已提交
830
		goto out;
L
Linus Torvalds 已提交
831 832 833 834

	reply_size >>= 16;
	reply_size <<= 2;

M
Markus Lidel 已提交
835
	reply = kzalloc(reply_size, GFP_KERNEL);
L
Linus Torvalds 已提交
836 837 838
	if (!reply) {
		printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
		       c->name);
V
Vasily Averin 已提交
839 840
		rcode = -ENOMEM;
		goto out;
L
Linus Torvalds 已提交
841 842 843 844 845 846 847
	}

	sg_offset = (msg->u.head[0] >> 4) & 0x0f;

	memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
	if (sg_offset) {
		struct sg_simple_element *sg;
A
Alan Cox 已提交
848
		struct i2o_dma *p;
L
Linus Torvalds 已提交
849 850 851 852 853 854 855 856 857 858 859 860 861

		if (sg_offset * 4 >= size) {
			rcode = -EFAULT;
			goto cleanup;
		}
		// TODO 64bit fix
		sg = (struct sg_simple_element *)((&msg->u.head[0]) +
						  sg_offset);
		sg_count =
		    (size - sg_offset * 4) / sizeof(struct sg_simple_element);
		if (sg_count > SG_TABLESIZE) {
			printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
			       c->name, sg_count);
862 863
			rcode = -EINVAL;
			goto cleanup;
L
Linus Torvalds 已提交
864 865 866 867 868 869 870 871 872 873 874
		}

		for (i = 0; i < sg_count; i++) {
			int sg_size;

			if (!(sg[i].flag_count & 0x10000000
			      /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
				printk(KERN_DEBUG
				       "%s:Bad SG element %d - not simple (%x)\n",
				       c->name, i, sg[i].flag_count);
				rcode = -EINVAL;
875
				goto sg_list_cleanup;
L
Linus Torvalds 已提交
876 877
			}
			sg_size = sg[i].flag_count & 0xffffff;
A
Alan Cox 已提交
878 879
			p = &(sg_list[sg_index]);
			if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
L
Linus Torvalds 已提交
880 881 882 883 884
			/* Allocate memory for the transfer */
				printk(KERN_DEBUG
				       "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
				       c->name, sg_size, i, sg_count);
				rcode = -ENOMEM;
885
				goto sg_list_cleanup;
L
Linus Torvalds 已提交
886
			}
A
Alan Cox 已提交
887
			sg_index++;
L
Linus Torvalds 已提交
888 889 890 891 892
			/* Copy in the user's SG buffer if necessary */
			if (sg[i].
			    flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
				// TODO 64bit fix
				if (copy_from_user
A
Alan Cox 已提交
893
				    (p->virt, (void __user *)sg[i].addr_bus,
L
Linus Torvalds 已提交
894 895 896 897 898
				     sg_size)) {
					printk(KERN_DEBUG
					       "%s: Could not copy SG buf %d FROM user\n",
					       c->name, i);
					rcode = -EFAULT;
899
					goto sg_list_cleanup;
L
Linus Torvalds 已提交
900 901
				}
			}
A
Alan Cox 已提交
902
			sg[i].addr_bus = p->phys;
L
Linus Torvalds 已提交
903 904 905
		}
	}

906
	rcode = i2o_msg_post_wait(c, msg, 60);
V
Vasily Averin 已提交
907
	msg = NULL;
M
Markus Lidel 已提交
908 909
	if (rcode) {
		reply[4] = ((u32) rcode) << 24;
910
		goto sg_list_cleanup;
M
Markus Lidel 已提交
911
	}
L
Linus Torvalds 已提交
912 913

	if (sg_offset) {
A
Alan Cox 已提交
914
		u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
L
Linus Torvalds 已提交
915 916 917 918 919 920 921
		/* Copy back the Scatter Gather buffers back to user space */
		u32 j;
		// TODO 64bit fix
		struct sg_simple_element *sg;
		int sg_size;

		// re-acquire the original message to handle correctly the sg copy operation
V
Vasily Averin 已提交
922
		memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
L
Linus Torvalds 已提交
923 924 925
		// get user msg size in u32s
		if (get_user(size, &user_msg[0])) {
			rcode = -EFAULT;
926
			goto sg_list_cleanup;
L
Linus Torvalds 已提交
927 928 929
		}
		size = size >> 16;
		size *= 4;
930 931 932 933 934
		if (size > sizeof(rmsg)) {
			rcode = -EFAULT;
			goto sg_list_cleanup;
		}

L
Linus Torvalds 已提交
935
		/* Copy in the user's I2O command */
V
Vasily Averin 已提交
936
		if (copy_from_user(rmsg, user_msg, size)) {
L
Linus Torvalds 已提交
937
			rcode = -EFAULT;
938
			goto sg_list_cleanup;
L
Linus Torvalds 已提交
939 940 941 942 943
		}
		sg_count =
		    (size - sg_offset * 4) / sizeof(struct sg_simple_element);

		// TODO 64bit fix
V
Vasily Averin 已提交
944
		sg = (struct sg_simple_element *)(rmsg + sg_offset);
L
Linus Torvalds 已提交
945 946 947 948 949 950 951 952
		for (j = 0; j < sg_count; j++) {
			/* Copy out the SG list to user's buffer if necessary */
			if (!
			    (sg[j].
			     flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
				sg_size = sg[j].flag_count & 0xffffff;
				// TODO 64bit fix
				if (copy_to_user
A
Alan Cox 已提交
953
				    ((void __user *)sg[j].addr_bus, sg_list[j].virt,
L
Linus Torvalds 已提交
954 955 956
				     sg_size)) {
					printk(KERN_WARNING
					       "%s: Could not copy %p TO user %x\n",
A
Alan Cox 已提交
957
					       c->name, sg_list[j].virt,
L
Linus Torvalds 已提交
958 959
					       sg[j].addr_bus);
					rcode = -EFAULT;
960
					goto sg_list_cleanup;
L
Linus Torvalds 已提交
961 962 963 964 965
				}
			}
		}
	}

V
Vasily Averin 已提交
966
sg_list_cleanup:
L
Linus Torvalds 已提交
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
	/* Copy back the reply to user space */
	if (reply_size) {
		// we wrote our own values for context - now restore the user supplied ones
		if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
			printk(KERN_WARNING
			       "%s: Could not copy message context FROM user\n",
			       c->name);
			rcode = -EFAULT;
		}
		if (copy_to_user(user_reply, reply, reply_size)) {
			printk(KERN_WARNING
			       "%s: Could not copy reply TO user\n", c->name);
			rcode = -EFAULT;
		}
	}

983
	for (i = 0; i < sg_index; i++)
A
Alan Cox 已提交
984
		i2o_dma_free(&c->pdev->dev, &sg_list[i]);
985

V
Vasily Averin 已提交
986
cleanup:
L
Linus Torvalds 已提交
987
	kfree(reply);
V
Vasily Averin 已提交
988 989 990
out:
	if (msg)
		i2o_msg_nop(c, msg);
L
Linus Torvalds 已提交
991 992
	return rcode;
}
993
#endif
L
Linus Torvalds 已提交
994 995 996 997

/*
 * IOCTL Handler
 */
998
static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
L
Linus Torvalds 已提交
999 1000 1001
{
	int ret;

1002
	mutex_lock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
	switch (cmd) {
	case I2OGETIOPS:
		ret = i2o_cfg_getiops(arg);
		break;

	case I2OHRTGET:
		ret = i2o_cfg_gethrt(arg);
		break;

	case I2OLCTGET:
		ret = i2o_cfg_getlct(arg);
		break;

	case I2OPARMSET:
		ret = i2o_cfg_parms(arg, I2OPARMSET);
		break;

	case I2OPARMGET:
		ret = i2o_cfg_parms(arg, I2OPARMGET);
		break;

	case I2OSWDL:
		ret = i2o_cfg_swdl(arg);
		break;

	case I2OSWUL:
		ret = i2o_cfg_swul(arg);
		break;

	case I2OSWDEL:
		ret = i2o_cfg_swdel(arg);
		break;

	case I2OVALIDATE:
		ret = i2o_cfg_validate(arg);
		break;

	case I2OEVTREG:
		ret = i2o_cfg_evt_reg(arg, fp);
		break;

	case I2OEVTGET:
		ret = i2o_cfg_evt_get(arg, fp);
		break;

1048
#ifdef CONFIG_I2O_EXT_ADAPTEC
L
Linus Torvalds 已提交
1049 1050 1051
	case I2OPASSTHRU:
		ret = i2o_cfg_passthru(arg);
		break;
1052
#endif
L
Linus Torvalds 已提交
1053 1054 1055 1056 1057

	default:
		osm_debug("unknown ioctl called!\n");
		ret = -EINVAL;
	}
1058
	mutex_unlock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1059 1060 1061 1062 1063
	return ret;
}

static int cfg_open(struct inode *inode, struct file *file)
{
1064
	struct i2o_cfg_info *tmp = kmalloc(sizeof(struct i2o_cfg_info),
L
Linus Torvalds 已提交
1065 1066 1067 1068 1069 1070
					   GFP_KERNEL);
	unsigned long flags;

	if (!tmp)
		return -ENOMEM;

1071
	mutex_lock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	file->private_data = (void *)(i2o_cfg_info_id++);
	tmp->fp = file;
	tmp->fasync = NULL;
	tmp->q_id = (ulong) file->private_data;
	tmp->q_len = 0;
	tmp->q_in = 0;
	tmp->q_out = 0;
	tmp->q_lost = 0;
	tmp->next = open_files;

	spin_lock_irqsave(&i2o_config_lock, flags);
	open_files = tmp;
	spin_unlock_irqrestore(&i2o_config_lock, flags);
1085
	mutex_unlock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1086 1087 1088 1089 1090 1091 1092 1093

	return 0;
}

static int cfg_fasync(int fd, struct file *fp, int on)
{
	ulong id = (ulong) fp->private_data;
	struct i2o_cfg_info *p;
J
Jonathan Corbet 已提交
1094
	int ret = -EBADF;
L
Linus Torvalds 已提交
1095

1096
	mutex_lock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1097 1098 1099 1100
	for (p = open_files; p; p = p->next)
		if (p->q_id == id)
			break;

J
Jonathan Corbet 已提交
1101 1102
	if (p)
		ret = fasync_helper(fd, fp, on, &p->fasync);
1103
	mutex_unlock(&i2o_cfg_mutex);
J
Jonathan Corbet 已提交
1104
	return ret;
L
Linus Torvalds 已提交
1105 1106 1107 1108 1109
}

static int cfg_release(struct inode *inode, struct file *file)
{
	ulong id = (ulong) file->private_data;
A
Al Viro 已提交
1110
	struct i2o_cfg_info *p, **q;
L
Linus Torvalds 已提交
1111 1112
	unsigned long flags;

1113
	mutex_lock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1114
	spin_lock_irqsave(&i2o_config_lock, flags);
A
Al Viro 已提交
1115 1116 1117 1118
	for (q = &open_files; (p = *q) != NULL; q = &p->next) {
		if (p->q_id == id) {
			*q = p->next;
			kfree(p);
L
Linus Torvalds 已提交
1119 1120 1121 1122
			break;
		}
	}
	spin_unlock_irqrestore(&i2o_config_lock, flags);
1123
	mutex_unlock(&i2o_cfg_mutex);
L
Linus Torvalds 已提交
1124 1125 1126 1127

	return 0;
}

1128
static const struct file_operations config_fops = {
L
Linus Torvalds 已提交
1129 1130
	.owner = THIS_MODULE,
	.llseek = no_llseek,
1131
	.unlocked_ioctl = i2o_cfg_ioctl,
已提交
1132 1133 1134
#ifdef CONFIG_COMPAT
	.compat_ioctl = i2o_cfg_compat_ioctl,
#endif
L
Linus Torvalds 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
	.open = cfg_open,
	.release = cfg_release,
	.fasync = cfg_fasync,
};

static struct miscdevice i2o_miscdev = {
	I2O_MINOR,
	"i2octl",
	&config_fops
};

1146
static int __init i2o_config_old_init(void)
L
Linus Torvalds 已提交
1147 1148 1149 1150 1151 1152 1153
{
	spin_lock_init(&i2o_config_lock);

	if (misc_register(&i2o_miscdev) < 0) {
		osm_err("can't register device.\n");
		return -EBUSY;
	}
1154

L
Linus Torvalds 已提交
1155 1156 1157
	return 0;
}

1158
static void i2o_config_old_exit(void)
L
Linus Torvalds 已提交
1159 1160 1161 1162 1163
{
	misc_deregister(&i2o_miscdev);
}

MODULE_AUTHOR("Red Hat Software");