1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/notifier.h>
26#include "ibmasm.h"
27#include "dot_command.h"
28#include "lowlevel.h"
29
30static int suspend_heartbeats = 0;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45static int panic_happened(struct notifier_block *n, unsigned long val, void *v)
46{
47 suspend_heartbeats = 1;
48 return 0;
49}
50
51static struct notifier_block panic_notifier = { panic_happened, NULL, 1 };
52
53void ibmasm_register_panic_notifier(void)
54{
55 atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier);
56}
57
58void ibmasm_unregister_panic_notifier(void)
59{
60 atomic_notifier_chain_unregister(&panic_notifier_list,
61 &panic_notifier);
62}
63
64
65int ibmasm_heartbeat_init(struct service_processor *sp)
66{
67 sp->heartbeat = ibmasm_new_command(sp, HEARTBEAT_BUFFER_SIZE);
68 if (sp->heartbeat == NULL)
69 return -ENOMEM;
70
71 return 0;
72}
73
74void ibmasm_heartbeat_exit(struct service_processor *sp)
75{
76 char tsbuf[32];
77
78 dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
79 ibmasm_wait_for_response(sp->heartbeat, IBMASM_CMD_TIMEOUT_NORMAL);
80 dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
81 suspend_heartbeats = 1;
82 command_put(sp->heartbeat);
83}
84
85void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size)
86{
87 struct command *cmd = sp->heartbeat;
88 struct dot_command_header *header = (struct dot_command_header *)cmd->buffer;
89 char tsbuf[32];
90
91 dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
92 if (suspend_heartbeats)
93 return;
94
95
96 cmd->status = IBMASM_CMD_PENDING;
97 size = min(size, cmd->buffer_size);
98 memcpy_fromio(cmd->buffer, message, size);
99 header->type = sp_write;
100 ibmasm_exec_command(sp, cmd);
101}
102