[PATCH] x86_64: CPU hotplug sibling map cleanup
[linux/fpc-iii.git] / drivers / message / i2o / config-osm.c
blobd0267609a94948c777fdbdafe111823b2984ab8c
1 /*
2 * Configuration OSM
4 * Copyright (C) 2005 Markus Lidel <Markus.Lidel@shadowconnect.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * Fixes/additions:
12 * Markus Lidel <Markus.Lidel@shadowconnect.com>
13 * initial version.
16 #include <linux/module.h>
17 #include <linux/i2o.h>
18 #include <linux/namei.h>
20 #include <asm/uaccess.h>
22 #define OSM_NAME "config-osm"
23 #define OSM_VERSION "1.248"
24 #define OSM_DESCRIPTION "I2O Configuration OSM"
26 /* access mode user rw */
27 #define S_IWRSR (S_IRUSR | S_IWUSR)
29 static struct i2o_driver i2o_config_driver;
31 /* Special file operations for sysfs */
32 struct fops_attribute {
33 struct bin_attribute bin;
34 struct file_operations fops;
37 /**
38 * sysfs_read_dummy
40 static ssize_t sysfs_read_dummy(struct kobject *kobj, char *buf, loff_t offset,
41 size_t count)
43 return 0;
46 /**
47 * sysfs_write_dummy
49 static ssize_t sysfs_write_dummy(struct kobject *kobj, char *buf, loff_t offset,
50 size_t count)
52 return 0;
55 /**
56 * sysfs_create_fops_file - Creates attribute with special file operations
57 * @kobj: kobject which should contains the attribute
58 * @attr: attributes which should be used to create file
60 * First creates attribute @attr in kobject @kobj. If it is the first time
61 * this function is called, merge old fops from sysfs with new one and
62 * write it back. Afterwords the new fops will be set for the created
63 * attribute.
65 * Returns 0 on success or negative error code on failure.
67 static int sysfs_create_fops_file(struct kobject *kobj,
68 struct fops_attribute *attr)
70 struct file_operations tmp, *fops;
71 struct dentry *d;
72 struct qstr qstr;
73 int rc;
75 fops = &attr->fops;
77 if (fops->read)
78 attr->bin.read = sysfs_read_dummy;
80 if (fops->write)
81 attr->bin.write = sysfs_write_dummy;
83 if ((rc = sysfs_create_bin_file(kobj, &attr->bin)))
84 return rc;
86 qstr.name = attr->bin.attr.name;
87 qstr.len = strlen(qstr.name);
88 qstr.hash = full_name_hash(qstr.name, qstr.len);
90 if ((d = lookup_hash(&qstr, kobj->dentry))) {
91 if (!fops->owner) {
92 memcpy(&tmp, d->d_inode->i_fop, sizeof(tmp));
93 if (fops->read)
94 tmp.read = fops->read;
95 if (fops->write)
96 tmp.write = fops->write;
97 memcpy(fops, &tmp, sizeof(tmp));
100 d->d_inode->i_fop = fops;
101 } else
102 sysfs_remove_bin_file(kobj, &attr->bin);
104 return -ENOENT;
108 * sysfs_remove_fops_file - Remove attribute with special file operations
109 * @kobj: kobject which contains the attribute
110 * @attr: attributes which are used to create file
112 * Only wrapper arround sysfs_remove_bin_file()
114 * Returns 0 on success or negative error code on failure.
116 static inline int sysfs_remove_fops_file(struct kobject *kobj,
117 struct fops_attribute *attr)
119 return sysfs_remove_bin_file(kobj, &attr->bin);
123 * i2o_config_read_hrt - Returns the HRT of the controller
124 * @kob: kernel object handle
125 * @buf: buffer into which the HRT should be copied
126 * @off: file offset
127 * @count: number of bytes to read
129 * Put @count bytes starting at @off into @buf from the HRT of the I2O
130 * controller corresponding to @kobj.
132 * Returns number of bytes copied into buffer.
134 static ssize_t i2o_config_read_hrt(struct kobject *kobj, char *buf,
135 loff_t offset, size_t count)
137 struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
138 i2o_hrt *hrt = c->hrt.virt;
140 u32 size = (hrt->num_entries * hrt->entry_len + 2) * 4;
142 if (offset > size)
143 return 0;
145 if (offset + count > size)
146 count = size - offset;
148 memcpy(buf, (u8 *) hrt + offset, count);
150 return count;
154 * i2o_config_read_lct - Returns the LCT of the controller
155 * @kob: kernel object handle
156 * @buf: buffer into which the LCT should be copied
157 * @off: file offset
158 * @count: number of bytes to read
160 * Put @count bytes starting at @off into @buf from the LCT of the I2O
161 * controller corresponding to @kobj.
163 * Returns number of bytes copied into buffer.
165 static ssize_t i2o_config_read_lct(struct kobject *kobj, char *buf,
166 loff_t offset, size_t count)
168 struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
169 u32 size = c->lct->table_size * 4;
171 if (offset > size)
172 return 0;
174 if (offset + count > size)
175 count = size - offset;
177 memcpy(buf, (u8 *) c->lct + offset, count);
179 return count;
182 #define I2O_CONFIG_SW_ATTR(_name,_mode,_type,_swid) \
183 static ssize_t i2o_config_##_name##_read(struct file *file, char __user *buf, size_t count, loff_t * offset) { \
184 return i2o_config_sw_read(file, buf, count, offset, _type, _swid); \
187 static ssize_t i2o_config_##_name##_write(struct file *file, const char __user *buf, size_t count, loff_t * offset) { \
188 return i2o_config_sw_write(file, buf, count, offset, _type, _swid); \
189 }; \
191 static struct fops_attribute i2o_config_attr_##_name = { \
192 .bin = { .attr = { .name = __stringify(_name), .mode = _mode, \
193 .owner = THIS_MODULE }, \
194 .size = 0, }, \
195 .fops = { .write = i2o_config_##_name##_write, \
196 .read = i2o_config_##_name##_read} \
199 #ifdef CONFIG_I2O_EXT_ADAPTEC
202 * i2o_config_dpt_reagion - Converts type and id to flash region
203 * @swtype: type of software module reading
204 * @swid: id of software which should be read
206 * Converts type and id from I2O spec to the matching region for DPT /
207 * Adaptec controllers.
209 * Returns region which match type and id or -1 on error.
211 static u32 i2o_config_dpt_region(u8 swtype, u8 swid)
213 switch (swtype) {
214 case I2O_SOFTWARE_MODULE_IRTOS:
216 * content: operation firmware
217 * region size:
218 * 0xbc000 for 2554, 3754, 2564, 3757
219 * 0x170000 for 2865
220 * 0x17c000 for 3966
222 if (!swid)
223 return 0;
225 break;
227 case I2O_SOFTWARE_MODULE_IOP_PRIVATE:
229 * content: BIOS and SMOR
230 * BIOS size: first 0x8000 bytes
231 * region size:
232 * 0x40000 for 2554, 3754, 2564, 3757
233 * 0x80000 for 2865, 3966
235 if (!swid)
236 return 1;
238 break;
240 case I2O_SOFTWARE_MODULE_IOP_CONFIG:
241 switch (swid) {
242 case 0:
244 * content: NVRAM defaults
245 * region size: 0x2000 bytes
247 return 2;
248 case 1:
250 * content: serial number
251 * region size: 0x2000 bytes
253 return 3;
255 break;
258 return -1;
261 #endif
264 * i2o_config_sw_read - Read a software module from controller
265 * @file: file pointer
266 * @buf: buffer into which the data should be copied
267 * @count: number of bytes to read
268 * @off: file offset
269 * @swtype: type of software module reading
270 * @swid: id of software which should be read
272 * Transfers @count bytes at offset @offset from IOP into buffer using
273 * type @swtype and id @swid as described in I2O spec.
275 * Returns number of bytes copied into buffer or error code on failure.
277 static ssize_t i2o_config_sw_read(struct file *file, char __user * buf,
278 size_t count, loff_t * offset, u8 swtype,
279 u32 swid)
281 struct sysfs_dirent *sd = file->f_dentry->d_parent->d_fsdata;
282 struct kobject *kobj = sd->s_element;
283 struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
284 u32 m, function = I2O_CMD_SW_UPLOAD;
285 struct i2o_dma buffer;
286 struct i2o_message __iomem *msg;
287 u32 __iomem *mptr;
288 int rc, status;
290 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
291 if (m == I2O_QUEUE_EMPTY)
292 return -EBUSY;
294 mptr = &msg->body[3];
296 if ((rc = i2o_dma_alloc(&c->pdev->dev, &buffer, count, GFP_KERNEL))) {
297 i2o_msg_nop(c, m);
298 return rc;
300 #ifdef CONFIG_I2O_EXT_ADAPTEC
301 if (c->adaptec) {
302 mptr = &msg->body[4];
303 function = I2O_CMD_PRIVATE;
305 writel(TEN_WORD_MSG_SIZE | SGL_OFFSET_8, &msg->u.head[0]);
307 writel(I2O_VENDOR_DPT << 16 | I2O_DPT_FLASH_READ,
308 &msg->body[0]);
309 writel(i2o_config_dpt_region(swtype, swid), &msg->body[1]);
310 writel(*offset, &msg->body[2]);
311 writel(count, &msg->body[3]);
312 } else
313 #endif
314 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
316 writel(0xD0000000 | count, mptr++);
317 writel(buffer.phys, mptr);
319 writel(function << 24 | HOST_TID << 12 | ADAPTER_TID, &msg->u.head[1]);
320 writel(i2o_config_driver.context, &msg->u.head[2]);
321 writel(0, &msg->u.head[3]);
323 #ifdef CONFIG_I2O_EXT_ADAPTEC
324 if (!c->adaptec)
325 #endif
327 writel((u32) swtype << 16 | (u32) 1 << 8, &msg->body[0]);
328 writel(0, &msg->body[1]);
329 writel(swid, &msg->body[2]);
332 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
334 if (status == I2O_POST_WAIT_OK) {
335 if (!(rc = copy_to_user(buf, buffer.virt, count))) {
336 rc = count;
337 *offset += count;
339 } else
340 rc = -EIO;
342 if (status != -ETIMEDOUT)
343 i2o_dma_free(&c->pdev->dev, &buffer);
345 return rc;
349 * i2o_config_sw_write - Write a software module to controller
350 * @file: file pointer
351 * @buf: buffer into which the data should be copied
352 * @count: number of bytes to read
353 * @off: file offset
354 * @swtype: type of software module writing
355 * @swid: id of software which should be written
357 * Transfers @count bytes at offset @offset from buffer to IOP using
358 * type @swtype and id @swid as described in I2O spec.
360 * Returns number of bytes copied from buffer or error code on failure.
362 static ssize_t i2o_config_sw_write(struct file *file, const char __user * buf,
363 size_t count, loff_t * offset, u8 swtype,
364 u32 swid)
366 struct sysfs_dirent *sd = file->f_dentry->d_parent->d_fsdata;
367 struct kobject *kobj = sd->s_element;
368 struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
369 u32 m, function = I2O_CMD_SW_DOWNLOAD;
370 struct i2o_dma buffer;
371 struct i2o_message __iomem *msg;
372 u32 __iomem *mptr;
373 int rc, status;
375 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
376 if (m == I2O_QUEUE_EMPTY)
377 return -EBUSY;
379 mptr = &msg->body[3];
381 if ((rc = i2o_dma_alloc(&c->pdev->dev, &buffer, count, GFP_KERNEL)))
382 goto nop_msg;
384 if ((rc = copy_from_user(buffer.virt, buf, count)))
385 goto free_buffer;
387 #ifdef CONFIG_I2O_EXT_ADAPTEC
388 if (c->adaptec) {
389 mptr = &msg->body[4];
390 function = I2O_CMD_PRIVATE;
392 writel(TEN_WORD_MSG_SIZE | SGL_OFFSET_8, &msg->u.head[0]);
394 writel(I2O_VENDOR_DPT << 16 | I2O_DPT_FLASH_WRITE,
395 &msg->body[0]);
396 writel(i2o_config_dpt_region(swtype, swid), &msg->body[1]);
397 writel(*offset, &msg->body[2]);
398 writel(count, &msg->body[3]);
399 } else
400 #endif
401 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
403 writel(0xD4000000 | count, mptr++);
404 writel(buffer.phys, mptr);
406 writel(function << 24 | HOST_TID << 12 | ADAPTER_TID, &msg->u.head[1]);
407 writel(i2o_config_driver.context, &msg->u.head[2]);
408 writel(0, &msg->u.head[3]);
410 #ifdef CONFIG_I2O_EXT_ADAPTEC
411 if (!c->adaptec)
412 #endif
414 writel((u32) swtype << 16 | (u32) 1 << 8, &msg->body[0]);
415 writel(0, &msg->body[1]);
416 writel(swid, &msg->body[2]);
419 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
421 if (status != -ETIMEDOUT)
422 i2o_dma_free(&c->pdev->dev, &buffer);
424 if (status != I2O_POST_WAIT_OK)
425 return -EIO;
427 *offset += count;
429 return count;
431 free_buffer:
432 i2o_dma_free(&c->pdev->dev, &buffer);
434 nop_msg:
435 i2o_msg_nop(c, m);
437 return rc;
440 /* attribute for HRT in sysfs */
441 static struct bin_attribute i2o_config_hrt_attr = {
442 .attr = {
443 .name = "hrt",
444 .mode = S_IRUGO,
445 .owner = THIS_MODULE},
446 .size = 0,
447 .read = i2o_config_read_hrt
450 /* attribute for LCT in sysfs */
451 static struct bin_attribute i2o_config_lct_attr = {
452 .attr = {
453 .name = "lct",
454 .mode = S_IRUGO,
455 .owner = THIS_MODULE},
456 .size = 0,
457 .read = i2o_config_read_lct
460 /* IRTOS firmware access */
461 I2O_CONFIG_SW_ATTR(irtos, S_IWRSR, I2O_SOFTWARE_MODULE_IRTOS, 0);
463 #ifdef CONFIG_I2O_EXT_ADAPTEC
466 * attribute for BIOS / SMOR, nvram and serial number access on DPT / Adaptec
467 * controllers
469 I2O_CONFIG_SW_ATTR(bios, S_IWRSR, I2O_SOFTWARE_MODULE_IOP_PRIVATE, 0);
470 I2O_CONFIG_SW_ATTR(nvram, S_IWRSR, I2O_SOFTWARE_MODULE_IOP_CONFIG, 0);
471 I2O_CONFIG_SW_ATTR(serial, S_IWRSR, I2O_SOFTWARE_MODULE_IOP_CONFIG, 1);
473 #endif
476 * i2o_config_notify_controller_add - Notify of added controller
477 * @c: the controller which was added
479 * If a I2O controller is added, we catch the notification to add sysfs
480 * entries.
482 static void i2o_config_notify_controller_add(struct i2o_controller *c)
484 struct kobject *kobj = &c->exec->device.kobj;
486 sysfs_create_bin_file(kobj, &i2o_config_hrt_attr);
487 sysfs_create_bin_file(kobj, &i2o_config_lct_attr);
489 sysfs_create_fops_file(kobj, &i2o_config_attr_irtos);
490 #ifdef CONFIG_I2O_EXT_ADAPTEC
491 if (c->adaptec) {
492 sysfs_create_fops_file(kobj, &i2o_config_attr_bios);
493 sysfs_create_fops_file(kobj, &i2o_config_attr_nvram);
494 sysfs_create_fops_file(kobj, &i2o_config_attr_serial);
496 #endif
500 * i2o_config_notify_controller_remove - Notify of removed controller
501 * @c: the controller which was removed
503 * If a I2O controller is removed, we catch the notification to remove the
504 * sysfs entries.
506 static void i2o_config_notify_controller_remove(struct i2o_controller *c)
508 struct kobject *kobj = &c->exec->device.kobj;
510 #ifdef CONFIG_I2O_EXT_ADAPTEC
511 if (c->adaptec) {
512 sysfs_remove_fops_file(kobj, &i2o_config_attr_serial);
513 sysfs_remove_fops_file(kobj, &i2o_config_attr_nvram);
514 sysfs_remove_fops_file(kobj, &i2o_config_attr_bios);
516 #endif
517 sysfs_remove_fops_file(kobj, &i2o_config_attr_irtos);
519 sysfs_remove_bin_file(kobj, &i2o_config_lct_attr);
520 sysfs_remove_bin_file(kobj, &i2o_config_hrt_attr);
523 /* Config OSM driver struct */
524 static struct i2o_driver i2o_config_driver = {
525 .name = OSM_NAME,
526 .notify_controller_add = i2o_config_notify_controller_add,
527 .notify_controller_remove = i2o_config_notify_controller_remove
530 #ifdef CONFIG_I2O_CONFIG_OLD_IOCTL
531 #include "i2o_config.c"
532 #endif
535 * i2o_config_init - Configuration OSM initialization function
537 * Registers Configuration OSM in the I2O core and if old ioctl's are
538 * compiled in initialize them.
540 * Returns 0 on success or negative error code on failure.
542 static int __init i2o_config_init(void)
544 printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
546 if (i2o_driver_register(&i2o_config_driver)) {
547 osm_err("handler register failed.\n");
548 return -EBUSY;
550 #ifdef CONFIG_I2O_CONFIG_OLD_IOCTL
551 if (i2o_config_old_init())
552 i2o_driver_unregister(&i2o_config_driver);
553 #endif
555 return 0;
559 * i2o_config_exit - Configuration OSM exit function
561 * If old ioctl's are compiled in exit remove them and unregisters
562 * Configuration OSM from I2O core.
564 static void i2o_config_exit(void)
566 #ifdef CONFIG_I2O_CONFIG_OLD_IOCTL
567 i2o_config_old_exit();
568 #endif
570 i2o_driver_unregister(&i2o_config_driver);
573 MODULE_AUTHOR("Markus Lidel <Markus.Lidel@shadowconnect.com>");
574 MODULE_LICENSE("GPL");
575 MODULE_DESCRIPTION(OSM_DESCRIPTION);
576 MODULE_VERSION(OSM_VERSION);
578 module_init(i2o_config_init);
579 module_exit(i2o_config_exit);