39 #elif __linux__ || __APPLE__
41 #include <linux/types.h>
43 #include <sys/ioctl.h>
51 #define ROUND_TO_ULONG(x) ni_round_up(x,sizeof(uint32_t))
63 uint32_t hw_id, uint32_t *p_instance_id)
73 "Hardware %u %s experiencing insufficient resource (instance %u opcode %x)!\n",
74 hw_id, type_str, *p_instance_id, opcode);
78 "Hardware %u %s failed to open session due to invalid "
80 "parameter values given (instance %u opcode %x)!\n",
81 hw_id, type_str, *p_instance_id, opcode);
85 "Hardware %u %s got stream error (instance %u opcode %x)!\n",
86 hw_id, type_str, *p_instance_id, opcode);
90 "Error: Hardware %u %s doesn't support Interlaced video (instance %u opcode %x)!\n",
91 hw_id, type_str, *p_instance_id, opcode);
98 type_str, hw_id, *p_instance_id);
102 "Error rc = 0x%x, op = %02x, %s %u.%u terminating?\n", rc,
103 opcode, type_str, hw_id,
120 ni_nvme_send_admin_pass_through_command(ni_device_handle_t handle,
121 ni_nvme_passthrough_cmd_t *p_cmd)
143 return ioctl(handle, NVME_IOCTL_ADMIN_CMD, p_cmd);
153 int32_t ni_nvme_send_io_pass_through_command(ni_device_handle_t handle,
154 ni_nvme_passthrough_cmd_t *p_cmd)
176 return ioctl(handle, NVME_IOCTL_IO_CMD, p_cmd);
179 #endif //__linux__ defined
183 #define ROUND_TO_DWORD_PTR(x) ni_round_up(x,sizeof(PDWORD))
185 static ni_retcode_t ni_nvme_get_identity(HANDLE handle, HANDLE event_handle,
201 LPTSTR p_scsi_path =
"\\\\.\\PHYSICALDRIVE";
202 LPCTSTR p_format =
"%s%d";
203 PUCHAR p_buffer = NULL;
205 CHAR firmware_revision[8] = {0};
206 int device_count = 0;
210 CHAR serial_num[20] = {0};
211 CHAR model_name[40] = {0};
224 memset(p_buffer, 0, data_len);
225 ni_event_handle_t event_handle = NULL;
227 for (scsi_port = 0; scsi_port < max_handles; scsi_port++)
229 wsprintf(port_name_buffer, p_format, p_scsi_path, scsi_port);
231 CreateFile(port_name_buffer, GENERIC_READ | GENERIC_WRITE,
232 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
233 FILE_ATTRIBUTE_NORMAL, NULL);
234 if (INVALID_HANDLE_VALUE == handle)
241 ZeroMemory(p_buffer, data_len);
242 rc = ni_nvme_get_identity(handle, event_handle, p_buffer);
248 "Identity information retrieved from the device "
252 " VID: 0x%x \n SSVID: 0x%x \n",
260 memset(firmware_revision, 0,
sizeof(firmware_revision));
261 memcpy(firmware_revision, p_ni_id_data->
ai8Fr,
262 sizeof(firmware_revision));
263 firmware_revision[
sizeof(firmware_revision) - 1] = 0;
265 memset(model_name, 0,
sizeof(model_name));
266 memcpy(model_name, p_ni_id_data->
ai8Mn,
sizeof(model_name));
267 model_name[
sizeof(model_name) - 1] = 0;
269 memset(serial_num, 0,
sizeof(serial_num));
270 memcpy(serial_num, p_ni_id_data->
ai8Sn,
sizeof(serial_num));
271 serial_num[
sizeof(serial_num) - 1] = 0;
279 "NETINT %s NVMe video transcoder identified "
281 model_name, port_name_buffer);
282 strncpy(ni_devices[device_count++], port_name_buffer,
287 "Device at port %s %d is not a NETINT NVMe device\n",
296 "Device at port %s is not a NETINT NVMe device,ret=%d\n\n",
297 port_name_buffer, retval);
309 "Total Number of NETINT NVMe Transcoders identified: %d \n\n",
314 #endif //_WIN32 defined
316 #ifndef XCODER_IO_RW_ENABLED
325 ni_device_handle_t handle,
327 uint32_t data_len,
void *p_data,
336 rc = ni_nvme_get_identity(handle, NI_INVALID_EVENT_HANDLE, p_data);
341 ni_nvme_passthrough_cmd_t nvme_cmd = {0};
343 nvme_cmd.opcode = opcode;
344 nvme_cmd.cdw10 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw10);
345 nvme_cmd.cdw11 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw11);
346 nvme_cmd.cdw12 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw12);
347 nvme_cmd.cdw13 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw13);
348 nvme_cmd.cdw14 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw14);
349 nvme_cmd.cdw15 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw15);
350 nvme_cmd.addr = (__u64)ni_htonll((uintptr_t)p_data);
351 nvme_cmd.data_len = ni_htonl(data_len);
353 rc = ni_nvme_send_admin_pass_through_command(handle, &nvme_cmd);
355 *p_result = ni_htonl(nvme_cmd.result);
359 __func__, (int64_t)handle, (uint32_t)(*p_result), rc);
373 void *p_data, uint32_t *p_result)
379 ni_nvme_passthrough_cmd_t nvme_cmd;
382 memset(&nvme_cmd, 0,
sizeof(nvme_cmd));
383 nvme_cmd.opcode = opcode;
384 nvme_cmd.nsid = ni_htonl(1);
385 nvme_cmd.addr = (__u64)ni_htonll((uintptr_t)p_data);
386 nvme_cmd.data_len = ni_htonl(data_len);
387 nvme_cmd.cdw2 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw2);
388 nvme_cmd.cdw3 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw3);
389 nvme_cmd.cdw10 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw10);
390 nvme_cmd.cdw11 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw11);
391 nvme_cmd.cdw12 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw12);
392 nvme_cmd.cdw13 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw13);
393 nvme_cmd.cdw14 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw14);
394 nvme_cmd.cdw15 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw15);
396 rc = ni_nvme_send_io_pass_through_command(handle, &nvme_cmd);
400 *p_result = ni_htonl(nvme_cmd.result);
404 __func__, (int64_t)handle, (uint32_t)(*p_result), rc);
420 ni_device_handle_t handle,
422 uint32_t data_len,
void *p_data,
426 ni_nvme_passthrough_cmd_t nvme_cmd = {0};
428 nvme_cmd.opcode = opcode;
429 nvme_cmd.nsid = ni_htonl(1);
430 nvme_cmd.addr = (__u64)ni_htonll((uintptr_t)p_data);
431 nvme_cmd.data_len = ni_htonl(data_len);
432 nvme_cmd.cdw10 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw10);
433 nvme_cmd.cdw11 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw11);
434 nvme_cmd.cdw12 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw12);
435 nvme_cmd.cdw13 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw13);
436 nvme_cmd.cdw14 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw14);
437 nvme_cmd.cdw15 = (__u32)ni_htonl(p_ni_nvme_cmd->
cdw15);
439 rc = ni_nvme_send_admin_pass_through_command(handle, &nvme_cmd);
443 *p_result = ni_htonl(nvme_cmd.result);
446 handle, *p_result, rc);
450 #endif //__linux__ defined
464 uint64_t lba_low = (lba & 0x3FFFF);
466 uint16_t session_id = (uint16_t)(
471 "encoder lba:0x%" PRIx64
"(4K-aligned), 0x%" PRIx64
472 "(512B-aligned), session ID:%u\n",
473 lba, ((uint64_t)lba << 3), session_id);
483 "encoder ctrl command failed: op-0x%x, "
484 "subtype-0x%x, option-0x%x\n",
489 (uint32_t)(lba_low & 0xF));
495 "decoder lba:0x%" PRIx64
"(4K-aligned), 0x%" PRIx64
496 "(512B-aligned), session ID:%u\n",
497 lba, ((uint64_t)lba << 3), session_id);
507 "decoder ctrl command failed: op-0x%x, "
508 "subtype-0x%x, option-0x%x\n",
513 (uint32_t)(lba_low & 0xF));
529 ni_event_handle_t event_handle,
void *p_data,
530 uint32_t data_len, uint32_t lba)
542 uint32_t offset_l = (uint32_t)(offset & 0xFFFFFFFF);
543 DWORD offset_h = (DWORD)(offset >> 32);
546 "%s: handle=%" PRIx64
", lba=0x%lx, len=%d,offset:0x%x,0x%x\n",
547 __func__, (int64_t)handle, ((uint64_t)lba << 3), data_len, offset_l, offset_h);
548 memset(&overlap, 0,
sizeof(overlap));
549 overlap.Offset = offset_l;
550 overlap.OffsetHigh = offset_h;
553 rc = ReadFile(handle, p_data, data_len, &data_len_, &overlap);
559 "%s() ReadFile handle=%" PRIx64
", event_handle="
560 "%" PRIx64
", lba=0x%lx, len=%d, rc=%d\n",
561 __func__, (int64_t)handle, (int64_t)event_handle, ((uint64_t)lba << 3),
570 if (!handle || handle == NI_INVALID_DEVICE_HANDLE)
574 ni_log(
NI_LOG_ERROR,
"%s: ERROR: invalid parameters: handle=%" PRId32
"\n", __func__, handle);
581 "%s: Buffer not %d aligned = %p! Reading to aligned memory "
588 "ERROR %d: %s() alloc data buffer failed\n",
NI_ERRNO,
594 rc = pread(handle, p_buf, data_len, offset);
597 memcpy(p_data, p_buf, data_len);
603 rc = pread(handle, p_data, data_len, offset);
606 "%s: handle=%" PRIx64
607 ", offset 0x%lx, lba=0x%lx, len=%d, rc=%d\n",
608 __func__, (int64_t)handle, offset, ((uint64_t)lba << 3), data_len, rc);
609 if (rc < 0 || rc != data_len)
612 "ERROR %d: %s failed, lba=0x%lx, len=%u, rc=%d, error=%d\n",
635 ni_event_handle_t event_handle,
void *p_data,
636 uint32_t data_len, uint32_t lba)
648 uint32_t offset_l = (uint32_t)(offset & 0xFFFFFFFF);
649 DWORD offset_h = (DWORD)(offset >> 32);
654 "%s: handle=%" PRIx64
", lba=0x%lx, len=%d,offset:0x%x,0x%x\n",
655 __func__, (int64_t)handle, ((uint64_t)lba << 3), data_len, offset_l, offset_h);
657 memset(&overlap, 0,
sizeof(overlap));
658 overlap.Offset = offset_l;
659 overlap.OffsetHigh = offset_h;
661 rc = WriteFile(handle, p_data, data_len, &data_len_, &overlap);
667 "%s() WriteFile handle=%" PRIx64
", event_handle="
668 "%" PRIx64
", lba=0x%lx, len=%d, rc=%d\n",
669 __func__, (int64_t)handle, (int64_t)event_handle, ((uint64_t)lba << 3),
678 if (!handle || handle == NI_INVALID_DEVICE_HANDLE)
682 ni_log(
NI_LOG_ERROR,
"%s: ERROR: invalid parameters: handle=%" PRId32
"\n", __func__, handle);
689 "%s: Buffer not %d aligned = %p! Copying to aligned memory "
696 "ERROR %d: %s() alloc data buffer failed\n",
NI_ERRNO,
702 memcpy(p_buf, p_data, data_len);
703 rc = pwrite(handle, p_buf, data_len, offset);
709 rc = pwrite(handle, p_data, data_len, offset);
712 "%s: handle=%" PRIx64
", lba=0x%lx, len=%d, rc=%d\n", __func__,
713 (int64_t)handle, ((uint64_t)lba << 3), data_len, rc);
714 if ((rc < 0) || (rc != data_len))
717 "ERROR %d: %s failed, lba=0x%lx, len=%u, rc=%d, error=%d\n",