scsi_dh_emc.c 19 KB

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