scsi_dh_rdac.c 19 KB

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