Commit f10378ff authored by Markus Lidel's avatar Markus Lidel Committed by Linus Torvalds
Browse files

[PATCH] I2O: new sysfs attributes and Adaptec specific block device access and 64-bit DMA support



Changes:
 - Added Bus-OSM which could be used by user space programs to reset a
   channel on the controller
 - Make ioctl's in Config-OSM obsolete in prefer for sysfs attributes and
   move those to its own file
 - Added sysfs attribute for firmware read and write access for I2O
   controllers
 - Added special handling of firmware read and write access for Adaptec
   controllers
 - Added vendor id and product id as sysfs-attribute to Executive classes
 - Added automatic notification of LCT change handling to Exec-OSM
 - Added flushing function to Block-OSM for later barrier implementation
 - Use PRIVATE messages for Block access on Adaptec controllers, which are
   faster then BLOCK class access
 - Cleaned up support for Promise controller
 - New messages are now detected using the IRQ status register as
   suggested by the I2O spec
 - Added i2o_dma_high() and i2o_dma_low() functions
 - Added facility for SG tablesize calculation when using 32-bit and
   64-bit DMA addresses
 - Added i2o_dma_map_single() and i2o_dma_map_sg() which could build the
   SG list for 32-bit as well as 64-bit DMA addresses
Signed-off-by: default avatarMarkus Lidel <Markus.Lidel@shadowconnect.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f88e119c
......@@ -35,6 +35,24 @@ config I2O_CONFIG
To compile this support as a module, choose M here: the
module will be called i2o_config.
config I2O_CONFIG_OLD_IOCTL
bool "Enable ioctls (OBSOLETE)"
depends on I2O_CONFIG
default y
---help---
Enables old ioctls.
config I2O_BUS
tristate "I2O Bus Adapter OSM"
depends on I2O
---help---
Include support for the I2O Bus Adapter OSM. The Bus Adapter OSM
provides access to the busses on the I2O controller. The main purpose
is to rescan the bus to find new devices.
To compile this support as a module, choose M here: the
module will be called i2o_bus.
config I2O_BLOCK
tristate "I2O Block OSM"
depends on I2O
......
......@@ -6,8 +6,11 @@
#
i2o_core-y += iop.o driver.o device.o debug.o pci.o exec-osm.o
i2o_bus-y += bus-osm.o
i2o_config-y += config-osm.o
obj-$(CONFIG_I2O) += i2o_core.o
obj-$(CONFIG_I2O_CONFIG)+= i2o_config.o
obj-$(CONFIG_I2O_BUS) += i2o_bus.o
obj-$(CONFIG_I2O_BLOCK) += i2o_block.o
obj-$(CONFIG_I2O_SCSI) += i2o_scsi.o
obj-$(CONFIG_I2O_PROC) += i2o_proc.o
/*
* Bus Adapter OSM
*
* Copyright (C) 2005 Markus Lidel <Markus.Lidel@shadowconnect.com>
*
* 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.
*
* Fixes/additions:
* Markus Lidel <Markus.Lidel@shadowconnect.com>
* initial version.
*/
#include <linux/module.h>
#include <linux/i2o.h>
#define OSM_NAME "bus-osm"
#define OSM_VERSION "$Rev$"
#define OSM_DESCRIPTION "I2O Bus Adapter OSM"
static struct i2o_driver i2o_bus_driver;
/* Bus OSM class handling definition */
static struct i2o_class_id i2o_bus_class_id[] = {
{I2O_CLASS_BUS_ADAPTER},
{I2O_CLASS_END}
};
/**
* i2o_bus_scan - Scan the bus for new devices
* @dev: I2O device of the bus, which should be scanned
*
* Scans the bus dev for new / removed devices. After the scan a new LCT
* will be fetched automatically.
*
* Returns 0 on success or negative error code on failure.
*/
static int i2o_bus_scan(struct i2o_device *dev)
{
struct i2o_message __iomem *msg;
u32 m;
m = i2o_msg_get_wait(dev->iop, &msg, I2O_TIMEOUT_MESSAGE_GET);
if (m == I2O_QUEUE_EMPTY)
return -ETIMEDOUT;
writel(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
writel(I2O_CMD_BUS_SCAN << 24 | HOST_TID << 12 | dev->lct_data.tid,
&msg->u.head[1]);
return i2o_msg_post_wait(dev->iop, m, 60);
};
/**
* i2o_bus_store_scan - Scan the I2O Bus Adapter
* @d: device which should be scanned
*
* Returns count.
*/
static ssize_t i2o_bus_store_scan(struct device *d, const char *buf,
size_t count)
{
struct i2o_device *i2o_dev = to_i2o_device(d);
int rc;
if ((rc = i2o_bus_scan(i2o_dev)))
osm_warn("bus scan failed %d\n", rc);
return count;
}
/* Bus Adapter OSM device attributes */
static DEVICE_ATTR(scan, S_IWUSR, NULL, i2o_bus_store_scan);
/**
* i2o_bus_probe - verify if dev is a I2O Bus Adapter device and install it
* @dev: device to verify if it is a I2O Bus Adapter device
*
* Because we want all Bus Adapters always return 0.
*
* Returns 0.
*/
static int i2o_bus_probe(struct device *dev)
{
struct i2o_device *i2o_dev = to_i2o_device(get_device(dev));
device_create_file(dev, &dev_attr_scan);
osm_info("device added (TID: %03x)\n", i2o_dev->lct_data.tid);
return 0;
};
/**
* i2o_bus_remove - remove the I2O Bus Adapter device from the system again
* @dev: I2O Bus Adapter device which should be removed
*
* Always returns 0.
*/
static int i2o_bus_remove(struct device *dev)
{
struct i2o_device *i2o_dev = to_i2o_device(dev);
device_remove_file(dev, &dev_attr_scan);
put_device(dev);
osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);
return 0;
};
/* Bus Adapter OSM driver struct */
static struct i2o_driver i2o_bus_driver = {
.name = OSM_NAME,
.classes = i2o_bus_class_id,
.driver = {
.probe = i2o_bus_probe,
.remove = i2o_bus_remove,
},
};
/**
* i2o_bus_init - Bus Adapter OSM initialization function
*
* Only register the Bus Adapter OSM in the I2O core.
*
* Returns 0 on success or negative error code on failure.
*/
static int __init i2o_bus_init(void)
{
int rc;
printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
/* Register Bus Adapter OSM into I2O core */
rc = i2o_driver_register(&i2o_bus_driver);
if (rc) {
osm_err("Could not register Bus Adapter OSM\n");
return rc;
}
return 0;
};
/**
* i2o_bus_exit - Bus Adapter OSM exit function
*
* Unregisters Bus Adapter OSM from I2O core.
*/
static void __exit i2o_bus_exit(void)
{
i2o_driver_unregister(&i2o_bus_driver);
};
MODULE_AUTHOR("Markus Lidel <Markus.Lidel@shadowconnect.com>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION(OSM_DESCRIPTION);
MODULE_VERSION(OSM_VERSION);
module_init(i2o_bus_init);
module_exit(i2o_bus_exit);
/*
* Configuration OSM
*
* Copyright (C) 2005 Markus Lidel <Markus.Lidel@shadowconnect.com>
*
* 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.
*
* Fixes/additions:
* Markus Lidel <Markus.Lidel@shadowconnect.com>
* initial version.
*/
#include <linux/module.h>
#include <linux/i2o.h>
#include <linux/namei.h>
#include <asm/uaccess.h>
#define OSM_NAME "config-osm"
#define OSM_VERSION "1.248"
#define OSM_DESCRIPTION "I2O Configuration OSM"
/* access mode user rw */
#define S_IWRSR (S_IRUSR | S_IWUSR)
static struct i2o_driver i2o_config_driver;
/* Special file operations for sysfs */
struct fops_attribute {
struct bin_attribute bin;
struct file_operations fops;
};
/**
* sysfs_read_dummy
*/
static ssize_t sysfs_read_dummy(struct kobject *kobj, char *buf, loff_t offset,
size_t count)
{
return 0;
};
/**
* sysfs_write_dummy
*/
static ssize_t sysfs_write_dummy(struct kobject *kobj, char *buf, loff_t offset,
size_t count)
{
return 0;
};
/**
* sysfs_create_fops_file - Creates attribute with special file operations
* @kobj: kobject which should contains the attribute
* @attr: attributes which should be used to create file
*
* First creates attribute @attr in kobject @kobj. If it is the first time
* this function is called, merge old fops from sysfs with new one and
* write it back. Afterwords the new fops will be set for the created
* attribute.
*
* Returns 0 on success or negative error code on failure.
*/
static int sysfs_create_fops_file(struct kobject *kobj,
struct fops_attribute *attr)
{
struct file_operations tmp, *fops;
struct dentry *d;
struct qstr qstr;
int rc;
fops = &attr->fops;
if (fops->read)
attr->bin.read = sysfs_read_dummy;
if (fops->write)
attr->bin.write = sysfs_write_dummy;
if ((rc = sysfs_create_bin_file(kobj, &attr->bin)))
return rc;
qstr.name = attr->bin.attr.name;
qstr.len = strlen(qstr.name);
qstr.hash = full_name_hash(qstr.name, qstr.len);
if ((d = lookup_hash(&qstr, kobj->dentry))) {
if (!fops->owner) {
memcpy(&tmp, d->d_inode->i_fop, sizeof(tmp));
if (fops->read)
tmp.read = fops->read;
if (fops->write)
tmp.write = fops->write;
memcpy(fops, &tmp, sizeof(tmp));
}
d->d_inode->i_fop = fops;
} else
sysfs_remove_bin_file(kobj, &attr->bin);
return -ENOENT;
};
/**
* sysfs_remove_fops_file - Remove attribute with special file operations
* @kobj: kobject which contains the attribute
* @attr: attributes which are used to create file
*
* Only wrapper arround sysfs_remove_bin_file()
*
* Returns 0 on success or negative error code on failure.
*/
static inline int sysfs_remove_fops_file(struct kobject *kobj,
struct fops_attribute *attr)
{
return sysfs_remove_bin_file(kobj, &attr->bin);
};
/**
* i2o_config_read_hrt - Returns the HRT of the controller
* @kob: kernel object handle
* @buf: buffer into which the HRT should be copied
* @off: file offset
* @count: number of bytes to read
*
* Put @count bytes starting at @off into @buf from the HRT of the I2O
* controller corresponding to @kobj.
*
* Returns number of bytes copied into buffer.
*/
static ssize_t i2o_config_read_hrt(struct kobject *kobj, char *buf,
loff_t offset, size_t count)
{
struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
i2o_hrt *hrt = c->hrt.virt;
u32 size = (hrt->num_entries * hrt->entry_len + 2) * 4;
if (offset > size)
return 0;
if (offset + count > size)
count = size - offset;
memcpy(buf, (u8 *) hrt + offset, count);
return count;
};
/**
* i2o_config_read_lct - Returns the LCT of the controller
* @kob: kernel object handle
* @buf: buffer into which the LCT should be copied
* @off: file offset
* @count: number of bytes to read
*
* Put @count bytes starting at @off into @buf from the LCT of the I2O
* controller corresponding to @kobj.
*
* Returns number of bytes copied into buffer.
*/
static ssize_t i2o_config_read_lct(struct kobject *kobj, char *buf,
loff_t offset, size_t count)
{
struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
u32 size = c->lct->table_size * 4;
if (offset > size)
return 0;
if (offset + count > size)
count = size - offset;
memcpy(buf, (u8 *) c->lct + offset, count);
return count;
};
#define I2O_CONFIG_SW_ATTR(_name,_mode,_type,_swid) \
static ssize_t i2o_config_##_name##_read(struct file *file, char __user *buf, size_t count, loff_t * offset) { \
return i2o_config_sw_read(file, buf, count, offset, _type, _swid); \
};\
\
static ssize_t i2o_config_##_name##_write(struct file *file, const char __user *buf, size_t count, loff_t * offset) { \
return i2o_config_sw_write(file, buf, count, offset, _type, _swid); \
}; \
\
static struct fops_attribute i2o_config_attr_##_name = { \
.bin = { .attr = { .name = __stringify(_name), .mode = _mode, \
.owner = THIS_MODULE }, \
.size = 0, }, \
.fops = { .write = i2o_config_##_name##_write, \
.read = i2o_config_##_name##_read} \
};
#ifdef CONFIG_I2O_EXT_ADAPTEC
/**
* i2o_config_dpt_reagion - Converts type and id to flash region
* @swtype: type of software module reading
* @swid: id of software which should be read
*
* Converts type and id from I2O spec to the matching region for DPT /
* Adaptec controllers.
*
* Returns region which match type and id or -1 on error.
*/
static u32 i2o_config_dpt_region(u8 swtype, u8 swid)
{
switch (swtype) {
case I2O_SOFTWARE_MODULE_IRTOS:
/*
* content: operation firmware
* region size:
* 0xbc000 for 2554, 3754, 2564, 3757
* 0x170000 for 2865
* 0x17c000 for 3966
*/
if (!swid)
return 0;
break;
case I2O_SOFTWARE_MODULE_IOP_PRIVATE:
/*
* content: BIOS and SMOR
* BIOS size: first 0x8000 bytes
* region size:
* 0x40000 for 2554, 3754, 2564, 3757
* 0x80000 for 2865, 3966
*/
if (!swid)
return 1;
break;
case I2O_SOFTWARE_MODULE_IOP_CONFIG:
switch (swid) {
case 0:
/*
* content: NVRAM defaults
* region size: 0x2000 bytes
*/
return 2;
case 1:
/*
* content: serial number
* region size: 0x2000 bytes
*/
return 3;
}
break;
}
return -1;
};
#endif
/**
* i2o_config_sw_read - Read a software module from controller
* @file: file pointer
* @buf: buffer into which the data should be copied
* @count: number of bytes to read
* @off: file offset
* @swtype: type of software module reading
* @swid: id of software which should be read
*
* Transfers @count bytes at offset @offset from IOP into buffer using
* type @swtype and id @swid as described in I2O spec.
*
* Returns number of bytes copied into buffer or error code on failure.
*/
static ssize_t i2o_config_sw_read(struct file *file, char __user * buf,
size_t count, loff_t * offset, u8 swtype,
u32 swid)
{
struct sysfs_dirent *sd = file->f_dentry->d_parent->d_fsdata;
struct kobject *kobj = sd->s_element;
struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
u32 m, function = I2O_CMD_SW_UPLOAD;
struct i2o_dma buffer;
struct i2o_message __iomem *msg;
u32 __iomem *mptr;
int rc, status;
m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
if (m == I2O_QUEUE_EMPTY)
return -EBUSY;
mptr = &msg->body[3];
if ((rc = i2o_dma_alloc(&c->pdev->dev, &buffer, count, GFP_KERNEL))) {
i2o_msg_nop(c, m);
return rc;
}
#ifdef CONFIG_I2O_EXT_ADAPTEC
if (c->adaptec) {
mptr = &msg->body[4];
function = I2O_CMD_PRIVATE;
writel(TEN_WORD_MSG_SIZE | SGL_OFFSET_8, &msg->u.head[0]);
writel(I2O_VENDOR_DPT << 16 | I2O_DPT_FLASH_READ,
&msg->body[0]);
writel(i2o_config_dpt_region(swtype, swid), &msg->body[1]);
writel(*offset, &msg->body[2]);
writel(count, &msg->body[3]);
} else
#endif
writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
writel(0xD0000000 | count, mptr++);
writel(buffer.phys, mptr);
writel(function << 24 | HOST_TID << 12 | ADAPTER_TID, &msg->u.head[1]);
writel(i2o_config_driver.context, &msg->u.head[2]);
writel(0, &msg->u.head[3]);
#ifdef CONFIG_I2O_EXT_ADAPTEC
if (!c->adaptec)
#endif
{
writel((u32) swtype << 16 | (u32) 1 << 8, &msg->body[0]);
writel(0, &msg->body[1]);
writel(swid, &msg->body[2]);
}
status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
if (status == I2O_POST_WAIT_OK) {
if (!(rc = copy_to_user(buf, buffer.virt, count))) {
rc = count;
*offset += count;
}
} else
rc = -EIO;
if (status != -ETIMEDOUT)
i2o_dma_free(&c->pdev->dev, &buffer);
return rc;
};
/**
* i2o_config_sw_write - Write a software module to controller
* @file: file pointer
* @buf: buffer into which the data should be copied
* @count: number of bytes to read
* @off: file offset
* @swtype: type of software module writing
* @swid: id of software which should be written
*
* Transfers @count bytes at offset @offset from buffer to IOP using
* type @swtype and id @swid as described in I2O spec.
*
* Returns number of bytes copied from buffer or error code on failure.
*/
static ssize_t i2o_config_sw_write(struct file *file, const char __user * buf,
size_t count, loff_t * offset, u8 swtype,
u32 swid)
{
struct sysfs_dirent *sd = file->f_dentry->d_parent->d_fsdata;
struct kobject *kobj = sd->s_element;
struct i2o_controller *c = kobj_to_i2o_device(kobj)->iop;
u32 m, function = I2O_CMD_SW_DOWNLOAD;
struct i2o_dma buffer;
struct i2o_message __iomem *msg;
u32 __iomem *mptr;
int rc, status;
m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
if (m == I2O_QUEUE_EMPTY)
return -EBUSY;
mptr = &msg->body[3];
if ((rc = i2o_dma_alloc(&c->pdev->dev, &buffer, count, GFP_KERNEL)))
goto nop_msg;
if ((rc = copy_from_user(buffer.virt, buf, count)))
goto free_buffer;
#ifdef CONFIG_I2O_EXT_ADAPTEC
if (c->adaptec) {
mptr = &msg->body[4];
function = I2O_CMD_PRIVATE;
writel(TEN_WORD_MSG_SIZE | SGL_OFFSET_8, &msg->u.head[0]);
writel(I2O_VENDOR_DPT << 16 | I2O_DPT_FLASH_WRITE,
&msg->body[0]);
writel(i2o_config_dpt_region(swtype, swid), &msg->body[1]);
writel(*offset, &msg->body[2]);
writel(count, &msg->body[3]);
} else
#endif
writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
writel(0xD4000000 | count, mptr++);
writel(buffer.phys, mptr);
writel(function << 24 | HOST_TID << 12 | ADAPTER_TID, &msg->u.head[1]);
writel(i2o_config_driver.context, &msg->u.head[2]);
writel(0, &msg->u.head[3]);
#ifdef CONFIG_I2O_EXT_ADAPTEC
if (!c->adaptec)
#endif
{
writel((u32) swtype << 16 | (u32) 1 << 8, &msg->body[0]);
writel(0, &msg->body[1]);
writel(swid, &msg->body[2]);
}