Lines Matching refs:psp
197 static int nvme_pt(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
319 get_open_pt_handle(struct sg_pt_win32_scsi * psp, int device_fd, bool vbb) in get_open_pt_handle() argument
327 if (psp) in get_open_pt_handle()
328 psp->os_err = EBADF; in get_open_pt_handle()
335 if (psp) in get_open_pt_handle()
336 psp->os_err = ENODEV; in get_open_pt_handle()
675 struct sg_pt_win32_scsi * psp; in construct_scsi_pt_obj_with_fd() local
697 psp = (struct sg_pt_win32_scsi *)calloc(sizeof(struct sg_pt_win32_scsi), in construct_scsi_pt_obj_with_fd()
699 if (psp) { in construct_scsi_pt_obj_with_fd()
700 psp->dev_fd = (dev_fd < 0) ? -1 : dev_fd; in construct_scsi_pt_obj_with_fd()
702 psp->is_nvme = shp->is_nvme; in construct_scsi_pt_obj_with_fd()
703 psp->dev_statp = &shp->dev_stat; in construct_scsi_pt_obj_with_fd()
705 sntl_init_dev_stat(psp->dev_statp); in construct_scsi_pt_obj_with_fd()
713 if (psp->is_nvme) { in construct_scsi_pt_obj_with_fd()
716 psp->swb_d.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; in construct_scsi_pt_obj_with_fd()
717 psp->swb_d.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; in construct_scsi_pt_obj_with_fd()
718 psp->swb_d.spt.SenseInfoOffset = in construct_scsi_pt_obj_with_fd()
720 psp->swb_d.spt.TimeOutValue = DEF_TIMEOUT; in construct_scsi_pt_obj_with_fd()
722 psp->swb_i.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; in construct_scsi_pt_obj_with_fd()
723 psp->swb_i.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; in construct_scsi_pt_obj_with_fd()
724 psp->swb_i.spt.SenseInfoOffset = in construct_scsi_pt_obj_with_fd()
726 psp->swb_i.spt.TimeOutValue = DEF_TIMEOUT; in construct_scsi_pt_obj_with_fd()
731 vp->implp = psp; in construct_scsi_pt_obj_with_fd()
733 free(psp); in construct_scsi_pt_obj_with_fd()
750 struct sg_pt_win32_scsi * psp = vp->implp; in destruct_scsi_pt_obj() local
752 if (psp) { in destruct_scsi_pt_obj()
753 free(psp); in destruct_scsi_pt_obj()
767 struct sg_pt_win32_scsi * psp; in set_pt_file_handle() local
774 if ((psp = vp->implp)) { in set_pt_file_handle()
778 psp->dev_fd = -1; in set_pt_file_handle()
779 psp->is_nvme = false; in set_pt_file_handle()
780 psp->nvme_nsid = 0; in set_pt_file_handle()
783 shp = get_open_pt_handle(psp, dev_han, vb > 1); in set_pt_file_handle()
787 psp->os_err = EINVAL; in set_pt_file_handle()
788 return psp->os_err; in set_pt_file_handle()
790 psp->os_err = 0; in set_pt_file_handle()
791 psp->transport_err = 0; in set_pt_file_handle()
792 psp->in_err = 0; in set_pt_file_handle()
793 psp->scsi_status = 0; in set_pt_file_handle()
794 psp->dev_fd = dev_han; in set_pt_file_handle()
800 psp->os_err = 0; in set_pt_file_handle()
806 psp->os_err = EIO; in set_pt_file_handle()
807 if (psp->os_err) in set_pt_file_handle()
808 return psp->os_err; in set_pt_file_handle()
809 psp->is_nvme = shp->is_nvme; in set_pt_file_handle()
810 psp->nvme_nsid = 0; /* should be 'psp->nvme_nsid = shp->nvme_nsid' */ in set_pt_file_handle()
811 psp->dev_statp = &shp->dev_stat; in set_pt_file_handle()
821 const struct sg_pt_win32_scsi * psp; in get_pt_file_handle() local
824 psp = vp->implp; in get_pt_file_handle()
825 return psp ? psp->dev_fd : -1; in get_pt_file_handle()
837 struct sg_pt_win32_scsi * psp = vp->implp; in clear_scsi_pt_obj() local
840 if (psp) { in clear_scsi_pt_obj()
841 dev_fd = psp->dev_fd; in clear_scsi_pt_obj()
842 is_nvme = psp->is_nvme; in clear_scsi_pt_obj()
843 nvme_nsid = psp->nvme_nsid; in clear_scsi_pt_obj()
844 dsp = psp->dev_statp; in clear_scsi_pt_obj()
845 memset(psp, 0, sizeof(struct sg_pt_win32_scsi)); in clear_scsi_pt_obj()
847 psp->swb_d.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; in clear_scsi_pt_obj()
848 psp->swb_d.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; in clear_scsi_pt_obj()
849 psp->swb_d.spt.SenseInfoOffset = in clear_scsi_pt_obj()
851 psp->swb_d.spt.TimeOutValue = DEF_TIMEOUT; in clear_scsi_pt_obj()
853 psp->swb_i.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; in clear_scsi_pt_obj()
854 psp->swb_i.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; in clear_scsi_pt_obj()
855 psp->swb_i.spt.SenseInfoOffset = in clear_scsi_pt_obj()
857 psp->swb_i.spt.TimeOutValue = DEF_TIMEOUT; in clear_scsi_pt_obj()
859 psp->dev_fd = dev_fd; in clear_scsi_pt_obj()
860 psp->is_nvme = is_nvme; in clear_scsi_pt_obj()
861 psp->nvme_nsid = nvme_nsid; in clear_scsi_pt_obj()
862 psp->dev_statp = dsp; in clear_scsi_pt_obj()
869 struct sg_pt_win32_scsi * psp = vp->implp; in partial_clear_scsi_pt_obj() local
871 if (NULL == psp) in partial_clear_scsi_pt_obj()
873 psp->in_err = 0; in partial_clear_scsi_pt_obj()
874 psp->os_err = 0; in partial_clear_scsi_pt_obj()
875 psp->transport_err = 0; in partial_clear_scsi_pt_obj()
876 psp->scsi_status = 0; in partial_clear_scsi_pt_obj()
878 psp->swb_d.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; in partial_clear_scsi_pt_obj()
879 psp->swb_d.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; in partial_clear_scsi_pt_obj()
880 psp->swb_d.spt.SenseInfoOffset = in partial_clear_scsi_pt_obj()
882 psp->swb_d.spt.TimeOutValue = DEF_TIMEOUT; in partial_clear_scsi_pt_obj()
884 psp->swb_i.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; in partial_clear_scsi_pt_obj()
885 psp->swb_i.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; in partial_clear_scsi_pt_obj()
886 psp->swb_i.spt.SenseInfoOffset = in partial_clear_scsi_pt_obj()
888 psp->swb_i.spt.TimeOutValue = DEF_TIMEOUT; in partial_clear_scsi_pt_obj()
897 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_cdb() local
900 psp->have_nvme_cmd = true; in set_scsi_pt_cdb()
901 memcpy(psp->nvme_cmd, cdb, cdb_len); in set_scsi_pt_cdb()
903 if (cdb_len > (int)sizeof(psp->swb_d.spt.Cdb)) { in set_scsi_pt_cdb()
904 ++psp->in_err; in set_scsi_pt_cdb()
907 memcpy(psp->swb_d.spt.Cdb, cdb, cdb_len); in set_scsi_pt_cdb()
908 psp->swb_d.spt.CdbLength = cdb_len; in set_scsi_pt_cdb()
910 if (cdb_len > (int)sizeof(psp->swb_i.spt.Cdb)) { in set_scsi_pt_cdb()
911 ++psp->in_err; in set_scsi_pt_cdb()
914 memcpy(psp->swb_i.spt.Cdb, cdb, cdb_len); in set_scsi_pt_cdb()
915 psp->swb_i.spt.CdbLength = cdb_len; in set_scsi_pt_cdb()
922 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_cdb_len() local
924 return spt_direct ? psp->swb_d.spt.CdbLength : psp->swb_i.spt.CdbLength; in get_scsi_pt_cdb_len()
930 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_cdb_buf() local
933 if (psp->swb_d.spt.CdbLength > 0) in get_scsi_pt_cdb_buf()
934 return (uint8_t *)(psp->swb_d.spt.Cdb); in get_scsi_pt_cdb_buf()
938 if (psp->swb_i.spt.CdbLength > 0) in get_scsi_pt_cdb_buf()
939 return (uint8_t *)(psp->swb_i.spt.Cdb); in get_scsi_pt_cdb_buf()
948 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_sense() local
952 psp->sensep = sense; in set_scsi_pt_sense()
953 psp->sense_len = sense_len; in set_scsi_pt_sense()
961 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_data_in() local
963 if (psp->dxferp) in set_scsi_pt_data_in()
964 ++psp->in_err; in set_scsi_pt_data_in()
966 psp->dxferp = dxferp; in set_scsi_pt_data_in()
967 psp->dxfer_len = (uint32_t)dxfer_len; in set_scsi_pt_data_in()
968 psp->is_read = true; in set_scsi_pt_data_in()
970 psp->swb_d.spt.DataIn = SCSI_IOCTL_DATA_IN; in set_scsi_pt_data_in()
972 psp->swb_i.spt.DataIn = SCSI_IOCTL_DATA_IN; in set_scsi_pt_data_in()
981 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_data_out() local
983 if (psp->dxferp) in set_scsi_pt_data_out()
984 ++psp->in_err; in set_scsi_pt_data_out()
986 psp->dxferp = (uint8_t *)dxferp; in set_scsi_pt_data_out()
987 psp->dxfer_len = (uint32_t)dxfer_len; in set_scsi_pt_data_out()
989 psp->swb_d.spt.DataIn = SCSI_IOCTL_DATA_OUT; in set_scsi_pt_data_out()
991 psp->swb_i.spt.DataIn = SCSI_IOCTL_DATA_OUT; in set_scsi_pt_data_out()
999 struct sg_pt_win32_scsi * psp = vp->implp; in set_pt_metadata_xfer() local
1001 if (psp->mdxferp) in set_pt_metadata_xfer()
1002 ++psp->in_err; in set_pt_metadata_xfer()
1004 psp->mdxferp = mdxferp; in set_pt_metadata_xfer()
1005 psp->mdxfer_len = mdxfer_len; in set_pt_metadata_xfer()
1006 psp->mdxfer_out = out_true; in set_pt_metadata_xfer()
1019 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_tag() local
1021 ++psp->in_err; in set_scsi_pt_tag()
1028 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_task_management() local
1030 ++psp->in_err; in set_scsi_pt_task_management()
1038 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_task_attr() local
1040 ++psp->in_err; in set_scsi_pt_task_attr()
1055 scsi_pt_direct(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in scsi_pt_direct() argument
1061 psp->os_err = 0; in scsi_pt_direct()
1062 if (0 == psp->swb_d.spt.CdbLength) { in scsi_pt_direct()
1067 psp->swb_d.spt.Length = sizeof (SCSI_PASS_THROUGH_DIRECT); in scsi_pt_direct()
1068 psp->swb_d.spt.PathId = shp->bus; in scsi_pt_direct()
1069 psp->swb_d.spt.TargetId = shp->target; in scsi_pt_direct()
1070 psp->swb_d.spt.Lun = shp->lun; in scsi_pt_direct()
1071 psp->swb_d.spt.TimeOutValue = time_secs; in scsi_pt_direct()
1072 psp->swb_d.spt.DataTransferLength = psp->dxfer_len; in scsi_pt_direct()
1076 (int)psp->swb_d.spt.Length, (int)psp->swb_d.spt.ScsiStatus, in scsi_pt_direct()
1077 (int)psp->swb_d.spt.PathId, (int)psp->swb_d.spt.TargetId, in scsi_pt_direct()
1078 (int)psp->swb_d.spt.Lun); in scsi_pt_direct()
1081 (int)psp->swb_d.spt.CdbLength, in scsi_pt_direct()
1082 (int)psp->swb_d.spt.SenseInfoLength, in scsi_pt_direct()
1083 (int)psp->swb_d.spt.DataIn, in scsi_pt_direct()
1084 (unsigned int)psp->swb_d.spt.DataTransferLength); in scsi_pt_direct()
1086 (unsigned int)psp->swb_d.spt.TimeOutValue, in scsi_pt_direct()
1087 (unsigned int)psp->swb_d.spt.SenseInfoOffset); in scsi_pt_direct()
1089 psp->swb_d.spt.DataBuffer = psp->dxferp; in scsi_pt_direct()
1091 &psp->swb_d, in scsi_pt_direct()
1092 sizeof(psp->swb_d), in scsi_pt_direct()
1093 &psp->swb_d, in scsi_pt_direct()
1094 sizeof(psp->swb_d), in scsi_pt_direct()
1107 psp->transport_err = (int)u; in scsi_pt_direct()
1108 psp->os_err = EIO; in scsi_pt_direct()
1112 psp->scsi_status = psp->swb_d.spt.ScsiStatus; in scsi_pt_direct()
1113 if ((SAM_STAT_CHECK_CONDITION == psp->scsi_status) || in scsi_pt_direct()
1114 (SAM_STAT_COMMAND_TERMINATED == psp->scsi_status)) in scsi_pt_direct()
1115 memcpy(psp->sensep, psp->swb_d.ucSenseBuf, psp->sense_len); in scsi_pt_direct()
1117 psp->sense_len = 0; in scsi_pt_direct()
1118 psp->sense_resid = 0; in scsi_pt_direct()
1119 if ((psp->dxfer_len > 0) && (psp->swb_d.spt.DataTransferLength > 0)) in scsi_pt_direct()
1120 psp->resid = psp->dxfer_len - psp->swb_d.spt.DataTransferLength; in scsi_pt_direct()
1122 psp->resid = 0; in scsi_pt_direct()
1136 struct sg_pt_win32_scsi * psp = vp->implp; in scsi_pt_indirect() local
1138 psp->os_err = 0; in scsi_pt_indirect()
1139 if (0 == psp->swb_i.spt.CdbLength) { in scsi_pt_indirect()
1144 if (psp->dxfer_len > (int)sizeof(psp->swb_i.ucDataBuf)) { in scsi_pt_indirect()
1145 int extra = psp->dxfer_len - (int)sizeof(psp->swb_i.ucDataBuf); in scsi_pt_indirect()
1150 " buffer (%d bytes), try enlarging\n", psp->dxfer_len, in scsi_pt_indirect()
1151 (int)sizeof(psp->swb_i.ucDataBuf)); in scsi_pt_indirect()
1156 psp->dxfer_len); in scsi_pt_indirect()
1157 psp->os_err = ENOMEM; in scsi_pt_indirect()
1158 return -psp->os_err; in scsi_pt_indirect()
1160 memcpy(epsp, psp, sizeof(struct sg_pt_win32_scsi)); in scsi_pt_indirect()
1161 free(psp); in scsi_pt_indirect()
1163 psp = epsp; in scsi_pt_indirect()
1165 psp->swb_i.spt.Length = sizeof (SCSI_PASS_THROUGH); in scsi_pt_indirect()
1166 psp->swb_i.spt.DataBufferOffset = in scsi_pt_indirect()
1168 psp->swb_i.spt.PathId = shp->bus; in scsi_pt_indirect()
1169 psp->swb_i.spt.TargetId = shp->target; in scsi_pt_indirect()
1170 psp->swb_i.spt.Lun = shp->lun; in scsi_pt_indirect()
1171 psp->swb_i.spt.TimeOutValue = time_secs; in scsi_pt_indirect()
1172 psp->swb_i.spt.DataTransferLength = psp->dxfer_len; in scsi_pt_indirect()
1176 (int)psp->swb_i.spt.Length, (int)psp->swb_i.spt.ScsiStatus, in scsi_pt_indirect()
1177 (int)psp->swb_i.spt.PathId, (int)psp->swb_i.spt.TargetId, in scsi_pt_indirect()
1178 (int)psp->swb_i.spt.Lun); in scsi_pt_indirect()
1181 (int)psp->swb_i.spt.CdbLength, in scsi_pt_indirect()
1182 (int)psp->swb_i.spt.SenseInfoLength, in scsi_pt_indirect()
1183 (int)psp->swb_i.spt.DataIn, in scsi_pt_indirect()
1184 (unsigned int)psp->swb_i.spt.DataTransferLength); in scsi_pt_indirect()
1187 (unsigned int)psp->swb_i.spt.TimeOutValue, in scsi_pt_indirect()
1188 (unsigned int)psp->swb_i.spt.DataBufferOffset, in scsi_pt_indirect()
1189 (unsigned int)psp->swb_i.spt.SenseInfoOffset); in scsi_pt_indirect()
1191 if ((psp->dxfer_len > 0) && in scsi_pt_indirect()
1192 (SCSI_IOCTL_DATA_OUT == psp->swb_i.spt.DataIn)) in scsi_pt_indirect()
1193 memcpy(psp->swb_i.ucDataBuf, psp->dxferp, psp->dxfer_len); in scsi_pt_indirect()
1195 &psp->swb_i, in scsi_pt_indirect()
1196 sizeof(psp->swb_i), in scsi_pt_indirect()
1197 &psp->swb_i, in scsi_pt_indirect()
1198 sizeof(psp->swb_i), in scsi_pt_indirect()
1210 psp->transport_err = (int)u; in scsi_pt_indirect()
1211 psp->os_err = EIO; in scsi_pt_indirect()
1214 if ((psp->dxfer_len > 0) && (SCSI_IOCTL_DATA_IN == psp->swb_i.spt.DataIn)) in scsi_pt_indirect()
1215 memcpy(psp->dxferp, psp->swb_i.ucDataBuf, psp->dxfer_len); in scsi_pt_indirect()
1217 psp->scsi_status = psp->swb_i.spt.ScsiStatus; in scsi_pt_indirect()
1218 if ((SAM_STAT_CHECK_CONDITION == psp->scsi_status) || in scsi_pt_indirect()
1219 (SAM_STAT_COMMAND_TERMINATED == psp->scsi_status)) in scsi_pt_indirect()
1220 memcpy(psp->sensep, psp->swb_i.ucSenseBuf, psp->sense_len); in scsi_pt_indirect()
1222 psp->sense_len = 0; in scsi_pt_indirect()
1223 psp->sense_resid = 0; in scsi_pt_indirect()
1224 if ((psp->dxfer_len > 0) && (psp->swb_i.spt.DataTransferLength > 0)) in scsi_pt_indirect()
1225 psp->resid = psp->dxfer_len - psp->swb_i.spt.DataTransferLength; in scsi_pt_indirect()
1227 psp->resid = 0; in scsi_pt_indirect()
1241 struct sg_pt_win32_scsi * psp = vp->implp; in do_scsi_pt() local
1244 if (! (vp && ((psp = vp->implp)))) { in do_scsi_pt()
1249 psp->os_err = 0; in do_scsi_pt()
1251 if ((psp->dev_fd >= 0) && (dev_fd != psp->dev_fd)) { in do_scsi_pt()
1257 psp->dev_fd = dev_fd; in do_scsi_pt()
1258 } else if (psp->dev_fd < 0) { /* so no dev_fd in ctor */ in do_scsi_pt()
1263 dev_fd = psp->dev_fd; in do_scsi_pt()
1264 shp = get_open_pt_handle(psp, dev_fd, vb > 3); in do_scsi_pt()
1266 return -psp->os_err; in do_scsi_pt()
1273 psp->os_err = 0; in do_scsi_pt()
1279 psp->os_err = EIO; in do_scsi_pt()
1280 if (psp->os_err) in do_scsi_pt()
1281 return -psp->os_err; in do_scsi_pt()
1282 psp->is_nvme = shp->is_nvme; in do_scsi_pt()
1283 psp->dev_statp = &shp->dev_stat; in do_scsi_pt()
1285 if (psp->is_nvme) in do_scsi_pt()
1286 return nvme_pt(psp, shp, time_secs, vb); in do_scsi_pt()
1288 return scsi_pt_direct(psp, shp, time_secs, vb); in do_scsi_pt()
1296 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_result_category() local
1298 if (psp->transport_err) /* give transport error highest priority */ in get_scsi_pt_result_category()
1300 else if (psp->os_err) in get_scsi_pt_result_category()
1302 else if ((SAM_STAT_CHECK_CONDITION == psp->scsi_status) || in get_scsi_pt_result_category()
1303 (SAM_STAT_COMMAND_TERMINATED == psp->scsi_status)) in get_scsi_pt_result_category()
1305 else if (psp->scsi_status) in get_scsi_pt_result_category()
1314 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_resid() local
1316 return psp->resid; in get_scsi_pt_resid()
1323 const struct sg_pt_win32_scsi * psp = vp->implp; in get_pt_req_lengths() local
1326 if (psp->is_read && (psp->dxfer_len > 0)) in get_pt_req_lengths()
1327 *req_dinp = psp->dxfer_len; in get_pt_req_lengths()
1332 if ((! psp->is_read) && (psp->dxfer_len > 0)) in get_pt_req_lengths()
1333 *req_doutp = psp->dxfer_len; in get_pt_req_lengths()
1343 const struct sg_pt_win32_scsi * psp = vp->implp; in get_pt_actual_lengths() local
1346 if (psp->is_read && (psp->dxfer_len > 0)) in get_pt_actual_lengths()
1347 *act_dinp = psp->dxfer_len - psp->resid; in get_pt_actual_lengths()
1352 if ((! psp->is_read) && (psp->dxfer_len > 0)) in get_pt_actual_lengths()
1353 *act_doutp = psp->dxfer_len - psp->resid; in get_pt_actual_lengths()
1363 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_status_response() local
1365 if (NULL == psp) in get_scsi_pt_status_response()
1367 return psp->nvme_direct ? (int)psp->nvme_status : psp->scsi_status; in get_scsi_pt_status_response()
1373 const struct sg_pt_win32_scsi * psp = vp->implp; in get_pt_result() local
1375 if (NULL == psp) in get_pt_result()
1377 return psp->nvme_direct ? psp->nvme_result : (uint32_t)psp->scsi_status; in get_pt_result()
1383 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_sense_len() local
1386 len = psp->sense_len - psp->sense_resid; in get_scsi_pt_sense_len()
1393 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_sense_buf() local
1395 return psp->sensep; in get_scsi_pt_sense_buf()
1418 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_transport_err() local
1420 return psp->transport_err; in get_scsi_pt_transport_err()
1426 struct sg_pt_win32_scsi * psp = vp->implp; in set_scsi_pt_transport_err() local
1428 psp->transport_err = err; in set_scsi_pt_transport_err()
1434 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_os_err() local
1436 return psp->os_err; in get_scsi_pt_os_err()
1442 const struct sg_pt_win32_scsi * psp = vp->implp; in pt_device_is_nvme() local
1444 return psp ? psp->is_nvme : false; in pt_device_is_nvme()
1453 const struct sg_pt_win32_scsi * psp = vp->implp; in get_pt_nvme_nsid() local
1455 return psp->nvme_nsid; in get_pt_nvme_nsid()
1463 struct sg_pt_win32_scsi * psp = (struct sg_pt_win32_scsi *)vp->implp; in get_scsi_pt_transport_err_str() local
1465 if ((max_b_len < 2) || (NULL == psp) || (NULL == b)) { in get_scsi_pt_transport_err_str()
1470 return get_err_str(psp->transport_err, max_b_len, b); in get_scsi_pt_transport_err_str()
1476 const struct sg_pt_win32_scsi * psp = vp->implp; in get_scsi_pt_os_err_str() local
1479 cp = safe_strerror(psp->os_err); in get_scsi_pt_os_err_str()
1489 mk_sense_asc_ascq(struct sg_pt_win32_scsi * psp, int sk, int asc, int ascq, in mk_sense_asc_ascq() argument
1492 bool dsense = psp->dev_statp->scsi_dsense; in mk_sense_asc_ascq()
1493 int slen = psp->sense_len; in mk_sense_asc_ascq()
1495 uint8_t * sbp = (uint8_t *)psp->sensep; in mk_sense_asc_ascq()
1497 psp->scsi_status = SAM_STAT_CHECK_CONDITION; in mk_sense_asc_ascq()
1508 psp->sense_resid = (slen > n) ? (slen - n) : 0; in mk_sense_asc_ascq()
1517 mk_sense_from_nvme_status(struct sg_pt_win32_scsi * psp, int vb) in mk_sense_from_nvme_status() argument
1520 bool dsense = psp->dev_statp->scsi_dsense; in mk_sense_from_nvme_status()
1522 int slen = psp->sense_len; in mk_sense_from_nvme_status()
1524 uint8_t * sbp = (uint8_t *)psp->sensep; in mk_sense_from_nvme_status()
1526 ok = sg_nvme_status2scsi(psp->nvme_status, &sstatus, &sk, &asc, &ascq); in mk_sense_from_nvme_status()
1534 psp->scsi_status = sstatus; in mk_sense_from_nvme_status()
1545 psp->sense_resid = (slen > n) ? slen - n : 0; in mk_sense_from_nvme_status()
1548 if (dsense && (psp->nvme_status > 0)) in mk_sense_from_nvme_status()
1550 psp->nvme_status); in mk_sense_from_nvme_status()
1558 mk_sense_invalid_fld(struct sg_pt_win32_scsi * psp, bool in_cdb, int in_byte, in mk_sense_invalid_fld() argument
1561 bool dsense = psp->dev_statp->scsi_dsense; in mk_sense_invalid_fld()
1563 int slen = psp->sense_len; in mk_sense_invalid_fld()
1564 uint8_t * sbp = (uint8_t *)psp->sensep; in mk_sense_invalid_fld()
1567 psp->scsi_status = SAM_STAT_CHECK_CONDITION; in mk_sense_invalid_fld()
1579 psp->sense_resid = (slen > n) ? (slen - n) : 0; in mk_sense_invalid_fld()
1612 nvme_identify(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in nvme_identify() argument
1640 psp->os_err = res; in nvme_identify()
1665 psp->transport_err = n; in nvme_identify()
1666 psp->os_err = EIO; /* simulate Unix error, */ in nvme_identify()
1674 res = -psp->os_err; in nvme_identify()
1681 if (0 == psp->nvme_nsid) { in nvme_identify()
1685 psp->nvme_nsid = 1; /* then its nsid must be 1 */ in nvme_identify()
1690 psp->nvme_status = 0; in nvme_identify()
1691 psp->nvme_result = in nvme_identify()
1704 nvme_get_features(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in nvme_get_features() argument
1730 psp->os_err = res; in nvme_get_features()
1753 psp->transport_err = n; in nvme_get_features()
1754 psp->os_err = EIO; /* simulate Unix error, */ in nvme_get_features()
1761 res = -psp->os_err; in nvme_get_features()
1769 psp->nvme_status = 0; in nvme_get_features()
1770 psp->nvme_result = in nvme_get_features()
1783 nvme_get_log_page(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in nvme_get_log_page() argument
1809 psp->os_err = res; in nvme_get_log_page()
1832 psp->transport_err = n; in nvme_get_log_page()
1833 psp->os_err = EIO; /* simulate Unix error, */ in nvme_get_log_page()
1840 res = -psp->os_err; in nvme_get_log_page()
1848 psp->nvme_status = 0; in nvme_get_log_page()
1849 psp->nvme_result = in nvme_get_log_page()
1862 nvme_real_pt(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in nvme_real_pt() argument
1871 uint32_t slen = psp->sense_len; in nvme_real_pt()
1873 uint8_t * sbp = psp->sensep; in nvme_real_pt()
1891 psp->os_err = res; in nvme_real_pt()
1931 psp->transport_err = n; in nvme_real_pt()
1932 psp->os_err = EIO; /* simulate Unix error, */ in nvme_real_pt()
1941 res = -psp->os_err; in nvme_real_pt()
1947 psp->nvme_status = 0x3ff & (neilp->Status.AsUshort >> 1); in nvme_real_pt()
1952 psp->nvme_result = protoCmdp->FixedProtocolReturnData; in nvme_real_pt()
1953 if (psp->nvme_direct && sbp && (slen > 3)) { in nvme_real_pt()
1957 psp->sense_resid = (slen > 16) ? (slen - 16) : 0; in nvme_real_pt()
1958 sg_put_unaligned_le32(psp->nvme_result, sbp + SG_NVME_PT_CQ_DW0); in nvme_real_pt()
1970 __func__, cmdp[0], psp->nvme_status, psp->nvme_result); in nvme_real_pt()
1971 res = psp->nvme_status ? SG_LIB_NVME_STATUS : 0; in nvme_real_pt()
1979 do_nvme_admin_cmd(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in do_nvme_admin_cmd() argument
1988 psp->os_err = 0; in do_nvme_admin_cmd()
1989 psp->transport_err = 0; in do_nvme_admin_cmd()
1991 if (! psp->have_nvme_cmd) in do_nvme_admin_cmd()
1993 cmdp = psp->nvme_cmd; in do_nvme_admin_cmd()
1994 is_read = psp->is_read; in do_nvme_admin_cmd()
1995 dlen = psp->dxfer_len; in do_nvme_admin_cmd()
1996 dp = psp->dxferp; in do_nvme_admin_cmd()
2018 res = nvme_identify(psp, shp, cmdp, dp, dlen, vb); in do_nvme_admin_cmd()
2023 res = nvme_get_features(psp, shp, cmdp, dp, dlen, vb); in do_nvme_admin_cmd()
2028 res = nvme_get_log_page(psp, shp, cmdp, dp, dlen, vb); in do_nvme_admin_cmd()
2033 res = nvme_real_pt(psp, shp, cmdp, dp, dlen, is_read, time_secs, vb); in do_nvme_admin_cmd()
2069 do_nvme_admin_cmd(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in do_nvme_admin_cmd() argument
2077 uint32_t slen = psp->sense_len; in do_nvme_admin_cmd()
2078 uint8_t * sbp = psp->sensep; in do_nvme_admin_cmd()
2084 psp->os_err = 0; in do_nvme_admin_cmd()
2085 psp->transport_err = 0; in do_nvme_admin_cmd()
2087 if (! psp->have_nvme_cmd) in do_nvme_admin_cmd()
2089 cmdp = psp->nvme_cmd; in do_nvme_admin_cmd()
2090 is_read = psp->is_read; in do_nvme_admin_cmd()
2091 dlen = psp->dxfer_len; in do_nvme_admin_cmd()
2092 dp = psp->dxferp; in do_nvme_admin_cmd()
2118 psp->os_err = res; in do_nvme_admin_cmd()
2137 shp = get_open_pt_handle(psp, psp->dev_fd, vb > 1); in do_nvme_admin_cmd()
2139 res = -psp->os_err; /* -ENODEV */ in do_nvme_admin_cmd()
2147 psp->transport_err = n; in do_nvme_admin_cmd()
2148 psp->os_err = EIO; /* simulate Unix error, */ in do_nvme_admin_cmd()
2157 psp->nvme_status = 0x3ff & (pthru->CplEntry[3] >> 17); in do_nvme_admin_cmd()
2158 if (psp->nvme_status && (vb > 1)) { in do_nvme_admin_cmd()
2159 uint16_t s = psp->nvme_status; in do_nvme_admin_cmd()
2165 psp->nvme_result = sg_get_unaligned_le32(pthru->CplEntry + 0); in do_nvme_admin_cmd()
2167 psp->sense_resid = 0; in do_nvme_admin_cmd()
2168 if (psp->nvme_direct && sbp && (slen > 3)) { in do_nvme_admin_cmd()
2172 psp->sense_resid = (slen > 16) ? (slen - 16) : 0; in do_nvme_admin_cmd()
2187 res = -psp->os_err; in do_nvme_admin_cmd()
2189 } else if (psp->nvme_status) { in do_nvme_admin_cmd()
2218 sntl_check_enclosure_override(struct sg_pt_win32_scsi * psp, in sntl_check_enclosure_override() argument
2221 uint8_t * up = psp->nvme_id_ctlp; in sntl_check_enclosure_override()
2273 sntl_cache_identity(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_cache_identity() argument
2283 &psp->free_nvme_id_ctlp, false); in sntl_cache_identity()
2284 psp->nvme_id_ctlp = up; in sntl_cache_identity()
2289 cmdp = psp->nvme_cmd; in sntl_cache_identity()
2290 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_cache_identity()
2297 ret = do_nvme_admin_cmd(psp, shp, cmdp, up, 4096, is_read, time_secs, in sntl_cache_identity()
2300 sntl_check_enclosure_override(psp, shp, vb); in sntl_cache_identity()
2309 sntl_inq(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_inq() argument
2325 mk_sense_invalid_fld(psp, true, 1, 1, vb); in sntl_inq()
2328 if (NULL == psp->nvme_id_ctlp) { in sntl_inq()
2329 res = sntl_cache_identity(psp, shp, time_secs, vb); in sntl_inq()
2331 mk_sense_from_nvme_status(psp, vb); in sntl_inq()
2360 memcpy(inq_dout + 4, psp->nvme_id_ctlp + 4, 20); /* SN */ in sntl_inq()
2363 if ((psp->nvme_nsid > 0) && in sntl_inq()
2364 (psp->nvme_nsid < SG_NVME_BROADCAST_NSID)) { in sntl_inq()
2368 cmdp = psp->nvme_cmd; in sntl_inq()
2369 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_inq()
2371 sg_put_unaligned_le32(psp->nvme_nsid, in sntl_inq()
2378 res = do_nvme_admin_cmd(psp, shp, cmdp, nvme_id_ns, pg_sz, in sntl_inq()
2387 n = sg_make_vpd_devid_for_nvme(psp->nvme_id_ctlp, nvme_id_ns, in sntl_inq()
2427 mk_sense_invalid_fld(psp, true, 2, 7, vb); in sntl_inq()
2432 n = (n < psp->dxfer_len) ? n : psp->dxfer_len; in sntl_inq()
2433 psp->resid = psp->dxfer_len - n; in sntl_inq()
2436 memcpy(psp->dxferp, inq_dout, (n < 16 ? n : 16)); in sntl_inq()
2438 memcpy(psp->dxferp + 16, in sntl_inq()
2439 psp->nvme_id_ctlp, n - 16); in sntl_inq()
2441 memcpy(psp->dxferp, inq_dout, n); in sntl_inq()
2454 memcpy(inq_dout + 16, psp->nvme_id_ctlp + 24, 16); /* Prod <-- MN */ in sntl_inq()
2455 memcpy(inq_dout + 32, psp->nvme_id_ctlp + 64, 4); /* Rev <-- FR */ in sntl_inq()
2458 n = (n < psp->dxfer_len) ? n : psp->dxfer_len; in sntl_inq()
2459 psp->resid = psp->dxfer_len - n; in sntl_inq()
2461 memcpy(psp->dxferp, inq_dout, n); in sntl_inq()
2468 sntl_rluns(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_rluns() argument
2482 if (NULL == psp->nvme_id_ctlp) { in sntl_rluns()
2483 res = sntl_cache_identity(psp, shp, time_secs, vb); in sntl_rluns()
2485 mk_sense_from_nvme_status(psp, vb); in sntl_rluns()
2490 max_nsid = sg_get_unaligned_le32(psp->nvme_id_ctlp + 516); in sntl_rluns()
2502 num = (1 == psp->nvme_nsid) ? max_nsid : 0; in sntl_rluns()
2508 mk_sense_invalid_fld(psp, true, 2, 7, vb); in sntl_rluns()
2523 n = (n < psp->dxfer_len) ? n : psp->dxfer_len; in sntl_rluns()
2524 psp->resid = psp->dxfer_len - n; in sntl_rluns()
2526 memcpy(psp->dxferp, rl_doutp, n); in sntl_rluns()
2534 sntl_tur(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_tur() argument
2543 if (NULL == psp->nvme_id_ctlp) { in sntl_tur()
2544 res = sntl_cache_identity(psp, shp, time_secs, vb); in sntl_tur()
2546 mk_sense_from_nvme_status(psp, vb); in sntl_tur()
2551 cmdp = psp->nvme_cmd; in sntl_tur()
2552 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_tur()
2557 res = do_nvme_admin_cmd(psp, shp, cmdp, NULL, 0, false, time_secs, vb); in sntl_tur()
2560 mk_sense_from_nvme_status(psp, vb); in sntl_tur()
2565 psp->os_err = 0; in sntl_tur()
2566 psp->nvme_status = 0; in sntl_tur()
2568 pow_state = (0x1f & psp->nvme_result); in sntl_tur()
2573 mk_sense_asc_ascq(psp, SPC_SK_NOT_READY, LOW_POWER_COND_ON_ASC, 0, in sntl_tur()
2580 sntl_req_sense(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_req_sense() argument
2591 if (NULL == psp->nvme_id_ctlp) { in sntl_req_sense()
2592 res = sntl_cache_identity(psp, shp, time_secs, vb); in sntl_req_sense()
2594 mk_sense_from_nvme_status(psp, vb); in sntl_req_sense()
2601 cmdp = psp->nvme_cmd; in sntl_req_sense()
2602 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_req_sense()
2607 res = do_nvme_admin_cmd(psp, shp, cmdp, NULL, 0, false, time_secs, vb); in sntl_req_sense()
2610 mk_sense_from_nvme_status(psp, vb); in sntl_req_sense()
2615 psp->os_err = 0; in sntl_req_sense()
2616 psp->nvme_status = 0; in sntl_req_sense()
2618 psp->sense_resid = psp->sense_len; in sntl_req_sense()
2619 pow_state = (0x1f & psp->nvme_result); in sntl_req_sense()
2631 n = (n < psp->dxfer_len) ? n : psp->dxfer_len; in sntl_req_sense()
2632 psp->resid = psp->dxfer_len - n; in sntl_req_sense()
2634 memcpy(psp->dxferp, rs_dout, n); in sntl_req_sense()
2639 sntl_mode_ss(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_mode_ss() argument
2650 if (NULL == psp->nvme_id_ctlp) { in sntl_mode_ss()
2651 res = sntl_cache_identity(psp, shp, time_secs, vb); in sntl_mode_ss()
2653 mk_sense_from_nvme_status(psp, vb); in sntl_mode_ss()
2659 len = psp->dxfer_len; in sntl_mode_ss()
2660 bp = psp->dxferp; in sntl_mode_ss()
2663 psp->resid = (n >= 0) ? len - n : len; in sntl_mode_ss()
2667 len = psp->dxfer_len; in sntl_mode_ss()
2668 bp = psp->dxferp; in sntl_mode_ss()
2672 sntl_check_enclosure_override(psp, shp, vb); /* ENC_OV changed */ in sntl_mode_ss()
2680 mk_sense_invalid_fld(psp, true, sntl_result.in_byte, in_bit, in sntl_mode_ss()
2683 mk_sense_invalid_fld(psp, false, sntl_result.in_byte, in_bit, in sntl_mode_ss()
2686 mk_sense_asc_ascq(psp, sntl_result.sk, sntl_result.asc, in sntl_mode_ss()
2700 sntl_senddiag(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_senddiag() argument
2716 cmdp = psp->nvme_cmd; in sntl_senddiag()
2718 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_senddiag()
2721 sg_put_unaligned_le32(psp->nvme_nsid, cmdp + SG_NVME_PT_NSID); in sntl_senddiag()
2737 mk_sense_invalid_fld(psp, true, 1, 7, vb); in sntl_senddiag()
2741 res = do_nvme_admin_cmd(psp, shp, cmdp, NULL, 0, false, time_secs, in sntl_senddiag()
2745 mk_sense_from_nvme_status(psp, vb); in sntl_senddiag()
2752 dout_len = psp->dxfer_len; in sntl_senddiag()
2755 mk_sense_invalid_fld(psp, true, 3, 7, vb); in sntl_senddiag()
2762 mk_sense_invalid_fld(psp, true, 3, 7, vb); in sntl_senddiag()
2782 dop = psp->dxferp; in sntl_senddiag()
2786 (uint64_t)(sg_uintptr_t)psp->dxferp); in sntl_senddiag()
2797 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_senddiag()
2811 res = do_nvme_admin_cmd(psp, shp, cmdp, dop, n, false, time_secs, vb); in sntl_senddiag()
2814 mk_sense_from_nvme_status(psp, vb); in sntl_senddiag()
2827 sntl_recvdiag(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_recvdiag() argument
2843 din_len = psp->dxfer_len; in sntl_recvdiag()
2845 dip = psp->dxferp; in sntl_recvdiag()
2849 (uint64_t)(sg_uintptr_t)psp->dxferp); in sntl_recvdiag()
2856 cmdp = psp->nvme_cmd; in sntl_recvdiag()
2857 memset(cmdp, 0, sizeof(psp->nvme_cmd)); in sntl_recvdiag()
2872 res = do_nvme_admin_cmd(psp, shp, cmdp, dip, n, true, time_secs, vb); in sntl_recvdiag()
2875 mk_sense_from_nvme_status(psp, vb); in sntl_recvdiag()
2880 psp->resid = din_len - n; in sntl_recvdiag()
2890 sntl_rep_opcodes(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_rep_opcodes() argument
2912 mk_sense_invalid_fld(psp, true, 6, -1, vb); in sntl_rep_opcodes()
2956 mk_sense_invalid_fld(psp, true, 2, 2, vb); in sntl_rep_opcodes()
2962 mk_sense_invalid_fld(psp, true, 4, -1, vb); in sntl_rep_opcodes()
2992 mk_sense_invalid_fld(psp, true, 2, 2, vb); in sntl_rep_opcodes()
2998 psp->resid = psp->dxfer_len - len; in sntl_rep_opcodes()
3000 memcpy(psp->dxferp, arr, len); in sntl_rep_opcodes()
3006 sntl_rep_tmfs(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in sntl_rep_tmfs() argument
3020 mk_sense_invalid_fld(psp, true, 6, -1, vb); in sntl_rep_tmfs()
3032 psp->resid = psp->dxfer_len - len; in sntl_rep_tmfs()
3034 memcpy(psp->dxferp, arr, len); in sntl_rep_tmfs()
3044 nvme_pt(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in nvme_pt() argument
3052 if (psp->have_nvme_cmd) { in nvme_pt()
3053 cdbp = psp->nvme_cmd; in nvme_pt()
3055 psp->nvme_direct = true; in nvme_pt()
3057 if (psp->swb_d.spt.CdbLength > 0) { in nvme_pt()
3058 cdbp = psp->swb_d.spt.Cdb; in nvme_pt()
3059 cmd_len = psp->swb_d.spt.CdbLength; in nvme_pt()
3061 psp->nvme_direct = false; in nvme_pt()
3064 if (psp->swb_i.spt.CdbLength > 0) { in nvme_pt()
3065 cdbp = psp->swb_i.spt.Cdb; in nvme_pt()
3066 cmd_len = psp->swb_i.spt.CdbLength; in nvme_pt()
3068 psp->nvme_direct = false; in nvme_pt()
3079 __func__, cdbp[0], cmd_len, shp->dname, psp->dxfer_len); in nvme_pt()
3084 return sntl_inq(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3086 return sntl_rluns(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3088 return sntl_tur(psp, shp, time_secs, vb); in nvme_pt()
3090 return sntl_req_sense(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3092 return sntl_senddiag(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3094 return sntl_recvdiag(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3097 return sntl_mode_ss(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3101 return sntl_rep_opcodes(psp, shp, cdbp, time_secs, in nvme_pt()
3104 return sntl_rep_tmfs(psp, shp, cdbp, time_secs, vb); in nvme_pt()
3114 mk_sense_asc_ascq(psp, SPC_SK_ILLEGAL_REQUEST, INVALID_OPCODE, in nvme_pt()
3119 if(psp->dxfer_len > 0) { in nvme_pt()
3120 uint8_t * cmdp = psp->nvme_cmd; in nvme_pt()
3122 sg_put_unaligned_le32(psp->dxfer_len, cmdp + SG_NVME_PT_DATA_LEN); in nvme_pt()
3123 sg_put_unaligned_le64((uint64_t)(sg_uintptr_t)psp->dxferp, in nvme_pt()
3127 psp->dxfer_len, psp->dxferp); in nvme_pt()
3129 return do_nvme_admin_cmd(psp, shp, NULL, NULL, 0, true, time_secs, vb); in nvme_pt()
3135 nvme_pt(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp, in nvme_pt() argument
3140 if (psp) { ; } /* suppress warning */ in nvme_pt()