target_core_xcopy.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. /*******************************************************************************
  2. * Filename: target_core_xcopy.c
  3. *
  4. * This file contains support for SPC-4 Extended-Copy offload with generic
  5. * TCM backends.
  6. *
  7. * Copyright (c) 2011-2013 Datera, Inc. All rights reserved.
  8. *
  9. * Author:
  10. * Nicholas A. Bellinger <nab@daterainc.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. ******************************************************************************/
  23. #include <linux/slab.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/list.h>
  26. #include <linux/configfs.h>
  27. #include <linux/ratelimit.h>
  28. #include <scsi/scsi_proto.h>
  29. #include <asm/unaligned.h>
  30. #include <target/target_core_base.h>
  31. #include <target/target_core_backend.h>
  32. #include <target/target_core_fabric.h>
  33. #include "target_core_internal.h"
  34. #include "target_core_pr.h"
  35. #include "target_core_ua.h"
  36. #include "target_core_xcopy.h"
  37. static struct workqueue_struct *xcopy_wq = NULL;
  38. static int target_xcopy_gen_naa_ieee(struct se_device *dev, unsigned char *buf)
  39. {
  40. int off = 0;
  41. buf[off++] = (0x6 << 4);
  42. buf[off++] = 0x01;
  43. buf[off++] = 0x40;
  44. buf[off] = (0x5 << 4);
  45. spc_parse_naa_6h_vendor_specific(dev, &buf[off]);
  46. return 0;
  47. }
  48. static int target_xcopy_locate_se_dev_e4(const unsigned char *dev_wwn,
  49. struct se_device **found_dev)
  50. {
  51. struct se_device *se_dev;
  52. unsigned char tmp_dev_wwn[XCOPY_NAA_IEEE_REGEX_LEN];
  53. int rc;
  54. mutex_lock(&g_device_mutex);
  55. list_for_each_entry(se_dev, &g_device_list, g_dev_node) {
  56. if (!se_dev->dev_attrib.emulate_3pc)
  57. continue;
  58. memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN);
  59. target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]);
  60. rc = memcmp(&tmp_dev_wwn[0], dev_wwn, XCOPY_NAA_IEEE_REGEX_LEN);
  61. if (rc != 0)
  62. continue;
  63. *found_dev = se_dev;
  64. pr_debug("XCOPY 0xe4: located se_dev: %p\n", se_dev);
  65. rc = target_depend_item(&se_dev->dev_group.cg_item);
  66. if (rc != 0) {
  67. pr_err("configfs_depend_item attempt failed:"
  68. " %d for se_dev: %p\n", rc, se_dev);
  69. mutex_unlock(&g_device_mutex);
  70. return rc;
  71. }
  72. pr_debug("Called configfs_depend_item for se_dev: %p"
  73. " se_dev->se_dev_group: %p\n", se_dev,
  74. &se_dev->dev_group);
  75. mutex_unlock(&g_device_mutex);
  76. return 0;
  77. }
  78. mutex_unlock(&g_device_mutex);
  79. pr_debug_ratelimited("Unable to locate 0xe4 descriptor for EXTENDED_COPY\n");
  80. return -EINVAL;
  81. }
  82. static int target_xcopy_parse_tiddesc_e4(struct se_cmd *se_cmd, struct xcopy_op *xop,
  83. unsigned char *p, unsigned short cscd_index)
  84. {
  85. unsigned char *desc = p;
  86. unsigned short ript;
  87. u8 desig_len;
  88. /*
  89. * Extract RELATIVE INITIATOR PORT IDENTIFIER
  90. */
  91. ript = get_unaligned_be16(&desc[2]);
  92. pr_debug("XCOPY 0xe4: RELATIVE INITIATOR PORT IDENTIFIER: %hu\n", ript);
  93. /*
  94. * Check for supported code set, association, and designator type
  95. */
  96. if ((desc[4] & 0x0f) != 0x1) {
  97. pr_err("XCOPY 0xe4: code set of non binary type not supported\n");
  98. return -EINVAL;
  99. }
  100. if ((desc[5] & 0x30) != 0x00) {
  101. pr_err("XCOPY 0xe4: association other than LUN not supported\n");
  102. return -EINVAL;
  103. }
  104. if ((desc[5] & 0x0f) != 0x3) {
  105. pr_err("XCOPY 0xe4: designator type unsupported: 0x%02x\n",
  106. (desc[5] & 0x0f));
  107. return -EINVAL;
  108. }
  109. /*
  110. * Check for matching 16 byte length for NAA IEEE Registered Extended
  111. * Assigned designator
  112. */
  113. desig_len = desc[7];
  114. if (desig_len != 16) {
  115. pr_err("XCOPY 0xe4: invalid desig_len: %d\n", (int)desig_len);
  116. return -EINVAL;
  117. }
  118. pr_debug("XCOPY 0xe4: desig_len: %d\n", (int)desig_len);
  119. /*
  120. * Check for NAA IEEE Registered Extended Assigned header..
  121. */
  122. if ((desc[8] & 0xf0) != 0x60) {
  123. pr_err("XCOPY 0xe4: Unsupported DESIGNATOR TYPE: 0x%02x\n",
  124. (desc[8] & 0xf0));
  125. return -EINVAL;
  126. }
  127. if (cscd_index != xop->stdi && cscd_index != xop->dtdi) {
  128. pr_debug("XCOPY 0xe4: ignoring CSCD entry %d - neither src nor "
  129. "dest\n", cscd_index);
  130. return 0;
  131. }
  132. if (cscd_index == xop->stdi) {
  133. memcpy(&xop->src_tid_wwn[0], &desc[8], XCOPY_NAA_IEEE_REGEX_LEN);
  134. /*
  135. * Determine if the source designator matches the local device
  136. */
  137. if (!memcmp(&xop->local_dev_wwn[0], &xop->src_tid_wwn[0],
  138. XCOPY_NAA_IEEE_REGEX_LEN)) {
  139. xop->op_origin = XCOL_SOURCE_RECV_OP;
  140. xop->src_dev = se_cmd->se_dev;
  141. pr_debug("XCOPY 0xe4: Set xop->src_dev %p from source"
  142. " received xop\n", xop->src_dev);
  143. }
  144. }
  145. if (cscd_index == xop->dtdi) {
  146. memcpy(&xop->dst_tid_wwn[0], &desc[8], XCOPY_NAA_IEEE_REGEX_LEN);
  147. /*
  148. * Determine if the destination designator matches the local
  149. * device. If @cscd_index corresponds to both source (stdi) and
  150. * destination (dtdi), or dtdi comes after stdi, then
  151. * XCOL_DEST_RECV_OP wins.
  152. */
  153. if (!memcmp(&xop->local_dev_wwn[0], &xop->dst_tid_wwn[0],
  154. XCOPY_NAA_IEEE_REGEX_LEN)) {
  155. xop->op_origin = XCOL_DEST_RECV_OP;
  156. xop->dst_dev = se_cmd->se_dev;
  157. pr_debug("XCOPY 0xe4: Set xop->dst_dev: %p from destination"
  158. " received xop\n", xop->dst_dev);
  159. }
  160. }
  161. return 0;
  162. }
  163. static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd,
  164. struct xcopy_op *xop, unsigned char *p,
  165. unsigned short tdll, sense_reason_t *sense_ret)
  166. {
  167. struct se_device *local_dev = se_cmd->se_dev;
  168. unsigned char *desc = p;
  169. int offset = tdll % XCOPY_TARGET_DESC_LEN, rc;
  170. unsigned short cscd_index = 0;
  171. unsigned short start = 0;
  172. *sense_ret = TCM_INVALID_PARAMETER_LIST;
  173. if (offset != 0) {
  174. pr_err("XCOPY target descriptor list length is not"
  175. " multiple of %d\n", XCOPY_TARGET_DESC_LEN);
  176. *sense_ret = TCM_UNSUPPORTED_TARGET_DESC_TYPE_CODE;
  177. return -EINVAL;
  178. }
  179. if (tdll > RCR_OP_MAX_TARGET_DESC_COUNT * XCOPY_TARGET_DESC_LEN) {
  180. pr_err("XCOPY target descriptor supports a maximum"
  181. " two src/dest descriptors, tdll: %hu too large..\n", tdll);
  182. /* spc4r37 6.4.3.4 CSCD DESCRIPTOR LIST LENGTH field */
  183. *sense_ret = TCM_TOO_MANY_TARGET_DESCS;
  184. return -EINVAL;
  185. }
  186. /*
  187. * Generate an IEEE Registered Extended designator based upon the
  188. * se_device the XCOPY was received upon..
  189. */
  190. memset(&xop->local_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN);
  191. target_xcopy_gen_naa_ieee(local_dev, &xop->local_dev_wwn[0]);
  192. while (start < tdll) {
  193. /*
  194. * Check target descriptor identification with 0xE4 type, and
  195. * compare the current index with the CSCD descriptor IDs in
  196. * the segment descriptor. Use VPD 0x83 WWPN matching ..
  197. */
  198. switch (desc[0]) {
  199. case 0xe4:
  200. rc = target_xcopy_parse_tiddesc_e4(se_cmd, xop,
  201. &desc[0], cscd_index);
  202. if (rc != 0)
  203. goto out;
  204. start += XCOPY_TARGET_DESC_LEN;
  205. desc += XCOPY_TARGET_DESC_LEN;
  206. cscd_index++;
  207. break;
  208. default:
  209. pr_err("XCOPY unsupported descriptor type code:"
  210. " 0x%02x\n", desc[0]);
  211. *sense_ret = TCM_UNSUPPORTED_TARGET_DESC_TYPE_CODE;
  212. goto out;
  213. }
  214. }
  215. switch (xop->op_origin) {
  216. case XCOL_SOURCE_RECV_OP:
  217. rc = target_xcopy_locate_se_dev_e4(xop->dst_tid_wwn,
  218. &xop->dst_dev);
  219. break;
  220. case XCOL_DEST_RECV_OP:
  221. rc = target_xcopy_locate_se_dev_e4(xop->src_tid_wwn,
  222. &xop->src_dev);
  223. break;
  224. default:
  225. pr_err("XCOPY CSCD descriptor IDs not found in CSCD list - "
  226. "stdi: %hu dtdi: %hu\n", xop->stdi, xop->dtdi);
  227. rc = -EINVAL;
  228. break;
  229. }
  230. /*
  231. * If a matching IEEE NAA 0x83 descriptor for the requested device
  232. * is not located on this node, return COPY_ABORTED with ASQ/ASQC
  233. * 0x0d/0x02 - COPY_TARGET_DEVICE_NOT_REACHABLE to request the
  234. * initiator to fall back to normal copy method.
  235. */
  236. if (rc < 0) {
  237. *sense_ret = TCM_COPY_TARGET_DEVICE_NOT_REACHABLE;
  238. goto out;
  239. }
  240. pr_debug("XCOPY TGT desc: Source dev: %p NAA IEEE WWN: 0x%16phN\n",
  241. xop->src_dev, &xop->src_tid_wwn[0]);
  242. pr_debug("XCOPY TGT desc: Dest dev: %p NAA IEEE WWN: 0x%16phN\n",
  243. xop->dst_dev, &xop->dst_tid_wwn[0]);
  244. return cscd_index;
  245. out:
  246. return -EINVAL;
  247. }
  248. static int target_xcopy_parse_segdesc_02(struct se_cmd *se_cmd, struct xcopy_op *xop,
  249. unsigned char *p)
  250. {
  251. unsigned char *desc = p;
  252. int dc = (desc[1] & 0x02);
  253. unsigned short desc_len;
  254. desc_len = get_unaligned_be16(&desc[2]);
  255. if (desc_len != 0x18) {
  256. pr_err("XCOPY segment desc 0x02: Illegal desc_len:"
  257. " %hu\n", desc_len);
  258. return -EINVAL;
  259. }
  260. xop->stdi = get_unaligned_be16(&desc[4]);
  261. xop->dtdi = get_unaligned_be16(&desc[6]);
  262. if (xop->stdi > XCOPY_CSCD_DESC_ID_LIST_OFF_MAX ||
  263. xop->dtdi > XCOPY_CSCD_DESC_ID_LIST_OFF_MAX) {
  264. pr_err("XCOPY segment desc 0x02: unsupported CSCD ID > 0x%x; stdi: %hu dtdi: %hu\n",
  265. XCOPY_CSCD_DESC_ID_LIST_OFF_MAX, xop->stdi, xop->dtdi);
  266. return -EINVAL;
  267. }
  268. pr_debug("XCOPY seg desc 0x02: desc_len: %hu stdi: %hu dtdi: %hu, DC: %d\n",
  269. desc_len, xop->stdi, xop->dtdi, dc);
  270. xop->nolb = get_unaligned_be16(&desc[10]);
  271. xop->src_lba = get_unaligned_be64(&desc[12]);
  272. xop->dst_lba = get_unaligned_be64(&desc[20]);
  273. pr_debug("XCOPY seg desc 0x02: nolb: %hu src_lba: %llu dst_lba: %llu\n",
  274. xop->nolb, (unsigned long long)xop->src_lba,
  275. (unsigned long long)xop->dst_lba);
  276. if (dc != 0) {
  277. xop->dbl = (desc[29] & 0xff) << 16;
  278. xop->dbl |= (desc[30] & 0xff) << 8;
  279. xop->dbl |= desc[31] & 0xff;
  280. pr_debug("XCOPY seg desc 0x02: DC=1 w/ dbl: %u\n", xop->dbl);
  281. }
  282. return 0;
  283. }
  284. static int target_xcopy_parse_segment_descriptors(struct se_cmd *se_cmd,
  285. struct xcopy_op *xop, unsigned char *p,
  286. unsigned int sdll, sense_reason_t *sense_ret)
  287. {
  288. unsigned char *desc = p;
  289. unsigned int start = 0;
  290. int offset = sdll % XCOPY_SEGMENT_DESC_LEN, rc, ret = 0;
  291. *sense_ret = TCM_INVALID_PARAMETER_LIST;
  292. if (offset != 0) {
  293. pr_err("XCOPY segment descriptor list length is not"
  294. " multiple of %d\n", XCOPY_SEGMENT_DESC_LEN);
  295. *sense_ret = TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE;
  296. return -EINVAL;
  297. }
  298. if (sdll > RCR_OP_MAX_SG_DESC_COUNT * XCOPY_SEGMENT_DESC_LEN) {
  299. pr_err("XCOPY supports %u segment descriptor(s), sdll: %u too"
  300. " large..\n", RCR_OP_MAX_SG_DESC_COUNT, sdll);
  301. /* spc4r37 6.4.3.5 SEGMENT DESCRIPTOR LIST LENGTH field */
  302. *sense_ret = TCM_TOO_MANY_SEGMENT_DESCS;
  303. return -EINVAL;
  304. }
  305. while (start < sdll) {
  306. /*
  307. * Check segment descriptor type code for block -> block
  308. */
  309. switch (desc[0]) {
  310. case 0x02:
  311. rc = target_xcopy_parse_segdesc_02(se_cmd, xop, desc);
  312. if (rc < 0)
  313. goto out;
  314. ret++;
  315. start += XCOPY_SEGMENT_DESC_LEN;
  316. desc += XCOPY_SEGMENT_DESC_LEN;
  317. break;
  318. default:
  319. pr_err("XCOPY unsupported segment descriptor"
  320. "type: 0x%02x\n", desc[0]);
  321. *sense_ret = TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE;
  322. goto out;
  323. }
  324. }
  325. return ret;
  326. out:
  327. return -EINVAL;
  328. }
  329. /*
  330. * Start xcopy_pt ops
  331. */
  332. struct xcopy_pt_cmd {
  333. bool remote_port;
  334. struct se_cmd se_cmd;
  335. struct xcopy_op *xcopy_op;
  336. struct completion xpt_passthrough_sem;
  337. unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
  338. };
  339. struct se_portal_group xcopy_pt_tpg;
  340. static struct se_session xcopy_pt_sess;
  341. static struct se_node_acl xcopy_pt_nacl;
  342. static char *xcopy_pt_get_fabric_name(void)
  343. {
  344. return "xcopy-pt";
  345. }
  346. static int xcopy_pt_get_cmd_state(struct se_cmd *se_cmd)
  347. {
  348. return 0;
  349. }
  350. static void xcopy_pt_undepend_remotedev(struct xcopy_op *xop)
  351. {
  352. struct se_device *remote_dev;
  353. if (xop->op_origin == XCOL_SOURCE_RECV_OP)
  354. remote_dev = xop->dst_dev;
  355. else
  356. remote_dev = xop->src_dev;
  357. pr_debug("Calling configfs_undepend_item for"
  358. " remote_dev: %p remote_dev->dev_group: %p\n",
  359. remote_dev, &remote_dev->dev_group.cg_item);
  360. target_undepend_item(&remote_dev->dev_group.cg_item);
  361. }
  362. static void xcopy_pt_release_cmd(struct se_cmd *se_cmd)
  363. {
  364. struct xcopy_pt_cmd *xpt_cmd = container_of(se_cmd,
  365. struct xcopy_pt_cmd, se_cmd);
  366. kfree(xpt_cmd);
  367. }
  368. static int xcopy_pt_check_stop_free(struct se_cmd *se_cmd)
  369. {
  370. struct xcopy_pt_cmd *xpt_cmd = container_of(se_cmd,
  371. struct xcopy_pt_cmd, se_cmd);
  372. complete(&xpt_cmd->xpt_passthrough_sem);
  373. return 0;
  374. }
  375. static int xcopy_pt_write_pending(struct se_cmd *se_cmd)
  376. {
  377. return 0;
  378. }
  379. static int xcopy_pt_write_pending_status(struct se_cmd *se_cmd)
  380. {
  381. return 0;
  382. }
  383. static int xcopy_pt_queue_data_in(struct se_cmd *se_cmd)
  384. {
  385. return 0;
  386. }
  387. static int xcopy_pt_queue_status(struct se_cmd *se_cmd)
  388. {
  389. return 0;
  390. }
  391. static const struct target_core_fabric_ops xcopy_pt_tfo = {
  392. .get_fabric_name = xcopy_pt_get_fabric_name,
  393. .get_cmd_state = xcopy_pt_get_cmd_state,
  394. .release_cmd = xcopy_pt_release_cmd,
  395. .check_stop_free = xcopy_pt_check_stop_free,
  396. .write_pending = xcopy_pt_write_pending,
  397. .write_pending_status = xcopy_pt_write_pending_status,
  398. .queue_data_in = xcopy_pt_queue_data_in,
  399. .queue_status = xcopy_pt_queue_status,
  400. };
  401. /*
  402. * End xcopy_pt_ops
  403. */
  404. int target_xcopy_setup_pt(void)
  405. {
  406. xcopy_wq = alloc_workqueue("xcopy_wq", WQ_MEM_RECLAIM, 0);
  407. if (!xcopy_wq) {
  408. pr_err("Unable to allocate xcopy_wq\n");
  409. return -ENOMEM;
  410. }
  411. memset(&xcopy_pt_tpg, 0, sizeof(struct se_portal_group));
  412. INIT_LIST_HEAD(&xcopy_pt_tpg.se_tpg_node);
  413. INIT_LIST_HEAD(&xcopy_pt_tpg.acl_node_list);
  414. INIT_LIST_HEAD(&xcopy_pt_tpg.tpg_sess_list);
  415. xcopy_pt_tpg.se_tpg_tfo = &xcopy_pt_tfo;
  416. memset(&xcopy_pt_nacl, 0, sizeof(struct se_node_acl));
  417. INIT_LIST_HEAD(&xcopy_pt_nacl.acl_list);
  418. INIT_LIST_HEAD(&xcopy_pt_nacl.acl_sess_list);
  419. memset(&xcopy_pt_sess, 0, sizeof(struct se_session));
  420. INIT_LIST_HEAD(&xcopy_pt_sess.sess_list);
  421. INIT_LIST_HEAD(&xcopy_pt_sess.sess_acl_list);
  422. INIT_LIST_HEAD(&xcopy_pt_sess.sess_cmd_list);
  423. spin_lock_init(&xcopy_pt_sess.sess_cmd_lock);
  424. xcopy_pt_nacl.se_tpg = &xcopy_pt_tpg;
  425. xcopy_pt_nacl.nacl_sess = &xcopy_pt_sess;
  426. xcopy_pt_sess.se_tpg = &xcopy_pt_tpg;
  427. xcopy_pt_sess.se_node_acl = &xcopy_pt_nacl;
  428. return 0;
  429. }
  430. void target_xcopy_release_pt(void)
  431. {
  432. if (xcopy_wq)
  433. destroy_workqueue(xcopy_wq);
  434. }
  435. static void target_xcopy_setup_pt_port(
  436. struct xcopy_pt_cmd *xpt_cmd,
  437. struct xcopy_op *xop,
  438. bool remote_port)
  439. {
  440. struct se_cmd *ec_cmd = xop->xop_se_cmd;
  441. struct se_cmd *pt_cmd = &xpt_cmd->se_cmd;
  442. if (xop->op_origin == XCOL_SOURCE_RECV_OP) {
  443. /*
  444. * Honor destination port reservations for X-COPY PUSH emulation
  445. * when CDB is received on local source port, and READs blocks to
  446. * WRITE on remote destination port.
  447. */
  448. if (remote_port) {
  449. xpt_cmd->remote_port = remote_port;
  450. } else {
  451. pt_cmd->se_lun = ec_cmd->se_lun;
  452. pt_cmd->se_dev = ec_cmd->se_dev;
  453. pr_debug("Honoring local SRC port from ec_cmd->se_dev:"
  454. " %p\n", pt_cmd->se_dev);
  455. pt_cmd->se_lun = ec_cmd->se_lun;
  456. pr_debug("Honoring local SRC port from ec_cmd->se_lun: %p\n",
  457. pt_cmd->se_lun);
  458. }
  459. } else {
  460. /*
  461. * Honor source port reservation for X-COPY PULL emulation
  462. * when CDB is received on local desintation port, and READs
  463. * blocks from the remote source port to WRITE on local
  464. * destination port.
  465. */
  466. if (remote_port) {
  467. xpt_cmd->remote_port = remote_port;
  468. } else {
  469. pt_cmd->se_lun = ec_cmd->se_lun;
  470. pt_cmd->se_dev = ec_cmd->se_dev;
  471. pr_debug("Honoring local DST port from ec_cmd->se_dev:"
  472. " %p\n", pt_cmd->se_dev);
  473. pt_cmd->se_lun = ec_cmd->se_lun;
  474. pr_debug("Honoring local DST port from ec_cmd->se_lun: %p\n",
  475. pt_cmd->se_lun);
  476. }
  477. }
  478. }
  479. static void target_xcopy_init_pt_lun(struct se_device *se_dev,
  480. struct se_cmd *pt_cmd, bool remote_port)
  481. {
  482. /*
  483. * Don't allocate + init an pt_cmd->se_lun if honoring local port for
  484. * reservations. The pt_cmd->se_lun pointer will be setup from within
  485. * target_xcopy_setup_pt_port()
  486. */
  487. if (remote_port) {
  488. pr_debug("Setup emulated se_dev: %p from se_dev\n",
  489. pt_cmd->se_dev);
  490. pt_cmd->se_lun = &se_dev->xcopy_lun;
  491. pt_cmd->se_dev = se_dev;
  492. }
  493. pt_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
  494. }
  495. static int target_xcopy_setup_pt_cmd(
  496. struct xcopy_pt_cmd *xpt_cmd,
  497. struct xcopy_op *xop,
  498. struct se_device *se_dev,
  499. unsigned char *cdb,
  500. bool remote_port,
  501. bool alloc_mem)
  502. {
  503. struct se_cmd *cmd = &xpt_cmd->se_cmd;
  504. sense_reason_t sense_rc;
  505. int ret = 0, rc;
  506. /*
  507. * Setup LUN+port to honor reservations based upon xop->op_origin for
  508. * X-COPY PUSH or X-COPY PULL based upon where the CDB was received.
  509. */
  510. target_xcopy_init_pt_lun(se_dev, cmd, remote_port);
  511. xpt_cmd->xcopy_op = xop;
  512. target_xcopy_setup_pt_port(xpt_cmd, xop, remote_port);
  513. cmd->tag = 0;
  514. sense_rc = target_setup_cmd_from_cdb(cmd, cdb);
  515. if (sense_rc) {
  516. ret = -EINVAL;
  517. goto out;
  518. }
  519. if (alloc_mem) {
  520. rc = target_alloc_sgl(&cmd->t_data_sg, &cmd->t_data_nents,
  521. cmd->data_length, false, false);
  522. if (rc < 0) {
  523. ret = rc;
  524. goto out;
  525. }
  526. /*
  527. * Set this bit so that transport_free_pages() allows the
  528. * caller to release SGLs + physical memory allocated by
  529. * transport_generic_get_mem()..
  530. */
  531. cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
  532. } else {
  533. /*
  534. * Here the previously allocated SGLs for the internal READ
  535. * are mapped zero-copy to the internal WRITE.
  536. */
  537. sense_rc = transport_generic_map_mem_to_cmd(cmd,
  538. xop->xop_data_sg, xop->xop_data_nents,
  539. NULL, 0);
  540. if (sense_rc) {
  541. ret = -EINVAL;
  542. goto out;
  543. }
  544. pr_debug("Setup PASSTHROUGH_NOALLOC t_data_sg: %p t_data_nents:"
  545. " %u\n", cmd->t_data_sg, cmd->t_data_nents);
  546. }
  547. return 0;
  548. out:
  549. return ret;
  550. }
  551. static int target_xcopy_issue_pt_cmd(struct xcopy_pt_cmd *xpt_cmd)
  552. {
  553. struct se_cmd *se_cmd = &xpt_cmd->se_cmd;
  554. sense_reason_t sense_rc;
  555. sense_rc = transport_generic_new_cmd(se_cmd);
  556. if (sense_rc)
  557. return -EINVAL;
  558. if (se_cmd->data_direction == DMA_TO_DEVICE)
  559. target_execute_cmd(se_cmd);
  560. wait_for_completion_interruptible(&xpt_cmd->xpt_passthrough_sem);
  561. pr_debug("target_xcopy_issue_pt_cmd(): SCSI status: 0x%02x\n",
  562. se_cmd->scsi_status);
  563. return (se_cmd->scsi_status) ? -EINVAL : 0;
  564. }
  565. static int target_xcopy_read_source(
  566. struct se_cmd *ec_cmd,
  567. struct xcopy_op *xop,
  568. struct se_device *src_dev,
  569. sector_t src_lba,
  570. u32 src_sectors)
  571. {
  572. struct xcopy_pt_cmd *xpt_cmd;
  573. struct se_cmd *se_cmd;
  574. u32 length = (src_sectors * src_dev->dev_attrib.block_size);
  575. int rc;
  576. unsigned char cdb[16];
  577. bool remote_port = (xop->op_origin == XCOL_DEST_RECV_OP);
  578. xpt_cmd = kzalloc(sizeof(struct xcopy_pt_cmd), GFP_KERNEL);
  579. if (!xpt_cmd) {
  580. pr_err("Unable to allocate xcopy_pt_cmd\n");
  581. return -ENOMEM;
  582. }
  583. init_completion(&xpt_cmd->xpt_passthrough_sem);
  584. se_cmd = &xpt_cmd->se_cmd;
  585. memset(&cdb[0], 0, 16);
  586. cdb[0] = READ_16;
  587. put_unaligned_be64(src_lba, &cdb[2]);
  588. put_unaligned_be32(src_sectors, &cdb[10]);
  589. pr_debug("XCOPY: Built READ_16: LBA: %llu Sectors: %u Length: %u\n",
  590. (unsigned long long)src_lba, src_sectors, length);
  591. transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, length,
  592. DMA_FROM_DEVICE, 0, &xpt_cmd->sense_buffer[0]);
  593. xop->src_pt_cmd = xpt_cmd;
  594. rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0],
  595. remote_port, true);
  596. if (rc < 0) {
  597. ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
  598. transport_generic_free_cmd(se_cmd, 0);
  599. return rc;
  600. }
  601. xop->xop_data_sg = se_cmd->t_data_sg;
  602. xop->xop_data_nents = se_cmd->t_data_nents;
  603. pr_debug("XCOPY-READ: Saved xop->xop_data_sg: %p, num: %u for READ"
  604. " memory\n", xop->xop_data_sg, xop->xop_data_nents);
  605. rc = target_xcopy_issue_pt_cmd(xpt_cmd);
  606. if (rc < 0) {
  607. ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
  608. transport_generic_free_cmd(se_cmd, 0);
  609. return rc;
  610. }
  611. /*
  612. * Clear off the allocated t_data_sg, that has been saved for
  613. * zero-copy WRITE submission reuse in struct xcopy_op..
  614. */
  615. se_cmd->t_data_sg = NULL;
  616. se_cmd->t_data_nents = 0;
  617. return 0;
  618. }
  619. static int target_xcopy_write_destination(
  620. struct se_cmd *ec_cmd,
  621. struct xcopy_op *xop,
  622. struct se_device *dst_dev,
  623. sector_t dst_lba,
  624. u32 dst_sectors)
  625. {
  626. struct xcopy_pt_cmd *xpt_cmd;
  627. struct se_cmd *se_cmd;
  628. u32 length = (dst_sectors * dst_dev->dev_attrib.block_size);
  629. int rc;
  630. unsigned char cdb[16];
  631. bool remote_port = (xop->op_origin == XCOL_SOURCE_RECV_OP);
  632. xpt_cmd = kzalloc(sizeof(struct xcopy_pt_cmd), GFP_KERNEL);
  633. if (!xpt_cmd) {
  634. pr_err("Unable to allocate xcopy_pt_cmd\n");
  635. return -ENOMEM;
  636. }
  637. init_completion(&xpt_cmd->xpt_passthrough_sem);
  638. se_cmd = &xpt_cmd->se_cmd;
  639. memset(&cdb[0], 0, 16);
  640. cdb[0] = WRITE_16;
  641. put_unaligned_be64(dst_lba, &cdb[2]);
  642. put_unaligned_be32(dst_sectors, &cdb[10]);
  643. pr_debug("XCOPY: Built WRITE_16: LBA: %llu Sectors: %u Length: %u\n",
  644. (unsigned long long)dst_lba, dst_sectors, length);
  645. transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, length,
  646. DMA_TO_DEVICE, 0, &xpt_cmd->sense_buffer[0]);
  647. xop->dst_pt_cmd = xpt_cmd;
  648. rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, dst_dev, &cdb[0],
  649. remote_port, false);
  650. if (rc < 0) {
  651. struct se_cmd *src_cmd = &xop->src_pt_cmd->se_cmd;
  652. ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
  653. /*
  654. * If the failure happened before the t_mem_list hand-off in
  655. * target_xcopy_setup_pt_cmd(), Reset memory + clear flag so that
  656. * core releases this memory on error during X-COPY WRITE I/O.
  657. */
  658. src_cmd->se_cmd_flags &= ~SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
  659. src_cmd->t_data_sg = xop->xop_data_sg;
  660. src_cmd->t_data_nents = xop->xop_data_nents;
  661. transport_generic_free_cmd(se_cmd, 0);
  662. return rc;
  663. }
  664. rc = target_xcopy_issue_pt_cmd(xpt_cmd);
  665. if (rc < 0) {
  666. ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
  667. se_cmd->se_cmd_flags &= ~SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
  668. transport_generic_free_cmd(se_cmd, 0);
  669. return rc;
  670. }
  671. return 0;
  672. }
  673. static void target_xcopy_do_work(struct work_struct *work)
  674. {
  675. struct xcopy_op *xop = container_of(work, struct xcopy_op, xop_work);
  676. struct se_device *src_dev = xop->src_dev, *dst_dev = xop->dst_dev;
  677. struct se_cmd *ec_cmd = xop->xop_se_cmd;
  678. sector_t src_lba = xop->src_lba, dst_lba = xop->dst_lba, end_lba;
  679. unsigned int max_sectors;
  680. int rc;
  681. unsigned short nolb = xop->nolb, cur_nolb, max_nolb, copied_nolb = 0;
  682. end_lba = src_lba + nolb;
  683. /*
  684. * Break up XCOPY I/O into hw_max_sectors sized I/O based on the
  685. * smallest max_sectors between src_dev + dev_dev, or
  686. */
  687. max_sectors = min(src_dev->dev_attrib.hw_max_sectors,
  688. dst_dev->dev_attrib.hw_max_sectors);
  689. max_sectors = min_t(u32, max_sectors, XCOPY_MAX_SECTORS);
  690. max_nolb = min_t(u16, max_sectors, ((u16)(~0U)));
  691. pr_debug("target_xcopy_do_work: nolb: %hu, max_nolb: %hu end_lba: %llu\n",
  692. nolb, max_nolb, (unsigned long long)end_lba);
  693. pr_debug("target_xcopy_do_work: Starting src_lba: %llu, dst_lba: %llu\n",
  694. (unsigned long long)src_lba, (unsigned long long)dst_lba);
  695. while (src_lba < end_lba) {
  696. cur_nolb = min(nolb, max_nolb);
  697. pr_debug("target_xcopy_do_work: Calling read src_dev: %p src_lba: %llu,"
  698. " cur_nolb: %hu\n", src_dev, (unsigned long long)src_lba, cur_nolb);
  699. rc = target_xcopy_read_source(ec_cmd, xop, src_dev, src_lba, cur_nolb);
  700. if (rc < 0)
  701. goto out;
  702. src_lba += cur_nolb;
  703. pr_debug("target_xcopy_do_work: Incremented READ src_lba to %llu\n",
  704. (unsigned long long)src_lba);
  705. pr_debug("target_xcopy_do_work: Calling write dst_dev: %p dst_lba: %llu,"
  706. " cur_nolb: %hu\n", dst_dev, (unsigned long long)dst_lba, cur_nolb);
  707. rc = target_xcopy_write_destination(ec_cmd, xop, dst_dev,
  708. dst_lba, cur_nolb);
  709. if (rc < 0) {
  710. transport_generic_free_cmd(&xop->src_pt_cmd->se_cmd, 0);
  711. goto out;
  712. }
  713. dst_lba += cur_nolb;
  714. pr_debug("target_xcopy_do_work: Incremented WRITE dst_lba to %llu\n",
  715. (unsigned long long)dst_lba);
  716. copied_nolb += cur_nolb;
  717. nolb -= cur_nolb;
  718. transport_generic_free_cmd(&xop->src_pt_cmd->se_cmd, 0);
  719. xop->dst_pt_cmd->se_cmd.se_cmd_flags &= ~SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
  720. transport_generic_free_cmd(&xop->dst_pt_cmd->se_cmd, 0);
  721. }
  722. xcopy_pt_undepend_remotedev(xop);
  723. kfree(xop);
  724. pr_debug("target_xcopy_do_work: Final src_lba: %llu, dst_lba: %llu\n",
  725. (unsigned long long)src_lba, (unsigned long long)dst_lba);
  726. pr_debug("target_xcopy_do_work: Blocks copied: %hu, Bytes Copied: %u\n",
  727. copied_nolb, copied_nolb * dst_dev->dev_attrib.block_size);
  728. pr_debug("target_xcopy_do_work: Setting X-COPY GOOD status -> sending response\n");
  729. target_complete_cmd(ec_cmd, SAM_STAT_GOOD);
  730. return;
  731. out:
  732. xcopy_pt_undepend_remotedev(xop);
  733. kfree(xop);
  734. /*
  735. * Don't override an error scsi status if it has already been set
  736. */
  737. if (ec_cmd->scsi_status == SAM_STAT_GOOD) {
  738. pr_warn_ratelimited("target_xcopy_do_work: rc: %d, Setting X-COPY"
  739. " CHECK_CONDITION -> sending response\n", rc);
  740. ec_cmd->scsi_status = SAM_STAT_CHECK_CONDITION;
  741. }
  742. target_complete_cmd(ec_cmd, SAM_STAT_CHECK_CONDITION);
  743. }
  744. sense_reason_t target_do_xcopy(struct se_cmd *se_cmd)
  745. {
  746. struct se_device *dev = se_cmd->se_dev;
  747. struct xcopy_op *xop = NULL;
  748. unsigned char *p = NULL, *seg_desc;
  749. unsigned int list_id, list_id_usage, sdll, inline_dl, sa;
  750. sense_reason_t ret = TCM_INVALID_PARAMETER_LIST;
  751. int rc;
  752. unsigned short tdll;
  753. if (!dev->dev_attrib.emulate_3pc) {
  754. pr_err("EXTENDED_COPY operation explicitly disabled\n");
  755. return TCM_UNSUPPORTED_SCSI_OPCODE;
  756. }
  757. sa = se_cmd->t_task_cdb[1] & 0x1f;
  758. if (sa != 0x00) {
  759. pr_err("EXTENDED_COPY(LID4) not supported\n");
  760. return TCM_UNSUPPORTED_SCSI_OPCODE;
  761. }
  762. if (se_cmd->data_length == 0) {
  763. target_complete_cmd(se_cmd, SAM_STAT_GOOD);
  764. return TCM_NO_SENSE;
  765. }
  766. if (se_cmd->data_length < XCOPY_HDR_LEN) {
  767. pr_err("XCOPY parameter truncation: length %u < hdr_len %u\n",
  768. se_cmd->data_length, XCOPY_HDR_LEN);
  769. return TCM_PARAMETER_LIST_LENGTH_ERROR;
  770. }
  771. xop = kzalloc(sizeof(struct xcopy_op), GFP_KERNEL);
  772. if (!xop) {
  773. pr_err("Unable to allocate xcopy_op\n");
  774. return TCM_OUT_OF_RESOURCES;
  775. }
  776. xop->xop_se_cmd = se_cmd;
  777. p = transport_kmap_data_sg(se_cmd);
  778. if (!p) {
  779. pr_err("transport_kmap_data_sg() failed in target_do_xcopy\n");
  780. kfree(xop);
  781. return TCM_OUT_OF_RESOURCES;
  782. }
  783. list_id = p[0];
  784. list_id_usage = (p[1] & 0x18) >> 3;
  785. /*
  786. * Determine TARGET DESCRIPTOR LIST LENGTH + SEGMENT DESCRIPTOR LIST LENGTH
  787. */
  788. tdll = get_unaligned_be16(&p[2]);
  789. sdll = get_unaligned_be32(&p[8]);
  790. if (tdll + sdll > RCR_OP_MAX_DESC_LIST_LEN) {
  791. pr_err("XCOPY descriptor list length %u exceeds maximum %u\n",
  792. tdll + sdll, RCR_OP_MAX_DESC_LIST_LEN);
  793. ret = TCM_PARAMETER_LIST_LENGTH_ERROR;
  794. goto out;
  795. }
  796. inline_dl = get_unaligned_be32(&p[12]);
  797. if (inline_dl != 0) {
  798. pr_err("XCOPY with non zero inline data length\n");
  799. goto out;
  800. }
  801. if (se_cmd->data_length < (XCOPY_HDR_LEN + tdll + sdll + inline_dl)) {
  802. pr_err("XCOPY parameter truncation: data length %u too small "
  803. "for tdll: %hu sdll: %u inline_dl: %u\n",
  804. se_cmd->data_length, tdll, sdll, inline_dl);
  805. ret = TCM_PARAMETER_LIST_LENGTH_ERROR;
  806. goto out;
  807. }
  808. pr_debug("Processing XCOPY with list_id: 0x%02x list_id_usage: 0x%02x"
  809. " tdll: %hu sdll: %u inline_dl: %u\n", list_id, list_id_usage,
  810. tdll, sdll, inline_dl);
  811. /*
  812. * skip over the target descriptors until segment descriptors
  813. * have been passed - CSCD ids are needed to determine src and dest.
  814. */
  815. seg_desc = &p[16] + tdll;
  816. rc = target_xcopy_parse_segment_descriptors(se_cmd, xop, seg_desc,
  817. sdll, &ret);
  818. if (rc <= 0)
  819. goto out;
  820. pr_debug("XCOPY: Processed %d segment descriptors, length: %u\n", rc,
  821. rc * XCOPY_SEGMENT_DESC_LEN);
  822. rc = target_xcopy_parse_target_descriptors(se_cmd, xop, &p[16], tdll, &ret);
  823. if (rc <= 0)
  824. goto out;
  825. if (xop->src_dev->dev_attrib.block_size !=
  826. xop->dst_dev->dev_attrib.block_size) {
  827. pr_err("XCOPY: Non matching src_dev block_size: %u + dst_dev"
  828. " block_size: %u currently unsupported\n",
  829. xop->src_dev->dev_attrib.block_size,
  830. xop->dst_dev->dev_attrib.block_size);
  831. xcopy_pt_undepend_remotedev(xop);
  832. ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  833. goto out;
  834. }
  835. pr_debug("XCOPY: Processed %d target descriptors, length: %u\n", rc,
  836. rc * XCOPY_TARGET_DESC_LEN);
  837. transport_kunmap_data_sg(se_cmd);
  838. INIT_WORK(&xop->xop_work, target_xcopy_do_work);
  839. queue_work(xcopy_wq, &xop->xop_work);
  840. return TCM_NO_SENSE;
  841. out:
  842. if (p)
  843. transport_kunmap_data_sg(se_cmd);
  844. kfree(xop);
  845. return ret;
  846. }
  847. static sense_reason_t target_rcr_operating_parameters(struct se_cmd *se_cmd)
  848. {
  849. unsigned char *p;
  850. p = transport_kmap_data_sg(se_cmd);
  851. if (!p) {
  852. pr_err("transport_kmap_data_sg failed in"
  853. " target_rcr_operating_parameters\n");
  854. return TCM_OUT_OF_RESOURCES;
  855. }
  856. if (se_cmd->data_length < 54) {
  857. pr_err("Receive Copy Results Op Parameters length"
  858. " too small: %u\n", se_cmd->data_length);
  859. transport_kunmap_data_sg(se_cmd);
  860. return TCM_INVALID_CDB_FIELD;
  861. }
  862. /*
  863. * Set SNLID=1 (Supports no List ID)
  864. */
  865. p[4] = 0x1;
  866. /*
  867. * MAXIMUM TARGET DESCRIPTOR COUNT
  868. */
  869. put_unaligned_be16(RCR_OP_MAX_TARGET_DESC_COUNT, &p[8]);
  870. /*
  871. * MAXIMUM SEGMENT DESCRIPTOR COUNT
  872. */
  873. put_unaligned_be16(RCR_OP_MAX_SG_DESC_COUNT, &p[10]);
  874. /*
  875. * MAXIMUM DESCRIPTOR LIST LENGTH
  876. */
  877. put_unaligned_be32(RCR_OP_MAX_DESC_LIST_LEN, &p[12]);
  878. /*
  879. * MAXIMUM SEGMENT LENGTH
  880. */
  881. put_unaligned_be32(RCR_OP_MAX_SEGMENT_LEN, &p[16]);
  882. /*
  883. * MAXIMUM INLINE DATA LENGTH for SA 0x04 (NOT SUPPORTED)
  884. */
  885. put_unaligned_be32(0x0, &p[20]);
  886. /*
  887. * HELD DATA LIMIT
  888. */
  889. put_unaligned_be32(0x0, &p[24]);
  890. /*
  891. * MAXIMUM STREAM DEVICE TRANSFER SIZE
  892. */
  893. put_unaligned_be32(0x0, &p[28]);
  894. /*
  895. * TOTAL CONCURRENT COPIES
  896. */
  897. put_unaligned_be16(RCR_OP_TOTAL_CONCURR_COPIES, &p[34]);
  898. /*
  899. * MAXIMUM CONCURRENT COPIES
  900. */
  901. p[36] = RCR_OP_MAX_CONCURR_COPIES;
  902. /*
  903. * DATA SEGMENT GRANULARITY (log 2)
  904. */
  905. p[37] = RCR_OP_DATA_SEG_GRAN_LOG2;
  906. /*
  907. * INLINE DATA GRANULARITY log 2)
  908. */
  909. p[38] = RCR_OP_INLINE_DATA_GRAN_LOG2;
  910. /*
  911. * HELD DATA GRANULARITY
  912. */
  913. p[39] = RCR_OP_HELD_DATA_GRAN_LOG2;
  914. /*
  915. * IMPLEMENTED DESCRIPTOR LIST LENGTH
  916. */
  917. p[43] = 0x2;
  918. /*
  919. * List of implemented descriptor type codes (ordered)
  920. */
  921. p[44] = 0x02; /* Copy Block to Block device */
  922. p[45] = 0xe4; /* Identification descriptor target descriptor */
  923. /*
  924. * AVAILABLE DATA (n-3)
  925. */
  926. put_unaligned_be32(42, &p[0]);
  927. transport_kunmap_data_sg(se_cmd);
  928. target_complete_cmd(se_cmd, GOOD);
  929. return TCM_NO_SENSE;
  930. }
  931. sense_reason_t target_do_receive_copy_results(struct se_cmd *se_cmd)
  932. {
  933. unsigned char *cdb = &se_cmd->t_task_cdb[0];
  934. int sa = (cdb[1] & 0x1f), list_id = cdb[2];
  935. sense_reason_t rc = TCM_NO_SENSE;
  936. pr_debug("Entering target_do_receive_copy_results: SA: 0x%02x, List ID:"
  937. " 0x%02x, AL: %u\n", sa, list_id, se_cmd->data_length);
  938. if (list_id != 0) {
  939. pr_err("Receive Copy Results with non zero list identifier"
  940. " not supported\n");
  941. return TCM_INVALID_CDB_FIELD;
  942. }
  943. switch (sa) {
  944. case RCR_SA_OPERATING_PARAMETERS:
  945. rc = target_rcr_operating_parameters(se_cmd);
  946. break;
  947. case RCR_SA_COPY_STATUS:
  948. case RCR_SA_RECEIVE_DATA:
  949. case RCR_SA_FAILED_SEGMENT_DETAILS:
  950. default:
  951. pr_err("Unsupported SA for receive copy results: 0x%02x\n", sa);
  952. return TCM_INVALID_CDB_FIELD;
  953. }
  954. return rc;
  955. }