#include <stdint.h>
#include <sys/time.h>
+#include <unistd.h>
+#include <pthread.h>
#include <rte_common.h>
#include <rte_byteorder.h>
#include <rte_memzone.h>
}
}
+static inline int hinic_mutex_init(pthread_mutex_t *pthreadmutex,
+ const pthread_mutexattr_t *mattr)
+{
+ int err;
+
+ err = pthread_mutex_init(pthreadmutex, mattr);
+ if (unlikely(err))
+ PMD_DRV_LOG(ERR, "Fail to initialize mutex, error: %d", err);
+
+ return err;
+}
+
+static inline int hinic_mutex_destroy(pthread_mutex_t *pthreadmutex)
+{
+ int err;
+
+ err = pthread_mutex_destroy(pthreadmutex);
+ if (unlikely(err))
+ PMD_DRV_LOG(ERR, "Fail to destroy mutex, error: %d", err);
+
+ return err;
+}
+
#endif /* _HINIC_COMPAT_H_ */
hwdev->pf_to_mgmt = pf_to_mgmt;
pf_to_mgmt->hwdev = hwdev;
- spin_lock_init(&pf_to_mgmt->async_msg_lock);
- spin_lock_init(&pf_to_mgmt->sync_msg_lock);
+ err = hinic_mutex_init(&pf_to_mgmt->sync_msg_lock, NULL);
+ if (err)
+ goto mutex_init_err;
err = alloc_msg_buf(pf_to_mgmt);
if (err) {
free_msg_buf(pf_to_mgmt);
alloc_msg_buf_err:
+ hinic_mutex_destroy(&pf_to_mgmt->sync_msg_lock);
+
+mutex_init_err:
kfree(pf_to_mgmt);
return err;
hinic_api_cmd_free(pf_to_mgmt->cmd_chain);
free_msg_buf(pf_to_mgmt);
+ hinic_mutex_destroy(&pf_to_mgmt->sync_msg_lock);
kfree(pf_to_mgmt);
}
u32 timeo;
int err, i;
- spin_lock(&pf_to_mgmt->sync_msg_lock);
+ pthread_mutex_lock(&pf_to_mgmt->sync_msg_lock);
SYNC_MSG_ID_INC(pf_to_mgmt);
recv_msg = &pf_to_mgmt->recv_resp_msg_from_mgmt;
unlock_sync_msg:
if (err && out_size)
*out_size = 0;
- spin_unlock(&pf_to_mgmt->sync_msg_lock);
+ pthread_mutex_unlock(&pf_to_mgmt->sync_msg_lock);
return err;
}
return err;
}
- spin_lock(&pf_to_mgmt->sync_msg_lock);
+ pthread_mutex_lock(&pf_to_mgmt->sync_msg_lock);
err = send_msg_to_mgmt_sync(pf_to_mgmt, mod, cmd, buf_in, in_size,
HINIC_MSG_NO_ACK, HINIC_MSG_DIRECT_SEND,
MSG_NO_RESP);
- spin_unlock(&pf_to_mgmt->sync_msg_lock);
+ pthread_mutex_unlock(&pf_to_mgmt->sync_msg_lock);
return err;
}
}
if (timeout != 0)
- rte_delay_ms(1);
+ usleep(1000);
} while (time_before(jiffies, end));
if (err != HINIC_OK) /*poll time out*/
struct hinic_msg_pf_to_mgmt {
struct hinic_hwdev *hwdev;
- /* Async cmd can not be scheduling */
- spinlock_t async_msg_lock;
- /* spinlock for sync message */
- spinlock_t sync_msg_lock;
+ /* mutex for sync message */
+ pthread_mutex_t sync_msg_lock;
void *async_msg_buf;
void *sync_msg_buf;