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) */
255 #define TO_QUEUED_CMD(scmd) ((void *)(scmd)->host_scribble)
256 #define ASSIGN_QUEUED_CMD(scmnd, qc) { (scmnd)->host_scribble = (void *) qc; }
335 dev_to_sdebug_host(shost->dma_dev)
373 u32 flags; /* OR-ed set of SDEB_F_* */
376 u8 len_mask[16]; /* len_mask[0]-->cdb_len, then mask for cdb */
413 SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */
419 /* 0x0; 0x0->0x1f: 6 byte cdbs */
427 /* 0x20; 0x20->0x3f: 10 byte cdbs */
432 /* 0x40; 0x40->0x5f: 10 byte cdbs */
438 /* 0x60; 0x60->0x7d are reserved, 0x7e is "extended cdb" */
442 /* 0x80; 0x80->0x9f: 16 byte cdbs */
449 /* 0xa0; 0xa0->0xbf: 12 byte cdbs */
456 /* 0xc0; 0xc0->0xff: vendor specific */
464 * The following "response" functions return the SCSI mid-level's 4 byte
465 * 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) */
820 static int sdeb_first_idx = -1; /* invalid index ==> none created */
821 static int sdeb_most_recent_idx = -1;
835 static bool sdeb_zbc_in_use; /* true for host-aware and host-managed disks */
841 static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */
882 if (!sip || !sip->storep) { in lba2fake_store()
886 return lsip->storep + lba * sdebug_sector_size; in lba2fake_store()
894 return sip->dif_storep + sector; in dif_store()
904 hpnt = sdbg_host->shost; in sdebug_max_tgts_luns()
905 if ((hpnt->this_id >= 0) && in sdebug_max_tgts_luns()
906 (sdebug_num_tgts > hpnt->this_id)) in sdebug_max_tgts_luns()
907 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_max_tgts_luns()
909 hpnt->max_id = sdebug_num_tgts; in sdebug_max_tgts_luns()
911 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_max_tgts_luns()
918 /* Set in_bit to -1 to indicate no bit position of invalid field */
927 sbuff = scp->sense_buffer; in mk_sense_invalid_fld()
929 sdev_printk(KERN_ERR, scp->device, in mk_sense_invalid_fld()
954 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq" in mk_sense_invalid_fld()
961 if (!scp->sense_buffer) { in mk_sense_buffer()
962 sdev_printk(KERN_ERR, scp->device, in mk_sense_buffer()
966 memset(scp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in mk_sense_buffer()
971 sdev_printk(KERN_INFO, scp->device, in mk_sense_buffer()
996 return -EINVAL; in scsi_debug_ioctl()
997 /* return -ENOTTY; // correct return but upsets fdisk */ in scsi_debug_ioctl()
1004 sdev->use_10_for_rw = false; in config_cdb_len()
1005 sdev->use_16_for_rw = false; in config_cdb_len()
1006 sdev->use_10_for_ms = false; in config_cdb_len()
1009 sdev->use_10_for_rw = true; in config_cdb_len()
1010 sdev->use_16_for_rw = false; in config_cdb_len()
1011 sdev->use_10_for_ms = false; in config_cdb_len()
1014 sdev->use_10_for_rw = true; in config_cdb_len()
1015 sdev->use_16_for_rw = false; in config_cdb_len()
1016 sdev->use_10_for_ms = true; in config_cdb_len()
1019 sdev->use_10_for_rw = false; in config_cdb_len()
1020 sdev->use_16_for_rw = true; in config_cdb_len()
1021 sdev->use_10_for_ms = true; in config_cdb_len()
1024 sdev->use_10_for_rw = false; in config_cdb_len()
1025 sdev->use_16_for_rw = true; in config_cdb_len()
1026 sdev->use_10_for_ms = true; in config_cdb_len()
1031 sdev->use_10_for_rw = true; in config_cdb_len()
1032 sdev->use_16_for_rw = false; in config_cdb_len()
1033 sdev->use_10_for_ms = false; in config_cdb_len()
1047 shost = sdbg_host->shost; in all_config_cdb_len()
1057 struct sdebug_host_info *sdhp = devip->sdbg_host; in clear_luns_changed_on_target()
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()
1072 k = find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS); in make_ua()
1123 * SPC-3 behavior is to report a UNIT ATTENTION with in make_ua()
1126 * received. SPC-4 behavior is to report it only once. in make_ua()
1128 * values as struct scsi_device->scsi_level. in make_ua()
1130 if (sdebug_scsi_level >= 6) /* SPC-4 and above */ in make_ua()
1144 clear_bit(k, devip->uas_bm); in make_ua()
1146 sdev_printk(KERN_INFO, scp->device, in make_ua()
1154 /* Build SCSI "data-in" buffer. Returns 0 if ok else (DID_ERROR << 16). */
1159 struct scsi_data_buffer *sdb = &scp->sdb; in fill_from_dev_buffer()
1161 if (!sdb->length) in fill_from_dev_buffer()
1163 if (scp->sc_data_direction != DMA_FROM_DEVICE) in fill_from_dev_buffer()
1166 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, in fill_from_dev_buffer()
1168 scsi_set_resid(scp, scsi_bufflen(scp) - act_len); in fill_from_dev_buffer()
1173 /* Partial build of SCSI "data-in" buffer. Returns 0 if ok else
1174 * (DID_ERROR << 16). Can write to offset in data-in buffer. If multiple
1182 struct scsi_data_buffer *sdb = &scp->sdb; in p_fill_from_dev_buffer()
1185 if (sdb->length <= off_dst) in p_fill_from_dev_buffer()
1187 if (scp->sc_data_direction != DMA_FROM_DEVICE) in p_fill_from_dev_buffer()
1190 act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents, in p_fill_from_dev_buffer()
1195 n = scsi_bufflen(scp) - (off_dst + act_len); in p_fill_from_dev_buffer()
1200 /* Fetches from SCSI "data-out" buffer. Returns number of bytes fetched into
1201 * 'arr' or -1 if error.
1208 if (scp->sc_data_direction != DMA_TO_DEVICE) in fetch_to_dev_buffer()
1209 return -1; in fetch_to_dev_buffer()
1255 /* NAA-3, Logical unit identifier (binary) */ in inquiry_vpd_83()
1273 /* NAA-3, Target port identifier */ in inquiry_vpd_83()
1280 /* NAA-3, Target port group identifier */ in inquiry_vpd_83()
1289 /* NAA-3, Target device identifier */ in inquiry_vpd_83()
1297 arr[num++] = 0x63; /* proto=sas, UTF-8 */ in inquiry_vpd_83()
1341 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1353 memset(arr + num + olen, 0, plen - olen); in inquiry_vpd_85()
1374 arr[num++] = 12; /* length tp descriptor */ in inquiry_vpd_88()
1375 /* naa-5 target port identifier (A) */ in inquiry_vpd_88()
1389 arr[num++] = 12; /* length tp descriptor */ in inquiry_vpd_88()
1390 /* naa-5 target port identifier (B) */ in inquiry_vpd_88()
1461 /* Block limits VPD page (SBC-3) */
1506 /* Block device characteristics VPD page (SBC-3) */
1514 if (devip->zmodel == BLK_ZONED_HA) in inquiry_vpd_b1()
1520 /* Logical block provisioning VPD page (SBC-4) */
1546 * Optimal number of non-sequentially written sequential write in inquiry_vpd_b6()
1552 if (sdeb_zbc_model == BLK_ZONED_HM && devip->max_open) in inquiry_vpd_b6()
1553 put_unaligned_be32(devip->max_open, &arr[12]); in inquiry_vpd_b6()
1556 if (devip->zcap < devip->zsize) { in inquiry_vpd_b6()
1558 put_unaligned_be64(devip->zsize, &arr[20]); in inquiry_vpd_b6()
1572 unsigned char *cmd = scp->cmnd; in resp_inquiry()
1582 is_zbc = (devip->zmodel != BLK_ZONED_NONE); in resp_inquiry()
1584 have_wlun = scsi_is_wlun(scp->device->lun); in resp_inquiry()
1587 else if (sdebug_no_lun_0 && (devip->lun == SDEBUG_LUN_0_VAL)) in resp_inquiry()
1600 int host_no = devip->sdbg_host->shost->host_no; in resp_inquiry()
1603 (devip->channel & 0x7f); in resp_inquiry()
1606 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) + in resp_inquiry()
1607 (devip->target * 1000) + devip->lun); in resp_inquiry()
1609 (devip->target * 1000) - 3; in resp_inquiry()
1631 arr[3] = n - 4; /* number of supported VPD pages */ in resp_inquiry()
1641 &devip->lu_name); in resp_inquiry()
1661 arr[4] = 0x2; /* disconnect-reconnect mp */ in resp_inquiry()
1685 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_inquiry()
1699 arr[4] = SDEBUG_LONG_INQ_SZ - 5; in resp_inquiry()
1712 put_unaligned_be16(0xc0, arr + 58); /* SAM-6 no version claimed */ in resp_inquiry()
1713 put_unaligned_be16(0x5c0, arr + 60); /* SPC-5 no version claimed */ in resp_inquiry()
1715 if (is_disk) { /* SBC-4 no version claimed */ in resp_inquiry()
1718 } else if (sdebug_ptype == TYPE_TAPE) { /* SSC-4 rev 3 */ in resp_inquiry()
1725 put_unaligned_be16(0x2100, arr + n); /* SPL-4 no version claimed */ in resp_inquiry()
1739 unsigned char *cmd = scp->cmnd; in resp_requests()
1744 int stopped_state = atomic_read(&devip->stopped); in resp_requests()
1792 unsigned char *cmd = scp->cmnd; in resp_start_stop()
1802 stopped_state = atomic_read(&devip->stopped); in resp_start_stop()
1806 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_start_stop()
1807 u64 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_start_stop()
1811 atomic_set(&devip->stopped, 0); in resp_start_stop()
1826 atomic_xchg(&devip->stopped, want_stop); in resp_start_stop()
1855 capac = (unsigned int)sdebug_capacity - 1; in resp_readcap()
1867 unsigned char *cmd = scp->cmnd; in resp_readcap16()
1875 put_unaligned_be64((u64)(sdebug_capacity - 1), arr + 0); in resp_readcap16()
1892 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices. in resp_readcap16()
1894 if (devip->zmodel == BLK_ZONED_HM) in resp_readcap16()
1900 arr[12] = (sdebug_dif - 1) << 1; /* P_TYPE */ in resp_readcap16()
1913 unsigned char *cmd = scp->cmnd; in resp_report_tgtpgs()
1915 int host_no = devip->sdbg_host->shost->host_no; in resp_report_tgtpgs()
1933 (devip->channel & 0x7f); in resp_report_tgtpgs()
1935 (devip->channel & 0x7f) + 0x80; in resp_report_tgtpgs()
1971 rlen = n - 4; in resp_report_tgtpgs()
1976 * - The allocated length in resp_report_tgtpgs()
1977 * - The constructed command length in resp_report_tgtpgs()
1978 * - The maximum array size in resp_report_tgtpgs()
1998 u8 *cmd = scp->cmnd; in resp_rsup_opcodes()
2006 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_opcodes()
2023 oip->num_attached != 0xff; ++oip) { in resp_rsup_opcodes()
2024 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2026 count += (oip->num_attached + 1); in resp_rsup_opcodes()
2031 oip->num_attached != 0xff && offset < a_len; ++oip) { in resp_rsup_opcodes()
2032 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2034 na = oip->num_attached; in resp_rsup_opcodes()
2035 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2036 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2039 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2041 put_unaligned_be16(oip->len_mask[0], arr + offset + 6); in resp_rsup_opcodes()
2045 for (k = 0, oip = oip->arrp; k < na; ++k, ++oip) { in resp_rsup_opcodes()
2046 if (F_INV_OP & oip->flags) in resp_rsup_opcodes()
2049 arr[offset] = oip->opcode; in resp_rsup_opcodes()
2050 put_unaligned_be16(oip->sa, arr + offset + 2); in resp_rsup_opcodes()
2053 if (FF_SA & oip->flags) in resp_rsup_opcodes()
2055 put_unaligned_be16(oip->len_mask[0], in resp_rsup_opcodes()
2070 if (F_INV_OP & oip->flags) { in resp_rsup_opcodes()
2075 if (FF_SA & oip->flags) { in resp_rsup_opcodes()
2083 0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2084 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); in resp_rsup_opcodes()
2088 if (0 == (FF_SA & oip->flags) && in resp_rsup_opcodes()
2089 req_opcode == oip->opcode) in resp_rsup_opcodes()
2091 else if (0 == (FF_SA & oip->flags)) { in resp_rsup_opcodes()
2092 na = oip->num_attached; in resp_rsup_opcodes()
2093 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2095 if (req_opcode == oip->opcode) in resp_rsup_opcodes()
2099 } else if (req_sa != oip->sa) { in resp_rsup_opcodes()
2100 na = oip->num_attached; in resp_rsup_opcodes()
2101 for (k = 0, oip = oip->arrp; k < na; in resp_rsup_opcodes()
2103 if (req_sa == oip->sa) in resp_rsup_opcodes()
2110 u = oip->len_mask[0]; in resp_rsup_opcodes()
2112 arr[4] = oip->opcode; in resp_rsup_opcodes()
2115 oip->len_mask[k] : 0xff; in resp_rsup_opcodes()
2144 u8 *cmd = scp->cmnd; in resp_rsup_tmfs()
2150 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_rsup_tmfs()
2168 { /* Read-Write Error Recovery page for mode_sense */ in resp_err_recov_pg()
2174 memset(p + 2, 0, sizeof(err_recov_pg) - 2); in resp_err_recov_pg()
2179 { /* Disconnect-Reconnect page for mode_sense */ in resp_disconnect_pg()
2185 memset(p + 2, 0, sizeof(disconnect_pg) - 2); in resp_disconnect_pg()
2201 memset(p + 2, 0, sizeof(format_pg) - 2); in resp_format_pg()
2269 { /* SAS SSP mode page - short format for mode_sense */ in resp_sas_sf_m_pg()
2275 memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2); in resp_sas_sf_m_pg()
2309 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4); in resp_sas_pcd_m_spg()
2321 memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4); in resp_sas_sha_m_spg()
2334 int target = scp->device->id; in resp_mode_sense()
2337 unsigned char *cmd = scp->cmnd; in resp_mode_sense()
2347 is_zbc = (devip->zmodel != BLK_ZONED_NONE); in resp_mode_sense()
2358 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) + in resp_mode_sense()
2359 (devip->target * 1000) - 3; in resp_mode_sense()
2362 dev_spec = 0x10; /* =0x90 if WP=1 implies read-only */ in resp_mode_sense()
2399 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2405 case 0x1: /* Read-Write error recovery page, direct access */ in resp_mode_sense()
2409 case 0x2: /* Disconnect-Reconnect page, all devices */ in resp_mode_sense()
2433 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2473 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_mode_sense()
2486 arr[0] = offset - 1; in resp_mode_sense()
2488 put_unaligned_be16((offset - 2), arr + 0); in resp_mode_sense()
2500 unsigned char *cmd = scp->cmnd; in resp_mode_select()
2508 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1); in resp_mode_select()
2512 if (-1 == res) in resp_mode_select()
2515 sdev_printk(KERN_INFO, scp->device, in resp_mode_select()
2522 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); in resp_mode_select()
2543 sizeof(caching_pg) - 2); in resp_mode_select()
2550 sizeof(ctrl_m_pg) - 2); in resp_mode_select()
2562 sizeof(iec_m_pg) - 2); in resp_mode_select()
2572 set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm); in resp_mode_select()
2619 unsigned char *cmd = scp->cmnd; in resp_log_sense()
2639 arr[3] = n - 4; in resp_log_sense()
2671 arr[3] = n - 4; in resp_log_sense()
2681 arr[3] = n - 4; in resp_log_sense()
2689 arr[3] = n - 4; in resp_log_sense()
2705 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); in resp_log_sense()
2715 return devip->nr_zones != 0; in sdebug_dev_is_zoned()
2721 u32 zno = lba >> devip->zsize_shift; in zbc_zone()
2724 if (devip->zcap == devip->zsize || zno < devip->nr_conv_zones) in zbc_zone()
2725 return &devip->zstate[zno]; in zbc_zone()
2728 * If the zone capacity is less than the zone size, adjust for gap in zbc_zone()
2731 zno = 2 * zno - devip->nr_conv_zones; in zbc_zone()
2732 WARN_ONCE(zno >= devip->nr_zones, "%u > %u\n", zno, devip->nr_zones); in zbc_zone()
2733 zsp = &devip->zstate[zno]; in zbc_zone()
2734 if (lba >= zsp->z_start + zsp->z_size) in zbc_zone()
2736 WARN_ON_ONCE(lba >= zsp->z_start + zsp->z_size); in zbc_zone()
2742 return zsp->z_type == ZBC_ZTYPE_CNV; in zbc_zone_is_conv()
2747 return zsp->z_type == ZBC_ZTYPE_GAP; in zbc_zone_is_gap()
2763 zc = zsp->z_cond; in zbc_close_zone()
2768 devip->nr_imp_open--; in zbc_close_zone()
2770 devip->nr_exp_open--; in zbc_close_zone()
2772 if (zsp->z_wp == zsp->z_start) { in zbc_close_zone()
2773 zsp->z_cond = ZC1_EMPTY; in zbc_close_zone()
2775 zsp->z_cond = ZC4_CLOSED; in zbc_close_zone()
2776 devip->nr_closed++; in zbc_close_zone()
2782 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_close_imp_open_zone()
2785 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_close_imp_open_zone()
2786 if (zsp->z_cond == ZC2_IMPLICIT_OPEN) { in zbc_close_imp_open_zone()
2801 zc = zsp->z_cond; in zbc_open_zone()
2807 if (explicit && zsp->z_cond == ZC2_IMPLICIT_OPEN) in zbc_open_zone()
2809 else if (devip->max_open && in zbc_open_zone()
2810 devip->nr_imp_open + devip->nr_exp_open >= devip->max_open) in zbc_open_zone()
2813 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_zone()
2814 devip->nr_closed--; in zbc_open_zone()
2816 zsp->z_cond = ZC3_EXPLICIT_OPEN; in zbc_open_zone()
2817 devip->nr_exp_open++; in zbc_open_zone()
2819 zsp->z_cond = ZC2_IMPLICIT_OPEN; in zbc_open_zone()
2820 devip->nr_imp_open++; in zbc_open_zone()
2827 switch (zsp->z_cond) { in zbc_set_zone_full()
2829 devip->nr_imp_open--; in zbc_set_zone_full()
2832 devip->nr_exp_open--; in zbc_set_zone_full()
2836 zsp->z_start, zsp->z_cond); in zbc_set_zone_full()
2839 zsp->z_cond = ZC5_FULL; in zbc_set_zone_full()
2846 unsigned long long n, end, zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
2851 if (zsp->z_type == ZBC_ZTYPE_SWR) { in zbc_inc_wp()
2852 zsp->z_wp += num; in zbc_inc_wp()
2853 if (zsp->z_wp >= zend) in zbc_inc_wp()
2859 if (lba != zsp->z_wp) in zbc_inc_wp()
2860 zsp->z_non_seq_resource = true; in zbc_inc_wp()
2864 n = zend - lba; in zbc_inc_wp()
2865 zsp->z_wp = zend; in zbc_inc_wp()
2866 } else if (end > zsp->z_wp) { in zbc_inc_wp()
2868 zsp->z_wp = end; in zbc_inc_wp()
2872 if (zsp->z_wp >= zend) in zbc_inc_wp()
2875 num -= n; in zbc_inc_wp()
2879 zend = zsp->z_start + zsp->z_size; in zbc_inc_wp()
2887 struct scsi_device *sdp = scp->device; in check_zbc_access_params()
2888 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_zbc_access_params()
2890 struct sdeb_zone_state *zsp_end = zbc_zone(devip, lba + num - 1); in check_zbc_access_params()
2893 if (devip->zmodel == BLK_ZONED_HA) in check_zbc_access_params()
2895 /* For host-managed, reads cannot cross zone types boundaries */ in check_zbc_access_params()
2896 if (zsp->z_type != zsp_end->z_type) { in check_zbc_access_params()
2923 if (zsp->z_type == ZBC_ZTYPE_SWR) { in check_zbc_access_params()
2932 if (zsp->z_cond == ZC5_FULL) { in check_zbc_access_params()
2938 if (lba != zsp->z_wp) { in check_zbc_access_params()
2947 if (zsp->z_cond == ZC1_EMPTY || zsp->z_cond == ZC4_CLOSED) { in check_zbc_access_params()
2948 if (devip->max_open && in check_zbc_access_params()
2949 devip->nr_exp_open >= devip->max_open) { in check_zbc_access_params()
2965 struct scsi_device *sdp = scp->device; in check_device_access_params()
2966 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in check_device_access_params()
3001 return xa_load(per_store_ap, devip->sdbg_host->si_idx); in devip2sip()
3004 /* Returns number of bytes copied or -1 if error. */
3011 struct scsi_data_buffer *sdb = &scp->sdb; in do_device_access()
3021 if (!sdb->length || !sip) in do_device_access()
3023 if (scp->sc_data_direction != dir) in do_device_access()
3024 return -1; in do_device_access()
3025 fsp = sip->storep; in do_device_access()
3029 rest = block + num - sdebug_store_sectors; in do_device_access()
3031 ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
3033 (num - rest) * sdebug_sector_size, sg_skip, do_write); in do_device_access()
3034 if (ret != (num - rest) * sdebug_sector_size) in do_device_access()
3038 ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, in do_device_access()
3040 sg_skip + ((num - rest) * sdebug_sector_size), in do_device_access()
3047 /* Returns number of bytes copied or -1 if error. */
3050 struct scsi_data_buffer *sdb = &scp->sdb; in do_dout_fetch()
3052 if (!sdb->length) in do_dout_fetch()
3054 if (scp->sc_data_direction != DMA_TO_DEVICE) in do_dout_fetch()
3055 return -1; in do_dout_fetch()
3056 return sg_copy_buffer(sdb->table.sgl, sdb->table.nents, doutp, in do_dout_fetch()
3060 /* If sip->storep+lba compares equal to arr(num), then copy top half of
3061 * arr into sip->storep+lba and return true. If comparison fails then
3070 u8 *fsp = sip->storep; in comp_write_worker()
3074 rest = block + num - store_blks; in comp_write_worker()
3076 res = !memcmp(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
3080 res = memcmp(fsp, arr + ((num - rest) * lb_size), in comp_write_worker()
3087 memcpy(fsp + (block * lb_size), arr, (num - rest) * lb_size); in comp_write_worker()
3089 memcpy(fsp, arr + ((num - rest) * lb_size), rest * lb_size); in comp_write_worker()
3110 if (sdt->guard_tag != csum) { in dif_verify()
3113 be16_to_cpu(sdt->guard_tag), in dif_verify()
3118 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { in dif_verify()
3124 be32_to_cpu(sdt->ref_tag) != ei_lba) { in dif_verify()
3138 scp->device->hostdata, true); in dif_copy_prot()
3139 struct t10_pi_tuple *dif_storep = sip->dif_storep; in dif_copy_prot()
3156 rest = start + len - dif_store_end; in dif_copy_prot()
3161 memcpy(paddr, start, len - rest); in dif_copy_prot()
3163 memcpy(start, paddr, len - rest); in dif_copy_prot()
3167 memcpy(paddr + len - rest, dif_storep, rest); in dif_copy_prot()
3169 memcpy(dif_storep, paddr + len - rest, rest); in dif_copy_prot()
3173 resid -= len; in dif_copy_prot()
3185 scp->device->hostdata, true); in prot_verify_read()
3192 if (sdt->app_tag == cpu_to_be16(0xffff)) in prot_verify_read()
3202 if (scp->cmnd[1] >> 5) { /* RDPROTECT */ in prot_verify_read()
3223 __acquire(&sip->macc_lck); in sdeb_read_lock()
3228 read_lock(&sip->macc_lck); in sdeb_read_lock()
3239 __release(&sip->macc_lck); in sdeb_read_unlock()
3244 read_unlock(&sip->macc_lck); in sdeb_read_unlock()
3255 __acquire(&sip->macc_lck); in sdeb_write_lock()
3260 write_lock(&sip->macc_lck); in sdeb_write_lock()
3271 __release(&sip->macc_lck); in sdeb_write_unlock()
3276 write_unlock(&sip->macc_lck); in sdeb_write_unlock()
3290 u8 *cmd = scp->cmnd; in resp_read_dt0()
3340 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " in resp_read_dt0()
3353 (lba <= (sdebug_medium_error_start + sdebug_medium_error_count - 1)) && in resp_read_dt0()
3358 if (0x70 == (scp->sense_buffer[0] & 0x7f)) { in resp_read_dt0()
3359 scp->sense_buffer[0] |= 0x80; /* Valid bit */ in resp_read_dt0()
3362 put_unaligned_be32(ret, scp->sense_buffer + 3); in resp_read_dt0()
3378 } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { in resp_read_dt0()
3389 } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { in resp_read_dt0()
3400 if (unlikely(ret == -1)) in resp_read_dt0()
3403 scsi_set_resid(scp, scsi_bufflen(scp) - ret); in resp_read_dt0()
3470 if (SCpnt->cmnd[1] >> 5 != 3) { /* WRPROTECT */ in prot_verify_write()
3500 lba += sdebug_unmap_granularity - sdebug_unmap_alignment; in lba_to_map_index()
3510 lba -= sdebug_unmap_granularity - sdebug_unmap_alignment; in map_index_to_lba()
3523 mapped = test_bit(index, sip->map_storep); in map_state()
3526 next = find_next_zero_bit(sip->map_storep, map_size, index); in map_state()
3528 next = find_next_bit(sip->map_storep, map_size, index); in map_state()
3531 *num = end - lba; in map_state()
3544 set_bit(index, sip->map_storep); in map_region()
3554 u8 *fsp = sip->storep; in unmap_region()
3562 clear_bit(index, sip->map_storep); in unmap_region()
3569 if (sip->dif_storep) { in unmap_region()
3570 memset(sip->dif_storep + lba, 0xff, in unmap_region()
3571 sizeof(*sip->dif_storep) * in unmap_region()
3587 u8 *cmd = scp->cmnd; in resp_write_dt0()
3637 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_write_dt0()
3652 if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { in resp_write_dt0()
3656 } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ in resp_write_dt0()
3663 if (scp->prot_flags & SCSI_PROT_REF_CHECK) { in resp_write_dt0()
3667 } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ in resp_write_dt0()
3683 if (unlikely(-1 == ret)) in resp_write_dt0()
3687 sdev_printk(KERN_INFO, scp->device, in resp_write_dt0()
3718 u8 *cmd = scp->cmnd; in resp_write_scat()
3753 sdev_printk(KERN_ERR, scp->device, in resp_write_scat()
3758 return 0; /* T10 says these do-nothings are not errors */ in resp_write_scat()
3761 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3770 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3780 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3784 if (res == -1) { in resp_write_scat()
3797 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3810 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3838 if (unlikely(-1 == ret)) { in resp_write_scat()
3842 sdev_printk(KERN_INFO, scp->device, in resp_write_scat()
3880 struct scsi_device *sdp = scp->device; in resp_write_same()
3881 struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; in resp_write_same()
3887 scp->device->hostdata, true); in resp_write_same()
3906 fsp = sip->storep; in resp_write_same()
3914 if (-1 == ret) { in resp_write_same()
3918 sdev_printk(KERN_INFO, scp->device, in resp_write_same()
3942 u8 *cmd = scp->cmnd; in resp_write_same_10()
3958 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_write_same_10()
3967 u8 *cmd = scp->cmnd; in resp_write_same_16()
3981 if (cmd[1] & 0x1) /* NDOB (no data-out buffer, assumes zeroes) */ in resp_write_same_16()
3986 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); in resp_write_same_16()
3993 * field. For the Report supported operation codes command, SPC-4 suggests
3998 u8 *cmd = scp->cmnd; in resp_write_buffer()
3999 struct scsi_device *sdp = scp->device; in resp_write_buffer()
4007 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in resp_write_buffer()
4008 set_bit(SDEBUG_UA_MICROCODE_CHANGED, devip->uas_bm); in resp_write_buffer()
4011 set_bit(SDEBUG_UA_MICROCODE_CHANGED_WO_RESET, devip->uas_bm); in resp_write_buffer()
4016 &devip->sdbg_host->dev_info_list, in resp_write_buffer()
4018 if (dp->target == sdp->id) { in resp_write_buffer()
4019 set_bit(SDEBUG_UA_BUS_RESET, dp->uas_bm); in resp_write_buffer()
4022 dp->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()
4032 dp->uas_bm); in resp_write_buffer()
4044 u8 *cmd = scp->cmnd; in resp_comp_write()
4066 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " in resp_comp_write()
4082 if (ret == -1) { in resp_comp_write()
4086 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " in resp_comp_write()
4118 payload_len = get_unaligned_be16(scp->cmnd + 7); in resp_unmap()
4121 descriptors = (payload_len - 8) / 16; in resp_unmap()
4123 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1); in resp_unmap()
4136 BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2); in resp_unmap()
4168 u8 *cmd = scp->cmnd; in resp_get_lba_status()
4192 if (sdebug_capacity - lba <= 0xffffffff) in resp_get_lba_status()
4193 num = sdebug_capacity - lba; in resp_get_lba_status()
4213 u8 *cmd = scp->cmnd; in resp_sync_cache()
4234 * Assuming the LBA+num_blocks is not out-of-range, this function will return
4247 u8 *cmd = scp->cmnd; in resp_pre_fetch()
4249 u8 *fsp = sip->storep; in resp_pre_fetch()
4254 } else { /* PRE-FETCH(16) */ in resp_pre_fetch()
4264 /* PRE-FETCH spec says nothing about LBP or PI so skip them */ in resp_pre_fetch()
4267 rest = block + nblks - sdebug_store_sectors; in resp_pre_fetch()
4269 /* Try to bring the PRE-FETCH range into CPU's cache */ in resp_pre_fetch()
4272 (nblks - rest) * sdebug_sector_size); in resp_pre_fetch()
4285 * (W-LUN), the normal Linux scanning logic does not associate it with a
4287 * "cd /sys/class/scsi_host/host<n> ; echo '- - 49409' > scan"
4289 * the above will associate a W-LUN to each target. To only get a W-LUN
4290 * for target 2, then use "echo '- 2 49409' > scan" .
4295 unsigned char *cmd = scp->cmnd; in resp_report_luns()
4302 unsigned int wlun_cnt; /* report luns W-LUN count */ in resp_report_luns()
4316 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1); in resp_report_luns()
4321 case 0: /* all LUNs apart from W-LUNs */ in resp_report_luns()
4325 case 1: /* only W-LUNs */ in resp_report_luns()
4334 case 0x11: /* see SPC-5 */ in resp_report_luns()
4338 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); in resp_report_luns()
4343 --lun_cnt; in resp_report_luns()
4366 lun_p->scsi_lun[0] |= 0x40; in resp_report_luns()
4394 u8 *cmd = scp->cmnd; in resp_verify()
4437 if (ret == -1) { in resp_verify()
4441 sdev_printk(KERN_INFO, scp->device, in resp_verify()
4473 u8 *cmd = scp->cmnd; in resp_report_zones()
4493 rep_max_zones = (alloc_len - 64) >> ilog2(RZONES_DESC_HD); in resp_report_zones()
4506 lba = zsp->z_start + zsp->z_size) { in resp_report_zones()
4516 if (zsp->z_cond != ZC1_EMPTY) in resp_report_zones()
4521 if (zsp->z_cond != ZC2_IMPLICIT_OPEN) in resp_report_zones()
4526 if (zsp->z_cond != ZC3_EXPLICIT_OPEN) in resp_report_zones()
4531 if (zsp->z_cond != ZC4_CLOSED) in resp_report_zones()
4536 if (zsp->z_cond != ZC5_FULL) in resp_report_zones()
4543 * Read-only, offline, reset WP recommended are in resp_report_zones()
4548 /* non-seq-resource set */ in resp_report_zones()
4549 if (!zsp->z_non_seq_resource) in resp_report_zones()
4571 desc[0] = zsp->z_type; in resp_report_zones()
4572 desc[1] = zsp->z_cond << 4; in resp_report_zones()
4573 if (zsp->z_non_seq_resource) in resp_report_zones()
4575 put_unaligned_be64((u64)zsp->z_size, desc + 8); in resp_report_zones()
4576 put_unaligned_be64((u64)zsp->z_start, desc + 16); in resp_report_zones()
4577 put_unaligned_be64((u64)zsp->z_wp, desc + 24); in resp_report_zones()
4591 put_unaligned_be64(sdebug_capacity - 1, arr + 8); in resp_report_zones()
4593 if (devip->zcap < devip->zsize) in resp_report_zones()
4594 put_unaligned_be64(devip->zsize, arr + 16); in resp_report_zones()
4596 rep_len = (unsigned long)desc - (unsigned long)arr; in resp_report_zones()
4605 /* Logic transplanted from tcmu-runner, file_zbc.c */
4608 struct sdeb_zone_state *zsp = &devip->zstate[0]; in zbc_open_all()
4611 for (i = 0; i < devip->nr_zones; i++, zsp++) { in zbc_open_all()
4612 if (zsp->z_cond == ZC4_CLOSED) in zbc_open_all()
4613 zbc_open_zone(devip, &devip->zstate[i], true); in zbc_open_all()
4622 u8 *cmd = scp->cmnd; in resp_open_zone()
4636 if (devip->max_open && in resp_open_zone()
4637 devip->nr_exp_open + devip->nr_closed > devip->max_open) { in resp_open_zone()
4657 if (z_id != zsp->z_start) { in resp_open_zone()
4668 zc = zsp->z_cond; in resp_open_zone()
4672 if (devip->max_open && devip->nr_exp_open >= devip->max_open) { in resp_open_zone()
4689 for (i = 0; i < devip->nr_zones; i++) in zbc_close_all()
4690 zbc_close_zone(devip, &devip->zstate[i]); in zbc_close_all()
4698 u8 *cmd = scp->cmnd; in resp_close_zone()
4724 if (z_id != zsp->z_start) { in resp_close_zone()
4744 enum sdebug_z_cond zc = zsp->z_cond; in zbc_finish_zone()
4750 if (zsp->z_cond == ZC4_CLOSED) in zbc_finish_zone()
4751 devip->nr_closed--; in zbc_finish_zone()
4752 zsp->z_wp = zsp->z_start + zsp->z_size; in zbc_finish_zone()
4753 zsp->z_cond = ZC5_FULL; in zbc_finish_zone()
4761 for (i = 0; i < devip->nr_zones; i++) in zbc_finish_all()
4762 zbc_finish_zone(devip, &devip->zstate[i], false); in zbc_finish_all()
4771 u8 *cmd = scp->cmnd; in resp_finish_zone()
4796 if (z_id != zsp->z_start) { in resp_finish_zone()
4822 zc = zsp->z_cond; in zbc_rwp_zone()
4826 if (zsp->z_cond == ZC4_CLOSED) in zbc_rwp_zone()
4827 devip->nr_closed--; in zbc_rwp_zone()
4829 if (zsp->z_wp > zsp->z_start) in zbc_rwp_zone()
4830 memset(sip->storep + zsp->z_start * sdebug_sector_size, 0, in zbc_rwp_zone()
4831 (zsp->z_wp - zsp->z_start) * sdebug_sector_size); in zbc_rwp_zone()
4833 zsp->z_non_seq_resource = false; in zbc_rwp_zone()
4834 zsp->z_wp = zsp->z_start; in zbc_rwp_zone()
4835 zsp->z_cond = ZC1_EMPTY; in zbc_rwp_zone()
4842 for (i = 0; i < devip->nr_zones; i++) in zbc_rwp_all()
4843 zbc_rwp_zone(devip, &devip->zstate[i]); in zbc_rwp_all()
4851 u8 *cmd = scp->cmnd; in resp_rwp_zone()
4875 if (z_id != zsp->z_start) { in resp_rwp_zone()
4902 struct scsi_cmnd *scp = sqcp->scmd; in sdebug_q_cmd_complete()
4908 if (raw_smp_processor_id() != sd_dp->issuing_cpu) in sdebug_q_cmd_complete()
4918 spin_lock_irqsave(&sdsc->lock, flags); in sdebug_q_cmd_complete()
4919 aborted = sd_dp->aborted; in sdebug_q_cmd_complete()
4921 sd_dp->aborted = false; in sdebug_q_cmd_complete()
4924 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_q_cmd_complete()
4927 pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); in sdebug_q_cmd_complete()
4972 devip->zsize = (DEF_ZBC_ZONE_SIZE_MB * SZ_1M) in sdebug_device_create_zones()
4974 while (capacity < devip->zsize << 2 && devip->zsize >= 2) in sdebug_device_create_zones()
4975 devip->zsize >>= 1; in sdebug_device_create_zones()
4976 if (devip->zsize < 2) { in sdebug_device_create_zones()
4978 return -EINVAL; in sdebug_device_create_zones()
4983 return -EINVAL; in sdebug_device_create_zones()
4985 devip->zsize = (sdeb_zbc_zone_size_mb * SZ_1M) in sdebug_device_create_zones()
4987 if (devip->zsize >= capacity) { in sdebug_device_create_zones()
4989 return -EINVAL; in sdebug_device_create_zones()
4993 devip->zsize_shift = ilog2(devip->zsize); in sdebug_device_create_zones()
4994 devip->nr_zones = (capacity + devip->zsize - 1) >> devip->zsize_shift; in sdebug_device_create_zones()
4997 devip->zcap = devip->zsize; in sdebug_device_create_zones()
4999 devip->zcap = (sdeb_zbc_zone_cap_mb * SZ_1M) >> in sdebug_device_create_zones()
5001 if (devip->zcap > devip->zsize) { in sdebug_device_create_zones()
5003 return -EINVAL; in sdebug_device_create_zones()
5007 conv_capacity = (sector_t)sdeb_zbc_nr_conv << devip->zsize_shift; in sdebug_device_create_zones()
5010 return -EINVAL; in sdebug_device_create_zones()
5012 devip->nr_conv_zones = sdeb_zbc_nr_conv; in sdebug_device_create_zones()
5013 devip->nr_seq_zones = ALIGN(capacity - conv_capacity, devip->zsize) >> in sdebug_device_create_zones()
5014 devip->zsize_shift; in sdebug_device_create_zones()
5015 devip->nr_zones = devip->nr_conv_zones + devip->nr_seq_zones; in sdebug_device_create_zones()
5018 if (devip->zcap < devip->zsize) in sdebug_device_create_zones()
5019 devip->nr_zones += devip->nr_seq_zones; in sdebug_device_create_zones()
5021 if (devip->zmodel == BLK_ZONED_HM) { in sdebug_device_create_zones()
5023 if (sdeb_zbc_max_open >= devip->nr_zones - 1) in sdebug_device_create_zones()
5024 devip->max_open = (devip->nr_zones - 1) / 2; in sdebug_device_create_zones()
5026 devip->max_open = sdeb_zbc_max_open; in sdebug_device_create_zones()
5029 devip->zstate = kcalloc(devip->nr_zones, in sdebug_device_create_zones()
5031 if (!devip->zstate) in sdebug_device_create_zones()
5032 return -ENOMEM; in sdebug_device_create_zones()
5034 for (i = 0; i < devip->nr_zones; i++) { in sdebug_device_create_zones()
5035 zsp = &devip->zstate[i]; in sdebug_device_create_zones()
5037 zsp->z_start = zstart; in sdebug_device_create_zones()
5039 if (i < devip->nr_conv_zones) { in sdebug_device_create_zones()
5040 zsp->z_type = ZBC_ZTYPE_CNV; in sdebug_device_create_zones()
5041 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
5042 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
5043 zsp->z_size = in sdebug_device_create_zones()
5044 min_t(u64, devip->zsize, capacity - zstart); in sdebug_device_create_zones()
5045 } else if ((zstart & (devip->zsize - 1)) == 0) { in sdebug_device_create_zones()
5046 if (devip->zmodel == BLK_ZONED_HM) in sdebug_device_create_zones()
5047 zsp->z_type = ZBC_ZTYPE_SWR; in sdebug_device_create_zones()
5049 zsp->z_type = ZBC_ZTYPE_SWP; in sdebug_device_create_zones()
5050 zsp->z_cond = ZC1_EMPTY; in sdebug_device_create_zones()
5051 zsp->z_wp = zsp->z_start; in sdebug_device_create_zones()
5052 zsp->z_size = in sdebug_device_create_zones()
5053 min_t(u64, devip->zcap, capacity - zstart); in sdebug_device_create_zones()
5055 zsp->z_type = ZBC_ZTYPE_GAP; in sdebug_device_create_zones()
5056 zsp->z_cond = ZBC_NOT_WRITE_POINTER; in sdebug_device_create_zones()
5057 zsp->z_wp = (sector_t)-1; in sdebug_device_create_zones()
5058 zsp->z_size = min_t(u64, devip->zsize - devip->zcap, in sdebug_device_create_zones()
5059 capacity - zstart); in sdebug_device_create_zones()
5062 WARN_ON_ONCE((int)zsp->z_size <= 0); in sdebug_device_create_zones()
5063 zstart += zsp->z_size; in sdebug_device_create_zones()
5077 uuid_gen(&devip->lu_name); in sdebug_device_create()
5080 devip->lu_name = shared_uuid; in sdebug_device_create()
5084 devip->lu_name = shared_uuid; in sdebug_device_create()
5087 devip->sdbg_host = sdbg_host; in sdebug_device_create()
5089 devip->zmodel = sdeb_zbc_model; in sdebug_device_create()
5095 devip->zmodel = BLK_ZONED_NONE; in sdebug_device_create()
5097 devip->create_ts = ktime_get_boottime(); in sdebug_device_create()
5098 atomic_set(&devip->stopped, (sdeb_tur_ms_to_ready > 0 ? 2 : 0)); in sdebug_device_create()
5099 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list); in sdebug_device_create()
5110 sdbg_host = shost_to_sdebug_host(sdev->host); in find_build_dev_info()
5112 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in find_build_dev_info()
5113 if ((devip->used) && (devip->channel == sdev->channel) && in find_build_dev_info()
5114 (devip->target == sdev->id) && in find_build_dev_info()
5115 (devip->lun == sdev->lun)) in find_build_dev_info()
5118 if ((!devip->used) && (!open_devip)) in find_build_dev_info()
5130 open_devip->channel = sdev->channel; in find_build_dev_info()
5131 open_devip->target = sdev->id; in find_build_dev_info()
5132 open_devip->lun = sdev->lun; in find_build_dev_info()
5133 open_devip->sdbg_host = sdbg_host; in find_build_dev_info()
5134 set_bit(SDEBUG_UA_POOCCUR, open_devip->uas_bm); in find_build_dev_info()
5135 open_devip->used = true; in find_build_dev_info()
5143 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_alloc()
5150 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_slave_configure()
5154 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_configure()
5155 if (sdp->host->max_cmd_len != SDEBUG_MAX_CMD_LEN) in scsi_debug_slave_configure()
5156 sdp->host->max_cmd_len = SDEBUG_MAX_CMD_LEN; in scsi_debug_slave_configure()
5162 sdp->hostdata = devip; in scsi_debug_slave_configure()
5164 sdp->no_uld_attach = 1; in scsi_debug_slave_configure()
5172 (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_slave_destroy()
5176 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); in scsi_debug_slave_destroy()
5178 /* make this slot available for re-use */ in scsi_debug_slave_destroy()
5179 devip->used = false; in scsi_debug_slave_destroy()
5180 sdp->hostdata = NULL; in scsi_debug_slave_destroy()
5189 int res = hrtimer_try_to_cancel(&sd_dp->hrt); in stop_qc_helper()
5193 case -1: /* -1 It's executing the CB */ in stop_qc_helper()
5201 if (cancel_work_sync(&sd_dp->ew.work)) in stop_qc_helper()
5220 lockdep_assert_held(&sdsc->lock); in scsi_debug_stop_cmnd()
5224 sd_dp = &sqcp->sd_dp; in scsi_debug_stop_cmnd()
5225 l_defer_t = READ_ONCE(sd_dp->defer_t); in scsi_debug_stop_cmnd()
5235 * Called from scsi_debug_abort() only, which is for timed-out cmd.
5243 spin_lock_irqsave(&sdsc->lock, flags); in scsi_debug_abort_cmnd()
5245 spin_unlock_irqrestore(&sdsc->lock, flags); in scsi_debug_abort_cmnd()
5268 struct Scsi_Host *shost = sdhp->shost; in stop_all_queued()
5270 blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_stop_cmnd, NULL); in stop_all_queued()
5282 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_abort()
5294 if (scmd->device == sdp) in scsi_debug_stop_all_queued_iter()
5303 struct Scsi_Host *shost = sdp->host; in scsi_debug_stop_all_queued()
5305 blk_mq_tagset_busy_iter(&shost->tag_set, in scsi_debug_stop_all_queued()
5311 struct scsi_device *sdp = SCpnt->device; in scsi_debug_device_reset()
5312 struct sdebug_dev_info *devip = sdp->hostdata; in scsi_debug_device_reset()
5321 set_bit(SDEBUG_UA_POR, devip->uas_bm); in scsi_debug_device_reset()
5328 struct scsi_device *sdp = SCpnt->device; in scsi_debug_target_reset()
5329 struct sdebug_host_info *sdbg_host = shost_to_sdebug_host(sdp->host); in scsi_debug_target_reset()
5337 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in scsi_debug_target_reset()
5338 if (devip->target == sdp->id) { in scsi_debug_target_reset()
5339 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_target_reset()
5353 struct scsi_device *sdp = SCpnt->device; in scsi_debug_bus_reset()
5354 struct sdebug_host_info *sdbg_host = shost_to_sdebug_host(sdp->host); in scsi_debug_bus_reset()
5363 list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { in scsi_debug_bus_reset()
5364 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_bus_reset()
5382 sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); in scsi_debug_host_reset()
5385 list_for_each_entry(devip, &sdbg_host->dev_info_list, in scsi_debug_host_reset()
5387 set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm); in scsi_debug_host_reset()
5394 sdev_printk(KERN_INFO, SCpnt->device, in scsi_debug_host_reset()
5414 sectors_per_part = (num_sectors - sdebug_sectors_per) in sdebug_build_parts()
5422 if (starts[k] - starts[k - 1] < max_part_secs) in sdebug_build_parts()
5423 max_part_secs = starts[k] - starts[k - 1]; in sdebug_build_parts()
5433 end_sec = starts[k] + max_part_secs - 1; in sdebug_build_parts()
5434 pp->boot_ind = 0; in sdebug_build_parts()
5436 pp->cyl = start_sec / heads_by_sects; in sdebug_build_parts()
5437 pp->head = (start_sec - (pp->cyl * heads_by_sects)) in sdebug_build_parts()
5439 pp->sector = (start_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
5441 pp->end_cyl = end_sec / heads_by_sects; in sdebug_build_parts()
5442 pp->end_head = (end_sec - (pp->end_cyl * heads_by_sects)) in sdebug_build_parts()
5444 pp->end_sector = (end_sec % sdebug_sectors_per) + 1; in sdebug_build_parts()
5446 pp->start_sect = cpu_to_le32(start_sec); in sdebug_build_parts()
5447 pp->nr_sects = cpu_to_le32(end_sec - start_sec + 1); in sdebug_build_parts()
5448 pp->sys_ind = 0x83; /* plain Linux partition */ in sdebug_build_parts()
5459 struct Scsi_Host *shost = sdhp->shost; in block_unblock_all_queues()
5468 /* Adjust (by rounding down) the sdebug_cmnd_count so abs(every_nth)-1
5520 sd_dp = &sqcp->sd_dp; in sdebug_alloc_queued_cmd()
5522 hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); in sdebug_alloc_queued_cmd()
5523 sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; in sdebug_alloc_queued_cmd()
5524 INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); in sdebug_alloc_queued_cmd()
5526 sqcp->scmd = scmd; in sdebug_alloc_queued_cmd()
5543 bool polled = rq->cmd_flags & REQ_POLLED; in schedule_resp()
5556 sdp = cmnd->device; in schedule_resp()
5565 int qdepth = cmnd->device->queue_depth; in schedule_resp()
5584 sd_dp = &sqcp->sd_dp; in schedule_resp()
5590 cmnd->result = pfp ? pfp(cmnd, devip) : 0; in schedule_resp()
5591 if (cmnd->result & SDEG_RES_IMMED_MASK) { in schedule_resp()
5592 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
5595 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
5596 cmnd->result = scsi_result; in schedule_resp()
5597 if (cmnd->result == 0 && unlikely(sdebug_opts & SDEBUG_OPT_TRANSPORT_ERR)) { in schedule_resp()
5601 cmnd->result = check_condition_result; in schedule_resp()
5605 if (unlikely(sdebug_verbose && cmnd->result)) in schedule_resp()
5606 sdev_printk(KERN_INFO, sdp, "%s: non-zero result=0x%x\n", in schedule_resp()
5607 __func__, cmnd->result); in schedule_resp()
5628 u64 d = ktime_get_boottime_ns() - ns_from_boot; in schedule_resp()
5637 kt -= d; in schedule_resp()
5641 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
5643 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
5644 sd_dp->cmpl_ts = ktime_add(ns_to_ktime(ns_from_boot), kt); in schedule_resp()
5646 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); in schedule_resp()
5647 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
5650 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
5652 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); in schedule_resp()
5653 hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); in schedule_resp()
5655 * The completion handler will try to grab sqcp->lock, in schedule_resp()
5660 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
5665 sd_dp->aborted = true; in schedule_resp()
5672 sd_dp->issuing_cpu = raw_smp_processor_id(); in schedule_resp()
5674 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
5676 sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot); in schedule_resp()
5677 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); in schedule_resp()
5678 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
5680 spin_lock_irqsave(&sdsc->lock, flags); in schedule_resp()
5682 WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_WQ); in schedule_resp()
5683 schedule_work(&sd_dp->ew.work); in schedule_resp()
5684 spin_unlock_irqrestore(&sdsc->lock, flags); in schedule_resp()
5690 respond_in_thread: /* call back to mid-layer using invocation thread */ in schedule_resp()
5691 cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; in schedule_resp()
5692 cmnd->result &= ~SDEG_RES_IMMED_MASK; in schedule_resp()
5693 if (cmnd->result == 0 && scsi_result != 0) in schedule_resp()
5694 cmnd->result = scsi_result; in schedule_resp()
5785 MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny");
5787 MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
5789 MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
5806 MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
5811 MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)");
5812 MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
5819 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
5822 MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1))");
5826 MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=7[SPC-5])");
5830 MODULE_PARM_DESC(submit_queues, "support for block multi-queue (def=1)");
5837 "1->use uuid for lu name, 0->don't, 2->all use same (def=0)");
5838 MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
5839 MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
5842 MODULE_PARM_DESC(zbc, "'none' [0]; 'aware' [1]; 'managed' [2] (def=0). Can have 'host-' prefix");
5857 if (k >= (SDEBUG_INFO_LEN - 1)) in scsi_debug_info()
5859 scnprintf(sdebug_info + k, SDEBUG_INFO_LEN - k, in scsi_debug_info()
5875 return -EACCES; in scsi_debug_write_info()
5879 return -EINVAL; in scsi_debug_write_info()
5900 int queue_num = data->queue_num; in sdebug_submit_queue_iter()
5906 if (*data->first == -1) in sdebug_submit_queue_iter()
5907 *data->first = *data->last = tag; in sdebug_submit_queue_iter()
5909 *data->last = tag; in sdebug_submit_queue_iter()
5949 int f = -1, l = -1; in scsi_debug_show_info()
5956 blk_mq_tagset_busy_iter(&host->tag_set, sdebug_submit_queue_iter, in scsi_debug_show_info()
5964 seq_printf(m, "this host_no=%d\n", host->host_no); in scsi_debug_show_info()
5974 idx = sdhp->si_idx; in scsi_debug_show_info()
5976 sdhp->shost->host_no, idx); in scsi_debug_show_info()
5998 /* Returns -EBUSY if jdelay is being changed and commands are queued. The unit
6015 struct Scsi_Host *shost = sdhp->shost; in delay_store()
6018 res = -EBUSY; /* queued commands */ in delay_store()
6031 return -EINVAL; in delay_store()
6039 /* Returns -EBUSY if ndelay is being changed and commands are queued */
6056 struct Scsi_Host *shost = sdhp->shost; in ndelay_store()
6059 res = -EBUSY; /* queued commands */ in ndelay_store()
6074 return -EINVAL; in ndelay_store()
6098 return -EINVAL; in opts_store()
6119 return -EINVAL; in ptype_store()
6123 return -EINVAL; in ptype_store()
6127 return -EINVAL; in ptype_store()
6144 return -EINVAL; in dsense_store()
6166 if (want_store) { /* 1 --> 0 transition, set up store */ in fake_rw_store()
6179 if (sdhp->si_idx != idx) { in fake_rw_store()
6180 xa_set_mark(per_store_ap, sdhp->si_idx, in fake_rw_store()
6182 sdhp->si_idx = idx; in fake_rw_store()
6186 } else { /* 0 --> 1 transition is trigger for shrink */ in fake_rw_store()
6192 return -EINVAL; in fake_rw_store()
6209 return -EINVAL; in no_lun_0_store()
6227 return -EINVAL; in num_tgts_store()
6248 return -EINVAL; in per_host_store_store()
6280 return -EINVAL; in every_nth_store()
6304 return -EINVAL; in lun_format_store()
6308 return -EINVAL; in lun_format_store()
6312 if (changed && sdebug_scsi_level >= 5) { /* >= SPC-3 */ in lun_format_store()
6318 list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { in lun_format_store()
6319 set_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); in lun_format_store()
6326 return -EINVAL; in lun_format_store()
6343 return -EINVAL; in max_luns_store()
6348 if (changed && (sdebug_scsi_level >= 5)) { /* >= SPC-3 */ in max_luns_store()
6355 list_for_each_entry(dp, &sdhp->dev_info_list, in max_luns_store()
6358 dp->uas_bm); in max_luns_store()
6365 return -EINVAL; in max_luns_store()
6389 count = -EBUSY; in max_queue_store()
6393 return -EINVAL; in max_queue_store()
6412 return -EINVAL; in no_rwlock_store()
6449 return -ENOTSUPP; in virtual_gb_store()
6462 list_for_each_entry(dp, &sdhp->dev_info_list, in virtual_gb_store()
6465 dp->uas_bm); in virtual_gb_store()
6472 return -EINVAL; in virtual_gb_store()
6492 return -EINVAL; in add_host_store()
6503 if (found) /* re-use case */ in add_host_store()
6510 } while (--delta_hosts); in add_host_store()
6533 return -EINVAL; in vpd_use_hostno_store()
6555 return -EINVAL; in statistics_store()
6600 return scnprintf(buf, PAGE_SIZE, "0-%u\n", in map_show()
6607 count = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", in map_show()
6608 (int)map_size, sip->map_storep); in map_show()
6628 return -EINVAL; in random_store()
6648 return -EINVAL; in removable_store()
6666 return -EINVAL; in host_lock_store()
6683 return -EINVAL; in strict_store()
6713 [BLK_ZONED_HA] = "host-aware",
6714 [BLK_ZONED_HM] = "host-managed",
6738 return -EINVAL; in sdeb_zbc_model_str()
6814 int idx = -1; in scsi_debug_init()
6830 return -EINVAL; in scsi_debug_init()
6844 return -EINVAL; in scsi_debug_init()
6849 return -EINVAL; in scsi_debug_init()
6854 return -EINVAL; in scsi_debug_init()
6859 return -EINVAL; in scsi_debug_init()
6864 return -EINVAL; in scsi_debug_init()
6883 return -EINVAL; in scsi_debug_init()
6888 return -EINVAL; in scsi_debug_init()
6893 return -EINVAL; in scsi_debug_init()
6900 return -EINVAL; in scsi_debug_init()
6931 return -EINVAL; in scsi_debug_init()
6978 return -EINVAL; in scsi_debug_init()
7010 ret = -ENOMEM; in scsi_debug_init()
7019 k, -ret); in scsi_debug_init()
7026 pr_err("add_host k=%d error=%d\n", k, -ret); in scsi_debug_init()
7051 for (; k; k--) in scsi_debug_exit()
7085 vfree(sip->map_storep); in sdebug_erase_store()
7086 vfree(sip->dif_storep); in sdebug_erase_store()
7087 vfree(sip->storep); in sdebug_erase_store()
7123 return -ENOMEM; in sdebug_add_store()
7130 pr_warn("%s: xa_alloc() errno=%d\n", __func__, -res); in sdebug_add_store()
7138 res = -ENOMEM; in sdebug_add_store()
7139 sip->storep = vzalloc(sz); in sdebug_add_store()
7140 if (!sip->storep) { in sdebug_add_store()
7145 sdebug_build_parts(sip->storep, sz); in sdebug_add_store()
7152 sip->dif_storep = vmalloc(dif_size); in sdebug_add_store()
7155 sip->dif_storep); in sdebug_add_store()
7157 if (!sip->dif_storep) { in sdebug_add_store()
7161 memset(sip->dif_storep, 0xff, dif_size); in sdebug_add_store()
7165 map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1; in sdebug_add_store()
7166 sip->map_storep = vmalloc(array_size(sizeof(long), in sdebug_add_store()
7171 if (!sip->map_storep) { in sdebug_add_store()
7176 bitmap_zero(sip->map_storep, map_size); in sdebug_add_store()
7183 rwlock_init(&sip->macc_lck); in sdebug_add_store()
7187 pr_warn("%s: failed, errno=%d\n", __func__, -res); in sdebug_add_store()
7194 int error = -ENOMEM; in sdebug_add_host_helper()
7200 return -ENOMEM; in sdebug_add_host_helper()
7204 sdbg_host->si_idx = idx; in sdebug_add_host_helper()
7206 INIT_LIST_HEAD(&sdbg_host->dev_info_list); in sdebug_add_host_helper()
7216 list_add_tail(&sdbg_host->host_list, &sdebug_host_list); in sdebug_add_host_helper()
7219 sdbg_host->dev.bus = &pseudo_lld_bus; in sdebug_add_host_helper()
7220 sdbg_host->dev.parent = pseudo_primary; in sdebug_add_host_helper()
7221 sdbg_host->dev.release = &sdebug_release_adapter; in sdebug_add_host_helper()
7222 dev_set_name(&sdbg_host->dev, "adapter%d", sdebug_num_hosts); in sdebug_add_host_helper()
7224 error = device_register(&sdbg_host->dev); in sdebug_add_host_helper()
7227 list_del(&sdbg_host->host_list); in sdebug_add_host_helper()
7236 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_add_host_helper()
7238 list_del(&sdbg_devinfo->dev_list); in sdebug_add_host_helper()
7239 kfree(sdbg_devinfo->zstate); in sdebug_add_host_helper()
7242 if (sdbg_host->dev.release) in sdebug_add_host_helper()
7243 put_device(&sdbg_host->dev); in sdebug_add_host_helper()
7246 pr_warn("%s: failed, errno=%d\n", __func__, -error); in sdebug_add_host_helper()
7264 int idx = -1; in sdebug_do_remove_host()
7272 idx = sdbg_host->si_idx; in sdebug_do_remove_host()
7280 if (idx == sdbg_host2->si_idx) { in sdebug_do_remove_host()
7288 --sdeb_most_recent_idx; in sdebug_do_remove_host()
7292 list_del(&sdbg_host->host_list); in sdebug_do_remove_host()
7298 device_unregister(&sdbg_host->dev); in sdebug_do_remove_host()
7299 --sdebug_num_hosts; in sdebug_do_remove_host()
7304 struct sdebug_dev_info *devip = sdev->hostdata; in sdebug_change_qdepth()
7307 return -ENODEV; in sdebug_change_qdepth()
7319 if (qdepth != sdev->queue_depth) in sdebug_change_qdepth()
7328 return sdev->queue_depth; in sdebug_change_qdepth()
7334 if (sdebug_every_nth < -1) in fake_timeout()
7335 sdebug_every_nth = -1; in fake_timeout()
7351 struct scsi_device *sdp = scp->device; in resp_not_ready()
7353 stopped_state = atomic_read(&devip->stopped); in resp_not_ready()
7355 if (ktime_to_ns(now_ts) > ktime_to_ns(devip->create_ts)) { in resp_not_ready()
7356 diff_ns = ktime_to_ns(ktime_sub(now_ts, devip->create_ts)); in resp_not_ready()
7359 atomic_set(&devip->stopped, 0); in resp_not_ready()
7367 if (scp->cmnd[0] == TEST_UNIT_READY) { in resp_not_ready()
7371 diff_ns = tur_nanosecs_to_ready - diff_ns; in resp_not_ready()
7374 /* As per 20-061r2 approved for spc6 by T10 on 20200716 */ in resp_not_ready()
7376 scsi_set_sense_information(scp->sense_buffer, SCSI_SENSE_BUFFERSIZE, in resp_not_ready()
7392 if (shost->nr_hw_queues == 1) in sdebug_map_queues()
7396 struct blk_mq_queue_map *map = &shost->tag_set.map[i]; in sdebug_map_queues()
7398 map->nr_queues = 0; in sdebug_map_queues()
7401 map->nr_queues = submit_queues - poll_queues; in sdebug_map_queues()
7403 map->nr_queues = poll_queues; in sdebug_map_queues()
7405 if (!map->nr_queues) { in sdebug_map_queues()
7410 map->queue_offset = qoff; in sdebug_map_queues()
7413 qoff += map->nr_queues; in sdebug_map_queues()
7436 int queue_num = data->queue_num; in sdebug_blk_mq_poll_iter()
7444 if (!test_bit(SCMD_STATE_INFLIGHT, &cmd->state)) in sdebug_blk_mq_poll_iter()
7449 spin_lock_irqsave(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
7452 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
7456 sd_dp = &sqcp->sd_dp; in sdebug_blk_mq_poll_iter()
7457 if (READ_ONCE(sd_dp->defer_t) != SDEB_DEFER_POLL) { in sdebug_blk_mq_poll_iter()
7458 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
7462 if (time < sd_dp->cmpl_ts) { in sdebug_blk_mq_poll_iter()
7463 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
7468 spin_unlock_irqrestore(&sdsc->lock, flags); in sdebug_blk_mq_poll_iter()
7472 if (raw_smp_processor_id() != sd_dp->issuing_cpu) in sdebug_blk_mq_poll_iter()
7479 (*data->num_entries)++; in sdebug_blk_mq_poll_iter()
7491 blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_blk_mq_poll_iter, in sdebug_blk_mq_poll()
7503 struct scsi_device *sdp = scp->device; in scsi_debug_queuecommand()
7507 u8 *cmd = scp->cmnd; in scsi_debug_queuecommand()
7512 u64 lun_index = sdp->lun & 0x3FFF; in scsi_debug_queuecommand()
7531 len = scp->cmd_len; in scsi_debug_queuecommand()
7537 n += scnprintf(b + n, sb - n, "%02x ", in scsi_debug_queuecommand()
7545 has_wlun_rl = (sdp->lun == SCSI_W_LUN_REPORT_LUNS); in scsi_debug_queuecommand()
7551 devip = (struct sdebug_dev_info *)sdp->hostdata; in scsi_debug_queuecommand()
7560 na = oip->num_attached; in scsi_debug_queuecommand()
7561 r_pfp = oip->pfp; in scsi_debug_queuecommand()
7564 if (FF_SA & r_oip->flags) { in scsi_debug_queuecommand()
7565 if (F_SA_LOW & oip->flags) in scsi_debug_queuecommand()
7569 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
7570 if (opcode == oip->opcode && sa == oip->sa) in scsi_debug_queuecommand()
7574 for (k = 0; k <= na; oip = r_oip->arrp + k++) { in scsi_debug_queuecommand()
7575 if (opcode == oip->opcode) in scsi_debug_queuecommand()
7580 if (F_SA_LOW & r_oip->flags) in scsi_debug_queuecommand()
7582 else if (F_SA_HIGH & r_oip->flags) in scsi_debug_queuecommand()
7589 flags = oip->flags; in scsi_debug_queuecommand()
7605 for (k = 1; k < oip->len_mask[0] && k < 16; ++k) { in scsi_debug_queuecommand()
7606 rem = ~oip->len_mask[k] & cmd[k]; in scsi_debug_queuecommand()
7608 for (j = 7; j >= 0; --j, rem <<= 1) { in scsi_debug_queuecommand()
7618 find_first_bit(devip->uas_bm, in scsi_debug_queuecommand()
7624 if (unlikely(((F_M_ACCESS & flags) || scp->cmnd[0] == TEST_UNIT_READY) && in scsi_debug_queuecommand()
7625 atomic_read(&devip->stopped))) { in scsi_debug_queuecommand()
7636 if (likely(oip->pfp)) in scsi_debug_queuecommand()
7637 pfp = oip->pfp; /* calls a resp_* function */ in scsi_debug_queuecommand()
7670 spin_lock_init(&sdsc->lock); in sdebug_init_cmd_priv()
7699 .max_sectors = -1U,
7700 .max_segment_size = -1U,
7719 sdebug_driver_template.dma_boundary = PAGE_SIZE - 1; in sdebug_driver_probe()
7724 error = -ENODEV; in sdebug_driver_probe()
7736 hpnt->nr_hw_queues = submit_queues; in sdebug_driver_probe()
7738 hpnt->host_tagset = 1; in sdebug_driver_probe()
7741 if (hpnt->nr_hw_queues == 1 || (poll_queues < 1)) { in sdebug_driver_probe()
7743 my_name, poll_queues, hpnt->nr_hw_queues); in sdebug_driver_probe()
7749 * left over for non-polled I/O. in sdebug_driver_probe()
7757 my_name, submit_queues - 1); in sdebug_driver_probe()
7761 hpnt->nr_maps = 3; in sdebug_driver_probe()
7763 sdbg_host->shost = hpnt; in sdebug_driver_probe()
7764 if ((hpnt->this_id >= 0) && (sdebug_num_tgts > hpnt->this_id)) in sdebug_driver_probe()
7765 hpnt->max_id = sdebug_num_tgts + 1; in sdebug_driver_probe()
7767 hpnt->max_id = sdebug_num_tgts; in sdebug_driver_probe()
7769 hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; in sdebug_driver_probe()
7820 error = scsi_add_host(hpnt, &sdbg_host->dev); in sdebug_driver_probe()
7823 error = -ENODEV; in sdebug_driver_probe()
7839 scsi_remove_host(sdbg_host->shost); in sdebug_driver_remove()
7841 list_for_each_entry_safe(sdbg_devinfo, tmp, &sdbg_host->dev_info_list, in sdebug_driver_remove()
7843 list_del(&sdbg_devinfo->dev_list); in sdebug_driver_remove()
7844 kfree(sdbg_devinfo->zstate); in sdebug_driver_remove()
7848 scsi_host_put(sdbg_host->shost); in sdebug_driver_remove()