From 9e7dd85758110c6816c0bdf121b7dd230cc8957a Mon Sep 17 00:00:00 2001 From: Gidon Studinski Date: Wed, 11 Dec 2019 17:35:43 +0200 Subject: [PATCH 1/2] wigig_sensing: change change_mode ioctl signature The new definition separates error code report from burst_size. This promotes uniformity in the ioctl definitions and prevents the usage of errno. Change-Id: I2145a8ba15cb25a82c1d1a4d4c3465e56f4358d6 Signed-off-by: Gidon Studinski Signed-off-by: Alexei Avshalom Lazar --- drivers/misc/wigig_sensing.c | 28 +++++++++++++++++--------- include/uapi/misc/wigig_sensing_uapi.h | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/misc/wigig_sensing.c b/drivers/misc/wigig_sensing.c index c1af5a164eb4..1e262d864784 100644 --- a/drivers/misc/wigig_sensing.c +++ b/drivers/misc/wigig_sensing.c @@ -514,22 +514,25 @@ static int wigig_sensing_ioc_get_mode(struct wigig_sensing_ctx *ctx) } static int wigig_sensing_ioc_change_mode(struct wigig_sensing_ctx *ctx, - struct wigig_sensing_change_mode req) + struct wigig_sensing_change_mode *req) { struct wigig_sensing_stm sim_state; int rc; u32 ch; + if (req == NULL) + return -EINVAL; + pr_info("mode = %d, channel = %d, has_channel = %d\n", - req.mode, req.channel, req.has_channel); + req->mode, req->channel, req->has_channel); if (!ctx) return -EINVAL; /* Save the request for later use */ - ctx->stm.mode_request = req.mode; + ctx->stm.mode_request = req->mode; /* Simulate a state change */ - ctx->stm.state_request = convert_mode_to_state(req.mode); + ctx->stm.state_request = convert_mode_to_state(req->mode); sim_state = ctx->stm; rc = wigig_sensing_change_state(ctx, &sim_state, ctx->stm.state_request); @@ -541,11 +544,11 @@ static int wigig_sensing_ioc_change_mode(struct wigig_sensing_ctx *ctx, /* Send command to FW */ mutex_lock(&ctx->dri_lock); ctx->stm.change_mode_in_progress = true; - ch = req.has_channel ? req.channel : 0; + ch = req->has_channel ? req->channel : 0; ctx->stm.channel_request = ch; ctx->stm.burst_size_ready = false; /* Change mode command must not be called during DRI processing */ - rc = wigig_sensing_send_change_mode_command(ctx, req.mode, ch); + rc = wigig_sensing_send_change_mode_command(ctx, req->mode, ch); mutex_unlock(&ctx->dri_lock); if (rc) { pr_err("wigig_sensing_send_change_mode_command() failed, err %d\n", @@ -585,7 +588,9 @@ End: ctx->stm.state_request = WIGIG_SENSING_STATE_MIN; ctx->stm.channel_request = 0; ctx->stm.mode_request = WIGIG_SENSING_MODE_STOP; - return (rc == 0) ? ctx->stm.burst_size : rc; + req->burst_size = ctx->stm.burst_size; + + return rc; } static int wigig_sensing_ioc_clear_data(struct wigig_sensing_ctx *ctx) @@ -808,7 +813,11 @@ static long wigig_sensing_ioctl(struct file *file, unsigned int cmd, if (copy_from_user(&req, (void *)arg, sizeof(req))) return -EFAULT; - rc = wigig_sensing_ioc_change_mode(ctx, req); + rc = wigig_sensing_ioc_change_mode(ctx, &req); + + if (copy_to_user((void *)arg, &req, sizeof(req))) + return -EFAULT; + break; } case WIGIG_SENSING_IOCTL_CLEAR_DATA: @@ -1483,10 +1492,11 @@ static int wigig_sensing_remove(struct spi_device *spi) .mode = WIGIG_SENSING_MODE_STOP, .has_channel = false, .channel = 0, + .burst_size = 0, }; /* Make sure that FW is in STOP mode */ - wigig_sensing_ioc_change_mode(ctx, req); + wigig_sensing_ioc_change_mode(ctx, &req); device_destroy(ctx->class, ctx->wigig_sensing_dev); unregister_chrdev_region(ctx->wigig_sensing_dev, 1); diff --git a/include/uapi/misc/wigig_sensing_uapi.h b/include/uapi/misc/wigig_sensing_uapi.h index d1c69645c024..2c50b35e61b3 100644 --- a/include/uapi/misc/wigig_sensing_uapi.h +++ b/include/uapi/misc/wigig_sensing_uapi.h @@ -24,6 +24,7 @@ struct wigig_sensing_change_mode { enum wigig_sensing_mode mode; bool has_channel; uint32_t channel; + uint32_t burst_size; }; enum wigig_sensing_event { From f92a7e71950d77c3709f77425e1d8dba8e620edc Mon Sep 17 00:00:00 2001 From: Gidon Studinski Date: Thu, 26 Dec 2019 14:51:47 +0200 Subject: [PATCH 2/2] wigig_sensing: fix driver state machine Allow mode change from INITIALIZED to READY_STOPPED only after SPI has been initialized. This change will prevent mode change before SPI is ready for operation. Change-Id: I12b52bb9c9726c2d8e615fa0c504d01c7b1e26e3 Signed-off-by: Gidon Studinski Signed-off-by: Alexei Avshalom Lazar --- drivers/misc/wigig_sensing.c | 9 +++++++-- drivers/misc/wigig_sensing.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/misc/wigig_sensing.c b/drivers/misc/wigig_sensing.c index 1e262d864784..ca35341efcc9 100644 --- a/drivers/misc/wigig_sensing.c +++ b/drivers/misc/wigig_sensing.c @@ -454,9 +454,11 @@ static int wigig_sensing_change_state(struct wigig_sensing_ctx *ctx, /* * Moving from INITIALIZED state is allowed only to READY_STOPPED state + * and only when spi_ready is set */ else if (curr_state == WIGIG_SENSING_STATE_INITIALIZED && - new_state != WIGIG_SENSING_STATE_READY_STOPPED) { + (new_state != WIGIG_SENSING_STATE_READY_STOPPED || + !ctx->stm.spi_ready)) { transition_allowed = false; rc = -EFAULT; } @@ -1255,9 +1257,11 @@ static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie) } ctx->stm.spi_malfunction = false; - if (ctx->stm.state == WIGIG_SENSING_STATE_INITIALIZED) + if (ctx->stm.state == WIGIG_SENSING_STATE_INITIALIZED) { wigig_sensing_change_state(ctx, &ctx->stm, WIGIG_SENSING_STATE_READY_STOPPED); + ctx->stm.spi_ready = true; + } } pr_debug("Reading SANITY register\n"); @@ -1313,6 +1317,7 @@ static irqreturn_t wigig_sensing_dri_isr_thread(int irq, void *cookie) WIGIG_SENSING_EVENT_RESET); ctx->stm.spi_malfunction = true; + ctx->stm.spi_ready = false; memset(&ctx->inb_cmd, 0, sizeof(ctx->inb_cmd)); spi_status.v &= ~INT_SYSASSERT; goto deassert_and_bail_out; diff --git a/drivers/misc/wigig_sensing.h b/drivers/misc/wigig_sensing.h index e45a7f62101e..d53eead8281a 100644 --- a/drivers/misc/wigig_sensing.h +++ b/drivers/misc/wigig_sensing.h @@ -146,6 +146,7 @@ struct wigig_sensing_stm { bool auto_recovery; bool fw_is_ready; bool spi_malfunction; + bool spi_ready; bool waiting_for_deep_sleep_exit; bool waiting_for_deep_sleep_exit_first_pass; bool burst_size_ready;