Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 1 | /* |
Chauhan, Vijay | 5f7a643 | 2011-09-02 13:26:32 +0530 | [diff] [blame] | 2 | * LSI/Engenio/NetApp E-Series RDAC SCSI Device Handler |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 Mike Christie. All rights reserved. |
| 5 | * Copyright (C) Chandra Seetharaman, IBM Corp. 2007 |
| 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; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | * |
| 21 | */ |
| 22 | #include <scsi/scsi.h> |
| 23 | #include <scsi/scsi_eh.h> |
| 24 | #include <scsi/scsi_dh.h> |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 25 | #include <linux/workqueue.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 28 | |
| 29 | #define RDAC_NAME "rdac" |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 30 | #define RDAC_RETRY_COUNT 5 |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * LSI mode page stuff |
| 34 | * |
| 35 | * These struct definitions and the forming of the |
| 36 | * mode page were taken from the LSI RDAC 2.4 GPL'd |
| 37 | * driver, and then converted to Linux conventions. |
| 38 | */ |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 39 | #define RDAC_QUIESCENCE_TIME 20 |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Page Codes |
| 42 | */ |
| 43 | #define RDAC_PAGE_CODE_REDUNDANT_CONTROLLER 0x2c |
| 44 | |
| 45 | /* |
| 46 | * Controller modes definitions |
| 47 | */ |
| 48 | #define RDAC_MODE_TRANSFER_SPECIFIED_LUNS 0x02 |
| 49 | |
| 50 | /* |
| 51 | * RDAC Options field |
| 52 | */ |
| 53 | #define RDAC_FORCED_QUIESENCE 0x02 |
| 54 | |
| 55 | #define RDAC_TIMEOUT (60 * HZ) |
| 56 | #define RDAC_RETRIES 3 |
| 57 | |
| 58 | struct rdac_mode_6_hdr { |
| 59 | u8 data_len; |
| 60 | u8 medium_type; |
| 61 | u8 device_params; |
| 62 | u8 block_desc_len; |
| 63 | }; |
| 64 | |
| 65 | struct rdac_mode_10_hdr { |
| 66 | u16 data_len; |
| 67 | u8 medium_type; |
| 68 | u8 device_params; |
| 69 | u16 reserved; |
| 70 | u16 block_desc_len; |
| 71 | }; |
| 72 | |
| 73 | struct rdac_mode_common { |
| 74 | u8 controller_serial[16]; |
| 75 | u8 alt_controller_serial[16]; |
| 76 | u8 rdac_mode[2]; |
| 77 | u8 alt_rdac_mode[2]; |
| 78 | u8 quiescence_timeout; |
| 79 | u8 rdac_options; |
| 80 | }; |
| 81 | |
| 82 | struct rdac_pg_legacy { |
| 83 | struct rdac_mode_6_hdr hdr; |
| 84 | u8 page_code; |
| 85 | u8 page_len; |
| 86 | struct rdac_mode_common common; |
| 87 | #define MODE6_MAX_LUN 32 |
| 88 | u8 lun_table[MODE6_MAX_LUN]; |
| 89 | u8 reserved2[32]; |
| 90 | u8 reserved3; |
| 91 | u8 reserved4; |
| 92 | }; |
| 93 | |
| 94 | struct rdac_pg_expanded { |
| 95 | struct rdac_mode_10_hdr hdr; |
| 96 | u8 page_code; |
| 97 | u8 subpage_code; |
| 98 | u8 page_len[2]; |
| 99 | struct rdac_mode_common common; |
| 100 | u8 lun_table[256]; |
| 101 | u8 reserved3; |
| 102 | u8 reserved4; |
| 103 | }; |
| 104 | |
| 105 | struct c9_inquiry { |
| 106 | u8 peripheral_info; |
| 107 | u8 page_code; /* 0xC9 */ |
| 108 | u8 reserved1; |
| 109 | u8 page_len; |
| 110 | u8 page_id[4]; /* "vace" */ |
| 111 | u8 avte_cvp; |
| 112 | u8 path_prio; |
| 113 | u8 reserved2[38]; |
| 114 | }; |
| 115 | |
| 116 | #define SUBSYS_ID_LEN 16 |
| 117 | #define SLOT_ID_LEN 2 |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame] | 118 | #define ARRAY_LABEL_LEN 31 |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 119 | |
| 120 | struct c4_inquiry { |
| 121 | u8 peripheral_info; |
| 122 | u8 page_code; /* 0xC4 */ |
| 123 | u8 reserved1; |
| 124 | u8 page_len; |
| 125 | u8 page_id[4]; /* "subs" */ |
| 126 | u8 subsys_id[SUBSYS_ID_LEN]; |
| 127 | u8 revision[4]; |
| 128 | u8 slot_id[SLOT_ID_LEN]; |
| 129 | u8 reserved[2]; |
| 130 | }; |
| 131 | |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 132 | #define UNIQUE_ID_LEN 16 |
| 133 | struct c8_inquiry { |
| 134 | u8 peripheral_info; |
| 135 | u8 page_code; /* 0xC8 */ |
| 136 | u8 reserved1; |
| 137 | u8 page_len; |
| 138 | u8 page_id[4]; /* "edid" */ |
| 139 | u8 reserved2[3]; |
| 140 | u8 vol_uniq_id_len; |
| 141 | u8 vol_uniq_id[16]; |
| 142 | u8 vol_user_label_len; |
| 143 | u8 vol_user_label[60]; |
| 144 | u8 array_uniq_id_len; |
| 145 | u8 array_unique_id[UNIQUE_ID_LEN]; |
| 146 | u8 array_user_label_len; |
| 147 | u8 array_user_label[60]; |
| 148 | u8 lun[8]; |
| 149 | }; |
| 150 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 151 | struct rdac_controller { |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 152 | u8 array_id[UNIQUE_ID_LEN]; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 153 | int use_ms10; |
| 154 | struct kref kref; |
| 155 | struct list_head node; /* list of all controllers */ |
| 156 | union { |
| 157 | struct rdac_pg_legacy legacy; |
| 158 | struct rdac_pg_expanded expanded; |
| 159 | } mode_select; |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame] | 160 | u8 index; |
| 161 | u8 array_name[ARRAY_LABEL_LEN]; |
Chandra Seetharaman | d685759 | 2011-07-27 11:22:56 -0700 | [diff] [blame] | 162 | struct Scsi_Host *host; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 163 | spinlock_t ms_lock; |
| 164 | int ms_queued; |
| 165 | struct work_struct ms_work; |
| 166 | struct scsi_device *ms_sdev; |
| 167 | struct list_head ms_head; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 168 | struct list_head dh_list; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 169 | }; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 170 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 171 | struct c2_inquiry { |
| 172 | u8 peripheral_info; |
| 173 | u8 page_code; /* 0xC2 */ |
| 174 | u8 reserved1; |
| 175 | u8 page_len; |
| 176 | u8 page_id[4]; /* "swr4" */ |
| 177 | u8 sw_version[3]; |
| 178 | u8 sw_date[3]; |
| 179 | u8 features_enabled; |
| 180 | u8 max_lun_supported; |
| 181 | u8 partitions[239]; /* Total allocation length should be 0xFF */ |
| 182 | }; |
| 183 | |
| 184 | struct rdac_dh_data { |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 185 | struct list_head node; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 186 | struct rdac_controller *ctlr; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 187 | struct scsi_device *sdev; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 188 | #define UNINITIALIZED_LUN (1 << 8) |
| 189 | unsigned lun; |
Moger, Babu | eebe9b9 | 2011-04-08 11:37:40 -0600 | [diff] [blame] | 190 | |
| 191 | #define RDAC_MODE 0 |
| 192 | #define RDAC_MODE_AVT 1 |
| 193 | #define RDAC_MODE_IOSHIP 2 |
| 194 | unsigned char mode; |
| 195 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 196 | #define RDAC_STATE_ACTIVE 0 |
| 197 | #define RDAC_STATE_PASSIVE 1 |
| 198 | unsigned char state; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 199 | |
| 200 | #define RDAC_LUN_UNOWNED 0 |
| 201 | #define RDAC_LUN_OWNED 1 |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 202 | char lun_state; |
Moger, Babu | eebe9b9 | 2011-04-08 11:37:40 -0600 | [diff] [blame] | 203 | |
| 204 | #define RDAC_PREFERRED 0 |
| 205 | #define RDAC_NON_PREFERRED 1 |
| 206 | char preferred; |
| 207 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 208 | union { |
| 209 | struct c2_inquiry c2; |
| 210 | struct c4_inquiry c4; |
| 211 | struct c8_inquiry c8; |
| 212 | struct c9_inquiry c9; |
| 213 | } inq; |
| 214 | }; |
| 215 | |
Moger, Babu | eebe9b9 | 2011-04-08 11:37:40 -0600 | [diff] [blame] | 216 | static const char *mode[] = { |
| 217 | "RDAC", |
| 218 | "AVT", |
| 219 | "IOSHIP", |
| 220 | }; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 221 | static const char *lun_state[] = |
| 222 | { |
| 223 | "unowned", |
| 224 | "owned", |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 227 | struct rdac_queue_data { |
| 228 | struct list_head entry; |
| 229 | struct rdac_dh_data *h; |
| 230 | activate_complete callback_fn; |
| 231 | void *callback_data; |
| 232 | }; |
| 233 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 234 | static LIST_HEAD(ctlr_list); |
| 235 | static DEFINE_SPINLOCK(list_lock); |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 236 | static struct workqueue_struct *kmpath_rdacd; |
| 237 | static void send_mode_select(struct work_struct *work); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 238 | |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 239 | /* |
| 240 | * module parameter to enable rdac debug logging. |
| 241 | * 2 bits for each type of logging, only two types defined for now |
| 242 | * Can be enhanced if required at later point |
| 243 | */ |
| 244 | static int rdac_logging = 1; |
| 245 | module_param(rdac_logging, int, S_IRUGO|S_IWUSR); |
| 246 | MODULE_PARM_DESC(rdac_logging, "A bit mask of rdac logging levels, " |
| 247 | "Default is 1 - failover logging enabled, " |
| 248 | "set it to 0xF to enable all the logs"); |
| 249 | |
| 250 | #define RDAC_LOG_FAILOVER 0 |
| 251 | #define RDAC_LOG_SENSE 2 |
| 252 | |
| 253 | #define RDAC_LOG_BITS 2 |
| 254 | |
| 255 | #define RDAC_LOG_LEVEL(SHIFT) \ |
| 256 | ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1)) |
| 257 | |
| 258 | #define RDAC_LOG(SHIFT, sdev, f, arg...) \ |
| 259 | do { \ |
| 260 | if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \ |
| 261 | sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \ |
| 262 | } while (0); |
| 263 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 264 | static unsigned int rdac_failover_get(struct rdac_controller *ctlr, |
| 265 | struct list_head *list, |
| 266 | unsigned char *cdb) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 267 | { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 268 | struct scsi_device *sdev = ctlr->ms_sdev; |
| 269 | struct rdac_dh_data *h = sdev->handler_data; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 270 | struct rdac_mode_common *common; |
| 271 | unsigned data_size; |
Moger, Babu | 04b6e15 | 2011-02-11 15:14:08 -0700 | [diff] [blame] | 272 | struct rdac_queue_data *qdata; |
| 273 | u8 *lun_table; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 274 | |
| 275 | if (h->ctlr->use_ms10) { |
| 276 | struct rdac_pg_expanded *rdac_pg; |
| 277 | |
| 278 | data_size = sizeof(struct rdac_pg_expanded); |
| 279 | rdac_pg = &h->ctlr->mode_select.expanded; |
| 280 | memset(rdac_pg, 0, data_size); |
| 281 | common = &rdac_pg->common; |
| 282 | rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40; |
| 283 | rdac_pg->subpage_code = 0x1; |
| 284 | rdac_pg->page_len[0] = 0x01; |
| 285 | rdac_pg->page_len[1] = 0x28; |
Moger, Babu | 04b6e15 | 2011-02-11 15:14:08 -0700 | [diff] [blame] | 286 | lun_table = rdac_pg->lun_table; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 287 | } else { |
| 288 | struct rdac_pg_legacy *rdac_pg; |
| 289 | |
| 290 | data_size = sizeof(struct rdac_pg_legacy); |
| 291 | rdac_pg = &h->ctlr->mode_select.legacy; |
| 292 | memset(rdac_pg, 0, data_size); |
| 293 | common = &rdac_pg->common; |
| 294 | rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER; |
| 295 | rdac_pg->page_len = 0x68; |
Moger, Babu | 04b6e15 | 2011-02-11 15:14:08 -0700 | [diff] [blame] | 296 | lun_table = rdac_pg->lun_table; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 297 | } |
| 298 | common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS; |
| 299 | common->quiescence_timeout = RDAC_QUIESCENCE_TIME; |
| 300 | common->rdac_options = RDAC_FORCED_QUIESENCE; |
| 301 | |
Moger, Babu | 04b6e15 | 2011-02-11 15:14:08 -0700 | [diff] [blame] | 302 | list_for_each_entry(qdata, list, entry) { |
| 303 | lun_table[qdata->h->lun] = 0x81; |
| 304 | } |
| 305 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 306 | /* Prepare the command. */ |
| 307 | if (h->ctlr->use_ms10) { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 308 | cdb[0] = MODE_SELECT_10; |
| 309 | cdb[7] = data_size >> 8; |
| 310 | cdb[8] = data_size & 0xff; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 311 | } else { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 312 | cdb[0] = MODE_SELECT; |
| 313 | cdb[4] = data_size; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 314 | } |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 315 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 316 | return data_size; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static void release_controller(struct kref *kref) |
| 320 | { |
| 321 | struct rdac_controller *ctlr; |
| 322 | ctlr = container_of(kref, struct rdac_controller, kref); |
| 323 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 324 | list_del(&ctlr->node); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 325 | kfree(ctlr); |
| 326 | } |
| 327 | |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 328 | static struct rdac_controller *get_controller(int index, char *array_name, |
Chandra Seetharaman | d685759 | 2011-07-27 11:22:56 -0700 | [diff] [blame] | 329 | u8 *array_id, struct scsi_device *sdev) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 330 | { |
| 331 | struct rdac_controller *ctlr, *tmp; |
| 332 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 333 | list_for_each_entry(tmp, &ctlr_list, node) { |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 334 | if ((memcmp(tmp->array_id, array_id, UNIQUE_ID_LEN) == 0) && |
Chandra Seetharaman | d685759 | 2011-07-27 11:22:56 -0700 | [diff] [blame] | 335 | (tmp->index == index) && |
| 336 | (tmp->host == sdev->host)) { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 337 | kref_get(&tmp->kref); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 338 | return tmp; |
| 339 | } |
| 340 | } |
| 341 | ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC); |
| 342 | if (!ctlr) |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 343 | return NULL; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 344 | |
| 345 | /* initialize fields of controller */ |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 346 | memcpy(ctlr->array_id, array_id, UNIQUE_ID_LEN); |
| 347 | ctlr->index = index; |
Chandra Seetharaman | d685759 | 2011-07-27 11:22:56 -0700 | [diff] [blame] | 348 | ctlr->host = sdev->host; |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame] | 349 | memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN); |
| 350 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 351 | kref_init(&ctlr->kref); |
| 352 | ctlr->use_ms10 = -1; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 353 | ctlr->ms_queued = 0; |
| 354 | ctlr->ms_sdev = NULL; |
| 355 | spin_lock_init(&ctlr->ms_lock); |
| 356 | INIT_WORK(&ctlr->ms_work, send_mode_select); |
| 357 | INIT_LIST_HEAD(&ctlr->ms_head); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 358 | list_add(&ctlr->node, &ctlr_list); |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 359 | INIT_LIST_HEAD(&ctlr->dh_list); |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 360 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 361 | return ctlr; |
| 362 | } |
| 363 | |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame] | 364 | static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h, |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 365 | char *array_name, u8 *array_id) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 366 | { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 367 | int err = SCSI_DH_IO, i; |
| 368 | struct c8_inquiry *inqp = &h->inq.c8; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 369 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 370 | if (!scsi_get_vpd_page(sdev, 0xC8, (unsigned char *)inqp, |
| 371 | sizeof(struct c8_inquiry))) { |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 372 | if (inqp->page_code != 0xc8) |
| 373 | return SCSI_DH_NOSYS; |
| 374 | if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' || |
| 375 | inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd') |
| 376 | return SCSI_DH_NOSYS; |
Chandra Seetharaman | 8479fca | 2008-08-12 17:26:58 -0700 | [diff] [blame] | 377 | h->lun = inqp->lun[7]; /* Uses only the last byte */ |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame] | 378 | |
| 379 | for(i=0; i<ARRAY_LABEL_LEN-1; ++i) |
| 380 | *(array_name+i) = inqp->array_user_label[(2*i)+1]; |
| 381 | |
| 382 | *(array_name+ARRAY_LABEL_LEN-1) = '\0'; |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 383 | memset(array_id, 0, UNIQUE_ID_LEN); |
| 384 | memcpy(array_id, inqp->array_unique_id, inqp->array_uniq_id_len); |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 385 | err = SCSI_DH_OK; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 386 | } |
| 387 | return err; |
| 388 | } |
| 389 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 390 | static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 391 | { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 392 | int err = SCSI_DH_IO, access_state; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 393 | struct rdac_dh_data *tmp; |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 394 | struct c9_inquiry *inqp = &h->inq.c9; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 395 | |
Chandra Seetharaman | 9eece96 | 2008-11-05 20:05:21 -0800 | [diff] [blame] | 396 | h->state = RDAC_STATE_ACTIVE; |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 397 | if (!scsi_get_vpd_page(sdev, 0xC9, (unsigned char *)inqp, |
| 398 | sizeof(struct c9_inquiry))) { |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 399 | /* detect the operating mode */ |
| 400 | if ((inqp->avte_cvp >> 5) & 0x1) |
| 401 | h->mode = RDAC_MODE_IOSHIP; /* LUN in IOSHIP mode */ |
| 402 | else if (inqp->avte_cvp >> 7) |
| 403 | h->mode = RDAC_MODE_AVT; /* LUN in AVT mode */ |
| 404 | else |
| 405 | h->mode = RDAC_MODE; /* LUN in RDAC mode */ |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 406 | |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 407 | /* Update ownership */ |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 408 | if (inqp->avte_cvp & 0x1) { |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 409 | h->lun_state = RDAC_LUN_OWNED; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 410 | access_state = SCSI_ACCESS_STATE_OPTIMAL; |
| 411 | } else { |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 412 | h->lun_state = RDAC_LUN_UNOWNED; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 413 | if (h->mode == RDAC_MODE) { |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 414 | h->state = RDAC_STATE_PASSIVE; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 415 | access_state = SCSI_ACCESS_STATE_STANDBY; |
| 416 | } else |
| 417 | access_state = SCSI_ACCESS_STATE_ACTIVE; |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /* Update path prio*/ |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 421 | if (inqp->path_prio & 0x1) { |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 422 | h->preferred = RDAC_PREFERRED; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 423 | access_state |= SCSI_ACCESS_STATE_PREFERRED; |
| 424 | } else |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 425 | h->preferred = RDAC_NON_PREFERRED; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 426 | rcu_read_lock(); |
| 427 | list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) { |
| 428 | /* h->sdev should always be valid */ |
| 429 | BUG_ON(!tmp->sdev); |
| 430 | tmp->sdev->access_state = access_state; |
| 431 | } |
| 432 | rcu_read_unlock(); |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 433 | err = SCSI_DH_OK; |
Moger, Babu | 1c3afc4 | 2011-04-08 11:38:33 -0600 | [diff] [blame] | 434 | } |
Chandra Seetharaman | 5a36756 | 2008-08-21 23:12:40 -0700 | [diff] [blame] | 435 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 436 | return err; |
| 437 | } |
| 438 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 439 | static int initialize_controller(struct scsi_device *sdev, |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 440 | struct rdac_dh_data *h, char *array_name, u8 *array_id) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 441 | { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 442 | int err = SCSI_DH_IO, index; |
| 443 | struct c4_inquiry *inqp = &h->inq.c4; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 444 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 445 | if (!scsi_get_vpd_page(sdev, 0xC4, (unsigned char *)inqp, |
| 446 | sizeof(struct c4_inquiry))) { |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 447 | /* get the controller index */ |
| 448 | if (inqp->slot_id[1] == 0x31) |
| 449 | index = 0; |
| 450 | else |
| 451 | index = 1; |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 452 | |
| 453 | spin_lock(&list_lock); |
Chandra Seetharaman | d685759 | 2011-07-27 11:22:56 -0700 | [diff] [blame] | 454 | h->ctlr = get_controller(index, array_name, array_id, sdev); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 455 | if (!h->ctlr) |
| 456 | err = SCSI_DH_RES_TEMP_UNAVAIL; |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 457 | else { |
| 458 | list_add_rcu(&h->node, &h->ctlr->dh_list); |
| 459 | h->sdev = sdev; |
| 460 | } |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 461 | spin_unlock(&list_lock); |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 462 | err = SCSI_DH_OK; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 463 | } |
| 464 | return err; |
| 465 | } |
| 466 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 467 | static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 468 | { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 469 | int err = SCSI_DH_IO; |
| 470 | struct c2_inquiry *inqp = &h->inq.c2; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 471 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 472 | if (!scsi_get_vpd_page(sdev, 0xC2, (unsigned char *)inqp, |
| 473 | sizeof(struct c2_inquiry))) { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 474 | /* |
| 475 | * If more than MODE6_MAX_LUN luns are supported, use |
| 476 | * mode select 10 |
| 477 | */ |
| 478 | if (inqp->max_lun_supported >= MODE6_MAX_LUN) |
| 479 | h->ctlr->use_ms10 = 1; |
| 480 | else |
| 481 | h->ctlr->use_ms10 = 0; |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 482 | err = SCSI_DH_OK; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 483 | } |
| 484 | return err; |
| 485 | } |
| 486 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 487 | static int mode_select_handle_sense(struct scsi_device *sdev, |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 488 | struct scsi_sense_hdr *sense_hdr) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 489 | { |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 490 | int err = SCSI_DH_IO; |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 491 | struct rdac_dh_data *h = sdev->handler_data; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 492 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 493 | if (!scsi_sense_valid(sense_hdr)) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 494 | goto done; |
| 495 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 496 | switch (sense_hdr->sense_key) { |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 497 | case NO_SENSE: |
| 498 | case ABORTED_COMMAND: |
| 499 | case UNIT_ATTENTION: |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 500 | err = SCSI_DH_RETRY; |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 501 | break; |
| 502 | case NOT_READY: |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 503 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01) |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 504 | /* LUN Not Ready and is in the Process of Becoming |
| 505 | * Ready |
| 506 | */ |
| 507 | err = SCSI_DH_RETRY; |
| 508 | break; |
| 509 | case ILLEGAL_REQUEST: |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 510 | if (sense_hdr->asc == 0x91 && sense_hdr->ascq == 0x36) |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 511 | /* |
| 512 | * Command Lock contention |
| 513 | */ |
Hannes Reinecke | d2d06d4 | 2016-01-22 15:42:41 +0100 | [diff] [blame] | 514 | err = SCSI_DH_IMM_RETRY; |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 515 | break; |
| 516 | default: |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 517 | break; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 520 | RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " |
| 521 | "MODE_SELECT returned with sense %02x/%02x/%02x", |
| 522 | (char *) h->ctlr->array_name, h->ctlr->index, |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 523 | sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq); |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 524 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 525 | done: |
| 526 | return err; |
| 527 | } |
| 528 | |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 529 | static void send_mode_select(struct work_struct *work) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 530 | { |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 531 | struct rdac_controller *ctlr = |
| 532 | container_of(work, struct rdac_controller, ms_work); |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 533 | struct scsi_device *sdev = ctlr->ms_sdev; |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 534 | struct rdac_dh_data *h = sdev->handler_data; |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 535 | int err = SCSI_DH_OK, retry_cnt = RDAC_RETRY_COUNT; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 536 | struct rdac_queue_data *tmp, *qdata; |
| 537 | LIST_HEAD(list); |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 538 | unsigned char cdb[COMMAND_SIZE(MODE_SELECT_10)]; |
| 539 | struct scsi_sense_hdr sshdr; |
| 540 | unsigned int data_size; |
| 541 | u64 req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
| 542 | REQ_FAILFAST_DRIVER; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 543 | |
| 544 | spin_lock(&ctlr->ms_lock); |
| 545 | list_splice_init(&ctlr->ms_head, &list); |
| 546 | ctlr->ms_queued = 0; |
| 547 | ctlr->ms_sdev = NULL; |
| 548 | spin_unlock(&ctlr->ms_lock); |
| 549 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 550 | retry: |
| 551 | data_size = rdac_failover_get(ctlr, &list, cdb); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 552 | |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 553 | RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " |
| 554 | "%s MODE_SELECT command", |
| 555 | (char *) h->ctlr->array_name, h->ctlr->index, |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 556 | (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying"); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 557 | |
Hannes Reinecke | 3278255 | 2016-11-03 14:20:21 +0100 | [diff] [blame] | 558 | if (scsi_execute_req_flags(sdev, cdb, DMA_TO_DEVICE, |
| 559 | &h->ctlr->mode_select, data_size, &sshdr, |
| 560 | RDAC_TIMEOUT * HZ, |
| 561 | RDAC_RETRIES, NULL, req_flags, 0)) { |
| 562 | err = mode_select_handle_sense(sdev, &sshdr); |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 563 | if (err == SCSI_DH_RETRY && retry_cnt--) |
| 564 | goto retry; |
Hannes Reinecke | d2d06d4 | 2016-01-22 15:42:41 +0100 | [diff] [blame] | 565 | if (err == SCSI_DH_IMM_RETRY) |
| 566 | goto retry; |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 567 | } |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 568 | if (err == SCSI_DH_OK) { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 569 | h->state = RDAC_STATE_ACTIVE; |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 570 | RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " |
| 571 | "MODE_SELECT completed", |
| 572 | (char *) h->ctlr->array_name, h->ctlr->index); |
| 573 | } |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 574 | |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 575 | list_for_each_entry_safe(qdata, tmp, &list, entry) { |
| 576 | list_del(&qdata->entry); |
| 577 | if (err == SCSI_DH_OK) |
| 578 | qdata->h->state = RDAC_STATE_ACTIVE; |
| 579 | if (qdata->callback_fn) |
| 580 | qdata->callback_fn(qdata->callback_data, err); |
| 581 | kfree(qdata); |
| 582 | } |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | static int queue_mode_select(struct scsi_device *sdev, |
| 587 | activate_complete fn, void *data) |
| 588 | { |
| 589 | struct rdac_queue_data *qdata; |
| 590 | struct rdac_controller *ctlr; |
| 591 | |
| 592 | qdata = kzalloc(sizeof(*qdata), GFP_KERNEL); |
| 593 | if (!qdata) |
| 594 | return SCSI_DH_RETRY; |
| 595 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 596 | qdata->h = sdev->handler_data; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 597 | qdata->callback_fn = fn; |
| 598 | qdata->callback_data = data; |
| 599 | |
| 600 | ctlr = qdata->h->ctlr; |
| 601 | spin_lock(&ctlr->ms_lock); |
| 602 | list_add_tail(&qdata->entry, &ctlr->ms_head); |
| 603 | if (!ctlr->ms_queued) { |
| 604 | ctlr->ms_queued = 1; |
| 605 | ctlr->ms_sdev = sdev; |
| 606 | queue_work(kmpath_rdacd, &ctlr->ms_work); |
| 607 | } |
| 608 | spin_unlock(&ctlr->ms_lock); |
| 609 | return SCSI_DH_OK; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Chandra Seetharaman | 3ae31f6 | 2009-10-21 09:22:46 -0700 | [diff] [blame] | 612 | static int rdac_activate(struct scsi_device *sdev, |
| 613 | activate_complete fn, void *data) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 614 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 615 | struct rdac_dh_data *h = sdev->handler_data; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 616 | int err = SCSI_DH_OK; |
Moger, Babu | 3425fbf | 2011-04-08 11:39:30 -0600 | [diff] [blame] | 617 | int act = 0; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 618 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 619 | err = check_ownership(sdev, h); |
| 620 | if (err != SCSI_DH_OK) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 621 | goto done; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 622 | |
Moger, Babu | 3425fbf | 2011-04-08 11:39:30 -0600 | [diff] [blame] | 623 | switch (h->mode) { |
| 624 | case RDAC_MODE: |
| 625 | if (h->lun_state == RDAC_LUN_UNOWNED) |
| 626 | act = 1; |
| 627 | break; |
| 628 | case RDAC_MODE_IOSHIP: |
| 629 | if ((h->lun_state == RDAC_LUN_UNOWNED) && |
| 630 | (h->preferred == RDAC_PREFERRED)) |
| 631 | act = 1; |
| 632 | break; |
| 633 | default: |
| 634 | break; |
| 635 | } |
| 636 | |
| 637 | if (act) { |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 638 | err = queue_mode_select(sdev, fn, data); |
| 639 | if (err == SCSI_DH_OK) |
| 640 | return 0; |
| 641 | } |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 642 | done: |
Chandra Seetharaman | 3ae31f6 | 2009-10-21 09:22:46 -0700 | [diff] [blame] | 643 | if (fn) |
| 644 | fn(data, err); |
| 645 | return 0; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static int rdac_prep_fn(struct scsi_device *sdev, struct request *req) |
| 649 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 650 | struct rdac_dh_data *h = sdev->handler_data; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 651 | int ret = BLKPREP_OK; |
| 652 | |
| 653 | if (h->state != RDAC_STATE_ACTIVE) { |
| 654 | ret = BLKPREP_KILL; |
Christoph Hellwig | e806402 | 2016-10-20 15:12:13 +0200 | [diff] [blame] | 655 | req->rq_flags |= RQF_QUIET; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 656 | } |
| 657 | return ret; |
| 658 | |
| 659 | } |
| 660 | |
| 661 | static int rdac_check_sense(struct scsi_device *sdev, |
| 662 | struct scsi_sense_hdr *sense_hdr) |
| 663 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 664 | struct rdac_dh_data *h = sdev->handler_data; |
Moger, Babu | dd784ed | 2009-09-03 21:42:28 -0600 | [diff] [blame] | 665 | |
| 666 | RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, " |
| 667 | "I/O returned with sense %02x/%02x/%02x", |
| 668 | (char *) h->ctlr->array_name, h->ctlr->index, |
| 669 | sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq); |
| 670 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 671 | switch (sense_hdr->sense_key) { |
| 672 | case NOT_READY: |
Chauhan, Vijay | 8f03226 | 2009-04-20 18:14:23 +0530 | [diff] [blame] | 673 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01) |
| 674 | /* LUN Not Ready - Logical Unit Not Ready and is in |
| 675 | * the process of becoming ready |
| 676 | * Just retry. |
| 677 | */ |
| 678 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 679 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81) |
| 680 | /* LUN Not Ready - Storage firmware incompatible |
| 681 | * Manual code synchonisation required. |
| 682 | * |
| 683 | * Nothing we can do here. Try to bypass the path. |
| 684 | */ |
| 685 | return SUCCESS; |
| 686 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1) |
| 687 | /* LUN Not Ready - Quiescense in progress |
| 688 | * |
| 689 | * Just retry and wait. |
| 690 | */ |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 691 | return ADD_TO_MLQUEUE; |
Chauhan, Vijay | af50bb9 | 2009-03-17 18:51:40 +0530 | [diff] [blame] | 692 | if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02) |
| 693 | /* LUN Not Ready - Quiescense in progress |
| 694 | * or has been achieved |
| 695 | * Just retry. |
| 696 | */ |
| 697 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 698 | break; |
| 699 | case ILLEGAL_REQUEST: |
| 700 | if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) { |
| 701 | /* Invalid Request - Current Logical Unit Ownership. |
| 702 | * Controller is not the current owner of the LUN, |
| 703 | * Fail the path, so that the other path be used. |
| 704 | */ |
| 705 | h->state = RDAC_STATE_PASSIVE; |
| 706 | return SUCCESS; |
| 707 | } |
| 708 | break; |
| 709 | case UNIT_ATTENTION: |
| 710 | if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) |
| 711 | /* |
| 712 | * Power On, Reset, or Bus Device Reset, just retry. |
| 713 | */ |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 714 | return ADD_TO_MLQUEUE; |
Chauhan, Vijay | ea41e41 | 2009-01-26 21:29:37 +0530 | [diff] [blame] | 715 | if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02) |
| 716 | /* |
| 717 | * Quiescence in progress , just retry. |
| 718 | */ |
| 719 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 720 | break; |
| 721 | } |
| 722 | /* success just means we do not care what scsi-ml does */ |
| 723 | return SCSI_RETURN_NOT_HANDLED; |
| 724 | } |
| 725 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 726 | static int rdac_bus_attach(struct scsi_device *sdev) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 727 | { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 728 | struct rdac_dh_data *h; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 729 | int err; |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame] | 730 | char array_name[ARRAY_LABEL_LEN]; |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 731 | char array_id[UNIQUE_ID_LEN]; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 732 | |
Christoph Hellwig | cd37743 | 2014-09-13 19:59:51 -0700 | [diff] [blame] | 733 | h = kzalloc(sizeof(*h) , GFP_KERNEL); |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 734 | if (!h) |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 735 | return -ENOMEM; |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 736 | h->lun = UNINITIALIZED_LUN; |
| 737 | h->state = RDAC_STATE_ACTIVE; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 738 | |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 739 | err = get_lun_info(sdev, h, array_name, array_id); |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 740 | if (err != SCSI_DH_OK) |
| 741 | goto failed; |
| 742 | |
Chandra Seetharaman | a53becc | 2011-07-20 14:18:56 -0700 | [diff] [blame] | 743 | err = initialize_controller(sdev, h, array_name, array_id); |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 744 | if (err != SCSI_DH_OK) |
| 745 | goto failed; |
| 746 | |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 747 | err = check_ownership(sdev, h); |
| 748 | if (err != SCSI_DH_OK) |
| 749 | goto clean_ctlr; |
| 750 | |
| 751 | err = set_mode_select(sdev, h); |
| 752 | if (err != SCSI_DH_OK) |
| 753 | goto clean_ctlr; |
| 754 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 755 | sdev_printk(KERN_NOTICE, sdev, |
Moger, Babu | eebe9b9 | 2011-04-08 11:37:40 -0600 | [diff] [blame] | 756 | "%s: LUN %d (%s) (%s)\n", |
| 757 | RDAC_NAME, h->lun, mode[(int)h->mode], |
| 758 | lun_state[(int)h->lun_state]); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 759 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 760 | sdev->handler_data = h; |
| 761 | return 0; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 762 | |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 763 | clean_ctlr: |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 764 | spin_lock(&list_lock); |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 765 | kref_put(&h->ctlr->kref, release_controller); |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 766 | spin_unlock(&list_lock); |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 767 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 768 | failed: |
Christoph Hellwig | cd37743 | 2014-09-13 19:59:51 -0700 | [diff] [blame] | 769 | kfree(h); |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 770 | return -EINVAL; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 773 | static void rdac_bus_detach( struct scsi_device *sdev ) |
| 774 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 775 | struct rdac_dh_data *h = sdev->handler_data; |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 776 | |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 777 | if (h->ctlr && h->ctlr->ms_queued) |
| 778 | flush_workqueue(kmpath_rdacd); |
| 779 | |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 780 | spin_lock(&list_lock); |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 781 | if (h->ctlr) { |
| 782 | list_del_rcu(&h->node); |
| 783 | h->sdev = NULL; |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 784 | kref_put(&h->ctlr->kref, release_controller); |
Hannes Reinecke | 1a5dc16 | 2016-03-03 07:54:10 +0100 | [diff] [blame] | 785 | } |
Moger, Babu | 3569e53 | 2012-02-02 15:21:54 +0000 | [diff] [blame] | 786 | spin_unlock(&list_lock); |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 787 | sdev->handler_data = NULL; |
Christoph Hellwig | cd37743 | 2014-09-13 19:59:51 -0700 | [diff] [blame] | 788 | kfree(h); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 791 | static struct scsi_device_handler rdac_dh = { |
| 792 | .name = RDAC_NAME, |
| 793 | .module = THIS_MODULE, |
| 794 | .prep_fn = rdac_prep_fn, |
| 795 | .check_sense = rdac_check_sense, |
| 796 | .attach = rdac_bus_attach, |
| 797 | .detach = rdac_bus_detach, |
| 798 | .activate = rdac_activate, |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 799 | }; |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 800 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 801 | static int __init rdac_init(void) |
| 802 | { |
| 803 | int r; |
| 804 | |
| 805 | r = scsi_register_device_handler(&rdac_dh); |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 806 | if (r != 0) { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 807 | printk(KERN_ERR "Failed to register scsi device handler."); |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 808 | goto done; |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * Create workqueue to handle mode selects for rdac |
| 813 | */ |
| 814 | kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd"); |
| 815 | if (!kmpath_rdacd) { |
| 816 | scsi_unregister_device_handler(&rdac_dh); |
| 817 | printk(KERN_ERR "kmpath_rdacd creation failed.\n"); |
Richard Weinberger | 9fc397f | 2011-11-18 01:44:27 +0100 | [diff] [blame] | 818 | |
| 819 | r = -EINVAL; |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 820 | } |
| 821 | done: |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 822 | return r; |
| 823 | } |
| 824 | |
| 825 | static void __exit rdac_exit(void) |
| 826 | { |
Chandra Seetharaman | 970f3f4 | 2009-10-21 09:22:51 -0700 | [diff] [blame] | 827 | destroy_workqueue(kmpath_rdacd); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 828 | scsi_unregister_device_handler(&rdac_dh); |
| 829 | } |
| 830 | |
| 831 | module_init(rdac_init); |
| 832 | module_exit(rdac_exit); |
| 833 | |
Chauhan, Vijay | 5f7a643 | 2011-09-02 13:26:32 +0530 | [diff] [blame] | 834 | MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver"); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 835 | MODULE_AUTHOR("Mike Christie, Chandra Seetharaman"); |
Moger, Babu | a0b990c | 2011-02-11 16:12:44 -0700 | [diff] [blame] | 836 | MODULE_VERSION("01.00.0000.0000"); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 837 | MODULE_LICENSE("GPL"); |