Lines Matching +full:tp +full:- +full:sensitive +full:- +full:adjust

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>
143 #define DEF_SCSI_LEVEL 7 /* INQUIRY, byte2 [6->SPC-4; 7->SPC-5] */
157 #define JDELAY_OVERRIDDEN -9999
195 /* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs) are returned in
217 * per-device DEF_CMD_PER_LUN can be changed via sysfs:
225 /* UA - Unit Attention; SA - Service Action; SSU - Start Stop Unit */
226 #define F_D_IN 1 /* Data-in command (e.g. READ) */
227 #define F_D_OUT 2 /* Data-out command (e.g. WRITE) */
230 #define F_RL_WLUN_OK 0x10 /* allowed with REPORT LUNS W-LUN */
238 #define F_SSU_DELAY 0x1000 /* SSU command delay (long-ish) */
375 u32 flags; /* OR-ed set of SDEB_F_* */
378 u8 len_mask[16]; /* len_mask[0]-->cdb_len, then mask for cdb */
415 SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */
421 /* 0x0; 0x0->0x1f: 6 byte cdbs */
429 /* 0x20; 0x20->0x3f: 10 byte cdbs */
434 /* 0x40; 0x40->0x5f: 10 byte cdbs */
440 /* 0x60; 0x60->0x7d are reserved, 0x7e is "extended cdb" */
444 /* 0x80; 0x80->0x9f: 16 byte cdbs */
451 /* 0xa0; 0xa0->0xbf: 12 byte cdbs */
458 /* 0xc0; 0xc0->0xff: vendor specific */
466 * The following "response" functions return the SCSI mid-level's 4 byte
467 * tuple-in-an-int. To handle commands with an IMMED bit, for a faster
512 * the opcode_info_arr array. The most time sensitive (or commonly used) cdb
603 0xff, 0xff, 0xff, 0xff, 0x3f, 0xc7} }, /* PRE-FETCH (16) */
723 0, 0, 0, 0} }, /* PRE-FETCH (10) */
821 static int sdeb_first_idx = -1; /* invalid index ==> none created */
822 static int sdeb_most_recent_idx = -1;
836 static bool sdeb_zbc_in_use; /* true for host-aware and host-managed disks */
842 static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */
889 if (!sip || !sip->storep) { in lba2fake_store()
893 return lsip->storep + lba * sdebug_sector_size; in lba2fake_store()
901 return sip->dif_storep + sector; in dif_store()
911 hpnt = sdbg_host->shost; in sdebug_max_tgts_luns()
912 if ((hpnt->this_id >= 0) && in sdebug_max_tgts_luns()
913 (sdebug_num_tgts > hpnt->this_id)) in sdebug_max_tgts_luns()
914 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_max_tgts_luns()
916 hpnt->max_id = sdebug_num_tgts; in sdebug_max_tgts_luns()
918 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_max_tgts_luns()
925 /* Set in_bit to -1 to indicate no bit position of invalid field */
934 sbuff = scp->sense_buffer; in mk_sense_invalid_fld()
936 sdev_printk(KERN_ERR, scp->device, in mk_sense_invalid_fld()
961 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq" in mk_sense_invalid_fld()
968 if (!scp->sense_buffer) { in mk_sense_buffer()
969 sdev_printk(KERN_ERR, scp->device, in mk_sense_buffer()
973 memset(scp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in mk_sense_buffer()
978 sdev_printk(KERN_INFO, scp->device, in mk_sense_buffer()
1003 return -EINVAL; in scsi_debug_ioctl()
1004 /* return -ENOTTY; // correct return but upsets fdisk */ in scsi_debug_ioctl()
1011 sdev->use_10_for_rw = false; in config_cdb_len()
1012 sdev->use_16_for_rw = false; in config_cdb_len()
1013 sdev->use_10_for_ms = false; in config_cdb_len()
1016 sdev->use_10_for_rw = true; in config_cdb_len()
1017 sdev->use_16_for_rw = false; in config_cdb_len()
1018 sdev->use_10_for_ms = false; in config_cdb_len()
1021 sdev->use_10_for_rw = true; in config_cdb_len()
1022 sdev->use_16_for_rw = false; in config_cdb_len()
1023 sdev->use_10_for_ms = true; in config_cdb_len()
1026 sdev->use_10_for_rw = false; in config_cdb_len()
1027 sdev->use_16_for_rw = true; in config_cdb_len()
1028 sdev->use_10_for_ms = true; in config_cdb_len()
1031 sdev->use_10_for_rw = false; in config_cdb_len()
1032 sdev->use_16_for_rw = true; in config_cdb_len()
1033 sdev->use_10_for_ms = true; in config_cdb_len()
1038 sdev->use_10_for_rw = true; in config_cdb_len()
1039 sdev->use_16_for_rw = false; in config_cdb_len()
1040 sdev->use_10_for_ms = false; in config_cdb_len()
1054 shost = sdbg_host->shost; in all_config_cdb_len()
1069 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in clear_luns_changed_on_target()
1070 if ((devip->sdbg_host == dp->sdbg_host) && in clear_luns_changed_on_target()
1071 (devip->target == dp->target)) in clear_luns_changed_on_target()
1072 clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in clear_luns_changed_on_target()
1082 k = find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS); in make_ua()
1133 * SPC-3 behavior is to report a UNIT ATTENTION with in make_ua()
1136 * received. SPC-4 behavior is to report it only once. in make_ua()
1138 * values as struct scsi_device->scsi_level. in make_ua()
1140 if (sdebug_scsi_level >= 6) /* SPC-4 and above */ in make_ua()
1154 clear_bit(k, devip->uas_bm); in make_ua()
1156 sdev_printk(KERN_INFO, scp->device, in make_ua()
1164 /* Build SCSI "data-in" buffer. Returns 0 if ok else (DID_ERROR << 16). */
1169 struct scsi_data_buffer *sdb = &scp->sdb; in fill_from_dev_buffer()
1171 if (!sdb->length) in fill_from_dev_buffer()
1173 if (scp->sc_data_direction != DMA_FROM_DEVICE) in fill_from_dev_buffer()
1176 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, in fill_from_dev_buffer()
1178 scsi_set_resid(scp, scsi_bufflen(scp) - act_len); in fill_from_dev_buffer()
1183 /* Partial build of SCSI "data-in" buffer. Returns 0 if ok else
1184 * (DID_ERROR << 16). Can write to offset in data-in buffer. If multiple
1192 struct scsi_data_buffer *sdb = &scp->sdb; in p_fill_from_dev_buffer()
1195 if (sdb->length <= off_dst) in p_fill_from_dev_buffer()
1197 if (scp->sc_data_direction != DMA_FROM_DEVICE) in p_fill_from_dev_buffer()
1200 act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents, in p_fill_from_dev_buffer()
1205 n = scsi_bufflen(scp) - (off_dst + act_len); in p_fill_from_dev_buffer()
1210 /* Fetches from SCSI "data-out" buffer. Returns number of bytes fetched into
1211 * 'arr' or -1 if error.
1218 if (scp->sc_data_direction != DMA_TO_DEVICE) in fetch_to_dev_buffer()
1219 return -1; in fetch_to_dev_buffer()
1265 /* NAA-3, Logical unit identifier (binary) */ in inquiry_vpd_83()
1283 /* NAA-3, Target port identifier */ in inquiry_vpd_83()
1290 /* NAA-3, Target port group identifier */ in inquiry_vpd_83()
1299 /* NAA-3, Target device identifier */ in inquiry_vpd_83()
1307 arr[num++] = 0x63; /* proto=sas, UTF-8 */ in inquiry_vpd_83()
1351 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1363 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1384 arr[num++] = 12; /* length tp descriptor */ in inquiry_vpd_88()
1385 /* naa-5 target port identifier (A) */ in inquiry_vpd_88()
1399 arr[num++] = 12; /* length tp descriptor */ in inquiry_vpd_88()
1400 /* naa-5 target port identifier (B) */ in inquiry_vpd_88()
1471 /* Block limits VPD page (SBC-3) */
1518 /* Block device characteristics VPD page (SBC-3) */
1526 if (devip->zmodel == BLK_ZONED_HA) in inquiry_vpd_b1()
1532 /* Logical block provisioning VPD page (SBC-4) */
1558 * Optimal number of non-sequentially written sequential write in inquiry_vpd_b6()
1564 if (sdeb_zbc_model == BLK_ZONED_HM && devip->max_open) in inquiry_vpd_b6()
1565 put_unaligned_be32(devip->max_open, &arr[12]); in inquiry_vpd_b6()
1568 if (devip->zcap < devip->zsize) { in inquiry_vpd_b6()
1570 put_unaligned_be64(devip->zsize, &arr[20]); in inquiry_vpd_b6()
1584 unsigned char *cmd = scp->cmnd; in resp_inquiry()
1594 is_zbc = (devip->zmodel != BLK_ZONED_NONE); in resp_inquiry()
1596 have_wlun = scsi_is_wlun(scp->device->lun); in resp_inquiry()
1599 else if (sdebug_no_lun_0 && (devip->lun == SDEBUG_LUN_0_VAL)) in resp_inquiry()
1612 int host_no = devip->sdbg_host->shost->host_no; in resp_inquiry()
1615 (devip->channel & 0x7f); in resp_inquiry()
1618 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) + in resp_inquiry()
1619 (devip->target * 1000) + devip->lun); in resp_inquiry()
1621 (devip->target * 1000) - 3; in resp_inquiry()
1643 arr[3] = n - 4; /* number of supported VPD pages */ in resp_inquiry()
1653 &devip->lu_name); in resp_inquiry()
1673 arr[4] = 0x2; /* disconnect-reconnect mp */ in resp_inquiry()
1697 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_inquiry()
1711 arr[4] = SDEBUG_LONG_INQ_SZ - 5; in resp_inquiry()
1724 put_unaligned_be16(0xc0, arr + 58); /* SAM-6 no version claimed */ in resp_inquiry()
1725 put_unaligned_be16(0x5c0, arr + 60); /* SPC-5 no version claimed */ in resp_inquiry()
1727 if (is_disk) { /* SBC-4 no version claimed */ in resp_inquiry()
1730 } else if (sdebug_ptype == TYPE_TAPE) { /* SSC-4 rev 3 */ in resp_inquiry()
1737 put_unaligned_be16(0x2100, arr + n); /* SPL-4 no version claimed */ in resp_inquiry()
1751 unsigned char *cmd = scp->cmnd; in resp_requests()
1756 int stopped_state = atomic_read(&devip->stopped); in resp_requests()
1804 unsigned char *cmd = scp->cmnd; in resp_start_stop()
1814 stopped_state = atomic_read(&devip->stopped); in resp_start_stop()
1818 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_start_stop()
1819 u64 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_start_stop()
1823 atomic_set(&devip->stopped, 0); in resp_start_stop()
1838 atomic_xchg(&devip->stopped, want_stop); in resp_start_stop()
1867 capac = (unsigned int)sdebug_capacity - 1; in resp_readcap()
1879 unsigned char *cmd = scp->cmnd; in resp_readcap16()
1887 put_unaligned_be64((u64)(sdebug_capacity - 1), arr + 0); in resp_readcap16()
1904 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices. in resp_readcap16()
1906 if (devip->zmodel == BLK_ZONED_HM) in resp_readcap16()
1912 arr[12] = (sdebug_dif - 1) << 1; /* P_TYPE */ in resp_readcap16()
1925 unsigned char *cmd = scp->cmnd; in resp_report_tgtpgs()
1927 int host_no = devip->sdbg_host->shost->host_no; in resp_report_tgtpgs()
1945 (devip->channel & 0x7f); in resp_report_tgtpgs()
1947 (devip->channel & 0x7f) + 0x80; in resp_report_tgtpgs()
1983 rlen = n - 4; in resp_report_tgtpgs()
1988 * - The allocated length in resp_report_tgtpgs()
1989 * - The constructed command length in resp_report_tgtpgs()
1990 * - The maximum array size in resp_report_tgtpgs()
2010 u8 *cmd = scp->cmnd; in resp_rsup_opcodes()
2018 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_opcodes()
2035 oip->num_attached != 0xff; ++oip) { in resp_rsup_opcodes()
2036 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2038 count += (oip->num_attached + 1); in resp_rsup_opcodes()
2043 oip->num_attached != 0xff && offset < a_len; ++oip) { in resp_rsup_opcodes()
2044 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2046 na = oip->num_attached; in resp_rsup_opcodes()
2047 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2048 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2051 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2053 put_unaligned_be16(oip->len_mask[0], arr + offset + 6); in resp_rsup_opcodes()
2057 for (k = 0, oip = oip->arrp; k < na; ++k, ++oip) { in resp_rsup_opcodes()
2058 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2061 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2062 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2065 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2067 put_unaligned_be16(oip->len_mask[0], in resp_rsup_opcodes()
2082 if (F_INV_OP & oip->flags) { in resp_rsup_opcodes()
2087 if (FF_SA & oip->flags) { in resp_rsup_opcodes()
2095 0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2096 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); in resp_rsup_opcodes()
2100 if (0 == (FF_SA & oip->flags) && in resp_rsup_opcodes()
2101 req_opcode == oip->opcode) in resp_rsup_opcodes()
2103 else if (0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2104 na = oip->num_attached; in resp_rsup_opcodes()
2105 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2107 if (req_opcode == oip->opcode) in resp_rsup_opcodes()
2111 } else if (req_sa != oip->sa) { in resp_rsup_opcodes()
2112 na = oip->num_attached; in resp_rsup_opcodes()
2113 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2115 if (req_sa == oip->sa) in resp_rsup_opcodes()
2122 u = oip->len_mask[0]; in resp_rsup_opcodes()
2124 arr[4] = oip->opcode; in resp_rsup_opcodes()
2127 oip->len_mask[k] : 0xff; in resp_rsup_opcodes()
2156 u8 *cmd = scp->cmnd; in resp_rsup_tmfs()
2162 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_tmfs()
2180 { /* Read-Write Error Recovery page for mode_sense */ in resp_err_recov_pg()
2186 memset(p + 2, 0, sizeof(err_recov_pg) - 2); in resp_err_recov_pg()
2191 { /* Disconnect-Reconnect page for mode_sense */ in resp_disconnect_pg()
2197 memset(p + 2, 0, sizeof(disconnect_pg) - 2); in resp_disconnect_pg()
2213 memset(p + 2, 0, sizeof(format_pg) - 2); in resp_format_pg()
2281 { /* SAS SSP mode page - short format for mode_sense */ in resp_sas_sf_m_pg()
2287 memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2); in resp_sas_sf_m_pg()
2321 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); in resp_sas_pcd_m_spg()
2333 memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4); in resp_sas_sha_m_spg()
2346 int target = scp->device->id; in resp_mode_sense()
2349 unsigned char *cmd = scp->cmnd; in resp_mode_sense()
2359 is_zbc = (devip->zmodel != BLK_ZONED_NONE); in resp_mode_sense()
2370 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + in resp_mode_sense()
2371 (devip->target * 1000) - 3; in resp_mode_sense()
2374 dev_spec = 0x10; /* =0x90 if WP=1 implies read-only */ in resp_mode_sense()
2411 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2417 case 0x1: /* Read-Write error recovery page, direct access */ in resp_mode_sense()
2421 case 0x2: /* Disconnect-Reconnect page, all devices */ in resp_mode_sense()
2445 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2485 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2498 arr[0] = offset - 1; in resp_mode_sense()
2500 put_unaligned_be16((offset - 2), arr + 0); in resp_mode_sense()
2512 unsigned char *cmd = scp->cmnd; in resp_mode_select()
2520 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1); in resp_mode_select()
2524 if (-1 == res) in resp_mode_select()
2527 sdev_printk(KERN_INFO, scp->device, in resp_mode_select()
2534 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); in resp_mode_select()
2555 sizeof(caching_pg) - 2); in resp_mode_select()
2562 sizeof(ctrl_m_pg) - 2); in resp_mode_select()
2574 sizeof(iec_m_pg) - 2); in resp_mode_select()
2584 set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm); in resp_mode_select()
2631 unsigned char *cmd = scp->cmnd; in resp_log_sense()
2651 arr[3] = n - 4; in resp_log_sense()
2683 arr[3] = n - 4; in resp_log_sense()
2693 arr[3] = n - 4; in resp_log_sense()
2701 arr[3] = n - 4; in resp_log_sense()
2717 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_log_sense()
2727 return devip->nr_zones != 0; in sdebug_dev_is_zoned()
2733 u32 zno = lba >> devip->zsize_shift; in zbc_zone()
2736 if (devip->zcap == devip->zsize || zno < devip->nr_conv_zones) in zbc_zone()
2737 return &devip->zstate[zno]; in zbc_zone()
2740 * If the zone capacity is less than the zone size, adjust for gap in zbc_zone()
2743 zno = 2 * zno - devip->nr_conv_zones; in zbc_zone()
2744 WARN_ONCE(zno >= devip->nr_zones, "%u > %u\n", zno, devip->nr_zones); in zbc_zone()
2745 zsp = &devip->zstate[zno]; in zbc_zone()
2746 if (lba >= zsp->z_start + zsp->z_size) in zbc_zone()
2748 WARN_ON_ONCE(lba >= zsp->z_start + zsp->z_size); in zbc_zone()
2754 return zsp->z_type == ZBC_ZTYPE_CNV; in zbc_zone_is_conv()
2759 return zsp->z_type == ZBC_ZTYPE_GAP; in zbc_zone_is_gap()
2775 zc = zsp->z_cond; in zbc_close_zone()
2780 devip->nr_imp_open--; in zbc_close_zone()
2782 devip->nr_exp_open--; in zbc_close_zone()
2784 if (zsp->z_wp == zsp->z_start) { in zbc_close_zone()
2785 zsp->z_cond = ZC1_EMPTY; in zbc_close_zone()
2787 zsp->z_cond = ZC4_CLOSED; in zbc_close_zone()
2788 devip->nr_closed++; in zbc_close_zone()
2794 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_close_imp_open_zone()
2797 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_close_imp_open_zone()
2798 if (zsp->z_cond == ZC2_IMPLICIT_OPEN) { in zbc_close_imp_open_zone()
2813 zc = zsp->z_cond; in zbc_open_zone()
2819 if (explicit && zsp->z_cond == ZC2_IMPLICIT_OPEN) in zbc_open_zone()
2821 else if (devip->max_open && in zbc_open_zone()
2822 devip->nr_imp_open + devip->nr_exp_open >= devip->max_open) in zbc_open_zone()
2825 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_zone()
2826 devip->nr_closed--; in zbc_open_zone()
2828 zsp->z_cond = ZC3_EXPLICIT_OPEN; in zbc_open_zone()
2829 devip->nr_exp_open++; in zbc_open_zone()
2831 zsp->z_cond = ZC2_IMPLICIT_OPEN; in zbc_open_zone()
2832 devip->nr_imp_open++; in zbc_open_zone()
2839 switch (zsp->z_cond) { in zbc_set_zone_full()
2841 devip->nr_imp_open--; in zbc_set_zone_full()
2844 devip->nr_exp_open--; in zbc_set_zone_full()
2848 zsp->z_start, zsp->z_cond); in zbc_set_zone_full()
2851 zsp->z_cond = ZC5_FULL; in zbc_set_zone_full()
2858 unsigned long long n, end, zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
2863 if (zsp->z_type == ZBC_ZTYPE_SWR) { in zbc_inc_wp()
2864 zsp->z_wp += num; in zbc_inc_wp()
2865 if (zsp->z_wp >= zend) in zbc_inc_wp()
2871 if (lba != zsp->z_wp) in zbc_inc_wp()
2872 zsp->z_non_seq_resource = true; in zbc_inc_wp()
2876 n = zend - lba; in zbc_inc_wp()
2877 zsp->z_wp = zend; in zbc_inc_wp()
2878 } else if (end > zsp->z_wp) { in zbc_inc_wp()
2880 zsp->z_wp = end; in zbc_inc_wp()
2884 if (zsp->z_wp >= zend) in zbc_inc_wp()
2887 num -= n; in zbc_inc_wp()
2891 zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
2899 struct scsi_device *sdp = scp->device; in check_zbc_access_params()
2900 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_zbc_access_params()
2902 struct sdeb_zone_state *zsp_end = zbc_zone(devip, lba + num - 1); in check_zbc_access_params()
2905 if (devip->zmodel == BLK_ZONED_HA) in check_zbc_access_params()
2907 /* For host-managed, reads cannot cross zone types boundaries */ in check_zbc_access_params()
2908 if (zsp->z_type != zsp_end->z_type) { in check_zbc_access_params()
2935 if (zsp->z_type == ZBC_ZTYPE_SWR) { in check_zbc_access_params()
2944 if (zsp->z_cond == ZC5_FULL) { in check_zbc_access_params()
2950 if (lba != zsp->z_wp) { in check_zbc_access_params()
2959 if (zsp->z_cond == ZC1_EMPTY || zsp->z_cond == ZC4_CLOSED) { in check_zbc_access_params()
2960 if (devip->max_open && in check_zbc_access_params()
2961 devip->nr_exp_open >= devip->max_open) { in check_zbc_access_params()
2977 struct scsi_device *sdp = scp->device; in check_device_access_params()
2978 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_device_access_params()
3013 return xa_load(per_store_ap, devip->sdbg_host->si_idx); in devip2sip()
3016 /* Returns number of bytes copied or -1 if error. */
3023 struct scsi_data_buffer *sdb = &scp->sdb; in do_device_access()
3033 if (!sdb->length || !sip) in do_device_access()
3035 if (scp->sc_data_direction != dir) in do_device_access()
3036 return -1; in do_device_access()
3037 fsp = sip->storep; in do_device_access()
3041 rest = block + num - sdebug_store_sectors; in do_device_access()
3043 ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
3045 (num - rest) * sdebug_sector_size, sg_skip, do_write); in do_device_access()
3046 if (ret != (num - rest) * sdebug_sector_size) in do_device_access()
3050 ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
3052 sg_skip + ((num - rest) * sdebug_sector_size), in do_device_access()
3059 /* Returns number of bytes copied or -1 if error. */
3062 struct scsi_data_buffer *sdb = &scp->sdb; in do_dout_fetch()
3064 if (!sdb->length) in do_dout_fetch()
3066 if (scp->sc_data_direction != DMA_TO_DEVICE) in do_dout_fetch()
3067 return -1; in do_dout_fetch()
3068 return sg_copy_buffer(sdb->table.sgl, sdb->table.nents, doutp, in do_dout_fetch()
3072 /* If sip->storep+lba compares equal to arr(num), then copy top half of
3073 * arr into sip->storep+lba and return true. If comparison fails then
3082 u8 *fsp = sip->storep; in comp_write_worker()
3086 rest = block + num - store_blks; in comp_write_worker()
3088 res = !memcmp(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
3092 res = memcmp(fsp, arr + ((num - rest) * lb_size), in comp_write_worker()
3099 memcpy(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
3101 memcpy(fsp, arr + ((num - rest) * lb_size), rest * lb_size); in comp_write_worker()
3122 if (sdt->guard_tag != csum) { in dif_verify()
3125 be16_to_cpu(sdt->guard_tag), in dif_verify()
3130 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { in dif_verify()
3136 be32_to_cpu(sdt->ref_tag) != ei_lba) { in dif_verify()
3150 scp->device->hostdata, true); in dif_copy_prot()
3151 struct t10_pi_tuple *dif_storep = sip->dif_storep; in dif_copy_prot()
3168 rest = start + len - dif_store_end; in dif_copy_prot()
3173 memcpy(paddr, start, len - rest); in dif_copy_prot()
3175 memcpy(start, paddr, len - rest); in dif_copy_prot()
3179 memcpy(paddr + len - rest, dif_storep, rest); in dif_copy_prot()
3181 memcpy(dif_storep, paddr + len - rest, rest); in dif_copy_prot()
3185 resid -= len; in dif_copy_prot()
3197 scp->device->hostdata, true); in prot_verify_read()
3204 if (sdt->app_tag == cpu_to_be16(0xffff)) in prot_verify_read()
3214 if (scp->cmnd[1] >> 5) { /* RDPROTECT */ in prot_verify_read()
3235 __acquire(&sip->macc_lck); in sdeb_read_lock()
3240 read_lock(&sip->macc_lck); in sdeb_read_lock()
3251 __release(&sip->macc_lck); in sdeb_read_unlock()
3256 read_unlock(&sip->macc_lck); in sdeb_read_unlock()
3267 __acquire(&sip->macc_lck); in sdeb_write_lock()
3272 write_lock(&sip->macc_lck); in sdeb_write_lock()
3283 __release(&sip->macc_lck); in sdeb_write_unlock()
3288 write_unlock(&sip->macc_lck); in sdeb_write_unlock()
3302 u8 *cmd = scp->cmnd; in resp_read_dt0()
3352 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " in resp_read_dt0()
3365 (lba <= (sdebug_medium_error_start + sdebug_medium_error_count - 1)) && in resp_read_dt0()
3370 if (0x70 == (scp->sense_buffer[0] & 0x7f)) { in resp_read_dt0()
3371 scp->sense_buffer[0] |= 0x80; /* Valid bit */ in resp_read_dt0()
3374 put_unaligned_be32(ret, scp->sense_buffer + 3); in resp_read_dt0()
3390 } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { in resp_read_dt0()
3401 } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { in resp_read_dt0()
3412 if (unlikely(ret == -1)) in resp_read_dt0()
3415 scsi_set_resid(scp, scsi_bufflen(scp) - ret); in resp_read_dt0()
3482 if (SCpnt->cmnd[1] >> 5 != 3) { /* WRPROTECT */ in prot_verify_write()
3512 lba += sdebug_unmap_granularity - sdebug_unmap_alignment; in lba_to_map_index()
3522 lba -= sdebug_unmap_granularity - sdebug_unmap_alignment; in map_index_to_lba()
3535 mapped = test_bit(index, sip->map_storep); in map_state()
3538 next = find_next_zero_bit(sip->map_storep, map_size, index); in map_state()
3540 next = find_next_bit(sip->map_storep, map_size, index); in map_state()
3543 *num = end - lba; in map_state()
3556 set_bit(index, sip->map_storep); in map_region()
3566 u8 *fsp = sip->storep; in unmap_region()
3574 clear_bit(index, sip->map_storep); in unmap_region()
3581 if (sip->dif_storep) { in unmap_region()
3582 memset(sip->dif_storep + lba, 0xff, in unmap_region()
3583 sizeof(*sip->dif_storep) * in unmap_region()
3599 u8 *cmd = scp->cmnd; in resp_write_dt0()
3649 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_write_dt0()
3664 if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { in resp_write_dt0()
3668 } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ in resp_write_dt0()
3675 if (scp->prot_flags & SCSI_PROT_REF_CHECK) { in resp_write_dt0()
3679 } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ in resp_write_dt0()
3695 if (unlikely(-1 == ret)) in resp_write_dt0()
3699 sdev_printk(KERN_INFO, scp->device, in resp_write_dt0()
3730 u8 *cmd = scp->cmnd; in resp_write_scat()
3765 sdev_printk(KERN_ERR, scp->device, in resp_write_scat()
3770 return 0; /* T10 says these do-nothings are not errors */ in resp_write_scat()
3773 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3782 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3792 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3796 if (res == -1) { in resp_write_scat()
3809 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3822 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3850 if (unlikely(-1 == ret)) { in resp_write_scat()
3854 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3892 struct scsi_device *sdp = scp->device; in resp_write_same()
3893 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in resp_write_same()
3899 scp->device->hostdata, true); in resp_write_same()
3918 fsp = sip->storep; in resp_write_same()
3926 if (-1 == ret) { in resp_write_same()
3930 sdev_printk(KERN_INFO, scp->device, in resp_write_same()
3954 u8 *cmd = scp->cmnd; in resp_write_same_10()
3970 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_write_same_10()
3979 u8 *cmd = scp->cmnd; in resp_write_same_16()
3993 if (cmd[1] & 0x1) /* NDOB (no data-out buffer, assumes zeroes) */ in resp_write_same_16()
3998 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); in resp_write_same_16()
4005 * field. For the Report supported operation codes command, SPC-4 suggests
4010 u8 *cmd = scp->cmnd; in resp_write_buffer()
4011 struct scsi_device *sdp = scp->device; in resp_write_buffer()
4019 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in resp_write_buffer()
4020 set_bit(SDEBUG_UA_MICROCODE_CHANGED, devip->uas_bm); in resp_write_buffer()
4023 set_bit(SDEBUG_UA_MICROCODE_CHANGED_WO_RESET, devip->uas_bm); in resp_write_buffer()
4028 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
4030 if (dp->target == sdp->id) { in resp_write_buffer()
4031 set_bit(SDEBUG_UA_BUS_RESET, dp->uas_bm); in resp_write_buffer()
4034 dp->uas_bm); in resp_write_buffer()
4040 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
4042 if (dp->target == sdp->id) in resp_write_buffer()
4044 dp->uas_bm); in resp_write_buffer()
4056 u8 *cmd = scp->cmnd; in resp_comp_write()
4078 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_comp_write()
4094 if (ret == -1) { in resp_comp_write()
4098 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " in resp_comp_write()
4130 payload_len = get_unaligned_be16(scp->cmnd + 7); in resp_unmap()
4133 descriptors = (payload_len - 8) / 16; in resp_unmap()
4135 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_unmap()
4148 BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2); in resp_unmap()
4180 u8 *cmd = scp->cmnd; in resp_get_lba_status()
4204 if (sdebug_capacity - lba <= 0xffffffff) in resp_get_lba_status()
4205 num = sdebug_capacity - lba; in resp_get_lba_status()
4225 u8 *cmd = scp->cmnd; in resp_sync_cache()
4246 * Assuming the LBA+num_blocks is not out-of-range, this function will return
4259 u8 *cmd = scp->cmnd; in resp_pre_fetch()
4261 u8 *fsp = sip->storep; in resp_pre_fetch()
4266 } else { /* PRE-FETCH(16) */ in resp_pre_fetch()
4276 /* PRE-FETCH spec says nothing about LBP or PI so skip them */ in resp_pre_fetch()
4279 rest = block + nblks - sdebug_store_sectors; in resp_pre_fetch()
4281 /* Try to bring the PRE-FETCH range into CPU's cache */ in resp_pre_fetch()
4284 (nblks - rest) * sdebug_sector_size); in resp_pre_fetch()
4297 * (W-LUN), the normal Linux scanning logic does not associate it with a
4299 * "cd /sys/class/scsi_host/host<n> ; echo '- - 49409' > scan"
4301 * the above will associate a W-LUN to each target. To only get a W-LUN
4302 * for target 2, then use "echo '- 2 49409' > scan" .
4307 unsigned char *cmd = scp->cmnd; in resp_report_luns()
4314 unsigned int wlun_cnt; /* report luns W-LUN count */ in resp_report_luns()
4328 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_report_luns()
4333 case 0: /* all LUNs apart from W-LUNs */ in resp_report_luns()
4337 case 1: /* only W-LUNs */ in resp_report_luns()
4346 case 0x11: /* see SPC-5 */ in resp_report_luns()
4350 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_report_luns()
4355 --lun_cnt; in resp_report_luns()
4378 lun_p->scsi_lun[0] |= 0x40; in resp_report_luns()
4406 u8 *cmd = scp->cmnd; in resp_verify()
4449 if (ret == -1) { in resp_verify()
4453 sdev_printk(KERN_INFO, scp->device, in resp_verify()
4485 u8 *cmd = scp->cmnd; in resp_report_zones()
4505 rep_max_zones = (alloc_len - 64) >> ilog2(RZONES_DESC_HD); in resp_report_zones()
4518 lba = zsp->z_start + zsp->z_size) { in resp_report_zones()
4528 if (zsp->z_cond != ZC1_EMPTY) in resp_report_zones()
4533 if (zsp->z_cond != ZC2_IMPLICIT_OPEN) in resp_report_zones()
4538 if (zsp->z_cond != ZC3_EXPLICIT_OPEN) in resp_report_zones()
4543 if (zsp->z_cond != ZC4_CLOSED) in resp_report_zones()
4548 if (zsp->z_cond != ZC5_FULL) in resp_report_zones()
4555 * Read-only, offline, reset WP recommended are in resp_report_zones()
4560 /* non-seq-resource set */ in resp_report_zones()
4561 if (!zsp->z_non_seq_resource) in resp_report_zones()
4583 desc[0] = zsp->z_type; in resp_report_zones()
4584 desc[1] = zsp->z_cond << 4; in resp_report_zones()
4585 if (zsp->z_non_seq_resource) in resp_report_zones()
4587 put_unaligned_be64((u64)zsp->z_size, desc + 8); in resp_report_zones()
4588 put_unaligned_be64((u64)zsp->z_start, desc + 16); in resp_report_zones()
4589 put_unaligned_be64((u64)zsp->z_wp, desc + 24); in resp_report_zones()
4603 put_unaligned_be64(sdebug_capacity - 1, arr + 8); in resp_report_zones()
4605 if (devip->zcap < devip->zsize) in resp_report_zones()
4606 put_unaligned_be64(devip->zsize, arr + 16); in resp_report_zones()
4608 rep_len = (unsigned long)desc - (unsigned long)arr; in resp_report_zones()
4617 /* Logic transplanted from tcmu-runner, file_zbc.c */
4620 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_open_all()
4623 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_open_all()
4624 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_all()
4625 zbc_open_zone(devip, &devip->zstate[i], true); in zbc_open_all()
4634 u8 *cmd = scp->cmnd; in resp_open_zone()
4648 if (devip->max_open && in resp_open_zone()
4649 devip->nr_exp_open + devip->nr_closed > devip->max_open) { in resp_open_zone()
4669 if (z_id != zsp->z_start) { in resp_open_zone()
4680 zc = zsp->z_cond; in resp_open_zone()
4684 if (devip->max_open && devip->nr_exp_open >= devip->max_open) { in resp_open_zone()
4701 for (i = 0; i < devip->nr_zones; i++) in zbc_close_all()
4702 zbc_close_zone(devip, &devip->zstate[i]); in zbc_close_all()
4710 u8 *cmd = scp->cmnd; in resp_close_zone()
4736 if (z_id != zsp->z_start) { in resp_close_zone()
4756 enum sdebug_z_cond zc = zsp->z_cond; in zbc_finish_zone()
4762 if (zsp->z_cond == ZC4_CLOSED) in zbc_finish_zone()
4763 devip->nr_closed--; in zbc_finish_zone()
4764 zsp->z_wp = zsp->z_start + zsp->z_size; in zbc_finish_zone()
4765 zsp->z_cond = ZC5_FULL; in zbc_finish_zone()
4773 for (i = 0; i < devip->nr_zones; i++) in zbc_finish_all()
4774 zbc_finish_zone(devip, &devip->zstate[i], false); in zbc_finish_all()
4783 u8 *cmd = scp->cmnd; in resp_finish_zone()
4808 if (z_id != zsp->z_start) { in resp_finish_zone()
4834 zc = zsp->z_cond; in zbc_rwp_zone()
4838 if (zsp->z_cond == ZC4_CLOSED) in zbc_rwp_zone()
4839 devip->nr_closed--; in zbc_rwp_zone()
4841 if (zsp->z_wp > zsp->z_start) in zbc_rwp_zone()
4842 memset(sip->storep + zsp->z_start * sdebug_sector_size, 0, in zbc_rwp_zone()
4843 (zsp->z_wp - zsp->z_start) * sdebug_sector_size); in zbc_rwp_zone()
4845 zsp->z_non_seq_resource = false; in zbc_rwp_zone()
4846 zsp->z_wp = zsp->z_start; in zbc_rwp_zone()
4847 zsp->z_cond = ZC1_EMPTY; in zbc_rwp_zone()
4854 for (i = 0; i < devip->nr_zones; i++) in zbc_rwp_all()
4855 zbc_rwp_zone(devip, &devip->zstate[i]); in zbc_rwp_all()
4863 u8 *cmd = scp->cmnd; in resp_rwp_zone()
4887 if (z_id != zsp->z_start) { in resp_rwp_zone()
4926 bool aborted = sd_dp->aborted; in sdebug_q_cmd_complete()
4936 sd_dp->aborted = false; in sdebug_q_cmd_complete()
4937 qc_idx = sd_dp->qc_idx; in sdebug_q_cmd_complete()
4938 sqp = sdebug_q_arr + sd_dp->sqa_idx; in sdebug_q_cmd_complete()
4941 if (raw_smp_processor_id() != sd_dp->issuing_cpu) in sdebug_q_cmd_complete()
4948 spin_lock_irqsave(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4949 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); in sdebug_q_cmd_complete()
4950 sqcp = &sqp->qc_arr[qc_idx]; in sdebug_q_cmd_complete()
4951 scp = sqcp->a_cmnd; in sdebug_q_cmd_complete()
4953 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4955 sd_dp->sqa_idx, qc_idx, sd_dp->hc_idx); in sdebug_q_cmd_complete()
4958 devip = (struct sdebug_dev_info *)scp->device->hostdata; in sdebug_q_cmd_complete()
4960 atomic_dec(&devip->num_in_q); in sdebug_q_cmd_complete()
4966 sqcp->a_cmnd = NULL; in sdebug_q_cmd_complete()
4967 if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { in sdebug_q_cmd_complete()
4968 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4978 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4982 k = find_last_bit(sqp->in_use_bm, retval); in sdebug_q_cmd_complete()
4988 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
5032 devip->zsize = (DEF_ZBC_ZONE_SIZE_MB * SZ_1M) in sdebug_device_create_zones()
5034 while (capacity < devip->zsize << 2 && devip->zsize >= 2) in sdebug_device_create_zones()
5035 devip->zsize >>= 1; in sdebug_device_create_zones()
5036 if (devip->zsize < 2) { in sdebug_device_create_zones()
5038 return -EINVAL; in sdebug_device_create_zones()
5043 return -EINVAL; in sdebug_device_create_zones()
5045 devip->zsize = (sdeb_zbc_zone_size_mb * SZ_1M) in sdebug_device_create_zones()
5047 if (devip->zsize >= capacity) { in sdebug_device_create_zones()
5049 return -EINVAL; in sdebug_device_create_zones()
5053 devip->zsize_shift = ilog2(devip->zsize); in sdebug_device_create_zones()
5054 devip->nr_zones = (capacity + devip->zsize - 1) >> devip->zsize_shift; in sdebug_device_create_zones()
5057 devip->zcap = devip->zsize; in sdebug_device_create_zones()
5059 devip->zcap = (sdeb_zbc_zone_cap_mb * SZ_1M) >> in sdebug_device_create_zones()
5061 if (devip->zcap > devip->zsize) { in sdebug_device_create_zones()
5063 return -EINVAL; in sdebug_device_create_zones()
5067 conv_capacity = (sector_t)sdeb_zbc_nr_conv << devip->zsize_shift; in sdebug_device_create_zones()
5070 return -EINVAL; in sdebug_device_create_zones()
5072 devip->nr_conv_zones = sdeb_zbc_nr_conv; in sdebug_device_create_zones()
5073 devip->nr_seq_zones = ALIGN(capacity - conv_capacity, devip->zsize) >> in sdebug_device_create_zones()
5074 devip->zsize_shift; in sdebug_device_create_zones()
5075 devip->nr_zones = devip->nr_conv_zones + devip->nr_seq_zones; in sdebug_device_create_zones()
5078 if (devip->zcap < devip->zsize) in sdebug_device_create_zones()
5079 devip->nr_zones += devip->nr_seq_zones; in sdebug_device_create_zones()
5081 if (devip->zmodel == BLK_ZONED_HM) { in sdebug_device_create_zones()
5083 if (sdeb_zbc_max_open >= devip->nr_zones - 1) in sdebug_device_create_zones()
5084 devip->max_open = (devip->nr_zones - 1) / 2; in sdebug_device_create_zones()
5086 devip->max_open = sdeb_zbc_max_open; in sdebug_device_create_zones()
5089 devip->zstate = kcalloc(devip->nr_zones, in sdebug_device_create_zones()
5091 if (!devip->zstate) in sdebug_device_create_zones()
5092 return -ENOMEM; in sdebug_device_create_zones()
5094 for (i = 0; i < devip->nr_zones; i++) { in sdebug_device_create_zones()
5095 zsp = &devip->zstate[i]; in sdebug_device_create_zones()
5097 zsp->z_start = zstart; in sdebug_device_create_zones()
5099 if (i < devip->nr_conv_zones) { in sdebug_device_create_zones()
5100 zsp->z_type = ZBC_ZTYPE_CNV; in sdebug_device_create_zones()
5101 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
5102 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
5103 zsp->z_size = in sdebug_device_create_zones()
5104 min_t(u64, devip->zsize, capacity - zstart); in sdebug_device_create_zones()
5105 } else if ((zstart & (devip->zsize - 1)) == 0) { in sdebug_device_create_zones()
5106 if (devip->zmodel == BLK_ZONED_HM) in sdebug_device_create_zones()
5107 zsp->z_type = ZBC_ZTYPE_SWR; in sdebug_device_create_zones()
5109 zsp->z_type = ZBC_ZTYPE_SWP; in sdebug_device_create_zones()
5110 zsp->z_cond = ZC1_EMPTY; in sdebug_device_create_zones()
5111 zsp->z_wp = zsp->z_start; in sdebug_device_create_zones()
5112 zsp->z_size = in sdebug_device_create_zones()
5113 min_t(u64, devip->zcap, capacity - zstart); in sdebug_device_create_zones()
5115 zsp->z_type = ZBC_ZTYPE_GAP; in sdebug_device_create_zones()
5116 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
5117 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
5118 zsp->z_size = min_t(u64, devip->zsize - devip->zcap, in sdebug_device_create_zones()
5119 capacity - zstart); in sdebug_device_create_zones()
5122 WARN_ON_ONCE((int)zsp->z_size <= 0); in sdebug_device_create_zones()
5123 zstart += zsp->z_size; in sdebug_device_create_zones()
5137 uuid_gen(&devip->lu_name); in sdebug_device_create()
5140 devip->lu_name = shared_uuid; in sdebug_device_create()
5144 devip->lu_name = shared_uuid; in sdebug_device_create()
5147 devip->sdbg_host = sdbg_host; in sdebug_device_create()
5149 devip->zmodel = sdeb_zbc_model; in sdebug_device_create()
5155 devip->zmodel = BLK_ZONED_NONE; in sdebug_device_create()
5157 devip->sdbg_host = sdbg_host; in sdebug_device_create()
5158 devip->create_ts = ktime_get_boottime(); in sdebug_device_create()
5159 atomic_set(&devip->stopped, (sdeb_tur_ms_to_ready > 0 ? 2 : 0)); in sdebug_device_create()
5160 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list); in sdebug_device_create()
5171 sdbg_host = *(struct sdebug_host_info **)shost_priv(sdev->host); in find_build_dev_info()
5177 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in find_build_dev_info()
5178 if ((devip->used) && (devip->channel == sdev->channel) && in find_build_dev_info()
5179 (devip->target == sdev->id) && in find_build_dev_info()
5180 (devip->lun == sdev->lun)) in find_build_dev_info()
5183 if ((!devip->used) && (!open_devip)) in find_build_dev_info()
5195 open_devip->channel = sdev->channel; in find_build_dev_info()
5196 open_devip->target = sdev->id; in find_build_dev_info()
5197 open_devip->lun = sdev->lun; in find_build_dev_info()
5198 open_devip->sdbg_host = sdbg_host; in find_build_dev_info()
5199 atomic_set(&open_devip->num_in_q, 0); in find_build_dev_info()
5200 set_bit(SDEBUG_UA_POOCCUR, open_devip->uas_bm); in find_build_dev_info()
5201 open_devip->used = true; in find_build_dev_info()
5209 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_alloc()
5216 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_slave_configure()
5220 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_configure()
5221 if (sdp->host->max_cmd_len != SDEBUG_MAX_CMD_LEN) in scsi_debug_slave_configure()
5222 sdp->host->max_cmd_len = SDEBUG_MAX_CMD_LEN; in scsi_debug_slave_configure()
5228 sdp->hostdata = devip; in scsi_debug_slave_configure()
5230 sdp->no_uld_attach = 1; in scsi_debug_slave_configure()
5238 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_slave_destroy()
5242 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_destroy()
5244 /* make this slot available for re-use */ in scsi_debug_slave_destroy()
5245 devip->used = false; in scsi_debug_slave_destroy()
5246 sdp->hostdata = NULL; in scsi_debug_slave_destroy()
5256 hrtimer_cancel(&sd_dp->hrt); in stop_qc_helper()
5258 cancel_work_sync(&sd_dp->ew.work); in stop_qc_helper()
5274 spin_lock_irqsave(&sqp->qc_lock, iflags); in stop_queued_cmnd()
5280 if (test_bit(k, sqp->in_use_bm)) { in stop_queued_cmnd()
5281 sqcp = &sqp->qc_arr[k]; in stop_queued_cmnd()
5282 if (cmnd != sqcp->a_cmnd) in stop_queued_cmnd()
5286 cmnd->device->hostdata; in stop_queued_cmnd()
5288 atomic_dec(&devip->num_in_q); in stop_queued_cmnd()
5289 sqcp->a_cmnd = NULL; in stop_queued_cmnd()
5290 sd_dp = sqcp->sd_dp; in stop_queued_cmnd()
5292 l_defer_t = READ_ONCE(sd_dp->defer_t); in stop_queued_cmnd()
5293 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); in stop_queued_cmnd()
5296 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_queued_cmnd()
5298 clear_bit(k, sqp->in_use_bm); in stop_queued_cmnd()
5302 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_queued_cmnd()
5319 spin_lock_irqsave(&sqp->qc_lock, iflags); in stop_all_queued()
5321 if (test_bit(k, sqp->in_use_bm)) { in stop_all_queued()
5322 sqcp = &sqp->qc_arr[k]; in stop_all_queued()
5323 if (sqcp->a_cmnd == NULL) in stop_all_queued()
5326 sqcp->a_cmnd->device->hostdata; in stop_all_queued()
5328 atomic_dec(&devip->num_in_q); in stop_all_queued()
5329 sqcp->a_cmnd = NULL; in stop_all_queued()
5330 sd_dp = sqcp->sd_dp; in stop_all_queued()
5332 l_defer_t = READ_ONCE(sd_dp->defer_t); in stop_all_queued()
5333 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); in stop_all_queued()
5336 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_all_queued()
5338 clear_bit(k, sqp->in_use_bm); in stop_all_queued()
5339 spin_lock_irqsave(&sqp->qc_lock, iflags); in stop_all_queued()
5342 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_all_queued()
5355 sqcp = &sqp->qc_arr[k]; in free_all_queued()
5356 kfree(sqcp->sd_dp); in free_all_queued()
5357 sqcp->sd_dp = NULL; in free_all_queued()
5369 if (SCpnt->device && (SDEBUG_OPT_ALL_NOISE & sdebug_opts)) in scsi_debug_abort()
5370 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_abort()
5380 if (SCpnt && SCpnt->device) { in scsi_debug_device_reset()
5381 struct scsi_device *sdp = SCpnt->device; in scsi_debug_device_reset()
5383 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_device_reset()
5388 set_bit(SDEBUG_UA_POR, devip->uas_bm); in scsi_debug_device_reset()
5404 sdp = SCpnt->device; in scsi_debug_target_reset()
5409 hp = sdp->host; in scsi_debug_target_reset()
5415 &sdbg_host->dev_info_list, in scsi_debug_target_reset()
5417 if (devip->target == sdp->id) { in scsi_debug_target_reset()
5418 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_target_reset()
5438 if (!(SCpnt && SCpnt->device)) in scsi_debug_bus_reset()
5440 sdp = SCpnt->device; in scsi_debug_bus_reset()
5443 hp = sdp->host; in scsi_debug_bus_reset()
5448 &sdbg_host->dev_info_list, in scsi_debug_bus_reset()
5450 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_bus_reset()
5469 if ((SCpnt->device) && (SDEBUG_OPT_ALL_NOISE & sdebug_opts)) in scsi_debug_host_reset()
5470 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); in scsi_debug_host_reset()
5473 list_for_each_entry(devip, &sdbg_host->dev_info_list, in scsi_debug_host_reset()
5475 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_host_reset()
5482 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_host_reset()
5502 sectors_per_part = (num_sectors - sdebug_sectors_per) in sdebug_build_parts()
5510 if (starts[k] - starts[k - 1] < max_part_secs) in sdebug_build_parts()
5511 max_part_secs = starts[k] - starts[k - 1]; in sdebug_build_parts()
5521 end_sec = starts[k] + max_part_secs - 1; in sdebug_build_parts()
5522 pp->boot_ind = 0; in sdebug_build_parts()
5524 pp->cyl = start_sec / heads_by_sects; in sdebug_build_parts()
5525 pp->head = (start_sec - (pp->cyl * heads_by_sects)) in sdebug_build_parts()
5527 pp->sector = (start_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
5529 pp->end_cyl = end_sec / heads_by_sects; in sdebug_build_parts()
5530 pp->end_head = (end_sec - (pp->end_cyl * heads_by_sects)) in sdebug_build_parts()
5532 pp->end_sector = (end_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
5534 pp->start_sect = cpu_to_le32(start_sec); in sdebug_build_parts()
5535 pp->nr_sects = cpu_to_le32(end_sec - start_sec + 1); in sdebug_build_parts()
5536 pp->sys_ind = 0x83; /* plain Linux partition */ in sdebug_build_parts()
5546 atomic_set(&sqp->blocked, (int)block); in block_unblock_all_queues()
5549 /* Adjust (by rounding down) the sdebug_cmnd_count so abs(every_nth)-1
5595 bool polled = scsi_cmd_to_rq(cmnd)->cmd_flags & REQ_POLLED; in schedule_resp()
5609 sdp = cmnd->device; in schedule_resp()
5615 spin_lock_irqsave(&sqp->qc_lock, iflags); in schedule_resp()
5616 if (unlikely(atomic_read(&sqp->blocked))) { in schedule_resp()
5617 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5620 num_in_q = atomic_read(&devip->num_in_q); in schedule_resp()
5621 qdepth = cmnd->device->queue_depth; in schedule_resp()
5624 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5631 if ((num_in_q == (qdepth - 1)) && in schedule_resp()
5640 k = find_first_zero_bit(sqp->in_use_bm, sdebug_max_queue); in schedule_resp()
5642 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5651 set_bit(k, sqp->in_use_bm); in schedule_resp()
5652 atomic_inc(&devip->num_in_q); in schedule_resp()
5653 sqcp = &sqp->qc_arr[k]; in schedule_resp()
5654 sqcp->a_cmnd = cmnd; in schedule_resp()
5655 cmnd->host_scribble = (unsigned char *)sqcp; in schedule_resp()
5656 sd_dp = sqcp->sd_dp; in schedule_resp()
5657 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5662 atomic_dec(&devip->num_in_q); in schedule_resp()
5663 clear_bit(k, sqp->in_use_bm); in schedule_resp()
5673 sd_dp->hc_idx = get_tag(cmnd); in schedule_resp()
5679 cmnd->result = pfp ? pfp(cmnd, devip) : 0; in schedule_resp()
5680 if (cmnd->result & SDEG_RES_IMMED_MASK) { in schedule_resp()
5681 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
5684 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
5685 cmnd->result = scsi_result; in schedule_resp()
5686 if (cmnd->result == 0 && unlikely(sdebug_opts & SDEBUG_OPT_TRANSPORT_ERR)) { in schedule_resp()
5690 cmnd->result = check_condition_result; in schedule_resp()
5694 if (unlikely(sdebug_verbose && cmnd->result)) in schedule_resp()
5695 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", in schedule_resp()
5696 __func__, cmnd->result); in schedule_resp()
5717 u64 d = ktime_get_boottime_ns() - ns_from_boot; in schedule_resp()
5720 spin_lock_irqsave(&sqp->qc_lock, iflags); in schedule_resp()
5721 sqcp->a_cmnd = NULL; in schedule_resp()
5722 atomic_dec(&devip->num_in_q); in schedule_resp()
5723 clear_bit(k, sqp->in_use_bm); in schedule_resp()
5724 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5732 kt -= d; in schedule_resp()
5736 sd_dp->cmpl_ts = ktime_add(ns_to_ktime(ns_from_boot), kt); in schedule_resp()
5737 spin_lock_irqsave(&sqp->qc_lock, iflags); in schedule_resp()
5738 if (!sd_dp->init_poll) { in schedule_resp()
5739 sd_dp->init_poll = true; in schedule_resp()
5740 sqcp->sd_dp = sd_dp; in schedule_resp()
5741 sd_dp->sqa_idx = sqp - sdebug_q_arr; in schedule_resp()
5742 sd_dp->qc_idx = k; in schedule_resp()
5744 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); in schedule_resp()
5745 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5747 if (!sd_dp->init_hrt) { in schedule_resp()
5748 sd_dp->init_hrt = true; in schedule_resp()
5749 sqcp->sd_dp = sd_dp; in schedule_resp()
5750 hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, in schedule_resp()
5752 sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; in schedule_resp()
5753 sd_dp->sqa_idx = sqp - sdebug_q_arr; in schedule_resp()
5754 sd_dp->qc_idx = k; in schedule_resp()
5756 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); in schedule_resp()
5758 hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); in schedule_resp()
5761 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
5765 sd_dp->aborted = true; in schedule_resp()
5767 sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot); in schedule_resp()
5768 spin_lock_irqsave(&sqp->qc_lock, iflags); in schedule_resp()
5769 if (!sd_dp->init_poll) { in schedule_resp()
5770 sd_dp->init_poll = true; in schedule_resp()
5771 sqcp->sd_dp = sd_dp; in schedule_resp()
5772 sd_dp->sqa_idx = sqp - sdebug_q_arr; in schedule_resp()
5773 sd_dp->qc_idx = k; in schedule_resp()
5775 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); in schedule_resp()
5776 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5778 if (!sd_dp->init_wq) { in schedule_resp()
5779 sd_dp->init_wq = true; in schedule_resp()
5780 sqcp->sd_dp = sd_dp; in schedule_resp()
5781 sd_dp->sqa_idx = sqp - sdebug_q_arr; in schedule_resp()
5782 sd_dp->qc_idx = k; in schedule_resp()
5783 INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); in schedule_resp()
5785 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_WQ); in schedule_resp()
5786 schedule_work(&sd_dp->ew.work); in schedule_resp()
5789 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
5790 if (unlikely(sd_dp->aborted)) { in schedule_resp()
5792 scsi_cmd_to_rq(cmnd)->tag); in schedule_resp()
5795 sd_dp->aborted = false; in schedule_resp()
5803 respond_in_thread: /* call back to mid-layer using invocation thread */ in schedule_resp()
5804 cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; in schedule_resp()
5805 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
5806 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
5807 cmnd->result = scsi_result; in schedule_resp()
5898 MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny");
5900 MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
5902 MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
5919 MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
5924 MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)");
5925 MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
5932 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
5935 MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1))");
5939 MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=7[SPC-5])");
5943 MODULE_PARM_DESC(submit_queues, "support for block multi-queue (def=1)");
5950 "1->use uuid for lu name, 0->don't, 2->all use same (def=0)");
5951 MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
5952 MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
5955 MODULE_PARM_DESC(zbc, "'none' [0]; 'aware' [1]; 'managed' [2] (def=0). Can have 'host-' prefix");
5970 if (k >= (SDEBUG_INFO_LEN - 1)) in scsi_debug_info()
5972 scnprintf(sdebug_info + k, SDEBUG_INFO_LEN - k, in scsi_debug_info()
5988 return -EACCES; in scsi_debug_write_info()
5992 return -EINVAL; in scsi_debug_write_info()
6038 f = find_first_bit(sqp->in_use_bm, sdebug_max_queue); in scsi_debug_show_info()
6040 l = find_last_bit(sqp->in_use_bm, sdebug_max_queue); in scsi_debug_show_info()
6046 seq_printf(m, "this host_no=%d\n", host->host_no); in scsi_debug_show_info()
6056 idx = sdhp->si_idx; in scsi_debug_show_info()
6058 sdhp->shost->host_no, idx); in scsi_debug_show_info()
6080 /* Returns -EBUSY if jdelay is being changed and commands are queued. The unit
6097 k = find_first_bit(sqp->in_use_bm, in delay_store()
6100 res = -EBUSY; /* queued commands */ in delay_store()
6112 return -EINVAL; in delay_store()
6120 /* Returns -EBUSY if ndelay is being changed and commands are queued */
6137 k = find_first_bit(sqp->in_use_bm, in ndelay_store()
6140 res = -EBUSY; /* queued commands */ in ndelay_store()
6153 return -EINVAL; in ndelay_store()
6177 return -EINVAL; in opts_store()
6198 return -EINVAL; in ptype_store()
6202 return -EINVAL; in ptype_store()
6206 return -EINVAL; in ptype_store()
6223 return -EINVAL; in dsense_store()
6245 if (want_store) { /* 1 --> 0 transition, set up store */ in fake_rw_store()
6258 if (sdhp->si_idx != idx) { in fake_rw_store()
6259 xa_set_mark(per_store_ap, sdhp->si_idx, in fake_rw_store()
6261 sdhp->si_idx = idx; in fake_rw_store()
6265 } else { /* 0 --> 1 transition is trigger for shrink */ in fake_rw_store()
6271 return -EINVAL; in fake_rw_store()
6288 return -EINVAL; in no_lun_0_store()
6306 return -EINVAL; in num_tgts_store()
6327 return -EINVAL; in per_host_store_store()
6359 return -EINVAL; in every_nth_store()
6383 return -EINVAL; in lun_format_store()
6387 return -EINVAL; in lun_format_store()
6391 if (changed && sdebug_scsi_level >= 5) { /* >= SPC-3 */ in lun_format_store()
6397 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in lun_format_store()
6398 set_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in lun_format_store()
6405 return -EINVAL; in lun_format_store()
6422 return -EINVAL; in max_luns_store()
6427 if (changed && (sdebug_scsi_level >= 5)) { /* >= SPC-3 */ in max_luns_store()
6434 list_for_each_entry(dp, &sdhp->dev_info_list, in max_luns_store()
6437 dp->uas_bm); in max_luns_store()
6444 return -EINVAL; in max_luns_store()
6467 a = find_last_bit(sqp->in_use_bm, SDEBUG_CANQUEUE); in max_queue_store()
6481 return -EINVAL; in max_queue_store()
6500 return -EINVAL; in no_rwlock_store()
6537 return -ENOTSUPP; in virtual_gb_store()
6550 list_for_each_entry(dp, &sdhp->dev_info_list, in virtual_gb_store()
6553 dp->uas_bm); in virtual_gb_store()
6560 return -EINVAL; in virtual_gb_store()
6580 return -EINVAL; in add_host_store()
6591 if (found) /* re-use case */ in add_host_store()
6598 } while (--delta_hosts); in add_host_store()
6621 return -EINVAL; in vpd_use_hostno_store()
6643 return -EINVAL; in statistics_store()
6688 return scnprintf(buf, PAGE_SIZE, "0-%u\n", in map_show()
6695 count = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", in map_show()
6696 (int)map_size, sip->map_storep); in map_show()
6716 return -EINVAL; in random_store()
6736 return -EINVAL; in removable_store()
6754 return -EINVAL; in host_lock_store()
6771 return -EINVAL; in strict_store()
6801 [BLK_ZONED_HA] = "host-aware",
6802 [BLK_ZONED_HM] = "host-managed",
6826 return -EINVAL; in sdeb_zbc_model_str()
6902 int idx = -1; in scsi_debug_init()
6922 return -EINVAL; in scsi_debug_init()
6936 return -EINVAL; in scsi_debug_init()
6941 return -EINVAL; in scsi_debug_init()
6946 return -EINVAL; in scsi_debug_init()
6951 return -EINVAL; in scsi_debug_init()
6956 return -EINVAL; in scsi_debug_init()
6975 return -EINVAL; in scsi_debug_init()
6980 return -EINVAL; in scsi_debug_init()
6985 return -EINVAL; in scsi_debug_init()
6992 return -EINVAL; in scsi_debug_init()
7005 return -ENOMEM; in scsi_debug_init()
7032 ret = -EINVAL; in scsi_debug_init()
7080 ret = -EINVAL; in scsi_debug_init()
7118 k, -ret); in scsi_debug_init()
7125 pr_err("add_host k=%d error=%d\n", k, -ret); in scsi_debug_init()
7151 for (; k; k--) in scsi_debug_exit()
7186 vfree(sip->map_storep); in sdebug_erase_store()
7187 vfree(sip->dif_storep); in sdebug_erase_store()
7188 vfree(sip->storep); in sdebug_erase_store()
7224 return -ENOMEM; in sdebug_add_store()
7231 pr_warn("%s: xa_alloc() errno=%d\n", __func__, -res); in sdebug_add_store()
7239 res = -ENOMEM; in sdebug_add_store()
7240 sip->storep = vzalloc(sz); in sdebug_add_store()
7241 if (!sip->storep) { in sdebug_add_store()
7246 sdebug_build_parts(sip->storep, sz); in sdebug_add_store()
7253 sip->dif_storep = vmalloc(dif_size); in sdebug_add_store()
7256 sip->dif_storep); in sdebug_add_store()
7258 if (!sip->dif_storep) { in sdebug_add_store()
7262 memset(sip->dif_storep, 0xff, dif_size); in sdebug_add_store()
7266 map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1; in sdebug_add_store()
7267 sip->map_storep = vmalloc(array_size(sizeof(long), in sdebug_add_store()
7272 if (!sip->map_storep) { in sdebug_add_store()
7277 bitmap_zero(sip->map_storep, map_size); in sdebug_add_store()
7284 rwlock_init(&sip->macc_lck); in sdebug_add_store()
7288 pr_warn("%s: failed, errno=%d\n", __func__, -res); in sdebug_add_store()
7295 int error = -ENOMEM; in sdebug_add_host_helper()
7301 return -ENOMEM; in sdebug_add_host_helper()
7305 sdbg_host->si_idx = idx; in sdebug_add_host_helper()
7307 INIT_LIST_HEAD(&sdbg_host->dev_info_list); in sdebug_add_host_helper()
7317 list_add_tail(&sdbg_host->host_list, &sdebug_host_list); in sdebug_add_host_helper()
7320 sdbg_host->dev.bus = &pseudo_lld_bus; in sdebug_add_host_helper()
7321 sdbg_host->dev.parent = pseudo_primary; in sdebug_add_host_helper()
7322 sdbg_host->dev.release = &sdebug_release_adapter; in sdebug_add_host_helper()
7323 dev_set_name(&sdbg_host->dev, "adapter%d", sdebug_num_hosts); in sdebug_add_host_helper()
7325 error = device_register(&sdbg_host->dev); in sdebug_add_host_helper()
7328 list_del(&sdbg_host->host_list); in sdebug_add_host_helper()
7337 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_add_host_helper()
7339 list_del(&sdbg_devinfo->dev_list); in sdebug_add_host_helper()
7340 kfree(sdbg_devinfo->zstate); in sdebug_add_host_helper()
7344 pr_warn("%s: failed, errno=%d\n", __func__, -error); in sdebug_add_host_helper()
7362 int idx = -1; in sdebug_do_remove_host()
7370 idx = sdbg_host->si_idx; in sdebug_do_remove_host()
7378 if (idx == sdbg_host2->si_idx) { in sdebug_do_remove_host()
7386 --sdeb_most_recent_idx; in sdebug_do_remove_host()
7390 list_del(&sdbg_host->host_list); in sdebug_do_remove_host()
7396 device_unregister(&sdbg_host->dev); in sdebug_do_remove_host()
7397 --sdebug_num_hosts; in sdebug_do_remove_host()
7406 devip = (struct sdebug_dev_info *)sdev->hostdata; in sdebug_change_qdepth()
7409 return -ENODEV; in sdebug_change_qdepth()
7411 num_in_q = atomic_read(&devip->num_in_q); in sdebug_change_qdepth()
7420 if (qdepth != sdev->queue_depth) in sdebug_change_qdepth()
7428 return sdev->queue_depth; in sdebug_change_qdepth()
7434 if (sdebug_every_nth < -1) in fake_timeout()
7435 sdebug_every_nth = -1; in fake_timeout()
7451 struct scsi_device *sdp = scp->device; in resp_not_ready()
7453 stopped_state = atomic_read(&devip->stopped); in resp_not_ready()
7455 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_not_ready()
7456 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_not_ready()
7459 atomic_set(&devip->stopped, 0); in resp_not_ready()
7467 if (scp->cmnd[0] == TEST_UNIT_READY) { in resp_not_ready()
7471 diff_ns = tur_nanosecs_to_ready - diff_ns; in resp_not_ready()
7474 /* As per 20-061r2 approved for spc6 by T10 on 20200716 */ in resp_not_ready()
7476 scsi_set_sense_information(scp->sense_buffer, SCSI_SENSE_BUFFERSIZE, in resp_not_ready()
7492 if (shost->nr_hw_queues == 1) in sdebug_map_queues()
7496 struct blk_mq_queue_map *map = &shost->tag_set.map[i]; in sdebug_map_queues()
7498 map->nr_queues = 0; in sdebug_map_queues()
7501 map->nr_queues = submit_queues - poll_queues; in sdebug_map_queues()
7503 map->nr_queues = poll_queues; in sdebug_map_queues()
7505 if (!map->nr_queues) { in sdebug_map_queues()
7510 map->queue_offset = qoff; in sdebug_map_queues()
7513 qoff += map->nr_queues; in sdebug_map_queues()
7533 spin_lock_irqsave(&sqp->qc_lock, iflags); in sdebug_blk_mq_poll()
7535 qc_idx = find_first_bit(sqp->in_use_bm, sdebug_max_queue); in sdebug_blk_mq_poll()
7542 if (!test_bit(qc_idx, sqp->in_use_bm)) in sdebug_blk_mq_poll()
7545 qc_idx = find_next_bit(sqp->in_use_bm, sdebug_max_queue, qc_idx + 1); in sdebug_blk_mq_poll()
7550 sqcp = &sqp->qc_arr[qc_idx]; in sdebug_blk_mq_poll()
7551 sd_dp = sqcp->sd_dp; in sdebug_blk_mq_poll()
7554 scp = sqcp->a_cmnd; in sdebug_blk_mq_poll()
7560 if (READ_ONCE(sd_dp->defer_t) == SDEB_DEFER_POLL) { in sdebug_blk_mq_poll()
7561 if (kt_from_boot < sd_dp->cmpl_ts) in sdebug_blk_mq_poll()
7566 devip = (struct sdebug_dev_info *)scp->device->hostdata; in sdebug_blk_mq_poll()
7568 atomic_dec(&devip->num_in_q); in sdebug_blk_mq_poll()
7574 sqcp->a_cmnd = NULL; in sdebug_blk_mq_poll()
7575 if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { in sdebug_blk_mq_poll()
7588 k = find_last_bit(sqp->in_use_bm, retval); in sdebug_blk_mq_poll()
7594 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); in sdebug_blk_mq_poll()
7595 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_blk_mq_poll()
7598 spin_lock_irqsave(&sqp->qc_lock, iflags); in sdebug_blk_mq_poll()
7599 if (find_first_bit(sqp->in_use_bm, sdebug_max_queue) >= sdebug_max_queue) in sdebug_blk_mq_poll()
7604 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_blk_mq_poll()
7615 struct scsi_device *sdp = scp->device; in scsi_debug_queuecommand()
7619 u8 *cmd = scp->cmnd; in scsi_debug_queuecommand()
7624 u64 lun_index = sdp->lun & 0x3FFF; in scsi_debug_queuecommand()
7643 len = scp->cmd_len; in scsi_debug_queuecommand()
7649 n += scnprintf(b + n, sb - n, "%02x ", in scsi_debug_queuecommand()
7657 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS); in scsi_debug_queuecommand()
7663 devip = (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_queuecommand()
7672 na = oip->num_attached; in scsi_debug_queuecommand()
7673 r_pfp = oip->pfp; in scsi_debug_queuecommand()
7676 if (FF_SA & r_oip->flags) { in scsi_debug_queuecommand()
7677 if (F_SA_LOW & oip->flags) in scsi_debug_queuecommand()
7681 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
7682 if (opcode == oip->opcode && sa == oip->sa) in scsi_debug_queuecommand()
7686 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
7687 if (opcode == oip->opcode) in scsi_debug_queuecommand()
7692 if (F_SA_LOW & r_oip->flags) in scsi_debug_queuecommand()
7694 else if (F_SA_HIGH & r_oip->flags) in scsi_debug_queuecommand()
7701 flags = oip->flags; in scsi_debug_queuecommand()
7717 for (k = 1; k < oip->len_mask[0] && k < 16; ++k) { in scsi_debug_queuecommand()
7718 rem = ~oip->len_mask[k] & cmd[k]; in scsi_debug_queuecommand()
7720 for (j = 7; j >= 0; --j, rem <<= 1) { in scsi_debug_queuecommand()
7730 find_first_bit(devip->uas_bm, in scsi_debug_queuecommand()
7736 if (unlikely(((F_M_ACCESS & flags) || scp->cmnd[0] == TEST_UNIT_READY) && in scsi_debug_queuecommand()
7737 atomic_read(&devip->stopped))) { in scsi_debug_queuecommand()
7748 if (likely(oip->pfp)) in scsi_debug_queuecommand()
7749 pfp = oip->pfp; /* calls a resp_* function */ in scsi_debug_queuecommand()
7801 .max_sectors = -1U,
7802 .max_segment_size = -1U,
7819 sdebug_driver_template.dma_boundary = PAGE_SIZE - 1; in sdebug_driver_probe()
7824 error = -ENODEV; in sdebug_driver_probe()
7836 hpnt->nr_hw_queues = submit_queues; in sdebug_driver_probe()
7838 hpnt->host_tagset = 1; in sdebug_driver_probe()
7841 if (hpnt->nr_hw_queues == 1 || (poll_queues < 1)) { in sdebug_driver_probe()
7843 my_name, poll_queues, hpnt->nr_hw_queues); in sdebug_driver_probe()
7849 * left over for non-polled I/O. in sdebug_driver_probe()
7857 my_name, submit_queues - 1); in sdebug_driver_probe()
7861 hpnt->nr_maps = 3; in sdebug_driver_probe()
7863 sdbg_host->shost = hpnt; in sdebug_driver_probe()
7864 *((struct sdebug_host_info **)hpnt->hostdata) = sdbg_host; in sdebug_driver_probe()
7865 if ((hpnt->this_id >= 0) && (sdebug_num_tgts > hpnt->this_id)) in sdebug_driver_probe()
7866 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_driver_probe()
7868 hpnt->max_id = sdebug_num_tgts; in sdebug_driver_probe()
7870 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_driver_probe()
7921 error = scsi_add_host(hpnt, &sdbg_host->dev); in sdebug_driver_probe()
7924 error = -ENODEV; in sdebug_driver_probe()
7940 scsi_remove_host(sdbg_host->shost); in sdebug_driver_remove()
7942 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_driver_remove()
7944 list_del(&sdbg_devinfo->dev_list); in sdebug_driver_remove()
7945 kfree(sdbg_devinfo->zstate); in sdebug_driver_remove()
7949 scsi_host_put(sdbg_host->shost); in sdebug_driver_remove()