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