Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'ipmi' (emailed ipmi fixes)

Merge ipmi fixes from Corey Minyard:
"Things collected since last kernel release.

Some of these are pretty important. The first three are bug fixes.
The next two are to hopefully make everyone happy about allowing
ACPI to be on all the time and not have IPMI have an effect on the
system when not in use. The last is a little cleanup"

* emailed patches from Corey Minyard <cminyard@mvista.com>:
ipmi: boolify some things
ipmi: Turn off all activity on an idle ipmi interface
ipmi: Turn off default probing of interfaces
ipmi: Reset the KCS timeout when starting error recovery
ipmi: Fix a race restarting the timer
Char: ipmi_bt_sm, fix infinite loop

+261 -155
+12
drivers/char/ipmi/Kconfig
··· 50 50 Currently, only KCS and SMIC are supported. If 51 51 you are using IPMI, you should probably say "y" here. 52 52 53 + config IPMI_SI_PROBE_DEFAULTS 54 + bool 'Probe for all possible IPMI system interfaces by default' 55 + default n 56 + depends on IPMI_SI 57 + help 58 + Modern systems will usually expose IPMI interfaces via a discoverable 59 + firmware mechanism such as ACPI or DMI. Older systems do not, and so 60 + the driver is forced to probe hardware manually. This may cause boot 61 + delays. Say "n" here to disable this manual probing. IPMI will then 62 + only be available on older systems if the "ipmi_si_intf.trydefaults=1" 63 + boot argument is passed. 64 + 53 65 config IPMI_WATCHDOG 54 66 tristate 'IPMI Watchdog Timer' 55 67 help
+1 -1
drivers/char/ipmi/ipmi_bt_sm.c
··· 352 352 353 353 static inline int read_all_bytes(struct si_sm_data *bt) 354 354 { 355 - unsigned char i; 355 + unsigned int i; 356 356 357 357 /* 358 358 * length is "framing info", minimum = 4: NetFn, Seq, Cmd, cCode.
+3 -2
drivers/char/ipmi/ipmi_kcs_sm.c
··· 251 251 if (!GET_STATUS_OBF(status)) { 252 252 kcs->obf_timeout -= time; 253 253 if (kcs->obf_timeout < 0) { 254 - start_error_recovery(kcs, "OBF not ready in time"); 255 - return 1; 254 + kcs->obf_timeout = OBF_RETRY_TIMEOUT; 255 + start_error_recovery(kcs, "OBF not ready in time"); 256 + return 1; 256 257 } 257 258 return 0; 258 259 }
+144 -95
drivers/char/ipmi/ipmi_msghandler.c
··· 55 55 static int ipmi_init_msghandler(void); 56 56 static void smi_recv_tasklet(unsigned long); 57 57 static void handle_new_recv_msgs(ipmi_smi_t intf); 58 + static void need_waiter(ipmi_smi_t intf); 58 59 59 60 static int initialized; 60 61 ··· 74 73 */ 75 74 #define MAX_MSG_TIMEOUT 60000 76 75 76 + /* Call every ~1000 ms. */ 77 + #define IPMI_TIMEOUT_TIME 1000 78 + 79 + /* How many jiffies does it take to get to the timeout time. */ 80 + #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000) 81 + 82 + /* 83 + * Request events from the queue every second (this is the number of 84 + * IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the 85 + * future, IPMI will add a way to know immediately if an event is in 86 + * the queue and this silliness can go away. 87 + */ 88 + #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME)) 89 + 77 90 /* 78 91 * The main "user" data structure. 79 92 */ 80 93 struct ipmi_user { 81 94 struct list_head link; 82 95 83 - /* Set to "0" when the user is destroyed. */ 84 - int valid; 96 + /* Set to false when the user is destroyed. */ 97 + bool valid; 85 98 86 99 struct kref refcount; 87 100 ··· 107 92 ipmi_smi_t intf; 108 93 109 94 /* Does this interface receive IPMI events? */ 110 - int gets_events; 95 + bool gets_events; 111 96 }; 112 97 113 98 struct cmd_rcvr { ··· 398 383 unsigned int waiting_events_count; /* How many events in queue? */ 399 384 char delivering_events; 400 385 char event_msg_printed; 386 + atomic_t event_waiters; 387 + unsigned int ticks_to_req_ev; 388 + int last_needs_timer; 401 389 402 390 /* 403 391 * The event receiver for my BMC, only really used at panic ··· 413 395 414 396 /* For handling of maintenance mode. */ 415 397 int maintenance_mode; 416 - int maintenance_mode_enable; 398 + bool maintenance_mode_enable; 417 399 int auto_maintenance_timeout; 418 400 spinlock_t maintenance_mode_lock; /* Used in a timer... */ 419 401 ··· 468 450 */ 469 451 static LIST_HEAD(smi_watchers); 470 452 static DEFINE_MUTEX(smi_watchers_mutex); 471 - 472 453 473 454 #define ipmi_inc_stat(intf, stat) \ 474 455 atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat]) ··· 789 772 *seq = i; 790 773 *seqid = intf->seq_table[i].seqid; 791 774 intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ; 775 + need_waiter(intf); 792 776 } else { 793 777 rv = -EAGAIN; 794 778 } ··· 959 941 new_user->handler = handler; 960 942 new_user->handler_data = handler_data; 961 943 new_user->intf = intf; 962 - new_user->gets_events = 0; 944 + new_user->gets_events = false; 963 945 964 946 if (!try_module_get(intf->handlers->owner)) { 965 947 rv = -ENODEV; ··· 980 962 */ 981 963 mutex_unlock(&ipmi_interfaces_mutex); 982 964 983 - new_user->valid = 1; 965 + new_user->valid = true; 984 966 spin_lock_irqsave(&intf->seq_lock, flags); 985 967 list_add_rcu(&new_user->link, &intf->users); 986 968 spin_unlock_irqrestore(&intf->seq_lock, flags); 969 + if (handler->ipmi_watchdog_pretimeout) { 970 + /* User wants pretimeouts, so make sure to watch for them. */ 971 + if (atomic_inc_return(&intf->event_waiters) == 1) 972 + need_waiter(intf); 973 + } 987 974 *user = new_user; 988 975 return 0; 989 976 ··· 1042 1019 struct cmd_rcvr *rcvr; 1043 1020 struct cmd_rcvr *rcvrs = NULL; 1044 1021 1045 - user->valid = 0; 1022 + user->valid = false; 1023 + 1024 + if (user->handler->ipmi_watchdog_pretimeout) 1025 + atomic_dec(&intf->event_waiters); 1026 + 1027 + if (user->gets_events) 1028 + atomic_dec(&intf->event_waiters); 1046 1029 1047 1030 /* Remove the user from the interface's sequence table. */ 1048 1031 spin_lock_irqsave(&intf->seq_lock, flags); ··· 1184 1155 if (intf->maintenance_mode != mode) { 1185 1156 switch (mode) { 1186 1157 case IPMI_MAINTENANCE_MODE_AUTO: 1187 - intf->maintenance_mode = mode; 1188 1158 intf->maintenance_mode_enable 1189 1159 = (intf->auto_maintenance_timeout > 0); 1190 1160 break; 1191 1161 1192 1162 case IPMI_MAINTENANCE_MODE_OFF: 1193 - intf->maintenance_mode = mode; 1194 - intf->maintenance_mode_enable = 0; 1163 + intf->maintenance_mode_enable = false; 1195 1164 break; 1196 1165 1197 1166 case IPMI_MAINTENANCE_MODE_ON: 1198 - intf->maintenance_mode = mode; 1199 - intf->maintenance_mode_enable = 1; 1167 + intf->maintenance_mode_enable = true; 1200 1168 break; 1201 1169 1202 1170 default: 1203 1171 rv = -EINVAL; 1204 1172 goto out_unlock; 1205 1173 } 1174 + intf->maintenance_mode = mode; 1206 1175 1207 1176 maintenance_mode_update(intf); 1208 1177 } ··· 1211 1184 } 1212 1185 EXPORT_SYMBOL(ipmi_set_maintenance_mode); 1213 1186 1214 - int ipmi_set_gets_events(ipmi_user_t user, int val) 1187 + int ipmi_set_gets_events(ipmi_user_t user, bool val) 1215 1188 { 1216 1189 unsigned long flags; 1217 1190 ipmi_smi_t intf = user->intf; ··· 1221 1194 INIT_LIST_HEAD(&msgs); 1222 1195 1223 1196 spin_lock_irqsave(&intf->events_lock, flags); 1197 + if (user->gets_events == val) 1198 + goto out; 1199 + 1224 1200 user->gets_events = val; 1201 + 1202 + if (val) { 1203 + if (atomic_inc_return(&intf->event_waiters) == 1) 1204 + need_waiter(intf); 1205 + } else { 1206 + atomic_dec(&intf->event_waiters); 1207 + } 1225 1208 1226 1209 if (intf->delivering_events) 1227 1210 /* ··· 1326 1289 goto out_unlock; 1327 1290 } 1328 1291 1292 + if (atomic_inc_return(&intf->event_waiters) == 1) 1293 + need_waiter(intf); 1294 + 1329 1295 list_add_rcu(&rcvr->link, &intf->cmd_rcvrs); 1330 1296 1331 1297 out_unlock: ··· 1370 1330 mutex_unlock(&intf->cmd_rcvrs_mutex); 1371 1331 synchronize_rcu(); 1372 1332 while (rcvrs) { 1333 + atomic_dec(&intf->event_waiters); 1373 1334 rcvr = rcvrs; 1374 1335 rcvrs = rcvr->next; 1375 1336 kfree(rcvr); ··· 1576 1535 = IPMI_MAINTENANCE_MODE_TIMEOUT; 1577 1536 if (!intf->maintenance_mode 1578 1537 && !intf->maintenance_mode_enable) { 1579 - intf->maintenance_mode_enable = 1; 1538 + intf->maintenance_mode_enable = true; 1580 1539 maintenance_mode_update(intf); 1581 1540 } 1582 1541 spin_unlock_irqrestore(&intf->maintenance_mode_lock, ··· 2917 2876 (unsigned long) intf); 2918 2877 atomic_set(&intf->watchdog_pretimeouts_to_deliver, 0); 2919 2878 spin_lock_init(&intf->events_lock); 2879 + atomic_set(&intf->event_waiters, 0); 2880 + intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME; 2920 2881 INIT_LIST_HEAD(&intf->waiting_events); 2921 2882 intf->waiting_events_count = 0; 2922 2883 mutex_init(&intf->cmd_rcvrs_mutex); ··· 4008 3965 4009 3966 static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, 4010 3967 struct list_head *timeouts, long timeout_period, 4011 - int slot, unsigned long *flags) 3968 + int slot, unsigned long *flags, 3969 + unsigned int *waiting_msgs) 4012 3970 { 4013 3971 struct ipmi_recv_msg *msg; 4014 3972 struct ipmi_smi_handlers *handlers; ··· 4021 3977 return; 4022 3978 4023 3979 ent->timeout -= timeout_period; 4024 - if (ent->timeout > 0) 3980 + if (ent->timeout > 0) { 3981 + (*waiting_msgs)++; 4025 3982 return; 3983 + } 4026 3984 4027 3985 if (ent->retries_left == 0) { 4028 3986 /* The message has used all its retries. */ ··· 4040 3994 } else { 4041 3995 struct ipmi_smi_msg *smi_msg; 4042 3996 /* More retries, send again. */ 3997 + 3998 + (*waiting_msgs)++; 4043 3999 4044 4000 /* 4045 4001 * Start with the max timer, set to normal timer after ··· 4088 4040 } 4089 4041 } 4090 4042 4091 - static void ipmi_timeout_handler(long timeout_period) 4043 + static unsigned int ipmi_timeout_handler(ipmi_smi_t intf, long timeout_period) 4092 4044 { 4093 - ipmi_smi_t intf; 4094 4045 struct list_head timeouts; 4095 4046 struct ipmi_recv_msg *msg, *msg2; 4096 4047 unsigned long flags; 4097 4048 int i; 4049 + unsigned int waiting_msgs = 0; 4098 4050 4099 - rcu_read_lock(); 4100 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 4101 - tasklet_schedule(&intf->recv_tasklet); 4051 + /* 4052 + * Go through the seq table and find any messages that 4053 + * have timed out, putting them in the timeouts 4054 + * list. 4055 + */ 4056 + INIT_LIST_HEAD(&timeouts); 4057 + spin_lock_irqsave(&intf->seq_lock, flags); 4058 + for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) 4059 + check_msg_timeout(intf, &(intf->seq_table[i]), 4060 + &timeouts, timeout_period, i, 4061 + &flags, &waiting_msgs); 4062 + spin_unlock_irqrestore(&intf->seq_lock, flags); 4102 4063 4103 - /* 4104 - * Go through the seq table and find any messages that 4105 - * have timed out, putting them in the timeouts 4106 - * list. 4107 - */ 4108 - INIT_LIST_HEAD(&timeouts); 4109 - spin_lock_irqsave(&intf->seq_lock, flags); 4110 - for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) 4111 - check_msg_timeout(intf, &(intf->seq_table[i]), 4112 - &timeouts, timeout_period, i, 4113 - &flags); 4114 - spin_unlock_irqrestore(&intf->seq_lock, flags); 4064 + list_for_each_entry_safe(msg, msg2, &timeouts, link) 4065 + deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE); 4115 4066 4116 - list_for_each_entry_safe(msg, msg2, &timeouts, link) 4117 - deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE); 4118 - 4119 - /* 4120 - * Maintenance mode handling. Check the timeout 4121 - * optimistically before we claim the lock. It may 4122 - * mean a timeout gets missed occasionally, but that 4123 - * only means the timeout gets extended by one period 4124 - * in that case. No big deal, and it avoids the lock 4125 - * most of the time. 4126 - */ 4067 + /* 4068 + * Maintenance mode handling. Check the timeout 4069 + * optimistically before we claim the lock. It may 4070 + * mean a timeout gets missed occasionally, but that 4071 + * only means the timeout gets extended by one period 4072 + * in that case. No big deal, and it avoids the lock 4073 + * most of the time. 4074 + */ 4075 + if (intf->auto_maintenance_timeout > 0) { 4076 + spin_lock_irqsave(&intf->maintenance_mode_lock, flags); 4127 4077 if (intf->auto_maintenance_timeout > 0) { 4128 - spin_lock_irqsave(&intf->maintenance_mode_lock, flags); 4129 - if (intf->auto_maintenance_timeout > 0) { 4130 - intf->auto_maintenance_timeout 4131 - -= timeout_period; 4132 - if (!intf->maintenance_mode 4133 - && (intf->auto_maintenance_timeout <= 0)) { 4134 - intf->maintenance_mode_enable = 0; 4135 - maintenance_mode_update(intf); 4136 - } 4078 + intf->auto_maintenance_timeout 4079 + -= timeout_period; 4080 + if (!intf->maintenance_mode 4081 + && (intf->auto_maintenance_timeout <= 0)) { 4082 + intf->maintenance_mode_enable = false; 4083 + maintenance_mode_update(intf); 4137 4084 } 4138 - spin_unlock_irqrestore(&intf->maintenance_mode_lock, 4139 - flags); 4140 4085 } 4086 + spin_unlock_irqrestore(&intf->maintenance_mode_lock, 4087 + flags); 4141 4088 } 4142 - rcu_read_unlock(); 4089 + 4090 + tasklet_schedule(&intf->recv_tasklet); 4091 + 4092 + return waiting_msgs; 4143 4093 } 4144 4094 4145 - static void ipmi_request_event(void) 4095 + static void ipmi_request_event(ipmi_smi_t intf) 4146 4096 { 4147 - ipmi_smi_t intf; 4148 4097 struct ipmi_smi_handlers *handlers; 4149 4098 4150 - rcu_read_lock(); 4151 - /* 4152 - * Called from the timer, no need to check if handlers is 4153 - * valid. 4154 - */ 4155 - list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 4156 - /* No event requests when in maintenance mode. */ 4157 - if (intf->maintenance_mode_enable) 4158 - continue; 4099 + /* No event requests when in maintenance mode. */ 4100 + if (intf->maintenance_mode_enable) 4101 + return; 4159 4102 4160 - handlers = intf->handlers; 4161 - if (handlers) 4162 - handlers->request_events(intf->send_info); 4163 - } 4164 - rcu_read_unlock(); 4103 + handlers = intf->handlers; 4104 + if (handlers) 4105 + handlers->request_events(intf->send_info); 4165 4106 } 4166 4107 4167 4108 static struct timer_list ipmi_timer; 4168 4109 4169 - /* Call every ~1000 ms. */ 4170 - #define IPMI_TIMEOUT_TIME 1000 4171 - 4172 - /* How many jiffies does it take to get to the timeout time. */ 4173 - #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000) 4174 - 4175 - /* 4176 - * Request events from the queue every second (this is the number of 4177 - * IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the 4178 - * future, IPMI will add a way to know immediately if an event is in 4179 - * the queue and this silliness can go away. 4180 - */ 4181 - #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME)) 4182 - 4183 4110 static atomic_t stop_operation; 4184 - static unsigned int ticks_to_req_ev = IPMI_REQUEST_EV_TIME; 4185 4111 4186 4112 static void ipmi_timeout(unsigned long data) 4187 4113 { 4114 + ipmi_smi_t intf; 4115 + int nt = 0; 4116 + 4188 4117 if (atomic_read(&stop_operation)) 4189 4118 return; 4190 4119 4191 - ticks_to_req_ev--; 4192 - if (ticks_to_req_ev == 0) { 4193 - ipmi_request_event(); 4194 - ticks_to_req_ev = IPMI_REQUEST_EV_TIME; 4120 + rcu_read_lock(); 4121 + list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 4122 + int lnt = 0; 4123 + 4124 + if (atomic_read(&intf->event_waiters)) { 4125 + intf->ticks_to_req_ev--; 4126 + if (intf->ticks_to_req_ev == 0) { 4127 + ipmi_request_event(intf); 4128 + intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME; 4129 + } 4130 + lnt++; 4131 + } 4132 + 4133 + lnt += ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME); 4134 + 4135 + lnt = !!lnt; 4136 + if (lnt != intf->last_needs_timer && 4137 + intf->handlers->set_need_watch) 4138 + intf->handlers->set_need_watch(intf->send_info, lnt); 4139 + intf->last_needs_timer = lnt; 4140 + 4141 + nt += lnt; 4195 4142 } 4143 + rcu_read_unlock(); 4196 4144 4197 - ipmi_timeout_handler(IPMI_TIMEOUT_TIME); 4198 - 4199 - mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); 4145 + if (nt) 4146 + mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); 4200 4147 } 4201 4148 4149 + static void need_waiter(ipmi_smi_t intf) 4150 + { 4151 + /* Racy, but worst case we start the timer twice. */ 4152 + if (!timer_pending(&ipmi_timer)) 4153 + mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); 4154 + } 4202 4155 4203 4156 static atomic_t smi_msg_inuse_count = ATOMIC_INIT(0); 4204 4157 static atomic_t recv_msg_inuse_count = ATOMIC_INIT(0);
+91 -54
drivers/char/ipmi/ipmi_si_intf.c
··· 217 217 unsigned char msg_flags; 218 218 219 219 /* Does the BMC have an event buffer? */ 220 - char has_event_buffer; 220 + bool has_event_buffer; 221 221 222 222 /* 223 223 * If set to true, this will request events the next time the ··· 230 230 * call. Generally used after a panic to make sure stuff goes 231 231 * out. 232 232 */ 233 - int run_to_completion; 233 + bool run_to_completion; 234 234 235 235 /* The I/O port of an SI interface. */ 236 236 int port; ··· 248 248 /* The timer for this si. */ 249 249 struct timer_list si_timer; 250 250 251 + /* This flag is set, if the timer is running (timer_pending() isn't enough) */ 252 + bool timer_running; 253 + 251 254 /* The time (in jiffies) the last timeout occurred at. */ 252 255 unsigned long last_timeout_jiffies; 253 256 254 257 /* Used to gracefully stop the timer without race conditions. */ 255 258 atomic_t stop_operation; 259 + 260 + /* Are we waiting for the events, pretimeouts, received msgs? */ 261 + atomic_t need_watch; 256 262 257 263 /* 258 264 * The driver will disable interrupts when it gets into a ··· 266 260 * memory. Once that situation clears up, it will re-enable 267 261 * interrupts. 268 262 */ 269 - int interrupt_disabled; 263 + bool interrupt_disabled; 270 264 271 265 /* From the get device id response... */ 272 266 struct ipmi_device_id device_id; ··· 279 273 * True if we allocated the device, false if it came from 280 274 * someplace else (like PCI). 281 275 */ 282 - int dev_registered; 276 + bool dev_registered; 283 277 284 278 /* Slave address, could be reported from DMI. */ 285 279 unsigned char slave_addr; ··· 303 297 static int force_kipmid[SI_MAX_PARMS]; 304 298 static int num_force_kipmid; 305 299 #ifdef CONFIG_PCI 306 - static int pci_registered; 300 + static bool pci_registered; 307 301 #endif 308 302 #ifdef CONFIG_ACPI 309 - static int pnp_registered; 303 + static bool pnp_registered; 310 304 #endif 311 305 #ifdef CONFIG_PARISC 312 - static int parisc_registered; 306 + static bool parisc_registered; 313 307 #endif 314 308 315 309 static unsigned int kipmid_max_busy_us[SI_MAX_PARMS]; 316 310 static int num_max_busy_us; 317 311 318 - static int unload_when_empty = 1; 312 + static bool unload_when_empty = true; 319 313 320 314 static int add_smi(struct smi_info *smi); 321 315 static int try_smi_init(struct smi_info *smi); ··· 440 434 smi_info->si_state = SI_CLEARING_FLAGS; 441 435 } 442 436 437 + static void smi_mod_timer(struct smi_info *smi_info, unsigned long new_val) 438 + { 439 + smi_info->last_timeout_jiffies = jiffies; 440 + mod_timer(&smi_info->si_timer, new_val); 441 + smi_info->timer_running = true; 442 + } 443 + 443 444 /* 444 445 * When we have a situtaion where we run out of memory and cannot 445 446 * allocate messages, we just leave them in the BMC and run the system ··· 457 444 { 458 445 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { 459 446 start_disable_irq(smi_info); 460 - smi_info->interrupt_disabled = 1; 447 + smi_info->interrupt_disabled = true; 461 448 if (!atomic_read(&smi_info->stop_operation)) 462 - mod_timer(&smi_info->si_timer, 463 - jiffies + SI_TIMEOUT_JIFFIES); 449 + smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES); 464 450 } 465 451 } 466 452 ··· 467 455 { 468 456 if ((smi_info->irq) && (smi_info->interrupt_disabled)) { 469 457 start_enable_irq(smi_info); 470 - smi_info->interrupt_disabled = 0; 458 + smi_info->interrupt_disabled = false; 471 459 } 472 460 } 473 461 ··· 712 700 dev_warn(smi_info->dev, 713 701 "Maybe ok, but ipmi might run very slowly.\n"); 714 702 } else 715 - smi_info->interrupt_disabled = 0; 703 + smi_info->interrupt_disabled = false; 716 704 smi_info->si_state = SI_NORMAL; 717 705 break; 718 706 } ··· 865 853 return si_sm_result; 866 854 } 867 855 856 + static void check_start_timer_thread(struct smi_info *smi_info) 857 + { 858 + if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) { 859 + smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES); 860 + 861 + if (smi_info->thread) 862 + wake_up_process(smi_info->thread); 863 + 864 + start_next_msg(smi_info); 865 + smi_event_handler(smi_info, 0); 866 + } 867 + } 868 + 868 869 static void sender(void *send_info, 869 870 struct ipmi_smi_msg *msg, 870 871 int priority) ··· 931 906 else 932 907 list_add_tail(&msg->link, &smi_info->xmit_msgs); 933 908 934 - if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) { 935 - /* 936 - * last_timeout_jiffies is updated here to avoid 937 - * smi_timeout() handler passing very large time_diff 938 - * value to smi_event_handler() that causes 939 - * the send command to abort. 940 - */ 941 - smi_info->last_timeout_jiffies = jiffies; 942 - 943 - mod_timer(&smi_info->si_timer, jiffies + SI_TIMEOUT_JIFFIES); 944 - 945 - if (smi_info->thread) 946 - wake_up_process(smi_info->thread); 947 - 948 - start_next_msg(smi_info); 949 - smi_event_handler(smi_info, 0); 950 - } 909 + check_start_timer_thread(smi_info); 951 910 spin_unlock_irqrestore(&smi_info->si_lock, flags); 952 911 } 953 912 954 - static void set_run_to_completion(void *send_info, int i_run_to_completion) 913 + static void set_run_to_completion(void *send_info, bool i_run_to_completion) 955 914 { 956 915 struct smi_info *smi_info = send_info; 957 916 enum si_sm_result result; ··· 1013 1004 1014 1005 spin_lock_irqsave(&(smi_info->si_lock), flags); 1015 1006 smi_result = smi_event_handler(smi_info, 0); 1007 + 1008 + /* 1009 + * If the driver is doing something, there is a possible 1010 + * race with the timer. If the timer handler see idle, 1011 + * and the thread here sees something else, the timer 1012 + * handler won't restart the timer even though it is 1013 + * required. So start it here if necessary. 1014 + */ 1015 + if (smi_result != SI_SM_IDLE && !smi_info->timer_running) 1016 + smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES); 1017 + 1016 1018 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 1017 1019 busy_wait = ipmi_thread_busy_wait(smi_result, smi_info, 1018 1020 &busy_until); ··· 1031 1011 ; /* do nothing */ 1032 1012 else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait) 1033 1013 schedule(); 1034 - else if (smi_result == SI_SM_IDLE) 1035 - schedule_timeout_interruptible(100); 1036 - else 1014 + else if (smi_result == SI_SM_IDLE) { 1015 + if (atomic_read(&smi_info->need_watch)) { 1016 + schedule_timeout_interruptible(100); 1017 + } else { 1018 + /* Wait to be woken up when we are needed. */ 1019 + __set_current_state(TASK_INTERRUPTIBLE); 1020 + schedule(); 1021 + } 1022 + } else 1037 1023 schedule_timeout_interruptible(1); 1038 1024 } 1039 1025 return 0; ··· 1050 1024 { 1051 1025 struct smi_info *smi_info = send_info; 1052 1026 unsigned long flags = 0; 1053 - int run_to_completion = smi_info->run_to_completion; 1027 + bool run_to_completion = smi_info->run_to_completion; 1054 1028 1055 1029 /* 1056 1030 * Make sure there is some delay in the poll loop so we can ··· 1073 1047 return; 1074 1048 1075 1049 atomic_set(&smi_info->req_events, 1); 1050 + } 1051 + 1052 + static void set_need_watch(void *send_info, bool enable) 1053 + { 1054 + struct smi_info *smi_info = send_info; 1055 + unsigned long flags; 1056 + 1057 + atomic_set(&smi_info->need_watch, enable); 1058 + spin_lock_irqsave(&smi_info->si_lock, flags); 1059 + check_start_timer_thread(smi_info); 1060 + spin_unlock_irqrestore(&smi_info->si_lock, flags); 1076 1061 } 1077 1062 1078 1063 static int initialized; ··· 1110 1073 * SI_USEC_PER_JIFFY); 1111 1074 smi_result = smi_event_handler(smi_info, time_diff); 1112 1075 1113 - spin_unlock_irqrestore(&(smi_info->si_lock), flags); 1114 - 1115 - smi_info->last_timeout_jiffies = jiffies_now; 1116 - 1117 1076 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { 1118 1077 /* Running with interrupts, only do long timeouts. */ 1119 1078 timeout = jiffies + SI_TIMEOUT_JIFFIES; ··· 1131 1098 1132 1099 do_mod_timer: 1133 1100 if (smi_result != SI_SM_IDLE) 1134 - mod_timer(&(smi_info->si_timer), timeout); 1101 + smi_mod_timer(smi_info, timeout); 1102 + else 1103 + smi_info->timer_running = false; 1104 + spin_unlock_irqrestore(&(smi_info->si_lock), flags); 1135 1105 } 1136 1106 1137 1107 static irqreturn_t si_irq_handler(int irq, void *data) ··· 1182 1146 1183 1147 /* Set up the timer that drives the interface. */ 1184 1148 setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi); 1185 - new_smi->last_timeout_jiffies = jiffies; 1186 - mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); 1149 + smi_mod_timer(new_smi, jiffies + SI_TIMEOUT_JIFFIES); 1187 1150 1188 1151 /* 1189 1152 * Check if the user forcefully enabled the daemon. ··· 1223 1188 return 0; 1224 1189 } 1225 1190 1226 - static void set_maintenance_mode(void *send_info, int enable) 1191 + static void set_maintenance_mode(void *send_info, bool enable) 1227 1192 { 1228 1193 struct smi_info *smi_info = send_info; 1229 1194 ··· 1237 1202 .get_smi_info = get_smi_info, 1238 1203 .sender = sender, 1239 1204 .request_events = request_events, 1205 + .set_need_watch = set_need_watch, 1240 1206 .set_maintenance_mode = set_maintenance_mode, 1241 1207 .set_run_to_completion = set_run_to_completion, 1242 1208 .poll = poll, ··· 1265 1229 #ifdef CONFIG_PCI 1266 1230 static bool si_trypci = 1; 1267 1231 #endif 1268 - static bool si_trydefaults = 1; 1232 + static bool si_trydefaults = IS_ENABLED(CONFIG_IPMI_SI_PROBE_DEFAULTS); 1269 1233 static char *si_type[SI_MAX_PARMS]; 1270 1234 #define MAX_SI_TYPE_STR 30 1271 1235 static char si_type_str[MAX_SI_TYPE_STR]; ··· 1364 1328 MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or" 1365 1329 " disabled(0). Normally the IPMI driver auto-detects" 1366 1330 " this, but the value may be overridden by this parm."); 1367 - module_param(unload_when_empty, int, 0); 1331 + module_param(unload_when_empty, bool, 0); 1368 1332 MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are" 1369 1333 " specified or found, default is 1. Setting to 0" 1370 1334 " is useful for hot add of devices using hotmod."); ··· 3372 3336 INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs)); 3373 3337 new_smi->curr_msg = NULL; 3374 3338 atomic_set(&new_smi->req_events, 0); 3375 - new_smi->run_to_completion = 0; 3339 + new_smi->run_to_completion = false; 3376 3340 for (i = 0; i < SI_NUM_STATS; i++) 3377 3341 atomic_set(&new_smi->stats[i], 0); 3378 3342 3379 - new_smi->interrupt_disabled = 1; 3343 + new_smi->interrupt_disabled = true; 3380 3344 atomic_set(&new_smi->stop_operation, 0); 3345 + atomic_set(&new_smi->need_watch, 0); 3381 3346 new_smi->intf_num = smi_num; 3382 3347 smi_num++; 3383 3348 3384 3349 rv = try_enable_event_buffer(new_smi); 3385 3350 if (rv == 0) 3386 - new_smi->has_event_buffer = 1; 3351 + new_smi->has_event_buffer = true; 3387 3352 3388 3353 /* 3389 3354 * Start clearing the flags before we enable interrupts or the ··· 3418 3381 rv); 3419 3382 goto out_err; 3420 3383 } 3421 - new_smi->dev_registered = 1; 3384 + new_smi->dev_registered = true; 3422 3385 } 3423 3386 3424 3387 rv = ipmi_register_smi(&handlers, ··· 3467 3430 wait_for_timer_and_thread(new_smi); 3468 3431 3469 3432 out_err: 3470 - new_smi->interrupt_disabled = 1; 3433 + new_smi->interrupt_disabled = true; 3471 3434 3472 3435 if (new_smi->intf) { 3473 3436 ipmi_unregister_smi(new_smi->intf); ··· 3503 3466 3504 3467 if (new_smi->dev_registered) { 3505 3468 platform_device_unregister(new_smi->pdev); 3506 - new_smi->dev_registered = 0; 3469 + new_smi->dev_registered = false; 3507 3470 } 3508 3471 3509 3472 return rv; ··· 3558 3521 printk(KERN_ERR PFX "Unable to register " 3559 3522 "PCI driver: %d\n", rv); 3560 3523 else 3561 - pci_registered = 1; 3524 + pci_registered = true; 3562 3525 } 3563 3526 #endif 3564 3527 3565 3528 #ifdef CONFIG_ACPI 3566 3529 if (si_tryacpi) { 3567 3530 pnp_register_driver(&ipmi_pnp_driver); 3568 - pnp_registered = 1; 3531 + pnp_registered = true; 3569 3532 } 3570 3533 #endif 3571 3534 ··· 3581 3544 3582 3545 #ifdef CONFIG_PARISC 3583 3546 register_parisc_driver(&ipmi_parisc_driver); 3584 - parisc_registered = 1; 3547 + parisc_registered = true; 3585 3548 /* poking PC IO addresses will crash machine, don't do it */ 3586 3549 si_trydefaults = 0; 3587 3550 #endif
+1 -1
include/linux/ipmi.h
··· 237 237 * The first user that sets this to TRUE will receive all events that 238 238 * have been queued while no one was waiting for events. 239 239 */ 240 - int ipmi_set_gets_events(ipmi_user_t user, int val); 240 + int ipmi_set_gets_events(ipmi_user_t user, bool val); 241 241 242 242 /* 243 243 * Called when a new SMI is registered. This will also be called on
+9 -2
include/linux/ipmi_smi.h
··· 109 109 events from the BMC we are attached to. */ 110 110 void (*request_events)(void *send_info); 111 111 112 + /* Called by the upper layer when some user requires that the 113 + interface watch for events, received messages, watchdog 114 + pretimeouts, or not. Used by the SMI to know if it should 115 + watch for these. This may be NULL if the SMI does not 116 + implement it. */ 117 + void (*set_need_watch)(void *send_info, bool enable); 118 + 112 119 /* Called when the interface should go into "run to 113 120 completion" mode. If this call sets the value to true, the 114 121 interface should make sure that all messages are flushed 115 122 out and that none are pending, and any new requests are run 116 123 to completion immediately. */ 117 - void (*set_run_to_completion)(void *send_info, int run_to_completion); 124 + void (*set_run_to_completion)(void *send_info, bool run_to_completion); 118 125 119 126 /* Called to poll for work to do. This is so upper layers can 120 127 poll for operations during things like crash dumps. */ ··· 132 125 setting. The message handler does the mode handling. Note 133 126 that this is called from interrupt context, so it cannot 134 127 block. */ 135 - void (*set_maintenance_mode)(void *send_info, int enable); 128 + void (*set_maintenance_mode)(void *send_info, bool enable); 136 129 137 130 /* Tell the handler that we are using it/not using it. The 138 131 message handler get the modules that this handler belongs