scsi_dh_rdac.c 16 KB

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