[9610] wlbt: Introduced halt confirmation (normal shutdown)
authorRoman Geller <r.geller@samsung.com>
Thu, 14 Jun 2018 18:27:37 +0000 (19:27 +0100)
committerTarun Karela <t.karela@samsung.com>
Fri, 22 Jun 2018 08:52:50 +0000 (09:52 +0100)
Added halt confirmation insuring that the fw shutdown
activity is completed before reset from host

Change-Id: I23d338d3ab212df1be9634dd62c190ef04d3cda4
SCSC-Bug-Id: SSB-38486
Signed-off-by: Roman Geller <r.geller@samsung.com>
drivers/misc/samsung/scsc/mxman.c
drivers/misc/samsung/scsc/mxman.h

index adbe5b40408086ecd8d04870951b55aab745156c..2ddc23bf5666db7cc73fc3374af7b84657cf37c2 100755 (executable)
@@ -77,6 +77,8 @@ static struct work_struct     wlbtd_work;
 #define SCSC_R4_V2_MINOR_52 52
 #define SCSC_R4_V2_MINOR_53 53
 
+#define MM_HALT_RSP_TIMEOUT_MS 1000
+
 static char panic_record_dump[PANIC_RECORD_DUMP_BUFFER_SZ];
 static BLOCKING_NOTIFIER_HEAD(firmware_chain);
 
@@ -110,10 +112,6 @@ static bool skip_mbox0_check;
 module_param(skip_mbox0_check, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(skip_mbox0_check, "Allow skipping firmware mbox0 signature check");
 
-static uint mif_access_max_time_ms = 100;
-module_param(mif_access_max_time_ms, uint, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(mif_access_max_time_ms, "Timeout send_mm_msg_stop_blocking (ms) - default 100");
-
 static uint firmware_startup_flags;
 module_param(firmware_startup_flags, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(firmware_startup_flags, "0 = Proceed as normal (default); Bit 0 = 1 - spin at start of CRT0; Other bits reserved = 0");
@@ -208,7 +206,8 @@ enum {
        MM_FORCE_PANIC = 2,
        MM_HOST_SUSPEND = 3,
        MM_HOST_RESUME = 4,
-       MM_FW_CONFIG = 5
+       MM_FW_CONFIG = 5,
+       MM_HALT_RSP = 6,
 } ma_msg;
 
 /**
@@ -264,17 +263,19 @@ static int _mx_exec(char *prog, int wait_exec) __attribute__((unused));
 #else
 static int _mx_exec(char *prog, int wait_exec);
 #endif
-static int wait_for_mm_msg_start_ind(struct mxman *mxman)
+static int wait_for_mm_msg(struct mxman *mxman, struct completion *mm_msg_completion, ulong timeout_ms)
 {
        int r;
 
-       if (0 == mm_completion_timeout_ms) {
+       (void)mxman; /* unused */
+
+       if (timeout_ms == 0) {
                /* Zero implies infinite wait */
-               r = wait_for_completion_interruptible(&mxman->mm_msg_start_ind_completion);
+               r = wait_for_completion_interruptible(mm_msg_completion);
                /* r = -ERESTARTSYS if interrupted, 0 if completed */
                return r;
        }
-       r = wait_for_completion_timeout(&mxman->mm_msg_start_ind_completion, msecs_to_jiffies(mm_completion_timeout_ms));
+       r = wait_for_completion_timeout(mm_msg_completion, msecs_to_jiffies(timeout_ms));
        if (r == 0) {
                SCSC_TAG_ERR(MXMAN, "timeout\n");
                return -ETIMEDOUT;
@@ -283,6 +284,16 @@ static int wait_for_mm_msg_start_ind(struct mxman *mxman)
        return 0;
 }
 
+static int wait_for_mm_msg_start_ind(struct mxman *mxman)
+{
+       return wait_for_mm_msg(mxman, &mxman->mm_msg_start_ind_completion, mm_completion_timeout_ms);
+}
+
+static int wait_for_mm_msg_halt_rsp(struct mxman *mxman)
+{
+       return wait_for_mm_msg(mxman, &mxman->mm_msg_halt_rsp_completion, MM_HALT_RSP_TIMEOUT_MS);
+}
+
 #ifndef CONFIG_SCSC_WLBTD
 static int coredump_helper(void)
 {
@@ -318,6 +329,7 @@ static int coredump_helper(void)
 
 static int send_mm_msg_stop_blocking(struct mxman *mxman)
 {
+       int r;
 #ifdef CONFIG_SCSC_FM
        struct ma_msg_packet message = { .ma_msg = MM_HALT_REQ,
                        .arg = mxman->on_halt_ldos_on };
@@ -325,7 +337,13 @@ static int send_mm_msg_stop_blocking(struct mxman *mxman)
        struct ma_msg_packet message = { .ma_msg = MM_HALT_REQ };
 #endif
        mxmgmt_transport_send(scsc_mx_get_mxmgmt_transport(mxman->mx), MMTRANS_CHAN_ID_MAXWELL_MANAGEMENT, &message, sizeof(message));
-       msleep(mif_access_max_time_ms);
+
+       r = wait_for_mm_msg_halt_rsp(mxman);
+       if (r) {
+               SCSC_TAG_ERR(MXMAN, "wait_for_MM_HALT_RSP() failed: r=%d\n", r);
+               return r;
+       }
+
 
        return 0;
 }
@@ -437,6 +455,10 @@ static void mxman_message_handler(const void *message, void *data)
                atomic_inc(&mxman->boot_count);
                complete(&mxman->mm_msg_start_ind_completion);
                break;
+       case MM_HALT_RSP:
+               complete(&mxman->mm_msg_halt_rsp_completion);
+               SCSC_TAG_INFO(MXMAN, "Received MM_HALT_RSP message from the firmware");
+               break;
        default:
                /* HERE: Unknown message, raise fault */
                SCSC_TAG_WARNING(MXMAN, "Received unknown message from the firmware: msg->ma_msg=%d\n", msg->ma_msg);
@@ -882,6 +904,7 @@ static int mxman_start(struct mxman *mxman)
        }
        mbox_init(mxman, fwhdr->firmware_entry_point);
        init_completion(&mxman->mm_msg_start_ind_completion);
+       init_completion(&mxman->mm_msg_halt_rsp_completion);
        mxmgmt_transport_register_channel_handler(scsc_mx_get_mxmgmt_transport(mxman->mx), MMTRANS_CHAN_ID_MAXWELL_MANAGEMENT,
                                                  &mxman_message_handler, mxman);
 
index fee44b9c24bc874d75a040ca42b19cf6b791b890..82e310e4c3c6cd4ec6ed085c18c40ad37ea21778 100755 (executable)
@@ -50,6 +50,7 @@ struct mxman {
        char                    *fw;
        u32                     fw_image_size;
        struct completion       mm_msg_start_ind_completion;
+       struct completion       mm_msg_halt_rsp_completion;
        struct fwhdr            fwhdr;
        struct mxconf           *mxconf;
        enum mxman_state        mxman_state;