target_core_spc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. /*
  2. * SCSI Primary Commands (SPC) parsing and emulation.
  3. *
  4. * Copyright (c) 2002, 2003, 2004, 2005 PyX Technologies, Inc.
  5. * Copyright (c) 2005, 2006, 2007 SBE, Inc.
  6. * Copyright (c) 2007-2010 Rising Tide Systems
  7. * Copyright (c) 2008-2010 Linux-iSCSI.org
  8. *
  9. * Nicholas A. Bellinger <nab@kernel.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <asm/unaligned.h>
  28. #include <scsi/scsi.h>
  29. #include <scsi/scsi_tcq.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_alua.h"
  35. #include "target_core_pr.h"
  36. #include "target_core_ua.h"
  37. static void spc_fill_alua_data(struct se_port *port, unsigned char *buf)
  38. {
  39. struct t10_alua_tg_pt_gp *tg_pt_gp;
  40. struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem;
  41. /*
  42. * Set SCCS for MAINTENANCE_IN + REPORT_TARGET_PORT_GROUPS.
  43. */
  44. buf[5] = 0x80;
  45. /*
  46. * Set TPGS field for explict and/or implict ALUA access type
  47. * and opteration.
  48. *
  49. * See spc4r17 section 6.4.2 Table 135
  50. */
  51. if (!port)
  52. return;
  53. tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem;
  54. if (!tg_pt_gp_mem)
  55. return;
  56. spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
  57. tg_pt_gp = tg_pt_gp_mem->tg_pt_gp;
  58. if (tg_pt_gp)
  59. buf[5] |= tg_pt_gp->tg_pt_gp_alua_access_type;
  60. spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
  61. }
  62. static int spc_emulate_inquiry_std(struct se_cmd *cmd, char *buf)
  63. {
  64. struct se_lun *lun = cmd->se_lun;
  65. struct se_device *dev = cmd->se_dev;
  66. /* Set RMB (removable media) for tape devices */
  67. if (dev->transport->get_device_type(dev) == TYPE_TAPE)
  68. buf[1] = 0x80;
  69. buf[2] = dev->transport->get_device_rev(dev);
  70. /*
  71. * NORMACA and HISUP = 0, RESPONSE DATA FORMAT = 2
  72. *
  73. * SPC4 says:
  74. * A RESPONSE DATA FORMAT field set to 2h indicates that the
  75. * standard INQUIRY data is in the format defined in this
  76. * standard. Response data format values less than 2h are
  77. * obsolete. Response data format values greater than 2h are
  78. * reserved.
  79. */
  80. buf[3] = 2;
  81. /*
  82. * Enable SCCS and TPGS fields for Emulated ALUA
  83. */
  84. if (dev->t10_alua.alua_type == SPC3_ALUA_EMULATED)
  85. spc_fill_alua_data(lun->lun_sep, buf);
  86. buf[7] = 0x2; /* CmdQue=1 */
  87. snprintf(&buf[8], 8, "LIO-ORG");
  88. snprintf(&buf[16], 16, "%s", dev->t10_wwn.model);
  89. snprintf(&buf[32], 4, "%s", dev->t10_wwn.revision);
  90. buf[4] = 31; /* Set additional length to 31 */
  91. return 0;
  92. }
  93. /* unit serial number */
  94. static int spc_emulate_evpd_80(struct se_cmd *cmd, unsigned char *buf)
  95. {
  96. struct se_device *dev = cmd->se_dev;
  97. u16 len = 0;
  98. if (dev->dev_flags & DF_EMULATED_VPD_UNIT_SERIAL) {
  99. u32 unit_serial_len;
  100. unit_serial_len = strlen(dev->t10_wwn.unit_serial);
  101. unit_serial_len++; /* For NULL Terminator */
  102. len += sprintf(&buf[4], "%s", dev->t10_wwn.unit_serial);
  103. len++; /* Extra Byte for NULL Terminator */
  104. buf[3] = len;
  105. }
  106. return 0;
  107. }
  108. static void spc_parse_naa_6h_vendor_specific(struct se_device *dev,
  109. unsigned char *buf)
  110. {
  111. unsigned char *p = &dev->t10_wwn.unit_serial[0];
  112. int cnt;
  113. bool next = true;
  114. /*
  115. * Generate up to 36 bits of VENDOR SPECIFIC IDENTIFIER starting on
  116. * byte 3 bit 3-0 for NAA IEEE Registered Extended DESIGNATOR field
  117. * format, followed by 64 bits of VENDOR SPECIFIC IDENTIFIER EXTENSION
  118. * to complete the payload. These are based from VPD=0x80 PRODUCT SERIAL
  119. * NUMBER set via vpd_unit_serial in target_core_configfs.c to ensure
  120. * per device uniqeness.
  121. */
  122. for (cnt = 0; *p && cnt < 13; p++) {
  123. int val = hex_to_bin(*p);
  124. if (val < 0)
  125. continue;
  126. if (next) {
  127. next = false;
  128. buf[cnt++] |= val;
  129. } else {
  130. next = true;
  131. buf[cnt] = val << 4;
  132. }
  133. }
  134. }
  135. /*
  136. * Device identification VPD, for a complete list of
  137. * DESIGNATOR TYPEs see spc4r17 Table 459.
  138. */
  139. static int spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf)
  140. {
  141. struct se_device *dev = cmd->se_dev;
  142. struct se_lun *lun = cmd->se_lun;
  143. struct se_port *port = NULL;
  144. struct se_portal_group *tpg = NULL;
  145. struct t10_alua_lu_gp_member *lu_gp_mem;
  146. struct t10_alua_tg_pt_gp *tg_pt_gp;
  147. struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem;
  148. unsigned char *prod = &dev->t10_wwn.model[0];
  149. u32 prod_len;
  150. u32 unit_serial_len, off = 0;
  151. u16 len = 0, id_len;
  152. off = 4;
  153. /*
  154. * NAA IEEE Registered Extended Assigned designator format, see
  155. * spc4r17 section 7.7.3.6.5
  156. *
  157. * We depend upon a target_core_mod/ConfigFS provided
  158. * /sys/kernel/config/target/core/$HBA/$DEV/wwn/vpd_unit_serial
  159. * value in order to return the NAA id.
  160. */
  161. if (!(dev->dev_flags & DF_EMULATED_VPD_UNIT_SERIAL))
  162. goto check_t10_vend_desc;
  163. /* CODE SET == Binary */
  164. buf[off++] = 0x1;
  165. /* Set ASSOCIATION == addressed logical unit: 0)b */
  166. buf[off] = 0x00;
  167. /* Identifier/Designator type == NAA identifier */
  168. buf[off++] |= 0x3;
  169. off++;
  170. /* Identifier/Designator length */
  171. buf[off++] = 0x10;
  172. /*
  173. * Start NAA IEEE Registered Extended Identifier/Designator
  174. */
  175. buf[off++] = (0x6 << 4);
  176. /*
  177. * Use OpenFabrics IEEE Company ID: 00 14 05
  178. */
  179. buf[off++] = 0x01;
  180. buf[off++] = 0x40;
  181. buf[off] = (0x5 << 4);
  182. /*
  183. * Return ConfigFS Unit Serial Number information for
  184. * VENDOR_SPECIFIC_IDENTIFIER and
  185. * VENDOR_SPECIFIC_IDENTIFIER_EXTENTION
  186. */
  187. spc_parse_naa_6h_vendor_specific(dev, &buf[off]);
  188. len = 20;
  189. off = (len + 4);
  190. check_t10_vend_desc:
  191. /*
  192. * T10 Vendor Identifier Page, see spc4r17 section 7.7.3.4
  193. */
  194. id_len = 8; /* For Vendor field */
  195. prod_len = 4; /* For VPD Header */
  196. prod_len += 8; /* For Vendor field */
  197. prod_len += strlen(prod);
  198. prod_len++; /* For : */
  199. if (dev->dev_flags & DF_EMULATED_VPD_UNIT_SERIAL) {
  200. unit_serial_len = strlen(&dev->t10_wwn.unit_serial[0]);
  201. unit_serial_len++; /* For NULL Terminator */
  202. id_len += sprintf(&buf[off+12], "%s:%s", prod,
  203. &dev->t10_wwn.unit_serial[0]);
  204. }
  205. buf[off] = 0x2; /* ASCII */
  206. buf[off+1] = 0x1; /* T10 Vendor ID */
  207. buf[off+2] = 0x0;
  208. memcpy(&buf[off+4], "LIO-ORG", 8);
  209. /* Extra Byte for NULL Terminator */
  210. id_len++;
  211. /* Identifier Length */
  212. buf[off+3] = id_len;
  213. /* Header size for Designation descriptor */
  214. len += (id_len + 4);
  215. off += (id_len + 4);
  216. /*
  217. * struct se_port is only set for INQUIRY VPD=1 through $FABRIC_MOD
  218. */
  219. port = lun->lun_sep;
  220. if (port) {
  221. struct t10_alua_lu_gp *lu_gp;
  222. u32 padding, scsi_name_len;
  223. u16 lu_gp_id = 0;
  224. u16 tg_pt_gp_id = 0;
  225. u16 tpgt;
  226. tpg = port->sep_tpg;
  227. /*
  228. * Relative target port identifer, see spc4r17
  229. * section 7.7.3.7
  230. *
  231. * Get the PROTOCOL IDENTIFIER as defined by spc4r17
  232. * section 7.5.1 Table 362
  233. */
  234. buf[off] =
  235. (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4);
  236. buf[off++] |= 0x1; /* CODE SET == Binary */
  237. buf[off] = 0x80; /* Set PIV=1 */
  238. /* Set ASSOCIATION == target port: 01b */
  239. buf[off] |= 0x10;
  240. /* DESIGNATOR TYPE == Relative target port identifer */
  241. buf[off++] |= 0x4;
  242. off++; /* Skip over Reserved */
  243. buf[off++] = 4; /* DESIGNATOR LENGTH */
  244. /* Skip over Obsolete field in RTPI payload
  245. * in Table 472 */
  246. off += 2;
  247. buf[off++] = ((port->sep_rtpi >> 8) & 0xff);
  248. buf[off++] = (port->sep_rtpi & 0xff);
  249. len += 8; /* Header size + Designation descriptor */
  250. /*
  251. * Target port group identifier, see spc4r17
  252. * section 7.7.3.8
  253. *
  254. * Get the PROTOCOL IDENTIFIER as defined by spc4r17
  255. * section 7.5.1 Table 362
  256. */
  257. if (dev->t10_alua.alua_type != SPC3_ALUA_EMULATED)
  258. goto check_scsi_name;
  259. tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem;
  260. if (!tg_pt_gp_mem)
  261. goto check_lu_gp;
  262. spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
  263. tg_pt_gp = tg_pt_gp_mem->tg_pt_gp;
  264. if (!tg_pt_gp) {
  265. spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
  266. goto check_lu_gp;
  267. }
  268. tg_pt_gp_id = tg_pt_gp->tg_pt_gp_id;
  269. spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
  270. buf[off] =
  271. (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4);
  272. buf[off++] |= 0x1; /* CODE SET == Binary */
  273. buf[off] = 0x80; /* Set PIV=1 */
  274. /* Set ASSOCIATION == target port: 01b */
  275. buf[off] |= 0x10;
  276. /* DESIGNATOR TYPE == Target port group identifier */
  277. buf[off++] |= 0x5;
  278. off++; /* Skip over Reserved */
  279. buf[off++] = 4; /* DESIGNATOR LENGTH */
  280. off += 2; /* Skip over Reserved Field */
  281. buf[off++] = ((tg_pt_gp_id >> 8) & 0xff);
  282. buf[off++] = (tg_pt_gp_id & 0xff);
  283. len += 8; /* Header size + Designation descriptor */
  284. /*
  285. * Logical Unit Group identifier, see spc4r17
  286. * section 7.7.3.8
  287. */
  288. check_lu_gp:
  289. lu_gp_mem = dev->dev_alua_lu_gp_mem;
  290. if (!lu_gp_mem)
  291. goto check_scsi_name;
  292. spin_lock(&lu_gp_mem->lu_gp_mem_lock);
  293. lu_gp = lu_gp_mem->lu_gp;
  294. if (!lu_gp) {
  295. spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
  296. goto check_scsi_name;
  297. }
  298. lu_gp_id = lu_gp->lu_gp_id;
  299. spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
  300. buf[off++] |= 0x1; /* CODE SET == Binary */
  301. /* DESIGNATOR TYPE == Logical Unit Group identifier */
  302. buf[off++] |= 0x6;
  303. off++; /* Skip over Reserved */
  304. buf[off++] = 4; /* DESIGNATOR LENGTH */
  305. off += 2; /* Skip over Reserved Field */
  306. buf[off++] = ((lu_gp_id >> 8) & 0xff);
  307. buf[off++] = (lu_gp_id & 0xff);
  308. len += 8; /* Header size + Designation descriptor */
  309. /*
  310. * SCSI name string designator, see spc4r17
  311. * section 7.7.3.11
  312. *
  313. * Get the PROTOCOL IDENTIFIER as defined by spc4r17
  314. * section 7.5.1 Table 362
  315. */
  316. check_scsi_name:
  317. scsi_name_len = strlen(tpg->se_tpg_tfo->tpg_get_wwn(tpg));
  318. /* UTF-8 ",t,0x<16-bit TPGT>" + NULL Terminator */
  319. scsi_name_len += 10;
  320. /* Check for 4-byte padding */
  321. padding = ((-scsi_name_len) & 3);
  322. if (padding != 0)
  323. scsi_name_len += padding;
  324. /* Header size + Designation descriptor */
  325. scsi_name_len += 4;
  326. buf[off] =
  327. (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4);
  328. buf[off++] |= 0x3; /* CODE SET == UTF-8 */
  329. buf[off] = 0x80; /* Set PIV=1 */
  330. /* Set ASSOCIATION == target port: 01b */
  331. buf[off] |= 0x10;
  332. /* DESIGNATOR TYPE == SCSI name string */
  333. buf[off++] |= 0x8;
  334. off += 2; /* Skip over Reserved and length */
  335. /*
  336. * SCSI name string identifer containing, $FABRIC_MOD
  337. * dependent information. For LIO-Target and iSCSI
  338. * Target Port, this means "<iSCSI name>,t,0x<TPGT> in
  339. * UTF-8 encoding.
  340. */
  341. tpgt = tpg->se_tpg_tfo->tpg_get_tag(tpg);
  342. scsi_name_len = sprintf(&buf[off], "%s,t,0x%04x",
  343. tpg->se_tpg_tfo->tpg_get_wwn(tpg), tpgt);
  344. scsi_name_len += 1 /* Include NULL terminator */;
  345. /*
  346. * The null-terminated, null-padded (see 4.4.2) SCSI
  347. * NAME STRING field contains a UTF-8 format string.
  348. * The number of bytes in the SCSI NAME STRING field
  349. * (i.e., the value in the DESIGNATOR LENGTH field)
  350. * shall be no larger than 256 and shall be a multiple
  351. * of four.
  352. */
  353. if (padding)
  354. scsi_name_len += padding;
  355. buf[off-1] = scsi_name_len;
  356. off += scsi_name_len;
  357. /* Header size + Designation descriptor */
  358. len += (scsi_name_len + 4);
  359. }
  360. buf[2] = ((len >> 8) & 0xff);
  361. buf[3] = (len & 0xff); /* Page Length for VPD 0x83 */
  362. return 0;
  363. }
  364. /* Extended INQUIRY Data VPD Page */
  365. static int spc_emulate_evpd_86(struct se_cmd *cmd, unsigned char *buf)
  366. {
  367. buf[3] = 0x3c;
  368. /* Set HEADSUP, ORDSUP, SIMPSUP */
  369. buf[5] = 0x07;
  370. /* If WriteCache emulation is enabled, set V_SUP */
  371. if (cmd->se_dev->dev_attrib.emulate_write_cache > 0)
  372. buf[6] = 0x01;
  373. return 0;
  374. }
  375. /* Block Limits VPD page */
  376. static int spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
  377. {
  378. struct se_device *dev = cmd->se_dev;
  379. u32 max_sectors;
  380. int have_tp = 0;
  381. /*
  382. * Following spc3r22 section 6.5.3 Block Limits VPD page, when
  383. * emulate_tpu=1 or emulate_tpws=1 we will be expect a
  384. * different page length for Thin Provisioning.
  385. */
  386. if (dev->dev_attrib.emulate_tpu || dev->dev_attrib.emulate_tpws)
  387. have_tp = 1;
  388. buf[0] = dev->transport->get_device_type(dev);
  389. buf[3] = have_tp ? 0x3c : 0x10;
  390. /* Set WSNZ to 1 */
  391. buf[4] = 0x01;
  392. /*
  393. * Set OPTIMAL TRANSFER LENGTH GRANULARITY
  394. */
  395. put_unaligned_be16(1, &buf[6]);
  396. /*
  397. * Set MAXIMUM TRANSFER LENGTH
  398. */
  399. max_sectors = min(dev->dev_attrib.fabric_max_sectors,
  400. dev->dev_attrib.hw_max_sectors);
  401. put_unaligned_be32(max_sectors, &buf[8]);
  402. /*
  403. * Set OPTIMAL TRANSFER LENGTH
  404. */
  405. put_unaligned_be32(dev->dev_attrib.optimal_sectors, &buf[12]);
  406. /*
  407. * Exit now if we don't support TP.
  408. */
  409. if (!have_tp)
  410. return 0;
  411. /*
  412. * Set MAXIMUM UNMAP LBA COUNT
  413. */
  414. put_unaligned_be32(dev->dev_attrib.max_unmap_lba_count, &buf[20]);
  415. /*
  416. * Set MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT
  417. */
  418. put_unaligned_be32(dev->dev_attrib.max_unmap_block_desc_count,
  419. &buf[24]);
  420. /*
  421. * Set OPTIMAL UNMAP GRANULARITY
  422. */
  423. put_unaligned_be32(dev->dev_attrib.unmap_granularity, &buf[28]);
  424. /*
  425. * UNMAP GRANULARITY ALIGNMENT
  426. */
  427. put_unaligned_be32(dev->dev_attrib.unmap_granularity_alignment,
  428. &buf[32]);
  429. if (dev->dev_attrib.unmap_granularity_alignment != 0)
  430. buf[32] |= 0x80; /* Set the UGAVALID bit */
  431. return 0;
  432. }
  433. /* Block Device Characteristics VPD page */
  434. static int spc_emulate_evpd_b1(struct se_cmd *cmd, unsigned char *buf)
  435. {
  436. struct se_device *dev = cmd->se_dev;
  437. buf[0] = dev->transport->get_device_type(dev);
  438. buf[3] = 0x3c;
  439. buf[5] = dev->dev_attrib.is_nonrot ? 1 : 0;
  440. return 0;
  441. }
  442. /* Thin Provisioning VPD */
  443. static int spc_emulate_evpd_b2(struct se_cmd *cmd, unsigned char *buf)
  444. {
  445. struct se_device *dev = cmd->se_dev;
  446. /*
  447. * From spc3r22 section 6.5.4 Thin Provisioning VPD page:
  448. *
  449. * The PAGE LENGTH field is defined in SPC-4. If the DP bit is set to
  450. * zero, then the page length shall be set to 0004h. If the DP bit
  451. * is set to one, then the page length shall be set to the value
  452. * defined in table 162.
  453. */
  454. buf[0] = dev->transport->get_device_type(dev);
  455. /*
  456. * Set Hardcoded length mentioned above for DP=0
  457. */
  458. put_unaligned_be16(0x0004, &buf[2]);
  459. /*
  460. * The THRESHOLD EXPONENT field indicates the threshold set size in
  461. * LBAs as a power of 2 (i.e., the threshold set size is equal to
  462. * 2(threshold exponent)).
  463. *
  464. * Note that this is currently set to 0x00 as mkp says it will be
  465. * changing again. We can enable this once it has settled in T10
  466. * and is actually used by Linux/SCSI ML code.
  467. */
  468. buf[4] = 0x00;
  469. /*
  470. * A TPU bit set to one indicates that the device server supports
  471. * the UNMAP command (see 5.25). A TPU bit set to zero indicates
  472. * that the device server does not support the UNMAP command.
  473. */
  474. if (dev->dev_attrib.emulate_tpu != 0)
  475. buf[5] = 0x80;
  476. /*
  477. * A TPWS bit set to one indicates that the device server supports
  478. * the use of the WRITE SAME (16) command (see 5.42) to unmap LBAs.
  479. * A TPWS bit set to zero indicates that the device server does not
  480. * support the use of the WRITE SAME (16) command to unmap LBAs.
  481. */
  482. if (dev->dev_attrib.emulate_tpws != 0)
  483. buf[5] |= 0x40;
  484. return 0;
  485. }
  486. static int spc_emulate_evpd_00(struct se_cmd *cmd, unsigned char *buf);
  487. static struct {
  488. uint8_t page;
  489. int (*emulate)(struct se_cmd *, unsigned char *);
  490. } evpd_handlers[] = {
  491. { .page = 0x00, .emulate = spc_emulate_evpd_00 },
  492. { .page = 0x80, .emulate = spc_emulate_evpd_80 },
  493. { .page = 0x83, .emulate = spc_emulate_evpd_83 },
  494. { .page = 0x86, .emulate = spc_emulate_evpd_86 },
  495. { .page = 0xb0, .emulate = spc_emulate_evpd_b0 },
  496. { .page = 0xb1, .emulate = spc_emulate_evpd_b1 },
  497. { .page = 0xb2, .emulate = spc_emulate_evpd_b2 },
  498. };
  499. /* supported vital product data pages */
  500. static int spc_emulate_evpd_00(struct se_cmd *cmd, unsigned char *buf)
  501. {
  502. int p;
  503. /*
  504. * Only report the INQUIRY EVPD=1 pages after a valid NAA
  505. * Registered Extended LUN WWN has been set via ConfigFS
  506. * during device creation/restart.
  507. */
  508. if (cmd->se_dev->dev_flags & DF_EMULATED_VPD_UNIT_SERIAL) {
  509. buf[3] = ARRAY_SIZE(evpd_handlers);
  510. for (p = 0; p < ARRAY_SIZE(evpd_handlers); ++p)
  511. buf[p + 4] = evpd_handlers[p].page;
  512. }
  513. return 0;
  514. }
  515. static int spc_emulate_inquiry(struct se_cmd *cmd)
  516. {
  517. struct se_device *dev = cmd->se_dev;
  518. struct se_portal_group *tpg = cmd->se_lun->lun_sep->sep_tpg;
  519. unsigned char *rbuf;
  520. unsigned char *cdb = cmd->t_task_cdb;
  521. unsigned char buf[SE_INQUIRY_BUF];
  522. int p, ret;
  523. memset(buf, 0, SE_INQUIRY_BUF);
  524. if (dev == tpg->tpg_virt_lun0.lun_se_dev)
  525. buf[0] = 0x3f; /* Not connected */
  526. else
  527. buf[0] = dev->transport->get_device_type(dev);
  528. if (!(cdb[1] & 0x1)) {
  529. if (cdb[2]) {
  530. pr_err("INQUIRY with EVPD==0 but PAGE CODE=%02x\n",
  531. cdb[2]);
  532. cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
  533. ret = -EINVAL;
  534. goto out;
  535. }
  536. ret = spc_emulate_inquiry_std(cmd, buf);
  537. goto out;
  538. }
  539. for (p = 0; p < ARRAY_SIZE(evpd_handlers); ++p) {
  540. if (cdb[2] == evpd_handlers[p].page) {
  541. buf[1] = cdb[2];
  542. ret = evpd_handlers[p].emulate(cmd, buf);
  543. goto out;
  544. }
  545. }
  546. pr_err("Unknown VPD Code: 0x%02x\n", cdb[2]);
  547. cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
  548. ret = -EINVAL;
  549. out:
  550. rbuf = transport_kmap_data_sg(cmd);
  551. if (rbuf) {
  552. memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
  553. transport_kunmap_data_sg(cmd);
  554. }
  555. if (!ret)
  556. target_complete_cmd(cmd, GOOD);
  557. return ret;
  558. }
  559. static int spc_modesense_rwrecovery(unsigned char *p)
  560. {
  561. p[0] = 0x01;
  562. p[1] = 0x0a;
  563. return 12;
  564. }
  565. static int spc_modesense_control(struct se_device *dev, unsigned char *p)
  566. {
  567. p[0] = 0x0a;
  568. p[1] = 0x0a;
  569. p[2] = 2;
  570. /*
  571. * From spc4r23, 7.4.7 Control mode page
  572. *
  573. * The QUEUE ALGORITHM MODIFIER field (see table 368) specifies
  574. * restrictions on the algorithm used for reordering commands
  575. * having the SIMPLE task attribute (see SAM-4).
  576. *
  577. * Table 368 -- QUEUE ALGORITHM MODIFIER field
  578. * Code Description
  579. * 0h Restricted reordering
  580. * 1h Unrestricted reordering allowed
  581. * 2h to 7h Reserved
  582. * 8h to Fh Vendor specific
  583. *
  584. * A value of zero in the QUEUE ALGORITHM MODIFIER field specifies that
  585. * the device server shall order the processing sequence of commands
  586. * having the SIMPLE task attribute such that data integrity is maintained
  587. * for that I_T nexus (i.e., if the transmission of new SCSI transport protocol
  588. * requests is halted at any time, the final value of all data observable
  589. * on the medium shall be the same as if all the commands had been processed
  590. * with the ORDERED task attribute).
  591. *
  592. * A value of one in the QUEUE ALGORITHM MODIFIER field specifies that the
  593. * device server may reorder the processing sequence of commands having the
  594. * SIMPLE task attribute in any manner. Any data integrity exposures related to
  595. * command sequence order shall be explicitly handled by the application client
  596. * through the selection of appropriate ommands and task attributes.
  597. */
  598. p[3] = (dev->dev_attrib.emulate_rest_reord == 1) ? 0x00 : 0x10;
  599. /*
  600. * From spc4r17, section 7.4.6 Control mode Page
  601. *
  602. * Unit Attention interlocks control (UN_INTLCK_CTRL) to code 00b
  603. *
  604. * 00b: The logical unit shall clear any unit attention condition
  605. * reported in the same I_T_L_Q nexus transaction as a CHECK CONDITION
  606. * status and shall not establish a unit attention condition when a com-
  607. * mand is completed with BUSY, TASK SET FULL, or RESERVATION CONFLICT
  608. * status.
  609. *
  610. * 10b: The logical unit shall not clear any unit attention condition
  611. * reported in the same I_T_L_Q nexus transaction as a CHECK CONDITION
  612. * status and shall not establish a unit attention condition when
  613. * a command is completed with BUSY, TASK SET FULL, or RESERVATION
  614. * CONFLICT status.
  615. *
  616. * 11b a The logical unit shall not clear any unit attention condition
  617. * reported in the same I_T_L_Q nexus transaction as a CHECK CONDITION
  618. * status and shall establish a unit attention condition for the
  619. * initiator port associated with the I_T nexus on which the BUSY,
  620. * TASK SET FULL, or RESERVATION CONFLICT status is being returned.
  621. * Depending on the status, the additional sense code shall be set to
  622. * PREVIOUS BUSY STATUS, PREVIOUS TASK SET FULL STATUS, or PREVIOUS
  623. * RESERVATION CONFLICT STATUS. Until it is cleared by a REQUEST SENSE
  624. * command, a unit attention condition shall be established only once
  625. * for a BUSY, TASK SET FULL, or RESERVATION CONFLICT status regardless
  626. * to the number of commands completed with one of those status codes.
  627. */
  628. p[4] = (dev->dev_attrib.emulate_ua_intlck_ctrl == 2) ? 0x30 :
  629. (dev->dev_attrib.emulate_ua_intlck_ctrl == 1) ? 0x20 : 0x00;
  630. /*
  631. * From spc4r17, section 7.4.6 Control mode Page
  632. *
  633. * Task Aborted Status (TAS) bit set to zero.
  634. *
  635. * A task aborted status (TAS) bit set to zero specifies that aborted
  636. * tasks shall be terminated by the device server without any response
  637. * to the application client. A TAS bit set to one specifies that tasks
  638. * aborted by the actions of an I_T nexus other than the I_T nexus on
  639. * which the command was received shall be completed with TASK ABORTED
  640. * status (see SAM-4).
  641. */
  642. p[5] = (dev->dev_attrib.emulate_tas) ? 0x40 : 0x00;
  643. p[8] = 0xff;
  644. p[9] = 0xff;
  645. p[11] = 30;
  646. return 12;
  647. }
  648. static int spc_modesense_caching(struct se_device *dev, unsigned char *p)
  649. {
  650. p[0] = 0x08;
  651. p[1] = 0x12;
  652. if (dev->dev_attrib.emulate_write_cache > 0)
  653. p[2] = 0x04; /* Write Cache Enable */
  654. p[12] = 0x20; /* Disabled Read Ahead */
  655. return 20;
  656. }
  657. static void spc_modesense_write_protect(unsigned char *buf, int type)
  658. {
  659. /*
  660. * I believe that the WP bit (bit 7) in the mode header is the same for
  661. * all device types..
  662. */
  663. switch (type) {
  664. case TYPE_DISK:
  665. case TYPE_TAPE:
  666. default:
  667. buf[0] |= 0x80; /* WP bit */
  668. break;
  669. }
  670. }
  671. static void spc_modesense_dpofua(unsigned char *buf, int type)
  672. {
  673. switch (type) {
  674. case TYPE_DISK:
  675. buf[0] |= 0x10; /* DPOFUA bit */
  676. break;
  677. default:
  678. break;
  679. }
  680. }
  681. static int spc_emulate_modesense(struct se_cmd *cmd)
  682. {
  683. struct se_device *dev = cmd->se_dev;
  684. char *cdb = cmd->t_task_cdb;
  685. unsigned char *rbuf;
  686. int type = dev->transport->get_device_type(dev);
  687. int ten = (cmd->t_task_cdb[0] == MODE_SENSE_10);
  688. u32 offset = ten ? 8 : 4;
  689. int length = 0;
  690. unsigned char buf[SE_MODE_PAGE_BUF];
  691. memset(buf, 0, SE_MODE_PAGE_BUF);
  692. switch (cdb[2] & 0x3f) {
  693. case 0x01:
  694. length = spc_modesense_rwrecovery(&buf[offset]);
  695. break;
  696. case 0x08:
  697. length = spc_modesense_caching(dev, &buf[offset]);
  698. break;
  699. case 0x0a:
  700. length = spc_modesense_control(dev, &buf[offset]);
  701. break;
  702. case 0x3f:
  703. length = spc_modesense_rwrecovery(&buf[offset]);
  704. length += spc_modesense_caching(dev, &buf[offset+length]);
  705. length += spc_modesense_control(dev, &buf[offset+length]);
  706. break;
  707. default:
  708. pr_err("MODE SENSE: unimplemented page/subpage: 0x%02x/0x%02x\n",
  709. cdb[2] & 0x3f, cdb[3]);
  710. cmd->scsi_sense_reason = TCM_UNKNOWN_MODE_PAGE;
  711. return -EINVAL;
  712. }
  713. offset += length;
  714. if (ten) {
  715. offset -= 2;
  716. buf[0] = (offset >> 8) & 0xff;
  717. buf[1] = offset & 0xff;
  718. offset += 2;
  719. if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) ||
  720. (cmd->se_deve &&
  721. (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)))
  722. spc_modesense_write_protect(&buf[3], type);
  723. if ((dev->dev_attrib.emulate_write_cache > 0) &&
  724. (dev->dev_attrib.emulate_fua_write > 0))
  725. spc_modesense_dpofua(&buf[3], type);
  726. } else {
  727. offset -= 1;
  728. buf[0] = offset & 0xff;
  729. offset += 1;
  730. if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) ||
  731. (cmd->se_deve &&
  732. (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)))
  733. spc_modesense_write_protect(&buf[2], type);
  734. if ((dev->dev_attrib.emulate_write_cache > 0) &&
  735. (dev->dev_attrib.emulate_fua_write > 0))
  736. spc_modesense_dpofua(&buf[2], type);
  737. }
  738. rbuf = transport_kmap_data_sg(cmd);
  739. if (rbuf) {
  740. memcpy(rbuf, buf, min(offset, cmd->data_length));
  741. transport_kunmap_data_sg(cmd);
  742. }
  743. target_complete_cmd(cmd, GOOD);
  744. return 0;
  745. }
  746. static int spc_emulate_request_sense(struct se_cmd *cmd)
  747. {
  748. unsigned char *cdb = cmd->t_task_cdb;
  749. unsigned char *rbuf;
  750. u8 ua_asc = 0, ua_ascq = 0;
  751. unsigned char buf[SE_SENSE_BUF];
  752. memset(buf, 0, SE_SENSE_BUF);
  753. if (cdb[1] & 0x01) {
  754. pr_err("REQUEST_SENSE description emulation not"
  755. " supported\n");
  756. cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
  757. return -ENOSYS;
  758. }
  759. rbuf = transport_kmap_data_sg(cmd);
  760. if (cmd->scsi_sense_reason != 0) {
  761. /*
  762. * Out of memory. We will fail with CHECK CONDITION, so
  763. * we must not clear the unit attention condition.
  764. */
  765. target_complete_cmd(cmd, CHECK_CONDITION);
  766. return 0;
  767. } else if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) {
  768. /*
  769. * CURRENT ERROR, UNIT ATTENTION
  770. */
  771. buf[0] = 0x70;
  772. buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION;
  773. /*
  774. * The Additional Sense Code (ASC) from the UNIT ATTENTION
  775. */
  776. buf[SPC_ASC_KEY_OFFSET] = ua_asc;
  777. buf[SPC_ASCQ_KEY_OFFSET] = ua_ascq;
  778. buf[7] = 0x0A;
  779. } else {
  780. /*
  781. * CURRENT ERROR, NO SENSE
  782. */
  783. buf[0] = 0x70;
  784. buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE;
  785. /*
  786. * NO ADDITIONAL SENSE INFORMATION
  787. */
  788. buf[SPC_ASC_KEY_OFFSET] = 0x00;
  789. buf[7] = 0x0A;
  790. }
  791. if (rbuf) {
  792. memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
  793. transport_kunmap_data_sg(cmd);
  794. }
  795. target_complete_cmd(cmd, GOOD);
  796. return 0;
  797. }
  798. static int spc_emulate_report_luns(struct se_cmd *cmd)
  799. {
  800. struct se_dev_entry *deve;
  801. struct se_session *sess = cmd->se_sess;
  802. unsigned char *buf;
  803. u32 lun_count = 0, offset = 8, i;
  804. if (cmd->data_length < 16) {
  805. pr_warn("REPORT LUNS allocation length %u too small\n",
  806. cmd->data_length);
  807. cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
  808. return -EINVAL;
  809. }
  810. buf = transport_kmap_data_sg(cmd);
  811. if (!buf)
  812. return -ENOMEM;
  813. /*
  814. * If no struct se_session pointer is present, this struct se_cmd is
  815. * coming via a target_core_mod PASSTHROUGH op, and not through
  816. * a $FABRIC_MOD. In that case, report LUN=0 only.
  817. */
  818. if (!sess) {
  819. int_to_scsilun(0, (struct scsi_lun *)&buf[offset]);
  820. lun_count = 1;
  821. goto done;
  822. }
  823. spin_lock_irq(&sess->se_node_acl->device_list_lock);
  824. for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
  825. deve = sess->se_node_acl->device_list[i];
  826. if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS))
  827. continue;
  828. /*
  829. * We determine the correct LUN LIST LENGTH even once we
  830. * have reached the initial allocation length.
  831. * See SPC2-R20 7.19.
  832. */
  833. lun_count++;
  834. if ((offset + 8) > cmd->data_length)
  835. continue;
  836. int_to_scsilun(deve->mapped_lun, (struct scsi_lun *)&buf[offset]);
  837. offset += 8;
  838. }
  839. spin_unlock_irq(&sess->se_node_acl->device_list_lock);
  840. /*
  841. * See SPC3 r07, page 159.
  842. */
  843. done:
  844. lun_count *= 8;
  845. buf[0] = ((lun_count >> 24) & 0xff);
  846. buf[1] = ((lun_count >> 16) & 0xff);
  847. buf[2] = ((lun_count >> 8) & 0xff);
  848. buf[3] = (lun_count & 0xff);
  849. transport_kunmap_data_sg(cmd);
  850. target_complete_cmd(cmd, GOOD);
  851. return 0;
  852. }
  853. static int spc_emulate_testunitready(struct se_cmd *cmd)
  854. {
  855. target_complete_cmd(cmd, GOOD);
  856. return 0;
  857. }
  858. int spc_parse_cdb(struct se_cmd *cmd, unsigned int *size)
  859. {
  860. struct se_device *dev = cmd->se_dev;
  861. unsigned char *cdb = cmd->t_task_cdb;
  862. switch (cdb[0]) {
  863. case MODE_SELECT:
  864. *size = cdb[4];
  865. break;
  866. case MODE_SELECT_10:
  867. *size = (cdb[7] << 8) + cdb[8];
  868. break;
  869. case MODE_SENSE:
  870. *size = cdb[4];
  871. cmd->execute_cmd = spc_emulate_modesense;
  872. break;
  873. case MODE_SENSE_10:
  874. *size = (cdb[7] << 8) + cdb[8];
  875. cmd->execute_cmd = spc_emulate_modesense;
  876. break;
  877. case LOG_SELECT:
  878. case LOG_SENSE:
  879. *size = (cdb[7] << 8) + cdb[8];
  880. break;
  881. case PERSISTENT_RESERVE_IN:
  882. if (dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
  883. cmd->execute_cmd = target_scsi3_emulate_pr_in;
  884. *size = (cdb[7] << 8) + cdb[8];
  885. break;
  886. case PERSISTENT_RESERVE_OUT:
  887. if (dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
  888. cmd->execute_cmd = target_scsi3_emulate_pr_out;
  889. *size = (cdb[7] << 8) + cdb[8];
  890. break;
  891. case RELEASE:
  892. case RELEASE_10:
  893. if (cdb[0] == RELEASE_10)
  894. *size = (cdb[7] << 8) | cdb[8];
  895. else
  896. *size = cmd->data_length;
  897. if (dev->t10_pr.res_type != SPC_PASSTHROUGH)
  898. cmd->execute_cmd = target_scsi2_reservation_release;
  899. break;
  900. case RESERVE:
  901. case RESERVE_10:
  902. /*
  903. * The SPC-2 RESERVE does not contain a size in the SCSI CDB.
  904. * Assume the passthrough or $FABRIC_MOD will tell us about it.
  905. */
  906. if (cdb[0] == RESERVE_10)
  907. *size = (cdb[7] << 8) | cdb[8];
  908. else
  909. *size = cmd->data_length;
  910. /*
  911. * Setup the legacy emulated handler for SPC-2 and
  912. * >= SPC-3 compatible reservation handling (CRH=1)
  913. * Otherwise, we assume the underlying SCSI logic is
  914. * is running in SPC_PASSTHROUGH, and wants reservations
  915. * emulation disabled.
  916. */
  917. if (dev->t10_pr.res_type != SPC_PASSTHROUGH)
  918. cmd->execute_cmd = target_scsi2_reservation_reserve;
  919. break;
  920. case REQUEST_SENSE:
  921. *size = cdb[4];
  922. cmd->execute_cmd = spc_emulate_request_sense;
  923. break;
  924. case INQUIRY:
  925. *size = (cdb[3] << 8) + cdb[4];
  926. /*
  927. * Do implict HEAD_OF_QUEUE processing for INQUIRY.
  928. * See spc4r17 section 5.3
  929. */
  930. if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
  931. cmd->sam_task_attr = MSG_HEAD_TAG;
  932. cmd->execute_cmd = spc_emulate_inquiry;
  933. break;
  934. case SECURITY_PROTOCOL_IN:
  935. case SECURITY_PROTOCOL_OUT:
  936. *size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
  937. break;
  938. case EXTENDED_COPY:
  939. case READ_ATTRIBUTE:
  940. case RECEIVE_COPY_RESULTS:
  941. case WRITE_ATTRIBUTE:
  942. *size = (cdb[10] << 24) | (cdb[11] << 16) |
  943. (cdb[12] << 8) | cdb[13];
  944. break;
  945. case RECEIVE_DIAGNOSTIC:
  946. case SEND_DIAGNOSTIC:
  947. *size = (cdb[3] << 8) | cdb[4];
  948. break;
  949. case WRITE_BUFFER:
  950. *size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
  951. break;
  952. case REPORT_LUNS:
  953. cmd->execute_cmd = spc_emulate_report_luns;
  954. *size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
  955. /*
  956. * Do implict HEAD_OF_QUEUE processing for REPORT_LUNS
  957. * See spc4r17 section 5.3
  958. */
  959. if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
  960. cmd->sam_task_attr = MSG_HEAD_TAG;
  961. break;
  962. case TEST_UNIT_READY:
  963. cmd->execute_cmd = spc_emulate_testunitready;
  964. *size = 0;
  965. break;
  966. case MAINTENANCE_IN:
  967. if (dev->transport->get_device_type(dev) != TYPE_ROM) {
  968. /*
  969. * MAINTENANCE_IN from SCC-2
  970. * Check for emulated MI_REPORT_TARGET_PGS
  971. */
  972. if ((cdb[1] & 0x1f) == MI_REPORT_TARGET_PGS &&
  973. dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) {
  974. cmd->execute_cmd =
  975. target_emulate_report_target_port_groups;
  976. }
  977. *size = get_unaligned_be32(&cdb[6]);
  978. } else {
  979. /*
  980. * GPCMD_SEND_KEY from multi media commands
  981. */
  982. *size = get_unaligned_be16(&cdb[8]);
  983. }
  984. break;
  985. case MAINTENANCE_OUT:
  986. if (dev->transport->get_device_type(dev) != TYPE_ROM) {
  987. /*
  988. * MAINTENANCE_OUT from SCC-2
  989. * Check for emulated MO_SET_TARGET_PGS.
  990. */
  991. if (cdb[1] == MO_SET_TARGET_PGS &&
  992. dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) {
  993. cmd->execute_cmd =
  994. target_emulate_set_target_port_groups;
  995. }
  996. *size = get_unaligned_be32(&cdb[6]);
  997. } else {
  998. /*
  999. * GPCMD_SEND_KEY from multi media commands
  1000. */
  1001. *size = get_unaligned_be16(&cdb[8]);
  1002. }
  1003. break;
  1004. default:
  1005. pr_warn("TARGET_CORE[%s]: Unsupported SCSI Opcode"
  1006. " 0x%02x, sending CHECK_CONDITION.\n",
  1007. cmd->se_tfo->get_fabric_name(), cdb[0]);
  1008. cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
  1009. cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
  1010. return -EINVAL;
  1011. }
  1012. return 0;
  1013. }
  1014. EXPORT_SYMBOL(spc_parse_cdb);