Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Disk Array driver for HP Smart Array SAS controllers |
Don Brace | 1358f6d | 2015-07-18 11:12:38 -0500 | [diff] [blame] | 3 | * Copyright 2014-2015 PMC-Sierra, Inc. |
| 4 | * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 13 | * NON INFRINGEMENT. See the GNU General Public License for more details. |
| 14 | * |
Don Brace | 1358f6d | 2015-07-18 11:12:38 -0500 | [diff] [blame] | 15 | * Questions/Comments/Bugfixes to storagedev@pmcs.com |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/pci.h> |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 23 | #include <linux/pci-aspm.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/fs.h> |
| 28 | #include <linux/timer.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 29 | #include <linux/init.h> |
| 30 | #include <linux/spinlock.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 31 | #include <linux/compat.h> |
| 32 | #include <linux/blktrace_api.h> |
| 33 | #include <linux/uaccess.h> |
| 34 | #include <linux/io.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/completion.h> |
| 37 | #include <linux/moduleparam.h> |
| 38 | #include <scsi/scsi.h> |
| 39 | #include <scsi/scsi_cmnd.h> |
| 40 | #include <scsi/scsi_device.h> |
| 41 | #include <scsi/scsi_host.h> |
Stephen M. Cameron | 667e23d | 2010-02-25 14:02:51 -0600 | [diff] [blame] | 42 | #include <scsi/scsi_tcq.h> |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 43 | #include <scsi/scsi_eh.h> |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 44 | #include <scsi/scsi_dbg.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 45 | #include <linux/cciss_ioctl.h> |
| 46 | #include <linux/string.h> |
| 47 | #include <linux/bitmap.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 48 | #include <linux/atomic.h> |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 49 | #include <linux/jiffies.h> |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 50 | #include <linux/percpu-defs.h> |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 51 | #include <linux/percpu.h> |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 52 | #include <asm/unaligned.h> |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 53 | #include <asm/div64.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 54 | #include "hpsa_cmd.h" |
| 55 | #include "hpsa.h" |
| 56 | |
| 57 | /* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */ |
Don Brace | f532a3f | 2015-04-23 09:35:33 -0500 | [diff] [blame] | 58 | #define HPSA_DRIVER_VERSION "3.4.10-0" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 59 | #define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 60 | #define HPSA "hpsa" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 61 | |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 62 | /* How long to wait for CISS doorbell communication */ |
| 63 | #define CLEAR_EVENT_WAIT_INTERVAL 20 /* ms for each msleep() call */ |
| 64 | #define MODE_CHANGE_WAIT_INTERVAL 10 /* ms for each msleep() call */ |
| 65 | #define MAX_CLEAR_EVENT_WAIT 30000 /* times 20 ms = 600 s */ |
| 66 | #define MAX_MODE_CHANGE_WAIT 2000 /* times 10 ms = 20 s */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 67 | #define MAX_IOCTL_CONFIG_WAIT 1000 |
| 68 | |
| 69 | /*define how many times we will try a command because of bus resets */ |
| 70 | #define MAX_CMD_RETRIES 3 |
| 71 | |
| 72 | /* Embedded module documentation macros - see modules.h */ |
| 73 | MODULE_AUTHOR("Hewlett-Packard Company"); |
| 74 | MODULE_DESCRIPTION("Driver for HP Smart Array Controller version " \ |
| 75 | HPSA_DRIVER_VERSION); |
| 76 | MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers"); |
| 77 | MODULE_VERSION(HPSA_DRIVER_VERSION); |
| 78 | MODULE_LICENSE("GPL"); |
| 79 | |
| 80 | static int hpsa_allow_any; |
| 81 | module_param(hpsa_allow_any, int, S_IRUGO|S_IWUSR); |
| 82 | MODULE_PARM_DESC(hpsa_allow_any, |
| 83 | "Allow hpsa driver to access unknown HP Smart Array hardware"); |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 84 | static int hpsa_simple_mode; |
| 85 | module_param(hpsa_simple_mode, int, S_IRUGO|S_IWUSR); |
| 86 | MODULE_PARM_DESC(hpsa_simple_mode, |
| 87 | "Use 'simple mode' rather than 'performant mode'"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 88 | |
| 89 | /* define the PCI info for the cards we can control */ |
| 90 | static const struct pci_device_id hpsa_pci_device_id[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 91 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3241}, |
| 92 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3243}, |
| 93 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3245}, |
| 94 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3247}, |
| 95 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 96 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A}, |
| 97 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B}, |
Mike Miller | f8b01eb | 2010-02-04 08:42:45 -0600 | [diff] [blame] | 98 | {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] | 99 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3350}, |
| 100 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3351}, |
| 101 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3352}, |
| 102 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3353}, |
| 103 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3354}, |
| 104 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3355}, |
| 105 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3356}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 106 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1921}, |
| 107 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1922}, |
| 108 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1923}, |
| 109 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1924}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 110 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1926}, |
| 111 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1928}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 112 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1929}, |
| 113 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BD}, |
| 114 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BE}, |
| 115 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BF}, |
| 116 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C0}, |
| 117 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C1}, |
| 118 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C2}, |
| 119 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C3}, |
| 120 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C4}, |
| 121 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C5}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 122 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C6}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 123 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C7}, |
| 124 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C8}, |
| 125 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C9}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 126 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CA}, |
| 127 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CB}, |
| 128 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CC}, |
| 129 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CD}, |
| 130 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CE}, |
Don Brace | fdfa4b6 | 2015-04-23 09:35:27 -0500 | [diff] [blame] | 131 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0580}, |
Don Brace | cbb47dc | 2015-07-18 11:12:54 -0500 | [diff] [blame] | 132 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0581}, |
| 133 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0582}, |
| 134 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0583}, |
| 135 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0584}, |
| 136 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0585}, |
Stephen M. Cameron | 8e616a5 | 2014-02-18 13:58:02 -0600 | [diff] [blame] | 137 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0076}, |
| 138 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0087}, |
| 139 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x007D}, |
| 140 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0088}, |
| 141 | {PCI_VENDOR_ID_HP, 0x333f, 0x103c, 0x333f}, |
Mike Miller | 7c03b87 | 2010-12-01 11:16:07 -0600 | [diff] [blame] | 142 | {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] | 143 | PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 144 | {0,} |
| 145 | }; |
| 146 | |
| 147 | MODULE_DEVICE_TABLE(pci, hpsa_pci_device_id); |
| 148 | |
| 149 | /* board_id = Subsystem Device ID & Vendor ID |
| 150 | * product = Marketing Name for the board |
| 151 | * access = Address of the struct of function pointers |
| 152 | */ |
| 153 | static struct board_type products[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 154 | {0x3241103C, "Smart Array P212", &SA5_access}, |
| 155 | {0x3243103C, "Smart Array P410", &SA5_access}, |
| 156 | {0x3245103C, "Smart Array P410i", &SA5_access}, |
| 157 | {0x3247103C, "Smart Array P411", &SA5_access}, |
| 158 | {0x3249103C, "Smart Array P812", &SA5_access}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 159 | {0x324A103C, "Smart Array P712m", &SA5_access}, |
| 160 | {0x324B103C, "Smart Array P711m", &SA5_access}, |
Stephen M. Cameron | 7d2cce5 | 2014-11-14 17:26:38 -0600 | [diff] [blame] | 161 | {0x3233103C, "HP StorageWorks 1210m", &SA5_access}, /* alias of 333f */ |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 162 | {0x3350103C, "Smart Array P222", &SA5_access}, |
| 163 | {0x3351103C, "Smart Array P420", &SA5_access}, |
| 164 | {0x3352103C, "Smart Array P421", &SA5_access}, |
| 165 | {0x3353103C, "Smart Array P822", &SA5_access}, |
| 166 | {0x3354103C, "Smart Array P420i", &SA5_access}, |
| 167 | {0x3355103C, "Smart Array P220i", &SA5_access}, |
| 168 | {0x3356103C, "Smart Array P721m", &SA5_access}, |
Mike Miller | 1fd6c8e | 2013-09-04 15:08:29 -0500 | [diff] [blame] | 169 | {0x1921103C, "Smart Array P830i", &SA5_access}, |
| 170 | {0x1922103C, "Smart Array P430", &SA5_access}, |
| 171 | {0x1923103C, "Smart Array P431", &SA5_access}, |
| 172 | {0x1924103C, "Smart Array P830", &SA5_access}, |
| 173 | {0x1926103C, "Smart Array P731m", &SA5_access}, |
| 174 | {0x1928103C, "Smart Array P230i", &SA5_access}, |
| 175 | {0x1929103C, "Smart Array P530", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 176 | {0x21BD103C, "Smart Array P244br", &SA5_access}, |
| 177 | {0x21BE103C, "Smart Array P741m", &SA5_access}, |
| 178 | {0x21BF103C, "Smart HBA H240ar", &SA5_access}, |
| 179 | {0x21C0103C, "Smart Array P440ar", &SA5_access}, |
Don Brace | c8ae0ab | 2015-01-23 16:45:12 -0600 | [diff] [blame] | 180 | {0x21C1103C, "Smart Array P840ar", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 181 | {0x21C2103C, "Smart Array P440", &SA5_access}, |
| 182 | {0x21C3103C, "Smart Array P441", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 183 | {0x21C4103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 184 | {0x21C5103C, "Smart Array P841", &SA5_access}, |
| 185 | {0x21C6103C, "Smart HBA H244br", &SA5_access}, |
| 186 | {0x21C7103C, "Smart HBA H240", &SA5_access}, |
| 187 | {0x21C8103C, "Smart HBA H241", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 188 | {0x21C9103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 189 | {0x21CA103C, "Smart Array P246br", &SA5_access}, |
| 190 | {0x21CB103C, "Smart Array P840", &SA5_access}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 191 | {0x21CC103C, "Smart Array", &SA5_access}, |
| 192 | {0x21CD103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 193 | {0x21CE103C, "Smart HBA", &SA5_access}, |
Don Brace | fdfa4b6 | 2015-04-23 09:35:27 -0500 | [diff] [blame] | 194 | {0x05809005, "SmartHBA-SA", &SA5_access}, |
Don Brace | cbb47dc | 2015-07-18 11:12:54 -0500 | [diff] [blame] | 195 | {0x05819005, "SmartHBA-SA 8i", &SA5_access}, |
| 196 | {0x05829005, "SmartHBA-SA 8i8e", &SA5_access}, |
| 197 | {0x05839005, "SmartHBA-SA 8e", &SA5_access}, |
| 198 | {0x05849005, "SmartHBA-SA 16i", &SA5_access}, |
| 199 | {0x05859005, "SmartHBA-SA 4i4e", &SA5_access}, |
Stephen M. Cameron | 8e616a5 | 2014-02-18 13:58:02 -0600 | [diff] [blame] | 200 | {0x00761590, "HP Storage P1224 Array Controller", &SA5_access}, |
| 201 | {0x00871590, "HP Storage P1224e Array Controller", &SA5_access}, |
| 202 | {0x007D1590, "HP Storage P1228 Array Controller", &SA5_access}, |
| 203 | {0x00881590, "HP Storage P1228e Array Controller", &SA5_access}, |
| 204 | {0x333f103c, "HP StorageWorks 1210m Array Controller", &SA5_access}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 205 | {0xFFFF103C, "Unknown Smart Array", &SA5_access}, |
| 206 | }; |
| 207 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 208 | #define SCSI_CMD_BUSY ((struct scsi_cmnd *)&hpsa_cmd_busy) |
| 209 | static const struct scsi_cmnd hpsa_cmd_busy; |
| 210 | #define SCSI_CMD_IDLE ((struct scsi_cmnd *)&hpsa_cmd_idle) |
| 211 | static const struct scsi_cmnd hpsa_cmd_idle; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 212 | static int number_of_controllers; |
| 213 | |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 214 | static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); |
| 215 | static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 216 | 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] | 217 | |
| 218 | #ifdef CONFIG_COMPAT |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 219 | static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, |
| 220 | void __user *arg); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 221 | #endif |
| 222 | |
| 223 | static void cmd_free(struct ctlr_info *h, struct CommandList *c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 224 | static struct CommandList *cmd_alloc(struct ctlr_info *h); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 225 | static void cmd_tagged_free(struct ctlr_info *h, struct CommandList *c); |
| 226 | static struct CommandList *cmd_tagged_alloc(struct ctlr_info *h, |
| 227 | struct scsi_cmnd *scmd); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 228 | 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] | 229 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 230 | int cmd_type); |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 231 | static void hpsa_free_cmd_pool(struct ctlr_info *h); |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 232 | #define VPD_PAGE (1 << 8) |
Don Brace | b48d980 | 2015-11-04 15:50:13 -0600 | [diff] [blame] | 233 | #define HPSA_SIMPLE_ERROR_BITS 0x03 |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 234 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 235 | static int hpsa_scsi_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 236 | static void hpsa_scan_start(struct Scsi_Host *); |
| 237 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 238 | unsigned long elapsed_time); |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 239 | 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] | 240 | |
| 241 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 242 | static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 243 | static int hpsa_slave_alloc(struct scsi_device *sdev); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 244 | static int hpsa_slave_configure(struct scsi_device *sdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 245 | static void hpsa_slave_destroy(struct scsi_device *sdev); |
| 246 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 247 | static void hpsa_update_scsi_devices(struct ctlr_info *h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 248 | static int check_for_unit_attention(struct ctlr_info *h, |
| 249 | struct CommandList *c); |
| 250 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 251 | struct CommandList *c); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 252 | /* performant mode helper functions */ |
| 253 | static void calc_bucket_map(int *bucket, int num_buckets, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 254 | int nsgs, int min_blocks, u32 *bucket_map); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 255 | static void hpsa_free_performant_mode(struct ctlr_info *h); |
| 256 | static int hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 257 | static inline u32 next_command(struct ctlr_info *h, u8 q); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 258 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 259 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 260 | u64 *cfg_offset); |
| 261 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 262 | unsigned long *memory_bar); |
| 263 | static int hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id); |
| 264 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 265 | int wait_for_ready); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 266 | static inline void finish_cmd(struct CommandList *c); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 267 | 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] | 268 | #define BOARD_NOT_READY 0 |
| 269 | #define BOARD_READY 1 |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 270 | static void hpsa_drain_accel_commands(struct ctlr_info *h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 271 | static void hpsa_flush_cache(struct ctlr_info *h); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 272 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 273 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 274 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 275 | static void hpsa_command_resubmit_worker(struct work_struct *work); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 276 | static u32 lockup_detected(struct ctlr_info *h); |
| 277 | static int detect_controller_lockup(struct ctlr_info *h); |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 278 | static void hpsa_disable_rld_caching(struct ctlr_info *h); |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 279 | static int hpsa_luns_changed(struct ctlr_info *h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 280 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 281 | static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev) |
| 282 | { |
| 283 | unsigned long *priv = shost_priv(sdev->host); |
| 284 | return (struct ctlr_info *) *priv; |
| 285 | } |
| 286 | |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 287 | static inline struct ctlr_info *shost_to_hba(struct Scsi_Host *sh) |
| 288 | { |
| 289 | unsigned long *priv = shost_priv(sh); |
| 290 | return (struct ctlr_info *) *priv; |
| 291 | } |
| 292 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 293 | static inline bool hpsa_is_cmd_idle(struct CommandList *c) |
| 294 | { |
| 295 | return c->scsi_cmd == SCSI_CMD_IDLE; |
| 296 | } |
| 297 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 298 | static inline bool hpsa_is_pending_event(struct CommandList *c) |
| 299 | { |
| 300 | return c->abort_pending || c->reset_pending; |
| 301 | } |
| 302 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 303 | /* extract sense key, asc, and ascq from sense data. -1 means invalid. */ |
| 304 | static void decode_sense_data(const u8 *sense_data, int sense_data_len, |
| 305 | u8 *sense_key, u8 *asc, u8 *ascq) |
| 306 | { |
| 307 | struct scsi_sense_hdr sshdr; |
| 308 | bool rc; |
| 309 | |
| 310 | *sense_key = -1; |
| 311 | *asc = -1; |
| 312 | *ascq = -1; |
| 313 | |
| 314 | if (sense_data_len < 1) |
| 315 | return; |
| 316 | |
| 317 | rc = scsi_normalize_sense(sense_data, sense_data_len, &sshdr); |
| 318 | if (rc) { |
| 319 | *sense_key = sshdr.sense_key; |
| 320 | *asc = sshdr.asc; |
| 321 | *ascq = sshdr.ascq; |
| 322 | } |
| 323 | } |
| 324 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 325 | static int check_for_unit_attention(struct ctlr_info *h, |
| 326 | struct CommandList *c) |
| 327 | { |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 328 | u8 sense_key, asc, ascq; |
| 329 | int sense_len; |
| 330 | |
| 331 | if (c->err_info->SenseLen > sizeof(c->err_info->SenseInfo)) |
| 332 | sense_len = sizeof(c->err_info->SenseInfo); |
| 333 | else |
| 334 | sense_len = c->err_info->SenseLen; |
| 335 | |
| 336 | decode_sense_data(c->err_info->SenseInfo, sense_len, |
| 337 | &sense_key, &asc, &ascq); |
Don Brace | 81c2755 | 2015-07-18 11:12:28 -0500 | [diff] [blame] | 338 | if (sense_key != UNIT_ATTENTION || asc == 0xff) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 339 | return 0; |
| 340 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 341 | switch (asc) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 342 | case STATE_CHANGED: |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 343 | dev_warn(&h->pdev->dev, |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 344 | "%s: a state change detected, command retried\n", |
| 345 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 346 | break; |
| 347 | case LUN_FAILED: |
Stephen M. Cameron | 7f73695 | 2014-11-14 17:26:48 -0600 | [diff] [blame] | 348 | dev_warn(&h->pdev->dev, |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 349 | "%s: LUN failure detected\n", h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 350 | break; |
| 351 | case REPORT_LUNS_CHANGED: |
Stephen M. Cameron | 7f73695 | 2014-11-14 17:26:48 -0600 | [diff] [blame] | 352 | dev_warn(&h->pdev->dev, |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 353 | "%s: report LUN data changed\n", h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 354 | /* |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 355 | * Note: this REPORT_LUNS_CHANGED condition only occurs on the external |
| 356 | * target (array) devices. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 357 | */ |
| 358 | break; |
| 359 | case POWER_OR_RESET: |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 360 | dev_warn(&h->pdev->dev, |
| 361 | "%s: a power on or device reset detected\n", |
| 362 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 363 | break; |
| 364 | case UNIT_ATTENTION_CLEARED: |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 365 | dev_warn(&h->pdev->dev, |
| 366 | "%s: unit attention cleared by another initiator\n", |
| 367 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 368 | break; |
| 369 | default: |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 370 | dev_warn(&h->pdev->dev, |
| 371 | "%s: unknown unit attention detected\n", |
| 372 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 373 | break; |
| 374 | } |
| 375 | return 1; |
| 376 | } |
| 377 | |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 378 | static int check_for_busy(struct ctlr_info *h, struct CommandList *c) |
| 379 | { |
| 380 | if (c->err_info->CommandStatus != CMD_TARGET_STATUS || |
| 381 | (c->err_info->ScsiStatus != SAM_STAT_BUSY && |
| 382 | c->err_info->ScsiStatus != SAM_STAT_TASK_SET_FULL)) |
| 383 | return 0; |
| 384 | dev_warn(&h->pdev->dev, HPSA "device busy"); |
| 385 | return 1; |
| 386 | } |
| 387 | |
Stephen Cameron | e985c58 | 2015-04-23 09:32:22 -0500 | [diff] [blame] | 388 | static u32 lockup_detected(struct ctlr_info *h); |
| 389 | static ssize_t host_show_lockup_detected(struct device *dev, |
| 390 | struct device_attribute *attr, char *buf) |
| 391 | { |
| 392 | int ld; |
| 393 | struct ctlr_info *h; |
| 394 | struct Scsi_Host *shost = class_to_shost(dev); |
| 395 | |
| 396 | h = shost_to_hba(shost); |
| 397 | ld = lockup_detected(h); |
| 398 | |
| 399 | return sprintf(buf, "ld=%d\n", ld); |
| 400 | } |
| 401 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 402 | static ssize_t host_store_hp_ssd_smart_path_status(struct device *dev, |
| 403 | struct device_attribute *attr, |
| 404 | const char *buf, size_t count) |
| 405 | { |
| 406 | int status, len; |
| 407 | struct ctlr_info *h; |
| 408 | struct Scsi_Host *shost = class_to_shost(dev); |
| 409 | char tmpbuf[10]; |
| 410 | |
| 411 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 412 | return -EACCES; |
| 413 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 414 | strncpy(tmpbuf, buf, len); |
| 415 | tmpbuf[len] = '\0'; |
| 416 | if (sscanf(tmpbuf, "%d", &status) != 1) |
| 417 | return -EINVAL; |
| 418 | h = shost_to_hba(shost); |
| 419 | h->acciopath_status = !!status; |
| 420 | dev_warn(&h->pdev->dev, |
| 421 | "hpsa: HP SSD Smart Path %s via sysfs update.\n", |
| 422 | h->acciopath_status ? "enabled" : "disabled"); |
| 423 | return count; |
| 424 | } |
| 425 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 426 | static ssize_t host_store_raid_offload_debug(struct device *dev, |
| 427 | struct device_attribute *attr, |
| 428 | const char *buf, size_t count) |
| 429 | { |
| 430 | int debug_level, len; |
| 431 | struct ctlr_info *h; |
| 432 | struct Scsi_Host *shost = class_to_shost(dev); |
| 433 | char tmpbuf[10]; |
| 434 | |
| 435 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 436 | return -EACCES; |
| 437 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 438 | strncpy(tmpbuf, buf, len); |
| 439 | tmpbuf[len] = '\0'; |
| 440 | if (sscanf(tmpbuf, "%d", &debug_level) != 1) |
| 441 | return -EINVAL; |
| 442 | if (debug_level < 0) |
| 443 | debug_level = 0; |
| 444 | h = shost_to_hba(shost); |
| 445 | h->raid_offload_debug = debug_level; |
| 446 | dev_warn(&h->pdev->dev, "hpsa: Set raid_offload_debug level = %d\n", |
| 447 | h->raid_offload_debug); |
| 448 | return count; |
| 449 | } |
| 450 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 451 | static ssize_t host_store_rescan(struct device *dev, |
| 452 | struct device_attribute *attr, |
| 453 | const char *buf, size_t count) |
| 454 | { |
| 455 | struct ctlr_info *h; |
| 456 | struct Scsi_Host *shost = class_to_shost(dev); |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 457 | h = shost_to_hba(shost); |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 458 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 459 | return count; |
| 460 | } |
| 461 | |
Stephen M. Cameron | d28ce02 | 2010-05-27 15:14:34 -0500 | [diff] [blame] | 462 | static ssize_t host_show_firmware_revision(struct device *dev, |
| 463 | struct device_attribute *attr, char *buf) |
| 464 | { |
| 465 | struct ctlr_info *h; |
| 466 | struct Scsi_Host *shost = class_to_shost(dev); |
| 467 | unsigned char *fwrev; |
| 468 | |
| 469 | h = shost_to_hba(shost); |
| 470 | if (!h->hba_inquiry_data) |
| 471 | return 0; |
| 472 | fwrev = &h->hba_inquiry_data[32]; |
| 473 | return snprintf(buf, 20, "%c%c%c%c\n", |
| 474 | fwrev[0], fwrev[1], fwrev[2], fwrev[3]); |
| 475 | } |
| 476 | |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 477 | static ssize_t host_show_commands_outstanding(struct device *dev, |
| 478 | struct device_attribute *attr, char *buf) |
| 479 | { |
| 480 | struct Scsi_Host *shost = class_to_shost(dev); |
| 481 | struct ctlr_info *h = shost_to_hba(shost); |
| 482 | |
Stephen M. Cameron | 0cbf768 | 2014-11-14 17:27:09 -0600 | [diff] [blame] | 483 | return snprintf(buf, 20, "%d\n", |
| 484 | atomic_read(&h->commands_outstanding)); |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 485 | } |
| 486 | |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 487 | static ssize_t host_show_transport_mode(struct device *dev, |
| 488 | struct device_attribute *attr, char *buf) |
| 489 | { |
| 490 | struct ctlr_info *h; |
| 491 | struct Scsi_Host *shost = class_to_shost(dev); |
| 492 | |
| 493 | h = shost_to_hba(shost); |
| 494 | return snprintf(buf, 20, "%s\n", |
Stephen M. Cameron | 960a30e7 | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 495 | h->transMethod & CFGTBL_Trans_Performant ? |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 496 | "performant" : "simple"); |
| 497 | } |
| 498 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 499 | static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev, |
| 500 | struct device_attribute *attr, char *buf) |
| 501 | { |
| 502 | struct ctlr_info *h; |
| 503 | struct Scsi_Host *shost = class_to_shost(dev); |
| 504 | |
| 505 | h = shost_to_hba(shost); |
| 506 | return snprintf(buf, 30, "HP SSD Smart Path %s\n", |
| 507 | (h->acciopath_status == 1) ? "enabled" : "disabled"); |
| 508 | } |
| 509 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 510 | /* 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] | 511 | static u32 unresettable_controller[] = { |
| 512 | 0x324a103C, /* Smart Array P712m */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 513 | 0x324b103C, /* Smart Array P711m */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 514 | 0x3223103C, /* Smart Array P800 */ |
| 515 | 0x3234103C, /* Smart Array P400 */ |
| 516 | 0x3235103C, /* Smart Array P400i */ |
| 517 | 0x3211103C, /* Smart Array E200i */ |
| 518 | 0x3212103C, /* Smart Array E200 */ |
| 519 | 0x3213103C, /* Smart Array E200i */ |
| 520 | 0x3214103C, /* Smart Array E200i */ |
| 521 | 0x3215103C, /* Smart Array E200i */ |
| 522 | 0x3237103C, /* Smart Array E500 */ |
| 523 | 0x323D103C, /* Smart Array P700m */ |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 524 | 0x40800E11, /* Smart Array 5i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 525 | 0x409C0E11, /* Smart Array 6400 */ |
| 526 | 0x409D0E11, /* Smart Array 6400 EM */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 527 | 0x40700E11, /* Smart Array 5300 */ |
| 528 | 0x40820E11, /* Smart Array 532 */ |
| 529 | 0x40830E11, /* Smart Array 5312 */ |
| 530 | 0x409A0E11, /* Smart Array 641 */ |
| 531 | 0x409B0E11, /* Smart Array 642 */ |
| 532 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 533 | }; |
| 534 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 535 | /* List of controllers which cannot even be soft reset */ |
| 536 | static u32 soft_unresettable_controller[] = { |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 537 | 0x40800E11, /* Smart Array 5i */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 538 | 0x40700E11, /* Smart Array 5300 */ |
| 539 | 0x40820E11, /* Smart Array 532 */ |
| 540 | 0x40830E11, /* Smart Array 5312 */ |
| 541 | 0x409A0E11, /* Smart Array 641 */ |
| 542 | 0x409B0E11, /* Smart Array 642 */ |
| 543 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 544 | /* Exclude 640x boards. These are two pci devices in one slot |
| 545 | * which share a battery backed cache module. One controls the |
| 546 | * cache, the other accesses the cache through the one that controls |
| 547 | * it. If we reset the one controlling the cache, the other will |
| 548 | * likely not be happy. Just forbid resetting this conjoined mess. |
| 549 | * The 640x isn't really supported by hpsa anyway. |
| 550 | */ |
| 551 | 0x409C0E11, /* Smart Array 6400 */ |
| 552 | 0x409D0E11, /* Smart Array 6400 EM */ |
| 553 | }; |
| 554 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 555 | static u32 needs_abort_tags_swizzled[] = { |
| 556 | 0x323D103C, /* Smart Array P700m */ |
| 557 | 0x324a103C, /* Smart Array P712m */ |
| 558 | 0x324b103C, /* SmartArray P711m */ |
| 559 | }; |
| 560 | |
| 561 | static int board_id_in_array(u32 a[], int nelems, u32 board_id) |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 562 | { |
| 563 | int i; |
| 564 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 565 | for (i = 0; i < nelems; i++) |
| 566 | if (a[i] == board_id) |
| 567 | return 1; |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | static int ctlr_is_hard_resettable(u32 board_id) |
| 572 | { |
| 573 | return !board_id_in_array(unresettable_controller, |
| 574 | ARRAY_SIZE(unresettable_controller), board_id); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 575 | } |
| 576 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 577 | static int ctlr_is_soft_resettable(u32 board_id) |
| 578 | { |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 579 | return !board_id_in_array(soft_unresettable_controller, |
| 580 | ARRAY_SIZE(soft_unresettable_controller), board_id); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static int ctlr_is_resettable(u32 board_id) |
| 584 | { |
| 585 | return ctlr_is_hard_resettable(board_id) || |
| 586 | ctlr_is_soft_resettable(board_id); |
| 587 | } |
| 588 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 589 | static int ctlr_needs_abort_tags_swizzled(u32 board_id) |
| 590 | { |
| 591 | return board_id_in_array(needs_abort_tags_swizzled, |
| 592 | ARRAY_SIZE(needs_abort_tags_swizzled), board_id); |
| 593 | } |
| 594 | |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 595 | static ssize_t host_show_resettable(struct device *dev, |
| 596 | struct device_attribute *attr, char *buf) |
| 597 | { |
| 598 | struct ctlr_info *h; |
| 599 | struct Scsi_Host *shost = class_to_shost(dev); |
| 600 | |
| 601 | h = shost_to_hba(shost); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 602 | 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] | 603 | } |
| 604 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 605 | static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[]) |
| 606 | { |
| 607 | return (scsi3addr[3] & 0xC0) == 0x40; |
| 608 | } |
| 609 | |
Robert Elliott | f2ef0ce | 2015-01-23 16:41:35 -0600 | [diff] [blame] | 610 | static const char * const raid_label[] = { "0", "4", "1(+0)", "5", "5+1", "6", |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 611 | "1(+0)ADM", "UNKNOWN", "PHYS DRV" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 612 | }; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 613 | #define HPSA_RAID_0 0 |
| 614 | #define HPSA_RAID_4 1 |
| 615 | #define HPSA_RAID_1 2 /* also used for RAID 10 */ |
| 616 | #define HPSA_RAID_5 3 /* also used for RAID 50 */ |
| 617 | #define HPSA_RAID_51 4 |
| 618 | #define HPSA_RAID_6 5 /* also used for RAID 60 */ |
| 619 | #define HPSA_RAID_ADM 6 /* also used for RAID 1+0 ADM */ |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 620 | #define RAID_UNKNOWN (ARRAY_SIZE(raid_label) - 2) |
| 621 | #define PHYSICAL_DRIVE (ARRAY_SIZE(raid_label) - 1) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 622 | |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 623 | static inline bool is_logical_device(struct hpsa_scsi_dev_t *device) |
| 624 | { |
| 625 | return !device->physical_device; |
| 626 | } |
| 627 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 628 | static ssize_t raid_level_show(struct device *dev, |
| 629 | struct device_attribute *attr, char *buf) |
| 630 | { |
| 631 | ssize_t l = 0; |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 632 | unsigned char rlevel; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 633 | struct ctlr_info *h; |
| 634 | struct scsi_device *sdev; |
| 635 | struct hpsa_scsi_dev_t *hdev; |
| 636 | unsigned long flags; |
| 637 | |
| 638 | sdev = to_scsi_device(dev); |
| 639 | h = sdev_to_hba(sdev); |
| 640 | spin_lock_irqsave(&h->lock, flags); |
| 641 | hdev = sdev->hostdata; |
| 642 | if (!hdev) { |
| 643 | spin_unlock_irqrestore(&h->lock, flags); |
| 644 | return -ENODEV; |
| 645 | } |
| 646 | |
| 647 | /* Is this even a logical drive? */ |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 648 | if (!is_logical_device(hdev)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 649 | spin_unlock_irqrestore(&h->lock, flags); |
| 650 | l = snprintf(buf, PAGE_SIZE, "N/A\n"); |
| 651 | return l; |
| 652 | } |
| 653 | |
| 654 | rlevel = hdev->raid_level; |
| 655 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 656 | if (rlevel > RAID_UNKNOWN) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 657 | rlevel = RAID_UNKNOWN; |
| 658 | l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]); |
| 659 | return l; |
| 660 | } |
| 661 | |
| 662 | static ssize_t lunid_show(struct device *dev, |
| 663 | struct device_attribute *attr, char *buf) |
| 664 | { |
| 665 | struct ctlr_info *h; |
| 666 | struct scsi_device *sdev; |
| 667 | struct hpsa_scsi_dev_t *hdev; |
| 668 | unsigned long flags; |
| 669 | unsigned char lunid[8]; |
| 670 | |
| 671 | sdev = to_scsi_device(dev); |
| 672 | h = sdev_to_hba(sdev); |
| 673 | spin_lock_irqsave(&h->lock, flags); |
| 674 | hdev = sdev->hostdata; |
| 675 | if (!hdev) { |
| 676 | spin_unlock_irqrestore(&h->lock, flags); |
| 677 | return -ENODEV; |
| 678 | } |
| 679 | memcpy(lunid, hdev->scsi3addr, sizeof(lunid)); |
| 680 | spin_unlock_irqrestore(&h->lock, flags); |
| 681 | return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 682 | lunid[0], lunid[1], lunid[2], lunid[3], |
| 683 | lunid[4], lunid[5], lunid[6], lunid[7]); |
| 684 | } |
| 685 | |
| 686 | static ssize_t unique_id_show(struct device *dev, |
| 687 | struct device_attribute *attr, char *buf) |
| 688 | { |
| 689 | struct ctlr_info *h; |
| 690 | struct scsi_device *sdev; |
| 691 | struct hpsa_scsi_dev_t *hdev; |
| 692 | unsigned long flags; |
| 693 | unsigned char sn[16]; |
| 694 | |
| 695 | sdev = to_scsi_device(dev); |
| 696 | h = sdev_to_hba(sdev); |
| 697 | spin_lock_irqsave(&h->lock, flags); |
| 698 | hdev = sdev->hostdata; |
| 699 | if (!hdev) { |
| 700 | spin_unlock_irqrestore(&h->lock, flags); |
| 701 | return -ENODEV; |
| 702 | } |
| 703 | memcpy(sn, hdev->device_id, sizeof(sn)); |
| 704 | spin_unlock_irqrestore(&h->lock, flags); |
| 705 | return snprintf(buf, 16 * 2 + 2, |
| 706 | "%02X%02X%02X%02X%02X%02X%02X%02X" |
| 707 | "%02X%02X%02X%02X%02X%02X%02X%02X\n", |
| 708 | sn[0], sn[1], sn[2], sn[3], |
| 709 | sn[4], sn[5], sn[6], sn[7], |
| 710 | sn[8], sn[9], sn[10], sn[11], |
| 711 | sn[12], sn[13], sn[14], sn[15]); |
| 712 | } |
| 713 | |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 714 | static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev, |
| 715 | struct device_attribute *attr, char *buf) |
| 716 | { |
| 717 | struct ctlr_info *h; |
| 718 | struct scsi_device *sdev; |
| 719 | struct hpsa_scsi_dev_t *hdev; |
| 720 | unsigned long flags; |
| 721 | int offload_enabled; |
| 722 | |
| 723 | sdev = to_scsi_device(dev); |
| 724 | h = sdev_to_hba(sdev); |
| 725 | spin_lock_irqsave(&h->lock, flags); |
| 726 | hdev = sdev->hostdata; |
| 727 | if (!hdev) { |
| 728 | spin_unlock_irqrestore(&h->lock, flags); |
| 729 | return -ENODEV; |
| 730 | } |
| 731 | offload_enabled = hdev->offload_enabled; |
| 732 | spin_unlock_irqrestore(&h->lock, flags); |
| 733 | return snprintf(buf, 20, "%d\n", offload_enabled); |
| 734 | } |
| 735 | |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 736 | #define MAX_PATHS 8 |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 737 | |
| 738 | static ssize_t path_info_show(struct device *dev, |
| 739 | struct device_attribute *attr, char *buf) |
| 740 | { |
| 741 | struct ctlr_info *h; |
| 742 | struct scsi_device *sdev; |
| 743 | struct hpsa_scsi_dev_t *hdev; |
| 744 | unsigned long flags; |
| 745 | int i; |
| 746 | int output_len = 0; |
| 747 | u8 box; |
| 748 | u8 bay; |
| 749 | u8 path_map_index = 0; |
| 750 | char *active; |
| 751 | unsigned char phys_connector[2]; |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 752 | |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 753 | sdev = to_scsi_device(dev); |
| 754 | h = sdev_to_hba(sdev); |
| 755 | spin_lock_irqsave(&h->devlock, flags); |
| 756 | hdev = sdev->hostdata; |
| 757 | if (!hdev) { |
| 758 | spin_unlock_irqrestore(&h->devlock, flags); |
| 759 | return -ENODEV; |
| 760 | } |
| 761 | |
| 762 | bay = hdev->bay; |
| 763 | for (i = 0; i < MAX_PATHS; i++) { |
| 764 | path_map_index = 1<<i; |
| 765 | if (i == hdev->active_path_index) |
| 766 | active = "Active"; |
| 767 | else if (hdev->path_map & path_map_index) |
| 768 | active = "Inactive"; |
| 769 | else |
| 770 | continue; |
| 771 | |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 772 | output_len += scnprintf(buf + output_len, |
| 773 | PAGE_SIZE - output_len, |
| 774 | "[%d:%d:%d:%d] %20.20s ", |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 775 | h->scsi_host->host_no, |
| 776 | hdev->bus, hdev->target, hdev->lun, |
| 777 | scsi_device_type(hdev->devtype)); |
| 778 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 779 | if (hdev->external || |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 780 | hdev->devtype == TYPE_RAID || |
| 781 | is_logical_device(hdev)) { |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 782 | output_len += snprintf(buf + output_len, |
| 783 | PAGE_SIZE - output_len, |
| 784 | "%s\n", active); |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 785 | continue; |
| 786 | } |
| 787 | |
| 788 | box = hdev->box[i]; |
| 789 | memcpy(&phys_connector, &hdev->phys_connector[i], |
| 790 | sizeof(phys_connector)); |
| 791 | if (phys_connector[0] < '0') |
| 792 | phys_connector[0] = '0'; |
| 793 | if (phys_connector[1] < '0') |
| 794 | phys_connector[1] = '0'; |
| 795 | if (hdev->phys_connector[i] > 0) |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 796 | output_len += snprintf(buf + output_len, |
| 797 | PAGE_SIZE - output_len, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 798 | "PORT: %.2s ", |
| 799 | phys_connector); |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 800 | if (hdev->devtype == TYPE_DISK && hdev->expose_device) { |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 801 | if (box == 0 || box == 0xFF) { |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 802 | output_len += snprintf(buf + output_len, |
| 803 | PAGE_SIZE - output_len, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 804 | "BAY: %hhu %s\n", |
| 805 | bay, active); |
| 806 | } else { |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 807 | output_len += snprintf(buf + output_len, |
| 808 | PAGE_SIZE - output_len, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 809 | "BOX: %hhu BAY: %hhu %s\n", |
| 810 | box, bay, active); |
| 811 | } |
| 812 | } else if (box != 0 && box != 0xFF) { |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 813 | output_len += snprintf(buf + output_len, |
| 814 | PAGE_SIZE - output_len, "BOX: %hhu %s\n", |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 815 | box, active); |
| 816 | } else |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 817 | output_len += snprintf(buf + output_len, |
| 818 | PAGE_SIZE - output_len, "%s\n", active); |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | spin_unlock_irqrestore(&h->devlock, flags); |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame^] | 822 | return output_len; |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 823 | } |
| 824 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 825 | static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL); |
| 826 | static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL); |
| 827 | static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL); |
| 828 | static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 829 | static DEVICE_ATTR(hp_ssd_smart_path_enabled, S_IRUGO, |
| 830 | host_show_hp_ssd_smart_path_enabled, NULL); |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 831 | static DEVICE_ATTR(path_info, S_IRUGO, path_info_show, NULL); |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 832 | static DEVICE_ATTR(hp_ssd_smart_path_status, S_IWUSR|S_IRUGO|S_IROTH, |
| 833 | host_show_hp_ssd_smart_path_status, |
| 834 | host_store_hp_ssd_smart_path_status); |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 835 | static DEVICE_ATTR(raid_offload_debug, S_IWUSR, NULL, |
| 836 | host_store_raid_offload_debug); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 837 | static DEVICE_ATTR(firmware_revision, S_IRUGO, |
| 838 | host_show_firmware_revision, NULL); |
| 839 | static DEVICE_ATTR(commands_outstanding, S_IRUGO, |
| 840 | host_show_commands_outstanding, NULL); |
| 841 | static DEVICE_ATTR(transport_mode, S_IRUGO, |
| 842 | host_show_transport_mode, NULL); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 843 | static DEVICE_ATTR(resettable, S_IRUGO, |
| 844 | host_show_resettable, NULL); |
Stephen Cameron | e985c58 | 2015-04-23 09:32:22 -0500 | [diff] [blame] | 845 | static DEVICE_ATTR(lockup_detected, S_IRUGO, |
| 846 | host_show_lockup_detected, NULL); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 847 | |
| 848 | static struct device_attribute *hpsa_sdev_attrs[] = { |
| 849 | &dev_attr_raid_level, |
| 850 | &dev_attr_lunid, |
| 851 | &dev_attr_unique_id, |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 852 | &dev_attr_hp_ssd_smart_path_enabled, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 853 | &dev_attr_path_info, |
Stephen Cameron | e985c58 | 2015-04-23 09:32:22 -0500 | [diff] [blame] | 854 | &dev_attr_lockup_detected, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 855 | NULL, |
| 856 | }; |
| 857 | |
| 858 | static struct device_attribute *hpsa_shost_attrs[] = { |
| 859 | &dev_attr_rescan, |
| 860 | &dev_attr_firmware_revision, |
| 861 | &dev_attr_commands_outstanding, |
| 862 | &dev_attr_transport_mode, |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 863 | &dev_attr_resettable, |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 864 | &dev_attr_hp_ssd_smart_path_status, |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 865 | &dev_attr_raid_offload_debug, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 866 | NULL, |
| 867 | }; |
| 868 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 869 | #define HPSA_NRESERVED_CMDS (HPSA_CMDS_RESERVED_FOR_ABORTS + \ |
| 870 | HPSA_CMDS_RESERVED_FOR_DRIVER + HPSA_MAX_CONCURRENT_PASSTHRUS) |
| 871 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 872 | static struct scsi_host_template hpsa_driver_template = { |
| 873 | .module = THIS_MODULE, |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 874 | .name = HPSA, |
| 875 | .proc_name = HPSA, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 876 | .queuecommand = hpsa_scsi_queue_command, |
| 877 | .scan_start = hpsa_scan_start, |
| 878 | .scan_finished = hpsa_scan_finished, |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 879 | .change_queue_depth = hpsa_change_queue_depth, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 880 | .this_id = -1, |
| 881 | .use_clustering = ENABLE_CLUSTERING, |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 882 | .eh_abort_handler = hpsa_eh_abort_handler, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 883 | .eh_device_reset_handler = hpsa_eh_device_reset_handler, |
| 884 | .ioctl = hpsa_ioctl, |
| 885 | .slave_alloc = hpsa_slave_alloc, |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 886 | .slave_configure = hpsa_slave_configure, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 887 | .slave_destroy = hpsa_slave_destroy, |
| 888 | #ifdef CONFIG_COMPAT |
| 889 | .compat_ioctl = hpsa_compat_ioctl, |
| 890 | #endif |
| 891 | .sdev_attrs = hpsa_sdev_attrs, |
| 892 | .shost_attrs = hpsa_shost_attrs, |
Stephen M. Cameron | c0d6a4d | 2011-10-26 16:20:53 -0500 | [diff] [blame] | 893 | .max_sectors = 8192, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 894 | .no_write_same = 1, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 895 | }; |
| 896 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 897 | static inline u32 next_command(struct ctlr_info *h, u8 q) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 898 | { |
| 899 | u32 a; |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 900 | struct reply_queue_buffer *rq = &h->reply_queue[q]; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 901 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 902 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 903 | return h->access.command_completed(h, q); |
| 904 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 905 | if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 906 | return h->access.command_completed(h, q); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 907 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 908 | if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { |
| 909 | a = rq->head[rq->current_entry]; |
| 910 | rq->current_entry++; |
Stephen M. Cameron | 0cbf768 | 2014-11-14 17:27:09 -0600 | [diff] [blame] | 911 | atomic_dec(&h->commands_outstanding); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 912 | } else { |
| 913 | a = FIFO_EMPTY; |
| 914 | } |
| 915 | /* Check for wraparound */ |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 916 | if (rq->current_entry == h->max_commands) { |
| 917 | rq->current_entry = 0; |
| 918 | rq->wraparound ^= 1; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 919 | } |
| 920 | return a; |
| 921 | } |
| 922 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 923 | /* |
| 924 | * There are some special bits in the bus address of the |
| 925 | * command that we have to set for the controller to know |
| 926 | * how to process the command: |
| 927 | * |
| 928 | * Normal performant mode: |
| 929 | * bit 0: 1 means performant mode, 0 means simple mode. |
| 930 | * bits 1-3 = block fetch table entry |
| 931 | * bits 4-6 = command type (== 0) |
| 932 | * |
| 933 | * ioaccel1 mode: |
| 934 | * bit 0 = "performant mode" bit. |
| 935 | * bits 1-3 = block fetch table entry |
| 936 | * bits 4-6 = command type (== 110) |
| 937 | * (command type is needed because ioaccel1 mode |
| 938 | * commands are submitted through the same register as normal |
| 939 | * mode commands, so this is how the controller knows whether |
| 940 | * the command is normal mode or ioaccel1 mode.) |
| 941 | * |
| 942 | * ioaccel2 mode: |
| 943 | * bit 0 = "performant mode" bit. |
| 944 | * bits 1-4 = block fetch table entry (note extra bit) |
| 945 | * bits 4-6 = not needed, because ioaccel2 mode has |
| 946 | * a separate special register for submitting commands. |
| 947 | */ |
| 948 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 949 | /* |
| 950 | * set_performant_mode: Modify the tag for cciss performant |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 951 | * set bit 0 for pull model, bits 3-1 for block fetch |
| 952 | * register number |
| 953 | */ |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 954 | #define DEFAULT_REPLY_QUEUE (-1) |
| 955 | static void set_performant_mode(struct ctlr_info *h, struct CommandList *c, |
| 956 | int reply_queue) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 957 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 958 | if (likely(h->transMethod & CFGTBL_Trans_Performant)) { |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 959 | c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 960 | if (unlikely(!h->msix_vector)) |
| 961 | return; |
| 962 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 963 | c->Header.ReplyQueue = |
John Kacur | 804a5cb | 2013-07-26 16:06:18 +0200 | [diff] [blame] | 964 | raw_smp_processor_id() % h->nreply_queues; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 965 | else |
| 966 | c->Header.ReplyQueue = reply_queue % h->nreply_queues; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 967 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 968 | } |
| 969 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 970 | static void set_ioaccel1_performant_mode(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 971 | struct CommandList *c, |
| 972 | int reply_queue) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 973 | { |
| 974 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 975 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 976 | /* |
| 977 | * Tell the controller to post the reply to the queue for this |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 978 | * processor. This seems to give the best I/O throughput. |
| 979 | */ |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 980 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
| 981 | cp->ReplyQueue = smp_processor_id() % h->nreply_queues; |
| 982 | else |
| 983 | cp->ReplyQueue = reply_queue % h->nreply_queues; |
| 984 | /* |
| 985 | * Set the bits in the address sent down to include: |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 986 | * - performant mode bit (bit 0) |
| 987 | * - pull count (bits 1-3) |
| 988 | * - command type (bits 4-6) |
| 989 | */ |
| 990 | c->busaddr |= 1 | (h->ioaccel1_blockFetchTable[c->Header.SGList] << 1) | |
| 991 | IOACCEL1_BUSADDR_CMDTYPE; |
| 992 | } |
| 993 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 994 | static void set_ioaccel2_tmf_performant_mode(struct ctlr_info *h, |
| 995 | struct CommandList *c, |
| 996 | int reply_queue) |
| 997 | { |
| 998 | struct hpsa_tmf_struct *cp = (struct hpsa_tmf_struct *) |
| 999 | &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 1000 | |
| 1001 | /* Tell the controller to post the reply to the queue for this |
| 1002 | * processor. This seems to give the best I/O throughput. |
| 1003 | */ |
| 1004 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
| 1005 | cp->reply_queue = smp_processor_id() % h->nreply_queues; |
| 1006 | else |
| 1007 | cp->reply_queue = reply_queue % h->nreply_queues; |
| 1008 | /* Set the bits in the address sent down to include: |
| 1009 | * - performant mode bit not used in ioaccel mode 2 |
| 1010 | * - pull count (bits 0-3) |
| 1011 | * - command type isn't needed for ioaccel2 |
| 1012 | */ |
| 1013 | c->busaddr |= h->ioaccel2_blockFetchTable[0]; |
| 1014 | } |
| 1015 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1016 | static void set_ioaccel2_performant_mode(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1017 | struct CommandList *c, |
| 1018 | int reply_queue) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1019 | { |
| 1020 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 1021 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1022 | /* |
| 1023 | * Tell the controller to post the reply to the queue for this |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1024 | * processor. This seems to give the best I/O throughput. |
| 1025 | */ |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1026 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
| 1027 | cp->reply_queue = smp_processor_id() % h->nreply_queues; |
| 1028 | else |
| 1029 | cp->reply_queue = reply_queue % h->nreply_queues; |
| 1030 | /* |
| 1031 | * Set the bits in the address sent down to include: |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1032 | * - performant mode bit not used in ioaccel mode 2 |
| 1033 | * - pull count (bits 0-3) |
| 1034 | * - command type isn't needed for ioaccel2 |
| 1035 | */ |
| 1036 | c->busaddr |= (h->ioaccel2_blockFetchTable[cp->sg_count]); |
| 1037 | } |
| 1038 | |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 1039 | static int is_firmware_flash_cmd(u8 *cdb) |
| 1040 | { |
| 1041 | return cdb[0] == BMIC_WRITE && cdb[6] == BMIC_FLASH_FIRMWARE; |
| 1042 | } |
| 1043 | |
| 1044 | /* |
| 1045 | * During firmware flash, the heartbeat register may not update as frequently |
| 1046 | * as it should. So we dial down lockup detection during firmware flash. and |
| 1047 | * dial it back up when firmware flash completes. |
| 1048 | */ |
| 1049 | #define HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH (240 * HZ) |
| 1050 | #define HEARTBEAT_SAMPLE_INTERVAL (30 * HZ) |
| 1051 | static void dial_down_lockup_detection_during_fw_flash(struct ctlr_info *h, |
| 1052 | struct CommandList *c) |
| 1053 | { |
| 1054 | if (!is_firmware_flash_cmd(c->Request.CDB)) |
| 1055 | return; |
| 1056 | atomic_inc(&h->firmware_flash_in_progress); |
| 1057 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH; |
| 1058 | } |
| 1059 | |
| 1060 | static void dial_up_lockup_detection_on_fw_flash_complete(struct ctlr_info *h, |
| 1061 | struct CommandList *c) |
| 1062 | { |
| 1063 | if (is_firmware_flash_cmd(c->Request.CDB) && |
| 1064 | atomic_dec_and_test(&h->firmware_flash_in_progress)) |
| 1065 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 1066 | } |
| 1067 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1068 | static void __enqueue_cmd_and_start_io(struct ctlr_info *h, |
| 1069 | struct CommandList *c, int reply_queue) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1070 | { |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1071 | dial_down_lockup_detection_during_fw_flash(h, c); |
| 1072 | atomic_inc(&h->commands_outstanding); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1073 | switch (c->cmd_type) { |
| 1074 | case CMD_IOACCEL1: |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1075 | set_ioaccel1_performant_mode(h, c, reply_queue); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1076 | writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1077 | break; |
| 1078 | case CMD_IOACCEL2: |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1079 | set_ioaccel2_performant_mode(h, c, reply_queue); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1080 | writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1081 | break; |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 1082 | case IOACCEL2_TMF: |
| 1083 | set_ioaccel2_tmf_performant_mode(h, c, reply_queue); |
| 1084 | writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32); |
| 1085 | break; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1086 | default: |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1087 | set_performant_mode(h, c, reply_queue); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1088 | h->access.submit_command(h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1089 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1090 | } |
| 1091 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 1092 | static void enqueue_cmd_and_start_io(struct ctlr_info *h, struct CommandList *c) |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1093 | { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 1094 | if (unlikely(hpsa_is_pending_event(c))) |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 1095 | return finish_cmd(c); |
| 1096 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1097 | __enqueue_cmd_and_start_io(h, c, DEFAULT_REPLY_QUEUE); |
| 1098 | } |
| 1099 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1100 | static inline int is_hba_lunid(unsigned char scsi3addr[]) |
| 1101 | { |
| 1102 | return memcmp(scsi3addr, RAID_CTLR_LUNID, 8) == 0; |
| 1103 | } |
| 1104 | |
| 1105 | static inline int is_scsi_rev_5(struct ctlr_info *h) |
| 1106 | { |
| 1107 | if (!h->hba_inquiry_data) |
| 1108 | return 0; |
| 1109 | if ((h->hba_inquiry_data[2] & 0x07) == 5) |
| 1110 | return 1; |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1114 | static int hpsa_find_target_lun(struct ctlr_info *h, |
| 1115 | unsigned char scsi3addr[], int bus, int *target, int *lun) |
| 1116 | { |
| 1117 | /* finds an unused bus, target, lun for a new physical device |
| 1118 | * assumes h->devlock is held |
| 1119 | */ |
| 1120 | int i, found = 0; |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1121 | DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1122 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 1123 | bitmap_zero(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1124 | |
| 1125 | for (i = 0; i < h->ndevices; i++) { |
| 1126 | if (h->dev[i]->bus == bus && h->dev[i]->target != -1) |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 1127 | __set_bit(h->dev[i]->target, lun_taken); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1128 | } |
| 1129 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 1130 | i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES); |
| 1131 | if (i < HPSA_MAX_DEVICES) { |
| 1132 | /* *bus = 1; */ |
| 1133 | *target = i; |
| 1134 | *lun = 0; |
| 1135 | found = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1136 | } |
| 1137 | return !found; |
| 1138 | } |
| 1139 | |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1140 | static void hpsa_show_dev_msg(const char *level, struct ctlr_info *h, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1141 | struct hpsa_scsi_dev_t *dev, char *description) |
| 1142 | { |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1143 | #define LABEL_SIZE 25 |
| 1144 | char label[LABEL_SIZE]; |
| 1145 | |
Don Brace | 9975ec9 | 2015-11-04 15:50:25 -0600 | [diff] [blame] | 1146 | if (h == NULL || h->pdev == NULL || h->scsi_host == NULL) |
| 1147 | return; |
| 1148 | |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1149 | switch (dev->devtype) { |
| 1150 | case TYPE_RAID: |
| 1151 | snprintf(label, LABEL_SIZE, "controller"); |
| 1152 | break; |
| 1153 | case TYPE_ENCLOSURE: |
| 1154 | snprintf(label, LABEL_SIZE, "enclosure"); |
| 1155 | break; |
| 1156 | case TYPE_DISK: |
| 1157 | if (dev->external) |
| 1158 | snprintf(label, LABEL_SIZE, "external"); |
| 1159 | else if (!is_logical_dev_addr_mode(dev->scsi3addr)) |
| 1160 | snprintf(label, LABEL_SIZE, "%s", |
| 1161 | raid_label[PHYSICAL_DRIVE]); |
| 1162 | else |
| 1163 | snprintf(label, LABEL_SIZE, "RAID-%s", |
| 1164 | dev->raid_level > RAID_UNKNOWN ? "?" : |
| 1165 | raid_label[dev->raid_level]); |
| 1166 | break; |
| 1167 | case TYPE_ROM: |
| 1168 | snprintf(label, LABEL_SIZE, "rom"); |
| 1169 | break; |
| 1170 | case TYPE_TAPE: |
| 1171 | snprintf(label, LABEL_SIZE, "tape"); |
| 1172 | break; |
| 1173 | case TYPE_MEDIUM_CHANGER: |
| 1174 | snprintf(label, LABEL_SIZE, "changer"); |
| 1175 | break; |
| 1176 | default: |
| 1177 | snprintf(label, LABEL_SIZE, "UNKNOWN"); |
| 1178 | break; |
| 1179 | } |
| 1180 | |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1181 | dev_printk(level, &h->pdev->dev, |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1182 | "scsi %d:%d:%d:%d: %s %s %.8s %.16s %s SSDSmartPathCap%c En%c Exp=%d\n", |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1183 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun, |
| 1184 | description, |
| 1185 | scsi_device_type(dev->devtype), |
| 1186 | dev->vendor, |
| 1187 | dev->model, |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1188 | label, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1189 | dev->offload_config ? '+' : '-', |
| 1190 | dev->offload_enabled ? '+' : '-', |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1191 | dev->expose_device); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1192 | } |
| 1193 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1194 | /* Add an entry into h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1195 | static int hpsa_scsi_add_entry(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1196 | struct hpsa_scsi_dev_t *device, |
| 1197 | struct hpsa_scsi_dev_t *added[], int *nadded) |
| 1198 | { |
| 1199 | /* assumes h->devlock is held */ |
| 1200 | int n = h->ndevices; |
| 1201 | int i; |
| 1202 | unsigned char addr1[8], addr2[8]; |
| 1203 | struct hpsa_scsi_dev_t *sd; |
| 1204 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1205 | if (n >= HPSA_MAX_DEVICES) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1206 | dev_err(&h->pdev->dev, "too many devices, some will be " |
| 1207 | "inaccessible.\n"); |
| 1208 | return -1; |
| 1209 | } |
| 1210 | |
| 1211 | /* physical devices do not have lun or target assigned until now. */ |
| 1212 | if (device->lun != -1) |
| 1213 | /* Logical device, lun is already assigned. */ |
| 1214 | goto lun_assigned; |
| 1215 | |
| 1216 | /* If this device a non-zero lun of a multi-lun device |
| 1217 | * byte 4 of the 8-byte LUN addr will contain the logical |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 1218 | * unit no, zero otherwise. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1219 | */ |
| 1220 | if (device->scsi3addr[4] == 0) { |
| 1221 | /* This is not a non-zero lun of a multi-lun device */ |
| 1222 | if (hpsa_find_target_lun(h, device->scsi3addr, |
| 1223 | device->bus, &device->target, &device->lun) != 0) |
| 1224 | return -1; |
| 1225 | goto lun_assigned; |
| 1226 | } |
| 1227 | |
| 1228 | /* This is a non-zero lun of a multi-lun device. |
| 1229 | * Search through our list and find the device which |
shane.seymour | 9a4178b | 2015-07-18 11:13:09 -0500 | [diff] [blame] | 1230 | * has the same 8 byte LUN address, excepting byte 4 and 5. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1231 | * Assign the same bus and target for this new LUN. |
| 1232 | * Use the logical unit number from the firmware. |
| 1233 | */ |
| 1234 | memcpy(addr1, device->scsi3addr, 8); |
| 1235 | addr1[4] = 0; |
shane.seymour | 9a4178b | 2015-07-18 11:13:09 -0500 | [diff] [blame] | 1236 | addr1[5] = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1237 | for (i = 0; i < n; i++) { |
| 1238 | sd = h->dev[i]; |
| 1239 | memcpy(addr2, sd->scsi3addr, 8); |
| 1240 | addr2[4] = 0; |
shane.seymour | 9a4178b | 2015-07-18 11:13:09 -0500 | [diff] [blame] | 1241 | addr2[5] = 0; |
| 1242 | /* differ only in byte 4 and 5? */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1243 | if (memcmp(addr1, addr2, 8) == 0) { |
| 1244 | device->bus = sd->bus; |
| 1245 | device->target = sd->target; |
| 1246 | device->lun = device->scsi3addr[4]; |
| 1247 | break; |
| 1248 | } |
| 1249 | } |
| 1250 | if (device->lun == -1) { |
| 1251 | dev_warn(&h->pdev->dev, "physical device with no LUN=0," |
| 1252 | " suspect firmware bug or unsupported hardware " |
| 1253 | "configuration.\n"); |
| 1254 | return -1; |
| 1255 | } |
| 1256 | |
| 1257 | lun_assigned: |
| 1258 | |
| 1259 | h->dev[n] = device; |
| 1260 | h->ndevices++; |
| 1261 | added[*nadded] = device; |
| 1262 | (*nadded)++; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1263 | hpsa_show_dev_msg(KERN_INFO, h, device, |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1264 | device->expose_device ? "added" : "masked"); |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1265 | device->offload_to_be_enabled = device->offload_enabled; |
| 1266 | device->offload_enabled = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1267 | return 0; |
| 1268 | } |
| 1269 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1270 | /* Update an entry in h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1271 | static void hpsa_scsi_update_entry(struct ctlr_info *h, |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1272 | int entry, struct hpsa_scsi_dev_t *new_entry) |
| 1273 | { |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1274 | int offload_enabled; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1275 | /* assumes h->devlock is held */ |
| 1276 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
| 1277 | |
| 1278 | /* Raid level changed. */ |
| 1279 | h->dev[entry]->raid_level = new_entry->raid_level; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1280 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1281 | /* Raid offload parameters changed. Careful about the ordering. */ |
| 1282 | if (new_entry->offload_config && new_entry->offload_enabled) { |
| 1283 | /* |
| 1284 | * if drive is newly offload_enabled, we want to copy the |
| 1285 | * raid map data first. If previously offload_enabled and |
| 1286 | * offload_config were set, raid map data had better be |
| 1287 | * the same as it was before. if raid map data is changed |
| 1288 | * then it had better be the case that |
| 1289 | * h->dev[entry]->offload_enabled is currently 0. |
| 1290 | */ |
| 1291 | h->dev[entry]->raid_map = new_entry->raid_map; |
| 1292 | h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1293 | } |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 1294 | if (new_entry->hba_ioaccel_enabled) { |
| 1295 | h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle; |
| 1296 | wmb(); /* set ioaccel_handle *before* hba_ioaccel_enabled */ |
| 1297 | } |
| 1298 | h->dev[entry]->hba_ioaccel_enabled = new_entry->hba_ioaccel_enabled; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1299 | h->dev[entry]->offload_config = new_entry->offload_config; |
Stephen M. Cameron | 9fb0de2 | 2014-02-18 13:56:50 -0600 | [diff] [blame] | 1300 | h->dev[entry]->offload_to_mirror = new_entry->offload_to_mirror; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1301 | h->dev[entry]->queue_depth = new_entry->queue_depth; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1302 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1303 | /* |
| 1304 | * We can turn off ioaccel offload now, but need to delay turning |
| 1305 | * it on until we can update h->dev[entry]->phys_disk[], but we |
| 1306 | * can't do that until all the devices are updated. |
| 1307 | */ |
| 1308 | h->dev[entry]->offload_to_be_enabled = new_entry->offload_enabled; |
| 1309 | if (!new_entry->offload_enabled) |
| 1310 | h->dev[entry]->offload_enabled = 0; |
| 1311 | |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1312 | offload_enabled = h->dev[entry]->offload_enabled; |
| 1313 | h->dev[entry]->offload_enabled = h->dev[entry]->offload_to_be_enabled; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1314 | hpsa_show_dev_msg(KERN_INFO, h, h->dev[entry], "updated"); |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1315 | h->dev[entry]->offload_enabled = offload_enabled; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1316 | } |
| 1317 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1318 | /* Replace an entry from h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1319 | static void hpsa_scsi_replace_entry(struct ctlr_info *h, |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1320 | int entry, struct hpsa_scsi_dev_t *new_entry, |
| 1321 | struct hpsa_scsi_dev_t *added[], int *nadded, |
| 1322 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1323 | { |
| 1324 | /* assumes h->devlock is held */ |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1325 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1326 | removed[*nremoved] = h->dev[entry]; |
| 1327 | (*nremoved)++; |
Stephen M. Cameron | 01350d0 | 2011-08-09 08:18:01 -0500 | [diff] [blame] | 1328 | |
| 1329 | /* |
| 1330 | * New physical devices won't have target/lun assigned yet |
| 1331 | * so we need to preserve the values in the slot we are replacing. |
| 1332 | */ |
| 1333 | if (new_entry->target == -1) { |
| 1334 | new_entry->target = h->dev[entry]->target; |
| 1335 | new_entry->lun = h->dev[entry]->lun; |
| 1336 | } |
| 1337 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1338 | h->dev[entry] = new_entry; |
| 1339 | added[*nadded] = new_entry; |
| 1340 | (*nadded)++; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1341 | hpsa_show_dev_msg(KERN_INFO, h, new_entry, "replaced"); |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1342 | new_entry->offload_to_be_enabled = new_entry->offload_enabled; |
| 1343 | new_entry->offload_enabled = 0; |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1344 | } |
| 1345 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1346 | /* Remove an entry from h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1347 | static void hpsa_scsi_remove_entry(struct ctlr_info *h, int entry, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1348 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1349 | { |
| 1350 | /* assumes h->devlock is held */ |
| 1351 | int i; |
| 1352 | struct hpsa_scsi_dev_t *sd; |
| 1353 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1354 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1355 | |
| 1356 | sd = h->dev[entry]; |
| 1357 | removed[*nremoved] = h->dev[entry]; |
| 1358 | (*nremoved)++; |
| 1359 | |
| 1360 | for (i = entry; i < h->ndevices-1; i++) |
| 1361 | h->dev[i] = h->dev[i+1]; |
| 1362 | h->ndevices--; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1363 | hpsa_show_dev_msg(KERN_INFO, h, sd, "removed"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | #define SCSI3ADDR_EQ(a, b) ( \ |
| 1367 | (a)[7] == (b)[7] && \ |
| 1368 | (a)[6] == (b)[6] && \ |
| 1369 | (a)[5] == (b)[5] && \ |
| 1370 | (a)[4] == (b)[4] && \ |
| 1371 | (a)[3] == (b)[3] && \ |
| 1372 | (a)[2] == (b)[2] && \ |
| 1373 | (a)[1] == (b)[1] && \ |
| 1374 | (a)[0] == (b)[0]) |
| 1375 | |
| 1376 | static void fixup_botched_add(struct ctlr_info *h, |
| 1377 | struct hpsa_scsi_dev_t *added) |
| 1378 | { |
| 1379 | /* called when scsi_add_device fails in order to re-adjust |
| 1380 | * h->dev[] to match the mid layer's view. |
| 1381 | */ |
| 1382 | unsigned long flags; |
| 1383 | int i, j; |
| 1384 | |
| 1385 | spin_lock_irqsave(&h->lock, flags); |
| 1386 | for (i = 0; i < h->ndevices; i++) { |
| 1387 | if (h->dev[i] == added) { |
| 1388 | for (j = i; j < h->ndevices-1; j++) |
| 1389 | h->dev[j] = h->dev[j+1]; |
| 1390 | h->ndevices--; |
| 1391 | break; |
| 1392 | } |
| 1393 | } |
| 1394 | spin_unlock_irqrestore(&h->lock, flags); |
| 1395 | kfree(added); |
| 1396 | } |
| 1397 | |
| 1398 | static inline int device_is_the_same(struct hpsa_scsi_dev_t *dev1, |
| 1399 | struct hpsa_scsi_dev_t *dev2) |
| 1400 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1401 | /* we compare everything except lun and target as these |
| 1402 | * are not yet assigned. Compare parts likely |
| 1403 | * to differ first |
| 1404 | */ |
| 1405 | if (memcmp(dev1->scsi3addr, dev2->scsi3addr, |
| 1406 | sizeof(dev1->scsi3addr)) != 0) |
| 1407 | return 0; |
| 1408 | if (memcmp(dev1->device_id, dev2->device_id, |
| 1409 | sizeof(dev1->device_id)) != 0) |
| 1410 | return 0; |
| 1411 | if (memcmp(dev1->model, dev2->model, sizeof(dev1->model)) != 0) |
| 1412 | return 0; |
| 1413 | if (memcmp(dev1->vendor, dev2->vendor, sizeof(dev1->vendor)) != 0) |
| 1414 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1415 | if (dev1->devtype != dev2->devtype) |
| 1416 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1417 | if (dev1->bus != dev2->bus) |
| 1418 | return 0; |
| 1419 | return 1; |
| 1420 | } |
| 1421 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1422 | static inline int device_updated(struct hpsa_scsi_dev_t *dev1, |
| 1423 | struct hpsa_scsi_dev_t *dev2) |
| 1424 | { |
| 1425 | /* Device attributes that can change, but don't mean |
| 1426 | * that the device is a different device, nor that the OS |
| 1427 | * needs to be told anything about the change. |
| 1428 | */ |
| 1429 | if (dev1->raid_level != dev2->raid_level) |
| 1430 | return 1; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1431 | if (dev1->offload_config != dev2->offload_config) |
| 1432 | return 1; |
| 1433 | if (dev1->offload_enabled != dev2->offload_enabled) |
| 1434 | return 1; |
Don Brace | 9384950 | 2015-07-18 11:12:49 -0500 | [diff] [blame] | 1435 | if (!is_logical_dev_addr_mode(dev1->scsi3addr)) |
| 1436 | if (dev1->queue_depth != dev2->queue_depth) |
| 1437 | return 1; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1441 | /* Find needle in haystack. If exact match found, return DEVICE_SAME, |
| 1442 | * and return needle location in *index. If scsi3addr matches, but not |
| 1443 | * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1444 | * location in *index. |
| 1445 | * In the case of a minor device attribute change, such as RAID level, just |
| 1446 | * return DEVICE_UPDATED, along with the updated device's location in index. |
| 1447 | * If needle not found, return DEVICE_NOT_FOUND. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1448 | */ |
| 1449 | static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle, |
| 1450 | struct hpsa_scsi_dev_t *haystack[], int haystack_size, |
| 1451 | int *index) |
| 1452 | { |
| 1453 | int i; |
| 1454 | #define DEVICE_NOT_FOUND 0 |
| 1455 | #define DEVICE_CHANGED 1 |
| 1456 | #define DEVICE_SAME 2 |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1457 | #define DEVICE_UPDATED 3 |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1458 | if (needle == NULL) |
| 1459 | return DEVICE_NOT_FOUND; |
| 1460 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1461 | for (i = 0; i < haystack_size; i++) { |
Stephen M. Cameron | 2323104 | 2010-02-04 08:43:36 -0600 | [diff] [blame] | 1462 | if (haystack[i] == NULL) /* previously removed. */ |
| 1463 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1464 | if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) { |
| 1465 | *index = i; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1466 | if (device_is_the_same(needle, haystack[i])) { |
| 1467 | if (device_updated(needle, haystack[i])) |
| 1468 | return DEVICE_UPDATED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1469 | return DEVICE_SAME; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1470 | } else { |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1471 | /* Keep offline devices offline */ |
| 1472 | if (needle->volume_offline) |
| 1473 | return DEVICE_NOT_FOUND; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1474 | return DEVICE_CHANGED; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1475 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | *index = -1; |
| 1479 | return DEVICE_NOT_FOUND; |
| 1480 | } |
| 1481 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1482 | static void hpsa_monitor_offline_device(struct ctlr_info *h, |
| 1483 | unsigned char scsi3addr[]) |
| 1484 | { |
| 1485 | struct offline_device_entry *device; |
| 1486 | unsigned long flags; |
| 1487 | |
| 1488 | /* Check to see if device is already on the list */ |
| 1489 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 1490 | list_for_each_entry(device, &h->offline_device_list, offline_list) { |
| 1491 | if (memcmp(device->scsi3addr, scsi3addr, |
| 1492 | sizeof(device->scsi3addr)) == 0) { |
| 1493 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1494 | return; |
| 1495 | } |
| 1496 | } |
| 1497 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1498 | |
| 1499 | /* Device is not on the list, add it. */ |
| 1500 | device = kmalloc(sizeof(*device), GFP_KERNEL); |
| 1501 | if (!device) { |
| 1502 | dev_warn(&h->pdev->dev, "out of memory in %s\n", __func__); |
| 1503 | return; |
| 1504 | } |
| 1505 | memcpy(device->scsi3addr, scsi3addr, sizeof(device->scsi3addr)); |
| 1506 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 1507 | list_add_tail(&device->offline_list, &h->offline_device_list); |
| 1508 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1509 | } |
| 1510 | |
| 1511 | /* Print a message explaining various offline volume states */ |
| 1512 | static void hpsa_show_volume_status(struct ctlr_info *h, |
| 1513 | struct hpsa_scsi_dev_t *sd) |
| 1514 | { |
| 1515 | if (sd->volume_offline == HPSA_VPD_LV_STATUS_UNSUPPORTED) |
| 1516 | dev_info(&h->pdev->dev, |
| 1517 | "C%d:B%d:T%d:L%d Volume status is not available through vital product data pages.\n", |
| 1518 | h->scsi_host->host_no, |
| 1519 | sd->bus, sd->target, sd->lun); |
| 1520 | switch (sd->volume_offline) { |
| 1521 | case HPSA_LV_OK: |
| 1522 | break; |
| 1523 | case HPSA_LV_UNDERGOING_ERASE: |
| 1524 | dev_info(&h->pdev->dev, |
| 1525 | "C%d:B%d:T%d:L%d Volume is undergoing background erase process.\n", |
| 1526 | h->scsi_host->host_no, |
| 1527 | sd->bus, sd->target, sd->lun); |
| 1528 | break; |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 1529 | case HPSA_LV_NOT_AVAILABLE: |
| 1530 | dev_info(&h->pdev->dev, |
| 1531 | "C%d:B%d:T%d:L%d Volume is waiting for transforming volume.\n", |
| 1532 | h->scsi_host->host_no, |
| 1533 | sd->bus, sd->target, sd->lun); |
| 1534 | break; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1535 | case HPSA_LV_UNDERGOING_RPI: |
| 1536 | dev_info(&h->pdev->dev, |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 1537 | "C%d:B%d:T%d:L%d Volume is undergoing rapid parity init.\n", |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1538 | h->scsi_host->host_no, |
| 1539 | sd->bus, sd->target, sd->lun); |
| 1540 | break; |
| 1541 | case HPSA_LV_PENDING_RPI: |
| 1542 | dev_info(&h->pdev->dev, |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 1543 | "C%d:B%d:T%d:L%d Volume is queued for rapid parity initialization process.\n", |
| 1544 | h->scsi_host->host_no, |
| 1545 | sd->bus, sd->target, sd->lun); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1546 | break; |
| 1547 | case HPSA_LV_ENCRYPTED_NO_KEY: |
| 1548 | dev_info(&h->pdev->dev, |
| 1549 | "C%d:B%d:T%d:L%d Volume is encrypted and cannot be accessed because key is not present.\n", |
| 1550 | h->scsi_host->host_no, |
| 1551 | sd->bus, sd->target, sd->lun); |
| 1552 | break; |
| 1553 | case HPSA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER: |
| 1554 | dev_info(&h->pdev->dev, |
| 1555 | "C%d:B%d:T%d:L%d Volume is not encrypted and cannot be accessed because controller is in encryption-only mode.\n", |
| 1556 | h->scsi_host->host_no, |
| 1557 | sd->bus, sd->target, sd->lun); |
| 1558 | break; |
| 1559 | case HPSA_LV_UNDERGOING_ENCRYPTION: |
| 1560 | dev_info(&h->pdev->dev, |
| 1561 | "C%d:B%d:T%d:L%d Volume is undergoing encryption process.\n", |
| 1562 | h->scsi_host->host_no, |
| 1563 | sd->bus, sd->target, sd->lun); |
| 1564 | break; |
| 1565 | case HPSA_LV_UNDERGOING_ENCRYPTION_REKEYING: |
| 1566 | dev_info(&h->pdev->dev, |
| 1567 | "C%d:B%d:T%d:L%d Volume is undergoing encryption re-keying process.\n", |
| 1568 | h->scsi_host->host_no, |
| 1569 | sd->bus, sd->target, sd->lun); |
| 1570 | break; |
| 1571 | case HPSA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: |
| 1572 | dev_info(&h->pdev->dev, |
| 1573 | "C%d:B%d:T%d:L%d Volume is encrypted and cannot be accessed because controller does not have encryption enabled.\n", |
| 1574 | h->scsi_host->host_no, |
| 1575 | sd->bus, sd->target, sd->lun); |
| 1576 | break; |
| 1577 | case HPSA_LV_PENDING_ENCRYPTION: |
| 1578 | dev_info(&h->pdev->dev, |
| 1579 | "C%d:B%d:T%d:L%d Volume is pending migration to encrypted state, but process has not started.\n", |
| 1580 | h->scsi_host->host_no, |
| 1581 | sd->bus, sd->target, sd->lun); |
| 1582 | break; |
| 1583 | case HPSA_LV_PENDING_ENCRYPTION_REKEYING: |
| 1584 | dev_info(&h->pdev->dev, |
| 1585 | "C%d:B%d:T%d:L%d Volume is encrypted and is pending encryption rekeying.\n", |
| 1586 | h->scsi_host->host_no, |
| 1587 | sd->bus, sd->target, sd->lun); |
| 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1592 | /* |
| 1593 | * Figure the list of physical drive pointers for a logical drive with |
| 1594 | * raid offload configured. |
| 1595 | */ |
| 1596 | static void hpsa_figure_phys_disk_ptrs(struct ctlr_info *h, |
| 1597 | struct hpsa_scsi_dev_t *dev[], int ndevices, |
| 1598 | struct hpsa_scsi_dev_t *logical_drive) |
| 1599 | { |
| 1600 | struct raid_map_data *map = &logical_drive->raid_map; |
| 1601 | struct raid_map_disk_data *dd = &map->data[0]; |
| 1602 | int i, j; |
| 1603 | int total_disks_per_row = le16_to_cpu(map->data_disks_per_row) + |
| 1604 | le16_to_cpu(map->metadata_disks_per_row); |
| 1605 | int nraid_map_entries = le16_to_cpu(map->row_cnt) * |
| 1606 | le16_to_cpu(map->layout_map_count) * |
| 1607 | total_disks_per_row; |
| 1608 | int nphys_disk = le16_to_cpu(map->layout_map_count) * |
| 1609 | total_disks_per_row; |
| 1610 | int qdepth; |
| 1611 | |
| 1612 | if (nraid_map_entries > RAID_MAP_MAX_ENTRIES) |
| 1613 | nraid_map_entries = RAID_MAP_MAX_ENTRIES; |
| 1614 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 1615 | logical_drive->nphysical_disks = nraid_map_entries; |
| 1616 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1617 | qdepth = 0; |
| 1618 | for (i = 0; i < nraid_map_entries; i++) { |
| 1619 | logical_drive->phys_disk[i] = NULL; |
| 1620 | if (!logical_drive->offload_config) |
| 1621 | continue; |
| 1622 | for (j = 0; j < ndevices; j++) { |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1623 | if (dev[j] == NULL) |
| 1624 | continue; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1625 | if (dev[j]->devtype != TYPE_DISK) |
| 1626 | continue; |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 1627 | if (is_logical_device(dev[j])) |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1628 | continue; |
| 1629 | if (dev[j]->ioaccel_handle != dd[i].ioaccel_handle) |
| 1630 | continue; |
| 1631 | |
| 1632 | logical_drive->phys_disk[i] = dev[j]; |
| 1633 | if (i < nphys_disk) |
| 1634 | qdepth = min(h->nr_cmds, qdepth + |
| 1635 | logical_drive->phys_disk[i]->queue_depth); |
| 1636 | break; |
| 1637 | } |
| 1638 | |
| 1639 | /* |
| 1640 | * This can happen if a physical drive is removed and |
| 1641 | * the logical drive is degraded. In that case, the RAID |
| 1642 | * map data will refer to a physical disk which isn't actually |
| 1643 | * present. And in that case offload_enabled should already |
| 1644 | * be 0, but we'll turn it off here just in case |
| 1645 | */ |
| 1646 | if (!logical_drive->phys_disk[i]) { |
| 1647 | logical_drive->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1648 | logical_drive->offload_to_be_enabled = 0; |
| 1649 | logical_drive->queue_depth = 8; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | if (nraid_map_entries) |
| 1653 | /* |
| 1654 | * This is correct for reads, too high for full stripe writes, |
| 1655 | * way too high for partial stripe writes |
| 1656 | */ |
| 1657 | logical_drive->queue_depth = qdepth; |
| 1658 | else |
| 1659 | logical_drive->queue_depth = h->nr_cmds; |
| 1660 | } |
| 1661 | |
| 1662 | static void hpsa_update_log_drive_phys_drive_ptrs(struct ctlr_info *h, |
| 1663 | struct hpsa_scsi_dev_t *dev[], int ndevices) |
| 1664 | { |
| 1665 | int i; |
| 1666 | |
| 1667 | for (i = 0; i < ndevices; i++) { |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1668 | if (dev[i] == NULL) |
| 1669 | continue; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1670 | if (dev[i]->devtype != TYPE_DISK) |
| 1671 | continue; |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 1672 | if (!is_logical_device(dev[i])) |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1673 | continue; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1674 | |
| 1675 | /* |
| 1676 | * If offload is currently enabled, the RAID map and |
| 1677 | * phys_disk[] assignment *better* not be changing |
| 1678 | * and since it isn't changing, we do not need to |
| 1679 | * update it. |
| 1680 | */ |
| 1681 | if (dev[i]->offload_enabled) |
| 1682 | continue; |
| 1683 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1684 | hpsa_figure_phys_disk_ptrs(h, dev, ndevices, dev[i]); |
| 1685 | } |
| 1686 | } |
| 1687 | |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1688 | static int hpsa_add_device(struct ctlr_info *h, struct hpsa_scsi_dev_t *device) |
| 1689 | { |
| 1690 | int rc = 0; |
| 1691 | |
| 1692 | if (!h->scsi_host) |
| 1693 | return 1; |
| 1694 | |
| 1695 | rc = scsi_add_device(h->scsi_host, device->bus, |
| 1696 | device->target, device->lun); |
| 1697 | return rc; |
| 1698 | } |
| 1699 | |
| 1700 | static void hpsa_remove_device(struct ctlr_info *h, |
| 1701 | struct hpsa_scsi_dev_t *device) |
| 1702 | { |
| 1703 | struct scsi_device *sdev = NULL; |
| 1704 | |
| 1705 | if (!h->scsi_host) |
| 1706 | return; |
| 1707 | |
| 1708 | sdev = scsi_device_lookup(h->scsi_host, device->bus, |
| 1709 | device->target, device->lun); |
| 1710 | |
| 1711 | if (sdev) { |
| 1712 | scsi_remove_device(sdev); |
| 1713 | scsi_device_put(sdev); |
| 1714 | } else { |
| 1715 | /* |
| 1716 | * We don't expect to get here. Future commands |
| 1717 | * to this device will get a selection timeout as |
| 1718 | * if the device were gone. |
| 1719 | */ |
| 1720 | hpsa_show_dev_msg(KERN_WARNING, h, device, |
| 1721 | "didn't find device for removal."); |
| 1722 | } |
| 1723 | } |
| 1724 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1725 | static void adjust_hpsa_scsi_table(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1726 | struct hpsa_scsi_dev_t *sd[], int nsds) |
| 1727 | { |
| 1728 | /* sd contains scsi3 addresses and devtypes, and inquiry |
| 1729 | * data. This function takes what's in sd to be the current |
| 1730 | * reality and updates h->dev[] to reflect that reality. |
| 1731 | */ |
| 1732 | int i, entry, device_change, changes = 0; |
| 1733 | struct hpsa_scsi_dev_t *csd; |
| 1734 | unsigned long flags; |
| 1735 | struct hpsa_scsi_dev_t **added, **removed; |
| 1736 | int nadded, nremoved; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1737 | |
Don Brace | da03ded | 2015-11-04 15:50:56 -0600 | [diff] [blame] | 1738 | /* |
| 1739 | * A reset can cause a device status to change |
| 1740 | * re-schedule the scan to see what happened. |
| 1741 | */ |
| 1742 | if (h->reset_in_progress) { |
| 1743 | h->drv_req_rescan = 1; |
| 1744 | return; |
| 1745 | } |
| 1746 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1747 | added = kzalloc(sizeof(*added) * HPSA_MAX_DEVICES, GFP_KERNEL); |
| 1748 | removed = kzalloc(sizeof(*removed) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1749 | |
| 1750 | if (!added || !removed) { |
| 1751 | dev_warn(&h->pdev->dev, "out of memory in " |
| 1752 | "adjust_hpsa_scsi_table\n"); |
| 1753 | goto free_and_out; |
| 1754 | } |
| 1755 | |
| 1756 | spin_lock_irqsave(&h->devlock, flags); |
| 1757 | |
| 1758 | /* find any devices in h->dev[] that are not in |
| 1759 | * sd[] and remove them from h->dev[], and for any |
| 1760 | * devices which have changed, remove the old device |
| 1761 | * info and add the new device info. |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1762 | * If minor device attributes change, just update |
| 1763 | * the existing device structure. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1764 | */ |
| 1765 | i = 0; |
| 1766 | nremoved = 0; |
| 1767 | nadded = 0; |
| 1768 | while (i < h->ndevices) { |
| 1769 | csd = h->dev[i]; |
| 1770 | device_change = hpsa_scsi_find_entry(csd, sd, nsds, &entry); |
| 1771 | if (device_change == DEVICE_NOT_FOUND) { |
| 1772 | changes++; |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1773 | hpsa_scsi_remove_entry(h, i, removed, &nremoved); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1774 | continue; /* remove ^^^, hence i not incremented */ |
| 1775 | } else if (device_change == DEVICE_CHANGED) { |
| 1776 | changes++; |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1777 | hpsa_scsi_replace_entry(h, i, sd[entry], |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1778 | added, &nadded, removed, &nremoved); |
Stephen M. Cameron | c7f172d | 2010-02-04 08:43:31 -0600 | [diff] [blame] | 1779 | /* Set it to NULL to prevent it from being freed |
| 1780 | * at the bottom of hpsa_update_scsi_devices() |
| 1781 | */ |
| 1782 | sd[entry] = NULL; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1783 | } else if (device_change == DEVICE_UPDATED) { |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1784 | hpsa_scsi_update_entry(h, i, sd[entry]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1785 | } |
| 1786 | i++; |
| 1787 | } |
| 1788 | |
| 1789 | /* Now, make sure every device listed in sd[] is also |
| 1790 | * listed in h->dev[], adding them if they aren't found |
| 1791 | */ |
| 1792 | |
| 1793 | for (i = 0; i < nsds; i++) { |
| 1794 | if (!sd[i]) /* if already added above. */ |
| 1795 | continue; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1796 | |
| 1797 | /* Don't add devices which are NOT READY, FORMAT IN PROGRESS |
| 1798 | * as the SCSI mid-layer does not handle such devices well. |
| 1799 | * It relentlessly loops sending TUR at 3Hz, then READ(10) |
| 1800 | * at 160Hz, and prevents the system from coming up. |
| 1801 | */ |
| 1802 | if (sd[i]->volume_offline) { |
| 1803 | hpsa_show_volume_status(h, sd[i]); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1804 | hpsa_show_dev_msg(KERN_INFO, h, sd[i], "offline"); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1805 | continue; |
| 1806 | } |
| 1807 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1808 | device_change = hpsa_scsi_find_entry(sd[i], h->dev, |
| 1809 | h->ndevices, &entry); |
| 1810 | if (device_change == DEVICE_NOT_FOUND) { |
| 1811 | changes++; |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1812 | if (hpsa_scsi_add_entry(h, sd[i], added, &nadded) != 0) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1813 | break; |
| 1814 | sd[i] = NULL; /* prevent from being freed later. */ |
| 1815 | } else if (device_change == DEVICE_CHANGED) { |
| 1816 | /* should never happen... */ |
| 1817 | changes++; |
| 1818 | dev_warn(&h->pdev->dev, |
| 1819 | "device unexpectedly changed.\n"); |
| 1820 | /* but if it does happen, we just ignore that device */ |
| 1821 | } |
| 1822 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1823 | hpsa_update_log_drive_phys_drive_ptrs(h, h->dev, h->ndevices); |
| 1824 | |
| 1825 | /* Now that h->dev[]->phys_disk[] is coherent, we can enable |
| 1826 | * any logical drives that need it enabled. |
| 1827 | */ |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1828 | for (i = 0; i < h->ndevices; i++) { |
| 1829 | if (h->dev[i] == NULL) |
| 1830 | continue; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1831 | h->dev[i]->offload_enabled = h->dev[i]->offload_to_be_enabled; |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1832 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1833 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1834 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1835 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1836 | /* Monitor devices which are in one of several NOT READY states to be |
| 1837 | * brought online later. This must be done without holding h->devlock, |
| 1838 | * so don't touch h->dev[] |
| 1839 | */ |
| 1840 | for (i = 0; i < nsds; i++) { |
| 1841 | if (!sd[i]) /* if already added above. */ |
| 1842 | continue; |
| 1843 | if (sd[i]->volume_offline) |
| 1844 | hpsa_monitor_offline_device(h, sd[i]->scsi3addr); |
| 1845 | } |
| 1846 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1847 | /* Don't notify scsi mid layer of any changes the first time through |
| 1848 | * (or if there are no changes) scsi_scan_host will do it later the |
| 1849 | * first time through. |
| 1850 | */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1851 | if (!changes) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1852 | goto free_and_out; |
| 1853 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1854 | /* Notify scsi mid layer of any removed devices */ |
| 1855 | for (i = 0; i < nremoved; i++) { |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1856 | if (removed[i] == NULL) |
| 1857 | continue; |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1858 | if (removed[i]->expose_device) |
| 1859 | hpsa_remove_device(h, removed[i]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1860 | kfree(removed[i]); |
| 1861 | removed[i] = NULL; |
| 1862 | } |
| 1863 | |
| 1864 | /* Notify scsi mid layer of any added devices */ |
| 1865 | for (i = 0; i < nadded; i++) { |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1866 | int rc = 0; |
| 1867 | |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1868 | if (added[i] == NULL) |
| 1869 | continue; |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1870 | if (!(added[i]->expose_device)) |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1871 | continue; |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1872 | rc = hpsa_add_device(h, added[i]); |
| 1873 | if (!rc) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1874 | continue; |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1875 | dev_warn(&h->pdev->dev, |
| 1876 | "addition failed %d, device not added.", rc); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1877 | /* now we have to remove it from h->dev, |
| 1878 | * since it didn't get added to scsi mid layer |
| 1879 | */ |
| 1880 | fixup_botched_add(h, added[i]); |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 1881 | h->drv_req_rescan = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | free_and_out: |
| 1885 | kfree(added); |
| 1886 | kfree(removed); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | /* |
Joe Perches | 9e03aa2 | 2013-09-03 13:45:58 -0700 | [diff] [blame] | 1890 | * 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] | 1891 | * Assume's h->devlock is held. |
| 1892 | */ |
| 1893 | static struct hpsa_scsi_dev_t *lookup_hpsa_scsi_dev(struct ctlr_info *h, |
| 1894 | int bus, int target, int lun) |
| 1895 | { |
| 1896 | int i; |
| 1897 | struct hpsa_scsi_dev_t *sd; |
| 1898 | |
| 1899 | for (i = 0; i < h->ndevices; i++) { |
| 1900 | sd = h->dev[i]; |
| 1901 | if (sd->bus == bus && sd->target == target && sd->lun == lun) |
| 1902 | return sd; |
| 1903 | } |
| 1904 | return NULL; |
| 1905 | } |
| 1906 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1907 | static int hpsa_slave_alloc(struct scsi_device *sdev) |
| 1908 | { |
| 1909 | struct hpsa_scsi_dev_t *sd; |
| 1910 | unsigned long flags; |
| 1911 | struct ctlr_info *h; |
| 1912 | |
| 1913 | h = sdev_to_hba(sdev); |
| 1914 | spin_lock_irqsave(&h->devlock, flags); |
| 1915 | sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev), |
| 1916 | sdev_id(sdev), sdev->lun); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1917 | if (likely(sd)) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1918 | atomic_set(&sd->ioaccel_cmds_out, 0); |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1919 | sdev->hostdata = sd->expose_device ? sd : NULL; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1920 | } else |
| 1921 | sdev->hostdata = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1922 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1926 | /* configure scsi device based on internal per-device structure */ |
| 1927 | static int hpsa_slave_configure(struct scsi_device *sdev) |
| 1928 | { |
| 1929 | struct hpsa_scsi_dev_t *sd; |
| 1930 | int queue_depth; |
| 1931 | |
| 1932 | sd = sdev->hostdata; |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1933 | sdev->no_uld_attach = !sd || !sd->expose_device; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1934 | |
| 1935 | if (sd) |
| 1936 | queue_depth = sd->queue_depth != 0 ? |
| 1937 | sd->queue_depth : sdev->host->can_queue; |
| 1938 | else |
| 1939 | queue_depth = sdev->host->can_queue; |
| 1940 | |
| 1941 | scsi_change_queue_depth(sdev, queue_depth); |
| 1942 | |
| 1943 | return 0; |
| 1944 | } |
| 1945 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1946 | static void hpsa_slave_destroy(struct scsi_device *sdev) |
| 1947 | { |
Stephen M. Cameron | bcc44255 | 2010-02-04 08:41:54 -0600 | [diff] [blame] | 1948 | /* nothing to do. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1949 | } |
| 1950 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 1951 | static void hpsa_free_ioaccel2_sg_chain_blocks(struct ctlr_info *h) |
| 1952 | { |
| 1953 | int i; |
| 1954 | |
| 1955 | if (!h->ioaccel2_cmd_sg_list) |
| 1956 | return; |
| 1957 | for (i = 0; i < h->nr_cmds; i++) { |
| 1958 | kfree(h->ioaccel2_cmd_sg_list[i]); |
| 1959 | h->ioaccel2_cmd_sg_list[i] = NULL; |
| 1960 | } |
| 1961 | kfree(h->ioaccel2_cmd_sg_list); |
| 1962 | h->ioaccel2_cmd_sg_list = NULL; |
| 1963 | } |
| 1964 | |
| 1965 | static int hpsa_allocate_ioaccel2_sg_chain_blocks(struct ctlr_info *h) |
| 1966 | { |
| 1967 | int i; |
| 1968 | |
| 1969 | if (h->chainsize <= 0) |
| 1970 | return 0; |
| 1971 | |
| 1972 | h->ioaccel2_cmd_sg_list = |
| 1973 | kzalloc(sizeof(*h->ioaccel2_cmd_sg_list) * h->nr_cmds, |
| 1974 | GFP_KERNEL); |
| 1975 | if (!h->ioaccel2_cmd_sg_list) |
| 1976 | return -ENOMEM; |
| 1977 | for (i = 0; i < h->nr_cmds; i++) { |
| 1978 | h->ioaccel2_cmd_sg_list[i] = |
| 1979 | kmalloc(sizeof(*h->ioaccel2_cmd_sg_list[i]) * |
| 1980 | h->maxsgentries, GFP_KERNEL); |
| 1981 | if (!h->ioaccel2_cmd_sg_list[i]) |
| 1982 | goto clean; |
| 1983 | } |
| 1984 | return 0; |
| 1985 | |
| 1986 | clean: |
| 1987 | hpsa_free_ioaccel2_sg_chain_blocks(h); |
| 1988 | return -ENOMEM; |
| 1989 | } |
| 1990 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 1991 | static void hpsa_free_sg_chain_blocks(struct ctlr_info *h) |
| 1992 | { |
| 1993 | int i; |
| 1994 | |
| 1995 | if (!h->cmd_sg_list) |
| 1996 | return; |
| 1997 | for (i = 0; i < h->nr_cmds; i++) { |
| 1998 | kfree(h->cmd_sg_list[i]); |
| 1999 | h->cmd_sg_list[i] = NULL; |
| 2000 | } |
| 2001 | kfree(h->cmd_sg_list); |
| 2002 | h->cmd_sg_list = NULL; |
| 2003 | } |
| 2004 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 2005 | static int hpsa_alloc_sg_chain_blocks(struct ctlr_info *h) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2006 | { |
| 2007 | int i; |
| 2008 | |
| 2009 | if (h->chainsize <= 0) |
| 2010 | return 0; |
| 2011 | |
| 2012 | h->cmd_sg_list = kzalloc(sizeof(*h->cmd_sg_list) * h->nr_cmds, |
| 2013 | GFP_KERNEL); |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2014 | if (!h->cmd_sg_list) { |
| 2015 | dev_err(&h->pdev->dev, "Failed to allocate SG list\n"); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2016 | return -ENOMEM; |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2017 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2018 | for (i = 0; i < h->nr_cmds; i++) { |
| 2019 | h->cmd_sg_list[i] = kmalloc(sizeof(*h->cmd_sg_list[i]) * |
| 2020 | h->chainsize, GFP_KERNEL); |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2021 | if (!h->cmd_sg_list[i]) { |
| 2022 | dev_err(&h->pdev->dev, "Failed to allocate cmd SG\n"); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2023 | goto clean; |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2024 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2025 | } |
| 2026 | return 0; |
| 2027 | |
| 2028 | clean: |
| 2029 | hpsa_free_sg_chain_blocks(h); |
| 2030 | return -ENOMEM; |
| 2031 | } |
| 2032 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2033 | static int hpsa_map_ioaccel2_sg_chain_block(struct ctlr_info *h, |
| 2034 | struct io_accel2_cmd *cp, struct CommandList *c) |
| 2035 | { |
| 2036 | struct ioaccel2_sg_element *chain_block; |
| 2037 | u64 temp64; |
| 2038 | u32 chain_size; |
| 2039 | |
| 2040 | chain_block = h->ioaccel2_cmd_sg_list[c->cmdindex]; |
Don Brace | a736e9b | 2015-11-04 15:51:14 -0600 | [diff] [blame] | 2041 | chain_size = le32_to_cpu(cp->sg[0].length); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2042 | temp64 = pci_map_single(h->pdev, chain_block, chain_size, |
| 2043 | PCI_DMA_TODEVICE); |
| 2044 | if (dma_mapping_error(&h->pdev->dev, temp64)) { |
| 2045 | /* prevent subsequent unmapping */ |
| 2046 | cp->sg->address = 0; |
| 2047 | return -1; |
| 2048 | } |
| 2049 | cp->sg->address = cpu_to_le64(temp64); |
| 2050 | return 0; |
| 2051 | } |
| 2052 | |
| 2053 | static void hpsa_unmap_ioaccel2_sg_chain_block(struct ctlr_info *h, |
| 2054 | struct io_accel2_cmd *cp) |
| 2055 | { |
| 2056 | struct ioaccel2_sg_element *chain_sg; |
| 2057 | u64 temp64; |
| 2058 | u32 chain_size; |
| 2059 | |
| 2060 | chain_sg = cp->sg; |
| 2061 | temp64 = le64_to_cpu(chain_sg->address); |
Don Brace | a736e9b | 2015-11-04 15:51:14 -0600 | [diff] [blame] | 2062 | chain_size = le32_to_cpu(cp->sg[0].length); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2063 | pci_unmap_single(h->pdev, temp64, chain_size, PCI_DMA_TODEVICE); |
| 2064 | } |
| 2065 | |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2066 | static int hpsa_map_sg_chain_block(struct ctlr_info *h, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2067 | struct CommandList *c) |
| 2068 | { |
| 2069 | struct SGDescriptor *chain_sg, *chain_block; |
| 2070 | u64 temp64; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2071 | u32 chain_len; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2072 | |
| 2073 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
| 2074 | chain_block = h->cmd_sg_list[c->cmdindex]; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2075 | chain_sg->Ext = cpu_to_le32(HPSA_SG_CHAIN); |
| 2076 | chain_len = sizeof(*chain_sg) * |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2077 | (le16_to_cpu(c->Header.SGTotal) - h->max_cmd_sg_entries); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2078 | chain_sg->Len = cpu_to_le32(chain_len); |
| 2079 | temp64 = pci_map_single(h->pdev, chain_block, chain_len, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2080 | PCI_DMA_TODEVICE); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2081 | if (dma_mapping_error(&h->pdev->dev, temp64)) { |
| 2082 | /* prevent subsequent unmapping */ |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2083 | chain_sg->Addr = cpu_to_le64(0); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2084 | return -1; |
| 2085 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2086 | chain_sg->Addr = cpu_to_le64(temp64); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2087 | return 0; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | static void hpsa_unmap_sg_chain_block(struct ctlr_info *h, |
| 2091 | struct CommandList *c) |
| 2092 | { |
| 2093 | struct SGDescriptor *chain_sg; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2094 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2095 | 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] | 2096 | return; |
| 2097 | |
| 2098 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2099 | pci_unmap_single(h->pdev, le64_to_cpu(chain_sg->Addr), |
| 2100 | le32_to_cpu(chain_sg->Len), PCI_DMA_TODEVICE); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2101 | } |
| 2102 | |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2103 | |
| 2104 | /* Decode the various types of errors on ioaccel2 path. |
| 2105 | * Return 1 for any error that should generate a RAID path retry. |
| 2106 | * Return 0 for errors that don't require a RAID path retry. |
| 2107 | */ |
| 2108 | static int handle_ioaccel_mode2_error(struct ctlr_info *h, |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2109 | struct CommandList *c, |
| 2110 | struct scsi_cmnd *cmd, |
| 2111 | struct io_accel2_cmd *c2) |
| 2112 | { |
| 2113 | int data_len; |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2114 | int retry = 0; |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2115 | u32 ioaccel2_resid = 0; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2116 | |
| 2117 | switch (c2->error_data.serv_response) { |
| 2118 | case IOACCEL2_SERV_RESPONSE_COMPLETE: |
| 2119 | switch (c2->error_data.status) { |
| 2120 | case IOACCEL2_STATUS_SR_TASK_COMP_GOOD: |
| 2121 | break; |
| 2122 | case IOACCEL2_STATUS_SR_TASK_COMP_CHK_COND: |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 2123 | cmd->result |= SAM_STAT_CHECK_CONDITION; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2124 | if (c2->error_data.data_present != |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 2125 | IOACCEL2_SENSE_DATA_PRESENT) { |
| 2126 | memset(cmd->sense_buffer, 0, |
| 2127 | SCSI_SENSE_BUFFERSIZE); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2128 | break; |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 2129 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2130 | /* copy the sense data */ |
| 2131 | data_len = c2->error_data.sense_data_len; |
| 2132 | if (data_len > SCSI_SENSE_BUFFERSIZE) |
| 2133 | data_len = SCSI_SENSE_BUFFERSIZE; |
| 2134 | if (data_len > sizeof(c2->error_data.sense_data_buff)) |
| 2135 | data_len = |
| 2136 | sizeof(c2->error_data.sense_data_buff); |
| 2137 | memcpy(cmd->sense_buffer, |
| 2138 | c2->error_data.sense_data_buff, data_len); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2139 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2140 | break; |
| 2141 | case IOACCEL2_STATUS_SR_TASK_COMP_BUSY: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2142 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2143 | break; |
| 2144 | case IOACCEL2_STATUS_SR_TASK_COMP_RES_CON: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2145 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2146 | break; |
| 2147 | case IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL: |
Stephen Cameron | 4a8da22 | 2015-04-23 09:32:43 -0500 | [diff] [blame] | 2148 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2149 | break; |
| 2150 | case IOACCEL2_STATUS_SR_TASK_COMP_ABORTED: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2151 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2152 | break; |
| 2153 | default: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2154 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2155 | break; |
| 2156 | } |
| 2157 | break; |
| 2158 | case IOACCEL2_SERV_RESPONSE_FAILURE: |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2159 | switch (c2->error_data.status) { |
| 2160 | case IOACCEL2_STATUS_SR_IO_ERROR: |
| 2161 | case IOACCEL2_STATUS_SR_IO_ABORTED: |
| 2162 | case IOACCEL2_STATUS_SR_OVERRUN: |
| 2163 | retry = 1; |
| 2164 | break; |
| 2165 | case IOACCEL2_STATUS_SR_UNDERRUN: |
| 2166 | cmd->result = (DID_OK << 16); /* host byte */ |
| 2167 | cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ |
| 2168 | ioaccel2_resid = get_unaligned_le32( |
| 2169 | &c2->error_data.resid_cnt[0]); |
| 2170 | scsi_set_resid(cmd, ioaccel2_resid); |
| 2171 | break; |
| 2172 | case IOACCEL2_STATUS_SR_NO_PATH_TO_DEVICE: |
| 2173 | case IOACCEL2_STATUS_SR_INVALID_DEVICE: |
| 2174 | case IOACCEL2_STATUS_SR_IOACCEL_DISABLED: |
| 2175 | /* We will get an event from ctlr to trigger rescan */ |
| 2176 | retry = 1; |
| 2177 | break; |
| 2178 | default: |
| 2179 | retry = 1; |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2180 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2181 | break; |
| 2182 | case IOACCEL2_SERV_RESPONSE_TMF_COMPLETE: |
| 2183 | break; |
| 2184 | case IOACCEL2_SERV_RESPONSE_TMF_SUCCESS: |
| 2185 | break; |
| 2186 | case IOACCEL2_SERV_RESPONSE_TMF_REJECTED: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2187 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2188 | break; |
| 2189 | case IOACCEL2_SERV_RESPONSE_TMF_WRONG_LUN: |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2190 | break; |
| 2191 | default: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2192 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2193 | break; |
| 2194 | } |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2195 | |
| 2196 | return retry; /* retry on raid path? */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2197 | } |
| 2198 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2199 | static void hpsa_cmd_resolve_events(struct ctlr_info *h, |
| 2200 | struct CommandList *c) |
| 2201 | { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2202 | bool do_wake = false; |
| 2203 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2204 | /* |
| 2205 | * Prevent the following race in the abort handler: |
| 2206 | * |
| 2207 | * 1. LLD is requested to abort a SCSI command |
| 2208 | * 2. The SCSI command completes |
| 2209 | * 3. The struct CommandList associated with step 2 is made available |
| 2210 | * 4. New I/O request to LLD to another LUN re-uses struct CommandList |
| 2211 | * 5. Abort handler follows scsi_cmnd->host_scribble and |
| 2212 | * finds struct CommandList and tries to aborts it |
| 2213 | * Now we have aborted the wrong command. |
| 2214 | * |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2215 | * Reset c->scsi_cmd here so that the abort or reset handler will know |
| 2216 | * this command has completed. Then, check to see if the handler is |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2217 | * waiting for this command, and, if so, wake it. |
| 2218 | */ |
| 2219 | c->scsi_cmd = SCSI_CMD_IDLE; |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2220 | mb(); /* Declare command idle before checking for pending events. */ |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2221 | if (c->abort_pending) { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2222 | do_wake = true; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2223 | c->abort_pending = false; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2224 | } |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2225 | if (c->reset_pending) { |
| 2226 | unsigned long flags; |
| 2227 | struct hpsa_scsi_dev_t *dev; |
| 2228 | |
| 2229 | /* |
| 2230 | * There appears to be a reset pending; lock the lock and |
| 2231 | * reconfirm. If so, then decrement the count of outstanding |
| 2232 | * commands and wake the reset command if this is the last one. |
| 2233 | */ |
| 2234 | spin_lock_irqsave(&h->lock, flags); |
| 2235 | dev = c->reset_pending; /* Re-fetch under the lock. */ |
| 2236 | if (dev && atomic_dec_and_test(&dev->reset_cmds_out)) |
| 2237 | do_wake = true; |
| 2238 | c->reset_pending = NULL; |
| 2239 | spin_unlock_irqrestore(&h->lock, flags); |
| 2240 | } |
| 2241 | |
| 2242 | if (do_wake) |
| 2243 | wake_up_all(&h->event_sync_wait_queue); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2244 | } |
| 2245 | |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 2246 | static void hpsa_cmd_resolve_and_free(struct ctlr_info *h, |
| 2247 | struct CommandList *c) |
| 2248 | { |
| 2249 | hpsa_cmd_resolve_events(h, c); |
| 2250 | cmd_tagged_free(h, c); |
| 2251 | } |
| 2252 | |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2253 | static void hpsa_cmd_free_and_done(struct ctlr_info *h, |
| 2254 | struct CommandList *c, struct scsi_cmnd *cmd) |
| 2255 | { |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 2256 | hpsa_cmd_resolve_and_free(h, c); |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2257 | cmd->scsi_done(cmd); |
| 2258 | } |
| 2259 | |
| 2260 | static void hpsa_retry_cmd(struct ctlr_info *h, struct CommandList *c) |
| 2261 | { |
| 2262 | INIT_WORK(&c->work, hpsa_command_resubmit_worker); |
| 2263 | queue_work_on(raw_smp_processor_id(), h->resubmit_wq, &c->work); |
| 2264 | } |
| 2265 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2266 | static void hpsa_set_scsi_cmd_aborted(struct scsi_cmnd *cmd) |
| 2267 | { |
| 2268 | cmd->result = DID_ABORT << 16; |
| 2269 | } |
| 2270 | |
| 2271 | static void hpsa_cmd_abort_and_free(struct ctlr_info *h, struct CommandList *c, |
| 2272 | struct scsi_cmnd *cmd) |
| 2273 | { |
| 2274 | hpsa_set_scsi_cmd_aborted(cmd); |
| 2275 | dev_warn(&h->pdev->dev, "CDB %16phN was aborted with status 0x%x\n", |
| 2276 | c->Request.CDB, c->err_info->ScsiStatus); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 2277 | hpsa_cmd_resolve_and_free(h, c); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2278 | } |
| 2279 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2280 | static void process_ioaccel2_completion(struct ctlr_info *h, |
| 2281 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 2282 | struct hpsa_scsi_dev_t *dev) |
| 2283 | { |
| 2284 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 2285 | |
| 2286 | /* check for good status */ |
| 2287 | if (likely(c2->error_data.serv_response == 0 && |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2288 | c2->error_data.status == 0)) |
| 2289 | return hpsa_cmd_free_and_done(h, c, cmd); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2290 | |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2291 | /* |
| 2292 | * Any RAID offload error results in retry which will use |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2293 | * the normal I/O path so the controller can handle whatever's |
| 2294 | * wrong. |
| 2295 | */ |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 2296 | if (is_logical_device(dev) && |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2297 | c2->error_data.serv_response == |
| 2298 | IOACCEL2_SERV_RESPONSE_FAILURE) { |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2299 | if (c2->error_data.status == |
| 2300 | IOACCEL2_STATUS_SR_IOACCEL_DISABLED) |
| 2301 | dev->offload_enabled = 0; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2302 | |
| 2303 | return hpsa_retry_cmd(h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2304 | } |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2305 | |
| 2306 | if (handle_ioaccel_mode2_error(h, c, cmd, c2)) |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2307 | return hpsa_retry_cmd(h, c); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2308 | |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2309 | return hpsa_cmd_free_and_done(h, c, cmd); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2310 | } |
| 2311 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2312 | /* Returns 0 on success, < 0 otherwise. */ |
| 2313 | static int hpsa_evaluate_tmf_status(struct ctlr_info *h, |
| 2314 | struct CommandList *cp) |
| 2315 | { |
| 2316 | u8 tmf_status = cp->err_info->ScsiStatus; |
| 2317 | |
| 2318 | switch (tmf_status) { |
| 2319 | case CISS_TMF_COMPLETE: |
| 2320 | /* |
| 2321 | * CISS_TMF_COMPLETE never happens, instead, |
| 2322 | * ei->CommandStatus == 0 for this case. |
| 2323 | */ |
| 2324 | case CISS_TMF_SUCCESS: |
| 2325 | return 0; |
| 2326 | case CISS_TMF_INVALID_FRAME: |
| 2327 | case CISS_TMF_NOT_SUPPORTED: |
| 2328 | case CISS_TMF_FAILED: |
| 2329 | case CISS_TMF_WRONG_LUN: |
| 2330 | case CISS_TMF_OVERLAPPED_TAG: |
| 2331 | break; |
| 2332 | default: |
| 2333 | dev_warn(&h->pdev->dev, "Unknown TMF status: 0x%02x\n", |
| 2334 | tmf_status); |
| 2335 | break; |
| 2336 | } |
| 2337 | return -tmf_status; |
| 2338 | } |
| 2339 | |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 2340 | static void complete_scsi_command(struct CommandList *cp) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2341 | { |
| 2342 | struct scsi_cmnd *cmd; |
| 2343 | struct ctlr_info *h; |
| 2344 | struct ErrorInfo *ei; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2345 | struct hpsa_scsi_dev_t *dev; |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2346 | struct io_accel2_cmd *c2; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2347 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2348 | u8 sense_key; |
| 2349 | u8 asc; /* additional sense code */ |
| 2350 | u8 ascq; /* additional sense code qualifier */ |
Stephen M. Cameron | db111e1 | 2011-06-03 09:57:34 -0500 | [diff] [blame] | 2351 | unsigned long sense_data_size; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2352 | |
| 2353 | ei = cp->err_info; |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 2354 | cmd = cp->scsi_cmd; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2355 | h = cp->h; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2356 | dev = cmd->device->hostdata; |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2357 | c2 = &h->ioaccel2_cmd_pool[cp->cmdindex]; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2358 | |
| 2359 | scsi_dma_unmap(cmd); /* undo the DMA mappings */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2360 | if ((cp->cmd_type == CMD_SCSI) && |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2361 | (le16_to_cpu(cp->Header.SGTotal) > h->max_cmd_sg_entries)) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2362 | hpsa_unmap_sg_chain_block(h, cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2363 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2364 | if ((cp->cmd_type == CMD_IOACCEL2) && |
| 2365 | (c2->sg[0].chain_indicator == IOACCEL2_CHAIN)) |
| 2366 | hpsa_unmap_ioaccel2_sg_chain_block(h, c2); |
| 2367 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2368 | cmd->result = (DID_OK << 16); /* host byte */ |
| 2369 | cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2370 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2371 | if (cp->cmd_type == CMD_IOACCEL2 || cp->cmd_type == CMD_IOACCEL1) |
| 2372 | atomic_dec(&cp->phys_disk->ioaccel_cmds_out); |
| 2373 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2374 | /* |
| 2375 | * We check for lockup status here as it may be set for |
| 2376 | * CMD_SCSI, CMD_IOACCEL1 and CMD_IOACCEL2 commands by |
| 2377 | * fail_all_oustanding_cmds() |
| 2378 | */ |
| 2379 | if (unlikely(ei->CommandStatus == CMD_CTLR_LOCKUP)) { |
| 2380 | /* DID_NO_CONNECT will prevent a retry */ |
| 2381 | cmd->result = DID_NO_CONNECT << 16; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2382 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2383 | } |
| 2384 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2385 | if ((unlikely(hpsa_is_pending_event(cp)))) { |
| 2386 | if (cp->reset_pending) |
| 2387 | return hpsa_cmd_resolve_and_free(h, cp); |
| 2388 | if (cp->abort_pending) |
| 2389 | return hpsa_cmd_abort_and_free(h, cp, cmd); |
| 2390 | } |
| 2391 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2392 | if (cp->cmd_type == CMD_IOACCEL2) |
| 2393 | return process_ioaccel2_completion(h, cp, cmd, dev); |
| 2394 | |
Robert Elliott | 6aa4c36 | 2014-07-03 10:18:19 -0500 | [diff] [blame] | 2395 | scsi_set_resid(cmd, ei->ResidualCnt); |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2396 | if (ei->CommandStatus == 0) |
| 2397 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Robert Elliott | 6aa4c36 | 2014-07-03 10:18:19 -0500 | [diff] [blame] | 2398 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2399 | /* For I/O accelerator commands, copy over some fields to the normal |
| 2400 | * CISS header used below for error handling. |
| 2401 | */ |
| 2402 | if (cp->cmd_type == CMD_IOACCEL1) { |
| 2403 | struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex]; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2404 | cp->Header.SGList = scsi_sg_count(cmd); |
| 2405 | cp->Header.SGTotal = cpu_to_le16(cp->Header.SGList); |
| 2406 | cp->Request.CDBLen = le16_to_cpu(c->io_flags) & |
| 2407 | IOACCEL1_IOFLAGS_CDBLEN_MASK; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2408 | cp->Header.tag = c->tag; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2409 | memcpy(cp->Header.LUN.LunAddrBytes, c->CISS_LUN, 8); |
| 2410 | memcpy(cp->Request.CDB, c->CDB, cp->Request.CDBLen); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2411 | |
| 2412 | /* Any RAID offload error results in retry which will use |
| 2413 | * the normal I/O path so the controller can handle whatever's |
| 2414 | * wrong. |
| 2415 | */ |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 2416 | if (is_logical_device(dev)) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2417 | if (ei->CommandStatus == CMD_IOACCEL_DISABLED) |
| 2418 | dev->offload_enabled = 0; |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2419 | return hpsa_retry_cmd(h, cp); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2420 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2421 | } |
| 2422 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2423 | /* an error has occurred */ |
| 2424 | switch (ei->CommandStatus) { |
| 2425 | |
| 2426 | case CMD_TARGET_STATUS: |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2427 | cmd->result |= ei->ScsiStatus; |
| 2428 | /* copy the sense data */ |
| 2429 | if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo)) |
| 2430 | sense_data_size = SCSI_SENSE_BUFFERSIZE; |
| 2431 | else |
| 2432 | sense_data_size = sizeof(ei->SenseInfo); |
| 2433 | if (ei->SenseLen < sense_data_size) |
| 2434 | sense_data_size = ei->SenseLen; |
| 2435 | memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size); |
| 2436 | if (ei->ScsiStatus) |
| 2437 | decode_sense_data(ei->SenseInfo, sense_data_size, |
| 2438 | &sense_key, &asc, &ascq); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2439 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) { |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 2440 | if (sense_key == ABORTED_COMMAND) { |
Stephen M. Cameron | 2e311fb | 2013-09-23 13:33:41 -0500 | [diff] [blame] | 2441 | cmd->result |= DID_SOFT_ERROR << 16; |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 2442 | break; |
| 2443 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2444 | break; |
| 2445 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2446 | /* Problem was not a check condition |
| 2447 | * Pass it up to the upper layers... |
| 2448 | */ |
| 2449 | if (ei->ScsiStatus) { |
| 2450 | dev_warn(&h->pdev->dev, "cp %p has status 0x%x " |
| 2451 | "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " |
| 2452 | "Returning result: 0x%x\n", |
| 2453 | cp, ei->ScsiStatus, |
| 2454 | sense_key, asc, ascq, |
| 2455 | cmd->result); |
| 2456 | } else { /* scsi status is zero??? How??? */ |
| 2457 | dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. " |
| 2458 | "Returning no connection.\n", cp), |
| 2459 | |
| 2460 | /* Ordinarily, this case should never happen, |
| 2461 | * but there is a bug in some released firmware |
| 2462 | * revisions that allows it to happen if, for |
| 2463 | * example, a 4100 backplane loses power and |
| 2464 | * the tape drive is in it. We assume that |
| 2465 | * it's a fatal error of some kind because we |
| 2466 | * can't show that it wasn't. We will make it |
| 2467 | * look like selection timeout since that is |
| 2468 | * the most common reason for this to occur, |
| 2469 | * and it's severe enough. |
| 2470 | */ |
| 2471 | |
| 2472 | cmd->result = DID_NO_CONNECT << 16; |
| 2473 | } |
| 2474 | break; |
| 2475 | |
| 2476 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
| 2477 | break; |
| 2478 | case CMD_DATA_OVERRUN: |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2479 | dev_warn(&h->pdev->dev, |
| 2480 | "CDB %16phN data overrun\n", cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2481 | break; |
| 2482 | case CMD_INVALID: { |
| 2483 | /* print_bytes(cp, sizeof(*cp), 1, 0); |
| 2484 | print_cmd(cp); */ |
| 2485 | /* We get CMD_INVALID if you address a non-existent device |
| 2486 | * instead of a selection timeout (no response). You will |
| 2487 | * see this if you yank out a drive, then try to access it. |
| 2488 | * This is kind of a shame because it means that any other |
| 2489 | * CMD_INVALID (e.g. driver bug) will get interpreted as a |
| 2490 | * missing target. */ |
| 2491 | cmd->result = DID_NO_CONNECT << 16; |
| 2492 | } |
| 2493 | break; |
| 2494 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | 256d0ea | 2012-09-14 16:34:25 -0500 | [diff] [blame] | 2495 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2496 | dev_warn(&h->pdev->dev, "CDB %16phN : protocol error\n", |
| 2497 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2498 | break; |
| 2499 | case CMD_HARDWARE_ERR: |
| 2500 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2501 | dev_warn(&h->pdev->dev, "CDB %16phN : hardware error\n", |
| 2502 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2503 | break; |
| 2504 | case CMD_CONNECTION_LOST: |
| 2505 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2506 | dev_warn(&h->pdev->dev, "CDB %16phN : connection lost\n", |
| 2507 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2508 | break; |
| 2509 | case CMD_ABORTED: |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2510 | /* Return now to avoid calling scsi_done(). */ |
| 2511 | return hpsa_cmd_abort_and_free(h, cp, cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2512 | case CMD_ABORT_FAILED: |
| 2513 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2514 | dev_warn(&h->pdev->dev, "CDB %16phN : abort failed\n", |
| 2515 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2516 | break; |
| 2517 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | f6e7605 | 2011-07-26 11:08:52 -0500 | [diff] [blame] | 2518 | cmd->result = DID_SOFT_ERROR << 16; /* retry the command */ |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2519 | dev_warn(&h->pdev->dev, "CDB %16phN : unsolicited abort\n", |
| 2520 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2521 | break; |
| 2522 | case CMD_TIMEOUT: |
| 2523 | cmd->result = DID_TIME_OUT << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2524 | dev_warn(&h->pdev->dev, "CDB %16phN timed out\n", |
| 2525 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2526 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2527 | case CMD_UNABORTABLE: |
| 2528 | cmd->result = DID_ERROR << 16; |
| 2529 | dev_warn(&h->pdev->dev, "Command unabortable\n"); |
| 2530 | break; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2531 | case CMD_TMF_STATUS: |
| 2532 | if (hpsa_evaluate_tmf_status(h, cp)) /* TMF failed? */ |
| 2533 | cmd->result = DID_ERROR << 16; |
| 2534 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2535 | case CMD_IOACCEL_DISABLED: |
| 2536 | /* This only handles the direct pass-through case since RAID |
| 2537 | * offload is handled above. Just attempt a retry. |
| 2538 | */ |
| 2539 | cmd->result = DID_SOFT_ERROR << 16; |
| 2540 | dev_warn(&h->pdev->dev, |
| 2541 | "cp %p had HP SSD Smart Path error\n", cp); |
| 2542 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2543 | default: |
| 2544 | cmd->result = DID_ERROR << 16; |
| 2545 | dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n", |
| 2546 | cp, ei->CommandStatus); |
| 2547 | } |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2548 | |
| 2549 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2552 | static void hpsa_pci_unmap(struct pci_dev *pdev, |
| 2553 | struct CommandList *c, int sg_used, int data_direction) |
| 2554 | { |
| 2555 | int i; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2556 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2557 | for (i = 0; i < sg_used; i++) |
| 2558 | pci_unmap_single(pdev, (dma_addr_t) le64_to_cpu(c->SG[i].Addr), |
| 2559 | le32_to_cpu(c->SG[i].Len), |
| 2560 | data_direction); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2561 | } |
| 2562 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2563 | static int hpsa_map_one(struct pci_dev *pdev, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2564 | struct CommandList *cp, |
| 2565 | unsigned char *buf, |
| 2566 | size_t buflen, |
| 2567 | int data_direction) |
| 2568 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2569 | u64 addr64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2570 | |
| 2571 | if (buflen == 0 || data_direction == PCI_DMA_NONE) { |
| 2572 | cp->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2573 | cp->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2574 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2575 | } |
| 2576 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2577 | addr64 = pci_map_single(pdev, buf, buflen, data_direction); |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2578 | if (dma_mapping_error(&pdev->dev, addr64)) { |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2579 | /* Prevent subsequent unmap of something never mapped */ |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2580 | cp->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2581 | cp->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2582 | return -1; |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2583 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2584 | cp->SG[0].Addr = cpu_to_le64(addr64); |
| 2585 | cp->SG[0].Len = cpu_to_le32(buflen); |
| 2586 | cp->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* we are not chaining */ |
| 2587 | cp->Header.SGList = 1; /* no. SGs contig in this cmd */ |
| 2588 | 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] | 2589 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2590 | } |
| 2591 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2592 | #define NO_TIMEOUT ((unsigned long) -1) |
| 2593 | #define DEFAULT_TIMEOUT 30000 /* milliseconds */ |
| 2594 | static int hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h, |
| 2595 | struct CommandList *c, int reply_queue, unsigned long timeout_msecs) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2596 | { |
| 2597 | DECLARE_COMPLETION_ONSTACK(wait); |
| 2598 | |
| 2599 | c->waiting = &wait; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2600 | __enqueue_cmd_and_start_io(h, c, reply_queue); |
| 2601 | if (timeout_msecs == NO_TIMEOUT) { |
| 2602 | /* TODO: get rid of this no-timeout thing */ |
| 2603 | wait_for_completion_io(&wait); |
| 2604 | return IO_OK; |
| 2605 | } |
| 2606 | if (!wait_for_completion_io_timeout(&wait, |
| 2607 | msecs_to_jiffies(timeout_msecs))) { |
| 2608 | dev_warn(&h->pdev->dev, "Command timed out.\n"); |
| 2609 | return -ETIMEDOUT; |
| 2610 | } |
| 2611 | return IO_OK; |
| 2612 | } |
| 2613 | |
| 2614 | static int hpsa_scsi_do_simple_cmd(struct ctlr_info *h, struct CommandList *c, |
| 2615 | int reply_queue, unsigned long timeout_msecs) |
| 2616 | { |
| 2617 | if (unlikely(lockup_detected(h))) { |
| 2618 | c->err_info->CommandStatus = CMD_CTLR_LOCKUP; |
| 2619 | return IO_OK; |
| 2620 | } |
| 2621 | return hpsa_scsi_do_simple_cmd_core(h, c, reply_queue, timeout_msecs); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2622 | } |
| 2623 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 2624 | static u32 lockup_detected(struct ctlr_info *h) |
| 2625 | { |
| 2626 | int cpu; |
| 2627 | u32 rc, *lockup_detected; |
| 2628 | |
| 2629 | cpu = get_cpu(); |
| 2630 | lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); |
| 2631 | rc = *lockup_detected; |
| 2632 | put_cpu(); |
| 2633 | return rc; |
| 2634 | } |
| 2635 | |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2636 | #define MAX_DRIVER_CMD_RETRIES 25 |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2637 | static int hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, |
| 2638 | struct CommandList *c, int data_direction, unsigned long timeout_msecs) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2639 | { |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2640 | int backoff_time = 10, retry_count = 0; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2641 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2642 | |
| 2643 | do { |
Joe Perches | 7630abd | 2011-05-08 23:32:40 -0700 | [diff] [blame] | 2644 | memset(c->err_info, 0, sizeof(*c->err_info)); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2645 | rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, |
| 2646 | timeout_msecs); |
| 2647 | if (rc) |
| 2648 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2649 | retry_count++; |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2650 | if (retry_count > 3) { |
| 2651 | msleep(backoff_time); |
| 2652 | if (backoff_time < 1000) |
| 2653 | backoff_time *= 2; |
| 2654 | } |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 2655 | } while ((check_for_unit_attention(h, c) || |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2656 | check_for_busy(h, c)) && |
| 2657 | retry_count <= MAX_DRIVER_CMD_RETRIES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2658 | hpsa_pci_unmap(h->pdev, c, 1, data_direction); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2659 | if (retry_count > MAX_DRIVER_CMD_RETRIES) |
| 2660 | rc = -EIO; |
| 2661 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2662 | } |
| 2663 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2664 | static void hpsa_print_cmd(struct ctlr_info *h, char *txt, |
| 2665 | struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2666 | { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2667 | const u8 *cdb = c->Request.CDB; |
| 2668 | const u8 *lun = c->Header.LUN.LunAddrBytes; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2669 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2670 | dev_warn(&h->pdev->dev, "%s: LUN:%02x%02x%02x%02x%02x%02x%02x%02x" |
| 2671 | " CDB:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 2672 | txt, lun[0], lun[1], lun[2], lun[3], |
| 2673 | lun[4], lun[5], lun[6], lun[7], |
| 2674 | cdb[0], cdb[1], cdb[2], cdb[3], |
| 2675 | cdb[4], cdb[5], cdb[6], cdb[7], |
| 2676 | cdb[8], cdb[9], cdb[10], cdb[11], |
| 2677 | cdb[12], cdb[13], cdb[14], cdb[15]); |
| 2678 | } |
| 2679 | |
| 2680 | static void hpsa_scsi_interpret_error(struct ctlr_info *h, |
| 2681 | struct CommandList *cp) |
| 2682 | { |
| 2683 | const struct ErrorInfo *ei = cp->err_info; |
| 2684 | struct device *d = &cp->h->pdev->dev; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2685 | u8 sense_key, asc, ascq; |
| 2686 | int sense_len; |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2687 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2688 | switch (ei->CommandStatus) { |
| 2689 | case CMD_TARGET_STATUS: |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2690 | if (ei->SenseLen > sizeof(ei->SenseInfo)) |
| 2691 | sense_len = sizeof(ei->SenseInfo); |
| 2692 | else |
| 2693 | sense_len = ei->SenseLen; |
| 2694 | decode_sense_data(ei->SenseInfo, sense_len, |
| 2695 | &sense_key, &asc, &ascq); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2696 | hpsa_print_cmd(h, "SCSI status", cp); |
| 2697 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2698 | dev_warn(d, "SCSI Status = 02, Sense key = 0x%02x, ASC = 0x%02x, ASCQ = 0x%02x\n", |
| 2699 | sense_key, asc, ascq); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2700 | else |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2701 | dev_warn(d, "SCSI Status = 0x%02x\n", ei->ScsiStatus); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2702 | if (ei->ScsiStatus == 0) |
| 2703 | dev_warn(d, "SCSI status is abnormally zero. " |
| 2704 | "(probably indicates selection timeout " |
| 2705 | "reported incorrectly due to a known " |
| 2706 | "firmware bug, circa July, 2001.)\n"); |
| 2707 | break; |
| 2708 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2709 | break; |
| 2710 | case CMD_DATA_OVERRUN: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2711 | hpsa_print_cmd(h, "overrun condition", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2712 | break; |
| 2713 | case CMD_INVALID: { |
| 2714 | /* controller unfortunately reports SCSI passthru's |
| 2715 | * to non-existent targets as invalid commands. |
| 2716 | */ |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2717 | hpsa_print_cmd(h, "invalid command", cp); |
| 2718 | dev_warn(d, "probably means device no longer present\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2719 | } |
| 2720 | break; |
| 2721 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2722 | hpsa_print_cmd(h, "protocol error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2723 | break; |
| 2724 | case CMD_HARDWARE_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2725 | hpsa_print_cmd(h, "hardware error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2726 | break; |
| 2727 | case CMD_CONNECTION_LOST: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2728 | hpsa_print_cmd(h, "connection lost", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2729 | break; |
| 2730 | case CMD_ABORTED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2731 | hpsa_print_cmd(h, "aborted", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2732 | break; |
| 2733 | case CMD_ABORT_FAILED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2734 | hpsa_print_cmd(h, "abort failed", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2735 | break; |
| 2736 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2737 | hpsa_print_cmd(h, "unsolicited abort", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2738 | break; |
| 2739 | case CMD_TIMEOUT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2740 | hpsa_print_cmd(h, "timed out", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2741 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2742 | case CMD_UNABORTABLE: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2743 | hpsa_print_cmd(h, "unabortable", cp); |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2744 | break; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2745 | case CMD_CTLR_LOCKUP: |
| 2746 | hpsa_print_cmd(h, "controller lockup detected", cp); |
| 2747 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2748 | default: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2749 | hpsa_print_cmd(h, "unknown status", cp); |
| 2750 | dev_warn(d, "Unknown command status %x\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2751 | ei->CommandStatus); |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | 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] | 2756 | u16 page, unsigned char *buf, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2757 | unsigned char bufsize) |
| 2758 | { |
| 2759 | int rc = IO_OK; |
| 2760 | struct CommandList *c; |
| 2761 | struct ErrorInfo *ei; |
| 2762 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2763 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2764 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2765 | if (fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize, |
| 2766 | page, scsi3addr, TYPE_CMD)) { |
| 2767 | rc = -1; |
| 2768 | goto out; |
| 2769 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2770 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 2771 | PCI_DMA_FROMDEVICE, NO_TIMEOUT); |
| 2772 | if (rc) |
| 2773 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2774 | ei = c->err_info; |
| 2775 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2776 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2777 | rc = -1; |
| 2778 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2779 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2780 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2781 | return rc; |
| 2782 | } |
| 2783 | |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2784 | static int hpsa_send_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2785 | u8 reset_type, int reply_queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2786 | { |
| 2787 | int rc = IO_OK; |
| 2788 | struct CommandList *c; |
| 2789 | struct ErrorInfo *ei; |
| 2790 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2791 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2792 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2793 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2794 | /* fill_cmd can't fail here, no data buffer to map. */ |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 2795 | (void) fill_cmd(c, reset_type, h, NULL, 0, 0, |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2796 | scsi3addr, TYPE_MSG); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2797 | rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT); |
| 2798 | if (rc) { |
| 2799 | dev_warn(&h->pdev->dev, "Failed to send reset command\n"); |
| 2800 | goto out; |
| 2801 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2802 | /* no unmap needed here because no data xfer. */ |
| 2803 | |
| 2804 | ei = c->err_info; |
| 2805 | if (ei->CommandStatus != 0) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2806 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2807 | rc = -1; |
| 2808 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2809 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2810 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2811 | return rc; |
| 2812 | } |
| 2813 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2814 | static bool hpsa_cmd_dev_match(struct ctlr_info *h, struct CommandList *c, |
| 2815 | struct hpsa_scsi_dev_t *dev, |
| 2816 | unsigned char *scsi3addr) |
| 2817 | { |
| 2818 | int i; |
| 2819 | bool match = false; |
| 2820 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 2821 | struct hpsa_tmf_struct *ac = (struct hpsa_tmf_struct *) c2; |
| 2822 | |
| 2823 | if (hpsa_is_cmd_idle(c)) |
| 2824 | return false; |
| 2825 | |
| 2826 | switch (c->cmd_type) { |
| 2827 | case CMD_SCSI: |
| 2828 | case CMD_IOCTL_PEND: |
| 2829 | match = !memcmp(scsi3addr, &c->Header.LUN.LunAddrBytes, |
| 2830 | sizeof(c->Header.LUN.LunAddrBytes)); |
| 2831 | break; |
| 2832 | |
| 2833 | case CMD_IOACCEL1: |
| 2834 | case CMD_IOACCEL2: |
| 2835 | if (c->phys_disk == dev) { |
| 2836 | /* HBA mode match */ |
| 2837 | match = true; |
| 2838 | } else { |
| 2839 | /* Possible RAID mode -- check each phys dev. */ |
| 2840 | /* FIXME: Do we need to take out a lock here? If |
| 2841 | * so, we could just call hpsa_get_pdisk_of_ioaccel2() |
| 2842 | * instead. */ |
| 2843 | for (i = 0; i < dev->nphysical_disks && !match; i++) { |
| 2844 | /* FIXME: an alternate test might be |
| 2845 | * |
| 2846 | * match = dev->phys_disk[i]->ioaccel_handle |
| 2847 | * == c2->scsi_nexus; */ |
| 2848 | match = dev->phys_disk[i] == c->phys_disk; |
| 2849 | } |
| 2850 | } |
| 2851 | break; |
| 2852 | |
| 2853 | case IOACCEL2_TMF: |
| 2854 | for (i = 0; i < dev->nphysical_disks && !match; i++) { |
| 2855 | match = dev->phys_disk[i]->ioaccel_handle == |
| 2856 | le32_to_cpu(ac->it_nexus); |
| 2857 | } |
| 2858 | break; |
| 2859 | |
| 2860 | case 0: /* The command is in the middle of being initialized. */ |
| 2861 | match = false; |
| 2862 | break; |
| 2863 | |
| 2864 | default: |
| 2865 | dev_err(&h->pdev->dev, "unexpected cmd_type: %d\n", |
| 2866 | c->cmd_type); |
| 2867 | BUG(); |
| 2868 | } |
| 2869 | |
| 2870 | return match; |
| 2871 | } |
| 2872 | |
| 2873 | static int hpsa_do_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev, |
| 2874 | unsigned char *scsi3addr, u8 reset_type, int reply_queue) |
| 2875 | { |
| 2876 | int i; |
| 2877 | int rc = 0; |
| 2878 | |
| 2879 | /* We can really only handle one reset at a time */ |
| 2880 | if (mutex_lock_interruptible(&h->reset_mutex) == -EINTR) { |
| 2881 | dev_warn(&h->pdev->dev, "concurrent reset wait interrupted.\n"); |
| 2882 | return -EINTR; |
| 2883 | } |
| 2884 | |
| 2885 | BUG_ON(atomic_read(&dev->reset_cmds_out) != 0); |
| 2886 | |
| 2887 | for (i = 0; i < h->nr_cmds; i++) { |
| 2888 | struct CommandList *c = h->cmd_pool + i; |
| 2889 | int refcount = atomic_inc_return(&c->refcount); |
| 2890 | |
| 2891 | if (refcount > 1 && hpsa_cmd_dev_match(h, c, dev, scsi3addr)) { |
| 2892 | unsigned long flags; |
| 2893 | |
| 2894 | /* |
| 2895 | * Mark the target command as having a reset pending, |
| 2896 | * then lock a lock so that the command cannot complete |
| 2897 | * while we're considering it. If the command is not |
| 2898 | * idle then count it; otherwise revoke the event. |
| 2899 | */ |
| 2900 | c->reset_pending = dev; |
| 2901 | spin_lock_irqsave(&h->lock, flags); /* Implied MB */ |
| 2902 | if (!hpsa_is_cmd_idle(c)) |
| 2903 | atomic_inc(&dev->reset_cmds_out); |
| 2904 | else |
| 2905 | c->reset_pending = NULL; |
| 2906 | spin_unlock_irqrestore(&h->lock, flags); |
| 2907 | } |
| 2908 | |
| 2909 | cmd_free(h, c); |
| 2910 | } |
| 2911 | |
| 2912 | rc = hpsa_send_reset(h, scsi3addr, reset_type, reply_queue); |
| 2913 | if (!rc) |
| 2914 | wait_event(h->event_sync_wait_queue, |
| 2915 | atomic_read(&dev->reset_cmds_out) == 0 || |
| 2916 | lockup_detected(h)); |
| 2917 | |
| 2918 | if (unlikely(lockup_detected(h))) { |
Don Brace | 77678d3 | 2015-07-18 11:12:22 -0500 | [diff] [blame] | 2919 | dev_warn(&h->pdev->dev, |
| 2920 | "Controller lockup detected during reset wait\n"); |
| 2921 | rc = -ENODEV; |
| 2922 | } |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2923 | |
| 2924 | if (unlikely(rc)) |
| 2925 | atomic_set(&dev->reset_cmds_out, 0); |
| 2926 | |
| 2927 | mutex_unlock(&h->reset_mutex); |
| 2928 | return rc; |
| 2929 | } |
| 2930 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2931 | static void hpsa_get_raid_level(struct ctlr_info *h, |
| 2932 | unsigned char *scsi3addr, unsigned char *raid_level) |
| 2933 | { |
| 2934 | int rc; |
| 2935 | unsigned char *buf; |
| 2936 | |
| 2937 | *raid_level = RAID_UNKNOWN; |
| 2938 | buf = kzalloc(64, GFP_KERNEL); |
| 2939 | if (!buf) |
| 2940 | return; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 2941 | 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] | 2942 | if (rc == 0) |
| 2943 | *raid_level = buf[8]; |
| 2944 | if (*raid_level > RAID_UNKNOWN) |
| 2945 | *raid_level = RAID_UNKNOWN; |
| 2946 | kfree(buf); |
| 2947 | return; |
| 2948 | } |
| 2949 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2950 | #define HPSA_MAP_DEBUG |
| 2951 | #ifdef HPSA_MAP_DEBUG |
| 2952 | static void hpsa_debug_map_buff(struct ctlr_info *h, int rc, |
| 2953 | struct raid_map_data *map_buff) |
| 2954 | { |
| 2955 | struct raid_map_disk_data *dd = &map_buff->data[0]; |
| 2956 | int map, row, col; |
| 2957 | u16 map_cnt, row_cnt, disks_per_row; |
| 2958 | |
| 2959 | if (rc != 0) |
| 2960 | return; |
| 2961 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 2962 | /* Show details only if debugging has been activated. */ |
| 2963 | if (h->raid_offload_debug < 2) |
| 2964 | return; |
| 2965 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2966 | dev_info(&h->pdev->dev, "structure_size = %u\n", |
| 2967 | le32_to_cpu(map_buff->structure_size)); |
| 2968 | dev_info(&h->pdev->dev, "volume_blk_size = %u\n", |
| 2969 | le32_to_cpu(map_buff->volume_blk_size)); |
| 2970 | dev_info(&h->pdev->dev, "volume_blk_cnt = 0x%llx\n", |
| 2971 | le64_to_cpu(map_buff->volume_blk_cnt)); |
| 2972 | dev_info(&h->pdev->dev, "physicalBlockShift = %u\n", |
| 2973 | map_buff->phys_blk_shift); |
| 2974 | dev_info(&h->pdev->dev, "parity_rotation_shift = %u\n", |
| 2975 | map_buff->parity_rotation_shift); |
| 2976 | dev_info(&h->pdev->dev, "strip_size = %u\n", |
| 2977 | le16_to_cpu(map_buff->strip_size)); |
| 2978 | dev_info(&h->pdev->dev, "disk_starting_blk = 0x%llx\n", |
| 2979 | le64_to_cpu(map_buff->disk_starting_blk)); |
| 2980 | dev_info(&h->pdev->dev, "disk_blk_cnt = 0x%llx\n", |
| 2981 | le64_to_cpu(map_buff->disk_blk_cnt)); |
| 2982 | dev_info(&h->pdev->dev, "data_disks_per_row = %u\n", |
| 2983 | le16_to_cpu(map_buff->data_disks_per_row)); |
| 2984 | dev_info(&h->pdev->dev, "metadata_disks_per_row = %u\n", |
| 2985 | le16_to_cpu(map_buff->metadata_disks_per_row)); |
| 2986 | dev_info(&h->pdev->dev, "row_cnt = %u\n", |
| 2987 | le16_to_cpu(map_buff->row_cnt)); |
| 2988 | dev_info(&h->pdev->dev, "layout_map_count = %u\n", |
| 2989 | le16_to_cpu(map_buff->layout_map_count)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2990 | dev_info(&h->pdev->dev, "flags = 0x%x\n", |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 2991 | le16_to_cpu(map_buff->flags)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2992 | dev_info(&h->pdev->dev, "encrypytion = %s\n", |
| 2993 | le16_to_cpu(map_buff->flags) & |
| 2994 | RAID_MAP_FLAG_ENCRYPT_ON ? "ON" : "OFF"); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 2995 | dev_info(&h->pdev->dev, "dekindex = %u\n", |
| 2996 | le16_to_cpu(map_buff->dekindex)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2997 | map_cnt = le16_to_cpu(map_buff->layout_map_count); |
| 2998 | for (map = 0; map < map_cnt; map++) { |
| 2999 | dev_info(&h->pdev->dev, "Map%u:\n", map); |
| 3000 | row_cnt = le16_to_cpu(map_buff->row_cnt); |
| 3001 | for (row = 0; row < row_cnt; row++) { |
| 3002 | dev_info(&h->pdev->dev, " Row%u:\n", row); |
| 3003 | disks_per_row = |
| 3004 | le16_to_cpu(map_buff->data_disks_per_row); |
| 3005 | for (col = 0; col < disks_per_row; col++, dd++) |
| 3006 | dev_info(&h->pdev->dev, |
| 3007 | " D%02u: h=0x%04x xor=%u,%u\n", |
| 3008 | col, dd->ioaccel_handle, |
| 3009 | dd->xor_mult[0], dd->xor_mult[1]); |
| 3010 | disks_per_row = |
| 3011 | le16_to_cpu(map_buff->metadata_disks_per_row); |
| 3012 | for (col = 0; col < disks_per_row; col++, dd++) |
| 3013 | dev_info(&h->pdev->dev, |
| 3014 | " M%02u: h=0x%04x xor=%u,%u\n", |
| 3015 | col, dd->ioaccel_handle, |
| 3016 | dd->xor_mult[0], dd->xor_mult[1]); |
| 3017 | } |
| 3018 | } |
| 3019 | } |
| 3020 | #else |
| 3021 | static void hpsa_debug_map_buff(__attribute__((unused)) struct ctlr_info *h, |
| 3022 | __attribute__((unused)) int rc, |
| 3023 | __attribute__((unused)) struct raid_map_data *map_buff) |
| 3024 | { |
| 3025 | } |
| 3026 | #endif |
| 3027 | |
| 3028 | static int hpsa_get_raid_map(struct ctlr_info *h, |
| 3029 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 3030 | { |
| 3031 | int rc = 0; |
| 3032 | struct CommandList *c; |
| 3033 | struct ErrorInfo *ei; |
| 3034 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3035 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3036 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3037 | if (fill_cmd(c, HPSA_GET_RAID_MAP, h, &this_device->raid_map, |
| 3038 | sizeof(this_device->raid_map), 0, |
| 3039 | scsi3addr, TYPE_CMD)) { |
Robert Elliott | 2dd02d7 | 2015-04-23 09:33:43 -0500 | [diff] [blame] | 3040 | dev_warn(&h->pdev->dev, "hpsa_get_raid_map fill_cmd failed\n"); |
| 3041 | cmd_free(h, c); |
| 3042 | return -1; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3043 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3044 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 3045 | PCI_DMA_FROMDEVICE, NO_TIMEOUT); |
| 3046 | if (rc) |
| 3047 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3048 | ei = c->err_info; |
| 3049 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 3050 | hpsa_scsi_interpret_error(h, c); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3051 | rc = -1; |
| 3052 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3053 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3054 | cmd_free(h, c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3055 | |
| 3056 | /* @todo in the future, dynamically allocate RAID map memory */ |
| 3057 | if (le32_to_cpu(this_device->raid_map.structure_size) > |
| 3058 | sizeof(this_device->raid_map)) { |
| 3059 | dev_warn(&h->pdev->dev, "RAID map size is too large!\n"); |
| 3060 | rc = -1; |
| 3061 | } |
| 3062 | hpsa_debug_map_buff(h, rc, &this_device->raid_map); |
| 3063 | return rc; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3064 | out: |
| 3065 | cmd_free(h, c); |
| 3066 | return rc; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3067 | } |
| 3068 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3069 | static int hpsa_bmic_id_controller(struct ctlr_info *h, |
| 3070 | struct bmic_identify_controller *buf, size_t bufsize) |
| 3071 | { |
| 3072 | int rc = IO_OK; |
| 3073 | struct CommandList *c; |
| 3074 | struct ErrorInfo *ei; |
| 3075 | |
| 3076 | c = cmd_alloc(h); |
| 3077 | |
| 3078 | rc = fill_cmd(c, BMIC_IDENTIFY_CONTROLLER, h, buf, bufsize, |
| 3079 | 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 3080 | if (rc) |
| 3081 | goto out; |
| 3082 | |
| 3083 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 3084 | PCI_DMA_FROMDEVICE, NO_TIMEOUT); |
| 3085 | if (rc) |
| 3086 | goto out; |
| 3087 | ei = c->err_info; |
| 3088 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 3089 | hpsa_scsi_interpret_error(h, c); |
| 3090 | rc = -1; |
| 3091 | } |
| 3092 | out: |
| 3093 | cmd_free(h, c); |
| 3094 | return rc; |
| 3095 | } |
| 3096 | |
| 3097 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3098 | static int hpsa_bmic_id_physical_device(struct ctlr_info *h, |
| 3099 | unsigned char scsi3addr[], u16 bmic_device_index, |
| 3100 | struct bmic_identify_physical_device *buf, size_t bufsize) |
| 3101 | { |
| 3102 | int rc = IO_OK; |
| 3103 | struct CommandList *c; |
| 3104 | struct ErrorInfo *ei; |
| 3105 | |
| 3106 | c = cmd_alloc(h); |
| 3107 | rc = fill_cmd(c, BMIC_IDENTIFY_PHYSICAL_DEVICE, h, buf, bufsize, |
| 3108 | 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 3109 | if (rc) |
| 3110 | goto out; |
| 3111 | |
| 3112 | c->Request.CDB[2] = bmic_device_index & 0xff; |
| 3113 | c->Request.CDB[9] = (bmic_device_index >> 8) & 0xff; |
| 3114 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3115 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE, |
| 3116 | NO_TIMEOUT); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3117 | ei = c->err_info; |
| 3118 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 3119 | hpsa_scsi_interpret_error(h, c); |
| 3120 | rc = -1; |
| 3121 | } |
| 3122 | out: |
| 3123 | cmd_free(h, c); |
| 3124 | return rc; |
| 3125 | } |
| 3126 | |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3127 | static int hpsa_vpd_page_supported(struct ctlr_info *h, |
| 3128 | unsigned char scsi3addr[], u8 page) |
| 3129 | { |
| 3130 | int rc; |
| 3131 | int i; |
| 3132 | int pages; |
| 3133 | unsigned char *buf, bufsize; |
| 3134 | |
| 3135 | buf = kzalloc(256, GFP_KERNEL); |
| 3136 | if (!buf) |
| 3137 | return 0; |
| 3138 | |
| 3139 | /* Get the size of the page list first */ |
| 3140 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 3141 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 3142 | buf, HPSA_VPD_HEADER_SZ); |
| 3143 | if (rc != 0) |
| 3144 | goto exit_unsupported; |
| 3145 | pages = buf[3]; |
| 3146 | if ((pages + HPSA_VPD_HEADER_SZ) <= 255) |
| 3147 | bufsize = pages + HPSA_VPD_HEADER_SZ; |
| 3148 | else |
| 3149 | bufsize = 255; |
| 3150 | |
| 3151 | /* Get the whole VPD page list */ |
| 3152 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 3153 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 3154 | buf, bufsize); |
| 3155 | if (rc != 0) |
| 3156 | goto exit_unsupported; |
| 3157 | |
| 3158 | pages = buf[3]; |
| 3159 | for (i = 1; i <= pages; i++) |
| 3160 | if (buf[3 + i] == page) |
| 3161 | goto exit_supported; |
| 3162 | exit_unsupported: |
| 3163 | kfree(buf); |
| 3164 | return 0; |
| 3165 | exit_supported: |
| 3166 | kfree(buf); |
| 3167 | return 1; |
| 3168 | } |
| 3169 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3170 | static void hpsa_get_ioaccel_status(struct ctlr_info *h, |
| 3171 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 3172 | { |
| 3173 | int rc; |
| 3174 | unsigned char *buf; |
| 3175 | u8 ioaccel_status; |
| 3176 | |
| 3177 | this_device->offload_config = 0; |
| 3178 | this_device->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3179 | this_device->offload_to_be_enabled = 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3180 | |
| 3181 | buf = kzalloc(64, GFP_KERNEL); |
| 3182 | if (!buf) |
| 3183 | return; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3184 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_IOACCEL_STATUS)) |
| 3185 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3186 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 3187 | VPD_PAGE | HPSA_VPD_LV_IOACCEL_STATUS, buf, 64); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3188 | if (rc != 0) |
| 3189 | goto out; |
| 3190 | |
| 3191 | #define IOACCEL_STATUS_BYTE 4 |
| 3192 | #define OFFLOAD_CONFIGURED_BIT 0x01 |
| 3193 | #define OFFLOAD_ENABLED_BIT 0x02 |
| 3194 | ioaccel_status = buf[IOACCEL_STATUS_BYTE]; |
| 3195 | this_device->offload_config = |
| 3196 | !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT); |
| 3197 | if (this_device->offload_config) { |
| 3198 | this_device->offload_enabled = |
| 3199 | !!(ioaccel_status & OFFLOAD_ENABLED_BIT); |
| 3200 | if (hpsa_get_raid_map(h, scsi3addr, this_device)) |
| 3201 | this_device->offload_enabled = 0; |
| 3202 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3203 | this_device->offload_to_be_enabled = this_device->offload_enabled; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3204 | out: |
| 3205 | kfree(buf); |
| 3206 | return; |
| 3207 | } |
| 3208 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3209 | /* Get the device id from inquiry page 0x83 */ |
| 3210 | static int hpsa_get_device_id(struct ctlr_info *h, unsigned char *scsi3addr, |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3211 | unsigned char *device_id, int index, int buflen) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3212 | { |
| 3213 | int rc; |
| 3214 | unsigned char *buf; |
| 3215 | |
| 3216 | if (buflen > 16) |
| 3217 | buflen = 16; |
| 3218 | buf = kzalloc(64, GFP_KERNEL); |
| 3219 | if (!buf) |
Stephen M. Cameron | a84d794 | 2014-05-29 10:54:20 -0500 | [diff] [blame] | 3220 | return -ENOMEM; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 3221 | 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] | 3222 | if (rc == 0) |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3223 | memcpy(device_id, &buf[index], buflen); |
| 3224 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3225 | kfree(buf); |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3226 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3227 | return rc != 0; |
| 3228 | } |
| 3229 | |
| 3230 | 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] | 3231 | void *buf, int bufsize, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3232 | int extended_response) |
| 3233 | { |
| 3234 | int rc = IO_OK; |
| 3235 | struct CommandList *c; |
| 3236 | unsigned char scsi3addr[8]; |
| 3237 | struct ErrorInfo *ei; |
| 3238 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3239 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3240 | |
Stephen M. Cameron | e89c0ae | 2010-02-04 08:42:04 -0600 | [diff] [blame] | 3241 | /* address the controller */ |
| 3242 | memset(scsi3addr, 0, sizeof(scsi3addr)); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 3243 | if (fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h, |
| 3244 | buf, bufsize, 0, scsi3addr, TYPE_CMD)) { |
| 3245 | rc = -1; |
| 3246 | goto out; |
| 3247 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3248 | if (extended_response) |
| 3249 | c->Request.CDB[1] = extended_response; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3250 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 3251 | PCI_DMA_FROMDEVICE, NO_TIMEOUT); |
| 3252 | if (rc) |
| 3253 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3254 | ei = c->err_info; |
| 3255 | if (ei->CommandStatus != 0 && |
| 3256 | ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 3257 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3258 | rc = -1; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3259 | } else { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3260 | struct ReportLUNdata *rld = buf; |
| 3261 | |
| 3262 | if (rld->extended_response_flag != extended_response) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3263 | dev_err(&h->pdev->dev, |
| 3264 | "report luns requested format %u, got %u\n", |
| 3265 | extended_response, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3266 | rld->extended_response_flag); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3267 | rc = -1; |
| 3268 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3269 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 3270 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3271 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3272 | return rc; |
| 3273 | } |
| 3274 | |
| 3275 | 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] | 3276 | struct ReportExtendedLUNdata *buf, int bufsize) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3277 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3278 | return hpsa_scsi_do_report_luns(h, 0, buf, bufsize, |
| 3279 | HPSA_REPORT_PHYS_EXTENDED); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | static inline int hpsa_scsi_do_report_log_luns(struct ctlr_info *h, |
| 3283 | struct ReportLUNdata *buf, int bufsize) |
| 3284 | { |
| 3285 | return hpsa_scsi_do_report_luns(h, 1, buf, bufsize, 0); |
| 3286 | } |
| 3287 | |
| 3288 | static inline void hpsa_set_bus_target_lun(struct hpsa_scsi_dev_t *device, |
| 3289 | int bus, int target, int lun) |
| 3290 | { |
| 3291 | device->bus = bus; |
| 3292 | device->target = target; |
| 3293 | device->lun = lun; |
| 3294 | } |
| 3295 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3296 | /* Use VPD inquiry to get details of volume status */ |
| 3297 | static int hpsa_get_volume_status(struct ctlr_info *h, |
| 3298 | unsigned char scsi3addr[]) |
| 3299 | { |
| 3300 | int rc; |
| 3301 | int status; |
| 3302 | int size; |
| 3303 | unsigned char *buf; |
| 3304 | |
| 3305 | buf = kzalloc(64, GFP_KERNEL); |
| 3306 | if (!buf) |
| 3307 | return HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 3308 | |
| 3309 | /* Does controller have VPD for logical volume status? */ |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 3310 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_STATUS)) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3311 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3312 | |
| 3313 | /* Get the size of the VPD return buffer */ |
| 3314 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS, |
| 3315 | buf, HPSA_VPD_HEADER_SZ); |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 3316 | if (rc != 0) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3317 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3318 | size = buf[3]; |
| 3319 | |
| 3320 | /* Now get the whole VPD buffer */ |
| 3321 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS, |
| 3322 | buf, size + HPSA_VPD_HEADER_SZ); |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 3323 | if (rc != 0) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3324 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3325 | status = buf[4]; /* status byte */ |
| 3326 | |
| 3327 | kfree(buf); |
| 3328 | return status; |
| 3329 | exit_failed: |
| 3330 | kfree(buf); |
| 3331 | return HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 3332 | } |
| 3333 | |
| 3334 | /* Determine offline status of a volume. |
| 3335 | * Return either: |
| 3336 | * 0 (not offline) |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3337 | * 0xff (offline for unknown reasons) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3338 | * # (integer code indicating one of several NOT READY states |
| 3339 | * describing why a volume is to be kept offline) |
| 3340 | */ |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3341 | static int hpsa_volume_offline(struct ctlr_info *h, |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3342 | unsigned char scsi3addr[]) |
| 3343 | { |
| 3344 | struct CommandList *c; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 3345 | unsigned char *sense; |
| 3346 | u8 sense_key, asc, ascq; |
| 3347 | int sense_len; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3348 | int rc, ldstat = 0; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3349 | u16 cmd_status; |
| 3350 | u8 scsi_status; |
| 3351 | #define ASC_LUN_NOT_READY 0x04 |
| 3352 | #define ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS 0x04 |
| 3353 | #define ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ 0x02 |
| 3354 | |
| 3355 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3356 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3357 | (void) fill_cmd(c, TEST_UNIT_READY, h, NULL, 0, 0, scsi3addr, TYPE_CMD); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3358 | rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, NO_TIMEOUT); |
| 3359 | if (rc) { |
| 3360 | cmd_free(h, c); |
| 3361 | return 0; |
| 3362 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3363 | sense = c->err_info->SenseInfo; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 3364 | if (c->err_info->SenseLen > sizeof(c->err_info->SenseInfo)) |
| 3365 | sense_len = sizeof(c->err_info->SenseInfo); |
| 3366 | else |
| 3367 | sense_len = c->err_info->SenseLen; |
| 3368 | decode_sense_data(sense, sense_len, &sense_key, &asc, &ascq); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3369 | cmd_status = c->err_info->CommandStatus; |
| 3370 | scsi_status = c->err_info->ScsiStatus; |
| 3371 | cmd_free(h, c); |
| 3372 | /* Is the volume 'not ready'? */ |
| 3373 | if (cmd_status != CMD_TARGET_STATUS || |
| 3374 | scsi_status != SAM_STAT_CHECK_CONDITION || |
| 3375 | sense_key != NOT_READY || |
| 3376 | asc != ASC_LUN_NOT_READY) { |
| 3377 | return 0; |
| 3378 | } |
| 3379 | |
| 3380 | /* Determine the reason for not ready state */ |
| 3381 | ldstat = hpsa_get_volume_status(h, scsi3addr); |
| 3382 | |
| 3383 | /* Keep volume offline in certain cases: */ |
| 3384 | switch (ldstat) { |
| 3385 | case HPSA_LV_UNDERGOING_ERASE: |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 3386 | case HPSA_LV_NOT_AVAILABLE: |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3387 | case HPSA_LV_UNDERGOING_RPI: |
| 3388 | case HPSA_LV_PENDING_RPI: |
| 3389 | case HPSA_LV_ENCRYPTED_NO_KEY: |
| 3390 | case HPSA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER: |
| 3391 | case HPSA_LV_UNDERGOING_ENCRYPTION: |
| 3392 | case HPSA_LV_UNDERGOING_ENCRYPTION_REKEYING: |
| 3393 | case HPSA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: |
| 3394 | return ldstat; |
| 3395 | case HPSA_VPD_LV_STATUS_UNSUPPORTED: |
| 3396 | /* If VPD status page isn't available, |
| 3397 | * use ASC/ASCQ to determine state |
| 3398 | */ |
| 3399 | if ((ascq == ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS) || |
| 3400 | (ascq == ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ)) |
| 3401 | return ldstat; |
| 3402 | break; |
| 3403 | default: |
| 3404 | break; |
| 3405 | } |
| 3406 | return 0; |
| 3407 | } |
| 3408 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3409 | /* |
| 3410 | * Find out if a logical device supports aborts by simply trying one. |
| 3411 | * Smart Array may claim not to support aborts on logical drives, but |
| 3412 | * if a MSA2000 * is connected, the drives on that will be presented |
| 3413 | * by the Smart Array as logical drives, and aborts may be sent to |
| 3414 | * those devices successfully. So the simplest way to find out is |
| 3415 | * to simply try an abort and see how the device responds. |
| 3416 | */ |
| 3417 | static int hpsa_device_supports_aborts(struct ctlr_info *h, |
| 3418 | unsigned char *scsi3addr) |
| 3419 | { |
| 3420 | struct CommandList *c; |
| 3421 | struct ErrorInfo *ei; |
| 3422 | int rc = 0; |
| 3423 | |
| 3424 | u64 tag = (u64) -1; /* bogus tag */ |
| 3425 | |
| 3426 | /* Assume that physical devices support aborts */ |
| 3427 | if (!is_logical_dev_addr_mode(scsi3addr)) |
| 3428 | return 1; |
| 3429 | |
| 3430 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3431 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3432 | (void) fill_cmd(c, HPSA_ABORT_MSG, h, &tag, 0, 0, scsi3addr, TYPE_MSG); |
| 3433 | (void) hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, NO_TIMEOUT); |
| 3434 | /* no unmap needed here because no data xfer. */ |
| 3435 | ei = c->err_info; |
| 3436 | switch (ei->CommandStatus) { |
| 3437 | case CMD_INVALID: |
| 3438 | rc = 0; |
| 3439 | break; |
| 3440 | case CMD_UNABORTABLE: |
| 3441 | case CMD_ABORT_FAILED: |
| 3442 | rc = 1; |
| 3443 | break; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 3444 | case CMD_TMF_STATUS: |
| 3445 | rc = hpsa_evaluate_tmf_status(h, c); |
| 3446 | break; |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3447 | default: |
| 3448 | rc = 0; |
| 3449 | break; |
| 3450 | } |
| 3451 | cmd_free(h, c); |
| 3452 | return rc; |
| 3453 | } |
| 3454 | |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3455 | static void sanitize_inquiry_string(unsigned char *s, int len) |
| 3456 | { |
| 3457 | bool terminated = false; |
| 3458 | |
| 3459 | for (; len > 0; (--len, ++s)) { |
| 3460 | if (*s == 0) |
| 3461 | terminated = true; |
| 3462 | if (terminated || *s < 0x20 || *s > 0x7e) |
| 3463 | *s = ' '; |
| 3464 | } |
| 3465 | } |
| 3466 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3467 | static int hpsa_update_device_info(struct ctlr_info *h, |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3468 | unsigned char scsi3addr[], struct hpsa_scsi_dev_t *this_device, |
| 3469 | unsigned char *is_OBDR_device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3470 | { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3471 | |
| 3472 | #define OBDR_SIG_OFFSET 43 |
| 3473 | #define OBDR_TAPE_SIG "$DR-10" |
| 3474 | #define OBDR_SIG_LEN (sizeof(OBDR_TAPE_SIG) - 1) |
| 3475 | #define OBDR_TAPE_INQ_SIZE (OBDR_SIG_OFFSET + OBDR_SIG_LEN) |
| 3476 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 3477 | unsigned char *inq_buff; |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3478 | unsigned char *obdr_sig; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3479 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3480 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 3481 | inq_buff = kzalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3482 | if (!inq_buff) { |
| 3483 | rc = -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3484 | goto bail_out; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3485 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3486 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3487 | /* Do an inquiry to the device to see what it is. */ |
| 3488 | if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff, |
| 3489 | (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) { |
| 3490 | /* Inquiry failed (msg printed already) */ |
| 3491 | dev_err(&h->pdev->dev, |
| 3492 | "hpsa_update_device_info: inquiry failed\n"); |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3493 | rc = -EIO; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3494 | goto bail_out; |
| 3495 | } |
| 3496 | |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3497 | sanitize_inquiry_string(&inq_buff[8], 8); |
| 3498 | sanitize_inquiry_string(&inq_buff[16], 16); |
| 3499 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3500 | this_device->devtype = (inq_buff[0] & 0x1f); |
| 3501 | memcpy(this_device->scsi3addr, scsi3addr, 8); |
| 3502 | memcpy(this_device->vendor, &inq_buff[8], |
| 3503 | sizeof(this_device->vendor)); |
| 3504 | memcpy(this_device->model, &inq_buff[16], |
| 3505 | sizeof(this_device->model)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3506 | memset(this_device->device_id, 0, |
| 3507 | sizeof(this_device->device_id)); |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3508 | hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3509 | sizeof(this_device->device_id)); |
| 3510 | |
| 3511 | if (this_device->devtype == TYPE_DISK && |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3512 | is_logical_dev_addr_mode(scsi3addr)) { |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3513 | int volume_offline; |
| 3514 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3515 | hpsa_get_raid_level(h, scsi3addr, &this_device->raid_level); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3516 | if (h->fw_support & MISC_FW_RAID_OFFLOAD_BASIC) |
| 3517 | hpsa_get_ioaccel_status(h, scsi3addr, this_device); |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3518 | volume_offline = hpsa_volume_offline(h, scsi3addr); |
| 3519 | if (volume_offline < 0 || volume_offline > 0xff) |
| 3520 | volume_offline = HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 3521 | this_device->volume_offline = volume_offline & 0xff; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3522 | } else { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3523 | this_device->raid_level = RAID_UNKNOWN; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3524 | this_device->offload_config = 0; |
| 3525 | this_device->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3526 | this_device->offload_to_be_enabled = 0; |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 3527 | this_device->hba_ioaccel_enabled = 0; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3528 | this_device->volume_offline = 0; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3529 | this_device->queue_depth = h->nr_cmds; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3530 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3531 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3532 | if (is_OBDR_device) { |
| 3533 | /* See if this is a One-Button-Disaster-Recovery device |
| 3534 | * by looking for "$DR-10" at offset 43 in inquiry data. |
| 3535 | */ |
| 3536 | obdr_sig = &inq_buff[OBDR_SIG_OFFSET]; |
| 3537 | *is_OBDR_device = (this_device->devtype == TYPE_ROM && |
| 3538 | strncmp(obdr_sig, OBDR_TAPE_SIG, |
| 3539 | OBDR_SIG_LEN) == 0); |
| 3540 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3541 | kfree(inq_buff); |
| 3542 | return 0; |
| 3543 | |
| 3544 | bail_out: |
| 3545 | kfree(inq_buff); |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3546 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3549 | static void hpsa_update_device_supports_aborts(struct ctlr_info *h, |
| 3550 | struct hpsa_scsi_dev_t *dev, u8 *scsi3addr) |
| 3551 | { |
| 3552 | unsigned long flags; |
| 3553 | int rc, entry; |
| 3554 | /* |
| 3555 | * See if this device supports aborts. If we already know |
| 3556 | * the device, we already know if it supports aborts, otherwise |
| 3557 | * we have to find out if it supports aborts by trying one. |
| 3558 | */ |
| 3559 | spin_lock_irqsave(&h->devlock, flags); |
| 3560 | rc = hpsa_scsi_find_entry(dev, h->dev, h->ndevices, &entry); |
| 3561 | if ((rc == DEVICE_SAME || rc == DEVICE_UPDATED) && |
| 3562 | entry >= 0 && entry < h->ndevices) { |
| 3563 | dev->supports_aborts = h->dev[entry]->supports_aborts; |
| 3564 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3565 | } else { |
| 3566 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3567 | dev->supports_aborts = |
| 3568 | hpsa_device_supports_aborts(h, scsi3addr); |
| 3569 | if (dev->supports_aborts < 0) |
| 3570 | dev->supports_aborts = 0; |
| 3571 | } |
| 3572 | } |
| 3573 | |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3574 | /* |
| 3575 | * Helper function to assign bus, target, lun mapping of devices. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3576 | * Logical drive target and lun are assigned at this time, but |
| 3577 | * physical device lun and target assignment are deferred (assigned |
| 3578 | * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3579 | */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3580 | static void figure_bus_target_lun(struct ctlr_info *h, |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3581 | u8 *lunaddrbytes, struct hpsa_scsi_dev_t *device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3582 | { |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3583 | u32 lunid = get_unaligned_le32(lunaddrbytes); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3584 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3585 | if (!is_logical_dev_addr_mode(lunaddrbytes)) { |
| 3586 | /* physical device, target and lun filled in later */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3587 | if (is_hba_lunid(lunaddrbytes)) |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3588 | hpsa_set_bus_target_lun(device, |
| 3589 | HPSA_HBA_BUS, 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3590 | else |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3591 | /* defer target, lun assignment for physical devices */ |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3592 | hpsa_set_bus_target_lun(device, |
| 3593 | HPSA_PHYSICAL_DEVICE_BUS, -1, -1); |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3594 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3595 | } |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3596 | /* It's a logical device */ |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3597 | if (device->external) { |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3598 | hpsa_set_bus_target_lun(device, |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3599 | HPSA_EXTERNAL_RAID_VOLUME_BUS, (lunid >> 16) & 0x3fff, |
| 3600 | lunid & 0x00ff); |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3601 | return; |
| 3602 | } |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3603 | hpsa_set_bus_target_lun(device, HPSA_RAID_VOLUME_BUS, |
| 3604 | 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3605 | } |
| 3606 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3607 | |
| 3608 | /* |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3609 | * Get address of physical disk used for an ioaccel2 mode command: |
| 3610 | * 1. Extract ioaccel2 handle from the command. |
| 3611 | * 2. Find a matching ioaccel2 handle from list of physical disks. |
| 3612 | * 3. Return: |
| 3613 | * 1 and set scsi3addr to address of matching physical |
| 3614 | * 0 if no matching physical disk was found. |
| 3615 | */ |
| 3616 | static int hpsa_get_pdisk_of_ioaccel2(struct ctlr_info *h, |
| 3617 | struct CommandList *ioaccel2_cmd_to_abort, unsigned char *scsi3addr) |
| 3618 | { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3619 | struct io_accel2_cmd *c2 = |
| 3620 | &h->ioaccel2_cmd_pool[ioaccel2_cmd_to_abort->cmdindex]; |
| 3621 | unsigned long flags; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3622 | int i; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3623 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3624 | spin_lock_irqsave(&h->devlock, flags); |
| 3625 | for (i = 0; i < h->ndevices; i++) |
| 3626 | if (h->dev[i]->ioaccel_handle == le32_to_cpu(c2->scsi_nexus)) { |
| 3627 | memcpy(scsi3addr, h->dev[i]->scsi3addr, |
| 3628 | sizeof(h->dev[i]->scsi3addr)); |
| 3629 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3630 | return 1; |
| 3631 | } |
| 3632 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3633 | return 0; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3634 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3635 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3636 | static int figure_external_status(struct ctlr_info *h, int raid_ctlr_position, |
| 3637 | int i, int nphysicals, int nlocal_logicals) |
| 3638 | { |
| 3639 | /* In report logicals, local logicals are listed first, |
| 3640 | * then any externals. |
| 3641 | */ |
| 3642 | int logicals_start = nphysicals + (raid_ctlr_position == 0); |
| 3643 | |
| 3644 | if (i == raid_ctlr_position) |
| 3645 | return 0; |
| 3646 | |
| 3647 | if (i < logicals_start) |
| 3648 | return 0; |
| 3649 | |
| 3650 | /* i is in logicals range, but still within local logicals */ |
| 3651 | if ((i - nphysicals - (raid_ctlr_position == 0)) < nlocal_logicals) |
| 3652 | return 0; |
| 3653 | |
| 3654 | return 1; /* it's an external lun */ |
| 3655 | } |
| 3656 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3657 | /* |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3658 | * Do CISS_REPORT_PHYS and CISS_REPORT_LOG. Data is returned in physdev, |
| 3659 | * logdev. The number of luns in physdev and logdev are returned in |
| 3660 | * *nphysicals and *nlogicals, respectively. |
| 3661 | * Returns 0 on success, -1 otherwise. |
| 3662 | */ |
| 3663 | static int hpsa_gather_lun_info(struct ctlr_info *h, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3664 | struct ReportExtendedLUNdata *physdev, u32 *nphysicals, |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 3665 | struct ReportLUNdata *logdev, u32 *nlogicals) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3666 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3667 | if (hpsa_scsi_do_report_phys_luns(h, physdev, sizeof(*physdev))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3668 | dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); |
| 3669 | return -1; |
| 3670 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3671 | *nphysicals = be32_to_cpu(*((__be32 *)physdev->LUNListLength)) / 24; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3672 | if (*nphysicals > HPSA_MAX_PHYS_LUN) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3673 | dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded. %d LUNs ignored.\n", |
| 3674 | HPSA_MAX_PHYS_LUN, *nphysicals - HPSA_MAX_PHYS_LUN); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3675 | *nphysicals = HPSA_MAX_PHYS_LUN; |
| 3676 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3677 | if (hpsa_scsi_do_report_log_luns(h, logdev, sizeof(*logdev))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3678 | dev_err(&h->pdev->dev, "report logical LUNs failed.\n"); |
| 3679 | return -1; |
| 3680 | } |
Stephen M. Cameron | 6df1e95 | 2010-02-04 08:42:19 -0600 | [diff] [blame] | 3681 | *nlogicals = be32_to_cpu(*((__be32 *) logdev->LUNListLength)) / 8; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3682 | /* Reject Logicals in excess of our max capability. */ |
| 3683 | if (*nlogicals > HPSA_MAX_LUN) { |
| 3684 | dev_warn(&h->pdev->dev, |
| 3685 | "maximum logical LUNs (%d) exceeded. " |
| 3686 | "%d LUNs ignored.\n", HPSA_MAX_LUN, |
| 3687 | *nlogicals - HPSA_MAX_LUN); |
| 3688 | *nlogicals = HPSA_MAX_LUN; |
| 3689 | } |
| 3690 | if (*nlogicals + *nphysicals > HPSA_MAX_PHYS_LUN) { |
| 3691 | dev_warn(&h->pdev->dev, |
| 3692 | "maximum logical + physical LUNs (%d) exceeded. " |
| 3693 | "%d LUNs ignored.\n", HPSA_MAX_PHYS_LUN, |
| 3694 | *nphysicals + *nlogicals - HPSA_MAX_PHYS_LUN); |
| 3695 | *nlogicals = HPSA_MAX_PHYS_LUN - *nphysicals; |
| 3696 | } |
| 3697 | return 0; |
| 3698 | } |
| 3699 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 3700 | static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, |
| 3701 | int i, int nphysicals, int nlogicals, |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 3702 | struct ReportExtendedLUNdata *physdev_list, |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3703 | struct ReportLUNdata *logdev_list) |
| 3704 | { |
| 3705 | /* Helper function, figure out where the LUN ID info is coming from |
| 3706 | * given index i, lists of physical and logical devices, where in |
| 3707 | * the list the raid controller is supposed to appear (first or last) |
| 3708 | */ |
| 3709 | |
| 3710 | int logicals_start = nphysicals + (raid_ctlr_position == 0); |
| 3711 | int last_device = nphysicals + nlogicals + (raid_ctlr_position == 0); |
| 3712 | |
| 3713 | if (i == raid_ctlr_position) |
| 3714 | return RAID_CTLR_LUNID; |
| 3715 | |
| 3716 | if (i < logicals_start) |
Stephen M. Cameron | d5b5d96 | 2014-05-29 10:53:34 -0500 | [diff] [blame] | 3717 | return &physdev_list->LUN[i - |
| 3718 | (raid_ctlr_position == 0)].lunid[0]; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3719 | |
| 3720 | if (i < last_device) |
| 3721 | return &logdev_list->LUN[i - nphysicals - |
| 3722 | (raid_ctlr_position == 0)][0]; |
| 3723 | BUG(); |
| 3724 | return NULL; |
| 3725 | } |
| 3726 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3727 | /* get physical drive ioaccel handle and queue depth */ |
| 3728 | static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h, |
| 3729 | struct hpsa_scsi_dev_t *dev, |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3730 | struct ReportExtendedLUNdata *rlep, int rle_index, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3731 | struct bmic_identify_physical_device *id_phys) |
| 3732 | { |
| 3733 | int rc; |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3734 | struct ext_report_lun_entry *rle = &rlep->LUN[rle_index]; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3735 | |
| 3736 | dev->ioaccel_handle = rle->ioaccel_handle; |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3737 | if ((rle->device_flags & 0x08) && dev->ioaccel_handle) |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 3738 | dev->hba_ioaccel_enabled = 1; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3739 | memset(id_phys, 0, sizeof(*id_phys)); |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3740 | rc = hpsa_bmic_id_physical_device(h, &rle->lunid[0], |
| 3741 | GET_BMIC_DRIVE_NUMBER(&rle->lunid[0]), id_phys, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3742 | sizeof(*id_phys)); |
| 3743 | if (!rc) |
| 3744 | /* Reserve space for FW operations */ |
| 3745 | #define DRIVE_CMDS_RESERVED_FOR_FW 2 |
| 3746 | #define DRIVE_QUEUE_DEPTH 7 |
| 3747 | dev->queue_depth = |
| 3748 | le16_to_cpu(id_phys->current_queue_depth_limit) - |
| 3749 | DRIVE_CMDS_RESERVED_FOR_FW; |
| 3750 | else |
| 3751 | dev->queue_depth = DRIVE_QUEUE_DEPTH; /* conservative */ |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3752 | } |
| 3753 | |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 3754 | static void hpsa_get_path_info(struct hpsa_scsi_dev_t *this_device, |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3755 | struct ReportExtendedLUNdata *rlep, int rle_index, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 3756 | struct bmic_identify_physical_device *id_phys) |
| 3757 | { |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3758 | struct ext_report_lun_entry *rle = &rlep->LUN[rle_index]; |
| 3759 | |
| 3760 | if ((rle->device_flags & 0x08) && this_device->ioaccel_handle) |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 3761 | this_device->hba_ioaccel_enabled = 1; |
| 3762 | |
| 3763 | memcpy(&this_device->active_path_index, |
| 3764 | &id_phys->active_path_number, |
| 3765 | sizeof(this_device->active_path_index)); |
| 3766 | memcpy(&this_device->path_map, |
| 3767 | &id_phys->redundant_path_present_map, |
| 3768 | sizeof(this_device->path_map)); |
| 3769 | memcpy(&this_device->box, |
| 3770 | &id_phys->alternate_paths_phys_box_on_port, |
| 3771 | sizeof(this_device->box)); |
| 3772 | memcpy(&this_device->phys_connector, |
| 3773 | &id_phys->alternate_paths_phys_connector, |
| 3774 | sizeof(this_device->phys_connector)); |
| 3775 | memcpy(&this_device->bay, |
| 3776 | &id_phys->phys_bay_in_box, |
| 3777 | sizeof(this_device->bay)); |
| 3778 | } |
| 3779 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3780 | /* get number of local logical disks. */ |
| 3781 | static int hpsa_set_local_logical_count(struct ctlr_info *h, |
| 3782 | struct bmic_identify_controller *id_ctlr, |
| 3783 | u32 *nlocals) |
| 3784 | { |
| 3785 | int rc; |
| 3786 | |
| 3787 | if (!id_ctlr) { |
| 3788 | dev_warn(&h->pdev->dev, "%s: id_ctlr buffer is NULL.\n", |
| 3789 | __func__); |
| 3790 | return -ENOMEM; |
| 3791 | } |
| 3792 | memset(id_ctlr, 0, sizeof(*id_ctlr)); |
| 3793 | rc = hpsa_bmic_id_controller(h, id_ctlr, sizeof(*id_ctlr)); |
| 3794 | if (!rc) |
| 3795 | if (id_ctlr->configured_logical_drive_count < 256) |
| 3796 | *nlocals = id_ctlr->configured_logical_drive_count; |
| 3797 | else |
| 3798 | *nlocals = le16_to_cpu( |
| 3799 | id_ctlr->extended_logical_unit_count); |
| 3800 | else |
| 3801 | *nlocals = -1; |
| 3802 | return rc; |
| 3803 | } |
| 3804 | |
| 3805 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 3806 | static void hpsa_update_scsi_devices(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3807 | { |
| 3808 | /* the idea here is we could get notified |
| 3809 | * that some devices have changed, so we do a report |
| 3810 | * physical luns and report logical luns cmd, and adjust |
| 3811 | * our list of devices accordingly. |
| 3812 | * |
| 3813 | * The scsi3addr's of devices won't change so long as the |
| 3814 | * adapter is not reset. That means we can rescan and |
| 3815 | * tell which devices we already know about, vs. new |
| 3816 | * devices, vs. disappearing devices. |
| 3817 | */ |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 3818 | struct ReportExtendedLUNdata *physdev_list = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3819 | struct ReportLUNdata *logdev_list = NULL; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3820 | struct bmic_identify_physical_device *id_phys = NULL; |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3821 | struct bmic_identify_controller *id_ctlr = NULL; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 3822 | u32 nphysicals = 0; |
| 3823 | u32 nlogicals = 0; |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3824 | u32 nlocal_logicals = 0; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 3825 | u32 ndev_allocated = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3826 | struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; |
| 3827 | int ncurrent = 0; |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3828 | int i, n_ext_target_devs, ndevs_to_allocate; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3829 | int raid_ctlr_position; |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 3830 | bool physical_device; |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 3831 | DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3832 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 3833 | currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | 9208471 | 2014-11-14 17:26:54 -0600 | [diff] [blame] | 3834 | physdev_list = kzalloc(sizeof(*physdev_list), GFP_KERNEL); |
| 3835 | logdev_list = kzalloc(sizeof(*logdev_list), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3836 | tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3837 | id_phys = kzalloc(sizeof(*id_phys), GFP_KERNEL); |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3838 | id_ctlr = kzalloc(sizeof(*id_ctlr), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3839 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3840 | if (!currentsd || !physdev_list || !logdev_list || |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3841 | !tmpdevice || !id_phys || !id_ctlr) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3842 | dev_err(&h->pdev->dev, "out of memory\n"); |
| 3843 | goto out; |
| 3844 | } |
| 3845 | memset(lunzerobits, 0, sizeof(lunzerobits)); |
| 3846 | |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 3847 | h->drv_req_rescan = 0; /* cancel scheduled rescan - we're doing it. */ |
| 3848 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3849 | if (hpsa_gather_lun_info(h, physdev_list, &nphysicals, |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 3850 | logdev_list, &nlogicals)) { |
| 3851 | h->drv_req_rescan = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3852 | goto out; |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 3853 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3854 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3855 | /* Set number of local logicals (non PTRAID) */ |
| 3856 | if (hpsa_set_local_logical_count(h, id_ctlr, &nlocal_logicals)) { |
| 3857 | dev_warn(&h->pdev->dev, |
| 3858 | "%s: Can't determine number of local logical devices.\n", |
| 3859 | __func__); |
| 3860 | } |
| 3861 | |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 3862 | /* We might see up to the maximum number of logical and physical disks |
| 3863 | * plus external target devices, and a device for the local RAID |
| 3864 | * controller. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3865 | */ |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 3866 | ndevs_to_allocate = nphysicals + nlogicals + MAX_EXT_TARGETS + 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3867 | |
| 3868 | /* Allocate the per device structures */ |
| 3869 | for (i = 0; i < ndevs_to_allocate; i++) { |
Scott Teel | b7ec021 | 2011-10-26 16:21:12 -0500 | [diff] [blame] | 3870 | if (i >= HPSA_MAX_DEVICES) { |
| 3871 | dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded." |
| 3872 | " %d devices ignored.\n", HPSA_MAX_DEVICES, |
| 3873 | ndevs_to_allocate - HPSA_MAX_DEVICES); |
| 3874 | break; |
| 3875 | } |
| 3876 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3877 | currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL); |
| 3878 | if (!currentsd[i]) { |
| 3879 | dev_warn(&h->pdev->dev, "out of memory at %s:%d\n", |
| 3880 | __FILE__, __LINE__); |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 3881 | h->drv_req_rescan = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3882 | goto out; |
| 3883 | } |
| 3884 | ndev_allocated++; |
| 3885 | } |
| 3886 | |
Stephen M. Cameron | 8645291 | 2014-05-29 10:53:49 -0500 | [diff] [blame] | 3887 | if (is_scsi_rev_5(h)) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3888 | raid_ctlr_position = 0; |
| 3889 | else |
| 3890 | raid_ctlr_position = nphysicals + nlogicals; |
| 3891 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3892 | /* adjust our table of devices */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 3893 | n_ext_target_devs = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3894 | for (i = 0; i < nphysicals + nlogicals + 1; i++) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3895 | u8 *lunaddrbytes, is_OBDR = 0; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3896 | int rc = 0; |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3897 | int phys_dev_index = i - (raid_ctlr_position == 0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3898 | |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 3899 | physical_device = i < nphysicals + (raid_ctlr_position == 0); |
| 3900 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3901 | /* Figure out where the LUN ID info is coming from */ |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 3902 | lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position, |
| 3903 | i, nphysicals, nlogicals, physdev_list, logdev_list); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3904 | |
| 3905 | /* skip masked non-disk devices */ |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 3906 | if (MASKED_DEVICE(lunaddrbytes) && physical_device && |
| 3907 | (physdev_list->LUN[phys_dev_index].device_flags & 0x01)) |
| 3908 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3909 | |
| 3910 | /* Get device type, vendor, model, device id */ |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3911 | rc = hpsa_update_device_info(h, lunaddrbytes, tmpdevice, |
| 3912 | &is_OBDR); |
| 3913 | if (rc == -ENOMEM) { |
| 3914 | dev_warn(&h->pdev->dev, |
| 3915 | "Out of memory, rescan deferred.\n"); |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 3916 | h->drv_req_rescan = 1; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3917 | goto out; |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 3918 | } |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3919 | if (rc) { |
| 3920 | dev_warn(&h->pdev->dev, |
| 3921 | "Inquiry failed, skipping device.\n"); |
| 3922 | continue; |
| 3923 | } |
| 3924 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3925 | /* Determine if this is a lun from an external target array */ |
| 3926 | tmpdevice->external = |
| 3927 | figure_external_status(h, raid_ctlr_position, i, |
| 3928 | nphysicals, nlocal_logicals); |
| 3929 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3930 | figure_bus_target_lun(h, lunaddrbytes, tmpdevice); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3931 | hpsa_update_device_supports_aborts(h, tmpdevice, lunaddrbytes); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3932 | this_device = currentsd[ncurrent]; |
| 3933 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 3934 | /* Turn on discovery_polling if there are ext target devices. |
| 3935 | * Event-based change notification is unreliable for those. |
| 3936 | */ |
| 3937 | if (!h->discovery_polling) { |
| 3938 | if (tmpdevice->external) { |
| 3939 | h->discovery_polling = 1; |
| 3940 | dev_info(&h->pdev->dev, |
| 3941 | "External target, activate discovery polling.\n"); |
| 3942 | } |
| 3943 | } |
| 3944 | |
| 3945 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3946 | *this_device = *tmpdevice; |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 3947 | this_device->physical_device = physical_device; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3948 | |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 3949 | /* |
| 3950 | * Expose all devices except for physical devices that |
| 3951 | * are masked. |
| 3952 | */ |
| 3953 | if (MASKED_DEVICE(lunaddrbytes) && this_device->physical_device) |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 3954 | this_device->expose_device = 0; |
| 3955 | else |
| 3956 | this_device->expose_device = 1; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3957 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3958 | switch (this_device->devtype) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3959 | case TYPE_ROM: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3960 | /* We don't *really* support actual CD-ROM devices, |
| 3961 | * just "One Button Disaster Recovery" tape drive |
| 3962 | * which temporarily pretends to be a CD-ROM drive. |
| 3963 | * So we check that the device is really an OBDR tape |
| 3964 | * device by checking for "$DR-10" in bytes 43-48 of |
| 3965 | * the inquiry data. |
| 3966 | */ |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3967 | if (is_OBDR) |
| 3968 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3969 | break; |
| 3970 | case TYPE_DISK: |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 3971 | if (this_device->physical_device) { |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 3972 | /* The disk is in HBA mode. */ |
| 3973 | /* Never use RAID mapper in HBA mode. */ |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 3974 | this_device->offload_enabled = 0; |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 3975 | hpsa_get_ioaccel_drive_info(h, this_device, |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 3976 | physdev_list, phys_dev_index, id_phys); |
| 3977 | hpsa_get_path_info(this_device, |
| 3978 | physdev_list, phys_dev_index, id_phys); |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 3979 | } |
Joe Handzik | ecf418d1 | 2015-04-23 09:33:04 -0500 | [diff] [blame] | 3980 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3981 | break; |
| 3982 | case TYPE_TAPE: |
| 3983 | case TYPE_MEDIUM_CHANGER: |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3984 | case TYPE_ENCLOSURE: |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 3985 | ncurrent++; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3986 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3987 | case TYPE_RAID: |
| 3988 | /* Only present the Smartarray HBA as a RAID controller. |
| 3989 | * If it's a RAID controller other than the HBA itself |
| 3990 | * (an external RAID controller, MSA500 or similar) |
| 3991 | * don't present it. |
| 3992 | */ |
| 3993 | if (!is_hba_lunid(lunaddrbytes)) |
| 3994 | break; |
| 3995 | ncurrent++; |
| 3996 | break; |
| 3997 | default: |
| 3998 | break; |
| 3999 | } |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 4000 | if (ncurrent >= HPSA_MAX_DEVICES) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4001 | break; |
| 4002 | } |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 4003 | adjust_hpsa_scsi_table(h, currentsd, ncurrent); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4004 | out: |
| 4005 | kfree(tmpdevice); |
| 4006 | for (i = 0; i < ndev_allocated; i++) |
| 4007 | kfree(currentsd[i]); |
| 4008 | kfree(currentsd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4009 | kfree(physdev_list); |
| 4010 | kfree(logdev_list); |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4011 | kfree(id_ctlr); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4012 | kfree(id_phys); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4013 | } |
| 4014 | |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4015 | static void hpsa_set_sg_descriptor(struct SGDescriptor *desc, |
| 4016 | struct scatterlist *sg) |
| 4017 | { |
| 4018 | u64 addr64 = (u64) sg_dma_address(sg); |
| 4019 | unsigned int len = sg_dma_len(sg); |
| 4020 | |
| 4021 | desc->Addr = cpu_to_le64(addr64); |
| 4022 | desc->Len = cpu_to_le32(len); |
| 4023 | desc->Ext = 0; |
| 4024 | } |
| 4025 | |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 4026 | /* |
| 4027 | * 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] | 4028 | * dma mapping and fills in the scatter gather entries of the |
| 4029 | * hpsa command, cp. |
| 4030 | */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4031 | static int hpsa_scatter_gather(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4032 | struct CommandList *cp, |
| 4033 | struct scsi_cmnd *cmd) |
| 4034 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4035 | struct scatterlist *sg; |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4036 | int use_sg, i, sg_limit, chained, last_sg; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4037 | struct SGDescriptor *curr_sg; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4038 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4039 | BUG_ON(scsi_sg_count(cmd) > h->maxsgentries); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4040 | |
| 4041 | use_sg = scsi_dma_map(cmd); |
| 4042 | if (use_sg < 0) |
| 4043 | return use_sg; |
| 4044 | |
| 4045 | if (!use_sg) |
| 4046 | goto sglist_finished; |
| 4047 | |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4048 | /* |
| 4049 | * If the number of entries is greater than the max for a single list, |
| 4050 | * then we have a chained list; we will set up all but one entry in the |
| 4051 | * first list (the last entry is saved for link information); |
| 4052 | * otherwise, we don't have a chained list and we'll set up at each of |
| 4053 | * the entries in the one list. |
| 4054 | */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4055 | curr_sg = cp->SG; |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4056 | chained = use_sg > h->max_cmd_sg_entries; |
| 4057 | sg_limit = chained ? h->max_cmd_sg_entries - 1 : use_sg; |
| 4058 | last_sg = scsi_sg_count(cmd) - 1; |
| 4059 | scsi_for_each_sg(cmd, sg, sg_limit, i) { |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4060 | hpsa_set_sg_descriptor(curr_sg, sg); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4061 | curr_sg++; |
| 4062 | } |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4063 | |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4064 | if (chained) { |
| 4065 | /* |
| 4066 | * Continue with the chained list. Set curr_sg to the chained |
| 4067 | * list. Modify the limit to the total count less the entries |
| 4068 | * we've already set up. Resume the scan at the list entry |
| 4069 | * where the previous loop left off. |
| 4070 | */ |
| 4071 | curr_sg = h->cmd_sg_list[cp->cmdindex]; |
| 4072 | sg_limit = use_sg - sg_limit; |
| 4073 | for_each_sg(sg, sg, sg_limit, i) { |
| 4074 | hpsa_set_sg_descriptor(curr_sg, sg); |
| 4075 | curr_sg++; |
| 4076 | } |
| 4077 | } |
| 4078 | |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4079 | /* Back the pointer up to the last entry and mark it as "last". */ |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4080 | (curr_sg - 1)->Ext = cpu_to_le32(HPSA_SG_LAST); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4081 | |
| 4082 | if (use_sg + chained > h->maxSG) |
| 4083 | h->maxSG = use_sg + chained; |
| 4084 | |
| 4085 | if (chained) { |
| 4086 | cp->Header.SGList = h->max_cmd_sg_entries; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4087 | cp->Header.SGTotal = cpu_to_le16(use_sg + 1); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 4088 | if (hpsa_map_sg_chain_block(h, cp)) { |
| 4089 | scsi_dma_unmap(cmd); |
| 4090 | return -1; |
| 4091 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4092 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | sglist_finished: |
| 4096 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4097 | cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */ |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 4098 | 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] | 4099 | return 0; |
| 4100 | } |
| 4101 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4102 | #define IO_ACCEL_INELIGIBLE (1) |
| 4103 | static int fixup_ioaccel_cdb(u8 *cdb, int *cdb_len) |
| 4104 | { |
| 4105 | int is_write = 0; |
| 4106 | u32 block; |
| 4107 | u32 block_cnt; |
| 4108 | |
| 4109 | /* Perform some CDB fixups if needed using 10 byte reads/writes only */ |
| 4110 | switch (cdb[0]) { |
| 4111 | case WRITE_6: |
| 4112 | case WRITE_12: |
| 4113 | is_write = 1; |
| 4114 | case READ_6: |
| 4115 | case READ_12: |
| 4116 | if (*cdb_len == 6) { |
Don Brace | c8a6c9a | 2015-11-04 15:50:50 -0600 | [diff] [blame] | 4117 | block = get_unaligned_be16(&cdb[2]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4118 | block_cnt = cdb[4]; |
Don Brace | c8a6c9a | 2015-11-04 15:50:50 -0600 | [diff] [blame] | 4119 | if (block_cnt == 0) |
| 4120 | block_cnt = 256; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4121 | } else { |
| 4122 | BUG_ON(*cdb_len != 12); |
Don Brace | c8a6c9a | 2015-11-04 15:50:50 -0600 | [diff] [blame] | 4123 | block = get_unaligned_be32(&cdb[2]); |
| 4124 | block_cnt = get_unaligned_be32(&cdb[6]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4125 | } |
| 4126 | if (block_cnt > 0xffff) |
| 4127 | return IO_ACCEL_INELIGIBLE; |
| 4128 | |
| 4129 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 4130 | cdb[1] = 0; |
| 4131 | cdb[2] = (u8) (block >> 24); |
| 4132 | cdb[3] = (u8) (block >> 16); |
| 4133 | cdb[4] = (u8) (block >> 8); |
| 4134 | cdb[5] = (u8) (block); |
| 4135 | cdb[6] = 0; |
| 4136 | cdb[7] = (u8) (block_cnt >> 8); |
| 4137 | cdb[8] = (u8) (block_cnt); |
| 4138 | cdb[9] = 0; |
| 4139 | *cdb_len = 10; |
| 4140 | break; |
| 4141 | } |
| 4142 | return 0; |
| 4143 | } |
| 4144 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4145 | static int hpsa_scsi_ioaccel1_queue_command(struct ctlr_info *h, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4146 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4147 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4148 | { |
| 4149 | struct scsi_cmnd *cmd = c->scsi_cmd; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4150 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 4151 | unsigned int len; |
| 4152 | unsigned int total_len = 0; |
| 4153 | struct scatterlist *sg; |
| 4154 | u64 addr64; |
| 4155 | int use_sg, i; |
| 4156 | struct SGDescriptor *curr_sg; |
| 4157 | u32 control = IOACCEL1_CONTROL_SIMPLEQUEUE; |
| 4158 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4159 | /* TODO: implement chaining support */ |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4160 | if (scsi_sg_count(cmd) > h->ioaccel_maxsg) { |
| 4161 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4162 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4163 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4164 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4165 | BUG_ON(cmd->cmd_len > IOACCEL1_IOFLAGS_CDBLEN_MAX); |
| 4166 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4167 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) { |
| 4168 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4169 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4170 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4171 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4172 | c->cmd_type = CMD_IOACCEL1; |
| 4173 | |
| 4174 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 4175 | c->busaddr = (u32) h->ioaccel_cmd_pool_dhandle + |
| 4176 | (c->cmdindex * sizeof(*cp)); |
| 4177 | BUG_ON(c->busaddr & 0x0000007F); |
| 4178 | |
| 4179 | use_sg = scsi_dma_map(cmd); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4180 | if (use_sg < 0) { |
| 4181 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4182 | return use_sg; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4183 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4184 | |
| 4185 | if (use_sg) { |
| 4186 | curr_sg = cp->SG; |
| 4187 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 4188 | addr64 = (u64) sg_dma_address(sg); |
| 4189 | len = sg_dma_len(sg); |
| 4190 | total_len += len; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4191 | curr_sg->Addr = cpu_to_le64(addr64); |
| 4192 | curr_sg->Len = cpu_to_le32(len); |
| 4193 | curr_sg->Ext = cpu_to_le32(0); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4194 | curr_sg++; |
| 4195 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4196 | (--curr_sg)->Ext = cpu_to_le32(HPSA_SG_LAST); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4197 | |
| 4198 | switch (cmd->sc_data_direction) { |
| 4199 | case DMA_TO_DEVICE: |
| 4200 | control |= IOACCEL1_CONTROL_DATA_OUT; |
| 4201 | break; |
| 4202 | case DMA_FROM_DEVICE: |
| 4203 | control |= IOACCEL1_CONTROL_DATA_IN; |
| 4204 | break; |
| 4205 | case DMA_NONE: |
| 4206 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 4207 | break; |
| 4208 | default: |
| 4209 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 4210 | cmd->sc_data_direction); |
| 4211 | BUG(); |
| 4212 | break; |
| 4213 | } |
| 4214 | } else { |
| 4215 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 4216 | } |
| 4217 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4218 | c->Header.SGList = use_sg; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4219 | /* Fill out the command structure to submit */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4220 | cp->dev_handle = cpu_to_le16(ioaccel_handle & 0xFFFF); |
| 4221 | cp->transfer_len = cpu_to_le32(total_len); |
| 4222 | cp->io_flags = cpu_to_le16(IOACCEL1_IOFLAGS_IO_REQ | |
| 4223 | (cdb_len & IOACCEL1_IOFLAGS_CDBLEN_MASK)); |
| 4224 | cp->control = cpu_to_le32(control); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4225 | memcpy(cp->CDB, cdb, cdb_len); |
| 4226 | memcpy(cp->CISS_LUN, scsi3addr, 8); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4227 | /* Tag was already set at init time. */ |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4228 | enqueue_cmd_and_start_io(h, c); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4229 | return 0; |
| 4230 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4231 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4232 | /* |
| 4233 | * Queue a command directly to a device behind the controller using the |
| 4234 | * I/O accelerator path. |
| 4235 | */ |
| 4236 | static int hpsa_scsi_ioaccel_direct_map(struct ctlr_info *h, |
| 4237 | struct CommandList *c) |
| 4238 | { |
| 4239 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4240 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4241 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4242 | c->phys_disk = dev; |
| 4243 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4244 | return hpsa_scsi_ioaccel_queue_command(h, c, dev->ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4245 | cmd->cmnd, cmd->cmd_len, dev->scsi3addr, dev); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4246 | } |
| 4247 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4248 | /* |
| 4249 | * Set encryption parameters for the ioaccel2 request |
| 4250 | */ |
| 4251 | static void set_encrypt_ioaccel2(struct ctlr_info *h, |
| 4252 | struct CommandList *c, struct io_accel2_cmd *cp) |
| 4253 | { |
| 4254 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4255 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4256 | struct raid_map_data *map = &dev->raid_map; |
| 4257 | u64 first_block; |
| 4258 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4259 | /* Are we doing encryption on this device */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4260 | if (!(le16_to_cpu(map->flags) & RAID_MAP_FLAG_ENCRYPT_ON)) |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4261 | return; |
| 4262 | /* Set the data encryption key index. */ |
| 4263 | cp->dekindex = map->dekindex; |
| 4264 | |
| 4265 | /* Set the encryption enable flag, encoded into direction field. */ |
| 4266 | cp->direction |= IOACCEL2_DIRECTION_ENCRYPT_MASK; |
| 4267 | |
| 4268 | /* Set encryption tweak values based on logical block address |
| 4269 | * If block size is 512, tweak value is LBA. |
| 4270 | * For other block sizes, tweak is (LBA * block size)/ 512) |
| 4271 | */ |
| 4272 | switch (cmd->cmnd[0]) { |
| 4273 | /* Required? 6-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 4274 | case WRITE_6: |
| 4275 | case READ_6: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4276 | first_block = get_unaligned_be16(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4277 | break; |
| 4278 | case WRITE_10: |
| 4279 | case READ_10: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4280 | /* Required? 12-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 4281 | case WRITE_12: |
| 4282 | case READ_12: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4283 | first_block = get_unaligned_be32(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4284 | break; |
| 4285 | case WRITE_16: |
| 4286 | case READ_16: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4287 | first_block = get_unaligned_be64(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4288 | break; |
| 4289 | default: |
| 4290 | dev_err(&h->pdev->dev, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4291 | "ERROR: %s: size (0x%x) not supported for encryption\n", |
| 4292 | __func__, cmd->cmnd[0]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4293 | BUG(); |
| 4294 | break; |
| 4295 | } |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4296 | |
| 4297 | if (le32_to_cpu(map->volume_blk_size) != 512) |
| 4298 | first_block = first_block * |
| 4299 | le32_to_cpu(map->volume_blk_size)/512; |
| 4300 | |
| 4301 | cp->tweak_lower = cpu_to_le32(first_block); |
| 4302 | cp->tweak_upper = cpu_to_le32(first_block >> 32); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4303 | } |
| 4304 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4305 | static int hpsa_scsi_ioaccel2_queue_command(struct ctlr_info *h, |
| 4306 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4307 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4308 | { |
| 4309 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4310 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 4311 | struct ioaccel2_sg_element *curr_sg; |
| 4312 | int use_sg, i; |
| 4313 | struct scatterlist *sg; |
| 4314 | u64 addr64; |
| 4315 | u32 len; |
| 4316 | u32 total_len = 0; |
| 4317 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4318 | BUG_ON(scsi_sg_count(cmd) > h->maxsgentries); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4319 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4320 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) { |
| 4321 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4322 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4323 | } |
| 4324 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4325 | c->cmd_type = CMD_IOACCEL2; |
| 4326 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 4327 | c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle + |
| 4328 | (c->cmdindex * sizeof(*cp)); |
| 4329 | BUG_ON(c->busaddr & 0x0000007F); |
| 4330 | |
| 4331 | memset(cp, 0, sizeof(*cp)); |
| 4332 | cp->IU_type = IOACCEL2_IU_TYPE; |
| 4333 | |
| 4334 | use_sg = scsi_dma_map(cmd); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4335 | if (use_sg < 0) { |
| 4336 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4337 | return use_sg; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4338 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4339 | |
| 4340 | if (use_sg) { |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4341 | curr_sg = cp->sg; |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4342 | if (use_sg > h->ioaccel_maxsg) { |
| 4343 | addr64 = le64_to_cpu( |
| 4344 | h->ioaccel2_cmd_sg_list[c->cmdindex]->address); |
| 4345 | curr_sg->address = cpu_to_le64(addr64); |
| 4346 | curr_sg->length = 0; |
| 4347 | curr_sg->reserved[0] = 0; |
| 4348 | curr_sg->reserved[1] = 0; |
| 4349 | curr_sg->reserved[2] = 0; |
| 4350 | curr_sg->chain_indicator = 0x80; |
| 4351 | |
| 4352 | curr_sg = h->ioaccel2_cmd_sg_list[c->cmdindex]; |
| 4353 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4354 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 4355 | addr64 = (u64) sg_dma_address(sg); |
| 4356 | len = sg_dma_len(sg); |
| 4357 | total_len += len; |
| 4358 | curr_sg->address = cpu_to_le64(addr64); |
| 4359 | curr_sg->length = cpu_to_le32(len); |
| 4360 | curr_sg->reserved[0] = 0; |
| 4361 | curr_sg->reserved[1] = 0; |
| 4362 | curr_sg->reserved[2] = 0; |
| 4363 | curr_sg->chain_indicator = 0; |
| 4364 | curr_sg++; |
| 4365 | } |
| 4366 | |
| 4367 | switch (cmd->sc_data_direction) { |
| 4368 | case DMA_TO_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4369 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4370 | cp->direction |= IOACCEL2_DIR_DATA_OUT; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4371 | break; |
| 4372 | case DMA_FROM_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4373 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4374 | cp->direction |= IOACCEL2_DIR_DATA_IN; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4375 | break; |
| 4376 | case DMA_NONE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4377 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4378 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4379 | break; |
| 4380 | default: |
| 4381 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 4382 | cmd->sc_data_direction); |
| 4383 | BUG(); |
| 4384 | break; |
| 4385 | } |
| 4386 | } else { |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4387 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4388 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4389 | } |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4390 | |
| 4391 | /* Set encryption parameters, if necessary */ |
| 4392 | set_encrypt_ioaccel2(h, c, cp); |
| 4393 | |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4394 | cp->scsi_nexus = cpu_to_le32(ioaccel_handle); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 4395 | cp->Tag = cpu_to_le32(c->cmdindex << DIRECT_LOOKUP_SHIFT); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4396 | memcpy(cp->cdb, cdb, sizeof(cp->cdb)); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4397 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4398 | cp->data_len = cpu_to_le32(total_len); |
| 4399 | cp->err_ptr = cpu_to_le64(c->busaddr + |
| 4400 | offsetof(struct io_accel2_cmd, error_data)); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4401 | cp->err_len = cpu_to_le32(sizeof(cp->error_data)); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4402 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4403 | /* fill in sg elements */ |
| 4404 | if (use_sg > h->ioaccel_maxsg) { |
| 4405 | cp->sg_count = 1; |
Don Brace | a736e9b | 2015-11-04 15:51:14 -0600 | [diff] [blame] | 4406 | cp->sg[0].length = cpu_to_le32(use_sg * sizeof(cp->sg[0])); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4407 | if (hpsa_map_ioaccel2_sg_chain_block(h, cp, c)) { |
| 4408 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
| 4409 | scsi_dma_unmap(cmd); |
| 4410 | return -1; |
| 4411 | } |
| 4412 | } else |
| 4413 | cp->sg_count = (u8) use_sg; |
| 4414 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4415 | enqueue_cmd_and_start_io(h, c); |
| 4416 | return 0; |
| 4417 | } |
| 4418 | |
| 4419 | /* |
| 4420 | * Queue a command to the correct I/O accelerator path. |
| 4421 | */ |
| 4422 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 4423 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4424 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4425 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4426 | /* Try to honor the device's queue depth */ |
| 4427 | if (atomic_inc_return(&phys_disk->ioaccel_cmds_out) > |
| 4428 | phys_disk->queue_depth) { |
| 4429 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
| 4430 | return IO_ACCEL_INELIGIBLE; |
| 4431 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4432 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 4433 | return hpsa_scsi_ioaccel1_queue_command(h, c, ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4434 | cdb, cdb_len, scsi3addr, |
| 4435 | phys_disk); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4436 | else |
| 4437 | return hpsa_scsi_ioaccel2_queue_command(h, c, ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4438 | cdb, cdb_len, scsi3addr, |
| 4439 | phys_disk); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4440 | } |
| 4441 | |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4442 | static void raid_map_helper(struct raid_map_data *map, |
| 4443 | int offload_to_mirror, u32 *map_index, u32 *current_group) |
| 4444 | { |
| 4445 | if (offload_to_mirror == 0) { |
| 4446 | /* use physical disk in the first mirrored group. */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4447 | *map_index %= le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4448 | return; |
| 4449 | } |
| 4450 | do { |
| 4451 | /* determine mirror group that *map_index indicates */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4452 | *current_group = *map_index / |
| 4453 | le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4454 | if (offload_to_mirror == *current_group) |
| 4455 | continue; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4456 | if (*current_group < le16_to_cpu(map->layout_map_count) - 1) { |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4457 | /* select map index from next group */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4458 | *map_index += le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4459 | (*current_group)++; |
| 4460 | } else { |
| 4461 | /* select map index from first group */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4462 | *map_index %= le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4463 | *current_group = 0; |
| 4464 | } |
| 4465 | } while (offload_to_mirror != *current_group); |
| 4466 | } |
| 4467 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4468 | /* |
| 4469 | * Attempt to perform offload RAID mapping for a logical volume I/O. |
| 4470 | */ |
| 4471 | static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h, |
| 4472 | struct CommandList *c) |
| 4473 | { |
| 4474 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4475 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4476 | struct raid_map_data *map = &dev->raid_map; |
| 4477 | struct raid_map_disk_data *dd = &map->data[0]; |
| 4478 | int is_write = 0; |
| 4479 | u32 map_index; |
| 4480 | u64 first_block, last_block; |
| 4481 | u32 block_cnt; |
| 4482 | u32 blocks_per_row; |
| 4483 | u64 first_row, last_row; |
| 4484 | u32 first_row_offset, last_row_offset; |
| 4485 | u32 first_column, last_column; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4486 | u64 r0_first_row, r0_last_row; |
| 4487 | u32 r5or6_blocks_per_row; |
| 4488 | u64 r5or6_first_row, r5or6_last_row; |
| 4489 | u32 r5or6_first_row_offset, r5or6_last_row_offset; |
| 4490 | u32 r5or6_first_column, r5or6_last_column; |
| 4491 | u32 total_disks_per_row; |
| 4492 | u32 stripesize; |
| 4493 | u32 first_group, last_group, current_group; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4494 | u32 map_row; |
| 4495 | u32 disk_handle; |
| 4496 | u64 disk_block; |
| 4497 | u32 disk_block_cnt; |
| 4498 | u8 cdb[16]; |
| 4499 | u8 cdb_len; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4500 | u16 strip_size; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4501 | #if BITS_PER_LONG == 32 |
| 4502 | u64 tmpdiv; |
| 4503 | #endif |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4504 | int offload_to_mirror; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4505 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4506 | /* check for valid opcode, get LBA and block count */ |
| 4507 | switch (cmd->cmnd[0]) { |
| 4508 | case WRITE_6: |
| 4509 | is_write = 1; |
| 4510 | case READ_6: |
Don Brace | c8a6c9a | 2015-11-04 15:50:50 -0600 | [diff] [blame] | 4511 | first_block = get_unaligned_be16(&cmd->cmnd[2]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4512 | block_cnt = cmd->cmnd[4]; |
Stephen M. Cameron | 3fa89a0 | 2014-07-03 10:18:14 -0500 | [diff] [blame] | 4513 | if (block_cnt == 0) |
| 4514 | block_cnt = 256; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4515 | break; |
| 4516 | case WRITE_10: |
| 4517 | is_write = 1; |
| 4518 | case READ_10: |
| 4519 | first_block = |
| 4520 | (((u64) cmd->cmnd[2]) << 24) | |
| 4521 | (((u64) cmd->cmnd[3]) << 16) | |
| 4522 | (((u64) cmd->cmnd[4]) << 8) | |
| 4523 | cmd->cmnd[5]; |
| 4524 | block_cnt = |
| 4525 | (((u32) cmd->cmnd[7]) << 8) | |
| 4526 | cmd->cmnd[8]; |
| 4527 | break; |
| 4528 | case WRITE_12: |
| 4529 | is_write = 1; |
| 4530 | case READ_12: |
| 4531 | first_block = |
| 4532 | (((u64) cmd->cmnd[2]) << 24) | |
| 4533 | (((u64) cmd->cmnd[3]) << 16) | |
| 4534 | (((u64) cmd->cmnd[4]) << 8) | |
| 4535 | cmd->cmnd[5]; |
| 4536 | block_cnt = |
| 4537 | (((u32) cmd->cmnd[6]) << 24) | |
| 4538 | (((u32) cmd->cmnd[7]) << 16) | |
| 4539 | (((u32) cmd->cmnd[8]) << 8) | |
| 4540 | cmd->cmnd[9]; |
| 4541 | break; |
| 4542 | case WRITE_16: |
| 4543 | is_write = 1; |
| 4544 | case READ_16: |
| 4545 | first_block = |
| 4546 | (((u64) cmd->cmnd[2]) << 56) | |
| 4547 | (((u64) cmd->cmnd[3]) << 48) | |
| 4548 | (((u64) cmd->cmnd[4]) << 40) | |
| 4549 | (((u64) cmd->cmnd[5]) << 32) | |
| 4550 | (((u64) cmd->cmnd[6]) << 24) | |
| 4551 | (((u64) cmd->cmnd[7]) << 16) | |
| 4552 | (((u64) cmd->cmnd[8]) << 8) | |
| 4553 | cmd->cmnd[9]; |
| 4554 | block_cnt = |
| 4555 | (((u32) cmd->cmnd[10]) << 24) | |
| 4556 | (((u32) cmd->cmnd[11]) << 16) | |
| 4557 | (((u32) cmd->cmnd[12]) << 8) | |
| 4558 | cmd->cmnd[13]; |
| 4559 | break; |
| 4560 | default: |
| 4561 | return IO_ACCEL_INELIGIBLE; /* process via normal I/O path */ |
| 4562 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4563 | last_block = first_block + block_cnt - 1; |
| 4564 | |
| 4565 | /* check for write to non-RAID-0 */ |
| 4566 | if (is_write && dev->raid_level != 0) |
| 4567 | return IO_ACCEL_INELIGIBLE; |
| 4568 | |
| 4569 | /* check for invalid block or wraparound */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4570 | if (last_block >= le64_to_cpu(map->volume_blk_cnt) || |
| 4571 | last_block < first_block) |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4572 | return IO_ACCEL_INELIGIBLE; |
| 4573 | |
| 4574 | /* calculate stripe information for the request */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4575 | blocks_per_row = le16_to_cpu(map->data_disks_per_row) * |
| 4576 | le16_to_cpu(map->strip_size); |
| 4577 | strip_size = le16_to_cpu(map->strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4578 | #if BITS_PER_LONG == 32 |
| 4579 | tmpdiv = first_block; |
| 4580 | (void) do_div(tmpdiv, blocks_per_row); |
| 4581 | first_row = tmpdiv; |
| 4582 | tmpdiv = last_block; |
| 4583 | (void) do_div(tmpdiv, blocks_per_row); |
| 4584 | last_row = tmpdiv; |
| 4585 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 4586 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
| 4587 | tmpdiv = first_row_offset; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4588 | (void) do_div(tmpdiv, strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4589 | first_column = tmpdiv; |
| 4590 | tmpdiv = last_row_offset; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4591 | (void) do_div(tmpdiv, strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4592 | last_column = tmpdiv; |
| 4593 | #else |
| 4594 | first_row = first_block / blocks_per_row; |
| 4595 | last_row = last_block / blocks_per_row; |
| 4596 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 4597 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4598 | first_column = first_row_offset / strip_size; |
| 4599 | last_column = last_row_offset / strip_size; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4600 | #endif |
| 4601 | |
| 4602 | /* if this isn't a single row/column then give to the controller */ |
| 4603 | if ((first_row != last_row) || (first_column != last_column)) |
| 4604 | return IO_ACCEL_INELIGIBLE; |
| 4605 | |
| 4606 | /* proceeding with driver mapping */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4607 | total_disks_per_row = le16_to_cpu(map->data_disks_per_row) + |
| 4608 | le16_to_cpu(map->metadata_disks_per_row); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4609 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4610 | le16_to_cpu(map->row_cnt); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4611 | map_index = (map_row * total_disks_per_row) + first_column; |
| 4612 | |
| 4613 | switch (dev->raid_level) { |
| 4614 | case HPSA_RAID_0: |
| 4615 | break; /* nothing special to do */ |
| 4616 | case HPSA_RAID_1: |
| 4617 | /* Handles load balance across RAID 1 members. |
| 4618 | * (2-drive R1 and R10 with even # of drives.) |
| 4619 | * Appropriate for SSDs, not optimal for HDDs |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4620 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4621 | BUG_ON(le16_to_cpu(map->layout_map_count) != 2); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4622 | if (dev->offload_to_mirror) |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4623 | map_index += le16_to_cpu(map->data_disks_per_row); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4624 | dev->offload_to_mirror = !dev->offload_to_mirror; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4625 | break; |
| 4626 | case HPSA_RAID_ADM: |
| 4627 | /* Handles N-way mirrors (R1-ADM) |
| 4628 | * and R10 with # of drives divisible by 3.) |
| 4629 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4630 | BUG_ON(le16_to_cpu(map->layout_map_count) != 3); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4631 | |
| 4632 | offload_to_mirror = dev->offload_to_mirror; |
| 4633 | raid_map_helper(map, offload_to_mirror, |
| 4634 | &map_index, ¤t_group); |
| 4635 | /* set mirror group to use next time */ |
| 4636 | offload_to_mirror = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4637 | (offload_to_mirror >= |
| 4638 | le16_to_cpu(map->layout_map_count) - 1) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4639 | ? 0 : offload_to_mirror + 1; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4640 | dev->offload_to_mirror = offload_to_mirror; |
| 4641 | /* Avoid direct use of dev->offload_to_mirror within this |
| 4642 | * function since multiple threads might simultaneously |
| 4643 | * increment it beyond the range of dev->layout_map_count -1. |
| 4644 | */ |
| 4645 | break; |
| 4646 | case HPSA_RAID_5: |
| 4647 | case HPSA_RAID_6: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4648 | if (le16_to_cpu(map->layout_map_count) <= 1) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4649 | break; |
| 4650 | |
| 4651 | /* Verify first and last block are in same RAID group */ |
| 4652 | r5or6_blocks_per_row = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4653 | le16_to_cpu(map->strip_size) * |
| 4654 | le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4655 | BUG_ON(r5or6_blocks_per_row == 0); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4656 | stripesize = r5or6_blocks_per_row * |
| 4657 | le16_to_cpu(map->layout_map_count); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4658 | #if BITS_PER_LONG == 32 |
| 4659 | tmpdiv = first_block; |
| 4660 | first_group = do_div(tmpdiv, stripesize); |
| 4661 | tmpdiv = first_group; |
| 4662 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 4663 | first_group = tmpdiv; |
| 4664 | tmpdiv = last_block; |
| 4665 | last_group = do_div(tmpdiv, stripesize); |
| 4666 | tmpdiv = last_group; |
| 4667 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 4668 | last_group = tmpdiv; |
| 4669 | #else |
| 4670 | first_group = (first_block % stripesize) / r5or6_blocks_per_row; |
| 4671 | last_group = (last_block % stripesize) / r5or6_blocks_per_row; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4672 | #endif |
Stephen M. Cameron | 000ff7c | 2014-03-13 17:12:50 -0500 | [diff] [blame] | 4673 | if (first_group != last_group) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4674 | return IO_ACCEL_INELIGIBLE; |
| 4675 | |
| 4676 | /* Verify request is in a single row of RAID 5/6 */ |
| 4677 | #if BITS_PER_LONG == 32 |
| 4678 | tmpdiv = first_block; |
| 4679 | (void) do_div(tmpdiv, stripesize); |
| 4680 | first_row = r5or6_first_row = r0_first_row = tmpdiv; |
| 4681 | tmpdiv = last_block; |
| 4682 | (void) do_div(tmpdiv, stripesize); |
| 4683 | r5or6_last_row = r0_last_row = tmpdiv; |
| 4684 | #else |
| 4685 | first_row = r5or6_first_row = r0_first_row = |
| 4686 | first_block / stripesize; |
| 4687 | r5or6_last_row = r0_last_row = last_block / stripesize; |
| 4688 | #endif |
| 4689 | if (r5or6_first_row != r5or6_last_row) |
| 4690 | return IO_ACCEL_INELIGIBLE; |
| 4691 | |
| 4692 | |
| 4693 | /* Verify request is in a single column */ |
| 4694 | #if BITS_PER_LONG == 32 |
| 4695 | tmpdiv = first_block; |
| 4696 | first_row_offset = do_div(tmpdiv, stripesize); |
| 4697 | tmpdiv = first_row_offset; |
| 4698 | first_row_offset = (u32) do_div(tmpdiv, r5or6_blocks_per_row); |
| 4699 | r5or6_first_row_offset = first_row_offset; |
| 4700 | tmpdiv = last_block; |
| 4701 | r5or6_last_row_offset = do_div(tmpdiv, stripesize); |
| 4702 | tmpdiv = r5or6_last_row_offset; |
| 4703 | r5or6_last_row_offset = do_div(tmpdiv, r5or6_blocks_per_row); |
| 4704 | tmpdiv = r5or6_first_row_offset; |
| 4705 | (void) do_div(tmpdiv, map->strip_size); |
| 4706 | first_column = r5or6_first_column = tmpdiv; |
| 4707 | tmpdiv = r5or6_last_row_offset; |
| 4708 | (void) do_div(tmpdiv, map->strip_size); |
| 4709 | r5or6_last_column = tmpdiv; |
| 4710 | #else |
| 4711 | first_row_offset = r5or6_first_row_offset = |
| 4712 | (u32)((first_block % stripesize) % |
| 4713 | r5or6_blocks_per_row); |
| 4714 | |
| 4715 | r5or6_last_row_offset = |
| 4716 | (u32)((last_block % stripesize) % |
| 4717 | r5or6_blocks_per_row); |
| 4718 | |
| 4719 | first_column = r5or6_first_column = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4720 | r5or6_first_row_offset / le16_to_cpu(map->strip_size); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4721 | r5or6_last_column = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4722 | r5or6_last_row_offset / le16_to_cpu(map->strip_size); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4723 | #endif |
| 4724 | if (r5or6_first_column != r5or6_last_column) |
| 4725 | return IO_ACCEL_INELIGIBLE; |
| 4726 | |
| 4727 | /* Request is eligible */ |
| 4728 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4729 | le16_to_cpu(map->row_cnt); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4730 | |
| 4731 | map_index = (first_group * |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4732 | (le16_to_cpu(map->row_cnt) * total_disks_per_row)) + |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4733 | (map_row * total_disks_per_row) + first_column; |
| 4734 | break; |
| 4735 | default: |
| 4736 | return IO_ACCEL_INELIGIBLE; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4737 | } |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4738 | |
Stephen Cameron | 07543e0 | 2015-01-23 16:44:14 -0600 | [diff] [blame] | 4739 | if (unlikely(map_index >= RAID_MAP_MAX_ENTRIES)) |
| 4740 | return IO_ACCEL_INELIGIBLE; |
| 4741 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4742 | c->phys_disk = dev->phys_disk[map_index]; |
| 4743 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4744 | disk_handle = dd[map_index].ioaccel_handle; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4745 | disk_block = le64_to_cpu(map->disk_starting_blk) + |
| 4746 | first_row * le16_to_cpu(map->strip_size) + |
| 4747 | (first_row_offset - first_column * |
| 4748 | le16_to_cpu(map->strip_size)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4749 | disk_block_cnt = block_cnt; |
| 4750 | |
| 4751 | /* handle differing logical/physical block sizes */ |
| 4752 | if (map->phys_blk_shift) { |
| 4753 | disk_block <<= map->phys_blk_shift; |
| 4754 | disk_block_cnt <<= map->phys_blk_shift; |
| 4755 | } |
| 4756 | BUG_ON(disk_block_cnt > 0xffff); |
| 4757 | |
| 4758 | /* build the new CDB for the physical disk I/O */ |
| 4759 | if (disk_block > 0xffffffff) { |
| 4760 | cdb[0] = is_write ? WRITE_16 : READ_16; |
| 4761 | cdb[1] = 0; |
| 4762 | cdb[2] = (u8) (disk_block >> 56); |
| 4763 | cdb[3] = (u8) (disk_block >> 48); |
| 4764 | cdb[4] = (u8) (disk_block >> 40); |
| 4765 | cdb[5] = (u8) (disk_block >> 32); |
| 4766 | cdb[6] = (u8) (disk_block >> 24); |
| 4767 | cdb[7] = (u8) (disk_block >> 16); |
| 4768 | cdb[8] = (u8) (disk_block >> 8); |
| 4769 | cdb[9] = (u8) (disk_block); |
| 4770 | cdb[10] = (u8) (disk_block_cnt >> 24); |
| 4771 | cdb[11] = (u8) (disk_block_cnt >> 16); |
| 4772 | cdb[12] = (u8) (disk_block_cnt >> 8); |
| 4773 | cdb[13] = (u8) (disk_block_cnt); |
| 4774 | cdb[14] = 0; |
| 4775 | cdb[15] = 0; |
| 4776 | cdb_len = 16; |
| 4777 | } else { |
| 4778 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 4779 | cdb[1] = 0; |
| 4780 | cdb[2] = (u8) (disk_block >> 24); |
| 4781 | cdb[3] = (u8) (disk_block >> 16); |
| 4782 | cdb[4] = (u8) (disk_block >> 8); |
| 4783 | cdb[5] = (u8) (disk_block); |
| 4784 | cdb[6] = 0; |
| 4785 | cdb[7] = (u8) (disk_block_cnt >> 8); |
| 4786 | cdb[8] = (u8) (disk_block_cnt); |
| 4787 | cdb[9] = 0; |
| 4788 | cdb_len = 10; |
| 4789 | } |
| 4790 | 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] | 4791 | dev->scsi3addr, |
| 4792 | dev->phys_disk[map_index]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4793 | } |
| 4794 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 4795 | /* |
| 4796 | * Submit commands down the "normal" RAID stack path |
| 4797 | * All callers to hpsa_ciss_submit must check lockup_detected |
| 4798 | * beforehand, before (opt.) and after calling cmd_alloc |
| 4799 | */ |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 4800 | static int hpsa_ciss_submit(struct ctlr_info *h, |
| 4801 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 4802 | unsigned char scsi3addr[]) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4803 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4804 | cmd->host_scribble = (unsigned char *) c; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4805 | c->cmd_type = CMD_SCSI; |
| 4806 | c->scsi_cmd = cmd; |
| 4807 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 4808 | memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 4809 | c->Header.tag = cpu_to_le64((c->cmdindex << DIRECT_LOOKUP_SHIFT)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4810 | |
| 4811 | /* Fill in the request block... */ |
| 4812 | |
| 4813 | c->Request.Timeout = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4814 | BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB)); |
| 4815 | c->Request.CDBLen = cmd->cmd_len; |
| 4816 | memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4817 | switch (cmd->sc_data_direction) { |
| 4818 | case DMA_TO_DEVICE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4819 | c->Request.type_attr_dir = |
| 4820 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4821 | break; |
| 4822 | case DMA_FROM_DEVICE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4823 | c->Request.type_attr_dir = |
| 4824 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4825 | break; |
| 4826 | case DMA_NONE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4827 | c->Request.type_attr_dir = |
| 4828 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4829 | break; |
| 4830 | case DMA_BIDIRECTIONAL: |
| 4831 | /* This can happen if a buggy application does a scsi passthru |
| 4832 | * and sets both inlen and outlen to non-zero. ( see |
| 4833 | * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) |
| 4834 | */ |
| 4835 | |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 4836 | c->Request.type_attr_dir = |
| 4837 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_RSVD); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4838 | /* This is technically wrong, and hpsa controllers should |
| 4839 | * reject it with CMD_INVALID, which is the most correct |
| 4840 | * response, but non-fibre backends appear to let it |
| 4841 | * slide by, and give the same results as if this field |
| 4842 | * were set correctly. Either way is acceptable for |
| 4843 | * our purposes here. |
| 4844 | */ |
| 4845 | |
| 4846 | break; |
| 4847 | |
| 4848 | default: |
| 4849 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 4850 | cmd->sc_data_direction); |
| 4851 | BUG(); |
| 4852 | break; |
| 4853 | } |
| 4854 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4855 | if (hpsa_scatter_gather(h, c, cmd) < 0) { /* Fill SG list */ |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 4856 | hpsa_cmd_resolve_and_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4857 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4858 | } |
| 4859 | enqueue_cmd_and_start_io(h, c); |
| 4860 | /* the cmd'll come back via intr handler in complete_scsi_command() */ |
| 4861 | return 0; |
| 4862 | } |
| 4863 | |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 4864 | static void hpsa_cmd_init(struct ctlr_info *h, int index, |
| 4865 | struct CommandList *c) |
| 4866 | { |
| 4867 | dma_addr_t cmd_dma_handle, err_dma_handle; |
| 4868 | |
| 4869 | /* Zero out all of commandlist except the last field, refcount */ |
| 4870 | memset(c, 0, offsetof(struct CommandList, refcount)); |
| 4871 | c->Header.tag = cpu_to_le64((u64) (index << DIRECT_LOOKUP_SHIFT)); |
| 4872 | cmd_dma_handle = h->cmd_pool_dhandle + index * sizeof(*c); |
| 4873 | c->err_info = h->errinfo_pool + index; |
| 4874 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 4875 | err_dma_handle = h->errinfo_pool_dhandle |
| 4876 | + index * sizeof(*c->err_info); |
| 4877 | c->cmdindex = index; |
| 4878 | c->busaddr = (u32) cmd_dma_handle; |
| 4879 | c->ErrDesc.Addr = cpu_to_le64((u64) err_dma_handle); |
| 4880 | c->ErrDesc.Len = cpu_to_le32((u32) sizeof(*c->err_info)); |
| 4881 | c->h = h; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 4882 | c->scsi_cmd = SCSI_CMD_IDLE; |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | static void hpsa_preinitialize_commands(struct ctlr_info *h) |
| 4886 | { |
| 4887 | int i; |
| 4888 | |
| 4889 | for (i = 0; i < h->nr_cmds; i++) { |
| 4890 | struct CommandList *c = h->cmd_pool + i; |
| 4891 | |
| 4892 | hpsa_cmd_init(h, i, c); |
| 4893 | atomic_set(&c->refcount, 0); |
| 4894 | } |
| 4895 | } |
| 4896 | |
| 4897 | static inline void hpsa_cmd_partial_init(struct ctlr_info *h, int index, |
| 4898 | struct CommandList *c) |
| 4899 | { |
| 4900 | dma_addr_t cmd_dma_handle = h->cmd_pool_dhandle + index * sizeof(*c); |
| 4901 | |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 4902 | BUG_ON(c->cmdindex != index); |
| 4903 | |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 4904 | memset(c->Request.CDB, 0, sizeof(c->Request.CDB)); |
| 4905 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 4906 | c->busaddr = (u32) cmd_dma_handle; |
| 4907 | } |
| 4908 | |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 4909 | static int hpsa_ioaccel_submit(struct ctlr_info *h, |
| 4910 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 4911 | unsigned char *scsi3addr) |
| 4912 | { |
| 4913 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4914 | int rc = IO_ACCEL_INELIGIBLE; |
| 4915 | |
| 4916 | cmd->host_scribble = (unsigned char *) c; |
| 4917 | |
| 4918 | if (dev->offload_enabled) { |
| 4919 | hpsa_cmd_init(h, c->cmdindex, c); |
| 4920 | c->cmd_type = CMD_SCSI; |
| 4921 | c->scsi_cmd = cmd; |
| 4922 | rc = hpsa_scsi_ioaccel_raid_map(h, c); |
| 4923 | if (rc < 0) /* scsi_dma_map failed. */ |
| 4924 | rc = SCSI_MLQUEUE_HOST_BUSY; |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 4925 | } else if (dev->hba_ioaccel_enabled) { |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 4926 | hpsa_cmd_init(h, c->cmdindex, c); |
| 4927 | c->cmd_type = CMD_SCSI; |
| 4928 | c->scsi_cmd = cmd; |
| 4929 | rc = hpsa_scsi_ioaccel_direct_map(h, c); |
| 4930 | if (rc < 0) /* scsi_dma_map failed. */ |
| 4931 | rc = SCSI_MLQUEUE_HOST_BUSY; |
| 4932 | } |
| 4933 | return rc; |
| 4934 | } |
| 4935 | |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 4936 | static void hpsa_command_resubmit_worker(struct work_struct *work) |
| 4937 | { |
| 4938 | struct scsi_cmnd *cmd; |
| 4939 | struct hpsa_scsi_dev_t *dev; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 4940 | struct CommandList *c = container_of(work, struct CommandList, work); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 4941 | |
| 4942 | cmd = c->scsi_cmd; |
| 4943 | dev = cmd->device->hostdata; |
| 4944 | if (!dev) { |
| 4945 | cmd->result = DID_NO_CONNECT << 16; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 4946 | return hpsa_cmd_free_and_done(c->h, c, cmd); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 4947 | } |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 4948 | if (c->reset_pending) |
| 4949 | return hpsa_cmd_resolve_and_free(c->h, c); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 4950 | if (c->abort_pending) |
| 4951 | return hpsa_cmd_abort_and_free(c->h, c, cmd); |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 4952 | if (c->cmd_type == CMD_IOACCEL2) { |
| 4953 | struct ctlr_info *h = c->h; |
| 4954 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 4955 | int rc; |
| 4956 | |
| 4957 | if (c2->error_data.serv_response == |
| 4958 | IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL) { |
| 4959 | rc = hpsa_ioaccel_submit(h, c, cmd, dev->scsi3addr); |
| 4960 | if (rc == 0) |
| 4961 | return; |
| 4962 | if (rc == SCSI_MLQUEUE_HOST_BUSY) { |
| 4963 | /* |
| 4964 | * If we get here, it means dma mapping failed. |
| 4965 | * Try again via scsi mid layer, which will |
| 4966 | * then get SCSI_MLQUEUE_HOST_BUSY. |
| 4967 | */ |
| 4968 | cmd->result = DID_IMM_RETRY << 16; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 4969 | return hpsa_cmd_free_and_done(h, c, cmd); |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 4970 | } |
| 4971 | /* else, fall thru and resubmit down CISS path */ |
| 4972 | } |
| 4973 | } |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 4974 | hpsa_cmd_partial_init(c->h, c->cmdindex, c); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 4975 | if (hpsa_ciss_submit(c->h, c, cmd, dev->scsi3addr)) { |
| 4976 | /* |
| 4977 | * If we get here, it means dma mapping failed. Try |
| 4978 | * again via scsi mid layer, which will then get |
| 4979 | * SCSI_MLQUEUE_HOST_BUSY. |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 4980 | * |
| 4981 | * hpsa_ciss_submit will have already freed c |
| 4982 | * if it encountered a dma mapping failure. |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 4983 | */ |
| 4984 | cmd->result = DID_IMM_RETRY << 16; |
| 4985 | cmd->scsi_done(cmd); |
| 4986 | } |
| 4987 | } |
| 4988 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 4989 | /* Running in struct Scsi_Host->host_lock less mode */ |
| 4990 | static int hpsa_scsi_queue_command(struct Scsi_Host *sh, struct scsi_cmnd *cmd) |
| 4991 | { |
| 4992 | struct ctlr_info *h; |
| 4993 | struct hpsa_scsi_dev_t *dev; |
| 4994 | unsigned char scsi3addr[8]; |
| 4995 | struct CommandList *c; |
| 4996 | int rc = 0; |
| 4997 | |
| 4998 | /* Get the ptr to our adapter structure out of cmd->host. */ |
| 4999 | h = sdev_to_hba(cmd->device); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5000 | |
| 5001 | BUG_ON(cmd->request->tag < 0); |
| 5002 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5003 | dev = cmd->device->hostdata; |
| 5004 | if (!dev) { |
| 5005 | cmd->result = DID_NO_CONNECT << 16; |
| 5006 | cmd->scsi_done(cmd); |
| 5007 | return 0; |
| 5008 | } |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5009 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5010 | memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); |
| 5011 | |
| 5012 | if (unlikely(lockup_detected(h))) { |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5013 | cmd->result = DID_NO_CONNECT << 16; |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5014 | cmd->scsi_done(cmd); |
| 5015 | return 0; |
| 5016 | } |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5017 | c = cmd_tagged_alloc(h, cmd); |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5018 | |
Stephen Cameron | 407863c | 2015-01-23 16:44:19 -0600 | [diff] [blame] | 5019 | /* |
| 5020 | * Call alternate submit routine for I/O accelerated commands. |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5021 | * Retries always go down the normal I/O path. |
| 5022 | */ |
| 5023 | if (likely(cmd->retries == 0 && |
| 5024 | cmd->request->cmd_type == REQ_TYPE_FS && |
| 5025 | h->acciopath_status)) { |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5026 | rc = hpsa_ioaccel_submit(h, c, cmd, scsi3addr); |
| 5027 | if (rc == 0) |
| 5028 | return 0; |
| 5029 | if (rc == SCSI_MLQUEUE_HOST_BUSY) { |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5030 | hpsa_cmd_resolve_and_free(h, c); |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5031 | return SCSI_MLQUEUE_HOST_BUSY; |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5032 | } |
| 5033 | } |
| 5034 | return hpsa_ciss_submit(h, c, cmd, scsi3addr); |
| 5035 | } |
| 5036 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5037 | static void hpsa_scan_complete(struct ctlr_info *h) |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5038 | { |
| 5039 | unsigned long flags; |
| 5040 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5041 | spin_lock_irqsave(&h->scan_lock, flags); |
| 5042 | h->scan_finished = 1; |
| 5043 | wake_up_all(&h->scan_wait_queue); |
| 5044 | spin_unlock_irqrestore(&h->scan_lock, flags); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5045 | } |
| 5046 | |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5047 | static void hpsa_scan_start(struct Scsi_Host *sh) |
| 5048 | { |
| 5049 | struct ctlr_info *h = shost_to_hba(sh); |
| 5050 | unsigned long flags; |
| 5051 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5052 | /* |
| 5053 | * Don't let rescans be initiated on a controller known to be locked |
| 5054 | * up. If the controller locks up *during* a rescan, that thread is |
| 5055 | * probably hosed, but at least we can prevent new rescan threads from |
| 5056 | * piling up on a locked up controller. |
| 5057 | */ |
| 5058 | if (unlikely(lockup_detected(h))) |
| 5059 | return hpsa_scan_complete(h); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5060 | |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5061 | /* wait until any scan already in progress is finished. */ |
| 5062 | while (1) { |
| 5063 | spin_lock_irqsave(&h->scan_lock, flags); |
| 5064 | if (h->scan_finished) |
| 5065 | break; |
| 5066 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 5067 | wait_event(h->scan_wait_queue, h->scan_finished); |
| 5068 | /* Note: We don't need to worry about a race between this |
| 5069 | * thread and driver unload because the midlayer will |
| 5070 | * have incremented the reference count, so unload won't |
| 5071 | * happen if we're in here. |
| 5072 | */ |
| 5073 | } |
| 5074 | h->scan_finished = 0; /* mark scan as in progress */ |
| 5075 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 5076 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5077 | if (unlikely(lockup_detected(h))) |
| 5078 | return hpsa_scan_complete(h); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5079 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 5080 | hpsa_update_scsi_devices(h); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5081 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5082 | hpsa_scan_complete(h); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5083 | } |
| 5084 | |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 5085 | static int hpsa_change_queue_depth(struct scsi_device *sdev, int qdepth) |
| 5086 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5087 | struct hpsa_scsi_dev_t *logical_drive = sdev->hostdata; |
| 5088 | |
| 5089 | if (!logical_drive) |
| 5090 | return -ENODEV; |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 5091 | |
| 5092 | if (qdepth < 1) |
| 5093 | qdepth = 1; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5094 | else if (qdepth > logical_drive->queue_depth) |
| 5095 | qdepth = logical_drive->queue_depth; |
| 5096 | |
| 5097 | return scsi_change_queue_depth(sdev, qdepth); |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 5098 | } |
| 5099 | |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5100 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 5101 | unsigned long elapsed_time) |
| 5102 | { |
| 5103 | struct ctlr_info *h = shost_to_hba(sh); |
| 5104 | unsigned long flags; |
| 5105 | int finished; |
| 5106 | |
| 5107 | spin_lock_irqsave(&h->scan_lock, flags); |
| 5108 | finished = h->scan_finished; |
| 5109 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 5110 | return finished; |
| 5111 | } |
| 5112 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5113 | static int hpsa_scsi_host_alloc(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5114 | { |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5115 | struct Scsi_Host *sh; |
| 5116 | int error; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5117 | |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5118 | sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h)); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5119 | if (sh == NULL) { |
| 5120 | dev_err(&h->pdev->dev, "scsi_host_alloc failed\n"); |
| 5121 | return -ENOMEM; |
| 5122 | } |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5123 | |
| 5124 | sh->io_port = 0; |
| 5125 | sh->n_io_port = 0; |
| 5126 | sh->this_id = -1; |
| 5127 | sh->max_channel = 3; |
| 5128 | sh->max_cmd_len = MAX_COMMAND_SIZE; |
| 5129 | sh->max_lun = HPSA_MAX_LUN; |
| 5130 | sh->max_id = HPSA_MAX_LUN; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 5131 | sh->can_queue = h->nr_cmds - HPSA_NRESERVED_CMDS; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5132 | sh->cmd_per_lun = sh->can_queue; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5133 | sh->sg_tablesize = h->maxsgentries; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5134 | sh->hostdata[0] = (unsigned long) h; |
| 5135 | sh->irq = h->intr[h->intr_mode]; |
| 5136 | sh->unique_id = sh->irq; |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5137 | error = scsi_init_shared_tag_map(sh, sh->can_queue); |
| 5138 | if (error) { |
| 5139 | dev_err(&h->pdev->dev, |
| 5140 | "%s: scsi_init_shared_tag_map failed for controller %d\n", |
| 5141 | __func__, h->ctlr); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5142 | scsi_host_put(sh); |
| 5143 | return error; |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5144 | } |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5145 | h->scsi_host = sh; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5146 | return 0; |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5147 | } |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5148 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5149 | static int hpsa_scsi_add_host(struct ctlr_info *h) |
| 5150 | { |
| 5151 | int rv; |
| 5152 | |
| 5153 | rv = scsi_add_host(h->scsi_host, &h->pdev->dev); |
| 5154 | if (rv) { |
| 5155 | dev_err(&h->pdev->dev, "scsi_add_host failed\n"); |
| 5156 | return rv; |
| 5157 | } |
| 5158 | scsi_scan_host(h->scsi_host); |
| 5159 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5160 | } |
| 5161 | |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5162 | /* |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5163 | * The block layer has already gone to the trouble of picking out a unique, |
| 5164 | * small-integer tag for this request. We use an offset from that value as |
| 5165 | * an index to select our command block. (The offset allows us to reserve the |
| 5166 | * low-numbered entries for our own uses.) |
| 5167 | */ |
| 5168 | static int hpsa_get_cmd_index(struct scsi_cmnd *scmd) |
| 5169 | { |
| 5170 | int idx = scmd->request->tag; |
| 5171 | |
| 5172 | if (idx < 0) |
| 5173 | return idx; |
| 5174 | |
| 5175 | /* Offset to leave space for internal cmds. */ |
| 5176 | return idx += HPSA_NRESERVED_CMDS; |
| 5177 | } |
| 5178 | |
| 5179 | /* |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5180 | * Send a TEST_UNIT_READY command to the specified LUN using the specified |
| 5181 | * reply queue; returns zero if the unit is ready, and non-zero otherwise. |
| 5182 | */ |
| 5183 | static int hpsa_send_test_unit_ready(struct ctlr_info *h, |
| 5184 | struct CommandList *c, unsigned char lunaddr[], |
| 5185 | int reply_queue) |
| 5186 | { |
| 5187 | int rc; |
| 5188 | |
| 5189 | /* Send the Test Unit Ready, fill_cmd can't fail, no mapping */ |
| 5190 | (void) fill_cmd(c, TEST_UNIT_READY, h, |
| 5191 | NULL, 0, 0, lunaddr, TYPE_CMD); |
| 5192 | rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT); |
| 5193 | if (rc) |
| 5194 | return rc; |
| 5195 | /* no unmap needed here because no data xfer. */ |
| 5196 | |
| 5197 | /* Check if the unit is already ready. */ |
| 5198 | if (c->err_info->CommandStatus == CMD_SUCCESS) |
| 5199 | return 0; |
| 5200 | |
| 5201 | /* |
| 5202 | * The first command sent after reset will receive "unit attention" to |
| 5203 | * indicate that the LUN has been reset...this is actually what we're |
| 5204 | * looking for (but, success is good too). |
| 5205 | */ |
| 5206 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 5207 | c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION && |
| 5208 | (c->err_info->SenseInfo[2] == NO_SENSE || |
| 5209 | c->err_info->SenseInfo[2] == UNIT_ATTENTION)) |
| 5210 | return 0; |
| 5211 | |
| 5212 | return 1; |
| 5213 | } |
| 5214 | |
| 5215 | /* |
| 5216 | * Wait for a TEST_UNIT_READY command to complete, retrying as necessary; |
| 5217 | * returns zero when the unit is ready, and non-zero when giving up. |
| 5218 | */ |
| 5219 | static int hpsa_wait_for_test_unit_ready(struct ctlr_info *h, |
| 5220 | struct CommandList *c, |
| 5221 | unsigned char lunaddr[], int reply_queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5222 | { |
Tomas Henzl | 8919358 | 2014-02-21 16:25:05 -0600 | [diff] [blame] | 5223 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5224 | int count = 0; |
| 5225 | int waittime = 1; /* seconds */ |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5226 | |
| 5227 | /* Send test unit ready until device ready, or give up. */ |
| 5228 | for (count = 0; count < HPSA_TUR_RETRY_LIMIT; count++) { |
| 5229 | |
| 5230 | /* |
| 5231 | * Wait for a bit. do this first, because if we send |
| 5232 | * the TUR right away, the reset will just abort it. |
| 5233 | */ |
| 5234 | msleep(1000 * waittime); |
| 5235 | |
| 5236 | rc = hpsa_send_test_unit_ready(h, c, lunaddr, reply_queue); |
| 5237 | if (!rc) |
| 5238 | break; |
| 5239 | |
| 5240 | /* Increase wait time with each try, up to a point. */ |
| 5241 | if (waittime < HPSA_MAX_WAIT_INTERVAL_SECS) |
| 5242 | waittime *= 2; |
| 5243 | |
| 5244 | dev_warn(&h->pdev->dev, |
| 5245 | "waiting %d secs for device to become ready.\n", |
| 5246 | waittime); |
| 5247 | } |
| 5248 | |
| 5249 | return rc; |
| 5250 | } |
| 5251 | |
| 5252 | static int wait_for_device_to_become_ready(struct ctlr_info *h, |
| 5253 | unsigned char lunaddr[], |
| 5254 | int reply_queue) |
| 5255 | { |
| 5256 | int first_queue; |
| 5257 | int last_queue; |
| 5258 | int rq; |
| 5259 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5260 | struct CommandList *c; |
| 5261 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5262 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5263 | |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5264 | /* |
| 5265 | * If no specific reply queue was requested, then send the TUR |
| 5266 | * repeatedly, requesting a reply on each reply queue; otherwise execute |
| 5267 | * the loop exactly once using only the specified queue. |
| 5268 | */ |
| 5269 | if (reply_queue == DEFAULT_REPLY_QUEUE) { |
| 5270 | first_queue = 0; |
| 5271 | last_queue = h->nreply_queues - 1; |
| 5272 | } else { |
| 5273 | first_queue = reply_queue; |
| 5274 | last_queue = reply_queue; |
| 5275 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5276 | |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5277 | for (rq = first_queue; rq <= last_queue; rq++) { |
| 5278 | rc = hpsa_wait_for_test_unit_ready(h, c, lunaddr, rq); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5279 | if (rc) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5280 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | if (rc) |
| 5284 | dev_warn(&h->pdev->dev, "giving up on device.\n"); |
| 5285 | else |
| 5286 | dev_warn(&h->pdev->dev, "device is ready.\n"); |
| 5287 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5288 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5289 | return rc; |
| 5290 | } |
| 5291 | |
| 5292 | /* Need at least one of these error handlers to keep ../scsi/hosts.c from |
| 5293 | * complaining. Doing a host- or bus-reset can't do anything good here. |
| 5294 | */ |
| 5295 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) |
| 5296 | { |
| 5297 | int rc; |
| 5298 | struct ctlr_info *h; |
| 5299 | struct hpsa_scsi_dev_t *dev; |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5300 | u8 reset_type; |
Dan Carpenter | 2dc127b | 2015-06-04 17:47:56 +0300 | [diff] [blame] | 5301 | char msg[48]; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5302 | |
| 5303 | /* find the controller to which the command to be aborted was sent */ |
| 5304 | h = sdev_to_hba(scsicmd->device); |
| 5305 | if (h == NULL) /* paranoia */ |
| 5306 | return FAILED; |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 5307 | |
| 5308 | if (lockup_detected(h)) |
| 5309 | return FAILED; |
| 5310 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5311 | dev = scsicmd->device->hostdata; |
| 5312 | if (!dev) { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5313 | dev_err(&h->pdev->dev, "%s: device lookup failed\n", __func__); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5314 | return FAILED; |
| 5315 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5316 | |
| 5317 | /* if controller locked up, we can guarantee command won't complete */ |
| 5318 | if (lockup_detected(h)) { |
Dan Carpenter | 2dc127b | 2015-06-04 17:47:56 +0300 | [diff] [blame] | 5319 | snprintf(msg, sizeof(msg), |
| 5320 | "cmd %d RESET FAILED, lockup detected", |
| 5321 | hpsa_get_cmd_index(scsicmd)); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5322 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5323 | return FAILED; |
| 5324 | } |
| 5325 | |
| 5326 | /* this reset request might be the result of a lockup; check */ |
| 5327 | if (detect_controller_lockup(h)) { |
Dan Carpenter | 2dc127b | 2015-06-04 17:47:56 +0300 | [diff] [blame] | 5328 | snprintf(msg, sizeof(msg), |
| 5329 | "cmd %d RESET FAILED, new lockup detected", |
| 5330 | hpsa_get_cmd_index(scsicmd)); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5331 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5332 | return FAILED; |
| 5333 | } |
| 5334 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5335 | /* Do not attempt on controller */ |
| 5336 | if (is_hba_lunid(dev->scsi3addr)) |
| 5337 | return SUCCESS; |
| 5338 | |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5339 | if (is_logical_dev_addr_mode(dev->scsi3addr)) |
| 5340 | reset_type = HPSA_DEVICE_RESET_MSG; |
| 5341 | else |
| 5342 | reset_type = HPSA_PHYS_TARGET_RESET; |
| 5343 | |
| 5344 | sprintf(msg, "resetting %s", |
| 5345 | reset_type == HPSA_DEVICE_RESET_MSG ? "logical " : "physical "); |
| 5346 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5347 | |
Don Brace | da03ded | 2015-11-04 15:50:56 -0600 | [diff] [blame] | 5348 | h->reset_in_progress = 1; |
| 5349 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5350 | /* send a reset to the SCSI LUN which the command was sent to */ |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5351 | rc = hpsa_do_reset(h, dev, dev->scsi3addr, reset_type, |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5352 | DEFAULT_REPLY_QUEUE); |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5353 | sprintf(msg, "reset %s %s", |
| 5354 | reset_type == HPSA_DEVICE_RESET_MSG ? "logical " : "physical ", |
| 5355 | rc == 0 ? "completed successfully" : "failed"); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5356 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Don Brace | da03ded | 2015-11-04 15:50:56 -0600 | [diff] [blame] | 5357 | h->reset_in_progress = 0; |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5358 | return rc == 0 ? SUCCESS : FAILED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5359 | } |
| 5360 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5361 | static void swizzle_abort_tag(u8 *tag) |
| 5362 | { |
| 5363 | u8 original_tag[8]; |
| 5364 | |
| 5365 | memcpy(original_tag, tag, 8); |
| 5366 | tag[0] = original_tag[3]; |
| 5367 | tag[1] = original_tag[2]; |
| 5368 | tag[2] = original_tag[1]; |
| 5369 | tag[3] = original_tag[0]; |
| 5370 | tag[4] = original_tag[7]; |
| 5371 | tag[5] = original_tag[6]; |
| 5372 | tag[6] = original_tag[5]; |
| 5373 | tag[7] = original_tag[4]; |
| 5374 | } |
| 5375 | |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5376 | static void hpsa_get_tag(struct ctlr_info *h, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5377 | struct CommandList *c, __le32 *taglower, __le32 *tagupper) |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5378 | { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5379 | u64 tag; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5380 | if (c->cmd_type == CMD_IOACCEL1) { |
| 5381 | struct io_accel1_cmd *cm1 = (struct io_accel1_cmd *) |
| 5382 | &h->ioaccel_cmd_pool[c->cmdindex]; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5383 | tag = le64_to_cpu(cm1->tag); |
| 5384 | *tagupper = cpu_to_le32(tag >> 32); |
| 5385 | *taglower = cpu_to_le32(tag); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5386 | return; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5387 | } |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5388 | if (c->cmd_type == CMD_IOACCEL2) { |
| 5389 | struct io_accel2_cmd *cm2 = (struct io_accel2_cmd *) |
| 5390 | &h->ioaccel2_cmd_pool[c->cmdindex]; |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 5391 | /* upper tag not used in ioaccel2 mode */ |
| 5392 | memset(tagupper, 0, sizeof(*tagupper)); |
| 5393 | *taglower = cm2->Tag; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5394 | return; |
| 5395 | } |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5396 | tag = le64_to_cpu(c->Header.tag); |
| 5397 | *tagupper = cpu_to_le32(tag >> 32); |
| 5398 | *taglower = cpu_to_le32(tag); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5399 | } |
| 5400 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5401 | static int hpsa_send_abort(struct ctlr_info *h, unsigned char *scsi3addr, |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5402 | struct CommandList *abort, int reply_queue) |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5403 | { |
| 5404 | int rc = IO_OK; |
| 5405 | struct CommandList *c; |
| 5406 | struct ErrorInfo *ei; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5407 | __le32 tagupper, taglower; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5408 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5409 | c = cmd_alloc(h); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5410 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5411 | /* fill_cmd can't fail here, no buffer to map */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5412 | (void) fill_cmd(c, HPSA_ABORT_MSG, h, &abort->Header.tag, |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5413 | 0, 0, scsi3addr, TYPE_MSG); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5414 | if (h->needs_abort_tags_swizzled) |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5415 | swizzle_abort_tag(&c->Request.CDB[4]); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5416 | (void) hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5417 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5418 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: do_simple_cmd(abort) completed.\n", |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5419 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5420 | /* no unmap needed here because no data xfer. */ |
| 5421 | |
| 5422 | ei = c->err_info; |
| 5423 | switch (ei->CommandStatus) { |
| 5424 | case CMD_SUCCESS: |
| 5425 | break; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 5426 | case CMD_TMF_STATUS: |
| 5427 | rc = hpsa_evaluate_tmf_status(h, c); |
| 5428 | break; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5429 | case CMD_UNABORTABLE: /* Very common, don't make noise. */ |
| 5430 | rc = -1; |
| 5431 | break; |
| 5432 | default: |
| 5433 | 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] | 5434 | __func__, tagupper, taglower); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 5435 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5436 | rc = -1; |
| 5437 | break; |
| 5438 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5439 | cmd_free(h, c); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 5440 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", |
| 5441 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5442 | return rc; |
| 5443 | } |
| 5444 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5445 | static void setup_ioaccel2_abort_cmd(struct CommandList *c, struct ctlr_info *h, |
| 5446 | struct CommandList *command_to_abort, int reply_queue) |
| 5447 | { |
| 5448 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 5449 | struct hpsa_tmf_struct *ac = (struct hpsa_tmf_struct *) c2; |
| 5450 | struct io_accel2_cmd *c2a = |
| 5451 | &h->ioaccel2_cmd_pool[command_to_abort->cmdindex]; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5452 | struct scsi_cmnd *scmd = command_to_abort->scsi_cmd; |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5453 | struct hpsa_scsi_dev_t *dev = scmd->device->hostdata; |
| 5454 | |
| 5455 | /* |
| 5456 | * We're overlaying struct hpsa_tmf_struct on top of something which |
| 5457 | * was allocated as a struct io_accel2_cmd, so we better be sure it |
| 5458 | * actually fits, and doesn't overrun the error info space. |
| 5459 | */ |
| 5460 | BUILD_BUG_ON(sizeof(struct hpsa_tmf_struct) > |
| 5461 | sizeof(struct io_accel2_cmd)); |
| 5462 | BUG_ON(offsetof(struct io_accel2_cmd, error_data) < |
| 5463 | offsetof(struct hpsa_tmf_struct, error_len) + |
| 5464 | sizeof(ac->error_len)); |
| 5465 | |
| 5466 | c->cmd_type = IOACCEL2_TMF; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5467 | c->scsi_cmd = SCSI_CMD_BUSY; |
| 5468 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5469 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 5470 | c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle + |
| 5471 | (c->cmdindex * sizeof(struct io_accel2_cmd)); |
| 5472 | BUG_ON(c->busaddr & 0x0000007F); |
| 5473 | |
| 5474 | memset(ac, 0, sizeof(*c2)); /* yes this is correct */ |
| 5475 | ac->iu_type = IOACCEL2_IU_TMF_TYPE; |
| 5476 | ac->reply_queue = reply_queue; |
| 5477 | ac->tmf = IOACCEL2_TMF_ABORT; |
| 5478 | ac->it_nexus = cpu_to_le32(dev->ioaccel_handle); |
| 5479 | memset(ac->lun_id, 0, sizeof(ac->lun_id)); |
| 5480 | ac->tag = cpu_to_le64(c->cmdindex << DIRECT_LOOKUP_SHIFT); |
| 5481 | ac->abort_tag = cpu_to_le64(le32_to_cpu(c2a->Tag)); |
| 5482 | ac->error_ptr = cpu_to_le64(c->busaddr + |
| 5483 | offsetof(struct io_accel2_cmd, error_data)); |
| 5484 | ac->error_len = cpu_to_le32(sizeof(c2->error_data)); |
| 5485 | } |
| 5486 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5487 | /* ioaccel2 path firmware cannot handle abort task requests. |
| 5488 | * Change abort requests to physical target reset, and send to the |
| 5489 | * address of the physical disk used for the ioaccel 2 command. |
| 5490 | * Return 0 on success (IO_OK) |
| 5491 | * -1 on failure |
| 5492 | */ |
| 5493 | |
| 5494 | static int hpsa_send_reset_as_abort_ioaccel2(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5495 | unsigned char *scsi3addr, struct CommandList *abort, int reply_queue) |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5496 | { |
| 5497 | int rc = IO_OK; |
| 5498 | struct scsi_cmnd *scmd; /* scsi command within request being aborted */ |
| 5499 | struct hpsa_scsi_dev_t *dev; /* device to which scsi cmd was sent */ |
| 5500 | unsigned char phys_scsi3addr[8]; /* addr of phys disk with volume */ |
| 5501 | unsigned char *psa = &phys_scsi3addr[0]; |
| 5502 | |
| 5503 | /* Get a pointer to the hpsa logical device. */ |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 5504 | scmd = abort->scsi_cmd; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5505 | dev = (struct hpsa_scsi_dev_t *)(scmd->device->hostdata); |
| 5506 | if (dev == NULL) { |
| 5507 | dev_warn(&h->pdev->dev, |
| 5508 | "Cannot abort: no device pointer for command.\n"); |
| 5509 | return -1; /* not abortable */ |
| 5510 | } |
| 5511 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 5512 | if (h->raid_offload_debug > 0) |
| 5513 | dev_info(&h->pdev->dev, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 5514 | "scsi %d:%d:%d:%d %s scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 5515 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 5516 | "Reset as abort", |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 5517 | scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3], |
| 5518 | scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); |
| 5519 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5520 | if (!dev->offload_enabled) { |
| 5521 | dev_warn(&h->pdev->dev, |
| 5522 | "Can't abort: device is not operating in HP SSD Smart Path mode.\n"); |
| 5523 | return -1; /* not abortable */ |
| 5524 | } |
| 5525 | |
| 5526 | /* Incoming scsi3addr is logical addr. We need physical disk addr. */ |
| 5527 | if (!hpsa_get_pdisk_of_ioaccel2(h, abort, psa)) { |
| 5528 | dev_warn(&h->pdev->dev, "Can't abort: Failed lookup of physical address.\n"); |
| 5529 | return -1; /* not abortable */ |
| 5530 | } |
| 5531 | |
| 5532 | /* send the reset */ |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 5533 | if (h->raid_offload_debug > 0) |
| 5534 | dev_info(&h->pdev->dev, |
| 5535 | "Reset as abort: Resetting physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 5536 | psa[0], psa[1], psa[2], psa[3], |
| 5537 | psa[4], psa[5], psa[6], psa[7]); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5538 | rc = hpsa_do_reset(h, dev, psa, HPSA_RESET_TYPE_TARGET, reply_queue); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5539 | if (rc != 0) { |
| 5540 | dev_warn(&h->pdev->dev, |
| 5541 | "Reset as abort: Failed on physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 5542 | psa[0], psa[1], psa[2], psa[3], |
| 5543 | psa[4], psa[5], psa[6], psa[7]); |
| 5544 | return rc; /* failed to reset */ |
| 5545 | } |
| 5546 | |
| 5547 | /* wait for device to recover */ |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5548 | if (wait_for_device_to_become_ready(h, psa, reply_queue) != 0) { |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5549 | dev_warn(&h->pdev->dev, |
| 5550 | "Reset as abort: Failed: Device never recovered from reset: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 5551 | psa[0], psa[1], psa[2], psa[3], |
| 5552 | psa[4], psa[5], psa[6], psa[7]); |
| 5553 | return -1; /* failed to recover */ |
| 5554 | } |
| 5555 | |
| 5556 | /* device recovered */ |
| 5557 | dev_info(&h->pdev->dev, |
| 5558 | "Reset as abort: Device recovered from reset: scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 5559 | psa[0], psa[1], psa[2], psa[3], |
| 5560 | psa[4], psa[5], psa[6], psa[7]); |
| 5561 | |
| 5562 | return rc; /* success */ |
| 5563 | } |
| 5564 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5565 | static int hpsa_send_abort_ioaccel2(struct ctlr_info *h, |
| 5566 | struct CommandList *abort, int reply_queue) |
| 5567 | { |
| 5568 | int rc = IO_OK; |
| 5569 | struct CommandList *c; |
| 5570 | __le32 taglower, tagupper; |
| 5571 | struct hpsa_scsi_dev_t *dev; |
| 5572 | struct io_accel2_cmd *c2; |
| 5573 | |
| 5574 | dev = abort->scsi_cmd->device->hostdata; |
| 5575 | if (!dev->offload_enabled && !dev->hba_ioaccel_enabled) |
| 5576 | return -1; |
| 5577 | |
| 5578 | c = cmd_alloc(h); |
| 5579 | setup_ioaccel2_abort_cmd(c, h, abort, reply_queue); |
| 5580 | c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 5581 | (void) hpsa_scsi_do_simple_cmd(h, c, reply_queue, NO_TIMEOUT); |
| 5582 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
| 5583 | dev_dbg(&h->pdev->dev, |
| 5584 | "%s: Tag:0x%08x:%08x: do_simple_cmd(ioaccel2 abort) completed.\n", |
| 5585 | __func__, tagupper, taglower); |
| 5586 | /* no unmap needed here because no data xfer. */ |
| 5587 | |
| 5588 | dev_dbg(&h->pdev->dev, |
| 5589 | "%s: Tag:0x%08x:%08x: abort service response = 0x%02x.\n", |
| 5590 | __func__, tagupper, taglower, c2->error_data.serv_response); |
| 5591 | switch (c2->error_data.serv_response) { |
| 5592 | case IOACCEL2_SERV_RESPONSE_TMF_COMPLETE: |
| 5593 | case IOACCEL2_SERV_RESPONSE_TMF_SUCCESS: |
| 5594 | rc = 0; |
| 5595 | break; |
| 5596 | case IOACCEL2_SERV_RESPONSE_TMF_REJECTED: |
| 5597 | case IOACCEL2_SERV_RESPONSE_FAILURE: |
| 5598 | case IOACCEL2_SERV_RESPONSE_TMF_WRONG_LUN: |
| 5599 | rc = -1; |
| 5600 | break; |
| 5601 | default: |
| 5602 | dev_warn(&h->pdev->dev, |
| 5603 | "%s: Tag:0x%08x:%08x: unknown abort service response 0x%02x\n", |
| 5604 | __func__, tagupper, taglower, |
| 5605 | c2->error_data.serv_response); |
| 5606 | rc = -1; |
| 5607 | } |
| 5608 | cmd_free(h, c); |
| 5609 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", __func__, |
| 5610 | tagupper, taglower); |
| 5611 | return rc; |
| 5612 | } |
| 5613 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5614 | static int hpsa_send_abort_both_ways(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5615 | unsigned char *scsi3addr, struct CommandList *abort, int reply_queue) |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5616 | { |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5617 | /* |
| 5618 | * ioccelerator mode 2 commands should be aborted via the |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5619 | * accelerated path, since RAID path is unaware of these commands, |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5620 | * but not all underlying firmware can handle abort TMF. |
| 5621 | * Change abort to physical device reset when abort TMF is unsupported. |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5622 | */ |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5623 | if (abort->cmd_type == CMD_IOACCEL2) { |
| 5624 | if (HPSATMF_IOACCEL_ENABLED & h->TMFSupportFlags) |
| 5625 | return hpsa_send_abort_ioaccel2(h, abort, |
| 5626 | reply_queue); |
| 5627 | else |
| 5628 | return hpsa_send_reset_as_abort_ioaccel2(h, scsi3addr, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5629 | abort, reply_queue); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5630 | } |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5631 | return hpsa_send_abort(h, scsi3addr, abort, reply_queue); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | /* Find out which reply queue a command was meant to return on */ |
| 5635 | static int hpsa_extract_reply_queue(struct ctlr_info *h, |
| 5636 | struct CommandList *c) |
| 5637 | { |
| 5638 | if (c->cmd_type == CMD_IOACCEL2) |
| 5639 | return h->ioaccel2_cmd_pool[c->cmdindex].reply_queue; |
| 5640 | return c->Header.ReplyQueue; |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5641 | } |
| 5642 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5643 | /* |
| 5644 | * Limit concurrency of abort commands to prevent |
| 5645 | * over-subscription of commands |
| 5646 | */ |
| 5647 | static inline int wait_for_available_abort_cmd(struct ctlr_info *h) |
| 5648 | { |
| 5649 | #define ABORT_CMD_WAIT_MSECS 5000 |
| 5650 | return !wait_event_timeout(h->abort_cmd_wait_queue, |
| 5651 | atomic_dec_if_positive(&h->abort_cmds_available) >= 0, |
| 5652 | msecs_to_jiffies(ABORT_CMD_WAIT_MSECS)); |
| 5653 | } |
| 5654 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5655 | /* Send an abort for the specified command. |
| 5656 | * If the device and controller support it, |
| 5657 | * send a task abort request. |
| 5658 | */ |
| 5659 | static int hpsa_eh_abort_handler(struct scsi_cmnd *sc) |
| 5660 | { |
| 5661 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5662 | int rc; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5663 | struct ctlr_info *h; |
| 5664 | struct hpsa_scsi_dev_t *dev; |
| 5665 | struct CommandList *abort; /* pointer to command to be aborted */ |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5666 | struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ |
| 5667 | char msg[256]; /* For debug messaging. */ |
| 5668 | int ml = 0; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5669 | __le32 tagupper, taglower; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5670 | int refcount, reply_queue; |
| 5671 | |
| 5672 | if (sc == NULL) |
| 5673 | return FAILED; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5674 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5675 | if (sc->device == NULL) |
| 5676 | return FAILED; |
| 5677 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5678 | /* Find the controller of the command to be aborted */ |
| 5679 | h = sdev_to_hba(sc->device); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5680 | if (h == NULL) |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5681 | return FAILED; |
| 5682 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5683 | /* Find the device of the command to be aborted */ |
| 5684 | dev = sc->device->hostdata; |
| 5685 | if (!dev) { |
| 5686 | dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", |
| 5687 | msg); |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 5688 | return FAILED; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | /* If controller locked up, we can guarantee command won't complete */ |
| 5692 | if (lockup_detected(h)) { |
| 5693 | hpsa_show_dev_msg(KERN_WARNING, h, dev, |
| 5694 | "ABORT FAILED, lockup detected"); |
| 5695 | return FAILED; |
| 5696 | } |
| 5697 | |
| 5698 | /* This is a good time to check if controller lockup has occurred */ |
| 5699 | if (detect_controller_lockup(h)) { |
| 5700 | hpsa_show_dev_msg(KERN_WARNING, h, dev, |
| 5701 | "ABORT FAILED, new lockup detected"); |
| 5702 | return FAILED; |
| 5703 | } |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 5704 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5705 | /* Check that controller supports some kind of task abort */ |
| 5706 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags) && |
| 5707 | !(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 5708 | return FAILED; |
| 5709 | |
| 5710 | memset(msg, 0, sizeof(msg)); |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5711 | ml += sprintf(msg+ml, "scsi %d:%d:%d:%llu %s %p", |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5712 | h->scsi_host->host_no, sc->device->channel, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 5713 | sc->device->id, sc->device->lun, |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5714 | "Aborting command", sc); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5715 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5716 | /* Get SCSI command to be aborted */ |
| 5717 | abort = (struct CommandList *) sc->host_scribble; |
| 5718 | if (abort == NULL) { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5719 | /* This can happen if the command already completed. */ |
| 5720 | return SUCCESS; |
| 5721 | } |
| 5722 | refcount = atomic_inc_return(&abort->refcount); |
| 5723 | if (refcount == 1) { /* Command is done already. */ |
| 5724 | cmd_free(h, abort); |
| 5725 | return SUCCESS; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5726 | } |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5727 | |
| 5728 | /* Don't bother trying the abort if we know it won't work. */ |
| 5729 | if (abort->cmd_type != CMD_IOACCEL2 && |
| 5730 | abort->cmd_type != CMD_IOACCEL1 && !dev->supports_aborts) { |
| 5731 | cmd_free(h, abort); |
| 5732 | return FAILED; |
| 5733 | } |
| 5734 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5735 | /* |
| 5736 | * Check that we're aborting the right command. |
| 5737 | * It's possible the CommandList already completed and got re-used. |
| 5738 | */ |
| 5739 | if (abort->scsi_cmd != sc) { |
| 5740 | cmd_free(h, abort); |
| 5741 | return SUCCESS; |
| 5742 | } |
| 5743 | |
| 5744 | abort->abort_pending = true; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5745 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5746 | reply_queue = hpsa_extract_reply_queue(h, abort); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5747 | ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", tagupper, taglower); |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 5748 | as = abort->scsi_cmd; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5749 | if (as != NULL) |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5750 | ml += sprintf(msg+ml, |
| 5751 | "CDBLen: %d CDB: 0x%02x%02x... SN: 0x%lx ", |
| 5752 | as->cmd_len, as->cmnd[0], as->cmnd[1], |
| 5753 | as->serial_number); |
| 5754 | dev_warn(&h->pdev->dev, "%s BEING SENT\n", msg); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 5755 | hpsa_show_dev_msg(KERN_WARNING, h, dev, "Aborting command"); |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5756 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5757 | /* |
| 5758 | * Command is in flight, or possibly already completed |
| 5759 | * by the firmware (but not to the scsi mid layer) but we can't |
| 5760 | * distinguish which. Send the abort down. |
| 5761 | */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5762 | if (wait_for_available_abort_cmd(h)) { |
| 5763 | dev_warn(&h->pdev->dev, |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5764 | "%s FAILED, timeout waiting for an abort command to become available.\n", |
| 5765 | msg); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5766 | cmd_free(h, abort); |
| 5767 | return FAILED; |
| 5768 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5769 | rc = hpsa_send_abort_both_ways(h, dev->scsi3addr, abort, reply_queue); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5770 | atomic_inc(&h->abort_cmds_available); |
| 5771 | wake_up_all(&h->abort_cmd_wait_queue); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5772 | if (rc != 0) { |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5773 | dev_warn(&h->pdev->dev, "%s SENT, FAILED\n", msg); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 5774 | hpsa_show_dev_msg(KERN_WARNING, h, dev, |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5775 | "FAILED to abort command"); |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5776 | cmd_free(h, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5777 | return FAILED; |
| 5778 | } |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 5779 | dev_info(&h->pdev->dev, "%s SENT, SUCCESS\n", msg); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5780 | wait_event(h->event_sync_wait_queue, |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5781 | abort->scsi_cmd != sc || lockup_detected(h)); |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5782 | cmd_free(h, abort); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5783 | return !lockup_detected(h) ? SUCCESS : FAILED; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5784 | } |
| 5785 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5786 | /* |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5787 | * For operations with an associated SCSI command, a command block is allocated |
| 5788 | * at init, and managed by cmd_tagged_alloc() and cmd_tagged_free() using the |
| 5789 | * block request tag as an index into a table of entries. cmd_tagged_free() is |
| 5790 | * the complement, although cmd_free() may be called instead. |
| 5791 | */ |
| 5792 | static struct CommandList *cmd_tagged_alloc(struct ctlr_info *h, |
| 5793 | struct scsi_cmnd *scmd) |
| 5794 | { |
| 5795 | int idx = hpsa_get_cmd_index(scmd); |
| 5796 | struct CommandList *c = h->cmd_pool + idx; |
| 5797 | |
| 5798 | if (idx < HPSA_NRESERVED_CMDS || idx >= h->nr_cmds) { |
| 5799 | dev_err(&h->pdev->dev, "Bad block tag: %d not in [%d..%d]\n", |
| 5800 | idx, HPSA_NRESERVED_CMDS, h->nr_cmds - 1); |
| 5801 | /* The index value comes from the block layer, so if it's out of |
| 5802 | * bounds, it's probably not our bug. |
| 5803 | */ |
| 5804 | BUG(); |
| 5805 | } |
| 5806 | |
| 5807 | atomic_inc(&c->refcount); |
| 5808 | if (unlikely(!hpsa_is_cmd_idle(c))) { |
| 5809 | /* |
| 5810 | * We expect that the SCSI layer will hand us a unique tag |
| 5811 | * value. Thus, there should never be a collision here between |
| 5812 | * two requests...because if the selected command isn't idle |
| 5813 | * then someone is going to be very disappointed. |
| 5814 | */ |
| 5815 | dev_err(&h->pdev->dev, |
| 5816 | "tag collision (tag=%d) in cmd_tagged_alloc().\n", |
| 5817 | idx); |
| 5818 | if (c->scsi_cmd != NULL) |
| 5819 | scsi_print_command(c->scsi_cmd); |
| 5820 | scsi_print_command(scmd); |
| 5821 | } |
| 5822 | |
| 5823 | hpsa_cmd_partial_init(h, idx, c); |
| 5824 | return c; |
| 5825 | } |
| 5826 | |
| 5827 | static void cmd_tagged_free(struct ctlr_info *h, struct CommandList *c) |
| 5828 | { |
| 5829 | /* |
| 5830 | * Release our reference to the block. We don't need to do anything |
| 5831 | * else to free it, because it is accessed by index. (There's no point |
| 5832 | * in checking the result of the decrement, since we cannot guarantee |
| 5833 | * that there isn't a concurrent abort which is also accessing it.) |
| 5834 | */ |
| 5835 | (void)atomic_dec(&c->refcount); |
| 5836 | } |
| 5837 | |
| 5838 | /* |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5839 | * For operations that cannot sleep, a command block is allocated at init, |
| 5840 | * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track |
| 5841 | * which ones are free or in use. Lock must be held when calling this. |
| 5842 | * cmd_free() is the complement. |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 5843 | * This function never gives up and returns NULL. If it hangs, |
| 5844 | * another thread must call cmd_free() to free some tags. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5845 | */ |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5846 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5847 | static struct CommandList *cmd_alloc(struct ctlr_info *h) |
| 5848 | { |
| 5849 | struct CommandList *c; |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 5850 | int refcount, i; |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5851 | int offset = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5852 | |
Robert Elliott | 3381102 | 2015-01-23 16:43:41 -0600 | [diff] [blame] | 5853 | /* |
| 5854 | * There is some *extremely* small but non-zero chance that that |
Stephen M. Cameron | 4c41312 | 2014-11-14 17:27:29 -0600 | [diff] [blame] | 5855 | * multiple threads could get in here, and one thread could |
| 5856 | * be scanning through the list of bits looking for a free |
| 5857 | * one, but the free ones are always behind him, and other |
| 5858 | * threads sneak in behind him and eat them before he can |
| 5859 | * get to them, so that while there is always a free one, a |
| 5860 | * very unlucky thread might be starved anyway, never able to |
| 5861 | * beat the other threads. In reality, this happens so |
| 5862 | * infrequently as to be indistinguishable from never. |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5863 | * |
| 5864 | * Note that we start allocating commands before the SCSI host structure |
| 5865 | * is initialized. Since the search starts at bit zero, this |
| 5866 | * all works, since we have at least one command structure available; |
| 5867 | * however, it means that the structures with the low indexes have to be |
| 5868 | * reserved for driver-initiated requests, while requests from the block |
| 5869 | * layer will use the higher indexes. |
Stephen M. Cameron | 4c41312 | 2014-11-14 17:27:29 -0600 | [diff] [blame] | 5870 | */ |
| 5871 | |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5872 | for (;;) { |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5873 | i = find_next_zero_bit(h->cmd_pool_bits, |
| 5874 | HPSA_NRESERVED_CMDS, |
| 5875 | offset); |
| 5876 | if (unlikely(i >= HPSA_NRESERVED_CMDS)) { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5877 | offset = 0; |
| 5878 | continue; |
| 5879 | } |
| 5880 | c = h->cmd_pool + i; |
| 5881 | refcount = atomic_inc_return(&c->refcount); |
| 5882 | if (unlikely(refcount > 1)) { |
| 5883 | cmd_free(h, c); /* already in use */ |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5884 | offset = (i + 1) % HPSA_NRESERVED_CMDS; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5885 | continue; |
| 5886 | } |
| 5887 | set_bit(i & (BITS_PER_LONG - 1), |
| 5888 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 5889 | break; /* it's ours now. */ |
| 5890 | } |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 5891 | hpsa_cmd_partial_init(h, i, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5892 | return c; |
| 5893 | } |
| 5894 | |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5895 | /* |
| 5896 | * This is the complementary operation to cmd_alloc(). Note, however, in some |
| 5897 | * corner cases it may also be used to free blocks allocated by |
| 5898 | * cmd_tagged_alloc() in which case the ref-count decrement does the trick and |
| 5899 | * the clear-bit is harmless. |
| 5900 | */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5901 | static void cmd_free(struct ctlr_info *h, struct CommandList *c) |
| 5902 | { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5903 | if (atomic_dec_and_test(&c->refcount)) { |
| 5904 | int i; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5905 | |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 5906 | i = c - h->cmd_pool; |
| 5907 | clear_bit(i & (BITS_PER_LONG - 1), |
| 5908 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 5909 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5910 | } |
| 5911 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5912 | #ifdef CONFIG_COMPAT |
| 5913 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5914 | static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, |
| 5915 | void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5916 | { |
| 5917 | IOCTL32_Command_struct __user *arg32 = |
| 5918 | (IOCTL32_Command_struct __user *) arg; |
| 5919 | IOCTL_Command_struct arg64; |
| 5920 | IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64)); |
| 5921 | int err; |
| 5922 | u32 cp; |
| 5923 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 5924 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5925 | err = 0; |
| 5926 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 5927 | sizeof(arg64.LUN_info)); |
| 5928 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 5929 | sizeof(arg64.Request)); |
| 5930 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 5931 | sizeof(arg64.error_info)); |
| 5932 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 5933 | err |= get_user(cp, &arg32->buf); |
| 5934 | arg64.buf = compat_ptr(cp); |
| 5935 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 5936 | |
| 5937 | if (err) |
| 5938 | return -EFAULT; |
| 5939 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5940 | err = hpsa_ioctl(dev, CCISS_PASSTHRU, p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5941 | if (err) |
| 5942 | return err; |
| 5943 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 5944 | sizeof(arg32->error_info)); |
| 5945 | if (err) |
| 5946 | return -EFAULT; |
| 5947 | return err; |
| 5948 | } |
| 5949 | |
| 5950 | static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5951 | int cmd, void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5952 | { |
| 5953 | BIG_IOCTL32_Command_struct __user *arg32 = |
| 5954 | (BIG_IOCTL32_Command_struct __user *) arg; |
| 5955 | BIG_IOCTL_Command_struct arg64; |
| 5956 | BIG_IOCTL_Command_struct __user *p = |
| 5957 | compat_alloc_user_space(sizeof(arg64)); |
| 5958 | int err; |
| 5959 | u32 cp; |
| 5960 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 5961 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5962 | err = 0; |
| 5963 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 5964 | sizeof(arg64.LUN_info)); |
| 5965 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 5966 | sizeof(arg64.Request)); |
| 5967 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 5968 | sizeof(arg64.error_info)); |
| 5969 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 5970 | err |= get_user(arg64.malloc_size, &arg32->malloc_size); |
| 5971 | err |= get_user(cp, &arg32->buf); |
| 5972 | arg64.buf = compat_ptr(cp); |
| 5973 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 5974 | |
| 5975 | if (err) |
| 5976 | return -EFAULT; |
| 5977 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5978 | err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5979 | if (err) |
| 5980 | return err; |
| 5981 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 5982 | sizeof(arg32->error_info)); |
| 5983 | if (err) |
| 5984 | return -EFAULT; |
| 5985 | return err; |
| 5986 | } |
Stephen M. Cameron | 71fe75a | 2010-02-04 08:43:51 -0600 | [diff] [blame] | 5987 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 5988 | 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] | 5989 | { |
| 5990 | switch (cmd) { |
| 5991 | case CCISS_GETPCIINFO: |
| 5992 | case CCISS_GETINTINFO: |
| 5993 | case CCISS_SETINTINFO: |
| 5994 | case CCISS_GETNODENAME: |
| 5995 | case CCISS_SETNODENAME: |
| 5996 | case CCISS_GETHEARTBEAT: |
| 5997 | case CCISS_GETBUSTYPES: |
| 5998 | case CCISS_GETFIRMVER: |
| 5999 | case CCISS_GETDRIVVER: |
| 6000 | case CCISS_REVALIDVOLS: |
| 6001 | case CCISS_DEREGDISK: |
| 6002 | case CCISS_REGNEWDISK: |
| 6003 | case CCISS_REGNEWD: |
| 6004 | case CCISS_RESCANDISK: |
| 6005 | case CCISS_GETLUNINFO: |
| 6006 | return hpsa_ioctl(dev, cmd, arg); |
| 6007 | |
| 6008 | case CCISS_PASSTHRU32: |
| 6009 | return hpsa_ioctl32_passthru(dev, cmd, arg); |
| 6010 | case CCISS_BIG_PASSTHRU32: |
| 6011 | return hpsa_ioctl32_big_passthru(dev, cmd, arg); |
| 6012 | |
| 6013 | default: |
| 6014 | return -ENOIOCTLCMD; |
| 6015 | } |
| 6016 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6017 | #endif |
| 6018 | |
| 6019 | static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp) |
| 6020 | { |
| 6021 | struct hpsa_pci_info pciinfo; |
| 6022 | |
| 6023 | if (!argp) |
| 6024 | return -EINVAL; |
| 6025 | pciinfo.domain = pci_domain_nr(h->pdev->bus); |
| 6026 | pciinfo.bus = h->pdev->bus->number; |
| 6027 | pciinfo.dev_fn = h->pdev->devfn; |
| 6028 | pciinfo.board_id = h->board_id; |
| 6029 | if (copy_to_user(argp, &pciinfo, sizeof(pciinfo))) |
| 6030 | return -EFAULT; |
| 6031 | return 0; |
| 6032 | } |
| 6033 | |
| 6034 | static int hpsa_getdrivver_ioctl(struct ctlr_info *h, void __user *argp) |
| 6035 | { |
| 6036 | DriverVer_type DriverVer; |
| 6037 | unsigned char vmaj, vmin, vsubmin; |
| 6038 | int rc; |
| 6039 | |
| 6040 | rc = sscanf(HPSA_DRIVER_VERSION, "%hhu.%hhu.%hhu", |
| 6041 | &vmaj, &vmin, &vsubmin); |
| 6042 | if (rc != 3) { |
| 6043 | dev_info(&h->pdev->dev, "driver version string '%s' " |
| 6044 | "unrecognized.", HPSA_DRIVER_VERSION); |
| 6045 | vmaj = 0; |
| 6046 | vmin = 0; |
| 6047 | vsubmin = 0; |
| 6048 | } |
| 6049 | DriverVer = (vmaj << 16) | (vmin << 8) | vsubmin; |
| 6050 | if (!argp) |
| 6051 | return -EINVAL; |
| 6052 | if (copy_to_user(argp, &DriverVer, sizeof(DriverVer_type))) |
| 6053 | return -EFAULT; |
| 6054 | return 0; |
| 6055 | } |
| 6056 | |
| 6057 | static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 6058 | { |
| 6059 | IOCTL_Command_struct iocommand; |
| 6060 | struct CommandList *c; |
| 6061 | char *buff = NULL; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6062 | u64 temp64; |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6063 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6064 | |
| 6065 | if (!argp) |
| 6066 | return -EINVAL; |
| 6067 | if (!capable(CAP_SYS_RAWIO)) |
| 6068 | return -EPERM; |
| 6069 | if (copy_from_user(&iocommand, argp, sizeof(iocommand))) |
| 6070 | return -EFAULT; |
| 6071 | if ((iocommand.buf_size < 1) && |
| 6072 | (iocommand.Request.Type.Direction != XFER_NONE)) { |
| 6073 | return -EINVAL; |
| 6074 | } |
| 6075 | if (iocommand.buf_size > 0) { |
| 6076 | buff = kmalloc(iocommand.buf_size, GFP_KERNEL); |
| 6077 | if (buff == NULL) |
Robert Elliott | 2dd02d7 | 2015-04-23 09:33:43 -0500 | [diff] [blame] | 6078 | return -ENOMEM; |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6079 | if (iocommand.Request.Type.Direction & XFER_WRITE) { |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6080 | /* Copy the data into the buffer we created */ |
| 6081 | if (copy_from_user(buff, iocommand.buf, |
| 6082 | iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6083 | rc = -EFAULT; |
| 6084 | goto out_kfree; |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6085 | } |
| 6086 | } else { |
| 6087 | memset(buff, 0, iocommand.buf_size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6088 | } |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6089 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6090 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6091 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6092 | /* Fill in the command type */ |
| 6093 | c->cmd_type = CMD_IOCTL_PEND; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6094 | c->scsi_cmd = SCSI_CMD_BUSY; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6095 | /* Fill in Command Header */ |
| 6096 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 6097 | if (iocommand.buf_size > 0) { /* buffer to fill */ |
| 6098 | c->Header.SGList = 1; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6099 | c->Header.SGTotal = cpu_to_le16(1); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6100 | } else { /* no buffers to fill */ |
| 6101 | c->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6102 | c->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6103 | } |
| 6104 | memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6105 | |
| 6106 | /* Fill in Request block */ |
| 6107 | memcpy(&c->Request, &iocommand.Request, |
| 6108 | sizeof(c->Request)); |
| 6109 | |
| 6110 | /* Fill in the scatter gather information */ |
| 6111 | if (iocommand.buf_size > 0) { |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6112 | temp64 = pci_map_single(h->pdev, buff, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6113 | iocommand.buf_size, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6114 | if (dma_mapping_error(&h->pdev->dev, (dma_addr_t) temp64)) { |
| 6115 | c->SG[0].Addr = cpu_to_le64(0); |
| 6116 | c->SG[0].Len = cpu_to_le32(0); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 6117 | rc = -ENOMEM; |
| 6118 | goto out; |
| 6119 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6120 | c->SG[0].Addr = cpu_to_le64(temp64); |
| 6121 | c->SG[0].Len = cpu_to_le32(iocommand.buf_size); |
| 6122 | 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] | 6123 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6124 | rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, NO_TIMEOUT); |
Stephen M. Cameron | c2dd32e | 2011-06-03 09:57:29 -0500 | [diff] [blame] | 6125 | if (iocommand.buf_size > 0) |
| 6126 | hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6127 | check_ioctl_unit_attention(h, c); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6128 | if (rc) { |
| 6129 | rc = -EIO; |
| 6130 | goto out; |
| 6131 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6132 | |
| 6133 | /* Copy the error information out */ |
| 6134 | memcpy(&iocommand.error_info, c->err_info, |
| 6135 | sizeof(iocommand.error_info)); |
| 6136 | if (copy_to_user(argp, &iocommand, sizeof(iocommand))) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6137 | rc = -EFAULT; |
| 6138 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6139 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6140 | if ((iocommand.Request.Type.Direction & XFER_READ) && |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6141 | iocommand.buf_size > 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6142 | /* Copy the data out of the buffer we created */ |
| 6143 | if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6144 | rc = -EFAULT; |
| 6145 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6146 | } |
| 6147 | } |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6148 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6149 | cmd_free(h, c); |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6150 | out_kfree: |
| 6151 | kfree(buff); |
| 6152 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 6156 | { |
| 6157 | BIG_IOCTL_Command_struct *ioc; |
| 6158 | struct CommandList *c; |
| 6159 | unsigned char **buff = NULL; |
| 6160 | int *buff_size = NULL; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6161 | u64 temp64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6162 | BYTE sg_used = 0; |
| 6163 | int status = 0; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 6164 | u32 left; |
| 6165 | u32 sz; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6166 | BYTE __user *data_ptr; |
| 6167 | |
| 6168 | if (!argp) |
| 6169 | return -EINVAL; |
| 6170 | if (!capable(CAP_SYS_RAWIO)) |
| 6171 | return -EPERM; |
| 6172 | ioc = (BIG_IOCTL_Command_struct *) |
| 6173 | kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 6174 | if (!ioc) { |
| 6175 | status = -ENOMEM; |
| 6176 | goto cleanup1; |
| 6177 | } |
| 6178 | if (copy_from_user(ioc, argp, sizeof(*ioc))) { |
| 6179 | status = -EFAULT; |
| 6180 | goto cleanup1; |
| 6181 | } |
| 6182 | if ((ioc->buf_size < 1) && |
| 6183 | (ioc->Request.Type.Direction != XFER_NONE)) { |
| 6184 | status = -EINVAL; |
| 6185 | goto cleanup1; |
| 6186 | } |
| 6187 | /* Check kmalloc limits using all SGs */ |
| 6188 | if (ioc->malloc_size > MAX_KMALLOC_SIZE) { |
| 6189 | status = -EINVAL; |
| 6190 | goto cleanup1; |
| 6191 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6192 | if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6193 | status = -EINVAL; |
| 6194 | goto cleanup1; |
| 6195 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6196 | buff = kzalloc(SG_ENTRIES_IN_CMD * sizeof(char *), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6197 | if (!buff) { |
| 6198 | status = -ENOMEM; |
| 6199 | goto cleanup1; |
| 6200 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6201 | buff_size = kmalloc(SG_ENTRIES_IN_CMD * sizeof(int), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6202 | if (!buff_size) { |
| 6203 | status = -ENOMEM; |
| 6204 | goto cleanup1; |
| 6205 | } |
| 6206 | left = ioc->buf_size; |
| 6207 | data_ptr = ioc->buf; |
| 6208 | while (left) { |
| 6209 | sz = (left > ioc->malloc_size) ? ioc->malloc_size : left; |
| 6210 | buff_size[sg_used] = sz; |
| 6211 | buff[sg_used] = kmalloc(sz, GFP_KERNEL); |
| 6212 | if (buff[sg_used] == NULL) { |
| 6213 | status = -ENOMEM; |
| 6214 | goto cleanup1; |
| 6215 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6216 | if (ioc->Request.Type.Direction & XFER_WRITE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6217 | if (copy_from_user(buff[sg_used], data_ptr, sz)) { |
Stephen M. Cameron | 0758f4f | 2014-07-03 10:18:03 -0500 | [diff] [blame] | 6218 | status = -EFAULT; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6219 | goto cleanup1; |
| 6220 | } |
| 6221 | } else |
| 6222 | memset(buff[sg_used], 0, sz); |
| 6223 | left -= sz; |
| 6224 | data_ptr += sz; |
| 6225 | sg_used++; |
| 6226 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6227 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6228 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6229 | c->cmd_type = CMD_IOCTL_PEND; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6230 | c->scsi_cmd = SCSI_CMD_BUSY; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6231 | c->Header.ReplyQueue = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6232 | c->Header.SGList = (u8) sg_used; |
| 6233 | c->Header.SGTotal = cpu_to_le16(sg_used); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6234 | memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6235 | memcpy(&c->Request, &ioc->Request, sizeof(c->Request)); |
| 6236 | if (ioc->buf_size > 0) { |
| 6237 | int i; |
| 6238 | for (i = 0; i < sg_used; i++) { |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6239 | temp64 = pci_map_single(h->pdev, buff[i], |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6240 | buff_size[i], PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6241 | if (dma_mapping_error(&h->pdev->dev, |
| 6242 | (dma_addr_t) temp64)) { |
| 6243 | c->SG[i].Addr = cpu_to_le64(0); |
| 6244 | c->SG[i].Len = cpu_to_le32(0); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 6245 | hpsa_pci_unmap(h->pdev, c, i, |
| 6246 | PCI_DMA_BIDIRECTIONAL); |
| 6247 | status = -ENOMEM; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6248 | goto cleanup0; |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 6249 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6250 | c->SG[i].Addr = cpu_to_le64(temp64); |
| 6251 | c->SG[i].Len = cpu_to_le32(buff_size[i]); |
| 6252 | c->SG[i].Ext = cpu_to_le32(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6253 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6254 | c->SG[--i].Ext = cpu_to_le32(HPSA_SG_LAST); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6255 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6256 | status = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, NO_TIMEOUT); |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6257 | if (sg_used) |
| 6258 | hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6259 | check_ioctl_unit_attention(h, c); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6260 | if (status) { |
| 6261 | status = -EIO; |
| 6262 | goto cleanup0; |
| 6263 | } |
| 6264 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6265 | /* Copy the error information out */ |
| 6266 | memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info)); |
| 6267 | if (copy_to_user(argp, ioc, sizeof(*ioc))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6268 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6269 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6270 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6271 | if ((ioc->Request.Type.Direction & XFER_READ) && ioc->buf_size > 0) { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6272 | int i; |
| 6273 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6274 | /* Copy the data out of the buffer we created */ |
| 6275 | BYTE __user *ptr = ioc->buf; |
| 6276 | for (i = 0; i < sg_used; i++) { |
| 6277 | if (copy_to_user(ptr, buff[i], buff_size[i])) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6278 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6279 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6280 | } |
| 6281 | ptr += buff_size[i]; |
| 6282 | } |
| 6283 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6284 | status = 0; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6285 | cleanup0: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6286 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6287 | cleanup1: |
| 6288 | if (buff) { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6289 | int i; |
| 6290 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6291 | for (i = 0; i < sg_used; i++) |
| 6292 | kfree(buff[i]); |
| 6293 | kfree(buff); |
| 6294 | } |
| 6295 | kfree(buff_size); |
| 6296 | kfree(ioc); |
| 6297 | return status; |
| 6298 | } |
| 6299 | |
| 6300 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 6301 | struct CommandList *c) |
| 6302 | { |
| 6303 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 6304 | c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) |
| 6305 | (void) check_for_unit_attention(h, c); |
| 6306 | } |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6307 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6308 | /* |
| 6309 | * ioctl |
| 6310 | */ |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6311 | 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] | 6312 | { |
| 6313 | struct ctlr_info *h; |
| 6314 | void __user *argp = (void __user *)arg; |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6315 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6316 | |
| 6317 | h = sdev_to_hba(dev); |
| 6318 | |
| 6319 | switch (cmd) { |
| 6320 | case CCISS_DEREGDISK: |
| 6321 | case CCISS_REGNEWDISK: |
| 6322 | case CCISS_REGNEWD: |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 6323 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6324 | return 0; |
| 6325 | case CCISS_GETPCIINFO: |
| 6326 | return hpsa_getpciinfo_ioctl(h, argp); |
| 6327 | case CCISS_GETDRIVVER: |
| 6328 | return hpsa_getdrivver_ioctl(h, argp); |
| 6329 | case CCISS_PASSTHRU: |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6330 | if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0) |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6331 | return -EAGAIN; |
| 6332 | rc = hpsa_passthru_ioctl(h, argp); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6333 | atomic_inc(&h->passthru_cmds_avail); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6334 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6335 | case CCISS_BIG_PASSTHRU: |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6336 | if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0) |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6337 | return -EAGAIN; |
| 6338 | rc = hpsa_big_passthru_ioctl(h, argp); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6339 | atomic_inc(&h->passthru_cmds_avail); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6340 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6341 | default: |
| 6342 | return -ENOTTY; |
| 6343 | } |
| 6344 | } |
| 6345 | |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6346 | static void hpsa_send_host_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6347 | u8 reset_type) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6348 | { |
| 6349 | struct CommandList *c; |
| 6350 | |
| 6351 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6352 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6353 | /* fill_cmd can't fail here, no data buffer to map */ |
| 6354 | (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] | 6355 | RAID_CTLR_LUNID, TYPE_MSG); |
| 6356 | c->Request.CDB[1] = reset_type; /* fill_cmd defaults to target reset */ |
| 6357 | c->waiting = NULL; |
| 6358 | enqueue_cmd_and_start_io(h, c); |
| 6359 | /* Don't wait for completion, the reset won't complete. Don't free |
| 6360 | * the command either. This is the last command we will send before |
| 6361 | * re-initializing everything, so it doesn't matter and won't leak. |
| 6362 | */ |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6363 | return; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6364 | } |
| 6365 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6366 | 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] | 6367 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6368 | int cmd_type) |
| 6369 | { |
| 6370 | int pci_dir = XFER_NONE; |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6371 | u64 tag; /* for commands to be aborted */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6372 | |
| 6373 | c->cmd_type = CMD_IOCTL_PEND; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6374 | c->scsi_cmd = SCSI_CMD_BUSY; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6375 | c->Header.ReplyQueue = 0; |
| 6376 | if (buff != NULL && size > 0) { |
| 6377 | c->Header.SGList = 1; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6378 | c->Header.SGTotal = cpu_to_le16(1); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6379 | } else { |
| 6380 | c->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6381 | c->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6382 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6383 | memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8); |
| 6384 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6385 | if (cmd_type == TYPE_CMD) { |
| 6386 | switch (cmd) { |
| 6387 | case HPSA_INQUIRY: |
| 6388 | /* are we trying to read a vital product page */ |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 6389 | if (page_code & VPD_PAGE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6390 | c->Request.CDB[1] = 0x01; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 6391 | c->Request.CDB[2] = (page_code & 0xff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6392 | } |
| 6393 | c->Request.CDBLen = 6; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6394 | c->Request.type_attr_dir = |
| 6395 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6396 | c->Request.Timeout = 0; |
| 6397 | c->Request.CDB[0] = HPSA_INQUIRY; |
| 6398 | c->Request.CDB[4] = size & 0xFF; |
| 6399 | break; |
| 6400 | case HPSA_REPORT_LOG: |
| 6401 | case HPSA_REPORT_PHYS: |
| 6402 | /* Talking to controller so It's a physical command |
| 6403 | mode = 00 target = 0. Nothing to write. |
| 6404 | */ |
| 6405 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6406 | c->Request.type_attr_dir = |
| 6407 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6408 | c->Request.Timeout = 0; |
| 6409 | c->Request.CDB[0] = cmd; |
| 6410 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 6411 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6412 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 6413 | c->Request.CDB[9] = size & 0xFF; |
| 6414 | break; |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 6415 | case BMIC_SENSE_DIAG_OPTIONS: |
| 6416 | c->Request.CDBLen = 16; |
| 6417 | c->Request.type_attr_dir = |
| 6418 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 6419 | c->Request.Timeout = 0; |
| 6420 | /* Spec says this should be BMIC_WRITE */ |
| 6421 | c->Request.CDB[0] = BMIC_READ; |
| 6422 | c->Request.CDB[6] = BMIC_SENSE_DIAG_OPTIONS; |
| 6423 | break; |
| 6424 | case BMIC_SET_DIAG_OPTIONS: |
| 6425 | c->Request.CDBLen = 16; |
| 6426 | c->Request.type_attr_dir = |
| 6427 | TYPE_ATTR_DIR(cmd_type, |
| 6428 | ATTR_SIMPLE, XFER_WRITE); |
| 6429 | c->Request.Timeout = 0; |
| 6430 | c->Request.CDB[0] = BMIC_WRITE; |
| 6431 | c->Request.CDB[6] = BMIC_SET_DIAG_OPTIONS; |
| 6432 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6433 | case HPSA_CACHE_FLUSH: |
| 6434 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6435 | c->Request.type_attr_dir = |
| 6436 | TYPE_ATTR_DIR(cmd_type, |
| 6437 | ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6438 | c->Request.Timeout = 0; |
| 6439 | c->Request.CDB[0] = BMIC_WRITE; |
| 6440 | c->Request.CDB[6] = BMIC_CACHE_FLUSH; |
Stephen M. Cameron | bb158ea | 2011-10-26 16:21:17 -0500 | [diff] [blame] | 6441 | c->Request.CDB[7] = (size >> 8) & 0xFF; |
| 6442 | c->Request.CDB[8] = size & 0xFF; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6443 | break; |
| 6444 | case TEST_UNIT_READY: |
| 6445 | c->Request.CDBLen = 6; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6446 | c->Request.type_attr_dir = |
| 6447 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6448 | c->Request.Timeout = 0; |
| 6449 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6450 | case HPSA_GET_RAID_MAP: |
| 6451 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6452 | c->Request.type_attr_dir = |
| 6453 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6454 | c->Request.Timeout = 0; |
| 6455 | c->Request.CDB[0] = HPSA_CISS_READ; |
| 6456 | c->Request.CDB[1] = cmd; |
| 6457 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 6458 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6459 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 6460 | c->Request.CDB[9] = size & 0xFF; |
| 6461 | break; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 6462 | case BMIC_SENSE_CONTROLLER_PARAMETERS: |
| 6463 | c->Request.CDBLen = 10; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6464 | c->Request.type_attr_dir = |
| 6465 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 6466 | c->Request.Timeout = 0; |
| 6467 | c->Request.CDB[0] = BMIC_READ; |
| 6468 | c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS; |
| 6469 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6470 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 6471 | break; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 6472 | case BMIC_IDENTIFY_PHYSICAL_DEVICE: |
| 6473 | c->Request.CDBLen = 10; |
| 6474 | c->Request.type_attr_dir = |
| 6475 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 6476 | c->Request.Timeout = 0; |
| 6477 | c->Request.CDB[0] = BMIC_READ; |
| 6478 | c->Request.CDB[6] = BMIC_IDENTIFY_PHYSICAL_DEVICE; |
| 6479 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6480 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 6481 | break; |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 6482 | case BMIC_IDENTIFY_CONTROLLER: |
| 6483 | c->Request.CDBLen = 10; |
| 6484 | c->Request.type_attr_dir = |
| 6485 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 6486 | c->Request.Timeout = 0; |
| 6487 | c->Request.CDB[0] = BMIC_READ; |
| 6488 | c->Request.CDB[1] = 0; |
| 6489 | c->Request.CDB[2] = 0; |
| 6490 | c->Request.CDB[3] = 0; |
| 6491 | c->Request.CDB[4] = 0; |
| 6492 | c->Request.CDB[5] = 0; |
| 6493 | c->Request.CDB[6] = BMIC_IDENTIFY_CONTROLLER; |
| 6494 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6495 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 6496 | c->Request.CDB[9] = 0; |
| 6497 | break; |
| 6498 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6499 | default: |
| 6500 | dev_warn(&h->pdev->dev, "unknown command 0x%c\n", cmd); |
| 6501 | BUG(); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6502 | return -1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6503 | } |
| 6504 | } else if (cmd_type == TYPE_MSG) { |
| 6505 | switch (cmd) { |
| 6506 | |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 6507 | case HPSA_PHYS_TARGET_RESET: |
| 6508 | c->Request.CDBLen = 16; |
| 6509 | c->Request.type_attr_dir = |
| 6510 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
| 6511 | c->Request.Timeout = 0; /* Don't time out */ |
| 6512 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
| 6513 | c->Request.CDB[0] = HPSA_RESET; |
| 6514 | c->Request.CDB[1] = HPSA_TARGET_RESET_TYPE; |
| 6515 | /* Physical target reset needs no control bytes 4-7*/ |
| 6516 | c->Request.CDB[4] = 0x00; |
| 6517 | c->Request.CDB[5] = 0x00; |
| 6518 | c->Request.CDB[6] = 0x00; |
| 6519 | c->Request.CDB[7] = 0x00; |
| 6520 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6521 | case HPSA_DEVICE_RESET_MSG: |
| 6522 | c->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6523 | c->Request.type_attr_dir = |
| 6524 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6525 | c->Request.Timeout = 0; /* Don't time out */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6526 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
| 6527 | c->Request.CDB[0] = cmd; |
Stephen M. Cameron | 21e89af | 2012-07-26 11:34:10 -0500 | [diff] [blame] | 6528 | c->Request.CDB[1] = HPSA_RESET_TYPE_LUN; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6529 | /* If bytes 4-7 are zero, it means reset the */ |
| 6530 | /* LunID device */ |
| 6531 | c->Request.CDB[4] = 0x00; |
| 6532 | c->Request.CDB[5] = 0x00; |
| 6533 | c->Request.CDB[6] = 0x00; |
| 6534 | c->Request.CDB[7] = 0x00; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6535 | break; |
| 6536 | case HPSA_ABORT_MSG: |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6537 | memcpy(&tag, buff, sizeof(tag)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6538 | dev_dbg(&h->pdev->dev, |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6539 | "Abort Tag:0x%016llx using rqst Tag:0x%016llx", |
| 6540 | tag, c->Header.tag); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6541 | c->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6542 | c->Request.type_attr_dir = |
| 6543 | TYPE_ATTR_DIR(cmd_type, |
| 6544 | ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6545 | c->Request.Timeout = 0; /* Don't time out */ |
| 6546 | c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; |
| 6547 | c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; |
| 6548 | c->Request.CDB[2] = 0x00; /* reserved */ |
| 6549 | c->Request.CDB[3] = 0x00; /* reserved */ |
| 6550 | /* Tag to abort goes in CDB[4]-CDB[11] */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6551 | memcpy(&c->Request.CDB[4], &tag, sizeof(tag)); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6552 | c->Request.CDB[12] = 0x00; /* reserved */ |
| 6553 | c->Request.CDB[13] = 0x00; /* reserved */ |
| 6554 | c->Request.CDB[14] = 0x00; /* reserved */ |
| 6555 | c->Request.CDB[15] = 0x00; /* reserved */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6556 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6557 | default: |
| 6558 | dev_warn(&h->pdev->dev, "unknown message type %d\n", |
| 6559 | cmd); |
| 6560 | BUG(); |
| 6561 | } |
| 6562 | } else { |
| 6563 | dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type); |
| 6564 | BUG(); |
| 6565 | } |
| 6566 | |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6567 | switch (GET_DIR(c->Request.type_attr_dir)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6568 | case XFER_READ: |
| 6569 | pci_dir = PCI_DMA_FROMDEVICE; |
| 6570 | break; |
| 6571 | case XFER_WRITE: |
| 6572 | pci_dir = PCI_DMA_TODEVICE; |
| 6573 | break; |
| 6574 | case XFER_NONE: |
| 6575 | pci_dir = PCI_DMA_NONE; |
| 6576 | break; |
| 6577 | default: |
| 6578 | pci_dir = PCI_DMA_BIDIRECTIONAL; |
| 6579 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6580 | if (hpsa_map_one(h->pdev, c, buff, size, pci_dir)) |
| 6581 | return -1; |
| 6582 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6583 | } |
| 6584 | |
| 6585 | /* |
| 6586 | * Map (physical) PCI mem into (virtual) kernel space |
| 6587 | */ |
| 6588 | static void __iomem *remap_pci_mem(ulong base, ulong size) |
| 6589 | { |
| 6590 | ulong page_base = ((ulong) base) & PAGE_MASK; |
| 6591 | ulong page_offs = ((ulong) base) - page_base; |
Stephen M. Cameron | 088ba34c | 2012-07-26 11:34:23 -0500 | [diff] [blame] | 6592 | void __iomem *page_remapped = ioremap_nocache(page_base, |
| 6593 | page_offs + size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6594 | |
| 6595 | return page_remapped ? (page_remapped + page_offs) : NULL; |
| 6596 | } |
| 6597 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6598 | 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] | 6599 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6600 | return h->access.command_completed(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6601 | } |
| 6602 | |
Stephen M. Cameron | 900c544 | 2010-02-04 08:42:35 -0600 | [diff] [blame] | 6603 | static inline bool interrupt_pending(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6604 | { |
| 6605 | return h->access.intr_pending(h); |
| 6606 | } |
| 6607 | |
| 6608 | static inline long interrupt_not_for_us(struct ctlr_info *h) |
| 6609 | { |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6610 | return (h->access.intr_pending(h) == 0) || |
| 6611 | (h->interrupts_enabled == 0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6612 | } |
| 6613 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 6614 | static inline int bad_tag(struct ctlr_info *h, u32 tag_index, |
| 6615 | u32 raw_tag) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6616 | { |
| 6617 | if (unlikely(tag_index >= h->nr_cmds)) { |
| 6618 | dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag); |
| 6619 | return 1; |
| 6620 | } |
| 6621 | return 0; |
| 6622 | } |
| 6623 | |
Stephen M. Cameron | 5a3d16f | 2012-05-01 11:42:46 -0500 | [diff] [blame] | 6624 | static inline void finish_cmd(struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6625 | { |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 6626 | dial_up_lockup_detection_on_fw_flash_complete(c->h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 6627 | if (likely(c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_SCSI |
| 6628 | || c->cmd_type == CMD_IOACCEL2)) |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 6629 | complete_scsi_command(c); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6630 | else if (c->cmd_type == CMD_IOCTL_PEND || c->cmd_type == IOACCEL2_TMF) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6631 | complete(c->waiting); |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 6632 | } |
| 6633 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6634 | /* process completion of an indexed ("direct lookup") command */ |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 6635 | static inline void process_indexed_cmd(struct ctlr_info *h, |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6636 | u32 raw_tag) |
| 6637 | { |
| 6638 | u32 tag_index; |
| 6639 | struct CommandList *c; |
| 6640 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6641 | tag_index = raw_tag >> DIRECT_LOOKUP_SHIFT; |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 6642 | if (!bad_tag(h, tag_index, raw_tag)) { |
| 6643 | c = h->cmd_pool + tag_index; |
| 6644 | finish_cmd(c); |
| 6645 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6646 | } |
| 6647 | |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6648 | /* Some controllers, like p400, will give us one interrupt |
| 6649 | * after a soft reset, even if we turned interrupts off. |
| 6650 | * Only need to check for this in the hpsa_xxx_discard_completions |
| 6651 | * functions. |
| 6652 | */ |
| 6653 | static int ignore_bogus_interrupt(struct ctlr_info *h) |
| 6654 | { |
| 6655 | if (likely(!reset_devices)) |
| 6656 | return 0; |
| 6657 | |
| 6658 | if (likely(h->interrupts_enabled)) |
| 6659 | return 0; |
| 6660 | |
| 6661 | dev_info(&h->pdev->dev, "Received interrupt while interrupts disabled " |
| 6662 | "(known firmware bug.) Ignoring.\n"); |
| 6663 | |
| 6664 | return 1; |
| 6665 | } |
| 6666 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6667 | /* |
| 6668 | * Convert &h->q[x] (passed to interrupt handlers) back to h. |
| 6669 | * Relies on (h-q[x] == x) being true for x such that |
| 6670 | * 0 <= x < MAX_REPLY_QUEUES. |
| 6671 | */ |
| 6672 | static struct ctlr_info *queue_to_hba(u8 *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6673 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6674 | return container_of((queue - *queue), struct ctlr_info, q[0]); |
| 6675 | } |
| 6676 | |
| 6677 | static irqreturn_t hpsa_intx_discard_completions(int irq, void *queue) |
| 6678 | { |
| 6679 | struct ctlr_info *h = queue_to_hba(queue); |
| 6680 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6681 | u32 raw_tag; |
| 6682 | |
| 6683 | if (ignore_bogus_interrupt(h)) |
| 6684 | return IRQ_NONE; |
| 6685 | |
| 6686 | if (interrupt_not_for_us(h)) |
| 6687 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6688 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6689 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6690 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6691 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6692 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6693 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6694 | return IRQ_HANDLED; |
| 6695 | } |
| 6696 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6697 | static irqreturn_t hpsa_msix_discard_completions(int irq, void *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6698 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6699 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6700 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6701 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6702 | |
| 6703 | if (ignore_bogus_interrupt(h)) |
| 6704 | return IRQ_NONE; |
| 6705 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6706 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6707 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6708 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6709 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6710 | return IRQ_HANDLED; |
| 6711 | } |
| 6712 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6713 | static irqreturn_t do_hpsa_intr_intx(int irq, void *queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6714 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6715 | struct ctlr_info *h = queue_to_hba((u8 *) queue); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6716 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6717 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6718 | |
| 6719 | if (interrupt_not_for_us(h)) |
| 6720 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6721 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6722 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6723 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6724 | while (raw_tag != FIFO_EMPTY) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6725 | process_indexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6726 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6727 | } |
| 6728 | } |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6729 | return IRQ_HANDLED; |
| 6730 | } |
| 6731 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6732 | static irqreturn_t do_hpsa_intr_msi(int irq, void *queue) |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6733 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6734 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6735 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6736 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 6737 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 6738 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6739 | raw_tag = get_next_completion(h, q); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 6740 | while (raw_tag != FIFO_EMPTY) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 6741 | process_indexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 6742 | raw_tag = next_command(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6743 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6744 | return IRQ_HANDLED; |
| 6745 | } |
| 6746 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 6747 | /* Send a message CDB to the firmware. Careful, this only works |
| 6748 | * in simple mode, not performant mode due to the tag lookup. |
| 6749 | * We only ever use this immediately after a controller reset. |
| 6750 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6751 | static int hpsa_message(struct pci_dev *pdev, unsigned char opcode, |
| 6752 | unsigned char type) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6753 | { |
| 6754 | struct Command { |
| 6755 | struct CommandListHeader CommandHeader; |
| 6756 | struct RequestBlock Request; |
| 6757 | struct ErrDescriptor ErrorDescriptor; |
| 6758 | }; |
| 6759 | struct Command *cmd; |
| 6760 | static const size_t cmd_sz = sizeof(*cmd) + |
| 6761 | sizeof(cmd->ErrorDescriptor); |
| 6762 | dma_addr_t paddr64; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6763 | __le32 paddr32; |
| 6764 | u32 tag; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6765 | void __iomem *vaddr; |
| 6766 | int i, err; |
| 6767 | |
| 6768 | vaddr = pci_ioremap_bar(pdev, 0); |
| 6769 | if (vaddr == NULL) |
| 6770 | return -ENOMEM; |
| 6771 | |
| 6772 | /* The Inbound Post Queue only accepts 32-bit physical addresses for the |
| 6773 | * CCISS commands, so they must be allocated from the lower 4GiB of |
| 6774 | * memory. |
| 6775 | */ |
| 6776 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 6777 | if (err) { |
| 6778 | iounmap(vaddr); |
Robert Elliott | 1eaec8f | 2015-01-23 16:42:37 -0600 | [diff] [blame] | 6779 | return err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | cmd = pci_alloc_consistent(pdev, cmd_sz, &paddr64); |
| 6783 | if (cmd == NULL) { |
| 6784 | iounmap(vaddr); |
| 6785 | return -ENOMEM; |
| 6786 | } |
| 6787 | |
| 6788 | /* This must fit, because of the 32-bit consistent DMA mask. Also, |
| 6789 | * although there's no guarantee, we assume that the address is at |
| 6790 | * least 4-byte aligned (most likely, it's page-aligned). |
| 6791 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6792 | paddr32 = cpu_to_le32(paddr64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6793 | |
| 6794 | cmd->CommandHeader.ReplyQueue = 0; |
| 6795 | cmd->CommandHeader.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6796 | cmd->CommandHeader.SGTotal = cpu_to_le16(0); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6797 | cmd->CommandHeader.tag = cpu_to_le64(paddr64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6798 | memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8); |
| 6799 | |
| 6800 | cmd->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6801 | cmd->Request.type_attr_dir = |
| 6802 | TYPE_ATTR_DIR(TYPE_MSG, ATTR_HEADOFQUEUE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6803 | cmd->Request.Timeout = 0; /* Don't time out */ |
| 6804 | cmd->Request.CDB[0] = opcode; |
| 6805 | cmd->Request.CDB[1] = type; |
| 6806 | 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] | 6807 | cmd->ErrorDescriptor.Addr = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6808 | cpu_to_le64((le32_to_cpu(paddr32) + sizeof(*cmd))); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6809 | cmd->ErrorDescriptor.Len = cpu_to_le32(sizeof(struct ErrorInfo)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6810 | |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6811 | writel(le32_to_cpu(paddr32), vaddr + SA5_REQUEST_PORT_OFFSET); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6812 | |
| 6813 | for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) { |
| 6814 | tag = readl(vaddr + SA5_REPLY_PORT_OFFSET); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6815 | if ((tag & ~HPSA_SIMPLE_ERROR_BITS) == paddr64) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6816 | break; |
| 6817 | msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS); |
| 6818 | } |
| 6819 | |
| 6820 | iounmap(vaddr); |
| 6821 | |
| 6822 | /* we leak the DMA buffer here ... no choice since the controller could |
| 6823 | * still complete the command. |
| 6824 | */ |
| 6825 | if (i == HPSA_MSG_SEND_RETRY_LIMIT) { |
| 6826 | dev_err(&pdev->dev, "controller message %02x:%02x timed out\n", |
| 6827 | opcode, type); |
| 6828 | return -ETIMEDOUT; |
| 6829 | } |
| 6830 | |
| 6831 | pci_free_consistent(pdev, cmd_sz, cmd, paddr64); |
| 6832 | |
| 6833 | if (tag & HPSA_ERROR_BIT) { |
| 6834 | dev_err(&pdev->dev, "controller message %02x:%02x failed\n", |
| 6835 | opcode, type); |
| 6836 | return -EIO; |
| 6837 | } |
| 6838 | |
| 6839 | dev_info(&pdev->dev, "controller message %02x:%02x succeeded\n", |
| 6840 | opcode, type); |
| 6841 | return 0; |
| 6842 | } |
| 6843 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6844 | #define hpsa_noop(p) hpsa_message(p, 3, 0) |
| 6845 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6846 | static int hpsa_controller_hard_reset(struct pci_dev *pdev, |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6847 | void __iomem *vaddr, u32 use_doorbell) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6848 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6849 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6850 | if (use_doorbell) { |
| 6851 | /* For everything after the P600, the PCI power state method |
| 6852 | * of resetting the controller doesn't work, so we have this |
| 6853 | * other way using the doorbell register. |
| 6854 | */ |
| 6855 | dev_info(&pdev->dev, "using doorbell to reset controller\n"); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 6856 | writel(use_doorbell, vaddr + SA5_DOORBELL); |
Stephen M. Cameron | 8500923 | 2013-09-23 13:33:36 -0500 | [diff] [blame] | 6857 | |
Justin Lindley | 00701a9 | 2014-05-29 10:52:47 -0500 | [diff] [blame] | 6858 | /* 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] | 6859 | * doorbell reset and before any attempt to talk to the board |
| 6860 | * at all to ensure that this actually works and doesn't fall |
| 6861 | * over in some weird corner cases. |
| 6862 | */ |
Justin Lindley | 00701a9 | 2014-05-29 10:52:47 -0500 | [diff] [blame] | 6863 | msleep(10000); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6864 | } else { /* Try to do it the PCI power state way */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6865 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6866 | /* Quoting from the Open CISS Specification: "The Power |
| 6867 | * Management Control/Status Register (CSR) controls the power |
| 6868 | * state of the device. The normal operating state is D0, |
| 6869 | * CSR=00h. The software off state is D3, CSR=03h. To reset |
| 6870 | * the controller, place the interface device in D3 then to D0, |
| 6871 | * this causes a secondary PCI reset which will reset the |
| 6872 | * controller." */ |
| 6873 | |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 6874 | int rc = 0; |
| 6875 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6876 | dev_info(&pdev->dev, "using PCI PM to reset controller\n"); |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 6877 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6878 | /* enter the D3hot power management state */ |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 6879 | rc = pci_set_power_state(pdev, PCI_D3hot); |
| 6880 | if (rc) |
| 6881 | return rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6882 | |
| 6883 | msleep(500); |
| 6884 | |
| 6885 | /* enter the D0 power management state */ |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 6886 | rc = pci_set_power_state(pdev, PCI_D0); |
| 6887 | if (rc) |
| 6888 | return rc; |
Mike Miller | c4853ef | 2011-10-21 08:19:43 +0200 | [diff] [blame] | 6889 | |
| 6890 | /* |
| 6891 | * The P600 requires a small delay when changing states. |
| 6892 | * Otherwise we may think the board did not reset and we bail. |
| 6893 | * This for kdump only and is particular to the P600. |
| 6894 | */ |
| 6895 | msleep(500); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6896 | } |
| 6897 | return 0; |
| 6898 | } |
| 6899 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6900 | static void init_driver_version(char *driver_version, int len) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6901 | { |
| 6902 | memset(driver_version, 0, len); |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 6903 | strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1); |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6904 | } |
| 6905 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6906 | static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6907 | { |
| 6908 | char *driver_version; |
| 6909 | int i, size = sizeof(cfgtable->driver_version); |
| 6910 | |
| 6911 | driver_version = kmalloc(size, GFP_KERNEL); |
| 6912 | if (!driver_version) |
| 6913 | return -ENOMEM; |
| 6914 | |
| 6915 | init_driver_version(driver_version, size); |
| 6916 | for (i = 0; i < size; i++) |
| 6917 | writeb(driver_version[i], &cfgtable->driver_version[i]); |
| 6918 | kfree(driver_version); |
| 6919 | return 0; |
| 6920 | } |
| 6921 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6922 | static void read_driver_ver_from_cfgtable(struct CfgTable __iomem *cfgtable, |
| 6923 | unsigned char *driver_ver) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6924 | { |
| 6925 | int i; |
| 6926 | |
| 6927 | for (i = 0; i < sizeof(cfgtable->driver_version); i++) |
| 6928 | driver_ver[i] = readb(&cfgtable->driver_version[i]); |
| 6929 | } |
| 6930 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6931 | static int controller_reset_failed(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6932 | { |
| 6933 | |
| 6934 | char *driver_ver, *old_driver_ver; |
| 6935 | int rc, size = sizeof(cfgtable->driver_version); |
| 6936 | |
| 6937 | old_driver_ver = kmalloc(2 * size, GFP_KERNEL); |
| 6938 | if (!old_driver_ver) |
| 6939 | return -ENOMEM; |
| 6940 | driver_ver = old_driver_ver + size; |
| 6941 | |
| 6942 | /* After a reset, the 32 bytes of "driver version" in the cfgtable |
| 6943 | * should have been changed, otherwise we know the reset failed. |
| 6944 | */ |
| 6945 | init_driver_version(old_driver_ver, size); |
| 6946 | read_driver_ver_from_cfgtable(cfgtable, driver_ver); |
| 6947 | rc = !memcmp(driver_ver, old_driver_ver, size); |
| 6948 | kfree(old_driver_ver); |
| 6949 | return rc; |
| 6950 | } |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6951 | /* This does a hard reset of the controller using PCI power management |
| 6952 | * states or the using the doorbell register. |
| 6953 | */ |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 6954 | 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] | 6955 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6956 | u64 cfg_offset; |
| 6957 | u32 cfg_base_addr; |
| 6958 | u64 cfg_base_addr_index; |
| 6959 | void __iomem *vaddr; |
| 6960 | unsigned long paddr; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 6961 | u32 misc_fw_support; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 6962 | int rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6963 | struct CfgTable __iomem *cfgtable; |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 6964 | u32 use_doorbell; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 6965 | u16 command_register; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6966 | |
| 6967 | /* For controllers as old as the P600, this is very nearly |
| 6968 | * the same thing as |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6969 | * |
| 6970 | * pci_save_state(pci_dev); |
| 6971 | * pci_set_power_state(pci_dev, PCI_D3hot); |
| 6972 | * pci_set_power_state(pci_dev, PCI_D0); |
| 6973 | * pci_restore_state(pci_dev); |
| 6974 | * |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6975 | * For controllers newer than the P600, the pci power state |
| 6976 | * method of resetting doesn't work so we have another way |
| 6977 | * using the doorbell register. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6978 | */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 6979 | |
Robert Elliott | 60f923b | 2015-01-23 16:42:06 -0600 | [diff] [blame] | 6980 | if (!ctlr_is_resettable(board_id)) { |
| 6981 | dev_warn(&pdev->dev, "Controller not resettable\n"); |
Stephen M. Cameron | 25c1e56a | 2011-01-06 14:48:18 -0600 | [diff] [blame] | 6982 | return -ENODEV; |
| 6983 | } |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 6984 | |
| 6985 | /* if controller is soft- but not hard resettable... */ |
| 6986 | if (!ctlr_is_hard_resettable(board_id)) |
| 6987 | return -ENOTSUPP; /* try soft reset later. */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 6988 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 6989 | /* Save the PCI command register */ |
| 6990 | pci_read_config_word(pdev, 4, &command_register); |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 6991 | pci_save_state(pdev); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 6992 | |
| 6993 | /* find the first memory BAR, so we can find the cfg table */ |
| 6994 | rc = hpsa_pci_find_memory_BAR(pdev, &paddr); |
| 6995 | if (rc) |
| 6996 | return rc; |
| 6997 | vaddr = remap_pci_mem(paddr, 0x250); |
| 6998 | if (!vaddr) |
| 6999 | return -ENOMEM; |
| 7000 | |
| 7001 | /* find cfgtable in order to check if reset via doorbell is supported */ |
| 7002 | rc = hpsa_find_cfg_addrs(pdev, vaddr, &cfg_base_addr, |
| 7003 | &cfg_base_addr_index, &cfg_offset); |
| 7004 | if (rc) |
| 7005 | goto unmap_vaddr; |
| 7006 | cfgtable = remap_pci_mem(pci_resource_start(pdev, |
| 7007 | cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable)); |
| 7008 | if (!cfgtable) { |
| 7009 | rc = -ENOMEM; |
| 7010 | goto unmap_vaddr; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7011 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7012 | rc = write_driver_ver_to_cfgtable(cfgtable); |
| 7013 | if (rc) |
Tomas Henzl | 03741d9 | 2015-01-23 16:41:14 -0600 | [diff] [blame] | 7014 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7015 | |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7016 | /* If reset via doorbell register is supported, use that. |
| 7017 | * There are two such methods. Favor the newest method. |
| 7018 | */ |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7019 | misc_fw_support = readl(&cfgtable->misc_fw_support); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7020 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET2; |
| 7021 | if (use_doorbell) { |
| 7022 | use_doorbell = DOORBELL_CTLR_RESET2; |
| 7023 | } else { |
| 7024 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET; |
| 7025 | if (use_doorbell) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7026 | dev_warn(&pdev->dev, |
| 7027 | "Soft reset not supported. Firmware update is required.\n"); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7028 | rc = -ENOTSUPP; /* try soft reset */ |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7029 | goto unmap_cfgtable; |
| 7030 | } |
| 7031 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7032 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7033 | rc = hpsa_controller_hard_reset(pdev, vaddr, use_doorbell); |
| 7034 | if (rc) |
| 7035 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7036 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7037 | pci_restore_state(pdev); |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7038 | pci_write_config_word(pdev, 4, command_register); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7039 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7040 | /* Some devices (notably the HP Smart Array 5i Controller) |
| 7041 | need a little pause here */ |
| 7042 | msleep(HPSA_POST_RESET_PAUSE_MSECS); |
| 7043 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7044 | rc = hpsa_wait_for_board_state(pdev, vaddr, BOARD_READY); |
| 7045 | if (rc) { |
| 7046 | dev_warn(&pdev->dev, |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7047 | "Failed waiting for board to become ready after hard reset\n"); |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7048 | goto unmap_cfgtable; |
| 7049 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7050 | |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7051 | rc = controller_reset_failed(vaddr); |
| 7052 | if (rc < 0) |
| 7053 | goto unmap_cfgtable; |
| 7054 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7055 | dev_warn(&pdev->dev, "Unable to successfully reset " |
| 7056 | "controller. Will try soft reset.\n"); |
| 7057 | rc = -ENOTSUPP; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7058 | } else { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7059 | dev_info(&pdev->dev, "board ready after hard reset.\n"); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7060 | } |
| 7061 | |
| 7062 | unmap_cfgtable: |
| 7063 | iounmap(cfgtable); |
| 7064 | |
| 7065 | unmap_vaddr: |
| 7066 | iounmap(vaddr); |
| 7067 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7068 | } |
| 7069 | |
| 7070 | /* |
| 7071 | * We cannot read the structure directly, for portability we must use |
| 7072 | * the io functions. |
| 7073 | * This is for debug only. |
| 7074 | */ |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 7075 | 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] | 7076 | { |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 7077 | #ifdef HPSA_DEBUG |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7078 | int i; |
| 7079 | char temp_name[17]; |
| 7080 | |
| 7081 | dev_info(dev, "Controller Configuration information\n"); |
| 7082 | dev_info(dev, "------------------------------------\n"); |
| 7083 | for (i = 0; i < 4; i++) |
| 7084 | temp_name[i] = readb(&(tb->Signature[i])); |
| 7085 | temp_name[4] = '\0'; |
| 7086 | dev_info(dev, " Signature = %s\n", temp_name); |
| 7087 | dev_info(dev, " Spec Number = %d\n", readl(&(tb->SpecValence))); |
| 7088 | dev_info(dev, " Transport methods supported = 0x%x\n", |
| 7089 | readl(&(tb->TransportSupport))); |
| 7090 | dev_info(dev, " Transport methods active = 0x%x\n", |
| 7091 | readl(&(tb->TransportActive))); |
| 7092 | dev_info(dev, " Requested transport Method = 0x%x\n", |
| 7093 | readl(&(tb->HostWrite.TransportRequest))); |
| 7094 | dev_info(dev, " Coalesce Interrupt Delay = 0x%x\n", |
| 7095 | readl(&(tb->HostWrite.CoalIntDelay))); |
| 7096 | dev_info(dev, " Coalesce Interrupt Count = 0x%x\n", |
| 7097 | readl(&(tb->HostWrite.CoalIntCount))); |
Robert Elliott | 69d6e33 | 2015-01-23 16:41:56 -0600 | [diff] [blame] | 7098 | dev_info(dev, " Max outstanding commands = %d\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7099 | readl(&(tb->CmdsOutMax))); |
| 7100 | dev_info(dev, " Bus Types = 0x%x\n", readl(&(tb->BusTypes))); |
| 7101 | for (i = 0; i < 16; i++) |
| 7102 | temp_name[i] = readb(&(tb->ServerName[i])); |
| 7103 | temp_name[16] = '\0'; |
| 7104 | dev_info(dev, " Server Name = %s\n", temp_name); |
| 7105 | dev_info(dev, " Heartbeat Counter = 0x%x\n\n\n", |
| 7106 | readl(&(tb->HeartBeat))); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7107 | #endif /* HPSA_DEBUG */ |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 7108 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7109 | |
| 7110 | static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) |
| 7111 | { |
| 7112 | int i, offset, mem_type, bar_type; |
| 7113 | |
| 7114 | if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */ |
| 7115 | return 0; |
| 7116 | offset = 0; |
| 7117 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 7118 | bar_type = pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE; |
| 7119 | if (bar_type == PCI_BASE_ADDRESS_SPACE_IO) |
| 7120 | offset += 4; |
| 7121 | else { |
| 7122 | mem_type = pci_resource_flags(pdev, i) & |
| 7123 | PCI_BASE_ADDRESS_MEM_TYPE_MASK; |
| 7124 | switch (mem_type) { |
| 7125 | case PCI_BASE_ADDRESS_MEM_TYPE_32: |
| 7126 | case PCI_BASE_ADDRESS_MEM_TYPE_1M: |
| 7127 | offset += 4; /* 32 bit */ |
| 7128 | break; |
| 7129 | case PCI_BASE_ADDRESS_MEM_TYPE_64: |
| 7130 | offset += 8; |
| 7131 | break; |
| 7132 | default: /* reserved in PCI 2.2 */ |
| 7133 | dev_warn(&pdev->dev, |
| 7134 | "base address is invalid\n"); |
| 7135 | return -1; |
| 7136 | break; |
| 7137 | } |
| 7138 | } |
| 7139 | if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0) |
| 7140 | return i + 1; |
| 7141 | } |
| 7142 | return -1; |
| 7143 | } |
| 7144 | |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 7145 | static void hpsa_disable_interrupt_mode(struct ctlr_info *h) |
| 7146 | { |
| 7147 | if (h->msix_vector) { |
| 7148 | if (h->pdev->msix_enabled) |
| 7149 | pci_disable_msix(h->pdev); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7150 | h->msix_vector = 0; |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 7151 | } else if (h->msi_vector) { |
| 7152 | if (h->pdev->msi_enabled) |
| 7153 | pci_disable_msi(h->pdev); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7154 | h->msi_vector = 0; |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 7155 | } |
| 7156 | } |
| 7157 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7158 | /* 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] | 7159 | * controllers that are capable. If not, we use legacy INTx mode. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7160 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7161 | static void hpsa_interrupt_mode(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7162 | { |
| 7163 | #ifdef CONFIG_PCI_MSI |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7164 | int err, i; |
| 7165 | struct msix_entry hpsa_msix_entries[MAX_REPLY_QUEUES]; |
| 7166 | |
| 7167 | for (i = 0; i < MAX_REPLY_QUEUES; i++) { |
| 7168 | hpsa_msix_entries[i].vector = 0; |
| 7169 | hpsa_msix_entries[i].entry = i; |
| 7170 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7171 | |
| 7172 | /* Some boards advertise MSI but don't really support it */ |
Stephen M. Cameron | 6b3f4c5 | 2010-05-27 15:13:02 -0500 | [diff] [blame] | 7173 | if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) || |
| 7174 | (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7175 | goto default_int_mode; |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7176 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7177 | dev_info(&h->pdev->dev, "MSI-X capable controller\n"); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7178 | h->msix_vector = MAX_REPLY_QUEUES; |
Stephen M. Cameron | f89439b | 2014-05-29 10:53:02 -0500 | [diff] [blame] | 7179 | if (h->msix_vector > num_online_cpus()) |
| 7180 | h->msix_vector = num_online_cpus(); |
Alexander Gordeev | 18fce3c | 2014-08-18 08:01:42 +0200 | [diff] [blame] | 7181 | err = pci_enable_msix_range(h->pdev, hpsa_msix_entries, |
| 7182 | 1, h->msix_vector); |
| 7183 | if (err < 0) { |
| 7184 | dev_warn(&h->pdev->dev, "MSI-X init failed %d\n", err); |
| 7185 | h->msix_vector = 0; |
| 7186 | goto single_msi_mode; |
| 7187 | } else if (err < h->msix_vector) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7188 | dev_warn(&h->pdev->dev, "only %d MSI-X vectors " |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7189 | "available\n", err); |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7190 | } |
Alexander Gordeev | 18fce3c | 2014-08-18 08:01:42 +0200 | [diff] [blame] | 7191 | h->msix_vector = err; |
| 7192 | for (i = 0; i < h->msix_vector; i++) |
| 7193 | h->intr[i] = hpsa_msix_entries[i].vector; |
| 7194 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7195 | } |
Alexander Gordeev | 18fce3c | 2014-08-18 08:01:42 +0200 | [diff] [blame] | 7196 | single_msi_mode: |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7197 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7198 | dev_info(&h->pdev->dev, "MSI capable controller\n"); |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7199 | if (!pci_enable_msi(h->pdev)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7200 | h->msi_vector = 1; |
| 7201 | else |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7202 | dev_warn(&h->pdev->dev, "MSI init failed\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7203 | } |
| 7204 | default_int_mode: |
| 7205 | #endif /* CONFIG_PCI_MSI */ |
| 7206 | /* 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] | 7207 | h->intr[h->intr_mode] = h->pdev->irq; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7208 | } |
| 7209 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7210 | 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] | 7211 | { |
| 7212 | int i; |
| 7213 | u32 subsystem_vendor_id, subsystem_device_id; |
| 7214 | |
| 7215 | subsystem_vendor_id = pdev->subsystem_vendor; |
| 7216 | subsystem_device_id = pdev->subsystem_device; |
| 7217 | *board_id = ((subsystem_device_id << 16) & 0xffff0000) | |
| 7218 | subsystem_vendor_id; |
| 7219 | |
| 7220 | for (i = 0; i < ARRAY_SIZE(products); i++) |
| 7221 | if (*board_id == products[i].board_id) |
| 7222 | return i; |
| 7223 | |
Stephen M. Cameron | 6798cc0 | 2010-06-16 13:51:20 -0500 | [diff] [blame] | 7224 | if ((subsystem_vendor_id != PCI_VENDOR_ID_HP && |
| 7225 | subsystem_vendor_id != PCI_VENDOR_ID_COMPAQ) || |
| 7226 | !hpsa_allow_any) { |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 7227 | dev_warn(&pdev->dev, "unrecognized board ID: " |
| 7228 | "0x%08x, ignoring.\n", *board_id); |
| 7229 | return -ENODEV; |
| 7230 | } |
| 7231 | return ARRAY_SIZE(products) - 1; /* generic unknown smart array */ |
| 7232 | } |
| 7233 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7234 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 7235 | unsigned long *memory_bar) |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7236 | { |
| 7237 | int i; |
| 7238 | |
| 7239 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7240 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7241 | /* addressing mode bits already removed */ |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7242 | *memory_bar = pci_resource_start(pdev, i); |
| 7243 | dev_dbg(&pdev->dev, "memory BAR = %lx\n", |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7244 | *memory_bar); |
| 7245 | return 0; |
| 7246 | } |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7247 | dev_warn(&pdev->dev, "no memory BAR found\n"); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7248 | return -ENODEV; |
| 7249 | } |
| 7250 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7251 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 7252 | int wait_for_ready) |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7253 | { |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7254 | int i, iterations; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7255 | u32 scratchpad; |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7256 | if (wait_for_ready) |
| 7257 | iterations = HPSA_BOARD_READY_ITERATIONS; |
| 7258 | else |
| 7259 | iterations = HPSA_BOARD_NOT_READY_ITERATIONS; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7260 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7261 | for (i = 0; i < iterations; i++) { |
| 7262 | scratchpad = readl(vaddr + SA5_SCRATCHPAD_OFFSET); |
| 7263 | if (wait_for_ready) { |
| 7264 | if (scratchpad == HPSA_FIRMWARE_READY) |
| 7265 | return 0; |
| 7266 | } else { |
| 7267 | if (scratchpad != HPSA_FIRMWARE_READY) |
| 7268 | return 0; |
| 7269 | } |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7270 | msleep(HPSA_BOARD_READY_POLL_INTERVAL_MSECS); |
| 7271 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7272 | dev_warn(&pdev->dev, "board not ready, timed out.\n"); |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7273 | return -ENODEV; |
| 7274 | } |
| 7275 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7276 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 7277 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 7278 | u64 *cfg_offset) |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7279 | { |
| 7280 | *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET); |
| 7281 | *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET); |
| 7282 | *cfg_base_addr &= (u32) 0x0000ffff; |
| 7283 | *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr); |
| 7284 | if (*cfg_base_addr_index == -1) { |
| 7285 | dev_warn(&pdev->dev, "cannot find cfg_base_addr_index\n"); |
| 7286 | return -ENODEV; |
| 7287 | } |
| 7288 | return 0; |
| 7289 | } |
| 7290 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7291 | static void hpsa_free_cfgtables(struct ctlr_info *h) |
| 7292 | { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7293 | if (h->transtable) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7294 | iounmap(h->transtable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7295 | h->transtable = NULL; |
| 7296 | } |
| 7297 | if (h->cfgtable) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7298 | iounmap(h->cfgtable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7299 | h->cfgtable = NULL; |
| 7300 | } |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7301 | } |
| 7302 | |
| 7303 | /* Find and map CISS config table and transfer table |
| 7304 | + * several items must be unmapped (freed) later |
| 7305 | + * */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7306 | static int hpsa_find_cfgtables(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7307 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 7308 | u64 cfg_offset; |
| 7309 | u32 cfg_base_addr; |
| 7310 | u64 cfg_base_addr_index; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7311 | u32 trans_offset; |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7312 | int rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7313 | |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7314 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 7315 | &cfg_base_addr_index, &cfg_offset); |
| 7316 | if (rc) |
| 7317 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7318 | h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev, |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7319 | cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable)); |
Robert Elliott | cd3c81c | 2015-01-23 16:42:27 -0600 | [diff] [blame] | 7320 | if (!h->cfgtable) { |
| 7321 | dev_err(&h->pdev->dev, "Failed mapping cfgtable\n"); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7322 | return -ENOMEM; |
Robert Elliott | cd3c81c | 2015-01-23 16:42:27 -0600 | [diff] [blame] | 7323 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7324 | rc = write_driver_ver_to_cfgtable(h->cfgtable); |
| 7325 | if (rc) |
| 7326 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7327 | /* Find performant mode table. */ |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7328 | trans_offset = readl(&h->cfgtable->TransMethodOffset); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7329 | h->transtable = remap_pci_mem(pci_resource_start(h->pdev, |
| 7330 | cfg_base_addr_index)+cfg_offset+trans_offset, |
| 7331 | sizeof(*h->transtable)); |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7332 | if (!h->transtable) { |
| 7333 | dev_err(&h->pdev->dev, "Failed mapping transfer table\n"); |
| 7334 | hpsa_free_cfgtables(h); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7335 | return -ENOMEM; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7336 | } |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7337 | return 0; |
| 7338 | } |
| 7339 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7340 | 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] | 7341 | { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 7342 | #define MIN_MAX_COMMANDS 16 |
| 7343 | BUILD_BUG_ON(MIN_MAX_COMMANDS <= HPSA_NRESERVED_CMDS); |
| 7344 | |
| 7345 | h->max_commands = readl(&h->cfgtable->MaxPerformantModeCommands); |
Stephen M. Cameron | 72ceeae | 2011-01-06 14:48:13 -0600 | [diff] [blame] | 7346 | |
| 7347 | /* Limit commands in memory limited kdump scenario. */ |
| 7348 | if (reset_devices && h->max_commands > 32) |
| 7349 | h->max_commands = 32; |
| 7350 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 7351 | if (h->max_commands < MIN_MAX_COMMANDS) { |
| 7352 | dev_warn(&h->pdev->dev, |
| 7353 | "Controller reports max supported commands of %d Using %d instead. Ensure that firmware is up to date.\n", |
| 7354 | h->max_commands, |
| 7355 | MIN_MAX_COMMANDS); |
| 7356 | h->max_commands = MIN_MAX_COMMANDS; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 7357 | } |
| 7358 | } |
| 7359 | |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7360 | /* If the controller reports that the total max sg entries is greater than 512, |
| 7361 | * then we know that chained SG blocks work. (Original smart arrays did not |
| 7362 | * support chained SG blocks and would return zero for max sg entries.) |
| 7363 | */ |
| 7364 | static int hpsa_supports_chained_sg_blocks(struct ctlr_info *h) |
| 7365 | { |
| 7366 | return h->maxsgentries > 512; |
| 7367 | } |
| 7368 | |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7369 | /* Interrogate the hardware for some limits: |
| 7370 | * max commands, max SG elements without chaining, and with chaining, |
| 7371 | * SG chain block size, etc. |
| 7372 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7373 | static void hpsa_find_board_params(struct ctlr_info *h) |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7374 | { |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 7375 | hpsa_get_max_perf_mode_cmds(h); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 7376 | h->nr_cmds = h->max_commands; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7377 | h->maxsgentries = readl(&(h->cfgtable->MaxScatterGatherElements)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7378 | h->fw_support = readl(&(h->cfgtable->misc_fw_support)); |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7379 | if (hpsa_supports_chained_sg_blocks(h)) { |
| 7380 | /* 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] | 7381 | h->max_cmd_sg_entries = 32; |
Webb Scales | 1a63ea6 | 2014-11-14 17:26:43 -0600 | [diff] [blame] | 7382 | h->chainsize = h->maxsgentries - h->max_cmd_sg_entries; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7383 | h->maxsgentries--; /* save one for chain pointer */ |
| 7384 | } else { |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7385 | /* |
| 7386 | * Original smart arrays supported at most 31 s/g entries |
| 7387 | * embedded inline in the command (trying to use more |
| 7388 | * would lock up the controller) |
| 7389 | */ |
| 7390 | h->max_cmd_sg_entries = 31; |
Webb Scales | 1a63ea6 | 2014-11-14 17:26:43 -0600 | [diff] [blame] | 7391 | h->maxsgentries = 31; /* default to traditional values */ |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7392 | h->chainsize = 0; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7393 | } |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 7394 | |
| 7395 | /* Find out what task management functions are supported and cache */ |
| 7396 | h->TMFSupportFlags = readl(&(h->cfgtable->TMFSupportFlags)); |
Scott Teel | 0e7a7fc | 2014-02-18 13:55:59 -0600 | [diff] [blame] | 7397 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags)) |
| 7398 | dev_warn(&h->pdev->dev, "Physical aborts not supported\n"); |
| 7399 | if (!(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 7400 | dev_warn(&h->pdev->dev, "Logical aborts not supported\n"); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 7401 | if (!(HPSATMF_IOACCEL_ENABLED & h->TMFSupportFlags)) |
| 7402 | dev_warn(&h->pdev->dev, "HP SSD Smart Path aborts not supported\n"); |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7403 | } |
| 7404 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 7405 | static inline bool hpsa_CISS_signature_present(struct ctlr_info *h) |
| 7406 | { |
Akinobu Mita | 0fc9fd4 | 2012-04-04 22:14:59 +0900 | [diff] [blame] | 7407 | if (!check_signature(h->cfgtable->Signature, "CISS", 4)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7408 | 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] | 7409 | return false; |
| 7410 | } |
| 7411 | return true; |
| 7412 | } |
| 7413 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7414 | 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] | 7415 | { |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7416 | u32 driver_support; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 7417 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7418 | driver_support = readl(&(h->cfgtable->driver_support)); |
Arnd Bergmann | 0b9e7b7 | 2014-06-26 15:44:52 +0200 | [diff] [blame] | 7419 | /* Need to enable prefetch in the SCSI core for 6400 in x86 */ |
| 7420 | #ifdef CONFIG_X86 |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7421 | driver_support |= ENABLE_SCSI_PREFETCH; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 7422 | #endif |
Stephen M. Cameron | 28e1344 | 2013-12-04 17:10:21 -0600 | [diff] [blame] | 7423 | driver_support |= ENABLE_UNIT_ATTN; |
| 7424 | writel(driver_support, &(h->cfgtable->driver_support)); |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 7425 | } |
| 7426 | |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 7427 | /* Disable DMA prefetch for the P600. Otherwise an ASIC bug may result |
| 7428 | * in a prefetch beyond physical memory. |
| 7429 | */ |
| 7430 | static inline void hpsa_p600_dma_prefetch_quirk(struct ctlr_info *h) |
| 7431 | { |
| 7432 | u32 dma_prefetch; |
| 7433 | |
| 7434 | if (h->board_id != 0x3225103C) |
| 7435 | return; |
| 7436 | dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG); |
| 7437 | dma_prefetch |= 0x8000; |
| 7438 | writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG); |
| 7439 | } |
| 7440 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7441 | 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] | 7442 | { |
| 7443 | int i; |
| 7444 | u32 doorbell_value; |
| 7445 | unsigned long flags; |
| 7446 | /* wait until the clear_event_notify bit 6 is cleared by controller. */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7447 | for (i = 0; i < MAX_CLEAR_EVENT_WAIT; i++) { |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7448 | spin_lock_irqsave(&h->lock, flags); |
| 7449 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 7450 | spin_unlock_irqrestore(&h->lock, flags); |
| 7451 | if (!(doorbell_value & DOORBELL_CLEAR_EVENTS)) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7452 | goto done; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7453 | /* delay and try again */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7454 | msleep(CLEAR_EVENT_WAIT_INTERVAL); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7455 | } |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7456 | return -ENODEV; |
| 7457 | done: |
| 7458 | return 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7459 | } |
| 7460 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7461 | 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] | 7462 | { |
| 7463 | int i; |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 7464 | u32 doorbell_value; |
| 7465 | unsigned long flags; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7466 | |
| 7467 | /* under certain very rare conditions, this can take awhile. |
| 7468 | * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right |
| 7469 | * as we enter this code.) |
| 7470 | */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7471 | for (i = 0; i < MAX_MODE_CHANGE_WAIT; i++) { |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7472 | if (h->remove_in_progress) |
| 7473 | goto done; |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 7474 | spin_lock_irqsave(&h->lock, flags); |
| 7475 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 7476 | spin_unlock_irqrestore(&h->lock, flags); |
Dan Carpenter | 382be66 | 2011-02-15 15:33:13 -0600 | [diff] [blame] | 7477 | if (!(doorbell_value & CFGTBL_ChangeReq)) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7478 | goto done; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7479 | /* delay and try again */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7480 | msleep(MODE_CHANGE_WAIT_INTERVAL); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7481 | } |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7482 | return -ENODEV; |
| 7483 | done: |
| 7484 | return 0; |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 7485 | } |
| 7486 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7487 | /* return -ENODEV or other reason on error, 0 on success */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7488 | static int hpsa_enter_simple_mode(struct ctlr_info *h) |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 7489 | { |
| 7490 | u32 trans_support; |
| 7491 | |
| 7492 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 7493 | if (!(trans_support & SIMPLE_MODE)) |
| 7494 | return -ENOTSUPP; |
| 7495 | |
| 7496 | h->max_commands = readl(&(h->cfgtable->CmdsOutMax)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7497 | |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 7498 | /* Update the field, and then ring the doorbell */ |
| 7499 | writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest)); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 7500 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 7501 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7502 | if (hpsa_wait_for_mode_change_ack(h)) |
| 7503 | goto error; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7504 | print_cfg_table(&h->pdev->dev, h->cfgtable); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7505 | if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) |
| 7506 | goto error; |
Stephen M. Cameron | 960a30e7 | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 7507 | h->transMethod = CFGTBL_Trans_Simple; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7508 | return 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7509 | error: |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7510 | dev_err(&h->pdev->dev, "failed to enter simple mode\n"); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7511 | return -ENODEV; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7512 | } |
| 7513 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7514 | /* free items allocated or mapped by hpsa_pci_init */ |
| 7515 | static void hpsa_free_pci_init(struct ctlr_info *h) |
| 7516 | { |
| 7517 | hpsa_free_cfgtables(h); /* pci_init 4 */ |
| 7518 | iounmap(h->vaddr); /* pci_init 3 */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7519 | h->vaddr = NULL; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7520 | hpsa_disable_interrupt_mode(h); /* pci_init 2 */ |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 7521 | /* |
| 7522 | * call pci_disable_device before pci_release_regions per |
| 7523 | * Documentation/PCI/pci.txt |
| 7524 | */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7525 | pci_disable_device(h->pdev); /* pci_init 1 */ |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 7526 | pci_release_regions(h->pdev); /* pci_init 2 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7527 | } |
| 7528 | |
| 7529 | /* several items must be freed later */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7530 | static int hpsa_pci_init(struct ctlr_info *h) |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7531 | { |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7532 | int prod_index, err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7533 | |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 7534 | prod_index = hpsa_lookup_board_id(h->pdev, &h->board_id); |
| 7535 | if (prod_index < 0) |
Robert Elliott | 60f923b | 2015-01-23 16:42:06 -0600 | [diff] [blame] | 7536 | return prod_index; |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 7537 | h->product_name = products[prod_index].product_name; |
| 7538 | h->access = *(products[prod_index].access); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7539 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 7540 | h->needs_abort_tags_swizzled = |
| 7541 | ctlr_needs_abort_tags_swizzled(h->board_id); |
| 7542 | |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 7543 | pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S | |
| 7544 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); |
| 7545 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7546 | err = pci_enable_device(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7547 | if (err) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7548 | dev_err(&h->pdev->dev, "failed to enable PCI device\n"); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 7549 | pci_disable_device(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7550 | return err; |
| 7551 | } |
| 7552 | |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 7553 | err = pci_request_regions(h->pdev, HPSA); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7554 | if (err) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 7555 | dev_err(&h->pdev->dev, |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7556 | "failed to obtain PCI resources\n"); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 7557 | pci_disable_device(h->pdev); |
| 7558 | return err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7559 | } |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 7560 | |
| 7561 | pci_set_master(h->pdev); |
| 7562 | |
Stephen M. Cameron | 6b3f4c5 | 2010-05-27 15:13:02 -0500 | [diff] [blame] | 7563 | hpsa_interrupt_mode(h); |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7564 | err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7565 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7566 | goto clean2; /* intmode+region, pci */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7567 | h->vaddr = remap_pci_mem(h->paddr, 0x250); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 7568 | if (!h->vaddr) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7569 | dev_err(&h->pdev->dev, "failed to remap PCI mem\n"); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 7570 | err = -ENOMEM; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7571 | goto clean2; /* intmode+region, pci */ |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 7572 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7573 | 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] | 7574 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7575 | goto clean3; /* vaddr, intmode+region, pci */ |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7576 | err = hpsa_find_cfgtables(h); |
| 7577 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7578 | goto clean3; /* vaddr, intmode+region, pci */ |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7579 | hpsa_find_board_params(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7580 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 7581 | if (!hpsa_CISS_signature_present(h)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7582 | err = -ENODEV; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7583 | goto clean4; /* cfgtables, vaddr, intmode+region, pci */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7584 | } |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7585 | hpsa_set_driver_support_bits(h); |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 7586 | hpsa_p600_dma_prefetch_quirk(h); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7587 | err = hpsa_enter_simple_mode(h); |
| 7588 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7589 | goto clean4; /* cfgtables, vaddr, intmode+region, pci */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7590 | return 0; |
| 7591 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7592 | clean4: /* cfgtables, vaddr, intmode+region, pci */ |
| 7593 | hpsa_free_cfgtables(h); |
| 7594 | clean3: /* vaddr, intmode+region, pci */ |
| 7595 | iounmap(h->vaddr); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7596 | h->vaddr = NULL; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7597 | clean2: /* intmode+region, pci */ |
| 7598 | hpsa_disable_interrupt_mode(h); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 7599 | /* |
| 7600 | * call pci_disable_device before pci_release_regions per |
| 7601 | * Documentation/PCI/pci.txt |
| 7602 | */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7603 | pci_disable_device(h->pdev); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 7604 | pci_release_regions(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7605 | return err; |
| 7606 | } |
| 7607 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7608 | static void hpsa_hba_inquiry(struct ctlr_info *h) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 7609 | { |
| 7610 | int rc; |
| 7611 | |
| 7612 | #define HBA_INQUIRY_BYTE_COUNT 64 |
| 7613 | h->hba_inquiry_data = kmalloc(HBA_INQUIRY_BYTE_COUNT, GFP_KERNEL); |
| 7614 | if (!h->hba_inquiry_data) |
| 7615 | return; |
| 7616 | rc = hpsa_scsi_do_inquiry(h, RAID_CTLR_LUNID, 0, |
| 7617 | h->hba_inquiry_data, HBA_INQUIRY_BYTE_COUNT); |
| 7618 | if (rc != 0) { |
| 7619 | kfree(h->hba_inquiry_data); |
| 7620 | h->hba_inquiry_data = NULL; |
| 7621 | } |
| 7622 | } |
| 7623 | |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 7624 | 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] | 7625 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7626 | int rc, i; |
Tomas Henzl | 3b74729 | 2015-01-23 16:41:20 -0600 | [diff] [blame] | 7627 | void __iomem *vaddr; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 7628 | |
| 7629 | if (!reset_devices) |
| 7630 | return 0; |
| 7631 | |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 7632 | /* kdump kernel is loading, we don't know in which state is |
| 7633 | * the pci interface. The dev->enable_cnt is equal zero |
| 7634 | * so we call enable+disable, wait a while and switch it on. |
| 7635 | */ |
| 7636 | rc = pci_enable_device(pdev); |
| 7637 | if (rc) { |
| 7638 | dev_warn(&pdev->dev, "Failed to enable PCI device\n"); |
| 7639 | return -ENODEV; |
| 7640 | } |
| 7641 | pci_disable_device(pdev); |
| 7642 | msleep(260); /* a randomly chosen number */ |
| 7643 | rc = pci_enable_device(pdev); |
| 7644 | if (rc) { |
| 7645 | dev_warn(&pdev->dev, "failed to enable device.\n"); |
| 7646 | return -ENODEV; |
| 7647 | } |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 7648 | |
Tomas Henzl | 859c75a | 2014-09-12 14:44:15 +0200 | [diff] [blame] | 7649 | pci_set_master(pdev); |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 7650 | |
Tomas Henzl | 3b74729 | 2015-01-23 16:41:20 -0600 | [diff] [blame] | 7651 | vaddr = pci_ioremap_bar(pdev, 0); |
| 7652 | if (vaddr == NULL) { |
| 7653 | rc = -ENOMEM; |
| 7654 | goto out_disable; |
| 7655 | } |
| 7656 | writel(SA5_INTR_OFF, vaddr + SA5_REPLY_INTR_MASK_OFFSET); |
| 7657 | iounmap(vaddr); |
| 7658 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7659 | /* Reset the controller with a PCI power-cycle or via doorbell */ |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 7660 | rc = hpsa_kdump_hard_reset_controller(pdev, board_id); |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 7661 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7662 | /* -ENOTSUPP here means we cannot reset the controller |
| 7663 | * but it's already (and still) up and running in |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 7664 | * "performant mode". Or, it might be 640x, which can't reset |
| 7665 | * due to concerns about shared bbwc between 6402/6404 pair. |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7666 | */ |
Robert Elliott | adf1b3a | 2015-01-23 16:42:01 -0600 | [diff] [blame] | 7667 | if (rc) |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 7668 | goto out_disable; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 7669 | |
| 7670 | /* Now try to get the controller to respond to a no-op */ |
Robert Elliott | 1ba66c9 | 2015-01-23 16:42:11 -0600 | [diff] [blame] | 7671 | 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] | 7672 | for (i = 0; i < HPSA_POST_RESET_NOOP_RETRIES; i++) { |
| 7673 | if (hpsa_noop(pdev) == 0) |
| 7674 | break; |
| 7675 | else |
| 7676 | dev_warn(&pdev->dev, "no-op failed%s\n", |
| 7677 | (i < 11 ? "; re-trying" : "")); |
| 7678 | } |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 7679 | |
| 7680 | out_disable: |
| 7681 | |
| 7682 | pci_disable_device(pdev); |
| 7683 | return rc; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 7684 | } |
| 7685 | |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 7686 | static void hpsa_free_cmd_pool(struct ctlr_info *h) |
| 7687 | { |
| 7688 | kfree(h->cmd_pool_bits); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7689 | h->cmd_pool_bits = NULL; |
| 7690 | if (h->cmd_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 7691 | pci_free_consistent(h->pdev, |
| 7692 | h->nr_cmds * sizeof(struct CommandList), |
| 7693 | h->cmd_pool, |
| 7694 | h->cmd_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7695 | h->cmd_pool = NULL; |
| 7696 | h->cmd_pool_dhandle = 0; |
| 7697 | } |
| 7698 | if (h->errinfo_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 7699 | pci_free_consistent(h->pdev, |
| 7700 | h->nr_cmds * sizeof(struct ErrorInfo), |
| 7701 | h->errinfo_pool, |
| 7702 | h->errinfo_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7703 | h->errinfo_pool = NULL; |
| 7704 | h->errinfo_pool_dhandle = 0; |
| 7705 | } |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 7706 | } |
| 7707 | |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 7708 | static int hpsa_alloc_cmd_pool(struct ctlr_info *h) |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 7709 | { |
| 7710 | h->cmd_pool_bits = kzalloc( |
| 7711 | DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) * |
| 7712 | sizeof(unsigned long), GFP_KERNEL); |
| 7713 | h->cmd_pool = pci_alloc_consistent(h->pdev, |
| 7714 | h->nr_cmds * sizeof(*h->cmd_pool), |
| 7715 | &(h->cmd_pool_dhandle)); |
| 7716 | h->errinfo_pool = pci_alloc_consistent(h->pdev, |
| 7717 | h->nr_cmds * sizeof(*h->errinfo_pool), |
| 7718 | &(h->errinfo_pool_dhandle)); |
| 7719 | if ((h->cmd_pool_bits == NULL) |
| 7720 | || (h->cmd_pool == NULL) |
| 7721 | || (h->errinfo_pool == NULL)) { |
| 7722 | dev_err(&h->pdev->dev, "out of memory in %s", __func__); |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 7723 | goto clean_up; |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 7724 | } |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 7725 | hpsa_preinitialize_commands(h); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 7726 | return 0; |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 7727 | clean_up: |
| 7728 | hpsa_free_cmd_pool(h); |
| 7729 | return -ENOMEM; |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 7730 | } |
| 7731 | |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 7732 | static void hpsa_irq_affinity_hints(struct ctlr_info *h) |
| 7733 | { |
Fabian Frederick | ec42995 | 2015-01-23 16:41:46 -0600 | [diff] [blame] | 7734 | int i, cpu; |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 7735 | |
| 7736 | cpu = cpumask_first(cpu_online_mask); |
| 7737 | for (i = 0; i < h->msix_vector; i++) { |
Fabian Frederick | ec42995 | 2015-01-23 16:41:46 -0600 | [diff] [blame] | 7738 | irq_set_affinity_hint(h->intr[i], get_cpu_mask(cpu)); |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 7739 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 7740 | } |
| 7741 | } |
| 7742 | |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 7743 | /* clear affinity hints and free MSI-X, MSI, or legacy INTx vectors */ |
| 7744 | static void hpsa_free_irqs(struct ctlr_info *h) |
| 7745 | { |
| 7746 | int i; |
| 7747 | |
| 7748 | if (!h->msix_vector || h->intr_mode != PERF_MODE_INT) { |
| 7749 | /* Single reply queue, only one irq to free */ |
| 7750 | i = h->intr_mode; |
| 7751 | irq_set_affinity_hint(h->intr[i], NULL); |
| 7752 | free_irq(h->intr[i], &h->q[i]); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7753 | h->q[i] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 7754 | return; |
| 7755 | } |
| 7756 | |
| 7757 | for (i = 0; i < h->msix_vector; i++) { |
| 7758 | irq_set_affinity_hint(h->intr[i], NULL); |
| 7759 | free_irq(h->intr[i], &h->q[i]); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7760 | h->q[i] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 7761 | } |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 7762 | for (; i < MAX_REPLY_QUEUES; i++) |
| 7763 | h->q[i] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 7764 | } |
| 7765 | |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 7766 | /* returns 0 on success; cleans up and returns -Enn on error */ |
| 7767 | static int hpsa_request_irqs(struct ctlr_info *h, |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 7768 | irqreturn_t (*msixhandler)(int, void *), |
| 7769 | irqreturn_t (*intxhandler)(int, void *)) |
| 7770 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7771 | int rc, i; |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 7772 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7773 | /* |
| 7774 | * initialize h->q[x] = x so that interrupt handlers know which |
| 7775 | * queue to process. |
| 7776 | */ |
| 7777 | for (i = 0; i < MAX_REPLY_QUEUES; i++) |
| 7778 | h->q[i] = (u8) i; |
| 7779 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7780 | if (h->intr_mode == PERF_MODE_INT && h->msix_vector > 0) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7781 | /* If performant mode and MSI-X, use multiple reply queues */ |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 7782 | for (i = 0; i < h->msix_vector; i++) { |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 7783 | sprintf(h->intrname[i], "%s-msix%d", h->devname, i); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7784 | rc = request_irq(h->intr[i], msixhandler, |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 7785 | 0, h->intrname[i], |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7786 | &h->q[i]); |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 7787 | if (rc) { |
| 7788 | int j; |
| 7789 | |
| 7790 | dev_err(&h->pdev->dev, |
| 7791 | "failed to get irq %d for %s\n", |
| 7792 | h->intr[i], h->devname); |
| 7793 | for (j = 0; j < i; j++) { |
| 7794 | free_irq(h->intr[j], &h->q[j]); |
| 7795 | h->q[j] = 0; |
| 7796 | } |
| 7797 | for (; j < MAX_REPLY_QUEUES; j++) |
| 7798 | h->q[j] = 0; |
| 7799 | return rc; |
| 7800 | } |
| 7801 | } |
Stephen M. Cameron | 41b3cf0 | 2014-05-29 10:53:13 -0500 | [diff] [blame] | 7802 | hpsa_irq_affinity_hints(h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7803 | } else { |
| 7804 | /* Use single reply pool */ |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7805 | if (h->msix_vector > 0 || h->msi_vector) { |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 7806 | if (h->msix_vector) |
| 7807 | sprintf(h->intrname[h->intr_mode], |
| 7808 | "%s-msix", h->devname); |
| 7809 | else |
| 7810 | sprintf(h->intrname[h->intr_mode], |
| 7811 | "%s-msi", h->devname); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7812 | rc = request_irq(h->intr[h->intr_mode], |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 7813 | msixhandler, 0, |
| 7814 | h->intrname[h->intr_mode], |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7815 | &h->q[h->intr_mode]); |
| 7816 | } else { |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 7817 | sprintf(h->intrname[h->intr_mode], |
| 7818 | "%s-intx", h->devname); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7819 | rc = request_irq(h->intr[h->intr_mode], |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 7820 | intxhandler, IRQF_SHARED, |
| 7821 | h->intrname[h->intr_mode], |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7822 | &h->q[h->intr_mode]); |
| 7823 | } |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7824 | irq_set_affinity_hint(h->intr[h->intr_mode], NULL); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7825 | } |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 7826 | if (rc) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7827 | dev_err(&h->pdev->dev, "failed to get irq %d for %s\n", |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 7828 | h->intr[h->intr_mode], h->devname); |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7829 | hpsa_free_irqs(h); |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 7830 | return -ENODEV; |
| 7831 | } |
| 7832 | return 0; |
| 7833 | } |
| 7834 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7835 | static int hpsa_kdump_soft_reset(struct ctlr_info *h) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7836 | { |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 7837 | int rc; |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 7838 | hpsa_send_host_reset(h, RAID_CTLR_LUNID, HPSA_RESET_TYPE_CONTROLLER); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7839 | |
| 7840 | dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 7841 | rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY); |
| 7842 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7843 | dev_warn(&h->pdev->dev, "Soft reset had no effect.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 7844 | return rc; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7845 | } |
| 7846 | |
| 7847 | dev_info(&h->pdev->dev, "Board reset, awaiting READY status.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 7848 | rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY); |
| 7849 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7850 | dev_warn(&h->pdev->dev, "Board failed to become ready " |
| 7851 | "after soft reset.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 7852 | return rc; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | return 0; |
| 7856 | } |
| 7857 | |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7858 | static void hpsa_free_reply_queues(struct ctlr_info *h) |
| 7859 | { |
| 7860 | int i; |
| 7861 | |
| 7862 | for (i = 0; i < h->nreply_queues; i++) { |
| 7863 | if (!h->reply_queue[i].head) |
| 7864 | continue; |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 7865 | pci_free_consistent(h->pdev, |
| 7866 | h->reply_queue_size, |
| 7867 | h->reply_queue[i].head, |
| 7868 | h->reply_queue[i].busaddr); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7869 | h->reply_queue[i].head = NULL; |
| 7870 | h->reply_queue[i].busaddr = 0; |
| 7871 | } |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7872 | h->reply_queue_size = 0; |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 7873 | } |
| 7874 | |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 7875 | static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h) |
| 7876 | { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7877 | hpsa_free_performant_mode(h); /* init_one 7 */ |
| 7878 | hpsa_free_sg_chain_blocks(h); /* init_one 6 */ |
| 7879 | hpsa_free_cmd_pool(h); /* init_one 5 */ |
| 7880 | hpsa_free_irqs(h); /* init_one 4 */ |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 7881 | scsi_host_put(h->scsi_host); /* init_one 3 */ |
| 7882 | h->scsi_host = NULL; /* init_one 3 */ |
| 7883 | hpsa_free_pci_init(h); /* init_one 2_5 */ |
Robert Elliott | 9ecd953 | 2015-04-23 09:34:43 -0500 | [diff] [blame] | 7884 | free_percpu(h->lockup_detected); /* init_one 2 */ |
| 7885 | h->lockup_detected = NULL; /* init_one 2 */ |
| 7886 | if (h->resubmit_wq) { |
| 7887 | destroy_workqueue(h->resubmit_wq); /* init_one 1 */ |
| 7888 | h->resubmit_wq = NULL; |
| 7889 | } |
| 7890 | if (h->rescan_ctlr_wq) { |
| 7891 | destroy_workqueue(h->rescan_ctlr_wq); |
| 7892 | h->rescan_ctlr_wq = NULL; |
| 7893 | } |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7894 | kfree(h); /* init_one 1 */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7895 | } |
| 7896 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7897 | /* Called when controller lockup detected. */ |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7898 | static void fail_all_outstanding_cmds(struct ctlr_info *h) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7899 | { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7900 | int i, refcount; |
| 7901 | struct CommandList *c; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7902 | int failcount = 0; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7903 | |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 7904 | flush_workqueue(h->resubmit_wq); /* ensure all cmds are fully built */ |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7905 | for (i = 0; i < h->nr_cmds; i++) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7906 | c = h->cmd_pool + i; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7907 | refcount = atomic_inc_return(&c->refcount); |
| 7908 | if (refcount > 1) { |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7909 | c->err_info->CommandStatus = CMD_CTLR_LOCKUP; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7910 | finish_cmd(c); |
Stephen Cameron | 433b5f4 | 2015-04-23 09:32:11 -0500 | [diff] [blame] | 7911 | atomic_dec(&h->commands_outstanding); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7912 | failcount++; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 7913 | } |
| 7914 | cmd_free(h, c); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7915 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7916 | dev_warn(&h->pdev->dev, |
| 7917 | "failed %d commands in fail_all\n", failcount); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7918 | } |
| 7919 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7920 | static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value) |
| 7921 | { |
Rusty Russell | c8ed001 | 2015-03-05 10:49:19 +1030 | [diff] [blame] | 7922 | int cpu; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7923 | |
Rusty Russell | c8ed001 | 2015-03-05 10:49:19 +1030 | [diff] [blame] | 7924 | for_each_online_cpu(cpu) { |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7925 | u32 *lockup_detected; |
| 7926 | lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); |
| 7927 | *lockup_detected = value; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7928 | } |
| 7929 | wmb(); /* be sure the per-cpu variables are out to memory */ |
| 7930 | } |
| 7931 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7932 | static void controller_lockup_detected(struct ctlr_info *h) |
| 7933 | { |
| 7934 | unsigned long flags; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7935 | u32 lockup_detected; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7936 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7937 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 7938 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7939 | lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); |
| 7940 | if (!lockup_detected) { |
| 7941 | /* no heartbeat, but controller gave us a zero. */ |
| 7942 | dev_warn(&h->pdev->dev, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7943 | "lockup detected after %d but scratchpad register is zero\n", |
| 7944 | h->heartbeat_sample_interval / HZ); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 7945 | lockup_detected = 0xffffffff; |
| 7946 | } |
| 7947 | set_lockup_detected_for_all_cpus(h, lockup_detected); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7948 | spin_unlock_irqrestore(&h->lock, flags); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7949 | dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x after %d\n", |
| 7950 | lockup_detected, h->heartbeat_sample_interval / HZ); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7951 | pci_disable_device(h->pdev); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7952 | fail_all_outstanding_cmds(h); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7953 | } |
| 7954 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7955 | static int detect_controller_lockup(struct ctlr_info *h) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7956 | { |
| 7957 | u64 now; |
| 7958 | u32 heartbeat; |
| 7959 | unsigned long flags; |
| 7960 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7961 | now = get_jiffies_64(); |
| 7962 | /* If we've received an interrupt recently, we're ok. */ |
| 7963 | if (time_after64(h->last_intr_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 7964 | (h->heartbeat_sample_interval), now)) |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7965 | return false; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7966 | |
| 7967 | /* |
| 7968 | * If we've already checked the heartbeat recently, we're ok. |
| 7969 | * This could happen if someone sends us a signal. We |
| 7970 | * otherwise don't care about signals in this thread. |
| 7971 | */ |
| 7972 | if (time_after64(h->last_heartbeat_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 7973 | (h->heartbeat_sample_interval), now)) |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7974 | return false; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7975 | |
| 7976 | /* If heartbeat has not changed since we last looked, we're not ok. */ |
| 7977 | spin_lock_irqsave(&h->lock, flags); |
| 7978 | heartbeat = readl(&h->cfgtable->HeartBeat); |
| 7979 | spin_unlock_irqrestore(&h->lock, flags); |
| 7980 | if (h->last_heartbeat == heartbeat) { |
| 7981 | controller_lockup_detected(h); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7982 | return true; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7983 | } |
| 7984 | |
| 7985 | /* We're ok. */ |
| 7986 | h->last_heartbeat = heartbeat; |
| 7987 | h->last_heartbeat_timestamp = now; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7988 | return false; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7989 | } |
| 7990 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 7991 | static void hpsa_ack_ctlr_events(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7992 | { |
| 7993 | int i; |
| 7994 | char *event_type; |
| 7995 | |
Stephen Cameron | e4aa3e6 | 2015-01-23 16:44:07 -0600 | [diff] [blame] | 7996 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
| 7997 | return; |
| 7998 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7999 | /* Ask the controller to clear the events we're handling. */ |
Stephen M. Cameron | 1f7cee8 | 2014-02-18 13:56:09 -0600 | [diff] [blame] | 8000 | if ((h->transMethod & (CFGTBL_Trans_io_accel1 |
| 8001 | | CFGTBL_Trans_io_accel2)) && |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8002 | (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE || |
| 8003 | h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE)) { |
| 8004 | |
| 8005 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE) |
| 8006 | event_type = "state change"; |
| 8007 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE) |
| 8008 | event_type = "configuration change"; |
| 8009 | /* Stop sending new RAID offload reqs via the IO accelerator */ |
| 8010 | scsi_block_requests(h->scsi_host); |
| 8011 | for (i = 0; i < h->ndevices; i++) |
| 8012 | h->dev[i]->offload_enabled = 0; |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 8013 | hpsa_drain_accel_commands(h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8014 | /* Set 'accelerator path config change' bit */ |
| 8015 | dev_warn(&h->pdev->dev, |
| 8016 | "Acknowledging event: 0x%08x (HP SSD Smart Path %s)\n", |
| 8017 | h->events, event_type); |
| 8018 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 8019 | /* Set the "clear event notify field update" bit 6 */ |
| 8020 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 8021 | /* Wait until ctlr clears 'clear event notify field', bit 6 */ |
| 8022 | hpsa_wait_for_clear_event_notify_ack(h); |
| 8023 | scsi_unblock_requests(h->scsi_host); |
| 8024 | } else { |
| 8025 | /* Acknowledge controller notification events. */ |
| 8026 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 8027 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 8028 | hpsa_wait_for_clear_event_notify_ack(h); |
| 8029 | #if 0 |
| 8030 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
| 8031 | hpsa_wait_for_mode_change_ack(h); |
| 8032 | #endif |
| 8033 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8034 | return; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8035 | } |
| 8036 | |
| 8037 | /* Check a register on the controller to see if there are configuration |
| 8038 | * changes (added/changed/removed logical drives, etc.) which mean that |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 8039 | * we should rescan the controller for devices. |
| 8040 | * Also check flag for driver-initiated rescan. |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8041 | */ |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8042 | static int hpsa_ctlr_needs_rescan(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8043 | { |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 8044 | if (h->drv_req_rescan) { |
| 8045 | h->drv_req_rescan = 0; |
| 8046 | return 1; |
| 8047 | } |
| 8048 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8049 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8050 | return 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8051 | |
| 8052 | h->events = readl(&(h->cfgtable->event_notify)); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8053 | return h->events & RESCAN_REQUIRED_EVENT_BITS; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8054 | } |
| 8055 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8056 | /* |
| 8057 | * Check if any of the offline devices have become ready |
| 8058 | */ |
| 8059 | static int hpsa_offline_devices_ready(struct ctlr_info *h) |
| 8060 | { |
| 8061 | unsigned long flags; |
| 8062 | struct offline_device_entry *d; |
| 8063 | struct list_head *this, *tmp; |
| 8064 | |
| 8065 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 8066 | list_for_each_safe(this, tmp, &h->offline_device_list) { |
| 8067 | d = list_entry(this, struct offline_device_entry, |
| 8068 | offline_list); |
| 8069 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
Stephen M. Cameron | d1fea47 | 2014-07-03 10:17:58 -0500 | [diff] [blame] | 8070 | if (!hpsa_volume_offline(h, d->scsi3addr)) { |
| 8071 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 8072 | list_del(&d->offline_list); |
| 8073 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8074 | return 1; |
Stephen M. Cameron | d1fea47 | 2014-07-03 10:17:58 -0500 | [diff] [blame] | 8075 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8076 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 8077 | } |
| 8078 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 8079 | return 0; |
| 8080 | } |
| 8081 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8082 | static int hpsa_luns_changed(struct ctlr_info *h) |
| 8083 | { |
| 8084 | int rc = 1; /* assume there are changes */ |
| 8085 | struct ReportLUNdata *logdev = NULL; |
| 8086 | |
| 8087 | /* if we can't find out if lun data has changed, |
| 8088 | * assume that it has. |
| 8089 | */ |
| 8090 | |
| 8091 | if (!h->lastlogicals) |
| 8092 | goto out; |
| 8093 | |
| 8094 | logdev = kzalloc(sizeof(*logdev), GFP_KERNEL); |
| 8095 | if (!logdev) { |
| 8096 | dev_warn(&h->pdev->dev, |
| 8097 | "Out of memory, can't track lun changes.\n"); |
| 8098 | goto out; |
| 8099 | } |
| 8100 | if (hpsa_scsi_do_report_luns(h, 1, logdev, sizeof(*logdev), 0)) { |
| 8101 | dev_warn(&h->pdev->dev, |
| 8102 | "report luns failed, can't track lun changes.\n"); |
| 8103 | goto out; |
| 8104 | } |
| 8105 | if (memcmp(logdev, h->lastlogicals, sizeof(*logdev))) { |
| 8106 | dev_info(&h->pdev->dev, |
| 8107 | "Lun changes detected.\n"); |
| 8108 | memcpy(h->lastlogicals, logdev, sizeof(*logdev)); |
| 8109 | goto out; |
| 8110 | } else |
| 8111 | rc = 0; /* no changes detected. */ |
| 8112 | out: |
| 8113 | kfree(logdev); |
| 8114 | return rc; |
| 8115 | } |
| 8116 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8117 | static void hpsa_rescan_ctlr_worker(struct work_struct *work) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8118 | { |
| 8119 | unsigned long flags; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8120 | struct ctlr_info *h = container_of(to_delayed_work(work), |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8121 | struct ctlr_info, rescan_ctlr_work); |
| 8122 | |
| 8123 | |
| 8124 | if (h->remove_in_progress) |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8125 | return; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8126 | |
| 8127 | if (hpsa_ctlr_needs_rescan(h) || hpsa_offline_devices_ready(h)) { |
| 8128 | scsi_host_get(h->scsi_host); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8129 | hpsa_ack_ctlr_events(h); |
| 8130 | hpsa_scan_start(h->scsi_host); |
| 8131 | scsi_host_put(h->scsi_host); |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8132 | } else if (h->discovery_polling) { |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 8133 | hpsa_disable_rld_caching(h); |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8134 | if (hpsa_luns_changed(h)) { |
| 8135 | struct Scsi_Host *sh = NULL; |
| 8136 | |
| 8137 | dev_info(&h->pdev->dev, |
| 8138 | "driver discovery polling rescan.\n"); |
| 8139 | sh = scsi_host_get(h->scsi_host); |
| 8140 | if (sh != NULL) { |
| 8141 | hpsa_scan_start(sh); |
| 8142 | scsi_host_put(sh); |
| 8143 | } |
| 8144 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8145 | } |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8146 | spin_lock_irqsave(&h->lock, flags); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8147 | if (!h->remove_in_progress) |
| 8148 | queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work, |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8149 | h->heartbeat_sample_interval); |
| 8150 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8151 | } |
| 8152 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8153 | static void hpsa_monitor_ctlr_worker(struct work_struct *work) |
| 8154 | { |
| 8155 | unsigned long flags; |
| 8156 | struct ctlr_info *h = container_of(to_delayed_work(work), |
| 8157 | struct ctlr_info, monitor_ctlr_work); |
| 8158 | |
| 8159 | detect_controller_lockup(h); |
| 8160 | if (lockup_detected(h)) |
| 8161 | return; |
| 8162 | |
| 8163 | spin_lock_irqsave(&h->lock, flags); |
| 8164 | if (!h->remove_in_progress) |
| 8165 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 8166 | h->heartbeat_sample_interval); |
| 8167 | spin_unlock_irqrestore(&h->lock, flags); |
| 8168 | } |
| 8169 | |
| 8170 | static struct workqueue_struct *hpsa_create_controller_wq(struct ctlr_info *h, |
| 8171 | char *name) |
| 8172 | { |
| 8173 | struct workqueue_struct *wq = NULL; |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8174 | |
Don Brace | 397ea9c | 2015-02-06 17:44:15 -0600 | [diff] [blame] | 8175 | wq = alloc_ordered_workqueue("%s_%d_hpsa", 0, name, h->ctlr); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8176 | if (!wq) |
| 8177 | dev_err(&h->pdev->dev, "failed to create %s workqueue\n", name); |
| 8178 | |
| 8179 | return wq; |
| 8180 | } |
| 8181 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8182 | 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] | 8183 | { |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 8184 | int dac, rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8185 | struct ctlr_info *h; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8186 | int try_soft_reset = 0; |
| 8187 | unsigned long flags; |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 8188 | u32 board_id; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8189 | |
| 8190 | if (number_of_controllers == 0) |
| 8191 | printk(KERN_INFO DRIVER_NAME "\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8192 | |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 8193 | rc = hpsa_lookup_board_id(pdev, &board_id); |
| 8194 | if (rc < 0) { |
| 8195 | dev_warn(&pdev->dev, "Board ID not found\n"); |
| 8196 | return rc; |
| 8197 | } |
| 8198 | |
| 8199 | rc = hpsa_init_reset_devices(pdev, board_id); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8200 | if (rc) { |
| 8201 | if (rc != -ENOTSUPP) |
| 8202 | return rc; |
| 8203 | /* If the reset fails in a particular way (it has no way to do |
| 8204 | * a proper hard reset, so returns -ENOTSUPP) we can try to do |
| 8205 | * a soft reset once we get the controller configured up to the |
| 8206 | * point that it can accept a command. |
| 8207 | */ |
| 8208 | try_soft_reset = 1; |
| 8209 | rc = 0; |
| 8210 | } |
| 8211 | |
| 8212 | reinit_after_soft_reset: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8213 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8214 | /* Command structures must be aligned on a 32-byte boundary because |
| 8215 | * the 5 lower bits of the address are used by the hardware. and by |
| 8216 | * the driver. See comments in hpsa.h for more info. |
| 8217 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8218 | BUILD_BUG_ON(sizeof(struct CommandList) % COMMANDLIST_ALIGNMENT); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8219 | h = kzalloc(sizeof(*h), GFP_KERNEL); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8220 | if (!h) { |
| 8221 | dev_err(&pdev->dev, "Failed to allocate controller head\n"); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8222 | return -ENOMEM; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8223 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8224 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 8225 | h->pdev = pdev; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8226 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 8227 | 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] | 8228 | INIT_LIST_HEAD(&h->offline_device_list); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 8229 | spin_lock_init(&h->lock); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8230 | spin_lock_init(&h->offline_device_lock); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 8231 | spin_lock_init(&h->scan_lock); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 8232 | atomic_set(&h->passthru_cmds_avail, HPSA_MAX_CONCURRENT_PASSTHRUS); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 8233 | atomic_set(&h->abort_cmds_available, HPSA_CMDS_RESERVED_FOR_ABORTS); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8234 | |
| 8235 | /* Allocate and clear per-cpu variable lockup_detected */ |
| 8236 | h->lockup_detected = alloc_percpu(u32); |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 8237 | if (!h->lockup_detected) { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8238 | dev_err(&h->pdev->dev, "Failed to allocate lockup detector\n"); |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 8239 | rc = -ENOMEM; |
Robert Elliott | 2efa592 | 2015-04-23 09:34:53 -0500 | [diff] [blame] | 8240 | goto clean1; /* aer/h */ |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 8241 | } |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8242 | set_lockup_detected_for_all_cpus(h, 0); |
| 8243 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 8244 | rc = hpsa_pci_init(h); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8245 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8246 | goto clean2; /* lu, aer/h */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8247 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8248 | /* relies on h-> settings made by hpsa_pci_init, including |
| 8249 | * interrupt_mode h->intr */ |
| 8250 | rc = hpsa_scsi_host_alloc(h); |
| 8251 | if (rc) |
| 8252 | goto clean2_5; /* pci, lu, aer/h */ |
| 8253 | |
| 8254 | sprintf(h->devname, HPSA "%d", h->scsi_host->host_no); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8255 | h->ctlr = number_of_controllers; |
| 8256 | number_of_controllers++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8257 | |
| 8258 | /* configure PCI DMA stuff */ |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8259 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 8260 | if (rc == 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8261 | dac = 1; |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8262 | } else { |
| 8263 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 8264 | if (rc == 0) { |
| 8265 | dac = 0; |
| 8266 | } else { |
| 8267 | dev_err(&pdev->dev, "no suitable DMA available\n"); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8268 | goto clean3; /* shost, pci, lu, aer/h */ |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8269 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8270 | } |
| 8271 | |
| 8272 | /* make sure the board interrupts are off */ |
| 8273 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 8274 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8275 | rc = hpsa_request_irqs(h, do_hpsa_intr_msi, do_hpsa_intr_intx); |
| 8276 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8277 | goto clean3; /* shost, pci, lu, aer/h */ |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 8278 | rc = hpsa_alloc_cmd_pool(h); |
Robert Elliott | 8947fd1 | 2015-01-23 16:42:54 -0600 | [diff] [blame] | 8279 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8280 | goto clean4; /* irq, shost, pci, lu, aer/h */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8281 | rc = hpsa_alloc_sg_chain_blocks(h); |
| 8282 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8283 | goto clean5; /* cmd, irq, shost, pci, lu, aer/h */ |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 8284 | init_waitqueue_head(&h->scan_wait_queue); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 8285 | init_waitqueue_head(&h->abort_cmd_wait_queue); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 8286 | init_waitqueue_head(&h->event_sync_wait_queue); |
| 8287 | mutex_init(&h->reset_mutex); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 8288 | h->scan_finished = 1; /* no scan currently in progress */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8289 | |
| 8290 | pci_set_drvdata(pdev, h); |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 8291 | h->ndevices = 0; |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8292 | |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 8293 | spin_lock_init(&h->devlock); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8294 | rc = hpsa_put_ctlr_into_performant_mode(h); |
| 8295 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8296 | goto clean6; /* sg, cmd, irq, shost, pci, lu, aer/h */ |
| 8297 | |
| 8298 | /* hook into SCSI subsystem */ |
| 8299 | rc = hpsa_scsi_add_host(h); |
| 8300 | if (rc) |
| 8301 | goto clean7; /* perf, sg, cmd, irq, shost, pci, lu, aer/h */ |
Robert Elliott | 2efa592 | 2015-04-23 09:34:53 -0500 | [diff] [blame] | 8302 | |
| 8303 | /* create the resubmit workqueue */ |
| 8304 | h->rescan_ctlr_wq = hpsa_create_controller_wq(h, "rescan"); |
| 8305 | if (!h->rescan_ctlr_wq) { |
| 8306 | rc = -ENOMEM; |
| 8307 | goto clean7; |
| 8308 | } |
| 8309 | |
| 8310 | h->resubmit_wq = hpsa_create_controller_wq(h, "resubmit"); |
| 8311 | if (!h->resubmit_wq) { |
| 8312 | rc = -ENOMEM; |
| 8313 | goto clean7; /* aer/h */ |
| 8314 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8315 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8316 | /* |
| 8317 | * At this point, the controller is ready to take commands. |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8318 | * Now, if reset_devices and the hard reset didn't work, try |
| 8319 | * the soft reset and see if that works. |
| 8320 | */ |
| 8321 | if (try_soft_reset) { |
| 8322 | |
| 8323 | /* This is kind of gross. We may or may not get a completion |
| 8324 | * from the soft reset command, and if we do, then the value |
| 8325 | * from the fifo may or may not be valid. So, we wait 10 secs |
| 8326 | * after the reset throwing away any completions we get during |
| 8327 | * that time. Unregister the interrupt handler and register |
| 8328 | * fake ones to scoop up any residual completions. |
| 8329 | */ |
| 8330 | spin_lock_irqsave(&h->lock, flags); |
| 8331 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8332 | spin_unlock_irqrestore(&h->lock, flags); |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8333 | hpsa_free_irqs(h); |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 8334 | rc = hpsa_request_irqs(h, hpsa_msix_discard_completions, |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8335 | hpsa_intx_discard_completions); |
| 8336 | if (rc) { |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 8337 | dev_warn(&h->pdev->dev, |
| 8338 | "Failed to request_irq after soft reset.\n"); |
Robert Elliott | d498757 | 2015-04-23 09:34:37 -0500 | [diff] [blame] | 8339 | /* |
Robert Elliott | b2ef480 | 2015-04-23 09:34:48 -0500 | [diff] [blame] | 8340 | * cannot goto clean7 or free_irqs will be called |
| 8341 | * again. Instead, do its work |
| 8342 | */ |
| 8343 | hpsa_free_performant_mode(h); /* clean7 */ |
| 8344 | hpsa_free_sg_chain_blocks(h); /* clean6 */ |
| 8345 | hpsa_free_cmd_pool(h); /* clean5 */ |
| 8346 | /* |
| 8347 | * skip hpsa_free_irqs(h) clean4 since that |
| 8348 | * was just called before request_irqs failed |
Robert Elliott | d498757 | 2015-04-23 09:34:37 -0500 | [diff] [blame] | 8349 | */ |
| 8350 | goto clean3; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8351 | } |
| 8352 | |
| 8353 | rc = hpsa_kdump_soft_reset(h); |
| 8354 | if (rc) |
| 8355 | /* Neither hard nor soft reset worked, we're hosed. */ |
Don Brace | 7ef7323 | 2015-07-18 11:12:33 -0500 | [diff] [blame] | 8356 | goto clean7; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8357 | |
| 8358 | dev_info(&h->pdev->dev, "Board READY.\n"); |
| 8359 | dev_info(&h->pdev->dev, |
| 8360 | "Waiting for stale completions to drain.\n"); |
| 8361 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 8362 | msleep(10000); |
| 8363 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8364 | |
| 8365 | rc = controller_reset_failed(h->cfgtable); |
| 8366 | if (rc) |
| 8367 | dev_info(&h->pdev->dev, |
| 8368 | "Soft reset appears to have failed.\n"); |
| 8369 | |
| 8370 | /* since the controller's reset, we have to go back and re-init |
| 8371 | * everything. Easiest to just forget what we've done and do it |
| 8372 | * all over again. |
| 8373 | */ |
| 8374 | hpsa_undo_allocations_after_kdump_soft_reset(h); |
| 8375 | try_soft_reset = 0; |
| 8376 | if (rc) |
Robert Elliott | b2ef480 | 2015-04-23 09:34:48 -0500 | [diff] [blame] | 8377 | /* don't goto clean, we already unallocated */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8378 | return -ENODEV; |
| 8379 | |
| 8380 | goto reinit_after_soft_reset; |
| 8381 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8382 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8383 | /* Enable Accelerated IO path at driver layer */ |
| 8384 | h->acciopath_status = 1; |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8385 | /* Disable discovery polling.*/ |
| 8386 | h->discovery_polling = 0; |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 8387 | |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 8388 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8389 | /* Turn the interrupts on so we can service requests */ |
| 8390 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 8391 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 8392 | hpsa_hba_inquiry(h); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8393 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8394 | h->lastlogicals = kzalloc(sizeof(*(h->lastlogicals)), GFP_KERNEL); |
| 8395 | if (!h->lastlogicals) |
| 8396 | dev_info(&h->pdev->dev, |
| 8397 | "Can't track change to report lun data\n"); |
| 8398 | |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8399 | /* Monitor the controller for firmware lockups */ |
| 8400 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 8401 | INIT_DELAYED_WORK(&h->monitor_ctlr_work, hpsa_monitor_ctlr_worker); |
| 8402 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 8403 | h->heartbeat_sample_interval); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8404 | INIT_DELAYED_WORK(&h->rescan_ctlr_work, hpsa_rescan_ctlr_worker); |
| 8405 | queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work, |
| 8406 | h->heartbeat_sample_interval); |
Stephen M. Cameron | 88bf6d6 | 2013-11-01 11:02:25 -0500 | [diff] [blame] | 8407 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8408 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8409 | clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8410 | hpsa_free_performant_mode(h); |
| 8411 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8412 | clean6: /* sg, cmd, irq, pci, lockup, wq/aer/h */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 8413 | hpsa_free_sg_chain_blocks(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8414 | clean5: /* cmd, irq, shost, pci, lu, aer/h */ |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 8415 | hpsa_free_cmd_pool(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8416 | clean4: /* irq, shost, pci, lu, aer/h */ |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8417 | hpsa_free_irqs(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8418 | clean3: /* shost, pci, lu, aer/h */ |
| 8419 | scsi_host_put(h->scsi_host); |
| 8420 | h->scsi_host = NULL; |
| 8421 | clean2_5: /* pci, lu, aer/h */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8422 | hpsa_free_pci_init(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8423 | clean2: /* lu, aer/h */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8424 | if (h->lockup_detected) { |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8425 | free_percpu(h->lockup_detected); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8426 | h->lockup_detected = NULL; |
| 8427 | } |
| 8428 | clean1: /* wq/aer/h */ |
| 8429 | if (h->resubmit_wq) { |
| 8430 | destroy_workqueue(h->resubmit_wq); |
| 8431 | h->resubmit_wq = NULL; |
| 8432 | } |
| 8433 | if (h->rescan_ctlr_wq) { |
| 8434 | destroy_workqueue(h->rescan_ctlr_wq); |
| 8435 | h->rescan_ctlr_wq = NULL; |
| 8436 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8437 | kfree(h); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8438 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8439 | } |
| 8440 | |
| 8441 | static void hpsa_flush_cache(struct ctlr_info *h) |
| 8442 | { |
| 8443 | char *flush_buf; |
| 8444 | struct CommandList *c; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8445 | int rc; |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 8446 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8447 | if (unlikely(lockup_detected(h))) |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 8448 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8449 | flush_buf = kzalloc(4, GFP_KERNEL); |
| 8450 | if (!flush_buf) |
| 8451 | return; |
| 8452 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 8453 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 8454 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 8455 | if (fill_cmd(c, HPSA_CACHE_FLUSH, h, flush_buf, 4, 0, |
| 8456 | RAID_CTLR_LUNID, TYPE_CMD)) { |
| 8457 | goto out; |
| 8458 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8459 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 8460 | PCI_DMA_TODEVICE, NO_TIMEOUT); |
| 8461 | if (rc) |
| 8462 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8463 | if (c->err_info->CommandStatus != 0) |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 8464 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8465 | dev_warn(&h->pdev->dev, |
| 8466 | "error flushing cache on controller\n"); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 8467 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8468 | kfree(flush_buf); |
| 8469 | } |
| 8470 | |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 8471 | /* Make controller gather fresh report lun data each time we |
| 8472 | * send down a report luns request |
| 8473 | */ |
| 8474 | static void hpsa_disable_rld_caching(struct ctlr_info *h) |
| 8475 | { |
| 8476 | u32 *options; |
| 8477 | struct CommandList *c; |
| 8478 | int rc; |
| 8479 | |
| 8480 | /* Don't bother trying to set diag options if locked up */ |
| 8481 | if (unlikely(h->lockup_detected)) |
| 8482 | return; |
| 8483 | |
| 8484 | options = kzalloc(sizeof(*options), GFP_KERNEL); |
| 8485 | if (!options) { |
| 8486 | dev_err(&h->pdev->dev, |
| 8487 | "Error: failed to disable rld caching, during alloc.\n"); |
| 8488 | return; |
| 8489 | } |
| 8490 | |
| 8491 | c = cmd_alloc(h); |
| 8492 | |
| 8493 | /* first, get the current diag options settings */ |
| 8494 | if (fill_cmd(c, BMIC_SENSE_DIAG_OPTIONS, h, options, 4, 0, |
| 8495 | RAID_CTLR_LUNID, TYPE_CMD)) |
| 8496 | goto errout; |
| 8497 | |
| 8498 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 8499 | PCI_DMA_FROMDEVICE, NO_TIMEOUT); |
| 8500 | if ((rc != 0) || (c->err_info->CommandStatus != 0)) |
| 8501 | goto errout; |
| 8502 | |
| 8503 | /* Now, set the bit for disabling the RLD caching */ |
| 8504 | *options |= HPSA_DIAG_OPTS_DISABLE_RLD_CACHING; |
| 8505 | |
| 8506 | if (fill_cmd(c, BMIC_SET_DIAG_OPTIONS, h, options, 4, 0, |
| 8507 | RAID_CTLR_LUNID, TYPE_CMD)) |
| 8508 | goto errout; |
| 8509 | |
| 8510 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 8511 | PCI_DMA_TODEVICE, NO_TIMEOUT); |
| 8512 | if ((rc != 0) || (c->err_info->CommandStatus != 0)) |
| 8513 | goto errout; |
| 8514 | |
| 8515 | /* Now verify that it got set: */ |
| 8516 | if (fill_cmd(c, BMIC_SENSE_DIAG_OPTIONS, h, options, 4, 0, |
| 8517 | RAID_CTLR_LUNID, TYPE_CMD)) |
| 8518 | goto errout; |
| 8519 | |
| 8520 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
| 8521 | PCI_DMA_FROMDEVICE, NO_TIMEOUT); |
| 8522 | if ((rc != 0) || (c->err_info->CommandStatus != 0)) |
| 8523 | goto errout; |
| 8524 | |
| 8525 | if (*options && HPSA_DIAG_OPTS_DISABLE_RLD_CACHING) |
| 8526 | goto out; |
| 8527 | |
| 8528 | errout: |
| 8529 | dev_err(&h->pdev->dev, |
| 8530 | "Error: failed to disable report lun data caching.\n"); |
| 8531 | out: |
| 8532 | cmd_free(h, c); |
| 8533 | kfree(options); |
| 8534 | } |
| 8535 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8536 | static void hpsa_shutdown(struct pci_dev *pdev) |
| 8537 | { |
| 8538 | struct ctlr_info *h; |
| 8539 | |
| 8540 | h = pci_get_drvdata(pdev); |
| 8541 | /* Turn board interrupts off and send the flush cache command |
| 8542 | * sendcmd will turn off interrupt, and send the flush... |
| 8543 | * To write all data in the battery backed cache to disks |
| 8544 | */ |
| 8545 | hpsa_flush_cache(h); |
| 8546 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8547 | hpsa_free_irqs(h); /* init_one 4 */ |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 8548 | hpsa_disable_interrupt_mode(h); /* pci_init 2 */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8549 | } |
| 8550 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8551 | static void hpsa_free_device_info(struct ctlr_info *h) |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 8552 | { |
| 8553 | int i; |
| 8554 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8555 | for (i = 0; i < h->ndevices; i++) { |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 8556 | kfree(h->dev[i]); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8557 | h->dev[i] = NULL; |
| 8558 | } |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 8559 | } |
| 8560 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8561 | static void hpsa_remove_one(struct pci_dev *pdev) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8562 | { |
| 8563 | struct ctlr_info *h; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8564 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8565 | |
| 8566 | if (pci_get_drvdata(pdev) == NULL) { |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8567 | dev_err(&pdev->dev, "unable to remove device\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8568 | return; |
| 8569 | } |
| 8570 | h = pci_get_drvdata(pdev); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8571 | |
| 8572 | /* Get rid of any controller monitoring work items */ |
| 8573 | spin_lock_irqsave(&h->lock, flags); |
| 8574 | h->remove_in_progress = 1; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8575 | spin_unlock_irqrestore(&h->lock, flags); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8576 | cancel_delayed_work_sync(&h->monitor_ctlr_work); |
| 8577 | cancel_delayed_work_sync(&h->rescan_ctlr_work); |
| 8578 | destroy_workqueue(h->rescan_ctlr_wq); |
| 8579 | destroy_workqueue(h->resubmit_wq); |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 8580 | |
Don Brace | 2d04130 | 2015-07-18 11:13:15 -0500 | [diff] [blame] | 8581 | /* |
| 8582 | * Call before disabling interrupts. |
| 8583 | * scsi_remove_host can trigger I/O operations especially |
| 8584 | * when multipath is enabled. There can be SYNCHRONIZE CACHE |
| 8585 | * operations which cannot complete and will hang the system. |
| 8586 | */ |
| 8587 | if (h->scsi_host) |
| 8588 | scsi_remove_host(h->scsi_host); /* init_one 8 */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8589 | /* includes hpsa_free_irqs - init_one 4 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8590 | /* includes hpsa_disable_interrupt_mode - pci_init 2 */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8591 | hpsa_shutdown(pdev); |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 8592 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8593 | hpsa_free_device_info(h); /* scan */ |
| 8594 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8595 | kfree(h->hba_inquiry_data); /* init_one 10 */ |
| 8596 | h->hba_inquiry_data = NULL; /* init_one 10 */ |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8597 | hpsa_free_ioaccel2_sg_chain_blocks(h); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8598 | hpsa_free_performant_mode(h); /* init_one 7 */ |
| 8599 | hpsa_free_sg_chain_blocks(h); /* init_one 6 */ |
| 8600 | hpsa_free_cmd_pool(h); /* init_one 5 */ |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8601 | kfree(h->lastlogicals); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8602 | |
| 8603 | /* hpsa_free_irqs already called via hpsa_shutdown init_one 4 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8604 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8605 | scsi_host_put(h->scsi_host); /* init_one 3 */ |
| 8606 | h->scsi_host = NULL; /* init_one 3 */ |
| 8607 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8608 | /* includes hpsa_disable_interrupt_mode - pci_init 2 */ |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8609 | hpsa_free_pci_init(h); /* init_one 2.5 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8610 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8611 | free_percpu(h->lockup_detected); /* init_one 2 */ |
| 8612 | h->lockup_detected = NULL; /* init_one 2 */ |
| 8613 | /* (void) pci_disable_pcie_error_reporting(pdev); */ /* init_one 1 */ |
| 8614 | kfree(h); /* init_one 1 */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8615 | } |
| 8616 | |
| 8617 | static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev, |
| 8618 | __attribute__((unused)) pm_message_t state) |
| 8619 | { |
| 8620 | return -ENOSYS; |
| 8621 | } |
| 8622 | |
| 8623 | static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev) |
| 8624 | { |
| 8625 | return -ENOSYS; |
| 8626 | } |
| 8627 | |
| 8628 | static struct pci_driver hpsa_pci_driver = { |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 8629 | .name = HPSA, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8630 | .probe = hpsa_init_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8631 | .remove = hpsa_remove_one, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8632 | .id_table = hpsa_pci_device_id, /* id_table */ |
| 8633 | .shutdown = hpsa_shutdown, |
| 8634 | .suspend = hpsa_suspend, |
| 8635 | .resume = hpsa_resume, |
| 8636 | }; |
| 8637 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8638 | /* Fill in bucket_map[], given nsgs (the max number of |
| 8639 | * scatter gather elements supported) and bucket[], |
| 8640 | * which is an array of 8 integers. The bucket[] array |
| 8641 | * contains 8 different DMA transfer sizes (in 16 |
| 8642 | * byte increments) which the controller uses to fetch |
| 8643 | * commands. This function fills in bucket_map[], which |
| 8644 | * maps a given number of scatter gather elements to one of |
| 8645 | * the 8 DMA transfer sizes. The point of it is to allow the |
| 8646 | * controller to only do as much DMA as needed to fetch the |
| 8647 | * command, with the DMA transfer size encoded in the lower |
| 8648 | * bits of the command address. |
| 8649 | */ |
| 8650 | static void calc_bucket_map(int bucket[], int num_buckets, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 8651 | int nsgs, int min_blocks, u32 *bucket_map) |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8652 | { |
| 8653 | int i, j, b, size; |
| 8654 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8655 | /* Note, bucket_map must have nsgs+1 entries. */ |
| 8656 | for (i = 0; i <= nsgs; i++) { |
| 8657 | /* Compute size of a command with i SG entries */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8658 | size = i + min_blocks; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8659 | b = num_buckets; /* Assume the biggest bucket */ |
| 8660 | /* Find the bucket that is just big enough */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8661 | for (j = 0; j < num_buckets; j++) { |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8662 | if (bucket[j] >= size) { |
| 8663 | b = j; |
| 8664 | break; |
| 8665 | } |
| 8666 | } |
| 8667 | /* for a command with i SG entries, use bucket b. */ |
| 8668 | bucket_map[i] = b; |
| 8669 | } |
| 8670 | } |
| 8671 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8672 | /* |
| 8673 | * return -ENODEV on err, 0 on success (or no action) |
| 8674 | * allocates numerous items that must be freed later |
| 8675 | */ |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 8676 | 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] | 8677 | { |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 8678 | int i; |
| 8679 | unsigned long register_value; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8680 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 8681 | (trans_support & CFGTBL_Trans_use_short_tags) | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8682 | CFGTBL_Trans_enable_directed_msix | |
| 8683 | (trans_support & (CFGTBL_Trans_io_accel1 | |
| 8684 | CFGTBL_Trans_io_accel2)); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8685 | struct access_method access = SA5_performant_access; |
Stephen M. Cameron | def342b | 2010-05-27 15:14:39 -0500 | [diff] [blame] | 8686 | |
| 8687 | /* This is a bit complicated. There are 8 registers on |
| 8688 | * the controller which we write to to tell it 8 different |
| 8689 | * sizes of commands which there may be. It's a way of |
| 8690 | * reducing the DMA done to fetch each command. Encoded into |
| 8691 | * each command's tag are 3 bits which communicate to the controller |
| 8692 | * which of the eight sizes that command fits within. The size of |
| 8693 | * each command depends on how many scatter gather entries there are. |
| 8694 | * Each SG entry requires 16 bytes. The eight registers are programmed |
| 8695 | * with the number of 16-byte blocks a command of that size requires. |
| 8696 | * The smallest command possible requires 5 such 16 byte blocks. |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 8697 | * 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] | 8698 | * blocks. Note, this only extends to the SG entries contained |
| 8699 | * within the command block, and does not extend to chained blocks |
| 8700 | * of SG elements. bft[] contains the eight values we write to |
| 8701 | * the registers. They are not evenly distributed, but have more |
| 8702 | * sizes for small commands, and fewer sizes for larger commands. |
| 8703 | */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 8704 | 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] | 8705 | #define MIN_IOACCEL2_BFT_ENTRY 5 |
| 8706 | #define HPSA_IOACCEL2_HEADER_SZ 4 |
| 8707 | int bft2[16] = {MIN_IOACCEL2_BFT_ENTRY, 6, 7, 8, 9, 10, 11, 12, |
| 8708 | 13, 14, 15, 16, 17, 18, 19, |
| 8709 | HPSA_IOACCEL2_HEADER_SZ + IOACCEL2_MAXSGENTRIES}; |
| 8710 | BUILD_BUG_ON(ARRAY_SIZE(bft2) != 16); |
| 8711 | BUILD_BUG_ON(ARRAY_SIZE(bft) != 8); |
| 8712 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) > |
| 8713 | 16 * MIN_IOACCEL2_BFT_ENTRY); |
| 8714 | BUILD_BUG_ON(sizeof(struct ioaccel2_sg_element) != 16); |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 8715 | BUILD_BUG_ON(28 > SG_ENTRIES_IN_CMD + 4); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8716 | /* 5 = 1 s/g entry or 4k |
| 8717 | * 6 = 2 s/g entry or 8k |
| 8718 | * 8 = 4 s/g entry or 16k |
| 8719 | * 10 = 6 s/g entry or 24k |
| 8720 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8721 | |
Stephen M. Cameron | b3a52e7 | 2014-05-29 10:53:23 -0500 | [diff] [blame] | 8722 | /* If the controller supports either ioaccel method then |
| 8723 | * we can also use the RAID stack submit path that does not |
| 8724 | * perform the superfluous readl() after each command submission. |
| 8725 | */ |
| 8726 | if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2)) |
| 8727 | access = SA5_performant_access_no_read; |
| 8728 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8729 | /* Controller spec: zero out this buffer. */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 8730 | for (i = 0; i < h->nreply_queues; i++) |
| 8731 | memset(h->reply_queue[i].head, 0, h->reply_queue_size); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8732 | |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 8733 | bft[7] = SG_ENTRIES_IN_CMD + 4; |
| 8734 | calc_bucket_map(bft, ARRAY_SIZE(bft), |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8735 | SG_ENTRIES_IN_CMD, 4, h->blockFetchTable); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8736 | for (i = 0; i < 8; i++) |
| 8737 | writel(bft[i], &h->transtable->BlockFetch[i]); |
| 8738 | |
| 8739 | /* size of controller ring buffer */ |
| 8740 | writel(h->max_commands, &h->transtable->RepQSize); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8741 | writel(h->nreply_queues, &h->transtable->RepQCount); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8742 | writel(0, &h->transtable->RepQCtrAddrLow32); |
| 8743 | writel(0, &h->transtable->RepQCtrAddrHigh32); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8744 | |
| 8745 | for (i = 0; i < h->nreply_queues; i++) { |
| 8746 | writel(0, &h->transtable->RepQAddr[i].upper); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 8747 | writel(h->reply_queue[i].busaddr, |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8748 | &h->transtable->RepQAddr[i].lower); |
| 8749 | } |
| 8750 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8751 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8752 | writel(transMethod, &(h->cfgtable->HostWrite.TransportRequest)); |
| 8753 | /* |
| 8754 | * enable outbound interrupt coalescing in accelerator mode; |
| 8755 | */ |
| 8756 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 8757 | access = SA5_ioaccel_mode1_access; |
| 8758 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 8759 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 8760 | } else { |
| 8761 | if (trans_support & CFGTBL_Trans_io_accel2) { |
| 8762 | access = SA5_ioaccel_mode2_access; |
| 8763 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 8764 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
| 8765 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8766 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8767 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 8768 | if (hpsa_wait_for_mode_change_ack(h)) { |
| 8769 | dev_err(&h->pdev->dev, |
| 8770 | "performant mode problem - doorbell timeout\n"); |
| 8771 | return -ENODEV; |
| 8772 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8773 | register_value = readl(&(h->cfgtable->TransportActive)); |
| 8774 | if (!(register_value & CFGTBL_Trans_Performant)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 8775 | dev_err(&h->pdev->dev, |
| 8776 | "performant mode problem - transport not active\n"); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 8777 | return -ENODEV; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8778 | } |
Stephen M. Cameron | 960a30e7 | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 8779 | /* Change the access methods to the performant access methods */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8780 | h->access = access; |
| 8781 | h->transMethod = transMethod; |
| 8782 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8783 | if (!((trans_support & CFGTBL_Trans_io_accel1) || |
| 8784 | (trans_support & CFGTBL_Trans_io_accel2))) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 8785 | return 0; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8786 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8787 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 8788 | /* Set up I/O accelerator mode */ |
| 8789 | for (i = 0; i < h->nreply_queues; i++) { |
| 8790 | writel(i, h->vaddr + IOACCEL_MODE1_REPLY_QUEUE_INDEX); |
| 8791 | h->reply_queue[i].current_entry = |
| 8792 | readl(h->vaddr + IOACCEL_MODE1_PRODUCER_INDEX); |
| 8793 | } |
| 8794 | bft[7] = h->ioaccel_maxsg + 8; |
| 8795 | calc_bucket_map(bft, ARRAY_SIZE(bft), h->ioaccel_maxsg, 8, |
| 8796 | h->ioaccel1_blockFetchTable); |
| 8797 | |
| 8798 | /* initialize all reply queue entries to unused */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 8799 | for (i = 0; i < h->nreply_queues; i++) |
| 8800 | memset(h->reply_queue[i].head, |
| 8801 | (u8) IOACCEL_MODE1_REPLY_UNUSED, |
| 8802 | h->reply_queue_size); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8803 | |
| 8804 | /* set all the constant fields in the accelerator command |
| 8805 | * frames once at init time to save CPU cycles later. |
| 8806 | */ |
| 8807 | for (i = 0; i < h->nr_cmds; i++) { |
| 8808 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[i]; |
| 8809 | |
| 8810 | cp->function = IOACCEL1_FUNCTION_SCSIIO; |
| 8811 | cp->err_info = (u32) (h->errinfo_pool_dhandle + |
| 8812 | (i * sizeof(struct ErrorInfo))); |
| 8813 | cp->err_info_len = sizeof(struct ErrorInfo); |
| 8814 | cp->sgl_offset = IOACCEL1_SGLOFFSET; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 8815 | cp->host_context_flags = |
| 8816 | cpu_to_le16(IOACCEL1_HCFLAGS_CISS_FORMAT); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8817 | cp->timeout_sec = 0; |
| 8818 | cp->ReplyQueue = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 8819 | cp->tag = |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 8820 | cpu_to_le64((i << DIRECT_LOOKUP_SHIFT)); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 8821 | cp->host_addr = |
| 8822 | cpu_to_le64(h->ioaccel_cmd_pool_dhandle + |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8823 | (i * sizeof(struct io_accel1_cmd))); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8824 | } |
| 8825 | } else if (trans_support & CFGTBL_Trans_io_accel2) { |
| 8826 | u64 cfg_offset, cfg_base_addr_index; |
| 8827 | u32 bft2_offset, cfg_base_addr; |
| 8828 | int rc; |
| 8829 | |
| 8830 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 8831 | &cfg_base_addr_index, &cfg_offset); |
| 8832 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) != 64); |
| 8833 | bft2[15] = h->ioaccel_maxsg + HPSA_IOACCEL2_HEADER_SZ; |
| 8834 | calc_bucket_map(bft2, ARRAY_SIZE(bft2), h->ioaccel_maxsg, |
| 8835 | 4, h->ioaccel2_blockFetchTable); |
| 8836 | bft2_offset = readl(&h->cfgtable->io_accel_request_size_offset); |
| 8837 | BUILD_BUG_ON(offsetof(struct CfgTable, |
| 8838 | io_accel_request_size_offset) != 0xb8); |
| 8839 | h->ioaccel2_bft2_regs = |
| 8840 | remap_pci_mem(pci_resource_start(h->pdev, |
| 8841 | cfg_base_addr_index) + |
| 8842 | cfg_offset + bft2_offset, |
| 8843 | ARRAY_SIZE(bft2) * |
| 8844 | sizeof(*h->ioaccel2_bft2_regs)); |
| 8845 | for (i = 0; i < ARRAY_SIZE(bft2); i++) |
| 8846 | writel(bft2[i], &h->ioaccel2_bft2_regs[i]); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8847 | } |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8848 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 8849 | if (hpsa_wait_for_mode_change_ack(h)) { |
| 8850 | dev_err(&h->pdev->dev, |
| 8851 | "performant mode problem - enabling ioaccel mode\n"); |
| 8852 | return -ENODEV; |
| 8853 | } |
| 8854 | return 0; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8855 | } |
| 8856 | |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8857 | /* Free ioaccel1 mode command blocks and block fetch table */ |
| 8858 | static void hpsa_free_ioaccel1_cmd_and_bft(struct ctlr_info *h) |
| 8859 | { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8860 | if (h->ioaccel_cmd_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8861 | pci_free_consistent(h->pdev, |
| 8862 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 8863 | h->ioaccel_cmd_pool, |
| 8864 | h->ioaccel_cmd_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8865 | h->ioaccel_cmd_pool = NULL; |
| 8866 | h->ioaccel_cmd_pool_dhandle = 0; |
| 8867 | } |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8868 | kfree(h->ioaccel1_blockFetchTable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8869 | h->ioaccel1_blockFetchTable = NULL; |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8870 | } |
| 8871 | |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 8872 | /* Allocate ioaccel1 mode command blocks and block fetch table */ |
| 8873 | static int hpsa_alloc_ioaccel1_cmd_and_bft(struct ctlr_info *h) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8874 | { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 8875 | h->ioaccel_maxsg = |
| 8876 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 8877 | if (h->ioaccel_maxsg > IOACCEL1_MAXSGENTRIES) |
| 8878 | h->ioaccel_maxsg = IOACCEL1_MAXSGENTRIES; |
| 8879 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8880 | /* Command structures must be aligned on a 128-byte boundary |
| 8881 | * because the 7 lower bits of the address are used by the |
| 8882 | * hardware. |
| 8883 | */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8884 | BUILD_BUG_ON(sizeof(struct io_accel1_cmd) % |
| 8885 | IOACCEL1_COMMANDLIST_ALIGNMENT); |
| 8886 | h->ioaccel_cmd_pool = |
| 8887 | pci_alloc_consistent(h->pdev, |
| 8888 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 8889 | &(h->ioaccel_cmd_pool_dhandle)); |
| 8890 | |
| 8891 | h->ioaccel1_blockFetchTable = |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 8892 | kmalloc(((h->ioaccel_maxsg + 1) * |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8893 | sizeof(u32)), GFP_KERNEL); |
| 8894 | |
| 8895 | if ((h->ioaccel_cmd_pool == NULL) || |
| 8896 | (h->ioaccel1_blockFetchTable == NULL)) |
| 8897 | goto clean_up; |
| 8898 | |
| 8899 | memset(h->ioaccel_cmd_pool, 0, |
| 8900 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool)); |
| 8901 | return 0; |
| 8902 | |
| 8903 | clean_up: |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8904 | hpsa_free_ioaccel1_cmd_and_bft(h); |
Robert Elliott | 2dd02d7 | 2015-04-23 09:33:43 -0500 | [diff] [blame] | 8905 | return -ENOMEM; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 8906 | } |
| 8907 | |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8908 | /* Free ioaccel2 mode command blocks and block fetch table */ |
| 8909 | static void hpsa_free_ioaccel2_cmd_and_bft(struct ctlr_info *h) |
| 8910 | { |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 8911 | hpsa_free_ioaccel2_sg_chain_blocks(h); |
| 8912 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8913 | if (h->ioaccel2_cmd_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8914 | pci_free_consistent(h->pdev, |
| 8915 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 8916 | h->ioaccel2_cmd_pool, |
| 8917 | h->ioaccel2_cmd_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8918 | h->ioaccel2_cmd_pool = NULL; |
| 8919 | h->ioaccel2_cmd_pool_dhandle = 0; |
| 8920 | } |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8921 | kfree(h->ioaccel2_blockFetchTable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8922 | h->ioaccel2_blockFetchTable = NULL; |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8923 | } |
| 8924 | |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 8925 | /* Allocate ioaccel2 mode command blocks and block fetch table */ |
| 8926 | static int hpsa_alloc_ioaccel2_cmd_and_bft(struct ctlr_info *h) |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 8927 | { |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 8928 | int rc; |
| 8929 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 8930 | /* Allocate ioaccel2 mode command blocks and block fetch table */ |
| 8931 | |
| 8932 | h->ioaccel_maxsg = |
| 8933 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 8934 | if (h->ioaccel_maxsg > IOACCEL2_MAXSGENTRIES) |
| 8935 | h->ioaccel_maxsg = IOACCEL2_MAXSGENTRIES; |
| 8936 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 8937 | BUILD_BUG_ON(sizeof(struct io_accel2_cmd) % |
| 8938 | IOACCEL2_COMMANDLIST_ALIGNMENT); |
| 8939 | h->ioaccel2_cmd_pool = |
| 8940 | pci_alloc_consistent(h->pdev, |
| 8941 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 8942 | &(h->ioaccel2_cmd_pool_dhandle)); |
| 8943 | |
| 8944 | h->ioaccel2_blockFetchTable = |
| 8945 | kmalloc(((h->ioaccel_maxsg + 1) * |
| 8946 | sizeof(u32)), GFP_KERNEL); |
| 8947 | |
| 8948 | if ((h->ioaccel2_cmd_pool == NULL) || |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 8949 | (h->ioaccel2_blockFetchTable == NULL)) { |
| 8950 | rc = -ENOMEM; |
| 8951 | goto clean_up; |
| 8952 | } |
| 8953 | |
| 8954 | rc = hpsa_allocate_ioaccel2_sg_chain_blocks(h); |
| 8955 | if (rc) |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 8956 | goto clean_up; |
| 8957 | |
| 8958 | memset(h->ioaccel2_cmd_pool, 0, |
| 8959 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool)); |
| 8960 | return 0; |
| 8961 | |
| 8962 | clean_up: |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8963 | hpsa_free_ioaccel2_cmd_and_bft(h); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 8964 | return rc; |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 8965 | } |
| 8966 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8967 | /* Free items allocated by hpsa_put_ctlr_into_performant_mode */ |
| 8968 | static void hpsa_free_performant_mode(struct ctlr_info *h) |
| 8969 | { |
| 8970 | kfree(h->blockFetchTable); |
| 8971 | h->blockFetchTable = NULL; |
| 8972 | hpsa_free_reply_queues(h); |
| 8973 | hpsa_free_ioaccel1_cmd_and_bft(h); |
| 8974 | hpsa_free_ioaccel2_cmd_and_bft(h); |
| 8975 | } |
| 8976 | |
| 8977 | /* return -ENODEV on error, 0 on success (or no action) |
| 8978 | * allocates numerous items that must be freed later |
| 8979 | */ |
| 8980 | static int hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h) |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 8981 | { |
| 8982 | u32 trans_support; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8983 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 8984 | CFGTBL_Trans_use_short_tags; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8985 | int i, rc; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 8986 | |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 8987 | if (hpsa_simple_mode) |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8988 | return 0; |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 8989 | |
scameron@beardog.cce.hp.com | 67c99a7 | 2014-04-14 14:01:09 -0500 | [diff] [blame] | 8990 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 8991 | if (!(trans_support & PERFORMANT_MODE)) |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8992 | return 0; |
scameron@beardog.cce.hp.com | 67c99a7 | 2014-04-14 14:01:09 -0500 | [diff] [blame] | 8993 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 8994 | /* Check for I/O accelerator mode support */ |
| 8995 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 8996 | transMethod |= CFGTBL_Trans_io_accel1 | |
| 8997 | CFGTBL_Trans_enable_directed_msix; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8998 | rc = hpsa_alloc_ioaccel1_cmd_and_bft(h); |
| 8999 | if (rc) |
| 9000 | return rc; |
| 9001 | } else if (trans_support & CFGTBL_Trans_io_accel2) { |
| 9002 | transMethod |= CFGTBL_Trans_io_accel2 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 9003 | CFGTBL_Trans_enable_directed_msix; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9004 | rc = hpsa_alloc_ioaccel2_cmd_and_bft(h); |
| 9005 | if (rc) |
| 9006 | return rc; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9007 | } |
| 9008 | |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 9009 | h->nreply_queues = h->msix_vector > 0 ? h->msix_vector : 1; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 9010 | hpsa_get_max_perf_mode_cmds(h); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9011 | /* Performant mode ring buffer and supporting data structures */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9012 | h->reply_queue_size = h->max_commands * sizeof(u64); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9013 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9014 | for (i = 0; i < h->nreply_queues; i++) { |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9015 | h->reply_queue[i].head = pci_alloc_consistent(h->pdev, |
| 9016 | h->reply_queue_size, |
| 9017 | &(h->reply_queue[i].busaddr)); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9018 | if (!h->reply_queue[i].head) { |
| 9019 | rc = -ENOMEM; |
| 9020 | goto clean1; /* rq, ioaccel */ |
| 9021 | } |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9022 | h->reply_queue[i].size = h->max_commands; |
| 9023 | h->reply_queue[i].wraparound = 1; /* spec: init to 1 */ |
| 9024 | h->reply_queue[i].current_entry = 0; |
| 9025 | } |
| 9026 | |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9027 | /* Need a block fetch table for performant mode */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 9028 | h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) * |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9029 | sizeof(u32)), GFP_KERNEL); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9030 | if (!h->blockFetchTable) { |
| 9031 | rc = -ENOMEM; |
| 9032 | goto clean1; /* rq, ioaccel */ |
| 9033 | } |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9034 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9035 | rc = hpsa_enter_performant_mode(h, trans_support); |
| 9036 | if (rc) |
| 9037 | goto clean2; /* bft, rq, ioaccel */ |
| 9038 | return 0; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9039 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9040 | clean2: /* bft, rq, ioaccel */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9041 | kfree(h->blockFetchTable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9042 | h->blockFetchTable = NULL; |
| 9043 | clean1: /* rq, ioaccel */ |
| 9044 | hpsa_free_reply_queues(h); |
| 9045 | hpsa_free_ioaccel1_cmd_and_bft(h); |
| 9046 | hpsa_free_ioaccel2_cmd_and_bft(h); |
| 9047 | return rc; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9048 | } |
| 9049 | |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9050 | static int is_accelerated_cmd(struct CommandList *c) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 9051 | { |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9052 | return c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_IOACCEL2; |
| 9053 | } |
| 9054 | |
| 9055 | static void hpsa_drain_accel_commands(struct ctlr_info *h) |
| 9056 | { |
| 9057 | struct CommandList *c = NULL; |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9058 | int i, accel_cmds_out; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 9059 | int refcount; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 9060 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9061 | do { /* wait for all outstanding ioaccel commands to drain out */ |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9062 | accel_cmds_out = 0; |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9063 | for (i = 0; i < h->nr_cmds; i++) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9064 | c = h->cmd_pool + i; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 9065 | refcount = atomic_inc_return(&c->refcount); |
| 9066 | if (refcount > 1) /* Command is allocated */ |
| 9067 | accel_cmds_out += is_accelerated_cmd(c); |
| 9068 | cmd_free(h, c); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9069 | } |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9070 | if (accel_cmds_out <= 0) |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 9071 | break; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 9072 | msleep(100); |
| 9073 | } while (1); |
| 9074 | } |
| 9075 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9076 | /* |
| 9077 | * This is it. Register the PCI driver information for the cards we control |
| 9078 | * the OS will call our registered routines when it finds one of our cards. |
| 9079 | */ |
| 9080 | static int __init hpsa_init(void) |
| 9081 | { |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 9082 | return pci_register_driver(&hpsa_pci_driver); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9083 | } |
| 9084 | |
| 9085 | static void __exit hpsa_cleanup(void) |
| 9086 | { |
| 9087 | pci_unregister_driver(&hpsa_pci_driver); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9088 | } |
| 9089 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9090 | static void __attribute__((unused)) verify_offsets(void) |
| 9091 | { |
| 9092 | #define VERIFY_OFFSET(member, offset) \ |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 9093 | BUILD_BUG_ON(offsetof(struct raid_map_data, member) != offset) |
| 9094 | |
| 9095 | VERIFY_OFFSET(structure_size, 0); |
| 9096 | VERIFY_OFFSET(volume_blk_size, 4); |
| 9097 | VERIFY_OFFSET(volume_blk_cnt, 8); |
| 9098 | VERIFY_OFFSET(phys_blk_shift, 16); |
| 9099 | VERIFY_OFFSET(parity_rotation_shift, 17); |
| 9100 | VERIFY_OFFSET(strip_size, 18); |
| 9101 | VERIFY_OFFSET(disk_starting_blk, 20); |
| 9102 | VERIFY_OFFSET(disk_blk_cnt, 28); |
| 9103 | VERIFY_OFFSET(data_disks_per_row, 36); |
| 9104 | VERIFY_OFFSET(metadata_disks_per_row, 38); |
| 9105 | VERIFY_OFFSET(row_cnt, 40); |
| 9106 | VERIFY_OFFSET(layout_map_count, 42); |
| 9107 | VERIFY_OFFSET(flags, 44); |
| 9108 | VERIFY_OFFSET(dekindex, 46); |
| 9109 | /* VERIFY_OFFSET(reserved, 48 */ |
| 9110 | VERIFY_OFFSET(data, 64); |
| 9111 | |
| 9112 | #undef VERIFY_OFFSET |
| 9113 | |
| 9114 | #define VERIFY_OFFSET(member, offset) \ |
Mike Miller | b66cc25 | 2014-02-18 13:56:04 -0600 | [diff] [blame] | 9115 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, member) != offset) |
| 9116 | |
| 9117 | VERIFY_OFFSET(IU_type, 0); |
| 9118 | VERIFY_OFFSET(direction, 1); |
| 9119 | VERIFY_OFFSET(reply_queue, 2); |
| 9120 | /* VERIFY_OFFSET(reserved1, 3); */ |
| 9121 | VERIFY_OFFSET(scsi_nexus, 4); |
| 9122 | VERIFY_OFFSET(Tag, 8); |
| 9123 | VERIFY_OFFSET(cdb, 16); |
| 9124 | VERIFY_OFFSET(cciss_lun, 32); |
| 9125 | VERIFY_OFFSET(data_len, 40); |
| 9126 | VERIFY_OFFSET(cmd_priority_task_attr, 44); |
| 9127 | VERIFY_OFFSET(sg_count, 45); |
| 9128 | /* VERIFY_OFFSET(reserved3 */ |
| 9129 | VERIFY_OFFSET(err_ptr, 48); |
| 9130 | VERIFY_OFFSET(err_len, 56); |
| 9131 | /* VERIFY_OFFSET(reserved4 */ |
| 9132 | VERIFY_OFFSET(sg, 64); |
| 9133 | |
| 9134 | #undef VERIFY_OFFSET |
| 9135 | |
| 9136 | #define VERIFY_OFFSET(member, offset) \ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9137 | BUILD_BUG_ON(offsetof(struct io_accel1_cmd, member) != offset) |
| 9138 | |
| 9139 | VERIFY_OFFSET(dev_handle, 0x00); |
| 9140 | VERIFY_OFFSET(reserved1, 0x02); |
| 9141 | VERIFY_OFFSET(function, 0x03); |
| 9142 | VERIFY_OFFSET(reserved2, 0x04); |
| 9143 | VERIFY_OFFSET(err_info, 0x0C); |
| 9144 | VERIFY_OFFSET(reserved3, 0x10); |
| 9145 | VERIFY_OFFSET(err_info_len, 0x12); |
| 9146 | VERIFY_OFFSET(reserved4, 0x13); |
| 9147 | VERIFY_OFFSET(sgl_offset, 0x14); |
| 9148 | VERIFY_OFFSET(reserved5, 0x15); |
| 9149 | VERIFY_OFFSET(transfer_len, 0x1C); |
| 9150 | VERIFY_OFFSET(reserved6, 0x20); |
| 9151 | VERIFY_OFFSET(io_flags, 0x24); |
| 9152 | VERIFY_OFFSET(reserved7, 0x26); |
| 9153 | VERIFY_OFFSET(LUN, 0x34); |
| 9154 | VERIFY_OFFSET(control, 0x3C); |
| 9155 | VERIFY_OFFSET(CDB, 0x40); |
| 9156 | VERIFY_OFFSET(reserved8, 0x50); |
| 9157 | VERIFY_OFFSET(host_context_flags, 0x60); |
| 9158 | VERIFY_OFFSET(timeout_sec, 0x62); |
| 9159 | VERIFY_OFFSET(ReplyQueue, 0x64); |
| 9160 | VERIFY_OFFSET(reserved9, 0x65); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 9161 | VERIFY_OFFSET(tag, 0x68); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9162 | VERIFY_OFFSET(host_addr, 0x70); |
| 9163 | VERIFY_OFFSET(CISS_LUN, 0x78); |
| 9164 | VERIFY_OFFSET(SG, 0x78 + 8); |
| 9165 | #undef VERIFY_OFFSET |
| 9166 | } |
| 9167 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9168 | module_init(hpsa_init); |
| 9169 | module_exit(hpsa_cleanup); |