53 #include <linux/module.h>
54 #include <linux/slab.h>
64 #include <scsi/scsi.h>
68 #define OSM_NAME "block-osm"
69 #define OSM_VERSION "1.325"
70 #define OSM_DESCRIPTION "I2O Block Device OSM"
107 static int i2o_block_remove(
struct device *
dev)
113 i2o_blk_dev->
gd->disk_name);
123 i2o_block_device_free(i2o_blk_dev);
151 return i2o_msg_post_wait(dev->
iop, msg, 60);
164 static int i2o_block_device_mount(
struct i2o_device *dev,
u32 media_id)
180 return i2o_msg_post_wait(dev->
iop, msg, 2);
193 static int i2o_block_device_lock(
struct i2o_device *dev,
u32 media_id)
208 return i2o_msg_post_wait(dev->
iop, msg, 2);
221 static int i2o_block_device_unlock(
struct i2o_device *dev,
u32 media_id)
236 return i2o_msg_post_wait(dev->
iop, msg, 2);
266 rc = i2o_msg_post_wait(c, msg, 60);
289 INIT_LIST_HEAD(&ireq->
queue);
316 static inline int i2o_block_sglist_alloc(
struct i2o_controller *c,
326 if (rq_data_dir(ireq->
req) ==
READ)
346 if (rq_data_dir(ireq->
req) ==
READ)
370 osm_err(
"block device already removed\n");
376 ireq = i2o_block_request_alloc();
378 osm_debug(
"unable to allocate i2o_block_request!\n");
379 return BLKPREP_DEFER;
411 spin_unlock_irqrestore(q->queue_lock, flags);
424 static void i2o_block_end_request(
struct request *req,
int error,
445 spin_unlock_irqrestore(q->queue_lock, flags);
447 i2o_block_sglist_free(ireq);
448 i2o_block_request_free(ireq);
468 osm_err(
"NULL reply received!\n");
491 osm_err(
"TID %03x error status: 0x%02x, detailed status: "
493 status >> 24, status & 0xffff);
535 #define BLOCK_SIZE_528M 1081344
536 #define BLOCK_SIZE_1G 2097152
537 #define BLOCK_SIZE_21G 4403200
538 #define BLOCK_SIZE_42G 8806400
539 #define BLOCK_SIZE_84G 17612800
541 static void i2o_block_biosparam(
unsigned long capacity,
unsigned short *cyls,
542 unsigned char *hds,
unsigned char *secs)
558 cylinders = (
unsigned long)capacity / (heads * sectors);
560 *cyls = (
unsigned short)cylinders;
561 *secs = (
unsigned char)sectors;
562 *hds = (
unsigned char)heads;
583 if (dev->
power > 0x1f)
584 i2o_block_device_power(dev, 0x02);
586 i2o_block_device_mount(dev->
i2o_dev, -1);
588 i2o_block_device_lock(dev->
i2o_dev, -1);
606 static int i2o_block_release(
struct gendisk *disk,
fmode_t mode)
623 i2o_block_device_flush(dev->
i2o_dev);
625 i2o_block_device_unlock(dev->
i2o_dev, -1);
627 if (dev->
flags & (1 << 3 | 1 << 4))
632 i2o_block_device_power(dev, operation);
640 i2o_block_biosparam(get_capacity(bdev->
bd_disk),
657 unsigned int cmd,
unsigned long arg)
659 struct gendisk *disk = bdev->
bd_disk;
706 static unsigned int i2o_block_check_events(
struct gendisk *disk,
707 unsigned int clearing)
713 return DISK_EVENT_MEDIA_CHANGE;
729 static int i2o_block_transfer(
struct request *req)
739 u32 ctl_flags = 0x00000000;
744 osm_err(
"transfer to removed drive\n");
749 tid = dev->
i2o_dev->lct_data.tid;
752 msg = i2o_msg_get(c);
758 tcntxt = i2o_cntxt_list_add(c, req);
767 mptr = &msg->
body[0];
769 if (rq_data_dir(req) ==
READ) {
774 ctl_flags = 0x201F0008;
777 case CACHE_SMARTFETCH:
778 if (blk_rq_sectors(req) > 16)
779 ctl_flags = 0x201F0008;
781 ctl_flags = 0x001F0000;
792 ctl_flags = 0x001F0008;
795 ctl_flags = 0x001F0010;
798 if (blk_rq_sectors(req) > 16)
799 ctl_flags = 0x001F0004;
801 ctl_flags = 0x001F0010;
804 if (blk_rq_sectors(req) > 16)
805 ctl_flags = 0x001F0004;
807 ctl_flags = 0x001F0010;
813 #ifdef CONFIG_I2O_EXT_ADAPTEC
835 if (rq_data_dir(req) ==
READ) {
837 scsi_flags = 0x60a0000a;
840 scsi_flags = 0xa0a0000a;
863 if (!i2o_block_sglist_alloc(c, ireq, &mptr)) {
874 i2o_msg_post(c, msg);
879 i2o_cntxt_list_remove(c, req);
901 if (req->cmd_type == REQ_TYPE_FS) {
909 if (!i2o_block_transfer(req)) {
926 i2o_block_delayed_request_fn);
944 static const struct block_device_operations i2o_block_fops = {
946 .open = i2o_block_open,
947 .release = i2o_block_release,
948 .ioctl = i2o_block_ioctl,
949 .compat_ioctl = i2o_block_ioctl,
950 .getgeo = i2o_block_getgeo,
951 .check_events = i2o_block_check_events,
972 osm_err(
"Insufficient memory to allocate I2O Block disk.\n");
985 osm_err(
"Insufficient memory to allocate gendisk.\n");
993 osm_err(
"Insufficient memory to allocate request queue.\n");
1002 gd->fops = &i2o_block_fops;
1003 gd->private_data =
dev;
1028 static int i2o_block_probe(
struct device *dev)
1035 static int unit = 0;
1041 unsigned short max_sectors;
1043 #ifdef CONFIG_I2O_EXT_ADAPTEC
1060 osm_warn(
"Unable to claim device. Installation aborted\n");
1065 i2o_blk_dev = i2o_block_device_alloc();
1066 if (IS_ERR(i2o_blk_dev)) {
1067 osm_err(
"could not alloc a new I2O block device");
1068 rc = PTR_ERR(i2o_blk_dev);
1072 i2o_blk_dev->
i2o_dev = i2o_dev;
1076 gd = i2o_blk_dev->
gd;
1077 gd->first_minor = unit << 4;
1078 sprintf(gd->disk_name,
"i2o/hd%c",
'a' + unit);
1079 gd->driverfs_dev = &i2o_dev->
device;
1083 queue->queuedata = i2o_blk_dev;
1088 osm_debug(
"max sectors = %d\n", queue->max_sectors);
1089 osm_debug(
"phys segments = %d\n", queue->max_phys_segments);
1090 osm_debug(
"max hw segments = %d\n", queue->max_hw_segments);
1100 osm_warn(
"unable to get blocksize of %s\n", gd->disk_name);
1106 osm_warn(
"could not get size of %s\n", gd->disk_name);
1109 i2o_blk_dev->
power = power;
1118 i2o_blk_dev->
gd->disk_name);
1130 static struct i2o_driver i2o_block_driver = {
1132 .event = i2o_block_event,
1133 .reply = i2o_block_reply,
1134 .classes = i2o_block_class_id,
1136 .probe = i2o_block_probe,
1137 .remove = i2o_block_remove,
1149 static int __init i2o_block_init(
void)
1160 if (!i2o_blk_req_pool.slab) {
1161 osm_err(
"can't init request slab\n");
1166 i2o_blk_req_pool.pool =
1168 i2o_blk_req_pool.slab);
1169 if (!i2o_blk_req_pool.pool) {
1170 osm_err(
"can't init request mempool\n");
1178 osm_err(
"unable to register block device\n");
1188 osm_err(
"Could not register Block driver\n");
1213 static void __exit i2o_block_exit(
void)