scsi_dh_rdac.c 21 KB

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