scsi_dh_rdac.c 21 KB

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