blob: e452673dff66128f33505e96b4b7e007038ddb78 [file] [log] [blame]
Greg Howardfc626b22005-04-25 13:29:46 -07001/*
2 * SN Platform system controller communication support
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
Aaron Young28ff6b9b2006-01-23 09:00:51 -08008 * Copyright (C) 2004-2006 Silicon Graphics, Inc. All rights reserved.
Greg Howardfc626b22005-04-25 13:29:46 -07009 */
10
11/*
12 * System controller event handler
13 *
14 * These routines deal with environmental events arriving from the
15 * system controllers.
16 */
17
18#include <linux/interrupt.h>
Ingo Molnar3f07c012017-02-08 18:51:30 +010019#include <linux/sched/signal.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Harvey Harrison9a6ab762008-05-16 11:20:25 -070021#include <asm/byteorder.h>
Greg Howardfc626b22005-04-25 13:29:46 -070022#include <asm/sn/sn_sal.h>
Greg Howard1a402aa2005-08-15 13:00:00 -070023#include <asm/unaligned.h>
Greg Howardfc626b22005-04-25 13:29:46 -070024#include "snsc.h"
25
26static struct subch_data_s *event_sd;
27
28void scdrv_event(unsigned long);
29DECLARE_TASKLET(sn_sysctl_event, scdrv_event, 0);
30
31/*
32 * scdrv_event_interrupt
33 *
34 * Pull incoming environmental events off the physical link to the
35 * system controller and put them in a temporary holding area in SAL.
36 * Schedule scdrv_event() to move them along to their ultimate
37 * destination.
38 */
39static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010040scdrv_event_interrupt(int irq, void *subch_data)
Greg Howardfc626b22005-04-25 13:29:46 -070041{
42 struct subch_data_s *sd = subch_data;
43 unsigned long flags;
44 int status;
45
46 spin_lock_irqsave(&sd->sd_rlock, flags);
47 status = ia64_sn_irtr_intr(sd->sd_nasid, sd->sd_subch);
48
49 if ((status > 0) && (status & SAL_IROUTER_INTR_RECV)) {
50 tasklet_schedule(&sn_sysctl_event);
51 }
52 spin_unlock_irqrestore(&sd->sd_rlock, flags);
53 return IRQ_HANDLED;
54}
55
56
57/*
58 * scdrv_parse_event
59 *
60 * Break an event (as read from SAL) into useful pieces so we can decide
61 * what to do with it.
62 */
63static int
64scdrv_parse_event(char *event, int *src, int *code, int *esp_code, char *desc)
65{
66 char *desc_end;
67
68 /* record event source address */
Harvey Harrison973ea702008-04-29 01:03:32 -070069 *src = get_unaligned_be32(event);
Greg Howardfc626b22005-04-25 13:29:46 -070070 event += 4; /* move on to event code */
71
72 /* record the system controller's event code */
Harvey Harrison973ea702008-04-29 01:03:32 -070073 *code = get_unaligned_be32(event);
Greg Howardfc626b22005-04-25 13:29:46 -070074 event += 4; /* move on to event arguments */
75
76 /* how many arguments are in the packet? */
77 if (*event++ != 2) {
78 /* if not 2, give up */
79 return -1;
80 }
81
82 /* parse out the ESP code */
83 if (*event++ != IR_ARG_INT) {
84 /* not an integer argument, so give up */
85 return -1;
86 }
Harvey Harrison973ea702008-04-29 01:03:32 -070087 *esp_code = get_unaligned_be32(event);
Greg Howardfc626b22005-04-25 13:29:46 -070088 event += 4;
89
90 /* parse out the event description */
91 if (*event++ != IR_ARG_ASCII) {
92 /* not an ASCII string, so give up */
93 return -1;
94 }
95 event[CHUNKSIZE-1] = '\0'; /* ensure this string ends! */
96 event += 2; /* skip leading CR/LF */
97 desc_end = desc + sprintf(desc, "%s", event);
98
99 /* strip trailing CR/LF (if any) */
100 for (desc_end--;
101 (desc_end != desc) && ((*desc_end == 0xd) || (*desc_end == 0xa));
102 desc_end--) {
103 *desc_end = '\0';
104 }
105
106 return 0;
107}
108
109
110/*
111 * scdrv_event_severity
112 *
113 * Figure out how urgent a message we should write to the console/syslog
114 * via printk.
115 */
116static char *
117scdrv_event_severity(int code)
118{
119 int ev_class = (code & EV_CLASS_MASK);
120 int ev_severity = (code & EV_SEVERITY_MASK);
121 char *pk_severity = KERN_NOTICE;
122
123 switch (ev_class) {
124 case EV_CLASS_POWER:
125 switch (ev_severity) {
126 case EV_SEVERITY_POWER_LOW_WARNING:
127 case EV_SEVERITY_POWER_HIGH_WARNING:
128 pk_severity = KERN_WARNING;
129 break;
130 case EV_SEVERITY_POWER_HIGH_FAULT:
131 case EV_SEVERITY_POWER_LOW_FAULT:
132 pk_severity = KERN_ALERT;
133 break;
134 }
135 break;
136 case EV_CLASS_FAN:
137 switch (ev_severity) {
138 case EV_SEVERITY_FAN_WARNING:
139 pk_severity = KERN_WARNING;
140 break;
141 case EV_SEVERITY_FAN_FAULT:
142 pk_severity = KERN_CRIT;
143 break;
144 }
145 break;
146 case EV_CLASS_TEMP:
147 switch (ev_severity) {
148 case EV_SEVERITY_TEMP_ADVISORY:
149 pk_severity = KERN_WARNING;
150 break;
151 case EV_SEVERITY_TEMP_CRITICAL:
152 pk_severity = KERN_CRIT;
153 break;
154 case EV_SEVERITY_TEMP_FAULT:
155 pk_severity = KERN_ALERT;
156 break;
157 }
158 break;
159 case EV_CLASS_ENV:
160 pk_severity = KERN_ALERT;
161 break;
162 case EV_CLASS_TEST_FAULT:
163 pk_severity = KERN_ALERT;
164 break;
165 case EV_CLASS_TEST_WARNING:
166 pk_severity = KERN_WARNING;
167 break;
168 case EV_CLASS_PWRD_NOTIFY:
169 pk_severity = KERN_ALERT;
170 break;
171 }
172
173 return pk_severity;
174}
175
176
177/*
178 * scdrv_dispatch_event
179 *
180 * Do the right thing with an incoming event. That's often nothing
181 * more than printing it to the system log. For power-down notifications
182 * we start a graceful shutdown.
183 */
184static void
185scdrv_dispatch_event(char *event, int len)
186{
Aaron Young28ff6b9b2006-01-23 09:00:51 -0800187 static int snsc_shutting_down = 0;
188 int code, esp_code, src, class;
Greg Howardfc626b22005-04-25 13:29:46 -0700189 char desc[CHUNKSIZE];
190 char *severity;
191
192 if (scdrv_parse_event(event, &src, &code, &esp_code, desc) < 0) {
193 /* ignore uninterpretible event */
194 return;
195 }
196
197 /* how urgent is the message? */
198 severity = scdrv_event_severity(code);
199
Aaron Young28ff6b9b2006-01-23 09:00:51 -0800200 class = (code & EV_CLASS_MASK);
201
202 if (class == EV_CLASS_PWRD_NOTIFY || code == ENV_PWRDN_PEND) {
Aaron Young28ff6b9b2006-01-23 09:00:51 -0800203 if (snsc_shutting_down)
204 return;
205
206 snsc_shutting_down = 1;
207
208 /* give a message for each type of event */
209 if (class == EV_CLASS_PWRD_NOTIFY)
210 printk(KERN_NOTICE "Power off indication received."
211 " Sending SIGPWR to init...\n");
212 else if (code == ENV_PWRDN_PEND)
213 printk(KERN_CRIT "WARNING: Shutting down the system"
214 " due to a critical environmental condition."
215 " Sending SIGPWR to init...\n");
216
Greg Howardfc626b22005-04-25 13:29:46 -0700217 /* give a SIGPWR signal to init proc */
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700218 kill_cad_pid(SIGPWR, 0);
Greg Howardfc626b22005-04-25 13:29:46 -0700219 } else {
220 /* print to system log */
221 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
222 }
223}
224
225
226/*
227 * scdrv_event
228 *
229 * Called as a tasklet when an event arrives from the L1. Read the event
230 * from where it's temporarily stored in SAL and call scdrv_dispatch_event()
231 * to send it on its way. Keep trying to read events until SAL indicates
232 * that there are no more immediately available.
233 */
234void
235scdrv_event(unsigned long dummy)
236{
237 int status;
238 int len;
239 unsigned long flags;
240 struct subch_data_s *sd = event_sd;
241
242 /* anything to read? */
243 len = CHUNKSIZE;
244 spin_lock_irqsave(&sd->sd_rlock, flags);
245 status = ia64_sn_irtr_recv(sd->sd_nasid, sd->sd_subch,
246 sd->sd_rb, &len);
247
248 while (!(status < 0)) {
249 spin_unlock_irqrestore(&sd->sd_rlock, flags);
250 scdrv_dispatch_event(sd->sd_rb, len);
251 len = CHUNKSIZE;
252 spin_lock_irqsave(&sd->sd_rlock, flags);
253 status = ia64_sn_irtr_recv(sd->sd_nasid, sd->sd_subch,
254 sd->sd_rb, &len);
255 }
256 spin_unlock_irqrestore(&sd->sd_rlock, flags);
257}
258
259
260/*
261 * scdrv_event_init
262 *
263 * Sets up a system controller subchannel to begin receiving event
264 * messages. This is sort of a specialized version of scdrv_open()
265 * in drivers/char/sn_sysctl.c.
266 */
267void
268scdrv_event_init(struct sysctl_data_s *scd)
269{
270 int rv;
271
Jes Sorensen40953ed2006-03-23 03:00:49 -0800272 event_sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL);
Greg Howardfc626b22005-04-25 13:29:46 -0700273 if (event_sd == NULL) {
274 printk(KERN_WARNING "%s: couldn't allocate subchannel info"
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700275 " for event monitoring\n", __func__);
Greg Howardfc626b22005-04-25 13:29:46 -0700276 return;
277 }
278
279 /* initialize subch_data_s fields */
Greg Howardfc626b22005-04-25 13:29:46 -0700280 event_sd->sd_nasid = scd->scd_nasid;
281 spin_lock_init(&event_sd->sd_rlock);
282
283 /* ask the system controllers to send events to this node */
284 event_sd->sd_subch = ia64_sn_sysctl_event_init(scd->scd_nasid);
285
286 if (event_sd->sd_subch < 0) {
287 kfree(event_sd);
288 printk(KERN_WARNING "%s: couldn't open event subchannel\n",
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700289 __func__);
Greg Howardfc626b22005-04-25 13:29:46 -0700290 return;
291 }
292
293 /* hook event subchannel up to the system controller interrupt */
294 rv = request_irq(SGI_UART_VECTOR, scdrv_event_interrupt,
Michael Opdenackerd88ed622013-10-13 06:14:42 +0200295 IRQF_SHARED, "system controller events", event_sd);
Greg Howardfc626b22005-04-25 13:29:46 -0700296 if (rv) {
297 printk(KERN_WARNING "%s: irq request failed (%d)\n",
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700298 __func__, rv);
Greg Howardfc626b22005-04-25 13:29:46 -0700299 ia64_sn_irtr_close(event_sd->sd_nasid, event_sd->sd_subch);
300 kfree(event_sd);
301 return;
302 }
303}