30 #include <linux/net.h>
31 #include <linux/string.h>
34 #include <linux/slab.h>
38 #include <linux/export.h>
41 #include <scsi/scsi.h>
56 static struct se_hba *lun0_hba;
86 pr_err(
"TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
87 " Access for 0x%08x\n",
88 se_cmd->
se_tfo->get_fabric_name(),
90 spin_unlock_irqrestore(&se_sess->
se_node_acl->device_list_lock, flags);
107 spin_unlock_irqrestore(&se_sess->
se_node_acl->device_list_lock, flags);
115 if (unpacked_lun != 0) {
118 pr_err(
"TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
119 " Access for 0x%08x\n",
120 se_cmd->
se_tfo->get_fabric_name(),
134 se_lun = &se_sess->
se_tpg->tpg_virt_lun0;
160 spin_unlock_irqrestore(&dev->
stats_lock, flags);
195 spin_unlock_irqrestore(&se_sess->
se_node_acl->device_list_lock, flags);
198 pr_debug(
"TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
199 " Access for 0x%08x\n",
200 se_cmd->
se_tfo->get_fabric_name(),
220 spin_unlock_irqrestore(&se_tmr->
tmr_dev->se_tmr_lock, flags);
250 pr_err(
"%s device entries device pointer is"
251 " NULL, but Initiator has access.\n",
257 pr_err(
"%s device entries device pointer is"
258 " NULL, but Initiator has access.\n",
295 pr_err(
"%s device entries device pointer is"
296 " NULL, but Initiator has access.\n",
339 deve->
lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
371 pr_err(
"struct se_dev_entry->se_lun_acl"
372 " already set for demo mode -> explict"
373 " LUN ACL transition\n");
377 if (deve->
se_lun != lun) {
378 pr_err(
"struct se_dev_entry->se_lun does"
379 " match passed struct se_lun for demo mode"
380 " -> explict LUN ACL transition\n");
390 deve->
lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
407 deve->
lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
516 pr_err(
"Unable to allocate struct se_port\n");
527 pr_warn(
"Reached dev->dev_port_count =="
562 static void core_export_port(
583 if (IS_ERR(tg_pt_gp_mem) || !tg_pt_gp_mem) {
584 pr_err(
"Unable to allocate t10_alua_tg_pt"
592 pr_debug(
"%s/%s: Adding to default ALUA Target Port"
593 " Group: alua/default_tg_pt_gp\n",
630 port = core_alloc_port(dev);
632 return PTR_ERR(port);
638 core_export_port(dev, tpg, port, lun);
658 core_release_port(dev, port);
673 pr_warn(
"REPORT LUNS allocation length %u too small\n",
694 spin_lock_irq(&se_sess->
se_node_acl->device_list_lock);
711 spin_unlock_irq(&se_sess->
se_node_acl->device_list_lock);
718 buf[0] = ((lun_count >> 24) & 0xff);
719 buf[1] = ((lun_count >> 16) & 0xff);
720 buf[2] = ((lun_count >> 8) & 0xff);
721 buf[3] = (lun_count & 0xff);
764 spin_lock(&dev->
se_sub_dev->t10_wwn.t10_vpd_lock);
770 spin_unlock(&dev->
se_sub_dev->t10_wwn.t10_vpd_lock);
788 static void se_dev_start(
struct se_device *dev)
808 static void se_dev_stop(
struct se_device *dev)
853 u32 aligned_max_sectors;
860 aligned_max_sectors =
rounddown(max_sectors, alignment);
862 if (max_sectors != aligned_max_sectors)
863 pr_info(
"Rounding down aligned max_sectors from %u to %u\n",
864 max_sectors, aligned_max_sectors);
866 return aligned_max_sectors;
873 struct queue_limits *limits = &dev_limits->
limits;
894 dev->
se_sub_dev->se_dev_attrib.max_unmap_block_desc_count =
897 dev->
se_sub_dev->se_dev_attrib.unmap_granularity_alignment =
902 dev->
se_sub_dev->se_dev_attrib.hw_block_size = limits->logical_block_size;
903 dev->
se_sub_dev->se_dev_attrib.block_size = limits->logical_block_size;
907 limits->max_hw_sectors = se_dev_align_max_sectors(limits->max_hw_sectors,
908 limits->logical_block_size);
909 dev->
se_sub_dev->se_dev_attrib.hw_max_sectors = limits->max_hw_sectors;
930 u32 max_unmap_lba_count)
932 dev->
se_sub_dev->se_dev_attrib.max_unmap_lba_count = max_unmap_lba_count;
933 pr_debug(
"dev[%p]: Set max_unmap_lba_count: %u\n",
934 dev, dev->
se_sub_dev->se_dev_attrib.max_unmap_lba_count);
940 u32 max_unmap_block_desc_count)
942 dev->
se_sub_dev->se_dev_attrib.max_unmap_block_desc_count =
943 max_unmap_block_desc_count;
944 pr_debug(
"dev[%p]: Set max_unmap_block_desc_count: %u\n",
945 dev, dev->
se_sub_dev->se_dev_attrib.max_unmap_block_desc_count);
951 u32 unmap_granularity)
953 dev->
se_sub_dev->se_dev_attrib.unmap_granularity = unmap_granularity;
954 pr_debug(
"dev[%p]: Set unmap_granularity: %u\n",
955 dev, dev->
se_sub_dev->se_dev_attrib.unmap_granularity);
961 u32 unmap_granularity_alignment)
963 dev->
se_sub_dev->se_dev_attrib.unmap_granularity_alignment = unmap_granularity_alignment;
964 pr_debug(
"dev[%p]: Set unmap_granularity_alignment: %u\n",
965 dev, dev->
se_sub_dev->se_dev_attrib.unmap_granularity_alignment);
971 if (flag != 0 && flag != 1) {
972 pr_err(
"Illegal value %d\n", flag);
977 pr_err(
"dpo_emulated not supported\n");
986 if (flag != 0 && flag != 1) {
987 pr_err(
"Illegal value %d\n", flag);
993 pr_err(
"emulate_fua_write not supported for pSCSI\n");
997 pr_debug(
"dev[%p]: SE Device Forced Unit Access WRITEs: %d\n",
998 dev, dev->
se_sub_dev->se_dev_attrib.emulate_fua_write);
1004 if (flag != 0 && flag != 1) {
1005 pr_err(
"Illegal value %d\n", flag);
1010 pr_err(
"ua read emulated not supported\n");
1019 if (flag != 0 && flag != 1) {
1020 pr_err(
"Illegal value %d\n", flag);
1025 pr_err(
"emulate_write_cache not supported for pSCSI\n");
1029 pr_debug(
"dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n",
1030 dev, dev->
se_sub_dev->se_dev_attrib.emulate_write_cache);
1036 if ((flag != 0) && (flag != 1) && (flag != 2)) {
1037 pr_err(
"Illegal value %d\n", flag);
1042 pr_err(
"dev[%p]: Unable to change SE Device"
1043 " UA_INTRLCK_CTRL while dev_export_obj: %d count"
1049 pr_debug(
"dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n",
1050 dev, dev->
se_sub_dev->se_dev_attrib.emulate_ua_intlck_ctrl);
1057 if ((flag != 0) && (flag != 1)) {
1058 pr_err(
"Illegal value %d\n", flag);
1063 pr_err(
"dev[%p]: Unable to change SE Device TAS while"
1064 " dev_export_obj: %d count exists\n", dev,
1069 pr_debug(
"dev[%p]: SE Device TASK_ABORTED status bit: %s\n",
1070 dev, (dev->
se_sub_dev->se_dev_attrib.emulate_tas) ?
"Enabled" :
"Disabled");
1077 if ((flag != 0) && (flag != 1)) {
1078 pr_err(
"Illegal value %d\n", flag);
1085 if (flag && !dev->
se_sub_dev->se_dev_attrib.max_unmap_block_desc_count) {
1086 pr_err(
"Generic Block Discard not supported\n");
1091 pr_debug(
"dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n",
1098 if ((flag != 0) && (flag != 1)) {
1099 pr_err(
"Illegal value %d\n", flag);
1106 if (flag && !dev->
se_sub_dev->se_dev_attrib.max_unmap_block_desc_count) {
1107 pr_err(
"Generic Block Discard not supported\n");
1112 pr_debug(
"dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n",
1119 if ((flag != 0) && (flag != 1)) {
1120 pr_err(
"Illegal value %d\n", flag);
1124 pr_debug(
"dev[%p]: SE Device enforce_pr_isids bit: %s\n", dev,
1125 (dev->
se_sub_dev->se_dev_attrib.enforce_pr_isids) ?
"Enabled" :
"Disabled");
1131 if ((flag != 0) && (flag != 1)) {
1136 pr_debug(
"dev[%p]: SE Device is_nonrot bit: %d\n",
1145 " reordering not implemented\n", dev);
1149 pr_debug(
"dev[%p]: SE Device emulate_rest_reord: %d\n", dev, flag);
1159 pr_err(
"dev[%p]: Unable to change SE Device TCQ while"
1160 " dev_export_obj: %d count exists\n", dev,
1165 pr_err(
"dev[%p]: Illegal ZERO value for queue"
1171 if (queue_depth > dev->
se_sub_dev->se_dev_attrib.hw_queue_depth) {
1172 pr_err(
"dev[%p]: Passed queue_depth: %u"
1173 " exceeds TCM/SE_Device TCQ: %u\n",
1175 dev->
se_sub_dev->se_dev_attrib.hw_queue_depth);
1179 if (queue_depth > dev->
se_sub_dev->se_dev_attrib.queue_depth) {
1180 if (queue_depth > dev->
se_sub_dev->se_dev_attrib.hw_queue_depth) {
1181 pr_err(
"dev[%p]: Passed queue_depth:"
1182 " %u exceeds TCM/SE_Device MAX"
1183 " TCQ: %u\n", dev, queue_depth,
1184 dev->
se_sub_dev->se_dev_attrib.hw_queue_depth);
1191 pr_debug(
"dev[%p]: SE Device TCQ Depth changed to: %u\n",
1199 pr_err(
"dev[%p]: Unable to change SE Device"
1200 " fabric_max_sectors while dev_export_obj: %d count exists\n",
1204 if (!fabric_max_sectors) {
1205 pr_err(
"dev[%p]: Illegal ZERO value for"
1206 " fabric_max_sectors\n", dev);
1210 pr_err(
"dev[%p]: Passed fabric_max_sectors: %u less than"
1211 " DA_STATUS_MAX_SECTORS_MIN: %u\n", dev, fabric_max_sectors,
1216 if (fabric_max_sectors > dev->
se_sub_dev->se_dev_attrib.hw_max_sectors) {
1217 pr_err(
"dev[%p]: Passed fabric_max_sectors: %u"
1218 " greater than TCM/SE_Device max_sectors:"
1219 " %u\n", dev, fabric_max_sectors,
1220 dev->
se_sub_dev->se_dev_attrib.hw_max_sectors);
1225 pr_err(
"dev[%p]: Passed fabric_max_sectors: %u"
1226 " greater than DA_STATUS_MAX_SECTORS_MAX:"
1227 " %u\n", dev, fabric_max_sectors,
1235 fabric_max_sectors = se_dev_align_max_sectors(fabric_max_sectors,
1238 dev->
se_sub_dev->se_dev_attrib.fabric_max_sectors = fabric_max_sectors;
1239 pr_debug(
"dev[%p]: SE Device max_sectors changed to %u\n",
1240 dev, fabric_max_sectors);
1247 pr_err(
"dev[%p]: Unable to change SE Device"
1248 " optimal_sectors while dev_export_obj: %d count exists\n",
1253 pr_err(
"dev[%p]: Passed optimal_sectors cannot be"
1254 " changed for TCM/pSCSI\n", dev);
1257 if (optimal_sectors > dev->
se_sub_dev->se_dev_attrib.fabric_max_sectors) {
1258 pr_err(
"dev[%p]: Passed optimal_sectors %u cannot be"
1259 " greater than fabric_max_sectors: %u\n", dev,
1260 optimal_sectors, dev->
se_sub_dev->se_dev_attrib.fabric_max_sectors);
1264 dev->
se_sub_dev->se_dev_attrib.optimal_sectors = optimal_sectors;
1265 pr_debug(
"dev[%p]: SE Device optimal_sectors changed to %u\n",
1266 dev, optimal_sectors);
1273 pr_err(
"dev[%p]: Unable to change SE Device block_size"
1274 " while dev_export_obj: %d count exists\n", dev,
1279 if ((block_size != 512) &&
1280 (block_size != 1024) &&
1281 (block_size != 2048) &&
1282 (block_size != 4096)) {
1283 pr_err(
"dev[%p]: Illegal value for block_device: %u"
1284 " for SE device, must be 512, 1024, 2048 or 4096\n",
1290 pr_err(
"dev[%p]: Not allowed to change block_size for"
1291 " Physical Device, use for Linux/SCSI to change"
1292 " block_size for underlying hardware\n", dev);
1297 pr_debug(
"dev[%p]: SE Device block_size changed to %u\n",
1311 pr_err(
"Unable to export struct se_device while dev_access_obj: %d\n",
1325 pr_debug(
"%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from"
1326 " CORE HBA: %u\n", tpg->
se_tpg_tfo->get_fabric_name(),
1333 if (tpg->
se_tpg_tfo->tpg_check_demo_mode(tpg)) {
1338 (!tpg->
se_tpg_tfo->tpg_check_demo_mode_login_only ||
1339 !tpg->
se_tpg_tfo->tpg_check_demo_mode_login_only(tpg))) {
1363 return PTR_ERR(lun);
1367 pr_debug(
"%s_TPG[%u]_LUN[%u] - Deactivated %s Logical Unit from"
1368 " device object\n", tpg->
se_tpg_tfo->get_fabric_name(),
1381 pr_err(
"%s LUN: %u exceeds TRANSPORT_MAX_LUNS"
1382 "_PER_TPG-1: %u for Target Portal Group: %hu\n",
1392 pr_err(
"%s Logical Unit Number: %u is not free on"
1393 " Target Portal Group: %hu, ignoring request.\n",
1414 pr_err(
"%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER"
1415 "_TPG-1: %u for Target Portal Group: %hu\n",
1425 pr_err(
"%s Logical Unit Number: %u is not active on"
1426 " Target Portal Group: %hu, ignoring request.\n",
1447 pr_err(
"%s InitiatorName exceeds maximum size.\n",
1459 pr_err(
"Unable to allocate memory for struct se_lun_acl.\n");
1481 lun = core_dev_get_lun(tpg, unpacked_lun);
1483 pr_err(
"%s Logical Unit Number: %u is not active on"
1484 " Target Portal Group: %hu, ignoring request.\n",
1485 tpg->
se_tpg_tfo->get_fabric_name(), unpacked_lun,
1501 lun_access, nacl, tpg) < 0)
1510 pr_debug(
"%s_TPG[%hu]_LUN[%u->%u] - Added %s ACL for "
1511 " InitiatorNode: %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
1549 pr_debug(
"%s_TPG[%hu]_LUN[%u] - Removed ACL for"
1550 " InitiatorNode: %s Mapped LUN: %u\n",
1562 pr_debug(
"%s_TPG[%hu] - Freeing ACL for %s InitiatorNode: %s"
1563 " Mapped LUN: %u\n", tpg->
se_tpg_tfo->get_fabric_name(),
1582 return PTR_ERR(hba);
1589 pr_err(
"Unable to allocate memory for"
1590 " struct se_subsystem_dev\n");
1594 INIT_LIST_HEAD(&se_dev->
t10_wwn.t10_vpd_list);
1596 INIT_LIST_HEAD(&se_dev->
t10_pr.registration_list);
1597 INIT_LIST_HEAD(&se_dev->
t10_pr.aptpl_reg_list);
1600 INIT_LIST_HEAD(&se_dev->
t10_alua.tg_pt_gps_list);
1604 se_dev->
t10_wwn.t10_sub_dev = se_dev;
1605 se_dev->
t10_alua.t10_sub_dev = se_dev;
1611 pr_err(
"Unable to locate subsystem dependent pointer"
1612 " from allocate_virtdevice()\n");
1616 lun0_su_dev = se_dev;
1644 struct se_hba *hba = lun0_hba;