scsi_dh_rdac.c 16 KB

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