scsi_dh_emc.c 18 KB

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