diff --git a/drivers/misc/wigig_sensing.c b/drivers/misc/wigig_sensing.c index 21446e2f45e9..e3758b116338 100644 --- a/drivers/misc/wigig_sensing.c +++ b/drivers/misc/wigig_sensing.c @@ -2,7 +2,6 @@ /* * Copyright (c) 2019, The Linux foundation. All rights reserved. */ - #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -639,9 +639,19 @@ static int wigig_sensing_ioc_get_num_avail_bursts( return 0; } -static int wigig_sensing_ioc_get_event(struct wigig_sensing_ctx *ctx) +static int wigig_sensing_ioc_get_event(struct wigig_sensing_ctx *ctx, + enum wigig_sensing_event *event) { - return 0; + u32 copied; + + if (!ctx->event_pending) + return -EINVAL; + + if (kfifo_len(&ctx->events_fifo) == 1) + ctx->event_pending = false; + + return kfifo_to_user(&ctx->events_fifo, event, + sizeof(enum wigig_sensing_event), &copied); } static int wigig_sensing_open(struct inode *inode, struct file *filp) @@ -769,7 +779,7 @@ static int wigig_sensing_release(struct inode *inode, struct file *filp) } static long wigig_sensing_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) + __user unsigned long arg) { int rc; struct wigig_sensing_ctx *ctx = file->private_data; @@ -822,7 +832,8 @@ static long wigig_sensing_ioctl(struct file *file, unsigned int cmd, break; case WIGIG_SENSING_IOCTL_GET_EVENT: pr_info("Received WIGIG_SENSING_IOCTL_GET_EVENT command\n"); - rc = wigig_sensing_ioc_get_event(ctx); + rc = wigig_sensing_ioc_get_event(ctx, + (enum wigig_sensing_event *)arg); break; case WIGIG_SENSING_IOCTL_GET_NUM_AVAIL_BURSTS: pr_info("Received WIGIG_SENSING_IOCTL_GET_NUM_AVAIL_BURSTS command\n"); @@ -1145,6 +1156,22 @@ cmd_reply_buf_alloc_failed: return rc; } +static int wigig_sensing_send_event(struct wigig_sensing_ctx *ctx, + enum wigig_sensing_event event) +{ + if (kfifo_is_full(&ctx->events_fifo)) { + pr_err("events fifo is full, unable to send event\n"); + return -EFAULT; + } + + kfifo_in(&ctx->events_fifo, &event, 1); + ctx->event_pending = true; + + wake_up_interruptible(&ctx->cmd_wait_q); + + return 0; +} + static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie) { struct wigig_sensing_ctx *ctx = cookie; @@ -1232,6 +1259,9 @@ static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie) wigig_sensing_change_state(ctx, &ctx->stm, WIGIG_SENSING_STATE_READY_STOPPED); + /* Send asynchronous FW_READY event to application */ + wigig_sensing_send_event(ctx, WIGIG_SENSING_EVENT_FW_READY); + spi_status.v &= ~INT_FW_READY; } if (spi_status.b.int_data_ready) { @@ -1254,6 +1284,9 @@ static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie) ctx->stm.state != WIGIG_SENSING_STATE_SYS_ASSERT) pr_err("State change to WIGIG_SENSING_SYS_ASSERT failed\n"); + /* Send asynchronous RESET event to application */ + wigig_sensing_send_event(ctx, WIGIG_SENSING_EVENT_RESET); + ctx->stm.spi_malfunction = true; spi_status.v &= ~INT_SYSASSERT; } @@ -1326,6 +1359,7 @@ static int wigig_sensing_probe(struct spi_device *spi) init_waitqueue_head(&ctx->cmd_wait_q); init_waitqueue_head(&ctx->data_wait_q); ctx->stm.state = WIGIG_SENSING_STATE_INITIALIZED; + INIT_KFIFO(ctx->events_fifo); /* Allocate memory for the CIRs */ /* Allocate a 2MB == 2^21 buffer for CIR data */ diff --git a/drivers/misc/wigig_sensing.h b/drivers/misc/wigig_sensing.h index c4b291062454..eaf2023ba25c 100644 --- a/drivers/misc/wigig_sensing.h +++ b/drivers/misc/wigig_sensing.h @@ -7,6 +7,7 @@ #define __WIGIG_SENSING_H__ #include #include +#include #include #include @@ -193,6 +194,7 @@ struct wigig_sensing_ctx { struct cir_data cir_data; u8 *temp_buffer; bool event_pending; + DECLARE_KFIFO(events_fifo, enum wigig_sensing_event, 8); u32 dropped_bursts; }; diff --git a/include/uapi/misc/wigig_sensing_uapi.h b/include/uapi/misc/wigig_sensing_uapi.h index c53d6bfa6010..d1c69645c024 100644 --- a/include/uapi/misc/wigig_sensing_uapi.h +++ b/include/uapi/misc/wigig_sensing_uapi.h @@ -27,8 +27,10 @@ struct wigig_sensing_change_mode { }; enum wigig_sensing_event { + WIGIG_SENSING_EVENT_MIN, WIGIG_SENSING_EVENT_FW_READY, WIGIG_SENSING_EVENT_RESET, + WIGIG_SENSING_EVENT_MAX, }; #define WIGIG_SENSING_IOC_MAGIC 'r' @@ -84,7 +86,7 @@ enum wigig_sensing_event { WIGIG_SENSING_IOCTL_GET_NUM_DROPPED_BURSTS, uint32_t) /** - * Get number of bursts that where dropped due to data buffer overflow + * Get asynchronous event (FW_READY, RESET) */ #define WIGIG_SENSING_IOC_GET_EVENT \ _IOR(WIGIG_SENSING_IOC_MAGIC, WIGIG_SENSING_IOCTL_GET_EVENT, \