23 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/pci.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
44 #include <asm/uaccess.h>
51 #include <scsi/scsi.h>
54 #include <linux/cdrom.h>
58 #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
59 #define DRIVER_NAME "HP CISS Driver (v 3.6.26)"
60 #define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 26)
68 static int cciss_tape_cmds = 6;
71 "number of commands to allocate for tape devices (default: 6)");
72 static int cciss_simple_mode;
75 "Use 'simple mode' rather than 'performant mode'");
82 #include <linux/cciss_ioctl.h>
116 {0x40700E11,
"Smart Array 5300", &SA5_access},
117 {0x40800E11,
"Smart Array 5i", &SA5B_access},
118 {0x40820E11,
"Smart Array 532", &SA5B_access},
119 {0x40830E11,
"Smart Array 5312", &SA5B_access},
120 {0x409A0E11,
"Smart Array 641", &SA5_access},
121 {0x409B0E11,
"Smart Array 642", &SA5_access},
122 {0x409C0E11,
"Smart Array 6400", &SA5_access},
123 {0x409D0E11,
"Smart Array 6400 EM", &SA5_access},
124 {0x40910E11,
"Smart Array 6i", &SA5_access},
125 {0x3225103C,
"Smart Array P600", &SA5_access},
126 {0x3223103C,
"Smart Array P800", &SA5_access},
127 {0x3234103C,
"Smart Array P400", &SA5_access},
128 {0x3235103C,
"Smart Array P400i", &SA5_access},
129 {0x3211103C,
"Smart Array E200i", &SA5_access},
130 {0x3212103C,
"Smart Array E200", &SA5_access},
131 {0x3213103C,
"Smart Array E200i", &SA5_access},
132 {0x3214103C,
"Smart Array E200i", &SA5_access},
133 {0x3215103C,
"Smart Array E200i", &SA5_access},
134 {0x3237103C,
"Smart Array E500", &SA5_access},
135 {0x3223103C,
"Smart Array P800", &SA5_access},
136 {0x3234103C,
"Smart Array P400", &SA5_access},
137 {0x323D103C,
"Smart Array P700m", &SA5_access},
141 #define MAX_CONFIG_WAIT 30000
142 #define MAX_IOCTL_CONFIG_WAIT 1000
145 #define MAX_CMD_RETRIES 3
150 #define MAX_CTLR_ORIG 8
163 static int cciss_release(
struct gendisk *disk,
fmode_t mode);
165 unsigned int cmd,
unsigned long arg);
167 unsigned int cmd,
unsigned long arg);
170 static int cciss_revalidate(
struct gendisk *disk);
171 static int rebuild_lun_table(
ctlr_info_t *
h,
int first_time,
int via_ioctl);
172 static int deregister_disk(
ctlr_info_t *
h,
int drv_index,
173 int clear_all,
int via_ioctl);
175 static void cciss_read_capacity(
ctlr_info_t *
h,
int logvol,
177 static void cciss_read_capacity_16(
ctlr_info_t *
h,
int logvol,
179 static void cciss_geometry_inquiry(
ctlr_info_t *
h,
int logvol,
193 static int add_to_scan_list(
struct ctlr_info *
h);
194 static int scan_thread(
void *
data);
196 static void cciss_hba_release(
struct device *
dev);
197 static void cciss_device_release(
struct device *
dev);
198 static void cciss_free_gendisk(
ctlr_info_t *
h,
int drv_index);
199 static void cciss_free_drive_info(
ctlr_info_t *
h,
int drv_index);
205 unsigned long *memory_bar);
207 static __devinit int write_driver_ver_to_cfgtable(
211 static void calc_bucket_map(
int *bucket,
int num_buckets,
int nsgs,
213 static void cciss_put_controller_into_performant_mode(
ctlr_info_t *
h);
215 #ifdef CONFIG_PROC_FS
225 unsigned,
unsigned long);
228 static const struct block_device_operations cciss_fops = {
230 .open = cciss_unlocked_open,
231 .release = cciss_release,
233 .getgeo = cciss_getgeo,
235 .compat_ioctl = cciss_compat_ioctl,
237 .revalidate_disk = cciss_revalidate,
273 list_del_init(&c->
list);
276 static void enqueue_cmd_and_start_io(
ctlr_info_t *h,
280 set_performant_mode(h, c);
287 spin_unlock_irqrestore(&h->
lock, flags);
297 for (i = 0; i < nr_cmds; i++) {
298 kfree(cmd_sg_list[i]);
299 cmd_sg_list[
i] =
NULL;
318 for (j = 0; j < nr_cmds; j++) {
320 cmd_sg_list[
j] =
kmalloc((chainsize *
322 if (!cmd_sg_list[j]) {
324 "for s/g chains.\n");
330 cciss_free_sg_chain_blocks(cmd_sg_list, nr_cmds);
343 temp64.
val32.lower = chain_sg->
Addr.lower;
344 temp64.
val32.upper = chain_sg->
Addr.upper;
357 temp64.
val = pci_map_single(h->
pdev, chain_block, len,
359 chain_sg->
Addr.lower = temp64.
val32.lower;
360 chain_sg->
Addr.upper = temp64.
val32.upper;
365 static const char *raid_label[] = {
"0",
"4",
"1(1+0)",
"5",
"5+1",
"ADG",
368 #define RAID_UNKNOWN (ARRAY_SIZE(raid_label)-1)
370 #ifdef CONFIG_PROC_FS
375 #define ENG_GIG 1000000000
376 #define ENG_GIG_FACTOR (ENG_GIG/512)
377 #define ENGAGE_SCSI "engage scsi"
379 static void cciss_seq_show_header(
struct seq_file *seq)
384 "Board ID: 0x%08lx\n"
385 "Firmware Version: %c%c%c%c\n"
387 "Logical drives: %d\n"
388 "Current Q depth: %d\n"
389 "Current # commands on controller: %d\n"
390 "Max Q depth since init: %d\n"
391 "Max # commands on controller since init: %d\n"
392 "Max SG entries since init: %d\n",
402 #ifdef CONFIG_CISS_SCSI_TAPE
403 cciss_seq_tape_report(seq, h);
407 static void *cciss_seq_start(
struct seq_file *seq, loff_t *
pos)
417 spin_unlock_irqrestore(&h->
lock, flags);
418 return ERR_PTR(-
EBUSY);
421 spin_unlock_irqrestore(&h->
lock, flags);
424 cciss_seq_show_header(seq);
429 static int cciss_seq_show(
struct seq_file *seq,
void *
v)
433 unsigned ctlr = h->
ctlr;
447 vol_sz_frac =
sector_div(vol_sz, ENG_GIG_FACTOR);
454 "\t%4u.%02uGB\tRAID %s\n",
455 ctlr, (
int) *pos, (
int)vol_sz, (
int)vol_sz_frac,
460 static void *cciss_seq_next(
struct seq_file *seq,
void *v, loff_t *pos)
471 static void cciss_seq_stop(
struct seq_file *seq,
void *v)
477 if (v == ERR_PTR(-
EBUSY))
484 .
start = cciss_seq_start,
485 .show = cciss_seq_show,
486 .next = cciss_seq_next,
487 .stop = cciss_seq_stop,
496 seq->
private = PDE(inode)->data;
502 cciss_proc_write(
struct file *file,
const char __user *
buf,
503 size_t length, loff_t *ppos)
508 #ifndef CONFIG_CISS_SCSI_TAPE
524 #ifdef CONFIG_CISS_SCSI_TAPE
525 if (
strncmp(ENGAGE_SCSI, buffer,
sizeof ENGAGE_SCSI - 1) == 0) {
545 .open = cciss_seq_open,
549 .write = cciss_proc_write,
556 if (proc_cciss ==
NULL)
562 &cciss_proc_fops, h);
566 #define MAX_PRODUCT_NAME_LEN 19
568 #define to_hba(n) container_of(n, struct ctlr_info, dev)
569 #define to_drv(n) container_of(n, drive_info_struct, dev)
572 static u32 unresettable_controller[] = {
590 static u32 soft_unresettable_controller[] = {
599 for (i = 0; i <
ARRAY_SIZE(unresettable_controller); i++)
600 if (unresettable_controller[i] == board_id)
605 static int ctlr_is_soft_resettable(
u32 board_id)
609 for (i = 0; i <
ARRAY_SIZE(soft_unresettable_controller); i++)
610 if (soft_unresettable_controller[i] == board_id)
615 static int ctlr_is_resettable(
u32 board_id)
617 return ctlr_is_hard_resettable(board_id) ||
618 ctlr_is_soft_resettable(board_id);
633 const char *buf,
size_t count)
653 "performant" :
"simple");
672 spin_unlock_irqrestore(&h->
lock, flags);
678 "%02X%02X%02X%02X%02X%02X%02X%02X"
679 "%02X%02X%02X%02X%02X%02X%02X%02X\n",
680 sn[0], sn[1], sn[2], sn[3],
681 sn[4], sn[5], sn[6], sn[7],
682 sn[8], sn[9], sn[10], sn[11],
683 sn[12], sn[13], sn[14], sn[15]);
702 spin_unlock_irqrestore(&h->
lock, flags);
726 spin_unlock_irqrestore(&h->
lock, flags);
750 spin_unlock_irqrestore(&h->
lock, flags);
755 return snprintf(buf,
sizeof(rev) + 1,
"%s\n", drv->
rev);
765 unsigned char lunid[8];
769 spin_unlock_irqrestore(&h->
lock, flags);
773 spin_unlock_irqrestore(&h->
lock, flags);
777 spin_unlock_irqrestore(&h->
lock, flags);
778 return snprintf(buf, 20,
"0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
779 lunid[0], lunid[1], lunid[2], lunid[3],
780 lunid[4], lunid[5], lunid[6], lunid[7]);
794 spin_unlock_irqrestore(&h->
lock, flags);
798 spin_unlock_irqrestore(&h->
lock, flags);
817 spin_unlock_irqrestore(&h->
lock, flags);
821 spin_unlock_irqrestore(&h->
lock, flags);
822 return snprintf(buf, 20,
"%d\n", count);
826 static struct attribute *cciss_host_attrs[] = {
827 &dev_attr_rescan.attr,
828 &dev_attr_resettable.attr,
829 &dev_attr_transport_mode.attr,
834 .attrs = cciss_host_attrs,
838 &cciss_host_attr_group,
843 .name =
"cciss_host",
844 .groups = cciss_host_attr_groups,
845 .release = cciss_hba_release,
848 static struct attribute *cciss_dev_attrs[] = {
849 &dev_attr_unique_id.attr,
850 &dev_attr_model.attr,
851 &dev_attr_vendor.attr,
853 &dev_attr_lunid.attr,
854 &dev_attr_raid_level.attr,
855 &dev_attr_usage_count.attr,
860 .attrs = cciss_dev_attrs,
864 &cciss_dev_attr_group,
869 .name =
"cciss_device",
870 .groups = cciss_dev_attr_groups,
871 .release = cciss_device_release,
874 static struct bus_type cciss_bus_type = {
882 static void cciss_hba_release(
struct device *dev)
895 static int cciss_create_hba_sysfs_entry(
struct ctlr_info *h)
898 h->
dev.type = &cciss_host_type;
899 h->
dev.bus = &cciss_bus_type;
909 static void cciss_destroy_hba_sysfs_entry(
struct ctlr_info *h)
918 static void cciss_device_release(
struct device *dev)
930 static long cciss_create_ld_sysfs_entry(
struct ctlr_info *h,
938 dev = &h->
drv[drv_index]->
dev;
940 dev->
type = &cciss_dev_type;
941 dev->
bus = &cciss_bus_type;
951 static void cciss_destroy_ld_sysfs_entry(
struct ctlr_info *h,
int drv_index,
957 if (drv_index == 0 && !ctlr_exiting)
994 INIT_LIST_HEAD(&c->
list);
996 temp64.
val = (
__u64) err_dma_handle;
1033 INIT_LIST_HEAD(&c->
list);
1035 temp64.
val = (
__u64) err_dma_handle;
1066 static inline ctlr_info_t *get_host(
struct gendisk *disk)
1068 return disk->queue->queuedata;
1073 return disk->private_data;
1095 if (drv->
heads == 0) {
1102 sizeof(drv->
LunID))) {
1119 ret = cciss_open(bdev, mode);
1128 static int cciss_release(
struct gendisk *disk,
fmode_t mode)
1135 drv = get_drv(disk);
1136 dev_dbg(&h->
pdev->dev,
"cciss_release %s\n", disk->disk_name);
1144 unsigned cmd,
unsigned long arg)
1148 ret = cciss_ioctl(bdev, mode, cmd, arg);
1153 #ifdef CONFIG_COMPAT
1156 unsigned cmd,
unsigned long arg);
1158 unsigned cmd,
unsigned long arg);
1161 unsigned cmd,
unsigned long arg)
1179 return do_ioctl(bdev, mode, cmd, arg);
1181 case CCISS_PASSTHRU32:
1182 return cciss_ioctl32_passthru(bdev, mode, cmd, arg);
1183 case CCISS_BIG_PASSTHRU32:
1184 return cciss_ioctl32_big_passthru(bdev, mode, cmd, arg);
1192 unsigned cmd,
unsigned long arg)
1194 IOCTL32_Command_struct
__user *arg32 =
1195 (IOCTL32_Command_struct
__user *) arg;
1213 arg64.
buf = compat_ptr(cp);
1224 sizeof(arg32->error_info));
1231 unsigned cmd,
unsigned long arg)
1233 BIG_IOCTL32_Command_struct
__user *arg32 =
1234 (BIG_IOCTL32_Command_struct
__user *) arg;
1241 memset(&arg64, 0,
sizeof(arg64));
1255 arg64.
buf = compat_ptr(cp);
1266 sizeof(arg32->error_info));
1290 (
void)check_for_unit_attention(h, c);
1300 pciinfo.
bus = h->
pdev->bus->number;
1308 static int cciss_getintinfo(
ctlr_info_t *h,
void __user *argp)
1322 static int cciss_setintinfo(
ctlr_info_t *h,
void __user *argp)
1325 unsigned long flags;
1334 if ((intinfo.
delay == 0) && (intinfo.
count == 0))
1347 spin_unlock_irqrestore(&h->
lock, flags);
1348 if (i >= MAX_IOCTL_CONFIG_WAIT)
1353 static int cciss_getnodename(
ctlr_info_t *h,
void __user *argp)
1360 for (i = 0; i < 16; i++)
1367 static int cciss_setnodename(
ctlr_info_t *h,
void __user *argp)
1370 unsigned long flags;
1381 for (i = 0; i < 16; i++)
1389 spin_unlock_irqrestore(&h->
lock, flags);
1390 if (i >= MAX_IOCTL_CONFIG_WAIT)
1395 static int cciss_getheartbeat(
ctlr_info_t *h,
void __user *argp)
1407 static int cciss_getbustypes(
ctlr_info_t *h,
void __user *argp)
1419 static int cciss_getfirmver(
ctlr_info_t *h,
void __user *argp)
1433 static int cciss_getdrivver(
ctlr_info_t *h,
void __user *argp)
1445 struct gendisk *disk,
void __user *argp)
1460 static int cciss_passthru(
ctlr_info_t *h,
void __user *argp)
1495 c = cmd_special_alloc(h);
1520 temp64.
val = pci_map_single(h->
pdev, buff,
1529 enqueue_cmd_and_start_io(h, c);
1537 check_ioctl_unit_attention(h, c);
1543 cmd_special_free(h, c);
1551 cmd_special_free(h, c);
1556 cmd_special_free(h, c);
1560 static int cciss_bigpassthru(
ctlr_info_t *h,
void __user *argp)
1564 unsigned char **buff =
NULL;
1613 data_ptr = ioc->
buf;
1616 buff_size[sg_used] = sz;
1618 if (buff[sg_used] ==
NULL) {
1628 memset(buff[sg_used], 0, sz);
1634 c = cmd_special_alloc(h);
1647 for (i = 0; i < sg_used; i++) {
1648 temp64.
val = pci_map_single(h->
pdev, buff[i], buff_size[i],
1656 enqueue_cmd_and_start_io(h, c);
1659 for (i = 0; i < sg_used; i++) {
1662 pci_unmap_single(h->
pdev,
1666 check_ioctl_unit_attention(h, c);
1670 cmd_special_free(h, c);
1677 for (i = 0; i < sg_used; i++) {
1679 cmd_special_free(h, c);
1683 ptr += buff_size[
i];
1686 cmd_special_free(h, c);
1690 for (i = 0; i < sg_used; i++)
1700 unsigned int cmd,
unsigned long arg)
1702 struct gendisk *disk = bdev->
bd_disk;
1706 dev_dbg(&h->
pdev->dev,
"cciss_ioctl: Called with cmd=%x %lx\n",
1710 return cciss_getpciinfo(h, argp);
1712 return cciss_getintinfo(h, argp);
1714 return cciss_setintinfo(h, argp);
1716 return cciss_getnodename(h, argp);
1718 return cciss_setnodename(h, argp);
1720 return cciss_getheartbeat(h, argp);
1722 return cciss_getbustypes(h, argp);
1724 return cciss_getfirmver(h, argp);
1726 return cciss_getdrivver(h, argp);
1730 return rebuild_lun_table(h, 0, 1);
1732 return cciss_getluninfo(h, disk, argp);
1734 return cciss_passthru(h, argp);
1736 return cciss_bigpassthru(h, argp);
1784 int curr_queue = (start_queue +
i) % (h->
highest_lun + 1);
1788 if (!h->
drv[curr_queue])
1790 if (!(h->
drv[curr_queue]->
queue) ||
1799 if (curr_queue == start_queue) {
1811 static void cciss_softirq_done(
struct request *
rq)
1817 unsigned long flags;
1830 cciss_unmap_sg_chain_block(h, c);
1835 temp64.
val32.lower = curr_sg[sg_index].
Addr.lower;
1836 temp64.
val32.upper = curr_sg[sg_index].
Addr.upper;
1837 pci_unmap_page(h->
pdev, temp64.
val, curr_sg[sg_index].
Len,
1845 if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
1852 cciss_check_queues(h);
1853 spin_unlock_irqrestore(&h->
lock, flags);
1856 static inline void log_unit_to_scsi3addr(
ctlr_info_t *h,
1857 unsigned char scsi3addr[],
uint32_t log_unit)
1867 static void cciss_get_device_descr(
ctlr_info_t *h,
int logvol,
1868 char *vendor,
char *model,
char *rev)
1872 unsigned char scsi3addr[8];
1882 log_unit_to_scsi3addr(h, scsi3addr, logvol);
1883 rc = sendcmd_withirq(h,
CISS_INQUIRY, inq_buf,
sizeof(*inq_buf), 0,
1903 static void cciss_get_serial_no(
ctlr_info_t *h,
int logvol,
1904 unsigned char *serial_no,
int buflen)
1906 #define PAGE_83_INQ_BYTES 64
1909 unsigned char scsi3addr[8];
1913 memset(serial_no, 0xff, buflen);
1914 buf = kzalloc(PAGE_83_INQ_BYTES,
GFP_KERNEL);
1917 memset(serial_no, 0, buflen);
1918 log_unit_to_scsi3addr(h, scsi3addr, logvol);
1920 PAGE_83_INQ_BYTES, 0x83, scsi3addr,
TYPE_CMD);
1922 memcpy(serial_no, &buf[8], buflen);
1930 static int cciss_add_disk(
ctlr_info_t *h,
struct gendisk *disk,
1935 goto init_queue_failure;
1936 sprintf(disk->disk_name,
"cciss/c%dd%d", h->
ctlr, drv_index);
1937 disk->major = h->
major;
1938 disk->first_minor = drv_index <<
NWD_SHIFT;
1939 disk->fops = &cciss_fops;
1940 if (cciss_create_ld_sysfs_entry(h, drv_index))
1942 disk->private_data = h->
drv[drv_index];
1943 disk->driverfs_dev = &h->
drv[drv_index]->
dev;
1955 disk->queue->queuedata =
h;
1964 h->
drv[drv_index]->
queue = disk->queue;
1985 static void cciss_update_drive_info(
ctlr_info_t *h,
int drv_index,
1986 int first_time,
int via_ioctl)
1988 struct gendisk *disk;
1992 unsigned long flags = 0;
1998 drvinfo = kzalloc(
sizeof(*drvinfo),
GFP_KERNEL);
1999 if (inq_buff ==
NULL || drvinfo ==
NULL)
2004 cciss_read_capacity_16(h, drv_index,
2005 &total_size, &block_size);
2008 cciss_read_capacity(h, drv_index, &total_size, &block_size);
2012 if (total_size == 0xFFFFFFFFULL) {
2013 cciss_read_capacity_16(h, drv_index,
2014 &total_size, &block_size);
2023 cciss_geometry_inquiry(h, drv_index, total_size, block_size,
2028 cciss_get_device_descr(h, drv_index, drvinfo->
vendor,
2030 cciss_get_serial_no(h, drv_index, drvinfo->
serial_no,
2034 sizeof(drvinfo->
LunID));
2054 if (h->
drv[drv_index]->
raid_level != -1 && drv_index != 0) {
2055 dev_warn(&h->
pdev->dev,
"disk %d has changed.\n", drv_index);
2058 spin_unlock_irqrestore(&h->
lock, flags);
2064 ret = deregister_disk(h, drv_index, 0, via_ioctl);
2075 if (h->
drv[drv_index] ==
NULL) {
2077 h->
drv[drv_index] = drvinfo;
2104 if (drv_index || first_time) {
2105 if (cciss_add_disk(h, disk, drv_index) != 0) {
2106 cciss_free_gendisk(h, drv_index);
2107 cciss_free_drive_info(h, drv_index);
2133 static int cciss_alloc_drive_info(
ctlr_info_t *h,
int controller_node)
2142 if (h->
drv[i] && i != 0)
2159 if (i == 0 && h->
drv[i] !=
NULL)
2176 static void cciss_free_drive_info(
ctlr_info_t *h,
int drv_index)
2182 static void cciss_free_gendisk(
ctlr_info_t *h,
int drv_index)
2197 static int cciss_add_gendisk(
ctlr_info_t *h,
unsigned char lunid[],
2198 int controller_node)
2202 drv_index = cciss_alloc_drive_info(h, controller_node);
2203 if (drv_index == -1)
2212 "could not allocate a new disk %d\n",
2214 goto err_free_drive_info;
2219 if (cciss_create_ld_sysfs_entry(h, drv_index))
2229 cciss_free_gendisk(h, drv_index);
2230 err_free_drive_info:
2231 cciss_free_drive_info(h, drv_index);
2240 static void cciss_add_controller_node(
ctlr_info_t *h)
2242 struct gendisk *disk;
2248 drv_index = cciss_add_gendisk(h,
CTLR_LUNID, 1);
2249 if (drv_index == -1)
2259 if (cciss_add_disk(h, disk, drv_index) == 0)
2261 cciss_free_gendisk(h, drv_index);
2262 cciss_free_drive_info(h, drv_index);
2276 static int rebuild_lun_table(
ctlr_info_t *h,
int first_time,
2287 unsigned long flags;
2295 spin_unlock_irqrestore(&h->
lock, flags);
2299 spin_unlock_irqrestore(&h->
lock, flags);
2302 if (ld_buff ==
NULL)
2309 if (return_code ==
IO_OK)
2313 "report logical volume command failed\n");
2318 num_luns = listlength / 8;
2319 if (num_luns > CISS_MAX_LUN) {
2322 " on controller than can be handled by"
2327 cciss_add_controller_node(h);
2342 for (j = 0; j < num_luns; j++) {
2343 memcpy(lunid, &ld_buff->
LUN[j][0],
sizeof(lunid));
2345 sizeof(lunid)) == 0) {
2354 spin_unlock_irqrestore(&h->
lock, flags);
2355 return_code = deregister_disk(h, i, 1, via_ioctl);
2366 for (i = 0; i < num_luns; i++) {
2371 memcpy(lunid, &ld_buff->
LUN[i][0],
sizeof(lunid));
2389 drv_index = cciss_add_gendisk(h, lunid, 0);
2390 if (drv_index == -1)
2393 cciss_update_drive_info(h, drv_index, first_time, via_ioctl);
2415 drive_info->
heads = 0;
2450 static int deregister_disk(
ctlr_info_t *h,
int drv_index,
2451 int clear_all,
int via_ioctl)
2454 struct gendisk *disk;
2456 int recalculate_highest_lun;
2461 drv = h->
drv[drv_index];
2465 if (clear_all || (h->
gendisk[0] == disk)) {
2479 if (disk->flags & GENHD_FL_UP) {
2480 cciss_destroy_ld_sysfs_entry(h, drv_index, 0);
2506 set_capacity(disk, 0);
2507 cciss_clear_drive_info(drv);
2513 if (clear_all && recalculate_highest_lun) {
2514 int newhighest = -1;
2549 if (page_code != 0) {
2614 dev_warn(&h->
pdev->dev,
"Unknown Command 0x%c\n", cmd);
2647 "unknown message type %d\n", cmd);
2651 dev_warn(&h->
pdev->dev,
"unknown command type %d\n", cmd_type);
2659 c->
SG[0].
Addr.lower = buff_dma_handle.
val32.lower;
2660 c->
SG[0].
Addr.upper = buff_dma_handle.
val32.upper;
2679 if (return_status !=
IO_OK) {
2680 cmd_special_free(h, c);
2681 return return_status;
2684 enqueue_cmd_and_start_io(h, c);
2699 case 0:
return IO_OK;
2700 case 1:
return IO_OK;
2702 if (check_for_unit_attention(h, c))
2705 "check condition, sense key = 0x%02x\n",
2711 "scsi status = 0x%02x\n",
2720 int return_status =
IO_OK;
2727 return_status = check_target_status(h, c);
2778 return return_status;
2786 int return_status =
IO_OK;
2790 enqueue_cmd_and_start_io(h, c);
2797 return_status = process_sendcmd_error(h, c);
2806 return_status =
IO_OK;
2813 buff_dma_handle.
val32.lower = c->
SG[0].
Addr.lower;
2814 buff_dma_handle.
val32.upper = c->
SG[0].
Addr.upper;
2817 return return_status;
2820 static int sendcmd_withirq(
ctlr_info_t *h,
__u8 cmd,
void *buff,
size_t size,
2821 __u8 page_code,
unsigned char scsi3addr[],
2827 c = cmd_special_alloc(h);
2830 return_status = fill_cmd(h, c, cmd, buff, size, page_code,
2831 scsi3addr, cmd_type);
2832 if (return_status ==
IO_OK)
2833 return_status = sendcmd_withirq_core(h, c, 1);
2835 cmd_special_free(h, c);
2836 return return_status;
2839 static void cciss_geometry_inquiry(
ctlr_info_t *h,
int logvol,
2841 unsigned int block_size,
2847 unsigned char scsi3addr[8];
2850 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2851 return_code = sendcmd_withirq(h,
CISS_INQUIRY, inq_buff,
2852 sizeof(*inq_buff), 0xC1, scsi3addr,
TYPE_CMD);
2853 if (return_code ==
IO_OK) {
2856 "reading geometry failed, volume "
2857 "does not support reading geometry\n");
2873 sector_t real_size = total_size + 1;
2874 unsigned long rem =
sector_div(real_size, t);
2886 unsigned int *block_size)
2890 unsigned char scsi3addr[8];
2898 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2901 if (return_code ==
IO_OK) {
2912 static void cciss_read_capacity_16(
ctlr_info_t *h,
int logvol,
2913 sector_t *total_size,
unsigned int *block_size)
2917 unsigned char scsi3addr[8];
2925 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2929 if (return_code ==
IO_OK) {
2937 dev_info(&h->
pdev->dev,
" blocks= %llu block_size= %d\n",
2938 (
unsigned long long)*total_size+1, *block_size);
2942 static int cciss_revalidate(
struct gendisk *disk)
2952 for (logvol = 0; logvol <= h->
highest_lun; logvol++) {
2953 if (!h->
drv[logvol])
2956 sizeof(drv->
LunID)) == 0) {
2966 if (inq_buff ==
NULL) {
2971 cciss_read_capacity(h, logvol,
2972 &total_size, &block_size);
2974 cciss_read_capacity_16(h, logvol,
2975 &total_size, &block_size);
2977 cciss_geometry_inquiry(h, logvol, total_size, block_size,
2993 ulong page_offs = ((
ulong) base) - page_base;
2994 void __iomem *page_remapped =
ioremap(page_base, page_offs + size);
2996 return page_remapped ? (page_remapped + page_offs) :
NULL;
3007 while (!list_empty(&h->
reqQ)) {
3010 if ((h->
access.fifo_full(h))) {
3020 h->
access.submit_command(h, c);
3044 static inline unsigned int make_status_bytes(
unsigned int scsi_status_byte,
3049 return (scsi_status_byte & 0xff) |
3050 ((msg_byte & 0xff) << 8) |
3051 ((host_byte & 0xff) << 16) |
3052 ((driver_byte & 0xff) << 24);
3055 static inline int evaluate_target_status(
ctlr_info_t *h,
3068 if (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC)
3073 error_value = make_status_bytes(status_byte, msg_byte,
3074 host_byte, driver_byte);
3077 if (cmd->
rq->cmd_type != REQ_TYPE_BLOCK_PC)
3079 "has SCSI Status 0x%x\n",
3087 if (((sense_key == 0x0) || (sense_key == 0x1)) &&
3088 (cmd->
rq->cmd_type != REQ_TYPE_BLOCK_PC))
3091 if (check_for_unit_attention(h, cmd)) {
3092 *retry_cmd = !(cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC);
3097 if (cmd->
rq->cmd_type != REQ_TYPE_BLOCK_PC) {
3098 if (error_value != 0)
3100 " sense key = 0x%x\n", cmd, sense_key);
3105 if (cmd->
rq->sense) {
3109 cmd->
rq->sense_len);
3111 cmd->
rq->sense_len = 0;
3132 goto after_error_processing;
3136 rq->errors = evaluate_target_status(h, cmd, &retry_cmd);
3139 if (cmd->
rq->cmd_type == REQ_TYPE_FS) {
3141 " completed with data underrun "
3147 if (cmd->
rq->cmd_type == REQ_TYPE_FS)
3149 " completed with data overrun "
3154 "reported invalid\n", cmd);
3157 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3162 "protocol error\n", cmd);
3165 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3170 " hardware error\n", cmd);
3173 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3178 "connection lost\n", cmd);
3181 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3189 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3194 "abort failed\n", cmd);
3197 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3202 "abort %p\n", h->
ctlr, cmd);
3209 "%p retried too many times\n", cmd);
3212 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3219 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3226 cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC ?
3231 "unknown status %x\n", cmd,
3235 (cmd->
rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3239 after_error_processing:
3243 resend_cciss_cmd(h, cmd);
3246 cmd->
rq->completion_data =
cmd;
3250 static inline u32 cciss_tag_contains_index(
u32 tag)
3252 #define DIRECT_LOOKUP_BIT 0x10
3256 static inline u32 cciss_tag_to_index(
u32 tag)
3258 #define DIRECT_LOOKUP_SHIFT 5
3264 #define CCISS_PERF_ERROR_BITS ((1 << DIRECT_LOOKUP_SHIFT) - 1)
3265 #define CCISS_SIMPLE_ERROR_BITS 0x03
3271 static inline void cciss_mark_tag_indexed(
u32 *tag)
3276 static inline void cciss_set_tag_index(
u32 *tag,
u32 index)
3313 spin_unlock_irq(q->queue_lock);
3319 drv = creq->rq_disk->private_data;
3325 cciss_mark_tag_indexed(&c->
Header.
Tag.lower);
3335 start_blk = blk_rq_pos(creq);
3336 dev_dbg(&h->
pdev->dev,
"sector =%d nr_sectors=%d\n",
3337 (
int)blk_rq_pos(creq), (
int)blk_rq_sectors(creq));
3351 for (i = 0; i <
seg; i++) {
3353 !chained && ((seg - i) > 1)) {
3360 temp64.
val = (
__u64) pci_map_page(h->
pdev, sg_page(&tmp_sg[i]),
3363 curr_sg[sg_index].
Addr.lower = temp64.
val32.lower;
3364 curr_sg[sg_index].
Addr.upper = temp64.
val32.upper;
3365 curr_sg[sg_index].
Ext = 0;
3377 dev_dbg(&h->
pdev->dev,
"Submitting %u sectors in %d segments "
3379 blk_rq_sectors(creq), seg, chained);
3382 if (seg <= h->max_cmd_sgentries)
3386 set_performant_mode(h, c);
3388 if (
likely(creq->cmd_type == REQ_TYPE_FS)) {
3391 c->
Request.
CDB[2] = (start_blk >> 24) & 0xff;
3392 c->
Request.
CDB[3] = (start_blk >> 16) & 0xff;
3396 c->
Request.
CDB[7] = (blk_rq_sectors(creq) >> 8) & 0xff;
3397 c->
Request.
CDB[8] = blk_rq_sectors(creq) & 0xff;
3412 c->
Request.
CDB[10]= (blk_rq_sectors(creq) >> 24) & 0xff;
3413 c->
Request.
CDB[11]= (blk_rq_sectors(creq) >> 16) & 0xff;
3414 c->
Request.
CDB[12]= (blk_rq_sectors(creq) >> 8) & 0xff;
3415 c->
Request.
CDB[13]= blk_rq_sectors(creq) & 0xff;
3418 }
else if (creq->cmd_type == REQ_TYPE_BLOCK_PC) {
3427 spin_lock_irq(q->queue_lock);
3444 static inline unsigned long get_next_completion(
ctlr_info_t *h)
3446 return h->
access.command_completed(h);
3449 static inline int interrupt_pending(
ctlr_info_t *h)
3451 return h->
access.intr_pending(h);
3454 static inline long interrupt_not_for_us(
ctlr_info_t *h)
3456 return ((h->
access.intr_pending(h) == 0) ||
3464 dev_warn(&h->
pdev->dev,
"bad tag 0x%08x ignored.\n", raw_tag);
3475 complete_command(h, c, 0);
3478 #ifdef CONFIG_CISS_SCSI_TAPE
3480 complete_scsi_command(c, 0, raw_tag);
3489 return h->
access.command_completed(h);
3512 tag_index = cciss_tag_to_index(raw_tag);
3513 if (bad_tag(h, tag_index, raw_tag))
3514 return next_command(h);
3516 finish_cmd(h, c, raw_tag);
3517 return next_command(h);
3524 __u32 busaddr_masked, tag_masked;
3526 tag_masked = cciss_tag_discard_error_bits(h, raw_tag);
3528 busaddr_masked = cciss_tag_discard_error_bits(h, c->
busaddr);
3529 if (busaddr_masked == tag_masked) {
3530 finish_cmd(h, c, raw_tag);
3531 return next_command(h);
3534 bad_tag(h, h->
nr_cmds + 1, raw_tag);
3535 return next_command(h);
3551 dev_info(&h->
pdev->dev,
"Received interrupt while interrupts disabled "
3552 "(known firmware bug.) Ignoring.\n");
3560 unsigned long flags;
3563 if (ignore_bogus_interrupt(h))
3566 if (interrupt_not_for_us(h))
3569 while (interrupt_pending(h)) {
3570 raw_tag = get_next_completion(h);
3572 raw_tag = next_command(h);
3574 spin_unlock_irqrestore(&h->
lock, flags);
3578 static irqreturn_t cciss_msix_discard_completions(
int irq,
void *dev_id)
3581 unsigned long flags;
3584 if (ignore_bogus_interrupt(h))
3588 raw_tag = get_next_completion(h);
3590 raw_tag = next_command(h);
3591 spin_unlock_irqrestore(&h->
lock, flags);
3595 static irqreturn_t do_cciss_intx(
int irq,
void *dev_id)
3598 unsigned long flags;
3601 if (interrupt_not_for_us(h))
3604 while (interrupt_pending(h)) {
3605 raw_tag = get_next_completion(h);
3607 if (cciss_tag_contains_index(raw_tag))
3608 raw_tag = process_indexed_cmd(h, raw_tag);
3610 raw_tag = process_nonindexed_cmd(h, raw_tag);
3613 spin_unlock_irqrestore(&h->
lock, flags);
3620 static irqreturn_t do_cciss_msix_intr(
int irq,
void *dev_id)
3623 unsigned long flags;
3627 raw_tag = get_next_completion(h);
3629 if (cciss_tag_contains_index(raw_tag))
3630 raw_tag = process_indexed_cmd(h, raw_tag);
3632 raw_tag = process_nonindexed_cmd(h, raw_tag);
3634 spin_unlock_irqrestore(&h->
lock, flags);
3648 static int add_to_scan_list(
struct ctlr_info *h)
3691 static void remove_from_scan_list(
struct ctlr_info *h)
3724 static int scan_thread(
void *
data)
3736 if (list_empty(&scan_q)) {
3748 rebuild_lun_table(h, 0, 0);
3767 "detected, command retried\n");
3772 "detected, action required\n");
3797 "a power on or device reset detected\n");
3802 "unit attention cleared by another initiator\n");
3806 dev_warn(&h->
pdev->dev,
"unknown unit attention detected\n");
3822 dev_dbg(&h->
pdev->dev,
"Controller Configuration information\n");
3823 dev_dbg(&h->
pdev->dev,
"------------------------------------\n");
3824 for (i = 0; i < 4; i++)
3826 temp_name[4] =
'\0';
3827 dev_dbg(&h->
pdev->dev,
" Signature = %s\n", temp_name);
3830 dev_dbg(&h->
pdev->dev,
" Transport methods supported = 0x%x\n",
3832 dev_dbg(&h->
pdev->dev,
" Transport methods active = 0x%x\n",
3834 dev_dbg(&h->
pdev->dev,
" Requested transport Method = 0x%x\n",
3836 dev_dbg(&h->
pdev->dev,
" Coalesce Interrupt Delay = 0x%x\n",
3838 dev_dbg(&h->
pdev->dev,
" Coalesce Interrupt Count = 0x%x\n",
3840 dev_dbg(&h->
pdev->dev,
" Max outstanding commands = 0x%d\n",
3844 for (i = 0; i < 16; i++)
3846 temp_name[16] =
'\0';
3847 dev_dbg(&h->
pdev->dev,
" Server Name = %s\n", temp_name);
3848 dev_dbg(&h->
pdev->dev,
" Heartbeat Counter = 0x%x\n\n\n",
3852 static int find_PCI_BAR_index(
struct pci_dev *
pdev,
unsigned long pci_bar_addr)
3875 "Base address is invalid\n");
3898 static void calc_bucket_map(
int bucket[],
int num_buckets,
3899 int nsgs,
int *bucket_map)
3904 #define MINIMUM_TRANSFER_BLOCKS 4
3905 #define NUM_BUCKETS 8
3907 for (i = 0; i <= nsgs; i++) {
3912 for (j = 0; j < 8; j++) {
3913 if (bucket[j] >= size) {
3958 int bft[8] = { 5, 6, 8, 10, 12, 20, 28,
MAXSGENTRIES + 4};
3965 unsigned long register_value;
3997 cciss_wait_for_mode_change_ack(h);
4000 dev_warn(&h->
pdev->dev,
"cciss: unable to get board into"
4001 " performant mode\n");
4008 if (cciss_simple_mode)
4011 dev_dbg(&h->
pdev->dev,
"Trying to put board into Performant mode\n");
4018 dev_dbg(&h->
pdev->dev,
"Placing controller into performant mode\n");
4025 "cciss info: command size[",
4027 "] not divisible by 32, no performant mode..\n");
4043 cciss_enter_performant_mode(h,
4047 h->
access = SA5_performant_access;
4068 #ifdef CONFIG_PCI_MSI
4070 struct msix_entry cciss_msix_entries[4] = { {0, 0}, {0, 1},
4077 goto default_int_mode;
4082 h->
intr[0] = cciss_msix_entries[0].vector;
4083 h->
intr[1] = cciss_msix_entries[1].vector;
4084 h->
intr[2] = cciss_msix_entries[2].vector;
4085 h->
intr[3] = cciss_msix_entries[3].vector;
4091 "only %d MSI-X vectors available\n", err);
4092 goto default_int_mode;
4095 "MSI-X init failed %d\n", err);
4096 goto default_int_mode;
4100 if (!pci_enable_msi(h->
pdev))
4115 u32 subsystem_vendor_id, subsystem_device_id;
4119 *board_id = ((subsystem_device_id << 16) & 0xffff0000) |
4120 subsystem_vendor_id;
4123 if (*board_id == products[i].board_id)
4125 dev_warn(&pdev->
dev,
"unrecognized board ID: 0x%08x, ignoring.\n",
4130 static inline bool cciss_board_disabled(
ctlr_info_t *h)
4139 unsigned long *memory_bar)
4157 #define BOARD_READY 1
4158 #define BOARD_NOT_READY 0
4168 for (i = 0; i < iterations; i++) {
4170 if (wait_for_ready) {
4179 dev_warn(&pdev->
dev,
"board not ready, timed out.\n");
4184 void __iomem *vaddr,
u32 *cfg_base_addr,
u64 *cfg_base_addr_index,
4189 *cfg_base_addr &= (
u32) 0x0000ffff;
4190 *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr);
4191 if (*cfg_base_addr_index == -1) {
4192 dev_warn(&pdev->
dev,
"cannot find cfg_base_addr_index, "
4193 "*cfg_base_addr = 0x%08x\n", *cfg_base_addr);
4203 u64 cfg_base_addr_index;
4207 rc = cciss_find_cfg_addrs(h->
pdev, h->
vaddr, &cfg_base_addr,
4208 &cfg_base_addr_index, &cfg_offset);
4212 cfg_base_addr_index) + cfg_offset,
sizeof(h->
cfgtable));
4215 rc = write_driver_ver_to_cfgtable(h->
cfgtable);
4221 cfg_base_addr_index)+cfg_offset+trans_offset,
4238 "max supported commands of %d, an obvious lie. "
4239 "Using 16. Ensure that firmware is up to date.\n",
4251 cciss_get_max_perf_mode_cmds(h);
4269 static inline bool CISS_signature_present(
ctlr_info_t *h)
4275 dev_warn(&h->
pdev->dev,
"not a valid CISS config table\n");
4282 static inline void cciss_enable_scsi_prefetch(
ctlr_info_t *h)
4296 static inline void cciss_p600_dma_prefetch_quirk(
ctlr_info_t *h)
4304 dma_prefetch |= 0x8000;
4313 int prod_index,
err;
4315 prod_index = cciss_lookup_board_id(h->
pdev, &h->
board_id);
4321 if (cciss_board_disabled(h)) {
4322 dev_warn(&h->
pdev->dev,
"controller appears to be disabled\n");
4331 dev_warn(&h->
pdev->dev,
"Unable to Enable PCI device\n");
4338 "Cannot obtain PCI resources, aborting\n");
4348 cciss_interrupt_mode(h);
4349 err = cciss_pci_find_memory_BAR(h->
pdev, &h->
paddr);
4351 goto err_out_free_res;
4355 goto err_out_free_res;
4357 err = cciss_wait_for_board_state(h->
pdev, h->
vaddr, BOARD_READY);
4359 goto err_out_free_res;
4360 err = cciss_find_cfgtables(h);
4362 goto err_out_free_res;
4364 cciss_find_board_params(h);
4366 if (!CISS_signature_present(h)) {
4368 goto err_out_free_res;
4370 cciss_enable_scsi_prefetch(h);
4371 cciss_p600_dma_prefetch_quirk(h);
4372 err = cciss_enter_simple_mode(h);
4374 goto err_out_free_res;
4375 cciss_put_controller_into_performant_mode(h);
4396 static int alloc_cciss_hba(
struct pci_dev *pdev)
4411 dev_warn(&pdev->
dev,
"This driver supports a maximum"
4412 " of %d controllers.\n", MAX_CTLR);
4452 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
4469 cmd->CommandHeader.ReplyQueue = 0;
4470 cmd->CommandHeader.SGList = 0;
4471 cmd->CommandHeader.SGTotal = 0;
4472 cmd->CommandHeader.Tag.lower = paddr32;
4473 cmd->CommandHeader.Tag.upper = 0;
4474 memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8);
4476 cmd->Request.CDBLen = 16;
4479 cmd->Request.Type.Direction =
XFER_NONE;
4480 cmd->Request.Timeout = 0;
4481 cmd->Request.CDB[0] =
opcode;
4482 cmd->Request.CDB[1] =
type;
4483 memset(&cmd->Request.CDB[2], 0, 14);
4485 cmd->ErrorDescriptor.Addr.lower = paddr32 +
sizeof(
Command);
4486 cmd->ErrorDescriptor.Addr.upper = 0;
4491 for (i = 0; i < 10; i++) {
4493 if ((tag & ~3) == paddr32)
4504 "controller message %02x:%02x timed out\n",
4512 dev_err(&pdev->
dev,
"controller message %02x:%02x failed\n",
4517 dev_info(&pdev->
dev,
"controller message %02x:%02x succeeded\n",
4522 #define cciss_noop(p) cciss_message(p, 3, 0)
4524 static int cciss_controller_hard_reset(
struct pci_dev *pdev,
4535 dev_info(&pdev->
dev,
"using doorbell to reset controller\n");
4550 "cciss_controller_hard_reset: "
4551 "PCI PM not supported\n");
4554 dev_info(&pdev->
dev,
"using PCI PM to reset controller\n");
4556 pci_read_config_word(pdev, pos +
PCI_PM_CTRL, &pmcsr);
4559 pci_write_config_word(pdev, pos +
PCI_PM_CTRL, pmcsr);
4566 pci_write_config_word(pdev, pos +
PCI_PM_CTRL, pmcsr);
4578 static __devinit void init_driver_version(
char *driver_version,
int len)
4580 memset(driver_version, 0, len);
4584 static __devinit int write_driver_ver_to_cfgtable(
4588 int i, size =
sizeof(cfgtable->driver_version);
4591 if (!driver_version)
4594 init_driver_version(driver_version, size);
4595 for (i = 0; i <
size; i++)
4596 writeb(driver_version[i], &cfgtable->driver_version[i]);
4597 kfree(driver_version);
4601 static __devinit void read_driver_ver_from_cfgtable(
4606 for (i = 0; i <
sizeof(cfgtable->driver_version); i++)
4607 driver_ver[i] =
readb(&cfgtable->driver_version[i]);
4610 static __devinit int controller_reset_failed(
4615 int rc, size =
sizeof(cfgtable->driver_version);
4618 if (!old_driver_ver)
4620 driver_ver = old_driver_ver +
size;
4625 init_driver_version(old_driver_ver, size);
4626 read_driver_ver_from_cfgtable(cfgtable, driver_ver);
4627 rc = !
memcmp(driver_ver, old_driver_ver, size);
4628 kfree(old_driver_ver);
4634 static __devinit int cciss_kdump_hard_reset_controller(
struct pci_dev *pdev)
4638 u64 cfg_base_addr_index;
4640 unsigned long paddr;
4641 u32 misc_fw_support;
4646 u16 command_register;
4667 cciss_lookup_board_id(pdev, &board_id);
4668 if (!ctlr_is_resettable(board_id)) {
4669 dev_warn(&pdev->
dev,
"Cannot reset Smart Array 640x "
4670 "due to shared cache module.");
4675 if (!ctlr_is_hard_resettable(board_id))
4679 pci_read_config_word(pdev, 4, &command_register);
4687 rc = cciss_pci_find_memory_BAR(pdev, &paddr);
4690 vaddr = remap_pci_mem(paddr, 0x250);
4695 rc = cciss_find_cfg_addrs(pdev, vaddr, &cfg_base_addr,
4696 &cfg_base_addr_index, &cfg_offset);
4700 cfg_base_addr_index) + cfg_offset,
sizeof(*cfgtable));
4705 rc = write_driver_ver_to_cfgtable(cfgtable);
4712 misc_fw_support =
readl(&cfgtable->misc_fw_support);
4720 "'Bit 2 doorbell reset' is "
4721 "supported, but not 'bit 5 doorbell reset'. "
4722 "Firmware update is recommended.\n");
4724 goto unmap_cfgtable;
4728 rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell);
4730 goto unmap_cfgtable;
4734 dev_warn(&pdev->
dev,
"failed to enable device.\n");
4735 goto unmap_cfgtable;
4737 pci_write_config_word(pdev, 4, command_register);
4744 dev_info(&pdev->
dev,
"Waiting for board to reset.\n");
4745 rc = cciss_wait_for_board_state(pdev, vaddr, BOARD_NOT_READY);
4747 dev_warn(&pdev->
dev,
"Failed waiting for board to hard reset."
4748 " Will try soft reset.\n");
4750 goto unmap_cfgtable;
4752 rc = cciss_wait_for_board_state(pdev, vaddr, BOARD_READY);
4755 "failed waiting for board to become ready "
4756 "after hard reset\n");
4757 goto unmap_cfgtable;
4760 rc = controller_reset_failed(vaddr);
4762 goto unmap_cfgtable;
4764 dev_warn(&pdev->
dev,
"Unable to successfully hard reset "
4765 "controller. Will try soft reset.\n");
4768 dev_info(&pdev->
dev,
"Board ready after hard reset.\n");
4787 rc = cciss_kdump_hard_reset_controller(pdev);
4800 dev_warn(&pdev->
dev,
"Waiting for controller to respond to no-op\n");
4806 (i < CCISS_POST_RESET_NOOP_RETRIES - 1 ?
4807 "; re-trying" :
""));
4843 for (i = 0; i < h->
nr_cmds; i++) {
4855 static void cciss_free_scatterlists(
ctlr_info_t *h)
4860 for (i = 0; i < h->
nr_cmds; i++)
4896 dev_err(&h->
pdev->dev,
"Unable to get irq %d for %s\n",
4904 dev_warn(&h->
pdev->dev,
"Resetting array controller failed.\n");
4908 dev_info(&h->
pdev->dev,
"Waiting for board to soft reset.\n");
4909 if (cciss_wait_for_board_state(h->
pdev, h->
vaddr, BOARD_NOT_READY)) {
4910 dev_warn(&h->
pdev->dev,
"Soft reset had no effect.\n");
4914 dev_info(&h->
pdev->dev,
"Board reset, awaiting READY status.\n");
4915 if (cciss_wait_for_board_state(h->
pdev, h->
vaddr, BOARD_READY)) {
4916 dev_warn(&h->
pdev->dev,
"Board failed to become ready "
4917 "after soft reset.\n");
4924 static void cciss_undo_allocations_after_kdump_soft_reset(
ctlr_info_t *h)
4929 #ifdef CONFIG_PCI_MSI
4936 cciss_free_scatterlists(h);
4937 cciss_free_cmd_pool(h);
4949 cciss_destroy_hba_sysfs_entry(h);
4966 int try_soft_reset = 0;
4970 unsigned long flags;
4972 rc = cciss_init_reset_devices(pdev);
4985 reinit_after_soft_reset:
4987 i = alloc_cciss_hba(pdev);
4995 INIT_LIST_HEAD(&h->
cmpQ);
4996 INIT_LIST_HEAD(&h->
reqQ);
4999 if (cciss_pci_init(h) != 0)
5000 goto clean_no_release_regions;
5005 if (cciss_tape_cmds < 2)
5006 cciss_tape_cmds = 2;
5007 if (cciss_tape_cmds > 16)
5008 cciss_tape_cmds = 16;
5012 if (cciss_create_hba_sysfs_entry(h))
5021 dev_err(&h->
pdev->dev,
"no suitable DMA available\n");
5035 "Unable to get major number %d for %s "
5045 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
5049 dev_info(&h->
pdev->dev,
"%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
5053 if (cciss_allocate_cmd_pool(h))
5056 if (cciss_allocate_scatterlists(h))
5059 h->
cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
5068 pci_set_drvdata(pdev, h);
5073 *
sizeof(
unsigned long));
5086 if (try_soft_reset) {
5097 spin_unlock_irqrestore(&h->
lock, flags);
5099 rc = cciss_request_irq(h, cciss_msix_discard_completions,
5100 cciss_intx_discard_completions);
5107 rc = cciss_kdump_soft_reset(h);
5115 "Waiting for stale completions to drain.\n");
5120 rc = controller_reset_failed(h->
cfgtable);
5123 "Soft reset appears to have failed.\n");
5129 cciss_undo_allocations_after_kdump_soft_reset(h);
5135 goto reinit_after_soft_reset;
5145 if (inq_buff ==
NULL) {
5150 return_code = sendcmd_withirq(h,
CISS_INQUIRY, inq_buff,
5152 if (return_code ==
IO_OK) {
5159 " version of controller\n");
5167 rebuild_lun_table(h, 1, 0);
5173 cciss_free_cmd_pool(h);
5174 cciss_free_scatterlists(h);
5180 cciss_destroy_hba_sysfs_entry(h);
5183 clean_no_release_regions:
5190 pci_set_drvdata(pdev,
NULL);
5195 static void cciss_shutdown(
struct pci_dev *pdev)
5201 h = pci_get_drvdata(pdev);
5204 dev_warn(&h->
pdev->dev,
"cache not flushed, out of memory.\n");
5211 if (return_code !=
IO_OK)
5228 cciss_wait_for_mode_change_ack(h);
5231 dev_warn(&h->
pdev->dev,
"unable to get board into simple mode\n");
5244 if (pci_get_drvdata(pdev) ==
NULL) {
5245 dev_err(&pdev->
dev,
"Unable to remove device\n");
5249 h = pci_get_drvdata(pdev);
5251 if (hba[i] ==
NULL) {
5252 dev_err(&pdev->
dev,
"device appears to already be removed\n");
5258 remove_from_scan_list(h);
5264 struct gendisk *disk = h->
gendisk[
j];
5268 if (disk->flags & GENHD_FL_UP) {
5269 cciss_destroy_ld_sysfs_entry(h, j, 1);
5277 #ifdef CONFIG_CISS_SCSI_TAPE
5278 cciss_unregister_scsi(h);
5281 cciss_shutdown(pdev);
5283 #ifdef CONFIG_PCI_MSI
5294 cciss_free_cmd_pool(h);
5296 for (j = 0; j < h->
nr_cmds; j++)
5309 pci_set_drvdata(pdev,
NULL);
5310 cciss_destroy_hba_sysfs_entry(h);
5315 static struct pci_driver cciss_pci_driver = {
5317 .probe = cciss_init_one,
5319 .id_table = cciss_pci_device_id,
5320 .shutdown = cciss_shutdown,
5327 static int __init cciss_init(
void)
5345 if (IS_ERR(cciss_scan_thread)) {
5346 err = PTR_ERR(cciss_scan_thread);
5347 goto err_bus_unregister;
5351 err = pci_register_driver(&cciss_pci_driver);
5353 goto err_thread_stop;
5365 static void __exit cciss_cleanup(
void)
5372 if (hba[i] !=
NULL) {
5374 "had to remove controller\n");
5375 cciss_remove_one(hba[i]->pdev);