Lines Matching +full:lbp +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Copyright (C) 2001 - 2021 Douglas Gilbert
33 #include <linux/crc-t10dif.h>
39 #include <linux/t10-pi.h>
155 #define DEF_SCSI_LEVEL 7 /* INQUIRY, byte2 [6->SPC-4; 7->SPC-5] */
175 #define JDELAY_OVERRIDDEN -9999
244 /* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs) are returned in
267 * per-device DEF_CMD_PER_LUN can be changed via sysfs:
275 /* UA - Unit Attention; SA - Service Action; SSU - Start Stop Unit */
276 #define F_D_IN 1 /* Data-in command (e.g. READ) */
277 #define F_D_OUT 2 /* Data-out command (e.g. WRITE) */
280 #define F_RL_WLUN_OK 0x10 /* allowed with REPORT LUNS W-LUN */
288 #define F_SSU_DELAY 0x1000 /* SSU command delay (long-ish) */
442 rwlock_t macc_sector_lck; /* per-sector media data access on this store */
452 dev_to_sdebug_host(shost->dma_dev)
484 u32 flags; /* OR-ed set of SDEB_F_* */
487 u8 len_mask[16]; /* len_mask[0]-->cdb_len, then mask for cdb */
524 SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */
537 /* 0x0; 0x0->0x1f: 6 byte cdbs */
545 /* 0x20; 0x20->0x3f: 10 byte cdbs */
550 /* 0x40; 0x40->0x5f: 10 byte cdbs */
556 /* 0x60; 0x60->0x7d are reserved, 0x7e is "extended cdb" */
560 /* 0x80; 0x80->0x9f: 16 byte cdbs */
568 /* 0xa0; 0xa0->0xbf: 12 byte cdbs */
575 /* 0xc0; 0xc0->0xff: vendor specific */
583 * The following "response" functions return the SCSI mid-level's 4 byte
584 * tuple-in-an-int. To handle commands with an IMMED bit, for a faster
741 0xff, 0xff, 0xff, 0xff, 0x3f, 0xc7} }, /* PRE-FETCH (16) */
864 0, 0, 0, 0} }, /* PRE-FETCH (10) */
992 static int sdeb_first_idx = -1; /* invalid index ==> none created */
993 static int sdeb_most_recent_idx = -1;
1007 static bool sdeb_zbc_in_use; /* true for host-aware and host-managed disks */
1013 static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */
1044 unsigned char devtype = sdp->type; in sdebug_get_devsel()
1065 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata; in sdebug_err_add()
1068 spin_lock(&devip->list_lock); in sdebug_err_add()
1069 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_err_add()
1070 if (err->type == new->type && err->cmd == new->cmd) { in sdebug_err_add()
1071 list_del_rcu(&err->list); in sdebug_err_add()
1072 call_rcu(&err->rcu, sdebug_err_free); in sdebug_err_add()
1076 list_add_tail_rcu(&new->list, &devip->inject_err_list); in sdebug_err_add()
1077 spin_unlock(&devip->list_lock); in sdebug_err_add()
1082 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata; in sdebug_err_remove()
1087 if (sscanf(buf, "- %d %hhx", &type, &cmd) != 2) { in sdebug_err_remove()
1089 return -EINVAL; in sdebug_err_remove()
1092 spin_lock(&devip->list_lock); in sdebug_err_remove()
1093 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_err_remove()
1094 if (err->type == type && err->cmd == cmd) { in sdebug_err_remove()
1095 list_del_rcu(&err->list); in sdebug_err_remove()
1096 call_rcu(&err->rcu, sdebug_err_free); in sdebug_err_remove()
1097 spin_unlock(&devip->list_lock); in sdebug_err_remove()
1102 spin_unlock(&devip->list_lock); in sdebug_err_remove()
1105 return -EINVAL; in sdebug_err_remove()
1110 struct scsi_device *sdev = (struct scsi_device *)m->private; in sdebug_error_show()
1111 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata; in sdebug_error_show()
1117 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_error_show()
1118 switch (err->type) { in sdebug_error_show()
1122 seq_printf(m, "%d\t%d\t0x%x\n", err->type, err->cnt, in sdebug_error_show()
1123 err->cmd); in sdebug_error_show()
1127 seq_printf(m, "%d\t%d\t0x%x\t0x%x\n", err->type, in sdebug_error_show()
1128 err->cnt, err->cmd, err->queuecmd_ret); in sdebug_error_show()
1133 err->type, err->cnt, err->cmd, in sdebug_error_show()
1134 err->host_byte, err->driver_byte, in sdebug_error_show()
1135 err->status_byte, err->sense_key, in sdebug_error_show()
1136 err->asc, err->asq); in sdebug_error_show()
1147 return single_open(file, sdebug_error_show, inode->i_private); in sdebug_error_open()
1156 struct scsi_device *sdev = (struct scsi_device *)file->f_inode->i_private; in sdebug_error_write()
1160 return -ENOMEM; in sdebug_error_write()
1164 return -EFAULT; in sdebug_error_write()
1167 if (buf[0] == '-') in sdebug_error_write()
1172 return -EINVAL; in sdebug_error_write()
1178 return -ENOMEM; in sdebug_error_write()
1185 if (sscanf(buf, "%d %d %hhx", &inject->type, &inject->cnt, in sdebug_error_write()
1186 &inject->cmd) != 3) in sdebug_error_write()
1191 if (sscanf(buf, "%d %d %hhx %x", &inject->type, &inject->cnt, in sdebug_error_write()
1192 &inject->cmd, &inject->queuecmd_ret) != 4) in sdebug_error_write()
1198 &inject->type, &inject->cnt, &inject->cmd, in sdebug_error_write()
1199 &inject->host_byte, &inject->driver_byte, in sdebug_error_write()
1200 &inject->status_byte, &inject->sense_key, in sdebug_error_write()
1201 &inject->asc, &inject->asq) != 9) in sdebug_error_write()
1218 return -EINVAL; in sdebug_error_write()
1230 struct scsi_target *starget = (struct scsi_target *)m->private; in sdebug_target_reset_fail_show()
1232 (struct sdebug_target_info *)starget->hostdata; in sdebug_target_reset_fail_show()
1235 seq_printf(m, "%c\n", targetip->reset_fail ? 'Y' : 'N'); in sdebug_target_reset_fail_show()
1242 return single_open(file, sdebug_target_reset_fail_show, inode->i_private); in sdebug_target_reset_fail_open()
1250 (struct scsi_target *)file->f_inode->i_private; in sdebug_target_reset_fail_write()
1252 (struct sdebug_target_info *)starget->hostdata; in sdebug_target_reset_fail_write()
1255 ret = kstrtobool_from_user(ubuf, count, &targetip->reset_fail); in sdebug_target_reset_fail_write()
1258 return -ENODEV; in sdebug_target_reset_fail_write()
1274 return -ENOMEM; in sdebug_target_alloc()
1278 targetip->debugfs_entry = debugfs_create_dir(dev_name(&starget->dev), in sdebug_target_alloc()
1281 debugfs_create_file("fail_reset", 0600, targetip->debugfs_entry, starget, in sdebug_target_alloc()
1284 starget->hostdata = targetip; in sdebug_target_alloc()
1293 debugfs_remove(targetip->debugfs_entry); in sdebug_tartget_cleanup_async()
1301 targetip = (struct sdebug_target_info *)starget->hostdata; in sdebug_target_destroy()
1303 starget->hostdata = NULL; in sdebug_target_destroy()
1330 if (!sip || !sip->storep) { in lba2fake_store()
1334 return lsip->storep + lba * sdebug_sector_size; in lba2fake_store()
1342 return sip->dif_storep + sector; in dif_store()
1352 hpnt = sdbg_host->shost; in sdebug_max_tgts_luns()
1353 if ((hpnt->this_id >= 0) && in sdebug_max_tgts_luns()
1354 (sdebug_num_tgts > hpnt->this_id)) in sdebug_max_tgts_luns()
1355 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_max_tgts_luns()
1357 hpnt->max_id = sdebug_num_tgts; in sdebug_max_tgts_luns()
1359 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_max_tgts_luns()
1366 /* Set in_bit to -1 to indicate no bit position of invalid field */
1375 sbuff = scp->sense_buffer; in mk_sense_invalid_fld()
1377 sdev_printk(KERN_ERR, scp->device, in mk_sense_invalid_fld()
1402 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq" in mk_sense_invalid_fld()
1409 if (!scp->sense_buffer) { in mk_sense_buffer()
1410 sdev_printk(KERN_ERR, scp->device, in mk_sense_buffer()
1414 memset(scp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in mk_sense_buffer()
1419 sdev_printk(KERN_INFO, scp->device, in mk_sense_buffer()
1428 if (!scp->sense_buffer) { in mk_sense_info_tape()
1429 sdev_printk(KERN_ERR, scp->device, in mk_sense_info_tape()
1433 memset(scp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in mk_sense_info_tape()
1438 scp->sense_buffer[0] |= 0x80; /* valid */ in mk_sense_info_tape()
1439 scp->sense_buffer[2] |= tape_flags; in mk_sense_info_tape()
1440 put_unaligned_be32(information, &scp->sense_buffer[3]); in mk_sense_info_tape()
1443 sdev_printk(KERN_INFO, scp->device, in mk_sense_info_tape()
1468 return -EINVAL; in scsi_debug_ioctl()
1469 /* return -ENOTTY; // correct return but upsets fdisk */ in scsi_debug_ioctl()
1476 sdev->use_10_for_rw = false; in config_cdb_len()
1477 sdev->use_16_for_rw = false; in config_cdb_len()
1478 sdev->use_10_for_ms = false; in config_cdb_len()
1481 sdev->use_10_for_rw = true; in config_cdb_len()
1482 sdev->use_16_for_rw = false; in config_cdb_len()
1483 sdev->use_10_for_ms = false; in config_cdb_len()
1486 sdev->use_10_for_rw = true; in config_cdb_len()
1487 sdev->use_16_for_rw = false; in config_cdb_len()
1488 sdev->use_10_for_ms = true; in config_cdb_len()
1491 sdev->use_10_for_rw = false; in config_cdb_len()
1492 sdev->use_16_for_rw = true; in config_cdb_len()
1493 sdev->use_10_for_ms = true; in config_cdb_len()
1496 sdev->use_10_for_rw = false; in config_cdb_len()
1497 sdev->use_16_for_rw = true; in config_cdb_len()
1498 sdev->use_10_for_ms = true; in config_cdb_len()
1503 sdev->use_10_for_rw = true; in config_cdb_len()
1504 sdev->use_16_for_rw = false; in config_cdb_len()
1505 sdev->use_10_for_ms = false; in config_cdb_len()
1519 shost = sdbg_host->shost; in all_config_cdb_len()
1529 struct sdebug_host_info *sdhp = devip->sdbg_host; in clear_luns_changed_on_target()
1532 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in clear_luns_changed_on_target()
1533 if ((devip->sdbg_host == dp->sdbg_host) && in clear_luns_changed_on_target()
1534 (devip->target == dp->target)) { in clear_luns_changed_on_target()
1535 clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in clear_luns_changed_on_target()
1544 k = find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS); in make_ua()
1595 * SPC-3 behavior is to report a UNIT ATTENTION with in make_ua()
1598 * received. SPC-4 behavior is to report it only once. in make_ua()
1600 * values as struct scsi_device->scsi_level. in make_ua()
1602 if (sdebug_scsi_level >= 6) /* SPC-4 and above */ in make_ua()
1622 clear_bit(k, devip->uas_bm); in make_ua()
1624 sdev_printk(KERN_INFO, scp->device, in make_ua()
1632 /* Build SCSI "data-in" buffer. Returns 0 if ok else (DID_ERROR << 16). */
1637 struct scsi_data_buffer *sdb = &scp->sdb; in fill_from_dev_buffer()
1639 if (!sdb->length) in fill_from_dev_buffer()
1641 if (scp->sc_data_direction != DMA_FROM_DEVICE) in fill_from_dev_buffer()
1644 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, in fill_from_dev_buffer()
1646 scsi_set_resid(scp, scsi_bufflen(scp) - act_len); in fill_from_dev_buffer()
1651 /* Partial build of SCSI "data-in" buffer. Returns 0 if ok else
1652 * (DID_ERROR << 16). Can write to offset in data-in buffer. If multiple
1660 struct scsi_data_buffer *sdb = &scp->sdb; in p_fill_from_dev_buffer()
1663 if (sdb->length <= off_dst) in p_fill_from_dev_buffer()
1665 if (scp->sc_data_direction != DMA_FROM_DEVICE) in p_fill_from_dev_buffer()
1668 act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents, in p_fill_from_dev_buffer()
1673 n = scsi_bufflen(scp) - (off_dst + act_len); in p_fill_from_dev_buffer()
1678 /* Fetches from SCSI "data-out" buffer. Returns number of bytes fetched into
1679 * 'arr' or -1 if error.
1686 if (scp->sc_data_direction != DMA_TO_DEVICE) in fetch_to_dev_buffer()
1687 return -1; in fetch_to_dev_buffer()
1733 /* NAA-3, Logical unit identifier (binary) */ in inquiry_vpd_83()
1751 /* NAA-3, Target port identifier */ in inquiry_vpd_83()
1758 /* NAA-3, Target port group identifier */ in inquiry_vpd_83()
1767 /* NAA-3, Target device identifier */ in inquiry_vpd_83()
1775 arr[num++] = 0x63; /* proto=sas, UTF-8 */ in inquiry_vpd_83()
1819 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1831 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1853 /* naa-5 target port identifier (A) */ in inquiry_vpd_88()
1868 /* naa-5 target port identifier (B) */ in inquiry_vpd_88()
1939 /* Block limits VPD page (SBC-3) */
1992 /* Block device characteristics VPD page (SBC-3) */
2004 /* Logical block provisioning VPD page (SBC-4) */
2030 * Optimal number of non-sequentially written sequential write in inquiry_vpd_b6()
2036 if (sdeb_zbc_model == BLK_ZONED_HM && devip->max_open) in inquiry_vpd_b6()
2037 put_unaligned_be32(devip->max_open, &arr[12]); in inquiry_vpd_b6()
2040 if (devip->zcap < devip->zsize) { in inquiry_vpd_b6()
2042 put_unaligned_be64(devip->zsize, &arr[20]); in inquiry_vpd_b6()
2053 /* Block limits extension VPD page (SBC-4) */
2069 unsigned char *cmd = scp->cmnd; in resp_inquiry()
2078 if (scp->device->type >= 32) { in resp_inquiry()
2082 is_disk = (scp->device->type == TYPE_DISK); in resp_inquiry()
2083 is_tape = (scp->device->type == TYPE_TAPE); in resp_inquiry()
2085 is_zbc = devip->zoned; in resp_inquiry()
2087 have_wlun = scsi_is_wlun(scp->device->lun); in resp_inquiry()
2090 else if (sdebug_no_lun_0 && (devip->lun == SDEBUG_LUN_0_VAL)) in resp_inquiry()
2093 pq_pdt = ((scp->device->type >= 32 ? in resp_inquiry()
2094 sdebug_ptype : scp->device->type) & 0x1f); in resp_inquiry()
2104 int host_no = devip->sdbg_host->shost->host_no; in resp_inquiry()
2108 (devip->channel & 0x7f); in resp_inquiry()
2111 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) + in resp_inquiry()
2112 (devip->target * 1000) + devip->lun); in resp_inquiry()
2114 (devip->target * 1000) - 3; in resp_inquiry()
2136 arr[3] = n - 4; /* number of supported VPD pages */ in resp_inquiry()
2144 &devip->lu_name); in resp_inquiry()
2164 arr[4] = 0x2; /* disconnect-reconnect mp */ in resp_inquiry()
2184 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_inquiry()
2198 arr[4] = SDEBUG_LONG_INQ_SZ - 5; in resp_inquiry()
2211 put_unaligned_be16(0xc0, arr + 58); /* SAM-6 no version claimed */ in resp_inquiry()
2212 put_unaligned_be16(0x5c0, arr + 60); /* SPC-5 no version claimed */ in resp_inquiry()
2214 if (is_disk) { /* SBC-4 no version claimed */ in resp_inquiry()
2217 } else if (is_tape) { /* SSC-4 rev 3 */ in resp_inquiry()
2224 put_unaligned_be16(0x2100, arr + n); /* SPL-4 no version claimed */ in resp_inquiry()
2238 unsigned char *cmd = scp->cmnd; in resp_requests()
2243 int stopped_state = atomic_read(&devip->stopped); in resp_requests()
2291 unsigned char *cmd = scp->cmnd; in resp_start_stop()
2301 stopped_state = atomic_read(&devip->stopped); in resp_start_stop()
2305 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_start_stop()
2306 u64 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_start_stop()
2310 atomic_set(&devip->stopped, 0); in resp_start_stop()
2325 atomic_xchg(&devip->stopped, want_stop); in resp_start_stop()
2326 if (scp->device->type == TYPE_TAPE && !want_stop) { in resp_start_stop()
2329 set_bit(SDEBUG_UA_NOT_READY_TO_READY, devip->uas_bm); /* not legal! */ in resp_start_stop()
2331 devip->tape_location[i] = 0; in resp_start_stop()
2332 devip->tape_partition = 0; in resp_start_stop()
2362 capac = (unsigned int)sdebug_capacity - 1; in resp_readcap()
2374 unsigned char *cmd = scp->cmnd; in resp_readcap16()
2382 put_unaligned_be64((u64)(sdebug_capacity - 1), arr + 0); in resp_readcap16()
2399 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices. in resp_readcap16()
2401 if (devip->zoned) in resp_readcap16()
2407 arr[12] = (sdebug_dif - 1) << 1; /* P_TYPE */ in resp_readcap16()
2420 unsigned char *cmd = scp->cmnd; in resp_report_tgtpgs()
2422 int host_no = devip->sdbg_host->shost->host_no; in resp_report_tgtpgs()
2440 (devip->channel & 0x7f); in resp_report_tgtpgs()
2442 (devip->channel & 0x7f) + 0x80; in resp_report_tgtpgs()
2478 rlen = n - 4; in resp_report_tgtpgs()
2483 * - The allocated length in resp_report_tgtpgs()
2484 * - The constructed command length in resp_report_tgtpgs()
2485 * - The maximum array size in resp_report_tgtpgs()
2505 u8 *cmd = scp->cmnd; in resp_rsup_opcodes()
2506 u32 devsel = sdebug_get_devsel(scp->device); in resp_rsup_opcodes()
2514 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_opcodes()
2531 oip->num_attached != 0xff && offset < a_len; ++oip) { in resp_rsup_opcodes()
2532 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2534 if ((devsel & oip->devsel) != 0) { in resp_rsup_opcodes()
2535 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2536 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2539 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2541 put_unaligned_be16(oip->len_mask[0], arr + offset + 6); in resp_rsup_opcodes()
2546 na = oip->num_attached; in resp_rsup_opcodes()
2548 for (k = 0, oip = oip->arrp; k < na; ++k, ++oip) { in resp_rsup_opcodes()
2549 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2551 if ((devsel & oip->devsel) == 0) in resp_rsup_opcodes()
2553 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2554 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2557 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2559 put_unaligned_be16(oip->len_mask[0], in resp_rsup_opcodes()
2568 put_unaligned_be32(offset - 4, arr); in resp_rsup_opcodes()
2575 if (F_INV_OP & oip->flags) { in resp_rsup_opcodes()
2580 if (FF_SA & oip->flags) { in resp_rsup_opcodes()
2588 0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2589 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); in resp_rsup_opcodes()
2593 if (0 == (FF_SA & oip->flags) && in resp_rsup_opcodes()
2594 (devsel & oip->devsel) != 0 && in resp_rsup_opcodes()
2595 req_opcode == oip->opcode) in resp_rsup_opcodes()
2597 else if (0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2598 na = oip->num_attached; in resp_rsup_opcodes()
2599 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2601 if (req_opcode == oip->opcode && in resp_rsup_opcodes()
2602 (devsel & oip->devsel) != 0) in resp_rsup_opcodes()
2606 } else if (req_sa != oip->sa) { in resp_rsup_opcodes()
2607 na = oip->num_attached; in resp_rsup_opcodes()
2608 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2610 if (req_sa == oip->sa && in resp_rsup_opcodes()
2611 (devsel & oip->devsel) != 0) in resp_rsup_opcodes()
2618 u = oip->len_mask[0]; in resp_rsup_opcodes()
2620 arr[4] = oip->opcode; in resp_rsup_opcodes()
2623 oip->len_mask[k] : 0xff; in resp_rsup_opcodes()
2652 u8 *cmd = scp->cmnd; in resp_rsup_tmfs()
2658 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_tmfs()
2676 { /* Read-Write Error Recovery page for mode_sense */ in resp_err_recov_pg()
2684 memset(p + 2, 0, sizeof(err_recov_pg) - 2); in resp_err_recov_pg()
2689 { /* Disconnect-Reconnect page for mode_sense */ in resp_disconnect_pg()
2697 memset(p + 2, 0, sizeof(disconnect_pg) - 2); in resp_disconnect_pg()
2715 memset(p + 2, 0, sizeof(format_pg) - 2); in resp_format_pg()
2786 .page_length = cpu_to_be16(sizeof(gr_m_pg) - 4), in resp_grouping_m_pg()
2802 memset(p + 4, 0, sizeof(gr_m_pg) - 4); in resp_grouping_m_pg()
2827 { /* SAS SSP mode page - short format for mode_sense */ in resp_sas_sf_m_pg()
2834 memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2); in resp_sas_sf_m_pg()
2868 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); in resp_sas_pcd_m_spg()
2881 memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4); in resp_sas_sha_m_spg()
2892 memset(p + 2, 0, sizeof(partition_pg) - 2); in resp_partition_m_pg()
2903 devip->tape_pending_nbr_partitions = TAPE_MAX_PARTITIONS; in process_medium_part_m_pg()
2904 devip->tape_pending_part_0_size = TAPE_UNITS - TAPE_PARTITION_1_UNITS; in process_medium_part_m_pg()
2905 devip->tape_pending_part_1_size = TAPE_PARTITION_1_UNITS; in process_medium_part_m_pg()
2912 p0_size = TAPE_UNITS - p1_size; in process_medium_part_m_pg()
2920 p1_size = TAPE_UNITS - p0_size; in process_medium_part_m_pg()
2922 p0_size = TAPE_UNITS - p1_size; in process_medium_part_m_pg()
2931 devip->tape_pending_nbr_partitions = new_nbr; in process_medium_part_m_pg()
2932 devip->tape_pending_part_0_size = p0_size; in process_medium_part_m_pg()
2933 devip->tape_pending_part_1_size = p1_size; in process_medium_part_m_pg()
2935 devip->tape_pending_nbr_partitions = new_nbr; in process_medium_part_m_pg()
2953 memset(p + 2, 0, sizeof(compression_pg) - 2); in resp_compression_m_pg()
2967 int target = scp->device->id; in resp_mode_sense()
2970 unsigned char *cmd = scp->cmnd; in resp_mode_sense()
2975 return -ENOMEM; in resp_mode_sense()
2982 is_disk = (scp->device->type == TYPE_DISK); in resp_mode_sense()
2983 is_zbc = devip->zoned; in resp_mode_sense()
2984 is_tape = (scp->device->type == TYPE_TAPE); in resp_mode_sense()
2994 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + in resp_mode_sense()
2995 (devip->target * 1000) - 3; in resp_mode_sense()
2998 dev_spec = 0x10; /* =0x90 if WP=1 implies read-only */ in resp_mode_sense()
3024 ap[0] = devip->tape_density; in resp_mode_sense()
3025 put_unaligned_be16(devip->tape_blksize, ap + 6); in resp_mode_sense()
3048 case 0x1: /* Read-Write error recovery page, direct access */ in resp_mode_sense()
3054 case 0x2: /* Disconnect-Reconnect page, all devices */ in resp_mode_sense()
3100 len = resp_compression_m_pg(ap, pcontrol, target, devip->tape_dce); in resp_mode_sense()
3156 arr[0] = offset - 1; in resp_mode_sense()
3158 put_unaligned_be16((offset - 2), arr + 0); in resp_mode_sense()
3166 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
3178 unsigned char *cmd = scp->cmnd; in resp_mode_select()
3186 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1); in resp_mode_select()
3190 if (-1 == res) in resp_mode_select()
3193 sdev_printk(KERN_INFO, scp->device, in resp_mode_select()
3199 if (scp->device->type == TYPE_TAPE) { in resp_mode_select()
3204 mselect6 ? 3 : 6, -1); in resp_mode_select()
3208 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); in resp_mode_select()
3216 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 1, -1); in resp_mode_select()
3219 devip->tape_density = arr[off]; in resp_mode_select()
3220 devip->tape_blksize = blksize; in resp_mode_select()
3226 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); in resp_mode_select()
3247 sizeof(caching_pg) - 2); in resp_mode_select()
3254 sizeof(ctrl_m_pg) - 2); in resp_mode_select()
3264 if (scp->device->type != TYPE_TAPE) in resp_mode_select()
3267 devip->tape_dce = (arr[off + 2] & 0x80) != 0; in resp_mode_select()
3272 if (scp->device->type == TYPE_TAPE) { in resp_mode_select()
3278 mk_sense_invalid_fld(scp, SDEB_IN_DATA, fld, -1); in resp_mode_select()
3285 sizeof(iec_m_pg) - 2); in resp_mode_select()
3295 set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm); in resp_mode_select()
3349 unsigned char *cmd = scp->cmnd; in resp_log_sense()
3369 arr[3] = n - 4; in resp_log_sense()
3401 arr[3] = n - 4; in resp_log_sense()
3411 arr[3] = n - 4; in resp_log_sense()
3419 arr[3] = n - 4; in resp_log_sense()
3435 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_log_sense()
3458 unsigned char *cmd = scp->cmnd; in resp_locate()
3464 if (cmd[8] >= devip->tape_nbr_partitions) { in resp_locate()
3465 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 8, -1); in resp_locate()
3468 devip->tape_partition = cmd[8]; in resp_locate()
3471 partition = devip->tape_partition; in resp_locate()
3473 for (i = 0, blp = devip->tape_blocks[partition]; in resp_locate()
3474 i < pos && i < devip->tape_eop[partition]; i++, blp++) in resp_locate()
3475 if (IS_TAPE_BLOCK_EOD(blp->fl_size)) in resp_locate()
3478 devip->tape_location[partition] = i; in resp_locate()
3482 devip->tape_location[partition] = pos; in resp_locate()
3490 unsigned char *cmd = scp->cmnd; in resp_write_filemarks()
3493 int partition = devip->tape_partition; in resp_write_filemarks()
3495 if ((cmd[1] & 0xfe) != 0) { /* probably write setmarks, not in >= SCSI-3 */ in resp_write_filemarks()
3501 for (i = 0, pos = devip->tape_location[partition]; i < count; i++, pos++) { in resp_write_filemarks()
3502 if (pos >= devip->tape_eop[partition] - 1) { /* don't overwrite EOD */ in resp_write_filemarks()
3503 devip->tape_location[partition] = devip->tape_eop[partition] - 1; in resp_write_filemarks()
3508 (devip->tape_blocks[partition] + pos)->fl_size = data; in resp_write_filemarks()
3510 (devip->tape_blocks[partition] + pos)->fl_size = in resp_write_filemarks()
3512 devip->tape_location[partition] = pos; in resp_write_filemarks()
3520 unsigned char *cmd = scp->cmnd, code; in resp_space()
3523 int partition = devip->tape_partition; in resp_space()
3526 if ((count & 0x800000) != 0) /* extend negative to 32-bit count */ in resp_space()
3530 pos = devip->tape_location[partition]; in resp_space()
3533 count = (-count); in resp_space()
3534 pos -= 1; in resp_space()
3535 for (i = 0, blp = devip->tape_blocks[partition] + pos; i < count; in resp_space()
3539 else if (IS_TAPE_BLOCK_FM(blp->fl_size)) in resp_space()
3542 pos--; in resp_space()
3543 blp--; in resp_space()
3547 for (i = 0, blp = devip->tape_blocks[partition] + pos; i < count; in resp_space()
3549 if (IS_TAPE_BLOCK_EOD(blp->fl_size)) in resp_space()
3551 if (IS_TAPE_BLOCK_FM(blp->fl_size)) { in resp_space()
3555 if (pos >= devip->tape_eop[partition]) in resp_space()
3561 count = (-count); in resp_space()
3565 for (i = 0, blp = devip->tape_blocks[partition] + pos; in resp_space()
3566 i < count && pos >= 0; i++, pos--, blp--) { in resp_space()
3567 for (pos--, blp-- ; !IS_TAPE_BLOCK_FM(blp->fl_size) && in resp_space()
3568 pos >= 0; pos--, blp--) in resp_space()
3576 for (i = 0, blp = devip->tape_blocks[partition] + pos; in resp_space()
3578 for ( ; !IS_TAPE_BLOCK_FM(blp->fl_size) && in resp_space()
3579 !IS_TAPE_BLOCK_EOD(blp->fl_size) && in resp_space()
3580 pos < devip->tape_eop[partition]; in resp_space()
3583 if (IS_TAPE_BLOCK_EOD(blp->fl_size)) in resp_space()
3585 if (pos >= devip->tape_eop[partition]) in resp_space()
3590 for (blp = devip->tape_blocks[partition] + pos; in resp_space()
3591 !IS_TAPE_BLOCK_EOD(blp->fl_size) && pos < devip->tape_eop[partition]; in resp_space()
3594 if (pos >= devip->tape_eop[partition]) in resp_space()
3598 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 8, -1); in resp_space()
3601 devip->tape_location[partition] = pos; in resp_space()
3605 devip->tape_location[partition] = pos; in resp_space()
3607 FILEMARK_DETECTED_ASCQ, count - i, in resp_space()
3612 devip->tape_location[partition] = pos; in resp_space()
3614 EOD_DETECTED_ASCQ, count - i, in resp_space()
3619 devip->tape_location[partition] = 0; in resp_space()
3621 BEGINNING_OF_P_M_DETECTED_ASCQ, count - i, in resp_space()
3623 devip->tape_location[partition] = 0; in resp_space()
3627 devip->tape_location[partition] = devip->tape_eop[partition] - 1; in resp_space()
3638 u8 *cmd = scp->cmnd; in resp_read_position()
3651 arr[1] = devip->tape_partition; in resp_read_position()
3652 pos = devip->tape_location[devip->tape_partition]; in resp_read_position()
3661 devip->tape_location[devip->tape_partition] = 0; in resp_rewind()
3672 return -1; in partition_tape()
3673 devip->tape_eop[0] = part_0_size; in partition_tape()
3674 devip->tape_blocks[0]->fl_size = TAPE_BLOCK_EOD_FLAG; in partition_tape()
3675 devip->tape_eop[1] = part_1_size; in partition_tape()
3676 devip->tape_blocks[1] = devip->tape_blocks[0] + in partition_tape()
3677 devip->tape_eop[0]; in partition_tape()
3678 devip->tape_blocks[1]->fl_size = TAPE_BLOCK_EOD_FLAG; in partition_tape()
3681 devip->tape_location[i] = 0; in partition_tape()
3683 devip->tape_nbr_partitions = nbr_partitions; in partition_tape()
3684 devip->tape_partition = 0; in partition_tape()
3686 partition_pg[3] = nbr_partitions - 1; in partition_tape()
3687 put_unaligned_be16(devip->tape_eop[0], partition_pg + 8); in partition_tape()
3688 put_unaligned_be16(devip->tape_eop[1], partition_pg + 10); in partition_tape()
3697 unsigned char *cmd = scp->cmnd; in resp_format_medium()
3700 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 2, -1); in resp_format_medium()
3704 if (devip->tape_pending_nbr_partitions > 0) { in resp_format_medium()
3706 devip->tape_pending_nbr_partitions, in resp_format_medium()
3707 devip->tape_pending_part_0_size, in resp_format_medium()
3708 devip->tape_pending_part_1_size); in resp_format_medium()
3710 res = partition_tape(devip, devip->tape_nbr_partitions, in resp_format_medium()
3711 devip->tape_eop[0], devip->tape_eop[1]); in resp_format_medium()
3715 return -EINVAL; in resp_format_medium()
3717 devip->tape_pending_nbr_partitions = -1; in resp_format_medium()
3725 int partition = devip->tape_partition; in resp_erase()
3726 int pos = devip->tape_location[partition]; in resp_erase()
3729 blp = devip->tape_blocks[partition] + pos; in resp_erase()
3730 blp->fl_size = TAPE_BLOCK_EOD_FLAG; in resp_erase()
3737 return devip->nr_zones != 0; in sdebug_dev_is_zoned()
3743 u32 zno = lba >> devip->zsize_shift; in zbc_zone()
3746 if (devip->zcap == devip->zsize || zno < devip->nr_conv_zones) in zbc_zone()
3747 return &devip->zstate[zno]; in zbc_zone()
3753 zno = 2 * zno - devip->nr_conv_zones; in zbc_zone()
3754 WARN_ONCE(zno >= devip->nr_zones, "%u > %u\n", zno, devip->nr_zones); in zbc_zone()
3755 zsp = &devip->zstate[zno]; in zbc_zone()
3756 if (lba >= zsp->z_start + zsp->z_size) in zbc_zone()
3758 WARN_ON_ONCE(lba >= zsp->z_start + zsp->z_size); in zbc_zone()
3764 return zsp->z_type == ZBC_ZTYPE_CNV; in zbc_zone_is_conv()
3769 return zsp->z_type == ZBC_ZTYPE_GAP; in zbc_zone_is_gap()
3785 zc = zsp->z_cond; in zbc_close_zone()
3790 devip->nr_imp_open--; in zbc_close_zone()
3792 devip->nr_exp_open--; in zbc_close_zone()
3794 if (zsp->z_wp == zsp->z_start) { in zbc_close_zone()
3795 zsp->z_cond = ZC1_EMPTY; in zbc_close_zone()
3797 zsp->z_cond = ZC4_CLOSED; in zbc_close_zone()
3798 devip->nr_closed++; in zbc_close_zone()
3804 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_close_imp_open_zone()
3807 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_close_imp_open_zone()
3808 if (zsp->z_cond == ZC2_IMPLICIT_OPEN) { in zbc_close_imp_open_zone()
3823 zc = zsp->z_cond; in zbc_open_zone()
3829 if (explicit && zsp->z_cond == ZC2_IMPLICIT_OPEN) in zbc_open_zone()
3831 else if (devip->max_open && in zbc_open_zone()
3832 devip->nr_imp_open + devip->nr_exp_open >= devip->max_open) in zbc_open_zone()
3835 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_zone()
3836 devip->nr_closed--; in zbc_open_zone()
3838 zsp->z_cond = ZC3_EXPLICIT_OPEN; in zbc_open_zone()
3839 devip->nr_exp_open++; in zbc_open_zone()
3841 zsp->z_cond = ZC2_IMPLICIT_OPEN; in zbc_open_zone()
3842 devip->nr_imp_open++; in zbc_open_zone()
3849 switch (zsp->z_cond) { in zbc_set_zone_full()
3851 devip->nr_imp_open--; in zbc_set_zone_full()
3854 devip->nr_exp_open--; in zbc_set_zone_full()
3858 zsp->z_start, zsp->z_cond); in zbc_set_zone_full()
3861 zsp->z_cond = ZC5_FULL; in zbc_set_zone_full()
3868 unsigned long long n, end, zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
3873 if (zsp->z_type == ZBC_ZTYPE_SWR) { in zbc_inc_wp()
3874 zsp->z_wp += num; in zbc_inc_wp()
3875 if (zsp->z_wp >= zend) in zbc_inc_wp()
3881 if (lba != zsp->z_wp) in zbc_inc_wp()
3882 zsp->z_non_seq_resource = true; in zbc_inc_wp()
3886 n = zend - lba; in zbc_inc_wp()
3887 zsp->z_wp = zend; in zbc_inc_wp()
3888 } else if (end > zsp->z_wp) { in zbc_inc_wp()
3890 zsp->z_wp = end; in zbc_inc_wp()
3894 if (zsp->z_wp >= zend) in zbc_inc_wp()
3897 num -= n; in zbc_inc_wp()
3901 zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
3909 struct scsi_device *sdp = scp->device; in check_zbc_access_params()
3910 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_zbc_access_params()
3912 struct sdeb_zone_state *zsp_end = zbc_zone(devip, lba + num - 1); in check_zbc_access_params()
3915 /* For host-managed, reads cannot cross zone types boundaries */ in check_zbc_access_params()
3916 if (zsp->z_type != zsp_end->z_type) { in check_zbc_access_params()
3943 if (zsp->z_type == ZBC_ZTYPE_SWR) { in check_zbc_access_params()
3952 if (zsp->z_cond == ZC5_FULL) { in check_zbc_access_params()
3958 if (lba != zsp->z_wp) { in check_zbc_access_params()
3967 if (zsp->z_cond == ZC1_EMPTY || zsp->z_cond == ZC4_CLOSED) { in check_zbc_access_params()
3968 if (devip->max_open && in check_zbc_access_params()
3969 devip->nr_exp_open >= devip->max_open) { in check_zbc_access_params()
3985 struct scsi_device *sdp = scp->device; in check_device_access_params()
3986 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_device_access_params()
4021 return xa_load(per_store_ap, devip->sdbg_host->si_idx); in devip2sip()
4065 sdeb_read_lock(&sip->macc_data_lck); in sdeb_data_read_lock()
4073 sdeb_read_unlock(&sip->macc_data_lck); in sdeb_data_read_unlock()
4081 sdeb_write_lock(&sip->macc_data_lck); in sdeb_data_write_lock()
4089 sdeb_write_unlock(&sip->macc_data_lck); in sdeb_data_write_unlock()
4097 sdeb_read_lock(&sip->macc_sector_lck); in sdeb_data_sector_read_lock()
4105 sdeb_read_unlock(&sip->macc_sector_lck); in sdeb_data_sector_read_unlock()
4113 sdeb_write_lock(&sip->macc_sector_lck); in sdeb_data_sector_write_lock()
4121 sdeb_write_unlock(&sip->macc_sector_lck); in sdeb_data_sector_write_unlock()
4126 * We simplify the atomic model to allow only 1x atomic write and many non-
4132 * So use a RW lock for per-device read and write locking:
4133 * An atomic access grabs the lock as a writer and non-atomic grabs the lock
4179 __acquire(&sip->macc_meta_lck); in sdeb_meta_read_lock()
4184 read_lock(&sip->macc_meta_lck); in sdeb_meta_read_lock()
4195 __release(&sip->macc_meta_lck); in sdeb_meta_read_unlock()
4200 read_unlock(&sip->macc_meta_lck); in sdeb_meta_read_unlock()
4211 __acquire(&sip->macc_meta_lck); in sdeb_meta_write_lock()
4216 write_lock(&sip->macc_meta_lck); in sdeb_meta_write_lock()
4227 __release(&sip->macc_meta_lck); in sdeb_meta_write_unlock()
4232 write_unlock(&sip->macc_meta_lck); in sdeb_meta_write_unlock()
4238 /* Returns number of bytes copied or -1 if error. */
4246 struct scsi_data_buffer *sdb = &scp->sdb; in do_device_access()
4255 return -1; in do_device_access()
4264 if (!sdb->length || !sip) in do_device_access()
4266 if (scp->sc_data_direction != dir) in do_device_access()
4267 return -1; in do_device_access()
4272 fsp = sip->storep; in do_device_access()
4276 /* Only allow 1x atomic write or multiple non-atomic writes at any given time */ in do_device_access()
4281 ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
4297 /* Returns number of bytes copied or -1 if error. */
4300 struct scsi_data_buffer *sdb = &scp->sdb; in do_dout_fetch()
4302 if (!sdb->length) in do_dout_fetch()
4304 if (scp->sc_data_direction != DMA_TO_DEVICE) in do_dout_fetch()
4305 return -1; in do_dout_fetch()
4306 return sg_copy_buffer(sdb->table.sgl, sdb->table.nents, doutp, in do_dout_fetch()
4310 /* If sip->storep+lba compares equal to arr(num), then copy top half of
4311 * arr into sip->storep+lba and return true. If comparison fails then
4320 u8 *fsp = sip->storep; in comp_write_worker()
4324 rest = block + num - store_blks; in comp_write_worker()
4326 res = !memcmp(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
4330 res = memcmp(fsp, arr + ((num - rest) * lb_size), in comp_write_worker()
4337 memcpy(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
4339 memcpy(fsp, arr + ((num - rest) * lb_size), rest * lb_size); in comp_write_worker()
4360 if (sdt->guard_tag != csum) { in dif_verify()
4363 be16_to_cpu(sdt->guard_tag), in dif_verify()
4368 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { in dif_verify()
4374 be32_to_cpu(sdt->ref_tag) != ei_lba) { in dif_verify()
4388 scp->device->hostdata, true); in dif_copy_prot()
4389 struct t10_pi_tuple *dif_storep = sip->dif_storep; in dif_copy_prot()
4406 rest = start + len - dif_store_end; in dif_copy_prot()
4411 memcpy(paddr, start, len - rest); in dif_copy_prot()
4413 memcpy(start, paddr, len - rest); in dif_copy_prot()
4417 memcpy(paddr + len - rest, dif_storep, rest); in dif_copy_prot()
4419 memcpy(dif_storep, paddr + len - rest, rest); in dif_copy_prot()
4423 resid -= len; in dif_copy_prot()
4435 scp->device->hostdata, true); in prot_verify_read()
4442 if (sdt->app_tag == cpu_to_be16(0xffff)) in prot_verify_read()
4452 if (scp->cmnd[1] >> 5) { /* RDPROTECT */ in prot_verify_read()
4471 u8 *cmd = scp->cmnd; in resp_read_tape()
4472 struct scsi_data_buffer *sdb = &scp->sdb; in resp_read_tape()
4473 int partition = devip->tape_partition; in resp_read_tape()
4474 u32 pos = devip->tape_location[partition]; in resp_read_tape()
4492 size = devip->tape_blksize; in resp_read_tape()
4496 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_read_tape()
4503 for (i = 0, blp = devip->tape_blocks[partition] + pos; in resp_read_tape()
4504 i < num && pos < devip->tape_eop[partition]; in resp_read_tape()
4506 devip->tape_location[partition] = pos + 1; in resp_read_tape()
4507 if (IS_TAPE_BLOCK_FM(blp->fl_size)) { in resp_read_tape()
4509 FILEMARK_DETECTED_ASCQ, fixed ? num - i : size, in resp_read_tape()
4511 scsi_set_resid(scp, (num - i) * size); in resp_read_tape()
4515 if (IS_TAPE_BLOCK_EOD(blp->fl_size)) { in resp_read_tape()
4517 EOD_DETECTED_ASCQ, fixed ? num - i : size, in resp_read_tape()
4519 devip->tape_location[partition] = pos; in resp_read_tape()
4520 scsi_set_resid(scp, (num - i) * size); in resp_read_tape()
4523 sg_zero_buffer(sdb->table.sgl, sdb->table.nents, in resp_read_tape()
4525 sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in resp_read_tape()
4526 &(blp->data), 4, i * size, false); in resp_read_tape()
4528 if (blp->fl_size != devip->tape_blksize) { in resp_read_tape()
4529 scsi_set_resid(scp, (num - i) * size); in resp_read_tape()
4531 0, num - i, in resp_read_tape()
4536 if (blp->fl_size != size) { in resp_read_tape()
4537 if (blp->fl_size < size) in resp_read_tape()
4538 scsi_set_resid(scp, size - blp->fl_size); in resp_read_tape()
4541 0, size - blp->fl_size, in resp_read_tape()
4548 if (pos >= devip->tape_eop[partition]) { in resp_read_tape()
4550 EOP_EOM_DETECTED_ASCQ, fixed ? num - i : size, in resp_read_tape()
4552 devip->tape_location[partition] = pos - 1; in resp_read_tape()
4555 devip->tape_location[partition] = pos; in resp_read_tape()
4568 u8 *cmd = scp->cmnd; in resp_read_dt0()
4619 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " in resp_read_dt0()
4636 (lba <= (sdebug_medium_error_start + sdebug_medium_error_count - 1)) && in resp_read_dt0()
4641 if (0x70 == (scp->sense_buffer[0] & 0x7f)) { in resp_read_dt0()
4642 scp->sense_buffer[0] |= 0x80; /* Valid bit */ in resp_read_dt0()
4645 put_unaligned_be32(ret, scp->sense_buffer + 3); in resp_read_dt0()
4665 } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { in resp_read_dt0()
4676 } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { in resp_read_dt0()
4688 if (unlikely(ret == -1)) in resp_read_dt0()
4691 scsi_set_resid(scp, scsi_bufflen(scp) - ret); in resp_read_dt0()
4758 if (SCpnt->cmnd[1] >> 5 != 3) { /* WRPROTECT */ in prot_verify_write()
4788 lba += sdebug_unmap_granularity - sdebug_unmap_alignment; in lba_to_map_index()
4798 lba -= sdebug_unmap_granularity - sdebug_unmap_alignment; in map_index_to_lba()
4811 mapped = test_bit(index, sip->map_storep); in map_state()
4814 next = find_next_zero_bit(sip->map_storep, map_size, index); in map_state()
4816 next = find_next_bit(sip->map_storep, map_size, index); in map_state()
4819 *num = end - lba; in map_state()
4832 set_bit(index, sip->map_storep); in map_region()
4842 u8 *fsp = sip->storep; in unmap_region()
4850 clear_bit(index, sip->map_storep); in unmap_region()
4857 if (sip->dif_storep) { in unmap_region()
4858 memset(sip->dif_storep + lba, 0xff, in unmap_region()
4859 sizeof(*sip->dif_storep) * in unmap_region()
4870 u8 *cmd = scp->cmnd; in resp_write_tape()
4871 struct scsi_data_buffer *sdb = &scp->sdb; in resp_write_tape()
4872 int partition = devip->tape_partition; in resp_write_tape()
4873 int pos = devip->tape_location[partition]; in resp_write_tape()
4886 size = devip->tape_blksize; in resp_write_tape()
4890 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_write_tape()
4898 for (i = 0, blp = devip->tape_blocks[partition] + pos, ew = false; in resp_write_tape()
4899 i < num && pos < devip->tape_eop[partition] - 1; i++, pos++, blp++) { in resp_write_tape()
4900 blp->fl_size = size; in resp_write_tape()
4901 sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in resp_write_tape()
4902 &(blp->data), 4, i * size, true); in resp_write_tape()
4904 scsi_set_resid(scp, num * transfer - written); in resp_write_tape()
4905 ew |= (pos == devip->tape_eop[partition] - TAPE_EW); in resp_write_tape()
4908 devip->tape_location[partition] = pos; in resp_write_tape()
4909 blp->fl_size = TAPE_BLOCK_EOD_FLAG; in resp_write_tape()
4910 if (pos >= devip->tape_eop[partition] - 1) { in resp_write_tape()
4913 fixed ? num - i : transfer, in resp_write_tape()
4920 fixed ? num - i : transfer, in resp_write_tape()
4937 u8 *cmd = scp->cmnd; in resp_write_dt0()
4993 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_write_dt0()
5015 if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { in resp_write_dt0()
5019 } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ in resp_write_dt0()
5026 if (scp->prot_flags & SCSI_PROT_REF_CHECK) { in resp_write_dt0()
5030 } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ in resp_write_dt0()
5049 if (unlikely(-1 == ret)) in resp_write_dt0()
5053 sdev_printk(KERN_INFO, scp->device, in resp_write_dt0()
5084 u8 *cmd = scp->cmnd; in resp_write_scat()
5122 sdev_printk(KERN_ERR, scp->device, in resp_write_scat()
5127 return 0; /* T10 says these do-nothings are not errors */ in resp_write_scat()
5130 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
5139 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
5149 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
5153 if (res == -1) { in resp_write_scat()
5167 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
5180 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
5203 * Write ranges atomically to keep as close to pre-atomic in resp_write_scat()
5212 if (unlikely(-1 == ret)) { in resp_write_scat()
5216 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
5254 struct scsi_device *sdp = scp->device; in resp_write_same()
5255 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in resp_write_same()
5261 scp->device->hostdata, true); in resp_write_same()
5282 fsp = sip->storep; in resp_write_same()
5291 if (-1 == ret) { in resp_write_same()
5295 sdev_printk(KERN_INFO, scp->device, in resp_write_same()
5321 u8 *cmd = scp->cmnd; in resp_write_same_10()
5337 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_write_same_10()
5346 u8 *cmd = scp->cmnd; in resp_write_same_16()
5360 if (cmd[1] & 0x1) /* NDOB (no data-out buffer, assumes zeroes) */ in resp_write_same_16()
5365 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); in resp_write_same_16()
5372 * field. For the Report supported operation codes command, SPC-4 suggests
5377 u8 *cmd = scp->cmnd; in resp_write_buffer()
5378 struct scsi_device *sdp = scp->device; in resp_write_buffer()
5386 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in resp_write_buffer()
5387 set_bit(SDEBUG_UA_MICROCODE_CHANGED, devip->uas_bm); in resp_write_buffer()
5390 set_bit(SDEBUG_UA_MICROCODE_CHANGED_WO_RESET, devip->uas_bm); in resp_write_buffer()
5395 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
5397 if (dp->target == sdp->id) { in resp_write_buffer()
5398 set_bit(SDEBUG_UA_BUS_RESET, dp->uas_bm); in resp_write_buffer()
5401 dp->uas_bm); in resp_write_buffer()
5407 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
5409 if (dp->target == sdp->id) in resp_write_buffer()
5411 dp->uas_bm); in resp_write_buffer()
5423 u8 *cmd = scp->cmnd; in resp_comp_write()
5445 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_comp_write()
5459 if (ret == -1) { in resp_comp_write()
5463 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " in resp_comp_write()
5475 /* Cover sip->map_storep (which map_region()) sets with data lock */ in resp_comp_write()
5502 payload_len = get_unaligned_be16(scp->cmnd + 7); in resp_unmap()
5505 descriptors = (payload_len - 8) / 16; in resp_unmap()
5507 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_unmap()
5520 BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2); in resp_unmap()
5552 u8 *cmd = scp->cmnd; in resp_get_lba_status()
5576 if (sdebug_capacity - lba <= 0xffffffff) in resp_get_lba_status()
5577 num = sdebug_capacity - lba; in resp_get_lba_status()
5595 const u8 *cmd = scp->cmnd; in resp_get_stream_status()
5604 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); in resp_get_stream_status()
5609 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); in resp_get_stream_status()
5615 * about open streams. Treat the non-permanent stream as open. in resp_get_stream_status()
5618 &h->number_of_open_streams); in resp_get_stream_status()
5626 stream_status->perm = stream_id < PERMANENT_STREAM_COUNT; in resp_get_stream_status()
5628 &stream_status->stream_identifier); in resp_get_stream_status()
5629 stream_status->rel_lifetime = stream_id + 1; in resp_get_stream_status()
5631 put_unaligned_be32(offset - 8, &h->len); /* PARAMETER DATA LENGTH */ in resp_get_stream_status()
5642 u8 *cmd = scp->cmnd; in resp_sync_cache()
5663 * Assuming the LBA+num_blocks is not out-of-range, this function will return
5678 u8 *cmd = scp->cmnd; in resp_pre_fetch()
5680 u8 *fsp = sip->storep; in resp_pre_fetch()
5685 } else { /* PRE-FETCH(16) */ in resp_pre_fetch()
5695 /* PRE-FETCH spec says nothing about LBP or PI so skip them */ in resp_pre_fetch()
5698 rest = block + nblks - sdebug_store_sectors; in resp_pre_fetch()
5700 /* Try to bring the PRE-FETCH range into CPU's cache */ in resp_pre_fetch()
5703 (nblks - rest) * sdebug_sector_size); in resp_pre_fetch()
5717 * (W-LUN), the normal Linux scanning logic does not associate it with a
5719 * "cd /sys/class/scsi_host/host<n> ; echo '- - 49409' > scan"
5721 * the above will associate a W-LUN to each target. To only get a W-LUN
5722 * for target 2, then use "echo '- 2 49409' > scan" .
5727 unsigned char *cmd = scp->cmnd; in resp_report_luns()
5734 unsigned int wlun_cnt; /* report luns W-LUN count */ in resp_report_luns()
5748 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_report_luns()
5753 case 0: /* all LUNs apart from W-LUNs */ in resp_report_luns()
5757 case 1: /* only W-LUNs */ in resp_report_luns()
5766 case 0x11: /* see SPC-5 */ in resp_report_luns()
5770 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_report_luns()
5775 --lun_cnt; in resp_report_luns()
5798 lun_p->scsi_lun[0] |= 0x40; in resp_report_luns()
5826 u8 *cmd = scp->cmnd; in resp_verify()
5869 if (ret == -1) { in resp_verify()
5873 sdev_printk(KERN_INFO, scp->device, in resp_verify()
5905 u8 *cmd = scp->cmnd; in resp_report_zones()
5925 rep_max_zones = (alloc_len - 64) >> ilog2(RZONES_DESC_HD); in resp_report_zones()
5938 lba = zsp->z_start + zsp->z_size) { in resp_report_zones()
5948 if (zsp->z_cond != ZC1_EMPTY) in resp_report_zones()
5953 if (zsp->z_cond != ZC2_IMPLICIT_OPEN) in resp_report_zones()
5958 if (zsp->z_cond != ZC3_EXPLICIT_OPEN) in resp_report_zones()
5963 if (zsp->z_cond != ZC4_CLOSED) in resp_report_zones()
5968 if (zsp->z_cond != ZC5_FULL) in resp_report_zones()
5975 * Read-only, offline, reset WP recommended are in resp_report_zones()
5980 /* non-seq-resource set */ in resp_report_zones()
5981 if (!zsp->z_non_seq_resource) in resp_report_zones()
6003 desc[0] = zsp->z_type; in resp_report_zones()
6004 desc[1] = zsp->z_cond << 4; in resp_report_zones()
6005 if (zsp->z_non_seq_resource) in resp_report_zones()
6007 put_unaligned_be64((u64)zsp->z_size, desc + 8); in resp_report_zones()
6008 put_unaligned_be64((u64)zsp->z_start, desc + 16); in resp_report_zones()
6009 put_unaligned_be64((u64)zsp->z_wp, desc + 24); in resp_report_zones()
6023 put_unaligned_be64(sdebug_capacity - 1, arr + 8); in resp_report_zones()
6025 if (devip->zcap < devip->zsize) in resp_report_zones()
6026 put_unaligned_be64(devip->zsize, arr + 16); in resp_report_zones()
6028 rep_len = (unsigned long)desc - (unsigned long)arr; in resp_report_zones()
6041 u8 *cmd = scp->cmnd; in resp_atomic_write()
6073 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); in resp_atomic_write()
6078 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); in resp_atomic_write()
6083 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); in resp_atomic_write()
6089 if (unlikely(ret == -1)) in resp_atomic_write()
6096 /* Logic transplanted from tcmu-runner, file_zbc.c */
6099 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_open_all()
6102 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_open_all()
6103 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_all()
6104 zbc_open_zone(devip, &devip->zstate[i], true); in zbc_open_all()
6113 u8 *cmd = scp->cmnd; in resp_open_zone()
6126 if (devip->max_open && in resp_open_zone()
6127 devip->nr_exp_open + devip->nr_closed > devip->max_open) { in resp_open_zone()
6147 if (z_id != zsp->z_start) { in resp_open_zone()
6158 zc = zsp->z_cond; in resp_open_zone()
6162 if (devip->max_open && devip->nr_exp_open >= devip->max_open) { in resp_open_zone()
6179 for (i = 0; i < devip->nr_zones; i++) in zbc_close_all()
6180 zbc_close_zone(devip, &devip->zstate[i]); in zbc_close_all()
6188 u8 *cmd = scp->cmnd; in resp_close_zone()
6214 if (z_id != zsp->z_start) { in resp_close_zone()
6234 enum sdebug_z_cond zc = zsp->z_cond; in zbc_finish_zone()
6240 if (zsp->z_cond == ZC4_CLOSED) in zbc_finish_zone()
6241 devip->nr_closed--; in zbc_finish_zone()
6242 zsp->z_wp = zsp->z_start + zsp->z_size; in zbc_finish_zone()
6243 zsp->z_cond = ZC5_FULL; in zbc_finish_zone()
6251 for (i = 0; i < devip->nr_zones; i++) in zbc_finish_all()
6252 zbc_finish_zone(devip, &devip->zstate[i], false); in zbc_finish_all()
6261 u8 *cmd = scp->cmnd; in resp_finish_zone()
6286 if (z_id != zsp->z_start) { in resp_finish_zone()
6312 zc = zsp->z_cond; in zbc_rwp_zone()
6316 if (zsp->z_cond == ZC4_CLOSED) in zbc_rwp_zone()
6317 devip->nr_closed--; in zbc_rwp_zone()
6319 if (zsp->z_wp > zsp->z_start) in zbc_rwp_zone()
6320 memset(sip->storep + zsp->z_start * sdebug_sector_size, 0, in zbc_rwp_zone()
6321 (zsp->z_wp - zsp->z_start) * sdebug_sector_size); in zbc_rwp_zone()
6323 zsp->z_non_seq_resource = false; in zbc_rwp_zone()
6324 zsp->z_wp = zsp->z_start; in zbc_rwp_zone()
6325 zsp->z_cond = ZC1_EMPTY; in zbc_rwp_zone()
6332 for (i = 0; i < devip->nr_zones; i++) in zbc_rwp_all()
6333 zbc_rwp_zone(devip, &devip->zstate[i]); in zbc_rwp_all()
6341 u8 *cmd = scp->cmnd; in resp_rwp_zone()
6365 if (z_id != zsp->z_start) { in resp_rwp_zone()
6392 struct scsi_cmnd *scp = (struct scsi_cmnd *)sdsc - 1; in sdebug_q_cmd_complete()
6398 if (raw_smp_processor_id() != sd_dp->issuing_cpu) in sdebug_q_cmd_complete()
6407 spin_lock_irqsave(&sdsc->lock, flags); in sdebug_q_cmd_complete()
6408 aborted = sd_dp->aborted; in sdebug_q_cmd_complete()
6410 sd_dp->aborted = false; in sdebug_q_cmd_complete()
6412 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_q_cmd_complete()
6415 pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); in sdebug_q_cmd_complete()
6458 devip->zsize = (DEF_ZBC_ZONE_SIZE_MB * SZ_1M) in sdebug_device_create_zones()
6460 while (capacity < devip->zsize << 2 && devip->zsize >= 2) in sdebug_device_create_zones()
6461 devip->zsize >>= 1; in sdebug_device_create_zones()
6462 if (devip->zsize < 2) { in sdebug_device_create_zones()
6464 return -EINVAL; in sdebug_device_create_zones()
6469 return -EINVAL; in sdebug_device_create_zones()
6471 devip->zsize = (sdeb_zbc_zone_size_mb * SZ_1M) in sdebug_device_create_zones()
6473 if (devip->zsize >= capacity) { in sdebug_device_create_zones()
6475 return -EINVAL; in sdebug_device_create_zones()
6479 devip->zsize_shift = ilog2(devip->zsize); in sdebug_device_create_zones()
6480 devip->nr_zones = (capacity + devip->zsize - 1) >> devip->zsize_shift; in sdebug_device_create_zones()
6483 devip->zcap = devip->zsize; in sdebug_device_create_zones()
6485 devip->zcap = (sdeb_zbc_zone_cap_mb * SZ_1M) >> in sdebug_device_create_zones()
6487 if (devip->zcap > devip->zsize) { in sdebug_device_create_zones()
6489 return -EINVAL; in sdebug_device_create_zones()
6493 conv_capacity = (sector_t)sdeb_zbc_nr_conv << devip->zsize_shift; in sdebug_device_create_zones()
6496 return -EINVAL; in sdebug_device_create_zones()
6498 devip->nr_conv_zones = sdeb_zbc_nr_conv; in sdebug_device_create_zones()
6499 devip->nr_seq_zones = ALIGN(capacity - conv_capacity, devip->zsize) >> in sdebug_device_create_zones()
6500 devip->zsize_shift; in sdebug_device_create_zones()
6501 devip->nr_zones = devip->nr_conv_zones + devip->nr_seq_zones; in sdebug_device_create_zones()
6504 if (devip->zcap < devip->zsize) in sdebug_device_create_zones()
6505 devip->nr_zones += devip->nr_seq_zones; in sdebug_device_create_zones()
6507 if (devip->zoned) { in sdebug_device_create_zones()
6509 if (sdeb_zbc_max_open >= devip->nr_zones - 1) in sdebug_device_create_zones()
6510 devip->max_open = (devip->nr_zones - 1) / 2; in sdebug_device_create_zones()
6512 devip->max_open = sdeb_zbc_max_open; in sdebug_device_create_zones()
6515 devip->zstate = kcalloc(devip->nr_zones, in sdebug_device_create_zones()
6517 if (!devip->zstate) in sdebug_device_create_zones()
6518 return -ENOMEM; in sdebug_device_create_zones()
6520 for (i = 0; i < devip->nr_zones; i++) { in sdebug_device_create_zones()
6521 zsp = &devip->zstate[i]; in sdebug_device_create_zones()
6523 zsp->z_start = zstart; in sdebug_device_create_zones()
6525 if (i < devip->nr_conv_zones) { in sdebug_device_create_zones()
6526 zsp->z_type = ZBC_ZTYPE_CNV; in sdebug_device_create_zones()
6527 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
6528 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
6529 zsp->z_size = in sdebug_device_create_zones()
6530 min_t(u64, devip->zsize, capacity - zstart); in sdebug_device_create_zones()
6531 } else if ((zstart & (devip->zsize - 1)) == 0) { in sdebug_device_create_zones()
6532 if (devip->zoned) in sdebug_device_create_zones()
6533 zsp->z_type = ZBC_ZTYPE_SWR; in sdebug_device_create_zones()
6535 zsp->z_type = ZBC_ZTYPE_SWP; in sdebug_device_create_zones()
6536 zsp->z_cond = ZC1_EMPTY; in sdebug_device_create_zones()
6537 zsp->z_wp = zsp->z_start; in sdebug_device_create_zones()
6538 zsp->z_size = in sdebug_device_create_zones()
6539 min_t(u64, devip->zcap, capacity - zstart); in sdebug_device_create_zones()
6541 zsp->z_type = ZBC_ZTYPE_GAP; in sdebug_device_create_zones()
6542 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
6543 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
6544 zsp->z_size = min_t(u64, devip->zsize - devip->zcap, in sdebug_device_create_zones()
6545 capacity - zstart); in sdebug_device_create_zones()
6548 WARN_ON_ONCE((int)zsp->z_size <= 0); in sdebug_device_create_zones()
6549 zstart += zsp->z_size; in sdebug_device_create_zones()
6563 uuid_gen(&devip->lu_name); in sdebug_device_create()
6566 devip->lu_name = shared_uuid; in sdebug_device_create()
6570 devip->lu_name = shared_uuid; in sdebug_device_create()
6573 devip->sdbg_host = sdbg_host; in sdebug_device_create()
6575 devip->zoned = sdeb_zbc_model == BLK_ZONED_HM; in sdebug_device_create()
6581 devip->zoned = false; in sdebug_device_create()
6584 devip->tape_density = TAPE_DEF_DENSITY; in sdebug_device_create()
6585 devip->tape_blksize = TAPE_DEF_BLKSIZE; in sdebug_device_create()
6587 devip->create_ts = ktime_get_boottime(); in sdebug_device_create()
6588 atomic_set(&devip->stopped, (sdeb_tur_ms_to_ready > 0 ? 2 : 0)); in sdebug_device_create()
6589 spin_lock_init(&devip->list_lock); in sdebug_device_create()
6590 INIT_LIST_HEAD(&devip->inject_err_list); in sdebug_device_create()
6591 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list); in sdebug_device_create()
6602 sdbg_host = shost_to_sdebug_host(sdev->host); in find_build_dev_info()
6604 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in find_build_dev_info()
6605 if ((devip->used) && (devip->channel == sdev->channel) && in find_build_dev_info()
6606 (devip->target == sdev->id) && in find_build_dev_info()
6607 (devip->lun == sdev->lun)) in find_build_dev_info()
6610 if ((!devip->used) && (!open_devip)) in find_build_dev_info()
6622 open_devip->channel = sdev->channel; in find_build_dev_info()
6623 open_devip->target = sdev->id; in find_build_dev_info()
6624 open_devip->lun = sdev->lun; in find_build_dev_info()
6625 open_devip->sdbg_host = sdbg_host; in find_build_dev_info()
6626 set_bit(SDEBUG_UA_POOCCUR, open_devip->uas_bm); in find_build_dev_info()
6627 open_devip->used = true; in find_build_dev_info()
6635 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_sdev_init()
6644 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_sdev_configure()
6649 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_sdev_configure()
6650 if (sdp->host->max_cmd_len != SDEBUG_MAX_CMD_LEN) in scsi_debug_sdev_configure()
6651 sdp->host->max_cmd_len = SDEBUG_MAX_CMD_LEN; in scsi_debug_sdev_configure()
6658 if (!devip->tape_blocks[0]) { in scsi_debug_sdev_configure()
6659 devip->tape_blocks[0] = in scsi_debug_sdev_configure()
6662 if (!devip->tape_blocks[0]) in scsi_debug_sdev_configure()
6665 devip->tape_pending_nbr_partitions = -1; in scsi_debug_sdev_configure()
6667 kfree(devip->tape_blocks[0]); in scsi_debug_sdev_configure()
6668 devip->tape_blocks[0] = NULL; in scsi_debug_sdev_configure()
6672 sdp->hostdata = devip; in scsi_debug_sdev_configure()
6674 sdp->no_uld_attach = 1; in scsi_debug_sdev_configure()
6678 sdp->allow_restart = 1; in scsi_debug_sdev_configure()
6680 devip->debugfs_entry = debugfs_create_dir(dev_name(&sdp->sdev_dev), in scsi_debug_sdev_configure()
6682 if (IS_ERR_OR_NULL(devip->debugfs_entry)) in scsi_debug_sdev_configure()
6684 __func__, dev_name(&sdp->sdev_gendev)); in scsi_debug_sdev_configure()
6686 dentry = debugfs_create_file("error", 0600, devip->debugfs_entry, sdp, in scsi_debug_sdev_configure()
6690 __func__, dev_name(&sdp->sdev_gendev)); in scsi_debug_sdev_configure()
6698 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_sdev_destroy()
6703 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_sdev_destroy()
6708 spin_lock(&devip->list_lock); in scsi_debug_sdev_destroy()
6709 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in scsi_debug_sdev_destroy()
6710 list_del_rcu(&err->list); in scsi_debug_sdev_destroy()
6711 call_rcu(&err->rcu, sdebug_err_free); in scsi_debug_sdev_destroy()
6713 spin_unlock(&devip->list_lock); in scsi_debug_sdev_destroy()
6715 debugfs_remove(devip->debugfs_entry); in scsi_debug_sdev_destroy()
6717 if (sdp->type == TYPE_TAPE) { in scsi_debug_sdev_destroy()
6718 kfree(devip->tape_blocks[0]); in scsi_debug_sdev_destroy()
6719 devip->tape_blocks[0] = NULL; in scsi_debug_sdev_destroy()
6722 /* make this slot available for re-use */ in scsi_debug_sdev_destroy()
6723 devip->used = false; in scsi_debug_sdev_destroy()
6724 sdp->hostdata = NULL; in scsi_debug_sdev_destroy()
6731 struct sdebug_defer *sd_dp = &sdsc->sd_dp; in scsi_debug_stop_cmnd()
6732 enum sdeb_defer_type defer_t = READ_ONCE(sd_dp->defer_t); in scsi_debug_stop_cmnd()
6734 lockdep_assert_held(&sdsc->lock); in scsi_debug_stop_cmnd()
6737 int res = hrtimer_try_to_cancel(&sd_dp->hrt); in scsi_debug_stop_cmnd()
6740 case -1: /* -1 It's executing the CB */ in scsi_debug_stop_cmnd()
6749 if (cancel_work(&sd_dp->ew.work)) in scsi_debug_stop_cmnd()
6761 * Called from scsi_debug_abort() only, which is for timed-out cmd.
6769 spin_lock_irqsave(&sdsc->lock, flags); in scsi_debug_abort_cmnd()
6771 spin_unlock_irqrestore(&sdsc->lock, flags); in scsi_debug_abort_cmnd()
6794 struct Scsi_Host *shost = sdhp->shost; in stop_all_queued()
6796 blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_stop_cmnd, NULL); in stop_all_queued()
6803 struct scsi_device *sdp = cmnd->device; in sdebug_fail_abort()
6804 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in sdebug_fail_abort()
6806 unsigned char *cmd = cmnd->cmnd; in sdebug_fail_abort()
6813 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_fail_abort()
6814 if (err->type == ERR_ABORT_CMD_FAILED && in sdebug_fail_abort()
6815 (err->cmd == cmd[0] || err->cmd == 0xff)) { in sdebug_fail_abort()
6816 ret = !!err->cnt; in sdebug_fail_abort()
6817 if (err->cnt < 0) in sdebug_fail_abort()
6818 err->cnt++; in sdebug_fail_abort()
6832 u8 *cmd = SCpnt->cmnd; in scsi_debug_abort()
6838 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_abort()
6860 if (scmd->device == sdp) in scsi_debug_stop_all_queued_iter()
6869 struct Scsi_Host *shost = sdp->host; in scsi_debug_stop_all_queued()
6871 blk_mq_tagset_busy_iter(&shost->tag_set, in scsi_debug_stop_all_queued()
6877 struct scsi_device *sdp = cmnd->device; in sdebug_fail_lun_reset()
6878 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in sdebug_fail_lun_reset()
6880 unsigned char *cmd = cmnd->cmnd; in sdebug_fail_lun_reset()
6887 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_fail_lun_reset()
6888 if (err->type == ERR_LUN_RESET_FAILED && in sdebug_fail_lun_reset()
6889 (err->cmd == cmd[0] || err->cmd == 0xff)) { in sdebug_fail_lun_reset()
6890 ret = !!err->cnt; in sdebug_fail_lun_reset()
6891 if (err->cnt < 0) in sdebug_fail_lun_reset()
6892 err->cnt++; in sdebug_fail_lun_reset()
6907 devip->tape_blksize = TAPE_DEF_BLKSIZE; in scsi_tape_reset_clear()
6908 devip->tape_density = TAPE_DEF_DENSITY; in scsi_tape_reset_clear()
6909 devip->tape_partition = 0; in scsi_tape_reset_clear()
6910 devip->tape_dce = 0; in scsi_tape_reset_clear()
6912 devip->tape_location[i] = 0; in scsi_tape_reset_clear()
6913 devip->tape_pending_nbr_partitions = -1; in scsi_tape_reset_clear()
6919 struct scsi_device *sdp = SCpnt->device; in scsi_debug_device_reset()
6920 struct sdebug_dev_info *devip = sdp->hostdata; in scsi_debug_device_reset()
6921 u8 *cmd = SCpnt->cmnd; in scsi_debug_device_reset()
6931 set_bit(SDEBUG_UA_POR, devip->uas_bm); in scsi_debug_device_reset()
6932 if (SCpnt->device->type == TYPE_TAPE) in scsi_debug_device_reset()
6946 struct scsi_target *starget = scsi_target(cmnd->device); in sdebug_fail_target_reset()
6948 (struct sdebug_target_info *)starget->hostdata; in sdebug_fail_target_reset()
6951 return targetip->reset_fail; in sdebug_fail_target_reset()
6958 struct scsi_device *sdp = SCpnt->device; in scsi_debug_target_reset()
6959 struct sdebug_host_info *sdbg_host = shost_to_sdebug_host(sdp->host); in scsi_debug_target_reset()
6961 u8 *cmd = SCpnt->cmnd; in scsi_debug_target_reset()
6969 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in scsi_debug_target_reset()
6970 if (devip->target == sdp->id) { in scsi_debug_target_reset()
6971 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_target_reset()
6972 if (SCpnt->device->type == TYPE_TAPE) in scsi_debug_target_reset()
6993 struct scsi_device *sdp = SCpnt->device; in scsi_debug_bus_reset()
6994 struct sdebug_host_info *sdbg_host = shost_to_sdebug_host(sdp->host); in scsi_debug_bus_reset()
7003 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in scsi_debug_bus_reset()
7004 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_bus_reset()
7005 if (SCpnt->device->type == TYPE_TAPE) in scsi_debug_bus_reset()
7024 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); in scsi_debug_host_reset()
7027 list_for_each_entry(devip, &sdbg_host->dev_info_list, in scsi_debug_host_reset()
7029 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_host_reset()
7030 if (SCpnt->device->type == TYPE_TAPE) in scsi_debug_host_reset()
7038 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_host_reset()
7058 sectors_per_part = (num_sectors - sdebug_sectors_per) in sdebug_build_parts()
7066 if (starts[k] - starts[k - 1] < max_part_secs) in sdebug_build_parts()
7067 max_part_secs = starts[k] - starts[k - 1]; in sdebug_build_parts()
7077 end_sec = starts[k] + max_part_secs - 1; in sdebug_build_parts()
7078 pp->boot_ind = 0; in sdebug_build_parts()
7080 pp->cyl = start_sec / heads_by_sects; in sdebug_build_parts()
7081 pp->head = (start_sec - (pp->cyl * heads_by_sects)) in sdebug_build_parts()
7083 pp->sector = (start_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
7085 pp->end_cyl = end_sec / heads_by_sects; in sdebug_build_parts()
7086 pp->end_head = (end_sec - (pp->end_cyl * heads_by_sects)) in sdebug_build_parts()
7088 pp->end_sector = (end_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
7090 pp->start_sect = cpu_to_le32(start_sec); in sdebug_build_parts()
7091 pp->nr_sects = cpu_to_le32(end_sec - start_sec + 1); in sdebug_build_parts()
7092 pp->sys_ind = 0x83; /* plain Linux partition */ in sdebug_build_parts()
7103 struct Scsi_Host *shost = sdhp->shost; in block_unblock_all_queues()
7112 /* Adjust (by rounding down) the sdebug_cmnd_count so abs(every_nth)-1
7160 bool polled = rq->cmd_flags & REQ_POLLED; in schedule_resp()
7172 sdp = cmnd->device; in schedule_resp()
7181 int qdepth = cmnd->device->queue_depth; in schedule_resp()
7195 sd_dp = &sdsc->sd_dp; in schedule_resp()
7201 cmnd->result = pfp ? pfp(cmnd, devip) : 0; in schedule_resp()
7202 if (cmnd->result & SDEG_RES_IMMED_MASK) { in schedule_resp()
7203 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
7206 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
7207 cmnd->result = scsi_result; in schedule_resp()
7208 if (cmnd->result == 0 && unlikely(sdebug_opts & SDEBUG_OPT_TRANSPORT_ERR)) { in schedule_resp()
7212 cmnd->result = check_condition_result; in schedule_resp()
7216 if (unlikely(sdebug_verbose && cmnd->result)) in schedule_resp()
7217 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", in schedule_resp()
7218 __func__, cmnd->result); in schedule_resp()
7239 u64 d = ktime_get_boottime_ns() - ns_from_boot; in schedule_resp()
7247 kt -= d; in schedule_resp()
7251 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
7253 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
7254 sd_dp->cmpl_ts = ktime_add(ns_to_ktime(ns_from_boot), kt); in schedule_resp()
7255 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); in schedule_resp()
7256 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
7259 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
7260 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); in schedule_resp()
7261 hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); in schedule_resp()
7263 * The completion handler will try to grab sqcp->lock, in schedule_resp()
7268 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
7273 sd_dp->aborted = true; in schedule_resp()
7280 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
7282 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
7283 sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot); in schedule_resp()
7284 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); in schedule_resp()
7285 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
7287 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
7288 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_WQ); in schedule_resp()
7289 schedule_work(&sd_dp->ew.work); in schedule_resp()
7290 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
7296 respond_in_thread: /* call back to mid-layer using invocation thread */ in schedule_resp()
7297 cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; in schedule_resp()
7298 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
7299 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
7300 cmnd->result = scsi_result; in schedule_resp()
7398 MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny");
7400 MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
7402 MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
7415 MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)");
7416 MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)");
7417 MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)");
7418 MODULE_PARM_DESC(atomic_write, "enable ATOMIC WRITE support, support WRITE ATOMIC(16) (def=0)");
7420 MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
7425 MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)");
7426 MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
7433 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
7436 MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1))");
7440 MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=7[SPC-5])");
7444 MODULE_PARM_DESC(submit_queues, "support for block multi-queue (def=1)");
7456 "1->use uuid for lu name, 0->don't, 2->all use same (def=0)");
7457 MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
7458 MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
7461 MODULE_PARM_DESC(zbc, "'none' [0]; 'aware' [1]; 'managed' [2] (def=0). Can have 'host-' prefix");
7477 if (k >= (SDEBUG_INFO_LEN - 1)) in scsi_debug_info()
7479 scnprintf(sdebug_info + k, SDEBUG_INFO_LEN - k, in scsi_debug_info()
7495 return -EACCES; in scsi_debug_write_info()
7499 return -EINVAL; in scsi_debug_write_info()
7520 int queue_num = data->queue_num; in sdebug_submit_queue_iter()
7526 if (*data->first == -1) in sdebug_submit_queue_iter()
7527 *data->first = *data->last = tag; in sdebug_submit_queue_iter()
7529 *data->last = tag; in sdebug_submit_queue_iter()
7569 int f = -1, l = -1; in scsi_debug_show_info()
7576 blk_mq_tagset_busy_iter(&host->tag_set, sdebug_submit_queue_iter, in scsi_debug_show_info()
7584 seq_printf(m, "this host_no=%d\n", host->host_no); in scsi_debug_show_info()
7594 idx = sdhp->si_idx; in scsi_debug_show_info()
7596 sdhp->shost->host_no, idx); in scsi_debug_show_info()
7618 /* Returns -EBUSY if jdelay is being changed and commands are queued. The unit
7635 struct Scsi_Host *shost = sdhp->shost; in delay_store()
7638 res = -EBUSY; /* queued commands */ in delay_store()
7651 return -EINVAL; in delay_store()
7659 /* Returns -EBUSY if ndelay is being changed and commands are queued */
7676 struct Scsi_Host *shost = sdhp->shost; in ndelay_store()
7679 res = -EBUSY; /* queued commands */ in ndelay_store()
7694 return -EINVAL; in ndelay_store()
7718 return -EINVAL; in opts_store()
7739 return -EINVAL; in ptype_store()
7743 return -EINVAL; in ptype_store()
7747 return -EINVAL; in ptype_store()
7764 return -EINVAL; in dsense_store()
7786 if (want_store) { /* 1 --> 0 transition, set up store */ in fake_rw_store()
7799 if (sdhp->si_idx != idx) { in fake_rw_store()
7800 xa_set_mark(per_store_ap, sdhp->si_idx, in fake_rw_store()
7802 sdhp->si_idx = idx; in fake_rw_store()
7806 } else { /* 0 --> 1 transition is trigger for shrink */ in fake_rw_store()
7812 return -EINVAL; in fake_rw_store()
7829 return -EINVAL; in no_lun_0_store()
7847 return -EINVAL; in num_tgts_store()
7868 return -EINVAL; in per_host_store_store()
7900 return -EINVAL; in every_nth_store()
7924 return -EINVAL; in lun_format_store()
7928 return -EINVAL; in lun_format_store()
7932 if (changed && sdebug_scsi_level >= 5) { /* >= SPC-3 */ in lun_format_store()
7938 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in lun_format_store()
7939 set_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in lun_format_store()
7946 return -EINVAL; in lun_format_store()
7963 return -EINVAL; in max_luns_store()
7968 if (changed && (sdebug_scsi_level >= 5)) { /* >= SPC-3 */ in max_luns_store()
7975 list_for_each_entry(dp, &sdhp->dev_info_list, in max_luns_store()
7978 dp->uas_bm); in max_luns_store()
7985 return -EINVAL; in max_luns_store()
8009 count = -EBUSY; in max_queue_store()
8013 return -EINVAL; in max_queue_store()
8032 return -EINVAL; in no_rwlock_store()
8069 return -ENOTSUPP; in virtual_gb_store()
8082 list_for_each_entry(dp, &sdhp->dev_info_list, in virtual_gb_store()
8085 dp->uas_bm); in virtual_gb_store()
8092 return -EINVAL; in virtual_gb_store()
8112 return -EINVAL; in add_host_store()
8123 if (found) /* re-use case */ in add_host_store()
8130 } while (--delta_hosts); in add_host_store()
8153 return -EINVAL; in vpd_use_hostno_store()
8175 return -EINVAL; in statistics_store()
8220 return scnprintf(buf, PAGE_SIZE, "0-%u\n", in map_show()
8227 count = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", in map_show()
8228 (int)map_size, sip->map_storep); in map_show()
8248 return -EINVAL; in random_store()
8268 return -EINVAL; in removable_store()
8286 return -EINVAL; in host_lock_store()
8303 return -EINVAL; in strict_store()
8333 [BLK_ZONED_HA] = "host-aware",
8334 [BLK_ZONED_HM] = "host-managed",
8358 return -EINVAL; in sdeb_zbc_model_str()
8383 p += scnprintf(p, end - p, "%d %ld\n", i, in group_number_stats_show()
8386 return p - buf; in group_number_stats_show()
8459 int idx = -1; in scsi_debug_init()
8475 return -EINVAL; in scsi_debug_init()
8489 return -EINVAL; in scsi_debug_init()
8494 return -EINVAL; in scsi_debug_init()
8499 return -EINVAL; in scsi_debug_init()
8504 return -EINVAL; in scsi_debug_init()
8509 return -EINVAL; in scsi_debug_init()
8528 return -EINVAL; in scsi_debug_init()
8533 return -EINVAL; in scsi_debug_init()
8538 return -EINVAL; in scsi_debug_init()
8545 return -EINVAL; in scsi_debug_init()
8576 return -EINVAL; in scsi_debug_init()
8623 return -EINVAL; in scsi_debug_init()
8663 k, -ret); in scsi_debug_init()
8670 pr_err("add_host k=%d error=%d\n", k, -ret); in scsi_debug_init()
8693 for (; k; k--) in scsi_debug_exit()
8727 vfree(sip->map_storep); in sdebug_erase_store()
8728 vfree(sip->dif_storep); in sdebug_erase_store()
8729 vfree(sip->storep); in sdebug_erase_store()
8765 return -ENOMEM; in sdebug_add_store()
8772 pr_warn("%s: xa_alloc() errno=%d\n", __func__, -res); in sdebug_add_store()
8780 res = -ENOMEM; in sdebug_add_store()
8781 sip->storep = vzalloc(sz); in sdebug_add_store()
8782 if (!sip->storep) { in sdebug_add_store()
8787 sdebug_build_parts(sip->storep, sz); in sdebug_add_store()
8794 sip->dif_storep = vmalloc(dif_size); in sdebug_add_store()
8797 sip->dif_storep); in sdebug_add_store()
8799 if (!sip->dif_storep) { in sdebug_add_store()
8803 memset(sip->dif_storep, 0xff, dif_size); in sdebug_add_store()
8807 map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1; in sdebug_add_store()
8808 sip->map_storep = vmalloc(array_size(sizeof(long), in sdebug_add_store()
8813 if (!sip->map_storep) { in sdebug_add_store()
8814 pr_err("LBP map oom\n"); in sdebug_add_store()
8818 bitmap_zero(sip->map_storep, map_size); in sdebug_add_store()
8825 rwlock_init(&sip->macc_data_lck); in sdebug_add_store()
8826 rwlock_init(&sip->macc_meta_lck); in sdebug_add_store()
8827 rwlock_init(&sip->macc_sector_lck); in sdebug_add_store()
8831 pr_warn("%s: failed, errno=%d\n", __func__, -res); in sdebug_add_store()
8838 int error = -ENOMEM; in sdebug_add_host_helper()
8844 return -ENOMEM; in sdebug_add_host_helper()
8848 sdbg_host->si_idx = idx; in sdebug_add_host_helper()
8850 INIT_LIST_HEAD(&sdbg_host->dev_info_list); in sdebug_add_host_helper()
8860 list_add_tail(&sdbg_host->host_list, &sdebug_host_list); in sdebug_add_host_helper()
8863 sdbg_host->dev.bus = &pseudo_lld_bus; in sdebug_add_host_helper()
8864 sdbg_host->dev.parent = pseudo_primary; in sdebug_add_host_helper()
8865 sdbg_host->dev.release = &sdebug_release_adapter; in sdebug_add_host_helper()
8866 dev_set_name(&sdbg_host->dev, "adapter%d", sdebug_num_hosts); in sdebug_add_host_helper()
8868 error = device_register(&sdbg_host->dev); in sdebug_add_host_helper()
8871 list_del(&sdbg_host->host_list); in sdebug_add_host_helper()
8880 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_add_host_helper()
8882 list_del(&sdbg_devinfo->dev_list); in sdebug_add_host_helper()
8883 kfree(sdbg_devinfo->zstate); in sdebug_add_host_helper()
8886 if (sdbg_host->dev.release) in sdebug_add_host_helper()
8887 put_device(&sdbg_host->dev); in sdebug_add_host_helper()
8890 pr_warn("%s: failed, errno=%d\n", __func__, -error); in sdebug_add_host_helper()
8908 int idx = -1; in sdebug_do_remove_host()
8916 idx = sdbg_host->si_idx; in sdebug_do_remove_host()
8924 if (idx == sdbg_host2->si_idx) { in sdebug_do_remove_host()
8932 --sdeb_most_recent_idx; in sdebug_do_remove_host()
8936 list_del(&sdbg_host->host_list); in sdebug_do_remove_host()
8942 device_unregister(&sdbg_host->dev); in sdebug_do_remove_host()
8943 --sdebug_num_hosts; in sdebug_do_remove_host()
8948 struct sdebug_dev_info *devip = sdev->hostdata; in sdebug_change_qdepth()
8951 return -ENODEV; in sdebug_change_qdepth()
8963 if (qdepth != sdev->queue_depth) in sdebug_change_qdepth()
8972 return sdev->queue_depth; in sdebug_change_qdepth()
8978 if (sdebug_every_nth < -1) in fake_timeout()
8979 sdebug_every_nth = -1; in fake_timeout()
8995 struct scsi_device *sdp = scp->device; in resp_not_ready()
8997 stopped_state = atomic_read(&devip->stopped); in resp_not_ready()
8999 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_not_ready()
9000 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_not_ready()
9003 atomic_set(&devip->stopped, 0); in resp_not_ready()
9011 if (scp->cmnd[0] == TEST_UNIT_READY) { in resp_not_ready()
9015 diff_ns = tur_nanosecs_to_ready - diff_ns; in resp_not_ready()
9018 /* As per 20-061r2 approved for spc6 by T10 on 20200716 */ in resp_not_ready()
9020 scsi_set_sense_information(scp->sense_buffer, SCSI_SENSE_BUFFERSIZE, in resp_not_ready()
9036 if (shost->nr_hw_queues == 1) in sdebug_map_queues()
9040 struct blk_mq_queue_map *map = &shost->tag_set.map[i]; in sdebug_map_queues()
9042 map->nr_queues = 0; in sdebug_map_queues()
9045 map->nr_queues = submit_queues - poll_queues; in sdebug_map_queues()
9047 map->nr_queues = poll_queues; in sdebug_map_queues()
9049 if (!map->nr_queues) { in sdebug_map_queues()
9054 map->queue_offset = qoff; in sdebug_map_queues()
9057 qoff += map->nr_queues; in sdebug_map_queues()
9079 int queue_num = data->queue_num; in sdebug_blk_mq_poll_iter()
9087 if (!test_bit(SCMD_STATE_INFLIGHT, &cmd->state)) in sdebug_blk_mq_poll_iter()
9092 spin_lock_irqsave(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
9093 sd_dp = &sdsc->sd_dp; in sdebug_blk_mq_poll_iter()
9094 if (READ_ONCE(sd_dp->defer_t) != SDEB_DEFER_POLL) { in sdebug_blk_mq_poll_iter()
9095 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
9099 if (time < sd_dp->cmpl_ts) { in sdebug_blk_mq_poll_iter()
9100 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
9103 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
9107 if (raw_smp_processor_id() != sd_dp->issuing_cpu) in sdebug_blk_mq_poll_iter()
9112 (*data->num_entries)++; in sdebug_blk_mq_poll_iter()
9124 blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_blk_mq_poll_iter, in sdebug_blk_mq_poll()
9134 struct scsi_device *sdp = cmnd->device; in sdebug_timeout_cmd()
9135 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in sdebug_timeout_cmd()
9137 unsigned char *cmd = cmnd->cmnd; in sdebug_timeout_cmd()
9144 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_timeout_cmd()
9145 if (err->type == ERR_TMOUT_CMD && in sdebug_timeout_cmd()
9146 (err->cmd == cmd[0] || err->cmd == 0xff)) { in sdebug_timeout_cmd()
9147 ret = !!err->cnt; in sdebug_timeout_cmd()
9148 if (err->cnt < 0) in sdebug_timeout_cmd()
9149 err->cnt++; in sdebug_timeout_cmd()
9162 struct scsi_device *sdp = cmnd->device; in sdebug_fail_queue_cmd()
9163 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in sdebug_fail_queue_cmd()
9165 unsigned char *cmd = cmnd->cmnd; in sdebug_fail_queue_cmd()
9172 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_fail_queue_cmd()
9173 if (err->type == ERR_FAIL_QUEUE_CMD && in sdebug_fail_queue_cmd()
9174 (err->cmd == cmd[0] || err->cmd == 0xff)) { in sdebug_fail_queue_cmd()
9175 ret = err->cnt ? err->queuecmd_ret : 0; in sdebug_fail_queue_cmd()
9176 if (err->cnt < 0) in sdebug_fail_queue_cmd()
9177 err->cnt++; in sdebug_fail_queue_cmd()
9191 struct scsi_device *sdp = cmnd->device; in sdebug_fail_cmd()
9192 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in sdebug_fail_cmd()
9194 unsigned char *cmd = cmnd->cmnd; in sdebug_fail_cmd()
9202 list_for_each_entry_rcu(err, &devip->inject_err_list, list) { in sdebug_fail_cmd()
9203 if (err->type == ERR_FAIL_CMD && in sdebug_fail_cmd()
9204 (err->cmd == cmd[0] || err->cmd == 0xff)) { in sdebug_fail_cmd()
9205 if (!err->cnt) { in sdebug_fail_cmd()
9210 ret = !!err->cnt; in sdebug_fail_cmd()
9220 if (err->cnt < 0) in sdebug_fail_cmd()
9221 err->cnt++; in sdebug_fail_cmd()
9222 mk_sense_buffer(cmnd, err->sense_key, err->asc, err->asq); in sdebug_fail_cmd()
9223 result = err->status_byte | err->host_byte << 16 | err->driver_byte << 24; in sdebug_fail_cmd()
9234 struct scsi_device *sdp = scp->device; in scsi_debug_queuecommand()
9238 u8 *cmd = scp->cmnd; in scsi_debug_queuecommand()
9243 u64 lun_index = sdp->lun & 0x3FFF; in scsi_debug_queuecommand()
9247 u32 devsel = sdebug_get_devsel(scp->device); in scsi_debug_queuecommand()
9265 len = scp->cmd_len; in scsi_debug_queuecommand()
9271 n += scnprintf(b + n, sb - n, "%02x ", in scsi_debug_queuecommand()
9279 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS); in scsi_debug_queuecommand()
9285 devip = (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_queuecommand()
9317 na = oip->num_attached; in scsi_debug_queuecommand()
9318 r_pfp = oip->pfp; in scsi_debug_queuecommand()
9321 if (FF_SA & r_oip->flags) { in scsi_debug_queuecommand()
9322 if (F_SA_LOW & oip->flags) in scsi_debug_queuecommand()
9326 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
9327 if (opcode == oip->opcode && sa == oip->sa && in scsi_debug_queuecommand()
9328 (devsel & oip->devsel) != 0) in scsi_debug_queuecommand()
9332 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
9333 if (opcode == oip->opcode && in scsi_debug_queuecommand()
9334 (devsel & oip->devsel) != 0) in scsi_debug_queuecommand()
9339 if (F_SA_LOW & r_oip->flags) in scsi_debug_queuecommand()
9341 else if (F_SA_HIGH & r_oip->flags) in scsi_debug_queuecommand()
9348 flags = oip->flags; in scsi_debug_queuecommand()
9364 for (k = 1; k < oip->len_mask[0] && k < 16; ++k) { in scsi_debug_queuecommand()
9365 rem = ~oip->len_mask[k] & cmd[k]; in scsi_debug_queuecommand()
9367 for (j = 7; j >= 0; --j, rem <<= 1) { in scsi_debug_queuecommand()
9377 find_first_bit(devip->uas_bm, in scsi_debug_queuecommand()
9383 if (unlikely(((F_M_ACCESS & flags) || scp->cmnd[0] == TEST_UNIT_READY) && in scsi_debug_queuecommand()
9384 atomic_read(&devip->stopped))) { in scsi_debug_queuecommand()
9395 if (likely(oip->pfp)) in scsi_debug_queuecommand()
9396 pfp = oip->pfp; /* calls a resp_* function */ in scsi_debug_queuecommand()
9428 struct sdebug_defer *sd_dp = &sdsc->sd_dp; in sdebug_init_cmd_priv()
9430 spin_lock_init(&sdsc->lock); in sdebug_init_cmd_priv()
9431 hrtimer_setup(&sd_dp->hrt, sdebug_q_cmd_hrt_complete, CLOCK_MONOTONIC, in sdebug_init_cmd_priv()
9433 INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); in sdebug_init_cmd_priv()
9461 .max_sectors = -1U,
9462 .max_segment_size = -1U,
9484 error = -ENODEV; in sdebug_driver_probe()
9487 hpnt->can_queue = sdebug_max_queue; in sdebug_driver_probe()
9488 hpnt->cmd_per_lun = sdebug_max_queue; in sdebug_driver_probe()
9490 hpnt->dma_boundary = PAGE_SIZE - 1; in sdebug_driver_probe()
9501 hpnt->nr_hw_queues = submit_queues; in sdebug_driver_probe()
9503 hpnt->host_tagset = 1; in sdebug_driver_probe()
9506 if (hpnt->nr_hw_queues == 1 || (poll_queues < 1)) { in sdebug_driver_probe()
9508 my_name, poll_queues, hpnt->nr_hw_queues); in sdebug_driver_probe()
9514 * left over for non-polled I/O. in sdebug_driver_probe()
9522 my_name, submit_queues - 1); in sdebug_driver_probe()
9526 hpnt->nr_maps = 3; in sdebug_driver_probe()
9528 sdbg_host->shost = hpnt; in sdebug_driver_probe()
9529 if ((hpnt->this_id >= 0) && (sdebug_num_tgts > hpnt->this_id)) in sdebug_driver_probe()
9530 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_driver_probe()
9532 hpnt->max_id = sdebug_num_tgts; in sdebug_driver_probe()
9534 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_driver_probe()
9585 error = scsi_add_host(hpnt, &sdbg_host->dev); in sdebug_driver_probe()
9588 error = -ENODEV; in sdebug_driver_probe()
9604 scsi_remove_host(sdbg_host->shost); in sdebug_driver_remove()
9606 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_driver_remove()
9608 list_del(&sdbg_devinfo->dev_list); in sdebug_driver_remove()
9609 kfree(sdbg_devinfo->zstate); in sdebug_driver_remove()
9613 scsi_host_put(sdbg_host->shost); in sdebug_driver_remove()