2 * SN Platform system controller communication support
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
8 * Copyright (C) 2004 Silicon Graphics, Inc. All rights reserved.
12 * System controller event handler
14 * These routines deal with environmental events arriving from the
18 #include <linux/interrupt.h>
19 #include <linux/sched.h>
20 #include <linux/byteorder/generic.h>
21 #include <asm/sn/sn_sal.h>
22 #include <asm/unaligned.h>
25 static struct subch_data_s *event_sd;
27 void scdrv_event(unsigned long);
28 DECLARE_TASKLET(sn_sysctl_event, scdrv_event, 0);
31 * scdrv_event_interrupt
33 * Pull incoming environmental events off the physical link to the
34 * system controller and put them in a temporary holding area in SAL.
35 * Schedule scdrv_event() to move them along to their ultimate
39 scdrv_event_interrupt(int irq, void *subch_data, struct pt_regs *regs)
41 struct subch_data_s *sd = subch_data;
45 spin_lock_irqsave(&sd->sd_rlock, flags);
46 status = ia64_sn_irtr_intr(sd->sd_nasid, sd->sd_subch);
48 if ((status > 0) && (status & SAL_IROUTER_INTR_RECV)) {
49 tasklet_schedule(&sn_sysctl_event);
51 spin_unlock_irqrestore(&sd->sd_rlock, flags);
59 * Break an event (as read from SAL) into useful pieces so we can decide
63 scdrv_parse_event(char *event, int *src, int *code, int *esp_code, char *desc)
68 /* record event source address */
69 from_buf = get_unaligned((__be32 *)event);
70 *src = be32_to_cpup(&from_buf);
71 event += 4; /* move on to event code */
73 /* record the system controller's event code */
74 from_buf = get_unaligned((__be32 *)event);
75 *code = be32_to_cpup(&from_buf);
76 event += 4; /* move on to event arguments */
78 /* how many arguments are in the packet? */
80 /* if not 2, give up */
84 /* parse out the ESP code */
85 if (*event++ != IR_ARG_INT) {
86 /* not an integer argument, so give up */
89 from_buf = get_unaligned((__be32 *)event);
90 *esp_code = be32_to_cpup(&from_buf);
93 /* parse out the event description */
94 if (*event++ != IR_ARG_ASCII) {
95 /* not an ASCII string, so give up */
98 event[CHUNKSIZE-1] = '\0'; /* ensure this string ends! */
99 event += 2; /* skip leading CR/LF */
100 desc_end = desc + sprintf(desc, "%s", event);
102 /* strip trailing CR/LF (if any) */
104 (desc_end != desc) && ((*desc_end == 0xd) || (*desc_end == 0xa));
114 * scdrv_event_severity
116 * Figure out how urgent a message we should write to the console/syslog
120 scdrv_event_severity(int code)
122 int ev_class = (code & EV_CLASS_MASK);
123 int ev_severity = (code & EV_SEVERITY_MASK);
124 char *pk_severity = KERN_NOTICE;
128 switch (ev_severity) {
129 case EV_SEVERITY_POWER_LOW_WARNING:
130 case EV_SEVERITY_POWER_HIGH_WARNING:
131 pk_severity = KERN_WARNING;
133 case EV_SEVERITY_POWER_HIGH_FAULT:
134 case EV_SEVERITY_POWER_LOW_FAULT:
135 pk_severity = KERN_ALERT;
140 switch (ev_severity) {
141 case EV_SEVERITY_FAN_WARNING:
142 pk_severity = KERN_WARNING;
144 case EV_SEVERITY_FAN_FAULT:
145 pk_severity = KERN_CRIT;
150 switch (ev_severity) {
151 case EV_SEVERITY_TEMP_ADVISORY:
152 pk_severity = KERN_WARNING;
154 case EV_SEVERITY_TEMP_CRITICAL:
155 pk_severity = KERN_CRIT;
157 case EV_SEVERITY_TEMP_FAULT:
158 pk_severity = KERN_ALERT;
163 pk_severity = KERN_ALERT;
165 case EV_CLASS_TEST_FAULT:
166 pk_severity = KERN_ALERT;
168 case EV_CLASS_TEST_WARNING:
169 pk_severity = KERN_WARNING;
171 case EV_CLASS_PWRD_NOTIFY:
172 pk_severity = KERN_ALERT;
181 * scdrv_dispatch_event
183 * Do the right thing with an incoming event. That's often nothing
184 * more than printing it to the system log. For power-down notifications
185 * we start a graceful shutdown.
188 scdrv_dispatch_event(char *event, int len)
190 int code, esp_code, src;
191 char desc[CHUNKSIZE];
194 if (scdrv_parse_event(event, &src, &code, &esp_code, desc) < 0) {
195 /* ignore uninterpretible event */
199 /* how urgent is the message? */
200 severity = scdrv_event_severity(code);
202 if ((code & EV_CLASS_MASK) == EV_CLASS_PWRD_NOTIFY) {
203 struct task_struct *p;
205 /* give a SIGPWR signal to init proc */
207 /* first find init's task */
208 read_lock(&tasklist_lock);
209 for_each_process(p) {
213 if (p) { /* we found init's task */
214 printk(KERN_EMERG "Power off indication received. Initiating power fail sequence...\n");
215 force_sig(SIGPWR, p);
216 } else { /* failed to find init's task - just give message(s) */
217 printk(KERN_WARNING "Failed to find init proc to handle power off!\n");
218 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
220 read_unlock(&tasklist_lock);
222 /* print to system log */
223 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
231 * Called as a tasklet when an event arrives from the L1. Read the event
232 * from where it's temporarily stored in SAL and call scdrv_dispatch_event()
233 * to send it on its way. Keep trying to read events until SAL indicates
234 * that there are no more immediately available.
237 scdrv_event(unsigned long dummy)
242 struct subch_data_s *sd = event_sd;
244 /* anything to read? */
246 spin_lock_irqsave(&sd->sd_rlock, flags);
247 status = ia64_sn_irtr_recv(sd->sd_nasid, sd->sd_subch,
250 while (!(status < 0)) {
251 spin_unlock_irqrestore(&sd->sd_rlock, flags);
252 scdrv_dispatch_event(sd->sd_rb, len);
254 spin_lock_irqsave(&sd->sd_rlock, flags);
255 status = ia64_sn_irtr_recv(sd->sd_nasid, sd->sd_subch,
258 spin_unlock_irqrestore(&sd->sd_rlock, flags);
265 * Sets up a system controller subchannel to begin receiving event
266 * messages. This is sort of a specialized version of scdrv_open()
267 * in drivers/char/sn_sysctl.c.
270 scdrv_event_init(struct sysctl_data_s *scd)
274 event_sd = kmalloc(sizeof (struct subch_data_s), GFP_KERNEL);
275 if (event_sd == NULL) {
276 printk(KERN_WARNING "%s: couldn't allocate subchannel info"
277 " for event monitoring\n", __FUNCTION__);
281 /* initialize subch_data_s fields */
282 memset(event_sd, 0, sizeof (struct subch_data_s));
283 event_sd->sd_nasid = scd->scd_nasid;
284 spin_lock_init(&event_sd->sd_rlock);
286 /* ask the system controllers to send events to this node */
287 event_sd->sd_subch = ia64_sn_sysctl_event_init(scd->scd_nasid);
289 if (event_sd->sd_subch < 0) {
291 printk(KERN_WARNING "%s: couldn't open event subchannel\n",
296 /* hook event subchannel up to the system controller interrupt */
297 rv = request_irq(SGI_UART_VECTOR, scdrv_event_interrupt,
298 SA_SHIRQ | SA_INTERRUPT,
299 "system controller events", event_sd);
301 printk(KERN_WARNING "%s: irq request failed (%d)\n",
303 ia64_sn_irtr_close(event_sd->sd_nasid, event_sd->sd_subch);