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 | |
| 204 | static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) |
| 205 | { |
| 206 | struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; |
| 207 | BUG_ON(scsi_dh_data == NULL); |
| 208 | return ((struct rdac_dh_data *) scsi_dh_data->buf); |
| 209 | } |
| 210 | |
| 211 | static struct request *get_rdac_req(struct scsi_device *sdev, |
| 212 | void *buffer, unsigned buflen, int rw) |
| 213 | { |
| 214 | struct request *rq; |
| 215 | struct request_queue *q = sdev->request_queue; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 216 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 217 | rq = blk_get_request(q, rw, GFP_NOIO); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 218 | |
| 219 | if (!rq) { |
| 220 | sdev_printk(KERN_INFO, sdev, |
| 221 | "get_rdac_req: blk_get_request failed.\n"); |
| 222 | return NULL; |
| 223 | } |
| 224 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 225 | if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 226 | blk_put_request(rq); |
| 227 | sdev_printk(KERN_INFO, sdev, |
| 228 | "get_rdac_req: blk_rq_map_kern failed.\n"); |
| 229 | return NULL; |
| 230 | } |
| 231 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 232 | rq->cmd_type = REQ_TYPE_BLOCK_PC; |
Mike Christie | 6000a36 | 2008-08-19 18:45:30 -0500 | [diff] [blame] | 233 | rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
| 234 | REQ_FAILFAST_DRIVER; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 235 | rq->retries = RDAC_RETRIES; |
| 236 | rq->timeout = RDAC_TIMEOUT; |
| 237 | |
| 238 | return rq; |
| 239 | } |
| 240 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 241 | static struct request *rdac_failover_get(struct scsi_device *sdev, |
| 242 | struct rdac_dh_data *h) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 243 | { |
| 244 | struct request *rq; |
| 245 | struct rdac_mode_common *common; |
| 246 | unsigned data_size; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 247 | |
| 248 | if (h->ctlr->use_ms10) { |
| 249 | struct rdac_pg_expanded *rdac_pg; |
| 250 | |
| 251 | data_size = sizeof(struct rdac_pg_expanded); |
| 252 | rdac_pg = &h->ctlr->mode_select.expanded; |
| 253 | memset(rdac_pg, 0, data_size); |
| 254 | common = &rdac_pg->common; |
| 255 | rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40; |
| 256 | rdac_pg->subpage_code = 0x1; |
| 257 | rdac_pg->page_len[0] = 0x01; |
| 258 | rdac_pg->page_len[1] = 0x28; |
| 259 | rdac_pg->lun_table[h->lun] = 0x81; |
| 260 | } else { |
| 261 | struct rdac_pg_legacy *rdac_pg; |
| 262 | |
| 263 | data_size = sizeof(struct rdac_pg_legacy); |
| 264 | rdac_pg = &h->ctlr->mode_select.legacy; |
| 265 | memset(rdac_pg, 0, data_size); |
| 266 | common = &rdac_pg->common; |
| 267 | rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER; |
| 268 | rdac_pg->page_len = 0x68; |
| 269 | rdac_pg->lun_table[h->lun] = 0x81; |
| 270 | } |
| 271 | common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS; |
| 272 | common->quiescence_timeout = RDAC_QUIESCENCE_TIME; |
| 273 | common->rdac_options = RDAC_FORCED_QUIESENCE; |
| 274 | |
| 275 | /* get request for block layer packet command */ |
| 276 | rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE); |
| 277 | if (!rq) |
| 278 | return NULL; |
| 279 | |
| 280 | /* Prepare the command. */ |
| 281 | if (h->ctlr->use_ms10) { |
| 282 | rq->cmd[0] = MODE_SELECT_10; |
| 283 | rq->cmd[7] = data_size >> 8; |
| 284 | rq->cmd[8] = data_size & 0xff; |
| 285 | } else { |
| 286 | rq->cmd[0] = MODE_SELECT; |
| 287 | rq->cmd[4] = data_size; |
| 288 | } |
| 289 | rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); |
| 290 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 291 | rq->sense = h->sense; |
| 292 | memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); |
| 293 | rq->sense_len = 0; |
| 294 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 295 | return rq; |
| 296 | } |
| 297 | |
| 298 | static void release_controller(struct kref *kref) |
| 299 | { |
| 300 | struct rdac_controller *ctlr; |
| 301 | ctlr = container_of(kref, struct rdac_controller, kref); |
| 302 | |
| 303 | spin_lock(&list_lock); |
| 304 | list_del(&ctlr->node); |
| 305 | spin_unlock(&list_lock); |
| 306 | kfree(ctlr); |
| 307 | } |
| 308 | |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 309 | static struct rdac_controller *get_controller(u8 *subsys_id, u8 *slot_id, |
| 310 | char *array_name) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 311 | { |
| 312 | struct rdac_controller *ctlr, *tmp; |
| 313 | |
| 314 | spin_lock(&list_lock); |
| 315 | |
| 316 | list_for_each_entry(tmp, &ctlr_list, node) { |
| 317 | if ((memcmp(tmp->subsys_id, subsys_id, SUBSYS_ID_LEN) == 0) && |
| 318 | (memcmp(tmp->slot_id, slot_id, SLOT_ID_LEN) == 0)) { |
| 319 | kref_get(&tmp->kref); |
| 320 | spin_unlock(&list_lock); |
| 321 | return tmp; |
| 322 | } |
| 323 | } |
| 324 | ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC); |
| 325 | if (!ctlr) |
| 326 | goto done; |
| 327 | |
| 328 | /* initialize fields of controller */ |
| 329 | memcpy(ctlr->subsys_id, subsys_id, SUBSYS_ID_LEN); |
| 330 | memcpy(ctlr->slot_id, slot_id, SLOT_ID_LEN); |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 331 | memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN); |
| 332 | |
| 333 | /* update the controller index */ |
| 334 | if (slot_id[1] == 0x31) |
| 335 | ctlr->index = 0; |
| 336 | else |
| 337 | ctlr->index = 1; |
| 338 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 339 | kref_init(&ctlr->kref); |
| 340 | ctlr->use_ms10 = -1; |
| 341 | list_add(&ctlr->node, &ctlr_list); |
| 342 | done: |
| 343 | spin_unlock(&list_lock); |
| 344 | return ctlr; |
| 345 | } |
| 346 | |
| 347 | static int submit_inquiry(struct scsi_device *sdev, int page_code, |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 348 | unsigned int len, struct rdac_dh_data *h) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 349 | { |
| 350 | struct request *rq; |
| 351 | struct request_queue *q = sdev->request_queue; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 352 | int err = SCSI_DH_RES_TEMP_UNAVAIL; |
| 353 | |
| 354 | rq = get_rdac_req(sdev, &h->inq, len, READ); |
| 355 | if (!rq) |
| 356 | goto done; |
| 357 | |
| 358 | /* Prepare the command. */ |
| 359 | rq->cmd[0] = INQUIRY; |
| 360 | rq->cmd[1] = 1; |
| 361 | rq->cmd[2] = page_code; |
| 362 | rq->cmd[4] = len; |
| 363 | rq->cmd_len = COMMAND_SIZE(INQUIRY); |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 364 | |
| 365 | rq->sense = h->sense; |
| 366 | memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); |
| 367 | rq->sense_len = 0; |
| 368 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 369 | err = blk_execute_rq(q, NULL, rq, 1); |
| 370 | if (err == -EIO) |
| 371 | err = SCSI_DH_IO; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 372 | |
| 373 | blk_put_request(rq); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 374 | done: |
| 375 | return err; |
| 376 | } |
| 377 | |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 378 | static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h, |
| 379 | char *array_name) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 380 | { |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 381 | int err, i; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 382 | struct c8_inquiry *inqp; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 383 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 384 | err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 385 | if (err == SCSI_DH_OK) { |
| 386 | inqp = &h->inq.c8; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 387 | if (inqp->page_code != 0xc8) |
| 388 | return SCSI_DH_NOSYS; |
| 389 | if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' || |
| 390 | inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd') |
| 391 | return SCSI_DH_NOSYS; |
Chandra Seetharaman | 8479fca | 2008-08-12 17:26:58 -0700 | [diff] [blame] | 392 | h->lun = inqp->lun[7]; /* Uses only the last byte */ |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 393 | |
| 394 | for(i=0; i<ARRAY_LABEL_LEN-1; ++i) |
| 395 | *(array_name+i) = inqp->array_user_label[(2*i)+1]; |
| 396 | |
| 397 | *(array_name+ARRAY_LABEL_LEN-1) = '\0'; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 398 | } |
| 399 | return err; |
| 400 | } |
| 401 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 402 | 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] | 403 | { |
| 404 | int err; |
| 405 | struct c9_inquiry *inqp; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 406 | |
Chandra Seetharaman | fe42625 | 2008-08-12 17:26:59 -0700 | [diff] [blame] | 407 | h->lun_state = RDAC_LUN_UNOWNED; |
Chandra Seetharaman | 9eece96 | 2008-11-05 20:05:21 -0800 | [diff] [blame] | 408 | h->state = RDAC_STATE_ACTIVE; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 409 | err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 410 | if (err == SCSI_DH_OK) { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 411 | inqp = &h->inq.c9; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 412 | if ((inqp->avte_cvp >> 7) == 0x1) { |
| 413 | /* LUN in AVT mode */ |
| 414 | sdev_printk(KERN_NOTICE, sdev, |
| 415 | "%s: AVT mode detected\n", |
| 416 | RDAC_NAME); |
| 417 | h->lun_state = RDAC_LUN_AVT; |
| 418 | } else if ((inqp->avte_cvp & 0x1) != 0) { |
| 419 | /* LUN was owned by the controller */ |
| 420 | h->lun_state = RDAC_LUN_OWNED; |
| 421 | } |
| 422 | } |
| 423 | |
Chandra Seetharaman | 5a36756 | 2008-08-21 23:12:40 -0700 | [diff] [blame] | 424 | if (h->lun_state == RDAC_LUN_UNOWNED) |
| 425 | h->state = RDAC_STATE_PASSIVE; |
| 426 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 427 | return err; |
| 428 | } |
| 429 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 430 | static int initialize_controller(struct scsi_device *sdev, |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 431 | struct rdac_dh_data *h, char *array_name) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 432 | { |
| 433 | int err; |
| 434 | struct c4_inquiry *inqp; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 435 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 436 | err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 437 | if (err == SCSI_DH_OK) { |
| 438 | inqp = &h->inq.c4; |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 439 | h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id, |
| 440 | array_name); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 441 | if (!h->ctlr) |
| 442 | err = SCSI_DH_RES_TEMP_UNAVAIL; |
| 443 | } |
| 444 | return err; |
| 445 | } |
| 446 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 447 | 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] | 448 | { |
| 449 | int err; |
| 450 | struct c2_inquiry *inqp; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 451 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 452 | err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 453 | if (err == SCSI_DH_OK) { |
| 454 | inqp = &h->inq.c2; |
| 455 | /* |
| 456 | * If more than MODE6_MAX_LUN luns are supported, use |
| 457 | * mode select 10 |
| 458 | */ |
| 459 | if (inqp->max_lun_supported >= MODE6_MAX_LUN) |
| 460 | h->ctlr->use_ms10 = 1; |
| 461 | else |
| 462 | h->ctlr->use_ms10 = 0; |
| 463 | } |
| 464 | return err; |
| 465 | } |
| 466 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 467 | static int mode_select_handle_sense(struct scsi_device *sdev, |
| 468 | unsigned char *sensebuf) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 469 | { |
| 470 | struct scsi_sense_hdr sense_hdr; |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 471 | int err = SCSI_DH_IO, ret; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 472 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 473 | ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 474 | if (!ret) |
| 475 | goto done; |
| 476 | |
| 477 | err = SCSI_DH_OK; |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 478 | |
| 479 | switch (sense_hdr.sense_key) { |
| 480 | case NO_SENSE: |
| 481 | case ABORTED_COMMAND: |
| 482 | case UNIT_ATTENTION: |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 483 | err = SCSI_DH_RETRY; |
Chauhan, Vijay | 7687fb9 | 2009-03-04 12:17:54 +0530 | [diff] [blame] | 484 | break; |
| 485 | case NOT_READY: |
| 486 | if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01) |
| 487 | /* LUN Not Ready and is in the Process of Becoming |
| 488 | * Ready |
| 489 | */ |
| 490 | err = SCSI_DH_RETRY; |
| 491 | break; |
| 492 | case ILLEGAL_REQUEST: |
| 493 | if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36) |
| 494 | /* |
| 495 | * Command Lock contention |
| 496 | */ |
| 497 | err = SCSI_DH_RETRY; |
| 498 | break; |
| 499 | default: |
| 500 | sdev_printk(KERN_INFO, sdev, |
| 501 | "MODE_SELECT failed with sense %02x/%02x/%02x.\n", |
| 502 | sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 505 | done: |
| 506 | return err; |
| 507 | } |
| 508 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 509 | 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] | 510 | { |
| 511 | struct request *rq; |
| 512 | struct request_queue *q = sdev->request_queue; |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 513 | int err, retry_cnt = RDAC_RETRY_COUNT; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 514 | |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 515 | retry: |
| 516 | err = SCSI_DH_RES_TEMP_UNAVAIL; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 517 | rq = rdac_failover_get(sdev, h); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 518 | if (!rq) |
| 519 | goto done; |
| 520 | |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 521 | sdev_printk(KERN_INFO, sdev, "%s MODE_SELECT command.\n", |
| 522 | (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying"); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 523 | |
| 524 | err = blk_execute_rq(q, NULL, rq, 1); |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 525 | blk_put_request(rq); |
| 526 | if (err != SCSI_DH_OK) { |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 527 | err = mode_select_handle_sense(sdev, h->sense); |
Chandra Seetharaman | c85f8cb9 | 2008-11-05 20:06:37 -0800 | [diff] [blame] | 528 | if (err == SCSI_DH_RETRY && retry_cnt--) |
| 529 | goto retry; |
| 530 | } |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 531 | if (err == SCSI_DH_OK) |
| 532 | h->state = RDAC_STATE_ACTIVE; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 533 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 534 | done: |
| 535 | return err; |
| 536 | } |
| 537 | |
| 538 | static int rdac_activate(struct scsi_device *sdev) |
| 539 | { |
| 540 | struct rdac_dh_data *h = get_rdac_data(sdev); |
| 541 | int err = SCSI_DH_OK; |
| 542 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 543 | err = check_ownership(sdev, h); |
| 544 | if (err != SCSI_DH_OK) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 545 | goto done; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 546 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 547 | if (h->lun_state == RDAC_LUN_UNOWNED) |
| 548 | err = send_mode_select(sdev, h); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 549 | done: |
| 550 | return err; |
| 551 | } |
| 552 | |
| 553 | static int rdac_prep_fn(struct scsi_device *sdev, struct request *req) |
| 554 | { |
| 555 | struct rdac_dh_data *h = get_rdac_data(sdev); |
| 556 | int ret = BLKPREP_OK; |
| 557 | |
| 558 | if (h->state != RDAC_STATE_ACTIVE) { |
| 559 | ret = BLKPREP_KILL; |
| 560 | req->cmd_flags |= REQ_QUIET; |
| 561 | } |
| 562 | return ret; |
| 563 | |
| 564 | } |
| 565 | |
| 566 | static int rdac_check_sense(struct scsi_device *sdev, |
| 567 | struct scsi_sense_hdr *sense_hdr) |
| 568 | { |
| 569 | struct rdac_dh_data *h = get_rdac_data(sdev); |
| 570 | switch (sense_hdr->sense_key) { |
| 571 | case NOT_READY: |
Chauhan, Vijay | 8f03226 | 2009-04-20 18:14:23 +0530 | [diff] [blame] | 572 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01) |
| 573 | /* LUN Not Ready - Logical Unit Not Ready and is in |
| 574 | * the process of becoming ready |
| 575 | * Just retry. |
| 576 | */ |
| 577 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 578 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81) |
| 579 | /* LUN Not Ready - Storage firmware incompatible |
| 580 | * Manual code synchonisation required. |
| 581 | * |
| 582 | * Nothing we can do here. Try to bypass the path. |
| 583 | */ |
| 584 | return SUCCESS; |
| 585 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1) |
| 586 | /* LUN Not Ready - Quiescense in progress |
| 587 | * |
| 588 | * Just retry and wait. |
| 589 | */ |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 590 | return ADD_TO_MLQUEUE; |
Chauhan, Vijay | af50bb9 | 2009-03-17 18:51:40 +0530 | [diff] [blame] | 591 | if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02) |
| 592 | /* LUN Not Ready - Quiescense in progress |
| 593 | * or has been achieved |
| 594 | * Just retry. |
| 595 | */ |
| 596 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 597 | break; |
| 598 | case ILLEGAL_REQUEST: |
| 599 | if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) { |
| 600 | /* Invalid Request - Current Logical Unit Ownership. |
| 601 | * Controller is not the current owner of the LUN, |
| 602 | * Fail the path, so that the other path be used. |
| 603 | */ |
| 604 | h->state = RDAC_STATE_PASSIVE; |
| 605 | return SUCCESS; |
| 606 | } |
| 607 | break; |
| 608 | case UNIT_ATTENTION: |
| 609 | if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) |
| 610 | /* |
| 611 | * Power On, Reset, or Bus Device Reset, just retry. |
| 612 | */ |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 613 | return ADD_TO_MLQUEUE; |
Chauhan, Vijay | ea41e41 | 2009-01-26 21:29:37 +0530 | [diff] [blame] | 614 | if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02) |
| 615 | /* |
| 616 | * Quiescence in progress , just retry. |
| 617 | */ |
| 618 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 619 | break; |
| 620 | } |
| 621 | /* success just means we do not care what scsi-ml does */ |
| 622 | return SCSI_RETURN_NOT_HANDLED; |
| 623 | } |
| 624 | |
Adrian Bunk | f08c076 | 2008-08-11 11:59:21 -0700 | [diff] [blame] | 625 | static const struct scsi_dh_devlist rdac_dev_list[] = { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 626 | {"IBM", "1722"}, |
| 627 | {"IBM", "1724"}, |
| 628 | {"IBM", "1726"}, |
| 629 | {"IBM", "1742"}, |
| 630 | {"IBM", "1814"}, |
| 631 | {"IBM", "1815"}, |
| 632 | {"IBM", "1818"}, |
| 633 | {"IBM", "3526"}, |
| 634 | {"SGI", "TP9400"}, |
| 635 | {"SGI", "TP9500"}, |
| 636 | {"SGI", "IS"}, |
| 637 | {"STK", "OPENstorage D280"}, |
| 638 | {"SUN", "CSM200_R"}, |
Charlie Brady | 5bab088 | 2009-08-26 14:16:57 -0400 | [diff] [blame] | 639 | {"SUN", "LCSM100_I"}, |
| 640 | {"SUN", "LCSM100_S"}, |
| 641 | {"SUN", "LCSM100_E"}, |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 642 | {"SUN", "LCSM100_F"}, |
Yanqing_Liu@Dell.com | 650849d | 2008-10-02 12:18:33 -0500 | [diff] [blame] | 643 | {"DELL", "MD3000"}, |
| 644 | {"DELL", "MD3000i"}, |
Yanqing_Liu@Dell.com | cdf69bb | 2009-08-17 14:31:42 -0500 | [diff] [blame] | 645 | {"DELL", "MD32xx"}, |
| 646 | {"DELL", "MD32xxi"}, |
Babu Moger | 273c478 | 2008-11-10 16:17:48 -0700 | [diff] [blame] | 647 | {"LSI", "INF-01-00"}, |
| 648 | {"ENGENIO", "INF-01-00"}, |
Chandra Seetharaman | 4dbfb54 | 2009-08-12 12:43:20 -0700 | [diff] [blame] | 649 | {"STK", "FLEXLINE 380"}, |
| 650 | {"SUN", "CSM100_R_FC"}, |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 651 | {NULL, NULL}, |
| 652 | }; |
| 653 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 654 | static int rdac_bus_attach(struct scsi_device *sdev); |
| 655 | static void rdac_bus_detach(struct scsi_device *sdev); |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 656 | |
| 657 | static struct scsi_device_handler rdac_dh = { |
| 658 | .name = RDAC_NAME, |
| 659 | .module = THIS_MODULE, |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 660 | .devlist = rdac_dev_list, |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 661 | .prep_fn = rdac_prep_fn, |
| 662 | .check_sense = rdac_check_sense, |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 663 | .attach = rdac_bus_attach, |
| 664 | .detach = rdac_bus_detach, |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 665 | .activate = rdac_activate, |
| 666 | }; |
| 667 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 668 | static int rdac_bus_attach(struct scsi_device *sdev) |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 669 | { |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 670 | struct scsi_dh_data *scsi_dh_data; |
| 671 | struct rdac_dh_data *h; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 672 | unsigned long flags; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 673 | int err; |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 674 | char array_name[ARRAY_LABEL_LEN]; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 675 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 676 | scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) |
| 677 | + sizeof(*h) , GFP_KERNEL); |
| 678 | if (!scsi_dh_data) { |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 679 | sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 680 | RDAC_NAME); |
Chandra Seetharaman | 33af79d | 2008-07-16 17:35:08 -0700 | [diff] [blame] | 681 | return 0; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 684 | scsi_dh_data->scsi_dh = &rdac_dh; |
| 685 | h = (struct rdac_dh_data *) scsi_dh_data->buf; |
| 686 | h->lun = UNINITIALIZED_LUN; |
| 687 | h->state = RDAC_STATE_ACTIVE; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 688 | |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 689 | err = get_lun_info(sdev, h, array_name); |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 690 | if (err != SCSI_DH_OK) |
| 691 | goto failed; |
| 692 | |
Moger, Babu | 1527666 | 2009-09-03 21:42:21 -0600 | [diff] [blame^] | 693 | err = initialize_controller(sdev, h, array_name); |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 694 | if (err != SCSI_DH_OK) |
| 695 | goto failed; |
| 696 | |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 697 | err = check_ownership(sdev, h); |
| 698 | if (err != SCSI_DH_OK) |
| 699 | goto clean_ctlr; |
| 700 | |
| 701 | err = set_mode_select(sdev, h); |
| 702 | if (err != SCSI_DH_OK) |
| 703 | goto clean_ctlr; |
| 704 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 705 | if (!try_module_get(THIS_MODULE)) |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 706 | goto clean_ctlr; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 707 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 708 | spin_lock_irqsave(sdev->request_queue->queue_lock, flags); |
| 709 | sdev->scsi_dh_data = scsi_dh_data; |
| 710 | spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 711 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 712 | sdev_printk(KERN_NOTICE, sdev, |
| 713 | "%s: LUN %d (%s)\n", |
| 714 | RDAC_NAME, h->lun, lun_state[(int)h->lun_state]); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 715 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 716 | return 0; |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 717 | |
Moger, Babu | 87b79a5 | 2009-09-03 21:42:15 -0600 | [diff] [blame] | 718 | clean_ctlr: |
| 719 | kref_put(&h->ctlr->kref, release_controller); |
| 720 | |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 721 | failed: |
| 722 | kfree(scsi_dh_data); |
| 723 | sdev_printk(KERN_ERR, sdev, "%s: not attached\n", |
| 724 | RDAC_NAME); |
| 725 | return -EINVAL; |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 728 | static void rdac_bus_detach( struct scsi_device *sdev ) |
| 729 | { |
| 730 | struct scsi_dh_data *scsi_dh_data; |
| 731 | struct rdac_dh_data *h; |
| 732 | unsigned long flags; |
| 733 | |
| 734 | spin_lock_irqsave(sdev->request_queue->queue_lock, flags); |
| 735 | scsi_dh_data = sdev->scsi_dh_data; |
| 736 | sdev->scsi_dh_data = NULL; |
| 737 | spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); |
| 738 | |
| 739 | h = (struct rdac_dh_data *) scsi_dh_data->buf; |
| 740 | if (h->ctlr) |
| 741 | kref_put(&h->ctlr->kref, release_controller); |
| 742 | kfree(scsi_dh_data); |
| 743 | module_put(THIS_MODULE); |
Hannes Reinecke | ca9f008 | 2008-07-17 16:53:15 -0700 | [diff] [blame] | 744 | sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | |
| 748 | |
Chandra Seetharaman | fbd7ab3 | 2008-05-01 14:49:52 -0700 | [diff] [blame] | 749 | static int __init rdac_init(void) |
| 750 | { |
| 751 | int r; |
| 752 | |
| 753 | r = scsi_register_device_handler(&rdac_dh); |
| 754 | if (r != 0) |
| 755 | printk(KERN_ERR "Failed to register scsi device handler."); |
| 756 | return r; |
| 757 | } |
| 758 | |
| 759 | static void __exit rdac_exit(void) |
| 760 | { |
| 761 | scsi_unregister_device_handler(&rdac_dh); |
| 762 | } |
| 763 | |
| 764 | module_init(rdac_init); |
| 765 | module_exit(rdac_exit); |
| 766 | |
| 767 | MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver"); |
| 768 | MODULE_AUTHOR("Mike Christie, Chandra Seetharaman"); |
| 769 | MODULE_LICENSE("GPL"); |