| @@ -529,9 +529,22 @@ struct ipmi_smi { · 528 unmodified lines |
| 529 | 529 | unsigned int waiting_events_count; /* How many events in queue? */ |
| 530 | 530 | char delivering_events; |
| 531 | 531 | char event_msg_printed; |
| 532 | + |
| 533 | + /* How many users are waiting for events? */ |
| 532 | 534 | atomic_t event_waiters; |
| 533 | 535 | unsigned int ticks_to_req_ev; |
| 534 | | − int last_needs_timer; |
| 536 | + |
| 537 | + /* How many users are waiting for commands? */ |
| 538 | + atomic_t command_waiters; |
| 539 | + |
| 540 | + /* How many users are waiting for watchdogs? */ |
| 541 | + atomic_t watchdog_waiters; |
| 542 | + |
| 543 | + /* |
| 544 | + * Tells what the lower layer has last been asked to watch for, |
| 545 | + * messages and/or watchdogs. Protected by xmit_msgs_lock. |
| 546 | + */ |
| 547 | + unsigned int last_watch_mask; |
| 535 | 548 | |
| 536 | 549 | /* |
| 537 | 550 | * The event receiver for my BMC, only really used at panic |
| @@ -1078,6 +1091,29 @@ static int intf_err_seq(struct ipmi_smi *intf, · 540 unmodified lines |
| 1078 | 1091 | return rv; |
| 1079 | 1092 | } |
| 1080 | 1093 | |
| 1094 | +/* Must be called with xmit_msgs_lock held. */ |
| 1095 | +static void smi_tell_to_watch(struct ipmi_smi *intf, |
| 1096 | + unsigned int flags, |
| 1097 | + struct ipmi_smi_msg *smi_msg) |
| 1098 | +{ |
| 1099 | + if (flags & IPMI_WATCH_MASK_CHECK_MESSAGES) { |
| 1100 | + if (!smi_msg) |
| 1101 | + return; |
| 1102 | + |
| 1103 | + if (!smi_msg->needs_response) |
| 1104 | + return; |
| 1105 | + } |
| 1106 | + |
| 1107 | + if (!intf->handlers->set_need_watch) |
| 1108 | + return; |
| 1109 | + |
| 1110 | + if ((intf->last_watch_mask & flags) == flags) |
| 1111 | + return; |
| 1112 | + |
| 1113 | + intf->last_watch_mask |= flags; |
| 1114 | + intf->handlers->set_need_watch(intf->send_info, |
| 1115 | + intf->last_watch_mask); |
| 1116 | +} |
| 1081 | 1117 | |
| 1082 | 1118 | int ipmi_create_user(unsigned int if_num, |
| 1083 | 1119 | const struct ipmi_user_hndl *handler, |
| @@ -1141,8 +1177,9 @@ int ipmi_create_user(unsigned int if_num, · 57 unmodified lines |
| 1141 | 1177 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
| 1142 | 1178 | if (handler->ipmi_watchdog_pretimeout) { |
| 1143 | 1179 | /* User wants pretimeouts, so make sure to watch for them. */ |
| 1144 | | − if (atomic_inc_return(&intf->event_waiters) == 1) |
| 1145 | | − need_waiter(intf); |
| 1180 | + if (atomic_inc_return(&intf->watchdog_waiters) == 1) |
| 1181 | + smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG, |
| 1182 | + NULL); |
| 1146 | 1183 | } |
| 1147 | 1184 | srcu_read_unlock(&ipmi_interfaces_srcu, index); |
| 1148 | 1185 | *user = new_user; |
| @@ -1214,7 +1251,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user) · 65 unmodified lines |
| 1214 | 1251 | user->handler->shutdown(user->handler_data); |
| 1215 | 1252 | |
| 1216 | 1253 | if (user->handler->ipmi_watchdog_pretimeout) |
| 1217 | | − atomic_dec(&intf->event_waiters); |
| 1254 | + atomic_dec(&intf->watchdog_waiters); |
| 1218 | 1255 | |
| 1219 | 1256 | if (user->gets_events) |
| 1220 | 1257 | atomic_dec(&intf->event_waiters); |
| @@ -1569,8 +1606,8 @@ int ipmi_register_for_cmd(struct ipmi_user *user, · 348 unmodified lines |
| 1569 | 1606 | goto out_unlock; |
| 1570 | 1607 | } |
| 1571 | 1608 | |
| 1572 | | − if (atomic_inc_return(&intf->event_waiters) == 1) |
| 1573 | | − need_waiter(intf); |
| 1609 | + if (atomic_inc_return(&intf->command_waiters) == 1) |
| 1610 | + smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_COMMANDS, NULL); |
| 1574 | 1611 | |
| 1575 | 1612 | list_add_rcu(&rcvr->link, &intf->cmd_rcvrs); |
| 1576 | 1613 | |
| @@ -1620,7 +1657,7 @@ int ipmi_unregister_for_cmd(struct ipmi_user *user, · 43 unmodified lines |
| 1620 | 1657 | synchronize_rcu(); |
| 1621 | 1658 | release_ipmi_user(user, index); |
| 1622 | 1659 | while (rcvrs) { |
| 1623 | | − atomic_dec(&intf->event_waiters); |
| 1660 | + atomic_dec(&intf->command_waiters); |
| 1624 | 1661 | rcvr = rcvrs; |
| 1625 | 1662 | rcvrs = rcvr->next; |
| 1626 | 1663 | kfree(rcvr); |
| @@ -1737,22 +1774,21 @@ static struct ipmi_smi_msg *smi_add_send_msg(struct ipmi_smi *intf, · 110 unmodified lines |
| 1737 | 1774 | return smi_msg; |
| 1738 | 1775 | } |
| 1739 | 1776 | |
| 1740 | | − |
| 1741 | 1777 | static void smi_send(struct ipmi_smi *intf, |
| 1742 | 1778 | const struct ipmi_smi_handlers *handlers, |
| 1743 | 1779 | struct ipmi_smi_msg *smi_msg, int priority) |
| 1744 | 1780 | { |
| 1745 | 1781 | int run_to_completion = intf->run_to_completion; |
| 1782 | + unsigned long flags = 0; |
| 1746 | 1783 | |
| 1747 | | − if (run_to_completion) { |
| 1748 | | − smi_msg = smi_add_send_msg(intf, smi_msg, priority); |
| 1749 | | − } else { |
| 1750 | | − unsigned long flags; |
| 1751 | | − |
| 1784 | + if (!run_to_completion) |
| 1752 | 1785 | spin_lock_irqsave(&intf->xmit_msgs_lock, flags); |
| 1753 | | − smi_msg = smi_add_send_msg(intf, smi_msg, priority); |
| 1786 | + smi_msg = smi_add_send_msg(intf, smi_msg, priority); |
| 1787 | + |
| 1788 | + smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES, smi_msg); |
| 1789 | + |
| 1790 | + if (!run_to_completion) |
| 1754 | 1791 | spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); |
| 1755 | | − } |
| 1756 | 1792 | |
| 1757 | 1793 | if (smi_msg) |
| 1758 | 1794 | handlers->sender(intf->send_info, smi_msg); |
| @@ -1950,6 +1986,9 @@ static int i_ipmi_req_ipmb(struct ipmi_smi *intf, · 191 unmodified lines |
| 1950 | 1986 | ipmb_seq, broadcast, |
| 1951 | 1987 | source_address, source_lun); |
| 1952 | 1988 | |
| 1989 | + /* We will be getting a response in the BMC message queue. */ |
| 1990 | + smi_msg->needs_response = true; |
| 1991 | + |
| 1953 | 1992 | /* |
| 1954 | 1993 | * Copy the message into the recv message data, so we |
| 1955 | 1994 | * can retransmit it later if necessary. |
| @@ -2137,6 +2176,7 @@ static int i_ipmi_request(struct ipmi_user *user, · 181 unmodified lines |
| 2137 | 2176 | goto out; |
| 2138 | 2177 | } |
| 2139 | 2178 | } |
| 2179 | + smi_msg->needs_response = false; |
| 2140 | 2180 | |
| 2141 | 2181 | rcu_read_lock(); |
| 2142 | 2182 | if (intf->in_shutdown) { |
| @@ -3351,6 +3391,8 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, · 1208 unmodified lines |
| 3351 | 3391 | INIT_LIST_HEAD(&intf->hp_xmit_msgs); |
| 3352 | 3392 | spin_lock_init(&intf->events_lock); |
| 3353 | 3393 | atomic_set(&intf->event_waiters, 0); |
| 3394 | + atomic_set(&intf->watchdog_waiters, 0); |
| 3395 | + atomic_set(&intf->command_waiters, 0); |
| 3354 | 3396 | intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME; |
| 3355 | 3397 | INIT_LIST_HEAD(&intf->waiting_events); |
| 3356 | 3398 | intf->waiting_events_count = 0; |
| @@ -4365,6 +4407,9 @@ static void smi_recv_tasklet(unsigned long val) · 1008 unmodified lines |
| 4365 | 4407 | intf->curr_msg = newmsg; |
| 4366 | 4408 | } |
| 4367 | 4409 | } |
| 4410 | + |
| 4411 | + smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES, newmsg); |
| 4412 | + |
| 4368 | 4413 | if (!run_to_completion) |
| 4369 | 4414 | spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); |
| 4370 | 4415 | if (newmsg) |
| @@ -4492,7 +4537,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 121 unmodified lines |
| 4492 | 4537 | struct list_head *timeouts, |
| 4493 | 4538 | unsigned long timeout_period, |
| 4494 | 4539 | int slot, unsigned long *flags, |
| 4495 | | − unsigned int *waiting_msgs) |
| 4540 | + unsigned int *watch_mask) |
| 4496 | 4541 | { |
| 4497 | 4542 | struct ipmi_recv_msg *msg; |
| 4498 | 4543 | |
| @@ -4504,7 +4549,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 5 unmodified lines |
| 4504 | 4549 | |
| 4505 | 4550 | if (timeout_period < ent->timeout) { |
| 4506 | 4551 | ent->timeout -= timeout_period; |
| 4507 | | − (*waiting_msgs)++; |
| 4552 | + *watch_mask |= IPMI_WATCH_MASK_CHECK_MESSAGES; |
| 4508 | 4553 | return; |
| 4509 | 4554 | } |
| 4510 | 4555 | |
| @@ -4523,7 +4568,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 12 unmodified lines |
| 4523 | 4568 | struct ipmi_smi_msg *smi_msg; |
| 4524 | 4569 | /* More retries, send again. */ |
| 4525 | 4570 | |
| 4526 | | − (*waiting_msgs)++; |
| 4571 | + *watch_mask |= IPMI_WATCH_MASK_CHECK_MESSAGES; |
| 4527 | 4572 | |
| 4528 | 4573 | /* |
| 4529 | 4574 | * Start with the max timer, set to normal timer after |
| @@ -4575,13 +4620,13 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 45 unmodified lines |
| 4575 | 4620 | struct ipmi_recv_msg *msg, *msg2; |
| 4576 | 4621 | unsigned long flags; |
| 4577 | 4622 | int i; |
| 4578 | | − unsigned int waiting_msgs = 0; |
| 4623 | + unsigned int watch_mask = 0; |
| 4579 | 4624 | |
| 4580 | 4625 | if (!intf->bmc_registered) { |
| 4581 | 4626 | kref_get(&intf->refcount); |
| 4582 | 4627 | if (!schedule_work(&intf->bmc_reg_work)) { |
| 4583 | 4628 | kref_put(&intf->refcount, intf_free); |
| 4584 | | − waiting_msgs++; |
| 4629 | + watch_mask |= IPMI_WATCH_MASK_INTERNAL; |
| 4585 | 4630 | } |
| 4586 | 4631 | } |
| 4587 | 4632 | |
| @@ -4601,7 +4646,7 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 13 unmodified lines |
| 4601 | 4646 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) |
| 4602 | 4647 | check_msg_timeout(intf, &intf->seq_table[i], |
| 4603 | 4648 | &timeouts, timeout_period, i, |
| 4604 | | − &flags, &waiting_msgs); |
| 4649 | + &flags, &watch_mask); |
| 4605 | 4650 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
| 4606 | 4651 | |
| 4607 | 4652 | list_for_each_entry_safe(msg, msg2, &timeouts, link) |
| @@ -4632,7 +4677,7 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 24 unmodified lines |
| 4632 | 4677 | |
| 4633 | 4678 | tasklet_schedule(&intf->recv_tasklet); |
| 4634 | 4679 | |
| 4635 | | − return waiting_msgs; |
| 4680 | + return watch_mask; |
| 4636 | 4681 | } |
| 4637 | 4682 | |
| 4638 | 4683 | static void ipmi_request_event(struct ipmi_smi *intf) |
| @@ -4652,37 +4697,43 @@ static atomic_t stop_operation; · 13 unmodified lines |
| 4652 | 4697 | static void ipmi_timeout(struct timer_list *unused) |
| 4653 | 4698 | { |
| 4654 | 4699 | struct ipmi_smi *intf; |
| 4655 | | − int nt = 0, index; |
| 4700 | + unsigned int watch_mask = 0; |
| 4701 | + int index; |
| 4702 | + unsigned long flags; |
| 4656 | 4703 | |
| 4657 | 4704 | if (atomic_read(&stop_operation)) |
| 4658 | 4705 | return; |
| 4659 | 4706 | |
| 4660 | 4707 | index = srcu_read_lock(&ipmi_interfaces_srcu); |
| 4661 | 4708 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
| 4662 | | − int lnt = 0; |
| 4663 | | − |
| 4664 | 4709 | if (atomic_read(&intf->event_waiters)) { |
| 4665 | 4710 | intf->ticks_to_req_ev--; |
| 4666 | 4711 | if (intf->ticks_to_req_ev == 0) { |
| 4667 | 4712 | ipmi_request_event(intf); |
| 4668 | 4713 | intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME; |
| 4669 | 4714 | } |
| 4670 | | − lnt++; |
| 4715 | + watch_mask |= IPMI_WATCH_MASK_INTERNAL; |
| 4671 | 4716 | } |
| 4672 | 4717 | |
| 4673 | | − lnt += ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME); |
| 4718 | + if (atomic_read(&intf->watchdog_waiters)) |
| 4719 | + watch_mask |= IPMI_WATCH_MASK_CHECK_WATCHDOG; |
| 4674 | 4720 | |
| 4675 | | − lnt = !!lnt; |
| 4676 | | − if (lnt != intf->last_needs_timer && |
| 4677 | | − intf->handlers->set_need_watch) |
| 4678 | | − intf->handlers->set_need_watch(intf->send_info, lnt); |
| 4679 | | − intf->last_needs_timer = lnt; |
| 4721 | + if (atomic_read(&intf->command_waiters)) |
| 4722 | + watch_mask |= IPMI_WATCH_MASK_CHECK_COMMANDS; |
| 4723 | + |
| 4724 | + watch_mask |= ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME); |
| 4680 | 4725 | |
| 4681 | | − nt += lnt; |
| 4726 | + spin_lock_irqsave(&intf->xmit_msgs_lock, flags); |
| 4727 | + if (watch_mask != intf->last_watch_mask && |
| 4728 | + intf->handlers->set_need_watch) |
| 4729 | + intf->handlers->set_need_watch(intf->send_info, |
| 4730 | + watch_mask); |
| 4731 | + intf->last_watch_mask = watch_mask; |
| 4732 | + spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); |
| 4682 | 4733 | } |
| 4683 | 4734 | srcu_read_unlock(&ipmi_interfaces_srcu, index); |
| 4684 | 4735 | |
| 4685 | | − if (nt) |
| 4736 | + if (watch_mask) |
| 4686 | 4737 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); |
| 4687 | 4738 | } |
| 4688 | 4739 | |