35 #elif defined(__linux__) || defined(__APPLE__)
36 #include <sys/ioctl.h>
44 #define ROUND_TO_ULONG(x) ni_logan_round_up(x,sizeof(uint32_t))
59 int32_t *p_instance_id)
78 hw_id, *p_instance_id);
85 hw_id, *p_instance_id);
114 int32_t ni_logan_nvme_send_admin_pass_through_command(ni_device_handle_t handle,
115 ni_logan_nvme_passthrough_cmd_t *p_cmd)
137 #ifndef XCODER_SIM_ENABLED
138 return ioctl(handle, NVME_IOCTL_ADMIN_CMD, p_cmd);
151 int32_t ni_logan_nvme_send_io_pass_through_command(ni_device_handle_t handle,
152 ni_logan_nvme_passthrough_cmd_t * p_cmd)
175 #ifndef XCODER_SIM_ENABLED
176 return ioctl(handle, NVME_IOCTL_IO_CMD, p_cmd);
186 #define ROUND_TO_DWORD_PTR(x) ni_logan_round_up(x,sizeof(PDWORD))
205 LPTSTR p_scsi_path =
"\\\\.\\PHYSICALDRIVE";
206 LPCTSTR p_format =
"%s%d";
207 PUCHAR p_buffer = NULL;
209 CHAR firmware_revision[9] = { 0 };
210 int device_count = 0;
214 CHAR serial_num[21] = { 0 };
215 CHAR model_name[41] = { 0 };
227 memset(p_buffer, 0, data_len);
229 if (NI_INVALID_EVENT_HANDLE == event_handle)
235 for (scsi_port = 0; scsi_port < max_handles; scsi_port++)
237 wsprintf(port_name_buffer, p_format, p_scsi_path, scsi_port);
238 HANDLE handle = CreateFile(port_name_buffer, GENERIC_READ | GENERIC_WRITE,
239 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
240 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
241 if (INVALID_HANDLE_VALUE == handle)
247 ZeroMemory(p_buffer, data_len);
248 rc = ni_logan_nvme_get_identity(handle, event_handle, p_buffer);
252 ni_log(
NI_LOG_INFO,
"Identity information retrieved from the device at port %s\n",
262 memset(firmware_revision, 0,
sizeof(firmware_revision));
263 memcpy(firmware_revision, p_ni_logan_id_data->
ai8Fr,
sizeof(p_ni_logan_id_data->
ai8Fr));
264 firmware_revision[
sizeof(p_ni_logan_id_data->
ai8Fr)] = 0;
266 memset(model_name, 0,
sizeof(model_name));
267 memcpy(model_name, p_ni_logan_id_data->
ai8Mn,
sizeof(p_ni_logan_id_data->
ai8Mn));
268 model_name[
sizeof(p_ni_logan_id_data->
ai8Mn)] = 0;
270 memset(serial_num, 0,
sizeof(serial_num));
271 memcpy(serial_num, p_ni_logan_id_data->
ai8Sn,
sizeof(p_ni_logan_id_data->
ai8Sn));
272 serial_num[
sizeof(p_ni_logan_id_data->
ai8Sn)] = 0;
278 "port %s\n\n", model_name, port_name_buffer);
293 "ret=%d\n\n", port_name_buffer ,retval);
306 "%d \n\n", device_count);
324 uint64_t lba_low = (lba & 0x3FFFF);
331 "(512B-aligned), session ID:%u\n", lba, (lba<<3), session_id);
346 (uint32_t)(lba_low & 0xF));
352 "(512B-aligned), session ID:%u\n", lba, (lba<<3), session_id);
367 (uint32_t)(lba_low & 0xF));
383 ni_event_handle_t event_handle,
391 uint32_t offset_l = (uint32_t)(offset & 0xFFFFFFFF);
392 DWORD offset_h = (DWORD)(offset >> 32);
397 "offset:0x%x,0x%x\n", __FUNCTION__, (int64_t) handle, (lba<<3),
398 data_len, offset_l, offset_h);
399 memset(&overlap, 0,
sizeof(overlap));
400 overlap.Offset = offset_l;
401 overlap.OffsetHigh = offset_h;
403 rc = ReadFile(handle, p_data, data_len, &data_len_, &overlap);
410 "event_handle=%" PRIx64
", lba=0x%x, len=%d, rc=%d\n",
411 __FUNCTION__, (int64_t)handle, (int64_t)event_handle,
412 (lba<<3), data_len, rc);
419 "event_handle=%" PRIx64
", lba=0x%x, len=%d, rc=%d\n",
420 __FUNCTION__, (int64_t) handle, (int64_t)event_handle,
421 (lba<<3), data_len, rc);
425 rc = pread(handle, p_data, data_len, offset);
427 __FUNCTION__, (int64_t)handle, (lba<<3), data_len, rc);
428 if ((rc < 0) || (rc != data_len))
431 "error=%d\n",
NI_ERRNO, __FUNCTION__,
455 ni_event_handle_t event_handle,
463 uint32_t offset_l = (uint32_t)(offset & 0xFFFFFFFF);
464 DWORD offset_h = (DWORD)(offset >> 32);
469 "offset:0x%x,0x%x\n", __FUNCTION__, (int64_t)handle, (lba<<3),
470 data_len,offset_l,offset_h);
472 memset(&overlap, 0,
sizeof(overlap));
473 overlap.Offset = offset_l;
474 overlap.OffsetHigh = offset_h;
476 rc = WriteFile(handle, p_data, data_len, &data_len_, &overlap);
483 "event_handle=%" PRIx64
", lba=0x%x, len=%d, rc=%d\n", __FUNCTION__,
484 (int64_t)handle, (int64_t)event_handle, (lba<<3), data_len, rc);
491 "event_handle=%" PRIx64
", lba=0x%x, len=%d, rc=%d\n",
492 __FUNCTION__, (int64_t)handle, (int64_t)event_handle, (lba<<3),
497 rc = pwrite(handle, p_data, data_len, offset);
499 __FUNCTION__, (int64_t) handle, (lba<<3), data_len, rc);
500 if ((rc < 0) || (rc != data_len))
503 "error=%d\n",
NI_ERRNO, __FUNCTION__,
@ NI_LOGAN_RETCODE_ERROR_INVALID_HANDLE
@ NI_LOGAN_RETCODE_NVME_SC_VPU_GENERAL_ERROR
@ NI_LOGAN_RETCODE_NVME_SC_RESOURCE_IS_EMPTY
@ NI_LOGAN_RETCODE_NVME_SC_REQUEST_IN_PROGRESS
@ NI_LOGAN_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_LOGAN_RETCODE_ERROR_MEM_ALOC
@ NI_LOGAN_RETCODE_SUCCESS
@ NI_LOGAN_RETCODE_FAILURE
@ NI_LOGAN_RETCODE_NVME_SC_VPU_RECOVERY
@ NI_LOGAN_RETCODE_NVME_SC_RESOURCE_UNAVAILABLE
@ NI_LOGAN_RETCODE_NVME_SC_VPU_RSRC_INSUFFICIENT
@ NI_LOGAN_RETCODE_NVME_SC_INVALID_PARAMETER
@ NI_LOGAN_RETCODE_NVME_SC_REQUEST_NOT_COMPLETED
@ NI_LOGAN_RETCODE_NVME_SC_RESOURCE_NOT_FOUND
#define NETINT_PCI_VENDOR_ID
#define NI_LOGAN_MAX_DEVICE_NAME_LEN
@ NI_LOGAN_DEVICE_TYPE_ENCODER
@ NI_LOGAN_DEVICE_TYPE_DECODER
void ni_logan_close_event(ni_event_handle_t event_handle)
Closes event and releases resources.
ni_event_handle_t ni_logan_create_event(void)
Create event and returnes event handle if successful.
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
void ni_logan_parse_lba(uint64_t lba)
parse the lba opcode, subtype, option It's called only if a I/O read/write fails, so just use the pri...
ni_logan_retcode_t ni_logan_nvme_check_error_code(int rc, ni_logan_nvme_admin_opcode_t opcode, uint32_t xcoder_type, uint32_t hw_id, int32_t *p_instance_id)
Check f/w error return code, and if it's a fatal one, terminate application's decoding/encoding proce...
int32_t ni_logan_nvme_send_write_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose a io write command.
int32_t ni_logan_nvme_send_read_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose a io read command.
Definitions related to working with NI T-408 over NVME interface.
#define NI_LOGAN_SUB_BIT_OFFSET
int ni_logan_nvme_enumerate_devices(char ni_logan_devices[][NI_LOGAN_MAX_DEVICE_NAME_LEN], int max_handles)
prints a report on detected nvme devices
#define NI_LOGAN_NVME_IDENTITY_CMD_DATA_SZ
#define NI_LOGAN_SESSION_ID_OFFSET
#define IDENTIFY_DEVICE_R
enum _ni_logan_nvme_admin_opcode ni_logan_nvme_admin_opcode_t
#define NI_LOGAN_INSTANCE_TYPE_OFFSET
#define START_OFFSET_IN_4K
#define NI_LOGAN_OP_BIT_OFFSET
int32_t ni_logan_posix_memalign(void **pp_memptr, size_t alignment, size_t size)
Exported utility routines definition.