scsi_dh_rdac.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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. static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
  185. {
  186. struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
  187. BUG_ON(scsi_dh_data == NULL);
  188. return ((struct rdac_dh_data *) scsi_dh_data->buf);
  189. }
  190. static struct request *get_rdac_req(struct scsi_device *sdev,
  191. void *buffer, unsigned buflen, int rw)
  192. {
  193. struct request *rq;
  194. struct request_queue *q = sdev->request_queue;
  195. rq = blk_get_request(q, rw, GFP_NOIO);
  196. if (!rq) {
  197. sdev_printk(KERN_INFO, sdev,
  198. "get_rdac_req: blk_get_request failed.\n");
  199. return NULL;
  200. }
  201. if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) {
  202. blk_put_request(rq);
  203. sdev_printk(KERN_INFO, sdev,
  204. "get_rdac_req: blk_rq_map_kern failed.\n");
  205. return NULL;
  206. }
  207. rq->cmd_type = REQ_TYPE_BLOCK_PC;
  208. rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
  209. REQ_FAILFAST_DRIVER;
  210. rq->retries = RDAC_RETRIES;
  211. rq->timeout = RDAC_TIMEOUT;
  212. return rq;
  213. }
  214. static struct request *rdac_failover_get(struct scsi_device *sdev,
  215. struct rdac_dh_data *h)
  216. {
  217. struct request *rq;
  218. struct rdac_mode_common *common;
  219. unsigned data_size;
  220. if (h->ctlr->use_ms10) {
  221. struct rdac_pg_expanded *rdac_pg;
  222. data_size = sizeof(struct rdac_pg_expanded);
  223. rdac_pg = &h->ctlr->mode_select.expanded;
  224. memset(rdac_pg, 0, data_size);
  225. common = &rdac_pg->common;
  226. rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40;
  227. rdac_pg->subpage_code = 0x1;
  228. rdac_pg->page_len[0] = 0x01;
  229. rdac_pg->page_len[1] = 0x28;
  230. rdac_pg->lun_table[h->lun] = 0x81;
  231. } else {
  232. struct rdac_pg_legacy *rdac_pg;
  233. data_size = sizeof(struct rdac_pg_legacy);
  234. rdac_pg = &h->ctlr->mode_select.legacy;
  235. memset(rdac_pg, 0, data_size);
  236. common = &rdac_pg->common;
  237. rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER;
  238. rdac_pg->page_len = 0x68;
  239. rdac_pg->lun_table[h->lun] = 0x81;
  240. }
  241. common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS;
  242. common->quiescence_timeout = RDAC_QUIESCENCE_TIME;
  243. common->rdac_options = RDAC_FORCED_QUIESENCE;
  244. /* get request for block layer packet command */
  245. rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE);
  246. if (!rq)
  247. return NULL;
  248. /* Prepare the command. */
  249. if (h->ctlr->use_ms10) {
  250. rq->cmd[0] = MODE_SELECT_10;
  251. rq->cmd[7] = data_size >> 8;
  252. rq->cmd[8] = data_size & 0xff;
  253. } else {
  254. rq->cmd[0] = MODE_SELECT;
  255. rq->cmd[4] = data_size;
  256. }
  257. rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
  258. rq->sense = h->sense;
  259. memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
  260. rq->sense_len = 0;
  261. return rq;
  262. }
  263. static void release_controller(struct kref *kref)
  264. {
  265. struct rdac_controller *ctlr;
  266. ctlr = container_of(kref, struct rdac_controller, kref);
  267. spin_lock(&list_lock);
  268. list_del(&ctlr->node);
  269. spin_unlock(&list_lock);
  270. kfree(ctlr);
  271. }
  272. static struct rdac_controller *get_controller(u8 *subsys_id, u8 *slot_id,
  273. char *array_name)
  274. {
  275. struct rdac_controller *ctlr, *tmp;
  276. spin_lock(&list_lock);
  277. list_for_each_entry(tmp, &ctlr_list, node) {
  278. if ((memcmp(tmp->subsys_id, subsys_id, SUBSYS_ID_LEN) == 0) &&
  279. (memcmp(tmp->slot_id, slot_id, SLOT_ID_LEN) == 0)) {
  280. kref_get(&tmp->kref);
  281. spin_unlock(&list_lock);
  282. return tmp;
  283. }
  284. }
  285. ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC);
  286. if (!ctlr)
  287. goto done;
  288. /* initialize fields of controller */
  289. memcpy(ctlr->subsys_id, subsys_id, SUBSYS_ID_LEN);
  290. memcpy(ctlr->slot_id, slot_id, SLOT_ID_LEN);
  291. memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN);
  292. /* update the controller index */
  293. if (slot_id[1] == 0x31)
  294. ctlr->index = 0;
  295. else
  296. ctlr->index = 1;
  297. kref_init(&ctlr->kref);
  298. ctlr->use_ms10 = -1;
  299. list_add(&ctlr->node, &ctlr_list);
  300. done:
  301. spin_unlock(&list_lock);
  302. return ctlr;
  303. }
  304. static int submit_inquiry(struct scsi_device *sdev, int page_code,
  305. unsigned int len, struct rdac_dh_data *h)
  306. {
  307. struct request *rq;
  308. struct request_queue *q = sdev->request_queue;
  309. int err = SCSI_DH_RES_TEMP_UNAVAIL;
  310. rq = get_rdac_req(sdev, &h->inq, len, READ);
  311. if (!rq)
  312. goto done;
  313. /* Prepare the command. */
  314. rq->cmd[0] = INQUIRY;
  315. rq->cmd[1] = 1;
  316. rq->cmd[2] = page_code;
  317. rq->cmd[4] = len;
  318. rq->cmd_len = COMMAND_SIZE(INQUIRY);
  319. rq->sense = h->sense;
  320. memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
  321. rq->sense_len = 0;
  322. err = blk_execute_rq(q, NULL, rq, 1);
  323. if (err == -EIO)
  324. err = SCSI_DH_IO;
  325. blk_put_request(rq);
  326. done:
  327. return err;
  328. }
  329. static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h,
  330. char *array_name)
  331. {
  332. int err, i;
  333. struct c8_inquiry *inqp;
  334. err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
  335. if (err == SCSI_DH_OK) {
  336. inqp = &h->inq.c8;
  337. if (inqp->page_code != 0xc8)
  338. return SCSI_DH_NOSYS;
  339. if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
  340. inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
  341. return SCSI_DH_NOSYS;
  342. h->lun = inqp->lun[7]; /* Uses only the last byte */
  343. for(i=0; i<ARRAY_LABEL_LEN-1; ++i)
  344. *(array_name+i) = inqp->array_user_label[(2*i)+1];
  345. *(array_name+ARRAY_LABEL_LEN-1) = '\0';
  346. }
  347. return err;
  348. }
  349. static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
  350. {
  351. int err;
  352. struct c9_inquiry *inqp;
  353. h->lun_state = RDAC_LUN_UNOWNED;
  354. h->state = RDAC_STATE_ACTIVE;
  355. err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
  356. if (err == SCSI_DH_OK) {
  357. inqp = &h->inq.c9;
  358. if ((inqp->avte_cvp >> 7) == 0x1) {
  359. /* LUN in AVT mode */
  360. sdev_printk(KERN_NOTICE, sdev,
  361. "%s: AVT mode detected\n",
  362. RDAC_NAME);
  363. h->lun_state = RDAC_LUN_AVT;
  364. } else if ((inqp->avte_cvp & 0x1) != 0) {
  365. /* LUN was owned by the controller */
  366. h->lun_state = RDAC_LUN_OWNED;
  367. }
  368. }
  369. if (h->lun_state == RDAC_LUN_UNOWNED)
  370. h->state = RDAC_STATE_PASSIVE;
  371. return err;
  372. }
  373. static int initialize_controller(struct scsi_device *sdev,
  374. struct rdac_dh_data *h, char *array_name)
  375. {
  376. int err;
  377. struct c4_inquiry *inqp;
  378. err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
  379. if (err == SCSI_DH_OK) {
  380. inqp = &h->inq.c4;
  381. h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id,
  382. array_name);
  383. if (!h->ctlr)
  384. err = SCSI_DH_RES_TEMP_UNAVAIL;
  385. }
  386. return err;
  387. }
  388. static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
  389. {
  390. int err;
  391. struct c2_inquiry *inqp;
  392. err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
  393. if (err == SCSI_DH_OK) {
  394. inqp = &h->inq.c2;
  395. /*
  396. * If more than MODE6_MAX_LUN luns are supported, use
  397. * mode select 10
  398. */
  399. if (inqp->max_lun_supported >= MODE6_MAX_LUN)
  400. h->ctlr->use_ms10 = 1;
  401. else
  402. h->ctlr->use_ms10 = 0;
  403. }
  404. return err;
  405. }
  406. static int mode_select_handle_sense(struct scsi_device *sdev,
  407. unsigned char *sensebuf)
  408. {
  409. struct scsi_sense_hdr sense_hdr;
  410. int err = SCSI_DH_IO, ret;
  411. ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
  412. if (!ret)
  413. goto done;
  414. err = SCSI_DH_OK;
  415. switch (sense_hdr.sense_key) {
  416. case NO_SENSE:
  417. case ABORTED_COMMAND:
  418. case UNIT_ATTENTION:
  419. err = SCSI_DH_RETRY;
  420. break;
  421. case NOT_READY:
  422. if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
  423. /* LUN Not Ready and is in the Process of Becoming
  424. * Ready
  425. */
  426. err = SCSI_DH_RETRY;
  427. break;
  428. case ILLEGAL_REQUEST:
  429. if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
  430. /*
  431. * Command Lock contention
  432. */
  433. err = SCSI_DH_RETRY;
  434. break;
  435. default:
  436. sdev_printk(KERN_INFO, sdev,
  437. "MODE_SELECT failed with sense %02x/%02x/%02x.\n",
  438. sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq);
  439. }
  440. done:
  441. return err;
  442. }
  443. static int send_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
  444. {
  445. struct request *rq;
  446. struct request_queue *q = sdev->request_queue;
  447. int err, retry_cnt = RDAC_RETRY_COUNT;
  448. retry:
  449. err = SCSI_DH_RES_TEMP_UNAVAIL;
  450. rq = rdac_failover_get(sdev, h);
  451. if (!rq)
  452. goto done;
  453. sdev_printk(KERN_INFO, sdev, "%s MODE_SELECT command.\n",
  454. (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying");
  455. err = blk_execute_rq(q, NULL, rq, 1);
  456. blk_put_request(rq);
  457. if (err != SCSI_DH_OK) {
  458. err = mode_select_handle_sense(sdev, h->sense);
  459. if (err == SCSI_DH_RETRY && retry_cnt--)
  460. goto retry;
  461. }
  462. if (err == SCSI_DH_OK)
  463. h->state = RDAC_STATE_ACTIVE;
  464. done:
  465. return err;
  466. }
  467. static int rdac_activate(struct scsi_device *sdev)
  468. {
  469. struct rdac_dh_data *h = get_rdac_data(sdev);
  470. int err = SCSI_DH_OK;
  471. err = check_ownership(sdev, h);
  472. if (err != SCSI_DH_OK)
  473. goto done;
  474. if (h->lun_state == RDAC_LUN_UNOWNED)
  475. err = send_mode_select(sdev, h);
  476. done:
  477. return err;
  478. }
  479. static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
  480. {
  481. struct rdac_dh_data *h = get_rdac_data(sdev);
  482. int ret = BLKPREP_OK;
  483. if (h->state != RDAC_STATE_ACTIVE) {
  484. ret = BLKPREP_KILL;
  485. req->cmd_flags |= REQ_QUIET;
  486. }
  487. return ret;
  488. }
  489. static int rdac_check_sense(struct scsi_device *sdev,
  490. struct scsi_sense_hdr *sense_hdr)
  491. {
  492. struct rdac_dh_data *h = get_rdac_data(sdev);
  493. switch (sense_hdr->sense_key) {
  494. case NOT_READY:
  495. if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01)
  496. /* LUN Not Ready - Logical Unit Not Ready and is in
  497. * the process of becoming ready
  498. * Just retry.
  499. */
  500. return ADD_TO_MLQUEUE;
  501. if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81)
  502. /* LUN Not Ready - Storage firmware incompatible
  503. * Manual code synchonisation required.
  504. *
  505. * Nothing we can do here. Try to bypass the path.
  506. */
  507. return SUCCESS;
  508. if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1)
  509. /* LUN Not Ready - Quiescense in progress
  510. *
  511. * Just retry and wait.
  512. */
  513. return ADD_TO_MLQUEUE;
  514. if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02)
  515. /* LUN Not Ready - Quiescense in progress
  516. * or has been achieved
  517. * Just retry.
  518. */
  519. return ADD_TO_MLQUEUE;
  520. break;
  521. case ILLEGAL_REQUEST:
  522. if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) {
  523. /* Invalid Request - Current Logical Unit Ownership.
  524. * Controller is not the current owner of the LUN,
  525. * Fail the path, so that the other path be used.
  526. */
  527. h->state = RDAC_STATE_PASSIVE;
  528. return SUCCESS;
  529. }
  530. break;
  531. case UNIT_ATTENTION:
  532. if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
  533. /*
  534. * Power On, Reset, or Bus Device Reset, just retry.
  535. */
  536. return ADD_TO_MLQUEUE;
  537. if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02)
  538. /*
  539. * Quiescence in progress , just retry.
  540. */
  541. return ADD_TO_MLQUEUE;
  542. break;
  543. }
  544. /* success just means we do not care what scsi-ml does */
  545. return SCSI_RETURN_NOT_HANDLED;
  546. }
  547. static const struct scsi_dh_devlist rdac_dev_list[] = {
  548. {"IBM", "1722"},
  549. {"IBM", "1724"},
  550. {"IBM", "1726"},
  551. {"IBM", "1742"},
  552. {"IBM", "1814"},
  553. {"IBM", "1815"},
  554. {"IBM", "1818"},
  555. {"IBM", "3526"},
  556. {"SGI", "TP9400"},
  557. {"SGI", "TP9500"},
  558. {"SGI", "IS"},
  559. {"STK", "OPENstorage D280"},
  560. {"SUN", "CSM200_R"},
  561. {"SUN", "LCSM100_I"},
  562. {"SUN", "LCSM100_S"},
  563. {"SUN", "LCSM100_E"},
  564. {"SUN", "LCSM100_F"},
  565. {"DELL", "MD3000"},
  566. {"DELL", "MD3000i"},
  567. {"DELL", "MD32xx"},
  568. {"DELL", "MD32xxi"},
  569. {"LSI", "INF-01-00"},
  570. {"ENGENIO", "INF-01-00"},
  571. {"STK", "FLEXLINE 380"},
  572. {"SUN", "CSM100_R_FC"},
  573. {NULL, NULL},
  574. };
  575. static int rdac_bus_attach(struct scsi_device *sdev);
  576. static void rdac_bus_detach(struct scsi_device *sdev);
  577. static struct scsi_device_handler rdac_dh = {
  578. .name = RDAC_NAME,
  579. .module = THIS_MODULE,
  580. .devlist = rdac_dev_list,
  581. .prep_fn = rdac_prep_fn,
  582. .check_sense = rdac_check_sense,
  583. .attach = rdac_bus_attach,
  584. .detach = rdac_bus_detach,
  585. .activate = rdac_activate,
  586. };
  587. static int rdac_bus_attach(struct scsi_device *sdev)
  588. {
  589. struct scsi_dh_data *scsi_dh_data;
  590. struct rdac_dh_data *h;
  591. unsigned long flags;
  592. int err;
  593. char array_name[ARRAY_LABEL_LEN];
  594. scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
  595. + sizeof(*h) , GFP_KERNEL);
  596. if (!scsi_dh_data) {
  597. sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
  598. RDAC_NAME);
  599. return 0;
  600. }
  601. scsi_dh_data->scsi_dh = &rdac_dh;
  602. h = (struct rdac_dh_data *) scsi_dh_data->buf;
  603. h->lun = UNINITIALIZED_LUN;
  604. h->state = RDAC_STATE_ACTIVE;
  605. err = get_lun_info(sdev, h, array_name);
  606. if (err != SCSI_DH_OK)
  607. goto failed;
  608. err = initialize_controller(sdev, h, array_name);
  609. if (err != SCSI_DH_OK)
  610. goto failed;
  611. err = check_ownership(sdev, h);
  612. if (err != SCSI_DH_OK)
  613. goto clean_ctlr;
  614. err = set_mode_select(sdev, h);
  615. if (err != SCSI_DH_OK)
  616. goto clean_ctlr;
  617. if (!try_module_get(THIS_MODULE))
  618. goto clean_ctlr;
  619. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  620. sdev->scsi_dh_data = scsi_dh_data;
  621. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  622. sdev_printk(KERN_NOTICE, sdev,
  623. "%s: LUN %d (%s)\n",
  624. RDAC_NAME, h->lun, lun_state[(int)h->lun_state]);
  625. return 0;
  626. clean_ctlr:
  627. kref_put(&h->ctlr->kref, release_controller);
  628. failed:
  629. kfree(scsi_dh_data);
  630. sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
  631. RDAC_NAME);
  632. return -EINVAL;
  633. }
  634. static void rdac_bus_detach( struct scsi_device *sdev )
  635. {
  636. struct scsi_dh_data *scsi_dh_data;
  637. struct rdac_dh_data *h;
  638. unsigned long flags;
  639. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  640. scsi_dh_data = sdev->scsi_dh_data;
  641. sdev->scsi_dh_data = NULL;
  642. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  643. h = (struct rdac_dh_data *) scsi_dh_data->buf;
  644. if (h->ctlr)
  645. kref_put(&h->ctlr->kref, release_controller);
  646. kfree(scsi_dh_data);
  647. module_put(THIS_MODULE);
  648. sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
  649. }
  650. static int __init rdac_init(void)
  651. {
  652. int r;
  653. r = scsi_register_device_handler(&rdac_dh);
  654. if (r != 0)
  655. printk(KERN_ERR "Failed to register scsi device handler.");
  656. return r;
  657. }
  658. static void __exit rdac_exit(void)
  659. {
  660. scsi_unregister_device_handler(&rdac_dh);
  661. }
  662. module_init(rdac_init);
  663. module_exit(rdac_exit);
  664. MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver");
  665. MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
  666. MODULE_LICENSE("GPL");