aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/ibmasm/r_heartbeat.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/misc/ibmasm/r_heartbeat.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/misc/ibmasm/r_heartbeat.c')
-rw-r--r--drivers/misc/ibmasm/r_heartbeat.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/drivers/misc/ibmasm/r_heartbeat.c b/drivers/misc/ibmasm/r_heartbeat.c
new file mode 100644
index 000000000000..93d9c1b2ad6f
--- /dev/null
+++ b/drivers/misc/ibmasm/r_heartbeat.c
@@ -0,0 +1,98 @@
1
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 * Copyright (C) IBM Corporation, 2004
18 *
19 * Author: Max Asböck <amax@us.ibm.com>
20 *
21 */
22
23#include "ibmasm.h"
24#include "dot_command.h"
25
26/*
27 * Reverse Heartbeat, i.e. heartbeats sent from the driver to the
28 * service processor.
29 * These heartbeats are initiated by user level programs.
30 */
31
32/* the reverse heartbeat dot command */
33#pragma pack(1)
34static struct {
35 struct dot_command_header header;
36 unsigned char command[3];
37} rhb_dot_cmd = {
38 .header = {
39 .type = sp_read,
40 .command_size = 3,
41 .data_size = 0,
42 .status = 0
43 },
44 .command = { 4, 3, 6 }
45};
46#pragma pack()
47
48void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
49{
50 init_waitqueue_head(&rhb->wait);
51 rhb->stopped = 0;
52}
53
54/**
55 * start_reverse_heartbeat
56 * Loop forever, sending a reverse heartbeat dot command to the service
57 * processor, then sleeping. The loop comes to an end if the service
58 * processor fails to respond 3 times or we were interrupted.
59 */
60int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
61{
62 struct command *cmd;
63 int times_failed = 0;
64 int result = 1;
65
66 cmd = ibmasm_new_command(sizeof rhb_dot_cmd);
67 if (!cmd)
68 return -ENOMEM;
69
70 while (times_failed < 3) {
71 memcpy(cmd->buffer, (void *)&rhb_dot_cmd, sizeof rhb_dot_cmd);
72 cmd->status = IBMASM_CMD_PENDING;
73 ibmasm_exec_command(sp, cmd);
74 ibmasm_wait_for_response(cmd, IBMASM_CMD_TIMEOUT_NORMAL);
75
76 if (cmd->status != IBMASM_CMD_COMPLETE)
77 times_failed++;
78
79 wait_event_interruptible_timeout(rhb->wait,
80 rhb->stopped,
81 REVERSE_HEARTBEAT_TIMEOUT * HZ);
82
83 if (signal_pending(current) || rhb->stopped) {
84 result = -EINTR;
85 break;
86 }
87 }
88 command_put(cmd);
89 rhb->stopped = 0;
90
91 return result;
92}
93
94void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb)
95{
96 rhb->stopped = 1;
97 wake_up_interruptible(&rhb->wait);
98}