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 | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 50 | #include <linux/jiffies.h> |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 51 | #include <linux/percpu-defs.h> |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 52 | #include <linux/percpu.h> |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 53 | #include <asm/unaligned.h> |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 54 | #include <asm/div64.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 55 | #include "hpsa_cmd.h" |
| 56 | #include "hpsa.h" |
| 57 | |
| 58 | /* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */ |
Stephen M. Cameron | 9a99330 | 2014-03-13 17:13:06 -0500 | [diff] [blame] | 59 | #define HPSA_DRIVER_VERSION "3.4.4-1" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 60 | #define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 61 | #define HPSA "hpsa" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 62 | |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 63 | /* How long to wait for CISS doorbell communication */ |
| 64 | #define CLEAR_EVENT_WAIT_INTERVAL 20 /* ms for each msleep() call */ |
| 65 | #define MODE_CHANGE_WAIT_INTERVAL 10 /* ms for each msleep() call */ |
| 66 | #define MAX_CLEAR_EVENT_WAIT 30000 /* times 20 ms = 600 s */ |
| 67 | #define MAX_MODE_CHANGE_WAIT 2000 /* times 10 ms = 20 s */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 68 | #define MAX_IOCTL_CONFIG_WAIT 1000 |
| 69 | |
| 70 | /*define how many times we will try a command because of bus resets */ |
| 71 | #define MAX_CMD_RETRIES 3 |
| 72 | |
| 73 | /* Embedded module documentation macros - see modules.h */ |
| 74 | MODULE_AUTHOR("Hewlett-Packard Company"); |
| 75 | MODULE_DESCRIPTION("Driver for HP Smart Array Controller version " \ |
| 76 | HPSA_DRIVER_VERSION); |
| 77 | MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers"); |
| 78 | MODULE_VERSION(HPSA_DRIVER_VERSION); |
| 79 | MODULE_LICENSE("GPL"); |
| 80 | |
| 81 | static int hpsa_allow_any; |
| 82 | module_param(hpsa_allow_any, int, S_IRUGO|S_IWUSR); |
| 83 | MODULE_PARM_DESC(hpsa_allow_any, |
| 84 | "Allow hpsa driver to access unknown HP Smart Array hardware"); |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 85 | static int hpsa_simple_mode; |
| 86 | module_param(hpsa_simple_mode, int, S_IRUGO|S_IWUSR); |
| 87 | MODULE_PARM_DESC(hpsa_simple_mode, |
| 88 | "Use 'simple mode' rather than 'performant mode'"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 89 | |
| 90 | /* define the PCI info for the cards we can control */ |
| 91 | static const struct pci_device_id hpsa_pci_device_id[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 92 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3241}, |
| 93 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3243}, |
| 94 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3245}, |
| 95 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3247}, |
| 96 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 97 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A}, |
| 98 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B}, |
Mike Miller | f8b01eb | 2010-02-04 08:42:45 -0600 | [diff] [blame] | 99 | {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] | 100 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3350}, |
| 101 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3351}, |
| 102 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3352}, |
| 103 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3353}, |
| 104 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3354}, |
| 105 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3355}, |
| 106 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3356}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 107 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1921}, |
| 108 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1922}, |
| 109 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1923}, |
| 110 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1924}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 111 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1926}, |
| 112 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1928}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 113 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1929}, |
| 114 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BD}, |
| 115 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BE}, |
| 116 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BF}, |
| 117 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C0}, |
| 118 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C1}, |
| 119 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C2}, |
| 120 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C3}, |
| 121 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C4}, |
| 122 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C5}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 123 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C6}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 124 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C7}, |
| 125 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C8}, |
| 126 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C9}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 127 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CA}, |
| 128 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CB}, |
| 129 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CC}, |
| 130 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CD}, |
| 131 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CE}, |
Stephen M. Cameron | 8e616a5 | 2014-02-18 13:58:02 -0600 | [diff] [blame] | 132 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0076}, |
| 133 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0087}, |
| 134 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x007D}, |
| 135 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0088}, |
| 136 | {PCI_VENDOR_ID_HP, 0x333f, 0x103c, 0x333f}, |
Mike Miller | 7c03b87 | 2010-12-01 11:16:07 -0600 | [diff] [blame] | 137 | {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] | 138 | PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 139 | {0,} |
| 140 | }; |
| 141 | |
| 142 | MODULE_DEVICE_TABLE(pci, hpsa_pci_device_id); |
| 143 | |
| 144 | /* board_id = Subsystem Device ID & Vendor ID |
| 145 | * product = Marketing Name for the board |
| 146 | * access = Address of the struct of function pointers |
| 147 | */ |
| 148 | static struct board_type products[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 149 | {0x3241103C, "Smart Array P212", &SA5_access}, |
| 150 | {0x3243103C, "Smart Array P410", &SA5_access}, |
| 151 | {0x3245103C, "Smart Array P410i", &SA5_access}, |
| 152 | {0x3247103C, "Smart Array P411", &SA5_access}, |
| 153 | {0x3249103C, "Smart Array P812", &SA5_access}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 154 | {0x324A103C, "Smart Array P712m", &SA5_access}, |
| 155 | {0x324B103C, "Smart Array P711m", &SA5_access}, |
Stephen M. Cameron | 7d2cce5 | 2014-11-14 17:26:38 -0600 | [diff] [blame] | 156 | {0x3233103C, "HP StorageWorks 1210m", &SA5_access}, /* alias of 333f */ |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 157 | {0x3350103C, "Smart Array P222", &SA5_access}, |
| 158 | {0x3351103C, "Smart Array P420", &SA5_access}, |
| 159 | {0x3352103C, "Smart Array P421", &SA5_access}, |
| 160 | {0x3353103C, "Smart Array P822", &SA5_access}, |
| 161 | {0x3354103C, "Smart Array P420i", &SA5_access}, |
| 162 | {0x3355103C, "Smart Array P220i", &SA5_access}, |
| 163 | {0x3356103C, "Smart Array P721m", &SA5_access}, |
Mike Miller | 1fd6c8e | 2013-09-04 15:08:29 -0500 | [diff] [blame] | 164 | {0x1921103C, "Smart Array P830i", &SA5_access}, |
| 165 | {0x1922103C, "Smart Array P430", &SA5_access}, |
| 166 | {0x1923103C, "Smart Array P431", &SA5_access}, |
| 167 | {0x1924103C, "Smart Array P830", &SA5_access}, |
| 168 | {0x1926103C, "Smart Array P731m", &SA5_access}, |
| 169 | {0x1928103C, "Smart Array P230i", &SA5_access}, |
| 170 | {0x1929103C, "Smart Array P530", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 171 | {0x21BD103C, "Smart Array P244br", &SA5_access}, |
| 172 | {0x21BE103C, "Smart Array P741m", &SA5_access}, |
| 173 | {0x21BF103C, "Smart HBA H240ar", &SA5_access}, |
| 174 | {0x21C0103C, "Smart Array P440ar", &SA5_access}, |
Don Brace | c8ae0ab | 2015-01-23 16:45:12 -0600 | [diff] [blame] | 175 | {0x21C1103C, "Smart Array P840ar", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 176 | {0x21C2103C, "Smart Array P440", &SA5_access}, |
| 177 | {0x21C3103C, "Smart Array P441", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 178 | {0x21C4103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 179 | {0x21C5103C, "Smart Array P841", &SA5_access}, |
| 180 | {0x21C6103C, "Smart HBA H244br", &SA5_access}, |
| 181 | {0x21C7103C, "Smart HBA H240", &SA5_access}, |
| 182 | {0x21C8103C, "Smart HBA H241", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 183 | {0x21C9103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 184 | {0x21CA103C, "Smart Array P246br", &SA5_access}, |
| 185 | {0x21CB103C, "Smart Array P840", &SA5_access}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 186 | {0x21CC103C, "Smart Array", &SA5_access}, |
| 187 | {0x21CD103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 188 | {0x21CE103C, "Smart HBA", &SA5_access}, |
Stephen M. Cameron | 8e616a5 | 2014-02-18 13:58:02 -0600 | [diff] [blame] | 189 | {0x00761590, "HP Storage P1224 Array Controller", &SA5_access}, |
| 190 | {0x00871590, "HP Storage P1224e Array Controller", &SA5_access}, |
| 191 | {0x007D1590, "HP Storage P1228 Array Controller", &SA5_access}, |
| 192 | {0x00881590, "HP Storage P1228e Array Controller", &SA5_access}, |
| 193 | {0x333f103c, "HP StorageWorks 1210m Array Controller", &SA5_access}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 194 | {0xFFFF103C, "Unknown Smart Array", &SA5_access}, |
| 195 | }; |
| 196 | |
| 197 | static int number_of_controllers; |
| 198 | |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 199 | static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); |
| 200 | static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 201 | static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 202 | |
| 203 | #ifdef CONFIG_COMPAT |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 204 | static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, |
| 205 | void __user *arg); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 206 | #endif |
| 207 | |
| 208 | static void cmd_free(struct ctlr_info *h, struct CommandList *c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 209 | static struct CommandList *cmd_alloc(struct ctlr_info *h); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 210 | 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] | 211 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 212 | int cmd_type); |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 213 | static void hpsa_free_cmd_pool(struct ctlr_info *h); |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 214 | #define VPD_PAGE (1 << 8) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 215 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 216 | 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] | 217 | static void hpsa_scan_start(struct Scsi_Host *); |
| 218 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 219 | unsigned long elapsed_time); |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 220 | static int hpsa_change_queue_depth(struct scsi_device *sdev, int qdepth); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 221 | |
| 222 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 223 | static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 224 | static int hpsa_slave_alloc(struct scsi_device *sdev); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 225 | static int hpsa_slave_configure(struct scsi_device *sdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 226 | static void hpsa_slave_destroy(struct scsi_device *sdev); |
| 227 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 228 | 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] | 229 | static int check_for_unit_attention(struct ctlr_info *h, |
| 230 | struct CommandList *c); |
| 231 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 232 | struct CommandList *c); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 233 | /* performant mode helper functions */ |
| 234 | static void calc_bucket_map(int *bucket, int num_buckets, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 235 | int nsgs, int min_blocks, u32 *bucket_map); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 236 | static void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 237 | static inline u32 next_command(struct ctlr_info *h, u8 q); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 238 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 239 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 240 | u64 *cfg_offset); |
| 241 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 242 | unsigned long *memory_bar); |
| 243 | static int hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id); |
| 244 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 245 | int wait_for_ready); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 246 | static inline void finish_cmd(struct CommandList *c); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 247 | static int hpsa_wait_for_mode_change_ack(struct ctlr_info *h); |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 248 | #define BOARD_NOT_READY 0 |
| 249 | #define BOARD_READY 1 |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 250 | static void hpsa_drain_accel_commands(struct ctlr_info *h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 251 | static void hpsa_flush_cache(struct ctlr_info *h); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 252 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 253 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 254 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 255 | static void hpsa_command_resubmit_worker(struct work_struct *work); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 256 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 257 | static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev) |
| 258 | { |
| 259 | unsigned long *priv = shost_priv(sdev->host); |
| 260 | return (struct ctlr_info *) *priv; |
| 261 | } |
| 262 | |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 263 | static inline struct ctlr_info *shost_to_hba(struct Scsi_Host *sh) |
| 264 | { |
| 265 | unsigned long *priv = shost_priv(sh); |
| 266 | return (struct ctlr_info *) *priv; |
| 267 | } |
| 268 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 269 | static int check_for_unit_attention(struct ctlr_info *h, |
| 270 | struct CommandList *c) |
| 271 | { |
| 272 | if (c->err_info->SenseInfo[2] != UNIT_ATTENTION) |
| 273 | return 0; |
| 274 | |
| 275 | switch (c->err_info->SenseInfo[12]) { |
| 276 | case STATE_CHANGED: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 277 | dev_warn(&h->pdev->dev, HPSA "%d: a state change " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 278 | "detected, command retried\n", h->ctlr); |
| 279 | break; |
| 280 | case LUN_FAILED: |
Stephen M. Cameron | 7f73695 | 2014-11-14 17:26:48 -0600 | [diff] [blame] | 281 | dev_warn(&h->pdev->dev, |
| 282 | HPSA "%d: LUN failure detected\n", h->ctlr); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 283 | break; |
| 284 | case REPORT_LUNS_CHANGED: |
Stephen M. Cameron | 7f73695 | 2014-11-14 17:26:48 -0600 | [diff] [blame] | 285 | dev_warn(&h->pdev->dev, |
| 286 | HPSA "%d: report LUN data changed\n", h->ctlr); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 287 | /* |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 288 | * Note: this REPORT_LUNS_CHANGED condition only occurs on the external |
| 289 | * target (array) devices. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 290 | */ |
| 291 | break; |
| 292 | case POWER_OR_RESET: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 293 | dev_warn(&h->pdev->dev, HPSA "%d: a power on " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 294 | "or device reset detected\n", h->ctlr); |
| 295 | break; |
| 296 | case UNIT_ATTENTION_CLEARED: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 297 | dev_warn(&h->pdev->dev, HPSA "%d: unit attention " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 298 | "cleared by another initiator\n", h->ctlr); |
| 299 | break; |
| 300 | default: |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 301 | dev_warn(&h->pdev->dev, HPSA "%d: unknown " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 302 | "unit attention detected\n", h->ctlr); |
| 303 | break; |
| 304 | } |
| 305 | return 1; |
| 306 | } |
| 307 | |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 308 | static int check_for_busy(struct ctlr_info *h, struct CommandList *c) |
| 309 | { |
| 310 | if (c->err_info->CommandStatus != CMD_TARGET_STATUS || |
| 311 | (c->err_info->ScsiStatus != SAM_STAT_BUSY && |
| 312 | c->err_info->ScsiStatus != SAM_STAT_TASK_SET_FULL)) |
| 313 | return 0; |
| 314 | dev_warn(&h->pdev->dev, HPSA "device busy"); |
| 315 | return 1; |
| 316 | } |
| 317 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 318 | static ssize_t host_store_hp_ssd_smart_path_status(struct device *dev, |
| 319 | struct device_attribute *attr, |
| 320 | const char *buf, size_t count) |
| 321 | { |
| 322 | int status, len; |
| 323 | struct ctlr_info *h; |
| 324 | struct Scsi_Host *shost = class_to_shost(dev); |
| 325 | char tmpbuf[10]; |
| 326 | |
| 327 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 328 | return -EACCES; |
| 329 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 330 | strncpy(tmpbuf, buf, len); |
| 331 | tmpbuf[len] = '\0'; |
| 332 | if (sscanf(tmpbuf, "%d", &status) != 1) |
| 333 | return -EINVAL; |
| 334 | h = shost_to_hba(shost); |
| 335 | h->acciopath_status = !!status; |
| 336 | dev_warn(&h->pdev->dev, |
| 337 | "hpsa: HP SSD Smart Path %s via sysfs update.\n", |
| 338 | h->acciopath_status ? "enabled" : "disabled"); |
| 339 | return count; |
| 340 | } |
| 341 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 342 | static ssize_t host_store_raid_offload_debug(struct device *dev, |
| 343 | struct device_attribute *attr, |
| 344 | const char *buf, size_t count) |
| 345 | { |
| 346 | int debug_level, len; |
| 347 | struct ctlr_info *h; |
| 348 | struct Scsi_Host *shost = class_to_shost(dev); |
| 349 | char tmpbuf[10]; |
| 350 | |
| 351 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 352 | return -EACCES; |
| 353 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 354 | strncpy(tmpbuf, buf, len); |
| 355 | tmpbuf[len] = '\0'; |
| 356 | if (sscanf(tmpbuf, "%d", &debug_level) != 1) |
| 357 | return -EINVAL; |
| 358 | if (debug_level < 0) |
| 359 | debug_level = 0; |
| 360 | h = shost_to_hba(shost); |
| 361 | h->raid_offload_debug = debug_level; |
| 362 | dev_warn(&h->pdev->dev, "hpsa: Set raid_offload_debug level = %d\n", |
| 363 | h->raid_offload_debug); |
| 364 | return count; |
| 365 | } |
| 366 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 367 | static ssize_t host_store_rescan(struct device *dev, |
| 368 | struct device_attribute *attr, |
| 369 | const char *buf, size_t count) |
| 370 | { |
| 371 | struct ctlr_info *h; |
| 372 | struct Scsi_Host *shost = class_to_shost(dev); |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 373 | h = shost_to_hba(shost); |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 374 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 375 | return count; |
| 376 | } |
| 377 | |
Stephen M. Cameron | d28ce02 | 2010-05-27 15:14:34 -0500 | [diff] [blame] | 378 | static ssize_t host_show_firmware_revision(struct device *dev, |
| 379 | struct device_attribute *attr, char *buf) |
| 380 | { |
| 381 | struct ctlr_info *h; |
| 382 | struct Scsi_Host *shost = class_to_shost(dev); |
| 383 | unsigned char *fwrev; |
| 384 | |
| 385 | h = shost_to_hba(shost); |
| 386 | if (!h->hba_inquiry_data) |
| 387 | return 0; |
| 388 | fwrev = &h->hba_inquiry_data[32]; |
| 389 | return snprintf(buf, 20, "%c%c%c%c\n", |
| 390 | fwrev[0], fwrev[1], fwrev[2], fwrev[3]); |
| 391 | } |
| 392 | |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 393 | static ssize_t host_show_commands_outstanding(struct device *dev, |
| 394 | struct device_attribute *attr, char *buf) |
| 395 | { |
| 396 | struct Scsi_Host *shost = class_to_shost(dev); |
| 397 | struct ctlr_info *h = shost_to_hba(shost); |
| 398 | |
Stephen M. Cameron | 0cbf768 | 2014-11-14 17:27:09 -0600 | [diff] [blame] | 399 | return snprintf(buf, 20, "%d\n", |
| 400 | atomic_read(&h->commands_outstanding)); |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 401 | } |
| 402 | |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 403 | static ssize_t host_show_transport_mode(struct device *dev, |
| 404 | struct device_attribute *attr, char *buf) |
| 405 | { |
| 406 | struct ctlr_info *h; |
| 407 | struct Scsi_Host *shost = class_to_shost(dev); |
| 408 | |
| 409 | h = shost_to_hba(shost); |
| 410 | return snprintf(buf, 20, "%s\n", |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 411 | h->transMethod & CFGTBL_Trans_Performant ? |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 412 | "performant" : "simple"); |
| 413 | } |
| 414 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 415 | static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev, |
| 416 | struct device_attribute *attr, char *buf) |
| 417 | { |
| 418 | struct ctlr_info *h; |
| 419 | struct Scsi_Host *shost = class_to_shost(dev); |
| 420 | |
| 421 | h = shost_to_hba(shost); |
| 422 | return snprintf(buf, 30, "HP SSD Smart Path %s\n", |
| 423 | (h->acciopath_status == 1) ? "enabled" : "disabled"); |
| 424 | } |
| 425 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 426 | /* 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] | 427 | static u32 unresettable_controller[] = { |
| 428 | 0x324a103C, /* Smart Array P712m */ |
| 429 | 0x324b103C, /* SmartArray P711m */ |
| 430 | 0x3223103C, /* Smart Array P800 */ |
| 431 | 0x3234103C, /* Smart Array P400 */ |
| 432 | 0x3235103C, /* Smart Array P400i */ |
| 433 | 0x3211103C, /* Smart Array E200i */ |
| 434 | 0x3212103C, /* Smart Array E200 */ |
| 435 | 0x3213103C, /* Smart Array E200i */ |
| 436 | 0x3214103C, /* Smart Array E200i */ |
| 437 | 0x3215103C, /* Smart Array E200i */ |
| 438 | 0x3237103C, /* Smart Array E500 */ |
| 439 | 0x323D103C, /* Smart Array P700m */ |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 440 | 0x40800E11, /* Smart Array 5i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 441 | 0x409C0E11, /* Smart Array 6400 */ |
| 442 | 0x409D0E11, /* Smart Array 6400 EM */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 443 | 0x40700E11, /* Smart Array 5300 */ |
| 444 | 0x40820E11, /* Smart Array 532 */ |
| 445 | 0x40830E11, /* Smart Array 5312 */ |
| 446 | 0x409A0E11, /* Smart Array 641 */ |
| 447 | 0x409B0E11, /* Smart Array 642 */ |
| 448 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 449 | }; |
| 450 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 451 | /* List of controllers which cannot even be soft reset */ |
| 452 | static u32 soft_unresettable_controller[] = { |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 453 | 0x40800E11, /* Smart Array 5i */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 454 | 0x40700E11, /* Smart Array 5300 */ |
| 455 | 0x40820E11, /* Smart Array 532 */ |
| 456 | 0x40830E11, /* Smart Array 5312 */ |
| 457 | 0x409A0E11, /* Smart Array 641 */ |
| 458 | 0x409B0E11, /* Smart Array 642 */ |
| 459 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 460 | /* Exclude 640x boards. These are two pci devices in one slot |
| 461 | * which share a battery backed cache module. One controls the |
| 462 | * cache, the other accesses the cache through the one that controls |
| 463 | * it. If we reset the one controlling the cache, the other will |
| 464 | * likely not be happy. Just forbid resetting this conjoined mess. |
| 465 | * The 640x isn't really supported by hpsa anyway. |
| 466 | */ |
| 467 | 0x409C0E11, /* Smart Array 6400 */ |
| 468 | 0x409D0E11, /* Smart Array 6400 EM */ |
| 469 | }; |
| 470 | |
| 471 | static int ctlr_is_hard_resettable(u32 board_id) |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 472 | { |
| 473 | int i; |
| 474 | |
| 475 | for (i = 0; i < ARRAY_SIZE(unresettable_controller); i++) |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 476 | if (unresettable_controller[i] == board_id) |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 477 | return 0; |
| 478 | return 1; |
| 479 | } |
| 480 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 481 | static int ctlr_is_soft_resettable(u32 board_id) |
| 482 | { |
| 483 | int i; |
| 484 | |
| 485 | for (i = 0; i < ARRAY_SIZE(soft_unresettable_controller); i++) |
| 486 | if (soft_unresettable_controller[i] == board_id) |
| 487 | return 0; |
| 488 | return 1; |
| 489 | } |
| 490 | |
| 491 | static int ctlr_is_resettable(u32 board_id) |
| 492 | { |
| 493 | return ctlr_is_hard_resettable(board_id) || |
| 494 | ctlr_is_soft_resettable(board_id); |
| 495 | } |
| 496 | |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 497 | static ssize_t host_show_resettable(struct device *dev, |
| 498 | struct device_attribute *attr, char *buf) |
| 499 | { |
| 500 | struct ctlr_info *h; |
| 501 | struct Scsi_Host *shost = class_to_shost(dev); |
| 502 | |
| 503 | h = shost_to_hba(shost); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 504 | 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] | 505 | } |
| 506 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 507 | static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[]) |
| 508 | { |
| 509 | return (scsi3addr[3] & 0xC0) == 0x40; |
| 510 | } |
| 511 | |
Robert Elliott | f2ef0ce | 2015-01-23 16:41:35 -0600 | [diff] [blame] | 512 | static const char * const raid_label[] = { "0", "4", "1(+0)", "5", "5+1", "6", |
| 513 | "1(+0)ADM", "UNKNOWN" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 514 | }; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 515 | #define HPSA_RAID_0 0 |
| 516 | #define HPSA_RAID_4 1 |
| 517 | #define HPSA_RAID_1 2 /* also used for RAID 10 */ |
| 518 | #define HPSA_RAID_5 3 /* also used for RAID 50 */ |
| 519 | #define HPSA_RAID_51 4 |
| 520 | #define HPSA_RAID_6 5 /* also used for RAID 60 */ |
| 521 | #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] | 522 | #define RAID_UNKNOWN (ARRAY_SIZE(raid_label) - 1) |
| 523 | |
| 524 | static ssize_t raid_level_show(struct device *dev, |
| 525 | struct device_attribute *attr, char *buf) |
| 526 | { |
| 527 | ssize_t l = 0; |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 528 | unsigned char rlevel; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 529 | struct ctlr_info *h; |
| 530 | struct scsi_device *sdev; |
| 531 | struct hpsa_scsi_dev_t *hdev; |
| 532 | unsigned long flags; |
| 533 | |
| 534 | sdev = to_scsi_device(dev); |
| 535 | h = sdev_to_hba(sdev); |
| 536 | spin_lock_irqsave(&h->lock, flags); |
| 537 | hdev = sdev->hostdata; |
| 538 | if (!hdev) { |
| 539 | spin_unlock_irqrestore(&h->lock, flags); |
| 540 | return -ENODEV; |
| 541 | } |
| 542 | |
| 543 | /* Is this even a logical drive? */ |
| 544 | if (!is_logical_dev_addr_mode(hdev->scsi3addr)) { |
| 545 | spin_unlock_irqrestore(&h->lock, flags); |
| 546 | l = snprintf(buf, PAGE_SIZE, "N/A\n"); |
| 547 | return l; |
| 548 | } |
| 549 | |
| 550 | rlevel = hdev->raid_level; |
| 551 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 552 | if (rlevel > RAID_UNKNOWN) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 553 | rlevel = RAID_UNKNOWN; |
| 554 | l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]); |
| 555 | return l; |
| 556 | } |
| 557 | |
| 558 | static ssize_t lunid_show(struct device *dev, |
| 559 | struct device_attribute *attr, char *buf) |
| 560 | { |
| 561 | struct ctlr_info *h; |
| 562 | struct scsi_device *sdev; |
| 563 | struct hpsa_scsi_dev_t *hdev; |
| 564 | unsigned long flags; |
| 565 | unsigned char lunid[8]; |
| 566 | |
| 567 | sdev = to_scsi_device(dev); |
| 568 | h = sdev_to_hba(sdev); |
| 569 | spin_lock_irqsave(&h->lock, flags); |
| 570 | hdev = sdev->hostdata; |
| 571 | if (!hdev) { |
| 572 | spin_unlock_irqrestore(&h->lock, flags); |
| 573 | return -ENODEV; |
| 574 | } |
| 575 | memcpy(lunid, hdev->scsi3addr, sizeof(lunid)); |
| 576 | spin_unlock_irqrestore(&h->lock, flags); |
| 577 | return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 578 | lunid[0], lunid[1], lunid[2], lunid[3], |
| 579 | lunid[4], lunid[5], lunid[6], lunid[7]); |
| 580 | } |
| 581 | |
| 582 | static ssize_t unique_id_show(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 | unsigned char sn[16]; |
| 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 | memcpy(sn, hdev->device_id, sizeof(sn)); |
| 600 | spin_unlock_irqrestore(&h->lock, flags); |
| 601 | return snprintf(buf, 16 * 2 + 2, |
| 602 | "%02X%02X%02X%02X%02X%02X%02X%02X" |
| 603 | "%02X%02X%02X%02X%02X%02X%02X%02X\n", |
| 604 | sn[0], sn[1], sn[2], sn[3], |
| 605 | sn[4], sn[5], sn[6], sn[7], |
| 606 | sn[8], sn[9], sn[10], sn[11], |
| 607 | sn[12], sn[13], sn[14], sn[15]); |
| 608 | } |
| 609 | |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 610 | static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev, |
| 611 | struct device_attribute *attr, char *buf) |
| 612 | { |
| 613 | struct ctlr_info *h; |
| 614 | struct scsi_device *sdev; |
| 615 | struct hpsa_scsi_dev_t *hdev; |
| 616 | unsigned long flags; |
| 617 | int offload_enabled; |
| 618 | |
| 619 | sdev = to_scsi_device(dev); |
| 620 | h = sdev_to_hba(sdev); |
| 621 | spin_lock_irqsave(&h->lock, flags); |
| 622 | hdev = sdev->hostdata; |
| 623 | if (!hdev) { |
| 624 | spin_unlock_irqrestore(&h->lock, flags); |
| 625 | return -ENODEV; |
| 626 | } |
| 627 | offload_enabled = hdev->offload_enabled; |
| 628 | spin_unlock_irqrestore(&h->lock, flags); |
| 629 | return snprintf(buf, 20, "%d\n", offload_enabled); |
| 630 | } |
| 631 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 632 | static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL); |
| 633 | static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL); |
| 634 | static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL); |
| 635 | static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 636 | static DEVICE_ATTR(hp_ssd_smart_path_enabled, S_IRUGO, |
| 637 | host_show_hp_ssd_smart_path_enabled, NULL); |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 638 | static DEVICE_ATTR(hp_ssd_smart_path_status, S_IWUSR|S_IRUGO|S_IROTH, |
| 639 | host_show_hp_ssd_smart_path_status, |
| 640 | host_store_hp_ssd_smart_path_status); |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 641 | static DEVICE_ATTR(raid_offload_debug, S_IWUSR, NULL, |
| 642 | host_store_raid_offload_debug); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 643 | static DEVICE_ATTR(firmware_revision, S_IRUGO, |
| 644 | host_show_firmware_revision, NULL); |
| 645 | static DEVICE_ATTR(commands_outstanding, S_IRUGO, |
| 646 | host_show_commands_outstanding, NULL); |
| 647 | static DEVICE_ATTR(transport_mode, S_IRUGO, |
| 648 | host_show_transport_mode, NULL); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 649 | static DEVICE_ATTR(resettable, S_IRUGO, |
| 650 | host_show_resettable, NULL); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 651 | |
| 652 | static struct device_attribute *hpsa_sdev_attrs[] = { |
| 653 | &dev_attr_raid_level, |
| 654 | &dev_attr_lunid, |
| 655 | &dev_attr_unique_id, |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 656 | &dev_attr_hp_ssd_smart_path_enabled, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 657 | NULL, |
| 658 | }; |
| 659 | |
| 660 | static struct device_attribute *hpsa_shost_attrs[] = { |
| 661 | &dev_attr_rescan, |
| 662 | &dev_attr_firmware_revision, |
| 663 | &dev_attr_commands_outstanding, |
| 664 | &dev_attr_transport_mode, |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 665 | &dev_attr_resettable, |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 666 | &dev_attr_hp_ssd_smart_path_status, |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 667 | &dev_attr_raid_offload_debug, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 668 | NULL, |
| 669 | }; |
| 670 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 671 | #define HPSA_NRESERVED_CMDS (HPSA_CMDS_RESERVED_FOR_ABORTS + \ |
| 672 | HPSA_CMDS_RESERVED_FOR_DRIVER + HPSA_MAX_CONCURRENT_PASSTHRUS) |
| 673 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 674 | static struct scsi_host_template hpsa_driver_template = { |
| 675 | .module = THIS_MODULE, |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 676 | .name = HPSA, |
| 677 | .proc_name = HPSA, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 678 | .queuecommand = hpsa_scsi_queue_command, |
| 679 | .scan_start = hpsa_scan_start, |
| 680 | .scan_finished = hpsa_scan_finished, |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 681 | .change_queue_depth = hpsa_change_queue_depth, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 682 | .this_id = -1, |
| 683 | .use_clustering = ENABLE_CLUSTERING, |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 684 | .eh_abort_handler = hpsa_eh_abort_handler, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 685 | .eh_device_reset_handler = hpsa_eh_device_reset_handler, |
| 686 | .ioctl = hpsa_ioctl, |
| 687 | .slave_alloc = hpsa_slave_alloc, |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 688 | .slave_configure = hpsa_slave_configure, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 689 | .slave_destroy = hpsa_slave_destroy, |
| 690 | #ifdef CONFIG_COMPAT |
| 691 | .compat_ioctl = hpsa_compat_ioctl, |
| 692 | #endif |
| 693 | .sdev_attrs = hpsa_sdev_attrs, |
| 694 | .shost_attrs = hpsa_shost_attrs, |
Stephen M. Cameron | c0d6a4d | 2011-10-26 16:20:53 -0500 | [diff] [blame] | 695 | .max_sectors = 8192, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 696 | .no_write_same = 1, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 697 | }; |
| 698 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 699 | static inline u32 next_command(struct ctlr_info *h, u8 q) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 700 | { |
| 701 | u32 a; |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 702 | struct reply_queue_buffer *rq = &h->reply_queue[q]; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 703 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 704 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 705 | return h->access.command_completed(h, q); |
| 706 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 707 | if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 708 | return h->access.command_completed(h, q); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 709 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 710 | if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { |
| 711 | a = rq->head[rq->current_entry]; |
| 712 | rq->current_entry++; |
Stephen M. Cameron | 0cbf768 | 2014-11-14 17:27:09 -0600 | [diff] [blame] | 713 | atomic_dec(&h->commands_outstanding); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 714 | } else { |
| 715 | a = FIFO_EMPTY; |
| 716 | } |
| 717 | /* Check for wraparound */ |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 718 | if (rq->current_entry == h->max_commands) { |
| 719 | rq->current_entry = 0; |
| 720 | rq->wraparound ^= 1; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 721 | } |
| 722 | return a; |
| 723 | } |
| 724 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 725 | /* |
| 726 | * There are some special bits in the bus address of the |
| 727 | * command that we have to set for the controller to know |
| 728 | * how to process the command: |
| 729 | * |
| 730 | * Normal performant mode: |
| 731 | * bit 0: 1 means performant mode, 0 means simple mode. |
| 732 | * bits 1-3 = block fetch table entry |
| 733 | * bits 4-6 = command type (== 0) |
| 734 | * |
| 735 | * ioaccel1 mode: |
| 736 | * bit 0 = "performant mode" bit. |
| 737 | * bits 1-3 = block fetch table entry |
| 738 | * bits 4-6 = command type (== 110) |
| 739 | * (command type is needed because ioaccel1 mode |
| 740 | * commands are submitted through the same register as normal |
| 741 | * mode commands, so this is how the controller knows whether |
| 742 | * the command is normal mode or ioaccel1 mode.) |
| 743 | * |
| 744 | * ioaccel2 mode: |
| 745 | * bit 0 = "performant mode" bit. |
| 746 | * bits 1-4 = block fetch table entry (note extra bit) |
| 747 | * bits 4-6 = not needed, because ioaccel2 mode has |
| 748 | * a separate special register for submitting commands. |
| 749 | */ |
| 750 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 751 | /* set_performant_mode: Modify the tag for cciss performant |
| 752 | * set bit 0 for pull model, bits 3-1 for block fetch |
| 753 | * register number |
| 754 | */ |
| 755 | static void set_performant_mode(struct ctlr_info *h, struct CommandList *c) |
| 756 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 757 | if (likely(h->transMethod & CFGTBL_Trans_Performant)) { |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 758 | c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 759 | if (likely(h->msix_vector > 0)) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 760 | c->Header.ReplyQueue = |
John Kacur | 804a5cb | 2013-07-26 16:06:18 +0200 | [diff] [blame] | 761 | raw_smp_processor_id() % h->nreply_queues; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 762 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 763 | } |
| 764 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 765 | static void set_ioaccel1_performant_mode(struct ctlr_info *h, |
| 766 | struct CommandList *c) |
| 767 | { |
| 768 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 769 | |
| 770 | /* Tell the controller to post the reply to the queue for this |
| 771 | * processor. This seems to give the best I/O throughput. |
| 772 | */ |
| 773 | cp->ReplyQueue = smp_processor_id() % h->nreply_queues; |
| 774 | /* Set the bits in the address sent down to include: |
| 775 | * - performant mode bit (bit 0) |
| 776 | * - pull count (bits 1-3) |
| 777 | * - command type (bits 4-6) |
| 778 | */ |
| 779 | c->busaddr |= 1 | (h->ioaccel1_blockFetchTable[c->Header.SGList] << 1) | |
| 780 | IOACCEL1_BUSADDR_CMDTYPE; |
| 781 | } |
| 782 | |
| 783 | static void set_ioaccel2_performant_mode(struct ctlr_info *h, |
| 784 | struct CommandList *c) |
| 785 | { |
| 786 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 787 | |
| 788 | /* Tell the controller to post the reply to the queue for this |
| 789 | * processor. This seems to give the best I/O throughput. |
| 790 | */ |
| 791 | cp->reply_queue = smp_processor_id() % h->nreply_queues; |
| 792 | /* Set the bits in the address sent down to include: |
| 793 | * - performant mode bit not used in ioaccel mode 2 |
| 794 | * - pull count (bits 0-3) |
| 795 | * - command type isn't needed for ioaccel2 |
| 796 | */ |
| 797 | c->busaddr |= (h->ioaccel2_blockFetchTable[cp->sg_count]); |
| 798 | } |
| 799 | |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 800 | static int is_firmware_flash_cmd(u8 *cdb) |
| 801 | { |
| 802 | return cdb[0] == BMIC_WRITE && cdb[6] == BMIC_FLASH_FIRMWARE; |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * During firmware flash, the heartbeat register may not update as frequently |
| 807 | * as it should. So we dial down lockup detection during firmware flash. and |
| 808 | * dial it back up when firmware flash completes. |
| 809 | */ |
| 810 | #define HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH (240 * HZ) |
| 811 | #define HEARTBEAT_SAMPLE_INTERVAL (30 * HZ) |
| 812 | static void dial_down_lockup_detection_during_fw_flash(struct ctlr_info *h, |
| 813 | struct CommandList *c) |
| 814 | { |
| 815 | if (!is_firmware_flash_cmd(c->Request.CDB)) |
| 816 | return; |
| 817 | atomic_inc(&h->firmware_flash_in_progress); |
| 818 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH; |
| 819 | } |
| 820 | |
| 821 | static void dial_up_lockup_detection_on_fw_flash_complete(struct ctlr_info *h, |
| 822 | struct CommandList *c) |
| 823 | { |
| 824 | if (is_firmware_flash_cmd(c->Request.CDB) && |
| 825 | atomic_dec_and_test(&h->firmware_flash_in_progress)) |
| 826 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 827 | } |
| 828 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 829 | static void enqueue_cmd_and_start_io(struct ctlr_info *h, |
| 830 | struct CommandList *c) |
| 831 | { |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 832 | dial_down_lockup_detection_during_fw_flash(h, c); |
| 833 | atomic_inc(&h->commands_outstanding); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 834 | switch (c->cmd_type) { |
| 835 | case CMD_IOACCEL1: |
| 836 | set_ioaccel1_performant_mode(h, c); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 837 | writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 838 | break; |
| 839 | case CMD_IOACCEL2: |
| 840 | set_ioaccel2_performant_mode(h, c); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 841 | writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 842 | break; |
| 843 | default: |
| 844 | set_performant_mode(h, c); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 845 | h->access.submit_command(h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 846 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static inline int is_hba_lunid(unsigned char scsi3addr[]) |
| 850 | { |
| 851 | return memcmp(scsi3addr, RAID_CTLR_LUNID, 8) == 0; |
| 852 | } |
| 853 | |
| 854 | static inline int is_scsi_rev_5(struct ctlr_info *h) |
| 855 | { |
| 856 | if (!h->hba_inquiry_data) |
| 857 | return 0; |
| 858 | if ((h->hba_inquiry_data[2] & 0x07) == 5) |
| 859 | return 1; |
| 860 | return 0; |
| 861 | } |
| 862 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 863 | static int hpsa_find_target_lun(struct ctlr_info *h, |
| 864 | unsigned char scsi3addr[], int bus, int *target, int *lun) |
| 865 | { |
| 866 | /* finds an unused bus, target, lun for a new physical device |
| 867 | * assumes h->devlock is held |
| 868 | */ |
| 869 | int i, found = 0; |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 870 | DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 871 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 872 | bitmap_zero(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 873 | |
| 874 | for (i = 0; i < h->ndevices; i++) { |
| 875 | if (h->dev[i]->bus == bus && h->dev[i]->target != -1) |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 876 | __set_bit(h->dev[i]->target, lun_taken); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 877 | } |
| 878 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 879 | i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES); |
| 880 | if (i < HPSA_MAX_DEVICES) { |
| 881 | /* *bus = 1; */ |
| 882 | *target = i; |
| 883 | *lun = 0; |
| 884 | found = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 885 | } |
| 886 | return !found; |
| 887 | } |
| 888 | |
| 889 | /* Add an entry into h->dev[] array. */ |
| 890 | static int hpsa_scsi_add_entry(struct ctlr_info *h, int hostno, |
| 891 | struct hpsa_scsi_dev_t *device, |
| 892 | struct hpsa_scsi_dev_t *added[], int *nadded) |
| 893 | { |
| 894 | /* assumes h->devlock is held */ |
| 895 | int n = h->ndevices; |
| 896 | int i; |
| 897 | unsigned char addr1[8], addr2[8]; |
| 898 | struct hpsa_scsi_dev_t *sd; |
| 899 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 900 | if (n >= HPSA_MAX_DEVICES) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 901 | dev_err(&h->pdev->dev, "too many devices, some will be " |
| 902 | "inaccessible.\n"); |
| 903 | return -1; |
| 904 | } |
| 905 | |
| 906 | /* physical devices do not have lun or target assigned until now. */ |
| 907 | if (device->lun != -1) |
| 908 | /* Logical device, lun is already assigned. */ |
| 909 | goto lun_assigned; |
| 910 | |
| 911 | /* If this device a non-zero lun of a multi-lun device |
| 912 | * byte 4 of the 8-byte LUN addr will contain the logical |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 913 | * unit no, zero otherwise. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 914 | */ |
| 915 | if (device->scsi3addr[4] == 0) { |
| 916 | /* This is not a non-zero lun of a multi-lun device */ |
| 917 | if (hpsa_find_target_lun(h, device->scsi3addr, |
| 918 | device->bus, &device->target, &device->lun) != 0) |
| 919 | return -1; |
| 920 | goto lun_assigned; |
| 921 | } |
| 922 | |
| 923 | /* This is a non-zero lun of a multi-lun device. |
| 924 | * Search through our list and find the device which |
| 925 | * has the same 8 byte LUN address, excepting byte 4. |
| 926 | * Assign the same bus and target for this new LUN. |
| 927 | * Use the logical unit number from the firmware. |
| 928 | */ |
| 929 | memcpy(addr1, device->scsi3addr, 8); |
| 930 | addr1[4] = 0; |
| 931 | for (i = 0; i < n; i++) { |
| 932 | sd = h->dev[i]; |
| 933 | memcpy(addr2, sd->scsi3addr, 8); |
| 934 | addr2[4] = 0; |
| 935 | /* differ only in byte 4? */ |
| 936 | if (memcmp(addr1, addr2, 8) == 0) { |
| 937 | device->bus = sd->bus; |
| 938 | device->target = sd->target; |
| 939 | device->lun = device->scsi3addr[4]; |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | if (device->lun == -1) { |
| 944 | dev_warn(&h->pdev->dev, "physical device with no LUN=0," |
| 945 | " suspect firmware bug or unsupported hardware " |
| 946 | "configuration.\n"); |
| 947 | return -1; |
| 948 | } |
| 949 | |
| 950 | lun_assigned: |
| 951 | |
| 952 | h->dev[n] = device; |
| 953 | h->ndevices++; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 954 | device->offload_to_be_enabled = device->offload_enabled; |
| 955 | device->offload_enabled = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 956 | added[*nadded] = device; |
| 957 | (*nadded)++; |
| 958 | |
| 959 | /* initially, (before registering with scsi layer) we don't |
| 960 | * know our hostno and we don't want to print anything first |
| 961 | * time anyway (the scsi layer's inquiries will show that info) |
| 962 | */ |
| 963 | /* if (hostno != -1) */ |
| 964 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d added.\n", |
| 965 | scsi_device_type(device->devtype), hostno, |
| 966 | device->bus, device->target, device->lun); |
| 967 | return 0; |
| 968 | } |
| 969 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 970 | /* Update an entry in h->dev[] array. */ |
| 971 | static void hpsa_scsi_update_entry(struct ctlr_info *h, int hostno, |
| 972 | int entry, struct hpsa_scsi_dev_t *new_entry) |
| 973 | { |
| 974 | /* assumes h->devlock is held */ |
| 975 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
| 976 | |
| 977 | /* Raid level changed. */ |
| 978 | h->dev[entry]->raid_level = new_entry->raid_level; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 979 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 980 | /* Raid offload parameters changed. Careful about the ordering. */ |
| 981 | if (new_entry->offload_config && new_entry->offload_enabled) { |
| 982 | /* |
| 983 | * if drive is newly offload_enabled, we want to copy the |
| 984 | * raid map data first. If previously offload_enabled and |
| 985 | * offload_config were set, raid map data had better be |
| 986 | * the same as it was before. if raid map data is changed |
| 987 | * then it had better be the case that |
| 988 | * h->dev[entry]->offload_enabled is currently 0. |
| 989 | */ |
| 990 | h->dev[entry]->raid_map = new_entry->raid_map; |
| 991 | h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 992 | } |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 993 | h->dev[entry]->offload_config = new_entry->offload_config; |
Stephen M. Cameron | 9fb0de2 | 2014-02-18 13:56:50 -0600 | [diff] [blame] | 994 | h->dev[entry]->offload_to_mirror = new_entry->offload_to_mirror; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 995 | h->dev[entry]->queue_depth = new_entry->queue_depth; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 996 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 997 | /* |
| 998 | * We can turn off ioaccel offload now, but need to delay turning |
| 999 | * it on until we can update h->dev[entry]->phys_disk[], but we |
| 1000 | * can't do that until all the devices are updated. |
| 1001 | */ |
| 1002 | h->dev[entry]->offload_to_be_enabled = new_entry->offload_enabled; |
| 1003 | if (!new_entry->offload_enabled) |
| 1004 | h->dev[entry]->offload_enabled = 0; |
| 1005 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1006 | } |
| 1007 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1008 | /* Replace an entry from h->dev[] array. */ |
| 1009 | static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno, |
| 1010 | int entry, struct hpsa_scsi_dev_t *new_entry, |
| 1011 | struct hpsa_scsi_dev_t *added[], int *nadded, |
| 1012 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1013 | { |
| 1014 | /* assumes h->devlock is held */ |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1015 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1016 | removed[*nremoved] = h->dev[entry]; |
| 1017 | (*nremoved)++; |
Stephen M. Cameron | 01350d0 | 2011-08-09 08:18:01 -0500 | [diff] [blame] | 1018 | |
| 1019 | /* |
| 1020 | * New physical devices won't have target/lun assigned yet |
| 1021 | * so we need to preserve the values in the slot we are replacing. |
| 1022 | */ |
| 1023 | if (new_entry->target == -1) { |
| 1024 | new_entry->target = h->dev[entry]->target; |
| 1025 | new_entry->lun = h->dev[entry]->lun; |
| 1026 | } |
| 1027 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1028 | new_entry->offload_to_be_enabled = new_entry->offload_enabled; |
| 1029 | new_entry->offload_enabled = 0; |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1030 | h->dev[entry] = new_entry; |
| 1031 | added[*nadded] = new_entry; |
| 1032 | (*nadded)++; |
| 1033 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d changed.\n", |
| 1034 | scsi_device_type(new_entry->devtype), hostno, new_entry->bus, |
| 1035 | new_entry->target, new_entry->lun); |
| 1036 | } |
| 1037 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1038 | /* Remove an entry from h->dev[] array. */ |
| 1039 | static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry, |
| 1040 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1041 | { |
| 1042 | /* assumes h->devlock is held */ |
| 1043 | int i; |
| 1044 | struct hpsa_scsi_dev_t *sd; |
| 1045 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1046 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1047 | |
| 1048 | sd = h->dev[entry]; |
| 1049 | removed[*nremoved] = h->dev[entry]; |
| 1050 | (*nremoved)++; |
| 1051 | |
| 1052 | for (i = entry; i < h->ndevices-1; i++) |
| 1053 | h->dev[i] = h->dev[i+1]; |
| 1054 | h->ndevices--; |
| 1055 | dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d removed.\n", |
| 1056 | scsi_device_type(sd->devtype), hostno, sd->bus, sd->target, |
| 1057 | sd->lun); |
| 1058 | } |
| 1059 | |
| 1060 | #define SCSI3ADDR_EQ(a, b) ( \ |
| 1061 | (a)[7] == (b)[7] && \ |
| 1062 | (a)[6] == (b)[6] && \ |
| 1063 | (a)[5] == (b)[5] && \ |
| 1064 | (a)[4] == (b)[4] && \ |
| 1065 | (a)[3] == (b)[3] && \ |
| 1066 | (a)[2] == (b)[2] && \ |
| 1067 | (a)[1] == (b)[1] && \ |
| 1068 | (a)[0] == (b)[0]) |
| 1069 | |
| 1070 | static void fixup_botched_add(struct ctlr_info *h, |
| 1071 | struct hpsa_scsi_dev_t *added) |
| 1072 | { |
| 1073 | /* called when scsi_add_device fails in order to re-adjust |
| 1074 | * h->dev[] to match the mid layer's view. |
| 1075 | */ |
| 1076 | unsigned long flags; |
| 1077 | int i, j; |
| 1078 | |
| 1079 | spin_lock_irqsave(&h->lock, flags); |
| 1080 | for (i = 0; i < h->ndevices; i++) { |
| 1081 | if (h->dev[i] == added) { |
| 1082 | for (j = i; j < h->ndevices-1; j++) |
| 1083 | h->dev[j] = h->dev[j+1]; |
| 1084 | h->ndevices--; |
| 1085 | break; |
| 1086 | } |
| 1087 | } |
| 1088 | spin_unlock_irqrestore(&h->lock, flags); |
| 1089 | kfree(added); |
| 1090 | } |
| 1091 | |
| 1092 | static inline int device_is_the_same(struct hpsa_scsi_dev_t *dev1, |
| 1093 | struct hpsa_scsi_dev_t *dev2) |
| 1094 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1095 | /* we compare everything except lun and target as these |
| 1096 | * are not yet assigned. Compare parts likely |
| 1097 | * to differ first |
| 1098 | */ |
| 1099 | if (memcmp(dev1->scsi3addr, dev2->scsi3addr, |
| 1100 | sizeof(dev1->scsi3addr)) != 0) |
| 1101 | return 0; |
| 1102 | if (memcmp(dev1->device_id, dev2->device_id, |
| 1103 | sizeof(dev1->device_id)) != 0) |
| 1104 | return 0; |
| 1105 | if (memcmp(dev1->model, dev2->model, sizeof(dev1->model)) != 0) |
| 1106 | return 0; |
| 1107 | if (memcmp(dev1->vendor, dev2->vendor, sizeof(dev1->vendor)) != 0) |
| 1108 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1109 | if (dev1->devtype != dev2->devtype) |
| 1110 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1111 | if (dev1->bus != dev2->bus) |
| 1112 | return 0; |
| 1113 | return 1; |
| 1114 | } |
| 1115 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1116 | static inline int device_updated(struct hpsa_scsi_dev_t *dev1, |
| 1117 | struct hpsa_scsi_dev_t *dev2) |
| 1118 | { |
| 1119 | /* Device attributes that can change, but don't mean |
| 1120 | * that the device is a different device, nor that the OS |
| 1121 | * needs to be told anything about the change. |
| 1122 | */ |
| 1123 | if (dev1->raid_level != dev2->raid_level) |
| 1124 | return 1; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1125 | if (dev1->offload_config != dev2->offload_config) |
| 1126 | return 1; |
| 1127 | if (dev1->offload_enabled != dev2->offload_enabled) |
| 1128 | return 1; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1129 | if (dev1->queue_depth != dev2->queue_depth) |
| 1130 | return 1; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1131 | return 0; |
| 1132 | } |
| 1133 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1134 | /* Find needle in haystack. If exact match found, return DEVICE_SAME, |
| 1135 | * and return needle location in *index. If scsi3addr matches, but not |
| 1136 | * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1137 | * location in *index. |
| 1138 | * In the case of a minor device attribute change, such as RAID level, just |
| 1139 | * return DEVICE_UPDATED, along with the updated device's location in index. |
| 1140 | * If needle not found, return DEVICE_NOT_FOUND. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1141 | */ |
| 1142 | static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle, |
| 1143 | struct hpsa_scsi_dev_t *haystack[], int haystack_size, |
| 1144 | int *index) |
| 1145 | { |
| 1146 | int i; |
| 1147 | #define DEVICE_NOT_FOUND 0 |
| 1148 | #define DEVICE_CHANGED 1 |
| 1149 | #define DEVICE_SAME 2 |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1150 | #define DEVICE_UPDATED 3 |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1151 | for (i = 0; i < haystack_size; i++) { |
Stephen M. Cameron | 2323104 | 2010-02-04 08:43:36 -0600 | [diff] [blame] | 1152 | if (haystack[i] == NULL) /* previously removed. */ |
| 1153 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1154 | if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) { |
| 1155 | *index = i; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1156 | if (device_is_the_same(needle, haystack[i])) { |
| 1157 | if (device_updated(needle, haystack[i])) |
| 1158 | return DEVICE_UPDATED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1159 | return DEVICE_SAME; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1160 | } else { |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1161 | /* Keep offline devices offline */ |
| 1162 | if (needle->volume_offline) |
| 1163 | return DEVICE_NOT_FOUND; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1164 | return DEVICE_CHANGED; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1165 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | *index = -1; |
| 1169 | return DEVICE_NOT_FOUND; |
| 1170 | } |
| 1171 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1172 | static void hpsa_monitor_offline_device(struct ctlr_info *h, |
| 1173 | unsigned char scsi3addr[]) |
| 1174 | { |
| 1175 | struct offline_device_entry *device; |
| 1176 | unsigned long flags; |
| 1177 | |
| 1178 | /* Check to see if device is already on the list */ |
| 1179 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 1180 | list_for_each_entry(device, &h->offline_device_list, offline_list) { |
| 1181 | if (memcmp(device->scsi3addr, scsi3addr, |
| 1182 | sizeof(device->scsi3addr)) == 0) { |
| 1183 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1184 | return; |
| 1185 | } |
| 1186 | } |
| 1187 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1188 | |
| 1189 | /* Device is not on the list, add it. */ |
| 1190 | device = kmalloc(sizeof(*device), GFP_KERNEL); |
| 1191 | if (!device) { |
| 1192 | dev_warn(&h->pdev->dev, "out of memory in %s\n", __func__); |
| 1193 | return; |
| 1194 | } |
| 1195 | memcpy(device->scsi3addr, scsi3addr, sizeof(device->scsi3addr)); |
| 1196 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 1197 | list_add_tail(&device->offline_list, &h->offline_device_list); |
| 1198 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1199 | } |
| 1200 | |
| 1201 | /* Print a message explaining various offline volume states */ |
| 1202 | static void hpsa_show_volume_status(struct ctlr_info *h, |
| 1203 | struct hpsa_scsi_dev_t *sd) |
| 1204 | { |
| 1205 | if (sd->volume_offline == HPSA_VPD_LV_STATUS_UNSUPPORTED) |
| 1206 | dev_info(&h->pdev->dev, |
| 1207 | "C%d:B%d:T%d:L%d Volume status is not available through vital product data pages.\n", |
| 1208 | h->scsi_host->host_no, |
| 1209 | sd->bus, sd->target, sd->lun); |
| 1210 | switch (sd->volume_offline) { |
| 1211 | case HPSA_LV_OK: |
| 1212 | break; |
| 1213 | case HPSA_LV_UNDERGOING_ERASE: |
| 1214 | dev_info(&h->pdev->dev, |
| 1215 | "C%d:B%d:T%d:L%d Volume is undergoing background erase process.\n", |
| 1216 | h->scsi_host->host_no, |
| 1217 | sd->bus, sd->target, sd->lun); |
| 1218 | break; |
| 1219 | case HPSA_LV_UNDERGOING_RPI: |
| 1220 | dev_info(&h->pdev->dev, |
| 1221 | "C%d:B%d:T%d:L%d Volume is undergoing rapid parity initialization process.\n", |
| 1222 | h->scsi_host->host_no, |
| 1223 | sd->bus, sd->target, sd->lun); |
| 1224 | break; |
| 1225 | case HPSA_LV_PENDING_RPI: |
| 1226 | dev_info(&h->pdev->dev, |
| 1227 | "C%d:B%d:T%d:L%d Volume is queued for rapid parity initialization process.\n", |
| 1228 | h->scsi_host->host_no, |
| 1229 | sd->bus, sd->target, sd->lun); |
| 1230 | break; |
| 1231 | case HPSA_LV_ENCRYPTED_NO_KEY: |
| 1232 | dev_info(&h->pdev->dev, |
| 1233 | "C%d:B%d:T%d:L%d Volume is encrypted and cannot be accessed because key is not present.\n", |
| 1234 | h->scsi_host->host_no, |
| 1235 | sd->bus, sd->target, sd->lun); |
| 1236 | break; |
| 1237 | case HPSA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER: |
| 1238 | dev_info(&h->pdev->dev, |
| 1239 | "C%d:B%d:T%d:L%d Volume is not encrypted and cannot be accessed because controller is in encryption-only mode.\n", |
| 1240 | h->scsi_host->host_no, |
| 1241 | sd->bus, sd->target, sd->lun); |
| 1242 | break; |
| 1243 | case HPSA_LV_UNDERGOING_ENCRYPTION: |
| 1244 | dev_info(&h->pdev->dev, |
| 1245 | "C%d:B%d:T%d:L%d Volume is undergoing encryption process.\n", |
| 1246 | h->scsi_host->host_no, |
| 1247 | sd->bus, sd->target, sd->lun); |
| 1248 | break; |
| 1249 | case HPSA_LV_UNDERGOING_ENCRYPTION_REKEYING: |
| 1250 | dev_info(&h->pdev->dev, |
| 1251 | "C%d:B%d:T%d:L%d Volume is undergoing encryption re-keying process.\n", |
| 1252 | h->scsi_host->host_no, |
| 1253 | sd->bus, sd->target, sd->lun); |
| 1254 | break; |
| 1255 | case HPSA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: |
| 1256 | dev_info(&h->pdev->dev, |
| 1257 | "C%d:B%d:T%d:L%d Volume is encrypted and cannot be accessed because controller does not have encryption enabled.\n", |
| 1258 | h->scsi_host->host_no, |
| 1259 | sd->bus, sd->target, sd->lun); |
| 1260 | break; |
| 1261 | case HPSA_LV_PENDING_ENCRYPTION: |
| 1262 | dev_info(&h->pdev->dev, |
| 1263 | "C%d:B%d:T%d:L%d Volume is pending migration to encrypted state, but process has not started.\n", |
| 1264 | h->scsi_host->host_no, |
| 1265 | sd->bus, sd->target, sd->lun); |
| 1266 | break; |
| 1267 | case HPSA_LV_PENDING_ENCRYPTION_REKEYING: |
| 1268 | dev_info(&h->pdev->dev, |
| 1269 | "C%d:B%d:T%d:L%d Volume is encrypted and is pending encryption rekeying.\n", |
| 1270 | h->scsi_host->host_no, |
| 1271 | sd->bus, sd->target, sd->lun); |
| 1272 | break; |
| 1273 | } |
| 1274 | } |
| 1275 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1276 | /* |
| 1277 | * Figure the list of physical drive pointers for a logical drive with |
| 1278 | * raid offload configured. |
| 1279 | */ |
| 1280 | static void hpsa_figure_phys_disk_ptrs(struct ctlr_info *h, |
| 1281 | struct hpsa_scsi_dev_t *dev[], int ndevices, |
| 1282 | struct hpsa_scsi_dev_t *logical_drive) |
| 1283 | { |
| 1284 | struct raid_map_data *map = &logical_drive->raid_map; |
| 1285 | struct raid_map_disk_data *dd = &map->data[0]; |
| 1286 | int i, j; |
| 1287 | int total_disks_per_row = le16_to_cpu(map->data_disks_per_row) + |
| 1288 | le16_to_cpu(map->metadata_disks_per_row); |
| 1289 | int nraid_map_entries = le16_to_cpu(map->row_cnt) * |
| 1290 | le16_to_cpu(map->layout_map_count) * |
| 1291 | total_disks_per_row; |
| 1292 | int nphys_disk = le16_to_cpu(map->layout_map_count) * |
| 1293 | total_disks_per_row; |
| 1294 | int qdepth; |
| 1295 | |
| 1296 | if (nraid_map_entries > RAID_MAP_MAX_ENTRIES) |
| 1297 | nraid_map_entries = RAID_MAP_MAX_ENTRIES; |
| 1298 | |
| 1299 | qdepth = 0; |
| 1300 | for (i = 0; i < nraid_map_entries; i++) { |
| 1301 | logical_drive->phys_disk[i] = NULL; |
| 1302 | if (!logical_drive->offload_config) |
| 1303 | continue; |
| 1304 | for (j = 0; j < ndevices; j++) { |
| 1305 | if (dev[j]->devtype != TYPE_DISK) |
| 1306 | continue; |
| 1307 | if (is_logical_dev_addr_mode(dev[j]->scsi3addr)) |
| 1308 | continue; |
| 1309 | if (dev[j]->ioaccel_handle != dd[i].ioaccel_handle) |
| 1310 | continue; |
| 1311 | |
| 1312 | logical_drive->phys_disk[i] = dev[j]; |
| 1313 | if (i < nphys_disk) |
| 1314 | qdepth = min(h->nr_cmds, qdepth + |
| 1315 | logical_drive->phys_disk[i]->queue_depth); |
| 1316 | break; |
| 1317 | } |
| 1318 | |
| 1319 | /* |
| 1320 | * This can happen if a physical drive is removed and |
| 1321 | * the logical drive is degraded. In that case, the RAID |
| 1322 | * map data will refer to a physical disk which isn't actually |
| 1323 | * present. And in that case offload_enabled should already |
| 1324 | * be 0, but we'll turn it off here just in case |
| 1325 | */ |
| 1326 | if (!logical_drive->phys_disk[i]) { |
| 1327 | logical_drive->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1328 | logical_drive->offload_to_be_enabled = 0; |
| 1329 | logical_drive->queue_depth = 8; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | if (nraid_map_entries) |
| 1333 | /* |
| 1334 | * This is correct for reads, too high for full stripe writes, |
| 1335 | * way too high for partial stripe writes |
| 1336 | */ |
| 1337 | logical_drive->queue_depth = qdepth; |
| 1338 | else |
| 1339 | logical_drive->queue_depth = h->nr_cmds; |
| 1340 | } |
| 1341 | |
| 1342 | static void hpsa_update_log_drive_phys_drive_ptrs(struct ctlr_info *h, |
| 1343 | struct hpsa_scsi_dev_t *dev[], int ndevices) |
| 1344 | { |
| 1345 | int i; |
| 1346 | |
| 1347 | for (i = 0; i < ndevices; i++) { |
| 1348 | if (dev[i]->devtype != TYPE_DISK) |
| 1349 | continue; |
| 1350 | if (!is_logical_dev_addr_mode(dev[i]->scsi3addr)) |
| 1351 | continue; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1352 | |
| 1353 | /* |
| 1354 | * If offload is currently enabled, the RAID map and |
| 1355 | * phys_disk[] assignment *better* not be changing |
| 1356 | * and since it isn't changing, we do not need to |
| 1357 | * update it. |
| 1358 | */ |
| 1359 | if (dev[i]->offload_enabled) |
| 1360 | continue; |
| 1361 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1362 | hpsa_figure_phys_disk_ptrs(h, dev, ndevices, dev[i]); |
| 1363 | } |
| 1364 | } |
| 1365 | |
Stephen M. Cameron | 4967bd3 | 2010-02-04 08:41:49 -0600 | [diff] [blame] | 1366 | 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] | 1367 | struct hpsa_scsi_dev_t *sd[], int nsds) |
| 1368 | { |
| 1369 | /* sd contains scsi3 addresses and devtypes, and inquiry |
| 1370 | * data. This function takes what's in sd to be the current |
| 1371 | * reality and updates h->dev[] to reflect that reality. |
| 1372 | */ |
| 1373 | int i, entry, device_change, changes = 0; |
| 1374 | struct hpsa_scsi_dev_t *csd; |
| 1375 | unsigned long flags; |
| 1376 | struct hpsa_scsi_dev_t **added, **removed; |
| 1377 | int nadded, nremoved; |
| 1378 | struct Scsi_Host *sh = NULL; |
| 1379 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1380 | added = kzalloc(sizeof(*added) * HPSA_MAX_DEVICES, GFP_KERNEL); |
| 1381 | removed = kzalloc(sizeof(*removed) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1382 | |
| 1383 | if (!added || !removed) { |
| 1384 | dev_warn(&h->pdev->dev, "out of memory in " |
| 1385 | "adjust_hpsa_scsi_table\n"); |
| 1386 | goto free_and_out; |
| 1387 | } |
| 1388 | |
| 1389 | spin_lock_irqsave(&h->devlock, flags); |
| 1390 | |
| 1391 | /* find any devices in h->dev[] that are not in |
| 1392 | * sd[] and remove them from h->dev[], and for any |
| 1393 | * devices which have changed, remove the old device |
| 1394 | * info and add the new device info. |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1395 | * If minor device attributes change, just update |
| 1396 | * the existing device structure. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1397 | */ |
| 1398 | i = 0; |
| 1399 | nremoved = 0; |
| 1400 | nadded = 0; |
| 1401 | while (i < h->ndevices) { |
| 1402 | csd = h->dev[i]; |
| 1403 | device_change = hpsa_scsi_find_entry(csd, sd, nsds, &entry); |
| 1404 | if (device_change == DEVICE_NOT_FOUND) { |
| 1405 | changes++; |
| 1406 | hpsa_scsi_remove_entry(h, hostno, i, |
| 1407 | removed, &nremoved); |
| 1408 | continue; /* remove ^^^, hence i not incremented */ |
| 1409 | } else if (device_change == DEVICE_CHANGED) { |
| 1410 | changes++; |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1411 | hpsa_scsi_replace_entry(h, hostno, i, sd[entry], |
| 1412 | added, &nadded, removed, &nremoved); |
Stephen M. Cameron | c7f172d | 2010-02-04 08:43:31 -0600 | [diff] [blame] | 1413 | /* Set it to NULL to prevent it from being freed |
| 1414 | * at the bottom of hpsa_update_scsi_devices() |
| 1415 | */ |
| 1416 | sd[entry] = NULL; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1417 | } else if (device_change == DEVICE_UPDATED) { |
| 1418 | hpsa_scsi_update_entry(h, hostno, i, sd[entry]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1419 | } |
| 1420 | i++; |
| 1421 | } |
| 1422 | |
| 1423 | /* Now, make sure every device listed in sd[] is also |
| 1424 | * listed in h->dev[], adding them if they aren't found |
| 1425 | */ |
| 1426 | |
| 1427 | for (i = 0; i < nsds; i++) { |
| 1428 | if (!sd[i]) /* if already added above. */ |
| 1429 | continue; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1430 | |
| 1431 | /* Don't add devices which are NOT READY, FORMAT IN PROGRESS |
| 1432 | * as the SCSI mid-layer does not handle such devices well. |
| 1433 | * It relentlessly loops sending TUR at 3Hz, then READ(10) |
| 1434 | * at 160Hz, and prevents the system from coming up. |
| 1435 | */ |
| 1436 | if (sd[i]->volume_offline) { |
| 1437 | hpsa_show_volume_status(h, sd[i]); |
| 1438 | dev_info(&h->pdev->dev, "c%db%dt%dl%d: temporarily offline\n", |
| 1439 | h->scsi_host->host_no, |
| 1440 | sd[i]->bus, sd[i]->target, sd[i]->lun); |
| 1441 | continue; |
| 1442 | } |
| 1443 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1444 | device_change = hpsa_scsi_find_entry(sd[i], h->dev, |
| 1445 | h->ndevices, &entry); |
| 1446 | if (device_change == DEVICE_NOT_FOUND) { |
| 1447 | changes++; |
| 1448 | if (hpsa_scsi_add_entry(h, hostno, sd[i], |
| 1449 | added, &nadded) != 0) |
| 1450 | break; |
| 1451 | sd[i] = NULL; /* prevent from being freed later. */ |
| 1452 | } else if (device_change == DEVICE_CHANGED) { |
| 1453 | /* should never happen... */ |
| 1454 | changes++; |
| 1455 | dev_warn(&h->pdev->dev, |
| 1456 | "device unexpectedly changed.\n"); |
| 1457 | /* but if it does happen, we just ignore that device */ |
| 1458 | } |
| 1459 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1460 | hpsa_update_log_drive_phys_drive_ptrs(h, h->dev, h->ndevices); |
| 1461 | |
| 1462 | /* Now that h->dev[]->phys_disk[] is coherent, we can enable |
| 1463 | * any logical drives that need it enabled. |
| 1464 | */ |
| 1465 | for (i = 0; i < h->ndevices; i++) |
| 1466 | h->dev[i]->offload_enabled = h->dev[i]->offload_to_be_enabled; |
| 1467 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1468 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1469 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1470 | /* Monitor devices which are in one of several NOT READY states to be |
| 1471 | * brought online later. This must be done without holding h->devlock, |
| 1472 | * so don't touch h->dev[] |
| 1473 | */ |
| 1474 | for (i = 0; i < nsds; i++) { |
| 1475 | if (!sd[i]) /* if already added above. */ |
| 1476 | continue; |
| 1477 | if (sd[i]->volume_offline) |
| 1478 | hpsa_monitor_offline_device(h, sd[i]->scsi3addr); |
| 1479 | } |
| 1480 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1481 | /* Don't notify scsi mid layer of any changes the first time through |
| 1482 | * (or if there are no changes) scsi_scan_host will do it later the |
| 1483 | * first time through. |
| 1484 | */ |
| 1485 | if (hostno == -1 || !changes) |
| 1486 | goto free_and_out; |
| 1487 | |
| 1488 | sh = h->scsi_host; |
| 1489 | /* Notify scsi mid layer of any removed devices */ |
| 1490 | for (i = 0; i < nremoved; i++) { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1491 | if (removed[i]->expose_state & HPSA_SCSI_ADD) { |
| 1492 | struct scsi_device *sdev = |
| 1493 | scsi_device_lookup(sh, removed[i]->bus, |
| 1494 | removed[i]->target, removed[i]->lun); |
| 1495 | if (sdev != NULL) { |
| 1496 | scsi_remove_device(sdev); |
| 1497 | scsi_device_put(sdev); |
| 1498 | } else { |
| 1499 | /* |
| 1500 | * We don't expect to get here. |
| 1501 | * future cmds to this device will get selection |
| 1502 | * timeout as if the device was gone. |
| 1503 | */ |
| 1504 | dev_warn(&h->pdev->dev, |
| 1505 | "didn't find c%db%dt%dl%d for removal.\n", |
| 1506 | hostno, removed[i]->bus, |
| 1507 | removed[i]->target, removed[i]->lun); |
| 1508 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1509 | } |
| 1510 | kfree(removed[i]); |
| 1511 | removed[i] = NULL; |
| 1512 | } |
| 1513 | |
| 1514 | /* Notify scsi mid layer of any added devices */ |
| 1515 | for (i = 0; i < nadded; i++) { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1516 | if (!(added[i]->expose_state & HPSA_SCSI_ADD)) |
| 1517 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1518 | if (scsi_add_device(sh, added[i]->bus, |
| 1519 | added[i]->target, added[i]->lun) == 0) |
| 1520 | continue; |
| 1521 | dev_warn(&h->pdev->dev, "scsi_add_device c%db%dt%dl%d failed, " |
| 1522 | "device not added.\n", hostno, added[i]->bus, |
| 1523 | added[i]->target, added[i]->lun); |
| 1524 | /* now we have to remove it from h->dev, |
| 1525 | * since it didn't get added to scsi mid layer |
| 1526 | */ |
| 1527 | fixup_botched_add(h, added[i]); |
| 1528 | } |
| 1529 | |
| 1530 | free_and_out: |
| 1531 | kfree(added); |
| 1532 | kfree(removed); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /* |
Joe Perches | 9e03aa2 | 2013-09-03 13:45:58 -0700 | [diff] [blame] | 1536 | * 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] | 1537 | * Assume's h->devlock is held. |
| 1538 | */ |
| 1539 | static struct hpsa_scsi_dev_t *lookup_hpsa_scsi_dev(struct ctlr_info *h, |
| 1540 | int bus, int target, int lun) |
| 1541 | { |
| 1542 | int i; |
| 1543 | struct hpsa_scsi_dev_t *sd; |
| 1544 | |
| 1545 | for (i = 0; i < h->ndevices; i++) { |
| 1546 | sd = h->dev[i]; |
| 1547 | if (sd->bus == bus && sd->target == target && sd->lun == lun) |
| 1548 | return sd; |
| 1549 | } |
| 1550 | return NULL; |
| 1551 | } |
| 1552 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1553 | static int hpsa_slave_alloc(struct scsi_device *sdev) |
| 1554 | { |
| 1555 | struct hpsa_scsi_dev_t *sd; |
| 1556 | unsigned long flags; |
| 1557 | struct ctlr_info *h; |
| 1558 | |
| 1559 | h = sdev_to_hba(sdev); |
| 1560 | spin_lock_irqsave(&h->devlock, flags); |
| 1561 | sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev), |
| 1562 | sdev_id(sdev), sdev->lun); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1563 | if (likely(sd)) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1564 | atomic_set(&sd->ioaccel_cmds_out, 0); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1565 | sdev->hostdata = (sd->expose_state & HPSA_SCSI_ADD) ? sd : NULL; |
| 1566 | } else |
| 1567 | sdev->hostdata = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1568 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 1572 | /* configure scsi device based on internal per-device structure */ |
| 1573 | static int hpsa_slave_configure(struct scsi_device *sdev) |
| 1574 | { |
| 1575 | struct hpsa_scsi_dev_t *sd; |
| 1576 | int queue_depth; |
| 1577 | |
| 1578 | sd = sdev->hostdata; |
| 1579 | sdev->no_uld_attach = !sd || !(sd->expose_state & HPSA_ULD_ATTACH); |
| 1580 | |
| 1581 | if (sd) |
| 1582 | queue_depth = sd->queue_depth != 0 ? |
| 1583 | sd->queue_depth : sdev->host->can_queue; |
| 1584 | else |
| 1585 | queue_depth = sdev->host->can_queue; |
| 1586 | |
| 1587 | scsi_change_queue_depth(sdev, queue_depth); |
| 1588 | |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1592 | static void hpsa_slave_destroy(struct scsi_device *sdev) |
| 1593 | { |
Stephen M. Cameron | bcc4425 | 2010-02-04 08:41:54 -0600 | [diff] [blame] | 1594 | /* nothing to do. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1595 | } |
| 1596 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1597 | static void hpsa_free_sg_chain_blocks(struct ctlr_info *h) |
| 1598 | { |
| 1599 | int i; |
| 1600 | |
| 1601 | if (!h->cmd_sg_list) |
| 1602 | return; |
| 1603 | for (i = 0; i < h->nr_cmds; i++) { |
| 1604 | kfree(h->cmd_sg_list[i]); |
| 1605 | h->cmd_sg_list[i] = NULL; |
| 1606 | } |
| 1607 | kfree(h->cmd_sg_list); |
| 1608 | h->cmd_sg_list = NULL; |
| 1609 | } |
| 1610 | |
| 1611 | static int hpsa_allocate_sg_chain_blocks(struct ctlr_info *h) |
| 1612 | { |
| 1613 | int i; |
| 1614 | |
| 1615 | if (h->chainsize <= 0) |
| 1616 | return 0; |
| 1617 | |
| 1618 | h->cmd_sg_list = kzalloc(sizeof(*h->cmd_sg_list) * h->nr_cmds, |
| 1619 | GFP_KERNEL); |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 1620 | if (!h->cmd_sg_list) { |
| 1621 | dev_err(&h->pdev->dev, "Failed to allocate SG list\n"); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1622 | return -ENOMEM; |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 1623 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1624 | for (i = 0; i < h->nr_cmds; i++) { |
| 1625 | h->cmd_sg_list[i] = kmalloc(sizeof(*h->cmd_sg_list[i]) * |
| 1626 | h->chainsize, GFP_KERNEL); |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 1627 | if (!h->cmd_sg_list[i]) { |
| 1628 | dev_err(&h->pdev->dev, "Failed to allocate cmd SG\n"); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1629 | goto clean; |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 1630 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1631 | } |
| 1632 | return 0; |
| 1633 | |
| 1634 | clean: |
| 1635 | hpsa_free_sg_chain_blocks(h); |
| 1636 | return -ENOMEM; |
| 1637 | } |
| 1638 | |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1639 | static int hpsa_map_sg_chain_block(struct ctlr_info *h, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1640 | struct CommandList *c) |
| 1641 | { |
| 1642 | struct SGDescriptor *chain_sg, *chain_block; |
| 1643 | u64 temp64; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1644 | u32 chain_len; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1645 | |
| 1646 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
| 1647 | chain_block = h->cmd_sg_list[c->cmdindex]; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1648 | chain_sg->Ext = cpu_to_le32(HPSA_SG_CHAIN); |
| 1649 | chain_len = sizeof(*chain_sg) * |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 1650 | (le16_to_cpu(c->Header.SGTotal) - h->max_cmd_sg_entries); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1651 | chain_sg->Len = cpu_to_le32(chain_len); |
| 1652 | temp64 = pci_map_single(h->pdev, chain_block, chain_len, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1653 | PCI_DMA_TODEVICE); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1654 | if (dma_mapping_error(&h->pdev->dev, temp64)) { |
| 1655 | /* prevent subsequent unmapping */ |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1656 | chain_sg->Addr = cpu_to_le64(0); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1657 | return -1; |
| 1658 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1659 | chain_sg->Addr = cpu_to_le64(temp64); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 1660 | return 0; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | static void hpsa_unmap_sg_chain_block(struct ctlr_info *h, |
| 1664 | struct CommandList *c) |
| 1665 | { |
| 1666 | struct SGDescriptor *chain_sg; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1667 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1668 | if (le16_to_cpu(c->Header.SGTotal) <= h->max_cmd_sg_entries) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1669 | return; |
| 1670 | |
| 1671 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1672 | pci_unmap_single(h->pdev, le64_to_cpu(chain_sg->Addr), |
| 1673 | le32_to_cpu(chain_sg->Len), PCI_DMA_TODEVICE); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1674 | } |
| 1675 | |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1676 | |
| 1677 | /* Decode the various types of errors on ioaccel2 path. |
| 1678 | * Return 1 for any error that should generate a RAID path retry. |
| 1679 | * Return 0 for errors that don't require a RAID path retry. |
| 1680 | */ |
| 1681 | static int handle_ioaccel_mode2_error(struct ctlr_info *h, |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1682 | struct CommandList *c, |
| 1683 | struct scsi_cmnd *cmd, |
| 1684 | struct io_accel2_cmd *c2) |
| 1685 | { |
| 1686 | int data_len; |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1687 | int retry = 0; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1688 | |
| 1689 | switch (c2->error_data.serv_response) { |
| 1690 | case IOACCEL2_SERV_RESPONSE_COMPLETE: |
| 1691 | switch (c2->error_data.status) { |
| 1692 | case IOACCEL2_STATUS_SR_TASK_COMP_GOOD: |
| 1693 | break; |
| 1694 | case IOACCEL2_STATUS_SR_TASK_COMP_CHK_COND: |
| 1695 | dev_warn(&h->pdev->dev, |
| 1696 | "%s: task complete with check condition.\n", |
| 1697 | "HP SSD Smart Path"); |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 1698 | cmd->result |= SAM_STAT_CHECK_CONDITION; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1699 | if (c2->error_data.data_present != |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 1700 | IOACCEL2_SENSE_DATA_PRESENT) { |
| 1701 | memset(cmd->sense_buffer, 0, |
| 1702 | SCSI_SENSE_BUFFERSIZE); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1703 | break; |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 1704 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1705 | /* copy the sense data */ |
| 1706 | data_len = c2->error_data.sense_data_len; |
| 1707 | if (data_len > SCSI_SENSE_BUFFERSIZE) |
| 1708 | data_len = SCSI_SENSE_BUFFERSIZE; |
| 1709 | if (data_len > sizeof(c2->error_data.sense_data_buff)) |
| 1710 | data_len = |
| 1711 | sizeof(c2->error_data.sense_data_buff); |
| 1712 | memcpy(cmd->sense_buffer, |
| 1713 | c2->error_data.sense_data_buff, data_len); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1714 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1715 | break; |
| 1716 | case IOACCEL2_STATUS_SR_TASK_COMP_BUSY: |
| 1717 | dev_warn(&h->pdev->dev, |
| 1718 | "%s: task complete with BUSY status.\n", |
| 1719 | "HP SSD Smart Path"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1720 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1721 | break; |
| 1722 | case IOACCEL2_STATUS_SR_TASK_COMP_RES_CON: |
| 1723 | dev_warn(&h->pdev->dev, |
| 1724 | "%s: task complete with reservation conflict.\n", |
| 1725 | "HP SSD Smart Path"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1726 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1727 | break; |
| 1728 | case IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL: |
| 1729 | /* Make scsi midlayer do unlimited retries */ |
| 1730 | cmd->result = DID_IMM_RETRY << 16; |
| 1731 | break; |
| 1732 | case IOACCEL2_STATUS_SR_TASK_COMP_ABORTED: |
| 1733 | dev_warn(&h->pdev->dev, |
| 1734 | "%s: task complete with aborted status.\n", |
| 1735 | "HP SSD Smart Path"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1736 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1737 | break; |
| 1738 | default: |
| 1739 | dev_warn(&h->pdev->dev, |
| 1740 | "%s: task complete with unrecognized status: 0x%02x\n", |
| 1741 | "HP SSD Smart Path", c2->error_data.status); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1742 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1743 | break; |
| 1744 | } |
| 1745 | break; |
| 1746 | case IOACCEL2_SERV_RESPONSE_FAILURE: |
| 1747 | /* don't expect to get here. */ |
| 1748 | dev_warn(&h->pdev->dev, |
| 1749 | "unexpected delivery or target failure, status = 0x%02x\n", |
| 1750 | c2->error_data.status); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1751 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1752 | break; |
| 1753 | case IOACCEL2_SERV_RESPONSE_TMF_COMPLETE: |
| 1754 | break; |
| 1755 | case IOACCEL2_SERV_RESPONSE_TMF_SUCCESS: |
| 1756 | break; |
| 1757 | case IOACCEL2_SERV_RESPONSE_TMF_REJECTED: |
| 1758 | dev_warn(&h->pdev->dev, "task management function rejected.\n"); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1759 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1760 | break; |
| 1761 | case IOACCEL2_SERV_RESPONSE_TMF_WRONG_LUN: |
| 1762 | dev_warn(&h->pdev->dev, "task management function invalid LUN\n"); |
| 1763 | break; |
| 1764 | default: |
| 1765 | dev_warn(&h->pdev->dev, |
| 1766 | "%s: Unrecognized server response: 0x%02x\n", |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1767 | "HP SSD Smart Path", |
| 1768 | c2->error_data.serv_response); |
| 1769 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1770 | break; |
| 1771 | } |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 1772 | |
| 1773 | return retry; /* retry on raid path? */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | static void process_ioaccel2_completion(struct ctlr_info *h, |
| 1777 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 1778 | struct hpsa_scsi_dev_t *dev) |
| 1779 | { |
| 1780 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 1781 | |
| 1782 | /* check for good status */ |
| 1783 | if (likely(c2->error_data.serv_response == 0 && |
| 1784 | c2->error_data.status == 0)) { |
| 1785 | cmd_free(h, c); |
| 1786 | cmd->scsi_done(cmd); |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | /* Any RAID offload error results in retry which will use |
| 1791 | * the normal I/O path so the controller can handle whatever's |
| 1792 | * wrong. |
| 1793 | */ |
| 1794 | if (is_logical_dev_addr_mode(dev->scsi3addr) && |
| 1795 | c2->error_data.serv_response == |
| 1796 | IOACCEL2_SERV_RESPONSE_FAILURE) { |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 1797 | if (c2->error_data.status == |
| 1798 | IOACCEL2_STATUS_SR_IOACCEL_DISABLED) |
| 1799 | dev->offload_enabled = 0; |
| 1800 | goto retry_cmd; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1801 | } |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 1802 | |
| 1803 | if (handle_ioaccel_mode2_error(h, c, cmd, c2)) |
| 1804 | goto retry_cmd; |
| 1805 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1806 | cmd_free(h, c); |
| 1807 | cmd->scsi_done(cmd); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 1808 | return; |
| 1809 | |
| 1810 | retry_cmd: |
| 1811 | INIT_WORK(&c->work, hpsa_command_resubmit_worker); |
| 1812 | queue_work_on(raw_smp_processor_id(), h->resubmit_wq, &c->work); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1813 | } |
| 1814 | |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 1815 | static void complete_scsi_command(struct CommandList *cp) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1816 | { |
| 1817 | struct scsi_cmnd *cmd; |
| 1818 | struct ctlr_info *h; |
| 1819 | struct ErrorInfo *ei; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1820 | struct hpsa_scsi_dev_t *dev; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1821 | |
| 1822 | unsigned char sense_key; |
| 1823 | unsigned char asc; /* additional sense code */ |
| 1824 | unsigned char ascq; /* additional sense code qualifier */ |
Stephen M. Cameron | db111e1 | 2011-06-03 09:57:34 -0500 | [diff] [blame] | 1825 | unsigned long sense_data_size; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1826 | |
| 1827 | ei = cp->err_info; |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 1828 | cmd = cp->scsi_cmd; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1829 | h = cp->h; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1830 | dev = cmd->device->hostdata; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1831 | |
| 1832 | scsi_dma_unmap(cmd); /* undo the DMA mappings */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1833 | if ((cp->cmd_type == CMD_SCSI) && |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 1834 | (le16_to_cpu(cp->Header.SGTotal) > h->max_cmd_sg_entries)) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1835 | hpsa_unmap_sg_chain_block(h, cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1836 | |
| 1837 | cmd->result = (DID_OK << 16); /* host byte */ |
| 1838 | cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1839 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1840 | if (cp->cmd_type == CMD_IOACCEL2 || cp->cmd_type == CMD_IOACCEL1) |
| 1841 | atomic_dec(&cp->phys_disk->ioaccel_cmds_out); |
| 1842 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1843 | if (cp->cmd_type == CMD_IOACCEL2) |
| 1844 | return process_ioaccel2_completion(h, cp, cmd, dev); |
| 1845 | |
Stephen M. Cameron | 5512672 | 2010-02-25 14:03:01 -0600 | [diff] [blame] | 1846 | cmd->result |= ei->ScsiStatus; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1847 | |
Robert Elliott | 6aa4c36 | 2014-07-03 10:18:19 -0500 | [diff] [blame] | 1848 | scsi_set_resid(cmd, ei->ResidualCnt); |
| 1849 | if (ei->CommandStatus == 0) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1850 | if (cp->cmd_type == CMD_IOACCEL1) |
| 1851 | atomic_dec(&cp->phys_disk->ioaccel_cmds_out); |
Robert Elliott | 6aa4c36 | 2014-07-03 10:18:19 -0500 | [diff] [blame] | 1852 | cmd_free(h, cp); |
| 1853 | cmd->scsi_done(cmd); |
| 1854 | return; |
| 1855 | } |
| 1856 | |
| 1857 | /* copy the sense data */ |
Stephen M. Cameron | db111e1 | 2011-06-03 09:57:34 -0500 | [diff] [blame] | 1858 | if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo)) |
| 1859 | sense_data_size = SCSI_SENSE_BUFFERSIZE; |
| 1860 | else |
| 1861 | sense_data_size = sizeof(ei->SenseInfo); |
| 1862 | if (ei->SenseLen < sense_data_size) |
| 1863 | sense_data_size = ei->SenseLen; |
| 1864 | |
| 1865 | memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1866 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1867 | /* For I/O accelerator commands, copy over some fields to the normal |
| 1868 | * CISS header used below for error handling. |
| 1869 | */ |
| 1870 | if (cp->cmd_type == CMD_IOACCEL1) { |
| 1871 | struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex]; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 1872 | cp->Header.SGList = scsi_sg_count(cmd); |
| 1873 | cp->Header.SGTotal = cpu_to_le16(cp->Header.SGList); |
| 1874 | cp->Request.CDBLen = le16_to_cpu(c->io_flags) & |
| 1875 | IOACCEL1_IOFLAGS_CDBLEN_MASK; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 1876 | cp->Header.tag = c->tag; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1877 | memcpy(cp->Header.LUN.LunAddrBytes, c->CISS_LUN, 8); |
| 1878 | memcpy(cp->Request.CDB, c->CDB, cp->Request.CDBLen); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1879 | |
| 1880 | /* Any RAID offload error results in retry which will use |
| 1881 | * the normal I/O path so the controller can handle whatever's |
| 1882 | * wrong. |
| 1883 | */ |
| 1884 | if (is_logical_dev_addr_mode(dev->scsi3addr)) { |
| 1885 | if (ei->CommandStatus == CMD_IOACCEL_DISABLED) |
| 1886 | dev->offload_enabled = 0; |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 1887 | INIT_WORK(&cp->work, hpsa_command_resubmit_worker); |
| 1888 | queue_work_on(raw_smp_processor_id(), |
| 1889 | h->resubmit_wq, &cp->work); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 1890 | return; |
| 1891 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 1892 | } |
| 1893 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1894 | /* an error has occurred */ |
| 1895 | switch (ei->CommandStatus) { |
| 1896 | |
| 1897 | case CMD_TARGET_STATUS: |
| 1898 | if (ei->ScsiStatus) { |
| 1899 | /* Get sense key */ |
| 1900 | sense_key = 0xf & ei->SenseInfo[2]; |
| 1901 | /* Get additional sense code */ |
| 1902 | asc = ei->SenseInfo[12]; |
| 1903 | /* Get addition sense code qualifier */ |
| 1904 | ascq = ei->SenseInfo[13]; |
| 1905 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1906 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) { |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 1907 | if (sense_key == ABORTED_COMMAND) { |
Stephen M. Cameron | 2e311fb | 2013-09-23 13:33:41 -0500 | [diff] [blame] | 1908 | cmd->result |= DID_SOFT_ERROR << 16; |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 1909 | break; |
| 1910 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1911 | break; |
| 1912 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1913 | /* Problem was not a check condition |
| 1914 | * Pass it up to the upper layers... |
| 1915 | */ |
| 1916 | if (ei->ScsiStatus) { |
| 1917 | dev_warn(&h->pdev->dev, "cp %p has status 0x%x " |
| 1918 | "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " |
| 1919 | "Returning result: 0x%x\n", |
| 1920 | cp, ei->ScsiStatus, |
| 1921 | sense_key, asc, ascq, |
| 1922 | cmd->result); |
| 1923 | } else { /* scsi status is zero??? How??? */ |
| 1924 | dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. " |
| 1925 | "Returning no connection.\n", cp), |
| 1926 | |
| 1927 | /* Ordinarily, this case should never happen, |
| 1928 | * but there is a bug in some released firmware |
| 1929 | * revisions that allows it to happen if, for |
| 1930 | * example, a 4100 backplane loses power and |
| 1931 | * the tape drive is in it. We assume that |
| 1932 | * it's a fatal error of some kind because we |
| 1933 | * can't show that it wasn't. We will make it |
| 1934 | * look like selection timeout since that is |
| 1935 | * the most common reason for this to occur, |
| 1936 | * and it's severe enough. |
| 1937 | */ |
| 1938 | |
| 1939 | cmd->result = DID_NO_CONNECT << 16; |
| 1940 | } |
| 1941 | break; |
| 1942 | |
| 1943 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
| 1944 | break; |
| 1945 | case CMD_DATA_OVERRUN: |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1946 | dev_warn(&h->pdev->dev, |
| 1947 | "CDB %16phN data overrun\n", cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1948 | break; |
| 1949 | case CMD_INVALID: { |
| 1950 | /* print_bytes(cp, sizeof(*cp), 1, 0); |
| 1951 | print_cmd(cp); */ |
| 1952 | /* We get CMD_INVALID if you address a non-existent device |
| 1953 | * instead of a selection timeout (no response). You will |
| 1954 | * see this if you yank out a drive, then try to access it. |
| 1955 | * This is kind of a shame because it means that any other |
| 1956 | * CMD_INVALID (e.g. driver bug) will get interpreted as a |
| 1957 | * missing target. */ |
| 1958 | cmd->result = DID_NO_CONNECT << 16; |
| 1959 | } |
| 1960 | break; |
| 1961 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | 256d0ea | 2012-09-14 16:34:25 -0500 | [diff] [blame] | 1962 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1963 | dev_warn(&h->pdev->dev, "CDB %16phN : protocol error\n", |
| 1964 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1965 | break; |
| 1966 | case CMD_HARDWARE_ERR: |
| 1967 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1968 | dev_warn(&h->pdev->dev, "CDB %16phN : hardware error\n", |
| 1969 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1970 | break; |
| 1971 | case CMD_CONNECTION_LOST: |
| 1972 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1973 | dev_warn(&h->pdev->dev, "CDB %16phN : connection lost\n", |
| 1974 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1975 | break; |
| 1976 | case CMD_ABORTED: |
| 1977 | cmd->result = DID_ABORT << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1978 | dev_warn(&h->pdev->dev, "CDB %16phN was aborted with status 0x%x\n", |
| 1979 | cp->Request.CDB, ei->ScsiStatus); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1980 | break; |
| 1981 | case CMD_ABORT_FAILED: |
| 1982 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1983 | dev_warn(&h->pdev->dev, "CDB %16phN : abort failed\n", |
| 1984 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1985 | break; |
| 1986 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | f6e7605 | 2011-07-26 11:08:52 -0500 | [diff] [blame] | 1987 | cmd->result = DID_SOFT_ERROR << 16; /* retry the command */ |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1988 | dev_warn(&h->pdev->dev, "CDB %16phN : unsolicited abort\n", |
| 1989 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1990 | break; |
| 1991 | case CMD_TIMEOUT: |
| 1992 | cmd->result = DID_TIME_OUT << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 1993 | dev_warn(&h->pdev->dev, "CDB %16phN timed out\n", |
| 1994 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1995 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 1996 | case CMD_UNABORTABLE: |
| 1997 | cmd->result = DID_ERROR << 16; |
| 1998 | dev_warn(&h->pdev->dev, "Command unabortable\n"); |
| 1999 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2000 | case CMD_IOACCEL_DISABLED: |
| 2001 | /* This only handles the direct pass-through case since RAID |
| 2002 | * offload is handled above. Just attempt a retry. |
| 2003 | */ |
| 2004 | cmd->result = DID_SOFT_ERROR << 16; |
| 2005 | dev_warn(&h->pdev->dev, |
| 2006 | "cp %p had HP SSD Smart Path error\n", cp); |
| 2007 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2008 | default: |
| 2009 | cmd->result = DID_ERROR << 16; |
| 2010 | dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n", |
| 2011 | cp, ei->CommandStatus); |
| 2012 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2013 | cmd_free(h, cp); |
Tomas Henzl | 2cc5bfa | 2013-08-01 15:14:00 +0200 | [diff] [blame] | 2014 | cmd->scsi_done(cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2015 | } |
| 2016 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2017 | static void hpsa_pci_unmap(struct pci_dev *pdev, |
| 2018 | struct CommandList *c, int sg_used, int data_direction) |
| 2019 | { |
| 2020 | int i; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2021 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2022 | for (i = 0; i < sg_used; i++) |
| 2023 | pci_unmap_single(pdev, (dma_addr_t) le64_to_cpu(c->SG[i].Addr), |
| 2024 | le32_to_cpu(c->SG[i].Len), |
| 2025 | data_direction); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2026 | } |
| 2027 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2028 | static int hpsa_map_one(struct pci_dev *pdev, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2029 | struct CommandList *cp, |
| 2030 | unsigned char *buf, |
| 2031 | size_t buflen, |
| 2032 | int data_direction) |
| 2033 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2034 | u64 addr64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2035 | |
| 2036 | if (buflen == 0 || data_direction == PCI_DMA_NONE) { |
| 2037 | cp->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2038 | cp->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2039 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2040 | } |
| 2041 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2042 | addr64 = pci_map_single(pdev, buf, buflen, data_direction); |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2043 | if (dma_mapping_error(&pdev->dev, addr64)) { |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2044 | /* Prevent subsequent unmap of something never mapped */ |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2045 | cp->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2046 | cp->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2047 | return -1; |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2048 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2049 | cp->SG[0].Addr = cpu_to_le64(addr64); |
| 2050 | cp->SG[0].Len = cpu_to_le32(buflen); |
| 2051 | cp->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* we are not chaining */ |
| 2052 | cp->Header.SGList = 1; /* no. SGs contig in this cmd */ |
| 2053 | cp->Header.SGTotal = cpu_to_le16(1); /* total sgs in cmd list */ |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2054 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h, |
| 2058 | struct CommandList *c) |
| 2059 | { |
| 2060 | DECLARE_COMPLETION_ONSTACK(wait); |
| 2061 | |
| 2062 | c->waiting = &wait; |
| 2063 | enqueue_cmd_and_start_io(h, c); |
| 2064 | wait_for_completion(&wait); |
| 2065 | } |
| 2066 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 2067 | static u32 lockup_detected(struct ctlr_info *h) |
| 2068 | { |
| 2069 | int cpu; |
| 2070 | u32 rc, *lockup_detected; |
| 2071 | |
| 2072 | cpu = get_cpu(); |
| 2073 | lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); |
| 2074 | rc = *lockup_detected; |
| 2075 | put_cpu(); |
| 2076 | return rc; |
| 2077 | } |
| 2078 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 2079 | static void hpsa_scsi_do_simple_cmd_core_if_no_lockup(struct ctlr_info *h, |
| 2080 | struct CommandList *c) |
| 2081 | { |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 2082 | /* If controller lockup detected, fake a hardware error. */ |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 2083 | if (unlikely(lockup_detected(h))) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 2084 | c->err_info->CommandStatus = CMD_HARDWARE_ERR; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 2085 | else |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 2086 | hpsa_scsi_do_simple_cmd_core(h, c); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 2087 | } |
| 2088 | |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2089 | #define MAX_DRIVER_CMD_RETRIES 25 |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2090 | static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, |
| 2091 | struct CommandList *c, int data_direction) |
| 2092 | { |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2093 | int backoff_time = 10, retry_count = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2094 | |
| 2095 | do { |
Joe Perches | 7630abd | 2011-05-08 23:32:40 -0700 | [diff] [blame] | 2096 | memset(c->err_info, 0, sizeof(*c->err_info)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2097 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 2098 | retry_count++; |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2099 | if (retry_count > 3) { |
| 2100 | msleep(backoff_time); |
| 2101 | if (backoff_time < 1000) |
| 2102 | backoff_time *= 2; |
| 2103 | } |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 2104 | } while ((check_for_unit_attention(h, c) || |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2105 | check_for_busy(h, c)) && |
| 2106 | retry_count <= MAX_DRIVER_CMD_RETRIES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2107 | hpsa_pci_unmap(h->pdev, c, 1, data_direction); |
| 2108 | } |
| 2109 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2110 | static void hpsa_print_cmd(struct ctlr_info *h, char *txt, |
| 2111 | struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2112 | { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2113 | const u8 *cdb = c->Request.CDB; |
| 2114 | const u8 *lun = c->Header.LUN.LunAddrBytes; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2115 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2116 | dev_warn(&h->pdev->dev, "%s: LUN:%02x%02x%02x%02x%02x%02x%02x%02x" |
| 2117 | " CDB:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 2118 | txt, lun[0], lun[1], lun[2], lun[3], |
| 2119 | lun[4], lun[5], lun[6], lun[7], |
| 2120 | cdb[0], cdb[1], cdb[2], cdb[3], |
| 2121 | cdb[4], cdb[5], cdb[6], cdb[7], |
| 2122 | cdb[8], cdb[9], cdb[10], cdb[11], |
| 2123 | cdb[12], cdb[13], cdb[14], cdb[15]); |
| 2124 | } |
| 2125 | |
| 2126 | static void hpsa_scsi_interpret_error(struct ctlr_info *h, |
| 2127 | struct CommandList *cp) |
| 2128 | { |
| 2129 | const struct ErrorInfo *ei = cp->err_info; |
| 2130 | struct device *d = &cp->h->pdev->dev; |
| 2131 | const u8 *sd = ei->SenseInfo; |
| 2132 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2133 | switch (ei->CommandStatus) { |
| 2134 | case CMD_TARGET_STATUS: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2135 | hpsa_print_cmd(h, "SCSI status", cp); |
| 2136 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) |
| 2137 | dev_warn(d, "SCSI Status = 02, Sense key = %02x, ASC = %02x, ASCQ = %02x\n", |
| 2138 | sd[2] & 0x0f, sd[12], sd[13]); |
| 2139 | else |
| 2140 | dev_warn(d, "SCSI Status = %02x\n", ei->ScsiStatus); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2141 | if (ei->ScsiStatus == 0) |
| 2142 | dev_warn(d, "SCSI status is abnormally zero. " |
| 2143 | "(probably indicates selection timeout " |
| 2144 | "reported incorrectly due to a known " |
| 2145 | "firmware bug, circa July, 2001.)\n"); |
| 2146 | break; |
| 2147 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2148 | break; |
| 2149 | case CMD_DATA_OVERRUN: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2150 | hpsa_print_cmd(h, "overrun condition", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2151 | break; |
| 2152 | case CMD_INVALID: { |
| 2153 | /* controller unfortunately reports SCSI passthru's |
| 2154 | * to non-existent targets as invalid commands. |
| 2155 | */ |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2156 | hpsa_print_cmd(h, "invalid command", cp); |
| 2157 | dev_warn(d, "probably means device no longer present\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2158 | } |
| 2159 | break; |
| 2160 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2161 | hpsa_print_cmd(h, "protocol error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2162 | break; |
| 2163 | case CMD_HARDWARE_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2164 | hpsa_print_cmd(h, "hardware error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2165 | break; |
| 2166 | case CMD_CONNECTION_LOST: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2167 | hpsa_print_cmd(h, "connection lost", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2168 | break; |
| 2169 | case CMD_ABORTED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2170 | hpsa_print_cmd(h, "aborted", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2171 | break; |
| 2172 | case CMD_ABORT_FAILED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2173 | hpsa_print_cmd(h, "abort failed", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2174 | break; |
| 2175 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2176 | hpsa_print_cmd(h, "unsolicited abort", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2177 | break; |
| 2178 | case CMD_TIMEOUT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2179 | hpsa_print_cmd(h, "timed out", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2180 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2181 | case CMD_UNABORTABLE: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2182 | hpsa_print_cmd(h, "unabortable", cp); |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2183 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2184 | default: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2185 | hpsa_print_cmd(h, "unknown status", cp); |
| 2186 | dev_warn(d, "Unknown command status %x\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2187 | ei->CommandStatus); |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | 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] | 2192 | u16 page, unsigned char *buf, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2193 | unsigned char bufsize) |
| 2194 | { |
| 2195 | int rc = IO_OK; |
| 2196 | struct CommandList *c; |
| 2197 | struct ErrorInfo *ei; |
| 2198 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2199 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2200 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 2201 | if (c == NULL) { |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2202 | dev_warn(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 2203 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2206 | if (fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize, |
| 2207 | page, scsi3addr, TYPE_CMD)) { |
| 2208 | rc = -1; |
| 2209 | goto out; |
| 2210 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2211 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2212 | ei = c->err_info; |
| 2213 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2214 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2215 | rc = -1; |
| 2216 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2217 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2218 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2219 | return rc; |
| 2220 | } |
| 2221 | |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 2222 | static int hpsa_bmic_ctrl_mode_sense(struct ctlr_info *h, |
| 2223 | unsigned char *scsi3addr, unsigned char page, |
| 2224 | struct bmic_controller_parameters *buf, size_t bufsize) |
| 2225 | { |
| 2226 | int rc = IO_OK; |
| 2227 | struct CommandList *c; |
| 2228 | struct ErrorInfo *ei; |
| 2229 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2230 | c = cmd_alloc(h); |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 2231 | if (c == NULL) { /* trouble... */ |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2232 | dev_warn(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 2233 | return -ENOMEM; |
| 2234 | } |
| 2235 | |
| 2236 | if (fill_cmd(c, BMIC_SENSE_CONTROLLER_PARAMETERS, h, buf, bufsize, |
| 2237 | page, scsi3addr, TYPE_CMD)) { |
| 2238 | rc = -1; |
| 2239 | goto out; |
| 2240 | } |
| 2241 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2242 | ei = c->err_info; |
| 2243 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 2244 | hpsa_scsi_interpret_error(h, c); |
| 2245 | rc = -1; |
| 2246 | } |
| 2247 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2248 | cmd_free(h, c); |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 2249 | return rc; |
| 2250 | } |
| 2251 | |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2252 | static int hpsa_send_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
| 2253 | u8 reset_type) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2254 | { |
| 2255 | int rc = IO_OK; |
| 2256 | struct CommandList *c; |
| 2257 | struct ErrorInfo *ei; |
| 2258 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2259 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2260 | |
| 2261 | if (c == NULL) { /* trouble... */ |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2262 | dev_warn(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | e9ea04a | 2010-02-25 14:03:06 -0600 | [diff] [blame] | 2263 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2264 | } |
| 2265 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2266 | /* fill_cmd can't fail here, no data buffer to map. */ |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2267 | (void) fill_cmd(c, HPSA_DEVICE_RESET_MSG, h, NULL, 0, 0, |
| 2268 | scsi3addr, TYPE_MSG); |
| 2269 | 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] | 2270 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 2271 | /* no unmap needed here because no data xfer. */ |
| 2272 | |
| 2273 | ei = c->err_info; |
| 2274 | if (ei->CommandStatus != 0) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2275 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2276 | rc = -1; |
| 2277 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2278 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2279 | return rc; |
| 2280 | } |
| 2281 | |
| 2282 | static void hpsa_get_raid_level(struct ctlr_info *h, |
| 2283 | unsigned char *scsi3addr, unsigned char *raid_level) |
| 2284 | { |
| 2285 | int rc; |
| 2286 | unsigned char *buf; |
| 2287 | |
| 2288 | *raid_level = RAID_UNKNOWN; |
| 2289 | buf = kzalloc(64, GFP_KERNEL); |
| 2290 | if (!buf) |
| 2291 | return; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2292 | 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] | 2293 | if (rc == 0) |
| 2294 | *raid_level = buf[8]; |
| 2295 | if (*raid_level > RAID_UNKNOWN) |
| 2296 | *raid_level = RAID_UNKNOWN; |
| 2297 | kfree(buf); |
| 2298 | return; |
| 2299 | } |
| 2300 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2301 | #define HPSA_MAP_DEBUG |
| 2302 | #ifdef HPSA_MAP_DEBUG |
| 2303 | static void hpsa_debug_map_buff(struct ctlr_info *h, int rc, |
| 2304 | struct raid_map_data *map_buff) |
| 2305 | { |
| 2306 | struct raid_map_disk_data *dd = &map_buff->data[0]; |
| 2307 | int map, row, col; |
| 2308 | u16 map_cnt, row_cnt, disks_per_row; |
| 2309 | |
| 2310 | if (rc != 0) |
| 2311 | return; |
| 2312 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 2313 | /* Show details only if debugging has been activated. */ |
| 2314 | if (h->raid_offload_debug < 2) |
| 2315 | return; |
| 2316 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2317 | dev_info(&h->pdev->dev, "structure_size = %u\n", |
| 2318 | le32_to_cpu(map_buff->structure_size)); |
| 2319 | dev_info(&h->pdev->dev, "volume_blk_size = %u\n", |
| 2320 | le32_to_cpu(map_buff->volume_blk_size)); |
| 2321 | dev_info(&h->pdev->dev, "volume_blk_cnt = 0x%llx\n", |
| 2322 | le64_to_cpu(map_buff->volume_blk_cnt)); |
| 2323 | dev_info(&h->pdev->dev, "physicalBlockShift = %u\n", |
| 2324 | map_buff->phys_blk_shift); |
| 2325 | dev_info(&h->pdev->dev, "parity_rotation_shift = %u\n", |
| 2326 | map_buff->parity_rotation_shift); |
| 2327 | dev_info(&h->pdev->dev, "strip_size = %u\n", |
| 2328 | le16_to_cpu(map_buff->strip_size)); |
| 2329 | dev_info(&h->pdev->dev, "disk_starting_blk = 0x%llx\n", |
| 2330 | le64_to_cpu(map_buff->disk_starting_blk)); |
| 2331 | dev_info(&h->pdev->dev, "disk_blk_cnt = 0x%llx\n", |
| 2332 | le64_to_cpu(map_buff->disk_blk_cnt)); |
| 2333 | dev_info(&h->pdev->dev, "data_disks_per_row = %u\n", |
| 2334 | le16_to_cpu(map_buff->data_disks_per_row)); |
| 2335 | dev_info(&h->pdev->dev, "metadata_disks_per_row = %u\n", |
| 2336 | le16_to_cpu(map_buff->metadata_disks_per_row)); |
| 2337 | dev_info(&h->pdev->dev, "row_cnt = %u\n", |
| 2338 | le16_to_cpu(map_buff->row_cnt)); |
| 2339 | dev_info(&h->pdev->dev, "layout_map_count = %u\n", |
| 2340 | le16_to_cpu(map_buff->layout_map_count)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2341 | dev_info(&h->pdev->dev, "flags = 0x%x\n", |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 2342 | le16_to_cpu(map_buff->flags)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2343 | dev_info(&h->pdev->dev, "encrypytion = %s\n", |
| 2344 | le16_to_cpu(map_buff->flags) & |
| 2345 | RAID_MAP_FLAG_ENCRYPT_ON ? "ON" : "OFF"); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 2346 | dev_info(&h->pdev->dev, "dekindex = %u\n", |
| 2347 | le16_to_cpu(map_buff->dekindex)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2348 | map_cnt = le16_to_cpu(map_buff->layout_map_count); |
| 2349 | for (map = 0; map < map_cnt; map++) { |
| 2350 | dev_info(&h->pdev->dev, "Map%u:\n", map); |
| 2351 | row_cnt = le16_to_cpu(map_buff->row_cnt); |
| 2352 | for (row = 0; row < row_cnt; row++) { |
| 2353 | dev_info(&h->pdev->dev, " Row%u:\n", row); |
| 2354 | disks_per_row = |
| 2355 | le16_to_cpu(map_buff->data_disks_per_row); |
| 2356 | for (col = 0; col < disks_per_row; col++, dd++) |
| 2357 | dev_info(&h->pdev->dev, |
| 2358 | " D%02u: h=0x%04x xor=%u,%u\n", |
| 2359 | col, dd->ioaccel_handle, |
| 2360 | dd->xor_mult[0], dd->xor_mult[1]); |
| 2361 | disks_per_row = |
| 2362 | le16_to_cpu(map_buff->metadata_disks_per_row); |
| 2363 | for (col = 0; col < disks_per_row; col++, dd++) |
| 2364 | dev_info(&h->pdev->dev, |
| 2365 | " M%02u: h=0x%04x xor=%u,%u\n", |
| 2366 | col, dd->ioaccel_handle, |
| 2367 | dd->xor_mult[0], dd->xor_mult[1]); |
| 2368 | } |
| 2369 | } |
| 2370 | } |
| 2371 | #else |
| 2372 | static void hpsa_debug_map_buff(__attribute__((unused)) struct ctlr_info *h, |
| 2373 | __attribute__((unused)) int rc, |
| 2374 | __attribute__((unused)) struct raid_map_data *map_buff) |
| 2375 | { |
| 2376 | } |
| 2377 | #endif |
| 2378 | |
| 2379 | static int hpsa_get_raid_map(struct ctlr_info *h, |
| 2380 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 2381 | { |
| 2382 | int rc = 0; |
| 2383 | struct CommandList *c; |
| 2384 | struct ErrorInfo *ei; |
| 2385 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2386 | c = cmd_alloc(h); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2387 | if (c == NULL) { |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2388 | dev_warn(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2389 | return -ENOMEM; |
| 2390 | } |
| 2391 | if (fill_cmd(c, HPSA_GET_RAID_MAP, h, &this_device->raid_map, |
| 2392 | sizeof(this_device->raid_map), 0, |
| 2393 | scsi3addr, TYPE_CMD)) { |
| 2394 | dev_warn(&h->pdev->dev, "Out of memory in hpsa_get_raid_map()\n"); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2395 | cmd_free(h, c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2396 | return -ENOMEM; |
| 2397 | } |
| 2398 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2399 | ei = c->err_info; |
| 2400 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2401 | hpsa_scsi_interpret_error(h, c); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2402 | cmd_free(h, c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2403 | return -1; |
| 2404 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2405 | cmd_free(h, c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2406 | |
| 2407 | /* @todo in the future, dynamically allocate RAID map memory */ |
| 2408 | if (le32_to_cpu(this_device->raid_map.structure_size) > |
| 2409 | sizeof(this_device->raid_map)) { |
| 2410 | dev_warn(&h->pdev->dev, "RAID map size is too large!\n"); |
| 2411 | rc = -1; |
| 2412 | } |
| 2413 | hpsa_debug_map_buff(h, rc, &this_device->raid_map); |
| 2414 | return rc; |
| 2415 | } |
| 2416 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2417 | static int hpsa_bmic_id_physical_device(struct ctlr_info *h, |
| 2418 | unsigned char scsi3addr[], u16 bmic_device_index, |
| 2419 | struct bmic_identify_physical_device *buf, size_t bufsize) |
| 2420 | { |
| 2421 | int rc = IO_OK; |
| 2422 | struct CommandList *c; |
| 2423 | struct ErrorInfo *ei; |
| 2424 | |
| 2425 | c = cmd_alloc(h); |
| 2426 | rc = fill_cmd(c, BMIC_IDENTIFY_PHYSICAL_DEVICE, h, buf, bufsize, |
| 2427 | 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 2428 | if (rc) |
| 2429 | goto out; |
| 2430 | |
| 2431 | c->Request.CDB[2] = bmic_device_index & 0xff; |
| 2432 | c->Request.CDB[9] = (bmic_device_index >> 8) & 0xff; |
| 2433 | |
| 2434 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2435 | ei = c->err_info; |
| 2436 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 2437 | hpsa_scsi_interpret_error(h, c); |
| 2438 | rc = -1; |
| 2439 | } |
| 2440 | out: |
| 2441 | cmd_free(h, c); |
| 2442 | return rc; |
| 2443 | } |
| 2444 | |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 2445 | static int hpsa_vpd_page_supported(struct ctlr_info *h, |
| 2446 | unsigned char scsi3addr[], u8 page) |
| 2447 | { |
| 2448 | int rc; |
| 2449 | int i; |
| 2450 | int pages; |
| 2451 | unsigned char *buf, bufsize; |
| 2452 | |
| 2453 | buf = kzalloc(256, GFP_KERNEL); |
| 2454 | if (!buf) |
| 2455 | return 0; |
| 2456 | |
| 2457 | /* Get the size of the page list first */ |
| 2458 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 2459 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 2460 | buf, HPSA_VPD_HEADER_SZ); |
| 2461 | if (rc != 0) |
| 2462 | goto exit_unsupported; |
| 2463 | pages = buf[3]; |
| 2464 | if ((pages + HPSA_VPD_HEADER_SZ) <= 255) |
| 2465 | bufsize = pages + HPSA_VPD_HEADER_SZ; |
| 2466 | else |
| 2467 | bufsize = 255; |
| 2468 | |
| 2469 | /* Get the whole VPD page list */ |
| 2470 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 2471 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 2472 | buf, bufsize); |
| 2473 | if (rc != 0) |
| 2474 | goto exit_unsupported; |
| 2475 | |
| 2476 | pages = buf[3]; |
| 2477 | for (i = 1; i <= pages; i++) |
| 2478 | if (buf[3 + i] == page) |
| 2479 | goto exit_supported; |
| 2480 | exit_unsupported: |
| 2481 | kfree(buf); |
| 2482 | return 0; |
| 2483 | exit_supported: |
| 2484 | kfree(buf); |
| 2485 | return 1; |
| 2486 | } |
| 2487 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2488 | static void hpsa_get_ioaccel_status(struct ctlr_info *h, |
| 2489 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 2490 | { |
| 2491 | int rc; |
| 2492 | unsigned char *buf; |
| 2493 | u8 ioaccel_status; |
| 2494 | |
| 2495 | this_device->offload_config = 0; |
| 2496 | this_device->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 2497 | this_device->offload_to_be_enabled = 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2498 | |
| 2499 | buf = kzalloc(64, GFP_KERNEL); |
| 2500 | if (!buf) |
| 2501 | return; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 2502 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_IOACCEL_STATUS)) |
| 2503 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2504 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2505 | VPD_PAGE | HPSA_VPD_LV_IOACCEL_STATUS, buf, 64); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2506 | if (rc != 0) |
| 2507 | goto out; |
| 2508 | |
| 2509 | #define IOACCEL_STATUS_BYTE 4 |
| 2510 | #define OFFLOAD_CONFIGURED_BIT 0x01 |
| 2511 | #define OFFLOAD_ENABLED_BIT 0x02 |
| 2512 | ioaccel_status = buf[IOACCEL_STATUS_BYTE]; |
| 2513 | this_device->offload_config = |
| 2514 | !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT); |
| 2515 | if (this_device->offload_config) { |
| 2516 | this_device->offload_enabled = |
| 2517 | !!(ioaccel_status & OFFLOAD_ENABLED_BIT); |
| 2518 | if (hpsa_get_raid_map(h, scsi3addr, this_device)) |
| 2519 | this_device->offload_enabled = 0; |
| 2520 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 2521 | this_device->offload_to_be_enabled = this_device->offload_enabled; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2522 | out: |
| 2523 | kfree(buf); |
| 2524 | return; |
| 2525 | } |
| 2526 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2527 | /* Get the device id from inquiry page 0x83 */ |
| 2528 | static int hpsa_get_device_id(struct ctlr_info *h, unsigned char *scsi3addr, |
| 2529 | unsigned char *device_id, int buflen) |
| 2530 | { |
| 2531 | int rc; |
| 2532 | unsigned char *buf; |
| 2533 | |
| 2534 | if (buflen > 16) |
| 2535 | buflen = 16; |
| 2536 | buf = kzalloc(64, GFP_KERNEL); |
| 2537 | if (!buf) |
Stephen M. Cameron | a84d794 | 2014-05-29 10:54:20 -0500 | [diff] [blame] | 2538 | return -ENOMEM; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2539 | 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] | 2540 | if (rc == 0) |
| 2541 | memcpy(device_id, &buf[8], buflen); |
| 2542 | kfree(buf); |
| 2543 | return rc != 0; |
| 2544 | } |
| 2545 | |
| 2546 | static int hpsa_scsi_do_report_luns(struct ctlr_info *h, int logical, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2547 | void *buf, int bufsize, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2548 | int extended_response) |
| 2549 | { |
| 2550 | int rc = IO_OK; |
| 2551 | struct CommandList *c; |
| 2552 | unsigned char scsi3addr[8]; |
| 2553 | struct ErrorInfo *ei; |
| 2554 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2555 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2556 | if (c == NULL) { /* trouble... */ |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2557 | dev_err(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2558 | return -1; |
| 2559 | } |
Stephen M. Cameron | e89c0ae | 2010-02-04 08:42:04 -0600 | [diff] [blame] | 2560 | /* address the controller */ |
| 2561 | memset(scsi3addr, 0, sizeof(scsi3addr)); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2562 | if (fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h, |
| 2563 | buf, bufsize, 0, scsi3addr, TYPE_CMD)) { |
| 2564 | rc = -1; |
| 2565 | goto out; |
| 2566 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2567 | if (extended_response) |
| 2568 | c->Request.CDB[1] = extended_response; |
| 2569 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE); |
| 2570 | ei = c->err_info; |
| 2571 | if (ei->CommandStatus != 0 && |
| 2572 | ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2573 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2574 | rc = -1; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2575 | } else { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2576 | struct ReportLUNdata *rld = buf; |
| 2577 | |
| 2578 | if (rld->extended_response_flag != extended_response) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2579 | dev_err(&h->pdev->dev, |
| 2580 | "report luns requested format %u, got %u\n", |
| 2581 | extended_response, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2582 | rld->extended_response_flag); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2583 | rc = -1; |
| 2584 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2585 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2586 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2587 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2588 | return rc; |
| 2589 | } |
| 2590 | |
| 2591 | static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info *h, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2592 | struct ReportExtendedLUNdata *buf, int bufsize) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2593 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2594 | return hpsa_scsi_do_report_luns(h, 0, buf, bufsize, |
| 2595 | HPSA_REPORT_PHYS_EXTENDED); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | static inline int hpsa_scsi_do_report_log_luns(struct ctlr_info *h, |
| 2599 | struct ReportLUNdata *buf, int bufsize) |
| 2600 | { |
| 2601 | return hpsa_scsi_do_report_luns(h, 1, buf, bufsize, 0); |
| 2602 | } |
| 2603 | |
| 2604 | static inline void hpsa_set_bus_target_lun(struct hpsa_scsi_dev_t *device, |
| 2605 | int bus, int target, int lun) |
| 2606 | { |
| 2607 | device->bus = bus; |
| 2608 | device->target = target; |
| 2609 | device->lun = lun; |
| 2610 | } |
| 2611 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2612 | /* Use VPD inquiry to get details of volume status */ |
| 2613 | static int hpsa_get_volume_status(struct ctlr_info *h, |
| 2614 | unsigned char scsi3addr[]) |
| 2615 | { |
| 2616 | int rc; |
| 2617 | int status; |
| 2618 | int size; |
| 2619 | unsigned char *buf; |
| 2620 | |
| 2621 | buf = kzalloc(64, GFP_KERNEL); |
| 2622 | if (!buf) |
| 2623 | return HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 2624 | |
| 2625 | /* Does controller have VPD for logical volume status? */ |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 2626 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_STATUS)) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2627 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2628 | |
| 2629 | /* Get the size of the VPD return buffer */ |
| 2630 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS, |
| 2631 | buf, HPSA_VPD_HEADER_SZ); |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 2632 | if (rc != 0) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2633 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2634 | size = buf[3]; |
| 2635 | |
| 2636 | /* Now get the whole VPD buffer */ |
| 2637 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS, |
| 2638 | buf, size + HPSA_VPD_HEADER_SZ); |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 2639 | if (rc != 0) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2640 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2641 | status = buf[4]; /* status byte */ |
| 2642 | |
| 2643 | kfree(buf); |
| 2644 | return status; |
| 2645 | exit_failed: |
| 2646 | kfree(buf); |
| 2647 | return HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 2648 | } |
| 2649 | |
| 2650 | /* Determine offline status of a volume. |
| 2651 | * Return either: |
| 2652 | * 0 (not offline) |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 2653 | * 0xff (offline for unknown reasons) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2654 | * # (integer code indicating one of several NOT READY states |
| 2655 | * describing why a volume is to be kept offline) |
| 2656 | */ |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 2657 | static int hpsa_volume_offline(struct ctlr_info *h, |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2658 | unsigned char scsi3addr[]) |
| 2659 | { |
| 2660 | struct CommandList *c; |
| 2661 | unsigned char *sense, sense_key, asc, ascq; |
| 2662 | int ldstat = 0; |
| 2663 | u16 cmd_status; |
| 2664 | u8 scsi_status; |
| 2665 | #define ASC_LUN_NOT_READY 0x04 |
| 2666 | #define ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS 0x04 |
| 2667 | #define ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ 0x02 |
| 2668 | |
| 2669 | c = cmd_alloc(h); |
| 2670 | if (!c) |
| 2671 | return 0; |
| 2672 | (void) fill_cmd(c, TEST_UNIT_READY, h, NULL, 0, 0, scsi3addr, TYPE_CMD); |
| 2673 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 2674 | sense = c->err_info->SenseInfo; |
| 2675 | sense_key = sense[2]; |
| 2676 | asc = sense[12]; |
| 2677 | ascq = sense[13]; |
| 2678 | cmd_status = c->err_info->CommandStatus; |
| 2679 | scsi_status = c->err_info->ScsiStatus; |
| 2680 | cmd_free(h, c); |
| 2681 | /* Is the volume 'not ready'? */ |
| 2682 | if (cmd_status != CMD_TARGET_STATUS || |
| 2683 | scsi_status != SAM_STAT_CHECK_CONDITION || |
| 2684 | sense_key != NOT_READY || |
| 2685 | asc != ASC_LUN_NOT_READY) { |
| 2686 | return 0; |
| 2687 | } |
| 2688 | |
| 2689 | /* Determine the reason for not ready state */ |
| 2690 | ldstat = hpsa_get_volume_status(h, scsi3addr); |
| 2691 | |
| 2692 | /* Keep volume offline in certain cases: */ |
| 2693 | switch (ldstat) { |
| 2694 | case HPSA_LV_UNDERGOING_ERASE: |
| 2695 | case HPSA_LV_UNDERGOING_RPI: |
| 2696 | case HPSA_LV_PENDING_RPI: |
| 2697 | case HPSA_LV_ENCRYPTED_NO_KEY: |
| 2698 | case HPSA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER: |
| 2699 | case HPSA_LV_UNDERGOING_ENCRYPTION: |
| 2700 | case HPSA_LV_UNDERGOING_ENCRYPTION_REKEYING: |
| 2701 | case HPSA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: |
| 2702 | return ldstat; |
| 2703 | case HPSA_VPD_LV_STATUS_UNSUPPORTED: |
| 2704 | /* If VPD status page isn't available, |
| 2705 | * use ASC/ASCQ to determine state |
| 2706 | */ |
| 2707 | if ((ascq == ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS) || |
| 2708 | (ascq == ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ)) |
| 2709 | return ldstat; |
| 2710 | break; |
| 2711 | default: |
| 2712 | break; |
| 2713 | } |
| 2714 | return 0; |
| 2715 | } |
| 2716 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2717 | static int hpsa_update_device_info(struct ctlr_info *h, |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2718 | unsigned char scsi3addr[], struct hpsa_scsi_dev_t *this_device, |
| 2719 | unsigned char *is_OBDR_device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2720 | { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2721 | |
| 2722 | #define OBDR_SIG_OFFSET 43 |
| 2723 | #define OBDR_TAPE_SIG "$DR-10" |
| 2724 | #define OBDR_SIG_LEN (sizeof(OBDR_TAPE_SIG) - 1) |
| 2725 | #define OBDR_TAPE_INQ_SIZE (OBDR_SIG_OFFSET + OBDR_SIG_LEN) |
| 2726 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 2727 | unsigned char *inq_buff; |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2728 | unsigned char *obdr_sig; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2729 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 2730 | inq_buff = kzalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2731 | if (!inq_buff) |
| 2732 | goto bail_out; |
| 2733 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2734 | /* Do an inquiry to the device to see what it is. */ |
| 2735 | if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff, |
| 2736 | (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) { |
| 2737 | /* Inquiry failed (msg printed already) */ |
| 2738 | dev_err(&h->pdev->dev, |
| 2739 | "hpsa_update_device_info: inquiry failed\n"); |
| 2740 | goto bail_out; |
| 2741 | } |
| 2742 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2743 | this_device->devtype = (inq_buff[0] & 0x1f); |
| 2744 | memcpy(this_device->scsi3addr, scsi3addr, 8); |
| 2745 | memcpy(this_device->vendor, &inq_buff[8], |
| 2746 | sizeof(this_device->vendor)); |
| 2747 | memcpy(this_device->model, &inq_buff[16], |
| 2748 | sizeof(this_device->model)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2749 | memset(this_device->device_id, 0, |
| 2750 | sizeof(this_device->device_id)); |
| 2751 | hpsa_get_device_id(h, scsi3addr, this_device->device_id, |
| 2752 | sizeof(this_device->device_id)); |
| 2753 | |
| 2754 | if (this_device->devtype == TYPE_DISK && |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2755 | is_logical_dev_addr_mode(scsi3addr)) { |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 2756 | int volume_offline; |
| 2757 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2758 | hpsa_get_raid_level(h, scsi3addr, &this_device->raid_level); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2759 | if (h->fw_support & MISC_FW_RAID_OFFLOAD_BASIC) |
| 2760 | hpsa_get_ioaccel_status(h, scsi3addr, this_device); |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 2761 | volume_offline = hpsa_volume_offline(h, scsi3addr); |
| 2762 | if (volume_offline < 0 || volume_offline > 0xff) |
| 2763 | volume_offline = HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 2764 | this_device->volume_offline = volume_offline & 0xff; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2765 | } else { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2766 | this_device->raid_level = RAID_UNKNOWN; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2767 | this_device->offload_config = 0; |
| 2768 | this_device->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 2769 | this_device->offload_to_be_enabled = 0; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 2770 | this_device->volume_offline = 0; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2771 | this_device->queue_depth = h->nr_cmds; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2772 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2773 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2774 | if (is_OBDR_device) { |
| 2775 | /* See if this is a One-Button-Disaster-Recovery device |
| 2776 | * by looking for "$DR-10" at offset 43 in inquiry data. |
| 2777 | */ |
| 2778 | obdr_sig = &inq_buff[OBDR_SIG_OFFSET]; |
| 2779 | *is_OBDR_device = (this_device->devtype == TYPE_ROM && |
| 2780 | strncmp(obdr_sig, OBDR_TAPE_SIG, |
| 2781 | OBDR_SIG_LEN) == 0); |
| 2782 | } |
| 2783 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2784 | kfree(inq_buff); |
| 2785 | return 0; |
| 2786 | |
| 2787 | bail_out: |
| 2788 | kfree(inq_buff); |
| 2789 | return 1; |
| 2790 | } |
| 2791 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2792 | static unsigned char *ext_target_model[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2793 | "MSA2012", |
| 2794 | "MSA2024", |
| 2795 | "MSA2312", |
| 2796 | "MSA2324", |
Stephen M. Cameron | fda3851 | 2011-05-03 15:00:07 -0500 | [diff] [blame] | 2797 | "P2000 G3 SAS", |
Stephen M. Cameron | e06c8e5 | 2013-09-23 13:33:56 -0500 | [diff] [blame] | 2798 | "MSA 2040 SAS", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2799 | NULL, |
| 2800 | }; |
| 2801 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2802 | 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] | 2803 | { |
| 2804 | int i; |
| 2805 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2806 | for (i = 0; ext_target_model[i]; i++) |
| 2807 | if (strncmp(device->model, ext_target_model[i], |
| 2808 | strlen(ext_target_model[i])) == 0) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2809 | return 1; |
| 2810 | return 0; |
| 2811 | } |
| 2812 | |
| 2813 | /* Helper function to assign bus, target, lun mapping of devices. |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2814 | * 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] | 2815 | * volumes on bus 1, physical devices on bus 2. and the hba on bus 3. |
| 2816 | * Logical drive target and lun are assigned at this time, but |
| 2817 | * physical device lun and target assignment are deferred (assigned |
| 2818 | * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) |
| 2819 | */ |
| 2820 | static void figure_bus_target_lun(struct ctlr_info *h, |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2821 | u8 *lunaddrbytes, struct hpsa_scsi_dev_t *device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2822 | { |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2823 | u32 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2824 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2825 | if (!is_logical_dev_addr_mode(lunaddrbytes)) { |
| 2826 | /* physical device, target and lun filled in later */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2827 | if (is_hba_lunid(lunaddrbytes)) |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2828 | hpsa_set_bus_target_lun(device, 3, 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2829 | else |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2830 | /* defer target, lun assignment for physical devices */ |
| 2831 | hpsa_set_bus_target_lun(device, 2, -1, -1); |
| 2832 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2833 | } |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2834 | /* It's a logical device */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2835 | if (is_ext_target(h, device)) { |
| 2836 | /* external target way, put logicals on bus 1 |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2837 | * and match target/lun numbers box |
| 2838 | * reports, other smart array, bus 0, target 0, match lunid |
| 2839 | */ |
| 2840 | hpsa_set_bus_target_lun(device, |
| 2841 | 1, (lunid >> 16) & 0x3fff, lunid & 0x00ff); |
| 2842 | return; |
| 2843 | } |
| 2844 | hpsa_set_bus_target_lun(device, 0, 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | /* |
| 2848 | * 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] | 2849 | * 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] | 2850 | * which is at lun zero, as CCISS_REPORT_PHYSICAL_LUNS doesn't report |
| 2851 | * it for some reason. *tmpdevice is the target we're adding, |
| 2852 | * this_device is a pointer into the current element of currentsd[] |
| 2853 | * that we're building up in update_scsi_devices(), below. |
| 2854 | * lunzerobits is a bitmap that tracks which targets already have a |
| 2855 | * lun 0 assigned. |
| 2856 | * Returns 1 if an enclosure was added, 0 if not. |
| 2857 | */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2858 | static int add_ext_target_dev(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2859 | struct hpsa_scsi_dev_t *tmpdevice, |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2860 | struct hpsa_scsi_dev_t *this_device, u8 *lunaddrbytes, |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2861 | unsigned long lunzerobits[], int *n_ext_target_devs) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2862 | { |
| 2863 | unsigned char scsi3addr[8]; |
| 2864 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2865 | if (test_bit(tmpdevice->target, lunzerobits)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2866 | return 0; /* There is already a lun 0 on this target. */ |
| 2867 | |
| 2868 | if (!is_logical_dev_addr_mode(lunaddrbytes)) |
| 2869 | return 0; /* It's the logical targets that may lack lun 0. */ |
| 2870 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2871 | if (!is_ext_target(h, tmpdevice)) |
| 2872 | return 0; /* Only external target devices have this problem. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2873 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2874 | 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] | 2875 | return 0; |
| 2876 | |
Stephen M. Cameron | c4f8a29 | 2011-01-07 10:55:43 -0600 | [diff] [blame] | 2877 | memset(scsi3addr, 0, 8); |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2878 | scsi3addr[3] = tmpdevice->target; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2879 | if (is_hba_lunid(scsi3addr)) |
| 2880 | return 0; /* Don't add the RAID controller here. */ |
| 2881 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2882 | if (is_scsi_rev_5(h)) |
| 2883 | return 0; /* p1210m doesn't need to do this. */ |
| 2884 | |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2885 | if (*n_ext_target_devs >= MAX_EXT_TARGETS) { |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 2886 | dev_warn(&h->pdev->dev, "Maximum number of external " |
| 2887 | "target devices exceeded. Check your hardware " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2888 | "configuration."); |
| 2889 | return 0; |
| 2890 | } |
| 2891 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 2892 | if (hpsa_update_device_info(h, scsi3addr, this_device, NULL)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2893 | return 0; |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 2894 | (*n_ext_target_devs)++; |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 2895 | hpsa_set_bus_target_lun(this_device, |
| 2896 | tmpdevice->bus, tmpdevice->target, 0); |
| 2897 | set_bit(tmpdevice->target, lunzerobits); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2898 | return 1; |
| 2899 | } |
| 2900 | |
| 2901 | /* |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2902 | * Get address of physical disk used for an ioaccel2 mode command: |
| 2903 | * 1. Extract ioaccel2 handle from the command. |
| 2904 | * 2. Find a matching ioaccel2 handle from list of physical disks. |
| 2905 | * 3. Return: |
| 2906 | * 1 and set scsi3addr to address of matching physical |
| 2907 | * 0 if no matching physical disk was found. |
| 2908 | */ |
| 2909 | static int hpsa_get_pdisk_of_ioaccel2(struct ctlr_info *h, |
| 2910 | struct CommandList *ioaccel2_cmd_to_abort, unsigned char *scsi3addr) |
| 2911 | { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 2912 | struct io_accel2_cmd *c2 = |
| 2913 | &h->ioaccel2_cmd_pool[ioaccel2_cmd_to_abort->cmdindex]; |
| 2914 | unsigned long flags; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2915 | int i; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2916 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 2917 | spin_lock_irqsave(&h->devlock, flags); |
| 2918 | for (i = 0; i < h->ndevices; i++) |
| 2919 | if (h->dev[i]->ioaccel_handle == le32_to_cpu(c2->scsi_nexus)) { |
| 2920 | memcpy(scsi3addr, h->dev[i]->scsi3addr, |
| 2921 | sizeof(h->dev[i]->scsi3addr)); |
| 2922 | spin_unlock_irqrestore(&h->devlock, flags); |
| 2923 | return 1; |
| 2924 | } |
| 2925 | spin_unlock_irqrestore(&h->devlock, flags); |
| 2926 | return 0; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2927 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 2928 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 2929 | /* |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2930 | * Do CISS_REPORT_PHYS and CISS_REPORT_LOG. Data is returned in physdev, |
| 2931 | * logdev. The number of luns in physdev and logdev are returned in |
| 2932 | * *nphysicals and *nlogicals, respectively. |
| 2933 | * Returns 0 on success, -1 otherwise. |
| 2934 | */ |
| 2935 | static int hpsa_gather_lun_info(struct ctlr_info *h, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2936 | struct ReportExtendedLUNdata *physdev, u32 *nphysicals, |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2937 | struct ReportLUNdata *logdev, u32 *nlogicals) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2938 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2939 | if (hpsa_scsi_do_report_phys_luns(h, physdev, sizeof(*physdev))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2940 | dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); |
| 2941 | return -1; |
| 2942 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2943 | *nphysicals = be32_to_cpu(*((__be32 *)physdev->LUNListLength)) / 24; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2944 | if (*nphysicals > HPSA_MAX_PHYS_LUN) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2945 | dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded. %d LUNs ignored.\n", |
| 2946 | HPSA_MAX_PHYS_LUN, *nphysicals - HPSA_MAX_PHYS_LUN); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2947 | *nphysicals = HPSA_MAX_PHYS_LUN; |
| 2948 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2949 | if (hpsa_scsi_do_report_log_luns(h, logdev, sizeof(*logdev))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2950 | dev_err(&h->pdev->dev, "report logical LUNs failed.\n"); |
| 2951 | return -1; |
| 2952 | } |
Stephen M. Cameron | 6df1e95 | 2010-02-04 08:42:19 -0600 | [diff] [blame] | 2953 | *nlogicals = be32_to_cpu(*((__be32 *) logdev->LUNListLength)) / 8; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2954 | /* Reject Logicals in excess of our max capability. */ |
| 2955 | if (*nlogicals > HPSA_MAX_LUN) { |
| 2956 | dev_warn(&h->pdev->dev, |
| 2957 | "maximum logical LUNs (%d) exceeded. " |
| 2958 | "%d LUNs ignored.\n", HPSA_MAX_LUN, |
| 2959 | *nlogicals - HPSA_MAX_LUN); |
| 2960 | *nlogicals = HPSA_MAX_LUN; |
| 2961 | } |
| 2962 | if (*nlogicals + *nphysicals > HPSA_MAX_PHYS_LUN) { |
| 2963 | dev_warn(&h->pdev->dev, |
| 2964 | "maximum logical + physical LUNs (%d) exceeded. " |
| 2965 | "%d LUNs ignored.\n", HPSA_MAX_PHYS_LUN, |
| 2966 | *nphysicals + *nlogicals - HPSA_MAX_PHYS_LUN); |
| 2967 | *nlogicals = HPSA_MAX_PHYS_LUN - *nphysicals; |
| 2968 | } |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 2972 | static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, |
| 2973 | int i, int nphysicals, int nlogicals, |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 2974 | struct ReportExtendedLUNdata *physdev_list, |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2975 | struct ReportLUNdata *logdev_list) |
| 2976 | { |
| 2977 | /* Helper function, figure out where the LUN ID info is coming from |
| 2978 | * given index i, lists of physical and logical devices, where in |
| 2979 | * the list the raid controller is supposed to appear (first or last) |
| 2980 | */ |
| 2981 | |
| 2982 | int logicals_start = nphysicals + (raid_ctlr_position == 0); |
| 2983 | int last_device = nphysicals + nlogicals + (raid_ctlr_position == 0); |
| 2984 | |
| 2985 | if (i == raid_ctlr_position) |
| 2986 | return RAID_CTLR_LUNID; |
| 2987 | |
| 2988 | if (i < logicals_start) |
Stephen M. Cameron | d5b5d96 | 2014-05-29 10:53:34 -0500 | [diff] [blame] | 2989 | return &physdev_list->LUN[i - |
| 2990 | (raid_ctlr_position == 0)].lunid[0]; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 2991 | |
| 2992 | if (i < last_device) |
| 2993 | return &logdev_list->LUN[i - nphysicals - |
| 2994 | (raid_ctlr_position == 0)][0]; |
| 2995 | BUG(); |
| 2996 | return NULL; |
| 2997 | } |
| 2998 | |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 2999 | static int hpsa_hba_mode_enabled(struct ctlr_info *h) |
| 3000 | { |
| 3001 | int rc; |
Joe Handzik | 6e8e808 | 2014-05-15 15:44:42 -0500 | [diff] [blame] | 3002 | int hba_mode_enabled; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3003 | struct bmic_controller_parameters *ctlr_params; |
| 3004 | ctlr_params = kzalloc(sizeof(struct bmic_controller_parameters), |
| 3005 | GFP_KERNEL); |
| 3006 | |
| 3007 | if (!ctlr_params) |
Joe Handzik | 96444fb | 2014-05-15 15:44:47 -0500 | [diff] [blame] | 3008 | return -ENOMEM; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3009 | rc = hpsa_bmic_ctrl_mode_sense(h, RAID_CTLR_LUNID, 0, ctlr_params, |
| 3010 | sizeof(struct bmic_controller_parameters)); |
Joe Handzik | 96444fb | 2014-05-15 15:44:47 -0500 | [diff] [blame] | 3011 | if (rc) { |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3012 | kfree(ctlr_params); |
Joe Handzik | 96444fb | 2014-05-15 15:44:47 -0500 | [diff] [blame] | 3013 | return rc; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3014 | } |
Joe Handzik | 6e8e808 | 2014-05-15 15:44:42 -0500 | [diff] [blame] | 3015 | |
| 3016 | hba_mode_enabled = |
| 3017 | ((ctlr_params->nvram_flags & HBA_MODE_ENABLED_FLAG) != 0); |
| 3018 | kfree(ctlr_params); |
| 3019 | return hba_mode_enabled; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3020 | } |
| 3021 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3022 | /* get physical drive ioaccel handle and queue depth */ |
| 3023 | static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h, |
| 3024 | struct hpsa_scsi_dev_t *dev, |
| 3025 | u8 *lunaddrbytes, |
| 3026 | struct bmic_identify_physical_device *id_phys) |
| 3027 | { |
| 3028 | int rc; |
| 3029 | struct ext_report_lun_entry *rle = |
| 3030 | (struct ext_report_lun_entry *) lunaddrbytes; |
| 3031 | |
| 3032 | dev->ioaccel_handle = rle->ioaccel_handle; |
| 3033 | memset(id_phys, 0, sizeof(*id_phys)); |
| 3034 | rc = hpsa_bmic_id_physical_device(h, lunaddrbytes, |
| 3035 | GET_BMIC_DRIVE_NUMBER(lunaddrbytes), id_phys, |
| 3036 | sizeof(*id_phys)); |
| 3037 | if (!rc) |
| 3038 | /* Reserve space for FW operations */ |
| 3039 | #define DRIVE_CMDS_RESERVED_FOR_FW 2 |
| 3040 | #define DRIVE_QUEUE_DEPTH 7 |
| 3041 | dev->queue_depth = |
| 3042 | le16_to_cpu(id_phys->current_queue_depth_limit) - |
| 3043 | DRIVE_CMDS_RESERVED_FOR_FW; |
| 3044 | else |
| 3045 | dev->queue_depth = DRIVE_QUEUE_DEPTH; /* conservative */ |
| 3046 | atomic_set(&dev->ioaccel_cmds_out, 0); |
| 3047 | } |
| 3048 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3049 | static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) |
| 3050 | { |
| 3051 | /* the idea here is we could get notified |
| 3052 | * that some devices have changed, so we do a report |
| 3053 | * physical luns and report logical luns cmd, and adjust |
| 3054 | * our list of devices accordingly. |
| 3055 | * |
| 3056 | * The scsi3addr's of devices won't change so long as the |
| 3057 | * adapter is not reset. That means we can rescan and |
| 3058 | * tell which devices we already know about, vs. new |
| 3059 | * devices, vs. disappearing devices. |
| 3060 | */ |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 3061 | struct ReportExtendedLUNdata *physdev_list = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3062 | struct ReportLUNdata *logdev_list = NULL; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3063 | struct bmic_identify_physical_device *id_phys = NULL; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 3064 | u32 nphysicals = 0; |
| 3065 | u32 nlogicals = 0; |
| 3066 | u32 ndev_allocated = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3067 | struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; |
| 3068 | int ncurrent = 0; |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3069 | int i, n_ext_target_devs, ndevs_to_allocate; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3070 | int raid_ctlr_position; |
Joe Handzik | 2bbf5c7 | 2014-05-21 11:16:01 -0500 | [diff] [blame] | 3071 | int rescan_hba_mode; |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 3072 | DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3073 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 3074 | currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | 9208471 | 2014-11-14 17:26:54 -0600 | [diff] [blame] | 3075 | physdev_list = kzalloc(sizeof(*physdev_list), GFP_KERNEL); |
| 3076 | logdev_list = kzalloc(sizeof(*logdev_list), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3077 | tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3078 | id_phys = kzalloc(sizeof(*id_phys), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3079 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3080 | if (!currentsd || !physdev_list || !logdev_list || |
| 3081 | !tmpdevice || !id_phys) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3082 | dev_err(&h->pdev->dev, "out of memory\n"); |
| 3083 | goto out; |
| 3084 | } |
| 3085 | memset(lunzerobits, 0, sizeof(lunzerobits)); |
| 3086 | |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3087 | rescan_hba_mode = hpsa_hba_mode_enabled(h); |
Joe Handzik | 96444fb | 2014-05-15 15:44:47 -0500 | [diff] [blame] | 3088 | if (rescan_hba_mode < 0) |
| 3089 | goto out; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3090 | |
| 3091 | if (!h->hba_mode_enabled && rescan_hba_mode) |
| 3092 | dev_warn(&h->pdev->dev, "HBA mode enabled\n"); |
| 3093 | else if (h->hba_mode_enabled && !rescan_hba_mode) |
| 3094 | dev_warn(&h->pdev->dev, "HBA mode disabled\n"); |
| 3095 | |
| 3096 | h->hba_mode_enabled = rescan_hba_mode; |
| 3097 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3098 | if (hpsa_gather_lun_info(h, physdev_list, &nphysicals, |
| 3099 | logdev_list, &nlogicals)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3100 | goto out; |
| 3101 | |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 3102 | /* We might see up to the maximum number of logical and physical disks |
| 3103 | * plus external target devices, and a device for the local RAID |
| 3104 | * controller. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3105 | */ |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 3106 | ndevs_to_allocate = nphysicals + nlogicals + MAX_EXT_TARGETS + 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3107 | |
| 3108 | /* Allocate the per device structures */ |
| 3109 | for (i = 0; i < ndevs_to_allocate; i++) { |
Scott Teel | b7ec021 | 2011-10-26 16:21:12 -0500 | [diff] [blame] | 3110 | if (i >= HPSA_MAX_DEVICES) { |
| 3111 | dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded." |
| 3112 | " %d devices ignored.\n", HPSA_MAX_DEVICES, |
| 3113 | ndevs_to_allocate - HPSA_MAX_DEVICES); |
| 3114 | break; |
| 3115 | } |
| 3116 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3117 | currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL); |
| 3118 | if (!currentsd[i]) { |
| 3119 | dev_warn(&h->pdev->dev, "out of memory at %s:%d\n", |
| 3120 | __FILE__, __LINE__); |
| 3121 | goto out; |
| 3122 | } |
| 3123 | ndev_allocated++; |
| 3124 | } |
| 3125 | |
Stephen M. Cameron | 8645291 | 2014-05-29 10:53:49 -0500 | [diff] [blame] | 3126 | if (is_scsi_rev_5(h)) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3127 | raid_ctlr_position = 0; |
| 3128 | else |
| 3129 | raid_ctlr_position = nphysicals + nlogicals; |
| 3130 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3131 | /* adjust our table of devices */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3132 | n_ext_target_devs = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3133 | for (i = 0; i < nphysicals + nlogicals + 1; i++) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3134 | u8 *lunaddrbytes, is_OBDR = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3135 | |
| 3136 | /* Figure out where the LUN ID info is coming from */ |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3137 | lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position, |
| 3138 | i, nphysicals, nlogicals, physdev_list, logdev_list); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 3139 | |
| 3140 | /* skip masked non-disk devices */ |
| 3141 | if (MASKED_DEVICE(lunaddrbytes)) |
| 3142 | if (i < nphysicals + (raid_ctlr_position == 0) && |
| 3143 | NON_DISK_PHYS_DEV(lunaddrbytes)) |
| 3144 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3145 | |
| 3146 | /* Get device type, vendor, model, device id */ |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3147 | if (hpsa_update_device_info(h, lunaddrbytes, tmpdevice, |
| 3148 | &is_OBDR)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3149 | continue; /* skip it if we can't talk to it. */ |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3150 | figure_bus_target_lun(h, lunaddrbytes, tmpdevice); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3151 | this_device = currentsd[ncurrent]; |
| 3152 | |
| 3153 | /* |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3154 | * 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] | 3155 | * doesn't show up in CCISS_REPORT_PHYSICAL data, but there |
| 3156 | * is nonetheless an enclosure device there. We have to |
| 3157 | * present that otherwise linux won't find anything if |
| 3158 | * there is no lun 0. |
| 3159 | */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3160 | if (add_ext_target_dev(h, tmpdevice, this_device, |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3161 | lunaddrbytes, lunzerobits, |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3162 | &n_ext_target_devs)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3163 | ncurrent++; |
| 3164 | this_device = currentsd[ncurrent]; |
| 3165 | } |
| 3166 | |
| 3167 | *this_device = *tmpdevice; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3168 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 3169 | /* do not expose masked devices */ |
| 3170 | if (MASKED_DEVICE(lunaddrbytes) && |
| 3171 | i < nphysicals + (raid_ctlr_position == 0)) { |
| 3172 | if (h->hba_mode_enabled) |
| 3173 | dev_warn(&h->pdev->dev, |
| 3174 | "Masked physical device detected\n"); |
| 3175 | this_device->expose_state = HPSA_DO_NOT_EXPOSE; |
| 3176 | } else { |
| 3177 | this_device->expose_state = |
| 3178 | HPSA_SG_ATTACH | HPSA_ULD_ATTACH; |
| 3179 | } |
| 3180 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3181 | switch (this_device->devtype) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3182 | case TYPE_ROM: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3183 | /* We don't *really* support actual CD-ROM devices, |
| 3184 | * just "One Button Disaster Recovery" tape drive |
| 3185 | * which temporarily pretends to be a CD-ROM drive. |
| 3186 | * So we check that the device is really an OBDR tape |
| 3187 | * device by checking for "$DR-10" in bytes 43-48 of |
| 3188 | * the inquiry data. |
| 3189 | */ |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3190 | if (is_OBDR) |
| 3191 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3192 | break; |
| 3193 | case TYPE_DISK: |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3194 | if (h->hba_mode_enabled) { |
| 3195 | /* never use raid mapper in HBA mode */ |
| 3196 | this_device->offload_enabled = 0; |
| 3197 | ncurrent++; |
| 3198 | break; |
| 3199 | } else if (h->acciopath_status) { |
| 3200 | if (i >= nphysicals) { |
| 3201 | ncurrent++; |
| 3202 | break; |
| 3203 | } |
| 3204 | } else { |
| 3205 | if (i < nphysicals) |
| 3206 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3207 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3208 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3209 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3210 | if (h->transMethod & CFGTBL_Trans_io_accel1 || |
| 3211 | h->transMethod & CFGTBL_Trans_io_accel2) { |
| 3212 | hpsa_get_ioaccel_drive_info(h, this_device, |
| 3213 | lunaddrbytes, id_phys); |
| 3214 | atomic_set(&this_device->ioaccel_cmds_out, 0); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3215 | ncurrent++; |
| 3216 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3217 | break; |
| 3218 | case TYPE_TAPE: |
| 3219 | case TYPE_MEDIUM_CHANGER: |
| 3220 | ncurrent++; |
| 3221 | break; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 3222 | case TYPE_ENCLOSURE: |
| 3223 | if (h->hba_mode_enabled) |
| 3224 | ncurrent++; |
| 3225 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3226 | case TYPE_RAID: |
| 3227 | /* Only present the Smartarray HBA as a RAID controller. |
| 3228 | * If it's a RAID controller other than the HBA itself |
| 3229 | * (an external RAID controller, MSA500 or similar) |
| 3230 | * don't present it. |
| 3231 | */ |
| 3232 | if (!is_hba_lunid(lunaddrbytes)) |
| 3233 | break; |
| 3234 | ncurrent++; |
| 3235 | break; |
| 3236 | default: |
| 3237 | break; |
| 3238 | } |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 3239 | if (ncurrent >= HPSA_MAX_DEVICES) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3240 | break; |
| 3241 | } |
| 3242 | adjust_hpsa_scsi_table(h, hostno, currentsd, ncurrent); |
| 3243 | out: |
| 3244 | kfree(tmpdevice); |
| 3245 | for (i = 0; i < ndev_allocated; i++) |
| 3246 | kfree(currentsd[i]); |
| 3247 | kfree(currentsd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3248 | kfree(physdev_list); |
| 3249 | kfree(logdev_list); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3250 | kfree(id_phys); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3251 | } |
| 3252 | |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 3253 | static void hpsa_set_sg_descriptor(struct SGDescriptor *desc, |
| 3254 | struct scatterlist *sg) |
| 3255 | { |
| 3256 | u64 addr64 = (u64) sg_dma_address(sg); |
| 3257 | unsigned int len = sg_dma_len(sg); |
| 3258 | |
| 3259 | desc->Addr = cpu_to_le64(addr64); |
| 3260 | desc->Len = cpu_to_le32(len); |
| 3261 | desc->Ext = 0; |
| 3262 | } |
| 3263 | |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 3264 | /* |
| 3265 | * hpsa_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3266 | * dma mapping and fills in the scatter gather entries of the |
| 3267 | * hpsa command, cp. |
| 3268 | */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3269 | static int hpsa_scatter_gather(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3270 | struct CommandList *cp, |
| 3271 | struct scsi_cmnd *cmd) |
| 3272 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3273 | struct scatterlist *sg; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3274 | int use_sg, i, sg_index, chained; |
| 3275 | struct SGDescriptor *curr_sg; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3276 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3277 | BUG_ON(scsi_sg_count(cmd) > h->maxsgentries); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3278 | |
| 3279 | use_sg = scsi_dma_map(cmd); |
| 3280 | if (use_sg < 0) |
| 3281 | return use_sg; |
| 3282 | |
| 3283 | if (!use_sg) |
| 3284 | goto sglist_finished; |
| 3285 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3286 | curr_sg = cp->SG; |
| 3287 | chained = 0; |
| 3288 | sg_index = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3289 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3290 | if (i == h->max_cmd_sg_entries - 1 && |
| 3291 | use_sg > h->max_cmd_sg_entries) { |
| 3292 | chained = 1; |
| 3293 | curr_sg = h->cmd_sg_list[cp->cmdindex]; |
| 3294 | sg_index = 0; |
| 3295 | } |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 3296 | hpsa_set_sg_descriptor(curr_sg, sg); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3297 | curr_sg++; |
| 3298 | } |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 3299 | |
| 3300 | /* Back the pointer up to the last entry and mark it as "last". */ |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 3301 | (--curr_sg)->Ext = cpu_to_le32(HPSA_SG_LAST); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3302 | |
| 3303 | if (use_sg + chained > h->maxSG) |
| 3304 | h->maxSG = use_sg + chained; |
| 3305 | |
| 3306 | if (chained) { |
| 3307 | cp->Header.SGList = h->max_cmd_sg_entries; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 3308 | cp->Header.SGTotal = cpu_to_le16(use_sg + 1); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 3309 | if (hpsa_map_sg_chain_block(h, cp)) { |
| 3310 | scsi_dma_unmap(cmd); |
| 3311 | return -1; |
| 3312 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 3313 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | sglist_finished: |
| 3317 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 3318 | cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */ |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 3319 | cp->Header.SGTotal = cpu_to_le16(use_sg); /* total sgs in cmd list */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3320 | return 0; |
| 3321 | } |
| 3322 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3323 | #define IO_ACCEL_INELIGIBLE (1) |
| 3324 | static int fixup_ioaccel_cdb(u8 *cdb, int *cdb_len) |
| 3325 | { |
| 3326 | int is_write = 0; |
| 3327 | u32 block; |
| 3328 | u32 block_cnt; |
| 3329 | |
| 3330 | /* Perform some CDB fixups if needed using 10 byte reads/writes only */ |
| 3331 | switch (cdb[0]) { |
| 3332 | case WRITE_6: |
| 3333 | case WRITE_12: |
| 3334 | is_write = 1; |
| 3335 | case READ_6: |
| 3336 | case READ_12: |
| 3337 | if (*cdb_len == 6) { |
| 3338 | block = (((u32) cdb[2]) << 8) | cdb[3]; |
| 3339 | block_cnt = cdb[4]; |
| 3340 | } else { |
| 3341 | BUG_ON(*cdb_len != 12); |
| 3342 | block = (((u32) cdb[2]) << 24) | |
| 3343 | (((u32) cdb[3]) << 16) | |
| 3344 | (((u32) cdb[4]) << 8) | |
| 3345 | cdb[5]; |
| 3346 | block_cnt = |
| 3347 | (((u32) cdb[6]) << 24) | |
| 3348 | (((u32) cdb[7]) << 16) | |
| 3349 | (((u32) cdb[8]) << 8) | |
| 3350 | cdb[9]; |
| 3351 | } |
| 3352 | if (block_cnt > 0xffff) |
| 3353 | return IO_ACCEL_INELIGIBLE; |
| 3354 | |
| 3355 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 3356 | cdb[1] = 0; |
| 3357 | cdb[2] = (u8) (block >> 24); |
| 3358 | cdb[3] = (u8) (block >> 16); |
| 3359 | cdb[4] = (u8) (block >> 8); |
| 3360 | cdb[5] = (u8) (block); |
| 3361 | cdb[6] = 0; |
| 3362 | cdb[7] = (u8) (block_cnt >> 8); |
| 3363 | cdb[8] = (u8) (block_cnt); |
| 3364 | cdb[9] = 0; |
| 3365 | *cdb_len = 10; |
| 3366 | break; |
| 3367 | } |
| 3368 | return 0; |
| 3369 | } |
| 3370 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3371 | static int hpsa_scsi_ioaccel1_queue_command(struct ctlr_info *h, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3372 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3373 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3374 | { |
| 3375 | struct scsi_cmnd *cmd = c->scsi_cmd; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3376 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 3377 | unsigned int len; |
| 3378 | unsigned int total_len = 0; |
| 3379 | struct scatterlist *sg; |
| 3380 | u64 addr64; |
| 3381 | int use_sg, i; |
| 3382 | struct SGDescriptor *curr_sg; |
| 3383 | u32 control = IOACCEL1_CONTROL_SIMPLEQUEUE; |
| 3384 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3385 | /* TODO: implement chaining support */ |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3386 | if (scsi_sg_count(cmd) > h->ioaccel_maxsg) { |
| 3387 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3388 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3389 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3390 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3391 | BUG_ON(cmd->cmd_len > IOACCEL1_IOFLAGS_CDBLEN_MAX); |
| 3392 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3393 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) { |
| 3394 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3395 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3396 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3397 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3398 | c->cmd_type = CMD_IOACCEL1; |
| 3399 | |
| 3400 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 3401 | c->busaddr = (u32) h->ioaccel_cmd_pool_dhandle + |
| 3402 | (c->cmdindex * sizeof(*cp)); |
| 3403 | BUG_ON(c->busaddr & 0x0000007F); |
| 3404 | |
| 3405 | use_sg = scsi_dma_map(cmd); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3406 | if (use_sg < 0) { |
| 3407 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3408 | return use_sg; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3409 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3410 | |
| 3411 | if (use_sg) { |
| 3412 | curr_sg = cp->SG; |
| 3413 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 3414 | addr64 = (u64) sg_dma_address(sg); |
| 3415 | len = sg_dma_len(sg); |
| 3416 | total_len += len; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 3417 | curr_sg->Addr = cpu_to_le64(addr64); |
| 3418 | curr_sg->Len = cpu_to_le32(len); |
| 3419 | curr_sg->Ext = cpu_to_le32(0); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3420 | curr_sg++; |
| 3421 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 3422 | (--curr_sg)->Ext = cpu_to_le32(HPSA_SG_LAST); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3423 | |
| 3424 | switch (cmd->sc_data_direction) { |
| 3425 | case DMA_TO_DEVICE: |
| 3426 | control |= IOACCEL1_CONTROL_DATA_OUT; |
| 3427 | break; |
| 3428 | case DMA_FROM_DEVICE: |
| 3429 | control |= IOACCEL1_CONTROL_DATA_IN; |
| 3430 | break; |
| 3431 | case DMA_NONE: |
| 3432 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 3433 | break; |
| 3434 | default: |
| 3435 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 3436 | cmd->sc_data_direction); |
| 3437 | BUG(); |
| 3438 | break; |
| 3439 | } |
| 3440 | } else { |
| 3441 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 3442 | } |
| 3443 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3444 | c->Header.SGList = use_sg; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3445 | /* Fill out the command structure to submit */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3446 | cp->dev_handle = cpu_to_le16(ioaccel_handle & 0xFFFF); |
| 3447 | cp->transfer_len = cpu_to_le32(total_len); |
| 3448 | cp->io_flags = cpu_to_le16(IOACCEL1_IOFLAGS_IO_REQ | |
| 3449 | (cdb_len & IOACCEL1_IOFLAGS_CDBLEN_MASK)); |
| 3450 | cp->control = cpu_to_le32(control); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3451 | memcpy(cp->CDB, cdb, cdb_len); |
| 3452 | memcpy(cp->CISS_LUN, scsi3addr, 8); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3453 | /* Tag was already set at init time. */ |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3454 | enqueue_cmd_and_start_io(h, c); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 3455 | return 0; |
| 3456 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3457 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3458 | /* |
| 3459 | * Queue a command directly to a device behind the controller using the |
| 3460 | * I/O accelerator path. |
| 3461 | */ |
| 3462 | static int hpsa_scsi_ioaccel_direct_map(struct ctlr_info *h, |
| 3463 | struct CommandList *c) |
| 3464 | { |
| 3465 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3466 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 3467 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3468 | c->phys_disk = dev; |
| 3469 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3470 | return hpsa_scsi_ioaccel_queue_command(h, c, dev->ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3471 | cmd->cmnd, cmd->cmd_len, dev->scsi3addr, dev); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3472 | } |
| 3473 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3474 | /* |
| 3475 | * Set encryption parameters for the ioaccel2 request |
| 3476 | */ |
| 3477 | static void set_encrypt_ioaccel2(struct ctlr_info *h, |
| 3478 | struct CommandList *c, struct io_accel2_cmd *cp) |
| 3479 | { |
| 3480 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3481 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 3482 | struct raid_map_data *map = &dev->raid_map; |
| 3483 | u64 first_block; |
| 3484 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3485 | /* Are we doing encryption on this device */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3486 | if (!(le16_to_cpu(map->flags) & RAID_MAP_FLAG_ENCRYPT_ON)) |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3487 | return; |
| 3488 | /* Set the data encryption key index. */ |
| 3489 | cp->dekindex = map->dekindex; |
| 3490 | |
| 3491 | /* Set the encryption enable flag, encoded into direction field. */ |
| 3492 | cp->direction |= IOACCEL2_DIRECTION_ENCRYPT_MASK; |
| 3493 | |
| 3494 | /* Set encryption tweak values based on logical block address |
| 3495 | * If block size is 512, tweak value is LBA. |
| 3496 | * For other block sizes, tweak is (LBA * block size)/ 512) |
| 3497 | */ |
| 3498 | switch (cmd->cmnd[0]) { |
| 3499 | /* Required? 6-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 3500 | case WRITE_6: |
| 3501 | case READ_6: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3502 | first_block = get_unaligned_be16(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3503 | break; |
| 3504 | case WRITE_10: |
| 3505 | case READ_10: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3506 | /* Required? 12-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 3507 | case WRITE_12: |
| 3508 | case READ_12: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3509 | first_block = get_unaligned_be32(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3510 | break; |
| 3511 | case WRITE_16: |
| 3512 | case READ_16: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3513 | first_block = get_unaligned_be64(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3514 | break; |
| 3515 | default: |
| 3516 | dev_err(&h->pdev->dev, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3517 | "ERROR: %s: size (0x%x) not supported for encryption\n", |
| 3518 | __func__, cmd->cmnd[0]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3519 | BUG(); |
| 3520 | break; |
| 3521 | } |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3522 | |
| 3523 | if (le32_to_cpu(map->volume_blk_size) != 512) |
| 3524 | first_block = first_block * |
| 3525 | le32_to_cpu(map->volume_blk_size)/512; |
| 3526 | |
| 3527 | cp->tweak_lower = cpu_to_le32(first_block); |
| 3528 | cp->tweak_upper = cpu_to_le32(first_block >> 32); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3529 | } |
| 3530 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3531 | static int hpsa_scsi_ioaccel2_queue_command(struct ctlr_info *h, |
| 3532 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3533 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3534 | { |
| 3535 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3536 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 3537 | struct ioaccel2_sg_element *curr_sg; |
| 3538 | int use_sg, i; |
| 3539 | struct scatterlist *sg; |
| 3540 | u64 addr64; |
| 3541 | u32 len; |
| 3542 | u32 total_len = 0; |
| 3543 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3544 | if (scsi_sg_count(cmd) > h->ioaccel_maxsg) { |
| 3545 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3546 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3547 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3548 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3549 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) { |
| 3550 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3551 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3552 | } |
| 3553 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3554 | c->cmd_type = CMD_IOACCEL2; |
| 3555 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 3556 | c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle + |
| 3557 | (c->cmdindex * sizeof(*cp)); |
| 3558 | BUG_ON(c->busaddr & 0x0000007F); |
| 3559 | |
| 3560 | memset(cp, 0, sizeof(*cp)); |
| 3561 | cp->IU_type = IOACCEL2_IU_TYPE; |
| 3562 | |
| 3563 | use_sg = scsi_dma_map(cmd); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3564 | if (use_sg < 0) { |
| 3565 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3566 | return use_sg; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3567 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3568 | |
| 3569 | if (use_sg) { |
| 3570 | BUG_ON(use_sg > IOACCEL2_MAXSGENTRIES); |
| 3571 | curr_sg = cp->sg; |
| 3572 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 3573 | addr64 = (u64) sg_dma_address(sg); |
| 3574 | len = sg_dma_len(sg); |
| 3575 | total_len += len; |
| 3576 | curr_sg->address = cpu_to_le64(addr64); |
| 3577 | curr_sg->length = cpu_to_le32(len); |
| 3578 | curr_sg->reserved[0] = 0; |
| 3579 | curr_sg->reserved[1] = 0; |
| 3580 | curr_sg->reserved[2] = 0; |
| 3581 | curr_sg->chain_indicator = 0; |
| 3582 | curr_sg++; |
| 3583 | } |
| 3584 | |
| 3585 | switch (cmd->sc_data_direction) { |
| 3586 | case DMA_TO_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3587 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3588 | cp->direction |= IOACCEL2_DIR_DATA_OUT; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3589 | break; |
| 3590 | case DMA_FROM_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3591 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3592 | cp->direction |= IOACCEL2_DIR_DATA_IN; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3593 | break; |
| 3594 | case DMA_NONE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3595 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3596 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3597 | break; |
| 3598 | default: |
| 3599 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 3600 | cmd->sc_data_direction); |
| 3601 | BUG(); |
| 3602 | break; |
| 3603 | } |
| 3604 | } else { |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3605 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 3606 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3607 | } |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3608 | |
| 3609 | /* Set encryption parameters, if necessary */ |
| 3610 | set_encrypt_ioaccel2(h, c, cp); |
| 3611 | |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3612 | cp->scsi_nexus = cpu_to_le32(ioaccel_handle); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 3613 | cp->Tag = cpu_to_le32(c->cmdindex << DIRECT_LOOKUP_SHIFT); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3614 | memcpy(cp->cdb, cdb, sizeof(cp->cdb)); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3615 | |
| 3616 | /* fill in sg elements */ |
| 3617 | cp->sg_count = (u8) use_sg; |
| 3618 | |
| 3619 | cp->data_len = cpu_to_le32(total_len); |
| 3620 | cp->err_ptr = cpu_to_le64(c->busaddr + |
| 3621 | offsetof(struct io_accel2_cmd, error_data)); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 3622 | cp->err_len = cpu_to_le32(sizeof(cp->error_data)); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3623 | |
| 3624 | enqueue_cmd_and_start_io(h, c); |
| 3625 | return 0; |
| 3626 | } |
| 3627 | |
| 3628 | /* |
| 3629 | * Queue a command to the correct I/O accelerator path. |
| 3630 | */ |
| 3631 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 3632 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3633 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3634 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3635 | /* Try to honor the device's queue depth */ |
| 3636 | if (atomic_inc_return(&phys_disk->ioaccel_cmds_out) > |
| 3637 | phys_disk->queue_depth) { |
| 3638 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
| 3639 | return IO_ACCEL_INELIGIBLE; |
| 3640 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3641 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 3642 | return hpsa_scsi_ioaccel1_queue_command(h, c, ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3643 | cdb, cdb_len, scsi3addr, |
| 3644 | phys_disk); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3645 | else |
| 3646 | return hpsa_scsi_ioaccel2_queue_command(h, c, ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3647 | cdb, cdb_len, scsi3addr, |
| 3648 | phys_disk); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 3649 | } |
| 3650 | |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3651 | static void raid_map_helper(struct raid_map_data *map, |
| 3652 | int offload_to_mirror, u32 *map_index, u32 *current_group) |
| 3653 | { |
| 3654 | if (offload_to_mirror == 0) { |
| 3655 | /* use physical disk in the first mirrored group. */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3656 | *map_index %= le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3657 | return; |
| 3658 | } |
| 3659 | do { |
| 3660 | /* determine mirror group that *map_index indicates */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3661 | *current_group = *map_index / |
| 3662 | le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3663 | if (offload_to_mirror == *current_group) |
| 3664 | continue; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3665 | if (*current_group < le16_to_cpu(map->layout_map_count) - 1) { |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3666 | /* select map index from next group */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3667 | *map_index += le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3668 | (*current_group)++; |
| 3669 | } else { |
| 3670 | /* select map index from first group */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3671 | *map_index %= le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3672 | *current_group = 0; |
| 3673 | } |
| 3674 | } while (offload_to_mirror != *current_group); |
| 3675 | } |
| 3676 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3677 | /* |
| 3678 | * Attempt to perform offload RAID mapping for a logical volume I/O. |
| 3679 | */ |
| 3680 | static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h, |
| 3681 | struct CommandList *c) |
| 3682 | { |
| 3683 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 3684 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 3685 | struct raid_map_data *map = &dev->raid_map; |
| 3686 | struct raid_map_disk_data *dd = &map->data[0]; |
| 3687 | int is_write = 0; |
| 3688 | u32 map_index; |
| 3689 | u64 first_block, last_block; |
| 3690 | u32 block_cnt; |
| 3691 | u32 blocks_per_row; |
| 3692 | u64 first_row, last_row; |
| 3693 | u32 first_row_offset, last_row_offset; |
| 3694 | u32 first_column, last_column; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3695 | u64 r0_first_row, r0_last_row; |
| 3696 | u32 r5or6_blocks_per_row; |
| 3697 | u64 r5or6_first_row, r5or6_last_row; |
| 3698 | u32 r5or6_first_row_offset, r5or6_last_row_offset; |
| 3699 | u32 r5or6_first_column, r5or6_last_column; |
| 3700 | u32 total_disks_per_row; |
| 3701 | u32 stripesize; |
| 3702 | u32 first_group, last_group, current_group; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3703 | u32 map_row; |
| 3704 | u32 disk_handle; |
| 3705 | u64 disk_block; |
| 3706 | u32 disk_block_cnt; |
| 3707 | u8 cdb[16]; |
| 3708 | u8 cdb_len; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3709 | u16 strip_size; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3710 | #if BITS_PER_LONG == 32 |
| 3711 | u64 tmpdiv; |
| 3712 | #endif |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3713 | int offload_to_mirror; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3714 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3715 | /* check for valid opcode, get LBA and block count */ |
| 3716 | switch (cmd->cmnd[0]) { |
| 3717 | case WRITE_6: |
| 3718 | is_write = 1; |
| 3719 | case READ_6: |
| 3720 | first_block = |
| 3721 | (((u64) cmd->cmnd[2]) << 8) | |
| 3722 | cmd->cmnd[3]; |
| 3723 | block_cnt = cmd->cmnd[4]; |
Stephen M. Cameron | 3fa89a0 | 2014-07-03 10:18:14 -0500 | [diff] [blame] | 3724 | if (block_cnt == 0) |
| 3725 | block_cnt = 256; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3726 | break; |
| 3727 | case WRITE_10: |
| 3728 | is_write = 1; |
| 3729 | case READ_10: |
| 3730 | first_block = |
| 3731 | (((u64) cmd->cmnd[2]) << 24) | |
| 3732 | (((u64) cmd->cmnd[3]) << 16) | |
| 3733 | (((u64) cmd->cmnd[4]) << 8) | |
| 3734 | cmd->cmnd[5]; |
| 3735 | block_cnt = |
| 3736 | (((u32) cmd->cmnd[7]) << 8) | |
| 3737 | cmd->cmnd[8]; |
| 3738 | break; |
| 3739 | case WRITE_12: |
| 3740 | is_write = 1; |
| 3741 | case READ_12: |
| 3742 | first_block = |
| 3743 | (((u64) cmd->cmnd[2]) << 24) | |
| 3744 | (((u64) cmd->cmnd[3]) << 16) | |
| 3745 | (((u64) cmd->cmnd[4]) << 8) | |
| 3746 | cmd->cmnd[5]; |
| 3747 | block_cnt = |
| 3748 | (((u32) cmd->cmnd[6]) << 24) | |
| 3749 | (((u32) cmd->cmnd[7]) << 16) | |
| 3750 | (((u32) cmd->cmnd[8]) << 8) | |
| 3751 | cmd->cmnd[9]; |
| 3752 | break; |
| 3753 | case WRITE_16: |
| 3754 | is_write = 1; |
| 3755 | case READ_16: |
| 3756 | first_block = |
| 3757 | (((u64) cmd->cmnd[2]) << 56) | |
| 3758 | (((u64) cmd->cmnd[3]) << 48) | |
| 3759 | (((u64) cmd->cmnd[4]) << 40) | |
| 3760 | (((u64) cmd->cmnd[5]) << 32) | |
| 3761 | (((u64) cmd->cmnd[6]) << 24) | |
| 3762 | (((u64) cmd->cmnd[7]) << 16) | |
| 3763 | (((u64) cmd->cmnd[8]) << 8) | |
| 3764 | cmd->cmnd[9]; |
| 3765 | block_cnt = |
| 3766 | (((u32) cmd->cmnd[10]) << 24) | |
| 3767 | (((u32) cmd->cmnd[11]) << 16) | |
| 3768 | (((u32) cmd->cmnd[12]) << 8) | |
| 3769 | cmd->cmnd[13]; |
| 3770 | break; |
| 3771 | default: |
| 3772 | return IO_ACCEL_INELIGIBLE; /* process via normal I/O path */ |
| 3773 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3774 | last_block = first_block + block_cnt - 1; |
| 3775 | |
| 3776 | /* check for write to non-RAID-0 */ |
| 3777 | if (is_write && dev->raid_level != 0) |
| 3778 | return IO_ACCEL_INELIGIBLE; |
| 3779 | |
| 3780 | /* check for invalid block or wraparound */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3781 | if (last_block >= le64_to_cpu(map->volume_blk_cnt) || |
| 3782 | last_block < first_block) |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3783 | return IO_ACCEL_INELIGIBLE; |
| 3784 | |
| 3785 | /* calculate stripe information for the request */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3786 | blocks_per_row = le16_to_cpu(map->data_disks_per_row) * |
| 3787 | le16_to_cpu(map->strip_size); |
| 3788 | strip_size = le16_to_cpu(map->strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3789 | #if BITS_PER_LONG == 32 |
| 3790 | tmpdiv = first_block; |
| 3791 | (void) do_div(tmpdiv, blocks_per_row); |
| 3792 | first_row = tmpdiv; |
| 3793 | tmpdiv = last_block; |
| 3794 | (void) do_div(tmpdiv, blocks_per_row); |
| 3795 | last_row = tmpdiv; |
| 3796 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 3797 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
| 3798 | tmpdiv = first_row_offset; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3799 | (void) do_div(tmpdiv, strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3800 | first_column = tmpdiv; |
| 3801 | tmpdiv = last_row_offset; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3802 | (void) do_div(tmpdiv, strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3803 | last_column = tmpdiv; |
| 3804 | #else |
| 3805 | first_row = first_block / blocks_per_row; |
| 3806 | last_row = last_block / blocks_per_row; |
| 3807 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 3808 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3809 | first_column = first_row_offset / strip_size; |
| 3810 | last_column = last_row_offset / strip_size; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3811 | #endif |
| 3812 | |
| 3813 | /* if this isn't a single row/column then give to the controller */ |
| 3814 | if ((first_row != last_row) || (first_column != last_column)) |
| 3815 | return IO_ACCEL_INELIGIBLE; |
| 3816 | |
| 3817 | /* proceeding with driver mapping */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3818 | total_disks_per_row = le16_to_cpu(map->data_disks_per_row) + |
| 3819 | le16_to_cpu(map->metadata_disks_per_row); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3820 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3821 | le16_to_cpu(map->row_cnt); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3822 | map_index = (map_row * total_disks_per_row) + first_column; |
| 3823 | |
| 3824 | switch (dev->raid_level) { |
| 3825 | case HPSA_RAID_0: |
| 3826 | break; /* nothing special to do */ |
| 3827 | case HPSA_RAID_1: |
| 3828 | /* Handles load balance across RAID 1 members. |
| 3829 | * (2-drive R1 and R10 with even # of drives.) |
| 3830 | * Appropriate for SSDs, not optimal for HDDs |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3831 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3832 | BUG_ON(le16_to_cpu(map->layout_map_count) != 2); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3833 | if (dev->offload_to_mirror) |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3834 | map_index += le16_to_cpu(map->data_disks_per_row); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3835 | dev->offload_to_mirror = !dev->offload_to_mirror; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3836 | break; |
| 3837 | case HPSA_RAID_ADM: |
| 3838 | /* Handles N-way mirrors (R1-ADM) |
| 3839 | * and R10 with # of drives divisible by 3.) |
| 3840 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3841 | BUG_ON(le16_to_cpu(map->layout_map_count) != 3); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3842 | |
| 3843 | offload_to_mirror = dev->offload_to_mirror; |
| 3844 | raid_map_helper(map, offload_to_mirror, |
| 3845 | &map_index, ¤t_group); |
| 3846 | /* set mirror group to use next time */ |
| 3847 | offload_to_mirror = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3848 | (offload_to_mirror >= |
| 3849 | le16_to_cpu(map->layout_map_count) - 1) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3850 | ? 0 : offload_to_mirror + 1; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3851 | dev->offload_to_mirror = offload_to_mirror; |
| 3852 | /* Avoid direct use of dev->offload_to_mirror within this |
| 3853 | * function since multiple threads might simultaneously |
| 3854 | * increment it beyond the range of dev->layout_map_count -1. |
| 3855 | */ |
| 3856 | break; |
| 3857 | case HPSA_RAID_5: |
| 3858 | case HPSA_RAID_6: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3859 | if (le16_to_cpu(map->layout_map_count) <= 1) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3860 | break; |
| 3861 | |
| 3862 | /* Verify first and last block are in same RAID group */ |
| 3863 | r5or6_blocks_per_row = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3864 | le16_to_cpu(map->strip_size) * |
| 3865 | le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3866 | BUG_ON(r5or6_blocks_per_row == 0); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3867 | stripesize = r5or6_blocks_per_row * |
| 3868 | le16_to_cpu(map->layout_map_count); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3869 | #if BITS_PER_LONG == 32 |
| 3870 | tmpdiv = first_block; |
| 3871 | first_group = do_div(tmpdiv, stripesize); |
| 3872 | tmpdiv = first_group; |
| 3873 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 3874 | first_group = tmpdiv; |
| 3875 | tmpdiv = last_block; |
| 3876 | last_group = do_div(tmpdiv, stripesize); |
| 3877 | tmpdiv = last_group; |
| 3878 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 3879 | last_group = tmpdiv; |
| 3880 | #else |
| 3881 | first_group = (first_block % stripesize) / r5or6_blocks_per_row; |
| 3882 | last_group = (last_block % stripesize) / r5or6_blocks_per_row; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3883 | #endif |
Stephen M. Cameron | 000ff7c | 2014-03-13 17:12:50 -0500 | [diff] [blame] | 3884 | if (first_group != last_group) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3885 | return IO_ACCEL_INELIGIBLE; |
| 3886 | |
| 3887 | /* Verify request is in a single row of RAID 5/6 */ |
| 3888 | #if BITS_PER_LONG == 32 |
| 3889 | tmpdiv = first_block; |
| 3890 | (void) do_div(tmpdiv, stripesize); |
| 3891 | first_row = r5or6_first_row = r0_first_row = tmpdiv; |
| 3892 | tmpdiv = last_block; |
| 3893 | (void) do_div(tmpdiv, stripesize); |
| 3894 | r5or6_last_row = r0_last_row = tmpdiv; |
| 3895 | #else |
| 3896 | first_row = r5or6_first_row = r0_first_row = |
| 3897 | first_block / stripesize; |
| 3898 | r5or6_last_row = r0_last_row = last_block / stripesize; |
| 3899 | #endif |
| 3900 | if (r5or6_first_row != r5or6_last_row) |
| 3901 | return IO_ACCEL_INELIGIBLE; |
| 3902 | |
| 3903 | |
| 3904 | /* Verify request is in a single column */ |
| 3905 | #if BITS_PER_LONG == 32 |
| 3906 | tmpdiv = first_block; |
| 3907 | first_row_offset = do_div(tmpdiv, stripesize); |
| 3908 | tmpdiv = first_row_offset; |
| 3909 | first_row_offset = (u32) do_div(tmpdiv, r5or6_blocks_per_row); |
| 3910 | r5or6_first_row_offset = first_row_offset; |
| 3911 | tmpdiv = last_block; |
| 3912 | r5or6_last_row_offset = do_div(tmpdiv, stripesize); |
| 3913 | tmpdiv = r5or6_last_row_offset; |
| 3914 | r5or6_last_row_offset = do_div(tmpdiv, r5or6_blocks_per_row); |
| 3915 | tmpdiv = r5or6_first_row_offset; |
| 3916 | (void) do_div(tmpdiv, map->strip_size); |
| 3917 | first_column = r5or6_first_column = tmpdiv; |
| 3918 | tmpdiv = r5or6_last_row_offset; |
| 3919 | (void) do_div(tmpdiv, map->strip_size); |
| 3920 | r5or6_last_column = tmpdiv; |
| 3921 | #else |
| 3922 | first_row_offset = r5or6_first_row_offset = |
| 3923 | (u32)((first_block % stripesize) % |
| 3924 | r5or6_blocks_per_row); |
| 3925 | |
| 3926 | r5or6_last_row_offset = |
| 3927 | (u32)((last_block % stripesize) % |
| 3928 | r5or6_blocks_per_row); |
| 3929 | |
| 3930 | first_column = r5or6_first_column = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3931 | r5or6_first_row_offset / le16_to_cpu(map->strip_size); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3932 | r5or6_last_column = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3933 | r5or6_last_row_offset / le16_to_cpu(map->strip_size); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3934 | #endif |
| 3935 | if (r5or6_first_column != r5or6_last_column) |
| 3936 | return IO_ACCEL_INELIGIBLE; |
| 3937 | |
| 3938 | /* Request is eligible */ |
| 3939 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3940 | le16_to_cpu(map->row_cnt); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3941 | |
| 3942 | map_index = (first_group * |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3943 | (le16_to_cpu(map->row_cnt) * total_disks_per_row)) + |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3944 | (map_row * total_disks_per_row) + first_column; |
| 3945 | break; |
| 3946 | default: |
| 3947 | return IO_ACCEL_INELIGIBLE; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3948 | } |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 3949 | |
Stephen Cameron | 07543e0 | 2015-01-23 16:44:14 -0600 | [diff] [blame] | 3950 | if (unlikely(map_index >= RAID_MAP_MAX_ENTRIES)) |
| 3951 | return IO_ACCEL_INELIGIBLE; |
| 3952 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3953 | c->phys_disk = dev->phys_disk[map_index]; |
| 3954 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3955 | disk_handle = dd[map_index].ioaccel_handle; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3956 | disk_block = le64_to_cpu(map->disk_starting_blk) + |
| 3957 | first_row * le16_to_cpu(map->strip_size) + |
| 3958 | (first_row_offset - first_column * |
| 3959 | le16_to_cpu(map->strip_size)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3960 | disk_block_cnt = block_cnt; |
| 3961 | |
| 3962 | /* handle differing logical/physical block sizes */ |
| 3963 | if (map->phys_blk_shift) { |
| 3964 | disk_block <<= map->phys_blk_shift; |
| 3965 | disk_block_cnt <<= map->phys_blk_shift; |
| 3966 | } |
| 3967 | BUG_ON(disk_block_cnt > 0xffff); |
| 3968 | |
| 3969 | /* build the new CDB for the physical disk I/O */ |
| 3970 | if (disk_block > 0xffffffff) { |
| 3971 | cdb[0] = is_write ? WRITE_16 : READ_16; |
| 3972 | cdb[1] = 0; |
| 3973 | cdb[2] = (u8) (disk_block >> 56); |
| 3974 | cdb[3] = (u8) (disk_block >> 48); |
| 3975 | cdb[4] = (u8) (disk_block >> 40); |
| 3976 | cdb[5] = (u8) (disk_block >> 32); |
| 3977 | cdb[6] = (u8) (disk_block >> 24); |
| 3978 | cdb[7] = (u8) (disk_block >> 16); |
| 3979 | cdb[8] = (u8) (disk_block >> 8); |
| 3980 | cdb[9] = (u8) (disk_block); |
| 3981 | cdb[10] = (u8) (disk_block_cnt >> 24); |
| 3982 | cdb[11] = (u8) (disk_block_cnt >> 16); |
| 3983 | cdb[12] = (u8) (disk_block_cnt >> 8); |
| 3984 | cdb[13] = (u8) (disk_block_cnt); |
| 3985 | cdb[14] = 0; |
| 3986 | cdb[15] = 0; |
| 3987 | cdb_len = 16; |
| 3988 | } else { |
| 3989 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 3990 | cdb[1] = 0; |
| 3991 | cdb[2] = (u8) (disk_block >> 24); |
| 3992 | cdb[3] = (u8) (disk_block >> 16); |
| 3993 | cdb[4] = (u8) (disk_block >> 8); |
| 3994 | cdb[5] = (u8) (disk_block); |
| 3995 | cdb[6] = 0; |
| 3996 | cdb[7] = (u8) (disk_block_cnt >> 8); |
| 3997 | cdb[8] = (u8) (disk_block_cnt); |
| 3998 | cdb[9] = 0; |
| 3999 | cdb_len = 10; |
| 4000 | } |
| 4001 | return hpsa_scsi_ioaccel_queue_command(h, c, disk_handle, cdb, cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4002 | dev->scsi3addr, |
| 4003 | dev->phys_disk[map_index]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4004 | } |
| 4005 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 4006 | /* Submit commands down the "normal" RAID stack path */ |
| 4007 | static int hpsa_ciss_submit(struct ctlr_info *h, |
| 4008 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 4009 | unsigned char scsi3addr[]) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4010 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4011 | cmd->host_scribble = (unsigned char *) c; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4012 | c->cmd_type = CMD_SCSI; |
| 4013 | c->scsi_cmd = cmd; |
| 4014 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 4015 | memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 4016 | c->Header.tag = cpu_to_le64((c->cmdindex << DIRECT_LOOKUP_SHIFT)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4017 | |
| 4018 | /* Fill in the request block... */ |
| 4019 | |
| 4020 | c->Request.Timeout = 0; |
| 4021 | memset(c->Request.CDB, 0, sizeof(c->Request.CDB)); |
| 4022 | BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB)); |
| 4023 | c->Request.CDBLen = cmd->cmd_len; |
| 4024 | memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4025 | switch (cmd->sc_data_direction) { |
| 4026 | case DMA_TO_DEVICE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4027 | c->Request.type_attr_dir = |
| 4028 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4029 | break; |
| 4030 | case DMA_FROM_DEVICE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4031 | c->Request.type_attr_dir = |
| 4032 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4033 | break; |
| 4034 | case DMA_NONE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4035 | c->Request.type_attr_dir = |
| 4036 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4037 | break; |
| 4038 | case DMA_BIDIRECTIONAL: |
| 4039 | /* This can happen if a buggy application does a scsi passthru |
| 4040 | * and sets both inlen and outlen to non-zero. ( see |
| 4041 | * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) |
| 4042 | */ |
| 4043 | |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4044 | c->Request.type_attr_dir = |
| 4045 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_RSVD); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4046 | /* This is technically wrong, and hpsa controllers should |
| 4047 | * reject it with CMD_INVALID, which is the most correct |
| 4048 | * response, but non-fibre backends appear to let it |
| 4049 | * slide by, and give the same results as if this field |
| 4050 | * were set correctly. Either way is acceptable for |
| 4051 | * our purposes here. |
| 4052 | */ |
| 4053 | |
| 4054 | break; |
| 4055 | |
| 4056 | default: |
| 4057 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 4058 | cmd->sc_data_direction); |
| 4059 | BUG(); |
| 4060 | break; |
| 4061 | } |
| 4062 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4063 | if (hpsa_scatter_gather(h, c, cmd) < 0) { /* Fill SG list */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4064 | cmd_free(h, c); |
| 4065 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4066 | } |
| 4067 | enqueue_cmd_and_start_io(h, c); |
| 4068 | /* the cmd'll come back via intr handler in complete_scsi_command() */ |
| 4069 | return 0; |
| 4070 | } |
| 4071 | |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 4072 | static void hpsa_command_resubmit_worker(struct work_struct *work) |
| 4073 | { |
| 4074 | struct scsi_cmnd *cmd; |
| 4075 | struct hpsa_scsi_dev_t *dev; |
| 4076 | struct CommandList *c = |
| 4077 | container_of(work, struct CommandList, work); |
| 4078 | |
| 4079 | cmd = c->scsi_cmd; |
| 4080 | dev = cmd->device->hostdata; |
| 4081 | if (!dev) { |
| 4082 | cmd->result = DID_NO_CONNECT << 16; |
| 4083 | cmd->scsi_done(cmd); |
| 4084 | return; |
| 4085 | } |
| 4086 | if (hpsa_ciss_submit(c->h, c, cmd, dev->scsi3addr)) { |
| 4087 | /* |
| 4088 | * If we get here, it means dma mapping failed. Try |
| 4089 | * again via scsi mid layer, which will then get |
| 4090 | * SCSI_MLQUEUE_HOST_BUSY. |
| 4091 | */ |
| 4092 | cmd->result = DID_IMM_RETRY << 16; |
| 4093 | cmd->scsi_done(cmd); |
| 4094 | } |
| 4095 | } |
| 4096 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 4097 | /* Running in struct Scsi_Host->host_lock less mode */ |
| 4098 | static int hpsa_scsi_queue_command(struct Scsi_Host *sh, struct scsi_cmnd *cmd) |
| 4099 | { |
| 4100 | struct ctlr_info *h; |
| 4101 | struct hpsa_scsi_dev_t *dev; |
| 4102 | unsigned char scsi3addr[8]; |
| 4103 | struct CommandList *c; |
| 4104 | int rc = 0; |
| 4105 | |
| 4106 | /* Get the ptr to our adapter structure out of cmd->host. */ |
| 4107 | h = sdev_to_hba(cmd->device); |
| 4108 | dev = cmd->device->hostdata; |
| 4109 | if (!dev) { |
| 4110 | cmd->result = DID_NO_CONNECT << 16; |
| 4111 | cmd->scsi_done(cmd); |
| 4112 | return 0; |
| 4113 | } |
| 4114 | memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); |
| 4115 | |
| 4116 | if (unlikely(lockup_detected(h))) { |
| 4117 | cmd->result = DID_ERROR << 16; |
| 4118 | cmd->scsi_done(cmd); |
| 4119 | return 0; |
| 4120 | } |
| 4121 | c = cmd_alloc(h); |
| 4122 | if (c == NULL) { /* trouble... */ |
| 4123 | dev_err(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
| 4124 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4125 | } |
Stephen Cameron | 407863c | 2015-01-23 16:44:19 -0600 | [diff] [blame] | 4126 | if (unlikely(lockup_detected(h))) { |
| 4127 | cmd->result = DID_ERROR << 16; |
| 4128 | cmd_free(h, c); |
| 4129 | cmd->scsi_done(cmd); |
| 4130 | return 0; |
| 4131 | } |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 4132 | |
Stephen Cameron | 407863c | 2015-01-23 16:44:19 -0600 | [diff] [blame] | 4133 | /* |
| 4134 | * Call alternate submit routine for I/O accelerated commands. |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 4135 | * Retries always go down the normal I/O path. |
| 4136 | */ |
| 4137 | if (likely(cmd->retries == 0 && |
| 4138 | cmd->request->cmd_type == REQ_TYPE_FS && |
| 4139 | h->acciopath_status)) { |
| 4140 | |
| 4141 | cmd->host_scribble = (unsigned char *) c; |
| 4142 | c->cmd_type = CMD_SCSI; |
| 4143 | c->scsi_cmd = cmd; |
| 4144 | |
| 4145 | if (dev->offload_enabled) { |
| 4146 | rc = hpsa_scsi_ioaccel_raid_map(h, c); |
| 4147 | if (rc == 0) |
| 4148 | return 0; /* Sent on ioaccel path */ |
| 4149 | if (rc < 0) { /* scsi_dma_map failed. */ |
| 4150 | cmd_free(h, c); |
| 4151 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4152 | } |
| 4153 | } else if (dev->ioaccel_handle) { |
| 4154 | rc = hpsa_scsi_ioaccel_direct_map(h, c); |
| 4155 | if (rc == 0) |
| 4156 | return 0; /* Sent on direct map path */ |
| 4157 | if (rc < 0) { /* scsi_dma_map failed. */ |
| 4158 | cmd_free(h, c); |
| 4159 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4160 | } |
| 4161 | } |
| 4162 | } |
| 4163 | return hpsa_ciss_submit(h, c, cmd, scsi3addr); |
| 4164 | } |
| 4165 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 4166 | static void hpsa_scan_complete(struct ctlr_info *h) |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 4167 | { |
| 4168 | unsigned long flags; |
| 4169 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 4170 | spin_lock_irqsave(&h->scan_lock, flags); |
| 4171 | h->scan_finished = 1; |
| 4172 | wake_up_all(&h->scan_wait_queue); |
| 4173 | spin_unlock_irqrestore(&h->scan_lock, flags); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 4174 | } |
| 4175 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 4176 | static void hpsa_scan_start(struct Scsi_Host *sh) |
| 4177 | { |
| 4178 | struct ctlr_info *h = shost_to_hba(sh); |
| 4179 | unsigned long flags; |
| 4180 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 4181 | /* |
| 4182 | * Don't let rescans be initiated on a controller known to be locked |
| 4183 | * up. If the controller locks up *during* a rescan, that thread is |
| 4184 | * probably hosed, but at least we can prevent new rescan threads from |
| 4185 | * piling up on a locked up controller. |
| 4186 | */ |
| 4187 | if (unlikely(lockup_detected(h))) |
| 4188 | return hpsa_scan_complete(h); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 4189 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 4190 | /* wait until any scan already in progress is finished. */ |
| 4191 | while (1) { |
| 4192 | spin_lock_irqsave(&h->scan_lock, flags); |
| 4193 | if (h->scan_finished) |
| 4194 | break; |
| 4195 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 4196 | wait_event(h->scan_wait_queue, h->scan_finished); |
| 4197 | /* Note: We don't need to worry about a race between this |
| 4198 | * thread and driver unload because the midlayer will |
| 4199 | * have incremented the reference count, so unload won't |
| 4200 | * happen if we're in here. |
| 4201 | */ |
| 4202 | } |
| 4203 | h->scan_finished = 0; /* mark scan as in progress */ |
| 4204 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 4205 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 4206 | if (unlikely(lockup_detected(h))) |
| 4207 | return hpsa_scan_complete(h); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 4208 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 4209 | hpsa_update_scsi_devices(h, h->scsi_host->host_no); |
| 4210 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 4211 | hpsa_scan_complete(h); |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 4212 | } |
| 4213 | |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 4214 | static int hpsa_change_queue_depth(struct scsi_device *sdev, int qdepth) |
| 4215 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4216 | struct hpsa_scsi_dev_t *logical_drive = sdev->hostdata; |
| 4217 | |
| 4218 | if (!logical_drive) |
| 4219 | return -ENODEV; |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 4220 | |
| 4221 | if (qdepth < 1) |
| 4222 | qdepth = 1; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4223 | else if (qdepth > logical_drive->queue_depth) |
| 4224 | qdepth = logical_drive->queue_depth; |
| 4225 | |
| 4226 | return scsi_change_queue_depth(sdev, qdepth); |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 4227 | } |
| 4228 | |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 4229 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 4230 | unsigned long elapsed_time) |
| 4231 | { |
| 4232 | struct ctlr_info *h = shost_to_hba(sh); |
| 4233 | unsigned long flags; |
| 4234 | int finished; |
| 4235 | |
| 4236 | spin_lock_irqsave(&h->scan_lock, flags); |
| 4237 | finished = h->scan_finished; |
| 4238 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 4239 | return finished; |
| 4240 | } |
| 4241 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4242 | static void hpsa_unregister_scsi(struct ctlr_info *h) |
| 4243 | { |
| 4244 | /* we are being forcibly unloaded, and may not refuse. */ |
| 4245 | scsi_remove_host(h->scsi_host); |
| 4246 | scsi_host_put(h->scsi_host); |
| 4247 | h->scsi_host = NULL; |
| 4248 | } |
| 4249 | |
| 4250 | static int hpsa_register_scsi(struct ctlr_info *h) |
| 4251 | { |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 4252 | struct Scsi_Host *sh; |
| 4253 | int error; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4254 | |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 4255 | sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h)); |
| 4256 | if (sh == NULL) |
| 4257 | goto fail; |
| 4258 | |
| 4259 | sh->io_port = 0; |
| 4260 | sh->n_io_port = 0; |
| 4261 | sh->this_id = -1; |
| 4262 | sh->max_channel = 3; |
| 4263 | sh->max_cmd_len = MAX_COMMAND_SIZE; |
| 4264 | sh->max_lun = HPSA_MAX_LUN; |
| 4265 | sh->max_id = HPSA_MAX_LUN; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 4266 | sh->can_queue = h->nr_cmds - HPSA_NRESERVED_CMDS; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4267 | sh->cmd_per_lun = sh->can_queue; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 4268 | sh->sg_tablesize = h->maxsgentries; |
| 4269 | h->scsi_host = sh; |
| 4270 | sh->hostdata[0] = (unsigned long) h; |
| 4271 | sh->irq = h->intr[h->intr_mode]; |
| 4272 | sh->unique_id = sh->irq; |
| 4273 | error = scsi_add_host(sh, &h->pdev->dev); |
| 4274 | if (error) |
| 4275 | goto fail_host_put; |
| 4276 | scsi_scan_host(sh); |
| 4277 | return 0; |
| 4278 | |
| 4279 | fail_host_put: |
| 4280 | dev_err(&h->pdev->dev, "%s: scsi_add_host" |
| 4281 | " failed for controller %d\n", __func__, h->ctlr); |
| 4282 | scsi_host_put(sh); |
| 4283 | return error; |
| 4284 | fail: |
| 4285 | dev_err(&h->pdev->dev, "%s: scsi_host_alloc" |
| 4286 | " failed for controller %d\n", __func__, h->ctlr); |
| 4287 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | static int wait_for_device_to_become_ready(struct ctlr_info *h, |
| 4291 | unsigned char lunaddr[]) |
| 4292 | { |
Tomas Henzl | 8919358 | 2014-02-21 16:25:05 -0600 | [diff] [blame] | 4293 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4294 | int count = 0; |
| 4295 | int waittime = 1; /* seconds */ |
| 4296 | struct CommandList *c; |
| 4297 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4298 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4299 | if (!c) { |
| 4300 | dev_warn(&h->pdev->dev, "out of memory in " |
| 4301 | "wait_for_device_to_become_ready.\n"); |
| 4302 | return IO_ERROR; |
| 4303 | } |
| 4304 | |
| 4305 | /* Send test unit ready until device ready, or give up. */ |
| 4306 | while (count < HPSA_TUR_RETRY_LIMIT) { |
| 4307 | |
| 4308 | /* Wait for a bit. do this first, because if we send |
| 4309 | * the TUR right away, the reset will just abort it. |
| 4310 | */ |
| 4311 | msleep(1000 * waittime); |
| 4312 | count++; |
Tomas Henzl | 8919358 | 2014-02-21 16:25:05 -0600 | [diff] [blame] | 4313 | rc = 0; /* Device ready. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4314 | |
| 4315 | /* Increase wait time with each try, up to a point. */ |
| 4316 | if (waittime < HPSA_MAX_WAIT_INTERVAL_SECS) |
| 4317 | waittime = waittime * 2; |
| 4318 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 4319 | /* Send the Test Unit Ready, fill_cmd can't fail, no mapping */ |
| 4320 | (void) fill_cmd(c, TEST_UNIT_READY, h, |
| 4321 | NULL, 0, 0, lunaddr, TYPE_CMD); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4322 | hpsa_scsi_do_simple_cmd_core(h, c); |
| 4323 | /* no unmap needed here because no data xfer. */ |
| 4324 | |
| 4325 | if (c->err_info->CommandStatus == CMD_SUCCESS) |
| 4326 | break; |
| 4327 | |
| 4328 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 4329 | c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION && |
| 4330 | (c->err_info->SenseInfo[2] == NO_SENSE || |
| 4331 | c->err_info->SenseInfo[2] == UNIT_ATTENTION)) |
| 4332 | break; |
| 4333 | |
| 4334 | dev_warn(&h->pdev->dev, "waiting %d secs " |
| 4335 | "for device to become ready.\n", waittime); |
| 4336 | rc = 1; /* device not ready. */ |
| 4337 | } |
| 4338 | |
| 4339 | if (rc) |
| 4340 | dev_warn(&h->pdev->dev, "giving up on device.\n"); |
| 4341 | else |
| 4342 | dev_warn(&h->pdev->dev, "device is ready.\n"); |
| 4343 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4344 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4345 | return rc; |
| 4346 | } |
| 4347 | |
| 4348 | /* Need at least one of these error handlers to keep ../scsi/hosts.c from |
| 4349 | * complaining. Doing a host- or bus-reset can't do anything good here. |
| 4350 | */ |
| 4351 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) |
| 4352 | { |
| 4353 | int rc; |
| 4354 | struct ctlr_info *h; |
| 4355 | struct hpsa_scsi_dev_t *dev; |
| 4356 | |
| 4357 | /* find the controller to which the command to be aborted was sent */ |
| 4358 | h = sdev_to_hba(scsicmd->device); |
| 4359 | if (h == NULL) /* paranoia */ |
| 4360 | return FAILED; |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 4361 | |
| 4362 | if (lockup_detected(h)) |
| 4363 | return FAILED; |
| 4364 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4365 | dev = scsicmd->device->hostdata; |
| 4366 | if (!dev) { |
| 4367 | dev_err(&h->pdev->dev, "hpsa_eh_device_reset_handler: " |
| 4368 | "device lookup failed.\n"); |
| 4369 | return FAILED; |
| 4370 | } |
Stephen M. Cameron | d416b0c | 2010-02-04 08:43:21 -0600 | [diff] [blame] | 4371 | dev_warn(&h->pdev->dev, "resetting device %d:%d:%d:%d\n", |
| 4372 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4373 | /* 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] | 4374 | rc = hpsa_send_reset(h, dev->scsi3addr, HPSA_RESET_TYPE_LUN); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4375 | if (rc == 0 && wait_for_device_to_become_ready(h, dev->scsi3addr) == 0) |
| 4376 | return SUCCESS; |
| 4377 | |
| 4378 | dev_warn(&h->pdev->dev, "resetting device failed.\n"); |
| 4379 | return FAILED; |
| 4380 | } |
| 4381 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4382 | static void swizzle_abort_tag(u8 *tag) |
| 4383 | { |
| 4384 | u8 original_tag[8]; |
| 4385 | |
| 4386 | memcpy(original_tag, tag, 8); |
| 4387 | tag[0] = original_tag[3]; |
| 4388 | tag[1] = original_tag[2]; |
| 4389 | tag[2] = original_tag[1]; |
| 4390 | tag[3] = original_tag[0]; |
| 4391 | tag[4] = original_tag[7]; |
| 4392 | tag[5] = original_tag[6]; |
| 4393 | tag[6] = original_tag[5]; |
| 4394 | tag[7] = original_tag[4]; |
| 4395 | } |
| 4396 | |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4397 | static void hpsa_get_tag(struct ctlr_info *h, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4398 | struct CommandList *c, __le32 *taglower, __le32 *tagupper) |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4399 | { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4400 | u64 tag; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4401 | if (c->cmd_type == CMD_IOACCEL1) { |
| 4402 | struct io_accel1_cmd *cm1 = (struct io_accel1_cmd *) |
| 4403 | &h->ioaccel_cmd_pool[c->cmdindex]; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4404 | tag = le64_to_cpu(cm1->tag); |
| 4405 | *tagupper = cpu_to_le32(tag >> 32); |
| 4406 | *taglower = cpu_to_le32(tag); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4407 | return; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4408 | } |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4409 | if (c->cmd_type == CMD_IOACCEL2) { |
| 4410 | struct io_accel2_cmd *cm2 = (struct io_accel2_cmd *) |
| 4411 | &h->ioaccel2_cmd_pool[c->cmdindex]; |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4412 | /* upper tag not used in ioaccel2 mode */ |
| 4413 | memset(tagupper, 0, sizeof(*tagupper)); |
| 4414 | *taglower = cm2->Tag; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4415 | return; |
| 4416 | } |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4417 | tag = le64_to_cpu(c->Header.tag); |
| 4418 | *tagupper = cpu_to_le32(tag >> 32); |
| 4419 | *taglower = cpu_to_le32(tag); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4420 | } |
| 4421 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4422 | 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] | 4423 | struct CommandList *abort, int swizzle) |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4424 | { |
| 4425 | int rc = IO_OK; |
| 4426 | struct CommandList *c; |
| 4427 | struct ErrorInfo *ei; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4428 | __le32 tagupper, taglower; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4429 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4430 | c = cmd_alloc(h); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4431 | if (c == NULL) { /* trouble... */ |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4432 | dev_warn(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4433 | return -ENOMEM; |
| 4434 | } |
| 4435 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 4436 | /* fill_cmd can't fail here, no buffer to map */ |
| 4437 | (void) fill_cmd(c, HPSA_ABORT_MSG, h, abort, |
| 4438 | 0, 0, scsi3addr, TYPE_MSG); |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4439 | if (swizzle) |
| 4440 | swizzle_abort_tag(&c->Request.CDB[4]); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4441 | hpsa_scsi_do_simple_cmd_core(h, c); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4442 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4443 | 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] | 4444 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4445 | /* no unmap needed here because no data xfer. */ |
| 4446 | |
| 4447 | ei = c->err_info; |
| 4448 | switch (ei->CommandStatus) { |
| 4449 | case CMD_SUCCESS: |
| 4450 | break; |
| 4451 | case CMD_UNABORTABLE: /* Very common, don't make noise. */ |
| 4452 | rc = -1; |
| 4453 | break; |
| 4454 | default: |
| 4455 | 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] | 4456 | __func__, tagupper, taglower); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 4457 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4458 | rc = -1; |
| 4459 | break; |
| 4460 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4461 | cmd_free(h, c); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4462 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", |
| 4463 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4464 | return rc; |
| 4465 | } |
| 4466 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4467 | /* ioaccel2 path firmware cannot handle abort task requests. |
| 4468 | * Change abort requests to physical target reset, and send to the |
| 4469 | * address of the physical disk used for the ioaccel 2 command. |
| 4470 | * Return 0 on success (IO_OK) |
| 4471 | * -1 on failure |
| 4472 | */ |
| 4473 | |
| 4474 | static int hpsa_send_reset_as_abort_ioaccel2(struct ctlr_info *h, |
| 4475 | unsigned char *scsi3addr, struct CommandList *abort) |
| 4476 | { |
| 4477 | int rc = IO_OK; |
| 4478 | struct scsi_cmnd *scmd; /* scsi command within request being aborted */ |
| 4479 | struct hpsa_scsi_dev_t *dev; /* device to which scsi cmd was sent */ |
| 4480 | unsigned char phys_scsi3addr[8]; /* addr of phys disk with volume */ |
| 4481 | unsigned char *psa = &phys_scsi3addr[0]; |
| 4482 | |
| 4483 | /* Get a pointer to the hpsa logical device. */ |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 4484 | scmd = abort->scsi_cmd; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4485 | dev = (struct hpsa_scsi_dev_t *)(scmd->device->hostdata); |
| 4486 | if (dev == NULL) { |
| 4487 | dev_warn(&h->pdev->dev, |
| 4488 | "Cannot abort: no device pointer for command.\n"); |
| 4489 | return -1; /* not abortable */ |
| 4490 | } |
| 4491 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 4492 | if (h->raid_offload_debug > 0) |
| 4493 | dev_info(&h->pdev->dev, |
| 4494 | "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", |
| 4495 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun, |
| 4496 | scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3], |
| 4497 | scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); |
| 4498 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4499 | if (!dev->offload_enabled) { |
| 4500 | dev_warn(&h->pdev->dev, |
| 4501 | "Can't abort: device is not operating in HP SSD Smart Path mode.\n"); |
| 4502 | return -1; /* not abortable */ |
| 4503 | } |
| 4504 | |
| 4505 | /* Incoming scsi3addr is logical addr. We need physical disk addr. */ |
| 4506 | if (!hpsa_get_pdisk_of_ioaccel2(h, abort, psa)) { |
| 4507 | dev_warn(&h->pdev->dev, "Can't abort: Failed lookup of physical address.\n"); |
| 4508 | return -1; /* not abortable */ |
| 4509 | } |
| 4510 | |
| 4511 | /* send the reset */ |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 4512 | if (h->raid_offload_debug > 0) |
| 4513 | dev_info(&h->pdev->dev, |
| 4514 | "Reset as abort: Resetting physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4515 | psa[0], psa[1], psa[2], psa[3], |
| 4516 | psa[4], psa[5], psa[6], psa[7]); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4517 | rc = hpsa_send_reset(h, psa, HPSA_RESET_TYPE_TARGET); |
| 4518 | if (rc != 0) { |
| 4519 | dev_warn(&h->pdev->dev, |
| 4520 | "Reset as abort: Failed on physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4521 | psa[0], psa[1], psa[2], psa[3], |
| 4522 | psa[4], psa[5], psa[6], psa[7]); |
| 4523 | return rc; /* failed to reset */ |
| 4524 | } |
| 4525 | |
| 4526 | /* wait for device to recover */ |
| 4527 | if (wait_for_device_to_become_ready(h, psa) != 0) { |
| 4528 | dev_warn(&h->pdev->dev, |
| 4529 | "Reset as abort: Failed: Device never recovered from reset: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4530 | psa[0], psa[1], psa[2], psa[3], |
| 4531 | psa[4], psa[5], psa[6], psa[7]); |
| 4532 | return -1; /* failed to recover */ |
| 4533 | } |
| 4534 | |
| 4535 | /* device recovered */ |
| 4536 | dev_info(&h->pdev->dev, |
| 4537 | "Reset as abort: Device recovered from reset: scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 4538 | psa[0], psa[1], psa[2], psa[3], |
| 4539 | psa[4], psa[5], psa[6], psa[7]); |
| 4540 | |
| 4541 | return rc; /* success */ |
| 4542 | } |
| 4543 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4544 | /* Some Smart Arrays need the abort tag swizzled, and some don't. It's hard to |
| 4545 | * tell which kind we're dealing with, so we send the abort both ways. There |
| 4546 | * shouldn't be any collisions between swizzled and unswizzled tags due to the |
| 4547 | * way we construct our tags but we check anyway in case the assumptions which |
| 4548 | * make this true someday become false. |
| 4549 | */ |
| 4550 | static int hpsa_send_abort_both_ways(struct ctlr_info *h, |
| 4551 | unsigned char *scsi3addr, struct CommandList *abort) |
| 4552 | { |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4553 | /* ioccelerator mode 2 commands should be aborted via the |
| 4554 | * accelerated path, since RAID path is unaware of these commands, |
| 4555 | * but underlying firmware can't handle abort TMF. |
| 4556 | * Change abort to physical device reset. |
| 4557 | */ |
| 4558 | if (abort->cmd_type == CMD_IOACCEL2) |
| 4559 | return hpsa_send_reset_as_abort_ioaccel2(h, scsi3addr, abort); |
| 4560 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 4561 | return hpsa_send_abort(h, scsi3addr, abort, 0) && |
| 4562 | hpsa_send_abort(h, scsi3addr, abort, 1); |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4563 | } |
| 4564 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4565 | /* Send an abort for the specified command. |
| 4566 | * If the device and controller support it, |
| 4567 | * send a task abort request. |
| 4568 | */ |
| 4569 | static int hpsa_eh_abort_handler(struct scsi_cmnd *sc) |
| 4570 | { |
| 4571 | |
| 4572 | int i, rc; |
| 4573 | struct ctlr_info *h; |
| 4574 | struct hpsa_scsi_dev_t *dev; |
| 4575 | struct CommandList *abort; /* pointer to command to be aborted */ |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4576 | struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ |
| 4577 | char msg[256]; /* For debug messaging. */ |
| 4578 | int ml = 0; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4579 | __le32 tagupper, taglower; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4580 | int refcount; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4581 | |
| 4582 | /* Find the controller of the command to be aborted */ |
| 4583 | h = sdev_to_hba(sc->device); |
| 4584 | if (WARN(h == NULL, |
| 4585 | "ABORT REQUEST FAILED, Controller lookup failed.\n")) |
| 4586 | return FAILED; |
| 4587 | |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 4588 | if (lockup_detected(h)) |
| 4589 | return FAILED; |
| 4590 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4591 | /* Check that controller supports some kind of task abort */ |
| 4592 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags) && |
| 4593 | !(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 4594 | return FAILED; |
| 4595 | |
| 4596 | memset(msg, 0, sizeof(msg)); |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 4597 | ml += sprintf(msg+ml, "ABORT REQUEST on C%d:B%d:T%d:L%llu ", |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4598 | h->scsi_host->host_no, sc->device->channel, |
| 4599 | sc->device->id, sc->device->lun); |
| 4600 | |
| 4601 | /* Find the device of the command to be aborted */ |
| 4602 | dev = sc->device->hostdata; |
| 4603 | if (!dev) { |
| 4604 | dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", |
| 4605 | msg); |
| 4606 | return FAILED; |
| 4607 | } |
| 4608 | |
| 4609 | /* Get SCSI command to be aborted */ |
| 4610 | abort = (struct CommandList *) sc->host_scribble; |
| 4611 | if (abort == NULL) { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4612 | /* This can happen if the command already completed. */ |
| 4613 | return SUCCESS; |
| 4614 | } |
| 4615 | refcount = atomic_inc_return(&abort->refcount); |
| 4616 | if (refcount == 1) { /* Command is done already. */ |
| 4617 | cmd_free(h, abort); |
| 4618 | return SUCCESS; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4619 | } |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 4620 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
| 4621 | ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", tagupper, taglower); |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 4622 | as = abort->scsi_cmd; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4623 | if (as != NULL) |
| 4624 | ml += sprintf(msg+ml, "Command:0x%x SN:0x%lx ", |
| 4625 | as->cmnd[0], as->serial_number); |
| 4626 | dev_dbg(&h->pdev->dev, "%s\n", msg); |
| 4627 | dev_warn(&h->pdev->dev, "Abort request on C%d:B%d:T%d:L%d\n", |
| 4628 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4629 | /* |
| 4630 | * Command is in flight, or possibly already completed |
| 4631 | * by the firmware (but not to the scsi mid layer) but we can't |
| 4632 | * distinguish which. Send the abort down. |
| 4633 | */ |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 4634 | rc = hpsa_send_abort_both_ways(h, dev->scsi3addr, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4635 | if (rc != 0) { |
| 4636 | dev_dbg(&h->pdev->dev, "%s Request FAILED.\n", msg); |
| 4637 | dev_warn(&h->pdev->dev, "FAILED abort on device C%d:B%d:T%d:L%d\n", |
| 4638 | h->scsi_host->host_no, |
| 4639 | dev->bus, dev->target, dev->lun); |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4640 | cmd_free(h, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4641 | return FAILED; |
| 4642 | } |
| 4643 | dev_info(&h->pdev->dev, "%s REQUEST SUCCEEDED.\n", msg); |
| 4644 | |
| 4645 | /* If the abort(s) above completed and actually aborted the |
| 4646 | * command, then the command to be aborted should already be |
| 4647 | * completed. If not, wait around a bit more to see if they |
| 4648 | * manage to complete normally. |
| 4649 | */ |
| 4650 | #define ABORT_COMPLETE_WAIT_SECS 30 |
| 4651 | for (i = 0; i < ABORT_COMPLETE_WAIT_SECS * 10; i++) { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4652 | refcount = atomic_read(&abort->refcount); |
| 4653 | if (refcount < 2) { |
| 4654 | cmd_free(h, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4655 | return SUCCESS; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4656 | } else { |
| 4657 | msleep(100); |
| 4658 | } |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4659 | } |
| 4660 | dev_warn(&h->pdev->dev, "%s FAILED. Aborted command has not completed after %d seconds.\n", |
| 4661 | msg, ABORT_COMPLETE_WAIT_SECS); |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4662 | cmd_free(h, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 4663 | return FAILED; |
| 4664 | } |
| 4665 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4666 | /* |
| 4667 | * For operations that cannot sleep, a command block is allocated at init, |
| 4668 | * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track |
| 4669 | * which ones are free or in use. Lock must be held when calling this. |
| 4670 | * cmd_free() is the complement. |
| 4671 | */ |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4672 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4673 | static struct CommandList *cmd_alloc(struct ctlr_info *h) |
| 4674 | { |
| 4675 | struct CommandList *c; |
| 4676 | int i; |
| 4677 | union u64bit temp64; |
| 4678 | dma_addr_t cmd_dma_handle, err_dma_handle; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4679 | int refcount; |
Robert Elliott | 3381102 | 2015-01-23 16:43:41 -0600 | [diff] [blame] | 4680 | unsigned long offset; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4681 | |
Robert Elliott | 3381102 | 2015-01-23 16:43:41 -0600 | [diff] [blame] | 4682 | /* |
| 4683 | * There is some *extremely* small but non-zero chance that that |
Stephen M. Cameron | 4c41312 | 2014-11-14 17:27:29 -0600 | [diff] [blame] | 4684 | * multiple threads could get in here, and one thread could |
| 4685 | * be scanning through the list of bits looking for a free |
| 4686 | * one, but the free ones are always behind him, and other |
| 4687 | * threads sneak in behind him and eat them before he can |
| 4688 | * get to them, so that while there is always a free one, a |
| 4689 | * very unlucky thread might be starved anyway, never able to |
| 4690 | * beat the other threads. In reality, this happens so |
| 4691 | * infrequently as to be indistinguishable from never. |
| 4692 | */ |
| 4693 | |
Robert Elliott | 3381102 | 2015-01-23 16:43:41 -0600 | [diff] [blame] | 4694 | offset = h->last_allocation; /* benignly racy */ |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4695 | for (;;) { |
| 4696 | i = find_next_zero_bit(h->cmd_pool_bits, h->nr_cmds, offset); |
| 4697 | if (unlikely(i == h->nr_cmds)) { |
| 4698 | offset = 0; |
| 4699 | continue; |
| 4700 | } |
| 4701 | c = h->cmd_pool + i; |
| 4702 | refcount = atomic_inc_return(&c->refcount); |
| 4703 | if (unlikely(refcount > 1)) { |
| 4704 | cmd_free(h, c); /* already in use */ |
| 4705 | offset = (i + 1) % h->nr_cmds; |
| 4706 | continue; |
| 4707 | } |
| 4708 | set_bit(i & (BITS_PER_LONG - 1), |
| 4709 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 4710 | break; /* it's ours now. */ |
| 4711 | } |
Robert Elliott | 3381102 | 2015-01-23 16:43:41 -0600 | [diff] [blame] | 4712 | h->last_allocation = i; /* benignly racy */ |
Stephen M. Cameron | 4c41312 | 2014-11-14 17:27:29 -0600 | [diff] [blame] | 4713 | |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4714 | /* Zero out all of commandlist except the last field, refcount */ |
| 4715 | memset(c, 0, offsetof(struct CommandList, refcount)); |
| 4716 | c->Header.tag = cpu_to_le64((u64) (i << DIRECT_LOOKUP_SHIFT)); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 4717 | cmd_dma_handle = h->cmd_pool_dhandle + i * sizeof(*c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4718 | c->err_info = h->errinfo_pool + i; |
| 4719 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 4720 | err_dma_handle = h->errinfo_pool_dhandle |
| 4721 | + i * sizeof(*c->err_info); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4722 | |
| 4723 | c->cmdindex = i; |
| 4724 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4725 | c->busaddr = (u32) cmd_dma_handle; |
| 4726 | temp64.val = (u64) err_dma_handle; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4727 | c->ErrDesc.Addr = cpu_to_le64((u64) err_dma_handle); |
| 4728 | c->ErrDesc.Len = cpu_to_le32((u32) sizeof(*c->err_info)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4729 | |
| 4730 | c->h = h; |
| 4731 | return c; |
| 4732 | } |
| 4733 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4734 | static void cmd_free(struct ctlr_info *h, struct CommandList *c) |
| 4735 | { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4736 | if (atomic_dec_and_test(&c->refcount)) { |
| 4737 | int i; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4738 | |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 4739 | i = c - h->cmd_pool; |
| 4740 | clear_bit(i & (BITS_PER_LONG - 1), |
| 4741 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 4742 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4743 | } |
| 4744 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4745 | #ifdef CONFIG_COMPAT |
| 4746 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 4747 | static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, |
| 4748 | void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4749 | { |
| 4750 | IOCTL32_Command_struct __user *arg32 = |
| 4751 | (IOCTL32_Command_struct __user *) arg; |
| 4752 | IOCTL_Command_struct arg64; |
| 4753 | IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64)); |
| 4754 | int err; |
| 4755 | u32 cp; |
| 4756 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 4757 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4758 | err = 0; |
| 4759 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 4760 | sizeof(arg64.LUN_info)); |
| 4761 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 4762 | sizeof(arg64.Request)); |
| 4763 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 4764 | sizeof(arg64.error_info)); |
| 4765 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 4766 | err |= get_user(cp, &arg32->buf); |
| 4767 | arg64.buf = compat_ptr(cp); |
| 4768 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 4769 | |
| 4770 | if (err) |
| 4771 | return -EFAULT; |
| 4772 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 4773 | err = hpsa_ioctl(dev, CCISS_PASSTHRU, p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4774 | if (err) |
| 4775 | return err; |
| 4776 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 4777 | sizeof(arg32->error_info)); |
| 4778 | if (err) |
| 4779 | return -EFAULT; |
| 4780 | return err; |
| 4781 | } |
| 4782 | |
| 4783 | static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 4784 | int cmd, void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4785 | { |
| 4786 | BIG_IOCTL32_Command_struct __user *arg32 = |
| 4787 | (BIG_IOCTL32_Command_struct __user *) arg; |
| 4788 | BIG_IOCTL_Command_struct arg64; |
| 4789 | BIG_IOCTL_Command_struct __user *p = |
| 4790 | compat_alloc_user_space(sizeof(arg64)); |
| 4791 | int err; |
| 4792 | u32 cp; |
| 4793 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 4794 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4795 | err = 0; |
| 4796 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 4797 | sizeof(arg64.LUN_info)); |
| 4798 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 4799 | sizeof(arg64.Request)); |
| 4800 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 4801 | sizeof(arg64.error_info)); |
| 4802 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 4803 | err |= get_user(arg64.malloc_size, &arg32->malloc_size); |
| 4804 | err |= get_user(cp, &arg32->buf); |
| 4805 | arg64.buf = compat_ptr(cp); |
| 4806 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 4807 | |
| 4808 | if (err) |
| 4809 | return -EFAULT; |
| 4810 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 4811 | err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4812 | if (err) |
| 4813 | return err; |
| 4814 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 4815 | sizeof(arg32->error_info)); |
| 4816 | if (err) |
| 4817 | return -EFAULT; |
| 4818 | return err; |
| 4819 | } |
Stephen M. Cameron | 71fe75a | 2010-02-04 08:43:51 -0600 | [diff] [blame] | 4820 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 4821 | static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void __user *arg) |
Stephen M. Cameron | 71fe75a | 2010-02-04 08:43:51 -0600 | [diff] [blame] | 4822 | { |
| 4823 | switch (cmd) { |
| 4824 | case CCISS_GETPCIINFO: |
| 4825 | case CCISS_GETINTINFO: |
| 4826 | case CCISS_SETINTINFO: |
| 4827 | case CCISS_GETNODENAME: |
| 4828 | case CCISS_SETNODENAME: |
| 4829 | case CCISS_GETHEARTBEAT: |
| 4830 | case CCISS_GETBUSTYPES: |
| 4831 | case CCISS_GETFIRMVER: |
| 4832 | case CCISS_GETDRIVVER: |
| 4833 | case CCISS_REVALIDVOLS: |
| 4834 | case CCISS_DEREGDISK: |
| 4835 | case CCISS_REGNEWDISK: |
| 4836 | case CCISS_REGNEWD: |
| 4837 | case CCISS_RESCANDISK: |
| 4838 | case CCISS_GETLUNINFO: |
| 4839 | return hpsa_ioctl(dev, cmd, arg); |
| 4840 | |
| 4841 | case CCISS_PASSTHRU32: |
| 4842 | return hpsa_ioctl32_passthru(dev, cmd, arg); |
| 4843 | case CCISS_BIG_PASSTHRU32: |
| 4844 | return hpsa_ioctl32_big_passthru(dev, cmd, arg); |
| 4845 | |
| 4846 | default: |
| 4847 | return -ENOIOCTLCMD; |
| 4848 | } |
| 4849 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4850 | #endif |
| 4851 | |
| 4852 | static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp) |
| 4853 | { |
| 4854 | struct hpsa_pci_info pciinfo; |
| 4855 | |
| 4856 | if (!argp) |
| 4857 | return -EINVAL; |
| 4858 | pciinfo.domain = pci_domain_nr(h->pdev->bus); |
| 4859 | pciinfo.bus = h->pdev->bus->number; |
| 4860 | pciinfo.dev_fn = h->pdev->devfn; |
| 4861 | pciinfo.board_id = h->board_id; |
| 4862 | if (copy_to_user(argp, &pciinfo, sizeof(pciinfo))) |
| 4863 | return -EFAULT; |
| 4864 | return 0; |
| 4865 | } |
| 4866 | |
| 4867 | static int hpsa_getdrivver_ioctl(struct ctlr_info *h, void __user *argp) |
| 4868 | { |
| 4869 | DriverVer_type DriverVer; |
| 4870 | unsigned char vmaj, vmin, vsubmin; |
| 4871 | int rc; |
| 4872 | |
| 4873 | rc = sscanf(HPSA_DRIVER_VERSION, "%hhu.%hhu.%hhu", |
| 4874 | &vmaj, &vmin, &vsubmin); |
| 4875 | if (rc != 3) { |
| 4876 | dev_info(&h->pdev->dev, "driver version string '%s' " |
| 4877 | "unrecognized.", HPSA_DRIVER_VERSION); |
| 4878 | vmaj = 0; |
| 4879 | vmin = 0; |
| 4880 | vsubmin = 0; |
| 4881 | } |
| 4882 | DriverVer = (vmaj << 16) | (vmin << 8) | vsubmin; |
| 4883 | if (!argp) |
| 4884 | return -EINVAL; |
| 4885 | if (copy_to_user(argp, &DriverVer, sizeof(DriverVer_type))) |
| 4886 | return -EFAULT; |
| 4887 | return 0; |
| 4888 | } |
| 4889 | |
| 4890 | static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 4891 | { |
| 4892 | IOCTL_Command_struct iocommand; |
| 4893 | struct CommandList *c; |
| 4894 | char *buff = NULL; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4895 | u64 temp64; |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4896 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4897 | |
| 4898 | if (!argp) |
| 4899 | return -EINVAL; |
| 4900 | if (!capable(CAP_SYS_RAWIO)) |
| 4901 | return -EPERM; |
| 4902 | if (copy_from_user(&iocommand, argp, sizeof(iocommand))) |
| 4903 | return -EFAULT; |
| 4904 | if ((iocommand.buf_size < 1) && |
| 4905 | (iocommand.Request.Type.Direction != XFER_NONE)) { |
| 4906 | return -EINVAL; |
| 4907 | } |
| 4908 | if (iocommand.buf_size > 0) { |
| 4909 | buff = kmalloc(iocommand.buf_size, GFP_KERNEL); |
| 4910 | if (buff == NULL) |
| 4911 | return -EFAULT; |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 4912 | if (iocommand.Request.Type.Direction & XFER_WRITE) { |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4913 | /* Copy the data into the buffer we created */ |
| 4914 | if (copy_from_user(buff, iocommand.buf, |
| 4915 | iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4916 | rc = -EFAULT; |
| 4917 | goto out_kfree; |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4918 | } |
| 4919 | } else { |
| 4920 | memset(buff, 0, iocommand.buf_size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4921 | } |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4922 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4923 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4924 | if (c == NULL) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4925 | rc = -ENOMEM; |
| 4926 | goto out_kfree; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4927 | } |
| 4928 | /* Fill in the command type */ |
| 4929 | c->cmd_type = CMD_IOCTL_PEND; |
| 4930 | /* Fill in Command Header */ |
| 4931 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 4932 | if (iocommand.buf_size > 0) { /* buffer to fill */ |
| 4933 | c->Header.SGList = 1; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4934 | c->Header.SGTotal = cpu_to_le16(1); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4935 | } else { /* no buffers to fill */ |
| 4936 | c->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4937 | c->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4938 | } |
| 4939 | memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4940 | |
| 4941 | /* Fill in Request block */ |
| 4942 | memcpy(&c->Request, &iocommand.Request, |
| 4943 | sizeof(c->Request)); |
| 4944 | |
| 4945 | /* Fill in the scatter gather information */ |
| 4946 | if (iocommand.buf_size > 0) { |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4947 | temp64 = pci_map_single(h->pdev, buff, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4948 | iocommand.buf_size, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4949 | if (dma_mapping_error(&h->pdev->dev, (dma_addr_t) temp64)) { |
| 4950 | c->SG[0].Addr = cpu_to_le64(0); |
| 4951 | c->SG[0].Len = cpu_to_le32(0); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 4952 | rc = -ENOMEM; |
| 4953 | goto out; |
| 4954 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4955 | c->SG[0].Addr = cpu_to_le64(temp64); |
| 4956 | c->SG[0].Len = cpu_to_le32(iocommand.buf_size); |
| 4957 | c->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* not chaining */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4958 | } |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 4959 | hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c); |
Stephen M. Cameron | c2dd32e | 2011-06-03 09:57:29 -0500 | [diff] [blame] | 4960 | if (iocommand.buf_size > 0) |
| 4961 | hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4962 | check_ioctl_unit_attention(h, c); |
| 4963 | |
| 4964 | /* Copy the error information out */ |
| 4965 | memcpy(&iocommand.error_info, c->err_info, |
| 4966 | sizeof(iocommand.error_info)); |
| 4967 | if (copy_to_user(argp, &iocommand, sizeof(iocommand))) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4968 | rc = -EFAULT; |
| 4969 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4970 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 4971 | if ((iocommand.Request.Type.Direction & XFER_READ) && |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 4972 | iocommand.buf_size > 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4973 | /* Copy the data out of the buffer we created */ |
| 4974 | if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4975 | rc = -EFAULT; |
| 4976 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4977 | } |
| 4978 | } |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4979 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 4980 | cmd_free(h, c); |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 4981 | out_kfree: |
| 4982 | kfree(buff); |
| 4983 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 4987 | { |
| 4988 | BIG_IOCTL_Command_struct *ioc; |
| 4989 | struct CommandList *c; |
| 4990 | unsigned char **buff = NULL; |
| 4991 | int *buff_size = NULL; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4992 | u64 temp64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4993 | BYTE sg_used = 0; |
| 4994 | int status = 0; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4995 | u32 left; |
| 4996 | u32 sz; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4997 | BYTE __user *data_ptr; |
| 4998 | |
| 4999 | if (!argp) |
| 5000 | return -EINVAL; |
| 5001 | if (!capable(CAP_SYS_RAWIO)) |
| 5002 | return -EPERM; |
| 5003 | ioc = (BIG_IOCTL_Command_struct *) |
| 5004 | kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 5005 | if (!ioc) { |
| 5006 | status = -ENOMEM; |
| 5007 | goto cleanup1; |
| 5008 | } |
| 5009 | if (copy_from_user(ioc, argp, sizeof(*ioc))) { |
| 5010 | status = -EFAULT; |
| 5011 | goto cleanup1; |
| 5012 | } |
| 5013 | if ((ioc->buf_size < 1) && |
| 5014 | (ioc->Request.Type.Direction != XFER_NONE)) { |
| 5015 | status = -EINVAL; |
| 5016 | goto cleanup1; |
| 5017 | } |
| 5018 | /* Check kmalloc limits using all SGs */ |
| 5019 | if (ioc->malloc_size > MAX_KMALLOC_SIZE) { |
| 5020 | status = -EINVAL; |
| 5021 | goto cleanup1; |
| 5022 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 5023 | if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5024 | status = -EINVAL; |
| 5025 | goto cleanup1; |
| 5026 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 5027 | buff = kzalloc(SG_ENTRIES_IN_CMD * sizeof(char *), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5028 | if (!buff) { |
| 5029 | status = -ENOMEM; |
| 5030 | goto cleanup1; |
| 5031 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 5032 | buff_size = kmalloc(SG_ENTRIES_IN_CMD * sizeof(int), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5033 | if (!buff_size) { |
| 5034 | status = -ENOMEM; |
| 5035 | goto cleanup1; |
| 5036 | } |
| 5037 | left = ioc->buf_size; |
| 5038 | data_ptr = ioc->buf; |
| 5039 | while (left) { |
| 5040 | sz = (left > ioc->malloc_size) ? ioc->malloc_size : left; |
| 5041 | buff_size[sg_used] = sz; |
| 5042 | buff[sg_used] = kmalloc(sz, GFP_KERNEL); |
| 5043 | if (buff[sg_used] == NULL) { |
| 5044 | status = -ENOMEM; |
| 5045 | goto cleanup1; |
| 5046 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 5047 | if (ioc->Request.Type.Direction & XFER_WRITE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5048 | if (copy_from_user(buff[sg_used], data_ptr, sz)) { |
Stephen M. Cameron | 0758f4f | 2014-07-03 10:18:03 -0500 | [diff] [blame] | 5049 | status = -EFAULT; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5050 | goto cleanup1; |
| 5051 | } |
| 5052 | } else |
| 5053 | memset(buff[sg_used], 0, sz); |
| 5054 | left -= sz; |
| 5055 | data_ptr += sz; |
| 5056 | sg_used++; |
| 5057 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5058 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5059 | if (c == NULL) { |
| 5060 | status = -ENOMEM; |
| 5061 | goto cleanup1; |
| 5062 | } |
| 5063 | c->cmd_type = CMD_IOCTL_PEND; |
| 5064 | c->Header.ReplyQueue = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5065 | c->Header.SGList = (u8) sg_used; |
| 5066 | c->Header.SGTotal = cpu_to_le16(sg_used); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5067 | memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5068 | memcpy(&c->Request, &ioc->Request, sizeof(c->Request)); |
| 5069 | if (ioc->buf_size > 0) { |
| 5070 | int i; |
| 5071 | for (i = 0; i < sg_used; i++) { |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5072 | temp64 = pci_map_single(h->pdev, buff[i], |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5073 | buff_size[i], PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5074 | if (dma_mapping_error(&h->pdev->dev, |
| 5075 | (dma_addr_t) temp64)) { |
| 5076 | c->SG[i].Addr = cpu_to_le64(0); |
| 5077 | c->SG[i].Len = cpu_to_le32(0); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 5078 | hpsa_pci_unmap(h->pdev, c, i, |
| 5079 | PCI_DMA_BIDIRECTIONAL); |
| 5080 | status = -ENOMEM; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 5081 | goto cleanup0; |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 5082 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5083 | c->SG[i].Addr = cpu_to_le64(temp64); |
| 5084 | c->SG[i].Len = cpu_to_le32(buff_size[i]); |
| 5085 | c->SG[i].Ext = cpu_to_le32(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5086 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5087 | c->SG[--i].Ext = cpu_to_le32(HPSA_SG_LAST); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5088 | } |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5089 | hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c); |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 5090 | if (sg_used) |
| 5091 | hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5092 | check_ioctl_unit_attention(h, c); |
| 5093 | /* Copy the error information out */ |
| 5094 | memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info)); |
| 5095 | if (copy_to_user(argp, ioc, sizeof(*ioc))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5096 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 5097 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5098 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 5099 | if ((ioc->Request.Type.Direction & XFER_READ) && ioc->buf_size > 0) { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5100 | int i; |
| 5101 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5102 | /* Copy the data out of the buffer we created */ |
| 5103 | BYTE __user *ptr = ioc->buf; |
| 5104 | for (i = 0; i < sg_used; i++) { |
| 5105 | if (copy_to_user(ptr, buff[i], buff_size[i])) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5106 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 5107 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5108 | } |
| 5109 | ptr += buff_size[i]; |
| 5110 | } |
| 5111 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5112 | status = 0; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 5113 | cleanup0: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5114 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5115 | cleanup1: |
| 5116 | if (buff) { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5117 | int i; |
| 5118 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5119 | for (i = 0; i < sg_used; i++) |
| 5120 | kfree(buff[i]); |
| 5121 | kfree(buff); |
| 5122 | } |
| 5123 | kfree(buff_size); |
| 5124 | kfree(ioc); |
| 5125 | return status; |
| 5126 | } |
| 5127 | |
| 5128 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 5129 | struct CommandList *c) |
| 5130 | { |
| 5131 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 5132 | c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) |
| 5133 | (void) check_for_unit_attention(h, c); |
| 5134 | } |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 5135 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5136 | /* |
| 5137 | * ioctl |
| 5138 | */ |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5139 | static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5140 | { |
| 5141 | struct ctlr_info *h; |
| 5142 | void __user *argp = (void __user *)arg; |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 5143 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5144 | |
| 5145 | h = sdev_to_hba(dev); |
| 5146 | |
| 5147 | switch (cmd) { |
| 5148 | case CCISS_DEREGDISK: |
| 5149 | case CCISS_REGNEWDISK: |
| 5150 | case CCISS_REGNEWD: |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5151 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5152 | return 0; |
| 5153 | case CCISS_GETPCIINFO: |
| 5154 | return hpsa_getpciinfo_ioctl(h, argp); |
| 5155 | case CCISS_GETDRIVVER: |
| 5156 | return hpsa_getdrivver_ioctl(h, argp); |
| 5157 | case CCISS_PASSTHRU: |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 5158 | if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0) |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 5159 | return -EAGAIN; |
| 5160 | rc = hpsa_passthru_ioctl(h, argp); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 5161 | atomic_inc(&h->passthru_cmds_avail); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 5162 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5163 | case CCISS_BIG_PASSTHRU: |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 5164 | if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0) |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 5165 | return -EAGAIN; |
| 5166 | rc = hpsa_big_passthru_ioctl(h, argp); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 5167 | atomic_inc(&h->passthru_cmds_avail); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 5168 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5169 | default: |
| 5170 | return -ENOTTY; |
| 5171 | } |
| 5172 | } |
| 5173 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5174 | static int hpsa_send_host_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
| 5175 | u8 reset_type) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5176 | { |
| 5177 | struct CommandList *c; |
| 5178 | |
| 5179 | c = cmd_alloc(h); |
| 5180 | if (!c) |
| 5181 | return -ENOMEM; |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5182 | /* fill_cmd can't fail here, no data buffer to map */ |
| 5183 | (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] | 5184 | RAID_CTLR_LUNID, TYPE_MSG); |
| 5185 | c->Request.CDB[1] = reset_type; /* fill_cmd defaults to target reset */ |
| 5186 | c->waiting = NULL; |
| 5187 | enqueue_cmd_and_start_io(h, c); |
| 5188 | /* Don't wait for completion, the reset won't complete. Don't free |
| 5189 | * the command either. This is the last command we will send before |
| 5190 | * re-initializing everything, so it doesn't matter and won't leak. |
| 5191 | */ |
| 5192 | return 0; |
| 5193 | } |
| 5194 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5195 | 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] | 5196 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5197 | int cmd_type) |
| 5198 | { |
| 5199 | int pci_dir = XFER_NONE; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5200 | struct CommandList *a; /* for commands to be aborted */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5201 | |
| 5202 | c->cmd_type = CMD_IOCTL_PEND; |
| 5203 | c->Header.ReplyQueue = 0; |
| 5204 | if (buff != NULL && size > 0) { |
| 5205 | c->Header.SGList = 1; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5206 | c->Header.SGTotal = cpu_to_le16(1); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5207 | } else { |
| 5208 | c->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5209 | c->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5210 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5211 | memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8); |
| 5212 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5213 | if (cmd_type == TYPE_CMD) { |
| 5214 | switch (cmd) { |
| 5215 | case HPSA_INQUIRY: |
| 5216 | /* are we trying to read a vital product page */ |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 5217 | if (page_code & VPD_PAGE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5218 | c->Request.CDB[1] = 0x01; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 5219 | c->Request.CDB[2] = (page_code & 0xff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5220 | } |
| 5221 | c->Request.CDBLen = 6; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5222 | c->Request.type_attr_dir = |
| 5223 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5224 | c->Request.Timeout = 0; |
| 5225 | c->Request.CDB[0] = HPSA_INQUIRY; |
| 5226 | c->Request.CDB[4] = size & 0xFF; |
| 5227 | break; |
| 5228 | case HPSA_REPORT_LOG: |
| 5229 | case HPSA_REPORT_PHYS: |
| 5230 | /* Talking to controller so It's a physical command |
| 5231 | mode = 00 target = 0. Nothing to write. |
| 5232 | */ |
| 5233 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5234 | c->Request.type_attr_dir = |
| 5235 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5236 | c->Request.Timeout = 0; |
| 5237 | c->Request.CDB[0] = cmd; |
| 5238 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 5239 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 5240 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 5241 | c->Request.CDB[9] = size & 0xFF; |
| 5242 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5243 | case HPSA_CACHE_FLUSH: |
| 5244 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5245 | c->Request.type_attr_dir = |
| 5246 | TYPE_ATTR_DIR(cmd_type, |
| 5247 | ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5248 | c->Request.Timeout = 0; |
| 5249 | c->Request.CDB[0] = BMIC_WRITE; |
| 5250 | c->Request.CDB[6] = BMIC_CACHE_FLUSH; |
Stephen M. Cameron | bb158ea | 2011-10-26 16:21:17 -0500 | [diff] [blame] | 5251 | c->Request.CDB[7] = (size >> 8) & 0xFF; |
| 5252 | c->Request.CDB[8] = size & 0xFF; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5253 | break; |
| 5254 | case TEST_UNIT_READY: |
| 5255 | c->Request.CDBLen = 6; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5256 | c->Request.type_attr_dir = |
| 5257 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5258 | c->Request.Timeout = 0; |
| 5259 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5260 | case HPSA_GET_RAID_MAP: |
| 5261 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5262 | c->Request.type_attr_dir = |
| 5263 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5264 | c->Request.Timeout = 0; |
| 5265 | c->Request.CDB[0] = HPSA_CISS_READ; |
| 5266 | c->Request.CDB[1] = cmd; |
| 5267 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 5268 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 5269 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 5270 | c->Request.CDB[9] = size & 0xFF; |
| 5271 | break; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 5272 | case BMIC_SENSE_CONTROLLER_PARAMETERS: |
| 5273 | c->Request.CDBLen = 10; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5274 | c->Request.type_attr_dir = |
| 5275 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 5276 | c->Request.Timeout = 0; |
| 5277 | c->Request.CDB[0] = BMIC_READ; |
| 5278 | c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS; |
| 5279 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 5280 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 5281 | break; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5282 | case BMIC_IDENTIFY_PHYSICAL_DEVICE: |
| 5283 | c->Request.CDBLen = 10; |
| 5284 | c->Request.type_attr_dir = |
| 5285 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 5286 | c->Request.Timeout = 0; |
| 5287 | c->Request.CDB[0] = BMIC_READ; |
| 5288 | c->Request.CDB[6] = BMIC_IDENTIFY_PHYSICAL_DEVICE; |
| 5289 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 5290 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 5291 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5292 | default: |
| 5293 | dev_warn(&h->pdev->dev, "unknown command 0x%c\n", cmd); |
| 5294 | BUG(); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5295 | return -1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5296 | } |
| 5297 | } else if (cmd_type == TYPE_MSG) { |
| 5298 | switch (cmd) { |
| 5299 | |
| 5300 | case HPSA_DEVICE_RESET_MSG: |
| 5301 | c->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5302 | c->Request.type_attr_dir = |
| 5303 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5304 | c->Request.Timeout = 0; /* Don't time out */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5305 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
| 5306 | c->Request.CDB[0] = cmd; |
Stephen M. Cameron | 21e89af | 2012-07-26 11:34:10 -0500 | [diff] [blame] | 5307 | c->Request.CDB[1] = HPSA_RESET_TYPE_LUN; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5308 | /* If bytes 4-7 are zero, it means reset the */ |
| 5309 | /* LunID device */ |
| 5310 | c->Request.CDB[4] = 0x00; |
| 5311 | c->Request.CDB[5] = 0x00; |
| 5312 | c->Request.CDB[6] = 0x00; |
| 5313 | c->Request.CDB[7] = 0x00; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5314 | break; |
| 5315 | case HPSA_ABORT_MSG: |
| 5316 | a = buff; /* point to command to be aborted */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5317 | dev_dbg(&h->pdev->dev, |
| 5318 | "Abort Tag:0x%016llx request Tag:0x%016llx", |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5319 | a->Header.tag, c->Header.tag); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5320 | c->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5321 | c->Request.type_attr_dir = |
| 5322 | TYPE_ATTR_DIR(cmd_type, |
| 5323 | ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5324 | c->Request.Timeout = 0; /* Don't time out */ |
| 5325 | c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; |
| 5326 | c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; |
| 5327 | c->Request.CDB[2] = 0x00; /* reserved */ |
| 5328 | c->Request.CDB[3] = 0x00; /* reserved */ |
| 5329 | /* Tag to abort goes in CDB[4]-CDB[11] */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5330 | memcpy(&c->Request.CDB[4], &a->Header.tag, |
| 5331 | sizeof(a->Header.tag)); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5332 | c->Request.CDB[12] = 0x00; /* reserved */ |
| 5333 | c->Request.CDB[13] = 0x00; /* reserved */ |
| 5334 | c->Request.CDB[14] = 0x00; /* reserved */ |
| 5335 | c->Request.CDB[15] = 0x00; /* reserved */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5336 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5337 | default: |
| 5338 | dev_warn(&h->pdev->dev, "unknown message type %d\n", |
| 5339 | cmd); |
| 5340 | BUG(); |
| 5341 | } |
| 5342 | } else { |
| 5343 | dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type); |
| 5344 | BUG(); |
| 5345 | } |
| 5346 | |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5347 | switch (GET_DIR(c->Request.type_attr_dir)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5348 | case XFER_READ: |
| 5349 | pci_dir = PCI_DMA_FROMDEVICE; |
| 5350 | break; |
| 5351 | case XFER_WRITE: |
| 5352 | pci_dir = PCI_DMA_TODEVICE; |
| 5353 | break; |
| 5354 | case XFER_NONE: |
| 5355 | pci_dir = PCI_DMA_NONE; |
| 5356 | break; |
| 5357 | default: |
| 5358 | pci_dir = PCI_DMA_BIDIRECTIONAL; |
| 5359 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5360 | if (hpsa_map_one(h->pdev, c, buff, size, pci_dir)) |
| 5361 | return -1; |
| 5362 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | /* |
| 5366 | * Map (physical) PCI mem into (virtual) kernel space |
| 5367 | */ |
| 5368 | static void __iomem *remap_pci_mem(ulong base, ulong size) |
| 5369 | { |
| 5370 | ulong page_base = ((ulong) base) & PAGE_MASK; |
| 5371 | ulong page_offs = ((ulong) base) - page_base; |
Stephen M. Cameron | 088ba34c | 2012-07-26 11:34:23 -0500 | [diff] [blame] | 5372 | void __iomem *page_remapped = ioremap_nocache(page_base, |
| 5373 | page_offs + size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5374 | |
| 5375 | return page_remapped ? (page_remapped + page_offs) : NULL; |
| 5376 | } |
| 5377 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5378 | 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] | 5379 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5380 | return h->access.command_completed(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5381 | } |
| 5382 | |
Stephen M. Cameron | 900c544 | 2010-02-04 08:42:35 -0600 | [diff] [blame] | 5383 | static inline bool interrupt_pending(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5384 | { |
| 5385 | return h->access.intr_pending(h); |
| 5386 | } |
| 5387 | |
| 5388 | static inline long interrupt_not_for_us(struct ctlr_info *h) |
| 5389 | { |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5390 | return (h->access.intr_pending(h) == 0) || |
| 5391 | (h->interrupts_enabled == 0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5392 | } |
| 5393 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 5394 | static inline int bad_tag(struct ctlr_info *h, u32 tag_index, |
| 5395 | u32 raw_tag) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5396 | { |
| 5397 | if (unlikely(tag_index >= h->nr_cmds)) { |
| 5398 | dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag); |
| 5399 | return 1; |
| 5400 | } |
| 5401 | return 0; |
| 5402 | } |
| 5403 | |
Stephen M. Cameron | 5a3d16f | 2012-05-01 11:42:46 -0500 | [diff] [blame] | 5404 | static inline void finish_cmd(struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5405 | { |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 5406 | dial_up_lockup_detection_on_fw_flash_complete(c->h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 5407 | if (likely(c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_SCSI |
| 5408 | || c->cmd_type == CMD_IOACCEL2)) |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 5409 | complete_scsi_command(c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5410 | else if (c->cmd_type == CMD_IOCTL_PEND) |
| 5411 | complete(c->waiting); |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5412 | } |
| 5413 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5414 | |
| 5415 | 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] | 5416 | { |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5417 | #define HPSA_PERF_ERROR_BITS ((1 << DIRECT_LOOKUP_SHIFT) - 1) |
| 5418 | #define HPSA_SIMPLE_ERROR_BITS 0x03 |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 5419 | if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5420 | return tag & ~HPSA_SIMPLE_ERROR_BITS; |
| 5421 | return tag & ~HPSA_PERF_ERROR_BITS; |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 5422 | } |
| 5423 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5424 | /* process completion of an indexed ("direct lookup") command */ |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5425 | static inline void process_indexed_cmd(struct ctlr_info *h, |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5426 | u32 raw_tag) |
| 5427 | { |
| 5428 | u32 tag_index; |
| 5429 | struct CommandList *c; |
| 5430 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 5431 | tag_index = raw_tag >> DIRECT_LOOKUP_SHIFT; |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 5432 | if (!bad_tag(h, tag_index, raw_tag)) { |
| 5433 | c = h->cmd_pool + tag_index; |
| 5434 | finish_cmd(c); |
| 5435 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5436 | } |
| 5437 | |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5438 | /* Some controllers, like p400, will give us one interrupt |
| 5439 | * after a soft reset, even if we turned interrupts off. |
| 5440 | * Only need to check for this in the hpsa_xxx_discard_completions |
| 5441 | * functions. |
| 5442 | */ |
| 5443 | static int ignore_bogus_interrupt(struct ctlr_info *h) |
| 5444 | { |
| 5445 | if (likely(!reset_devices)) |
| 5446 | return 0; |
| 5447 | |
| 5448 | if (likely(h->interrupts_enabled)) |
| 5449 | return 0; |
| 5450 | |
| 5451 | dev_info(&h->pdev->dev, "Received interrupt while interrupts disabled " |
| 5452 | "(known firmware bug.) Ignoring.\n"); |
| 5453 | |
| 5454 | return 1; |
| 5455 | } |
| 5456 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5457 | /* |
| 5458 | * Convert &h->q[x] (passed to interrupt handlers) back to h. |
| 5459 | * Relies on (h-q[x] == x) being true for x such that |
| 5460 | * 0 <= x < MAX_REPLY_QUEUES. |
| 5461 | */ |
| 5462 | static struct ctlr_info *queue_to_hba(u8 *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5463 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5464 | return container_of((queue - *queue), struct ctlr_info, q[0]); |
| 5465 | } |
| 5466 | |
| 5467 | static irqreturn_t hpsa_intx_discard_completions(int irq, void *queue) |
| 5468 | { |
| 5469 | struct ctlr_info *h = queue_to_hba(queue); |
| 5470 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5471 | u32 raw_tag; |
| 5472 | |
| 5473 | if (ignore_bogus_interrupt(h)) |
| 5474 | return IRQ_NONE; |
| 5475 | |
| 5476 | if (interrupt_not_for_us(h)) |
| 5477 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5478 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5479 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5480 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5481 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5482 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5483 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5484 | return IRQ_HANDLED; |
| 5485 | } |
| 5486 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5487 | static irqreturn_t hpsa_msix_discard_completions(int irq, void *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5488 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5489 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5490 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5491 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5492 | |
| 5493 | if (ignore_bogus_interrupt(h)) |
| 5494 | return IRQ_NONE; |
| 5495 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5496 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5497 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5498 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5499 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5500 | return IRQ_HANDLED; |
| 5501 | } |
| 5502 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5503 | static irqreturn_t do_hpsa_intr_intx(int irq, void *queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5504 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5505 | struct ctlr_info *h = queue_to_hba((u8 *) queue); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5506 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5507 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5508 | |
| 5509 | if (interrupt_not_for_us(h)) |
| 5510 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5511 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5512 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5513 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5514 | while (raw_tag != FIFO_EMPTY) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 5515 | process_indexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5516 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5517 | } |
| 5518 | } |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5519 | return IRQ_HANDLED; |
| 5520 | } |
| 5521 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5522 | static irqreturn_t do_hpsa_intr_msi(int irq, void *queue) |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5523 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5524 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5525 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5526 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 5527 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 5528 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5529 | raw_tag = get_next_completion(h, q); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 5530 | while (raw_tag != FIFO_EMPTY) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 5531 | process_indexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5532 | raw_tag = next_command(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5533 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5534 | return IRQ_HANDLED; |
| 5535 | } |
| 5536 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 5537 | /* Send a message CDB to the firmware. Careful, this only works |
| 5538 | * in simple mode, not performant mode due to the tag lookup. |
| 5539 | * We only ever use this immediately after a controller reset. |
| 5540 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5541 | static int hpsa_message(struct pci_dev *pdev, unsigned char opcode, |
| 5542 | unsigned char type) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5543 | { |
| 5544 | struct Command { |
| 5545 | struct CommandListHeader CommandHeader; |
| 5546 | struct RequestBlock Request; |
| 5547 | struct ErrDescriptor ErrorDescriptor; |
| 5548 | }; |
| 5549 | struct Command *cmd; |
| 5550 | static const size_t cmd_sz = sizeof(*cmd) + |
| 5551 | sizeof(cmd->ErrorDescriptor); |
| 5552 | dma_addr_t paddr64; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5553 | __le32 paddr32; |
| 5554 | u32 tag; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5555 | void __iomem *vaddr; |
| 5556 | int i, err; |
| 5557 | |
| 5558 | vaddr = pci_ioremap_bar(pdev, 0); |
| 5559 | if (vaddr == NULL) |
| 5560 | return -ENOMEM; |
| 5561 | |
| 5562 | /* The Inbound Post Queue only accepts 32-bit physical addresses for the |
| 5563 | * CCISS commands, so they must be allocated from the lower 4GiB of |
| 5564 | * memory. |
| 5565 | */ |
| 5566 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 5567 | if (err) { |
| 5568 | iounmap(vaddr); |
Robert Elliott | 1eaec8f | 2015-01-23 16:42:37 -0600 | [diff] [blame] | 5569 | return err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | cmd = pci_alloc_consistent(pdev, cmd_sz, &paddr64); |
| 5573 | if (cmd == NULL) { |
| 5574 | iounmap(vaddr); |
| 5575 | return -ENOMEM; |
| 5576 | } |
| 5577 | |
| 5578 | /* This must fit, because of the 32-bit consistent DMA mask. Also, |
| 5579 | * although there's no guarantee, we assume that the address is at |
| 5580 | * least 4-byte aligned (most likely, it's page-aligned). |
| 5581 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5582 | paddr32 = cpu_to_le32(paddr64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5583 | |
| 5584 | cmd->CommandHeader.ReplyQueue = 0; |
| 5585 | cmd->CommandHeader.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5586 | cmd->CommandHeader.SGTotal = cpu_to_le16(0); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5587 | cmd->CommandHeader.tag = cpu_to_le64(paddr64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5588 | memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8); |
| 5589 | |
| 5590 | cmd->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5591 | cmd->Request.type_attr_dir = |
| 5592 | TYPE_ATTR_DIR(TYPE_MSG, ATTR_HEADOFQUEUE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5593 | cmd->Request.Timeout = 0; /* Don't time out */ |
| 5594 | cmd->Request.CDB[0] = opcode; |
| 5595 | cmd->Request.CDB[1] = type; |
| 5596 | memset(&cmd->Request.CDB[2], 0, 14); /* rest of the CDB is reserved */ |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5597 | cmd->ErrorDescriptor.Addr = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5598 | cpu_to_le64((le32_to_cpu(paddr32) + sizeof(*cmd))); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 5599 | cmd->ErrorDescriptor.Len = cpu_to_le32(sizeof(struct ErrorInfo)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5600 | |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5601 | writel(le32_to_cpu(paddr32), vaddr + SA5_REQUEST_PORT_OFFSET); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5602 | |
| 5603 | for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) { |
| 5604 | tag = readl(vaddr + SA5_REPLY_PORT_OFFSET); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5605 | if ((tag & ~HPSA_SIMPLE_ERROR_BITS) == paddr64) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5606 | break; |
| 5607 | msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS); |
| 5608 | } |
| 5609 | |
| 5610 | iounmap(vaddr); |
| 5611 | |
| 5612 | /* we leak the DMA buffer here ... no choice since the controller could |
| 5613 | * still complete the command. |
| 5614 | */ |
| 5615 | if (i == HPSA_MSG_SEND_RETRY_LIMIT) { |
| 5616 | dev_err(&pdev->dev, "controller message %02x:%02x timed out\n", |
| 5617 | opcode, type); |
| 5618 | return -ETIMEDOUT; |
| 5619 | } |
| 5620 | |
| 5621 | pci_free_consistent(pdev, cmd_sz, cmd, paddr64); |
| 5622 | |
| 5623 | if (tag & HPSA_ERROR_BIT) { |
| 5624 | dev_err(&pdev->dev, "controller message %02x:%02x failed\n", |
| 5625 | opcode, type); |
| 5626 | return -EIO; |
| 5627 | } |
| 5628 | |
| 5629 | dev_info(&pdev->dev, "controller message %02x:%02x succeeded\n", |
| 5630 | opcode, type); |
| 5631 | return 0; |
| 5632 | } |
| 5633 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5634 | #define hpsa_noop(p) hpsa_message(p, 3, 0) |
| 5635 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5636 | static int hpsa_controller_hard_reset(struct pci_dev *pdev, |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5637 | void __iomem *vaddr, u32 use_doorbell) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5638 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5639 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5640 | if (use_doorbell) { |
| 5641 | /* For everything after the P600, the PCI power state method |
| 5642 | * of resetting the controller doesn't work, so we have this |
| 5643 | * other way using the doorbell register. |
| 5644 | */ |
| 5645 | dev_info(&pdev->dev, "using doorbell to reset controller\n"); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5646 | writel(use_doorbell, vaddr + SA5_DOORBELL); |
Stephen M. Cameron | 8500923 | 2013-09-23 13:33:36 -0500 | [diff] [blame] | 5647 | |
Justin Lindley | 00701a9 | 2014-05-29 10:52:47 -0500 | [diff] [blame] | 5648 | /* PMC hardware guys tell us we need a 10 second delay after |
Stephen M. Cameron | 8500923 | 2013-09-23 13:33:36 -0500 | [diff] [blame] | 5649 | * doorbell reset and before any attempt to talk to the board |
| 5650 | * at all to ensure that this actually works and doesn't fall |
| 5651 | * over in some weird corner cases. |
| 5652 | */ |
Justin Lindley | 00701a9 | 2014-05-29 10:52:47 -0500 | [diff] [blame] | 5653 | msleep(10000); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5654 | } else { /* Try to do it the PCI power state way */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5655 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5656 | /* Quoting from the Open CISS Specification: "The Power |
| 5657 | * Management Control/Status Register (CSR) controls the power |
| 5658 | * state of the device. The normal operating state is D0, |
| 5659 | * CSR=00h. The software off state is D3, CSR=03h. To reset |
| 5660 | * the controller, place the interface device in D3 then to D0, |
| 5661 | * this causes a secondary PCI reset which will reset the |
| 5662 | * controller." */ |
| 5663 | |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 5664 | int rc = 0; |
| 5665 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5666 | dev_info(&pdev->dev, "using PCI PM to reset controller\n"); |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 5667 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5668 | /* enter the D3hot power management state */ |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 5669 | rc = pci_set_power_state(pdev, PCI_D3hot); |
| 5670 | if (rc) |
| 5671 | return rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5672 | |
| 5673 | msleep(500); |
| 5674 | |
| 5675 | /* enter the D0 power management state */ |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 5676 | rc = pci_set_power_state(pdev, PCI_D0); |
| 5677 | if (rc) |
| 5678 | return rc; |
Mike Miller | c4853ef | 2011-10-21 08:19:43 +0200 | [diff] [blame] | 5679 | |
| 5680 | /* |
| 5681 | * The P600 requires a small delay when changing states. |
| 5682 | * Otherwise we may think the board did not reset and we bail. |
| 5683 | * This for kdump only and is particular to the P600. |
| 5684 | */ |
| 5685 | msleep(500); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5686 | } |
| 5687 | return 0; |
| 5688 | } |
| 5689 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5690 | static void init_driver_version(char *driver_version, int len) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5691 | { |
| 5692 | memset(driver_version, 0, len); |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 5693 | strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1); |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5694 | } |
| 5695 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5696 | static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5697 | { |
| 5698 | char *driver_version; |
| 5699 | int i, size = sizeof(cfgtable->driver_version); |
| 5700 | |
| 5701 | driver_version = kmalloc(size, GFP_KERNEL); |
| 5702 | if (!driver_version) |
| 5703 | return -ENOMEM; |
| 5704 | |
| 5705 | init_driver_version(driver_version, size); |
| 5706 | for (i = 0; i < size; i++) |
| 5707 | writeb(driver_version[i], &cfgtable->driver_version[i]); |
| 5708 | kfree(driver_version); |
| 5709 | return 0; |
| 5710 | } |
| 5711 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5712 | static void read_driver_ver_from_cfgtable(struct CfgTable __iomem *cfgtable, |
| 5713 | unsigned char *driver_ver) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5714 | { |
| 5715 | int i; |
| 5716 | |
| 5717 | for (i = 0; i < sizeof(cfgtable->driver_version); i++) |
| 5718 | driver_ver[i] = readb(&cfgtable->driver_version[i]); |
| 5719 | } |
| 5720 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5721 | static int controller_reset_failed(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5722 | { |
| 5723 | |
| 5724 | char *driver_ver, *old_driver_ver; |
| 5725 | int rc, size = sizeof(cfgtable->driver_version); |
| 5726 | |
| 5727 | old_driver_ver = kmalloc(2 * size, GFP_KERNEL); |
| 5728 | if (!old_driver_ver) |
| 5729 | return -ENOMEM; |
| 5730 | driver_ver = old_driver_ver + size; |
| 5731 | |
| 5732 | /* After a reset, the 32 bytes of "driver version" in the cfgtable |
| 5733 | * should have been changed, otherwise we know the reset failed. |
| 5734 | */ |
| 5735 | init_driver_version(old_driver_ver, size); |
| 5736 | read_driver_ver_from_cfgtable(cfgtable, driver_ver); |
| 5737 | rc = !memcmp(driver_ver, old_driver_ver, size); |
| 5738 | kfree(old_driver_ver); |
| 5739 | return rc; |
| 5740 | } |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5741 | /* This does a hard reset of the controller using PCI power management |
| 5742 | * states or the using the doorbell register. |
| 5743 | */ |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 5744 | static int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev, u32 board_id) |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5745 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5746 | u64 cfg_offset; |
| 5747 | u32 cfg_base_addr; |
| 5748 | u64 cfg_base_addr_index; |
| 5749 | void __iomem *vaddr; |
| 5750 | unsigned long paddr; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5751 | u32 misc_fw_support; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5752 | int rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5753 | struct CfgTable __iomem *cfgtable; |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5754 | u32 use_doorbell; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5755 | u16 command_register; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5756 | |
| 5757 | /* For controllers as old as the P600, this is very nearly |
| 5758 | * the same thing as |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5759 | * |
| 5760 | * pci_save_state(pci_dev); |
| 5761 | * pci_set_power_state(pci_dev, PCI_D3hot); |
| 5762 | * pci_set_power_state(pci_dev, PCI_D0); |
| 5763 | * pci_restore_state(pci_dev); |
| 5764 | * |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5765 | * For controllers newer than the P600, the pci power state |
| 5766 | * method of resetting doesn't work so we have another way |
| 5767 | * using the doorbell register. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5768 | */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 5769 | |
Robert Elliott | 60f923b | 2015-01-23 16:42:06 -0600 | [diff] [blame] | 5770 | if (!ctlr_is_resettable(board_id)) { |
| 5771 | dev_warn(&pdev->dev, "Controller not resettable\n"); |
Stephen M. Cameron | 25c1e56a | 2011-01-06 14:48:18 -0600 | [diff] [blame] | 5772 | return -ENODEV; |
| 5773 | } |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 5774 | |
| 5775 | /* if controller is soft- but not hard resettable... */ |
| 5776 | if (!ctlr_is_hard_resettable(board_id)) |
| 5777 | return -ENOTSUPP; /* try soft reset later. */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 5778 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5779 | /* Save the PCI command register */ |
| 5780 | pci_read_config_word(pdev, 4, &command_register); |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5781 | pci_save_state(pdev); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5782 | |
| 5783 | /* find the first memory BAR, so we can find the cfg table */ |
| 5784 | rc = hpsa_pci_find_memory_BAR(pdev, &paddr); |
| 5785 | if (rc) |
| 5786 | return rc; |
| 5787 | vaddr = remap_pci_mem(paddr, 0x250); |
| 5788 | if (!vaddr) |
| 5789 | return -ENOMEM; |
| 5790 | |
| 5791 | /* find cfgtable in order to check if reset via doorbell is supported */ |
| 5792 | rc = hpsa_find_cfg_addrs(pdev, vaddr, &cfg_base_addr, |
| 5793 | &cfg_base_addr_index, &cfg_offset); |
| 5794 | if (rc) |
| 5795 | goto unmap_vaddr; |
| 5796 | cfgtable = remap_pci_mem(pci_resource_start(pdev, |
| 5797 | cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable)); |
| 5798 | if (!cfgtable) { |
| 5799 | rc = -ENOMEM; |
| 5800 | goto unmap_vaddr; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5801 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5802 | rc = write_driver_ver_to_cfgtable(cfgtable); |
| 5803 | if (rc) |
Tomas Henzl | 03741d9 | 2015-01-23 16:41:14 -0600 | [diff] [blame] | 5804 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5805 | |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5806 | /* If reset via doorbell register is supported, use that. |
| 5807 | * There are two such methods. Favor the newest method. |
| 5808 | */ |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5809 | misc_fw_support = readl(&cfgtable->misc_fw_support); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5810 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET2; |
| 5811 | if (use_doorbell) { |
| 5812 | use_doorbell = DOORBELL_CTLR_RESET2; |
| 5813 | } else { |
| 5814 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET; |
| 5815 | if (use_doorbell) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 5816 | dev_warn(&pdev->dev, |
| 5817 | "Soft reset not supported. Firmware update is required.\n"); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5818 | rc = -ENOTSUPP; /* try soft reset */ |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 5819 | goto unmap_cfgtable; |
| 5820 | } |
| 5821 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5822 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5823 | rc = hpsa_controller_hard_reset(pdev, vaddr, use_doorbell); |
| 5824 | if (rc) |
| 5825 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5826 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5827 | pci_restore_state(pdev); |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 5828 | pci_write_config_word(pdev, 4, command_register); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5829 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5830 | /* Some devices (notably the HP Smart Array 5i Controller) |
| 5831 | need a little pause here */ |
| 5832 | msleep(HPSA_POST_RESET_PAUSE_MSECS); |
| 5833 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5834 | rc = hpsa_wait_for_board_state(pdev, vaddr, BOARD_READY); |
| 5835 | if (rc) { |
| 5836 | dev_warn(&pdev->dev, |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 5837 | "Failed waiting for board to become ready after hard reset\n"); |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5838 | goto unmap_cfgtable; |
| 5839 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 5840 | |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5841 | rc = controller_reset_failed(vaddr); |
| 5842 | if (rc < 0) |
| 5843 | goto unmap_cfgtable; |
| 5844 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5845 | dev_warn(&pdev->dev, "Unable to successfully reset " |
| 5846 | "controller. Will try soft reset.\n"); |
| 5847 | rc = -ENOTSUPP; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 5848 | } else { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 5849 | dev_info(&pdev->dev, "board ready after hard reset.\n"); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | unmap_cfgtable: |
| 5853 | iounmap(cfgtable); |
| 5854 | |
| 5855 | unmap_vaddr: |
| 5856 | iounmap(vaddr); |
| 5857 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5858 | } |
| 5859 | |
| 5860 | /* |
| 5861 | * We cannot read the structure directly, for portability we must use |
| 5862 | * the io functions. |
| 5863 | * This is for debug only. |
| 5864 | */ |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5865 | static void print_cfg_table(struct device *dev, struct CfgTable __iomem *tb) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5866 | { |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 5867 | #ifdef HPSA_DEBUG |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5868 | int i; |
| 5869 | char temp_name[17]; |
| 5870 | |
| 5871 | dev_info(dev, "Controller Configuration information\n"); |
| 5872 | dev_info(dev, "------------------------------------\n"); |
| 5873 | for (i = 0; i < 4; i++) |
| 5874 | temp_name[i] = readb(&(tb->Signature[i])); |
| 5875 | temp_name[4] = '\0'; |
| 5876 | dev_info(dev, " Signature = %s\n", temp_name); |
| 5877 | dev_info(dev, " Spec Number = %d\n", readl(&(tb->SpecValence))); |
| 5878 | dev_info(dev, " Transport methods supported = 0x%x\n", |
| 5879 | readl(&(tb->TransportSupport))); |
| 5880 | dev_info(dev, " Transport methods active = 0x%x\n", |
| 5881 | readl(&(tb->TransportActive))); |
| 5882 | dev_info(dev, " Requested transport Method = 0x%x\n", |
| 5883 | readl(&(tb->HostWrite.TransportRequest))); |
| 5884 | dev_info(dev, " Coalesce Interrupt Delay = 0x%x\n", |
| 5885 | readl(&(tb->HostWrite.CoalIntDelay))); |
| 5886 | dev_info(dev, " Coalesce Interrupt Count = 0x%x\n", |
| 5887 | readl(&(tb->HostWrite.CoalIntCount))); |
Robert Elliott | 69d6e33 | 2015-01-23 16:41:56 -0600 | [diff] [blame] | 5888 | dev_info(dev, " Max outstanding commands = %d\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5889 | readl(&(tb->CmdsOutMax))); |
| 5890 | dev_info(dev, " Bus Types = 0x%x\n", readl(&(tb->BusTypes))); |
| 5891 | for (i = 0; i < 16; i++) |
| 5892 | temp_name[i] = readb(&(tb->ServerName[i])); |
| 5893 | temp_name[16] = '\0'; |
| 5894 | dev_info(dev, " Server Name = %s\n", temp_name); |
| 5895 | dev_info(dev, " Heartbeat Counter = 0x%x\n\n\n", |
| 5896 | readl(&(tb->HeartBeat))); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5897 | #endif /* HPSA_DEBUG */ |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 5898 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5899 | |
| 5900 | static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) |
| 5901 | { |
| 5902 | int i, offset, mem_type, bar_type; |
| 5903 | |
| 5904 | if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */ |
| 5905 | return 0; |
| 5906 | offset = 0; |
| 5907 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 5908 | bar_type = pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE; |
| 5909 | if (bar_type == PCI_BASE_ADDRESS_SPACE_IO) |
| 5910 | offset += 4; |
| 5911 | else { |
| 5912 | mem_type = pci_resource_flags(pdev, i) & |
| 5913 | PCI_BASE_ADDRESS_MEM_TYPE_MASK; |
| 5914 | switch (mem_type) { |
| 5915 | case PCI_BASE_ADDRESS_MEM_TYPE_32: |
| 5916 | case PCI_BASE_ADDRESS_MEM_TYPE_1M: |
| 5917 | offset += 4; /* 32 bit */ |
| 5918 | break; |
| 5919 | case PCI_BASE_ADDRESS_MEM_TYPE_64: |
| 5920 | offset += 8; |
| 5921 | break; |
| 5922 | default: /* reserved in PCI 2.2 */ |
| 5923 | dev_warn(&pdev->dev, |
| 5924 | "base address is invalid\n"); |
| 5925 | return -1; |
| 5926 | break; |
| 5927 | } |
| 5928 | } |
| 5929 | if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0) |
| 5930 | return i + 1; |
| 5931 | } |
| 5932 | return -1; |
| 5933 | } |
| 5934 | |
| 5935 | /* If MSI/MSI-X is supported by the kernel we will try to enable it on |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 5936 | * controllers that are capable. If not, we use legacy INTx mode. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5937 | */ |
| 5938 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5939 | static void hpsa_interrupt_mode(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5940 | { |
| 5941 | #ifdef CONFIG_PCI_MSI |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 5942 | int err, i; |
| 5943 | struct msix_entry hpsa_msix_entries[MAX_REPLY_QUEUES]; |
| 5944 | |
| 5945 | for (i = 0; i < MAX_REPLY_QUEUES; i++) { |
| 5946 | hpsa_msix_entries[i].vector = 0; |
| 5947 | hpsa_msix_entries[i].entry = i; |
| 5948 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5949 | |
| 5950 | /* Some boards advertise MSI but don't really support it */ |
Stephen M. Cameron | 6b3f4c5 | 2010-05-27 15:13:02 -0500 | [diff] [blame] | 5951 | if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) || |
| 5952 | (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5953 | goto default_int_mode; |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5954 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 5955 | dev_info(&h->pdev->dev, "MSI-X capable controller\n"); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 5956 | h->msix_vector = MAX_REPLY_QUEUES; |
Stephen M. Cameron | f89439b | 2014-05-29 10:53:02 -0500 | [diff] [blame] | 5957 | if (h->msix_vector > num_online_cpus()) |
| 5958 | h->msix_vector = num_online_cpus(); |
Alexander Gordeev | 18fce3c | 2014-08-18 08:01:42 +0200 | [diff] [blame] | 5959 | err = pci_enable_msix_range(h->pdev, hpsa_msix_entries, |
| 5960 | 1, h->msix_vector); |
| 5961 | if (err < 0) { |
| 5962 | dev_warn(&h->pdev->dev, "MSI-X init failed %d\n", err); |
| 5963 | h->msix_vector = 0; |
| 5964 | goto single_msi_mode; |
| 5965 | } else if (err < h->msix_vector) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5966 | dev_warn(&h->pdev->dev, "only %d MSI-X vectors " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5967 | "available\n", err); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 5968 | } |
Alexander Gordeev | 18fce3c | 2014-08-18 08:01:42 +0200 | [diff] [blame] | 5969 | h->msix_vector = err; |
| 5970 | for (i = 0; i < h->msix_vector; i++) |
| 5971 | h->intr[i] = hpsa_msix_entries[i].vector; |
| 5972 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5973 | } |
Alexander Gordeev | 18fce3c | 2014-08-18 08:01:42 +0200 | [diff] [blame] | 5974 | single_msi_mode: |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5975 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 5976 | dev_info(&h->pdev->dev, "MSI capable controller\n"); |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5977 | if (!pci_enable_msi(h->pdev)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5978 | h->msi_vector = 1; |
| 5979 | else |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 5980 | dev_warn(&h->pdev->dev, "MSI init failed\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5981 | } |
| 5982 | default_int_mode: |
| 5983 | #endif /* CONFIG_PCI_MSI */ |
| 5984 | /* 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] | 5985 | h->intr[h->intr_mode] = h->pdev->irq; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5986 | } |
| 5987 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5988 | 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] | 5989 | { |
| 5990 | int i; |
| 5991 | u32 subsystem_vendor_id, subsystem_device_id; |
| 5992 | |
| 5993 | subsystem_vendor_id = pdev->subsystem_vendor; |
| 5994 | subsystem_device_id = pdev->subsystem_device; |
| 5995 | *board_id = ((subsystem_device_id << 16) & 0xffff0000) | |
| 5996 | subsystem_vendor_id; |
| 5997 | |
| 5998 | for (i = 0; i < ARRAY_SIZE(products); i++) |
| 5999 | if (*board_id == products[i].board_id) |
| 6000 | return i; |
| 6001 | |
Stephen M. Cameron | 6798cc0 | 2010-06-16 13:51:20 -0500 | [diff] [blame] | 6002 | if ((subsystem_vendor_id != PCI_VENDOR_ID_HP && |
| 6003 | subsystem_vendor_id != PCI_VENDOR_ID_COMPAQ) || |
| 6004 | !hpsa_allow_any) { |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 6005 | dev_warn(&pdev->dev, "unrecognized board ID: " |
| 6006 | "0x%08x, ignoring.\n", *board_id); |
| 6007 | return -ENODEV; |
| 6008 | } |
| 6009 | return ARRAY_SIZE(products) - 1; /* generic unknown smart array */ |
| 6010 | } |
| 6011 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6012 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 6013 | unsigned long *memory_bar) |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 6014 | { |
| 6015 | int i; |
| 6016 | |
| 6017 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 6018 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 6019 | /* addressing mode bits already removed */ |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 6020 | *memory_bar = pci_resource_start(pdev, i); |
| 6021 | dev_dbg(&pdev->dev, "memory BAR = %lx\n", |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 6022 | *memory_bar); |
| 6023 | return 0; |
| 6024 | } |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 6025 | dev_warn(&pdev->dev, "no memory BAR found\n"); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 6026 | return -ENODEV; |
| 6027 | } |
| 6028 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6029 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 6030 | int wait_for_ready) |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 6031 | { |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 6032 | int i, iterations; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 6033 | u32 scratchpad; |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 6034 | if (wait_for_ready) |
| 6035 | iterations = HPSA_BOARD_READY_ITERATIONS; |
| 6036 | else |
| 6037 | iterations = HPSA_BOARD_NOT_READY_ITERATIONS; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 6038 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 6039 | for (i = 0; i < iterations; i++) { |
| 6040 | scratchpad = readl(vaddr + SA5_SCRATCHPAD_OFFSET); |
| 6041 | if (wait_for_ready) { |
| 6042 | if (scratchpad == HPSA_FIRMWARE_READY) |
| 6043 | return 0; |
| 6044 | } else { |
| 6045 | if (scratchpad != HPSA_FIRMWARE_READY) |
| 6046 | return 0; |
| 6047 | } |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 6048 | msleep(HPSA_BOARD_READY_POLL_INTERVAL_MSECS); |
| 6049 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 6050 | dev_warn(&pdev->dev, "board not ready, timed out.\n"); |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 6051 | return -ENODEV; |
| 6052 | } |
| 6053 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6054 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 6055 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 6056 | u64 *cfg_offset) |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 6057 | { |
| 6058 | *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET); |
| 6059 | *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET); |
| 6060 | *cfg_base_addr &= (u32) 0x0000ffff; |
| 6061 | *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr); |
| 6062 | if (*cfg_base_addr_index == -1) { |
| 6063 | dev_warn(&pdev->dev, "cannot find cfg_base_addr_index\n"); |
| 6064 | return -ENODEV; |
| 6065 | } |
| 6066 | return 0; |
| 6067 | } |
| 6068 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6069 | static int hpsa_find_cfgtables(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6070 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 6071 | u64 cfg_offset; |
| 6072 | u32 cfg_base_addr; |
| 6073 | u64 cfg_base_addr_index; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6074 | u32 trans_offset; |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 6075 | int rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6076 | |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 6077 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 6078 | &cfg_base_addr_index, &cfg_offset); |
| 6079 | if (rc) |
| 6080 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6081 | h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev, |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 6082 | cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable)); |
Robert Elliott | cd3c81c | 2015-01-23 16:42:27 -0600 | [diff] [blame] | 6083 | if (!h->cfgtable) { |
| 6084 | dev_err(&h->pdev->dev, "Failed mapping cfgtable\n"); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6085 | return -ENOMEM; |
Robert Elliott | cd3c81c | 2015-01-23 16:42:27 -0600 | [diff] [blame] | 6086 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6087 | rc = write_driver_ver_to_cfgtable(h->cfgtable); |
| 6088 | if (rc) |
| 6089 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6090 | /* Find performant mode table. */ |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 6091 | trans_offset = readl(&h->cfgtable->TransMethodOffset); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6092 | h->transtable = remap_pci_mem(pci_resource_start(h->pdev, |
| 6093 | cfg_base_addr_index)+cfg_offset+trans_offset, |
| 6094 | sizeof(*h->transtable)); |
| 6095 | if (!h->transtable) |
| 6096 | return -ENOMEM; |
| 6097 | return 0; |
| 6098 | } |
| 6099 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6100 | 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] | 6101 | { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 6102 | #define MIN_MAX_COMMANDS 16 |
| 6103 | BUILD_BUG_ON(MIN_MAX_COMMANDS <= HPSA_NRESERVED_CMDS); |
| 6104 | |
| 6105 | h->max_commands = readl(&h->cfgtable->MaxPerformantModeCommands); |
Stephen M. Cameron | 72ceeae | 2011-01-06 14:48:13 -0600 | [diff] [blame] | 6106 | |
| 6107 | /* Limit commands in memory limited kdump scenario. */ |
| 6108 | if (reset_devices && h->max_commands > 32) |
| 6109 | h->max_commands = 32; |
| 6110 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame^] | 6111 | if (h->max_commands < MIN_MAX_COMMANDS) { |
| 6112 | dev_warn(&h->pdev->dev, |
| 6113 | "Controller reports max supported commands of %d Using %d instead. Ensure that firmware is up to date.\n", |
| 6114 | h->max_commands, |
| 6115 | MIN_MAX_COMMANDS); |
| 6116 | h->max_commands = MIN_MAX_COMMANDS; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 6117 | } |
| 6118 | } |
| 6119 | |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 6120 | /* If the controller reports that the total max sg entries is greater than 512, |
| 6121 | * then we know that chained SG blocks work. (Original smart arrays did not |
| 6122 | * support chained SG blocks and would return zero for max sg entries.) |
| 6123 | */ |
| 6124 | static int hpsa_supports_chained_sg_blocks(struct ctlr_info *h) |
| 6125 | { |
| 6126 | return h->maxsgentries > 512; |
| 6127 | } |
| 6128 | |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6129 | /* Interrogate the hardware for some limits: |
| 6130 | * max commands, max SG elements without chaining, and with chaining, |
| 6131 | * SG chain block size, etc. |
| 6132 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6133 | static void hpsa_find_board_params(struct ctlr_info *h) |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6134 | { |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 6135 | hpsa_get_max_perf_mode_cmds(h); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6136 | h->nr_cmds = h->max_commands; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6137 | h->maxsgentries = readl(&(h->cfgtable->MaxScatterGatherElements)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6138 | h->fw_support = readl(&(h->cfgtable->misc_fw_support)); |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 6139 | if (hpsa_supports_chained_sg_blocks(h)) { |
| 6140 | /* Limit in-command s/g elements to 32 save dma'able memory. */ |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6141 | h->max_cmd_sg_entries = 32; |
Webb Scales | 1a63ea6 | 2014-11-14 17:26:43 -0600 | [diff] [blame] | 6142 | h->chainsize = h->maxsgentries - h->max_cmd_sg_entries; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6143 | h->maxsgentries--; /* save one for chain pointer */ |
| 6144 | } else { |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 6145 | /* |
| 6146 | * Original smart arrays supported at most 31 s/g entries |
| 6147 | * embedded inline in the command (trying to use more |
| 6148 | * would lock up the controller) |
| 6149 | */ |
| 6150 | h->max_cmd_sg_entries = 31; |
Webb Scales | 1a63ea6 | 2014-11-14 17:26:43 -0600 | [diff] [blame] | 6151 | h->maxsgentries = 31; /* default to traditional values */ |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 6152 | h->chainsize = 0; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6153 | } |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6154 | |
| 6155 | /* Find out what task management functions are supported and cache */ |
| 6156 | h->TMFSupportFlags = readl(&(h->cfgtable->TMFSupportFlags)); |
Scott Teel | 0e7a7fc | 2014-02-18 13:55:59 -0600 | [diff] [blame] | 6157 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags)) |
| 6158 | dev_warn(&h->pdev->dev, "Physical aborts not supported\n"); |
| 6159 | if (!(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 6160 | dev_warn(&h->pdev->dev, "Logical aborts not supported\n"); |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6161 | } |
| 6162 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 6163 | static inline bool hpsa_CISS_signature_present(struct ctlr_info *h) |
| 6164 | { |
Akinobu Mita | 0fc9fd4 | 2012-04-04 22:14:59 +0900 | [diff] [blame] | 6165 | if (!check_signature(h->cfgtable->Signature, "CISS", 4)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 6166 | dev_err(&h->pdev->dev, "not a valid CISS config table\n"); |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 6167 | return false; |
| 6168 | } |
| 6169 | return true; |
| 6170 | } |
| 6171 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6172 | 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] | 6173 | { |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6174 | u32 driver_support; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6175 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6176 | driver_support = readl(&(h->cfgtable->driver_support)); |
Arnd Bergmann | 0b9e7b7 | 2014-06-26 15:44:52 +0200 | [diff] [blame] | 6177 | /* Need to enable prefetch in the SCSI core for 6400 in x86 */ |
| 6178 | #ifdef CONFIG_X86 |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6179 | driver_support |= ENABLE_SCSI_PREFETCH; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6180 | #endif |
Stephen M. Cameron | 28e1344 | 2013-12-04 17:10:21 -0600 | [diff] [blame] | 6181 | driver_support |= ENABLE_UNIT_ATTN; |
| 6182 | writel(driver_support, &(h->cfgtable->driver_support)); |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 6183 | } |
| 6184 | |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 6185 | /* Disable DMA prefetch for the P600. Otherwise an ASIC bug may result |
| 6186 | * in a prefetch beyond physical memory. |
| 6187 | */ |
| 6188 | static inline void hpsa_p600_dma_prefetch_quirk(struct ctlr_info *h) |
| 6189 | { |
| 6190 | u32 dma_prefetch; |
| 6191 | |
| 6192 | if (h->board_id != 0x3225103C) |
| 6193 | return; |
| 6194 | dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG); |
| 6195 | dma_prefetch |= 0x8000; |
| 6196 | writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG); |
| 6197 | } |
| 6198 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6199 | static int hpsa_wait_for_clear_event_notify_ack(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6200 | { |
| 6201 | int i; |
| 6202 | u32 doorbell_value; |
| 6203 | unsigned long flags; |
| 6204 | /* wait until the clear_event_notify bit 6 is cleared by controller. */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 6205 | for (i = 0; i < MAX_CLEAR_EVENT_WAIT; i++) { |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6206 | spin_lock_irqsave(&h->lock, flags); |
| 6207 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 6208 | spin_unlock_irqrestore(&h->lock, flags); |
| 6209 | if (!(doorbell_value & DOORBELL_CLEAR_EVENTS)) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6210 | goto done; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6211 | /* delay and try again */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 6212 | msleep(CLEAR_EVENT_WAIT_INTERVAL); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6213 | } |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6214 | return -ENODEV; |
| 6215 | done: |
| 6216 | return 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6217 | } |
| 6218 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6219 | static int hpsa_wait_for_mode_change_ack(struct ctlr_info *h) |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6220 | { |
| 6221 | int i; |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6222 | u32 doorbell_value; |
| 6223 | unsigned long flags; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6224 | |
| 6225 | /* under certain very rare conditions, this can take awhile. |
| 6226 | * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right |
| 6227 | * as we enter this code.) |
| 6228 | */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 6229 | for (i = 0; i < MAX_MODE_CHANGE_WAIT; i++) { |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6230 | spin_lock_irqsave(&h->lock, flags); |
| 6231 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 6232 | spin_unlock_irqrestore(&h->lock, flags); |
Dan Carpenter | 382be66 | 2011-02-15 15:33:13 -0600 | [diff] [blame] | 6233 | if (!(doorbell_value & CFGTBL_ChangeReq)) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6234 | goto done; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6235 | /* delay and try again */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 6236 | msleep(MODE_CHANGE_WAIT_INTERVAL); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6237 | } |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6238 | return -ENODEV; |
| 6239 | done: |
| 6240 | return 0; |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6241 | } |
| 6242 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6243 | /* return -ENODEV or other reason on error, 0 on success */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6244 | static int hpsa_enter_simple_mode(struct ctlr_info *h) |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6245 | { |
| 6246 | u32 trans_support; |
| 6247 | |
| 6248 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 6249 | if (!(trans_support & SIMPLE_MODE)) |
| 6250 | return -ENOTSUPP; |
| 6251 | |
| 6252 | h->max_commands = readl(&(h->cfgtable->CmdsOutMax)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6253 | |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6254 | /* Update the field, and then ring the doorbell */ |
| 6255 | writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest)); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 6256 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 6257 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 6258 | if (hpsa_wait_for_mode_change_ack(h)) |
| 6259 | goto error; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6260 | print_cfg_table(&h->pdev->dev, h->cfgtable); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6261 | if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) |
| 6262 | goto error; |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 6263 | h->transMethod = CFGTBL_Trans_Simple; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6264 | return 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6265 | error: |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 6266 | dev_err(&h->pdev->dev, "failed to enter simple mode\n"); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6267 | return -ENODEV; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6268 | } |
| 6269 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6270 | static int hpsa_pci_init(struct ctlr_info *h) |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6271 | { |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6272 | int prod_index, err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6273 | |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 6274 | prod_index = hpsa_lookup_board_id(h->pdev, &h->board_id); |
| 6275 | if (prod_index < 0) |
Robert Elliott | 60f923b | 2015-01-23 16:42:06 -0600 | [diff] [blame] | 6276 | return prod_index; |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 6277 | h->product_name = products[prod_index].product_name; |
| 6278 | h->access = *(products[prod_index].access); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6279 | |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 6280 | pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S | |
| 6281 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); |
| 6282 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6283 | err = pci_enable_device(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6284 | if (err) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6285 | dev_warn(&h->pdev->dev, "unable to enable PCI device\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6286 | return err; |
| 6287 | } |
| 6288 | |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 6289 | err = pci_request_regions(h->pdev, HPSA); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6290 | if (err) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6291 | dev_err(&h->pdev->dev, |
| 6292 | "cannot obtain PCI resources, aborting\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6293 | return err; |
| 6294 | } |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 6295 | |
| 6296 | pci_set_master(h->pdev); |
| 6297 | |
Stephen M. Cameron | 6b3f4c5 | 2010-05-27 15:13:02 -0500 | [diff] [blame] | 6298 | hpsa_interrupt_mode(h); |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 6299 | err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 6300 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6301 | goto err_out_free_res; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6302 | h->vaddr = remap_pci_mem(h->paddr, 0x250); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 6303 | if (!h->vaddr) { |
| 6304 | err = -ENOMEM; |
| 6305 | goto err_out_free_res; |
| 6306 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 6307 | 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] | 6308 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6309 | goto err_out_free_res; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 6310 | err = hpsa_find_cfgtables(h); |
| 6311 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6312 | goto err_out_free_res; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 6313 | hpsa_find_board_params(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6314 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 6315 | if (!hpsa_CISS_signature_present(h)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6316 | err = -ENODEV; |
| 6317 | goto err_out_free_res; |
| 6318 | } |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 6319 | hpsa_set_driver_support_bits(h); |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 6320 | hpsa_p600_dma_prefetch_quirk(h); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 6321 | err = hpsa_enter_simple_mode(h); |
| 6322 | if (err) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6323 | goto err_out_free_res; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6324 | return 0; |
| 6325 | |
| 6326 | err_out_free_res: |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 6327 | if (h->transtable) |
| 6328 | iounmap(h->transtable); |
| 6329 | if (h->cfgtable) |
| 6330 | iounmap(h->cfgtable); |
| 6331 | if (h->vaddr) |
| 6332 | iounmap(h->vaddr); |
Stephen M. Cameron | f0bd0b68 | 2012-05-01 11:42:09 -0500 | [diff] [blame] | 6333 | pci_disable_device(h->pdev); |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6334 | pci_release_regions(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6335 | return err; |
| 6336 | } |
| 6337 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6338 | static void hpsa_hba_inquiry(struct ctlr_info *h) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 6339 | { |
| 6340 | int rc; |
| 6341 | |
| 6342 | #define HBA_INQUIRY_BYTE_COUNT 64 |
| 6343 | h->hba_inquiry_data = kmalloc(HBA_INQUIRY_BYTE_COUNT, GFP_KERNEL); |
| 6344 | if (!h->hba_inquiry_data) |
| 6345 | return; |
| 6346 | rc = hpsa_scsi_do_inquiry(h, RAID_CTLR_LUNID, 0, |
| 6347 | h->hba_inquiry_data, HBA_INQUIRY_BYTE_COUNT); |
| 6348 | if (rc != 0) { |
| 6349 | kfree(h->hba_inquiry_data); |
| 6350 | h->hba_inquiry_data = NULL; |
| 6351 | } |
| 6352 | } |
| 6353 | |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 6354 | static int hpsa_init_reset_devices(struct pci_dev *pdev, u32 board_id) |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6355 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6356 | int rc, i; |
Tomas Henzl | 3b74729 | 2015-01-23 16:41:20 -0600 | [diff] [blame] | 6357 | void __iomem *vaddr; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6358 | |
| 6359 | if (!reset_devices) |
| 6360 | return 0; |
| 6361 | |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 6362 | /* kdump kernel is loading, we don't know in which state is |
| 6363 | * the pci interface. The dev->enable_cnt is equal zero |
| 6364 | * so we call enable+disable, wait a while and switch it on. |
| 6365 | */ |
| 6366 | rc = pci_enable_device(pdev); |
| 6367 | if (rc) { |
| 6368 | dev_warn(&pdev->dev, "Failed to enable PCI device\n"); |
| 6369 | return -ENODEV; |
| 6370 | } |
| 6371 | pci_disable_device(pdev); |
| 6372 | msleep(260); /* a randomly chosen number */ |
| 6373 | rc = pci_enable_device(pdev); |
| 6374 | if (rc) { |
| 6375 | dev_warn(&pdev->dev, "failed to enable device.\n"); |
| 6376 | return -ENODEV; |
| 6377 | } |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 6378 | |
Tomas Henzl | 859c75a | 2014-09-12 14:44:15 +0200 | [diff] [blame] | 6379 | pci_set_master(pdev); |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 6380 | |
Tomas Henzl | 3b74729 | 2015-01-23 16:41:20 -0600 | [diff] [blame] | 6381 | vaddr = pci_ioremap_bar(pdev, 0); |
| 6382 | if (vaddr == NULL) { |
| 6383 | rc = -ENOMEM; |
| 6384 | goto out_disable; |
| 6385 | } |
| 6386 | writel(SA5_INTR_OFF, vaddr + SA5_REPLY_INTR_MASK_OFFSET); |
| 6387 | iounmap(vaddr); |
| 6388 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6389 | /* Reset the controller with a PCI power-cycle or via doorbell */ |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 6390 | rc = hpsa_kdump_hard_reset_controller(pdev, board_id); |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6391 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6392 | /* -ENOTSUPP here means we cannot reset the controller |
| 6393 | * but it's already (and still) up and running in |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 6394 | * "performant mode". Or, it might be 640x, which can't reset |
| 6395 | * due to concerns about shared bbwc between 6402/6404 pair. |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6396 | */ |
Robert Elliott | adf1b3a | 2015-01-23 16:42:01 -0600 | [diff] [blame] | 6397 | if (rc) |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 6398 | goto out_disable; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6399 | |
| 6400 | /* Now try to get the controller to respond to a no-op */ |
Robert Elliott | 1ba66c9 | 2015-01-23 16:42:11 -0600 | [diff] [blame] | 6401 | dev_info(&pdev->dev, "Waiting for controller to respond to no-op\n"); |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6402 | for (i = 0; i < HPSA_POST_RESET_NOOP_RETRIES; i++) { |
| 6403 | if (hpsa_noop(pdev) == 0) |
| 6404 | break; |
| 6405 | else |
| 6406 | dev_warn(&pdev->dev, "no-op failed%s\n", |
| 6407 | (i < 11 ? "; re-trying" : "")); |
| 6408 | } |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 6409 | |
| 6410 | out_disable: |
| 6411 | |
| 6412 | pci_disable_device(pdev); |
| 6413 | return rc; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6414 | } |
| 6415 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6416 | static int hpsa_allocate_cmd_pool(struct ctlr_info *h) |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6417 | { |
| 6418 | h->cmd_pool_bits = kzalloc( |
| 6419 | DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) * |
| 6420 | sizeof(unsigned long), GFP_KERNEL); |
| 6421 | h->cmd_pool = pci_alloc_consistent(h->pdev, |
| 6422 | h->nr_cmds * sizeof(*h->cmd_pool), |
| 6423 | &(h->cmd_pool_dhandle)); |
| 6424 | h->errinfo_pool = pci_alloc_consistent(h->pdev, |
| 6425 | h->nr_cmds * sizeof(*h->errinfo_pool), |
| 6426 | &(h->errinfo_pool_dhandle)); |
| 6427 | if ((h->cmd_pool_bits == NULL) |
| 6428 | || (h->cmd_pool == NULL) |
| 6429 | || (h->errinfo_pool == NULL)) { |
| 6430 | dev_err(&h->pdev->dev, "out of memory in %s", __func__); |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 6431 | goto clean_up; |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6432 | } |
| 6433 | return 0; |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 6434 | clean_up: |
| 6435 | hpsa_free_cmd_pool(h); |
| 6436 | return -ENOMEM; |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6437 | } |
| 6438 | |
| 6439 | static void hpsa_free_cmd_pool(struct ctlr_info *h) |
| 6440 | { |
| 6441 | kfree(h->cmd_pool_bits); |
| 6442 | if (h->cmd_pool) |
| 6443 | pci_free_consistent(h->pdev, |
| 6444 | h->nr_cmds * sizeof(struct CommandList), |
| 6445 | h->cmd_pool, h->cmd_pool_dhandle); |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 6446 | if (h->ioaccel2_cmd_pool) |
| 6447 | pci_free_consistent(h->pdev, |
| 6448 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 6449 | h->ioaccel2_cmd_pool, h->ioaccel2_cmd_pool_dhandle); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6450 | if (h->errinfo_pool) |
| 6451 | pci_free_consistent(h->pdev, |
| 6452 | h->nr_cmds * sizeof(struct ErrorInfo), |
| 6453 | h->errinfo_pool, |
| 6454 | h->errinfo_pool_dhandle); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6455 | if (h->ioaccel_cmd_pool) |
| 6456 | pci_free_consistent(h->pdev, |
| 6457 | h->nr_cmds * sizeof(struct io_accel1_cmd), |
| 6458 | h->ioaccel_cmd_pool, h->ioaccel_cmd_pool_dhandle); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 6459 | } |
| 6460 | |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 6461 | static void hpsa_irq_affinity_hints(struct ctlr_info *h) |
| 6462 | { |
Fabian Frederick | ec42995 | 2015-01-23 16:41:46 -0600 | [diff] [blame] | 6463 | int i, cpu; |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 6464 | |
| 6465 | cpu = cpumask_first(cpu_online_mask); |
| 6466 | for (i = 0; i < h->msix_vector; i++) { |
Fabian Frederick | ec42995 | 2015-01-23 16:41:46 -0600 | [diff] [blame] | 6467 | irq_set_affinity_hint(h->intr[i], get_cpu_mask(cpu)); |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 6468 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 6469 | } |
| 6470 | } |
| 6471 | |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 6472 | /* clear affinity hints and free MSI-X, MSI, or legacy INTx vectors */ |
| 6473 | static void hpsa_free_irqs(struct ctlr_info *h) |
| 6474 | { |
| 6475 | int i; |
| 6476 | |
| 6477 | if (!h->msix_vector || h->intr_mode != PERF_MODE_INT) { |
| 6478 | /* Single reply queue, only one irq to free */ |
| 6479 | i = h->intr_mode; |
| 6480 | irq_set_affinity_hint(h->intr[i], NULL); |
| 6481 | free_irq(h->intr[i], &h->q[i]); |
| 6482 | return; |
| 6483 | } |
| 6484 | |
| 6485 | for (i = 0; i < h->msix_vector; i++) { |
| 6486 | irq_set_affinity_hint(h->intr[i], NULL); |
| 6487 | free_irq(h->intr[i], &h->q[i]); |
| 6488 | } |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 6489 | for (; i < MAX_REPLY_QUEUES; i++) |
| 6490 | h->q[i] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 6491 | } |
| 6492 | |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 6493 | /* returns 0 on success; cleans up and returns -Enn on error */ |
| 6494 | static int hpsa_request_irqs(struct ctlr_info *h, |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6495 | irqreturn_t (*msixhandler)(int, void *), |
| 6496 | irqreturn_t (*intxhandler)(int, void *)) |
| 6497 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6498 | int rc, i; |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6499 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6500 | /* |
| 6501 | * initialize h->q[x] = x so that interrupt handlers know which |
| 6502 | * queue to process. |
| 6503 | */ |
| 6504 | for (i = 0; i < MAX_REPLY_QUEUES; i++) |
| 6505 | h->q[i] = (u8) i; |
| 6506 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 6507 | if (h->intr_mode == PERF_MODE_INT && h->msix_vector > 0) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6508 | /* If performant mode and MSI-X, use multiple reply queues */ |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 6509 | for (i = 0; i < h->msix_vector; i++) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6510 | rc = request_irq(h->intr[i], msixhandler, |
| 6511 | 0, h->devname, |
| 6512 | &h->q[i]); |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 6513 | if (rc) { |
| 6514 | int j; |
| 6515 | |
| 6516 | dev_err(&h->pdev->dev, |
| 6517 | "failed to get irq %d for %s\n", |
| 6518 | h->intr[i], h->devname); |
| 6519 | for (j = 0; j < i; j++) { |
| 6520 | free_irq(h->intr[j], &h->q[j]); |
| 6521 | h->q[j] = 0; |
| 6522 | } |
| 6523 | for (; j < MAX_REPLY_QUEUES; j++) |
| 6524 | h->q[j] = 0; |
| 6525 | return rc; |
| 6526 | } |
| 6527 | } |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 6528 | hpsa_irq_affinity_hints(h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6529 | } else { |
| 6530 | /* Use single reply pool */ |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 6531 | if (h->msix_vector > 0 || h->msi_vector) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6532 | rc = request_irq(h->intr[h->intr_mode], |
| 6533 | msixhandler, 0, h->devname, |
| 6534 | &h->q[h->intr_mode]); |
| 6535 | } else { |
| 6536 | rc = request_irq(h->intr[h->intr_mode], |
| 6537 | intxhandler, IRQF_SHARED, h->devname, |
| 6538 | &h->q[h->intr_mode]); |
| 6539 | } |
| 6540 | } |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 6541 | if (rc) { |
| 6542 | dev_err(&h->pdev->dev, "unable to get irq %d for %s\n", |
| 6543 | h->intr[h->intr_mode], h->devname); |
| 6544 | return -ENODEV; |
| 6545 | } |
| 6546 | return 0; |
| 6547 | } |
| 6548 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6549 | static int hpsa_kdump_soft_reset(struct ctlr_info *h) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6550 | { |
| 6551 | if (hpsa_send_host_reset(h, RAID_CTLR_LUNID, |
| 6552 | HPSA_RESET_TYPE_CONTROLLER)) { |
| 6553 | dev_warn(&h->pdev->dev, "Resetting array controller failed.\n"); |
| 6554 | return -EIO; |
| 6555 | } |
| 6556 | |
| 6557 | dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n"); |
| 6558 | if (hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY)) { |
| 6559 | dev_warn(&h->pdev->dev, "Soft reset had no effect.\n"); |
| 6560 | return -1; |
| 6561 | } |
| 6562 | |
| 6563 | dev_info(&h->pdev->dev, "Board reset, awaiting READY status.\n"); |
| 6564 | if (hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY)) { |
| 6565 | dev_warn(&h->pdev->dev, "Board failed to become ready " |
| 6566 | "after soft reset.\n"); |
| 6567 | return -1; |
| 6568 | } |
| 6569 | |
| 6570 | return 0; |
| 6571 | } |
| 6572 | |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6573 | 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] | 6574 | { |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 6575 | hpsa_free_irqs(h); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6576 | #ifdef CONFIG_PCI_MSI |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6577 | if (h->msix_vector) { |
| 6578 | if (h->pdev->msix_enabled) |
| 6579 | pci_disable_msix(h->pdev); |
| 6580 | } else if (h->msi_vector) { |
| 6581 | if (h->pdev->msi_enabled) |
| 6582 | pci_disable_msi(h->pdev); |
| 6583 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6584 | #endif /* CONFIG_PCI_MSI */ |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6585 | } |
| 6586 | |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 6587 | static void hpsa_free_reply_queues(struct ctlr_info *h) |
| 6588 | { |
| 6589 | int i; |
| 6590 | |
| 6591 | for (i = 0; i < h->nreply_queues; i++) { |
| 6592 | if (!h->reply_queue[i].head) |
| 6593 | continue; |
| 6594 | pci_free_consistent(h->pdev, h->reply_queue_size, |
| 6595 | h->reply_queue[i].head, h->reply_queue[i].busaddr); |
| 6596 | h->reply_queue[i].head = NULL; |
| 6597 | h->reply_queue[i].busaddr = 0; |
| 6598 | } |
| 6599 | } |
| 6600 | |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 6601 | static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h) |
| 6602 | { |
| 6603 | hpsa_free_irqs_and_disable_msix(h); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6604 | hpsa_free_sg_chain_blocks(h); |
| 6605 | hpsa_free_cmd_pool(h); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 6606 | kfree(h->ioaccel1_blockFetchTable); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6607 | kfree(h->blockFetchTable); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 6608 | hpsa_free_reply_queues(h); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6609 | if (h->vaddr) |
| 6610 | iounmap(h->vaddr); |
| 6611 | if (h->transtable) |
| 6612 | iounmap(h->transtable); |
| 6613 | if (h->cfgtable) |
| 6614 | iounmap(h->cfgtable); |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 6615 | pci_disable_device(h->pdev); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6616 | pci_release_regions(h->pdev); |
| 6617 | kfree(h); |
| 6618 | } |
| 6619 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6620 | /* Called when controller lockup detected. */ |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6621 | static void fail_all_outstanding_cmds(struct ctlr_info *h) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6622 | { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6623 | int i, refcount; |
| 6624 | struct CommandList *c; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6625 | |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 6626 | flush_workqueue(h->resubmit_wq); /* ensure all cmds are fully built */ |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6627 | for (i = 0; i < h->nr_cmds; i++) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6628 | c = h->cmd_pool + i; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6629 | refcount = atomic_inc_return(&c->refcount); |
| 6630 | if (refcount > 1) { |
| 6631 | c->err_info->CommandStatus = CMD_HARDWARE_ERR; |
| 6632 | finish_cmd(c); |
| 6633 | } |
| 6634 | cmd_free(h, c); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6635 | } |
| 6636 | } |
| 6637 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6638 | static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value) |
| 6639 | { |
Rusty Russell | c8ed001 | 2015-03-05 10:49:19 +1030 | [diff] [blame] | 6640 | int cpu; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6641 | |
Rusty Russell | c8ed001 | 2015-03-05 10:49:19 +1030 | [diff] [blame] | 6642 | for_each_online_cpu(cpu) { |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6643 | u32 *lockup_detected; |
| 6644 | lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); |
| 6645 | *lockup_detected = value; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6646 | } |
| 6647 | wmb(); /* be sure the per-cpu variables are out to memory */ |
| 6648 | } |
| 6649 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6650 | static void controller_lockup_detected(struct ctlr_info *h) |
| 6651 | { |
| 6652 | unsigned long flags; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6653 | u32 lockup_detected; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6654 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6655 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 6656 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6657 | lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); |
| 6658 | if (!lockup_detected) { |
| 6659 | /* no heartbeat, but controller gave us a zero. */ |
| 6660 | dev_warn(&h->pdev->dev, |
| 6661 | "lockup detected but scratchpad register is zero\n"); |
| 6662 | lockup_detected = 0xffffffff; |
| 6663 | } |
| 6664 | set_lockup_detected_for_all_cpus(h, lockup_detected); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6665 | spin_unlock_irqrestore(&h->lock, flags); |
| 6666 | dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n", |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6667 | lockup_detected); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6668 | pci_disable_device(h->pdev); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6669 | fail_all_outstanding_cmds(h); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6670 | } |
| 6671 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6672 | static void detect_controller_lockup(struct ctlr_info *h) |
| 6673 | { |
| 6674 | u64 now; |
| 6675 | u32 heartbeat; |
| 6676 | unsigned long flags; |
| 6677 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6678 | now = get_jiffies_64(); |
| 6679 | /* If we've received an interrupt recently, we're ok. */ |
| 6680 | if (time_after64(h->last_intr_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 6681 | (h->heartbeat_sample_interval), now)) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6682 | return; |
| 6683 | |
| 6684 | /* |
| 6685 | * If we've already checked the heartbeat recently, we're ok. |
| 6686 | * This could happen if someone sends us a signal. We |
| 6687 | * otherwise don't care about signals in this thread. |
| 6688 | */ |
| 6689 | if (time_after64(h->last_heartbeat_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 6690 | (h->heartbeat_sample_interval), now)) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6691 | return; |
| 6692 | |
| 6693 | /* If heartbeat has not changed since we last looked, we're not ok. */ |
| 6694 | spin_lock_irqsave(&h->lock, flags); |
| 6695 | heartbeat = readl(&h->cfgtable->HeartBeat); |
| 6696 | spin_unlock_irqrestore(&h->lock, flags); |
| 6697 | if (h->last_heartbeat == heartbeat) { |
| 6698 | controller_lockup_detected(h); |
| 6699 | return; |
| 6700 | } |
| 6701 | |
| 6702 | /* We're ok. */ |
| 6703 | h->last_heartbeat = heartbeat; |
| 6704 | h->last_heartbeat_timestamp = now; |
| 6705 | } |
| 6706 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6707 | static void hpsa_ack_ctlr_events(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6708 | { |
| 6709 | int i; |
| 6710 | char *event_type; |
| 6711 | |
Stephen Cameron | e4aa3e6 | 2015-01-23 16:44:07 -0600 | [diff] [blame] | 6712 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
| 6713 | return; |
| 6714 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6715 | /* Ask the controller to clear the events we're handling. */ |
Stephen M. Cameron | 1f7cee8 | 2014-02-18 13:56:09 -0600 | [diff] [blame] | 6716 | if ((h->transMethod & (CFGTBL_Trans_io_accel1 |
| 6717 | | CFGTBL_Trans_io_accel2)) && |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6718 | (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE || |
| 6719 | h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE)) { |
| 6720 | |
| 6721 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE) |
| 6722 | event_type = "state change"; |
| 6723 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE) |
| 6724 | event_type = "configuration change"; |
| 6725 | /* Stop sending new RAID offload reqs via the IO accelerator */ |
| 6726 | scsi_block_requests(h->scsi_host); |
| 6727 | for (i = 0; i < h->ndevices; i++) |
| 6728 | h->dev[i]->offload_enabled = 0; |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 6729 | hpsa_drain_accel_commands(h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6730 | /* Set 'accelerator path config change' bit */ |
| 6731 | dev_warn(&h->pdev->dev, |
| 6732 | "Acknowledging event: 0x%08x (HP SSD Smart Path %s)\n", |
| 6733 | h->events, event_type); |
| 6734 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 6735 | /* Set the "clear event notify field update" bit 6 */ |
| 6736 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 6737 | /* Wait until ctlr clears 'clear event notify field', bit 6 */ |
| 6738 | hpsa_wait_for_clear_event_notify_ack(h); |
| 6739 | scsi_unblock_requests(h->scsi_host); |
| 6740 | } else { |
| 6741 | /* Acknowledge controller notification events. */ |
| 6742 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 6743 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 6744 | hpsa_wait_for_clear_event_notify_ack(h); |
| 6745 | #if 0 |
| 6746 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
| 6747 | hpsa_wait_for_mode_change_ack(h); |
| 6748 | #endif |
| 6749 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6750 | return; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | /* Check a register on the controller to see if there are configuration |
| 6754 | * changes (added/changed/removed logical drives, etc.) which mean that |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 6755 | * we should rescan the controller for devices. |
| 6756 | * Also check flag for driver-initiated rescan. |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6757 | */ |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6758 | static int hpsa_ctlr_needs_rescan(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6759 | { |
| 6760 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6761 | return 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6762 | |
| 6763 | h->events = readl(&(h->cfgtable->event_notify)); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6764 | return h->events & RESCAN_REQUIRED_EVENT_BITS; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 6765 | } |
| 6766 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6767 | /* |
| 6768 | * Check if any of the offline devices have become ready |
| 6769 | */ |
| 6770 | static int hpsa_offline_devices_ready(struct ctlr_info *h) |
| 6771 | { |
| 6772 | unsigned long flags; |
| 6773 | struct offline_device_entry *d; |
| 6774 | struct list_head *this, *tmp; |
| 6775 | |
| 6776 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 6777 | list_for_each_safe(this, tmp, &h->offline_device_list) { |
| 6778 | d = list_entry(this, struct offline_device_entry, |
| 6779 | offline_list); |
| 6780 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
Stephen M. Cameron | d1fea47 | 2014-07-03 10:17:58 -0500 | [diff] [blame] | 6781 | if (!hpsa_volume_offline(h, d->scsi3addr)) { |
| 6782 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 6783 | list_del(&d->offline_list); |
| 6784 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6785 | return 1; |
Stephen M. Cameron | d1fea47 | 2014-07-03 10:17:58 -0500 | [diff] [blame] | 6786 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6787 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 6788 | } |
| 6789 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 6790 | return 0; |
| 6791 | } |
| 6792 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6793 | static void hpsa_rescan_ctlr_worker(struct work_struct *work) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6794 | { |
| 6795 | unsigned long flags; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6796 | struct ctlr_info *h = container_of(to_delayed_work(work), |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6797 | struct ctlr_info, rescan_ctlr_work); |
| 6798 | |
| 6799 | |
| 6800 | if (h->remove_in_progress) |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6801 | return; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6802 | |
| 6803 | if (hpsa_ctlr_needs_rescan(h) || hpsa_offline_devices_ready(h)) { |
| 6804 | scsi_host_get(h->scsi_host); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6805 | hpsa_ack_ctlr_events(h); |
| 6806 | hpsa_scan_start(h->scsi_host); |
| 6807 | scsi_host_put(h->scsi_host); |
| 6808 | } |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6809 | spin_lock_irqsave(&h->lock, flags); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6810 | if (!h->remove_in_progress) |
| 6811 | queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work, |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 6812 | h->heartbeat_sample_interval); |
| 6813 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6814 | } |
| 6815 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6816 | static void hpsa_monitor_ctlr_worker(struct work_struct *work) |
| 6817 | { |
| 6818 | unsigned long flags; |
| 6819 | struct ctlr_info *h = container_of(to_delayed_work(work), |
| 6820 | struct ctlr_info, monitor_ctlr_work); |
| 6821 | |
| 6822 | detect_controller_lockup(h); |
| 6823 | if (lockup_detected(h)) |
| 6824 | return; |
| 6825 | |
| 6826 | spin_lock_irqsave(&h->lock, flags); |
| 6827 | if (!h->remove_in_progress) |
| 6828 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 6829 | h->heartbeat_sample_interval); |
| 6830 | spin_unlock_irqrestore(&h->lock, flags); |
| 6831 | } |
| 6832 | |
| 6833 | static struct workqueue_struct *hpsa_create_controller_wq(struct ctlr_info *h, |
| 6834 | char *name) |
| 6835 | { |
| 6836 | struct workqueue_struct *wq = NULL; |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6837 | |
Don Brace | 397ea9c | 2015-02-06 17:44:15 -0600 | [diff] [blame] | 6838 | wq = alloc_ordered_workqueue("%s_%d_hpsa", 0, name, h->ctlr); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6839 | if (!wq) |
| 6840 | dev_err(&h->pdev->dev, "failed to create %s workqueue\n", name); |
| 6841 | |
| 6842 | return wq; |
| 6843 | } |
| 6844 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6845 | 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] | 6846 | { |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 6847 | int dac, rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6848 | struct ctlr_info *h; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6849 | int try_soft_reset = 0; |
| 6850 | unsigned long flags; |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 6851 | u32 board_id; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6852 | |
| 6853 | if (number_of_controllers == 0) |
| 6854 | printk(KERN_INFO DRIVER_NAME "\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6855 | |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 6856 | rc = hpsa_lookup_board_id(pdev, &board_id); |
| 6857 | if (rc < 0) { |
| 6858 | dev_warn(&pdev->dev, "Board ID not found\n"); |
| 6859 | return rc; |
| 6860 | } |
| 6861 | |
| 6862 | rc = hpsa_init_reset_devices(pdev, board_id); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6863 | if (rc) { |
| 6864 | if (rc != -ENOTSUPP) |
| 6865 | return rc; |
| 6866 | /* If the reset fails in a particular way (it has no way to do |
| 6867 | * a proper hard reset, so returns -ENOTSUPP) we can try to do |
| 6868 | * a soft reset once we get the controller configured up to the |
| 6869 | * point that it can accept a command. |
| 6870 | */ |
| 6871 | try_soft_reset = 1; |
| 6872 | rc = 0; |
| 6873 | } |
| 6874 | |
| 6875 | reinit_after_soft_reset: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6876 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6877 | /* Command structures must be aligned on a 32-byte boundary because |
| 6878 | * the 5 lower bits of the address are used by the hardware. and by |
| 6879 | * the driver. See comments in hpsa.h for more info. |
| 6880 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6881 | BUILD_BUG_ON(sizeof(struct CommandList) % COMMANDLIST_ALIGNMENT); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6882 | h = kzalloc(sizeof(*h), GFP_KERNEL); |
| 6883 | if (!h) |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6884 | return -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6885 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6886 | h->pdev = pdev; |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 6887 | h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6888 | INIT_LIST_HEAD(&h->offline_device_list); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6889 | spin_lock_init(&h->lock); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 6890 | spin_lock_init(&h->offline_device_lock); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 6891 | spin_lock_init(&h->scan_lock); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6892 | atomic_set(&h->passthru_cmds_avail, HPSA_MAX_CONCURRENT_PASSTHRUS); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6893 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6894 | h->rescan_ctlr_wq = hpsa_create_controller_wq(h, "rescan"); |
| 6895 | if (!h->rescan_ctlr_wq) { |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 6896 | rc = -ENOMEM; |
| 6897 | goto clean1; |
| 6898 | } |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 6899 | |
| 6900 | h->resubmit_wq = hpsa_create_controller_wq(h, "resubmit"); |
| 6901 | if (!h->resubmit_wq) { |
| 6902 | rc = -ENOMEM; |
| 6903 | goto clean1; |
| 6904 | } |
| 6905 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6906 | /* Allocate and clear per-cpu variable lockup_detected */ |
| 6907 | h->lockup_detected = alloc_percpu(u32); |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 6908 | if (!h->lockup_detected) { |
| 6909 | rc = -ENOMEM; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6910 | goto clean1; |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 6911 | } |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 6912 | set_lockup_detected_for_all_cpus(h, 0); |
| 6913 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 6914 | rc = hpsa_pci_init(h); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6915 | if (rc != 0) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6916 | goto clean1; |
| 6917 | |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 6918 | sprintf(h->devname, HPSA "%d", number_of_controllers); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6919 | h->ctlr = number_of_controllers; |
| 6920 | number_of_controllers++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6921 | |
| 6922 | /* configure PCI DMA stuff */ |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6923 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 6924 | if (rc == 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6925 | dac = 1; |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 6926 | } else { |
| 6927 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 6928 | if (rc == 0) { |
| 6929 | dac = 0; |
| 6930 | } else { |
| 6931 | dev_err(&pdev->dev, "no suitable DMA available\n"); |
| 6932 | goto clean1; |
| 6933 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6934 | } |
| 6935 | |
| 6936 | /* make sure the board interrupts are off */ |
| 6937 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6938 | |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 6939 | if (hpsa_request_irqs(h, do_hpsa_intr_msi, do_hpsa_intr_intx)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6940 | goto clean2; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6941 | dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n", |
| 6942 | h->devname, pdev->device, |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 6943 | h->intr[h->intr_mode], dac ? "" : " not"); |
Robert Elliott | 8947fd1 | 2015-01-23 16:42:54 -0600 | [diff] [blame] | 6944 | rc = hpsa_allocate_cmd_pool(h); |
| 6945 | if (rc) |
| 6946 | goto clean2_and_free_irqs; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 6947 | if (hpsa_allocate_sg_chain_blocks(h)) |
| 6948 | goto clean4; |
Stephen M. Cameron | a08a8471 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 6949 | init_waitqueue_head(&h->scan_wait_queue); |
| 6950 | h->scan_finished = 1; /* no scan currently in progress */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6951 | |
| 6952 | pci_set_drvdata(pdev, h); |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 6953 | h->ndevices = 0; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 6954 | h->hba_mode_enabled = 0; |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 6955 | h->scsi_host = NULL; |
| 6956 | spin_lock_init(&h->devlock); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6957 | hpsa_put_ctlr_into_performant_mode(h); |
| 6958 | |
| 6959 | /* At this point, the controller is ready to take commands. |
| 6960 | * Now, if reset_devices and the hard reset didn't work, try |
| 6961 | * the soft reset and see if that works. |
| 6962 | */ |
| 6963 | if (try_soft_reset) { |
| 6964 | |
| 6965 | /* This is kind of gross. We may or may not get a completion |
| 6966 | * from the soft reset command, and if we do, then the value |
| 6967 | * from the fifo may or may not be valid. So, we wait 10 secs |
| 6968 | * after the reset throwing away any completions we get during |
| 6969 | * that time. Unregister the interrupt handler and register |
| 6970 | * fake ones to scoop up any residual completions. |
| 6971 | */ |
| 6972 | spin_lock_irqsave(&h->lock, flags); |
| 6973 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 6974 | spin_unlock_irqrestore(&h->lock, flags); |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 6975 | hpsa_free_irqs(h); |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 6976 | rc = hpsa_request_irqs(h, hpsa_msix_discard_completions, |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6977 | hpsa_intx_discard_completions); |
| 6978 | if (rc) { |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 6979 | dev_warn(&h->pdev->dev, |
| 6980 | "Failed to request_irq after soft reset.\n"); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6981 | goto clean4; |
| 6982 | } |
| 6983 | |
| 6984 | rc = hpsa_kdump_soft_reset(h); |
| 6985 | if (rc) |
| 6986 | /* Neither hard nor soft reset worked, we're hosed. */ |
| 6987 | goto clean4; |
| 6988 | |
| 6989 | dev_info(&h->pdev->dev, "Board READY.\n"); |
| 6990 | dev_info(&h->pdev->dev, |
| 6991 | "Waiting for stale completions to drain.\n"); |
| 6992 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 6993 | msleep(10000); |
| 6994 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 6995 | |
| 6996 | rc = controller_reset_failed(h->cfgtable); |
| 6997 | if (rc) |
| 6998 | dev_info(&h->pdev->dev, |
| 6999 | "Soft reset appears to have failed.\n"); |
| 7000 | |
| 7001 | /* since the controller's reset, we have to go back and re-init |
| 7002 | * everything. Easiest to just forget what we've done and do it |
| 7003 | * all over again. |
| 7004 | */ |
| 7005 | hpsa_undo_allocations_after_kdump_soft_reset(h); |
| 7006 | try_soft_reset = 0; |
| 7007 | if (rc) |
| 7008 | /* don't go to clean4, we already unallocated */ |
| 7009 | return -ENODEV; |
| 7010 | |
| 7011 | goto reinit_after_soft_reset; |
| 7012 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7013 | |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 7014 | /* Enable Accelerated IO path at driver layer */ |
| 7015 | h->acciopath_status = 1; |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 7016 | |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 7017 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7018 | /* Turn the interrupts on so we can service requests */ |
| 7019 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 7020 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 7021 | hpsa_hba_inquiry(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7022 | hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */ |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 7023 | |
| 7024 | /* Monitor the controller for firmware lockups */ |
| 7025 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 7026 | INIT_DELAYED_WORK(&h->monitor_ctlr_work, hpsa_monitor_ctlr_worker); |
| 7027 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 7028 | h->heartbeat_sample_interval); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 7029 | INIT_DELAYED_WORK(&h->rescan_ctlr_work, hpsa_rescan_ctlr_worker); |
| 7030 | queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work, |
| 7031 | h->heartbeat_sample_interval); |
Stephen M. Cameron | 88bf6d6 | 2013-11-01 11:02:25 -0500 | [diff] [blame] | 7032 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7033 | |
| 7034 | clean4: |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 7035 | hpsa_free_sg_chain_blocks(h); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 7036 | hpsa_free_cmd_pool(h); |
Robert Elliott | 8947fd1 | 2015-01-23 16:42:54 -0600 | [diff] [blame] | 7037 | clean2_and_free_irqs: |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 7038 | hpsa_free_irqs(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7039 | clean2: |
| 7040 | clean1: |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 7041 | if (h->resubmit_wq) |
| 7042 | destroy_workqueue(h->resubmit_wq); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 7043 | if (h->rescan_ctlr_wq) |
| 7044 | destroy_workqueue(h->rescan_ctlr_wq); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7045 | if (h->lockup_detected) |
| 7046 | free_percpu(h->lockup_detected); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7047 | kfree(h); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 7048 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | static void hpsa_flush_cache(struct ctlr_info *h) |
| 7052 | { |
| 7053 | char *flush_buf; |
| 7054 | struct CommandList *c; |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 7055 | |
| 7056 | /* Don't bother trying to flush the cache if locked up */ |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7057 | if (unlikely(lockup_detected(h))) |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 7058 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7059 | flush_buf = kzalloc(4, GFP_KERNEL); |
| 7060 | if (!flush_buf) |
| 7061 | return; |
| 7062 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 7063 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7064 | if (!c) { |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 7065 | dev_warn(&h->pdev->dev, "cmd_alloc returned NULL!\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7066 | goto out_of_memory; |
| 7067 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 7068 | if (fill_cmd(c, HPSA_CACHE_FLUSH, h, flush_buf, 4, 0, |
| 7069 | RAID_CTLR_LUNID, TYPE_CMD)) { |
| 7070 | goto out; |
| 7071 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7072 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_TODEVICE); |
| 7073 | if (c->err_info->CommandStatus != 0) |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 7074 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7075 | dev_warn(&h->pdev->dev, |
| 7076 | "error flushing cache on controller\n"); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 7077 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7078 | out_of_memory: |
| 7079 | kfree(flush_buf); |
| 7080 | } |
| 7081 | |
| 7082 | static void hpsa_shutdown(struct pci_dev *pdev) |
| 7083 | { |
| 7084 | struct ctlr_info *h; |
| 7085 | |
| 7086 | h = pci_get_drvdata(pdev); |
| 7087 | /* Turn board interrupts off and send the flush cache command |
| 7088 | * sendcmd will turn off interrupt, and send the flush... |
| 7089 | * To write all data in the battery backed cache to disks |
| 7090 | */ |
| 7091 | hpsa_flush_cache(h); |
| 7092 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 7093 | hpsa_free_irqs_and_disable_msix(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7096 | static void hpsa_free_device_info(struct ctlr_info *h) |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 7097 | { |
| 7098 | int i; |
| 7099 | |
| 7100 | for (i = 0; i < h->ndevices; i++) |
| 7101 | kfree(h->dev[i]); |
| 7102 | } |
| 7103 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7104 | static void hpsa_remove_one(struct pci_dev *pdev) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7105 | { |
| 7106 | struct ctlr_info *h; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 7107 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7108 | |
| 7109 | if (pci_get_drvdata(pdev) == NULL) { |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7110 | dev_err(&pdev->dev, "unable to remove device\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7111 | return; |
| 7112 | } |
| 7113 | h = pci_get_drvdata(pdev); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 7114 | |
| 7115 | /* Get rid of any controller monitoring work items */ |
| 7116 | spin_lock_irqsave(&h->lock, flags); |
| 7117 | h->remove_in_progress = 1; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 7118 | spin_unlock_irqrestore(&h->lock, flags); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 7119 | cancel_delayed_work_sync(&h->monitor_ctlr_work); |
| 7120 | cancel_delayed_work_sync(&h->rescan_ctlr_work); |
| 7121 | destroy_workqueue(h->rescan_ctlr_wq); |
| 7122 | destroy_workqueue(h->resubmit_wq); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7123 | hpsa_unregister_scsi(h); /* unhook from SCSI subsystem */ |
| 7124 | hpsa_shutdown(pdev); |
| 7125 | iounmap(h->vaddr); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 7126 | iounmap(h->transtable); |
| 7127 | iounmap(h->cfgtable); |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 7128 | hpsa_free_device_info(h); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 7129 | hpsa_free_sg_chain_blocks(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7130 | pci_free_consistent(h->pdev, |
| 7131 | h->nr_cmds * sizeof(struct CommandList), |
| 7132 | h->cmd_pool, h->cmd_pool_dhandle); |
| 7133 | pci_free_consistent(h->pdev, |
| 7134 | h->nr_cmds * sizeof(struct ErrorInfo), |
| 7135 | h->errinfo_pool, h->errinfo_pool_dhandle); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7136 | hpsa_free_reply_queues(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7137 | kfree(h->cmd_pool_bits); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7138 | kfree(h->blockFetchTable); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7139 | kfree(h->ioaccel1_blockFetchTable); |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 7140 | kfree(h->ioaccel2_blockFetchTable); |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 7141 | kfree(h->hba_inquiry_data); |
Stephen M. Cameron | f0bd0b68 | 2012-05-01 11:42:09 -0500 | [diff] [blame] | 7142 | pci_disable_device(pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7143 | pci_release_regions(pdev); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7144 | free_percpu(h->lockup_detected); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7145 | kfree(h); |
| 7146 | } |
| 7147 | |
| 7148 | static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev, |
| 7149 | __attribute__((unused)) pm_message_t state) |
| 7150 | { |
| 7151 | return -ENOSYS; |
| 7152 | } |
| 7153 | |
| 7154 | static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev) |
| 7155 | { |
| 7156 | return -ENOSYS; |
| 7157 | } |
| 7158 | |
| 7159 | static struct pci_driver hpsa_pci_driver = { |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 7160 | .name = HPSA, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7161 | .probe = hpsa_init_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7162 | .remove = hpsa_remove_one, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7163 | .id_table = hpsa_pci_device_id, /* id_table */ |
| 7164 | .shutdown = hpsa_shutdown, |
| 7165 | .suspend = hpsa_suspend, |
| 7166 | .resume = hpsa_resume, |
| 7167 | }; |
| 7168 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7169 | /* Fill in bucket_map[], given nsgs (the max number of |
| 7170 | * scatter gather elements supported) and bucket[], |
| 7171 | * which is an array of 8 integers. The bucket[] array |
| 7172 | * contains 8 different DMA transfer sizes (in 16 |
| 7173 | * byte increments) which the controller uses to fetch |
| 7174 | * commands. This function fills in bucket_map[], which |
| 7175 | * maps a given number of scatter gather elements to one of |
| 7176 | * the 8 DMA transfer sizes. The point of it is to allow the |
| 7177 | * controller to only do as much DMA as needed to fetch the |
| 7178 | * command, with the DMA transfer size encoded in the lower |
| 7179 | * bits of the command address. |
| 7180 | */ |
| 7181 | static void calc_bucket_map(int bucket[], int num_buckets, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7182 | int nsgs, int min_blocks, u32 *bucket_map) |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7183 | { |
| 7184 | int i, j, b, size; |
| 7185 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7186 | /* Note, bucket_map must have nsgs+1 entries. */ |
| 7187 | for (i = 0; i <= nsgs; i++) { |
| 7188 | /* Compute size of a command with i SG entries */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7189 | size = i + min_blocks; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7190 | b = num_buckets; /* Assume the biggest bucket */ |
| 7191 | /* Find the bucket that is just big enough */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7192 | for (j = 0; j < num_buckets; j++) { |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7193 | if (bucket[j] >= size) { |
| 7194 | b = j; |
| 7195 | break; |
| 7196 | } |
| 7197 | } |
| 7198 | /* for a command with i SG entries, use bucket b. */ |
| 7199 | bucket_map[i] = b; |
| 7200 | } |
| 7201 | } |
| 7202 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7203 | /* return -ENODEV or other reason on error, 0 on success */ |
| 7204 | static int hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support) |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7205 | { |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7206 | int i; |
| 7207 | unsigned long register_value; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7208 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 7209 | (trans_support & CFGTBL_Trans_use_short_tags) | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7210 | CFGTBL_Trans_enable_directed_msix | |
| 7211 | (trans_support & (CFGTBL_Trans_io_accel1 | |
| 7212 | CFGTBL_Trans_io_accel2)); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7213 | struct access_method access = SA5_performant_access; |
Stephen M. Cameron | def342b | 2010-05-27 15:14:39 -0500 | [diff] [blame] | 7214 | |
| 7215 | /* This is a bit complicated. There are 8 registers on |
| 7216 | * the controller which we write to to tell it 8 different |
| 7217 | * sizes of commands which there may be. It's a way of |
| 7218 | * reducing the DMA done to fetch each command. Encoded into |
| 7219 | * each command's tag are 3 bits which communicate to the controller |
| 7220 | * which of the eight sizes that command fits within. The size of |
| 7221 | * each command depends on how many scatter gather entries there are. |
| 7222 | * Each SG entry requires 16 bytes. The eight registers are programmed |
| 7223 | * with the number of 16-byte blocks a command of that size requires. |
| 7224 | * The smallest command possible requires 5 such 16 byte blocks. |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 7225 | * 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] | 7226 | * blocks. Note, this only extends to the SG entries contained |
| 7227 | * within the command block, and does not extend to chained blocks |
| 7228 | * of SG elements. bft[] contains the eight values we write to |
| 7229 | * the registers. They are not evenly distributed, but have more |
| 7230 | * sizes for small commands, and fewer sizes for larger commands. |
| 7231 | */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 7232 | 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] | 7233 | #define MIN_IOACCEL2_BFT_ENTRY 5 |
| 7234 | #define HPSA_IOACCEL2_HEADER_SZ 4 |
| 7235 | int bft2[16] = {MIN_IOACCEL2_BFT_ENTRY, 6, 7, 8, 9, 10, 11, 12, |
| 7236 | 13, 14, 15, 16, 17, 18, 19, |
| 7237 | HPSA_IOACCEL2_HEADER_SZ + IOACCEL2_MAXSGENTRIES}; |
| 7238 | BUILD_BUG_ON(ARRAY_SIZE(bft2) != 16); |
| 7239 | BUILD_BUG_ON(ARRAY_SIZE(bft) != 8); |
| 7240 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) > |
| 7241 | 16 * MIN_IOACCEL2_BFT_ENTRY); |
| 7242 | BUILD_BUG_ON(sizeof(struct ioaccel2_sg_element) != 16); |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 7243 | BUILD_BUG_ON(28 > SG_ENTRIES_IN_CMD + 4); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7244 | /* 5 = 1 s/g entry or 4k |
| 7245 | * 6 = 2 s/g entry or 8k |
| 7246 | * 8 = 4 s/g entry or 16k |
| 7247 | * 10 = 6 s/g entry or 24k |
| 7248 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7249 | |
Stephen M. Cameron | b3a52e7 | 2014-05-29 10:53:23 -0500 | [diff] [blame] | 7250 | /* If the controller supports either ioaccel method then |
| 7251 | * we can also use the RAID stack submit path that does not |
| 7252 | * perform the superfluous readl() after each command submission. |
| 7253 | */ |
| 7254 | if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2)) |
| 7255 | access = SA5_performant_access_no_read; |
| 7256 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7257 | /* Controller spec: zero out this buffer. */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7258 | for (i = 0; i < h->nreply_queues; i++) |
| 7259 | memset(h->reply_queue[i].head, 0, h->reply_queue_size); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7260 | |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 7261 | bft[7] = SG_ENTRIES_IN_CMD + 4; |
| 7262 | calc_bucket_map(bft, ARRAY_SIZE(bft), |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7263 | SG_ENTRIES_IN_CMD, 4, h->blockFetchTable); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7264 | for (i = 0; i < 8; i++) |
| 7265 | writel(bft[i], &h->transtable->BlockFetch[i]); |
| 7266 | |
| 7267 | /* size of controller ring buffer */ |
| 7268 | writel(h->max_commands, &h->transtable->RepQSize); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7269 | writel(h->nreply_queues, &h->transtable->RepQCount); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7270 | writel(0, &h->transtable->RepQCtrAddrLow32); |
| 7271 | writel(0, &h->transtable->RepQCtrAddrHigh32); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7272 | |
| 7273 | for (i = 0; i < h->nreply_queues; i++) { |
| 7274 | writel(0, &h->transtable->RepQAddr[i].upper); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7275 | writel(h->reply_queue[i].busaddr, |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7276 | &h->transtable->RepQAddr[i].lower); |
| 7277 | } |
| 7278 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7279 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7280 | writel(transMethod, &(h->cfgtable->HostWrite.TransportRequest)); |
| 7281 | /* |
| 7282 | * enable outbound interrupt coalescing in accelerator mode; |
| 7283 | */ |
| 7284 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 7285 | access = SA5_ioaccel_mode1_access; |
| 7286 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 7287 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 7288 | } else { |
| 7289 | if (trans_support & CFGTBL_Trans_io_accel2) { |
| 7290 | access = SA5_ioaccel_mode2_access; |
| 7291 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 7292 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
| 7293 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7294 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7295 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7296 | if (hpsa_wait_for_mode_change_ack(h)) { |
| 7297 | dev_err(&h->pdev->dev, |
| 7298 | "performant mode problem - doorbell timeout\n"); |
| 7299 | return -ENODEV; |
| 7300 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7301 | register_value = readl(&(h->cfgtable->TransportActive)); |
| 7302 | if (!(register_value & CFGTBL_Trans_Performant)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7303 | dev_err(&h->pdev->dev, |
| 7304 | "performant mode problem - transport not active\n"); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7305 | return -ENODEV; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7306 | } |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 7307 | /* Change the access methods to the performant access methods */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7308 | h->access = access; |
| 7309 | h->transMethod = transMethod; |
| 7310 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7311 | if (!((trans_support & CFGTBL_Trans_io_accel1) || |
| 7312 | (trans_support & CFGTBL_Trans_io_accel2))) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7313 | return 0; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7314 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7315 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 7316 | /* Set up I/O accelerator mode */ |
| 7317 | for (i = 0; i < h->nreply_queues; i++) { |
| 7318 | writel(i, h->vaddr + IOACCEL_MODE1_REPLY_QUEUE_INDEX); |
| 7319 | h->reply_queue[i].current_entry = |
| 7320 | readl(h->vaddr + IOACCEL_MODE1_PRODUCER_INDEX); |
| 7321 | } |
| 7322 | bft[7] = h->ioaccel_maxsg + 8; |
| 7323 | calc_bucket_map(bft, ARRAY_SIZE(bft), h->ioaccel_maxsg, 8, |
| 7324 | h->ioaccel1_blockFetchTable); |
| 7325 | |
| 7326 | /* initialize all reply queue entries to unused */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7327 | for (i = 0; i < h->nreply_queues; i++) |
| 7328 | memset(h->reply_queue[i].head, |
| 7329 | (u8) IOACCEL_MODE1_REPLY_UNUSED, |
| 7330 | h->reply_queue_size); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7331 | |
| 7332 | /* set all the constant fields in the accelerator command |
| 7333 | * frames once at init time to save CPU cycles later. |
| 7334 | */ |
| 7335 | for (i = 0; i < h->nr_cmds; i++) { |
| 7336 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[i]; |
| 7337 | |
| 7338 | cp->function = IOACCEL1_FUNCTION_SCSIIO; |
| 7339 | cp->err_info = (u32) (h->errinfo_pool_dhandle + |
| 7340 | (i * sizeof(struct ErrorInfo))); |
| 7341 | cp->err_info_len = sizeof(struct ErrorInfo); |
| 7342 | cp->sgl_offset = IOACCEL1_SGLOFFSET; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7343 | cp->host_context_flags = |
| 7344 | cpu_to_le16(IOACCEL1_HCFLAGS_CISS_FORMAT); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7345 | cp->timeout_sec = 0; |
| 7346 | cp->ReplyQueue = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 7347 | cp->tag = |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7348 | cpu_to_le64((i << DIRECT_LOOKUP_SHIFT)); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 7349 | cp->host_addr = |
| 7350 | cpu_to_le64(h->ioaccel_cmd_pool_dhandle + |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7351 | (i * sizeof(struct io_accel1_cmd))); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7352 | } |
| 7353 | } else if (trans_support & CFGTBL_Trans_io_accel2) { |
| 7354 | u64 cfg_offset, cfg_base_addr_index; |
| 7355 | u32 bft2_offset, cfg_base_addr; |
| 7356 | int rc; |
| 7357 | |
| 7358 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 7359 | &cfg_base_addr_index, &cfg_offset); |
| 7360 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) != 64); |
| 7361 | bft2[15] = h->ioaccel_maxsg + HPSA_IOACCEL2_HEADER_SZ; |
| 7362 | calc_bucket_map(bft2, ARRAY_SIZE(bft2), h->ioaccel_maxsg, |
| 7363 | 4, h->ioaccel2_blockFetchTable); |
| 7364 | bft2_offset = readl(&h->cfgtable->io_accel_request_size_offset); |
| 7365 | BUILD_BUG_ON(offsetof(struct CfgTable, |
| 7366 | io_accel_request_size_offset) != 0xb8); |
| 7367 | h->ioaccel2_bft2_regs = |
| 7368 | remap_pci_mem(pci_resource_start(h->pdev, |
| 7369 | cfg_base_addr_index) + |
| 7370 | cfg_offset + bft2_offset, |
| 7371 | ARRAY_SIZE(bft2) * |
| 7372 | sizeof(*h->ioaccel2_bft2_regs)); |
| 7373 | for (i = 0; i < ARRAY_SIZE(bft2); i++) |
| 7374 | writel(bft2[i], &h->ioaccel2_bft2_regs[i]); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7375 | } |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7376 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7377 | if (hpsa_wait_for_mode_change_ack(h)) { |
| 7378 | dev_err(&h->pdev->dev, |
| 7379 | "performant mode problem - enabling ioaccel mode\n"); |
| 7380 | return -ENODEV; |
| 7381 | } |
| 7382 | return 0; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | static int hpsa_alloc_ioaccel_cmd_and_bft(struct ctlr_info *h) |
| 7386 | { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7387 | h->ioaccel_maxsg = |
| 7388 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 7389 | if (h->ioaccel_maxsg > IOACCEL1_MAXSGENTRIES) |
| 7390 | h->ioaccel_maxsg = IOACCEL1_MAXSGENTRIES; |
| 7391 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7392 | /* Command structures must be aligned on a 128-byte boundary |
| 7393 | * because the 7 lower bits of the address are used by the |
| 7394 | * hardware. |
| 7395 | */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7396 | BUILD_BUG_ON(sizeof(struct io_accel1_cmd) % |
| 7397 | IOACCEL1_COMMANDLIST_ALIGNMENT); |
| 7398 | h->ioaccel_cmd_pool = |
| 7399 | pci_alloc_consistent(h->pdev, |
| 7400 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 7401 | &(h->ioaccel_cmd_pool_dhandle)); |
| 7402 | |
| 7403 | h->ioaccel1_blockFetchTable = |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7404 | kmalloc(((h->ioaccel_maxsg + 1) * |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7405 | sizeof(u32)), GFP_KERNEL); |
| 7406 | |
| 7407 | if ((h->ioaccel_cmd_pool == NULL) || |
| 7408 | (h->ioaccel1_blockFetchTable == NULL)) |
| 7409 | goto clean_up; |
| 7410 | |
| 7411 | memset(h->ioaccel_cmd_pool, 0, |
| 7412 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool)); |
| 7413 | return 0; |
| 7414 | |
| 7415 | clean_up: |
| 7416 | if (h->ioaccel_cmd_pool) |
| 7417 | pci_free_consistent(h->pdev, |
| 7418 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 7419 | h->ioaccel_cmd_pool, h->ioaccel_cmd_pool_dhandle); |
| 7420 | kfree(h->ioaccel1_blockFetchTable); |
| 7421 | return 1; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7422 | } |
| 7423 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 7424 | static int ioaccel2_alloc_cmds_and_bft(struct ctlr_info *h) |
| 7425 | { |
| 7426 | /* Allocate ioaccel2 mode command blocks and block fetch table */ |
| 7427 | |
| 7428 | h->ioaccel_maxsg = |
| 7429 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 7430 | if (h->ioaccel_maxsg > IOACCEL2_MAXSGENTRIES) |
| 7431 | h->ioaccel_maxsg = IOACCEL2_MAXSGENTRIES; |
| 7432 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 7433 | BUILD_BUG_ON(sizeof(struct io_accel2_cmd) % |
| 7434 | IOACCEL2_COMMANDLIST_ALIGNMENT); |
| 7435 | h->ioaccel2_cmd_pool = |
| 7436 | pci_alloc_consistent(h->pdev, |
| 7437 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 7438 | &(h->ioaccel2_cmd_pool_dhandle)); |
| 7439 | |
| 7440 | h->ioaccel2_blockFetchTable = |
| 7441 | kmalloc(((h->ioaccel_maxsg + 1) * |
| 7442 | sizeof(u32)), GFP_KERNEL); |
| 7443 | |
| 7444 | if ((h->ioaccel2_cmd_pool == NULL) || |
| 7445 | (h->ioaccel2_blockFetchTable == NULL)) |
| 7446 | goto clean_up; |
| 7447 | |
| 7448 | memset(h->ioaccel2_cmd_pool, 0, |
| 7449 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool)); |
| 7450 | return 0; |
| 7451 | |
| 7452 | clean_up: |
| 7453 | if (h->ioaccel2_cmd_pool) |
| 7454 | pci_free_consistent(h->pdev, |
| 7455 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 7456 | h->ioaccel2_cmd_pool, h->ioaccel2_cmd_pool_dhandle); |
| 7457 | kfree(h->ioaccel2_blockFetchTable); |
| 7458 | return 1; |
| 7459 | } |
| 7460 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7461 | 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] | 7462 | { |
| 7463 | u32 trans_support; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7464 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 7465 | CFGTBL_Trans_use_short_tags; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7466 | int i; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7467 | |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 7468 | if (hpsa_simple_mode) |
| 7469 | return; |
| 7470 | |
scameron@beardog.cce.hp.com | 67c99a7 | 2014-04-14 14:01:09 -0500 | [diff] [blame] | 7471 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 7472 | if (!(trans_support & PERFORMANT_MODE)) |
| 7473 | return; |
| 7474 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7475 | /* Check for I/O accelerator mode support */ |
| 7476 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 7477 | transMethod |= CFGTBL_Trans_io_accel1 | |
| 7478 | CFGTBL_Trans_enable_directed_msix; |
| 7479 | if (hpsa_alloc_ioaccel_cmd_and_bft(h)) |
| 7480 | goto clean_up; |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 7481 | } else { |
| 7482 | if (trans_support & CFGTBL_Trans_io_accel2) { |
| 7483 | transMethod |= CFGTBL_Trans_io_accel2 | |
| 7484 | CFGTBL_Trans_enable_directed_msix; |
| 7485 | if (ioaccel2_alloc_cmds_and_bft(h)) |
| 7486 | goto clean_up; |
| 7487 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7488 | } |
| 7489 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7490 | h->nreply_queues = h->msix_vector > 0 ? h->msix_vector : 1; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 7491 | hpsa_get_max_perf_mode_cmds(h); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7492 | /* Performant mode ring buffer and supporting data structures */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7493 | h->reply_queue_size = h->max_commands * sizeof(u64); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7494 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7495 | for (i = 0; i < h->nreply_queues; i++) { |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7496 | h->reply_queue[i].head = pci_alloc_consistent(h->pdev, |
| 7497 | h->reply_queue_size, |
| 7498 | &(h->reply_queue[i].busaddr)); |
| 7499 | if (!h->reply_queue[i].head) |
| 7500 | goto clean_up; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7501 | h->reply_queue[i].size = h->max_commands; |
| 7502 | h->reply_queue[i].wraparound = 1; /* spec: init to 1 */ |
| 7503 | h->reply_queue[i].current_entry = 0; |
| 7504 | } |
| 7505 | |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7506 | /* Need a block fetch table for performant mode */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 7507 | h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) * |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7508 | sizeof(u32)), GFP_KERNEL); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7509 | if (!h->blockFetchTable) |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 7510 | goto clean_up; |
| 7511 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7512 | hpsa_enter_performant_mode(h, trans_support); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7513 | return; |
| 7514 | |
| 7515 | clean_up: |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7516 | hpsa_free_reply_queues(h); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7517 | kfree(h->blockFetchTable); |
| 7518 | } |
| 7519 | |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7520 | static int is_accelerated_cmd(struct CommandList *c) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7521 | { |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7522 | return c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_IOACCEL2; |
| 7523 | } |
| 7524 | |
| 7525 | static void hpsa_drain_accel_commands(struct ctlr_info *h) |
| 7526 | { |
| 7527 | struct CommandList *c = NULL; |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7528 | int i, accel_cmds_out; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7529 | int refcount; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7530 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7531 | do { /* wait for all outstanding ioaccel commands to drain out */ |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7532 | accel_cmds_out = 0; |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7533 | for (i = 0; i < h->nr_cmds; i++) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7534 | c = h->cmd_pool + i; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7535 | refcount = atomic_inc_return(&c->refcount); |
| 7536 | if (refcount > 1) /* Command is allocated */ |
| 7537 | accel_cmds_out += is_accelerated_cmd(c); |
| 7538 | cmd_free(h, c); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7539 | } |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 7540 | if (accel_cmds_out <= 0) |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7541 | break; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7542 | msleep(100); |
| 7543 | } while (1); |
| 7544 | } |
| 7545 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7546 | /* |
| 7547 | * This is it. Register the PCI driver information for the cards we control |
| 7548 | * the OS will call our registered routines when it finds one of our cards. |
| 7549 | */ |
| 7550 | static int __init hpsa_init(void) |
| 7551 | { |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 7552 | return pci_register_driver(&hpsa_pci_driver); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | static void __exit hpsa_cleanup(void) |
| 7556 | { |
| 7557 | pci_unregister_driver(&hpsa_pci_driver); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7558 | } |
| 7559 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7560 | static void __attribute__((unused)) verify_offsets(void) |
| 7561 | { |
| 7562 | #define VERIFY_OFFSET(member, offset) \ |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 7563 | BUILD_BUG_ON(offsetof(struct raid_map_data, member) != offset) |
| 7564 | |
| 7565 | VERIFY_OFFSET(structure_size, 0); |
| 7566 | VERIFY_OFFSET(volume_blk_size, 4); |
| 7567 | VERIFY_OFFSET(volume_blk_cnt, 8); |
| 7568 | VERIFY_OFFSET(phys_blk_shift, 16); |
| 7569 | VERIFY_OFFSET(parity_rotation_shift, 17); |
| 7570 | VERIFY_OFFSET(strip_size, 18); |
| 7571 | VERIFY_OFFSET(disk_starting_blk, 20); |
| 7572 | VERIFY_OFFSET(disk_blk_cnt, 28); |
| 7573 | VERIFY_OFFSET(data_disks_per_row, 36); |
| 7574 | VERIFY_OFFSET(metadata_disks_per_row, 38); |
| 7575 | VERIFY_OFFSET(row_cnt, 40); |
| 7576 | VERIFY_OFFSET(layout_map_count, 42); |
| 7577 | VERIFY_OFFSET(flags, 44); |
| 7578 | VERIFY_OFFSET(dekindex, 46); |
| 7579 | /* VERIFY_OFFSET(reserved, 48 */ |
| 7580 | VERIFY_OFFSET(data, 64); |
| 7581 | |
| 7582 | #undef VERIFY_OFFSET |
| 7583 | |
| 7584 | #define VERIFY_OFFSET(member, offset) \ |
Mike Miller | b66cc25 | 2014-02-18 13:56:04 -0600 | [diff] [blame] | 7585 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, member) != offset) |
| 7586 | |
| 7587 | VERIFY_OFFSET(IU_type, 0); |
| 7588 | VERIFY_OFFSET(direction, 1); |
| 7589 | VERIFY_OFFSET(reply_queue, 2); |
| 7590 | /* VERIFY_OFFSET(reserved1, 3); */ |
| 7591 | VERIFY_OFFSET(scsi_nexus, 4); |
| 7592 | VERIFY_OFFSET(Tag, 8); |
| 7593 | VERIFY_OFFSET(cdb, 16); |
| 7594 | VERIFY_OFFSET(cciss_lun, 32); |
| 7595 | VERIFY_OFFSET(data_len, 40); |
| 7596 | VERIFY_OFFSET(cmd_priority_task_attr, 44); |
| 7597 | VERIFY_OFFSET(sg_count, 45); |
| 7598 | /* VERIFY_OFFSET(reserved3 */ |
| 7599 | VERIFY_OFFSET(err_ptr, 48); |
| 7600 | VERIFY_OFFSET(err_len, 56); |
| 7601 | /* VERIFY_OFFSET(reserved4 */ |
| 7602 | VERIFY_OFFSET(sg, 64); |
| 7603 | |
| 7604 | #undef VERIFY_OFFSET |
| 7605 | |
| 7606 | #define VERIFY_OFFSET(member, offset) \ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7607 | BUILD_BUG_ON(offsetof(struct io_accel1_cmd, member) != offset) |
| 7608 | |
| 7609 | VERIFY_OFFSET(dev_handle, 0x00); |
| 7610 | VERIFY_OFFSET(reserved1, 0x02); |
| 7611 | VERIFY_OFFSET(function, 0x03); |
| 7612 | VERIFY_OFFSET(reserved2, 0x04); |
| 7613 | VERIFY_OFFSET(err_info, 0x0C); |
| 7614 | VERIFY_OFFSET(reserved3, 0x10); |
| 7615 | VERIFY_OFFSET(err_info_len, 0x12); |
| 7616 | VERIFY_OFFSET(reserved4, 0x13); |
| 7617 | VERIFY_OFFSET(sgl_offset, 0x14); |
| 7618 | VERIFY_OFFSET(reserved5, 0x15); |
| 7619 | VERIFY_OFFSET(transfer_len, 0x1C); |
| 7620 | VERIFY_OFFSET(reserved6, 0x20); |
| 7621 | VERIFY_OFFSET(io_flags, 0x24); |
| 7622 | VERIFY_OFFSET(reserved7, 0x26); |
| 7623 | VERIFY_OFFSET(LUN, 0x34); |
| 7624 | VERIFY_OFFSET(control, 0x3C); |
| 7625 | VERIFY_OFFSET(CDB, 0x40); |
| 7626 | VERIFY_OFFSET(reserved8, 0x50); |
| 7627 | VERIFY_OFFSET(host_context_flags, 0x60); |
| 7628 | VERIFY_OFFSET(timeout_sec, 0x62); |
| 7629 | VERIFY_OFFSET(ReplyQueue, 0x64); |
| 7630 | VERIFY_OFFSET(reserved9, 0x65); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 7631 | VERIFY_OFFSET(tag, 0x68); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 7632 | VERIFY_OFFSET(host_addr, 0x70); |
| 7633 | VERIFY_OFFSET(CISS_LUN, 0x78); |
| 7634 | VERIFY_OFFSET(SG, 0x78 + 8); |
| 7635 | #undef VERIFY_OFFSET |
| 7636 | } |
| 7637 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7638 | module_init(hpsa_init); |
| 7639 | module_exit(hpsa_cleanup); |