File: sim_watchdog.c

package info (click to toggle)
openhpi 3.8.0-2.3
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 31,888 kB
  • sloc: ansic: 225,326; cpp: 63,687; java: 16,472; cs: 15,161; python: 11,884; sh: 11,508; makefile: 4,945; perl: 1,529; xml: 36; asm: 13
file content (280 lines) | stat: -rw-r--r-- 9,231 bytes parent folder | download | duplicates (8)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*      -*- linux-c -*-
 *
 * (C) Copyright IBM Corp. 2005, 2006
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
 * file and program are licensed under a BSD style license.  See
 * the Copying file included with the OpenHPI distribution for
 * full licensing terms.
 *
 * Author(s):
 *      W. David Ashley <dashley@us.ibm.com>
 *	Renier Morales <renier@openhpi.org>
 */


#include <sim_init.h>


static SaErrorT new_watchdog(struct oh_handler_state *state,
                             struct oh_event *e,
                             struct sim_watchdog *mywatchdog) {
        SaHpiRdrT *rdr = NULL;
        struct simWatchdogInfo *info = NULL;
	SaErrorT error = SA_OK;

        rdr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT));
        // set up rdr
        rdr->RdrType = SAHPI_WATCHDOG_RDR;
        memcpy(&rdr->RdrTypeUnion.WatchdogRec,
               &mywatchdog->watchdogrec, sizeof(SaHpiWatchdogRecT));
        oh_init_textbuffer(&rdr->IdString);
        oh_append_textbuffer(&rdr->IdString, mywatchdog->comment);

        // get the RptEntry
	rdr->Entity = e->resource.ResourceEntity;

        // set up our private info
        info = (struct simWatchdogInfo *)g_malloc0(sizeof(struct simWatchdogInfo));
        memcpy(&info->watchdog,&mywatchdog->wd, sizeof(SaHpiWatchdogT));

        /* everything ready so inject the rdr */
	error = sim_inject_rdr(state, e, rdr, info);
        if (error) {
                g_free(rdr);
                g_free(info);
        }

        return error;
}


