2 * Disk Array driver for HP Smart Array SAS controllers
3 * Copyright 2000, 2009 Hewlett-Packard Development Company, L.P.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * Questions/Comments/Bugfixes to iss_storagedev@hp.com
22 #include <linux/module.h>
23 #include <linux/interrupt.h>
24 #include <linux/types.h>
25 #include <linux/pci.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
30 #include <linux/timer.h>
31 #include <linux/seq_file.h>
32 #include <linux/init.h>
33 #include <linux/spinlock.h>
34 #include <linux/smp_lock.h>
35 #include <linux/compat.h>
36 #include <linux/blktrace_api.h>
37 #include <linux/uaccess.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/completion.h>
41 #include <linux/moduleparam.h>
42 #include <scsi/scsi.h>
43 #include <scsi/scsi_cmnd.h>
44 #include <scsi/scsi_device.h>
45 #include <scsi/scsi_host.h>
46 #include <linux/cciss_ioctl.h>
47 #include <linux/string.h>
48 #include <linux/bitmap.h>
49 #include <asm/atomic.h>
53 /* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */
54 #define HPSA_DRIVER_VERSION "1.0.0"
55 #define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")"
57 /* How long to wait (in milliseconds) for board to go into simple mode */
58 #define MAX_CONFIG_WAIT 30000
59 #define MAX_IOCTL_CONFIG_WAIT 1000
61 /*define how many times we will try a command because of bus resets */
62 #define MAX_CMD_RETRIES 3
64 /* Embedded module documentation macros - see modules.h */
65 MODULE_AUTHOR("Hewlett-Packard Company");
66 MODULE_DESCRIPTION("Driver for HP Smart Array Controller version " \
68 MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
69 MODULE_VERSION(HPSA_DRIVER_VERSION
);
70 MODULE_LICENSE("GPL");
72 static int hpsa_allow_any
;
73 module_param(hpsa_allow_any
, int, S_IRUGO
|S_IWUSR
);
74 MODULE_PARM_DESC(hpsa_allow_any
,
75 "Allow hpsa driver to access unknown HP Smart Array hardware");
77 /* define the PCI info for the cards we can control */
78 static const struct pci_device_id hpsa_pci_device_id
[] = {
79 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSC
, 0x103C, 0x3223},
80 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSC
, 0x103C, 0x3234},
81 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSC
, 0x103C, 0x323D},
82 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x3241},
83 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x3243},
84 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x3245},
85 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x3247},
86 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x3249},
87 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x324a},
88 {PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_CISSE
, 0x103C, 0x324b},
89 {PCI_VENDOR_ID_HP
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_ANY_ID
,
90 PCI_CLASS_STORAGE_RAID
<< 8, 0xffff << 8, 0},
94 MODULE_DEVICE_TABLE(pci
, hpsa_pci_device_id
);
96 /* board_id = Subsystem Device ID & Vendor ID
97 * product = Marketing Name for the board
98 * access = Address of the struct of function pointers
100 static struct board_type products
[] = {
101 {0x3223103C, "Smart Array P800", &SA5_access
},
102 {0x3234103C, "Smart Array P400", &SA5_access
},
103 {0x323d103c, "Smart Array P700M", &SA5_access
},
104 {0x3241103C, "Smart Array P212", &SA5_access
},
105 {0x3243103C, "Smart Array P410", &SA5_access
},
106 {0x3245103C, "Smart Array P410i", &SA5_access
},
107 {0x3247103C, "Smart Array P411", &SA5_access
},
108 {0x3249103C, "Smart Array P812", &SA5_access
},
109 {0x324a103C, "Smart Array P712m", &SA5_access
},
110 {0x324b103C, "Smart Array P711m", &SA5_access
},
111 {0xFFFF103C, "Unknown Smart Array", &SA5_access
},
114 static int number_of_controllers
;
116 static irqreturn_t
do_hpsa_intr(int irq
, void *dev_id
);
117 static int hpsa_ioctl(struct scsi_device
*dev
, int cmd
, void *arg
);
118 static void start_io(struct ctlr_info
*h
);
119 static int sendcmd(__u8 cmd
, struct ctlr_info
*h
, void *buff
, size_t size
,
120 __u8 page_code
, unsigned char *scsi3addr
, int cmd_type
);
123 static int hpsa_compat_ioctl(struct scsi_device
*dev
, int cmd
, void *arg
);
126 static void cmd_free(struct ctlr_info
*h
, struct CommandList
*c
);
127 static void cmd_special_free(struct ctlr_info
*h
, struct CommandList
*c
);
128 static struct CommandList
*cmd_alloc(struct ctlr_info
*h
);
129 static struct CommandList
*cmd_special_alloc(struct ctlr_info
*h
);
130 static int fill_cmd(struct CommandList
*c
, __u8 cmd
, struct ctlr_info
*h
,
131 void *buff
, size_t size
, __u8 page_code
, unsigned char *scsi3addr
,
133 static int sendcmd_core(struct ctlr_info
*h
, struct CommandList
*c
);
135 static int hpsa_scsi_queue_command(struct scsi_cmnd
*cmd
,
136 void (*done
)(struct scsi_cmnd
*));
138 static int hpsa_eh_device_reset_handler(struct scsi_cmnd
*scsicmd
);
139 static int hpsa_slave_alloc(struct scsi_device
*sdev
);
140 static void hpsa_slave_destroy(struct scsi_device
*sdev
);
142 static ssize_t
raid_level_show(struct device
*dev
,
143 struct device_attribute
*attr
, char *buf
);
144 static ssize_t
lunid_show(struct device
*dev
,
145 struct device_attribute
*attr
, char *buf
);
146 static ssize_t
unique_id_show(struct device
*dev
,
147 struct device_attribute
*attr
, char *buf
);
149 DEVICE_ATTR(raid_level
, S_IRUGO
, raid_level_show
, NULL
);
150 DEVICE_ATTR(lunid
, S_IRUGO
, lunid_show
, NULL
);
151 DEVICE_ATTR(unique_id
, S_IRUGO
, unique_id_show
, NULL
);
153 struct device_attribute
*hpsa_sdev_attrs
[] = {
154 &dev_attr_raid_level
,
160 static struct scsi_host_template hpsa_driver_template
= {
161 .module
= THIS_MODULE
,
164 .queuecommand
= hpsa_scsi_queue_command
,
167 .sg_tablesize
= MAXSGENTRIES
,
169 .use_clustering
= ENABLE_CLUSTERING
,
170 .eh_device_reset_handler
= hpsa_eh_device_reset_handler
,
172 .slave_alloc
= hpsa_slave_alloc
,
173 .slave_destroy
= hpsa_slave_destroy
,
175 .compat_ioctl
= hpsa_compat_ioctl
,
177 .sdev_attrs
= hpsa_sdev_attrs
,
180 /* Enqueuing and dequeuing functions for cmdlists. */
181 static inline void addQ(struct hlist_head
*list
, struct CommandList
*c
)
183 hlist_add_head(&c
->list
, list
);
186 static void enqueue_cmd_and_start_io(struct ctlr_info
*h
,
187 struct CommandList
*c
)
190 spin_lock_irqsave(&h
->lock
, flags
);
194 spin_unlock_irqrestore(&h
->lock
, flags
);
197 static inline void removeQ(struct CommandList
*c
)
199 if (WARN_ON(hlist_unhashed(&c
->list
)))
201 hlist_del_init(&c
->list
);
204 static inline int is_hba_lunid(unsigned char scsi3addr
[])
206 return memcmp(scsi3addr
, RAID_CTLR_LUNID
, 8) == 0;
209 static inline int is_logical_dev_addr_mode(unsigned char scsi3addr
[])
211 return (scsi3addr
[3] & 0xC0) == 0x40;
214 static const char *raid_label
[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
217 #define RAID_UNKNOWN (ARRAY_SIZE(raid_label) - 1)
219 static ssize_t
raid_level_show(struct device
*dev
,
220 struct device_attribute
*attr
, char *buf
)
225 struct scsi_device
*sdev
;
226 struct hpsa_scsi_dev_t
*hdev
;
229 sdev
= to_scsi_device(dev
);
230 h
= (struct ctlr_info
*) sdev
->host
->hostdata
[0];
231 spin_lock_irqsave(&h
->lock
, flags
);
232 hdev
= sdev
->hostdata
;
234 spin_unlock_irqrestore(&h
->lock
, flags
);
238 /* Is this even a logical drive? */
239 if (!is_logical_dev_addr_mode(hdev
->scsi3addr
)) {
240 spin_unlock_irqrestore(&h
->lock
, flags
);
241 l
= snprintf(buf
, PAGE_SIZE
, "N/A\n");
245 rlevel
= hdev
->raid_level
;
246 spin_unlock_irqrestore(&h
->lock
, flags
);
247 if (rlevel
< 0 || rlevel
> RAID_UNKNOWN
)
248 rlevel
= RAID_UNKNOWN
;
249 l
= snprintf(buf
, PAGE_SIZE
, "RAID %s\n", raid_label
[rlevel
]);
253 static ssize_t
lunid_show(struct device
*dev
,
254 struct device_attribute
*attr
, char *buf
)
257 struct scsi_device
*sdev
;
258 struct hpsa_scsi_dev_t
*hdev
;
260 unsigned char lunid
[8];
262 sdev
= to_scsi_device(dev
);
263 h
= (struct ctlr_info
*) sdev
->host
->hostdata
[0];
264 spin_lock_irqsave(&h
->lock
, flags
);
265 hdev
= sdev
->hostdata
;
267 spin_unlock_irqrestore(&h
->lock
, flags
);
270 memcpy(lunid
, hdev
->scsi3addr
, sizeof(lunid
));
271 spin_unlock_irqrestore(&h
->lock
, flags
);
272 return snprintf(buf
, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
273 lunid
[0], lunid
[1], lunid
[2], lunid
[3],
274 lunid
[4], lunid
[5], lunid
[6], lunid
[7]);
277 static ssize_t
unique_id_show(struct device
*dev
,
278 struct device_attribute
*attr
, char *buf
)
281 struct scsi_device
*sdev
;
282 struct hpsa_scsi_dev_t
*hdev
;
284 unsigned char sn
[16];
286 sdev
= to_scsi_device(dev
);
287 h
= (struct ctlr_info
*) sdev
->host
->hostdata
[0];
288 spin_lock_irqsave(&h
->lock
, flags
);
289 hdev
= sdev
->hostdata
;
291 spin_unlock_irqrestore(&h
->lock
, flags
);
294 memcpy(sn
, hdev
->device_id
, sizeof(sn
));
295 spin_unlock_irqrestore(&h
->lock
, flags
);
296 return snprintf(buf
, 16 * 2 + 2,
297 "%02X%02X%02X%02X%02X%02X%02X%02X"
298 "%02X%02X%02X%02X%02X%02X%02X%02X\n",
299 sn
[0], sn
[1], sn
[2], sn
[3],
300 sn
[4], sn
[5], sn
[6], sn
[7],
301 sn
[8], sn
[9], sn
[10], sn
[11],
302 sn
[12], sn
[13], sn
[14], sn
[15]);
305 static int hpsa_find_target_lun(struct ctlr_info
*h
,
306 unsigned char scsi3addr
[], int bus
, int *target
, int *lun
)
308 /* finds an unused bus, target, lun for a new physical device
309 * assumes h->devlock is held
312 DECLARE_BITMAP(lun_taken
, HPSA_MAX_SCSI_DEVS_PER_HBA
);
314 memset(&lun_taken
[0], 0, HPSA_MAX_SCSI_DEVS_PER_HBA
>> 3);
316 for (i
= 0; i
< h
->ndevices
; i
++) {
317 if (h
->dev
[i
]->bus
== bus
&& h
->dev
[i
]->target
!= -1)
318 set_bit(h
->dev
[i
]->target
, lun_taken
);
321 for (i
= 0; i
< HPSA_MAX_SCSI_DEVS_PER_HBA
; i
++) {
322 if (!test_bit(i
, lun_taken
)) {
333 /* Add an entry into h->dev[] array. */
334 static int hpsa_scsi_add_entry(struct ctlr_info
*h
, int hostno
,
335 struct hpsa_scsi_dev_t
*device
,
336 struct hpsa_scsi_dev_t
*added
[], int *nadded
)
338 /* assumes h->devlock is held */
341 unsigned char addr1
[8], addr2
[8];
342 struct hpsa_scsi_dev_t
*sd
;
344 if (n
>= HPSA_MAX_SCSI_DEVS_PER_HBA
) {
345 dev_err(&h
->pdev
->dev
, "too many devices, some will be "
350 /* physical devices do not have lun or target assigned until now. */
351 if (device
->lun
!= -1)
352 /* Logical device, lun is already assigned. */
355 /* If this device a non-zero lun of a multi-lun device
356 * byte 4 of the 8-byte LUN addr will contain the logical
357 * unit no, zero otherise.
359 if (device
->scsi3addr
[4] == 0) {
360 /* This is not a non-zero lun of a multi-lun device */
361 if (hpsa_find_target_lun(h
, device
->scsi3addr
,
362 device
->bus
, &device
->target
, &device
->lun
) != 0)
367 /* This is a non-zero lun of a multi-lun device.
368 * Search through our list and find the device which
369 * has the same 8 byte LUN address, excepting byte 4.
370 * Assign the same bus and target for this new LUN.
371 * Use the logical unit number from the firmware.
373 memcpy(addr1
, device
->scsi3addr
, 8);
375 for (i
= 0; i
< n
; i
++) {
377 memcpy(addr2
, sd
->scsi3addr
, 8);
379 /* differ only in byte 4? */
380 if (memcmp(addr1
, addr2
, 8) == 0) {
381 device
->bus
= sd
->bus
;
382 device
->target
= sd
->target
;
383 device
->lun
= device
->scsi3addr
[4];
387 if (device
->lun
== -1) {
388 dev_warn(&h
->pdev
->dev
, "physical device with no LUN=0,"
389 " suspect firmware bug or unsupported hardware "
398 added
[*nadded
] = device
;
401 /* initially, (before registering with scsi layer) we don't
402 * know our hostno and we don't want to print anything first
403 * time anyway (the scsi layer's inquiries will show that info)
405 /* if (hostno != -1) */
406 dev_info(&h
->pdev
->dev
, "%s device c%db%dt%dl%d added.\n",
407 scsi_device_type(device
->devtype
), hostno
,
408 device
->bus
, device
->target
, device
->lun
);
412 /* Remove an entry from h->dev[] array. */
413 static void hpsa_scsi_remove_entry(struct ctlr_info
*h
, int hostno
, int entry
,
414 struct hpsa_scsi_dev_t
*removed
[], int *nremoved
)
416 /* assumes h->devlock is held */
418 struct hpsa_scsi_dev_t
*sd
;
420 if (entry
< 0 || entry
>= HPSA_MAX_SCSI_DEVS_PER_HBA
)
424 removed
[*nremoved
] = h
->dev
[entry
];
427 for (i
= entry
; i
< h
->ndevices
-1; i
++)
428 h
->dev
[i
] = h
->dev
[i
+1];
430 dev_info(&h
->pdev
->dev
, "%s device c%db%dt%dl%d removed.\n",
431 scsi_device_type(sd
->devtype
), hostno
, sd
->bus
, sd
->target
,
435 #define SCSI3ADDR_EQ(a, b) ( \
436 (a)[7] == (b)[7] && \
437 (a)[6] == (b)[6] && \
438 (a)[5] == (b)[5] && \
439 (a)[4] == (b)[4] && \
440 (a)[3] == (b)[3] && \
441 (a)[2] == (b)[2] && \
442 (a)[1] == (b)[1] && \
445 static void fixup_botched_add(struct ctlr_info
*h
,
446 struct hpsa_scsi_dev_t
*added
)
448 /* called when scsi_add_device fails in order to re-adjust
449 * h->dev[] to match the mid layer's view.
454 spin_lock_irqsave(&h
->lock
, flags
);
455 for (i
= 0; i
< h
->ndevices
; i
++) {
456 if (h
->dev
[i
] == added
) {
457 for (j
= i
; j
< h
->ndevices
-1; j
++)
458 h
->dev
[j
] = h
->dev
[j
+1];
463 spin_unlock_irqrestore(&h
->lock
, flags
);
467 static inline int device_is_the_same(struct hpsa_scsi_dev_t
*dev1
,
468 struct hpsa_scsi_dev_t
*dev2
)
470 if ((is_logical_dev_addr_mode(dev1
->scsi3addr
) ||
471 (dev1
->lun
!= -1 && dev2
->lun
!= -1)) &&
472 dev1
->devtype
!= 0x0C)
473 return (memcmp(dev1
, dev2
, sizeof(*dev1
)) == 0);
475 /* we compare everything except lun and target as these
476 * are not yet assigned. Compare parts likely
479 if (memcmp(dev1
->scsi3addr
, dev2
->scsi3addr
,
480 sizeof(dev1
->scsi3addr
)) != 0)
482 if (memcmp(dev1
->device_id
, dev2
->device_id
,
483 sizeof(dev1
->device_id
)) != 0)
485 if (memcmp(dev1
->model
, dev2
->model
, sizeof(dev1
->model
)) != 0)
487 if (memcmp(dev1
->vendor
, dev2
->vendor
, sizeof(dev1
->vendor
)) != 0)
489 if (memcmp(dev1
->revision
, dev2
->revision
, sizeof(dev1
->revision
)) != 0)
491 if (dev1
->devtype
!= dev2
->devtype
)
493 if (dev1
->raid_level
!= dev2
->raid_level
)
495 if (dev1
->bus
!= dev2
->bus
)
500 /* Find needle in haystack. If exact match found, return DEVICE_SAME,
501 * and return needle location in *index. If scsi3addr matches, but not
502 * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle
503 * location in *index. If needle not found, return DEVICE_NOT_FOUND.
505 static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t
*needle
,
506 struct hpsa_scsi_dev_t
*haystack
[], int haystack_size
,
510 #define DEVICE_NOT_FOUND 0
511 #define DEVICE_CHANGED 1
512 #define DEVICE_SAME 2
513 for (i
= 0; i
< haystack_size
; i
++) {
514 if (SCSI3ADDR_EQ(needle
->scsi3addr
, haystack
[i
]->scsi3addr
)) {
516 if (device_is_the_same(needle
, haystack
[i
]))
519 return DEVICE_CHANGED
;
523 return DEVICE_NOT_FOUND
;
526 static int adjust_hpsa_scsi_table(struct ctlr_info
*h
, int hostno
,
527 struct hpsa_scsi_dev_t
*sd
[], int nsds
)
529 /* sd contains scsi3 addresses and devtypes, and inquiry
530 * data. This function takes what's in sd to be the current
531 * reality and updates h->dev[] to reflect that reality.
533 int i
, entry
, device_change
, changes
= 0;
534 struct hpsa_scsi_dev_t
*csd
;
536 struct hpsa_scsi_dev_t
**added
, **removed
;
537 int nadded
, nremoved
;
538 struct Scsi_Host
*sh
= NULL
;
540 added
= kzalloc(sizeof(*added
) * HPSA_MAX_SCSI_DEVS_PER_HBA
,
542 removed
= kzalloc(sizeof(*removed
) * HPSA_MAX_SCSI_DEVS_PER_HBA
,
545 if (!added
|| !removed
) {
546 dev_warn(&h
->pdev
->dev
, "out of memory in "
547 "adjust_hpsa_scsi_table\n");
551 spin_lock_irqsave(&h
->devlock
, flags
);
553 /* find any devices in h->dev[] that are not in
554 * sd[] and remove them from h->dev[], and for any
555 * devices which have changed, remove the old device
556 * info and add the new device info.
561 while (i
< h
->ndevices
) {
563 device_change
= hpsa_scsi_find_entry(csd
, sd
, nsds
, &entry
);
564 if (device_change
== DEVICE_NOT_FOUND
) {
566 hpsa_scsi_remove_entry(h
, hostno
, i
,
568 continue; /* remove ^^^, hence i not incremented */
569 } else if (device_change
== DEVICE_CHANGED
) {
571 hpsa_scsi_remove_entry(h
, hostno
, i
,
573 (void) hpsa_scsi_add_entry(h
, hostno
, sd
[entry
],
575 /* add can't fail, we just removed one. */
576 sd
[entry
] = NULL
; /* prevent it from being freed */
581 /* Now, make sure every device listed in sd[] is also
582 * listed in h->dev[], adding them if they aren't found
585 for (i
= 0; i
< nsds
; i
++) {
586 if (!sd
[i
]) /* if already added above. */
588 device_change
= hpsa_scsi_find_entry(sd
[i
], h
->dev
,
589 h
->ndevices
, &entry
);
590 if (device_change
== DEVICE_NOT_FOUND
) {
592 if (hpsa_scsi_add_entry(h
, hostno
, sd
[i
],
593 added
, &nadded
) != 0)
595 sd
[i
] = NULL
; /* prevent from being freed later. */
596 } else if (device_change
== DEVICE_CHANGED
) {
597 /* should never happen... */
599 dev_warn(&h
->pdev
->dev
,
600 "device unexpectedly changed.\n");
601 /* but if it does happen, we just ignore that device */
604 spin_unlock_irqrestore(&h
->devlock
, flags
);
606 /* Don't notify scsi mid layer of any changes the first time through
607 * (or if there are no changes) scsi_scan_host will do it later the
608 * first time through.
610 if (hostno
== -1 || !changes
)
614 /* Notify scsi mid layer of any removed devices */
615 for (i
= 0; i
< nremoved
; i
++) {
616 struct scsi_device
*sdev
=
617 scsi_device_lookup(sh
, removed
[i
]->bus
,
618 removed
[i
]->target
, removed
[i
]->lun
);
620 scsi_remove_device(sdev
);
621 scsi_device_put(sdev
);
623 /* We don't expect to get here.
624 * future cmds to this device will get selection
625 * timeout as if the device was gone.
627 dev_warn(&h
->pdev
->dev
, "didn't find c%db%dt%dl%d "
628 " for removal.", hostno
, removed
[i
]->bus
,
629 removed
[i
]->target
, removed
[i
]->lun
);
635 /* Notify scsi mid layer of any added devices */
636 for (i
= 0; i
< nadded
; i
++) {
637 if (scsi_add_device(sh
, added
[i
]->bus
,
638 added
[i
]->target
, added
[i
]->lun
) == 0)
640 dev_warn(&h
->pdev
->dev
, "scsi_add_device c%db%dt%dl%d failed, "
641 "device not added.\n", hostno
, added
[i
]->bus
,
642 added
[i
]->target
, added
[i
]->lun
);
643 /* now we have to remove it from h->dev,
644 * since it didn't get added to scsi mid layer
646 fixup_botched_add(h
, added
[i
]);
656 * Lookup bus/target/lun and retrun corresponding struct hpsa_scsi_dev_t *
657 * Assume's h->devlock is held.
659 static struct hpsa_scsi_dev_t
*lookup_hpsa_scsi_dev(struct ctlr_info
*h
,
660 int bus
, int target
, int lun
)
663 struct hpsa_scsi_dev_t
*sd
;
665 for (i
= 0; i
< h
->ndevices
; i
++) {
667 if (sd
->bus
== bus
&& sd
->target
== target
&& sd
->lun
== lun
)
673 /* link sdev->hostdata to our per-device structure. */
674 static int hpsa_slave_alloc(struct scsi_device
*sdev
)
676 struct hpsa_scsi_dev_t
*sd
;
680 h
= (struct ctlr_info
*) sdev
->host
->hostdata
[0];
681 spin_lock_irqsave(&h
->devlock
, flags
);
682 sd
= lookup_hpsa_scsi_dev(h
, sdev_channel(sdev
),
683 sdev_id(sdev
), sdev
->lun
);
686 spin_unlock_irqrestore(&h
->devlock
, flags
);
690 static void hpsa_slave_destroy(struct scsi_device
*sdev
)
692 return; /* nothing to do. */
695 static void hpsa_scsi_setup(struct ctlr_info
*h
)
699 spin_lock_init(&h
->devlock
);
703 static void complete_scsi_command(struct CommandList
*cp
,
704 int timeout
, __u32 tag
)
706 struct scsi_cmnd
*cmd
;
708 struct ErrorInfo
*ei
;
710 unsigned char sense_key
;
711 unsigned char asc
; /* additional sense code */
712 unsigned char ascq
; /* additional sense code qualifier */
715 cmd
= (struct scsi_cmnd
*) cp
->scsi_cmd
;
718 scsi_dma_unmap(cmd
); /* undo the DMA mappings */
720 cmd
->result
= (DID_OK
<< 16); /* host byte */
721 cmd
->result
|= (COMMAND_COMPLETE
<< 8); /* msg byte */
722 cmd
->result
|= (ei
->ScsiStatus
);
724 /* copy the sense data whether we need to or not. */
725 memcpy(cmd
->sense_buffer
, ei
->SenseInfo
,
726 ei
->SenseLen
> SCSI_SENSE_BUFFERSIZE
?
727 SCSI_SENSE_BUFFERSIZE
:
729 scsi_set_resid(cmd
, ei
->ResidualCnt
);
731 if (ei
->CommandStatus
== 0) {
737 /* an error has occurred */
738 switch (ei
->CommandStatus
) {
740 case CMD_TARGET_STATUS
:
741 if (ei
->ScsiStatus
) {
743 sense_key
= 0xf & ei
->SenseInfo
[2];
744 /* Get additional sense code */
745 asc
= ei
->SenseInfo
[12];
746 /* Get addition sense code qualifier */
747 ascq
= ei
->SenseInfo
[13];
750 if (ei
->ScsiStatus
== SAM_STAT_CHECK_CONDITION
) {
752 if (sense_key
== ILLEGAL_REQUEST
) {
753 /* If ASC/ASCQ indicate Logical Unit
754 * Not Supported condition,
756 if ((asc
== 0x25) && (ascq
== 0x0)) {
757 dev_warn(&h
->pdev
->dev
, "cp %p "
758 "has check condition\n", cp
);
763 if (sense_key
== NOT_READY
) {
764 /* If Sense is Not Ready, Logical Unit
765 * Not ready, Manual Intervention
768 if ((asc
== 0x04) && (ascq
== 0x03)) {
769 cmd
->result
= DID_NO_CONNECT
<< 16;
770 dev_warn(&h
->pdev
->dev
, "cp %p "
771 "has check condition: unit "
773 "intervention required\n", cp
);
779 /* Must be some other type of check condition */
780 cmd
->result
|= (ei
->ScsiStatus
< 1);
781 dev_warn(&h
->pdev
->dev
, "cp %p has check condition: "
783 "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, "
784 "Returning result: 0x%x, "
785 "cmd=[%02x %02x %02x %02x %02x "
786 "%02x %02x %02x %02x %02x]\n",
787 cp
, sense_key
, asc
, ascq
,
789 cmd
->cmnd
[0], cmd
->cmnd
[1],
790 cmd
->cmnd
[2], cmd
->cmnd
[3],
791 cmd
->cmnd
[4], cmd
->cmnd
[5],
792 cmd
->cmnd
[6], cmd
->cmnd
[7],
793 cmd
->cmnd
[8], cmd
->cmnd
[9]);
798 /* Problem was not a check condition
799 * Pass it up to the upper layers...
801 if (ei
->ScsiStatus
) {
803 cmd
->result
|= (ei
->ScsiStatus
< 1);
804 dev_warn(&h
->pdev
->dev
, "cp %p has status 0x%x "
805 "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, "
806 "Returning result: 0x%x\n",
808 sense_key
, asc
, ascq
,
810 } else { /* scsi status is zero??? How??? */
811 dev_warn(&h
->pdev
->dev
, "cp %p SCSI status was 0. "
812 "Returning no connection.\n", cp
),
814 /* Ordinarily, this case should never happen,
815 * but there is a bug in some released firmware
816 * revisions that allows it to happen if, for
817 * example, a 4100 backplane loses power and
818 * the tape drive is in it. We assume that
819 * it's a fatal error of some kind because we
820 * can't show that it wasn't. We will make it
821 * look like selection timeout since that is
822 * the most common reason for this to occur,
823 * and it's severe enough.
826 cmd
->result
= DID_NO_CONNECT
<< 16;
830 case CMD_DATA_UNDERRUN
: /* let mid layer handle it. */
832 case CMD_DATA_OVERRUN
:
833 dev_warn(&h
->pdev
->dev
, "cp %p has"
834 " completed with data overrun "
838 /* print_bytes(cp, sizeof(*cp), 1, 0);
840 /* We get CMD_INVALID if you address a non-existent device
841 * instead of a selection timeout (no response). You will
842 * see this if you yank out a drive, then try to access it.
843 * This is kind of a shame because it means that any other
844 * CMD_INVALID (e.g. driver bug) will get interpreted as a
846 cmd
->result
= DID_NO_CONNECT
<< 16;
849 case CMD_PROTOCOL_ERR
:
850 dev_warn(&h
->pdev
->dev
, "cp %p has "
851 "protocol error \n", cp
);
853 case CMD_HARDWARE_ERR
:
854 cmd
->result
= DID_ERROR
<< 16;
855 dev_warn(&h
->pdev
->dev
, "cp %p had hardware error\n", cp
);
857 case CMD_CONNECTION_LOST
:
858 cmd
->result
= DID_ERROR
<< 16;
859 dev_warn(&h
->pdev
->dev
, "cp %p had connection lost\n", cp
);
862 cmd
->result
= DID_ABORT
<< 16;
863 dev_warn(&h
->pdev
->dev
, "cp %p was aborted with status 0x%x\n",
866 case CMD_ABORT_FAILED
:
867 cmd
->result
= DID_ERROR
<< 16;
868 dev_warn(&h
->pdev
->dev
, "cp %p reports abort failed\n", cp
);
870 case CMD_UNSOLICITED_ABORT
:
871 cmd
->result
= DID_ABORT
<< 16;
872 dev_warn(&h
->pdev
->dev
, "cp %p aborted do to an unsolicited "
876 cmd
->result
= DID_TIME_OUT
<< 16;
877 dev_warn(&h
->pdev
->dev
, "cp %p timedout\n", cp
);
880 cmd
->result
= DID_ERROR
<< 16;
881 dev_warn(&h
->pdev
->dev
, "cp %p returned unknown status %x\n",
882 cp
, ei
->CommandStatus
);
888 static int hpsa_scsi_detect(struct ctlr_info
*h
)
890 struct Scsi_Host
*sh
;
893 sh
= scsi_host_alloc(&hpsa_driver_template
, sizeof(*h
));
901 sh
->max_cmd_len
= MAX_COMMAND_SIZE
;
902 sh
->max_lun
= HPSA_MAX_LUN
;
903 sh
->max_id
= HPSA_MAX_LUN
;
905 sh
->hostdata
[0] = (unsigned long) h
;
906 sh
->irq
= h
->intr
[SIMPLE_MODE_INT
];
907 sh
->unique_id
= sh
->irq
;
908 error
= scsi_add_host(sh
, &h
->pdev
->dev
);
915 dev_err(&h
->pdev
->dev
, "hpsa_scsi_detect: scsi_add_host"
916 " failed for controller %d\n", h
->ctlr
);
920 dev_err(&h
->pdev
->dev
, "hpsa_scsi_detect: scsi_host_alloc"
921 " failed for controller %d\n", h
->ctlr
);
925 static void hpsa_unmap_one(struct pci_dev
*pdev
,
926 struct CommandList
*cp
,
932 addr64
.val32
.lower
= cp
->SG
[0].Addr
.lower
;
933 addr64
.val32
.upper
= cp
->SG
[0].Addr
.upper
;
934 pci_unmap_single(pdev
, (dma_addr_t
) addr64
.val
,
935 buflen
, data_direction
);
938 static void hpsa_map_one(struct pci_dev
*pdev
,
939 struct CommandList
*cp
,
946 if (buflen
== 0 || data_direction
== PCI_DMA_NONE
) {
947 cp
->Header
.SGList
= 0;
948 cp
->Header
.SGTotal
= 0;
952 addr64
= (__u64
) pci_map_single(pdev
, buf
, buflen
, data_direction
);
953 cp
->SG
[0].Addr
.lower
=
954 (__u32
) (addr64
& (__u64
) 0x00000000FFFFFFFF);
955 cp
->SG
[0].Addr
.upper
=
956 (__u32
) ((addr64
>> 32) & (__u64
) 0x00000000FFFFFFFF);
957 cp
->SG
[0].Len
= buflen
;
958 cp
->Header
.SGList
= (__u8
) 1; /* no. SGs contig in this cmd */
959 cp
->Header
.SGTotal
= (__u16
) 1; /* total sgs in this cmd list */
962 static void hpsa_scsi_do_simple_cmd_core(struct ctlr_info
*h
,
963 struct CommandList
*c
)
965 DECLARE_COMPLETION_ONSTACK(wait
);
968 enqueue_cmd_and_start_io(h
, c
);
969 wait_for_completion(&wait
);
972 static void hpsa_scsi_interpret_error(struct CommandList
*cp
)
974 struct ErrorInfo
*ei
;
975 struct device
*d
= &cp
->h
->pdev
->dev
;
978 switch (ei
->CommandStatus
) {
979 case CMD_TARGET_STATUS
:
980 dev_warn(d
, "cmd %p has completed with errors\n", cp
);
981 dev_warn(d
, "cmd %p has SCSI Status = %x\n", cp
,
983 if (ei
->ScsiStatus
== 0)
984 dev_warn(d
, "SCSI status is abnormally zero. "
985 "(probably indicates selection timeout "
986 "reported incorrectly due to a known "
987 "firmware bug, circa July, 2001.)\n");
989 case CMD_DATA_UNDERRUN
: /* let mid layer handle it. */
990 dev_info(d
, "UNDERRUN\n");
992 case CMD_DATA_OVERRUN
:
993 dev_warn(d
, "cp %p has completed with data overrun\n", cp
);
996 /* controller unfortunately reports SCSI passthru's
997 * to non-existent targets as invalid commands.
999 dev_warn(d
, "cp %p is reported invalid (probably means "
1000 "target device no longer present)\n", cp
);
1001 /* print_bytes((unsigned char *) cp, sizeof(*cp), 1, 0);
1005 case CMD_PROTOCOL_ERR
:
1006 dev_warn(d
, "cp %p has protocol error \n", cp
);
1008 case CMD_HARDWARE_ERR
:
1009 /* cmd->result = DID_ERROR << 16; */
1010 dev_warn(d
, "cp %p had hardware error\n", cp
);
1012 case CMD_CONNECTION_LOST
:
1013 dev_warn(d
, "cp %p had connection lost\n", cp
);
1016 dev_warn(d
, "cp %p was aborted\n", cp
);
1018 case CMD_ABORT_FAILED
:
1019 dev_warn(d
, "cp %p reports abort failed\n", cp
);
1021 case CMD_UNSOLICITED_ABORT
:
1022 dev_warn(d
, "cp %p aborted due to an unsolicited abort\n", cp
);
1025 dev_warn(d
, "cp %p timed out\n", cp
);
1028 dev_warn(d
, "cp %p returned unknown status %x\n", cp
,
1033 static int hpsa_scsi_do_inquiry(struct ctlr_info
*h
, unsigned char *scsi3addr
,
1034 unsigned char page
, unsigned char *buf
,
1035 unsigned char bufsize
)
1038 struct CommandList
*c
;
1039 struct ErrorInfo
*ei
;
1041 c
= cmd_special_alloc(h
);
1043 if (c
== NULL
) { /* trouble... */
1044 dev_warn(&h
->pdev
->dev
, "cmd_special_alloc returned NULL!\n");
1048 rc
= fill_cmd(c
, HPSA_INQUIRY
, h
, buf
, bufsize
, page
, scsi3addr
,
1051 hpsa_scsi_do_simple_cmd_core(h
, c
);
1052 hpsa_unmap_one(h
->pdev
, c
, bufsize
, PCI_DMA_FROMDEVICE
);
1055 if (ei
->CommandStatus
!= 0 &&
1056 ei
->CommandStatus
!= CMD_DATA_UNDERRUN
) {
1057 hpsa_scsi_interpret_error(c
);
1061 cmd_special_free(h
, c
);
1065 static int hpsa_send_reset(struct ctlr_info
*h
, unsigned char *scsi3addr
)
1068 struct CommandList
*c
;
1069 struct ErrorInfo
*ei
;
1071 c
= cmd_special_alloc(h
);
1073 if (c
== NULL
) { /* trouble... */
1074 dev_warn(&h
->pdev
->dev
, "cmd_special_alloc returned NULL!\n");
1078 rc
= fill_cmd(c
, HPSA_DEVICE_RESET_MSG
, h
, NULL
, 0, 0, scsi3addr
,
1083 hpsa_scsi_do_simple_cmd_core(h
, c
);
1084 /* no unmap needed here because no data xfer. */
1087 if (ei
->CommandStatus
!= 0) {
1088 hpsa_scsi_interpret_error(c
);
1092 cmd_special_free(h
, c
);
1096 static void hpsa_get_raid_level(struct ctlr_info
*h
,
1097 unsigned char *scsi3addr
, unsigned char *raid_level
)
1102 *raid_level
= RAID_UNKNOWN
;
1103 buf
= kzalloc(64, GFP_KERNEL
);
1106 rc
= hpsa_scsi_do_inquiry(h
, scsi3addr
, 0xC1, buf
, 64);
1108 *raid_level
= buf
[8];
1109 if (*raid_level
> RAID_UNKNOWN
)
1110 *raid_level
= RAID_UNKNOWN
;
1115 /* Get the device id from inquiry page 0x83 */
1116 static int hpsa_get_device_id(struct ctlr_info
*h
, unsigned char *scsi3addr
,
1117 unsigned char *device_id
, int buflen
)
1124 buf
= kzalloc(64, GFP_KERNEL
);
1127 rc
= hpsa_scsi_do_inquiry(h
, scsi3addr
, 0x83, buf
, 64);
1129 memcpy(device_id
, &buf
[8], buflen
);
1134 static int hpsa_scsi_do_report_luns(struct ctlr_info
*h
, int logical
,
1135 struct ReportLUNdata
*buf
, int bufsize
,
1136 int extended_response
)
1139 struct CommandList
*c
;
1140 unsigned char scsi3addr
[8];
1141 struct ErrorInfo
*ei
;
1143 c
= cmd_special_alloc(h
);
1144 if (c
== NULL
) { /* trouble... */
1145 dev_err(&h
->pdev
->dev
, "cmd_special_alloc returned NULL!\n");
1149 memset(&scsi3addr
[0], 0, 8); /* address the controller */
1151 rc
= fill_cmd(c
, logical
? HPSA_REPORT_LOG
: HPSA_REPORT_PHYS
, h
,
1152 buf
, bufsize
, 0, scsi3addr
, TYPE_CMD
);
1156 if (extended_response
)
1157 c
->Request
.CDB
[1] = extended_response
;
1158 hpsa_scsi_do_simple_cmd_core(h
, c
);
1159 hpsa_unmap_one(h
->pdev
, c
, bufsize
, PCI_DMA_FROMDEVICE
);
1161 if (ei
->CommandStatus
!= 0 &&
1162 ei
->CommandStatus
!= CMD_DATA_UNDERRUN
) {
1163 hpsa_scsi_interpret_error(c
);
1167 cmd_special_free(h
, c
);
1171 static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info
*h
,
1172 struct ReportLUNdata
*buf
,
1173 int bufsize
, int extended_response
)
1175 return hpsa_scsi_do_report_luns(h
, 0, buf
, bufsize
, extended_response
);
1178 static inline int hpsa_scsi_do_report_log_luns(struct ctlr_info
*h
,
1179 struct ReportLUNdata
*buf
, int bufsize
)
1181 return hpsa_scsi_do_report_luns(h
, 1, buf
, bufsize
, 0);
1184 static inline void hpsa_set_bus_target_lun(struct hpsa_scsi_dev_t
*device
,
1185 int bus
, int target
, int lun
)
1188 device
->target
= target
;
1192 static int hpsa_update_device_info(struct ctlr_info
*h
,
1193 unsigned char scsi3addr
[], struct hpsa_scsi_dev_t
*this_device
)
1195 #define OBDR_TAPE_INQ_SIZE 49
1196 unsigned char *inq_buff
= NULL
;
1198 inq_buff
= kmalloc(OBDR_TAPE_INQ_SIZE
, GFP_KERNEL
);
1202 memset(inq_buff
, 0, OBDR_TAPE_INQ_SIZE
);
1203 /* Do an inquiry to the device to see what it is. */
1204 if (hpsa_scsi_do_inquiry(h
, scsi3addr
, 0, inq_buff
,
1205 (unsigned char) OBDR_TAPE_INQ_SIZE
) != 0) {
1206 /* Inquiry failed (msg printed already) */
1207 dev_err(&h
->pdev
->dev
,
1208 "hpsa_update_device_info: inquiry failed\n");
1212 /* As a side effect, record the firmware version number
1213 * if we happen to be talking to the RAID controller.
1215 if (is_hba_lunid(scsi3addr
))
1216 memcpy(h
->firm_ver
, &inq_buff
[32], 4);
1218 this_device
->devtype
= (inq_buff
[0] & 0x1f);
1219 memcpy(this_device
->scsi3addr
, scsi3addr
, 8);
1220 memcpy(this_device
->vendor
, &inq_buff
[8],
1221 sizeof(this_device
->vendor
));
1222 memcpy(this_device
->model
, &inq_buff
[16],
1223 sizeof(this_device
->model
));
1224 memcpy(this_device
->revision
, &inq_buff
[32],
1225 sizeof(this_device
->revision
));
1226 memset(this_device
->device_id
, 0,
1227 sizeof(this_device
->device_id
));
1228 hpsa_get_device_id(h
, scsi3addr
, this_device
->device_id
,
1229 sizeof(this_device
->device_id
));
1231 if (this_device
->devtype
== TYPE_DISK
&&
1232 is_logical_dev_addr_mode(scsi3addr
))
1233 hpsa_get_raid_level(h
, scsi3addr
, &this_device
->raid_level
);
1235 this_device
->raid_level
= RAID_UNKNOWN
;
1245 static unsigned char *msa2xxx_model
[] = {
1253 static int is_msa2xxx(struct ctlr_info
*h
, struct hpsa_scsi_dev_t
*device
)
1257 for (i
= 0; msa2xxx_model
[i
]; i
++)
1258 if (strncmp(device
->model
, msa2xxx_model
[i
],
1259 strlen(msa2xxx_model
[i
])) == 0)
1264 /* Helper function to assign bus, target, lun mapping of devices.
1265 * Puts non-msa2xxx logical volumes on bus 0, msa2xxx logical
1266 * volumes on bus 1, physical devices on bus 2. and the hba on bus 3.
1267 * Logical drive target and lun are assigned at this time, but
1268 * physical device lun and target assignment are deferred (assigned
1269 * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.)
1271 static void figure_bus_target_lun(struct ctlr_info
*h
,
1272 __u8
*lunaddrbytes
, int *bus
, int *target
, int *lun
,
1273 struct hpsa_scsi_dev_t
*device
)
1278 if (is_logical_dev_addr_mode(lunaddrbytes
)) {
1279 /* logical device */
1280 memcpy(&lunid
, lunaddrbytes
, sizeof(lunid
));
1281 lunid
= le32_to_cpu(lunid
);
1283 if (is_msa2xxx(h
, device
)) {
1285 *target
= (lunid
>> 16) & 0x3fff;
1286 *lun
= lunid
& 0x00ff;
1290 *target
= lunid
& 0x3fff;
1293 /* physical device */
1294 if (is_hba_lunid(lunaddrbytes
))
1299 *lun
= -1; /* we will fill these in later. */
1304 * If there is no lun 0 on a target, linux won't find any devices.
1305 * For the MSA2xxx boxes, we have to manually detect the enclosure
1306 * which is at lun zero, as CCISS_REPORT_PHYSICAL_LUNS doesn't report
1307 * it for some reason. *tmpdevice is the target we're adding,
1308 * this_device is a pointer into the current element of currentsd[]
1309 * that we're building up in update_scsi_devices(), below.
1310 * lunzerobits is a bitmap that tracks which targets already have a
1312 * Returns 1 if an enclosure was added, 0 if not.
1314 static int add_msa2xxx_enclosure_device(struct ctlr_info
*h
,
1315 struct hpsa_scsi_dev_t
*tmpdevice
,
1316 struct hpsa_scsi_dev_t
*this_device
, __u8
*lunaddrbytes
,
1317 int bus
, int target
, int lun
, unsigned long lunzerobits
[],
1318 int *nmsa2xxx_enclosures
)
1320 unsigned char scsi3addr
[8];
1322 if (test_bit(target
, lunzerobits
))
1323 return 0; /* There is already a lun 0 on this target. */
1325 if (!is_logical_dev_addr_mode(lunaddrbytes
))
1326 return 0; /* It's the logical targets that may lack lun 0. */
1328 if (!is_msa2xxx(h
, tmpdevice
))
1329 return 0; /* It's only the MSA2xxx that have this problem. */
1331 if (lun
== 0) /* if lun is 0, then obviously we have a lun 0. */
1334 if (is_hba_lunid(scsi3addr
))
1335 return 0; /* Don't add the RAID controller here. */
1337 #define MAX_MSA2XXX_ENCLOSURES 32
1338 if (*nmsa2xxx_enclosures
>= MAX_MSA2XXX_ENCLOSURES
) {
1339 dev_warn(&h
->pdev
->dev
, "Maximum number of MSA2XXX "
1340 "enclosures exceeded. Check your hardware "
1345 memset(scsi3addr
, 0, 8);
1346 scsi3addr
[3] = target
;
1347 if (hpsa_update_device_info(h
, scsi3addr
, this_device
))
1349 (*nmsa2xxx_enclosures
)++;
1350 hpsa_set_bus_target_lun(this_device
, bus
, target
, 0);
1351 set_bit(target
, lunzerobits
);
1356 * Do CISS_REPORT_PHYS and CISS_REPORT_LOG. Data is returned in physdev,
1357 * logdev. The number of luns in physdev and logdev are returned in
1358 * *nphysicals and *nlogicals, respectively.
1359 * Returns 0 on success, -1 otherwise.
1361 static int hpsa_gather_lun_info(struct ctlr_info
*h
,
1363 struct ReportLUNdata
*physdev
, __u32
*nphysicals
,
1364 struct ReportLUNdata
*logdev
, __u32
*nlogicals
)
1366 if (hpsa_scsi_do_report_phys_luns(h
, physdev
, reportlunsize
, 0)) {
1367 dev_err(&h
->pdev
->dev
, "report physical LUNs failed.\n");
1370 memcpy(nphysicals
, &physdev
->LUNListLength
[0], sizeof(*nphysicals
));
1371 *nphysicals
= be32_to_cpu(*nphysicals
) / 8;
1373 dev_info(&h
->pdev
->dev
, "number of physical luns is %d\n", *nphysicals
);
1375 if (*nphysicals
> HPSA_MAX_PHYS_LUN
) {
1376 dev_warn(&h
->pdev
->dev
, "maximum physical LUNs (%d) exceeded."
1377 " %d LUNs ignored.\n", HPSA_MAX_PHYS_LUN
,
1378 *nphysicals
- HPSA_MAX_PHYS_LUN
);
1379 *nphysicals
= HPSA_MAX_PHYS_LUN
;
1381 if (hpsa_scsi_do_report_log_luns(h
, logdev
, reportlunsize
)) {
1382 dev_err(&h
->pdev
->dev
, "report logical LUNs failed.\n");
1385 memcpy(nlogicals
, &logdev
->LUNListLength
[0], sizeof(*nlogicals
));
1386 *nlogicals
= be32_to_cpu(*nlogicals
) / 8;
1388 dev_info(&h
->pdev
->dev
, "number of logical luns is %d\n", *nlogicals
);
1390 /* Reject Logicals in excess of our max capability. */
1391 if (*nlogicals
> HPSA_MAX_LUN
) {
1392 dev_warn(&h
->pdev
->dev
,
1393 "maximum logical LUNs (%d) exceeded. "
1394 "%d LUNs ignored.\n", HPSA_MAX_LUN
,
1395 *nlogicals
- HPSA_MAX_LUN
);
1396 *nlogicals
= HPSA_MAX_LUN
;
1398 if (*nlogicals
+ *nphysicals
> HPSA_MAX_PHYS_LUN
) {
1399 dev_warn(&h
->pdev
->dev
,
1400 "maximum logical + physical LUNs (%d) exceeded. "
1401 "%d LUNs ignored.\n", HPSA_MAX_PHYS_LUN
,
1402 *nphysicals
+ *nlogicals
- HPSA_MAX_PHYS_LUN
);
1403 *nlogicals
= HPSA_MAX_PHYS_LUN
- *nphysicals
;
1408 static void hpsa_update_scsi_devices(struct ctlr_info
*h
, int hostno
)
1410 /* the idea here is we could get notified
1411 * that some devices have changed, so we do a report
1412 * physical luns and report logical luns cmd, and adjust
1413 * our list of devices accordingly.
1415 * The scsi3addr's of devices won't change so long as the
1416 * adapter is not reset. That means we can rescan and
1417 * tell which devices we already know about, vs. new
1418 * devices, vs. disappearing devices.
1420 struct ReportLUNdata
*physdev_list
= NULL
;
1421 struct ReportLUNdata
*logdev_list
= NULL
;
1422 unsigned char *inq_buff
= NULL
;
1423 __u32 nphysicals
= 0;
1424 __u32 nlogicals
= 0;
1425 __u32 ndev_allocated
= 0;
1426 struct hpsa_scsi_dev_t
**currentsd
, *this_device
, *tmpdevice
;
1428 int reportlunsize
= sizeof(*physdev_list
) + HPSA_MAX_PHYS_LUN
* 8;
1429 int i
, nmsa2xxx_enclosures
, ndevs_to_allocate
;
1430 int bus
, target
, lun
;
1431 DECLARE_BITMAP(lunzerobits
, HPSA_MAX_TARGETS_PER_CTLR
);
1433 currentsd
= kzalloc(sizeof(*currentsd
) * HPSA_MAX_SCSI_DEVS_PER_HBA
,
1435 physdev_list
= kzalloc(reportlunsize
, GFP_KERNEL
);
1436 logdev_list
= kzalloc(reportlunsize
, GFP_KERNEL
);
1437 inq_buff
= kmalloc(OBDR_TAPE_INQ_SIZE
, GFP_KERNEL
);
1438 tmpdevice
= kzalloc(sizeof(*tmpdevice
), GFP_KERNEL
);
1440 if (!currentsd
|| !physdev_list
|| !logdev_list
||
1441 !inq_buff
|| !tmpdevice
) {
1442 dev_err(&h
->pdev
->dev
, "out of memory\n");
1445 memset(lunzerobits
, 0, sizeof(lunzerobits
));
1447 if (hpsa_gather_lun_info(h
, reportlunsize
, physdev_list
, &nphysicals
,
1448 logdev_list
, &nlogicals
))
1451 /* We might see up to 32 MSA2xxx enclosures, actually 8 of them
1452 * but each of them 4 times through different paths. The plus 1
1453 * is for the RAID controller.
1455 ndevs_to_allocate
= nphysicals
+ nlogicals
+ MAX_MSA2XXX_ENCLOSURES
+ 1;
1457 /* Allocate the per device structures */
1458 for (i
= 0; i
< ndevs_to_allocate
; i
++) {
1459 currentsd
[i
] = kzalloc(sizeof(*currentsd
[i
]), GFP_KERNEL
);
1460 if (!currentsd
[i
]) {
1461 dev_warn(&h
->pdev
->dev
, "out of memory at %s:%d\n",
1462 __FILE__
, __LINE__
);
1468 /* adjust our table of devices */
1469 nmsa2xxx_enclosures
= 0;
1470 for (i
= 0; i
< nphysicals
+ nlogicals
+ 1; i
++) {
1473 /* Figure out where the LUN ID info is coming from */
1475 lunaddrbytes
= &physdev_list
->LUN
[i
][0];
1477 if (i
< nphysicals
+ nlogicals
)
1479 &logdev_list
->LUN
[i
-nphysicals
][0];
1480 else /* jam in the RAID controller at the end */
1481 lunaddrbytes
= RAID_CTLR_LUNID
;
1483 /* skip masked physical devices. */
1484 if (lunaddrbytes
[3] & 0xC0 && i
< nphysicals
)
1487 /* Get device type, vendor, model, device id */
1488 if (hpsa_update_device_info(h
, lunaddrbytes
, tmpdevice
))
1489 continue; /* skip it if we can't talk to it. */
1490 figure_bus_target_lun(h
, lunaddrbytes
, &bus
, &target
, &lun
,
1492 this_device
= currentsd
[ncurrent
];
1495 * For the msa2xxx boxes, we have to insert a LUN 0 which
1496 * doesn't show up in CCISS_REPORT_PHYSICAL data, but there
1497 * is nonetheless an enclosure device there. We have to
1498 * present that otherwise linux won't find anything if
1499 * there is no lun 0.
1501 if (add_msa2xxx_enclosure_device(h
, tmpdevice
, this_device
,
1502 lunaddrbytes
, bus
, target
, lun
, lunzerobits
,
1503 &nmsa2xxx_enclosures
)) {
1505 this_device
= currentsd
[ncurrent
];
1508 *this_device
= *tmpdevice
;
1509 hpsa_set_bus_target_lun(this_device
, bus
, target
, lun
);
1511 switch (this_device
->devtype
) {
1513 /* We don't *really* support actual CD-ROM devices,
1514 * just "One Button Disaster Recovery" tape drive
1515 * which temporarily pretends to be a CD-ROM drive.
1516 * So we check that the device is really an OBDR tape
1517 * device by checking for "$DR-10" in bytes 43-48 of
1521 #define OBDR_TAPE_SIG "$DR-10"
1522 strncpy(obdr_sig
, &inq_buff
[43], 6);
1524 if (strncmp(obdr_sig
, OBDR_TAPE_SIG
, 6) != 0)
1525 /* Not OBDR device, ignore it. */
1536 case TYPE_MEDIUM_CHANGER
:
1540 /* Only present the Smartarray HBA as a RAID controller.
1541 * If it's a RAID controller other than the HBA itself
1542 * (an external RAID controller, MSA500 or similar)
1545 if (!is_hba_lunid(lunaddrbytes
))
1552 if (ncurrent
>= HPSA_MAX_SCSI_DEVS_PER_HBA
)
1555 adjust_hpsa_scsi_table(h
, hostno
, currentsd
, ncurrent
);
1558 for (i
= 0; i
< ndev_allocated
; i
++)
1559 kfree(currentsd
[i
]);
1562 kfree(physdev_list
);
1567 /* hpsa_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
1568 * dma mapping and fills in the scatter gather entries of the
1571 static int hpsa_scatter_gather(struct pci_dev
*pdev
,
1572 struct CommandList
*cp
,
1573 struct scsi_cmnd
*cmd
)
1576 struct scatterlist
*sg
;
1580 BUG_ON(scsi_sg_count(cmd
) > MAXSGENTRIES
);
1582 use_sg
= scsi_dma_map(cmd
);
1587 goto sglist_finished
;
1589 scsi_for_each_sg(cmd
, sg
, use_sg
, i
) {
1590 addr64
= (__u64
) sg_dma_address(sg
);
1591 len
= sg_dma_len(sg
);
1592 cp
->SG
[i
].Addr
.lower
=
1593 (__u32
) (addr64
& (__u64
) 0x00000000FFFFFFFF);
1594 cp
->SG
[i
].Addr
.upper
=
1595 (__u32
) ((addr64
>> 32) & (__u64
) 0x00000000FFFFFFFF);
1596 cp
->SG
[i
].Len
= len
;
1597 cp
->SG
[i
].Ext
= 0; /* we are not chaining */
1602 cp
->Header
.SGList
= (__u8
) use_sg
; /* no. SGs contig in this cmd */
1603 cp
->Header
.SGTotal
= (__u16
) use_sg
; /* total sgs in this cmd list */
1608 static int hpsa_scsi_queue_command(struct scsi_cmnd
*cmd
,
1609 void (*done
)(struct scsi_cmnd
*))
1611 struct ctlr_info
*h
;
1612 struct hpsa_scsi_dev_t
*dev
;
1613 unsigned char scsi3addr
[8];
1614 struct CommandList
*c
;
1615 unsigned long flags
;
1617 /* Get the ptr to our adapter structure out of cmd->host. */
1618 h
= (struct ctlr_info
*) cmd
->device
->host
->hostdata
[0];
1619 dev
= cmd
->device
->hostdata
;
1621 cmd
->result
= DID_NO_CONNECT
<< 16;
1625 memcpy(scsi3addr
, dev
->scsi3addr
, sizeof(scsi3addr
));
1627 /* Need a lock as this is being allocated from the pool */
1628 spin_lock_irqsave(&h
->lock
, flags
);
1630 spin_unlock_irqrestore(&h
->lock
, flags
);
1631 if (c
== NULL
) { /* trouble... */
1632 dev_err(&h
->pdev
->dev
, "cmd_alloc returned NULL!\n");
1633 cmd
->result
= DID_NO_CONNECT
<< 16;
1638 /* Fill in the command list header */
1640 cmd
->scsi_done
= done
; /* save this for use by completion code */
1642 /* save c in case we have to abort it */
1643 cmd
->host_scribble
= (unsigned char *) c
;
1645 c
->cmd_type
= CMD_SCSI
;
1647 c
->Header
.ReplyQueue
= 0; /* unused in simple mode */
1648 memcpy(&c
->Header
.LUN
.LunAddrBytes
[0], &scsi3addr
[0], 8);
1649 c
->Header
.Tag
.lower
= c
->busaddr
; /* Use k. address of cmd as tag */
1651 /* Fill in the request block... */
1653 c
->Request
.Timeout
= 0;
1654 memset(c
->Request
.CDB
, 0, sizeof(c
->Request
.CDB
));
1655 BUG_ON(cmd
->cmd_len
> sizeof(c
->Request
.CDB
));
1656 c
->Request
.CDBLen
= cmd
->cmd_len
;
1657 memcpy(c
->Request
.CDB
, cmd
->cmnd
, cmd
->cmd_len
);
1658 c
->Request
.Type
.Type
= TYPE_CMD
;
1659 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
1660 switch (cmd
->sc_data_direction
) {
1662 c
->Request
.Type
.Direction
= XFER_WRITE
;
1664 case DMA_FROM_DEVICE
:
1665 c
->Request
.Type
.Direction
= XFER_READ
;
1668 c
->Request
.Type
.Direction
= XFER_NONE
;
1670 case DMA_BIDIRECTIONAL
:
1671 /* This can happen if a buggy application does a scsi passthru
1672 * and sets both inlen and outlen to non-zero. ( see
1673 * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
1676 c
->Request
.Type
.Direction
= XFER_RSVD
;
1677 /* This is technically wrong, and hpsa controllers should
1678 * reject it with CMD_INVALID, which is the most correct
1679 * response, but non-fibre backends appear to let it
1680 * slide by, and give the same results as if this field
1681 * were set correctly. Either way is acceptable for
1682 * our purposes here.
1688 dev_err(&h
->pdev
->dev
, "unknown data direction: %d\n",
1689 cmd
->sc_data_direction
);
1694 if (hpsa_scatter_gather(h
->pdev
, c
, cmd
) < 0) { /* Fill SG list */
1696 return SCSI_MLQUEUE_HOST_BUSY
;
1698 enqueue_cmd_and_start_io(h
, c
);
1699 /* the cmd'll come back via intr handler in complete_scsi_command() */
1703 static void hpsa_unregister_scsi(struct ctlr_info
*h
)
1705 /* we are being forcibly unloaded, and may not refuse. */
1706 scsi_remove_host(h
->scsi_host
);
1707 scsi_host_put(h
->scsi_host
);
1708 h
->scsi_host
= NULL
;
1711 static int hpsa_register_scsi(struct ctlr_info
*h
)
1715 hpsa_update_scsi_devices(h
, -1);
1716 rc
= hpsa_scsi_detect(h
);
1718 dev_err(&h
->pdev
->dev
, "hpsa_register_scsi: failed"
1719 " hpsa_scsi_detect(), rc is %d\n", rc
);
1723 static int wait_for_device_to_become_ready(struct ctlr_info
*h
,
1724 unsigned char lunaddr
[])
1729 struct CommandList
*c
;
1731 c
= cmd_special_alloc(h
);
1733 dev_warn(&h
->pdev
->dev
, "out of memory in "
1734 "wait_for_device_to_become_ready.\n");
1738 /* Send test unit ready until device ready, or give up. */
1739 while (count
< HPSA_TUR_RETRY_LIMIT
) {
1741 /* Wait for a bit. do this first, because if we send
1742 * the TUR right away, the reset will just abort it.
1744 set_current_state(TASK_UNINTERRUPTIBLE
);
1745 schedule_timeout(waittime
);
1748 /* Increase wait time with each try, up to a point. */
1749 if (waittime
< (HZ
* HPSA_MAX_WAIT_INTERVAL_SECS
))
1750 waittime
= waittime
* 2;
1752 /* Send the Test Unit Ready */
1753 rc
= fill_cmd(c
, TEST_UNIT_READY
, h
, NULL
, 0, 0,
1756 /* We don't expect to get in here */
1757 dev_warn(&h
->pdev
->dev
, "fill_cmd failed at %s:%d\n",
1758 __FILE__
, __LINE__
);
1762 hpsa_scsi_do_simple_cmd_core(h
, c
);
1763 /* no unmap needed here because no data xfer. */
1765 if (c
->err_info
->CommandStatus
== CMD_SUCCESS
)
1768 if (c
->err_info
->CommandStatus
== CMD_TARGET_STATUS
&&
1769 c
->err_info
->ScsiStatus
== SAM_STAT_CHECK_CONDITION
&&
1770 (c
->err_info
->SenseInfo
[2] == NO_SENSE
||
1771 c
->err_info
->SenseInfo
[2] == UNIT_ATTENTION
))
1774 dev_warn(&h
->pdev
->dev
, "waiting %d secs "
1775 "for device to become ready.\n", waittime
/ HZ
);
1776 rc
= 1; /* device not ready. */
1780 dev_warn(&h
->pdev
->dev
, "giving up on device.\n");
1782 dev_warn(&h
->pdev
->dev
, "device is ready.\n");
1784 cmd_special_free(h
, c
);
1788 /* Need at least one of these error handlers to keep ../scsi/hosts.c from
1789 * complaining. Doing a host- or bus-reset can't do anything good here.
1791 static int hpsa_eh_device_reset_handler(struct scsi_cmnd
*scsicmd
)
1794 struct ctlr_info
*h
;
1795 struct hpsa_scsi_dev_t
*dev
;
1797 /* find the controller to which the command to be aborted was sent */
1798 h
= (struct ctlr_info
*) scsicmd
->device
->host
->hostdata
[0];
1799 if (h
== NULL
) /* paranoia */
1801 dev_warn(&h
->pdev
->dev
, "resetting drive\n");
1803 dev
= scsicmd
->device
->hostdata
;
1805 dev_err(&h
->pdev
->dev
, "hpsa_eh_device_reset_handler: "
1806 "device lookup failed.\n");
1809 /* send a reset to the SCSI LUN which the command was sent to */
1810 rc
= hpsa_send_reset(h
, dev
->scsi3addr
);
1811 if (rc
== 0 && wait_for_device_to_become_ready(h
, dev
->scsi3addr
) == 0)
1814 dev_warn(&h
->pdev
->dev
, "resetting device failed.\n");
1819 * For operations that cannot sleep, a command block is allocated at init,
1820 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
1821 * which ones are free or in use. Lock must be held when calling this.
1822 * cmd_free() is the complement.
1824 static struct CommandList
*cmd_alloc(struct ctlr_info
*h
)
1826 struct CommandList
*c
;
1828 union u64bit temp64
;
1829 dma_addr_t cmd_dma_handle
, err_dma_handle
;
1832 i
= find_first_zero_bit(h
->cmd_pool_bits
, h
->nr_cmds
);
1833 if (i
== h
->nr_cmds
)
1835 } while (test_and_set_bit
1836 (i
& (BITS_PER_LONG
- 1),
1837 h
->cmd_pool_bits
+ (i
/ BITS_PER_LONG
)) != 0);
1838 c
= h
->cmd_pool
+ i
;
1839 memset(c
, 0, sizeof(*c
));
1840 cmd_dma_handle
= h
->cmd_pool_dhandle
1842 c
->err_info
= h
->errinfo_pool
+ i
;
1843 memset(c
->err_info
, 0, sizeof(*c
->err_info
));
1844 err_dma_handle
= h
->errinfo_pool_dhandle
1845 + i
* sizeof(*c
->err_info
);
1850 INIT_HLIST_NODE(&c
->list
);
1851 c
->busaddr
= (__u32
) cmd_dma_handle
;
1852 temp64
.val
= (__u64
) err_dma_handle
;
1853 c
->ErrDesc
.Addr
.lower
= temp64
.val32
.lower
;
1854 c
->ErrDesc
.Addr
.upper
= temp64
.val32
.upper
;
1855 c
->ErrDesc
.Len
= sizeof(*c
->err_info
);
1861 /* For operations that can wait for kmalloc to possibly sleep,
1862 * this routine can be called. Lock need not be held to call
1863 * cmd_special_alloc. cmd_special_free() is the complement.
1865 static struct CommandList
*cmd_special_alloc(struct ctlr_info
*h
)
1867 struct CommandList
*c
;
1868 union u64bit temp64
;
1869 dma_addr_t cmd_dma_handle
, err_dma_handle
;
1871 c
= pci_alloc_consistent(h
->pdev
, sizeof(*c
), &cmd_dma_handle
);
1874 memset(c
, 0, sizeof(*c
));
1878 c
->err_info
= pci_alloc_consistent(h
->pdev
, sizeof(*c
->err_info
),
1881 if (c
->err_info
== NULL
) {
1882 pci_free_consistent(h
->pdev
,
1883 sizeof(*c
), c
, cmd_dma_handle
);
1886 memset(c
->err_info
, 0, sizeof(*c
->err_info
));
1888 INIT_HLIST_NODE(&c
->list
);
1889 c
->busaddr
= (__u32
) cmd_dma_handle
;
1890 temp64
.val
= (__u64
) err_dma_handle
;
1891 c
->ErrDesc
.Addr
.lower
= temp64
.val32
.lower
;
1892 c
->ErrDesc
.Addr
.upper
= temp64
.val32
.upper
;
1893 c
->ErrDesc
.Len
= sizeof(*c
->err_info
);
1899 static void cmd_free(struct ctlr_info
*h
, struct CommandList
*c
)
1903 i
= c
- h
->cmd_pool
;
1904 clear_bit(i
& (BITS_PER_LONG
- 1),
1905 h
->cmd_pool_bits
+ (i
/ BITS_PER_LONG
));
1909 static void cmd_special_free(struct ctlr_info
*h
, struct CommandList
*c
)
1911 union u64bit temp64
;
1913 temp64
.val32
.lower
= c
->ErrDesc
.Addr
.lower
;
1914 temp64
.val32
.upper
= c
->ErrDesc
.Addr
.upper
;
1915 pci_free_consistent(h
->pdev
, sizeof(*c
->err_info
),
1916 c
->err_info
, (dma_addr_t
) temp64
.val
);
1917 pci_free_consistent(h
->pdev
, sizeof(*c
),
1918 c
, (dma_addr_t
) c
->busaddr
);
1921 #ifdef CONFIG_COMPAT
1923 static int do_ioctl(struct scsi_device
*dev
, int cmd
, void *arg
)
1928 ret
= hpsa_ioctl(dev
, cmd
, arg
);
1933 static int hpsa_ioctl32_passthru(struct scsi_device
*dev
, int cmd
, void *arg
);
1934 static int hpsa_ioctl32_big_passthru(struct scsi_device
*dev
,
1935 int cmd
, void *arg
);
1937 static int hpsa_compat_ioctl(struct scsi_device
*dev
, int cmd
, void *arg
)
1940 case CCISS_GETPCIINFO
:
1941 case CCISS_GETINTINFO
:
1942 case CCISS_SETINTINFO
:
1943 case CCISS_GETNODENAME
:
1944 case CCISS_SETNODENAME
:
1945 case CCISS_GETHEARTBEAT
:
1946 case CCISS_GETBUSTYPES
:
1947 case CCISS_GETFIRMVER
:
1948 case CCISS_GETDRIVVER
:
1949 case CCISS_REVALIDVOLS
:
1950 case CCISS_DEREGDISK
:
1951 case CCISS_REGNEWDISK
:
1953 case CCISS_RESCANDISK
:
1954 case CCISS_GETLUNINFO
:
1955 return do_ioctl(dev
, cmd
, arg
);
1957 case CCISS_PASSTHRU32
:
1958 return hpsa_ioctl32_passthru(dev
, cmd
, arg
);
1959 case CCISS_BIG_PASSTHRU32
:
1960 return hpsa_ioctl32_big_passthru(dev
, cmd
, arg
);
1963 return -ENOIOCTLCMD
;
1967 static int hpsa_ioctl32_passthru(struct scsi_device
*dev
, int cmd
, void *arg
)
1969 IOCTL32_Command_struct __user
*arg32
=
1970 (IOCTL32_Command_struct __user
*) arg
;
1971 IOCTL_Command_struct arg64
;
1972 IOCTL_Command_struct __user
*p
= compat_alloc_user_space(sizeof(arg64
));
1977 err
|= copy_from_user(&arg64
.LUN_info
, &arg32
->LUN_info
,
1978 sizeof(arg64
.LUN_info
));
1979 err
|= copy_from_user(&arg64
.Request
, &arg32
->Request
,
1980 sizeof(arg64
.Request
));
1981 err
|= copy_from_user(&arg64
.error_info
, &arg32
->error_info
,
1982 sizeof(arg64
.error_info
));
1983 err
|= get_user(arg64
.buf_size
, &arg32
->buf_size
);
1984 err
|= get_user(cp
, &arg32
->buf
);
1985 arg64
.buf
= compat_ptr(cp
);
1986 err
|= copy_to_user(p
, &arg64
, sizeof(arg64
));
1991 err
= do_ioctl(dev
, CCISS_PASSTHRU
, (void *)p
);
1994 err
|= copy_in_user(&arg32
->error_info
, &p
->error_info
,
1995 sizeof(arg32
->error_info
));
2001 static int hpsa_ioctl32_big_passthru(struct scsi_device
*dev
,
2004 BIG_IOCTL32_Command_struct __user
*arg32
=
2005 (BIG_IOCTL32_Command_struct __user
*) arg
;
2006 BIG_IOCTL_Command_struct arg64
;
2007 BIG_IOCTL_Command_struct __user
*p
=
2008 compat_alloc_user_space(sizeof(arg64
));
2013 err
|= copy_from_user(&arg64
.LUN_info
, &arg32
->LUN_info
,
2014 sizeof(arg64
.LUN_info
));
2015 err
|= copy_from_user(&arg64
.Request
, &arg32
->Request
,
2016 sizeof(arg64
.Request
));
2017 err
|= copy_from_user(&arg64
.error_info
, &arg32
->error_info
,
2018 sizeof(arg64
.error_info
));
2019 err
|= get_user(arg64
.buf_size
, &arg32
->buf_size
);
2020 err
|= get_user(arg64
.malloc_size
, &arg32
->malloc_size
);
2021 err
|= get_user(cp
, &arg32
->buf
);
2022 arg64
.buf
= compat_ptr(cp
);
2023 err
|= copy_to_user(p
, &arg64
, sizeof(arg64
));
2028 err
= do_ioctl(dev
, CCISS_BIG_PASSTHRU
, (void *)p
);
2031 err
|= copy_in_user(&arg32
->error_info
, &p
->error_info
,
2032 sizeof(arg32
->error_info
));
2039 static int hpsa_getpciinfo_ioctl(struct ctlr_info
*h
, void __user
*argp
)
2041 struct hpsa_pci_info pciinfo
;
2045 pciinfo
.domain
= pci_domain_nr(h
->pdev
->bus
);
2046 pciinfo
.bus
= h
->pdev
->bus
->number
;
2047 pciinfo
.dev_fn
= h
->pdev
->devfn
;
2048 pciinfo
.board_id
= h
->board_id
;
2049 if (copy_to_user(argp
, &pciinfo
, sizeof(pciinfo
)))
2054 static int hpsa_getdrivver_ioctl(struct ctlr_info
*h
, void __user
*argp
)
2056 DriverVer_type DriverVer
;
2057 unsigned char vmaj
, vmin
, vsubmin
;
2060 rc
= sscanf(HPSA_DRIVER_VERSION
, "%hhu.%hhu.%hhu",
2061 &vmaj
, &vmin
, &vsubmin
);
2063 dev_info(&h
->pdev
->dev
, "driver version string '%s' "
2064 "unrecognized.", HPSA_DRIVER_VERSION
);
2069 DriverVer
= (vmaj
<< 16) | (vmin
<< 8) | vsubmin
;
2072 if (copy_to_user(argp
, &DriverVer
, sizeof(DriverVer_type
)))
2077 static int hpsa_passthru_ioctl(struct ctlr_info
*h
, void __user
*argp
)
2079 IOCTL_Command_struct iocommand
;
2080 struct CommandList
*c
;
2082 union u64bit temp64
;
2083 DECLARE_COMPLETION_ONSTACK(wait
);
2087 if (!capable(CAP_SYS_RAWIO
))
2089 if (copy_from_user(&iocommand
, argp
, sizeof(iocommand
)))
2091 if ((iocommand
.buf_size
< 1) &&
2092 (iocommand
.Request
.Type
.Direction
!= XFER_NONE
)) {
2095 if (iocommand
.buf_size
> 0) {
2096 buff
= kmalloc(iocommand
.buf_size
, GFP_KERNEL
);
2100 if (iocommand
.Request
.Type
.Direction
== XFER_WRITE
) {
2101 /* Copy the data into the buffer we created */
2102 if (copy_from_user(buff
, iocommand
.buf
, iocommand
.buf_size
)) {
2107 memset(buff
, 0, iocommand
.buf_size
);
2108 c
= cmd_special_alloc(h
);
2113 /* Fill in the command type */
2114 c
->cmd_type
= CMD_IOCTL_PEND
;
2115 /* Fill in Command Header */
2116 c
->Header
.ReplyQueue
= 0; /* unused in simple mode */
2117 if (iocommand
.buf_size
> 0) { /* buffer to fill */
2118 c
->Header
.SGList
= 1;
2119 c
->Header
.SGTotal
= 1;
2120 } else { /* no buffers to fill */
2121 c
->Header
.SGList
= 0;
2122 c
->Header
.SGTotal
= 0;
2124 memcpy(&c
->Header
.LUN
, &iocommand
.LUN_info
, sizeof(c
->Header
.LUN
));
2125 /* use the kernel address the cmd block for tag */
2126 c
->Header
.Tag
.lower
= c
->busaddr
;
2128 /* Fill in Request block */
2129 memcpy(&c
->Request
, &iocommand
.Request
,
2130 sizeof(c
->Request
));
2132 /* Fill in the scatter gather information */
2133 if (iocommand
.buf_size
> 0) {
2134 temp64
.val
= pci_map_single(h
->pdev
, buff
,
2135 iocommand
.buf_size
, PCI_DMA_BIDIRECTIONAL
);
2136 c
->SG
[0].Addr
.lower
= temp64
.val32
.lower
;
2137 c
->SG
[0].Addr
.upper
= temp64
.val32
.upper
;
2138 c
->SG
[0].Len
= iocommand
.buf_size
;
2139 c
->SG
[0].Ext
= 0; /* we are not chaining*/
2142 enqueue_cmd_and_start_io(h
, c
);
2143 wait_for_completion(&wait
);
2145 /* unlock the buffers from DMA */
2146 temp64
.val32
.lower
= c
->SG
[0].Addr
.lower
;
2147 temp64
.val32
.upper
= c
->SG
[0].Addr
.upper
;
2148 pci_unmap_single(h
->pdev
, (dma_addr_t
) temp64
.val
, iocommand
.buf_size
,
2149 PCI_DMA_BIDIRECTIONAL
);
2151 /* Copy the error information out */
2152 memcpy(&iocommand
.error_info
, c
->err_info
,
2153 sizeof(iocommand
.error_info
));
2154 if (copy_to_user(argp
, &iocommand
, sizeof(iocommand
))) {
2156 cmd_special_free(h
, c
);
2160 if (iocommand
.Request
.Type
.Direction
== XFER_READ
) {
2161 /* Copy the data out of the buffer we created */
2162 if (copy_to_user(iocommand
.buf
, buff
, iocommand
.buf_size
)) {
2164 cmd_special_free(h
, c
);
2169 cmd_special_free(h
, c
);
2173 static int hpsa_big_passthru_ioctl(struct ctlr_info
*h
, void __user
*argp
)
2175 BIG_IOCTL_Command_struct
*ioc
;
2176 struct CommandList
*c
;
2177 unsigned char **buff
= NULL
;
2178 int *buff_size
= NULL
;
2179 union u64bit temp64
;
2183 DECLARE_COMPLETION_ONSTACK(wait
);
2186 BYTE __user
*data_ptr
;
2190 if (!capable(CAP_SYS_RAWIO
))
2192 ioc
= (BIG_IOCTL_Command_struct
*)
2193 kmalloc(sizeof(*ioc
), GFP_KERNEL
);
2198 if (copy_from_user(ioc
, argp
, sizeof(*ioc
))) {
2202 if ((ioc
->buf_size
< 1) &&
2203 (ioc
->Request
.Type
.Direction
!= XFER_NONE
)) {
2207 /* Check kmalloc limits using all SGs */
2208 if (ioc
->malloc_size
> MAX_KMALLOC_SIZE
) {
2212 if (ioc
->buf_size
> ioc
->malloc_size
* MAXSGENTRIES
) {
2216 buff
= kzalloc(MAXSGENTRIES
* sizeof(char *), GFP_KERNEL
);
2221 buff_size
= kmalloc(MAXSGENTRIES
* sizeof(int), GFP_KERNEL
);
2226 left
= ioc
->buf_size
;
2227 data_ptr
= ioc
->buf
;
2229 sz
= (left
> ioc
->malloc_size
) ? ioc
->malloc_size
: left
;
2230 buff_size
[sg_used
] = sz
;
2231 buff
[sg_used
] = kmalloc(sz
, GFP_KERNEL
);
2232 if (buff
[sg_used
] == NULL
) {
2236 if (ioc
->Request
.Type
.Direction
== XFER_WRITE
) {
2237 if (copy_from_user(buff
[sg_used
], data_ptr
, sz
)) {
2242 memset(buff
[sg_used
], 0, sz
);
2247 c
= cmd_special_alloc(h
);
2252 c
->cmd_type
= CMD_IOCTL_PEND
;
2253 c
->Header
.ReplyQueue
= 0;
2255 if (ioc
->buf_size
> 0) {
2256 c
->Header
.SGList
= sg_used
;
2257 c
->Header
.SGTotal
= sg_used
;
2259 c
->Header
.SGList
= 0;
2260 c
->Header
.SGTotal
= 0;
2262 memcpy(&c
->Header
.LUN
, &ioc
->LUN_info
, sizeof(c
->Header
.LUN
));
2263 c
->Header
.Tag
.lower
= c
->busaddr
;
2264 memcpy(&c
->Request
, &ioc
->Request
, sizeof(c
->Request
));
2265 if (ioc
->buf_size
> 0) {
2267 for (i
= 0; i
< sg_used
; i
++) {
2268 temp64
.val
= pci_map_single(h
->pdev
, buff
[i
],
2269 buff_size
[i
], PCI_DMA_BIDIRECTIONAL
);
2270 c
->SG
[i
].Addr
.lower
= temp64
.val32
.lower
;
2271 c
->SG
[i
].Addr
.upper
= temp64
.val32
.upper
;
2272 c
->SG
[i
].Len
= buff_size
[i
];
2273 /* we are not chaining */
2278 enqueue_cmd_and_start_io(h
, c
);
2279 wait_for_completion(&wait
);
2280 /* unlock the buffers from DMA */
2281 for (i
= 0; i
< sg_used
; i
++) {
2282 temp64
.val32
.lower
= c
->SG
[i
].Addr
.lower
;
2283 temp64
.val32
.upper
= c
->SG
[i
].Addr
.upper
;
2284 pci_unmap_single(h
->pdev
,
2285 (dma_addr_t
) temp64
.val
, buff_size
[i
],
2286 PCI_DMA_BIDIRECTIONAL
);
2288 /* Copy the error information out */
2289 memcpy(&ioc
->error_info
, c
->err_info
, sizeof(ioc
->error_info
));
2290 if (copy_to_user(argp
, ioc
, sizeof(*ioc
))) {
2291 cmd_special_free(h
, c
);
2295 if (ioc
->Request
.Type
.Direction
== XFER_READ
) {
2296 /* Copy the data out of the buffer we created */
2297 BYTE __user
*ptr
= ioc
->buf
;
2298 for (i
= 0; i
< sg_used
; i
++) {
2299 if (copy_to_user(ptr
, buff
[i
], buff_size
[i
])) {
2300 cmd_special_free(h
, c
);
2304 ptr
+= buff_size
[i
];
2307 cmd_special_free(h
, c
);
2311 for (i
= 0; i
< sg_used
; i
++)
2323 static int hpsa_ioctl(struct scsi_device
*dev
, int cmd
, void *arg
)
2325 struct ctlr_info
*h
;
2326 void __user
*argp
= (void __user
*)arg
;
2328 h
= (struct ctlr_info
*) dev
->host
->hostdata
[0];
2331 case CCISS_DEREGDISK
:
2332 case CCISS_REGNEWDISK
:
2334 hpsa_update_scsi_devices(h
, dev
->host
->host_no
);
2336 case CCISS_GETPCIINFO
:
2337 return hpsa_getpciinfo_ioctl(h
, argp
);
2338 case CCISS_GETDRIVVER
:
2339 return hpsa_getdrivver_ioctl(h
, argp
);
2340 case CCISS_PASSTHRU
:
2341 return hpsa_passthru_ioctl(h
, argp
);
2342 case CCISS_BIG_PASSTHRU
:
2343 return hpsa_big_passthru_ioctl(h
, argp
);
2349 static int fill_cmd(struct CommandList
*c
, __u8 cmd
, struct ctlr_info
*h
,
2350 void *buff
, size_t size
, __u8 page_code
, unsigned char *scsi3addr
,
2353 int pci_dir
= XFER_NONE
;
2355 c
->cmd_type
= CMD_IOCTL_PEND
;
2356 c
->Header
.ReplyQueue
= 0;
2357 if (buff
!= NULL
&& size
> 0) {
2358 c
->Header
.SGList
= 1;
2359 c
->Header
.SGTotal
= 1;
2361 c
->Header
.SGList
= 0;
2362 c
->Header
.SGTotal
= 0;
2364 c
->Header
.Tag
.lower
= c
->busaddr
;
2365 memcpy(c
->Header
.LUN
.LunAddrBytes
, scsi3addr
, 8);
2367 c
->Request
.Type
.Type
= cmd_type
;
2368 if (cmd_type
== TYPE_CMD
) {
2371 /* are we trying to read a vital product page */
2372 if (page_code
!= 0) {
2373 c
->Request
.CDB
[1] = 0x01;
2374 c
->Request
.CDB
[2] = page_code
;
2376 c
->Request
.CDBLen
= 6;
2377 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
2378 c
->Request
.Type
.Direction
= XFER_READ
;
2379 c
->Request
.Timeout
= 0;
2380 c
->Request
.CDB
[0] = HPSA_INQUIRY
;
2381 c
->Request
.CDB
[4] = size
& 0xFF;
2383 case HPSA_REPORT_LOG
:
2384 case HPSA_REPORT_PHYS
:
2385 /* Talking to controller so It's a physical command
2386 mode = 00 target = 0. Nothing to write.
2388 c
->Request
.CDBLen
= 12;
2389 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
2390 c
->Request
.Type
.Direction
= XFER_READ
;
2391 c
->Request
.Timeout
= 0;
2392 c
->Request
.CDB
[0] = cmd
;
2393 c
->Request
.CDB
[6] = (size
>> 24) & 0xFF; /* MSB */
2394 c
->Request
.CDB
[7] = (size
>> 16) & 0xFF;
2395 c
->Request
.CDB
[8] = (size
>> 8) & 0xFF;
2396 c
->Request
.CDB
[9] = size
& 0xFF;
2399 case HPSA_READ_CAPACITY
:
2400 c
->Request
.CDBLen
= 10;
2401 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
2402 c
->Request
.Type
.Direction
= XFER_READ
;
2403 c
->Request
.Timeout
= 0;
2404 c
->Request
.CDB
[0] = cmd
;
2406 case HPSA_CACHE_FLUSH
:
2407 c
->Request
.CDBLen
= 12;
2408 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
2409 c
->Request
.Type
.Direction
= XFER_WRITE
;
2410 c
->Request
.Timeout
= 0;
2411 c
->Request
.CDB
[0] = BMIC_WRITE
;
2412 c
->Request
.CDB
[6] = BMIC_CACHE_FLUSH
;
2414 case TEST_UNIT_READY
:
2415 c
->Request
.CDBLen
= 6;
2416 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
2417 c
->Request
.Type
.Direction
= XFER_NONE
;
2418 c
->Request
.Timeout
= 0;
2421 dev_warn(&h
->pdev
->dev
, "unknown command 0x%c\n", cmd
);
2424 } else if (cmd_type
== TYPE_MSG
) {
2427 case HPSA_DEVICE_RESET_MSG
:
2428 c
->Request
.CDBLen
= 16;
2429 c
->Request
.Type
.Type
= 1; /* It is a MSG not a CMD */
2430 c
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
2431 c
->Request
.Type
.Direction
= XFER_NONE
;
2432 c
->Request
.Timeout
= 0; /* Don't time out */
2433 c
->Request
.CDB
[0] = 0x01; /* RESET_MSG is 0x01 */
2434 c
->Request
.CDB
[1] = 0x03; /* Reset target above */
2435 /* If bytes 4-7 are zero, it means reset the */
2437 c
->Request
.CDB
[4] = 0x00;
2438 c
->Request
.CDB
[5] = 0x00;
2439 c
->Request
.CDB
[6] = 0x00;
2440 c
->Request
.CDB
[7] = 0x00;
2444 dev_warn(&h
->pdev
->dev
, "unknown message type %d\n",
2449 dev_warn(&h
->pdev
->dev
, "unknown command type %d\n", cmd_type
);
2453 switch (c
->Request
.Type
.Direction
) {
2455 pci_dir
= PCI_DMA_FROMDEVICE
;
2458 pci_dir
= PCI_DMA_TODEVICE
;
2461 pci_dir
= PCI_DMA_NONE
;
2464 pci_dir
= PCI_DMA_BIDIRECTIONAL
;
2467 hpsa_map_one(h
->pdev
, c
, buff
, size
, pci_dir
);
2473 * Wait polling for a command to complete.
2474 * The memory mapped FIFO is polled for the completion.
2475 * Used only at init time, interrupts from the HBA are disabled.
2477 static unsigned long pollcomplete(struct ctlr_info
*h
)
2482 /* Wait (up to HPSA_MAX_POLL_TIME_SECS) for a command to complete */
2483 for (i
= HPSA_MAX_POLL_TIME_SECS
* HZ
; i
> 0; i
--) {
2484 done
= h
->access
.command_completed(h
);
2485 if (done
== FIFO_EMPTY
)
2486 schedule_timeout_uninterruptible(1);
2490 /* Invalid address to tell caller we ran out of time */
2491 dev_warn(&h
->pdev
->dev
, "pollcomplete(): returning 1\n");
2495 /* Send command c to controller h and poll for it to complete.
2496 * Turns interrupts off on the board. Used at driver init time
2497 * and during SCSI error recovery.
2499 static int sendcmd_core(struct ctlr_info
*h
, struct CommandList
*c
)
2502 unsigned long complete
;
2503 int status
= IO_ERROR
;
2504 union u64bit buff_dma_handle
;
2510 h
->access
.set_intr_mask(h
, HPSA_INTR_OFF
);
2512 /* Make sure there is room in the command FIFO
2513 * Actually it should be completely empty at this time
2514 * unless we are in here doing error handling for the scsi
2515 * side of the driver.
2517 for (i
= 200000; i
> 0; i
--) {
2518 /* if fifo isn't full go */
2519 if (!(h
->access
.fifo_full(h
)))
2522 dev_warn(&h
->pdev
->dev
, "sendcmd FIFO full, waiting!\n");
2524 h
->access
.submit_command(h
, c
); /* Send the cmd */
2526 complete
= pollcomplete(h
);
2528 if (complete
== 1) {
2529 dev_warn(&h
->pdev
->dev
,
2530 "sendcmd timeout, no command list address "
2536 /* If it's not the cmd we're looking for, save it for later */
2537 if ((complete
& ~HPSA_ERROR_BIT
) != c
->busaddr
) {
2538 dev_warn(&h
->pdev
->dev
, "unexpected command "
2543 /* It is our command. If no error, we're done. */
2544 if (!(complete
& HPSA_ERROR_BIT
)) {
2549 /* There is an error... */
2551 /* if data overrun or underun on Report command ignore it */
2552 if (((c
->Request
.CDB
[0] == HPSA_REPORT_LOG
) ||
2553 (c
->Request
.CDB
[0] == HPSA_REPORT_PHYS
) ||
2554 (c
->Request
.CDB
[0] == HPSA_INQUIRY
)) &&
2555 ((c
->err_info
->CommandStatus
== CMD_DATA_OVERRUN
) ||
2556 (c
->err_info
->CommandStatus
== CMD_DATA_UNDERRUN
))) {
2557 complete
= c
->busaddr
;
2561 if (c
->err_info
->CommandStatus
== CMD_UNSOLICITED_ABORT
) {
2562 dev_warn(&h
->pdev
->dev
, "unsolicited abort %p\n", c
);
2563 if (c
->retry_count
< MAX_CMD_RETRIES
) {
2564 dev_warn(&h
->pdev
->dev
, "retrying %p\n", c
);
2566 /* erase the old error information */
2567 memset(c
->err_info
, 0, sizeof(c
->err_info
));
2570 dev_warn(&h
->pdev
->dev
,
2571 "retried %p too many times\n", c
);
2575 if (c
->err_info
->CommandStatus
== CMD_UNABORTABLE
) {
2576 dev_warn(&h
->pdev
->dev
,
2577 "command could not be aborted.\n");
2581 dev_warn(&h
->pdev
->dev
, "sendcmd error\n");
2582 dev_warn(&h
->pdev
->dev
,
2583 "cmd = 0x%02x, CommandStatus = 0x%02x\n",
2584 c
->Request
.CDB
[0], c
->err_info
->CommandStatus
);
2585 if (c
->err_info
->CommandStatus
== CMD_TARGET_STATUS
) {
2586 dev_warn(&h
->pdev
->dev
, "target status = 0x%02x\n",
2587 c
->err_info
->ScsiStatus
);
2588 if (c
->err_info
->ScsiStatus
== 2) /* chk cond */
2589 dev_warn(&h
->pdev
->dev
, "sense key = 0x%02x\n",
2590 0xf & c
->err_info
->SenseInfo
[2]);
2600 /* unlock the data buffer from DMA */
2601 buff_dma_handle
.val32
.lower
= c
->SG
[0].Addr
.lower
;
2602 buff_dma_handle
.val32
.upper
= c
->SG
[0].Addr
.upper
;
2603 pci_unmap_single(h
->pdev
, (dma_addr_t
) buff_dma_handle
.val
,
2604 c
->SG
[0].Len
, PCI_DMA_BIDIRECTIONAL
);
2609 * Send a command to the controller, and wait for it to complete.
2610 * Used at init time, and during SCSI error recovery.
2612 static int sendcmd(__u8 cmd
, struct ctlr_info
*h
, void *buff
, size_t size
,
2613 __u8 page_code
, unsigned char *scsi3addr
, int cmd_type
)
2615 struct CommandList
*c
;
2620 dev_warn(&h
->pdev
->dev
, "unable to get memory");
2623 status
= fill_cmd(c
, cmd
, h
, buff
, size
, page_code
,
2624 scsi3addr
, cmd_type
);
2625 if (status
== IO_OK
)
2626 status
= sendcmd_core(h
, c
);
2632 * Map (physical) PCI mem into (virtual) kernel space
2634 static void __iomem
*remap_pci_mem(ulong base
, ulong size
)
2636 ulong page_base
= ((ulong
) base
) & PAGE_MASK
;
2637 ulong page_offs
= ((ulong
) base
) - page_base
;
2638 void __iomem
*page_remapped
= ioremap(page_base
, page_offs
+ size
);
2640 return page_remapped
? (page_remapped
+ page_offs
) : NULL
;
2643 /* Takes cmds off the submission queue and sends them to the hardware,
2644 * then puts them on the queue of cmds waiting for completion.
2646 static void start_io(struct ctlr_info
*h
)
2648 struct CommandList
*c
;
2650 while (!hlist_empty(&h
->reqQ
)) {
2651 c
= hlist_entry(h
->reqQ
.first
, struct CommandList
, list
);
2652 /* can't do anything if fifo is full */
2653 if ((h
->access
.fifo_full(h
))) {
2654 dev_warn(&h
->pdev
->dev
, "fifo full\n");
2658 /* Get the first entry from the Request Q */
2662 /* Tell the controller execute command */
2663 h
->access
.submit_command(h
, c
);
2665 /* Put job onto the completed Q */
2670 static inline unsigned long get_next_completion(struct ctlr_info
*h
)
2672 return h
->access
.command_completed(h
);
2675 static inline int interrupt_pending(struct ctlr_info
*h
)
2677 return h
->access
.intr_pending(h
);
2680 static inline long interrupt_not_for_us(struct ctlr_info
*h
)
2682 return ((h
->access
.intr_pending(h
) == 0) ||
2683 (h
->interrupts_enabled
== 0));
2686 static inline int bad_tag(struct ctlr_info
*h
, __u32 tag_index
,
2689 if (unlikely(tag_index
>= h
->nr_cmds
)) {
2690 dev_warn(&h
->pdev
->dev
, "bad tag 0x%08x ignored.\n", raw_tag
);
2696 static inline void finish_cmd(struct CommandList
*c
, __u32 raw_tag
)
2699 if (likely(c
->cmd_type
== CMD_SCSI
))
2700 complete_scsi_command(c
, 0, raw_tag
);
2701 else if (c
->cmd_type
== CMD_IOCTL_PEND
)
2702 complete(c
->waiting
);
2705 static irqreturn_t
do_hpsa_intr(int irq
, void *dev_id
)
2707 struct ctlr_info
*h
= dev_id
;
2708 struct CommandList
*c
;
2709 unsigned long flags
;
2710 __u32 raw_tag
, tag
, tag_index
;
2711 struct hlist_node
*tmp
;
2713 if (interrupt_not_for_us(h
))
2715 spin_lock_irqsave(&h
->lock
, flags
);
2716 while (interrupt_pending(h
)) {
2717 while ((raw_tag
= get_next_completion(h
)) != FIFO_EMPTY
) {
2718 if (likely(HPSA_TAG_CONTAINS_INDEX(raw_tag
))) {
2719 tag_index
= HPSA_TAG_TO_INDEX(raw_tag
);
2720 if (bad_tag(h
, tag_index
, raw_tag
))
2722 c
= h
->cmd_pool
+ tag_index
;
2723 finish_cmd(c
, raw_tag
);
2726 tag
= HPSA_TAG_DISCARD_ERROR_BITS(raw_tag
);
2728 hlist_for_each_entry(c
, tmp
, &h
->cmpQ
, list
) {
2729 if (c
->busaddr
== tag
) {
2730 finish_cmd(c
, raw_tag
);
2736 spin_unlock_irqrestore(&h
->lock
, flags
);
2740 /* Send a message CDB to the firmware. */
2741 static __devinit
int hpsa_message(struct pci_dev
*pdev
, unsigned char opcode
,
2745 struct CommandListHeader CommandHeader
;
2746 struct RequestBlock Request
;
2747 struct ErrDescriptor ErrorDescriptor
;
2749 struct Command
*cmd
;
2750 static const size_t cmd_sz
= sizeof(*cmd
) +
2751 sizeof(cmd
->ErrorDescriptor
);
2753 uint32_t paddr32
, tag
;
2754 void __iomem
*vaddr
;
2757 vaddr
= pci_ioremap_bar(pdev
, 0);
2761 /* The Inbound Post Queue only accepts 32-bit physical addresses for the
2762 * CCISS commands, so they must be allocated from the lower 4GiB of
2765 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
2771 cmd
= pci_alloc_consistent(pdev
, cmd_sz
, &paddr64
);
2777 /* This must fit, because of the 32-bit consistent DMA mask. Also,
2778 * although there's no guarantee, we assume that the address is at
2779 * least 4-byte aligned (most likely, it's page-aligned).
2783 cmd
->CommandHeader
.ReplyQueue
= 0;
2784 cmd
->CommandHeader
.SGList
= 0;
2785 cmd
->CommandHeader
.SGTotal
= 0;
2786 cmd
->CommandHeader
.Tag
.lower
= paddr32
;
2787 cmd
->CommandHeader
.Tag
.upper
= 0;
2788 memset(&cmd
->CommandHeader
.LUN
.LunAddrBytes
, 0, 8);
2790 cmd
->Request
.CDBLen
= 16;
2791 cmd
->Request
.Type
.Type
= TYPE_MSG
;
2792 cmd
->Request
.Type
.Attribute
= ATTR_HEADOFQUEUE
;
2793 cmd
->Request
.Type
.Direction
= XFER_NONE
;
2794 cmd
->Request
.Timeout
= 0; /* Don't time out */
2795 cmd
->Request
.CDB
[0] = opcode
;
2796 cmd
->Request
.CDB
[1] = type
;
2797 memset(&cmd
->Request
.CDB
[2], 0, 14); /* rest of the CDB is reserved */
2798 cmd
->ErrorDescriptor
.Addr
.lower
= paddr32
+ sizeof(*cmd
);
2799 cmd
->ErrorDescriptor
.Addr
.upper
= 0;
2800 cmd
->ErrorDescriptor
.Len
= sizeof(struct ErrorInfo
);
2802 writel(paddr32
, vaddr
+ SA5_REQUEST_PORT_OFFSET
);
2804 for (i
= 0; i
< HPSA_MSG_SEND_RETRY_LIMIT
; i
++) {
2805 tag
= readl(vaddr
+ SA5_REPLY_PORT_OFFSET
);
2806 if (HPSA_TAG_DISCARD_ERROR_BITS(tag
) == paddr32
)
2808 schedule_timeout_uninterruptible(
2809 HPSA_MSG_SEND_RETRY_INTERVAL_SECS
* HZ
);
2814 /* we leak the DMA buffer here ... no choice since the controller could
2815 * still complete the command.
2817 if (i
== HPSA_MSG_SEND_RETRY_LIMIT
) {
2818 dev_err(&pdev
->dev
, "controller message %02x:%02x timed out\n",
2823 pci_free_consistent(pdev
, cmd_sz
, cmd
, paddr64
);
2825 if (tag
& HPSA_ERROR_BIT
) {
2826 dev_err(&pdev
->dev
, "controller message %02x:%02x failed\n",
2831 dev_info(&pdev
->dev
, "controller message %02x:%02x succeeded\n",
2836 #define hpsa_soft_reset_controller(p) hpsa_message(p, 1, 0)
2837 #define hpsa_noop(p) hpsa_message(p, 3, 0)
2839 static __devinit
int hpsa_reset_msi(struct pci_dev
*pdev
)
2841 /* the #defines are stolen from drivers/pci/msi.h. */
2842 #define msi_control_reg(base) (base + PCI_MSI_FLAGS)
2843 #define PCI_MSIX_FLAGS_ENABLE (1 << 15)
2848 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSI
);
2850 pci_read_config_word(pdev
, msi_control_reg(pos
), &control
);
2851 if (control
& PCI_MSI_FLAGS_ENABLE
) {
2852 dev_info(&pdev
->dev
, "resetting MSI\n");
2853 pci_write_config_word(pdev
, msi_control_reg(pos
),
2854 control
& ~PCI_MSI_FLAGS_ENABLE
);
2858 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
2860 pci_read_config_word(pdev
, msi_control_reg(pos
), &control
);
2861 if (control
& PCI_MSIX_FLAGS_ENABLE
) {
2862 dev_info(&pdev
->dev
, "resetting MSI-X\n");
2863 pci_write_config_word(pdev
, msi_control_reg(pos
),
2864 control
& ~PCI_MSIX_FLAGS_ENABLE
);
2871 /* This does a hard reset of the controller using PCI power management
2874 static __devinit
int hpsa_hard_reset_controller(struct pci_dev
*pdev
)
2876 u16 pmcsr
, saved_config_space
[32];
2879 dev_info(&pdev
->dev
, "using PCI PM to reset controller\n");
2881 /* This is very nearly the same thing as
2883 * pci_save_state(pci_dev);
2884 * pci_set_power_state(pci_dev, PCI_D3hot);
2885 * pci_set_power_state(pci_dev, PCI_D0);
2886 * pci_restore_state(pci_dev);
2888 * but we can't use these nice canned kernel routines on
2889 * kexec, because they also check the MSI/MSI-X state in PCI
2890 * configuration space and do the wrong thing when it is
2891 * set/cleared. Also, the pci_save/restore_state functions
2892 * violate the ordering requirements for restoring the
2893 * configuration space from the CCISS document (see the
2894 * comment below). So we roll our own ....
2897 for (i
= 0; i
< 32; i
++)
2898 pci_read_config_word(pdev
, 2*i
, &saved_config_space
[i
]);
2900 pos
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
2903 "hpsa_reset_controller: PCI PM not supported\n");
2907 /* Quoting from the Open CISS Specification: "The Power
2908 * Management Control/Status Register (CSR) controls the power
2909 * state of the device. The normal operating state is D0,
2910 * CSR=00h. The software off state is D3, CSR=03h. To reset
2911 * the controller, place the interface device in D3 then to
2912 * D0, this causes a secondary PCI reset which will reset the
2916 /* enter the D3hot power management state */
2917 pci_read_config_word(pdev
, pos
+ PCI_PM_CTRL
, &pmcsr
);
2918 pmcsr
&= ~PCI_PM_CTRL_STATE_MASK
;
2920 pci_write_config_word(pdev
, pos
+ PCI_PM_CTRL
, pmcsr
);
2922 set_current_state(TASK_UNINTERRUPTIBLE
);
2923 schedule_timeout(HZ
>> 1);
2925 /* enter the D0 power management state */
2926 pmcsr
&= ~PCI_PM_CTRL_STATE_MASK
;
2928 pci_write_config_word(pdev
, pos
+ PCI_PM_CTRL
, pmcsr
);
2930 set_current_state(TASK_UNINTERRUPTIBLE
);
2931 schedule_timeout(HZ
>> 1);
2933 /* Restore the PCI configuration space. The Open CISS
2934 * Specification says, "Restore the PCI Configuration
2935 * Registers, offsets 00h through 60h. It is important to
2936 * restore the command register, 16-bits at offset 04h,
2937 * last. Do not restore the configuration status register,
2938 * 16-bits at offset 06h." Note that the offset is 2*i.
2940 for (i
= 0; i
< 32; i
++) {
2941 if (i
== 2 || i
== 3)
2943 pci_write_config_word(pdev
, 2*i
, saved_config_space
[i
]);
2946 pci_write_config_word(pdev
, 4, saved_config_space
[2]);
2952 * We cannot read the structure directly, for portability we must use
2954 * This is for debug only.
2957 static void print_cfg_table(struct device
*dev
, struct CfgTable
*tb
)
2962 dev_info(dev
, "Controller Configuration information\n");
2963 dev_info(dev
, "------------------------------------\n");
2964 for (i
= 0; i
< 4; i
++)
2965 temp_name
[i
] = readb(&(tb
->Signature
[i
]));
2966 temp_name
[4] = '\0';
2967 dev_info(dev
, " Signature = %s\n", temp_name
);
2968 dev_info(dev
, " Spec Number = %d\n", readl(&(tb
->SpecValence
)));
2969 dev_info(dev
, " Transport methods supported = 0x%x\n",
2970 readl(&(tb
->TransportSupport
)));
2971 dev_info(dev
, " Transport methods active = 0x%x\n",
2972 readl(&(tb
->TransportActive
)));
2973 dev_info(dev
, " Requested transport Method = 0x%x\n",
2974 readl(&(tb
->HostWrite
.TransportRequest
)));
2975 dev_info(dev
, " Coalesce Interrupt Delay = 0x%x\n",
2976 readl(&(tb
->HostWrite
.CoalIntDelay
)));
2977 dev_info(dev
, " Coalesce Interrupt Count = 0x%x\n",
2978 readl(&(tb
->HostWrite
.CoalIntCount
)));
2979 dev_info(dev
, " Max outstanding commands = 0x%d\n",
2980 readl(&(tb
->CmdsOutMax
)));
2981 dev_info(dev
, " Bus Types = 0x%x\n", readl(&(tb
->BusTypes
)));
2982 for (i
= 0; i
< 16; i
++)
2983 temp_name
[i
] = readb(&(tb
->ServerName
[i
]));
2984 temp_name
[16] = '\0';
2985 dev_info(dev
, " Server Name = %s\n", temp_name
);
2986 dev_info(dev
, " Heartbeat Counter = 0x%x\n\n\n",
2987 readl(&(tb
->HeartBeat
)));
2989 #endif /* HPSA_DEBUG */
2991 static int find_PCI_BAR_index(struct pci_dev
*pdev
, unsigned long pci_bar_addr
)
2993 int i
, offset
, mem_type
, bar_type
;
2995 if (pci_bar_addr
== PCI_BASE_ADDRESS_0
) /* looking for BAR zero? */
2998 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
2999 bar_type
= pci_resource_flags(pdev
, i
) & PCI_BASE_ADDRESS_SPACE
;
3000 if (bar_type
== PCI_BASE_ADDRESS_SPACE_IO
)
3003 mem_type
= pci_resource_flags(pdev
, i
) &
3004 PCI_BASE_ADDRESS_MEM_TYPE_MASK
;
3006 case PCI_BASE_ADDRESS_MEM_TYPE_32
:
3007 case PCI_BASE_ADDRESS_MEM_TYPE_1M
:
3008 offset
+= 4; /* 32 bit */
3010 case PCI_BASE_ADDRESS_MEM_TYPE_64
:
3013 default: /* reserved in PCI 2.2 */
3014 dev_warn(&pdev
->dev
,
3015 "base address is invalid\n");
3020 if (offset
== pci_bar_addr
- PCI_BASE_ADDRESS_0
)
3026 /* If MSI/MSI-X is supported by the kernel we will try to enable it on
3027 * controllers that are capable. If not, we use IO-APIC mode.
3030 static void __devinit
hpsa_interrupt_mode(struct ctlr_info
*h
,
3031 struct pci_dev
*pdev
, __u32 board_id
)
3033 #ifdef CONFIG_PCI_MSI
3035 struct msix_entry hpsa_msix_entries
[4] = { {0, 0}, {0, 1},
3039 /* Some boards advertise MSI but don't really support it */
3040 if ((board_id
== 0x40700E11) ||
3041 (board_id
== 0x40800E11) ||
3042 (board_id
== 0x40820E11) || (board_id
== 0x40830E11))
3043 goto default_int_mode
;
3044 if (pci_find_capability(pdev
, PCI_CAP_ID_MSIX
)) {
3045 dev_info(&pdev
->dev
, "MSIX\n");
3046 err
= pci_enable_msix(pdev
, hpsa_msix_entries
, 4);
3048 h
->intr
[0] = hpsa_msix_entries
[0].vector
;
3049 h
->intr
[1] = hpsa_msix_entries
[1].vector
;
3050 h
->intr
[2] = hpsa_msix_entries
[2].vector
;
3051 h
->intr
[3] = hpsa_msix_entries
[3].vector
;
3056 dev_warn(&pdev
->dev
, "only %d MSI-X vectors "
3057 "available\n", err
);
3058 goto default_int_mode
;
3060 dev_warn(&pdev
->dev
, "MSI-X init failed %d\n",
3062 goto default_int_mode
;
3065 if (pci_find_capability(pdev
, PCI_CAP_ID_MSI
)) {
3066 dev_info(&pdev
->dev
, "MSI\n");
3067 if (!pci_enable_msi(pdev
))
3070 dev_warn(&pdev
->dev
, "MSI init failed\n");
3073 #endif /* CONFIG_PCI_MSI */
3074 /* if we get here we're going to use the default interrupt mode */
3075 h
->intr
[SIMPLE_MODE_INT
] = pdev
->irq
;
3079 static int hpsa_pci_init(struct ctlr_info
*h
, struct pci_dev
*pdev
)
3081 ushort subsystem_vendor_id
, subsystem_device_id
, command
;
3082 __u32 board_id
, scratchpad
= 0;
3084 __u32 cfg_base_addr
;
3085 __u64 cfg_base_addr_index
;
3086 int i
, prod_index
, err
;
3088 subsystem_vendor_id
= pdev
->subsystem_vendor
;
3089 subsystem_device_id
= pdev
->subsystem_device
;
3090 board_id
= (((__u32
) (subsystem_device_id
<< 16) & 0xffff0000) |
3091 subsystem_vendor_id
);
3093 for (i
= 0; i
< ARRAY_SIZE(products
); i
++)
3094 if (board_id
== products
[i
].board_id
)
3099 if (prod_index
== ARRAY_SIZE(products
)) {
3101 if (subsystem_vendor_id
!= PCI_VENDOR_ID_HP
||
3103 dev_warn(&pdev
->dev
, "unrecognized board ID:"
3104 " 0x%08lx, ignoring.\n",
3105 (unsigned long) board_id
);
3109 /* check to see if controller has been disabled
3110 * BEFORE trying to enable it
3112 (void)pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
3113 if (!(command
& 0x02)) {
3114 dev_warn(&pdev
->dev
, "controller appears to be disabled\n");
3118 err
= pci_enable_device(pdev
);
3120 dev_warn(&pdev
->dev
, "unable to enable PCI device\n");
3124 err
= pci_request_regions(pdev
, "hpsa");
3126 dev_err(&pdev
->dev
, "cannot obtain PCI resources, aborting\n");
3130 /* If the kernel supports MSI/MSI-X we will try to enable that,
3131 * else we use the IO-APIC interrupt assigned to us by system ROM.
3133 hpsa_interrupt_mode(h
, pdev
, board_id
);
3135 /* find the memory BAR */
3136 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
3137 if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
)
3140 if (i
== DEVICE_COUNT_RESOURCE
) {
3141 dev_warn(&pdev
->dev
, "no memory BAR found\n");
3143 goto err_out_free_res
;
3146 h
->paddr
= pci_resource_start(pdev
, i
); /* addressing mode bits
3150 h
->vaddr
= remap_pci_mem(h
->paddr
, 0x250);
3152 /* Wait for the board to become ready. */
3153 for (i
= 0; i
< HPSA_BOARD_READY_ITERATIONS
; i
++) {
3154 scratchpad
= readl(h
->vaddr
+ SA5_SCRATCHPAD_OFFSET
);
3155 if (scratchpad
== HPSA_FIRMWARE_READY
)
3157 set_current_state(TASK_INTERRUPTIBLE
);
3158 schedule_timeout(HPSA_BOARD_READY_POLL_INTERVAL
);
3160 if (scratchpad
!= HPSA_FIRMWARE_READY
) {
3161 dev_warn(&pdev
->dev
, "board not ready, timed out.\n");
3163 goto err_out_free_res
;
3166 /* get the address index number */
3167 cfg_base_addr
= readl(h
->vaddr
+ SA5_CTCFG_OFFSET
);
3168 cfg_base_addr
&= (__u32
) 0x0000ffff;
3169 cfg_base_addr_index
= find_PCI_BAR_index(pdev
, cfg_base_addr
);
3170 if (cfg_base_addr_index
== -1) {
3171 dev_warn(&pdev
->dev
, "cannot find cfg_base_addr_index\n");
3173 goto err_out_free_res
;
3176 cfg_offset
= readl(h
->vaddr
+ SA5_CTMEM_OFFSET
);
3177 h
->cfgtable
= remap_pci_mem(pci_resource_start(pdev
,
3178 cfg_base_addr_index
) + cfg_offset
,
3179 sizeof(h
->cfgtable
));
3180 h
->board_id
= board_id
;
3182 /* Query controller for max supported commands: */
3183 h
->max_commands
= readl(&(h
->cfgtable
->CmdsOutMax
));
3185 h
->product_name
= products
[prod_index
].product_name
;
3186 h
->access
= *(products
[prod_index
].access
);
3187 /* Allow room for some ioctls */
3188 h
->nr_cmds
= h
->max_commands
- 4;
3190 if ((readb(&h
->cfgtable
->Signature
[0]) != 'C') ||
3191 (readb(&h
->cfgtable
->Signature
[1]) != 'I') ||
3192 (readb(&h
->cfgtable
->Signature
[2]) != 'S') ||
3193 (readb(&h
->cfgtable
->Signature
[3]) != 'S')) {
3194 dev_warn(&pdev
->dev
, "not a valid CISS config table\n");
3196 goto err_out_free_res
;
3200 /* Need to enable prefetch in the SCSI core for 6400 in x86 */
3202 prefetch
= readl(&(h
->cfgtable
->SCSI_Prefetch
));
3204 writel(prefetch
, &(h
->cfgtable
->SCSI_Prefetch
));
3208 /* Disabling DMA prefetch for the P600
3209 * An ASIC bug may result in a prefetch beyond
3212 if (board_id
== 0x3225103C) {
3214 dma_prefetch
= readl(h
->vaddr
+ I2O_DMA1_CFG
);
3215 dma_prefetch
|= 0x8000;
3216 writel(dma_prefetch
, h
->vaddr
+ I2O_DMA1_CFG
);
3219 h
->max_commands
= readl(&(h
->cfgtable
->CmdsOutMax
));
3220 /* Update the field, and then ring the doorbell */
3221 writel(CFGTBL_Trans_Simple
, &(h
->cfgtable
->HostWrite
.TransportRequest
));
3222 writel(CFGTBL_ChangeReq
, h
->vaddr
+ SA5_DOORBELL
);
3224 /* under certain very rare conditions, this can take awhile.
3225 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
3226 * as we enter this code.)
3228 for (i
= 0; i
< MAX_CONFIG_WAIT
; i
++) {
3229 if (!(readl(h
->vaddr
+ SA5_DOORBELL
) & CFGTBL_ChangeReq
))
3231 /* delay and try again */
3232 set_current_state(TASK_INTERRUPTIBLE
);
3233 schedule_timeout(10);
3237 print_cfg_table(&pdev
->dev
, h
->cfgtable
);
3238 #endif /* HPSA_DEBUG */
3240 if (!(readl(&(h
->cfgtable
->TransportActive
)) & CFGTBL_Trans_Simple
)) {
3241 dev_warn(&pdev
->dev
, "unable to get board into simple mode\n");
3243 goto err_out_free_res
;
3249 * Deliberately omit pci_disable_device(): it does something nasty to
3250 * Smart Array controllers that pci_enable_device does not undo
3252 pci_release_regions(pdev
);
3256 static int __devinit
hpsa_init_one(struct pci_dev
*pdev
,
3257 const struct pci_device_id
*ent
)
3261 struct ctlr_info
*h
;
3263 if (number_of_controllers
== 0)
3264 printk(KERN_INFO DRIVER_NAME
"\n");
3265 if (reset_devices
) {
3266 /* Reset the controller with a PCI power-cycle */
3267 if (hpsa_hard_reset_controller(pdev
) || hpsa_reset_msi(pdev
))
3270 /* Some devices (notably the HP Smart Array 5i Controller)
3271 need a little pause here */
3272 schedule_timeout_uninterruptible(HPSA_POST_RESET_PAUSE
);
3274 /* Now try to get the controller to respond to a no-op */
3275 for (i
= 0; i
< HPSA_POST_RESET_NOOP_RETRIES
; i
++) {
3276 if (hpsa_noop(pdev
) == 0)
3279 dev_warn(&pdev
->dev
, "no-op failed%s\n",
3280 (i
< 11 ? "; re-trying" : ""));
3284 BUILD_BUG_ON(sizeof(struct CommandList
) % 8);
3285 h
= kzalloc(sizeof(*h
), GFP_KERNEL
);
3289 INIT_HLIST_HEAD(&h
->cmpQ
);
3290 INIT_HLIST_HEAD(&h
->reqQ
);
3291 if (hpsa_pci_init(h
, pdev
) != 0)
3294 sprintf(h
->devname
, "hpsa%d", number_of_controllers
);
3295 h
->ctlr
= number_of_controllers
;
3296 number_of_controllers
++;
3299 /* configure PCI DMA stuff */
3300 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
3302 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
3305 dev_err(&pdev
->dev
, "no suitable DMA available\n");
3309 /* make sure the board interrupts are off */
3310 h
->access
.set_intr_mask(h
, HPSA_INTR_OFF
);
3311 if (request_irq(h
->intr
[SIMPLE_MODE_INT
], do_hpsa_intr
,
3312 IRQF_DISABLED
| IRQF_SHARED
, h
->devname
, h
)) {
3313 dev_err(&pdev
->dev
, "unable to get irq %d for %s\n",
3314 h
->intr
[SIMPLE_MODE_INT
], h
->devname
);
3318 dev_info(&pdev
->dev
, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
3319 h
->devname
, pdev
->device
, pci_name(pdev
),
3320 h
->intr
[SIMPLE_MODE_INT
], dac
? "" : " not");
3323 kmalloc(((h
->nr_cmds
+ BITS_PER_LONG
-
3324 1) / BITS_PER_LONG
) * sizeof(unsigned long), GFP_KERNEL
);
3325 h
->cmd_pool
= pci_alloc_consistent(h
->pdev
,
3326 h
->nr_cmds
* sizeof(*h
->cmd_pool
),
3327 &(h
->cmd_pool_dhandle
));
3328 h
->errinfo_pool
= pci_alloc_consistent(h
->pdev
,
3329 h
->nr_cmds
* sizeof(*h
->errinfo_pool
),
3330 &(h
->errinfo_pool_dhandle
));
3331 if ((h
->cmd_pool_bits
== NULL
)
3332 || (h
->cmd_pool
== NULL
)
3333 || (h
->errinfo_pool
== NULL
)) {
3334 dev_err(&pdev
->dev
, "out of memory");
3337 spin_lock_init(&h
->lock
);
3339 pci_set_drvdata(pdev
, h
);
3340 memset(h
->cmd_pool_bits
, 0,
3341 ((h
->nr_cmds
+ BITS_PER_LONG
-
3342 1) / BITS_PER_LONG
) * sizeof(unsigned long));
3346 /* Turn the interrupts on so we can service requests */
3347 h
->access
.set_intr_mask(h
, HPSA_INTR_ON
);
3349 hpsa_register_scsi(h
); /* hook ourselves into SCSI subsystem */
3354 kfree(h
->cmd_pool_bits
);
3356 pci_free_consistent(h
->pdev
,
3357 h
->nr_cmds
* sizeof(struct CommandList
),
3358 h
->cmd_pool
, h
->cmd_pool_dhandle
);
3359 if (h
->errinfo_pool
)
3360 pci_free_consistent(h
->pdev
,
3361 h
->nr_cmds
* sizeof(struct ErrorInfo
),
3363 h
->errinfo_pool_dhandle
);
3364 free_irq(h
->intr
[SIMPLE_MODE_INT
], h
);
3371 static void hpsa_shutdown(struct pci_dev
*pdev
)
3373 struct ctlr_info
*h
;
3377 h
= pci_get_drvdata(pdev
);
3378 /* Turn board interrupts off and send the flush cache command
3379 * sendcmd will turn off interrupt, and send the flush...
3380 * To write all data in the battery backed cache to disks
3382 memset(flush_buf
, 0, 4);
3383 return_code
= sendcmd(HPSA_CACHE_FLUSH
, h
, flush_buf
, 4, 0,
3384 RAID_CTLR_LUNID
, TYPE_CMD
);
3385 if (return_code
!= IO_OK
) {
3386 dev_warn(&pdev
->dev
, "error flushing cache on controller %d\n",
3389 free_irq(h
->intr
[2], h
);
3390 #ifdef CONFIG_PCI_MSI
3392 pci_disable_msix(h
->pdev
);
3393 else if (h
->msi_vector
)
3394 pci_disable_msi(h
->pdev
);
3395 #endif /* CONFIG_PCI_MSI */
3398 static void __devexit
hpsa_remove_one(struct pci_dev
*pdev
)
3400 struct ctlr_info
*h
;
3402 if (pci_get_drvdata(pdev
) == NULL
) {
3403 dev_err(&pdev
->dev
, "unable to remove device \n");
3406 h
= pci_get_drvdata(pdev
);
3407 hpsa_unregister_scsi(h
); /* unhook from SCSI subsystem */
3408 hpsa_shutdown(pdev
);
3410 pci_free_consistent(h
->pdev
,
3411 h
->nr_cmds
* sizeof(struct CommandList
),
3412 h
->cmd_pool
, h
->cmd_pool_dhandle
);
3413 pci_free_consistent(h
->pdev
,
3414 h
->nr_cmds
* sizeof(struct ErrorInfo
),
3415 h
->errinfo_pool
, h
->errinfo_pool_dhandle
);
3416 kfree(h
->cmd_pool_bits
);
3418 * Deliberately omit pci_disable_device(): it does something nasty to
3419 * Smart Array controllers that pci_enable_device does not undo
3421 pci_release_regions(pdev
);
3422 pci_set_drvdata(pdev
, NULL
);
3426 static int hpsa_suspend(__attribute__((unused
)) struct pci_dev
*pdev
,
3427 __attribute__((unused
)) pm_message_t state
)
3432 static int hpsa_resume(__attribute__((unused
)) struct pci_dev
*pdev
)
3437 static struct pci_driver hpsa_pci_driver
= {
3439 .probe
= hpsa_init_one
,
3440 .remove
= __devexit_p(hpsa_remove_one
),
3441 .id_table
= hpsa_pci_device_id
, /* id_table */
3442 .shutdown
= hpsa_shutdown
,
3443 .suspend
= hpsa_suspend
,
3444 .resume
= hpsa_resume
,
3448 * This is it. Register the PCI driver information for the cards we control
3449 * the OS will call our registered routines when it finds one of our cards.
3451 static int __init
hpsa_init(void)
3453 return pci_register_driver(&hpsa_pci_driver
);
3456 static void __exit
hpsa_cleanup(void)
3458 pci_unregister_driver(&hpsa_pci_driver
);
3461 module_init(hpsa_init
);
3462 module_exit(hpsa_cleanup
);