sg_pt.h (sdparm-1.11.tgz) | : | sg_pt.h (sdparm-1.12.tgz) | ||
---|---|---|---|---|
#ifndef SG_PT_H | #ifndef SG_PT_H | |||
#define SG_PT_H | #define SG_PT_H | |||
/* | /* | |||
* Copyright (c) 2005-2019 Douglas Gilbert. | * Copyright (c) 2005-2020 Douglas Gilbert. | |||
* All rights reserved. | * All rights reserved. | |||
* Use of this source code is governed by a BSD-style | * Use of this source code is governed by a BSD-style | |||
* license that can be found in the BSD_LICENSE file. | * license that can be found in the BSD_LICENSE file. | |||
* | * | |||
* SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | |||
*/ | */ | |||
#include <stdint.h> | #include <stdint.h> | |||
#include <stdbool.h> | #include <stdbool.h> | |||
skipping to change at line 96 | skipping to change at line 96 | |||
/* Valid file handles (which is the return value) are >= 0 . Returns -1 | /* Valid file handles (which is the return value) are >= 0 . Returns -1 | |||
* if there is no valid file handle. */ | * if there is no valid file handle. */ | |||
int get_pt_file_handle(const struct sg_pt_base * objp); | int get_pt_file_handle(const struct sg_pt_base * objp); | |||
/* Clear state information held in *objp . This allows this object to be | /* Clear state information held in *objp . This allows this object to be | |||
* used to issue more than one SCSI command. The dev_fd is remembered. | * used to issue more than one SCSI command. The dev_fd is remembered. | |||
* Use set_pt_file_handle() to change dev_fd. */ | * Use set_pt_file_handle() to change dev_fd. */ | |||
void clear_scsi_pt_obj(struct sg_pt_base * objp); | void clear_scsi_pt_obj(struct sg_pt_base * objp); | |||
/* Partially clear state information held in *objp . Any error settings and | ||||
* the data-in and data-out settings are cleared. So dev_fd, cdb and sense | ||||
* settings are kept. */ | ||||
void partial_clear_scsi_pt_obj(struct sg_pt_base * objp); | ||||
/* Set the CDB (command descriptor block). May also be a NVMe Admin command | /* Set the CDB (command descriptor block). May also be a NVMe Admin command | |||
* which will be 64 bytes long. | * which will be 64 bytes long. | |||
* | * | |||
* Note that the sg_cmds_is_nvme() function found in sg_cmds_basic.h can be | * Note that the sg_cmds_is_nvme() function found in sg_cmds_basic.h can be | |||
* called after this function to "guess" which command set the given command | * called after this function to "guess" which command set the given command | |||
* belongs to. */ | * belongs to. It is valid to supply a cdb value of NULL. */ | |||
void set_scsi_pt_cdb(struct sg_pt_base * objp, const uint8_t * cdb, | void set_scsi_pt_cdb(struct sg_pt_base * objp, const uint8_t * cdb, | |||
int cdb_len); | int cdb_len); | |||
/* Set the sense buffer and the maximum length of that buffer. For NVMe | /* Set the sense buffer and the maximum length of that buffer. For NVMe | |||
* commands this "sense" buffer will receive the 4 DWORDs of from the | * commands this "sense" buffer will receive the 4 DWORDs of from the | |||
* completion queue. */ | * completion queue. It is valid to supply a sense value of NULL. */ | |||
void set_scsi_pt_sense(struct sg_pt_base * objp, uint8_t * sense, | void set_scsi_pt_sense(struct sg_pt_base * objp, uint8_t * sense, | |||
int max_sense_len); | int max_sense_len); | |||
/* Set a pointer and length to be used for data transferred from device */ | /* Set a pointer and length to be used for data transferred from device */ | |||
void set_scsi_pt_data_in(struct sg_pt_base * objp, /* from device */ | void set_scsi_pt_data_in(struct sg_pt_base * objp, /* from device */ | |||
uint8_t * dxferp, int dxfer_ilen); | uint8_t * dxferp, int dxfer_ilen); | |||
/* Set a pointer and length to be used for data transferred to device */ | /* Set a pointer and length to be used for data transferred to device */ | |||
void set_scsi_pt_data_out(struct sg_pt_base * objp, /* to device */ | void set_scsi_pt_data_out(struct sg_pt_base * objp, /* to device */ | |||
const uint8_t * dxferp, int dxfer_olen); | const uint8_t * dxferp, int dxfer_olen); | |||
skipping to change at line 145 | skipping to change at line 150 | |||
* are given, use the pass-through default. */ | * are given, use the pass-through default. */ | |||
#define SCSI_PT_FLAGS_QUEUE_AT_TAIL 0x10 | #define SCSI_PT_FLAGS_QUEUE_AT_TAIL 0x10 | |||
#define SCSI_PT_FLAGS_QUEUE_AT_HEAD 0x20 | #define SCSI_PT_FLAGS_QUEUE_AT_HEAD 0x20 | |||
/* Set (potentially OS dependent) flags for pass-through mechanism. | /* Set (potentially OS dependent) flags for pass-through mechanism. | |||
* Apart from contradictions, flags can be OR-ed together. */ | * Apart from contradictions, flags can be OR-ed together. */ | |||
void set_scsi_pt_flags(struct sg_pt_base * objp, int flags); | void set_scsi_pt_flags(struct sg_pt_base * objp, int flags); | |||
#define SCSI_PT_DO_START_OK 0 | #define SCSI_PT_DO_START_OK 0 | |||
#define SCSI_PT_DO_BAD_PARAMS 1 | #define SCSI_PT_DO_BAD_PARAMS 1 | |||
#define SCSI_PT_DO_TIMEOUT 2 | #define SCSI_PT_DO_TIMEOUT 2 | |||
#define SCSI_PT_DO_NOT_SUPPORTED 4 | ||||
#define SCSI_PT_DO_NVME_STATUS 48 /* == SG_LIB_NVME_STATUS */ | #define SCSI_PT_DO_NVME_STATUS 48 /* == SG_LIB_NVME_STATUS */ | |||
/* If OS error prior to or during command submission then returns negated | /* If OS error prior to or during command submission then returns negated | |||
* error value (e.g. Unix '-errno'). This includes interrupted system calls | * error value (e.g. Unix '-errno'). This includes interrupted system calls | |||
* (e.g. by a signal) in which case -EINTR would be returned. Note that | * (e.g. by a signal) in which case -EINTR would be returned. Note that | |||
* system call errors also can be fetched with get_scsi_pt_os_err(). | * system call errors also can be fetched with get_scsi_pt_os_err(). | |||
* Return 0 if okay (i.e. at the very least: command sent). Positive | * Return 0 if okay (i.e. at the very least: command sent). Positive | |||
* return values are errors (see SCSI_PT_DO_* defines). If a file descriptor | * return values are errors (see SCSI_PT_DO_* defines). If a file descriptor | |||
* has already been provided by construct_scsi_pt_obj_with_fd() then the | * has already been provided by construct_scsi_pt_obj_with_fd() then the | |||
* given 'fd' can be -1 or the same value as given to the constructor. */ | * given 'fd' can be -1 or the same value as given to the constructor. */ | |||
int do_scsi_pt(struct sg_pt_base * objp, int fd, int timeout_secs, | int do_scsi_pt(struct sg_pt_base * objp, int fd, int timeout_secs, | |||
int verbose); | int verbose); | |||
/* NVMe Admin commands can be sent directly to do_scsi_pt(). Unfortunately | ||||
* NVMe has at least one other command set: "NVM" to access user data and | ||||
* the opcodes in the NVM command set overlap with the Admin command set. | ||||
* So NVMe Admin commands should be sent do_scsi_pt() while NVMe "NVM" | ||||
* commands should be sent to this function. No SCSI commands should be | ||||
* sent to this function. Currently submq is not implemented and all | ||||
* submitted NVM commands are sent on queue 0, the same queue use for | ||||
* Admin commands. The return values follow the same pattern as do_scsi_pt(), | ||||
* with 0 returned being good. The NVMe device file descriptor must either | ||||
* be given to the obj constructor, or a prior set_pt_file_handle() call. */ | ||||
int do_nvm_pt(struct sg_pt_base * objp, int submq, int timeout_secs, | ||||
int verbose); | ||||
#define SCSI_PT_RESULT_GOOD 0 | #define SCSI_PT_RESULT_GOOD 0 | |||
#define SCSI_PT_RESULT_STATUS 1 /* other than GOOD and CHECK CONDITION */ | #define SCSI_PT_RESULT_STATUS 1 /* other than GOOD and CHECK CONDITION */ | |||
#define SCSI_PT_RESULT_SENSE 2 | #define SCSI_PT_RESULT_SENSE 2 | |||
#define SCSI_PT_RESULT_TRANSPORT_ERR 3 | #define SCSI_PT_RESULT_TRANSPORT_ERR 3 | |||
#define SCSI_PT_RESULT_OS_ERR 4 | #define SCSI_PT_RESULT_OS_ERR 4 | |||
/* This function, called soon after do_scsi_pt(), returns one of the above | /* This function, called soon after do_scsi_pt(), returns one of the above | |||
* result categories. The highest numbered applicable category is returned. | * result categories. The highest numbered applicable category is returned. | |||
* | * | |||
* Note that the sg_cmds_process_resp() function found in sg_cmds_basic.h | * Note that the sg_cmds_process_resp() function found in sg_cmds_basic.h | |||
* is useful for processing SCSI command responses. | * is useful for processing SCSI command responses. | |||
skipping to change at line 190 | skipping to change at line 209 | |||
/* Returns SCSI status value (from device that received the command). If an | /* Returns SCSI status value (from device that received the command). If an | |||
* NVMe command was issued directly (i.e. through do_scsi_pt() then return | * NVMe command was issued directly (i.e. through do_scsi_pt() then return | |||
* NVMe status (i.e. ((SCT << 8) | SC)). If problem returns -1. */ | * NVMe status (i.e. ((SCT << 8) | SC)). If problem returns -1. */ | |||
int get_scsi_pt_status_response(const struct sg_pt_base * objp); | int get_scsi_pt_status_response(const struct sg_pt_base * objp); | |||
/* Returns SCSI status value or, if NVMe command given to do_scsi_pt(), | /* Returns SCSI status value or, if NVMe command given to do_scsi_pt(), | |||
* then returns NVMe result (i.e. DWord(0) from completion queue). If | * then returns NVMe result (i.e. DWord(0) from completion queue). If | |||
* 'objp' is NULL then returns 0xffffffff. */ | * 'objp' is NULL then returns 0xffffffff. */ | |||
uint32_t get_pt_result(const struct sg_pt_base * objp); | uint32_t get_pt_result(const struct sg_pt_base * objp); | |||
/* These two get functions should just echo what has been given to | ||||
* set_scsi_pt_cdb(). If it has not been called or clear_scsi_pt_obj() | ||||
* has been called then return 0 and NULL respectively. */ | ||||
int get_scsi_pt_cdb_len(const struct sg_pt_base * objp); | ||||
uint8_t * get_scsi_pt_cdb_buf(const struct sg_pt_base * objp); | ||||
/* Actual sense length returned. If sense data is present but | /* Actual sense length returned. If sense data is present but | |||
actual sense length is not known, return 'max_sense_len' */ | actual sense length is not known, return 'max_sense_len' */ | |||
int get_scsi_pt_sense_len(const struct sg_pt_base * objp); | int get_scsi_pt_sense_len(const struct sg_pt_base * objp); | |||
uint8_t * get_scsi_pt_sense_buf(const struct sg_pt_base * objp); | uint8_t * get_scsi_pt_sense_buf(const struct sg_pt_base * objp); | |||
/* If not available return 0 (for success). */ | /* If not available return 0 (for success). */ | |||
int get_scsi_pt_os_err(const struct sg_pt_base * objp); | int get_scsi_pt_os_err(const struct sg_pt_base * objp); | |||
char * get_scsi_pt_os_err_str(const struct sg_pt_base * objp, int max_b_len, | char * get_scsi_pt_os_err_str(const struct sg_pt_base * objp, int max_b_len, | |||
char * b); | char * b); | |||
End of changes. 7 change blocks. | ||||
3 lines changed or deleted | 28 lines changed or added |