Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Disk Array driver for HP Smart Array SAS controllers |
Scott Teel | 51c3513 | 2014-02-18 13:57:26 -0600 | [diff] [blame] | 3 | * Copyright 2000, 2014 Hewlett-Packard Development Company, L.P. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [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; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 12 | * NON INFRINGEMENT. See the GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | * |
| 18 | * Questions/Comments/Bugfixes to iss_storagedev@hp.com |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/pci.h> |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 26 | #include <linux/pci-aspm.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 27 | #include <linux/kernel.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/timer.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/spinlock.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 34 | #include <linux/compat.h> |
| 35 | #include <linux/blktrace_api.h> |
| 36 | #include <linux/uaccess.h> |
| 37 | #include <linux/io.h> |
| 38 | #include <linux/dma-mapping.h> |
| 39 | #include <linux/completion.h> |
| 40 | #include <linux/moduleparam.h> |
| 41 | #include <scsi/scsi.h> |
| 42 | #include <scsi/scsi_cmnd.h> |
| 43 | #include <scsi/scsi_device.h> |
| 44 | #include <scsi/scsi_host.h> |
Stephen M. Cameron | 667e23d | 2010-02-25 14:02:51 -0600 | [diff] [blame] | 45 | #include <scsi/scsi_tcq.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 46 | #include <linux/cciss_ioctl.h> |
| 47 | #include <linux/string.h> |
| 48 | #include <linux/bitmap.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 49 | #include <linux/atomic.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 50 | #include <linux/kthread.h> |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 51 | #include <linux/jiffies.h> |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 52 | #include <asm/div64.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 53 | #include "hpsa_cmd.h" |
| 54 | #include "hpsa.h" |
| 55 | |
| 56 | /* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */ |
Mike Miller | e481cce | 2013-09-04 15:12:27 -0500 | [diff] [blame] | 57 | #define HPSA_DRIVER_VERSION "3.4.0-1" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 58 | #define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 59 | #define HPSA "hpsa" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 60 | |
| 61 | /* How long to wait (in milliseconds) for board to go into simple mode */ |
| 62 | #define MAX_CONFIG_WAIT 30000 |
| 63 | #define MAX_IOCTL_CONFIG_WAIT 1000 |
| 64 | |
| 65 | /*define how many times we will try a command because of bus resets */ |
| 66 | #define MAX_CMD_RETRIES 3 |
| 67 | |
| 68 | /* Embedded module documentation macros - see modules.h */ |
| 69 | MODULE_AUTHOR("Hewlett-Packard Company"); |
| 70 | MODULE_DESCRIPTION("Driver for HP Smart Array Controller version " \ |
| 71 | HPSA_DRIVER_VERSION); |
| 72 | MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers"); |
| 73 | MODULE_VERSION(HPSA_DRIVER_VERSION); |
| 74 | MODULE_LICENSE("GPL"); |
| 75 | |
| 76 | static int hpsa_allow_any; |
| 77 | module_param(hpsa_allow_any, int, S_IRUGO|S_IWUSR); |
| 78 | MODULE_PARM_DESC(hpsa_allow_any, |
| 79 | "Allow hpsa driver to access unknown HP Smart Array hardware"); |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 80 | static int hpsa_simple_mode; |
| 81 | module_param(hpsa_simple_mode, int, S_IRUGO|S_IWUSR); |
| 82 | MODULE_PARM_DESC(hpsa_simple_mode, |
| 83 | "Use 'simple mode' rather than 'performant mode'"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 84 | |
| 85 | /* define the PCI info for the cards we can control */ |
| 86 | static const struct pci_device_id hpsa_pci_device_id[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 87 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3241}, |
| 88 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3243}, |
| 89 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3245}, |
| 90 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3247}, |
| 91 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 92 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A}, |
| 93 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B}, |
Mike Miller | f8b01eb | 2010-02-04 08:42:45 -0600 | [diff] [blame] | 94 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3233}, |
scameron@beardog.cce.hp.com | 9143a96 | 2011-03-07 10:44:16 -0600 | [diff] [blame] | 95 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3350}, |
| 96 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3351}, |
| 97 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3352}, |
| 98 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3353}, |
| 99 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3354}, |
| 100 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3355}, |
| 101 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3356}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 102 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1921}, |
| 103 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1922}, |
| 104 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1923}, |
| 105 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1924}, |
| 106 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1925}, |
| 107 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1926}, |
| 108 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1928}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 109 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1929}, |
| 110 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BD}, |
| 111 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BE}, |
| 112 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BF}, |
| 113 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C0}, |
| 114 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C1}, |
| 115 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C2}, |
| 116 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C3}, |
| 117 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C4}, |
| 118 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C5}, |
| 119 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C7}, |
| 120 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C8}, |
| 121 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C9}, |
Mike Miller | 7c03b87 | 2010-12-01 11:16:07 -0600 | [diff] [blame] | 122 | {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
Stephen M. Cameron | 6798cc0 | 2010-06-16 13:51:20 -0500 | [diff] [blame] | 123 | PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 124 | {0,} |
| 125 | }; |
| 126 | |
| 127 | MODULE_DEVICE_TABLE(pci, hpsa_pci_device_id); |
| 128 | |
| 129 | /* board_id = Subsystem Device ID & Vendor ID |
| 130 | * product = Marketing Name for the board |
| 131 | * access = Address of the struct of function pointers |
| 132 | */ |
| 133 | static struct board_type products[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 134 | {0x3241103C, "Smart Array P212", &SA5_access}, |
| 135 | {0x3243103C, "Smart Array P410", &SA5_access}, |
| 136 | {0x3245103C, "Smart Array P410i", &SA5_access}, |
| 137 | {0x3247103C, "Smart Array P411", &SA5_access}, |
| 138 | {0x3249103C, "Smart Array P812", &SA5_access}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 139 | {0x324A103C, "Smart Array P712m", &SA5_access}, |
| 140 | {0x324B103C, "Smart Array P711m", &SA5_access}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 141 | {0x3350103C, "Smart Array P222", &SA5_access}, |
| 142 | {0x3351103C, "Smart Array P420", &SA5_access}, |
| 143 | {0x3352103C, "Smart Array P421", &SA5_access}, |
| 144 | {0x3353103C, "Smart Array P822", &SA5_access}, |
| 145 | {0x3354103C, "Smart Array P420i", &SA5_access}, |
| 146 | {0x3355103C, "Smart Array P220i", &SA5_access}, |
| 147 | {0x3356103C, "Smart Array P721m", &SA5_access}, |
Mike Miller | 1fd6c8e | 2013-09-04 15:08:29 -0500 | [diff] [blame] | 148 | {0x1921103C, "Smart Array P830i", &SA5_access}, |
| 149 | {0x1922103C, "Smart Array P430", &SA5_access}, |
| 150 | {0x1923103C, "Smart Array P431", &SA5_access}, |
| 151 | {0x1924103C, "Smart Array P830", &SA5_access}, |
| 152 | {0x1926103C, "Smart Array P731m", &SA5_access}, |
| 153 | {0x1928103C, "Smart Array P230i", &SA5_access}, |
| 154 | {0x1929103C, "Smart Array P530", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 155 | {0x21BD103C, "Smart Array", &SA5_access}, |
| 156 | {0x21BE103C, "Smart Array", &SA5_access}, |
| 157 | {0x21BF103C, "Smart Array", &SA5_access}, |
| 158 | {0x21C0103C, "Smart Array", &SA5_access}, |
| 159 | {0x21C1103C, "Smart Array", &SA5_access}, |
| 160 | {0x21C2103C, "Smart Array", &SA5_access}, |
| 161 | {0x21C3103C, "Smart Array", &SA5_access}, |
| 162 | {0x21C4103C, "Smart Array", &SA5_access}, |
| 163 | {0x21C5103C, "Smart Array", &SA5_access}, |
| 164 | {0x21C7103C, "Smart Array", &SA5_access}, |
| 165 | {0x21C8103C, "Smart Array", &SA5_access}, |
| 166 | {0x21C9103C, "Smart Array", &SA5_access}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 167 | {0xFFFF103C, "Unknown Smart Array", &SA5_access}, |
| 168 | }; |
| 169 | |
| 170 | static int number_of_controllers; |
| 171 | |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 172 | static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); |
| 173 | static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 174 | static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg); |
| 175 | static void start_io(struct ctlr_info *h); |
| 176 | |
| 177 | #ifdef CONFIG_COMPAT |
| 178 | static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void *arg); |
| 179 | #endif |
| 180 | |
| 181 | static void cmd_free(struct ctlr_info *h, struct CommandList *c); |
| 182 | static void cmd_special_free(struct ctlr_info *h, struct CommandList *c); |
| 183 | static struct CommandList *cmd_alloc(struct ctlr_info *h); |
| 184 | static struct CommandList *cmd_special_alloc(struct ctlr_info *h); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 185 | static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 186 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 187 | int cmd_type); |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 188 | #define VPD_PAGE (1 << 8) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 189 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 190 | static int hpsa_scsi_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 191 | static void hpsa_scan_start(struct Scsi_Host *); |
| 192 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 193 | unsigned long elapsed_time); |
Stephen M. Cameron | 667e23d | 2010-02-25 14:02:51 -0600 | [diff] [blame] | 194 | static int hpsa_change_queue_depth(struct scsi_device *sdev, |
| 195 | int qdepth, int reason); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 196 | |
| 197 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 198 | static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 199 | static int hpsa_slave_alloc(struct scsi_device *sdev); |
| 200 | static void hpsa_slave_destroy(struct scsi_device *sdev); |
| 201 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 202 | static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 203 | static int check_for_unit_attention(struct ctlr_info *h, |
| 204 | struct CommandList *c); |
| 205 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 206 | struct CommandList *c); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 207 | /* performant mode helper functions */ |
| 208 | static void calc_bucket_map(int *bucket, int num_buckets, |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 209 | int nsgs, int min_blocks, int *bucket_map); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 210 | static void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 211 | static inline u32 next_command(struct ctlr_info *h, u8 q); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 212 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 213 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 214 | u64 *cfg_offset); |
| 215 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 216 | unsigned long *memory_bar); |
| 217 | static int hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id); |
| 218 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 219 | int wait_for_ready); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 220 | static inline void finish_cmd(struct CommandList *c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 221 | static void hpsa_wait_for_mode_change_ack(struct ctlr_info *h); |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 222 | #define BOARD_NOT_READY 0 |
| 223 | #define BOARD_READY 1 |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 224 | static void hpsa_drain_accel_commands(struct ctlr_info *h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 225 | static void hpsa_flush_cache(struct ctlr_info *h); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 226 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 227 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
| 228 | u8 *scsi3addr); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 229 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 230 | static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev) |
| 231 | { |
| 232 | unsigned long *priv = shost_priv(sdev->host); |
| 233 | return (struct ctlr_info *) *priv; |
| 234 | } |
| 235 | |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 236 | static inline struct ctlr_info *shost_to_hba(struct Scsi_Host *sh) |
| 237 | { |
| 238 | unsigned long *priv = shost_priv(sh); |
| 239 | return (struct ctlr_info *) *priv; |
| 240 | } |
| 241 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 242 | static int check_for_unit_attention(struct ctlr_info *h, |
| 243 | struct CommandList *c) |
| 244 | { |
| 245 | if (c->err_info->SenseInfo[2] != UNIT_ATTENTION) |
| 246 | return 0; |
| 247 | |
| 248 | switch (c->err_info->SenseInfo[12]) { |
| 249 | case STATE_CHANGED: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 250 | dev_warn(&h->pdev->dev, HPSA "%d: a state change " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 251 | "detected, command retried\n", h->ctlr); |
| 252 | break; |
| 253 | case LUN_FAILED: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 254 | dev_warn(&h->pdev->dev, HPSA "%d: LUN failure " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 255 | "detected, action required\n", h->ctlr); |
| 256 | break; |
| 257 | case REPORT_LUNS_CHANGED: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 258 | dev_warn(&h->pdev->dev, HPSA "%d: report LUN data " |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 259 | "changed, action required\n", h->ctlr); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 260 | /* |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 261 | * Note: this REPORT_LUNS_CHANGED condition only occurs on the external |
| 262 | * target (array) devices. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 263 | */ |
| 264 | break; |
| 265 | case POWER_OR_RESET: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 266 | dev_warn(&h->pdev->dev, HPSA "%d: a power on " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 267 | "or device reset detected\n", h->ctlr); |
| 268 | break; |
| 269 | case UNIT_ATTENTION_CLEARED: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 270 | dev_warn(&h->pdev->dev, HPSA "%d: unit attention " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 271 | "cleared by another initiator\n", h->ctlr); |
| 272 | break; |
| 273 | default: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 274 | dev_warn(&h->pdev->dev, HPSA "%d: unknown " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 275 | "unit attention detected\n", h->ctlr); |
| 276 | break; |
| 277 | } |
| 278 | return 1; |
| 279 | } |
| 280 | |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 281 | static int check_for_busy(struct ctlr_info *h, struct CommandList *c) |
| 282 | { |
| 283 | if (c->err_info->CommandStatus != CMD_TARGET_STATUS || |
| 284 | (c->err_info->ScsiStatus != SAM_STAT_BUSY && |
| 285 | c->err_info->ScsiStatus != SAM_STAT_TASK_SET_FULL)) |
| 286 | return 0; |
| 287 | dev_warn(&h->pdev->dev, HPSA "device busy"); |
| 288 | return 1; |
| 289 | } |
| 290 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 291 | static ssize_t host_store_hp_ssd_smart_path_status(struct device *dev, |
| 292 | struct device_attribute *attr, |
| 293 | const char *buf, size_t count) |
| 294 | { |
| 295 | int status, len; |
| 296 | struct ctlr_info *h; |
| 297 | struct Scsi_Host *shost = class_to_shost(dev); |
| 298 | char tmpbuf[10]; |
| 299 | |
| 300 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 301 | return -EACCES; |
| 302 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 303 | strncpy(tmpbuf, buf, len); |
| 304 | tmpbuf[len] = '\0'; |
| 305 | if (sscanf(tmpbuf, "%d", &status) != 1) |
| 306 | return -EINVAL; |
| 307 | h = shost_to_hba(shost); |
| 308 | h->acciopath_status = !!status; |
| 309 | dev_warn(&h->pdev->dev, |
| 310 | "hpsa: HP SSD Smart Path %s via sysfs update.\n", |
| 311 | h->acciopath_status ? "enabled" : "disabled"); |
| 312 | return count; |
| 313 | } |
| 314 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 315 | static ssize_t host_store_raid_offload_debug(struct device *dev, |
| 316 | struct device_attribute *attr, |
| 317 | const char *buf, size_t count) |
| 318 | { |
| 319 | int debug_level, len; |
| 320 | struct ctlr_info *h; |
| 321 | struct Scsi_Host *shost = class_to_shost(dev); |
| 322 | char tmpbuf[10]; |
| 323 | |
| 324 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 325 | return -EACCES; |
| 326 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 327 | strncpy(tmpbuf, buf, len); |
| 328 | tmpbuf[len] = '\0'; |
| 329 | if (sscanf(tmpbuf, "%d", &debug_level) != 1) |
| 330 | return -EINVAL; |
| 331 | if (debug_level < 0) |
| 332 | debug_level = 0; |
| 333 | h = shost_to_hba(shost); |
| 334 | h->raid_offload_debug = debug_level; |
| 335 | dev_warn(&h->pdev->dev, "hpsa: Set raid_offload_debug level = %d\n", |
| 336 | h->raid_offload_debug); |
| 337 | return count; |
| 338 | } |
| 339 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 340 | static ssize_t host_store_rescan(struct device *dev, |
| 341 | struct device_attribute *attr, |
| 342 | const char *buf, size_t count) |
| 343 | { |
| 344 | struct ctlr_info *h; |
| 345 | struct Scsi_Host *shost = class_to_shost(dev); |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 346 | h = shost_to_hba(shost); |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 347 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 348 | return count; |
| 349 | } |
| 350 | |
Stephen M. Cameron | d28ce02 | 2010-05-27 15:14:34 -0500 | [diff] [blame] | 351 | static ssize_t host_show_firmware_revision(struct device *dev, |
| 352 | struct device_attribute *attr, char *buf) |
| 353 | { |
| 354 | struct ctlr_info *h; |
| 355 | struct Scsi_Host *shost = class_to_shost(dev); |
| 356 | unsigned char *fwrev; |
| 357 | |
| 358 | h = shost_to_hba(shost); |
| 359 | if (!h->hba_inquiry_data) |
| 360 | return 0; |
| 361 | fwrev = &h->hba_inquiry_data[32]; |
| 362 | return snprintf(buf, 20, "%c%c%c%c\n", |
| 363 | fwrev[0], fwrev[1], fwrev[2], fwrev[3]); |
| 364 | } |
| 365 | |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 366 | static ssize_t host_show_commands_outstanding(struct device *dev, |
| 367 | struct device_attribute *attr, char *buf) |
| 368 | { |
| 369 | struct Scsi_Host *shost = class_to_shost(dev); |
| 370 | struct ctlr_info *h = shost_to_hba(shost); |
| 371 | |
| 372 | return snprintf(buf, 20, "%d\n", h->commands_outstanding); |
| 373 | } |
| 374 | |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 375 | static ssize_t host_show_transport_mode(struct device *dev, |
| 376 | struct device_attribute *attr, char *buf) |
| 377 | { |
| 378 | struct ctlr_info *h; |
| 379 | struct Scsi_Host *shost = class_to_shost(dev); |
| 380 | |
| 381 | h = shost_to_hba(shost); |
| 382 | return snprintf(buf, 20, "%s\n", |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 383 | h->transMethod & CFGTBL_Trans_Performant ? |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 384 | "performant" : "simple"); |
| 385 | } |
| 386 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 387 | static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev, |
| 388 | struct device_attribute *attr, char *buf) |
| 389 | { |
| 390 | struct ctlr_info *h; |
| 391 | struct Scsi_Host *shost = class_to_shost(dev); |
| 392 | |
| 393 | h = shost_to_hba(shost); |
| 394 | return snprintf(buf, 30, "HP SSD Smart Path %s\n", |
| 395 | (h->acciopath_status == 1) ? "enabled" : "disabled"); |
| 396 | } |
| 397 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 398 | /* List of controllers which cannot be hard reset on kexec with reset_devices */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 399 | static u32 unresettable_controller[] = { |
| 400 | 0x324a103C, /* Smart Array P712m */ |
| 401 | 0x324b103C, /* SmartArray P711m */ |
| 402 | 0x3223103C, /* Smart Array P800 */ |
| 403 | 0x3234103C, /* Smart Array P400 */ |
| 404 | 0x3235103C, /* Smart Array P400i */ |
| 405 | 0x3211103C, /* Smart Array E200i */ |
| 406 | 0x3212103C, /* Smart Array E200 */ |
| 407 | 0x3213103C, /* Smart Array E200i */ |
| 408 | 0x3214103C, /* Smart Array E200i */ |
| 409 | 0x3215103C, /* Smart Array E200i */ |
| 410 | 0x3237103C, /* Smart Array E500 */ |
| 411 | 0x323D103C, /* Smart Array P700m */ |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 412 | 0x40800E11, /* Smart Array 5i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 413 | 0x409C0E11, /* Smart Array 6400 */ |
| 414 | 0x409D0E11, /* Smart Array 6400 EM */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 415 | 0x40700E11, /* Smart Array 5300 */ |
| 416 | 0x40820E11, /* Smart Array 532 */ |
| 417 | 0x40830E11, /* Smart Array 5312 */ |
| 418 | 0x409A0E11, /* Smart Array 641 */ |
| 419 | 0x409B0E11, /* Smart Array 642 */ |
| 420 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 421 | }; |
| 422 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 423 | /* List of controllers which cannot even be soft reset */ |
| 424 | static u32 soft_unresettable_controller[] = { |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 425 | 0x40800E11, /* Smart Array 5i */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 426 | 0x40700E11, /* Smart Array 5300 */ |
| 427 | 0x40820E11, /* Smart Array 532 */ |
| 428 | 0x40830E11, /* Smart Array 5312 */ |
| 429 | 0x409A0E11, /* Smart Array 641 */ |
| 430 | 0x409B0E11, /* Smart Array 642 */ |
| 431 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 432 | /* Exclude 640x boards. These are two pci devices in one slot |
| 433 | * which share a battery backed cache module. One controls the |
| 434 | * cache, the other accesses the cache through the one that controls |
| 435 | * it. If we reset the one controlling the cache, the other will |
| 436 | * likely not be happy. Just forbid resetting this conjoined mess. |
| 437 | * The 640x isn't really supported by hpsa anyway. |
| 438 | */ |
| 439 | 0x409C0E11, /* Smart Array 6400 */ |
| 440 | 0x409D0E11, /* Smart Array 6400 EM */ |
| 441 | }; |
| 442 | |
| 443 | static int ctlr_is_hard_resettable(u32 board_id) |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 444 | { |
| 445 | int i; |
| 446 | |
| 447 | for (i = 0; i < ARRAY_SIZE(unresettable_controller); i++) |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 448 | if (unresettable_controller[i] == board_id) |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 449 | return 0; |
| 450 | return 1; |
| 451 | } |
| 452 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 453 | static int ctlr_is_soft_resettable(u32 board_id) |
| 454 | { |
| 455 | int i; |
| 456 | |
| 457 | for (i = 0; i < ARRAY_SIZE(soft_unresettable_controller); i++) |
| 458 | if (soft_unresettable_controller[i] == board_id) |
| 459 | return 0; |
| 460 | return 1; |
| 461 | } |
| 462 | |
| 463 | static int ctlr_is_resettable(u32 board_id) |
| 464 | { |
| 465 | return ctlr_is_hard_resettable(board_id) || |
| 466 | ctlr_is_soft_resettable(board_id); |
| 467 | } |
| 468 | |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 469 | static ssize_t host_show_resettable(struct device *dev, |
| 470 | struct device_attribute *attr, char *buf) |
| 471 | { |
| 472 | struct ctlr_info *h; |
| 473 | struct Scsi_Host *shost = class_to_shost(dev); |
| 474 | |
| 475 | h = shost_to_hba(shost); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 476 | return snprintf(buf, 20, "%d\n", ctlr_is_resettable(h->board_id)); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 477 | } |
| 478 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 479 | static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[]) |
| 480 | { |
| 481 | return (scsi3addr[3] & 0xC0) == 0x40; |
| 482 | } |
| 483 | |
| 484 | static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", |
Mike Miller | d82357e | 2012-05-01 11:43:32 -0500 | [diff] [blame] | 485 | "1(ADM)", "UNKNOWN" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 486 | }; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 487 | #define HPSA_RAID_0 0 |
| 488 | #define HPSA_RAID_4 1 |
| 489 | #define HPSA_RAID_1 2 /* also used for RAID 10 */ |
| 490 | #define HPSA_RAID_5 3 /* also used for RAID 50 */ |
| 491 | #define HPSA_RAID_51 4 |
| 492 | #define HPSA_RAID_6 5 /* also used for RAID 60 */ |
| 493 | #define HPSA_RAID_ADM 6 /* also used for RAID 1+0 ADM */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 494 | #define RAID_UNKNOWN (ARRAY_SIZE(raid_label) - 1) |
| 495 | |
| 496 | static ssize_t raid_level_show(struct device *dev, |
| 497 | struct device_attribute *attr, char *buf) |
| 498 | { |
| 499 | ssize_t l = 0; |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 500 | unsigned char rlevel; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 501 | struct ctlr_info *h; |
| 502 | struct scsi_device *sdev; |
| 503 | struct hpsa_scsi_dev_t *hdev; |
| 504 | unsigned long flags; |
| 505 | |
| 506 | sdev = to_scsi_device(dev); |
| 507 | h = sdev_to_hba(sdev); |
| 508 | spin_lock_irqsave(&h->lock, flags); |
| 509 | hdev = sdev->hostdata; |
| 510 | if (!hdev) { |
| 511 | spin_unlock_irqrestore(&h->lock, flags); |
| 512 | return -ENODEV; |
| 513 | } |
| 514 | |
| 515 | /* Is this even a logical drive? */ |
| 516 | if (!is_logical_dev_addr_mode(hdev->scsi3addr)) { |
| 517 | spin_unlock_irqrestore(&h->lock, flags); |
| 518 | l = snprintf(buf, PAGE_SIZE, "N/A\n"); |
| 519 | return l; |
| 520 | } |
| 521 | |
| 522 | rlevel = hdev->raid_level; |
| 523 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 524 | if (rlevel > RAID_UNKNOWN) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 525 | rlevel = RAID_UNKNOWN; |
| 526 | l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]); |
| 527 | return l; |
| 528 | } |
| 529 | |
| 530 | static ssize_t lunid_show(struct device *dev, |
| 531 | struct device_attribute *attr, char *buf) |
| 532 | { |
| 533 | struct ctlr_info *h; |
| 534 | struct scsi_device *sdev; |
| 535 | struct hpsa_scsi_dev_t *hdev; |
| 536 | unsigned long flags; |
| 537 | unsigned char lunid[8]; |
| 538 | |
| 539 | sdev = to_scsi_device(dev); |
| 540 | h = sdev_to_hba(sdev); |
| 541 | spin_lock_irqsave(&h->lock, flags); |
| 542 | hdev = sdev->hostdata; |
| 543 | if (!hdev) { |
| 544 | spin_unlock_irqrestore(&h->lock, flags); |
| 545 | return -ENODEV; |
| 546 | } |
| 547 | memcpy(lunid, hdev->scsi3addr, sizeof(lunid)); |
| 548 | spin_unlock_irqrestore(&h->lock, flags); |
| 549 | return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 550 | lunid[0], lunid[1], lunid[2], lunid[3], |
| 551 | lunid[4], lunid[5], lunid[6], lunid[7]); |
| 552 | } |
| 553 | |
| 554 | static ssize_t unique_id_show(struct device *dev, |
| 555 | struct device_attribute *attr, char *buf) |
| 556 | { |
| 557 | struct ctlr_info *h; |
| 558 | struct scsi_device *sdev; |
| 559 | struct hpsa_scsi_dev_t *hdev; |
| 560 | unsigned long flags; |
| 561 | unsigned char sn[16]; |
| 562 | |
| 563 | sdev = to_scsi_device(dev); |
| 564 | h = sdev_to_hba(sdev); |
| 565 | spin_lock_irqsave(&h->lock, flags); |
| 566 | hdev = sdev->hostdata; |
| 567 | if (!hdev) { |
| 568 | spin_unlock_irqrestore(&h->lock, flags); |
| 569 | return -ENODEV; |
| 570 | } |
| 571 | memcpy(sn, hdev->device_id, sizeof(sn)); |
| 572 | spin_unlock_irqrestore(&h->lock, flags); |
| 573 | return snprintf(buf, 16 * 2 + 2, |
| 574 | "%02X%02X%02X%02X%02X%02X%02X%02X" |
| 575 | "%02X%02X%02X%02X%02X%02X%02X%02X\n", |
| 576 | sn[0], sn[1], sn[2], sn[3], |
| 577 | sn[4], sn[5], sn[6], sn[7], |
| 578 | sn[8], sn[9], sn[10], sn[11], |
| 579 | sn[12], sn[13], sn[14], sn[15]); |
| 580 | } |
| 581 | |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 582 | static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev, |
| 583 | struct device_attribute *attr, char *buf) |
| 584 | { |
| 585 | struct ctlr_info *h; |
| 586 | struct scsi_device *sdev; |
| 587 | struct hpsa_scsi_dev_t *hdev; |
| 588 | unsigned long flags; |
| 589 | int offload_enabled; |
| 590 | |
| 591 | sdev = to_scsi_device(dev); |
| 592 | h = sdev_to_hba(sdev); |
| 593 | spin_lock_irqsave(&h->lock, flags); |
| 594 | hdev = sdev->hostdata; |
| 595 | if (!hdev) { |
| 596 | spin_unlock_irqrestore(&h->lock, flags); |
| 597 | return -ENODEV; |
| 598 | } |
| 599 | offload_enabled = hdev->offload_enabled; |
| 600 | spin_unlock_irqrestore(&h->lock, flags); |
| 601 | return snprintf(buf, 20, "%d\n", offload_enabled); |
| 602 | } |
| 603 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 604 | static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL); |
| 605 | static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL); |
| 606 | static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL); |
| 607 | static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 608 | static DEVICE_ATTR(hp_ssd_smart_path_enabled, S_IRUGO, |
| 609 | host_show_hp_ssd_smart_path_enabled, NULL); |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 610 | static DEVICE_ATTR(hp_ssd_smart_path_status, S_IWUSR|S_IRUGO|S_IROTH, |
| 611 | host_show_hp_ssd_smart_path_status, |
| 612 | host_store_hp_ssd_smart_path_status); |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 613 | static DEVICE_ATTR(raid_offload_debug, S_IWUSR, NULL, |
| 614 | host_store_raid_offload_debug); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 615 | static DEVICE_ATTR(firmware_revision, S_IRUGO, |
| 616 | host_show_firmware_revision, NULL); |
| 617 | static DEVICE_ATTR(commands_outstanding, S_IRUGO, |
| 618 | host_show_commands_outstanding, NULL); |
| 619 | static DEVICE_ATTR(transport_mode, S_IRUGO, |
| 620 | host_show_transport_mode, NULL); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 621 | static DEVICE_ATTR(resettable, S_IRUGO, |
| 622 | host_show_resettable, NULL); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 623 | |
| 624 | static struct device_attribute *hpsa_sdev_attrs[] = { |
| 625 | &dev_attr_raid_level, |
| 626 | &dev_attr_lunid, |
| 627 | &dev_attr_unique_id, |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 628 | &dev_attr_hp_ssd_smart_path_enabled, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 629 | NULL, |
| 630 | }; |
| 631 | |
| 632 | static struct device_attribute *hpsa_shost_attrs[] = { |
| 633 | &dev_attr_rescan, |
| 634 | &dev_attr_firmware_revision, |
| 635 | &dev_attr_commands_outstanding, |
| 636 | &dev_attr_transport_mode, |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 637 | &dev_attr_resettable, |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 638 | &dev_attr_hp_ssd_smart_path_status, |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 639 | &dev_attr_raid_offload_debug, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 640 | NULL, |
| 641 | }; |
| 642 | |
| 643 | static struct scsi_host_template hpsa_driver_template = { |
| 644 | .module = THIS_MODULE, |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 645 | .name = HPSA, |
| 646 | .proc_name = HPSA, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 647 | .queuecommand = hpsa_scsi_queue_command, |
| 648 | .scan_start = hpsa_scan_start, |
| 649 | .scan_finished = hpsa_scan_finished, |
| 650 | .change_queue_depth = hpsa_change_queue_depth, |
| 651 | .this_id = -1, |
| 652 | .use_clustering = ENABLE_CLUSTERING, |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 653 | .eh_abort_handler = hpsa_eh_abort_handler, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 654 | .eh_device_reset_handler = hpsa_eh_device_reset_handler, |
| 655 | .ioctl = hpsa_ioctl, |
| 656 | .slave_alloc = hpsa_slave_alloc, |
| 657 | .slave_destroy = hpsa_slave_destroy, |
| 658 | #ifdef CONFIG_COMPAT |
| 659 | .compat_ioctl = hpsa_compat_ioctl, |
| 660 | #endif |
| 661 | .sdev_attrs = hpsa_sdev_attrs, |
| 662 | .shost_attrs = hpsa_shost_attrs, |
Stephen M. Cameron | c0d6a4d | 2011-10-26 16:20:53 -0500 | [diff] [blame] | 663 | .max_sectors = 8192, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 664 | .no_write_same = 1, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | |
| 668 | /* Enqueuing and dequeuing functions for cmdlists. */ |
| 669 | static inline void addQ(struct list_head *list, struct CommandList *c) |
| 670 | { |
| 671 | list_add_tail(&c->list, list); |
| 672 | } |
| 673 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 674 | static inline u32 next_command(struct ctlr_info *h, u8 q) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 675 | { |
| 676 | u32 a; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 677 | struct reply_pool *rq = &h->reply_queue[q]; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 678 | unsigned long flags; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 679 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 680 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 681 | return h->access.command_completed(h, q); |
| 682 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 683 | if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 684 | return h->access.command_completed(h, q); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 685 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 686 | if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { |
| 687 | a = rq->head[rq->current_entry]; |
| 688 | rq->current_entry++; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 689 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 690 | h->commands_outstanding--; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 691 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 692 | } else { |
| 693 | a = FIFO_EMPTY; |
| 694 | } |
| 695 | /* Check for wraparound */ |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 696 | if (rq->current_entry == h->max_commands) { |
| 697 | rq->current_entry = 0; |
| 698 | rq->wraparound ^= 1; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 699 | } |
| 700 | return a; |
| 701 | } |
| 702 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 703 | /* |
| 704 | * There are some special bits in the bus address of the |
| 705 | * command that we have to set for the controller to know |
| 706 | * how to process the command: |
| 707 | * |
| 708 | * Normal performant mode: |
| 709 | * bit 0: 1 means performant mode, 0 means simple mode. |
| 710 | * bits 1-3 = block fetch table entry |
| 711 | * bits 4-6 = command type (== 0) |
| 712 | * |
| 713 | * ioaccel1 mode: |
| 714 | * bit 0 = "performant mode" bit. |
| 715 | * bits 1-3 = block fetch table entry |
| 716 | * bits 4-6 = command type (== 110) |
| 717 | * (command type is needed because ioaccel1 mode |
| 718 | * commands are submitted through the same register as normal |
| 719 | * mode commands, so this is how the controller knows whether |
| 720 | * the command is normal mode or ioaccel1 mode.) |
| 721 | * |
| 722 | * ioaccel2 mode: |
| 723 | * bit 0 = "performant mode" bit. |
| 724 | * bits 1-4 = block fetch table entry (note extra bit) |
| 725 | * bits 4-6 = not needed, because ioaccel2 mode has |
| 726 | * a separate special register for submitting commands. |
| 727 | */ |
| 728 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 729 | /* set_performant_mode: Modify the tag for cciss performant |
| 730 | * set bit 0 for pull model, bits 3-1 for block fetch |
| 731 | * register number |
| 732 | */ |
| 733 | static void set_performant_mode(struct ctlr_info *h, struct CommandList *c) |
| 734 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 735 | if (likely(h->transMethod & CFGTBL_Trans_Performant)) { |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 736 | c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 737 | if (likely(h->msix_vector > 0)) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 738 | c->Header.ReplyQueue = |
John Kacur | 804a5cb | 2013-07-26 16:06:18 +0200 | [diff] [blame] | 739 | raw_smp_processor_id() % h->nreply_queues; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 740 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 741 | } |
| 742 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 743 | static void set_ioaccel1_performant_mode(struct ctlr_info *h, |
| 744 | struct CommandList *c) |
| 745 | { |
| 746 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 747 | |
| 748 | /* Tell the controller to post the reply to the queue for this |
| 749 | * processor. This seems to give the best I/O throughput. |
| 750 | */ |
| 751 | cp->ReplyQueue = smp_processor_id() % h->nreply_queues; |
| 752 | /* Set the bits in the address sent down to include: |
| 753 | * - performant mode bit (bit 0) |
| 754 | * - pull count (bits 1-3) |
| 755 | * - command type (bits 4-6) |
| 756 | */ |
| 757 | c->busaddr |= 1 | (h->ioaccel1_blockFetchTable[c->Header.SGList] << 1) | |
| 758 | IOACCEL1_BUSADDR_CMDTYPE; |
| 759 | } |
| 760 | |
| 761 | static void set_ioaccel2_performant_mode(struct ctlr_info *h, |
| 762 | struct CommandList *c) |
| 763 | { |
| 764 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 765 | |
| 766 | /* Tell the controller to post the reply to the queue for this |
| 767 | * processor. This seems to give the best I/O throughput. |
| 768 | */ |
| 769 | cp->reply_queue = smp_processor_id() % h->nreply_queues; |
| 770 | /* Set the bits in the address sent down to include: |
| 771 | * - performant mode bit not used in ioaccel mode 2 |
| 772 | * - pull count (bits 0-3) |
| 773 | * - command type isn't needed for ioaccel2 |
| 774 | */ |
| 775 | c->busaddr |= (h->ioaccel2_blockFetchTable[cp->sg_count]); |
| 776 | } |
| 777 | |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 778 | static int is_firmware_flash_cmd(u8 *cdb) |
| 779 | { |
| 780 | return cdb[0] == BMIC_WRITE && cdb[6] == BMIC_FLASH_FIRMWARE; |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 | * During firmware flash, the heartbeat register may not update as frequently |
| 785 | * as it should. So we dial down lockup detection during firmware flash. and |
| 786 | * dial it back up when firmware flash completes. |
| 787 | */ |
| 788 | #define HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH (240 * HZ) |
| 789 | #define HEARTBEAT_SAMPLE_INTERVAL (30 * HZ) |
| 790 | static void dial_down_lockup_detection_during_fw_flash(struct ctlr_info *h, |
| 791 | struct CommandList *c) |
| 792 | { |
| 793 | if (!is_firmware_flash_cmd(c->Request.CDB)) |
| 794 | return; |
| 795 | atomic_inc(&h->firmware_flash_in_progress); |
| 796 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH; |
| 797 | } |
| 798 | |
| 799 | static void dial_up_lockup_detection_on_fw_flash_complete(struct ctlr_info *h, |
| 800 | struct CommandList *c) |
| 801 | { |
| 802 | if (is_firmware_flash_cmd(c->Request.CDB) && |
| 803 | atomic_dec_and_test(&h->firmware_flash_in_progress)) |
| 804 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 805 | } |
| 806 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 807 | static void enqueue_cmd_and_start_io(struct ctlr_info *h, |
| 808 | struct CommandList *c) |
| 809 | { |
| 810 | unsigned long flags; |
| 811 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 812 | switch (c->cmd_type) { |
| 813 | case CMD_IOACCEL1: |
| 814 | set_ioaccel1_performant_mode(h, c); |
| 815 | break; |
| 816 | case CMD_IOACCEL2: |
| 817 | set_ioaccel2_performant_mode(h, c); |
| 818 | break; |
| 819 | default: |
| 820 | set_performant_mode(h, c); |
| 821 | } |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 822 | dial_down_lockup_detection_during_fw_flash(h, c); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 823 | spin_lock_irqsave(&h->lock, flags); |
| 824 | addQ(&h->reqQ, c); |
| 825 | h->Qdepth++; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 826 | spin_unlock_irqrestore(&h->lock, flags); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 827 | start_io(h); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static inline void removeQ(struct CommandList *c) |
| 831 | { |
| 832 | if (WARN_ON(list_empty(&c->list))) |
| 833 | return; |
| 834 | list_del_init(&c->list); |
| 835 | } |
| 836 | |
| 837 | static inline int is_hba_lunid(unsigned char scsi3addr[]) |
| 838 | { |
| 839 | return memcmp(scsi3addr, RAID_CTLR_LUNID, 8) == 0; |
| 840 | } |
| 841 | |
| 842 | static inline int is_scsi_rev_5(struct ctlr_info *h) |
| 843 | { |
| 844 | if (!h->hba_inquiry_data) |
| 845 | return 0; |
| 846 | if ((h->hba_inquiry_data[2] & 0x07) == 5) |
| 847 | return 1; |
| 848 | return 0; |
| 849 | } |
| 850 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 851 | static int hpsa_find_target_lun(struct ctlr_info *h, |
| 852 | unsigned char scsi3addr[], int bus, int *target, int *lun) |
| 853 | { |
| 854 | /* finds an unused bus, target, lun for a new physical device |
| 855 | * assumes h->devlock is held |
| 856 | */ |
| 857 | int i, found = 0; |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 858 | DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 859 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 860 | bitmap_zero(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 861 | |
| 862 | for (i = 0; i < h->ndevices; i++) { |
| 863 | if (h->dev[i]->bus == bus && h->dev[i]->target != -1) |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 864 | __set_bit(h->dev[i]->target, lun_taken); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 865 | } |
| 866 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 867 | i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES); |
| 868 | if (i < HPSA_MAX_DEVICES) { |
| 869 | /* *bus = 1; */ |
| 870 | *target = i; |
| 871 | *lun = 0; |
| 872 | found = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 873 | } |
| 874 | return !found; |
| 875 | } |
| 876 | |
| 877 | /* Add an entry into h->dev[] array. */ |
| 878 | static int hpsa_scsi_add_entry(struct ctlr_info *h, int hostno, |
| 879 | struct hpsa_scsi_dev_t *device, |
| 880 | struct hpsa_scsi_dev_t *added[], int *nadded) |
| 881 | { |
| 882 | /* assumes h->devlock is held */ |
| 883 | int n = h->ndevices; |
| 884 | int i; |
| 885 | unsigned char addr1[8], addr2[8]; |
| 886 | struct hpsa_scsi_dev_t *sd; |
| 887 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 888 | if (n >= HPSA_MAX_DEVICES) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 889 | dev_err(&h->pdev->dev, "too many devices, some will be " |
| 890 | "inaccessible.\n"); |
| 891 | return -1; |
| 892 | } |
| 893 | |
| 894 | /* physical devices do not have lun or target assigned until now. */ |
| 895 | if (device->lun != -1) |
| 896 | /* Logical device, lun is already assigned. */ |
| 897 | goto lun_assigned; |
| 898 | |
| 899 | /* If this device a non-zero lun of a multi-lun device |
| 900 | * byte 4 of the 8-byte LUN addr will contain the logical |
| 901 | * unit no, zero otherise. |
| 902 | */ |
| 903 | if (device->scsi3addr[4] == 0) { |
| 904 | /* This is not a non-zero lun of a multi-lun device */ |
| 905 | if (hpsa_find_target_lun(h, device->scsi3addr, |
| 906 | device->bus, &device->target, &device->lun) != 0) |
| 907 | return -1; |
| 908 | goto lun_assigned; |
| 909 | } |
| 910 | |
| 911 | /* This is a non-zero lun of a multi-lun device. |
| 912 | * Search through our list and find the device which |
| 913 | * has the same 8 byte LUN address, excepting byte 4. |
| 914 | * Assign the same bus and target for this new LUN. |
| 915 | * Use the logical unit number from the firmware. |
| 916 | */ |
| 917 | memcpy(addr1, device->scsi3addr, 8); |
| 918 | addr1[4] = 0; |
| 919 | for (i = 0; i < n; i++) { |
| 920 | sd = h->dev[i]; |
| 921 | memcpy(addr2, sd->scsi3addr, 8); |
| 922 | addr2[4] = 0; |
| 923 | /* differ only in byte 4? */ |
| 924 | if (memcmp(addr1, addr2, 8) == 0) { |
| 925 | device->bus = sd->bus; |
| 926 | device->target = sd->target; |
| 927 | device->lun = device->scsi3addr[4]; |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | if (device->lun == -1) { |
| 932 | dev_warn(&h->pdev->dev, "physical device with no LUN=0," |
| 933 | " suspect firmware bug or unsupported hardware " |
| 934 | "configuration.\n"); |
| 935 | return -1; |
| 936 | } |
| 937 | |
| 938 | lun_assigned: |
| 939 | |
| 940 | h->dev[n] = device; |
| 941 | h->ndevices++; |
| 942 | added[*nadded] = device; |
| 943 | (*nadded)++; |
| 944 | |
| 945 | /* initially, (before registering with scsi layer) we don't |
| 946 | * know our hostno and we don't want to print anything first |
| 947 | * time anyway (the scsi layer's inquiries will show that info) |
| 948 | */ |
| 949 | /* if (hostno != -1) */ |
| 950 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d added.\n", |
| 951 | scsi_device_type(device->devtype), hostno, |
| 952 | device->bus, device->target, device->lun); |
| 953 | return 0; |
| 954 | } |
| 955 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 956 | /* Update an entry in h->dev[] array. */ |
| 957 | static void hpsa_scsi_update_entry(struct ctlr_info *h, int hostno, |
| 958 | int entry, struct hpsa_scsi_dev_t *new_entry) |
| 959 | { |
| 960 | /* assumes h->devlock is held */ |
| 961 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
| 962 | |
| 963 | /* Raid level changed. */ |
| 964 | h->dev[entry]->raid_level = new_entry->raid_level; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 965 | |
| 966 | /* Raid offload parameters changed. */ |
| 967 | h->dev[entry]->offload_config = new_entry->offload_config; |
| 968 | h->dev[entry]->offload_enabled = new_entry->offload_enabled; |
Stephen M. Cameron | 9fb0de2 | 2014-02-18 13:56:50 -0600 | [diff] [blame] | 969 | h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle; |
| 970 | h->dev[entry]->offload_to_mirror = new_entry->offload_to_mirror; |
| 971 | h->dev[entry]->raid_map = new_entry->raid_map; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 972 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 973 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d updated.\n", |
| 974 | scsi_device_type(new_entry->devtype), hostno, new_entry->bus, |
| 975 | new_entry->target, new_entry->lun); |
| 976 | } |
| 977 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 978 | /* Replace an entry from h->dev[] array. */ |
| 979 | static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno, |
| 980 | int entry, struct hpsa_scsi_dev_t *new_entry, |
| 981 | struct hpsa_scsi_dev_t *added[], int *nadded, |
| 982 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 983 | { |
| 984 | /* assumes h->devlock is held */ |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 985 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 986 | removed[*nremoved] = h->dev[entry]; |
| 987 | (*nremoved)++; |
Stephen M. Cameron | 01350d0 | 2011-08-09 08:18:01 -0500 | [diff] [blame] | 988 | |
| 989 | /* |
| 990 | * New physical devices won't have target/lun assigned yet |
| 991 | * so we need to preserve the values in the slot we are replacing. |
| 992 | */ |
| 993 | if (new_entry->target == -1) { |
| 994 | new_entry->target = h->dev[entry]->target; |
| 995 | new_entry->lun = h->dev[entry]->lun; |
| 996 | } |
| 997 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 998 | h->dev[entry] = new_entry; |
| 999 | added[*nadded] = new_entry; |
| 1000 | (*nadded)++; |
| 1001 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d changed.\n", |
| 1002 | scsi_device_type(new_entry->devtype), hostno, new_entry->bus, |
| 1003 | new_entry->target, new_entry->lun); |
| 1004 | } |
| 1005 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1006 | /* Remove an entry from h->dev[] array. */ |
| 1007 | static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry, |
| 1008 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1009 | { |
| 1010 | /* assumes h->devlock is held */ |
| 1011 | int i; |
| 1012 | struct hpsa_scsi_dev_t *sd; |
| 1013 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1014 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1015 | |
| 1016 | sd = h->dev[entry]; |
| 1017 | removed[*nremoved] = h->dev[entry]; |
| 1018 | (*nremoved)++; |
| 1019 | |
| 1020 | for (i = entry; i < h->ndevices-1; i++) |
| 1021 | h->dev[i] = h->dev[i+1]; |
| 1022 | h->ndevices--; |
| 1023 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d removed.\n", |
| 1024 | scsi_device_type(sd->devtype), hostno, sd->bus, sd->target, |
| 1025 | sd->lun); |
| 1026 | } |
| 1027 | |
| 1028 | #define SCSI3ADDR_EQ(a, b) ( \ |
| 1029 | (a)[7] == (b)[7] && \ |
| 1030 | (a)[6] == (b)[6] && \ |
| 1031 | (a)[5] == (b)[5] && \ |
| 1032 | (a)[4] == (b)[4] && \ |
| 1033 | (a)[3] == (b)[3] && \ |
| 1034 | (a)[2] == (b)[2] && \ |
| 1035 | (a)[1] == (b)[1] && \ |
| 1036 | (a)[0] == (b)[0]) |
| 1037 | |
| 1038 | static void fixup_botched_add(struct ctlr_info *h, |
| 1039 | struct hpsa_scsi_dev_t *added) |
| 1040 | { |
| 1041 | /* called when scsi_add_device fails in order to re-adjust |
| 1042 | * h->dev[] to match the mid layer's view. |
| 1043 | */ |
| 1044 | unsigned long flags; |
| 1045 | int i, j; |
| 1046 | |
| 1047 | spin_lock_irqsave(&h->lock, flags); |
| 1048 | for (i = 0; i < h->ndevices; i++) { |
| 1049 | if (h->dev[i] == added) { |
| 1050 | for (j = i; j < h->ndevices-1; j++) |
| 1051 | h->dev[j] = h->dev[j+1]; |
| 1052 | h->ndevices--; |
| 1053 | break; |
| 1054 | } |
| 1055 | } |
| 1056 | spin_unlock_irqrestore(&h->lock, flags); |
| 1057 | kfree(added); |
| 1058 | } |
| 1059 | |
| 1060 | static inline int device_is_the_same(struct hpsa_scsi_dev_t *dev1, |
| 1061 | struct hpsa_scsi_dev_t *dev2) |
| 1062 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1063 | /* we compare everything except lun and target as these |
| 1064 | * are not yet assigned. Compare parts likely |
| 1065 | * to differ first |
| 1066 | */ |
| 1067 | if (memcmp(dev1->scsi3addr, dev2->scsi3addr, |
| 1068 | sizeof(dev1->scsi3addr)) != 0) |
| 1069 | return 0; |
| 1070 | if (memcmp(dev1->device_id, dev2->device_id, |
| 1071 | sizeof(dev1->device_id)) != 0) |
| 1072 | return 0; |
| 1073 | if (memcmp(dev1->model, dev2->model, sizeof(dev1->model)) != 0) |
| 1074 | return 0; |
| 1075 | if (memcmp(dev1->vendor, dev2->vendor, sizeof(dev1->vendor)) != 0) |
| 1076 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1077 | if (dev1->devtype != dev2->devtype) |
| 1078 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1079 | if (dev1->bus != dev2->bus) |
| 1080 | return 0; |
| 1081 | return 1; |
| 1082 | } |
| 1083 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1084 | static inline int device_updated(struct hpsa_scsi_dev_t *dev1, |
| 1085 | struct hpsa_scsi_dev_t *dev2) |
| 1086 | { |
| 1087 | /* Device attributes that can change, but don't mean |
| 1088 | * that the device is a different device, nor that the OS |
| 1089 | * needs to be told anything about the change. |
| 1090 | */ |
| 1091 | if (dev1->raid_level != dev2->raid_level) |
| 1092 | return 1; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1093 | if (dev1->offload_config != dev2->offload_config) |
| 1094 | return 1; |
| 1095 | if (dev1->offload_enabled != dev2->offload_enabled) |
| 1096 | return 1; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1097 | return 0; |
| 1098 | } |
| 1099 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1100 | /* Find needle in haystack. If exact match found, return DEVICE_SAME, |
| 1101 | * and return needle location in *index. If scsi3addr matches, but not |
| 1102 | * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1103 | * location in *index. |
| 1104 | * In the case of a minor device attribute change, such as RAID level, just |
| 1105 | * return DEVICE_UPDATED, along with the updated device's location in index. |
| 1106 | * If needle not found, return DEVICE_NOT_FOUND. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1107 | */ |
| 1108 | static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle, |
| 1109 | struct hpsa_scsi_dev_t *haystack[], int haystack_size, |
| 1110 | int *index) |
| 1111 | { |
| 1112 | int i; |
| 1113 | #define DEVICE_NOT_FOUND 0 |
| 1114 | #define DEVICE_CHANGED 1 |
| 1115 | #define DEVICE_SAME 2 |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1116 | #define DEVICE_UPDATED 3 |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1117 | for (i = 0; i < haystack_size; i++) { |
Stephen M. Cameron | 2323104 | 2010-02-04 08:43:36 -0600 | [diff] [blame] | 1118 | if (haystack[i] == NULL) /* previously removed. */ |
| 1119 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1120 | if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) { |
| 1121 | *index = i; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1122 | if (device_is_the_same(needle, haystack[i])) { |
| 1123 | if (device_updated(needle, haystack[i])) |
| 1124 | return DEVICE_UPDATED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1125 | return DEVICE_SAME; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1126 | } else { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1127 | return DEVICE_CHANGED; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1128 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | *index = -1; |
| 1132 | return DEVICE_NOT_FOUND; |
| 1133 | } |
| 1134 | |
Stephen M. Cameron | 4967bd3 | 2010-02-04 08:41:49 -0600 | [diff] [blame] | 1135 | static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1136 | struct hpsa_scsi_dev_t *sd[], int nsds) |
| 1137 | { |
| 1138 | /* sd contains scsi3 addresses and devtypes, and inquiry |
| 1139 | * data. This function takes what's in sd to be the current |
| 1140 | * reality and updates h->dev[] to reflect that reality. |
| 1141 | */ |
| 1142 | int i, entry, device_change, changes = 0; |
| 1143 | struct hpsa_scsi_dev_t *csd; |
| 1144 | unsigned long flags; |
| 1145 | struct hpsa_scsi_dev_t **added, **removed; |
| 1146 | int nadded, nremoved; |
| 1147 | struct Scsi_Host *sh = NULL; |
| 1148 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1149 | added = kzalloc(sizeof(*added) * HPSA_MAX_DEVICES, GFP_KERNEL); |
| 1150 | removed = kzalloc(sizeof(*removed) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1151 | |
| 1152 | if (!added || !removed) { |
| 1153 | dev_warn(&h->pdev->dev, "out of memory in " |
| 1154 | "adjust_hpsa_scsi_table\n"); |
| 1155 | goto free_and_out; |
| 1156 | } |
| 1157 | |
| 1158 | spin_lock_irqsave(&h->devlock, flags); |
| 1159 | |
| 1160 | /* find any devices in h->dev[] that are not in |
| 1161 | * sd[] and remove them from h->dev[], and for any |
| 1162 | * devices which have changed, remove the old device |
| 1163 | * info and add the new device info. |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1164 | * If minor device attributes change, just update |
| 1165 | * the existing device structure. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1166 | */ |
| 1167 | i = 0; |
| 1168 | nremoved = 0; |
| 1169 | nadded = 0; |
| 1170 | while (i < h->ndevices) { |
| 1171 | csd = h->dev[i]; |
| 1172 | device_change = hpsa_scsi_find_entry(csd, sd, nsds, &entry); |
| 1173 | if (device_change == DEVICE_NOT_FOUND) { |
| 1174 | changes++; |
| 1175 | hpsa_scsi_remove_entry(h, hostno, i, |
| 1176 | removed, &nremoved); |
| 1177 | continue; /* remove ^^^, hence i not incremented */ |
| 1178 | } else if (device_change == DEVICE_CHANGED) { |
| 1179 | changes++; |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1180 | hpsa_scsi_replace_entry(h, hostno, i, sd[entry], |
| 1181 | added, &nadded, removed, &nremoved); |
Stephen M. Cameron | c7f172d | 2010-02-04 08:43:31 -0600 | [diff] [blame] | 1182 | /* Set it to NULL to prevent it from being freed |
| 1183 | * at the bottom of hpsa_update_scsi_devices() |
| 1184 | */ |
| 1185 | sd[entry] = NULL; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1186 | } else if (device_change == DEVICE_UPDATED) { |
| 1187 | hpsa_scsi_update_entry(h, hostno, i, sd[entry]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1188 | } |
| 1189 | i++; |
| 1190 | } |
| 1191 | |
| 1192 | /* Now, make sure every device listed in sd[] is also |
| 1193 | * listed in h->dev[], adding them if they aren't found |
| 1194 | */ |
| 1195 | |
| 1196 | for (i = 0; i < nsds; i++) { |
| 1197 | if (!sd[i]) /* if already added above. */ |
| 1198 | continue; |
| 1199 | device_change = hpsa_scsi_find_entry(sd[i], h->dev, |
| 1200 | h->ndevices, &entry); |
| 1201 | if (device_change == DEVICE_NOT_FOUND) { |
| 1202 | changes++; |
| 1203 | if (hpsa_scsi_add_entry(h, hostno, sd[i], |
| 1204 | added, &nadded) != 0) |
| 1205 | break; |
| 1206 | sd[i] = NULL; /* prevent from being freed later. */ |
| 1207 | } else if (device_change == DEVICE_CHANGED) { |
| 1208 | /* should never happen... */ |
| 1209 | changes++; |
| 1210 | dev_warn(&h->pdev->dev, |
| 1211 | "device unexpectedly changed.\n"); |
| 1212 | /* but if it does happen, we just ignore that device */ |
| 1213 | } |
| 1214 | } |
| 1215 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1216 | |
| 1217 | /* Don't notify scsi mid layer of any changes the first time through |
| 1218 | * (or if there are no changes) scsi_scan_host will do it later the |
| 1219 | * first time through. |
| 1220 | */ |
| 1221 | if (hostno == -1 || !changes) |
| 1222 | goto free_and_out; |
| 1223 | |
| 1224 | sh = h->scsi_host; |
| 1225 | /* Notify scsi mid layer of any removed devices */ |
| 1226 | for (i = 0; i < nremoved; i++) { |
| 1227 | struct scsi_device *sdev = |
| 1228 | scsi_device_lookup(sh, removed[i]->bus, |
| 1229 | removed[i]->target, removed[i]->lun); |
| 1230 | if (sdev != NULL) { |
| 1231 | scsi_remove_device(sdev); |
| 1232 | scsi_device_put(sdev); |
| 1233 | } else { |
| 1234 | /* We don't expect to get here. |
| 1235 | * future cmds to this device will get selection |
| 1236 | * timeout as if the device was gone. |
| 1237 | */ |
| 1238 | dev_warn(&h->pdev->dev, "didn't find c%db%dt%dl%d " |
| 1239 | " for removal.", hostno, removed[i]->bus, |
| 1240 | removed[i]->target, removed[i]->lun); |
| 1241 | } |
| 1242 | kfree(removed[i]); |
| 1243 | removed[i] = NULL; |
| 1244 | } |
| 1245 | |
| 1246 | /* Notify scsi mid layer of any added devices */ |
| 1247 | for (i = 0; i < nadded; i++) { |
| 1248 | if (scsi_add_device(sh, added[i]->bus, |
| 1249 | added[i]->target, added[i]->lun) == 0) |
| 1250 | continue; |
| 1251 | dev_warn(&h->pdev->dev, "scsi_add_device c%db%dt%dl%d failed, " |
| 1252 | "device not added.\n", hostno, added[i]->bus, |
| 1253 | added[i]->target, added[i]->lun); |
| 1254 | /* now we have to remove it from h->dev, |
| 1255 | * since it didn't get added to scsi mid layer |
| 1256 | */ |
| 1257 | fixup_botched_add(h, added[i]); |
| 1258 | } |
| 1259 | |
| 1260 | free_and_out: |
| 1261 | kfree(added); |
| 1262 | kfree(removed); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /* |
Joe Perches | 9e03aa2 | 2013-09-03 13:45:58 -0700 | [diff] [blame] | 1266 | * Lookup bus/target/lun and return corresponding struct hpsa_scsi_dev_t * |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1267 | * Assume's h->devlock is held. |
| 1268 | */ |
| 1269 | static struct hpsa_scsi_dev_t *lookup_hpsa_scsi_dev(struct ctlr_info *h, |
| 1270 | int bus, int target, int lun) |
| 1271 | { |
| 1272 | int i; |
| 1273 | struct hpsa_scsi_dev_t *sd; |
| 1274 | |
| 1275 | for (i = 0; i < h->ndevices; i++) { |
| 1276 | sd = h->dev[i]; |
| 1277 | if (sd->bus == bus && sd->target == target && sd->lun == lun) |
| 1278 | return sd; |
| 1279 | } |
| 1280 | return NULL; |
| 1281 | } |
| 1282 | |
| 1283 | /* link sdev->hostdata to our per-device structure. */ |
| 1284 | static int hpsa_slave_alloc(struct scsi_device *sdev) |
| 1285 | { |
| 1286 | struct hpsa_scsi_dev_t *sd; |
| 1287 | unsigned long flags; |
| 1288 | struct ctlr_info *h; |
| 1289 | |
| 1290 | h = sdev_to_hba(sdev); |
| 1291 | spin_lock_irqsave(&h->devlock, flags); |
| 1292 | sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev), |
| 1293 | sdev_id(sdev), sdev->lun); |
| 1294 | if (sd != NULL) |
| 1295 | sdev->hostdata = sd; |
| 1296 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | static void hpsa_slave_destroy(struct scsi_device *sdev) |
| 1301 | { |
Stephen M. Cameron | bcc4425 | 2010-02-04 08:41:54 -0600 | [diff] [blame] | 1302 | /* nothing to do. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1303 | } |
| 1304 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1305 | static void hpsa_free_sg_chain_blocks(struct ctlr_info *h) |
| 1306 | { |
| 1307 | int i; |
| 1308 | |
| 1309 | if (!h->cmd_sg_list) |
| 1310 | return; |
| 1311 | for (i = 0; i < h->nr_cmds; i++) { |
| 1312 | kfree(h->cmd_sg_list[i]); |
| 1313 | h->cmd_sg_list[i] = NULL; |
| 1314 | } |
| 1315 | kfree(h->cmd_sg_list); |
| 1316 | h->cmd_sg_list = NULL; |
| 1317 | } |
| 1318 | |
| 1319 | static int hpsa_allocate_sg_chain_blocks(struct ctlr_info *h) |
| 1320 | { |
| 1321 | int i; |
| 1322 | |
| 1323 | if (h->chainsize <= 0) |
| 1324 | return 0; |
| 1325 | |
| 1326 | h->cmd_sg_list = kzalloc(sizeof(*h->cmd_sg_list) * h->nr_cmds, |
| 1327 | GFP_KERNEL); |
| 1328 | if (!h->cmd_sg_list) |
| 1329 | return -ENOMEM; |
| 1330 | for (i = 0; i < h->nr_cmds; i++) { |
| 1331 | h->cmd_sg_list[i] = kmalloc(sizeof(*h->cmd_sg_list[i]) * |
| 1332 | h->chainsize, GFP_KERNEL); |
| 1333 | if (!h->cmd_sg_list[i]) |
| 1334 | goto clean; |
| 1335 | } |
| 1336 | return 0; |
| 1337 | |
| 1338 | clean: |
| 1339 | hpsa_free_sg_chain_blocks(h); |
| 1340 | return -ENOMEM; |
| 1341 | } |
| 1342 | |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1343 | static int hpsa_map_sg_chain_block(struct ctlr_info *h, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1344 | struct CommandList *c) |
| 1345 | { |
| 1346 | struct SGDescriptor *chain_sg, *chain_block; |
| 1347 | u64 temp64; |
| 1348 | |
| 1349 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
| 1350 | chain_block = h->cmd_sg_list[c->cmdindex]; |
| 1351 | chain_sg->Ext = HPSA_SG_CHAIN; |
| 1352 | chain_sg->Len = sizeof(*chain_sg) * |
| 1353 | (c->Header.SGTotal - h->max_cmd_sg_entries); |
| 1354 | temp64 = pci_map_single(h->pdev, chain_block, chain_sg->Len, |
| 1355 | PCI_DMA_TODEVICE); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1356 | if (dma_mapping_error(&h->pdev->dev, temp64)) { |
| 1357 | /* prevent subsequent unmapping */ |
| 1358 | chain_sg->Addr.lower = 0; |
| 1359 | chain_sg->Addr.upper = 0; |
| 1360 | return -1; |
| 1361 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1362 | chain_sg->Addr.lower = (u32) (temp64 & 0x0FFFFFFFFULL); |
| 1363 | chain_sg->Addr.upper = (u32) ((temp64 >> 32) & 0x0FFFFFFFFULL); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1364 | return 0; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | static void hpsa_unmap_sg_chain_block(struct ctlr_info *h, |
| 1368 | struct CommandList *c) |
| 1369 | { |
| 1370 | struct SGDescriptor *chain_sg; |
| 1371 | union u64bit temp64; |
| 1372 | |
| 1373 | if (c->Header.SGTotal <= h->max_cmd_sg_entries) |
| 1374 | return; |
| 1375 | |
| 1376 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
| 1377 | temp64.val32.lower = chain_sg->Addr.lower; |
| 1378 | temp64.val32.upper = chain_sg->Addr.upper; |
| 1379 | pci_unmap_single(h->pdev, temp64.val, chain_sg->Len, PCI_DMA_TODEVICE); |
| 1380 | } |
| 1381 | |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1382 | |
| 1383 | /* Decode the various types of errors on ioaccel2 path. |
| 1384 | * Return 1 for any error that should generate a RAID path retry. |
| 1385 | * Return 0 for errors that don't require a RAID path retry. |
| 1386 | */ |
| 1387 | static int handle_ioaccel_mode2_error(struct ctlr_info *h, |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1388 | struct CommandList *c, |
| 1389 | struct scsi_cmnd *cmd, |
| 1390 | struct io_accel2_cmd *c2) |
| 1391 | { |
| 1392 | int data_len; |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1393 | int retry = 0; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1394 | |
| 1395 | switch (c2->error_data.serv_response) { |
| 1396 | case IOACCEL2_SERV_RESPONSE_COMPLETE: |
| 1397 | switch (c2->error_data.status) { |
| 1398 | case IOACCEL2_STATUS_SR_TASK_COMP_GOOD: |
| 1399 | break; |
| 1400 | case IOACCEL2_STATUS_SR_TASK_COMP_CHK_COND: |
| 1401 | dev_warn(&h->pdev->dev, |
| 1402 | "%s: task complete with check condition.\n", |
| 1403 | "HP SSD Smart Path"); |
| 1404 | if (c2->error_data.data_present != |
| 1405 | IOACCEL2_SENSE_DATA_PRESENT) |
| 1406 | break; |
| 1407 | /* copy the sense data */ |
| 1408 | data_len = c2->error_data.sense_data_len; |
| 1409 | if (data_len > SCSI_SENSE_BUFFERSIZE) |
| 1410 | data_len = SCSI_SENSE_BUFFERSIZE; |
| 1411 | if (data_len > sizeof(c2->error_data.sense_data_buff)) |
| 1412 | data_len = |
| 1413 | sizeof(c2->error_data.sense_data_buff); |
| 1414 | memcpy(cmd->sense_buffer, |
| 1415 | c2->error_data.sense_data_buff, data_len); |
| 1416 | cmd->result |= SAM_STAT_CHECK_CONDITION; |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1417 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1418 | break; |
| 1419 | case IOACCEL2_STATUS_SR_TASK_COMP_BUSY: |
| 1420 | dev_warn(&h->pdev->dev, |
| 1421 | "%s: task complete with BUSY status.\n", |
| 1422 | "HP SSD Smart Path"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1423 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1424 | break; |
| 1425 | case IOACCEL2_STATUS_SR_TASK_COMP_RES_CON: |
| 1426 | dev_warn(&h->pdev->dev, |
| 1427 | "%s: task complete with reservation conflict.\n", |
| 1428 | "HP SSD Smart Path"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1429 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1430 | break; |
| 1431 | case IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL: |
| 1432 | /* Make scsi midlayer do unlimited retries */ |
| 1433 | cmd->result = DID_IMM_RETRY << 16; |
| 1434 | break; |
| 1435 | case IOACCEL2_STATUS_SR_TASK_COMP_ABORTED: |
| 1436 | dev_warn(&h->pdev->dev, |
| 1437 | "%s: task complete with aborted status.\n", |
| 1438 | "HP SSD Smart Path"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1439 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1440 | break; |
| 1441 | default: |
| 1442 | dev_warn(&h->pdev->dev, |
| 1443 | "%s: task complete with unrecognized status: 0x%02x\n", |
| 1444 | "HP SSD Smart Path", c2->error_data.status); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1445 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1446 | break; |
| 1447 | } |
| 1448 | break; |
| 1449 | case IOACCEL2_SERV_RESPONSE_FAILURE: |
| 1450 | /* don't expect to get here. */ |
| 1451 | dev_warn(&h->pdev->dev, |
| 1452 | "unexpected delivery or target failure, status = 0x%02x\n", |
| 1453 | c2->error_data.status); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1454 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1455 | break; |
| 1456 | case IOACCEL2_SERV_RESPONSE_TMF_COMPLETE: |
| 1457 | break; |
| 1458 | case IOACCEL2_SERV_RESPONSE_TMF_SUCCESS: |
| 1459 | break; |
| 1460 | case IOACCEL2_SERV_RESPONSE_TMF_REJECTED: |
| 1461 | dev_warn(&h->pdev->dev, "task management function rejected.\n"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1462 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1463 | break; |
| 1464 | case IOACCEL2_SERV_RESPONSE_TMF_WRONG_LUN: |
| 1465 | dev_warn(&h->pdev->dev, "task management function invalid LUN\n"); |
| 1466 | break; |
| 1467 | default: |
| 1468 | dev_warn(&h->pdev->dev, |
| 1469 | "%s: Unrecognized server response: 0x%02x\n", |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1470 | "HP SSD Smart Path", |
| 1471 | c2->error_data.serv_response); |
| 1472 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1473 | break; |
| 1474 | } |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1475 | |
| 1476 | return retry; /* retry on raid path? */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static void process_ioaccel2_completion(struct ctlr_info *h, |
| 1480 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 1481 | struct hpsa_scsi_dev_t *dev) |
| 1482 | { |
| 1483 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1484 | int raid_retry = 0; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1485 | |
| 1486 | /* check for good status */ |
| 1487 | if (likely(c2->error_data.serv_response == 0 && |
| 1488 | c2->error_data.status == 0)) { |
| 1489 | cmd_free(h, c); |
| 1490 | cmd->scsi_done(cmd); |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | /* Any RAID offload error results in retry which will use |
| 1495 | * the normal I/O path so the controller can handle whatever's |
| 1496 | * wrong. |
| 1497 | */ |
| 1498 | if (is_logical_dev_addr_mode(dev->scsi3addr) && |
| 1499 | c2->error_data.serv_response == |
| 1500 | IOACCEL2_SERV_RESPONSE_FAILURE) { |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1501 | if (c2->error_data.status == |
| 1502 | IOACCEL2_STATUS_SR_IOACCEL_DISABLED) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1503 | dev_warn(&h->pdev->dev, |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1504 | "%s: Path is unavailable, retrying on standard path.\n", |
| 1505 | "HP SSD Smart Path"); |
| 1506 | else |
| 1507 | dev_warn(&h->pdev->dev, |
| 1508 | "%s: Error 0x%02x, retrying on standard path.\n", |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1509 | "HP SSD Smart Path", c2->error_data.status); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1510 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1511 | dev->offload_enabled = 0; |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 1512 | h->drv_req_rescan = 1; /* schedule controller for a rescan */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1513 | cmd->result = DID_SOFT_ERROR << 16; |
| 1514 | cmd_free(h, c); |
| 1515 | cmd->scsi_done(cmd); |
| 1516 | return; |
| 1517 | } |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1518 | raid_retry = handle_ioaccel_mode2_error(h, c, cmd, c2); |
| 1519 | /* If error found, disable Smart Path, schedule a rescan, |
| 1520 | * and force a retry on the standard path. |
| 1521 | */ |
| 1522 | if (raid_retry) { |
| 1523 | dev_warn(&h->pdev->dev, "%s: Retrying on standard path.\n", |
| 1524 | "HP SSD Smart Path"); |
| 1525 | dev->offload_enabled = 0; /* Disable Smart Path */ |
| 1526 | h->drv_req_rescan = 1; /* schedule controller rescan */ |
| 1527 | cmd->result = DID_SOFT_ERROR << 16; |
| 1528 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1529 | cmd_free(h, c); |
| 1530 | cmd->scsi_done(cmd); |
| 1531 | } |
| 1532 | |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 1533 | static void complete_scsi_command(struct CommandList *cp) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1534 | { |
| 1535 | struct scsi_cmnd *cmd; |
| 1536 | struct ctlr_info *h; |
| 1537 | struct ErrorInfo *ei; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1538 | struct hpsa_scsi_dev_t *dev; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1539 | |
| 1540 | unsigned char sense_key; |
| 1541 | unsigned char asc; /* additional sense code */ |
| 1542 | unsigned char ascq; /* additional sense code qualifier */ |
Stephen M. Cameron | db111e1 | 2011-06-03 09:57:34 -0500 | [diff] [blame] | 1543 | unsigned long sense_data_size; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1544 | |
| 1545 | ei = cp->err_info; |
| 1546 | cmd = (struct scsi_cmnd *) cp->scsi_cmd; |
| 1547 | h = cp->h; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1548 | dev = cmd->device->hostdata; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1549 | |
| 1550 | scsi_dma_unmap(cmd); /* undo the DMA mappings */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1551 | if ((cp->cmd_type == CMD_SCSI) && |
| 1552 | (cp->Header.SGTotal > h->max_cmd_sg_entries)) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1553 | hpsa_unmap_sg_chain_block(h, cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1554 | |
| 1555 | cmd->result = (DID_OK << 16); /* host byte */ |
| 1556 | cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1557 | |
| 1558 | if (cp->cmd_type == CMD_IOACCEL2) |
| 1559 | return process_ioaccel2_completion(h, cp, cmd, dev); |
| 1560 | |
Stephen M. Cameron | 5512672 | 2010-02-25 14:03:01 -0600 | [diff] [blame] | 1561 | cmd->result |= ei->ScsiStatus; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1562 | |
| 1563 | /* copy the sense data whether we need to or not. */ |
Stephen M. Cameron | db111e1 | 2011-06-03 09:57:34 -0500 | [diff] [blame] | 1564 | if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo)) |
| 1565 | sense_data_size = SCSI_SENSE_BUFFERSIZE; |
| 1566 | else |
| 1567 | sense_data_size = sizeof(ei->SenseInfo); |
| 1568 | if (ei->SenseLen < sense_data_size) |
| 1569 | sense_data_size = ei->SenseLen; |
| 1570 | |
| 1571 | memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1572 | scsi_set_resid(cmd, ei->ResidualCnt); |
| 1573 | |
| 1574 | if (ei->CommandStatus == 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1575 | cmd_free(h, cp); |
Tomas Henzl | 2cc5bfa | 2013-08-01 15:14:00 +0200 | [diff] [blame] | 1576 | cmd->scsi_done(cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1577 | return; |
| 1578 | } |
| 1579 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1580 | /* For I/O accelerator commands, copy over some fields to the normal |
| 1581 | * CISS header used below for error handling. |
| 1582 | */ |
| 1583 | if (cp->cmd_type == CMD_IOACCEL1) { |
| 1584 | struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex]; |
| 1585 | cp->Header.SGList = cp->Header.SGTotal = scsi_sg_count(cmd); |
| 1586 | cp->Request.CDBLen = c->io_flags & IOACCEL1_IOFLAGS_CDBLEN_MASK; |
| 1587 | cp->Header.Tag.lower = c->Tag.lower; |
| 1588 | cp->Header.Tag.upper = c->Tag.upper; |
| 1589 | memcpy(cp->Header.LUN.LunAddrBytes, c->CISS_LUN, 8); |
| 1590 | memcpy(cp->Request.CDB, c->CDB, cp->Request.CDBLen); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1591 | |
| 1592 | /* Any RAID offload error results in retry which will use |
| 1593 | * the normal I/O path so the controller can handle whatever's |
| 1594 | * wrong. |
| 1595 | */ |
| 1596 | if (is_logical_dev_addr_mode(dev->scsi3addr)) { |
| 1597 | if (ei->CommandStatus == CMD_IOACCEL_DISABLED) |
| 1598 | dev->offload_enabled = 0; |
| 1599 | cmd->result = DID_SOFT_ERROR << 16; |
| 1600 | cmd_free(h, cp); |
| 1601 | cmd->scsi_done(cmd); |
| 1602 | return; |
| 1603 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1604 | } |
| 1605 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1606 | /* an error has occurred */ |
| 1607 | switch (ei->CommandStatus) { |
| 1608 | |
| 1609 | case CMD_TARGET_STATUS: |
| 1610 | if (ei->ScsiStatus) { |
| 1611 | /* Get sense key */ |
| 1612 | sense_key = 0xf & ei->SenseInfo[2]; |
| 1613 | /* Get additional sense code */ |
| 1614 | asc = ei->SenseInfo[12]; |
| 1615 | /* Get addition sense code qualifier */ |
| 1616 | ascq = ei->SenseInfo[13]; |
| 1617 | } |
| 1618 | |
| 1619 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) { |
Matt Gates | 3ce438d | 2013-12-04 17:10:36 -0600 | [diff] [blame] | 1620 | if (check_for_unit_attention(h, cp)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1621 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1622 | if (sense_key == ILLEGAL_REQUEST) { |
| 1623 | /* |
| 1624 | * SCSI REPORT_LUNS is commonly unsupported on |
| 1625 | * Smart Array. Suppress noisy complaint. |
| 1626 | */ |
| 1627 | if (cp->Request.CDB[0] == REPORT_LUNS) |
| 1628 | break; |
| 1629 | |
| 1630 | /* If ASC/ASCQ indicate Logical Unit |
| 1631 | * Not Supported condition, |
| 1632 | */ |
| 1633 | if ((asc == 0x25) && (ascq == 0x0)) { |
| 1634 | dev_warn(&h->pdev->dev, "cp %p " |
| 1635 | "has check condition\n", cp); |
| 1636 | break; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | if (sense_key == NOT_READY) { |
| 1641 | /* If Sense is Not Ready, Logical Unit |
| 1642 | * Not ready, Manual Intervention |
| 1643 | * required |
| 1644 | */ |
| 1645 | if ((asc == 0x04) && (ascq == 0x03)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1646 | dev_warn(&h->pdev->dev, "cp %p " |
| 1647 | "has check condition: unit " |
| 1648 | "not ready, manual " |
| 1649 | "intervention required\n", cp); |
| 1650 | break; |
| 1651 | } |
| 1652 | } |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 1653 | if (sense_key == ABORTED_COMMAND) { |
| 1654 | /* Aborted command is retryable */ |
| 1655 | dev_warn(&h->pdev->dev, "cp %p " |
| 1656 | "has check condition: aborted command: " |
| 1657 | "ASC: 0x%x, ASCQ: 0x%x\n", |
| 1658 | cp, asc, ascq); |
Stephen M. Cameron | 2e311fb | 2013-09-23 13:33:41 -0500 | [diff] [blame] | 1659 | cmd->result |= DID_SOFT_ERROR << 16; |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 1660 | break; |
| 1661 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1662 | /* Must be some other type of check condition */ |
Stephen M. Cameron | 21b8e4e | 2012-05-01 11:42:25 -0500 | [diff] [blame] | 1663 | dev_dbg(&h->pdev->dev, "cp %p has check condition: " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1664 | "unknown type: " |
| 1665 | "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " |
| 1666 | "Returning result: 0x%x, " |
| 1667 | "cmd=[%02x %02x %02x %02x %02x " |
Mike Miller | 807be73 | 2010-02-04 08:43:26 -0600 | [diff] [blame] | 1668 | "%02x %02x %02x %02x %02x %02x " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1669 | "%02x %02x %02x %02x %02x]\n", |
| 1670 | cp, sense_key, asc, ascq, |
| 1671 | cmd->result, |
| 1672 | cmd->cmnd[0], cmd->cmnd[1], |
| 1673 | cmd->cmnd[2], cmd->cmnd[3], |
| 1674 | cmd->cmnd[4], cmd->cmnd[5], |
| 1675 | cmd->cmnd[6], cmd->cmnd[7], |
Mike Miller | 807be73 | 2010-02-04 08:43:26 -0600 | [diff] [blame] | 1676 | cmd->cmnd[8], cmd->cmnd[9], |
| 1677 | cmd->cmnd[10], cmd->cmnd[11], |
| 1678 | cmd->cmnd[12], cmd->cmnd[13], |
| 1679 | cmd->cmnd[14], cmd->cmnd[15]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1680 | break; |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | /* Problem was not a check condition |
| 1685 | * Pass it up to the upper layers... |
| 1686 | */ |
| 1687 | if (ei->ScsiStatus) { |
| 1688 | dev_warn(&h->pdev->dev, "cp %p has status 0x%x " |
| 1689 | "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " |
| 1690 | "Returning result: 0x%x\n", |
| 1691 | cp, ei->ScsiStatus, |
| 1692 | sense_key, asc, ascq, |
| 1693 | cmd->result); |
| 1694 | } else { /* scsi status is zero??? How??? */ |
| 1695 | dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. " |
| 1696 | "Returning no connection.\n", cp), |
| 1697 | |
| 1698 | /* Ordinarily, this case should never happen, |
| 1699 | * but there is a bug in some released firmware |
| 1700 | * revisions that allows it to happen if, for |
| 1701 | * example, a 4100 backplane loses power and |
| 1702 | * the tape drive is in it. We assume that |
| 1703 | * it's a fatal error of some kind because we |
| 1704 | * can't show that it wasn't. We will make it |
| 1705 | * look like selection timeout since that is |
| 1706 | * the most common reason for this to occur, |
| 1707 | * and it's severe enough. |
| 1708 | */ |
| 1709 | |
| 1710 | cmd->result = DID_NO_CONNECT << 16; |
| 1711 | } |
| 1712 | break; |
| 1713 | |
| 1714 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
| 1715 | break; |
| 1716 | case CMD_DATA_OVERRUN: |
| 1717 | dev_warn(&h->pdev->dev, "cp %p has" |
| 1718 | " completed with data overrun " |
| 1719 | "reported\n", cp); |
| 1720 | break; |
| 1721 | case CMD_INVALID: { |
| 1722 | /* print_bytes(cp, sizeof(*cp), 1, 0); |
| 1723 | print_cmd(cp); */ |
| 1724 | /* We get CMD_INVALID if you address a non-existent device |
| 1725 | * instead of a selection timeout (no response). You will |
| 1726 | * see this if you yank out a drive, then try to access it. |
| 1727 | * This is kind of a shame because it means that any other |
| 1728 | * CMD_INVALID (e.g. driver bug) will get interpreted as a |
| 1729 | * missing target. */ |
| 1730 | cmd->result = DID_NO_CONNECT << 16; |
| 1731 | } |
| 1732 | break; |
| 1733 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | 256d0ea | 2012-09-14 16:34:25 -0500 | [diff] [blame] | 1734 | cmd->result = DID_ERROR << 16; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1735 | dev_warn(&h->pdev->dev, "cp %p has " |
Stephen M. Cameron | 256d0ea | 2012-09-14 16:34:25 -0500 | [diff] [blame] | 1736 | "protocol error\n", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1737 | break; |
| 1738 | case CMD_HARDWARE_ERR: |
| 1739 | cmd->result = DID_ERROR << 16; |
| 1740 | dev_warn(&h->pdev->dev, "cp %p had hardware error\n", cp); |
| 1741 | break; |
| 1742 | case CMD_CONNECTION_LOST: |
| 1743 | cmd->result = DID_ERROR << 16; |
| 1744 | dev_warn(&h->pdev->dev, "cp %p had connection lost\n", cp); |
| 1745 | break; |
| 1746 | case CMD_ABORTED: |
| 1747 | cmd->result = DID_ABORT << 16; |
| 1748 | dev_warn(&h->pdev->dev, "cp %p was aborted with status 0x%x\n", |
| 1749 | cp, ei->ScsiStatus); |
| 1750 | break; |
| 1751 | case CMD_ABORT_FAILED: |
| 1752 | cmd->result = DID_ERROR << 16; |
| 1753 | dev_warn(&h->pdev->dev, "cp %p reports abort failed\n", cp); |
| 1754 | break; |
| 1755 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | f6e7605 | 2011-07-26 11:08:52 -0500 | [diff] [blame] | 1756 | cmd->result = DID_SOFT_ERROR << 16; /* retry the command */ |
| 1757 | dev_warn(&h->pdev->dev, "cp %p aborted due to an unsolicited " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1758 | "abort\n", cp); |
| 1759 | break; |
| 1760 | case CMD_TIMEOUT: |
| 1761 | cmd->result = DID_TIME_OUT << 16; |
| 1762 | dev_warn(&h->pdev->dev, "cp %p timedout\n", cp); |
| 1763 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 1764 | case CMD_UNABORTABLE: |
| 1765 | cmd->result = DID_ERROR << 16; |
| 1766 | dev_warn(&h->pdev->dev, "Command unabortable\n"); |
| 1767 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1768 | case CMD_IOACCEL_DISABLED: |
| 1769 | /* This only handles the direct pass-through case since RAID |
| 1770 | * offload is handled above. Just attempt a retry. |
| 1771 | */ |
| 1772 | cmd->result = DID_SOFT_ERROR << 16; |
| 1773 | dev_warn(&h->pdev->dev, |
| 1774 | "cp %p had HP SSD Smart Path error\n", cp); |
| 1775 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1776 | default: |
| 1777 | cmd->result = DID_ERROR << 16; |
| 1778 | dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n", |
| 1779 | cp, ei->CommandStatus); |
| 1780 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1781 | cmd_free(h, cp); |
Tomas Henzl | 2cc5bfa | 2013-08-01 15:14:00 +0200 | [diff] [blame] | 1782 | cmd->scsi_done(cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1783 | } |
| 1784 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1785 | static void hpsa_pci_unmap(struct pci_dev *pdev, |
| 1786 | struct CommandList *c, int sg_used, int data_direction) |
| 1787 | { |
| 1788 | int i; |
| 1789 | union u64bit addr64; |
| 1790 | |
| 1791 | for (i = 0; i < sg_used; i++) { |
| 1792 | addr64.val32.lower = c->SG[i].Addr.lower; |
| 1793 | addr64.val32.upper = c->SG[i].Addr.upper; |
| 1794 | pci_unmap_single(pdev, (dma_addr_t) addr64.val, c->SG[i].Len, |
| 1795 | data_direction); |
| 1796 | } |
| 1797 | } |
| 1798 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1799 | static int hpsa_map_one(struct pci_dev *pdev, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1800 | struct CommandList *cp, |
| 1801 | unsigned char *buf, |
| 1802 | size_t buflen, |
| 1803 | int data_direction) |
| 1804 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 1805 | u64 addr64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1806 | |
| 1807 | if (buflen == 0 || data_direction == PCI_DMA_NONE) { |
| 1808 | cp->Header.SGList = 0; |
| 1809 | cp->Header.SGTotal = 0; |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1810 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 1813 | addr64 = (u64) pci_map_single(pdev, buf, buflen, data_direction); |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 1814 | if (dma_mapping_error(&pdev->dev, addr64)) { |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1815 | /* Prevent subsequent unmap of something never mapped */ |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 1816 | cp->Header.SGList = 0; |
| 1817 | cp->Header.SGTotal = 0; |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1818 | return -1; |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 1819 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1820 | cp->SG[0].Addr.lower = |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 1821 | (u32) (addr64 & (u64) 0x00000000FFFFFFFF); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1822 | cp->SG[0].Addr.upper = |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 1823 | (u32) ((addr64 >> 32) & (u64) 0x00000000FFFFFFFF); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1824 | cp->SG[0].Len = buflen; |
Matt Gates | e1d9cbf | 2014-02-18 13:55:12 -0600 | [diff] [blame] | 1825 | cp->SG[0].Ext = HPSA_SG_LAST; /* we are not chaining */ |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 1826 | cp->Header.SGList = (u8) 1; /* no. SGs contig in this cmd */ |
| 1827 | cp->Header.SGTotal = (u16) 1; /* total sgs in this cmd list */ |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1828 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h, |
| 1832 | struct CommandList *c) |
| 1833 | { |
| 1834 | DECLARE_COMPLETION_ONSTACK(wait); |
| 1835 | |
| 1836 | c->waiting = &wait; |
| 1837 | enqueue_cmd_and_start_io(h, c); |
| 1838 | wait_for_completion(&wait); |
| 1839 | } |
| 1840 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 1841 | static void hpsa_scsi_do_simple_cmd_core_if_no_lockup(struct ctlr_info *h, |
| 1842 | struct CommandList *c) |
| 1843 | { |
| 1844 | unsigned long flags; |
| 1845 | |
| 1846 | /* If controller lockup detected, fake a hardware error. */ |
| 1847 | spin_lock_irqsave(&h->lock, flags); |
| 1848 | if (unlikely(h->lockup_detected)) { |
| 1849 | spin_unlock_irqrestore(&h->lock, flags); |
| 1850 | c->err_info->CommandStatus = CMD_HARDWARE_ERR; |
| 1851 | } else { |
| 1852 | spin_unlock_irqrestore(&h->lock, flags); |
| 1853 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 1854 | } |
| 1855 | } |
| 1856 | |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 1857 | #define MAX_DRIVER_CMD_RETRIES 25 |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1858 | static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, |
| 1859 | struct CommandList *c, int data_direction) |
| 1860 | { |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 1861 | int backoff_time = 10, retry_count = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1862 | |
| 1863 | do { |
Joe Perches | 7630abd | 2011-05-08 23:32:40 -0700 | [diff] [blame] | 1864 | memset(c->err_info, 0, sizeof(*c->err_info)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1865 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 1866 | retry_count++; |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 1867 | if (retry_count > 3) { |
| 1868 | msleep(backoff_time); |
| 1869 | if (backoff_time < 1000) |
| 1870 | backoff_time *= 2; |
| 1871 | } |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 1872 | } while ((check_for_unit_attention(h, c) || |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 1873 | check_for_busy(h, c)) && |
| 1874 | retry_count <= MAX_DRIVER_CMD_RETRIES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1875 | hpsa_pci_unmap(h->pdev, c, 1, data_direction); |
| 1876 | } |
| 1877 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1878 | static void hpsa_print_cmd(struct ctlr_info *h, char *txt, |
| 1879 | struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1880 | { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1881 | const u8 *cdb = c->Request.CDB; |
| 1882 | const u8 *lun = c->Header.LUN.LunAddrBytes; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1883 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1884 | dev_warn(&h->pdev->dev, "%s: LUN:%02x%02x%02x%02x%02x%02x%02x%02x" |
| 1885 | " CDB:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1886 | txt, lun[0], lun[1], lun[2], lun[3], |
| 1887 | lun[4], lun[5], lun[6], lun[7], |
| 1888 | cdb[0], cdb[1], cdb[2], cdb[3], |
| 1889 | cdb[4], cdb[5], cdb[6], cdb[7], |
| 1890 | cdb[8], cdb[9], cdb[10], cdb[11], |
| 1891 | cdb[12], cdb[13], cdb[14], cdb[15]); |
| 1892 | } |
| 1893 | |
| 1894 | static void hpsa_scsi_interpret_error(struct ctlr_info *h, |
| 1895 | struct CommandList *cp) |
| 1896 | { |
| 1897 | const struct ErrorInfo *ei = cp->err_info; |
| 1898 | struct device *d = &cp->h->pdev->dev; |
| 1899 | const u8 *sd = ei->SenseInfo; |
| 1900 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1901 | switch (ei->CommandStatus) { |
| 1902 | case CMD_TARGET_STATUS: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1903 | hpsa_print_cmd(h, "SCSI status", cp); |
| 1904 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) |
| 1905 | dev_warn(d, "SCSI Status = 02, Sense key = %02x, ASC = %02x, ASCQ = %02x\n", |
| 1906 | sd[2] & 0x0f, sd[12], sd[13]); |
| 1907 | else |
| 1908 | dev_warn(d, "SCSI Status = %02x\n", ei->ScsiStatus); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1909 | if (ei->ScsiStatus == 0) |
| 1910 | dev_warn(d, "SCSI status is abnormally zero. " |
| 1911 | "(probably indicates selection timeout " |
| 1912 | "reported incorrectly due to a known " |
| 1913 | "firmware bug, circa July, 2001.)\n"); |
| 1914 | break; |
| 1915 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1916 | break; |
| 1917 | case CMD_DATA_OVERRUN: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1918 | hpsa_print_cmd(h, "overrun condition", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1919 | break; |
| 1920 | case CMD_INVALID: { |
| 1921 | /* controller unfortunately reports SCSI passthru's |
| 1922 | * to non-existent targets as invalid commands. |
| 1923 | */ |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1924 | hpsa_print_cmd(h, "invalid command", cp); |
| 1925 | dev_warn(d, "probably means device no longer present\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1926 | } |
| 1927 | break; |
| 1928 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1929 | hpsa_print_cmd(h, "protocol error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1930 | break; |
| 1931 | case CMD_HARDWARE_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1932 | hpsa_print_cmd(h, "hardware error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1933 | break; |
| 1934 | case CMD_CONNECTION_LOST: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1935 | hpsa_print_cmd(h, "connection lost", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1936 | break; |
| 1937 | case CMD_ABORTED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1938 | hpsa_print_cmd(h, "aborted", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1939 | break; |
| 1940 | case CMD_ABORT_FAILED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1941 | hpsa_print_cmd(h, "abort failed", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1942 | break; |
| 1943 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1944 | hpsa_print_cmd(h, "unsolicited abort", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1945 | break; |
| 1946 | case CMD_TIMEOUT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1947 | hpsa_print_cmd(h, "timed out", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1948 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 1949 | case CMD_UNABORTABLE: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1950 | hpsa_print_cmd(h, "unabortable", cp); |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 1951 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1952 | default: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1953 | hpsa_print_cmd(h, "unknown status", cp); |
| 1954 | dev_warn(d, "Unknown command status %x\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1955 | ei->CommandStatus); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | static int hpsa_scsi_do_inquiry(struct ctlr_info *h, unsigned char *scsi3addr, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 1960 | u16 page, unsigned char *buf, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1961 | unsigned char bufsize) |
| 1962 | { |
| 1963 | int rc = IO_OK; |
| 1964 | struct CommandList *c; |
| 1965 | struct ErrorInfo *ei; |
| 1966 | |
| 1967 | c = cmd_special_alloc(h); |
| 1968 | |
| 1969 | if (c == NULL) { /* trouble... */ |
| 1970 | dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 1971 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1972 | } |
| 1973 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1974 | if (fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize, |
| 1975 | page, scsi3addr, TYPE_CMD)) { |
| 1976 | rc = -1; |
| 1977 | goto out; |
| 1978 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1979 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 1980 | ei = c->err_info; |
| 1981 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 1982 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1983 | rc = -1; |
| 1984 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 1985 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1986 | cmd_special_free(h, c); |
| 1987 | return rc; |
| 1988 | } |
| 1989 | |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 1990 | static int hpsa_send_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
| 1991 | u8 reset_type) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1992 | { |
| 1993 | int rc = IO_OK; |
| 1994 | struct CommandList *c; |
| 1995 | struct ErrorInfo *ei; |
| 1996 | |
| 1997 | c = cmd_special_alloc(h); |
| 1998 | |
| 1999 | if (c == NULL) { /* trouble... */ |
| 2000 | dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); |
Stephen M. Cameron | e9ea04a | 2010-02-25 14:03:06 -0600 | [diff] [blame] | 2001 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2002 | } |
| 2003 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2004 | /* fill_cmd can't fail here, no data buffer to map. */ |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2005 | (void) fill_cmd(c, HPSA_DEVICE_RESET_MSG, h, NULL, 0, 0, |
| 2006 | scsi3addr, TYPE_MSG); |
| 2007 | c->Request.CDB[1] = reset_type; /* fill_cmd defaults to LUN reset */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2008 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 2009 | /* no unmap needed here because no data xfer. */ |
| 2010 | |
| 2011 | ei = c->err_info; |
| 2012 | if (ei->CommandStatus != 0) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2013 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2014 | rc = -1; |
| 2015 | } |
| 2016 | cmd_special_free(h, c); |
| 2017 | return rc; |
| 2018 | } |
| 2019 | |
| 2020 | static void hpsa_get_raid_level(struct ctlr_info *h, |
| 2021 | unsigned char *scsi3addr, unsigned char *raid_level) |
| 2022 | { |
| 2023 | int rc; |
| 2024 | unsigned char *buf; |
| 2025 | |
| 2026 | *raid_level = RAID_UNKNOWN; |
| 2027 | buf = kzalloc(64, GFP_KERNEL); |
| 2028 | if (!buf) |
| 2029 | return; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2030 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | 0xC1, buf, 64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2031 | if (rc == 0) |
| 2032 | *raid_level = buf[8]; |
| 2033 | if (*raid_level > RAID_UNKNOWN) |
| 2034 | *raid_level = RAID_UNKNOWN; |
| 2035 | kfree(buf); |
| 2036 | return; |
| 2037 | } |
| 2038 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2039 | #define HPSA_MAP_DEBUG |
| 2040 | #ifdef HPSA_MAP_DEBUG |
| 2041 | static void hpsa_debug_map_buff(struct ctlr_info *h, int rc, |
| 2042 | struct raid_map_data *map_buff) |
| 2043 | { |
| 2044 | struct raid_map_disk_data *dd = &map_buff->data[0]; |
| 2045 | int map, row, col; |
| 2046 | u16 map_cnt, row_cnt, disks_per_row; |
| 2047 | |
| 2048 | if (rc != 0) |
| 2049 | return; |
| 2050 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 2051 | /* Show details only if debugging has been activated. */ |
| 2052 | if (h->raid_offload_debug < 2) |
| 2053 | return; |
| 2054 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2055 | dev_info(&h->pdev->dev, "structure_size = %u\n", |
| 2056 | le32_to_cpu(map_buff->structure_size)); |
| 2057 | dev_info(&h->pdev->dev, "volume_blk_size = %u\n", |
| 2058 | le32_to_cpu(map_buff->volume_blk_size)); |
| 2059 | dev_info(&h->pdev->dev, "volume_blk_cnt = 0x%llx\n", |
| 2060 | le64_to_cpu(map_buff->volume_blk_cnt)); |
| 2061 | dev_info(&h->pdev->dev, "physicalBlockShift = %u\n", |
| 2062 | map_buff->phys_blk_shift); |
| 2063 | dev_info(&h->pdev->dev, "parity_rotation_shift = %u\n", |
| 2064 | map_buff->parity_rotation_shift); |
| 2065 | dev_info(&h->pdev->dev, "strip_size = %u\n", |
| 2066 | le16_to_cpu(map_buff->strip_size)); |
| 2067 | dev_info(&h->pdev->dev, "disk_starting_blk = 0x%llx\n", |
| 2068 | le64_to_cpu(map_buff->disk_starting_blk)); |
| 2069 | dev_info(&h->pdev->dev, "disk_blk_cnt = 0x%llx\n", |
| 2070 | le64_to_cpu(map_buff->disk_blk_cnt)); |
| 2071 | dev_info(&h->pdev->dev, "data_disks_per_row = %u\n", |
| 2072 | le16_to_cpu(map_buff->data_disks_per_row)); |
| 2073 | dev_info(&h->pdev->dev, "metadata_disks_per_row = %u\n", |
| 2074 | le16_to_cpu(map_buff->metadata_disks_per_row)); |
| 2075 | dev_info(&h->pdev->dev, "row_cnt = %u\n", |
| 2076 | le16_to_cpu(map_buff->row_cnt)); |
| 2077 | dev_info(&h->pdev->dev, "layout_map_count = %u\n", |
| 2078 | le16_to_cpu(map_buff->layout_map_count)); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 2079 | dev_info(&h->pdev->dev, "flags = %u\n", |
| 2080 | le16_to_cpu(map_buff->flags)); |
| 2081 | if (map_buff->flags & RAID_MAP_FLAG_ENCRYPT_ON) |
| 2082 | dev_info(&h->pdev->dev, "encrypytion = ON\n"); |
| 2083 | else |
| 2084 | dev_info(&h->pdev->dev, "encrypytion = OFF\n"); |
| 2085 | dev_info(&h->pdev->dev, "dekindex = %u\n", |
| 2086 | le16_to_cpu(map_buff->dekindex)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2087 | |
| 2088 | map_cnt = le16_to_cpu(map_buff->layout_map_count); |
| 2089 | for (map = 0; map < map_cnt; map++) { |
| 2090 | dev_info(&h->pdev->dev, "Map%u:\n", map); |
| 2091 | row_cnt = le16_to_cpu(map_buff->row_cnt); |
| 2092 | for (row = 0; row < row_cnt; row++) { |
| 2093 | dev_info(&h->pdev->dev, " Row%u:\n", row); |
| 2094 | disks_per_row = |
| 2095 | le16_to_cpu(map_buff->data_disks_per_row); |
| 2096 | for (col = 0; col < disks_per_row; col++, dd++) |
| 2097 | dev_info(&h->pdev->dev, |
| 2098 | " D%02u: h=0x%04x xor=%u,%u\n", |
| 2099 | col, dd->ioaccel_handle, |
| 2100 | dd->xor_mult[0], dd->xor_mult[1]); |
| 2101 | disks_per_row = |
| 2102 | le16_to_cpu(map_buff->metadata_disks_per_row); |
| 2103 | for (col = 0; col < disks_per_row; col++, dd++) |
| 2104 | dev_info(&h->pdev->dev, |
| 2105 | " M%02u: h=0x%04x xor=%u,%u\n", |
| 2106 | col, dd->ioaccel_handle, |
| 2107 | dd->xor_mult[0], dd->xor_mult[1]); |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | #else |
| 2112 | static void hpsa_debug_map_buff(__attribute__((unused)) struct ctlr_info *h, |
| 2113 | __attribute__((unused)) int rc, |
| 2114 | __attribute__((unused)) struct raid_map_data *map_buff) |
| 2115 | { |
| 2116 | } |
| 2117 | #endif |
| 2118 | |
| 2119 | static int hpsa_get_raid_map(struct ctlr_info *h, |
| 2120 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 2121 | { |
| 2122 | int rc = 0; |
| 2123 | struct CommandList *c; |
| 2124 | struct ErrorInfo *ei; |
| 2125 | |
| 2126 | c = cmd_special_alloc(h); |
| 2127 | if (c == NULL) { |
| 2128 | dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); |
| 2129 | return -ENOMEM; |
| 2130 | } |
| 2131 | if (fill_cmd(c, HPSA_GET_RAID_MAP, h, &this_device->raid_map, |
| 2132 | sizeof(this_device->raid_map), 0, |
| 2133 | scsi3addr, TYPE_CMD)) { |
| 2134 | dev_warn(&h->pdev->dev, "Out of memory in hpsa_get_raid_map()\n"); |
| 2135 | cmd_special_free(h, c); |
| 2136 | return -ENOMEM; |
| 2137 | } |
| 2138 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2139 | ei = c->err_info; |
| 2140 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2141 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2142 | cmd_special_free(h, c); |
| 2143 | return -1; |
| 2144 | } |
| 2145 | cmd_special_free(h, c); |
| 2146 | |
| 2147 | /* @todo in the future, dynamically allocate RAID map memory */ |
| 2148 | if (le32_to_cpu(this_device->raid_map.structure_size) > |
| 2149 | sizeof(this_device->raid_map)) { |
| 2150 | dev_warn(&h->pdev->dev, "RAID map size is too large!\n"); |
| 2151 | rc = -1; |
| 2152 | } |
| 2153 | hpsa_debug_map_buff(h, rc, &this_device->raid_map); |
| 2154 | return rc; |
| 2155 | } |
| 2156 | |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 2157 | static int hpsa_vpd_page_supported(struct ctlr_info *h, |
| 2158 | unsigned char scsi3addr[], u8 page) |
| 2159 | { |
| 2160 | int rc; |
| 2161 | int i; |
| 2162 | int pages; |
| 2163 | unsigned char *buf, bufsize; |
| 2164 | |
| 2165 | buf = kzalloc(256, GFP_KERNEL); |
| 2166 | if (!buf) |
| 2167 | return 0; |
| 2168 | |
| 2169 | /* Get the size of the page list first */ |
| 2170 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 2171 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 2172 | buf, HPSA_VPD_HEADER_SZ); |
| 2173 | if (rc != 0) |
| 2174 | goto exit_unsupported; |
| 2175 | pages = buf[3]; |
| 2176 | if ((pages + HPSA_VPD_HEADER_SZ) <= 255) |
| 2177 | bufsize = pages + HPSA_VPD_HEADER_SZ; |
| 2178 | else |
| 2179 | bufsize = 255; |
| 2180 | |
| 2181 | /* Get the whole VPD page list */ |
| 2182 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 2183 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 2184 | buf, bufsize); |
| 2185 | if (rc != 0) |
| 2186 | goto exit_unsupported; |
| 2187 | |
| 2188 | pages = buf[3]; |
| 2189 | for (i = 1; i <= pages; i++) |
| 2190 | if (buf[3 + i] == page) |
| 2191 | goto exit_supported; |
| 2192 | exit_unsupported: |
| 2193 | kfree(buf); |
| 2194 | return 0; |
| 2195 | exit_supported: |
| 2196 | kfree(buf); |
| 2197 | return 1; |
| 2198 | } |
| 2199 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2200 | static void hpsa_get_ioaccel_status(struct ctlr_info *h, |
| 2201 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 2202 | { |
| 2203 | int rc; |
| 2204 | unsigned char *buf; |
| 2205 | u8 ioaccel_status; |
| 2206 | |
| 2207 | this_device->offload_config = 0; |
| 2208 | this_device->offload_enabled = 0; |
| 2209 | |
| 2210 | buf = kzalloc(64, GFP_KERNEL); |
| 2211 | if (!buf) |
| 2212 | return; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 2213 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_IOACCEL_STATUS)) |
| 2214 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2215 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2216 | VPD_PAGE | HPSA_VPD_LV_IOACCEL_STATUS, buf, 64); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2217 | if (rc != 0) |
| 2218 | goto out; |
| 2219 | |
| 2220 | #define IOACCEL_STATUS_BYTE 4 |
| 2221 | #define OFFLOAD_CONFIGURED_BIT 0x01 |
| 2222 | #define OFFLOAD_ENABLED_BIT 0x02 |
| 2223 | ioaccel_status = buf[IOACCEL_STATUS_BYTE]; |
| 2224 | this_device->offload_config = |
| 2225 | !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT); |
| 2226 | if (this_device->offload_config) { |
| 2227 | this_device->offload_enabled = |
| 2228 | !!(ioaccel_status & OFFLOAD_ENABLED_BIT); |
| 2229 | if (hpsa_get_raid_map(h, scsi3addr, this_device)) |
| 2230 | this_device->offload_enabled = 0; |
| 2231 | } |
| 2232 | out: |
| 2233 | kfree(buf); |
| 2234 | return; |
| 2235 | } |
| 2236 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2237 | /* Get the device id from inquiry page 0x83 */ |
| 2238 | static int hpsa_get_device_id(struct ctlr_info *h, unsigned char *scsi3addr, |
| 2239 | unsigned char *device_id, int buflen) |
| 2240 | { |
| 2241 | int rc; |
| 2242 | unsigned char *buf; |
| 2243 | |
| 2244 | if (buflen > 16) |
| 2245 | buflen = 16; |
| 2246 | buf = kzalloc(64, GFP_KERNEL); |
| 2247 | if (!buf) |
| 2248 | return -1; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2249 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | 0x83, buf, 64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2250 | if (rc == 0) |
| 2251 | memcpy(device_id, &buf[8], buflen); |
| 2252 | kfree(buf); |
| 2253 | return rc != 0; |
| 2254 | } |
| 2255 | |
| 2256 | static int hpsa_scsi_do_report_luns(struct ctlr_info *h, int logical, |
| 2257 | struct ReportLUNdata *buf, int bufsize, |
| 2258 | int extended_response) |
| 2259 | { |
| 2260 | int rc = IO_OK; |
| 2261 | struct CommandList *c; |
| 2262 | unsigned char scsi3addr[8]; |
| 2263 | struct ErrorInfo *ei; |
| 2264 | |
| 2265 | c = cmd_special_alloc(h); |
| 2266 | if (c == NULL) { /* trouble... */ |
| 2267 | dev_err(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); |
| 2268 | return -1; |
| 2269 | } |
Stephen M. Cameron | e89c0ae | 2010-02-04 08:42:04 -0600 | [diff] [blame] | 2270 | /* address the controller */ |
| 2271 | memset(scsi3addr, 0, sizeof(scsi3addr)); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2272 | if (fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h, |
| 2273 | buf, bufsize, 0, scsi3addr, TYPE_CMD)) { |
| 2274 | rc = -1; |
| 2275 | goto out; |
| 2276 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2277 | if (extended_response) |
| 2278 | c->Request.CDB[1] = extended_response; |
| 2279 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2280 | ei = c->err_info; |
| 2281 | if (ei->CommandStatus != 0 && |
| 2282 | ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2283 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2284 | rc = -1; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2285 | } else { |
| 2286 | if (buf->extended_response_flag != extended_response) { |
| 2287 | dev_err(&h->pdev->dev, |
| 2288 | "report luns requested format %u, got %u\n", |
| 2289 | extended_response, |
| 2290 | buf->extended_response_flag); |
| 2291 | rc = -1; |
| 2292 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2293 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2294 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2295 | cmd_special_free(h, c); |
| 2296 | return rc; |
| 2297 | } |
| 2298 | |
| 2299 | static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info *h, |
| 2300 | struct ReportLUNdata *buf, |
| 2301 | int bufsize, int extended_response) |
| 2302 | { |
| 2303 | return hpsa_scsi_do_report_luns(h, 0, buf, bufsize, extended_response); |
| 2304 | } |
| 2305 | |
| 2306 | static inline int hpsa_scsi_do_report_log_luns(struct ctlr_info *h, |
| 2307 | struct ReportLUNdata *buf, int bufsize) |
| 2308 | { |
| 2309 | return hpsa_scsi_do_report_luns(h, 1, buf, bufsize, 0); |
| 2310 | } |
| 2311 | |
| 2312 | static inline void hpsa_set_bus_target_lun(struct hpsa_scsi_dev_t *device, |
| 2313 | int bus, int target, int lun) |
| 2314 | { |
| 2315 | device->bus = bus; |
| 2316 | device->target = target; |
| 2317 | device->lun = lun; |
| 2318 | } |
| 2319 | |
| 2320 | static int hpsa_update_device_info(struct ctlr_info *h, |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2321 | unsigned char scsi3addr[], struct hpsa_scsi_dev_t *this_device, |
| 2322 | unsigned char *is_OBDR_device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2323 | { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2324 | |
| 2325 | #define OBDR_SIG_OFFSET 43 |
| 2326 | #define OBDR_TAPE_SIG "$DR-10" |
| 2327 | #define OBDR_SIG_LEN (sizeof(OBDR_TAPE_SIG) - 1) |
| 2328 | #define OBDR_TAPE_INQ_SIZE (OBDR_SIG_OFFSET + OBDR_SIG_LEN) |
| 2329 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 2330 | unsigned char *inq_buff; |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2331 | unsigned char *obdr_sig; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2332 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 2333 | inq_buff = kzalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2334 | if (!inq_buff) |
| 2335 | goto bail_out; |
| 2336 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2337 | /* Do an inquiry to the device to see what it is. */ |
| 2338 | if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff, |
| 2339 | (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) { |
| 2340 | /* Inquiry failed (msg printed already) */ |
| 2341 | dev_err(&h->pdev->dev, |
| 2342 | "hpsa_update_device_info: inquiry failed\n"); |
| 2343 | goto bail_out; |
| 2344 | } |
| 2345 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2346 | this_device->devtype = (inq_buff[0] & 0x1f); |
| 2347 | memcpy(this_device->scsi3addr, scsi3addr, 8); |
| 2348 | memcpy(this_device->vendor, &inq_buff[8], |
| 2349 | sizeof(this_device->vendor)); |
| 2350 | memcpy(this_device->model, &inq_buff[16], |
| 2351 | sizeof(this_device->model)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2352 | memset(this_device->device_id, 0, |
| 2353 | sizeof(this_device->device_id)); |
| 2354 | hpsa_get_device_id(h, scsi3addr, this_device->device_id, |
| 2355 | sizeof(this_device->device_id)); |
| 2356 | |
| 2357 | if (this_device->devtype == TYPE_DISK && |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2358 | is_logical_dev_addr_mode(scsi3addr)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2359 | hpsa_get_raid_level(h, scsi3addr, &this_device->raid_level); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2360 | if (h->fw_support & MISC_FW_RAID_OFFLOAD_BASIC) |
| 2361 | hpsa_get_ioaccel_status(h, scsi3addr, this_device); |
| 2362 | } else { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2363 | this_device->raid_level = RAID_UNKNOWN; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2364 | this_device->offload_config = 0; |
| 2365 | this_device->offload_enabled = 0; |
| 2366 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2367 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2368 | if (is_OBDR_device) { |
| 2369 | /* See if this is a One-Button-Disaster-Recovery device |
| 2370 | * by looking for "$DR-10" at offset 43 in inquiry data. |
| 2371 | */ |
| 2372 | obdr_sig = &inq_buff[OBDR_SIG_OFFSET]; |
| 2373 | *is_OBDR_device = (this_device->devtype == TYPE_ROM && |
| 2374 | strncmp(obdr_sig, OBDR_TAPE_SIG, |
| 2375 | OBDR_SIG_LEN) == 0); |
| 2376 | } |
| 2377 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2378 | kfree(inq_buff); |
| 2379 | return 0; |
| 2380 | |
| 2381 | bail_out: |
| 2382 | kfree(inq_buff); |
| 2383 | return 1; |
| 2384 | } |
| 2385 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2386 | static unsigned char *ext_target_model[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2387 | "MSA2012", |
| 2388 | "MSA2024", |
| 2389 | "MSA2312", |
| 2390 | "MSA2324", |
Stephen M. Cameron | fda3851 | 2011-05-03 15:00:07 -0500 | [diff] [blame] | 2391 | "P2000 G3 SAS", |
Stephen M. Cameron | e06c8e5 | 2013-09-23 13:33:56 -0500 | [diff] [blame] | 2392 | "MSA 2040 SAS", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2393 | NULL, |
| 2394 | }; |
| 2395 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2396 | static int is_ext_target(struct ctlr_info *h, struct hpsa_scsi_dev_t *device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2397 | { |
| 2398 | int i; |
| 2399 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2400 | for (i = 0; ext_target_model[i]; i++) |
| 2401 | if (strncmp(device->model, ext_target_model[i], |
| 2402 | strlen(ext_target_model[i])) == 0) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2403 | return 1; |
| 2404 | return 0; |
| 2405 | } |
| 2406 | |
| 2407 | /* Helper function to assign bus, target, lun mapping of devices. |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2408 | * Puts non-external target logical volumes on bus 0, external target logical |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2409 | * volumes on bus 1, physical devices on bus 2. and the hba on bus 3. |
| 2410 | * Logical drive target and lun are assigned at this time, but |
| 2411 | * physical device lun and target assignment are deferred (assigned |
| 2412 | * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) |
| 2413 | */ |
| 2414 | static void figure_bus_target_lun(struct ctlr_info *h, |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2415 | u8 *lunaddrbytes, struct hpsa_scsi_dev_t *device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2416 | { |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2417 | u32 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2418 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2419 | if (!is_logical_dev_addr_mode(lunaddrbytes)) { |
| 2420 | /* physical device, target and lun filled in later */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2421 | if (is_hba_lunid(lunaddrbytes)) |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2422 | hpsa_set_bus_target_lun(device, 3, 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2423 | else |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2424 | /* defer target, lun assignment for physical devices */ |
| 2425 | hpsa_set_bus_target_lun(device, 2, -1, -1); |
| 2426 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2427 | } |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2428 | /* It's a logical device */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2429 | if (is_ext_target(h, device)) { |
| 2430 | /* external target way, put logicals on bus 1 |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2431 | * and match target/lun numbers box |
| 2432 | * reports, other smart array, bus 0, target 0, match lunid |
| 2433 | */ |
| 2434 | hpsa_set_bus_target_lun(device, |
| 2435 | 1, (lunid >> 16) & 0x3fff, lunid & 0x00ff); |
| 2436 | return; |
| 2437 | } |
| 2438 | hpsa_set_bus_target_lun(device, 0, 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | /* |
| 2442 | * If there is no lun 0 on a target, linux won't find any devices. |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2443 | * For the external targets (arrays), we have to manually detect the enclosure |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2444 | * which is at lun zero, as CCISS_REPORT_PHYSICAL_LUNS doesn't report |
| 2445 | * it for some reason. *tmpdevice is the target we're adding, |
| 2446 | * this_device is a pointer into the current element of currentsd[] |
| 2447 | * that we're building up in update_scsi_devices(), below. |
| 2448 | * lunzerobits is a bitmap that tracks which targets already have a |
| 2449 | * lun 0 assigned. |
| 2450 | * Returns 1 if an enclosure was added, 0 if not. |
| 2451 | */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2452 | static int add_ext_target_dev(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2453 | struct hpsa_scsi_dev_t *tmpdevice, |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2454 | struct hpsa_scsi_dev_t *this_device, u8 *lunaddrbytes, |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2455 | unsigned long lunzerobits[], int *n_ext_target_devs) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2456 | { |
| 2457 | unsigned char scsi3addr[8]; |
| 2458 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2459 | if (test_bit(tmpdevice->target, lunzerobits)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2460 | return 0; /* There is already a lun 0 on this target. */ |
| 2461 | |
| 2462 | if (!is_logical_dev_addr_mode(lunaddrbytes)) |
| 2463 | return 0; /* It's the logical targets that may lack lun 0. */ |
| 2464 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2465 | if (!is_ext_target(h, tmpdevice)) |
| 2466 | return 0; /* Only external target devices have this problem. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2467 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2468 | if (tmpdevice->lun == 0) /* if lun is 0, then we have a lun 0. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2469 | return 0; |
| 2470 | |
Stephen M. Cameron | c4f8a29 | 2011-01-07 10:55:43 -0600 | [diff] [blame] | 2471 | memset(scsi3addr, 0, 8); |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2472 | scsi3addr[3] = tmpdevice->target; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2473 | if (is_hba_lunid(scsi3addr)) |
| 2474 | return 0; /* Don't add the RAID controller here. */ |
| 2475 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2476 | if (is_scsi_rev_5(h)) |
| 2477 | return 0; /* p1210m doesn't need to do this. */ |
| 2478 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2479 | if (*n_ext_target_devs >= MAX_EXT_TARGETS) { |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 2480 | dev_warn(&h->pdev->dev, "Maximum number of external " |
| 2481 | "target devices exceeded. Check your hardware " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2482 | "configuration."); |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2486 | if (hpsa_update_device_info(h, scsi3addr, this_device, NULL)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2487 | return 0; |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2488 | (*n_ext_target_devs)++; |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2489 | hpsa_set_bus_target_lun(this_device, |
| 2490 | tmpdevice->bus, tmpdevice->target, 0); |
| 2491 | set_bit(tmpdevice->target, lunzerobits); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2492 | return 1; |
| 2493 | } |
| 2494 | |
| 2495 | /* |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2496 | * Get address of physical disk used for an ioaccel2 mode command: |
| 2497 | * 1. Extract ioaccel2 handle from the command. |
| 2498 | * 2. Find a matching ioaccel2 handle from list of physical disks. |
| 2499 | * 3. Return: |
| 2500 | * 1 and set scsi3addr to address of matching physical |
| 2501 | * 0 if no matching physical disk was found. |
| 2502 | */ |
| 2503 | static int hpsa_get_pdisk_of_ioaccel2(struct ctlr_info *h, |
| 2504 | struct CommandList *ioaccel2_cmd_to_abort, unsigned char *scsi3addr) |
| 2505 | { |
| 2506 | struct ReportExtendedLUNdata *physicals = NULL; |
| 2507 | int responsesize = 24; /* size of physical extended response */ |
| 2508 | int extended = 2; /* flag forces reporting 'other dev info'. */ |
| 2509 | int reportsize = sizeof(*physicals) + HPSA_MAX_PHYS_LUN * responsesize; |
| 2510 | u32 nphysicals = 0; /* number of reported physical devs */ |
| 2511 | int found = 0; /* found match (1) or not (0) */ |
| 2512 | u32 find; /* handle we need to match */ |
| 2513 | int i; |
| 2514 | struct scsi_cmnd *scmd; /* scsi command within request being aborted */ |
| 2515 | struct hpsa_scsi_dev_t *d; /* device of request being aborted */ |
| 2516 | struct io_accel2_cmd *c2a; /* ioaccel2 command to abort */ |
| 2517 | u32 it_nexus; /* 4 byte device handle for the ioaccel2 cmd */ |
| 2518 | u32 scsi_nexus; /* 4 byte device handle for the ioaccel2 cmd */ |
| 2519 | |
| 2520 | if (ioaccel2_cmd_to_abort->cmd_type != CMD_IOACCEL2) |
| 2521 | return 0; /* no match */ |
| 2522 | |
| 2523 | /* point to the ioaccel2 device handle */ |
| 2524 | c2a = &h->ioaccel2_cmd_pool[ioaccel2_cmd_to_abort->cmdindex]; |
| 2525 | if (c2a == NULL) |
| 2526 | return 0; /* no match */ |
| 2527 | |
| 2528 | scmd = (struct scsi_cmnd *) ioaccel2_cmd_to_abort->scsi_cmd; |
| 2529 | if (scmd == NULL) |
| 2530 | return 0; /* no match */ |
| 2531 | |
| 2532 | d = scmd->device->hostdata; |
| 2533 | if (d == NULL) |
| 2534 | return 0; /* no match */ |
| 2535 | |
| 2536 | it_nexus = cpu_to_le32((u32) d->ioaccel_handle); |
| 2537 | scsi_nexus = cpu_to_le32((u32) c2a->scsi_nexus); |
| 2538 | find = c2a->scsi_nexus; |
| 2539 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 2540 | if (h->raid_offload_debug > 0) |
| 2541 | dev_info(&h->pdev->dev, |
| 2542 | "%s: scsi_nexus:0x%08x device id: 0x%02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x\n", |
| 2543 | __func__, scsi_nexus, |
| 2544 | d->device_id[0], d->device_id[1], d->device_id[2], |
| 2545 | d->device_id[3], d->device_id[4], d->device_id[5], |
| 2546 | d->device_id[6], d->device_id[7], d->device_id[8], |
| 2547 | d->device_id[9], d->device_id[10], d->device_id[11], |
| 2548 | d->device_id[12], d->device_id[13], d->device_id[14], |
| 2549 | d->device_id[15]); |
| 2550 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2551 | /* Get the list of physical devices */ |
| 2552 | physicals = kzalloc(reportsize, GFP_KERNEL); |
| 2553 | if (hpsa_scsi_do_report_phys_luns(h, (struct ReportLUNdata *) physicals, |
| 2554 | reportsize, extended)) { |
| 2555 | dev_err(&h->pdev->dev, |
| 2556 | "Can't lookup %s device handle: report physical LUNs failed.\n", |
| 2557 | "HP SSD Smart Path"); |
| 2558 | kfree(physicals); |
| 2559 | return 0; |
| 2560 | } |
| 2561 | nphysicals = be32_to_cpu(*((__be32 *)physicals->LUNListLength)) / |
| 2562 | responsesize; |
| 2563 | |
| 2564 | |
| 2565 | /* find ioaccel2 handle in list of physicals: */ |
| 2566 | for (i = 0; i < nphysicals; i++) { |
| 2567 | /* handle is in bytes 28-31 of each lun */ |
| 2568 | if (memcmp(&((struct ReportExtendedLUNdata *) |
| 2569 | physicals)->LUN[i][20], &find, 4) != 0) { |
| 2570 | continue; /* didn't match */ |
| 2571 | } |
| 2572 | found = 1; |
| 2573 | memcpy(scsi3addr, &((struct ReportExtendedLUNdata *) |
| 2574 | physicals)->LUN[i][0], 8); |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 2575 | if (h->raid_offload_debug > 0) |
| 2576 | dev_info(&h->pdev->dev, |
| 2577 | "%s: Searched h=0x%08x, Found h=0x%08x, scsiaddr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 2578 | __func__, find, |
| 2579 | ((struct ReportExtendedLUNdata *) |
| 2580 | physicals)->LUN[i][20], |
| 2581 | scsi3addr[0], scsi3addr[1], scsi3addr[2], |
| 2582 | scsi3addr[3], scsi3addr[4], scsi3addr[5], |
| 2583 | scsi3addr[6], scsi3addr[7]); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2584 | break; /* found it */ |
| 2585 | } |
| 2586 | |
| 2587 | kfree(physicals); |
| 2588 | if (found) |
| 2589 | return 1; |
| 2590 | else |
| 2591 | return 0; |
| 2592 | |
| 2593 | } |
| 2594 | /* |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2595 | * Do CISS_REPORT_PHYS and CISS_REPORT_LOG. Data is returned in physdev, |
| 2596 | * logdev. The number of luns in physdev and logdev are returned in |
| 2597 | * *nphysicals and *nlogicals, respectively. |
| 2598 | * Returns 0 on success, -1 otherwise. |
| 2599 | */ |
| 2600 | static int hpsa_gather_lun_info(struct ctlr_info *h, |
| 2601 | int reportlunsize, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2602 | struct ReportLUNdata *physdev, u32 *nphysicals, int *physical_mode, |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2603 | struct ReportLUNdata *logdev, u32 *nlogicals) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2604 | { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2605 | int physical_entry_size = 8; |
| 2606 | |
| 2607 | *physical_mode = 0; |
| 2608 | |
| 2609 | /* For I/O accelerator mode we need to read physical device handles */ |
Mike MIller | 317d4ad | 2014-02-18 13:56:20 -0600 | [diff] [blame] | 2610 | if (h->transMethod & CFGTBL_Trans_io_accel1 || |
| 2611 | h->transMethod & CFGTBL_Trans_io_accel2) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2612 | *physical_mode = HPSA_REPORT_PHYS_EXTENDED; |
| 2613 | physical_entry_size = 24; |
| 2614 | } |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 2615 | if (hpsa_scsi_do_report_phys_luns(h, physdev, reportlunsize, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2616 | *physical_mode)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2617 | dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); |
| 2618 | return -1; |
| 2619 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2620 | *nphysicals = be32_to_cpu(*((__be32 *)physdev->LUNListLength)) / |
| 2621 | physical_entry_size; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2622 | if (*nphysicals > HPSA_MAX_PHYS_LUN) { |
| 2623 | dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded." |
| 2624 | " %d LUNs ignored.\n", HPSA_MAX_PHYS_LUN, |
| 2625 | *nphysicals - HPSA_MAX_PHYS_LUN); |
| 2626 | *nphysicals = HPSA_MAX_PHYS_LUN; |
| 2627 | } |
| 2628 | if (hpsa_scsi_do_report_log_luns(h, logdev, reportlunsize)) { |
| 2629 | dev_err(&h->pdev->dev, "report logical LUNs failed.\n"); |
| 2630 | return -1; |
| 2631 | } |
Stephen M. Cameron | 6df1e95 | 2010-02-04 08:42:19 -0600 | [diff] [blame] | 2632 | *nlogicals = be32_to_cpu(*((__be32 *) logdev->LUNListLength)) / 8; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2633 | /* Reject Logicals in excess of our max capability. */ |
| 2634 | if (*nlogicals > HPSA_MAX_LUN) { |
| 2635 | dev_warn(&h->pdev->dev, |
| 2636 | "maximum logical LUNs (%d) exceeded. " |
| 2637 | "%d LUNs ignored.\n", HPSA_MAX_LUN, |
| 2638 | *nlogicals - HPSA_MAX_LUN); |
| 2639 | *nlogicals = HPSA_MAX_LUN; |
| 2640 | } |
| 2641 | if (*nlogicals + *nphysicals > HPSA_MAX_PHYS_LUN) { |
| 2642 | dev_warn(&h->pdev->dev, |
| 2643 | "maximum logical + physical LUNs (%d) exceeded. " |
| 2644 | "%d LUNs ignored.\n", HPSA_MAX_PHYS_LUN, |
| 2645 | *nphysicals + *nlogicals - HPSA_MAX_PHYS_LUN); |
| 2646 | *nlogicals = HPSA_MAX_PHYS_LUN - *nphysicals; |
| 2647 | } |
| 2648 | return 0; |
| 2649 | } |
| 2650 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2651 | u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, int i, |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 2652 | int nphysicals, int nlogicals, |
| 2653 | struct ReportExtendedLUNdata *physdev_list, |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2654 | struct ReportLUNdata *logdev_list) |
| 2655 | { |
| 2656 | /* Helper function, figure out where the LUN ID info is coming from |
| 2657 | * given index i, lists of physical and logical devices, where in |
| 2658 | * the list the raid controller is supposed to appear (first or last) |
| 2659 | */ |
| 2660 | |
| 2661 | int logicals_start = nphysicals + (raid_ctlr_position == 0); |
| 2662 | int last_device = nphysicals + nlogicals + (raid_ctlr_position == 0); |
| 2663 | |
| 2664 | if (i == raid_ctlr_position) |
| 2665 | return RAID_CTLR_LUNID; |
| 2666 | |
| 2667 | if (i < logicals_start) |
| 2668 | return &physdev_list->LUN[i - (raid_ctlr_position == 0)][0]; |
| 2669 | |
| 2670 | if (i < last_device) |
| 2671 | return &logdev_list->LUN[i - nphysicals - |
| 2672 | (raid_ctlr_position == 0)][0]; |
| 2673 | BUG(); |
| 2674 | return NULL; |
| 2675 | } |
| 2676 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2677 | static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) |
| 2678 | { |
| 2679 | /* the idea here is we could get notified |
| 2680 | * that some devices have changed, so we do a report |
| 2681 | * physical luns and report logical luns cmd, and adjust |
| 2682 | * our list of devices accordingly. |
| 2683 | * |
| 2684 | * The scsi3addr's of devices won't change so long as the |
| 2685 | * adapter is not reset. That means we can rescan and |
| 2686 | * tell which devices we already know about, vs. new |
| 2687 | * devices, vs. disappearing devices. |
| 2688 | */ |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 2689 | struct ReportExtendedLUNdata *physdev_list = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2690 | struct ReportLUNdata *logdev_list = NULL; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2691 | u32 nphysicals = 0; |
| 2692 | u32 nlogicals = 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2693 | int physical_mode = 0; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2694 | u32 ndev_allocated = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2695 | struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; |
| 2696 | int ncurrent = 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2697 | int reportlunsize = sizeof(*physdev_list) + HPSA_MAX_PHYS_LUN * 24; |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2698 | int i, n_ext_target_devs, ndevs_to_allocate; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2699 | int raid_ctlr_position; |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 2700 | DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2701 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 2702 | currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2703 | physdev_list = kzalloc(reportlunsize, GFP_KERNEL); |
| 2704 | logdev_list = kzalloc(reportlunsize, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2705 | tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); |
| 2706 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2707 | if (!currentsd || !physdev_list || !logdev_list || !tmpdevice) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2708 | dev_err(&h->pdev->dev, "out of memory\n"); |
| 2709 | goto out; |
| 2710 | } |
| 2711 | memset(lunzerobits, 0, sizeof(lunzerobits)); |
| 2712 | |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 2713 | if (hpsa_gather_lun_info(h, reportlunsize, |
| 2714 | (struct ReportLUNdata *) physdev_list, &nphysicals, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2715 | &physical_mode, logdev_list, &nlogicals)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2716 | goto out; |
| 2717 | |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 2718 | /* We might see up to the maximum number of logical and physical disks |
| 2719 | * plus external target devices, and a device for the local RAID |
| 2720 | * controller. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2721 | */ |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 2722 | ndevs_to_allocate = nphysicals + nlogicals + MAX_EXT_TARGETS + 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2723 | |
| 2724 | /* Allocate the per device structures */ |
| 2725 | for (i = 0; i < ndevs_to_allocate; i++) { |
Scott Teel | b7ec021 | 2011-10-26 16:21:12 -0500 | [diff] [blame] | 2726 | if (i >= HPSA_MAX_DEVICES) { |
| 2727 | dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded." |
| 2728 | " %d devices ignored.\n", HPSA_MAX_DEVICES, |
| 2729 | ndevs_to_allocate - HPSA_MAX_DEVICES); |
| 2730 | break; |
| 2731 | } |
| 2732 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2733 | currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL); |
| 2734 | if (!currentsd[i]) { |
| 2735 | dev_warn(&h->pdev->dev, "out of memory at %s:%d\n", |
| 2736 | __FILE__, __LINE__); |
| 2737 | goto out; |
| 2738 | } |
| 2739 | ndev_allocated++; |
| 2740 | } |
| 2741 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2742 | if (unlikely(is_scsi_rev_5(h))) |
| 2743 | raid_ctlr_position = 0; |
| 2744 | else |
| 2745 | raid_ctlr_position = nphysicals + nlogicals; |
| 2746 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2747 | /* adjust our table of devices */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2748 | n_ext_target_devs = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2749 | for (i = 0; i < nphysicals + nlogicals + 1; i++) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2750 | u8 *lunaddrbytes, is_OBDR = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2751 | |
| 2752 | /* Figure out where the LUN ID info is coming from */ |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2753 | lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position, |
| 2754 | i, nphysicals, nlogicals, physdev_list, logdev_list); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2755 | /* skip masked physical devices. */ |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2756 | if (lunaddrbytes[3] & 0xC0 && |
| 2757 | i < nphysicals + (raid_ctlr_position == 0)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2758 | continue; |
| 2759 | |
| 2760 | /* Get device type, vendor, model, device id */ |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2761 | if (hpsa_update_device_info(h, lunaddrbytes, tmpdevice, |
| 2762 | &is_OBDR)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2763 | continue; /* skip it if we can't talk to it. */ |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2764 | figure_bus_target_lun(h, lunaddrbytes, tmpdevice); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2765 | this_device = currentsd[ncurrent]; |
| 2766 | |
| 2767 | /* |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2768 | * For external target devices, we have to insert a LUN 0 which |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2769 | * doesn't show up in CCISS_REPORT_PHYSICAL data, but there |
| 2770 | * is nonetheless an enclosure device there. We have to |
| 2771 | * present that otherwise linux won't find anything if |
| 2772 | * there is no lun 0. |
| 2773 | */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2774 | if (add_ext_target_dev(h, tmpdevice, this_device, |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2775 | lunaddrbytes, lunzerobits, |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2776 | &n_ext_target_devs)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2777 | ncurrent++; |
| 2778 | this_device = currentsd[ncurrent]; |
| 2779 | } |
| 2780 | |
| 2781 | *this_device = *tmpdevice; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2782 | |
| 2783 | switch (this_device->devtype) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2784 | case TYPE_ROM: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2785 | /* We don't *really* support actual CD-ROM devices, |
| 2786 | * just "One Button Disaster Recovery" tape drive |
| 2787 | * which temporarily pretends to be a CD-ROM drive. |
| 2788 | * So we check that the device is really an OBDR tape |
| 2789 | * device by checking for "$DR-10" in bytes 43-48 of |
| 2790 | * the inquiry data. |
| 2791 | */ |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2792 | if (is_OBDR) |
| 2793 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2794 | break; |
| 2795 | case TYPE_DISK: |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2796 | if (i >= nphysicals) { |
| 2797 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2798 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2799 | } |
| 2800 | if (physical_mode == HPSA_REPORT_PHYS_EXTENDED) { |
| 2801 | memcpy(&this_device->ioaccel_handle, |
| 2802 | &lunaddrbytes[20], |
| 2803 | sizeof(this_device->ioaccel_handle)); |
| 2804 | ncurrent++; |
| 2805 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2806 | break; |
| 2807 | case TYPE_TAPE: |
| 2808 | case TYPE_MEDIUM_CHANGER: |
| 2809 | ncurrent++; |
| 2810 | break; |
| 2811 | case TYPE_RAID: |
| 2812 | /* Only present the Smartarray HBA as a RAID controller. |
| 2813 | * If it's a RAID controller other than the HBA itself |
| 2814 | * (an external RAID controller, MSA500 or similar) |
| 2815 | * don't present it. |
| 2816 | */ |
| 2817 | if (!is_hba_lunid(lunaddrbytes)) |
| 2818 | break; |
| 2819 | ncurrent++; |
| 2820 | break; |
| 2821 | default: |
| 2822 | break; |
| 2823 | } |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 2824 | if (ncurrent >= HPSA_MAX_DEVICES) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2825 | break; |
| 2826 | } |
| 2827 | adjust_hpsa_scsi_table(h, hostno, currentsd, ncurrent); |
| 2828 | out: |
| 2829 | kfree(tmpdevice); |
| 2830 | for (i = 0; i < ndev_allocated; i++) |
| 2831 | kfree(currentsd[i]); |
| 2832 | kfree(currentsd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2833 | kfree(physdev_list); |
| 2834 | kfree(logdev_list); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | /* hpsa_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci |
| 2838 | * dma mapping and fills in the scatter gather entries of the |
| 2839 | * hpsa command, cp. |
| 2840 | */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2841 | static int hpsa_scatter_gather(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2842 | struct CommandList *cp, |
| 2843 | struct scsi_cmnd *cmd) |
| 2844 | { |
| 2845 | unsigned int len; |
| 2846 | struct scatterlist *sg; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2847 | u64 addr64; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2848 | int use_sg, i, sg_index, chained; |
| 2849 | struct SGDescriptor *curr_sg; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2850 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2851 | BUG_ON(scsi_sg_count(cmd) > h->maxsgentries); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2852 | |
| 2853 | use_sg = scsi_dma_map(cmd); |
| 2854 | if (use_sg < 0) |
| 2855 | return use_sg; |
| 2856 | |
| 2857 | if (!use_sg) |
| 2858 | goto sglist_finished; |
| 2859 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2860 | curr_sg = cp->SG; |
| 2861 | chained = 0; |
| 2862 | sg_index = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2863 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2864 | if (i == h->max_cmd_sg_entries - 1 && |
| 2865 | use_sg > h->max_cmd_sg_entries) { |
| 2866 | chained = 1; |
| 2867 | curr_sg = h->cmd_sg_list[cp->cmdindex]; |
| 2868 | sg_index = 0; |
| 2869 | } |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2870 | addr64 = (u64) sg_dma_address(sg); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2871 | len = sg_dma_len(sg); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2872 | curr_sg->Addr.lower = (u32) (addr64 & 0x0FFFFFFFFULL); |
| 2873 | curr_sg->Addr.upper = (u32) ((addr64 >> 32) & 0x0FFFFFFFFULL); |
| 2874 | curr_sg->Len = len; |
Matt Gates | e1d9cbf | 2014-02-18 13:55:12 -0600 | [diff] [blame] | 2875 | curr_sg->Ext = (i < scsi_sg_count(cmd) - 1) ? 0 : HPSA_SG_LAST; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2876 | curr_sg++; |
| 2877 | } |
| 2878 | |
| 2879 | if (use_sg + chained > h->maxSG) |
| 2880 | h->maxSG = use_sg + chained; |
| 2881 | |
| 2882 | if (chained) { |
| 2883 | cp->Header.SGList = h->max_cmd_sg_entries; |
| 2884 | cp->Header.SGTotal = (u16) (use_sg + 1); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2885 | if (hpsa_map_sg_chain_block(h, cp)) { |
| 2886 | scsi_dma_unmap(cmd); |
| 2887 | return -1; |
| 2888 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2889 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | sglist_finished: |
| 2893 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2894 | cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */ |
| 2895 | cp->Header.SGTotal = (u16) use_sg; /* total sgs in this cmd list */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2896 | return 0; |
| 2897 | } |
| 2898 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2899 | #define IO_ACCEL_INELIGIBLE (1) |
| 2900 | static int fixup_ioaccel_cdb(u8 *cdb, int *cdb_len) |
| 2901 | { |
| 2902 | int is_write = 0; |
| 2903 | u32 block; |
| 2904 | u32 block_cnt; |
| 2905 | |
| 2906 | /* Perform some CDB fixups if needed using 10 byte reads/writes only */ |
| 2907 | switch (cdb[0]) { |
| 2908 | case WRITE_6: |
| 2909 | case WRITE_12: |
| 2910 | is_write = 1; |
| 2911 | case READ_6: |
| 2912 | case READ_12: |
| 2913 | if (*cdb_len == 6) { |
| 2914 | block = (((u32) cdb[2]) << 8) | cdb[3]; |
| 2915 | block_cnt = cdb[4]; |
| 2916 | } else { |
| 2917 | BUG_ON(*cdb_len != 12); |
| 2918 | block = (((u32) cdb[2]) << 24) | |
| 2919 | (((u32) cdb[3]) << 16) | |
| 2920 | (((u32) cdb[4]) << 8) | |
| 2921 | cdb[5]; |
| 2922 | block_cnt = |
| 2923 | (((u32) cdb[6]) << 24) | |
| 2924 | (((u32) cdb[7]) << 16) | |
| 2925 | (((u32) cdb[8]) << 8) | |
| 2926 | cdb[9]; |
| 2927 | } |
| 2928 | if (block_cnt > 0xffff) |
| 2929 | return IO_ACCEL_INELIGIBLE; |
| 2930 | |
| 2931 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 2932 | cdb[1] = 0; |
| 2933 | cdb[2] = (u8) (block >> 24); |
| 2934 | cdb[3] = (u8) (block >> 16); |
| 2935 | cdb[4] = (u8) (block >> 8); |
| 2936 | cdb[5] = (u8) (block); |
| 2937 | cdb[6] = 0; |
| 2938 | cdb[7] = (u8) (block_cnt >> 8); |
| 2939 | cdb[8] = (u8) (block_cnt); |
| 2940 | cdb[9] = 0; |
| 2941 | *cdb_len = 10; |
| 2942 | break; |
| 2943 | } |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2947 | static int hpsa_scsi_ioaccel1_queue_command(struct ctlr_info *h, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2948 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
| 2949 | u8 *scsi3addr) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2950 | { |
| 2951 | struct scsi_cmnd *cmd = c->scsi_cmd; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2952 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 2953 | unsigned int len; |
| 2954 | unsigned int total_len = 0; |
| 2955 | struct scatterlist *sg; |
| 2956 | u64 addr64; |
| 2957 | int use_sg, i; |
| 2958 | struct SGDescriptor *curr_sg; |
| 2959 | u32 control = IOACCEL1_CONTROL_SIMPLEQUEUE; |
| 2960 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2961 | /* TODO: implement chaining support */ |
| 2962 | if (scsi_sg_count(cmd) > h->ioaccel_maxsg) |
| 2963 | return IO_ACCEL_INELIGIBLE; |
| 2964 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2965 | BUG_ON(cmd->cmd_len > IOACCEL1_IOFLAGS_CDBLEN_MAX); |
| 2966 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2967 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) |
| 2968 | return IO_ACCEL_INELIGIBLE; |
| 2969 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2970 | c->cmd_type = CMD_IOACCEL1; |
| 2971 | |
| 2972 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 2973 | c->busaddr = (u32) h->ioaccel_cmd_pool_dhandle + |
| 2974 | (c->cmdindex * sizeof(*cp)); |
| 2975 | BUG_ON(c->busaddr & 0x0000007F); |
| 2976 | |
| 2977 | use_sg = scsi_dma_map(cmd); |
| 2978 | if (use_sg < 0) |
| 2979 | return use_sg; |
| 2980 | |
| 2981 | if (use_sg) { |
| 2982 | curr_sg = cp->SG; |
| 2983 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 2984 | addr64 = (u64) sg_dma_address(sg); |
| 2985 | len = sg_dma_len(sg); |
| 2986 | total_len += len; |
| 2987 | curr_sg->Addr.lower = (u32) (addr64 & 0x0FFFFFFFFULL); |
| 2988 | curr_sg->Addr.upper = |
| 2989 | (u32) ((addr64 >> 32) & 0x0FFFFFFFFULL); |
| 2990 | curr_sg->Len = len; |
| 2991 | |
| 2992 | if (i == (scsi_sg_count(cmd) - 1)) |
| 2993 | curr_sg->Ext = HPSA_SG_LAST; |
| 2994 | else |
| 2995 | curr_sg->Ext = 0; /* we are not chaining */ |
| 2996 | curr_sg++; |
| 2997 | } |
| 2998 | |
| 2999 | switch (cmd->sc_data_direction) { |
| 3000 | case DMA_TO_DEVICE: |
| 3001 | control |= IOACCEL1_CONTROL_DATA_OUT; |
| 3002 | break; |
| 3003 | case DMA_FROM_DEVICE: |
| 3004 | control |= IOACCEL1_CONTROL_DATA_IN; |
| 3005 | break; |
| 3006 | case DMA_NONE: |
| 3007 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 3008 | break; |
| 3009 | default: |
| 3010 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 3011 | cmd->sc_data_direction); |
| 3012 | BUG(); |
| 3013 | break; |
| 3014 | } |
| 3015 | } else { |
| 3016 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 3017 | } |
| 3018 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3019 | c->Header.SGList = use_sg; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3020 | /* Fill out the command structure to submit */ |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3021 | cp->dev_handle = ioaccel_handle & 0xFFFF; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3022 | cp->transfer_len = total_len; |
| 3023 | cp->io_flags = IOACCEL1_IOFLAGS_IO_REQ | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3024 | (cdb_len & IOACCEL1_IOFLAGS_CDBLEN_MASK); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3025 | cp->control = control; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3026 | memcpy(cp->CDB, cdb, cdb_len); |
| 3027 | memcpy(cp->CISS_LUN, scsi3addr, 8); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3028 | /* Tag was already set at init time. */ |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3029 | enqueue_cmd_and_start_io(h, c); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3030 | return 0; |
| 3031 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3032 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3033 | /* |
| 3034 | * Queue a command directly to a device behind the controller using the |
| 3035 | * I/O accelerator path. |
| 3036 | */ |
| 3037 | static int hpsa_scsi_ioaccel_direct_map(struct ctlr_info *h, |
| 3038 | struct CommandList *c) |
| 3039 | { |
| 3040 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3041 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 3042 | |
| 3043 | return hpsa_scsi_ioaccel_queue_command(h, c, dev->ioaccel_handle, |
| 3044 | cmd->cmnd, cmd->cmd_len, dev->scsi3addr); |
| 3045 | } |
| 3046 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3047 | /* |
| 3048 | * Set encryption parameters for the ioaccel2 request |
| 3049 | */ |
| 3050 | static void set_encrypt_ioaccel2(struct ctlr_info *h, |
| 3051 | struct CommandList *c, struct io_accel2_cmd *cp) |
| 3052 | { |
| 3053 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3054 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 3055 | struct raid_map_data *map = &dev->raid_map; |
| 3056 | u64 first_block; |
| 3057 | |
| 3058 | BUG_ON(!(dev->offload_config && dev->offload_enabled)); |
| 3059 | |
| 3060 | /* Are we doing encryption on this device */ |
| 3061 | if (!(map->flags & RAID_MAP_FLAG_ENCRYPT_ON)) |
| 3062 | return; |
| 3063 | /* Set the data encryption key index. */ |
| 3064 | cp->dekindex = map->dekindex; |
| 3065 | |
| 3066 | /* Set the encryption enable flag, encoded into direction field. */ |
| 3067 | cp->direction |= IOACCEL2_DIRECTION_ENCRYPT_MASK; |
| 3068 | |
| 3069 | /* Set encryption tweak values based on logical block address |
| 3070 | * If block size is 512, tweak value is LBA. |
| 3071 | * For other block sizes, tweak is (LBA * block size)/ 512) |
| 3072 | */ |
| 3073 | switch (cmd->cmnd[0]) { |
| 3074 | /* Required? 6-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 3075 | case WRITE_6: |
| 3076 | case READ_6: |
| 3077 | if (map->volume_blk_size == 512) { |
| 3078 | cp->tweak_lower = |
| 3079 | (((u32) cmd->cmnd[2]) << 8) | |
| 3080 | cmd->cmnd[3]; |
| 3081 | cp->tweak_upper = 0; |
| 3082 | } else { |
| 3083 | first_block = |
| 3084 | (((u64) cmd->cmnd[2]) << 8) | |
| 3085 | cmd->cmnd[3]; |
| 3086 | first_block = (first_block * map->volume_blk_size)/512; |
| 3087 | cp->tweak_lower = (u32)first_block; |
| 3088 | cp->tweak_upper = (u32)(first_block >> 32); |
| 3089 | } |
| 3090 | break; |
| 3091 | case WRITE_10: |
| 3092 | case READ_10: |
| 3093 | if (map->volume_blk_size == 512) { |
| 3094 | cp->tweak_lower = |
| 3095 | (((u32) cmd->cmnd[2]) << 24) | |
| 3096 | (((u32) cmd->cmnd[3]) << 16) | |
| 3097 | (((u32) cmd->cmnd[4]) << 8) | |
| 3098 | cmd->cmnd[5]; |
| 3099 | cp->tweak_upper = 0; |
| 3100 | } else { |
| 3101 | first_block = |
| 3102 | (((u64) cmd->cmnd[2]) << 24) | |
| 3103 | (((u64) cmd->cmnd[3]) << 16) | |
| 3104 | (((u64) cmd->cmnd[4]) << 8) | |
| 3105 | cmd->cmnd[5]; |
| 3106 | first_block = (first_block * map->volume_blk_size)/512; |
| 3107 | cp->tweak_lower = (u32)first_block; |
| 3108 | cp->tweak_upper = (u32)(first_block >> 32); |
| 3109 | } |
| 3110 | break; |
| 3111 | /* Required? 12-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 3112 | case WRITE_12: |
| 3113 | case READ_12: |
| 3114 | if (map->volume_blk_size == 512) { |
| 3115 | cp->tweak_lower = |
| 3116 | (((u32) cmd->cmnd[2]) << 24) | |
| 3117 | (((u32) cmd->cmnd[3]) << 16) | |
| 3118 | (((u32) cmd->cmnd[4]) << 8) | |
| 3119 | cmd->cmnd[5]; |
| 3120 | cp->tweak_upper = 0; |
| 3121 | } else { |
| 3122 | first_block = |
| 3123 | (((u64) cmd->cmnd[2]) << 24) | |
| 3124 | (((u64) cmd->cmnd[3]) << 16) | |
| 3125 | (((u64) cmd->cmnd[4]) << 8) | |
| 3126 | cmd->cmnd[5]; |
| 3127 | first_block = (first_block * map->volume_blk_size)/512; |
| 3128 | cp->tweak_lower = (u32)first_block; |
| 3129 | cp->tweak_upper = (u32)(first_block >> 32); |
| 3130 | } |
| 3131 | break; |
| 3132 | case WRITE_16: |
| 3133 | case READ_16: |
| 3134 | if (map->volume_blk_size == 512) { |
| 3135 | cp->tweak_lower = |
| 3136 | (((u32) cmd->cmnd[6]) << 24) | |
| 3137 | (((u32) cmd->cmnd[7]) << 16) | |
| 3138 | (((u32) cmd->cmnd[8]) << 8) | |
| 3139 | cmd->cmnd[9]; |
| 3140 | cp->tweak_upper = |
| 3141 | (((u32) cmd->cmnd[2]) << 24) | |
| 3142 | (((u32) cmd->cmnd[3]) << 16) | |
| 3143 | (((u32) cmd->cmnd[4]) << 8) | |
| 3144 | cmd->cmnd[5]; |
| 3145 | } else { |
| 3146 | first_block = |
| 3147 | (((u64) cmd->cmnd[2]) << 56) | |
| 3148 | (((u64) cmd->cmnd[3]) << 48) | |
| 3149 | (((u64) cmd->cmnd[4]) << 40) | |
| 3150 | (((u64) cmd->cmnd[5]) << 32) | |
| 3151 | (((u64) cmd->cmnd[6]) << 24) | |
| 3152 | (((u64) cmd->cmnd[7]) << 16) | |
| 3153 | (((u64) cmd->cmnd[8]) << 8) | |
| 3154 | cmd->cmnd[9]; |
| 3155 | first_block = (first_block * map->volume_blk_size)/512; |
| 3156 | cp->tweak_lower = (u32)first_block; |
| 3157 | cp->tweak_upper = (u32)(first_block >> 32); |
| 3158 | } |
| 3159 | break; |
| 3160 | default: |
| 3161 | dev_err(&h->pdev->dev, |
| 3162 | "ERROR: %s: IOACCEL request CDB size not supported for encryption\n", |
| 3163 | __func__); |
| 3164 | BUG(); |
| 3165 | break; |
| 3166 | } |
| 3167 | } |
| 3168 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3169 | static int hpsa_scsi_ioaccel2_queue_command(struct ctlr_info *h, |
| 3170 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
| 3171 | u8 *scsi3addr) |
| 3172 | { |
| 3173 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3174 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 3175 | struct ioaccel2_sg_element *curr_sg; |
| 3176 | int use_sg, i; |
| 3177 | struct scatterlist *sg; |
| 3178 | u64 addr64; |
| 3179 | u32 len; |
| 3180 | u32 total_len = 0; |
| 3181 | |
| 3182 | if (scsi_sg_count(cmd) > h->ioaccel_maxsg) |
| 3183 | return IO_ACCEL_INELIGIBLE; |
| 3184 | |
| 3185 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) |
| 3186 | return IO_ACCEL_INELIGIBLE; |
| 3187 | c->cmd_type = CMD_IOACCEL2; |
| 3188 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 3189 | c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle + |
| 3190 | (c->cmdindex * sizeof(*cp)); |
| 3191 | BUG_ON(c->busaddr & 0x0000007F); |
| 3192 | |
| 3193 | memset(cp, 0, sizeof(*cp)); |
| 3194 | cp->IU_type = IOACCEL2_IU_TYPE; |
| 3195 | |
| 3196 | use_sg = scsi_dma_map(cmd); |
| 3197 | if (use_sg < 0) |
| 3198 | return use_sg; |
| 3199 | |
| 3200 | if (use_sg) { |
| 3201 | BUG_ON(use_sg > IOACCEL2_MAXSGENTRIES); |
| 3202 | curr_sg = cp->sg; |
| 3203 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 3204 | addr64 = (u64) sg_dma_address(sg); |
| 3205 | len = sg_dma_len(sg); |
| 3206 | total_len += len; |
| 3207 | curr_sg->address = cpu_to_le64(addr64); |
| 3208 | curr_sg->length = cpu_to_le32(len); |
| 3209 | curr_sg->reserved[0] = 0; |
| 3210 | curr_sg->reserved[1] = 0; |
| 3211 | curr_sg->reserved[2] = 0; |
| 3212 | curr_sg->chain_indicator = 0; |
| 3213 | curr_sg++; |
| 3214 | } |
| 3215 | |
| 3216 | switch (cmd->sc_data_direction) { |
| 3217 | case DMA_TO_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3218 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3219 | cp->direction |= IOACCEL2_DIR_DATA_OUT; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3220 | break; |
| 3221 | case DMA_FROM_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3222 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3223 | cp->direction |= IOACCEL2_DIR_DATA_IN; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3224 | break; |
| 3225 | case DMA_NONE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3226 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3227 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3228 | break; |
| 3229 | default: |
| 3230 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 3231 | cmd->sc_data_direction); |
| 3232 | BUG(); |
| 3233 | break; |
| 3234 | } |
| 3235 | } else { |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3236 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3237 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3238 | } |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3239 | |
| 3240 | /* Set encryption parameters, if necessary */ |
| 3241 | set_encrypt_ioaccel2(h, c, cp); |
| 3242 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3243 | cp->scsi_nexus = ioaccel_handle; |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3244 | cp->Tag = (c->cmdindex << DIRECT_LOOKUP_SHIFT) | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3245 | DIRECT_LOOKUP_BIT; |
| 3246 | memcpy(cp->cdb, cdb, sizeof(cp->cdb)); |
| 3247 | memset(cp->cciss_lun, 0, sizeof(cp->cciss_lun)); |
| 3248 | cp->cmd_priority_task_attr = 0; |
| 3249 | |
| 3250 | /* fill in sg elements */ |
| 3251 | cp->sg_count = (u8) use_sg; |
| 3252 | |
| 3253 | cp->data_len = cpu_to_le32(total_len); |
| 3254 | cp->err_ptr = cpu_to_le64(c->busaddr + |
| 3255 | offsetof(struct io_accel2_cmd, error_data)); |
| 3256 | cp->err_len = cpu_to_le32((u32) sizeof(cp->error_data)); |
| 3257 | |
| 3258 | enqueue_cmd_and_start_io(h, c); |
| 3259 | return 0; |
| 3260 | } |
| 3261 | |
| 3262 | /* |
| 3263 | * Queue a command to the correct I/O accelerator path. |
| 3264 | */ |
| 3265 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 3266 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
| 3267 | u8 *scsi3addr) |
| 3268 | { |
| 3269 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 3270 | return hpsa_scsi_ioaccel1_queue_command(h, c, ioaccel_handle, |
| 3271 | cdb, cdb_len, scsi3addr); |
| 3272 | else |
| 3273 | return hpsa_scsi_ioaccel2_queue_command(h, c, ioaccel_handle, |
| 3274 | cdb, cdb_len, scsi3addr); |
| 3275 | } |
| 3276 | |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3277 | static void raid_map_helper(struct raid_map_data *map, |
| 3278 | int offload_to_mirror, u32 *map_index, u32 *current_group) |
| 3279 | { |
| 3280 | if (offload_to_mirror == 0) { |
| 3281 | /* use physical disk in the first mirrored group. */ |
| 3282 | *map_index %= map->data_disks_per_row; |
| 3283 | return; |
| 3284 | } |
| 3285 | do { |
| 3286 | /* determine mirror group that *map_index indicates */ |
| 3287 | *current_group = *map_index / map->data_disks_per_row; |
| 3288 | if (offload_to_mirror == *current_group) |
| 3289 | continue; |
| 3290 | if (*current_group < (map->layout_map_count - 1)) { |
| 3291 | /* select map index from next group */ |
| 3292 | *map_index += map->data_disks_per_row; |
| 3293 | (*current_group)++; |
| 3294 | } else { |
| 3295 | /* select map index from first group */ |
| 3296 | *map_index %= map->data_disks_per_row; |
| 3297 | *current_group = 0; |
| 3298 | } |
| 3299 | } while (offload_to_mirror != *current_group); |
| 3300 | } |
| 3301 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3302 | /* |
| 3303 | * Attempt to perform offload RAID mapping for a logical volume I/O. |
| 3304 | */ |
| 3305 | static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h, |
| 3306 | struct CommandList *c) |
| 3307 | { |
| 3308 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3309 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 3310 | struct raid_map_data *map = &dev->raid_map; |
| 3311 | struct raid_map_disk_data *dd = &map->data[0]; |
| 3312 | int is_write = 0; |
| 3313 | u32 map_index; |
| 3314 | u64 first_block, last_block; |
| 3315 | u32 block_cnt; |
| 3316 | u32 blocks_per_row; |
| 3317 | u64 first_row, last_row; |
| 3318 | u32 first_row_offset, last_row_offset; |
| 3319 | u32 first_column, last_column; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3320 | u64 r0_first_row, r0_last_row; |
| 3321 | u32 r5or6_blocks_per_row; |
| 3322 | u64 r5or6_first_row, r5or6_last_row; |
| 3323 | u32 r5or6_first_row_offset, r5or6_last_row_offset; |
| 3324 | u32 r5or6_first_column, r5or6_last_column; |
| 3325 | u32 total_disks_per_row; |
| 3326 | u32 stripesize; |
| 3327 | u32 first_group, last_group, current_group; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3328 | u32 map_row; |
| 3329 | u32 disk_handle; |
| 3330 | u64 disk_block; |
| 3331 | u32 disk_block_cnt; |
| 3332 | u8 cdb[16]; |
| 3333 | u8 cdb_len; |
| 3334 | #if BITS_PER_LONG == 32 |
| 3335 | u64 tmpdiv; |
| 3336 | #endif |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3337 | int offload_to_mirror; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3338 | |
| 3339 | BUG_ON(!(dev->offload_config && dev->offload_enabled)); |
| 3340 | |
| 3341 | /* check for valid opcode, get LBA and block count */ |
| 3342 | switch (cmd->cmnd[0]) { |
| 3343 | case WRITE_6: |
| 3344 | is_write = 1; |
| 3345 | case READ_6: |
| 3346 | first_block = |
| 3347 | (((u64) cmd->cmnd[2]) << 8) | |
| 3348 | cmd->cmnd[3]; |
| 3349 | block_cnt = cmd->cmnd[4]; |
| 3350 | break; |
| 3351 | case WRITE_10: |
| 3352 | is_write = 1; |
| 3353 | case READ_10: |
| 3354 | first_block = |
| 3355 | (((u64) cmd->cmnd[2]) << 24) | |
| 3356 | (((u64) cmd->cmnd[3]) << 16) | |
| 3357 | (((u64) cmd->cmnd[4]) << 8) | |
| 3358 | cmd->cmnd[5]; |
| 3359 | block_cnt = |
| 3360 | (((u32) cmd->cmnd[7]) << 8) | |
| 3361 | cmd->cmnd[8]; |
| 3362 | break; |
| 3363 | case WRITE_12: |
| 3364 | is_write = 1; |
| 3365 | case READ_12: |
| 3366 | first_block = |
| 3367 | (((u64) cmd->cmnd[2]) << 24) | |
| 3368 | (((u64) cmd->cmnd[3]) << 16) | |
| 3369 | (((u64) cmd->cmnd[4]) << 8) | |
| 3370 | cmd->cmnd[5]; |
| 3371 | block_cnt = |
| 3372 | (((u32) cmd->cmnd[6]) << 24) | |
| 3373 | (((u32) cmd->cmnd[7]) << 16) | |
| 3374 | (((u32) cmd->cmnd[8]) << 8) | |
| 3375 | cmd->cmnd[9]; |
| 3376 | break; |
| 3377 | case WRITE_16: |
| 3378 | is_write = 1; |
| 3379 | case READ_16: |
| 3380 | first_block = |
| 3381 | (((u64) cmd->cmnd[2]) << 56) | |
| 3382 | (((u64) cmd->cmnd[3]) << 48) | |
| 3383 | (((u64) cmd->cmnd[4]) << 40) | |
| 3384 | (((u64) cmd->cmnd[5]) << 32) | |
| 3385 | (((u64) cmd->cmnd[6]) << 24) | |
| 3386 | (((u64) cmd->cmnd[7]) << 16) | |
| 3387 | (((u64) cmd->cmnd[8]) << 8) | |
| 3388 | cmd->cmnd[9]; |
| 3389 | block_cnt = |
| 3390 | (((u32) cmd->cmnd[10]) << 24) | |
| 3391 | (((u32) cmd->cmnd[11]) << 16) | |
| 3392 | (((u32) cmd->cmnd[12]) << 8) | |
| 3393 | cmd->cmnd[13]; |
| 3394 | break; |
| 3395 | default: |
| 3396 | return IO_ACCEL_INELIGIBLE; /* process via normal I/O path */ |
| 3397 | } |
| 3398 | BUG_ON(block_cnt == 0); |
| 3399 | last_block = first_block + block_cnt - 1; |
| 3400 | |
| 3401 | /* check for write to non-RAID-0 */ |
| 3402 | if (is_write && dev->raid_level != 0) |
| 3403 | return IO_ACCEL_INELIGIBLE; |
| 3404 | |
| 3405 | /* check for invalid block or wraparound */ |
| 3406 | if (last_block >= map->volume_blk_cnt || last_block < first_block) |
| 3407 | return IO_ACCEL_INELIGIBLE; |
| 3408 | |
| 3409 | /* calculate stripe information for the request */ |
| 3410 | blocks_per_row = map->data_disks_per_row * map->strip_size; |
| 3411 | #if BITS_PER_LONG == 32 |
| 3412 | tmpdiv = first_block; |
| 3413 | (void) do_div(tmpdiv, blocks_per_row); |
| 3414 | first_row = tmpdiv; |
| 3415 | tmpdiv = last_block; |
| 3416 | (void) do_div(tmpdiv, blocks_per_row); |
| 3417 | last_row = tmpdiv; |
| 3418 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 3419 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
| 3420 | tmpdiv = first_row_offset; |
| 3421 | (void) do_div(tmpdiv, map->strip_size); |
| 3422 | first_column = tmpdiv; |
| 3423 | tmpdiv = last_row_offset; |
| 3424 | (void) do_div(tmpdiv, map->strip_size); |
| 3425 | last_column = tmpdiv; |
| 3426 | #else |
| 3427 | first_row = first_block / blocks_per_row; |
| 3428 | last_row = last_block / blocks_per_row; |
| 3429 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 3430 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
| 3431 | first_column = first_row_offset / map->strip_size; |
| 3432 | last_column = last_row_offset / map->strip_size; |
| 3433 | #endif |
| 3434 | |
| 3435 | /* if this isn't a single row/column then give to the controller */ |
| 3436 | if ((first_row != last_row) || (first_column != last_column)) |
| 3437 | return IO_ACCEL_INELIGIBLE; |
| 3438 | |
| 3439 | /* proceeding with driver mapping */ |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3440 | total_disks_per_row = map->data_disks_per_row + |
| 3441 | map->metadata_disks_per_row; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3442 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
| 3443 | map->row_cnt; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3444 | map_index = (map_row * total_disks_per_row) + first_column; |
| 3445 | |
| 3446 | switch (dev->raid_level) { |
| 3447 | case HPSA_RAID_0: |
| 3448 | break; /* nothing special to do */ |
| 3449 | case HPSA_RAID_1: |
| 3450 | /* Handles load balance across RAID 1 members. |
| 3451 | * (2-drive R1 and R10 with even # of drives.) |
| 3452 | * Appropriate for SSDs, not optimal for HDDs |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3453 | */ |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3454 | BUG_ON(map->layout_map_count != 2); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3455 | if (dev->offload_to_mirror) |
| 3456 | map_index += map->data_disks_per_row; |
| 3457 | dev->offload_to_mirror = !dev->offload_to_mirror; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3458 | break; |
| 3459 | case HPSA_RAID_ADM: |
| 3460 | /* Handles N-way mirrors (R1-ADM) |
| 3461 | * and R10 with # of drives divisible by 3.) |
| 3462 | */ |
| 3463 | BUG_ON(map->layout_map_count != 3); |
| 3464 | |
| 3465 | offload_to_mirror = dev->offload_to_mirror; |
| 3466 | raid_map_helper(map, offload_to_mirror, |
| 3467 | &map_index, ¤t_group); |
| 3468 | /* set mirror group to use next time */ |
| 3469 | offload_to_mirror = |
| 3470 | (offload_to_mirror >= map->layout_map_count - 1) |
| 3471 | ? 0 : offload_to_mirror + 1; |
| 3472 | /* FIXME: remove after debug/dev */ |
| 3473 | BUG_ON(offload_to_mirror >= map->layout_map_count); |
| 3474 | dev_warn(&h->pdev->dev, |
| 3475 | "DEBUG: Using physical disk map index %d from mirror group %d\n", |
| 3476 | map_index, offload_to_mirror); |
| 3477 | dev->offload_to_mirror = offload_to_mirror; |
| 3478 | /* Avoid direct use of dev->offload_to_mirror within this |
| 3479 | * function since multiple threads might simultaneously |
| 3480 | * increment it beyond the range of dev->layout_map_count -1. |
| 3481 | */ |
| 3482 | break; |
| 3483 | case HPSA_RAID_5: |
| 3484 | case HPSA_RAID_6: |
| 3485 | if (map->layout_map_count <= 1) |
| 3486 | break; |
| 3487 | |
| 3488 | /* Verify first and last block are in same RAID group */ |
| 3489 | r5or6_blocks_per_row = |
| 3490 | map->strip_size * map->data_disks_per_row; |
| 3491 | BUG_ON(r5or6_blocks_per_row == 0); |
| 3492 | stripesize = r5or6_blocks_per_row * map->layout_map_count; |
| 3493 | #if BITS_PER_LONG == 32 |
| 3494 | tmpdiv = first_block; |
| 3495 | first_group = do_div(tmpdiv, stripesize); |
| 3496 | tmpdiv = first_group; |
| 3497 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 3498 | first_group = tmpdiv; |
| 3499 | tmpdiv = last_block; |
| 3500 | last_group = do_div(tmpdiv, stripesize); |
| 3501 | tmpdiv = last_group; |
| 3502 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 3503 | last_group = tmpdiv; |
| 3504 | #else |
| 3505 | first_group = (first_block % stripesize) / r5or6_blocks_per_row; |
| 3506 | last_group = (last_block % stripesize) / r5or6_blocks_per_row; |
| 3507 | if (first_group != last_group) |
| 3508 | #endif |
| 3509 | return IO_ACCEL_INELIGIBLE; |
| 3510 | |
| 3511 | /* Verify request is in a single row of RAID 5/6 */ |
| 3512 | #if BITS_PER_LONG == 32 |
| 3513 | tmpdiv = first_block; |
| 3514 | (void) do_div(tmpdiv, stripesize); |
| 3515 | first_row = r5or6_first_row = r0_first_row = tmpdiv; |
| 3516 | tmpdiv = last_block; |
| 3517 | (void) do_div(tmpdiv, stripesize); |
| 3518 | r5or6_last_row = r0_last_row = tmpdiv; |
| 3519 | #else |
| 3520 | first_row = r5or6_first_row = r0_first_row = |
| 3521 | first_block / stripesize; |
| 3522 | r5or6_last_row = r0_last_row = last_block / stripesize; |
| 3523 | #endif |
| 3524 | if (r5or6_first_row != r5or6_last_row) |
| 3525 | return IO_ACCEL_INELIGIBLE; |
| 3526 | |
| 3527 | |
| 3528 | /* Verify request is in a single column */ |
| 3529 | #if BITS_PER_LONG == 32 |
| 3530 | tmpdiv = first_block; |
| 3531 | first_row_offset = do_div(tmpdiv, stripesize); |
| 3532 | tmpdiv = first_row_offset; |
| 3533 | first_row_offset = (u32) do_div(tmpdiv, r5or6_blocks_per_row); |
| 3534 | r5or6_first_row_offset = first_row_offset; |
| 3535 | tmpdiv = last_block; |
| 3536 | r5or6_last_row_offset = do_div(tmpdiv, stripesize); |
| 3537 | tmpdiv = r5or6_last_row_offset; |
| 3538 | r5or6_last_row_offset = do_div(tmpdiv, r5or6_blocks_per_row); |
| 3539 | tmpdiv = r5or6_first_row_offset; |
| 3540 | (void) do_div(tmpdiv, map->strip_size); |
| 3541 | first_column = r5or6_first_column = tmpdiv; |
| 3542 | tmpdiv = r5or6_last_row_offset; |
| 3543 | (void) do_div(tmpdiv, map->strip_size); |
| 3544 | r5or6_last_column = tmpdiv; |
| 3545 | #else |
| 3546 | first_row_offset = r5or6_first_row_offset = |
| 3547 | (u32)((first_block % stripesize) % |
| 3548 | r5or6_blocks_per_row); |
| 3549 | |
| 3550 | r5or6_last_row_offset = |
| 3551 | (u32)((last_block % stripesize) % |
| 3552 | r5or6_blocks_per_row); |
| 3553 | |
| 3554 | first_column = r5or6_first_column = |
| 3555 | r5or6_first_row_offset / map->strip_size; |
| 3556 | r5or6_last_column = |
| 3557 | r5or6_last_row_offset / map->strip_size; |
| 3558 | #endif |
| 3559 | if (r5or6_first_column != r5or6_last_column) |
| 3560 | return IO_ACCEL_INELIGIBLE; |
| 3561 | |
| 3562 | /* Request is eligible */ |
| 3563 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
| 3564 | map->row_cnt; |
| 3565 | |
| 3566 | map_index = (first_group * |
| 3567 | (map->row_cnt * total_disks_per_row)) + |
| 3568 | (map_row * total_disks_per_row) + first_column; |
| 3569 | break; |
| 3570 | default: |
| 3571 | return IO_ACCEL_INELIGIBLE; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3572 | } |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3573 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3574 | disk_handle = dd[map_index].ioaccel_handle; |
| 3575 | disk_block = map->disk_starting_blk + (first_row * map->strip_size) + |
| 3576 | (first_row_offset - (first_column * map->strip_size)); |
| 3577 | disk_block_cnt = block_cnt; |
| 3578 | |
| 3579 | /* handle differing logical/physical block sizes */ |
| 3580 | if (map->phys_blk_shift) { |
| 3581 | disk_block <<= map->phys_blk_shift; |
| 3582 | disk_block_cnt <<= map->phys_blk_shift; |
| 3583 | } |
| 3584 | BUG_ON(disk_block_cnt > 0xffff); |
| 3585 | |
| 3586 | /* build the new CDB for the physical disk I/O */ |
| 3587 | if (disk_block > 0xffffffff) { |
| 3588 | cdb[0] = is_write ? WRITE_16 : READ_16; |
| 3589 | cdb[1] = 0; |
| 3590 | cdb[2] = (u8) (disk_block >> 56); |
| 3591 | cdb[3] = (u8) (disk_block >> 48); |
| 3592 | cdb[4] = (u8) (disk_block >> 40); |
| 3593 | cdb[5] = (u8) (disk_block >> 32); |
| 3594 | cdb[6] = (u8) (disk_block >> 24); |
| 3595 | cdb[7] = (u8) (disk_block >> 16); |
| 3596 | cdb[8] = (u8) (disk_block >> 8); |
| 3597 | cdb[9] = (u8) (disk_block); |
| 3598 | cdb[10] = (u8) (disk_block_cnt >> 24); |
| 3599 | cdb[11] = (u8) (disk_block_cnt >> 16); |
| 3600 | cdb[12] = (u8) (disk_block_cnt >> 8); |
| 3601 | cdb[13] = (u8) (disk_block_cnt); |
| 3602 | cdb[14] = 0; |
| 3603 | cdb[15] = 0; |
| 3604 | cdb_len = 16; |
| 3605 | } else { |
| 3606 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 3607 | cdb[1] = 0; |
| 3608 | cdb[2] = (u8) (disk_block >> 24); |
| 3609 | cdb[3] = (u8) (disk_block >> 16); |
| 3610 | cdb[4] = (u8) (disk_block >> 8); |
| 3611 | cdb[5] = (u8) (disk_block); |
| 3612 | cdb[6] = 0; |
| 3613 | cdb[7] = (u8) (disk_block_cnt >> 8); |
| 3614 | cdb[8] = (u8) (disk_block_cnt); |
| 3615 | cdb[9] = 0; |
| 3616 | cdb_len = 10; |
| 3617 | } |
| 3618 | return hpsa_scsi_ioaccel_queue_command(h, c, disk_handle, cdb, cdb_len, |
| 3619 | dev->scsi3addr); |
| 3620 | } |
| 3621 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3622 | static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3623 | void (*done)(struct scsi_cmnd *)) |
| 3624 | { |
| 3625 | struct ctlr_info *h; |
| 3626 | struct hpsa_scsi_dev_t *dev; |
| 3627 | unsigned char scsi3addr[8]; |
| 3628 | struct CommandList *c; |
| 3629 | unsigned long flags; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3630 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3631 | |
| 3632 | /* Get the ptr to our adapter structure out of cmd->host. */ |
| 3633 | h = sdev_to_hba(cmd->device); |
| 3634 | dev = cmd->device->hostdata; |
| 3635 | if (!dev) { |
| 3636 | cmd->result = DID_NO_CONNECT << 16; |
| 3637 | done(cmd); |
| 3638 | return 0; |
| 3639 | } |
| 3640 | memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); |
| 3641 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3642 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 3643 | if (unlikely(h->lockup_detected)) { |
| 3644 | spin_unlock_irqrestore(&h->lock, flags); |
| 3645 | cmd->result = DID_ERROR << 16; |
| 3646 | done(cmd); |
| 3647 | return 0; |
| 3648 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3649 | spin_unlock_irqrestore(&h->lock, flags); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 3650 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3651 | if (c == NULL) { /* trouble... */ |
| 3652 | dev_err(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
| 3653 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3654 | } |
| 3655 | |
| 3656 | /* Fill in the command list header */ |
| 3657 | |
| 3658 | cmd->scsi_done = done; /* save this for use by completion code */ |
| 3659 | |
| 3660 | /* save c in case we have to abort it */ |
| 3661 | cmd->host_scribble = (unsigned char *) c; |
| 3662 | |
| 3663 | c->cmd_type = CMD_SCSI; |
| 3664 | c->scsi_cmd = cmd; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3665 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3666 | /* Call alternate submit routine for I/O accelerated commands. |
| 3667 | * Retries always go down the normal I/O path. |
| 3668 | */ |
| 3669 | if (likely(cmd->retries == 0 && |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 3670 | cmd->request->cmd_type == REQ_TYPE_FS && |
| 3671 | h->acciopath_status)) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3672 | if (dev->offload_enabled) { |
| 3673 | rc = hpsa_scsi_ioaccel_raid_map(h, c); |
| 3674 | if (rc == 0) |
| 3675 | return 0; /* Sent on ioaccel path */ |
| 3676 | if (rc < 0) { /* scsi_dma_map failed. */ |
| 3677 | cmd_free(h, c); |
| 3678 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3679 | } |
| 3680 | } else if (dev->ioaccel_handle) { |
| 3681 | rc = hpsa_scsi_ioaccel_direct_map(h, c); |
| 3682 | if (rc == 0) |
| 3683 | return 0; /* Sent on direct map path */ |
| 3684 | if (rc < 0) { /* scsi_dma_map failed. */ |
| 3685 | cmd_free(h, c); |
| 3686 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3687 | } |
| 3688 | } |
| 3689 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3690 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3691 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 3692 | memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 3693 | c->Header.Tag.lower = (c->cmdindex << DIRECT_LOOKUP_SHIFT); |
| 3694 | c->Header.Tag.lower |= DIRECT_LOOKUP_BIT; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3695 | |
| 3696 | /* Fill in the request block... */ |
| 3697 | |
| 3698 | c->Request.Timeout = 0; |
| 3699 | memset(c->Request.CDB, 0, sizeof(c->Request.CDB)); |
| 3700 | BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB)); |
| 3701 | c->Request.CDBLen = cmd->cmd_len; |
| 3702 | memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len); |
| 3703 | c->Request.Type.Type = TYPE_CMD; |
| 3704 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 3705 | switch (cmd->sc_data_direction) { |
| 3706 | case DMA_TO_DEVICE: |
| 3707 | c->Request.Type.Direction = XFER_WRITE; |
| 3708 | break; |
| 3709 | case DMA_FROM_DEVICE: |
| 3710 | c->Request.Type.Direction = XFER_READ; |
| 3711 | break; |
| 3712 | case DMA_NONE: |
| 3713 | c->Request.Type.Direction = XFER_NONE; |
| 3714 | break; |
| 3715 | case DMA_BIDIRECTIONAL: |
| 3716 | /* This can happen if a buggy application does a scsi passthru |
| 3717 | * and sets both inlen and outlen to non-zero. ( see |
| 3718 | * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) |
| 3719 | */ |
| 3720 | |
| 3721 | c->Request.Type.Direction = XFER_RSVD; |
| 3722 | /* This is technically wrong, and hpsa controllers should |
| 3723 | * reject it with CMD_INVALID, which is the most correct |
| 3724 | * response, but non-fibre backends appear to let it |
| 3725 | * slide by, and give the same results as if this field |
| 3726 | * were set correctly. Either way is acceptable for |
| 3727 | * our purposes here. |
| 3728 | */ |
| 3729 | |
| 3730 | break; |
| 3731 | |
| 3732 | default: |
| 3733 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 3734 | cmd->sc_data_direction); |
| 3735 | BUG(); |
| 3736 | break; |
| 3737 | } |
| 3738 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3739 | if (hpsa_scatter_gather(h, c, cmd) < 0) { /* Fill SG list */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3740 | cmd_free(h, c); |
| 3741 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3742 | } |
| 3743 | enqueue_cmd_and_start_io(h, c); |
| 3744 | /* the cmd'll come back via intr handler in complete_scsi_command() */ |
| 3745 | return 0; |
| 3746 | } |
| 3747 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3748 | static DEF_SCSI_QCMD(hpsa_scsi_queue_command) |
| 3749 | |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 3750 | static int do_not_scan_if_controller_locked_up(struct ctlr_info *h) |
| 3751 | { |
| 3752 | unsigned long flags; |
| 3753 | |
| 3754 | /* |
| 3755 | * Don't let rescans be initiated on a controller known |
| 3756 | * to be locked up. If the controller locks up *during* |
| 3757 | * a rescan, that thread is probably hosed, but at least |
| 3758 | * we can prevent new rescan threads from piling up on a |
| 3759 | * locked up controller. |
| 3760 | */ |
| 3761 | spin_lock_irqsave(&h->lock, flags); |
| 3762 | if (unlikely(h->lockup_detected)) { |
| 3763 | spin_unlock_irqrestore(&h->lock, flags); |
| 3764 | spin_lock_irqsave(&h->scan_lock, flags); |
| 3765 | h->scan_finished = 1; |
| 3766 | wake_up_all(&h->scan_wait_queue); |
| 3767 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 3768 | return 1; |
| 3769 | } |
| 3770 | spin_unlock_irqrestore(&h->lock, flags); |
| 3771 | return 0; |
| 3772 | } |
| 3773 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 3774 | static void hpsa_scan_start(struct Scsi_Host *sh) |
| 3775 | { |
| 3776 | struct ctlr_info *h = shost_to_hba(sh); |
| 3777 | unsigned long flags; |
| 3778 | |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 3779 | if (do_not_scan_if_controller_locked_up(h)) |
| 3780 | return; |
| 3781 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 3782 | /* wait until any scan already in progress is finished. */ |
| 3783 | while (1) { |
| 3784 | spin_lock_irqsave(&h->scan_lock, flags); |
| 3785 | if (h->scan_finished) |
| 3786 | break; |
| 3787 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 3788 | wait_event(h->scan_wait_queue, h->scan_finished); |
| 3789 | /* Note: We don't need to worry about a race between this |
| 3790 | * thread and driver unload because the midlayer will |
| 3791 | * have incremented the reference count, so unload won't |
| 3792 | * happen if we're in here. |
| 3793 | */ |
| 3794 | } |
| 3795 | h->scan_finished = 0; /* mark scan as in progress */ |
| 3796 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 3797 | |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 3798 | if (do_not_scan_if_controller_locked_up(h)) |
| 3799 | return; |
| 3800 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 3801 | hpsa_update_scsi_devices(h, h->scsi_host->host_no); |
| 3802 | |
| 3803 | spin_lock_irqsave(&h->scan_lock, flags); |
| 3804 | h->scan_finished = 1; /* mark scan as finished. */ |
| 3805 | wake_up_all(&h->scan_wait_queue); |
| 3806 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 3807 | } |
| 3808 | |
| 3809 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 3810 | unsigned long elapsed_time) |
| 3811 | { |
| 3812 | struct ctlr_info *h = shost_to_hba(sh); |
| 3813 | unsigned long flags; |
| 3814 | int finished; |
| 3815 | |
| 3816 | spin_lock_irqsave(&h->scan_lock, flags); |
| 3817 | finished = h->scan_finished; |
| 3818 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 3819 | return finished; |
| 3820 | } |
| 3821 | |
Stephen M. Cameron | 667e23d | 2010-02-25 14:02:51 -0600 | [diff] [blame] | 3822 | static int hpsa_change_queue_depth(struct scsi_device *sdev, |
| 3823 | int qdepth, int reason) |
| 3824 | { |
| 3825 | struct ctlr_info *h = sdev_to_hba(sdev); |
| 3826 | |
| 3827 | if (reason != SCSI_QDEPTH_DEFAULT) |
| 3828 | return -ENOTSUPP; |
| 3829 | |
| 3830 | if (qdepth < 1) |
| 3831 | qdepth = 1; |
| 3832 | else |
| 3833 | if (qdepth > h->nr_cmds) |
| 3834 | qdepth = h->nr_cmds; |
| 3835 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 3836 | return sdev->queue_depth; |
| 3837 | } |
| 3838 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3839 | static void hpsa_unregister_scsi(struct ctlr_info *h) |
| 3840 | { |
| 3841 | /* we are being forcibly unloaded, and may not refuse. */ |
| 3842 | scsi_remove_host(h->scsi_host); |
| 3843 | scsi_host_put(h->scsi_host); |
| 3844 | h->scsi_host = NULL; |
| 3845 | } |
| 3846 | |
| 3847 | static int hpsa_register_scsi(struct ctlr_info *h) |
| 3848 | { |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 3849 | struct Scsi_Host *sh; |
| 3850 | int error; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3851 | |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 3852 | sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h)); |
| 3853 | if (sh == NULL) |
| 3854 | goto fail; |
| 3855 | |
| 3856 | sh->io_port = 0; |
| 3857 | sh->n_io_port = 0; |
| 3858 | sh->this_id = -1; |
| 3859 | sh->max_channel = 3; |
| 3860 | sh->max_cmd_len = MAX_COMMAND_SIZE; |
| 3861 | sh->max_lun = HPSA_MAX_LUN; |
| 3862 | sh->max_id = HPSA_MAX_LUN; |
| 3863 | sh->can_queue = h->nr_cmds; |
| 3864 | sh->cmd_per_lun = h->nr_cmds; |
| 3865 | sh->sg_tablesize = h->maxsgentries; |
| 3866 | h->scsi_host = sh; |
| 3867 | sh->hostdata[0] = (unsigned long) h; |
| 3868 | sh->irq = h->intr[h->intr_mode]; |
| 3869 | sh->unique_id = sh->irq; |
| 3870 | error = scsi_add_host(sh, &h->pdev->dev); |
| 3871 | if (error) |
| 3872 | goto fail_host_put; |
| 3873 | scsi_scan_host(sh); |
| 3874 | return 0; |
| 3875 | |
| 3876 | fail_host_put: |
| 3877 | dev_err(&h->pdev->dev, "%s: scsi_add_host" |
| 3878 | " failed for controller %d\n", __func__, h->ctlr); |
| 3879 | scsi_host_put(sh); |
| 3880 | return error; |
| 3881 | fail: |
| 3882 | dev_err(&h->pdev->dev, "%s: scsi_host_alloc" |
| 3883 | " failed for controller %d\n", __func__, h->ctlr); |
| 3884 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | static int wait_for_device_to_become_ready(struct ctlr_info *h, |
| 3888 | unsigned char lunaddr[]) |
| 3889 | { |
| 3890 | int rc = 0; |
| 3891 | int count = 0; |
| 3892 | int waittime = 1; /* seconds */ |
| 3893 | struct CommandList *c; |
| 3894 | |
| 3895 | c = cmd_special_alloc(h); |
| 3896 | if (!c) { |
| 3897 | dev_warn(&h->pdev->dev, "out of memory in " |
| 3898 | "wait_for_device_to_become_ready.\n"); |
| 3899 | return IO_ERROR; |
| 3900 | } |
| 3901 | |
| 3902 | /* Send test unit ready until device ready, or give up. */ |
| 3903 | while (count < HPSA_TUR_RETRY_LIMIT) { |
| 3904 | |
| 3905 | /* Wait for a bit. do this first, because if we send |
| 3906 | * the TUR right away, the reset will just abort it. |
| 3907 | */ |
| 3908 | msleep(1000 * waittime); |
| 3909 | count++; |
| 3910 | |
| 3911 | /* Increase wait time with each try, up to a point. */ |
| 3912 | if (waittime < HPSA_MAX_WAIT_INTERVAL_SECS) |
| 3913 | waittime = waittime * 2; |
| 3914 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 3915 | /* Send the Test Unit Ready, fill_cmd can't fail, no mapping */ |
| 3916 | (void) fill_cmd(c, TEST_UNIT_READY, h, |
| 3917 | NULL, 0, 0, lunaddr, TYPE_CMD); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3918 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 3919 | /* no unmap needed here because no data xfer. */ |
| 3920 | |
| 3921 | if (c->err_info->CommandStatus == CMD_SUCCESS) |
| 3922 | break; |
| 3923 | |
| 3924 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 3925 | c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION && |
| 3926 | (c->err_info->SenseInfo[2] == NO_SENSE || |
| 3927 | c->err_info->SenseInfo[2] == UNIT_ATTENTION)) |
| 3928 | break; |
| 3929 | |
| 3930 | dev_warn(&h->pdev->dev, "waiting %d secs " |
| 3931 | "for device to become ready.\n", waittime); |
| 3932 | rc = 1; /* device not ready. */ |
| 3933 | } |
| 3934 | |
| 3935 | if (rc) |
| 3936 | dev_warn(&h->pdev->dev, "giving up on device.\n"); |
| 3937 | else |
| 3938 | dev_warn(&h->pdev->dev, "device is ready.\n"); |
| 3939 | |
| 3940 | cmd_special_free(h, c); |
| 3941 | return rc; |
| 3942 | } |
| 3943 | |
| 3944 | /* Need at least one of these error handlers to keep ../scsi/hosts.c from |
| 3945 | * complaining. Doing a host- or bus-reset can't do anything good here. |
| 3946 | */ |
| 3947 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) |
| 3948 | { |
| 3949 | int rc; |
| 3950 | struct ctlr_info *h; |
| 3951 | struct hpsa_scsi_dev_t *dev; |
| 3952 | |
| 3953 | /* find the controller to which the command to be aborted was sent */ |
| 3954 | h = sdev_to_hba(scsicmd->device); |
| 3955 | if (h == NULL) /* paranoia */ |
| 3956 | return FAILED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3957 | dev = scsicmd->device->hostdata; |
| 3958 | if (!dev) { |
| 3959 | dev_err(&h->pdev->dev, "hpsa_eh_device_reset_handler: " |
| 3960 | "device lookup failed.\n"); |
| 3961 | return FAILED; |
| 3962 | } |
Stephen M. Cameron | d416b0c | 2010-02-04 08:43:21 -0600 | [diff] [blame] | 3963 | dev_warn(&h->pdev->dev, "resetting device %d:%d:%d:%d\n", |
| 3964 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3965 | /* send a reset to the SCSI LUN which the command was sent to */ |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 3966 | rc = hpsa_send_reset(h, dev->scsi3addr, HPSA_RESET_TYPE_LUN); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3967 | if (rc == 0 && wait_for_device_to_become_ready(h, dev->scsi3addr) == 0) |
| 3968 | return SUCCESS; |
| 3969 | |
| 3970 | dev_warn(&h->pdev->dev, "resetting device failed.\n"); |
| 3971 | return FAILED; |
| 3972 | } |
| 3973 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 3974 | static void swizzle_abort_tag(u8 *tag) |
| 3975 | { |
| 3976 | u8 original_tag[8]; |
| 3977 | |
| 3978 | memcpy(original_tag, tag, 8); |
| 3979 | tag[0] = original_tag[3]; |
| 3980 | tag[1] = original_tag[2]; |
| 3981 | tag[2] = original_tag[1]; |
| 3982 | tag[3] = original_tag[0]; |
| 3983 | tag[4] = original_tag[7]; |
| 3984 | tag[5] = original_tag[6]; |
| 3985 | tag[6] = original_tag[5]; |
| 3986 | tag[7] = original_tag[4]; |
| 3987 | } |
| 3988 | |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 3989 | static void hpsa_get_tag(struct ctlr_info *h, |
| 3990 | struct CommandList *c, u32 *taglower, u32 *tagupper) |
| 3991 | { |
| 3992 | if (c->cmd_type == CMD_IOACCEL1) { |
| 3993 | struct io_accel1_cmd *cm1 = (struct io_accel1_cmd *) |
| 3994 | &h->ioaccel_cmd_pool[c->cmdindex]; |
| 3995 | *tagupper = cm1->Tag.upper; |
| 3996 | *taglower = cm1->Tag.lower; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3997 | return; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 3998 | } |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3999 | if (c->cmd_type == CMD_IOACCEL2) { |
| 4000 | struct io_accel2_cmd *cm2 = (struct io_accel2_cmd *) |
| 4001 | &h->ioaccel2_cmd_pool[c->cmdindex]; |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4002 | /* upper tag not used in ioaccel2 mode */ |
| 4003 | memset(tagupper, 0, sizeof(*tagupper)); |
| 4004 | *taglower = cm2->Tag; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4005 | return; |
| 4006 | } |
| 4007 | *tagupper = c->Header.Tag.upper; |
| 4008 | *taglower = c->Header.Tag.lower; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4009 | } |
| 4010 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4011 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4012 | static int hpsa_send_abort(struct ctlr_info *h, unsigned char *scsi3addr, |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4013 | struct CommandList *abort, int swizzle) |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4014 | { |
| 4015 | int rc = IO_OK; |
| 4016 | struct CommandList *c; |
| 4017 | struct ErrorInfo *ei; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4018 | u32 tagupper, taglower; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4019 | |
| 4020 | c = cmd_special_alloc(h); |
| 4021 | if (c == NULL) { /* trouble... */ |
| 4022 | dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); |
| 4023 | return -ENOMEM; |
| 4024 | } |
| 4025 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 4026 | /* fill_cmd can't fail here, no buffer to map */ |
| 4027 | (void) fill_cmd(c, HPSA_ABORT_MSG, h, abort, |
| 4028 | 0, 0, scsi3addr, TYPE_MSG); |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4029 | if (swizzle) |
| 4030 | swizzle_abort_tag(&c->Request.CDB[4]); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4031 | hpsa_scsi_do_simple_cmd_core(h, c); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4032 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4033 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: do_simple_cmd_core completed.\n", |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4034 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4035 | /* no unmap needed here because no data xfer. */ |
| 4036 | |
| 4037 | ei = c->err_info; |
| 4038 | switch (ei->CommandStatus) { |
| 4039 | case CMD_SUCCESS: |
| 4040 | break; |
| 4041 | case CMD_UNABORTABLE: /* Very common, don't make noise. */ |
| 4042 | rc = -1; |
| 4043 | break; |
| 4044 | default: |
| 4045 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: interpreting error.\n", |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4046 | __func__, tagupper, taglower); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 4047 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4048 | rc = -1; |
| 4049 | break; |
| 4050 | } |
| 4051 | cmd_special_free(h, c); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4052 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", |
| 4053 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4054 | return rc; |
| 4055 | } |
| 4056 | |
| 4057 | /* |
| 4058 | * hpsa_find_cmd_in_queue |
| 4059 | * |
| 4060 | * Used to determine whether a command (find) is still present |
| 4061 | * in queue_head. Optionally excludes the last element of queue_head. |
| 4062 | * |
| 4063 | * This is used to avoid unnecessary aborts. Commands in h->reqQ have |
| 4064 | * not yet been submitted, and so can be aborted by the driver without |
| 4065 | * sending an abort to the hardware. |
| 4066 | * |
| 4067 | * Returns pointer to command if found in queue, NULL otherwise. |
| 4068 | */ |
| 4069 | static struct CommandList *hpsa_find_cmd_in_queue(struct ctlr_info *h, |
| 4070 | struct scsi_cmnd *find, struct list_head *queue_head) |
| 4071 | { |
| 4072 | unsigned long flags; |
| 4073 | struct CommandList *c = NULL; /* ptr into cmpQ */ |
| 4074 | |
| 4075 | if (!find) |
| 4076 | return 0; |
| 4077 | spin_lock_irqsave(&h->lock, flags); |
| 4078 | list_for_each_entry(c, queue_head, list) { |
| 4079 | if (c->scsi_cmd == NULL) /* e.g.: passthru ioctl */ |
| 4080 | continue; |
| 4081 | if (c->scsi_cmd == find) { |
| 4082 | spin_unlock_irqrestore(&h->lock, flags); |
| 4083 | return c; |
| 4084 | } |
| 4085 | } |
| 4086 | spin_unlock_irqrestore(&h->lock, flags); |
| 4087 | return NULL; |
| 4088 | } |
| 4089 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4090 | static struct CommandList *hpsa_find_cmd_in_queue_by_tag(struct ctlr_info *h, |
| 4091 | u8 *tag, struct list_head *queue_head) |
| 4092 | { |
| 4093 | unsigned long flags; |
| 4094 | struct CommandList *c; |
| 4095 | |
| 4096 | spin_lock_irqsave(&h->lock, flags); |
| 4097 | list_for_each_entry(c, queue_head, list) { |
| 4098 | if (memcmp(&c->Header.Tag, tag, 8) != 0) |
| 4099 | continue; |
| 4100 | spin_unlock_irqrestore(&h->lock, flags); |
| 4101 | return c; |
| 4102 | } |
| 4103 | spin_unlock_irqrestore(&h->lock, flags); |
| 4104 | return NULL; |
| 4105 | } |
| 4106 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4107 | /* ioaccel2 path firmware cannot handle abort task requests. |
| 4108 | * Change abort requests to physical target reset, and send to the |
| 4109 | * address of the physical disk used for the ioaccel 2 command. |
| 4110 | * Return 0 on success (IO_OK) |
| 4111 | * -1 on failure |
| 4112 | */ |
| 4113 | |
| 4114 | static int hpsa_send_reset_as_abort_ioaccel2(struct ctlr_info *h, |
| 4115 | unsigned char *scsi3addr, struct CommandList *abort) |
| 4116 | { |
| 4117 | int rc = IO_OK; |
| 4118 | struct scsi_cmnd *scmd; /* scsi command within request being aborted */ |
| 4119 | struct hpsa_scsi_dev_t *dev; /* device to which scsi cmd was sent */ |
| 4120 | unsigned char phys_scsi3addr[8]; /* addr of phys disk with volume */ |
| 4121 | unsigned char *psa = &phys_scsi3addr[0]; |
| 4122 | |
| 4123 | /* Get a pointer to the hpsa logical device. */ |
| 4124 | scmd = (struct scsi_cmnd *) abort->scsi_cmd; |
| 4125 | dev = (struct hpsa_scsi_dev_t *)(scmd->device->hostdata); |
| 4126 | if (dev == NULL) { |
| 4127 | dev_warn(&h->pdev->dev, |
| 4128 | "Cannot abort: no device pointer for command.\n"); |
| 4129 | return -1; /* not abortable */ |
| 4130 | } |
| 4131 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 4132 | if (h->raid_offload_debug > 0) |
| 4133 | dev_info(&h->pdev->dev, |
| 4134 | "Reset as abort: Abort requested on C%d:B%d:T%d:L%d scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4135 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun, |
| 4136 | scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3], |
| 4137 | scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); |
| 4138 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4139 | if (!dev->offload_enabled) { |
| 4140 | dev_warn(&h->pdev->dev, |
| 4141 | "Can't abort: device is not operating in HP SSD Smart Path mode.\n"); |
| 4142 | return -1; /* not abortable */ |
| 4143 | } |
| 4144 | |
| 4145 | /* Incoming scsi3addr is logical addr. We need physical disk addr. */ |
| 4146 | if (!hpsa_get_pdisk_of_ioaccel2(h, abort, psa)) { |
| 4147 | dev_warn(&h->pdev->dev, "Can't abort: Failed lookup of physical address.\n"); |
| 4148 | return -1; /* not abortable */ |
| 4149 | } |
| 4150 | |
| 4151 | /* send the reset */ |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame^] | 4152 | if (h->raid_offload_debug > 0) |
| 4153 | dev_info(&h->pdev->dev, |
| 4154 | "Reset as abort: Resetting physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4155 | psa[0], psa[1], psa[2], psa[3], |
| 4156 | psa[4], psa[5], psa[6], psa[7]); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4157 | rc = hpsa_send_reset(h, psa, HPSA_RESET_TYPE_TARGET); |
| 4158 | if (rc != 0) { |
| 4159 | dev_warn(&h->pdev->dev, |
| 4160 | "Reset as abort: Failed on physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4161 | psa[0], psa[1], psa[2], psa[3], |
| 4162 | psa[4], psa[5], psa[6], psa[7]); |
| 4163 | return rc; /* failed to reset */ |
| 4164 | } |
| 4165 | |
| 4166 | /* wait for device to recover */ |
| 4167 | if (wait_for_device_to_become_ready(h, psa) != 0) { |
| 4168 | dev_warn(&h->pdev->dev, |
| 4169 | "Reset as abort: Failed: Device never recovered from reset: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4170 | psa[0], psa[1], psa[2], psa[3], |
| 4171 | psa[4], psa[5], psa[6], psa[7]); |
| 4172 | return -1; /* failed to recover */ |
| 4173 | } |
| 4174 | |
| 4175 | /* device recovered */ |
| 4176 | dev_info(&h->pdev->dev, |
| 4177 | "Reset as abort: Device recovered from reset: scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4178 | psa[0], psa[1], psa[2], psa[3], |
| 4179 | psa[4], psa[5], psa[6], psa[7]); |
| 4180 | |
| 4181 | return rc; /* success */ |
| 4182 | } |
| 4183 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4184 | /* Some Smart Arrays need the abort tag swizzled, and some don't. It's hard to |
| 4185 | * tell which kind we're dealing with, so we send the abort both ways. There |
| 4186 | * shouldn't be any collisions between swizzled and unswizzled tags due to the |
| 4187 | * way we construct our tags but we check anyway in case the assumptions which |
| 4188 | * make this true someday become false. |
| 4189 | */ |
| 4190 | static int hpsa_send_abort_both_ways(struct ctlr_info *h, |
| 4191 | unsigned char *scsi3addr, struct CommandList *abort) |
| 4192 | { |
| 4193 | u8 swizzled_tag[8]; |
| 4194 | struct CommandList *c; |
| 4195 | int rc = 0, rc2 = 0; |
| 4196 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4197 | /* ioccelerator mode 2 commands should be aborted via the |
| 4198 | * accelerated path, since RAID path is unaware of these commands, |
| 4199 | * but underlying firmware can't handle abort TMF. |
| 4200 | * Change abort to physical device reset. |
| 4201 | */ |
| 4202 | if (abort->cmd_type == CMD_IOACCEL2) |
| 4203 | return hpsa_send_reset_as_abort_ioaccel2(h, scsi3addr, abort); |
| 4204 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4205 | /* we do not expect to find the swizzled tag in our queue, but |
| 4206 | * check anyway just to be sure the assumptions which make this |
| 4207 | * the case haven't become wrong. |
| 4208 | */ |
| 4209 | memcpy(swizzled_tag, &abort->Request.CDB[4], 8); |
| 4210 | swizzle_abort_tag(swizzled_tag); |
| 4211 | c = hpsa_find_cmd_in_queue_by_tag(h, swizzled_tag, &h->cmpQ); |
| 4212 | if (c != NULL) { |
| 4213 | dev_warn(&h->pdev->dev, "Unexpectedly found byte-swapped tag in completion queue.\n"); |
| 4214 | return hpsa_send_abort(h, scsi3addr, abort, 0); |
| 4215 | } |
| 4216 | rc = hpsa_send_abort(h, scsi3addr, abort, 0); |
| 4217 | |
| 4218 | /* if the command is still in our queue, we can't conclude that it was |
| 4219 | * aborted (it might have just completed normally) but in any case |
| 4220 | * we don't need to try to abort it another way. |
| 4221 | */ |
| 4222 | c = hpsa_find_cmd_in_queue(h, abort->scsi_cmd, &h->cmpQ); |
| 4223 | if (c) |
| 4224 | rc2 = hpsa_send_abort(h, scsi3addr, abort, 1); |
| 4225 | return rc && rc2; |
| 4226 | } |
| 4227 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4228 | /* Send an abort for the specified command. |
| 4229 | * If the device and controller support it, |
| 4230 | * send a task abort request. |
| 4231 | */ |
| 4232 | static int hpsa_eh_abort_handler(struct scsi_cmnd *sc) |
| 4233 | { |
| 4234 | |
| 4235 | int i, rc; |
| 4236 | struct ctlr_info *h; |
| 4237 | struct hpsa_scsi_dev_t *dev; |
| 4238 | struct CommandList *abort; /* pointer to command to be aborted */ |
| 4239 | struct CommandList *found; |
| 4240 | struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ |
| 4241 | char msg[256]; /* For debug messaging. */ |
| 4242 | int ml = 0; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4243 | u32 tagupper, taglower; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4244 | |
| 4245 | /* Find the controller of the command to be aborted */ |
| 4246 | h = sdev_to_hba(sc->device); |
| 4247 | if (WARN(h == NULL, |
| 4248 | "ABORT REQUEST FAILED, Controller lookup failed.\n")) |
| 4249 | return FAILED; |
| 4250 | |
| 4251 | /* Check that controller supports some kind of task abort */ |
| 4252 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags) && |
| 4253 | !(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 4254 | return FAILED; |
| 4255 | |
| 4256 | memset(msg, 0, sizeof(msg)); |
| 4257 | ml += sprintf(msg+ml, "ABORT REQUEST on C%d:B%d:T%d:L%d ", |
| 4258 | h->scsi_host->host_no, sc->device->channel, |
| 4259 | sc->device->id, sc->device->lun); |
| 4260 | |
| 4261 | /* Find the device of the command to be aborted */ |
| 4262 | dev = sc->device->hostdata; |
| 4263 | if (!dev) { |
| 4264 | dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", |
| 4265 | msg); |
| 4266 | return FAILED; |
| 4267 | } |
| 4268 | |
| 4269 | /* Get SCSI command to be aborted */ |
| 4270 | abort = (struct CommandList *) sc->host_scribble; |
| 4271 | if (abort == NULL) { |
| 4272 | dev_err(&h->pdev->dev, "%s FAILED, Command to abort is NULL.\n", |
| 4273 | msg); |
| 4274 | return FAILED; |
| 4275 | } |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4276 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
| 4277 | ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4278 | as = (struct scsi_cmnd *) abort->scsi_cmd; |
| 4279 | if (as != NULL) |
| 4280 | ml += sprintf(msg+ml, "Command:0x%x SN:0x%lx ", |
| 4281 | as->cmnd[0], as->serial_number); |
| 4282 | dev_dbg(&h->pdev->dev, "%s\n", msg); |
| 4283 | dev_warn(&h->pdev->dev, "Abort request on C%d:B%d:T%d:L%d\n", |
| 4284 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun); |
| 4285 | |
| 4286 | /* Search reqQ to See if command is queued but not submitted, |
| 4287 | * if so, complete the command with aborted status and remove |
| 4288 | * it from the reqQ. |
| 4289 | */ |
| 4290 | found = hpsa_find_cmd_in_queue(h, sc, &h->reqQ); |
| 4291 | if (found) { |
| 4292 | found->err_info->CommandStatus = CMD_ABORTED; |
| 4293 | finish_cmd(found); |
| 4294 | dev_info(&h->pdev->dev, "%s Request SUCCEEDED (driver queue).\n", |
| 4295 | msg); |
| 4296 | return SUCCESS; |
| 4297 | } |
| 4298 | |
| 4299 | /* not in reqQ, if also not in cmpQ, must have already completed */ |
| 4300 | found = hpsa_find_cmd_in_queue(h, sc, &h->cmpQ); |
| 4301 | if (!found) { |
Stephen M. Cameron | d6ebd0f | 2012-07-26 11:34:17 -0500 | [diff] [blame] | 4302 | dev_dbg(&h->pdev->dev, "%s Request SUCCEEDED (not known to driver).\n", |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4303 | msg); |
| 4304 | return SUCCESS; |
| 4305 | } |
| 4306 | |
| 4307 | /* |
| 4308 | * Command is in flight, or possibly already completed |
| 4309 | * by the firmware (but not to the scsi mid layer) but we can't |
| 4310 | * distinguish which. Send the abort down. |
| 4311 | */ |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4312 | rc = hpsa_send_abort_both_ways(h, dev->scsi3addr, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4313 | if (rc != 0) { |
| 4314 | dev_dbg(&h->pdev->dev, "%s Request FAILED.\n", msg); |
| 4315 | dev_warn(&h->pdev->dev, "FAILED abort on device C%d:B%d:T%d:L%d\n", |
| 4316 | h->scsi_host->host_no, |
| 4317 | dev->bus, dev->target, dev->lun); |
| 4318 | return FAILED; |
| 4319 | } |
| 4320 | dev_info(&h->pdev->dev, "%s REQUEST SUCCEEDED.\n", msg); |
| 4321 | |
| 4322 | /* If the abort(s) above completed and actually aborted the |
| 4323 | * command, then the command to be aborted should already be |
| 4324 | * completed. If not, wait around a bit more to see if they |
| 4325 | * manage to complete normally. |
| 4326 | */ |
| 4327 | #define ABORT_COMPLETE_WAIT_SECS 30 |
| 4328 | for (i = 0; i < ABORT_COMPLETE_WAIT_SECS * 10; i++) { |
| 4329 | found = hpsa_find_cmd_in_queue(h, sc, &h->cmpQ); |
| 4330 | if (!found) |
| 4331 | return SUCCESS; |
| 4332 | msleep(100); |
| 4333 | } |
| 4334 | dev_warn(&h->pdev->dev, "%s FAILED. Aborted command has not completed after %d seconds.\n", |
| 4335 | msg, ABORT_COMPLETE_WAIT_SECS); |
| 4336 | return FAILED; |
| 4337 | } |
| 4338 | |
| 4339 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4340 | /* |
| 4341 | * For operations that cannot sleep, a command block is allocated at init, |
| 4342 | * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track |
| 4343 | * which ones are free or in use. Lock must be held when calling this. |
| 4344 | * cmd_free() is the complement. |
| 4345 | */ |
| 4346 | static struct CommandList *cmd_alloc(struct ctlr_info *h) |
| 4347 | { |
| 4348 | struct CommandList *c; |
| 4349 | int i; |
| 4350 | union u64bit temp64; |
| 4351 | dma_addr_t cmd_dma_handle, err_dma_handle; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4352 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4353 | |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4354 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4355 | do { |
| 4356 | i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4357 | if (i == h->nr_cmds) { |
| 4358 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4359 | return NULL; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4360 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4361 | } while (test_and_set_bit |
| 4362 | (i & (BITS_PER_LONG - 1), |
| 4363 | h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4364 | spin_unlock_irqrestore(&h->lock, flags); |
| 4365 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4366 | c = h->cmd_pool + i; |
| 4367 | memset(c, 0, sizeof(*c)); |
| 4368 | cmd_dma_handle = h->cmd_pool_dhandle |
| 4369 | + i * sizeof(*c); |
| 4370 | c->err_info = h->errinfo_pool + i; |
| 4371 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 4372 | err_dma_handle = h->errinfo_pool_dhandle |
| 4373 | + i * sizeof(*c->err_info); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4374 | |
| 4375 | c->cmdindex = i; |
| 4376 | |
Stephen M. Cameron | 9e0fc76 | 2011-02-15 15:32:48 -0600 | [diff] [blame] | 4377 | INIT_LIST_HEAD(&c->list); |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4378 | c->busaddr = (u32) cmd_dma_handle; |
| 4379 | temp64.val = (u64) err_dma_handle; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4380 | c->ErrDesc.Addr.lower = temp64.val32.lower; |
| 4381 | c->ErrDesc.Addr.upper = temp64.val32.upper; |
| 4382 | c->ErrDesc.Len = sizeof(*c->err_info); |
| 4383 | |
| 4384 | c->h = h; |
| 4385 | return c; |
| 4386 | } |
| 4387 | |
| 4388 | /* For operations that can wait for kmalloc to possibly sleep, |
| 4389 | * this routine can be called. Lock need not be held to call |
| 4390 | * cmd_special_alloc. cmd_special_free() is the complement. |
| 4391 | */ |
| 4392 | static struct CommandList *cmd_special_alloc(struct ctlr_info *h) |
| 4393 | { |
| 4394 | struct CommandList *c; |
| 4395 | union u64bit temp64; |
| 4396 | dma_addr_t cmd_dma_handle, err_dma_handle; |
| 4397 | |
| 4398 | c = pci_alloc_consistent(h->pdev, sizeof(*c), &cmd_dma_handle); |
| 4399 | if (c == NULL) |
| 4400 | return NULL; |
| 4401 | memset(c, 0, sizeof(*c)); |
| 4402 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4403 | c->cmd_type = CMD_SCSI; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4404 | c->cmdindex = -1; |
| 4405 | |
| 4406 | c->err_info = pci_alloc_consistent(h->pdev, sizeof(*c->err_info), |
| 4407 | &err_dma_handle); |
| 4408 | |
| 4409 | if (c->err_info == NULL) { |
| 4410 | pci_free_consistent(h->pdev, |
| 4411 | sizeof(*c), c, cmd_dma_handle); |
| 4412 | return NULL; |
| 4413 | } |
| 4414 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 4415 | |
Stephen M. Cameron | 9e0fc76 | 2011-02-15 15:32:48 -0600 | [diff] [blame] | 4416 | INIT_LIST_HEAD(&c->list); |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4417 | c->busaddr = (u32) cmd_dma_handle; |
| 4418 | temp64.val = (u64) err_dma_handle; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4419 | c->ErrDesc.Addr.lower = temp64.val32.lower; |
| 4420 | c->ErrDesc.Addr.upper = temp64.val32.upper; |
| 4421 | c->ErrDesc.Len = sizeof(*c->err_info); |
| 4422 | |
| 4423 | c->h = h; |
| 4424 | return c; |
| 4425 | } |
| 4426 | |
| 4427 | static void cmd_free(struct ctlr_info *h, struct CommandList *c) |
| 4428 | { |
| 4429 | int i; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4430 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4431 | |
| 4432 | i = c - h->cmd_pool; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4433 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4434 | clear_bit(i & (BITS_PER_LONG - 1), |
| 4435 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 4436 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | static void cmd_special_free(struct ctlr_info *h, struct CommandList *c) |
| 4440 | { |
| 4441 | union u64bit temp64; |
| 4442 | |
| 4443 | temp64.val32.lower = c->ErrDesc.Addr.lower; |
| 4444 | temp64.val32.upper = c->ErrDesc.Addr.upper; |
| 4445 | pci_free_consistent(h->pdev, sizeof(*c->err_info), |
| 4446 | c->err_info, (dma_addr_t) temp64.val); |
| 4447 | pci_free_consistent(h->pdev, sizeof(*c), |
Stephen M. Cameron | d896f3f | 2011-01-06 14:47:53 -0600 | [diff] [blame] | 4448 | c, (dma_addr_t) (c->busaddr & DIRECT_LOOKUP_MASK)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | #ifdef CONFIG_COMPAT |
| 4452 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4453 | static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg) |
| 4454 | { |
| 4455 | IOCTL32_Command_struct __user *arg32 = |
| 4456 | (IOCTL32_Command_struct __user *) arg; |
| 4457 | IOCTL_Command_struct arg64; |
| 4458 | IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64)); |
| 4459 | int err; |
| 4460 | u32 cp; |
| 4461 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 4462 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4463 | err = 0; |
| 4464 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 4465 | sizeof(arg64.LUN_info)); |
| 4466 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 4467 | sizeof(arg64.Request)); |
| 4468 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 4469 | sizeof(arg64.error_info)); |
| 4470 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 4471 | err |= get_user(cp, &arg32->buf); |
| 4472 | arg64.buf = compat_ptr(cp); |
| 4473 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 4474 | |
| 4475 | if (err) |
| 4476 | return -EFAULT; |
| 4477 | |
Stephen M. Cameron | e39eeae | 2010-02-04 08:43:46 -0600 | [diff] [blame] | 4478 | err = hpsa_ioctl(dev, CCISS_PASSTHRU, (void *)p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4479 | if (err) |
| 4480 | return err; |
| 4481 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 4482 | sizeof(arg32->error_info)); |
| 4483 | if (err) |
| 4484 | return -EFAULT; |
| 4485 | return err; |
| 4486 | } |
| 4487 | |
| 4488 | static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, |
| 4489 | int cmd, void *arg) |
| 4490 | { |
| 4491 | BIG_IOCTL32_Command_struct __user *arg32 = |
| 4492 | (BIG_IOCTL32_Command_struct __user *) arg; |
| 4493 | BIG_IOCTL_Command_struct arg64; |
| 4494 | BIG_IOCTL_Command_struct __user *p = |
| 4495 | compat_alloc_user_space(sizeof(arg64)); |
| 4496 | int err; |
| 4497 | u32 cp; |
| 4498 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 4499 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4500 | err = 0; |
| 4501 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 4502 | sizeof(arg64.LUN_info)); |
| 4503 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 4504 | sizeof(arg64.Request)); |
| 4505 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 4506 | sizeof(arg64.error_info)); |
| 4507 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 4508 | err |= get_user(arg64.malloc_size, &arg32->malloc_size); |
| 4509 | err |= get_user(cp, &arg32->buf); |
| 4510 | arg64.buf = compat_ptr(cp); |
| 4511 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 4512 | |
| 4513 | if (err) |
| 4514 | return -EFAULT; |
| 4515 | |
Stephen M. Cameron | e39eeae | 2010-02-04 08:43:46 -0600 | [diff] [blame] | 4516 | err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, (void *)p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4517 | if (err) |
| 4518 | return err; |
| 4519 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 4520 | sizeof(arg32->error_info)); |
| 4521 | if (err) |
| 4522 | return -EFAULT; |
| 4523 | return err; |
| 4524 | } |
Stephen M. Cameron | 71fe75a | 2010-02-04 08:43:51 -0600 | [diff] [blame] | 4525 | |
| 4526 | static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void *arg) |
| 4527 | { |
| 4528 | switch (cmd) { |
| 4529 | case CCISS_GETPCIINFO: |
| 4530 | case CCISS_GETINTINFO: |
| 4531 | case CCISS_SETINTINFO: |
| 4532 | case CCISS_GETNODENAME: |
| 4533 | case CCISS_SETNODENAME: |
| 4534 | case CCISS_GETHEARTBEAT: |
| 4535 | case CCISS_GETBUSTYPES: |
| 4536 | case CCISS_GETFIRMVER: |
| 4537 | case CCISS_GETDRIVVER: |
| 4538 | case CCISS_REVALIDVOLS: |
| 4539 | case CCISS_DEREGDISK: |
| 4540 | case CCISS_REGNEWDISK: |
| 4541 | case CCISS_REGNEWD: |
| 4542 | case CCISS_RESCANDISK: |
| 4543 | case CCISS_GETLUNINFO: |
| 4544 | return hpsa_ioctl(dev, cmd, arg); |
| 4545 | |
| 4546 | case CCISS_PASSTHRU32: |
| 4547 | return hpsa_ioctl32_passthru(dev, cmd, arg); |
| 4548 | case CCISS_BIG_PASSTHRU32: |
| 4549 | return hpsa_ioctl32_big_passthru(dev, cmd, arg); |
| 4550 | |
| 4551 | default: |
| 4552 | return -ENOIOCTLCMD; |
| 4553 | } |
| 4554 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4555 | #endif |
| 4556 | |
| 4557 | static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp) |
| 4558 | { |
| 4559 | struct hpsa_pci_info pciinfo; |
| 4560 | |
| 4561 | if (!argp) |
| 4562 | return -EINVAL; |
| 4563 | pciinfo.domain = pci_domain_nr(h->pdev->bus); |
| 4564 | pciinfo.bus = h->pdev->bus->number; |
| 4565 | pciinfo.dev_fn = h->pdev->devfn; |
| 4566 | pciinfo.board_id = h->board_id; |
| 4567 | if (copy_to_user(argp, &pciinfo, sizeof(pciinfo))) |
| 4568 | return -EFAULT; |
| 4569 | return 0; |
| 4570 | } |
| 4571 | |
| 4572 | static int hpsa_getdrivver_ioctl(struct ctlr_info *h, void __user *argp) |
| 4573 | { |
| 4574 | DriverVer_type DriverVer; |
| 4575 | unsigned char vmaj, vmin, vsubmin; |
| 4576 | int rc; |
| 4577 | |
| 4578 | rc = sscanf(HPSA_DRIVER_VERSION, "%hhu.%hhu.%hhu", |
| 4579 | &vmaj, &vmin, &vsubmin); |
| 4580 | if (rc != 3) { |
| 4581 | dev_info(&h->pdev->dev, "driver version string '%s' " |
| 4582 | "unrecognized.", HPSA_DRIVER_VERSION); |
| 4583 | vmaj = 0; |
| 4584 | vmin = 0; |
| 4585 | vsubmin = 0; |
| 4586 | } |
| 4587 | DriverVer = (vmaj << 16) | (vmin << 8) | vsubmin; |
| 4588 | if (!argp) |
| 4589 | return -EINVAL; |
| 4590 | if (copy_to_user(argp, &DriverVer, sizeof(DriverVer_type))) |
| 4591 | return -EFAULT; |
| 4592 | return 0; |
| 4593 | } |
| 4594 | |
| 4595 | static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 4596 | { |
| 4597 | IOCTL_Command_struct iocommand; |
| 4598 | struct CommandList *c; |
| 4599 | char *buff = NULL; |
| 4600 | union u64bit temp64; |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4601 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4602 | |
| 4603 | if (!argp) |
| 4604 | return -EINVAL; |
| 4605 | if (!capable(CAP_SYS_RAWIO)) |
| 4606 | return -EPERM; |
| 4607 | if (copy_from_user(&iocommand, argp, sizeof(iocommand))) |
| 4608 | return -EFAULT; |
| 4609 | if ((iocommand.buf_size < 1) && |
| 4610 | (iocommand.Request.Type.Direction != XFER_NONE)) { |
| 4611 | return -EINVAL; |
| 4612 | } |
| 4613 | if (iocommand.buf_size > 0) { |
| 4614 | buff = kmalloc(iocommand.buf_size, GFP_KERNEL); |
| 4615 | if (buff == NULL) |
| 4616 | return -EFAULT; |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4617 | if (iocommand.Request.Type.Direction == XFER_WRITE) { |
| 4618 | /* Copy the data into the buffer we created */ |
| 4619 | if (copy_from_user(buff, iocommand.buf, |
| 4620 | iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4621 | rc = -EFAULT; |
| 4622 | goto out_kfree; |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4623 | } |
| 4624 | } else { |
| 4625 | memset(buff, 0, iocommand.buf_size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4626 | } |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4627 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4628 | c = cmd_special_alloc(h); |
| 4629 | if (c == NULL) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4630 | rc = -ENOMEM; |
| 4631 | goto out_kfree; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4632 | } |
| 4633 | /* Fill in the command type */ |
| 4634 | c->cmd_type = CMD_IOCTL_PEND; |
| 4635 | /* Fill in Command Header */ |
| 4636 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 4637 | if (iocommand.buf_size > 0) { /* buffer to fill */ |
| 4638 | c->Header.SGList = 1; |
| 4639 | c->Header.SGTotal = 1; |
| 4640 | } else { /* no buffers to fill */ |
| 4641 | c->Header.SGList = 0; |
| 4642 | c->Header.SGTotal = 0; |
| 4643 | } |
| 4644 | memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN)); |
| 4645 | /* use the kernel address the cmd block for tag */ |
| 4646 | c->Header.Tag.lower = c->busaddr; |
| 4647 | |
| 4648 | /* Fill in Request block */ |
| 4649 | memcpy(&c->Request, &iocommand.Request, |
| 4650 | sizeof(c->Request)); |
| 4651 | |
| 4652 | /* Fill in the scatter gather information */ |
| 4653 | if (iocommand.buf_size > 0) { |
| 4654 | temp64.val = pci_map_single(h->pdev, buff, |
| 4655 | iocommand.buf_size, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 4656 | if (dma_mapping_error(&h->pdev->dev, temp64.val)) { |
| 4657 | c->SG[0].Addr.lower = 0; |
| 4658 | c->SG[0].Addr.upper = 0; |
| 4659 | c->SG[0].Len = 0; |
| 4660 | rc = -ENOMEM; |
| 4661 | goto out; |
| 4662 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4663 | c->SG[0].Addr.lower = temp64.val32.lower; |
| 4664 | c->SG[0].Addr.upper = temp64.val32.upper; |
| 4665 | c->SG[0].Len = iocommand.buf_size; |
Matt Gates | e1d9cbf | 2014-02-18 13:55:12 -0600 | [diff] [blame] | 4666 | c->SG[0].Ext = HPSA_SG_LAST; /* we are not chaining*/ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4667 | } |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 4668 | hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c); |
Stephen M. Cameron | c2dd32e | 2011-06-03 09:57:29 -0500 | [diff] [blame] | 4669 | if (iocommand.buf_size > 0) |
| 4670 | hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4671 | check_ioctl_unit_attention(h, c); |
| 4672 | |
| 4673 | /* Copy the error information out */ |
| 4674 | memcpy(&iocommand.error_info, c->err_info, |
| 4675 | sizeof(iocommand.error_info)); |
| 4676 | if (copy_to_user(argp, &iocommand, sizeof(iocommand))) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4677 | rc = -EFAULT; |
| 4678 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4679 | } |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4680 | if (iocommand.Request.Type.Direction == XFER_READ && |
| 4681 | iocommand.buf_size > 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4682 | /* Copy the data out of the buffer we created */ |
| 4683 | if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4684 | rc = -EFAULT; |
| 4685 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4686 | } |
| 4687 | } |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4688 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4689 | cmd_special_free(h, c); |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4690 | out_kfree: |
| 4691 | kfree(buff); |
| 4692 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 4696 | { |
| 4697 | BIG_IOCTL_Command_struct *ioc; |
| 4698 | struct CommandList *c; |
| 4699 | unsigned char **buff = NULL; |
| 4700 | int *buff_size = NULL; |
| 4701 | union u64bit temp64; |
| 4702 | BYTE sg_used = 0; |
| 4703 | int status = 0; |
| 4704 | int i; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4705 | u32 left; |
| 4706 | u32 sz; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4707 | BYTE __user *data_ptr; |
| 4708 | |
| 4709 | if (!argp) |
| 4710 | return -EINVAL; |
| 4711 | if (!capable(CAP_SYS_RAWIO)) |
| 4712 | return -EPERM; |
| 4713 | ioc = (BIG_IOCTL_Command_struct *) |
| 4714 | kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 4715 | if (!ioc) { |
| 4716 | status = -ENOMEM; |
| 4717 | goto cleanup1; |
| 4718 | } |
| 4719 | if (copy_from_user(ioc, argp, sizeof(*ioc))) { |
| 4720 | status = -EFAULT; |
| 4721 | goto cleanup1; |
| 4722 | } |
| 4723 | if ((ioc->buf_size < 1) && |
| 4724 | (ioc->Request.Type.Direction != XFER_NONE)) { |
| 4725 | status = -EINVAL; |
| 4726 | goto cleanup1; |
| 4727 | } |
| 4728 | /* Check kmalloc limits using all SGs */ |
| 4729 | if (ioc->malloc_size > MAX_KMALLOC_SIZE) { |
| 4730 | status = -EINVAL; |
| 4731 | goto cleanup1; |
| 4732 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 4733 | if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4734 | status = -EINVAL; |
| 4735 | goto cleanup1; |
| 4736 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 4737 | buff = kzalloc(SG_ENTRIES_IN_CMD * sizeof(char *), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4738 | if (!buff) { |
| 4739 | status = -ENOMEM; |
| 4740 | goto cleanup1; |
| 4741 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 4742 | buff_size = kmalloc(SG_ENTRIES_IN_CMD * sizeof(int), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4743 | if (!buff_size) { |
| 4744 | status = -ENOMEM; |
| 4745 | goto cleanup1; |
| 4746 | } |
| 4747 | left = ioc->buf_size; |
| 4748 | data_ptr = ioc->buf; |
| 4749 | while (left) { |
| 4750 | sz = (left > ioc->malloc_size) ? ioc->malloc_size : left; |
| 4751 | buff_size[sg_used] = sz; |
| 4752 | buff[sg_used] = kmalloc(sz, GFP_KERNEL); |
| 4753 | if (buff[sg_used] == NULL) { |
| 4754 | status = -ENOMEM; |
| 4755 | goto cleanup1; |
| 4756 | } |
| 4757 | if (ioc->Request.Type.Direction == XFER_WRITE) { |
| 4758 | if (copy_from_user(buff[sg_used], data_ptr, sz)) { |
| 4759 | status = -ENOMEM; |
| 4760 | goto cleanup1; |
| 4761 | } |
| 4762 | } else |
| 4763 | memset(buff[sg_used], 0, sz); |
| 4764 | left -= sz; |
| 4765 | data_ptr += sz; |
| 4766 | sg_used++; |
| 4767 | } |
| 4768 | c = cmd_special_alloc(h); |
| 4769 | if (c == NULL) { |
| 4770 | status = -ENOMEM; |
| 4771 | goto cleanup1; |
| 4772 | } |
| 4773 | c->cmd_type = CMD_IOCTL_PEND; |
| 4774 | c->Header.ReplyQueue = 0; |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4775 | c->Header.SGList = c->Header.SGTotal = sg_used; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4776 | memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN)); |
| 4777 | c->Header.Tag.lower = c->busaddr; |
| 4778 | memcpy(&c->Request, &ioc->Request, sizeof(c->Request)); |
| 4779 | if (ioc->buf_size > 0) { |
| 4780 | int i; |
| 4781 | for (i = 0; i < sg_used; i++) { |
| 4782 | temp64.val = pci_map_single(h->pdev, buff[i], |
| 4783 | buff_size[i], PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 4784 | if (dma_mapping_error(&h->pdev->dev, temp64.val)) { |
| 4785 | c->SG[i].Addr.lower = 0; |
| 4786 | c->SG[i].Addr.upper = 0; |
| 4787 | c->SG[i].Len = 0; |
| 4788 | hpsa_pci_unmap(h->pdev, c, i, |
| 4789 | PCI_DMA_BIDIRECTIONAL); |
| 4790 | status = -ENOMEM; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 4791 | goto cleanup0; |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 4792 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4793 | c->SG[i].Addr.lower = temp64.val32.lower; |
| 4794 | c->SG[i].Addr.upper = temp64.val32.upper; |
| 4795 | c->SG[i].Len = buff_size[i]; |
Matt Gates | e1d9cbf | 2014-02-18 13:55:12 -0600 | [diff] [blame] | 4796 | c->SG[i].Ext = i < sg_used - 1 ? 0 : HPSA_SG_LAST; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4797 | } |
| 4798 | } |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 4799 | hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c); |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4800 | if (sg_used) |
| 4801 | hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4802 | check_ioctl_unit_attention(h, c); |
| 4803 | /* Copy the error information out */ |
| 4804 | memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info)); |
| 4805 | if (copy_to_user(argp, ioc, sizeof(*ioc))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4806 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 4807 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4808 | } |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4809 | if (ioc->Request.Type.Direction == XFER_READ && ioc->buf_size > 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4810 | /* Copy the data out of the buffer we created */ |
| 4811 | BYTE __user *ptr = ioc->buf; |
| 4812 | for (i = 0; i < sg_used; i++) { |
| 4813 | if (copy_to_user(ptr, buff[i], buff_size[i])) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4814 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 4815 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4816 | } |
| 4817 | ptr += buff_size[i]; |
| 4818 | } |
| 4819 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4820 | status = 0; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 4821 | cleanup0: |
| 4822 | cmd_special_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4823 | cleanup1: |
| 4824 | if (buff) { |
| 4825 | for (i = 0; i < sg_used; i++) |
| 4826 | kfree(buff[i]); |
| 4827 | kfree(buff); |
| 4828 | } |
| 4829 | kfree(buff_size); |
| 4830 | kfree(ioc); |
| 4831 | return status; |
| 4832 | } |
| 4833 | |
| 4834 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 4835 | struct CommandList *c) |
| 4836 | { |
| 4837 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 4838 | c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) |
| 4839 | (void) check_for_unit_attention(h, c); |
| 4840 | } |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 4841 | |
| 4842 | static int increment_passthru_count(struct ctlr_info *h) |
| 4843 | { |
| 4844 | unsigned long flags; |
| 4845 | |
| 4846 | spin_lock_irqsave(&h->passthru_count_lock, flags); |
| 4847 | if (h->passthru_count >= HPSA_MAX_CONCURRENT_PASSTHRUS) { |
| 4848 | spin_unlock_irqrestore(&h->passthru_count_lock, flags); |
| 4849 | return -1; |
| 4850 | } |
| 4851 | h->passthru_count++; |
| 4852 | spin_unlock_irqrestore(&h->passthru_count_lock, flags); |
| 4853 | return 0; |
| 4854 | } |
| 4855 | |
| 4856 | static void decrement_passthru_count(struct ctlr_info *h) |
| 4857 | { |
| 4858 | unsigned long flags; |
| 4859 | |
| 4860 | spin_lock_irqsave(&h->passthru_count_lock, flags); |
| 4861 | if (h->passthru_count <= 0) { |
| 4862 | spin_unlock_irqrestore(&h->passthru_count_lock, flags); |
| 4863 | /* not expecting to get here. */ |
| 4864 | dev_warn(&h->pdev->dev, "Bug detected, passthru_count seems to be incorrect.\n"); |
| 4865 | return; |
| 4866 | } |
| 4867 | h->passthru_count--; |
| 4868 | spin_unlock_irqrestore(&h->passthru_count_lock, flags); |
| 4869 | } |
| 4870 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4871 | /* |
| 4872 | * ioctl |
| 4873 | */ |
| 4874 | static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg) |
| 4875 | { |
| 4876 | struct ctlr_info *h; |
| 4877 | void __user *argp = (void __user *)arg; |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 4878 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4879 | |
| 4880 | h = sdev_to_hba(dev); |
| 4881 | |
| 4882 | switch (cmd) { |
| 4883 | case CCISS_DEREGDISK: |
| 4884 | case CCISS_REGNEWDISK: |
| 4885 | case CCISS_REGNEWD: |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 4886 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4887 | return 0; |
| 4888 | case CCISS_GETPCIINFO: |
| 4889 | return hpsa_getpciinfo_ioctl(h, argp); |
| 4890 | case CCISS_GETDRIVVER: |
| 4891 | return hpsa_getdrivver_ioctl(h, argp); |
| 4892 | case CCISS_PASSTHRU: |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 4893 | if (increment_passthru_count(h)) |
| 4894 | return -EAGAIN; |
| 4895 | rc = hpsa_passthru_ioctl(h, argp); |
| 4896 | decrement_passthru_count(h); |
| 4897 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4898 | case CCISS_BIG_PASSTHRU: |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 4899 | if (increment_passthru_count(h)) |
| 4900 | return -EAGAIN; |
| 4901 | rc = hpsa_big_passthru_ioctl(h, argp); |
| 4902 | decrement_passthru_count(h); |
| 4903 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4904 | default: |
| 4905 | return -ENOTTY; |
| 4906 | } |
| 4907 | } |
| 4908 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 4909 | static int hpsa_send_host_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
| 4910 | u8 reset_type) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 4911 | { |
| 4912 | struct CommandList *c; |
| 4913 | |
| 4914 | c = cmd_alloc(h); |
| 4915 | if (!c) |
| 4916 | return -ENOMEM; |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 4917 | /* fill_cmd can't fail here, no data buffer to map */ |
| 4918 | (void) fill_cmd(c, HPSA_DEVICE_RESET_MSG, h, NULL, 0, 0, |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 4919 | RAID_CTLR_LUNID, TYPE_MSG); |
| 4920 | c->Request.CDB[1] = reset_type; /* fill_cmd defaults to target reset */ |
| 4921 | c->waiting = NULL; |
| 4922 | enqueue_cmd_and_start_io(h, c); |
| 4923 | /* Don't wait for completion, the reset won't complete. Don't free |
| 4924 | * the command either. This is the last command we will send before |
| 4925 | * re-initializing everything, so it doesn't matter and won't leak. |
| 4926 | */ |
| 4927 | return 0; |
| 4928 | } |
| 4929 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 4930 | static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 4931 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4932 | int cmd_type) |
| 4933 | { |
| 4934 | int pci_dir = XFER_NONE; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4935 | struct CommandList *a; /* for commands to be aborted */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4936 | |
| 4937 | c->cmd_type = CMD_IOCTL_PEND; |
| 4938 | c->Header.ReplyQueue = 0; |
| 4939 | if (buff != NULL && size > 0) { |
| 4940 | c->Header.SGList = 1; |
| 4941 | c->Header.SGTotal = 1; |
| 4942 | } else { |
| 4943 | c->Header.SGList = 0; |
| 4944 | c->Header.SGTotal = 0; |
| 4945 | } |
| 4946 | c->Header.Tag.lower = c->busaddr; |
| 4947 | memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8); |
| 4948 | |
| 4949 | c->Request.Type.Type = cmd_type; |
| 4950 | if (cmd_type == TYPE_CMD) { |
| 4951 | switch (cmd) { |
| 4952 | case HPSA_INQUIRY: |
| 4953 | /* are we trying to read a vital product page */ |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 4954 | if (page_code & VPD_PAGE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4955 | c->Request.CDB[1] = 0x01; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 4956 | c->Request.CDB[2] = (page_code & 0xff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4957 | } |
| 4958 | c->Request.CDBLen = 6; |
| 4959 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 4960 | c->Request.Type.Direction = XFER_READ; |
| 4961 | c->Request.Timeout = 0; |
| 4962 | c->Request.CDB[0] = HPSA_INQUIRY; |
| 4963 | c->Request.CDB[4] = size & 0xFF; |
| 4964 | break; |
| 4965 | case HPSA_REPORT_LOG: |
| 4966 | case HPSA_REPORT_PHYS: |
| 4967 | /* Talking to controller so It's a physical command |
| 4968 | mode = 00 target = 0. Nothing to write. |
| 4969 | */ |
| 4970 | c->Request.CDBLen = 12; |
| 4971 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 4972 | c->Request.Type.Direction = XFER_READ; |
| 4973 | c->Request.Timeout = 0; |
| 4974 | c->Request.CDB[0] = cmd; |
| 4975 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 4976 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 4977 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 4978 | c->Request.CDB[9] = size & 0xFF; |
| 4979 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4980 | case HPSA_CACHE_FLUSH: |
| 4981 | c->Request.CDBLen = 12; |
| 4982 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 4983 | c->Request.Type.Direction = XFER_WRITE; |
| 4984 | c->Request.Timeout = 0; |
| 4985 | c->Request.CDB[0] = BMIC_WRITE; |
| 4986 | c->Request.CDB[6] = BMIC_CACHE_FLUSH; |
Stephen M. Cameron | bb158ea | 2011-10-26 16:21:17 -0500 | [diff] [blame] | 4987 | c->Request.CDB[7] = (size >> 8) & 0xFF; |
| 4988 | c->Request.CDB[8] = size & 0xFF; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4989 | break; |
| 4990 | case TEST_UNIT_READY: |
| 4991 | c->Request.CDBLen = 6; |
| 4992 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 4993 | c->Request.Type.Direction = XFER_NONE; |
| 4994 | c->Request.Timeout = 0; |
| 4995 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4996 | case HPSA_GET_RAID_MAP: |
| 4997 | c->Request.CDBLen = 12; |
| 4998 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 4999 | c->Request.Type.Direction = XFER_READ; |
| 5000 | c->Request.Timeout = 0; |
| 5001 | c->Request.CDB[0] = HPSA_CISS_READ; |
| 5002 | c->Request.CDB[1] = cmd; |
| 5003 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 5004 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 5005 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 5006 | c->Request.CDB[9] = size & 0xFF; |
| 5007 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5008 | default: |
| 5009 | dev_warn(&h->pdev->dev, "unknown command 0x%c\n", cmd); |
| 5010 | BUG(); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5011 | return -1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5012 | } |
| 5013 | } else if (cmd_type == TYPE_MSG) { |
| 5014 | switch (cmd) { |
| 5015 | |
| 5016 | case HPSA_DEVICE_RESET_MSG: |
| 5017 | c->Request.CDBLen = 16; |
| 5018 | c->Request.Type.Type = 1; /* It is a MSG not a CMD */ |
| 5019 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 5020 | c->Request.Type.Direction = XFER_NONE; |
| 5021 | c->Request.Timeout = 0; /* Don't time out */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5022 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
| 5023 | c->Request.CDB[0] = cmd; |
Stephen M. Cameron | 21e89af | 2012-07-26 11:34:10 -0500 | [diff] [blame] | 5024 | c->Request.CDB[1] = HPSA_RESET_TYPE_LUN; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5025 | /* If bytes 4-7 are zero, it means reset the */ |
| 5026 | /* LunID device */ |
| 5027 | c->Request.CDB[4] = 0x00; |
| 5028 | c->Request.CDB[5] = 0x00; |
| 5029 | c->Request.CDB[6] = 0x00; |
| 5030 | c->Request.CDB[7] = 0x00; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5031 | break; |
| 5032 | case HPSA_ABORT_MSG: |
| 5033 | a = buff; /* point to command to be aborted */ |
| 5034 | dev_dbg(&h->pdev->dev, "Abort Tag:0x%08x:%08x using request Tag:0x%08x:%08x\n", |
| 5035 | a->Header.Tag.upper, a->Header.Tag.lower, |
| 5036 | c->Header.Tag.upper, c->Header.Tag.lower); |
| 5037 | c->Request.CDBLen = 16; |
| 5038 | c->Request.Type.Type = TYPE_MSG; |
| 5039 | c->Request.Type.Attribute = ATTR_SIMPLE; |
| 5040 | c->Request.Type.Direction = XFER_WRITE; |
| 5041 | c->Request.Timeout = 0; /* Don't time out */ |
| 5042 | c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; |
| 5043 | c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; |
| 5044 | c->Request.CDB[2] = 0x00; /* reserved */ |
| 5045 | c->Request.CDB[3] = 0x00; /* reserved */ |
| 5046 | /* Tag to abort goes in CDB[4]-CDB[11] */ |
| 5047 | c->Request.CDB[4] = a->Header.Tag.lower & 0xFF; |
| 5048 | c->Request.CDB[5] = (a->Header.Tag.lower >> 8) & 0xFF; |
| 5049 | c->Request.CDB[6] = (a->Header.Tag.lower >> 16) & 0xFF; |
| 5050 | c->Request.CDB[7] = (a->Header.Tag.lower >> 24) & 0xFF; |
| 5051 | c->Request.CDB[8] = a->Header.Tag.upper & 0xFF; |
| 5052 | c->Request.CDB[9] = (a->Header.Tag.upper >> 8) & 0xFF; |
| 5053 | c->Request.CDB[10] = (a->Header.Tag.upper >> 16) & 0xFF; |
| 5054 | c->Request.CDB[11] = (a->Header.Tag.upper >> 24) & 0xFF; |
| 5055 | c->Request.CDB[12] = 0x00; /* reserved */ |
| 5056 | c->Request.CDB[13] = 0x00; /* reserved */ |
| 5057 | c->Request.CDB[14] = 0x00; /* reserved */ |
| 5058 | c->Request.CDB[15] = 0x00; /* reserved */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5059 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5060 | default: |
| 5061 | dev_warn(&h->pdev->dev, "unknown message type %d\n", |
| 5062 | cmd); |
| 5063 | BUG(); |
| 5064 | } |
| 5065 | } else { |
| 5066 | dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type); |
| 5067 | BUG(); |
| 5068 | } |
| 5069 | |
| 5070 | switch (c->Request.Type.Direction) { |
| 5071 | case XFER_READ: |
| 5072 | pci_dir = PCI_DMA_FROMDEVICE; |
| 5073 | break; |
| 5074 | case XFER_WRITE: |
| 5075 | pci_dir = PCI_DMA_TODEVICE; |
| 5076 | break; |
| 5077 | case XFER_NONE: |
| 5078 | pci_dir = PCI_DMA_NONE; |
| 5079 | break; |
| 5080 | default: |
| 5081 | pci_dir = PCI_DMA_BIDIRECTIONAL; |
| 5082 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5083 | if (hpsa_map_one(h->pdev, c, buff, size, pci_dir)) |
| 5084 | return -1; |
| 5085 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | /* |
| 5089 | * Map (physical) PCI mem into (virtual) kernel space |
| 5090 | */ |
| 5091 | static void __iomem *remap_pci_mem(ulong base, ulong size) |
| 5092 | { |
| 5093 | ulong page_base = ((ulong) base) & PAGE_MASK; |
| 5094 | ulong page_offs = ((ulong) base) - page_base; |
Stephen M. Cameron | 088ba34c | 2012-07-26 11:34:23 -0500 | [diff] [blame] | 5095 | void __iomem *page_remapped = ioremap_nocache(page_base, |
| 5096 | page_offs + size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5097 | |
| 5098 | return page_remapped ? (page_remapped + page_offs) : NULL; |
| 5099 | } |
| 5100 | |
| 5101 | /* Takes cmds off the submission queue and sends them to the hardware, |
| 5102 | * then puts them on the queue of cmds waiting for completion. |
| 5103 | */ |
| 5104 | static void start_io(struct ctlr_info *h) |
| 5105 | { |
| 5106 | struct CommandList *c; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5107 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5108 | |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5109 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 9e0fc76 | 2011-02-15 15:32:48 -0600 | [diff] [blame] | 5110 | while (!list_empty(&h->reqQ)) { |
| 5111 | c = list_entry(h->reqQ.next, struct CommandList, list); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5112 | /* can't do anything if fifo is full */ |
| 5113 | if ((h->access.fifo_full(h))) { |
Stephen M. Cameron | 396883e | 2013-09-23 13:34:17 -0500 | [diff] [blame] | 5114 | h->fifo_recently_full = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5115 | dev_warn(&h->pdev->dev, "fifo full\n"); |
| 5116 | break; |
| 5117 | } |
Stephen M. Cameron | 396883e | 2013-09-23 13:34:17 -0500 | [diff] [blame] | 5118 | h->fifo_recently_full = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5119 | |
| 5120 | /* Get the first entry from the Request Q */ |
| 5121 | removeQ(c); |
| 5122 | h->Qdepth--; |
| 5123 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5124 | /* Put job onto the completed Q */ |
| 5125 | addQ(&h->cmpQ, c); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5126 | |
| 5127 | /* Must increment commands_outstanding before unlocking |
| 5128 | * and submitting to avoid race checking for fifo full |
| 5129 | * condition. |
| 5130 | */ |
| 5131 | h->commands_outstanding++; |
| 5132 | if (h->commands_outstanding > h->max_outstanding) |
| 5133 | h->max_outstanding = h->commands_outstanding; |
| 5134 | |
| 5135 | /* Tell the controller execute command */ |
| 5136 | spin_unlock_irqrestore(&h->lock, flags); |
| 5137 | h->access.submit_command(h, c); |
| 5138 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5139 | } |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5140 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5141 | } |
| 5142 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5143 | static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5144 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5145 | return h->access.command_completed(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5146 | } |
| 5147 | |
Stephen M. Cameron | 900c544 | 2010-02-04 08:42:35 -0600 | [diff] [blame] | 5148 | static inline bool interrupt_pending(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5149 | { |
| 5150 | return h->access.intr_pending(h); |
| 5151 | } |
| 5152 | |
| 5153 | static inline long interrupt_not_for_us(struct ctlr_info *h) |
| 5154 | { |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5155 | return (h->access.intr_pending(h) == 0) || |
| 5156 | (h->interrupts_enabled == 0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5157 | } |
| 5158 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 5159 | static inline int bad_tag(struct ctlr_info *h, u32 tag_index, |
| 5160 | u32 raw_tag) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5161 | { |
| 5162 | if (unlikely(tag_index >= h->nr_cmds)) { |
| 5163 | dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag); |
| 5164 | return 1; |
| 5165 | } |
| 5166 | return 0; |
| 5167 | } |
| 5168 | |
Stephen M. Cameron | 5a3d16f | 2012-05-01 11:42:46 -0500 | [diff] [blame] | 5169 | static inline void finish_cmd(struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5170 | { |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5171 | unsigned long flags; |
Stephen M. Cameron | 396883e | 2013-09-23 13:34:17 -0500 | [diff] [blame] | 5172 | int io_may_be_stalled = 0; |
| 5173 | struct ctlr_info *h = c->h; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5174 | |
Stephen M. Cameron | 396883e | 2013-09-23 13:34:17 -0500 | [diff] [blame] | 5175 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5176 | removeQ(c); |
Stephen M. Cameron | 396883e | 2013-09-23 13:34:17 -0500 | [diff] [blame] | 5177 | |
| 5178 | /* |
| 5179 | * Check for possibly stalled i/o. |
| 5180 | * |
| 5181 | * If a fifo_full condition is encountered, requests will back up |
| 5182 | * in h->reqQ. This queue is only emptied out by start_io which is |
| 5183 | * only called when a new i/o request comes in. If no i/o's are |
| 5184 | * forthcoming, the i/o's in h->reqQ can get stuck. So we call |
| 5185 | * start_io from here if we detect such a danger. |
| 5186 | * |
| 5187 | * Normally, we shouldn't hit this case, but pounding on the |
| 5188 | * CCISS_PASSTHRU ioctl can provoke it. Only call start_io if |
| 5189 | * commands_outstanding is low. We want to avoid calling |
| 5190 | * start_io from in here as much as possible, and esp. don't |
| 5191 | * want to get in a cycle where we call start_io every time |
| 5192 | * through here. |
| 5193 | */ |
| 5194 | if (unlikely(h->fifo_recently_full) && |
| 5195 | h->commands_outstanding < 5) |
| 5196 | io_may_be_stalled = 1; |
| 5197 | |
| 5198 | spin_unlock_irqrestore(&h->lock, flags); |
| 5199 | |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 5200 | dial_up_lockup_detection_on_fw_flash_complete(c->h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 5201 | if (likely(c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_SCSI |
| 5202 | || c->cmd_type == CMD_IOACCEL2)) |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 5203 | complete_scsi_command(c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5204 | else if (c->cmd_type == CMD_IOCTL_PEND) |
| 5205 | complete(c->waiting); |
Stephen M. Cameron | 396883e | 2013-09-23 13:34:17 -0500 | [diff] [blame] | 5206 | if (unlikely(io_may_be_stalled)) |
| 5207 | start_io(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5208 | } |
| 5209 | |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5210 | static inline u32 hpsa_tag_contains_index(u32 tag) |
| 5211 | { |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5212 | return tag & DIRECT_LOOKUP_BIT; |
| 5213 | } |
| 5214 | |
| 5215 | static inline u32 hpsa_tag_to_index(u32 tag) |
| 5216 | { |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5217 | return tag >> DIRECT_LOOKUP_SHIFT; |
| 5218 | } |
| 5219 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5220 | |
| 5221 | static inline u32 hpsa_tag_discard_error_bits(struct ctlr_info *h, u32 tag) |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5222 | { |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5223 | #define HPSA_PERF_ERROR_BITS ((1 << DIRECT_LOOKUP_SHIFT) - 1) |
| 5224 | #define HPSA_SIMPLE_ERROR_BITS 0x03 |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 5225 | if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5226 | return tag & ~HPSA_SIMPLE_ERROR_BITS; |
| 5227 | return tag & ~HPSA_PERF_ERROR_BITS; |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5228 | } |
| 5229 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5230 | /* process completion of an indexed ("direct lookup") command */ |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5231 | static inline void process_indexed_cmd(struct ctlr_info *h, |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5232 | u32 raw_tag) |
| 5233 | { |
| 5234 | u32 tag_index; |
| 5235 | struct CommandList *c; |
| 5236 | |
| 5237 | tag_index = hpsa_tag_to_index(raw_tag); |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5238 | if (!bad_tag(h, tag_index, raw_tag)) { |
| 5239 | c = h->cmd_pool + tag_index; |
| 5240 | finish_cmd(c); |
| 5241 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | /* process completion of a non-indexed command */ |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5245 | static inline void process_nonindexed_cmd(struct ctlr_info *h, |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5246 | u32 raw_tag) |
| 5247 | { |
| 5248 | u32 tag; |
| 5249 | struct CommandList *c = NULL; |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5250 | unsigned long flags; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5251 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5252 | tag = hpsa_tag_discard_error_bits(h, raw_tag); |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5253 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 9e0fc76 | 2011-02-15 15:32:48 -0600 | [diff] [blame] | 5254 | list_for_each_entry(c, &h->cmpQ, list) { |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5255 | if ((c->busaddr & 0xFFFFFFE0) == (tag & 0xFFFFFFE0)) { |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5256 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 5a3d16f | 2012-05-01 11:42:46 -0500 | [diff] [blame] | 5257 | finish_cmd(c); |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5258 | return; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5259 | } |
| 5260 | } |
Matt Gates | e16a33a | 2012-05-01 11:43:11 -0500 | [diff] [blame] | 5261 | spin_unlock_irqrestore(&h->lock, flags); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5262 | bad_tag(h, h->nr_cmds + 1, raw_tag); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5263 | } |
| 5264 | |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5265 | /* Some controllers, like p400, will give us one interrupt |
| 5266 | * after a soft reset, even if we turned interrupts off. |
| 5267 | * Only need to check for this in the hpsa_xxx_discard_completions |
| 5268 | * functions. |
| 5269 | */ |
| 5270 | static int ignore_bogus_interrupt(struct ctlr_info *h) |
| 5271 | { |
| 5272 | if (likely(!reset_devices)) |
| 5273 | return 0; |
| 5274 | |
| 5275 | if (likely(h->interrupts_enabled)) |
| 5276 | return 0; |
| 5277 | |
| 5278 | dev_info(&h->pdev->dev, "Received interrupt while interrupts disabled " |
| 5279 | "(known firmware bug.) Ignoring.\n"); |
| 5280 | |
| 5281 | return 1; |
| 5282 | } |
| 5283 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5284 | /* |
| 5285 | * Convert &h->q[x] (passed to interrupt handlers) back to h. |
| 5286 | * Relies on (h-q[x] == x) being true for x such that |
| 5287 | * 0 <= x < MAX_REPLY_QUEUES. |
| 5288 | */ |
| 5289 | static struct ctlr_info *queue_to_hba(u8 *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5290 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5291 | return container_of((queue - *queue), struct ctlr_info, q[0]); |
| 5292 | } |
| 5293 | |
| 5294 | static irqreturn_t hpsa_intx_discard_completions(int irq, void *queue) |
| 5295 | { |
| 5296 | struct ctlr_info *h = queue_to_hba(queue); |
| 5297 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5298 | u32 raw_tag; |
| 5299 | |
| 5300 | if (ignore_bogus_interrupt(h)) |
| 5301 | return IRQ_NONE; |
| 5302 | |
| 5303 | if (interrupt_not_for_us(h)) |
| 5304 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5305 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5306 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5307 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5308 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5309 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5310 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5311 | return IRQ_HANDLED; |
| 5312 | } |
| 5313 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5314 | static irqreturn_t hpsa_msix_discard_completions(int irq, void *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5315 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5316 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5317 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5318 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5319 | |
| 5320 | if (ignore_bogus_interrupt(h)) |
| 5321 | return IRQ_NONE; |
| 5322 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5323 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5324 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5325 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5326 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5327 | return IRQ_HANDLED; |
| 5328 | } |
| 5329 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5330 | static irqreturn_t do_hpsa_intr_intx(int irq, void *queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5331 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5332 | struct ctlr_info *h = queue_to_hba((u8 *) queue); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5333 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5334 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5335 | |
| 5336 | if (interrupt_not_for_us(h)) |
| 5337 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5338 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5339 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5340 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5341 | while (raw_tag != FIFO_EMPTY) { |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5342 | if (likely(hpsa_tag_contains_index(raw_tag))) |
| 5343 | process_indexed_cmd(h, raw_tag); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5344 | else |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5345 | process_nonindexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5346 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5347 | } |
| 5348 | } |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5349 | return IRQ_HANDLED; |
| 5350 | } |
| 5351 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5352 | static irqreturn_t do_hpsa_intr_msi(int irq, void *queue) |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5353 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5354 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5355 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5356 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5357 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5358 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5359 | raw_tag = get_next_completion(h, q); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5360 | while (raw_tag != FIFO_EMPTY) { |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5361 | if (likely(hpsa_tag_contains_index(raw_tag))) |
| 5362 | process_indexed_cmd(h, raw_tag); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5363 | else |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5364 | process_nonindexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5365 | raw_tag = next_command(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5366 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5367 | return IRQ_HANDLED; |
| 5368 | } |
| 5369 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5370 | /* Send a message CDB to the firmware. Careful, this only works |
| 5371 | * in simple mode, not performant mode due to the tag lookup. |
| 5372 | * We only ever use this immediately after a controller reset. |
| 5373 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5374 | static int hpsa_message(struct pci_dev *pdev, unsigned char opcode, |
| 5375 | unsigned char type) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5376 | { |
| 5377 | struct Command { |
| 5378 | struct CommandListHeader CommandHeader; |
| 5379 | struct RequestBlock Request; |
| 5380 | struct ErrDescriptor ErrorDescriptor; |
| 5381 | }; |
| 5382 | struct Command *cmd; |
| 5383 | static const size_t cmd_sz = sizeof(*cmd) + |
| 5384 | sizeof(cmd->ErrorDescriptor); |
| 5385 | dma_addr_t paddr64; |
| 5386 | uint32_t paddr32, tag; |
| 5387 | void __iomem *vaddr; |
| 5388 | int i, err; |
| 5389 | |
| 5390 | vaddr = pci_ioremap_bar(pdev, 0); |
| 5391 | if (vaddr == NULL) |
| 5392 | return -ENOMEM; |
| 5393 | |
| 5394 | /* The Inbound Post Queue only accepts 32-bit physical addresses for the |
| 5395 | * CCISS commands, so they must be allocated from the lower 4GiB of |
| 5396 | * memory. |
| 5397 | */ |
| 5398 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 5399 | if (err) { |
| 5400 | iounmap(vaddr); |
| 5401 | return -ENOMEM; |
| 5402 | } |
| 5403 | |
| 5404 | cmd = pci_alloc_consistent(pdev, cmd_sz, &paddr64); |
| 5405 | if (cmd == NULL) { |
| 5406 | iounmap(vaddr); |
| 5407 | return -ENOMEM; |
| 5408 | } |
| 5409 | |
| 5410 | /* This must fit, because of the 32-bit consistent DMA mask. Also, |
| 5411 | * although there's no guarantee, we assume that the address is at |
| 5412 | * least 4-byte aligned (most likely, it's page-aligned). |
| 5413 | */ |
| 5414 | paddr32 = paddr64; |
| 5415 | |
| 5416 | cmd->CommandHeader.ReplyQueue = 0; |
| 5417 | cmd->CommandHeader.SGList = 0; |
| 5418 | cmd->CommandHeader.SGTotal = 0; |
| 5419 | cmd->CommandHeader.Tag.lower = paddr32; |
| 5420 | cmd->CommandHeader.Tag.upper = 0; |
| 5421 | memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8); |
| 5422 | |
| 5423 | cmd->Request.CDBLen = 16; |
| 5424 | cmd->Request.Type.Type = TYPE_MSG; |
| 5425 | cmd->Request.Type.Attribute = ATTR_HEADOFQUEUE; |
| 5426 | cmd->Request.Type.Direction = XFER_NONE; |
| 5427 | cmd->Request.Timeout = 0; /* Don't time out */ |
| 5428 | cmd->Request.CDB[0] = opcode; |
| 5429 | cmd->Request.CDB[1] = type; |
| 5430 | memset(&cmd->Request.CDB[2], 0, 14); /* rest of the CDB is reserved */ |
| 5431 | cmd->ErrorDescriptor.Addr.lower = paddr32 + sizeof(*cmd); |
| 5432 | cmd->ErrorDescriptor.Addr.upper = 0; |
| 5433 | cmd->ErrorDescriptor.Len = sizeof(struct ErrorInfo); |
| 5434 | |
| 5435 | writel(paddr32, vaddr + SA5_REQUEST_PORT_OFFSET); |
| 5436 | |
| 5437 | for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) { |
| 5438 | tag = readl(vaddr + SA5_REPLY_PORT_OFFSET); |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5439 | if ((tag & ~HPSA_SIMPLE_ERROR_BITS) == paddr32) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5440 | break; |
| 5441 | msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS); |
| 5442 | } |
| 5443 | |
| 5444 | iounmap(vaddr); |
| 5445 | |
| 5446 | /* we leak the DMA buffer here ... no choice since the controller could |
| 5447 | * still complete the command. |
| 5448 | */ |
| 5449 | if (i == HPSA_MSG_SEND_RETRY_LIMIT) { |
| 5450 | dev_err(&pdev->dev, "controller message %02x:%02x timed out\n", |
| 5451 | opcode, type); |
| 5452 | return -ETIMEDOUT; |
| 5453 | } |
| 5454 | |
| 5455 | pci_free_consistent(pdev, cmd_sz, cmd, paddr64); |
| 5456 | |
| 5457 | if (tag & HPSA_ERROR_BIT) { |
| 5458 | dev_err(&pdev->dev, "controller message %02x:%02x failed\n", |
| 5459 | opcode, type); |
| 5460 | return -EIO; |
| 5461 | } |
| 5462 | |
| 5463 | dev_info(&pdev->dev, "controller message %02x:%02x succeeded\n", |
| 5464 | opcode, type); |
| 5465 | return 0; |
| 5466 | } |
| 5467 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5468 | #define hpsa_noop(p) hpsa_message(p, 3, 0) |
| 5469 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5470 | static int hpsa_controller_hard_reset(struct pci_dev *pdev, |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5471 | void * __iomem vaddr, u32 use_doorbell) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5472 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5473 | u16 pmcsr; |
| 5474 | int pos; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5475 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5476 | if (use_doorbell) { |
| 5477 | /* For everything after the P600, the PCI power state method |
| 5478 | * of resetting the controller doesn't work, so we have this |
| 5479 | * other way using the doorbell register. |
| 5480 | */ |
| 5481 | dev_info(&pdev->dev, "using doorbell to reset controller\n"); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5482 | writel(use_doorbell, vaddr + SA5_DOORBELL); |
Stephen M. Cameron | 8500923 | 2013-09-23 13:33:36 -0500 | [diff] [blame] | 5483 | |
| 5484 | /* PMC hardware guys tell us we need a 5 second delay after |
| 5485 | * doorbell reset and before any attempt to talk to the board |
| 5486 | * at all to ensure that this actually works and doesn't fall |
| 5487 | * over in some weird corner cases. |
| 5488 | */ |
| 5489 | msleep(5000); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5490 | } else { /* Try to do it the PCI power state way */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5491 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5492 | /* Quoting from the Open CISS Specification: "The Power |
| 5493 | * Management Control/Status Register (CSR) controls the power |
| 5494 | * state of the device. The normal operating state is D0, |
| 5495 | * CSR=00h. The software off state is D3, CSR=03h. To reset |
| 5496 | * the controller, place the interface device in D3 then to D0, |
| 5497 | * this causes a secondary PCI reset which will reset the |
| 5498 | * controller." */ |
| 5499 | |
| 5500 | pos = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 5501 | if (pos == 0) { |
| 5502 | dev_err(&pdev->dev, |
| 5503 | "hpsa_reset_controller: " |
| 5504 | "PCI PM not supported\n"); |
| 5505 | return -ENODEV; |
| 5506 | } |
| 5507 | dev_info(&pdev->dev, "using PCI PM to reset controller\n"); |
| 5508 | /* enter the D3hot power management state */ |
| 5509 | pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr); |
| 5510 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 5511 | pmcsr |= PCI_D3hot; |
| 5512 | pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); |
| 5513 | |
| 5514 | msleep(500); |
| 5515 | |
| 5516 | /* enter the D0 power management state */ |
| 5517 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 5518 | pmcsr |= PCI_D0; |
| 5519 | pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); |
Mike Miller | c4853ef | 2011-10-21 08:19:43 +0200 | [diff] [blame] | 5520 | |
| 5521 | /* |
| 5522 | * The P600 requires a small delay when changing states. |
| 5523 | * Otherwise we may think the board did not reset and we bail. |
| 5524 | * This for kdump only and is particular to the P600. |
| 5525 | */ |
| 5526 | msleep(500); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5527 | } |
| 5528 | return 0; |
| 5529 | } |
| 5530 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5531 | static void init_driver_version(char *driver_version, int len) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5532 | { |
| 5533 | memset(driver_version, 0, len); |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 5534 | strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1); |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5535 | } |
| 5536 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5537 | static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5538 | { |
| 5539 | char *driver_version; |
| 5540 | int i, size = sizeof(cfgtable->driver_version); |
| 5541 | |
| 5542 | driver_version = kmalloc(size, GFP_KERNEL); |
| 5543 | if (!driver_version) |
| 5544 | return -ENOMEM; |
| 5545 | |
| 5546 | init_driver_version(driver_version, size); |
| 5547 | for (i = 0; i < size; i++) |
| 5548 | writeb(driver_version[i], &cfgtable->driver_version[i]); |
| 5549 | kfree(driver_version); |
| 5550 | return 0; |
| 5551 | } |
| 5552 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5553 | static void read_driver_ver_from_cfgtable(struct CfgTable __iomem *cfgtable, |
| 5554 | unsigned char *driver_ver) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5555 | { |
| 5556 | int i; |
| 5557 | |
| 5558 | for (i = 0; i < sizeof(cfgtable->driver_version); i++) |
| 5559 | driver_ver[i] = readb(&cfgtable->driver_version[i]); |
| 5560 | } |
| 5561 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5562 | static int controller_reset_failed(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5563 | { |
| 5564 | |
| 5565 | char *driver_ver, *old_driver_ver; |
| 5566 | int rc, size = sizeof(cfgtable->driver_version); |
| 5567 | |
| 5568 | old_driver_ver = kmalloc(2 * size, GFP_KERNEL); |
| 5569 | if (!old_driver_ver) |
| 5570 | return -ENOMEM; |
| 5571 | driver_ver = old_driver_ver + size; |
| 5572 | |
| 5573 | /* After a reset, the 32 bytes of "driver version" in the cfgtable |
| 5574 | * should have been changed, otherwise we know the reset failed. |
| 5575 | */ |
| 5576 | init_driver_version(old_driver_ver, size); |
| 5577 | read_driver_ver_from_cfgtable(cfgtable, driver_ver); |
| 5578 | rc = !memcmp(driver_ver, old_driver_ver, size); |
| 5579 | kfree(old_driver_ver); |
| 5580 | return rc; |
| 5581 | } |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5582 | /* This does a hard reset of the controller using PCI power management |
| 5583 | * states or the using the doorbell register. |
| 5584 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5585 | static int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev) |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5586 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5587 | u64 cfg_offset; |
| 5588 | u32 cfg_base_addr; |
| 5589 | u64 cfg_base_addr_index; |
| 5590 | void __iomem *vaddr; |
| 5591 | unsigned long paddr; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5592 | u32 misc_fw_support; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5593 | int rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5594 | struct CfgTable __iomem *cfgtable; |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5595 | u32 use_doorbell; |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 5596 | u32 board_id; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5597 | u16 command_register; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5598 | |
| 5599 | /* For controllers as old as the P600, this is very nearly |
| 5600 | * the same thing as |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5601 | * |
| 5602 | * pci_save_state(pci_dev); |
| 5603 | * pci_set_power_state(pci_dev, PCI_D3hot); |
| 5604 | * pci_set_power_state(pci_dev, PCI_D0); |
| 5605 | * pci_restore_state(pci_dev); |
| 5606 | * |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5607 | * For controllers newer than the P600, the pci power state |
| 5608 | * method of resetting doesn't work so we have another way |
| 5609 | * using the doorbell register. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5610 | */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 5611 | |
Stephen M. Cameron | 25c1e56a | 2011-01-06 14:48:18 -0600 | [diff] [blame] | 5612 | rc = hpsa_lookup_board_id(pdev, &board_id); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 5613 | if (rc < 0 || !ctlr_is_resettable(board_id)) { |
Stephen M. Cameron | 25c1e56a | 2011-01-06 14:48:18 -0600 | [diff] [blame] | 5614 | dev_warn(&pdev->dev, "Not resetting device.\n"); |
| 5615 | return -ENODEV; |
| 5616 | } |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 5617 | |
| 5618 | /* if controller is soft- but not hard resettable... */ |
| 5619 | if (!ctlr_is_hard_resettable(board_id)) |
| 5620 | return -ENOTSUPP; /* try soft reset later. */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 5621 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5622 | /* Save the PCI command register */ |
| 5623 | pci_read_config_word(pdev, 4, &command_register); |
| 5624 | /* Turn the board off. This is so that later pci_restore_state() |
| 5625 | * won't turn the board on before the rest of config space is ready. |
| 5626 | */ |
| 5627 | pci_disable_device(pdev); |
| 5628 | pci_save_state(pdev); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5629 | |
| 5630 | /* find the first memory BAR, so we can find the cfg table */ |
| 5631 | rc = hpsa_pci_find_memory_BAR(pdev, &paddr); |
| 5632 | if (rc) |
| 5633 | return rc; |
| 5634 | vaddr = remap_pci_mem(paddr, 0x250); |
| 5635 | if (!vaddr) |
| 5636 | return -ENOMEM; |
| 5637 | |
| 5638 | /* find cfgtable in order to check if reset via doorbell is supported */ |
| 5639 | rc = hpsa_find_cfg_addrs(pdev, vaddr, &cfg_base_addr, |
| 5640 | &cfg_base_addr_index, &cfg_offset); |
| 5641 | if (rc) |
| 5642 | goto unmap_vaddr; |
| 5643 | cfgtable = remap_pci_mem(pci_resource_start(pdev, |
| 5644 | cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable)); |
| 5645 | if (!cfgtable) { |
| 5646 | rc = -ENOMEM; |
| 5647 | goto unmap_vaddr; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5648 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5649 | rc = write_driver_ver_to_cfgtable(cfgtable); |
| 5650 | if (rc) |
| 5651 | goto unmap_vaddr; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5652 | |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5653 | /* If reset via doorbell register is supported, use that. |
| 5654 | * There are two such methods. Favor the newest method. |
| 5655 | */ |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5656 | misc_fw_support = readl(&cfgtable->misc_fw_support); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5657 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET2; |
| 5658 | if (use_doorbell) { |
| 5659 | use_doorbell = DOORBELL_CTLR_RESET2; |
| 5660 | } else { |
| 5661 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET; |
| 5662 | if (use_doorbell) { |
Mike Miller | fba6309 | 2011-10-13 11:44:06 -0500 | [diff] [blame] | 5663 | dev_warn(&pdev->dev, "Soft reset not supported. " |
| 5664 | "Firmware update is required.\n"); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5665 | rc = -ENOTSUPP; /* try soft reset */ |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5666 | goto unmap_cfgtable; |
| 5667 | } |
| 5668 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5669 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5670 | rc = hpsa_controller_hard_reset(pdev, vaddr, use_doorbell); |
| 5671 | if (rc) |
| 5672 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5673 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5674 | pci_restore_state(pdev); |
| 5675 | rc = pci_enable_device(pdev); |
| 5676 | if (rc) { |
| 5677 | dev_warn(&pdev->dev, "failed to enable device.\n"); |
| 5678 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5679 | } |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5680 | pci_write_config_word(pdev, 4, command_register); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5681 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5682 | /* Some devices (notably the HP Smart Array 5i Controller) |
| 5683 | need a little pause here */ |
| 5684 | msleep(HPSA_POST_RESET_PAUSE_MSECS); |
| 5685 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5686 | rc = hpsa_wait_for_board_state(pdev, vaddr, BOARD_READY); |
| 5687 | if (rc) { |
| 5688 | dev_warn(&pdev->dev, |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5689 | "failed waiting for board to become ready " |
| 5690 | "after hard reset\n"); |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5691 | goto unmap_cfgtable; |
| 5692 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5693 | |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5694 | rc = controller_reset_failed(vaddr); |
| 5695 | if (rc < 0) |
| 5696 | goto unmap_cfgtable; |
| 5697 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5698 | dev_warn(&pdev->dev, "Unable to successfully reset " |
| 5699 | "controller. Will try soft reset.\n"); |
| 5700 | rc = -ENOTSUPP; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5701 | } else { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5702 | dev_info(&pdev->dev, "board ready after hard reset.\n"); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | unmap_cfgtable: |
| 5706 | iounmap(cfgtable); |
| 5707 | |
| 5708 | unmap_vaddr: |
| 5709 | iounmap(vaddr); |
| 5710 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | /* |
| 5714 | * We cannot read the structure directly, for portability we must use |
| 5715 | * the io functions. |
| 5716 | * This is for debug only. |
| 5717 | */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5718 | static void print_cfg_table(struct device *dev, struct CfgTable *tb) |
| 5719 | { |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 5720 | #ifdef HPSA_DEBUG |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5721 | int i; |
| 5722 | char temp_name[17]; |
| 5723 | |
| 5724 | dev_info(dev, "Controller Configuration information\n"); |
| 5725 | dev_info(dev, "------------------------------------\n"); |
| 5726 | for (i = 0; i < 4; i++) |
| 5727 | temp_name[i] = readb(&(tb->Signature[i])); |
| 5728 | temp_name[4] = '\0'; |
| 5729 | dev_info(dev, " Signature = %s\n", temp_name); |
| 5730 | dev_info(dev, " Spec Number = %d\n", readl(&(tb->SpecValence))); |
| 5731 | dev_info(dev, " Transport methods supported = 0x%x\n", |
| 5732 | readl(&(tb->TransportSupport))); |
| 5733 | dev_info(dev, " Transport methods active = 0x%x\n", |
| 5734 | readl(&(tb->TransportActive))); |
| 5735 | dev_info(dev, " Requested transport Method = 0x%x\n", |
| 5736 | readl(&(tb->HostWrite.TransportRequest))); |
| 5737 | dev_info(dev, " Coalesce Interrupt Delay = 0x%x\n", |
| 5738 | readl(&(tb->HostWrite.CoalIntDelay))); |
| 5739 | dev_info(dev, " Coalesce Interrupt Count = 0x%x\n", |
| 5740 | readl(&(tb->HostWrite.CoalIntCount))); |
| 5741 | dev_info(dev, " Max outstanding commands = 0x%d\n", |
| 5742 | readl(&(tb->CmdsOutMax))); |
| 5743 | dev_info(dev, " Bus Types = 0x%x\n", readl(&(tb->BusTypes))); |
| 5744 | for (i = 0; i < 16; i++) |
| 5745 | temp_name[i] = readb(&(tb->ServerName[i])); |
| 5746 | temp_name[16] = '\0'; |
| 5747 | dev_info(dev, " Server Name = %s\n", temp_name); |
| 5748 | dev_info(dev, " Heartbeat Counter = 0x%x\n\n\n", |
| 5749 | readl(&(tb->HeartBeat))); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5750 | #endif /* HPSA_DEBUG */ |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 5751 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5752 | |
| 5753 | static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) |
| 5754 | { |
| 5755 | int i, offset, mem_type, bar_type; |
| 5756 | |
| 5757 | if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */ |
| 5758 | return 0; |
| 5759 | offset = 0; |
| 5760 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 5761 | bar_type = pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE; |
| 5762 | if (bar_type == PCI_BASE_ADDRESS_SPACE_IO) |
| 5763 | offset += 4; |
| 5764 | else { |
| 5765 | mem_type = pci_resource_flags(pdev, i) & |
| 5766 | PCI_BASE_ADDRESS_MEM_TYPE_MASK; |
| 5767 | switch (mem_type) { |
| 5768 | case PCI_BASE_ADDRESS_MEM_TYPE_32: |
| 5769 | case PCI_BASE_ADDRESS_MEM_TYPE_1M: |
| 5770 | offset += 4; /* 32 bit */ |
| 5771 | break; |
| 5772 | case PCI_BASE_ADDRESS_MEM_TYPE_64: |
| 5773 | offset += 8; |
| 5774 | break; |
| 5775 | default: /* reserved in PCI 2.2 */ |
| 5776 | dev_warn(&pdev->dev, |
| 5777 | "base address is invalid\n"); |
| 5778 | return -1; |
| 5779 | break; |
| 5780 | } |
| 5781 | } |
| 5782 | if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0) |
| 5783 | return i + 1; |
| 5784 | } |
| 5785 | return -1; |
| 5786 | } |
| 5787 | |
| 5788 | /* If MSI/MSI-X is supported by the kernel we will try to enable it on |
| 5789 | * controllers that are capable. If not, we use IO-APIC mode. |
| 5790 | */ |
| 5791 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5792 | static void hpsa_interrupt_mode(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5793 | { |
| 5794 | #ifdef CONFIG_PCI_MSI |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5795 | int err, i; |
| 5796 | struct msix_entry hpsa_msix_entries[MAX_REPLY_QUEUES]; |
| 5797 | |
| 5798 | for (i = 0; i < MAX_REPLY_QUEUES; i++) { |
| 5799 | hpsa_msix_entries[i].vector = 0; |
| 5800 | hpsa_msix_entries[i].entry = i; |
| 5801 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5802 | |
| 5803 | /* Some boards advertise MSI but don't really support it */ |
Stephen M. Cameron | 6b3f4c5 | 2010-05-27 15:13:02 -0500 | [diff] [blame] | 5804 | if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) || |
| 5805 | (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5806 | goto default_int_mode; |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5807 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) { |
| 5808 | dev_info(&h->pdev->dev, "MSIX\n"); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 5809 | h->msix_vector = MAX_REPLY_QUEUES; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5810 | err = pci_enable_msix(h->pdev, hpsa_msix_entries, |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 5811 | h->msix_vector); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5812 | if (err > 0) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5813 | dev_warn(&h->pdev->dev, "only %d MSI-X vectors " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5814 | "available\n", err); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 5815 | h->msix_vector = err; |
| 5816 | err = pci_enable_msix(h->pdev, hpsa_msix_entries, |
| 5817 | h->msix_vector); |
| 5818 | } |
| 5819 | if (!err) { |
| 5820 | for (i = 0; i < h->msix_vector; i++) |
| 5821 | h->intr[i] = hpsa_msix_entries[i].vector; |
| 5822 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5823 | } else { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5824 | dev_warn(&h->pdev->dev, "MSI-X init failed %d\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5825 | err); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 5826 | h->msix_vector = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5827 | goto default_int_mode; |
| 5828 | } |
| 5829 | } |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5830 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) { |
| 5831 | dev_info(&h->pdev->dev, "MSI\n"); |
| 5832 | if (!pci_enable_msi(h->pdev)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5833 | h->msi_vector = 1; |
| 5834 | else |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5835 | dev_warn(&h->pdev->dev, "MSI init failed\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5836 | } |
| 5837 | default_int_mode: |
| 5838 | #endif /* CONFIG_PCI_MSI */ |
| 5839 | /* if we get here we're going to use the default interrupt mode */ |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5840 | h->intr[h->intr_mode] = h->pdev->irq; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5841 | } |
| 5842 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5843 | static int hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id) |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 5844 | { |
| 5845 | int i; |
| 5846 | u32 subsystem_vendor_id, subsystem_device_id; |
| 5847 | |
| 5848 | subsystem_vendor_id = pdev->subsystem_vendor; |
| 5849 | subsystem_device_id = pdev->subsystem_device; |
| 5850 | *board_id = ((subsystem_device_id << 16) & 0xffff0000) | |
| 5851 | subsystem_vendor_id; |
| 5852 | |
| 5853 | for (i = 0; i < ARRAY_SIZE(products); i++) |
| 5854 | if (*board_id == products[i].board_id) |
| 5855 | return i; |
| 5856 | |
Stephen M. Cameron | 6798cc0 | 2010-06-16 13:51:20 -0500 | [diff] [blame] | 5857 | if ((subsystem_vendor_id != PCI_VENDOR_ID_HP && |
| 5858 | subsystem_vendor_id != PCI_VENDOR_ID_COMPAQ) || |
| 5859 | !hpsa_allow_any) { |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 5860 | dev_warn(&pdev->dev, "unrecognized board ID: " |
| 5861 | "0x%08x, ignoring.\n", *board_id); |
| 5862 | return -ENODEV; |
| 5863 | } |
| 5864 | return ARRAY_SIZE(products) - 1; /* generic unknown smart array */ |
| 5865 | } |
| 5866 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5867 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 5868 | unsigned long *memory_bar) |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 5869 | { |
| 5870 | int i; |
| 5871 | |
| 5872 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 5873 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 5874 | /* addressing mode bits already removed */ |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 5875 | *memory_bar = pci_resource_start(pdev, i); |
| 5876 | dev_dbg(&pdev->dev, "memory BAR = %lx\n", |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 5877 | *memory_bar); |
| 5878 | return 0; |
| 5879 | } |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 5880 | dev_warn(&pdev->dev, "no memory BAR found\n"); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 5881 | return -ENODEV; |
| 5882 | } |
| 5883 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5884 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 5885 | int wait_for_ready) |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 5886 | { |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5887 | int i, iterations; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 5888 | u32 scratchpad; |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5889 | if (wait_for_ready) |
| 5890 | iterations = HPSA_BOARD_READY_ITERATIONS; |
| 5891 | else |
| 5892 | iterations = HPSA_BOARD_NOT_READY_ITERATIONS; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 5893 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5894 | for (i = 0; i < iterations; i++) { |
| 5895 | scratchpad = readl(vaddr + SA5_SCRATCHPAD_OFFSET); |
| 5896 | if (wait_for_ready) { |
| 5897 | if (scratchpad == HPSA_FIRMWARE_READY) |
| 5898 | return 0; |
| 5899 | } else { |
| 5900 | if (scratchpad != HPSA_FIRMWARE_READY) |
| 5901 | return 0; |
| 5902 | } |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 5903 | msleep(HPSA_BOARD_READY_POLL_INTERVAL_MSECS); |
| 5904 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5905 | dev_warn(&pdev->dev, "board not ready, timed out.\n"); |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 5906 | return -ENODEV; |
| 5907 | } |
| 5908 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5909 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 5910 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 5911 | u64 *cfg_offset) |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 5912 | { |
| 5913 | *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET); |
| 5914 | *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET); |
| 5915 | *cfg_base_addr &= (u32) 0x0000ffff; |
| 5916 | *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr); |
| 5917 | if (*cfg_base_addr_index == -1) { |
| 5918 | dev_warn(&pdev->dev, "cannot find cfg_base_addr_index\n"); |
| 5919 | return -ENODEV; |
| 5920 | } |
| 5921 | return 0; |
| 5922 | } |
| 5923 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5924 | static int hpsa_find_cfgtables(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5925 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 5926 | u64 cfg_offset; |
| 5927 | u32 cfg_base_addr; |
| 5928 | u64 cfg_base_addr_index; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5929 | u32 trans_offset; |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 5930 | int rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 5931 | |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 5932 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 5933 | &cfg_base_addr_index, &cfg_offset); |
| 5934 | if (rc) |
| 5935 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 5936 | h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev, |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 5937 | cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable)); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 5938 | if (!h->cfgtable) |
| 5939 | return -ENOMEM; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5940 | rc = write_driver_ver_to_cfgtable(h->cfgtable); |
| 5941 | if (rc) |
| 5942 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 5943 | /* Find performant mode table. */ |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 5944 | trans_offset = readl(&h->cfgtable->TransMethodOffset); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 5945 | h->transtable = remap_pci_mem(pci_resource_start(h->pdev, |
| 5946 | cfg_base_addr_index)+cfg_offset+trans_offset, |
| 5947 | sizeof(*h->transtable)); |
| 5948 | if (!h->transtable) |
| 5949 | return -ENOMEM; |
| 5950 | return 0; |
| 5951 | } |
| 5952 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5953 | static void hpsa_get_max_perf_mode_cmds(struct ctlr_info *h) |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 5954 | { |
| 5955 | h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands)); |
Stephen M. Cameron | 72ceeae | 2011-01-06 14:48:13 -0600 | [diff] [blame] | 5956 | |
| 5957 | /* Limit commands in memory limited kdump scenario. */ |
| 5958 | if (reset_devices && h->max_commands > 32) |
| 5959 | h->max_commands = 32; |
| 5960 | |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 5961 | if (h->max_commands < 16) { |
| 5962 | dev_warn(&h->pdev->dev, "Controller reports " |
| 5963 | "max supported commands of %d, an obvious lie. " |
| 5964 | "Using 16. Ensure that firmware is up to date.\n", |
| 5965 | h->max_commands); |
| 5966 | h->max_commands = 16; |
| 5967 | } |
| 5968 | } |
| 5969 | |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 5970 | /* Interrogate the hardware for some limits: |
| 5971 | * max commands, max SG elements without chaining, and with chaining, |
| 5972 | * SG chain block size, etc. |
| 5973 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5974 | static void hpsa_find_board_params(struct ctlr_info *h) |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 5975 | { |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 5976 | hpsa_get_max_perf_mode_cmds(h); |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 5977 | h->nr_cmds = h->max_commands - 4; /* Allow room for some ioctls */ |
| 5978 | h->maxsgentries = readl(&(h->cfgtable->MaxScatterGatherElements)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5979 | h->fw_support = readl(&(h->cfgtable->misc_fw_support)); |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 5980 | /* |
| 5981 | * Limit in-command s/g elements to 32 save dma'able memory. |
| 5982 | * Howvever spec says if 0, use 31 |
| 5983 | */ |
| 5984 | h->max_cmd_sg_entries = 31; |
| 5985 | if (h->maxsgentries > 512) { |
| 5986 | h->max_cmd_sg_entries = 32; |
| 5987 | h->chainsize = h->maxsgentries - h->max_cmd_sg_entries + 1; |
| 5988 | h->maxsgentries--; /* save one for chain pointer */ |
| 5989 | } else { |
| 5990 | h->maxsgentries = 31; /* default to traditional values */ |
| 5991 | h->chainsize = 0; |
| 5992 | } |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5993 | |
| 5994 | /* Find out what task management functions are supported and cache */ |
| 5995 | h->TMFSupportFlags = readl(&(h->cfgtable->TMFSupportFlags)); |
Scott Teel | 0e7a7fc | 2014-02-18 13:55:59 -0600 | [diff] [blame] | 5996 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags)) |
| 5997 | dev_warn(&h->pdev->dev, "Physical aborts not supported\n"); |
| 5998 | if (!(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 5999 | dev_warn(&h->pdev->dev, "Logical aborts not supported\n"); |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6000 | } |
| 6001 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 6002 | static inline bool hpsa_CISS_signature_present(struct ctlr_info *h) |
| 6003 | { |
Akinobu Mita | 0fc9fd4 | 2012-04-04 22:14:59 +0900 | [diff] [blame] | 6004 | if (!check_signature(h->cfgtable->Signature, "CISS", 4)) { |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 6005 | dev_warn(&h->pdev->dev, "not a valid CISS config table\n"); |
| 6006 | return false; |
| 6007 | } |
| 6008 | return true; |
| 6009 | } |
| 6010 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6011 | static inline void hpsa_set_driver_support_bits(struct ctlr_info *h) |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6012 | { |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6013 | u32 driver_support; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6014 | |
Stephen M. Cameron | 28e1344 | 2013-12-04 17:10:21 -0600 | [diff] [blame] | 6015 | #ifdef CONFIG_X86 |
| 6016 | /* Need to enable prefetch in the SCSI core for 6400 in x86 */ |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6017 | driver_support = readl(&(h->cfgtable->driver_support)); |
| 6018 | driver_support |= ENABLE_SCSI_PREFETCH; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6019 | #endif |
Stephen M. Cameron | 28e1344 | 2013-12-04 17:10:21 -0600 | [diff] [blame] | 6020 | driver_support |= ENABLE_UNIT_ATTN; |
| 6021 | writel(driver_support, &(h->cfgtable->driver_support)); |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6022 | } |
| 6023 | |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 6024 | /* Disable DMA prefetch for the P600. Otherwise an ASIC bug may result |
| 6025 | * in a prefetch beyond physical memory. |
| 6026 | */ |
| 6027 | static inline void hpsa_p600_dma_prefetch_quirk(struct ctlr_info *h) |
| 6028 | { |
| 6029 | u32 dma_prefetch; |
| 6030 | |
| 6031 | if (h->board_id != 0x3225103C) |
| 6032 | return; |
| 6033 | dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG); |
| 6034 | dma_prefetch |= 0x8000; |
| 6035 | writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG); |
| 6036 | } |
| 6037 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6038 | static void hpsa_wait_for_clear_event_notify_ack(struct ctlr_info *h) |
| 6039 | { |
| 6040 | int i; |
| 6041 | u32 doorbell_value; |
| 6042 | unsigned long flags; |
| 6043 | /* wait until the clear_event_notify bit 6 is cleared by controller. */ |
| 6044 | for (i = 0; i < MAX_CONFIG_WAIT; i++) { |
| 6045 | spin_lock_irqsave(&h->lock, flags); |
| 6046 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 6047 | spin_unlock_irqrestore(&h->lock, flags); |
| 6048 | if (!(doorbell_value & DOORBELL_CLEAR_EVENTS)) |
| 6049 | break; |
| 6050 | /* delay and try again */ |
| 6051 | msleep(20); |
| 6052 | } |
| 6053 | } |
| 6054 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6055 | static void hpsa_wait_for_mode_change_ack(struct ctlr_info *h) |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6056 | { |
| 6057 | int i; |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6058 | u32 doorbell_value; |
| 6059 | unsigned long flags; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6060 | |
| 6061 | /* under certain very rare conditions, this can take awhile. |
| 6062 | * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right |
| 6063 | * as we enter this code.) |
| 6064 | */ |
| 6065 | for (i = 0; i < MAX_CONFIG_WAIT; i++) { |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6066 | spin_lock_irqsave(&h->lock, flags); |
| 6067 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 6068 | spin_unlock_irqrestore(&h->lock, flags); |
Dan Carpenter | 382be66 | 2011-02-15 15:33:13 -0600 | [diff] [blame] | 6069 | if (!(doorbell_value & CFGTBL_ChangeReq)) |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6070 | break; |
| 6071 | /* delay and try again */ |
Stephen M. Cameron | 60d3f5b | 2011-01-06 14:48:34 -0600 | [diff] [blame] | 6072 | usleep_range(10000, 20000); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6073 | } |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6074 | } |
| 6075 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6076 | static int hpsa_enter_simple_mode(struct ctlr_info *h) |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6077 | { |
| 6078 | u32 trans_support; |
| 6079 | |
| 6080 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 6081 | if (!(trans_support & SIMPLE_MODE)) |
| 6082 | return -ENOTSUPP; |
| 6083 | |
| 6084 | h->max_commands = readl(&(h->cfgtable->CmdsOutMax)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6085 | |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6086 | /* Update the field, and then ring the doorbell */ |
| 6087 | writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest)); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6088 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6089 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
| 6090 | hpsa_wait_for_mode_change_ack(h); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6091 | print_cfg_table(&h->pdev->dev, h->cfgtable); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6092 | if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) |
| 6093 | goto error; |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 6094 | h->transMethod = CFGTBL_Trans_Simple; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6095 | return 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6096 | error: |
| 6097 | dev_warn(&h->pdev->dev, "unable to get board into simple mode\n"); |
| 6098 | return -ENODEV; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6099 | } |
| 6100 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6101 | static int hpsa_pci_init(struct ctlr_info *h) |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6102 | { |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6103 | int prod_index, err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6104 | |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 6105 | prod_index = hpsa_lookup_board_id(h->pdev, &h->board_id); |
| 6106 | if (prod_index < 0) |
| 6107 | return -ENODEV; |
| 6108 | h->product_name = products[prod_index].product_name; |
| 6109 | h->access = *(products[prod_index].access); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6110 | |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 6111 | pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S | |
| 6112 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); |
| 6113 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6114 | err = pci_enable_device(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6115 | if (err) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6116 | dev_warn(&h->pdev->dev, "unable to enable PCI device\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6117 | return err; |
| 6118 | } |
| 6119 | |
Stephen M. Cameron | 5cb460a | 2012-05-01 11:42:20 -0500 | [diff] [blame] | 6120 | /* Enable bus mastering (pci_disable_device may disable this) */ |
| 6121 | pci_set_master(h->pdev); |
| 6122 | |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 6123 | err = pci_request_regions(h->pdev, HPSA); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6124 | if (err) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6125 | dev_err(&h->pdev->dev, |
| 6126 | "cannot obtain PCI resources, aborting\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6127 | return err; |
| 6128 | } |
Stephen M. Cameron | 6b3f4c5 | 2010-05-27 15:13:02 -0500 | [diff] [blame] | 6129 | hpsa_interrupt_mode(h); |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 6130 | err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 6131 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6132 | goto err_out_free_res; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6133 | h->vaddr = remap_pci_mem(h->paddr, 0x250); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 6134 | if (!h->vaddr) { |
| 6135 | err = -ENOMEM; |
| 6136 | goto err_out_free_res; |
| 6137 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 6138 | err = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY); |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 6139 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6140 | goto err_out_free_res; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6141 | err = hpsa_find_cfgtables(h); |
| 6142 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6143 | goto err_out_free_res; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6144 | hpsa_find_board_params(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6145 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 6146 | if (!hpsa_CISS_signature_present(h)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6147 | err = -ENODEV; |
| 6148 | goto err_out_free_res; |
| 6149 | } |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6150 | hpsa_set_driver_support_bits(h); |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 6151 | hpsa_p600_dma_prefetch_quirk(h); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6152 | err = hpsa_enter_simple_mode(h); |
| 6153 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6154 | goto err_out_free_res; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6155 | return 0; |
| 6156 | |
| 6157 | err_out_free_res: |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 6158 | if (h->transtable) |
| 6159 | iounmap(h->transtable); |
| 6160 | if (h->cfgtable) |
| 6161 | iounmap(h->cfgtable); |
| 6162 | if (h->vaddr) |
| 6163 | iounmap(h->vaddr); |
Stephen M. Cameron | f0bd0b68 | 2012-05-01 11:42:09 -0500 | [diff] [blame] | 6164 | pci_disable_device(h->pdev); |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6165 | pci_release_regions(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6166 | return err; |
| 6167 | } |
| 6168 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6169 | static void hpsa_hba_inquiry(struct ctlr_info *h) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 6170 | { |
| 6171 | int rc; |
| 6172 | |
| 6173 | #define HBA_INQUIRY_BYTE_COUNT 64 |
| 6174 | h->hba_inquiry_data = kmalloc(HBA_INQUIRY_BYTE_COUNT, GFP_KERNEL); |
| 6175 | if (!h->hba_inquiry_data) |
| 6176 | return; |
| 6177 | rc = hpsa_scsi_do_inquiry(h, RAID_CTLR_LUNID, 0, |
| 6178 | h->hba_inquiry_data, HBA_INQUIRY_BYTE_COUNT); |
| 6179 | if (rc != 0) { |
| 6180 | kfree(h->hba_inquiry_data); |
| 6181 | h->hba_inquiry_data = NULL; |
| 6182 | } |
| 6183 | } |
| 6184 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6185 | static int hpsa_init_reset_devices(struct pci_dev *pdev) |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6186 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6187 | int rc, i; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6188 | |
| 6189 | if (!reset_devices) |
| 6190 | return 0; |
| 6191 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6192 | /* Reset the controller with a PCI power-cycle or via doorbell */ |
| 6193 | rc = hpsa_kdump_hard_reset_controller(pdev); |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6194 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6195 | /* -ENOTSUPP here means we cannot reset the controller |
| 6196 | * but it's already (and still) up and running in |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 6197 | * "performant mode". Or, it might be 640x, which can't reset |
| 6198 | * due to concerns about shared bbwc between 6402/6404 pair. |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6199 | */ |
| 6200 | if (rc == -ENOTSUPP) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6201 | return rc; /* just try to do the kdump anyhow. */ |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6202 | if (rc) |
| 6203 | return -ENODEV; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6204 | |
| 6205 | /* Now try to get the controller to respond to a no-op */ |
Stephen M. Cameron | 2b870cb | 2011-05-03 14:59:36 -0500 | [diff] [blame] | 6206 | dev_warn(&pdev->dev, "Waiting for controller to respond to no-op\n"); |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6207 | for (i = 0; i < HPSA_POST_RESET_NOOP_RETRIES; i++) { |
| 6208 | if (hpsa_noop(pdev) == 0) |
| 6209 | break; |
| 6210 | else |
| 6211 | dev_warn(&pdev->dev, "no-op failed%s\n", |
| 6212 | (i < 11 ? "; re-trying" : "")); |
| 6213 | } |
| 6214 | return 0; |
| 6215 | } |
| 6216 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6217 | static int hpsa_allocate_cmd_pool(struct ctlr_info *h) |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6218 | { |
| 6219 | h->cmd_pool_bits = kzalloc( |
| 6220 | DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) * |
| 6221 | sizeof(unsigned long), GFP_KERNEL); |
| 6222 | h->cmd_pool = pci_alloc_consistent(h->pdev, |
| 6223 | h->nr_cmds * sizeof(*h->cmd_pool), |
| 6224 | &(h->cmd_pool_dhandle)); |
| 6225 | h->errinfo_pool = pci_alloc_consistent(h->pdev, |
| 6226 | h->nr_cmds * sizeof(*h->errinfo_pool), |
| 6227 | &(h->errinfo_pool_dhandle)); |
| 6228 | if ((h->cmd_pool_bits == NULL) |
| 6229 | || (h->cmd_pool == NULL) |
| 6230 | || (h->errinfo_pool == NULL)) { |
| 6231 | dev_err(&h->pdev->dev, "out of memory in %s", __func__); |
| 6232 | return -ENOMEM; |
| 6233 | } |
| 6234 | return 0; |
| 6235 | } |
| 6236 | |
| 6237 | static void hpsa_free_cmd_pool(struct ctlr_info *h) |
| 6238 | { |
| 6239 | kfree(h->cmd_pool_bits); |
| 6240 | if (h->cmd_pool) |
| 6241 | pci_free_consistent(h->pdev, |
| 6242 | h->nr_cmds * sizeof(struct CommandList), |
| 6243 | h->cmd_pool, h->cmd_pool_dhandle); |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 6244 | if (h->ioaccel2_cmd_pool) |
| 6245 | pci_free_consistent(h->pdev, |
| 6246 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 6247 | h->ioaccel2_cmd_pool, h->ioaccel2_cmd_pool_dhandle); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6248 | if (h->errinfo_pool) |
| 6249 | pci_free_consistent(h->pdev, |
| 6250 | h->nr_cmds * sizeof(struct ErrorInfo), |
| 6251 | h->errinfo_pool, |
| 6252 | h->errinfo_pool_dhandle); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6253 | if (h->ioaccel_cmd_pool) |
| 6254 | pci_free_consistent(h->pdev, |
| 6255 | h->nr_cmds * sizeof(struct io_accel1_cmd), |
| 6256 | h->ioaccel_cmd_pool, h->ioaccel_cmd_pool_dhandle); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6257 | } |
| 6258 | |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6259 | static int hpsa_request_irq(struct ctlr_info *h, |
| 6260 | irqreturn_t (*msixhandler)(int, void *), |
| 6261 | irqreturn_t (*intxhandler)(int, void *)) |
| 6262 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6263 | int rc, i; |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6264 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6265 | /* |
| 6266 | * initialize h->q[x] = x so that interrupt handlers know which |
| 6267 | * queue to process. |
| 6268 | */ |
| 6269 | for (i = 0; i < MAX_REPLY_QUEUES; i++) |
| 6270 | h->q[i] = (u8) i; |
| 6271 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 6272 | if (h->intr_mode == PERF_MODE_INT && h->msix_vector > 0) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6273 | /* If performant mode and MSI-X, use multiple reply queues */ |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 6274 | for (i = 0; i < h->msix_vector; i++) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6275 | rc = request_irq(h->intr[i], msixhandler, |
| 6276 | 0, h->devname, |
| 6277 | &h->q[i]); |
| 6278 | } else { |
| 6279 | /* Use single reply pool */ |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 6280 | if (h->msix_vector > 0 || h->msi_vector) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6281 | rc = request_irq(h->intr[h->intr_mode], |
| 6282 | msixhandler, 0, h->devname, |
| 6283 | &h->q[h->intr_mode]); |
| 6284 | } else { |
| 6285 | rc = request_irq(h->intr[h->intr_mode], |
| 6286 | intxhandler, IRQF_SHARED, h->devname, |
| 6287 | &h->q[h->intr_mode]); |
| 6288 | } |
| 6289 | } |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6290 | if (rc) { |
| 6291 | dev_err(&h->pdev->dev, "unable to get irq %d for %s\n", |
| 6292 | h->intr[h->intr_mode], h->devname); |
| 6293 | return -ENODEV; |
| 6294 | } |
| 6295 | return 0; |
| 6296 | } |
| 6297 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6298 | static int hpsa_kdump_soft_reset(struct ctlr_info *h) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6299 | { |
| 6300 | if (hpsa_send_host_reset(h, RAID_CTLR_LUNID, |
| 6301 | HPSA_RESET_TYPE_CONTROLLER)) { |
| 6302 | dev_warn(&h->pdev->dev, "Resetting array controller failed.\n"); |
| 6303 | return -EIO; |
| 6304 | } |
| 6305 | |
| 6306 | dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n"); |
| 6307 | if (hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY)) { |
| 6308 | dev_warn(&h->pdev->dev, "Soft reset had no effect.\n"); |
| 6309 | return -1; |
| 6310 | } |
| 6311 | |
| 6312 | dev_info(&h->pdev->dev, "Board reset, awaiting READY status.\n"); |
| 6313 | if (hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY)) { |
| 6314 | dev_warn(&h->pdev->dev, "Board failed to become ready " |
| 6315 | "after soft reset.\n"); |
| 6316 | return -1; |
| 6317 | } |
| 6318 | |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6322 | static void free_irqs(struct ctlr_info *h) |
| 6323 | { |
| 6324 | int i; |
| 6325 | |
| 6326 | if (!h->msix_vector || h->intr_mode != PERF_MODE_INT) { |
| 6327 | /* Single reply queue, only one irq to free */ |
| 6328 | i = h->intr_mode; |
| 6329 | free_irq(h->intr[i], &h->q[i]); |
| 6330 | return; |
| 6331 | } |
| 6332 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 6333 | for (i = 0; i < h->msix_vector; i++) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6334 | free_irq(h->intr[i], &h->q[i]); |
| 6335 | } |
| 6336 | |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6337 | static void hpsa_free_irqs_and_disable_msix(struct ctlr_info *h) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6338 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6339 | free_irqs(h); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6340 | #ifdef CONFIG_PCI_MSI |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6341 | if (h->msix_vector) { |
| 6342 | if (h->pdev->msix_enabled) |
| 6343 | pci_disable_msix(h->pdev); |
| 6344 | } else if (h->msi_vector) { |
| 6345 | if (h->pdev->msi_enabled) |
| 6346 | pci_disable_msi(h->pdev); |
| 6347 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6348 | #endif /* CONFIG_PCI_MSI */ |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h) |
| 6352 | { |
| 6353 | hpsa_free_irqs_and_disable_msix(h); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6354 | hpsa_free_sg_chain_blocks(h); |
| 6355 | hpsa_free_cmd_pool(h); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6356 | kfree(h->ioaccel1_blockFetchTable); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6357 | kfree(h->blockFetchTable); |
| 6358 | pci_free_consistent(h->pdev, h->reply_pool_size, |
| 6359 | h->reply_pool, h->reply_pool_dhandle); |
| 6360 | if (h->vaddr) |
| 6361 | iounmap(h->vaddr); |
| 6362 | if (h->transtable) |
| 6363 | iounmap(h->transtable); |
| 6364 | if (h->cfgtable) |
| 6365 | iounmap(h->cfgtable); |
| 6366 | pci_release_regions(h->pdev); |
| 6367 | kfree(h); |
| 6368 | } |
| 6369 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6370 | /* Called when controller lockup detected. */ |
| 6371 | static void fail_all_cmds_on_list(struct ctlr_info *h, struct list_head *list) |
| 6372 | { |
| 6373 | struct CommandList *c = NULL; |
| 6374 | |
| 6375 | assert_spin_locked(&h->lock); |
| 6376 | /* Mark all outstanding commands as failed and complete them. */ |
| 6377 | while (!list_empty(list)) { |
| 6378 | c = list_entry(list->next, struct CommandList, list); |
| 6379 | c->err_info->CommandStatus = CMD_HARDWARE_ERR; |
Stephen M. Cameron | 5a3d16f | 2012-05-01 11:42:46 -0500 | [diff] [blame] | 6380 | finish_cmd(c); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6381 | } |
| 6382 | } |
| 6383 | |
| 6384 | static void controller_lockup_detected(struct ctlr_info *h) |
| 6385 | { |
| 6386 | unsigned long flags; |
| 6387 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6388 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 6389 | spin_lock_irqsave(&h->lock, flags); |
| 6390 | h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); |
| 6391 | spin_unlock_irqrestore(&h->lock, flags); |
| 6392 | dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n", |
| 6393 | h->lockup_detected); |
| 6394 | pci_disable_device(h->pdev); |
| 6395 | spin_lock_irqsave(&h->lock, flags); |
| 6396 | fail_all_cmds_on_list(h, &h->cmpQ); |
| 6397 | fail_all_cmds_on_list(h, &h->reqQ); |
| 6398 | spin_unlock_irqrestore(&h->lock, flags); |
| 6399 | } |
| 6400 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6401 | static void detect_controller_lockup(struct ctlr_info *h) |
| 6402 | { |
| 6403 | u64 now; |
| 6404 | u32 heartbeat; |
| 6405 | unsigned long flags; |
| 6406 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6407 | now = get_jiffies_64(); |
| 6408 | /* If we've received an interrupt recently, we're ok. */ |
| 6409 | if (time_after64(h->last_intr_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 6410 | (h->heartbeat_sample_interval), now)) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6411 | return; |
| 6412 | |
| 6413 | /* |
| 6414 | * If we've already checked the heartbeat recently, we're ok. |
| 6415 | * This could happen if someone sends us a signal. We |
| 6416 | * otherwise don't care about signals in this thread. |
| 6417 | */ |
| 6418 | if (time_after64(h->last_heartbeat_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 6419 | (h->heartbeat_sample_interval), now)) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6420 | return; |
| 6421 | |
| 6422 | /* If heartbeat has not changed since we last looked, we're not ok. */ |
| 6423 | spin_lock_irqsave(&h->lock, flags); |
| 6424 | heartbeat = readl(&h->cfgtable->HeartBeat); |
| 6425 | spin_unlock_irqrestore(&h->lock, flags); |
| 6426 | if (h->last_heartbeat == heartbeat) { |
| 6427 | controller_lockup_detected(h); |
| 6428 | return; |
| 6429 | } |
| 6430 | |
| 6431 | /* We're ok. */ |
| 6432 | h->last_heartbeat = heartbeat; |
| 6433 | h->last_heartbeat_timestamp = now; |
| 6434 | } |
| 6435 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6436 | static int hpsa_kickoff_rescan(struct ctlr_info *h) |
| 6437 | { |
| 6438 | int i; |
| 6439 | char *event_type; |
| 6440 | |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 6441 | /* Clear the driver-requested rescan flag */ |
| 6442 | h->drv_req_rescan = 0; |
| 6443 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6444 | /* Ask the controller to clear the events we're handling. */ |
Stephen M. Cameron | 1f7cee8 | 2014-02-18 13:56:09 -0600 | [diff] [blame] | 6445 | if ((h->transMethod & (CFGTBL_Trans_io_accel1 |
| 6446 | | CFGTBL_Trans_io_accel2)) && |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6447 | (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE || |
| 6448 | h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE)) { |
| 6449 | |
| 6450 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE) |
| 6451 | event_type = "state change"; |
| 6452 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE) |
| 6453 | event_type = "configuration change"; |
| 6454 | /* Stop sending new RAID offload reqs via the IO accelerator */ |
| 6455 | scsi_block_requests(h->scsi_host); |
| 6456 | for (i = 0; i < h->ndevices; i++) |
| 6457 | h->dev[i]->offload_enabled = 0; |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 6458 | hpsa_drain_accel_commands(h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6459 | /* Set 'accelerator path config change' bit */ |
| 6460 | dev_warn(&h->pdev->dev, |
| 6461 | "Acknowledging event: 0x%08x (HP SSD Smart Path %s)\n", |
| 6462 | h->events, event_type); |
| 6463 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 6464 | /* Set the "clear event notify field update" bit 6 */ |
| 6465 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 6466 | /* Wait until ctlr clears 'clear event notify field', bit 6 */ |
| 6467 | hpsa_wait_for_clear_event_notify_ack(h); |
| 6468 | scsi_unblock_requests(h->scsi_host); |
| 6469 | } else { |
| 6470 | /* Acknowledge controller notification events. */ |
| 6471 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 6472 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 6473 | hpsa_wait_for_clear_event_notify_ack(h); |
| 6474 | #if 0 |
| 6475 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
| 6476 | hpsa_wait_for_mode_change_ack(h); |
| 6477 | #endif |
| 6478 | } |
| 6479 | |
| 6480 | /* Something in the device list may have changed to trigger |
| 6481 | * the event, so do a rescan. |
| 6482 | */ |
| 6483 | hpsa_scan_start(h->scsi_host); |
| 6484 | /* release reference taken on scsi host in check_controller_events */ |
| 6485 | scsi_host_put(h->scsi_host); |
| 6486 | return 0; |
| 6487 | } |
| 6488 | |
| 6489 | /* Check a register on the controller to see if there are configuration |
| 6490 | * changes (added/changed/removed logical drives, etc.) which mean that |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 6491 | * we should rescan the controller for devices. |
| 6492 | * Also check flag for driver-initiated rescan. |
| 6493 | * If either flag or controller event indicate rescan, add the controller |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6494 | * to the list of controllers needing to be rescanned, and gets a |
| 6495 | * reference to the associated scsi_host. |
| 6496 | */ |
| 6497 | static void hpsa_ctlr_needs_rescan(struct ctlr_info *h) |
| 6498 | { |
| 6499 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
| 6500 | return; |
| 6501 | |
| 6502 | h->events = readl(&(h->cfgtable->event_notify)); |
Stephen M. Cameron | faff6ee | 2014-02-18 13:57:42 -0600 | [diff] [blame] | 6503 | if (!(h->events & RESCAN_REQUIRED_EVENT_BITS) && !h->drv_req_rescan) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6504 | return; |
| 6505 | |
| 6506 | /* |
| 6507 | * Take a reference on scsi host for the duration of the scan |
| 6508 | * Release in hpsa_kickoff_rescan(). No lock needed for scan_list |
| 6509 | * as only a single thread accesses this list. |
| 6510 | */ |
| 6511 | scsi_host_get(h->scsi_host); |
| 6512 | hpsa_kickoff_rescan(h); |
| 6513 | } |
| 6514 | |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6515 | static void hpsa_monitor_ctlr_worker(struct work_struct *work) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6516 | { |
| 6517 | unsigned long flags; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6518 | struct ctlr_info *h = container_of(to_delayed_work(work), |
| 6519 | struct ctlr_info, monitor_ctlr_work); |
| 6520 | detect_controller_lockup(h); |
| 6521 | if (h->lockup_detected) |
| 6522 | return; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6523 | hpsa_ctlr_needs_rescan(h); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6524 | spin_lock_irqsave(&h->lock, flags); |
| 6525 | if (h->remove_in_progress) { |
| 6526 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6527 | return; |
| 6528 | } |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6529 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 6530 | h->heartbeat_sample_interval); |
| 6531 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6532 | } |
| 6533 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6534 | static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6535 | { |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6536 | int dac, rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6537 | struct ctlr_info *h; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6538 | int try_soft_reset = 0; |
| 6539 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6540 | |
| 6541 | if (number_of_controllers == 0) |
| 6542 | printk(KERN_INFO DRIVER_NAME "\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6543 | |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6544 | rc = hpsa_init_reset_devices(pdev); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6545 | if (rc) { |
| 6546 | if (rc != -ENOTSUPP) |
| 6547 | return rc; |
| 6548 | /* If the reset fails in a particular way (it has no way to do |
| 6549 | * a proper hard reset, so returns -ENOTSUPP) we can try to do |
| 6550 | * a soft reset once we get the controller configured up to the |
| 6551 | * point that it can accept a command. |
| 6552 | */ |
| 6553 | try_soft_reset = 1; |
| 6554 | rc = 0; |
| 6555 | } |
| 6556 | |
| 6557 | reinit_after_soft_reset: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6558 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6559 | /* Command structures must be aligned on a 32-byte boundary because |
| 6560 | * the 5 lower bits of the address are used by the hardware. and by |
| 6561 | * the driver. See comments in hpsa.h for more info. |
| 6562 | */ |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6563 | #define COMMANDLIST_ALIGNMENT 128 |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6564 | BUILD_BUG_ON(sizeof(struct CommandList) % COMMANDLIST_ALIGNMENT); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6565 | h = kzalloc(sizeof(*h), GFP_KERNEL); |
| 6566 | if (!h) |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6567 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6568 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6569 | h->pdev = pdev; |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 6570 | h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT; |
Stephen M. Cameron | 9e0fc76 | 2011-02-15 15:32:48 -0600 | [diff] [blame] | 6571 | INIT_LIST_HEAD(&h->cmpQ); |
| 6572 | INIT_LIST_HEAD(&h->reqQ); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6573 | spin_lock_init(&h->lock); |
| 6574 | spin_lock_init(&h->scan_lock); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6575 | spin_lock_init(&h->passthru_count_lock); |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6576 | rc = hpsa_pci_init(h); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6577 | if (rc != 0) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6578 | goto clean1; |
| 6579 | |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 6580 | sprintf(h->devname, HPSA "%d", number_of_controllers); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6581 | h->ctlr = number_of_controllers; |
| 6582 | number_of_controllers++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6583 | |
| 6584 | /* configure PCI DMA stuff */ |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6585 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 6586 | if (rc == 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6587 | dac = 1; |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6588 | } else { |
| 6589 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 6590 | if (rc == 0) { |
| 6591 | dac = 0; |
| 6592 | } else { |
| 6593 | dev_err(&pdev->dev, "no suitable DMA available\n"); |
| 6594 | goto clean1; |
| 6595 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | /* make sure the board interrupts are off */ |
| 6599 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6600 | |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6601 | if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6602 | goto clean2; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6603 | dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n", |
| 6604 | h->devname, pdev->device, |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 6605 | h->intr[h->intr_mode], dac ? "" : " not"); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6606 | if (hpsa_allocate_cmd_pool(h)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6607 | goto clean4; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 6608 | if (hpsa_allocate_sg_chain_blocks(h)) |
| 6609 | goto clean4; |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 6610 | init_waitqueue_head(&h->scan_wait_queue); |
| 6611 | h->scan_finished = 1; /* no scan currently in progress */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6612 | |
| 6613 | pci_set_drvdata(pdev, h); |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 6614 | h->ndevices = 0; |
| 6615 | h->scsi_host = NULL; |
| 6616 | spin_lock_init(&h->devlock); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6617 | hpsa_put_ctlr_into_performant_mode(h); |
| 6618 | |
| 6619 | /* At this point, the controller is ready to take commands. |
| 6620 | * Now, if reset_devices and the hard reset didn't work, try |
| 6621 | * the soft reset and see if that works. |
| 6622 | */ |
| 6623 | if (try_soft_reset) { |
| 6624 | |
| 6625 | /* This is kind of gross. We may or may not get a completion |
| 6626 | * from the soft reset command, and if we do, then the value |
| 6627 | * from the fifo may or may not be valid. So, we wait 10 secs |
| 6628 | * after the reset throwing away any completions we get during |
| 6629 | * that time. Unregister the interrupt handler and register |
| 6630 | * fake ones to scoop up any residual completions. |
| 6631 | */ |
| 6632 | spin_lock_irqsave(&h->lock, flags); |
| 6633 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 6634 | spin_unlock_irqrestore(&h->lock, flags); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6635 | free_irqs(h); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6636 | rc = hpsa_request_irq(h, hpsa_msix_discard_completions, |
| 6637 | hpsa_intx_discard_completions); |
| 6638 | if (rc) { |
| 6639 | dev_warn(&h->pdev->dev, "Failed to request_irq after " |
| 6640 | "soft reset.\n"); |
| 6641 | goto clean4; |
| 6642 | } |
| 6643 | |
| 6644 | rc = hpsa_kdump_soft_reset(h); |
| 6645 | if (rc) |
| 6646 | /* Neither hard nor soft reset worked, we're hosed. */ |
| 6647 | goto clean4; |
| 6648 | |
| 6649 | dev_info(&h->pdev->dev, "Board READY.\n"); |
| 6650 | dev_info(&h->pdev->dev, |
| 6651 | "Waiting for stale completions to drain.\n"); |
| 6652 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 6653 | msleep(10000); |
| 6654 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 6655 | |
| 6656 | rc = controller_reset_failed(h->cfgtable); |
| 6657 | if (rc) |
| 6658 | dev_info(&h->pdev->dev, |
| 6659 | "Soft reset appears to have failed.\n"); |
| 6660 | |
| 6661 | /* since the controller's reset, we have to go back and re-init |
| 6662 | * everything. Easiest to just forget what we've done and do it |
| 6663 | * all over again. |
| 6664 | */ |
| 6665 | hpsa_undo_allocations_after_kdump_soft_reset(h); |
| 6666 | try_soft_reset = 0; |
| 6667 | if (rc) |
| 6668 | /* don't go to clean4, we already unallocated */ |
| 6669 | return -ENODEV; |
| 6670 | |
| 6671 | goto reinit_after_soft_reset; |
| 6672 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6673 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 6674 | /* Enable Accelerated IO path at driver layer */ |
| 6675 | h->acciopath_status = 1; |
| 6676 | |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 6677 | h->drv_req_rescan = 0; |
| 6678 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6679 | /* Turn the interrupts on so we can service requests */ |
| 6680 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 6681 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 6682 | hpsa_hba_inquiry(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6683 | hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */ |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6684 | |
| 6685 | /* Monitor the controller for firmware lockups */ |
| 6686 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 6687 | INIT_DELAYED_WORK(&h->monitor_ctlr_work, hpsa_monitor_ctlr_worker); |
| 6688 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 6689 | h->heartbeat_sample_interval); |
Stephen M. Cameron | 88bf6d6 | 2013-11-01 11:02:25 -0500 | [diff] [blame] | 6690 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6691 | |
| 6692 | clean4: |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 6693 | hpsa_free_sg_chain_blocks(h); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6694 | hpsa_free_cmd_pool(h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6695 | free_irqs(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6696 | clean2: |
| 6697 | clean1: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6698 | kfree(h); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6699 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | static void hpsa_flush_cache(struct ctlr_info *h) |
| 6703 | { |
| 6704 | char *flush_buf; |
| 6705 | struct CommandList *c; |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 6706 | unsigned long flags; |
| 6707 | |
| 6708 | /* Don't bother trying to flush the cache if locked up */ |
| 6709 | spin_lock_irqsave(&h->lock, flags); |
| 6710 | if (unlikely(h->lockup_detected)) { |
| 6711 | spin_unlock_irqrestore(&h->lock, flags); |
| 6712 | return; |
| 6713 | } |
| 6714 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6715 | |
| 6716 | flush_buf = kzalloc(4, GFP_KERNEL); |
| 6717 | if (!flush_buf) |
| 6718 | return; |
| 6719 | |
| 6720 | c = cmd_special_alloc(h); |
| 6721 | if (!c) { |
| 6722 | dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); |
| 6723 | goto out_of_memory; |
| 6724 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6725 | if (fill_cmd(c, HPSA_CACHE_FLUSH, h, flush_buf, 4, 0, |
| 6726 | RAID_CTLR_LUNID, TYPE_CMD)) { |
| 6727 | goto out; |
| 6728 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6729 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_TODEVICE); |
| 6730 | if (c->err_info->CommandStatus != 0) |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6731 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6732 | dev_warn(&h->pdev->dev, |
| 6733 | "error flushing cache on controller\n"); |
| 6734 | cmd_special_free(h, c); |
| 6735 | out_of_memory: |
| 6736 | kfree(flush_buf); |
| 6737 | } |
| 6738 | |
| 6739 | static void hpsa_shutdown(struct pci_dev *pdev) |
| 6740 | { |
| 6741 | struct ctlr_info *h; |
| 6742 | |
| 6743 | h = pci_get_drvdata(pdev); |
| 6744 | /* Turn board interrupts off and send the flush cache command |
| 6745 | * sendcmd will turn off interrupt, and send the flush... |
| 6746 | * To write all data in the battery backed cache to disks |
| 6747 | */ |
| 6748 | hpsa_flush_cache(h); |
| 6749 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6750 | hpsa_free_irqs_and_disable_msix(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6751 | } |
| 6752 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6753 | static void hpsa_free_device_info(struct ctlr_info *h) |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 6754 | { |
| 6755 | int i; |
| 6756 | |
| 6757 | for (i = 0; i < h->ndevices; i++) |
| 6758 | kfree(h->dev[i]); |
| 6759 | } |
| 6760 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6761 | static void hpsa_remove_one(struct pci_dev *pdev) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6762 | { |
| 6763 | struct ctlr_info *h; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6764 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6765 | |
| 6766 | if (pci_get_drvdata(pdev) == NULL) { |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6767 | dev_err(&pdev->dev, "unable to remove device\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6768 | return; |
| 6769 | } |
| 6770 | h = pci_get_drvdata(pdev); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6771 | |
| 6772 | /* Get rid of any controller monitoring work items */ |
| 6773 | spin_lock_irqsave(&h->lock, flags); |
| 6774 | h->remove_in_progress = 1; |
| 6775 | cancel_delayed_work(&h->monitor_ctlr_work); |
| 6776 | spin_unlock_irqrestore(&h->lock, flags); |
| 6777 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6778 | hpsa_unregister_scsi(h); /* unhook from SCSI subsystem */ |
| 6779 | hpsa_shutdown(pdev); |
| 6780 | iounmap(h->vaddr); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 6781 | iounmap(h->transtable); |
| 6782 | iounmap(h->cfgtable); |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 6783 | hpsa_free_device_info(h); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 6784 | hpsa_free_sg_chain_blocks(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6785 | pci_free_consistent(h->pdev, |
| 6786 | h->nr_cmds * sizeof(struct CommandList), |
| 6787 | h->cmd_pool, h->cmd_pool_dhandle); |
| 6788 | pci_free_consistent(h->pdev, |
| 6789 | h->nr_cmds * sizeof(struct ErrorInfo), |
| 6790 | h->errinfo_pool, h->errinfo_pool_dhandle); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6791 | pci_free_consistent(h->pdev, h->reply_pool_size, |
| 6792 | h->reply_pool, h->reply_pool_dhandle); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6793 | kfree(h->cmd_pool_bits); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6794 | kfree(h->blockFetchTable); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6795 | kfree(h->ioaccel1_blockFetchTable); |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 6796 | kfree(h->ioaccel2_blockFetchTable); |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 6797 | kfree(h->hba_inquiry_data); |
Stephen M. Cameron | f0bd0b68 | 2012-05-01 11:42:09 -0500 | [diff] [blame] | 6798 | pci_disable_device(pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6799 | pci_release_regions(pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6800 | kfree(h); |
| 6801 | } |
| 6802 | |
| 6803 | static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev, |
| 6804 | __attribute__((unused)) pm_message_t state) |
| 6805 | { |
| 6806 | return -ENOSYS; |
| 6807 | } |
| 6808 | |
| 6809 | static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev) |
| 6810 | { |
| 6811 | return -ENOSYS; |
| 6812 | } |
| 6813 | |
| 6814 | static struct pci_driver hpsa_pci_driver = { |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 6815 | .name = HPSA, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6816 | .probe = hpsa_init_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6817 | .remove = hpsa_remove_one, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6818 | .id_table = hpsa_pci_device_id, /* id_table */ |
| 6819 | .shutdown = hpsa_shutdown, |
| 6820 | .suspend = hpsa_suspend, |
| 6821 | .resume = hpsa_resume, |
| 6822 | }; |
| 6823 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6824 | /* Fill in bucket_map[], given nsgs (the max number of |
| 6825 | * scatter gather elements supported) and bucket[], |
| 6826 | * which is an array of 8 integers. The bucket[] array |
| 6827 | * contains 8 different DMA transfer sizes (in 16 |
| 6828 | * byte increments) which the controller uses to fetch |
| 6829 | * commands. This function fills in bucket_map[], which |
| 6830 | * maps a given number of scatter gather elements to one of |
| 6831 | * the 8 DMA transfer sizes. The point of it is to allow the |
| 6832 | * controller to only do as much DMA as needed to fetch the |
| 6833 | * command, with the DMA transfer size encoded in the lower |
| 6834 | * bits of the command address. |
| 6835 | */ |
| 6836 | static void calc_bucket_map(int bucket[], int num_buckets, |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6837 | int nsgs, int min_blocks, int *bucket_map) |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6838 | { |
| 6839 | int i, j, b, size; |
| 6840 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6841 | /* Note, bucket_map must have nsgs+1 entries. */ |
| 6842 | for (i = 0; i <= nsgs; i++) { |
| 6843 | /* Compute size of a command with i SG entries */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6844 | size = i + min_blocks; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6845 | b = num_buckets; /* Assume the biggest bucket */ |
| 6846 | /* Find the bucket that is just big enough */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6847 | for (j = 0; j < num_buckets; j++) { |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6848 | if (bucket[j] >= size) { |
| 6849 | b = j; |
| 6850 | break; |
| 6851 | } |
| 6852 | } |
| 6853 | /* for a command with i SG entries, use bucket b. */ |
| 6854 | bucket_map[i] = b; |
| 6855 | } |
| 6856 | } |
| 6857 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6858 | static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support) |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6859 | { |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 6860 | int i; |
| 6861 | unsigned long register_value; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6862 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 6863 | (trans_support & CFGTBL_Trans_use_short_tags) | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6864 | CFGTBL_Trans_enable_directed_msix | |
| 6865 | (trans_support & (CFGTBL_Trans_io_accel1 | |
| 6866 | CFGTBL_Trans_io_accel2)); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6867 | struct access_method access = SA5_performant_access; |
Stephen M. Cameron | def342b | 2010-05-27 15:14:39 -0500 | [diff] [blame] | 6868 | |
| 6869 | /* This is a bit complicated. There are 8 registers on |
| 6870 | * the controller which we write to to tell it 8 different |
| 6871 | * sizes of commands which there may be. It's a way of |
| 6872 | * reducing the DMA done to fetch each command. Encoded into |
| 6873 | * each command's tag are 3 bits which communicate to the controller |
| 6874 | * which of the eight sizes that command fits within. The size of |
| 6875 | * each command depends on how many scatter gather entries there are. |
| 6876 | * Each SG entry requires 16 bytes. The eight registers are programmed |
| 6877 | * with the number of 16-byte blocks a command of that size requires. |
| 6878 | * The smallest command possible requires 5 such 16 byte blocks. |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6879 | * the largest command possible requires SG_ENTRIES_IN_CMD + 4 16-byte |
Stephen M. Cameron | def342b | 2010-05-27 15:14:39 -0500 | [diff] [blame] | 6880 | * blocks. Note, this only extends to the SG entries contained |
| 6881 | * within the command block, and does not extend to chained blocks |
| 6882 | * of SG elements. bft[] contains the eight values we write to |
| 6883 | * the registers. They are not evenly distributed, but have more |
| 6884 | * sizes for small commands, and fewer sizes for larger commands. |
| 6885 | */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6886 | int bft[8] = {5, 6, 8, 10, 12, 20, 28, SG_ENTRIES_IN_CMD + 4}; |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6887 | #define MIN_IOACCEL2_BFT_ENTRY 5 |
| 6888 | #define HPSA_IOACCEL2_HEADER_SZ 4 |
| 6889 | int bft2[16] = {MIN_IOACCEL2_BFT_ENTRY, 6, 7, 8, 9, 10, 11, 12, |
| 6890 | 13, 14, 15, 16, 17, 18, 19, |
| 6891 | HPSA_IOACCEL2_HEADER_SZ + IOACCEL2_MAXSGENTRIES}; |
| 6892 | BUILD_BUG_ON(ARRAY_SIZE(bft2) != 16); |
| 6893 | BUILD_BUG_ON(ARRAY_SIZE(bft) != 8); |
| 6894 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) > |
| 6895 | 16 * MIN_IOACCEL2_BFT_ENTRY); |
| 6896 | BUILD_BUG_ON(sizeof(struct ioaccel2_sg_element) != 16); |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6897 | BUILD_BUG_ON(28 > SG_ENTRIES_IN_CMD + 4); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6898 | /* 5 = 1 s/g entry or 4k |
| 6899 | * 6 = 2 s/g entry or 8k |
| 6900 | * 8 = 4 s/g entry or 16k |
| 6901 | * 10 = 6 s/g entry or 24k |
| 6902 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6903 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6904 | /* Controller spec: zero out this buffer. */ |
| 6905 | memset(h->reply_pool, 0, h->reply_pool_size); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6906 | |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6907 | bft[7] = SG_ENTRIES_IN_CMD + 4; |
| 6908 | calc_bucket_map(bft, ARRAY_SIZE(bft), |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6909 | SG_ENTRIES_IN_CMD, 4, h->blockFetchTable); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6910 | for (i = 0; i < 8; i++) |
| 6911 | writel(bft[i], &h->transtable->BlockFetch[i]); |
| 6912 | |
| 6913 | /* size of controller ring buffer */ |
| 6914 | writel(h->max_commands, &h->transtable->RepQSize); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6915 | writel(h->nreply_queues, &h->transtable->RepQCount); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6916 | writel(0, &h->transtable->RepQCtrAddrLow32); |
| 6917 | writel(0, &h->transtable->RepQCtrAddrHigh32); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6918 | |
| 6919 | for (i = 0; i < h->nreply_queues; i++) { |
| 6920 | writel(0, &h->transtable->RepQAddr[i].upper); |
| 6921 | writel(h->reply_pool_dhandle + |
| 6922 | (h->max_commands * sizeof(u64) * i), |
| 6923 | &h->transtable->RepQAddr[i].lower); |
| 6924 | } |
| 6925 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6926 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6927 | writel(transMethod, &(h->cfgtable->HostWrite.TransportRequest)); |
| 6928 | /* |
| 6929 | * enable outbound interrupt coalescing in accelerator mode; |
| 6930 | */ |
| 6931 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 6932 | access = SA5_ioaccel_mode1_access; |
| 6933 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 6934 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 6935 | } else { |
| 6936 | if (trans_support & CFGTBL_Trans_io_accel2) { |
| 6937 | access = SA5_ioaccel_mode2_access; |
| 6938 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 6939 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
| 6940 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6941 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6942 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6943 | hpsa_wait_for_mode_change_ack(h); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6944 | register_value = readl(&(h->cfgtable->TransportActive)); |
| 6945 | if (!(register_value & CFGTBL_Trans_Performant)) { |
| 6946 | dev_warn(&h->pdev->dev, "unable to get board into" |
| 6947 | " performant mode\n"); |
| 6948 | return; |
| 6949 | } |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 6950 | /* Change the access methods to the performant access methods */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6951 | h->access = access; |
| 6952 | h->transMethod = transMethod; |
| 6953 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6954 | if (!((trans_support & CFGTBL_Trans_io_accel1) || |
| 6955 | (trans_support & CFGTBL_Trans_io_accel2))) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6956 | return; |
| 6957 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6958 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 6959 | /* Set up I/O accelerator mode */ |
| 6960 | for (i = 0; i < h->nreply_queues; i++) { |
| 6961 | writel(i, h->vaddr + IOACCEL_MODE1_REPLY_QUEUE_INDEX); |
| 6962 | h->reply_queue[i].current_entry = |
| 6963 | readl(h->vaddr + IOACCEL_MODE1_PRODUCER_INDEX); |
| 6964 | } |
| 6965 | bft[7] = h->ioaccel_maxsg + 8; |
| 6966 | calc_bucket_map(bft, ARRAY_SIZE(bft), h->ioaccel_maxsg, 8, |
| 6967 | h->ioaccel1_blockFetchTable); |
| 6968 | |
| 6969 | /* initialize all reply queue entries to unused */ |
| 6970 | memset(h->reply_pool, (u8) IOACCEL_MODE1_REPLY_UNUSED, |
| 6971 | h->reply_pool_size); |
| 6972 | |
| 6973 | /* set all the constant fields in the accelerator command |
| 6974 | * frames once at init time to save CPU cycles later. |
| 6975 | */ |
| 6976 | for (i = 0; i < h->nr_cmds; i++) { |
| 6977 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[i]; |
| 6978 | |
| 6979 | cp->function = IOACCEL1_FUNCTION_SCSIIO; |
| 6980 | cp->err_info = (u32) (h->errinfo_pool_dhandle + |
| 6981 | (i * sizeof(struct ErrorInfo))); |
| 6982 | cp->err_info_len = sizeof(struct ErrorInfo); |
| 6983 | cp->sgl_offset = IOACCEL1_SGLOFFSET; |
| 6984 | cp->host_context_flags = IOACCEL1_HCFLAGS_CISS_FORMAT; |
| 6985 | cp->timeout_sec = 0; |
| 6986 | cp->ReplyQueue = 0; |
| 6987 | cp->Tag.lower = (i << DIRECT_LOOKUP_SHIFT) | |
| 6988 | DIRECT_LOOKUP_BIT; |
| 6989 | cp->Tag.upper = 0; |
| 6990 | cp->host_addr.lower = |
| 6991 | (u32) (h->ioaccel_cmd_pool_dhandle + |
| 6992 | (i * sizeof(struct io_accel1_cmd))); |
| 6993 | cp->host_addr.upper = 0; |
| 6994 | } |
| 6995 | } else if (trans_support & CFGTBL_Trans_io_accel2) { |
| 6996 | u64 cfg_offset, cfg_base_addr_index; |
| 6997 | u32 bft2_offset, cfg_base_addr; |
| 6998 | int rc; |
| 6999 | |
| 7000 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 7001 | &cfg_base_addr_index, &cfg_offset); |
| 7002 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) != 64); |
| 7003 | bft2[15] = h->ioaccel_maxsg + HPSA_IOACCEL2_HEADER_SZ; |
| 7004 | calc_bucket_map(bft2, ARRAY_SIZE(bft2), h->ioaccel_maxsg, |
| 7005 | 4, h->ioaccel2_blockFetchTable); |
| 7006 | bft2_offset = readl(&h->cfgtable->io_accel_request_size_offset); |
| 7007 | BUILD_BUG_ON(offsetof(struct CfgTable, |
| 7008 | io_accel_request_size_offset) != 0xb8); |
| 7009 | h->ioaccel2_bft2_regs = |
| 7010 | remap_pci_mem(pci_resource_start(h->pdev, |
| 7011 | cfg_base_addr_index) + |
| 7012 | cfg_offset + bft2_offset, |
| 7013 | ARRAY_SIZE(bft2) * |
| 7014 | sizeof(*h->ioaccel2_bft2_regs)); |
| 7015 | for (i = 0; i < ARRAY_SIZE(bft2); i++) |
| 7016 | writel(bft2[i], &h->ioaccel2_bft2_regs[i]); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7017 | } |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7018 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
| 7019 | hpsa_wait_for_mode_change_ack(h); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7020 | } |
| 7021 | |
| 7022 | static int hpsa_alloc_ioaccel_cmd_and_bft(struct ctlr_info *h) |
| 7023 | { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7024 | h->ioaccel_maxsg = |
| 7025 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 7026 | if (h->ioaccel_maxsg > IOACCEL1_MAXSGENTRIES) |
| 7027 | h->ioaccel_maxsg = IOACCEL1_MAXSGENTRIES; |
| 7028 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7029 | /* Command structures must be aligned on a 128-byte boundary |
| 7030 | * because the 7 lower bits of the address are used by the |
| 7031 | * hardware. |
| 7032 | */ |
| 7033 | #define IOACCEL1_COMMANDLIST_ALIGNMENT 128 |
| 7034 | BUILD_BUG_ON(sizeof(struct io_accel1_cmd) % |
| 7035 | IOACCEL1_COMMANDLIST_ALIGNMENT); |
| 7036 | h->ioaccel_cmd_pool = |
| 7037 | pci_alloc_consistent(h->pdev, |
| 7038 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 7039 | &(h->ioaccel_cmd_pool_dhandle)); |
| 7040 | |
| 7041 | h->ioaccel1_blockFetchTable = |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7042 | kmalloc(((h->ioaccel_maxsg + 1) * |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7043 | sizeof(u32)), GFP_KERNEL); |
| 7044 | |
| 7045 | if ((h->ioaccel_cmd_pool == NULL) || |
| 7046 | (h->ioaccel1_blockFetchTable == NULL)) |
| 7047 | goto clean_up; |
| 7048 | |
| 7049 | memset(h->ioaccel_cmd_pool, 0, |
| 7050 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool)); |
| 7051 | return 0; |
| 7052 | |
| 7053 | clean_up: |
| 7054 | if (h->ioaccel_cmd_pool) |
| 7055 | pci_free_consistent(h->pdev, |
| 7056 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 7057 | h->ioaccel_cmd_pool, h->ioaccel_cmd_pool_dhandle); |
| 7058 | kfree(h->ioaccel1_blockFetchTable); |
| 7059 | return 1; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7060 | } |
| 7061 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 7062 | static int ioaccel2_alloc_cmds_and_bft(struct ctlr_info *h) |
| 7063 | { |
| 7064 | /* Allocate ioaccel2 mode command blocks and block fetch table */ |
| 7065 | |
| 7066 | h->ioaccel_maxsg = |
| 7067 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 7068 | if (h->ioaccel_maxsg > IOACCEL2_MAXSGENTRIES) |
| 7069 | h->ioaccel_maxsg = IOACCEL2_MAXSGENTRIES; |
| 7070 | |
| 7071 | #define IOACCEL2_COMMANDLIST_ALIGNMENT 128 |
| 7072 | BUILD_BUG_ON(sizeof(struct io_accel2_cmd) % |
| 7073 | IOACCEL2_COMMANDLIST_ALIGNMENT); |
| 7074 | h->ioaccel2_cmd_pool = |
| 7075 | pci_alloc_consistent(h->pdev, |
| 7076 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 7077 | &(h->ioaccel2_cmd_pool_dhandle)); |
| 7078 | |
| 7079 | h->ioaccel2_blockFetchTable = |
| 7080 | kmalloc(((h->ioaccel_maxsg + 1) * |
| 7081 | sizeof(u32)), GFP_KERNEL); |
| 7082 | |
| 7083 | if ((h->ioaccel2_cmd_pool == NULL) || |
| 7084 | (h->ioaccel2_blockFetchTable == NULL)) |
| 7085 | goto clean_up; |
| 7086 | |
| 7087 | memset(h->ioaccel2_cmd_pool, 0, |
| 7088 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool)); |
| 7089 | return 0; |
| 7090 | |
| 7091 | clean_up: |
| 7092 | if (h->ioaccel2_cmd_pool) |
| 7093 | pci_free_consistent(h->pdev, |
| 7094 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 7095 | h->ioaccel2_cmd_pool, h->ioaccel2_cmd_pool_dhandle); |
| 7096 | kfree(h->ioaccel2_blockFetchTable); |
| 7097 | return 1; |
| 7098 | } |
| 7099 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7100 | static void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h) |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7101 | { |
| 7102 | u32 trans_support; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7103 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 7104 | CFGTBL_Trans_use_short_tags; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7105 | int i; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7106 | |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 7107 | if (hpsa_simple_mode) |
| 7108 | return; |
| 7109 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7110 | /* Check for I/O accelerator mode support */ |
| 7111 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 7112 | transMethod |= CFGTBL_Trans_io_accel1 | |
| 7113 | CFGTBL_Trans_enable_directed_msix; |
| 7114 | if (hpsa_alloc_ioaccel_cmd_and_bft(h)) |
| 7115 | goto clean_up; |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 7116 | } else { |
| 7117 | if (trans_support & CFGTBL_Trans_io_accel2) { |
| 7118 | transMethod |= CFGTBL_Trans_io_accel2 | |
| 7119 | CFGTBL_Trans_enable_directed_msix; |
| 7120 | if (ioaccel2_alloc_cmds_and_bft(h)) |
| 7121 | goto clean_up; |
| 7122 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7123 | } |
| 7124 | |
| 7125 | /* TODO, check that this next line h->nreply_queues is correct */ |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7126 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 7127 | if (!(trans_support & PERFORMANT_MODE)) |
| 7128 | return; |
| 7129 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7130 | h->nreply_queues = h->msix_vector > 0 ? h->msix_vector : 1; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 7131 | hpsa_get_max_perf_mode_cmds(h); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7132 | /* Performant mode ring buffer and supporting data structures */ |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7133 | h->reply_pool_size = h->max_commands * sizeof(u64) * h->nreply_queues; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7134 | h->reply_pool = pci_alloc_consistent(h->pdev, h->reply_pool_size, |
| 7135 | &(h->reply_pool_dhandle)); |
| 7136 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7137 | for (i = 0; i < h->nreply_queues; i++) { |
| 7138 | h->reply_queue[i].head = &h->reply_pool[h->max_commands * i]; |
| 7139 | h->reply_queue[i].size = h->max_commands; |
| 7140 | h->reply_queue[i].wraparound = 1; /* spec: init to 1 */ |
| 7141 | h->reply_queue[i].current_entry = 0; |
| 7142 | } |
| 7143 | |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7144 | /* Need a block fetch table for performant mode */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 7145 | h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) * |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7146 | sizeof(u32)), GFP_KERNEL); |
| 7147 | |
| 7148 | if ((h->reply_pool == NULL) |
| 7149 | || (h->blockFetchTable == NULL)) |
| 7150 | goto clean_up; |
| 7151 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7152 | hpsa_enter_performant_mode(h, trans_support); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7153 | return; |
| 7154 | |
| 7155 | clean_up: |
| 7156 | if (h->reply_pool) |
| 7157 | pci_free_consistent(h->pdev, h->reply_pool_size, |
| 7158 | h->reply_pool, h->reply_pool_dhandle); |
| 7159 | kfree(h->blockFetchTable); |
| 7160 | } |
| 7161 | |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7162 | static int is_accelerated_cmd(struct CommandList *c) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7163 | { |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7164 | return c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_IOACCEL2; |
| 7165 | } |
| 7166 | |
| 7167 | static void hpsa_drain_accel_commands(struct ctlr_info *h) |
| 7168 | { |
| 7169 | struct CommandList *c = NULL; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7170 | unsigned long flags; |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7171 | int accel_cmds_out; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7172 | |
| 7173 | do { /* wait for all outstanding commands to drain out */ |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7174 | accel_cmds_out = 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7175 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7176 | list_for_each_entry(c, &h->cmpQ, list) |
| 7177 | accel_cmds_out += is_accelerated_cmd(c); |
| 7178 | list_for_each_entry(c, &h->reqQ, list) |
| 7179 | accel_cmds_out += is_accelerated_cmd(c); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7180 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7181 | if (accel_cmds_out <= 0) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7182 | break; |
| 7183 | msleep(100); |
| 7184 | } while (1); |
| 7185 | } |
| 7186 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7187 | /* |
| 7188 | * This is it. Register the PCI driver information for the cards we control |
| 7189 | * the OS will call our registered routines when it finds one of our cards. |
| 7190 | */ |
| 7191 | static int __init hpsa_init(void) |
| 7192 | { |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 7193 | return pci_register_driver(&hpsa_pci_driver); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | static void __exit hpsa_cleanup(void) |
| 7197 | { |
| 7198 | pci_unregister_driver(&hpsa_pci_driver); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7199 | } |
| 7200 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7201 | static void __attribute__((unused)) verify_offsets(void) |
| 7202 | { |
| 7203 | #define VERIFY_OFFSET(member, offset) \ |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 7204 | BUILD_BUG_ON(offsetof(struct raid_map_data, member) != offset) |
| 7205 | |
| 7206 | VERIFY_OFFSET(structure_size, 0); |
| 7207 | VERIFY_OFFSET(volume_blk_size, 4); |
| 7208 | VERIFY_OFFSET(volume_blk_cnt, 8); |
| 7209 | VERIFY_OFFSET(phys_blk_shift, 16); |
| 7210 | VERIFY_OFFSET(parity_rotation_shift, 17); |
| 7211 | VERIFY_OFFSET(strip_size, 18); |
| 7212 | VERIFY_OFFSET(disk_starting_blk, 20); |
| 7213 | VERIFY_OFFSET(disk_blk_cnt, 28); |
| 7214 | VERIFY_OFFSET(data_disks_per_row, 36); |
| 7215 | VERIFY_OFFSET(metadata_disks_per_row, 38); |
| 7216 | VERIFY_OFFSET(row_cnt, 40); |
| 7217 | VERIFY_OFFSET(layout_map_count, 42); |
| 7218 | VERIFY_OFFSET(flags, 44); |
| 7219 | VERIFY_OFFSET(dekindex, 46); |
| 7220 | /* VERIFY_OFFSET(reserved, 48 */ |
| 7221 | VERIFY_OFFSET(data, 64); |
| 7222 | |
| 7223 | #undef VERIFY_OFFSET |
| 7224 | |
| 7225 | #define VERIFY_OFFSET(member, offset) \ |
Mike Miller | b66cc25 | 2014-02-18 13:56:04 -0600 | [diff] [blame] | 7226 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, member) != offset) |
| 7227 | |
| 7228 | VERIFY_OFFSET(IU_type, 0); |
| 7229 | VERIFY_OFFSET(direction, 1); |
| 7230 | VERIFY_OFFSET(reply_queue, 2); |
| 7231 | /* VERIFY_OFFSET(reserved1, 3); */ |
| 7232 | VERIFY_OFFSET(scsi_nexus, 4); |
| 7233 | VERIFY_OFFSET(Tag, 8); |
| 7234 | VERIFY_OFFSET(cdb, 16); |
| 7235 | VERIFY_OFFSET(cciss_lun, 32); |
| 7236 | VERIFY_OFFSET(data_len, 40); |
| 7237 | VERIFY_OFFSET(cmd_priority_task_attr, 44); |
| 7238 | VERIFY_OFFSET(sg_count, 45); |
| 7239 | /* VERIFY_OFFSET(reserved3 */ |
| 7240 | VERIFY_OFFSET(err_ptr, 48); |
| 7241 | VERIFY_OFFSET(err_len, 56); |
| 7242 | /* VERIFY_OFFSET(reserved4 */ |
| 7243 | VERIFY_OFFSET(sg, 64); |
| 7244 | |
| 7245 | #undef VERIFY_OFFSET |
| 7246 | |
| 7247 | #define VERIFY_OFFSET(member, offset) \ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7248 | BUILD_BUG_ON(offsetof(struct io_accel1_cmd, member) != offset) |
| 7249 | |
| 7250 | VERIFY_OFFSET(dev_handle, 0x00); |
| 7251 | VERIFY_OFFSET(reserved1, 0x02); |
| 7252 | VERIFY_OFFSET(function, 0x03); |
| 7253 | VERIFY_OFFSET(reserved2, 0x04); |
| 7254 | VERIFY_OFFSET(err_info, 0x0C); |
| 7255 | VERIFY_OFFSET(reserved3, 0x10); |
| 7256 | VERIFY_OFFSET(err_info_len, 0x12); |
| 7257 | VERIFY_OFFSET(reserved4, 0x13); |
| 7258 | VERIFY_OFFSET(sgl_offset, 0x14); |
| 7259 | VERIFY_OFFSET(reserved5, 0x15); |
| 7260 | VERIFY_OFFSET(transfer_len, 0x1C); |
| 7261 | VERIFY_OFFSET(reserved6, 0x20); |
| 7262 | VERIFY_OFFSET(io_flags, 0x24); |
| 7263 | VERIFY_OFFSET(reserved7, 0x26); |
| 7264 | VERIFY_OFFSET(LUN, 0x34); |
| 7265 | VERIFY_OFFSET(control, 0x3C); |
| 7266 | VERIFY_OFFSET(CDB, 0x40); |
| 7267 | VERIFY_OFFSET(reserved8, 0x50); |
| 7268 | VERIFY_OFFSET(host_context_flags, 0x60); |
| 7269 | VERIFY_OFFSET(timeout_sec, 0x62); |
| 7270 | VERIFY_OFFSET(ReplyQueue, 0x64); |
| 7271 | VERIFY_OFFSET(reserved9, 0x65); |
| 7272 | VERIFY_OFFSET(Tag, 0x68); |
| 7273 | VERIFY_OFFSET(host_addr, 0x70); |
| 7274 | VERIFY_OFFSET(CISS_LUN, 0x78); |
| 7275 | VERIFY_OFFSET(SG, 0x78 + 8); |
| 7276 | #undef VERIFY_OFFSET |
| 7277 | } |
| 7278 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7279 | module_init(hpsa_init); |
| 7280 | module_exit(hpsa_cleanup); |