scsi_dh_rdac.c 22 KB

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