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