scsi_dh_rdac.c 22 KB

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