SaErrorT sim_discover_chassis_watchdogs(struct oh_handler_state *state,
                                        struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_chassis_watchdogs[i].watchdogrec.WatchdogNum != 0) {
                rc = new_watchdog(state, e, &sim_chassis_watchdogs[i]);
                if (rc) {
                        err("Error %d returned when adding chassis watchdog", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d chassis watchdogs injected", j, i);


        return 0;
}


SaErrorT sim_discover_cpu_watchdogs(struct oh_handler_state *state,
                                    struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_cpu_watchdogs[i].watchdogrec.WatchdogNum != 0) {
                rc = new_watchdog(state, e, &sim_cpu_watchdogs[i]);
                if (rc) {
                        err("Error %d returned when adding cpu watchdog", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d cpu watchdogs injected", j, i);

        return 0;
}


SaErrorT sim_discover_dasd_watchdogs(struct oh_handler_state *state,
                                     struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_dasd_watchdogs[i].watchdogrec.WatchdogNum != 0) {
                rc = new_watchdog(state, e, &sim_dasd_watchdogs[i]);
                if (rc) {
                        err("Error %d returned when adding dasd watchdog", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d dasd watchdogs injected", j, i);

        return 0;
}


SaErrorT sim_discover_hs_dasd_watchdogs(struct oh_handler_state *state,
                                        struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_hs_dasd_watchdogs[i].watchdogrec.WatchdogNum != 0) {
                rc = new_watchdog(state, e, &sim_hs_dasd_watchdogs[i]);
                if (rc) {
                        err("Error %d returned when adding hs dasd watchdog", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d hs dasd watchdogs injected", j, i);

        return 0;
}


SaErrorT sim_discover_fan_watchdogs(struct oh_handler_state *state,
                                    struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_fan_watchdogs[i].watchdogrec.WatchdogNum != 0) {
                rc = new_watchdog(state, e, &sim_fan_watchdogs[i]);
                if (rc) {
                        err("Error %d returned when adding fan watchdog", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d fan watchdogs injected", j, i);

        return 0;
}

SaErrorT sim_get_watchdog_info(void *hnd,
                                   SaHpiResourceIdT rid,
                                   SaHpiWatchdogNumT num,
                                   SaHpiWatchdogT *wdt)
{
        struct simWatchdogInfo *info;

        if (!hnd) {
                err("Invalid parameter.");
                return SA_ERR_HPI_INVALID_PARAMS;
        }

        struct oh_handler_state *state = (struct oh_handler_state *)hnd;

        /* Check if resource exists and has managed hotswap capabilities */
        SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid);
        if (!rpt) {
                return SA_ERR_HPI_INVALID_RESOURCE;
        }
        if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG)) {
                return SA_ERR_HPI_CAPABILITY;
        }

        /* get our private info */
        SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid,
                                            SAHPI_WATCHDOG_RDR, num);
        if (rdr == NULL)
                return SA_ERR_HPI_NOT_PRESENT;
        info = (struct simWatchdogInfo *)oh_get_rdr_data(state->rptcache, rid,
                                                         rdr->RecordId);
        if (info == NULL) {
                err("No watchdog data. Watchdog=%s", rdr->IdString.Data);
                return SA_ERR_HPI_NOT_PRESENT;
        }

        memcpy(wdt, &info->watchdog, sizeof(SaHpiWatchdogT));
        return SA_OK;
}

SaErrorT sim_set_watchdog_info(void *hnd,
                                   SaHpiResourceIdT rid,
                                   SaHpiWatchdogNumT num,
                                   SaHpiWatchdogT *wdt)
{
        struct simWatchdogInfo *info;

        if (!hnd) {
                err("Invalid parameter.");
                return SA_ERR_HPI_INVALID_PARAMS;
        }

        struct oh_handler_state *state = (struct oh_handler_state *)hnd;

        /* Check if resource exists and has managed hotswap capabilities */
        SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid);
        if (!rpt) {
                return SA_ERR_HPI_INVALID_RESOURCE;
        }
        if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG)) {
                return SA_ERR_HPI_CAPABILITY;
        }

        /* get our private info */
        SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid,
                                            SAHPI_WATCHDOG_RDR, num);
        if (rdr == NULL)
                return SA_ERR_HPI_NOT_PRESENT;
        info = (struct simWatchdogInfo *)oh_get_rdr_data(state->rptcache, rid,
                                                         rdr->RecordId);
        if (info == NULL) {
                err("No watchdog data. Watchdog=%s", rdr->IdString.Data);
                return SA_ERR_HPI_NOT_PRESENT;
        }

        memcpy(&info->watchdog, wdt, sizeof(SaHpiWatchdogT));
        return SA_OK;
}

SaErrorT sim_reset_watchdog(void *hnd,
                                SaHpiResourceIdT rid,
                                SaHpiWatchdogNumT num)
{
        SaHpiRdrT *rdr;
        
        if (!hnd) {
                err("Invalid parameter.");
                return SA_ERR_HPI_INVALID_PARAMS;
        }

        struct oh_handler_state *state = (struct oh_handler_state *)hnd;

        /* Check if resource exists and has managed hotswap capabilities */
        SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid);
        if (!rpt) {
                return SA_ERR_HPI_INVALID_RESOURCE;
        }
        
        if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG)) {
                return SA_ERR_HPI_CAPABILITY;
        }
        
	rdr = oh_get_rdr_by_type(state->rptcache, rid,
                                            SAHPI_WATCHDOG_RDR, num);
        if (rdr == NULL)
                return SA_ERR_HPI_NOT_PRESENT;

        // since no timer is actually running we can just do nothing here
        return SA_OK;
}


void * oh_get_watchdog_info (void *, SaHpiResourceIdT, SaHpiWatchdogNumT,
                             SaHpiWatchdogT *)
                __attribute__ ((weak, alias("sim_get_watchdog_info")));

void * oh_set_watchdog_info (void *, SaHpiResourceIdT, SaHpiWatchdogNumT,
                             SaHpiWatchdogT *)
                __attribute__ ((weak, alias("sim_set_watchdog_info")));

void * oh_reset_watchdog (void *, SaHpiResourceIdT, SaHpiWatchdogNumT)
                __attribute__ ((weak, alias("sim_reset_watchdog")));