scsi_dh_emc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*
  2. * Target driver for EMC CLARiiON AX/CX-series hardware.
  3. * Based on code from Lars Marowsky-Bree <lmb@suse.de>
  4. * and Ed Goggin <egoggin@emc.com>.
  5. *
  6. * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  7. * Copyright (C) 2006 Mike Christie
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; see the file COPYING. If not, write to
  21. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <scsi/scsi.h>
  24. #include <scsi/scsi_eh.h>
  25. #include <scsi/scsi_dh.h>
  26. #include <scsi/scsi_device.h>
  27. #define CLARIION_NAME "emc"
  28. #define CLARIION_TRESPASS_PAGE 0x22
  29. #define CLARIION_BUFFER_SIZE 0xFC
  30. #define CLARIION_TIMEOUT (60 * HZ)
  31. #define CLARIION_RETRIES 3
  32. #define CLARIION_UNBOUND_LU -1
  33. #define CLARIION_SP_A 0
  34. #define CLARIION_SP_B 1
  35. /* Flags */
  36. #define CLARIION_SHORT_TRESPASS 1
  37. #define CLARIION_HONOR_RESERVATIONS 2
  38. /* LUN states */
  39. #define CLARIION_LUN_UNINITIALIZED -1
  40. #define CLARIION_LUN_UNBOUND 0
  41. #define CLARIION_LUN_BOUND 1
  42. #define CLARIION_LUN_OWNED 2
  43. static unsigned char long_trespass[] = {
  44. 0, 0, 0, 0, 0, 0, 0, 0,
  45. CLARIION_TRESPASS_PAGE, /* Page code */
  46. 0x09, /* Page length - 2 */
  47. 0x01, /* Trespass code */
  48. 0xff, 0xff, /* Trespass target */
  49. 0, 0, 0, 0, 0, 0 /* Reserved bytes / unknown */
  50. };
  51. static unsigned char short_trespass[] = {
  52. 0, 0, 0, 0,
  53. CLARIION_TRESPASS_PAGE, /* Page code */
  54. 0x02, /* Page length - 2 */
  55. 0x01, /* Trespass code */
  56. 0xff, /* Trespass target */
  57. };
  58. static const char * lun_state[] =
  59. {
  60. "not bound",
  61. "bound",
  62. "owned",
  63. };
  64. struct clariion_dh_data {
  65. /*
  66. * Flags:
  67. * CLARIION_SHORT_TRESPASS
  68. * Use short trespass command (FC-series) or the long version
  69. * (default for AX/CX CLARiiON arrays).
  70. *
  71. * CLARIION_HONOR_RESERVATIONS
  72. * Whether or not (default) to honor SCSI reservations when
  73. * initiating a switch-over.
  74. */
  75. unsigned flags;
  76. /*
  77. * I/O buffer for both MODE_SELECT and INQUIRY commands.
  78. */
  79. unsigned char buffer[CLARIION_BUFFER_SIZE];
  80. /*
  81. * SCSI sense buffer for commands -- assumes serial issuance
  82. * and completion sequence of all commands for same multipath.
  83. */
  84. unsigned char sense[SCSI_SENSE_BUFFERSIZE];
  85. unsigned int senselen;
  86. /*
  87. * LUN state
  88. */
  89. int lun_state;
  90. /*
  91. * SP Port number
  92. */
  93. int port;
  94. /*
  95. * which SP (A=0,B=1,UNBOUND=-1) is the default SP for this
  96. * path's mapped LUN
  97. */
  98. int default_sp;
  99. /*
  100. * which SP (A=0,B=1,UNBOUND=-1) is the active SP for this
  101. * path's mapped LUN
  102. */
  103. int current_sp;
  104. };
  105. static inline struct clariion_dh_data
  106. *get_clariion_data(struct scsi_device *sdev)
  107. {
  108. struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
  109. BUG_ON(scsi_dh_data == NULL);
  110. return ((struct clariion_dh_data *) scsi_dh_data->buf);
  111. }
  112. /*
  113. * Parse MODE_SELECT cmd reply.
  114. */
  115. static int trespass_endio(struct scsi_device *sdev, char *sense)
  116. {
  117. int err = SCSI_DH_IO;
  118. struct scsi_sense_hdr sshdr;
  119. if (!scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr)) {
  120. sdev_printk(KERN_ERR, sdev, "%s: Found valid sense data 0x%2x, "
  121. "0x%2x, 0x%2x while sending CLARiiON trespass "
  122. "command.\n", CLARIION_NAME, sshdr.sense_key,
  123. sshdr.asc, sshdr.ascq);
  124. if ((sshdr.sense_key == 0x05) && (sshdr.asc == 0x04) &&
  125. (sshdr.ascq == 0x00)) {
  126. /*
  127. * Array based copy in progress -- do not send
  128. * mode_select or copy will be aborted mid-stream.
  129. */
  130. sdev_printk(KERN_INFO, sdev, "%s: Array Based Copy in "
  131. "progress while sending CLARiiON trespass "
  132. "command.\n", CLARIION_NAME);
  133. err = SCSI_DH_DEV_TEMP_BUSY;
  134. } else if ((sshdr.sense_key == 0x02) && (sshdr.asc == 0x04) &&
  135. (sshdr.ascq == 0x03)) {
  136. /*
  137. * LUN Not Ready - Manual Intervention Required
  138. * indicates in-progress ucode upgrade (NDU).
  139. */
  140. sdev_printk(KERN_INFO, sdev, "%s: Detected in-progress "
  141. "ucode upgrade NDU operation while sending "
  142. "CLARiiON trespass command.\n", CLARIION_NAME);
  143. err = SCSI_DH_DEV_TEMP_BUSY;
  144. } else
  145. err = SCSI_DH_DEV_FAILED;
  146. } else {
  147. sdev_printk(KERN_INFO, sdev,
  148. "%s: failed to send MODE SELECT, no sense available\n",
  149. CLARIION_NAME);
  150. }
  151. return err;
  152. }
  153. static int parse_sp_info_reply(struct scsi_device *sdev,
  154. struct clariion_dh_data *csdev)
  155. {
  156. int err = SCSI_DH_OK;
  157. /* check for in-progress ucode upgrade (NDU) */
  158. if (csdev->buffer[48] != 0) {
  159. sdev_printk(KERN_NOTICE, sdev, "%s: Detected in-progress "
  160. "ucode upgrade NDU operation while finding "
  161. "current active SP.", CLARIION_NAME);
  162. err = SCSI_DH_DEV_TEMP_BUSY;
  163. goto out;
  164. }
  165. if (csdev->buffer[4] > 2) {
  166. /* Invalid buffer format */
  167. sdev_printk(KERN_NOTICE, sdev,
  168. "%s: invalid VPD page 0xC0 format\n",
  169. CLARIION_NAME);
  170. err = SCSI_DH_NOSYS;
  171. goto out;
  172. }
  173. switch (csdev->buffer[28] & 0x0f) {
  174. case 6:
  175. sdev_printk(KERN_NOTICE, sdev,
  176. "%s: ALUA failover mode detected\n",
  177. CLARIION_NAME);
  178. break;
  179. case 4:
  180. /* Linux failover */
  181. break;
  182. default:
  183. sdev_printk(KERN_WARNING, sdev,
  184. "%s: Invalid failover mode %d\n",
  185. CLARIION_NAME, csdev->buffer[28] & 0x0f);
  186. err = SCSI_DH_NOSYS;
  187. goto out;
  188. }
  189. csdev->default_sp = csdev->buffer[5];
  190. csdev->lun_state = csdev->buffer[4];
  191. csdev->current_sp = csdev->buffer[8];
  192. csdev->port = csdev->buffer[7];
  193. out:
  194. return err;
  195. }
  196. #define emc_default_str "FC (Legacy)"
  197. static char * parse_sp_model(struct scsi_device *sdev, unsigned char *buffer)
  198. {
  199. unsigned char len = buffer[4] + 5;
  200. char *sp_model = NULL;
  201. unsigned char sp_len, serial_len;
  202. if (len < 160) {
  203. sdev_printk(KERN_WARNING, sdev,
  204. "%s: Invalid information section length %d\n",
  205. CLARIION_NAME, len);
  206. /* Check for old FC arrays */
  207. if (!strncmp(buffer + 8, "DGC", 3)) {
  208. /* Old FC array, not supporting extended information */
  209. sp_model = emc_default_str;
  210. }
  211. goto out;
  212. }
  213. /*
  214. * Parse extended information for SP model number
  215. */
  216. serial_len = buffer[160];
  217. if (serial_len == 0 || serial_len + 161 > len) {
  218. sdev_printk(KERN_WARNING, sdev,
  219. "%s: Invalid array serial number length %d\n",
  220. CLARIION_NAME, serial_len);
  221. goto out;
  222. }
  223. sp_len = buffer[99];
  224. if (sp_len == 0 || serial_len + sp_len + 161 > len) {
  225. sdev_printk(KERN_WARNING, sdev,
  226. "%s: Invalid model number length %d\n",
  227. CLARIION_NAME, sp_len);
  228. goto out;
  229. }
  230. sp_model = &buffer[serial_len + 161];
  231. /* Strip whitespace at the end */
  232. while (sp_len > 1 && sp_model[sp_len - 1] == ' ')
  233. sp_len--;
  234. sp_model[sp_len] = '\0';
  235. out:
  236. return sp_model;
  237. }
  238. /*
  239. * Get block request for REQ_BLOCK_PC command issued to path. Currently
  240. * limited to MODE_SELECT (trespass) and INQUIRY (VPD page 0xC0) commands.
  241. *
  242. * Uses data and sense buffers in hardware handler context structure and
  243. * assumes serial servicing of commands, both issuance and completion.
  244. */
  245. static struct request *get_req(struct scsi_device *sdev, int cmd,
  246. unsigned char *buffer)
  247. {
  248. struct request *rq;
  249. int len = 0;
  250. rq = blk_get_request(sdev->request_queue,
  251. (cmd == MODE_SELECT) ? WRITE : READ, GFP_NOIO);
  252. if (!rq) {
  253. sdev_printk(KERN_INFO, sdev, "get_req: blk_get_request failed");
  254. return NULL;
  255. }
  256. rq->cmd_len = COMMAND_SIZE(cmd);
  257. rq->cmd[0] = cmd;
  258. switch (cmd) {
  259. case MODE_SELECT:
  260. len = sizeof(short_trespass);
  261. rq->cmd_flags |= REQ_RW;
  262. rq->cmd[1] = 0x10;
  263. break;
  264. case MODE_SELECT_10:
  265. len = sizeof(long_trespass);
  266. rq->cmd_flags |= REQ_RW;
  267. rq->cmd[1] = 0x10;
  268. break;
  269. case INQUIRY:
  270. len = CLARIION_BUFFER_SIZE;
  271. memset(buffer, 0, len);
  272. break;
  273. default:
  274. BUG_ON(1);
  275. break;
  276. }
  277. rq->cmd[4] = len;
  278. rq->cmd_type = REQ_TYPE_BLOCK_PC;
  279. rq->cmd_flags |= REQ_FAILFAST;
  280. rq->timeout = CLARIION_TIMEOUT;
  281. rq->retries = CLARIION_RETRIES;
  282. if (blk_rq_map_kern(rq->q, rq, buffer, len, GFP_NOIO)) {
  283. blk_put_request(rq);
  284. return NULL;
  285. }
  286. return rq;
  287. }
  288. static int send_inquiry_cmd(struct scsi_device *sdev, int page,
  289. struct clariion_dh_data *csdev)
  290. {
  291. struct request *rq = get_req(sdev, INQUIRY, csdev->buffer);
  292. int err;
  293. if (!rq)
  294. return SCSI_DH_RES_TEMP_UNAVAIL;
  295. rq->sense = csdev->sense;
  296. memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
  297. rq->sense_len = csdev->senselen = 0;
  298. rq->cmd[0] = INQUIRY;
  299. if (page != 0) {
  300. rq->cmd[1] = 1;
  301. rq->cmd[2] = page;
  302. }
  303. err = blk_execute_rq(sdev->request_queue, NULL, rq, 1);
  304. if (err == -EIO) {
  305. sdev_printk(KERN_INFO, sdev,
  306. "%s: failed to send %s INQUIRY: %x\n",
  307. CLARIION_NAME, page?"EVPD":"standard",
  308. rq->errors);
  309. csdev->senselen = rq->sense_len;
  310. err = SCSI_DH_IO;
  311. }
  312. blk_put_request(rq);
  313. return err;
  314. }
  315. static int send_trespass_cmd(struct scsi_device *sdev,
  316. struct clariion_dh_data *csdev)
  317. {
  318. struct request *rq;
  319. unsigned char *page22;
  320. int err, len, cmd;
  321. if (csdev->flags & CLARIION_SHORT_TRESPASS) {
  322. page22 = short_trespass;
  323. if (!(csdev->flags & CLARIION_HONOR_RESERVATIONS))
  324. /* Set Honor Reservations bit */
  325. page22[6] |= 0x80;
  326. len = sizeof(short_trespass);
  327. cmd = MODE_SELECT;
  328. } else {
  329. page22 = long_trespass;
  330. if (!(csdev->flags & CLARIION_HONOR_RESERVATIONS))
  331. /* Set Honor Reservations bit */
  332. page22[10] |= 0x80;
  333. len = sizeof(long_trespass);
  334. cmd = MODE_SELECT_10;
  335. }
  336. BUG_ON((len > CLARIION_BUFFER_SIZE));
  337. memcpy(csdev->buffer, page22, len);
  338. rq = get_req(sdev, cmd, csdev->buffer);
  339. if (!rq)
  340. return SCSI_DH_RES_TEMP_UNAVAIL;
  341. rq->sense = csdev->sense;
  342. memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
  343. rq->sense_len = csdev->senselen = 0;
  344. err = blk_execute_rq(sdev->request_queue, NULL, rq, 1);
  345. if (err == -EIO) {
  346. if (rq->sense_len) {
  347. err = trespass_endio(sdev, csdev->sense);
  348. } else {
  349. sdev_printk(KERN_INFO, sdev,
  350. "%s: failed to send MODE SELECT: %x\n",
  351. CLARIION_NAME, rq->errors);
  352. }
  353. }
  354. blk_put_request(rq);
  355. return err;
  356. }
  357. static int clariion_check_sense(struct scsi_device *sdev,
  358. struct scsi_sense_hdr *sense_hdr)
  359. {
  360. switch (sense_hdr->sense_key) {
  361. case NOT_READY:
  362. if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x03)
  363. /*
  364. * LUN Not Ready - Manual Intervention Required
  365. * indicates this is a passive path.
  366. *
  367. * FIXME: However, if this is seen and EVPD C0
  368. * indicates that this is due to a NDU in
  369. * progress, we should set FAIL_PATH too.
  370. * This indicates we might have to do a SCSI
  371. * inquiry in the end_io path. Ugh.
  372. *
  373. * Can return FAILED only when we want the error
  374. * recovery process to kick in.
  375. */
  376. return SUCCESS;
  377. break;
  378. case ILLEGAL_REQUEST:
  379. if (sense_hdr->asc == 0x25 && sense_hdr->ascq == 0x01)
  380. /*
  381. * An array based copy is in progress. Do not
  382. * fail the path, do not bypass to another PG,
  383. * do not retry. Fail the IO immediately.
  384. * (Actually this is the same conclusion as in
  385. * the default handler, but lets make sure.)
  386. *
  387. * Can return FAILED only when we want the error
  388. * recovery process to kick in.
  389. */
  390. return SUCCESS;
  391. break;
  392. case UNIT_ATTENTION:
  393. if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
  394. /*
  395. * Unit Attention Code. This is the first IO
  396. * to the new path, so just retry.
  397. */
  398. return ADD_TO_MLQUEUE;
  399. break;
  400. }
  401. return SCSI_RETURN_NOT_HANDLED;
  402. }
  403. static int clariion_prep_fn(struct scsi_device *sdev, struct request *req)
  404. {
  405. struct clariion_dh_data *h = get_clariion_data(sdev);
  406. int ret = BLKPREP_OK;
  407. if (h->lun_state != CLARIION_LUN_OWNED) {
  408. ret = BLKPREP_KILL;
  409. req->cmd_flags |= REQ_QUIET;
  410. }
  411. return ret;
  412. }
  413. static int clariion_std_inquiry(struct scsi_device *sdev,
  414. struct clariion_dh_data *csdev)
  415. {
  416. int err;
  417. char *sp_model;
  418. err = send_inquiry_cmd(sdev, 0, csdev);
  419. if (err != SCSI_DH_OK && csdev->senselen) {
  420. struct scsi_sense_hdr sshdr;
  421. if (scsi_normalize_sense(csdev->sense, SCSI_SENSE_BUFFERSIZE,
  422. &sshdr)) {
  423. sdev_printk(KERN_ERR, sdev, "%s: INQUIRY sense code "
  424. "%02x/%02x/%02x\n", CLARIION_NAME,
  425. sshdr.sense_key, sshdr.asc, sshdr.ascq);
  426. }
  427. err = SCSI_DH_IO;
  428. goto out;
  429. }
  430. sp_model = parse_sp_model(sdev, csdev->buffer);
  431. if (!sp_model) {
  432. err = SCSI_DH_DEV_UNSUPP;
  433. goto out;
  434. }
  435. /*
  436. * FC Series arrays do not support long trespass
  437. */
  438. if (!strlen(sp_model) || !strncmp(sp_model, "FC",2))
  439. csdev->flags |= CLARIION_SHORT_TRESPASS;
  440. sdev_printk(KERN_INFO, sdev,
  441. "%s: detected Clariion %s, flags %x\n",
  442. CLARIION_NAME, sp_model, csdev->flags);
  443. out:
  444. return err;
  445. }
  446. static int clariion_send_inquiry(struct scsi_device *sdev,
  447. struct clariion_dh_data *csdev)
  448. {
  449. int err, retry = CLARIION_RETRIES;
  450. retry:
  451. err = send_inquiry_cmd(sdev, 0xC0, csdev);
  452. if (err != SCSI_DH_OK && csdev->senselen) {
  453. struct scsi_sense_hdr sshdr;
  454. err = scsi_normalize_sense(csdev->sense, SCSI_SENSE_BUFFERSIZE,
  455. &sshdr);
  456. if (!err)
  457. return SCSI_DH_IO;
  458. err = clariion_check_sense(sdev, &sshdr);
  459. if (retry > 0 && err == ADD_TO_MLQUEUE) {
  460. retry--;
  461. goto retry;
  462. }
  463. sdev_printk(KERN_ERR, sdev, "%s: INQUIRY sense code "
  464. "%02x/%02x/%02x\n", CLARIION_NAME,
  465. sshdr.sense_key, sshdr.asc, sshdr.ascq);
  466. err = SCSI_DH_IO;
  467. } else {
  468. err = parse_sp_info_reply(sdev, csdev);
  469. }
  470. return err;
  471. }
  472. static int clariion_activate(struct scsi_device *sdev)
  473. {
  474. struct clariion_dh_data *csdev = get_clariion_data(sdev);
  475. int result;
  476. result = clariion_send_inquiry(sdev, csdev);
  477. if (result != SCSI_DH_OK)
  478. goto done;
  479. if (csdev->lun_state == CLARIION_LUN_OWNED)
  480. goto done;
  481. result = send_trespass_cmd(sdev, csdev);
  482. if (result != SCSI_DH_OK)
  483. goto done;
  484. sdev_printk(KERN_INFO, sdev,"%s: %s trespass command sent\n",
  485. CLARIION_NAME,
  486. csdev->flags&CLARIION_SHORT_TRESPASS?"short":"long" );
  487. /* Update status */
  488. result = clariion_send_inquiry(sdev, csdev);
  489. if (result != SCSI_DH_OK)
  490. goto done;
  491. done:
  492. sdev_printk(KERN_INFO, sdev,
  493. "%s: at SP %c Port %d (%s, default SP %c)\n",
  494. CLARIION_NAME, csdev->current_sp + 'A',
  495. csdev->port, lun_state[csdev->lun_state],
  496. csdev->default_sp + 'A');
  497. return result;
  498. }
  499. static const struct scsi_dh_devlist clariion_dev_list[] = {
  500. {"DGC", "RAID"},
  501. {"DGC", "DISK"},
  502. {"DGC", "VRAID"},
  503. {NULL, NULL},
  504. };
  505. static int clariion_bus_attach(struct scsi_device *sdev);
  506. static void clariion_bus_detach(struct scsi_device *sdev);
  507. static struct scsi_device_handler clariion_dh = {
  508. .name = CLARIION_NAME,
  509. .module = THIS_MODULE,
  510. .devlist = clariion_dev_list,
  511. .attach = clariion_bus_attach,
  512. .detach = clariion_bus_detach,
  513. .check_sense = clariion_check_sense,
  514. .activate = clariion_activate,
  515. .prep_fn = clariion_prep_fn,
  516. };
  517. /*
  518. * TODO: need some interface so we can set trespass values
  519. */
  520. static int clariion_bus_attach(struct scsi_device *sdev)
  521. {
  522. struct scsi_dh_data *scsi_dh_data;
  523. struct clariion_dh_data *h;
  524. unsigned long flags;
  525. int err;
  526. scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
  527. + sizeof(*h) , GFP_KERNEL);
  528. if (!scsi_dh_data) {
  529. sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
  530. CLARIION_NAME);
  531. return -ENOMEM;
  532. }
  533. scsi_dh_data->scsi_dh = &clariion_dh;
  534. h = (struct clariion_dh_data *) scsi_dh_data->buf;
  535. h->lun_state = CLARIION_LUN_UNINITIALIZED;
  536. h->default_sp = CLARIION_UNBOUND_LU;
  537. h->current_sp = CLARIION_UNBOUND_LU;
  538. err = clariion_std_inquiry(sdev, h);
  539. if (err != SCSI_DH_OK)
  540. goto failed;
  541. err = clariion_send_inquiry(sdev, h);
  542. if (err != SCSI_DH_OK)
  543. goto failed;
  544. if (!try_module_get(THIS_MODULE))
  545. goto failed;
  546. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  547. sdev->scsi_dh_data = scsi_dh_data;
  548. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  549. sdev_printk(KERN_INFO, sdev,
  550. "%s: connected to SP %c Port %d (%s, default SP %c)\n",
  551. CLARIION_NAME, h->current_sp + 'A',
  552. h->port, lun_state[h->lun_state],
  553. h->default_sp + 'A');
  554. return 0;
  555. failed:
  556. kfree(scsi_dh_data);
  557. sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
  558. CLARIION_NAME);
  559. return -EINVAL;
  560. }
  561. static void clariion_bus_detach(struct scsi_device *sdev)
  562. {
  563. struct scsi_dh_data *scsi_dh_data;
  564. unsigned long flags;
  565. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  566. scsi_dh_data = sdev->scsi_dh_data;
  567. sdev->scsi_dh_data = NULL;
  568. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  569. sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n",
  570. CLARIION_NAME);
  571. kfree(scsi_dh_data);
  572. module_put(THIS_MODULE);
  573. }
  574. static int __init clariion_init(void)
  575. {
  576. int r;
  577. r = scsi_register_device_handler(&clariion_dh);
  578. if (r != 0)
  579. printk(KERN_ERR "%s: Failed to register scsi device handler.",
  580. CLARIION_NAME);
  581. return r;
  582. }
  583. static void __exit clariion_exit(void)
  584. {
  585. scsi_unregister_device_handler(&clariion_dh);
  586. }
  587. module_init(clariion_init);
  588. module_exit(clariion_exit);
  589. MODULE_DESCRIPTION("EMC CX/AX/FC-family driver");
  590. MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, Chandra Seetharaman <sekharan@us.ibm.com>");
  591. MODULE_LICENSE("GPL");