• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Copyright (C) 2001 - 2020 Douglas Gilbert
34 #include <linux/crc-t10dif.h>
40 #include <linux/t10-pi.h>
142 #define DEF_SCSI_LEVEL 7 /* INQUIRY, byte2 [6->SPC-4; 7->SPC-5] */
156 #define JDELAY_OVERRIDDEN -9999
194 /* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs) are returned in
215 * per-device DEF_CMD_PER_LUN can be changed via sysfs:
223 /* UA - Unit Attention; SA - Service Action; SSU - Start Stop Unit */
224 #define F_D_IN 1 /* Data-in command (e.g. READ) */
225 #define F_D_OUT 2 /* Data-out command (e.g. WRITE) */
228 #define F_RL_WLUN_OK 0x10 /* allowed with REPORT LUNS W-LUN */
236 #define F_SSU_DELAY 0x1000 /* SSU command delay (long-ish) */
366 u32 flags; /* OR-ed set of SDEB_F_* */
369 u8 len_mask[16]; /* len_mask[0]-->cdb_len, then mask for cdb */
406 SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */
412 /* 0x0; 0x0->0x1f: 6 byte cdbs */
420 /* 0x20; 0x20->0x3f: 10 byte cdbs */
425 /* 0x40; 0x40->0x5f: 10 byte cdbs */
431 /* 0x60; 0x60->0x7d are reserved, 0x7e is "extended cdb" */
435 /* 0x80; 0x80->0x9f: 16 byte cdbs */
442 /* 0xa0; 0xa0->0xbf: 12 byte cdbs */
449 /* 0xc0; 0xc0->0xff: vendor specific */
457 * The following "response" functions return the SCSI mid-level's 4 byte
458 * tuple-in-an-int. To handle commands with an IMMED bit, for a faster
503 * the opcode_info_arr array. The most time sensitive (or commonly used) cdb
594 0xff, 0xff, 0xff, 0xff, 0x3f, 0xc7} }, /* PRE-FETCH (16) */
714 0, 0, 0, 0} }, /* PRE-FETCH (10) */
811 static int sdeb_first_idx = -1; /* invalid index ==> none created */
812 static int sdeb_most_recent_idx = -1;
826 static bool sdeb_zbc_in_use; /* true for host-aware and host-managed disks */
831 static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */
877 if (!sip || !sip->storep) { in lba2fake_store()
881 return lsip->storep + lba * sdebug_sector_size; in lba2fake_store()
889 return sip->dif_storep + sector; in dif_store()
899 hpnt = sdbg_host->shost; in sdebug_max_tgts_luns()
900 if ((hpnt->this_id >= 0) && in sdebug_max_tgts_luns()
901 (sdebug_num_tgts > hpnt->this_id)) in sdebug_max_tgts_luns()
902 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_max_tgts_luns()
904 hpnt->max_id = sdebug_num_tgts; in sdebug_max_tgts_luns()
906 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_max_tgts_luns()
913 /* Set in_bit to -1 to indicate no bit position of invalid field */
922 sbuff = scp->sense_buffer; in mk_sense_invalid_fld()
924 sdev_printk(KERN_ERR, scp->device, in mk_sense_invalid_fld()
949 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq" in mk_sense_invalid_fld()
958 sbuff = scp->sense_buffer; in mk_sense_buffer()
960 sdev_printk(KERN_ERR, scp->device, in mk_sense_buffer()
969 sdev_printk(KERN_INFO, scp->device, in mk_sense_buffer()
994 return -EINVAL; in scsi_debug_ioctl()
995 /* return -ENOTTY; // correct return but upsets fdisk */ in scsi_debug_ioctl()
1002 sdev->use_10_for_rw = false; in config_cdb_len()
1003 sdev->use_16_for_rw = false; in config_cdb_len()
1004 sdev->use_10_for_ms = false; in config_cdb_len()
1007 sdev->use_10_for_rw = true; in config_cdb_len()
1008 sdev->use_16_for_rw = false; in config_cdb_len()
1009 sdev->use_10_for_ms = false; in config_cdb_len()
1012 sdev->use_10_for_rw = true; in config_cdb_len()
1013 sdev->use_16_for_rw = false; in config_cdb_len()
1014 sdev->use_10_for_ms = true; in config_cdb_len()
1017 sdev->use_10_for_rw = false; in config_cdb_len()
1018 sdev->use_16_for_rw = true; in config_cdb_len()
1019 sdev->use_10_for_ms = true; in config_cdb_len()
1022 sdev->use_10_for_rw = false; in config_cdb_len()
1023 sdev->use_16_for_rw = true; in config_cdb_len()
1024 sdev->use_10_for_ms = true; in config_cdb_len()
1029 sdev->use_10_for_rw = true; in config_cdb_len()
1030 sdev->use_16_for_rw = false; in config_cdb_len()
1031 sdev->use_10_for_ms = false; in config_cdb_len()
1045 shost = sdbg_host->shost; in all_config_cdb_len()
1060 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in clear_luns_changed_on_target()
1061 if ((devip->sdbg_host == dp->sdbg_host) && in clear_luns_changed_on_target()
1062 (devip->target == dp->target)) in clear_luns_changed_on_target()
1063 clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in clear_luns_changed_on_target()
1073 k = find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS); in make_ua()
1118 * SPC-3 behavior is to report a UNIT ATTENTION with in make_ua()
1121 * received. SPC-4 behavior is to report it only once. in make_ua()
1123 * values as struct scsi_device->scsi_level. in make_ua()
1125 if (sdebug_scsi_level >= 6) /* SPC-4 and above */ in make_ua()
1139 clear_bit(k, devip->uas_bm); in make_ua()
1141 sdev_printk(KERN_INFO, scp->device, in make_ua()
1149 /* Build SCSI "data-in" buffer. Returns 0 if ok else (DID_ERROR << 16). */
1154 struct scsi_data_buffer *sdb = &scp->sdb; in fill_from_dev_buffer()
1156 if (!sdb->length) in fill_from_dev_buffer()
1158 if (scp->sc_data_direction != DMA_FROM_DEVICE) in fill_from_dev_buffer()
1161 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, in fill_from_dev_buffer()
1163 scsi_set_resid(scp, scsi_bufflen(scp) - act_len); in fill_from_dev_buffer()
1168 /* Partial build of SCSI "data-in" buffer. Returns 0 if ok else
1169 * (DID_ERROR << 16). Can write to offset in data-in buffer. If multiple
1177 struct scsi_data_buffer *sdb = &scp->sdb; in p_fill_from_dev_buffer()
1180 if (sdb->length <= off_dst) in p_fill_from_dev_buffer()
1182 if (scp->sc_data_direction != DMA_FROM_DEVICE) in p_fill_from_dev_buffer()
1185 act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents, in p_fill_from_dev_buffer()
1190 n = scsi_bufflen(scp) - (off_dst + act_len); in p_fill_from_dev_buffer()
1195 /* Fetches from SCSI "data-out" buffer. Returns number of bytes fetched into
1196 * 'arr' or -1 if error.
1203 if (scp->sc_data_direction != DMA_TO_DEVICE) in fetch_to_dev_buffer()
1204 return -1; in fetch_to_dev_buffer()
1250 /* NAA-3, Logical unit identifier (binary) */ in inquiry_vpd_83()
1268 /* NAA-3, Target port identifier */ in inquiry_vpd_83()
1275 /* NAA-3, Target port group identifier */ in inquiry_vpd_83()
1284 /* NAA-3, Target device identifier */ in inquiry_vpd_83()
1292 arr[num++] = 0x63; /* proto=sas, UTF-8 */ in inquiry_vpd_83()
1336 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1348 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1369 arr[num++] = 12; /* length tp descriptor */ in inquiry_vpd_88()
1370 /* naa-5 target port identifier (A) */ in inquiry_vpd_88()
1384 arr[num++] = 12; /* length tp descriptor */ in inquiry_vpd_88()
1385 /* naa-5 target port identifier (B) */ in inquiry_vpd_88()
1456 /* Block limits VPD page (SBC-3) */
1503 /* Block device characteristics VPD page (SBC-3) */
1511 if (devip->zmodel == BLK_ZONED_HA) in inquiry_vpd_b1()
1517 /* Logical block provisioning VPD page (SBC-4) */
1543 * Optimal number of non-sequentially written sequential write in inquiry_vpd_b6()
1549 if (sdeb_zbc_model == BLK_ZONED_HM && devip->max_open) in inquiry_vpd_b6()
1550 put_unaligned_be32(devip->max_open, &arr[12]); in inquiry_vpd_b6()
1563 unsigned char *cmd = scp->cmnd; in resp_inquiry()
1573 is_zbc = (devip->zmodel != BLK_ZONED_NONE); in resp_inquiry()
1575 have_wlun = scsi_is_wlun(scp->device->lun); in resp_inquiry()
1578 else if (sdebug_no_lun_0 && (devip->lun == SDEBUG_LUN_0_VAL)) in resp_inquiry()
1591 int host_no = devip->sdbg_host->shost->host_no; in resp_inquiry()
1594 (devip->channel & 0x7f); in resp_inquiry()
1597 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) + in resp_inquiry()
1598 (devip->target * 1000) + devip->lun); in resp_inquiry()
1600 (devip->target * 1000) - 3; in resp_inquiry()
1622 arr[3] = n - 4; /* number of supported VPD pages */ in resp_inquiry()
1632 &devip->lu_name); in resp_inquiry()
1652 arr[4] = 0x2; /* disconnect-reconnect mp */ in resp_inquiry()
1676 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_inquiry()
1690 arr[4] = SDEBUG_LONG_INQ_SZ - 5; in resp_inquiry()
1703 put_unaligned_be16(0xc0, arr + 58); /* SAM-6 no version claimed */ in resp_inquiry()
1704 put_unaligned_be16(0x5c0, arr + 60); /* SPC-5 no version claimed */ in resp_inquiry()
1706 if (is_disk) { /* SBC-4 no version claimed */ in resp_inquiry()
1709 } else if (sdebug_ptype == TYPE_TAPE) { /* SSC-4 rev 3 */ in resp_inquiry()
1716 put_unaligned_be16(0x2100, arr + n); /* SPL-4 no version claimed */ in resp_inquiry()
1730 unsigned char *cmd = scp->cmnd; in resp_requests()
1735 int stopped_state = atomic_read(&devip->stopped); in resp_requests()
1783 unsigned char *cmd = scp->cmnd; in resp_start_stop()
1793 stopped_state = atomic_read(&devip->stopped); in resp_start_stop()
1797 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_start_stop()
1798 u64 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_start_stop()
1802 atomic_set(&devip->stopped, 0); in resp_start_stop()
1817 atomic_xchg(&devip->stopped, want_stop); in resp_start_stop()
1846 capac = (unsigned int)sdebug_capacity - 1; in resp_readcap()
1858 unsigned char *cmd = scp->cmnd; in resp_readcap16()
1866 put_unaligned_be64((u64)(sdebug_capacity - 1), arr + 0); in resp_readcap16()
1883 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices. in resp_readcap16()
1885 if (devip->zmodel == BLK_ZONED_HM) in resp_readcap16()
1891 arr[12] = (sdebug_dif - 1) << 1; /* P_TYPE */ in resp_readcap16()
1904 unsigned char *cmd = scp->cmnd; in resp_report_tgtpgs()
1906 int host_no = devip->sdbg_host->shost->host_no; in resp_report_tgtpgs()
1924 (devip->channel & 0x7f); in resp_report_tgtpgs()
1926 (devip->channel & 0x7f) + 0x80; in resp_report_tgtpgs()
1962 rlen = n - 4; in resp_report_tgtpgs()
1967 * - The allocated length in resp_report_tgtpgs()
1968 * - The constructed command length in resp_report_tgtpgs()
1969 * - The maximum array size in resp_report_tgtpgs()
1989 u8 *cmd = scp->cmnd; in resp_rsup_opcodes()
1997 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_opcodes()
2014 oip->num_attached != 0xff; ++oip) { in resp_rsup_opcodes()
2015 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2017 count += (oip->num_attached + 1); in resp_rsup_opcodes()
2022 oip->num_attached != 0xff && offset < a_len; ++oip) { in resp_rsup_opcodes()
2023 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2025 na = oip->num_attached; in resp_rsup_opcodes()
2026 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2027 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2030 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2032 put_unaligned_be16(oip->len_mask[0], arr + offset + 6); in resp_rsup_opcodes()
2036 for (k = 0, oip = oip->arrp; k < na; ++k, ++oip) { in resp_rsup_opcodes()
2037 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2040 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2041 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2044 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2046 put_unaligned_be16(oip->len_mask[0], in resp_rsup_opcodes()
2061 if (F_INV_OP & oip->flags) { in resp_rsup_opcodes()
2066 if (FF_SA & oip->flags) { in resp_rsup_opcodes()
2074 0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2075 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); in resp_rsup_opcodes()
2079 if (0 == (FF_SA & oip->flags) && in resp_rsup_opcodes()
2080 req_opcode == oip->opcode) in resp_rsup_opcodes()
2082 else if (0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2083 na = oip->num_attached; in resp_rsup_opcodes()
2084 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2086 if (req_opcode == oip->opcode) in resp_rsup_opcodes()
2090 } else if (req_sa != oip->sa) { in resp_rsup_opcodes()
2091 na = oip->num_attached; in resp_rsup_opcodes()
2092 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2094 if (req_sa == oip->sa) in resp_rsup_opcodes()
2101 u = oip->len_mask[0]; in resp_rsup_opcodes()
2103 arr[4] = oip->opcode; in resp_rsup_opcodes()
2106 oip->len_mask[k] : 0xff; in resp_rsup_opcodes()
2135 u8 *cmd = scp->cmnd; in resp_rsup_tmfs()
2141 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_tmfs()
2159 { /* Read-Write Error Recovery page for mode_sense */ in resp_err_recov_pg()
2165 memset(p + 2, 0, sizeof(err_recov_pg) - 2); in resp_err_recov_pg()
2170 { /* Disconnect-Reconnect page for mode_sense */ in resp_disconnect_pg()
2176 memset(p + 2, 0, sizeof(disconnect_pg) - 2); in resp_disconnect_pg()
2192 memset(p + 2, 0, sizeof(format_pg) - 2); in resp_format_pg()
2260 { /* SAS SSP mode page - short format for mode_sense */ in resp_sas_sf_m_pg()
2266 memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2); in resp_sas_sf_m_pg()
2300 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); in resp_sas_pcd_m_spg()
2312 memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4); in resp_sas_sha_m_spg()
2325 int target = scp->device->id; in resp_mode_sense()
2328 unsigned char *cmd = scp->cmnd; in resp_mode_sense()
2338 is_zbc = (devip->zmodel != BLK_ZONED_NONE); in resp_mode_sense()
2349 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + in resp_mode_sense()
2350 (devip->target * 1000) - 3; in resp_mode_sense()
2353 dev_spec = 0x10; /* =0x90 if WP=1 implies read-only */ in resp_mode_sense()
2390 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2396 case 0x1: /* Read-Write error recovery page, direct access */ in resp_mode_sense()
2400 case 0x2: /* Disconnect-Reconnect page, all devices */ in resp_mode_sense()
2424 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2464 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2477 arr[0] = offset - 1; in resp_mode_sense()
2479 put_unaligned_be16((offset - 2), arr + 0); in resp_mode_sense()
2491 unsigned char *cmd = scp->cmnd; in resp_mode_select()
2499 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1); in resp_mode_select()
2503 if (-1 == res) in resp_mode_select()
2506 sdev_printk(KERN_INFO, scp->device, in resp_mode_select()
2513 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); in resp_mode_select()
2534 sizeof(caching_pg) - 2); in resp_mode_select()
2541 sizeof(ctrl_m_pg) - 2); in resp_mode_select()
2553 sizeof(iec_m_pg) - 2); in resp_mode_select()
2563 set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm); in resp_mode_select()
2598 unsigned char *cmd = scp->cmnd; in resp_log_sense()
2618 arr[3] = n - 4; in resp_log_sense()
2644 arr[3] = n - 4; in resp_log_sense()
2650 arr[3] = n - 4; in resp_log_sense()
2656 arr[3] = n - 4; in resp_log_sense()
2663 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_log_sense()
2673 return devip->nr_zones != 0; in sdebug_dev_is_zoned()
2679 return &devip->zstate[lba >> devip->zsize_shift]; in zbc_zone()
2684 return zsp->z_type == ZBC_ZONE_TYPE_CNV; in zbc_zone_is_conv()
2695 zc = zsp->z_cond; in zbc_close_zone()
2700 devip->nr_imp_open--; in zbc_close_zone()
2702 devip->nr_exp_open--; in zbc_close_zone()
2704 if (zsp->z_wp == zsp->z_start) { in zbc_close_zone()
2705 zsp->z_cond = ZC1_EMPTY; in zbc_close_zone()
2707 zsp->z_cond = ZC4_CLOSED; in zbc_close_zone()
2708 devip->nr_closed++; in zbc_close_zone()
2714 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_close_imp_open_zone()
2717 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_close_imp_open_zone()
2718 if (zsp->z_cond == ZC2_IMPLICIT_OPEN) { in zbc_close_imp_open_zone()
2733 zc = zsp->z_cond; in zbc_open_zone()
2739 if (explicit && zsp->z_cond == ZC2_IMPLICIT_OPEN) in zbc_open_zone()
2741 else if (devip->max_open && in zbc_open_zone()
2742 devip->nr_imp_open + devip->nr_exp_open >= devip->max_open) in zbc_open_zone()
2745 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_zone()
2746 devip->nr_closed--; in zbc_open_zone()
2748 zsp->z_cond = ZC3_EXPLICIT_OPEN; in zbc_open_zone()
2749 devip->nr_exp_open++; in zbc_open_zone()
2751 zsp->z_cond = ZC2_IMPLICIT_OPEN; in zbc_open_zone()
2752 devip->nr_imp_open++; in zbc_open_zone()
2759 switch (zsp->z_cond) { in zbc_set_zone_full()
2761 devip->nr_imp_open--; in zbc_set_zone_full()
2764 devip->nr_exp_open--; in zbc_set_zone_full()
2768 zsp->z_start, zsp->z_cond); in zbc_set_zone_full()
2771 zsp->z_cond = ZC5_FULL; in zbc_set_zone_full()
2778 unsigned long long n, end, zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
2783 if (zsp->z_type == ZBC_ZONE_TYPE_SWR) { in zbc_inc_wp()
2784 zsp->z_wp += num; in zbc_inc_wp()
2785 if (zsp->z_wp >= zend) in zbc_inc_wp()
2791 if (lba != zsp->z_wp) in zbc_inc_wp()
2792 zsp->z_non_seq_resource = true; in zbc_inc_wp()
2796 n = zend - lba; in zbc_inc_wp()
2797 zsp->z_wp = zend; in zbc_inc_wp()
2798 } else if (end > zsp->z_wp) { in zbc_inc_wp()
2800 zsp->z_wp = end; in zbc_inc_wp()
2804 if (zsp->z_wp >= zend) in zbc_inc_wp()
2807 num -= n; in zbc_inc_wp()
2811 zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
2819 struct scsi_device *sdp = scp->device; in check_zbc_access_params()
2820 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_zbc_access_params()
2822 struct sdeb_zone_state *zsp_end = zbc_zone(devip, lba + num - 1); in check_zbc_access_params()
2825 if (devip->zmodel == BLK_ZONED_HA) in check_zbc_access_params()
2827 /* For host-managed, reads cannot cross zone types boundaries */ in check_zbc_access_params()
2850 if (zsp->z_type == ZBC_ZONE_TYPE_SWR) { in check_zbc_access_params()
2859 if (zsp->z_cond == ZC5_FULL) { in check_zbc_access_params()
2865 if (lba != zsp->z_wp) { in check_zbc_access_params()
2874 if (zsp->z_cond == ZC1_EMPTY || zsp->z_cond == ZC4_CLOSED) { in check_zbc_access_params()
2875 if (devip->max_open && in check_zbc_access_params()
2876 devip->nr_exp_open >= devip->max_open) { in check_zbc_access_params()
2892 struct scsi_device *sdp = scp->device; in check_device_access_params()
2893 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_device_access_params()
2928 return xa_load(per_store_ap, devip->sdbg_host->si_idx); in devip2sip()
2931 /* Returns number of bytes copied or -1 if error. */
2938 struct scsi_data_buffer *sdb = &scp->sdb; in do_device_access()
2948 if (!sdb->length || !sip) in do_device_access()
2950 if (scp->sc_data_direction != dir) in do_device_access()
2951 return -1; in do_device_access()
2952 fsp = sip->storep; in do_device_access()
2956 rest = block + num - sdebug_store_sectors; in do_device_access()
2958 ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
2960 (num - rest) * sdebug_sector_size, sg_skip, do_write); in do_device_access()
2961 if (ret != (num - rest) * sdebug_sector_size) in do_device_access()
2965 ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
2967 sg_skip + ((num - rest) * sdebug_sector_size), in do_device_access()
2974 /* Returns number of bytes copied or -1 if error. */
2977 struct scsi_data_buffer *sdb = &scp->sdb; in do_dout_fetch()
2979 if (!sdb->length) in do_dout_fetch()
2981 if (scp->sc_data_direction != DMA_TO_DEVICE) in do_dout_fetch()
2982 return -1; in do_dout_fetch()
2983 return sg_copy_buffer(sdb->table.sgl, sdb->table.nents, doutp, in do_dout_fetch()
2987 /* If sip->storep+lba compares equal to arr(num), then copy top half of
2988 * arr into sip->storep+lba and return true. If comparison fails then
2997 u8 *fsp = sip->storep; in comp_write_worker()
3001 rest = block + num - store_blks; in comp_write_worker()
3003 res = !memcmp(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
3007 res = memcmp(fsp, arr + ((num - rest) * lb_size), in comp_write_worker()
3014 memcpy(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
3016 memcpy(fsp, arr + ((num - rest) * lb_size), rest * lb_size); in comp_write_worker()
3037 if (sdt->guard_tag != csum) { in dif_verify()
3040 be16_to_cpu(sdt->guard_tag), in dif_verify()
3045 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { in dif_verify()
3051 be32_to_cpu(sdt->ref_tag) != ei_lba) { in dif_verify()
3065 scp->device->hostdata, true); in dif_copy_prot()
3066 struct t10_pi_tuple *dif_storep = sip->dif_storep; in dif_copy_prot()
3083 rest = start + len - dif_store_end; in dif_copy_prot()
3088 memcpy(paddr, start, len - rest); in dif_copy_prot()
3090 memcpy(start, paddr, len - rest); in dif_copy_prot()
3094 memcpy(paddr + len - rest, dif_storep, rest); in dif_copy_prot()
3096 memcpy(dif_storep, paddr + len - rest, rest); in dif_copy_prot()
3100 resid -= len; in dif_copy_prot()
3111 scp->device->hostdata, true); in prot_verify_read()
3120 if (sdt->app_tag == cpu_to_be16(0xffff)) in prot_verify_read()
3145 rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; in resp_read_dt0()
3146 u8 *cmd = scp->cmnd; in resp_read_dt0()
3196 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " in resp_read_dt0()
3209 (lba <= (sdebug_medium_error_start + sdebug_medium_error_count - 1)) && in resp_read_dt0()
3214 if (0x70 == (scp->sense_buffer[0] & 0x7f)) { in resp_read_dt0()
3215 scp->sense_buffer[0] |= 0x80; /* Valid bit */ in resp_read_dt0()
3218 put_unaligned_be32(ret, scp->sense_buffer + 3); in resp_read_dt0()
3239 if (unlikely(ret == -1)) in resp_read_dt0()
3242 scsi_set_resid(scp, scsi_bufflen(scp) - ret); in resp_read_dt0()
3276 n += scnprintf(b + n, sizeof(b) - n, in dump_sector()
3279 n += scnprintf(b + n, sizeof(b) - n, in dump_sector()
3361 lba += sdebug_unmap_granularity - sdebug_unmap_alignment; in lba_to_map_index()
3371 lba -= sdebug_unmap_granularity - sdebug_unmap_alignment; in map_index_to_lba()
3384 mapped = test_bit(index, sip->map_storep); in map_state()
3387 next = find_next_zero_bit(sip->map_storep, map_size, index); in map_state()
3389 next = find_next_bit(sip->map_storep, map_size, index); in map_state()
3392 *num = end - lba; in map_state()
3405 set_bit(index, sip->map_storep); in map_region()
3415 u8 *fsp = sip->storep; in unmap_region()
3423 clear_bit(index, sip->map_storep); in unmap_region()
3430 if (sip->dif_storep) { in unmap_region()
3431 memset(sip->dif_storep + lba, 0xff, in unmap_region()
3432 sizeof(*sip->dif_storep) * in unmap_region()
3448 rwlock_t *macc_lckp = &sip->macc_lck; in resp_write_dt0()
3449 u8 *cmd = scp->cmnd; in resp_write_dt0()
3499 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_write_dt0()
3528 if (unlikely(-1 == ret)) in resp_write_dt0()
3532 sdev_printk(KERN_INFO, scp->device, in resp_write_dt0()
3563 u8 *cmd = scp->cmnd; in resp_write_scat()
3567 rwlock_t *macc_lckp = &sip->macc_lck; in resp_write_scat()
3599 sdev_printk(KERN_ERR, scp->device, in resp_write_scat()
3604 return 0; /* T10 says these do-nothings are not errors */ in resp_write_scat()
3607 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3616 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3626 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3630 if (res == -1) { in resp_write_scat()
3643 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3656 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3684 if (unlikely(-1 == ret)) { in resp_write_scat()
3688 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3726 struct scsi_device *sdp = scp->device; in resp_write_same()
3727 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in resp_write_same()
3733 scp->device->hostdata, true); in resp_write_same()
3734 rwlock_t *macc_lckp = &sip->macc_lck; in resp_write_same()
3753 fsp = sip->storep; in resp_write_same()
3761 if (-1 == ret) { in resp_write_same()
3762 write_unlock(&sip->macc_lck); in resp_write_same()
3765 sdev_printk(KERN_INFO, scp->device, in resp_write_same()
3789 u8 *cmd = scp->cmnd; in resp_write_same_10()
3805 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_write_same_10()
3814 u8 *cmd = scp->cmnd; in resp_write_same_16()
3828 if (cmd[1] & 0x1) /* NDOB (no data-out buffer, assumes zeroes) */ in resp_write_same_16()
3833 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); in resp_write_same_16()
3840 * field. For the Report supported operation codes command, SPC-4 suggests
3845 u8 *cmd = scp->cmnd; in resp_write_buffer()
3846 struct scsi_device *sdp = scp->device; in resp_write_buffer()
3854 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in resp_write_buffer()
3855 set_bit(SDEBUG_UA_MICROCODE_CHANGED, devip->uas_bm); in resp_write_buffer()
3858 set_bit(SDEBUG_UA_MICROCODE_CHANGED_WO_RESET, devip->uas_bm); in resp_write_buffer()
3863 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
3865 if (dp->target == sdp->id) { in resp_write_buffer()
3866 set_bit(SDEBUG_UA_BUS_RESET, dp->uas_bm); in resp_write_buffer()
3869 dp->uas_bm); in resp_write_buffer()
3875 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
3877 if (dp->target == sdp->id) in resp_write_buffer()
3879 dp->uas_bm); in resp_write_buffer()
3891 u8 *cmd = scp->cmnd; in resp_comp_write()
3894 rwlock_t *macc_lckp = &sip->macc_lck; in resp_comp_write()
3914 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_comp_write()
3930 if (ret == -1) { in resp_comp_write()
3934 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " in resp_comp_write()
3961 rwlock_t *macc_lckp = &sip->macc_lck; in resp_unmap()
3967 payload_len = get_unaligned_be16(scp->cmnd + 7); in resp_unmap()
3970 descriptors = (payload_len - 8) / 16; in resp_unmap()
3972 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_unmap()
3985 BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2); in resp_unmap()
4017 u8 *cmd = scp->cmnd; in resp_get_lba_status()
4041 if (sdebug_capacity - lba <= 0xffffffff) in resp_get_lba_status()
4042 num = sdebug_capacity - lba; in resp_get_lba_status()
4062 u8 *cmd = scp->cmnd; in resp_sync_cache()
4083 * Assuming the LBA+num_blocks is not out-of-range, this function will return
4096 u8 *cmd = scp->cmnd; in resp_pre_fetch()
4098 rwlock_t *macc_lckp = &sip->macc_lck; in resp_pre_fetch()
4099 u8 *fsp = sip->storep; in resp_pre_fetch()
4104 } else { /* PRE-FETCH(16) */ in resp_pre_fetch()
4114 /* PRE-FETCH spec says nothing about LBP or PI so skip them */ in resp_pre_fetch()
4117 rest = block + nblks - sdebug_store_sectors; in resp_pre_fetch()
4119 /* Try to bring the PRE-FETCH range into CPU's cache */ in resp_pre_fetch()
4122 (nblks - rest) * sdebug_sector_size); in resp_pre_fetch()
4135 * (W-LUN), the normal Linux scanning logic does not associate it with a
4137 * "cd /sys/class/scsi_host/host<n> ; echo '- - 49409' > scan"
4139 * the above will associate a W-LUN to each target. To only get a W-LUN
4140 * for target 2, then use "echo '- 2 49409' > scan" .
4145 unsigned char *cmd = scp->cmnd; in resp_report_luns()
4152 unsigned int wlun_cnt; /* report luns W-LUN count */ in resp_report_luns()
4166 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_report_luns()
4171 case 0: /* all LUNs apart from W-LUNs */ in resp_report_luns()
4175 case 1: /* only W-LUNs */ in resp_report_luns()
4184 case 0x11: /* see SPC-5 */ in resp_report_luns()
4188 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_report_luns()
4193 --lun_cnt; in resp_report_luns()
4216 lun_p->scsi_lun[0] |= 0x40; in resp_report_luns()
4244 u8 *cmd = scp->cmnd; in resp_verify()
4246 rwlock_t *macc_lckp = &sip->macc_lck; in resp_verify()
4288 if (ret == -1) { in resp_verify()
4292 sdev_printk(KERN_INFO, scp->device, in resp_verify()
4324 u8 *cmd = scp->cmnd; in resp_report_zones()
4327 rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; in resp_report_zones()
4345 max_zones = devip->nr_zones - (zs_lba >> devip->zsize_shift); in resp_report_zones()
4346 rep_max_zones = min((alloc_len - 64) >> ilog2(RZONES_DESC_HD), in resp_report_zones()
4360 lba = zs_lba + devip->zsize * i; in resp_report_zones()
4370 if (zsp->z_cond != ZC1_EMPTY) in resp_report_zones()
4375 if (zsp->z_cond != ZC2_IMPLICIT_OPEN) in resp_report_zones()
4380 if (zsp->z_cond != ZC3_EXPLICIT_OPEN) in resp_report_zones()
4385 if (zsp->z_cond != ZC4_CLOSED) in resp_report_zones()
4390 if (zsp->z_cond != ZC5_FULL) in resp_report_zones()
4397 * Read-only, offline, reset WP recommended are in resp_report_zones()
4402 /* non-seq-resource set */ in resp_report_zones()
4403 if (!zsp->z_non_seq_resource) in resp_report_zones()
4420 desc[0] = zsp->z_type; in resp_report_zones()
4421 desc[1] = zsp->z_cond << 4; in resp_report_zones()
4422 if (zsp->z_non_seq_resource) in resp_report_zones()
4424 put_unaligned_be64((u64)zsp->z_size, desc + 8); in resp_report_zones()
4425 put_unaligned_be64((u64)zsp->z_start, desc + 16); in resp_report_zones()
4426 put_unaligned_be64((u64)zsp->z_wp, desc + 24); in resp_report_zones()
4438 put_unaligned_be64(sdebug_capacity - 1, arr + 8); in resp_report_zones()
4440 rep_len = (unsigned long)desc - (unsigned long)arr; in resp_report_zones()
4449 /* Logic transplanted from tcmu-runner, file_zbc.c */
4452 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_open_all()
4455 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_open_all()
4456 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_all()
4457 zbc_open_zone(devip, &devip->zstate[i], true); in zbc_open_all()
4466 u8 *cmd = scp->cmnd; in resp_open_zone()
4470 rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; in resp_open_zone()
4481 if (devip->max_open && in resp_open_zone()
4482 devip->nr_exp_open + devip->nr_closed > devip->max_open) { in resp_open_zone()
4502 if (z_id != zsp->z_start) { in resp_open_zone()
4513 zc = zsp->z_cond; in resp_open_zone()
4517 if (devip->max_open && devip->nr_exp_open >= devip->max_open) { in resp_open_zone()
4534 for (i = 0; i < devip->nr_zones; i++) in zbc_close_all()
4535 zbc_close_zone(devip, &devip->zstate[i]); in zbc_close_all()
4543 u8 *cmd = scp->cmnd; in resp_close_zone()
4547 rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; in resp_close_zone()
4570 if (z_id != zsp->z_start) { in resp_close_zone()
4590 enum sdebug_z_cond zc = zsp->z_cond; in zbc_finish_zone()
4596 if (zsp->z_cond == ZC4_CLOSED) in zbc_finish_zone()
4597 devip->nr_closed--; in zbc_finish_zone()
4598 zsp->z_wp = zsp->z_start + zsp->z_size; in zbc_finish_zone()
4599 zsp->z_cond = ZC5_FULL; in zbc_finish_zone()
4607 for (i = 0; i < devip->nr_zones; i++) in zbc_finish_all()
4608 zbc_finish_zone(devip, &devip->zstate[i], false); in zbc_finish_all()
4617 u8 *cmd = scp->cmnd; in resp_finish_zone()
4620 rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; in resp_finish_zone()
4643 if (z_id != zsp->z_start) { in resp_finish_zone()
4669 zc = zsp->z_cond; in zbc_rwp_zone()
4673 if (zsp->z_cond == ZC4_CLOSED) in zbc_rwp_zone()
4674 devip->nr_closed--; in zbc_rwp_zone()
4676 if (zsp->z_wp > zsp->z_start) in zbc_rwp_zone()
4677 memset(sip->storep + zsp->z_start * sdebug_sector_size, 0, in zbc_rwp_zone()
4678 (zsp->z_wp - zsp->z_start) * sdebug_sector_size); in zbc_rwp_zone()
4680 zsp->z_non_seq_resource = false; in zbc_rwp_zone()
4681 zsp->z_wp = zsp->z_start; in zbc_rwp_zone()
4682 zsp->z_cond = ZC1_EMPTY; in zbc_rwp_zone()
4689 for (i = 0; i < devip->nr_zones; i++) in zbc_rwp_all()
4690 zbc_rwp_zone(devip, &devip->zstate[i]); in zbc_rwp_all()
4698 u8 *cmd = scp->cmnd; in resp_rwp_zone()
4701 rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; in resp_rwp_zone()
4723 if (z_id != zsp->z_start) { in resp_rwp_zone()
4743 u32 tag = blk_mq_unique_tag(cmnd->request); in get_queue()
4756 return blk_mq_unique_tag(cmnd->request); in get_tag()
4762 bool aborted = sd_dp->aborted; in sdebug_q_cmd_complete()
4771 sd_dp->defer_t = SDEB_DEFER_NONE; in sdebug_q_cmd_complete()
4773 sd_dp->aborted = false; in sdebug_q_cmd_complete()
4774 qc_idx = sd_dp->qc_idx; in sdebug_q_cmd_complete()
4775 sqp = sdebug_q_arr + sd_dp->sqa_idx; in sdebug_q_cmd_complete()
4778 if (raw_smp_processor_id() != sd_dp->issuing_cpu) in sdebug_q_cmd_complete()
4785 spin_lock_irqsave(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4786 sqcp = &sqp->qc_arr[qc_idx]; in sdebug_q_cmd_complete()
4787 scp = sqcp->a_cmnd; in sdebug_q_cmd_complete()
4789 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4791 sd_dp->sqa_idx, qc_idx, sd_dp->hc_idx); in sdebug_q_cmd_complete()
4794 devip = (struct sdebug_dev_info *)scp->device->hostdata; in sdebug_q_cmd_complete()
4796 atomic_dec(&devip->num_in_q); in sdebug_q_cmd_complete()
4802 sqcp->a_cmnd = NULL; in sdebug_q_cmd_complete()
4803 if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { in sdebug_q_cmd_complete()
4804 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4814 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4818 k = find_last_bit(sqp->in_use_bm, retval); in sdebug_q_cmd_complete()
4824 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in sdebug_q_cmd_complete()
4830 scp->scsi_done(scp); /* callback to mid level */ in sdebug_q_cmd_complete()
4867 devip->zsize = (DEF_ZBC_ZONE_SIZE_MB * SZ_1M) in sdebug_device_create_zones()
4869 while (capacity < devip->zsize << 2 && devip->zsize >= 2) in sdebug_device_create_zones()
4870 devip->zsize >>= 1; in sdebug_device_create_zones()
4871 if (devip->zsize < 2) { in sdebug_device_create_zones()
4873 return -EINVAL; in sdebug_device_create_zones()
4878 return -EINVAL; in sdebug_device_create_zones()
4880 devip->zsize = (sdeb_zbc_zone_size_mb * SZ_1M) in sdebug_device_create_zones()
4882 if (devip->zsize >= capacity) { in sdebug_device_create_zones()
4884 return -EINVAL; in sdebug_device_create_zones()
4888 devip->zsize_shift = ilog2(devip->zsize); in sdebug_device_create_zones()
4889 devip->nr_zones = (capacity + devip->zsize - 1) >> devip->zsize_shift; in sdebug_device_create_zones()
4891 if (sdeb_zbc_nr_conv >= devip->nr_zones) { in sdebug_device_create_zones()
4893 return -EINVAL; in sdebug_device_create_zones()
4895 devip->nr_conv_zones = sdeb_zbc_nr_conv; in sdebug_device_create_zones()
4897 if (devip->zmodel == BLK_ZONED_HM) { in sdebug_device_create_zones()
4899 if (sdeb_zbc_max_open >= devip->nr_zones - 1) in sdebug_device_create_zones()
4900 devip->max_open = (devip->nr_zones - 1) / 2; in sdebug_device_create_zones()
4902 devip->max_open = sdeb_zbc_max_open; in sdebug_device_create_zones()
4905 devip->zstate = kcalloc(devip->nr_zones, in sdebug_device_create_zones()
4907 if (!devip->zstate) in sdebug_device_create_zones()
4908 return -ENOMEM; in sdebug_device_create_zones()
4910 for (i = 0; i < devip->nr_zones; i++) { in sdebug_device_create_zones()
4911 zsp = &devip->zstate[i]; in sdebug_device_create_zones()
4913 zsp->z_start = zstart; in sdebug_device_create_zones()
4915 if (i < devip->nr_conv_zones) { in sdebug_device_create_zones()
4916 zsp->z_type = ZBC_ZONE_TYPE_CNV; in sdebug_device_create_zones()
4917 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
4918 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
4920 if (devip->zmodel == BLK_ZONED_HM) in sdebug_device_create_zones()
4921 zsp->z_type = ZBC_ZONE_TYPE_SWR; in sdebug_device_create_zones()
4923 zsp->z_type = ZBC_ZONE_TYPE_SWP; in sdebug_device_create_zones()
4924 zsp->z_cond = ZC1_EMPTY; in sdebug_device_create_zones()
4925 zsp->z_wp = zsp->z_start; in sdebug_device_create_zones()
4928 if (zsp->z_start + devip->zsize < capacity) in sdebug_device_create_zones()
4929 zsp->z_size = devip->zsize; in sdebug_device_create_zones()
4931 zsp->z_size = capacity - zsp->z_start; in sdebug_device_create_zones()
4933 zstart += zsp->z_size; in sdebug_device_create_zones()
4947 uuid_gen(&devip->lu_name); in sdebug_device_create()
4950 devip->lu_name = shared_uuid; in sdebug_device_create()
4954 devip->lu_name = shared_uuid; in sdebug_device_create()
4957 devip->sdbg_host = sdbg_host; in sdebug_device_create()
4959 devip->zmodel = sdeb_zbc_model; in sdebug_device_create()
4965 devip->zmodel = BLK_ZONED_NONE; in sdebug_device_create()
4967 devip->sdbg_host = sdbg_host; in sdebug_device_create()
4968 devip->create_ts = ktime_get_boottime(); in sdebug_device_create()
4969 atomic_set(&devip->stopped, (sdeb_tur_ms_to_ready > 0 ? 2 : 0)); in sdebug_device_create()
4970 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list); in sdebug_device_create()
4981 sdbg_host = *(struct sdebug_host_info **)shost_priv(sdev->host); in find_build_dev_info()
4987 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in find_build_dev_info()
4988 if ((devip->used) && (devip->channel == sdev->channel) && in find_build_dev_info()
4989 (devip->target == sdev->id) && in find_build_dev_info()
4990 (devip->lun == sdev->lun)) in find_build_dev_info()
4993 if ((!devip->used) && (!open_devip)) in find_build_dev_info()
5005 open_devip->channel = sdev->channel; in find_build_dev_info()
5006 open_devip->target = sdev->id; in find_build_dev_info()
5007 open_devip->lun = sdev->lun; in find_build_dev_info()
5008 open_devip->sdbg_host = sdbg_host; in find_build_dev_info()
5009 atomic_set(&open_devip->num_in_q, 0); in find_build_dev_info()
5010 set_bit(SDEBUG_UA_POR, open_devip->uas_bm); in find_build_dev_info()
5011 open_devip->used = true; in find_build_dev_info()
5019 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_alloc()
5026 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_slave_configure()
5030 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_configure()
5031 if (sdp->host->max_cmd_len != SDEBUG_MAX_CMD_LEN) in scsi_debug_slave_configure()
5032 sdp->host->max_cmd_len = SDEBUG_MAX_CMD_LEN; in scsi_debug_slave_configure()
5038 sdp->hostdata = devip; in scsi_debug_slave_configure()
5040 sdp->no_uld_attach = 1; in scsi_debug_slave_configure()
5048 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_slave_destroy()
5052 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_destroy()
5054 /* make this slot available for re-use */ in scsi_debug_slave_destroy()
5055 devip->used = false; in scsi_debug_slave_destroy()
5056 sdp->hostdata = NULL; in scsi_debug_slave_destroy()
5066 hrtimer_cancel(&sd_dp->hrt); in stop_qc_helper()
5068 cancel_work_sync(&sd_dp->ew.work); in stop_qc_helper()
5084 spin_lock_irqsave(&sqp->qc_lock, iflags); in stop_queued_cmnd()
5090 if (test_bit(k, sqp->in_use_bm)) { in stop_queued_cmnd()
5091 sqcp = &sqp->qc_arr[k]; in stop_queued_cmnd()
5092 if (cmnd != sqcp->a_cmnd) in stop_queued_cmnd()
5096 cmnd->device->hostdata; in stop_queued_cmnd()
5098 atomic_dec(&devip->num_in_q); in stop_queued_cmnd()
5099 sqcp->a_cmnd = NULL; in stop_queued_cmnd()
5100 sd_dp = sqcp->sd_dp; in stop_queued_cmnd()
5102 l_defer_t = sd_dp->defer_t; in stop_queued_cmnd()
5103 sd_dp->defer_t = SDEB_DEFER_NONE; in stop_queued_cmnd()
5106 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_queued_cmnd()
5108 clear_bit(k, sqp->in_use_bm); in stop_queued_cmnd()
5112 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_queued_cmnd()
5129 spin_lock_irqsave(&sqp->qc_lock, iflags); in stop_all_queued()
5131 if (test_bit(k, sqp->in_use_bm)) { in stop_all_queued()
5132 sqcp = &sqp->qc_arr[k]; in stop_all_queued()
5133 if (sqcp->a_cmnd == NULL) in stop_all_queued()
5136 sqcp->a_cmnd->device->hostdata; in stop_all_queued()
5138 atomic_dec(&devip->num_in_q); in stop_all_queued()
5139 sqcp->a_cmnd = NULL; in stop_all_queued()
5140 sd_dp = sqcp->sd_dp; in stop_all_queued()
5142 l_defer_t = sd_dp->defer_t; in stop_all_queued()
5143 sd_dp->defer_t = SDEB_DEFER_NONE; in stop_all_queued()
5146 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_all_queued()
5148 clear_bit(k, sqp->in_use_bm); in stop_all_queued()
5149 spin_lock_irqsave(&sqp->qc_lock, iflags); in stop_all_queued()
5152 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in stop_all_queued()
5165 sqcp = &sqp->qc_arr[k]; in free_all_queued()
5166 kfree(sqcp->sd_dp); in free_all_queued()
5167 sqcp->sd_dp = NULL; in free_all_queued()
5179 if (SCpnt->device && (SDEBUG_OPT_ALL_NOISE & sdebug_opts)) in scsi_debug_abort()
5180 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_abort()
5190 if (SCpnt && SCpnt->device) { in scsi_debug_device_reset()
5191 struct scsi_device *sdp = SCpnt->device; in scsi_debug_device_reset()
5193 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_device_reset()
5198 set_bit(SDEBUG_UA_POR, devip->uas_bm); in scsi_debug_device_reset()
5214 sdp = SCpnt->device; in scsi_debug_target_reset()
5219 hp = sdp->host; in scsi_debug_target_reset()
5225 &sdbg_host->dev_info_list, in scsi_debug_target_reset()
5227 if (devip->target == sdp->id) { in scsi_debug_target_reset()
5228 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_target_reset()
5248 if (!(SCpnt && SCpnt->device)) in scsi_debug_bus_reset()
5250 sdp = SCpnt->device; in scsi_debug_bus_reset()
5253 hp = sdp->host; in scsi_debug_bus_reset()
5258 &sdbg_host->dev_info_list, in scsi_debug_bus_reset()
5260 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_bus_reset()
5279 if ((SCpnt->device) && (SDEBUG_OPT_ALL_NOISE & sdebug_opts)) in scsi_debug_host_reset()
5280 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); in scsi_debug_host_reset()
5283 list_for_each_entry(devip, &sdbg_host->dev_info_list, in scsi_debug_host_reset()
5285 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_host_reset()
5292 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_host_reset()
5312 sectors_per_part = (num_sectors - sdebug_sectors_per) in sdebug_build_parts()
5320 if (starts[k] - starts[k - 1] < max_part_secs) in sdebug_build_parts()
5321 max_part_secs = starts[k] - starts[k - 1]; in sdebug_build_parts()
5331 end_sec = starts[k] + max_part_secs - 1; in sdebug_build_parts()
5332 pp->boot_ind = 0; in sdebug_build_parts()
5334 pp->cyl = start_sec / heads_by_sects; in sdebug_build_parts()
5335 pp->head = (start_sec - (pp->cyl * heads_by_sects)) in sdebug_build_parts()
5337 pp->sector = (start_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
5339 pp->end_cyl = end_sec / heads_by_sects; in sdebug_build_parts()
5340 pp->end_head = (end_sec - (pp->end_cyl * heads_by_sects)) in sdebug_build_parts()
5342 pp->end_sector = (end_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
5344 pp->start_sect = cpu_to_le32(start_sec); in sdebug_build_parts()
5345 pp->nr_sects = cpu_to_le32(end_sec - start_sec + 1); in sdebug_build_parts()
5346 pp->sys_ind = 0x83; /* plain Linux partition */ in sdebug_build_parts()
5356 atomic_set(&sqp->blocked, (int)block); in block_unblock_all_queues()
5359 /* Adjust (by rounding down) the sdebug_cmnd_count so abs(every_nth)-1
5418 sdp = cmnd->device; in schedule_resp()
5424 spin_lock_irqsave(&sqp->qc_lock, iflags); in schedule_resp()
5425 if (unlikely(atomic_read(&sqp->blocked))) { in schedule_resp()
5426 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5429 num_in_q = atomic_read(&devip->num_in_q); in schedule_resp()
5430 qdepth = cmnd->device->queue_depth; in schedule_resp()
5433 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5440 if ((num_in_q == (qdepth - 1)) && in schedule_resp()
5449 k = find_first_zero_bit(sqp->in_use_bm, sdebug_max_queue); in schedule_resp()
5451 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5467 set_bit(k, sqp->in_use_bm); in schedule_resp()
5468 atomic_inc(&devip->num_in_q); in schedule_resp()
5469 sqcp = &sqp->qc_arr[k]; in schedule_resp()
5470 sqcp->a_cmnd = cmnd; in schedule_resp()
5471 cmnd->host_scribble = (unsigned char *)sqcp; in schedule_resp()
5472 sd_dp = sqcp->sd_dp; in schedule_resp()
5473 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5477 atomic_dec(&devip->num_in_q); in schedule_resp()
5478 clear_bit(k, sqp->in_use_bm); in schedule_resp()
5488 sd_dp->hc_idx = get_tag(cmnd); in schedule_resp()
5494 cmnd->result = pfp ? pfp(cmnd, devip) : 0; in schedule_resp()
5495 if (cmnd->result & SDEG_RES_IMMED_MASK) { in schedule_resp()
5496 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
5499 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
5500 cmnd->result = scsi_result; in schedule_resp()
5501 if (cmnd->result == 0 && unlikely(sdebug_opts & SDEBUG_OPT_TRANSPORT_ERR)) { in schedule_resp()
5505 cmnd->result = check_condition_result; in schedule_resp()
5509 if (unlikely(sdebug_verbose && cmnd->result)) in schedule_resp()
5510 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", in schedule_resp()
5511 __func__, cmnd->result); in schedule_resp()
5532 u64 d = ktime_get_boottime_ns() - ns_from_boot; in schedule_resp()
5535 spin_lock_irqsave(&sqp->qc_lock, iflags); in schedule_resp()
5536 sqcp->a_cmnd = NULL; in schedule_resp()
5537 atomic_dec(&devip->num_in_q); in schedule_resp()
5538 clear_bit(k, sqp->in_use_bm); in schedule_resp()
5539 spin_unlock_irqrestore(&sqp->qc_lock, iflags); in schedule_resp()
5543 cmnd->scsi_done(cmnd); in schedule_resp()
5547 kt -= d; in schedule_resp()
5550 if (!sd_dp->init_hrt) { in schedule_resp()
5551 sd_dp->init_hrt = true; in schedule_resp()
5552 sqcp->sd_dp = sd_dp; in schedule_resp()
5553 hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, in schedule_resp()
5555 sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; in schedule_resp()
5556 sd_dp->sqa_idx = sqp - sdebug_q_arr; in schedule_resp()
5557 sd_dp->qc_idx = k; in schedule_resp()
5560 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
5561 sd_dp->defer_t = SDEB_DEFER_HRT; in schedule_resp()
5563 hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); in schedule_resp()
5565 if (!sd_dp->init_wq) { in schedule_resp()
5566 sd_dp->init_wq = true; in schedule_resp()
5567 sqcp->sd_dp = sd_dp; in schedule_resp()
5568 sd_dp->sqa_idx = sqp - sdebug_q_arr; in schedule_resp()
5569 sd_dp->qc_idx = k; in schedule_resp()
5570 INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); in schedule_resp()
5573 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
5574 sd_dp->defer_t = SDEB_DEFER_WQ; in schedule_resp()
5577 sd_dp->aborted = true; in schedule_resp()
5578 schedule_work(&sd_dp->ew.work); in schedule_resp()
5581 sdev_printk(KERN_INFO, sdp, "abort request tag %d\n", cmnd->request->tag); in schedule_resp()
5582 blk_abort_request(cmnd->request); in schedule_resp()
5591 respond_in_thread: /* call back to mid-layer using invocation thread */ in schedule_resp()
5592 cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; in schedule_resp()
5593 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
5594 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
5595 cmnd->result = scsi_result; in schedule_resp()
5596 cmnd->scsi_done(cmnd); in schedule_resp()
5683 MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny");
5685 MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
5687 MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
5705 MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
5709 MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)");
5710 MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
5716 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
5722 MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=7[SPC-5])");
5726 MODULE_PARM_DESC(submit_queues, "support for block multi-queue (def=1)");
5733 "1->use uuid for lu name, 0->don't, 2->all use same (def=0)");
5734 MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
5735 MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
5738 MODULE_PARM_DESC(zbc, "'none' [0]; 'aware' [1]; 'managed' [2] (def=0). Can have 'host-' prefix");
5752 if (k >= (SDEBUG_INFO_LEN - 1)) in scsi_debug_info()
5754 scnprintf(sdebug_info + k, SDEBUG_INFO_LEN - k, in scsi_debug_info()
5770 return -EACCES; in scsi_debug_write_info()
5774 return -EINVAL; in scsi_debug_write_info()
5819 f = find_first_bit(sqp->in_use_bm, sdebug_max_queue); in scsi_debug_show_info()
5821 l = find_last_bit(sqp->in_use_bm, sdebug_max_queue); in scsi_debug_show_info()
5827 seq_printf(m, "this host_no=%d\n", host->host_no); in scsi_debug_show_info()
5837 idx = sdhp->si_idx; in scsi_debug_show_info()
5839 sdhp->shost->host_no, idx); in scsi_debug_show_info()
5861 /* Returns -EBUSY if jdelay is being changed and commands are queued. The unit
5878 k = find_first_bit(sqp->in_use_bm, in delay_store()
5881 res = -EBUSY; /* queued commands */ in delay_store()
5893 return -EINVAL; in delay_store()
5901 /* Returns -EBUSY if ndelay is being changed and commands are queued */
5918 k = find_first_bit(sqp->in_use_bm, in ndelay_store()
5921 res = -EBUSY; /* queued commands */ in ndelay_store()
5934 return -EINVAL; in ndelay_store()
5958 return -EINVAL; in opts_store()
5979 return -EINVAL; in ptype_store()
5983 return -EINVAL; in ptype_store()
5987 return -EINVAL; in ptype_store()
6004 return -EINVAL; in dsense_store()
6026 if (want_store) { /* 1 --> 0 transition, set up store */ in fake_rw_store()
6039 if (sdhp->si_idx != idx) { in fake_rw_store()
6040 xa_set_mark(per_store_ap, sdhp->si_idx, in fake_rw_store()
6042 sdhp->si_idx = idx; in fake_rw_store()
6046 } else { /* 0 --> 1 transition is trigger for shrink */ in fake_rw_store()
6052 return -EINVAL; in fake_rw_store()
6069 return -EINVAL; in no_lun_0_store()
6087 return -EINVAL; in num_tgts_store()
6108 return -EINVAL; in per_host_store_store()
6140 return -EINVAL; in every_nth_store()
6164 return -EINVAL; in lun_format_store()
6168 return -EINVAL; in lun_format_store()
6172 if (changed && sdebug_scsi_level >= 5) { /* >= SPC-3 */ in lun_format_store()
6178 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in lun_format_store()
6179 set_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in lun_format_store()
6186 return -EINVAL; in lun_format_store()
6203 return -EINVAL; in max_luns_store()
6208 if (changed && (sdebug_scsi_level >= 5)) { /* >= SPC-3 */ in max_luns_store()
6215 list_for_each_entry(dp, &sdhp->dev_info_list, in max_luns_store()
6218 dp->uas_bm); in max_luns_store()
6225 return -EINVAL; in max_luns_store()
6248 a = find_last_bit(sqp->in_use_bm, SDEBUG_CANQUEUE); in max_queue_store()
6262 return -EINVAL; in max_queue_store()
6301 return -ENOTSUPP; in virtual_gb_store()
6314 list_for_each_entry(dp, &sdhp->dev_info_list, in virtual_gb_store()
6317 dp->uas_bm); in virtual_gb_store()
6324 return -EINVAL; in virtual_gb_store()
6344 return -EINVAL; in add_host_store()
6355 if (found) /* re-use case */ in add_host_store()
6362 } while (--delta_hosts); in add_host_store()
6385 return -EINVAL; in vpd_use_hostno_store()
6407 return -EINVAL; in statistics_store()
6452 return scnprintf(buf, PAGE_SIZE, "0-%u\n", in map_show()
6459 count = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", in map_show()
6460 (int)map_size, sip->map_storep); in map_show()
6480 return -EINVAL; in random_store()
6500 return -EINVAL; in removable_store()
6518 return -EINVAL; in host_lock_store()
6535 return -EINVAL; in strict_store()
6565 [BLK_ZONED_HA] = "host-aware",
6566 [BLK_ZONED_HM] = "host-managed",
6590 return -EINVAL; in sdeb_zbc_model_str()
6665 int idx = -1; in scsi_debug_init()
6685 return -EINVAL; in scsi_debug_init()
6699 return -EINVAL; in scsi_debug_init()
6704 return -EINVAL; in scsi_debug_init()
6709 return -EINVAL; in scsi_debug_init()
6714 return -EINVAL; in scsi_debug_init()
6719 return -EINVAL; in scsi_debug_init()
6738 return -EINVAL; in scsi_debug_init()
6743 return -EINVAL; in scsi_debug_init()
6748 return -EINVAL; in scsi_debug_init()
6755 return -EINVAL; in scsi_debug_init()
6768 return -ENOMEM; in scsi_debug_init()
6795 ret = -EINVAL; in scsi_debug_init()
6843 ret = -EINVAL; in scsi_debug_init()
6881 k, -ret); in scsi_debug_init()
6888 pr_err("add_host k=%d error=%d\n", k, -ret); in scsi_debug_init()
6914 for (; k; k--) in scsi_debug_exit()
6949 vfree(sip->map_storep); in sdebug_erase_store()
6950 vfree(sip->dif_storep); in sdebug_erase_store()
6951 vfree(sip->storep); in sdebug_erase_store()
6987 return -ENOMEM; in sdebug_add_store()
6994 pr_warn("%s: xa_alloc() errno=%d\n", __func__, -res); in sdebug_add_store()
7002 res = -ENOMEM; in sdebug_add_store()
7003 sip->storep = vzalloc(sz); in sdebug_add_store()
7004 if (!sip->storep) { in sdebug_add_store()
7009 sdebug_build_parts(sip->storep, sz); in sdebug_add_store()
7016 sip->dif_storep = vmalloc(dif_size); in sdebug_add_store()
7019 sip->dif_storep); in sdebug_add_store()
7021 if (!sip->dif_storep) { in sdebug_add_store()
7025 memset(sip->dif_storep, 0xff, dif_size); in sdebug_add_store()
7029 map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1; in sdebug_add_store()
7030 sip->map_storep = vmalloc(array_size(sizeof(long), in sdebug_add_store()
7035 if (!sip->map_storep) { in sdebug_add_store()
7040 bitmap_zero(sip->map_storep, map_size); in sdebug_add_store()
7047 rwlock_init(&sip->macc_lck); in sdebug_add_store()
7051 pr_warn("%s: failed, errno=%d\n", __func__, -res); in sdebug_add_store()
7058 int error = -ENOMEM; in sdebug_add_host_helper()
7064 return -ENOMEM; in sdebug_add_host_helper()
7068 sdbg_host->si_idx = idx; in sdebug_add_host_helper()
7070 INIT_LIST_HEAD(&sdbg_host->dev_info_list); in sdebug_add_host_helper()
7080 list_add_tail(&sdbg_host->host_list, &sdebug_host_list); in sdebug_add_host_helper()
7083 sdbg_host->dev.bus = &pseudo_lld_bus; in sdebug_add_host_helper()
7084 sdbg_host->dev.parent = pseudo_primary; in sdebug_add_host_helper()
7085 sdbg_host->dev.release = &sdebug_release_adapter; in sdebug_add_host_helper()
7086 dev_set_name(&sdbg_host->dev, "adapter%d", sdebug_num_hosts); in sdebug_add_host_helper()
7088 error = device_register(&sdbg_host->dev); in sdebug_add_host_helper()
7091 list_del(&sdbg_host->host_list); in sdebug_add_host_helper()
7100 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_add_host_helper()
7102 list_del(&sdbg_devinfo->dev_list); in sdebug_add_host_helper()
7103 kfree(sdbg_devinfo->zstate); in sdebug_add_host_helper()
7106 if (sdbg_host->dev.release) in sdebug_add_host_helper()
7107 put_device(&sdbg_host->dev); in sdebug_add_host_helper()
7110 pr_warn("%s: failed, errno=%d\n", __func__, -error); in sdebug_add_host_helper()
7128 int idx = -1; in sdebug_do_remove_host()
7136 idx = sdbg_host->si_idx; in sdebug_do_remove_host()
7144 if (idx == sdbg_host2->si_idx) { in sdebug_do_remove_host()
7152 --sdeb_most_recent_idx; in sdebug_do_remove_host()
7156 list_del(&sdbg_host->host_list); in sdebug_do_remove_host()
7162 device_unregister(&sdbg_host->dev); in sdebug_do_remove_host()
7163 --sdebug_num_hosts; in sdebug_do_remove_host()
7172 devip = (struct sdebug_dev_info *)sdev->hostdata; in sdebug_change_qdepth()
7175 return -ENODEV; in sdebug_change_qdepth()
7177 num_in_q = atomic_read(&devip->num_in_q); in sdebug_change_qdepth()
7191 return sdev->queue_depth; in sdebug_change_qdepth()
7197 if (sdebug_every_nth < -1) in fake_timeout()
7198 sdebug_every_nth = -1; in fake_timeout()
7214 struct scsi_device *sdp = scp->device; in resp_not_ready()
7216 stopped_state = atomic_read(&devip->stopped); in resp_not_ready()
7218 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_not_ready()
7219 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_not_ready()
7222 atomic_set(&devip->stopped, 0); in resp_not_ready()
7230 if (scp->cmnd[0] == TEST_UNIT_READY) { in resp_not_ready()
7234 diff_ns = tur_nanosecs_to_ready - diff_ns; in resp_not_ready()
7237 /* As per 20-061r2 approved for spc6 by T10 on 20200716 */ in resp_not_ready()
7239 scsi_set_sense_information(scp->sense_buffer, SCSI_SENSE_BUFFERSIZE, in resp_not_ready()
7255 struct scsi_device *sdp = scp->device; in scsi_debug_queuecommand()
7259 u8 *cmd = scp->cmnd; in scsi_debug_queuecommand()
7264 u64 lun_index = sdp->lun & 0x3FFF; in scsi_debug_queuecommand()
7283 len = scp->cmd_len; in scsi_debug_queuecommand()
7289 n += scnprintf(b + n, sb - n, "%02x ", in scsi_debug_queuecommand()
7293 blk_mq_unique_tag(scp->request), b); in scsi_debug_queuecommand()
7297 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS); in scsi_debug_queuecommand()
7303 devip = (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_queuecommand()
7312 na = oip->num_attached; in scsi_debug_queuecommand()
7313 r_pfp = oip->pfp; in scsi_debug_queuecommand()
7316 if (FF_SA & r_oip->flags) { in scsi_debug_queuecommand()
7317 if (F_SA_LOW & oip->flags) in scsi_debug_queuecommand()
7321 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
7322 if (opcode == oip->opcode && sa == oip->sa) in scsi_debug_queuecommand()
7326 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
7327 if (opcode == oip->opcode) in scsi_debug_queuecommand()
7332 if (F_SA_LOW & r_oip->flags) in scsi_debug_queuecommand()
7334 else if (F_SA_HIGH & r_oip->flags) in scsi_debug_queuecommand()
7341 flags = oip->flags; in scsi_debug_queuecommand()
7357 for (k = 1; k < oip->len_mask[0] && k < 16; ++k) { in scsi_debug_queuecommand()
7358 rem = ~oip->len_mask[k] & cmd[k]; in scsi_debug_queuecommand()
7360 for (j = 7; j >= 0; --j, rem <<= 1) { in scsi_debug_queuecommand()
7370 find_first_bit(devip->uas_bm, in scsi_debug_queuecommand()
7376 if (unlikely(((F_M_ACCESS & flags) || scp->cmnd[0] == TEST_UNIT_READY) && in scsi_debug_queuecommand()
7377 atomic_read(&devip->stopped))) { in scsi_debug_queuecommand()
7388 if (likely(oip->pfp)) in scsi_debug_queuecommand()
7389 pfp = oip->pfp; /* calls a resp_* function */ in scsi_debug_queuecommand()
7439 .max_sectors = -1U,
7440 .max_segment_size = -1U,
7456 sdebug_driver_template.dma_boundary = PAGE_SIZE - 1; in sdebug_driver_probe()
7461 error = -ENODEV; in sdebug_driver_probe()
7473 hpnt->nr_hw_queues = submit_queues; in sdebug_driver_probe()
7475 hpnt->host_tagset = 1; in sdebug_driver_probe()
7477 sdbg_host->shost = hpnt; in sdebug_driver_probe()
7478 *((struct sdebug_host_info **)hpnt->hostdata) = sdbg_host; in sdebug_driver_probe()
7479 if ((hpnt->this_id >= 0) && (sdebug_num_tgts > hpnt->this_id)) in sdebug_driver_probe()
7480 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_driver_probe()
7482 hpnt->max_id = sdebug_num_tgts; in sdebug_driver_probe()
7484 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_driver_probe()
7535 error = scsi_add_host(hpnt, &sdbg_host->dev); in sdebug_driver_probe()
7538 error = -ENODEV; in sdebug_driver_probe()
7556 return -ENODEV; in sdebug_driver_remove()
7559 scsi_remove_host(sdbg_host->shost); in sdebug_driver_remove()
7561 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_driver_remove()
7563 list_del(&sdbg_devinfo->dev_list); in sdebug_driver_remove()
7564 kfree(sdbg_devinfo->zstate); in sdebug_driver_remove()
7568 scsi_host_put(sdbg_host->shost); in sdebug_driver_remove()