1 diff -uNr linux-2.6.16.orig/Documentation/cciss.txt linux-2.6.16/Documentation/cciss.txt
2 --- linux-2.6.16.orig/Documentation/cciss.txt 2006-03-20 06:53:29.000000000 +0100
3 +++ linux-2.6.16/Documentation/cciss.txt 2008-10-03 02:40:19.000000000 +0200
15 +This driver also implements a new method of detecting HP Smart Array
16 +controllers. If an "unknown" controller is detected, we will attempt to
17 +bind to the controller. On success a message is displayed informing the
18 +user to upgrade the driver. On failure we bail.
20 If nodes are not already created in the /dev/cciss directory, run as root:
34 the SCSI core may not yet be initialized (because the driver is a block
35 driver) and attempting to register it with the SCSI core in such a case
36 would cause a hang. This is best done via an initialization script
37 -(typically in /etc/init.d, but could vary depending on distibution).
38 +(typically in /etc/init.d, but could vary depending on distribution).
41 for x in /proc/driver/cciss/cciss[0-9]*
43 If that doesn't work, the SCSI bus is reset. If that doesn't work
44 the host bus adapter is reset. Because the cciss driver is a block
45 driver as well as a SCSI driver and only the tape drives and medium
46 -changers are presented to the SCSI mid layer, and unlike more
47 +changers are presented to the SCSI mid layer, and unlike more
48 straightforward SCSI drivers, disk i/o continues through the block
49 side during the SCSI error recovery process, the cciss driver only
50 implements the first two of these actions, aborting the command, and
51 -resetting the device. Additionally, most tape drives will not oblige
52 -in aborting commands, and sometimes it appears they will not even
53 -obey a reset coommand, though in most circumstances they will. In
54 -the case that the command cannot be aborted and the device cannot be
55 +resetting the device. Additionally, most tape drives will not oblige
56 +in aborting commands, and sometimes it appears they will not even
57 +obey a reset command, though in most circumstances they will. In
58 +the case that the command cannot be aborted and the device cannot be
59 reset, the device will be set offline.
61 In the event the error handling code is triggered and a tape drive is
62 -successfully reset or the tardy command is successfully aborted, the
63 +successfully reset or the tardy command is successfully aborted, the
64 tape drive may still not allow i/o to continue until some command
65 is issued which positions the tape to a known position. Typically you
66 must rewind the tape (by issuing "mt -f /dev/st0 rewind" for example)
67 diff -uNr linux-2.6.16.orig/drivers/block/cciss.c linux-2.6.16/drivers/block/cciss.c
68 --- linux-2.6.16.orig/drivers/block/cciss.c 2008-11-02 19:51:53.000000000 +0100
69 +++ linux-2.6.16/drivers/block/cciss.c 2008-10-03 02:40:19.000000000 +0200
71 #include <linux/bio.h>
72 #include <linux/blkpg.h>
73 #include <linux/timer.h>
74 +#include <linux/seq_file.h>
75 #include <linux/proc_fs.h>
76 #include <linux/init.h>
77 #include <linux/hdreg.h>
79 #include <linux/compat.h>
80 #include <asm/uaccess.h>
82 +#include <asm/div64.h>
84 +#ifdef CONFIG_BLK_DEV_IO_TRACE
85 +#include <linux/blktrace_api.h>
88 #include <linux/dma-mapping.h>
89 #include <linux/blkdev.h>
90 #include <linux/genhd.h>
91 #include <linux/completion.h>
92 +#include <scsi/scsi.h>
94 +#include <scsi/scsi_ioctl.h>
95 +#include <linux/cdrom.h>
97 #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
98 -#define DRIVER_NAME "HP CISS Driver (v 2.6.10)"
99 -#define DRIVER_VERSION CCISS_DRIVER_VERSION(2,6,10)
100 +#define DRIVER_NAME "HP CISS Driver (v 3.6.18)"
101 +#define DRIVER_VERSION CCISS_DRIVER_VERSION(3,6,18)
103 /* Embedded module documentation macros - see modules.h */
104 MODULE_AUTHOR("Hewlett-Packard Company");
105 -MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.10");
106 +MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 3.6.18");
107 MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
108 - " SA6i P600 P800 P400 P400i E200 E200i");
109 + " SA6i P600 P800 P400 P400i E200 E200i E500");
110 MODULE_LICENSE("GPL");
112 #include "cciss_cmd.h"
114 #include <linux/cciss_ioctl.h>
116 +#ifndef PCI_DEVICE_ID_COMPAQ_CISSC
117 +#define PCI_DEVICE_ID_COMPAQ_CISSC 0x46
119 +#ifndef PCI_DEVICE_ID_HP_CISS
120 +#define PCI_DEVICE_ID_HP_CISS 0x3210
122 +#ifndef PCI_DEVICE_ID_HP_CISSA
123 +#define PCI_DEVICE_ID_HP_CISSA 0x3220
125 +#ifndef PCI_DEVICE_ID_HP_CISSC
126 +#define PCI_DEVICE_ID_HP_CISSC 0x3230
128 +#ifndef PCI_DEVICE_ID_HP_CISSD
129 +#define PCI_DEVICE_ID_HP_CISSD 0x3238
131 /* define the PCI info for the cards we can control */
132 static const struct pci_device_id cciss_pci_device_id[] = {
133 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISS,
134 - 0x0E11, 0x4070, 0, 0, 0},
135 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
136 - 0x0E11, 0x4080, 0, 0, 0},
137 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
138 - 0x0E11, 0x4082, 0, 0, 0},
139 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
140 - 0x0E11, 0x4083, 0, 0, 0},
141 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
142 - 0x0E11, 0x409A, 0, 0, 0},
143 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
144 - 0x0E11, 0x409B, 0, 0, 0},
145 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
146 - 0x0E11, 0x409C, 0, 0, 0},
147 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
148 - 0x0E11, 0x409D, 0, 0, 0},
149 - { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
150 - 0x0E11, 0x4091, 0, 0, 0},
151 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSA,
152 - 0x103C, 0x3225, 0, 0, 0},
153 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
154 - 0x103c, 0x3223, 0, 0, 0},
155 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
156 - 0x103c, 0x3234, 0, 0, 0},
157 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
158 - 0x103c, 0x3235, 0, 0, 0},
159 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
160 - 0x103c, 0x3211, 0, 0, 0},
161 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
162 - 0x103c, 0x3212, 0, 0, 0},
163 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
164 - 0x103c, 0x3213, 0, 0, 0},
165 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
166 - 0x103c, 0x3214, 0, 0, 0},
167 - { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
168 - 0x103c, 0x3215, 0, 0, 0},
169 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISS, 0x0E11, 0x4070},
170 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4080},
171 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4082},
172 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4083},
173 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409A},
174 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409B},
175 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409C},
176 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409D},
177 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x4091},
178 + {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409E},
179 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSA, 0x103C, 0x3225},
180 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103c, 0x3234},
181 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103c, 0x3235},
182 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103c, 0x3211},
183 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103c, 0x3212},
184 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103c, 0x3213},
185 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103c, 0x3214},
186 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103c, 0x3215},
187 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3223},
188 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103c, 0x3237},
189 + {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x323D},
190 + {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
191 + PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0},
194 MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
196 -#define NR_PRODUCTS ARRAY_SIZE(products)
198 /* board_id = Subsystem Device ID & Vendor ID
199 * product = Marketing Name for the board
200 * access = Address of the struct of function pointers
201 + * nr_cmds = Number of commands supported by controller
203 static struct board_type products[] = {
204 - { 0x40700E11, "Smart Array 5300", &SA5_access },
205 - { 0x40800E11, "Smart Array 5i", &SA5B_access},
206 - { 0x40820E11, "Smart Array 532", &SA5B_access},
207 - { 0x40830E11, "Smart Array 5312", &SA5B_access},
208 - { 0x409A0E11, "Smart Array 641", &SA5_access},
209 - { 0x409B0E11, "Smart Array 642", &SA5_access},
210 - { 0x409C0E11, "Smart Array 6400", &SA5_access},
211 - { 0x409D0E11, "Smart Array 6400 EM", &SA5_access},
212 - { 0x40910E11, "Smart Array 6i", &SA5_access},
213 - { 0x3225103C, "Smart Array P600", &SA5_access},
214 - { 0x3223103C, "Smart Array P800", &SA5_access},
215 - { 0x3234103C, "Smart Array P400", &SA5_access},
216 - { 0x3235103C, "Smart Array P400i", &SA5_access},
217 - { 0x3211103C, "Smart Array E200i", &SA5_access},
218 - { 0x3212103C, "Smart Array E200", &SA5_access},
219 - { 0x3213103C, "Smart Array E200i", &SA5_access},
220 - { 0x3214103C, "Smart Array E200i", &SA5_access},
221 - { 0x3215103C, "Smart Array E200i", &SA5_access},
222 + { 0x40700E11, "Smart Array 5300", &SA5_access, 384},
223 + { 0x40800E11, "Smart Array 5i", &SA5B_access, 384},
224 + { 0x40820E11, "Smart Array 532", &SA5B_access, 384},
225 + { 0x40830E11, "Smart Array 5312", &SA5B_access, 384},
226 + { 0x409A0E11, "Smart Array 641", &SA5_access, 384},
227 + { 0x409B0E11, "Smart Array 642", &SA5_access, 384},
228 + { 0x409C0E11, "Smart Array 6400", &SA5_access, 384},
229 + { 0x409D0E11, "Smart Array 6400 EM", &SA5_access, 384},
230 + { 0x40910E11, "Smart Array 6i", &SA5_access, 384},
231 + { 0x409E0E11, "Smart Array 6422", &SA5_access, 384},
232 + { 0x3225103C, "Smart Array P600", &SA5_access, 384},
233 + { 0x3234103C, "Smart Array P400", &SA5_access, 512},
234 + { 0x3235103C, "Smart Array P400i", &SA5_access, 512},
235 + { 0x3211103C, "Smart Array E200i", &SA5_access,120},
236 + { 0x3212103C, "Smart Array E200", &SA5_access,120},
237 + { 0x3213103C, "Smart Array E200i", &SA5_access,120},
238 + { 0x3214103C, "Smart Array E200i", &SA5_access, 120},
239 + { 0x3215103C, "Smart Array E200i", &SA5_access, 120},
240 + { 0x3223103C, "Smart Array P800", &SA5_access, 512},
241 + { 0x3237103C, "Smart Array E500", &SA5_access, 128},
242 + { 0x323D103C, "Smart Array P700m", &SA5_access, 512},
243 + { 0xFFFF103C, "Unknown Smart Array", &SA5_access, 120},
246 -/* How long to wait (in millesconds) for board to go into simple mode */
247 +/* How long to wait (in millisconds) for board to go into simple mode */
248 #define MAX_CONFIG_WAIT 30000
249 #define MAX_IOCTL_CONFIG_WAIT 1000
251 /*define how many times we will try a command because of bus resets */
252 #define MAX_CMD_RETRIES 3
254 -#define READ_AHEAD 1024
255 -#define NR_CMDS 384 /* #commands that can be outstanding */
258 /* Originally cciss driver only supports 8 major numbers */
259 #define MAX_CTLR_ORIG 8
262 static ctlr_info_t *hba[MAX_CTLR];
264 static void do_cciss_request(request_queue_t *q);
265 @@ -155,35 +166,40 @@
266 unsigned int cmd, unsigned long arg);
267 static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
269 -static int revalidate_allvol(ctlr_info_t *host);
270 static int cciss_revalidate(struct gendisk *disk);
271 static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk);
272 -static int deregister_disk(struct gendisk *disk, drive_info_struct *drv, int clear_all);
274 -static void cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
275 - int withirq, unsigned int *total_size, unsigned int *block_size);
276 +static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
278 +static void cciss_read_capacity(int ctlr, int logvol, int withirq,
279 + sector_t *total_size, unsigned int *block_size);
280 +static void cciss_read_capacity_16(int ctlr, int logvol, int withirq,
281 + sector_t *total_size, unsigned int *block_size);
282 static void cciss_geometry_inquiry(int ctlr, int logvol,
283 - int withirq, unsigned int total_size,
284 + int withirq, sector_t total_size,
285 unsigned int block_size, InquiryData_struct *inq_buff,
286 drive_info_struct *drv);
287 static void cciss_getgeometry(int cntl_num);
288 -static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *, __u32);
289 +static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
291 static void start_io( ctlr_info_t *h);
292 static int sendcmd( __u8 cmd, int ctlr, void *buff, size_t size,
293 - unsigned int use_unit_num, unsigned int log_unit, __u8 page_code,
294 - unsigned char *scsi3addr, int cmd_type);
295 + unsigned int use_unit_num, unsigned int log_unit,
296 + __u8 page_code, unsigned char *scsi3addr, int cmd_type);
297 static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
298 - unsigned int use_unit_num, unsigned int log_unit, __u8 page_code,
300 + unsigned int use_unit_num, unsigned int log_unit,
301 + __u8 page_code, int cmd_type);
303 -static void fail_all_cmds(unsigned long ctlr);
304 +static void cciss_shutdown (struct pci_dev *pdev);
305 +static void __devexit cciss_remove_one(struct pci_dev *pdev);
307 +static void fail_all_cmds(unsigned long ctlr);
308 +static void print_cmd(CommandList_struct *);
309 #ifdef CONFIG_PROC_FS
310 -static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
311 - int length, int *eof, void *data);
312 static void cciss_procinit(int i);
314 -static void cciss_procinit(int i) {}
315 +static void cciss_procinit(int i)
318 #endif /* CONFIG_PROC_FS */
322 CommandList_struct *c)
324 if (c && c->next != c) {
325 - if (*Qptr == c) *Qptr = c->next;
328 c->prev->next = c->next;
329 c->next->prev = c->prev;
331 @@ -231,46 +248,492 @@
335 -#include "cciss_scsi.c" /* For SCSI tape support */
336 +static inline int find_drv_index(int ctlr, drive_info_struct *drv){
338 + for (i=0; i < CISS_MAX_LUN; i++) {
339 + if (hba[ctlr]->drv[i].LunID == drv->LunID)
345 -#ifdef CONFIG_PROC_FS
346 +#include "cciss_scsi.c" /* For SCSI tape support */
349 - * Report information about this controller.
351 #define ENG_GIG 1000000000
352 #define ENG_GIG_FACTOR (ENG_GIG/512)
353 #define RAID_UNKNOWN 6
354 +#define ENGAGE_SCSI "engage scsi"
355 +#define RESCAN_VOLUMES "rescan volumes"
357 static const char *raid_label[] = {"0","4","1(1+0)","5","5+1","ADG",
360 -static struct proc_dir_entry *proc_cciss;
361 +static spinlock_t sysfs_lock = SPIN_LOCK_UNLOCKED;
363 +static void cciss_sysfs_stat_inquiry(int ctlr, int logvol,
364 + int withirq, drive_info_struct *drv)
367 + InquiryData_struct *inq_buff;
369 + /* If there are no heads then this is the controller disk and
370 + * not a valid logical drive so don't query it.
375 + inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
377 + printk(KERN_ERR "cciss: out of memory\n");
382 + return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
383 + inq_buff, sizeof(*inq_buff), 1, logvol ,0, TYPE_CMD);
385 + return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
386 + sizeof(*inq_buff), 1, logvol , 0, NULL, TYPE_CMD);
387 + if (return_code == IO_OK) {
388 + memcpy(drv->vendor, &inq_buff->data_byte[8], 8);
389 + drv->vendor[8]='\0';
390 + memcpy(drv->model, &inq_buff->data_byte[16], 16);
391 + drv->model[16] = '\0';
392 + memcpy(drv->rev, &inq_buff->data_byte[32], 4);
393 + drv->rev[4] = '\0';
394 + } else { /* Get geometry failed */
395 + printk(KERN_WARNING "cciss: inquiry for VPD page 0 failed\n");
399 + return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
400 + inq_buff, sizeof(*inq_buff), 1, logvol ,0x83, TYPE_CMD);
402 + return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
403 + sizeof(*inq_buff), 1, logvol , 0x83, NULL, TYPE_CMD);
405 + if (return_code == IO_OK) {
406 + memcpy(drv->uid, &inq_buff->data_byte[8], 16);
407 + } else { /* Get geometry failed */
408 + printk(KERN_WARNING "cciss: id logical drive failed\n");
413 + drv->vendor[8] = '\0';
414 + drv->model[16] = '\0';
415 + drv->rev[4] = '\0';
419 -static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
420 - int length, int *eof, void *data)
421 +static ssize_t cciss_show_raid_level(struct device *dev,
422 + struct device_attribute *attr, char *buf)
427 - ctlr_info_t *h = (ctlr_info_t*)data;
428 - drive_info_struct *drv;
429 + struct drv_dynamic *d;
430 + drive_info_struct *drv;
433 - sector_t vol_sz, vol_sz_frac;
437 + d = container_of(dev, struct drv_dynamic, dev);
438 + spin_lock(&sysfs_lock);
440 + spin_unlock(&sysfs_lock);
444 - /* prevent displaying bogus info during configuration
445 - * or deconfiguration of a logical volume
447 - spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
448 + h = get_host(d->disk);
450 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
451 if (h->busy_configuring) {
452 - spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
454 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
455 + spin_unlock(&sysfs_lock);
456 + return snprintf(buf, 30, "Device busy configuring\n");
458 - h->busy_configuring = 1;
459 - spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
461 - size = sprintf(buffer, "%s: HP %s Controller\n"
462 + drv = d->disk->private_data;
463 + if ((drv->raid_level < 0) || (drv->raid_level) > 5)
464 + raid = RAID_UNKNOWN;
466 + raid = drv->raid_level;
468 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
469 + spin_unlock(&sysfs_lock);
470 + return snprintf(buf, 20, "RAID %s\n", raid_label[raid]);
473 +static ssize_t cciss_show_disk_size(struct device *dev,
474 + struct device_attribute *attr, char *buf)
476 + struct drv_dynamic *d;
477 + drive_info_struct *drv;
479 + unsigned long flags;
480 + sector_t vol_sz, vol_sz_frac;
482 + d = container_of(dev, struct drv_dynamic, dev);
483 + spin_lock(&sysfs_lock);
485 + spin_unlock(&sysfs_lock);
488 + h = get_host(d->disk);
490 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
491 + if (h->busy_configuring) {
492 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
493 + spin_unlock(&sysfs_lock);
494 + return snprintf(buf, 30, "Device busy configuring\n");
497 + drv = d->disk->private_data;
498 + vol_sz = drv->nr_blocks;
499 + vol_sz_frac = sector_div(vol_sz, ENG_GIG_FACTOR);
500 + vol_sz_frac *= 100;
501 + sector_div(vol_sz_frac, ENG_GIG_FACTOR);
503 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
504 + spin_unlock(&sysfs_lock);
505 + return snprintf(buf, 30, "%4u.%02uGB\n", (int)vol_sz, (int)vol_sz_frac);
508 +static ssize_t cciss_show_usage_count(struct device *dev,
509 + struct device_attribute *attr, char *buf)
511 + struct drv_dynamic *d;
512 + drive_info_struct *drv;
515 + d = container_of(dev, struct drv_dynamic, dev);
516 + spin_lock(&sysfs_lock);
518 + spin_unlock(&sysfs_lock);
521 + drv = d->disk->private_data;
522 + count = drv->usage_count;
523 + spin_unlock(&sysfs_lock);
524 + return snprintf(buf, 20, "%d\n", count);
527 +static ssize_t cciss_show_vendor(struct device *dev,
528 + struct device_attribute *attr, char *buf)
530 + struct drv_dynamic *d;
531 + drive_info_struct *drv;
533 + unsigned long flags;
536 + d = container_of(dev, struct drv_dynamic, dev);
537 + spin_lock(&sysfs_lock);
539 + spin_unlock(&sysfs_lock);
543 + h = get_host(d->disk);
545 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
546 + if (h->busy_configuring) {
547 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
548 + spin_unlock(&sysfs_lock);
552 + drv = d->disk->private_data;
555 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
556 + spin_unlock(&sysfs_lock);
560 + drv_index = find_drv_index(h->ctlr, drv);
561 + if (drv_index != CISS_MAX_LUN) {
562 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
563 + spin_unlock(&sysfs_lock);
564 + return snprintf(buf, 20, "%s\n", (char *)drv->vendor);
567 + printk(KERN_ERR "cciss: logical drive not found\n");
568 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
569 + spin_unlock(&sysfs_lock);
573 +static ssize_t cciss_show_model(struct device *dev,
574 + struct device_attribute *attr, char *buf)
576 + struct drv_dynamic *d;
577 + drive_info_struct *drv;
579 + unsigned long flags;
582 + d = container_of(dev, struct drv_dynamic, dev);
583 + spin_lock(&sysfs_lock);
585 + spin_unlock(&sysfs_lock);
589 + h = get_host(d->disk);
591 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
592 + if (h->busy_configuring) {
593 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
594 + spin_unlock(&sysfs_lock);
598 + drv = d->disk->private_data;
601 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
602 + spin_unlock(&sysfs_lock);
606 + drv_index = find_drv_index(h->ctlr, drv);
607 + if (drv_index != CISS_MAX_LUN) {
608 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
609 + spin_unlock(&sysfs_lock);
610 + return snprintf(buf, 20, "%s\n", (char *)drv->model);
612 + printk(KERN_ERR "cciss: logical drive not found\n");
613 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
614 + spin_unlock(&sysfs_lock);
618 +static ssize_t cciss_show_rev(struct device *dev,
619 + struct device_attribute *attr, char *buf)
621 + struct drv_dynamic *d;
622 + drive_info_struct *drv;
624 + unsigned long flags;
627 + d = container_of(dev, struct drv_dynamic, dev);
628 + spin_lock(&sysfs_lock);
630 + spin_unlock(&sysfs_lock);
634 + h = get_host(d->disk);
636 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
637 + if (h->busy_configuring) {
638 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
639 + spin_unlock(&sysfs_lock);
643 + drv = d->disk->private_data;
646 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
647 + spin_unlock(&sysfs_lock);
651 + drv_index = find_drv_index(h->ctlr, drv);
652 + if (drv_index != CISS_MAX_LUN) {
653 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
654 + spin_unlock(&sysfs_lock);
655 + return snprintf(buf, 20, "%s\n", (char *)drv->rev);
658 + printk(KERN_ERR "cciss: logical drive not found\n");
659 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
660 + spin_unlock(&sysfs_lock);
664 +static ssize_t cciss_show_unique_id(struct device *dev,
665 + struct device_attribute *attr, char *buf)
667 + struct drv_dynamic *d;
668 + drive_info_struct *drv;
670 + unsigned long flags;
673 + d = container_of(dev, struct drv_dynamic, dev);
674 + spin_lock(&sysfs_lock);
676 + spin_unlock(&sysfs_lock);
680 + h = get_host(d->disk);
682 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
683 + if (h->busy_configuring) {
684 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
685 + spin_unlock(&sysfs_lock);
686 + return snprintf(buf, 30, "Device busy configuring\n");
688 + drv = d->disk->private_data;
691 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
692 + spin_unlock(&sysfs_lock);
696 + drv_index = find_drv_index(h->ctlr, drv);
697 + if (drv_index != CISS_MAX_LUN) {
698 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
699 + spin_unlock(&sysfs_lock);
701 + return snprintf(buf, 40, "%02X%02X%02X%02X%02X%02X%02X%02X"
702 + "%02X%02X%02X%02X%02X%02X%02X%02X\n",
703 + drv->uid[0], drv->uid[1], drv->uid[2],
704 + drv->uid[3], drv->uid[4], drv->uid[5],
705 + drv->uid[6], drv->uid[7], drv->uid[8],
706 + drv->uid[9], drv->uid[10], drv->uid[11],
707 + drv->uid[12], drv->uid[13], drv->uid[14],
711 + printk(KERN_ERR "cciss: logical drive not found\n");
712 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
713 + spin_unlock(&sysfs_lock);
717 +static ssize_t cciss_show_bus(struct device *dev,
718 + struct device_attribute *attr, char *buf)
720 + return snprintf(buf, 20, "cciss\n");
723 +static ssize_t cciss_show_lunid(struct device *dev,
724 + struct device_attribute *attr, char *buf)
726 + struct drv_dynamic *d;
727 + drive_info_struct *drv;
729 + unsigned long flags;
732 + d = container_of(dev, struct drv_dynamic, dev);
733 + spin_lock(&sysfs_lock);
735 + spin_unlock(&sysfs_lock);
739 + h = get_host(d->disk);
741 + spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
742 + if (h->busy_configuring) {
743 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
744 + spin_unlock(&sysfs_lock);
748 + drv = d->disk->private_data;
751 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
752 + spin_unlock(&sysfs_lock);
756 + drv_index = find_drv_index(h->ctlr, drv);
757 + if (drv_index != CISS_MAX_LUN) {
758 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
759 + spin_unlock(&sysfs_lock);
760 + return snprintf(buf, 20, "%d\n", drv->LunID);
763 + printk(KERN_ERR "cciss: logical drive not found\n");
764 + spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
765 + spin_unlock(&sysfs_lock);
769 +DEVICE_ATTR(raid_level, S_IRUGO | S_IWUSR, cciss_show_raid_level, NULL);
770 +DEVICE_ATTR(disk_size, S_IRUGO | S_IWUSR, cciss_show_disk_size, NULL);
771 +DEVICE_ATTR(usage_count, S_IRUGO | S_IWUSR, cciss_show_usage_count, NULL);
772 +DEVICE_ATTR(vendor, S_IRUGO | S_IWUSR, cciss_show_vendor, NULL);
773 +DEVICE_ATTR(model, S_IRUGO | S_IWUSR, cciss_show_model, NULL);
774 +DEVICE_ATTR(rev, S_IRUGO | S_IWUSR, cciss_show_rev, NULL);
775 +DEVICE_ATTR(unique_id, S_IRUGO | S_IWUSR, cciss_show_unique_id, NULL);
776 +DEVICE_ATTR(bus, S_IRUGO | S_IWUSR, cciss_show_bus, NULL);
777 +DEVICE_ATTR(lunid, S_IRUGO | S_IWUSR, cciss_show_lunid, NULL);
779 +static struct attribute *cciss_sysfs_attrs[] = {
780 + &dev_attr_raid_level.attr,
781 + &dev_attr_disk_size.attr,
782 + &dev_attr_usage_count.attr,
783 + &dev_attr_vendor.attr,
784 + &dev_attr_model.attr,
785 + &dev_attr_rev.attr,
786 + &dev_attr_unique_id.attr,
787 + &dev_attr_bus.attr,
788 + &dev_attr_lunid.attr,
792 +static struct attribute_group cciss_attrs = {.attrs = cciss_sysfs_attrs};
794 +static void cciss_add_blk_sysfs_dev(drive_info_struct *drv,
795 + struct gendisk* disk,
796 + struct pci_dev *pdev, int disk_num)
798 + struct drv_dynamic *d = kmalloc(sizeof(struct drv_dynamic), GFP_KERNEL);
801 + memset(d, 0, sizeof(struct drv_dynamic));
802 + disk->driverfs_dev = &d->dev;
803 + d->dev.parent = &pdev->dev;
804 + d->dev.release = (void (*)(struct device *))kfree;
805 + sprintf(d->dev.bus_id, "disk%d", disk_num);
806 + d->dev.driver_data = "cciss";
807 + if (device_register(&d->dev)) {
808 + put_device(&d->dev);
811 + sysfs_create_group(&d->dev.kobj, &cciss_attrs);
813 + drv->dev_info = &d->dev;
816 +static void cciss_remove_blk_sysfs_dev(struct gendisk *disk)
818 + drive_info_struct *drv = get_drv(disk);
819 + struct drv_dynamic *d;
821 + if (!drv->dev_info)
824 + d = container_of(drv->dev_info, struct drv_dynamic, dev);
825 + spin_lock(&sysfs_lock);
826 + sysfs_remove_group(&d->dev.kobj, &cciss_attrs);
828 + spin_unlock(&sysfs_lock);
829 + device_unregister(drv->dev_info);
830 + drv->dev_info = NULL;
833 +#ifdef CONFIG_PROC_FS
836 + * Report information about this controller.
838 +static struct proc_dir_entry *proc_cciss;
840 +static void cciss_seq_show_header(struct seq_file *seq)
842 + ctlr_info_t *h = seq->private;
844 + seq_printf(seq, "%s: HP %s Controller\n"
845 "Board ID: 0x%08lx\n"
846 "Firmware Version: %c%c%c%c\n"
848 @@ -279,94 +742,196 @@
849 "Current # commands on controller: %d\n"
850 "Max Q depth since init: %d\n"
851 "Max # commands on controller since init: %d\n"
852 - "Max SG entries since init: %d\n\n",
855 - (unsigned long)h->board_id,
856 - h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], h->firm_ver[3],
857 - (unsigned int)h->intr[SIMPLE_MODE_INT],
859 + "Max SG entries since init: %d\n",
862 + (unsigned long)h->board_id,
863 + h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
864 + h->firm_ver[3], (unsigned int)h->intr[SIMPLE_MODE_INT],
866 h->Qdepth, h->commands_outstanding,
867 h->maxQsinceinit, h->max_outstanding, h->maxSG);
869 +#ifdef CONFIG_CISS_SCSI_TAPE
870 + cciss_seq_tape_report(seq, h->ctlr);
871 +#endif /* CONFIG_CISS_SCSI_TAPE */
874 - pos += size; len += size;
875 - cciss_proc_tape_report(ctlr, buffer, &pos, &len);
876 - for(i=0; i<=h->highest_lun; i++) {
877 +static void *cciss_seq_start(struct seq_file *seq, loff_t *pos)
879 + ctlr_info_t *h = seq->private;
880 + unsigned ctlr = h->ctlr;
881 + unsigned long flags;
884 - if (drv->heads == 0)
886 + /* prevent displaying bogus info during configuration
887 + * or deconfiguration of a logical volume
889 + spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
890 + if (h->busy_configuring) {
891 + spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
892 + return ERR_PTR(-EBUSY);
894 + h->busy_configuring = 1;
895 + spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
897 - vol_sz = drv->nr_blocks;
898 - vol_sz_frac = sector_div(vol_sz, ENG_GIG_FACTOR);
899 - vol_sz_frac *= 100;
900 - sector_div(vol_sz_frac, ENG_GIG_FACTOR);
902 + cciss_seq_show_header(seq);
904 - if (drv->raid_level > 5)
905 - drv->raid_level = RAID_UNKNOWN;
906 - size = sprintf(buffer+len, "cciss/c%dd%d:"
907 - "\t%4u.%02uGB\tRAID %s\n",
908 - ctlr, i, (int)vol_sz, (int)vol_sz_frac,
909 - raid_label[drv->raid_level]);
910 - pos += size; len += size;
915 +static int cciss_seq_show(struct seq_file *seq, void *v)
917 + sector_t vol_sz, vol_sz_frac;
918 + ctlr_info_t *h = seq->private;
919 + unsigned ctlr = h->ctlr;
921 + drive_info_struct *drv = &h->drv[*pos];
923 + if (*pos > h->highest_lun)
926 + if (drv->heads == 0)
929 + vol_sz = drv->nr_blocks;
930 + vol_sz_frac = sector_div(vol_sz, ENG_GIG_FACTOR);
931 + vol_sz_frac *= 100;
932 + sector_div(vol_sz_frac, ENG_GIG_FACTOR);
934 + if (drv->raid_level > 5)
935 + drv->raid_level = RAID_UNKNOWN;
936 + seq_printf(seq, "cciss/c%dd%d:"
937 + "\t%4u.%02uGB\tRAID %s\n",
938 + ctlr, (int) *pos, (int)vol_sz, (int)vol_sz_frac,
939 + raid_label[drv->raid_level]);
943 +static void *cciss_seq_next(struct seq_file *seq, void *v, loff_t *pos)
945 + ctlr_info_t *h = seq->private;
947 + if (*pos > h->highest_lun)
954 +static void cciss_seq_stop(struct seq_file *seq, void *v)
956 + ctlr_info_t *h = seq->private;
958 + /* Only reset h->busy_configuring if we succeeded in setting
959 + * it during cciss_seq_start. */
960 + if (v == ERR_PTR(-EBUSY))
964 - *start = buffer+offset;
968 h->busy_configuring = 0;
973 -cciss_proc_write(struct file *file, const char __user *buffer,
974 - unsigned long count, void *data)
975 +static struct seq_operations cciss_seq_ops = {
976 + .start = cciss_seq_start,
977 + .show = cciss_seq_show,
978 + .next = cciss_seq_next,
979 + .stop = cciss_seq_stop,
982 +static int cciss_seq_open(struct inode *inode, struct file *file)
984 + int ret = seq_open(file, &cciss_seq_ops);
985 + struct seq_file *seq = file->private_data;
988 + seq->private = PDE(inode)->data;
994 +cciss_proc_write(struct file *file, const char __user *buf,
995 + size_t length, loff_t *ppos)
997 - unsigned char cmd[80];
999 -#ifdef CONFIG_CISS_SCSI_TAPE
1000 - ctlr_info_t *h = (ctlr_info_t *) data;
1003 + struct seq_file *seq = file->private_data;
1004 + ctlr_info_t *h = seq->private;
1008 - if (count > sizeof(cmd)-1) return -EINVAL;
1009 - if (copy_from_user(cmd, buffer, count)) return -EFAULT;
1010 - cmd[count] = '\0';
1011 - len = strlen(cmd); // above 3 lines ensure safety
1012 - if (len && cmd[len-1] == '\n')
1013 - cmd[--len] = '\0';
1014 -# ifdef CONFIG_CISS_SCSI_TAPE
1015 - if (strcmp("engage scsi", cmd)==0) {
1016 - rc = cciss_engage_scsi(h->ctlr);
1017 - if (rc != 0) return -rc;
1020 + if (!buf || length > PAGE_SIZE - 1)
1023 + buffer = (char *)__get_free_page(GFP_KERNEL);
1028 + if (copy_from_user(buffer, buf, length))
1030 + buffer[length] = '\0';
1032 + /* For the MSA2000 the firmware cannot tell the driver to
1033 + * rescan when new logical volumes are created. We provide
1034 + * this interface so users can `echo "rescan volumes" >
1035 + * /proc/driver/cciss/ccissN` to accomplish that task. It's not
1036 + * the best solution because it must be done on every server
1037 + * that connected to the storage.
1039 + if (strncmp(RESCAN_VOLUMES, buffer, sizeof RESCAN_VOLUMES - 1) == 0) {
1040 + /* rebuild_lun_table returns -1 on success to tell ACU
1041 + * to quit calling it. In this case we just ignore any
1044 + (void) rebuild_lun_table(h, NULL);
1049 +#ifdef CONFIG_CISS_SCSI_TAPE
1050 + if (strncmp(ENGAGE_SCSI, buffer, sizeof ENGAGE_SCSI - 1) == 0) {
1051 + rc = cciss_engage_scsi(h->ctlr);
1057 +#endif /* CONFIG_CISS_SCSI_TAPE */
1059 /* might be nice to have "disengage" too, but it's not
1060 safely possible. (only 1 module use count, lock issues.) */
1065 + free_page((unsigned long)buffer);
1070 - * Get us a file in /proc/cciss that says something about each controller.
1071 - * Create /proc/cciss if it doesn't exist yet.
1073 +static struct file_operations cciss_proc_fops = {
1074 + .owner = THIS_MODULE,
1075 + .open = cciss_seq_open,
1077 + .llseek = seq_lseek,
1078 + .release = seq_release,
1079 + .write = cciss_proc_write,
1082 static void __devinit cciss_procinit(int i)
1084 struct proc_dir_entry *pde;
1086 - if (proc_cciss == NULL) {
1087 + if (proc_cciss == NULL)
1088 proc_cciss = proc_mkdir("cciss", proc_root_driver);
1093 - pde = create_proc_read_entry(hba[i]->devname,
1094 - S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
1095 - proc_cciss, cciss_proc_get_info, hba[i]);
1096 - pde->write_proc = cciss_proc_write;
1100 + pde = create_proc_entry(hba[i]->devname,
1101 + S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, proc_cciss);
1105 + pde->proc_fops = &cciss_proc_fops;
1106 + pde->data = hba[i];
1108 #endif /* CONFIG_PROC_FS */
1110 @@ -377,52 +942,51 @@
1111 * to possible sleep, this routine can be called with get_from_pool set to 0.
1112 * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was.
1114 -static CommandList_struct * cmd_alloc(ctlr_info_t *h, int get_from_pool)
1115 +static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool)
1117 CommandList_struct *c;
1120 dma_addr_t cmd_dma_handle, err_dma_handle;
1122 - if (!get_from_pool)
1124 - c = (CommandList_struct *) pci_alloc_consistent(
1125 - h->pdev, sizeof(CommandList_struct), &cmd_dma_handle);
1127 + if (!get_from_pool) {
1128 + c = (CommandList_struct *) pci_alloc_consistent(h->pdev,
1129 + sizeof(CommandList_struct), &cmd_dma_handle);
1132 memset(c, 0, sizeof(CommandList_struct));
1136 - c->err_info = (ErrorInfo_struct *)pci_alloc_consistent(
1137 - h->pdev, sizeof(ErrorInfo_struct),
1138 + c->err_info = (ErrorInfo_struct *)
1139 + pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct),
1142 - if (c->err_info == NULL)
1144 + if (c->err_info == NULL) {
1145 pci_free_consistent(h->pdev,
1146 sizeof(CommandList_struct), c, cmd_dma_handle);
1149 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
1150 - } else /* get it out of the controllers pool */
1153 - i = find_first_zero_bit(h->cmd_pool_bits, NR_CMDS);
1156 - } while(test_and_set_bit(i & (BITS_PER_LONG - 1), h->cmd_pool_bits+(i/BITS_PER_LONG)) != 0);
1157 + } else { /* get it out of the controllers pool */
1159 + i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
1160 + if (i == h->nr_cmds)
1162 + } while(test_and_set_bit
1163 + (i & (BITS_PER_LONG - 1),
1164 + h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
1166 printk(KERN_DEBUG "cciss: using command buffer %d\n", i);
1168 c = h->cmd_pool + i;
1169 memset(c, 0, sizeof(CommandList_struct));
1170 - cmd_dma_handle = h->cmd_pool_dhandle
1171 - + i*sizeof(CommandList_struct);
1172 + cmd_dma_handle = h->cmd_pool_dhandle
1173 + + i * sizeof(CommandList_struct);
1174 c->err_info = h->errinfo_pool + i;
1175 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
1176 err_dma_handle = h->errinfo_pool_dhandle
1177 - + i*sizeof(ErrorInfo_struct);
1178 + + i * sizeof(ErrorInfo_struct);
1182 @@ -436,8 +1000,6 @@
1191 @@ -448,32 +1010,21 @@
1195 - if( !got_from_pool)
1197 + if (!got_from_pool) {
1198 temp64.val32.lower = c->ErrDesc.Addr.lower;
1199 temp64.val32.upper = c->ErrDesc.Addr.upper;
1200 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct),
1201 c->err_info, (dma_addr_t) temp64.val);
1202 pci_free_consistent(h->pdev, sizeof(CommandList_struct),
1203 c, (dma_addr_t) c->busaddr);
1207 i = c - h->cmd_pool;
1208 - clear_bit(i&(BITS_PER_LONG-1), h->cmd_pool_bits+(i/BITS_PER_LONG));
1209 + clear_bit(i & (BITS_PER_LONG - 1),
1210 + h->cmd_pool_bits + (i / BITS_PER_LONG));
1215 -static inline ctlr_info_t *get_host(struct gendisk *disk)
1217 - return disk->queue->queuedata;
1220 -static inline drive_info_struct *get_drv(struct gendisk *disk)
1222 - return disk->private_data;
1226 * Open. Make sure the device is really there.
1228 @@ -496,7 +1047,7 @@
1229 * but I'm already using way to many device nodes to claim another one
1230 * for "raw controller".
1232 - if (drv->nr_blocks == 0) {
1233 + if (drv->heads == 0) {
1234 if (iminor(inode) != 0) { /* not node 0? */
1235 /* if not node 0 make sure it is a partition = 0 */
1236 if (iminor(inode) & 0x0f) {
1237 @@ -513,6 +1064,7 @@
1238 host->usage_count++;
1243 * Close. Sync first.
1245 @@ -522,7 +1074,8 @@
1246 drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk);
1249 - printk(KERN_DEBUG "cciss_release %s\n", inode->i_bdev->bd_disk->disk_name);
1250 + printk(KERN_DEBUG "cciss_release %s\n",
1251 + inode->i_bdev->bd_disk->disk_name);
1252 #endif /* CCISS_DEBUG */
1255 @@ -541,8 +1094,10 @@
1259 -static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, unsigned long arg);
1260 -static int cciss_ioctl32_big_passthru(struct file *f, unsigned cmd, unsigned long arg);
1261 +static int cciss_ioctl32_passthru(struct file *f, unsigned cmd,
1262 + unsigned long arg);
1263 +static int cciss_ioctl32_big_passthru(struct file *f, unsigned cmd,
1264 + unsigned long arg);
1266 static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg)
1268 @@ -574,7 +1129,8 @@
1272 -static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, unsigned long arg)
1273 +static int cciss_ioctl32_passthru(struct file *f, unsigned cmd,
1274 + unsigned long arg)
1276 IOCTL32_Command_struct __user *arg32 =
1277 (IOCTL32_Command_struct __user *) arg;
1278 @@ -584,9 +1140,12 @@
1282 - err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, sizeof(arg64.LUN_info));
1283 - err |= copy_from_user(&arg64.Request, &arg32->Request, sizeof(arg64.Request));
1284 - err |= copy_from_user(&arg64.error_info, &arg32->error_info, sizeof(arg64.error_info));
1285 + err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
1286 + sizeof(arg64.LUN_info));
1287 + err |= copy_from_user(&arg64.Request, &arg32->Request,
1288 + sizeof(arg64.Request));
1289 + err |= copy_from_user(&arg64.error_info, &arg32->error_info,
1290 + sizeof(arg64.error_info));
1291 err |= get_user(arg64.buf_size, &arg32->buf_size);
1292 err |= get_user(cp, &arg32->buf);
1293 arg64.buf = compat_ptr(cp);
1294 @@ -595,28 +1154,34 @@
1298 - err = do_ioctl(f, CCISS_PASSTHRU, (unsigned long) p);
1299 + err = do_ioctl(f, CCISS_PASSTHRU, (unsigned long)p);
1302 - err |= copy_in_user(&arg32->error_info, &p->error_info, sizeof(arg32->error_info));
1303 + err |= copy_in_user(&arg32->error_info, &p->error_info,
1304 + sizeof(arg32->error_info));
1310 -static int cciss_ioctl32_big_passthru(struct file *file, unsigned cmd, unsigned long arg)
1311 +static int cciss_ioctl32_big_passthru(struct file *file, unsigned cmd,
1312 + unsigned long arg)
1314 BIG_IOCTL32_Command_struct __user *arg32 =
1315 (BIG_IOCTL32_Command_struct __user *) arg;
1316 BIG_IOCTL_Command_struct arg64;
1317 - BIG_IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64));
1318 + BIG_IOCTL_Command_struct __user *p =
1319 + compat_alloc_user_space(sizeof(arg64));
1324 - err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, sizeof(arg64.LUN_info));
1325 - err |= copy_from_user(&arg64.Request, &arg32->Request, sizeof(arg64.Request));
1326 - err |= copy_from_user(&arg64.error_info, &arg32->error_info, sizeof(arg64.error_info));
1327 + err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
1328 + sizeof(arg64.LUN_info));
1329 + err |= copy_from_user(&arg64.Request, &arg32->Request,
1330 + sizeof(arg64.Request));
1331 + err |= copy_from_user(&arg64.error_info, &arg32->error_info,
1332 + sizeof(arg64.error_info));
1333 err |= get_user(arg64.buf_size, &arg32->buf_size);
1334 err |= get_user(arg64.malloc_size, &arg32->malloc_size);
1335 err |= get_user(cp, &arg32->buf);
1336 @@ -626,10 +1191,11 @@
1340 - err = do_ioctl(file, CCISS_BIG_PASSTHRU, (unsigned long) p);
1341 + err = do_ioctl(file, CCISS_BIG_PASSTHRU, (unsigned long)p);
1344 - err |= copy_in_user(&arg32->error_info, &p->error_info, sizeof(arg32->error_info));
1345 + err |= copy_in_user(&arg32->error_info, &p->error_info,
1346 + sizeof(arg32->error_info));
1350 @@ -666,29 +1232,33 @@
1351 printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg);
1352 #endif /* CCISS_DEBUG */
1356 case CCISS_GETPCIINFO:
1358 cciss_pci_info_struct pciinfo;
1360 - if (!arg) return -EINVAL;
1363 pciinfo.domain = pci_domain_nr(host->pdev->bus);
1364 pciinfo.bus = host->pdev->bus->number;
1365 pciinfo.dev_fn = host->pdev->devfn;
1366 pciinfo.board_id = host->board_id;
1367 - if (copy_to_user(argp, &pciinfo, sizeof( cciss_pci_info_struct )))
1370 + if (copy_to_user(argp, &pciinfo,
1371 + sizeof( cciss_pci_info_struct)))
1375 case CCISS_GETINTINFO:
1377 cciss_coalint_struct intinfo;
1378 - if (!arg) return -EINVAL;
1381 intinfo.delay = readl(&host->cfgtable->HostWrite.CoalIntDelay);
1382 intinfo.count = readl(&host->cfgtable->HostWrite.CoalIntCount);
1383 - if (copy_to_user(argp, &intinfo, sizeof( cciss_coalint_struct )))
1384 + if (copy_to_user(argp, &intinfo,
1385 + sizeof( cciss_coalint_struct)))
1390 case CCISS_SETINTINFO:
1392 @@ -696,25 +1266,28 @@
1393 unsigned long flags;
1396 - if (!arg) return -EINVAL;
1397 - if (!capable(CAP_SYS_ADMIN)) return -EPERM;
1398 - if (copy_from_user(&intinfo, argp, sizeof( cciss_coalint_struct)))
1401 + if (!capable(CAP_SYS_ADMIN))
1403 + if (copy_from_user(&intinfo, argp,
1404 + sizeof(cciss_coalint_struct)))
1406 - if ( (intinfo.delay == 0 ) && (intinfo.count == 0))
1407 + if ((intinfo.delay == 0 ) && (intinfo.count == 0))
1410 // printk("cciss_ioctl: delay and count cannot be 0\n");
1414 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1415 /* Update the field, and then ring the doorbell */
1416 - writel( intinfo.delay,
1417 + writel(intinfo.delay,
1418 &(host->cfgtable->HostWrite.CoalIntDelay));
1419 - writel( intinfo.count,
1420 + writel(intinfo.count,
1421 &(host->cfgtable->HostWrite.CoalIntCount));
1422 - writel( CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
1423 + writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
1425 - for(i=0;i<MAX_IOCTL_CONFIG_WAIT;i++) {
1426 + for(i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) {
1427 if (!(readl(host->vaddr + SA5_DOORBELL)
1428 & CFGTBL_ChangeReq))
1430 @@ -724,19 +1297,21 @@
1431 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1432 if (i >= MAX_IOCTL_CONFIG_WAIT)
1437 case CCISS_GETNODENAME:
1439 NodeName_type NodeName;
1442 - if (!arg) return -EINVAL;
1446 + for(i = 0; i < 16; i++) {
1447 NodeName[i] = readb(&host->cfgtable->ServerName[i]);
1448 - if (copy_to_user(argp, NodeName, sizeof( NodeName_type)))
1452 + if (copy_to_user(argp, NodeName, sizeof(NodeName_type)))
1456 case CCISS_SETNODENAME:
1458 @@ -744,21 +1319,23 @@
1459 unsigned long flags;
1462 - if (!arg) return -EINVAL;
1463 - if (!capable(CAP_SYS_ADMIN)) return -EPERM;
1466 + if (!capable(CAP_SYS_ADMIN))
1469 - if (copy_from_user(NodeName, argp, sizeof( NodeName_type)))
1470 + if (copy_from_user(NodeName, argp, sizeof(NodeName_type)))
1473 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1475 /* Update the field, and then ring the doorbell */
1477 - writeb( NodeName[i], &host->cfgtable->ServerName[i]);
1478 + for(i = 0; i < 16; i++)
1479 + writeb(NodeName[i], &host->cfgtable->ServerName[i]);
1481 - writel( CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
1482 + writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
1484 - for(i=0;i<MAX_IOCTL_CONFIG_WAIT;i++) {
1485 + for(i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) {
1486 if (!(readl(host->vaddr + SA5_DOORBELL)
1487 & CFGTBL_ChangeReq))
1489 @@ -768,70 +1345,70 @@
1490 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1491 if (i >= MAX_IOCTL_CONFIG_WAIT)
1497 case CCISS_GETHEARTBEAT:
1499 Heartbeat_type heartbeat;
1501 - if (!arg) return -EINVAL;
1504 heartbeat = readl(&host->cfgtable->HeartBeat);
1505 - if (copy_to_user(argp, &heartbeat, sizeof( Heartbeat_type)))
1506 + if (copy_to_user(argp, &heartbeat, sizeof(Heartbeat_type)))
1511 case CCISS_GETBUSTYPES:
1513 BusTypes_type BusTypes;
1515 - if (!arg) return -EINVAL;
1518 BusTypes = readl(&host->cfgtable->BusTypes);
1519 - if (copy_to_user(argp, &BusTypes, sizeof( BusTypes_type) ))
1522 + if (copy_to_user(argp, &BusTypes, sizeof(BusTypes_type)))
1526 case CCISS_GETFIRMVER:
1528 FirmwareVer_type firmware;
1530 - if (!arg) return -EINVAL;
1533 memcpy(firmware, host->firm_ver, 4);
1535 - if (copy_to_user(argp, firmware, sizeof( FirmwareVer_type)))
1536 + if (copy_to_user(argp, firmware, sizeof(FirmwareVer_type)))
1541 case CCISS_GETDRIVVER:
1543 DriverVer_type DriverVer = DRIVER_VERSION;
1545 - if (!arg) return -EINVAL;
1549 - if (copy_to_user(argp, &DriverVer, sizeof( DriverVer_type) ))
1550 + if (copy_to_user(argp, &DriverVer, sizeof(DriverVer_type)))
1556 - case CCISS_REVALIDVOLS:
1557 - if (bdev != bdev->bd_contains || drv != host->drv)
1559 - return revalidate_allvol(host);
1561 - case CCISS_GETLUNINFO: {
1562 + case CCISS_GETLUNINFO:
1564 LogvolInfo_struct luninfo;
1566 luninfo.LunID = drv->LunID;
1567 luninfo.num_opens = drv->usage_count;
1568 - luninfo.num_parts = 0;
1570 if (copy_to_user(argp, &luninfo,
1571 sizeof(LogvolInfo_struct)))
1576 - case CCISS_DEREGDISK:
1577 - return rebuild_lun_table(host, disk);
1579 + case CCISS_REVALIDVOLS:
1580 + case CCISS_DEREGDISK:
1582 return rebuild_lun_table(host, NULL);
1584 @@ -842,17 +1419,19 @@
1587 unsigned long flags;
1588 - DECLARE_COMPLETION(wait);
1589 + CCISS_DECLARE_COMPLETION(wait);
1591 - if (!arg) return -EINVAL;
1595 - if (!capable(CAP_SYS_RAWIO)) return -EPERM;
1596 + if (!capable(CAP_SYS_RAWIO))
1599 - if (copy_from_user(&iocommand, argp, sizeof( IOCTL_Command_struct) ))
1600 + if (copy_from_user(&iocommand, argp,
1601 + sizeof(IOCTL_Command_struct)))
1603 - if((iocommand.buf_size < 1) &&
1604 - (iocommand.Request.Type.Direction != XFER_NONE))
1606 + if((iocommand.buf_size < 1) &&
1607 + (iocommand.Request.Type.Direction != XFER_NONE)) {
1610 #if 0 /* 'buf_size' member is 16-bits, and always smaller than kmalloc limit */
1611 @@ -860,25 +1439,22 @@
1612 if(iocommand.buf_size > 128000)
1615 - if(iocommand.buf_size > 0)
1617 + if (iocommand.buf_size > 0) {
1618 buff = kmalloc(iocommand.buf_size, GFP_KERNEL);
1623 - if (iocommand.Request.Type.Direction == XFER_WRITE)
1625 + if (iocommand.Request.Type.Direction == XFER_WRITE) {
1626 /* Copy the data into the buffer we created */
1627 - if (copy_from_user(buff, iocommand.buf, iocommand.buf_size))
1629 + if (copy_from_user(buff,
1630 + iocommand.buf, iocommand.buf_size)) {
1635 memset(buff, 0, iocommand.buf_size);
1637 - if ((c = cmd_alloc(host , 0)) == NULL)
1639 + if ((c = cmd_alloc(host, 0)) == NULL) {
1643 @@ -886,14 +1462,12 @@
1644 c->cmd_type = CMD_IOCTL_PEND;
1645 // Fill in Command Header
1646 c->Header.ReplyQueue = 0; // unused in simple mode
1647 - if( iocommand.buf_size > 0) // buffer to fill
1649 + if(iocommand.buf_size > 0) { // buffer to fill
1650 c->Header.SGList = 1;
1651 - c->Header.SGTotal= 1;
1652 - } else // no buffers to fill
1654 + c->Header.SGTotal = 1;
1655 + } else { // no buffers to fill
1656 c->Header.SGList = 0;
1657 - c->Header.SGTotal= 0;
1658 + c->Header.SGTotal = 0;
1660 c->Header.LUN = iocommand.LUN_info;
1661 c->Header.Tag.lower = c->busaddr; // use the kernel address the cmd block for tag
1662 @@ -902,11 +1476,10 @@
1663 c->Request = iocommand.Request;
1665 // Fill in the scatter gather information
1666 - if (iocommand.buf_size > 0 )
1668 - temp64.val = pci_map_single( host->pdev, buff,
1669 - iocommand.buf_size,
1670 - PCI_DMA_BIDIRECTIONAL);
1671 + if (iocommand.buf_size > 0) {
1672 + temp64.val = pci_map_single(host->pdev, buff,
1673 + iocommand.buf_size,
1674 + PCI_DMA_BIDIRECTIONAL);
1675 c->SG[0].Addr.lower = temp64.val32.lower;
1676 c->SG[0].Addr.upper = temp64.val32.upper;
1677 c->SG[0].Len = iocommand.buf_size;
1678 @@ -926,23 +1499,22 @@
1679 /* unlock the buffers from DMA */
1680 temp64.val32.lower = c->SG[0].Addr.lower;
1681 temp64.val32.upper = c->SG[0].Addr.upper;
1682 - pci_unmap_single( host->pdev, (dma_addr_t) temp64.val,
1683 + pci_unmap_single(host->pdev, (dma_addr_t) temp64.val,
1684 iocommand.buf_size, PCI_DMA_BIDIRECTIONAL);
1686 /* Copy the error information out */
1687 iocommand.error_info = *(c->err_info);
1688 - if ( copy_to_user(argp, &iocommand, sizeof( IOCTL_Command_struct) ) )
1690 + if (copy_to_user(argp, &iocommand,
1691 + sizeof(IOCTL_Command_struct))) {
1693 cmd_free(host, c, 0);
1698 - if (iocommand.Request.Type.Direction == XFER_READ)
1700 + if (iocommand.Request.Type.Direction == XFER_READ) {
1701 /* Copy the data out of the buffer we created */
1702 - if (copy_to_user(iocommand.buf, buff, iocommand.buf_size))
1704 + if (copy_to_user(iocommand.buf, buff,
1705 + iocommand.buf_size)) {
1707 cmd_free(host, c, 0);
1709 @@ -950,9 +1522,10 @@
1712 cmd_free(host, c, 0);
1716 - case CCISS_BIG_PASSTHRU: {
1717 + case CCISS_BIG_PASSTHRU:
1719 BIG_IOCTL_Command_struct *ioc;
1720 CommandList_struct *c;
1721 unsigned char **buff = NULL;
1722 @@ -962,7 +1535,7 @@
1726 - DECLARE_COMPLETION(wait);
1727 + CCISS_DECLARE_COMPLETION(wait);
1730 BYTE __user *data_ptr;
1731 @@ -995,14 +1568,13 @@
1735 - buff = (unsigned char **) kmalloc(MAXSGENTRIES *
1736 - sizeof(char *), GFP_KERNEL);
1737 + buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL);
1743 - memset(buff, 0, MAXSGENTRIES);
1744 - buff_size = (int *) kmalloc(MAXSGENTRIES * sizeof(int),
1745 + buff_size = (int *) kmalloc(MAXSGENTRIES * sizeof(int),
1749 @@ -1019,8 +1591,8 @@
1752 if (ioc->Request.Type.Direction == XFER_WRITE) {
1753 - if (copy_from_user(buff[sg_used], data_ptr, sz)) {
1755 + if (copy_from_user(buff[sg_used],data_ptr,sz)) {
1760 @@ -1030,19 +1602,19 @@
1764 - if ((c = cmd_alloc(host , 0)) == NULL) {
1765 + if ((c = cmd_alloc(host, 0)) == NULL) {
1769 c->cmd_type = CMD_IOCTL_PEND;
1770 c->Header.ReplyQueue = 0;
1772 - if( ioc->buf_size > 0) {
1773 + if (ioc->buf_size > 0) {
1774 c->Header.SGList = sg_used;
1775 - c->Header.SGTotal= sg_used;
1776 + c->Header.SGTotal = sg_used;
1778 c->Header.SGList = 0;
1779 - c->Header.SGTotal= 0;
1780 + c->Header.SGTotal = 0;
1782 c->Header.LUN = ioc->LUN_info;
1783 c->Header.Tag.lower = c->busaddr;
1784 @@ -1050,8 +1622,9 @@
1785 c->Request = ioc->Request;
1786 if (ioc->buf_size > 0 ) {
1788 - for(i=0; i<sg_used; i++) {
1789 - temp64.val = pci_map_single( host->pdev, buff[i],
1790 + for (i = 0; i < sg_used; i++) {
1792 + pci_map_single(host->pdev, buff[i],
1794 PCI_DMA_BIDIRECTIONAL);
1795 c->SG[i].Addr.lower = temp64.val32.lower;
1796 @@ -1069,10 +1642,10 @@
1797 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1798 wait_for_completion(&wait);
1799 /* unlock the buffers from DMA */
1800 - for(i=0; i<sg_used; i++) {
1801 + for (i = 0; i < sg_used; i++) {
1802 temp64.val32.lower = c->SG[i].Addr.lower;
1803 temp64.val32.upper = c->SG[i].Addr.upper;
1804 - pci_unmap_single( host->pdev, (dma_addr_t) temp64.val,
1805 + pci_unmap_single(host->pdev, (dma_addr_t) temp64.val,
1806 buff_size[i], PCI_DMA_BIDIRECTIONAL);
1808 /* Copy the error information out */
1809 @@ -1085,7 +1658,7 @@
1810 if (ioc->Request.Type.Direction == XFER_READ) {
1811 /* Copy the data out of the buffer we created */
1812 BYTE __user *ptr = ioc->buf;
1813 - for(i=0; i< sg_used; i++) {
1814 + for(i=0; i < sg_used; i++) {
1815 if (copy_to_user(ptr, buff[i], buff_size[i])) {
1816 cmd_free(host, c, 0);
1818 @@ -1098,101 +1671,103 @@
1822 - for(i=0; i<sg_used; i++)
1823 + for (i = 0; i < sg_used; i++)
1834 + /* scsi_cmd_ioctl handles these, below, though some are not */
1835 + /* very meaningful for cciss. SG_IO is the main one people want. */
1837 + case SG_GET_VERSION_NUM:
1838 + case SG_SET_TIMEOUT:
1839 + case SG_GET_TIMEOUT:
1840 + case SG_GET_RESERVED_SIZE:
1841 + case SG_SET_RESERVED_SIZE:
1842 + case SG_EMULATED_HOST:
1844 + case SCSI_IOCTL_SEND_COMMAND:
1845 + return scsi_cmd_ioctl(filep, disk, cmd, argp);
1847 + /* scsi_cmd_ioctl would normally handle these, below, but */
1848 + /* they aren't a good fit for cciss, as CD-ROMs are */
1849 + /* not supported, and we don't have any bus/target/lun */
1850 + /* which we present to the kernel. */
1852 + case CDROM_SEND_PACKET:
1853 + case CDROMCLOSETRAY:
1855 + case SCSI_IOCTL_GET_IDLUN:
1856 + case SCSI_IOCTL_GET_BUS_NUMBER:
1864 - * revalidate_allvol is for online array config utilities. After a
1865 - * utility reconfigures the drives in the array, it can use this function
1866 - * (through an ioctl) to make the driver zap any previous disk structs for
1867 - * that controller and get new ones.
1869 - * Right now I'm using the getgeometry() function to do this, but this
1870 - * function should probably be finer grained and allow you to revalidate one
1871 - * particualar logical volume (instead of all of them on a particular
1874 -static int revalidate_allvol(ctlr_info_t *host)
1876 - int ctlr = host->ctlr, i;
1877 - unsigned long flags;
1879 - spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1880 - if (host->usage_count > 1) {
1881 - spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1882 - printk(KERN_WARNING "cciss: Device busy for volume"
1883 - " revalidation (usage=%d)\n", host->usage_count);
1886 - host->usage_count++;
1887 - spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1889 - for(i=0; i< NWD; i++) {
1890 - struct gendisk *disk = host->gendisk[i];
1892 - request_queue_t *q = disk->queue;
1894 - if (disk->flags & GENHD_FL_UP)
1895 - del_gendisk(disk);
1897 - blk_cleanup_queue(q);
1902 - * Set the partition and block size structures for all volumes
1903 - * on this controller to zero. We will reread all of this data
1905 - memset(host->drv, 0, sizeof(drive_info_struct)
1908 - * Tell the array controller not to give us any interrupts while
1909 - * we check the new geometry. Then turn interrupts back on when
1912 - host->access.set_intr_mask(host, CCISS_INTR_OFF);
1913 - cciss_getgeometry(ctlr);
1914 - host->access.set_intr_mask(host, CCISS_INTR_ON);
1916 - /* Loop through each real device */
1917 - for (i = 0; i < NWD; i++) {
1918 - struct gendisk *disk = host->gendisk[i];
1919 - drive_info_struct *drv = &(host->drv[i]);
1920 - /* we must register the controller even if no disks exist */
1921 - /* this is for the online array utilities */
1922 - if (!drv->heads && i)
1924 - blk_queue_hardsect_size(drv->queue, drv->block_size);
1925 - set_capacity(disk, drv->nr_blocks);
1928 - host->usage_count--;
1932 static inline void complete_buffers(struct bio *bio, int status)
1935 struct bio *xbh = bio->bi_next;
1936 int nr_sectors = bio_sectors(bio);
1939 bio->bi_next = NULL;
1940 blk_finished_io(len);
1941 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
1946 +static void cciss_check_queues(ctlr_info_t *h)
1948 + int start_queue = h->next_to_run;
1951 + /* check to see if we have maxed out the number of commands that can
1952 + * be placed on the queue. If so then exit. We do this check here
1953 + * in case the interrupt we serviced was from an ioctl and did not
1954 + * free any new commands.
1956 + if ((find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds)) == h->nr_cmds)
1959 + /* We have room on the queue for more commands. Now we need to queue
1960 + * them up. We will also keep track of the next queue to run so
1961 + * that every queue gets a chance to be started first.
1963 + for (i = 0; i < h->highest_lun + 1; i++) {
1964 + int curr_queue = (start_queue + i) % (h->highest_lun + 1);
1965 + /* make sure the disk has been added and the drive is real
1966 + * because this can be called from the middle of init_one.
1968 + if (!(h->drv[curr_queue].queue) ||
1969 + !(h->drv[curr_queue].heads) ||
1970 + h->drv[curr_queue].busy_configuring)
1973 + blk_start_queue(h->gendisk[curr_queue]->queue);
1975 + /* check to see if we have maxed out the number of commands
1976 + * that can be placed on the queue.
1978 + if ((find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds)) == h->nr_cmds) {
1979 + if (curr_queue == start_queue) {
1981 + (start_queue + 1) % (h->highest_lun + 1);
1984 + h->next_to_run = curr_queue;
1988 + curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
1993 static void cciss_softirq_done(struct request *rq)
1994 @@ -1210,17 +1785,16 @@
1996 /* command did not need to be retried */
1997 /* unmap the DMA mapping for all the scatter gather elements */
1998 - for(i=0; i<cmd->Header.SGList; i++) {
1999 + for (i = 0; i < cmd->Header.SGList; i++) {
2000 temp64.val32.lower = cmd->SG[i].Addr.lower;
2001 temp64.val32.upper = cmd->SG[i].Addr.upper;
2002 pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir);
2005 - complete_buffers(rq->bio, rq->errors);
2006 + complete_buffers(rq->bio, (rq->errors == 0));
2008 if (blk_fs_request(rq)) {
2009 const int rw = rq_data_dir(rq);
2011 disk_stat_add(rq->rq_disk, sectors[rw], rq->nr_sectors);
2014 @@ -1228,9 +1802,11 @@
2015 printk("Done with %p\n", rq);
2016 #endif /* CCISS_DEBUG */
2018 + add_disk_randomness(rq->rq_disk);
2019 spin_lock_irqsave(&h->lock, flags);
2020 - end_that_request_last(rq, rq->errors);
2021 - cmd_free(h, cmd,1);
2022 + end_that_request_last(rq, (rq->errors == 0));
2023 + cmd_free(h, cmd, 1);
2024 + cciss_check_queues(h);
2025 spin_unlock_irqrestore(&h->lock, flags);
2028 @@ -1241,23 +1817,26 @@
2029 * will always be left registered with the kernel since it is also the
2030 * controller node. Any changes to disk 0 will show up on the next
2034 static void cciss_update_drive_info(int ctlr, int drv_index)
2037 ctlr_info_t *h = hba[ctlr];
2038 struct gendisk *disk;
2039 - ReadCapdata_struct *size_buff = NULL;
2040 InquiryData_struct *inq_buff = NULL;
2041 unsigned int block_size;
2042 - unsigned int total_size;
2043 + sector_t total_size;
2044 unsigned long flags = 0;
2047 - /* if the disk already exists then deregister it before proceeding*/
2048 - if (h->drv[drv_index].raid_level != -1){
2049 + /* if the disk already exists then deregister it before proceeding */
2050 + if (h->drv[drv_index].raid_level != -1) {
2051 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2052 h->drv[drv_index].busy_configuring = 1;
2053 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2055 + /* deregister_disk sets h->drv[drv_index].queue = NULL */
2056 + /* which keeps the interrupt handler from starting */
2058 ret = deregister_disk(h->gendisk[drv_index],
2059 &h->drv[drv_index], 0);
2060 h->drv[drv_index].busy_configuring = 0;
2061 @@ -1268,16 +1847,38 @@
2065 - /* Get information about the disk and modify the driver sturcture */
2066 - size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
2067 - if (size_buff == NULL)
2069 - inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
2070 + /* Get information about the disk and modify the driver structure */
2071 + inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
2072 if (inq_buff == NULL)
2075 - cciss_read_capacity(ctlr, drv_index, size_buff, 1,
2076 + /* testing to see if 16-byte CDBs are already
2078 + if (h->cciss_read == CCISS_READ_16) {
2079 + cciss_read_capacity_16(h->ctlr, drv_index, 1,
2080 + &total_size, &block_size);
2084 + cciss_read_capacity(ctlr, drv_index, 1,
2085 &total_size, &block_size);
2088 + * If read_capacity returns all F's the logical volume is >2TB
2089 + * so we switch to 16-byte CDBs for all read/write ops
2092 + if (total_size == 0xFFFFFFFFULL) {
2093 + cciss_read_capacity_16(ctlr, drv_index, 1,
2094 + &total_size, &block_size);
2095 + h->cciss_read = CCISS_READ_16;
2096 + h->cciss_write = CCISS_WRITE_16;
2098 + h->cciss_read = CCISS_READ_10;
2099 + h->cciss_write = CCISS_WRITE_10;
2103 cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size,
2104 inq_buff, &h->drv[drv_index]);
2106 @@ -1287,11 +1888,16 @@
2109 /* if it's the controller it's already added */
2113 disk->queue = blk_init_queue(do_cciss_request, &h->lock);
2114 + sprintf(disk->disk_name, "cciss/c%dd%d", ctlr, drv_index);
2115 + disk->major = h->major;
2116 + disk->first_minor = drv_index << NWD_SHIFT;
2117 + disk->fops = &cciss_fops;
2118 + disk->private_data = &h->drv[drv_index];
2120 /* Set up queue information */
2121 - disk->queue->backing_dev_info.ra_pages = READ_AHEAD;
2122 blk_queue_bounce_limit(disk->queue, hba[ctlr]->pdev->dma_mask);
2124 /* This is a hardware imposed limit. */
2125 @@ -1304,17 +1910,30 @@
2127 blk_queue_softirq_done(disk->queue, cciss_softirq_done);
2129 + blk_queue_max_sectors(disk->queue, hba[ctlr]->cciss_sector_size);
2131 disk->queue->queuedata = hba[ctlr];
2133 + if (!h->drv[drv_index].heads)
2136 blk_queue_hardsect_size(disk->queue,
2137 hba[ctlr]->drv[drv_index].block_size);
2140 + cciss_sysfs_stat_inquiry(ctlr, drv_index, 1, &h->drv[drv_index]);
2142 + cciss_add_blk_sysfs_dev(&h->drv[drv_index], disk, h->pdev, drv_index);
2144 + /* Make sure all queue data is written out before */
2145 + /* setting h->drv[drv_index].queue, as setting this */
2146 + /* allows the interrupt handler to start the queue */
2148 h->drv[drv_index].queue = disk->queue;
2157 @@ -1327,13 +1946,13 @@
2158 * where new drives will be added. If the index to be returned is greater
2159 * than the highest_lun index for the controller then highest_lun is set
2160 * to this new index. If there are no available indexes then -1 is returned.
2163 static int cciss_find_free_drive_index(int ctlr)
2167 - for (i=0; i < CISS_MAX_LUN; i++){
2168 - if (hba[ctlr]->drv[i].raid_level == -1){
2169 + for (i = 0; i < CISS_MAX_LUN; i++){
2170 + if (hba[ctlr]->drv[i].raid_level == -1) {
2171 if (i > hba[ctlr]->highest_lun)
2172 hba[ctlr]->highest_lun = i;
2174 @@ -1343,7 +1962,7 @@
2177 /* This function will add and remove logical drives from the Logical
2178 - * drive array of the controller and maintain persistancy of ordering
2179 + * drive array of the controller and maintain persistency of ordering
2180 * so that mount points are preserved until the next reboot. This allows
2181 * for the removal of logical drives in the middle of the drive array
2182 * without a re-ordering of those drives.
2183 @@ -1351,7 +1970,7 @@
2184 * h = The controller to perform the operations on
2185 * del_disk = The disk to remove if specified. If the value given
2186 * is NULL then no disk is removed.
2189 static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk)
2192 @@ -1368,12 +1987,7 @@
2194 /* Set busy_configuring flag for this operation */
2195 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2196 - if (h->num_luns >= CISS_MAX_LUN){
2197 - spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2201 - if (h->busy_configuring){
2202 + if (h->busy_configuring) {
2203 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2206 @@ -1383,7 +1997,7 @@
2207 * and update the logical drive table. If it is not NULL then
2208 * we will check if the disk is in use or not.
2210 - if (del_disk != NULL){
2211 + if (del_disk != NULL) {
2212 drv = get_drv(del_disk);
2213 drv->busy_configuring = 1;
2214 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2215 @@ -1405,11 +2019,9 @@
2218 if (return_code == IO_OK){
2219 - listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24;
2220 - listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
2221 - listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
2222 - listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
2223 - } else{ /* reading number of logical volumes failed */
2225 + be32_to_cpu(*(__u32 *) ld_buff->LUNListLength);
2226 + } else { /* reading number of logical volumes failed */
2227 printk(KERN_WARNING "cciss: report logical volume"
2228 " command failed\n");
2230 @@ -1417,7 +2029,7 @@
2233 num_luns = listlength / 8; /* 8 bytes per entry */
2234 - if (num_luns > CISS_MAX_LUN){
2235 + if (num_luns > CISS_MAX_LUN) {
2236 num_luns = CISS_MAX_LUN;
2237 printk(KERN_WARNING "cciss: more luns configured"
2238 " on controller than can be handled by"
2239 @@ -1428,7 +2040,7 @@
2240 * Check for updates in the drive information and any new drives
2241 * on the controller.
2243 - for (i=0; i < num_luns; i++){
2244 + for (i = 0; i < num_luns; i++) {
2248 @@ -1447,19 +2059,26 @@
2249 * if not is use. If it does not exist then find
2250 * the first free index and add it.
2252 - for (j=0; j <= h->highest_lun; j++){
2253 - if (h->drv[j].LunID == lunid){
2254 + for (j = 0; j <= h->highest_lun; j++) {
2255 + if (h->drv[j].LunID == lunid) {
2261 /* check if the drive was found already in the array */
2264 drv_index = cciss_find_free_drive_index(ctlr);
2265 if (drv_index == -1)
2268 + /*Check if the gendisk needs to be allocated */
2269 + if (!h->gendisk[drv_index]) {
2270 + h->gendisk[drv_index] = alloc_disk(1 << NWD_SHIFT);
2271 + if (!h->gendisk[drv_index]) {
2272 + printk(KERN_ERR "cciss: could not allocate new disk %d\n", drv_index);
2277 h->drv[drv_index].LunID = lunid;
2278 cciss_update_drive_info(ctlr, drv_index);
2279 @@ -1490,41 +2109,68 @@
2280 * clear_all = This flag determines whether or not the disk information
2281 * is going to be completely cleared out and the highest_lun
2282 * reset. Sometimes we want to clear out information about
2283 - * the disk in preperation for re-adding it. In this case
2284 + * the disk in preparation for re-adding it. In this case
2285 * the highest_lun should be left unchanged and the LunID
2286 * should not be cleared.
2288 static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
2292 ctlr_info_t *h = get_host(disk);
2294 if (!capable(CAP_SYS_RAWIO))
2297 /* make sure logical volume is NOT is use */
2298 - if(clear_all || (h->gendisk[0] == disk)) {
2299 + if (clear_all || (h->gendisk[0] == disk)) {
2300 if (drv->usage_count > 1)
2304 - if( drv->usage_count > 0 )
2305 + } else if (drv->usage_count > 0)
2308 /* invalidate the devices and deregister the disk. If it is disk
2309 * zero do not deregister it but just zero out it's values. This
2310 * allows us to delete disk zero but keep the controller registered.
2312 - if (h->gendisk[0] != disk){
2313 + if (h->gendisk[0] != disk) {
2315 request_queue_t *q = disk->queue;
2316 - if (disk->flags & GENHD_FL_UP)
2317 + if (disk->flags & GENHD_FL_UP) {
2318 + cciss_remove_blk_sysfs_dev(disk);
2322 blk_cleanup_queue(q);
2323 + /* Set drv->queue to NULL so that we do not try
2324 + * to call blk_start_queue on this queue in the
2325 + * interrupt handler
2329 + /* If clear_all is set then we are deleting the logical
2330 + * drive, not just refreshing its info. For drives
2331 + * other than disk 0 we will call put_disk. We do not
2332 + * do this for disk 0 as we need it to be able to
2333 + * configure the controller.
2336 + /* This isn't pretty, but we need to find the
2337 + * disk in our array and NULL our the pointer.
2338 + * This is so that we will call alloc_disk if
2339 + * this index is used again later.
2341 + for (i = 0; i < CISS_MAX_LUN; i++) {
2342 + if (h->gendisk[i] == disk) {
2343 + h->gendisk[i] = NULL;
2351 + set_capacity(disk, 0);
2355 @@ -1539,22 +2185,22 @@
2360 - /* check to see if it was the last disk */
2361 - if (drv == h->drv + h->highest_lun) {
2362 - /* if so, find the new hightest lun */
2363 - int i, newhighest =-1;
2364 - for(i=0; i<h->highest_lun; i++) {
2365 - /* if the disk has size > 0, it is available */
2366 - if (h->drv[i].heads)
2369 + /* check to see if it was the last disk */
2370 + if (drv == h->drv + h->highest_lun) {
2371 + /* if so, find the new hightest lun */
2372 + int i, newhighest = -1;
2373 + for (i = 0; i < h->highest_lun; i++) {
2374 + /* if the disk has size > 0, it is available */
2375 + if (h->drv[i].heads)
2378 + h->highest_lun = newhighest;
2380 - h->highest_lun = newhighest;
2390 static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
2391 @@ -1565,24 +2211,24 @@
2392 unsigned int log_unit, __u8 page_code, unsigned char *scsi3addr,
2395 - ctlr_info_t *h= hba[ctlr];
2396 + ctlr_info_t *h = hba[ctlr];
2397 u64bit buff_dma_handle;
2400 c->cmd_type = CMD_IOCTL_PEND;
2401 c->Header.ReplyQueue = 0;
2402 - if( buff != NULL) {
2403 + if (buff != NULL) {
2404 c->Header.SGList = 1;
2405 - c->Header.SGTotal= 1;
2406 + c->Header.SGTotal = 1;
2408 c->Header.SGList = 0;
2409 - c->Header.SGTotal= 0;
2410 + c->Header.SGTotal = 0;
2412 c->Header.Tag.lower = c->busaddr;
2414 c->Request.Type.Type = cmd_type;
2415 if (cmd_type == TYPE_CMD) {
2419 /* If the logical unit number is 0 then, this is going
2420 to controller so It's a physical command
2421 @@ -1592,15 +2238,16 @@
2422 otherwise, if use_unit_num == 2,
2423 mode = 0(periph dev addr) target = scsi3addr */
2424 if (use_unit_num == 1) {
2425 - c->Header.LUN.LogDev.VolId=
2426 + c->Header.LUN.LogDev.VolId =
2427 h->drv[log_unit].LunID;
2428 c->Header.LUN.LogDev.Mode = 1;
2429 } else if (use_unit_num == 2) {
2430 - memcpy(c->Header.LUN.LunAddrBytes,scsi3addr,8);
2431 + memcpy(c->Header.LUN.LunAddrBytes, scsi3addr,
2433 c->Header.LUN.LogDev.Mode = 0;
2435 /* are we trying to read a vital product page */
2436 - if(page_code != 0) {
2437 + if (page_code != 0) {
2438 c->Request.CDB[1] = 0x01;
2439 c->Request.CDB[2] = page_code;
2441 @@ -1636,6 +2283,20 @@
2442 c->Request.Timeout = 0;
2443 c->Request.CDB[0] = cmd;
2445 + case CCISS_READ_CAPACITY_16:
2446 + c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
2447 + c->Header.LUN.LogDev.Mode = 1;
2448 + c->Request.CDBLen = 16;
2449 + c->Request.Type.Attribute = ATTR_SIMPLE;
2450 + c->Request.Type.Direction = XFER_READ;
2451 + c->Request.Timeout = 0;
2452 + c->Request.CDB[0] = cmd;
2453 + c->Request.CDB[1] = 0x10;
2454 + c->Request.CDB[10] = (size >> 24) & 0xFF;
2455 + c->Request.CDB[11] = (size >> 16) & 0xFF;
2456 + c->Request.CDB[12] = (size >> 8) & 0xFF;
2457 + c->Request.CDB[13] = size & 0xFF;
2459 case CCISS_CACHE_FLUSH:
2460 c->Request.CDBLen = 12;
2461 c->Request.Type.Attribute = ATTR_SIMPLE;
2462 @@ -1647,7 +2308,7 @@
2465 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
2469 } else if (cmd_type == TYPE_MSG) {
2471 @@ -1669,6 +2330,7 @@
2472 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
2473 c->Request.CDB[0] = cmd; /* reset */
2474 c->Request.CDB[1] = 0x04; /* reset a LUN */
2476 case 3: /* No-Op message */
2477 c->Request.CDBLen = 1;
2478 c->Request.Type.Attribute = ATTR_SIMPLE;
2479 @@ -1698,6 +2360,7 @@
2484 static int sendcmd_withirq(__u8 cmd,
2487 @@ -1712,9 +2375,10 @@
2488 u64bit buff_dma_handle;
2489 unsigned long flags;
2491 - DECLARE_COMPLETION(wait);
2492 + int print_this_error = 1; /* by default print this error */
2493 + CCISS_DECLARE_COMPLETION(wait);
2495 - if ((c = cmd_alloc(h , 0)) == NULL)
2496 + if ((c = cmd_alloc(h, 0)) == NULL)
2498 return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2499 log_unit, page_code, NULL, cmd_type);
2500 @@ -1734,22 +2398,56 @@
2502 wait_for_completion(&wait);
2504 - if(c->err_info->CommandStatus != 0)
2505 - { /* an error has occurred */
2506 - switch(c->err_info->CommandStatus)
2508 + if(c->err_info->CommandStatus != 0) { /* an error has occurred */
2509 + switch(c->err_info->CommandStatus) {
2510 + unsigned char sense_key;
2511 case CMD_TARGET_STATUS:
2512 - printk(KERN_WARNING "cciss: cmd %p has "
2513 - " completed with errors\n", c);
2514 - if( c->err_info->ScsiStatus)
2516 - printk(KERN_WARNING "cciss: cmd %p "
2517 - "has SCSI Status = %x\n",
2519 - c->err_info->ScsiStatus);
2521 + return_status = IO_ERROR;
2522 + switch( c->err_info->ScsiStatus) {
2523 + case 0x02: /* Check Condition */
2524 + /* Check if condition is Unit
2527 + if((c->err_info->SenseInfo[2] == 6) &&
2528 + (c->retry_count < MAX_CMD_RETRIES))
2530 + printk(KERN_WARNING
2531 + "cciss%d: retrying unit "
2532 + "attention\n", ctlr);
2534 + /* erase old err info */
2535 + memset(c->err_info, 0,
2536 + sizeof(ErrorInfo_struct));
2537 + return_status = IO_OK;
2538 + INIT_COMPLETION(wait);
2541 + printk(KERN_WARNING "cciss%d: "
2542 + "has CHECK CONDITION "
2543 + "byte 2 = 0x%x\n", ctlr,
2544 + c->err_info->SenseInfo[2]);
2546 + /* check the sense key */
2548 + c->err_info->SenseInfo[2];
2550 + /* no status or recovered error */
2552 + if((sense_key == 0x0) ||
2553 + (sense_key == 0x1) )
2554 + return_status=IO_OK;
2556 + case 0x18: /* Reserve Conflict */
2557 + return_status=IO_ERROR;
2558 + print_this_error=0;
2561 + printk(KERN_WARNING "cciss%d:"
2562 + " cmd has SCSI Status"
2564 + c->err_info->ScsiStatus);
2567 case CMD_DATA_UNDERRUN:
2568 case CMD_DATA_OVERRUN:
2569 /* expected for inquire and report lun commands */
2570 @@ -1764,7 +2462,7 @@
2571 "protocol error \n", c);
2572 return_status = IO_ERROR;
2574 -case CMD_HARDWARE_ERR:
2575 + case CMD_HARDWARE_ERR:
2576 printk(KERN_WARNING "cciss: cmd %p had "
2577 " hardware error\n", c);
2578 return_status = IO_ERROR;
2579 @@ -1807,23 +2505,31 @@
2580 "unknown status %x\n", c,
2581 c->err_info->CommandStatus);
2582 return_status = IO_ERROR;
2587 + if ((return_status == IO_ERROR) && (print_this_error)) {
2591 /* unlock the buffers from DMA */
2592 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2593 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2594 - pci_unmap_single( h->pdev, (dma_addr_t) buff_dma_handle.val,
2595 + pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2596 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2598 - return(return_status);
2599 + return return_status;
2602 static void cciss_geometry_inquiry(int ctlr, int logvol,
2603 - int withirq, unsigned int total_size,
2604 + int withirq, sector_t total_size,
2605 unsigned int block_size, InquiryData_struct *inq_buff,
2606 drive_info_struct *drv)
2611 memset(inq_buff, 0, sizeof(InquiryData_struct));
2613 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
2614 @@ -1832,58 +2538,98 @@
2615 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
2616 sizeof(*inq_buff), 1, logvol ,0xC1, NULL, TYPE_CMD);
2617 if (return_code == IO_OK) {
2618 - if(inq_buff->data_byte[8] == 0xFF) {
2619 + if (inq_buff->data_byte[8] == 0xFF) {
2621 "cciss: reading geometry failed, volume "
2622 "does not support reading geometry\n");
2623 - drv->block_size = block_size;
2624 - drv->nr_blocks = total_size;
2626 drv->sectors = 32; // Sectors per track
2627 - drv->cylinders = total_size / 255 / 32;
2628 + drv->raid_level = RAID_UNKNOWN;
2632 - drv->block_size = block_size;
2633 - drv->nr_blocks = total_size;
2634 drv->heads = inq_buff->data_byte[6];
2635 drv->sectors = inq_buff->data_byte[7];
2636 drv->cylinders = (inq_buff->data_byte[4] & 0xff) << 8;
2637 drv->cylinders += inq_buff->data_byte[5];
2638 drv->raid_level = inq_buff->data_byte[8];
2639 - t = drv->heads * drv->sectors;
2641 - drv->cylinders = total_size/t;
2644 + drv->block_size = block_size;
2645 + drv->nr_blocks = total_size + 1;
2646 + t = drv->heads * drv->sectors;
2648 + sector_t real_size = total_size+1;
2649 + unsigned long rem = sector_div(real_size, t);
2652 + drv->cylinders = real_size;
2654 } else { /* Get geometry failed */
2655 printk(KERN_WARNING "cciss: reading geometry failed\n");
2657 - printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d\n\n",
2658 - drv->heads, drv->sectors, drv->cylinders);
2662 -cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
2663 - int withirq, unsigned int *total_size, unsigned int *block_size)
2664 +cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2665 + unsigned int *block_size)
2667 + ReadCapdata_struct *buf;
2669 - memset(buf, 0, sizeof(*buf));
2670 + buf = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2671 + if (buf == NULL) {
2672 + printk(KERN_WARNING "cciss: out of memory\n");
2675 + memset(buf, 0, sizeof(ReadCapdata_struct));
2678 return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
2679 - ctlr, buf, sizeof(*buf), 1, logvol, 0, TYPE_CMD);
2680 + ctlr, buf, sizeof(ReadCapdata_struct),
2681 + 1, logvol, 0, TYPE_CMD);
2683 return_code = sendcmd(CCISS_READ_CAPACITY,
2684 - ctlr, buf, sizeof(*buf), 1, logvol, 0, NULL, TYPE_CMD);
2685 + ctlr, buf, sizeof(ReadCapdata_struct),
2686 + 1, logvol, 0, NULL, TYPE_CMD);
2687 + if (return_code == IO_OK) {
2688 + *total_size = be32_to_cpu(*(__u32 *) buf->total_size);
2689 + *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
2690 + } else { /* read capacity command failed */
2691 + printk(KERN_WARNING "cciss: read capacity failed\n");
2693 + *block_size = BLOCK_SIZE;
2700 +cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size, unsigned int *block_size)
2702 + ReadCapdata_struct_16 *buf;
2704 + buf = kmalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2705 + if (buf == NULL) {
2706 + printk(KERN_WARNING "cciss: out of memory\n");
2709 + memset(buf, 0, sizeof(ReadCapdata_struct_16));
2711 + return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16,
2712 + ctlr, buf, sizeof(ReadCapdata_struct_16),
2713 + 1, logvol, 0, TYPE_CMD);
2716 + return_code = sendcmd(CCISS_READ_CAPACITY_16,
2717 + ctlr, buf, sizeof(ReadCapdata_struct_16),
2718 + 1, logvol, 0, NULL, TYPE_CMD);
2720 if (return_code == IO_OK) {
2721 - *total_size = be32_to_cpu(*((__be32 *) &buf->total_size[0]))+1;
2722 - *block_size = be32_to_cpu(*((__be32 *) &buf->block_size[0]));
2723 + *total_size = be64_to_cpu(*(__u64 *) buf->total_size);
2724 + *block_size = be32_to_cpu(*(__u32 *) buf->block_size);
2725 } else { /* read capacity command failed */
2726 printk(KERN_WARNING "cciss: read capacity failed\n");
2728 *block_size = BLOCK_SIZE;
2730 - printk(KERN_INFO " blocks= %u block_size= %d\n",
2731 - *total_size, *block_size);
2736 @@ -1894,8 +2640,7 @@
2739 unsigned int block_size;
2740 - unsigned int total_size;
2741 - ReadCapdata_struct *size_buff = NULL;
2742 + sector_t total_size;
2743 InquiryData_struct *inq_buff = NULL;
2745 for(logvol=0; logvol < CISS_MAX_LUN; logvol++)
2746 @@ -1908,27 +2653,24 @@
2748 if (!FOUND) return 1;
2750 - size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
2751 - if (size_buff == NULL)
2753 - printk(KERN_WARNING "cciss: out of memory\n");
2756 inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
2757 - if (inq_buff == NULL)
2759 + if (inq_buff == NULL) {
2760 printk(KERN_WARNING "cciss: out of memory\n");
2765 - cciss_read_capacity(h->ctlr, logvol, size_buff, 1, &total_size, &block_size);
2766 - cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, inq_buff, drv);
2767 + if (h->cciss_read == CCISS_READ_10) {
2768 + cciss_read_capacity(h->ctlr, logvol, 1,
2769 + &total_size, &block_size);
2771 + cciss_read_capacity_16(h->ctlr, logvol, 1,
2772 + &total_size, &block_size);
2774 + cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size,
2777 blk_queue_hardsect_size(drv->queue, drv->block_size);
2778 set_capacity(disk, drv->nr_blocks);
2784 @@ -1943,14 +2685,17 @@
2788 - /* Wait (up to 20 seconds) for a command to complete */
2789 + /* Increase timeout from 20 to 60 seconds to support a
2790 + * large number of logical volumes. Otherwise we may
2791 + * timeout during init.
2794 - for (i = 20 * HZ; i > 0; i--) {
2795 + for (i = 60 * HZ; i > 0; i--) {
2796 done = hba[ctlr]->access.command_completed(hba[ctlr]);
2797 if (done == FIFO_EMPTY)
2798 schedule_timeout_uninterruptible(1);
2803 /* Invalid address to tell caller we ran out of time */
2805 @@ -1978,7 +2723,7 @@
2806 /* or reset) then we don't expect anything weird. */
2807 if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) {
2809 - printk( KERN_WARNING "cciss cciss%d: SendCmd "
2810 + printk(KERN_WARNING "cciss cciss%d: SendCmd "
2811 "Invalid command list address returned! (%lx)\n",
2813 /* not much we can do. */
2814 @@ -1988,7 +2733,7 @@
2816 /* We've sent down an abort or reset, but something else
2818 - if (srl->ncompletions >= (NR_CMDS + 2)) {
2819 + if (srl->ncompletions >= (hba[ctlr]->nr_cmds + 2)) {
2820 /* Uh oh. No room to save it for later... */
2821 printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, "
2822 "reject list overflow, command lost!\n", ctlr);
2823 @@ -2021,13 +2766,15 @@
2824 CommandList_struct *c;
2826 unsigned long complete;
2827 - ctlr_info_t *info_p= hba[ctlr];
2828 + ctlr_info_t *info_p = hba[ctlr];
2829 u64bit buff_dma_handle;
2830 int status, done = 0;
2831 + unsigned char sense_key;
2832 + int print_this_error = 1; /* print errors by default */
2834 if ((c = cmd_alloc(info_p, 1)) == NULL) {
2835 printk(KERN_WARNING "cciss: unable to get memory");
2839 status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2840 log_unit, page_code, scsi3addr, cmd_type);
2841 @@ -2048,12 +2795,9 @@
2842 /* Actually it should be completely empty at this time */
2843 /* unless we are in here doing error handling for the scsi */
2844 /* tape side of the driver. */
2845 - for (i = 200000; i > 0; i--)
2847 + for (i = 200000; i > 0; i--) {
2848 /* if fifo isn't full go */
2849 - if (!(info_p->access.fifo_full(info_p)))
2852 + if (!(info_p->access.fifo_full(info_p))) {
2856 @@ -2081,11 +2825,9 @@
2861 /* This will need to change for direct lookup completions */
2862 - if ( (complete & CISS_ERROR_BIT)
2863 - && (complete & ~CISS_ERROR_BIT) == c->busaddr)
2865 + if ((complete & CISS_ERROR_BIT)
2866 + && (complete & ~CISS_ERROR_BIT) == c->busaddr) {
2867 /* if data overrun or underun on Report command
2870 @@ -2095,37 +2837,44 @@
2871 ((c->err_info->CommandStatus ==
2872 CMD_DATA_OVERRUN) ||
2873 (c->err_info->CommandStatus ==
2874 - CMD_DATA_UNDERRUN)
2877 + CMD_DATA_UNDERRUN))) {
2878 complete = c->busaddr;
2880 - if (c->err_info->CommandStatus ==
2881 - CMD_UNSOLICITED_ABORT) {
2882 + switch(c->err_info->CommandStatus) {
2883 + case CMD_UNSOLICITED_ABORT:
2884 printk(KERN_WARNING "cciss%d: "
2885 - "unsolicited abort %p\n",
2887 - if (c->retry_count < MAX_CMD_RETRIES) {
2888 + "unsolicited abort\n",
2890 + if (c->retry_count
2891 + < MAX_CMD_RETRIES) {
2893 - "cciss%d: retrying %p\n",
2900 - /* erase the old error */
2905 memset(c->err_info, 0,
2906 - sizeof(ErrorInfo_struct));
2907 + sizeof (ErrorInfo_struct));
2911 - "cciss%d: retried %p too "
2912 - "many times\n", ctlr, c);
2913 + "cciss%d: retried"
2915 + " times\n", ctlr);
2919 - } else if (c->err_info->CommandStatus == CMD_UNABORTABLE) {
2920 - printk(KERN_WARNING "cciss%d: command could not be aborted.\n", ctlr);
2922 + case CMD_UNABORTABLE:
2923 + printk(KERN_WARNING "cciss%d"
2924 + " command could not be"
2925 + " aborted.\n", ctlr);
2930 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2931 " Error %x \n", ctlr,
2932 @@ -2140,6 +2889,15 @@
2936 + if ((c->err_info->ScsiStatus) ==
2937 + CMD_RESERVATION_CONFLICT) {
2938 + printk(KERN_WARNING "cciss:%d"
2939 + " device is reserved."
2941 + print_this_error = 0;
2942 + status = IO_ERROR;
2945 /* This will need changing for direct lookup completions */
2946 if (complete != c->busaddr) {
2947 if (add_sendcmd_reject(cmd, ctlr, complete) != 0) {
2948 @@ -2151,6 +2909,10 @@
2953 + if ((status == IO_ERROR) && (print_this_error))
2956 /* unlock the data buffer from DMA */
2957 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2958 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2959 @@ -2162,7 +2924,7 @@
2960 do_cciss_intr(0, info_p, NULL);
2962 cmd_free(info_p, c, 1);
2967 * Map (physical) PCI mem into (virtual) kernel space
2968 @@ -2171,7 +2933,7 @@
2970 ulong page_base = ((ulong) base) & PAGE_MASK;
2971 ulong page_offs = ((ulong) base) - page_base;
2972 - void __iomem *page_remapped = ioremap(page_base, page_offs+size);
2973 + void __iomem *page_remapped = ioremap(page_base, page_offs + size);
2975 return page_remapped ? (page_remapped + page_offs) : NULL;
2977 @@ -2180,19 +2942,18 @@
2978 * Takes jobs of the Q and sends them to the hardware, then puts it on
2979 * the Q to wait for completion.
2981 -static void start_io( ctlr_info_t *h)
2982 +static void start_io(ctlr_info_t *h)
2984 CommandList_struct *c;
2986 - while(( c = h->reqQ) != NULL )
2988 + while(( c = h->reqQ) != NULL ) {
2989 /* can't do anything if fifo is full */
2990 if ((h->access.fifo_full(h))) {
2991 printk(KERN_WARNING "cciss: fifo full\n");
2995 - /* Get the frist entry from the Request Q */
2996 + /* Get the first entry from the Request Q */
2997 removeQ(&(h->reqQ), c);
3000 @@ -2200,145 +2961,220 @@
3001 h->access.submit_command(h, c);
3003 /* Put job onto the completed Q */
3004 - addQ (&(h->cmpQ), c);
3005 + addQ(&(h->cmpQ), c);
3008 /* Assumes that CCISS_LOCK(h->ctlr) is held. */
3009 /* Zeros out the error record and then resends the command back */
3010 /* to the controller */
3011 -static inline void resend_cciss_cmd( ctlr_info_t *h, CommandList_struct *c)
3012 +static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c)
3014 /* erase the old error information */
3015 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
3017 /* add it to software queue and then send it to the controller */
3018 - addQ(&(h->reqQ),c);
3019 + addQ(&(h->reqQ), c);
3021 - if(h->Qdepth > h->maxQsinceinit)
3022 + if (h->Qdepth > h->maxQsinceinit)
3023 h->maxQsinceinit = h->Qdepth;
3028 +static inline unsigned int make_status_bytes(unsigned int scsi_status_byte,
3029 + unsigned int msg_byte, unsigned int host_byte,
3030 + unsigned int driver_byte)
3032 + /* inverse of macros in scsi.h */
3033 + return (scsi_status_byte & 0xff) |
3034 + ((msg_byte & 0xff) << 8) |
3035 + ((host_byte & 0xff) << 16) |
3036 + ((driver_byte & 0xff) << 24);
3039 +static inline int evaluate_target_status(CommandList_struct *cmd)
3041 + unsigned char sense_key;
3042 + unsigned char status_byte, msg_byte, host_byte, driver_byte;
3045 + /* If we get in here, it means we got "target status", that is, scsi status */
3046 + status_byte = cmd->err_info->ScsiStatus;
3047 + driver_byte = DRIVER_OK;
3048 + msg_byte = cmd->err_info->CommandStatus; /* correct? seems too device specific */
3050 + if (blk_pc_request(cmd->rq))
3051 + host_byte = DID_PASSTHROUGH;
3053 + host_byte = DID_OK;
3055 + error_value = make_status_bytes(status_byte, msg_byte,
3056 + host_byte, driver_byte);
3058 + if (cmd->err_info->ScsiStatus != CMD_RESERVATION_CONFLICT) {
3059 + if (cmd->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION)
3060 + if (!blk_pc_request(cmd->rq))
3061 + printk(KERN_WARNING "cciss: cmd %p "
3062 + "has SCSI Status 0x%x\n",
3063 + cmd, cmd->err_info->ScsiStatus);
3064 + return error_value;
3067 + /* check the sense key */
3068 + sense_key = 0xf & cmd->err_info->SenseInfo[2];
3069 + /* no status or recovered error */
3070 + if (((sense_key == 0x0) || (sense_key == 0x1)) && !blk_pc_request(cmd->rq))
3073 + if (!blk_pc_request(cmd->rq)) { /* Not SG_IO or similar? */
3074 + if (error_value != 0)
3075 + printk(KERN_WARNING "cciss: cmd %p has CHECK CONDITION"
3076 + " sense key = 0x%x\n", cmd, sense_key);
3077 + return error_value;
3080 + /* SG_IO or similar, copy sense data back */
3081 + if (cmd->rq->sense) {
3082 + if (cmd->rq->sense_len > cmd->err_info->SenseLen)
3083 + cmd->rq->sense_len = cmd->err_info->SenseLen;
3084 + memcpy(cmd->rq->sense, cmd->err_info->SenseInfo,
3085 + cmd->rq->sense_len);
3087 + cmd->rq->sense_len = 0;
3089 + return error_value;
3092 /* checks the status of the job and calls complete buffers to mark all
3093 * buffers for the completed job. Note that this function does not need
3094 * to hold the hba/queue lock.
3096 -static inline void complete_command( ctlr_info_t *h, CommandList_struct *cmd,
3097 +static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
3103 + struct request *rq = cmd->rq;
3104 + int ctlr = h->ctlr;
3105 + int print_this_error = 1; /* print errors by default */
3110 + rq->errors = make_status_bytes(0, 0, 0, DRIVER_TIMEOUT);
3112 - if(cmd->err_info->CommandStatus != 0)
3113 - { /* an error has occurred */
3114 - switch(cmd->err_info->CommandStatus)
3116 - unsigned char sense_key;
3117 - case CMD_TARGET_STATUS:
3120 - if( cmd->err_info->ScsiStatus == 0x02)
3122 - printk(KERN_WARNING "cciss: cmd %p "
3123 - "has CHECK CONDITION "
3124 - " byte 2 = 0x%x\n", cmd,
3125 - cmd->err_info->SenseInfo[2]
3127 - /* check the sense key */
3129 - cmd->err_info->SenseInfo[2];
3130 - /* no status or recovered error */
3131 - if((sense_key == 0x0) ||
3132 - (sense_key == 0x1))
3138 - printk(KERN_WARNING "cciss: cmd %p "
3139 - "has SCSI Status 0x%x\n",
3140 - cmd, cmd->err_info->ScsiStatus);
3143 - case CMD_DATA_UNDERRUN:
3144 - printk(KERN_WARNING "cciss: cmd %p has"
3145 - " completed with data underrun "
3146 - "reported\n", cmd);
3148 - case CMD_DATA_OVERRUN:
3149 - printk(KERN_WARNING "cciss: cmd %p has"
3150 - " completed with data overrun "
3151 - "reported\n", cmd);
3154 - printk(KERN_WARNING "cciss: cmd %p is "
3155 - "reported invalid\n", cmd);
3158 - case CMD_PROTOCOL_ERR:
3159 - printk(KERN_WARNING "cciss: cmd %p has "
3160 - "protocol error \n", cmd);
3163 - case CMD_HARDWARE_ERR:
3164 - printk(KERN_WARNING "cciss: cmd %p had "
3165 - " hardware error\n", cmd);
3168 - case CMD_CONNECTION_LOST:
3169 - printk(KERN_WARNING "cciss: cmd %p had "
3170 - "connection lost\n", cmd);
3174 - printk(KERN_WARNING "cciss: cmd %p was "
3175 - "aborted\n", cmd);
3178 - case CMD_ABORT_FAILED:
3179 - printk(KERN_WARNING "cciss: cmd %p reports "
3180 - "abort failed\n", cmd);
3183 - case CMD_UNSOLICITED_ABORT:
3184 - printk(KERN_WARNING "cciss%d: unsolicited "
3185 - "abort %p\n", h->ctlr, cmd);
3186 - if (cmd->retry_count < MAX_CMD_RETRIES) {
3188 - printk(KERN_WARNING
3189 - "cciss%d: retrying %p\n",
3191 - cmd->retry_count++;
3193 - printk(KERN_WARNING
3194 - "cciss%d: %p retried too "
3195 - "many times\n", h->ctlr, cmd);
3199 - printk(KERN_WARNING "cciss: cmd %p timedout\n",
3204 - printk(KERN_WARNING "cciss: cmd %p returned "
3205 - "unknown status %x\n", cmd,
3206 - cmd->err_info->CommandStatus);
3209 + if(cmd->err_info->CommandStatus == 0) /* no error has occurred */
3210 + goto after_error_processing;
3212 + switch(cmd->err_info->CommandStatus) {
3213 + case CMD_TARGET_STATUS:
3214 + rq->errors = evaluate_target_status(cmd);
3216 + case CMD_DATA_UNDERRUN:
3217 + if (blk_fs_request(rq))
3218 + printk(KERN_WARNING "cciss: cmd %p has"
3219 + " completed with data underrun "
3220 + "reported\n", cmd);
3222 + case CMD_DATA_OVERRUN:
3223 + if (blk_fs_request(rq))
3224 + printk(KERN_WARNING "cciss: cmd %p has"
3225 + " completed with data overrun "
3226 + "reported\n", cmd);
3229 + printk(KERN_WARNING "cciss%d: cmd is "
3230 + "reported invalid\n", ctlr);
3231 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3232 + cmd->err_info->CommandStatus, DRIVER_OK,
3233 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3235 + case CMD_PROTOCOL_ERR:
3236 + printk(KERN_WARNING "cciss%d: cmd has "
3237 + "protocol error \n", ctlr);
3238 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3239 + cmd->err_info->CommandStatus, DRIVER_OK,
3240 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3242 + case CMD_HARDWARE_ERR:
3243 + printk(KERN_WARNING "cciss%d: cmd had "
3244 + " hardware error\n", ctlr);
3245 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3246 + cmd->err_info->CommandStatus, DRIVER_OK,
3247 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3249 + case CMD_CONNECTION_LOST:
3250 + printk(KERN_WARNING "cciss%d: cmd had "
3251 + "connection lost\n", ctlr);
3252 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3253 + cmd->err_info->CommandStatus, DRIVER_OK,
3254 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3257 + printk(KERN_WARNING "cciss%d: cmd was "
3258 + "aborted\n", ctlr);
3259 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3260 + cmd->err_info->CommandStatus, DRIVER_OK,
3261 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ABORT);
3263 + case CMD_ABORT_FAILED:
3264 + printk(KERN_WARNING "cciss%d: cmd reports "
3265 + "abort failed\n", ctlr);
3266 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3267 + cmd->err_info->CommandStatus, DRIVER_OK,
3268 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3270 + case CMD_UNSOLICITED_ABORT:
3271 + printk(KERN_WARNING "cciss%d: unsolicited "
3273 + if (cmd->retry_count < MAX_CMD_RETRIES) {
3275 + printk(KERN_WARNING
3276 + "cciss%d: retrying cmd\n", ctlr);
3277 + cmd->retry_count++;
3279 + printk(KERN_WARNING
3280 + "cciss%d: cmd retried too "
3281 + "many times\n", ctlr);
3282 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3283 + cmd->err_info->CommandStatus, DRIVER_OK,
3284 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ABORT);
3287 + printk(KERN_WARNING "cciss%d: cmd timedout\n", ctlr);
3288 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3289 + cmd->err_info->CommandStatus, DRIVER_OK,
3290 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3292 + case CMD_RESERVATION_CONFLICT:
3293 + printk(KERN_WARNING "reservation conflict in complete_command\n");
3294 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3295 + cmd->err_info->CommandStatus, DRIVER_OK,
3296 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3297 + print_this_error = 0;
3300 + printk(KERN_WARNING "cciss%d: cmd returned "
3301 + "unknown status %x\n", ctlr,
3302 + cmd->err_info->CommandStatus);
3303 + rq->errors = make_status_bytes(SAM_STAT_GOOD,
3304 + cmd->err_info->CommandStatus, DRIVER_OK,
3305 + blk_pc_request(rq) ? DID_PASSTHROUGH : DID_ERROR);
3308 +after_error_processing:
3310 /* We need to return this command */
3312 - resend_cciss_cmd(h,cmd);
3314 + resend_cciss_cmd(h, cmd);
3319 + if ((rq->errors != 0) && !blk_pc_request(rq) && print_this_error)
3322 cmd->rq->completion_data = cmd;
3323 - cmd->rq->errors = status;
3324 +#ifdef CONFIG_BLK_DEV_IO_TRACE
3325 + blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE);
3327 blk_complete_request(cmd->rq);
3330 @@ -2347,9 +3183,10 @@
3332 static void do_cciss_request(request_queue_t *q)
3334 - ctlr_info_t *h= q->queuedata;
3335 + ctlr_info_t *h = q->queuedata;
3336 CommandList_struct *c;
3337 - int start_blk, seg;
3338 + sector_t start_blk;
3340 struct request *creq;
3342 struct scatterlist tmp_sg[MAXSGENTRIES];
3343 @@ -2367,10 +3204,9 @@
3347 - if (creq->nr_phys_segments > MAXSGENTRIES)
3349 + BUG_ON(creq->nr_phys_segments > MAXSGENTRIES);
3351 - if (( c = cmd_alloc(h, 1)) == NULL)
3352 + if ((c = cmd_alloc(h, 1)) == NULL)
3355 blkdev_dequeue_request(creq);
3356 @@ -2388,7 +3224,7 @@
3357 /* The first 2 bits are reserved for controller error reporting. */
3358 c->Header.Tag.lower = (c->cmdindex << 3);
3359 c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */
3360 - c->Header.LUN.LogDev.VolId= drv->LunID;
3361 + c->Header.LUN.LogDev.VolId = drv->LunID;
3362 c->Header.LUN.LogDev.Mode = 1;
3363 c->Request.CDBLen = 10; // 12 byte commands not in FW yet;
3364 c->Request.Type.Type = TYPE_CMD; // It is a command.
3365 @@ -2396,10 +3232,10 @@
3366 c->Request.Type.Direction =
3367 (rq_data_dir(creq) == READ) ? XFER_READ: XFER_WRITE;
3368 c->Request.Timeout = 0; // Don't time out
3369 - c->Request.CDB[0] = (rq_data_dir(creq) == READ) ? CCISS_READ : CCISS_WRITE;
3370 + c->Request.CDB[0] = (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
3371 start_blk = creq->sector;
3373 - printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",(int) creq->sector,
3374 + printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector,
3375 (int) creq->nr_sectors);
3376 #endif /* CCISS_DEBUG */
3378 @@ -2411,8 +3247,7 @@
3380 dir = PCI_DMA_TODEVICE;
3382 - for (i=0; i<seg; i++)
3384 + for (i = 0; i < seg; i++) {
3385 c->SG[i].Len = tmp_sg[i].length;
3386 temp64.val = (__u64) pci_map_page(h->pdev, tmp_sg[i].page,
3387 tmp_sg[i].offset, tmp_sg[i].length,
3388 @@ -2422,7 +3257,7 @@
3389 c->SG[i].Ext = 0; // we are not chaining
3391 /* track how many SG entries we are using */
3392 - if( seg > h->maxSG)
3393 + if(seg > h->maxSG)
3397 @@ -2430,21 +3265,49 @@
3398 #endif /* CCISS_DEBUG */
3400 c->Header.SGList = c->Header.SGTotal = seg;
3401 - c->Request.CDB[1]= 0;
3402 - c->Request.CDB[2]= (start_blk >> 24) & 0xff; //MSB
3403 - c->Request.CDB[3]= (start_blk >> 16) & 0xff;
3404 - c->Request.CDB[4]= (start_blk >> 8) & 0xff;
3405 - c->Request.CDB[5]= start_blk & 0xff;
3406 - c->Request.CDB[6]= 0; // (sect >> 24) & 0xff; MSB
3407 - c->Request.CDB[7]= (creq->nr_sectors >> 8) & 0xff;
3408 - c->Request.CDB[8]= creq->nr_sectors & 0xff;
3409 - c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
3410 + if (likely(blk_fs_request(creq))) {
3411 + if(h->cciss_read == CCISS_READ_10) {
3412 + c->Request.CDB[1] = 0;
3413 + c->Request.CDB[2] = (start_blk >> 24) & 0xff; //MSB
3414 + c->Request.CDB[3] = (start_blk >> 16) & 0xff;
3415 + c->Request.CDB[4] = (start_blk >> 8) & 0xff;
3416 + c->Request.CDB[5] = start_blk & 0xff;
3417 + c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB
3418 + c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff;
3419 + c->Request.CDB[8] = creq->nr_sectors & 0xff;
3420 + c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
3422 + c->Request.CDBLen = 16;
3423 + c->Request.CDB[1] = 0;
3424 + c->Request.CDB[2] = (start_blk >> 56) & 0xff; //MSB
3425 + c->Request.CDB[3] = (start_blk >> 48) & 0xff;
3426 + c->Request.CDB[4] = (start_blk >> 40) & 0xff;
3427 + c->Request.CDB[5] = (start_blk >> 32) & 0xff;
3428 + c->Request.CDB[6] = (start_blk >> 24) & 0xff;
3429 + c->Request.CDB[7] = (start_blk >> 16) & 0xff;
3430 + c->Request.CDB[8] = (start_blk >> 8) & 0xff;
3431 + c->Request.CDB[9] = start_blk & 0xff;
3432 + c->Request.CDB[10] = (creq->nr_sectors >> 24) & 0xff;
3433 + c->Request.CDB[11] = (creq->nr_sectors >> 16) & 0xff;
3434 + c->Request.CDB[12] = (creq->nr_sectors >> 8) & 0xff;
3435 + c->Request.CDB[13] = creq->nr_sectors & 0xff;
3436 + c->Request.CDB[14] = c->Request.CDB[15] = 0;
3438 + } else if (blk_pc_request(creq)) {
3439 + c->Request.CDBLen = creq->cmd_len;
3440 + memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB);
3442 + /* In later kernels, rq->flags is supplanted by rq->cmd_type */
3443 + printk(KERN_WARNING "cciss%d: bad request type, rq->flags=%ld\n",
3444 + h->ctlr, creq->flags);
3448 spin_lock_irq(q->queue_lock);
3450 - addQ(&(h->reqQ),c);
3451 + addQ(&(h->reqQ), c);
3453 - if(h->Qdepth > h->maxQsinceinit)
3454 + if (h->Qdepth > h->maxQsinceinit)
3455 h->maxQsinceinit = h->Qdepth;
3458 @@ -2480,7 +3343,7 @@
3459 static inline int interrupt_pending(ctlr_info_t *h)
3461 #ifdef CONFIG_CISS_SCSI_TAPE
3462 - return ( h->access.intr_pending(h)
3463 + return (h->access.intr_pending(h)
3464 || (h->scsi_rejects.ncompletions > 0));
3466 return h->access.intr_pending(h);
3467 @@ -2505,8 +3368,6 @@
3468 CommandList_struct *c;
3469 unsigned long flags;
3472 - int start_queue = h->next_to_run;
3474 if (interrupt_not_for_us(h))
3476 @@ -2516,12 +3377,14 @@
3478 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
3479 while (interrupt_pending(h)) {
3480 - while((a = get_next_completion(h)) != FIFO_EMPTY) {
3481 + while ((a = get_next_completion(h)) != FIFO_EMPTY) {
3485 - if (a2 >= NR_CMDS) {
3486 + if (a2 >= h->nr_cmds) {
3487 printk(KERN_WARNING "cciss: controller cciss%d failed, stopping.\n", h->ctlr);
3488 + spin_unlock_irqrestore(
3489 + CCISS_LOCK(h->ctlr), flags);
3490 fail_all_cmds(h->ctlr);
3493 @@ -2535,7 +3398,7 @@
3494 printk(KERN_WARNING "cciss: Completion of %08x ignored\n", a1);
3497 - while(c->busaddr != a) {
3498 + while (c->busaddr != a) {
3502 @@ -2560,66 +3423,25 @@
3507 - /* check to see if we have maxed out the number of commands that can
3508 - * be placed on the queue. If so then exit. We do this check here
3509 - * in case the interrupt we serviced was from an ioctl and did not
3510 - * free any new commands.
3512 - if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
3515 - /* We have room on the queue for more commands. Now we need to queue
3516 - * them up. We will also keep track of the next queue to run so
3517 - * that every queue gets a chance to be started first.
3519 - for (j=0; j < h->highest_lun + 1; j++){
3520 - int curr_queue = (start_queue + j) % (h->highest_lun + 1);
3521 - /* make sure the disk has been added and the drive is real
3522 - * because this can be called from the middle of init_one.
3524 - if(!(h->drv[curr_queue].queue) ||
3525 - !(h->drv[curr_queue].heads))
3527 - blk_start_queue(h->gendisk[curr_queue]->queue);
3529 - /* check to see if we have maxed out the number of commands
3530 - * that can be placed on the queue.
3532 - if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
3534 - if (curr_queue == start_queue){
3535 - h->next_to_run = (start_queue + 1) % (h->highest_lun + 1);
3538 - h->next_to_run = curr_queue;
3542 - curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
3547 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
3551 - * We cannot read the structure directly, for portablity we must use
3552 + * We cannot read the structure directly, for portability we must use
3554 * This is for debug only.
3557 -static void print_cfg_table( CfgTable_struct *tb)
3558 +static void print_cfg_table(CfgTable_struct *tb)
3563 printk("Controller Configuration information\n");
3564 printk("------------------------------------\n");
3566 + for (i = 0; i < 4; i++)
3567 temp_name[i] = readb(&(tb->Signature[i]));
3568 - temp_name[4]='\0';
3569 + temp_name[4] = '\0';
3570 printk(" Signature = %s\n", temp_name);
3571 printk(" Spec Number = %d\n", readl(&(tb->SpecValence)));
3572 printk(" Transport methods supported = 0x%x\n",
3573 @@ -2628,14 +3450,14 @@
3574 readl(&(tb->TransportActive)));
3575 printk(" Requested transport Method = 0x%x\n",
3576 readl(&(tb->HostWrite.TransportRequest)));
3577 - printk(" Coalese Interrupt Delay = 0x%x\n",
3578 + printk(" Coalesce Interrupt Delay = 0x%x\n",
3579 readl(&(tb->HostWrite.CoalIntDelay)));
3580 - printk(" Coalese Interrupt Count = 0x%x\n",
3581 + printk(" Coalesce Interrupt Count = 0x%x\n",
3582 readl(&(tb->HostWrite.CoalIntCount)));
3583 printk(" Max outstanding commands = 0x%d\n",
3584 readl(&(tb->CmdsOutMax)));
3585 printk(" Bus Types = 0x%x\n", readl(&(tb-> BusTypes)));
3587 + for (i = 0; i < 16; i++)
3588 temp_name[i] = readb(&(tb->ServerName[i]));
3589 temp_name[16] = '\0';
3590 printk(" Server Name = %s\n", temp_name);
3591 @@ -2644,16 +3466,6 @@
3593 #endif /* CCISS_DEBUG */
3595 -static void release_io_mem(ctlr_info_t *c)
3597 - /* if IO mem was not protected do nothing */
3598 - if( c->io_mem_addr == 0)
3600 - release_region(c->io_mem_addr, c->io_mem_length);
3601 - c->io_mem_addr = 0;
3602 - c->io_mem_length = 0;
3605 static int find_PCI_BAR_index(struct pci_dev *pdev,
3606 unsigned long pci_bar_addr)
3608 @@ -2661,7 +3473,7 @@
3609 if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */
3612 - for (i=0; i<DEVICE_COUNT_RESOURCE; i++) {
3613 + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
3614 bar_type = pci_resource_flags(pdev, i) &
3615 PCI_BASE_ADDRESS_SPACE;
3616 if (bar_type == PCI_BASE_ADDRESS_SPACE_IO)
3617 @@ -2684,7 +3496,7 @@
3620 if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0)
3626 @@ -2692,8 +3504,8 @@
3627 /* If MSI/MSI-X is supported by the kernel we will try to enable it on
3628 * controllers that are capable. If not, we use IO-APIC mode.
3631 -static void __devinit cciss_interrupt_mode(ctlr_info_t *c, struct pci_dev *pdev, __u32 board_id)
3632 +static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
3633 + struct pci_dev *pdev, __u32 board_id)
3635 #ifdef CONFIG_PCI_MSI
3637 @@ -2719,26 +3531,24 @@
3640 printk(KERN_WARNING "cciss: only %d MSI-X vectors "
3641 - "available\n", err);
3642 + " available\n", err);
3643 + goto default_int_mode;
3645 - printk(KERN_WARNING "cciss: MSI-X init failed %d\n",
3647 + printk(KERN_WARNING "cciss: MSI-X init failed,"
3648 + " failure mode unknown, error = %d\n", err);
3649 + goto default_int_mode;
3652 if (pci_find_capability(pdev, PCI_CAP_ID_MSI)) {
3653 if (!pci_enable_msi(pdev)) {
3654 - c->intr[SIMPLE_MODE_INT] = pdev->irq;
3658 printk(KERN_WARNING "cciss: MSI init failed\n");
3659 - c->intr[SIMPLE_MODE_INT] = pdev->irq;
3664 #endif /* CONFIG_PCI_MSI */
3665 /* if we get here we're going to use the default interrupt mode */
3667 c->intr[SIMPLE_MODE_INT] = pdev->irq;
3670 @@ -2750,53 +3560,34 @@
3672 __u32 cfg_base_addr;
3673 __u64 cfg_base_addr_index;
3677 /* check to see if controller has been disabled */
3678 /* BEFORE trying to enable it */
3679 - (void) pci_read_config_word(pdev, PCI_COMMAND,&command);
3680 - if(!(command & 0x02))
3682 - printk(KERN_WARNING "cciss: controller appears to be disabled\n");
3684 + (void)pci_read_config_word(pdev, PCI_COMMAND,&command);
3685 + if (!(command & 0x02)) {
3686 + printk(KERN_WARNING
3687 + "cciss: controller appears to be disabled\n");
3691 - if (pci_enable_device(pdev))
3693 + err = pci_enable_device(pdev);
3695 printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
3700 + err = pci_request_regions(pdev, "cciss");
3702 + printk(KERN_ERR "cciss: Cannot obtain PCI resources, "
3704 + goto err_out_disable_pdev;
3706 subsystem_vendor_id = pdev->subsystem_vendor;
3707 subsystem_device_id = pdev->subsystem_device;
3708 board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) |
3709 subsystem_vendor_id);
3711 - /* search for our IO range so we can protect it */
3712 - for(i=0; i<DEVICE_COUNT_RESOURCE; i++)
3714 - /* is this an IO range */
3715 - if( pci_resource_flags(pdev, i) & 0x01 ) {
3716 - c->io_mem_addr = pci_resource_start(pdev, i);
3717 - c->io_mem_length = pci_resource_end(pdev, i) -
3718 - pci_resource_start(pdev, i) +1;
3720 - printk("IO value found base_addr[%d] %lx %lx\n", i,
3721 - c->io_mem_addr, c->io_mem_length);
3722 -#endif /* CCISS_DEBUG */
3723 - /* register the IO range */
3724 - if(!request_region( c->io_mem_addr,
3725 - c->io_mem_length, "cciss"))
3727 - printk(KERN_WARNING "cciss I/O memory range already in use addr=%lx length=%ld\n",
3728 - c->io_mem_addr, c->io_mem_length);
3729 - c->io_mem_addr= 0;
3730 - c->io_mem_length = 0;
3737 printk("command = %x\n", command);
3738 printk("irq = %x\n", pdev->irq);
3739 @@ -2817,11 +3608,11 @@
3741 printk("address 0 = %x\n", c->paddr);
3742 #endif /* CCISS_DEBUG */
3743 - c->vaddr = remap_pci_mem(c->paddr, 200);
3744 + c->vaddr = remap_pci_mem(c->paddr, 0x250);
3746 /* Wait for the board to become ready. (PCI hotplug needs this.)
3747 * We poll for up to 120 secs, once per 100ms. */
3748 - for (i=0; i < 1200; i++) {
3749 + for (i = 0; i < 1200; i++) {
3750 scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET);
3751 if (scratchpad == CCISS_FIRMWARE_READY)
3753 @@ -2830,7 +3621,8 @@
3755 if (scratchpad != CCISS_FIRMWARE_READY) {
3756 printk(KERN_WARNING "cciss: Board not ready. Timed out.\n");
3759 + goto err_out_free_res;
3762 /* get the address index number */
3763 @@ -2839,15 +3631,14 @@
3765 printk("cfg base address = %x\n", cfg_base_addr);
3766 #endif /* CCISS_DEBUG */
3767 - cfg_base_addr_index =
3768 - find_PCI_BAR_index(pdev, cfg_base_addr);
3769 + cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr);
3771 printk("cfg base address index = %x\n", cfg_base_addr_index);
3772 #endif /* CCISS_DEBUG */
3773 if (cfg_base_addr_index == -1) {
3774 printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
3775 - release_io_mem(c);
3778 + goto err_out_free_res;
3781 cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
3782 @@ -2863,19 +3654,14 @@
3783 print_cfg_table(c->cfgtable);
3784 #endif /* CCISS_DEBUG */
3786 - for(i=0; i<NR_PRODUCTS; i++) {
3787 + for (i = 0; i < ARRAY_SIZE(products); i++) {
3788 if (board_id == products[i].board_id) {
3789 c->product_name = products[i].product_name;
3790 c->access = *(products[i].access);
3791 + c->nr_cmds = products[i].nr_cmds;
3795 - if (i == NR_PRODUCTS) {
3796 - printk(KERN_WARNING "cciss: Sorry, I don't know how"
3797 - " to access the Smart Array controller %08lx\n",
3798 - (unsigned long)board_id);
3801 if ( (readb(&c->cfgtable->Signature[0]) != 'C') ||
3802 (readb(&c->cfgtable->Signature[1]) != 'I') ||
3803 (readb(&c->cfgtable->Signature[2]) != 'S') ||
3804 @@ -2885,6 +3671,27 @@
3808 + /* We didn't find the controller in our list. We know the
3809 + * signature is valid. If it's an HP device let's try to
3810 + * bind to the device and fire it up. Otherwise we bail.
3812 + if (i == ARRAY_SIZE(products)) {
3813 + if (subsystem_vendor_id == PCI_VENDOR_ID_HP) {
3814 + c->product_name = products[ARRAY_SIZE(products)-1].product_name;
3815 + c->access = *(products[ARRAY_SIZE(products)-1].access);
3816 + c->nr_cmds = products[ARRAY_SIZE(products)-1].nr_cmds;
3817 + printk(KERN_WARNING "cciss: This is an unknown "
3818 + "Smart Array controller.\n"
3819 + "cciss: Please update to the latest driver "
3820 + "available from www.hp.com.\n");
3822 + printk(KERN_WARNING "cciss: Sorry, I don't know how"
3823 + " to access the Smart Array controller %08lx\n"
3824 + , (unsigned long)board_id);
3831 /* Need to enable prefetch in the SCSI core for 6400 in x86 */
3832 @@ -2895,6 +3702,28 @@
3836 + /* Disabling DMA prefetch for the P600
3837 + * An ASIC bug may result in a prefetch beyond
3838 + * physical memory.
3840 + if(board_id == 0x3225103C) {
3841 + __u32 dma_prefetch;
3842 + dma_prefetch = readl(c->vaddr + I2O_DMA1_CFG);
3843 + dma_prefetch |= 0x8000;
3844 + writel(dma_prefetch, c->vaddr + I2O_DMA1_CFG);
3846 + /* On HP Integrity platforms, turn off DMA refetch
3850 + __u32 dma_refetch;
3851 + pci_read_config_dword(pdev, PCI_COMMAND_PARITY, &dma_refetch);
3852 + dma_refetch |= 0x1;
3853 + pci_write_config_dword(pdev, PCI_COMMAND_PARITY, dma_refetch);
3859 printk("Trying to put board into Simple mode\n");
3860 #endif /* CCISS_DEBUG */
3861 @@ -2907,7 +3736,7 @@
3862 /* under certain very rare conditions, this can take awhile.
3863 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
3864 * as we enter this code.) */
3865 - for(i=0;i<MAX_CONFIG_WAIT;i++) {
3866 + for (i = 0; i < MAX_CONFIG_WAIT; i++) {
3867 if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
3869 /* delay and try again */
3870 @@ -2922,14 +3751,20 @@
3871 print_cfg_table(c->cfgtable);
3872 #endif /* CCISS_DEBUG */
3874 - if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple))
3876 + if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
3877 printk(KERN_WARNING "cciss: unable to get board into"
3881 + goto err_out_free_res;
3886 + pci_release_regions(pdev);
3888 +err_out_disable_pdev:
3889 + pci_disable_device(pdev);
3894 @@ -2938,48 +3773,34 @@
3895 static void cciss_getgeometry(int cntl_num)
3897 ReportLunData_struct *ld_buff;
3898 - ReadCapdata_struct *size_buff;
3899 InquiryData_struct *inq_buff;
3906 + sector_t total_size;
3908 - ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
3909 - if (ld_buff == NULL)
3911 + ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
3912 + if (ld_buff == NULL) {
3913 printk(KERN_ERR "cciss: out of memory\n");
3916 - memset(ld_buff, 0, sizeof(ReportLunData_struct));
3917 - size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
3918 - if (size_buff == NULL)
3920 - printk(KERN_ERR "cciss: out of memory\n");
3924 - inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
3925 - if (inq_buff == NULL)
3927 + inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
3928 + if (inq_buff == NULL) {
3929 printk(KERN_ERR "cciss: out of memory\n");
3934 /* Get the firmware version */
3935 return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
3936 sizeof(InquiryData_struct), 0, 0 ,0, NULL, TYPE_CMD);
3937 - if (return_code == IO_OK)
3939 + if (return_code == IO_OK) {
3940 hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32];
3941 hba[cntl_num]->firm_ver[1] = inq_buff->data_byte[33];
3942 hba[cntl_num]->firm_ver[2] = inq_buff->data_byte[34];
3943 hba[cntl_num]->firm_ver[3] = inq_buff->data_byte[35];
3944 - } else /* send command failed */
3946 + } else { /* send command failed */
3947 printk(KERN_WARNING "cciss: unable to determine firmware"
3948 " version of controller\n");
3950 @@ -2987,8 +3808,7 @@
3951 return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff,
3952 sizeof(ReportLunData_struct), 0, 0, 0, NULL, TYPE_CMD);
3954 - if( return_code == IO_OK)
3956 + if (return_code == IO_OK) {
3958 printk("LUN Data\n--------------------------\n");
3959 #endif /* CCISS_DEBUG */
3960 @@ -2997,15 +3817,14 @@
3961 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
3962 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
3963 listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
3964 - } else /* reading number of logical volumes failed */
3967 + /* reading number of logical volumes failed */
3968 printk(KERN_WARNING "cciss: report logical volume"
3969 " command failed\n");
3972 - hba[cntl_num]->num_luns = listlength / 8; // 8 bytes pre entry
3973 - if (hba[cntl_num]->num_luns > CISS_MAX_LUN)
3975 + hba[cntl_num]->num_luns = listlength / 8; // 8 bytes per entry
3976 + if (hba[cntl_num]->num_luns > CISS_MAX_LUN) {
3977 printk(KERN_ERR "ciss: only %d number of logical volumes supported\n",
3979 hba[cntl_num]->num_luns = CISS_MAX_LUN;
3980 @@ -3016,11 +3835,9 @@
3981 ld_buff->LUNListLength[3], hba[cntl_num]->num_luns);
3982 #endif /* CCISS_DEBUG */
3984 - hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns-1;
3985 -// for(i=0; i< hba[cntl_num]->num_luns; i++)
3986 - for(i=0; i < CISS_MAX_LUN; i++)
3988 - if (i < hba[cntl_num]->num_luns){
3989 + hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns - 1;
3990 + for (i = 0; i < CISS_MAX_LUN; i++) {
3991 + if (i < hba[cntl_num]->num_luns) {
3992 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3]))
3994 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2]))
3995 @@ -3031,15 +3848,33 @@
3997 hba[cntl_num]->drv[i].LunID = lunid;
4001 printk(KERN_DEBUG "LUN[%d]: %x %x %x %x = %x\n", i,
4002 ld_buff->LUN[i][0], ld_buff->LUN[i][1],
4003 ld_buff->LUN[i][2], ld_buff->LUN[i][3],
4004 hba[cntl_num]->drv[i].LunID);
4005 #endif /* CCISS_DEBUG */
4006 - cciss_read_capacity(cntl_num, i, size_buff, 0,
4007 - &total_size, &block_size);
4009 + /* testing to see if 16-byte CDBs are already being used */
4010 + if(hba[cntl_num]->cciss_read == CCISS_READ_16) {
4011 + cciss_read_capacity_16(cntl_num, i, 0,
4012 + &total_size, &block_size);
4015 + cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size);
4017 + /* If read_capacity returns all F's the volume is >2TB */
4018 + /* so we switch to 16-byte CDBs for all read/write ops */
4019 + if(total_size == 0xFFFFFFFFULL) {
4020 + cciss_read_capacity_16(cntl_num, i, 0,
4021 + &total_size, &block_size);
4022 + hba[cntl_num]->cciss_read = CCISS_READ_16;
4023 + hba[cntl_num]->cciss_write = CCISS_WRITE_16;
4025 + hba[cntl_num]->cciss_read = CCISS_READ_10;
4026 + hba[cntl_num]->cciss_write = CCISS_WRITE_10;
4029 cciss_geometry_inquiry(cntl_num, i, 0, total_size,
4030 block_size, inq_buff, &hba[cntl_num]->drv[i]);
4032 @@ -3048,7 +3883,6 @@
4040 @@ -3056,35 +3890,29 @@
4041 /* Returns -1 if no free entries are left. */
4042 static int alloc_cciss_hba(void)
4044 - struct gendisk *disk[NWD];
4046 - for (n = 0; n < NWD; n++) {
4047 - disk[n] = alloc_disk(1 << NWD_SHIFT);
4053 - for(i=0; i< MAX_CTLR; i++) {
4054 + for (i = 0; i < MAX_CTLR; i++) {
4057 p = kmalloc(sizeof(ctlr_info_t), GFP_KERNEL);
4060 memset(p, 0, sizeof(ctlr_info_t));
4061 - for (n = 0; n < NWD; n++)
4062 - p->gendisk[n] = disk[n];
4063 + p->gendisk[0] = alloc_disk(1 << NWD_SHIFT);
4064 + if (!p->gendisk[0]) {
4072 printk(KERN_WARNING "cciss: This driver supports a maximum"
4073 " of %d controllers.\n", MAX_CTLR);
4077 printk(KERN_ERR "cciss: out of memory.\n");
4080 - put_disk(disk[n]);
4084 @@ -3094,7 +3922,7 @@
4088 - for (n = 0; n < NWD; n++)
4089 + for (n = 0; n < CISS_MAX_LUN; n++)
4090 put_disk(p->gendisk[n]);
4093 @@ -3107,18 +3935,19 @@
4094 static int __devinit cciss_init_one(struct pci_dev *pdev,
4095 const struct pci_device_id *ent)
4097 - request_queue_t *q;
4104 + InquiryData_struct *inq_buff;
4106 printk(KERN_DEBUG "cciss: Device 0x%x has been found at"
4107 " bus %d dev %d func %d\n",
4108 pdev->device, pdev->bus->number, PCI_SLOT(pdev->devfn),
4109 PCI_FUNC(pdev->devfn));
4110 i = alloc_cciss_hba();
4116 hba[i]->busy_initializing = 1;
4118 @@ -3131,11 +3960,11 @@
4120 /* configure PCI DMA stuff */
4121 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK))
4122 - printk("cciss: using DAC cycles\n");
4124 else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4125 - printk("cciss: not using DAC cycles\n");
4128 - printk("cciss: no suitable DMA available\n");
4129 + printk(KERN_ERR "cciss: no suitable DMA available\n");
4133 @@ -3147,45 +3976,62 @@
4134 if (i < MAX_CTLR_ORIG)
4135 hba[i]->major = COMPAQ_CISS_MAJOR + i;
4136 rc = register_blkdev(hba[i]->major, hba[i]->devname);
4137 - if(rc == -EBUSY || rc == -EINVAL) {
4138 + if (rc == -EBUSY || rc == -EINVAL) {
4140 "cciss: Unable to get major number %d for %s "
4141 "on hba %d\n", hba[i]->major, hba[i]->devname, i);
4146 if (i >= MAX_CTLR_ORIG)
4150 /* make sure the board interrupts are off */
4151 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
4152 - if( request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
4153 - SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
4154 + /* If we are running in IO-APIC or MSI mode we register only
4155 + * one interrupt. If we're running MSI-X mode we must register
4156 + * four interrupts because the hardware ORing is ignored.
4158 + if (hba[i]->msix_vector) {
4159 + for (k = 0; k < 4; k++) {
4160 + if (request_irq(hba[i]->intr[k], do_cciss_intr,
4161 + SA_INTERRUPT | SA_SAMPLE_RANDOM,
4162 + hba[i]->devname, hba[i])) {
4163 + printk(KERN_ERR "cciss: Unable to get msi irq %d"
4165 + hba[i]->intr[k], hba[i]->devname);
4170 + if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
4171 + SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
4172 hba[i]->devname, hba[i])) {
4173 - printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
4174 - hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname);
4176 + printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
4177 + hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname);
4181 - hba[i]->cmd_pool_bits = kmalloc(((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long), GFP_KERNEL);
4183 + hba[i]->cmd_pool_bits = kmalloc(((hba[i]->nr_cmds+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long), GFP_KERNEL);
4184 hba[i]->cmd_pool = (CommandList_struct *)pci_alloc_consistent(
4185 - hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
4186 + hba[i]->pdev, hba[i]->nr_cmds * sizeof(CommandList_struct),
4187 &(hba[i]->cmd_pool_dhandle));
4188 hba[i]->errinfo_pool = (ErrorInfo_struct *)pci_alloc_consistent(
4189 - hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
4190 + hba[i]->pdev, hba[i]->nr_cmds * sizeof( ErrorInfo_struct),
4191 &(hba[i]->errinfo_pool_dhandle));
4192 - if((hba[i]->cmd_pool_bits == NULL)
4193 + if ((hba[i]->cmd_pool_bits == NULL)
4194 || (hba[i]->cmd_pool == NULL)
4195 || (hba[i]->errinfo_pool == NULL)) {
4196 - printk( KERN_ERR "cciss: out of memory");
4197 + printk(KERN_ERR "cciss: out of memory");
4200 #ifdef CONFIG_CISS_SCSI_TAPE
4201 hba[i]->scsi_rejects.complete =
4202 kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) *
4203 - (NR_CMDS + 5), GFP_KERNEL);
4204 + (hba[i]->nr_cmds + 5), GFP_KERNEL);
4205 if (hba[i]->scsi_rejects.complete == NULL) {
4206 - printk( KERN_ERR "cciss: out of memory");
4207 + printk(KERN_ERR "cciss: out of memory");
4211 @@ -3196,10 +4042,10 @@
4212 pci_set_drvdata(pdev, hba[i]);
4213 /* command and error info recs zeroed out before
4215 - memset(hba[i]->cmd_pool_bits, 0, ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long));
4216 + memset(hba[i]->cmd_pool_bits, 0, ((hba[i]->nr_cmds+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long));
4219 - printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n",i);
4220 + printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n", i);
4221 #endif /* CCISS_DEBUG */
4223 cciss_getgeometry(i);
4224 @@ -3210,22 +4056,35 @@
4225 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
4228 + hba[i]->cciss_sector_size = 2048;
4230 hba[i]->busy_initializing = 0;
4232 - for(j=0; j < NWD; j++) { /* mfm */
4234 drive_info_struct *drv = &(hba[i]->drv[j]);
4235 struct gendisk *disk = hba[i]->gendisk[j];
4236 + request_queue_t *q;
4238 + /* Check if the disk was allocated already */
4240 + hba[i]->gendisk[j] = alloc_disk(1 << NWD_SHIFT);
4241 + disk = hba[i]->gendisk[j];
4244 + /* Check that the disk was able to be allocated */
4246 + printk(KERN_ERR "cciss: unable to allocate memory for disk %d\n", j);
4250 q = blk_init_queue(do_cciss_request, &hba[i]->lock);
4253 "cciss: unable to allocate queue for disk %d\n",
4260 - q->backing_dev_info.ra_pages = READ_AHEAD;
4261 blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask);
4263 /* This is a hardware imposed limit. */
4264 @@ -3234,130 +4093,181 @@
4265 /* This is a limit in the driver and could be eliminated. */
4266 blk_queue_max_phys_segments(q, MAXSGENTRIES);
4268 - blk_queue_max_sectors(q, 512);
4269 + blk_queue_max_sectors(q, hba[i]->cciss_sector_size);
4271 blk_queue_softirq_done(q, cciss_softirq_done);
4273 q->queuedata = hba[i];
4274 - sprintf(disk->disk_name, "cciss/c%dd%d", i, j);
4275 - sprintf(disk->devfs_name, "cciss/host%d/target%d", i, j);
4276 - disk->major = hba[i]->major;
4277 - disk->first_minor = j << NWD_SHIFT;
4278 - disk->fops = &cciss_fops;
4280 - disk->private_data = drv;
4281 /* we must register the controller even if no disks exist */
4282 /* this is for the online array utilities */
4283 - if(!drv->heads && j)
4284 + if (!drv->heads && j)
4286 blk_queue_hardsect_size(q, drv->block_size);
4287 + cciss_sysfs_stat_inquiry(i, j, 1, drv);
4288 + cciss_add_blk_sysfs_dev(drv, disk, pdev, j);
4289 set_capacity(disk, drv->nr_blocks);
4290 + sprintf(disk->disk_name, "cciss/c%dd%d", i, j);
4291 + disk->major = hba[i]->major;
4292 + disk->first_minor = j << NWD_SHIFT;
4293 + disk->fops = &cciss_fops;
4294 + disk->private_data = drv;
4300 + } while (j <= hba[i]->highest_lun);
4306 #ifdef CONFIG_CISS_SCSI_TAPE
4307 - if(hba[i]->scsi_rejects.complete)
4308 - kfree(hba[i]->scsi_rejects.complete);
4309 + kfree(hba[i]->scsi_rejects.complete);
4311 kfree(hba[i]->cmd_pool_bits);
4312 - if(hba[i]->cmd_pool)
4313 + if (hba[i]->cmd_pool)
4314 pci_free_consistent(hba[i]->pdev,
4315 - NR_CMDS * sizeof(CommandList_struct),
4316 + hba[i]->nr_cmds * sizeof(CommandList_struct),
4317 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
4318 - if(hba[i]->errinfo_pool)
4319 + if (hba[i]->errinfo_pool)
4320 pci_free_consistent(hba[i]->pdev,
4321 - NR_CMDS * sizeof( ErrorInfo_struct),
4322 + hba[i]->nr_cmds * sizeof( ErrorInfo_struct),
4323 hba[i]->errinfo_pool,
4324 hba[i]->errinfo_pool_dhandle);
4325 - free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]);
4326 + if (hba[i]->msix_vector) {
4327 + for (j = 0; j < 4; j++)
4328 + free_irq(hba[i]->intr[j], hba[i]);
4330 + free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]);
4332 +#ifdef CONFIG_PCI_MSI
4333 + if (hba[i]->msix_vector)
4334 + pci_disable_msix(hba[i]->pdev);
4335 + else if (hba[i]->msi_vector)
4336 + pci_disable_msi(hba[i]->pdev);
4337 +#endif /* CONFIG_PCI_MSI */
4339 unregister_blkdev(hba[i]->major, hba[i]->devname);
4341 - release_io_mem(hba[i]);
4342 hba[i]->busy_initializing = 0;
4343 + /* cleanup any queues that may have been initialized */
4344 + for (j = 0; j <= hba[i]->highest_lun; j++){
4345 + drive_info_struct *drv = &(hba[i]->drv[j]);
4347 + blk_cleanup_queue(drv->queue);
4349 + pci_release_regions(pdev);
4350 + /* This call to pci_disable_device causes the driver to be unable
4351 + * to load/unload multiple times. No reason why yet, but we are
4352 + * leaving it out for now.
4354 +// pci_disable_device(pdev);
4355 + pci_set_drvdata(pdev, NULL);
4361 -static void __devexit cciss_remove_one (struct pci_dev *pdev)
4362 +static void cciss_shutdown (struct pci_dev *pdev)
4364 ctlr_info_t *tmp_ptr;
4369 - if (pci_get_drvdata(pdev) == NULL)
4371 - printk( KERN_ERR "cciss: Unable to remove device \n");
4374 tmp_ptr = pci_get_drvdata(pdev);
4375 + if (tmp_ptr == NULL)
4378 - if (hba[i] == NULL)
4380 - printk(KERN_ERR "cciss: device appears to "
4381 - "already be removed \n");
4382 + if (hba[i] == NULL)
4386 /* Turn board interrupts off and send the flush cache command */
4387 /* sendcmd will turn off interrupt, and send the flush...
4388 * To write all data in the battery backed cache to disks */
4389 memset(flush_buf, 0, 4);
4390 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL,
4392 - if(return_code != IO_OK)
4394 + if(return_code != IO_OK) {
4395 printk(KERN_WARNING "Error Flushing cache on controller %d\n",
4398 - free_irq(hba[i]->intr[2], hba[i]);
4399 + if (hba[i]->msix_vector) {
4400 + for (j = 0; j < 4; j++)
4401 + free_irq(hba[i]->intr[j], hba[i]);
4403 + free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]);
4407 -#ifdef CONFIG_PCI_MSI
4408 - if (hba[i]->msix_vector)
4409 - pci_disable_msix(hba[i]->pdev);
4410 - else if (hba[i]->msi_vector)
4411 - pci_disable_msi(hba[i]->pdev);
4412 -#endif /* CONFIG_PCI_MSI */
4413 +static void __devexit cciss_remove_one(struct pci_dev *pdev)
4415 + ctlr_info_t *tmp_ptr;
4418 - pci_set_drvdata(pdev, NULL);
4419 - iounmap(hba[i]->vaddr);
4420 - cciss_unregister_scsi(i); /* unhook from SCSI subsystem */
4421 + if (pci_get_drvdata(pdev) == NULL) {
4422 + printk(KERN_ERR "cciss: Unable to remove device \n");
4425 + tmp_ptr = pci_get_drvdata(pdev);
4426 + i = tmp_ptr->ctlr;
4427 + if (hba[i] == NULL) {
4428 + printk(KERN_ERR "cciss: device appears to "
4429 + "already be removed \n");
4433 + remove_proc_entry(hba[i]->devname, proc_cciss);
4434 unregister_blkdev(hba[i]->major, hba[i]->devname);
4435 - remove_proc_entry(hba[i]->devname, proc_cciss);
4438 /* remove it from the disk list */
4439 - for (j = 0; j < NWD; j++) {
4440 + for (j = 0; j < CISS_MAX_LUN; j++) {
4441 struct gendisk *disk = hba[i]->gendisk[j];
4443 request_queue_t *q = disk->queue;
4445 - if (disk->flags & GENHD_FL_UP)
4446 + if (disk->flags & GENHD_FL_UP)
4447 + cciss_remove_blk_sysfs_dev(disk);
4450 blk_cleanup_queue(q);
4454 - pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
4455 + cciss_unregister_scsi(i); /* unhook from SCSI subsystem */
4457 + cciss_shutdown(pdev);
4459 +#ifdef CONFIG_PCI_MSI
4460 + if (hba[i]->msix_vector)
4461 + pci_disable_msix(hba[i]->pdev);
4462 + else if (hba[i]->msi_vector)
4463 + pci_disable_msi(hba[i]->pdev);
4464 +#endif /* CONFIG_PCI_MSI */
4466 + iounmap(hba[i]->vaddr);
4468 + pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(CommandList_struct),
4469 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
4470 - pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
4471 - hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
4472 + pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct),
4473 + hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
4474 kfree(hba[i]->cmd_pool_bits);
4475 #ifdef CONFIG_CISS_SCSI_TAPE
4476 kfree(hba[i]->scsi_rejects.complete);
4478 - release_io_mem(hba[i]);
4480 + * Deliberately omit pci_disable_device(): it does something nasty to
4481 + * Smart Array controllers that pci_enable_device does not undo
4483 + pci_release_regions(pdev);
4484 + pci_set_drvdata(pdev, NULL);
4489 static struct pci_driver cciss_pci_driver = {
4491 - .probe = cciss_init_one,
4492 - .remove = __devexit_p(cciss_remove_one),
4493 - .id_table = cciss_pci_device_id, /* id_table */
4495 + .probe = cciss_init_one,
4496 + .remove = __devexit_p(cciss_remove_one),
4497 + .id_table = cciss_pci_device_id, /* id_table */
4498 + .shutdown = cciss_shutdown,
4502 @@ -3378,10 +4288,8 @@
4504 pci_unregister_driver(&cciss_pci_driver);
4505 /* double check that all controller entrys have been removed */
4506 - for (i=0; i< MAX_CTLR; i++)
4508 - if (hba[i] != NULL)
4510 + for (i = 0; i < MAX_CTLR; i++) {
4511 + if (hba[i] != NULL) {
4512 printk(KERN_WARNING "cciss: had to remove"
4513 " controller %d\n", i);
4514 cciss_remove_one(hba[i]->pdev);
4515 @@ -3405,14 +4313,14 @@
4516 pci_disable_device(h->pdev); /* Make sure it is really dead. */
4518 /* move everything off the request queue onto the completed queue */
4519 - while( (c = h->reqQ) != NULL ) {
4520 + while ((c = h->reqQ) != NULL) {
4521 removeQ(&(h->reqQ), c);
4523 - addQ (&(h->cmpQ), c);
4524 + addQ(&(h->cmpQ), c);
4527 /* Now, fail everything on the completed queue with a HW error */
4528 - while( (c = h->cmpQ) != NULL ) {
4529 + while ((c = h->cmpQ) != NULL) {
4530 removeQ(&h->cmpQ, c);
4531 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
4532 if (c->cmd_type == CMD_RWREQ) {
4533 diff -uNr linux-2.6.16.orig/drivers/block/cciss_cmd.h linux-2.6.16/drivers/block/cciss_cmd.h
4534 --- linux-2.6.16.orig/drivers/block/cciss_cmd.h 2006-03-20 06:53:29.000000000 +0100
4535 +++ linux-2.6.16/drivers/block/cciss_cmd.h 2008-10-03 02:40:19.000000000 +0200
4537 //general boundary defintions
4538 #define SENSEINFOBYTES 32//note that this value may vary between host implementations
4539 #define MAXSGENTRIES 31
4540 -#define MAXREPLYQS 256
4541 +#define MAXREPLYQS 1024
4543 //Command Status value
4544 #define CMD_SUCCESS 0x0000
4546 #define CMD_UNSOLICITED_ABORT 0x000A
4547 #define CMD_TIMEOUT 0x000B
4548 #define CMD_UNABORTABLE 0x000C
4549 +#define CMD_RESERVATION_CONFLICT 0x0018
4551 //transfer direction
4552 #define XFER_NONE 0x00
4554 #define I2O_INT_MASK 0x34
4555 #define I2O_IBPOST_Q 0x40
4556 #define I2O_OBPOST_Q 0x44
4557 +#define I2O_DMA1_CFG 0x214
4559 //Configuration Table
4560 #define CFGTBL_ChangeReq 0x00000001l
4562 //###########################################################################
4564 //###########################################################################
4565 -#define CISS_MAX_LUN 16
4566 +#define CISS_MAX_LUN 1024
4567 #define CISS_MAX_PHYS_LUN 1024
4570 @@ -118,11 +120,34 @@
4571 BYTE block_size[4]; // Size of blocks in bytes
4572 } ReadCapdata_struct;
4574 -// 12 byte commands not implemented in firmware yet.
4575 -// #define CCISS_READ 0xa8 // Read(12)
4576 -// #define CCISS_WRITE 0xaa // Write(12)
4577 - #define CCISS_READ 0x28 // Read(10)
4578 - #define CCISS_WRITE 0x2a // Write(10)
4579 +#define CCISS_READ_CAPACITY_16 0x9e /* Read Capacity 16 */
4581 +/* service action to differentiate a 16 byte read capacity from
4582 + other commands that use the 0x9e SCSI op code */
4584 +#define CCISS_READ_CAPACITY_16_SERVICE_ACT 0x10
4586 +typedef struct _ReadCapdata_struct_16
4588 + BYTE total_size[8]; /* Total size in blocks */
4589 + BYTE block_size[4]; /* Size of blocks in bytes */
4590 + BYTE prot_en:1; /* protection enable bit */
4591 + BYTE rto_en:1; /* reference tag own enable bit */
4592 + BYTE reserved:6; /* reserved bits */
4593 + BYTE reserved2[18]; /* reserved bytes per spec */
4594 +} ReadCapdata_struct_16;
4596 +/* Define the supported read/write commands for cciss based controllers */
4598 +#define CCISS_READ_10 0x28 /* Read(10) */
4599 +#define CCISS_WRITE_10 0x2a /* Write(10) */
4600 +#define CCISS_READ_16 0x88 /* Read(16) */
4601 +#define CCISS_WRITE_16 0x8a /* Write(16) */
4603 +/* Define the CDB lengths supported by cciss based controllers */
4605 +#define CDB_LEN10 10
4606 +#define CDB_LEN16 16
4609 #define BMIC_READ 0x26
4610 diff -uNr linux-2.6.16.orig/drivers/block/cciss.h linux-2.6.16/drivers/block/cciss.h
4611 --- linux-2.6.16.orig/drivers/block/cciss.h 2006-03-20 06:53:29.000000000 +0100
4612 +++ linux-2.6.16/drivers/block/cciss.h 2008-10-03 02:40:19.000000000 +0200
4614 #include "cciss_cmd.h"
4619 #define MAX_PART (1 << NWD_SHIFT)
4622 * the drive is not in use/configured
4624 int busy_configuring; /*This is set when the drive is being removed
4625 - *to prevent it from being opened or it's queue
4626 - *from being started.
4627 + *to prevent it from being opened or it's
4628 + *queue from being started.
4634 + struct device *dev_info;
4635 } drive_info_struct;
4637 #ifdef CONFIG_CISS_SCSI_TAPE
4639 struct sendcmd_reject_list {
4641 - unsigned long *complete; /* array of NR_CMDS tags */
4642 + unsigned long *complete; /* array of tags */
4648 void __iomem *vaddr;
4649 unsigned long paddr;
4650 - unsigned long io_mem_addr;
4651 - unsigned long io_mem_length;
4652 + int nr_cmds; /* Number of commands allowed on this controller */
4653 CfgTable_struct __iomem *cfgtable;
4654 int interrupts_enabled;
4657 unsigned int intr[4];
4658 unsigned int msix_vector;
4659 unsigned int msi_vector;
4660 + int cciss_sector_size; /* For setting blk_queue_max_sectors */
4663 + BYTE cciss_read_capacity;
4665 // information about each logical volume
4666 drive_info_struct drv[CISS_MAX_LUN];
4670 // Disk structures we need to pass back
4671 - struct gendisk *gendisk[NWD];
4672 + struct gendisk *gendisk[CISS_MAX_LUN];
4673 #ifdef CONFIG_CISS_SCSI_TAPE
4674 void *scsi_ctlr; /* ptr to structure containing scsi related stuff */
4675 /* list of block side commands the scsi error handling sucked up */
4676 @@ -144,6 +151,17 @@
4678 #define CCISS_INTR_ON 1
4679 #define CCISS_INTR_OFF 0
4681 +static inline ctlr_info_t *get_host(struct gendisk *disk)
4683 + return disk->queue->queuedata;
4686 +static inline drive_info_struct *get_drv(struct gendisk *disk)
4688 + return disk->private_data;
4692 Send the command to the hardware
4694 @@ -281,9 +299,21 @@
4697 struct access_method *access;
4698 + int nr_cmds; /* Max cmds to send to this kind of ctlr. */
4701 +struct drv_dynamic {
4702 + struct device dev; /* should be the first member */
4703 + struct gendisk *disk;
4706 #define CCISS_LOCK(i) (&hba[i]->lock)
4708 +#ifdef DECLARE_COMPLETION_ONSTACK
4709 +#define CCISS_DECLARE_COMPLETION(work) DECLARE_COMPLETION_ONSTACK(work)
4711 +#define CCISS_DECLARE_COMPLETION(work) DECLARE_COMPLETION(work)
4714 #endif /* CCISS_H */
4716 diff -uNr linux-2.6.16.orig/drivers/block/cciss_scsi.c linux-2.6.16/drivers/block/cciss_scsi.c
4717 --- linux-2.6.16.orig/drivers/block/cciss_scsi.c 2006-03-20 06:53:29.000000000 +0100
4718 +++ linux-2.6.16/drivers/block/cciss_scsi.c 2008-10-03 02:40:19.000000000 +0200
4721 #include <asm/atomic.h>
4723 -#include <scsi/scsi.h>
4724 #include <scsi/scsi_cmnd.h>
4725 #include <scsi/scsi_device.h>
4726 #include <scsi/scsi_host.h>
4728 #include "cciss_scsi.h"
4731 #define CCISS_ABORT_MSG 0x00
4732 #define CCISS_RESET_MSG 0x01
4734 #define DEVICETYPE(n) (n<0 || n>MAX_SCSI_DEVICE_CODE) ? \
4735 "Unknown" : scsi_device_types[n]
4738 static int xmargin=8;
4739 static int amargin=60;
4747 print_cmd(CommandList_struct *cp)
4749 @@ -329,18 +329,21 @@
4750 cp->ErrDesc.Addr.upper, cp->ErrDesc.Addr.lower,
4752 printk("sgs..........Errorinfo:\n");
4753 - printk("scsistatus:%d\n", cp->err_info->ScsiStatus);
4754 - printk("senselen:%d\n", cp->err_info->SenseLen);
4755 - printk("cmd status:%d\n", cp->err_info->CommandStatus);
4756 - printk("resid cnt:%d\n", cp->err_info->ResidualCnt);
4757 - printk("offense size:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_size);
4758 - printk("offense byte:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_num);
4759 - printk("offense value:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
4760 + printk("scsistatus: 0x%x\n", cp->err_info->ScsiStatus);
4761 + printk("senselen: 0x%x\n", cp->err_info->SenseLen);
4762 + printk("cmd status: 0x%x\n", cp->err_info->CommandStatus);
4763 + printk("resid cnt: 0x%x\n", cp->err_info->ResidualCnt);
4765 + /* If this is a check condition print the SenseInfo */
4766 + if ((cp->err_info->SenseInfo[2] & 0x0F) == 0x02)
4767 + print_bytes(cp->err_info->SenseInfo, cp->err_info->SenseLen, 1, 0);
4769 + printk("offense size: 0x%x\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_size);
4770 + printk("offense byte: 0x%x\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_num);
4771 + printk("offense value: 0x%x\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
4778 find_bus_target_lun(int ctlr, int *bus, int *target, int *lun)
4783 pci_unmap_sg(ctlr->pdev,
4784 - cmd->buffer, cmd->use_sg,
4785 + cmd->request_buffer, cmd->use_sg,
4786 cmd->sc_data_direction);
4788 else if (cmd->request_bufflen) {
4792 case CMD_PROTOCOL_ERR:
4793 + cmd->result = DID_ERROR << 16;
4794 printk(KERN_WARNING "cciss: cp %p has "
4795 "protocol error \n", cp);
4800 unsigned long flags;
4801 - DECLARE_COMPLETION(wait);
4802 + CCISS_DECLARE_COMPLETION(wait);
4804 cp->cmd_type = CMD_IOCTL_PEND; // treat this like an ioctl
4805 cp->scsi_cmd = NULL;
4806 @@ -1211,7 +1215,7 @@
4807 struct scsi_cmnd *cmd)
4809 unsigned int use_sg, nsegs=0, len;
4810 - struct scatterlist *scatter = (struct scatterlist *) cmd->buffer;
4811 + struct scatterlist *scatter = (struct scatterlist *) cmd->request_buffer;
4814 /* is it just one virtual address? */
4815 @@ -1233,7 +1237,7 @@
4816 } /* else, must be a list of virtual addresses.... */
4817 else if (cmd->use_sg <= MAXSGENTRIES) { /* not too many addrs? */
4819 - use_sg = pci_map_sg(pdev, cmd->buffer, cmd->use_sg,
4820 + use_sg = pci_map_sg(pdev, cmd->request_buffer, cmd->use_sg,
4821 cmd->sc_data_direction);
4823 for (nsegs=0; nsegs < use_sg; nsegs++) {
4824 @@ -1441,21 +1445,18 @@
4828 -cciss_proc_tape_report(int ctlr, unsigned char *buffer, off_t *pos, off_t *len)
4829 +cciss_seq_tape_report(struct seq_file *seq, int ctlr)
4831 unsigned long flags;
4834 - *pos = *pos -1; *len = *len - 1; // cut off the last trailing newline
4836 CPQ_TAPE_LOCK(ctlr, flags);
4837 - size = sprintf(buffer + *len,
4839 "Sequential access devices: %d\n\n",
4840 ccissscsi[ctlr].ndevices);
4841 CPQ_TAPE_UNLOCK(ctlr, flags);
4842 - *pos += size; *len += size;
4846 /* Need at least one of these error handlers to keep ../scsi/hosts.c from
4847 * complaining. Doing a host- or bus-reset can't do anything good here.
4848 * Despite what it might say in scsi_error.c, there may well be commands
4849 @@ -1535,6 +1536,5 @@
4850 #define cciss_scsi_setup(cntl_num)
4851 #define cciss_unregister_scsi(ctlr)
4852 #define cciss_register_scsi(ctlr)
4853 -#define cciss_proc_tape_report(ctlr, buffer, pos, len)
4855 #endif /* CONFIG_CISS_SCSI_TAPE */
4856 diff -uNr linux-2.6.16.orig/include/linux/cciss_ioctl.h linux-2.6.16/include/linux/cciss_ioctl.h
4857 --- linux-2.6.16.orig/include/linux/cciss_ioctl.h 2006-03-20 06:53:29.000000000 +0100
4858 +++ linux-2.6.16/include/linux/cciss_ioctl.h 2008-10-03 02:40:19.000000000 +0200
4862 unsigned char dev_fn;
4863 - unsigned short domain;
4866 } cciss_pci_info_struct;
4872 -#define CISS_MAX_LUN 16
4873 +#define CISS_MAX_LUN 256
4875 #define LEVEL2LUN 1 // index into Target(x) structure, due to byte swapping