blob: 5c7dd26db716f4409b542193d016533b006df463 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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 *
Al Virod36b6912011-12-29 17:09:01 -050019 * Author: Max Asböck <amax@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 *
21 */
22
Ingo Molnar174cd4b2017-02-02 19:15:33 +010023#include <linux/sched/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "ibmasm.h"
25#include "dot_command.h"
26
27/*
28 * Reverse Heartbeat, i.e. heartbeats sent from the driver to the
29 * service processor.
30 * These heartbeats are initiated by user level programs.
31 */
32
33/* the reverse heartbeat dot command */
34#pragma pack(1)
35static struct {
36 struct dot_command_header header;
37 unsigned char command[3];
38} rhb_dot_cmd = {
39 .header = {
Dmitry Torokhov3110dc72007-07-17 04:03:58 -070040 .type = sp_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 .command_size = 3,
42 .data_size = 0,
Dmitry Torokhov3110dc72007-07-17 04:03:58 -070043 .status = 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 },
45 .command = { 4, 3, 6 }
46};
47#pragma pack()
48
49void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
50{
51 init_waitqueue_head(&rhb->wait);
52 rhb->stopped = 0;
53}
54
55/**
56 * start_reverse_heartbeat
57 * Loop forever, sending a reverse heartbeat dot command to the service
58 * processor, then sleeping. The loop comes to an end if the service
59 * processor fails to respond 3 times or we were interrupted.
60 */
61int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
62{
63 struct command *cmd;
64 int times_failed = 0;
65 int result = 1;
66
Max Asbock88187602005-06-21 17:16:36 -070067 cmd = ibmasm_new_command(sp, sizeof rhb_dot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 if (!cmd)
69 return -ENOMEM;
70
71 while (times_failed < 3) {
72 memcpy(cmd->buffer, (void *)&rhb_dot_cmd, sizeof rhb_dot_cmd);
73 cmd->status = IBMASM_CMD_PENDING;
74 ibmasm_exec_command(sp, cmd);
75 ibmasm_wait_for_response(cmd, IBMASM_CMD_TIMEOUT_NORMAL);
76
77 if (cmd->status != IBMASM_CMD_COMPLETE)
78 times_failed++;
79
Dmitry Torokhov3110dc72007-07-17 04:03:58 -070080 wait_event_interruptible_timeout(rhb->wait,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 rhb->stopped,
Dmitry Torokhov3110dc72007-07-17 04:03:58 -070082 REVERSE_HEARTBEAT_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 if (signal_pending(current) || rhb->stopped) {
85 result = -EINTR;
86 break;
87 }
88 }
89 command_put(cmd);
90 rhb->stopped = 0;
91
92 return result;
93}
94
95void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb)
96{
97 rhb->stopped = 1;
98 wake_up_interruptible(&rhb->wait);
99}