blob: 1583329ac2ec6debc2dee7221e6dedb895089411 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ipmi_poweroff.c
3 *
4 * MontaVista IPMI Poweroff extension to sys_reboot
5 *
6 * Author: MontaVista Software, Inc.
7 * Steven Dake <sdake@mvista.com>
8 * Corey Minyard <cminyard@mvista.com>
9 * source@mvista.com
10 *
11 * Copyright 2002,2004 MontaVista Software Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 *
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
28 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 */
Corey Minyard77cf3972005-06-23 22:01:44 -070034#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/module.h>
Corey Minyard3b625942005-06-23 22:01:42 -070036#include <linux/moduleparam.h>
37#include <linux/proc_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/string.h>
Corey Minyard77cf3972005-06-23 22:01:44 -070039#include <linux/completion.h>
40#include <linux/kdev_t.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/ipmi.h>
42#include <linux/ipmi_smi.h>
43
44#define PFX "IPMI poweroff: "
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46/* Where to we insert our poweroff function? */
47extern void (*pm_power_off)(void);
48
Corey Minyard3b625942005-06-23 22:01:42 -070049/* Definitions for controlling power off (if the system supports it). It
50 * conveniently matches the IPMI chassis control values. */
51#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */
52#define IPMI_CHASSIS_POWER_CYCLE 0x02 /* power cycle */
53
54/* the IPMI data command */
55static int poweroff_control = IPMI_CHASSIS_POWER_DOWN;
56
57/* parameter definition to allow user to flag power cycle */
58module_param(poweroff_control, int, IPMI_CHASSIS_POWER_DOWN);
59MODULE_PARM_DESC(poweroff_control, " Set to 2 to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/* Stuff from the get device id command. */
62static unsigned int mfg_id;
63static unsigned int prod_id;
64static unsigned char capabilities;
65
66/* We use our own messages for this operation, we don't let the system
67 allocate them, since we may be in a panic situation. The whole
68 thing is single-threaded, anyway, so multiple messages are not
69 required. */
70static void dummy_smi_free(struct ipmi_smi_msg *msg)
71{
72}
73static void dummy_recv_free(struct ipmi_recv_msg *msg)
74{
75}
76static struct ipmi_smi_msg halt_smi_msg =
77{
78 .done = dummy_smi_free
79};
80static struct ipmi_recv_msg halt_recv_msg =
81{
82 .done = dummy_recv_free
83};
84
85
86/*
87 * Code to send a message and wait for the reponse.
88 */
89
90static void receive_handler(struct ipmi_recv_msg *recv_msg, void *handler_data)
91{
Corey Minyard77cf3972005-06-23 22:01:44 -070092 struct completion *comp = recv_msg->user_msg_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Corey Minyard77cf3972005-06-23 22:01:44 -070094 if (comp)
95 complete(comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98static struct ipmi_user_hndl ipmi_poweroff_handler =
99{
100 .ipmi_recv_hndl = receive_handler
101};
102
103
104static int ipmi_request_wait_for_response(ipmi_user_t user,
105 struct ipmi_addr *addr,
106 struct kernel_ipmi_msg *send_msg)
107{
Corey Minyard77cf3972005-06-23 22:01:44 -0700108 int rv;
109 struct completion comp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Corey Minyard77cf3972005-06-23 22:01:44 -0700111 init_completion(&comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Corey Minyard77cf3972005-06-23 22:01:44 -0700113 rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, &comp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 &halt_smi_msg, &halt_recv_msg, 0);
115 if (rv)
116 return rv;
117
Corey Minyard77cf3972005-06-23 22:01:44 -0700118 wait_for_completion(&comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 return halt_recv_msg.msg.data[0];
121}
122
Corey Minyard77cf3972005-06-23 22:01:44 -0700123/* We are in run-to-completion mode, no completion is desired. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int ipmi_request_in_rc_mode(ipmi_user_t user,
125 struct ipmi_addr *addr,
126 struct kernel_ipmi_msg *send_msg)
127{
Corey Minyard77cf3972005-06-23 22:01:44 -0700128 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, NULL,
131 &halt_smi_msg, &halt_recv_msg, 0);
132 if (rv)
133 return rv;
134
135 return halt_recv_msg.msg.data[0];
136}
137
138/*
139 * ATCA Support
140 */
141
142#define IPMI_NETFN_ATCA 0x2c
143#define IPMI_ATCA_SET_POWER_CMD 0x11
144#define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01
145#define IPMI_PICMG_ID 0
146
147static int ipmi_atca_detect (ipmi_user_t user)
148{
149 struct ipmi_system_interface_addr smi_addr;
150 struct kernel_ipmi_msg send_msg;
151 int rv;
152 unsigned char data[1];
153
154 /*
155 * Configure IPMI address for local access
156 */
157 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
158 smi_addr.channel = IPMI_BMC_CHANNEL;
159 smi_addr.lun = 0;
160
161 /*
162 * Use get address info to check and see if we are ATCA
163 */
164 send_msg.netfn = IPMI_NETFN_ATCA;
165 send_msg.cmd = IPMI_ATCA_GET_ADDR_INFO_CMD;
166 data[0] = IPMI_PICMG_ID;
167 send_msg.data = data;
168 send_msg.data_len = sizeof(data);
169 rv = ipmi_request_wait_for_response(user,
170 (struct ipmi_addr *) &smi_addr,
171 &send_msg);
172 return !rv;
173}
174
175static void ipmi_poweroff_atca (ipmi_user_t user)
176{
177 struct ipmi_system_interface_addr smi_addr;
178 struct kernel_ipmi_msg send_msg;
179 int rv;
180 unsigned char data[4];
181
182 /*
183 * Configure IPMI address for local access
184 */
185 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
186 smi_addr.channel = IPMI_BMC_CHANNEL;
187 smi_addr.lun = 0;
188
189 printk(KERN_INFO PFX "Powering down via ATCA power command\n");
190
191 /*
192 * Power down
193 */
194 send_msg.netfn = IPMI_NETFN_ATCA;
195 send_msg.cmd = IPMI_ATCA_SET_POWER_CMD;
196 data[0] = IPMI_PICMG_ID;
197 data[1] = 0; /* FRU id */
198 data[2] = 0; /* Power Level */
199 data[3] = 0; /* Don't change saved presets */
200 send_msg.data = data;
201 send_msg.data_len = sizeof (data);
202 rv = ipmi_request_in_rc_mode(user,
203 (struct ipmi_addr *) &smi_addr,
204 &send_msg);
205 if (rv) {
206 printk(KERN_ERR PFX "Unable to send ATCA powerdown message,"
207 " IPMI error 0x%x\n", rv);
208 goto out;
209 }
210
211 out:
212 return;
213}
214
215/*
216 * CPI1 Support
217 */
218
219#define IPMI_NETFN_OEM_1 0xf8
220#define OEM_GRP_CMD_SET_RESET_STATE 0x84
221#define OEM_GRP_CMD_SET_POWER_STATE 0x82
222#define IPMI_NETFN_OEM_8 0xf8
223#define OEM_GRP_CMD_REQUEST_HOTSWAP_CTRL 0x80
224#define OEM_GRP_CMD_GET_SLOT_GA 0xa3
225#define IPMI_NETFN_SENSOR_EVT 0x10
226#define IPMI_CMD_GET_EVENT_RECEIVER 0x01
227
228#define IPMI_CPI1_PRODUCT_ID 0x000157
229#define IPMI_CPI1_MANUFACTURER_ID 0x0108
230
231static int ipmi_cpi1_detect (ipmi_user_t user)
232{
233 return ((mfg_id == IPMI_CPI1_MANUFACTURER_ID)
234 && (prod_id == IPMI_CPI1_PRODUCT_ID));
235}
236
237static void ipmi_poweroff_cpi1 (ipmi_user_t user)
238{
239 struct ipmi_system_interface_addr smi_addr;
240 struct ipmi_ipmb_addr ipmb_addr;
241 struct kernel_ipmi_msg send_msg;
242 int rv;
243 unsigned char data[1];
244 int slot;
245 unsigned char hotswap_ipmb;
246 unsigned char aer_addr;
247 unsigned char aer_lun;
248
249 /*
250 * Configure IPMI address for local access
251 */
252 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
253 smi_addr.channel = IPMI_BMC_CHANNEL;
254 smi_addr.lun = 0;
255
256 printk(KERN_INFO PFX "Powering down via CPI1 power command\n");
257
258 /*
259 * Get IPMI ipmb address
260 */
261 send_msg.netfn = IPMI_NETFN_OEM_8 >> 2;
262 send_msg.cmd = OEM_GRP_CMD_GET_SLOT_GA;
263 send_msg.data = NULL;
264 send_msg.data_len = 0;
265 rv = ipmi_request_in_rc_mode(user,
266 (struct ipmi_addr *) &smi_addr,
267 &send_msg);
268 if (rv)
269 goto out;
270 slot = halt_recv_msg.msg.data[1];
271 hotswap_ipmb = (slot > 9) ? (0xb0 + 2 * slot) : (0xae + 2 * slot);
272
273 /*
274 * Get active event receiver
275 */
276 send_msg.netfn = IPMI_NETFN_SENSOR_EVT >> 2;
277 send_msg.cmd = IPMI_CMD_GET_EVENT_RECEIVER;
278 send_msg.data = NULL;
279 send_msg.data_len = 0;
280 rv = ipmi_request_in_rc_mode(user,
281 (struct ipmi_addr *) &smi_addr,
282 &send_msg);
283 if (rv)
284 goto out;
285 aer_addr = halt_recv_msg.msg.data[1];
286 aer_lun = halt_recv_msg.msg.data[2];
287
288 /*
289 * Setup IPMB address target instead of local target
290 */
291 ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE;
292 ipmb_addr.channel = 0;
293 ipmb_addr.slave_addr = aer_addr;
294 ipmb_addr.lun = aer_lun;
295
296 /*
297 * Send request hotswap control to remove blade from dpv
298 */
299 send_msg.netfn = IPMI_NETFN_OEM_8 >> 2;
300 send_msg.cmd = OEM_GRP_CMD_REQUEST_HOTSWAP_CTRL;
301 send_msg.data = &hotswap_ipmb;
302 send_msg.data_len = 1;
303 ipmi_request_in_rc_mode(user,
304 (struct ipmi_addr *) &ipmb_addr,
305 &send_msg);
306
307 /*
308 * Set reset asserted
309 */
310 send_msg.netfn = IPMI_NETFN_OEM_1 >> 2;
311 send_msg.cmd = OEM_GRP_CMD_SET_RESET_STATE;
312 send_msg.data = data;
313 data[0] = 1; /* Reset asserted state */
314 send_msg.data_len = 1;
315 rv = ipmi_request_in_rc_mode(user,
316 (struct ipmi_addr *) &smi_addr,
317 &send_msg);
318 if (rv)
319 goto out;
320
321 /*
322 * Power down
323 */
324 send_msg.netfn = IPMI_NETFN_OEM_1 >> 2;
325 send_msg.cmd = OEM_GRP_CMD_SET_POWER_STATE;
326 send_msg.data = data;
327 data[0] = 1; /* Power down state */
328 send_msg.data_len = 1;
329 rv = ipmi_request_in_rc_mode(user,
330 (struct ipmi_addr *) &smi_addr,
331 &send_msg);
332 if (rv)
333 goto out;
334
335 out:
336 return;
337}
338
339/*
340 * Standard chassis support
341 */
342
343#define IPMI_NETFN_CHASSIS_REQUEST 0
344#define IPMI_CHASSIS_CONTROL_CMD 0x02
345
346static int ipmi_chassis_detect (ipmi_user_t user)
347{
348 /* Chassis support, use it. */
349 return (capabilities & 0x80);
350}
351
352static void ipmi_poweroff_chassis (ipmi_user_t user)
353{
354 struct ipmi_system_interface_addr smi_addr;
355 struct kernel_ipmi_msg send_msg;
356 int rv;
357 unsigned char data[1];
358
359 /*
360 * Configure IPMI address for local access
361 */
362 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
363 smi_addr.channel = IPMI_BMC_CHANNEL;
364 smi_addr.lun = 0;
365
Corey Minyard3b625942005-06-23 22:01:42 -0700366 powercyclefailed:
367 printk(KERN_INFO PFX "Powering %s via IPMI chassis control command\n",
368 ((poweroff_control != IPMI_CHASSIS_POWER_CYCLE) ? "down" : "cycle"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 /*
371 * Power down
372 */
373 send_msg.netfn = IPMI_NETFN_CHASSIS_REQUEST;
374 send_msg.cmd = IPMI_CHASSIS_CONTROL_CMD;
Corey Minyard3b625942005-06-23 22:01:42 -0700375 data[0] = poweroff_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 send_msg.data = data;
377 send_msg.data_len = sizeof(data);
378 rv = ipmi_request_in_rc_mode(user,
379 (struct ipmi_addr *) &smi_addr,
380 &send_msg);
381 if (rv) {
Corey Minyard3b625942005-06-23 22:01:42 -0700382 switch (poweroff_control) {
383 case IPMI_CHASSIS_POWER_CYCLE:
384 /* power cycle failed, default to power down */
385 printk(KERN_ERR PFX "Unable to send chassis power " \
386 "cycle message, IPMI error 0x%x\n", rv);
387 poweroff_control = IPMI_CHASSIS_POWER_DOWN;
388 goto powercyclefailed;
389
390 case IPMI_CHASSIS_POWER_DOWN:
391 default:
392 printk(KERN_ERR PFX "Unable to send chassis power " \
393 "down message, IPMI error 0x%x\n", rv);
394 break;
395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return;
399}
400
401
402/* Table of possible power off functions. */
403struct poweroff_function {
404 char *platform_type;
405 int (*detect)(ipmi_user_t user);
406 void (*poweroff_func)(ipmi_user_t user);
407};
408
409static struct poweroff_function poweroff_functions[] = {
410 { .platform_type = "ATCA",
411 .detect = ipmi_atca_detect,
412 .poweroff_func = ipmi_poweroff_atca },
413 { .platform_type = "CPI1",
414 .detect = ipmi_cpi1_detect,
415 .poweroff_func = ipmi_poweroff_cpi1 },
416 /* Chassis should generally be last, other things should override
417 it. */
418 { .platform_type = "chassis",
419 .detect = ipmi_chassis_detect,
420 .poweroff_func = ipmi_poweroff_chassis },
421};
422#define NUM_PO_FUNCS (sizeof(poweroff_functions) \
423 / sizeof(struct poweroff_function))
424
425
426/* Our local state. */
427static int ready = 0;
428static ipmi_user_t ipmi_user;
429static void (*specific_poweroff_func)(ipmi_user_t user) = NULL;
430
431/* Holds the old poweroff function so we can restore it on removal. */
432static void (*old_poweroff_func)(void);
433
434
435/* Called on a powerdown request. */
436static void ipmi_poweroff_function (void)
437{
438 if (!ready)
439 return;
440
441 /* Use run-to-completion mode, since interrupts may be off. */
442 ipmi_user_set_run_to_completion(ipmi_user, 1);
443 specific_poweroff_func(ipmi_user);
444 ipmi_user_set_run_to_completion(ipmi_user, 0);
445}
446
447/* Wait for an IPMI interface to be installed, the first one installed
448 will be grabbed by this code and used to perform the powerdown. */
449static void ipmi_po_new_smi(int if_num)
450{
451 struct ipmi_system_interface_addr smi_addr;
452 struct kernel_ipmi_msg send_msg;
453 int rv;
454 int i;
455
456 if (ready)
457 return;
458
Corey Minyard3b625942005-06-23 22:01:42 -0700459 rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL,
460 &ipmi_user);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 if (rv) {
462 printk(KERN_ERR PFX "could not create IPMI user, error %d\n",
463 rv);
464 return;
465 }
466
467 /*
468 * Do a get device ide and store some results, since this is
469 * used by several functions.
470 */
471 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
472 smi_addr.channel = IPMI_BMC_CHANNEL;
473 smi_addr.lun = 0;
474
475 send_msg.netfn = IPMI_NETFN_APP_REQUEST;
476 send_msg.cmd = IPMI_GET_DEVICE_ID_CMD;
477 send_msg.data = NULL;
478 send_msg.data_len = 0;
479 rv = ipmi_request_wait_for_response(ipmi_user,
480 (struct ipmi_addr *) &smi_addr,
481 &send_msg);
482 if (rv) {
483 printk(KERN_ERR PFX "Unable to send IPMI get device id info,"
484 " IPMI error 0x%x\n", rv);
485 goto out_err;
486 }
487
488 if (halt_recv_msg.msg.data_len < 12) {
489 printk(KERN_ERR PFX "(chassis) IPMI get device id info too,"
490 " short, was %d bytes, needed %d bytes\n",
491 halt_recv_msg.msg.data_len, 12);
492 goto out_err;
493 }
494
495 mfg_id = (halt_recv_msg.msg.data[7]
496 | (halt_recv_msg.msg.data[8] << 8)
497 | (halt_recv_msg.msg.data[9] << 16));
498 prod_id = (halt_recv_msg.msg.data[10]
499 | (halt_recv_msg.msg.data[11] << 8));
500 capabilities = halt_recv_msg.msg.data[6];
501
502
503 /* Scan for a poweroff method */
504 for (i=0; i<NUM_PO_FUNCS; i++) {
505 if (poweroff_functions[i].detect(ipmi_user))
506 goto found;
507 }
508
509 out_err:
510 printk(KERN_ERR PFX "Unable to find a poweroff function that"
511 " will work, giving up\n");
512 ipmi_destroy_user(ipmi_user);
513 return;
514
515 found:
516 printk(KERN_INFO PFX "Found a %s style poweroff function\n",
517 poweroff_functions[i].platform_type);
518 specific_poweroff_func = poweroff_functions[i].poweroff_func;
519 old_poweroff_func = pm_power_off;
520 pm_power_off = ipmi_poweroff_function;
521 ready = 1;
522}
523
524static void ipmi_po_smi_gone(int if_num)
525{
526 /* This can never be called, because once poweroff driver is
527 registered, the interface can't go away until the power
528 driver is unregistered. */
529}
530
531static struct ipmi_smi_watcher smi_watcher =
532{
533 .owner = THIS_MODULE,
534 .new_smi = ipmi_po_new_smi,
535 .smi_gone = ipmi_po_smi_gone
536};
537
538
Corey Minyard3b625942005-06-23 22:01:42 -0700539#ifdef CONFIG_PROC_FS
540/* displays properties to proc */
541static int proc_read_chassctrl(char *page, char **start, off_t off, int count,
542 int *eof, void *data)
543{
544 return sprintf(page, "%d\t[ 0=powerdown 2=powercycle ]\n",
545 poweroff_control);
546}
547
548/* process property writes from proc */
549static int proc_write_chassctrl(struct file *file, const char *buffer,
550 unsigned long count, void *data)
551{
552 int rv = count;
553 unsigned int newval = 0;
554
555 sscanf(buffer, "%d", &newval);
556 switch (newval) {
557 case IPMI_CHASSIS_POWER_CYCLE:
558 printk(KERN_INFO PFX "power cycle is now enabled\n");
559 poweroff_control = newval;
560 break;
561
562 case IPMI_CHASSIS_POWER_DOWN:
563 poweroff_control = IPMI_CHASSIS_POWER_DOWN;
564 break;
565
566 default:
567 rv = -EINVAL;
568 break;
569 }
570
571 return rv;
572}
573#endif /* CONFIG_PROC_FS */
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575/*
576 * Startup and shutdown functions.
577 */
578static int ipmi_poweroff_init (void)
579{
Corey Minyard3b625942005-06-23 22:01:42 -0700580 int rv;
581 struct proc_dir_entry *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 printk ("Copyright (C) 2004 MontaVista Software -"
Corey Minyard1fdd75b2005-09-06 15:18:42 -0700584 " IPMI Powerdown via sys_reboot.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Corey Minyard3b625942005-06-23 22:01:42 -0700586 switch (poweroff_control) {
587 case IPMI_CHASSIS_POWER_CYCLE:
588 printk(KERN_INFO PFX "Power cycle is enabled.\n");
589 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Corey Minyard3b625942005-06-23 22:01:42 -0700591 case IPMI_CHASSIS_POWER_DOWN:
592 default:
593 poweroff_control = IPMI_CHASSIS_POWER_DOWN;
594 break;
595 }
596
597 rv = ipmi_smi_watcher_register(&smi_watcher);
598 if (rv) {
599 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
600 goto out_err;
601 }
602
603#ifdef CONFIG_PROC_FS
604 file = create_proc_entry("poweroff_control", 0, proc_ipmi_root);
605 if (!file) {
606 printk(KERN_ERR PFX "Unable to create proc power control\n");
607 } else {
608 file->nlink = 1;
609 file->read_proc = proc_read_chassctrl;
610 file->write_proc = proc_write_chassctrl;
611 file->owner = THIS_MODULE;
612 }
613#endif
614
615 out_err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 return rv;
617}
618
619#ifdef MODULE
620static __exit void ipmi_poweroff_cleanup(void)
621{
622 int rv;
623
Corey Minyard3b625942005-06-23 22:01:42 -0700624#ifdef CONFIG_PROC_FS
625 remove_proc_entry("poweroff_control", proc_ipmi_root);
626#endif
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 ipmi_smi_watcher_unregister(&smi_watcher);
629
630 if (ready) {
631 rv = ipmi_destroy_user(ipmi_user);
632 if (rv)
633 printk(KERN_ERR PFX "could not cleanup the IPMI"
634 " user: 0x%x\n", rv);
635 pm_power_off = old_poweroff_func;
636 }
637}
638module_exit(ipmi_poweroff_cleanup);
639#endif
640
641module_init(ipmi_poweroff_init);
642MODULE_LICENSE("GPL");
Corey Minyard1fdd75b2005-09-06 15:18:42 -0700643MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
644MODULE_DESCRIPTION("IPMI Poweroff extension to sys_reboot");