Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Disk Array driver for HP SA 5xxx and 6xxx Controllers |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 3 | * Copyright 2000, 2006 Hewlett-Packard Development Company, L.P. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 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; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 13 | * NON INFRINGEMENT. See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | * |
| 19 | * Questions/Comments/Bugfixes to iss_storagedev@hp.com |
| 20 | * |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/pci.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/major.h> |
| 31 | #include <linux/fs.h> |
| 32 | #include <linux/bio.h> |
| 33 | #include <linux/blkpg.h> |
| 34 | #include <linux/timer.h> |
| 35 | #include <linux/proc_fs.h> |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 36 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/hdreg.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/compat.h> |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 40 | #include <linux/blktrace_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/uaccess.h> |
| 42 | #include <asm/io.h> |
| 43 | |
mike.miller@hp.com | eb0df99 | 2005-06-10 14:51:04 -0500 | [diff] [blame] | 44 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/blkdev.h> |
| 46 | #include <linux/genhd.h> |
| 47 | #include <linux/completion.h> |
| 48 | |
| 49 | #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin)) |
Mike Miller | 9d827c9 | 2006-12-06 20:34:58 -0800 | [diff] [blame] | 50 | #define DRIVER_NAME "HP CISS Driver (v 3.6.14)" |
| 51 | #define DRIVER_VERSION CCISS_DRIVER_VERSION(3,6,14) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* Embedded module documentation macros - see modules.h */ |
| 54 | MODULE_AUTHOR("Hewlett-Packard Company"); |
Mike Miller | 9d827c9 | 2006-12-06 20:34:58 -0800 | [diff] [blame] | 55 | MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 3.6.14"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400" |
Mike Miller | 1883c5a | 2006-09-12 20:36:07 -0700 | [diff] [blame] | 57 | " SA6i P600 P800 P400 P400i E200 E200i E500"); |
Mike Miller | 9d827c9 | 2006-12-06 20:34:58 -0800 | [diff] [blame] | 58 | MODULE_VERSION("3.6.14"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | MODULE_LICENSE("GPL"); |
| 60 | |
| 61 | #include "cciss_cmd.h" |
| 62 | #include "cciss.h" |
| 63 | #include <linux/cciss_ioctl.h> |
| 64 | |
| 65 | /* define the PCI info for the cards we can control */ |
| 66 | static const struct pci_device_id cciss_pci_device_id[] = { |
Bjorn Helgaas | f82ccdb | 2006-06-25 05:49:07 -0700 | [diff] [blame] | 67 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISS, 0x0E11, 0x4070}, |
| 68 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4080}, |
| 69 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4082}, |
| 70 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4083}, |
| 71 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x4091}, |
| 72 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409A}, |
| 73 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409B}, |
| 74 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409C}, |
| 75 | {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC, 0x0E11, 0x409D}, |
| 76 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSA, 0x103C, 0x3225}, |
| 77 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3223}, |
| 78 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3234}, |
| 79 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3235}, |
| 80 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3211}, |
| 81 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3212}, |
| 82 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3213}, |
| 83 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3214}, |
| 84 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3215}, |
Mike Miller | de92391 | 2006-12-06 20:35:03 -0800 | [diff] [blame] | 85 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3237}, |
Mike Miller | 4ff9a9a | 2006-12-06 20:35:00 -0800 | [diff] [blame] | 86 | {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 87 | PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | {0,} |
| 89 | }; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | MODULE_DEVICE_TABLE(pci, cciss_pci_device_id); |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* board_id = Subsystem Device ID & Vendor ID |
| 94 | * product = Marketing Name for the board |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 95 | * access = Address of the struct of function pointers |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 96 | * nr_cmds = Number of commands supported by controller |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | */ |
| 98 | static struct board_type products[] = { |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 99 | {0x40700E11, "Smart Array 5300", &SA5_access, 512}, |
| 100 | {0x40800E11, "Smart Array 5i", &SA5B_access, 512}, |
| 101 | {0x40820E11, "Smart Array 532", &SA5B_access, 512}, |
| 102 | {0x40830E11, "Smart Array 5312", &SA5B_access, 512}, |
| 103 | {0x409A0E11, "Smart Array 641", &SA5_access, 512}, |
| 104 | {0x409B0E11, "Smart Array 642", &SA5_access, 512}, |
| 105 | {0x409C0E11, "Smart Array 6400", &SA5_access, 512}, |
| 106 | {0x409D0E11, "Smart Array 6400 EM", &SA5_access, 512}, |
| 107 | {0x40910E11, "Smart Array 6i", &SA5_access, 512}, |
| 108 | {0x3225103C, "Smart Array P600", &SA5_access, 512}, |
| 109 | {0x3223103C, "Smart Array P800", &SA5_access, 512}, |
| 110 | {0x3234103C, "Smart Array P400", &SA5_access, 512}, |
| 111 | {0x3235103C, "Smart Array P400i", &SA5_access, 512}, |
| 112 | {0x3211103C, "Smart Array E200i", &SA5_access, 120}, |
| 113 | {0x3212103C, "Smart Array E200", &SA5_access, 120}, |
| 114 | {0x3213103C, "Smart Array E200i", &SA5_access, 120}, |
| 115 | {0x3214103C, "Smart Array E200i", &SA5_access, 120}, |
| 116 | {0x3215103C, "Smart Array E200i", &SA5_access, 120}, |
Mike Miller | de92391 | 2006-12-06 20:35:03 -0800 | [diff] [blame] | 117 | {0x3237103C, "Smart Array E500", &SA5_access, 512}, |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 118 | {0xFFFF103C, "Unknown Smart Array", &SA5_access, 120}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 121 | /* How long to wait (in milliseconds) for board to go into simple mode */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 122 | #define MAX_CONFIG_WAIT 30000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #define MAX_IOCTL_CONFIG_WAIT 1000 |
| 124 | |
| 125 | /*define how many times we will try a command because of bus resets */ |
| 126 | #define MAX_CMD_RETRIES 3 |
| 127 | |
| 128 | #define READ_AHEAD 1024 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | #define MAX_CTLR 32 |
| 130 | |
| 131 | /* Originally cciss driver only supports 8 major numbers */ |
| 132 | #define MAX_CTLR_ORIG 8 |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | static ctlr_info_t *hba[MAX_CTLR]; |
| 135 | |
| 136 | static void do_cciss_request(request_queue_t *q); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 137 | static irqreturn_t do_cciss_intr(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static int cciss_open(struct inode *inode, struct file *filep); |
| 139 | static int cciss_release(struct inode *inode, struct file *filep); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 140 | static int cciss_ioctl(struct inode *inode, struct file *filep, |
| 141 | unsigned int cmd, unsigned long arg); |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 142 | static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static int cciss_revalidate(struct gendisk *disk); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 145 | static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 146 | static int deregister_disk(struct gendisk *disk, drive_info_struct *drv, |
| 147 | int clear_all); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 149 | static void cciss_read_capacity(int ctlr, int logvol, int withirq, |
| 150 | sector_t *total_size, unsigned int *block_size); |
| 151 | static void cciss_read_capacity_16(int ctlr, int logvol, int withirq, |
| 152 | sector_t *total_size, unsigned int *block_size); |
| 153 | static void cciss_geometry_inquiry(int ctlr, int logvol, |
| 154 | int withirq, sector_t total_size, |
| 155 | unsigned int block_size, InquiryData_struct *inq_buff, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 156 | drive_info_struct *drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | static void cciss_getgeometry(int cntl_num); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 158 | static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *, |
| 159 | __u32); |
| 160 | static void start_io(ctlr_info_t *h); |
| 161 | static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, |
| 162 | unsigned int use_unit_num, unsigned int log_unit, |
| 163 | __u8 page_code, unsigned char *scsi3addr, int cmd_type); |
| 164 | static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, |
| 165 | unsigned int use_unit_num, unsigned int log_unit, |
| 166 | __u8 page_code, int cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 168 | static void fail_all_cmds(unsigned long ctlr); |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #ifdef CONFIG_PROC_FS |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 171 | static int cciss_proc_get_info(char *buffer, char **start, off_t offset, |
| 172 | int length, int *eof, void *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | static void cciss_procinit(int i); |
| 174 | #else |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 175 | static void cciss_procinit(int i) |
| 176 | { |
| 177 | } |
| 178 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | #ifdef CONFIG_COMPAT |
| 181 | static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg); |
| 182 | #endif |
| 183 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 184 | static struct block_device_operations cciss_fops = { |
| 185 | .owner = THIS_MODULE, |
| 186 | .open = cciss_open, |
| 187 | .release = cciss_release, |
| 188 | .ioctl = cciss_ioctl, |
| 189 | .getgeo = cciss_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #ifdef CONFIG_COMPAT |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 191 | .compat_ioctl = cciss_compat_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | #endif |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 193 | .revalidate_disk = cciss_revalidate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | /* |
| 197 | * Enqueuing and dequeuing functions for cmdlists. |
| 198 | */ |
| 199 | static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c) |
| 200 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 201 | if (*Qptr == NULL) { |
| 202 | *Qptr = c; |
| 203 | c->next = c->prev = c; |
| 204 | } else { |
| 205 | c->prev = (*Qptr)->prev; |
| 206 | c->next = (*Qptr); |
| 207 | (*Qptr)->prev->next = c; |
| 208 | (*Qptr)->prev = c; |
| 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 212 | static inline CommandList_struct *removeQ(CommandList_struct **Qptr, |
| 213 | CommandList_struct *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 215 | if (c && c->next != c) { |
| 216 | if (*Qptr == c) |
| 217 | *Qptr = c->next; |
| 218 | c->prev->next = c->next; |
| 219 | c->next->prev = c->prev; |
| 220 | } else { |
| 221 | *Qptr = NULL; |
| 222 | } |
| 223 | return c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | #include "cciss_scsi.c" /* For SCSI tape support */ |
| 227 | |
| 228 | #ifdef CONFIG_PROC_FS |
| 229 | |
| 230 | /* |
| 231 | * Report information about this controller. |
| 232 | */ |
| 233 | #define ENG_GIG 1000000000 |
| 234 | #define ENG_GIG_FACTOR (ENG_GIG/512) |
| 235 | #define RAID_UNKNOWN 6 |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 236 | static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", |
| 237 | "UNKNOWN" |
| 238 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | static struct proc_dir_entry *proc_cciss; |
| 241 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 242 | static int cciss_proc_get_info(char *buffer, char **start, off_t offset, |
| 243 | int length, int *eof, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 245 | off_t pos = 0; |
| 246 | off_t len = 0; |
| 247 | int size, i, ctlr; |
| 248 | ctlr_info_t *h = (ctlr_info_t *) data; |
| 249 | drive_info_struct *drv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | unsigned long flags; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 251 | sector_t vol_sz, vol_sz_frac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 253 | ctlr = h->ctlr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | /* prevent displaying bogus info during configuration |
| 256 | * or deconfiguration of a logical volume |
| 257 | */ |
| 258 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
| 259 | if (h->busy_configuring) { |
| 260 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 261 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | h->busy_configuring = 1; |
| 264 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
| 265 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 266 | size = sprintf(buffer, "%s: HP %s Controller\n" |
| 267 | "Board ID: 0x%08lx\n" |
| 268 | "Firmware Version: %c%c%c%c\n" |
| 269 | "IRQ: %d\n" |
| 270 | "Logical drives: %d\n" |
Mike Miller | 92c4231a | 2006-12-06 20:35:06 -0800 | [diff] [blame] | 271 | "Max sectors: %d\n" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 272 | "Current Q depth: %d\n" |
| 273 | "Current # commands on controller: %d\n" |
| 274 | "Max Q depth since init: %d\n" |
| 275 | "Max # commands on controller since init: %d\n" |
| 276 | "Max SG entries since init: %d\n\n", |
| 277 | h->devname, |
| 278 | h->product_name, |
| 279 | (unsigned long)h->board_id, |
| 280 | h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], |
| 281 | h->firm_ver[3], (unsigned int)h->intr[SIMPLE_MODE_INT], |
Mike Miller | 92c4231a | 2006-12-06 20:35:06 -0800 | [diff] [blame] | 282 | h->num_luns, |
| 283 | h->cciss_max_sectors, |
| 284 | h->Qdepth, h->commands_outstanding, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 285 | h->maxQsinceinit, h->max_outstanding, h->maxSG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 287 | pos += size; |
| 288 | len += size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | cciss_proc_tape_report(ctlr, buffer, &pos, &len); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 290 | for (i = 0; i <= h->highest_lun; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 292 | drv = &h->drv[i]; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 293 | if (drv->heads == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | continue; |
| 295 | |
| 296 | vol_sz = drv->nr_blocks; |
| 297 | vol_sz_frac = sector_div(vol_sz, ENG_GIG_FACTOR); |
| 298 | vol_sz_frac *= 100; |
| 299 | sector_div(vol_sz_frac, ENG_GIG_FACTOR); |
| 300 | |
| 301 | if (drv->raid_level > 5) |
| 302 | drv->raid_level = RAID_UNKNOWN; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 303 | size = sprintf(buffer + len, "cciss/c%dd%d:" |
| 304 | "\t%4u.%02uGB\tRAID %s\n", |
| 305 | ctlr, i, (int)vol_sz, (int)vol_sz_frac, |
| 306 | raid_label[drv->raid_level]); |
| 307 | pos += size; |
| 308 | len += size; |
| 309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 311 | *eof = 1; |
| 312 | *start = buffer + offset; |
| 313 | len -= offset; |
| 314 | if (len > length) |
| 315 | len = length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | h->busy_configuring = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 317 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 320 | static int |
| 321 | cciss_proc_write(struct file *file, const char __user *buffer, |
| 322 | unsigned long count, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
| 324 | unsigned char cmd[80]; |
| 325 | int len; |
| 326 | #ifdef CONFIG_CISS_SCSI_TAPE |
| 327 | ctlr_info_t *h = (ctlr_info_t *) data; |
| 328 | int rc; |
| 329 | #endif |
| 330 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 331 | if (count > sizeof(cmd) - 1) |
| 332 | return -EINVAL; |
| 333 | if (copy_from_user(cmd, buffer, count)) |
| 334 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | cmd[count] = '\0'; |
| 336 | len = strlen(cmd); // above 3 lines ensure safety |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 337 | if (len && cmd[len - 1] == '\n') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | cmd[--len] = '\0'; |
| 339 | # ifdef CONFIG_CISS_SCSI_TAPE |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 340 | if (strcmp("engage scsi", cmd) == 0) { |
| 341 | rc = cciss_engage_scsi(h->ctlr); |
| 342 | if (rc != 0) |
| 343 | return -rc; |
| 344 | return count; |
| 345 | } |
| 346 | /* might be nice to have "disengage" too, but it's not |
| 347 | safely possible. (only 1 module use count, lock issues.) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | # endif |
| 349 | return -EINVAL; |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * Get us a file in /proc/cciss that says something about each controller. |
| 354 | * Create /proc/cciss if it doesn't exist yet. |
| 355 | */ |
| 356 | static void __devinit cciss_procinit(int i) |
| 357 | { |
| 358 | struct proc_dir_entry *pde; |
| 359 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 360 | if (proc_cciss == NULL) { |
| 361 | proc_cciss = proc_mkdir("cciss", proc_root_driver); |
| 362 | if (!proc_cciss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 366 | pde = create_proc_read_entry(hba[i]->devname, |
| 367 | S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, |
| 368 | proc_cciss, cciss_proc_get_info, hba[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | pde->write_proc = cciss_proc_write; |
| 370 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 371 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 373 | /* |
| 374 | * For operations that cannot sleep, a command block is allocated at init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 376 | * which ones are free or in use. For operations that can wait for kmalloc |
| 377 | * to possible sleep, this routine can be called with get_from_pool set to 0. |
| 378 | * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was. |
| 379 | */ |
| 380 | static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
| 382 | CommandList_struct *c; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 383 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | u64bit temp64; |
| 385 | dma_addr_t cmd_dma_handle, err_dma_handle; |
| 386 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 387 | if (!get_from_pool) { |
| 388 | c = (CommandList_struct *) pci_alloc_consistent(h->pdev, |
| 389 | sizeof(CommandList_struct), &cmd_dma_handle); |
| 390 | if (c == NULL) |
| 391 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | memset(c, 0, sizeof(CommandList_struct)); |
| 393 | |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 394 | c->cmdindex = -1; |
| 395 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 396 | c->err_info = (ErrorInfo_struct *) |
| 397 | pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct), |
| 398 | &err_dma_handle); |
| 399 | |
| 400 | if (c->err_info == NULL) { |
| 401 | pci_free_consistent(h->pdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | sizeof(CommandList_struct), c, cmd_dma_handle); |
| 403 | return NULL; |
| 404 | } |
| 405 | memset(c->err_info, 0, sizeof(ErrorInfo_struct)); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 406 | } else { /* get it out of the controllers pool */ |
| 407 | |
| 408 | do { |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 409 | i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds); |
| 410 | if (i == h->nr_cmds) |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 411 | return NULL; |
| 412 | } while (test_and_set_bit |
| 413 | (i & (BITS_PER_LONG - 1), |
| 414 | h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | #ifdef CCISS_DEBUG |
| 416 | printk(KERN_DEBUG "cciss: using command buffer %d\n", i); |
| 417 | #endif |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 418 | c = h->cmd_pool + i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | memset(c, 0, sizeof(CommandList_struct)); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 420 | cmd_dma_handle = h->cmd_pool_dhandle |
| 421 | + i * sizeof(CommandList_struct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | c->err_info = h->errinfo_pool + i; |
| 423 | memset(c->err_info, 0, sizeof(ErrorInfo_struct)); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 424 | err_dma_handle = h->errinfo_pool_dhandle |
| 425 | + i * sizeof(ErrorInfo_struct); |
| 426 | h->nr_allocs++; |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 427 | |
| 428 | c->cmdindex = i; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | c->busaddr = (__u32) cmd_dma_handle; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 432 | temp64.val = (__u64) err_dma_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | c->ErrDesc.Addr.lower = temp64.val32.lower; |
| 434 | c->ErrDesc.Addr.upper = temp64.val32.upper; |
| 435 | c->ErrDesc.Len = sizeof(ErrorInfo_struct); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | c->ctlr = h->ctlr; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 438 | return c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 441 | /* |
| 442 | * Frees a command block that was previously allocated with cmd_alloc(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | */ |
| 444 | static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool) |
| 445 | { |
| 446 | int i; |
| 447 | u64bit temp64; |
| 448 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 449 | if (!got_from_pool) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | temp64.val32.lower = c->ErrDesc.Addr.lower; |
| 451 | temp64.val32.upper = c->ErrDesc.Addr.upper; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 452 | pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct), |
| 453 | c->err_info, (dma_addr_t) temp64.val); |
| 454 | pci_free_consistent(h->pdev, sizeof(CommandList_struct), |
| 455 | c, (dma_addr_t) c->busaddr); |
| 456 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | i = c - h->cmd_pool; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 458 | clear_bit(i & (BITS_PER_LONG - 1), |
| 459 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 460 | h->nr_frees++; |
| 461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static inline ctlr_info_t *get_host(struct gendisk *disk) |
| 465 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 466 | return disk->queue->queuedata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static inline drive_info_struct *get_drv(struct gendisk *disk) |
| 470 | { |
| 471 | return disk->private_data; |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * Open. Make sure the device is really there. |
| 476 | */ |
| 477 | static int cciss_open(struct inode *inode, struct file *filep) |
| 478 | { |
| 479 | ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); |
| 480 | drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk); |
| 481 | |
| 482 | #ifdef CCISS_DEBUG |
| 483 | printk(KERN_DEBUG "cciss_open %s\n", inode->i_bdev->bd_disk->disk_name); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 484 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 486 | if (host->busy_initializing || drv->busy_configuring) |
| 487 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | /* |
| 489 | * Root is allowed to open raw volume zero even if it's not configured |
| 490 | * so array config can still work. Root is also allowed to open any |
| 491 | * volume that has a LUN ID, so it can issue IOCTL to reread the |
| 492 | * disk information. I don't think I really like this |
| 493 | * but I'm already using way to many device nodes to claim another one |
| 494 | * for "raw controller". |
| 495 | */ |
Mike Miller | 7a06f78 | 2006-12-06 20:35:08 -0800 | [diff] [blame] | 496 | if (drv->heads == 0) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 497 | if (iminor(inode) != 0) { /* not node 0? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* if not node 0 make sure it is a partition = 0 */ |
| 499 | if (iminor(inode) & 0x0f) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 500 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | /* if it is, make sure we have a LUN ID */ |
| 502 | } else if (drv->LunID == 0) { |
| 503 | return -ENXIO; |
| 504 | } |
| 505 | } |
| 506 | if (!capable(CAP_SYS_ADMIN)) |
| 507 | return -EPERM; |
| 508 | } |
| 509 | drv->usage_count++; |
| 510 | host->usage_count++; |
| 511 | return 0; |
| 512 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* |
| 515 | * Close. Sync first. |
| 516 | */ |
| 517 | static int cciss_release(struct inode *inode, struct file *filep) |
| 518 | { |
| 519 | ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); |
| 520 | drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk); |
| 521 | |
| 522 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 523 | printk(KERN_DEBUG "cciss_release %s\n", |
| 524 | inode->i_bdev->bd_disk->disk_name); |
| 525 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | drv->usage_count--; |
| 528 | host->usage_count--; |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | #ifdef CONFIG_COMPAT |
| 533 | |
| 534 | static int do_ioctl(struct file *f, unsigned cmd, unsigned long arg) |
| 535 | { |
| 536 | int ret; |
| 537 | lock_kernel(); |
Josef Sipek | 6c648be | 2006-12-08 02:36:55 -0800 | [diff] [blame] | 538 | ret = cciss_ioctl(f->f_path.dentry->d_inode, f, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | unlock_kernel(); |
| 540 | return ret; |
| 541 | } |
| 542 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 543 | static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, |
| 544 | unsigned long arg); |
| 545 | static int cciss_ioctl32_big_passthru(struct file *f, unsigned cmd, |
| 546 | unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg) |
| 549 | { |
| 550 | switch (cmd) { |
| 551 | case CCISS_GETPCIINFO: |
| 552 | case CCISS_GETINTINFO: |
| 553 | case CCISS_SETINTINFO: |
| 554 | case CCISS_GETNODENAME: |
| 555 | case CCISS_SETNODENAME: |
| 556 | case CCISS_GETHEARTBEAT: |
| 557 | case CCISS_GETBUSTYPES: |
| 558 | case CCISS_GETFIRMVER: |
| 559 | case CCISS_GETDRIVVER: |
| 560 | case CCISS_REVALIDVOLS: |
| 561 | case CCISS_DEREGDISK: |
| 562 | case CCISS_REGNEWDISK: |
| 563 | case CCISS_REGNEWD: |
| 564 | case CCISS_RESCANDISK: |
| 565 | case CCISS_GETLUNINFO: |
| 566 | return do_ioctl(f, cmd, arg); |
| 567 | |
| 568 | case CCISS_PASSTHRU32: |
| 569 | return cciss_ioctl32_passthru(f, cmd, arg); |
| 570 | case CCISS_BIG_PASSTHRU32: |
| 571 | return cciss_ioctl32_big_passthru(f, cmd, arg); |
| 572 | |
| 573 | default: |
| 574 | return -ENOIOCTLCMD; |
| 575 | } |
| 576 | } |
| 577 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 578 | static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, |
| 579 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
| 581 | IOCTL32_Command_struct __user *arg32 = |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 582 | (IOCTL32_Command_struct __user *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | IOCTL_Command_struct arg64; |
| 584 | IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64)); |
| 585 | int err; |
| 586 | u32 cp; |
| 587 | |
| 588 | err = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 589 | err |= |
| 590 | copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 591 | sizeof(arg64.LUN_info)); |
| 592 | err |= |
| 593 | copy_from_user(&arg64.Request, &arg32->Request, |
| 594 | sizeof(arg64.Request)); |
| 595 | err |= |
| 596 | copy_from_user(&arg64.error_info, &arg32->error_info, |
| 597 | sizeof(arg64.error_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 599 | err |= get_user(cp, &arg32->buf); |
| 600 | arg64.buf = compat_ptr(cp); |
| 601 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 602 | |
| 603 | if (err) |
| 604 | return -EFAULT; |
| 605 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 606 | err = do_ioctl(f, CCISS_PASSTHRU, (unsigned long)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | if (err) |
| 608 | return err; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 609 | err |= |
| 610 | copy_in_user(&arg32->error_info, &p->error_info, |
| 611 | sizeof(arg32->error_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | if (err) |
| 613 | return -EFAULT; |
| 614 | return err; |
| 615 | } |
| 616 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 617 | static int cciss_ioctl32_big_passthru(struct file *file, unsigned cmd, |
| 618 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
| 620 | BIG_IOCTL32_Command_struct __user *arg32 = |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 621 | (BIG_IOCTL32_Command_struct __user *) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | BIG_IOCTL_Command_struct arg64; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 623 | BIG_IOCTL_Command_struct __user *p = |
| 624 | compat_alloc_user_space(sizeof(arg64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | int err; |
| 626 | u32 cp; |
| 627 | |
| 628 | err = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 629 | err |= |
| 630 | copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 631 | sizeof(arg64.LUN_info)); |
| 632 | err |= |
| 633 | copy_from_user(&arg64.Request, &arg32->Request, |
| 634 | sizeof(arg64.Request)); |
| 635 | err |= |
| 636 | copy_from_user(&arg64.error_info, &arg32->error_info, |
| 637 | sizeof(arg64.error_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 639 | err |= get_user(arg64.malloc_size, &arg32->malloc_size); |
| 640 | err |= get_user(cp, &arg32->buf); |
| 641 | arg64.buf = compat_ptr(cp); |
| 642 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 643 | |
| 644 | if (err) |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 645 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 647 | err = do_ioctl(file, CCISS_BIG_PASSTHRU, (unsigned long)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (err) |
| 649 | return err; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 650 | err |= |
| 651 | copy_in_user(&arg32->error_info, &p->error_info, |
| 652 | sizeof(arg32->error_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | if (err) |
| 654 | return -EFAULT; |
| 655 | return err; |
| 656 | } |
| 657 | #endif |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 658 | |
| 659 | static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 660 | { |
| 661 | drive_info_struct *drv = get_drv(bdev->bd_disk); |
| 662 | |
| 663 | if (!drv->cylinders) |
| 664 | return -ENXIO; |
| 665 | |
| 666 | geo->heads = drv->heads; |
| 667 | geo->sectors = drv->sectors; |
| 668 | geo->cylinders = drv->cylinders; |
| 669 | return 0; |
| 670 | } |
| 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | /* |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 673 | * ioctl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 675 | static int cciss_ioctl(struct inode *inode, struct file *filep, |
| 676 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | { |
| 678 | struct block_device *bdev = inode->i_bdev; |
| 679 | struct gendisk *disk = bdev->bd_disk; |
| 680 | ctlr_info_t *host = get_host(disk); |
| 681 | drive_info_struct *drv = get_drv(disk); |
| 682 | int ctlr = host->ctlr; |
| 683 | void __user *argp = (void __user *)arg; |
| 684 | |
| 685 | #ifdef CCISS_DEBUG |
| 686 | printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 687 | #endif /* CCISS_DEBUG */ |
| 688 | |
| 689 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | case CCISS_GETPCIINFO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 692 | cciss_pci_info_struct pciinfo; |
| 693 | |
| 694 | if (!arg) |
| 695 | return -EINVAL; |
| 696 | pciinfo.domain = pci_domain_nr(host->pdev->bus); |
| 697 | pciinfo.bus = host->pdev->bus->number; |
| 698 | pciinfo.dev_fn = host->pdev->devfn; |
| 699 | pciinfo.board_id = host->board_id; |
| 700 | if (copy_to_user |
| 701 | (argp, &pciinfo, sizeof(cciss_pci_info_struct))) |
| 702 | return -EFAULT; |
| 703 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 705 | case CCISS_GETINTINFO: |
| 706 | { |
| 707 | cciss_coalint_struct intinfo; |
| 708 | if (!arg) |
| 709 | return -EINVAL; |
| 710 | intinfo.delay = |
| 711 | readl(&host->cfgtable->HostWrite.CoalIntDelay); |
| 712 | intinfo.count = |
| 713 | readl(&host->cfgtable->HostWrite.CoalIntCount); |
| 714 | if (copy_to_user |
| 715 | (argp, &intinfo, sizeof(cciss_coalint_struct))) |
| 716 | return -EFAULT; |
| 717 | return 0; |
| 718 | } |
| 719 | case CCISS_SETINTINFO: |
| 720 | { |
| 721 | cciss_coalint_struct intinfo; |
| 722 | unsigned long flags; |
| 723 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 725 | if (!arg) |
| 726 | return -EINVAL; |
| 727 | if (!capable(CAP_SYS_ADMIN)) |
| 728 | return -EPERM; |
| 729 | if (copy_from_user |
| 730 | (&intinfo, argp, sizeof(cciss_coalint_struct))) |
| 731 | return -EFAULT; |
| 732 | if ((intinfo.delay == 0) && (intinfo.count == 0)) |
| 733 | { |
| 734 | // printk("cciss_ioctl: delay and count cannot be 0\n"); |
| 735 | return -EINVAL; |
| 736 | } |
| 737 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
| 738 | /* Update the field, and then ring the doorbell */ |
| 739 | writel(intinfo.delay, |
| 740 | &(host->cfgtable->HostWrite.CoalIntDelay)); |
| 741 | writel(intinfo.count, |
| 742 | &(host->cfgtable->HostWrite.CoalIntCount)); |
| 743 | writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL); |
| 744 | |
| 745 | for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) { |
| 746 | if (!(readl(host->vaddr + SA5_DOORBELL) |
| 747 | & CFGTBL_ChangeReq)) |
| 748 | break; |
| 749 | /* delay and try again */ |
| 750 | udelay(1000); |
| 751 | } |
| 752 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
| 753 | if (i >= MAX_IOCTL_CONFIG_WAIT) |
| 754 | return -EAGAIN; |
| 755 | return 0; |
| 756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | case CCISS_GETNODENAME: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 758 | { |
| 759 | NodeName_type NodeName; |
| 760 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 762 | if (!arg) |
| 763 | return -EINVAL; |
| 764 | for (i = 0; i < 16; i++) |
| 765 | NodeName[i] = |
| 766 | readb(&host->cfgtable->ServerName[i]); |
| 767 | if (copy_to_user(argp, NodeName, sizeof(NodeName_type))) |
| 768 | return -EFAULT; |
| 769 | return 0; |
| 770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | case CCISS_SETNODENAME: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 772 | { |
| 773 | NodeName_type NodeName; |
| 774 | unsigned long flags; |
| 775 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 777 | if (!arg) |
| 778 | return -EINVAL; |
| 779 | if (!capable(CAP_SYS_ADMIN)) |
| 780 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 782 | if (copy_from_user |
| 783 | (NodeName, argp, sizeof(NodeName_type))) |
| 784 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 786 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 788 | /* Update the field, and then ring the doorbell */ |
| 789 | for (i = 0; i < 16; i++) |
| 790 | writeb(NodeName[i], |
| 791 | &host->cfgtable->ServerName[i]); |
| 792 | |
| 793 | writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL); |
| 794 | |
| 795 | for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) { |
| 796 | if (!(readl(host->vaddr + SA5_DOORBELL) |
| 797 | & CFGTBL_ChangeReq)) |
| 798 | break; |
| 799 | /* delay and try again */ |
| 800 | udelay(1000); |
| 801 | } |
| 802 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
| 803 | if (i >= MAX_IOCTL_CONFIG_WAIT) |
| 804 | return -EAGAIN; |
| 805 | return 0; |
| 806 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
| 808 | case CCISS_GETHEARTBEAT: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 809 | { |
| 810 | Heartbeat_type heartbeat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 812 | if (!arg) |
| 813 | return -EINVAL; |
| 814 | heartbeat = readl(&host->cfgtable->HeartBeat); |
| 815 | if (copy_to_user |
| 816 | (argp, &heartbeat, sizeof(Heartbeat_type))) |
| 817 | return -EFAULT; |
| 818 | return 0; |
| 819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | case CCISS_GETBUSTYPES: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 821 | { |
| 822 | BusTypes_type BusTypes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 824 | if (!arg) |
| 825 | return -EINVAL; |
| 826 | BusTypes = readl(&host->cfgtable->BusTypes); |
| 827 | if (copy_to_user |
| 828 | (argp, &BusTypes, sizeof(BusTypes_type))) |
| 829 | return -EFAULT; |
| 830 | return 0; |
| 831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | case CCISS_GETFIRMVER: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 833 | { |
| 834 | FirmwareVer_type firmware; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 836 | if (!arg) |
| 837 | return -EINVAL; |
| 838 | memcpy(firmware, host->firm_ver, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 840 | if (copy_to_user |
| 841 | (argp, firmware, sizeof(FirmwareVer_type))) |
| 842 | return -EFAULT; |
| 843 | return 0; |
| 844 | } |
| 845 | case CCISS_GETDRIVVER: |
| 846 | { |
| 847 | DriverVer_type DriverVer = DRIVER_VERSION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 849 | if (!arg) |
| 850 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 852 | if (copy_to_user |
| 853 | (argp, &DriverVer, sizeof(DriverVer_type))) |
| 854 | return -EFAULT; |
| 855 | return 0; |
| 856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
| 858 | case CCISS_REVALIDVOLS: |
Mike Miller | 3833a74 | 2006-12-06 20:35:10 -0800 | [diff] [blame] | 859 | return rebuild_lun_table(host, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 861 | case CCISS_GETLUNINFO:{ |
| 862 | LogvolInfo_struct luninfo; |
| 863 | |
| 864 | luninfo.LunID = drv->LunID; |
| 865 | luninfo.num_opens = drv->usage_count; |
| 866 | luninfo.num_parts = 0; |
| 867 | if (copy_to_user(argp, &luninfo, |
| 868 | sizeof(LogvolInfo_struct))) |
| 869 | return -EFAULT; |
| 870 | return 0; |
| 871 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | case CCISS_DEREGDISK: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 873 | return rebuild_lun_table(host, disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | case CCISS_REGNEWD: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 876 | return rebuild_lun_table(host, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | case CCISS_PASSTHRU: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 880 | IOCTL_Command_struct iocommand; |
| 881 | CommandList_struct *c; |
| 882 | char *buff = NULL; |
| 883 | u64bit temp64; |
| 884 | unsigned long flags; |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 885 | DECLARE_COMPLETION_ONSTACK(wait); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 886 | |
| 887 | if (!arg) |
| 888 | return -EINVAL; |
| 889 | |
| 890 | if (!capable(CAP_SYS_RAWIO)) |
| 891 | return -EPERM; |
| 892 | |
| 893 | if (copy_from_user |
| 894 | (&iocommand, argp, sizeof(IOCTL_Command_struct))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | return -EFAULT; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 896 | if ((iocommand.buf_size < 1) && |
| 897 | (iocommand.Request.Type.Direction != XFER_NONE)) { |
| 898 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 900 | #if 0 /* 'buf_size' member is 16-bits, and always smaller than kmalloc limit */ |
| 901 | /* Check kmalloc limits */ |
| 902 | if (iocommand.buf_size > 128000) |
| 903 | return -EINVAL; |
| 904 | #endif |
| 905 | if (iocommand.buf_size > 0) { |
| 906 | buff = kmalloc(iocommand.buf_size, GFP_KERNEL); |
| 907 | if (buff == NULL) |
| 908 | return -EFAULT; |
| 909 | } |
| 910 | if (iocommand.Request.Type.Direction == XFER_WRITE) { |
| 911 | /* Copy the data into the buffer we created */ |
| 912 | if (copy_from_user |
| 913 | (buff, iocommand.buf, iocommand.buf_size)) { |
| 914 | kfree(buff); |
| 915 | return -EFAULT; |
| 916 | } |
| 917 | } else { |
| 918 | memset(buff, 0, iocommand.buf_size); |
| 919 | } |
| 920 | if ((c = cmd_alloc(host, 0)) == NULL) { |
| 921 | kfree(buff); |
| 922 | return -ENOMEM; |
| 923 | } |
| 924 | // Fill in the command type |
| 925 | c->cmd_type = CMD_IOCTL_PEND; |
| 926 | // Fill in Command Header |
| 927 | c->Header.ReplyQueue = 0; // unused in simple mode |
| 928 | if (iocommand.buf_size > 0) // buffer to fill |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 930 | c->Header.SGList = 1; |
| 931 | c->Header.SGTotal = 1; |
| 932 | } else // no buffers to fill |
| 933 | { |
| 934 | c->Header.SGList = 0; |
| 935 | c->Header.SGTotal = 0; |
| 936 | } |
| 937 | c->Header.LUN = iocommand.LUN_info; |
| 938 | c->Header.Tag.lower = c->busaddr; // use the kernel address the cmd block for tag |
| 939 | |
| 940 | // Fill in Request block |
| 941 | c->Request = iocommand.Request; |
| 942 | |
| 943 | // Fill in the scatter gather information |
| 944 | if (iocommand.buf_size > 0) { |
| 945 | temp64.val = pci_map_single(host->pdev, buff, |
| 946 | iocommand.buf_size, |
| 947 | PCI_DMA_BIDIRECTIONAL); |
| 948 | c->SG[0].Addr.lower = temp64.val32.lower; |
| 949 | c->SG[0].Addr.upper = temp64.val32.upper; |
| 950 | c->SG[0].Len = iocommand.buf_size; |
| 951 | c->SG[0].Ext = 0; // we are not chaining |
| 952 | } |
| 953 | c->waiting = &wait; |
| 954 | |
| 955 | /* Put the request on the tail of the request queue */ |
| 956 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
| 957 | addQ(&host->reqQ, c); |
| 958 | host->Qdepth++; |
| 959 | start_io(host); |
| 960 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
| 961 | |
| 962 | wait_for_completion(&wait); |
| 963 | |
| 964 | /* unlock the buffers from DMA */ |
| 965 | temp64.val32.lower = c->SG[0].Addr.lower; |
| 966 | temp64.val32.upper = c->SG[0].Addr.upper; |
| 967 | pci_unmap_single(host->pdev, (dma_addr_t) temp64.val, |
| 968 | iocommand.buf_size, |
| 969 | PCI_DMA_BIDIRECTIONAL); |
| 970 | |
| 971 | /* Copy the error information out */ |
| 972 | iocommand.error_info = *(c->err_info); |
| 973 | if (copy_to_user |
| 974 | (argp, &iocommand, sizeof(IOCTL_Command_struct))) { |
| 975 | kfree(buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | cmd_free(host, c, 0); |
| 977 | return -EFAULT; |
| 978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 980 | if (iocommand.Request.Type.Direction == XFER_READ) { |
| 981 | /* Copy the data out of the buffer we created */ |
| 982 | if (copy_to_user |
| 983 | (iocommand.buf, buff, iocommand.buf_size)) { |
| 984 | kfree(buff); |
| 985 | cmd_free(host, c, 0); |
| 986 | return -EFAULT; |
| 987 | } |
| 988 | } |
| 989 | kfree(buff); |
| 990 | cmd_free(host, c, 0); |
| 991 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 993 | case CCISS_BIG_PASSTHRU:{ |
| 994 | BIG_IOCTL_Command_struct *ioc; |
| 995 | CommandList_struct *c; |
| 996 | unsigned char **buff = NULL; |
| 997 | int *buff_size = NULL; |
| 998 | u64bit temp64; |
| 999 | unsigned long flags; |
| 1000 | BYTE sg_used = 0; |
| 1001 | int status = 0; |
| 1002 | int i; |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 1003 | DECLARE_COMPLETION_ONSTACK(wait); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1004 | __u32 left; |
| 1005 | __u32 sz; |
| 1006 | BYTE __user *data_ptr; |
| 1007 | |
| 1008 | if (!arg) |
| 1009 | return -EINVAL; |
| 1010 | if (!capable(CAP_SYS_RAWIO)) |
| 1011 | return -EPERM; |
| 1012 | ioc = (BIG_IOCTL_Command_struct *) |
| 1013 | kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 1014 | if (!ioc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | status = -ENOMEM; |
| 1016 | goto cleanup1; |
| 1017 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1018 | if (copy_from_user(ioc, argp, sizeof(*ioc))) { |
| 1019 | status = -EFAULT; |
| 1020 | goto cleanup1; |
| 1021 | } |
| 1022 | if ((ioc->buf_size < 1) && |
| 1023 | (ioc->Request.Type.Direction != XFER_NONE)) { |
| 1024 | status = -EINVAL; |
| 1025 | goto cleanup1; |
| 1026 | } |
| 1027 | /* Check kmalloc limits using all SGs */ |
| 1028 | if (ioc->malloc_size > MAX_KMALLOC_SIZE) { |
| 1029 | status = -EINVAL; |
| 1030 | goto cleanup1; |
| 1031 | } |
| 1032 | if (ioc->buf_size > ioc->malloc_size * MAXSGENTRIES) { |
| 1033 | status = -EINVAL; |
| 1034 | goto cleanup1; |
| 1035 | } |
| 1036 | buff = |
| 1037 | kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL); |
| 1038 | if (!buff) { |
| 1039 | status = -ENOMEM; |
| 1040 | goto cleanup1; |
| 1041 | } |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 1042 | buff_size = kmalloc(MAXSGENTRIES * sizeof(int), |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1043 | GFP_KERNEL); |
| 1044 | if (!buff_size) { |
| 1045 | status = -ENOMEM; |
| 1046 | goto cleanup1; |
| 1047 | } |
| 1048 | left = ioc->buf_size; |
| 1049 | data_ptr = ioc->buf; |
| 1050 | while (left) { |
| 1051 | sz = (left > |
| 1052 | ioc->malloc_size) ? ioc-> |
| 1053 | malloc_size : left; |
| 1054 | buff_size[sg_used] = sz; |
| 1055 | buff[sg_used] = kmalloc(sz, GFP_KERNEL); |
| 1056 | if (buff[sg_used] == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | status = -ENOMEM; |
Jens Axboe | 15534d3 | 2005-11-18 22:02:44 +0100 | [diff] [blame] | 1058 | goto cleanup1; |
| 1059 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1060 | if (ioc->Request.Type.Direction == XFER_WRITE) { |
| 1061 | if (copy_from_user |
| 1062 | (buff[sg_used], data_ptr, sz)) { |
| 1063 | status = -ENOMEM; |
| 1064 | goto cleanup1; |
| 1065 | } |
| 1066 | } else { |
| 1067 | memset(buff[sg_used], 0, sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1069 | left -= sz; |
| 1070 | data_ptr += sz; |
| 1071 | sg_used++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1073 | if ((c = cmd_alloc(host, 0)) == NULL) { |
| 1074 | status = -ENOMEM; |
| 1075 | goto cleanup1; |
| 1076 | } |
| 1077 | c->cmd_type = CMD_IOCTL_PEND; |
| 1078 | c->Header.ReplyQueue = 0; |
| 1079 | |
| 1080 | if (ioc->buf_size > 0) { |
| 1081 | c->Header.SGList = sg_used; |
| 1082 | c->Header.SGTotal = sg_used; |
| 1083 | } else { |
| 1084 | c->Header.SGList = 0; |
| 1085 | c->Header.SGTotal = 0; |
| 1086 | } |
| 1087 | c->Header.LUN = ioc->LUN_info; |
| 1088 | c->Header.Tag.lower = c->busaddr; |
| 1089 | |
| 1090 | c->Request = ioc->Request; |
| 1091 | if (ioc->buf_size > 0) { |
| 1092 | int i; |
| 1093 | for (i = 0; i < sg_used; i++) { |
| 1094 | temp64.val = |
| 1095 | pci_map_single(host->pdev, buff[i], |
| 1096 | buff_size[i], |
| 1097 | PCI_DMA_BIDIRECTIONAL); |
| 1098 | c->SG[i].Addr.lower = |
| 1099 | temp64.val32.lower; |
| 1100 | c->SG[i].Addr.upper = |
| 1101 | temp64.val32.upper; |
| 1102 | c->SG[i].Len = buff_size[i]; |
| 1103 | c->SG[i].Ext = 0; /* we are not chaining */ |
| 1104 | } |
| 1105 | } |
| 1106 | c->waiting = &wait; |
| 1107 | /* Put the request on the tail of the request queue */ |
| 1108 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
| 1109 | addQ(&host->reqQ, c); |
| 1110 | host->Qdepth++; |
| 1111 | start_io(host); |
| 1112 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
| 1113 | wait_for_completion(&wait); |
| 1114 | /* unlock the buffers from DMA */ |
| 1115 | for (i = 0; i < sg_used; i++) { |
| 1116 | temp64.val32.lower = c->SG[i].Addr.lower; |
| 1117 | temp64.val32.upper = c->SG[i].Addr.upper; |
| 1118 | pci_unmap_single(host->pdev, |
| 1119 | (dma_addr_t) temp64.val, buff_size[i], |
| 1120 | PCI_DMA_BIDIRECTIONAL); |
| 1121 | } |
| 1122 | /* Copy the error information out */ |
| 1123 | ioc->error_info = *(c->err_info); |
| 1124 | if (copy_to_user(argp, ioc, sizeof(*ioc))) { |
| 1125 | cmd_free(host, c, 0); |
| 1126 | status = -EFAULT; |
| 1127 | goto cleanup1; |
| 1128 | } |
| 1129 | if (ioc->Request.Type.Direction == XFER_READ) { |
| 1130 | /* Copy the data out of the buffer we created */ |
| 1131 | BYTE __user *ptr = ioc->buf; |
| 1132 | for (i = 0; i < sg_used; i++) { |
| 1133 | if (copy_to_user |
| 1134 | (ptr, buff[i], buff_size[i])) { |
| 1135 | cmd_free(host, c, 0); |
| 1136 | status = -EFAULT; |
| 1137 | goto cleanup1; |
| 1138 | } |
| 1139 | ptr += buff_size[i]; |
| 1140 | } |
| 1141 | } |
| 1142 | cmd_free(host, c, 0); |
| 1143 | status = 0; |
| 1144 | cleanup1: |
| 1145 | if (buff) { |
| 1146 | for (i = 0; i < sg_used; i++) |
| 1147 | kfree(buff[i]); |
| 1148 | kfree(buff); |
| 1149 | } |
| 1150 | kfree(buff_size); |
| 1151 | kfree(ioc); |
| 1152 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | default: |
| 1155 | return -ENOTTY; |
| 1156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1159 | static inline void complete_buffers(struct bio *bio, int status) |
| 1160 | { |
| 1161 | while (bio) { |
| 1162 | struct bio *xbh = bio->bi_next; |
| 1163 | int nr_sectors = bio_sectors(bio); |
| 1164 | |
| 1165 | bio->bi_next = NULL; |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1166 | bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO); |
| 1167 | bio = xbh; |
| 1168 | } |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Jens Axboe | 7b30f09 | 2006-07-25 15:02:48 +0200 | [diff] [blame] | 1171 | static void cciss_check_queues(ctlr_info_t *h) |
| 1172 | { |
| 1173 | int start_queue = h->next_to_run; |
| 1174 | int i; |
| 1175 | |
| 1176 | /* check to see if we have maxed out the number of commands that can |
| 1177 | * be placed on the queue. If so then exit. We do this check here |
| 1178 | * in case the interrupt we serviced was from an ioctl and did not |
| 1179 | * free any new commands. |
| 1180 | */ |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 1181 | if ((find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds)) == h->nr_cmds) |
Jens Axboe | 7b30f09 | 2006-07-25 15:02:48 +0200 | [diff] [blame] | 1182 | return; |
| 1183 | |
| 1184 | /* We have room on the queue for more commands. Now we need to queue |
| 1185 | * them up. We will also keep track of the next queue to run so |
| 1186 | * that every queue gets a chance to be started first. |
| 1187 | */ |
| 1188 | for (i = 0; i < h->highest_lun + 1; i++) { |
| 1189 | int curr_queue = (start_queue + i) % (h->highest_lun + 1); |
| 1190 | /* make sure the disk has been added and the drive is real |
| 1191 | * because this can be called from the middle of init_one. |
| 1192 | */ |
| 1193 | if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads)) |
| 1194 | continue; |
| 1195 | blk_start_queue(h->gendisk[curr_queue]->queue); |
| 1196 | |
| 1197 | /* check to see if we have maxed out the number of commands |
| 1198 | * that can be placed on the queue. |
| 1199 | */ |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 1200 | if ((find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds)) == h->nr_cmds) { |
Jens Axboe | 7b30f09 | 2006-07-25 15:02:48 +0200 | [diff] [blame] | 1201 | if (curr_queue == start_queue) { |
| 1202 | h->next_to_run = |
| 1203 | (start_queue + 1) % (h->highest_lun + 1); |
| 1204 | break; |
| 1205 | } else { |
| 1206 | h->next_to_run = curr_queue; |
| 1207 | break; |
| 1208 | } |
| 1209 | } else { |
| 1210 | curr_queue = (curr_queue + 1) % (h->highest_lun + 1); |
| 1211 | } |
| 1212 | } |
| 1213 | } |
| 1214 | |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1215 | static void cciss_softirq_done(struct request *rq) |
| 1216 | { |
| 1217 | CommandList_struct *cmd = rq->completion_data; |
| 1218 | ctlr_info_t *h = hba[cmd->ctlr]; |
| 1219 | unsigned long flags; |
| 1220 | u64bit temp64; |
| 1221 | int i, ddir; |
| 1222 | |
| 1223 | if (cmd->Request.Type.Direction == XFER_READ) |
| 1224 | ddir = PCI_DMA_FROMDEVICE; |
| 1225 | else |
| 1226 | ddir = PCI_DMA_TODEVICE; |
| 1227 | |
| 1228 | /* command did not need to be retried */ |
| 1229 | /* unmap the DMA mapping for all the scatter gather elements */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1230 | for (i = 0; i < cmd->Header.SGList; i++) { |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1231 | temp64.val32.lower = cmd->SG[i].Addr.lower; |
| 1232 | temp64.val32.upper = cmd->SG[i].Addr.upper; |
| 1233 | pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir); |
| 1234 | } |
| 1235 | |
| 1236 | complete_buffers(rq->bio, rq->errors); |
| 1237 | |
Jens Axboe | b369c2c | 2006-11-14 12:36:03 +0100 | [diff] [blame] | 1238 | if (blk_fs_request(rq)) { |
| 1239 | const int rw = rq_data_dir(rq); |
| 1240 | |
| 1241 | disk_stat_add(rq->rq_disk, sectors[rw], rq->nr_sectors); |
| 1242 | } |
| 1243 | |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1244 | #ifdef CCISS_DEBUG |
| 1245 | printk("Done with %p\n", rq); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1246 | #endif /* CCISS_DEBUG */ |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1247 | |
Matt Mackall | 8bd0b97 | 2006-06-25 05:47:11 -0700 | [diff] [blame] | 1248 | add_disk_randomness(rq->rq_disk); |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1249 | spin_lock_irqsave(&h->lock, flags); |
| 1250 | end_that_request_last(rq, rq->errors); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1251 | cmd_free(h, cmd, 1); |
Jens Axboe | 7b30f09 | 2006-07-25 15:02:48 +0200 | [diff] [blame] | 1252 | cciss_check_queues(h); |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1253 | spin_unlock_irqrestore(&h->lock, flags); |
| 1254 | } |
| 1255 | |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1256 | /* This function will check the usage_count of the drive to be updated/added. |
| 1257 | * If the usage_count is zero then the drive information will be updated and |
| 1258 | * the disk will be re-registered with the kernel. If not then it will be |
| 1259 | * left alone for the next reboot. The exception to this is disk 0 which |
| 1260 | * will always be left registered with the kernel since it is also the |
| 1261 | * controller node. Any changes to disk 0 will show up on the next |
| 1262 | * reboot. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1263 | */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1264 | static void cciss_update_drive_info(int ctlr, int drv_index) |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1265 | { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1266 | ctlr_info_t *h = hba[ctlr]; |
| 1267 | struct gendisk *disk; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1268 | InquiryData_struct *inq_buff = NULL; |
| 1269 | unsigned int block_size; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1270 | sector_t total_size; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1271 | unsigned long flags = 0; |
| 1272 | int ret = 0; |
| 1273 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1274 | /* if the disk already exists then deregister it before proceeding */ |
| 1275 | if (h->drv[drv_index].raid_level != -1) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1276 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); |
| 1277 | h->drv[drv_index].busy_configuring = 1; |
| 1278 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
| 1279 | ret = deregister_disk(h->gendisk[drv_index], |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1280 | &h->drv[drv_index], 0); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1281 | h->drv[drv_index].busy_configuring = 0; |
| 1282 | } |
| 1283 | |
| 1284 | /* If the disk is in use return */ |
| 1285 | if (ret) |
| 1286 | return; |
| 1287 | |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 1288 | /* Get information about the disk and modify the driver structure */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1289 | inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1290 | if (inq_buff == NULL) |
| 1291 | goto mem_msg; |
| 1292 | |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1293 | cciss_read_capacity(ctlr, drv_index, 1, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1294 | &total_size, &block_size); |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1295 | |
| 1296 | /* total size = last LBA + 1 */ |
| 1297 | /* FFFFFFFF + 1 = 0, cannot have a logical volume of size 0 */ |
| 1298 | /* so we assume this volume this must be >2TB in size */ |
| 1299 | if (total_size == (__u32) 0) { |
| 1300 | cciss_read_capacity_16(ctlr, drv_index, 1, |
| 1301 | &total_size, &block_size); |
| 1302 | h->cciss_read = CCISS_READ_16; |
| 1303 | h->cciss_write = CCISS_WRITE_16; |
| 1304 | } else { |
| 1305 | h->cciss_read = CCISS_READ_10; |
| 1306 | h->cciss_write = CCISS_WRITE_10; |
| 1307 | } |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1308 | cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1309 | inq_buff, &h->drv[drv_index]); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1310 | |
| 1311 | ++h->num_luns; |
| 1312 | disk = h->gendisk[drv_index]; |
| 1313 | set_capacity(disk, h->drv[drv_index].nr_blocks); |
| 1314 | |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1315 | /* if it's the controller it's already added */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1316 | if (drv_index) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1317 | disk->queue = blk_init_queue(do_cciss_request, &h->lock); |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1318 | sprintf(disk->disk_name, "cciss/c%dd%d", ctlr, drv_index); |
| 1319 | disk->major = h->major; |
| 1320 | disk->first_minor = drv_index << NWD_SHIFT; |
| 1321 | disk->fops = &cciss_fops; |
| 1322 | disk->private_data = &h->drv[drv_index]; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1323 | |
| 1324 | /* Set up queue information */ |
| 1325 | disk->queue->backing_dev_info.ra_pages = READ_AHEAD; |
| 1326 | blk_queue_bounce_limit(disk->queue, hba[ctlr]->pdev->dma_mask); |
| 1327 | |
| 1328 | /* This is a hardware imposed limit. */ |
| 1329 | blk_queue_max_hw_segments(disk->queue, MAXSGENTRIES); |
| 1330 | |
| 1331 | /* This is a limit in the driver and could be eliminated. */ |
| 1332 | blk_queue_max_phys_segments(disk->queue, MAXSGENTRIES); |
| 1333 | |
Mike Miller | 92c4231a | 2006-12-06 20:35:06 -0800 | [diff] [blame] | 1334 | blk_queue_max_sectors(disk->queue, h->cciss_max_sectors); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1335 | |
Mike Miller | ca1e048 | 2006-04-10 15:38:07 -0700 | [diff] [blame] | 1336 | blk_queue_softirq_done(disk->queue, cciss_softirq_done); |
| 1337 | |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1338 | disk->queue->queuedata = hba[ctlr]; |
| 1339 | |
| 1340 | blk_queue_hardsect_size(disk->queue, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1341 | hba[ctlr]->drv[drv_index].block_size); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1342 | |
| 1343 | h->drv[drv_index].queue = disk->queue; |
| 1344 | add_disk(disk); |
| 1345 | } |
| 1346 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1347 | freeret: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1348 | kfree(inq_buff); |
| 1349 | return; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1350 | mem_msg: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1351 | printk(KERN_ERR "cciss: out of memory\n"); |
| 1352 | goto freeret; |
| 1353 | } |
| 1354 | |
| 1355 | /* This function will find the first index of the controllers drive array |
| 1356 | * that has a -1 for the raid_level and will return that index. This is |
| 1357 | * where new drives will be added. If the index to be returned is greater |
| 1358 | * than the highest_lun index for the controller then highest_lun is set |
| 1359 | * to this new index. If there are no available indexes then -1 is returned. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1360 | */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1361 | static int cciss_find_free_drive_index(int ctlr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1363 | int i; |
| 1364 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1365 | for (i = 0; i < CISS_MAX_LUN; i++) { |
| 1366 | if (hba[ctlr]->drv[i].raid_level == -1) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1367 | if (i > hba[ctlr]->highest_lun) |
| 1368 | hba[ctlr]->highest_lun = i; |
| 1369 | return i; |
| 1370 | } |
| 1371 | } |
| 1372 | return -1; |
| 1373 | } |
| 1374 | |
| 1375 | /* This function will add and remove logical drives from the Logical |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 1376 | * drive array of the controller and maintain persistency of ordering |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1377 | * so that mount points are preserved until the next reboot. This allows |
| 1378 | * for the removal of logical drives in the middle of the drive array |
| 1379 | * without a re-ordering of those drives. |
| 1380 | * INPUT |
| 1381 | * h = The controller to perform the operations on |
| 1382 | * del_disk = The disk to remove if specified. If the value given |
| 1383 | * is NULL then no disk is removed. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1384 | */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1385 | static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk) |
| 1386 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | int ctlr = h->ctlr; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1388 | int num_luns; |
| 1389 | ReportLunData_struct *ld_buff = NULL; |
| 1390 | drive_info_struct *drv = NULL; |
| 1391 | int return_code; |
| 1392 | int listlength = 0; |
| 1393 | int i; |
| 1394 | int drv_found; |
| 1395 | int drv_index = 0; |
| 1396 | __u32 lunid = 0; |
| 1397 | unsigned long flags; |
| 1398 | |
| 1399 | /* Set busy_configuring flag for this operation */ |
| 1400 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1401 | if (h->busy_configuring) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1402 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
| 1403 | return -EBUSY; |
| 1404 | } |
| 1405 | h->busy_configuring = 1; |
| 1406 | |
| 1407 | /* if del_disk is NULL then we are being called to add a new disk |
| 1408 | * and update the logical drive table. If it is not NULL then |
| 1409 | * we will check if the disk is in use or not. |
| 1410 | */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1411 | if (del_disk != NULL) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1412 | drv = get_drv(del_disk); |
| 1413 | drv->busy_configuring = 1; |
| 1414 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
| 1415 | return_code = deregister_disk(del_disk, drv, 1); |
| 1416 | drv->busy_configuring = 0; |
| 1417 | h->busy_configuring = 0; |
| 1418 | return return_code; |
| 1419 | } else { |
| 1420 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
| 1421 | if (!capable(CAP_SYS_RAWIO)) |
| 1422 | return -EPERM; |
| 1423 | |
| 1424 | ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); |
| 1425 | if (ld_buff == NULL) |
| 1426 | goto mem_msg; |
| 1427 | |
| 1428 | return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1429 | sizeof(ReportLunData_struct), 0, |
| 1430 | 0, 0, TYPE_CMD); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1431 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1432 | if (return_code == IO_OK) { |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1433 | listlength = |
| 1434 | be32_to_cpu(*(__u32 *) ld_buff->LUNListLength); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1435 | } else { /* reading number of logical volumes failed */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1436 | printk(KERN_WARNING "cciss: report logical volume" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1437 | " command failed\n"); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1438 | listlength = 0; |
| 1439 | goto freeret; |
| 1440 | } |
| 1441 | |
| 1442 | num_luns = listlength / 8; /* 8 bytes per entry */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1443 | if (num_luns > CISS_MAX_LUN) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1444 | num_luns = CISS_MAX_LUN; |
| 1445 | printk(KERN_WARNING "cciss: more luns configured" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1446 | " on controller than can be handled by" |
| 1447 | " this driver.\n"); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /* Compare controller drive array to drivers drive array. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1451 | * Check for updates in the drive information and any new drives |
| 1452 | * on the controller. |
| 1453 | */ |
| 1454 | for (i = 0; i < num_luns; i++) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1455 | int j; |
| 1456 | |
| 1457 | drv_found = 0; |
| 1458 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1459 | lunid = (0xff & |
| 1460 | (unsigned int)(ld_buff->LUN[i][3])) << 24; |
| 1461 | lunid |= (0xff & |
| 1462 | (unsigned int)(ld_buff->LUN[i][2])) << 16; |
| 1463 | lunid |= (0xff & |
| 1464 | (unsigned int)(ld_buff->LUN[i][1])) << 8; |
| 1465 | lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1466 | |
| 1467 | /* Find if the LUN is already in the drive array |
| 1468 | * of the controller. If so then update its info |
| 1469 | * if not is use. If it does not exist then find |
| 1470 | * the first free index and add it. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1471 | */ |
| 1472 | for (j = 0; j <= h->highest_lun; j++) { |
| 1473 | if (h->drv[j].LunID == lunid) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1474 | drv_index = j; |
| 1475 | drv_found = 1; |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | /* check if the drive was found already in the array */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1480 | if (!drv_found) { |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1481 | drv_index = cciss_find_free_drive_index(ctlr); |
| 1482 | if (drv_index == -1) |
| 1483 | goto freeret; |
| 1484 | |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1485 | /*Check if the gendisk needs to be allocated */ |
| 1486 | if (!h->gendisk[drv_index]){ |
| 1487 | h->gendisk[drv_index] = alloc_disk(1 << NWD_SHIFT); |
| 1488 | if (!h->gendisk[drv_index]){ |
| 1489 | printk(KERN_ERR "cciss: could not allocate new disk %d\n", drv_index); |
| 1490 | goto mem_msg; |
| 1491 | } |
| 1492 | } |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1493 | } |
| 1494 | h->drv[drv_index].LunID = lunid; |
| 1495 | cciss_update_drive_info(ctlr, drv_index); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1496 | } /* end for */ |
| 1497 | } /* end else */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1498 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1499 | freeret: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1500 | kfree(ld_buff); |
| 1501 | h->busy_configuring = 0; |
| 1502 | /* We return -1 here to tell the ACU that we have registered/updated |
| 1503 | * all of the drives that we can and to keep it from calling us |
| 1504 | * additional times. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1505 | */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1506 | return -1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1507 | mem_msg: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1508 | printk(KERN_ERR "cciss: out of memory\n"); |
| 1509 | goto freeret; |
| 1510 | } |
| 1511 | |
| 1512 | /* This function will deregister the disk and it's queue from the |
| 1513 | * kernel. It must be called with the controller lock held and the |
| 1514 | * drv structures busy_configuring flag set. It's parameters are: |
| 1515 | * |
| 1516 | * disk = This is the disk to be deregistered |
| 1517 | * drv = This is the drive_info_struct associated with the disk to be |
| 1518 | * deregistered. It contains information about the disk used |
| 1519 | * by the driver. |
| 1520 | * clear_all = This flag determines whether or not the disk information |
| 1521 | * is going to be completely cleared out and the highest_lun |
| 1522 | * reset. Sometimes we want to clear out information about |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 1523 | * the disk in preparation for re-adding it. In this case |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1524 | * the highest_lun should be left unchanged and the LunID |
| 1525 | * should not be cleared. |
| 1526 | */ |
| 1527 | static int deregister_disk(struct gendisk *disk, drive_info_struct *drv, |
| 1528 | int clear_all) |
| 1529 | { |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1530 | int i; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1531 | ctlr_info_t *h = get_host(disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
| 1533 | if (!capable(CAP_SYS_RAWIO)) |
| 1534 | return -EPERM; |
| 1535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | /* make sure logical volume is NOT is use */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1537 | if (clear_all || (h->gendisk[0] == disk)) { |
| 1538 | if (drv->usage_count > 1) |
| 1539 | return -EBUSY; |
| 1540 | } else if (drv->usage_count > 0) |
| 1541 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1543 | /* invalidate the devices and deregister the disk. If it is disk |
| 1544 | * zero do not deregister it but just zero out it's values. This |
| 1545 | * allows us to delete disk zero but keep the controller registered. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1546 | */ |
| 1547 | if (h->gendisk[0] != disk) { |
mikem | 6f5a0f7 | 2005-11-18 22:05:36 +0100 | [diff] [blame] | 1548 | if (disk) { |
| 1549 | request_queue_t *q = disk->queue; |
| 1550 | if (disk->flags & GENHD_FL_UP) |
| 1551 | del_gendisk(disk); |
Mike Miller | 2f6331f | 2005-12-12 22:17:14 -0800 | [diff] [blame] | 1552 | if (q) { |
mikem | 6f5a0f7 | 2005-11-18 22:05:36 +0100 | [diff] [blame] | 1553 | blk_cleanup_queue(q); |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1554 | /* Set drv->queue to NULL so that we do not try |
| 1555 | * to call blk_start_queue on this queue in the |
| 1556 | * interrupt handler |
| 1557 | */ |
Mike Miller | 2f6331f | 2005-12-12 22:17:14 -0800 | [diff] [blame] | 1558 | drv->queue = NULL; |
| 1559 | } |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1560 | /* If clear_all is set then we are deleting the logical |
| 1561 | * drive, not just refreshing its info. For drives |
| 1562 | * other than disk 0 we will call put_disk. We do not |
| 1563 | * do this for disk 0 as we need it to be able to |
| 1564 | * configure the controller. |
| 1565 | */ |
| 1566 | if (clear_all){ |
| 1567 | /* This isn't pretty, but we need to find the |
| 1568 | * disk in our array and NULL our the pointer. |
| 1569 | * This is so that we will call alloc_disk if |
| 1570 | * this index is used again later. |
| 1571 | */ |
| 1572 | for (i=0; i < CISS_MAX_LUN; i++){ |
| 1573 | if(h->gendisk[i] == disk){ |
| 1574 | h->gendisk[i] = NULL; |
| 1575 | break; |
| 1576 | } |
| 1577 | } |
| 1578 | put_disk(disk); |
| 1579 | } |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1580 | } |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 1581 | } else { |
| 1582 | set_capacity(disk, 0); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | --h->num_luns; |
| 1586 | /* zero out the disk size info */ |
| 1587 | drv->nr_blocks = 0; |
| 1588 | drv->block_size = 0; |
| 1589 | drv->heads = 0; |
| 1590 | drv->sectors = 0; |
| 1591 | drv->cylinders = 0; |
| 1592 | drv->raid_level = -1; /* This can be used as a flag variable to |
| 1593 | * indicate that this element of the drive |
| 1594 | * array is free. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1595 | */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1596 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1597 | if (clear_all) { |
| 1598 | /* check to see if it was the last disk */ |
| 1599 | if (drv == h->drv + h->highest_lun) { |
| 1600 | /* if so, find the new hightest lun */ |
| 1601 | int i, newhighest = -1; |
| 1602 | for (i = 0; i < h->highest_lun; i++) { |
| 1603 | /* if the disk has size > 0, it is available */ |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1604 | if (h->drv[i].heads) |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1605 | newhighest = i; |
| 1606 | } |
| 1607 | h->highest_lun = newhighest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | } |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1609 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1610 | drv->LunID = 0; |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1611 | } |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 1612 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | } |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 1614 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1615 | static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, |
| 1616 | 1: address logical volume log_unit, |
| 1617 | 2: periph device address is scsi3addr */ |
| 1618 | unsigned int log_unit, __u8 page_code, |
| 1619 | unsigned char *scsi3addr, int cmd_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1621 | ctlr_info_t *h = hba[ctlr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | u64bit buff_dma_handle; |
| 1623 | int status = IO_OK; |
| 1624 | |
| 1625 | c->cmd_type = CMD_IOCTL_PEND; |
| 1626 | c->Header.ReplyQueue = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1627 | if (buff != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | c->Header.SGList = 1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1629 | c->Header.SGTotal = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | } else { |
| 1631 | c->Header.SGList = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1632 | c->Header.SGTotal = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | } |
| 1634 | c->Header.Tag.lower = c->busaddr; |
| 1635 | |
| 1636 | c->Request.Type.Type = cmd_type; |
| 1637 | if (cmd_type == TYPE_CMD) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1638 | switch (cmd) { |
| 1639 | case CISS_INQUIRY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | /* If the logical unit number is 0 then, this is going |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1641 | to controller so It's a physical command |
| 1642 | mode = 0 target = 0. So we have nothing to write. |
| 1643 | otherwise, if use_unit_num == 1, |
| 1644 | mode = 1(volume set addressing) target = LUNID |
| 1645 | otherwise, if use_unit_num == 2, |
| 1646 | mode = 0(periph dev addr) target = scsi3addr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | if (use_unit_num == 1) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1648 | c->Header.LUN.LogDev.VolId = |
| 1649 | h->drv[log_unit].LunID; |
| 1650 | c->Header.LUN.LogDev.Mode = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | } else if (use_unit_num == 2) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1652 | memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, |
| 1653 | 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | c->Header.LUN.LogDev.Mode = 0; |
| 1655 | } |
| 1656 | /* are we trying to read a vital product page */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1657 | if (page_code != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | c->Request.CDB[1] = 0x01; |
| 1659 | c->Request.CDB[2] = page_code; |
| 1660 | } |
| 1661 | c->Request.CDBLen = 6; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1662 | c->Request.Type.Attribute = ATTR_SIMPLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | c->Request.Type.Direction = XFER_READ; |
| 1664 | c->Request.Timeout = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1665 | c->Request.CDB[0] = CISS_INQUIRY; |
| 1666 | c->Request.CDB[4] = size & 0xFF; |
| 1667 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | case CISS_REPORT_LOG: |
| 1669 | case CISS_REPORT_PHYS: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1670 | /* Talking to controller so It's a physical command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | mode = 00 target = 0. Nothing to write. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1672 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | c->Request.CDBLen = 12; |
| 1674 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1675 | c->Request.Type.Direction = XFER_READ; |
| 1676 | c->Request.Timeout = 0; |
| 1677 | c->Request.CDB[0] = cmd; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1678 | c->Request.CDB[6] = (size >> 24) & 0xFF; //MSB |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 1680 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 1681 | c->Request.CDB[9] = size & 0xFF; |
| 1682 | break; |
| 1683 | |
| 1684 | case CCISS_READ_CAPACITY: |
| 1685 | c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID; |
| 1686 | c->Header.LUN.LogDev.Mode = 1; |
| 1687 | c->Request.CDBLen = 10; |
| 1688 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1689 | c->Request.Type.Direction = XFER_READ; |
| 1690 | c->Request.Timeout = 0; |
| 1691 | c->Request.CDB[0] = cmd; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1692 | break; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1693 | case CCISS_READ_CAPACITY_16: |
| 1694 | c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID; |
| 1695 | c->Header.LUN.LogDev.Mode = 1; |
| 1696 | c->Request.CDBLen = 16; |
| 1697 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1698 | c->Request.Type.Direction = XFER_READ; |
| 1699 | c->Request.Timeout = 0; |
| 1700 | c->Request.CDB[0] = cmd; |
| 1701 | c->Request.CDB[1] = 0x10; |
| 1702 | c->Request.CDB[10] = (size >> 24) & 0xFF; |
| 1703 | c->Request.CDB[11] = (size >> 16) & 0xFF; |
| 1704 | c->Request.CDB[12] = (size >> 8) & 0xFF; |
| 1705 | c->Request.CDB[13] = size & 0xFF; |
| 1706 | c->Request.Timeout = 0; |
| 1707 | c->Request.CDB[0] = cmd; |
| 1708 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | case CCISS_CACHE_FLUSH: |
| 1710 | c->Request.CDBLen = 12; |
| 1711 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1712 | c->Request.Type.Direction = XFER_WRITE; |
| 1713 | c->Request.Timeout = 0; |
| 1714 | c->Request.CDB[0] = BMIC_WRITE; |
| 1715 | c->Request.CDB[6] = BMIC_CACHE_FLUSH; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1716 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | default: |
| 1718 | printk(KERN_WARNING |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1719 | "cciss%d: Unknown Command 0x%c\n", ctlr, cmd); |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 1720 | return IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | } |
| 1722 | } else if (cmd_type == TYPE_MSG) { |
| 1723 | switch (cmd) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1724 | case 0: /* ABORT message */ |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 1725 | c->Request.CDBLen = 12; |
| 1726 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1727 | c->Request.Type.Direction = XFER_WRITE; |
| 1728 | c->Request.Timeout = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1729 | c->Request.CDB[0] = cmd; /* abort */ |
| 1730 | c->Request.CDB[1] = 0; /* abort a command */ |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 1731 | /* buff contains the tag of the command to abort */ |
| 1732 | memcpy(&c->Request.CDB[4], buff, 8); |
| 1733 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1734 | case 1: /* RESET message */ |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 1735 | c->Request.CDBLen = 12; |
| 1736 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1737 | c->Request.Type.Direction = XFER_WRITE; |
| 1738 | c->Request.Timeout = 0; |
| 1739 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1740 | c->Request.CDB[0] = cmd; /* reset */ |
| 1741 | c->Request.CDB[1] = 0x04; /* reset a LUN */ |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1742 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | case 3: /* No-Op message */ |
| 1744 | c->Request.CDBLen = 1; |
| 1745 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 1746 | c->Request.Type.Direction = XFER_WRITE; |
| 1747 | c->Request.Timeout = 0; |
| 1748 | c->Request.CDB[0] = cmd; |
| 1749 | break; |
| 1750 | default: |
| 1751 | printk(KERN_WARNING |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1752 | "cciss%d: unknown message type %d\n", ctlr, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | return IO_ERROR; |
| 1754 | } |
| 1755 | } else { |
| 1756 | printk(KERN_WARNING |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1757 | "cciss%d: unknown command type %d\n", ctlr, cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | return IO_ERROR; |
| 1759 | } |
| 1760 | /* Fill in the scatter gather information */ |
| 1761 | if (size > 0) { |
| 1762 | buff_dma_handle.val = (__u64) pci_map_single(h->pdev, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1763 | buff, size, |
| 1764 | PCI_DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | c->SG[0].Addr.lower = buff_dma_handle.val32.lower; |
| 1766 | c->SG[0].Addr.upper = buff_dma_handle.val32.upper; |
| 1767 | c->SG[0].Len = size; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1768 | c->SG[0].Ext = 0; /* we are not chaining */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | } |
| 1770 | return status; |
| 1771 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1772 | |
| 1773 | static int sendcmd_withirq(__u8 cmd, |
| 1774 | int ctlr, |
| 1775 | void *buff, |
| 1776 | size_t size, |
| 1777 | unsigned int use_unit_num, |
| 1778 | unsigned int log_unit, __u8 page_code, int cmd_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | { |
| 1780 | ctlr_info_t *h = hba[ctlr]; |
| 1781 | CommandList_struct *c; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1782 | u64bit buff_dma_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | unsigned long flags; |
| 1784 | int return_status; |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 1785 | DECLARE_COMPLETION_ONSTACK(wait); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1786 | |
| 1787 | if ((c = cmd_alloc(h, 0)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | return -ENOMEM; |
| 1789 | return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1790 | log_unit, page_code, NULL, cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | if (return_status != IO_OK) { |
| 1792 | cmd_free(h, c, 0); |
| 1793 | return return_status; |
| 1794 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1795 | resend_cmd2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | c->waiting = &wait; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | /* Put the request on the tail of the queue and send it */ |
| 1799 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
| 1800 | addQ(&h->reqQ, c); |
| 1801 | h->Qdepth++; |
| 1802 | start_io(h); |
| 1803 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | wait_for_completion(&wait); |
| 1806 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1807 | if (c->err_info->CommandStatus != 0) { /* an error has occurred */ |
| 1808 | switch (c->err_info->CommandStatus) { |
| 1809 | case CMD_TARGET_STATUS: |
| 1810 | printk(KERN_WARNING "cciss: cmd %p has " |
| 1811 | " completed with errors\n", c); |
| 1812 | if (c->err_info->ScsiStatus) { |
| 1813 | printk(KERN_WARNING "cciss: cmd %p " |
| 1814 | "has SCSI Status = %x\n", |
| 1815 | c, c->err_info->ScsiStatus); |
| 1816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | |
| 1818 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1819 | case CMD_DATA_UNDERRUN: |
| 1820 | case CMD_DATA_OVERRUN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | /* expected for inquire and report lun commands */ |
| 1822 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1823 | case CMD_INVALID: |
| 1824 | printk(KERN_WARNING "cciss: Cmd %p is " |
| 1825 | "reported invalid\n", c); |
| 1826 | return_status = IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1828 | case CMD_PROTOCOL_ERR: |
| 1829 | printk(KERN_WARNING "cciss: cmd %p has " |
| 1830 | "protocol error \n", c); |
| 1831 | return_status = IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1833 | case CMD_HARDWARE_ERR: |
| 1834 | printk(KERN_WARNING "cciss: cmd %p had " |
| 1835 | " hardware error\n", c); |
| 1836 | return_status = IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1838 | case CMD_CONNECTION_LOST: |
| 1839 | printk(KERN_WARNING "cciss: cmd %p had " |
| 1840 | "connection lost\n", c); |
| 1841 | return_status = IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1843 | case CMD_ABORTED: |
| 1844 | printk(KERN_WARNING "cciss: cmd %p was " |
| 1845 | "aborted\n", c); |
| 1846 | return_status = IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1848 | case CMD_ABORT_FAILED: |
| 1849 | printk(KERN_WARNING "cciss: cmd %p reports " |
| 1850 | "abort failed\n", c); |
| 1851 | return_status = IO_ERROR; |
| 1852 | break; |
| 1853 | case CMD_UNSOLICITED_ABORT: |
| 1854 | printk(KERN_WARNING |
| 1855 | "cciss%d: unsolicited abort %p\n", ctlr, c); |
| 1856 | if (c->retry_count < MAX_CMD_RETRIES) { |
| 1857 | printk(KERN_WARNING |
| 1858 | "cciss%d: retrying %p\n", ctlr, c); |
| 1859 | c->retry_count++; |
| 1860 | /* erase the old error information */ |
| 1861 | memset(c->err_info, 0, |
| 1862 | sizeof(ErrorInfo_struct)); |
| 1863 | return_status = IO_OK; |
| 1864 | INIT_COMPLETION(wait); |
| 1865 | goto resend_cmd2; |
| 1866 | } |
| 1867 | return_status = IO_ERROR; |
| 1868 | break; |
| 1869 | default: |
| 1870 | printk(KERN_WARNING "cciss: cmd %p returned " |
| 1871 | "unknown status %x\n", c, |
| 1872 | c->err_info->CommandStatus); |
| 1873 | return_status = IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1875 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | /* unlock the buffers from DMA */ |
Mike Miller | bb2a37b | 2005-09-13 01:25:24 -0700 | [diff] [blame] | 1877 | buff_dma_handle.val32.lower = c->SG[0].Addr.lower; |
| 1878 | buff_dma_handle.val32.upper = c->SG[0].Addr.upper; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1879 | pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val, |
| 1880 | c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | cmd_free(h, c, 0); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1882 | return return_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | static void cciss_geometry_inquiry(int ctlr, int logvol, |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1886 | int withirq, sector_t total_size, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1887 | unsigned int block_size, |
| 1888 | InquiryData_struct *inq_buff, |
| 1889 | drive_info_struct *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | { |
| 1891 | int return_code; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1892 | unsigned long t; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | memset(inq_buff, 0, sizeof(InquiryData_struct)); |
| 1895 | if (withirq) |
| 1896 | return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1897 | inq_buff, sizeof(*inq_buff), 1, |
| 1898 | logvol, 0xC1, TYPE_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | else |
| 1900 | return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1901 | sizeof(*inq_buff), 1, logvol, 0xC1, NULL, |
| 1902 | TYPE_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | if (return_code == IO_OK) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1904 | if (inq_buff->data_byte[8] == 0xFF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | printk(KERN_WARNING |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1906 | "cciss: reading geometry failed, volume " |
| 1907 | "does not support reading geometry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | drv->heads = 255; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1909 | drv->sectors = 32; // Sectors per track |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | drv->heads = inq_buff->data_byte[6]; |
| 1912 | drv->sectors = inq_buff->data_byte[7]; |
| 1913 | drv->cylinders = (inq_buff->data_byte[4] & 0xff) << 8; |
| 1914 | drv->cylinders += inq_buff->data_byte[5]; |
| 1915 | drv->raid_level = inq_buff->data_byte[8]; |
Matthew Wilcox | 3f7705e | 2006-10-21 10:24:19 -0700 | [diff] [blame] | 1916 | } |
| 1917 | drv->block_size = block_size; |
| 1918 | drv->nr_blocks = total_size; |
| 1919 | t = drv->heads * drv->sectors; |
| 1920 | if (t > 1) { |
| 1921 | unsigned rem = sector_div(total_size, t); |
| 1922 | if (rem) |
| 1923 | total_size++; |
| 1924 | drv->cylinders = total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1926 | } else { /* Get geometry failed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | printk(KERN_WARNING "cciss: reading geometry failed\n"); |
| 1928 | } |
Metathronius Galabant | cc088d1 | 2006-09-30 23:27:47 -0700 | [diff] [blame] | 1929 | printk(KERN_INFO " heads=%d, sectors=%d, cylinders=%d\n\n", |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1930 | drv->heads, drv->sectors, drv->cylinders); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | static void |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1934 | cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1935 | unsigned int *block_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | { |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1937 | ReadCapdata_struct *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | int return_code; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1939 | buf = kmalloc(sizeof(ReadCapdata_struct), GFP_KERNEL); |
| 1940 | if (buf == NULL) { |
| 1941 | printk(KERN_WARNING "cciss: out of memory\n"); |
| 1942 | return; |
| 1943 | } |
| 1944 | memset(buf, 0, sizeof(ReadCapdata_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | if (withirq) |
| 1946 | return_code = sendcmd_withirq(CCISS_READ_CAPACITY, |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1947 | ctlr, buf, sizeof(ReadCapdata_struct), |
| 1948 | 1, logvol, 0, TYPE_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | else |
| 1950 | return_code = sendcmd(CCISS_READ_CAPACITY, |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1951 | ctlr, buf, sizeof(ReadCapdata_struct), |
| 1952 | 1, logvol, 0, NULL, TYPE_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | if (return_code == IO_OK) { |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1954 | *total_size = be32_to_cpu(*(__u32 *) buf->total_size)+1; |
| 1955 | *block_size = be32_to_cpu(*(__u32 *) buf->block_size); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 1956 | } else { /* read capacity command failed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | printk(KERN_WARNING "cciss: read capacity failed\n"); |
| 1958 | *total_size = 0; |
| 1959 | *block_size = BLOCK_SIZE; |
| 1960 | } |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1961 | if (*total_size != (__u32) 0) |
Randy Dunlap | 7b92aad | 2006-10-28 10:38:40 -0700 | [diff] [blame] | 1962 | printk(KERN_INFO " blocks= %llu block_size= %d\n", |
| 1963 | (unsigned long long)*total_size, *block_size); |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1964 | kfree(buf); |
| 1965 | return; |
| 1966 | } |
| 1967 | |
| 1968 | static void |
| 1969 | cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size, unsigned int *block_size) |
| 1970 | { |
| 1971 | ReadCapdata_struct_16 *buf; |
| 1972 | int return_code; |
| 1973 | buf = kmalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL); |
| 1974 | if (buf == NULL) { |
| 1975 | printk(KERN_WARNING "cciss: out of memory\n"); |
| 1976 | return; |
| 1977 | } |
| 1978 | memset(buf, 0, sizeof(ReadCapdata_struct_16)); |
| 1979 | if (withirq) { |
| 1980 | return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16, |
| 1981 | ctlr, buf, sizeof(ReadCapdata_struct_16), |
| 1982 | 1, logvol, 0, TYPE_CMD); |
| 1983 | } |
| 1984 | else { |
| 1985 | return_code = sendcmd(CCISS_READ_CAPACITY_16, |
| 1986 | ctlr, buf, sizeof(ReadCapdata_struct_16), |
| 1987 | 1, logvol, 0, NULL, TYPE_CMD); |
| 1988 | } |
| 1989 | if (return_code == IO_OK) { |
| 1990 | *total_size = be64_to_cpu(*(__u64 *) buf->total_size)+1; |
| 1991 | *block_size = be32_to_cpu(*(__u32 *) buf->block_size); |
| 1992 | } else { /* read capacity command failed */ |
| 1993 | printk(KERN_WARNING "cciss: read capacity failed\n"); |
| 1994 | *total_size = 0; |
| 1995 | *block_size = BLOCK_SIZE; |
| 1996 | } |
Randy Dunlap | 7b92aad | 2006-10-28 10:38:40 -0700 | [diff] [blame] | 1997 | printk(KERN_INFO " blocks= %llu block_size= %d\n", |
| 1998 | (unsigned long long)*total_size, *block_size); |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 1999 | kfree(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | return; |
| 2001 | } |
| 2002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | static int cciss_revalidate(struct gendisk *disk) |
| 2004 | { |
| 2005 | ctlr_info_t *h = get_host(disk); |
| 2006 | drive_info_struct *drv = get_drv(disk); |
| 2007 | int logvol; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2008 | int FOUND = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | unsigned int block_size; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2010 | sector_t total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | InquiryData_struct *inq_buff = NULL; |
| 2012 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2013 | for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) { |
| 2014 | if (h->drv[logvol].LunID == drv->LunID) { |
| 2015 | FOUND = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | break; |
| 2017 | } |
| 2018 | } |
| 2019 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2020 | if (!FOUND) |
| 2021 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2023 | inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); |
| 2024 | if (inq_buff == NULL) { |
| 2025 | printk(KERN_WARNING "cciss: out of memory\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2026 | return 1; |
| 2027 | } |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2028 | if (h->cciss_read == CCISS_READ_10) { |
| 2029 | cciss_read_capacity(h->ctlr, logvol, 1, |
| 2030 | &total_size, &block_size); |
| 2031 | } else { |
| 2032 | cciss_read_capacity_16(h->ctlr, logvol, 1, |
| 2033 | &total_size, &block_size); |
| 2034 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2035 | cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, |
| 2036 | inq_buff, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 2038 | blk_queue_hardsect_size(drv->queue, drv->block_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | set_capacity(disk, drv->nr_blocks); |
| 2040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | kfree(inq_buff); |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | /* |
| 2046 | * Wait polling for a command to complete. |
| 2047 | * The memory mapped FIFO is polled for the completion. |
| 2048 | * Used only at init time, interrupts from the HBA are disabled. |
| 2049 | */ |
| 2050 | static unsigned long pollcomplete(int ctlr) |
| 2051 | { |
| 2052 | unsigned long done; |
| 2053 | int i; |
| 2054 | |
| 2055 | /* Wait (up to 20 seconds) for a command to complete */ |
| 2056 | |
| 2057 | for (i = 20 * HZ; i > 0; i--) { |
| 2058 | done = hba[ctlr]->access.command_completed(hba[ctlr]); |
Nishanth Aravamudan | 86e8486 | 2005-09-10 00:27:28 -0700 | [diff] [blame] | 2059 | if (done == FIFO_EMPTY) |
| 2060 | schedule_timeout_uninterruptible(1); |
| 2061 | else |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 2062 | return done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | } |
| 2064 | /* Invalid address to tell caller we ran out of time */ |
| 2065 | return 1; |
| 2066 | } |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2067 | |
| 2068 | static int add_sendcmd_reject(__u8 cmd, int ctlr, unsigned long complete) |
| 2069 | { |
| 2070 | /* We get in here if sendcmd() is polling for completions |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2071 | and gets some command back that it wasn't expecting -- |
| 2072 | something other than that which it just sent down. |
| 2073 | Ordinarily, that shouldn't happen, but it can happen when |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2074 | the scsi tape stuff gets into error handling mode, and |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2075 | starts using sendcmd() to try to abort commands and |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2076 | reset tape drives. In that case, sendcmd may pick up |
| 2077 | completions of commands that were sent to logical drives |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2078 | through the block i/o system, or cciss ioctls completing, etc. |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2079 | In that case, we need to save those completions for later |
| 2080 | processing by the interrupt handler. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2081 | */ |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2082 | |
| 2083 | #ifdef CONFIG_CISS_SCSI_TAPE |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2084 | struct sendcmd_reject_list *srl = &hba[ctlr]->scsi_rejects; |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2085 | |
| 2086 | /* If it's not the scsi tape stuff doing error handling, (abort */ |
| 2087 | /* or reset) then we don't expect anything weird. */ |
| 2088 | if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) { |
| 2089 | #endif |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2090 | printk(KERN_WARNING "cciss cciss%d: SendCmd " |
| 2091 | "Invalid command list address returned! (%lx)\n", |
| 2092 | ctlr, complete); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2093 | /* not much we can do. */ |
| 2094 | #ifdef CONFIG_CISS_SCSI_TAPE |
| 2095 | return 1; |
| 2096 | } |
| 2097 | |
| 2098 | /* We've sent down an abort or reset, but something else |
| 2099 | has completed */ |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 2100 | if (srl->ncompletions >= (hba[ctlr]->nr_cmds + 2)) { |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2101 | /* Uh oh. No room to save it for later... */ |
| 2102 | printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, " |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2103 | "reject list overflow, command lost!\n", ctlr); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2104 | return 1; |
| 2105 | } |
| 2106 | /* Save it for later */ |
| 2107 | srl->complete[srl->ncompletions] = complete; |
| 2108 | srl->ncompletions++; |
| 2109 | #endif |
| 2110 | return 0; |
| 2111 | } |
| 2112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | /* |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2114 | * Send a command to the controller, and wait for it to complete. |
| 2115 | * Only used at init time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2117 | static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, |
| 2118 | 1: address logical volume log_unit, |
| 2119 | 2: periph device address is scsi3addr */ |
| 2120 | unsigned int log_unit, |
| 2121 | __u8 page_code, unsigned char *scsi3addr, int cmd_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | { |
| 2123 | CommandList_struct *c; |
| 2124 | int i; |
| 2125 | unsigned long complete; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2126 | ctlr_info_t *info_p = hba[ctlr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | u64bit buff_dma_handle; |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2128 | int status, done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
| 2130 | if ((c = cmd_alloc(info_p, 1)) == NULL) { |
| 2131 | printk(KERN_WARNING "cciss: unable to get memory"); |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 2132 | return IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | } |
| 2134 | status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2135 | log_unit, page_code, scsi3addr, cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | if (status != IO_OK) { |
| 2137 | cmd_free(info_p, c, 1); |
| 2138 | return status; |
| 2139 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2140 | resend_cmd1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | /* |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2142 | * Disable interrupt |
| 2143 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | #ifdef CCISS_DEBUG |
| 2145 | printk(KERN_DEBUG "cciss: turning intr off\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2146 | #endif /* CCISS_DEBUG */ |
| 2147 | info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF); |
| 2148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | /* Make sure there is room in the command FIFO */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2150 | /* Actually it should be completely empty at this time */ |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2151 | /* unless we are in here doing error handling for the scsi */ |
| 2152 | /* tape side of the driver. */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2153 | for (i = 200000; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | /* if fifo isn't full go */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2155 | if (!(info_p->access.fifo_full(info_p))) { |
| 2156 | |
| 2157 | break; |
| 2158 | } |
| 2159 | udelay(10); |
| 2160 | printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full," |
| 2161 | " waiting!\n", ctlr); |
| 2162 | } |
| 2163 | /* |
| 2164 | * Send the cmd |
| 2165 | */ |
| 2166 | info_p->access.submit_command(info_p, c); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2167 | done = 0; |
| 2168 | do { |
| 2169 | complete = pollcomplete(ctlr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | |
| 2171 | #ifdef CCISS_DEBUG |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2172 | printk(KERN_DEBUG "cciss: command completed\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2173 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2175 | if (complete == 1) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2176 | printk(KERN_WARNING |
| 2177 | "cciss cciss%d: SendCmd Timeout out, " |
| 2178 | "No command list address returned!\n", ctlr); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2179 | status = IO_ERROR; |
| 2180 | done = 1; |
| 2181 | break; |
| 2182 | } |
| 2183 | |
| 2184 | /* This will need to change for direct lookup completions */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2185 | if ((complete & CISS_ERROR_BIT) |
| 2186 | && (complete & ~CISS_ERROR_BIT) == c->busaddr) { |
| 2187 | /* if data overrun or underun on Report command |
| 2188 | ignore it |
| 2189 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | if (((c->Request.CDB[0] == CISS_REPORT_LOG) || |
| 2191 | (c->Request.CDB[0] == CISS_REPORT_PHYS) || |
| 2192 | (c->Request.CDB[0] == CISS_INQUIRY)) && |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2193 | ((c->err_info->CommandStatus == |
| 2194 | CMD_DATA_OVERRUN) || |
| 2195 | (c->err_info->CommandStatus == CMD_DATA_UNDERRUN) |
| 2196 | )) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | complete = c->busaddr; |
| 2198 | } else { |
| 2199 | if (c->err_info->CommandStatus == |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2200 | CMD_UNSOLICITED_ABORT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | printk(KERN_WARNING "cciss%d: " |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2202 | "unsolicited abort %p\n", |
| 2203 | ctlr, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | if (c->retry_count < MAX_CMD_RETRIES) { |
| 2205 | printk(KERN_WARNING |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2206 | "cciss%d: retrying %p\n", |
| 2207 | ctlr, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | c->retry_count++; |
| 2209 | /* erase the old error */ |
| 2210 | /* information */ |
| 2211 | memset(c->err_info, 0, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2212 | sizeof |
| 2213 | (ErrorInfo_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | goto resend_cmd1; |
| 2215 | } else { |
| 2216 | printk(KERN_WARNING |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2217 | "cciss%d: retried %p too " |
| 2218 | "many times\n", ctlr, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | status = IO_ERROR; |
| 2220 | goto cleanup1; |
| 2221 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2222 | } else if (c->err_info->CommandStatus == |
| 2223 | CMD_UNABORTABLE) { |
| 2224 | printk(KERN_WARNING |
| 2225 | "cciss%d: command could not be aborted.\n", |
| 2226 | ctlr); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2227 | status = IO_ERROR; |
| 2228 | goto cleanup1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | } |
| 2230 | printk(KERN_WARNING "ciss ciss%d: sendcmd" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2231 | " Error %x \n", ctlr, |
| 2232 | c->err_info->CommandStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | printk(KERN_WARNING "ciss ciss%d: sendcmd" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2234 | " offensive info\n" |
| 2235 | " size %x\n num %x value %x\n", |
| 2236 | ctlr, |
| 2237 | c->err_info->MoreErrInfo.Invalid_Cmd. |
| 2238 | offense_size, |
| 2239 | c->err_info->MoreErrInfo.Invalid_Cmd. |
| 2240 | offense_num, |
| 2241 | c->err_info->MoreErrInfo.Invalid_Cmd. |
| 2242 | offense_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | status = IO_ERROR; |
| 2244 | goto cleanup1; |
| 2245 | } |
| 2246 | } |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2247 | /* This will need changing for direct lookup completions */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2248 | if (complete != c->busaddr) { |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2249 | if (add_sendcmd_reject(cmd, ctlr, complete) != 0) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2250 | BUG(); /* we are pretty much hosed if we get here. */ |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2251 | } |
| 2252 | continue; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2253 | } else |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2254 | done = 1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2255 | } while (!done); |
| 2256 | |
| 2257 | cleanup1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | /* unlock the data buffer from DMA */ |
Mike Miller | bb2a37b | 2005-09-13 01:25:24 -0700 | [diff] [blame] | 2259 | buff_dma_handle.val32.lower = c->SG[0].Addr.lower; |
| 2260 | buff_dma_handle.val32.upper = c->SG[0].Addr.upper; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2262 | c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2263 | #ifdef CONFIG_CISS_SCSI_TAPE |
| 2264 | /* if we saved some commands for later, process them now. */ |
| 2265 | if (info_p->scsi_rejects.ncompletions > 0) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2266 | do_cciss_intr(0, info_p); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2267 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | cmd_free(info_p, c, 1); |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 2269 | return status; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | /* |
| 2273 | * Map (physical) PCI mem into (virtual) kernel space |
| 2274 | */ |
| 2275 | static void __iomem *remap_pci_mem(ulong base, ulong size) |
| 2276 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2277 | ulong page_base = ((ulong) base) & PAGE_MASK; |
| 2278 | ulong page_offs = ((ulong) base) - page_base; |
| 2279 | void __iomem *page_remapped = ioremap(page_base, page_offs + size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2281 | return page_remapped ? (page_remapped + page_offs) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2284 | /* |
| 2285 | * Takes jobs of the Q and sends them to the hardware, then puts it on |
| 2286 | * the Q to wait for completion. |
| 2287 | */ |
| 2288 | static void start_io(ctlr_info_t *h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | { |
| 2290 | CommandList_struct *c; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2291 | |
| 2292 | while ((c = h->reqQ) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | /* can't do anything if fifo is full */ |
| 2294 | if ((h->access.fifo_full(h))) { |
| 2295 | printk(KERN_WARNING "cciss: fifo full\n"); |
| 2296 | break; |
| 2297 | } |
| 2298 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2299 | /* Get the first entry from the Request Q */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | removeQ(&(h->reqQ), c); |
| 2301 | h->Qdepth--; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2302 | |
| 2303 | /* Tell the controller execute command */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | h->access.submit_command(h, c); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2305 | |
| 2306 | /* Put job onto the completed Q */ |
| 2307 | addQ(&(h->cmpQ), c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } |
| 2309 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | /* Assumes that CCISS_LOCK(h->ctlr) is held. */ |
| 2312 | /* Zeros out the error record and then resends the command back */ |
| 2313 | /* to the controller */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2314 | static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | { |
| 2316 | /* erase the old error information */ |
| 2317 | memset(c->err_info, 0, sizeof(ErrorInfo_struct)); |
| 2318 | |
| 2319 | /* add it to software queue and then send it to the controller */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2320 | addQ(&(h->reqQ), c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | h->Qdepth++; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2322 | if (h->Qdepth > h->maxQsinceinit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | h->maxQsinceinit = h->Qdepth; |
| 2324 | |
| 2325 | start_io(h); |
| 2326 | } |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 2327 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2328 | /* checks the status of the job and calls complete buffers to mark all |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 2329 | * buffers for the completed job. Note that this function does not need |
| 2330 | * to hold the hba/queue lock. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2331 | */ |
| 2332 | static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd, |
| 2333 | int timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | { |
| 2335 | int status = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | int retry_cmd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2338 | if (timeout) |
| 2339 | status = 0; |
| 2340 | |
| 2341 | if (cmd->err_info->CommandStatus != 0) { /* an error has occurred */ |
| 2342 | switch (cmd->err_info->CommandStatus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | unsigned char sense_key; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2344 | case CMD_TARGET_STATUS: |
| 2345 | status = 0; |
| 2346 | |
| 2347 | if (cmd->err_info->ScsiStatus == 0x02) { |
| 2348 | printk(KERN_WARNING "cciss: cmd %p " |
| 2349 | "has CHECK CONDITION " |
| 2350 | " byte 2 = 0x%x\n", cmd, |
| 2351 | cmd->err_info->SenseInfo[2] |
| 2352 | ); |
| 2353 | /* check the sense key */ |
| 2354 | sense_key = 0xf & cmd->err_info->SenseInfo[2]; |
| 2355 | /* no status or recovered error */ |
| 2356 | if ((sense_key == 0x0) || (sense_key == 0x1)) { |
| 2357 | status = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2359 | } else { |
| 2360 | printk(KERN_WARNING "cciss: cmd %p " |
| 2361 | "has SCSI Status 0x%x\n", |
| 2362 | cmd, cmd->err_info->ScsiStatus); |
| 2363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2365 | case CMD_DATA_UNDERRUN: |
| 2366 | printk(KERN_WARNING "cciss: cmd %p has" |
| 2367 | " completed with data underrun " |
| 2368 | "reported\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2370 | case CMD_DATA_OVERRUN: |
| 2371 | printk(KERN_WARNING "cciss: cmd %p has" |
| 2372 | " completed with data overrun " |
| 2373 | "reported\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2375 | case CMD_INVALID: |
| 2376 | printk(KERN_WARNING "cciss: cmd %p is " |
| 2377 | "reported invalid\n", cmd); |
| 2378 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2380 | case CMD_PROTOCOL_ERR: |
| 2381 | printk(KERN_WARNING "cciss: cmd %p has " |
| 2382 | "protocol error \n", cmd); |
| 2383 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2385 | case CMD_HARDWARE_ERR: |
| 2386 | printk(KERN_WARNING "cciss: cmd %p had " |
| 2387 | " hardware error\n", cmd); |
| 2388 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2390 | case CMD_CONNECTION_LOST: |
| 2391 | printk(KERN_WARNING "cciss: cmd %p had " |
| 2392 | "connection lost\n", cmd); |
| 2393 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2395 | case CMD_ABORTED: |
| 2396 | printk(KERN_WARNING "cciss: cmd %p was " |
| 2397 | "aborted\n", cmd); |
| 2398 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2400 | case CMD_ABORT_FAILED: |
| 2401 | printk(KERN_WARNING "cciss: cmd %p reports " |
| 2402 | "abort failed\n", cmd); |
| 2403 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | break; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2405 | case CMD_UNSOLICITED_ABORT: |
| 2406 | printk(KERN_WARNING "cciss%d: unsolicited " |
| 2407 | "abort %p\n", h->ctlr, cmd); |
| 2408 | if (cmd->retry_count < MAX_CMD_RETRIES) { |
| 2409 | retry_cmd = 1; |
| 2410 | printk(KERN_WARNING |
| 2411 | "cciss%d: retrying %p\n", h->ctlr, cmd); |
| 2412 | cmd->retry_count++; |
| 2413 | } else |
| 2414 | printk(KERN_WARNING |
| 2415 | "cciss%d: %p retried too " |
| 2416 | "many times\n", h->ctlr, cmd); |
| 2417 | status = 0; |
| 2418 | break; |
| 2419 | case CMD_TIMEOUT: |
| 2420 | printk(KERN_WARNING "cciss: cmd %p timedout\n", cmd); |
| 2421 | status = 0; |
| 2422 | break; |
| 2423 | default: |
| 2424 | printk(KERN_WARNING "cciss: cmd %p returned " |
| 2425 | "unknown status %x\n", cmd, |
| 2426 | cmd->err_info->CommandStatus); |
| 2427 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | /* We need to return this command */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2431 | if (retry_cmd) { |
| 2432 | resend_cciss_cmd(h, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | return; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 2436 | cmd->rq->completion_data = cmd; |
| 2437 | cmd->rq->errors = status; |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 2438 | blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE); |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 2439 | blk_complete_request(cmd->rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2442 | /* |
| 2443 | * Get a request and submit it to the controller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | */ |
| 2445 | static void do_cciss_request(request_queue_t *q) |
| 2446 | { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2447 | ctlr_info_t *h = q->queuedata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | CommandList_struct *c; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2449 | sector_t start_blk; |
| 2450 | int seg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | struct request *creq; |
| 2452 | u64bit temp64; |
| 2453 | struct scatterlist tmp_sg[MAXSGENTRIES]; |
| 2454 | drive_info_struct *drv; |
| 2455 | int i, dir; |
| 2456 | |
| 2457 | /* We call start_io here in case there is a command waiting on the |
| 2458 | * queue that has not been sent. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2459 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | if (blk_queue_plugged(q)) |
| 2461 | goto startio; |
| 2462 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2463 | queue: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | creq = elv_next_request(q); |
| 2465 | if (!creq) |
| 2466 | goto startio; |
| 2467 | |
Eric Sesterhenn | 089fe1b | 2006-03-24 18:50:27 +0100 | [diff] [blame] | 2468 | BUG_ON(creq->nr_phys_segments > MAXSGENTRIES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2470 | if ((c = cmd_alloc(h, 1)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | goto full; |
| 2472 | |
| 2473 | blkdev_dequeue_request(creq); |
| 2474 | |
| 2475 | spin_unlock_irq(q->queue_lock); |
| 2476 | |
| 2477 | c->cmd_type = CMD_RWREQ; |
| 2478 | c->rq = creq; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2479 | |
| 2480 | /* fill in the request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | drv = creq->rq_disk->private_data; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2482 | c->Header.ReplyQueue = 0; // unused in simple mode |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 2483 | /* got command from pool, so use the command block index instead */ |
| 2484 | /* for direct lookups. */ |
| 2485 | /* The first 2 bits are reserved for controller error reporting. */ |
| 2486 | c->Header.Tag.lower = (c->cmdindex << 3); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2487 | c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */ |
| 2488 | c->Header.LUN.LogDev.VolId = drv->LunID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | c->Header.LUN.LogDev.Mode = 1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2490 | c->Request.CDBLen = 10; // 12 byte commands not in FW yet; |
| 2491 | c->Request.Type.Type = TYPE_CMD; // It is a command. |
| 2492 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 2493 | c->Request.Type.Direction = |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2494 | (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2495 | c->Request.Timeout = 0; // Don't time out |
| 2496 | c->Request.CDB[0] = |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2497 | (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | start_blk = creq->sector; |
| 2499 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2500 | printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector, |
| 2501 | (int)creq->nr_sectors); |
| 2502 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | |
| 2504 | seg = blk_rq_map_sg(q, creq, tmp_sg); |
| 2505 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2506 | /* get the DMA records for the setup */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | if (c->Request.Type.Direction == XFER_READ) |
| 2508 | dir = PCI_DMA_FROMDEVICE; |
| 2509 | else |
| 2510 | dir = PCI_DMA_TODEVICE; |
| 2511 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2512 | for (i = 0; i < seg; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | c->SG[i].Len = tmp_sg[i].length; |
| 2514 | temp64.val = (__u64) pci_map_page(h->pdev, tmp_sg[i].page, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2515 | tmp_sg[i].offset, |
| 2516 | tmp_sg[i].length, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | c->SG[i].Addr.lower = temp64.val32.lower; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2518 | c->SG[i].Addr.upper = temp64.val32.upper; |
| 2519 | c->SG[i].Ext = 0; // we are not chaining |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2521 | /* track how many SG entries we are using */ |
| 2522 | if (seg > h->maxSG) |
| 2523 | h->maxSG = seg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
| 2525 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2526 | printk(KERN_DEBUG "cciss: Submitting %d sectors in %d segments\n", |
| 2527 | creq->nr_sectors, seg); |
| 2528 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | |
| 2530 | c->Header.SGList = c->Header.SGTotal = seg; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2531 | if(h->cciss_read == CCISS_READ_10) { |
| 2532 | c->Request.CDB[1] = 0; |
| 2533 | c->Request.CDB[2] = (start_blk >> 24) & 0xff; //MSB |
| 2534 | c->Request.CDB[3] = (start_blk >> 16) & 0xff; |
| 2535 | c->Request.CDB[4] = (start_blk >> 8) & 0xff; |
| 2536 | c->Request.CDB[5] = start_blk & 0xff; |
| 2537 | c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB |
| 2538 | c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff; |
| 2539 | c->Request.CDB[8] = creq->nr_sectors & 0xff; |
| 2540 | c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0; |
| 2541 | } else { |
| 2542 | c->Request.CDBLen = 16; |
| 2543 | c->Request.CDB[1]= 0; |
| 2544 | c->Request.CDB[2]= (start_blk >> 56) & 0xff; //MSB |
| 2545 | c->Request.CDB[3]= (start_blk >> 48) & 0xff; |
| 2546 | c->Request.CDB[4]= (start_blk >> 40) & 0xff; |
| 2547 | c->Request.CDB[5]= (start_blk >> 32) & 0xff; |
| 2548 | c->Request.CDB[6]= (start_blk >> 24) & 0xff; |
| 2549 | c->Request.CDB[7]= (start_blk >> 16) & 0xff; |
| 2550 | c->Request.CDB[8]= (start_blk >> 8) & 0xff; |
| 2551 | c->Request.CDB[9]= start_blk & 0xff; |
| 2552 | c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff; |
| 2553 | c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff; |
| 2554 | c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff; |
| 2555 | c->Request.CDB[13]= creq->nr_sectors & 0xff; |
| 2556 | c->Request.CDB[14] = c->Request.CDB[15] = 0; |
| 2557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
| 2559 | spin_lock_irq(q->queue_lock); |
| 2560 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2561 | addQ(&(h->reqQ), c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | h->Qdepth++; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2563 | if (h->Qdepth > h->maxQsinceinit) |
| 2564 | h->maxQsinceinit = h->Qdepth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
| 2566 | goto queue; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2567 | full: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | blk_stop_queue(q); |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 2569 | startio: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | /* We will already have the driver lock here so not need |
| 2571 | * to lock it. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2572 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | start_io(h); |
| 2574 | } |
| 2575 | |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2576 | static inline unsigned long get_next_completion(ctlr_info_t *h) |
| 2577 | { |
| 2578 | #ifdef CONFIG_CISS_SCSI_TAPE |
| 2579 | /* Any rejects from sendcmd() lying around? Process them first */ |
| 2580 | if (h->scsi_rejects.ncompletions == 0) |
| 2581 | return h->access.command_completed(h); |
| 2582 | else { |
| 2583 | struct sendcmd_reject_list *srl; |
| 2584 | int n; |
| 2585 | srl = &h->scsi_rejects; |
| 2586 | n = --srl->ncompletions; |
| 2587 | /* printk("cciss%d: processing saved reject\n", h->ctlr); */ |
| 2588 | printk("p"); |
| 2589 | return srl->complete[n]; |
| 2590 | } |
| 2591 | #else |
| 2592 | return h->access.command_completed(h); |
| 2593 | #endif |
| 2594 | } |
| 2595 | |
| 2596 | static inline int interrupt_pending(ctlr_info_t *h) |
| 2597 | { |
| 2598 | #ifdef CONFIG_CISS_SCSI_TAPE |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2599 | return (h->access.intr_pending(h) |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2600 | || (h->scsi_rejects.ncompletions > 0)); |
| 2601 | #else |
| 2602 | return h->access.intr_pending(h); |
| 2603 | #endif |
| 2604 | } |
| 2605 | |
| 2606 | static inline long interrupt_not_for_us(ctlr_info_t *h) |
| 2607 | { |
| 2608 | #ifdef CONFIG_CISS_SCSI_TAPE |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2609 | return (((h->access.intr_pending(h) == 0) || |
| 2610 | (h->interrupts_enabled == 0)) |
| 2611 | && (h->scsi_rejects.ncompletions == 0)); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2612 | #else |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2613 | return (((h->access.intr_pending(h) == 0) || |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2614 | (h->interrupts_enabled == 0))); |
| 2615 | #endif |
| 2616 | } |
| 2617 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2618 | static irqreturn_t do_cciss_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | { |
| 2620 | ctlr_info_t *h = dev_id; |
| 2621 | CommandList_struct *c; |
| 2622 | unsigned long flags; |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 2623 | __u32 a, a1, a2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2625 | if (interrupt_not_for_us(h)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | /* |
| 2628 | * If there are completed commands in the completion queue, |
| 2629 | * we had better do something about it. |
| 2630 | */ |
| 2631 | spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 2632 | while (interrupt_pending(h)) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2633 | while ((a = get_next_completion(h)) != FIFO_EMPTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | a1 = a; |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 2635 | if ((a & 0x04)) { |
| 2636 | a2 = (a >> 3); |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 2637 | if (a2 >= h->nr_cmds) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2638 | printk(KERN_WARNING |
| 2639 | "cciss: controller cciss%d failed, stopping.\n", |
| 2640 | h->ctlr); |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 2641 | fail_all_cmds(h->ctlr); |
| 2642 | return IRQ_HANDLED; |
| 2643 | } |
| 2644 | |
| 2645 | c = h->cmd_pool + a2; |
| 2646 | a = c->busaddr; |
| 2647 | |
| 2648 | } else { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2649 | a &= ~3; |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 2650 | if ((c = h->cmpQ) == NULL) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2651 | printk(KERN_WARNING |
| 2652 | "cciss: Completion of %08x ignored\n", |
| 2653 | a1); |
| 2654 | continue; |
| 2655 | } |
| 2656 | while (c->busaddr != a) { |
| 2657 | c = c->next; |
| 2658 | if (c == h->cmpQ) |
| 2659 | break; |
| 2660 | } |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 2661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | /* |
| 2663 | * If we've found the command, take it off the |
| 2664 | * completion Q and free it |
| 2665 | */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2666 | if (c->busaddr == a) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | removeQ(&h->cmpQ, c); |
| 2668 | if (c->cmd_type == CMD_RWREQ) { |
| 2669 | complete_command(h, c, 0); |
| 2670 | } else if (c->cmd_type == CMD_IOCTL_PEND) { |
| 2671 | complete(c->waiting); |
| 2672 | } |
| 2673 | # ifdef CONFIG_CISS_SCSI_TAPE |
| 2674 | else if (c->cmd_type == CMD_SCSI) |
| 2675 | complete_scsi_command(c, 0, a1); |
| 2676 | # endif |
| 2677 | continue; |
| 2678 | } |
| 2679 | } |
| 2680 | } |
| 2681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); |
| 2683 | return IRQ_HANDLED; |
| 2684 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2685 | |
| 2686 | /* |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 2687 | * We cannot read the structure directly, for portability we must use |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | * the io functions. |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2689 | * This is for debug only. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | */ |
| 2691 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2692 | static void print_cfg_table(CfgTable_struct *tb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | { |
| 2694 | int i; |
| 2695 | char temp_name[17]; |
| 2696 | |
| 2697 | printk("Controller Configuration information\n"); |
| 2698 | printk("------------------------------------\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2699 | for (i = 0; i < 4; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | temp_name[i] = readb(&(tb->Signature[i])); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2701 | temp_name[4] = '\0'; |
| 2702 | printk(" Signature = %s\n", temp_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | printk(" Spec Number = %d\n", readl(&(tb->SpecValence))); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2704 | printk(" Transport methods supported = 0x%x\n", |
| 2705 | readl(&(tb->TransportSupport))); |
| 2706 | printk(" Transport methods active = 0x%x\n", |
| 2707 | readl(&(tb->TransportActive))); |
| 2708 | printk(" Requested transport Method = 0x%x\n", |
| 2709 | readl(&(tb->HostWrite.TransportRequest))); |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 2710 | printk(" Coalesce Interrupt Delay = 0x%x\n", |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2711 | readl(&(tb->HostWrite.CoalIntDelay))); |
Bjorn Helgaas | d14c4ab | 2006-06-25 05:49:04 -0700 | [diff] [blame] | 2712 | printk(" Coalesce Interrupt Count = 0x%x\n", |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2713 | readl(&(tb->HostWrite.CoalIntCount))); |
| 2714 | printk(" Max outstanding commands = 0x%d\n", |
| 2715 | readl(&(tb->CmdsOutMax))); |
| 2716 | printk(" Bus Types = 0x%x\n", readl(&(tb->BusTypes))); |
| 2717 | for (i = 0; i < 16; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | temp_name[i] = readb(&(tb->ServerName[i])); |
| 2719 | temp_name[16] = '\0'; |
| 2720 | printk(" Server Name = %s\n", temp_name); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2721 | printk(" Heartbeat Counter = 0x%x\n\n\n", readl(&(tb->HeartBeat))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2723 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2725 | static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | { |
| 2727 | int i, offset, mem_type, bar_type; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2728 | if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | return 0; |
| 2730 | offset = 0; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2731 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 2732 | bar_type = pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | if (bar_type == PCI_BASE_ADDRESS_SPACE_IO) |
| 2734 | offset += 4; |
| 2735 | else { |
| 2736 | mem_type = pci_resource_flags(pdev, i) & |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2737 | PCI_BASE_ADDRESS_MEM_TYPE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | switch (mem_type) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2739 | case PCI_BASE_ADDRESS_MEM_TYPE_32: |
| 2740 | case PCI_BASE_ADDRESS_MEM_TYPE_1M: |
| 2741 | offset += 4; /* 32 bit */ |
| 2742 | break; |
| 2743 | case PCI_BASE_ADDRESS_MEM_TYPE_64: |
| 2744 | offset += 8; |
| 2745 | break; |
| 2746 | default: /* reserved in PCI 2.2 */ |
| 2747 | printk(KERN_WARNING |
| 2748 | "Base address is invalid\n"); |
| 2749 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | break; |
| 2751 | } |
| 2752 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2753 | if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0) |
| 2754 | return i + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | } |
| 2756 | return -1; |
| 2757 | } |
| 2758 | |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2759 | /* If MSI/MSI-X is supported by the kernel we will try to enable it on |
| 2760 | * controllers that are capable. If not, we use IO-APIC mode. |
| 2761 | */ |
| 2762 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2763 | static void __devinit cciss_interrupt_mode(ctlr_info_t *c, |
| 2764 | struct pci_dev *pdev, __u32 board_id) |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2765 | { |
| 2766 | #ifdef CONFIG_PCI_MSI |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2767 | int err; |
| 2768 | struct msix_entry cciss_msix_entries[4] = { {0, 0}, {0, 1}, |
| 2769 | {0, 2}, {0, 3} |
| 2770 | }; |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2771 | |
| 2772 | /* Some boards advertise MSI but don't really support it */ |
| 2773 | if ((board_id == 0x40700E11) || |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2774 | (board_id == 0x40800E11) || |
| 2775 | (board_id == 0x40820E11) || (board_id == 0x40830E11)) |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2776 | goto default_int_mode; |
| 2777 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2778 | if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) { |
| 2779 | err = pci_enable_msix(pdev, cciss_msix_entries, 4); |
| 2780 | if (!err) { |
| 2781 | c->intr[0] = cciss_msix_entries[0].vector; |
| 2782 | c->intr[1] = cciss_msix_entries[1].vector; |
| 2783 | c->intr[2] = cciss_msix_entries[2].vector; |
| 2784 | c->intr[3] = cciss_msix_entries[3].vector; |
| 2785 | c->msix_vector = 1; |
| 2786 | return; |
| 2787 | } |
| 2788 | if (err > 0) { |
| 2789 | printk(KERN_WARNING "cciss: only %d MSI-X vectors " |
| 2790 | "available\n", err); |
Mike Miller | 1ecb9c0 | 2006-12-06 20:35:13 -0800 | [diff] [blame] | 2791 | goto default_int_mode; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2792 | } else { |
| 2793 | printk(KERN_WARNING "cciss: MSI-X init failed %d\n", |
| 2794 | err); |
Mike Miller | 1ecb9c0 | 2006-12-06 20:35:13 -0800 | [diff] [blame] | 2795 | goto default_int_mode; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | if (pci_find_capability(pdev, PCI_CAP_ID_MSI)) { |
| 2799 | if (!pci_enable_msi(pdev)) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2800 | c->msi_vector = 1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2801 | } else { |
| 2802 | printk(KERN_WARNING "cciss: MSI init failed\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2803 | } |
| 2804 | } |
Mike Miller | 1ecb9c0 | 2006-12-06 20:35:13 -0800 | [diff] [blame] | 2805 | default_int_mode: |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2806 | #endif /* CONFIG_PCI_MSI */ |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2807 | /* if we get here we're going to use the default interrupt mode */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2808 | c->intr[SIMPLE_MODE_INT] = pdev->irq; |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2809 | return; |
| 2810 | } |
| 2811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev) |
| 2813 | { |
| 2814 | ushort subsystem_vendor_id, subsystem_device_id, command; |
| 2815 | __u32 board_id, scratchpad = 0; |
| 2816 | __u64 cfg_offset; |
| 2817 | __u32 cfg_base_addr; |
| 2818 | __u64 cfg_base_addr_index; |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2819 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
| 2821 | /* check to see if controller has been disabled */ |
| 2822 | /* BEFORE trying to enable it */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2823 | (void)pci_read_config_word(pdev, PCI_COMMAND, &command); |
| 2824 | if (!(command & 0x02)) { |
| 2825 | printk(KERN_WARNING |
| 2826 | "cciss: controller appears to be disabled\n"); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2827 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2830 | err = pci_enable_device(pdev); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2831 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | printk(KERN_ERR "cciss: Unable to Enable PCI device\n"); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2833 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 2836 | err = pci_request_regions(pdev, "cciss"); |
| 2837 | if (err) { |
| 2838 | printk(KERN_ERR "cciss: Cannot obtain PCI resources, " |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2839 | "aborting\n"); |
Mike Miller | 872225c | 2006-12-13 00:34:22 -0800 | [diff] [blame] | 2840 | return err; |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | subsystem_vendor_id = pdev->subsystem_vendor; |
| 2844 | subsystem_device_id = pdev->subsystem_device; |
| 2845 | board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2846 | subsystem_vendor_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | #ifdef CCISS_DEBUG |
| 2849 | printk("command = %x\n", command); |
| 2850 | printk("irq = %x\n", pdev->irq); |
| 2851 | printk("board_id = %x\n", board_id); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2852 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 2854 | /* If the kernel supports MSI/MSI-X we will try to enable that functionality, |
| 2855 | * else we use the IO-APIC interrupt assigned to us by system ROM. |
| 2856 | */ |
| 2857 | cciss_interrupt_mode(c, pdev, board_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | |
| 2859 | /* |
| 2860 | * Memory base addr is first addr , the second points to the config |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2861 | * table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | */ |
| 2863 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2864 | c->paddr = pci_resource_start(pdev, 0); /* addressing mode bits already removed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | #ifdef CCISS_DEBUG |
| 2866 | printk("address 0 = %x\n", c->paddr); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2867 | #endif /* CCISS_DEBUG */ |
Mike Miller | a5b9287 | 2006-12-13 00:34:21 -0800 | [diff] [blame] | 2868 | c->vaddr = remap_pci_mem(c->paddr, 0x250); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | |
| 2870 | /* Wait for the board to become ready. (PCI hotplug needs this.) |
| 2871 | * We poll for up to 120 secs, once per 100ms. */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2872 | for (i = 0; i < 1200; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET); |
| 2874 | if (scratchpad == CCISS_FIRMWARE_READY) |
| 2875 | break; |
| 2876 | set_current_state(TASK_INTERRUPTIBLE); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2877 | schedule_timeout(HZ / 10); /* wait 100ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | } |
| 2879 | if (scratchpad != CCISS_FIRMWARE_READY) { |
| 2880 | printk(KERN_WARNING "cciss: Board not ready. Timed out.\n"); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2881 | err = -ENODEV; |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 2882 | goto err_out_free_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | /* get the address index number */ |
| 2886 | cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET); |
| 2887 | cfg_base_addr &= (__u32) 0x0000ffff; |
| 2888 | #ifdef CCISS_DEBUG |
| 2889 | printk("cfg base address = %x\n", cfg_base_addr); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2890 | #endif /* CCISS_DEBUG */ |
| 2891 | cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | #ifdef CCISS_DEBUG |
| 2893 | printk("cfg base address index = %x\n", cfg_base_addr_index); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2894 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | if (cfg_base_addr_index == -1) { |
| 2896 | printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n"); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2897 | err = -ENODEV; |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 2898 | goto err_out_free_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET); |
| 2902 | #ifdef CCISS_DEBUG |
| 2903 | printk("cfg offset = %x\n", cfg_offset); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2904 | #endif /* CCISS_DEBUG */ |
| 2905 | c->cfgtable = remap_pci_mem(pci_resource_start(pdev, |
| 2906 | cfg_base_addr_index) + |
| 2907 | cfg_offset, sizeof(CfgTable_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | c->board_id = board_id; |
| 2909 | |
| 2910 | #ifdef CCISS_DEBUG |
Tobias Klauser | 945f390 | 2006-01-08 01:05:11 -0800 | [diff] [blame] | 2911 | print_cfg_table(c->cfgtable); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2912 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2914 | for (i = 0; i < ARRAY_SIZE(products); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | if (board_id == products[i].board_id) { |
| 2916 | c->product_name = products[i].product_name; |
| 2917 | c->access = *(products[i].access); |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 2918 | c->nr_cmds = products[i].nr_cmds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | break; |
| 2920 | } |
| 2921 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2922 | if ((readb(&c->cfgtable->Signature[0]) != 'C') || |
| 2923 | (readb(&c->cfgtable->Signature[1]) != 'I') || |
| 2924 | (readb(&c->cfgtable->Signature[2]) != 'S') || |
| 2925 | (readb(&c->cfgtable->Signature[3]) != 'S')) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | printk("Does not appear to be a valid CISS config table\n"); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 2927 | err = -ENODEV; |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 2928 | goto err_out_free_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | } |
Mike Miller | 4ff9a9a | 2006-12-06 20:35:00 -0800 | [diff] [blame] | 2930 | /* We didn't find the controller in our list. We know the |
| 2931 | * signature is valid. If it's an HP device let's try to |
| 2932 | * bind to the device and fire it up. Otherwise we bail. |
| 2933 | */ |
| 2934 | if (i == ARRAY_SIZE(products)) { |
| 2935 | if (subsystem_vendor_id == PCI_VENDOR_ID_HP) { |
| 2936 | c->product_name = products[i-1].product_name; |
| 2937 | c->access = *(products[i-1].access); |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 2938 | c->nr_cmds = products[i-1].nr_cmds; |
Mike Miller | 4ff9a9a | 2006-12-06 20:35:00 -0800 | [diff] [blame] | 2939 | printk(KERN_WARNING "cciss: This is an unknown " |
| 2940 | "Smart Array controller.\n" |
| 2941 | "cciss: Please update to the latest driver " |
| 2942 | "available from www.hp.com.\n"); |
| 2943 | } else { |
| 2944 | printk(KERN_WARNING "cciss: Sorry, I don't know how" |
| 2945 | " to access the Smart Array controller %08lx\n" |
| 2946 | , (unsigned long)board_id); |
| 2947 | err = -ENODEV; |
| 2948 | goto err_out_free_res; |
| 2949 | } |
| 2950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | #ifdef CONFIG_X86 |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2952 | { |
| 2953 | /* Need to enable prefetch in the SCSI core for 6400 in x86 */ |
| 2954 | __u32 prefetch; |
| 2955 | prefetch = readl(&(c->cfgtable->SCSI_Prefetch)); |
| 2956 | prefetch |= 0x100; |
| 2957 | writel(prefetch, &(c->cfgtable->SCSI_Prefetch)); |
| 2958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | #endif |
| 2960 | |
Mike Miller | f92e2f5 | 2006-12-06 20:35:04 -0800 | [diff] [blame] | 2961 | /* Disabling DMA prefetch for the P600 |
| 2962 | * An ASIC bug may result in a prefetch beyond |
| 2963 | * physical memory. |
| 2964 | */ |
| 2965 | if(board_id == 0x3225103C) { |
| 2966 | __u32 dma_prefetch; |
| 2967 | dma_prefetch = readl(c->vaddr + I2O_DMA1_CFG); |
| 2968 | dma_prefetch |= 0x8000; |
| 2969 | writel(dma_prefetch, c->vaddr + I2O_DMA1_CFG); |
| 2970 | } |
| 2971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | #ifdef CCISS_DEBUG |
| 2973 | printk("Trying to put board into Simple mode\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2974 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | c->max_commands = readl(&(c->cfgtable->CmdsOutMax)); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2976 | /* Update the field, and then ring the doorbell */ |
| 2977 | writel(CFGTBL_Trans_Simple, &(c->cfgtable->HostWrite.TransportRequest)); |
| 2978 | writel(CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | |
| 2980 | /* under certain very rare conditions, this can take awhile. |
| 2981 | * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right |
| 2982 | * as we enter this code.) */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2983 | for (i = 0; i < MAX_CONFIG_WAIT; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq)) |
| 2985 | break; |
| 2986 | /* delay and try again */ |
| 2987 | set_current_state(TASK_INTERRUPTIBLE); |
| 2988 | schedule_timeout(10); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2989 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | |
| 2991 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2992 | printk(KERN_DEBUG "I counter got to %d %x\n", i, |
| 2993 | readl(c->vaddr + SA5_DOORBELL)); |
| 2994 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2996 | print_cfg_table(c->cfgtable); |
| 2997 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 2999 | if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | printk(KERN_WARNING "cciss: unable to get board into" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3001 | " simple mode\n"); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 3002 | err = -ENODEV; |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 3003 | goto err_out_free_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | } |
| 3005 | return 0; |
| 3006 | |
Linus Torvalds | 5faad62 | 2006-12-13 09:15:34 -0800 | [diff] [blame^] | 3007 | err_out_free_res: |
Mike Miller | 872225c | 2006-12-13 00:34:22 -0800 | [diff] [blame] | 3008 | /* |
| 3009 | * Deliberately omit pci_disable_device(): it does something nasty to |
| 3010 | * Smart Array controllers that pci_enable_device does not undo |
| 3011 | */ |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 3012 | pci_release_regions(pdev); |
Bjorn Helgaas | c33ac89 | 2006-06-25 05:49:01 -0700 | [diff] [blame] | 3013 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3016 | /* |
| 3017 | * Gets information about the local volumes attached to the controller. |
| 3018 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | static void cciss_getgeometry(int cntl_num) |
| 3020 | { |
| 3021 | ReportLunData_struct *ld_buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | InquiryData_struct *inq_buff; |
| 3023 | int return_code; |
| 3024 | int i; |
| 3025 | int listlength = 0; |
| 3026 | __u32 lunid = 0; |
| 3027 | int block_size; |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 3028 | sector_t total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | |
Eric Sesterhenn | 06ff37f | 2006-03-08 11:21:52 +0100 | [diff] [blame] | 3030 | ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3031 | if (ld_buff == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | printk(KERN_ERR "cciss: out of memory\n"); |
| 3033 | return; |
| 3034 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3035 | inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); |
| 3036 | if (inq_buff == NULL) { |
| 3037 | printk(KERN_ERR "cciss: out of memory\n"); |
| 3038 | kfree(ld_buff); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3039 | return; |
| 3040 | } |
| 3041 | /* Get the firmware version */ |
| 3042 | return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff, |
| 3043 | sizeof(InquiryData_struct), 0, 0, 0, NULL, |
| 3044 | TYPE_CMD); |
| 3045 | if (return_code == IO_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32]; |
| 3047 | hba[cntl_num]->firm_ver[1] = inq_buff->data_byte[33]; |
| 3048 | hba[cntl_num]->firm_ver[2] = inq_buff->data_byte[34]; |
| 3049 | hba[cntl_num]->firm_ver[3] = inq_buff->data_byte[35]; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3050 | } else { /* send command failed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3052 | printk(KERN_WARNING "cciss: unable to determine firmware" |
| 3053 | " version of controller\n"); |
| 3054 | } |
| 3055 | /* Get the number of logical volumes */ |
| 3056 | return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff, |
| 3057 | sizeof(ReportLunData_struct), 0, 0, 0, NULL, |
| 3058 | TYPE_CMD); |
| 3059 | |
| 3060 | if (return_code == IO_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | #ifdef CCISS_DEBUG |
| 3062 | printk("LUN Data\n--------------------------\n"); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3063 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3065 | listlength |= |
| 3066 | (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24; |
| 3067 | listlength |= |
| 3068 | (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16; |
| 3069 | listlength |= |
| 3070 | (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3072 | } else { /* reading number of logical volumes failed */ |
| 3073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | printk(KERN_WARNING "cciss: report logical volume" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3075 | " command failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | listlength = 0; |
| 3077 | } |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3078 | hba[cntl_num]->num_luns = listlength / 8; // 8 bytes pre entry |
| 3079 | if (hba[cntl_num]->num_luns > CISS_MAX_LUN) { |
| 3080 | printk(KERN_ERR |
| 3081 | "ciss: only %d number of logical volumes supported\n", |
| 3082 | CISS_MAX_LUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | hba[cntl_num]->num_luns = CISS_MAX_LUN; |
| 3084 | } |
| 3085 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3086 | printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", |
| 3087 | ld_buff->LUNListLength[0], ld_buff->LUNListLength[1], |
| 3088 | ld_buff->LUNListLength[2], ld_buff->LUNListLength[3], |
| 3089 | hba[cntl_num]->num_luns); |
| 3090 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3092 | hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns - 1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3093 | for (i = 0; i < CISS_MAX_LUN; i++) { |
| 3094 | if (i < hba[cntl_num]->num_luns) { |
| 3095 | lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) |
| 3096 | << 24; |
| 3097 | lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2])) |
| 3098 | << 16; |
| 3099 | lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1])) |
| 3100 | << 8; |
| 3101 | lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3103 | hba[cntl_num]->drv[i].LunID = lunid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | |
| 3105 | #ifdef CCISS_DEBUG |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3106 | printk(KERN_DEBUG "LUN[%d]: %x %x %x %x = %x\n", i, |
| 3107 | ld_buff->LUN[i][0], ld_buff->LUN[i][1], |
| 3108 | ld_buff->LUN[i][2], ld_buff->LUN[i][3], |
| 3109 | hba[cntl_num]->drv[i].LunID); |
| 3110 | #endif /* CCISS_DEBUG */ |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 3111 | |
| 3112 | /* testing to see if 16-byte CDBs are already being used */ |
| 3113 | if(hba[cntl_num]->cciss_read == CCISS_READ_16) { |
| 3114 | cciss_read_capacity_16(cntl_num, i, 0, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3115 | &total_size, &block_size); |
Mike Miller (OS Dev) | 00988a3 | 2006-09-30 23:27:23 -0700 | [diff] [blame] | 3116 | goto geo_inq; |
| 3117 | } |
| 3118 | cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size); |
| 3119 | |
| 3120 | /* total_size = last LBA + 1 */ |
| 3121 | if(total_size == (__u32) 0) { |
| 3122 | cciss_read_capacity_16(cntl_num, i, 0, |
| 3123 | &total_size, &block_size); |
| 3124 | hba[cntl_num]->cciss_read = CCISS_READ_16; |
| 3125 | hba[cntl_num]->cciss_write = CCISS_WRITE_16; |
| 3126 | } else { |
| 3127 | hba[cntl_num]->cciss_read = CCISS_READ_10; |
| 3128 | hba[cntl_num]->cciss_write = CCISS_WRITE_10; |
| 3129 | } |
| 3130 | geo_inq: |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3131 | cciss_geometry_inquiry(cntl_num, i, 0, total_size, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3132 | block_size, inq_buff, |
| 3133 | &hba[cntl_num]->drv[i]); |
Mike Miller | ddd4744 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3134 | } else { |
| 3135 | /* initialize raid_level to indicate a free space */ |
| 3136 | hba[cntl_num]->drv[i].raid_level = -1; |
| 3137 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
| 3139 | kfree(ld_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | kfree(inq_buff); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | |
| 3143 | /* Function to find the first free pointer into our hba[] array */ |
| 3144 | /* Returns -1 if no free entries are left. */ |
| 3145 | static int alloc_cciss_hba(void) |
| 3146 | { |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3147 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3149 | for (i = 0; i < MAX_CTLR; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | if (!hba[i]) { |
| 3151 | ctlr_info_t *p; |
Eric Sesterhenn | 06ff37f | 2006-03-08 11:21:52 +0100 | [diff] [blame] | 3152 | p = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | if (!p) |
| 3154 | goto Enomem; |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3155 | p->gendisk[0] = alloc_disk(1 << NWD_SHIFT); |
| 3156 | if (!p->gendisk[0]) |
| 3157 | goto Enomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | hba[i] = p; |
| 3159 | return i; |
| 3160 | } |
| 3161 | } |
| 3162 | printk(KERN_WARNING "cciss: This driver supports a maximum" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3163 | " of %d controllers.\n", MAX_CTLR); |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3164 | return -1; |
| 3165 | Enomem: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | printk(KERN_ERR "cciss: out of memory.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | return -1; |
| 3168 | } |
| 3169 | |
| 3170 | static void free_hba(int i) |
| 3171 | { |
| 3172 | ctlr_info_t *p = hba[i]; |
| 3173 | int n; |
| 3174 | |
| 3175 | hba[i] = NULL; |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3176 | for (n = 0; n < CISS_MAX_LUN; n++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | put_disk(p->gendisk[n]); |
| 3178 | kfree(p); |
| 3179 | } |
| 3180 | |
| 3181 | /* |
| 3182 | * This is it. Find all the controllers and register them. I really hate |
| 3183 | * stealing all these major device numbers. |
| 3184 | * returns the number of block devices registered. |
| 3185 | */ |
| 3186 | static int __devinit cciss_init_one(struct pci_dev *pdev, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3187 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | int i; |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3190 | int j = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | int rc; |
Bjorn Helgaas | 40aabb5 | 2006-06-25 05:49:03 -0700 | [diff] [blame] | 3192 | int dac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | i = alloc_cciss_hba(); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3195 | if (i < 0) |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 3196 | return -1; |
Mike Miller | 1f8ef38 | 2005-09-13 01:25:21 -0700 | [diff] [blame] | 3197 | |
| 3198 | hba[i]->busy_initializing = 1; |
| 3199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | if (cciss_pci_init(hba[i], pdev) != 0) |
| 3201 | goto clean1; |
| 3202 | |
| 3203 | sprintf(hba[i]->devname, "cciss%d", i); |
| 3204 | hba[i]->ctlr = i; |
| 3205 | hba[i]->pdev = pdev; |
| 3206 | |
| 3207 | /* configure PCI DMA stuff */ |
mike.miller@hp.com | eb0df99 | 2005-06-10 14:51:04 -0500 | [diff] [blame] | 3208 | if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) |
Bjorn Helgaas | 40aabb5 | 2006-06-25 05:49:03 -0700 | [diff] [blame] | 3209 | dac = 1; |
mike.miller@hp.com | eb0df99 | 2005-06-10 14:51:04 -0500 | [diff] [blame] | 3210 | else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) |
Bjorn Helgaas | 40aabb5 | 2006-06-25 05:49:03 -0700 | [diff] [blame] | 3211 | dac = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | else { |
Bjorn Helgaas | 40aabb5 | 2006-06-25 05:49:03 -0700 | [diff] [blame] | 3213 | printk(KERN_ERR "cciss: no suitable DMA available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | goto clean1; |
| 3215 | } |
| 3216 | |
| 3217 | /* |
| 3218 | * register with the major number, or get a dynamic major number |
| 3219 | * by passing 0 as argument. This is done for greater than |
| 3220 | * 8 controller support. |
| 3221 | */ |
| 3222 | if (i < MAX_CTLR_ORIG) |
Christoph Hellwig | 564de74 | 2006-01-08 01:05:17 -0800 | [diff] [blame] | 3223 | hba[i]->major = COMPAQ_CISS_MAJOR + i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | rc = register_blkdev(hba[i]->major, hba[i]->devname); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3225 | if (rc == -EBUSY || rc == -EINVAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | printk(KERN_ERR |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3227 | "cciss: Unable to get major number %d for %s " |
| 3228 | "on hba %d\n", hba[i]->major, hba[i]->devname, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | goto clean1; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3230 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | if (i >= MAX_CTLR_ORIG) |
| 3232 | hba[i]->major = rc; |
| 3233 | } |
| 3234 | |
| 3235 | /* make sure the board interrupts are off */ |
| 3236 | hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3237 | if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr, |
Thomas Gleixner | 69ab391 | 2006-07-01 19:29:32 -0700 | [diff] [blame] | 3238 | IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | printk(KERN_ERR "cciss: Unable to get irq %d for %s\n", |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3240 | hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | goto clean2; |
| 3242 | } |
Bjorn Helgaas | 40aabb5 | 2006-06-25 05:49:03 -0700 | [diff] [blame] | 3243 | |
| 3244 | printk(KERN_INFO "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n", |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3245 | hba[i]->devname, pdev->device, pci_name(pdev), |
| 3246 | hba[i]->intr[SIMPLE_MODE_INT], dac ? "" : " not"); |
Bjorn Helgaas | 40aabb5 | 2006-06-25 05:49:03 -0700 | [diff] [blame] | 3247 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3248 | hba[i]->cmd_pool_bits = |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3249 | kmalloc(((hba[i]->nr_cmds + BITS_PER_LONG - |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3250 | 1) / BITS_PER_LONG) * sizeof(unsigned long), GFP_KERNEL); |
| 3251 | hba[i]->cmd_pool = (CommandList_struct *) |
| 3252 | pci_alloc_consistent(hba[i]->pdev, |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3253 | hba[i]->nr_cmds * sizeof(CommandList_struct), |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3254 | &(hba[i]->cmd_pool_dhandle)); |
| 3255 | hba[i]->errinfo_pool = (ErrorInfo_struct *) |
| 3256 | pci_alloc_consistent(hba[i]->pdev, |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3257 | hba[i]->nr_cmds * sizeof(ErrorInfo_struct), |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3258 | &(hba[i]->errinfo_pool_dhandle)); |
| 3259 | if ((hba[i]->cmd_pool_bits == NULL) |
| 3260 | || (hba[i]->cmd_pool == NULL) |
| 3261 | || (hba[i]->errinfo_pool == NULL)) { |
| 3262 | printk(KERN_ERR "cciss: out of memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | goto clean4; |
| 3264 | } |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 3265 | #ifdef CONFIG_CISS_SCSI_TAPE |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3266 | hba[i]->scsi_rejects.complete = |
| 3267 | kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) * |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3268 | (hba[i]->nr_cmds + 5), GFP_KERNEL); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 3269 | if (hba[i]->scsi_rejects.complete == NULL) { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3270 | printk(KERN_ERR "cciss: out of memory"); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 3271 | goto clean4; |
| 3272 | } |
| 3273 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | spin_lock_init(&hba[i]->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3276 | /* Initialize the pdev driver private data. |
| 3277 | have it point to hba[i]. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | pci_set_drvdata(pdev, hba[i]); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3279 | /* command and error info recs zeroed out before |
| 3280 | they are used */ |
| 3281 | memset(hba[i]->cmd_pool_bits, 0, |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3282 | ((hba[i]->nr_cmds + BITS_PER_LONG - |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3283 | 1) / BITS_PER_LONG) * sizeof(unsigned long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3285 | #ifdef CCISS_DEBUG |
| 3286 | printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n", i); |
| 3287 | #endif /* CCISS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | |
| 3289 | cciss_getgeometry(i); |
| 3290 | |
| 3291 | cciss_scsi_setup(i); |
| 3292 | |
| 3293 | /* Turn the interrupts on so we can service requests */ |
| 3294 | hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON); |
| 3295 | |
| 3296 | cciss_procinit(i); |
Mike Miller | 92c4231a | 2006-12-06 20:35:06 -0800 | [diff] [blame] | 3297 | |
| 3298 | hba[i]->cciss_max_sectors = 2048; |
| 3299 | |
Mike Miller | d6dbf42 | 2005-09-21 09:55:32 -0700 | [diff] [blame] | 3300 | hba[i]->busy_initializing = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3302 | do { |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3303 | drive_info_struct *drv = &(hba[i]->drv[j]); |
| 3304 | struct gendisk *disk = hba[i]->gendisk[j]; |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3305 | request_queue_t *q; |
| 3306 | |
| 3307 | /* Check if the disk was allocated already */ |
| 3308 | if (!disk){ |
| 3309 | hba[i]->gendisk[j] = alloc_disk(1 << NWD_SHIFT); |
| 3310 | disk = hba[i]->gendisk[j]; |
| 3311 | } |
| 3312 | |
| 3313 | /* Check that the disk was able to be allocated */ |
| 3314 | if (!disk) { |
| 3315 | printk(KERN_ERR "cciss: unable to allocate memory for disk %d\n", j); |
| 3316 | goto clean4; |
| 3317 | } |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3318 | |
| 3319 | q = blk_init_queue(do_cciss_request, &hba[i]->lock); |
| 3320 | if (!q) { |
| 3321 | printk(KERN_ERR |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3322 | "cciss: unable to allocate queue for disk %d\n", |
| 3323 | j); |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3324 | goto clean4; |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3325 | } |
| 3326 | drv->queue = q; |
| 3327 | |
| 3328 | q->backing_dev_info.ra_pages = READ_AHEAD; |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 3329 | blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 3331 | /* This is a hardware imposed limit. */ |
| 3332 | blk_queue_max_hw_segments(q, MAXSGENTRIES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 3334 | /* This is a limit in the driver and could be eliminated. */ |
| 3335 | blk_queue_max_phys_segments(q, MAXSGENTRIES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | |
Mike Miller | 92c4231a | 2006-12-06 20:35:06 -0800 | [diff] [blame] | 3337 | blk_queue_max_sectors(q, hba[i]->cciss_max_sectors); |
Jens Axboe | a9925a0 | 2006-01-09 16:04:06 +0100 | [diff] [blame] | 3338 | |
| 3339 | blk_queue_softirq_done(q, cciss_softirq_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3341 | q->queuedata = hba[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | sprintf(disk->disk_name, "cciss/c%dd%d", i, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | disk->major = hba[i]->major; |
| 3344 | disk->first_minor = j << NWD_SHIFT; |
| 3345 | disk->fops = &cciss_fops; |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3346 | disk->queue = q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | disk->private_data = drv; |
Greg Kroah-Hartman | 27c0ff8 | 2006-04-27 15:46:39 -0700 | [diff] [blame] | 3348 | disk->driverfs_dev = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | /* we must register the controller even if no disks exist */ |
| 3350 | /* this is for the online array utilities */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3351 | if (!drv->heads && j) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | continue; |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3353 | blk_queue_hardsect_size(q, drv->block_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | set_capacity(disk, drv->nr_blocks); |
| 3355 | add_disk(disk); |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3356 | j++; |
| 3357 | } while (j <= hba[i]->highest_lun); |
Mike Miller | ad2b931 | 2005-07-28 01:07:31 -0700 | [diff] [blame] | 3358 | |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 3359 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3361 | clean4: |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 3362 | #ifdef CONFIG_CISS_SCSI_TAPE |
Andrew Morton | 1acc0b0 | 2006-01-04 18:30:03 -0800 | [diff] [blame] | 3363 | kfree(hba[i]->scsi_rejects.complete); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 3364 | #endif |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 3365 | kfree(hba[i]->cmd_pool_bits); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3366 | if (hba[i]->cmd_pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | pci_free_consistent(hba[i]->pdev, |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3368 | hba[i]->nr_cmds * sizeof(CommandList_struct), |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3369 | hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); |
| 3370 | if (hba[i]->errinfo_pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | pci_free_consistent(hba[i]->pdev, |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3372 | hba[i]->nr_cmds * sizeof(ErrorInfo_struct), |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3373 | hba[i]->errinfo_pool, |
| 3374 | hba[i]->errinfo_pool_dhandle); |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 3375 | free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3376 | clean2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | unregister_blkdev(hba[i]->major, hba[i]->devname); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3378 | clean1: |
Mike Miller | 1f8ef38 | 2005-09-13 01:25:21 -0700 | [diff] [blame] | 3379 | hba[i]->busy_initializing = 0; |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3380 | /* cleanup any queues that may have been initialized */ |
| 3381 | for (j=0; j <= hba[i]->highest_lun; j++){ |
| 3382 | drive_info_struct *drv = &(hba[i]->drv[j]); |
| 3383 | if (drv->queue) |
| 3384 | blk_cleanup_queue(drv->queue); |
| 3385 | } |
Mike Miller | 872225c | 2006-12-13 00:34:22 -0800 | [diff] [blame] | 3386 | /* |
| 3387 | * Deliberately omit pci_disable_device(): it does something nasty to |
| 3388 | * Smart Array controllers that pci_enable_device does not undo |
| 3389 | */ |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3390 | pci_release_regions(pdev); |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3391 | pci_set_drvdata(pdev, NULL); |
Patrick McHardy | 61808c2 | 2006-03-23 02:59:24 -0800 | [diff] [blame] | 3392 | free_hba(i); |
Bjorn Helgaas | e2019b5 | 2006-06-25 05:49:05 -0700 | [diff] [blame] | 3393 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3396 | static void __devexit cciss_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | { |
| 3398 | ctlr_info_t *tmp_ptr; |
| 3399 | int i, j; |
| 3400 | char flush_buf[4]; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3401 | int return_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3403 | if (pci_get_drvdata(pdev) == NULL) { |
| 3404 | printk(KERN_ERR "cciss: Unable to remove device \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | return; |
| 3406 | } |
| 3407 | tmp_ptr = pci_get_drvdata(pdev); |
| 3408 | i = tmp_ptr->ctlr; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3409 | if (hba[i] == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | printk(KERN_ERR "cciss: device appears to " |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3411 | "already be removed \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | return; |
| 3413 | } |
| 3414 | /* Turn board interrupts off and send the flush cache command */ |
| 3415 | /* sendcmd will turn off interrupt, and send the flush... |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3416 | * To write all data in the battery backed cache to disks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | memset(flush_buf, 0, 4); |
| 3418 | return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL, |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3419 | TYPE_CMD); |
| 3420 | if (return_code != IO_OK) { |
| 3421 | printk(KERN_WARNING "Error Flushing cache on controller %d\n", |
| 3422 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | } |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 3424 | free_irq(hba[i]->intr[2], hba[i]); |
| 3425 | |
| 3426 | #ifdef CONFIG_PCI_MSI |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3427 | if (hba[i]->msix_vector) |
| 3428 | pci_disable_msix(hba[i]->pdev); |
| 3429 | else if (hba[i]->msi_vector) |
| 3430 | pci_disable_msi(hba[i]->pdev); |
| 3431 | #endif /* CONFIG_PCI_MSI */ |
Mike Miller | fb86a35 | 2006-01-08 01:03:50 -0800 | [diff] [blame] | 3432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | iounmap(hba[i]->vaddr); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3434 | cciss_unregister_scsi(i); /* unhook from SCSI subsystem */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | unregister_blkdev(hba[i]->major, hba[i]->devname); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3436 | remove_proc_entry(hba[i]->devname, proc_cciss); |
| 3437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | /* remove it from the disk list */ |
Mike Miller | 799202c | 2006-12-06 20:35:12 -0800 | [diff] [blame] | 3439 | for (j = 0; j < CISS_MAX_LUN; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | struct gendisk *disk = hba[i]->gendisk[j]; |
mikem | 6f5a0f7 | 2005-11-18 22:05:36 +0100 | [diff] [blame] | 3441 | if (disk) { |
| 3442 | request_queue_t *q = disk->queue; |
| 3443 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3444 | if (disk->flags & GENHD_FL_UP) |
mikem | 6f5a0f7 | 2005-11-18 22:05:36 +0100 | [diff] [blame] | 3445 | del_gendisk(disk); |
| 3446 | if (q) |
| 3447 | blk_cleanup_queue(q); |
Mike Miller | 6a445d3 | 2005-09-13 01:25:23 -0700 | [diff] [blame] | 3448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | } |
| 3450 | |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3451 | pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(CommandList_struct), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); |
Mike Miller | f880632 | 2006-12-06 20:35:01 -0800 | [diff] [blame] | 3453 | pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct), |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3454 | hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | kfree(hba[i]->cmd_pool_bits); |
mike.miller@hp.com | 3da8b71 | 2005-11-04 12:30:37 -0600 | [diff] [blame] | 3456 | #ifdef CONFIG_CISS_SCSI_TAPE |
| 3457 | kfree(hba[i]->scsi_rejects.complete); |
| 3458 | #endif |
Mike Miller | 872225c | 2006-12-13 00:34:22 -0800 | [diff] [blame] | 3459 | /* |
| 3460 | * Deliberately omit pci_disable_device(): it does something nasty to |
| 3461 | * Smart Array controllers that pci_enable_device does not undo |
| 3462 | */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3463 | pci_release_regions(pdev); |
Bjorn Helgaas | 4e57030 | 2006-06-25 05:49:02 -0700 | [diff] [blame] | 3464 | pci_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | free_hba(i); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | |
| 3468 | static struct pci_driver cciss_pci_driver = { |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3469 | .name = "cciss", |
| 3470 | .probe = cciss_init_one, |
| 3471 | .remove = __devexit_p(cciss_remove_one), |
| 3472 | .id_table = cciss_pci_device_id, /* id_table */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | }; |
| 3474 | |
| 3475 | /* |
| 3476 | * This is it. Register the PCI driver information for the cards we control |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3477 | * the OS will call our registered routines when it finds one of our cards. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | */ |
| 3479 | static int __init cciss_init(void) |
| 3480 | { |
| 3481 | printk(KERN_INFO DRIVER_NAME "\n"); |
| 3482 | |
| 3483 | /* Register for our PCI devices */ |
Richard Knutsson | 9bfab8c | 2005-11-30 00:59:34 +0100 | [diff] [blame] | 3484 | return pci_register_driver(&cciss_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | static void __exit cciss_cleanup(void) |
| 3488 | { |
| 3489 | int i; |
| 3490 | |
| 3491 | pci_unregister_driver(&cciss_pci_driver); |
| 3492 | /* double check that all controller entrys have been removed */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3493 | for (i = 0; i < MAX_CTLR; i++) { |
| 3494 | if (hba[i] != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | printk(KERN_WARNING "cciss: had to remove" |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3496 | " controller %d\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | cciss_remove_one(hba[i]->pdev); |
| 3498 | } |
| 3499 | } |
| 3500 | remove_proc_entry("cciss", proc_root_driver); |
| 3501 | } |
| 3502 | |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3503 | static void fail_all_cmds(unsigned long ctlr) |
| 3504 | { |
| 3505 | /* If we get here, the board is apparently dead. */ |
| 3506 | ctlr_info_t *h = hba[ctlr]; |
| 3507 | CommandList_struct *c; |
| 3508 | unsigned long flags; |
| 3509 | |
| 3510 | printk(KERN_WARNING "cciss%d: controller not responding.\n", h->ctlr); |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3511 | h->alive = 0; /* the controller apparently died... */ |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3512 | |
| 3513 | spin_lock_irqsave(CCISS_LOCK(ctlr), flags); |
| 3514 | |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3515 | pci_disable_device(h->pdev); /* Make sure it is really dead. */ |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3516 | |
| 3517 | /* move everything off the request queue onto the completed queue */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3518 | while ((c = h->reqQ) != NULL) { |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3519 | removeQ(&(h->reqQ), c); |
| 3520 | h->Qdepth--; |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3521 | addQ(&(h->cmpQ), c); |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | /* Now, fail everything on the completed queue with a HW error */ |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3525 | while ((c = h->cmpQ) != NULL) { |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3526 | removeQ(&h->cmpQ, c); |
| 3527 | c->err_info->CommandStatus = CMD_HARDWARE_ERR; |
| 3528 | if (c->cmd_type == CMD_RWREQ) { |
| 3529 | complete_command(h, c, 0); |
| 3530 | } else if (c->cmd_type == CMD_IOCTL_PEND) |
| 3531 | complete(c->waiting); |
| 3532 | #ifdef CONFIG_CISS_SCSI_TAPE |
Bjorn Helgaas | 7c83283 | 2006-06-25 05:49:06 -0700 | [diff] [blame] | 3533 | else if (c->cmd_type == CMD_SCSI) |
| 3534 | complete_scsi_command(c, 0, 0); |
Mike Miller | 33079b2 | 2005-09-13 01:25:22 -0700 | [diff] [blame] | 3535 | #endif |
| 3536 | } |
| 3537 | spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); |
| 3538 | return; |
| 3539 | } |
| 3540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | module_init(cciss_init); |
| 3542 | module_exit(cciss_cleanup); |