static int qat_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) { unsigned int retVal = 1; CpaStatus status = CPA_STATUS_SUCCESS; int flags = 0; int fd = 0; switch (cmd) { case QAT_CMD_POLL: if (qatInstanceHandles == NULL) { /* * It is possible to call this ctrl function while the engine is * in a state where there are no instances available. This * happens for example immediately when the engine is waiting * for get_next_inst() to be called. * * To avoid this condition we call get_next_inst() */ get_next_inst(); BREAK_IF(qatInstanceHandles == NULL, "POLL failed as no instances are available\n"); } BREAK_IF(!engine_inited, "POLL failed as engine is not initialized\n"); BREAK_IF(!enable_external_polling, "POLL failed as external polling is not enabled\n"); BREAK_IF(p == NULL, "POLL failed as the input parameter was NULL\n"); *(int *)p = (int)poll_instances(); break; case QAT_CMD_ENABLE_EXTERNAL_POLLING: BREAK_IF(engine_inited, \ "ENABLE_EXTERNAL_POLLING failed as the engine is already initialized\n"); DEBUG("[%s] Enabled external polling\n", __func__); enable_external_polling = 1; break; case QAT_CMD_GET_EXTERNAL_POLLING_FD: BREAK_IF(!enable_event_driven_polling || !enable_external_polling, \ "GET_EXTERNAL_POLLING_FD failed as this engine message is only supported \ when running in Event Driven Mode with External Polling enabled\n"); if (qatInstanceHandles == NULL) { get_next_inst(); BREAK_IF(qatInstanceHandles == NULL, \ "GET_EXTERNAL_POLLING_FD failed as no instances are available\n"); } BREAK_IF(!engine_inited, \ "GET_EXTERNAL_POLLING_FD failed as the engine is not initialized\n"); BREAK_IF(p == NULL, "GET_EXTERNAL_POLLING_FD failed as the input parameter was NULL\n"); BREAK_IF(i >= numInstances, \ "GET_EXTERNAL_POLLING_FD failed as the instance does not exist\n"); /* Get the file descriptor for the instance */ status = icp_sal_CyGetFileDescriptor(qatInstanceHandles[i], &fd); BREAK_IF(CPA_STATUS_FAIL == status, \ "GET_EXTERNAL_POLLING_FD failed as there was an error retrieving the fd\n"); /* Make the file descriptor non-blocking */ flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK); DEBUG("[%s] External polling FD for instance[%d] = %d\n", __func__, i, fd); *(int *)p = fd; break; case QAT_CMD_ENABLE_EVENT_DRIVEN_POLLING_MODE: DEBUG("[%s] Enabled event driven polling mode\n", __func__); BREAK_IF(engine_inited, \ "ENABLE_EVENT_DRIVEN_POLLING_MODE failed as the engine is already initialized\n"); enable_event_driven_polling = 1; break; case QAT_CMD_DISABLE_EVENT_DRIVEN_POLLING_MODE: DEBUG("[%s] Disabled event driven polling mode\n", __func__); BREAK_IF(engine_inited, \ "DISABLE_EVENT_DRIVEN_POLLING_MODE failed as the engine is already initialized\n"); enable_event_driven_polling = 0; break; case QAT_CMD_SET_INSTANCE_FOR_THREAD: if (qatInstanceHandles == NULL) { get_next_inst(); BREAK_IF(qatInstanceHandles == NULL, \ "SET_INSTANCE_FOR_THREAD failed as no instances are available\n"); } BREAK_IF(!engine_inited, \ "SET_INSTANCE_FOR_THREAD failed as the engine is not initialized\n"); DEBUG("[%s] Set instance for thread = %d\n", __func__, i); qat_set_instance_for_thread(i); break; case QAT_CMD_GET_NUM_OP_RETRIES: BREAK_IF(p == NULL, "GET_NUM_OP_RETRIES failed as the input parameter was NULL\n"); BREAK_IF(!engine_inited, "GET_NUM_OP_RETRIES failed as the engine is not initialized\n"); *(int *)p = qatPerformOpRetries; break; case QAT_CMD_SET_MAX_RETRY_COUNT: BREAK_IF(i < -1 || i > 100000, "The Message retry count value is out of range, using default value\n"); DEBUG("[%s] Set max retry counter = %d\n", __func__, i); qat_max_retry_count = (int)i; break; case QAT_CMD_SET_INTERNAL_POLL_INTERVAL: BREAK_IF(i < 1 || i > 1000000, "The polling interval value is out of range, using default value\n"); DEBUG("[%s] Set internal poll interval = %d ns\n", __func__, i); qat_poll_interval = (useconds_t) i; break; case QAT_CMD_SET_EPOLL_TIMEOUT: BREAK_IF(i < 1 || i > 10000, "The epoll timeout value is out of range, using default value\n") DEBUG("[%s] Set epoll_wait timeout = %d ms\n", __func__, i); qat_epoll_timeout = (int) i; break; case QAT_CMD_GET_NUM_CRYPTO_INSTANCES: BREAK_IF(p == NULL, \ "GET_NUM_CRYPTO_INSTANCES failed as the input parameter was NULL\n"); if (qatInstanceHandles == NULL) { get_next_inst(); BREAK_IF(qatInstanceHandles == NULL, \ "GET_NUM_CRYPTO_INSTANCES failed as no instances are available\n"); } BREAK_IF(!engine_inited, \ "GET_NUM_CRYPTO_INSTANCES failed as the engine is not initialized\n"); DEBUG("[%s] Get number of crypto instances = %d\n", __func__, numInstances); *(int *)p = numInstances; break; case QAT_CMD_SET_CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD: #ifndef OPENSSL_ENABLE_QAT_SMALL_PACKET_CIPHER_OFFLOADS if(p) { char *token; while((token = strsep((char **)&p, ","))) { char *name_token = strsep(&token,":"); char *value_token = strsep(&token,":"); if(name_token && value_token) { retVal = setQatSmallPacketThreshold(name_token, atoi(value_token)); } else { WARN("Invalid parameter!\n"); retVal = 0; } } } else { WARN("Invalid parameter!\n"); retVal = 0; } #else WARN("QAT_CMD_SET_CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD is not supported\n"); retVal = 0; #endif break; default: WARN("CTRL command not implemented\n"); retVal = 0; break; } return retVal; }
static int qat_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) { unsigned int retVal = 1; CpaStatus status = CPA_STATUS_SUCCESS; int flags = 0; int fd = 0; switch (cmd) { case QAT_CMD_POLL: BREAK_IF(!engine_inited, "POLL failed as engine is not initialized\n"); BREAK_IF(qat_instance_handles == NULL, "POLL failed as no instances are available\n"); BREAK_IF(!enable_external_polling, "POLL failed as external polling is not enabled\n"); BREAK_IF(p == NULL, "POLL failed as the input parameter was NULL\n"); *(int *)p = (int)poll_instances(); break; case QAT_CMD_ENABLE_EXTERNAL_POLLING: BREAK_IF(engine_inited, \ "ENABLE_EXTERNAL_POLLING failed as the engine is already initialized\n"); DEBUG("Enabled external polling\n"); enable_external_polling = 1; enable_inline_polling = 0; break; case QAT_CMD_ENABLE_INLINE_POLLING: BREAK_IF(engine_inited, \ "ENABLE_INLINE_POLLING failed as the engine is already initialized\n"); DEBUG("Enabled inline polling\n"); enable_inline_polling = 1; enable_external_polling = 0; break; case QAT_CMD_GET_EXTERNAL_POLLING_FD: BREAK_IF(!enable_event_driven_polling || !enable_external_polling, \ "GET_EXTERNAL_POLLING_FD failed as this engine message is only supported \ when running in Event Driven Mode with External Polling enabled\n"); BREAK_IF(!engine_inited, \ "GET_EXTERNAL_POLLING_FD failed as the engine is not initialized\n"); BREAK_IF(qat_instance_handles == NULL, \ "GET_EXTERNAL_POLLING_FD failed as no instances are available\n"); BREAK_IF(p == NULL, "GET_EXTERNAL_POLLING_FD failed as the input parameter was NULL\n"); BREAK_IF(i >= qat_num_instances, \ "GET_EXTERNAL_POLLING_FD failed as the instance does not exist\n"); /* Get the file descriptor for the instance */ status = icp_sal_CyGetFileDescriptor(qat_instance_handles[i], &fd); BREAK_IF(CPA_STATUS_FAIL == status, \ "GET_EXTERNAL_POLLING_FD failed as there was an error retrieving the fd\n"); /* Make the file descriptor non-blocking */ flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK); DEBUG("External polling FD for instance[%ld] = %d\n", i, fd); *(int *)p = fd; break; case QAT_CMD_ENABLE_EVENT_DRIVEN_POLLING_MODE: DEBUG("Enabled event driven polling mode\n"); BREAK_IF(engine_inited, \ "ENABLE_EVENT_DRIVEN_POLLING_MODE failed as the engine is already initialized\n"); enable_event_driven_polling = 1; break; case QAT_CMD_DISABLE_EVENT_DRIVEN_POLLING_MODE: DEBUG("Disabled event driven polling mode\n"); BREAK_IF(engine_inited, \ "DISABLE_EVENT_DRIVEN_POLLING_MODE failed as the engine is already initialized\n"); enable_event_driven_polling = 0; break; case QAT_CMD_SET_INSTANCE_FOR_THREAD: BREAK_IF(!engine_inited, \ "SET_INSTANCE_FOR_THREAD failed as the engine is not initialized\n"); BREAK_IF(qat_instance_handles == NULL, \ "SET_INSTANCE_FOR_THREAD failed as no instances are available\n"); DEBUG("Set instance for thread = %ld\n", i); qat_set_instance_for_thread(i); break; case QAT_CMD_GET_NUM_OP_RETRIES: BREAK_IF(p == NULL, "GET_NUM_OP_RETRIES failed as the input parameter was NULL\n"); BREAK_IF(!engine_inited, "GET_NUM_OP_RETRIES failed as the engine is not initialized\n"); *(int *)p = qatPerformOpRetries; break; case QAT_CMD_SET_MAX_RETRY_COUNT: BREAK_IF(i < -1 || i > 100000, "The Message retry count value is out of range, using default value\n"); DEBUG("Set max retry counter = %ld\n", i); qat_max_retry_count = (int)i; break; case QAT_CMD_SET_INTERNAL_POLL_INTERVAL: BREAK_IF(i < 1 || i > 1000000, "The polling interval value is out of range, using default value\n"); DEBUG("Set internal poll interval = %ld ns\n", i); qat_poll_interval = (useconds_t) i; break; case QAT_CMD_SET_EPOLL_TIMEOUT: BREAK_IF(i < 1 || i > 10000, "The epoll timeout value is out of range, using default value\n") DEBUG("Set epoll_wait timeout = %ld ms\n", i); qat_epoll_timeout = (int) i; break; case QAT_CMD_GET_NUM_CRYPTO_INSTANCES: BREAK_IF(p == NULL, \ "GET_NUM_CRYPTO_INSTANCES failed as the input parameter was NULL\n"); BREAK_IF(!engine_inited, \ "GET_NUM_CRYPTO_INSTANCES failed as the engine is not initialized\n"); BREAK_IF(qat_instance_handles == NULL, \ "GET_NUM_CRYPTO_INSTANCES failed as no instances are available\n"); DEBUG("Get number of crypto instances = %d\n", qat_num_instances); *(int *)p = qat_num_instances; break; case QAT_CMD_SET_CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD: #ifndef OPENSSL_ENABLE_QAT_SMALL_PACKET_CIPHER_OFFLOADS if(p) { char *token; char str_p[1024]; char *itr = str_p; strncpy(str_p, (const char *)p, 1024); while((token = strsep(&itr, ","))) { char *name_token = strsep(&token,":"); char *value_token = strsep(&token,":"); if(name_token && value_token) { retVal = qat_pkt_threshold_table_set_threshold( name_token, atoi(value_token)); } else { WARN("Invalid name_token or value_token\n"); retVal = 0; } } } else { WARN("Invalid p parameter\n"); retVal = 0; } #else WARN("QAT_CMD_SET_CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD is not supported\n"); retVal = 0; #endif break; default: WARN("CTRL command not implemented\n"); retVal = 0; break; } if(!retVal) { QATerr(QAT_F_QAT_ENGINE_CTRL, QAT_R_ENGINE_CTRL_CMD_FAILURE); } return retVal; }