diff --git a/src/cndm/modules/cndm/cndm.h b/src/cndm/modules/cndm/cndm.h index 0c8649e..be18897 100644 --- a/src/cndm/modules/cndm/cndm.h +++ b/src/cndm/modules/cndm/cndm.h @@ -51,6 +51,8 @@ struct cndm_dev { phys_addr_t hw_regs_phys; void __iomem *hw_addr; + struct mutex mbox_lock; + u32 port_count; u32 port_offset; u32 port_stride; diff --git a/src/cndm/modules/cndm/cndm_cmd.c b/src/cndm/modules/cndm/cndm_cmd.c index 01bb8bd..5aed20a 100644 --- a/src/cndm/modules/cndm/cndm_cmd.c +++ b/src/cndm/modules/cndm/cndm_cmd.c @@ -17,6 +17,8 @@ int cndm_exec_mbox_cmd(struct cndm_dev *cdev, void *cmd, void *rsp) if (!cmd || !rsp) return -EINVAL; + mutex_lock(&cdev->mbox_lock); + // write command to mailbox for (k = 0; k < 16; k++) { iowrite32(*((u32 *)(cmd + k*4)), cdev->hw_addr + 0x10000 + k*4); @@ -38,6 +40,9 @@ int cndm_exec_mbox_cmd(struct cndm_dev *cdev, void *cmd, void *rsp) for (k = 0; k < 16; k++) { *((u32 *)(rsp + k*4)) = ioread32(cdev->hw_addr + 0x10000 + 0x40 + k*4); } + + mutex_unlock(&cdev->mbox_lock); + return 0; } diff --git a/src/cndm/modules/cndm/cndm_main.c b/src/cndm/modules/cndm/cndm_main.c index 7951a79..510fb4a 100644 --- a/src/cndm/modules/cndm/cndm_main.c +++ b/src/cndm/modules/cndm/cndm_main.c @@ -47,6 +47,8 @@ static int cndm_common_probe(struct cndm_dev *cdev) int ret = 0; int k; + mutex_init(&cdev->mbox_lock); + #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) devlink_register(devlink); #else