]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/char/ipmi/ipmi_si_intf.c
ipmi: Turn off all activity on an idle ipmi interface
[mirror_ubuntu-artful-kernel.git] / drivers / char / ipmi / ipmi_si_intf.c
index 9c4069151955b6bfb94309dbde7681039307c5f1..444ea548dfe3f910da0960dd82a6ffa86643ce48 100644 (file)
@@ -257,6 +257,9 @@ struct smi_info {
        /* Used to gracefully stop the timer without race conditions. */
        atomic_t            stop_operation;
 
+       /* Are we waiting for the events, pretimeouts, received msgs? */
+       atomic_t            need_watch;
+
        /*
         * The driver will disable interrupts when it gets into a
         * situation where it cannot handle messages due to lack of
@@ -862,6 +865,19 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
        return si_sm_result;
 }
 
+static void check_start_timer_thread(struct smi_info *smi_info)
+{
+       if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) {
+               smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES);
+
+               if (smi_info->thread)
+                       wake_up_process(smi_info->thread);
+
+               start_next_msg(smi_info);
+               smi_event_handler(smi_info, 0);
+       }
+}
+
 static void sender(void                *send_info,
                   struct ipmi_smi_msg *msg,
                   int                 priority)
@@ -915,15 +931,7 @@ static void sender(void                *send_info,
        else
                list_add_tail(&msg->link, &smi_info->xmit_msgs);
 
-       if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) {
-               smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES);
-
-               if (smi_info->thread)
-                       wake_up_process(smi_info->thread);
-
-               start_next_msg(smi_info);
-               smi_event_handler(smi_info, 0);
-       }
+       check_start_timer_thread(smi_info);
        spin_unlock_irqrestore(&smi_info->si_lock, flags);
 }
 
@@ -1023,9 +1031,15 @@ static int ipmi_thread(void *data)
                        ; /* do nothing */
                else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait)
                        schedule();
-               else if (smi_result == SI_SM_IDLE)
-                       schedule_timeout_interruptible(100);
-               else
+               else if (smi_result == SI_SM_IDLE) {
+                       if (atomic_read(&smi_info->need_watch)) {
+                               schedule_timeout_interruptible(100);
+                       } else {
+                               /* Wait to be woken up when we are needed. */
+                               __set_current_state(TASK_INTERRUPTIBLE);
+                               schedule();
+                       }
+               } else
                        schedule_timeout_interruptible(1);
        }
        return 0;
@@ -1061,6 +1075,17 @@ static void request_events(void *send_info)
        atomic_set(&smi_info->req_events, 1);
 }
 
+static void set_need_watch(void *send_info, int enable)
+{
+       struct smi_info *smi_info = send_info;
+       unsigned long flags;
+
+       atomic_set(&smi_info->need_watch, enable);
+       spin_lock_irqsave(&smi_info->si_lock, flags);
+       check_start_timer_thread(smi_info);
+       spin_unlock_irqrestore(&smi_info->si_lock, flags);
+}
+
 static int initialized;
 
 static void smi_timeout(unsigned long data)
@@ -1212,6 +1237,7 @@ static struct ipmi_smi_handlers handlers = {
        .get_smi_info           = get_smi_info,
        .sender                 = sender,
        .request_events         = request_events,
+       .set_need_watch         = set_need_watch,
        .set_maintenance_mode   = set_maintenance_mode,
        .set_run_to_completion  = set_run_to_completion,
        .poll                   = poll,
@@ -1239,7 +1265,7 @@ static bool          si_tryplatform = 1;
 #ifdef CONFIG_PCI
 static bool          si_trypci = 1;
 #endif
-static bool          si_trydefaults = 1;
+static bool          si_trydefaults = IS_ENABLED(CONFIG_IPMI_SI_PROBE_DEFAULTS);
 static char          *si_type[SI_MAX_PARMS];
 #define MAX_SI_TYPE_STR 30
 static char          si_type_str[MAX_SI_TYPE_STR];
@@ -3352,6 +3378,7 @@ static int try_smi_init(struct smi_info *new_smi)
 
        new_smi->interrupt_disabled = 1;
        atomic_set(&new_smi->stop_operation, 0);
+       atomic_set(&new_smi->need_watch, 0);
        new_smi->intf_num = smi_num;
        smi_num++;