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