diff options
Diffstat (limited to 'drivers/block/cciss.c')
-rw-r--r-- | drivers/block/cciss.c | 755 |
1 files changed, 547 insertions, 208 deletions
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index 24c3e21ab263..fb5be2d95d52 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c | |||
@@ -36,9 +36,11 @@ | |||
36 | #include <linux/proc_fs.h> | 36 | #include <linux/proc_fs.h> |
37 | #include <linux/seq_file.h> | 37 | #include <linux/seq_file.h> |
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/jiffies.h> | ||
39 | #include <linux/hdreg.h> | 40 | #include <linux/hdreg.h> |
40 | #include <linux/spinlock.h> | 41 | #include <linux/spinlock.h> |
41 | #include <linux/compat.h> | 42 | #include <linux/compat.h> |
43 | #include <linux/mutex.h> | ||
42 | #include <asm/uaccess.h> | 44 | #include <asm/uaccess.h> |
43 | #include <asm/io.h> | 45 | #include <asm/io.h> |
44 | 46 | ||
@@ -155,6 +157,10 @@ static struct board_type products[] = { | |||
155 | 157 | ||
156 | static ctlr_info_t *hba[MAX_CTLR]; | 158 | static ctlr_info_t *hba[MAX_CTLR]; |
157 | 159 | ||
160 | static struct task_struct *cciss_scan_thread; | ||
161 | static DEFINE_MUTEX(scan_mutex); | ||
162 | static LIST_HEAD(scan_q); | ||
163 | |||
158 | static void do_cciss_request(struct request_queue *q); | 164 | static void do_cciss_request(struct request_queue *q); |
159 | static irqreturn_t do_cciss_intr(int irq, void *dev_id); | 165 | static irqreturn_t do_cciss_intr(int irq, void *dev_id); |
160 | static int cciss_open(struct block_device *bdev, fmode_t mode); | 166 | static int cciss_open(struct block_device *bdev, fmode_t mode); |
@@ -164,9 +170,9 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode, | |||
164 | static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); | 170 | static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); |
165 | 171 | ||
166 | static int cciss_revalidate(struct gendisk *disk); | 172 | static int cciss_revalidate(struct gendisk *disk); |
167 | static int rebuild_lun_table(ctlr_info_t *h, int first_time); | 173 | static int rebuild_lun_table(ctlr_info_t *h, int first_time, int via_ioctl); |
168 | static int deregister_disk(ctlr_info_t *h, int drv_index, | 174 | static int deregister_disk(ctlr_info_t *h, int drv_index, |
169 | int clear_all); | 175 | int clear_all, int via_ioctl); |
170 | 176 | ||
171 | static void cciss_read_capacity(int ctlr, int logvol, int withirq, | 177 | static void cciss_read_capacity(int ctlr, int logvol, int withirq, |
172 | sector_t *total_size, unsigned int *block_size); | 178 | sector_t *total_size, unsigned int *block_size); |
@@ -189,8 +195,13 @@ static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c, | |||
189 | static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c); | 195 | static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c); |
190 | 196 | ||
191 | static void fail_all_cmds(unsigned long ctlr); | 197 | static void fail_all_cmds(unsigned long ctlr); |
198 | static int add_to_scan_list(struct ctlr_info *h); | ||
192 | static int scan_thread(void *data); | 199 | static int scan_thread(void *data); |
193 | static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c); | 200 | static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c); |
201 | static void cciss_hba_release(struct device *dev); | ||
202 | static void cciss_device_release(struct device *dev); | ||
203 | static void cciss_free_gendisk(ctlr_info_t *h, int drv_index); | ||
204 | static void cciss_free_drive_info(ctlr_info_t *h, int drv_index); | ||
194 | 205 | ||
195 | #ifdef CONFIG_PROC_FS | 206 | #ifdef CONFIG_PROC_FS |
196 | static void cciss_procinit(int i); | 207 | static void cciss_procinit(int i); |
@@ -245,7 +256,10 @@ static inline void removeQ(CommandList_struct *c) | |||
245 | 256 | ||
246 | #include "cciss_scsi.c" /* For SCSI tape support */ | 257 | #include "cciss_scsi.c" /* For SCSI tape support */ |
247 | 258 | ||
248 | #define RAID_UNKNOWN 6 | 259 | static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", |
260 | "UNKNOWN" | ||
261 | }; | ||
262 | #define RAID_UNKNOWN (sizeof(raid_label) / sizeof(raid_label[0])-1) | ||
249 | 263 | ||
250 | #ifdef CONFIG_PROC_FS | 264 | #ifdef CONFIG_PROC_FS |
251 | 265 | ||
@@ -255,9 +269,6 @@ static inline void removeQ(CommandList_struct *c) | |||
255 | #define ENG_GIG 1000000000 | 269 | #define ENG_GIG 1000000000 |
256 | #define ENG_GIG_FACTOR (ENG_GIG/512) | 270 | #define ENG_GIG_FACTOR (ENG_GIG/512) |
257 | #define ENGAGE_SCSI "engage scsi" | 271 | #define ENGAGE_SCSI "engage scsi" |
258 | static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", | ||
259 | "UNKNOWN" | ||
260 | }; | ||
261 | 272 | ||
262 | static struct proc_dir_entry *proc_cciss; | 273 | static struct proc_dir_entry *proc_cciss; |
263 | 274 | ||
@@ -318,7 +329,7 @@ static int cciss_seq_show(struct seq_file *seq, void *v) | |||
318 | ctlr_info_t *h = seq->private; | 329 | ctlr_info_t *h = seq->private; |
319 | unsigned ctlr = h->ctlr; | 330 | unsigned ctlr = h->ctlr; |
320 | loff_t *pos = v; | 331 | loff_t *pos = v; |
321 | drive_info_struct *drv = &h->drv[*pos]; | 332 | drive_info_struct *drv = h->drv[*pos]; |
322 | 333 | ||
323 | if (*pos > h->highest_lun) | 334 | if (*pos > h->highest_lun) |
324 | return 0; | 335 | return 0; |
@@ -331,7 +342,7 @@ static int cciss_seq_show(struct seq_file *seq, void *v) | |||
331 | vol_sz_frac *= 100; | 342 | vol_sz_frac *= 100; |
332 | sector_div(vol_sz_frac, ENG_GIG_FACTOR); | 343 | sector_div(vol_sz_frac, ENG_GIG_FACTOR); |
333 | 344 | ||
334 | if (drv->raid_level > 5) | 345 | if (drv->raid_level < 0 || drv->raid_level > RAID_UNKNOWN) |
335 | drv->raid_level = RAID_UNKNOWN; | 346 | drv->raid_level = RAID_UNKNOWN; |
336 | seq_printf(seq, "cciss/c%dd%d:" | 347 | seq_printf(seq, "cciss/c%dd%d:" |
337 | "\t%4u.%02uGB\tRAID %s\n", | 348 | "\t%4u.%02uGB\tRAID %s\n", |
@@ -426,7 +437,7 @@ out: | |||
426 | return err; | 437 | return err; |
427 | } | 438 | } |
428 | 439 | ||
429 | static struct file_operations cciss_proc_fops = { | 440 | static const struct file_operations cciss_proc_fops = { |
430 | .owner = THIS_MODULE, | 441 | .owner = THIS_MODULE, |
431 | .open = cciss_seq_open, | 442 | .open = cciss_seq_open, |
432 | .read = seq_read, | 443 | .read = seq_read, |
@@ -454,9 +465,19 @@ static void __devinit cciss_procinit(int i) | |||
454 | #define to_hba(n) container_of(n, struct ctlr_info, dev) | 465 | #define to_hba(n) container_of(n, struct ctlr_info, dev) |
455 | #define to_drv(n) container_of(n, drive_info_struct, dev) | 466 | #define to_drv(n) container_of(n, drive_info_struct, dev) |
456 | 467 | ||
457 | static struct device_type cciss_host_type = { | 468 | static ssize_t host_store_rescan(struct device *dev, |
458 | .name = "cciss_host", | 469 | struct device_attribute *attr, |
459 | }; | 470 | const char *buf, size_t count) |
471 | { | ||
472 | struct ctlr_info *h = to_hba(dev); | ||
473 | |||
474 | add_to_scan_list(h); | ||
475 | wake_up_process(cciss_scan_thread); | ||
476 | wait_for_completion_interruptible(&h->scan_wait); | ||
477 | |||
478 | return count; | ||
479 | } | ||
480 | DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); | ||
460 | 481 | ||
461 | static ssize_t dev_show_unique_id(struct device *dev, | 482 | static ssize_t dev_show_unique_id(struct device *dev, |
462 | struct device_attribute *attr, | 483 | struct device_attribute *attr, |
@@ -560,11 +581,101 @@ static ssize_t dev_show_rev(struct device *dev, | |||
560 | } | 581 | } |
561 | DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL); | 582 | DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL); |
562 | 583 | ||
584 | static ssize_t cciss_show_lunid(struct device *dev, | ||
585 | struct device_attribute *attr, char *buf) | ||
586 | { | ||
587 | drive_info_struct *drv = to_drv(dev); | ||
588 | struct ctlr_info *h = to_hba(drv->dev.parent); | ||
589 | unsigned long flags; | ||
590 | unsigned char lunid[8]; | ||
591 | |||
592 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); | ||
593 | if (h->busy_configuring) { | ||
594 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
595 | return -EBUSY; | ||
596 | } | ||
597 | if (!drv->heads) { | ||
598 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
599 | return -ENOTTY; | ||
600 | } | ||
601 | memcpy(lunid, drv->LunID, sizeof(lunid)); | ||
602 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
603 | return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", | ||
604 | lunid[0], lunid[1], lunid[2], lunid[3], | ||
605 | lunid[4], lunid[5], lunid[6], lunid[7]); | ||
606 | } | ||
607 | DEVICE_ATTR(lunid, S_IRUGO, cciss_show_lunid, NULL); | ||
608 | |||
609 | static ssize_t cciss_show_raid_level(struct device *dev, | ||
610 | struct device_attribute *attr, char *buf) | ||
611 | { | ||
612 | drive_info_struct *drv = to_drv(dev); | ||
613 | struct ctlr_info *h = to_hba(drv->dev.parent); | ||
614 | int raid; | ||
615 | unsigned long flags; | ||
616 | |||
617 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); | ||
618 | if (h->busy_configuring) { | ||
619 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
620 | return -EBUSY; | ||
621 | } | ||
622 | raid = drv->raid_level; | ||
623 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
624 | if (raid < 0 || raid > RAID_UNKNOWN) | ||
625 | raid = RAID_UNKNOWN; | ||
626 | |||
627 | return snprintf(buf, strlen(raid_label[raid]) + 7, "RAID %s\n", | ||
628 | raid_label[raid]); | ||
629 | } | ||
630 | DEVICE_ATTR(raid_level, S_IRUGO, cciss_show_raid_level, NULL); | ||
631 | |||
632 | static ssize_t cciss_show_usage_count(struct device *dev, | ||
633 | struct device_attribute *attr, char *buf) | ||
634 | { | ||
635 | drive_info_struct *drv = to_drv(dev); | ||
636 | struct ctlr_info *h = to_hba(drv->dev.parent); | ||
637 | unsigned long flags; | ||
638 | int count; | ||
639 | |||
640 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); | ||
641 | if (h->busy_configuring) { | ||
642 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
643 | return -EBUSY; | ||
644 | } | ||
645 | count = drv->usage_count; | ||
646 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | ||
647 | return snprintf(buf, 20, "%d\n", count); | ||
648 | } | ||
649 | DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL); | ||
650 | |||
651 | static struct attribute *cciss_host_attrs[] = { | ||
652 | &dev_attr_rescan.attr, | ||
653 | NULL | ||
654 | }; | ||
655 | |||
656 | static struct attribute_group cciss_host_attr_group = { | ||
657 | .attrs = cciss_host_attrs, | ||
658 | }; | ||
659 | |||
660 | static const struct attribute_group *cciss_host_attr_groups[] = { | ||
661 | &cciss_host_attr_group, | ||
662 | NULL | ||
663 | }; | ||
664 | |||
665 | static struct device_type cciss_host_type = { | ||
666 | .name = "cciss_host", | ||
667 | .groups = cciss_host_attr_groups, | ||
668 | .release = cciss_hba_release, | ||
669 | }; | ||
670 | |||
563 | static struct attribute *cciss_dev_attrs[] = { | 671 | static struct attribute *cciss_dev_attrs[] = { |
564 | &dev_attr_unique_id.attr, | 672 | &dev_attr_unique_id.attr, |
565 | &dev_attr_model.attr, | 673 | &dev_attr_model.attr, |
566 | &dev_attr_vendor.attr, | 674 | &dev_attr_vendor.attr, |
567 | &dev_attr_rev.attr, | 675 | &dev_attr_rev.attr, |
676 | &dev_attr_lunid.attr, | ||
677 | &dev_attr_raid_level.attr, | ||
678 | &dev_attr_usage_count.attr, | ||
568 | NULL | 679 | NULL |
569 | }; | 680 | }; |
570 | 681 | ||
@@ -580,12 +691,24 @@ static const struct attribute_group *cciss_dev_attr_groups[] = { | |||
580 | static struct device_type cciss_dev_type = { | 691 | static struct device_type cciss_dev_type = { |
581 | .name = "cciss_device", | 692 | .name = "cciss_device", |
582 | .groups = cciss_dev_attr_groups, | 693 | .groups = cciss_dev_attr_groups, |
694 | .release = cciss_device_release, | ||
583 | }; | 695 | }; |
584 | 696 | ||
585 | static struct bus_type cciss_bus_type = { | 697 | static struct bus_type cciss_bus_type = { |
586 | .name = "cciss", | 698 | .name = "cciss", |
587 | }; | 699 | }; |
588 | 700 | ||
701 | /* | ||
702 | * cciss_hba_release is called when the reference count | ||
703 | * of h->dev goes to zero. | ||
704 | */ | ||
705 | static void cciss_hba_release(struct device *dev) | ||
706 | { | ||
707 | /* | ||
708 | * nothing to do, but need this to avoid a warning | ||
709 | * about not having a release handler from lib/kref.c. | ||
710 | */ | ||
711 | } | ||
589 | 712 | ||
590 | /* | 713 | /* |
591 | * Initialize sysfs entry for each controller. This sets up and registers | 714 | * Initialize sysfs entry for each controller. This sets up and registers |
@@ -609,6 +732,16 @@ static int cciss_create_hba_sysfs_entry(struct ctlr_info *h) | |||
609 | static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h) | 732 | static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h) |
610 | { | 733 | { |
611 | device_del(&h->dev); | 734 | device_del(&h->dev); |
735 | put_device(&h->dev); /* final put. */ | ||
736 | } | ||
737 | |||
738 | /* cciss_device_release is called when the reference count | ||
739 | * of h->drv[x]dev goes to zero. | ||
740 | */ | ||
741 | static void cciss_device_release(struct device *dev) | ||
742 | { | ||
743 | drive_info_struct *drv = to_drv(dev); | ||
744 | kfree(drv); | ||
612 | } | 745 | } |
613 | 746 | ||
614 | /* | 747 | /* |
@@ -617,24 +750,39 @@ static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h) | |||
617 | * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from | 750 | * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from |
618 | * /sys/block/cciss!c#d# to this entry. | 751 | * /sys/block/cciss!c#d# to this entry. |
619 | */ | 752 | */ |
620 | static int cciss_create_ld_sysfs_entry(struct ctlr_info *h, | 753 | static long cciss_create_ld_sysfs_entry(struct ctlr_info *h, |
621 | drive_info_struct *drv, | ||
622 | int drv_index) | 754 | int drv_index) |
623 | { | 755 | { |
624 | device_initialize(&drv->dev); | 756 | struct device *dev; |
625 | drv->dev.type = &cciss_dev_type; | 757 | |
626 | drv->dev.bus = &cciss_bus_type; | 758 | if (h->drv[drv_index]->device_initialized) |
627 | dev_set_name(&drv->dev, "c%dd%d", h->ctlr, drv_index); | 759 | return 0; |
628 | drv->dev.parent = &h->dev; | 760 | |
629 | return device_add(&drv->dev); | 761 | dev = &h->drv[drv_index]->dev; |
762 | device_initialize(dev); | ||
763 | dev->type = &cciss_dev_type; | ||
764 | dev->bus = &cciss_bus_type; | ||
765 | dev_set_name(dev, "c%dd%d", h->ctlr, drv_index); | ||
766 | dev->parent = &h->dev; | ||
767 | h->drv[drv_index]->device_initialized = 1; | ||
768 | return device_add(dev); | ||
630 | } | 769 | } |
631 | 770 | ||
632 | /* | 771 | /* |
633 | * Remove sysfs entries for a logical drive. | 772 | * Remove sysfs entries for a logical drive. |
634 | */ | 773 | */ |
635 | static void cciss_destroy_ld_sysfs_entry(drive_info_struct *drv) | 774 | static void cciss_destroy_ld_sysfs_entry(struct ctlr_info *h, int drv_index, |
775 | int ctlr_exiting) | ||
636 | { | 776 | { |
637 | device_del(&drv->dev); | 777 | struct device *dev = &h->drv[drv_index]->dev; |
778 | |||
779 | /* special case for c*d0, we only destroy it on controller exit */ | ||
780 | if (drv_index == 0 && !ctlr_exiting) | ||
781 | return; | ||
782 | |||
783 | device_del(dev); | ||
784 | put_device(dev); /* the "final" put. */ | ||
785 | h->drv[drv_index] = NULL; | ||
638 | } | 786 | } |
639 | 787 | ||
640 | /* | 788 | /* |
@@ -751,7 +899,7 @@ static int cciss_open(struct block_device *bdev, fmode_t mode) | |||
751 | printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name); | 899 | printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name); |
752 | #endif /* CCISS_DEBUG */ | 900 | #endif /* CCISS_DEBUG */ |
753 | 901 | ||
754 | if (host->busy_initializing || drv->busy_configuring) | 902 | if (drv->busy_configuring) |
755 | return -EBUSY; | 903 | return -EBUSY; |
756 | /* | 904 | /* |
757 | * Root is allowed to open raw volume zero even if it's not configured | 905 | * Root is allowed to open raw volume zero even if it's not configured |
@@ -767,7 +915,8 @@ static int cciss_open(struct block_device *bdev, fmode_t mode) | |||
767 | if (MINOR(bdev->bd_dev) & 0x0f) { | 915 | if (MINOR(bdev->bd_dev) & 0x0f) { |
768 | return -ENXIO; | 916 | return -ENXIO; |
769 | /* if it is, make sure we have a LUN ID */ | 917 | /* if it is, make sure we have a LUN ID */ |
770 | } else if (drv->LunID == 0) { | 918 | } else if (memcmp(drv->LunID, CTLR_LUNID, |
919 | sizeof(drv->LunID))) { | ||
771 | return -ENXIO; | 920 | return -ENXIO; |
772 | } | 921 | } |
773 | } | 922 | } |
@@ -1132,12 +1281,13 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode, | |||
1132 | case CCISS_DEREGDISK: | 1281 | case CCISS_DEREGDISK: |
1133 | case CCISS_REGNEWD: | 1282 | case CCISS_REGNEWD: |
1134 | case CCISS_REVALIDVOLS: | 1283 | case CCISS_REVALIDVOLS: |
1135 | return rebuild_lun_table(host, 0); | 1284 | return rebuild_lun_table(host, 0, 1); |
1136 | 1285 | ||
1137 | case CCISS_GETLUNINFO:{ | 1286 | case CCISS_GETLUNINFO:{ |
1138 | LogvolInfo_struct luninfo; | 1287 | LogvolInfo_struct luninfo; |
1139 | 1288 | ||
1140 | luninfo.LunID = drv->LunID; | 1289 | memcpy(&luninfo.LunID, drv->LunID, |
1290 | sizeof(luninfo.LunID)); | ||
1141 | luninfo.num_opens = drv->usage_count; | 1291 | luninfo.num_opens = drv->usage_count; |
1142 | luninfo.num_parts = 0; | 1292 | luninfo.num_parts = 0; |
1143 | if (copy_to_user(argp, &luninfo, | 1293 | if (copy_to_user(argp, &luninfo, |
@@ -1475,7 +1625,10 @@ static void cciss_check_queues(ctlr_info_t *h) | |||
1475 | /* make sure the disk has been added and the drive is real | 1625 | /* make sure the disk has been added and the drive is real |
1476 | * because this can be called from the middle of init_one. | 1626 | * because this can be called from the middle of init_one. |
1477 | */ | 1627 | */ |
1478 | if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads)) | 1628 | if (!h->drv[curr_queue]) |
1629 | continue; | ||
1630 | if (!(h->drv[curr_queue]->queue) || | ||
1631 | !(h->drv[curr_queue]->heads)) | ||
1479 | continue; | 1632 | continue; |
1480 | blk_start_queue(h->gendisk[curr_queue]->queue); | 1633 | blk_start_queue(h->gendisk[curr_queue]->queue); |
1481 | 1634 | ||
@@ -1532,13 +1685,11 @@ static void cciss_softirq_done(struct request *rq) | |||
1532 | spin_unlock_irqrestore(&h->lock, flags); | 1685 | spin_unlock_irqrestore(&h->lock, flags); |
1533 | } | 1686 | } |
1534 | 1687 | ||
1535 | static void log_unit_to_scsi3addr(ctlr_info_t *h, unsigned char scsi3addr[], | 1688 | static inline void log_unit_to_scsi3addr(ctlr_info_t *h, |
1536 | uint32_t log_unit) | 1689 | unsigned char scsi3addr[], uint32_t log_unit) |
1537 | { | 1690 | { |
1538 | log_unit = h->drv[log_unit].LunID & 0x03fff; | 1691 | memcpy(scsi3addr, h->drv[log_unit]->LunID, |
1539 | memset(&scsi3addr[4], 0, 4); | 1692 | sizeof(h->drv[log_unit]->LunID)); |
1540 | memcpy(&scsi3addr[0], &log_unit, 4); | ||
1541 | scsi3addr[3] |= 0x40; | ||
1542 | } | 1693 | } |
1543 | 1694 | ||
1544 | /* This function gets the SCSI vendor, model, and revision of a logical drive | 1695 | /* This function gets the SCSI vendor, model, and revision of a logical drive |
@@ -1615,16 +1766,23 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq, | |||
1615 | return; | 1766 | return; |
1616 | } | 1767 | } |
1617 | 1768 | ||
1618 | static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk, | 1769 | /* |
1770 | * cciss_add_disk sets up the block device queue for a logical drive | ||
1771 | */ | ||
1772 | static int cciss_add_disk(ctlr_info_t *h, struct gendisk *disk, | ||
1619 | int drv_index) | 1773 | int drv_index) |
1620 | { | 1774 | { |
1621 | disk->queue = blk_init_queue(do_cciss_request, &h->lock); | 1775 | disk->queue = blk_init_queue(do_cciss_request, &h->lock); |
1776 | if (!disk->queue) | ||
1777 | goto init_queue_failure; | ||
1622 | sprintf(disk->disk_name, "cciss/c%dd%d", h->ctlr, drv_index); | 1778 | sprintf(disk->disk_name, "cciss/c%dd%d", h->ctlr, drv_index); |
1623 | disk->major = h->major; | 1779 | disk->major = h->major; |
1624 | disk->first_minor = drv_index << NWD_SHIFT; | 1780 | disk->first_minor = drv_index << NWD_SHIFT; |
1625 | disk->fops = &cciss_fops; | 1781 | disk->fops = &cciss_fops; |
1626 | disk->private_data = &h->drv[drv_index]; | 1782 | if (cciss_create_ld_sysfs_entry(h, drv_index)) |
1627 | disk->driverfs_dev = &h->drv[drv_index].dev; | 1783 | goto cleanup_queue; |
1784 | disk->private_data = h->drv[drv_index]; | ||
1785 | disk->driverfs_dev = &h->drv[drv_index]->dev; | ||
1628 | 1786 | ||
1629 | /* Set up queue information */ | 1787 | /* Set up queue information */ |
1630 | blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); | 1788 | blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); |
@@ -1642,14 +1800,21 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk, | |||
1642 | disk->queue->queuedata = h; | 1800 | disk->queue->queuedata = h; |
1643 | 1801 | ||
1644 | blk_queue_logical_block_size(disk->queue, | 1802 | blk_queue_logical_block_size(disk->queue, |
1645 | h->drv[drv_index].block_size); | 1803 | h->drv[drv_index]->block_size); |
1646 | 1804 | ||
1647 | /* Make sure all queue data is written out before */ | 1805 | /* Make sure all queue data is written out before */ |
1648 | /* setting h->drv[drv_index].queue, as setting this */ | 1806 | /* setting h->drv[drv_index]->queue, as setting this */ |
1649 | /* allows the interrupt handler to start the queue */ | 1807 | /* allows the interrupt handler to start the queue */ |
1650 | wmb(); | 1808 | wmb(); |
1651 | h->drv[drv_index].queue = disk->queue; | 1809 | h->drv[drv_index]->queue = disk->queue; |
1652 | add_disk(disk); | 1810 | add_disk(disk); |
1811 | return 0; | ||
1812 | |||
1813 | cleanup_queue: | ||
1814 | blk_cleanup_queue(disk->queue); | ||
1815 | disk->queue = NULL; | ||
1816 | init_queue_failure: | ||
1817 | return -1; | ||
1653 | } | 1818 | } |
1654 | 1819 | ||
1655 | /* This function will check the usage_count of the drive to be updated/added. | 1820 | /* This function will check the usage_count of the drive to be updated/added. |
@@ -1662,7 +1827,8 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk, | |||
1662 | * is also the controller node. Any changes to disk 0 will show up on | 1827 | * is also the controller node. Any changes to disk 0 will show up on |
1663 | * the next reboot. | 1828 | * the next reboot. |
1664 | */ | 1829 | */ |
1665 | static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) | 1830 | static void cciss_update_drive_info(int ctlr, int drv_index, int first_time, |
1831 | int via_ioctl) | ||
1666 | { | 1832 | { |
1667 | ctlr_info_t *h = hba[ctlr]; | 1833 | ctlr_info_t *h = hba[ctlr]; |
1668 | struct gendisk *disk; | 1834 | struct gendisk *disk; |
@@ -1672,21 +1838,13 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) | |||
1672 | unsigned long flags = 0; | 1838 | unsigned long flags = 0; |
1673 | int ret = 0; | 1839 | int ret = 0; |
1674 | drive_info_struct *drvinfo; | 1840 | drive_info_struct *drvinfo; |
1675 | int was_only_controller_node; | ||
1676 | 1841 | ||
1677 | /* Get information about the disk and modify the driver structure */ | 1842 | /* Get information about the disk and modify the driver structure */ |
1678 | inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); | 1843 | inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); |
1679 | drvinfo = kmalloc(sizeof(*drvinfo), GFP_KERNEL); | 1844 | drvinfo = kzalloc(sizeof(*drvinfo), GFP_KERNEL); |
1680 | if (inq_buff == NULL || drvinfo == NULL) | 1845 | if (inq_buff == NULL || drvinfo == NULL) |
1681 | goto mem_msg; | 1846 | goto mem_msg; |
1682 | 1847 | ||
1683 | /* See if we're trying to update the "controller node" | ||
1684 | * this will happen the when the first logical drive gets | ||
1685 | * created by ACU. | ||
1686 | */ | ||
1687 | was_only_controller_node = (drv_index == 0 && | ||
1688 | h->drv[0].raid_level == -1); | ||
1689 | |||
1690 | /* testing to see if 16-byte CDBs are already being used */ | 1848 | /* testing to see if 16-byte CDBs are already being used */ |
1691 | if (h->cciss_read == CCISS_READ_16) { | 1849 | if (h->cciss_read == CCISS_READ_16) { |
1692 | cciss_read_capacity_16(h->ctlr, drv_index, 1, | 1850 | cciss_read_capacity_16(h->ctlr, drv_index, 1, |
@@ -1719,16 +1877,19 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) | |||
1719 | drvinfo->model, drvinfo->rev); | 1877 | drvinfo->model, drvinfo->rev); |
1720 | cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no, | 1878 | cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no, |
1721 | sizeof(drvinfo->serial_no)); | 1879 | sizeof(drvinfo->serial_no)); |
1880 | /* Save the lunid in case we deregister the disk, below. */ | ||
1881 | memcpy(drvinfo->LunID, h->drv[drv_index]->LunID, | ||
1882 | sizeof(drvinfo->LunID)); | ||
1722 | 1883 | ||
1723 | /* Is it the same disk we already know, and nothing's changed? */ | 1884 | /* Is it the same disk we already know, and nothing's changed? */ |
1724 | if (h->drv[drv_index].raid_level != -1 && | 1885 | if (h->drv[drv_index]->raid_level != -1 && |
1725 | ((memcmp(drvinfo->serial_no, | 1886 | ((memcmp(drvinfo->serial_no, |
1726 | h->drv[drv_index].serial_no, 16) == 0) && | 1887 | h->drv[drv_index]->serial_no, 16) == 0) && |
1727 | drvinfo->block_size == h->drv[drv_index].block_size && | 1888 | drvinfo->block_size == h->drv[drv_index]->block_size && |
1728 | drvinfo->nr_blocks == h->drv[drv_index].nr_blocks && | 1889 | drvinfo->nr_blocks == h->drv[drv_index]->nr_blocks && |
1729 | drvinfo->heads == h->drv[drv_index].heads && | 1890 | drvinfo->heads == h->drv[drv_index]->heads && |
1730 | drvinfo->sectors == h->drv[drv_index].sectors && | 1891 | drvinfo->sectors == h->drv[drv_index]->sectors && |
1731 | drvinfo->cylinders == h->drv[drv_index].cylinders)) | 1892 | drvinfo->cylinders == h->drv[drv_index]->cylinders)) |
1732 | /* The disk is unchanged, nothing to update */ | 1893 | /* The disk is unchanged, nothing to update */ |
1733 | goto freeret; | 1894 | goto freeret; |
1734 | 1895 | ||
@@ -1738,18 +1899,17 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) | |||
1738 | * If the disk already exists then deregister it before proceeding | 1899 | * If the disk already exists then deregister it before proceeding |
1739 | * (unless it's the first disk (for the controller node). | 1900 | * (unless it's the first disk (for the controller node). |
1740 | */ | 1901 | */ |
1741 | if (h->drv[drv_index].raid_level != -1 && drv_index != 0) { | 1902 | if (h->drv[drv_index]->raid_level != -1 && drv_index != 0) { |
1742 | printk(KERN_WARNING "disk %d has changed.\n", drv_index); | 1903 | printk(KERN_WARNING "disk %d has changed.\n", drv_index); |
1743 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); | 1904 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); |
1744 | h->drv[drv_index].busy_configuring = 1; | 1905 | h->drv[drv_index]->busy_configuring = 1; |
1745 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | 1906 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
1746 | 1907 | ||
1747 | /* deregister_disk sets h->drv[drv_index].queue = NULL | 1908 | /* deregister_disk sets h->drv[drv_index]->queue = NULL |
1748 | * which keeps the interrupt handler from starting | 1909 | * which keeps the interrupt handler from starting |
1749 | * the queue. | 1910 | * the queue. |
1750 | */ | 1911 | */ |
1751 | ret = deregister_disk(h, drv_index, 0); | 1912 | ret = deregister_disk(h, drv_index, 0, via_ioctl); |
1752 | h->drv[drv_index].busy_configuring = 0; | ||
1753 | } | 1913 | } |
1754 | 1914 | ||
1755 | /* If the disk is in use return */ | 1915 | /* If the disk is in use return */ |
@@ -1757,22 +1917,31 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) | |||
1757 | goto freeret; | 1917 | goto freeret; |
1758 | 1918 | ||
1759 | /* Save the new information from cciss_geometry_inquiry | 1919 | /* Save the new information from cciss_geometry_inquiry |
1760 | * and serial number inquiry. | 1920 | * and serial number inquiry. If the disk was deregistered |
1921 | * above, then h->drv[drv_index] will be NULL. | ||
1761 | */ | 1922 | */ |
1762 | h->drv[drv_index].block_size = drvinfo->block_size; | 1923 | if (h->drv[drv_index] == NULL) { |
1763 | h->drv[drv_index].nr_blocks = drvinfo->nr_blocks; | 1924 | drvinfo->device_initialized = 0; |
1764 | h->drv[drv_index].heads = drvinfo->heads; | 1925 | h->drv[drv_index] = drvinfo; |
1765 | h->drv[drv_index].sectors = drvinfo->sectors; | 1926 | drvinfo = NULL; /* so it won't be freed below. */ |
1766 | h->drv[drv_index].cylinders = drvinfo->cylinders; | 1927 | } else { |
1767 | h->drv[drv_index].raid_level = drvinfo->raid_level; | 1928 | /* special case for cxd0 */ |
1768 | memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16); | 1929 | h->drv[drv_index]->block_size = drvinfo->block_size; |
1769 | memcpy(h->drv[drv_index].vendor, drvinfo->vendor, VENDOR_LEN + 1); | 1930 | h->drv[drv_index]->nr_blocks = drvinfo->nr_blocks; |
1770 | memcpy(h->drv[drv_index].model, drvinfo->model, MODEL_LEN + 1); | 1931 | h->drv[drv_index]->heads = drvinfo->heads; |
1771 | memcpy(h->drv[drv_index].rev, drvinfo->rev, REV_LEN + 1); | 1932 | h->drv[drv_index]->sectors = drvinfo->sectors; |
1933 | h->drv[drv_index]->cylinders = drvinfo->cylinders; | ||
1934 | h->drv[drv_index]->raid_level = drvinfo->raid_level; | ||
1935 | memcpy(h->drv[drv_index]->serial_no, drvinfo->serial_no, 16); | ||
1936 | memcpy(h->drv[drv_index]->vendor, drvinfo->vendor, | ||
1937 | VENDOR_LEN + 1); | ||
1938 | memcpy(h->drv[drv_index]->model, drvinfo->model, MODEL_LEN + 1); | ||
1939 | memcpy(h->drv[drv_index]->rev, drvinfo->rev, REV_LEN + 1); | ||
1940 | } | ||
1772 | 1941 | ||
1773 | ++h->num_luns; | 1942 | ++h->num_luns; |
1774 | disk = h->gendisk[drv_index]; | 1943 | disk = h->gendisk[drv_index]; |
1775 | set_capacity(disk, h->drv[drv_index].nr_blocks); | 1944 | set_capacity(disk, h->drv[drv_index]->nr_blocks); |
1776 | 1945 | ||
1777 | /* If it's not disk 0 (drv_index != 0) | 1946 | /* If it's not disk 0 (drv_index != 0) |
1778 | * or if it was disk 0, but there was previously | 1947 | * or if it was disk 0, but there was previously |
@@ -1780,8 +1949,15 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) | |||
1780 | * (raid_leve == -1) then we want to update the | 1949 | * (raid_leve == -1) then we want to update the |
1781 | * logical drive's information. | 1950 | * logical drive's information. |
1782 | */ | 1951 | */ |
1783 | if (drv_index || first_time) | 1952 | if (drv_index || first_time) { |
1784 | cciss_add_disk(h, disk, drv_index); | 1953 | if (cciss_add_disk(h, disk, drv_index) != 0) { |
1954 | cciss_free_gendisk(h, drv_index); | ||
1955 | cciss_free_drive_info(h, drv_index); | ||
1956 | printk(KERN_WARNING "cciss:%d could not update " | ||
1957 | "disk %d\n", h->ctlr, drv_index); | ||
1958 | --h->num_luns; | ||
1959 | } | ||
1960 | } | ||
1785 | 1961 | ||
1786 | freeret: | 1962 | freeret: |
1787 | kfree(inq_buff); | 1963 | kfree(inq_buff); |
@@ -1793,28 +1969,70 @@ mem_msg: | |||
1793 | } | 1969 | } |
1794 | 1970 | ||
1795 | /* This function will find the first index of the controllers drive array | 1971 | /* This function will find the first index of the controllers drive array |
1796 | * that has a -1 for the raid_level and will return that index. This is | 1972 | * that has a null drv pointer and allocate the drive info struct and |
1797 | * where new drives will be added. If the index to be returned is greater | 1973 | * will return that index This is where new drives will be added. |
1798 | * than the highest_lun index for the controller then highest_lun is set | 1974 | * If the index to be returned is greater than the highest_lun index for |
1799 | * to this new index. If there are no available indexes then -1 is returned. | 1975 | * the controller then highest_lun is set * to this new index. |
1800 | * "controller_node" is used to know if this is a real logical drive, or just | 1976 | * If there are no available indexes or if tha allocation fails, then -1 |
1801 | * the controller node, which determines if this counts towards highest_lun. | 1977 | * is returned. * "controller_node" is used to know if this is a real |
1978 | * logical drive, or just the controller node, which determines if this | ||
1979 | * counts towards highest_lun. | ||
1802 | */ | 1980 | */ |
1803 | static int cciss_find_free_drive_index(int ctlr, int controller_node) | 1981 | static int cciss_alloc_drive_info(ctlr_info_t *h, int controller_node) |
1804 | { | 1982 | { |
1805 | int i; | 1983 | int i; |
1984 | drive_info_struct *drv; | ||
1806 | 1985 | ||
1986 | /* Search for an empty slot for our drive info */ | ||
1807 | for (i = 0; i < CISS_MAX_LUN; i++) { | 1987 | for (i = 0; i < CISS_MAX_LUN; i++) { |
1808 | if (hba[ctlr]->drv[i].raid_level == -1) { | 1988 | |
1809 | if (i > hba[ctlr]->highest_lun) | 1989 | /* if not cxd0 case, and it's occupied, skip it. */ |
1810 | if (!controller_node) | 1990 | if (h->drv[i] && i != 0) |
1811 | hba[ctlr]->highest_lun = i; | 1991 | continue; |
1992 | /* | ||
1993 | * If it's cxd0 case, and drv is alloc'ed already, and a | ||
1994 | * disk is configured there, skip it. | ||
1995 | */ | ||
1996 | if (i == 0 && h->drv[i] && h->drv[i]->raid_level != -1) | ||
1997 | continue; | ||
1998 | |||
1999 | /* | ||
2000 | * We've found an empty slot. Update highest_lun | ||
2001 | * provided this isn't just the fake cxd0 controller node. | ||
2002 | */ | ||
2003 | if (i > h->highest_lun && !controller_node) | ||
2004 | h->highest_lun = i; | ||
2005 | |||
2006 | /* If adding a real disk at cxd0, and it's already alloc'ed */ | ||
2007 | if (i == 0 && h->drv[i] != NULL) | ||
1812 | return i; | 2008 | return i; |
1813 | } | 2009 | |
2010 | /* | ||
2011 | * Found an empty slot, not already alloc'ed. Allocate it. | ||
2012 | * Mark it with raid_level == -1, so we know it's new later on. | ||
2013 | */ | ||
2014 | drv = kzalloc(sizeof(*drv), GFP_KERNEL); | ||
2015 | if (!drv) | ||
2016 | return -1; | ||
2017 | drv->raid_level = -1; /* so we know it's new */ | ||
2018 | h->drv[i] = drv; | ||
2019 | return i; | ||
1814 | } | 2020 | } |
1815 | return -1; | 2021 | return -1; |
1816 | } | 2022 | } |
1817 | 2023 | ||
2024 | static void cciss_free_drive_info(ctlr_info_t *h, int drv_index) | ||
2025 | { | ||
2026 | kfree(h->drv[drv_index]); | ||
2027 | h->drv[drv_index] = NULL; | ||
2028 | } | ||
2029 | |||
2030 | static void cciss_free_gendisk(ctlr_info_t *h, int drv_index) | ||
2031 | { | ||
2032 | put_disk(h->gendisk[drv_index]); | ||
2033 | h->gendisk[drv_index] = NULL; | ||
2034 | } | ||
2035 | |||
1818 | /* cciss_add_gendisk finds a free hba[]->drv structure | 2036 | /* cciss_add_gendisk finds a free hba[]->drv structure |
1819 | * and allocates a gendisk if needed, and sets the lunid | 2037 | * and allocates a gendisk if needed, and sets the lunid |
1820 | * in the drvinfo structure. It returns the index into | 2038 | * in the drvinfo structure. It returns the index into |
@@ -1824,13 +2042,15 @@ static int cciss_find_free_drive_index(int ctlr, int controller_node) | |||
1824 | * a means to talk to the controller in case no logical | 2042 | * a means to talk to the controller in case no logical |
1825 | * drives have yet been configured. | 2043 | * drives have yet been configured. |
1826 | */ | 2044 | */ |
1827 | static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node) | 2045 | static int cciss_add_gendisk(ctlr_info_t *h, unsigned char lunid[], |
2046 | int controller_node) | ||
1828 | { | 2047 | { |
1829 | int drv_index; | 2048 | int drv_index; |
1830 | 2049 | ||
1831 | drv_index = cciss_find_free_drive_index(h->ctlr, controller_node); | 2050 | drv_index = cciss_alloc_drive_info(h, controller_node); |
1832 | if (drv_index == -1) | 2051 | if (drv_index == -1) |
1833 | return -1; | 2052 | return -1; |
2053 | |||
1834 | /*Check if the gendisk needs to be allocated */ | 2054 | /*Check if the gendisk needs to be allocated */ |
1835 | if (!h->gendisk[drv_index]) { | 2055 | if (!h->gendisk[drv_index]) { |
1836 | h->gendisk[drv_index] = | 2056 | h->gendisk[drv_index] = |
@@ -1839,23 +2059,24 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node) | |||
1839 | printk(KERN_ERR "cciss%d: could not " | 2059 | printk(KERN_ERR "cciss%d: could not " |
1840 | "allocate a new disk %d\n", | 2060 | "allocate a new disk %d\n", |
1841 | h->ctlr, drv_index); | 2061 | h->ctlr, drv_index); |
1842 | return -1; | 2062 | goto err_free_drive_info; |
1843 | } | 2063 | } |
1844 | } | 2064 | } |
1845 | h->drv[drv_index].LunID = lunid; | 2065 | memcpy(h->drv[drv_index]->LunID, lunid, |
1846 | if (cciss_create_ld_sysfs_entry(h, &h->drv[drv_index], drv_index)) | 2066 | sizeof(h->drv[drv_index]->LunID)); |
2067 | if (cciss_create_ld_sysfs_entry(h, drv_index)) | ||
1847 | goto err_free_disk; | 2068 | goto err_free_disk; |
1848 | |||
1849 | /* Don't need to mark this busy because nobody */ | 2069 | /* Don't need to mark this busy because nobody */ |
1850 | /* else knows about this disk yet to contend */ | 2070 | /* else knows about this disk yet to contend */ |
1851 | /* for access to it. */ | 2071 | /* for access to it. */ |
1852 | h->drv[drv_index].busy_configuring = 0; | 2072 | h->drv[drv_index]->busy_configuring = 0; |
1853 | wmb(); | 2073 | wmb(); |
1854 | return drv_index; | 2074 | return drv_index; |
1855 | 2075 | ||
1856 | err_free_disk: | 2076 | err_free_disk: |
1857 | put_disk(h->gendisk[drv_index]); | 2077 | cciss_free_gendisk(h, drv_index); |
1858 | h->gendisk[drv_index] = NULL; | 2078 | err_free_drive_info: |
2079 | cciss_free_drive_info(h, drv_index); | ||
1859 | return -1; | 2080 | return -1; |
1860 | } | 2081 | } |
1861 | 2082 | ||
@@ -1872,21 +2093,25 @@ static void cciss_add_controller_node(ctlr_info_t *h) | |||
1872 | if (h->gendisk[0] != NULL) /* already did this? Then bail. */ | 2093 | if (h->gendisk[0] != NULL) /* already did this? Then bail. */ |
1873 | return; | 2094 | return; |
1874 | 2095 | ||
1875 | drv_index = cciss_add_gendisk(h, 0, 1); | 2096 | drv_index = cciss_add_gendisk(h, CTLR_LUNID, 1); |
1876 | if (drv_index == -1) { | 2097 | if (drv_index == -1) |
1877 | printk(KERN_WARNING "cciss%d: could not " | 2098 | goto error; |
1878 | "add disk 0.\n", h->ctlr); | 2099 | h->drv[drv_index]->block_size = 512; |
1879 | return; | 2100 | h->drv[drv_index]->nr_blocks = 0; |
1880 | } | 2101 | h->drv[drv_index]->heads = 0; |
1881 | h->drv[drv_index].block_size = 512; | 2102 | h->drv[drv_index]->sectors = 0; |
1882 | h->drv[drv_index].nr_blocks = 0; | 2103 | h->drv[drv_index]->cylinders = 0; |
1883 | h->drv[drv_index].heads = 0; | 2104 | h->drv[drv_index]->raid_level = -1; |
1884 | h->drv[drv_index].sectors = 0; | 2105 | memset(h->drv[drv_index]->serial_no, 0, 16); |
1885 | h->drv[drv_index].cylinders = 0; | ||
1886 | h->drv[drv_index].raid_level = -1; | ||
1887 | memset(h->drv[drv_index].serial_no, 0, 16); | ||
1888 | disk = h->gendisk[drv_index]; | 2106 | disk = h->gendisk[drv_index]; |
1889 | cciss_add_disk(h, disk, drv_index); | 2107 | if (cciss_add_disk(h, disk, drv_index) == 0) |
2108 | return; | ||
2109 | cciss_free_gendisk(h, drv_index); | ||
2110 | cciss_free_drive_info(h, drv_index); | ||
2111 | error: | ||
2112 | printk(KERN_WARNING "cciss%d: could not " | ||
2113 | "add disk 0.\n", h->ctlr); | ||
2114 | return; | ||
1890 | } | 2115 | } |
1891 | 2116 | ||
1892 | /* This function will add and remove logical drives from the Logical | 2117 | /* This function will add and remove logical drives from the Logical |
@@ -1897,7 +2122,8 @@ static void cciss_add_controller_node(ctlr_info_t *h) | |||
1897 | * INPUT | 2122 | * INPUT |
1898 | * h = The controller to perform the operations on | 2123 | * h = The controller to perform the operations on |
1899 | */ | 2124 | */ |
1900 | static int rebuild_lun_table(ctlr_info_t *h, int first_time) | 2125 | static int rebuild_lun_table(ctlr_info_t *h, int first_time, |
2126 | int via_ioctl) | ||
1901 | { | 2127 | { |
1902 | int ctlr = h->ctlr; | 2128 | int ctlr = h->ctlr; |
1903 | int num_luns; | 2129 | int num_luns; |
@@ -1907,7 +2133,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time) | |||
1907 | int i; | 2133 | int i; |
1908 | int drv_found; | 2134 | int drv_found; |
1909 | int drv_index = 0; | 2135 | int drv_index = 0; |
1910 | __u32 lunid = 0; | 2136 | unsigned char lunid[8] = CTLR_LUNID; |
1911 | unsigned long flags; | 2137 | unsigned long flags; |
1912 | 2138 | ||
1913 | if (!capable(CAP_SYS_RAWIO)) | 2139 | if (!capable(CAP_SYS_RAWIO)) |
@@ -1960,13 +2186,13 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time) | |||
1960 | drv_found = 0; | 2186 | drv_found = 0; |
1961 | 2187 | ||
1962 | /* skip holes in the array from already deleted drives */ | 2188 | /* skip holes in the array from already deleted drives */ |
1963 | if (h->drv[i].raid_level == -1) | 2189 | if (h->drv[i] == NULL) |
1964 | continue; | 2190 | continue; |
1965 | 2191 | ||
1966 | for (j = 0; j < num_luns; j++) { | 2192 | for (j = 0; j < num_luns; j++) { |
1967 | memcpy(&lunid, &ld_buff->LUN[j][0], 4); | 2193 | memcpy(lunid, &ld_buff->LUN[j][0], sizeof(lunid)); |
1968 | lunid = le32_to_cpu(lunid); | 2194 | if (memcmp(h->drv[i]->LunID, lunid, |
1969 | if (h->drv[i].LunID == lunid) { | 2195 | sizeof(lunid)) == 0) { |
1970 | drv_found = 1; | 2196 | drv_found = 1; |
1971 | break; | 2197 | break; |
1972 | } | 2198 | } |
@@ -1974,11 +2200,11 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time) | |||
1974 | if (!drv_found) { | 2200 | if (!drv_found) { |
1975 | /* Deregister it from the OS, it's gone. */ | 2201 | /* Deregister it from the OS, it's gone. */ |
1976 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); | 2202 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); |
1977 | h->drv[i].busy_configuring = 1; | 2203 | h->drv[i]->busy_configuring = 1; |
1978 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); | 2204 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
1979 | return_code = deregister_disk(h, i, 1); | 2205 | return_code = deregister_disk(h, i, 1, via_ioctl); |
1980 | cciss_destroy_ld_sysfs_entry(&h->drv[i]); | 2206 | if (h->drv[i] != NULL) |
1981 | h->drv[i].busy_configuring = 0; | 2207 | h->drv[i]->busy_configuring = 0; |
1982 | } | 2208 | } |
1983 | } | 2209 | } |
1984 | 2210 | ||
@@ -1992,17 +2218,16 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time) | |||
1992 | 2218 | ||
1993 | drv_found = 0; | 2219 | drv_found = 0; |
1994 | 2220 | ||
1995 | memcpy(&lunid, &ld_buff->LUN[i][0], 4); | 2221 | memcpy(lunid, &ld_buff->LUN[i][0], sizeof(lunid)); |
1996 | lunid = le32_to_cpu(lunid); | ||
1997 | |||
1998 | /* Find if the LUN is already in the drive array | 2222 | /* Find if the LUN is already in the drive array |
1999 | * of the driver. If so then update its info | 2223 | * of the driver. If so then update its info |
2000 | * if not in use. If it does not exist then find | 2224 | * if not in use. If it does not exist then find |
2001 | * the first free index and add it. | 2225 | * the first free index and add it. |
2002 | */ | 2226 | */ |
2003 | for (j = 0; j <= h->highest_lun; j++) { | 2227 | for (j = 0; j <= h->highest_lun; j++) { |
2004 | if (h->drv[j].raid_level != -1 && | 2228 | if (h->drv[j] != NULL && |
2005 | h->drv[j].LunID == lunid) { | 2229 | memcmp(h->drv[j]->LunID, lunid, |
2230 | sizeof(h->drv[j]->LunID)) == 0) { | ||
2006 | drv_index = j; | 2231 | drv_index = j; |
2007 | drv_found = 1; | 2232 | drv_found = 1; |
2008 | break; | 2233 | break; |
@@ -2015,7 +2240,8 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time) | |||
2015 | if (drv_index == -1) | 2240 | if (drv_index == -1) |
2016 | goto freeret; | 2241 | goto freeret; |
2017 | } | 2242 | } |
2018 | cciss_update_drive_info(ctlr, drv_index, first_time); | 2243 | cciss_update_drive_info(ctlr, drv_index, first_time, |
2244 | via_ioctl); | ||
2019 | } /* end for */ | 2245 | } /* end for */ |
2020 | 2246 | ||
2021 | freeret: | 2247 | freeret: |
@@ -2032,6 +2258,25 @@ mem_msg: | |||
2032 | goto freeret; | 2258 | goto freeret; |
2033 | } | 2259 | } |
2034 | 2260 | ||
2261 | static void cciss_clear_drive_info(drive_info_struct *drive_info) | ||
2262 | { | ||
2263 | /* zero out the disk size info */ | ||
2264 | drive_info->nr_blocks = 0; | ||
2265 | drive_info->block_size = 0; | ||
2266 | drive_info->heads = 0; | ||
2267 | drive_info->sectors = 0; | ||
2268 | drive_info->cylinders = 0; | ||
2269 | drive_info->raid_level = -1; | ||
2270 | memset(drive_info->serial_no, 0, sizeof(drive_info->serial_no)); | ||
2271 | memset(drive_info->model, 0, sizeof(drive_info->model)); | ||
2272 | memset(drive_info->rev, 0, sizeof(drive_info->rev)); | ||
2273 | memset(drive_info->vendor, 0, sizeof(drive_info->vendor)); | ||
2274 | /* | ||
2275 | * don't clear the LUNID though, we need to remember which | ||
2276 | * one this one is. | ||
2277 | */ | ||
2278 | } | ||
2279 | |||
2035 | /* This function will deregister the disk and it's queue from the | 2280 | /* This function will deregister the disk and it's queue from the |
2036 | * kernel. It must be called with the controller lock held and the | 2281 | * kernel. It must be called with the controller lock held and the |
2037 | * drv structures busy_configuring flag set. It's parameters are: | 2282 | * drv structures busy_configuring flag set. It's parameters are: |
@@ -2046,43 +2291,48 @@ mem_msg: | |||
2046 | * the disk in preparation for re-adding it. In this case | 2291 | * the disk in preparation for re-adding it. In this case |
2047 | * the highest_lun should be left unchanged and the LunID | 2292 | * the highest_lun should be left unchanged and the LunID |
2048 | * should not be cleared. | 2293 | * should not be cleared. |
2294 | * via_ioctl | ||
2295 | * This indicates whether we've reached this path via ioctl. | ||
2296 | * This affects the maximum usage count allowed for c0d0 to be messed with. | ||
2297 | * If this path is reached via ioctl(), then the max_usage_count will | ||
2298 | * be 1, as the process calling ioctl() has got to have the device open. | ||
2299 | * If we get here via sysfs, then the max usage count will be zero. | ||
2049 | */ | 2300 | */ |
2050 | static int deregister_disk(ctlr_info_t *h, int drv_index, | 2301 | static int deregister_disk(ctlr_info_t *h, int drv_index, |
2051 | int clear_all) | 2302 | int clear_all, int via_ioctl) |
2052 | { | 2303 | { |
2053 | int i; | 2304 | int i; |
2054 | struct gendisk *disk; | 2305 | struct gendisk *disk; |
2055 | drive_info_struct *drv; | 2306 | drive_info_struct *drv; |
2307 | int recalculate_highest_lun; | ||
2056 | 2308 | ||
2057 | if (!capable(CAP_SYS_RAWIO)) | 2309 | if (!capable(CAP_SYS_RAWIO)) |
2058 | return -EPERM; | 2310 | return -EPERM; |
2059 | 2311 | ||
2060 | drv = &h->drv[drv_index]; | 2312 | drv = h->drv[drv_index]; |
2061 | disk = h->gendisk[drv_index]; | 2313 | disk = h->gendisk[drv_index]; |
2062 | 2314 | ||
2063 | /* make sure logical volume is NOT is use */ | 2315 | /* make sure logical volume is NOT is use */ |
2064 | if (clear_all || (h->gendisk[0] == disk)) { | 2316 | if (clear_all || (h->gendisk[0] == disk)) { |
2065 | if (drv->usage_count > 1) | 2317 | if (drv->usage_count > via_ioctl) |
2066 | return -EBUSY; | 2318 | return -EBUSY; |
2067 | } else if (drv->usage_count > 0) | 2319 | } else if (drv->usage_count > 0) |
2068 | return -EBUSY; | 2320 | return -EBUSY; |
2069 | 2321 | ||
2322 | recalculate_highest_lun = (drv == h->drv[h->highest_lun]); | ||
2323 | |||
2070 | /* invalidate the devices and deregister the disk. If it is disk | 2324 | /* invalidate the devices and deregister the disk. If it is disk |
2071 | * zero do not deregister it but just zero out it's values. This | 2325 | * zero do not deregister it but just zero out it's values. This |
2072 | * allows us to delete disk zero but keep the controller registered. | 2326 | * allows us to delete disk zero but keep the controller registered. |
2073 | */ | 2327 | */ |
2074 | if (h->gendisk[0] != disk) { | 2328 | if (h->gendisk[0] != disk) { |
2075 | struct request_queue *q = disk->queue; | 2329 | struct request_queue *q = disk->queue; |
2076 | if (disk->flags & GENHD_FL_UP) | 2330 | if (disk->flags & GENHD_FL_UP) { |
2331 | cciss_destroy_ld_sysfs_entry(h, drv_index, 0); | ||
2077 | del_gendisk(disk); | 2332 | del_gendisk(disk); |
2078 | if (q) { | ||
2079 | blk_cleanup_queue(q); | ||
2080 | /* Set drv->queue to NULL so that we do not try | ||
2081 | * to call blk_start_queue on this queue in the | ||
2082 | * interrupt handler | ||
2083 | */ | ||
2084 | drv->queue = NULL; | ||
2085 | } | 2333 | } |
2334 | if (q) | ||
2335 | blk_cleanup_queue(q); | ||
2086 | /* If clear_all is set then we are deleting the logical | 2336 | /* If clear_all is set then we are deleting the logical |
2087 | * drive, not just refreshing its info. For drives | 2337 | * drive, not just refreshing its info. For drives |
2088 | * other than disk 0 we will call put_disk. We do not | 2338 | * other than disk 0 we will call put_disk. We do not |
@@ -2105,34 +2355,20 @@ static int deregister_disk(ctlr_info_t *h, int drv_index, | |||
2105 | } | 2355 | } |
2106 | } else { | 2356 | } else { |
2107 | set_capacity(disk, 0); | 2357 | set_capacity(disk, 0); |
2358 | cciss_clear_drive_info(drv); | ||
2108 | } | 2359 | } |
2109 | 2360 | ||
2110 | --h->num_luns; | 2361 | --h->num_luns; |
2111 | /* zero out the disk size info */ | ||
2112 | drv->nr_blocks = 0; | ||
2113 | drv->block_size = 0; | ||
2114 | drv->heads = 0; | ||
2115 | drv->sectors = 0; | ||
2116 | drv->cylinders = 0; | ||
2117 | drv->raid_level = -1; /* This can be used as a flag variable to | ||
2118 | * indicate that this element of the drive | ||
2119 | * array is free. | ||
2120 | */ | ||
2121 | |||
2122 | if (clear_all) { | ||
2123 | /* check to see if it was the last disk */ | ||
2124 | if (drv == h->drv + h->highest_lun) { | ||
2125 | /* if so, find the new hightest lun */ | ||
2126 | int i, newhighest = -1; | ||
2127 | for (i = 0; i <= h->highest_lun; i++) { | ||
2128 | /* if the disk has size > 0, it is available */ | ||
2129 | if (h->drv[i].heads) | ||
2130 | newhighest = i; | ||
2131 | } | ||
2132 | h->highest_lun = newhighest; | ||
2133 | } | ||
2134 | 2362 | ||
2135 | drv->LunID = 0; | 2363 | /* if it was the last disk, find the new hightest lun */ |
2364 | if (clear_all && recalculate_highest_lun) { | ||
2365 | int i, newhighest = -1; | ||
2366 | for (i = 0; i <= h->highest_lun; i++) { | ||
2367 | /* if the disk has size > 0, it is available */ | ||
2368 | if (h->drv[i] && h->drv[i]->heads) | ||
2369 | newhighest = i; | ||
2370 | } | ||
2371 | h->highest_lun = newhighest; | ||
2136 | } | 2372 | } |
2137 | return 0; | 2373 | return 0; |
2138 | } | 2374 | } |
@@ -2479,8 +2715,6 @@ static void cciss_geometry_inquiry(int ctlr, int logvol, | |||
2479 | } else { /* Get geometry failed */ | 2715 | } else { /* Get geometry failed */ |
2480 | printk(KERN_WARNING "cciss: reading geometry failed\n"); | 2716 | printk(KERN_WARNING "cciss: reading geometry failed\n"); |
2481 | } | 2717 | } |
2482 | printk(KERN_INFO " heads=%d, sectors=%d, cylinders=%d\n\n", | ||
2483 | drv->heads, drv->sectors, drv->cylinders); | ||
2484 | } | 2718 | } |
2485 | 2719 | ||
2486 | static void | 2720 | static void |
@@ -2514,9 +2748,6 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size, | |||
2514 | *total_size = 0; | 2748 | *total_size = 0; |
2515 | *block_size = BLOCK_SIZE; | 2749 | *block_size = BLOCK_SIZE; |
2516 | } | 2750 | } |
2517 | if (*total_size != 0) | ||
2518 | printk(KERN_INFO " blocks= %llu block_size= %d\n", | ||
2519 | (unsigned long long)*total_size+1, *block_size); | ||
2520 | kfree(buf); | 2751 | kfree(buf); |
2521 | } | 2752 | } |
2522 | 2753 | ||
@@ -2568,7 +2799,8 @@ static int cciss_revalidate(struct gendisk *disk) | |||
2568 | InquiryData_struct *inq_buff = NULL; | 2799 | InquiryData_struct *inq_buff = NULL; |
2569 | 2800 | ||
2570 | for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) { | 2801 | for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) { |
2571 | if (h->drv[logvol].LunID == drv->LunID) { | 2802 | if (memcmp(h->drv[logvol]->LunID, drv->LunID, |
2803 | sizeof(drv->LunID)) == 0) { | ||
2572 | FOUND = 1; | 2804 | FOUND = 1; |
2573 | break; | 2805 | break; |
2574 | } | 2806 | } |
@@ -3053,8 +3285,7 @@ static void do_cciss_request(struct request_queue *q) | |||
3053 | /* The first 2 bits are reserved for controller error reporting. */ | 3285 | /* The first 2 bits are reserved for controller error reporting. */ |
3054 | c->Header.Tag.lower = (c->cmdindex << 3); | 3286 | c->Header.Tag.lower = (c->cmdindex << 3); |
3055 | c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */ | 3287 | c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */ |
3056 | c->Header.LUN.LogDev.VolId = drv->LunID; | 3288 | memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID)); |
3057 | c->Header.LUN.LogDev.Mode = 1; | ||
3058 | c->Request.CDBLen = 10; // 12 byte commands not in FW yet; | 3289 | c->Request.CDBLen = 10; // 12 byte commands not in FW yet; |
3059 | c->Request.Type.Type = TYPE_CMD; // It is a command. | 3290 | c->Request.Type.Type = TYPE_CMD; // It is a command. |
3060 | c->Request.Type.Attribute = ATTR_SIMPLE; | 3291 | c->Request.Type.Attribute = ATTR_SIMPLE; |
@@ -3232,20 +3463,121 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id) | |||
3232 | return IRQ_HANDLED; | 3463 | return IRQ_HANDLED; |
3233 | } | 3464 | } |
3234 | 3465 | ||
3466 | /** | ||
3467 | * add_to_scan_list() - add controller to rescan queue | ||
3468 | * @h: Pointer to the controller. | ||
3469 | * | ||
3470 | * Adds the controller to the rescan queue if not already on the queue. | ||
3471 | * | ||
3472 | * returns 1 if added to the queue, 0 if skipped (could be on the | ||
3473 | * queue already, or the controller could be initializing or shutting | ||
3474 | * down). | ||
3475 | **/ | ||
3476 | static int add_to_scan_list(struct ctlr_info *h) | ||
3477 | { | ||
3478 | struct ctlr_info *test_h; | ||
3479 | int found = 0; | ||
3480 | int ret = 0; | ||
3481 | |||
3482 | if (h->busy_initializing) | ||
3483 | return 0; | ||
3484 | |||
3485 | if (!mutex_trylock(&h->busy_shutting_down)) | ||
3486 | return 0; | ||
3487 | |||
3488 | mutex_lock(&scan_mutex); | ||
3489 | list_for_each_entry(test_h, &scan_q, scan_list) { | ||
3490 | if (test_h == h) { | ||
3491 | found = 1; | ||
3492 | break; | ||
3493 | } | ||
3494 | } | ||
3495 | if (!found && !h->busy_scanning) { | ||
3496 | INIT_COMPLETION(h->scan_wait); | ||
3497 | list_add_tail(&h->scan_list, &scan_q); | ||
3498 | ret = 1; | ||
3499 | } | ||
3500 | mutex_unlock(&scan_mutex); | ||
3501 | mutex_unlock(&h->busy_shutting_down); | ||
3502 | |||
3503 | return ret; | ||
3504 | } | ||
3505 | |||
3506 | /** | ||
3507 | * remove_from_scan_list() - remove controller from rescan queue | ||
3508 | * @h: Pointer to the controller. | ||
3509 | * | ||
3510 | * Removes the controller from the rescan queue if present. Blocks if | ||
3511 | * the controller is currently conducting a rescan. | ||
3512 | **/ | ||
3513 | static void remove_from_scan_list(struct ctlr_info *h) | ||
3514 | { | ||
3515 | struct ctlr_info *test_h, *tmp_h; | ||
3516 | int scanning = 0; | ||
3517 | |||
3518 | mutex_lock(&scan_mutex); | ||
3519 | list_for_each_entry_safe(test_h, tmp_h, &scan_q, scan_list) { | ||
3520 | if (test_h == h) { | ||
3521 | list_del(&h->scan_list); | ||
3522 | complete_all(&h->scan_wait); | ||
3523 | mutex_unlock(&scan_mutex); | ||
3524 | return; | ||
3525 | } | ||
3526 | } | ||
3527 | if (&h->busy_scanning) | ||
3528 | scanning = 0; | ||
3529 | mutex_unlock(&scan_mutex); | ||
3530 | |||
3531 | if (scanning) | ||
3532 | wait_for_completion(&h->scan_wait); | ||
3533 | } | ||
3534 | |||
3535 | /** | ||
3536 | * scan_thread() - kernel thread used to rescan controllers | ||
3537 | * @data: Ignored. | ||
3538 | * | ||
3539 | * A kernel thread used scan for drive topology changes on | ||
3540 | * controllers. The thread processes only one controller at a time | ||
3541 | * using a queue. Controllers are added to the queue using | ||
3542 | * add_to_scan_list() and removed from the queue either after done | ||
3543 | * processing or using remove_from_scan_list(). | ||
3544 | * | ||
3545 | * returns 0. | ||
3546 | **/ | ||
3235 | static int scan_thread(void *data) | 3547 | static int scan_thread(void *data) |
3236 | { | 3548 | { |
3237 | ctlr_info_t *h = data; | 3549 | struct ctlr_info *h; |
3238 | int rc; | ||
3239 | DECLARE_COMPLETION_ONSTACK(wait); | ||
3240 | h->rescan_wait = &wait; | ||
3241 | 3550 | ||
3242 | for (;;) { | 3551 | while (1) { |
3243 | rc = wait_for_completion_interruptible(&wait); | 3552 | set_current_state(TASK_INTERRUPTIBLE); |
3553 | schedule(); | ||
3244 | if (kthread_should_stop()) | 3554 | if (kthread_should_stop()) |
3245 | break; | 3555 | break; |
3246 | if (!rc) | 3556 | |
3247 | rebuild_lun_table(h, 0); | 3557 | while (1) { |
3558 | mutex_lock(&scan_mutex); | ||
3559 | if (list_empty(&scan_q)) { | ||
3560 | mutex_unlock(&scan_mutex); | ||
3561 | break; | ||
3562 | } | ||
3563 | |||
3564 | h = list_entry(scan_q.next, | ||
3565 | struct ctlr_info, | ||
3566 | scan_list); | ||
3567 | list_del(&h->scan_list); | ||
3568 | h->busy_scanning = 1; | ||
3569 | mutex_unlock(&scan_mutex); | ||
3570 | |||
3571 | if (h) { | ||
3572 | rebuild_lun_table(h, 0, 0); | ||
3573 | complete_all(&h->scan_wait); | ||
3574 | mutex_lock(&scan_mutex); | ||
3575 | h->busy_scanning = 0; | ||
3576 | mutex_unlock(&scan_mutex); | ||
3577 | } | ||
3578 | } | ||
3248 | } | 3579 | } |
3580 | |||
3249 | return 0; | 3581 | return 0; |
3250 | } | 3582 | } |
3251 | 3583 | ||
@@ -3268,8 +3600,8 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c) | |||
3268 | case REPORT_LUNS_CHANGED: | 3600 | case REPORT_LUNS_CHANGED: |
3269 | printk(KERN_WARNING "cciss%d: report LUN data " | 3601 | printk(KERN_WARNING "cciss%d: report LUN data " |
3270 | "changed\n", h->ctlr); | 3602 | "changed\n", h->ctlr); |
3271 | if (h->rescan_wait) | 3603 | add_to_scan_list(h); |
3272 | complete(h->rescan_wait); | 3604 | wake_up_process(cciss_scan_thread); |
3273 | return 1; | 3605 | return 1; |
3274 | break; | 3606 | break; |
3275 | case POWER_OR_RESET: | 3607 | case POWER_OR_RESET: |
@@ -3489,7 +3821,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev) | |||
3489 | if (scratchpad == CCISS_FIRMWARE_READY) | 3821 | if (scratchpad == CCISS_FIRMWARE_READY) |
3490 | break; | 3822 | break; |
3491 | set_current_state(TASK_INTERRUPTIBLE); | 3823 | set_current_state(TASK_INTERRUPTIBLE); |
3492 | schedule_timeout(HZ / 10); /* wait 100ms */ | 3824 | schedule_timeout(msecs_to_jiffies(100)); /* wait 100ms */ |
3493 | } | 3825 | } |
3494 | if (scratchpad != CCISS_FIRMWARE_READY) { | 3826 | if (scratchpad != CCISS_FIRMWARE_READY) { |
3495 | printk(KERN_WARNING "cciss: Board not ready. Timed out.\n"); | 3827 | printk(KERN_WARNING "cciss: Board not ready. Timed out.\n"); |
@@ -3615,7 +3947,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev) | |||
3615 | break; | 3947 | break; |
3616 | /* delay and try again */ | 3948 | /* delay and try again */ |
3617 | set_current_state(TASK_INTERRUPTIBLE); | 3949 | set_current_state(TASK_INTERRUPTIBLE); |
3618 | schedule_timeout(10); | 3950 | schedule_timeout(msecs_to_jiffies(1)); |
3619 | } | 3951 | } |
3620 | 3952 | ||
3621 | #ifdef CCISS_DEBUG | 3953 | #ifdef CCISS_DEBUG |
@@ -3669,15 +4001,16 @@ Enomem: | |||
3669 | return -1; | 4001 | return -1; |
3670 | } | 4002 | } |
3671 | 4003 | ||
3672 | static void free_hba(int i) | 4004 | static void free_hba(int n) |
3673 | { | 4005 | { |
3674 | ctlr_info_t *p = hba[i]; | 4006 | ctlr_info_t *h = hba[n]; |
3675 | int n; | 4007 | int i; |
3676 | 4008 | ||
3677 | hba[i] = NULL; | 4009 | hba[n] = NULL; |
3678 | for (n = 0; n < CISS_MAX_LUN; n++) | 4010 | for (i = 0; i < h->highest_lun + 1; i++) |
3679 | put_disk(p->gendisk[n]); | 4011 | if (h->gendisk[i] != NULL) |
3680 | kfree(p); | 4012 | put_disk(h->gendisk[i]); |
4013 | kfree(h); | ||
3681 | } | 4014 | } |
3682 | 4015 | ||
3683 | /* Send a message CDB to the firmware. */ | 4016 | /* Send a message CDB to the firmware. */ |
@@ -3918,6 +4251,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
3918 | hba[i]->busy_initializing = 1; | 4251 | hba[i]->busy_initializing = 1; |
3919 | INIT_HLIST_HEAD(&hba[i]->cmpQ); | 4252 | INIT_HLIST_HEAD(&hba[i]->cmpQ); |
3920 | INIT_HLIST_HEAD(&hba[i]->reqQ); | 4253 | INIT_HLIST_HEAD(&hba[i]->reqQ); |
4254 | mutex_init(&hba[i]->busy_shutting_down); | ||
3921 | 4255 | ||
3922 | if (cciss_pci_init(hba[i], pdev) != 0) | 4256 | if (cciss_pci_init(hba[i], pdev) != 0) |
3923 | goto clean0; | 4257 | goto clean0; |
@@ -3926,6 +4260,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
3926 | hba[i]->ctlr = i; | 4260 | hba[i]->ctlr = i; |
3927 | hba[i]->pdev = pdev; | 4261 | hba[i]->pdev = pdev; |
3928 | 4262 | ||
4263 | init_completion(&hba[i]->scan_wait); | ||
4264 | |||
3929 | if (cciss_create_hba_sysfs_entry(hba[i])) | 4265 | if (cciss_create_hba_sysfs_entry(hba[i])) |
3930 | goto clean0; | 4266 | goto clean0; |
3931 | 4267 | ||
@@ -4001,8 +4337,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
4001 | hba[i]->num_luns = 0; | 4337 | hba[i]->num_luns = 0; |
4002 | hba[i]->highest_lun = -1; | 4338 | hba[i]->highest_lun = -1; |
4003 | for (j = 0; j < CISS_MAX_LUN; j++) { | 4339 | for (j = 0; j < CISS_MAX_LUN; j++) { |
4004 | hba[i]->drv[j].raid_level = -1; | 4340 | hba[i]->drv[j] = NULL; |
4005 | hba[i]->drv[j].queue = NULL; | ||
4006 | hba[i]->gendisk[j] = NULL; | 4341 | hba[i]->gendisk[j] = NULL; |
4007 | } | 4342 | } |
4008 | 4343 | ||
@@ -4035,14 +4370,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
4035 | 4370 | ||
4036 | hba[i]->cciss_max_sectors = 2048; | 4371 | hba[i]->cciss_max_sectors = 2048; |
4037 | 4372 | ||
4373 | rebuild_lun_table(hba[i], 1, 0); | ||
4038 | hba[i]->busy_initializing = 0; | 4374 | hba[i]->busy_initializing = 0; |
4039 | |||
4040 | rebuild_lun_table(hba[i], 1); | ||
4041 | hba[i]->cciss_scan_thread = kthread_run(scan_thread, hba[i], | ||
4042 | "cciss_scan%02d", i); | ||
4043 | if (IS_ERR(hba[i]->cciss_scan_thread)) | ||
4044 | return PTR_ERR(hba[i]->cciss_scan_thread); | ||
4045 | |||
4046 | return 1; | 4375 | return 1; |
4047 | 4376 | ||
4048 | clean4: | 4377 | clean4: |
@@ -4063,12 +4392,7 @@ clean1: | |||
4063 | cciss_destroy_hba_sysfs_entry(hba[i]); | 4392 | cciss_destroy_hba_sysfs_entry(hba[i]); |
4064 | clean0: | 4393 | clean0: |
4065 | hba[i]->busy_initializing = 0; | 4394 | hba[i]->busy_initializing = 0; |
4066 | /* cleanup any queues that may have been initialized */ | 4395 | |
4067 | for (j=0; j <= hba[i]->highest_lun; j++){ | ||
4068 | drive_info_struct *drv = &(hba[i]->drv[j]); | ||
4069 | if (drv->queue) | ||
4070 | blk_cleanup_queue(drv->queue); | ||
4071 | } | ||
4072 | /* | 4396 | /* |
4073 | * Deliberately omit pci_disable_device(): it does something nasty to | 4397 | * Deliberately omit pci_disable_device(): it does something nasty to |
4074 | * Smart Array controllers that pci_enable_device does not undo | 4398 | * Smart Array controllers that pci_enable_device does not undo |
@@ -4125,8 +4449,9 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev) | |||
4125 | return; | 4449 | return; |
4126 | } | 4450 | } |
4127 | 4451 | ||
4128 | kthread_stop(hba[i]->cciss_scan_thread); | 4452 | mutex_lock(&hba[i]->busy_shutting_down); |
4129 | 4453 | ||
4454 | remove_from_scan_list(hba[i]); | ||
4130 | remove_proc_entry(hba[i]->devname, proc_cciss); | 4455 | remove_proc_entry(hba[i]->devname, proc_cciss); |
4131 | unregister_blkdev(hba[i]->major, hba[i]->devname); | 4456 | unregister_blkdev(hba[i]->major, hba[i]->devname); |
4132 | 4457 | ||
@@ -4136,8 +4461,10 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev) | |||
4136 | if (disk) { | 4461 | if (disk) { |
4137 | struct request_queue *q = disk->queue; | 4462 | struct request_queue *q = disk->queue; |
4138 | 4463 | ||
4139 | if (disk->flags & GENHD_FL_UP) | 4464 | if (disk->flags & GENHD_FL_UP) { |
4465 | cciss_destroy_ld_sysfs_entry(hba[i], j, 1); | ||
4140 | del_gendisk(disk); | 4466 | del_gendisk(disk); |
4467 | } | ||
4141 | if (q) | 4468 | if (q) |
4142 | blk_cleanup_queue(q); | 4469 | blk_cleanup_queue(q); |
4143 | } | 4470 | } |
@@ -4170,6 +4497,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev) | |||
4170 | pci_release_regions(pdev); | 4497 | pci_release_regions(pdev); |
4171 | pci_set_drvdata(pdev, NULL); | 4498 | pci_set_drvdata(pdev, NULL); |
4172 | cciss_destroy_hba_sysfs_entry(hba[i]); | 4499 | cciss_destroy_hba_sysfs_entry(hba[i]); |
4500 | mutex_unlock(&hba[i]->busy_shutting_down); | ||
4173 | free_hba(i); | 4501 | free_hba(i); |
4174 | } | 4502 | } |
4175 | 4503 | ||
@@ -4202,15 +4530,25 @@ static int __init cciss_init(void) | |||
4202 | if (err) | 4530 | if (err) |
4203 | return err; | 4531 | return err; |
4204 | 4532 | ||
4533 | /* Start the scan thread */ | ||
4534 | cciss_scan_thread = kthread_run(scan_thread, NULL, "cciss_scan"); | ||
4535 | if (IS_ERR(cciss_scan_thread)) { | ||
4536 | err = PTR_ERR(cciss_scan_thread); | ||
4537 | goto err_bus_unregister; | ||
4538 | } | ||
4539 | |||
4205 | /* Register for our PCI devices */ | 4540 | /* Register for our PCI devices */ |
4206 | err = pci_register_driver(&cciss_pci_driver); | 4541 | err = pci_register_driver(&cciss_pci_driver); |
4207 | if (err) | 4542 | if (err) |
4208 | goto err_bus_register; | 4543 | goto err_thread_stop; |
4209 | 4544 | ||
4210 | return 0; | 4545 | return err; |
4211 | 4546 | ||
4212 | err_bus_register: | 4547 | err_thread_stop: |
4548 | kthread_stop(cciss_scan_thread); | ||
4549 | err_bus_unregister: | ||
4213 | bus_unregister(&cciss_bus_type); | 4550 | bus_unregister(&cciss_bus_type); |
4551 | |||
4214 | return err; | 4552 | return err; |
4215 | } | 4553 | } |
4216 | 4554 | ||
@@ -4227,6 +4565,7 @@ static void __exit cciss_cleanup(void) | |||
4227 | cciss_remove_one(hba[i]->pdev); | 4565 | cciss_remove_one(hba[i]->pdev); |
4228 | } | 4566 | } |
4229 | } | 4567 | } |
4568 | kthread_stop(cciss_scan_thread); | ||
4230 | remove_proc_entry("driver/cciss", NULL); | 4569 | remove_proc_entry("driver/cciss", NULL); |
4231 | bus_unregister(&cciss_bus_type); | 4570 | bus_unregister(&cciss_bus_type); |
4232 | } | 4571 | } |