#include <caam_jr_pvt.h>
#include <caam_jr_log.h>
-/* RTA header files */
-#include <hw/desc/common.h>
-#include <hw/desc/algo.h>
-#include <hw/desc/ipsec.h>
-
/* Prefix path to sysfs directory where UIO device attributes are exported.
* Path for UIO device X is /sys/class/uio/uioX
*/
"%s/%s/%s", root, subdir, filename);
fd = open(absolute_file_name, O_RDONLY);
- SEC_ASSERT(fd > 0, fd, "Error opening file %s",
+ SEC_ASSERT(fd >= 0, fd, "Error opening file %s",
absolute_file_name);
/* read UIO device name from first line in file */
* kernel driver as well. No special return values are used.
*/
static int
-sec_uio_send_command(uint32_t uio_fd, int32_t uio_command)
+sec_uio_send_command(int uio_fd, int32_t uio_command)
{
int ret;
* @retval 0 for success
* @retval -1 value for error
*/
-uint32_t
-caam_jr_enable_irqs(uint32_t uio_fd)
+int
+caam_jr_enable_irqs(int uio_fd)
{
int ret;
* value that indicates an IRQ disable action into UIO file descriptor
* of this job ring.
*
- * @param [in] uio_fd UIO File descripto
+ * @param [in] uio_fd UIO File descriptor
* @retval 0 for success
* @retval -1 value for error
*
*/
-uint32_t
-caam_jr_disable_irqs(uint32_t uio_fd)
+int
+caam_jr_disable_irqs(int uio_fd)
{
int ret;
memset(uio_map_size_str, 0, sizeof(uio_map_size_str));
/* Compose string: /sys/class/uio/uioX */
- sprintf(uio_sys_root, "%s/%s%d", SEC_UIO_DEVICE_SYS_ATTR_PATH,
- "uio", uio_device_id);
+ snprintf(uio_sys_root, sizeof(uio_sys_root), "%s/%s%d",
+ SEC_UIO_DEVICE_SYS_ATTR_PATH, "uio", uio_device_id);
/* Compose string: maps/mapY */
- sprintf(uio_sys_map_subdir, "%s%d", SEC_UIO_DEVICE_SYS_MAP_ATTR,
- uio_map_id);
+ snprintf(uio_sys_map_subdir, sizeof(uio_sys_map_subdir), "%s%d",
+ SEC_UIO_DEVICE_SYS_MAP_ATTR, uio_map_id);
/* Read first (and only) line from file
* /sys/class/uio/uioX/maps/mapY/size
}
void
-free_job_ring(uint32_t uio_fd)
+free_job_ring(int uio_fd)
{
struct uio_job_ring *job_ring = NULL;
int i;
- if (!job_ring->uio_fd)
+ if (uio_fd == -1)
return;
for (i = 0; i < MAX_SEC_JOB_RINGS; i++) {
job_ring->jr_id, job_ring->uio_fd);
close(job_ring->uio_fd);
g_uio_jr_num--;
- job_ring->uio_fd = 0;
+ job_ring->uio_fd = -1;
if (job_ring->register_base_addr == NULL)
return;
job_ring->register_base_addr,
(unsigned long)job_ring->map_size, strerror(errno));
} else
- CAAM_JR_DEBUG(" JR UIO memory unmapped at %p",
- job_ring->register_base_addr);
+ CAAM_JR_DEBUG("JR UIO memory is unmapped");
+
job_ring->register_base_addr = NULL;
}
int i;
for (i = 0; i < MAX_SEC_JOB_RINGS; i++) {
- if (g_uio_job_ring[i].uio_fd == 0) {
+ if (g_uio_job_ring[i].uio_fd == -1) {
job_ring = &g_uio_job_ring[i];
g_uio_jr_num++;
break;
/* Find UIO device created by SEC kernel driver for this job ring. */
memset(uio_device_file_name, 0, sizeof(uio_device_file_name));
-
- sprintf(uio_device_file_name, "%s%d", SEC_UIO_DEVICE_FILE_NAME,
- job_ring->uio_minor_number);
+ snprintf(uio_device_file_name, sizeof(uio_device_file_name), "%s%d",
+ SEC_UIO_DEVICE_FILE_NAME, job_ring->uio_minor_number);
/* Open device file */
job_ring->uio_fd = open(uio_device_file_name, O_RDWR);
- SEC_ASSERT(job_ring->uio_fd > 0, NULL,
+ SEC_ASSERT(job_ring->uio_fd >= 0, NULL,
"Failed to open UIO device file for job ring %d",
job_ring->jr_id);
ret = file_read_first_line(SEC_UIO_DEVICE_SYS_ATTR_PATH,
dir->d_name, "name", uio_name);
CAAM_JR_INFO("sec device uio name: %s", uio_name);
- SEC_ASSERT(ret == 0, -1, "file_read_first_line failed");
+ if (ret != 0) {
+ CAAM_JR_ERR("file_read_first_line failed\n");
+ closedir(d);
+ return -1;
+ }
if (file_name_match_extract(uio_name,
SEC_UIO_DEVICE_NAME,
/* I need to close the fd after shutdown UIO commands need to be
* sent using the fd
*/
- if (job_ring->uio_fd != 0) {
+ if (job_ring->uio_fd != -1) {
CAAM_JR_INFO(
"Closed device file for job ring %d , fd = %d",
job_ring->jr_id, job_ring->uio_fd);
close(job_ring->uio_fd);
+ job_ring->uio_fd = -1;
}
}
return 0;
}
+
+void
+sec_uio_job_rings_init(void)
+{
+ int i;
+
+ for (i = 0; i < MAX_SEC_JOB_RINGS; i++)
+ g_uio_job_ring[i].uio_fd = -1;
+}