scsi_dh_emc.c 17 KB

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