scsi_dh_rdac.c 16 KB

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