aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/cciss.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-08-10 18:22:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-10 18:22:42 -0400
commit2f9e825d3e0e2b407ae8f082de5c00afcf7378fb (patch)
treef8b3ee40674ce4acd5508a0a0bf52a30904caf6c /drivers/block/cciss.c
parent7ae0dea900b027cd90e8a3e14deca9a19e17638b (diff)
parentde75d60d5ea235e6e09f4962ab22541ce0fe176a (diff)
Merge branch 'for-2.6.36' of git://git.kernel.dk/linux-2.6-block
* 'for-2.6.36' of git://git.kernel.dk/linux-2.6-block: (149 commits) block: make sure that REQ_* types are seen even with CONFIG_BLOCK=n xen-blkfront: fix missing out label blkdev: fix blkdev_issue_zeroout return value block: update request stacking methods to support discards block: fix missing export of blk_types.h writeback: fix bad _bh spinlock nesting drbd: revert "delay probes", feature is being re-implemented differently drbd: Initialize all members of sync_conf to their defaults [Bugz 315] drbd: Disable delay probes for the upcomming release writeback: cleanup bdi_register writeback: add new tracepoints writeback: remove unnecessary init_timer call writeback: optimize periodic bdi thread wakeups writeback: prevent unnecessary bdi threads wakeups writeback: move bdi threads exiting logic to the forker thread writeback: restructure bdi forker loop a little writeback: move last_active to bdi writeback: do not remove bdi from bdi_list writeback: simplify bdi code a little writeback: do not lose wake-ups in bdi threads ... Fixed up pretty trivial conflicts in drivers/block/virtio_blk.c and drivers/scsi/scsi_error.c as per Jens.
Diffstat (limited to 'drivers/block/cciss.c')
-rw-r--r--drivers/block/cciss.c2165
1 files changed, 1281 insertions, 884 deletions
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index e1e7143ca1e3..31064df1370a 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -56,16 +56,14 @@
56#include <linux/kthread.h> 56#include <linux/kthread.h>
57 57
58#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin)) 58#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
59#define DRIVER_NAME "HP CISS Driver (v 3.6.20)" 59#define DRIVER_NAME "HP CISS Driver (v 3.6.26)"
60#define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 20) 60#define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 26)
61 61
62/* Embedded module documentation macros - see modules.h */ 62/* Embedded module documentation macros - see modules.h */
63MODULE_AUTHOR("Hewlett-Packard Company"); 63MODULE_AUTHOR("Hewlett-Packard Company");
64MODULE_DESCRIPTION("Driver for HP Smart Array Controllers"); 64MODULE_DESCRIPTION("Driver for HP Smart Array Controllers");
65MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400" 65MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
66 " SA6i P600 P800 P400 P400i E200 E200i E500 P700m" 66MODULE_VERSION("3.6.26");
67 " Smart Array G2 Series SAS/SATA Controllers");
68MODULE_VERSION("3.6.20");
69MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
70 68
71static int cciss_allow_hpsa; 69static int cciss_allow_hpsa;
@@ -107,6 +105,11 @@ static const struct pci_device_id cciss_pci_device_id[] = {
107 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, 105 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249},
108 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A}, 106 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A},
109 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B}, 107 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B},
108 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3250},
109 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3251},
110 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3252},
111 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3253},
112 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3254},
110 {0,} 113 {0,}
111}; 114};
112 115
@@ -146,6 +149,11 @@ static struct board_type products[] = {
146 {0x3249103C, "Smart Array P812", &SA5_access}, 149 {0x3249103C, "Smart Array P812", &SA5_access},
147 {0x324A103C, "Smart Array P712m", &SA5_access}, 150 {0x324A103C, "Smart Array P712m", &SA5_access},
148 {0x324B103C, "Smart Array P711m", &SA5_access}, 151 {0x324B103C, "Smart Array P711m", &SA5_access},
152 {0x3250103C, "Smart Array", &SA5_access},
153 {0x3251103C, "Smart Array", &SA5_access},
154 {0x3252103C, "Smart Array", &SA5_access},
155 {0x3253103C, "Smart Array", &SA5_access},
156 {0x3254103C, "Smart Array", &SA5_access},
149}; 157};
150 158
151/* How long to wait (in milliseconds) for board to go into simple mode */ 159/* How long to wait (in milliseconds) for board to go into simple mode */
@@ -167,9 +175,13 @@ static DEFINE_MUTEX(scan_mutex);
167static LIST_HEAD(scan_q); 175static LIST_HEAD(scan_q);
168 176
169static void do_cciss_request(struct request_queue *q); 177static void do_cciss_request(struct request_queue *q);
170static irqreturn_t do_cciss_intr(int irq, void *dev_id); 178static irqreturn_t do_cciss_intx(int irq, void *dev_id);
179static irqreturn_t do_cciss_msix_intr(int irq, void *dev_id);
171static int cciss_open(struct block_device *bdev, fmode_t mode); 180static int cciss_open(struct block_device *bdev, fmode_t mode);
181static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode);
172static int cciss_release(struct gendisk *disk, fmode_t mode); 182static int cciss_release(struct gendisk *disk, fmode_t mode);
183static int do_ioctl(struct block_device *bdev, fmode_t mode,
184 unsigned int cmd, unsigned long arg);
173static int cciss_ioctl(struct block_device *bdev, fmode_t mode, 185static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
174 unsigned int cmd, unsigned long arg); 186 unsigned int cmd, unsigned long arg);
175static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); 187static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
@@ -179,25 +191,23 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time, int via_ioctl);
179static int deregister_disk(ctlr_info_t *h, int drv_index, 191static int deregister_disk(ctlr_info_t *h, int drv_index,
180 int clear_all, int via_ioctl); 192 int clear_all, int via_ioctl);
181 193
182static void cciss_read_capacity(int ctlr, int logvol, 194static void cciss_read_capacity(ctlr_info_t *h, int logvol,
183 sector_t *total_size, unsigned int *block_size); 195 sector_t *total_size, unsigned int *block_size);
184static void cciss_read_capacity_16(int ctlr, int logvol, 196static void cciss_read_capacity_16(ctlr_info_t *h, int logvol,
185 sector_t *total_size, unsigned int *block_size); 197 sector_t *total_size, unsigned int *block_size);
186static void cciss_geometry_inquiry(int ctlr, int logvol, 198static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol,
187 sector_t total_size, 199 sector_t total_size,
188 unsigned int block_size, InquiryData_struct *inq_buff, 200 unsigned int block_size, InquiryData_struct *inq_buff,
189 drive_info_struct *drv); 201 drive_info_struct *drv);
190static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *, 202static void __devinit cciss_interrupt_mode(ctlr_info_t *);
191 __u32);
192static void start_io(ctlr_info_t *h); 203static void start_io(ctlr_info_t *h);
193static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 204static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
194 __u8 page_code, unsigned char scsi3addr[], 205 __u8 page_code, unsigned char scsi3addr[],
195 int cmd_type); 206 int cmd_type);
196static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c, 207static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
197 int attempt_retry); 208 int attempt_retry);
198static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c); 209static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
199 210
200static void fail_all_cmds(unsigned long ctlr);
201static int add_to_scan_list(struct ctlr_info *h); 211static int add_to_scan_list(struct ctlr_info *h);
202static int scan_thread(void *data); 212static int scan_thread(void *data);
203static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c); 213static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c);
@@ -205,11 +215,23 @@ static void cciss_hba_release(struct device *dev);
205static void cciss_device_release(struct device *dev); 215static void cciss_device_release(struct device *dev);
206static void cciss_free_gendisk(ctlr_info_t *h, int drv_index); 216static void cciss_free_gendisk(ctlr_info_t *h, int drv_index);
207static void cciss_free_drive_info(ctlr_info_t *h, int drv_index); 217static void cciss_free_drive_info(ctlr_info_t *h, int drv_index);
218static inline u32 next_command(ctlr_info_t *h);
219static int __devinit cciss_find_cfg_addrs(struct pci_dev *pdev,
220 void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index,
221 u64 *cfg_offset);
222static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
223 unsigned long *memory_bar);
224
225
226/* performant mode helper functions */
227static void calc_bucket_map(int *bucket, int num_buckets, int nsgs,
228 int *bucket_map);
229static void cciss_put_controller_into_performant_mode(ctlr_info_t *h);
208 230
209#ifdef CONFIG_PROC_FS 231#ifdef CONFIG_PROC_FS
210static void cciss_procinit(int i); 232static void cciss_procinit(ctlr_info_t *h);
211#else 233#else
212static void cciss_procinit(int i) 234static void cciss_procinit(ctlr_info_t *h)
213{ 235{
214} 236}
215#endif /* CONFIG_PROC_FS */ 237#endif /* CONFIG_PROC_FS */
@@ -221,9 +243,9 @@ static int cciss_compat_ioctl(struct block_device *, fmode_t,
221 243
222static const struct block_device_operations cciss_fops = { 244static const struct block_device_operations cciss_fops = {
223 .owner = THIS_MODULE, 245 .owner = THIS_MODULE,
224 .open = cciss_open, 246 .open = cciss_unlocked_open,
225 .release = cciss_release, 247 .release = cciss_release,
226 .locked_ioctl = cciss_ioctl, 248 .ioctl = do_ioctl,
227 .getgeo = cciss_getgeo, 249 .getgeo = cciss_getgeo,
228#ifdef CONFIG_COMPAT 250#ifdef CONFIG_COMPAT
229 .compat_ioctl = cciss_compat_ioctl, 251 .compat_ioctl = cciss_compat_ioctl,
@@ -231,6 +253,16 @@ static const struct block_device_operations cciss_fops = {
231 .revalidate_disk = cciss_revalidate, 253 .revalidate_disk = cciss_revalidate,
232}; 254};
233 255
256/* set_performant_mode: Modify the tag for cciss performant
257 * set bit 0 for pull model, bits 3-1 for block fetch
258 * register number
259 */
260static void set_performant_mode(ctlr_info_t *h, CommandList_struct *c)
261{
262 if (likely(h->transMethod == CFGTBL_Trans_Performant))
263 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
264}
265
234/* 266/*
235 * Enqueuing and dequeuing functions for cmdlists. 267 * Enqueuing and dequeuing functions for cmdlists.
236 */ 268 */
@@ -257,6 +289,18 @@ static inline void removeQ(CommandList_struct *c)
257 hlist_del_init(&c->list); 289 hlist_del_init(&c->list);
258} 290}
259 291
292static void enqueue_cmd_and_start_io(ctlr_info_t *h,
293 CommandList_struct *c)
294{
295 unsigned long flags;
296 set_performant_mode(h, c);
297 spin_lock_irqsave(&h->lock, flags);
298 addQ(&h->reqQ, c);
299 h->Qdepth++;
300 start_io(h);
301 spin_unlock_irqrestore(&h->lock, flags);
302}
303
260static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list, 304static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list,
261 int nr_cmds) 305 int nr_cmds)
262{ 306{
@@ -366,32 +410,31 @@ static void cciss_seq_show_header(struct seq_file *seq)
366 h->product_name, 410 h->product_name,
367 (unsigned long)h->board_id, 411 (unsigned long)h->board_id,
368 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], 412 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
369 h->firm_ver[3], (unsigned int)h->intr[SIMPLE_MODE_INT], 413 h->firm_ver[3], (unsigned int)h->intr[PERF_MODE_INT],
370 h->num_luns, 414 h->num_luns,
371 h->Qdepth, h->commands_outstanding, 415 h->Qdepth, h->commands_outstanding,
372 h->maxQsinceinit, h->max_outstanding, h->maxSG); 416 h->maxQsinceinit, h->max_outstanding, h->maxSG);
373 417
374#ifdef CONFIG_CISS_SCSI_TAPE 418#ifdef CONFIG_CISS_SCSI_TAPE
375 cciss_seq_tape_report(seq, h->ctlr); 419 cciss_seq_tape_report(seq, h);
376#endif /* CONFIG_CISS_SCSI_TAPE */ 420#endif /* CONFIG_CISS_SCSI_TAPE */
377} 421}
378 422
379static void *cciss_seq_start(struct seq_file *seq, loff_t *pos) 423static void *cciss_seq_start(struct seq_file *seq, loff_t *pos)
380{ 424{
381 ctlr_info_t *h = seq->private; 425 ctlr_info_t *h = seq->private;
382 unsigned ctlr = h->ctlr;
383 unsigned long flags; 426 unsigned long flags;
384 427
385 /* prevent displaying bogus info during configuration 428 /* prevent displaying bogus info during configuration
386 * or deconfiguration of a logical volume 429 * or deconfiguration of a logical volume
387 */ 430 */
388 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 431 spin_lock_irqsave(&h->lock, flags);
389 if (h->busy_configuring) { 432 if (h->busy_configuring) {
390 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 433 spin_unlock_irqrestore(&h->lock, flags);
391 return ERR_PTR(-EBUSY); 434 return ERR_PTR(-EBUSY);
392 } 435 }
393 h->busy_configuring = 1; 436 h->busy_configuring = 1;
394 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 437 spin_unlock_irqrestore(&h->lock, flags);
395 438
396 if (*pos == 0) 439 if (*pos == 0)
397 cciss_seq_show_header(seq); 440 cciss_seq_show_header(seq);
@@ -499,7 +542,7 @@ cciss_proc_write(struct file *file, const char __user *buf,
499 struct seq_file *seq = file->private_data; 542 struct seq_file *seq = file->private_data;
500 ctlr_info_t *h = seq->private; 543 ctlr_info_t *h = seq->private;
501 544
502 err = cciss_engage_scsi(h->ctlr); 545 err = cciss_engage_scsi(h);
503 if (err == 0) 546 if (err == 0)
504 err = length; 547 err = length;
505 } else 548 } else
@@ -522,7 +565,7 @@ static const struct file_operations cciss_proc_fops = {
522 .write = cciss_proc_write, 565 .write = cciss_proc_write,
523}; 566};
524 567
525static void __devinit cciss_procinit(int i) 568static void __devinit cciss_procinit(ctlr_info_t *h)
526{ 569{
527 struct proc_dir_entry *pde; 570 struct proc_dir_entry *pde;
528 571
@@ -530,9 +573,9 @@ static void __devinit cciss_procinit(int i)
530 proc_cciss = proc_mkdir("driver/cciss", NULL); 573 proc_cciss = proc_mkdir("driver/cciss", NULL);
531 if (!proc_cciss) 574 if (!proc_cciss)
532 return; 575 return;
533 pde = proc_create_data(hba[i]->devname, S_IWUSR | S_IRUSR | S_IRGRP | 576 pde = proc_create_data(h->devname, S_IWUSR | S_IRUSR | S_IRGRP |
534 S_IROTH, proc_cciss, 577 S_IROTH, proc_cciss,
535 &cciss_proc_fops, hba[i]); 578 &cciss_proc_fops, h);
536} 579}
537#endif /* CONFIG_PROC_FS */ 580#endif /* CONFIG_PROC_FS */
538 581
@@ -565,12 +608,12 @@ static ssize_t dev_show_unique_id(struct device *dev,
565 unsigned long flags; 608 unsigned long flags;
566 int ret = 0; 609 int ret = 0;
567 610
568 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 611 spin_lock_irqsave(&h->lock, flags);
569 if (h->busy_configuring) 612 if (h->busy_configuring)
570 ret = -EBUSY; 613 ret = -EBUSY;
571 else 614 else
572 memcpy(sn, drv->serial_no, sizeof(sn)); 615 memcpy(sn, drv->serial_no, sizeof(sn));
573 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 616 spin_unlock_irqrestore(&h->lock, flags);
574 617
575 if (ret) 618 if (ret)
576 return ret; 619 return ret;
@@ -595,12 +638,12 @@ static ssize_t dev_show_vendor(struct device *dev,
595 unsigned long flags; 638 unsigned long flags;
596 int ret = 0; 639 int ret = 0;
597 640
598 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 641 spin_lock_irqsave(&h->lock, flags);
599 if (h->busy_configuring) 642 if (h->busy_configuring)
600 ret = -EBUSY; 643 ret = -EBUSY;
601 else 644 else
602 memcpy(vendor, drv->vendor, VENDOR_LEN + 1); 645 memcpy(vendor, drv->vendor, VENDOR_LEN + 1);
603 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 646 spin_unlock_irqrestore(&h->lock, flags);
604 647
605 if (ret) 648 if (ret)
606 return ret; 649 return ret;
@@ -619,12 +662,12 @@ static ssize_t dev_show_model(struct device *dev,
619 unsigned long flags; 662 unsigned long flags;
620 int ret = 0; 663 int ret = 0;
621 664
622 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 665 spin_lock_irqsave(&h->lock, flags);
623 if (h->busy_configuring) 666 if (h->busy_configuring)
624 ret = -EBUSY; 667 ret = -EBUSY;
625 else 668 else
626 memcpy(model, drv->model, MODEL_LEN + 1); 669 memcpy(model, drv->model, MODEL_LEN + 1);
627 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 670 spin_unlock_irqrestore(&h->lock, flags);
628 671
629 if (ret) 672 if (ret)
630 return ret; 673 return ret;
@@ -643,12 +686,12 @@ static ssize_t dev_show_rev(struct device *dev,
643 unsigned long flags; 686 unsigned long flags;
644 int ret = 0; 687 int ret = 0;
645 688
646 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 689 spin_lock_irqsave(&h->lock, flags);
647 if (h->busy_configuring) 690 if (h->busy_configuring)
648 ret = -EBUSY; 691 ret = -EBUSY;
649 else 692 else
650 memcpy(rev, drv->rev, REV_LEN + 1); 693 memcpy(rev, drv->rev, REV_LEN + 1);
651 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 694 spin_unlock_irqrestore(&h->lock, flags);
652 695
653 if (ret) 696 if (ret)
654 return ret; 697 return ret;
@@ -665,17 +708,17 @@ static ssize_t cciss_show_lunid(struct device *dev,
665 unsigned long flags; 708 unsigned long flags;
666 unsigned char lunid[8]; 709 unsigned char lunid[8];
667 710
668 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 711 spin_lock_irqsave(&h->lock, flags);
669 if (h->busy_configuring) { 712 if (h->busy_configuring) {
670 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 713 spin_unlock_irqrestore(&h->lock, flags);
671 return -EBUSY; 714 return -EBUSY;
672 } 715 }
673 if (!drv->heads) { 716 if (!drv->heads) {
674 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 717 spin_unlock_irqrestore(&h->lock, flags);
675 return -ENOTTY; 718 return -ENOTTY;
676 } 719 }
677 memcpy(lunid, drv->LunID, sizeof(lunid)); 720 memcpy(lunid, drv->LunID, sizeof(lunid));
678 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 721 spin_unlock_irqrestore(&h->lock, flags);
679 return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 722 return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
680 lunid[0], lunid[1], lunid[2], lunid[3], 723 lunid[0], lunid[1], lunid[2], lunid[3],
681 lunid[4], lunid[5], lunid[6], lunid[7]); 724 lunid[4], lunid[5], lunid[6], lunid[7]);
@@ -690,13 +733,13 @@ static ssize_t cciss_show_raid_level(struct device *dev,
690 int raid; 733 int raid;
691 unsigned long flags; 734 unsigned long flags;
692 735
693 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 736 spin_lock_irqsave(&h->lock, flags);
694 if (h->busy_configuring) { 737 if (h->busy_configuring) {
695 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 738 spin_unlock_irqrestore(&h->lock, flags);
696 return -EBUSY; 739 return -EBUSY;
697 } 740 }
698 raid = drv->raid_level; 741 raid = drv->raid_level;
699 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 742 spin_unlock_irqrestore(&h->lock, flags);
700 if (raid < 0 || raid > RAID_UNKNOWN) 743 if (raid < 0 || raid > RAID_UNKNOWN)
701 raid = RAID_UNKNOWN; 744 raid = RAID_UNKNOWN;
702 745
@@ -713,13 +756,13 @@ static ssize_t cciss_show_usage_count(struct device *dev,
713 unsigned long flags; 756 unsigned long flags;
714 int count; 757 int count;
715 758
716 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 759 spin_lock_irqsave(&h->lock, flags);
717 if (h->busy_configuring) { 760 if (h->busy_configuring) {
718 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 761 spin_unlock_irqrestore(&h->lock, flags);
719 return -EBUSY; 762 return -EBUSY;
720 } 763 }
721 count = drv->usage_count; 764 count = drv->usage_count;
722 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 765 spin_unlock_irqrestore(&h->lock, flags);
723 return snprintf(buf, 20, "%d\n", count); 766 return snprintf(buf, 20, "%d\n", count);
724} 767}
725static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL); 768static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL);
@@ -864,60 +907,70 @@ static void cciss_destroy_ld_sysfs_entry(struct ctlr_info *h, int drv_index,
864/* 907/*
865 * For operations that cannot sleep, a command block is allocated at init, 908 * For operations that cannot sleep, a command block is allocated at init,
866 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 909 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
867 * which ones are free or in use. For operations that can wait for kmalloc 910 * which ones are free or in use.
868 * to possible sleep, this routine can be called with get_from_pool set to 0.
869 * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was.
870 */ 911 */
871static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool) 912static CommandList_struct *cmd_alloc(ctlr_info_t *h)
872{ 913{
873 CommandList_struct *c; 914 CommandList_struct *c;
874 int i; 915 int i;
875 u64bit temp64; 916 u64bit temp64;
876 dma_addr_t cmd_dma_handle, err_dma_handle; 917 dma_addr_t cmd_dma_handle, err_dma_handle;
877 918
878 if (!get_from_pool) { 919 do {
879 c = (CommandList_struct *) pci_alloc_consistent(h->pdev, 920 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
880 sizeof(CommandList_struct), &cmd_dma_handle); 921 if (i == h->nr_cmds)
881 if (c == NULL)
882 return NULL; 922 return NULL;
883 memset(c, 0, sizeof(CommandList_struct)); 923 } while (test_and_set_bit(i & (BITS_PER_LONG - 1),
924 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
925 c = h->cmd_pool + i;
926 memset(c, 0, sizeof(CommandList_struct));
927 cmd_dma_handle = h->cmd_pool_dhandle + i * sizeof(CommandList_struct);
928 c->err_info = h->errinfo_pool + i;
929 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
930 err_dma_handle = h->errinfo_pool_dhandle
931 + i * sizeof(ErrorInfo_struct);
932 h->nr_allocs++;
884 933
885 c->cmdindex = -1; 934 c->cmdindex = i;
886 935
887 c->err_info = (ErrorInfo_struct *) 936 INIT_HLIST_NODE(&c->list);
888 pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct), 937 c->busaddr = (__u32) cmd_dma_handle;
889 &err_dma_handle); 938 temp64.val = (__u64) err_dma_handle;
939 c->ErrDesc.Addr.lower = temp64.val32.lower;
940 c->ErrDesc.Addr.upper = temp64.val32.upper;
941 c->ErrDesc.Len = sizeof(ErrorInfo_struct);
890 942
891 if (c->err_info == NULL) { 943 c->ctlr = h->ctlr;
892 pci_free_consistent(h->pdev, 944 return c;
893 sizeof(CommandList_struct), c, cmd_dma_handle); 945}
894 return NULL;
895 }
896 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
897 } else { /* get it out of the controllers pool */
898
899 do {
900 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
901 if (i == h->nr_cmds)
902 return NULL;
903 } while (test_and_set_bit
904 (i & (BITS_PER_LONG - 1),
905 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
906#ifdef CCISS_DEBUG
907 printk(KERN_DEBUG "cciss: using command buffer %d\n", i);
908#endif
909 c = h->cmd_pool + i;
910 memset(c, 0, sizeof(CommandList_struct));
911 cmd_dma_handle = h->cmd_pool_dhandle
912 + i * sizeof(CommandList_struct);
913 c->err_info = h->errinfo_pool + i;
914 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
915 err_dma_handle = h->errinfo_pool_dhandle
916 + i * sizeof(ErrorInfo_struct);
917 h->nr_allocs++;
918 946
919 c->cmdindex = i; 947/* allocate a command using pci_alloc_consistent, used for ioctls,
948 * etc., not for the main i/o path.
949 */
950static CommandList_struct *cmd_special_alloc(ctlr_info_t *h)
951{
952 CommandList_struct *c;
953 u64bit temp64;
954 dma_addr_t cmd_dma_handle, err_dma_handle;
955
956 c = (CommandList_struct *) pci_alloc_consistent(h->pdev,
957 sizeof(CommandList_struct), &cmd_dma_handle);
958 if (c == NULL)
959 return NULL;
960 memset(c, 0, sizeof(CommandList_struct));
961
962 c->cmdindex = -1;
963
964 c->err_info = (ErrorInfo_struct *)
965 pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct),
966 &err_dma_handle);
967
968 if (c->err_info == NULL) {
969 pci_free_consistent(h->pdev,
970 sizeof(CommandList_struct), c, cmd_dma_handle);
971 return NULL;
920 } 972 }
973 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
921 974
922 INIT_HLIST_NODE(&c->list); 975 INIT_HLIST_NODE(&c->list);
923 c->busaddr = (__u32) cmd_dma_handle; 976 c->busaddr = (__u32) cmd_dma_handle;
@@ -930,27 +983,26 @@ static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool)
930 return c; 983 return c;
931} 984}
932 985
933/* 986static void cmd_free(ctlr_info_t *h, CommandList_struct *c)
934 * Frees a command block that was previously allocated with cmd_alloc().
935 */
936static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool)
937{ 987{
938 int i; 988 int i;
989
990 i = c - h->cmd_pool;
991 clear_bit(i & (BITS_PER_LONG - 1),
992 h->cmd_pool_bits + (i / BITS_PER_LONG));
993 h->nr_frees++;
994}
995
996static void cmd_special_free(ctlr_info_t *h, CommandList_struct *c)
997{
939 u64bit temp64; 998 u64bit temp64;
940 999
941 if (!got_from_pool) { 1000 temp64.val32.lower = c->ErrDesc.Addr.lower;
942 temp64.val32.lower = c->ErrDesc.Addr.lower; 1001 temp64.val32.upper = c->ErrDesc.Addr.upper;
943 temp64.val32.upper = c->ErrDesc.Addr.upper; 1002 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct),
944 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct), 1003 c->err_info, (dma_addr_t) temp64.val);
945 c->err_info, (dma_addr_t) temp64.val); 1004 pci_free_consistent(h->pdev, sizeof(CommandList_struct),
946 pci_free_consistent(h->pdev, sizeof(CommandList_struct), 1005 c, (dma_addr_t) c->busaddr);
947 c, (dma_addr_t) c->busaddr);
948 } else {
949 i = c - h->cmd_pool;
950 clear_bit(i & (BITS_PER_LONG - 1),
951 h->cmd_pool_bits + (i / BITS_PER_LONG));
952 h->nr_frees++;
953 }
954} 1006}
955 1007
956static inline ctlr_info_t *get_host(struct gendisk *disk) 1008static inline ctlr_info_t *get_host(struct gendisk *disk)
@@ -968,13 +1020,10 @@ static inline drive_info_struct *get_drv(struct gendisk *disk)
968 */ 1020 */
969static int cciss_open(struct block_device *bdev, fmode_t mode) 1021static int cciss_open(struct block_device *bdev, fmode_t mode)
970{ 1022{
971 ctlr_info_t *host = get_host(bdev->bd_disk); 1023 ctlr_info_t *h = get_host(bdev->bd_disk);
972 drive_info_struct *drv = get_drv(bdev->bd_disk); 1024 drive_info_struct *drv = get_drv(bdev->bd_disk);
973 1025
974#ifdef CCISS_DEBUG 1026 dev_dbg(&h->pdev->dev, "cciss_open %s\n", bdev->bd_disk->disk_name);
975 printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name);
976#endif /* CCISS_DEBUG */
977
978 if (drv->busy_configuring) 1027 if (drv->busy_configuring)
979 return -EBUSY; 1028 return -EBUSY;
980 /* 1029 /*
@@ -1000,29 +1049,39 @@ static int cciss_open(struct block_device *bdev, fmode_t mode)
1000 return -EPERM; 1049 return -EPERM;
1001 } 1050 }
1002 drv->usage_count++; 1051 drv->usage_count++;
1003 host->usage_count++; 1052 h->usage_count++;
1004 return 0; 1053 return 0;
1005} 1054}
1006 1055
1056static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
1057{
1058 int ret;
1059
1060 lock_kernel();
1061 ret = cciss_open(bdev, mode);
1062 unlock_kernel();
1063
1064 return ret;
1065}
1066
1007/* 1067/*
1008 * Close. Sync first. 1068 * Close. Sync first.
1009 */ 1069 */
1010static int cciss_release(struct gendisk *disk, fmode_t mode) 1070static int cciss_release(struct gendisk *disk, fmode_t mode)
1011{ 1071{
1012 ctlr_info_t *host = get_host(disk); 1072 ctlr_info_t *h;
1013 drive_info_struct *drv = get_drv(disk); 1073 drive_info_struct *drv;
1014
1015#ifdef CCISS_DEBUG
1016 printk(KERN_DEBUG "cciss_release %s\n", disk->disk_name);
1017#endif /* CCISS_DEBUG */
1018 1074
1075 lock_kernel();
1076 h = get_host(disk);
1077 drv = get_drv(disk);
1078 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
1019 drv->usage_count--; 1079 drv->usage_count--;
1020 host->usage_count--; 1080 h->usage_count--;
1081 unlock_kernel();
1021 return 0; 1082 return 0;
1022} 1083}
1023 1084
1024#ifdef CONFIG_COMPAT
1025
1026static int do_ioctl(struct block_device *bdev, fmode_t mode, 1085static int do_ioctl(struct block_device *bdev, fmode_t mode,
1027 unsigned cmd, unsigned long arg) 1086 unsigned cmd, unsigned long arg)
1028{ 1087{
@@ -1033,6 +1092,8 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode,
1033 return ret; 1092 return ret;
1034} 1093}
1035 1094
1095#ifdef CONFIG_COMPAT
1096
1036static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode, 1097static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
1037 unsigned cmd, unsigned long arg); 1098 unsigned cmd, unsigned long arg);
1038static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode, 1099static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode,
@@ -1163,11 +1224,11 @@ static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1163 return 0; 1224 return 0;
1164} 1225}
1165 1226
1166static void check_ioctl_unit_attention(ctlr_info_t *host, CommandList_struct *c) 1227static void check_ioctl_unit_attention(ctlr_info_t *h, CommandList_struct *c)
1167{ 1228{
1168 if (c->err_info->CommandStatus == CMD_TARGET_STATUS && 1229 if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
1169 c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) 1230 c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION)
1170 (void)check_for_unit_attention(host, c); 1231 (void)check_for_unit_attention(h, c);
1171} 1232}
1172/* 1233/*
1173 * ioctl 1234 * ioctl
@@ -1176,15 +1237,12 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1176 unsigned int cmd, unsigned long arg) 1237 unsigned int cmd, unsigned long arg)
1177{ 1238{
1178 struct gendisk *disk = bdev->bd_disk; 1239 struct gendisk *disk = bdev->bd_disk;
1179 ctlr_info_t *host = get_host(disk); 1240 ctlr_info_t *h = get_host(disk);
1180 drive_info_struct *drv = get_drv(disk); 1241 drive_info_struct *drv = get_drv(disk);
1181 int ctlr = host->ctlr;
1182 void __user *argp = (void __user *)arg; 1242 void __user *argp = (void __user *)arg;
1183 1243
1184#ifdef CCISS_DEBUG 1244 dev_dbg(&h->pdev->dev, "cciss_ioctl: Called with cmd=%x %lx\n",
1185 printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg); 1245 cmd, arg);
1186#endif /* CCISS_DEBUG */
1187
1188 switch (cmd) { 1246 switch (cmd) {
1189 case CCISS_GETPCIINFO: 1247 case CCISS_GETPCIINFO:
1190 { 1248 {
@@ -1192,10 +1250,10 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1192 1250
1193 if (!arg) 1251 if (!arg)
1194 return -EINVAL; 1252 return -EINVAL;
1195 pciinfo.domain = pci_domain_nr(host->pdev->bus); 1253 pciinfo.domain = pci_domain_nr(h->pdev->bus);
1196 pciinfo.bus = host->pdev->bus->number; 1254 pciinfo.bus = h->pdev->bus->number;
1197 pciinfo.dev_fn = host->pdev->devfn; 1255 pciinfo.dev_fn = h->pdev->devfn;
1198 pciinfo.board_id = host->board_id; 1256 pciinfo.board_id = h->board_id;
1199 if (copy_to_user 1257 if (copy_to_user
1200 (argp, &pciinfo, sizeof(cciss_pci_info_struct))) 1258 (argp, &pciinfo, sizeof(cciss_pci_info_struct)))
1201 return -EFAULT; 1259 return -EFAULT;
@@ -1207,9 +1265,9 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1207 if (!arg) 1265 if (!arg)
1208 return -EINVAL; 1266 return -EINVAL;
1209 intinfo.delay = 1267 intinfo.delay =
1210 readl(&host->cfgtable->HostWrite.CoalIntDelay); 1268 readl(&h->cfgtable->HostWrite.CoalIntDelay);
1211 intinfo.count = 1269 intinfo.count =
1212 readl(&host->cfgtable->HostWrite.CoalIntCount); 1270 readl(&h->cfgtable->HostWrite.CoalIntCount);
1213 if (copy_to_user 1271 if (copy_to_user
1214 (argp, &intinfo, sizeof(cciss_coalint_struct))) 1272 (argp, &intinfo, sizeof(cciss_coalint_struct)))
1215 return -EFAULT; 1273 return -EFAULT;
@@ -1229,26 +1287,23 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1229 (&intinfo, argp, sizeof(cciss_coalint_struct))) 1287 (&intinfo, argp, sizeof(cciss_coalint_struct)))
1230 return -EFAULT; 1288 return -EFAULT;
1231 if ((intinfo.delay == 0) && (intinfo.count == 0)) 1289 if ((intinfo.delay == 0) && (intinfo.count == 0))
1232 {
1233// printk("cciss_ioctl: delay and count cannot be 0\n");
1234 return -EINVAL; 1290 return -EINVAL;
1235 } 1291 spin_lock_irqsave(&h->lock, flags);
1236 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1237 /* Update the field, and then ring the doorbell */ 1292 /* Update the field, and then ring the doorbell */
1238 writel(intinfo.delay, 1293 writel(intinfo.delay,
1239 &(host->cfgtable->HostWrite.CoalIntDelay)); 1294 &(h->cfgtable->HostWrite.CoalIntDelay));
1240 writel(intinfo.count, 1295 writel(intinfo.count,
1241 &(host->cfgtable->HostWrite.CoalIntCount)); 1296 &(h->cfgtable->HostWrite.CoalIntCount));
1242 writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL); 1297 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
1243 1298
1244 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) { 1299 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) {
1245 if (!(readl(host->vaddr + SA5_DOORBELL) 1300 if (!(readl(h->vaddr + SA5_DOORBELL)
1246 & CFGTBL_ChangeReq)) 1301 & CFGTBL_ChangeReq))
1247 break; 1302 break;
1248 /* delay and try again */ 1303 /* delay and try again */
1249 udelay(1000); 1304 udelay(1000);
1250 } 1305 }
1251 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1306 spin_unlock_irqrestore(&h->lock, flags);
1252 if (i >= MAX_IOCTL_CONFIG_WAIT) 1307 if (i >= MAX_IOCTL_CONFIG_WAIT)
1253 return -EAGAIN; 1308 return -EAGAIN;
1254 return 0; 1309 return 0;
@@ -1262,7 +1317,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1262 return -EINVAL; 1317 return -EINVAL;
1263 for (i = 0; i < 16; i++) 1318 for (i = 0; i < 16; i++)
1264 NodeName[i] = 1319 NodeName[i] =
1265 readb(&host->cfgtable->ServerName[i]); 1320 readb(&h->cfgtable->ServerName[i]);
1266 if (copy_to_user(argp, NodeName, sizeof(NodeName_type))) 1321 if (copy_to_user(argp, NodeName, sizeof(NodeName_type)))
1267 return -EFAULT; 1322 return -EFAULT;
1268 return 0; 1323 return 0;
@@ -1282,23 +1337,23 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1282 (NodeName, argp, sizeof(NodeName_type))) 1337 (NodeName, argp, sizeof(NodeName_type)))
1283 return -EFAULT; 1338 return -EFAULT;
1284 1339
1285 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 1340 spin_lock_irqsave(&h->lock, flags);
1286 1341
1287 /* Update the field, and then ring the doorbell */ 1342 /* Update the field, and then ring the doorbell */
1288 for (i = 0; i < 16; i++) 1343 for (i = 0; i < 16; i++)
1289 writeb(NodeName[i], 1344 writeb(NodeName[i],
1290 &host->cfgtable->ServerName[i]); 1345 &h->cfgtable->ServerName[i]);
1291 1346
1292 writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL); 1347 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
1293 1348
1294 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) { 1349 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) {
1295 if (!(readl(host->vaddr + SA5_DOORBELL) 1350 if (!(readl(h->vaddr + SA5_DOORBELL)
1296 & CFGTBL_ChangeReq)) 1351 & CFGTBL_ChangeReq))
1297 break; 1352 break;
1298 /* delay and try again */ 1353 /* delay and try again */
1299 udelay(1000); 1354 udelay(1000);
1300 } 1355 }
1301 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1356 spin_unlock_irqrestore(&h->lock, flags);
1302 if (i >= MAX_IOCTL_CONFIG_WAIT) 1357 if (i >= MAX_IOCTL_CONFIG_WAIT)
1303 return -EAGAIN; 1358 return -EAGAIN;
1304 return 0; 1359 return 0;
@@ -1310,7 +1365,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1310 1365
1311 if (!arg) 1366 if (!arg)
1312 return -EINVAL; 1367 return -EINVAL;
1313 heartbeat = readl(&host->cfgtable->HeartBeat); 1368 heartbeat = readl(&h->cfgtable->HeartBeat);
1314 if (copy_to_user 1369 if (copy_to_user
1315 (argp, &heartbeat, sizeof(Heartbeat_type))) 1370 (argp, &heartbeat, sizeof(Heartbeat_type)))
1316 return -EFAULT; 1371 return -EFAULT;
@@ -1322,7 +1377,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1322 1377
1323 if (!arg) 1378 if (!arg)
1324 return -EINVAL; 1379 return -EINVAL;
1325 BusTypes = readl(&host->cfgtable->BusTypes); 1380 BusTypes = readl(&h->cfgtable->BusTypes);
1326 if (copy_to_user 1381 if (copy_to_user
1327 (argp, &BusTypes, sizeof(BusTypes_type))) 1382 (argp, &BusTypes, sizeof(BusTypes_type)))
1328 return -EFAULT; 1383 return -EFAULT;
@@ -1334,7 +1389,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1334 1389
1335 if (!arg) 1390 if (!arg)
1336 return -EINVAL; 1391 return -EINVAL;
1337 memcpy(firmware, host->firm_ver, 4); 1392 memcpy(firmware, h->firm_ver, 4);
1338 1393
1339 if (copy_to_user 1394 if (copy_to_user
1340 (argp, firmware, sizeof(FirmwareVer_type))) 1395 (argp, firmware, sizeof(FirmwareVer_type)))
@@ -1357,7 +1412,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1357 case CCISS_DEREGDISK: 1412 case CCISS_DEREGDISK:
1358 case CCISS_REGNEWD: 1413 case CCISS_REGNEWD:
1359 case CCISS_REVALIDVOLS: 1414 case CCISS_REVALIDVOLS:
1360 return rebuild_lun_table(host, 0, 1); 1415 return rebuild_lun_table(h, 0, 1);
1361 1416
1362 case CCISS_GETLUNINFO:{ 1417 case CCISS_GETLUNINFO:{
1363 LogvolInfo_struct luninfo; 1418 LogvolInfo_struct luninfo;
@@ -1377,7 +1432,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1377 CommandList_struct *c; 1432 CommandList_struct *c;
1378 char *buff = NULL; 1433 char *buff = NULL;
1379 u64bit temp64; 1434 u64bit temp64;
1380 unsigned long flags;
1381 DECLARE_COMPLETION_ONSTACK(wait); 1435 DECLARE_COMPLETION_ONSTACK(wait);
1382 1436
1383 if (!arg) 1437 if (!arg)
@@ -1413,7 +1467,8 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1413 } else { 1467 } else {
1414 memset(buff, 0, iocommand.buf_size); 1468 memset(buff, 0, iocommand.buf_size);
1415 } 1469 }
1416 if ((c = cmd_alloc(host, 0)) == NULL) { 1470 c = cmd_special_alloc(h);
1471 if (!c) {
1417 kfree(buff); 1472 kfree(buff);
1418 return -ENOMEM; 1473 return -ENOMEM;
1419 } 1474 }
@@ -1439,7 +1494,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1439 1494
1440 /* Fill in the scatter gather information */ 1495 /* Fill in the scatter gather information */
1441 if (iocommand.buf_size > 0) { 1496 if (iocommand.buf_size > 0) {
1442 temp64.val = pci_map_single(host->pdev, buff, 1497 temp64.val = pci_map_single(h->pdev, buff,
1443 iocommand.buf_size, 1498 iocommand.buf_size,
1444 PCI_DMA_BIDIRECTIONAL); 1499 PCI_DMA_BIDIRECTIONAL);
1445 c->SG[0].Addr.lower = temp64.val32.lower; 1500 c->SG[0].Addr.lower = temp64.val32.lower;
@@ -1449,30 +1504,24 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1449 } 1504 }
1450 c->waiting = &wait; 1505 c->waiting = &wait;
1451 1506
1452 /* Put the request on the tail of the request queue */ 1507 enqueue_cmd_and_start_io(h, c);
1453 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1454 addQ(&host->reqQ, c);
1455 host->Qdepth++;
1456 start_io(host);
1457 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1458
1459 wait_for_completion(&wait); 1508 wait_for_completion(&wait);
1460 1509
1461 /* unlock the buffers from DMA */ 1510 /* unlock the buffers from DMA */
1462 temp64.val32.lower = c->SG[0].Addr.lower; 1511 temp64.val32.lower = c->SG[0].Addr.lower;
1463 temp64.val32.upper = c->SG[0].Addr.upper; 1512 temp64.val32.upper = c->SG[0].Addr.upper;
1464 pci_unmap_single(host->pdev, (dma_addr_t) temp64.val, 1513 pci_unmap_single(h->pdev, (dma_addr_t) temp64.val,
1465 iocommand.buf_size, 1514 iocommand.buf_size,
1466 PCI_DMA_BIDIRECTIONAL); 1515 PCI_DMA_BIDIRECTIONAL);
1467 1516
1468 check_ioctl_unit_attention(host, c); 1517 check_ioctl_unit_attention(h, c);
1469 1518
1470 /* Copy the error information out */ 1519 /* Copy the error information out */
1471 iocommand.error_info = *(c->err_info); 1520 iocommand.error_info = *(c->err_info);
1472 if (copy_to_user 1521 if (copy_to_user
1473 (argp, &iocommand, sizeof(IOCTL_Command_struct))) { 1522 (argp, &iocommand, sizeof(IOCTL_Command_struct))) {
1474 kfree(buff); 1523 kfree(buff);
1475 cmd_free(host, c, 0); 1524 cmd_special_free(h, c);
1476 return -EFAULT; 1525 return -EFAULT;
1477 } 1526 }
1478 1527
@@ -1481,12 +1530,12 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1481 if (copy_to_user 1530 if (copy_to_user
1482 (iocommand.buf, buff, iocommand.buf_size)) { 1531 (iocommand.buf, buff, iocommand.buf_size)) {
1483 kfree(buff); 1532 kfree(buff);
1484 cmd_free(host, c, 0); 1533 cmd_special_free(h, c);
1485 return -EFAULT; 1534 return -EFAULT;
1486 } 1535 }
1487 } 1536 }
1488 kfree(buff); 1537 kfree(buff);
1489 cmd_free(host, c, 0); 1538 cmd_special_free(h, c);
1490 return 0; 1539 return 0;
1491 } 1540 }
1492 case CCISS_BIG_PASSTHRU:{ 1541 case CCISS_BIG_PASSTHRU:{
@@ -1495,7 +1544,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1495 unsigned char **buff = NULL; 1544 unsigned char **buff = NULL;
1496 int *buff_size = NULL; 1545 int *buff_size = NULL;
1497 u64bit temp64; 1546 u64bit temp64;
1498 unsigned long flags;
1499 BYTE sg_used = 0; 1547 BYTE sg_used = 0;
1500 int status = 0; 1548 int status = 0;
1501 int i; 1549 int i;
@@ -1569,7 +1617,8 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1569 data_ptr += sz; 1617 data_ptr += sz;
1570 sg_used++; 1618 sg_used++;
1571 } 1619 }
1572 if ((c = cmd_alloc(host, 0)) == NULL) { 1620 c = cmd_special_alloc(h);
1621 if (!c) {
1573 status = -ENOMEM; 1622 status = -ENOMEM;
1574 goto cleanup1; 1623 goto cleanup1;
1575 } 1624 }
@@ -1590,7 +1639,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1590 if (ioc->buf_size > 0) { 1639 if (ioc->buf_size > 0) {
1591 for (i = 0; i < sg_used; i++) { 1640 for (i = 0; i < sg_used; i++) {
1592 temp64.val = 1641 temp64.val =
1593 pci_map_single(host->pdev, buff[i], 1642 pci_map_single(h->pdev, buff[i],
1594 buff_size[i], 1643 buff_size[i],
1595 PCI_DMA_BIDIRECTIONAL); 1644 PCI_DMA_BIDIRECTIONAL);
1596 c->SG[i].Addr.lower = 1645 c->SG[i].Addr.lower =
@@ -1602,26 +1651,21 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1602 } 1651 }
1603 } 1652 }
1604 c->waiting = &wait; 1653 c->waiting = &wait;
1605 /* Put the request on the tail of the request queue */ 1654 enqueue_cmd_and_start_io(h, c);
1606 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1607 addQ(&host->reqQ, c);
1608 host->Qdepth++;
1609 start_io(host);
1610 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1611 wait_for_completion(&wait); 1655 wait_for_completion(&wait);
1612 /* unlock the buffers from DMA */ 1656 /* unlock the buffers from DMA */
1613 for (i = 0; i < sg_used; i++) { 1657 for (i = 0; i < sg_used; i++) {
1614 temp64.val32.lower = c->SG[i].Addr.lower; 1658 temp64.val32.lower = c->SG[i].Addr.lower;
1615 temp64.val32.upper = c->SG[i].Addr.upper; 1659 temp64.val32.upper = c->SG[i].Addr.upper;
1616 pci_unmap_single(host->pdev, 1660 pci_unmap_single(h->pdev,
1617 (dma_addr_t) temp64.val, buff_size[i], 1661 (dma_addr_t) temp64.val, buff_size[i],
1618 PCI_DMA_BIDIRECTIONAL); 1662 PCI_DMA_BIDIRECTIONAL);
1619 } 1663 }
1620 check_ioctl_unit_attention(host, c); 1664 check_ioctl_unit_attention(h, c);
1621 /* Copy the error information out */ 1665 /* Copy the error information out */
1622 ioc->error_info = *(c->err_info); 1666 ioc->error_info = *(c->err_info);
1623 if (copy_to_user(argp, ioc, sizeof(*ioc))) { 1667 if (copy_to_user(argp, ioc, sizeof(*ioc))) {
1624 cmd_free(host, c, 0); 1668 cmd_special_free(h, c);
1625 status = -EFAULT; 1669 status = -EFAULT;
1626 goto cleanup1; 1670 goto cleanup1;
1627 } 1671 }
@@ -1631,14 +1675,14 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1631 for (i = 0; i < sg_used; i++) { 1675 for (i = 0; i < sg_used; i++) {
1632 if (copy_to_user 1676 if (copy_to_user
1633 (ptr, buff[i], buff_size[i])) { 1677 (ptr, buff[i], buff_size[i])) {
1634 cmd_free(host, c, 0); 1678 cmd_special_free(h, c);
1635 status = -EFAULT; 1679 status = -EFAULT;
1636 goto cleanup1; 1680 goto cleanup1;
1637 } 1681 }
1638 ptr += buff_size[i]; 1682 ptr += buff_size[i];
1639 } 1683 }
1640 } 1684 }
1641 cmd_free(host, c, 0); 1685 cmd_special_free(h, c);
1642 status = 0; 1686 status = 0;
1643 cleanup1: 1687 cleanup1:
1644 if (buff) { 1688 if (buff) {
@@ -1726,26 +1770,26 @@ static void cciss_check_queues(ctlr_info_t *h)
1726 1770
1727static void cciss_softirq_done(struct request *rq) 1771static void cciss_softirq_done(struct request *rq)
1728{ 1772{
1729 CommandList_struct *cmd = rq->completion_data; 1773 CommandList_struct *c = rq->completion_data;
1730 ctlr_info_t *h = hba[cmd->ctlr]; 1774 ctlr_info_t *h = hba[c->ctlr];
1731 SGDescriptor_struct *curr_sg = cmd->SG; 1775 SGDescriptor_struct *curr_sg = c->SG;
1732 unsigned long flags;
1733 u64bit temp64; 1776 u64bit temp64;
1777 unsigned long flags;
1734 int i, ddir; 1778 int i, ddir;
1735 int sg_index = 0; 1779 int sg_index = 0;
1736 1780
1737 if (cmd->Request.Type.Direction == XFER_READ) 1781 if (c->Request.Type.Direction == XFER_READ)
1738 ddir = PCI_DMA_FROMDEVICE; 1782 ddir = PCI_DMA_FROMDEVICE;
1739 else 1783 else
1740 ddir = PCI_DMA_TODEVICE; 1784 ddir = PCI_DMA_TODEVICE;
1741 1785
1742 /* command did not need to be retried */ 1786 /* command did not need to be retried */
1743 /* unmap the DMA mapping for all the scatter gather elements */ 1787 /* unmap the DMA mapping for all the scatter gather elements */
1744 for (i = 0; i < cmd->Header.SGList; i++) { 1788 for (i = 0; i < c->Header.SGList; i++) {
1745 if (curr_sg[sg_index].Ext == CCISS_SG_CHAIN) { 1789 if (curr_sg[sg_index].Ext == CCISS_SG_CHAIN) {
1746 cciss_unmap_sg_chain_block(h, cmd); 1790 cciss_unmap_sg_chain_block(h, c);
1747 /* Point to the next block */ 1791 /* Point to the next block */
1748 curr_sg = h->cmd_sg_list[cmd->cmdindex]; 1792 curr_sg = h->cmd_sg_list[c->cmdindex];
1749 sg_index = 0; 1793 sg_index = 0;
1750 } 1794 }
1751 temp64.val32.lower = curr_sg[sg_index].Addr.lower; 1795 temp64.val32.lower = curr_sg[sg_index].Addr.lower;
@@ -1755,18 +1799,16 @@ static void cciss_softirq_done(struct request *rq)
1755 ++sg_index; 1799 ++sg_index;
1756 } 1800 }
1757 1801
1758#ifdef CCISS_DEBUG 1802 dev_dbg(&h->pdev->dev, "Done with %p\n", rq);
1759 printk("Done with %p\n", rq);
1760#endif /* CCISS_DEBUG */
1761 1803
1762 /* set the residual count for pc requests */ 1804 /* set the residual count for pc requests */
1763 if (blk_pc_request(rq)) 1805 if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
1764 rq->resid_len = cmd->err_info->ResidualCnt; 1806 rq->resid_len = c->err_info->ResidualCnt;
1765 1807
1766 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO); 1808 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
1767 1809
1768 spin_lock_irqsave(&h->lock, flags); 1810 spin_lock_irqsave(&h->lock, flags);
1769 cmd_free(h, cmd, 1); 1811 cmd_free(h, c);
1770 cciss_check_queues(h); 1812 cciss_check_queues(h);
1771 spin_unlock_irqrestore(&h->lock, flags); 1813 spin_unlock_irqrestore(&h->lock, flags);
1772} 1814}
@@ -1782,7 +1824,7 @@ static inline void log_unit_to_scsi3addr(ctlr_info_t *h,
1782 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if 1824 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if
1783 * they cannot be read. 1825 * they cannot be read.
1784 */ 1826 */
1785static void cciss_get_device_descr(int ctlr, int logvol, 1827static void cciss_get_device_descr(ctlr_info_t *h, int logvol,
1786 char *vendor, char *model, char *rev) 1828 char *vendor, char *model, char *rev)
1787{ 1829{
1788 int rc; 1830 int rc;
@@ -1797,8 +1839,8 @@ static void cciss_get_device_descr(int ctlr, int logvol,
1797 if (!inq_buf) 1839 if (!inq_buf)
1798 return; 1840 return;
1799 1841
1800 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 1842 log_unit_to_scsi3addr(h, scsi3addr, logvol);
1801 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buf, sizeof(*inq_buf), 0, 1843 rc = sendcmd_withirq(h, CISS_INQUIRY, inq_buf, sizeof(*inq_buf), 0,
1802 scsi3addr, TYPE_CMD); 1844 scsi3addr, TYPE_CMD);
1803 if (rc == IO_OK) { 1845 if (rc == IO_OK) {
1804 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN); 1846 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN);
@@ -1818,7 +1860,7 @@ static void cciss_get_device_descr(int ctlr, int logvol,
1818 * number cannot be had, for whatever reason, 16 bytes of 0xff 1860 * number cannot be had, for whatever reason, 16 bytes of 0xff
1819 * are returned instead. 1861 * are returned instead.
1820 */ 1862 */
1821static void cciss_get_serial_no(int ctlr, int logvol, 1863static void cciss_get_serial_no(ctlr_info_t *h, int logvol,
1822 unsigned char *serial_no, int buflen) 1864 unsigned char *serial_no, int buflen)
1823{ 1865{
1824#define PAGE_83_INQ_BYTES 64 1866#define PAGE_83_INQ_BYTES 64
@@ -1833,8 +1875,8 @@ static void cciss_get_serial_no(int ctlr, int logvol,
1833 if (!buf) 1875 if (!buf)
1834 return; 1876 return;
1835 memset(serial_no, 0, buflen); 1877 memset(serial_no, 0, buflen);
1836 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 1878 log_unit_to_scsi3addr(h, scsi3addr, logvol);
1837 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf, 1879 rc = sendcmd_withirq(h, CISS_INQUIRY, buf,
1838 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD); 1880 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1839 if (rc == IO_OK) 1881 if (rc == IO_OK)
1840 memcpy(serial_no, &buf[8], buflen); 1882 memcpy(serial_no, &buf[8], buflen);
@@ -1900,10 +1942,9 @@ init_queue_failure:
1900 * is also the controller node. Any changes to disk 0 will show up on 1942 * is also the controller node. Any changes to disk 0 will show up on
1901 * the next reboot. 1943 * the next reboot.
1902 */ 1944 */
1903static void cciss_update_drive_info(int ctlr, int drv_index, int first_time, 1945static void cciss_update_drive_info(ctlr_info_t *h, int drv_index,
1904 int via_ioctl) 1946 int first_time, int via_ioctl)
1905{ 1947{
1906 ctlr_info_t *h = hba[ctlr];
1907 struct gendisk *disk; 1948 struct gendisk *disk;
1908 InquiryData_struct *inq_buff = NULL; 1949 InquiryData_struct *inq_buff = NULL;
1909 unsigned int block_size; 1950 unsigned int block_size;
@@ -1920,16 +1961,16 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1920 1961
1921 /* testing to see if 16-byte CDBs are already being used */ 1962 /* testing to see if 16-byte CDBs are already being used */
1922 if (h->cciss_read == CCISS_READ_16) { 1963 if (h->cciss_read == CCISS_READ_16) {
1923 cciss_read_capacity_16(h->ctlr, drv_index, 1964 cciss_read_capacity_16(h, drv_index,
1924 &total_size, &block_size); 1965 &total_size, &block_size);
1925 1966
1926 } else { 1967 } else {
1927 cciss_read_capacity(ctlr, drv_index, &total_size, &block_size); 1968 cciss_read_capacity(h, drv_index, &total_size, &block_size);
1928 /* if read_capacity returns all F's this volume is >2TB */ 1969 /* if read_capacity returns all F's this volume is >2TB */
1929 /* in size so we switch to 16-byte CDB's for all */ 1970 /* in size so we switch to 16-byte CDB's for all */
1930 /* read/write ops */ 1971 /* read/write ops */
1931 if (total_size == 0xFFFFFFFFULL) { 1972 if (total_size == 0xFFFFFFFFULL) {
1932 cciss_read_capacity_16(ctlr, drv_index, 1973 cciss_read_capacity_16(h, drv_index,
1933 &total_size, &block_size); 1974 &total_size, &block_size);
1934 h->cciss_read = CCISS_READ_16; 1975 h->cciss_read = CCISS_READ_16;
1935 h->cciss_write = CCISS_WRITE_16; 1976 h->cciss_write = CCISS_WRITE_16;
@@ -1939,14 +1980,14 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1939 } 1980 }
1940 } 1981 }
1941 1982
1942 cciss_geometry_inquiry(ctlr, drv_index, total_size, block_size, 1983 cciss_geometry_inquiry(h, drv_index, total_size, block_size,
1943 inq_buff, drvinfo); 1984 inq_buff, drvinfo);
1944 drvinfo->block_size = block_size; 1985 drvinfo->block_size = block_size;
1945 drvinfo->nr_blocks = total_size + 1; 1986 drvinfo->nr_blocks = total_size + 1;
1946 1987
1947 cciss_get_device_descr(ctlr, drv_index, drvinfo->vendor, 1988 cciss_get_device_descr(h, drv_index, drvinfo->vendor,
1948 drvinfo->model, drvinfo->rev); 1989 drvinfo->model, drvinfo->rev);
1949 cciss_get_serial_no(ctlr, drv_index, drvinfo->serial_no, 1990 cciss_get_serial_no(h, drv_index, drvinfo->serial_no,
1950 sizeof(drvinfo->serial_no)); 1991 sizeof(drvinfo->serial_no));
1951 /* Save the lunid in case we deregister the disk, below. */ 1992 /* Save the lunid in case we deregister the disk, below. */
1952 memcpy(drvinfo->LunID, h->drv[drv_index]->LunID, 1993 memcpy(drvinfo->LunID, h->drv[drv_index]->LunID,
@@ -1971,10 +2012,10 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1971 * (unless it's the first disk (for the controller node). 2012 * (unless it's the first disk (for the controller node).
1972 */ 2013 */
1973 if (h->drv[drv_index]->raid_level != -1 && drv_index != 0) { 2014 if (h->drv[drv_index]->raid_level != -1 && drv_index != 0) {
1974 printk(KERN_WARNING "disk %d has changed.\n", drv_index); 2015 dev_warn(&h->pdev->dev, "disk %d has changed.\n", drv_index);
1975 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2016 spin_lock_irqsave(&h->lock, flags);
1976 h->drv[drv_index]->busy_configuring = 1; 2017 h->drv[drv_index]->busy_configuring = 1;
1977 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2018 spin_unlock_irqrestore(&h->lock, flags);
1978 2019
1979 /* deregister_disk sets h->drv[drv_index]->queue = NULL 2020 /* deregister_disk sets h->drv[drv_index]->queue = NULL
1980 * which keeps the interrupt handler from starting 2021 * which keeps the interrupt handler from starting
@@ -2024,8 +2065,8 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
2024 if (cciss_add_disk(h, disk, drv_index) != 0) { 2065 if (cciss_add_disk(h, disk, drv_index) != 0) {
2025 cciss_free_gendisk(h, drv_index); 2066 cciss_free_gendisk(h, drv_index);
2026 cciss_free_drive_info(h, drv_index); 2067 cciss_free_drive_info(h, drv_index);
2027 printk(KERN_WARNING "cciss:%d could not update " 2068 dev_warn(&h->pdev->dev, "could not update disk %d\n",
2028 "disk %d\n", h->ctlr, drv_index); 2069 drv_index);
2029 --h->num_luns; 2070 --h->num_luns;
2030 } 2071 }
2031 } 2072 }
@@ -2035,7 +2076,7 @@ freeret:
2035 kfree(drvinfo); 2076 kfree(drvinfo);
2036 return; 2077 return;
2037mem_msg: 2078mem_msg:
2038 printk(KERN_ERR "cciss: out of memory\n"); 2079 dev_err(&h->pdev->dev, "out of memory\n");
2039 goto freeret; 2080 goto freeret;
2040} 2081}
2041 2082
@@ -2127,9 +2168,9 @@ static int cciss_add_gendisk(ctlr_info_t *h, unsigned char lunid[],
2127 h->gendisk[drv_index] = 2168 h->gendisk[drv_index] =
2128 alloc_disk(1 << NWD_SHIFT); 2169 alloc_disk(1 << NWD_SHIFT);
2129 if (!h->gendisk[drv_index]) { 2170 if (!h->gendisk[drv_index]) {
2130 printk(KERN_ERR "cciss%d: could not " 2171 dev_err(&h->pdev->dev,
2131 "allocate a new disk %d\n", 2172 "could not allocate a new disk %d\n",
2132 h->ctlr, drv_index); 2173 drv_index);
2133 goto err_free_drive_info; 2174 goto err_free_drive_info;
2134 } 2175 }
2135 } 2176 }
@@ -2180,8 +2221,7 @@ static void cciss_add_controller_node(ctlr_info_t *h)
2180 cciss_free_gendisk(h, drv_index); 2221 cciss_free_gendisk(h, drv_index);
2181 cciss_free_drive_info(h, drv_index); 2222 cciss_free_drive_info(h, drv_index);
2182error: 2223error:
2183 printk(KERN_WARNING "cciss%d: could not " 2224 dev_warn(&h->pdev->dev, "could not add disk 0.\n");
2184 "add disk 0.\n", h->ctlr);
2185 return; 2225 return;
2186} 2226}
2187 2227
@@ -2196,7 +2236,6 @@ error:
2196static int rebuild_lun_table(ctlr_info_t *h, int first_time, 2236static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2197 int via_ioctl) 2237 int via_ioctl)
2198{ 2238{
2199 int ctlr = h->ctlr;
2200 int num_luns; 2239 int num_luns;
2201 ReportLunData_struct *ld_buff = NULL; 2240 ReportLunData_struct *ld_buff = NULL;
2202 int return_code; 2241 int return_code;
@@ -2211,27 +2250,27 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2211 return -EPERM; 2250 return -EPERM;
2212 2251
2213 /* Set busy_configuring flag for this operation */ 2252 /* Set busy_configuring flag for this operation */
2214 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2253 spin_lock_irqsave(&h->lock, flags);
2215 if (h->busy_configuring) { 2254 if (h->busy_configuring) {
2216 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2255 spin_unlock_irqrestore(&h->lock, flags);
2217 return -EBUSY; 2256 return -EBUSY;
2218 } 2257 }
2219 h->busy_configuring = 1; 2258 h->busy_configuring = 1;
2220 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2259 spin_unlock_irqrestore(&h->lock, flags);
2221 2260
2222 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); 2261 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
2223 if (ld_buff == NULL) 2262 if (ld_buff == NULL)
2224 goto mem_msg; 2263 goto mem_msg;
2225 2264
2226 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, 2265 return_code = sendcmd_withirq(h, CISS_REPORT_LOG, ld_buff,
2227 sizeof(ReportLunData_struct), 2266 sizeof(ReportLunData_struct),
2228 0, CTLR_LUNID, TYPE_CMD); 2267 0, CTLR_LUNID, TYPE_CMD);
2229 2268
2230 if (return_code == IO_OK) 2269 if (return_code == IO_OK)
2231 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength); 2270 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength);
2232 else { /* reading number of logical volumes failed */ 2271 else { /* reading number of logical volumes failed */
2233 printk(KERN_WARNING "cciss: report logical volume" 2272 dev_warn(&h->pdev->dev,
2234 " command failed\n"); 2273 "report logical volume command failed\n");
2235 listlength = 0; 2274 listlength = 0;
2236 goto freeret; 2275 goto freeret;
2237 } 2276 }
@@ -2239,7 +2278,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2239 num_luns = listlength / 8; /* 8 bytes per entry */ 2278 num_luns = listlength / 8; /* 8 bytes per entry */
2240 if (num_luns > CISS_MAX_LUN) { 2279 if (num_luns > CISS_MAX_LUN) {
2241 num_luns = CISS_MAX_LUN; 2280 num_luns = CISS_MAX_LUN;
2242 printk(KERN_WARNING "cciss: more luns configured" 2281 dev_warn(&h->pdev->dev, "more luns configured"
2243 " on controller than can be handled by" 2282 " on controller than can be handled by"
2244 " this driver.\n"); 2283 " this driver.\n");
2245 } 2284 }
@@ -2270,9 +2309,9 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2270 } 2309 }
2271 if (!drv_found) { 2310 if (!drv_found) {
2272 /* Deregister it from the OS, it's gone. */ 2311 /* Deregister it from the OS, it's gone. */
2273 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2312 spin_lock_irqsave(&h->lock, flags);
2274 h->drv[i]->busy_configuring = 1; 2313 h->drv[i]->busy_configuring = 1;
2275 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2314 spin_unlock_irqrestore(&h->lock, flags);
2276 return_code = deregister_disk(h, i, 1, via_ioctl); 2315 return_code = deregister_disk(h, i, 1, via_ioctl);
2277 if (h->drv[i] != NULL) 2316 if (h->drv[i] != NULL)
2278 h->drv[i]->busy_configuring = 0; 2317 h->drv[i]->busy_configuring = 0;
@@ -2311,8 +2350,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2311 if (drv_index == -1) 2350 if (drv_index == -1)
2312 goto freeret; 2351 goto freeret;
2313 } 2352 }
2314 cciss_update_drive_info(ctlr, drv_index, first_time, 2353 cciss_update_drive_info(h, drv_index, first_time, via_ioctl);
2315 via_ioctl);
2316 } /* end for */ 2354 } /* end for */
2317 2355
2318freeret: 2356freeret:
@@ -2324,7 +2362,7 @@ freeret:
2324 */ 2362 */
2325 return -1; 2363 return -1;
2326mem_msg: 2364mem_msg:
2327 printk(KERN_ERR "cciss: out of memory\n"); 2365 dev_err(&h->pdev->dev, "out of memory\n");
2328 h->busy_configuring = 0; 2366 h->busy_configuring = 0;
2329 goto freeret; 2367 goto freeret;
2330} 2368}
@@ -2444,11 +2482,10 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
2444 return 0; 2482 return 0;
2445} 2483}
2446 2484
2447static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, 2485static int fill_cmd(ctlr_info_t *h, CommandList_struct *c, __u8 cmd, void *buff,
2448 size_t size, __u8 page_code, unsigned char *scsi3addr, 2486 size_t size, __u8 page_code, unsigned char *scsi3addr,
2449 int cmd_type) 2487 int cmd_type)
2450{ 2488{
2451 ctlr_info_t *h = hba[ctlr];
2452 u64bit buff_dma_handle; 2489 u64bit buff_dma_handle;
2453 int status = IO_OK; 2490 int status = IO_OK;
2454 2491
@@ -2532,8 +2569,7 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
2532 c->Request.Timeout = 0; 2569 c->Request.Timeout = 0;
2533 break; 2570 break;
2534 default: 2571 default:
2535 printk(KERN_WARNING 2572 dev_warn(&h->pdev->dev, "Unknown Command 0x%c\n", cmd);
2536 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
2537 return IO_ERROR; 2573 return IO_ERROR;
2538 } 2574 }
2539 } else if (cmd_type == TYPE_MSG) { 2575 } else if (cmd_type == TYPE_MSG) {
@@ -2565,13 +2601,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
2565 c->Request.CDB[0] = cmd; 2601 c->Request.CDB[0] = cmd;
2566 break; 2602 break;
2567 default: 2603 default:
2568 printk(KERN_WARNING 2604 dev_warn(&h->pdev->dev,
2569 "cciss%d: unknown message type %d\n", ctlr, cmd); 2605 "unknown message type %d\n", cmd);
2570 return IO_ERROR; 2606 return IO_ERROR;
2571 } 2607 }
2572 } else { 2608 } else {
2573 printk(KERN_WARNING 2609 dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type);
2574 "cciss%d: unknown command type %d\n", ctlr, cmd_type);
2575 return IO_ERROR; 2610 return IO_ERROR;
2576 } 2611 }
2577 /* Fill in the scatter gather information */ 2612 /* Fill in the scatter gather information */
@@ -2599,15 +2634,14 @@ static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
2599 default: 2634 default:
2600 if (check_for_unit_attention(h, c)) 2635 if (check_for_unit_attention(h, c))
2601 return IO_NEEDS_RETRY; 2636 return IO_NEEDS_RETRY;
2602 printk(KERN_WARNING "cciss%d: cmd 0x%02x " 2637 dev_warn(&h->pdev->dev, "cmd 0x%02x "
2603 "check condition, sense key = 0x%02x\n", 2638 "check condition, sense key = 0x%02x\n",
2604 h->ctlr, c->Request.CDB[0], 2639 c->Request.CDB[0], c->err_info->SenseInfo[2]);
2605 c->err_info->SenseInfo[2]);
2606 } 2640 }
2607 break; 2641 break;
2608 default: 2642 default:
2609 printk(KERN_WARNING "cciss%d: cmd 0x%02x" 2643 dev_warn(&h->pdev->dev, "cmd 0x%02x"
2610 "scsi status = 0x%02x\n", h->ctlr, 2644 "scsi status = 0x%02x\n",
2611 c->Request.CDB[0], c->err_info->ScsiStatus); 2645 c->Request.CDB[0], c->err_info->ScsiStatus);
2612 break; 2646 break;
2613 } 2647 }
@@ -2630,43 +2664,42 @@ static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c)
2630 /* expected for inquiry and report lun commands */ 2664 /* expected for inquiry and report lun commands */
2631 break; 2665 break;
2632 case CMD_INVALID: 2666 case CMD_INVALID:
2633 printk(KERN_WARNING "cciss: cmd 0x%02x is " 2667 dev_warn(&h->pdev->dev, "cmd 0x%02x is "
2634 "reported invalid\n", c->Request.CDB[0]); 2668 "reported invalid\n", c->Request.CDB[0]);
2635 return_status = IO_ERROR; 2669 return_status = IO_ERROR;
2636 break; 2670 break;
2637 case CMD_PROTOCOL_ERR: 2671 case CMD_PROTOCOL_ERR:
2638 printk(KERN_WARNING "cciss: cmd 0x%02x has " 2672 dev_warn(&h->pdev->dev, "cmd 0x%02x has "
2639 "protocol error \n", c->Request.CDB[0]); 2673 "protocol error\n", c->Request.CDB[0]);
2640 return_status = IO_ERROR; 2674 return_status = IO_ERROR;
2641 break; 2675 break;
2642 case CMD_HARDWARE_ERR: 2676 case CMD_HARDWARE_ERR:
2643 printk(KERN_WARNING "cciss: cmd 0x%02x had " 2677 dev_warn(&h->pdev->dev, "cmd 0x%02x had "
2644 " hardware error\n", c->Request.CDB[0]); 2678 " hardware error\n", c->Request.CDB[0]);
2645 return_status = IO_ERROR; 2679 return_status = IO_ERROR;
2646 break; 2680 break;
2647 case CMD_CONNECTION_LOST: 2681 case CMD_CONNECTION_LOST:
2648 printk(KERN_WARNING "cciss: cmd 0x%02x had " 2682 dev_warn(&h->pdev->dev, "cmd 0x%02x had "
2649 "connection lost\n", c->Request.CDB[0]); 2683 "connection lost\n", c->Request.CDB[0]);
2650 return_status = IO_ERROR; 2684 return_status = IO_ERROR;
2651 break; 2685 break;
2652 case CMD_ABORTED: 2686 case CMD_ABORTED:
2653 printk(KERN_WARNING "cciss: cmd 0x%02x was " 2687 dev_warn(&h->pdev->dev, "cmd 0x%02x was "
2654 "aborted\n", c->Request.CDB[0]); 2688 "aborted\n", c->Request.CDB[0]);
2655 return_status = IO_ERROR; 2689 return_status = IO_ERROR;
2656 break; 2690 break;
2657 case CMD_ABORT_FAILED: 2691 case CMD_ABORT_FAILED:
2658 printk(KERN_WARNING "cciss: cmd 0x%02x reports " 2692 dev_warn(&h->pdev->dev, "cmd 0x%02x reports "
2659 "abort failed\n", c->Request.CDB[0]); 2693 "abort failed\n", c->Request.CDB[0]);
2660 return_status = IO_ERROR; 2694 return_status = IO_ERROR;
2661 break; 2695 break;
2662 case CMD_UNSOLICITED_ABORT: 2696 case CMD_UNSOLICITED_ABORT:
2663 printk(KERN_WARNING 2697 dev_warn(&h->pdev->dev, "unsolicited abort 0x%02x\n",
2664 "cciss%d: unsolicited abort 0x%02x\n", h->ctlr,
2665 c->Request.CDB[0]); 2698 c->Request.CDB[0]);
2666 return_status = IO_NEEDS_RETRY; 2699 return_status = IO_NEEDS_RETRY;
2667 break; 2700 break;
2668 default: 2701 default:
2669 printk(KERN_WARNING "cciss: cmd 0x%02x returned " 2702 dev_warn(&h->pdev->dev, "cmd 0x%02x returned "
2670 "unknown status %x\n", c->Request.CDB[0], 2703 "unknown status %x\n", c->Request.CDB[0],
2671 c->err_info->CommandStatus); 2704 c->err_info->CommandStatus);
2672 return_status = IO_ERROR; 2705 return_status = IO_ERROR;
@@ -2679,17 +2712,11 @@ static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
2679{ 2712{
2680 DECLARE_COMPLETION_ONSTACK(wait); 2713 DECLARE_COMPLETION_ONSTACK(wait);
2681 u64bit buff_dma_handle; 2714 u64bit buff_dma_handle;
2682 unsigned long flags;
2683 int return_status = IO_OK; 2715 int return_status = IO_OK;
2684 2716
2685resend_cmd2: 2717resend_cmd2:
2686 c->waiting = &wait; 2718 c->waiting = &wait;
2687 /* Put the request on the tail of the queue and send it */ 2719 enqueue_cmd_and_start_io(h, c);
2688 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2689 addQ(&h->reqQ, c);
2690 h->Qdepth++;
2691 start_io(h);
2692 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2693 2720
2694 wait_for_completion(&wait); 2721 wait_for_completion(&wait);
2695 2722
@@ -2700,7 +2727,7 @@ resend_cmd2:
2700 2727
2701 if (return_status == IO_NEEDS_RETRY && 2728 if (return_status == IO_NEEDS_RETRY &&
2702 c->retry_count < MAX_CMD_RETRIES) { 2729 c->retry_count < MAX_CMD_RETRIES) {
2703 printk(KERN_WARNING "cciss%d: retrying 0x%02x\n", h->ctlr, 2730 dev_warn(&h->pdev->dev, "retrying 0x%02x\n",
2704 c->Request.CDB[0]); 2731 c->Request.CDB[0]);
2705 c->retry_count++; 2732 c->retry_count++;
2706 /* erase the old error information */ 2733 /* erase the old error information */
@@ -2719,27 +2746,26 @@ command_done:
2719 return return_status; 2746 return return_status;
2720} 2747}
2721 2748
2722static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 2749static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
2723 __u8 page_code, unsigned char scsi3addr[], 2750 __u8 page_code, unsigned char scsi3addr[],
2724 int cmd_type) 2751 int cmd_type)
2725{ 2752{
2726 ctlr_info_t *h = hba[ctlr];
2727 CommandList_struct *c; 2753 CommandList_struct *c;
2728 int return_status; 2754 int return_status;
2729 2755
2730 c = cmd_alloc(h, 0); 2756 c = cmd_special_alloc(h);
2731 if (!c) 2757 if (!c)
2732 return -ENOMEM; 2758 return -ENOMEM;
2733 return_status = fill_cmd(c, cmd, ctlr, buff, size, page_code, 2759 return_status = fill_cmd(h, c, cmd, buff, size, page_code,
2734 scsi3addr, cmd_type); 2760 scsi3addr, cmd_type);
2735 if (return_status == IO_OK) 2761 if (return_status == IO_OK)
2736 return_status = sendcmd_withirq_core(h, c, 1); 2762 return_status = sendcmd_withirq_core(h, c, 1);
2737 2763
2738 cmd_free(h, c, 0); 2764 cmd_special_free(h, c);
2739 return return_status; 2765 return return_status;
2740} 2766}
2741 2767
2742static void cciss_geometry_inquiry(int ctlr, int logvol, 2768static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol,
2743 sector_t total_size, 2769 sector_t total_size,
2744 unsigned int block_size, 2770 unsigned int block_size,
2745 InquiryData_struct *inq_buff, 2771 InquiryData_struct *inq_buff,
@@ -2750,13 +2776,13 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2750 unsigned char scsi3addr[8]; 2776 unsigned char scsi3addr[8];
2751 2777
2752 memset(inq_buff, 0, sizeof(InquiryData_struct)); 2778 memset(inq_buff, 0, sizeof(InquiryData_struct));
2753 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 2779 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2754 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buff, 2780 return_code = sendcmd_withirq(h, CISS_INQUIRY, inq_buff,
2755 sizeof(*inq_buff), 0xC1, scsi3addr, TYPE_CMD); 2781 sizeof(*inq_buff), 0xC1, scsi3addr, TYPE_CMD);
2756 if (return_code == IO_OK) { 2782 if (return_code == IO_OK) {
2757 if (inq_buff->data_byte[8] == 0xFF) { 2783 if (inq_buff->data_byte[8] == 0xFF) {
2758 printk(KERN_WARNING 2784 dev_warn(&h->pdev->dev,
2759 "cciss: reading geometry failed, volume " 2785 "reading geometry failed, volume "
2760 "does not support reading geometry\n"); 2786 "does not support reading geometry\n");
2761 drv->heads = 255; 2787 drv->heads = 255;
2762 drv->sectors = 32; /* Sectors per track */ 2788 drv->sectors = 32; /* Sectors per track */
@@ -2780,12 +2806,12 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2780 drv->cylinders = real_size; 2806 drv->cylinders = real_size;
2781 } 2807 }
2782 } else { /* Get geometry failed */ 2808 } else { /* Get geometry failed */
2783 printk(KERN_WARNING "cciss: reading geometry failed\n"); 2809 dev_warn(&h->pdev->dev, "reading geometry failed\n");
2784 } 2810 }
2785} 2811}
2786 2812
2787static void 2813static void
2788cciss_read_capacity(int ctlr, int logvol, sector_t *total_size, 2814cciss_read_capacity(ctlr_info_t *h, int logvol, sector_t *total_size,
2789 unsigned int *block_size) 2815 unsigned int *block_size)
2790{ 2816{
2791 ReadCapdata_struct *buf; 2817 ReadCapdata_struct *buf;
@@ -2794,25 +2820,25 @@ cciss_read_capacity(int ctlr, int logvol, sector_t *total_size,
2794 2820
2795 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL); 2821 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2796 if (!buf) { 2822 if (!buf) {
2797 printk(KERN_WARNING "cciss: out of memory\n"); 2823 dev_warn(&h->pdev->dev, "out of memory\n");
2798 return; 2824 return;
2799 } 2825 }
2800 2826
2801 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 2827 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2802 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, ctlr, buf, 2828 return_code = sendcmd_withirq(h, CCISS_READ_CAPACITY, buf,
2803 sizeof(ReadCapdata_struct), 0, scsi3addr, TYPE_CMD); 2829 sizeof(ReadCapdata_struct), 0, scsi3addr, TYPE_CMD);
2804 if (return_code == IO_OK) { 2830 if (return_code == IO_OK) {
2805 *total_size = be32_to_cpu(*(__be32 *) buf->total_size); 2831 *total_size = be32_to_cpu(*(__be32 *) buf->total_size);
2806 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2832 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
2807 } else { /* read capacity command failed */ 2833 } else { /* read capacity command failed */
2808 printk(KERN_WARNING "cciss: read capacity failed\n"); 2834 dev_warn(&h->pdev->dev, "read capacity failed\n");
2809 *total_size = 0; 2835 *total_size = 0;
2810 *block_size = BLOCK_SIZE; 2836 *block_size = BLOCK_SIZE;
2811 } 2837 }
2812 kfree(buf); 2838 kfree(buf);
2813} 2839}
2814 2840
2815static void cciss_read_capacity_16(int ctlr, int logvol, 2841static void cciss_read_capacity_16(ctlr_info_t *h, int logvol,
2816 sector_t *total_size, unsigned int *block_size) 2842 sector_t *total_size, unsigned int *block_size)
2817{ 2843{
2818 ReadCapdata_struct_16 *buf; 2844 ReadCapdata_struct_16 *buf;
@@ -2821,23 +2847,23 @@ static void cciss_read_capacity_16(int ctlr, int logvol,
2821 2847
2822 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL); 2848 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2823 if (!buf) { 2849 if (!buf) {
2824 printk(KERN_WARNING "cciss: out of memory\n"); 2850 dev_warn(&h->pdev->dev, "out of memory\n");
2825 return; 2851 return;
2826 } 2852 }
2827 2853
2828 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 2854 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2829 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16, 2855 return_code = sendcmd_withirq(h, CCISS_READ_CAPACITY_16,
2830 ctlr, buf, sizeof(ReadCapdata_struct_16), 2856 buf, sizeof(ReadCapdata_struct_16),
2831 0, scsi3addr, TYPE_CMD); 2857 0, scsi3addr, TYPE_CMD);
2832 if (return_code == IO_OK) { 2858 if (return_code == IO_OK) {
2833 *total_size = be64_to_cpu(*(__be64 *) buf->total_size); 2859 *total_size = be64_to_cpu(*(__be64 *) buf->total_size);
2834 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2860 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
2835 } else { /* read capacity command failed */ 2861 } else { /* read capacity command failed */
2836 printk(KERN_WARNING "cciss: read capacity failed\n"); 2862 dev_warn(&h->pdev->dev, "read capacity failed\n");
2837 *total_size = 0; 2863 *total_size = 0;
2838 *block_size = BLOCK_SIZE; 2864 *block_size = BLOCK_SIZE;
2839 } 2865 }
2840 printk(KERN_INFO " blocks= %llu block_size= %d\n", 2866 dev_info(&h->pdev->dev, " blocks= %llu block_size= %d\n",
2841 (unsigned long long)*total_size+1, *block_size); 2867 (unsigned long long)*total_size+1, *block_size);
2842 kfree(buf); 2868 kfree(buf);
2843} 2869}
@@ -2865,17 +2891,17 @@ static int cciss_revalidate(struct gendisk *disk)
2865 2891
2866 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 2892 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
2867 if (inq_buff == NULL) { 2893 if (inq_buff == NULL) {
2868 printk(KERN_WARNING "cciss: out of memory\n"); 2894 dev_warn(&h->pdev->dev, "out of memory\n");
2869 return 1; 2895 return 1;
2870 } 2896 }
2871 if (h->cciss_read == CCISS_READ_10) { 2897 if (h->cciss_read == CCISS_READ_10) {
2872 cciss_read_capacity(h->ctlr, logvol, 2898 cciss_read_capacity(h, logvol,
2873 &total_size, &block_size); 2899 &total_size, &block_size);
2874 } else { 2900 } else {
2875 cciss_read_capacity_16(h->ctlr, logvol, 2901 cciss_read_capacity_16(h, logvol,
2876 &total_size, &block_size); 2902 &total_size, &block_size);
2877 } 2903 }
2878 cciss_geometry_inquiry(h->ctlr, logvol, total_size, block_size, 2904 cciss_geometry_inquiry(h, logvol, total_size, block_size,
2879 inq_buff, drv); 2905 inq_buff, drv);
2880 2906
2881 blk_queue_logical_block_size(drv->queue, drv->block_size); 2907 blk_queue_logical_block_size(drv->queue, drv->block_size);
@@ -2909,7 +2935,7 @@ static void start_io(ctlr_info_t *h)
2909 c = hlist_entry(h->reqQ.first, CommandList_struct, list); 2935 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
2910 /* can't do anything if fifo is full */ 2936 /* can't do anything if fifo is full */
2911 if ((h->access.fifo_full(h))) { 2937 if ((h->access.fifo_full(h))) {
2912 printk(KERN_WARNING "cciss: fifo full\n"); 2938 dev_warn(&h->pdev->dev, "fifo full\n");
2913 break; 2939 break;
2914 } 2940 }
2915 2941
@@ -2925,7 +2951,7 @@ static void start_io(ctlr_info_t *h)
2925 } 2951 }
2926} 2952}
2927 2953
2928/* Assumes that CCISS_LOCK(h->ctlr) is held. */ 2954/* Assumes that h->lock is held. */
2929/* Zeros out the error record and then resends the command back */ 2955/* Zeros out the error record and then resends the command back */
2930/* to the controller */ 2956/* to the controller */
2931static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c) 2957static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c)
@@ -2966,7 +2992,7 @@ static inline int evaluate_target_status(ctlr_info_t *h,
2966 driver_byte = DRIVER_OK; 2992 driver_byte = DRIVER_OK;
2967 msg_byte = cmd->err_info->CommandStatus; /* correct? seems too device specific */ 2993 msg_byte = cmd->err_info->CommandStatus; /* correct? seems too device specific */
2968 2994
2969 if (blk_pc_request(cmd->rq)) 2995 if (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC)
2970 host_byte = DID_PASSTHROUGH; 2996 host_byte = DID_PASSTHROUGH;
2971 else 2997 else
2972 host_byte = DID_OK; 2998 host_byte = DID_OK;
@@ -2975,8 +3001,8 @@ static inline int evaluate_target_status(ctlr_info_t *h,
2975 host_byte, driver_byte); 3001 host_byte, driver_byte);
2976 3002
2977 if (cmd->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) { 3003 if (cmd->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) {
2978 if (!blk_pc_request(cmd->rq)) 3004 if (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC)
2979 printk(KERN_WARNING "cciss: cmd %p " 3005 dev_warn(&h->pdev->dev, "cmd %p "
2980 "has SCSI Status 0x%x\n", 3006 "has SCSI Status 0x%x\n",
2981 cmd, cmd->err_info->ScsiStatus); 3007 cmd, cmd->err_info->ScsiStatus);
2982 return error_value; 3008 return error_value;
@@ -2985,17 +3011,19 @@ static inline int evaluate_target_status(ctlr_info_t *h,
2985 /* check the sense key */ 3011 /* check the sense key */
2986 sense_key = 0xf & cmd->err_info->SenseInfo[2]; 3012 sense_key = 0xf & cmd->err_info->SenseInfo[2];
2987 /* no status or recovered error */ 3013 /* no status or recovered error */
2988 if (((sense_key == 0x0) || (sense_key == 0x1)) && !blk_pc_request(cmd->rq)) 3014 if (((sense_key == 0x0) || (sense_key == 0x1)) &&
3015 (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC))
2989 error_value = 0; 3016 error_value = 0;
2990 3017
2991 if (check_for_unit_attention(h, cmd)) { 3018 if (check_for_unit_attention(h, cmd)) {
2992 *retry_cmd = !blk_pc_request(cmd->rq); 3019 *retry_cmd = !(cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC);
2993 return 0; 3020 return 0;
2994 } 3021 }
2995 3022
2996 if (!blk_pc_request(cmd->rq)) { /* Not SG_IO or similar? */ 3023 /* Not SG_IO or similar? */
3024 if (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC) {
2997 if (error_value != 0) 3025 if (error_value != 0)
2998 printk(KERN_WARNING "cciss: cmd %p has CHECK CONDITION" 3026 dev_warn(&h->pdev->dev, "cmd %p has CHECK CONDITION"
2999 " sense key = 0x%x\n", cmd, sense_key); 3027 " sense key = 0x%x\n", cmd, sense_key);
3000 return error_value; 3028 return error_value;
3001 } 3029 }
@@ -3035,90 +3063,97 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
3035 rq->errors = evaluate_target_status(h, cmd, &retry_cmd); 3063 rq->errors = evaluate_target_status(h, cmd, &retry_cmd);
3036 break; 3064 break;
3037 case CMD_DATA_UNDERRUN: 3065 case CMD_DATA_UNDERRUN:
3038 if (blk_fs_request(cmd->rq)) { 3066 if (cmd->rq->cmd_type == REQ_TYPE_FS) {
3039 printk(KERN_WARNING "cciss: cmd %p has" 3067 dev_warn(&h->pdev->dev, "cmd %p has"
3040 " completed with data underrun " 3068 " completed with data underrun "
3041 "reported\n", cmd); 3069 "reported\n", cmd);
3042 cmd->rq->resid_len = cmd->err_info->ResidualCnt; 3070 cmd->rq->resid_len = cmd->err_info->ResidualCnt;
3043 } 3071 }
3044 break; 3072 break;
3045 case CMD_DATA_OVERRUN: 3073 case CMD_DATA_OVERRUN:
3046 if (blk_fs_request(cmd->rq)) 3074 if (cmd->rq->cmd_type == REQ_TYPE_FS)
3047 printk(KERN_WARNING "cciss: cmd %p has" 3075 dev_warn(&h->pdev->dev, "cciss: cmd %p has"
3048 " completed with data overrun " 3076 " completed with data overrun "
3049 "reported\n", cmd); 3077 "reported\n", cmd);
3050 break; 3078 break;
3051 case CMD_INVALID: 3079 case CMD_INVALID:
3052 printk(KERN_WARNING "cciss: cmd %p is " 3080 dev_warn(&h->pdev->dev, "cciss: cmd %p is "
3053 "reported invalid\n", cmd); 3081 "reported invalid\n", cmd);
3054 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3082 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3055 cmd->err_info->CommandStatus, DRIVER_OK, 3083 cmd->err_info->CommandStatus, DRIVER_OK,
3056 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3084 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3085 DID_PASSTHROUGH : DID_ERROR);
3057 break; 3086 break;
3058 case CMD_PROTOCOL_ERR: 3087 case CMD_PROTOCOL_ERR:
3059 printk(KERN_WARNING "cciss: cmd %p has " 3088 dev_warn(&h->pdev->dev, "cciss: cmd %p has "
3060 "protocol error \n", cmd); 3089 "protocol error\n", cmd);
3061 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3090 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3062 cmd->err_info->CommandStatus, DRIVER_OK, 3091 cmd->err_info->CommandStatus, DRIVER_OK,
3063 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3092 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3093 DID_PASSTHROUGH : DID_ERROR);
3064 break; 3094 break;
3065 case CMD_HARDWARE_ERR: 3095 case CMD_HARDWARE_ERR:
3066 printk(KERN_WARNING "cciss: cmd %p had " 3096 dev_warn(&h->pdev->dev, "cciss: cmd %p had "
3067 " hardware error\n", cmd); 3097 " hardware error\n", cmd);
3068 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3098 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3069 cmd->err_info->CommandStatus, DRIVER_OK, 3099 cmd->err_info->CommandStatus, DRIVER_OK,
3070 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3100 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3101 DID_PASSTHROUGH : DID_ERROR);
3071 break; 3102 break;
3072 case CMD_CONNECTION_LOST: 3103 case CMD_CONNECTION_LOST:
3073 printk(KERN_WARNING "cciss: cmd %p had " 3104 dev_warn(&h->pdev->dev, "cciss: cmd %p had "
3074 "connection lost\n", cmd); 3105 "connection lost\n", cmd);
3075 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3106 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3076 cmd->err_info->CommandStatus, DRIVER_OK, 3107 cmd->err_info->CommandStatus, DRIVER_OK,
3077 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3108 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3109 DID_PASSTHROUGH : DID_ERROR);
3078 break; 3110 break;
3079 case CMD_ABORTED: 3111 case CMD_ABORTED:
3080 printk(KERN_WARNING "cciss: cmd %p was " 3112 dev_warn(&h->pdev->dev, "cciss: cmd %p was "
3081 "aborted\n", cmd); 3113 "aborted\n", cmd);
3082 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3114 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3083 cmd->err_info->CommandStatus, DRIVER_OK, 3115 cmd->err_info->CommandStatus, DRIVER_OK,
3084 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ABORT); 3116 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3117 DID_PASSTHROUGH : DID_ABORT);
3085 break; 3118 break;
3086 case CMD_ABORT_FAILED: 3119 case CMD_ABORT_FAILED:
3087 printk(KERN_WARNING "cciss: cmd %p reports " 3120 dev_warn(&h->pdev->dev, "cciss: cmd %p reports "
3088 "abort failed\n", cmd); 3121 "abort failed\n", cmd);
3089 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3122 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3090 cmd->err_info->CommandStatus, DRIVER_OK, 3123 cmd->err_info->CommandStatus, DRIVER_OK,
3091 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3124 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3125 DID_PASSTHROUGH : DID_ERROR);
3092 break; 3126 break;
3093 case CMD_UNSOLICITED_ABORT: 3127 case CMD_UNSOLICITED_ABORT:
3094 printk(KERN_WARNING "cciss%d: unsolicited " 3128 dev_warn(&h->pdev->dev, "cciss%d: unsolicited "
3095 "abort %p\n", h->ctlr, cmd); 3129 "abort %p\n", h->ctlr, cmd);
3096 if (cmd->retry_count < MAX_CMD_RETRIES) { 3130 if (cmd->retry_count < MAX_CMD_RETRIES) {
3097 retry_cmd = 1; 3131 retry_cmd = 1;
3098 printk(KERN_WARNING 3132 dev_warn(&h->pdev->dev, "retrying %p\n", cmd);
3099 "cciss%d: retrying %p\n", h->ctlr, cmd);
3100 cmd->retry_count++; 3133 cmd->retry_count++;
3101 } else 3134 } else
3102 printk(KERN_WARNING 3135 dev_warn(&h->pdev->dev,
3103 "cciss%d: %p retried too " 3136 "%p retried too many times\n", cmd);
3104 "many times\n", h->ctlr, cmd);
3105 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3137 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3106 cmd->err_info->CommandStatus, DRIVER_OK, 3138 cmd->err_info->CommandStatus, DRIVER_OK,
3107 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ABORT); 3139 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3140 DID_PASSTHROUGH : DID_ABORT);
3108 break; 3141 break;
3109 case CMD_TIMEOUT: 3142 case CMD_TIMEOUT:
3110 printk(KERN_WARNING "cciss: cmd %p timedout\n", cmd); 3143 dev_warn(&h->pdev->dev, "cmd %p timedout\n", cmd);
3111 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3144 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3112 cmd->err_info->CommandStatus, DRIVER_OK, 3145 cmd->err_info->CommandStatus, DRIVER_OK,
3113 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3146 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3147 DID_PASSTHROUGH : DID_ERROR);
3114 break; 3148 break;
3115 default: 3149 default:
3116 printk(KERN_WARNING "cciss: cmd %p returned " 3150 dev_warn(&h->pdev->dev, "cmd %p returned "
3117 "unknown status %x\n", cmd, 3151 "unknown status %x\n", cmd,
3118 cmd->err_info->CommandStatus); 3152 cmd->err_info->CommandStatus);
3119 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3153 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3120 cmd->err_info->CommandStatus, DRIVER_OK, 3154 cmd->err_info->CommandStatus, DRIVER_OK,
3121 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3155 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3156 DID_PASSTHROUGH : DID_ERROR);
3122 } 3157 }
3123 3158
3124after_error_processing: 3159after_error_processing:
@@ -3132,6 +3167,34 @@ after_error_processing:
3132 blk_complete_request(cmd->rq); 3167 blk_complete_request(cmd->rq);
3133} 3168}
3134 3169
3170static inline u32 cciss_tag_contains_index(u32 tag)
3171{
3172#define DIRECT_LOOKUP_BIT 0x10
3173 return tag & DIRECT_LOOKUP_BIT;
3174}
3175
3176static inline u32 cciss_tag_to_index(u32 tag)
3177{
3178#define DIRECT_LOOKUP_SHIFT 5
3179 return tag >> DIRECT_LOOKUP_SHIFT;
3180}
3181
3182static inline u32 cciss_tag_discard_error_bits(u32 tag)
3183{
3184#define CCISS_ERROR_BITS 0x03
3185 return tag & ~CCISS_ERROR_BITS;
3186}
3187
3188static inline void cciss_mark_tag_indexed(u32 *tag)
3189{
3190 *tag |= DIRECT_LOOKUP_BIT;
3191}
3192
3193static inline void cciss_set_tag_index(u32 *tag, u32 index)
3194{
3195 *tag |= (index << DIRECT_LOOKUP_SHIFT);
3196}
3197
3135/* 3198/*
3136 * Get a request and submit it to the controller. 3199 * Get a request and submit it to the controller.
3137 */ 3200 */
@@ -3163,7 +3226,8 @@ static void do_cciss_request(struct request_queue *q)
3163 3226
3164 BUG_ON(creq->nr_phys_segments > h->maxsgentries); 3227 BUG_ON(creq->nr_phys_segments > h->maxsgentries);
3165 3228
3166 if ((c = cmd_alloc(h, 1)) == NULL) 3229 c = cmd_alloc(h);
3230 if (!c)
3167 goto full; 3231 goto full;
3168 3232
3169 blk_start_request(creq); 3233 blk_start_request(creq);
@@ -3180,8 +3244,8 @@ static void do_cciss_request(struct request_queue *q)
3180 /* got command from pool, so use the command block index instead */ 3244 /* got command from pool, so use the command block index instead */
3181 /* for direct lookups. */ 3245 /* for direct lookups. */
3182 /* The first 2 bits are reserved for controller error reporting. */ 3246 /* The first 2 bits are reserved for controller error reporting. */
3183 c->Header.Tag.lower = (c->cmdindex << 3); 3247 cciss_set_tag_index(&c->Header.Tag.lower, c->cmdindex);
3184 c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */ 3248 cciss_mark_tag_indexed(&c->Header.Tag.lower);
3185 memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID)); 3249 memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID));
3186 c->Request.CDBLen = 10; /* 12 byte commands not in FW yet; */ 3250 c->Request.CDBLen = 10; /* 12 byte commands not in FW yet; */
3187 c->Request.Type.Type = TYPE_CMD; /* It is a command. */ 3251 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
@@ -3192,11 +3256,8 @@ static void do_cciss_request(struct request_queue *q)
3192 c->Request.CDB[0] = 3256 c->Request.CDB[0] =
3193 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 3257 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
3194 start_blk = blk_rq_pos(creq); 3258 start_blk = blk_rq_pos(creq);
3195#ifdef CCISS_DEBUG 3259 dev_dbg(&h->pdev->dev, "sector =%d nr_sectors=%d\n",
3196 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",
3197 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq)); 3260 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq));
3198#endif /* CCISS_DEBUG */
3199
3200 sg_init_table(tmp_sg, h->maxsgentries); 3261 sg_init_table(tmp_sg, h->maxsgentries);
3201 seg = blk_rq_map_sg(q, creq, tmp_sg); 3262 seg = blk_rq_map_sg(q, creq, tmp_sg);
3202 3263
@@ -3236,17 +3297,18 @@ static void do_cciss_request(struct request_queue *q)
3236 if (seg > h->maxSG) 3297 if (seg > h->maxSG)
3237 h->maxSG = seg; 3298 h->maxSG = seg;
3238 3299
3239#ifdef CCISS_DEBUG 3300 dev_dbg(&h->pdev->dev, "Submitting %u sectors in %d segments "
3240 printk(KERN_DEBUG "cciss: Submitting %ld sectors in %d segments "
3241 "chained[%d]\n", 3301 "chained[%d]\n",
3242 blk_rq_sectors(creq), seg, chained); 3302 blk_rq_sectors(creq), seg, chained);
3243#endif /* CCISS_DEBUG */
3244 3303
3245 c->Header.SGList = c->Header.SGTotal = seg + chained; 3304 c->Header.SGTotal = seg + chained;
3246 if (seg > h->max_cmd_sgentries) 3305 if (seg <= h->max_cmd_sgentries)
3306 c->Header.SGList = c->Header.SGTotal;
3307 else
3247 c->Header.SGList = h->max_cmd_sgentries; 3308 c->Header.SGList = h->max_cmd_sgentries;
3309 set_performant_mode(h, c);
3248 3310
3249 if (likely(blk_fs_request(creq))) { 3311 if (likely(creq->cmd_type == REQ_TYPE_FS)) {
3250 if(h->cciss_read == CCISS_READ_10) { 3312 if(h->cciss_read == CCISS_READ_10) {
3251 c->Request.CDB[1] = 0; 3313 c->Request.CDB[1] = 0;
3252 c->Request.CDB[2] = (start_blk >> 24) & 0xff; /* MSB */ 3314 c->Request.CDB[2] = (start_blk >> 24) & 0xff; /* MSB */
@@ -3276,11 +3338,12 @@ static void do_cciss_request(struct request_queue *q)
3276 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff; 3338 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
3277 c->Request.CDB[14] = c->Request.CDB[15] = 0; 3339 c->Request.CDB[14] = c->Request.CDB[15] = 0;
3278 } 3340 }
3279 } else if (blk_pc_request(creq)) { 3341 } else if (creq->cmd_type == REQ_TYPE_BLOCK_PC) {
3280 c->Request.CDBLen = creq->cmd_len; 3342 c->Request.CDBLen = creq->cmd_len;
3281 memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB); 3343 memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB);
3282 } else { 3344 } else {
3283 printk(KERN_WARNING "cciss%d: bad request type %d\n", h->ctlr, creq->cmd_type); 3345 dev_warn(&h->pdev->dev, "bad request type %d\n",
3346 creq->cmd_type);
3284 BUG(); 3347 BUG();
3285 } 3348 }
3286 3349
@@ -3313,72 +3376,131 @@ static inline int interrupt_pending(ctlr_info_t *h)
3313 3376
3314static inline long interrupt_not_for_us(ctlr_info_t *h) 3377static inline long interrupt_not_for_us(ctlr_info_t *h)
3315{ 3378{
3316 return (((h->access.intr_pending(h) == 0) || 3379 return ((h->access.intr_pending(h) == 0) ||
3317 (h->interrupts_enabled == 0))); 3380 (h->interrupts_enabled == 0));
3318} 3381}
3319 3382
3320static irqreturn_t do_cciss_intr(int irq, void *dev_id) 3383static inline int bad_tag(ctlr_info_t *h, u32 tag_index,
3384 u32 raw_tag)
3321{ 3385{
3322 ctlr_info_t *h = dev_id; 3386 if (unlikely(tag_index >= h->nr_cmds)) {
3387 dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag);
3388 return 1;
3389 }
3390 return 0;
3391}
3392
3393static inline void finish_cmd(ctlr_info_t *h, CommandList_struct *c,
3394 u32 raw_tag)
3395{
3396 removeQ(c);
3397 if (likely(c->cmd_type == CMD_RWREQ))
3398 complete_command(h, c, 0);
3399 else if (c->cmd_type == CMD_IOCTL_PEND)
3400 complete(c->waiting);
3401#ifdef CONFIG_CISS_SCSI_TAPE
3402 else if (c->cmd_type == CMD_SCSI)
3403 complete_scsi_command(c, 0, raw_tag);
3404#endif
3405}
3406
3407static inline u32 next_command(ctlr_info_t *h)
3408{
3409 u32 a;
3410
3411 if (unlikely(h->transMethod != CFGTBL_Trans_Performant))
3412 return h->access.command_completed(h);
3413
3414 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
3415 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
3416 (h->reply_pool_head)++;
3417 h->commands_outstanding--;
3418 } else {
3419 a = FIFO_EMPTY;
3420 }
3421 /* Check for wraparound */
3422 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
3423 h->reply_pool_head = h->reply_pool;
3424 h->reply_pool_wraparound ^= 1;
3425 }
3426 return a;
3427}
3428
3429/* process completion of an indexed ("direct lookup") command */
3430static inline u32 process_indexed_cmd(ctlr_info_t *h, u32 raw_tag)
3431{
3432 u32 tag_index;
3323 CommandList_struct *c; 3433 CommandList_struct *c;
3434
3435 tag_index = cciss_tag_to_index(raw_tag);
3436 if (bad_tag(h, tag_index, raw_tag))
3437 return next_command(h);
3438 c = h->cmd_pool + tag_index;
3439 finish_cmd(h, c, raw_tag);
3440 return next_command(h);
3441}
3442
3443/* process completion of a non-indexed command */
3444static inline u32 process_nonindexed_cmd(ctlr_info_t *h, u32 raw_tag)
3445{
3446 u32 tag;
3447 CommandList_struct *c = NULL;
3448 struct hlist_node *tmp;
3449 __u32 busaddr_masked, tag_masked;
3450
3451 tag = cciss_tag_discard_error_bits(raw_tag);
3452 hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
3453 busaddr_masked = cciss_tag_discard_error_bits(c->busaddr);
3454 tag_masked = cciss_tag_discard_error_bits(tag);
3455 if (busaddr_masked == tag_masked) {
3456 finish_cmd(h, c, raw_tag);
3457 return next_command(h);
3458 }
3459 }
3460 bad_tag(h, h->nr_cmds + 1, raw_tag);
3461 return next_command(h);
3462}
3463
3464static irqreturn_t do_cciss_intx(int irq, void *dev_id)
3465{
3466 ctlr_info_t *h = dev_id;
3324 unsigned long flags; 3467 unsigned long flags;
3325 __u32 a, a1, a2; 3468 u32 raw_tag;
3326 3469
3327 if (interrupt_not_for_us(h)) 3470 if (interrupt_not_for_us(h))
3328 return IRQ_NONE; 3471 return IRQ_NONE;
3329 /* 3472 spin_lock_irqsave(&h->lock, flags);
3330 * If there are completed commands in the completion queue,
3331 * we had better do something about it.
3332 */
3333 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
3334 while (interrupt_pending(h)) { 3473 while (interrupt_pending(h)) {
3335 while ((a = get_next_completion(h)) != FIFO_EMPTY) { 3474 raw_tag = get_next_completion(h);
3336 a1 = a; 3475 while (raw_tag != FIFO_EMPTY) {
3337 if ((a & 0x04)) { 3476 if (cciss_tag_contains_index(raw_tag))
3338 a2 = (a >> 3); 3477 raw_tag = process_indexed_cmd(h, raw_tag);
3339 if (a2 >= h->nr_cmds) { 3478 else
3340 printk(KERN_WARNING 3479 raw_tag = process_nonindexed_cmd(h, raw_tag);
3341 "cciss: controller cciss%d failed, stopping.\n",
3342 h->ctlr);
3343 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
3344 fail_all_cmds(h->ctlr);
3345 return IRQ_HANDLED;
3346 }
3347
3348 c = h->cmd_pool + a2;
3349 a = c->busaddr;
3350
3351 } else {
3352 struct hlist_node *tmp;
3353
3354 a &= ~3;
3355 c = NULL;
3356 hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
3357 if (c->busaddr == a)
3358 break;
3359 }
3360 }
3361 /*
3362 * If we've found the command, take it off the
3363 * completion Q and free it
3364 */
3365 if (c && c->busaddr == a) {
3366 removeQ(c);
3367 if (c->cmd_type == CMD_RWREQ) {
3368 complete_command(h, c, 0);
3369 } else if (c->cmd_type == CMD_IOCTL_PEND) {
3370 complete(c->waiting);
3371 }
3372# ifdef CONFIG_CISS_SCSI_TAPE
3373 else if (c->cmd_type == CMD_SCSI)
3374 complete_scsi_command(c, 0, a1);
3375# endif
3376 continue;
3377 }
3378 } 3480 }
3379 } 3481 }
3482 spin_unlock_irqrestore(&h->lock, flags);
3483 return IRQ_HANDLED;
3484}
3380 3485
3381 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 3486/* Add a second interrupt handler for MSI/MSI-X mode. In this mode we never
3487 * check the interrupt pending register because it is not set.
3488 */
3489static irqreturn_t do_cciss_msix_intr(int irq, void *dev_id)
3490{
3491 ctlr_info_t *h = dev_id;
3492 unsigned long flags;
3493 u32 raw_tag;
3494
3495 spin_lock_irqsave(&h->lock, flags);
3496 raw_tag = get_next_completion(h);
3497 while (raw_tag != FIFO_EMPTY) {
3498 if (cciss_tag_contains_index(raw_tag))
3499 raw_tag = process_indexed_cmd(h, raw_tag);
3500 else
3501 raw_tag = process_nonindexed_cmd(h, raw_tag);
3502 }
3503 spin_unlock_irqrestore(&h->lock, flags);
3382 return IRQ_HANDLED; 3504 return IRQ_HANDLED;
3383} 3505}
3384 3506
@@ -3510,18 +3632,17 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3510 3632
3511 switch (c->err_info->SenseInfo[12]) { 3633 switch (c->err_info->SenseInfo[12]) {
3512 case STATE_CHANGED: 3634 case STATE_CHANGED:
3513 printk(KERN_WARNING "cciss%d: a state change " 3635 dev_warn(&h->pdev->dev, "a state change "
3514 "detected, command retried\n", h->ctlr); 3636 "detected, command retried\n");
3515 return 1; 3637 return 1;
3516 break; 3638 break;
3517 case LUN_FAILED: 3639 case LUN_FAILED:
3518 printk(KERN_WARNING "cciss%d: LUN failure " 3640 dev_warn(&h->pdev->dev, "LUN failure "
3519 "detected, action required\n", h->ctlr); 3641 "detected, action required\n");
3520 return 1; 3642 return 1;
3521 break; 3643 break;
3522 case REPORT_LUNS_CHANGED: 3644 case REPORT_LUNS_CHANGED:
3523 printk(KERN_WARNING "cciss%d: report LUN data " 3645 dev_warn(&h->pdev->dev, "report LUN data changed\n");
3524 "changed\n", h->ctlr);
3525 /* 3646 /*
3526 * Here, we could call add_to_scan_list and wake up the scan thread, 3647 * Here, we could call add_to_scan_list and wake up the scan thread,
3527 * except that it's quite likely that we will get more than one 3648 * except that it's quite likely that we will get more than one
@@ -3541,19 +3662,18 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3541 return 1; 3662 return 1;
3542 break; 3663 break;
3543 case POWER_OR_RESET: 3664 case POWER_OR_RESET:
3544 printk(KERN_WARNING "cciss%d: a power on " 3665 dev_warn(&h->pdev->dev,
3545 "or device reset detected\n", h->ctlr); 3666 "a power on or device reset detected\n");
3546 return 1; 3667 return 1;
3547 break; 3668 break;
3548 case UNIT_ATTENTION_CLEARED: 3669 case UNIT_ATTENTION_CLEARED:
3549 printk(KERN_WARNING "cciss%d: unit attention " 3670 dev_warn(&h->pdev->dev,
3550 "cleared by another initiator\n", h->ctlr); 3671 "unit attention cleared by another initiator\n");
3551 return 1; 3672 return 1;
3552 break; 3673 break;
3553 default: 3674 default:
3554 printk(KERN_WARNING "cciss%d: unknown " 3675 dev_warn(&h->pdev->dev, "unknown unit attention detected\n");
3555 "unit attention detected\n", h->ctlr); 3676 return 1;
3556 return 1;
3557 } 3677 }
3558} 3678}
3559 3679
@@ -3562,39 +3682,41 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3562 * the io functions. 3682 * the io functions.
3563 * This is for debug only. 3683 * This is for debug only.
3564 */ 3684 */
3565#ifdef CCISS_DEBUG 3685static void print_cfg_table(ctlr_info_t *h)
3566static void print_cfg_table(CfgTable_struct *tb)
3567{ 3686{
3568 int i; 3687 int i;
3569 char temp_name[17]; 3688 char temp_name[17];
3689 CfgTable_struct *tb = h->cfgtable;
3570 3690
3571 printk("Controller Configuration information\n"); 3691 dev_dbg(&h->pdev->dev, "Controller Configuration information\n");
3572 printk("------------------------------------\n"); 3692 dev_dbg(&h->pdev->dev, "------------------------------------\n");
3573 for (i = 0; i < 4; i++) 3693 for (i = 0; i < 4; i++)
3574 temp_name[i] = readb(&(tb->Signature[i])); 3694 temp_name[i] = readb(&(tb->Signature[i]));
3575 temp_name[4] = '\0'; 3695 temp_name[4] = '\0';
3576 printk(" Signature = %s\n", temp_name); 3696 dev_dbg(&h->pdev->dev, " Signature = %s\n", temp_name);
3577 printk(" Spec Number = %d\n", readl(&(tb->SpecValence))); 3697 dev_dbg(&h->pdev->dev, " Spec Number = %d\n",
3578 printk(" Transport methods supported = 0x%x\n", 3698 readl(&(tb->SpecValence)));
3699 dev_dbg(&h->pdev->dev, " Transport methods supported = 0x%x\n",
3579 readl(&(tb->TransportSupport))); 3700 readl(&(tb->TransportSupport)));
3580 printk(" Transport methods active = 0x%x\n", 3701 dev_dbg(&h->pdev->dev, " Transport methods active = 0x%x\n",
3581 readl(&(tb->TransportActive))); 3702 readl(&(tb->TransportActive)));
3582 printk(" Requested transport Method = 0x%x\n", 3703 dev_dbg(&h->pdev->dev, " Requested transport Method = 0x%x\n",
3583 readl(&(tb->HostWrite.TransportRequest))); 3704 readl(&(tb->HostWrite.TransportRequest)));
3584 printk(" Coalesce Interrupt Delay = 0x%x\n", 3705 dev_dbg(&h->pdev->dev, " Coalesce Interrupt Delay = 0x%x\n",
3585 readl(&(tb->HostWrite.CoalIntDelay))); 3706 readl(&(tb->HostWrite.CoalIntDelay)));
3586 printk(" Coalesce Interrupt Count = 0x%x\n", 3707 dev_dbg(&h->pdev->dev, " Coalesce Interrupt Count = 0x%x\n",
3587 readl(&(tb->HostWrite.CoalIntCount))); 3708 readl(&(tb->HostWrite.CoalIntCount)));
3588 printk(" Max outstanding commands = 0x%d\n", 3709 dev_dbg(&h->pdev->dev, " Max outstanding commands = 0x%d\n",
3589 readl(&(tb->CmdsOutMax))); 3710 readl(&(tb->CmdsOutMax)));
3590 printk(" Bus Types = 0x%x\n", readl(&(tb->BusTypes))); 3711 dev_dbg(&h->pdev->dev, " Bus Types = 0x%x\n",
3712 readl(&(tb->BusTypes)));
3591 for (i = 0; i < 16; i++) 3713 for (i = 0; i < 16; i++)
3592 temp_name[i] = readb(&(tb->ServerName[i])); 3714 temp_name[i] = readb(&(tb->ServerName[i]));
3593 temp_name[16] = '\0'; 3715 temp_name[16] = '\0';
3594 printk(" Server Name = %s\n", temp_name); 3716 dev_dbg(&h->pdev->dev, " Server Name = %s\n", temp_name);
3595 printk(" Heartbeat Counter = 0x%x\n\n\n", readl(&(tb->HeartBeat))); 3717 dev_dbg(&h->pdev->dev, " Heartbeat Counter = 0x%x\n\n\n",
3718 readl(&(tb->HeartBeat)));
3596} 3719}
3597#endif /* CCISS_DEBUG */
3598 3720
3599static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) 3721static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3600{ 3722{
@@ -3618,7 +3740,7 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3618 offset += 8; 3740 offset += 8;
3619 break; 3741 break;
3620 default: /* reserved in PCI 2.2 */ 3742 default: /* reserved in PCI 2.2 */
3621 printk(KERN_WARNING 3743 dev_warn(&pdev->dev,
3622 "Base address is invalid\n"); 3744 "Base address is invalid\n");
3623 return -1; 3745 return -1;
3624 break; 3746 break;
@@ -3630,12 +3752,182 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3630 return -1; 3752 return -1;
3631} 3753}
3632 3754
3755/* Fill in bucket_map[], given nsgs (the max number of
3756 * scatter gather elements supported) and bucket[],
3757 * which is an array of 8 integers. The bucket[] array
3758 * contains 8 different DMA transfer sizes (in 16
3759 * byte increments) which the controller uses to fetch
3760 * commands. This function fills in bucket_map[], which
3761 * maps a given number of scatter gather elements to one of
3762 * the 8 DMA transfer sizes. The point of it is to allow the
3763 * controller to only do as much DMA as needed to fetch the
3764 * command, with the DMA transfer size encoded in the lower
3765 * bits of the command address.
3766 */
3767static void calc_bucket_map(int bucket[], int num_buckets,
3768 int nsgs, int *bucket_map)
3769{
3770 int i, j, b, size;
3771
3772 /* even a command with 0 SGs requires 4 blocks */
3773#define MINIMUM_TRANSFER_BLOCKS 4
3774#define NUM_BUCKETS 8
3775 /* Note, bucket_map must have nsgs+1 entries. */
3776 for (i = 0; i <= nsgs; i++) {
3777 /* Compute size of a command with i SG entries */
3778 size = i + MINIMUM_TRANSFER_BLOCKS;
3779 b = num_buckets; /* Assume the biggest bucket */
3780 /* Find the bucket that is just big enough */
3781 for (j = 0; j < 8; j++) {
3782 if (bucket[j] >= size) {
3783 b = j;
3784 break;
3785 }
3786 }
3787 /* for a command with i SG entries, use bucket b. */
3788 bucket_map[i] = b;
3789 }
3790}
3791
3792static void __devinit cciss_wait_for_mode_change_ack(ctlr_info_t *h)
3793{
3794 int i;
3795
3796 /* under certain very rare conditions, this can take awhile.
3797 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
3798 * as we enter this code.) */
3799 for (i = 0; i < MAX_CONFIG_WAIT; i++) {
3800 if (!(readl(h->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
3801 break;
3802 msleep(10);
3803 }
3804}
3805
3806static __devinit void cciss_enter_performant_mode(ctlr_info_t *h)
3807{
3808 /* This is a bit complicated. There are 8 registers on
3809 * the controller which we write to to tell it 8 different
3810 * sizes of commands which there may be. It's a way of
3811 * reducing the DMA done to fetch each command. Encoded into
3812 * each command's tag are 3 bits which communicate to the controller
3813 * which of the eight sizes that command fits within. The size of
3814 * each command depends on how many scatter gather entries there are.
3815 * Each SG entry requires 16 bytes. The eight registers are programmed
3816 * with the number of 16-byte blocks a command of that size requires.
3817 * The smallest command possible requires 5 such 16 byte blocks.
3818 * the largest command possible requires MAXSGENTRIES + 4 16-byte
3819 * blocks. Note, this only extends to the SG entries contained
3820 * within the command block, and does not extend to chained blocks
3821 * of SG elements. bft[] contains the eight values we write to
3822 * the registers. They are not evenly distributed, but have more
3823 * sizes for small commands, and fewer sizes for larger commands.
3824 */
3825 __u32 trans_offset;
3826 int bft[8] = { 5, 6, 8, 10, 12, 20, 28, MAXSGENTRIES + 4};
3827 /*
3828 * 5 = 1 s/g entry or 4k
3829 * 6 = 2 s/g entry or 8k
3830 * 8 = 4 s/g entry or 16k
3831 * 10 = 6 s/g entry or 24k
3832 */
3833 unsigned long register_value;
3834 BUILD_BUG_ON(28 > MAXSGENTRIES + 4);
3835
3836 h->reply_pool_wraparound = 1; /* spec: init to 1 */
3837
3838 /* Controller spec: zero out this buffer. */
3839 memset(h->reply_pool, 0, h->max_commands * sizeof(__u64));
3840 h->reply_pool_head = h->reply_pool;
3841
3842 trans_offset = readl(&(h->cfgtable->TransMethodOffset));
3843 calc_bucket_map(bft, ARRAY_SIZE(bft), h->maxsgentries,
3844 h->blockFetchTable);
3845 writel(bft[0], &h->transtable->BlockFetch0);
3846 writel(bft[1], &h->transtable->BlockFetch1);
3847 writel(bft[2], &h->transtable->BlockFetch2);
3848 writel(bft[3], &h->transtable->BlockFetch3);
3849 writel(bft[4], &h->transtable->BlockFetch4);
3850 writel(bft[5], &h->transtable->BlockFetch5);
3851 writel(bft[6], &h->transtable->BlockFetch6);
3852 writel(bft[7], &h->transtable->BlockFetch7);
3853
3854 /* size of controller ring buffer */
3855 writel(h->max_commands, &h->transtable->RepQSize);
3856 writel(1, &h->transtable->RepQCount);
3857 writel(0, &h->transtable->RepQCtrAddrLow32);
3858 writel(0, &h->transtable->RepQCtrAddrHigh32);
3859 writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32);
3860 writel(0, &h->transtable->RepQAddr0High32);
3861 writel(CFGTBL_Trans_Performant,
3862 &(h->cfgtable->HostWrite.TransportRequest));
3863
3864 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
3865 cciss_wait_for_mode_change_ack(h);
3866 register_value = readl(&(h->cfgtable->TransportActive));
3867 if (!(register_value & CFGTBL_Trans_Performant))
3868 dev_warn(&h->pdev->dev, "cciss: unable to get board into"
3869 " performant mode\n");
3870}
3871
3872static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
3873{
3874 __u32 trans_support;
3875
3876 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n");
3877 /* Attempt to put controller into performant mode if supported */
3878 /* Does board support performant mode? */
3879 trans_support = readl(&(h->cfgtable->TransportSupport));
3880 if (!(trans_support & PERFORMANT_MODE))
3881 return;
3882
3883 dev_dbg(&h->pdev->dev, "Placing controller into performant mode\n");
3884 /* Performant mode demands commands on a 32 byte boundary
3885 * pci_alloc_consistent aligns on page boundarys already.
3886 * Just need to check if divisible by 32
3887 */
3888 if ((sizeof(CommandList_struct) % 32) != 0) {
3889 dev_warn(&h->pdev->dev, "%s %d %s\n",
3890 "cciss info: command size[",
3891 (int)sizeof(CommandList_struct),
3892 "] not divisible by 32, no performant mode..\n");
3893 return;
3894 }
3895
3896 /* Performant mode ring buffer and supporting data structures */
3897 h->reply_pool = (__u64 *)pci_alloc_consistent(
3898 h->pdev, h->max_commands * sizeof(__u64),
3899 &(h->reply_pool_dhandle));
3900
3901 /* Need a block fetch table for performant mode */
3902 h->blockFetchTable = kmalloc(((h->maxsgentries+1) *
3903 sizeof(__u32)), GFP_KERNEL);
3904
3905 if ((h->reply_pool == NULL) || (h->blockFetchTable == NULL))
3906 goto clean_up;
3907
3908 cciss_enter_performant_mode(h);
3909
3910 /* Change the access methods to the performant access methods */
3911 h->access = SA5_performant_access;
3912 h->transMethod = CFGTBL_Trans_Performant;
3913
3914 return;
3915clean_up:
3916 kfree(h->blockFetchTable);
3917 if (h->reply_pool)
3918 pci_free_consistent(h->pdev,
3919 h->max_commands * sizeof(__u64),
3920 h->reply_pool,
3921 h->reply_pool_dhandle);
3922 return;
3923
3924} /* cciss_put_controller_into_performant_mode */
3925
3633/* If MSI/MSI-X is supported by the kernel we will try to enable it on 3926/* If MSI/MSI-X is supported by the kernel we will try to enable it on
3634 * controllers that are capable. If not, we use IO-APIC mode. 3927 * controllers that are capable. If not, we use IO-APIC mode.
3635 */ 3928 */
3636 3929
3637static void __devinit cciss_interrupt_mode(ctlr_info_t *c, 3930static void __devinit cciss_interrupt_mode(ctlr_info_t *h)
3638 struct pci_dev *pdev, __u32 board_id)
3639{ 3931{
3640#ifdef CONFIG_PCI_MSI 3932#ifdef CONFIG_PCI_MSI
3641 int err; 3933 int err;
@@ -3644,268 +3936,283 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
3644 }; 3936 };
3645 3937
3646 /* Some boards advertise MSI but don't really support it */ 3938 /* Some boards advertise MSI but don't really support it */
3647 if ((board_id == 0x40700E11) || 3939 if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) ||
3648 (board_id == 0x40800E11) || 3940 (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11))
3649 (board_id == 0x40820E11) || (board_id == 0x40830E11))
3650 goto default_int_mode; 3941 goto default_int_mode;
3651 3942
3652 if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) { 3943 if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) {
3653 err = pci_enable_msix(pdev, cciss_msix_entries, 4); 3944 err = pci_enable_msix(h->pdev, cciss_msix_entries, 4);
3654 if (!err) { 3945 if (!err) {
3655 c->intr[0] = cciss_msix_entries[0].vector; 3946 h->intr[0] = cciss_msix_entries[0].vector;
3656 c->intr[1] = cciss_msix_entries[1].vector; 3947 h->intr[1] = cciss_msix_entries[1].vector;
3657 c->intr[2] = cciss_msix_entries[2].vector; 3948 h->intr[2] = cciss_msix_entries[2].vector;
3658 c->intr[3] = cciss_msix_entries[3].vector; 3949 h->intr[3] = cciss_msix_entries[3].vector;
3659 c->msix_vector = 1; 3950 h->msix_vector = 1;
3660 return; 3951 return;
3661 } 3952 }
3662 if (err > 0) { 3953 if (err > 0) {
3663 printk(KERN_WARNING "cciss: only %d MSI-X vectors " 3954 dev_warn(&h->pdev->dev,
3664 "available\n", err); 3955 "only %d MSI-X vectors available\n", err);
3665 goto default_int_mode; 3956 goto default_int_mode;
3666 } else { 3957 } else {
3667 printk(KERN_WARNING "cciss: MSI-X init failed %d\n", 3958 dev_warn(&h->pdev->dev,
3668 err); 3959 "MSI-X init failed %d\n", err);
3669 goto default_int_mode; 3960 goto default_int_mode;
3670 } 3961 }
3671 } 3962 }
3672 if (pci_find_capability(pdev, PCI_CAP_ID_MSI)) { 3963 if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) {
3673 if (!pci_enable_msi(pdev)) { 3964 if (!pci_enable_msi(h->pdev))
3674 c->msi_vector = 1; 3965 h->msi_vector = 1;
3675 } else { 3966 else
3676 printk(KERN_WARNING "cciss: MSI init failed\n"); 3967 dev_warn(&h->pdev->dev, "MSI init failed\n");
3677 }
3678 } 3968 }
3679default_int_mode: 3969default_int_mode:
3680#endif /* CONFIG_PCI_MSI */ 3970#endif /* CONFIG_PCI_MSI */
3681 /* if we get here we're going to use the default interrupt mode */ 3971 /* if we get here we're going to use the default interrupt mode */
3682 c->intr[SIMPLE_MODE_INT] = pdev->irq; 3972 h->intr[PERF_MODE_INT] = h->pdev->irq;
3683 return; 3973 return;
3684} 3974}
3685 3975
3686static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev) 3976static int __devinit cciss_lookup_board_id(struct pci_dev *pdev, u32 *board_id)
3687{ 3977{
3688 ushort subsystem_vendor_id, subsystem_device_id, command; 3978 int i;
3689 __u32 board_id, scratchpad = 0; 3979 u32 subsystem_vendor_id, subsystem_device_id;
3690 __u64 cfg_offset;
3691 __u32 cfg_base_addr;
3692 __u64 cfg_base_addr_index;
3693 int i, prod_index, err;
3694 3980
3695 subsystem_vendor_id = pdev->subsystem_vendor; 3981 subsystem_vendor_id = pdev->subsystem_vendor;
3696 subsystem_device_id = pdev->subsystem_device; 3982 subsystem_device_id = pdev->subsystem_device;
3697 board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) | 3983 *board_id = ((subsystem_device_id << 16) & 0xffff0000) |
3698 subsystem_vendor_id); 3984 subsystem_vendor_id;
3699 3985
3700 for (i = 0; i < ARRAY_SIZE(products); i++) { 3986 for (i = 0; i < ARRAY_SIZE(products); i++) {
3701 /* Stand aside for hpsa driver on request */ 3987 /* Stand aside for hpsa driver on request */
3702 if (cciss_allow_hpsa && products[i].board_id == HPSA_BOUNDARY) 3988 if (cciss_allow_hpsa && products[i].board_id == HPSA_BOUNDARY)
3703 return -ENODEV; 3989 return -ENODEV;
3704 if (board_id == products[i].board_id) 3990 if (*board_id == products[i].board_id)
3705 break; 3991 return i;
3706 }
3707 prod_index = i;
3708 if (prod_index == ARRAY_SIZE(products)) {
3709 dev_warn(&pdev->dev,
3710 "unrecognized board ID: 0x%08lx, ignoring.\n",
3711 (unsigned long) board_id);
3712 return -ENODEV;
3713 } 3992 }
3993 dev_warn(&pdev->dev, "unrecognized board ID: 0x%08x, ignoring.\n",
3994 *board_id);
3995 return -ENODEV;
3996}
3714 3997
3715 /* check to see if controller has been disabled */ 3998static inline bool cciss_board_disabled(ctlr_info_t *h)
3716 /* BEFORE trying to enable it */ 3999{
3717 (void)pci_read_config_word(pdev, PCI_COMMAND, &command); 4000 u16 command;
3718 if (!(command & 0x02)) {
3719 printk(KERN_WARNING
3720 "cciss: controller appears to be disabled\n");
3721 return -ENODEV;
3722 }
3723 4001
3724 err = pci_enable_device(pdev); 4002 (void) pci_read_config_word(h->pdev, PCI_COMMAND, &command);
3725 if (err) { 4003 return ((command & PCI_COMMAND_MEMORY) == 0);
3726 printk(KERN_ERR "cciss: Unable to Enable PCI device\n"); 4004}
3727 return err;
3728 }
3729 4005
3730 err = pci_request_regions(pdev, "cciss"); 4006static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
3731 if (err) { 4007 unsigned long *memory_bar)
3732 printk(KERN_ERR "cciss: Cannot obtain PCI resources, " 4008{
3733 "aborting\n"); 4009 int i;
3734 return err;
3735 }
3736 4010
3737#ifdef CCISS_DEBUG 4011 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
3738 printk("command = %x\n", command); 4012 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3739 printk("irq = %x\n", pdev->irq); 4013 /* addressing mode bits already removed */
3740 printk("board_id = %x\n", board_id); 4014 *memory_bar = pci_resource_start(pdev, i);
3741#endif /* CCISS_DEBUG */ 4015 dev_dbg(&pdev->dev, "memory BAR = %lx\n",
4016 *memory_bar);
4017 return 0;
4018 }
4019 dev_warn(&pdev->dev, "no memory BAR found\n");
4020 return -ENODEV;
4021}
3742 4022
3743/* If the kernel supports MSI/MSI-X we will try to enable that functionality, 4023static int __devinit cciss_wait_for_board_ready(ctlr_info_t *h)
3744 * else we use the IO-APIC interrupt assigned to us by system ROM. 4024{
3745 */ 4025 int i;
3746 cciss_interrupt_mode(c, pdev, board_id); 4026 u32 scratchpad;
3747 4027
3748 /* find the memory BAR */ 4028 for (i = 0; i < CCISS_BOARD_READY_ITERATIONS; i++) {
3749 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 4029 scratchpad = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
3750 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) 4030 if (scratchpad == CCISS_FIRMWARE_READY)
3751 break; 4031 return 0;
3752 } 4032 msleep(CCISS_BOARD_READY_POLL_INTERVAL_MSECS);
3753 if (i == DEVICE_COUNT_RESOURCE) {
3754 printk(KERN_WARNING "cciss: No memory BAR found\n");
3755 err = -ENODEV;
3756 goto err_out_free_res;
3757 } 4033 }
4034 dev_warn(&h->pdev->dev, "board not ready, timed out.\n");
4035 return -ENODEV;
4036}
3758 4037
3759 c->paddr = pci_resource_start(pdev, i); /* addressing mode bits 4038static int __devinit cciss_find_cfg_addrs(struct pci_dev *pdev,
3760 * already removed 4039 void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index,
3761 */ 4040 u64 *cfg_offset)
4041{
4042 *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET);
4043 *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET);
4044 *cfg_base_addr &= (u32) 0x0000ffff;
4045 *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr);
4046 if (*cfg_base_addr_index == -1) {
4047 dev_warn(&pdev->dev, "cannot find cfg_base_addr_index, "
4048 "*cfg_base_addr = 0x%08x\n", *cfg_base_addr);
4049 return -ENODEV;
4050 }
4051 return 0;
4052}
3762 4053
3763#ifdef CCISS_DEBUG 4054static int __devinit cciss_find_cfgtables(ctlr_info_t *h)
3764 printk("address 0 = %lx\n", c->paddr); 4055{
3765#endif /* CCISS_DEBUG */ 4056 u64 cfg_offset;
3766 c->vaddr = remap_pci_mem(c->paddr, 0x250); 4057 u32 cfg_base_addr;
4058 u64 cfg_base_addr_index;
4059 u32 trans_offset;
4060 int rc;
3767 4061
3768 /* Wait for the board to become ready. (PCI hotplug needs this.) 4062 rc = cciss_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr,
3769 * We poll for up to 120 secs, once per 100ms. */ 4063 &cfg_base_addr_index, &cfg_offset);
3770 for (i = 0; i < 1200; i++) { 4064 if (rc)
3771 scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET); 4065 return rc;
3772 if (scratchpad == CCISS_FIRMWARE_READY) 4066 h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev,
3773 break; 4067 cfg_base_addr_index) + cfg_offset, sizeof(h->cfgtable));
3774 set_current_state(TASK_INTERRUPTIBLE); 4068 if (!h->cfgtable)
3775 schedule_timeout(msecs_to_jiffies(100)); /* wait 100ms */ 4069 return -ENOMEM;
3776 } 4070 /* Find performant mode table. */
3777 if (scratchpad != CCISS_FIRMWARE_READY) { 4071 trans_offset = readl(&h->cfgtable->TransMethodOffset);
3778 printk(KERN_WARNING "cciss: Board not ready. Timed out.\n"); 4072 h->transtable = remap_pci_mem(pci_resource_start(h->pdev,
3779 err = -ENODEV; 4073 cfg_base_addr_index)+cfg_offset+trans_offset,
3780 goto err_out_free_res; 4074 sizeof(*h->transtable));
3781 } 4075 if (!h->transtable)
4076 return -ENOMEM;
4077 return 0;
4078}
3782 4079
3783 /* get the address index number */ 4080static void __devinit cciss_get_max_perf_mode_cmds(struct ctlr_info *h)
3784 cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET); 4081{
3785 cfg_base_addr &= (__u32) 0x0000ffff; 4082 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
3786#ifdef CCISS_DEBUG 4083 if (h->max_commands < 16) {
3787 printk("cfg base address = %x\n", cfg_base_addr); 4084 dev_warn(&h->pdev->dev, "Controller reports "
3788#endif /* CCISS_DEBUG */ 4085 "max supported commands of %d, an obvious lie. "
3789 cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr); 4086 "Using 16. Ensure that firmware is up to date.\n",
3790#ifdef CCISS_DEBUG 4087 h->max_commands);
3791 printk("cfg base address index = %llx\n", 4088 h->max_commands = 16;
3792 (unsigned long long)cfg_base_addr_index);
3793#endif /* CCISS_DEBUG */
3794 if (cfg_base_addr_index == -1) {
3795 printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
3796 err = -ENODEV;
3797 goto err_out_free_res;
3798 } 4089 }
4090}
3799 4091
3800 cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET); 4092/* Interrogate the hardware for some limits:
3801#ifdef CCISS_DEBUG 4093 * max commands, max SG elements without chaining, and with chaining,
3802 printk("cfg offset = %llx\n", (unsigned long long)cfg_offset); 4094 * SG chain block size, etc.
3803#endif /* CCISS_DEBUG */ 4095 */
3804 c->cfgtable = remap_pci_mem(pci_resource_start(pdev, 4096static void __devinit cciss_find_board_params(ctlr_info_t *h)
3805 cfg_base_addr_index) + 4097{
3806 cfg_offset, sizeof(CfgTable_struct)); 4098 cciss_get_max_perf_mode_cmds(h);
3807 c->board_id = board_id; 4099 h->nr_cmds = h->max_commands - 4; /* Allow room for some ioctls */
3808 4100 h->maxsgentries = readl(&(h->cfgtable->MaxSGElements));
3809#ifdef CCISS_DEBUG
3810 print_cfg_table(c->cfgtable);
3811#endif /* CCISS_DEBUG */
3812
3813 /* Some controllers support Zero Memory Raid (ZMR).
3814 * When configured in ZMR mode the number of supported
3815 * commands drops to 64. So instead of just setting an
3816 * arbitrary value we make the driver a little smarter.
3817 * We read the config table to tell us how many commands
3818 * are supported on the controller then subtract 4 to
3819 * leave a little room for ioctl calls.
3820 */
3821 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
3822 c->maxsgentries = readl(&(c->cfgtable->MaxSGElements));
3823
3824 /* 4101 /*
3825 * Limit native command to 32 s/g elements to save dma'able memory. 4102 * Limit in-command s/g elements to 32 save dma'able memory.
3826 * Howvever spec says if 0, use 31 4103 * Howvever spec says if 0, use 31
3827 */ 4104 */
3828 4105 h->max_cmd_sgentries = 31;
3829 c->max_cmd_sgentries = 31; 4106 if (h->maxsgentries > 512) {
3830 if (c->maxsgentries > 512) { 4107 h->max_cmd_sgentries = 32;
3831 c->max_cmd_sgentries = 32; 4108 h->chainsize = h->maxsgentries - h->max_cmd_sgentries + 1;
3832 c->chainsize = c->maxsgentries - c->max_cmd_sgentries + 1; 4109 h->maxsgentries--; /* save one for chain pointer */
3833 c->maxsgentries -= 1; /* account for chain pointer */
3834 } else { 4110 } else {
3835 c->maxsgentries = 31; /* Default to traditional value */ 4111 h->maxsgentries = 31; /* default to traditional values */
3836 c->chainsize = 0; /* traditional */ 4112 h->chainsize = 0;
3837 } 4113 }
4114}
3838 4115
3839 c->product_name = products[prod_index].product_name; 4116static inline bool CISS_signature_present(ctlr_info_t *h)
3840 c->access = *(products[prod_index].access); 4117{
3841 c->nr_cmds = c->max_commands - 4; 4118 if ((readb(&h->cfgtable->Signature[0]) != 'C') ||
3842 if ((readb(&c->cfgtable->Signature[0]) != 'C') || 4119 (readb(&h->cfgtable->Signature[1]) != 'I') ||
3843 (readb(&c->cfgtable->Signature[1]) != 'I') || 4120 (readb(&h->cfgtable->Signature[2]) != 'S') ||
3844 (readb(&c->cfgtable->Signature[2]) != 'S') || 4121 (readb(&h->cfgtable->Signature[3]) != 'S')) {
3845 (readb(&c->cfgtable->Signature[3]) != 'S')) { 4122 dev_warn(&h->pdev->dev, "not a valid CISS config table\n");
3846 printk("Does not appear to be a valid CISS config table\n"); 4123 return false;
3847 err = -ENODEV;
3848 goto err_out_free_res;
3849 } 4124 }
4125 return true;
4126}
4127
4128/* Need to enable prefetch in the SCSI core for 6400 in x86 */
4129static inline void cciss_enable_scsi_prefetch(ctlr_info_t *h)
4130{
3850#ifdef CONFIG_X86 4131#ifdef CONFIG_X86
3851 { 4132 u32 prefetch;
3852 /* Need to enable prefetch in the SCSI core for 6400 in x86 */ 4133
3853 __u32 prefetch; 4134 prefetch = readl(&(h->cfgtable->SCSI_Prefetch));
3854 prefetch = readl(&(c->cfgtable->SCSI_Prefetch)); 4135 prefetch |= 0x100;
3855 prefetch |= 0x100; 4136 writel(prefetch, &(h->cfgtable->SCSI_Prefetch));
3856 writel(prefetch, &(c->cfgtable->SCSI_Prefetch));
3857 }
3858#endif 4137#endif
4138}
3859 4139
3860 /* Disabling DMA prefetch and refetch for the P600. 4140/* Disable DMA prefetch for the P600. Otherwise an ASIC bug may result
3861 * An ASIC bug may result in accesses to invalid memory addresses. 4141 * in a prefetch beyond physical memory.
3862 * We've disabled prefetch for some time now. Testing with XEN 4142 */
3863 * kernels revealed a bug in the refetch if dom0 resides on a P600. 4143static inline void cciss_p600_dma_prefetch_quirk(ctlr_info_t *h)
3864 */ 4144{
3865 if(board_id == 0x3225103C) { 4145 u32 dma_prefetch;
3866 __u32 dma_prefetch; 4146 __u32 dma_refetch;
3867 __u32 dma_refetch; 4147
3868 dma_prefetch = readl(c->vaddr + I2O_DMA1_CFG); 4148 if (h->board_id != 0x3225103C)
3869 dma_prefetch |= 0x8000; 4149 return;
3870 writel(dma_prefetch, c->vaddr + I2O_DMA1_CFG); 4150 dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG);
3871 pci_read_config_dword(pdev, PCI_COMMAND_PARITY, &dma_refetch); 4151 dma_prefetch |= 0x8000;
3872 dma_refetch |= 0x1; 4152 writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG);
3873 pci_write_config_dword(pdev, PCI_COMMAND_PARITY, dma_refetch); 4153 pci_read_config_dword(h->pdev, PCI_COMMAND_PARITY, &dma_refetch);
4154 dma_refetch |= 0x1;
4155 pci_write_config_dword(h->pdev, PCI_COMMAND_PARITY, dma_refetch);
4156}
4157
4158static int __devinit cciss_pci_init(ctlr_info_t *h)
4159{
4160 int prod_index, err;
4161
4162 prod_index = cciss_lookup_board_id(h->pdev, &h->board_id);
4163 if (prod_index < 0)
4164 return -ENODEV;
4165 h->product_name = products[prod_index].product_name;
4166 h->access = *(products[prod_index].access);
4167
4168 if (cciss_board_disabled(h)) {
4169 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
4170 return -ENODEV;
4171 }
4172 err = pci_enable_device(h->pdev);
4173 if (err) {
4174 dev_warn(&h->pdev->dev, "Unable to Enable PCI device\n");
4175 return err;
3874 } 4176 }
3875 4177
3876#ifdef CCISS_DEBUG 4178 err = pci_request_regions(h->pdev, "cciss");
3877 printk("Trying to put board into Simple mode\n"); 4179 if (err) {
3878#endif /* CCISS_DEBUG */ 4180 dev_warn(&h->pdev->dev,
3879 c->max_commands = readl(&(c->cfgtable->CmdsOutMax)); 4181 "Cannot obtain PCI resources, aborting\n");
3880 /* Update the field, and then ring the doorbell */ 4182 return err;
3881 writel(CFGTBL_Trans_Simple, &(c->cfgtable->HostWrite.TransportRequest)); 4183 }
3882 writel(CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
3883 4184
3884 /* under certain very rare conditions, this can take awhile. 4185 dev_dbg(&h->pdev->dev, "irq = %x\n", h->pdev->irq);
3885 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right 4186 dev_dbg(&h->pdev->dev, "board_id = %x\n", h->board_id);
3886 * as we enter this code.) */ 4187
3887 for (i = 0; i < MAX_CONFIG_WAIT; i++) { 4188/* If the kernel supports MSI/MSI-X we will try to enable that functionality,
3888 if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq)) 4189 * else we use the IO-APIC interrupt assigned to us by system ROM.
3889 break; 4190 */
3890 /* delay and try again */ 4191 cciss_interrupt_mode(h);
3891 set_current_state(TASK_INTERRUPTIBLE); 4192 err = cciss_pci_find_memory_BAR(h->pdev, &h->paddr);
3892 schedule_timeout(msecs_to_jiffies(1)); 4193 if (err)
4194 goto err_out_free_res;
4195 h->vaddr = remap_pci_mem(h->paddr, 0x250);
4196 if (!h->vaddr) {
4197 err = -ENOMEM;
4198 goto err_out_free_res;
3893 } 4199 }
4200 err = cciss_wait_for_board_ready(h);
4201 if (err)
4202 goto err_out_free_res;
4203 err = cciss_find_cfgtables(h);
4204 if (err)
4205 goto err_out_free_res;
4206 print_cfg_table(h);
4207 cciss_find_board_params(h);
3894 4208
3895#ifdef CCISS_DEBUG 4209 if (!CISS_signature_present(h)) {
3896 printk(KERN_DEBUG "I counter got to %d %x\n", i,
3897 readl(c->vaddr + SA5_DOORBELL));
3898#endif /* CCISS_DEBUG */
3899#ifdef CCISS_DEBUG
3900 print_cfg_table(c->cfgtable);
3901#endif /* CCISS_DEBUG */
3902
3903 if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
3904 printk(KERN_WARNING "cciss: unable to get board into"
3905 " simple mode\n");
3906 err = -ENODEV; 4210 err = -ENODEV;
3907 goto err_out_free_res; 4211 goto err_out_free_res;
3908 } 4212 }
4213 cciss_enable_scsi_prefetch(h);
4214 cciss_p600_dma_prefetch_quirk(h);
4215 cciss_put_controller_into_performant_mode(h);
3909 return 0; 4216 return 0;
3910 4217
3911err_out_free_res: 4218err_out_free_res:
@@ -3913,42 +4220,47 @@ err_out_free_res:
3913 * Deliberately omit pci_disable_device(): it does something nasty to 4220 * Deliberately omit pci_disable_device(): it does something nasty to
3914 * Smart Array controllers that pci_enable_device does not undo 4221 * Smart Array controllers that pci_enable_device does not undo
3915 */ 4222 */
3916 pci_release_regions(pdev); 4223 if (h->transtable)
4224 iounmap(h->transtable);
4225 if (h->cfgtable)
4226 iounmap(h->cfgtable);
4227 if (h->vaddr)
4228 iounmap(h->vaddr);
4229 pci_release_regions(h->pdev);
3917 return err; 4230 return err;
3918} 4231}
3919 4232
3920/* Function to find the first free pointer into our hba[] array 4233/* Function to find the first free pointer into our hba[] array
3921 * Returns -1 if no free entries are left. 4234 * Returns -1 if no free entries are left.
3922 */ 4235 */
3923static int alloc_cciss_hba(void) 4236static int alloc_cciss_hba(struct pci_dev *pdev)
3924{ 4237{
3925 int i; 4238 int i;
3926 4239
3927 for (i = 0; i < MAX_CTLR; i++) { 4240 for (i = 0; i < MAX_CTLR; i++) {
3928 if (!hba[i]) { 4241 if (!hba[i]) {
3929 ctlr_info_t *p; 4242 ctlr_info_t *h;
3930 4243
3931 p = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL); 4244 h = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL);
3932 if (!p) 4245 if (!h)
3933 goto Enomem; 4246 goto Enomem;
3934 hba[i] = p; 4247 hba[i] = h;
3935 return i; 4248 return i;
3936 } 4249 }
3937 } 4250 }
3938 printk(KERN_WARNING "cciss: This driver supports a maximum" 4251 dev_warn(&pdev->dev, "This driver supports a maximum"
3939 " of %d controllers.\n", MAX_CTLR); 4252 " of %d controllers.\n", MAX_CTLR);
3940 return -1; 4253 return -1;
3941Enomem: 4254Enomem:
3942 printk(KERN_ERR "cciss: out of memory.\n"); 4255 dev_warn(&pdev->dev, "out of memory.\n");
3943 return -1; 4256 return -1;
3944} 4257}
3945 4258
3946static void free_hba(int n) 4259static void free_hba(ctlr_info_t *h)
3947{ 4260{
3948 ctlr_info_t *h = hba[n];
3949 int i; 4261 int i;
3950 4262
3951 hba[n] = NULL; 4263 hba[h->ctlr] = NULL;
3952 for (i = 0; i < h->highest_lun + 1; i++) 4264 for (i = 0; i < h->highest_lun + 1; i++)
3953 if (h->gendisk[i] != NULL) 4265 if (h->gendisk[i] != NULL)
3954 put_disk(h->gendisk[i]); 4266 put_disk(h->gendisk[i]);
@@ -4028,7 +4340,8 @@ static __devinit int cciss_message(struct pci_dev *pdev, unsigned char opcode, u
4028 /* we leak the DMA buffer here ... no choice since the controller could 4340 /* we leak the DMA buffer here ... no choice since the controller could
4029 still complete the command. */ 4341 still complete the command. */
4030 if (i == 10) { 4342 if (i == 10) {
4031 printk(KERN_ERR "cciss: controller message %02x:%02x timed out\n", 4343 dev_err(&pdev->dev,
4344 "controller message %02x:%02x timed out\n",
4032 opcode, type); 4345 opcode, type);
4033 return -ETIMEDOUT; 4346 return -ETIMEDOUT;
4034 } 4347 }
@@ -4036,12 +4349,12 @@ static __devinit int cciss_message(struct pci_dev *pdev, unsigned char opcode, u
4036 pci_free_consistent(pdev, cmd_sz, cmd, paddr64); 4349 pci_free_consistent(pdev, cmd_sz, cmd, paddr64);
4037 4350
4038 if (tag & 2) { 4351 if (tag & 2) {
4039 printk(KERN_ERR "cciss: controller message %02x:%02x failed\n", 4352 dev_err(&pdev->dev, "controller message %02x:%02x failed\n",
4040 opcode, type); 4353 opcode, type);
4041 return -EIO; 4354 return -EIO;
4042 } 4355 }
4043 4356
4044 printk(KERN_INFO "cciss: controller message %02x:%02x succeeded\n", 4357 dev_info(&pdev->dev, "controller message %02x:%02x succeeded\n",
4045 opcode, type); 4358 opcode, type);
4046 return 0; 4359 return 0;
4047} 4360}
@@ -4062,7 +4375,7 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4062 if (pos) { 4375 if (pos) {
4063 pci_read_config_word(pdev, msi_control_reg(pos), &control); 4376 pci_read_config_word(pdev, msi_control_reg(pos), &control);
4064 if (control & PCI_MSI_FLAGS_ENABLE) { 4377 if (control & PCI_MSI_FLAGS_ENABLE) {
4065 printk(KERN_INFO "cciss: resetting MSI\n"); 4378 dev_info(&pdev->dev, "resetting MSI\n");
4066 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSI_FLAGS_ENABLE); 4379 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSI_FLAGS_ENABLE);
4067 } 4380 }
4068 } 4381 }
@@ -4071,7 +4384,7 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4071 if (pos) { 4384 if (pos) {
4072 pci_read_config_word(pdev, msi_control_reg(pos), &control); 4385 pci_read_config_word(pdev, msi_control_reg(pos), &control);
4073 if (control & PCI_MSIX_FLAGS_ENABLE) { 4386 if (control & PCI_MSIX_FLAGS_ENABLE) {
4074 printk(KERN_INFO "cciss: resetting MSI-X\n"); 4387 dev_info(&pdev->dev, "resetting MSI-X\n");
4075 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSIX_FLAGS_ENABLE); 4388 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSIX_FLAGS_ENABLE);
4076 } 4389 }
4077 } 4390 }
@@ -4079,68 +4392,144 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4079 return 0; 4392 return 0;
4080} 4393}
4081 4394
4082/* This does a hard reset of the controller using PCI power management 4395static int cciss_controller_hard_reset(struct pci_dev *pdev,
4083 * states. */ 4396 void * __iomem vaddr, bool use_doorbell)
4084static __devinit int cciss_hard_reset_controller(struct pci_dev *pdev)
4085{ 4397{
4086 u16 pmcsr, saved_config_space[32]; 4398 u16 pmcsr;
4087 int i, pos; 4399 int pos;
4088 4400
4089 printk(KERN_INFO "cciss: using PCI PM to reset controller\n"); 4401 if (use_doorbell) {
4402 /* For everything after the P600, the PCI power state method
4403 * of resetting the controller doesn't work, so we have this
4404 * other way using the doorbell register.
4405 */
4406 dev_info(&pdev->dev, "using doorbell to reset controller\n");
4407 writel(DOORBELL_CTLR_RESET, vaddr + SA5_DOORBELL);
4408 msleep(1000);
4409 } else { /* Try to do it the PCI power state way */
4410
4411 /* Quoting from the Open CISS Specification: "The Power
4412 * Management Control/Status Register (CSR) controls the power
4413 * state of the device. The normal operating state is D0,
4414 * CSR=00h. The software off state is D3, CSR=03h. To reset
4415 * the controller, place the interface device in D3 then to D0,
4416 * this causes a secondary PCI reset which will reset the
4417 * controller." */
4418
4419 pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
4420 if (pos == 0) {
4421 dev_err(&pdev->dev,
4422 "cciss_controller_hard_reset: "
4423 "PCI PM not supported\n");
4424 return -ENODEV;
4425 }
4426 dev_info(&pdev->dev, "using PCI PM to reset controller\n");
4427 /* enter the D3hot power management state */
4428 pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr);
4429 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4430 pmcsr |= PCI_D3hot;
4431 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4090 4432
4091 /* This is very nearly the same thing as 4433 msleep(500);
4092 4434
4093 pci_save_state(pci_dev); 4435 /* enter the D0 power management state */
4094 pci_set_power_state(pci_dev, PCI_D3hot); 4436 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4095 pci_set_power_state(pci_dev, PCI_D0); 4437 pmcsr |= PCI_D0;
4096 pci_restore_state(pci_dev); 4438 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4097 4439
4098 but we can't use these nice canned kernel routines on 4440 msleep(500);
4099 kexec, because they also check the MSI/MSI-X state in PCI 4441 }
4100 configuration space and do the wrong thing when it is 4442 return 0;
4101 set/cleared. Also, the pci_save/restore_state functions 4443}
4102 violate the ordering requirements for restoring the
4103 configuration space from the CCISS document (see the
4104 comment below). So we roll our own .... */
4105 4444
4106 for (i = 0; i < 32; i++) 4445/* This does a hard reset of the controller using PCI power management
4107 pci_read_config_word(pdev, 2*i, &saved_config_space[i]); 4446 * states or using the doorbell register. */
4447static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4448{
4449 u16 saved_config_space[32];
4450 u64 cfg_offset;
4451 u32 cfg_base_addr;
4452 u64 cfg_base_addr_index;
4453 void __iomem *vaddr;
4454 unsigned long paddr;
4455 u32 misc_fw_support, active_transport;
4456 int rc, i;
4457 CfgTable_struct __iomem *cfgtable;
4458 bool use_doorbell;
4459 u32 board_id;
4460
4461 /* For controllers as old a the p600, this is very nearly
4462 * the same thing as
4463 *
4464 * pci_save_state(pci_dev);
4465 * pci_set_power_state(pci_dev, PCI_D3hot);
4466 * pci_set_power_state(pci_dev, PCI_D0);
4467 * pci_restore_state(pci_dev);
4468 *
4469 * but we can't use these nice canned kernel routines on
4470 * kexec, because they also check the MSI/MSI-X state in PCI
4471 * configuration space and do the wrong thing when it is
4472 * set/cleared. Also, the pci_save/restore_state functions
4473 * violate the ordering requirements for restoring the
4474 * configuration space from the CCISS document (see the
4475 * comment below). So we roll our own ....
4476 *
4477 * For controllers newer than the P600, the pci power state
4478 * method of resetting doesn't work so we have another way
4479 * using the doorbell register.
4480 */
4108 4481
4109 pos = pci_find_capability(pdev, PCI_CAP_ID_PM); 4482 /* Exclude 640x boards. These are two pci devices in one slot
4110 if (pos == 0) { 4483 * which share a battery backed cache module. One controls the
4111 printk(KERN_ERR "cciss_reset_controller: PCI PM not supported\n"); 4484 * cache, the other accesses the cache through the one that controls
4485 * it. If we reset the one controlling the cache, the other will
4486 * likely not be happy. Just forbid resetting this conjoined mess.
4487 */
4488 cciss_lookup_board_id(pdev, &board_id);
4489 if (board_id == 0x409C0E11 || board_id == 0x409D0E11) {
4490 dev_warn(&pdev->dev, "Cannot reset Smart Array 640x "
4491 "due to shared cache module.");
4112 return -ENODEV; 4492 return -ENODEV;
4113 } 4493 }
4114 4494
4115 /* Quoting from the Open CISS Specification: "The Power 4495 for (i = 0; i < 32; i++)
4116 * Management Control/Status Register (CSR) controls the power 4496 pci_read_config_word(pdev, 2*i, &saved_config_space[i]);
4117 * state of the device. The normal operating state is D0,
4118 * CSR=00h. The software off state is D3, CSR=03h. To reset
4119 * the controller, place the interface device in D3 then to
4120 * D0, this causes a secondary PCI reset which will reset the
4121 * controller." */
4122 4497
4123 /* enter the D3hot power management state */ 4498 /* find the first memory BAR, so we can find the cfg table */
4124 pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr); 4499 rc = cciss_pci_find_memory_BAR(pdev, &paddr);
4125 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 4500 if (rc)
4126 pmcsr |= PCI_D3hot; 4501 return rc;
4127 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); 4502 vaddr = remap_pci_mem(paddr, 0x250);
4503 if (!vaddr)
4504 return -ENOMEM;
4128 4505
4129 schedule_timeout_uninterruptible(HZ >> 1); 4506 /* find cfgtable in order to check if reset via doorbell is supported */
4507 rc = cciss_find_cfg_addrs(pdev, vaddr, &cfg_base_addr,
4508 &cfg_base_addr_index, &cfg_offset);
4509 if (rc)
4510 goto unmap_vaddr;
4511 cfgtable = remap_pci_mem(pci_resource_start(pdev,
4512 cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable));
4513 if (!cfgtable) {
4514 rc = -ENOMEM;
4515 goto unmap_vaddr;
4516 }
4130 4517
4131 /* enter the D0 power management state */ 4518 /* If reset via doorbell register is supported, use that. */
4132 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 4519 misc_fw_support = readl(&cfgtable->misc_fw_support);
4133 pmcsr |= PCI_D0; 4520 use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
4134 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4135 4521
4136 schedule_timeout_uninterruptible(HZ >> 1); 4522 rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell);
4523 if (rc)
4524 goto unmap_cfgtable;
4137 4525
4138 /* Restore the PCI configuration space. The Open CISS 4526 /* Restore the PCI configuration space. The Open CISS
4139 * Specification says, "Restore the PCI Configuration 4527 * Specification says, "Restore the PCI Configuration
4140 * Registers, offsets 00h through 60h. It is important to 4528 * Registers, offsets 00h through 60h. It is important to
4141 * restore the command register, 16-bits at offset 04h, 4529 * restore the command register, 16-bits at offset 04h,
4142 * last. Do not restore the configuration status register, 4530 * last. Do not restore the configuration status register,
4143 * 16-bits at offset 06h." Note that the offset is 2*i. */ 4531 * 16-bits at offset 06h." Note that the offset is 2*i.
4532 */
4144 for (i = 0; i < 32; i++) { 4533 for (i = 0; i < 32; i++) {
4145 if (i == 2 || i == 3) 4534 if (i == 2 || i == 3)
4146 continue; 4535 continue;
@@ -4149,6 +4538,63 @@ static __devinit int cciss_hard_reset_controller(struct pci_dev *pdev)
4149 wmb(); 4538 wmb();
4150 pci_write_config_word(pdev, 4, saved_config_space[2]); 4539 pci_write_config_word(pdev, 4, saved_config_space[2]);
4151 4540
4541 /* Some devices (notably the HP Smart Array 5i Controller)
4542 need a little pause here */
4543 msleep(CCISS_POST_RESET_PAUSE_MSECS);
4544
4545 /* Controller should be in simple mode at this point. If it's not,
4546 * It means we're on one of those controllers which doesn't support
4547 * the doorbell reset method and on which the PCI power management reset
4548 * method doesn't work (P800, for example.)
4549 * In those cases, don't try to proceed, as it generally doesn't work.
4550 */
4551 active_transport = readl(&cfgtable->TransportActive);
4552 if (active_transport & PERFORMANT_MODE) {
4553 dev_warn(&pdev->dev, "Unable to successfully reset controller,"
4554 " Ignoring controller.\n");
4555 rc = -ENODEV;
4556 }
4557
4558unmap_cfgtable:
4559 iounmap(cfgtable);
4560
4561unmap_vaddr:
4562 iounmap(vaddr);
4563 return rc;
4564}
4565
4566static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
4567{
4568 int rc, i;
4569
4570 if (!reset_devices)
4571 return 0;
4572
4573 /* Reset the controller with a PCI power-cycle or via doorbell */
4574 rc = cciss_kdump_hard_reset_controller(pdev);
4575
4576 /* -ENOTSUPP here means we cannot reset the controller
4577 * but it's already (and still) up and running in
4578 * "performant mode". Or, it might be 640x, which can't reset
4579 * due to concerns about shared bbwc between 6402/6404 pair.
4580 */
4581 if (rc == -ENOTSUPP)
4582 return 0; /* just try to do the kdump anyhow. */
4583 if (rc)
4584 return -ENODEV;
4585 if (cciss_reset_msi(pdev))
4586 return -ENODEV;
4587
4588 /* Now try to get the controller to respond to a no-op */
4589 for (i = 0; i < CCISS_POST_RESET_NOOP_RETRIES; i++) {
4590 if (cciss_noop(pdev) == 0)
4591 break;
4592 else
4593 dev_warn(&pdev->dev, "no-op failed%s\n",
4594 (i < CCISS_POST_RESET_NOOP_RETRIES - 1 ?
4595 "; re-trying" : ""));
4596 msleep(CCISS_POST_RESET_NOOP_INTERVAL_MSECS);
4597 }
4152 return 0; 4598 return 0;
4153} 4599}
4154 4600
@@ -4166,46 +4612,31 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4166 int rc; 4612 int rc;
4167 int dac, return_code; 4613 int dac, return_code;
4168 InquiryData_struct *inq_buff; 4614 InquiryData_struct *inq_buff;
4615 ctlr_info_t *h;
4169 4616
4170 if (reset_devices) { 4617 rc = cciss_init_reset_devices(pdev);
4171 /* Reset the controller with a PCI power-cycle */ 4618 if (rc)
4172 if (cciss_hard_reset_controller(pdev) || cciss_reset_msi(pdev)) 4619 return rc;
4173 return -ENODEV; 4620 i = alloc_cciss_hba(pdev);
4174
4175 /* Now try to get the controller to respond to a no-op. Some
4176 devices (notably the HP Smart Array 5i Controller) need
4177 up to 30 seconds to respond. */
4178 for (i=0; i<30; i++) {
4179 if (cciss_noop(pdev) == 0)
4180 break;
4181
4182 schedule_timeout_uninterruptible(HZ);
4183 }
4184 if (i == 30) {
4185 printk(KERN_ERR "cciss: controller seems dead\n");
4186 return -EBUSY;
4187 }
4188 }
4189
4190 i = alloc_cciss_hba();
4191 if (i < 0) 4621 if (i < 0)
4192 return -1; 4622 return -1;
4193 4623
4194 hba[i]->busy_initializing = 1; 4624 h = hba[i];
4195 INIT_HLIST_HEAD(&hba[i]->cmpQ); 4625 h->pdev = pdev;
4196 INIT_HLIST_HEAD(&hba[i]->reqQ); 4626 h->busy_initializing = 1;
4197 mutex_init(&hba[i]->busy_shutting_down); 4627 INIT_HLIST_HEAD(&h->cmpQ);
4628 INIT_HLIST_HEAD(&h->reqQ);
4629 mutex_init(&h->busy_shutting_down);
4198 4630
4199 if (cciss_pci_init(hba[i], pdev) != 0) 4631 if (cciss_pci_init(h) != 0)
4200 goto clean_no_release_regions; 4632 goto clean_no_release_regions;
4201 4633
4202 sprintf(hba[i]->devname, "cciss%d", i); 4634 sprintf(h->devname, "cciss%d", i);
4203 hba[i]->ctlr = i; 4635 h->ctlr = i;
4204 hba[i]->pdev = pdev;
4205 4636
4206 init_completion(&hba[i]->scan_wait); 4637 init_completion(&h->scan_wait);
4207 4638
4208 if (cciss_create_hba_sysfs_entry(hba[i])) 4639 if (cciss_create_hba_sysfs_entry(h))
4209 goto clean0; 4640 goto clean0;
4210 4641
4211 /* configure PCI DMA stuff */ 4642 /* configure PCI DMA stuff */
@@ -4214,7 +4645,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4214 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) 4645 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))
4215 dac = 0; 4646 dac = 0;
4216 else { 4647 else {
4217 printk(KERN_ERR "cciss: no suitable DMA available\n"); 4648 dev_err(&h->pdev->dev, "no suitable DMA available\n");
4218 goto clean1; 4649 goto clean1;
4219 } 4650 }
4220 4651
@@ -4224,151 +4655,161 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4224 * 8 controller support. 4655 * 8 controller support.
4225 */ 4656 */
4226 if (i < MAX_CTLR_ORIG) 4657 if (i < MAX_CTLR_ORIG)
4227 hba[i]->major = COMPAQ_CISS_MAJOR + i; 4658 h->major = COMPAQ_CISS_MAJOR + i;
4228 rc = register_blkdev(hba[i]->major, hba[i]->devname); 4659 rc = register_blkdev(h->major, h->devname);
4229 if (rc == -EBUSY || rc == -EINVAL) { 4660 if (rc == -EBUSY || rc == -EINVAL) {
4230 printk(KERN_ERR 4661 dev_err(&h->pdev->dev,
4231 "cciss: Unable to get major number %d for %s " 4662 "Unable to get major number %d for %s "
4232 "on hba %d\n", hba[i]->major, hba[i]->devname, i); 4663 "on hba %d\n", h->major, h->devname, i);
4233 goto clean1; 4664 goto clean1;
4234 } else { 4665 } else {
4235 if (i >= MAX_CTLR_ORIG) 4666 if (i >= MAX_CTLR_ORIG)
4236 hba[i]->major = rc; 4667 h->major = rc;
4237 } 4668 }
4238 4669
4239 /* make sure the board interrupts are off */ 4670 /* make sure the board interrupts are off */
4240 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF); 4671 h->access.set_intr_mask(h, CCISS_INTR_OFF);
4241 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr, 4672 if (h->msi_vector || h->msix_vector) {
4242 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) { 4673 if (request_irq(h->intr[PERF_MODE_INT],
4243 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n", 4674 do_cciss_msix_intr,
4244 hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname); 4675 IRQF_DISABLED, h->devname, h)) {
4245 goto clean2; 4676 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4677 h->intr[PERF_MODE_INT], h->devname);
4678 goto clean2;
4679 }
4680 } else {
4681 if (request_irq(h->intr[PERF_MODE_INT], do_cciss_intx,
4682 IRQF_DISABLED, h->devname, h)) {
4683 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4684 h->intr[PERF_MODE_INT], h->devname);
4685 goto clean2;
4686 }
4246 } 4687 }
4247 4688
4248 printk(KERN_INFO "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n", 4689 dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
4249 hba[i]->devname, pdev->device, pci_name(pdev), 4690 h->devname, pdev->device, pci_name(pdev),
4250 hba[i]->intr[SIMPLE_MODE_INT], dac ? "" : " not"); 4691 h->intr[PERF_MODE_INT], dac ? "" : " not");
4251 4692
4252 hba[i]->cmd_pool_bits = 4693 h->cmd_pool_bits =
4253 kmalloc(DIV_ROUND_UP(hba[i]->nr_cmds, BITS_PER_LONG) 4694 kmalloc(DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
4254 * sizeof(unsigned long), GFP_KERNEL); 4695 * sizeof(unsigned long), GFP_KERNEL);
4255 hba[i]->cmd_pool = (CommandList_struct *) 4696 h->cmd_pool = (CommandList_struct *)
4256 pci_alloc_consistent(hba[i]->pdev, 4697 pci_alloc_consistent(h->pdev,
4257 hba[i]->nr_cmds * sizeof(CommandList_struct), 4698 h->nr_cmds * sizeof(CommandList_struct),
4258 &(hba[i]->cmd_pool_dhandle)); 4699 &(h->cmd_pool_dhandle));
4259 hba[i]->errinfo_pool = (ErrorInfo_struct *) 4700 h->errinfo_pool = (ErrorInfo_struct *)
4260 pci_alloc_consistent(hba[i]->pdev, 4701 pci_alloc_consistent(h->pdev,
4261 hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4702 h->nr_cmds * sizeof(ErrorInfo_struct),
4262 &(hba[i]->errinfo_pool_dhandle)); 4703 &(h->errinfo_pool_dhandle));
4263 if ((hba[i]->cmd_pool_bits == NULL) 4704 if ((h->cmd_pool_bits == NULL)
4264 || (hba[i]->cmd_pool == NULL) 4705 || (h->cmd_pool == NULL)
4265 || (hba[i]->errinfo_pool == NULL)) { 4706 || (h->errinfo_pool == NULL)) {
4266 printk(KERN_ERR "cciss: out of memory"); 4707 dev_err(&h->pdev->dev, "out of memory");
4267 goto clean4; 4708 goto clean4;
4268 } 4709 }
4269 4710
4270 /* Need space for temp scatter list */ 4711 /* Need space for temp scatter list */
4271 hba[i]->scatter_list = kmalloc(hba[i]->max_commands * 4712 h->scatter_list = kmalloc(h->max_commands *
4272 sizeof(struct scatterlist *), 4713 sizeof(struct scatterlist *),
4273 GFP_KERNEL); 4714 GFP_KERNEL);
4274 for (k = 0; k < hba[i]->nr_cmds; k++) { 4715 for (k = 0; k < h->nr_cmds; k++) {
4275 hba[i]->scatter_list[k] = kmalloc(sizeof(struct scatterlist) * 4716 h->scatter_list[k] = kmalloc(sizeof(struct scatterlist) *
4276 hba[i]->maxsgentries, 4717 h->maxsgentries,
4277 GFP_KERNEL); 4718 GFP_KERNEL);
4278 if (hba[i]->scatter_list[k] == NULL) { 4719 if (h->scatter_list[k] == NULL) {
4279 printk(KERN_ERR "cciss%d: could not allocate " 4720 dev_err(&h->pdev->dev,
4280 "s/g lists\n", i); 4721 "could not allocate s/g lists\n");
4281 goto clean4; 4722 goto clean4;
4282 } 4723 }
4283 } 4724 }
4284 hba[i]->cmd_sg_list = cciss_allocate_sg_chain_blocks(hba[i], 4725 h->cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
4285 hba[i]->chainsize, hba[i]->nr_cmds); 4726 h->chainsize, h->nr_cmds);
4286 if (!hba[i]->cmd_sg_list && hba[i]->chainsize > 0) 4727 if (!h->cmd_sg_list && h->chainsize > 0)
4287 goto clean4; 4728 goto clean4;
4288 4729
4289 spin_lock_init(&hba[i]->lock); 4730 spin_lock_init(&h->lock);
4290 4731
4291 /* Initialize the pdev driver private data. 4732 /* Initialize the pdev driver private data.
4292 have it point to hba[i]. */ 4733 have it point to h. */
4293 pci_set_drvdata(pdev, hba[i]); 4734 pci_set_drvdata(pdev, h);
4294 /* command and error info recs zeroed out before 4735 /* command and error info recs zeroed out before
4295 they are used */ 4736 they are used */
4296 memset(hba[i]->cmd_pool_bits, 0, 4737 memset(h->cmd_pool_bits, 0,
4297 DIV_ROUND_UP(hba[i]->nr_cmds, BITS_PER_LONG) 4738 DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
4298 * sizeof(unsigned long)); 4739 * sizeof(unsigned long));
4299 4740
4300 hba[i]->num_luns = 0; 4741 h->num_luns = 0;
4301 hba[i]->highest_lun = -1; 4742 h->highest_lun = -1;
4302 for (j = 0; j < CISS_MAX_LUN; j++) { 4743 for (j = 0; j < CISS_MAX_LUN; j++) {
4303 hba[i]->drv[j] = NULL; 4744 h->drv[j] = NULL;
4304 hba[i]->gendisk[j] = NULL; 4745 h->gendisk[j] = NULL;
4305 } 4746 }
4306 4747
4307 cciss_scsi_setup(i); 4748 cciss_scsi_setup(h);
4308 4749
4309 /* Turn the interrupts on so we can service requests */ 4750 /* Turn the interrupts on so we can service requests */
4310 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON); 4751 h->access.set_intr_mask(h, CCISS_INTR_ON);
4311 4752
4312 /* Get the firmware version */ 4753 /* Get the firmware version */
4313 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL); 4754 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
4314 if (inq_buff == NULL) { 4755 if (inq_buff == NULL) {
4315 printk(KERN_ERR "cciss: out of memory\n"); 4756 dev_err(&h->pdev->dev, "out of memory\n");
4316 goto clean4; 4757 goto clean4;
4317 } 4758 }
4318 4759
4319 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff, 4760 return_code = sendcmd_withirq(h, CISS_INQUIRY, inq_buff,
4320 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD); 4761 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD);
4321 if (return_code == IO_OK) { 4762 if (return_code == IO_OK) {
4322 hba[i]->firm_ver[0] = inq_buff->data_byte[32]; 4763 h->firm_ver[0] = inq_buff->data_byte[32];
4323 hba[i]->firm_ver[1] = inq_buff->data_byte[33]; 4764 h->firm_ver[1] = inq_buff->data_byte[33];
4324 hba[i]->firm_ver[2] = inq_buff->data_byte[34]; 4765 h->firm_ver[2] = inq_buff->data_byte[34];
4325 hba[i]->firm_ver[3] = inq_buff->data_byte[35]; 4766 h->firm_ver[3] = inq_buff->data_byte[35];
4326 } else { /* send command failed */ 4767 } else { /* send command failed */
4327 printk(KERN_WARNING "cciss: unable to determine firmware" 4768 dev_warn(&h->pdev->dev, "unable to determine firmware"
4328 " version of controller\n"); 4769 " version of controller\n");
4329 } 4770 }
4330 kfree(inq_buff); 4771 kfree(inq_buff);
4331 4772
4332 cciss_procinit(i); 4773 cciss_procinit(h);
4333 4774
4334 hba[i]->cciss_max_sectors = 8192; 4775 h->cciss_max_sectors = 8192;
4335 4776
4336 rebuild_lun_table(hba[i], 1, 0); 4777 rebuild_lun_table(h, 1, 0);
4337 hba[i]->busy_initializing = 0; 4778 h->busy_initializing = 0;
4338 return 1; 4779 return 1;
4339 4780
4340clean4: 4781clean4:
4341 kfree(hba[i]->cmd_pool_bits); 4782 kfree(h->cmd_pool_bits);
4342 /* Free up sg elements */ 4783 /* Free up sg elements */
4343 for (k = 0; k < hba[i]->nr_cmds; k++) 4784 for (k = 0; k < h->nr_cmds; k++)
4344 kfree(hba[i]->scatter_list[k]); 4785 kfree(h->scatter_list[k]);
4345 kfree(hba[i]->scatter_list); 4786 kfree(h->scatter_list);
4346 cciss_free_sg_chain_blocks(hba[i]->cmd_sg_list, hba[i]->nr_cmds); 4787 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4347 if (hba[i]->cmd_pool) 4788 if (h->cmd_pool)
4348 pci_free_consistent(hba[i]->pdev, 4789 pci_free_consistent(h->pdev,
4349 hba[i]->nr_cmds * sizeof(CommandList_struct), 4790 h->nr_cmds * sizeof(CommandList_struct),
4350 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); 4791 h->cmd_pool, h->cmd_pool_dhandle);
4351 if (hba[i]->errinfo_pool) 4792 if (h->errinfo_pool)
4352 pci_free_consistent(hba[i]->pdev, 4793 pci_free_consistent(h->pdev,
4353 hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4794 h->nr_cmds * sizeof(ErrorInfo_struct),
4354 hba[i]->errinfo_pool, 4795 h->errinfo_pool,
4355 hba[i]->errinfo_pool_dhandle); 4796 h->errinfo_pool_dhandle);
4356 free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]); 4797 free_irq(h->intr[PERF_MODE_INT], h);
4357clean2: 4798clean2:
4358 unregister_blkdev(hba[i]->major, hba[i]->devname); 4799 unregister_blkdev(h->major, h->devname);
4359clean1: 4800clean1:
4360 cciss_destroy_hba_sysfs_entry(hba[i]); 4801 cciss_destroy_hba_sysfs_entry(h);
4361clean0: 4802clean0:
4362 pci_release_regions(pdev); 4803 pci_release_regions(pdev);
4363clean_no_release_regions: 4804clean_no_release_regions:
4364 hba[i]->busy_initializing = 0; 4805 h->busy_initializing = 0;
4365 4806
4366 /* 4807 /*
4367 * Deliberately omit pci_disable_device(): it does something nasty to 4808 * Deliberately omit pci_disable_device(): it does something nasty to
4368 * Smart Array controllers that pci_enable_device does not undo 4809 * Smart Array controllers that pci_enable_device does not undo
4369 */ 4810 */
4370 pci_set_drvdata(pdev, NULL); 4811 pci_set_drvdata(pdev, NULL);
4371 free_hba(i); 4812 free_hba(h);
4372 return -1; 4813 return -1;
4373} 4814}
4374 4815
@@ -4381,55 +4822,51 @@ static void cciss_shutdown(struct pci_dev *pdev)
4381 h = pci_get_drvdata(pdev); 4822 h = pci_get_drvdata(pdev);
4382 flush_buf = kzalloc(4, GFP_KERNEL); 4823 flush_buf = kzalloc(4, GFP_KERNEL);
4383 if (!flush_buf) { 4824 if (!flush_buf) {
4384 printk(KERN_WARNING 4825 dev_warn(&h->pdev->dev, "cache not flushed, out of memory.\n");
4385 "cciss:%d cache not flushed, out of memory.\n",
4386 h->ctlr);
4387 return; 4826 return;
4388 } 4827 }
4389 /* write all data in the battery backed cache to disk */ 4828 /* write all data in the battery backed cache to disk */
4390 memset(flush_buf, 0, 4); 4829 memset(flush_buf, 0, 4);
4391 return_code = sendcmd_withirq(CCISS_CACHE_FLUSH, h->ctlr, flush_buf, 4830 return_code = sendcmd_withirq(h, CCISS_CACHE_FLUSH, flush_buf,
4392 4, 0, CTLR_LUNID, TYPE_CMD); 4831 4, 0, CTLR_LUNID, TYPE_CMD);
4393 kfree(flush_buf); 4832 kfree(flush_buf);
4394 if (return_code != IO_OK) 4833 if (return_code != IO_OK)
4395 printk(KERN_WARNING "cciss%d: Error flushing cache\n", 4834 dev_warn(&h->pdev->dev, "Error flushing cache\n");
4396 h->ctlr);
4397 h->access.set_intr_mask(h, CCISS_INTR_OFF); 4835 h->access.set_intr_mask(h, CCISS_INTR_OFF);
4398 free_irq(h->intr[2], h); 4836 free_irq(h->intr[PERF_MODE_INT], h);
4399} 4837}
4400 4838
4401static void __devexit cciss_remove_one(struct pci_dev *pdev) 4839static void __devexit cciss_remove_one(struct pci_dev *pdev)
4402{ 4840{
4403 ctlr_info_t *tmp_ptr; 4841 ctlr_info_t *h;
4404 int i, j; 4842 int i, j;
4405 4843
4406 if (pci_get_drvdata(pdev) == NULL) { 4844 if (pci_get_drvdata(pdev) == NULL) {
4407 printk(KERN_ERR "cciss: Unable to remove device \n"); 4845 dev_err(&pdev->dev, "Unable to remove device\n");
4408 return; 4846 return;
4409 } 4847 }
4410 4848
4411 tmp_ptr = pci_get_drvdata(pdev); 4849 h = pci_get_drvdata(pdev);
4412 i = tmp_ptr->ctlr; 4850 i = h->ctlr;
4413 if (hba[i] == NULL) { 4851 if (hba[i] == NULL) {
4414 printk(KERN_ERR "cciss: device appears to " 4852 dev_err(&pdev->dev, "device appears to already be removed\n");
4415 "already be removed \n");
4416 return; 4853 return;
4417 } 4854 }
4418 4855
4419 mutex_lock(&hba[i]->busy_shutting_down); 4856 mutex_lock(&h->busy_shutting_down);
4420 4857
4421 remove_from_scan_list(hba[i]); 4858 remove_from_scan_list(h);
4422 remove_proc_entry(hba[i]->devname, proc_cciss); 4859 remove_proc_entry(h->devname, proc_cciss);
4423 unregister_blkdev(hba[i]->major, hba[i]->devname); 4860 unregister_blkdev(h->major, h->devname);
4424 4861
4425 /* remove it from the disk list */ 4862 /* remove it from the disk list */
4426 for (j = 0; j < CISS_MAX_LUN; j++) { 4863 for (j = 0; j < CISS_MAX_LUN; j++) {
4427 struct gendisk *disk = hba[i]->gendisk[j]; 4864 struct gendisk *disk = h->gendisk[j];
4428 if (disk) { 4865 if (disk) {
4429 struct request_queue *q = disk->queue; 4866 struct request_queue *q = disk->queue;
4430 4867
4431 if (disk->flags & GENHD_FL_UP) { 4868 if (disk->flags & GENHD_FL_UP) {
4432 cciss_destroy_ld_sysfs_entry(hba[i], j, 1); 4869 cciss_destroy_ld_sysfs_entry(h, j, 1);
4433 del_gendisk(disk); 4870 del_gendisk(disk);
4434 } 4871 }
4435 if (q) 4872 if (q)
@@ -4438,39 +4875,41 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
4438 } 4875 }
4439 4876
4440#ifdef CONFIG_CISS_SCSI_TAPE 4877#ifdef CONFIG_CISS_SCSI_TAPE
4441 cciss_unregister_scsi(i); /* unhook from SCSI subsystem */ 4878 cciss_unregister_scsi(h); /* unhook from SCSI subsystem */
4442#endif 4879#endif
4443 4880
4444 cciss_shutdown(pdev); 4881 cciss_shutdown(pdev);
4445 4882
4446#ifdef CONFIG_PCI_MSI 4883#ifdef CONFIG_PCI_MSI
4447 if (hba[i]->msix_vector) 4884 if (h->msix_vector)
4448 pci_disable_msix(hba[i]->pdev); 4885 pci_disable_msix(h->pdev);
4449 else if (hba[i]->msi_vector) 4886 else if (h->msi_vector)
4450 pci_disable_msi(hba[i]->pdev); 4887 pci_disable_msi(h->pdev);
4451#endif /* CONFIG_PCI_MSI */ 4888#endif /* CONFIG_PCI_MSI */
4452 4889
4453 iounmap(hba[i]->vaddr); 4890 iounmap(h->transtable);
4891 iounmap(h->cfgtable);
4892 iounmap(h->vaddr);
4454 4893
4455 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(CommandList_struct), 4894 pci_free_consistent(h->pdev, h->nr_cmds * sizeof(CommandList_struct),
4456 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); 4895 h->cmd_pool, h->cmd_pool_dhandle);
4457 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4896 pci_free_consistent(h->pdev, h->nr_cmds * sizeof(ErrorInfo_struct),
4458 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle); 4897 h->errinfo_pool, h->errinfo_pool_dhandle);
4459 kfree(hba[i]->cmd_pool_bits); 4898 kfree(h->cmd_pool_bits);
4460 /* Free up sg elements */ 4899 /* Free up sg elements */
4461 for (j = 0; j < hba[i]->nr_cmds; j++) 4900 for (j = 0; j < h->nr_cmds; j++)
4462 kfree(hba[i]->scatter_list[j]); 4901 kfree(h->scatter_list[j]);
4463 kfree(hba[i]->scatter_list); 4902 kfree(h->scatter_list);
4464 cciss_free_sg_chain_blocks(hba[i]->cmd_sg_list, hba[i]->nr_cmds); 4903 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4465 /* 4904 /*
4466 * Deliberately omit pci_disable_device(): it does something nasty to 4905 * Deliberately omit pci_disable_device(): it does something nasty to
4467 * Smart Array controllers that pci_enable_device does not undo 4906 * Smart Array controllers that pci_enable_device does not undo
4468 */ 4907 */
4469 pci_release_regions(pdev); 4908 pci_release_regions(pdev);
4470 pci_set_drvdata(pdev, NULL); 4909 pci_set_drvdata(pdev, NULL);
4471 cciss_destroy_hba_sysfs_entry(hba[i]); 4910 cciss_destroy_hba_sysfs_entry(h);
4472 mutex_unlock(&hba[i]->busy_shutting_down); 4911 mutex_unlock(&h->busy_shutting_down);
4473 free_hba(i); 4912 free_hba(h);
4474} 4913}
4475 4914
4476static struct pci_driver cciss_pci_driver = { 4915static struct pci_driver cciss_pci_driver = {
@@ -4495,7 +4934,6 @@ static int __init cciss_init(void)
4495 * array of them, the size must be a multiple of 8 bytes. 4934 * array of them, the size must be a multiple of 8 bytes.
4496 */ 4935 */
4497 BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT); 4936 BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT);
4498
4499 printk(KERN_INFO DRIVER_NAME "\n"); 4937 printk(KERN_INFO DRIVER_NAME "\n");
4500 4938
4501 err = bus_register(&cciss_bus_type); 4939 err = bus_register(&cciss_bus_type);
@@ -4532,8 +4970,8 @@ static void __exit cciss_cleanup(void)
4532 /* double check that all controller entrys have been removed */ 4970 /* double check that all controller entrys have been removed */
4533 for (i = 0; i < MAX_CTLR; i++) { 4971 for (i = 0; i < MAX_CTLR; i++) {
4534 if (hba[i] != NULL) { 4972 if (hba[i] != NULL) {
4535 printk(KERN_WARNING "cciss: had to remove" 4973 dev_warn(&hba[i]->pdev->dev,
4536 " controller %d\n", i); 4974 "had to remove controller\n");
4537 cciss_remove_one(hba[i]->pdev); 4975 cciss_remove_one(hba[i]->pdev);
4538 } 4976 }
4539 } 4977 }
@@ -4542,46 +4980,5 @@ static void __exit cciss_cleanup(void)
4542 bus_unregister(&cciss_bus_type); 4980 bus_unregister(&cciss_bus_type);
4543} 4981}
4544 4982
4545static void fail_all_cmds(unsigned long ctlr)
4546{
4547 /* If we get here, the board is apparently dead. */
4548 ctlr_info_t *h = hba[ctlr];
4549 CommandList_struct *c;
4550 unsigned long flags;
4551
4552 printk(KERN_WARNING "cciss%d: controller not responding.\n", h->ctlr);
4553 h->alive = 0; /* the controller apparently died... */
4554
4555 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
4556
4557 pci_disable_device(h->pdev); /* Make sure it is really dead. */
4558
4559 /* move everything off the request queue onto the completed queue */
4560 while (!hlist_empty(&h->reqQ)) {
4561 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
4562 removeQ(c);
4563 h->Qdepth--;
4564 addQ(&h->cmpQ, c);
4565 }
4566
4567 /* Now, fail everything on the completed queue with a HW error */
4568 while (!hlist_empty(&h->cmpQ)) {
4569 c = hlist_entry(h->cmpQ.first, CommandList_struct, list);
4570 removeQ(c);
4571 if (c->cmd_type != CMD_MSG_STALE)
4572 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
4573 if (c->cmd_type == CMD_RWREQ) {
4574 complete_command(h, c, 0);
4575 } else if (c->cmd_type == CMD_IOCTL_PEND)
4576 complete(c->waiting);
4577#ifdef CONFIG_CISS_SCSI_TAPE
4578 else if (c->cmd_type == CMD_SCSI)
4579 complete_scsi_command(c, 0, 0);
4580#endif
4581 }
4582 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
4583 return;
4584}
4585
4586module_init(cciss_init); 4983module_init(cciss_init);
4587module_exit(cciss_cleanup); 4984module_exit(cciss_cleanup);