scsi_dh_rdac.c 16 KB

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