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 | 94c7bc3 | 2016-02-23 15:16:46 -0600 | [diff] [blame] | 3 | * Copyright 2016 Microsemi Corporation |
Don Brace | 1358f6d | 2015-07-18 11:12:38 -0500 | [diff] [blame] | 4 | * Copyright 2014-2015 PMC-Sierra, Inc. |
| 5 | * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 14 | * NON INFRINGEMENT. See the GNU General Public License for more details. |
| 15 | * |
Don Brace | 94c7bc3 | 2016-02-23 15:16:46 -0600 | [diff] [blame] | 16 | * Questions/Comments/Bugfixes to esc.storagedev@microsemi.com |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/pci.h> |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 24 | #include <linux/pci-aspm.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/timer.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 30 | #include <linux/init.h> |
| 31 | #include <linux/spinlock.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 32 | #include <linux/compat.h> |
| 33 | #include <linux/blktrace_api.h> |
| 34 | #include <linux/uaccess.h> |
| 35 | #include <linux/io.h> |
| 36 | #include <linux/dma-mapping.h> |
| 37 | #include <linux/completion.h> |
| 38 | #include <linux/moduleparam.h> |
| 39 | #include <scsi/scsi.h> |
| 40 | #include <scsi/scsi_cmnd.h> |
| 41 | #include <scsi/scsi_device.h> |
| 42 | #include <scsi/scsi_host.h> |
Stephen M. Cameron | 667e23d | 2010-02-25 14:02:51 -0600 | [diff] [blame] | 43 | #include <scsi/scsi_tcq.h> |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 44 | #include <scsi/scsi_eh.h> |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 45 | #include <scsi/scsi_transport_sas.h> |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 46 | #include <scsi/scsi_dbg.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 47 | #include <linux/cciss_ioctl.h> |
| 48 | #include <linux/string.h> |
| 49 | #include <linux/bitmap.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 50 | #include <linux/atomic.h> |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 51 | #include <linux/jiffies.h> |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 52 | #include <linux/percpu-defs.h> |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 53 | #include <linux/percpu.h> |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 54 | #include <asm/unaligned.h> |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 55 | #include <asm/div64.h> |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 56 | #include "hpsa_cmd.h" |
| 57 | #include "hpsa.h" |
| 58 | |
Don Brace | ec2c3aa | 2015-11-04 15:52:40 -0600 | [diff] [blame] | 59 | /* |
| 60 | * HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' |
| 61 | * with an optional trailing '-' followed by a byte value (0-255). |
| 62 | */ |
Don Brace | ff54aee | 2016-04-27 17:14:26 -0500 | [diff] [blame] | 63 | #define HPSA_DRIVER_VERSION "3.4.16-0" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 64 | #define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 65 | #define HPSA "hpsa" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 66 | |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 67 | /* How long to wait for CISS doorbell communication */ |
| 68 | #define CLEAR_EVENT_WAIT_INTERVAL 20 /* ms for each msleep() call */ |
| 69 | #define MODE_CHANGE_WAIT_INTERVAL 10 /* ms for each msleep() call */ |
| 70 | #define MAX_CLEAR_EVENT_WAIT 30000 /* times 20 ms = 600 s */ |
| 71 | #define MAX_MODE_CHANGE_WAIT 2000 /* times 10 ms = 20 s */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 72 | #define MAX_IOCTL_CONFIG_WAIT 1000 |
| 73 | |
| 74 | /*define how many times we will try a command because of bus resets */ |
| 75 | #define MAX_CMD_RETRIES 3 |
| 76 | |
| 77 | /* Embedded module documentation macros - see modules.h */ |
| 78 | MODULE_AUTHOR("Hewlett-Packard Company"); |
| 79 | MODULE_DESCRIPTION("Driver for HP Smart Array Controller version " \ |
| 80 | HPSA_DRIVER_VERSION); |
| 81 | MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers"); |
| 82 | MODULE_VERSION(HPSA_DRIVER_VERSION); |
| 83 | MODULE_LICENSE("GPL"); |
| 84 | |
| 85 | static int hpsa_allow_any; |
| 86 | module_param(hpsa_allow_any, int, S_IRUGO|S_IWUSR); |
| 87 | MODULE_PARM_DESC(hpsa_allow_any, |
| 88 | "Allow hpsa driver to access unknown HP Smart Array hardware"); |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 89 | static int hpsa_simple_mode; |
| 90 | module_param(hpsa_simple_mode, int, S_IRUGO|S_IWUSR); |
| 91 | MODULE_PARM_DESC(hpsa_simple_mode, |
| 92 | "Use 'simple mode' rather than 'performant mode'"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 93 | |
| 94 | /* define the PCI info for the cards we can control */ |
| 95 | static const struct pci_device_id hpsa_pci_device_id[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 96 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3241}, |
| 97 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3243}, |
| 98 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3245}, |
| 99 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3247}, |
| 100 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 101 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A}, |
| 102 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B}, |
Mike Miller | f8b01eb | 2010-02-04 08:42:45 -0600 | [diff] [blame] | 103 | {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] | 104 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3350}, |
| 105 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3351}, |
| 106 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3352}, |
| 107 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3353}, |
| 108 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3354}, |
| 109 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3355}, |
| 110 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3356}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 111 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1921}, |
| 112 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1922}, |
| 113 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1923}, |
| 114 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1924}, |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 115 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1926}, |
| 116 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1928}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 117 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1929}, |
| 118 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BD}, |
| 119 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BE}, |
| 120 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21BF}, |
| 121 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C0}, |
| 122 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C1}, |
| 123 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C2}, |
| 124 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C3}, |
| 125 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C4}, |
| 126 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C5}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 127 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C6}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 128 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C7}, |
| 129 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C8}, |
| 130 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C9}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 131 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CA}, |
| 132 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CB}, |
| 133 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CC}, |
| 134 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CD}, |
| 135 | {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CE}, |
Don Brace | fdfa4b6 | 2015-04-23 09:35:27 -0500 | [diff] [blame] | 136 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0580}, |
Don Brace | cbb47dc | 2015-07-18 11:12:54 -0500 | [diff] [blame] | 137 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0581}, |
| 138 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0582}, |
| 139 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0583}, |
| 140 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0584}, |
| 141 | {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0585}, |
Stephen M. Cameron | 8e616a5 | 2014-02-18 13:58:02 -0600 | [diff] [blame] | 142 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0076}, |
| 143 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0087}, |
| 144 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x007D}, |
| 145 | {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0088}, |
| 146 | {PCI_VENDOR_ID_HP, 0x333f, 0x103c, 0x333f}, |
Mike Miller | 7c03b87 | 2010-12-01 11:16:07 -0600 | [diff] [blame] | 147 | {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] | 148 | PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 149 | {0,} |
| 150 | }; |
| 151 | |
| 152 | MODULE_DEVICE_TABLE(pci, hpsa_pci_device_id); |
| 153 | |
| 154 | /* board_id = Subsystem Device ID & Vendor ID |
| 155 | * product = Marketing Name for the board |
| 156 | * access = Address of the struct of function pointers |
| 157 | */ |
| 158 | static struct board_type products[] = { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 159 | {0x3241103C, "Smart Array P212", &SA5_access}, |
| 160 | {0x3243103C, "Smart Array P410", &SA5_access}, |
| 161 | {0x3245103C, "Smart Array P410i", &SA5_access}, |
| 162 | {0x3247103C, "Smart Array P411", &SA5_access}, |
| 163 | {0x3249103C, "Smart Array P812", &SA5_access}, |
Mike Miller | 163dbcd | 2013-09-04 15:11:10 -0500 | [diff] [blame] | 164 | {0x324A103C, "Smart Array P712m", &SA5_access}, |
| 165 | {0x324B103C, "Smart Array P711m", &SA5_access}, |
Stephen M. Cameron | 7d2cce5 | 2014-11-14 17:26:38 -0600 | [diff] [blame] | 166 | {0x3233103C, "HP StorageWorks 1210m", &SA5_access}, /* alias of 333f */ |
Mike Miller | fe0c961 | 2012-09-20 16:05:18 -0500 | [diff] [blame] | 167 | {0x3350103C, "Smart Array P222", &SA5_access}, |
| 168 | {0x3351103C, "Smart Array P420", &SA5_access}, |
| 169 | {0x3352103C, "Smart Array P421", &SA5_access}, |
| 170 | {0x3353103C, "Smart Array P822", &SA5_access}, |
| 171 | {0x3354103C, "Smart Array P420i", &SA5_access}, |
| 172 | {0x3355103C, "Smart Array P220i", &SA5_access}, |
| 173 | {0x3356103C, "Smart Array P721m", &SA5_access}, |
Mike Miller | 1fd6c8e | 2013-09-04 15:08:29 -0500 | [diff] [blame] | 174 | {0x1921103C, "Smart Array P830i", &SA5_access}, |
| 175 | {0x1922103C, "Smart Array P430", &SA5_access}, |
| 176 | {0x1923103C, "Smart Array P431", &SA5_access}, |
| 177 | {0x1924103C, "Smart Array P830", &SA5_access}, |
| 178 | {0x1926103C, "Smart Array P731m", &SA5_access}, |
| 179 | {0x1928103C, "Smart Array P230i", &SA5_access}, |
| 180 | {0x1929103C, "Smart Array P530", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 181 | {0x21BD103C, "Smart Array P244br", &SA5_access}, |
| 182 | {0x21BE103C, "Smart Array P741m", &SA5_access}, |
| 183 | {0x21BF103C, "Smart HBA H240ar", &SA5_access}, |
| 184 | {0x21C0103C, "Smart Array P440ar", &SA5_access}, |
Don Brace | c8ae0ab | 2015-01-23 16:45:12 -0600 | [diff] [blame] | 185 | {0x21C1103C, "Smart Array P840ar", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 186 | {0x21C2103C, "Smart Array P440", &SA5_access}, |
| 187 | {0x21C3103C, "Smart Array P441", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 188 | {0x21C4103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 189 | {0x21C5103C, "Smart Array P841", &SA5_access}, |
| 190 | {0x21C6103C, "Smart HBA H244br", &SA5_access}, |
| 191 | {0x21C7103C, "Smart HBA H240", &SA5_access}, |
| 192 | {0x21C8103C, "Smart HBA H241", &SA5_access}, |
Mike Miller | 97b9f53 | 2013-09-04 15:05:55 -0500 | [diff] [blame] | 193 | {0x21C9103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 194 | {0x21CA103C, "Smart Array P246br", &SA5_access}, |
| 195 | {0x21CB103C, "Smart Array P840", &SA5_access}, |
Joe Handzik | 3b7a45e | 2014-05-08 14:27:24 -0500 | [diff] [blame] | 196 | {0x21CC103C, "Smart Array", &SA5_access}, |
| 197 | {0x21CD103C, "Smart Array", &SA5_access}, |
Don Brace | 27fb813 | 2015-01-23 16:45:07 -0600 | [diff] [blame] | 198 | {0x21CE103C, "Smart HBA", &SA5_access}, |
Don Brace | fdfa4b6 | 2015-04-23 09:35:27 -0500 | [diff] [blame] | 199 | {0x05809005, "SmartHBA-SA", &SA5_access}, |
Don Brace | cbb47dc | 2015-07-18 11:12:54 -0500 | [diff] [blame] | 200 | {0x05819005, "SmartHBA-SA 8i", &SA5_access}, |
| 201 | {0x05829005, "SmartHBA-SA 8i8e", &SA5_access}, |
| 202 | {0x05839005, "SmartHBA-SA 8e", &SA5_access}, |
| 203 | {0x05849005, "SmartHBA-SA 16i", &SA5_access}, |
| 204 | {0x05859005, "SmartHBA-SA 4i4e", &SA5_access}, |
Stephen M. Cameron | 8e616a5 | 2014-02-18 13:58:02 -0600 | [diff] [blame] | 205 | {0x00761590, "HP Storage P1224 Array Controller", &SA5_access}, |
| 206 | {0x00871590, "HP Storage P1224e Array Controller", &SA5_access}, |
| 207 | {0x007D1590, "HP Storage P1228 Array Controller", &SA5_access}, |
| 208 | {0x00881590, "HP Storage P1228e Array Controller", &SA5_access}, |
| 209 | {0x333f103c, "HP StorageWorks 1210m Array Controller", &SA5_access}, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 210 | {0xFFFF103C, "Unknown Smart Array", &SA5_access}, |
| 211 | }; |
| 212 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 213 | static struct scsi_transport_template *hpsa_sas_transport_template; |
| 214 | static int hpsa_add_sas_host(struct ctlr_info *h); |
| 215 | static void hpsa_delete_sas_host(struct ctlr_info *h); |
| 216 | static int hpsa_add_sas_device(struct hpsa_sas_node *hpsa_sas_node, |
| 217 | struct hpsa_scsi_dev_t *device); |
| 218 | static void hpsa_remove_sas_device(struct hpsa_scsi_dev_t *device); |
| 219 | static struct hpsa_scsi_dev_t |
| 220 | *hpsa_find_device_by_sas_rphy(struct ctlr_info *h, |
| 221 | struct sas_rphy *rphy); |
| 222 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 223 | #define SCSI_CMD_BUSY ((struct scsi_cmnd *)&hpsa_cmd_busy) |
| 224 | static const struct scsi_cmnd hpsa_cmd_busy; |
| 225 | #define SCSI_CMD_IDLE ((struct scsi_cmnd *)&hpsa_cmd_idle) |
| 226 | static const struct scsi_cmnd hpsa_cmd_idle; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 227 | static int number_of_controllers; |
| 228 | |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 229 | static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); |
| 230 | static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 231 | 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] | 232 | |
| 233 | #ifdef CONFIG_COMPAT |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 234 | static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, |
| 235 | void __user *arg); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 236 | #endif |
| 237 | |
| 238 | static void cmd_free(struct ctlr_info *h, struct CommandList *c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 239 | static struct CommandList *cmd_alloc(struct ctlr_info *h); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 240 | static void cmd_tagged_free(struct ctlr_info *h, struct CommandList *c); |
| 241 | static struct CommandList *cmd_tagged_alloc(struct ctlr_info *h, |
| 242 | struct scsi_cmnd *scmd); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 243 | 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] | 244 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 245 | int cmd_type); |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 246 | static void hpsa_free_cmd_pool(struct ctlr_info *h); |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 247 | #define VPD_PAGE (1 << 8) |
Don Brace | b48d980 | 2015-11-04 15:50:13 -0600 | [diff] [blame] | 248 | #define HPSA_SIMPLE_ERROR_BITS 0x03 |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 249 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 250 | 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] | 251 | static void hpsa_scan_start(struct Scsi_Host *); |
| 252 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 253 | unsigned long elapsed_time); |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 254 | 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] | 255 | |
| 256 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 257 | static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 258 | static int hpsa_slave_alloc(struct scsi_device *sdev); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 259 | static int hpsa_slave_configure(struct scsi_device *sdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 260 | static void hpsa_slave_destroy(struct scsi_device *sdev); |
| 261 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 262 | static void hpsa_update_scsi_devices(struct ctlr_info *h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 263 | static int check_for_unit_attention(struct ctlr_info *h, |
| 264 | struct CommandList *c); |
| 265 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 266 | struct CommandList *c); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 267 | /* performant mode helper functions */ |
| 268 | static void calc_bucket_map(int *bucket, int num_buckets, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 269 | int nsgs, int min_blocks, u32 *bucket_map); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 270 | static void hpsa_free_performant_mode(struct ctlr_info *h); |
| 271 | static int hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 272 | static inline u32 next_command(struct ctlr_info *h, u8 q); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 273 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 274 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 275 | u64 *cfg_offset); |
| 276 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 277 | unsigned long *memory_bar); |
| 278 | static int hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id); |
Don Brace | bfd7546 | 2016-11-15 14:45:32 -0600 | [diff] [blame] | 279 | static int wait_for_device_to_become_ready(struct ctlr_info *h, |
| 280 | unsigned char lunaddr[], |
| 281 | int reply_queue); |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 282 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 283 | int wait_for_ready); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 284 | static inline void finish_cmd(struct CommandList *c); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 285 | 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] | 286 | #define BOARD_NOT_READY 0 |
| 287 | #define BOARD_READY 1 |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 288 | static void hpsa_drain_accel_commands(struct ctlr_info *h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 289 | static void hpsa_flush_cache(struct ctlr_info *h); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 290 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 291 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 292 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 293 | static void hpsa_command_resubmit_worker(struct work_struct *work); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 294 | static u32 lockup_detected(struct ctlr_info *h); |
| 295 | static int detect_controller_lockup(struct ctlr_info *h); |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 296 | static void hpsa_disable_rld_caching(struct ctlr_info *h); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 297 | static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info *h, |
| 298 | struct ReportExtendedLUNdata *buf, int bufsize); |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 299 | static bool hpsa_vpd_page_supported(struct ctlr_info *h, |
| 300 | unsigned char scsi3addr[], u8 page); |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 301 | static int hpsa_luns_changed(struct ctlr_info *h); |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 302 | static bool hpsa_cmd_dev_match(struct ctlr_info *h, struct CommandList *c, |
| 303 | struct hpsa_scsi_dev_t *dev, |
| 304 | unsigned char *scsi3addr); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 305 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 306 | static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev) |
| 307 | { |
| 308 | unsigned long *priv = shost_priv(sdev->host); |
| 309 | return (struct ctlr_info *) *priv; |
| 310 | } |
| 311 | |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 312 | static inline struct ctlr_info *shost_to_hba(struct Scsi_Host *sh) |
| 313 | { |
| 314 | unsigned long *priv = shost_priv(sh); |
| 315 | return (struct ctlr_info *) *priv; |
| 316 | } |
| 317 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 318 | static inline bool hpsa_is_cmd_idle(struct CommandList *c) |
| 319 | { |
| 320 | return c->scsi_cmd == SCSI_CMD_IDLE; |
| 321 | } |
| 322 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 323 | static inline bool hpsa_is_pending_event(struct CommandList *c) |
| 324 | { |
| 325 | return c->abort_pending || c->reset_pending; |
| 326 | } |
| 327 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 328 | /* extract sense key, asc, and ascq from sense data. -1 means invalid. */ |
| 329 | static void decode_sense_data(const u8 *sense_data, int sense_data_len, |
| 330 | u8 *sense_key, u8 *asc, u8 *ascq) |
| 331 | { |
| 332 | struct scsi_sense_hdr sshdr; |
| 333 | bool rc; |
| 334 | |
| 335 | *sense_key = -1; |
| 336 | *asc = -1; |
| 337 | *ascq = -1; |
| 338 | |
| 339 | if (sense_data_len < 1) |
| 340 | return; |
| 341 | |
| 342 | rc = scsi_normalize_sense(sense_data, sense_data_len, &sshdr); |
| 343 | if (rc) { |
| 344 | *sense_key = sshdr.sense_key; |
| 345 | *asc = sshdr.asc; |
| 346 | *ascq = sshdr.ascq; |
| 347 | } |
| 348 | } |
| 349 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 350 | static int check_for_unit_attention(struct ctlr_info *h, |
| 351 | struct CommandList *c) |
| 352 | { |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 353 | u8 sense_key, asc, ascq; |
| 354 | int sense_len; |
| 355 | |
| 356 | if (c->err_info->SenseLen > sizeof(c->err_info->SenseInfo)) |
| 357 | sense_len = sizeof(c->err_info->SenseInfo); |
| 358 | else |
| 359 | sense_len = c->err_info->SenseLen; |
| 360 | |
| 361 | decode_sense_data(c->err_info->SenseInfo, sense_len, |
| 362 | &sense_key, &asc, &ascq); |
Don Brace | 81c2755 | 2015-07-18 11:12:28 -0500 | [diff] [blame] | 363 | if (sense_key != UNIT_ATTENTION || asc == 0xff) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 364 | return 0; |
| 365 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 366 | switch (asc) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 367 | case STATE_CHANGED: |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 368 | dev_warn(&h->pdev->dev, |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 369 | "%s: a state change detected, command retried\n", |
| 370 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 371 | break; |
| 372 | case LUN_FAILED: |
Stephen M. Cameron | 7f73695 | 2014-11-14 17:26:48 -0600 | [diff] [blame] | 373 | dev_warn(&h->pdev->dev, |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 374 | "%s: LUN failure detected\n", h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 375 | break; |
| 376 | case REPORT_LUNS_CHANGED: |
Stephen M. Cameron | 7f73695 | 2014-11-14 17:26:48 -0600 | [diff] [blame] | 377 | dev_warn(&h->pdev->dev, |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 378 | "%s: report LUN data changed\n", h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 379 | /* |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 380 | * Note: this REPORT_LUNS_CHANGED condition only occurs on the external |
| 381 | * target (array) devices. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 382 | */ |
| 383 | break; |
| 384 | case POWER_OR_RESET: |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 385 | dev_warn(&h->pdev->dev, |
| 386 | "%s: a power on or device reset detected\n", |
| 387 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 388 | break; |
| 389 | case UNIT_ATTENTION_CLEARED: |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 390 | dev_warn(&h->pdev->dev, |
| 391 | "%s: unit attention cleared by another initiator\n", |
| 392 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 393 | break; |
| 394 | default: |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 395 | dev_warn(&h->pdev->dev, |
| 396 | "%s: unknown unit attention detected\n", |
| 397 | h->devname); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 398 | break; |
| 399 | } |
| 400 | return 1; |
| 401 | } |
| 402 | |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 403 | static int check_for_busy(struct ctlr_info *h, struct CommandList *c) |
| 404 | { |
| 405 | if (c->err_info->CommandStatus != CMD_TARGET_STATUS || |
| 406 | (c->err_info->ScsiStatus != SAM_STAT_BUSY && |
| 407 | c->err_info->ScsiStatus != SAM_STAT_TASK_SET_FULL)) |
| 408 | return 0; |
| 409 | dev_warn(&h->pdev->dev, HPSA "device busy"); |
| 410 | return 1; |
| 411 | } |
| 412 | |
Stephen Cameron | e985c58 | 2015-04-23 09:32:22 -0500 | [diff] [blame] | 413 | static u32 lockup_detected(struct ctlr_info *h); |
| 414 | static ssize_t host_show_lockup_detected(struct device *dev, |
| 415 | struct device_attribute *attr, char *buf) |
| 416 | { |
| 417 | int ld; |
| 418 | struct ctlr_info *h; |
| 419 | struct Scsi_Host *shost = class_to_shost(dev); |
| 420 | |
| 421 | h = shost_to_hba(shost); |
| 422 | ld = lockup_detected(h); |
| 423 | |
| 424 | return sprintf(buf, "ld=%d\n", ld); |
| 425 | } |
| 426 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 427 | static ssize_t host_store_hp_ssd_smart_path_status(struct device *dev, |
| 428 | struct device_attribute *attr, |
| 429 | const char *buf, size_t count) |
| 430 | { |
| 431 | int status, len; |
| 432 | struct ctlr_info *h; |
| 433 | struct Scsi_Host *shost = class_to_shost(dev); |
| 434 | char tmpbuf[10]; |
| 435 | |
| 436 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 437 | return -EACCES; |
| 438 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 439 | strncpy(tmpbuf, buf, len); |
| 440 | tmpbuf[len] = '\0'; |
| 441 | if (sscanf(tmpbuf, "%d", &status) != 1) |
| 442 | return -EINVAL; |
| 443 | h = shost_to_hba(shost); |
| 444 | h->acciopath_status = !!status; |
| 445 | dev_warn(&h->pdev->dev, |
| 446 | "hpsa: HP SSD Smart Path %s via sysfs update.\n", |
| 447 | h->acciopath_status ? "enabled" : "disabled"); |
| 448 | return count; |
| 449 | } |
| 450 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 451 | static ssize_t host_store_raid_offload_debug(struct device *dev, |
| 452 | struct device_attribute *attr, |
| 453 | const char *buf, size_t count) |
| 454 | { |
| 455 | int debug_level, len; |
| 456 | struct ctlr_info *h; |
| 457 | struct Scsi_Host *shost = class_to_shost(dev); |
| 458 | char tmpbuf[10]; |
| 459 | |
| 460 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 461 | return -EACCES; |
| 462 | len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; |
| 463 | strncpy(tmpbuf, buf, len); |
| 464 | tmpbuf[len] = '\0'; |
| 465 | if (sscanf(tmpbuf, "%d", &debug_level) != 1) |
| 466 | return -EINVAL; |
| 467 | if (debug_level < 0) |
| 468 | debug_level = 0; |
| 469 | h = shost_to_hba(shost); |
| 470 | h->raid_offload_debug = debug_level; |
| 471 | dev_warn(&h->pdev->dev, "hpsa: Set raid_offload_debug level = %d\n", |
| 472 | h->raid_offload_debug); |
| 473 | return count; |
| 474 | } |
| 475 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 476 | static ssize_t host_store_rescan(struct device *dev, |
| 477 | struct device_attribute *attr, |
| 478 | const char *buf, size_t count) |
| 479 | { |
| 480 | struct ctlr_info *h; |
| 481 | struct Scsi_Host *shost = class_to_shost(dev); |
Stephen M. Cameron | a23513e | 2010-02-04 08:43:11 -0600 | [diff] [blame] | 482 | h = shost_to_hba(shost); |
Mike Miller | 3146840 | 2010-02-25 14:03:12 -0600 | [diff] [blame] | 483 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 484 | return count; |
| 485 | } |
| 486 | |
Stephen M. Cameron | d28ce02 | 2010-05-27 15:14:34 -0500 | [diff] [blame] | 487 | static ssize_t host_show_firmware_revision(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 | unsigned char *fwrev; |
| 493 | |
| 494 | h = shost_to_hba(shost); |
| 495 | if (!h->hba_inquiry_data) |
| 496 | return 0; |
| 497 | fwrev = &h->hba_inquiry_data[32]; |
| 498 | return snprintf(buf, 20, "%c%c%c%c\n", |
| 499 | fwrev[0], fwrev[1], fwrev[2], fwrev[3]); |
| 500 | } |
| 501 | |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 502 | static ssize_t host_show_commands_outstanding(struct device *dev, |
| 503 | struct device_attribute *attr, char *buf) |
| 504 | { |
| 505 | struct Scsi_Host *shost = class_to_shost(dev); |
| 506 | struct ctlr_info *h = shost_to_hba(shost); |
| 507 | |
Stephen M. Cameron | 0cbf768 | 2014-11-14 17:27:09 -0600 | [diff] [blame] | 508 | return snprintf(buf, 20, "%d\n", |
| 509 | atomic_read(&h->commands_outstanding)); |
Stephen M. Cameron | 94a1364 | 2011-01-06 14:48:39 -0600 | [diff] [blame] | 510 | } |
| 511 | |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 512 | static ssize_t host_show_transport_mode(struct device *dev, |
| 513 | struct device_attribute *attr, char *buf) |
| 514 | { |
| 515 | struct ctlr_info *h; |
| 516 | struct Scsi_Host *shost = class_to_shost(dev); |
| 517 | |
| 518 | h = shost_to_hba(shost); |
| 519 | return snprintf(buf, 20, "%s\n", |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 520 | h->transMethod & CFGTBL_Trans_Performant ? |
Stephen M. Cameron | 745a7a2 | 2011-02-15 15:32:58 -0600 | [diff] [blame] | 521 | "performant" : "simple"); |
| 522 | } |
| 523 | |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 524 | static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev, |
| 525 | struct device_attribute *attr, char *buf) |
| 526 | { |
| 527 | struct ctlr_info *h; |
| 528 | struct Scsi_Host *shost = class_to_shost(dev); |
| 529 | |
| 530 | h = shost_to_hba(shost); |
| 531 | return snprintf(buf, 30, "HP SSD Smart Path %s\n", |
| 532 | (h->acciopath_status == 1) ? "enabled" : "disabled"); |
| 533 | } |
| 534 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 535 | /* 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] | 536 | static u32 unresettable_controller[] = { |
| 537 | 0x324a103C, /* Smart Array P712m */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 538 | 0x324b103C, /* Smart Array P711m */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 539 | 0x3223103C, /* Smart Array P800 */ |
| 540 | 0x3234103C, /* Smart Array P400 */ |
| 541 | 0x3235103C, /* Smart Array P400i */ |
| 542 | 0x3211103C, /* Smart Array E200i */ |
| 543 | 0x3212103C, /* Smart Array E200 */ |
| 544 | 0x3213103C, /* Smart Array E200i */ |
| 545 | 0x3214103C, /* Smart Array E200i */ |
| 546 | 0x3215103C, /* Smart Array E200i */ |
| 547 | 0x3237103C, /* Smart Array E500 */ |
| 548 | 0x323D103C, /* Smart Array P700m */ |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 549 | 0x40800E11, /* Smart Array 5i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 550 | 0x409C0E11, /* Smart Array 6400 */ |
| 551 | 0x409D0E11, /* Smart Array 6400 EM */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 552 | 0x40700E11, /* Smart Array 5300 */ |
| 553 | 0x40820E11, /* Smart Array 532 */ |
| 554 | 0x40830E11, /* Smart Array 5312 */ |
| 555 | 0x409A0E11, /* Smart Array 641 */ |
| 556 | 0x409B0E11, /* Smart Array 642 */ |
| 557 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 558 | }; |
| 559 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 560 | /* List of controllers which cannot even be soft reset */ |
| 561 | static u32 soft_unresettable_controller[] = { |
Tomas Henzl | 7af0abb | 2011-11-28 15:39:55 +0100 | [diff] [blame] | 562 | 0x40800E11, /* Smart Array 5i */ |
Tomas Henzl | 5a4f934 | 2012-02-14 18:07:59 +0100 | [diff] [blame] | 563 | 0x40700E11, /* Smart Array 5300 */ |
| 564 | 0x40820E11, /* Smart Array 532 */ |
| 565 | 0x40830E11, /* Smart Array 5312 */ |
| 566 | 0x409A0E11, /* Smart Array 641 */ |
| 567 | 0x409B0E11, /* Smart Array 642 */ |
| 568 | 0x40910E11, /* Smart Array 6i */ |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 569 | /* Exclude 640x boards. These are two pci devices in one slot |
| 570 | * which share a battery backed cache module. One controls the |
| 571 | * cache, the other accesses the cache through the one that controls |
| 572 | * it. If we reset the one controlling the cache, the other will |
| 573 | * likely not be happy. Just forbid resetting this conjoined mess. |
| 574 | * The 640x isn't really supported by hpsa anyway. |
| 575 | */ |
| 576 | 0x409C0E11, /* Smart Array 6400 */ |
| 577 | 0x409D0E11, /* Smart Array 6400 EM */ |
| 578 | }; |
| 579 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 580 | static u32 needs_abort_tags_swizzled[] = { |
| 581 | 0x323D103C, /* Smart Array P700m */ |
| 582 | 0x324a103C, /* Smart Array P712m */ |
| 583 | 0x324b103C, /* SmartArray P711m */ |
| 584 | }; |
| 585 | |
| 586 | 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] | 587 | { |
| 588 | int i; |
| 589 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 590 | for (i = 0; i < nelems; i++) |
| 591 | if (a[i] == board_id) |
| 592 | return 1; |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static int ctlr_is_hard_resettable(u32 board_id) |
| 597 | { |
| 598 | return !board_id_in_array(unresettable_controller, |
| 599 | ARRAY_SIZE(unresettable_controller), board_id); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 600 | } |
| 601 | |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 602 | static int ctlr_is_soft_resettable(u32 board_id) |
| 603 | { |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 604 | return !board_id_in_array(soft_unresettable_controller, |
| 605 | ARRAY_SIZE(soft_unresettable_controller), board_id); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static int ctlr_is_resettable(u32 board_id) |
| 609 | { |
| 610 | return ctlr_is_hard_resettable(board_id) || |
| 611 | ctlr_is_soft_resettable(board_id); |
| 612 | } |
| 613 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 614 | static int ctlr_needs_abort_tags_swizzled(u32 board_id) |
| 615 | { |
| 616 | return board_id_in_array(needs_abort_tags_swizzled, |
| 617 | ARRAY_SIZE(needs_abort_tags_swizzled), board_id); |
| 618 | } |
| 619 | |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 620 | static ssize_t host_show_resettable(struct device *dev, |
| 621 | struct device_attribute *attr, char *buf) |
| 622 | { |
| 623 | struct ctlr_info *h; |
| 624 | struct Scsi_Host *shost = class_to_shost(dev); |
| 625 | |
| 626 | h = shost_to_hba(shost); |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 627 | 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] | 628 | } |
| 629 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 630 | static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[]) |
| 631 | { |
| 632 | return (scsi3addr[3] & 0xC0) == 0x40; |
| 633 | } |
| 634 | |
Robert Elliott | f2ef0ce | 2015-01-23 16:41:35 -0600 | [diff] [blame] | 635 | 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] | 636 | "1(+0)ADM", "UNKNOWN", "PHYS DRV" |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 637 | }; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 638 | #define HPSA_RAID_0 0 |
| 639 | #define HPSA_RAID_4 1 |
| 640 | #define HPSA_RAID_1 2 /* also used for RAID 10 */ |
| 641 | #define HPSA_RAID_5 3 /* also used for RAID 50 */ |
| 642 | #define HPSA_RAID_51 4 |
| 643 | #define HPSA_RAID_6 5 /* also used for RAID 60 */ |
| 644 | #define HPSA_RAID_ADM 6 /* also used for RAID 1+0 ADM */ |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 645 | #define RAID_UNKNOWN (ARRAY_SIZE(raid_label) - 2) |
| 646 | #define PHYSICAL_DRIVE (ARRAY_SIZE(raid_label) - 1) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 647 | |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 648 | static inline bool is_logical_device(struct hpsa_scsi_dev_t *device) |
| 649 | { |
| 650 | return !device->physical_device; |
| 651 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 652 | |
| 653 | static ssize_t raid_level_show(struct device *dev, |
| 654 | struct device_attribute *attr, char *buf) |
| 655 | { |
| 656 | ssize_t l = 0; |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 657 | unsigned char rlevel; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 658 | struct ctlr_info *h; |
| 659 | struct scsi_device *sdev; |
| 660 | struct hpsa_scsi_dev_t *hdev; |
| 661 | unsigned long flags; |
| 662 | |
| 663 | sdev = to_scsi_device(dev); |
| 664 | h = sdev_to_hba(sdev); |
| 665 | spin_lock_irqsave(&h->lock, flags); |
| 666 | hdev = sdev->hostdata; |
| 667 | if (!hdev) { |
| 668 | spin_unlock_irqrestore(&h->lock, flags); |
| 669 | return -ENODEV; |
| 670 | } |
| 671 | |
| 672 | /* Is this even a logical drive? */ |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 673 | if (!is_logical_device(hdev)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 674 | spin_unlock_irqrestore(&h->lock, flags); |
| 675 | l = snprintf(buf, PAGE_SIZE, "N/A\n"); |
| 676 | return l; |
| 677 | } |
| 678 | |
| 679 | rlevel = hdev->raid_level; |
| 680 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | 82a72c0 | 2010-02-04 08:41:38 -0600 | [diff] [blame] | 681 | if (rlevel > RAID_UNKNOWN) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 682 | rlevel = RAID_UNKNOWN; |
| 683 | l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]); |
| 684 | return l; |
| 685 | } |
| 686 | |
| 687 | static ssize_t lunid_show(struct device *dev, |
| 688 | struct device_attribute *attr, char *buf) |
| 689 | { |
| 690 | struct ctlr_info *h; |
| 691 | struct scsi_device *sdev; |
| 692 | struct hpsa_scsi_dev_t *hdev; |
| 693 | unsigned long flags; |
| 694 | unsigned char lunid[8]; |
| 695 | |
| 696 | sdev = to_scsi_device(dev); |
| 697 | h = sdev_to_hba(sdev); |
| 698 | spin_lock_irqsave(&h->lock, flags); |
| 699 | hdev = sdev->hostdata; |
| 700 | if (!hdev) { |
| 701 | spin_unlock_irqrestore(&h->lock, flags); |
| 702 | return -ENODEV; |
| 703 | } |
| 704 | memcpy(lunid, hdev->scsi3addr, sizeof(lunid)); |
| 705 | spin_unlock_irqrestore(&h->lock, flags); |
| 706 | return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 707 | lunid[0], lunid[1], lunid[2], lunid[3], |
| 708 | lunid[4], lunid[5], lunid[6], lunid[7]); |
| 709 | } |
| 710 | |
| 711 | static ssize_t unique_id_show(struct device *dev, |
| 712 | struct device_attribute *attr, char *buf) |
| 713 | { |
| 714 | struct ctlr_info *h; |
| 715 | struct scsi_device *sdev; |
| 716 | struct hpsa_scsi_dev_t *hdev; |
| 717 | unsigned long flags; |
| 718 | unsigned char sn[16]; |
| 719 | |
| 720 | sdev = to_scsi_device(dev); |
| 721 | h = sdev_to_hba(sdev); |
| 722 | spin_lock_irqsave(&h->lock, flags); |
| 723 | hdev = sdev->hostdata; |
| 724 | if (!hdev) { |
| 725 | spin_unlock_irqrestore(&h->lock, flags); |
| 726 | return -ENODEV; |
| 727 | } |
| 728 | memcpy(sn, hdev->device_id, sizeof(sn)); |
| 729 | spin_unlock_irqrestore(&h->lock, flags); |
| 730 | return snprintf(buf, 16 * 2 + 2, |
| 731 | "%02X%02X%02X%02X%02X%02X%02X%02X" |
| 732 | "%02X%02X%02X%02X%02X%02X%02X%02X\n", |
| 733 | sn[0], sn[1], sn[2], sn[3], |
| 734 | sn[4], sn[5], sn[6], sn[7], |
| 735 | sn[8], sn[9], sn[10], sn[11], |
| 736 | sn[12], sn[13], sn[14], sn[15]); |
| 737 | } |
| 738 | |
Joseph T Handzik | ded1be4 | 2016-04-27 17:13:33 -0500 | [diff] [blame] | 739 | static ssize_t sas_address_show(struct device *dev, |
| 740 | struct device_attribute *attr, char *buf) |
| 741 | { |
| 742 | struct ctlr_info *h; |
| 743 | struct scsi_device *sdev; |
| 744 | struct hpsa_scsi_dev_t *hdev; |
| 745 | unsigned long flags; |
| 746 | u64 sas_address; |
| 747 | |
| 748 | sdev = to_scsi_device(dev); |
| 749 | h = sdev_to_hba(sdev); |
| 750 | spin_lock_irqsave(&h->lock, flags); |
| 751 | hdev = sdev->hostdata; |
| 752 | if (!hdev || is_logical_device(hdev) || !hdev->expose_device) { |
| 753 | spin_unlock_irqrestore(&h->lock, flags); |
| 754 | return -ENODEV; |
| 755 | } |
| 756 | sas_address = hdev->sas_address; |
| 757 | spin_unlock_irqrestore(&h->lock, flags); |
| 758 | |
| 759 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", sas_address); |
| 760 | } |
| 761 | |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 762 | static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev, |
| 763 | struct device_attribute *attr, char *buf) |
| 764 | { |
| 765 | struct ctlr_info *h; |
| 766 | struct scsi_device *sdev; |
| 767 | struct hpsa_scsi_dev_t *hdev; |
| 768 | unsigned long flags; |
| 769 | int offload_enabled; |
| 770 | |
| 771 | sdev = to_scsi_device(dev); |
| 772 | h = sdev_to_hba(sdev); |
| 773 | spin_lock_irqsave(&h->lock, flags); |
| 774 | hdev = sdev->hostdata; |
| 775 | if (!hdev) { |
| 776 | spin_unlock_irqrestore(&h->lock, flags); |
| 777 | return -ENODEV; |
| 778 | } |
| 779 | offload_enabled = hdev->offload_enabled; |
| 780 | spin_unlock_irqrestore(&h->lock, flags); |
| 781 | return snprintf(buf, 20, "%d\n", offload_enabled); |
| 782 | } |
| 783 | |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 784 | #define MAX_PATHS 8 |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 785 | static ssize_t path_info_show(struct device *dev, |
| 786 | struct device_attribute *attr, char *buf) |
| 787 | { |
| 788 | struct ctlr_info *h; |
| 789 | struct scsi_device *sdev; |
| 790 | struct hpsa_scsi_dev_t *hdev; |
| 791 | unsigned long flags; |
| 792 | int i; |
| 793 | int output_len = 0; |
| 794 | u8 box; |
| 795 | u8 bay; |
| 796 | u8 path_map_index = 0; |
| 797 | char *active; |
| 798 | unsigned char phys_connector[2]; |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 799 | |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 800 | sdev = to_scsi_device(dev); |
| 801 | h = sdev_to_hba(sdev); |
| 802 | spin_lock_irqsave(&h->devlock, flags); |
| 803 | hdev = sdev->hostdata; |
| 804 | if (!hdev) { |
| 805 | spin_unlock_irqrestore(&h->devlock, flags); |
| 806 | return -ENODEV; |
| 807 | } |
| 808 | |
| 809 | bay = hdev->bay; |
| 810 | for (i = 0; i < MAX_PATHS; i++) { |
| 811 | path_map_index = 1<<i; |
| 812 | if (i == hdev->active_path_index) |
| 813 | active = "Active"; |
| 814 | else if (hdev->path_map & path_map_index) |
| 815 | active = "Inactive"; |
| 816 | else |
| 817 | continue; |
| 818 | |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 819 | output_len += scnprintf(buf + output_len, |
| 820 | PAGE_SIZE - output_len, |
| 821 | "[%d:%d:%d:%d] %20.20s ", |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 822 | h->scsi_host->host_no, |
| 823 | hdev->bus, hdev->target, hdev->lun, |
| 824 | scsi_device_type(hdev->devtype)); |
| 825 | |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 826 | if (hdev->devtype == TYPE_RAID || is_logical_device(hdev)) { |
Don Brace | 2708f29 | 2015-12-22 10:36:36 -0600 | [diff] [blame] | 827 | output_len += scnprintf(buf + output_len, |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 828 | PAGE_SIZE - output_len, |
| 829 | "%s\n", active); |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 830 | continue; |
| 831 | } |
| 832 | |
| 833 | box = hdev->box[i]; |
| 834 | memcpy(&phys_connector, &hdev->phys_connector[i], |
| 835 | sizeof(phys_connector)); |
| 836 | if (phys_connector[0] < '0') |
| 837 | phys_connector[0] = '0'; |
| 838 | if (phys_connector[1] < '0') |
| 839 | phys_connector[1] = '0'; |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 840 | output_len += scnprintf(buf + output_len, |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 841 | PAGE_SIZE - output_len, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 842 | "PORT: %.2s ", |
| 843 | phys_connector); |
Don Brace | af15ed3 | 2016-02-23 15:16:15 -0600 | [diff] [blame] | 844 | if ((hdev->devtype == TYPE_DISK || hdev->devtype == TYPE_ZBC) && |
| 845 | hdev->expose_device) { |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 846 | if (box == 0 || box == 0xFF) { |
Don Brace | 2708f29 | 2015-12-22 10:36:36 -0600 | [diff] [blame] | 847 | output_len += scnprintf(buf + output_len, |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 848 | PAGE_SIZE - output_len, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 849 | "BAY: %hhu %s\n", |
| 850 | bay, active); |
| 851 | } else { |
Don Brace | 2708f29 | 2015-12-22 10:36:36 -0600 | [diff] [blame] | 852 | output_len += scnprintf(buf + output_len, |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 853 | PAGE_SIZE - output_len, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 854 | "BOX: %hhu BAY: %hhu %s\n", |
| 855 | box, bay, active); |
| 856 | } |
| 857 | } else if (box != 0 && box != 0xFF) { |
Don Brace | 2708f29 | 2015-12-22 10:36:36 -0600 | [diff] [blame] | 858 | output_len += scnprintf(buf + output_len, |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 859 | PAGE_SIZE - output_len, "BOX: %hhu %s\n", |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 860 | box, active); |
| 861 | } else |
Don Brace | 2708f29 | 2015-12-22 10:36:36 -0600 | [diff] [blame] | 862 | output_len += scnprintf(buf + output_len, |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 863 | PAGE_SIZE - output_len, "%s\n", active); |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | spin_unlock_irqrestore(&h->devlock, flags); |
Rasmus Villemoes | 1faf072 | 2015-11-04 15:52:28 -0600 | [diff] [blame] | 867 | return output_len; |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 868 | } |
| 869 | |
Hannes Reinecke | 1696120 | 2016-11-18 08:32:49 +0100 | [diff] [blame^] | 870 | static ssize_t host_show_ctlr_num(struct device *dev, |
| 871 | struct device_attribute *attr, char *buf) |
| 872 | { |
| 873 | struct ctlr_info *h; |
| 874 | struct Scsi_Host *shost = class_to_shost(dev); |
| 875 | |
| 876 | h = shost_to_hba(shost); |
| 877 | return snprintf(buf, 20, "%d\n", h->ctlr); |
| 878 | } |
| 879 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 880 | static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL); |
| 881 | static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL); |
| 882 | static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL); |
| 883 | static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); |
Joseph T Handzik | ded1be4 | 2016-04-27 17:13:33 -0500 | [diff] [blame] | 884 | static DEVICE_ATTR(sas_address, S_IRUGO, sas_address_show, NULL); |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 885 | static DEVICE_ATTR(hp_ssd_smart_path_enabled, S_IRUGO, |
| 886 | host_show_hp_ssd_smart_path_enabled, NULL); |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 887 | static DEVICE_ATTR(path_info, S_IRUGO, path_info_show, NULL); |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 888 | static DEVICE_ATTR(hp_ssd_smart_path_status, S_IWUSR|S_IRUGO|S_IROTH, |
| 889 | host_show_hp_ssd_smart_path_status, |
| 890 | host_store_hp_ssd_smart_path_status); |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 891 | static DEVICE_ATTR(raid_offload_debug, S_IWUSR, NULL, |
| 892 | host_store_raid_offload_debug); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 893 | static DEVICE_ATTR(firmware_revision, S_IRUGO, |
| 894 | host_show_firmware_revision, NULL); |
| 895 | static DEVICE_ATTR(commands_outstanding, S_IRUGO, |
| 896 | host_show_commands_outstanding, NULL); |
| 897 | static DEVICE_ATTR(transport_mode, S_IRUGO, |
| 898 | host_show_transport_mode, NULL); |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 899 | static DEVICE_ATTR(resettable, S_IRUGO, |
| 900 | host_show_resettable, NULL); |
Stephen Cameron | e985c58 | 2015-04-23 09:32:22 -0500 | [diff] [blame] | 901 | static DEVICE_ATTR(lockup_detected, S_IRUGO, |
| 902 | host_show_lockup_detected, NULL); |
Hannes Reinecke | 1696120 | 2016-11-18 08:32:49 +0100 | [diff] [blame^] | 903 | static DEVICE_ATTR(ctlr_num, S_IRUGO, |
| 904 | host_show_ctlr_num, NULL); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 905 | |
| 906 | static struct device_attribute *hpsa_sdev_attrs[] = { |
| 907 | &dev_attr_raid_level, |
| 908 | &dev_attr_lunid, |
| 909 | &dev_attr_unique_id, |
Scott Teel | c198868 | 2014-02-18 13:55:54 -0600 | [diff] [blame] | 910 | &dev_attr_hp_ssd_smart_path_enabled, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 911 | &dev_attr_path_info, |
Joseph T Handzik | ded1be4 | 2016-04-27 17:13:33 -0500 | [diff] [blame] | 912 | &dev_attr_sas_address, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 913 | NULL, |
| 914 | }; |
| 915 | |
| 916 | static struct device_attribute *hpsa_shost_attrs[] = { |
| 917 | &dev_attr_rescan, |
| 918 | &dev_attr_firmware_revision, |
| 919 | &dev_attr_commands_outstanding, |
| 920 | &dev_attr_transport_mode, |
Stephen M. Cameron | 941b1cd | 2011-03-09 17:00:06 -0600 | [diff] [blame] | 921 | &dev_attr_resettable, |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 922 | &dev_attr_hp_ssd_smart_path_status, |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 923 | &dev_attr_raid_offload_debug, |
Tomas Henzl | fb53c43 | 2015-11-06 16:24:09 +0100 | [diff] [blame] | 924 | &dev_attr_lockup_detected, |
Hannes Reinecke | 1696120 | 2016-11-18 08:32:49 +0100 | [diff] [blame^] | 925 | &dev_attr_ctlr_num, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 926 | NULL, |
| 927 | }; |
| 928 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 929 | #define HPSA_NRESERVED_CMDS (HPSA_CMDS_RESERVED_FOR_ABORTS + \ |
| 930 | HPSA_CMDS_RESERVED_FOR_DRIVER + HPSA_MAX_CONCURRENT_PASSTHRUS) |
| 931 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 932 | static struct scsi_host_template hpsa_driver_template = { |
| 933 | .module = THIS_MODULE, |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 934 | .name = HPSA, |
| 935 | .proc_name = HPSA, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 936 | .queuecommand = hpsa_scsi_queue_command, |
| 937 | .scan_start = hpsa_scan_start, |
| 938 | .scan_finished = hpsa_scan_finished, |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 939 | .change_queue_depth = hpsa_change_queue_depth, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 940 | .this_id = -1, |
| 941 | .use_clustering = ENABLE_CLUSTERING, |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 942 | .eh_abort_handler = hpsa_eh_abort_handler, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 943 | .eh_device_reset_handler = hpsa_eh_device_reset_handler, |
| 944 | .ioctl = hpsa_ioctl, |
| 945 | .slave_alloc = hpsa_slave_alloc, |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 946 | .slave_configure = hpsa_slave_configure, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 947 | .slave_destroy = hpsa_slave_destroy, |
| 948 | #ifdef CONFIG_COMPAT |
| 949 | .compat_ioctl = hpsa_compat_ioctl, |
| 950 | #endif |
| 951 | .sdev_attrs = hpsa_sdev_attrs, |
| 952 | .shost_attrs = hpsa_shost_attrs, |
Stephen M. Cameron | c0d6a4d | 2011-10-26 16:20:53 -0500 | [diff] [blame] | 953 | .max_sectors = 8192, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 954 | .no_write_same = 1, |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 955 | }; |
| 956 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 957 | static inline u32 next_command(struct ctlr_info *h, u8 q) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 958 | { |
| 959 | u32 a; |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 960 | struct reply_queue_buffer *rq = &h->reply_queue[q]; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 961 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 962 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 963 | return h->access.command_completed(h, q); |
| 964 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 965 | if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 966 | return h->access.command_completed(h, q); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 967 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 968 | if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { |
| 969 | a = rq->head[rq->current_entry]; |
| 970 | rq->current_entry++; |
Stephen M. Cameron | 0cbf768 | 2014-11-14 17:27:09 -0600 | [diff] [blame] | 971 | atomic_dec(&h->commands_outstanding); |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 972 | } else { |
| 973 | a = FIFO_EMPTY; |
| 974 | } |
| 975 | /* Check for wraparound */ |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 976 | if (rq->current_entry == h->max_commands) { |
| 977 | rq->current_entry = 0; |
| 978 | rq->wraparound ^= 1; |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 979 | } |
| 980 | return a; |
| 981 | } |
| 982 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 983 | /* |
| 984 | * There are some special bits in the bus address of the |
| 985 | * command that we have to set for the controller to know |
| 986 | * how to process the command: |
| 987 | * |
| 988 | * Normal performant mode: |
| 989 | * bit 0: 1 means performant mode, 0 means simple mode. |
| 990 | * bits 1-3 = block fetch table entry |
| 991 | * bits 4-6 = command type (== 0) |
| 992 | * |
| 993 | * ioaccel1 mode: |
| 994 | * bit 0 = "performant mode" bit. |
| 995 | * bits 1-3 = block fetch table entry |
| 996 | * bits 4-6 = command type (== 110) |
| 997 | * (command type is needed because ioaccel1 mode |
| 998 | * commands are submitted through the same register as normal |
| 999 | * mode commands, so this is how the controller knows whether |
| 1000 | * the command is normal mode or ioaccel1 mode.) |
| 1001 | * |
| 1002 | * ioaccel2 mode: |
| 1003 | * bit 0 = "performant mode" bit. |
| 1004 | * bits 1-4 = block fetch table entry (note extra bit) |
| 1005 | * bits 4-6 = not needed, because ioaccel2 mode has |
| 1006 | * a separate special register for submitting commands. |
| 1007 | */ |
| 1008 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1009 | /* |
| 1010 | * set_performant_mode: Modify the tag for cciss performant |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1011 | * set bit 0 for pull model, bits 3-1 for block fetch |
| 1012 | * register number |
| 1013 | */ |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1014 | #define DEFAULT_REPLY_QUEUE (-1) |
| 1015 | static void set_performant_mode(struct ctlr_info *h, struct CommandList *c, |
| 1016 | int reply_queue) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1017 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 1018 | if (likely(h->transMethod & CFGTBL_Trans_Performant)) { |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1019 | c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1); |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 1020 | if (unlikely(!h->msix_vectors)) |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1021 | return; |
| 1022 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 1023 | c->Header.ReplyQueue = |
John Kacur | 804a5cb | 2013-07-26 16:06:18 +0200 | [diff] [blame] | 1024 | raw_smp_processor_id() % h->nreply_queues; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1025 | else |
| 1026 | c->Header.ReplyQueue = reply_queue % h->nreply_queues; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 1027 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1028 | } |
| 1029 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1030 | static void set_ioaccel1_performant_mode(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1031 | struct CommandList *c, |
| 1032 | int reply_queue) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1033 | { |
| 1034 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 1035 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1036 | /* |
| 1037 | * Tell the controller to post the reply to the queue for this |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1038 | * processor. This seems to give the best I/O throughput. |
| 1039 | */ |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1040 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
| 1041 | cp->ReplyQueue = smp_processor_id() % h->nreply_queues; |
| 1042 | else |
| 1043 | cp->ReplyQueue = reply_queue % h->nreply_queues; |
| 1044 | /* |
| 1045 | * Set the bits in the address sent down to include: |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1046 | * - performant mode bit (bit 0) |
| 1047 | * - pull count (bits 1-3) |
| 1048 | * - command type (bits 4-6) |
| 1049 | */ |
| 1050 | c->busaddr |= 1 | (h->ioaccel1_blockFetchTable[c->Header.SGList] << 1) | |
| 1051 | IOACCEL1_BUSADDR_CMDTYPE; |
| 1052 | } |
| 1053 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 1054 | static void set_ioaccel2_tmf_performant_mode(struct ctlr_info *h, |
| 1055 | struct CommandList *c, |
| 1056 | int reply_queue) |
| 1057 | { |
| 1058 | struct hpsa_tmf_struct *cp = (struct hpsa_tmf_struct *) |
| 1059 | &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 1060 | |
| 1061 | /* Tell the controller to post the reply to the queue for this |
| 1062 | * processor. This seems to give the best I/O throughput. |
| 1063 | */ |
| 1064 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
| 1065 | cp->reply_queue = smp_processor_id() % h->nreply_queues; |
| 1066 | else |
| 1067 | cp->reply_queue = reply_queue % h->nreply_queues; |
| 1068 | /* Set the bits in the address sent down to include: |
| 1069 | * - performant mode bit not used in ioaccel mode 2 |
| 1070 | * - pull count (bits 0-3) |
| 1071 | * - command type isn't needed for ioaccel2 |
| 1072 | */ |
| 1073 | c->busaddr |= h->ioaccel2_blockFetchTable[0]; |
| 1074 | } |
| 1075 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1076 | static void set_ioaccel2_performant_mode(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1077 | struct CommandList *c, |
| 1078 | int reply_queue) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1079 | { |
| 1080 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 1081 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1082 | /* |
| 1083 | * Tell the controller to post the reply to the queue for this |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1084 | * processor. This seems to give the best I/O throughput. |
| 1085 | */ |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1086 | if (likely(reply_queue == DEFAULT_REPLY_QUEUE)) |
| 1087 | cp->reply_queue = smp_processor_id() % h->nreply_queues; |
| 1088 | else |
| 1089 | cp->reply_queue = reply_queue % h->nreply_queues; |
| 1090 | /* |
| 1091 | * Set the bits in the address sent down to include: |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1092 | * - performant mode bit not used in ioaccel mode 2 |
| 1093 | * - pull count (bits 0-3) |
| 1094 | * - command type isn't needed for ioaccel2 |
| 1095 | */ |
| 1096 | c->busaddr |= (h->ioaccel2_blockFetchTable[cp->sg_count]); |
| 1097 | } |
| 1098 | |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 1099 | static int is_firmware_flash_cmd(u8 *cdb) |
| 1100 | { |
| 1101 | return cdb[0] == BMIC_WRITE && cdb[6] == BMIC_FLASH_FIRMWARE; |
| 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * During firmware flash, the heartbeat register may not update as frequently |
| 1106 | * as it should. So we dial down lockup detection during firmware flash. and |
| 1107 | * dial it back up when firmware flash completes. |
| 1108 | */ |
| 1109 | #define HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH (240 * HZ) |
| 1110 | #define HEARTBEAT_SAMPLE_INTERVAL (30 * HZ) |
| 1111 | static void dial_down_lockup_detection_during_fw_flash(struct ctlr_info *h, |
| 1112 | struct CommandList *c) |
| 1113 | { |
| 1114 | if (!is_firmware_flash_cmd(c->Request.CDB)) |
| 1115 | return; |
| 1116 | atomic_inc(&h->firmware_flash_in_progress); |
| 1117 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH; |
| 1118 | } |
| 1119 | |
| 1120 | static void dial_up_lockup_detection_on_fw_flash_complete(struct ctlr_info *h, |
| 1121 | struct CommandList *c) |
| 1122 | { |
| 1123 | if (is_firmware_flash_cmd(c->Request.CDB) && |
| 1124 | atomic_dec_and_test(&h->firmware_flash_in_progress)) |
| 1125 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 1126 | } |
| 1127 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1128 | static void __enqueue_cmd_and_start_io(struct ctlr_info *h, |
| 1129 | struct CommandList *c, int reply_queue) |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1130 | { |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1131 | dial_down_lockup_detection_during_fw_flash(h, c); |
| 1132 | atomic_inc(&h->commands_outstanding); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1133 | switch (c->cmd_type) { |
| 1134 | case CMD_IOACCEL1: |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1135 | set_ioaccel1_performant_mode(h, c, reply_queue); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1136 | writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1137 | break; |
| 1138 | case CMD_IOACCEL2: |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1139 | set_ioaccel2_performant_mode(h, c, reply_queue); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1140 | writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1141 | break; |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 1142 | case IOACCEL2_TMF: |
| 1143 | set_ioaccel2_tmf_performant_mode(h, c, reply_queue); |
| 1144 | writel(c->busaddr, h->vaddr + IOACCEL2_INBOUND_POSTQ_32); |
| 1145 | break; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1146 | default: |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1147 | set_performant_mode(h, c, reply_queue); |
Stephen Cameron | c05e886 | 2015-01-23 16:44:40 -0600 | [diff] [blame] | 1148 | h->access.submit_command(h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 1149 | } |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 1152 | 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] | 1153 | { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 1154 | if (unlikely(hpsa_is_pending_event(c))) |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 1155 | return finish_cmd(c); |
| 1156 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 1157 | __enqueue_cmd_and_start_io(h, c, DEFAULT_REPLY_QUEUE); |
| 1158 | } |
| 1159 | |
Stephen M. Cameron | 3f5eac3 | 2011-03-09 17:00:01 -0600 | [diff] [blame] | 1160 | static inline int is_hba_lunid(unsigned char scsi3addr[]) |
| 1161 | { |
| 1162 | return memcmp(scsi3addr, RAID_CTLR_LUNID, 8) == 0; |
| 1163 | } |
| 1164 | |
| 1165 | static inline int is_scsi_rev_5(struct ctlr_info *h) |
| 1166 | { |
| 1167 | if (!h->hba_inquiry_data) |
| 1168 | return 0; |
| 1169 | if ((h->hba_inquiry_data[2] & 0x07) == 5) |
| 1170 | return 1; |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1174 | static int hpsa_find_target_lun(struct ctlr_info *h, |
| 1175 | unsigned char scsi3addr[], int bus, int *target, int *lun) |
| 1176 | { |
| 1177 | /* finds an unused bus, target, lun for a new physical device |
| 1178 | * assumes h->devlock is held |
| 1179 | */ |
| 1180 | int i, found = 0; |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1181 | DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1182 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 1183 | bitmap_zero(lun_taken, HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1184 | |
| 1185 | for (i = 0; i < h->ndevices; i++) { |
| 1186 | if (h->dev[i]->bus == bus && h->dev[i]->target != -1) |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 1187 | __set_bit(h->dev[i]->target, lun_taken); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Akinobu Mita | 263d940 | 2012-01-21 00:15:27 +0900 | [diff] [blame] | 1190 | i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES); |
| 1191 | if (i < HPSA_MAX_DEVICES) { |
| 1192 | /* *bus = 1; */ |
| 1193 | *target = i; |
| 1194 | *lun = 0; |
| 1195 | found = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1196 | } |
| 1197 | return !found; |
| 1198 | } |
| 1199 | |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1200 | 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] | 1201 | struct hpsa_scsi_dev_t *dev, char *description) |
| 1202 | { |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1203 | #define LABEL_SIZE 25 |
| 1204 | char label[LABEL_SIZE]; |
| 1205 | |
Don Brace | 9975ec9 | 2015-11-04 15:50:25 -0600 | [diff] [blame] | 1206 | if (h == NULL || h->pdev == NULL || h->scsi_host == NULL) |
| 1207 | return; |
| 1208 | |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1209 | switch (dev->devtype) { |
| 1210 | case TYPE_RAID: |
| 1211 | snprintf(label, LABEL_SIZE, "controller"); |
| 1212 | break; |
| 1213 | case TYPE_ENCLOSURE: |
| 1214 | snprintf(label, LABEL_SIZE, "enclosure"); |
| 1215 | break; |
| 1216 | case TYPE_DISK: |
Don Brace | af15ed3 | 2016-02-23 15:16:15 -0600 | [diff] [blame] | 1217 | case TYPE_ZBC: |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1218 | if (dev->external) |
| 1219 | snprintf(label, LABEL_SIZE, "external"); |
| 1220 | else if (!is_logical_dev_addr_mode(dev->scsi3addr)) |
| 1221 | snprintf(label, LABEL_SIZE, "%s", |
| 1222 | raid_label[PHYSICAL_DRIVE]); |
| 1223 | else |
| 1224 | snprintf(label, LABEL_SIZE, "RAID-%s", |
| 1225 | dev->raid_level > RAID_UNKNOWN ? "?" : |
| 1226 | raid_label[dev->raid_level]); |
| 1227 | break; |
| 1228 | case TYPE_ROM: |
| 1229 | snprintf(label, LABEL_SIZE, "rom"); |
| 1230 | break; |
| 1231 | case TYPE_TAPE: |
| 1232 | snprintf(label, LABEL_SIZE, "tape"); |
| 1233 | break; |
| 1234 | case TYPE_MEDIUM_CHANGER: |
| 1235 | snprintf(label, LABEL_SIZE, "changer"); |
| 1236 | break; |
| 1237 | default: |
| 1238 | snprintf(label, LABEL_SIZE, "UNKNOWN"); |
| 1239 | break; |
| 1240 | } |
| 1241 | |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1242 | dev_printk(level, &h->pdev->dev, |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1243 | "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] | 1244 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun, |
| 1245 | description, |
| 1246 | scsi_device_type(dev->devtype), |
| 1247 | dev->vendor, |
| 1248 | dev->model, |
Don Brace | 7c59a0d | 2015-11-04 15:52:22 -0600 | [diff] [blame] | 1249 | label, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1250 | dev->offload_config ? '+' : '-', |
| 1251 | dev->offload_enabled ? '+' : '-', |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1252 | dev->expose_device); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1253 | } |
| 1254 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1255 | /* Add an entry into h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1256 | static int hpsa_scsi_add_entry(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1257 | struct hpsa_scsi_dev_t *device, |
| 1258 | struct hpsa_scsi_dev_t *added[], int *nadded) |
| 1259 | { |
| 1260 | /* assumes h->devlock is held */ |
| 1261 | int n = h->ndevices; |
| 1262 | int i; |
| 1263 | unsigned char addr1[8], addr2[8]; |
| 1264 | struct hpsa_scsi_dev_t *sd; |
| 1265 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1266 | if (n >= HPSA_MAX_DEVICES) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1267 | dev_err(&h->pdev->dev, "too many devices, some will be " |
| 1268 | "inaccessible.\n"); |
| 1269 | return -1; |
| 1270 | } |
| 1271 | |
| 1272 | /* physical devices do not have lun or target assigned until now. */ |
| 1273 | if (device->lun != -1) |
| 1274 | /* Logical device, lun is already assigned. */ |
| 1275 | goto lun_assigned; |
| 1276 | |
| 1277 | /* If this device a non-zero lun of a multi-lun device |
| 1278 | * byte 4 of the 8-byte LUN addr will contain the logical |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 1279 | * unit no, zero otherwise. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1280 | */ |
| 1281 | if (device->scsi3addr[4] == 0) { |
| 1282 | /* This is not a non-zero lun of a multi-lun device */ |
| 1283 | if (hpsa_find_target_lun(h, device->scsi3addr, |
| 1284 | device->bus, &device->target, &device->lun) != 0) |
| 1285 | return -1; |
| 1286 | goto lun_assigned; |
| 1287 | } |
| 1288 | |
| 1289 | /* This is a non-zero lun of a multi-lun device. |
| 1290 | * Search through our list and find the device which |
shane.seymour | 9a4178b | 2015-07-18 11:13:09 -0500 | [diff] [blame] | 1291 | * 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] | 1292 | * Assign the same bus and target for this new LUN. |
| 1293 | * Use the logical unit number from the firmware. |
| 1294 | */ |
| 1295 | memcpy(addr1, device->scsi3addr, 8); |
| 1296 | addr1[4] = 0; |
shane.seymour | 9a4178b | 2015-07-18 11:13:09 -0500 | [diff] [blame] | 1297 | addr1[5] = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1298 | for (i = 0; i < n; i++) { |
| 1299 | sd = h->dev[i]; |
| 1300 | memcpy(addr2, sd->scsi3addr, 8); |
| 1301 | addr2[4] = 0; |
shane.seymour | 9a4178b | 2015-07-18 11:13:09 -0500 | [diff] [blame] | 1302 | addr2[5] = 0; |
| 1303 | /* differ only in byte 4 and 5? */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1304 | if (memcmp(addr1, addr2, 8) == 0) { |
| 1305 | device->bus = sd->bus; |
| 1306 | device->target = sd->target; |
| 1307 | device->lun = device->scsi3addr[4]; |
| 1308 | break; |
| 1309 | } |
| 1310 | } |
| 1311 | if (device->lun == -1) { |
| 1312 | dev_warn(&h->pdev->dev, "physical device with no LUN=0," |
| 1313 | " suspect firmware bug or unsupported hardware " |
| 1314 | "configuration.\n"); |
| 1315 | return -1; |
| 1316 | } |
| 1317 | |
| 1318 | lun_assigned: |
| 1319 | |
| 1320 | h->dev[n] = device; |
| 1321 | h->ndevices++; |
| 1322 | added[*nadded] = device; |
| 1323 | (*nadded)++; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1324 | hpsa_show_dev_msg(KERN_INFO, h, device, |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1325 | device->expose_device ? "added" : "masked"); |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1326 | device->offload_to_be_enabled = device->offload_enabled; |
| 1327 | device->offload_enabled = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1331 | /* Update an entry in h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1332 | static void hpsa_scsi_update_entry(struct ctlr_info *h, |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1333 | int entry, struct hpsa_scsi_dev_t *new_entry) |
| 1334 | { |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1335 | int offload_enabled; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1336 | /* assumes h->devlock is held */ |
| 1337 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
| 1338 | |
| 1339 | /* Raid level changed. */ |
| 1340 | h->dev[entry]->raid_level = new_entry->raid_level; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1341 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1342 | /* Raid offload parameters changed. Careful about the ordering. */ |
| 1343 | if (new_entry->offload_config && new_entry->offload_enabled) { |
| 1344 | /* |
| 1345 | * if drive is newly offload_enabled, we want to copy the |
| 1346 | * raid map data first. If previously offload_enabled and |
| 1347 | * offload_config were set, raid map data had better be |
| 1348 | * the same as it was before. if raid map data is changed |
| 1349 | * then it had better be the case that |
| 1350 | * h->dev[entry]->offload_enabled is currently 0. |
| 1351 | */ |
| 1352 | h->dev[entry]->raid_map = new_entry->raid_map; |
| 1353 | h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1354 | } |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 1355 | if (new_entry->hba_ioaccel_enabled) { |
| 1356 | h->dev[entry]->ioaccel_handle = new_entry->ioaccel_handle; |
| 1357 | wmb(); /* set ioaccel_handle *before* hba_ioaccel_enabled */ |
| 1358 | } |
| 1359 | h->dev[entry]->hba_ioaccel_enabled = new_entry->hba_ioaccel_enabled; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1360 | h->dev[entry]->offload_config = new_entry->offload_config; |
Stephen M. Cameron | 9fb0de2 | 2014-02-18 13:56:50 -0600 | [diff] [blame] | 1361 | h->dev[entry]->offload_to_mirror = new_entry->offload_to_mirror; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1362 | h->dev[entry]->queue_depth = new_entry->queue_depth; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1363 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1364 | /* |
| 1365 | * We can turn off ioaccel offload now, but need to delay turning |
| 1366 | * it on until we can update h->dev[entry]->phys_disk[], but we |
| 1367 | * can't do that until all the devices are updated. |
| 1368 | */ |
| 1369 | h->dev[entry]->offload_to_be_enabled = new_entry->offload_enabled; |
| 1370 | if (!new_entry->offload_enabled) |
| 1371 | h->dev[entry]->offload_enabled = 0; |
| 1372 | |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1373 | offload_enabled = h->dev[entry]->offload_enabled; |
| 1374 | h->dev[entry]->offload_enabled = h->dev[entry]->offload_to_be_enabled; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1375 | hpsa_show_dev_msg(KERN_INFO, h, h->dev[entry], "updated"); |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1376 | h->dev[entry]->offload_enabled = offload_enabled; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1377 | } |
| 1378 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1379 | /* Replace an entry from h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1380 | static void hpsa_scsi_replace_entry(struct ctlr_info *h, |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1381 | int entry, struct hpsa_scsi_dev_t *new_entry, |
| 1382 | struct hpsa_scsi_dev_t *added[], int *nadded, |
| 1383 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1384 | { |
| 1385 | /* assumes h->devlock is held */ |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1386 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1387 | removed[*nremoved] = h->dev[entry]; |
| 1388 | (*nremoved)++; |
Stephen M. Cameron | 01350d0 | 2011-08-09 08:18:01 -0500 | [diff] [blame] | 1389 | |
| 1390 | /* |
| 1391 | * New physical devices won't have target/lun assigned yet |
| 1392 | * so we need to preserve the values in the slot we are replacing. |
| 1393 | */ |
| 1394 | if (new_entry->target == -1) { |
| 1395 | new_entry->target = h->dev[entry]->target; |
| 1396 | new_entry->lun = h->dev[entry]->lun; |
| 1397 | } |
| 1398 | |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1399 | h->dev[entry] = new_entry; |
| 1400 | added[*nadded] = new_entry; |
| 1401 | (*nadded)++; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1402 | hpsa_show_dev_msg(KERN_INFO, h, new_entry, "replaced"); |
Robert Elliott | a473d86 | 2015-04-23 09:32:54 -0500 | [diff] [blame] | 1403 | new_entry->offload_to_be_enabled = new_entry->offload_enabled; |
| 1404 | new_entry->offload_enabled = 0; |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1405 | } |
| 1406 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1407 | /* Remove an entry from h->dev[] array. */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1408 | 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] | 1409 | struct hpsa_scsi_dev_t *removed[], int *nremoved) |
| 1410 | { |
| 1411 | /* assumes h->devlock is held */ |
| 1412 | int i; |
| 1413 | struct hpsa_scsi_dev_t *sd; |
| 1414 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1415 | BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1416 | |
| 1417 | sd = h->dev[entry]; |
| 1418 | removed[*nremoved] = h->dev[entry]; |
| 1419 | (*nremoved)++; |
| 1420 | |
| 1421 | for (i = entry; i < h->ndevices-1; i++) |
| 1422 | h->dev[i] = h->dev[i+1]; |
| 1423 | h->ndevices--; |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1424 | hpsa_show_dev_msg(KERN_INFO, h, sd, "removed"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | #define SCSI3ADDR_EQ(a, b) ( \ |
| 1428 | (a)[7] == (b)[7] && \ |
| 1429 | (a)[6] == (b)[6] && \ |
| 1430 | (a)[5] == (b)[5] && \ |
| 1431 | (a)[4] == (b)[4] && \ |
| 1432 | (a)[3] == (b)[3] && \ |
| 1433 | (a)[2] == (b)[2] && \ |
| 1434 | (a)[1] == (b)[1] && \ |
| 1435 | (a)[0] == (b)[0]) |
| 1436 | |
| 1437 | static void fixup_botched_add(struct ctlr_info *h, |
| 1438 | struct hpsa_scsi_dev_t *added) |
| 1439 | { |
| 1440 | /* called when scsi_add_device fails in order to re-adjust |
| 1441 | * h->dev[] to match the mid layer's view. |
| 1442 | */ |
| 1443 | unsigned long flags; |
| 1444 | int i, j; |
| 1445 | |
| 1446 | spin_lock_irqsave(&h->lock, flags); |
| 1447 | for (i = 0; i < h->ndevices; i++) { |
| 1448 | if (h->dev[i] == added) { |
| 1449 | for (j = i; j < h->ndevices-1; j++) |
| 1450 | h->dev[j] = h->dev[j+1]; |
| 1451 | h->ndevices--; |
| 1452 | break; |
| 1453 | } |
| 1454 | } |
| 1455 | spin_unlock_irqrestore(&h->lock, flags); |
| 1456 | kfree(added); |
| 1457 | } |
| 1458 | |
| 1459 | static inline int device_is_the_same(struct hpsa_scsi_dev_t *dev1, |
| 1460 | struct hpsa_scsi_dev_t *dev2) |
| 1461 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1462 | /* we compare everything except lun and target as these |
| 1463 | * are not yet assigned. Compare parts likely |
| 1464 | * to differ first |
| 1465 | */ |
| 1466 | if (memcmp(dev1->scsi3addr, dev2->scsi3addr, |
| 1467 | sizeof(dev1->scsi3addr)) != 0) |
| 1468 | return 0; |
| 1469 | if (memcmp(dev1->device_id, dev2->device_id, |
| 1470 | sizeof(dev1->device_id)) != 0) |
| 1471 | return 0; |
| 1472 | if (memcmp(dev1->model, dev2->model, sizeof(dev1->model)) != 0) |
| 1473 | return 0; |
| 1474 | if (memcmp(dev1->vendor, dev2->vendor, sizeof(dev1->vendor)) != 0) |
| 1475 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1476 | if (dev1->devtype != dev2->devtype) |
| 1477 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1478 | if (dev1->bus != dev2->bus) |
| 1479 | return 0; |
| 1480 | return 1; |
| 1481 | } |
| 1482 | |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1483 | static inline int device_updated(struct hpsa_scsi_dev_t *dev1, |
| 1484 | struct hpsa_scsi_dev_t *dev2) |
| 1485 | { |
| 1486 | /* Device attributes that can change, but don't mean |
| 1487 | * that the device is a different device, nor that the OS |
| 1488 | * needs to be told anything about the change. |
| 1489 | */ |
| 1490 | if (dev1->raid_level != dev2->raid_level) |
| 1491 | return 1; |
Stephen M. Cameron | 250fb12 | 2014-02-18 13:55:38 -0600 | [diff] [blame] | 1492 | if (dev1->offload_config != dev2->offload_config) |
| 1493 | return 1; |
| 1494 | if (dev1->offload_enabled != dev2->offload_enabled) |
| 1495 | return 1; |
Don Brace | 9384950 | 2015-07-18 11:12:49 -0500 | [diff] [blame] | 1496 | if (!is_logical_dev_addr_mode(dev1->scsi3addr)) |
| 1497 | if (dev1->queue_depth != dev2->queue_depth) |
| 1498 | return 1; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |
| 1501 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1502 | /* Find needle in haystack. If exact match found, return DEVICE_SAME, |
| 1503 | * and return needle location in *index. If scsi3addr matches, but not |
| 1504 | * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1505 | * location in *index. |
| 1506 | * In the case of a minor device attribute change, such as RAID level, just |
| 1507 | * return DEVICE_UPDATED, along with the updated device's location in index. |
| 1508 | * If needle not found, return DEVICE_NOT_FOUND. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1509 | */ |
| 1510 | static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle, |
| 1511 | struct hpsa_scsi_dev_t *haystack[], int haystack_size, |
| 1512 | int *index) |
| 1513 | { |
| 1514 | int i; |
| 1515 | #define DEVICE_NOT_FOUND 0 |
| 1516 | #define DEVICE_CHANGED 1 |
| 1517 | #define DEVICE_SAME 2 |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1518 | #define DEVICE_UPDATED 3 |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1519 | if (needle == NULL) |
| 1520 | return DEVICE_NOT_FOUND; |
| 1521 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1522 | for (i = 0; i < haystack_size; i++) { |
Stephen M. Cameron | 2323104 | 2010-02-04 08:43:36 -0600 | [diff] [blame] | 1523 | if (haystack[i] == NULL) /* previously removed. */ |
| 1524 | continue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1525 | if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) { |
| 1526 | *index = i; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1527 | if (device_is_the_same(needle, haystack[i])) { |
| 1528 | if (device_updated(needle, haystack[i])) |
| 1529 | return DEVICE_UPDATED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1530 | return DEVICE_SAME; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1531 | } else { |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1532 | /* Keep offline devices offline */ |
| 1533 | if (needle->volume_offline) |
| 1534 | return DEVICE_NOT_FOUND; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1535 | return DEVICE_CHANGED; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1536 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | *index = -1; |
| 1540 | return DEVICE_NOT_FOUND; |
| 1541 | } |
| 1542 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1543 | static void hpsa_monitor_offline_device(struct ctlr_info *h, |
| 1544 | unsigned char scsi3addr[]) |
| 1545 | { |
| 1546 | struct offline_device_entry *device; |
| 1547 | unsigned long flags; |
| 1548 | |
| 1549 | /* Check to see if device is already on the list */ |
| 1550 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 1551 | list_for_each_entry(device, &h->offline_device_list, offline_list) { |
| 1552 | if (memcmp(device->scsi3addr, scsi3addr, |
| 1553 | sizeof(device->scsi3addr)) == 0) { |
| 1554 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1555 | return; |
| 1556 | } |
| 1557 | } |
| 1558 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1559 | |
| 1560 | /* Device is not on the list, add it. */ |
| 1561 | device = kmalloc(sizeof(*device), GFP_KERNEL); |
| 1562 | if (!device) { |
| 1563 | dev_warn(&h->pdev->dev, "out of memory in %s\n", __func__); |
| 1564 | return; |
| 1565 | } |
| 1566 | memcpy(device->scsi3addr, scsi3addr, sizeof(device->scsi3addr)); |
| 1567 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 1568 | list_add_tail(&device->offline_list, &h->offline_device_list); |
| 1569 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 1570 | } |
| 1571 | |
| 1572 | /* Print a message explaining various offline volume states */ |
| 1573 | static void hpsa_show_volume_status(struct ctlr_info *h, |
| 1574 | struct hpsa_scsi_dev_t *sd) |
| 1575 | { |
| 1576 | if (sd->volume_offline == HPSA_VPD_LV_STATUS_UNSUPPORTED) |
| 1577 | dev_info(&h->pdev->dev, |
| 1578 | "C%d:B%d:T%d:L%d Volume status is not available through vital product data pages.\n", |
| 1579 | h->scsi_host->host_no, |
| 1580 | sd->bus, sd->target, sd->lun); |
| 1581 | switch (sd->volume_offline) { |
| 1582 | case HPSA_LV_OK: |
| 1583 | break; |
| 1584 | case HPSA_LV_UNDERGOING_ERASE: |
| 1585 | dev_info(&h->pdev->dev, |
| 1586 | "C%d:B%d:T%d:L%d Volume is undergoing background erase process.\n", |
| 1587 | h->scsi_host->host_no, |
| 1588 | sd->bus, sd->target, sd->lun); |
| 1589 | break; |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 1590 | case HPSA_LV_NOT_AVAILABLE: |
| 1591 | dev_info(&h->pdev->dev, |
| 1592 | "C%d:B%d:T%d:L%d Volume is waiting for transforming volume.\n", |
| 1593 | h->scsi_host->host_no, |
| 1594 | sd->bus, sd->target, sd->lun); |
| 1595 | break; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1596 | case HPSA_LV_UNDERGOING_RPI: |
| 1597 | dev_info(&h->pdev->dev, |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 1598 | "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] | 1599 | h->scsi_host->host_no, |
| 1600 | sd->bus, sd->target, sd->lun); |
| 1601 | break; |
| 1602 | case HPSA_LV_PENDING_RPI: |
| 1603 | dev_info(&h->pdev->dev, |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 1604 | "C%d:B%d:T%d:L%d Volume is queued for rapid parity initialization process.\n", |
| 1605 | h->scsi_host->host_no, |
| 1606 | sd->bus, sd->target, sd->lun); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1607 | break; |
| 1608 | case HPSA_LV_ENCRYPTED_NO_KEY: |
| 1609 | dev_info(&h->pdev->dev, |
| 1610 | "C%d:B%d:T%d:L%d Volume is encrypted and cannot be accessed because key is not present.\n", |
| 1611 | h->scsi_host->host_no, |
| 1612 | sd->bus, sd->target, sd->lun); |
| 1613 | break; |
| 1614 | case HPSA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER: |
| 1615 | dev_info(&h->pdev->dev, |
| 1616 | "C%d:B%d:T%d:L%d Volume is not encrypted and cannot be accessed because controller is in encryption-only mode.\n", |
| 1617 | h->scsi_host->host_no, |
| 1618 | sd->bus, sd->target, sd->lun); |
| 1619 | break; |
| 1620 | case HPSA_LV_UNDERGOING_ENCRYPTION: |
| 1621 | dev_info(&h->pdev->dev, |
| 1622 | "C%d:B%d:T%d:L%d Volume is undergoing encryption process.\n", |
| 1623 | h->scsi_host->host_no, |
| 1624 | sd->bus, sd->target, sd->lun); |
| 1625 | break; |
| 1626 | case HPSA_LV_UNDERGOING_ENCRYPTION_REKEYING: |
| 1627 | dev_info(&h->pdev->dev, |
| 1628 | "C%d:B%d:T%d:L%d Volume is undergoing encryption re-keying process.\n", |
| 1629 | h->scsi_host->host_no, |
| 1630 | sd->bus, sd->target, sd->lun); |
| 1631 | break; |
| 1632 | case HPSA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: |
| 1633 | dev_info(&h->pdev->dev, |
| 1634 | "C%d:B%d:T%d:L%d Volume is encrypted and cannot be accessed because controller does not have encryption enabled.\n", |
| 1635 | h->scsi_host->host_no, |
| 1636 | sd->bus, sd->target, sd->lun); |
| 1637 | break; |
| 1638 | case HPSA_LV_PENDING_ENCRYPTION: |
| 1639 | dev_info(&h->pdev->dev, |
| 1640 | "C%d:B%d:T%d:L%d Volume is pending migration to encrypted state, but process has not started.\n", |
| 1641 | h->scsi_host->host_no, |
| 1642 | sd->bus, sd->target, sd->lun); |
| 1643 | break; |
| 1644 | case HPSA_LV_PENDING_ENCRYPTION_REKEYING: |
| 1645 | dev_info(&h->pdev->dev, |
| 1646 | "C%d:B%d:T%d:L%d Volume is encrypted and is pending encryption rekeying.\n", |
| 1647 | h->scsi_host->host_no, |
| 1648 | sd->bus, sd->target, sd->lun); |
| 1649 | break; |
| 1650 | } |
| 1651 | } |
| 1652 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1653 | /* |
| 1654 | * Figure the list of physical drive pointers for a logical drive with |
| 1655 | * raid offload configured. |
| 1656 | */ |
| 1657 | static void hpsa_figure_phys_disk_ptrs(struct ctlr_info *h, |
| 1658 | struct hpsa_scsi_dev_t *dev[], int ndevices, |
| 1659 | struct hpsa_scsi_dev_t *logical_drive) |
| 1660 | { |
| 1661 | struct raid_map_data *map = &logical_drive->raid_map; |
| 1662 | struct raid_map_disk_data *dd = &map->data[0]; |
| 1663 | int i, j; |
| 1664 | int total_disks_per_row = le16_to_cpu(map->data_disks_per_row) + |
| 1665 | le16_to_cpu(map->metadata_disks_per_row); |
| 1666 | int nraid_map_entries = le16_to_cpu(map->row_cnt) * |
| 1667 | le16_to_cpu(map->layout_map_count) * |
| 1668 | total_disks_per_row; |
| 1669 | int nphys_disk = le16_to_cpu(map->layout_map_count) * |
| 1670 | total_disks_per_row; |
| 1671 | int qdepth; |
| 1672 | |
| 1673 | if (nraid_map_entries > RAID_MAP_MAX_ENTRIES) |
| 1674 | nraid_map_entries = RAID_MAP_MAX_ENTRIES; |
| 1675 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 1676 | logical_drive->nphysical_disks = nraid_map_entries; |
| 1677 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1678 | qdepth = 0; |
| 1679 | for (i = 0; i < nraid_map_entries; i++) { |
| 1680 | logical_drive->phys_disk[i] = NULL; |
| 1681 | if (!logical_drive->offload_config) |
| 1682 | continue; |
| 1683 | for (j = 0; j < ndevices; j++) { |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1684 | if (dev[j] == NULL) |
| 1685 | continue; |
Petros Koutoupis | ff615f0 | 2016-05-09 13:44:10 -0500 | [diff] [blame] | 1686 | if (dev[j]->devtype != TYPE_DISK && |
| 1687 | dev[j]->devtype != TYPE_ZBC) |
Don Brace | af15ed3 | 2016-02-23 15:16:15 -0600 | [diff] [blame] | 1688 | continue; |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 1689 | if (is_logical_device(dev[j])) |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1690 | continue; |
| 1691 | if (dev[j]->ioaccel_handle != dd[i].ioaccel_handle) |
| 1692 | continue; |
| 1693 | |
| 1694 | logical_drive->phys_disk[i] = dev[j]; |
| 1695 | if (i < nphys_disk) |
| 1696 | qdepth = min(h->nr_cmds, qdepth + |
| 1697 | logical_drive->phys_disk[i]->queue_depth); |
| 1698 | break; |
| 1699 | } |
| 1700 | |
| 1701 | /* |
| 1702 | * This can happen if a physical drive is removed and |
| 1703 | * the logical drive is degraded. In that case, the RAID |
| 1704 | * map data will refer to a physical disk which isn't actually |
| 1705 | * present. And in that case offload_enabled should already |
| 1706 | * be 0, but we'll turn it off here just in case |
| 1707 | */ |
| 1708 | if (!logical_drive->phys_disk[i]) { |
| 1709 | logical_drive->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1710 | logical_drive->offload_to_be_enabled = 0; |
| 1711 | logical_drive->queue_depth = 8; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | if (nraid_map_entries) |
| 1715 | /* |
| 1716 | * This is correct for reads, too high for full stripe writes, |
| 1717 | * way too high for partial stripe writes |
| 1718 | */ |
| 1719 | logical_drive->queue_depth = qdepth; |
| 1720 | else |
| 1721 | logical_drive->queue_depth = h->nr_cmds; |
| 1722 | } |
| 1723 | |
| 1724 | static void hpsa_update_log_drive_phys_drive_ptrs(struct ctlr_info *h, |
| 1725 | struct hpsa_scsi_dev_t *dev[], int ndevices) |
| 1726 | { |
| 1727 | int i; |
| 1728 | |
| 1729 | for (i = 0; i < ndevices; i++) { |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1730 | if (dev[i] == NULL) |
| 1731 | continue; |
Petros Koutoupis | ff615f0 | 2016-05-09 13:44:10 -0500 | [diff] [blame] | 1732 | if (dev[i]->devtype != TYPE_DISK && |
| 1733 | dev[i]->devtype != TYPE_ZBC) |
Don Brace | af15ed3 | 2016-02-23 15:16:15 -0600 | [diff] [blame] | 1734 | continue; |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 1735 | if (!is_logical_device(dev[i])) |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1736 | continue; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1737 | |
| 1738 | /* |
| 1739 | * If offload is currently enabled, the RAID map and |
| 1740 | * phys_disk[] assignment *better* not be changing |
| 1741 | * and since it isn't changing, we do not need to |
| 1742 | * update it. |
| 1743 | */ |
| 1744 | if (dev[i]->offload_enabled) |
| 1745 | continue; |
| 1746 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 1747 | hpsa_figure_phys_disk_ptrs(h, dev, ndevices, dev[i]); |
| 1748 | } |
| 1749 | } |
| 1750 | |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1751 | static int hpsa_add_device(struct ctlr_info *h, struct hpsa_scsi_dev_t *device) |
| 1752 | { |
| 1753 | int rc = 0; |
| 1754 | |
| 1755 | if (!h->scsi_host) |
| 1756 | return 1; |
| 1757 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 1758 | if (is_logical_device(device)) /* RAID */ |
| 1759 | rc = scsi_add_device(h->scsi_host, device->bus, |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1760 | device->target, device->lun); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 1761 | else /* HBA */ |
| 1762 | rc = hpsa_add_sas_device(h->sas_host, device); |
| 1763 | |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1764 | return rc; |
| 1765 | } |
| 1766 | |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 1767 | static int hpsa_find_outstanding_commands_for_dev(struct ctlr_info *h, |
| 1768 | struct hpsa_scsi_dev_t *dev) |
| 1769 | { |
| 1770 | int i; |
| 1771 | int count = 0; |
| 1772 | |
| 1773 | for (i = 0; i < h->nr_cmds; i++) { |
| 1774 | struct CommandList *c = h->cmd_pool + i; |
| 1775 | int refcount = atomic_inc_return(&c->refcount); |
| 1776 | |
| 1777 | if (refcount > 1 && hpsa_cmd_dev_match(h, c, dev, |
| 1778 | dev->scsi3addr)) { |
| 1779 | unsigned long flags; |
| 1780 | |
| 1781 | spin_lock_irqsave(&h->lock, flags); /* Implied MB */ |
| 1782 | if (!hpsa_is_cmd_idle(c)) |
| 1783 | ++count; |
| 1784 | spin_unlock_irqrestore(&h->lock, flags); |
| 1785 | } |
| 1786 | |
| 1787 | cmd_free(h, c); |
| 1788 | } |
| 1789 | |
| 1790 | return count; |
| 1791 | } |
| 1792 | |
| 1793 | static void hpsa_wait_for_outstanding_commands_for_dev(struct ctlr_info *h, |
| 1794 | struct hpsa_scsi_dev_t *device) |
| 1795 | { |
| 1796 | int cmds = 0; |
| 1797 | int waits = 0; |
| 1798 | |
| 1799 | while (1) { |
| 1800 | cmds = hpsa_find_outstanding_commands_for_dev(h, device); |
| 1801 | if (cmds == 0) |
| 1802 | break; |
| 1803 | if (++waits > 20) |
| 1804 | break; |
| 1805 | dev_warn(&h->pdev->dev, |
| 1806 | "%s: removing device with %d outstanding commands!\n", |
| 1807 | __func__, cmds); |
| 1808 | msleep(1000); |
| 1809 | } |
| 1810 | } |
| 1811 | |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1812 | static void hpsa_remove_device(struct ctlr_info *h, |
| 1813 | struct hpsa_scsi_dev_t *device) |
| 1814 | { |
| 1815 | struct scsi_device *sdev = NULL; |
| 1816 | |
| 1817 | if (!h->scsi_host) |
| 1818 | return; |
| 1819 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 1820 | if (is_logical_device(device)) { /* RAID */ |
| 1821 | sdev = scsi_device_lookup(h->scsi_host, device->bus, |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1822 | device->target, device->lun); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 1823 | if (sdev) { |
| 1824 | scsi_remove_device(sdev); |
| 1825 | scsi_device_put(sdev); |
| 1826 | } else { |
| 1827 | /* |
| 1828 | * We don't expect to get here. Future commands |
| 1829 | * to this device will get a selection timeout as |
| 1830 | * if the device were gone. |
| 1831 | */ |
| 1832 | hpsa_show_dev_msg(KERN_WARNING, h, device, |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1833 | "didn't find device for removal."); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 1834 | } |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 1835 | } else { /* HBA */ |
| 1836 | |
| 1837 | device->removed = 1; |
| 1838 | hpsa_wait_for_outstanding_commands_for_dev(h, device); |
| 1839 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 1840 | hpsa_remove_sas_device(device); |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 1841 | } |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1842 | } |
| 1843 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1844 | static void adjust_hpsa_scsi_table(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1845 | struct hpsa_scsi_dev_t *sd[], int nsds) |
| 1846 | { |
| 1847 | /* sd contains scsi3 addresses and devtypes, and inquiry |
| 1848 | * data. This function takes what's in sd to be the current |
| 1849 | * reality and updates h->dev[] to reflect that reality. |
| 1850 | */ |
| 1851 | int i, entry, device_change, changes = 0; |
| 1852 | struct hpsa_scsi_dev_t *csd; |
| 1853 | unsigned long flags; |
| 1854 | struct hpsa_scsi_dev_t **added, **removed; |
| 1855 | int nadded, nremoved; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1856 | |
Don Brace | da03ded | 2015-11-04 15:50:56 -0600 | [diff] [blame] | 1857 | /* |
| 1858 | * A reset can cause a device status to change |
| 1859 | * re-schedule the scan to see what happened. |
| 1860 | */ |
| 1861 | if (h->reset_in_progress) { |
| 1862 | h->drv_req_rescan = 1; |
| 1863 | return; |
| 1864 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1865 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 1866 | added = kzalloc(sizeof(*added) * HPSA_MAX_DEVICES, GFP_KERNEL); |
| 1867 | removed = kzalloc(sizeof(*removed) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1868 | |
| 1869 | if (!added || !removed) { |
| 1870 | dev_warn(&h->pdev->dev, "out of memory in " |
| 1871 | "adjust_hpsa_scsi_table\n"); |
| 1872 | goto free_and_out; |
| 1873 | } |
| 1874 | |
| 1875 | spin_lock_irqsave(&h->devlock, flags); |
| 1876 | |
| 1877 | /* find any devices in h->dev[] that are not in |
| 1878 | * sd[] and remove them from h->dev[], and for any |
| 1879 | * devices which have changed, remove the old device |
| 1880 | * info and add the new device info. |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1881 | * If minor device attributes change, just update |
| 1882 | * the existing device structure. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1883 | */ |
| 1884 | i = 0; |
| 1885 | nremoved = 0; |
| 1886 | nadded = 0; |
| 1887 | while (i < h->ndevices) { |
| 1888 | csd = h->dev[i]; |
| 1889 | device_change = hpsa_scsi_find_entry(csd, sd, nsds, &entry); |
| 1890 | if (device_change == DEVICE_NOT_FOUND) { |
| 1891 | changes++; |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1892 | hpsa_scsi_remove_entry(h, i, removed, &nremoved); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1893 | continue; /* remove ^^^, hence i not incremented */ |
| 1894 | } else if (device_change == DEVICE_CHANGED) { |
| 1895 | changes++; |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1896 | hpsa_scsi_replace_entry(h, i, sd[entry], |
Stephen M. Cameron | 2a8ccf3 | 2010-02-04 08:43:41 -0600 | [diff] [blame] | 1897 | added, &nadded, removed, &nremoved); |
Stephen M. Cameron | c7f172d | 2010-02-04 08:43:31 -0600 | [diff] [blame] | 1898 | /* Set it to NULL to prevent it from being freed |
| 1899 | * at the bottom of hpsa_update_scsi_devices() |
| 1900 | */ |
| 1901 | sd[entry] = NULL; |
Scott Teel | bd9244f | 2012-01-19 14:01:30 -0600 | [diff] [blame] | 1902 | } else if (device_change == DEVICE_UPDATED) { |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1903 | hpsa_scsi_update_entry(h, i, sd[entry]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1904 | } |
| 1905 | i++; |
| 1906 | } |
| 1907 | |
| 1908 | /* Now, make sure every device listed in sd[] is also |
| 1909 | * listed in h->dev[], adding them if they aren't found |
| 1910 | */ |
| 1911 | |
| 1912 | for (i = 0; i < nsds; i++) { |
| 1913 | if (!sd[i]) /* if already added above. */ |
| 1914 | continue; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1915 | |
| 1916 | /* Don't add devices which are NOT READY, FORMAT IN PROGRESS |
| 1917 | * as the SCSI mid-layer does not handle such devices well. |
| 1918 | * It relentlessly loops sending TUR at 3Hz, then READ(10) |
| 1919 | * at 160Hz, and prevents the system from coming up. |
| 1920 | */ |
| 1921 | if (sd[i]->volume_offline) { |
| 1922 | hpsa_show_volume_status(h, sd[i]); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 1923 | hpsa_show_dev_msg(KERN_INFO, h, sd[i], "offline"); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1924 | continue; |
| 1925 | } |
| 1926 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1927 | device_change = hpsa_scsi_find_entry(sd[i], h->dev, |
| 1928 | h->ndevices, &entry); |
| 1929 | if (device_change == DEVICE_NOT_FOUND) { |
| 1930 | changes++; |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1931 | if (hpsa_scsi_add_entry(h, sd[i], added, &nadded) != 0) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1932 | break; |
| 1933 | sd[i] = NULL; /* prevent from being freed later. */ |
| 1934 | } else if (device_change == DEVICE_CHANGED) { |
| 1935 | /* should never happen... */ |
| 1936 | changes++; |
| 1937 | dev_warn(&h->pdev->dev, |
| 1938 | "device unexpectedly changed.\n"); |
| 1939 | /* but if it does happen, we just ignore that device */ |
| 1940 | } |
| 1941 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1942 | hpsa_update_log_drive_phys_drive_ptrs(h, h->dev, h->ndevices); |
| 1943 | |
| 1944 | /* Now that h->dev[]->phys_disk[] is coherent, we can enable |
| 1945 | * any logical drives that need it enabled. |
| 1946 | */ |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1947 | for (i = 0; i < h->ndevices; i++) { |
| 1948 | if (h->dev[i] == NULL) |
| 1949 | continue; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1950 | h->dev[i]->offload_enabled = h->dev[i]->offload_to_be_enabled; |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1951 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1952 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1953 | spin_unlock_irqrestore(&h->devlock, flags); |
| 1954 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 1955 | /* Monitor devices which are in one of several NOT READY states to be |
| 1956 | * brought online later. This must be done without holding h->devlock, |
| 1957 | * so don't touch h->dev[] |
| 1958 | */ |
| 1959 | for (i = 0; i < nsds; i++) { |
| 1960 | if (!sd[i]) /* if already added above. */ |
| 1961 | continue; |
| 1962 | if (sd[i]->volume_offline) |
| 1963 | hpsa_monitor_offline_device(h, sd[i]->scsi3addr); |
| 1964 | } |
| 1965 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1966 | /* Don't notify scsi mid layer of any changes the first time through |
| 1967 | * (or if there are no changes) scsi_scan_host will do it later the |
| 1968 | * first time through. |
| 1969 | */ |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 1970 | if (!changes) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1971 | goto free_and_out; |
| 1972 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1973 | /* Notify scsi mid layer of any removed devices */ |
| 1974 | for (i = 0; i < nremoved; i++) { |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1975 | if (removed[i] == NULL) |
| 1976 | continue; |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1977 | if (removed[i]->expose_device) |
| 1978 | hpsa_remove_device(h, removed[i]); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1979 | kfree(removed[i]); |
| 1980 | removed[i] = NULL; |
| 1981 | } |
| 1982 | |
| 1983 | /* Notify scsi mid layer of any added devices */ |
| 1984 | for (i = 0; i < nadded; i++) { |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1985 | int rc = 0; |
| 1986 | |
Don Brace | 1d33d85 | 2015-11-04 15:50:31 -0600 | [diff] [blame] | 1987 | if (added[i] == NULL) |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 1988 | continue; |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 1989 | if (!(added[i]->expose_device)) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1990 | continue; |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1991 | rc = hpsa_add_device(h, added[i]); |
| 1992 | if (!rc) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1993 | continue; |
Kevin Barnett | 096ccff | 2015-11-04 15:51:51 -0600 | [diff] [blame] | 1994 | dev_warn(&h->pdev->dev, |
| 1995 | "addition failed %d, device not added.", rc); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 1996 | /* now we have to remove it from h->dev, |
| 1997 | * since it didn't get added to scsi mid layer |
| 1998 | */ |
| 1999 | fixup_botched_add(h, added[i]); |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 2000 | h->drv_req_rescan = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | free_and_out: |
| 2004 | kfree(added); |
| 2005 | kfree(removed); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /* |
Joe Perches | 9e03aa2 | 2013-09-03 13:45:58 -0700 | [diff] [blame] | 2009 | * 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] | 2010 | * Assume's h->devlock is held. |
| 2011 | */ |
| 2012 | static struct hpsa_scsi_dev_t *lookup_hpsa_scsi_dev(struct ctlr_info *h, |
| 2013 | int bus, int target, int lun) |
| 2014 | { |
| 2015 | int i; |
| 2016 | struct hpsa_scsi_dev_t *sd; |
| 2017 | |
| 2018 | for (i = 0; i < h->ndevices; i++) { |
| 2019 | sd = h->dev[i]; |
| 2020 | if (sd->bus == bus && sd->target == target && sd->lun == lun) |
| 2021 | return sd; |
| 2022 | } |
| 2023 | return NULL; |
| 2024 | } |
| 2025 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2026 | static int hpsa_slave_alloc(struct scsi_device *sdev) |
| 2027 | { |
| 2028 | struct hpsa_scsi_dev_t *sd; |
| 2029 | unsigned long flags; |
| 2030 | struct ctlr_info *h; |
| 2031 | |
| 2032 | h = sdev_to_hba(sdev); |
| 2033 | spin_lock_irqsave(&h->devlock, flags); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 2034 | if (sdev_channel(sdev) == HPSA_PHYSICAL_DEVICE_BUS) { |
| 2035 | struct scsi_target *starget; |
| 2036 | struct sas_rphy *rphy; |
| 2037 | |
| 2038 | starget = scsi_target(sdev); |
| 2039 | rphy = target_to_rphy(starget); |
| 2040 | sd = hpsa_find_device_by_sas_rphy(h, rphy); |
| 2041 | if (sd) { |
| 2042 | sd->target = sdev_id(sdev); |
| 2043 | sd->lun = sdev->lun; |
| 2044 | } |
| 2045 | } else |
| 2046 | sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev), |
| 2047 | sdev_id(sdev), sdev->lun); |
| 2048 | |
| 2049 | if (sd && sd->expose_device) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2050 | atomic_set(&sd->ioaccel_cmds_out, 0); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 2051 | sdev->hostdata = sd; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 2052 | } else |
| 2053 | sdev->hostdata = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2054 | spin_unlock_irqrestore(&h->devlock, flags); |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 2058 | /* configure scsi device based on internal per-device structure */ |
| 2059 | static int hpsa_slave_configure(struct scsi_device *sdev) |
| 2060 | { |
| 2061 | struct hpsa_scsi_dev_t *sd; |
| 2062 | int queue_depth; |
| 2063 | |
| 2064 | sd = sdev->hostdata; |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 2065 | sdev->no_uld_attach = !sd || !sd->expose_device; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 2066 | |
| 2067 | if (sd) |
| 2068 | queue_depth = sd->queue_depth != 0 ? |
| 2069 | sd->queue_depth : sdev->host->can_queue; |
| 2070 | else |
| 2071 | queue_depth = sdev->host->can_queue; |
| 2072 | |
| 2073 | scsi_change_queue_depth(sdev, queue_depth); |
| 2074 | |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2078 | static void hpsa_slave_destroy(struct scsi_device *sdev) |
| 2079 | { |
Stephen M. Cameron | bcc4425 | 2010-02-04 08:41:54 -0600 | [diff] [blame] | 2080 | /* nothing to do. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2081 | } |
| 2082 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2083 | static void hpsa_free_ioaccel2_sg_chain_blocks(struct ctlr_info *h) |
| 2084 | { |
| 2085 | int i; |
| 2086 | |
| 2087 | if (!h->ioaccel2_cmd_sg_list) |
| 2088 | return; |
| 2089 | for (i = 0; i < h->nr_cmds; i++) { |
| 2090 | kfree(h->ioaccel2_cmd_sg_list[i]); |
| 2091 | h->ioaccel2_cmd_sg_list[i] = NULL; |
| 2092 | } |
| 2093 | kfree(h->ioaccel2_cmd_sg_list); |
| 2094 | h->ioaccel2_cmd_sg_list = NULL; |
| 2095 | } |
| 2096 | |
| 2097 | static int hpsa_allocate_ioaccel2_sg_chain_blocks(struct ctlr_info *h) |
| 2098 | { |
| 2099 | int i; |
| 2100 | |
| 2101 | if (h->chainsize <= 0) |
| 2102 | return 0; |
| 2103 | |
| 2104 | h->ioaccel2_cmd_sg_list = |
| 2105 | kzalloc(sizeof(*h->ioaccel2_cmd_sg_list) * h->nr_cmds, |
| 2106 | GFP_KERNEL); |
| 2107 | if (!h->ioaccel2_cmd_sg_list) |
| 2108 | return -ENOMEM; |
| 2109 | for (i = 0; i < h->nr_cmds; i++) { |
| 2110 | h->ioaccel2_cmd_sg_list[i] = |
| 2111 | kmalloc(sizeof(*h->ioaccel2_cmd_sg_list[i]) * |
| 2112 | h->maxsgentries, GFP_KERNEL); |
| 2113 | if (!h->ioaccel2_cmd_sg_list[i]) |
| 2114 | goto clean; |
| 2115 | } |
| 2116 | return 0; |
| 2117 | |
| 2118 | clean: |
| 2119 | hpsa_free_ioaccel2_sg_chain_blocks(h); |
| 2120 | return -ENOMEM; |
| 2121 | } |
| 2122 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2123 | static void hpsa_free_sg_chain_blocks(struct ctlr_info *h) |
| 2124 | { |
| 2125 | int i; |
| 2126 | |
| 2127 | if (!h->cmd_sg_list) |
| 2128 | return; |
| 2129 | for (i = 0; i < h->nr_cmds; i++) { |
| 2130 | kfree(h->cmd_sg_list[i]); |
| 2131 | h->cmd_sg_list[i] = NULL; |
| 2132 | } |
| 2133 | kfree(h->cmd_sg_list); |
| 2134 | h->cmd_sg_list = NULL; |
| 2135 | } |
| 2136 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 2137 | static int hpsa_alloc_sg_chain_blocks(struct ctlr_info *h) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2138 | { |
| 2139 | int i; |
| 2140 | |
| 2141 | if (h->chainsize <= 0) |
| 2142 | return 0; |
| 2143 | |
| 2144 | h->cmd_sg_list = kzalloc(sizeof(*h->cmd_sg_list) * h->nr_cmds, |
| 2145 | GFP_KERNEL); |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2146 | if (!h->cmd_sg_list) { |
| 2147 | dev_err(&h->pdev->dev, "Failed to allocate SG list\n"); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2148 | return -ENOMEM; |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2149 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2150 | for (i = 0; i < h->nr_cmds; i++) { |
| 2151 | h->cmd_sg_list[i] = kmalloc(sizeof(*h->cmd_sg_list[i]) * |
| 2152 | h->chainsize, GFP_KERNEL); |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2153 | if (!h->cmd_sg_list[i]) { |
| 2154 | dev_err(&h->pdev->dev, "Failed to allocate cmd SG\n"); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2155 | goto clean; |
Robert Elliott | 3d4e6af | 2015-01-23 16:42:42 -0600 | [diff] [blame] | 2156 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2157 | } |
| 2158 | return 0; |
| 2159 | |
| 2160 | clean: |
| 2161 | hpsa_free_sg_chain_blocks(h); |
| 2162 | return -ENOMEM; |
| 2163 | } |
| 2164 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2165 | static int hpsa_map_ioaccel2_sg_chain_block(struct ctlr_info *h, |
| 2166 | struct io_accel2_cmd *cp, struct CommandList *c) |
| 2167 | { |
| 2168 | struct ioaccel2_sg_element *chain_block; |
| 2169 | u64 temp64; |
| 2170 | u32 chain_size; |
| 2171 | |
| 2172 | chain_block = h->ioaccel2_cmd_sg_list[c->cmdindex]; |
Don Brace | a736e9b | 2015-11-04 15:51:14 -0600 | [diff] [blame] | 2173 | chain_size = le32_to_cpu(cp->sg[0].length); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2174 | temp64 = pci_map_single(h->pdev, chain_block, chain_size, |
| 2175 | PCI_DMA_TODEVICE); |
| 2176 | if (dma_mapping_error(&h->pdev->dev, temp64)) { |
| 2177 | /* prevent subsequent unmapping */ |
| 2178 | cp->sg->address = 0; |
| 2179 | return -1; |
| 2180 | } |
| 2181 | cp->sg->address = cpu_to_le64(temp64); |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
| 2185 | static void hpsa_unmap_ioaccel2_sg_chain_block(struct ctlr_info *h, |
| 2186 | struct io_accel2_cmd *cp) |
| 2187 | { |
| 2188 | struct ioaccel2_sg_element *chain_sg; |
| 2189 | u64 temp64; |
| 2190 | u32 chain_size; |
| 2191 | |
| 2192 | chain_sg = cp->sg; |
| 2193 | temp64 = le64_to_cpu(chain_sg->address); |
Don Brace | a736e9b | 2015-11-04 15:51:14 -0600 | [diff] [blame] | 2194 | chain_size = le32_to_cpu(cp->sg[0].length); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2195 | pci_unmap_single(h->pdev, temp64, chain_size, PCI_DMA_TODEVICE); |
| 2196 | } |
| 2197 | |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2198 | static int hpsa_map_sg_chain_block(struct ctlr_info *h, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2199 | struct CommandList *c) |
| 2200 | { |
| 2201 | struct SGDescriptor *chain_sg, *chain_block; |
| 2202 | u64 temp64; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2203 | u32 chain_len; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2204 | |
| 2205 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
| 2206 | chain_block = h->cmd_sg_list[c->cmdindex]; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2207 | chain_sg->Ext = cpu_to_le32(HPSA_SG_CHAIN); |
| 2208 | chain_len = sizeof(*chain_sg) * |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2209 | (le16_to_cpu(c->Header.SGTotal) - h->max_cmd_sg_entries); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2210 | chain_sg->Len = cpu_to_le32(chain_len); |
| 2211 | temp64 = pci_map_single(h->pdev, chain_block, chain_len, |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2212 | PCI_DMA_TODEVICE); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2213 | if (dma_mapping_error(&h->pdev->dev, temp64)) { |
| 2214 | /* prevent subsequent unmapping */ |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2215 | chain_sg->Addr = cpu_to_le64(0); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2216 | return -1; |
| 2217 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2218 | chain_sg->Addr = cpu_to_le64(temp64); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 2219 | return 0; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | static void hpsa_unmap_sg_chain_block(struct ctlr_info *h, |
| 2223 | struct CommandList *c) |
| 2224 | { |
| 2225 | struct SGDescriptor *chain_sg; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2226 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2227 | 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] | 2228 | return; |
| 2229 | |
| 2230 | chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2231 | pci_unmap_single(h->pdev, le64_to_cpu(chain_sg->Addr), |
| 2232 | le32_to_cpu(chain_sg->Len), PCI_DMA_TODEVICE); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2233 | } |
| 2234 | |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2235 | |
| 2236 | /* Decode the various types of errors on ioaccel2 path. |
| 2237 | * Return 1 for any error that should generate a RAID path retry. |
| 2238 | * Return 0 for errors that don't require a RAID path retry. |
| 2239 | */ |
| 2240 | static int handle_ioaccel_mode2_error(struct ctlr_info *h, |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2241 | struct CommandList *c, |
| 2242 | struct scsi_cmnd *cmd, |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 2243 | struct io_accel2_cmd *c2, |
| 2244 | struct hpsa_scsi_dev_t *dev) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2245 | { |
| 2246 | int data_len; |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2247 | int retry = 0; |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2248 | u32 ioaccel2_resid = 0; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2249 | |
| 2250 | switch (c2->error_data.serv_response) { |
| 2251 | case IOACCEL2_SERV_RESPONSE_COMPLETE: |
| 2252 | switch (c2->error_data.status) { |
| 2253 | case IOACCEL2_STATUS_SR_TASK_COMP_GOOD: |
| 2254 | break; |
| 2255 | case IOACCEL2_STATUS_SR_TASK_COMP_CHK_COND: |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 2256 | cmd->result |= SAM_STAT_CHECK_CONDITION; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2257 | if (c2->error_data.data_present != |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 2258 | IOACCEL2_SENSE_DATA_PRESENT) { |
| 2259 | memset(cmd->sense_buffer, 0, |
| 2260 | SCSI_SENSE_BUFFERSIZE); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2261 | break; |
Stephen M. Cameron | ee6b188 | 2014-05-29 10:53:54 -0500 | [diff] [blame] | 2262 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2263 | /* copy the sense data */ |
| 2264 | data_len = c2->error_data.sense_data_len; |
| 2265 | if (data_len > SCSI_SENSE_BUFFERSIZE) |
| 2266 | data_len = SCSI_SENSE_BUFFERSIZE; |
| 2267 | if (data_len > sizeof(c2->error_data.sense_data_buff)) |
| 2268 | data_len = |
| 2269 | sizeof(c2->error_data.sense_data_buff); |
| 2270 | memcpy(cmd->sense_buffer, |
| 2271 | c2->error_data.sense_data_buff, data_len); |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2272 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2273 | break; |
| 2274 | case IOACCEL2_STATUS_SR_TASK_COMP_BUSY: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2275 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2276 | break; |
| 2277 | case IOACCEL2_STATUS_SR_TASK_COMP_RES_CON: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2278 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2279 | break; |
| 2280 | case IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL: |
Stephen Cameron | 4a8da22 | 2015-04-23 09:32:43 -0500 | [diff] [blame] | 2281 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2282 | break; |
| 2283 | case IOACCEL2_STATUS_SR_TASK_COMP_ABORTED: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2284 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2285 | break; |
| 2286 | default: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2287 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2288 | break; |
| 2289 | } |
| 2290 | break; |
| 2291 | case IOACCEL2_SERV_RESPONSE_FAILURE: |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2292 | switch (c2->error_data.status) { |
| 2293 | case IOACCEL2_STATUS_SR_IO_ERROR: |
| 2294 | case IOACCEL2_STATUS_SR_IO_ABORTED: |
| 2295 | case IOACCEL2_STATUS_SR_OVERRUN: |
| 2296 | retry = 1; |
| 2297 | break; |
| 2298 | case IOACCEL2_STATUS_SR_UNDERRUN: |
| 2299 | cmd->result = (DID_OK << 16); /* host byte */ |
| 2300 | cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ |
| 2301 | ioaccel2_resid = get_unaligned_le32( |
| 2302 | &c2->error_data.resid_cnt[0]); |
| 2303 | scsi_set_resid(cmd, ioaccel2_resid); |
| 2304 | break; |
| 2305 | case IOACCEL2_STATUS_SR_NO_PATH_TO_DEVICE: |
| 2306 | case IOACCEL2_STATUS_SR_INVALID_DEVICE: |
| 2307 | case IOACCEL2_STATUS_SR_IOACCEL_DISABLED: |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 2308 | /* |
| 2309 | * Did an HBA disk disappear? We will eventually |
| 2310 | * get a state change event from the controller but |
| 2311 | * in the meantime, we need to tell the OS that the |
| 2312 | * HBA disk is no longer there and stop I/O |
| 2313 | * from going down. This allows the potential re-insert |
| 2314 | * of the disk to get the same device node. |
| 2315 | */ |
| 2316 | if (dev->physical_device && dev->expose_device) { |
| 2317 | cmd->result = DID_NO_CONNECT << 16; |
| 2318 | dev->removed = 1; |
| 2319 | h->drv_req_rescan = 1; |
| 2320 | dev_warn(&h->pdev->dev, |
| 2321 | "%s: device is gone!\n", __func__); |
| 2322 | } else |
| 2323 | /* |
| 2324 | * Retry by sending down the RAID path. |
| 2325 | * We will get an event from ctlr to |
| 2326 | * trigger rescan regardless. |
| 2327 | */ |
| 2328 | retry = 1; |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2329 | break; |
| 2330 | default: |
| 2331 | retry = 1; |
Joe Handzik | c40820d | 2015-04-23 09:33:32 -0500 | [diff] [blame] | 2332 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2333 | break; |
| 2334 | case IOACCEL2_SERV_RESPONSE_TMF_COMPLETE: |
| 2335 | break; |
| 2336 | case IOACCEL2_SERV_RESPONSE_TMF_SUCCESS: |
| 2337 | break; |
| 2338 | case IOACCEL2_SERV_RESPONSE_TMF_REJECTED: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2339 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2340 | break; |
| 2341 | case IOACCEL2_SERV_RESPONSE_TMF_WRONG_LUN: |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2342 | break; |
| 2343 | default: |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2344 | retry = 1; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2345 | break; |
| 2346 | } |
Scott Teel | a09c144 | 2014-02-18 13:57:21 -0600 | [diff] [blame] | 2347 | |
| 2348 | return retry; /* retry on raid path? */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2349 | } |
| 2350 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2351 | static void hpsa_cmd_resolve_events(struct ctlr_info *h, |
| 2352 | struct CommandList *c) |
| 2353 | { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2354 | bool do_wake = false; |
| 2355 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2356 | /* |
| 2357 | * Prevent the following race in the abort handler: |
| 2358 | * |
| 2359 | * 1. LLD is requested to abort a SCSI command |
| 2360 | * 2. The SCSI command completes |
| 2361 | * 3. The struct CommandList associated with step 2 is made available |
| 2362 | * 4. New I/O request to LLD to another LUN re-uses struct CommandList |
| 2363 | * 5. Abort handler follows scsi_cmnd->host_scribble and |
| 2364 | * finds struct CommandList and tries to aborts it |
| 2365 | * Now we have aborted the wrong command. |
| 2366 | * |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2367 | * Reset c->scsi_cmd here so that the abort or reset handler will know |
| 2368 | * this command has completed. Then, check to see if the handler is |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2369 | * waiting for this command, and, if so, wake it. |
| 2370 | */ |
| 2371 | c->scsi_cmd = SCSI_CMD_IDLE; |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2372 | mb(); /* Declare command idle before checking for pending events. */ |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2373 | if (c->abort_pending) { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2374 | do_wake = true; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2375 | c->abort_pending = false; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2376 | } |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2377 | if (c->reset_pending) { |
| 2378 | unsigned long flags; |
| 2379 | struct hpsa_scsi_dev_t *dev; |
| 2380 | |
| 2381 | /* |
| 2382 | * There appears to be a reset pending; lock the lock and |
| 2383 | * reconfirm. If so, then decrement the count of outstanding |
| 2384 | * commands and wake the reset command if this is the last one. |
| 2385 | */ |
| 2386 | spin_lock_irqsave(&h->lock, flags); |
| 2387 | dev = c->reset_pending; /* Re-fetch under the lock. */ |
| 2388 | if (dev && atomic_dec_and_test(&dev->reset_cmds_out)) |
| 2389 | do_wake = true; |
| 2390 | c->reset_pending = NULL; |
| 2391 | spin_unlock_irqrestore(&h->lock, flags); |
| 2392 | } |
| 2393 | |
| 2394 | if (do_wake) |
| 2395 | wake_up_all(&h->event_sync_wait_queue); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2396 | } |
| 2397 | |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 2398 | static void hpsa_cmd_resolve_and_free(struct ctlr_info *h, |
| 2399 | struct CommandList *c) |
| 2400 | { |
| 2401 | hpsa_cmd_resolve_events(h, c); |
| 2402 | cmd_tagged_free(h, c); |
| 2403 | } |
| 2404 | |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2405 | static void hpsa_cmd_free_and_done(struct ctlr_info *h, |
| 2406 | struct CommandList *c, struct scsi_cmnd *cmd) |
| 2407 | { |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 2408 | hpsa_cmd_resolve_and_free(h, c); |
Don Brace | d49c207 | 2016-09-09 16:30:23 -0500 | [diff] [blame] | 2409 | if (cmd && cmd->scsi_done) |
| 2410 | cmd->scsi_done(cmd); |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | static void hpsa_retry_cmd(struct ctlr_info *h, struct CommandList *c) |
| 2414 | { |
| 2415 | INIT_WORK(&c->work, hpsa_command_resubmit_worker); |
| 2416 | queue_work_on(raw_smp_processor_id(), h->resubmit_wq, &c->work); |
| 2417 | } |
| 2418 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2419 | static void hpsa_set_scsi_cmd_aborted(struct scsi_cmnd *cmd) |
| 2420 | { |
| 2421 | cmd->result = DID_ABORT << 16; |
| 2422 | } |
| 2423 | |
| 2424 | static void hpsa_cmd_abort_and_free(struct ctlr_info *h, struct CommandList *c, |
| 2425 | struct scsi_cmnd *cmd) |
| 2426 | { |
| 2427 | hpsa_set_scsi_cmd_aborted(cmd); |
| 2428 | dev_warn(&h->pdev->dev, "CDB %16phN was aborted with status 0x%x\n", |
| 2429 | c->Request.CDB, c->err_info->ScsiStatus); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 2430 | hpsa_cmd_resolve_and_free(h, c); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2431 | } |
| 2432 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2433 | static void process_ioaccel2_completion(struct ctlr_info *h, |
| 2434 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 2435 | struct hpsa_scsi_dev_t *dev) |
| 2436 | { |
| 2437 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 2438 | |
| 2439 | /* check for good status */ |
| 2440 | if (likely(c2->error_data.serv_response == 0 && |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2441 | c2->error_data.status == 0)) |
| 2442 | return hpsa_cmd_free_and_done(h, c, cmd); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2443 | |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2444 | /* |
| 2445 | * Any RAID offload error results in retry which will use |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2446 | * the normal I/O path so the controller can handle whatever's |
| 2447 | * wrong. |
| 2448 | */ |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 2449 | if (is_logical_device(dev) && |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2450 | c2->error_data.serv_response == |
| 2451 | IOACCEL2_SERV_RESPONSE_FAILURE) { |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2452 | if (c2->error_data.status == |
Don Brace | 064d1b1 | 2016-04-27 17:14:07 -0500 | [diff] [blame] | 2453 | IOACCEL2_STATUS_SR_IOACCEL_DISABLED) { |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2454 | dev->offload_enabled = 0; |
Don Brace | 064d1b1 | 2016-04-27 17:14:07 -0500 | [diff] [blame] | 2455 | dev->offload_to_be_enabled = 0; |
| 2456 | } |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2457 | |
| 2458 | return hpsa_retry_cmd(h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2459 | } |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2460 | |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 2461 | if (handle_ioaccel_mode2_error(h, c, cmd, c2, dev)) |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2462 | return hpsa_retry_cmd(h, c); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 2463 | |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2464 | return hpsa_cmd_free_and_done(h, c, cmd); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2465 | } |
| 2466 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2467 | /* Returns 0 on success, < 0 otherwise. */ |
| 2468 | static int hpsa_evaluate_tmf_status(struct ctlr_info *h, |
| 2469 | struct CommandList *cp) |
| 2470 | { |
| 2471 | u8 tmf_status = cp->err_info->ScsiStatus; |
| 2472 | |
| 2473 | switch (tmf_status) { |
| 2474 | case CISS_TMF_COMPLETE: |
| 2475 | /* |
| 2476 | * CISS_TMF_COMPLETE never happens, instead, |
| 2477 | * ei->CommandStatus == 0 for this case. |
| 2478 | */ |
| 2479 | case CISS_TMF_SUCCESS: |
| 2480 | return 0; |
| 2481 | case CISS_TMF_INVALID_FRAME: |
| 2482 | case CISS_TMF_NOT_SUPPORTED: |
| 2483 | case CISS_TMF_FAILED: |
| 2484 | case CISS_TMF_WRONG_LUN: |
| 2485 | case CISS_TMF_OVERLAPPED_TAG: |
| 2486 | break; |
| 2487 | default: |
| 2488 | dev_warn(&h->pdev->dev, "Unknown TMF status: 0x%02x\n", |
| 2489 | tmf_status); |
| 2490 | break; |
| 2491 | } |
| 2492 | return -tmf_status; |
| 2493 | } |
| 2494 | |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 2495 | static void complete_scsi_command(struct CommandList *cp) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2496 | { |
| 2497 | struct scsi_cmnd *cmd; |
| 2498 | struct ctlr_info *h; |
| 2499 | struct ErrorInfo *ei; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2500 | struct hpsa_scsi_dev_t *dev; |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2501 | struct io_accel2_cmd *c2; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2502 | |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2503 | u8 sense_key; |
| 2504 | u8 asc; /* additional sense code */ |
| 2505 | u8 ascq; /* additional sense code qualifier */ |
Stephen M. Cameron | db111e1 | 2011-06-03 09:57:34 -0500 | [diff] [blame] | 2506 | unsigned long sense_data_size; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2507 | |
| 2508 | ei = cp->err_info; |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 2509 | cmd = cp->scsi_cmd; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2510 | h = cp->h; |
Don Brace | d49c207 | 2016-09-09 16:30:23 -0500 | [diff] [blame] | 2511 | |
| 2512 | if (!cmd->device) { |
| 2513 | cmd->result = DID_NO_CONNECT << 16; |
| 2514 | return hpsa_cmd_free_and_done(h, cp, cmd); |
| 2515 | } |
| 2516 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2517 | dev = cmd->device->hostdata; |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 2518 | if (!dev) { |
| 2519 | cmd->result = DID_NO_CONNECT << 16; |
| 2520 | return hpsa_cmd_free_and_done(h, cp, cmd); |
| 2521 | } |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2522 | c2 = &h->ioaccel2_cmd_pool[cp->cmdindex]; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2523 | |
| 2524 | scsi_dma_unmap(cmd); /* undo the DMA mappings */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2525 | if ((cp->cmd_type == CMD_SCSI) && |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2526 | (le16_to_cpu(cp->Header.SGTotal) > h->max_cmd_sg_entries)) |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 2527 | hpsa_unmap_sg_chain_block(h, cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2528 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 2529 | if ((cp->cmd_type == CMD_IOACCEL2) && |
| 2530 | (c2->sg[0].chain_indicator == IOACCEL2_CHAIN)) |
| 2531 | hpsa_unmap_ioaccel2_sg_chain_block(h, c2); |
| 2532 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2533 | cmd->result = (DID_OK << 16); /* host byte */ |
| 2534 | cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2535 | |
Don Brace | d49c207 | 2016-09-09 16:30:23 -0500 | [diff] [blame] | 2536 | if (cp->cmd_type == CMD_IOACCEL2 || cp->cmd_type == CMD_IOACCEL1) { |
| 2537 | if (dev->physical_device && dev->expose_device && |
| 2538 | dev->removed) { |
| 2539 | cmd->result = DID_NO_CONNECT << 16; |
| 2540 | return hpsa_cmd_free_and_done(h, cp, cmd); |
| 2541 | } |
| 2542 | if (likely(cp->phys_disk != NULL)) |
| 2543 | atomic_dec(&cp->phys_disk->ioaccel_cmds_out); |
| 2544 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 2545 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2546 | /* |
| 2547 | * We check for lockup status here as it may be set for |
| 2548 | * CMD_SCSI, CMD_IOACCEL1 and CMD_IOACCEL2 commands by |
| 2549 | * fail_all_oustanding_cmds() |
| 2550 | */ |
| 2551 | if (unlikely(ei->CommandStatus == CMD_CTLR_LOCKUP)) { |
| 2552 | /* DID_NO_CONNECT will prevent a retry */ |
| 2553 | cmd->result = DID_NO_CONNECT << 16; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2554 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2555 | } |
| 2556 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2557 | if ((unlikely(hpsa_is_pending_event(cp)))) { |
| 2558 | if (cp->reset_pending) |
Don Brace | bfd7546 | 2016-11-15 14:45:32 -0600 | [diff] [blame] | 2559 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2560 | if (cp->abort_pending) |
| 2561 | return hpsa_cmd_abort_and_free(h, cp, cmd); |
| 2562 | } |
| 2563 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 2564 | if (cp->cmd_type == CMD_IOACCEL2) |
| 2565 | return process_ioaccel2_completion(h, cp, cmd, dev); |
| 2566 | |
Robert Elliott | 6aa4c36 | 2014-07-03 10:18:19 -0500 | [diff] [blame] | 2567 | scsi_set_resid(cmd, ei->ResidualCnt); |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2568 | if (ei->CommandStatus == 0) |
| 2569 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Robert Elliott | 6aa4c36 | 2014-07-03 10:18:19 -0500 | [diff] [blame] | 2570 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2571 | /* For I/O accelerator commands, copy over some fields to the normal |
| 2572 | * CISS header used below for error handling. |
| 2573 | */ |
| 2574 | if (cp->cmd_type == CMD_IOACCEL1) { |
| 2575 | struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex]; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 2576 | cp->Header.SGList = scsi_sg_count(cmd); |
| 2577 | cp->Header.SGTotal = cpu_to_le16(cp->Header.SGList); |
| 2578 | cp->Request.CDBLen = le16_to_cpu(c->io_flags) & |
| 2579 | IOACCEL1_IOFLAGS_CDBLEN_MASK; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2580 | cp->Header.tag = c->tag; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2581 | memcpy(cp->Header.LUN.LunAddrBytes, c->CISS_LUN, 8); |
| 2582 | memcpy(cp->Request.CDB, c->CDB, cp->Request.CDBLen); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2583 | |
| 2584 | /* Any RAID offload error results in retry which will use |
| 2585 | * the normal I/O path so the controller can handle whatever's |
| 2586 | * wrong. |
| 2587 | */ |
Kevin Barnett | f3f0173 | 2015-11-04 15:51:33 -0600 | [diff] [blame] | 2588 | if (is_logical_device(dev)) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2589 | if (ei->CommandStatus == CMD_IOACCEL_DISABLED) |
| 2590 | dev->offload_enabled = 0; |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2591 | return hpsa_retry_cmd(h, cp); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2592 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 2593 | } |
| 2594 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2595 | /* an error has occurred */ |
| 2596 | switch (ei->CommandStatus) { |
| 2597 | |
| 2598 | case CMD_TARGET_STATUS: |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2599 | cmd->result |= ei->ScsiStatus; |
| 2600 | /* copy the sense data */ |
| 2601 | if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo)) |
| 2602 | sense_data_size = SCSI_SENSE_BUFFERSIZE; |
| 2603 | else |
| 2604 | sense_data_size = sizeof(ei->SenseInfo); |
| 2605 | if (ei->SenseLen < sense_data_size) |
| 2606 | sense_data_size = ei->SenseLen; |
| 2607 | memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size); |
| 2608 | if (ei->ScsiStatus) |
| 2609 | decode_sense_data(ei->SenseInfo, sense_data_size, |
| 2610 | &sense_key, &asc, &ascq); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2611 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) { |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 2612 | if (sense_key == ABORTED_COMMAND) { |
Stephen M. Cameron | 2e311fb | 2013-09-23 13:33:41 -0500 | [diff] [blame] | 2613 | cmd->result |= DID_SOFT_ERROR << 16; |
Matt Gates | 1d3b360 | 2010-02-04 08:43:00 -0600 | [diff] [blame] | 2614 | break; |
| 2615 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2616 | break; |
| 2617 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2618 | /* Problem was not a check condition |
| 2619 | * Pass it up to the upper layers... |
| 2620 | */ |
| 2621 | if (ei->ScsiStatus) { |
| 2622 | dev_warn(&h->pdev->dev, "cp %p has status 0x%x " |
| 2623 | "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " |
| 2624 | "Returning result: 0x%x\n", |
| 2625 | cp, ei->ScsiStatus, |
| 2626 | sense_key, asc, ascq, |
| 2627 | cmd->result); |
| 2628 | } else { /* scsi status is zero??? How??? */ |
| 2629 | dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. " |
| 2630 | "Returning no connection.\n", cp), |
| 2631 | |
| 2632 | /* Ordinarily, this case should never happen, |
| 2633 | * but there is a bug in some released firmware |
| 2634 | * revisions that allows it to happen if, for |
| 2635 | * example, a 4100 backplane loses power and |
| 2636 | * the tape drive is in it. We assume that |
| 2637 | * it's a fatal error of some kind because we |
| 2638 | * can't show that it wasn't. We will make it |
| 2639 | * look like selection timeout since that is |
| 2640 | * the most common reason for this to occur, |
| 2641 | * and it's severe enough. |
| 2642 | */ |
| 2643 | |
| 2644 | cmd->result = DID_NO_CONNECT << 16; |
| 2645 | } |
| 2646 | break; |
| 2647 | |
| 2648 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
| 2649 | break; |
| 2650 | case CMD_DATA_OVERRUN: |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2651 | dev_warn(&h->pdev->dev, |
| 2652 | "CDB %16phN data overrun\n", cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2653 | break; |
| 2654 | case CMD_INVALID: { |
| 2655 | /* print_bytes(cp, sizeof(*cp), 1, 0); |
| 2656 | print_cmd(cp); */ |
| 2657 | /* We get CMD_INVALID if you address a non-existent device |
| 2658 | * instead of a selection timeout (no response). You will |
| 2659 | * see this if you yank out a drive, then try to access it. |
| 2660 | * This is kind of a shame because it means that any other |
| 2661 | * CMD_INVALID (e.g. driver bug) will get interpreted as a |
| 2662 | * missing target. */ |
| 2663 | cmd->result = DID_NO_CONNECT << 16; |
| 2664 | } |
| 2665 | break; |
| 2666 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | 256d0ea | 2012-09-14 16:34:25 -0500 | [diff] [blame] | 2667 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2668 | dev_warn(&h->pdev->dev, "CDB %16phN : protocol error\n", |
| 2669 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2670 | break; |
| 2671 | case CMD_HARDWARE_ERR: |
| 2672 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2673 | dev_warn(&h->pdev->dev, "CDB %16phN : hardware error\n", |
| 2674 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2675 | break; |
| 2676 | case CMD_CONNECTION_LOST: |
| 2677 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2678 | dev_warn(&h->pdev->dev, "CDB %16phN : connection lost\n", |
| 2679 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2680 | break; |
| 2681 | case CMD_ABORTED: |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 2682 | /* Return now to avoid calling scsi_done(). */ |
| 2683 | return hpsa_cmd_abort_and_free(h, cp, cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2684 | case CMD_ABORT_FAILED: |
| 2685 | cmd->result = DID_ERROR << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2686 | dev_warn(&h->pdev->dev, "CDB %16phN : abort failed\n", |
| 2687 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2688 | break; |
| 2689 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | f6e7605 | 2011-07-26 11:08:52 -0500 | [diff] [blame] | 2690 | cmd->result = DID_SOFT_ERROR << 16; /* retry the command */ |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2691 | dev_warn(&h->pdev->dev, "CDB %16phN : unsolicited abort\n", |
| 2692 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2693 | break; |
| 2694 | case CMD_TIMEOUT: |
| 2695 | cmd->result = DID_TIME_OUT << 16; |
Stephen Cameron | f42e81e | 2015-01-23 16:44:35 -0600 | [diff] [blame] | 2696 | dev_warn(&h->pdev->dev, "CDB %16phN timed out\n", |
| 2697 | cp->Request.CDB); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2698 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2699 | case CMD_UNABORTABLE: |
| 2700 | cmd->result = DID_ERROR << 16; |
| 2701 | dev_warn(&h->pdev->dev, "Command unabortable\n"); |
| 2702 | break; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2703 | case CMD_TMF_STATUS: |
| 2704 | if (hpsa_evaluate_tmf_status(h, cp)) /* TMF failed? */ |
| 2705 | cmd->result = DID_ERROR << 16; |
| 2706 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 2707 | case CMD_IOACCEL_DISABLED: |
| 2708 | /* This only handles the direct pass-through case since RAID |
| 2709 | * offload is handled above. Just attempt a retry. |
| 2710 | */ |
| 2711 | cmd->result = DID_SOFT_ERROR << 16; |
| 2712 | dev_warn(&h->pdev->dev, |
| 2713 | "cp %p had HP SSD Smart Path error\n", cp); |
| 2714 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2715 | default: |
| 2716 | cmd->result = DID_ERROR << 16; |
| 2717 | dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n", |
| 2718 | cp, ei->CommandStatus); |
| 2719 | } |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 2720 | |
| 2721 | return hpsa_cmd_free_and_done(h, cp, cmd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2722 | } |
| 2723 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2724 | static void hpsa_pci_unmap(struct pci_dev *pdev, |
| 2725 | struct CommandList *c, int sg_used, int data_direction) |
| 2726 | { |
| 2727 | int i; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2728 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2729 | for (i = 0; i < sg_used; i++) |
| 2730 | pci_unmap_single(pdev, (dma_addr_t) le64_to_cpu(c->SG[i].Addr), |
| 2731 | le32_to_cpu(c->SG[i].Len), |
| 2732 | data_direction); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2733 | } |
| 2734 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2735 | static int hpsa_map_one(struct pci_dev *pdev, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2736 | struct CommandList *cp, |
| 2737 | unsigned char *buf, |
| 2738 | size_t buflen, |
| 2739 | int data_direction) |
| 2740 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 2741 | u64 addr64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2742 | |
| 2743 | if (buflen == 0 || data_direction == PCI_DMA_NONE) { |
| 2744 | cp->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2745 | cp->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2746 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2749 | addr64 = pci_map_single(pdev, buf, buflen, data_direction); |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2750 | if (dma_mapping_error(&pdev->dev, addr64)) { |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2751 | /* Prevent subsequent unmap of something never mapped */ |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2752 | cp->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2753 | cp->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2754 | return -1; |
Shuah Khan | eceaae1 | 2013-02-20 11:24:34 -0600 | [diff] [blame] | 2755 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 2756 | cp->SG[0].Addr = cpu_to_le64(addr64); |
| 2757 | cp->SG[0].Len = cpu_to_le32(buflen); |
| 2758 | cp->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* we are not chaining */ |
| 2759 | cp->Header.SGList = 1; /* no. SGs contig in this cmd */ |
| 2760 | 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] | 2761 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2762 | } |
| 2763 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2764 | #define NO_TIMEOUT ((unsigned long) -1) |
| 2765 | #define DEFAULT_TIMEOUT 30000 /* milliseconds */ |
| 2766 | static int hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h, |
| 2767 | struct CommandList *c, int reply_queue, unsigned long timeout_msecs) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2768 | { |
| 2769 | DECLARE_COMPLETION_ONSTACK(wait); |
| 2770 | |
| 2771 | c->waiting = &wait; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2772 | __enqueue_cmd_and_start_io(h, c, reply_queue); |
| 2773 | if (timeout_msecs == NO_TIMEOUT) { |
| 2774 | /* TODO: get rid of this no-timeout thing */ |
| 2775 | wait_for_completion_io(&wait); |
| 2776 | return IO_OK; |
| 2777 | } |
| 2778 | if (!wait_for_completion_io_timeout(&wait, |
| 2779 | msecs_to_jiffies(timeout_msecs))) { |
| 2780 | dev_warn(&h->pdev->dev, "Command timed out.\n"); |
| 2781 | return -ETIMEDOUT; |
| 2782 | } |
| 2783 | return IO_OK; |
| 2784 | } |
| 2785 | |
| 2786 | static int hpsa_scsi_do_simple_cmd(struct ctlr_info *h, struct CommandList *c, |
| 2787 | int reply_queue, unsigned long timeout_msecs) |
| 2788 | { |
| 2789 | if (unlikely(lockup_detected(h))) { |
| 2790 | c->err_info->CommandStatus = CMD_CTLR_LOCKUP; |
| 2791 | return IO_OK; |
| 2792 | } |
| 2793 | 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] | 2794 | } |
| 2795 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 2796 | static u32 lockup_detected(struct ctlr_info *h) |
| 2797 | { |
| 2798 | int cpu; |
| 2799 | u32 rc, *lockup_detected; |
| 2800 | |
| 2801 | cpu = get_cpu(); |
| 2802 | lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); |
| 2803 | rc = *lockup_detected; |
| 2804 | put_cpu(); |
| 2805 | return rc; |
| 2806 | } |
| 2807 | |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2808 | #define MAX_DRIVER_CMD_RETRIES 25 |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2809 | static int hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, |
| 2810 | struct CommandList *c, int data_direction, unsigned long timeout_msecs) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2811 | { |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2812 | int backoff_time = 10, retry_count = 0; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2813 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2814 | |
| 2815 | do { |
Joe Perches | 7630abd | 2011-05-08 23:32:40 -0700 | [diff] [blame] | 2816 | memset(c->err_info, 0, sizeof(*c->err_info)); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2817 | rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, |
| 2818 | timeout_msecs); |
| 2819 | if (rc) |
| 2820 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2821 | retry_count++; |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2822 | if (retry_count > 3) { |
| 2823 | msleep(backoff_time); |
| 2824 | if (backoff_time < 1000) |
| 2825 | backoff_time *= 2; |
| 2826 | } |
Matt Bondurant | 852af20 | 2012-05-01 11:42:35 -0500 | [diff] [blame] | 2827 | } while ((check_for_unit_attention(h, c) || |
Stephen M. Cameron | 9c2fc16 | 2012-05-01 11:42:40 -0500 | [diff] [blame] | 2828 | check_for_busy(h, c)) && |
| 2829 | retry_count <= MAX_DRIVER_CMD_RETRIES); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2830 | hpsa_pci_unmap(h->pdev, c, 1, data_direction); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2831 | if (retry_count > MAX_DRIVER_CMD_RETRIES) |
| 2832 | rc = -EIO; |
| 2833 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2834 | } |
| 2835 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2836 | static void hpsa_print_cmd(struct ctlr_info *h, char *txt, |
| 2837 | struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2838 | { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2839 | const u8 *cdb = c->Request.CDB; |
| 2840 | const u8 *lun = c->Header.LUN.LunAddrBytes; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2841 | |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2842 | dev_warn(&h->pdev->dev, "%s: LUN:%02x%02x%02x%02x%02x%02x%02x%02x" |
| 2843 | " CDB:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 2844 | txt, lun[0], lun[1], lun[2], lun[3], |
| 2845 | lun[4], lun[5], lun[6], lun[7], |
| 2846 | cdb[0], cdb[1], cdb[2], cdb[3], |
| 2847 | cdb[4], cdb[5], cdb[6], cdb[7], |
| 2848 | cdb[8], cdb[9], cdb[10], cdb[11], |
| 2849 | cdb[12], cdb[13], cdb[14], cdb[15]); |
| 2850 | } |
| 2851 | |
| 2852 | static void hpsa_scsi_interpret_error(struct ctlr_info *h, |
| 2853 | struct CommandList *cp) |
| 2854 | { |
| 2855 | const struct ErrorInfo *ei = cp->err_info; |
| 2856 | struct device *d = &cp->h->pdev->dev; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2857 | u8 sense_key, asc, ascq; |
| 2858 | int sense_len; |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2859 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2860 | switch (ei->CommandStatus) { |
| 2861 | case CMD_TARGET_STATUS: |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2862 | if (ei->SenseLen > sizeof(ei->SenseInfo)) |
| 2863 | sense_len = sizeof(ei->SenseInfo); |
| 2864 | else |
| 2865 | sense_len = ei->SenseLen; |
| 2866 | decode_sense_data(ei->SenseInfo, sense_len, |
| 2867 | &sense_key, &asc, &ascq); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2868 | hpsa_print_cmd(h, "SCSI status", cp); |
| 2869 | if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2870 | dev_warn(d, "SCSI Status = 02, Sense key = 0x%02x, ASC = 0x%02x, ASCQ = 0x%02x\n", |
| 2871 | sense_key, asc, ascq); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2872 | else |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 2873 | dev_warn(d, "SCSI Status = 0x%02x\n", ei->ScsiStatus); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2874 | if (ei->ScsiStatus == 0) |
| 2875 | dev_warn(d, "SCSI status is abnormally zero. " |
| 2876 | "(probably indicates selection timeout " |
| 2877 | "reported incorrectly due to a known " |
| 2878 | "firmware bug, circa July, 2001.)\n"); |
| 2879 | break; |
| 2880 | case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2881 | break; |
| 2882 | case CMD_DATA_OVERRUN: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2883 | hpsa_print_cmd(h, "overrun condition", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2884 | break; |
| 2885 | case CMD_INVALID: { |
| 2886 | /* controller unfortunately reports SCSI passthru's |
| 2887 | * to non-existent targets as invalid commands. |
| 2888 | */ |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2889 | hpsa_print_cmd(h, "invalid command", cp); |
| 2890 | dev_warn(d, "probably means device no longer present\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2891 | } |
| 2892 | break; |
| 2893 | case CMD_PROTOCOL_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2894 | hpsa_print_cmd(h, "protocol error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2895 | break; |
| 2896 | case CMD_HARDWARE_ERR: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2897 | hpsa_print_cmd(h, "hardware error", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2898 | break; |
| 2899 | case CMD_CONNECTION_LOST: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2900 | hpsa_print_cmd(h, "connection lost", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2901 | break; |
| 2902 | case CMD_ABORTED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2903 | hpsa_print_cmd(h, "aborted", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2904 | break; |
| 2905 | case CMD_ABORT_FAILED: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2906 | hpsa_print_cmd(h, "abort failed", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2907 | break; |
| 2908 | case CMD_UNSOLICITED_ABORT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2909 | hpsa_print_cmd(h, "unsolicited abort", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2910 | break; |
| 2911 | case CMD_TIMEOUT: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2912 | hpsa_print_cmd(h, "timed out", cp); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2913 | break; |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2914 | case CMD_UNABORTABLE: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2915 | hpsa_print_cmd(h, "unabortable", cp); |
Stephen M. Cameron | 1d5e2ed | 2011-01-07 10:55:48 -0600 | [diff] [blame] | 2916 | break; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2917 | case CMD_CTLR_LOCKUP: |
| 2918 | hpsa_print_cmd(h, "controller lockup detected", cp); |
| 2919 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2920 | default: |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2921 | hpsa_print_cmd(h, "unknown status", cp); |
| 2922 | dev_warn(d, "Unknown command status %x\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2923 | ei->CommandStatus); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | 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] | 2928 | u16 page, unsigned char *buf, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2929 | unsigned char bufsize) |
| 2930 | { |
| 2931 | int rc = IO_OK; |
| 2932 | struct CommandList *c; |
| 2933 | struct ErrorInfo *ei; |
| 2934 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2935 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2936 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2937 | if (fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize, |
| 2938 | page, scsi3addr, TYPE_CMD)) { |
| 2939 | rc = -1; |
| 2940 | goto out; |
| 2941 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2942 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 2943 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2944 | if (rc) |
| 2945 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2946 | ei = c->err_info; |
| 2947 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2948 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2949 | rc = -1; |
| 2950 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2951 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2952 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2953 | return rc; |
| 2954 | } |
| 2955 | |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2956 | static int hpsa_send_reset(struct ctlr_info *h, unsigned char *scsi3addr, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2957 | u8 reset_type, int reply_queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2958 | { |
| 2959 | int rc = IO_OK; |
| 2960 | struct CommandList *c; |
| 2961 | struct ErrorInfo *ei; |
| 2962 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2963 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2964 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2965 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 2966 | /* fill_cmd can't fail here, no data buffer to map. */ |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 2967 | (void) fill_cmd(c, reset_type, h, NULL, 0, 0, |
Scott Teel | bf711ac | 2014-02-18 13:56:39 -0600 | [diff] [blame] | 2968 | scsi3addr, TYPE_MSG); |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 2969 | rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, DEFAULT_TIMEOUT); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2970 | if (rc) { |
| 2971 | dev_warn(&h->pdev->dev, "Failed to send reset command\n"); |
| 2972 | goto out; |
| 2973 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2974 | /* no unmap needed here because no data xfer. */ |
| 2975 | |
| 2976 | ei = c->err_info; |
| 2977 | if (ei->CommandStatus != 0) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 2978 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2979 | rc = -1; |
| 2980 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 2981 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 2982 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 2983 | return rc; |
| 2984 | } |
| 2985 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 2986 | static bool hpsa_cmd_dev_match(struct ctlr_info *h, struct CommandList *c, |
| 2987 | struct hpsa_scsi_dev_t *dev, |
| 2988 | unsigned char *scsi3addr) |
| 2989 | { |
| 2990 | int i; |
| 2991 | bool match = false; |
| 2992 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 2993 | struct hpsa_tmf_struct *ac = (struct hpsa_tmf_struct *) c2; |
| 2994 | |
| 2995 | if (hpsa_is_cmd_idle(c)) |
| 2996 | return false; |
| 2997 | |
| 2998 | switch (c->cmd_type) { |
| 2999 | case CMD_SCSI: |
| 3000 | case CMD_IOCTL_PEND: |
| 3001 | match = !memcmp(scsi3addr, &c->Header.LUN.LunAddrBytes, |
| 3002 | sizeof(c->Header.LUN.LunAddrBytes)); |
| 3003 | break; |
| 3004 | |
| 3005 | case CMD_IOACCEL1: |
| 3006 | case CMD_IOACCEL2: |
| 3007 | if (c->phys_disk == dev) { |
| 3008 | /* HBA mode match */ |
| 3009 | match = true; |
| 3010 | } else { |
| 3011 | /* Possible RAID mode -- check each phys dev. */ |
| 3012 | /* FIXME: Do we need to take out a lock here? If |
| 3013 | * so, we could just call hpsa_get_pdisk_of_ioaccel2() |
| 3014 | * instead. */ |
| 3015 | for (i = 0; i < dev->nphysical_disks && !match; i++) { |
| 3016 | /* FIXME: an alternate test might be |
| 3017 | * |
| 3018 | * match = dev->phys_disk[i]->ioaccel_handle |
| 3019 | * == c2->scsi_nexus; */ |
| 3020 | match = dev->phys_disk[i] == c->phys_disk; |
| 3021 | } |
| 3022 | } |
| 3023 | break; |
| 3024 | |
| 3025 | case IOACCEL2_TMF: |
| 3026 | for (i = 0; i < dev->nphysical_disks && !match; i++) { |
| 3027 | match = dev->phys_disk[i]->ioaccel_handle == |
| 3028 | le32_to_cpu(ac->it_nexus); |
| 3029 | } |
| 3030 | break; |
| 3031 | |
| 3032 | case 0: /* The command is in the middle of being initialized. */ |
| 3033 | match = false; |
| 3034 | break; |
| 3035 | |
| 3036 | default: |
| 3037 | dev_err(&h->pdev->dev, "unexpected cmd_type: %d\n", |
| 3038 | c->cmd_type); |
| 3039 | BUG(); |
| 3040 | } |
| 3041 | |
| 3042 | return match; |
| 3043 | } |
| 3044 | |
| 3045 | static int hpsa_do_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev, |
| 3046 | unsigned char *scsi3addr, u8 reset_type, int reply_queue) |
| 3047 | { |
| 3048 | int i; |
| 3049 | int rc = 0; |
| 3050 | |
| 3051 | /* We can really only handle one reset at a time */ |
| 3052 | if (mutex_lock_interruptible(&h->reset_mutex) == -EINTR) { |
| 3053 | dev_warn(&h->pdev->dev, "concurrent reset wait interrupted.\n"); |
| 3054 | return -EINTR; |
| 3055 | } |
| 3056 | |
| 3057 | BUG_ON(atomic_read(&dev->reset_cmds_out) != 0); |
| 3058 | |
| 3059 | for (i = 0; i < h->nr_cmds; i++) { |
| 3060 | struct CommandList *c = h->cmd_pool + i; |
| 3061 | int refcount = atomic_inc_return(&c->refcount); |
| 3062 | |
| 3063 | if (refcount > 1 && hpsa_cmd_dev_match(h, c, dev, scsi3addr)) { |
| 3064 | unsigned long flags; |
| 3065 | |
| 3066 | /* |
| 3067 | * Mark the target command as having a reset pending, |
| 3068 | * then lock a lock so that the command cannot complete |
| 3069 | * while we're considering it. If the command is not |
| 3070 | * idle then count it; otherwise revoke the event. |
| 3071 | */ |
| 3072 | c->reset_pending = dev; |
| 3073 | spin_lock_irqsave(&h->lock, flags); /* Implied MB */ |
| 3074 | if (!hpsa_is_cmd_idle(c)) |
| 3075 | atomic_inc(&dev->reset_cmds_out); |
| 3076 | else |
| 3077 | c->reset_pending = NULL; |
| 3078 | spin_unlock_irqrestore(&h->lock, flags); |
| 3079 | } |
| 3080 | |
| 3081 | cmd_free(h, c); |
| 3082 | } |
| 3083 | |
| 3084 | rc = hpsa_send_reset(h, scsi3addr, reset_type, reply_queue); |
| 3085 | if (!rc) |
| 3086 | wait_event(h->event_sync_wait_queue, |
| 3087 | atomic_read(&dev->reset_cmds_out) == 0 || |
| 3088 | lockup_detected(h)); |
| 3089 | |
| 3090 | if (unlikely(lockup_detected(h))) { |
Don Brace | 77678d3 | 2015-07-18 11:12:22 -0500 | [diff] [blame] | 3091 | dev_warn(&h->pdev->dev, |
| 3092 | "Controller lockup detected during reset wait\n"); |
| 3093 | rc = -ENODEV; |
| 3094 | } |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 3095 | |
| 3096 | if (unlikely(rc)) |
| 3097 | atomic_set(&dev->reset_cmds_out, 0); |
Don Brace | bfd7546 | 2016-11-15 14:45:32 -0600 | [diff] [blame] | 3098 | else |
| 3099 | wait_for_device_to_become_ready(h, scsi3addr, 0); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 3100 | |
| 3101 | mutex_unlock(&h->reset_mutex); |
| 3102 | return rc; |
| 3103 | } |
| 3104 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3105 | static void hpsa_get_raid_level(struct ctlr_info *h, |
| 3106 | unsigned char *scsi3addr, unsigned char *raid_level) |
| 3107 | { |
| 3108 | int rc; |
| 3109 | unsigned char *buf; |
| 3110 | |
| 3111 | *raid_level = RAID_UNKNOWN; |
| 3112 | buf = kzalloc(64, GFP_KERNEL); |
| 3113 | if (!buf) |
| 3114 | return; |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3115 | |
| 3116 | if (!hpsa_vpd_page_supported(h, scsi3addr, |
| 3117 | HPSA_VPD_LV_DEVICE_GEOMETRY)) |
| 3118 | goto exit; |
| 3119 | |
| 3120 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | |
| 3121 | HPSA_VPD_LV_DEVICE_GEOMETRY, buf, 64); |
| 3122 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3123 | if (rc == 0) |
| 3124 | *raid_level = buf[8]; |
| 3125 | if (*raid_level > RAID_UNKNOWN) |
| 3126 | *raid_level = RAID_UNKNOWN; |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3127 | exit: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3128 | kfree(buf); |
| 3129 | return; |
| 3130 | } |
| 3131 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3132 | #define HPSA_MAP_DEBUG |
| 3133 | #ifdef HPSA_MAP_DEBUG |
| 3134 | static void hpsa_debug_map_buff(struct ctlr_info *h, int rc, |
| 3135 | struct raid_map_data *map_buff) |
| 3136 | { |
| 3137 | struct raid_map_disk_data *dd = &map_buff->data[0]; |
| 3138 | int map, row, col; |
| 3139 | u16 map_cnt, row_cnt, disks_per_row; |
| 3140 | |
| 3141 | if (rc != 0) |
| 3142 | return; |
| 3143 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 3144 | /* Show details only if debugging has been activated. */ |
| 3145 | if (h->raid_offload_debug < 2) |
| 3146 | return; |
| 3147 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3148 | dev_info(&h->pdev->dev, "structure_size = %u\n", |
| 3149 | le32_to_cpu(map_buff->structure_size)); |
| 3150 | dev_info(&h->pdev->dev, "volume_blk_size = %u\n", |
| 3151 | le32_to_cpu(map_buff->volume_blk_size)); |
| 3152 | dev_info(&h->pdev->dev, "volume_blk_cnt = 0x%llx\n", |
| 3153 | le64_to_cpu(map_buff->volume_blk_cnt)); |
| 3154 | dev_info(&h->pdev->dev, "physicalBlockShift = %u\n", |
| 3155 | map_buff->phys_blk_shift); |
| 3156 | dev_info(&h->pdev->dev, "parity_rotation_shift = %u\n", |
| 3157 | map_buff->parity_rotation_shift); |
| 3158 | dev_info(&h->pdev->dev, "strip_size = %u\n", |
| 3159 | le16_to_cpu(map_buff->strip_size)); |
| 3160 | dev_info(&h->pdev->dev, "disk_starting_blk = 0x%llx\n", |
| 3161 | le64_to_cpu(map_buff->disk_starting_blk)); |
| 3162 | dev_info(&h->pdev->dev, "disk_blk_cnt = 0x%llx\n", |
| 3163 | le64_to_cpu(map_buff->disk_blk_cnt)); |
| 3164 | dev_info(&h->pdev->dev, "data_disks_per_row = %u\n", |
| 3165 | le16_to_cpu(map_buff->data_disks_per_row)); |
| 3166 | dev_info(&h->pdev->dev, "metadata_disks_per_row = %u\n", |
| 3167 | le16_to_cpu(map_buff->metadata_disks_per_row)); |
| 3168 | dev_info(&h->pdev->dev, "row_cnt = %u\n", |
| 3169 | le16_to_cpu(map_buff->row_cnt)); |
| 3170 | dev_info(&h->pdev->dev, "layout_map_count = %u\n", |
| 3171 | le16_to_cpu(map_buff->layout_map_count)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3172 | dev_info(&h->pdev->dev, "flags = 0x%x\n", |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3173 | le16_to_cpu(map_buff->flags)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 3174 | dev_info(&h->pdev->dev, "encrypytion = %s\n", |
| 3175 | le16_to_cpu(map_buff->flags) & |
| 3176 | RAID_MAP_FLAG_ENCRYPT_ON ? "ON" : "OFF"); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 3177 | dev_info(&h->pdev->dev, "dekindex = %u\n", |
| 3178 | le16_to_cpu(map_buff->dekindex)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3179 | map_cnt = le16_to_cpu(map_buff->layout_map_count); |
| 3180 | for (map = 0; map < map_cnt; map++) { |
| 3181 | dev_info(&h->pdev->dev, "Map%u:\n", map); |
| 3182 | row_cnt = le16_to_cpu(map_buff->row_cnt); |
| 3183 | for (row = 0; row < row_cnt; row++) { |
| 3184 | dev_info(&h->pdev->dev, " Row%u:\n", row); |
| 3185 | disks_per_row = |
| 3186 | le16_to_cpu(map_buff->data_disks_per_row); |
| 3187 | for (col = 0; col < disks_per_row; col++, dd++) |
| 3188 | dev_info(&h->pdev->dev, |
| 3189 | " D%02u: h=0x%04x xor=%u,%u\n", |
| 3190 | col, dd->ioaccel_handle, |
| 3191 | dd->xor_mult[0], dd->xor_mult[1]); |
| 3192 | disks_per_row = |
| 3193 | le16_to_cpu(map_buff->metadata_disks_per_row); |
| 3194 | for (col = 0; col < disks_per_row; col++, dd++) |
| 3195 | dev_info(&h->pdev->dev, |
| 3196 | " M%02u: h=0x%04x xor=%u,%u\n", |
| 3197 | col, dd->ioaccel_handle, |
| 3198 | dd->xor_mult[0], dd->xor_mult[1]); |
| 3199 | } |
| 3200 | } |
| 3201 | } |
| 3202 | #else |
| 3203 | static void hpsa_debug_map_buff(__attribute__((unused)) struct ctlr_info *h, |
| 3204 | __attribute__((unused)) int rc, |
| 3205 | __attribute__((unused)) struct raid_map_data *map_buff) |
| 3206 | { |
| 3207 | } |
| 3208 | #endif |
| 3209 | |
| 3210 | static int hpsa_get_raid_map(struct ctlr_info *h, |
| 3211 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 3212 | { |
| 3213 | int rc = 0; |
| 3214 | struct CommandList *c; |
| 3215 | struct ErrorInfo *ei; |
| 3216 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3217 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3218 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3219 | if (fill_cmd(c, HPSA_GET_RAID_MAP, h, &this_device->raid_map, |
| 3220 | sizeof(this_device->raid_map), 0, |
| 3221 | scsi3addr, TYPE_CMD)) { |
Robert Elliott | 2dd02d7 | 2015-04-23 09:33:43 -0500 | [diff] [blame] | 3222 | dev_warn(&h->pdev->dev, "hpsa_get_raid_map fill_cmd failed\n"); |
| 3223 | cmd_free(h, c); |
| 3224 | return -1; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3225 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3226 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3227 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3228 | if (rc) |
| 3229 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3230 | ei = c->err_info; |
| 3231 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 3232 | hpsa_scsi_interpret_error(h, c); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3233 | rc = -1; |
| 3234 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3235 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3236 | cmd_free(h, c); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3237 | |
| 3238 | /* @todo in the future, dynamically allocate RAID map memory */ |
| 3239 | if (le32_to_cpu(this_device->raid_map.structure_size) > |
| 3240 | sizeof(this_device->raid_map)) { |
| 3241 | dev_warn(&h->pdev->dev, "RAID map size is too large!\n"); |
| 3242 | rc = -1; |
| 3243 | } |
| 3244 | hpsa_debug_map_buff(h, rc, &this_device->raid_map); |
| 3245 | return rc; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3246 | out: |
| 3247 | cmd_free(h, c); |
| 3248 | return rc; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3249 | } |
| 3250 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 3251 | static int hpsa_bmic_sense_subsystem_information(struct ctlr_info *h, |
| 3252 | unsigned char scsi3addr[], u16 bmic_device_index, |
| 3253 | struct bmic_sense_subsystem_info *buf, size_t bufsize) |
| 3254 | { |
| 3255 | int rc = IO_OK; |
| 3256 | struct CommandList *c; |
| 3257 | struct ErrorInfo *ei; |
| 3258 | |
| 3259 | c = cmd_alloc(h); |
| 3260 | |
| 3261 | rc = fill_cmd(c, BMIC_SENSE_SUBSYSTEM_INFORMATION, h, buf, bufsize, |
| 3262 | 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 3263 | if (rc) |
| 3264 | goto out; |
| 3265 | |
| 3266 | c->Request.CDB[2] = bmic_device_index & 0xff; |
| 3267 | c->Request.CDB[9] = (bmic_device_index >> 8) & 0xff; |
| 3268 | |
| 3269 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3270 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 3271 | if (rc) |
| 3272 | goto out; |
| 3273 | ei = c->err_info; |
| 3274 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 3275 | hpsa_scsi_interpret_error(h, c); |
| 3276 | rc = -1; |
| 3277 | } |
| 3278 | out: |
| 3279 | cmd_free(h, c); |
| 3280 | return rc; |
| 3281 | } |
| 3282 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3283 | static int hpsa_bmic_id_controller(struct ctlr_info *h, |
| 3284 | struct bmic_identify_controller *buf, size_t bufsize) |
| 3285 | { |
| 3286 | int rc = IO_OK; |
| 3287 | struct CommandList *c; |
| 3288 | struct ErrorInfo *ei; |
| 3289 | |
| 3290 | c = cmd_alloc(h); |
| 3291 | |
| 3292 | rc = fill_cmd(c, BMIC_IDENTIFY_CONTROLLER, h, buf, bufsize, |
| 3293 | 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 3294 | if (rc) |
| 3295 | goto out; |
| 3296 | |
| 3297 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3298 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3299 | if (rc) |
| 3300 | goto out; |
| 3301 | ei = c->err_info; |
| 3302 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 3303 | hpsa_scsi_interpret_error(h, c); |
| 3304 | rc = -1; |
| 3305 | } |
| 3306 | out: |
| 3307 | cmd_free(h, c); |
| 3308 | return rc; |
| 3309 | } |
| 3310 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3311 | static int hpsa_bmic_id_physical_device(struct ctlr_info *h, |
| 3312 | unsigned char scsi3addr[], u16 bmic_device_index, |
| 3313 | struct bmic_identify_physical_device *buf, size_t bufsize) |
| 3314 | { |
| 3315 | int rc = IO_OK; |
| 3316 | struct CommandList *c; |
| 3317 | struct ErrorInfo *ei; |
| 3318 | |
| 3319 | c = cmd_alloc(h); |
| 3320 | rc = fill_cmd(c, BMIC_IDENTIFY_PHYSICAL_DEVICE, h, buf, bufsize, |
| 3321 | 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 3322 | if (rc) |
| 3323 | goto out; |
| 3324 | |
| 3325 | c->Request.CDB[2] = bmic_device_index & 0xff; |
| 3326 | c->Request.CDB[9] = (bmic_device_index >> 8) & 0xff; |
| 3327 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3328 | hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3329 | DEFAULT_TIMEOUT); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3330 | ei = c->err_info; |
| 3331 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 3332 | hpsa_scsi_interpret_error(h, c); |
| 3333 | rc = -1; |
| 3334 | } |
| 3335 | out: |
| 3336 | cmd_free(h, c); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 3337 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3338 | return rc; |
| 3339 | } |
| 3340 | |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 3341 | /* |
| 3342 | * get enclosure information |
| 3343 | * struct ReportExtendedLUNdata *rlep - Used for BMIC drive number |
| 3344 | * struct hpsa_scsi_dev_t *encl_dev - device entry for enclosure |
| 3345 | * Uses id_physical_device to determine the box_index. |
| 3346 | */ |
| 3347 | static void hpsa_get_enclosure_info(struct ctlr_info *h, |
| 3348 | unsigned char *scsi3addr, |
| 3349 | struct ReportExtendedLUNdata *rlep, int rle_index, |
| 3350 | struct hpsa_scsi_dev_t *encl_dev) |
| 3351 | { |
| 3352 | int rc = -1; |
| 3353 | struct CommandList *c = NULL; |
| 3354 | struct ErrorInfo *ei = NULL; |
| 3355 | struct bmic_sense_storage_box_params *bssbp = NULL; |
| 3356 | struct bmic_identify_physical_device *id_phys = NULL; |
| 3357 | struct ext_report_lun_entry *rle = &rlep->LUN[rle_index]; |
| 3358 | u16 bmic_device_index = 0; |
| 3359 | |
| 3360 | bmic_device_index = GET_BMIC_DRIVE_NUMBER(&rle->lunid[0]); |
| 3361 | |
Don Brace | 17a9e54 | 2016-02-23 15:16:09 -0600 | [diff] [blame] | 3362 | if (bmic_device_index == 0xFF00 || MASKED_DEVICE(&rle->lunid[0])) { |
| 3363 | rc = IO_OK; |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 3364 | goto out; |
Don Brace | 17a9e54 | 2016-02-23 15:16:09 -0600 | [diff] [blame] | 3365 | } |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 3366 | |
| 3367 | bssbp = kzalloc(sizeof(*bssbp), GFP_KERNEL); |
| 3368 | if (!bssbp) |
| 3369 | goto out; |
| 3370 | |
| 3371 | id_phys = kzalloc(sizeof(*id_phys), GFP_KERNEL); |
| 3372 | if (!id_phys) |
| 3373 | goto out; |
| 3374 | |
| 3375 | rc = hpsa_bmic_id_physical_device(h, scsi3addr, bmic_device_index, |
| 3376 | id_phys, sizeof(*id_phys)); |
| 3377 | if (rc) { |
| 3378 | dev_warn(&h->pdev->dev, "%s: id_phys failed %d bdi[0x%x]\n", |
| 3379 | __func__, encl_dev->external, bmic_device_index); |
| 3380 | goto out; |
| 3381 | } |
| 3382 | |
| 3383 | c = cmd_alloc(h); |
| 3384 | |
| 3385 | rc = fill_cmd(c, BMIC_SENSE_STORAGE_BOX_PARAMS, h, bssbp, |
| 3386 | sizeof(*bssbp), 0, RAID_CTLR_LUNID, TYPE_CMD); |
| 3387 | |
| 3388 | if (rc) |
| 3389 | goto out; |
| 3390 | |
| 3391 | if (id_phys->phys_connector[1] == 'E') |
| 3392 | c->Request.CDB[5] = id_phys->box_index; |
| 3393 | else |
| 3394 | c->Request.CDB[5] = 0; |
| 3395 | |
| 3396 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, PCI_DMA_FROMDEVICE, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3397 | DEFAULT_TIMEOUT); |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 3398 | if (rc) |
| 3399 | goto out; |
| 3400 | |
| 3401 | ei = c->err_info; |
| 3402 | if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) { |
| 3403 | rc = -1; |
| 3404 | goto out; |
| 3405 | } |
| 3406 | |
| 3407 | encl_dev->box[id_phys->active_path_number] = bssbp->phys_box_on_port; |
| 3408 | memcpy(&encl_dev->phys_connector[id_phys->active_path_number], |
| 3409 | bssbp->phys_connector, sizeof(bssbp->phys_connector)); |
| 3410 | |
| 3411 | rc = IO_OK; |
| 3412 | out: |
| 3413 | kfree(bssbp); |
| 3414 | kfree(id_phys); |
| 3415 | |
| 3416 | if (c) |
| 3417 | cmd_free(h, c); |
| 3418 | |
| 3419 | if (rc != IO_OK) |
| 3420 | hpsa_show_dev_msg(KERN_INFO, h, encl_dev, |
| 3421 | "Error, could not get enclosure information\n"); |
| 3422 | } |
| 3423 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 3424 | static u64 hpsa_get_sas_address_from_report_physical(struct ctlr_info *h, |
| 3425 | unsigned char *scsi3addr) |
| 3426 | { |
| 3427 | struct ReportExtendedLUNdata *physdev; |
| 3428 | u32 nphysicals; |
| 3429 | u64 sa = 0; |
| 3430 | int i; |
| 3431 | |
| 3432 | physdev = kzalloc(sizeof(*physdev), GFP_KERNEL); |
| 3433 | if (!physdev) |
| 3434 | return 0; |
| 3435 | |
| 3436 | if (hpsa_scsi_do_report_phys_luns(h, physdev, sizeof(*physdev))) { |
| 3437 | dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); |
| 3438 | kfree(physdev); |
| 3439 | return 0; |
| 3440 | } |
| 3441 | nphysicals = get_unaligned_be32(physdev->LUNListLength) / 24; |
| 3442 | |
| 3443 | for (i = 0; i < nphysicals; i++) |
| 3444 | if (!memcmp(&physdev->LUN[i].lunid[0], scsi3addr, 8)) { |
| 3445 | sa = get_unaligned_be64(&physdev->LUN[i].wwid[0]); |
| 3446 | break; |
| 3447 | } |
| 3448 | |
| 3449 | kfree(physdev); |
| 3450 | |
| 3451 | return sa; |
| 3452 | } |
| 3453 | |
| 3454 | static void hpsa_get_sas_address(struct ctlr_info *h, unsigned char *scsi3addr, |
| 3455 | struct hpsa_scsi_dev_t *dev) |
| 3456 | { |
| 3457 | int rc; |
| 3458 | u64 sa = 0; |
| 3459 | |
| 3460 | if (is_hba_lunid(scsi3addr)) { |
| 3461 | struct bmic_sense_subsystem_info *ssi; |
| 3462 | |
| 3463 | ssi = kzalloc(sizeof(*ssi), GFP_KERNEL); |
| 3464 | if (ssi == NULL) { |
| 3465 | dev_warn(&h->pdev->dev, |
| 3466 | "%s: out of memory\n", __func__); |
| 3467 | return; |
| 3468 | } |
| 3469 | |
| 3470 | rc = hpsa_bmic_sense_subsystem_information(h, |
| 3471 | scsi3addr, 0, ssi, sizeof(*ssi)); |
| 3472 | if (rc == 0) { |
| 3473 | sa = get_unaligned_be64(ssi->primary_world_wide_id); |
| 3474 | h->sas_address = sa; |
| 3475 | } |
| 3476 | |
| 3477 | kfree(ssi); |
| 3478 | } else |
| 3479 | sa = hpsa_get_sas_address_from_report_physical(h, scsi3addr); |
| 3480 | |
| 3481 | dev->sas_address = sa; |
| 3482 | } |
| 3483 | |
| 3484 | /* Get a device id from inquiry page 0x83 */ |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3485 | static bool hpsa_vpd_page_supported(struct ctlr_info *h, |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3486 | unsigned char scsi3addr[], u8 page) |
| 3487 | { |
| 3488 | int rc; |
| 3489 | int i; |
| 3490 | int pages; |
| 3491 | unsigned char *buf, bufsize; |
| 3492 | |
| 3493 | buf = kzalloc(256, GFP_KERNEL); |
| 3494 | if (!buf) |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3495 | return false; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3496 | |
| 3497 | /* Get the size of the page list first */ |
| 3498 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 3499 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 3500 | buf, HPSA_VPD_HEADER_SZ); |
| 3501 | if (rc != 0) |
| 3502 | goto exit_unsupported; |
| 3503 | pages = buf[3]; |
| 3504 | if ((pages + HPSA_VPD_HEADER_SZ) <= 255) |
| 3505 | bufsize = pages + HPSA_VPD_HEADER_SZ; |
| 3506 | else |
| 3507 | bufsize = 255; |
| 3508 | |
| 3509 | /* Get the whole VPD page list */ |
| 3510 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
| 3511 | VPD_PAGE | HPSA_VPD_SUPPORTED_PAGES, |
| 3512 | buf, bufsize); |
| 3513 | if (rc != 0) |
| 3514 | goto exit_unsupported; |
| 3515 | |
| 3516 | pages = buf[3]; |
| 3517 | for (i = 1; i <= pages; i++) |
| 3518 | if (buf[3 + i] == page) |
| 3519 | goto exit_supported; |
| 3520 | exit_unsupported: |
| 3521 | kfree(buf); |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3522 | return false; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3523 | exit_supported: |
| 3524 | kfree(buf); |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3525 | return true; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3526 | } |
| 3527 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3528 | static void hpsa_get_ioaccel_status(struct ctlr_info *h, |
| 3529 | unsigned char *scsi3addr, struct hpsa_scsi_dev_t *this_device) |
| 3530 | { |
| 3531 | int rc; |
| 3532 | unsigned char *buf; |
| 3533 | u8 ioaccel_status; |
| 3534 | |
| 3535 | this_device->offload_config = 0; |
| 3536 | this_device->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3537 | this_device->offload_to_be_enabled = 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3538 | |
| 3539 | buf = kzalloc(64, GFP_KERNEL); |
| 3540 | if (!buf) |
| 3541 | return; |
Stephen M. Cameron | 1b70150a | 2014-02-18 13:57:16 -0600 | [diff] [blame] | 3542 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_IOACCEL_STATUS)) |
| 3543 | goto out; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3544 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 3545 | VPD_PAGE | HPSA_VPD_LV_IOACCEL_STATUS, buf, 64); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3546 | if (rc != 0) |
| 3547 | goto out; |
| 3548 | |
| 3549 | #define IOACCEL_STATUS_BYTE 4 |
| 3550 | #define OFFLOAD_CONFIGURED_BIT 0x01 |
| 3551 | #define OFFLOAD_ENABLED_BIT 0x02 |
| 3552 | ioaccel_status = buf[IOACCEL_STATUS_BYTE]; |
| 3553 | this_device->offload_config = |
| 3554 | !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT); |
| 3555 | if (this_device->offload_config) { |
| 3556 | this_device->offload_enabled = |
| 3557 | !!(ioaccel_status & OFFLOAD_ENABLED_BIT); |
| 3558 | if (hpsa_get_raid_map(h, scsi3addr, this_device)) |
| 3559 | this_device->offload_enabled = 0; |
| 3560 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3561 | this_device->offload_to_be_enabled = this_device->offload_enabled; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3562 | out: |
| 3563 | kfree(buf); |
| 3564 | return; |
| 3565 | } |
| 3566 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3567 | /* Get the device id from inquiry page 0x83 */ |
| 3568 | 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] | 3569 | unsigned char *device_id, int index, int buflen) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3570 | { |
| 3571 | int rc; |
| 3572 | unsigned char *buf; |
| 3573 | |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3574 | /* Does controller have VPD for device id? */ |
| 3575 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_DEVICE_ID)) |
| 3576 | return 1; /* not supported */ |
| 3577 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3578 | buf = kzalloc(64, GFP_KERNEL); |
| 3579 | if (!buf) |
Stephen M. Cameron | a84d794 | 2014-05-29 10:54:20 -0500 | [diff] [blame] | 3580 | return -ENOMEM; |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3581 | |
| 3582 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | |
| 3583 | HPSA_VPD_LV_DEVICE_ID, buf, 64); |
| 3584 | if (rc == 0) { |
| 3585 | if (buflen > 16) |
| 3586 | buflen = 16; |
| 3587 | memcpy(device_id, &buf[8], buflen); |
| 3588 | } |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3589 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3590 | kfree(buf); |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3591 | |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3592 | return rc; /*0 - got id, otherwise, didn't */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | 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] | 3596 | void *buf, int bufsize, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3597 | int extended_response) |
| 3598 | { |
| 3599 | int rc = IO_OK; |
| 3600 | struct CommandList *c; |
| 3601 | unsigned char scsi3addr[8]; |
| 3602 | struct ErrorInfo *ei; |
| 3603 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3604 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3605 | |
Stephen M. Cameron | e89c0ae | 2010-02-04 08:42:04 -0600 | [diff] [blame] | 3606 | /* address the controller */ |
| 3607 | memset(scsi3addr, 0, sizeof(scsi3addr)); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 3608 | if (fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h, |
| 3609 | buf, bufsize, 0, scsi3addr, TYPE_CMD)) { |
| 3610 | rc = -1; |
| 3611 | goto out; |
| 3612 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3613 | if (extended_response) |
| 3614 | c->Request.CDB[1] = extended_response; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3615 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3616 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3617 | if (rc) |
| 3618 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3619 | ei = c->err_info; |
| 3620 | if (ei->CommandStatus != 0 && |
| 3621 | ei->CommandStatus != CMD_DATA_UNDERRUN) { |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 3622 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3623 | rc = -1; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3624 | } else { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3625 | struct ReportLUNdata *rld = buf; |
| 3626 | |
| 3627 | if (rld->extended_response_flag != extended_response) { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3628 | dev_err(&h->pdev->dev, |
| 3629 | "report luns requested format %u, got %u\n", |
| 3630 | extended_response, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3631 | rld->extended_response_flag); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3632 | rc = -1; |
| 3633 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3634 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 3635 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 3636 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3637 | return rc; |
| 3638 | } |
| 3639 | |
| 3640 | 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] | 3641 | struct ReportExtendedLUNdata *buf, int bufsize) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3642 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3643 | return hpsa_scsi_do_report_luns(h, 0, buf, bufsize, |
| 3644 | HPSA_REPORT_PHYS_EXTENDED); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | static inline int hpsa_scsi_do_report_log_luns(struct ctlr_info *h, |
| 3648 | struct ReportLUNdata *buf, int bufsize) |
| 3649 | { |
| 3650 | return hpsa_scsi_do_report_luns(h, 1, buf, bufsize, 0); |
| 3651 | } |
| 3652 | |
| 3653 | static inline void hpsa_set_bus_target_lun(struct hpsa_scsi_dev_t *device, |
| 3654 | int bus, int target, int lun) |
| 3655 | { |
| 3656 | device->bus = bus; |
| 3657 | device->target = target; |
| 3658 | device->lun = lun; |
| 3659 | } |
| 3660 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3661 | /* Use VPD inquiry to get details of volume status */ |
| 3662 | static int hpsa_get_volume_status(struct ctlr_info *h, |
| 3663 | unsigned char scsi3addr[]) |
| 3664 | { |
| 3665 | int rc; |
| 3666 | int status; |
| 3667 | int size; |
| 3668 | unsigned char *buf; |
| 3669 | |
| 3670 | buf = kzalloc(64, GFP_KERNEL); |
| 3671 | if (!buf) |
| 3672 | return HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 3673 | |
| 3674 | /* Does controller have VPD for logical volume status? */ |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 3675 | if (!hpsa_vpd_page_supported(h, scsi3addr, HPSA_VPD_LV_STATUS)) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3676 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3677 | |
| 3678 | /* Get the size of the VPD return buffer */ |
| 3679 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS, |
| 3680 | buf, HPSA_VPD_HEADER_SZ); |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 3681 | if (rc != 0) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3682 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3683 | size = buf[3]; |
| 3684 | |
| 3685 | /* Now get the whole VPD buffer */ |
| 3686 | rc = hpsa_scsi_do_inquiry(h, scsi3addr, VPD_PAGE | HPSA_VPD_LV_STATUS, |
| 3687 | buf, size + HPSA_VPD_HEADER_SZ); |
Stephen M. Cameron | 24a4b07 | 2014-05-29 10:54:10 -0500 | [diff] [blame] | 3688 | if (rc != 0) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3689 | goto exit_failed; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3690 | status = buf[4]; /* status byte */ |
| 3691 | |
| 3692 | kfree(buf); |
| 3693 | return status; |
| 3694 | exit_failed: |
| 3695 | kfree(buf); |
| 3696 | return HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 3697 | } |
| 3698 | |
| 3699 | /* Determine offline status of a volume. |
| 3700 | * Return either: |
| 3701 | * 0 (not offline) |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3702 | * 0xff (offline for unknown reasons) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3703 | * # (integer code indicating one of several NOT READY states |
| 3704 | * describing why a volume is to be kept offline) |
| 3705 | */ |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3706 | static int hpsa_volume_offline(struct ctlr_info *h, |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3707 | unsigned char scsi3addr[]) |
| 3708 | { |
| 3709 | struct CommandList *c; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 3710 | unsigned char *sense; |
| 3711 | u8 sense_key, asc, ascq; |
| 3712 | int sense_len; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3713 | int rc, ldstat = 0; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3714 | u16 cmd_status; |
| 3715 | u8 scsi_status; |
| 3716 | #define ASC_LUN_NOT_READY 0x04 |
| 3717 | #define ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS 0x04 |
| 3718 | #define ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ 0x02 |
| 3719 | |
| 3720 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3721 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3722 | (void) fill_cmd(c, TEST_UNIT_READY, h, NULL, 0, 0, scsi3addr, TYPE_CMD); |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3723 | rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, |
| 3724 | DEFAULT_TIMEOUT); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 3725 | if (rc) { |
| 3726 | cmd_free(h, c); |
| 3727 | return 0; |
| 3728 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3729 | sense = c->err_info->SenseInfo; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 3730 | if (c->err_info->SenseLen > sizeof(c->err_info->SenseInfo)) |
| 3731 | sense_len = sizeof(c->err_info->SenseInfo); |
| 3732 | else |
| 3733 | sense_len = c->err_info->SenseLen; |
| 3734 | decode_sense_data(sense, sense_len, &sense_key, &asc, &ascq); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3735 | cmd_status = c->err_info->CommandStatus; |
| 3736 | scsi_status = c->err_info->ScsiStatus; |
| 3737 | cmd_free(h, c); |
| 3738 | /* Is the volume 'not ready'? */ |
| 3739 | if (cmd_status != CMD_TARGET_STATUS || |
| 3740 | scsi_status != SAM_STAT_CHECK_CONDITION || |
| 3741 | sense_key != NOT_READY || |
| 3742 | asc != ASC_LUN_NOT_READY) { |
| 3743 | return 0; |
| 3744 | } |
| 3745 | |
| 3746 | /* Determine the reason for not ready state */ |
| 3747 | ldstat = hpsa_get_volume_status(h, scsi3addr); |
| 3748 | |
| 3749 | /* Keep volume offline in certain cases: */ |
| 3750 | switch (ldstat) { |
| 3751 | case HPSA_LV_UNDERGOING_ERASE: |
Scott Benesh | 5ca0120 | 2015-07-18 11:13:04 -0500 | [diff] [blame] | 3752 | case HPSA_LV_NOT_AVAILABLE: |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3753 | case HPSA_LV_UNDERGOING_RPI: |
| 3754 | case HPSA_LV_PENDING_RPI: |
| 3755 | case HPSA_LV_ENCRYPTED_NO_KEY: |
| 3756 | case HPSA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER: |
| 3757 | case HPSA_LV_UNDERGOING_ENCRYPTION: |
| 3758 | case HPSA_LV_UNDERGOING_ENCRYPTION_REKEYING: |
| 3759 | case HPSA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER: |
| 3760 | return ldstat; |
| 3761 | case HPSA_VPD_LV_STATUS_UNSUPPORTED: |
| 3762 | /* If VPD status page isn't available, |
| 3763 | * use ASC/ASCQ to determine state |
| 3764 | */ |
| 3765 | if ((ascq == ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS) || |
| 3766 | (ascq == ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ)) |
| 3767 | return ldstat; |
| 3768 | break; |
| 3769 | default: |
| 3770 | break; |
| 3771 | } |
| 3772 | return 0; |
| 3773 | } |
| 3774 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3775 | /* |
| 3776 | * Find out if a logical device supports aborts by simply trying one. |
| 3777 | * Smart Array may claim not to support aborts on logical drives, but |
| 3778 | * if a MSA2000 * is connected, the drives on that will be presented |
| 3779 | * by the Smart Array as logical drives, and aborts may be sent to |
| 3780 | * those devices successfully. So the simplest way to find out is |
| 3781 | * to simply try an abort and see how the device responds. |
| 3782 | */ |
| 3783 | static int hpsa_device_supports_aborts(struct ctlr_info *h, |
| 3784 | unsigned char *scsi3addr) |
| 3785 | { |
| 3786 | struct CommandList *c; |
| 3787 | struct ErrorInfo *ei; |
| 3788 | int rc = 0; |
| 3789 | |
| 3790 | u64 tag = (u64) -1; /* bogus tag */ |
| 3791 | |
| 3792 | /* Assume that physical devices support aborts */ |
| 3793 | if (!is_logical_dev_addr_mode(scsi3addr)) |
| 3794 | return 1; |
| 3795 | |
| 3796 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 3797 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3798 | (void) fill_cmd(c, HPSA_ABORT_MSG, h, &tag, 0, 0, scsi3addr, TYPE_MSG); |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 3799 | (void) hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, |
| 3800 | DEFAULT_TIMEOUT); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3801 | /* no unmap needed here because no data xfer. */ |
| 3802 | ei = c->err_info; |
| 3803 | switch (ei->CommandStatus) { |
| 3804 | case CMD_INVALID: |
| 3805 | rc = 0; |
| 3806 | break; |
| 3807 | case CMD_UNABORTABLE: |
| 3808 | case CMD_ABORT_FAILED: |
| 3809 | rc = 1; |
| 3810 | break; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 3811 | case CMD_TMF_STATUS: |
| 3812 | rc = hpsa_evaluate_tmf_status(h, c); |
| 3813 | break; |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3814 | default: |
| 3815 | rc = 0; |
| 3816 | break; |
| 3817 | } |
| 3818 | cmd_free(h, c); |
| 3819 | return rc; |
| 3820 | } |
| 3821 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3822 | static int hpsa_update_device_info(struct ctlr_info *h, |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3823 | unsigned char scsi3addr[], struct hpsa_scsi_dev_t *this_device, |
| 3824 | unsigned char *is_OBDR_device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3825 | { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3826 | |
| 3827 | #define OBDR_SIG_OFFSET 43 |
| 3828 | #define OBDR_TAPE_SIG "$DR-10" |
| 3829 | #define OBDR_SIG_LEN (sizeof(OBDR_TAPE_SIG) - 1) |
| 3830 | #define OBDR_TAPE_INQ_SIZE (OBDR_SIG_OFFSET + OBDR_SIG_LEN) |
| 3831 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 3832 | unsigned char *inq_buff; |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3833 | unsigned char *obdr_sig; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3834 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3835 | |
Stephen M. Cameron | ea6d3bc | 2010-02-04 08:42:09 -0600 | [diff] [blame] | 3836 | inq_buff = kzalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3837 | if (!inq_buff) { |
| 3838 | rc = -ENOMEM; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3839 | goto bail_out; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3840 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3841 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3842 | /* Do an inquiry to the device to see what it is. */ |
| 3843 | if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff, |
| 3844 | (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) { |
| 3845 | /* Inquiry failed (msg printed already) */ |
| 3846 | dev_err(&h->pdev->dev, |
| 3847 | "hpsa_update_device_info: inquiry failed\n"); |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3848 | rc = -EIO; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3849 | goto bail_out; |
| 3850 | } |
| 3851 | |
Don Brace | 4af61e4 | 2016-02-23 15:16:40 -0600 | [diff] [blame] | 3852 | scsi_sanitize_inquiry_string(&inq_buff[8], 8); |
| 3853 | scsi_sanitize_inquiry_string(&inq_buff[16], 16); |
Don Brace | 75d23d8 | 2015-11-04 15:51:39 -0600 | [diff] [blame] | 3854 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3855 | this_device->devtype = (inq_buff[0] & 0x1f); |
| 3856 | memcpy(this_device->scsi3addr, scsi3addr, 8); |
| 3857 | memcpy(this_device->vendor, &inq_buff[8], |
| 3858 | sizeof(this_device->vendor)); |
| 3859 | memcpy(this_device->model, &inq_buff[16], |
| 3860 | sizeof(this_device->model)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3861 | memset(this_device->device_id, 0, |
| 3862 | sizeof(this_device->device_id)); |
Scott Teel | 8383278 | 2016-09-09 16:30:29 -0500 | [diff] [blame] | 3863 | if (hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8, |
| 3864 | sizeof(this_device->device_id))) |
| 3865 | dev_err(&h->pdev->dev, |
| 3866 | "hpsa%d: %s: can't get device id for host %d:C0:T%d:L%d\t%s\t%.16s\n", |
| 3867 | h->ctlr, __func__, |
| 3868 | h->scsi_host->host_no, |
| 3869 | this_device->target, this_device->lun, |
| 3870 | scsi_device_type(this_device->devtype), |
| 3871 | this_device->model); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3872 | |
Don Brace | af15ed3 | 2016-02-23 15:16:15 -0600 | [diff] [blame] | 3873 | if ((this_device->devtype == TYPE_DISK || |
| 3874 | this_device->devtype == TYPE_ZBC) && |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3875 | is_logical_dev_addr_mode(scsi3addr)) { |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3876 | int volume_offline; |
| 3877 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3878 | hpsa_get_raid_level(h, scsi3addr, &this_device->raid_level); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3879 | if (h->fw_support & MISC_FW_RAID_OFFLOAD_BASIC) |
| 3880 | hpsa_get_ioaccel_status(h, scsi3addr, this_device); |
Stephen M. Cameron | 67955ba | 2014-05-29 10:54:25 -0500 | [diff] [blame] | 3881 | volume_offline = hpsa_volume_offline(h, scsi3addr); |
| 3882 | if (volume_offline < 0 || volume_offline > 0xff) |
| 3883 | volume_offline = HPSA_VPD_LV_STATUS_UNSUPPORTED; |
| 3884 | this_device->volume_offline = volume_offline & 0xff; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3885 | } else { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3886 | this_device->raid_level = RAID_UNKNOWN; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3887 | this_device->offload_config = 0; |
| 3888 | this_device->offload_enabled = 0; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3889 | this_device->offload_to_be_enabled = 0; |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 3890 | this_device->hba_ioaccel_enabled = 0; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 3891 | this_device->volume_offline = 0; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 3892 | this_device->queue_depth = h->nr_cmds; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 3893 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3894 | |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 3895 | if (is_OBDR_device) { |
| 3896 | /* See if this is a One-Button-Disaster-Recovery device |
| 3897 | * by looking for "$DR-10" at offset 43 in inquiry data. |
| 3898 | */ |
| 3899 | obdr_sig = &inq_buff[OBDR_SIG_OFFSET]; |
| 3900 | *is_OBDR_device = (this_device->devtype == TYPE_ROM && |
| 3901 | strncmp(obdr_sig, OBDR_TAPE_SIG, |
| 3902 | OBDR_SIG_LEN) == 0); |
| 3903 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3904 | kfree(inq_buff); |
| 3905 | return 0; |
| 3906 | |
| 3907 | bail_out: |
| 3908 | kfree(inq_buff); |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 3909 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3910 | } |
| 3911 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 3912 | static void hpsa_update_device_supports_aborts(struct ctlr_info *h, |
| 3913 | struct hpsa_scsi_dev_t *dev, u8 *scsi3addr) |
| 3914 | { |
| 3915 | unsigned long flags; |
| 3916 | int rc, entry; |
| 3917 | /* |
| 3918 | * See if this device supports aborts. If we already know |
| 3919 | * the device, we already know if it supports aborts, otherwise |
| 3920 | * we have to find out if it supports aborts by trying one. |
| 3921 | */ |
| 3922 | spin_lock_irqsave(&h->devlock, flags); |
| 3923 | rc = hpsa_scsi_find_entry(dev, h->dev, h->ndevices, &entry); |
| 3924 | if ((rc == DEVICE_SAME || rc == DEVICE_UPDATED) && |
| 3925 | entry >= 0 && entry < h->ndevices) { |
| 3926 | dev->supports_aborts = h->dev[entry]->supports_aborts; |
| 3927 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3928 | } else { |
| 3929 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3930 | dev->supports_aborts = |
| 3931 | hpsa_device_supports_aborts(h, scsi3addr); |
| 3932 | if (dev->supports_aborts < 0) |
| 3933 | dev->supports_aborts = 0; |
| 3934 | } |
| 3935 | } |
| 3936 | |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3937 | /* |
| 3938 | * Helper function to assign bus, target, lun mapping of devices. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3939 | * Logical drive target and lun are assigned at this time, but |
| 3940 | * physical device lun and target assignment are deferred (assigned |
| 3941 | * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3942 | */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3943 | static void figure_bus_target_lun(struct ctlr_info *h, |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3944 | u8 *lunaddrbytes, struct hpsa_scsi_dev_t *device) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3945 | { |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3946 | u32 lunid = get_unaligned_le32(lunaddrbytes); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3947 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3948 | if (!is_logical_dev_addr_mode(lunaddrbytes)) { |
| 3949 | /* physical device, target and lun filled in later */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3950 | if (is_hba_lunid(lunaddrbytes)) |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3951 | hpsa_set_bus_target_lun(device, |
| 3952 | HPSA_HBA_BUS, 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3953 | else |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3954 | /* defer target, lun assignment for physical devices */ |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3955 | hpsa_set_bus_target_lun(device, |
| 3956 | HPSA_PHYSICAL_DEVICE_BUS, -1, -1); |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3957 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3958 | } |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3959 | /* It's a logical device */ |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3960 | if (device->external) { |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3961 | hpsa_set_bus_target_lun(device, |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3962 | HPSA_EXTERNAL_RAID_VOLUME_BUS, (lunid >> 16) & 0x3fff, |
| 3963 | lunid & 0x00ff); |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 3964 | return; |
| 3965 | } |
Kevin Barnett | c795505 | 2015-11-04 15:51:45 -0600 | [diff] [blame] | 3966 | hpsa_set_bus_target_lun(device, HPSA_RAID_VOLUME_BUS, |
| 3967 | 0, lunid & 0x3fff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3968 | } |
| 3969 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 3970 | |
| 3971 | /* |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3972 | * Get address of physical disk used for an ioaccel2 mode command: |
| 3973 | * 1. Extract ioaccel2 handle from the command. |
| 3974 | * 2. Find a matching ioaccel2 handle from list of physical disks. |
| 3975 | * 3. Return: |
| 3976 | * 1 and set scsi3addr to address of matching physical |
| 3977 | * 0 if no matching physical disk was found. |
| 3978 | */ |
| 3979 | static int hpsa_get_pdisk_of_ioaccel2(struct ctlr_info *h, |
| 3980 | struct CommandList *ioaccel2_cmd_to_abort, unsigned char *scsi3addr) |
| 3981 | { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3982 | struct io_accel2_cmd *c2 = |
| 3983 | &h->ioaccel2_cmd_pool[ioaccel2_cmd_to_abort->cmdindex]; |
| 3984 | unsigned long flags; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3985 | int i; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3986 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3987 | spin_lock_irqsave(&h->devlock, flags); |
| 3988 | for (i = 0; i < h->ndevices; i++) |
| 3989 | if (h->dev[i]->ioaccel_handle == le32_to_cpu(c2->scsi_nexus)) { |
| 3990 | memcpy(scsi3addr, h->dev[i]->scsi3addr, |
| 3991 | sizeof(h->dev[i]->scsi3addr)); |
| 3992 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3993 | return 1; |
| 3994 | } |
| 3995 | spin_unlock_irqrestore(&h->devlock, flags); |
| 3996 | return 0; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 3997 | } |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 3998 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 3999 | static int figure_external_status(struct ctlr_info *h, int raid_ctlr_position, |
| 4000 | int i, int nphysicals, int nlocal_logicals) |
| 4001 | { |
| 4002 | /* In report logicals, local logicals are listed first, |
| 4003 | * then any externals. |
| 4004 | */ |
| 4005 | int logicals_start = nphysicals + (raid_ctlr_position == 0); |
| 4006 | |
| 4007 | if (i == raid_ctlr_position) |
| 4008 | return 0; |
| 4009 | |
| 4010 | if (i < logicals_start) |
| 4011 | return 0; |
| 4012 | |
| 4013 | /* i is in logicals range, but still within local logicals */ |
| 4014 | if ((i - nphysicals - (raid_ctlr_position == 0)) < nlocal_logicals) |
| 4015 | return 0; |
| 4016 | |
| 4017 | return 1; /* it's an external lun */ |
| 4018 | } |
| 4019 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 4020 | /* |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4021 | * Do CISS_REPORT_PHYS and CISS_REPORT_LOG. Data is returned in physdev, |
| 4022 | * logdev. The number of luns in physdev and logdev are returned in |
| 4023 | * *nphysicals and *nlogicals, respectively. |
| 4024 | * Returns 0 on success, -1 otherwise. |
| 4025 | */ |
| 4026 | static int hpsa_gather_lun_info(struct ctlr_info *h, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4027 | struct ReportExtendedLUNdata *physdev, u32 *nphysicals, |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4028 | struct ReportLUNdata *logdev, u32 *nlogicals) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4029 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4030 | if (hpsa_scsi_do_report_phys_luns(h, physdev, sizeof(*physdev))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4031 | dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); |
| 4032 | return -1; |
| 4033 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4034 | *nphysicals = be32_to_cpu(*((__be32 *)physdev->LUNListLength)) / 24; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4035 | if (*nphysicals > HPSA_MAX_PHYS_LUN) { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4036 | dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded. %d LUNs ignored.\n", |
| 4037 | HPSA_MAX_PHYS_LUN, *nphysicals - HPSA_MAX_PHYS_LUN); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4038 | *nphysicals = HPSA_MAX_PHYS_LUN; |
| 4039 | } |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4040 | if (hpsa_scsi_do_report_log_luns(h, logdev, sizeof(*logdev))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4041 | dev_err(&h->pdev->dev, "report logical LUNs failed.\n"); |
| 4042 | return -1; |
| 4043 | } |
Stephen M. Cameron | 6df1e95 | 2010-02-04 08:42:19 -0600 | [diff] [blame] | 4044 | *nlogicals = be32_to_cpu(*((__be32 *) logdev->LUNListLength)) / 8; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4045 | /* Reject Logicals in excess of our max capability. */ |
| 4046 | if (*nlogicals > HPSA_MAX_LUN) { |
| 4047 | dev_warn(&h->pdev->dev, |
| 4048 | "maximum logical LUNs (%d) exceeded. " |
| 4049 | "%d LUNs ignored.\n", HPSA_MAX_LUN, |
| 4050 | *nlogicals - HPSA_MAX_LUN); |
| 4051 | *nlogicals = HPSA_MAX_LUN; |
| 4052 | } |
| 4053 | if (*nlogicals + *nphysicals > HPSA_MAX_PHYS_LUN) { |
| 4054 | dev_warn(&h->pdev->dev, |
| 4055 | "maximum logical + physical LUNs (%d) exceeded. " |
| 4056 | "%d LUNs ignored.\n", HPSA_MAX_PHYS_LUN, |
| 4057 | *nphysicals + *nlogicals - HPSA_MAX_PHYS_LUN); |
| 4058 | *nlogicals = HPSA_MAX_PHYS_LUN - *nphysicals; |
| 4059 | } |
| 4060 | return 0; |
| 4061 | } |
| 4062 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 4063 | static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, |
| 4064 | int i, int nphysicals, int nlogicals, |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 4065 | struct ReportExtendedLUNdata *physdev_list, |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 4066 | struct ReportLUNdata *logdev_list) |
| 4067 | { |
| 4068 | /* Helper function, figure out where the LUN ID info is coming from |
| 4069 | * given index i, lists of physical and logical devices, where in |
| 4070 | * the list the raid controller is supposed to appear (first or last) |
| 4071 | */ |
| 4072 | |
| 4073 | int logicals_start = nphysicals + (raid_ctlr_position == 0); |
| 4074 | int last_device = nphysicals + nlogicals + (raid_ctlr_position == 0); |
| 4075 | |
| 4076 | if (i == raid_ctlr_position) |
| 4077 | return RAID_CTLR_LUNID; |
| 4078 | |
| 4079 | if (i < logicals_start) |
Stephen M. Cameron | d5b5d96 | 2014-05-29 10:53:34 -0500 | [diff] [blame] | 4080 | return &physdev_list->LUN[i - |
| 4081 | (raid_ctlr_position == 0)].lunid[0]; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 4082 | |
| 4083 | if (i < last_device) |
| 4084 | return &logdev_list->LUN[i - nphysicals - |
| 4085 | (raid_ctlr_position == 0)][0]; |
| 4086 | BUG(); |
| 4087 | return NULL; |
| 4088 | } |
| 4089 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4090 | /* get physical drive ioaccel handle and queue depth */ |
| 4091 | static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h, |
| 4092 | struct hpsa_scsi_dev_t *dev, |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 4093 | struct ReportExtendedLUNdata *rlep, int rle_index, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4094 | struct bmic_identify_physical_device *id_phys) |
| 4095 | { |
| 4096 | int rc; |
Scott Teel | 4b6e559 | 2016-09-09 16:30:36 -0500 | [diff] [blame] | 4097 | struct ext_report_lun_entry *rle; |
| 4098 | |
| 4099 | /* |
| 4100 | * external targets don't support BMIC |
| 4101 | */ |
| 4102 | if (dev->external) { |
| 4103 | dev->queue_depth = 7; |
| 4104 | return; |
| 4105 | } |
| 4106 | |
| 4107 | rle = &rlep->LUN[rle_index]; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4108 | |
| 4109 | dev->ioaccel_handle = rle->ioaccel_handle; |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 4110 | if ((rle->device_flags & 0x08) && dev->ioaccel_handle) |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 4111 | dev->hba_ioaccel_enabled = 1; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4112 | memset(id_phys, 0, sizeof(*id_phys)); |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 4113 | rc = hpsa_bmic_id_physical_device(h, &rle->lunid[0], |
| 4114 | GET_BMIC_DRIVE_NUMBER(&rle->lunid[0]), id_phys, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4115 | sizeof(*id_phys)); |
| 4116 | if (!rc) |
| 4117 | /* Reserve space for FW operations */ |
| 4118 | #define DRIVE_CMDS_RESERVED_FOR_FW 2 |
| 4119 | #define DRIVE_QUEUE_DEPTH 7 |
| 4120 | dev->queue_depth = |
| 4121 | le16_to_cpu(id_phys->current_queue_depth_limit) - |
| 4122 | DRIVE_CMDS_RESERVED_FOR_FW; |
| 4123 | else |
| 4124 | dev->queue_depth = DRIVE_QUEUE_DEPTH; /* conservative */ |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4125 | } |
| 4126 | |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 4127 | 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] | 4128 | struct ReportExtendedLUNdata *rlep, int rle_index, |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 4129 | struct bmic_identify_physical_device *id_phys) |
| 4130 | { |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 4131 | struct ext_report_lun_entry *rle = &rlep->LUN[rle_index]; |
| 4132 | |
| 4133 | if ((rle->device_flags & 0x08) && this_device->ioaccel_handle) |
Joe Handzik | 8270b86 | 2015-07-18 11:12:43 -0500 | [diff] [blame] | 4134 | this_device->hba_ioaccel_enabled = 1; |
| 4135 | |
| 4136 | memcpy(&this_device->active_path_index, |
| 4137 | &id_phys->active_path_number, |
| 4138 | sizeof(this_device->active_path_index)); |
| 4139 | memcpy(&this_device->path_map, |
| 4140 | &id_phys->redundant_path_present_map, |
| 4141 | sizeof(this_device->path_map)); |
| 4142 | memcpy(&this_device->box, |
| 4143 | &id_phys->alternate_paths_phys_box_on_port, |
| 4144 | sizeof(this_device->box)); |
| 4145 | memcpy(&this_device->phys_connector, |
| 4146 | &id_phys->alternate_paths_phys_connector, |
| 4147 | sizeof(this_device->phys_connector)); |
| 4148 | memcpy(&this_device->bay, |
| 4149 | &id_phys->phys_bay_in_box, |
| 4150 | sizeof(this_device->bay)); |
| 4151 | } |
| 4152 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4153 | /* get number of local logical disks. */ |
| 4154 | static int hpsa_set_local_logical_count(struct ctlr_info *h, |
| 4155 | struct bmic_identify_controller *id_ctlr, |
| 4156 | u32 *nlocals) |
| 4157 | { |
| 4158 | int rc; |
| 4159 | |
| 4160 | if (!id_ctlr) { |
| 4161 | dev_warn(&h->pdev->dev, "%s: id_ctlr buffer is NULL.\n", |
| 4162 | __func__); |
| 4163 | return -ENOMEM; |
| 4164 | } |
| 4165 | memset(id_ctlr, 0, sizeof(*id_ctlr)); |
| 4166 | rc = hpsa_bmic_id_controller(h, id_ctlr, sizeof(*id_ctlr)); |
| 4167 | if (!rc) |
| 4168 | if (id_ctlr->configured_logical_drive_count < 256) |
| 4169 | *nlocals = id_ctlr->configured_logical_drive_count; |
| 4170 | else |
| 4171 | *nlocals = le16_to_cpu( |
| 4172 | id_ctlr->extended_logical_unit_count); |
| 4173 | else |
| 4174 | *nlocals = -1; |
| 4175 | return rc; |
| 4176 | } |
| 4177 | |
Don Brace | 64ce60c | 2016-07-01 13:37:31 -0500 | [diff] [blame] | 4178 | static bool hpsa_is_disk_spare(struct ctlr_info *h, u8 *lunaddrbytes) |
| 4179 | { |
| 4180 | struct bmic_identify_physical_device *id_phys; |
| 4181 | bool is_spare = false; |
| 4182 | int rc; |
| 4183 | |
| 4184 | id_phys = kzalloc(sizeof(*id_phys), GFP_KERNEL); |
| 4185 | if (!id_phys) |
| 4186 | return false; |
| 4187 | |
| 4188 | rc = hpsa_bmic_id_physical_device(h, |
| 4189 | lunaddrbytes, |
| 4190 | GET_BMIC_DRIVE_NUMBER(lunaddrbytes), |
| 4191 | id_phys, sizeof(*id_phys)); |
| 4192 | if (rc == 0) |
| 4193 | is_spare = (id_phys->more_flags >> 6) & 0x01; |
| 4194 | |
| 4195 | kfree(id_phys); |
| 4196 | return is_spare; |
| 4197 | } |
| 4198 | |
| 4199 | #define RPL_DEV_FLAG_NON_DISK 0x1 |
| 4200 | #define RPL_DEV_FLAG_UNCONFIG_DISK_REPORTING_SUPPORTED 0x2 |
| 4201 | #define RPL_DEV_FLAG_UNCONFIG_DISK 0x4 |
| 4202 | |
| 4203 | #define BMIC_DEVICE_TYPE_ENCLOSURE 6 |
| 4204 | |
| 4205 | static bool hpsa_skip_device(struct ctlr_info *h, u8 *lunaddrbytes, |
| 4206 | struct ext_report_lun_entry *rle) |
| 4207 | { |
| 4208 | u8 device_flags; |
| 4209 | u8 device_type; |
| 4210 | |
| 4211 | if (!MASKED_DEVICE(lunaddrbytes)) |
| 4212 | return false; |
| 4213 | |
| 4214 | device_flags = rle->device_flags; |
| 4215 | device_type = rle->device_type; |
| 4216 | |
| 4217 | if (device_flags & RPL_DEV_FLAG_NON_DISK) { |
| 4218 | if (device_type == BMIC_DEVICE_TYPE_ENCLOSURE) |
| 4219 | return false; |
| 4220 | return true; |
| 4221 | } |
| 4222 | |
| 4223 | if (!(device_flags & RPL_DEV_FLAG_UNCONFIG_DISK_REPORTING_SUPPORTED)) |
| 4224 | return false; |
| 4225 | |
| 4226 | if (device_flags & RPL_DEV_FLAG_UNCONFIG_DISK) |
| 4227 | return false; |
| 4228 | |
| 4229 | /* |
| 4230 | * Spares may be spun down, we do not want to |
| 4231 | * do an Inquiry to a RAID set spare drive as |
| 4232 | * that would have them spun up, that is a |
| 4233 | * performance hit because I/O to the RAID device |
| 4234 | * stops while the spin up occurs which can take |
| 4235 | * over 50 seconds. |
| 4236 | */ |
| 4237 | if (hpsa_is_disk_spare(h, lunaddrbytes)) |
| 4238 | return true; |
| 4239 | |
| 4240 | return false; |
| 4241 | } |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4242 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 4243 | static void hpsa_update_scsi_devices(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4244 | { |
| 4245 | /* the idea here is we could get notified |
| 4246 | * that some devices have changed, so we do a report |
| 4247 | * physical luns and report logical luns cmd, and adjust |
| 4248 | * our list of devices accordingly. |
| 4249 | * |
| 4250 | * The scsi3addr's of devices won't change so long as the |
| 4251 | * adapter is not reset. That means we can rescan and |
| 4252 | * tell which devices we already know about, vs. new |
| 4253 | * devices, vs. disappearing devices. |
| 4254 | */ |
Matt Gates | a93aa1f | 2014-02-18 13:55:07 -0600 | [diff] [blame] | 4255 | struct ReportExtendedLUNdata *physdev_list = NULL; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4256 | struct ReportLUNdata *logdev_list = NULL; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4257 | struct bmic_identify_physical_device *id_phys = NULL; |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4258 | struct bmic_identify_controller *id_ctlr = NULL; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4259 | u32 nphysicals = 0; |
| 4260 | u32 nlogicals = 0; |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4261 | u32 nlocal_logicals = 0; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4262 | u32 ndev_allocated = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4263 | struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; |
| 4264 | int ncurrent = 0; |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 4265 | int i, n_ext_target_devs, ndevs_to_allocate; |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 4266 | int raid_ctlr_position; |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 4267 | bool physical_device; |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 4268 | DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4269 | |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 4270 | currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL); |
Stephen M. Cameron | 9208471 | 2014-11-14 17:26:54 -0600 | [diff] [blame] | 4271 | physdev_list = kzalloc(sizeof(*physdev_list), GFP_KERNEL); |
| 4272 | logdev_list = kzalloc(sizeof(*logdev_list), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4273 | tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4274 | id_phys = kzalloc(sizeof(*id_phys), GFP_KERNEL); |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4275 | id_ctlr = kzalloc(sizeof(*id_ctlr), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4276 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4277 | if (!currentsd || !physdev_list || !logdev_list || |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4278 | !tmpdevice || !id_phys || !id_ctlr) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4279 | dev_err(&h->pdev->dev, "out of memory\n"); |
| 4280 | goto out; |
| 4281 | } |
| 4282 | memset(lunzerobits, 0, sizeof(lunzerobits)); |
| 4283 | |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 4284 | h->drv_req_rescan = 0; /* cancel scheduled rescan - we're doing it. */ |
| 4285 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4286 | if (hpsa_gather_lun_info(h, physdev_list, &nphysicals, |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 4287 | logdev_list, &nlogicals)) { |
| 4288 | h->drv_req_rescan = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4289 | goto out; |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 4290 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4291 | |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4292 | /* Set number of local logicals (non PTRAID) */ |
| 4293 | if (hpsa_set_local_logical_count(h, id_ctlr, &nlocal_logicals)) { |
| 4294 | dev_warn(&h->pdev->dev, |
| 4295 | "%s: Can't determine number of local logical devices.\n", |
| 4296 | __func__); |
| 4297 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4298 | |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 4299 | /* We might see up to the maximum number of logical and physical disks |
| 4300 | * plus external target devices, and a device for the local RAID |
| 4301 | * controller. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4302 | */ |
Scott Teel | aca4a52 | 2012-01-19 14:01:19 -0600 | [diff] [blame] | 4303 | ndevs_to_allocate = nphysicals + nlogicals + MAX_EXT_TARGETS + 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4304 | |
| 4305 | /* Allocate the per device structures */ |
| 4306 | for (i = 0; i < ndevs_to_allocate; i++) { |
Scott Teel | b7ec021 | 2011-10-26 16:21:12 -0500 | [diff] [blame] | 4307 | if (i >= HPSA_MAX_DEVICES) { |
| 4308 | dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded." |
| 4309 | " %d devices ignored.\n", HPSA_MAX_DEVICES, |
| 4310 | ndevs_to_allocate - HPSA_MAX_DEVICES); |
| 4311 | break; |
| 4312 | } |
| 4313 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4314 | currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL); |
| 4315 | if (!currentsd[i]) { |
| 4316 | dev_warn(&h->pdev->dev, "out of memory at %s:%d\n", |
| 4317 | __FILE__, __LINE__); |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 4318 | h->drv_req_rescan = 1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4319 | goto out; |
| 4320 | } |
| 4321 | ndev_allocated++; |
| 4322 | } |
| 4323 | |
Stephen M. Cameron | 8645291 | 2014-05-29 10:53:49 -0500 | [diff] [blame] | 4324 | if (is_scsi_rev_5(h)) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 4325 | raid_ctlr_position = 0; |
| 4326 | else |
| 4327 | raid_ctlr_position = nphysicals + nlogicals; |
| 4328 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4329 | /* adjust our table of devices */ |
Scott Teel | 4f4eb9f | 2012-01-19 14:01:25 -0600 | [diff] [blame] | 4330 | n_ext_target_devs = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4331 | for (i = 0; i < nphysicals + nlogicals + 1; i++) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 4332 | u8 *lunaddrbytes, is_OBDR = 0; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 4333 | int rc = 0; |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 4334 | int phys_dev_index = i - (raid_ctlr_position == 0); |
Don Brace | 64ce60c | 2016-07-01 13:37:31 -0500 | [diff] [blame] | 4335 | bool skip_device = false; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4336 | |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 4337 | physical_device = i < nphysicals + (raid_ctlr_position == 0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4338 | |
| 4339 | /* Figure out where the LUN ID info is coming from */ |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 4340 | lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position, |
| 4341 | i, nphysicals, nlogicals, physdev_list, logdev_list); |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 4342 | |
Don Brace | 86cf713 | 2016-09-09 16:30:17 -0500 | [diff] [blame] | 4343 | /* Determine if this is a lun from an external target array */ |
| 4344 | tmpdevice->external = |
| 4345 | figure_external_status(h, raid_ctlr_position, i, |
| 4346 | nphysicals, nlocal_logicals); |
| 4347 | |
Don Brace | 64ce60c | 2016-07-01 13:37:31 -0500 | [diff] [blame] | 4348 | /* |
| 4349 | * Skip over some devices such as a spare. |
| 4350 | */ |
| 4351 | if (!tmpdevice->external && physical_device) { |
| 4352 | skip_device = hpsa_skip_device(h, lunaddrbytes, |
| 4353 | &physdev_list->LUN[phys_dev_index]); |
| 4354 | if (skip_device) |
| 4355 | continue; |
| 4356 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4357 | |
| 4358 | /* Get device type, vendor, model, device id */ |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 4359 | rc = hpsa_update_device_info(h, lunaddrbytes, tmpdevice, |
| 4360 | &is_OBDR); |
| 4361 | if (rc == -ENOMEM) { |
| 4362 | dev_warn(&h->pdev->dev, |
| 4363 | "Out of memory, rescan deferred.\n"); |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 4364 | h->drv_req_rescan = 1; |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 4365 | goto out; |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 4366 | } |
Don Brace | 683fc44 | 2015-11-04 15:50:44 -0600 | [diff] [blame] | 4367 | if (rc) { |
| 4368 | dev_warn(&h->pdev->dev, |
| 4369 | "Inquiry failed, skipping device.\n"); |
| 4370 | continue; |
| 4371 | } |
| 4372 | |
Stephen M. Cameron | 1f310bd | 2012-01-19 14:01:14 -0600 | [diff] [blame] | 4373 | figure_bus_target_lun(h, lunaddrbytes, tmpdevice); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 4374 | hpsa_update_device_supports_aborts(h, tmpdevice, lunaddrbytes); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4375 | this_device = currentsd[ncurrent]; |
| 4376 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 4377 | /* Turn on discovery_polling if there are ext target devices. |
| 4378 | * Event-based change notification is unreliable for those. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4379 | */ |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 4380 | if (!h->discovery_polling) { |
| 4381 | if (tmpdevice->external) { |
| 4382 | h->discovery_polling = 1; |
| 4383 | dev_info(&h->pdev->dev, |
| 4384 | "External target, activate discovery polling.\n"); |
| 4385 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4386 | } |
| 4387 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 4388 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4389 | *this_device = *tmpdevice; |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 4390 | this_device->physical_device = physical_device; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4391 | |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 4392 | /* |
| 4393 | * Expose all devices except for physical devices that |
| 4394 | * are masked. |
| 4395 | */ |
| 4396 | if (MASKED_DEVICE(lunaddrbytes) && this_device->physical_device) |
Kevin Barnett | 2a16820 | 2015-11-04 15:51:21 -0600 | [diff] [blame] | 4397 | this_device->expose_device = 0; |
| 4398 | else |
| 4399 | this_device->expose_device = 1; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 4400 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 4401 | |
| 4402 | /* |
| 4403 | * Get the SAS address for physical devices that are exposed. |
| 4404 | */ |
| 4405 | if (this_device->physical_device && this_device->expose_device) |
| 4406 | hpsa_get_sas_address(h, lunaddrbytes, this_device); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4407 | |
| 4408 | switch (this_device->devtype) { |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 4409 | case TYPE_ROM: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4410 | /* We don't *really* support actual CD-ROM devices, |
| 4411 | * just "One Button Disaster Recovery" tape drive |
| 4412 | * which temporarily pretends to be a CD-ROM drive. |
| 4413 | * So we check that the device is really an OBDR tape |
| 4414 | * device by checking for "$DR-10" in bytes 43-48 of |
| 4415 | * the inquiry data. |
| 4416 | */ |
Stephen M. Cameron | 0b0e1d6 | 2011-08-09 08:17:30 -0500 | [diff] [blame] | 4417 | if (is_OBDR) |
| 4418 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4419 | break; |
| 4420 | case TYPE_DISK: |
Don Brace | af15ed3 | 2016-02-23 15:16:15 -0600 | [diff] [blame] | 4421 | case TYPE_ZBC: |
Kevin Barnett | 04fa2f4 | 2015-11-04 15:51:27 -0600 | [diff] [blame] | 4422 | if (this_device->physical_device) { |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 4423 | /* The disk is in HBA mode. */ |
| 4424 | /* Never use RAID mapper in HBA mode. */ |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 4425 | this_device->offload_enabled = 0; |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 4426 | hpsa_get_ioaccel_drive_info(h, this_device, |
Don Brace | f2039b0 | 2015-11-04 15:51:08 -0600 | [diff] [blame] | 4427 | physdev_list, phys_dev_index, id_phys); |
| 4428 | hpsa_get_path_info(this_device, |
| 4429 | physdev_list, phys_dev_index, id_phys); |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 4430 | } |
Joe Handzik | ecf418d1 | 2015-04-23 09:33:04 -0500 | [diff] [blame] | 4431 | ncurrent++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4432 | break; |
| 4433 | case TYPE_TAPE: |
| 4434 | case TYPE_MEDIUM_CHANGER: |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 4435 | ncurrent++; |
| 4436 | break; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 4437 | case TYPE_ENCLOSURE: |
Don Brace | 17a9e54 | 2016-02-23 15:16:09 -0600 | [diff] [blame] | 4438 | if (!this_device->external) |
| 4439 | hpsa_get_enclosure_info(h, lunaddrbytes, |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 4440 | physdev_list, phys_dev_index, |
| 4441 | this_device); |
Kevin Barnett | b9092b7 | 2015-07-18 11:12:59 -0500 | [diff] [blame] | 4442 | ncurrent++; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 4443 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4444 | case TYPE_RAID: |
| 4445 | /* Only present the Smartarray HBA as a RAID controller. |
| 4446 | * If it's a RAID controller other than the HBA itself |
| 4447 | * (an external RAID controller, MSA500 or similar) |
| 4448 | * don't present it. |
| 4449 | */ |
| 4450 | if (!is_hba_lunid(lunaddrbytes)) |
| 4451 | break; |
| 4452 | ncurrent++; |
| 4453 | break; |
| 4454 | default: |
| 4455 | break; |
| 4456 | } |
Scott Teel | cfe5bad | 2011-10-26 16:21:07 -0500 | [diff] [blame] | 4457 | if (ncurrent >= HPSA_MAX_DEVICES) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4458 | break; |
| 4459 | } |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 4460 | |
| 4461 | if (h->sas_host == NULL) { |
| 4462 | int rc = 0; |
| 4463 | |
| 4464 | rc = hpsa_add_sas_host(h); |
| 4465 | if (rc) { |
| 4466 | dev_warn(&h->pdev->dev, |
| 4467 | "Could not add sas host %d\n", rc); |
| 4468 | goto out; |
| 4469 | } |
| 4470 | } |
| 4471 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 4472 | adjust_hpsa_scsi_table(h, currentsd, ncurrent); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4473 | out: |
| 4474 | kfree(tmpdevice); |
| 4475 | for (i = 0; i < ndev_allocated; i++) |
| 4476 | kfree(currentsd[i]); |
| 4477 | kfree(currentsd); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4478 | kfree(physdev_list); |
| 4479 | kfree(logdev_list); |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 4480 | kfree(id_ctlr); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4481 | kfree(id_phys); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4482 | } |
| 4483 | |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4484 | static void hpsa_set_sg_descriptor(struct SGDescriptor *desc, |
| 4485 | struct scatterlist *sg) |
| 4486 | { |
| 4487 | u64 addr64 = (u64) sg_dma_address(sg); |
| 4488 | unsigned int len = sg_dma_len(sg); |
| 4489 | |
| 4490 | desc->Addr = cpu_to_le64(addr64); |
| 4491 | desc->Len = cpu_to_le32(len); |
| 4492 | desc->Ext = 0; |
| 4493 | } |
| 4494 | |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 4495 | /* |
| 4496 | * 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] | 4497 | * dma mapping and fills in the scatter gather entries of the |
| 4498 | * hpsa command, cp. |
| 4499 | */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4500 | static int hpsa_scatter_gather(struct ctlr_info *h, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4501 | struct CommandList *cp, |
| 4502 | struct scsi_cmnd *cmd) |
| 4503 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4504 | struct scatterlist *sg; |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4505 | int use_sg, i, sg_limit, chained, last_sg; |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4506 | struct SGDescriptor *curr_sg; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4507 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4508 | BUG_ON(scsi_sg_count(cmd) > h->maxsgentries); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4509 | |
| 4510 | use_sg = scsi_dma_map(cmd); |
| 4511 | if (use_sg < 0) |
| 4512 | return use_sg; |
| 4513 | |
| 4514 | if (!use_sg) |
| 4515 | goto sglist_finished; |
| 4516 | |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4517 | /* |
| 4518 | * If the number of entries is greater than the max for a single list, |
| 4519 | * then we have a chained list; we will set up all but one entry in the |
| 4520 | * first list (the last entry is saved for link information); |
| 4521 | * otherwise, we don't have a chained list and we'll set up at each of |
| 4522 | * the entries in the one list. |
| 4523 | */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4524 | curr_sg = cp->SG; |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4525 | chained = use_sg > h->max_cmd_sg_entries; |
| 4526 | sg_limit = chained ? h->max_cmd_sg_entries - 1 : use_sg; |
| 4527 | last_sg = scsi_sg_count(cmd) - 1; |
| 4528 | scsi_for_each_sg(cmd, sg, sg_limit, i) { |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4529 | hpsa_set_sg_descriptor(curr_sg, sg); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4530 | curr_sg++; |
| 4531 | } |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4532 | |
Webb Scales | b3a7ba7 | 2015-04-23 09:34:27 -0500 | [diff] [blame] | 4533 | if (chained) { |
| 4534 | /* |
| 4535 | * Continue with the chained list. Set curr_sg to the chained |
| 4536 | * list. Modify the limit to the total count less the entries |
| 4537 | * we've already set up. Resume the scan at the list entry |
| 4538 | * where the previous loop left off. |
| 4539 | */ |
| 4540 | curr_sg = h->cmd_sg_list[cp->cmdindex]; |
| 4541 | sg_limit = use_sg - sg_limit; |
| 4542 | for_each_sg(sg, sg, sg_limit, i) { |
| 4543 | hpsa_set_sg_descriptor(curr_sg, sg); |
| 4544 | curr_sg++; |
| 4545 | } |
| 4546 | } |
| 4547 | |
Webb Scales | ec5cbf0 | 2015-01-23 16:44:45 -0600 | [diff] [blame] | 4548 | /* 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] | 4549 | (curr_sg - 1)->Ext = cpu_to_le32(HPSA_SG_LAST); |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4550 | |
| 4551 | if (use_sg + chained > h->maxSG) |
| 4552 | h->maxSG = use_sg + chained; |
| 4553 | |
| 4554 | if (chained) { |
| 4555 | cp->Header.SGList = h->max_cmd_sg_entries; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4556 | cp->Header.SGTotal = cpu_to_le16(use_sg + 1); |
Stephen M. Cameron | e2bea6d | 2013-02-20 11:24:46 -0600 | [diff] [blame] | 4557 | if (hpsa_map_sg_chain_block(h, cp)) { |
| 4558 | scsi_dma_unmap(cmd); |
| 4559 | return -1; |
| 4560 | } |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 4561 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | sglist_finished: |
| 4565 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 4566 | cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */ |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 4567 | 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] | 4568 | return 0; |
| 4569 | } |
| 4570 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4571 | #define IO_ACCEL_INELIGIBLE (1) |
| 4572 | static int fixup_ioaccel_cdb(u8 *cdb, int *cdb_len) |
| 4573 | { |
| 4574 | int is_write = 0; |
| 4575 | u32 block; |
| 4576 | u32 block_cnt; |
| 4577 | |
| 4578 | /* Perform some CDB fixups if needed using 10 byte reads/writes only */ |
| 4579 | switch (cdb[0]) { |
| 4580 | case WRITE_6: |
| 4581 | case WRITE_12: |
| 4582 | is_write = 1; |
| 4583 | case READ_6: |
| 4584 | case READ_12: |
| 4585 | if (*cdb_len == 6) { |
Mahesh Rajashekhara | abbada7 | 2016-09-16 14:54:23 -0500 | [diff] [blame] | 4586 | block = (((cdb[1] & 0x1F) << 16) | |
| 4587 | (cdb[2] << 8) | |
| 4588 | cdb[3]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4589 | block_cnt = cdb[4]; |
Don Brace | c8a6c9a | 2015-11-04 15:50:50 -0600 | [diff] [blame] | 4590 | if (block_cnt == 0) |
| 4591 | block_cnt = 256; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4592 | } else { |
| 4593 | BUG_ON(*cdb_len != 12); |
Don Brace | c8a6c9a | 2015-11-04 15:50:50 -0600 | [diff] [blame] | 4594 | block = get_unaligned_be32(&cdb[2]); |
| 4595 | block_cnt = get_unaligned_be32(&cdb[6]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4596 | } |
| 4597 | if (block_cnt > 0xffff) |
| 4598 | return IO_ACCEL_INELIGIBLE; |
| 4599 | |
| 4600 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 4601 | cdb[1] = 0; |
| 4602 | cdb[2] = (u8) (block >> 24); |
| 4603 | cdb[3] = (u8) (block >> 16); |
| 4604 | cdb[4] = (u8) (block >> 8); |
| 4605 | cdb[5] = (u8) (block); |
| 4606 | cdb[6] = 0; |
| 4607 | cdb[7] = (u8) (block_cnt >> 8); |
| 4608 | cdb[8] = (u8) (block_cnt); |
| 4609 | cdb[9] = 0; |
| 4610 | *cdb_len = 10; |
| 4611 | break; |
| 4612 | } |
| 4613 | return 0; |
| 4614 | } |
| 4615 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4616 | static int hpsa_scsi_ioaccel1_queue_command(struct ctlr_info *h, |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4617 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4618 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4619 | { |
| 4620 | struct scsi_cmnd *cmd = c->scsi_cmd; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4621 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[c->cmdindex]; |
| 4622 | unsigned int len; |
| 4623 | unsigned int total_len = 0; |
| 4624 | struct scatterlist *sg; |
| 4625 | u64 addr64; |
| 4626 | int use_sg, i; |
| 4627 | struct SGDescriptor *curr_sg; |
| 4628 | u32 control = IOACCEL1_CONTROL_SIMPLEQUEUE; |
| 4629 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4630 | /* TODO: implement chaining support */ |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4631 | if (scsi_sg_count(cmd) > h->ioaccel_maxsg) { |
| 4632 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4633 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4634 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4635 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4636 | BUG_ON(cmd->cmd_len > IOACCEL1_IOFLAGS_CDBLEN_MAX); |
| 4637 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4638 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) { |
| 4639 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4640 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4641 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4642 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4643 | c->cmd_type = CMD_IOACCEL1; |
| 4644 | |
| 4645 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 4646 | c->busaddr = (u32) h->ioaccel_cmd_pool_dhandle + |
| 4647 | (c->cmdindex * sizeof(*cp)); |
| 4648 | BUG_ON(c->busaddr & 0x0000007F); |
| 4649 | |
| 4650 | use_sg = scsi_dma_map(cmd); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4651 | if (use_sg < 0) { |
| 4652 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4653 | return use_sg; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4654 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4655 | |
| 4656 | if (use_sg) { |
| 4657 | curr_sg = cp->SG; |
| 4658 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 4659 | addr64 = (u64) sg_dma_address(sg); |
| 4660 | len = sg_dma_len(sg); |
| 4661 | total_len += len; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4662 | curr_sg->Addr = cpu_to_le64(addr64); |
| 4663 | curr_sg->Len = cpu_to_le32(len); |
| 4664 | curr_sg->Ext = cpu_to_le32(0); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4665 | curr_sg++; |
| 4666 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4667 | (--curr_sg)->Ext = cpu_to_le32(HPSA_SG_LAST); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4668 | |
| 4669 | switch (cmd->sc_data_direction) { |
| 4670 | case DMA_TO_DEVICE: |
| 4671 | control |= IOACCEL1_CONTROL_DATA_OUT; |
| 4672 | break; |
| 4673 | case DMA_FROM_DEVICE: |
| 4674 | control |= IOACCEL1_CONTROL_DATA_IN; |
| 4675 | break; |
| 4676 | case DMA_NONE: |
| 4677 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 4678 | break; |
| 4679 | default: |
| 4680 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 4681 | cmd->sc_data_direction); |
| 4682 | BUG(); |
| 4683 | break; |
| 4684 | } |
| 4685 | } else { |
| 4686 | control |= IOACCEL1_CONTROL_NODATAXFER; |
| 4687 | } |
| 4688 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4689 | c->Header.SGList = use_sg; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4690 | /* Fill out the command structure to submit */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4691 | cp->dev_handle = cpu_to_le16(ioaccel_handle & 0xFFFF); |
| 4692 | cp->transfer_len = cpu_to_le32(total_len); |
| 4693 | cp->io_flags = cpu_to_le16(IOACCEL1_IOFLAGS_IO_REQ | |
| 4694 | (cdb_len & IOACCEL1_IOFLAGS_CDBLEN_MASK)); |
| 4695 | cp->control = cpu_to_le32(control); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4696 | memcpy(cp->CDB, cdb, cdb_len); |
| 4697 | memcpy(cp->CISS_LUN, scsi3addr, 8); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4698 | /* Tag was already set at init time. */ |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4699 | enqueue_cmd_and_start_io(h, c); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 4700 | return 0; |
| 4701 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 4702 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4703 | /* |
| 4704 | * Queue a command directly to a device behind the controller using the |
| 4705 | * I/O accelerator path. |
| 4706 | */ |
| 4707 | static int hpsa_scsi_ioaccel_direct_map(struct ctlr_info *h, |
| 4708 | struct CommandList *c) |
| 4709 | { |
| 4710 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4711 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4712 | |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 4713 | if (!dev) |
| 4714 | return -1; |
| 4715 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4716 | c->phys_disk = dev; |
| 4717 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4718 | return hpsa_scsi_ioaccel_queue_command(h, c, dev->ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4719 | cmd->cmnd, cmd->cmd_len, dev->scsi3addr, dev); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4720 | } |
| 4721 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4722 | /* |
| 4723 | * Set encryption parameters for the ioaccel2 request |
| 4724 | */ |
| 4725 | static void set_encrypt_ioaccel2(struct ctlr_info *h, |
| 4726 | struct CommandList *c, struct io_accel2_cmd *cp) |
| 4727 | { |
| 4728 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4729 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4730 | struct raid_map_data *map = &dev->raid_map; |
| 4731 | u64 first_block; |
| 4732 | |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4733 | /* Are we doing encryption on this device */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4734 | if (!(le16_to_cpu(map->flags) & RAID_MAP_FLAG_ENCRYPT_ON)) |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4735 | return; |
| 4736 | /* Set the data encryption key index. */ |
| 4737 | cp->dekindex = map->dekindex; |
| 4738 | |
| 4739 | /* Set the encryption enable flag, encoded into direction field. */ |
| 4740 | cp->direction |= IOACCEL2_DIRECTION_ENCRYPT_MASK; |
| 4741 | |
| 4742 | /* Set encryption tweak values based on logical block address |
| 4743 | * If block size is 512, tweak value is LBA. |
| 4744 | * For other block sizes, tweak is (LBA * block size)/ 512) |
| 4745 | */ |
| 4746 | switch (cmd->cmnd[0]) { |
| 4747 | /* Required? 6-byte cdbs eliminated by fixup_ioaccel_cdb */ |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4748 | case READ_6: |
Mahesh Rajashekhara | abbada7 | 2016-09-16 14:54:23 -0500 | [diff] [blame] | 4749 | case WRITE_6: |
| 4750 | first_block = (((cmd->cmnd[1] & 0x1F) << 16) | |
| 4751 | (cmd->cmnd[2] << 8) | |
| 4752 | cmd->cmnd[3]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4753 | break; |
| 4754 | case WRITE_10: |
| 4755 | case READ_10: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4756 | /* Required? 12-byte cdbs eliminated by fixup_ioaccel_cdb */ |
| 4757 | case WRITE_12: |
| 4758 | case READ_12: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4759 | first_block = get_unaligned_be32(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4760 | break; |
| 4761 | case WRITE_16: |
| 4762 | case READ_16: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4763 | first_block = get_unaligned_be64(&cmd->cmnd[2]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4764 | break; |
| 4765 | default: |
| 4766 | dev_err(&h->pdev->dev, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4767 | "ERROR: %s: size (0x%x) not supported for encryption\n", |
| 4768 | __func__, cmd->cmnd[0]); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4769 | BUG(); |
| 4770 | break; |
| 4771 | } |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4772 | |
| 4773 | if (le32_to_cpu(map->volume_blk_size) != 512) |
| 4774 | first_block = first_block * |
| 4775 | le32_to_cpu(map->volume_blk_size)/512; |
| 4776 | |
| 4777 | cp->tweak_lower = cpu_to_le32(first_block); |
| 4778 | cp->tweak_upper = cpu_to_le32(first_block >> 32); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4779 | } |
| 4780 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4781 | static int hpsa_scsi_ioaccel2_queue_command(struct ctlr_info *h, |
| 4782 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4783 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4784 | { |
| 4785 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4786 | struct io_accel2_cmd *cp = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 4787 | struct ioaccel2_sg_element *curr_sg; |
| 4788 | int use_sg, i; |
| 4789 | struct scatterlist *sg; |
| 4790 | u64 addr64; |
| 4791 | u32 len; |
| 4792 | u32 total_len = 0; |
| 4793 | |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 4794 | if (!cmd->device) |
| 4795 | return -1; |
| 4796 | |
| 4797 | if (!cmd->device->hostdata) |
| 4798 | return -1; |
| 4799 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4800 | BUG_ON(scsi_sg_count(cmd) > h->maxsgentries); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4801 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4802 | if (fixup_ioaccel_cdb(cdb, &cdb_len)) { |
| 4803 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4804 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4805 | } |
| 4806 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4807 | c->cmd_type = CMD_IOACCEL2; |
| 4808 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 4809 | c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle + |
| 4810 | (c->cmdindex * sizeof(*cp)); |
| 4811 | BUG_ON(c->busaddr & 0x0000007F); |
| 4812 | |
| 4813 | memset(cp, 0, sizeof(*cp)); |
| 4814 | cp->IU_type = IOACCEL2_IU_TYPE; |
| 4815 | |
| 4816 | use_sg = scsi_dma_map(cmd); |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4817 | if (use_sg < 0) { |
| 4818 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4819 | return use_sg; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4820 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4821 | |
| 4822 | if (use_sg) { |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4823 | curr_sg = cp->sg; |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4824 | if (use_sg > h->ioaccel_maxsg) { |
| 4825 | addr64 = le64_to_cpu( |
| 4826 | h->ioaccel2_cmd_sg_list[c->cmdindex]->address); |
| 4827 | curr_sg->address = cpu_to_le64(addr64); |
| 4828 | curr_sg->length = 0; |
| 4829 | curr_sg->reserved[0] = 0; |
| 4830 | curr_sg->reserved[1] = 0; |
| 4831 | curr_sg->reserved[2] = 0; |
| 4832 | curr_sg->chain_indicator = 0x80; |
| 4833 | |
| 4834 | curr_sg = h->ioaccel2_cmd_sg_list[c->cmdindex]; |
| 4835 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4836 | scsi_for_each_sg(cmd, sg, use_sg, i) { |
| 4837 | addr64 = (u64) sg_dma_address(sg); |
| 4838 | len = sg_dma_len(sg); |
| 4839 | total_len += len; |
| 4840 | curr_sg->address = cpu_to_le64(addr64); |
| 4841 | curr_sg->length = cpu_to_le32(len); |
| 4842 | curr_sg->reserved[0] = 0; |
| 4843 | curr_sg->reserved[1] = 0; |
| 4844 | curr_sg->reserved[2] = 0; |
| 4845 | curr_sg->chain_indicator = 0; |
| 4846 | curr_sg++; |
| 4847 | } |
| 4848 | |
| 4849 | switch (cmd->sc_data_direction) { |
| 4850 | case DMA_TO_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4851 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4852 | cp->direction |= IOACCEL2_DIR_DATA_OUT; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4853 | break; |
| 4854 | case DMA_FROM_DEVICE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4855 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4856 | cp->direction |= IOACCEL2_DIR_DATA_IN; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4857 | break; |
| 4858 | case DMA_NONE: |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4859 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4860 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4861 | break; |
| 4862 | default: |
| 4863 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 4864 | cmd->sc_data_direction); |
| 4865 | BUG(); |
| 4866 | break; |
| 4867 | } |
| 4868 | } else { |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4869 | cp->direction &= ~IOACCEL2_DIRECTION_MASK; |
| 4870 | cp->direction |= IOACCEL2_DIR_NO_DATA; |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4871 | } |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 4872 | |
| 4873 | /* Set encryption parameters, if necessary */ |
| 4874 | set_encrypt_ioaccel2(h, c, cp); |
| 4875 | |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4876 | cp->scsi_nexus = cpu_to_le32(ioaccel_handle); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 4877 | cp->Tag = cpu_to_le32(c->cmdindex << DIRECT_LOOKUP_SHIFT); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4878 | memcpy(cp->cdb, cdb, sizeof(cp->cdb)); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4879 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4880 | cp->data_len = cpu_to_le32(total_len); |
| 4881 | cp->err_ptr = cpu_to_le64(c->busaddr + |
| 4882 | offsetof(struct io_accel2_cmd, error_data)); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 4883 | cp->err_len = cpu_to_le32(sizeof(cp->error_data)); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4884 | |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 4885 | /* fill in sg elements */ |
| 4886 | if (use_sg > h->ioaccel_maxsg) { |
| 4887 | cp->sg_count = 1; |
Don Brace | a736e9b | 2015-11-04 15:51:14 -0600 | [diff] [blame] | 4888 | 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] | 4889 | if (hpsa_map_ioaccel2_sg_chain_block(h, cp, c)) { |
| 4890 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
| 4891 | scsi_dma_unmap(cmd); |
| 4892 | return -1; |
| 4893 | } |
| 4894 | } else |
| 4895 | cp->sg_count = (u8) use_sg; |
| 4896 | |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4897 | enqueue_cmd_and_start_io(h, c); |
| 4898 | return 0; |
| 4899 | } |
| 4900 | |
| 4901 | /* |
| 4902 | * Queue a command to the correct I/O accelerator path. |
| 4903 | */ |
| 4904 | static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, |
| 4905 | struct CommandList *c, u32 ioaccel_handle, u8 *cdb, int cdb_len, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4906 | u8 *scsi3addr, struct hpsa_scsi_dev_t *phys_disk) |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4907 | { |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 4908 | if (!c->scsi_cmd->device) |
| 4909 | return -1; |
| 4910 | |
| 4911 | if (!c->scsi_cmd->device->hostdata) |
| 4912 | return -1; |
| 4913 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4914 | /* Try to honor the device's queue depth */ |
| 4915 | if (atomic_inc_return(&phys_disk->ioaccel_cmds_out) > |
| 4916 | phys_disk->queue_depth) { |
| 4917 | atomic_dec(&phys_disk->ioaccel_cmds_out); |
| 4918 | return IO_ACCEL_INELIGIBLE; |
| 4919 | } |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4920 | if (h->transMethod & CFGTBL_Trans_io_accel1) |
| 4921 | return hpsa_scsi_ioaccel1_queue_command(h, c, ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4922 | cdb, cdb_len, scsi3addr, |
| 4923 | phys_disk); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4924 | else |
| 4925 | return hpsa_scsi_ioaccel2_queue_command(h, c, ioaccel_handle, |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 4926 | cdb, cdb_len, scsi3addr, |
| 4927 | phys_disk); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 4928 | } |
| 4929 | |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4930 | static void raid_map_helper(struct raid_map_data *map, |
| 4931 | int offload_to_mirror, u32 *map_index, u32 *current_group) |
| 4932 | { |
| 4933 | if (offload_to_mirror == 0) { |
| 4934 | /* use physical disk in the first mirrored group. */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4935 | *map_index %= le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4936 | return; |
| 4937 | } |
| 4938 | do { |
| 4939 | /* determine mirror group that *map_index indicates */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4940 | *current_group = *map_index / |
| 4941 | le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4942 | if (offload_to_mirror == *current_group) |
| 4943 | continue; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4944 | if (*current_group < le16_to_cpu(map->layout_map_count) - 1) { |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4945 | /* select map index from next group */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4946 | *map_index += le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4947 | (*current_group)++; |
| 4948 | } else { |
| 4949 | /* select map index from first group */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4950 | *map_index %= le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4951 | *current_group = 0; |
| 4952 | } |
| 4953 | } while (offload_to_mirror != *current_group); |
| 4954 | } |
| 4955 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4956 | /* |
| 4957 | * Attempt to perform offload RAID mapping for a logical volume I/O. |
| 4958 | */ |
| 4959 | static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h, |
| 4960 | struct CommandList *c) |
| 4961 | { |
| 4962 | struct scsi_cmnd *cmd = c->scsi_cmd; |
| 4963 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 4964 | struct raid_map_data *map = &dev->raid_map; |
| 4965 | struct raid_map_disk_data *dd = &map->data[0]; |
| 4966 | int is_write = 0; |
| 4967 | u32 map_index; |
| 4968 | u64 first_block, last_block; |
| 4969 | u32 block_cnt; |
| 4970 | u32 blocks_per_row; |
| 4971 | u64 first_row, last_row; |
| 4972 | u32 first_row_offset, last_row_offset; |
| 4973 | u32 first_column, last_column; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4974 | u64 r0_first_row, r0_last_row; |
| 4975 | u32 r5or6_blocks_per_row; |
| 4976 | u64 r5or6_first_row, r5or6_last_row; |
| 4977 | u32 r5or6_first_row_offset, r5or6_last_row_offset; |
| 4978 | u32 r5or6_first_column, r5or6_last_column; |
| 4979 | u32 total_disks_per_row; |
| 4980 | u32 stripesize; |
| 4981 | u32 first_group, last_group, current_group; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4982 | u32 map_row; |
| 4983 | u32 disk_handle; |
| 4984 | u64 disk_block; |
| 4985 | u32 disk_block_cnt; |
| 4986 | u8 cdb[16]; |
| 4987 | u8 cdb_len; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 4988 | u16 strip_size; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4989 | #if BITS_PER_LONG == 32 |
| 4990 | u64 tmpdiv; |
| 4991 | #endif |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 4992 | int offload_to_mirror; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4993 | |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 4994 | if (!dev) |
| 4995 | return -1; |
| 4996 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 4997 | /* check for valid opcode, get LBA and block count */ |
| 4998 | switch (cmd->cmnd[0]) { |
| 4999 | case WRITE_6: |
| 5000 | is_write = 1; |
| 5001 | case READ_6: |
Mahesh Rajashekhara | abbada7 | 2016-09-16 14:54:23 -0500 | [diff] [blame] | 5002 | first_block = (((cmd->cmnd[1] & 0x1F) << 16) | |
| 5003 | (cmd->cmnd[2] << 8) | |
| 5004 | cmd->cmnd[3]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5005 | block_cnt = cmd->cmnd[4]; |
Stephen M. Cameron | 3fa89a0 | 2014-07-03 10:18:14 -0500 | [diff] [blame] | 5006 | if (block_cnt == 0) |
| 5007 | block_cnt = 256; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5008 | break; |
| 5009 | case WRITE_10: |
| 5010 | is_write = 1; |
| 5011 | case READ_10: |
| 5012 | first_block = |
| 5013 | (((u64) cmd->cmnd[2]) << 24) | |
| 5014 | (((u64) cmd->cmnd[3]) << 16) | |
| 5015 | (((u64) cmd->cmnd[4]) << 8) | |
| 5016 | cmd->cmnd[5]; |
| 5017 | block_cnt = |
| 5018 | (((u32) cmd->cmnd[7]) << 8) | |
| 5019 | cmd->cmnd[8]; |
| 5020 | break; |
| 5021 | case WRITE_12: |
| 5022 | is_write = 1; |
| 5023 | case READ_12: |
| 5024 | first_block = |
| 5025 | (((u64) cmd->cmnd[2]) << 24) | |
| 5026 | (((u64) cmd->cmnd[3]) << 16) | |
| 5027 | (((u64) cmd->cmnd[4]) << 8) | |
| 5028 | cmd->cmnd[5]; |
| 5029 | block_cnt = |
| 5030 | (((u32) cmd->cmnd[6]) << 24) | |
| 5031 | (((u32) cmd->cmnd[7]) << 16) | |
| 5032 | (((u32) cmd->cmnd[8]) << 8) | |
| 5033 | cmd->cmnd[9]; |
| 5034 | break; |
| 5035 | case WRITE_16: |
| 5036 | is_write = 1; |
| 5037 | case READ_16: |
| 5038 | first_block = |
| 5039 | (((u64) cmd->cmnd[2]) << 56) | |
| 5040 | (((u64) cmd->cmnd[3]) << 48) | |
| 5041 | (((u64) cmd->cmnd[4]) << 40) | |
| 5042 | (((u64) cmd->cmnd[5]) << 32) | |
| 5043 | (((u64) cmd->cmnd[6]) << 24) | |
| 5044 | (((u64) cmd->cmnd[7]) << 16) | |
| 5045 | (((u64) cmd->cmnd[8]) << 8) | |
| 5046 | cmd->cmnd[9]; |
| 5047 | block_cnt = |
| 5048 | (((u32) cmd->cmnd[10]) << 24) | |
| 5049 | (((u32) cmd->cmnd[11]) << 16) | |
| 5050 | (((u32) cmd->cmnd[12]) << 8) | |
| 5051 | cmd->cmnd[13]; |
| 5052 | break; |
| 5053 | default: |
| 5054 | return IO_ACCEL_INELIGIBLE; /* process via normal I/O path */ |
| 5055 | } |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5056 | last_block = first_block + block_cnt - 1; |
| 5057 | |
| 5058 | /* check for write to non-RAID-0 */ |
| 5059 | if (is_write && dev->raid_level != 0) |
| 5060 | return IO_ACCEL_INELIGIBLE; |
| 5061 | |
| 5062 | /* check for invalid block or wraparound */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5063 | if (last_block >= le64_to_cpu(map->volume_blk_cnt) || |
| 5064 | last_block < first_block) |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5065 | return IO_ACCEL_INELIGIBLE; |
| 5066 | |
| 5067 | /* calculate stripe information for the request */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5068 | blocks_per_row = le16_to_cpu(map->data_disks_per_row) * |
| 5069 | le16_to_cpu(map->strip_size); |
| 5070 | strip_size = le16_to_cpu(map->strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5071 | #if BITS_PER_LONG == 32 |
| 5072 | tmpdiv = first_block; |
| 5073 | (void) do_div(tmpdiv, blocks_per_row); |
| 5074 | first_row = tmpdiv; |
| 5075 | tmpdiv = last_block; |
| 5076 | (void) do_div(tmpdiv, blocks_per_row); |
| 5077 | last_row = tmpdiv; |
| 5078 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 5079 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
| 5080 | tmpdiv = first_row_offset; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5081 | (void) do_div(tmpdiv, strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5082 | first_column = tmpdiv; |
| 5083 | tmpdiv = last_row_offset; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5084 | (void) do_div(tmpdiv, strip_size); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5085 | last_column = tmpdiv; |
| 5086 | #else |
| 5087 | first_row = first_block / blocks_per_row; |
| 5088 | last_row = last_block / blocks_per_row; |
| 5089 | first_row_offset = (u32) (first_block - (first_row * blocks_per_row)); |
| 5090 | last_row_offset = (u32) (last_block - (last_row * blocks_per_row)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5091 | first_column = first_row_offset / strip_size; |
| 5092 | last_column = last_row_offset / strip_size; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5093 | #endif |
| 5094 | |
| 5095 | /* if this isn't a single row/column then give to the controller */ |
| 5096 | if ((first_row != last_row) || (first_column != last_column)) |
| 5097 | return IO_ACCEL_INELIGIBLE; |
| 5098 | |
| 5099 | /* proceeding with driver mapping */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5100 | total_disks_per_row = le16_to_cpu(map->data_disks_per_row) + |
| 5101 | le16_to_cpu(map->metadata_disks_per_row); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5102 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5103 | le16_to_cpu(map->row_cnt); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5104 | map_index = (map_row * total_disks_per_row) + first_column; |
| 5105 | |
| 5106 | switch (dev->raid_level) { |
| 5107 | case HPSA_RAID_0: |
| 5108 | break; /* nothing special to do */ |
| 5109 | case HPSA_RAID_1: |
| 5110 | /* Handles load balance across RAID 1 members. |
| 5111 | * (2-drive R1 and R10 with even # of drives.) |
| 5112 | * Appropriate for SSDs, not optimal for HDDs |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5113 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5114 | BUG_ON(le16_to_cpu(map->layout_map_count) != 2); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5115 | if (dev->offload_to_mirror) |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5116 | map_index += le16_to_cpu(map->data_disks_per_row); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5117 | dev->offload_to_mirror = !dev->offload_to_mirror; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5118 | break; |
| 5119 | case HPSA_RAID_ADM: |
| 5120 | /* Handles N-way mirrors (R1-ADM) |
| 5121 | * and R10 with # of drives divisible by 3.) |
| 5122 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5123 | BUG_ON(le16_to_cpu(map->layout_map_count) != 3); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5124 | |
| 5125 | offload_to_mirror = dev->offload_to_mirror; |
| 5126 | raid_map_helper(map, offload_to_mirror, |
| 5127 | &map_index, ¤t_group); |
| 5128 | /* set mirror group to use next time */ |
| 5129 | offload_to_mirror = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5130 | (offload_to_mirror >= |
| 5131 | le16_to_cpu(map->layout_map_count) - 1) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5132 | ? 0 : offload_to_mirror + 1; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5133 | dev->offload_to_mirror = offload_to_mirror; |
| 5134 | /* Avoid direct use of dev->offload_to_mirror within this |
| 5135 | * function since multiple threads might simultaneously |
| 5136 | * increment it beyond the range of dev->layout_map_count -1. |
| 5137 | */ |
| 5138 | break; |
| 5139 | case HPSA_RAID_5: |
| 5140 | case HPSA_RAID_6: |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5141 | if (le16_to_cpu(map->layout_map_count) <= 1) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5142 | break; |
| 5143 | |
| 5144 | /* Verify first and last block are in same RAID group */ |
| 5145 | r5or6_blocks_per_row = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5146 | le16_to_cpu(map->strip_size) * |
| 5147 | le16_to_cpu(map->data_disks_per_row); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5148 | BUG_ON(r5or6_blocks_per_row == 0); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5149 | stripesize = r5or6_blocks_per_row * |
| 5150 | le16_to_cpu(map->layout_map_count); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5151 | #if BITS_PER_LONG == 32 |
| 5152 | tmpdiv = first_block; |
| 5153 | first_group = do_div(tmpdiv, stripesize); |
| 5154 | tmpdiv = first_group; |
| 5155 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 5156 | first_group = tmpdiv; |
| 5157 | tmpdiv = last_block; |
| 5158 | last_group = do_div(tmpdiv, stripesize); |
| 5159 | tmpdiv = last_group; |
| 5160 | (void) do_div(tmpdiv, r5or6_blocks_per_row); |
| 5161 | last_group = tmpdiv; |
| 5162 | #else |
| 5163 | first_group = (first_block % stripesize) / r5or6_blocks_per_row; |
| 5164 | last_group = (last_block % stripesize) / r5or6_blocks_per_row; |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5165 | #endif |
Stephen M. Cameron | 000ff7c | 2014-03-13 17:12:50 -0500 | [diff] [blame] | 5166 | if (first_group != last_group) |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5167 | return IO_ACCEL_INELIGIBLE; |
| 5168 | |
| 5169 | /* Verify request is in a single row of RAID 5/6 */ |
| 5170 | #if BITS_PER_LONG == 32 |
| 5171 | tmpdiv = first_block; |
| 5172 | (void) do_div(tmpdiv, stripesize); |
| 5173 | first_row = r5or6_first_row = r0_first_row = tmpdiv; |
| 5174 | tmpdiv = last_block; |
| 5175 | (void) do_div(tmpdiv, stripesize); |
| 5176 | r5or6_last_row = r0_last_row = tmpdiv; |
| 5177 | #else |
| 5178 | first_row = r5or6_first_row = r0_first_row = |
| 5179 | first_block / stripesize; |
| 5180 | r5or6_last_row = r0_last_row = last_block / stripesize; |
| 5181 | #endif |
| 5182 | if (r5or6_first_row != r5or6_last_row) |
| 5183 | return IO_ACCEL_INELIGIBLE; |
| 5184 | |
| 5185 | |
| 5186 | /* Verify request is in a single column */ |
| 5187 | #if BITS_PER_LONG == 32 |
| 5188 | tmpdiv = first_block; |
| 5189 | first_row_offset = do_div(tmpdiv, stripesize); |
| 5190 | tmpdiv = first_row_offset; |
| 5191 | first_row_offset = (u32) do_div(tmpdiv, r5or6_blocks_per_row); |
| 5192 | r5or6_first_row_offset = first_row_offset; |
| 5193 | tmpdiv = last_block; |
| 5194 | r5or6_last_row_offset = do_div(tmpdiv, stripesize); |
| 5195 | tmpdiv = r5or6_last_row_offset; |
| 5196 | r5or6_last_row_offset = do_div(tmpdiv, r5or6_blocks_per_row); |
| 5197 | tmpdiv = r5or6_first_row_offset; |
| 5198 | (void) do_div(tmpdiv, map->strip_size); |
| 5199 | first_column = r5or6_first_column = tmpdiv; |
| 5200 | tmpdiv = r5or6_last_row_offset; |
| 5201 | (void) do_div(tmpdiv, map->strip_size); |
| 5202 | r5or6_last_column = tmpdiv; |
| 5203 | #else |
| 5204 | first_row_offset = r5or6_first_row_offset = |
| 5205 | (u32)((first_block % stripesize) % |
| 5206 | r5or6_blocks_per_row); |
| 5207 | |
| 5208 | r5or6_last_row_offset = |
| 5209 | (u32)((last_block % stripesize) % |
| 5210 | r5or6_blocks_per_row); |
| 5211 | |
| 5212 | first_column = r5or6_first_column = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5213 | r5or6_first_row_offset / le16_to_cpu(map->strip_size); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5214 | r5or6_last_column = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5215 | r5or6_last_row_offset / le16_to_cpu(map->strip_size); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5216 | #endif |
| 5217 | if (r5or6_first_column != r5or6_last_column) |
| 5218 | return IO_ACCEL_INELIGIBLE; |
| 5219 | |
| 5220 | /* Request is eligible */ |
| 5221 | map_row = ((u32)(first_row >> map->parity_rotation_shift)) % |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5222 | le16_to_cpu(map->row_cnt); |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5223 | |
| 5224 | map_index = (first_group * |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5225 | (le16_to_cpu(map->row_cnt) * total_disks_per_row)) + |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5226 | (map_row * total_disks_per_row) + first_column; |
| 5227 | break; |
| 5228 | default: |
| 5229 | return IO_ACCEL_INELIGIBLE; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5230 | } |
Scott Teel | 6b80b18 | 2014-02-18 13:56:55 -0600 | [diff] [blame] | 5231 | |
Stephen Cameron | 07543e0 | 2015-01-23 16:44:14 -0600 | [diff] [blame] | 5232 | if (unlikely(map_index >= RAID_MAP_MAX_ENTRIES)) |
| 5233 | return IO_ACCEL_INELIGIBLE; |
| 5234 | |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5235 | c->phys_disk = dev->phys_disk[map_index]; |
Don Brace | c3390df | 2016-02-23 15:16:34 -0600 | [diff] [blame] | 5236 | if (!c->phys_disk) |
| 5237 | return IO_ACCEL_INELIGIBLE; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5238 | |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5239 | disk_handle = dd[map_index].ioaccel_handle; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5240 | disk_block = le64_to_cpu(map->disk_starting_blk) + |
| 5241 | first_row * le16_to_cpu(map->strip_size) + |
| 5242 | (first_row_offset - first_column * |
| 5243 | le16_to_cpu(map->strip_size)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5244 | disk_block_cnt = block_cnt; |
| 5245 | |
| 5246 | /* handle differing logical/physical block sizes */ |
| 5247 | if (map->phys_blk_shift) { |
| 5248 | disk_block <<= map->phys_blk_shift; |
| 5249 | disk_block_cnt <<= map->phys_blk_shift; |
| 5250 | } |
| 5251 | BUG_ON(disk_block_cnt > 0xffff); |
| 5252 | |
| 5253 | /* build the new CDB for the physical disk I/O */ |
| 5254 | if (disk_block > 0xffffffff) { |
| 5255 | cdb[0] = is_write ? WRITE_16 : READ_16; |
| 5256 | cdb[1] = 0; |
| 5257 | cdb[2] = (u8) (disk_block >> 56); |
| 5258 | cdb[3] = (u8) (disk_block >> 48); |
| 5259 | cdb[4] = (u8) (disk_block >> 40); |
| 5260 | cdb[5] = (u8) (disk_block >> 32); |
| 5261 | cdb[6] = (u8) (disk_block >> 24); |
| 5262 | cdb[7] = (u8) (disk_block >> 16); |
| 5263 | cdb[8] = (u8) (disk_block >> 8); |
| 5264 | cdb[9] = (u8) (disk_block); |
| 5265 | cdb[10] = (u8) (disk_block_cnt >> 24); |
| 5266 | cdb[11] = (u8) (disk_block_cnt >> 16); |
| 5267 | cdb[12] = (u8) (disk_block_cnt >> 8); |
| 5268 | cdb[13] = (u8) (disk_block_cnt); |
| 5269 | cdb[14] = 0; |
| 5270 | cdb[15] = 0; |
| 5271 | cdb_len = 16; |
| 5272 | } else { |
| 5273 | cdb[0] = is_write ? WRITE_10 : READ_10; |
| 5274 | cdb[1] = 0; |
| 5275 | cdb[2] = (u8) (disk_block >> 24); |
| 5276 | cdb[3] = (u8) (disk_block >> 16); |
| 5277 | cdb[4] = (u8) (disk_block >> 8); |
| 5278 | cdb[5] = (u8) (disk_block); |
| 5279 | cdb[6] = 0; |
| 5280 | cdb[7] = (u8) (disk_block_cnt >> 8); |
| 5281 | cdb[8] = (u8) (disk_block_cnt); |
| 5282 | cdb[9] = 0; |
| 5283 | cdb_len = 10; |
| 5284 | } |
| 5285 | 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] | 5286 | dev->scsi3addr, |
| 5287 | dev->phys_disk[map_index]); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 5288 | } |
| 5289 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5290 | /* |
| 5291 | * Submit commands down the "normal" RAID stack path |
| 5292 | * All callers to hpsa_ciss_submit must check lockup_detected |
| 5293 | * beforehand, before (opt.) and after calling cmd_alloc |
| 5294 | */ |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5295 | static int hpsa_ciss_submit(struct ctlr_info *h, |
| 5296 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 5297 | unsigned char scsi3addr[]) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5298 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5299 | cmd->host_scribble = (unsigned char *) c; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5300 | c->cmd_type = CMD_SCSI; |
| 5301 | c->scsi_cmd = cmd; |
| 5302 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 5303 | memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 5304 | c->Header.tag = cpu_to_le64((c->cmdindex << DIRECT_LOOKUP_SHIFT)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5305 | |
| 5306 | /* Fill in the request block... */ |
| 5307 | |
| 5308 | c->Request.Timeout = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5309 | BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB)); |
| 5310 | c->Request.CDBLen = cmd->cmd_len; |
| 5311 | memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5312 | switch (cmd->sc_data_direction) { |
| 5313 | case DMA_TO_DEVICE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5314 | c->Request.type_attr_dir = |
| 5315 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5316 | break; |
| 5317 | case DMA_FROM_DEVICE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5318 | c->Request.type_attr_dir = |
| 5319 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5320 | break; |
| 5321 | case DMA_NONE: |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5322 | c->Request.type_attr_dir = |
| 5323 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5324 | break; |
| 5325 | case DMA_BIDIRECTIONAL: |
| 5326 | /* This can happen if a buggy application does a scsi passthru |
| 5327 | * and sets both inlen and outlen to non-zero. ( see |
| 5328 | * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) |
| 5329 | */ |
| 5330 | |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 5331 | c->Request.type_attr_dir = |
| 5332 | TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_RSVD); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5333 | /* This is technically wrong, and hpsa controllers should |
| 5334 | * reject it with CMD_INVALID, which is the most correct |
| 5335 | * response, but non-fibre backends appear to let it |
| 5336 | * slide by, and give the same results as if this field |
| 5337 | * were set correctly. Either way is acceptable for |
| 5338 | * our purposes here. |
| 5339 | */ |
| 5340 | |
| 5341 | break; |
| 5342 | |
| 5343 | default: |
| 5344 | dev_err(&h->pdev->dev, "unknown data direction: %d\n", |
| 5345 | cmd->sc_data_direction); |
| 5346 | BUG(); |
| 5347 | break; |
| 5348 | } |
| 5349 | |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 5350 | if (hpsa_scatter_gather(h, c, cmd) < 0) { /* Fill SG list */ |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5351 | hpsa_cmd_resolve_and_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5352 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5353 | } |
| 5354 | enqueue_cmd_and_start_io(h, c); |
| 5355 | /* the cmd'll come back via intr handler in complete_scsi_command() */ |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 5359 | static void hpsa_cmd_init(struct ctlr_info *h, int index, |
| 5360 | struct CommandList *c) |
| 5361 | { |
| 5362 | dma_addr_t cmd_dma_handle, err_dma_handle; |
| 5363 | |
| 5364 | /* Zero out all of commandlist except the last field, refcount */ |
| 5365 | memset(c, 0, offsetof(struct CommandList, refcount)); |
| 5366 | c->Header.tag = cpu_to_le64((u64) (index << DIRECT_LOOKUP_SHIFT)); |
| 5367 | cmd_dma_handle = h->cmd_pool_dhandle + index * sizeof(*c); |
| 5368 | c->err_info = h->errinfo_pool + index; |
| 5369 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 5370 | err_dma_handle = h->errinfo_pool_dhandle |
| 5371 | + index * sizeof(*c->err_info); |
| 5372 | c->cmdindex = index; |
| 5373 | c->busaddr = (u32) cmd_dma_handle; |
| 5374 | c->ErrDesc.Addr = cpu_to_le64((u64) err_dma_handle); |
| 5375 | c->ErrDesc.Len = cpu_to_le32((u32) sizeof(*c->err_info)); |
| 5376 | c->h = h; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5377 | c->scsi_cmd = SCSI_CMD_IDLE; |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | static void hpsa_preinitialize_commands(struct ctlr_info *h) |
| 5381 | { |
| 5382 | int i; |
| 5383 | |
| 5384 | for (i = 0; i < h->nr_cmds; i++) { |
| 5385 | struct CommandList *c = h->cmd_pool + i; |
| 5386 | |
| 5387 | hpsa_cmd_init(h, i, c); |
| 5388 | atomic_set(&c->refcount, 0); |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | static inline void hpsa_cmd_partial_init(struct ctlr_info *h, int index, |
| 5393 | struct CommandList *c) |
| 5394 | { |
| 5395 | dma_addr_t cmd_dma_handle = h->cmd_pool_dhandle + index * sizeof(*c); |
| 5396 | |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5397 | BUG_ON(c->cmdindex != index); |
| 5398 | |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 5399 | memset(c->Request.CDB, 0, sizeof(c->Request.CDB)); |
| 5400 | memset(c->err_info, 0, sizeof(*c->err_info)); |
| 5401 | c->busaddr = (u32) cmd_dma_handle; |
| 5402 | } |
| 5403 | |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5404 | static int hpsa_ioaccel_submit(struct ctlr_info *h, |
| 5405 | struct CommandList *c, struct scsi_cmnd *cmd, |
| 5406 | unsigned char *scsi3addr) |
| 5407 | { |
| 5408 | struct hpsa_scsi_dev_t *dev = cmd->device->hostdata; |
| 5409 | int rc = IO_ACCEL_INELIGIBLE; |
| 5410 | |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 5411 | if (!dev) |
| 5412 | return SCSI_MLQUEUE_HOST_BUSY; |
| 5413 | |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5414 | cmd->host_scribble = (unsigned char *) c; |
| 5415 | |
| 5416 | if (dev->offload_enabled) { |
| 5417 | hpsa_cmd_init(h, c->cmdindex, c); |
| 5418 | c->cmd_type = CMD_SCSI; |
| 5419 | c->scsi_cmd = cmd; |
| 5420 | rc = hpsa_scsi_ioaccel_raid_map(h, c); |
| 5421 | if (rc < 0) /* scsi_dma_map failed. */ |
| 5422 | rc = SCSI_MLQUEUE_HOST_BUSY; |
Joe Handzik | a3144e0 | 2015-04-23 09:32:59 -0500 | [diff] [blame] | 5423 | } else if (dev->hba_ioaccel_enabled) { |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5424 | hpsa_cmd_init(h, c->cmdindex, c); |
| 5425 | c->cmd_type = CMD_SCSI; |
| 5426 | c->scsi_cmd = cmd; |
| 5427 | rc = hpsa_scsi_ioaccel_direct_map(h, c); |
| 5428 | if (rc < 0) /* scsi_dma_map failed. */ |
| 5429 | rc = SCSI_MLQUEUE_HOST_BUSY; |
| 5430 | } |
| 5431 | return rc; |
| 5432 | } |
| 5433 | |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 5434 | static void hpsa_command_resubmit_worker(struct work_struct *work) |
| 5435 | { |
| 5436 | struct scsi_cmnd *cmd; |
| 5437 | struct hpsa_scsi_dev_t *dev; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 5438 | struct CommandList *c = container_of(work, struct CommandList, work); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 5439 | |
| 5440 | cmd = c->scsi_cmd; |
| 5441 | dev = cmd->device->hostdata; |
| 5442 | if (!dev) { |
| 5443 | cmd->result = DID_NO_CONNECT << 16; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 5444 | return hpsa_cmd_free_and_done(c->h, c, cmd); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 5445 | } |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5446 | if (c->reset_pending) |
| 5447 | return hpsa_cmd_resolve_and_free(c->h, c); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5448 | if (c->abort_pending) |
| 5449 | return hpsa_cmd_abort_and_free(c->h, c, cmd); |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5450 | if (c->cmd_type == CMD_IOACCEL2) { |
| 5451 | struct ctlr_info *h = c->h; |
| 5452 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 5453 | int rc; |
| 5454 | |
| 5455 | if (c2->error_data.serv_response == |
| 5456 | IOACCEL2_STATUS_SR_TASK_COMP_SET_FULL) { |
| 5457 | rc = hpsa_ioaccel_submit(h, c, cmd, dev->scsi3addr); |
| 5458 | if (rc == 0) |
| 5459 | return; |
| 5460 | if (rc == SCSI_MLQUEUE_HOST_BUSY) { |
| 5461 | /* |
| 5462 | * If we get here, it means dma mapping failed. |
| 5463 | * Try again via scsi mid layer, which will |
| 5464 | * then get SCSI_MLQUEUE_HOST_BUSY. |
| 5465 | */ |
| 5466 | cmd->result = DID_IMM_RETRY << 16; |
Webb Scales | 8a0ff92 | 2015-04-23 09:34:11 -0500 | [diff] [blame] | 5467 | return hpsa_cmd_free_and_done(h, c, cmd); |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5468 | } |
| 5469 | /* else, fall thru and resubmit down CISS path */ |
| 5470 | } |
| 5471 | } |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 5472 | hpsa_cmd_partial_init(c->h, c->cmdindex, c); |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 5473 | if (hpsa_ciss_submit(c->h, c, cmd, dev->scsi3addr)) { |
| 5474 | /* |
| 5475 | * If we get here, it means dma mapping failed. Try |
| 5476 | * again via scsi mid layer, which will then get |
| 5477 | * SCSI_MLQUEUE_HOST_BUSY. |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5478 | * |
| 5479 | * hpsa_ciss_submit will have already freed c |
| 5480 | * if it encountered a dma mapping failure. |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 5481 | */ |
| 5482 | cmd->result = DID_IMM_RETRY << 16; |
| 5483 | cmd->scsi_done(cmd); |
| 5484 | } |
| 5485 | } |
| 5486 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5487 | /* Running in struct Scsi_Host->host_lock less mode */ |
| 5488 | static int hpsa_scsi_queue_command(struct Scsi_Host *sh, struct scsi_cmnd *cmd) |
| 5489 | { |
| 5490 | struct ctlr_info *h; |
| 5491 | struct hpsa_scsi_dev_t *dev; |
| 5492 | unsigned char scsi3addr[8]; |
| 5493 | struct CommandList *c; |
| 5494 | int rc = 0; |
| 5495 | |
| 5496 | /* Get the ptr to our adapter structure out of cmd->host. */ |
| 5497 | h = sdev_to_hba(cmd->device); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5498 | |
| 5499 | BUG_ON(cmd->request->tag < 0); |
| 5500 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5501 | dev = cmd->device->hostdata; |
| 5502 | if (!dev) { |
Hannes Reinecke | 1ccde70 | 2016-11-18 08:32:47 +0100 | [diff] [blame] | 5503 | cmd->result = DID_NO_CONNECT << 16; |
Don Brace | ba74fdc | 2016-04-27 17:14:17 -0500 | [diff] [blame] | 5504 | cmd->scsi_done(cmd); |
| 5505 | return 0; |
| 5506 | } |
| 5507 | |
| 5508 | if (dev->removed) { |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5509 | cmd->result = DID_NO_CONNECT << 16; |
| 5510 | cmd->scsi_done(cmd); |
| 5511 | return 0; |
| 5512 | } |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5513 | |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5514 | memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); |
| 5515 | |
| 5516 | if (unlikely(lockup_detected(h))) { |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5517 | cmd->result = DID_NO_CONNECT << 16; |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5518 | cmd->scsi_done(cmd); |
| 5519 | return 0; |
| 5520 | } |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5521 | c = cmd_tagged_alloc(h, cmd); |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5522 | |
Stephen Cameron | 407863c | 2015-01-23 16:44:19 -0600 | [diff] [blame] | 5523 | /* |
| 5524 | * Call alternate submit routine for I/O accelerated commands. |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5525 | * Retries always go down the normal I/O path. |
| 5526 | */ |
| 5527 | if (likely(cmd->retries == 0 && |
| 5528 | cmd->request->cmd_type == REQ_TYPE_FS && |
| 5529 | h->acciopath_status)) { |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5530 | rc = hpsa_ioaccel_submit(h, c, cmd, scsi3addr); |
| 5531 | if (rc == 0) |
| 5532 | return 0; |
| 5533 | if (rc == SCSI_MLQUEUE_HOST_BUSY) { |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5534 | hpsa_cmd_resolve_and_free(h, c); |
Webb Scales | 592a0ad | 2015-04-23 09:32:48 -0500 | [diff] [blame] | 5535 | return SCSI_MLQUEUE_HOST_BUSY; |
Stephen Cameron | 574f05d | 2015-01-23 16:43:20 -0600 | [diff] [blame] | 5536 | } |
| 5537 | } |
| 5538 | return hpsa_ciss_submit(h, c, cmd, scsi3addr); |
| 5539 | } |
| 5540 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5541 | static void hpsa_scan_complete(struct ctlr_info *h) |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5542 | { |
| 5543 | unsigned long flags; |
| 5544 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5545 | spin_lock_irqsave(&h->scan_lock, flags); |
| 5546 | h->scan_finished = 1; |
| 5547 | wake_up_all(&h->scan_wait_queue); |
| 5548 | spin_unlock_irqrestore(&h->scan_lock, flags); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5549 | } |
| 5550 | |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5551 | static void hpsa_scan_start(struct Scsi_Host *sh) |
| 5552 | { |
| 5553 | struct ctlr_info *h = shost_to_hba(sh); |
| 5554 | unsigned long flags; |
| 5555 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5556 | /* |
| 5557 | * Don't let rescans be initiated on a controller known to be locked |
| 5558 | * up. If the controller locks up *during* a rescan, that thread is |
| 5559 | * probably hosed, but at least we can prevent new rescan threads from |
| 5560 | * piling up on a locked up controller. |
| 5561 | */ |
| 5562 | if (unlikely(lockup_detected(h))) |
| 5563 | return hpsa_scan_complete(h); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5564 | |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5565 | /* wait until any scan already in progress is finished. */ |
| 5566 | while (1) { |
| 5567 | spin_lock_irqsave(&h->scan_lock, flags); |
| 5568 | if (h->scan_finished) |
| 5569 | break; |
| 5570 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 5571 | wait_event(h->scan_wait_queue, h->scan_finished); |
| 5572 | /* Note: We don't need to worry about a race between this |
| 5573 | * thread and driver unload because the midlayer will |
| 5574 | * have incremented the reference count, so unload won't |
| 5575 | * happen if we're in here. |
| 5576 | */ |
| 5577 | } |
| 5578 | h->scan_finished = 0; /* mark scan as in progress */ |
| 5579 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 5580 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5581 | if (unlikely(lockup_detected(h))) |
| 5582 | return hpsa_scan_complete(h); |
Stephen M. Cameron | 5f38936 | 2014-02-18 13:55:48 -0600 | [diff] [blame] | 5583 | |
Don Brace | bfd7546 | 2016-11-15 14:45:32 -0600 | [diff] [blame] | 5584 | /* |
| 5585 | * Do the scan after a reset completion |
| 5586 | */ |
| 5587 | if (h->reset_in_progress) { |
| 5588 | h->drv_req_rescan = 1; |
| 5589 | return; |
| 5590 | } |
| 5591 | |
Don Brace | 8aa6068 | 2015-11-04 15:50:01 -0600 | [diff] [blame] | 5592 | hpsa_update_scsi_devices(h); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5593 | |
Webb Scales | 8ebc924 | 2015-01-23 16:44:50 -0600 | [diff] [blame] | 5594 | hpsa_scan_complete(h); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5595 | } |
| 5596 | |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 5597 | static int hpsa_change_queue_depth(struct scsi_device *sdev, int qdepth) |
| 5598 | { |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5599 | struct hpsa_scsi_dev_t *logical_drive = sdev->hostdata; |
| 5600 | |
| 5601 | if (!logical_drive) |
| 5602 | return -ENODEV; |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 5603 | |
| 5604 | if (qdepth < 1) |
| 5605 | qdepth = 1; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5606 | else if (qdepth > logical_drive->queue_depth) |
| 5607 | qdepth = logical_drive->queue_depth; |
| 5608 | |
| 5609 | return scsi_change_queue_depth(sdev, qdepth); |
Don Brace | 7c0a022 | 2015-01-23 16:41:30 -0600 | [diff] [blame] | 5610 | } |
| 5611 | |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 5612 | static int hpsa_scan_finished(struct Scsi_Host *sh, |
| 5613 | unsigned long elapsed_time) |
| 5614 | { |
| 5615 | struct ctlr_info *h = shost_to_hba(sh); |
| 5616 | unsigned long flags; |
| 5617 | int finished; |
| 5618 | |
| 5619 | spin_lock_irqsave(&h->scan_lock, flags); |
| 5620 | finished = h->scan_finished; |
| 5621 | spin_unlock_irqrestore(&h->scan_lock, flags); |
| 5622 | return finished; |
| 5623 | } |
| 5624 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5625 | static int hpsa_scsi_host_alloc(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5626 | { |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5627 | struct Scsi_Host *sh; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5628 | |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5629 | sh = scsi_host_alloc(&hpsa_driver_template, sizeof(h)); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5630 | if (sh == NULL) { |
| 5631 | dev_err(&h->pdev->dev, "scsi_host_alloc failed\n"); |
| 5632 | return -ENOMEM; |
| 5633 | } |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5634 | |
| 5635 | sh->io_port = 0; |
| 5636 | sh->n_io_port = 0; |
| 5637 | sh->this_id = -1; |
| 5638 | sh->max_channel = 3; |
| 5639 | sh->max_cmd_len = MAX_COMMAND_SIZE; |
| 5640 | sh->max_lun = HPSA_MAX_LUN; |
| 5641 | sh->max_id = HPSA_MAX_LUN; |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 5642 | sh->can_queue = h->nr_cmds - HPSA_NRESERVED_CMDS; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 5643 | sh->cmd_per_lun = sh->can_queue; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5644 | sh->sg_tablesize = h->maxsgentries; |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 5645 | sh->transportt = hpsa_sas_transport_template; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5646 | sh->hostdata[0] = (unsigned long) h; |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 5647 | sh->irq = pci_irq_vector(h->pdev, 0); |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5648 | sh->unique_id = sh->irq; |
Christoph Hellwig | 64d513ac | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 5649 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5650 | h->scsi_host = sh; |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5651 | return 0; |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5652 | } |
Stephen M. Cameron | b705690 | 2012-01-19 14:00:53 -0600 | [diff] [blame] | 5653 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 5654 | static int hpsa_scsi_add_host(struct ctlr_info *h) |
| 5655 | { |
| 5656 | int rv; |
| 5657 | |
| 5658 | rv = scsi_add_host(h->scsi_host, &h->pdev->dev); |
| 5659 | if (rv) { |
| 5660 | dev_err(&h->pdev->dev, "scsi_add_host failed\n"); |
| 5661 | return rv; |
| 5662 | } |
| 5663 | scsi_scan_host(h->scsi_host); |
| 5664 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5665 | } |
| 5666 | |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5667 | /* |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5668 | * The block layer has already gone to the trouble of picking out a unique, |
| 5669 | * small-integer tag for this request. We use an offset from that value as |
| 5670 | * an index to select our command block. (The offset allows us to reserve the |
| 5671 | * low-numbered entries for our own uses.) |
| 5672 | */ |
| 5673 | static int hpsa_get_cmd_index(struct scsi_cmnd *scmd) |
| 5674 | { |
| 5675 | int idx = scmd->request->tag; |
| 5676 | |
| 5677 | if (idx < 0) |
| 5678 | return idx; |
| 5679 | |
| 5680 | /* Offset to leave space for internal cmds. */ |
| 5681 | return idx += HPSA_NRESERVED_CMDS; |
| 5682 | } |
| 5683 | |
| 5684 | /* |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5685 | * Send a TEST_UNIT_READY command to the specified LUN using the specified |
| 5686 | * reply queue; returns zero if the unit is ready, and non-zero otherwise. |
| 5687 | */ |
| 5688 | static int hpsa_send_test_unit_ready(struct ctlr_info *h, |
| 5689 | struct CommandList *c, unsigned char lunaddr[], |
| 5690 | int reply_queue) |
| 5691 | { |
| 5692 | int rc; |
| 5693 | |
| 5694 | /* Send the Test Unit Ready, fill_cmd can't fail, no mapping */ |
| 5695 | (void) fill_cmd(c, TEST_UNIT_READY, h, |
| 5696 | NULL, 0, 0, lunaddr, TYPE_CMD); |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 5697 | rc = hpsa_scsi_do_simple_cmd(h, c, reply_queue, DEFAULT_TIMEOUT); |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5698 | if (rc) |
| 5699 | return rc; |
| 5700 | /* no unmap needed here because no data xfer. */ |
| 5701 | |
| 5702 | /* Check if the unit is already ready. */ |
| 5703 | if (c->err_info->CommandStatus == CMD_SUCCESS) |
| 5704 | return 0; |
| 5705 | |
| 5706 | /* |
| 5707 | * The first command sent after reset will receive "unit attention" to |
| 5708 | * indicate that the LUN has been reset...this is actually what we're |
| 5709 | * looking for (but, success is good too). |
| 5710 | */ |
| 5711 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 5712 | c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION && |
| 5713 | (c->err_info->SenseInfo[2] == NO_SENSE || |
| 5714 | c->err_info->SenseInfo[2] == UNIT_ATTENTION)) |
| 5715 | return 0; |
| 5716 | |
| 5717 | return 1; |
| 5718 | } |
| 5719 | |
| 5720 | /* |
| 5721 | * Wait for a TEST_UNIT_READY command to complete, retrying as necessary; |
| 5722 | * returns zero when the unit is ready, and non-zero when giving up. |
| 5723 | */ |
| 5724 | static int hpsa_wait_for_test_unit_ready(struct ctlr_info *h, |
| 5725 | struct CommandList *c, |
| 5726 | unsigned char lunaddr[], int reply_queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5727 | { |
Tomas Henzl | 8919358 | 2014-02-21 16:25:05 -0600 | [diff] [blame] | 5728 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5729 | int count = 0; |
| 5730 | int waittime = 1; /* seconds */ |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5731 | |
| 5732 | /* Send test unit ready until device ready, or give up. */ |
| 5733 | for (count = 0; count < HPSA_TUR_RETRY_LIMIT; count++) { |
| 5734 | |
| 5735 | /* |
| 5736 | * Wait for a bit. do this first, because if we send |
| 5737 | * the TUR right away, the reset will just abort it. |
| 5738 | */ |
| 5739 | msleep(1000 * waittime); |
| 5740 | |
| 5741 | rc = hpsa_send_test_unit_ready(h, c, lunaddr, reply_queue); |
| 5742 | if (!rc) |
| 5743 | break; |
| 5744 | |
| 5745 | /* Increase wait time with each try, up to a point. */ |
| 5746 | if (waittime < HPSA_MAX_WAIT_INTERVAL_SECS) |
| 5747 | waittime *= 2; |
| 5748 | |
| 5749 | dev_warn(&h->pdev->dev, |
| 5750 | "waiting %d secs for device to become ready.\n", |
| 5751 | waittime); |
| 5752 | } |
| 5753 | |
| 5754 | return rc; |
| 5755 | } |
| 5756 | |
| 5757 | static int wait_for_device_to_become_ready(struct ctlr_info *h, |
| 5758 | unsigned char lunaddr[], |
| 5759 | int reply_queue) |
| 5760 | { |
| 5761 | int first_queue; |
| 5762 | int last_queue; |
| 5763 | int rq; |
| 5764 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5765 | struct CommandList *c; |
| 5766 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5767 | c = cmd_alloc(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5768 | |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5769 | /* |
| 5770 | * If no specific reply queue was requested, then send the TUR |
| 5771 | * repeatedly, requesting a reply on each reply queue; otherwise execute |
| 5772 | * the loop exactly once using only the specified queue. |
| 5773 | */ |
| 5774 | if (reply_queue == DEFAULT_REPLY_QUEUE) { |
| 5775 | first_queue = 0; |
| 5776 | last_queue = h->nreply_queues - 1; |
| 5777 | } else { |
| 5778 | first_queue = reply_queue; |
| 5779 | last_queue = reply_queue; |
| 5780 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5781 | |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 5782 | for (rq = first_queue; rq <= last_queue; rq++) { |
| 5783 | rc = hpsa_wait_for_test_unit_ready(h, c, lunaddr, rq); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5784 | if (rc) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5785 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | if (rc) |
| 5789 | dev_warn(&h->pdev->dev, "giving up on device.\n"); |
| 5790 | else |
| 5791 | dev_warn(&h->pdev->dev, "device is ready.\n"); |
| 5792 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5793 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5794 | return rc; |
| 5795 | } |
| 5796 | |
| 5797 | /* Need at least one of these error handlers to keep ../scsi/hosts.c from |
| 5798 | * complaining. Doing a host- or bus-reset can't do anything good here. |
| 5799 | */ |
| 5800 | static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) |
| 5801 | { |
| 5802 | int rc; |
| 5803 | struct ctlr_info *h; |
| 5804 | struct hpsa_scsi_dev_t *dev; |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5805 | u8 reset_type; |
Dan Carpenter | 2dc127b | 2015-06-04 17:47:56 +0300 | [diff] [blame] | 5806 | char msg[48]; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5807 | |
| 5808 | /* find the controller to which the command to be aborted was sent */ |
| 5809 | h = sdev_to_hba(scsicmd->device); |
| 5810 | if (h == NULL) /* paranoia */ |
| 5811 | return FAILED; |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 5812 | |
| 5813 | if (lockup_detected(h)) |
| 5814 | return FAILED; |
| 5815 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5816 | dev = scsicmd->device->hostdata; |
| 5817 | if (!dev) { |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5818 | dev_err(&h->pdev->dev, "%s: device lookup failed\n", __func__); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5819 | return FAILED; |
| 5820 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5821 | |
| 5822 | /* if controller locked up, we can guarantee command won't complete */ |
| 5823 | if (lockup_detected(h)) { |
Dan Carpenter | 2dc127b | 2015-06-04 17:47:56 +0300 | [diff] [blame] | 5824 | snprintf(msg, sizeof(msg), |
| 5825 | "cmd %d RESET FAILED, lockup detected", |
| 5826 | hpsa_get_cmd_index(scsicmd)); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5827 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5828 | return FAILED; |
| 5829 | } |
| 5830 | |
| 5831 | /* this reset request might be the result of a lockup; check */ |
| 5832 | if (detect_controller_lockup(h)) { |
Dan Carpenter | 2dc127b | 2015-06-04 17:47:56 +0300 | [diff] [blame] | 5833 | snprintf(msg, sizeof(msg), |
| 5834 | "cmd %d RESET FAILED, new lockup detected", |
| 5835 | hpsa_get_cmd_index(scsicmd)); |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 5836 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5837 | return FAILED; |
| 5838 | } |
| 5839 | |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5840 | /* Do not attempt on controller */ |
| 5841 | if (is_hba_lunid(dev->scsi3addr)) |
| 5842 | return SUCCESS; |
| 5843 | |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5844 | if (is_logical_dev_addr_mode(dev->scsi3addr)) |
| 5845 | reset_type = HPSA_DEVICE_RESET_MSG; |
| 5846 | else |
| 5847 | reset_type = HPSA_PHYS_TARGET_RESET; |
| 5848 | |
| 5849 | sprintf(msg, "resetting %s", |
| 5850 | reset_type == HPSA_DEVICE_RESET_MSG ? "logical " : "physical "); |
| 5851 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5852 | |
Don Brace | da03ded | 2015-11-04 15:50:56 -0600 | [diff] [blame] | 5853 | h->reset_in_progress = 1; |
Stephen M. Cameron | d416b0c | 2010-02-04 08:43:21 -0600 | [diff] [blame] | 5854 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5855 | /* 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] | 5856 | rc = hpsa_do_reset(h, dev, dev->scsi3addr, reset_type, |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5857 | DEFAULT_REPLY_QUEUE); |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 5858 | sprintf(msg, "reset %s %s", |
| 5859 | reset_type == HPSA_DEVICE_RESET_MSG ? "logical " : "physical ", |
| 5860 | rc == 0 ? "completed successfully" : "failed"); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5861 | hpsa_show_dev_msg(KERN_WARNING, h, dev, msg); |
Don Brace | da03ded | 2015-11-04 15:50:56 -0600 | [diff] [blame] | 5862 | h->reset_in_progress = 0; |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 5863 | return rc == 0 ? SUCCESS : FAILED; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 5864 | } |
| 5865 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5866 | static void swizzle_abort_tag(u8 *tag) |
| 5867 | { |
| 5868 | u8 original_tag[8]; |
| 5869 | |
| 5870 | memcpy(original_tag, tag, 8); |
| 5871 | tag[0] = original_tag[3]; |
| 5872 | tag[1] = original_tag[2]; |
| 5873 | tag[2] = original_tag[1]; |
| 5874 | tag[3] = original_tag[0]; |
| 5875 | tag[4] = original_tag[7]; |
| 5876 | tag[5] = original_tag[6]; |
| 5877 | tag[6] = original_tag[5]; |
| 5878 | tag[7] = original_tag[4]; |
| 5879 | } |
| 5880 | |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5881 | static void hpsa_get_tag(struct ctlr_info *h, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5882 | struct CommandList *c, __le32 *taglower, __le32 *tagupper) |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5883 | { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5884 | u64 tag; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5885 | if (c->cmd_type == CMD_IOACCEL1) { |
| 5886 | struct io_accel1_cmd *cm1 = (struct io_accel1_cmd *) |
| 5887 | &h->ioaccel_cmd_pool[c->cmdindex]; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5888 | tag = le64_to_cpu(cm1->tag); |
| 5889 | *tagupper = cpu_to_le32(tag >> 32); |
| 5890 | *taglower = cpu_to_le32(tag); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5891 | return; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5892 | } |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5893 | if (c->cmd_type == CMD_IOACCEL2) { |
| 5894 | struct io_accel2_cmd *cm2 = (struct io_accel2_cmd *) |
| 5895 | &h->ioaccel2_cmd_pool[c->cmdindex]; |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 5896 | /* upper tag not used in ioaccel2 mode */ |
| 5897 | memset(tagupper, 0, sizeof(*tagupper)); |
| 5898 | *taglower = cm2->Tag; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5899 | return; |
| 5900 | } |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5901 | tag = le64_to_cpu(c->Header.tag); |
| 5902 | *tagupper = cpu_to_le32(tag >> 32); |
| 5903 | *taglower = cpu_to_le32(tag); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5904 | } |
| 5905 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5906 | static int hpsa_send_abort(struct ctlr_info *h, unsigned char *scsi3addr, |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5907 | struct CommandList *abort, int reply_queue) |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5908 | { |
| 5909 | int rc = IO_OK; |
| 5910 | struct CommandList *c; |
| 5911 | struct ErrorInfo *ei; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 5912 | __le32 tagupper, taglower; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5913 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5914 | c = cmd_alloc(h); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5915 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5916 | /* fill_cmd can't fail here, no buffer to map */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5917 | (void) fill_cmd(c, HPSA_ABORT_MSG, h, &abort->Header.tag, |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 5918 | 0, 0, scsi3addr, TYPE_MSG); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 5919 | if (h->needs_abort_tags_swizzled) |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 5920 | swizzle_abort_tag(&c->Request.CDB[4]); |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 5921 | (void) hpsa_scsi_do_simple_cmd(h, c, reply_queue, DEFAULT_TIMEOUT); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 5922 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 5923 | 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] | 5924 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5925 | /* no unmap needed here because no data xfer. */ |
| 5926 | |
| 5927 | ei = c->err_info; |
| 5928 | switch (ei->CommandStatus) { |
| 5929 | case CMD_SUCCESS: |
| 5930 | break; |
Stephen Cameron | 9437ac4 | 2015-04-23 09:32:16 -0500 | [diff] [blame] | 5931 | case CMD_TMF_STATUS: |
| 5932 | rc = hpsa_evaluate_tmf_status(h, c); |
| 5933 | break; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5934 | case CMD_UNABORTABLE: /* Very common, don't make noise. */ |
| 5935 | rc = -1; |
| 5936 | break; |
| 5937 | default: |
| 5938 | 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] | 5939 | __func__, tagupper, taglower); |
Stephen M. Cameron | d1e8bea | 2014-02-18 13:57:47 -0600 | [diff] [blame] | 5940 | hpsa_scsi_interpret_error(h, c); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5941 | rc = -1; |
| 5942 | break; |
| 5943 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 5944 | cmd_free(h, c); |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 5945 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", |
| 5946 | __func__, tagupper, taglower); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 5947 | return rc; |
| 5948 | } |
| 5949 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5950 | static void setup_ioaccel2_abort_cmd(struct CommandList *c, struct ctlr_info *h, |
| 5951 | struct CommandList *command_to_abort, int reply_queue) |
| 5952 | { |
| 5953 | struct io_accel2_cmd *c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
| 5954 | struct hpsa_tmf_struct *ac = (struct hpsa_tmf_struct *) c2; |
| 5955 | struct io_accel2_cmd *c2a = |
| 5956 | &h->ioaccel2_cmd_pool[command_to_abort->cmdindex]; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5957 | struct scsi_cmnd *scmd = command_to_abort->scsi_cmd; |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5958 | struct hpsa_scsi_dev_t *dev = scmd->device->hostdata; |
| 5959 | |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 5960 | if (!dev) |
| 5961 | return; |
| 5962 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5963 | /* |
| 5964 | * We're overlaying struct hpsa_tmf_struct on top of something which |
| 5965 | * was allocated as a struct io_accel2_cmd, so we better be sure it |
| 5966 | * actually fits, and doesn't overrun the error info space. |
| 5967 | */ |
| 5968 | BUILD_BUG_ON(sizeof(struct hpsa_tmf_struct) > |
| 5969 | sizeof(struct io_accel2_cmd)); |
| 5970 | BUG_ON(offsetof(struct io_accel2_cmd, error_data) < |
| 5971 | offsetof(struct hpsa_tmf_struct, error_len) + |
| 5972 | sizeof(ac->error_len)); |
| 5973 | |
| 5974 | c->cmd_type = IOACCEL2_TMF; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 5975 | c->scsi_cmd = SCSI_CMD_BUSY; |
| 5976 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 5977 | /* Adjust the DMA address to point to the accelerated command buffer */ |
| 5978 | c->busaddr = (u32) h->ioaccel2_cmd_pool_dhandle + |
| 5979 | (c->cmdindex * sizeof(struct io_accel2_cmd)); |
| 5980 | BUG_ON(c->busaddr & 0x0000007F); |
| 5981 | |
| 5982 | memset(ac, 0, sizeof(*c2)); /* yes this is correct */ |
| 5983 | ac->iu_type = IOACCEL2_IU_TMF_TYPE; |
| 5984 | ac->reply_queue = reply_queue; |
| 5985 | ac->tmf = IOACCEL2_TMF_ABORT; |
| 5986 | ac->it_nexus = cpu_to_le32(dev->ioaccel_handle); |
| 5987 | memset(ac->lun_id, 0, sizeof(ac->lun_id)); |
| 5988 | ac->tag = cpu_to_le64(c->cmdindex << DIRECT_LOOKUP_SHIFT); |
| 5989 | ac->abort_tag = cpu_to_le64(le32_to_cpu(c2a->Tag)); |
| 5990 | ac->error_ptr = cpu_to_le64(c->busaddr + |
| 5991 | offsetof(struct io_accel2_cmd, error_data)); |
| 5992 | ac->error_len = cpu_to_le32(sizeof(c2->error_data)); |
| 5993 | } |
| 5994 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 5995 | /* ioaccel2 path firmware cannot handle abort task requests. |
| 5996 | * Change abort requests to physical target reset, and send to the |
| 5997 | * address of the physical disk used for the ioaccel 2 command. |
| 5998 | * Return 0 on success (IO_OK) |
| 5999 | * -1 on failure |
| 6000 | */ |
| 6001 | |
| 6002 | static int hpsa_send_reset_as_abort_ioaccel2(struct ctlr_info *h, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6003 | unsigned char *scsi3addr, struct CommandList *abort, int reply_queue) |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6004 | { |
| 6005 | int rc = IO_OK; |
| 6006 | struct scsi_cmnd *scmd; /* scsi command within request being aborted */ |
| 6007 | struct hpsa_scsi_dev_t *dev; /* device to which scsi cmd was sent */ |
| 6008 | unsigned char phys_scsi3addr[8]; /* addr of phys disk with volume */ |
| 6009 | unsigned char *psa = &phys_scsi3addr[0]; |
| 6010 | |
| 6011 | /* Get a pointer to the hpsa logical device. */ |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 6012 | scmd = abort->scsi_cmd; |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6013 | dev = (struct hpsa_scsi_dev_t *)(scmd->device->hostdata); |
| 6014 | if (dev == NULL) { |
| 6015 | dev_warn(&h->pdev->dev, |
| 6016 | "Cannot abort: no device pointer for command.\n"); |
| 6017 | return -1; /* not abortable */ |
| 6018 | } |
| 6019 | |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 6020 | if (h->raid_offload_debug > 0) |
| 6021 | dev_info(&h->pdev->dev, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 6022 | "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] | 6023 | h->scsi_host->host_no, dev->bus, dev->target, dev->lun, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 6024 | "Reset as abort", |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 6025 | scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3], |
| 6026 | scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); |
| 6027 | |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6028 | if (!dev->offload_enabled) { |
| 6029 | dev_warn(&h->pdev->dev, |
| 6030 | "Can't abort: device is not operating in HP SSD Smart Path mode.\n"); |
| 6031 | return -1; /* not abortable */ |
| 6032 | } |
| 6033 | |
| 6034 | /* Incoming scsi3addr is logical addr. We need physical disk addr. */ |
| 6035 | if (!hpsa_get_pdisk_of_ioaccel2(h, abort, psa)) { |
| 6036 | dev_warn(&h->pdev->dev, "Can't abort: Failed lookup of physical address.\n"); |
| 6037 | return -1; /* not abortable */ |
| 6038 | } |
| 6039 | |
| 6040 | /* send the reset */ |
Stephen M. Cameron | 2ba8bfc | 2014-02-18 13:57:52 -0600 | [diff] [blame] | 6041 | if (h->raid_offload_debug > 0) |
| 6042 | dev_info(&h->pdev->dev, |
| 6043 | "Reset as abort: Resetting physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 6044 | psa[0], psa[1], psa[2], psa[3], |
| 6045 | psa[4], psa[5], psa[6], psa[7]); |
Don Brace | b32ece0 | 2016-09-20 15:42:30 -0500 | [diff] [blame] | 6046 | rc = hpsa_do_reset(h, dev, psa, HPSA_PHYS_TARGET_RESET, reply_queue); |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6047 | if (rc != 0) { |
| 6048 | dev_warn(&h->pdev->dev, |
| 6049 | "Reset as abort: Failed on physical device at scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 6050 | psa[0], psa[1], psa[2], psa[3], |
| 6051 | psa[4], psa[5], psa[6], psa[7]); |
| 6052 | return rc; /* failed to reset */ |
| 6053 | } |
| 6054 | |
| 6055 | /* wait for device to recover */ |
Webb Scales | b69324f | 2015-04-23 09:34:22 -0500 | [diff] [blame] | 6056 | if (wait_for_device_to_become_ready(h, psa, reply_queue) != 0) { |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6057 | dev_warn(&h->pdev->dev, |
| 6058 | "Reset as abort: Failed: Device never recovered from reset: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 6059 | psa[0], psa[1], psa[2], psa[3], |
| 6060 | psa[4], psa[5], psa[6], psa[7]); |
| 6061 | return -1; /* failed to recover */ |
| 6062 | } |
| 6063 | |
| 6064 | /* device recovered */ |
| 6065 | dev_info(&h->pdev->dev, |
| 6066 | "Reset as abort: Device recovered from reset: scsi3addr 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 6067 | psa[0], psa[1], psa[2], psa[3], |
| 6068 | psa[4], psa[5], psa[6], psa[7]); |
| 6069 | |
| 6070 | return rc; /* success */ |
| 6071 | } |
| 6072 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6073 | static int hpsa_send_abort_ioaccel2(struct ctlr_info *h, |
| 6074 | struct CommandList *abort, int reply_queue) |
| 6075 | { |
| 6076 | int rc = IO_OK; |
| 6077 | struct CommandList *c; |
| 6078 | __le32 taglower, tagupper; |
| 6079 | struct hpsa_scsi_dev_t *dev; |
| 6080 | struct io_accel2_cmd *c2; |
| 6081 | |
| 6082 | dev = abort->scsi_cmd->device->hostdata; |
Don Brace | 45e596c | 2016-09-09 16:30:42 -0500 | [diff] [blame] | 6083 | if (!dev) |
| 6084 | return -1; |
| 6085 | |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6086 | if (!dev->offload_enabled && !dev->hba_ioaccel_enabled) |
| 6087 | return -1; |
| 6088 | |
| 6089 | c = cmd_alloc(h); |
| 6090 | setup_ioaccel2_abort_cmd(c, h, abort, reply_queue); |
| 6091 | c2 = &h->ioaccel2_cmd_pool[c->cmdindex]; |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 6092 | (void) hpsa_scsi_do_simple_cmd(h, c, reply_queue, DEFAULT_TIMEOUT); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6093 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
| 6094 | dev_dbg(&h->pdev->dev, |
| 6095 | "%s: Tag:0x%08x:%08x: do_simple_cmd(ioaccel2 abort) completed.\n", |
| 6096 | __func__, tagupper, taglower); |
| 6097 | /* no unmap needed here because no data xfer. */ |
| 6098 | |
| 6099 | dev_dbg(&h->pdev->dev, |
| 6100 | "%s: Tag:0x%08x:%08x: abort service response = 0x%02x.\n", |
| 6101 | __func__, tagupper, taglower, c2->error_data.serv_response); |
| 6102 | switch (c2->error_data.serv_response) { |
| 6103 | case IOACCEL2_SERV_RESPONSE_TMF_COMPLETE: |
| 6104 | case IOACCEL2_SERV_RESPONSE_TMF_SUCCESS: |
| 6105 | rc = 0; |
| 6106 | break; |
| 6107 | case IOACCEL2_SERV_RESPONSE_TMF_REJECTED: |
| 6108 | case IOACCEL2_SERV_RESPONSE_FAILURE: |
| 6109 | case IOACCEL2_SERV_RESPONSE_TMF_WRONG_LUN: |
| 6110 | rc = -1; |
| 6111 | break; |
| 6112 | default: |
| 6113 | dev_warn(&h->pdev->dev, |
| 6114 | "%s: Tag:0x%08x:%08x: unknown abort service response 0x%02x\n", |
| 6115 | __func__, tagupper, taglower, |
| 6116 | c2->error_data.serv_response); |
| 6117 | rc = -1; |
| 6118 | } |
| 6119 | cmd_free(h, c); |
| 6120 | dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", __func__, |
| 6121 | tagupper, taglower); |
| 6122 | return rc; |
| 6123 | } |
| 6124 | |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 6125 | static int hpsa_send_abort_both_ways(struct ctlr_info *h, |
Don Brace | 39f3deb | 2016-02-23 15:16:28 -0600 | [diff] [blame] | 6126 | struct hpsa_scsi_dev_t *dev, struct CommandList *abort, int reply_queue) |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 6127 | { |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6128 | /* |
| 6129 | * ioccelerator mode 2 commands should be aborted via the |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6130 | * accelerated path, since RAID path is unaware of these commands, |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6131 | * but not all underlying firmware can handle abort TMF. |
| 6132 | * Change abort to physical device reset when abort TMF is unsupported. |
Scott Teel | 54b6e9e | 2014-02-18 13:56:45 -0600 | [diff] [blame] | 6133 | */ |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6134 | if (abort->cmd_type == CMD_IOACCEL2) { |
Don Brace | 39f3deb | 2016-02-23 15:16:28 -0600 | [diff] [blame] | 6135 | if ((HPSATMF_IOACCEL_ENABLED & h->TMFSupportFlags) || |
| 6136 | dev->physical_device) |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6137 | return hpsa_send_abort_ioaccel2(h, abort, |
| 6138 | reply_queue); |
| 6139 | else |
Don Brace | 39f3deb | 2016-02-23 15:16:28 -0600 | [diff] [blame] | 6140 | return hpsa_send_reset_as_abort_ioaccel2(h, |
| 6141 | dev->scsi3addr, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6142 | abort, reply_queue); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 6143 | } |
Don Brace | 39f3deb | 2016-02-23 15:16:28 -0600 | [diff] [blame] | 6144 | return hpsa_send_abort(h, dev->scsi3addr, abort, reply_queue); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | /* Find out which reply queue a command was meant to return on */ |
| 6148 | static int hpsa_extract_reply_queue(struct ctlr_info *h, |
| 6149 | struct CommandList *c) |
| 6150 | { |
| 6151 | if (c->cmd_type == CMD_IOACCEL2) |
| 6152 | return h->ioaccel2_cmd_pool[c->cmdindex].reply_queue; |
| 6153 | return c->Header.ReplyQueue; |
Stephen M. Cameron | 6cba3f1 | 2012-05-01 11:42:56 -0500 | [diff] [blame] | 6154 | } |
| 6155 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6156 | /* |
| 6157 | * Limit concurrency of abort commands to prevent |
| 6158 | * over-subscription of commands |
| 6159 | */ |
| 6160 | static inline int wait_for_available_abort_cmd(struct ctlr_info *h) |
| 6161 | { |
| 6162 | #define ABORT_CMD_WAIT_MSECS 5000 |
| 6163 | return !wait_event_timeout(h->abort_cmd_wait_queue, |
| 6164 | atomic_dec_if_positive(&h->abort_cmds_available) >= 0, |
| 6165 | msecs_to_jiffies(ABORT_CMD_WAIT_MSECS)); |
| 6166 | } |
| 6167 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6168 | /* Send an abort for the specified command. |
| 6169 | * If the device and controller support it, |
| 6170 | * send a task abort request. |
| 6171 | */ |
| 6172 | static int hpsa_eh_abort_handler(struct scsi_cmnd *sc) |
| 6173 | { |
| 6174 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6175 | int rc; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6176 | struct ctlr_info *h; |
| 6177 | struct hpsa_scsi_dev_t *dev; |
| 6178 | struct CommandList *abort; /* pointer to command to be aborted */ |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6179 | struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ |
| 6180 | char msg[256]; /* For debug messaging. */ |
| 6181 | int ml = 0; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6182 | __le32 tagupper, taglower; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6183 | int refcount, reply_queue; |
| 6184 | |
| 6185 | if (sc == NULL) |
| 6186 | return FAILED; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6187 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6188 | if (sc->device == NULL) |
| 6189 | return FAILED; |
| 6190 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6191 | /* Find the controller of the command to be aborted */ |
| 6192 | h = sdev_to_hba(sc->device); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6193 | if (h == NULL) |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6194 | return FAILED; |
| 6195 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6196 | /* Find the device of the command to be aborted */ |
| 6197 | dev = sc->device->hostdata; |
| 6198 | if (!dev) { |
| 6199 | dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", |
| 6200 | msg); |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 6201 | return FAILED; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | /* If controller locked up, we can guarantee command won't complete */ |
| 6205 | if (lockup_detected(h)) { |
| 6206 | hpsa_show_dev_msg(KERN_WARNING, h, dev, |
| 6207 | "ABORT FAILED, lockup detected"); |
| 6208 | return FAILED; |
| 6209 | } |
| 6210 | |
| 6211 | /* This is a good time to check if controller lockup has occurred */ |
| 6212 | if (detect_controller_lockup(h)) { |
| 6213 | hpsa_show_dev_msg(KERN_WARNING, h, dev, |
| 6214 | "ABORT FAILED, new lockup detected"); |
| 6215 | return FAILED; |
| 6216 | } |
Don Brace | e345893 | 2015-01-23 16:44:24 -0600 | [diff] [blame] | 6217 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6218 | /* Check that controller supports some kind of task abort */ |
| 6219 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags) && |
| 6220 | !(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 6221 | return FAILED; |
| 6222 | |
| 6223 | memset(msg, 0, sizeof(msg)); |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6224 | ml += sprintf(msg+ml, "scsi %d:%d:%d:%llu %s %p", |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6225 | h->scsi_host->host_no, sc->device->channel, |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 6226 | sc->device->id, sc->device->lun, |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6227 | "Aborting command", sc); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6228 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6229 | /* Get SCSI command to be aborted */ |
| 6230 | abort = (struct CommandList *) sc->host_scribble; |
| 6231 | if (abort == NULL) { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6232 | /* This can happen if the command already completed. */ |
| 6233 | return SUCCESS; |
| 6234 | } |
| 6235 | refcount = atomic_inc_return(&abort->refcount); |
| 6236 | if (refcount == 1) { /* Command is done already. */ |
| 6237 | cmd_free(h, abort); |
| 6238 | return SUCCESS; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6239 | } |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6240 | |
| 6241 | /* Don't bother trying the abort if we know it won't work. */ |
| 6242 | if (abort->cmd_type != CMD_IOACCEL2 && |
| 6243 | abort->cmd_type != CMD_IOACCEL1 && !dev->supports_aborts) { |
| 6244 | cmd_free(h, abort); |
| 6245 | return FAILED; |
| 6246 | } |
| 6247 | |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6248 | /* |
| 6249 | * Check that we're aborting the right command. |
| 6250 | * It's possible the CommandList already completed and got re-used. |
| 6251 | */ |
| 6252 | if (abort->scsi_cmd != sc) { |
| 6253 | cmd_free(h, abort); |
| 6254 | return SUCCESS; |
| 6255 | } |
| 6256 | |
| 6257 | abort->abort_pending = true; |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 6258 | hpsa_get_tag(h, abort, &taglower, &tagupper); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6259 | reply_queue = hpsa_extract_reply_queue(h, abort); |
Scott Teel | 17eb87d | 2014-02-18 13:55:28 -0600 | [diff] [blame] | 6260 | ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", tagupper, taglower); |
Stephen Cameron | 7fa3030 | 2015-01-23 16:44:30 -0600 | [diff] [blame] | 6261 | as = abort->scsi_cmd; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6262 | if (as != NULL) |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6263 | ml += sprintf(msg+ml, |
| 6264 | "CDBLen: %d CDB: 0x%02x%02x... SN: 0x%lx ", |
| 6265 | as->cmd_len, as->cmnd[0], as->cmnd[1], |
| 6266 | as->serial_number); |
| 6267 | dev_warn(&h->pdev->dev, "%s BEING SENT\n", msg); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 6268 | hpsa_show_dev_msg(KERN_WARNING, h, dev, "Aborting command"); |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6269 | |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6270 | /* |
| 6271 | * Command is in flight, or possibly already completed |
| 6272 | * by the firmware (but not to the scsi mid layer) but we can't |
| 6273 | * distinguish which. Send the abort down. |
| 6274 | */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6275 | if (wait_for_available_abort_cmd(h)) { |
| 6276 | dev_warn(&h->pdev->dev, |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6277 | "%s FAILED, timeout waiting for an abort command to become available.\n", |
| 6278 | msg); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6279 | cmd_free(h, abort); |
| 6280 | return FAILED; |
| 6281 | } |
Don Brace | 39f3deb | 2016-02-23 15:16:28 -0600 | [diff] [blame] | 6282 | rc = hpsa_send_abort_both_ways(h, dev, abort, reply_queue); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6283 | atomic_inc(&h->abort_cmds_available); |
| 6284 | wake_up_all(&h->abort_cmd_wait_queue); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6285 | if (rc != 0) { |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6286 | dev_warn(&h->pdev->dev, "%s SENT, FAILED\n", msg); |
Webb Scales | 0d96ef5 | 2015-04-23 09:31:55 -0500 | [diff] [blame] | 6287 | hpsa_show_dev_msg(KERN_WARNING, h, dev, |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6288 | "FAILED to abort command"); |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6289 | cmd_free(h, abort); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6290 | return FAILED; |
| 6291 | } |
Robert Elliott | 4b76155 | 2015-04-23 09:33:54 -0500 | [diff] [blame] | 6292 | dev_info(&h->pdev->dev, "%s SENT, SUCCESS\n", msg); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 6293 | wait_event(h->event_sync_wait_queue, |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6294 | abort->scsi_cmd != sc || lockup_detected(h)); |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6295 | cmd_free(h, abort); |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6296 | return !lockup_detected(h) ? SUCCESS : FAILED; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 6297 | } |
| 6298 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6299 | /* |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 6300 | * For operations with an associated SCSI command, a command block is allocated |
| 6301 | * at init, and managed by cmd_tagged_alloc() and cmd_tagged_free() using the |
| 6302 | * block request tag as an index into a table of entries. cmd_tagged_free() is |
| 6303 | * the complement, although cmd_free() may be called instead. |
| 6304 | */ |
| 6305 | static struct CommandList *cmd_tagged_alloc(struct ctlr_info *h, |
| 6306 | struct scsi_cmnd *scmd) |
| 6307 | { |
| 6308 | int idx = hpsa_get_cmd_index(scmd); |
| 6309 | struct CommandList *c = h->cmd_pool + idx; |
| 6310 | |
| 6311 | if (idx < HPSA_NRESERVED_CMDS || idx >= h->nr_cmds) { |
| 6312 | dev_err(&h->pdev->dev, "Bad block tag: %d not in [%d..%d]\n", |
| 6313 | idx, HPSA_NRESERVED_CMDS, h->nr_cmds - 1); |
| 6314 | /* The index value comes from the block layer, so if it's out of |
| 6315 | * bounds, it's probably not our bug. |
| 6316 | */ |
| 6317 | BUG(); |
| 6318 | } |
| 6319 | |
| 6320 | atomic_inc(&c->refcount); |
| 6321 | if (unlikely(!hpsa_is_cmd_idle(c))) { |
| 6322 | /* |
| 6323 | * We expect that the SCSI layer will hand us a unique tag |
| 6324 | * value. Thus, there should never be a collision here between |
| 6325 | * two requests...because if the selected command isn't idle |
| 6326 | * then someone is going to be very disappointed. |
| 6327 | */ |
| 6328 | dev_err(&h->pdev->dev, |
| 6329 | "tag collision (tag=%d) in cmd_tagged_alloc().\n", |
| 6330 | idx); |
| 6331 | if (c->scsi_cmd != NULL) |
| 6332 | scsi_print_command(c->scsi_cmd); |
| 6333 | scsi_print_command(scmd); |
| 6334 | } |
| 6335 | |
| 6336 | hpsa_cmd_partial_init(h, idx, c); |
| 6337 | return c; |
| 6338 | } |
| 6339 | |
| 6340 | static void cmd_tagged_free(struct ctlr_info *h, struct CommandList *c) |
| 6341 | { |
| 6342 | /* |
| 6343 | * Release our reference to the block. We don't need to do anything |
| 6344 | * else to free it, because it is accessed by index. (There's no point |
| 6345 | * in checking the result of the decrement, since we cannot guarantee |
| 6346 | * that there isn't a concurrent abort which is also accessing it.) |
| 6347 | */ |
| 6348 | (void)atomic_dec(&c->refcount); |
| 6349 | } |
| 6350 | |
| 6351 | /* |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6352 | * For operations that cannot sleep, a command block is allocated at init, |
| 6353 | * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track |
| 6354 | * which ones are free or in use. Lock must be held when calling this. |
| 6355 | * cmd_free() is the complement. |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6356 | * This function never gives up and returns NULL. If it hangs, |
| 6357 | * another thread must call cmd_free() to free some tags. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6358 | */ |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6359 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6360 | static struct CommandList *cmd_alloc(struct ctlr_info *h) |
| 6361 | { |
| 6362 | struct CommandList *c; |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 6363 | int refcount, i; |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 6364 | int offset = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6365 | |
Robert Elliott | 3381102 | 2015-01-23 16:43:41 -0600 | [diff] [blame] | 6366 | /* |
| 6367 | * There is some *extremely* small but non-zero chance that that |
Stephen M. Cameron | 4c41312 | 2014-11-14 17:27:29 -0600 | [diff] [blame] | 6368 | * multiple threads could get in here, and one thread could |
| 6369 | * be scanning through the list of bits looking for a free |
| 6370 | * one, but the free ones are always behind him, and other |
| 6371 | * threads sneak in behind him and eat them before he can |
| 6372 | * get to them, so that while there is always a free one, a |
| 6373 | * very unlucky thread might be starved anyway, never able to |
| 6374 | * beat the other threads. In reality, this happens so |
| 6375 | * infrequently as to be indistinguishable from never. |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 6376 | * |
| 6377 | * Note that we start allocating commands before the SCSI host structure |
| 6378 | * is initialized. Since the search starts at bit zero, this |
| 6379 | * all works, since we have at least one command structure available; |
| 6380 | * however, it means that the structures with the low indexes have to be |
| 6381 | * reserved for driver-initiated requests, while requests from the block |
| 6382 | * layer will use the higher indexes. |
Stephen M. Cameron | 4c41312 | 2014-11-14 17:27:29 -0600 | [diff] [blame] | 6383 | */ |
| 6384 | |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6385 | for (;;) { |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 6386 | i = find_next_zero_bit(h->cmd_pool_bits, |
| 6387 | HPSA_NRESERVED_CMDS, |
| 6388 | offset); |
| 6389 | if (unlikely(i >= HPSA_NRESERVED_CMDS)) { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6390 | offset = 0; |
| 6391 | continue; |
| 6392 | } |
| 6393 | c = h->cmd_pool + i; |
| 6394 | refcount = atomic_inc_return(&c->refcount); |
| 6395 | if (unlikely(refcount > 1)) { |
| 6396 | cmd_free(h, c); /* already in use */ |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 6397 | offset = (i + 1) % HPSA_NRESERVED_CMDS; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6398 | continue; |
| 6399 | } |
| 6400 | set_bit(i & (BITS_PER_LONG - 1), |
| 6401 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 6402 | break; /* it's ours now. */ |
| 6403 | } |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 6404 | hpsa_cmd_partial_init(h, i, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6405 | return c; |
| 6406 | } |
| 6407 | |
Webb Scales | 73153fe | 2015-04-23 09:35:04 -0500 | [diff] [blame] | 6408 | /* |
| 6409 | * This is the complementary operation to cmd_alloc(). Note, however, in some |
| 6410 | * corner cases it may also be used to free blocks allocated by |
| 6411 | * cmd_tagged_alloc() in which case the ref-count decrement does the trick and |
| 6412 | * the clear-bit is harmless. |
| 6413 | */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6414 | static void cmd_free(struct ctlr_info *h, struct CommandList *c) |
| 6415 | { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6416 | if (atomic_dec_and_test(&c->refcount)) { |
| 6417 | int i; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6418 | |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 6419 | i = c - h->cmd_pool; |
| 6420 | clear_bit(i & (BITS_PER_LONG - 1), |
| 6421 | h->cmd_pool_bits + (i / BITS_PER_LONG)); |
| 6422 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6423 | } |
| 6424 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6425 | #ifdef CONFIG_COMPAT |
| 6426 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6427 | static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, |
| 6428 | void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6429 | { |
| 6430 | IOCTL32_Command_struct __user *arg32 = |
| 6431 | (IOCTL32_Command_struct __user *) arg; |
| 6432 | IOCTL_Command_struct arg64; |
| 6433 | IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64)); |
| 6434 | int err; |
| 6435 | u32 cp; |
| 6436 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 6437 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6438 | err = 0; |
| 6439 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 6440 | sizeof(arg64.LUN_info)); |
| 6441 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 6442 | sizeof(arg64.Request)); |
| 6443 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 6444 | sizeof(arg64.error_info)); |
| 6445 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 6446 | err |= get_user(cp, &arg32->buf); |
| 6447 | arg64.buf = compat_ptr(cp); |
| 6448 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 6449 | |
| 6450 | if (err) |
| 6451 | return -EFAULT; |
| 6452 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6453 | err = hpsa_ioctl(dev, CCISS_PASSTHRU, p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6454 | if (err) |
| 6455 | return err; |
| 6456 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 6457 | sizeof(arg32->error_info)); |
| 6458 | if (err) |
| 6459 | return -EFAULT; |
| 6460 | return err; |
| 6461 | } |
| 6462 | |
| 6463 | static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6464 | int cmd, void __user *arg) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6465 | { |
| 6466 | BIG_IOCTL32_Command_struct __user *arg32 = |
| 6467 | (BIG_IOCTL32_Command_struct __user *) arg; |
| 6468 | BIG_IOCTL_Command_struct arg64; |
| 6469 | BIG_IOCTL_Command_struct __user *p = |
| 6470 | compat_alloc_user_space(sizeof(arg64)); |
| 6471 | int err; |
| 6472 | u32 cp; |
| 6473 | |
Vasiliy Kulikov | 938abd8 | 2011-01-07 10:55:53 -0600 | [diff] [blame] | 6474 | memset(&arg64, 0, sizeof(arg64)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6475 | err = 0; |
| 6476 | err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, |
| 6477 | sizeof(arg64.LUN_info)); |
| 6478 | err |= copy_from_user(&arg64.Request, &arg32->Request, |
| 6479 | sizeof(arg64.Request)); |
| 6480 | err |= copy_from_user(&arg64.error_info, &arg32->error_info, |
| 6481 | sizeof(arg64.error_info)); |
| 6482 | err |= get_user(arg64.buf_size, &arg32->buf_size); |
| 6483 | err |= get_user(arg64.malloc_size, &arg32->malloc_size); |
| 6484 | err |= get_user(cp, &arg32->buf); |
| 6485 | arg64.buf = compat_ptr(cp); |
| 6486 | err |= copy_to_user(p, &arg64, sizeof(arg64)); |
| 6487 | |
| 6488 | if (err) |
| 6489 | return -EFAULT; |
| 6490 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6491 | err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, p); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6492 | if (err) |
| 6493 | return err; |
| 6494 | err |= copy_in_user(&arg32->error_info, &p->error_info, |
| 6495 | sizeof(arg32->error_info)); |
| 6496 | if (err) |
| 6497 | return -EFAULT; |
| 6498 | return err; |
| 6499 | } |
Stephen M. Cameron | 71fe75a | 2010-02-04 08:43:51 -0600 | [diff] [blame] | 6500 | |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6501 | 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] | 6502 | { |
| 6503 | switch (cmd) { |
| 6504 | case CCISS_GETPCIINFO: |
| 6505 | case CCISS_GETINTINFO: |
| 6506 | case CCISS_SETINTINFO: |
| 6507 | case CCISS_GETNODENAME: |
| 6508 | case CCISS_SETNODENAME: |
| 6509 | case CCISS_GETHEARTBEAT: |
| 6510 | case CCISS_GETBUSTYPES: |
| 6511 | case CCISS_GETFIRMVER: |
| 6512 | case CCISS_GETDRIVVER: |
| 6513 | case CCISS_REVALIDVOLS: |
| 6514 | case CCISS_DEREGDISK: |
| 6515 | case CCISS_REGNEWDISK: |
| 6516 | case CCISS_REGNEWD: |
| 6517 | case CCISS_RESCANDISK: |
| 6518 | case CCISS_GETLUNINFO: |
| 6519 | return hpsa_ioctl(dev, cmd, arg); |
| 6520 | |
| 6521 | case CCISS_PASSTHRU32: |
| 6522 | return hpsa_ioctl32_passthru(dev, cmd, arg); |
| 6523 | case CCISS_BIG_PASSTHRU32: |
| 6524 | return hpsa_ioctl32_big_passthru(dev, cmd, arg); |
| 6525 | |
| 6526 | default: |
| 6527 | return -ENOIOCTLCMD; |
| 6528 | } |
| 6529 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6530 | #endif |
| 6531 | |
| 6532 | static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp) |
| 6533 | { |
| 6534 | struct hpsa_pci_info pciinfo; |
| 6535 | |
| 6536 | if (!argp) |
| 6537 | return -EINVAL; |
| 6538 | pciinfo.domain = pci_domain_nr(h->pdev->bus); |
| 6539 | pciinfo.bus = h->pdev->bus->number; |
| 6540 | pciinfo.dev_fn = h->pdev->devfn; |
| 6541 | pciinfo.board_id = h->board_id; |
| 6542 | if (copy_to_user(argp, &pciinfo, sizeof(pciinfo))) |
| 6543 | return -EFAULT; |
| 6544 | return 0; |
| 6545 | } |
| 6546 | |
| 6547 | static int hpsa_getdrivver_ioctl(struct ctlr_info *h, void __user *argp) |
| 6548 | { |
| 6549 | DriverVer_type DriverVer; |
| 6550 | unsigned char vmaj, vmin, vsubmin; |
| 6551 | int rc; |
| 6552 | |
| 6553 | rc = sscanf(HPSA_DRIVER_VERSION, "%hhu.%hhu.%hhu", |
| 6554 | &vmaj, &vmin, &vsubmin); |
| 6555 | if (rc != 3) { |
| 6556 | dev_info(&h->pdev->dev, "driver version string '%s' " |
| 6557 | "unrecognized.", HPSA_DRIVER_VERSION); |
| 6558 | vmaj = 0; |
| 6559 | vmin = 0; |
| 6560 | vsubmin = 0; |
| 6561 | } |
| 6562 | DriverVer = (vmaj << 16) | (vmin << 8) | vsubmin; |
| 6563 | if (!argp) |
| 6564 | return -EINVAL; |
| 6565 | if (copy_to_user(argp, &DriverVer, sizeof(DriverVer_type))) |
| 6566 | return -EFAULT; |
| 6567 | return 0; |
| 6568 | } |
| 6569 | |
| 6570 | static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 6571 | { |
| 6572 | IOCTL_Command_struct iocommand; |
| 6573 | struct CommandList *c; |
| 6574 | char *buff = NULL; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6575 | u64 temp64; |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6576 | int rc = 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6577 | |
| 6578 | if (!argp) |
| 6579 | return -EINVAL; |
| 6580 | if (!capable(CAP_SYS_RAWIO)) |
| 6581 | return -EPERM; |
| 6582 | if (copy_from_user(&iocommand, argp, sizeof(iocommand))) |
| 6583 | return -EFAULT; |
| 6584 | if ((iocommand.buf_size < 1) && |
| 6585 | (iocommand.Request.Type.Direction != XFER_NONE)) { |
| 6586 | return -EINVAL; |
| 6587 | } |
| 6588 | if (iocommand.buf_size > 0) { |
| 6589 | buff = kmalloc(iocommand.buf_size, GFP_KERNEL); |
| 6590 | if (buff == NULL) |
Robert Elliott | 2dd02d7 | 2015-04-23 09:33:43 -0500 | [diff] [blame] | 6591 | return -ENOMEM; |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6592 | if (iocommand.Request.Type.Direction & XFER_WRITE) { |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6593 | /* Copy the data into the buffer we created */ |
| 6594 | if (copy_from_user(buff, iocommand.buf, |
| 6595 | iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6596 | rc = -EFAULT; |
| 6597 | goto out_kfree; |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6598 | } |
| 6599 | } else { |
| 6600 | memset(buff, 0, iocommand.buf_size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6601 | } |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6602 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6603 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6604 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6605 | /* Fill in the command type */ |
| 6606 | c->cmd_type = CMD_IOCTL_PEND; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6607 | c->scsi_cmd = SCSI_CMD_BUSY; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6608 | /* Fill in Command Header */ |
| 6609 | c->Header.ReplyQueue = 0; /* unused in simple mode */ |
| 6610 | if (iocommand.buf_size > 0) { /* buffer to fill */ |
| 6611 | c->Header.SGList = 1; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6612 | c->Header.SGTotal = cpu_to_le16(1); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6613 | } else { /* no buffers to fill */ |
| 6614 | c->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6615 | c->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6616 | } |
| 6617 | memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6618 | |
| 6619 | /* Fill in Request block */ |
| 6620 | memcpy(&c->Request, &iocommand.Request, |
| 6621 | sizeof(c->Request)); |
| 6622 | |
| 6623 | /* Fill in the scatter gather information */ |
| 6624 | if (iocommand.buf_size > 0) { |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6625 | temp64 = pci_map_single(h->pdev, buff, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6626 | iocommand.buf_size, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6627 | if (dma_mapping_error(&h->pdev->dev, (dma_addr_t) temp64)) { |
| 6628 | c->SG[0].Addr = cpu_to_le64(0); |
| 6629 | c->SG[0].Len = cpu_to_le32(0); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 6630 | rc = -ENOMEM; |
| 6631 | goto out; |
| 6632 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6633 | c->SG[0].Addr = cpu_to_le64(temp64); |
| 6634 | c->SG[0].Len = cpu_to_le32(iocommand.buf_size); |
| 6635 | 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] | 6636 | } |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 6637 | rc = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, |
Don Brace | 3fb134c | 2016-07-01 13:37:38 -0500 | [diff] [blame] | 6638 | NO_TIMEOUT); |
Stephen M. Cameron | c2dd32e | 2011-06-03 09:57:29 -0500 | [diff] [blame] | 6639 | if (iocommand.buf_size > 0) |
| 6640 | hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6641 | check_ioctl_unit_attention(h, c); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6642 | if (rc) { |
| 6643 | rc = -EIO; |
| 6644 | goto out; |
| 6645 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6646 | |
| 6647 | /* Copy the error information out */ |
| 6648 | memcpy(&iocommand.error_info, c->err_info, |
| 6649 | sizeof(iocommand.error_info)); |
| 6650 | if (copy_to_user(argp, &iocommand, sizeof(iocommand))) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6651 | rc = -EFAULT; |
| 6652 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6653 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6654 | if ((iocommand.Request.Type.Direction & XFER_READ) && |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6655 | iocommand.buf_size > 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6656 | /* Copy the data out of the buffer we created */ |
| 6657 | if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) { |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6658 | rc = -EFAULT; |
| 6659 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6660 | } |
| 6661 | } |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6662 | out: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6663 | cmd_free(h, c); |
Stephen M. Cameron | c1f63c8 | 2013-02-20 11:24:52 -0600 | [diff] [blame] | 6664 | out_kfree: |
| 6665 | kfree(buff); |
| 6666 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) |
| 6670 | { |
| 6671 | BIG_IOCTL_Command_struct *ioc; |
| 6672 | struct CommandList *c; |
| 6673 | unsigned char **buff = NULL; |
| 6674 | int *buff_size = NULL; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6675 | u64 temp64; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6676 | BYTE sg_used = 0; |
| 6677 | int status = 0; |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 6678 | u32 left; |
| 6679 | u32 sz; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6680 | BYTE __user *data_ptr; |
| 6681 | |
| 6682 | if (!argp) |
| 6683 | return -EINVAL; |
| 6684 | if (!capable(CAP_SYS_RAWIO)) |
| 6685 | return -EPERM; |
Javier Martinez Canillas | 19be606b | 2016-10-13 13:10:08 -0300 | [diff] [blame] | 6686 | ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6687 | if (!ioc) { |
| 6688 | status = -ENOMEM; |
| 6689 | goto cleanup1; |
| 6690 | } |
| 6691 | if (copy_from_user(ioc, argp, sizeof(*ioc))) { |
| 6692 | status = -EFAULT; |
| 6693 | goto cleanup1; |
| 6694 | } |
| 6695 | if ((ioc->buf_size < 1) && |
| 6696 | (ioc->Request.Type.Direction != XFER_NONE)) { |
| 6697 | status = -EINVAL; |
| 6698 | goto cleanup1; |
| 6699 | } |
| 6700 | /* Check kmalloc limits using all SGs */ |
| 6701 | if (ioc->malloc_size > MAX_KMALLOC_SIZE) { |
| 6702 | status = -EINVAL; |
| 6703 | goto cleanup1; |
| 6704 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6705 | if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6706 | status = -EINVAL; |
| 6707 | goto cleanup1; |
| 6708 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6709 | buff = kzalloc(SG_ENTRIES_IN_CMD * sizeof(char *), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6710 | if (!buff) { |
| 6711 | status = -ENOMEM; |
| 6712 | goto cleanup1; |
| 6713 | } |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 6714 | buff_size = kmalloc(SG_ENTRIES_IN_CMD * sizeof(int), GFP_KERNEL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6715 | if (!buff_size) { |
| 6716 | status = -ENOMEM; |
| 6717 | goto cleanup1; |
| 6718 | } |
| 6719 | left = ioc->buf_size; |
| 6720 | data_ptr = ioc->buf; |
| 6721 | while (left) { |
| 6722 | sz = (left > ioc->malloc_size) ? ioc->malloc_size : left; |
| 6723 | buff_size[sg_used] = sz; |
| 6724 | buff[sg_used] = kmalloc(sz, GFP_KERNEL); |
| 6725 | if (buff[sg_used] == NULL) { |
| 6726 | status = -ENOMEM; |
| 6727 | goto cleanup1; |
| 6728 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6729 | if (ioc->Request.Type.Direction & XFER_WRITE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6730 | if (copy_from_user(buff[sg_used], data_ptr, sz)) { |
Stephen M. Cameron | 0758f4f | 2014-07-03 10:18:03 -0500 | [diff] [blame] | 6731 | status = -EFAULT; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6732 | goto cleanup1; |
| 6733 | } |
| 6734 | } else |
| 6735 | memset(buff[sg_used], 0, sz); |
| 6736 | left -= sz; |
| 6737 | data_ptr += sz; |
| 6738 | sg_used++; |
| 6739 | } |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6740 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6741 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6742 | c->cmd_type = CMD_IOCTL_PEND; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6743 | c->scsi_cmd = SCSI_CMD_BUSY; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6744 | c->Header.ReplyQueue = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6745 | c->Header.SGList = (u8) sg_used; |
| 6746 | c->Header.SGTotal = cpu_to_le16(sg_used); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6747 | memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6748 | memcpy(&c->Request, &ioc->Request, sizeof(c->Request)); |
| 6749 | if (ioc->buf_size > 0) { |
| 6750 | int i; |
| 6751 | for (i = 0; i < sg_used; i++) { |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6752 | temp64 = pci_map_single(h->pdev, buff[i], |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6753 | buff_size[i], PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6754 | if (dma_mapping_error(&h->pdev->dev, |
| 6755 | (dma_addr_t) temp64)) { |
| 6756 | c->SG[i].Addr = cpu_to_le64(0); |
| 6757 | c->SG[i].Len = cpu_to_le32(0); |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 6758 | hpsa_pci_unmap(h->pdev, c, i, |
| 6759 | PCI_DMA_BIDIRECTIONAL); |
| 6760 | status = -ENOMEM; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6761 | goto cleanup0; |
Stephen M. Cameron | bcc48ff | 2013-02-20 11:24:57 -0600 | [diff] [blame] | 6762 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6763 | c->SG[i].Addr = cpu_to_le64(temp64); |
| 6764 | c->SG[i].Len = cpu_to_le32(buff_size[i]); |
| 6765 | c->SG[i].Ext = cpu_to_le32(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6766 | } |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6767 | c->SG[--i].Ext = cpu_to_le32(HPSA_SG_LAST); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6768 | } |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 6769 | status = hpsa_scsi_do_simple_cmd(h, c, DEFAULT_REPLY_QUEUE, |
Don Brace | 3fb134c | 2016-07-01 13:37:38 -0500 | [diff] [blame] | 6770 | NO_TIMEOUT); |
Stephen M. Cameron | b03a777 | 2011-01-06 14:47:48 -0600 | [diff] [blame] | 6771 | if (sg_used) |
| 6772 | hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6773 | check_ioctl_unit_attention(h, c); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 6774 | if (status) { |
| 6775 | status = -EIO; |
| 6776 | goto cleanup0; |
| 6777 | } |
| 6778 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6779 | /* Copy the error information out */ |
| 6780 | memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info)); |
| 6781 | if (copy_to_user(argp, ioc, sizeof(*ioc))) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6782 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6783 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6784 | } |
Stephen M. Cameron | 9233fb1 | 2014-05-29 10:52:41 -0500 | [diff] [blame] | 6785 | if ((ioc->Request.Type.Direction & XFER_READ) && ioc->buf_size > 0) { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6786 | int i; |
| 6787 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6788 | /* Copy the data out of the buffer we created */ |
| 6789 | BYTE __user *ptr = ioc->buf; |
| 6790 | for (i = 0; i < sg_used; i++) { |
| 6791 | if (copy_to_user(ptr, buff[i], buff_size[i])) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6792 | status = -EFAULT; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6793 | goto cleanup0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6794 | } |
| 6795 | ptr += buff_size[i]; |
| 6796 | } |
| 6797 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6798 | status = 0; |
Stephen M. Cameron | e2d4a1f | 2013-09-23 13:33:51 -0500 | [diff] [blame] | 6799 | cleanup0: |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 6800 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6801 | cleanup1: |
| 6802 | if (buff) { |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 6803 | int i; |
| 6804 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6805 | for (i = 0; i < sg_used; i++) |
| 6806 | kfree(buff[i]); |
| 6807 | kfree(buff); |
| 6808 | } |
| 6809 | kfree(buff_size); |
| 6810 | kfree(ioc); |
| 6811 | return status; |
| 6812 | } |
| 6813 | |
| 6814 | static void check_ioctl_unit_attention(struct ctlr_info *h, |
| 6815 | struct CommandList *c) |
| 6816 | { |
| 6817 | if (c->err_info->CommandStatus == CMD_TARGET_STATUS && |
| 6818 | c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) |
| 6819 | (void) check_for_unit_attention(h, c); |
| 6820 | } |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6821 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6822 | /* |
| 6823 | * ioctl |
| 6824 | */ |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 6825 | 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] | 6826 | { |
| 6827 | struct ctlr_info *h; |
| 6828 | void __user *argp = (void __user *)arg; |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6829 | int rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6830 | |
| 6831 | h = sdev_to_hba(dev); |
| 6832 | |
| 6833 | switch (cmd) { |
| 6834 | case CCISS_DEREGDISK: |
| 6835 | case CCISS_REGNEWDISK: |
| 6836 | case CCISS_REGNEWD: |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 6837 | hpsa_scan_start(h->scsi_host); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6838 | return 0; |
| 6839 | case CCISS_GETPCIINFO: |
| 6840 | return hpsa_getpciinfo_ioctl(h, argp); |
| 6841 | case CCISS_GETDRIVVER: |
| 6842 | return hpsa_getdrivver_ioctl(h, argp); |
| 6843 | case CCISS_PASSTHRU: |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6844 | if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0) |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6845 | return -EAGAIN; |
| 6846 | rc = hpsa_passthru_ioctl(h, argp); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6847 | atomic_inc(&h->passthru_cmds_avail); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6848 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6849 | case CCISS_BIG_PASSTHRU: |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6850 | if (atomic_dec_if_positive(&h->passthru_cmds_avail) < 0) |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6851 | return -EAGAIN; |
| 6852 | rc = hpsa_big_passthru_ioctl(h, argp); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 6853 | atomic_inc(&h->passthru_cmds_avail); |
Stephen M. Cameron | 0390f0c | 2013-09-23 13:34:12 -0500 | [diff] [blame] | 6854 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6855 | default: |
| 6856 | return -ENOTTY; |
| 6857 | } |
| 6858 | } |
| 6859 | |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6860 | 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] | 6861 | u8 reset_type) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6862 | { |
| 6863 | struct CommandList *c; |
| 6864 | |
| 6865 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6866 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6867 | /* fill_cmd can't fail here, no data buffer to map */ |
| 6868 | (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] | 6869 | RAID_CTLR_LUNID, TYPE_MSG); |
| 6870 | c->Request.CDB[1] = reset_type; /* fill_cmd defaults to target reset */ |
| 6871 | c->waiting = NULL; |
| 6872 | enqueue_cmd_and_start_io(h, c); |
| 6873 | /* Don't wait for completion, the reset won't complete. Don't free |
| 6874 | * the command either. This is the last command we will send before |
| 6875 | * re-initializing everything, so it doesn't matter and won't leak. |
| 6876 | */ |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 6877 | return; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 6878 | } |
| 6879 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 6880 | 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] | 6881 | void *buff, size_t size, u16 page_code, unsigned char *scsi3addr, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6882 | int cmd_type) |
| 6883 | { |
| 6884 | int pci_dir = XFER_NONE; |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 6885 | u64 tag; /* for commands to be aborted */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6886 | |
| 6887 | c->cmd_type = CMD_IOCTL_PEND; |
Webb Scales | a58e7e5 | 2015-04-23 09:34:16 -0500 | [diff] [blame] | 6888 | c->scsi_cmd = SCSI_CMD_BUSY; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6889 | c->Header.ReplyQueue = 0; |
| 6890 | if (buff != NULL && size > 0) { |
| 6891 | c->Header.SGList = 1; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6892 | c->Header.SGTotal = cpu_to_le16(1); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6893 | } else { |
| 6894 | c->Header.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 6895 | c->Header.SGTotal = cpu_to_le16(0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6896 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6897 | memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8); |
| 6898 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6899 | if (cmd_type == TYPE_CMD) { |
| 6900 | switch (cmd) { |
| 6901 | case HPSA_INQUIRY: |
| 6902 | /* are we trying to read a vital product page */ |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 6903 | if (page_code & VPD_PAGE) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6904 | c->Request.CDB[1] = 0x01; |
Stephen M. Cameron | b7bb24e | 2014-02-18 13:57:11 -0600 | [diff] [blame] | 6905 | c->Request.CDB[2] = (page_code & 0xff); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6906 | } |
| 6907 | c->Request.CDBLen = 6; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6908 | c->Request.type_attr_dir = |
| 6909 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6910 | c->Request.Timeout = 0; |
| 6911 | c->Request.CDB[0] = HPSA_INQUIRY; |
| 6912 | c->Request.CDB[4] = size & 0xFF; |
| 6913 | break; |
| 6914 | case HPSA_REPORT_LOG: |
| 6915 | case HPSA_REPORT_PHYS: |
| 6916 | /* Talking to controller so It's a physical command |
| 6917 | mode = 00 target = 0. Nothing to write. |
| 6918 | */ |
| 6919 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6920 | c->Request.type_attr_dir = |
| 6921 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6922 | c->Request.Timeout = 0; |
| 6923 | c->Request.CDB[0] = cmd; |
| 6924 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 6925 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6926 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 6927 | c->Request.CDB[9] = size & 0xFF; |
| 6928 | break; |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 6929 | case BMIC_SENSE_DIAG_OPTIONS: |
| 6930 | c->Request.CDBLen = 16; |
| 6931 | c->Request.type_attr_dir = |
| 6932 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 6933 | c->Request.Timeout = 0; |
| 6934 | /* Spec says this should be BMIC_WRITE */ |
| 6935 | c->Request.CDB[0] = BMIC_READ; |
| 6936 | c->Request.CDB[6] = BMIC_SENSE_DIAG_OPTIONS; |
| 6937 | break; |
| 6938 | case BMIC_SET_DIAG_OPTIONS: |
| 6939 | c->Request.CDBLen = 16; |
| 6940 | c->Request.type_attr_dir = |
| 6941 | TYPE_ATTR_DIR(cmd_type, |
| 6942 | ATTR_SIMPLE, XFER_WRITE); |
| 6943 | c->Request.Timeout = 0; |
| 6944 | c->Request.CDB[0] = BMIC_WRITE; |
| 6945 | c->Request.CDB[6] = BMIC_SET_DIAG_OPTIONS; |
| 6946 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6947 | case HPSA_CACHE_FLUSH: |
| 6948 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6949 | c->Request.type_attr_dir = |
| 6950 | TYPE_ATTR_DIR(cmd_type, |
| 6951 | ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6952 | c->Request.Timeout = 0; |
| 6953 | c->Request.CDB[0] = BMIC_WRITE; |
| 6954 | c->Request.CDB[6] = BMIC_CACHE_FLUSH; |
Stephen M. Cameron | bb158ea | 2011-10-26 16:21:17 -0500 | [diff] [blame] | 6955 | c->Request.CDB[7] = (size >> 8) & 0xFF; |
| 6956 | c->Request.CDB[8] = size & 0xFF; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6957 | break; |
| 6958 | case TEST_UNIT_READY: |
| 6959 | c->Request.CDBLen = 6; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6960 | c->Request.type_attr_dir = |
| 6961 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 6962 | c->Request.Timeout = 0; |
| 6963 | break; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6964 | case HPSA_GET_RAID_MAP: |
| 6965 | c->Request.CDBLen = 12; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6966 | c->Request.type_attr_dir = |
| 6967 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 6968 | c->Request.Timeout = 0; |
| 6969 | c->Request.CDB[0] = HPSA_CISS_READ; |
| 6970 | c->Request.CDB[1] = cmd; |
| 6971 | c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ |
| 6972 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6973 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 6974 | c->Request.CDB[9] = size & 0xFF; |
| 6975 | break; |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 6976 | case BMIC_SENSE_CONTROLLER_PARAMETERS: |
| 6977 | c->Request.CDBLen = 10; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 6978 | c->Request.type_attr_dir = |
| 6979 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
Stephen M. Cameron | 316b221 | 2014-02-21 16:25:15 -0600 | [diff] [blame] | 6980 | c->Request.Timeout = 0; |
| 6981 | c->Request.CDB[0] = BMIC_READ; |
| 6982 | c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS; |
| 6983 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6984 | c->Request.CDB[8] = (size >> 8) & 0xFF; |
| 6985 | break; |
Don Brace | 0338373 | 2015-01-23 16:43:30 -0600 | [diff] [blame] | 6986 | case BMIC_IDENTIFY_PHYSICAL_DEVICE: |
| 6987 | c->Request.CDBLen = 10; |
| 6988 | c->Request.type_attr_dir = |
| 6989 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 6990 | c->Request.Timeout = 0; |
| 6991 | c->Request.CDB[0] = BMIC_READ; |
| 6992 | c->Request.CDB[6] = BMIC_IDENTIFY_PHYSICAL_DEVICE; |
| 6993 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 6994 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 6995 | break; |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 6996 | case BMIC_SENSE_SUBSYSTEM_INFORMATION: |
| 6997 | c->Request.CDBLen = 10; |
| 6998 | c->Request.type_attr_dir = |
| 6999 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 7000 | c->Request.Timeout = 0; |
| 7001 | c->Request.CDB[0] = BMIC_READ; |
| 7002 | c->Request.CDB[6] = BMIC_SENSE_SUBSYSTEM_INFORMATION; |
| 7003 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 7004 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 7005 | break; |
Don Brace | cca8f13 | 2015-12-22 10:36:48 -0600 | [diff] [blame] | 7006 | case BMIC_SENSE_STORAGE_BOX_PARAMS: |
| 7007 | c->Request.CDBLen = 10; |
| 7008 | c->Request.type_attr_dir = |
| 7009 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 7010 | c->Request.Timeout = 0; |
| 7011 | c->Request.CDB[0] = BMIC_READ; |
| 7012 | c->Request.CDB[6] = BMIC_SENSE_STORAGE_BOX_PARAMS; |
| 7013 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 7014 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 7015 | break; |
Scott Teel | 66749d0 | 2015-11-04 15:51:57 -0600 | [diff] [blame] | 7016 | case BMIC_IDENTIFY_CONTROLLER: |
| 7017 | c->Request.CDBLen = 10; |
| 7018 | c->Request.type_attr_dir = |
| 7019 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ); |
| 7020 | c->Request.Timeout = 0; |
| 7021 | c->Request.CDB[0] = BMIC_READ; |
| 7022 | c->Request.CDB[1] = 0; |
| 7023 | c->Request.CDB[2] = 0; |
| 7024 | c->Request.CDB[3] = 0; |
| 7025 | c->Request.CDB[4] = 0; |
| 7026 | c->Request.CDB[5] = 0; |
| 7027 | c->Request.CDB[6] = BMIC_IDENTIFY_CONTROLLER; |
| 7028 | c->Request.CDB[7] = (size >> 16) & 0xFF; |
| 7029 | c->Request.CDB[8] = (size >> 8) & 0XFF; |
| 7030 | c->Request.CDB[9] = 0; |
| 7031 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7032 | default: |
| 7033 | dev_warn(&h->pdev->dev, "unknown command 0x%c\n", cmd); |
| 7034 | BUG(); |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 7035 | return -1; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7036 | } |
| 7037 | } else if (cmd_type == TYPE_MSG) { |
| 7038 | switch (cmd) { |
| 7039 | |
Scott Teel | 0b9b7b6 | 2015-11-04 15:51:02 -0600 | [diff] [blame] | 7040 | case HPSA_PHYS_TARGET_RESET: |
| 7041 | c->Request.CDBLen = 16; |
| 7042 | c->Request.type_attr_dir = |
| 7043 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
| 7044 | c->Request.Timeout = 0; /* Don't time out */ |
| 7045 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
| 7046 | c->Request.CDB[0] = HPSA_RESET; |
| 7047 | c->Request.CDB[1] = HPSA_TARGET_RESET_TYPE; |
| 7048 | /* Physical target reset needs no control bytes 4-7*/ |
| 7049 | c->Request.CDB[4] = 0x00; |
| 7050 | c->Request.CDB[5] = 0x00; |
| 7051 | c->Request.CDB[6] = 0x00; |
| 7052 | c->Request.CDB[7] = 0x00; |
| 7053 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7054 | case HPSA_DEVICE_RESET_MSG: |
| 7055 | c->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 7056 | c->Request.type_attr_dir = |
| 7057 | TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7058 | c->Request.Timeout = 0; /* Don't time out */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7059 | memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); |
| 7060 | c->Request.CDB[0] = cmd; |
Stephen M. Cameron | 21e89af | 2012-07-26 11:34:10 -0500 | [diff] [blame] | 7061 | c->Request.CDB[1] = HPSA_RESET_TYPE_LUN; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7062 | /* If bytes 4-7 are zero, it means reset the */ |
| 7063 | /* LunID device */ |
| 7064 | c->Request.CDB[4] = 0x00; |
| 7065 | c->Request.CDB[5] = 0x00; |
| 7066 | c->Request.CDB[6] = 0x00; |
| 7067 | c->Request.CDB[7] = 0x00; |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 7068 | break; |
| 7069 | case HPSA_ABORT_MSG: |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 7070 | memcpy(&tag, buff, sizeof(tag)); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7071 | dev_dbg(&h->pdev->dev, |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 7072 | "Abort Tag:0x%016llx using rqst Tag:0x%016llx", |
| 7073 | tag, c->Header.tag); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 7074 | c->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 7075 | c->Request.type_attr_dir = |
| 7076 | TYPE_ATTR_DIR(cmd_type, |
| 7077 | ATTR_SIMPLE, XFER_WRITE); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 7078 | c->Request.Timeout = 0; /* Don't time out */ |
| 7079 | c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; |
| 7080 | c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; |
| 7081 | c->Request.CDB[2] = 0x00; /* reserved */ |
| 7082 | c->Request.CDB[3] = 0x00; /* reserved */ |
| 7083 | /* Tag to abort goes in CDB[4]-CDB[11] */ |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 7084 | memcpy(&c->Request.CDB[4], &tag, sizeof(tag)); |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 7085 | c->Request.CDB[12] = 0x00; /* reserved */ |
| 7086 | c->Request.CDB[13] = 0x00; /* reserved */ |
| 7087 | c->Request.CDB[14] = 0x00; /* reserved */ |
| 7088 | c->Request.CDB[15] = 0x00; /* reserved */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7089 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7090 | default: |
| 7091 | dev_warn(&h->pdev->dev, "unknown message type %d\n", |
| 7092 | cmd); |
| 7093 | BUG(); |
| 7094 | } |
| 7095 | } else { |
| 7096 | dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type); |
| 7097 | BUG(); |
| 7098 | } |
| 7099 | |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 7100 | switch (GET_DIR(c->Request.type_attr_dir)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7101 | case XFER_READ: |
| 7102 | pci_dir = PCI_DMA_FROMDEVICE; |
| 7103 | break; |
| 7104 | case XFER_WRITE: |
| 7105 | pci_dir = PCI_DMA_TODEVICE; |
| 7106 | break; |
| 7107 | case XFER_NONE: |
| 7108 | pci_dir = PCI_DMA_NONE; |
| 7109 | break; |
| 7110 | default: |
| 7111 | pci_dir = PCI_DMA_BIDIRECTIONAL; |
| 7112 | } |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 7113 | if (hpsa_map_one(h->pdev, c, buff, size, pci_dir)) |
| 7114 | return -1; |
| 7115 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | /* |
| 7119 | * Map (physical) PCI mem into (virtual) kernel space |
| 7120 | */ |
| 7121 | static void __iomem *remap_pci_mem(ulong base, ulong size) |
| 7122 | { |
| 7123 | ulong page_base = ((ulong) base) & PAGE_MASK; |
| 7124 | ulong page_offs = ((ulong) base) - page_base; |
Stephen M. Cameron | 088ba34 | 2012-07-26 11:34:23 -0500 | [diff] [blame] | 7125 | void __iomem *page_remapped = ioremap_nocache(page_base, |
| 7126 | page_offs + size); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7127 | |
| 7128 | return page_remapped ? (page_remapped + page_offs) : NULL; |
| 7129 | } |
| 7130 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7131 | 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] | 7132 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7133 | return h->access.command_completed(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7134 | } |
| 7135 | |
Stephen M. Cameron | 900c544 | 2010-02-04 08:42:35 -0600 | [diff] [blame] | 7136 | static inline bool interrupt_pending(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7137 | { |
| 7138 | return h->access.intr_pending(h); |
| 7139 | } |
| 7140 | |
| 7141 | static inline long interrupt_not_for_us(struct ctlr_info *h) |
| 7142 | { |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7143 | return (h->access.intr_pending(h) == 0) || |
| 7144 | (h->interrupts_enabled == 0); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7145 | } |
| 7146 | |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 7147 | static inline int bad_tag(struct ctlr_info *h, u32 tag_index, |
| 7148 | u32 raw_tag) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7149 | { |
| 7150 | if (unlikely(tag_index >= h->nr_cmds)) { |
| 7151 | dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag); |
| 7152 | return 1; |
| 7153 | } |
| 7154 | return 0; |
| 7155 | } |
| 7156 | |
Stephen M. Cameron | 5a3d16f | 2012-05-01 11:42:46 -0500 | [diff] [blame] | 7157 | static inline void finish_cmd(struct CommandList *c) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7158 | { |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 7159 | dial_up_lockup_detection_on_fw_flash_complete(c->h, c); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 7160 | if (likely(c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_SCSI |
| 7161 | || c->cmd_type == CMD_IOACCEL2)) |
Stephen M. Cameron | 1fb011f | 2011-05-03 14:59:00 -0500 | [diff] [blame] | 7162 | complete_scsi_command(c); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 7163 | 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] | 7164 | complete(c->waiting); |
Stephen M. Cameron | a104c99 | 2010-02-04 08:42:24 -0600 | [diff] [blame] | 7165 | } |
| 7166 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7167 | /* process completion of an indexed ("direct lookup") command */ |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 7168 | static inline void process_indexed_cmd(struct ctlr_info *h, |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7169 | u32 raw_tag) |
| 7170 | { |
| 7171 | u32 tag_index; |
| 7172 | struct CommandList *c; |
| 7173 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7174 | tag_index = raw_tag >> DIRECT_LOOKUP_SHIFT; |
Stephen M. Cameron | 1d94f94 | 2012-05-01 11:43:01 -0500 | [diff] [blame] | 7175 | if (!bad_tag(h, tag_index, raw_tag)) { |
| 7176 | c = h->cmd_pool + tag_index; |
| 7177 | finish_cmd(c); |
| 7178 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7179 | } |
| 7180 | |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7181 | /* Some controllers, like p400, will give us one interrupt |
| 7182 | * after a soft reset, even if we turned interrupts off. |
| 7183 | * Only need to check for this in the hpsa_xxx_discard_completions |
| 7184 | * functions. |
| 7185 | */ |
| 7186 | static int ignore_bogus_interrupt(struct ctlr_info *h) |
| 7187 | { |
| 7188 | if (likely(!reset_devices)) |
| 7189 | return 0; |
| 7190 | |
| 7191 | if (likely(h->interrupts_enabled)) |
| 7192 | return 0; |
| 7193 | |
| 7194 | dev_info(&h->pdev->dev, "Received interrupt while interrupts disabled " |
| 7195 | "(known firmware bug.) Ignoring.\n"); |
| 7196 | |
| 7197 | return 1; |
| 7198 | } |
| 7199 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7200 | /* |
| 7201 | * Convert &h->q[x] (passed to interrupt handlers) back to h. |
| 7202 | * Relies on (h-q[x] == x) being true for x such that |
| 7203 | * 0 <= x < MAX_REPLY_QUEUES. |
| 7204 | */ |
| 7205 | static struct ctlr_info *queue_to_hba(u8 *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7206 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7207 | return container_of((queue - *queue), struct ctlr_info, q[0]); |
| 7208 | } |
| 7209 | |
| 7210 | static irqreturn_t hpsa_intx_discard_completions(int irq, void *queue) |
| 7211 | { |
| 7212 | struct ctlr_info *h = queue_to_hba(queue); |
| 7213 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7214 | u32 raw_tag; |
| 7215 | |
| 7216 | if (ignore_bogus_interrupt(h)) |
| 7217 | return IRQ_NONE; |
| 7218 | |
| 7219 | if (interrupt_not_for_us(h)) |
| 7220 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7221 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7222 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7223 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7224 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7225 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7226 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7227 | return IRQ_HANDLED; |
| 7228 | } |
| 7229 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7230 | static irqreturn_t hpsa_msix_discard_completions(int irq, void *queue) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7231 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7232 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7233 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7234 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7235 | |
| 7236 | if (ignore_bogus_interrupt(h)) |
| 7237 | return IRQ_NONE; |
| 7238 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7239 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7240 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7241 | while (raw_tag != FIFO_EMPTY) |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7242 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7243 | return IRQ_HANDLED; |
| 7244 | } |
| 7245 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7246 | static irqreturn_t do_hpsa_intr_intx(int irq, void *queue) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7247 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7248 | struct ctlr_info *h = queue_to_hba((u8 *) queue); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7249 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7250 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7251 | |
| 7252 | if (interrupt_not_for_us(h)) |
| 7253 | return IRQ_NONE; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7254 | h->last_intr_timestamp = get_jiffies_64(); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7255 | while (interrupt_pending(h)) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7256 | raw_tag = get_next_completion(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7257 | while (raw_tag != FIFO_EMPTY) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7258 | process_indexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7259 | raw_tag = next_command(h, q); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7260 | } |
| 7261 | } |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7262 | return IRQ_HANDLED; |
| 7263 | } |
| 7264 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7265 | static irqreturn_t do_hpsa_intr_msi(int irq, void *queue) |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7266 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7267 | struct ctlr_info *h = queue_to_hba(queue); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7268 | u32 raw_tag; |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7269 | u8 q = *(u8 *) queue; |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 7270 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 7271 | h->last_intr_timestamp = get_jiffies_64(); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7272 | raw_tag = get_next_completion(h, q); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7273 | while (raw_tag != FIFO_EMPTY) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 7274 | process_indexed_cmd(h, raw_tag); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 7275 | raw_tag = next_command(h, q); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7276 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7277 | return IRQ_HANDLED; |
| 7278 | } |
| 7279 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 7280 | /* Send a message CDB to the firmware. Careful, this only works |
| 7281 | * in simple mode, not performant mode due to the tag lookup. |
| 7282 | * We only ever use this immediately after a controller reset. |
| 7283 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7284 | static int hpsa_message(struct pci_dev *pdev, unsigned char opcode, |
| 7285 | unsigned char type) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7286 | { |
| 7287 | struct Command { |
| 7288 | struct CommandListHeader CommandHeader; |
| 7289 | struct RequestBlock Request; |
| 7290 | struct ErrDescriptor ErrorDescriptor; |
| 7291 | }; |
| 7292 | struct Command *cmd; |
| 7293 | static const size_t cmd_sz = sizeof(*cmd) + |
| 7294 | sizeof(cmd->ErrorDescriptor); |
| 7295 | dma_addr_t paddr64; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7296 | __le32 paddr32; |
| 7297 | u32 tag; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7298 | void __iomem *vaddr; |
| 7299 | int i, err; |
| 7300 | |
| 7301 | vaddr = pci_ioremap_bar(pdev, 0); |
| 7302 | if (vaddr == NULL) |
| 7303 | return -ENOMEM; |
| 7304 | |
| 7305 | /* The Inbound Post Queue only accepts 32-bit physical addresses for the |
| 7306 | * CCISS commands, so they must be allocated from the lower 4GiB of |
| 7307 | * memory. |
| 7308 | */ |
| 7309 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7310 | if (err) { |
| 7311 | iounmap(vaddr); |
Robert Elliott | 1eaec8f | 2015-01-23 16:42:37 -0600 | [diff] [blame] | 7312 | return err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7313 | } |
| 7314 | |
| 7315 | cmd = pci_alloc_consistent(pdev, cmd_sz, &paddr64); |
| 7316 | if (cmd == NULL) { |
| 7317 | iounmap(vaddr); |
| 7318 | return -ENOMEM; |
| 7319 | } |
| 7320 | |
| 7321 | /* This must fit, because of the 32-bit consistent DMA mask. Also, |
| 7322 | * although there's no guarantee, we assume that the address is at |
| 7323 | * least 4-byte aligned (most likely, it's page-aligned). |
| 7324 | */ |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7325 | paddr32 = cpu_to_le32(paddr64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7326 | |
| 7327 | cmd->CommandHeader.ReplyQueue = 0; |
| 7328 | cmd->CommandHeader.SGList = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 7329 | cmd->CommandHeader.SGTotal = cpu_to_le16(0); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7330 | cmd->CommandHeader.tag = cpu_to_le64(paddr64); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7331 | memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8); |
| 7332 | |
| 7333 | cmd->Request.CDBLen = 16; |
Stephen M. Cameron | a505b86 | 2014-11-14 17:27:04 -0600 | [diff] [blame] | 7334 | cmd->Request.type_attr_dir = |
| 7335 | TYPE_ATTR_DIR(TYPE_MSG, ATTR_HEADOFQUEUE, XFER_NONE); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7336 | cmd->Request.Timeout = 0; /* Don't time out */ |
| 7337 | cmd->Request.CDB[0] = opcode; |
| 7338 | cmd->Request.CDB[1] = type; |
| 7339 | 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] | 7340 | cmd->ErrorDescriptor.Addr = |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7341 | cpu_to_le64((le32_to_cpu(paddr32) + sizeof(*cmd))); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 7342 | cmd->ErrorDescriptor.Len = cpu_to_le32(sizeof(struct ErrorInfo)); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7343 | |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7344 | writel(le32_to_cpu(paddr32), vaddr + SA5_REQUEST_PORT_OFFSET); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7345 | |
| 7346 | for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) { |
| 7347 | tag = readl(vaddr + SA5_REPLY_PORT_OFFSET); |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 7348 | if ((tag & ~HPSA_SIMPLE_ERROR_BITS) == paddr64) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7349 | break; |
| 7350 | msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS); |
| 7351 | } |
| 7352 | |
| 7353 | iounmap(vaddr); |
| 7354 | |
| 7355 | /* we leak the DMA buffer here ... no choice since the controller could |
| 7356 | * still complete the command. |
| 7357 | */ |
| 7358 | if (i == HPSA_MSG_SEND_RETRY_LIMIT) { |
| 7359 | dev_err(&pdev->dev, "controller message %02x:%02x timed out\n", |
| 7360 | opcode, type); |
| 7361 | return -ETIMEDOUT; |
| 7362 | } |
| 7363 | |
| 7364 | pci_free_consistent(pdev, cmd_sz, cmd, paddr64); |
| 7365 | |
| 7366 | if (tag & HPSA_ERROR_BIT) { |
| 7367 | dev_err(&pdev->dev, "controller message %02x:%02x failed\n", |
| 7368 | opcode, type); |
| 7369 | return -EIO; |
| 7370 | } |
| 7371 | |
| 7372 | dev_info(&pdev->dev, "controller message %02x:%02x succeeded\n", |
| 7373 | opcode, type); |
| 7374 | return 0; |
| 7375 | } |
| 7376 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7377 | #define hpsa_noop(p) hpsa_message(p, 3, 0) |
| 7378 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7379 | static int hpsa_controller_hard_reset(struct pci_dev *pdev, |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 7380 | void __iomem *vaddr, u32 use_doorbell) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7381 | { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7382 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7383 | if (use_doorbell) { |
| 7384 | /* For everything after the P600, the PCI power state method |
| 7385 | * of resetting the controller doesn't work, so we have this |
| 7386 | * other way using the doorbell register. |
| 7387 | */ |
| 7388 | dev_info(&pdev->dev, "using doorbell to reset controller\n"); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7389 | writel(use_doorbell, vaddr + SA5_DOORBELL); |
Stephen M. Cameron | 8500923 | 2013-09-23 13:33:36 -0500 | [diff] [blame] | 7390 | |
Justin Lindley | 00701a9 | 2014-05-29 10:52:47 -0500 | [diff] [blame] | 7391 | /* 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] | 7392 | * doorbell reset and before any attempt to talk to the board |
| 7393 | * at all to ensure that this actually works and doesn't fall |
| 7394 | * over in some weird corner cases. |
| 7395 | */ |
Justin Lindley | 00701a9 | 2014-05-29 10:52:47 -0500 | [diff] [blame] | 7396 | msleep(10000); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7397 | } else { /* Try to do it the PCI power state way */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7398 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7399 | /* Quoting from the Open CISS Specification: "The Power |
| 7400 | * Management Control/Status Register (CSR) controls the power |
| 7401 | * state of the device. The normal operating state is D0, |
| 7402 | * CSR=00h. The software off state is D3, CSR=03h. To reset |
| 7403 | * the controller, place the interface device in D3 then to D0, |
| 7404 | * this causes a secondary PCI reset which will reset the |
| 7405 | * controller." */ |
| 7406 | |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 7407 | int rc = 0; |
| 7408 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7409 | dev_info(&pdev->dev, "using PCI PM to reset controller\n"); |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 7410 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7411 | /* enter the D3hot power management state */ |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 7412 | rc = pci_set_power_state(pdev, PCI_D3hot); |
| 7413 | if (rc) |
| 7414 | return rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7415 | |
| 7416 | msleep(500); |
| 7417 | |
| 7418 | /* enter the D0 power management state */ |
Don Brace | 2662cab | 2015-01-23 16:41:25 -0600 | [diff] [blame] | 7419 | rc = pci_set_power_state(pdev, PCI_D0); |
| 7420 | if (rc) |
| 7421 | return rc; |
Mike Miller | c4853ef | 2011-10-21 08:19:43 +0200 | [diff] [blame] | 7422 | |
| 7423 | /* |
| 7424 | * The P600 requires a small delay when changing states. |
| 7425 | * Otherwise we may think the board did not reset and we bail. |
| 7426 | * This for kdump only and is particular to the P600. |
| 7427 | */ |
| 7428 | msleep(500); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7429 | } |
| 7430 | return 0; |
| 7431 | } |
| 7432 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7433 | static void init_driver_version(char *driver_version, int len) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7434 | { |
| 7435 | memset(driver_version, 0, len); |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 7436 | strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1); |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7437 | } |
| 7438 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7439 | static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7440 | { |
| 7441 | char *driver_version; |
| 7442 | int i, size = sizeof(cfgtable->driver_version); |
| 7443 | |
| 7444 | driver_version = kmalloc(size, GFP_KERNEL); |
| 7445 | if (!driver_version) |
| 7446 | return -ENOMEM; |
| 7447 | |
| 7448 | init_driver_version(driver_version, size); |
| 7449 | for (i = 0; i < size; i++) |
| 7450 | writeb(driver_version[i], &cfgtable->driver_version[i]); |
| 7451 | kfree(driver_version); |
| 7452 | return 0; |
| 7453 | } |
| 7454 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7455 | static void read_driver_ver_from_cfgtable(struct CfgTable __iomem *cfgtable, |
| 7456 | unsigned char *driver_ver) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7457 | { |
| 7458 | int i; |
| 7459 | |
| 7460 | for (i = 0; i < sizeof(cfgtable->driver_version); i++) |
| 7461 | driver_ver[i] = readb(&cfgtable->driver_version[i]); |
| 7462 | } |
| 7463 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7464 | static int controller_reset_failed(struct CfgTable __iomem *cfgtable) |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7465 | { |
| 7466 | |
| 7467 | char *driver_ver, *old_driver_ver; |
| 7468 | int rc, size = sizeof(cfgtable->driver_version); |
| 7469 | |
| 7470 | old_driver_ver = kmalloc(2 * size, GFP_KERNEL); |
| 7471 | if (!old_driver_ver) |
| 7472 | return -ENOMEM; |
| 7473 | driver_ver = old_driver_ver + size; |
| 7474 | |
| 7475 | /* After a reset, the 32 bytes of "driver version" in the cfgtable |
| 7476 | * should have been changed, otherwise we know the reset failed. |
| 7477 | */ |
| 7478 | init_driver_version(old_driver_ver, size); |
| 7479 | read_driver_ver_from_cfgtable(cfgtable, driver_ver); |
| 7480 | rc = !memcmp(driver_ver, old_driver_ver, size); |
| 7481 | kfree(old_driver_ver); |
| 7482 | return rc; |
| 7483 | } |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7484 | /* This does a hard reset of the controller using PCI power management |
| 7485 | * states or the using the doorbell register. |
| 7486 | */ |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 7487 | 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] | 7488 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7489 | u64 cfg_offset; |
| 7490 | u32 cfg_base_addr; |
| 7491 | u64 cfg_base_addr_index; |
| 7492 | void __iomem *vaddr; |
| 7493 | unsigned long paddr; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7494 | u32 misc_fw_support; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7495 | int rc; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7496 | struct CfgTable __iomem *cfgtable; |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7497 | u32 use_doorbell; |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7498 | u16 command_register; |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7499 | |
| 7500 | /* For controllers as old as the P600, this is very nearly |
| 7501 | * the same thing as |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7502 | * |
| 7503 | * pci_save_state(pci_dev); |
| 7504 | * pci_set_power_state(pci_dev, PCI_D3hot); |
| 7505 | * pci_set_power_state(pci_dev, PCI_D0); |
| 7506 | * pci_restore_state(pci_dev); |
| 7507 | * |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7508 | * For controllers newer than the P600, the pci power state |
| 7509 | * method of resetting doesn't work so we have another way |
| 7510 | * using the doorbell register. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7511 | */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 7512 | |
Robert Elliott | 60f923b | 2015-01-23 16:42:06 -0600 | [diff] [blame] | 7513 | if (!ctlr_is_resettable(board_id)) { |
| 7514 | dev_warn(&pdev->dev, "Controller not resettable\n"); |
Stephen M. Cameron | 25c1e56a | 2011-01-06 14:48:18 -0600 | [diff] [blame] | 7515 | return -ENODEV; |
| 7516 | } |
Stephen M. Cameron | 4638078 | 2011-05-03 15:00:01 -0500 | [diff] [blame] | 7517 | |
| 7518 | /* if controller is soft- but not hard resettable... */ |
| 7519 | if (!ctlr_is_hard_resettable(board_id)) |
| 7520 | return -ENOTSUPP; /* try soft reset later. */ |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 7521 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7522 | /* Save the PCI command register */ |
| 7523 | pci_read_config_word(pdev, 4, &command_register); |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7524 | pci_save_state(pdev); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7525 | |
| 7526 | /* find the first memory BAR, so we can find the cfg table */ |
| 7527 | rc = hpsa_pci_find_memory_BAR(pdev, &paddr); |
| 7528 | if (rc) |
| 7529 | return rc; |
| 7530 | vaddr = remap_pci_mem(paddr, 0x250); |
| 7531 | if (!vaddr) |
| 7532 | return -ENOMEM; |
| 7533 | |
| 7534 | /* find cfgtable in order to check if reset via doorbell is supported */ |
| 7535 | rc = hpsa_find_cfg_addrs(pdev, vaddr, &cfg_base_addr, |
| 7536 | &cfg_base_addr_index, &cfg_offset); |
| 7537 | if (rc) |
| 7538 | goto unmap_vaddr; |
| 7539 | cfgtable = remap_pci_mem(pci_resource_start(pdev, |
| 7540 | cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable)); |
| 7541 | if (!cfgtable) { |
| 7542 | rc = -ENOMEM; |
| 7543 | goto unmap_vaddr; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7544 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7545 | rc = write_driver_ver_to_cfgtable(cfgtable); |
| 7546 | if (rc) |
Tomas Henzl | 03741d9 | 2015-01-23 16:41:14 -0600 | [diff] [blame] | 7547 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7548 | |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7549 | /* If reset via doorbell register is supported, use that. |
| 7550 | * There are two such methods. Favor the newest method. |
| 7551 | */ |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7552 | misc_fw_support = readl(&cfgtable->misc_fw_support); |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7553 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET2; |
| 7554 | if (use_doorbell) { |
| 7555 | use_doorbell = DOORBELL_CTLR_RESET2; |
| 7556 | } else { |
| 7557 | use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET; |
| 7558 | if (use_doorbell) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7559 | dev_warn(&pdev->dev, |
| 7560 | "Soft reset not supported. Firmware update is required.\n"); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7561 | rc = -ENOTSUPP; /* try soft reset */ |
Stephen M. Cameron | cf0b08d | 2011-05-03 14:59:46 -0500 | [diff] [blame] | 7562 | goto unmap_cfgtable; |
| 7563 | } |
| 7564 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7565 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7566 | rc = hpsa_controller_hard_reset(pdev, vaddr, use_doorbell); |
| 7567 | if (rc) |
| 7568 | goto unmap_cfgtable; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7569 | |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7570 | pci_restore_state(pdev); |
Stephen M. Cameron | 270d05d | 2011-01-06 14:48:08 -0600 | [diff] [blame] | 7571 | pci_write_config_word(pdev, 4, command_register); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7572 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7573 | /* Some devices (notably the HP Smart Array 5i Controller) |
| 7574 | need a little pause here */ |
| 7575 | msleep(HPSA_POST_RESET_PAUSE_MSECS); |
| 7576 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7577 | rc = hpsa_wait_for_board_state(pdev, vaddr, BOARD_READY); |
| 7578 | if (rc) { |
| 7579 | dev_warn(&pdev->dev, |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7580 | "Failed waiting for board to become ready after hard reset\n"); |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7581 | goto unmap_cfgtable; |
| 7582 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7583 | |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7584 | rc = controller_reset_failed(vaddr); |
| 7585 | if (rc < 0) |
| 7586 | goto unmap_cfgtable; |
| 7587 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7588 | dev_warn(&pdev->dev, "Unable to successfully reset " |
| 7589 | "controller. Will try soft reset.\n"); |
| 7590 | rc = -ENOTSUPP; |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7591 | } else { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 7592 | dev_info(&pdev->dev, "board ready after hard reset.\n"); |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | unmap_cfgtable: |
| 7596 | iounmap(cfgtable); |
| 7597 | |
| 7598 | unmap_vaddr: |
| 7599 | iounmap(vaddr); |
| 7600 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | /* |
| 7604 | * We cannot read the structure directly, for portability we must use |
| 7605 | * the io functions. |
| 7606 | * This is for debug only. |
| 7607 | */ |
Don Brace | 42a9164 | 2014-11-14 17:26:27 -0600 | [diff] [blame] | 7608 | 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] | 7609 | { |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 7610 | #ifdef HPSA_DEBUG |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7611 | int i; |
| 7612 | char temp_name[17]; |
| 7613 | |
| 7614 | dev_info(dev, "Controller Configuration information\n"); |
| 7615 | dev_info(dev, "------------------------------------\n"); |
| 7616 | for (i = 0; i < 4; i++) |
| 7617 | temp_name[i] = readb(&(tb->Signature[i])); |
| 7618 | temp_name[4] = '\0'; |
| 7619 | dev_info(dev, " Signature = %s\n", temp_name); |
| 7620 | dev_info(dev, " Spec Number = %d\n", readl(&(tb->SpecValence))); |
| 7621 | dev_info(dev, " Transport methods supported = 0x%x\n", |
| 7622 | readl(&(tb->TransportSupport))); |
| 7623 | dev_info(dev, " Transport methods active = 0x%x\n", |
| 7624 | readl(&(tb->TransportActive))); |
| 7625 | dev_info(dev, " Requested transport Method = 0x%x\n", |
| 7626 | readl(&(tb->HostWrite.TransportRequest))); |
| 7627 | dev_info(dev, " Coalesce Interrupt Delay = 0x%x\n", |
| 7628 | readl(&(tb->HostWrite.CoalIntDelay))); |
| 7629 | dev_info(dev, " Coalesce Interrupt Count = 0x%x\n", |
| 7630 | readl(&(tb->HostWrite.CoalIntCount))); |
Robert Elliott | 69d6e33 | 2015-01-23 16:41:56 -0600 | [diff] [blame] | 7631 | dev_info(dev, " Max outstanding commands = %d\n", |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7632 | readl(&(tb->CmdsOutMax))); |
| 7633 | dev_info(dev, " Bus Types = 0x%x\n", readl(&(tb->BusTypes))); |
| 7634 | for (i = 0; i < 16; i++) |
| 7635 | temp_name[i] = readb(&(tb->ServerName[i])); |
| 7636 | temp_name[16] = '\0'; |
| 7637 | dev_info(dev, " Server Name = %s\n", temp_name); |
| 7638 | dev_info(dev, " Heartbeat Counter = 0x%x\n\n\n", |
| 7639 | readl(&(tb->HeartBeat))); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7640 | #endif /* HPSA_DEBUG */ |
Stephen M. Cameron | 58f8665 | 2010-05-27 15:13:58 -0500 | [diff] [blame] | 7641 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7642 | |
| 7643 | static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) |
| 7644 | { |
| 7645 | int i, offset, mem_type, bar_type; |
| 7646 | |
| 7647 | if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */ |
| 7648 | return 0; |
| 7649 | offset = 0; |
| 7650 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 7651 | bar_type = pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE; |
| 7652 | if (bar_type == PCI_BASE_ADDRESS_SPACE_IO) |
| 7653 | offset += 4; |
| 7654 | else { |
| 7655 | mem_type = pci_resource_flags(pdev, i) & |
| 7656 | PCI_BASE_ADDRESS_MEM_TYPE_MASK; |
| 7657 | switch (mem_type) { |
| 7658 | case PCI_BASE_ADDRESS_MEM_TYPE_32: |
| 7659 | case PCI_BASE_ADDRESS_MEM_TYPE_1M: |
| 7660 | offset += 4; /* 32 bit */ |
| 7661 | break; |
| 7662 | case PCI_BASE_ADDRESS_MEM_TYPE_64: |
| 7663 | offset += 8; |
| 7664 | break; |
| 7665 | default: /* reserved in PCI 2.2 */ |
| 7666 | dev_warn(&pdev->dev, |
| 7667 | "base address is invalid\n"); |
| 7668 | return -1; |
| 7669 | break; |
| 7670 | } |
| 7671 | } |
| 7672 | if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0) |
| 7673 | return i + 1; |
| 7674 | } |
| 7675 | return -1; |
| 7676 | } |
| 7677 | |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 7678 | static void hpsa_disable_interrupt_mode(struct ctlr_info *h) |
| 7679 | { |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 7680 | pci_free_irq_vectors(h->pdev); |
| 7681 | h->msix_vectors = 0; |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 7682 | } |
| 7683 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7684 | /* 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] | 7685 | * controllers that are capable. If not, we use legacy INTx mode. |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7686 | */ |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 7687 | static int hpsa_interrupt_mode(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7688 | { |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 7689 | unsigned int flags = PCI_IRQ_LEGACY; |
| 7690 | int ret; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7691 | |
| 7692 | /* Some boards advertise MSI but don't really support it */ |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 7693 | switch (h->board_id) { |
| 7694 | case 0x40700E11: |
| 7695 | case 0x40800E11: |
| 7696 | case 0x40820E11: |
| 7697 | case 0x40830E11: |
| 7698 | break; |
| 7699 | default: |
| 7700 | ret = pci_alloc_irq_vectors(h->pdev, 1, MAX_REPLY_QUEUES, |
| 7701 | PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); |
| 7702 | if (ret > 0) { |
| 7703 | h->msix_vectors = ret; |
| 7704 | return 0; |
Hannes Reinecke | eee0f03 | 2014-01-15 13:30:53 +0100 | [diff] [blame] | 7705 | } |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 7706 | |
| 7707 | flags |= PCI_IRQ_MSI; |
| 7708 | break; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7709 | } |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 7710 | |
| 7711 | ret = pci_alloc_irq_vectors(h->pdev, 1, 1, flags); |
| 7712 | if (ret < 0) |
| 7713 | return ret; |
| 7714 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7715 | } |
| 7716 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7717 | 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] | 7718 | { |
| 7719 | int i; |
| 7720 | u32 subsystem_vendor_id, subsystem_device_id; |
| 7721 | |
| 7722 | subsystem_vendor_id = pdev->subsystem_vendor; |
| 7723 | subsystem_device_id = pdev->subsystem_device; |
| 7724 | *board_id = ((subsystem_device_id << 16) & 0xffff0000) | |
| 7725 | subsystem_vendor_id; |
| 7726 | |
| 7727 | for (i = 0; i < ARRAY_SIZE(products); i++) |
| 7728 | if (*board_id == products[i].board_id) |
| 7729 | return i; |
| 7730 | |
Stephen M. Cameron | 6798cc0 | 2010-06-16 13:51:20 -0500 | [diff] [blame] | 7731 | if ((subsystem_vendor_id != PCI_VENDOR_ID_HP && |
| 7732 | subsystem_vendor_id != PCI_VENDOR_ID_COMPAQ) || |
| 7733 | !hpsa_allow_any) { |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 7734 | dev_warn(&pdev->dev, "unrecognized board ID: " |
| 7735 | "0x%08x, ignoring.\n", *board_id); |
| 7736 | return -ENODEV; |
| 7737 | } |
| 7738 | return ARRAY_SIZE(products) - 1; /* generic unknown smart array */ |
| 7739 | } |
| 7740 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7741 | static int hpsa_pci_find_memory_BAR(struct pci_dev *pdev, |
| 7742 | unsigned long *memory_bar) |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7743 | { |
| 7744 | int i; |
| 7745 | |
| 7746 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7747 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7748 | /* addressing mode bits already removed */ |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7749 | *memory_bar = pci_resource_start(pdev, i); |
| 7750 | dev_dbg(&pdev->dev, "memory BAR = %lx\n", |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7751 | *memory_bar); |
| 7752 | return 0; |
| 7753 | } |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 7754 | dev_warn(&pdev->dev, "no memory BAR found\n"); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 7755 | return -ENODEV; |
| 7756 | } |
| 7757 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7758 | static int hpsa_wait_for_board_state(struct pci_dev *pdev, void __iomem *vaddr, |
| 7759 | int wait_for_ready) |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7760 | { |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7761 | int i, iterations; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7762 | u32 scratchpad; |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7763 | if (wait_for_ready) |
| 7764 | iterations = HPSA_BOARD_READY_ITERATIONS; |
| 7765 | else |
| 7766 | iterations = HPSA_BOARD_NOT_READY_ITERATIONS; |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7767 | |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7768 | for (i = 0; i < iterations; i++) { |
| 7769 | scratchpad = readl(vaddr + SA5_SCRATCHPAD_OFFSET); |
| 7770 | if (wait_for_ready) { |
| 7771 | if (scratchpad == HPSA_FIRMWARE_READY) |
| 7772 | return 0; |
| 7773 | } else { |
| 7774 | if (scratchpad != HPSA_FIRMWARE_READY) |
| 7775 | return 0; |
| 7776 | } |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7777 | msleep(HPSA_BOARD_READY_POLL_INTERVAL_MSECS); |
| 7778 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 7779 | dev_warn(&pdev->dev, "board not ready, timed out.\n"); |
Stephen M. Cameron | 2c4c8c8 | 2010-05-27 15:13:12 -0500 | [diff] [blame] | 7780 | return -ENODEV; |
| 7781 | } |
| 7782 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7783 | static int hpsa_find_cfg_addrs(struct pci_dev *pdev, void __iomem *vaddr, |
| 7784 | u32 *cfg_base_addr, u64 *cfg_base_addr_index, |
| 7785 | u64 *cfg_offset) |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7786 | { |
| 7787 | *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET); |
| 7788 | *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET); |
| 7789 | *cfg_base_addr &= (u32) 0x0000ffff; |
| 7790 | *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr); |
| 7791 | if (*cfg_base_addr_index == -1) { |
| 7792 | dev_warn(&pdev->dev, "cannot find cfg_base_addr_index\n"); |
| 7793 | return -ENODEV; |
| 7794 | } |
| 7795 | return 0; |
| 7796 | } |
| 7797 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7798 | static void hpsa_free_cfgtables(struct ctlr_info *h) |
| 7799 | { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7800 | if (h->transtable) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7801 | iounmap(h->transtable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7802 | h->transtable = NULL; |
| 7803 | } |
| 7804 | if (h->cfgtable) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7805 | iounmap(h->cfgtable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 7806 | h->cfgtable = NULL; |
| 7807 | } |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7808 | } |
| 7809 | |
| 7810 | /* Find and map CISS config table and transfer table |
| 7811 | + * several items must be unmapped (freed) later |
| 7812 | + * */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7813 | static int hpsa_find_cfgtables(struct ctlr_info *h) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 7814 | { |
Stephen M. Cameron | 01a02ff | 2010-02-04 08:41:33 -0600 | [diff] [blame] | 7815 | u64 cfg_offset; |
| 7816 | u32 cfg_base_addr; |
| 7817 | u64 cfg_base_addr_index; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 7818 | u32 trans_offset; |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7819 | int rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7820 | |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7821 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 7822 | &cfg_base_addr_index, &cfg_offset); |
| 7823 | if (rc) |
| 7824 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7825 | h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev, |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7826 | cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable)); |
Robert Elliott | cd3c81c | 2015-01-23 16:42:27 -0600 | [diff] [blame] | 7827 | if (!h->cfgtable) { |
| 7828 | dev_err(&h->pdev->dev, "Failed mapping cfgtable\n"); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7829 | return -ENOMEM; |
Robert Elliott | cd3c81c | 2015-01-23 16:42:27 -0600 | [diff] [blame] | 7830 | } |
Stephen M. Cameron | 580ada3 | 2011-05-03 14:59:10 -0500 | [diff] [blame] | 7831 | rc = write_driver_ver_to_cfgtable(h->cfgtable); |
| 7832 | if (rc) |
| 7833 | return rc; |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7834 | /* Find performant mode table. */ |
Stephen M. Cameron | a51fd47 | 2010-06-16 13:51:30 -0500 | [diff] [blame] | 7835 | trans_offset = readl(&h->cfgtable->TransMethodOffset); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7836 | h->transtable = remap_pci_mem(pci_resource_start(h->pdev, |
| 7837 | cfg_base_addr_index)+cfg_offset+trans_offset, |
| 7838 | sizeof(*h->transtable)); |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7839 | if (!h->transtable) { |
| 7840 | dev_err(&h->pdev->dev, "Failed mapping transfer table\n"); |
| 7841 | hpsa_free_cfgtables(h); |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7842 | return -ENOMEM; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 7843 | } |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 7844 | return 0; |
| 7845 | } |
| 7846 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7847 | 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] | 7848 | { |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 7849 | #define MIN_MAX_COMMANDS 16 |
| 7850 | BUILD_BUG_ON(MIN_MAX_COMMANDS <= HPSA_NRESERVED_CMDS); |
| 7851 | |
| 7852 | h->max_commands = readl(&h->cfgtable->MaxPerformantModeCommands); |
Stephen M. Cameron | 72ceeae | 2011-01-06 14:48:13 -0600 | [diff] [blame] | 7853 | |
| 7854 | /* Limit commands in memory limited kdump scenario. */ |
| 7855 | if (reset_devices && h->max_commands > 32) |
| 7856 | h->max_commands = 32; |
| 7857 | |
Stephen Cameron | 41ce4c3 | 2015-04-23 09:31:47 -0500 | [diff] [blame] | 7858 | if (h->max_commands < MIN_MAX_COMMANDS) { |
| 7859 | dev_warn(&h->pdev->dev, |
| 7860 | "Controller reports max supported commands of %d Using %d instead. Ensure that firmware is up to date.\n", |
| 7861 | h->max_commands, |
| 7862 | MIN_MAX_COMMANDS); |
| 7863 | h->max_commands = MIN_MAX_COMMANDS; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 7864 | } |
| 7865 | } |
| 7866 | |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7867 | /* If the controller reports that the total max sg entries is greater than 512, |
| 7868 | * then we know that chained SG blocks work. (Original smart arrays did not |
| 7869 | * support chained SG blocks and would return zero for max sg entries.) |
| 7870 | */ |
| 7871 | static int hpsa_supports_chained_sg_blocks(struct ctlr_info *h) |
| 7872 | { |
| 7873 | return h->maxsgentries > 512; |
| 7874 | } |
| 7875 | |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7876 | /* Interrogate the hardware for some limits: |
| 7877 | * max commands, max SG elements without chaining, and with chaining, |
| 7878 | * SG chain block size, etc. |
| 7879 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7880 | static void hpsa_find_board_params(struct ctlr_info *h) |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7881 | { |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 7882 | hpsa_get_max_perf_mode_cmds(h); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 7883 | h->nr_cmds = h->max_commands; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7884 | h->maxsgentries = readl(&(h->cfgtable->MaxScatterGatherElements)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 7885 | h->fw_support = readl(&(h->cfgtable->misc_fw_support)); |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7886 | if (hpsa_supports_chained_sg_blocks(h)) { |
| 7887 | /* 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] | 7888 | h->max_cmd_sg_entries = 32; |
Webb Scales | 1a63ea6 | 2014-11-14 17:26:43 -0600 | [diff] [blame] | 7889 | h->chainsize = h->maxsgentries - h->max_cmd_sg_entries; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7890 | h->maxsgentries--; /* save one for chain pointer */ |
| 7891 | } else { |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7892 | /* |
| 7893 | * Original smart arrays supported at most 31 s/g entries |
| 7894 | * embedded inline in the command (trying to use more |
| 7895 | * would lock up the controller) |
| 7896 | */ |
| 7897 | h->max_cmd_sg_entries = 31; |
Webb Scales | 1a63ea6 | 2014-11-14 17:26:43 -0600 | [diff] [blame] | 7898 | h->maxsgentries = 31; /* default to traditional values */ |
Webb Scales | c7ee65b | 2015-01-23 16:42:17 -0600 | [diff] [blame] | 7899 | h->chainsize = 0; |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 7900 | } |
Stephen M. Cameron | 75167d2 | 2012-05-01 11:42:51 -0500 | [diff] [blame] | 7901 | |
| 7902 | /* Find out what task management functions are supported and cache */ |
| 7903 | h->TMFSupportFlags = readl(&(h->cfgtable->TMFSupportFlags)); |
Scott Teel | 0e7a7fc | 2014-02-18 13:55:59 -0600 | [diff] [blame] | 7904 | if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags)) |
| 7905 | dev_warn(&h->pdev->dev, "Physical aborts not supported\n"); |
| 7906 | if (!(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) |
| 7907 | dev_warn(&h->pdev->dev, "Logical aborts not supported\n"); |
Stephen Cameron | 8be986c | 2015-04-23 09:34:06 -0500 | [diff] [blame] | 7908 | if (!(HPSATMF_IOACCEL_ENABLED & h->TMFSupportFlags)) |
| 7909 | 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] | 7910 | } |
| 7911 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 7912 | static inline bool hpsa_CISS_signature_present(struct ctlr_info *h) |
| 7913 | { |
Akinobu Mita | 0fc9fd4 | 2012-04-04 22:14:59 +0900 | [diff] [blame] | 7914 | if (!check_signature(h->cfgtable->Signature, "CISS", 4)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 7915 | 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] | 7916 | return false; |
| 7917 | } |
| 7918 | return true; |
| 7919 | } |
| 7920 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7921 | 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] | 7922 | { |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7923 | u32 driver_support; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 7924 | |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7925 | driver_support = readl(&(h->cfgtable->driver_support)); |
Arnd Bergmann | 0b9e7b7 | 2014-06-26 15:44:52 +0200 | [diff] [blame] | 7926 | /* Need to enable prefetch in the SCSI core for 6400 in x86 */ |
| 7927 | #ifdef CONFIG_X86 |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 7928 | driver_support |= ENABLE_SCSI_PREFETCH; |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 7929 | #endif |
Stephen M. Cameron | 28e1344 | 2013-12-04 17:10:21 -0600 | [diff] [blame] | 7930 | driver_support |= ENABLE_UNIT_ATTN; |
| 7931 | writel(driver_support, &(h->cfgtable->driver_support)); |
Stephen M. Cameron | f7c3910 | 2010-05-27 15:13:38 -0500 | [diff] [blame] | 7932 | } |
| 7933 | |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 7934 | /* Disable DMA prefetch for the P600. Otherwise an ASIC bug may result |
| 7935 | * in a prefetch beyond physical memory. |
| 7936 | */ |
| 7937 | static inline void hpsa_p600_dma_prefetch_quirk(struct ctlr_info *h) |
| 7938 | { |
| 7939 | u32 dma_prefetch; |
| 7940 | |
| 7941 | if (h->board_id != 0x3225103C) |
| 7942 | return; |
| 7943 | dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG); |
| 7944 | dma_prefetch |= 0x8000; |
| 7945 | writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG); |
| 7946 | } |
| 7947 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7948 | 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] | 7949 | { |
| 7950 | int i; |
| 7951 | u32 doorbell_value; |
| 7952 | unsigned long flags; |
| 7953 | /* wait until the clear_event_notify bit 6 is cleared by controller. */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7954 | for (i = 0; i < MAX_CLEAR_EVENT_WAIT; i++) { |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7955 | spin_lock_irqsave(&h->lock, flags); |
| 7956 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 7957 | spin_unlock_irqrestore(&h->lock, flags); |
| 7958 | if (!(doorbell_value & DOORBELL_CLEAR_EVENTS)) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7959 | goto done; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7960 | /* delay and try again */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7961 | msleep(CLEAR_EVENT_WAIT_INTERVAL); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7962 | } |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7963 | return -ENODEV; |
| 7964 | done: |
| 7965 | return 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 7966 | } |
| 7967 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7968 | 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] | 7969 | { |
| 7970 | int i; |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 7971 | u32 doorbell_value; |
| 7972 | unsigned long flags; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7973 | |
| 7974 | /* under certain very rare conditions, this can take awhile. |
| 7975 | * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right |
| 7976 | * as we enter this code.) |
| 7977 | */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7978 | for (i = 0; i < MAX_MODE_CHANGE_WAIT; i++) { |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 7979 | if (h->remove_in_progress) |
| 7980 | goto done; |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 7981 | spin_lock_irqsave(&h->lock, flags); |
| 7982 | doorbell_value = readl(h->vaddr + SA5_DOORBELL); |
| 7983 | spin_unlock_irqrestore(&h->lock, flags); |
Dan Carpenter | 382be66 | 2011-02-15 15:33:13 -0600 | [diff] [blame] | 7984 | if (!(doorbell_value & CFGTBL_ChangeReq)) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7985 | goto done; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7986 | /* delay and try again */ |
Robert Elliott | 007e7aa | 2015-01-23 16:44:56 -0600 | [diff] [blame] | 7987 | msleep(MODE_CHANGE_WAIT_INTERVAL); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 7988 | } |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7989 | return -ENODEV; |
| 7990 | done: |
| 7991 | return 0; |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 7992 | } |
| 7993 | |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 7994 | /* return -ENODEV or other reason on error, 0 on success */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7995 | static int hpsa_enter_simple_mode(struct ctlr_info *h) |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 7996 | { |
| 7997 | u32 trans_support; |
| 7998 | |
| 7999 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 8000 | if (!(trans_support & SIMPLE_MODE)) |
| 8001 | return -ENOTSUPP; |
| 8002 | |
| 8003 | h->max_commands = readl(&(h->cfgtable->CmdsOutMax)); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 8004 | |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 8005 | /* Update the field, and then ring the doorbell */ |
| 8006 | writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest)); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 8007 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Stephen M. Cameron | 3f4336f | 2010-05-27 15:14:08 -0500 | [diff] [blame] | 8008 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 8009 | if (hpsa_wait_for_mode_change_ack(h)) |
| 8010 | goto error; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 8011 | print_cfg_table(&h->pdev->dev, h->cfgtable); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 8012 | if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) |
| 8013 | goto error; |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 8014 | h->transMethod = CFGTBL_Trans_Simple; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 8015 | return 0; |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 8016 | error: |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 8017 | dev_err(&h->pdev->dev, "failed to enter simple mode\n"); |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 8018 | return -ENODEV; |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 8019 | } |
| 8020 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8021 | /* free items allocated or mapped by hpsa_pci_init */ |
| 8022 | static void hpsa_free_pci_init(struct ctlr_info *h) |
| 8023 | { |
| 8024 | hpsa_free_cfgtables(h); /* pci_init 4 */ |
| 8025 | iounmap(h->vaddr); /* pci_init 3 */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8026 | h->vaddr = NULL; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8027 | hpsa_disable_interrupt_mode(h); /* pci_init 2 */ |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 8028 | /* |
| 8029 | * call pci_disable_device before pci_release_regions per |
| 8030 | * Documentation/PCI/pci.txt |
| 8031 | */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8032 | pci_disable_device(h->pdev); /* pci_init 1 */ |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 8033 | pci_release_regions(h->pdev); /* pci_init 2 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | /* several items must be freed later */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8037 | static int hpsa_pci_init(struct ctlr_info *h) |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 8038 | { |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 8039 | int prod_index, err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8040 | |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 8041 | prod_index = hpsa_lookup_board_id(h->pdev, &h->board_id); |
| 8042 | if (prod_index < 0) |
Robert Elliott | 60f923b | 2015-01-23 16:42:06 -0600 | [diff] [blame] | 8043 | return prod_index; |
Stephen M. Cameron | e5c880d | 2010-05-27 15:12:52 -0500 | [diff] [blame] | 8044 | h->product_name = products[prod_index].product_name; |
| 8045 | h->access = *(products[prod_index].access); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8046 | |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 8047 | h->needs_abort_tags_swizzled = |
| 8048 | ctlr_needs_abort_tags_swizzled(h->board_id); |
| 8049 | |
Matthew Garrett | e5a44df | 2011-11-11 11:14:23 -0500 | [diff] [blame] | 8050 | pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S | |
| 8051 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); |
| 8052 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 8053 | err = pci_enable_device(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8054 | if (err) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8055 | dev_err(&h->pdev->dev, "failed to enable PCI device\n"); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 8056 | pci_disable_device(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8057 | return err; |
| 8058 | } |
| 8059 | |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 8060 | err = pci_request_regions(h->pdev, HPSA); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8061 | if (err) { |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 8062 | dev_err(&h->pdev->dev, |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8063 | "failed to obtain PCI resources\n"); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 8064 | pci_disable_device(h->pdev); |
| 8065 | return err; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8066 | } |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 8067 | |
| 8068 | pci_set_master(h->pdev); |
| 8069 | |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8070 | err = hpsa_interrupt_mode(h); |
| 8071 | if (err) |
| 8072 | goto clean1; |
Stephen M. Cameron | 12d2cd4 | 2010-06-16 13:51:25 -0500 | [diff] [blame] | 8073 | err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr); |
Stephen M. Cameron | 3a7774c | 2010-05-27 15:13:07 -0500 | [diff] [blame] | 8074 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8075 | goto clean2; /* intmode+region, pci */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8076 | h->vaddr = remap_pci_mem(h->paddr, 0x250); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 8077 | if (!h->vaddr) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8078 | dev_err(&h->pdev->dev, "failed to remap PCI mem\n"); |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 8079 | err = -ENOMEM; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8080 | goto clean2; /* intmode+region, pci */ |
Stephen M. Cameron | 204892e | 2010-05-27 15:13:22 -0500 | [diff] [blame] | 8081 | } |
Stephen M. Cameron | fe5389c | 2011-01-06 14:48:03 -0600 | [diff] [blame] | 8082 | 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] | 8083 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8084 | goto clean3; /* vaddr, intmode+region, pci */ |
Stephen M. Cameron | 77c4495 | 2010-05-27 15:13:17 -0500 | [diff] [blame] | 8085 | err = hpsa_find_cfgtables(h); |
| 8086 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8087 | goto clean3; /* vaddr, intmode+region, pci */ |
Stephen M. Cameron | b93d753 | 2010-05-27 15:13:27 -0500 | [diff] [blame] | 8088 | hpsa_find_board_params(h); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8089 | |
Stephen M. Cameron | 76c46e4 | 2010-05-27 15:13:32 -0500 | [diff] [blame] | 8090 | if (!hpsa_CISS_signature_present(h)) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8091 | err = -ENODEV; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8092 | goto clean4; /* cfgtables, vaddr, intmode+region, pci */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8093 | } |
Stephen M. Cameron | 97a5e98 | 2013-12-04 17:10:16 -0600 | [diff] [blame] | 8094 | hpsa_set_driver_support_bits(h); |
Stephen M. Cameron | 3d0eab6 | 2010-05-27 15:13:43 -0500 | [diff] [blame] | 8095 | hpsa_p600_dma_prefetch_quirk(h); |
Stephen M. Cameron | eb6b2ae | 2010-05-27 15:13:48 -0500 | [diff] [blame] | 8096 | err = hpsa_enter_simple_mode(h); |
| 8097 | if (err) |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8098 | goto clean4; /* cfgtables, vaddr, intmode+region, pci */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8099 | return 0; |
| 8100 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8101 | clean4: /* cfgtables, vaddr, intmode+region, pci */ |
| 8102 | hpsa_free_cfgtables(h); |
| 8103 | clean3: /* vaddr, intmode+region, pci */ |
| 8104 | iounmap(h->vaddr); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8105 | h->vaddr = NULL; |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8106 | clean2: /* intmode+region, pci */ |
| 8107 | hpsa_disable_interrupt_mode(h); |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8108 | clean1: |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 8109 | /* |
| 8110 | * call pci_disable_device before pci_release_regions per |
| 8111 | * Documentation/PCI/pci.txt |
| 8112 | */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8113 | pci_disable_device(h->pdev); |
Robert Elliott | 943a702 | 2015-04-23 09:34:32 -0500 | [diff] [blame] | 8114 | pci_release_regions(h->pdev); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8115 | return err; |
| 8116 | } |
| 8117 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8118 | static void hpsa_hba_inquiry(struct ctlr_info *h) |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 8119 | { |
| 8120 | int rc; |
| 8121 | |
| 8122 | #define HBA_INQUIRY_BYTE_COUNT 64 |
| 8123 | h->hba_inquiry_data = kmalloc(HBA_INQUIRY_BYTE_COUNT, GFP_KERNEL); |
| 8124 | if (!h->hba_inquiry_data) |
| 8125 | return; |
| 8126 | rc = hpsa_scsi_do_inquiry(h, RAID_CTLR_LUNID, 0, |
| 8127 | h->hba_inquiry_data, HBA_INQUIRY_BYTE_COUNT); |
| 8128 | if (rc != 0) { |
| 8129 | kfree(h->hba_inquiry_data); |
| 8130 | h->hba_inquiry_data = NULL; |
| 8131 | } |
| 8132 | } |
| 8133 | |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 8134 | 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] | 8135 | { |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 8136 | int rc, i; |
Tomas Henzl | 3b74729 | 2015-01-23 16:41:20 -0600 | [diff] [blame] | 8137 | void __iomem *vaddr; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 8138 | |
| 8139 | if (!reset_devices) |
| 8140 | return 0; |
| 8141 | |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 8142 | /* kdump kernel is loading, we don't know in which state is |
| 8143 | * the pci interface. The dev->enable_cnt is equal zero |
| 8144 | * so we call enable+disable, wait a while and switch it on. |
| 8145 | */ |
| 8146 | rc = pci_enable_device(pdev); |
| 8147 | if (rc) { |
| 8148 | dev_warn(&pdev->dev, "Failed to enable PCI device\n"); |
| 8149 | return -ENODEV; |
| 8150 | } |
| 8151 | pci_disable_device(pdev); |
| 8152 | msleep(260); /* a randomly chosen number */ |
| 8153 | rc = pci_enable_device(pdev); |
| 8154 | if (rc) { |
| 8155 | dev_warn(&pdev->dev, "failed to enable device.\n"); |
| 8156 | return -ENODEV; |
| 8157 | } |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 8158 | |
Tomas Henzl | 859c75a | 2014-09-12 14:44:15 +0200 | [diff] [blame] | 8159 | pci_set_master(pdev); |
Robert Elliott | 4fa604e | 2014-11-14 17:27:24 -0600 | [diff] [blame] | 8160 | |
Tomas Henzl | 3b74729 | 2015-01-23 16:41:20 -0600 | [diff] [blame] | 8161 | vaddr = pci_ioremap_bar(pdev, 0); |
| 8162 | if (vaddr == NULL) { |
| 8163 | rc = -ENOMEM; |
| 8164 | goto out_disable; |
| 8165 | } |
| 8166 | writel(SA5_INTR_OFF, vaddr + SA5_REPLY_INTR_MASK_OFFSET); |
| 8167 | iounmap(vaddr); |
| 8168 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 8169 | /* Reset the controller with a PCI power-cycle or via doorbell */ |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 8170 | rc = hpsa_kdump_hard_reset_controller(pdev, board_id); |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 8171 | |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 8172 | /* -ENOTSUPP here means we cannot reset the controller |
| 8173 | * but it's already (and still) up and running in |
Stephen M. Cameron | 1886765 | 2010-06-16 13:51:45 -0500 | [diff] [blame] | 8174 | * "performant mode". Or, it might be 640x, which can't reset |
| 8175 | * due to concerns about shared bbwc between 6402/6404 pair. |
Stephen M. Cameron | 1df8552 | 2010-06-16 13:51:40 -0500 | [diff] [blame] | 8176 | */ |
Robert Elliott | adf1b3a | 2015-01-23 16:42:01 -0600 | [diff] [blame] | 8177 | if (rc) |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 8178 | goto out_disable; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 8179 | |
| 8180 | /* Now try to get the controller to respond to a no-op */ |
Robert Elliott | 1ba66c9 | 2015-01-23 16:42:11 -0600 | [diff] [blame] | 8181 | 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] | 8182 | for (i = 0; i < HPSA_POST_RESET_NOOP_RETRIES; i++) { |
| 8183 | if (hpsa_noop(pdev) == 0) |
| 8184 | break; |
| 8185 | else |
| 8186 | dev_warn(&pdev->dev, "no-op failed%s\n", |
| 8187 | (i < 11 ? "; re-trying" : "")); |
| 8188 | } |
Tomas Henzl | 132aa22 | 2014-08-14 16:12:39 +0200 | [diff] [blame] | 8189 | |
| 8190 | out_disable: |
| 8191 | |
| 8192 | pci_disable_device(pdev); |
| 8193 | return rc; |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 8194 | } |
| 8195 | |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8196 | static void hpsa_free_cmd_pool(struct ctlr_info *h) |
| 8197 | { |
| 8198 | kfree(h->cmd_pool_bits); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8199 | h->cmd_pool_bits = NULL; |
| 8200 | if (h->cmd_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8201 | pci_free_consistent(h->pdev, |
| 8202 | h->nr_cmds * sizeof(struct CommandList), |
| 8203 | h->cmd_pool, |
| 8204 | h->cmd_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8205 | h->cmd_pool = NULL; |
| 8206 | h->cmd_pool_dhandle = 0; |
| 8207 | } |
| 8208 | if (h->errinfo_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8209 | pci_free_consistent(h->pdev, |
| 8210 | h->nr_cmds * sizeof(struct ErrorInfo), |
| 8211 | h->errinfo_pool, |
| 8212 | h->errinfo_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8213 | h->errinfo_pool = NULL; |
| 8214 | h->errinfo_pool_dhandle = 0; |
| 8215 | } |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8216 | } |
| 8217 | |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 8218 | static int hpsa_alloc_cmd_pool(struct ctlr_info *h) |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 8219 | { |
| 8220 | h->cmd_pool_bits = kzalloc( |
| 8221 | DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) * |
| 8222 | sizeof(unsigned long), GFP_KERNEL); |
| 8223 | h->cmd_pool = pci_alloc_consistent(h->pdev, |
| 8224 | h->nr_cmds * sizeof(*h->cmd_pool), |
| 8225 | &(h->cmd_pool_dhandle)); |
| 8226 | h->errinfo_pool = pci_alloc_consistent(h->pdev, |
| 8227 | h->nr_cmds * sizeof(*h->errinfo_pool), |
| 8228 | &(h->errinfo_pool_dhandle)); |
| 8229 | if ((h->cmd_pool_bits == NULL) |
| 8230 | || (h->cmd_pool == NULL) |
| 8231 | || (h->errinfo_pool == NULL)) { |
| 8232 | dev_err(&h->pdev->dev, "out of memory in %s", __func__); |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 8233 | goto clean_up; |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 8234 | } |
Stephen Cameron | 360c73b | 2015-04-23 09:32:32 -0500 | [diff] [blame] | 8235 | hpsa_preinitialize_commands(h); |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 8236 | return 0; |
Robert Elliott | 2c14334 | 2015-01-23 16:42:48 -0600 | [diff] [blame] | 8237 | clean_up: |
| 8238 | hpsa_free_cmd_pool(h); |
| 8239 | return -ENOMEM; |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 8240 | } |
| 8241 | |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8242 | /* clear affinity hints and free MSI-X, MSI, or legacy INTx vectors */ |
| 8243 | static void hpsa_free_irqs(struct ctlr_info *h) |
| 8244 | { |
| 8245 | int i; |
| 8246 | |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8247 | if (!h->msix_vectors || h->intr_mode != PERF_MODE_INT) { |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8248 | /* Single reply queue, only one irq to free */ |
Colin Ian King | 7dc62d9 | 2016-11-14 12:59:35 +0000 | [diff] [blame] | 8249 | free_irq(pci_irq_vector(h->pdev, 0), &h->q[h->intr_mode]); |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8250 | h->q[h->intr_mode] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8251 | return; |
| 8252 | } |
| 8253 | |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8254 | for (i = 0; i < h->msix_vectors; i++) { |
| 8255 | free_irq(pci_irq_vector(h->pdev, i), &h->q[i]); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8256 | h->q[i] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8257 | } |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 8258 | for (; i < MAX_REPLY_QUEUES; i++) |
| 8259 | h->q[i] = 0; |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8260 | } |
| 8261 | |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 8262 | /* returns 0 on success; cleans up and returns -Enn on error */ |
| 8263 | static int hpsa_request_irqs(struct ctlr_info *h, |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 8264 | irqreturn_t (*msixhandler)(int, void *), |
| 8265 | irqreturn_t (*intxhandler)(int, void *)) |
| 8266 | { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8267 | int rc, i; |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 8268 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8269 | /* |
| 8270 | * initialize h->q[x] = x so that interrupt handlers know which |
| 8271 | * queue to process. |
| 8272 | */ |
| 8273 | for (i = 0; i < MAX_REPLY_QUEUES; i++) |
| 8274 | h->q[i] = (u8) i; |
| 8275 | |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8276 | if (h->intr_mode == PERF_MODE_INT && h->msix_vectors > 0) { |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8277 | /* If performant mode and MSI-X, use multiple reply queues */ |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8278 | for (i = 0; i < h->msix_vectors; i++) { |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 8279 | sprintf(h->intrname[i], "%s-msix%d", h->devname, i); |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8280 | rc = request_irq(pci_irq_vector(h->pdev, i), msixhandler, |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 8281 | 0, h->intrname[i], |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8282 | &h->q[i]); |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 8283 | if (rc) { |
| 8284 | int j; |
| 8285 | |
| 8286 | dev_err(&h->pdev->dev, |
| 8287 | "failed to get irq %d for %s\n", |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8288 | pci_irq_vector(h->pdev, i), h->devname); |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 8289 | for (j = 0; j < i; j++) { |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8290 | free_irq(pci_irq_vector(h->pdev, j), &h->q[j]); |
Robert Elliott | a4e17fc | 2015-01-23 16:41:51 -0600 | [diff] [blame] | 8291 | h->q[j] = 0; |
| 8292 | } |
| 8293 | for (; j < MAX_REPLY_QUEUES; j++) |
| 8294 | h->q[j] = 0; |
| 8295 | return rc; |
| 8296 | } |
| 8297 | } |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8298 | } else { |
| 8299 | /* Use single reply pool */ |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8300 | if (h->msix_vectors > 0 || h->pdev->msi_enabled) { |
| 8301 | sprintf(h->intrname[0], "%s-msi%s", h->devname, |
| 8302 | h->msix_vectors ? "x" : ""); |
| 8303 | rc = request_irq(pci_irq_vector(h->pdev, 0), |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 8304 | msixhandler, 0, |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8305 | h->intrname[0], |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8306 | &h->q[h->intr_mode]); |
| 8307 | } else { |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 8308 | sprintf(h->intrname[h->intr_mode], |
| 8309 | "%s-intx", h->devname); |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8310 | rc = request_irq(pci_irq_vector(h->pdev, 0), |
Robert Elliott | 8b47004 | 2015-04-23 09:34:58 -0500 | [diff] [blame] | 8311 | intxhandler, IRQF_SHARED, |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8312 | h->intrname[0], |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 8313 | &h->q[h->intr_mode]); |
| 8314 | } |
| 8315 | } |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 8316 | if (rc) { |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8317 | dev_err(&h->pdev->dev, "failed to get irq %d for %s\n", |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 8318 | pci_irq_vector(h->pdev, 0), h->devname); |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8319 | hpsa_free_irqs(h); |
Stephen M. Cameron | 0ae01a3 | 2011-05-03 14:59:25 -0500 | [diff] [blame] | 8320 | return -ENODEV; |
| 8321 | } |
| 8322 | return 0; |
| 8323 | } |
| 8324 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8325 | static int hpsa_kdump_soft_reset(struct ctlr_info *h) |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8326 | { |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 8327 | int rc; |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 8328 | 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] | 8329 | |
| 8330 | dev_info(&h->pdev->dev, "Waiting for board to soft reset.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 8331 | rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_NOT_READY); |
| 8332 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8333 | dev_warn(&h->pdev->dev, "Soft reset had no effect.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 8334 | return rc; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8335 | } |
| 8336 | |
| 8337 | dev_info(&h->pdev->dev, "Board reset, awaiting READY status.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 8338 | rc = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY); |
| 8339 | if (rc) { |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8340 | dev_warn(&h->pdev->dev, "Board failed to become ready " |
| 8341 | "after soft reset.\n"); |
Robert Elliott | 39c53f5 | 2015-04-23 09:35:14 -0500 | [diff] [blame] | 8342 | return rc; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8343 | } |
| 8344 | |
| 8345 | return 0; |
| 8346 | } |
| 8347 | |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 8348 | static void hpsa_free_reply_queues(struct ctlr_info *h) |
| 8349 | { |
| 8350 | int i; |
| 8351 | |
| 8352 | for (i = 0; i < h->nreply_queues; i++) { |
| 8353 | if (!h->reply_queue[i].head) |
| 8354 | continue; |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 8355 | pci_free_consistent(h->pdev, |
| 8356 | h->reply_queue_size, |
| 8357 | h->reply_queue[i].head, |
| 8358 | h->reply_queue[i].busaddr); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 8359 | h->reply_queue[i].head = NULL; |
| 8360 | h->reply_queue[i].busaddr = 0; |
| 8361 | } |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8362 | h->reply_queue_size = 0; |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 8363 | } |
| 8364 | |
Stephen M. Cameron | 0097f0f | 2012-05-01 11:43:21 -0500 | [diff] [blame] | 8365 | static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h) |
| 8366 | { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8367 | hpsa_free_performant_mode(h); /* init_one 7 */ |
| 8368 | hpsa_free_sg_chain_blocks(h); /* init_one 6 */ |
| 8369 | hpsa_free_cmd_pool(h); /* init_one 5 */ |
| 8370 | hpsa_free_irqs(h); /* init_one 4 */ |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8371 | scsi_host_put(h->scsi_host); /* init_one 3 */ |
| 8372 | h->scsi_host = NULL; /* init_one 3 */ |
| 8373 | hpsa_free_pci_init(h); /* init_one 2_5 */ |
Robert Elliott | 9ecd953 | 2015-04-23 09:34:43 -0500 | [diff] [blame] | 8374 | free_percpu(h->lockup_detected); /* init_one 2 */ |
| 8375 | h->lockup_detected = NULL; /* init_one 2 */ |
| 8376 | if (h->resubmit_wq) { |
| 8377 | destroy_workqueue(h->resubmit_wq); /* init_one 1 */ |
| 8378 | h->resubmit_wq = NULL; |
| 8379 | } |
| 8380 | if (h->rescan_ctlr_wq) { |
| 8381 | destroy_workqueue(h->rescan_ctlr_wq); |
| 8382 | h->rescan_ctlr_wq = NULL; |
| 8383 | } |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8384 | kfree(h); /* init_one 1 */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8385 | } |
| 8386 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8387 | /* Called when controller lockup detected. */ |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 8388 | static void fail_all_outstanding_cmds(struct ctlr_info *h) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8389 | { |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 8390 | int i, refcount; |
| 8391 | struct CommandList *c; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8392 | int failcount = 0; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8393 | |
Don Brace | 080ef1c | 2015-01-23 16:43:25 -0600 | [diff] [blame] | 8394 | flush_workqueue(h->resubmit_wq); /* ensure all cmds are fully built */ |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 8395 | for (i = 0; i < h->nr_cmds; i++) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 8396 | c = h->cmd_pool + i; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 8397 | refcount = atomic_inc_return(&c->refcount); |
| 8398 | if (refcount > 1) { |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8399 | c->err_info->CommandStatus = CMD_CTLR_LOCKUP; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 8400 | finish_cmd(c); |
Stephen Cameron | 433b5f4 | 2015-04-23 09:32:11 -0500 | [diff] [blame] | 8401 | atomic_dec(&h->commands_outstanding); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8402 | failcount++; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 8403 | } |
| 8404 | cmd_free(h, c); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8405 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8406 | dev_warn(&h->pdev->dev, |
| 8407 | "failed %d commands in fail_all\n", failcount); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8408 | } |
| 8409 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8410 | static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value) |
| 8411 | { |
Rusty Russell | c8ed001 | 2015-03-05 10:49:19 +1030 | [diff] [blame] | 8412 | int cpu; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8413 | |
Rusty Russell | c8ed001 | 2015-03-05 10:49:19 +1030 | [diff] [blame] | 8414 | for_each_online_cpu(cpu) { |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8415 | u32 *lockup_detected; |
| 8416 | lockup_detected = per_cpu_ptr(h->lockup_detected, cpu); |
| 8417 | *lockup_detected = value; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8418 | } |
| 8419 | wmb(); /* be sure the per-cpu variables are out to memory */ |
| 8420 | } |
| 8421 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8422 | static void controller_lockup_detected(struct ctlr_info *h) |
| 8423 | { |
| 8424 | unsigned long flags; |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8425 | u32 lockup_detected; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8426 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8427 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8428 | spin_lock_irqsave(&h->lock, flags); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8429 | lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); |
| 8430 | if (!lockup_detected) { |
| 8431 | /* no heartbeat, but controller gave us a zero. */ |
| 8432 | dev_warn(&h->pdev->dev, |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8433 | "lockup detected after %d but scratchpad register is zero\n", |
| 8434 | h->heartbeat_sample_interval / HZ); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8435 | lockup_detected = 0xffffffff; |
| 8436 | } |
| 8437 | set_lockup_detected_for_all_cpus(h, lockup_detected); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8438 | spin_unlock_irqrestore(&h->lock, flags); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8439 | dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x after %d\n", |
| 8440 | lockup_detected, h->heartbeat_sample_interval / HZ); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8441 | pci_disable_device(h->pdev); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 8442 | fail_all_outstanding_cmds(h); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8443 | } |
| 8444 | |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8445 | static int detect_controller_lockup(struct ctlr_info *h) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8446 | { |
| 8447 | u64 now; |
| 8448 | u32 heartbeat; |
| 8449 | unsigned long flags; |
| 8450 | |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8451 | now = get_jiffies_64(); |
| 8452 | /* If we've received an interrupt recently, we're ok. */ |
| 8453 | if (time_after64(h->last_intr_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 8454 | (h->heartbeat_sample_interval), now)) |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8455 | return false; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8456 | |
| 8457 | /* |
| 8458 | * If we've already checked the heartbeat recently, we're ok. |
| 8459 | * This could happen if someone sends us a signal. We |
| 8460 | * otherwise don't care about signals in this thread. |
| 8461 | */ |
| 8462 | if (time_after64(h->last_heartbeat_timestamp + |
Stephen M. Cameron | e85c597 | 2012-05-01 11:43:42 -0500 | [diff] [blame] | 8463 | (h->heartbeat_sample_interval), now)) |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8464 | return false; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8465 | |
| 8466 | /* If heartbeat has not changed since we last looked, we're not ok. */ |
| 8467 | spin_lock_irqsave(&h->lock, flags); |
| 8468 | heartbeat = readl(&h->cfgtable->HeartBeat); |
| 8469 | spin_unlock_irqrestore(&h->lock, flags); |
| 8470 | if (h->last_heartbeat == heartbeat) { |
| 8471 | controller_lockup_detected(h); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8472 | return true; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8473 | } |
| 8474 | |
| 8475 | /* We're ok. */ |
| 8476 | h->last_heartbeat = heartbeat; |
| 8477 | h->last_heartbeat_timestamp = now; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8478 | return false; |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8479 | } |
| 8480 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8481 | static void hpsa_ack_ctlr_events(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8482 | { |
| 8483 | int i; |
| 8484 | char *event_type; |
| 8485 | |
Stephen Cameron | e4aa3e6 | 2015-01-23 16:44:07 -0600 | [diff] [blame] | 8486 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
| 8487 | return; |
| 8488 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8489 | /* Ask the controller to clear the events we're handling. */ |
Stephen M. Cameron | 1f7cee8 | 2014-02-18 13:56:09 -0600 | [diff] [blame] | 8490 | if ((h->transMethod & (CFGTBL_Trans_io_accel1 |
| 8491 | | CFGTBL_Trans_io_accel2)) && |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8492 | (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE || |
| 8493 | h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE)) { |
| 8494 | |
| 8495 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE) |
| 8496 | event_type = "state change"; |
| 8497 | if (h->events & HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE) |
| 8498 | event_type = "configuration change"; |
| 8499 | /* Stop sending new RAID offload reqs via the IO accelerator */ |
| 8500 | scsi_block_requests(h->scsi_host); |
Don Brace | 5323ed7 | 2016-04-27 17:13:59 -0500 | [diff] [blame] | 8501 | for (i = 0; i < h->ndevices; i++) { |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8502 | h->dev[i]->offload_enabled = 0; |
Don Brace | 5323ed7 | 2016-04-27 17:13:59 -0500 | [diff] [blame] | 8503 | h->dev[i]->offload_to_be_enabled = 0; |
| 8504 | } |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 8505 | hpsa_drain_accel_commands(h); |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8506 | /* Set 'accelerator path config change' bit */ |
| 8507 | dev_warn(&h->pdev->dev, |
| 8508 | "Acknowledging event: 0x%08x (HP SSD Smart Path %s)\n", |
| 8509 | h->events, event_type); |
| 8510 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 8511 | /* Set the "clear event notify field update" bit 6 */ |
| 8512 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 8513 | /* Wait until ctlr clears 'clear event notify field', bit 6 */ |
| 8514 | hpsa_wait_for_clear_event_notify_ack(h); |
| 8515 | scsi_unblock_requests(h->scsi_host); |
| 8516 | } else { |
| 8517 | /* Acknowledge controller notification events. */ |
| 8518 | writel(h->events, &(h->cfgtable->clear_event_notify)); |
| 8519 | writel(DOORBELL_CLEAR_EVENTS, h->vaddr + SA5_DOORBELL); |
| 8520 | hpsa_wait_for_clear_event_notify_ack(h); |
| 8521 | #if 0 |
| 8522 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
| 8523 | hpsa_wait_for_mode_change_ack(h); |
| 8524 | #endif |
| 8525 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8526 | return; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8527 | } |
| 8528 | |
| 8529 | /* Check a register on the controller to see if there are configuration |
| 8530 | * changes (added/changed/removed logical drives, etc.) which mean that |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 8531 | * we should rescan the controller for devices. |
| 8532 | * Also check flag for driver-initiated rescan. |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8533 | */ |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8534 | static int hpsa_ctlr_needs_rescan(struct ctlr_info *h) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8535 | { |
Don Brace | 853633e | 2015-11-04 15:50:37 -0600 | [diff] [blame] | 8536 | if (h->drv_req_rescan) { |
| 8537 | h->drv_req_rescan = 0; |
| 8538 | return 1; |
| 8539 | } |
| 8540 | |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8541 | if (!(h->fw_support & MISC_FW_EVENT_NOTIFY)) |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8542 | return 0; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8543 | |
| 8544 | h->events = readl(&(h->cfgtable->event_notify)); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8545 | return h->events & RESCAN_REQUIRED_EVENT_BITS; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 8546 | } |
| 8547 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8548 | /* |
| 8549 | * Check if any of the offline devices have become ready |
| 8550 | */ |
| 8551 | static int hpsa_offline_devices_ready(struct ctlr_info *h) |
| 8552 | { |
| 8553 | unsigned long flags; |
| 8554 | struct offline_device_entry *d; |
| 8555 | struct list_head *this, *tmp; |
| 8556 | |
| 8557 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 8558 | list_for_each_safe(this, tmp, &h->offline_device_list) { |
| 8559 | d = list_entry(this, struct offline_device_entry, |
| 8560 | offline_list); |
| 8561 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
Stephen M. Cameron | d1fea47 | 2014-07-03 10:17:58 -0500 | [diff] [blame] | 8562 | if (!hpsa_volume_offline(h, d->scsi3addr)) { |
| 8563 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 8564 | list_del(&d->offline_list); |
| 8565 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8566 | return 1; |
Stephen M. Cameron | d1fea47 | 2014-07-03 10:17:58 -0500 | [diff] [blame] | 8567 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8568 | spin_lock_irqsave(&h->offline_device_lock, flags); |
| 8569 | } |
| 8570 | spin_unlock_irqrestore(&h->offline_device_lock, flags); |
| 8571 | return 0; |
| 8572 | } |
| 8573 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8574 | static int hpsa_luns_changed(struct ctlr_info *h) |
| 8575 | { |
| 8576 | int rc = 1; /* assume there are changes */ |
| 8577 | struct ReportLUNdata *logdev = NULL; |
| 8578 | |
| 8579 | /* if we can't find out if lun data has changed, |
| 8580 | * assume that it has. |
| 8581 | */ |
| 8582 | |
| 8583 | if (!h->lastlogicals) |
| 8584 | goto out; |
| 8585 | |
| 8586 | logdev = kzalloc(sizeof(*logdev), GFP_KERNEL); |
| 8587 | if (!logdev) { |
| 8588 | dev_warn(&h->pdev->dev, |
| 8589 | "Out of memory, can't track lun changes.\n"); |
| 8590 | goto out; |
| 8591 | } |
| 8592 | if (hpsa_scsi_do_report_luns(h, 1, logdev, sizeof(*logdev), 0)) { |
| 8593 | dev_warn(&h->pdev->dev, |
| 8594 | "report luns failed, can't track lun changes.\n"); |
| 8595 | goto out; |
| 8596 | } |
| 8597 | if (memcmp(logdev, h->lastlogicals, sizeof(*logdev))) { |
| 8598 | dev_info(&h->pdev->dev, |
| 8599 | "Lun changes detected.\n"); |
| 8600 | memcpy(h->lastlogicals, logdev, sizeof(*logdev)); |
| 8601 | goto out; |
| 8602 | } else |
| 8603 | rc = 0; /* no changes detected. */ |
| 8604 | out: |
| 8605 | kfree(logdev); |
| 8606 | return rc; |
| 8607 | } |
| 8608 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8609 | static void hpsa_rescan_ctlr_worker(struct work_struct *work) |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8610 | { |
| 8611 | unsigned long flags; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8612 | struct ctlr_info *h = container_of(to_delayed_work(work), |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8613 | struct ctlr_info, rescan_ctlr_work); |
| 8614 | |
| 8615 | |
| 8616 | if (h->remove_in_progress) |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8617 | return; |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8618 | |
Don Brace | bfd7546 | 2016-11-15 14:45:32 -0600 | [diff] [blame] | 8619 | /* |
| 8620 | * Do the scan after the reset |
| 8621 | */ |
| 8622 | if (h->reset_in_progress) { |
| 8623 | h->drv_req_rescan = 1; |
| 8624 | return; |
| 8625 | } |
| 8626 | |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8627 | if (hpsa_ctlr_needs_rescan(h) || hpsa_offline_devices_ready(h)) { |
| 8628 | scsi_host_get(h->scsi_host); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8629 | hpsa_ack_ctlr_events(h); |
| 8630 | hpsa_scan_start(h->scsi_host); |
| 8631 | scsi_host_put(h->scsi_host); |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8632 | } else if (h->discovery_polling) { |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 8633 | hpsa_disable_rld_caching(h); |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8634 | if (hpsa_luns_changed(h)) { |
| 8635 | struct Scsi_Host *sh = NULL; |
| 8636 | |
| 8637 | dev_info(&h->pdev->dev, |
| 8638 | "driver discovery polling rescan.\n"); |
| 8639 | sh = scsi_host_get(h->scsi_host); |
| 8640 | if (sh != NULL) { |
| 8641 | hpsa_scan_start(sh); |
| 8642 | scsi_host_put(sh); |
| 8643 | } |
| 8644 | } |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8645 | } |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8646 | spin_lock_irqsave(&h->lock, flags); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8647 | if (!h->remove_in_progress) |
| 8648 | queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work, |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8649 | h->heartbeat_sample_interval); |
| 8650 | spin_unlock_irqrestore(&h->lock, flags); |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 8651 | } |
| 8652 | |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8653 | static void hpsa_monitor_ctlr_worker(struct work_struct *work) |
| 8654 | { |
| 8655 | unsigned long flags; |
| 8656 | struct ctlr_info *h = container_of(to_delayed_work(work), |
| 8657 | struct ctlr_info, monitor_ctlr_work); |
| 8658 | |
| 8659 | detect_controller_lockup(h); |
| 8660 | if (lockup_detected(h)) |
| 8661 | return; |
| 8662 | |
| 8663 | spin_lock_irqsave(&h->lock, flags); |
| 8664 | if (!h->remove_in_progress) |
| 8665 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 8666 | h->heartbeat_sample_interval); |
| 8667 | spin_unlock_irqrestore(&h->lock, flags); |
| 8668 | } |
| 8669 | |
| 8670 | static struct workqueue_struct *hpsa_create_controller_wq(struct ctlr_info *h, |
| 8671 | char *name) |
| 8672 | { |
| 8673 | struct workqueue_struct *wq = NULL; |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8674 | |
Don Brace | 397ea9c | 2015-02-06 17:44:15 -0600 | [diff] [blame] | 8675 | wq = alloc_ordered_workqueue("%s_%d_hpsa", 0, name, h->ctlr); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8676 | if (!wq) |
| 8677 | dev_err(&h->pdev->dev, "failed to create %s workqueue\n", name); |
| 8678 | |
| 8679 | return wq; |
| 8680 | } |
| 8681 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8682 | 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] | 8683 | { |
Stephen M. Cameron | 4c2a8c4 | 2010-06-16 13:51:35 -0500 | [diff] [blame] | 8684 | int dac, rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8685 | struct ctlr_info *h; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8686 | int try_soft_reset = 0; |
| 8687 | unsigned long flags; |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 8688 | u32 board_id; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8689 | |
| 8690 | if (number_of_controllers == 0) |
| 8691 | printk(KERN_INFO DRIVER_NAME "\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8692 | |
Tomas Henzl | 6b6c1cd | 2015-04-02 15:25:54 +0200 | [diff] [blame] | 8693 | rc = hpsa_lookup_board_id(pdev, &board_id); |
| 8694 | if (rc < 0) { |
| 8695 | dev_warn(&pdev->dev, "Board ID not found\n"); |
| 8696 | return rc; |
| 8697 | } |
| 8698 | |
| 8699 | rc = hpsa_init_reset_devices(pdev, board_id); |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8700 | if (rc) { |
| 8701 | if (rc != -ENOTSUPP) |
| 8702 | return rc; |
| 8703 | /* If the reset fails in a particular way (it has no way to do |
| 8704 | * a proper hard reset, so returns -ENOTSUPP) we can try to do |
| 8705 | * a soft reset once we get the controller configured up to the |
| 8706 | * point that it can accept a command. |
| 8707 | */ |
| 8708 | try_soft_reset = 1; |
| 8709 | rc = 0; |
| 8710 | } |
| 8711 | |
| 8712 | reinit_after_soft_reset: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8713 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8714 | /* Command structures must be aligned on a 32-byte boundary because |
| 8715 | * the 5 lower bits of the address are used by the hardware. and by |
| 8716 | * the driver. See comments in hpsa.h for more info. |
| 8717 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 8718 | BUILD_BUG_ON(sizeof(struct CommandList) % COMMANDLIST_ALIGNMENT); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8719 | h = kzalloc(sizeof(*h), GFP_KERNEL); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8720 | if (!h) { |
| 8721 | dev_err(&pdev->dev, "Failed to allocate controller head\n"); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8722 | return -ENOMEM; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8723 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8724 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 8725 | h->pdev = pdev; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8726 | |
Stephen M. Cameron | a9a3a27 | 2011-02-15 15:32:53 -0600 | [diff] [blame] | 8727 | 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] | 8728 | INIT_LIST_HEAD(&h->offline_device_list); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 8729 | spin_lock_init(&h->lock); |
Stephen M. Cameron | 9846590 | 2014-02-21 16:25:00 -0600 | [diff] [blame] | 8730 | spin_lock_init(&h->offline_device_lock); |
Stephen M. Cameron | 6eaf46f | 2011-01-06 14:48:24 -0600 | [diff] [blame] | 8731 | spin_lock_init(&h->scan_lock); |
Don Brace | 34f0c62 | 2015-01-23 16:43:46 -0600 | [diff] [blame] | 8732 | atomic_set(&h->passthru_cmds_avail, HPSA_MAX_CONCURRENT_PASSTHRUS); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 8733 | atomic_set(&h->abort_cmds_available, HPSA_CMDS_RESERVED_FOR_ABORTS); |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8734 | |
| 8735 | /* Allocate and clear per-cpu variable lockup_detected */ |
| 8736 | h->lockup_detected = alloc_percpu(u32); |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 8737 | if (!h->lockup_detected) { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8738 | dev_err(&h->pdev->dev, "Failed to allocate lockup detector\n"); |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 8739 | rc = -ENOMEM; |
Robert Elliott | 2efa592 | 2015-04-23 09:34:53 -0500 | [diff] [blame] | 8740 | goto clean1; /* aer/h */ |
Stephen M. Cameron | 2a5ac32 | 2014-07-03 10:18:08 -0500 | [diff] [blame] | 8741 | } |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8742 | set_lockup_detected_for_all_cpus(h, 0); |
| 8743 | |
Stephen M. Cameron | 55c06c7 | 2010-05-27 15:12:46 -0500 | [diff] [blame] | 8744 | rc = hpsa_pci_init(h); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8745 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8746 | goto clean2; /* lu, aer/h */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8747 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8748 | /* relies on h-> settings made by hpsa_pci_init, including |
| 8749 | * interrupt_mode h->intr */ |
| 8750 | rc = hpsa_scsi_host_alloc(h); |
| 8751 | if (rc) |
| 8752 | goto clean2_5; /* pci, lu, aer/h */ |
| 8753 | |
| 8754 | sprintf(h->devname, HPSA "%d", h->scsi_host->host_no); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8755 | h->ctlr = number_of_controllers; |
| 8756 | number_of_controllers++; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8757 | |
| 8758 | /* configure PCI DMA stuff */ |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8759 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 8760 | if (rc == 0) { |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8761 | dac = 1; |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8762 | } else { |
| 8763 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 8764 | if (rc == 0) { |
| 8765 | dac = 0; |
| 8766 | } else { |
| 8767 | dev_err(&pdev->dev, "no suitable DMA available\n"); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8768 | goto clean3; /* shost, pci, lu, aer/h */ |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8769 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8770 | } |
| 8771 | |
| 8772 | /* make sure the board interrupts are off */ |
| 8773 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Stephen M. Cameron | 10f6601 | 2010-06-16 13:51:50 -0500 | [diff] [blame] | 8774 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8775 | rc = hpsa_request_irqs(h, do_hpsa_intr_msi, do_hpsa_intr_intx); |
| 8776 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8777 | goto clean3; /* shost, pci, lu, aer/h */ |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 8778 | rc = hpsa_alloc_cmd_pool(h); |
Robert Elliott | 8947fd1 | 2015-01-23 16:42:54 -0600 | [diff] [blame] | 8779 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8780 | goto clean4; /* irq, shost, pci, lu, aer/h */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8781 | rc = hpsa_alloc_sg_chain_blocks(h); |
| 8782 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8783 | goto clean5; /* cmd, irq, shost, pci, lu, aer/h */ |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 8784 | init_waitqueue_head(&h->scan_wait_queue); |
Stephen Cameron | 9b5c48c | 2015-04-23 09:32:06 -0500 | [diff] [blame] | 8785 | init_waitqueue_head(&h->abort_cmd_wait_queue); |
Webb Scales | d604f53 | 2015-04-23 09:35:22 -0500 | [diff] [blame] | 8786 | init_waitqueue_head(&h->event_sync_wait_queue); |
| 8787 | mutex_init(&h->reset_mutex); |
Stephen M. Cameron | a08a847 | 2010-02-04 08:43:16 -0600 | [diff] [blame] | 8788 | h->scan_finished = 1; /* no scan currently in progress */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8789 | |
| 8790 | pci_set_drvdata(pdev, h); |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 8791 | h->ndevices = 0; |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8792 | |
Stephen M. Cameron | 9a41338 | 2011-05-03 14:59:41 -0500 | [diff] [blame] | 8793 | spin_lock_init(&h->devlock); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8794 | rc = hpsa_put_ctlr_into_performant_mode(h); |
| 8795 | if (rc) |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8796 | goto clean6; /* sg, cmd, irq, shost, pci, lu, aer/h */ |
| 8797 | |
Robert Elliott | 2efa592 | 2015-04-23 09:34:53 -0500 | [diff] [blame] | 8798 | /* create the resubmit workqueue */ |
| 8799 | h->rescan_ctlr_wq = hpsa_create_controller_wq(h, "rescan"); |
| 8800 | if (!h->rescan_ctlr_wq) { |
| 8801 | rc = -ENOMEM; |
| 8802 | goto clean7; |
| 8803 | } |
| 8804 | |
| 8805 | h->resubmit_wq = hpsa_create_controller_wq(h, "resubmit"); |
| 8806 | if (!h->resubmit_wq) { |
| 8807 | rc = -ENOMEM; |
| 8808 | goto clean7; /* aer/h */ |
| 8809 | } |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8810 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8811 | /* |
| 8812 | * At this point, the controller is ready to take commands. |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8813 | * Now, if reset_devices and the hard reset didn't work, try |
| 8814 | * the soft reset and see if that works. |
| 8815 | */ |
| 8816 | if (try_soft_reset) { |
| 8817 | |
| 8818 | /* This is kind of gross. We may or may not get a completion |
| 8819 | * from the soft reset command, and if we do, then the value |
| 8820 | * from the fifo may or may not be valid. So, we wait 10 secs |
| 8821 | * after the reset throwing away any completions we get during |
| 8822 | * that time. Unregister the interrupt handler and register |
| 8823 | * fake ones to scoop up any residual completions. |
| 8824 | */ |
| 8825 | spin_lock_irqsave(&h->lock, flags); |
| 8826 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8827 | spin_unlock_irqrestore(&h->lock, flags); |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8828 | hpsa_free_irqs(h); |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 8829 | rc = hpsa_request_irqs(h, hpsa_msix_discard_completions, |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8830 | hpsa_intx_discard_completions); |
| 8831 | if (rc) { |
Robert Elliott | 9ee6179 | 2015-01-23 16:42:32 -0600 | [diff] [blame] | 8832 | dev_warn(&h->pdev->dev, |
| 8833 | "Failed to request_irq after soft reset.\n"); |
Robert Elliott | d498757 | 2015-04-23 09:34:37 -0500 | [diff] [blame] | 8834 | /* |
Robert Elliott | b2ef480 | 2015-04-23 09:34:48 -0500 | [diff] [blame] | 8835 | * cannot goto clean7 or free_irqs will be called |
| 8836 | * again. Instead, do its work |
| 8837 | */ |
| 8838 | hpsa_free_performant_mode(h); /* clean7 */ |
| 8839 | hpsa_free_sg_chain_blocks(h); /* clean6 */ |
| 8840 | hpsa_free_cmd_pool(h); /* clean5 */ |
| 8841 | /* |
| 8842 | * skip hpsa_free_irqs(h) clean4 since that |
| 8843 | * was just called before request_irqs failed |
Robert Elliott | d498757 | 2015-04-23 09:34:37 -0500 | [diff] [blame] | 8844 | */ |
| 8845 | goto clean3; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8846 | } |
| 8847 | |
| 8848 | rc = hpsa_kdump_soft_reset(h); |
| 8849 | if (rc) |
| 8850 | /* Neither hard nor soft reset worked, we're hosed. */ |
Don Brace | 7ef7323 | 2015-07-18 11:12:33 -0500 | [diff] [blame] | 8851 | goto clean7; |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8852 | |
| 8853 | dev_info(&h->pdev->dev, "Board READY.\n"); |
| 8854 | dev_info(&h->pdev->dev, |
| 8855 | "Waiting for stale completions to drain.\n"); |
| 8856 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 8857 | msleep(10000); |
| 8858 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8859 | |
| 8860 | rc = controller_reset_failed(h->cfgtable); |
| 8861 | if (rc) |
| 8862 | dev_info(&h->pdev->dev, |
| 8863 | "Soft reset appears to have failed.\n"); |
| 8864 | |
| 8865 | /* since the controller's reset, we have to go back and re-init |
| 8866 | * everything. Easiest to just forget what we've done and do it |
| 8867 | * all over again. |
| 8868 | */ |
| 8869 | hpsa_undo_allocations_after_kdump_soft_reset(h); |
| 8870 | try_soft_reset = 0; |
| 8871 | if (rc) |
Robert Elliott | b2ef480 | 2015-04-23 09:34:48 -0500 | [diff] [blame] | 8872 | /* don't goto clean, we already unallocated */ |
Stephen M. Cameron | 64670ac | 2011-05-03 14:59:51 -0500 | [diff] [blame] | 8873 | return -ENODEV; |
| 8874 | |
| 8875 | goto reinit_after_soft_reset; |
| 8876 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8877 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8878 | /* Enable Accelerated IO path at driver layer */ |
| 8879 | h->acciopath_status = 1; |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8880 | /* Disable discovery polling.*/ |
| 8881 | h->discovery_polling = 0; |
Scott Teel | da0697b | 2014-02-18 13:57:00 -0600 | [diff] [blame] | 8882 | |
Scott Teel | e863d68 | 2014-02-18 13:57:05 -0600 | [diff] [blame] | 8883 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8884 | /* Turn the interrupts on so we can service requests */ |
| 8885 | h->access.set_intr_mask(h, HPSA_INTR_ON); |
| 8886 | |
Stephen M. Cameron | 339b2b1 | 2010-02-04 08:42:50 -0600 | [diff] [blame] | 8887 | hpsa_hba_inquiry(h); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8888 | |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 8889 | h->lastlogicals = kzalloc(sizeof(*(h->lastlogicals)), GFP_KERNEL); |
| 8890 | if (!h->lastlogicals) |
| 8891 | dev_info(&h->pdev->dev, |
| 8892 | "Can't track change to report lun data\n"); |
| 8893 | |
Don Brace | cf47723 | 2016-04-27 17:13:26 -0500 | [diff] [blame] | 8894 | /* hook into SCSI subsystem */ |
| 8895 | rc = hpsa_scsi_add_host(h); |
| 8896 | if (rc) |
| 8897 | goto clean7; /* perf, sg, cmd, irq, shost, pci, lu, aer/h */ |
| 8898 | |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 8899 | /* Monitor the controller for firmware lockups */ |
| 8900 | h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; |
| 8901 | INIT_DELAYED_WORK(&h->monitor_ctlr_work, hpsa_monitor_ctlr_worker); |
| 8902 | schedule_delayed_work(&h->monitor_ctlr_work, |
| 8903 | h->heartbeat_sample_interval); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 8904 | INIT_DELAYED_WORK(&h->rescan_ctlr_work, hpsa_rescan_ctlr_worker); |
| 8905 | queue_delayed_work(h->rescan_ctlr_wq, &h->rescan_ctlr_work, |
| 8906 | h->heartbeat_sample_interval); |
Stephen M. Cameron | 88bf6d6 | 2013-11-01 11:02:25 -0500 | [diff] [blame] | 8907 | return 0; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8908 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8909 | clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8910 | hpsa_free_performant_mode(h); |
| 8911 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
| 8912 | clean6: /* sg, cmd, irq, pci, lockup, wq/aer/h */ |
Stephen M. Cameron | 33a2ffc | 2010-02-25 14:03:27 -0600 | [diff] [blame] | 8913 | hpsa_free_sg_chain_blocks(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8914 | clean5: /* cmd, irq, shost, pci, lu, aer/h */ |
Stephen M. Cameron | 2e9d1b3 | 2011-05-03 14:59:20 -0500 | [diff] [blame] | 8915 | hpsa_free_cmd_pool(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8916 | clean4: /* irq, shost, pci, lu, aer/h */ |
Robert Elliott | ec501a1 | 2015-01-23 16:41:40 -0600 | [diff] [blame] | 8917 | hpsa_free_irqs(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8918 | clean3: /* shost, pci, lu, aer/h */ |
| 8919 | scsi_host_put(h->scsi_host); |
| 8920 | h->scsi_host = NULL; |
| 8921 | clean2_5: /* pci, lu, aer/h */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 8922 | hpsa_free_pci_init(h); |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 8923 | clean2: /* lu, aer/h */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8924 | if (h->lockup_detected) { |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8925 | free_percpu(h->lockup_detected); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 8926 | h->lockup_detected = NULL; |
| 8927 | } |
| 8928 | clean1: /* wq/aer/h */ |
| 8929 | if (h->resubmit_wq) { |
| 8930 | destroy_workqueue(h->resubmit_wq); |
| 8931 | h->resubmit_wq = NULL; |
| 8932 | } |
| 8933 | if (h->rescan_ctlr_wq) { |
| 8934 | destroy_workqueue(h->rescan_ctlr_wq); |
| 8935 | h->rescan_ctlr_wq = NULL; |
| 8936 | } |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8937 | kfree(h); |
Stephen M. Cameron | ecd9aad | 2010-02-04 08:41:59 -0600 | [diff] [blame] | 8938 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8939 | } |
| 8940 | |
| 8941 | static void hpsa_flush_cache(struct ctlr_info *h) |
| 8942 | { |
| 8943 | char *flush_buf; |
| 8944 | struct CommandList *c; |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8945 | int rc; |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 8946 | |
Stephen M. Cameron | 094963d | 2014-05-29 10:53:18 -0500 | [diff] [blame] | 8947 | if (unlikely(lockup_detected(h))) |
Stephen M. Cameron | 702890e | 2013-09-23 13:33:30 -0500 | [diff] [blame] | 8948 | return; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8949 | flush_buf = kzalloc(4, GFP_KERNEL); |
| 8950 | if (!flush_buf) |
| 8951 | return; |
| 8952 | |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 8953 | c = cmd_alloc(h); |
Robert Elliott | bf43caf | 2015-04-23 09:33:38 -0500 | [diff] [blame] | 8954 | |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 8955 | if (fill_cmd(c, HPSA_CACHE_FLUSH, h, flush_buf, 4, 0, |
| 8956 | RAID_CTLR_LUNID, TYPE_CMD)) { |
| 8957 | goto out; |
| 8958 | } |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8959 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 8960 | PCI_DMA_TODEVICE, DEFAULT_TIMEOUT); |
Webb Scales | 25163bd | 2015-04-23 09:32:00 -0500 | [diff] [blame] | 8961 | if (rc) |
| 8962 | goto out; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8963 | if (c->err_info->CommandStatus != 0) |
Stephen M. Cameron | a2dac13 | 2013-02-20 11:24:41 -0600 | [diff] [blame] | 8964 | out: |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8965 | dev_warn(&h->pdev->dev, |
| 8966 | "error flushing cache on controller\n"); |
Stephen Cameron | 45fcb86 | 2015-01-23 16:43:04 -0600 | [diff] [blame] | 8967 | cmd_free(h, c); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 8968 | kfree(flush_buf); |
| 8969 | } |
| 8970 | |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 8971 | /* Make controller gather fresh report lun data each time we |
| 8972 | * send down a report luns request |
| 8973 | */ |
| 8974 | static void hpsa_disable_rld_caching(struct ctlr_info *h) |
| 8975 | { |
| 8976 | u32 *options; |
| 8977 | struct CommandList *c; |
| 8978 | int rc; |
| 8979 | |
| 8980 | /* Don't bother trying to set diag options if locked up */ |
| 8981 | if (unlikely(h->lockup_detected)) |
| 8982 | return; |
| 8983 | |
| 8984 | options = kzalloc(sizeof(*options), GFP_KERNEL); |
| 8985 | if (!options) { |
| 8986 | dev_err(&h->pdev->dev, |
| 8987 | "Error: failed to disable rld caching, during alloc.\n"); |
| 8988 | return; |
| 8989 | } |
| 8990 | |
| 8991 | c = cmd_alloc(h); |
| 8992 | |
| 8993 | /* first, get the current diag options settings */ |
| 8994 | if (fill_cmd(c, BMIC_SENSE_DIAG_OPTIONS, h, options, 4, 0, |
| 8995 | RAID_CTLR_LUNID, TYPE_CMD)) |
| 8996 | goto errout; |
| 8997 | |
| 8998 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 8999 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 9000 | if ((rc != 0) || (c->err_info->CommandStatus != 0)) |
| 9001 | goto errout; |
| 9002 | |
| 9003 | /* Now, set the bit for disabling the RLD caching */ |
| 9004 | *options |= HPSA_DIAG_OPTS_DISABLE_RLD_CACHING; |
| 9005 | |
| 9006 | if (fill_cmd(c, BMIC_SET_DIAG_OPTIONS, h, options, 4, 0, |
| 9007 | RAID_CTLR_LUNID, TYPE_CMD)) |
| 9008 | goto errout; |
| 9009 | |
| 9010 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 9011 | PCI_DMA_TODEVICE, DEFAULT_TIMEOUT); |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 9012 | if ((rc != 0) || (c->err_info->CommandStatus != 0)) |
| 9013 | goto errout; |
| 9014 | |
| 9015 | /* Now verify that it got set: */ |
| 9016 | if (fill_cmd(c, BMIC_SENSE_DIAG_OPTIONS, h, options, 4, 0, |
| 9017 | RAID_CTLR_LUNID, TYPE_CMD)) |
| 9018 | goto errout; |
| 9019 | |
| 9020 | rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, |
Don Brace | c448ecf | 2016-04-27 17:13:51 -0500 | [diff] [blame] | 9021 | PCI_DMA_FROMDEVICE, DEFAULT_TIMEOUT); |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 9022 | if ((rc != 0) || (c->err_info->CommandStatus != 0)) |
| 9023 | goto errout; |
| 9024 | |
Dan Carpenter | d8a080c | 2015-11-12 12:43:38 +0300 | [diff] [blame] | 9025 | if (*options & HPSA_DIAG_OPTS_DISABLE_RLD_CACHING) |
Scott Teel | c2adae4 | 2015-11-04 15:52:16 -0600 | [diff] [blame] | 9026 | goto out; |
| 9027 | |
| 9028 | errout: |
| 9029 | dev_err(&h->pdev->dev, |
| 9030 | "Error: failed to disable report lun data caching.\n"); |
| 9031 | out: |
| 9032 | cmd_free(h, c); |
| 9033 | kfree(options); |
| 9034 | } |
| 9035 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9036 | static void hpsa_shutdown(struct pci_dev *pdev) |
| 9037 | { |
| 9038 | struct ctlr_info *h; |
| 9039 | |
| 9040 | h = pci_get_drvdata(pdev); |
| 9041 | /* Turn board interrupts off and send the flush cache command |
| 9042 | * sendcmd will turn off interrupt, and send the flush... |
| 9043 | * To write all data in the battery backed cache to disks |
| 9044 | */ |
| 9045 | hpsa_flush_cache(h); |
| 9046 | h->access.set_intr_mask(h, HPSA_INTR_OFF); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9047 | hpsa_free_irqs(h); /* init_one 4 */ |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 9048 | hpsa_disable_interrupt_mode(h); /* pci_init 2 */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9049 | } |
| 9050 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9051 | static void hpsa_free_device_info(struct ctlr_info *h) |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 9052 | { |
| 9053 | int i; |
| 9054 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9055 | for (i = 0; i < h->ndevices; i++) { |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 9056 | kfree(h->dev[i]); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9057 | h->dev[i] = NULL; |
| 9058 | } |
Stephen M. Cameron | 55e14e7 | 2012-01-19 14:00:42 -0600 | [diff] [blame] | 9059 | } |
| 9060 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9061 | static void hpsa_remove_one(struct pci_dev *pdev) |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9062 | { |
| 9063 | struct ctlr_info *h; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 9064 | unsigned long flags; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9065 | |
| 9066 | if (pci_get_drvdata(pdev) == NULL) { |
Stephen M. Cameron | a0c1241 | 2011-10-26 16:22:04 -0500 | [diff] [blame] | 9067 | dev_err(&pdev->dev, "unable to remove device\n"); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9068 | return; |
| 9069 | } |
| 9070 | h = pci_get_drvdata(pdev); |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 9071 | |
| 9072 | /* Get rid of any controller monitoring work items */ |
| 9073 | spin_lock_irqsave(&h->lock, flags); |
| 9074 | h->remove_in_progress = 1; |
Stephen M. Cameron | 8a98db73 | 2013-12-04 17:10:07 -0600 | [diff] [blame] | 9075 | spin_unlock_irqrestore(&h->lock, flags); |
Don Brace | 6636e7f | 2015-01-23 16:45:17 -0600 | [diff] [blame] | 9076 | cancel_delayed_work_sync(&h->monitor_ctlr_work); |
| 9077 | cancel_delayed_work_sync(&h->rescan_ctlr_work); |
| 9078 | destroy_workqueue(h->rescan_ctlr_wq); |
| 9079 | destroy_workqueue(h->resubmit_wq); |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 9080 | |
Don Brace | 2d04130 | 2015-07-18 11:13:15 -0500 | [diff] [blame] | 9081 | /* |
| 9082 | * Call before disabling interrupts. |
| 9083 | * scsi_remove_host can trigger I/O operations especially |
| 9084 | * when multipath is enabled. There can be SYNCHRONIZE CACHE |
| 9085 | * operations which cannot complete and will hang the system. |
| 9086 | */ |
| 9087 | if (h->scsi_host) |
| 9088 | scsi_remove_host(h->scsi_host); /* init_one 8 */ |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9089 | /* includes hpsa_free_irqs - init_one 4 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 9090 | /* includes hpsa_disable_interrupt_mode - pci_init 2 */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9091 | hpsa_shutdown(pdev); |
Robert Elliott | cc64c81 | 2015-04-23 09:33:12 -0500 | [diff] [blame] | 9092 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9093 | hpsa_free_device_info(h); /* scan */ |
| 9094 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 9095 | kfree(h->hba_inquiry_data); /* init_one 10 */ |
| 9096 | h->hba_inquiry_data = NULL; /* init_one 10 */ |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 9097 | hpsa_free_ioaccel2_sg_chain_blocks(h); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9098 | hpsa_free_performant_mode(h); /* init_one 7 */ |
| 9099 | hpsa_free_sg_chain_blocks(h); /* init_one 6 */ |
| 9100 | hpsa_free_cmd_pool(h); /* init_one 5 */ |
Scott Teel | 3459225 | 2015-11-04 15:52:09 -0600 | [diff] [blame] | 9101 | kfree(h->lastlogicals); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9102 | |
| 9103 | /* hpsa_free_irqs already called via hpsa_shutdown init_one 4 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 9104 | |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 9105 | scsi_host_put(h->scsi_host); /* init_one 3 */ |
| 9106 | h->scsi_host = NULL; /* init_one 3 */ |
| 9107 | |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 9108 | /* includes hpsa_disable_interrupt_mode - pci_init 2 */ |
Robert Elliott | 2946e82 | 2015-04-23 09:35:09 -0500 | [diff] [blame] | 9109 | hpsa_free_pci_init(h); /* init_one 2.5 */ |
Robert Elliott | 195f2c6 | 2015-04-23 09:33:17 -0500 | [diff] [blame] | 9110 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9111 | free_percpu(h->lockup_detected); /* init_one 2 */ |
| 9112 | h->lockup_detected = NULL; /* init_one 2 */ |
| 9113 | /* (void) pci_disable_pcie_error_reporting(pdev); */ /* init_one 1 */ |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 9114 | |
| 9115 | hpsa_delete_sas_host(h); |
| 9116 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9117 | kfree(h); /* init_one 1 */ |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9118 | } |
| 9119 | |
| 9120 | static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev, |
| 9121 | __attribute__((unused)) pm_message_t state) |
| 9122 | { |
| 9123 | return -ENOSYS; |
| 9124 | } |
| 9125 | |
| 9126 | static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev) |
| 9127 | { |
| 9128 | return -ENOSYS; |
| 9129 | } |
| 9130 | |
| 9131 | static struct pci_driver hpsa_pci_driver = { |
Stephen M. Cameron | f79cfec | 2012-01-19 14:00:59 -0600 | [diff] [blame] | 9132 | .name = HPSA, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9133 | .probe = hpsa_init_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9134 | .remove = hpsa_remove_one, |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9135 | .id_table = hpsa_pci_device_id, /* id_table */ |
| 9136 | .shutdown = hpsa_shutdown, |
| 9137 | .suspend = hpsa_suspend, |
| 9138 | .resume = hpsa_resume, |
| 9139 | }; |
| 9140 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9141 | /* Fill in bucket_map[], given nsgs (the max number of |
| 9142 | * scatter gather elements supported) and bucket[], |
| 9143 | * which is an array of 8 integers. The bucket[] array |
| 9144 | * contains 8 different DMA transfer sizes (in 16 |
| 9145 | * byte increments) which the controller uses to fetch |
| 9146 | * commands. This function fills in bucket_map[], which |
| 9147 | * maps a given number of scatter gather elements to one of |
| 9148 | * the 8 DMA transfer sizes. The point of it is to allow the |
| 9149 | * controller to only do as much DMA as needed to fetch the |
| 9150 | * command, with the DMA transfer size encoded in the lower |
| 9151 | * bits of the command address. |
| 9152 | */ |
| 9153 | static void calc_bucket_map(int bucket[], int num_buckets, |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 9154 | int nsgs, int min_blocks, u32 *bucket_map) |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9155 | { |
| 9156 | int i, j, b, size; |
| 9157 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9158 | /* Note, bucket_map must have nsgs+1 entries. */ |
| 9159 | for (i = 0; i <= nsgs; i++) { |
| 9160 | /* Compute size of a command with i SG entries */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9161 | size = i + min_blocks; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9162 | b = num_buckets; /* Assume the biggest bucket */ |
| 9163 | /* Find the bucket that is just big enough */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9164 | for (j = 0; j < num_buckets; j++) { |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9165 | if (bucket[j] >= size) { |
| 9166 | b = j; |
| 9167 | break; |
| 9168 | } |
| 9169 | } |
| 9170 | /* for a command with i SG entries, use bucket b. */ |
| 9171 | bucket_map[i] = b; |
| 9172 | } |
| 9173 | } |
| 9174 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9175 | /* |
| 9176 | * return -ENODEV on err, 0 on success (or no action) |
| 9177 | * allocates numerous items that must be freed later |
| 9178 | */ |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 9179 | 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] | 9180 | { |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9181 | int i; |
| 9182 | unsigned long register_value; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9183 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 9184 | (trans_support & CFGTBL_Trans_use_short_tags) | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9185 | CFGTBL_Trans_enable_directed_msix | |
| 9186 | (trans_support & (CFGTBL_Trans_io_accel1 | |
| 9187 | CFGTBL_Trans_io_accel2)); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9188 | struct access_method access = SA5_performant_access; |
Stephen M. Cameron | def342b | 2010-05-27 15:14:39 -0500 | [diff] [blame] | 9189 | |
| 9190 | /* This is a bit complicated. There are 8 registers on |
| 9191 | * the controller which we write to to tell it 8 different |
| 9192 | * sizes of commands which there may be. It's a way of |
| 9193 | * reducing the DMA done to fetch each command. Encoded into |
| 9194 | * each command's tag are 3 bits which communicate to the controller |
| 9195 | * which of the eight sizes that command fits within. The size of |
| 9196 | * each command depends on how many scatter gather entries there are. |
| 9197 | * Each SG entry requires 16 bytes. The eight registers are programmed |
| 9198 | * with the number of 16-byte blocks a command of that size requires. |
| 9199 | * The smallest command possible requires 5 such 16 byte blocks. |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 9200 | * 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] | 9201 | * blocks. Note, this only extends to the SG entries contained |
| 9202 | * within the command block, and does not extend to chained blocks |
| 9203 | * of SG elements. bft[] contains the eight values we write to |
| 9204 | * the registers. They are not evenly distributed, but have more |
| 9205 | * sizes for small commands, and fewer sizes for larger commands. |
| 9206 | */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 9207 | 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] | 9208 | #define MIN_IOACCEL2_BFT_ENTRY 5 |
| 9209 | #define HPSA_IOACCEL2_HEADER_SZ 4 |
| 9210 | int bft2[16] = {MIN_IOACCEL2_BFT_ENTRY, 6, 7, 8, 9, 10, 11, 12, |
| 9211 | 13, 14, 15, 16, 17, 18, 19, |
| 9212 | HPSA_IOACCEL2_HEADER_SZ + IOACCEL2_MAXSGENTRIES}; |
| 9213 | BUILD_BUG_ON(ARRAY_SIZE(bft2) != 16); |
| 9214 | BUILD_BUG_ON(ARRAY_SIZE(bft) != 8); |
| 9215 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) > |
| 9216 | 16 * MIN_IOACCEL2_BFT_ENTRY); |
| 9217 | BUILD_BUG_ON(sizeof(struct ioaccel2_sg_element) != 16); |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 9218 | BUILD_BUG_ON(28 > SG_ENTRIES_IN_CMD + 4); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9219 | /* 5 = 1 s/g entry or 4k |
| 9220 | * 6 = 2 s/g entry or 8k |
| 9221 | * 8 = 4 s/g entry or 16k |
| 9222 | * 10 = 6 s/g entry or 24k |
| 9223 | */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9224 | |
Stephen M. Cameron | b3a52e7 | 2014-05-29 10:53:23 -0500 | [diff] [blame] | 9225 | /* If the controller supports either ioaccel method then |
| 9226 | * we can also use the RAID stack submit path that does not |
| 9227 | * perform the superfluous readl() after each command submission. |
| 9228 | */ |
| 9229 | if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2)) |
| 9230 | access = SA5_performant_access_no_read; |
| 9231 | |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9232 | /* Controller spec: zero out this buffer. */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9233 | for (i = 0; i < h->nreply_queues; i++) |
| 9234 | memset(h->reply_queue[i].head, 0, h->reply_queue_size); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9235 | |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 9236 | bft[7] = SG_ENTRIES_IN_CMD + 4; |
| 9237 | calc_bucket_map(bft, ARRAY_SIZE(bft), |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9238 | SG_ENTRIES_IN_CMD, 4, h->blockFetchTable); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9239 | for (i = 0; i < 8; i++) |
| 9240 | writel(bft[i], &h->transtable->BlockFetch[i]); |
| 9241 | |
| 9242 | /* size of controller ring buffer */ |
| 9243 | writel(h->max_commands, &h->transtable->RepQSize); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9244 | writel(h->nreply_queues, &h->transtable->RepQCount); |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9245 | writel(0, &h->transtable->RepQCtrAddrLow32); |
| 9246 | writel(0, &h->transtable->RepQCtrAddrHigh32); |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9247 | |
| 9248 | for (i = 0; i < h->nreply_queues; i++) { |
| 9249 | writel(0, &h->transtable->RepQAddr[i].upper); |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9250 | writel(h->reply_queue[i].busaddr, |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9251 | &h->transtable->RepQAddr[i].lower); |
| 9252 | } |
| 9253 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9254 | writel(0, &h->cfgtable->HostWrite.command_pool_addr_hi); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9255 | writel(transMethod, &(h->cfgtable->HostWrite.TransportRequest)); |
| 9256 | /* |
| 9257 | * enable outbound interrupt coalescing in accelerator mode; |
| 9258 | */ |
| 9259 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 9260 | access = SA5_ioaccel_mode1_access; |
| 9261 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 9262 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
Scott Teel | c349775 | 2014-02-18 13:56:34 -0600 | [diff] [blame] | 9263 | } else { |
| 9264 | if (trans_support & CFGTBL_Trans_io_accel2) { |
| 9265 | access = SA5_ioaccel_mode2_access; |
| 9266 | writel(10, &h->cfgtable->HostWrite.CoalIntDelay); |
| 9267 | writel(4, &h->cfgtable->HostWrite.CoalIntCount); |
| 9268 | } |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9269 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9270 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 9271 | if (hpsa_wait_for_mode_change_ack(h)) { |
| 9272 | dev_err(&h->pdev->dev, |
| 9273 | "performant mode problem - doorbell timeout\n"); |
| 9274 | return -ENODEV; |
| 9275 | } |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9276 | register_value = readl(&(h->cfgtable->TransportActive)); |
| 9277 | if (!(register_value & CFGTBL_Trans_Performant)) { |
Stephen Cameron | 050f714 | 2015-01-23 16:42:22 -0600 | [diff] [blame] | 9278 | dev_err(&h->pdev->dev, |
| 9279 | "performant mode problem - transport not active\n"); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 9280 | return -ENODEV; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9281 | } |
Stephen M. Cameron | 960a30e | 2011-02-15 15:33:03 -0600 | [diff] [blame] | 9282 | /* Change the access methods to the performant access methods */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9283 | h->access = access; |
| 9284 | h->transMethod = transMethod; |
| 9285 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9286 | if (!((trans_support & CFGTBL_Trans_io_accel1) || |
| 9287 | (trans_support & CFGTBL_Trans_io_accel2))) |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 9288 | return 0; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9289 | |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9290 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 9291 | /* Set up I/O accelerator mode */ |
| 9292 | for (i = 0; i < h->nreply_queues; i++) { |
| 9293 | writel(i, h->vaddr + IOACCEL_MODE1_REPLY_QUEUE_INDEX); |
| 9294 | h->reply_queue[i].current_entry = |
| 9295 | readl(h->vaddr + IOACCEL_MODE1_PRODUCER_INDEX); |
| 9296 | } |
| 9297 | bft[7] = h->ioaccel_maxsg + 8; |
| 9298 | calc_bucket_map(bft, ARRAY_SIZE(bft), h->ioaccel_maxsg, 8, |
| 9299 | h->ioaccel1_blockFetchTable); |
| 9300 | |
| 9301 | /* initialize all reply queue entries to unused */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9302 | for (i = 0; i < h->nreply_queues; i++) |
| 9303 | memset(h->reply_queue[i].head, |
| 9304 | (u8) IOACCEL_MODE1_REPLY_UNUSED, |
| 9305 | h->reply_queue_size); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9306 | |
| 9307 | /* set all the constant fields in the accelerator command |
| 9308 | * frames once at init time to save CPU cycles later. |
| 9309 | */ |
| 9310 | for (i = 0; i < h->nr_cmds; i++) { |
| 9311 | struct io_accel1_cmd *cp = &h->ioaccel_cmd_pool[i]; |
| 9312 | |
| 9313 | cp->function = IOACCEL1_FUNCTION_SCSIIO; |
| 9314 | cp->err_info = (u32) (h->errinfo_pool_dhandle + |
| 9315 | (i * sizeof(struct ErrorInfo))); |
| 9316 | cp->err_info_len = sizeof(struct ErrorInfo); |
| 9317 | cp->sgl_offset = IOACCEL1_SGLOFFSET; |
Don Brace | 2b08b3e | 2015-01-23 16:41:09 -0600 | [diff] [blame] | 9318 | cp->host_context_flags = |
| 9319 | cpu_to_le16(IOACCEL1_HCFLAGS_CISS_FORMAT); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9320 | cp->timeout_sec = 0; |
| 9321 | cp->ReplyQueue = 0; |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 9322 | cp->tag = |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9323 | cpu_to_le64((i << DIRECT_LOOKUP_SHIFT)); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 9324 | cp->host_addr = |
| 9325 | cpu_to_le64(h->ioaccel_cmd_pool_dhandle + |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9326 | (i * sizeof(struct io_accel1_cmd))); |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9327 | } |
| 9328 | } else if (trans_support & CFGTBL_Trans_io_accel2) { |
| 9329 | u64 cfg_offset, cfg_base_addr_index; |
| 9330 | u32 bft2_offset, cfg_base_addr; |
| 9331 | int rc; |
| 9332 | |
| 9333 | rc = hpsa_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr, |
| 9334 | &cfg_base_addr_index, &cfg_offset); |
| 9335 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, sg) != 64); |
| 9336 | bft2[15] = h->ioaccel_maxsg + HPSA_IOACCEL2_HEADER_SZ; |
| 9337 | calc_bucket_map(bft2, ARRAY_SIZE(bft2), h->ioaccel_maxsg, |
| 9338 | 4, h->ioaccel2_blockFetchTable); |
| 9339 | bft2_offset = readl(&h->cfgtable->io_accel_request_size_offset); |
| 9340 | BUILD_BUG_ON(offsetof(struct CfgTable, |
| 9341 | io_accel_request_size_offset) != 0xb8); |
| 9342 | h->ioaccel2_bft2_regs = |
| 9343 | remap_pci_mem(pci_resource_start(h->pdev, |
| 9344 | cfg_base_addr_index) + |
| 9345 | cfg_offset + bft2_offset, |
| 9346 | ARRAY_SIZE(bft2) * |
| 9347 | sizeof(*h->ioaccel2_bft2_regs)); |
| 9348 | for (i = 0; i < ARRAY_SIZE(bft2); i++) |
| 9349 | writel(bft2[i], &h->ioaccel2_bft2_regs[i]); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9350 | } |
Stephen M. Cameron | b9af493 | 2014-02-18 13:56:29 -0600 | [diff] [blame] | 9351 | writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); |
Robert Elliott | c706a79 | 2015-01-23 16:45:01 -0600 | [diff] [blame] | 9352 | if (hpsa_wait_for_mode_change_ack(h)) { |
| 9353 | dev_err(&h->pdev->dev, |
| 9354 | "performant mode problem - enabling ioaccel mode\n"); |
| 9355 | return -ENODEV; |
| 9356 | } |
| 9357 | return 0; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9358 | } |
| 9359 | |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9360 | /* Free ioaccel1 mode command blocks and block fetch table */ |
| 9361 | static void hpsa_free_ioaccel1_cmd_and_bft(struct ctlr_info *h) |
| 9362 | { |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9363 | if (h->ioaccel_cmd_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9364 | pci_free_consistent(h->pdev, |
| 9365 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 9366 | h->ioaccel_cmd_pool, |
| 9367 | h->ioaccel_cmd_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9368 | h->ioaccel_cmd_pool = NULL; |
| 9369 | h->ioaccel_cmd_pool_dhandle = 0; |
| 9370 | } |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9371 | kfree(h->ioaccel1_blockFetchTable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9372 | h->ioaccel1_blockFetchTable = NULL; |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9373 | } |
| 9374 | |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 9375 | /* Allocate ioaccel1 mode command blocks and block fetch table */ |
| 9376 | static int hpsa_alloc_ioaccel1_cmd_and_bft(struct ctlr_info *h) |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9377 | { |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 9378 | h->ioaccel_maxsg = |
| 9379 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 9380 | if (h->ioaccel_maxsg > IOACCEL1_MAXSGENTRIES) |
| 9381 | h->ioaccel_maxsg = IOACCEL1_MAXSGENTRIES; |
| 9382 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9383 | /* Command structures must be aligned on a 128-byte boundary |
| 9384 | * because the 7 lower bits of the address are used by the |
| 9385 | * hardware. |
| 9386 | */ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9387 | BUILD_BUG_ON(sizeof(struct io_accel1_cmd) % |
| 9388 | IOACCEL1_COMMANDLIST_ALIGNMENT); |
| 9389 | h->ioaccel_cmd_pool = |
| 9390 | pci_alloc_consistent(h->pdev, |
| 9391 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool), |
| 9392 | &(h->ioaccel_cmd_pool_dhandle)); |
| 9393 | |
| 9394 | h->ioaccel1_blockFetchTable = |
Stephen M. Cameron | 283b4a9 | 2014-02-18 13:55:33 -0600 | [diff] [blame] | 9395 | kmalloc(((h->ioaccel_maxsg + 1) * |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9396 | sizeof(u32)), GFP_KERNEL); |
| 9397 | |
| 9398 | if ((h->ioaccel_cmd_pool == NULL) || |
| 9399 | (h->ioaccel1_blockFetchTable == NULL)) |
| 9400 | goto clean_up; |
| 9401 | |
| 9402 | memset(h->ioaccel_cmd_pool, 0, |
| 9403 | h->nr_cmds * sizeof(*h->ioaccel_cmd_pool)); |
| 9404 | return 0; |
| 9405 | |
| 9406 | clean_up: |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9407 | hpsa_free_ioaccel1_cmd_and_bft(h); |
Robert Elliott | 2dd02d7 | 2015-04-23 09:33:43 -0500 | [diff] [blame] | 9408 | return -ENOMEM; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9409 | } |
| 9410 | |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9411 | /* Free ioaccel2 mode command blocks and block fetch table */ |
| 9412 | static void hpsa_free_ioaccel2_cmd_and_bft(struct ctlr_info *h) |
| 9413 | { |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 9414 | hpsa_free_ioaccel2_sg_chain_blocks(h); |
| 9415 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9416 | if (h->ioaccel2_cmd_pool) { |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9417 | pci_free_consistent(h->pdev, |
| 9418 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 9419 | h->ioaccel2_cmd_pool, |
| 9420 | h->ioaccel2_cmd_pool_dhandle); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9421 | h->ioaccel2_cmd_pool = NULL; |
| 9422 | h->ioaccel2_cmd_pool_dhandle = 0; |
| 9423 | } |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9424 | kfree(h->ioaccel2_blockFetchTable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9425 | h->ioaccel2_blockFetchTable = NULL; |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9426 | } |
| 9427 | |
Robert Elliott | d37ffbe | 2015-04-23 09:32:27 -0500 | [diff] [blame] | 9428 | /* Allocate ioaccel2 mode command blocks and block fetch table */ |
| 9429 | 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] | 9430 | { |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 9431 | int rc; |
| 9432 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 9433 | /* Allocate ioaccel2 mode command blocks and block fetch table */ |
| 9434 | |
| 9435 | h->ioaccel_maxsg = |
| 9436 | readl(&(h->cfgtable->io_accel_max_embedded_sg_count)); |
| 9437 | if (h->ioaccel_maxsg > IOACCEL2_MAXSGENTRIES) |
| 9438 | h->ioaccel_maxsg = IOACCEL2_MAXSGENTRIES; |
| 9439 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 9440 | BUILD_BUG_ON(sizeof(struct io_accel2_cmd) % |
| 9441 | IOACCEL2_COMMANDLIST_ALIGNMENT); |
| 9442 | h->ioaccel2_cmd_pool = |
| 9443 | pci_alloc_consistent(h->pdev, |
| 9444 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool), |
| 9445 | &(h->ioaccel2_cmd_pool_dhandle)); |
| 9446 | |
| 9447 | h->ioaccel2_blockFetchTable = |
| 9448 | kmalloc(((h->ioaccel_maxsg + 1) * |
| 9449 | sizeof(u32)), GFP_KERNEL); |
| 9450 | |
| 9451 | if ((h->ioaccel2_cmd_pool == NULL) || |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 9452 | (h->ioaccel2_blockFetchTable == NULL)) { |
| 9453 | rc = -ENOMEM; |
| 9454 | goto clean_up; |
| 9455 | } |
| 9456 | |
| 9457 | rc = hpsa_allocate_ioaccel2_sg_chain_blocks(h); |
| 9458 | if (rc) |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 9459 | goto clean_up; |
| 9460 | |
| 9461 | memset(h->ioaccel2_cmd_pool, 0, |
| 9462 | h->nr_cmds * sizeof(*h->ioaccel2_cmd_pool)); |
| 9463 | return 0; |
| 9464 | |
| 9465 | clean_up: |
Robert Elliott | 1fb7c98 | 2015-04-23 09:33:22 -0500 | [diff] [blame] | 9466 | hpsa_free_ioaccel2_cmd_and_bft(h); |
Webb Scales | d9a729f | 2015-04-23 09:33:27 -0500 | [diff] [blame] | 9467 | return rc; |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 9468 | } |
| 9469 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9470 | /* Free items allocated by hpsa_put_ctlr_into_performant_mode */ |
| 9471 | static void hpsa_free_performant_mode(struct ctlr_info *h) |
| 9472 | { |
| 9473 | kfree(h->blockFetchTable); |
| 9474 | h->blockFetchTable = NULL; |
| 9475 | hpsa_free_reply_queues(h); |
| 9476 | hpsa_free_ioaccel1_cmd_and_bft(h); |
| 9477 | hpsa_free_ioaccel2_cmd_and_bft(h); |
| 9478 | } |
| 9479 | |
| 9480 | /* return -ENODEV on error, 0 on success (or no action) |
| 9481 | * allocates numerous items that must be freed later |
| 9482 | */ |
| 9483 | 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] | 9484 | { |
| 9485 | u32 trans_support; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9486 | unsigned long transMethod = CFGTBL_Trans_Performant | |
| 9487 | CFGTBL_Trans_use_short_tags; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9488 | int i, rc; |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9489 | |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 9490 | if (hpsa_simple_mode) |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9491 | return 0; |
Stephen M. Cameron | 02ec19c | 2011-01-06 14:48:29 -0600 | [diff] [blame] | 9492 | |
scameron@beardog.cce.hp.com | 67c99a7 | 2014-04-14 14:01:09 -0500 | [diff] [blame] | 9493 | trans_support = readl(&(h->cfgtable->TransportSupport)); |
| 9494 | if (!(trans_support & PERFORMANT_MODE)) |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9495 | return 0; |
scameron@beardog.cce.hp.com | 67c99a7 | 2014-04-14 14:01:09 -0500 | [diff] [blame] | 9496 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9497 | /* Check for I/O accelerator mode support */ |
| 9498 | if (trans_support & CFGTBL_Trans_io_accel1) { |
| 9499 | transMethod |= CFGTBL_Trans_io_accel1 | |
| 9500 | CFGTBL_Trans_enable_directed_msix; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9501 | rc = hpsa_alloc_ioaccel1_cmd_and_bft(h); |
| 9502 | if (rc) |
| 9503 | return rc; |
| 9504 | } else if (trans_support & CFGTBL_Trans_io_accel2) { |
| 9505 | transMethod |= CFGTBL_Trans_io_accel2 | |
Stephen M. Cameron | aca9012 | 2014-02-18 13:56:14 -0600 | [diff] [blame] | 9506 | CFGTBL_Trans_enable_directed_msix; |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9507 | rc = hpsa_alloc_ioaccel2_cmd_and_bft(h); |
| 9508 | if (rc) |
| 9509 | return rc; |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9510 | } |
| 9511 | |
Christoph Hellwig | bc2bb15 | 2016-11-09 10:42:22 -0800 | [diff] [blame] | 9512 | h->nreply_queues = h->msix_vectors > 0 ? h->msix_vectors : 1; |
Stephen M. Cameron | cba3d38 | 2010-06-16 13:51:56 -0500 | [diff] [blame] | 9513 | hpsa_get_max_perf_mode_cmds(h); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9514 | /* Performant mode ring buffer and supporting data structures */ |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9515 | h->reply_queue_size = h->max_commands * sizeof(u64); |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9516 | |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9517 | for (i = 0; i < h->nreply_queues; i++) { |
Stephen M. Cameron | 072b051 | 2014-05-29 10:53:07 -0500 | [diff] [blame] | 9518 | h->reply_queue[i].head = pci_alloc_consistent(h->pdev, |
| 9519 | h->reply_queue_size, |
| 9520 | &(h->reply_queue[i].busaddr)); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9521 | if (!h->reply_queue[i].head) { |
| 9522 | rc = -ENOMEM; |
| 9523 | goto clean1; /* rq, ioaccel */ |
| 9524 | } |
Matt Gates | 254f796 | 2012-05-01 11:43:06 -0500 | [diff] [blame] | 9525 | h->reply_queue[i].size = h->max_commands; |
| 9526 | h->reply_queue[i].wraparound = 1; /* spec: init to 1 */ |
| 9527 | h->reply_queue[i].current_entry = 0; |
| 9528 | } |
| 9529 | |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9530 | /* Need a block fetch table for performant mode */ |
Stephen M. Cameron | d66ae08 | 2012-01-19 14:00:48 -0600 | [diff] [blame] | 9531 | h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) * |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9532 | sizeof(u32)), GFP_KERNEL); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9533 | if (!h->blockFetchTable) { |
| 9534 | rc = -ENOMEM; |
| 9535 | goto clean1; /* rq, ioaccel */ |
| 9536 | } |
Stephen M. Cameron | 6c311b5 | 2010-05-27 15:14:19 -0500 | [diff] [blame] | 9537 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9538 | rc = hpsa_enter_performant_mode(h, trans_support); |
| 9539 | if (rc) |
| 9540 | goto clean2; /* bft, rq, ioaccel */ |
| 9541 | return 0; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9542 | |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9543 | clean2: /* bft, rq, ioaccel */ |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9544 | kfree(h->blockFetchTable); |
Robert Elliott | 105a3db | 2015-04-23 09:33:48 -0500 | [diff] [blame] | 9545 | h->blockFetchTable = NULL; |
| 9546 | clean1: /* rq, ioaccel */ |
| 9547 | hpsa_free_reply_queues(h); |
| 9548 | hpsa_free_ioaccel1_cmd_and_bft(h); |
| 9549 | hpsa_free_ioaccel2_cmd_and_bft(h); |
| 9550 | return rc; |
Don Brace | 303932f | 2010-02-04 08:42:40 -0600 | [diff] [blame] | 9551 | } |
| 9552 | |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9553 | static int is_accelerated_cmd(struct CommandList *c) |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 9554 | { |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9555 | return c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_IOACCEL2; |
| 9556 | } |
| 9557 | |
| 9558 | static void hpsa_drain_accel_commands(struct ctlr_info *h) |
| 9559 | { |
| 9560 | struct CommandList *c = NULL; |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9561 | int i, accel_cmds_out; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 9562 | int refcount; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 9563 | |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9564 | do { /* wait for all outstanding ioaccel commands to drain out */ |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9565 | accel_cmds_out = 0; |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9566 | for (i = 0; i < h->nr_cmds; i++) { |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9567 | c = h->cmd_pool + i; |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 9568 | refcount = atomic_inc_return(&c->refcount); |
| 9569 | if (refcount > 1) /* Command is allocated */ |
| 9570 | accel_cmds_out += is_accelerated_cmd(c); |
| 9571 | cmd_free(h, c); |
Don Brace | f2405db | 2015-01-23 16:43:09 -0600 | [diff] [blame] | 9572 | } |
Stephen M. Cameron | 23100dd | 2014-02-18 13:57:37 -0600 | [diff] [blame] | 9573 | if (accel_cmds_out <= 0) |
Webb Scales | 281a7fd | 2015-01-23 16:43:35 -0600 | [diff] [blame] | 9574 | break; |
Stephen M. Cameron | 76438d0 | 2014-02-18 13:55:43 -0600 | [diff] [blame] | 9575 | msleep(100); |
| 9576 | } while (1); |
| 9577 | } |
| 9578 | |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 9579 | static struct hpsa_sas_phy *hpsa_alloc_sas_phy( |
| 9580 | struct hpsa_sas_port *hpsa_sas_port) |
| 9581 | { |
| 9582 | struct hpsa_sas_phy *hpsa_sas_phy; |
| 9583 | struct sas_phy *phy; |
| 9584 | |
| 9585 | hpsa_sas_phy = kzalloc(sizeof(*hpsa_sas_phy), GFP_KERNEL); |
| 9586 | if (!hpsa_sas_phy) |
| 9587 | return NULL; |
| 9588 | |
| 9589 | phy = sas_phy_alloc(hpsa_sas_port->parent_node->parent_dev, |
| 9590 | hpsa_sas_port->next_phy_index); |
| 9591 | if (!phy) { |
| 9592 | kfree(hpsa_sas_phy); |
| 9593 | return NULL; |
| 9594 | } |
| 9595 | |
| 9596 | hpsa_sas_port->next_phy_index++; |
| 9597 | hpsa_sas_phy->phy = phy; |
| 9598 | hpsa_sas_phy->parent_port = hpsa_sas_port; |
| 9599 | |
| 9600 | return hpsa_sas_phy; |
| 9601 | } |
| 9602 | |
| 9603 | static void hpsa_free_sas_phy(struct hpsa_sas_phy *hpsa_sas_phy) |
| 9604 | { |
| 9605 | struct sas_phy *phy = hpsa_sas_phy->phy; |
| 9606 | |
| 9607 | sas_port_delete_phy(hpsa_sas_phy->parent_port->port, phy); |
| 9608 | sas_phy_free(phy); |
| 9609 | if (hpsa_sas_phy->added_to_port) |
| 9610 | list_del(&hpsa_sas_phy->phy_list_entry); |
| 9611 | kfree(hpsa_sas_phy); |
| 9612 | } |
| 9613 | |
| 9614 | static int hpsa_sas_port_add_phy(struct hpsa_sas_phy *hpsa_sas_phy) |
| 9615 | { |
| 9616 | int rc; |
| 9617 | struct hpsa_sas_port *hpsa_sas_port; |
| 9618 | struct sas_phy *phy; |
| 9619 | struct sas_identify *identify; |
| 9620 | |
| 9621 | hpsa_sas_port = hpsa_sas_phy->parent_port; |
| 9622 | phy = hpsa_sas_phy->phy; |
| 9623 | |
| 9624 | identify = &phy->identify; |
| 9625 | memset(identify, 0, sizeof(*identify)); |
| 9626 | identify->sas_address = hpsa_sas_port->sas_address; |
| 9627 | identify->device_type = SAS_END_DEVICE; |
| 9628 | identify->initiator_port_protocols = SAS_PROTOCOL_STP; |
| 9629 | identify->target_port_protocols = SAS_PROTOCOL_STP; |
| 9630 | phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN; |
| 9631 | phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN; |
| 9632 | phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN; |
| 9633 | phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN; |
| 9634 | phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; |
| 9635 | |
| 9636 | rc = sas_phy_add(hpsa_sas_phy->phy); |
| 9637 | if (rc) |
| 9638 | return rc; |
| 9639 | |
| 9640 | sas_port_add_phy(hpsa_sas_port->port, hpsa_sas_phy->phy); |
| 9641 | list_add_tail(&hpsa_sas_phy->phy_list_entry, |
| 9642 | &hpsa_sas_port->phy_list_head); |
| 9643 | hpsa_sas_phy->added_to_port = true; |
| 9644 | |
| 9645 | return 0; |
| 9646 | } |
| 9647 | |
| 9648 | static int |
| 9649 | hpsa_sas_port_add_rphy(struct hpsa_sas_port *hpsa_sas_port, |
| 9650 | struct sas_rphy *rphy) |
| 9651 | { |
| 9652 | struct sas_identify *identify; |
| 9653 | |
| 9654 | identify = &rphy->identify; |
| 9655 | identify->sas_address = hpsa_sas_port->sas_address; |
| 9656 | identify->initiator_port_protocols = SAS_PROTOCOL_STP; |
| 9657 | identify->target_port_protocols = SAS_PROTOCOL_STP; |
| 9658 | |
| 9659 | return sas_rphy_add(rphy); |
| 9660 | } |
| 9661 | |
| 9662 | static struct hpsa_sas_port |
| 9663 | *hpsa_alloc_sas_port(struct hpsa_sas_node *hpsa_sas_node, |
| 9664 | u64 sas_address) |
| 9665 | { |
| 9666 | int rc; |
| 9667 | struct hpsa_sas_port *hpsa_sas_port; |
| 9668 | struct sas_port *port; |
| 9669 | |
| 9670 | hpsa_sas_port = kzalloc(sizeof(*hpsa_sas_port), GFP_KERNEL); |
| 9671 | if (!hpsa_sas_port) |
| 9672 | return NULL; |
| 9673 | |
| 9674 | INIT_LIST_HEAD(&hpsa_sas_port->phy_list_head); |
| 9675 | hpsa_sas_port->parent_node = hpsa_sas_node; |
| 9676 | |
| 9677 | port = sas_port_alloc_num(hpsa_sas_node->parent_dev); |
| 9678 | if (!port) |
| 9679 | goto free_hpsa_port; |
| 9680 | |
| 9681 | rc = sas_port_add(port); |
| 9682 | if (rc) |
| 9683 | goto free_sas_port; |
| 9684 | |
| 9685 | hpsa_sas_port->port = port; |
| 9686 | hpsa_sas_port->sas_address = sas_address; |
| 9687 | list_add_tail(&hpsa_sas_port->port_list_entry, |
| 9688 | &hpsa_sas_node->port_list_head); |
| 9689 | |
| 9690 | return hpsa_sas_port; |
| 9691 | |
| 9692 | free_sas_port: |
| 9693 | sas_port_free(port); |
| 9694 | free_hpsa_port: |
| 9695 | kfree(hpsa_sas_port); |
| 9696 | |
| 9697 | return NULL; |
| 9698 | } |
| 9699 | |
| 9700 | static void hpsa_free_sas_port(struct hpsa_sas_port *hpsa_sas_port) |
| 9701 | { |
| 9702 | struct hpsa_sas_phy *hpsa_sas_phy; |
| 9703 | struct hpsa_sas_phy *next; |
| 9704 | |
| 9705 | list_for_each_entry_safe(hpsa_sas_phy, next, |
| 9706 | &hpsa_sas_port->phy_list_head, phy_list_entry) |
| 9707 | hpsa_free_sas_phy(hpsa_sas_phy); |
| 9708 | |
| 9709 | sas_port_delete(hpsa_sas_port->port); |
| 9710 | list_del(&hpsa_sas_port->port_list_entry); |
| 9711 | kfree(hpsa_sas_port); |
| 9712 | } |
| 9713 | |
| 9714 | static struct hpsa_sas_node *hpsa_alloc_sas_node(struct device *parent_dev) |
| 9715 | { |
| 9716 | struct hpsa_sas_node *hpsa_sas_node; |
| 9717 | |
| 9718 | hpsa_sas_node = kzalloc(sizeof(*hpsa_sas_node), GFP_KERNEL); |
| 9719 | if (hpsa_sas_node) { |
| 9720 | hpsa_sas_node->parent_dev = parent_dev; |
| 9721 | INIT_LIST_HEAD(&hpsa_sas_node->port_list_head); |
| 9722 | } |
| 9723 | |
| 9724 | return hpsa_sas_node; |
| 9725 | } |
| 9726 | |
| 9727 | static void hpsa_free_sas_node(struct hpsa_sas_node *hpsa_sas_node) |
| 9728 | { |
| 9729 | struct hpsa_sas_port *hpsa_sas_port; |
| 9730 | struct hpsa_sas_port *next; |
| 9731 | |
| 9732 | if (!hpsa_sas_node) |
| 9733 | return; |
| 9734 | |
| 9735 | list_for_each_entry_safe(hpsa_sas_port, next, |
| 9736 | &hpsa_sas_node->port_list_head, port_list_entry) |
| 9737 | hpsa_free_sas_port(hpsa_sas_port); |
| 9738 | |
| 9739 | kfree(hpsa_sas_node); |
| 9740 | } |
| 9741 | |
| 9742 | static struct hpsa_scsi_dev_t |
| 9743 | *hpsa_find_device_by_sas_rphy(struct ctlr_info *h, |
| 9744 | struct sas_rphy *rphy) |
| 9745 | { |
| 9746 | int i; |
| 9747 | struct hpsa_scsi_dev_t *device; |
| 9748 | |
| 9749 | for (i = 0; i < h->ndevices; i++) { |
| 9750 | device = h->dev[i]; |
| 9751 | if (!device->sas_port) |
| 9752 | continue; |
| 9753 | if (device->sas_port->rphy == rphy) |
| 9754 | return device; |
| 9755 | } |
| 9756 | |
| 9757 | return NULL; |
| 9758 | } |
| 9759 | |
| 9760 | static int hpsa_add_sas_host(struct ctlr_info *h) |
| 9761 | { |
| 9762 | int rc; |
| 9763 | struct device *parent_dev; |
| 9764 | struct hpsa_sas_node *hpsa_sas_node; |
| 9765 | struct hpsa_sas_port *hpsa_sas_port; |
| 9766 | struct hpsa_sas_phy *hpsa_sas_phy; |
| 9767 | |
| 9768 | parent_dev = &h->scsi_host->shost_gendev; |
| 9769 | |
| 9770 | hpsa_sas_node = hpsa_alloc_sas_node(parent_dev); |
| 9771 | if (!hpsa_sas_node) |
| 9772 | return -ENOMEM; |
| 9773 | |
| 9774 | hpsa_sas_port = hpsa_alloc_sas_port(hpsa_sas_node, h->sas_address); |
| 9775 | if (!hpsa_sas_port) { |
| 9776 | rc = -ENODEV; |
| 9777 | goto free_sas_node; |
| 9778 | } |
| 9779 | |
| 9780 | hpsa_sas_phy = hpsa_alloc_sas_phy(hpsa_sas_port); |
| 9781 | if (!hpsa_sas_phy) { |
| 9782 | rc = -ENODEV; |
| 9783 | goto free_sas_port; |
| 9784 | } |
| 9785 | |
| 9786 | rc = hpsa_sas_port_add_phy(hpsa_sas_phy); |
| 9787 | if (rc) |
| 9788 | goto free_sas_phy; |
| 9789 | |
| 9790 | h->sas_host = hpsa_sas_node; |
| 9791 | |
| 9792 | return 0; |
| 9793 | |
| 9794 | free_sas_phy: |
| 9795 | hpsa_free_sas_phy(hpsa_sas_phy); |
| 9796 | free_sas_port: |
| 9797 | hpsa_free_sas_port(hpsa_sas_port); |
| 9798 | free_sas_node: |
| 9799 | hpsa_free_sas_node(hpsa_sas_node); |
| 9800 | |
| 9801 | return rc; |
| 9802 | } |
| 9803 | |
| 9804 | static void hpsa_delete_sas_host(struct ctlr_info *h) |
| 9805 | { |
| 9806 | hpsa_free_sas_node(h->sas_host); |
| 9807 | } |
| 9808 | |
| 9809 | static int hpsa_add_sas_device(struct hpsa_sas_node *hpsa_sas_node, |
| 9810 | struct hpsa_scsi_dev_t *device) |
| 9811 | { |
| 9812 | int rc; |
| 9813 | struct hpsa_sas_port *hpsa_sas_port; |
| 9814 | struct sas_rphy *rphy; |
| 9815 | |
| 9816 | hpsa_sas_port = hpsa_alloc_sas_port(hpsa_sas_node, device->sas_address); |
| 9817 | if (!hpsa_sas_port) |
| 9818 | return -ENOMEM; |
| 9819 | |
| 9820 | rphy = sas_end_device_alloc(hpsa_sas_port->port); |
| 9821 | if (!rphy) { |
| 9822 | rc = -ENODEV; |
| 9823 | goto free_sas_port; |
| 9824 | } |
| 9825 | |
| 9826 | hpsa_sas_port->rphy = rphy; |
| 9827 | device->sas_port = hpsa_sas_port; |
| 9828 | |
| 9829 | rc = hpsa_sas_port_add_rphy(hpsa_sas_port, rphy); |
| 9830 | if (rc) |
| 9831 | goto free_sas_port; |
| 9832 | |
| 9833 | return 0; |
| 9834 | |
| 9835 | free_sas_port: |
| 9836 | hpsa_free_sas_port(hpsa_sas_port); |
| 9837 | device->sas_port = NULL; |
| 9838 | |
| 9839 | return rc; |
| 9840 | } |
| 9841 | |
| 9842 | static void hpsa_remove_sas_device(struct hpsa_scsi_dev_t *device) |
| 9843 | { |
| 9844 | if (device->sas_port) { |
| 9845 | hpsa_free_sas_port(device->sas_port); |
| 9846 | device->sas_port = NULL; |
| 9847 | } |
| 9848 | } |
| 9849 | |
| 9850 | static int |
| 9851 | hpsa_sas_get_linkerrors(struct sas_phy *phy) |
| 9852 | { |
| 9853 | return 0; |
| 9854 | } |
| 9855 | |
| 9856 | static int |
| 9857 | hpsa_sas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) |
| 9858 | { |
Dan Carpenter | aa10569 | 2016-04-14 12:37:44 +0300 | [diff] [blame] | 9859 | *identifier = 0; |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 9860 | return 0; |
| 9861 | } |
| 9862 | |
| 9863 | static int |
| 9864 | hpsa_sas_get_bay_identifier(struct sas_rphy *rphy) |
| 9865 | { |
| 9866 | return -ENXIO; |
| 9867 | } |
| 9868 | |
| 9869 | static int |
| 9870 | hpsa_sas_phy_reset(struct sas_phy *phy, int hard_reset) |
| 9871 | { |
| 9872 | return 0; |
| 9873 | } |
| 9874 | |
| 9875 | static int |
| 9876 | hpsa_sas_phy_enable(struct sas_phy *phy, int enable) |
| 9877 | { |
| 9878 | return 0; |
| 9879 | } |
| 9880 | |
| 9881 | static int |
| 9882 | hpsa_sas_phy_setup(struct sas_phy *phy) |
| 9883 | { |
| 9884 | return 0; |
| 9885 | } |
| 9886 | |
| 9887 | static void |
| 9888 | hpsa_sas_phy_release(struct sas_phy *phy) |
| 9889 | { |
| 9890 | } |
| 9891 | |
| 9892 | static int |
| 9893 | hpsa_sas_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates) |
| 9894 | { |
| 9895 | return -EINVAL; |
| 9896 | } |
| 9897 | |
| 9898 | /* SMP = Serial Management Protocol */ |
| 9899 | static int |
| 9900 | hpsa_sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, |
| 9901 | struct request *req) |
| 9902 | { |
| 9903 | return -EINVAL; |
| 9904 | } |
| 9905 | |
| 9906 | static struct sas_function_template hpsa_sas_transport_functions = { |
| 9907 | .get_linkerrors = hpsa_sas_get_linkerrors, |
| 9908 | .get_enclosure_identifier = hpsa_sas_get_enclosure_identifier, |
| 9909 | .get_bay_identifier = hpsa_sas_get_bay_identifier, |
| 9910 | .phy_reset = hpsa_sas_phy_reset, |
| 9911 | .phy_enable = hpsa_sas_phy_enable, |
| 9912 | .phy_setup = hpsa_sas_phy_setup, |
| 9913 | .phy_release = hpsa_sas_phy_release, |
| 9914 | .set_phy_speed = hpsa_sas_phy_speed, |
| 9915 | .smp_handler = hpsa_sas_smp_handler, |
| 9916 | }; |
| 9917 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9918 | /* |
| 9919 | * This is it. Register the PCI driver information for the cards we control |
| 9920 | * the OS will call our registered routines when it finds one of our cards. |
| 9921 | */ |
| 9922 | static int __init hpsa_init(void) |
| 9923 | { |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 9924 | int rc; |
| 9925 | |
| 9926 | hpsa_sas_transport_template = |
| 9927 | sas_attach_transport(&hpsa_sas_transport_functions); |
| 9928 | if (!hpsa_sas_transport_template) |
| 9929 | return -ENODEV; |
| 9930 | |
| 9931 | rc = pci_register_driver(&hpsa_pci_driver); |
| 9932 | |
| 9933 | if (rc) |
| 9934 | sas_release_transport(hpsa_sas_transport_template); |
| 9935 | |
| 9936 | return rc; |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9937 | } |
| 9938 | |
| 9939 | static void __exit hpsa_cleanup(void) |
| 9940 | { |
| 9941 | pci_unregister_driver(&hpsa_pci_driver); |
Kevin Barnett | d04e62b | 2015-11-04 15:52:34 -0600 | [diff] [blame] | 9942 | sas_release_transport(hpsa_sas_transport_template); |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 9943 | } |
| 9944 | |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9945 | static void __attribute__((unused)) verify_offsets(void) |
| 9946 | { |
| 9947 | #define VERIFY_OFFSET(member, offset) \ |
Scott Teel | dd0e19f | 2014-02-18 13:57:31 -0600 | [diff] [blame] | 9948 | BUILD_BUG_ON(offsetof(struct raid_map_data, member) != offset) |
| 9949 | |
| 9950 | VERIFY_OFFSET(structure_size, 0); |
| 9951 | VERIFY_OFFSET(volume_blk_size, 4); |
| 9952 | VERIFY_OFFSET(volume_blk_cnt, 8); |
| 9953 | VERIFY_OFFSET(phys_blk_shift, 16); |
| 9954 | VERIFY_OFFSET(parity_rotation_shift, 17); |
| 9955 | VERIFY_OFFSET(strip_size, 18); |
| 9956 | VERIFY_OFFSET(disk_starting_blk, 20); |
| 9957 | VERIFY_OFFSET(disk_blk_cnt, 28); |
| 9958 | VERIFY_OFFSET(data_disks_per_row, 36); |
| 9959 | VERIFY_OFFSET(metadata_disks_per_row, 38); |
| 9960 | VERIFY_OFFSET(row_cnt, 40); |
| 9961 | VERIFY_OFFSET(layout_map_count, 42); |
| 9962 | VERIFY_OFFSET(flags, 44); |
| 9963 | VERIFY_OFFSET(dekindex, 46); |
| 9964 | /* VERIFY_OFFSET(reserved, 48 */ |
| 9965 | VERIFY_OFFSET(data, 64); |
| 9966 | |
| 9967 | #undef VERIFY_OFFSET |
| 9968 | |
| 9969 | #define VERIFY_OFFSET(member, offset) \ |
Mike Miller | b66cc25 | 2014-02-18 13:56:04 -0600 | [diff] [blame] | 9970 | BUILD_BUG_ON(offsetof(struct io_accel2_cmd, member) != offset) |
| 9971 | |
| 9972 | VERIFY_OFFSET(IU_type, 0); |
| 9973 | VERIFY_OFFSET(direction, 1); |
| 9974 | VERIFY_OFFSET(reply_queue, 2); |
| 9975 | /* VERIFY_OFFSET(reserved1, 3); */ |
| 9976 | VERIFY_OFFSET(scsi_nexus, 4); |
| 9977 | VERIFY_OFFSET(Tag, 8); |
| 9978 | VERIFY_OFFSET(cdb, 16); |
| 9979 | VERIFY_OFFSET(cciss_lun, 32); |
| 9980 | VERIFY_OFFSET(data_len, 40); |
| 9981 | VERIFY_OFFSET(cmd_priority_task_attr, 44); |
| 9982 | VERIFY_OFFSET(sg_count, 45); |
| 9983 | /* VERIFY_OFFSET(reserved3 */ |
| 9984 | VERIFY_OFFSET(err_ptr, 48); |
| 9985 | VERIFY_OFFSET(err_len, 56); |
| 9986 | /* VERIFY_OFFSET(reserved4 */ |
| 9987 | VERIFY_OFFSET(sg, 64); |
| 9988 | |
| 9989 | #undef VERIFY_OFFSET |
| 9990 | |
| 9991 | #define VERIFY_OFFSET(member, offset) \ |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 9992 | BUILD_BUG_ON(offsetof(struct io_accel1_cmd, member) != offset) |
| 9993 | |
| 9994 | VERIFY_OFFSET(dev_handle, 0x00); |
| 9995 | VERIFY_OFFSET(reserved1, 0x02); |
| 9996 | VERIFY_OFFSET(function, 0x03); |
| 9997 | VERIFY_OFFSET(reserved2, 0x04); |
| 9998 | VERIFY_OFFSET(err_info, 0x0C); |
| 9999 | VERIFY_OFFSET(reserved3, 0x10); |
| 10000 | VERIFY_OFFSET(err_info_len, 0x12); |
| 10001 | VERIFY_OFFSET(reserved4, 0x13); |
| 10002 | VERIFY_OFFSET(sgl_offset, 0x14); |
| 10003 | VERIFY_OFFSET(reserved5, 0x15); |
| 10004 | VERIFY_OFFSET(transfer_len, 0x1C); |
| 10005 | VERIFY_OFFSET(reserved6, 0x20); |
| 10006 | VERIFY_OFFSET(io_flags, 0x24); |
| 10007 | VERIFY_OFFSET(reserved7, 0x26); |
| 10008 | VERIFY_OFFSET(LUN, 0x34); |
| 10009 | VERIFY_OFFSET(control, 0x3C); |
| 10010 | VERIFY_OFFSET(CDB, 0x40); |
| 10011 | VERIFY_OFFSET(reserved8, 0x50); |
| 10012 | VERIFY_OFFSET(host_context_flags, 0x60); |
| 10013 | VERIFY_OFFSET(timeout_sec, 0x62); |
| 10014 | VERIFY_OFFSET(ReplyQueue, 0x64); |
| 10015 | VERIFY_OFFSET(reserved9, 0x65); |
Stephen M. Cameron | 50a0dec | 2014-11-14 17:26:59 -0600 | [diff] [blame] | 10016 | VERIFY_OFFSET(tag, 0x68); |
Matt Gates | e1f7de0 | 2014-02-18 13:55:17 -0600 | [diff] [blame] | 10017 | VERIFY_OFFSET(host_addr, 0x70); |
| 10018 | VERIFY_OFFSET(CISS_LUN, 0x78); |
| 10019 | VERIFY_OFFSET(SG, 0x78 + 8); |
| 10020 | #undef VERIFY_OFFSET |
| 10021 | } |
| 10022 | |
Stephen M. Cameron | edd1636 | 2009-12-08 14:09:11 -0800 | [diff] [blame] | 10023 | module_init(hpsa_init); |
| 10024 | module_exit(hpsa_cleanup); |