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