scsi_dh_rdac.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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, struct list_head *list)
  251. {
  252. struct request *rq;
  253. struct rdac_mode_common *common;
  254. unsigned data_size;
  255. struct rdac_queue_data *qdata;
  256. u8 *lun_table;
  257. if (h->ctlr->use_ms10) {
  258. struct rdac_pg_expanded *rdac_pg;
  259. data_size = sizeof(struct rdac_pg_expanded);
  260. rdac_pg = &h->ctlr->mode_select.expanded;
  261. memset(rdac_pg, 0, data_size);
  262. common = &rdac_pg->common;
  263. rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40;
  264. rdac_pg->subpage_code = 0x1;
  265. rdac_pg->page_len[0] = 0x01;
  266. rdac_pg->page_len[1] = 0x28;
  267. lun_table = rdac_pg->lun_table;
  268. } else {
  269. struct rdac_pg_legacy *rdac_pg;
  270. data_size = sizeof(struct rdac_pg_legacy);
  271. rdac_pg = &h->ctlr->mode_select.legacy;
  272. memset(rdac_pg, 0, data_size);
  273. common = &rdac_pg->common;
  274. rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER;
  275. rdac_pg->page_len = 0x68;
  276. lun_table = rdac_pg->lun_table;
  277. }
  278. common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS;
  279. common->quiescence_timeout = RDAC_QUIESCENCE_TIME;
  280. common->rdac_options = RDAC_FORCED_QUIESENCE;
  281. list_for_each_entry(qdata, list, entry) {
  282. lun_table[qdata->h->lun] = 0x81;
  283. }
  284. /* get request for block layer packet command */
  285. rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE);
  286. if (!rq)
  287. return NULL;
  288. /* Prepare the command. */
  289. if (h->ctlr->use_ms10) {
  290. rq->cmd[0] = MODE_SELECT_10;
  291. rq->cmd[7] = data_size >> 8;
  292. rq->cmd[8] = data_size & 0xff;
  293. } else {
  294. rq->cmd[0] = MODE_SELECT;
  295. rq->cmd[4] = data_size;
  296. }
  297. rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
  298. rq->sense = h->sense;
  299. memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
  300. rq->sense_len = 0;
  301. return rq;
  302. }
  303. static void release_controller(struct kref *kref)
  304. {
  305. struct rdac_controller *ctlr;
  306. ctlr = container_of(kref, struct rdac_controller, kref);
  307. flush_workqueue(kmpath_rdacd);
  308. spin_lock(&list_lock);
  309. list_del(&ctlr->node);
  310. spin_unlock(&list_lock);
  311. kfree(ctlr);
  312. }
  313. static struct rdac_controller *get_controller(u8 *subsys_id, u8 *slot_id,
  314. char *array_name)
  315. {
  316. struct rdac_controller *ctlr, *tmp;
  317. spin_lock(&list_lock);
  318. list_for_each_entry(tmp, &ctlr_list, node) {
  319. if ((memcmp(tmp->subsys_id, subsys_id, SUBSYS_ID_LEN) == 0) &&
  320. (memcmp(tmp->slot_id, slot_id, SLOT_ID_LEN) == 0)) {
  321. kref_get(&tmp->kref);
  322. spin_unlock(&list_lock);
  323. return tmp;
  324. }
  325. }
  326. ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC);
  327. if (!ctlr)
  328. goto done;
  329. /* initialize fields of controller */
  330. memcpy(ctlr->subsys_id, subsys_id, SUBSYS_ID_LEN);
  331. memcpy(ctlr->slot_id, slot_id, SLOT_ID_LEN);
  332. memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN);
  333. /* update the controller index */
  334. if (slot_id[1] == 0x31)
  335. ctlr->index = 0;
  336. else
  337. ctlr->index = 1;
  338. kref_init(&ctlr->kref);
  339. ctlr->use_ms10 = -1;
  340. ctlr->ms_queued = 0;
  341. ctlr->ms_sdev = NULL;
  342. spin_lock_init(&ctlr->ms_lock);
  343. INIT_WORK(&ctlr->ms_work, send_mode_select);
  344. INIT_LIST_HEAD(&ctlr->ms_head);
  345. list_add(&ctlr->node, &ctlr_list);
  346. done:
  347. spin_unlock(&list_lock);
  348. return ctlr;
  349. }
  350. static int submit_inquiry(struct scsi_device *sdev, int page_code,
  351. unsigned int len, struct rdac_dh_data *h)
  352. {
  353. struct request *rq;
  354. struct request_queue *q = sdev->request_queue;
  355. int err = SCSI_DH_RES_TEMP_UNAVAIL;
  356. rq = get_rdac_req(sdev, &h->inq, len, READ);
  357. if (!rq)
  358. goto done;
  359. /* Prepare the command. */
  360. rq->cmd[0] = INQUIRY;
  361. rq->cmd[1] = 1;
  362. rq->cmd[2] = page_code;
  363. rq->cmd[4] = len;
  364. rq->cmd_len = COMMAND_SIZE(INQUIRY);
  365. rq->sense = h->sense;
  366. memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
  367. rq->sense_len = 0;
  368. err = blk_execute_rq(q, NULL, rq, 1);
  369. if (err == -EIO)
  370. err = SCSI_DH_IO;
  371. blk_put_request(rq);
  372. done:
  373. return err;
  374. }
  375. static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h,
  376. char *array_name)
  377. {
  378. int err, i;
  379. struct c8_inquiry *inqp;
  380. err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
  381. if (err == SCSI_DH_OK) {
  382. inqp = &h->inq.c8;
  383. if (inqp->page_code != 0xc8)
  384. return SCSI_DH_NOSYS;
  385. if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
  386. inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
  387. return SCSI_DH_NOSYS;
  388. h->lun = inqp->lun[7]; /* Uses only the last byte */
  389. for(i=0; i<ARRAY_LABEL_LEN-1; ++i)
  390. *(array_name+i) = inqp->array_user_label[(2*i)+1];
  391. *(array_name+ARRAY_LABEL_LEN-1) = '\0';
  392. }
  393. return err;
  394. }
  395. static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
  396. {
  397. int err;
  398. struct c9_inquiry *inqp;
  399. h->lun_state = RDAC_LUN_UNOWNED;
  400. h->state = RDAC_STATE_ACTIVE;
  401. err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
  402. if (err == SCSI_DH_OK) {
  403. inqp = &h->inq.c9;
  404. if ((inqp->avte_cvp >> 7) == 0x1) {
  405. /* LUN in AVT mode */
  406. sdev_printk(KERN_NOTICE, sdev,
  407. "%s: AVT mode detected\n",
  408. RDAC_NAME);
  409. h->lun_state = RDAC_LUN_AVT;
  410. } else if ((inqp->avte_cvp & 0x1) != 0) {
  411. /* LUN was owned by the controller */
  412. h->lun_state = RDAC_LUN_OWNED;
  413. }
  414. }
  415. if (h->lun_state == RDAC_LUN_UNOWNED)
  416. h->state = RDAC_STATE_PASSIVE;
  417. return err;
  418. }
  419. static int initialize_controller(struct scsi_device *sdev,
  420. struct rdac_dh_data *h, char *array_name)
  421. {
  422. int err;
  423. struct c4_inquiry *inqp;
  424. err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
  425. if (err == SCSI_DH_OK) {
  426. inqp = &h->inq.c4;
  427. h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id,
  428. array_name);
  429. if (!h->ctlr)
  430. err = SCSI_DH_RES_TEMP_UNAVAIL;
  431. }
  432. return err;
  433. }
  434. static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
  435. {
  436. int err;
  437. struct c2_inquiry *inqp;
  438. err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
  439. if (err == SCSI_DH_OK) {
  440. inqp = &h->inq.c2;
  441. /*
  442. * If more than MODE6_MAX_LUN luns are supported, use
  443. * mode select 10
  444. */
  445. if (inqp->max_lun_supported >= MODE6_MAX_LUN)
  446. h->ctlr->use_ms10 = 1;
  447. else
  448. h->ctlr->use_ms10 = 0;
  449. }
  450. return err;
  451. }
  452. static int mode_select_handle_sense(struct scsi_device *sdev,
  453. unsigned char *sensebuf)
  454. {
  455. struct scsi_sense_hdr sense_hdr;
  456. int err = SCSI_DH_IO, ret;
  457. struct rdac_dh_data *h = get_rdac_data(sdev);
  458. ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
  459. if (!ret)
  460. goto done;
  461. switch (sense_hdr.sense_key) {
  462. case NO_SENSE:
  463. case ABORTED_COMMAND:
  464. case UNIT_ATTENTION:
  465. err = SCSI_DH_RETRY;
  466. break;
  467. case NOT_READY:
  468. if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
  469. /* LUN Not Ready and is in the Process of Becoming
  470. * Ready
  471. */
  472. err = SCSI_DH_RETRY;
  473. break;
  474. case ILLEGAL_REQUEST:
  475. if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
  476. /*
  477. * Command Lock contention
  478. */
  479. err = SCSI_DH_RETRY;
  480. break;
  481. default:
  482. break;
  483. }
  484. RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
  485. "MODE_SELECT returned with sense %02x/%02x/%02x",
  486. (char *) h->ctlr->array_name, h->ctlr->index,
  487. sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq);
  488. done:
  489. return err;
  490. }
  491. static void send_mode_select(struct work_struct *work)
  492. {
  493. struct rdac_controller *ctlr =
  494. container_of(work, struct rdac_controller, ms_work);
  495. struct request *rq;
  496. struct scsi_device *sdev = ctlr->ms_sdev;
  497. struct rdac_dh_data *h = get_rdac_data(sdev);
  498. struct request_queue *q = sdev->request_queue;
  499. int err, retry_cnt = RDAC_RETRY_COUNT;
  500. struct rdac_queue_data *tmp, *qdata;
  501. LIST_HEAD(list);
  502. spin_lock(&ctlr->ms_lock);
  503. list_splice_init(&ctlr->ms_head, &list);
  504. ctlr->ms_queued = 0;
  505. ctlr->ms_sdev = NULL;
  506. spin_unlock(&ctlr->ms_lock);
  507. retry:
  508. err = SCSI_DH_RES_TEMP_UNAVAIL;
  509. rq = rdac_failover_get(sdev, h, &list);
  510. if (!rq)
  511. goto done;
  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. {"DELL", "MD36xxi"},
  677. {"DELL", "MD36xxf"},
  678. {"LSI", "INF-01-00"},
  679. {"ENGENIO", "INF-01-00"},
  680. {"STK", "FLEXLINE 380"},
  681. {"SUN", "CSM100_R_FC"},
  682. {"SUN", "STK6580_6780"},
  683. {"SUN", "SUN_6180"},
  684. {NULL, NULL},
  685. };
  686. static int rdac_bus_attach(struct scsi_device *sdev);
  687. static void rdac_bus_detach(struct scsi_device *sdev);
  688. static struct scsi_device_handler rdac_dh = {
  689. .name = RDAC_NAME,
  690. .module = THIS_MODULE,
  691. .devlist = rdac_dev_list,
  692. .prep_fn = rdac_prep_fn,
  693. .check_sense = rdac_check_sense,
  694. .attach = rdac_bus_attach,
  695. .detach = rdac_bus_detach,
  696. .activate = rdac_activate,
  697. };
  698. static int rdac_bus_attach(struct scsi_device *sdev)
  699. {
  700. struct scsi_dh_data *scsi_dh_data;
  701. struct rdac_dh_data *h;
  702. unsigned long flags;
  703. int err;
  704. char array_name[ARRAY_LABEL_LEN];
  705. scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
  706. + sizeof(*h) , GFP_KERNEL);
  707. if (!scsi_dh_data) {
  708. sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
  709. RDAC_NAME);
  710. return 0;
  711. }
  712. scsi_dh_data->scsi_dh = &rdac_dh;
  713. h = (struct rdac_dh_data *) scsi_dh_data->buf;
  714. h->lun = UNINITIALIZED_LUN;
  715. h->state = RDAC_STATE_ACTIVE;
  716. err = get_lun_info(sdev, h, array_name);
  717. if (err != SCSI_DH_OK)
  718. goto failed;
  719. err = initialize_controller(sdev, h, array_name);
  720. if (err != SCSI_DH_OK)
  721. goto failed;
  722. err = check_ownership(sdev, h);
  723. if (err != SCSI_DH_OK)
  724. goto clean_ctlr;
  725. err = set_mode_select(sdev, h);
  726. if (err != SCSI_DH_OK)
  727. goto clean_ctlr;
  728. if (!try_module_get(THIS_MODULE))
  729. goto clean_ctlr;
  730. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  731. sdev->scsi_dh_data = scsi_dh_data;
  732. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  733. sdev_printk(KERN_NOTICE, sdev,
  734. "%s: LUN %d (%s)\n",
  735. RDAC_NAME, h->lun, lun_state[(int)h->lun_state]);
  736. return 0;
  737. clean_ctlr:
  738. kref_put(&h->ctlr->kref, release_controller);
  739. failed:
  740. kfree(scsi_dh_data);
  741. sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
  742. RDAC_NAME);
  743. return -EINVAL;
  744. }
  745. static void rdac_bus_detach( struct scsi_device *sdev )
  746. {
  747. struct scsi_dh_data *scsi_dh_data;
  748. struct rdac_dh_data *h;
  749. unsigned long flags;
  750. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  751. scsi_dh_data = sdev->scsi_dh_data;
  752. sdev->scsi_dh_data = NULL;
  753. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  754. h = (struct rdac_dh_data *) scsi_dh_data->buf;
  755. if (h->ctlr)
  756. kref_put(&h->ctlr->kref, release_controller);
  757. kfree(scsi_dh_data);
  758. module_put(THIS_MODULE);
  759. sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
  760. }
  761. static int __init rdac_init(void)
  762. {
  763. int r;
  764. r = scsi_register_device_handler(&rdac_dh);
  765. if (r != 0) {
  766. printk(KERN_ERR "Failed to register scsi device handler.");
  767. goto done;
  768. }
  769. /*
  770. * Create workqueue to handle mode selects for rdac
  771. */
  772. kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd");
  773. if (!kmpath_rdacd) {
  774. scsi_unregister_device_handler(&rdac_dh);
  775. printk(KERN_ERR "kmpath_rdacd creation failed.\n");
  776. }
  777. done:
  778. return r;
  779. }
  780. static void __exit rdac_exit(void)
  781. {
  782. destroy_workqueue(kmpath_rdacd);
  783. scsi_unregister_device_handler(&rdac_dh);
  784. }
  785. module_init(rdac_init);
  786. module_exit(rdac_exit);
  787. MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver");
  788. MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
  789. MODULE_VERSION("01.00.0000.0000");
  790. MODULE_LICENSE("GPL");