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>
24 static struct subch_data_s *event_sd;
26 void scdrv_event(unsigned long);
27 DECLARE_TASKLET(sn_sysctl_event, scdrv_event, 0);
30 * scdrv_event_interrupt
32 * Pull incoming environmental events off the physical link to the
33 * system controller and put them in a temporary holding area in SAL.
34 * Schedule scdrv_event() to move them along to their ultimate
38 scdrv_event_interrupt(int irq, void *subch_data, struct pt_regs *regs)
40 struct subch_data_s *sd = subch_data;
44 spin_lock_irqsave(&sd->sd_rlock, flags);
45 status = ia64_sn_irtr_intr(sd->sd_nasid, sd->sd_subch);
47 if ((status > 0) && (status & SAL_IROUTER_INTR_RECV)) {
48 tasklet_schedule(&sn_sysctl_event);
50 spin_unlock_irqrestore(&sd->sd_rlock, flags);
58 * Break an event (as read from SAL) into useful pieces so we can decide
62 scdrv_parse_event(char *event, int *src, int *code, int *esp_code, char *desc)
66 /* record event source address */
67 *src = be32_to_cpup((__be32 *)event);
68 event += 4; /* move on to event code */
70 /* record the system controller's event code */
71 *code = be32_to_cpup((__be32 *)event);
72 event += 4; /* move on to event arguments */
74 /* how many arguments are in the packet? */
76 /* if not 2, give up */
80 /* parse out the ESP code */
81 if (*event++ != IR_ARG_INT) {
82 /* not an integer argument, so give up */
85 *esp_code = be32_to_cpup((__be32 *)event);
88 /* parse out the event description */
89 if (*event++ != IR_ARG_ASCII) {
90 /* not an ASCII string, so give up */
93 event[CHUNKSIZE-1] = '\0'; /* ensure this string ends! */
94 event += 2; /* skip leading CR/LF */
95 desc_end = desc + sprintf(desc, "%s", event);
97 /* strip trailing CR/LF (if any) */
99 (desc_end != desc) && ((*desc_end == 0xd) || (*desc_end == 0xa));
109 * scdrv_event_severity
111 * Figure out how urgent a message we should write to the console/syslog
115 scdrv_event_severity(int code)
117 int ev_class = (code & EV_CLASS_MASK);
118 int ev_severity = (code & EV_SEVERITY_MASK);
119 char *pk_severity = KERN_NOTICE;
123 switch (ev_severity) {
124 case EV_SEVERITY_POWER_LOW_WARNING:
125 case EV_SEVERITY_POWER_HIGH_WARNING:
126 pk_severity = KERN_WARNING;
128 case EV_SEVERITY_POWER_HIGH_FAULT:
129 case EV_SEVERITY_POWER_LOW_FAULT:
130 pk_severity = KERN_ALERT;
135 switch (ev_severity) {
136 case EV_SEVERITY_FAN_WARNING:
137 pk_severity = KERN_WARNING;
139 case EV_SEVERITY_FAN_FAULT:
140 pk_severity = KERN_CRIT;
145 switch (ev_severity) {
146 case EV_SEVERITY_TEMP_ADVISORY:
147 pk_severity = KERN_WARNING;
149 case EV_SEVERITY_TEMP_CRITICAL:
150 pk_severity = KERN_CRIT;
152 case EV_SEVERITY_TEMP_FAULT:
153 pk_severity = KERN_ALERT;
158 pk_severity = KERN_ALERT;
160 case EV_CLASS_TEST_FAULT:
161 pk_severity = KERN_ALERT;
163 case EV_CLASS_TEST_WARNING:
164 pk_severity = KERN_WARNING;
166 case EV_CLASS_PWRD_NOTIFY:
167 pk_severity = KERN_ALERT;
176 * scdrv_dispatch_event
178 * Do the right thing with an incoming event. That's often nothing
179 * more than printing it to the system log. For power-down notifications
180 * we start a graceful shutdown.
183 scdrv_dispatch_event(char *event, int len)
185 int code, esp_code, src;
186 char desc[CHUNKSIZE];
189 if (scdrv_parse_event(event, &src, &code, &esp_code, desc) < 0) {
190 /* ignore uninterpretible event */
194 /* how urgent is the message? */
195 severity = scdrv_event_severity(code);
197 if ((code & EV_CLASS_MASK) == EV_CLASS_PWRD_NOTIFY) {
198 struct task_struct *p;
200 /* give a SIGPWR signal to init proc */
202 /* first find init's task */
203 read_lock(&tasklist_lock);
204 for_each_process(p) {
208 if (p) { /* we found init's task */
209 printk(KERN_EMERG "Power off indication received. Initiating power fail sequence...\n");
210 force_sig(SIGPWR, p);
211 } else { /* failed to find init's task - just give message(s) */
212 printk(KERN_WARNING "Failed to find init proc to handle power off!\n");
213 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
215 read_unlock(&tasklist_lock);
217 /* print to system log */
218 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
226 * Called as a tasklet when an event arrives from the L1. Read the event
227 * from where it's temporarily stored in SAL and call scdrv_dispatch_event()
228 * to send it on its way. Keep trying to read events until SAL indicates
229 * that there are no more immediately available.
232 scdrv_event(unsigned long dummy)
237 struct subch_data_s *sd = event_sd;
239 /* anything to read? */
241 spin_lock_irqsave(&sd->sd_rlock, flags);
242 status = ia64_sn_irtr_recv(sd->sd_nasid, sd->sd_subch,
245 while (!(status < 0)) {
246 spin_unlock_irqrestore(&sd->sd_rlock, flags);
247 scdrv_dispatch_event(sd->sd_rb, len);
249 spin_lock_irqsave(&sd->sd_rlock, flags);
250 status = ia64_sn_irtr_recv(sd->sd_nasid, sd->sd_subch,
253 spin_unlock_irqrestore(&sd->sd_rlock, flags);
260 * Sets up a system controller subchannel to begin receiving event
261 * messages. This is sort of a specialized version of scdrv_open()
262 * in drivers/char/sn_sysctl.c.
265 scdrv_event_init(struct sysctl_data_s *scd)
269 event_sd = kmalloc(sizeof (struct subch_data_s), GFP_KERNEL);
270 if (event_sd == NULL) {
271 printk(KERN_WARNING "%s: couldn't allocate subchannel info"
272 " for event monitoring\n", __FUNCTION__);
276 /* initialize subch_data_s fields */
277 memset(event_sd, 0, sizeof (struct subch_data_s));
278 event_sd->sd_nasid = scd->scd_nasid;
279 spin_lock_init(&event_sd->sd_rlock);
281 /* ask the system controllers to send events to this node */
282 event_sd->sd_subch = ia64_sn_sysctl_event_init(scd->scd_nasid);
284 if (event_sd->sd_subch < 0) {
286 printk(KERN_WARNING "%s: couldn't open event subchannel\n",
291 /* hook event subchannel up to the system controller interrupt */
292 rv = request_irq(SGI_UART_VECTOR, scdrv_event_interrupt,
293 SA_SHIRQ | SA_INTERRUPT,
294 "system controller events", event_sd);
296 printk(KERN_WARNING "%s: irq request failed (%d)\n",
298 ia64_sn_irtr_close(event_sd->sd_nasid, event_sd->sd_subch);