ipmi_poweroff.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  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. */
  34. #include <linux/config.h>
  35. #include <linux/module.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/proc_fs.h>
  38. #include <linux/string.h>
  39. #include <linux/completion.h>
  40. #include <linux/pm.h>
  41. #include <linux/kdev_t.h>
  42. #include <linux/ipmi.h>
  43. #include <linux/ipmi_smi.h>
  44. #define PFX "IPMI poweroff: "
  45. /* Definitions for controlling power off (if the system supports it). It
  46. * conveniently matches the IPMI chassis control values. */
  47. #define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */
  48. #define IPMI_CHASSIS_POWER_CYCLE 0x02 /* power cycle */
  49. /* the IPMI data command */
  50. static int poweroff_powercycle;
  51. /* parameter definition to allow user to flag power cycle */
  52. module_param(poweroff_powercycle, int, 0644);
  53. MODULE_PARM_DESC(poweroff_powercycle, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");
  54. /* Stuff from the get device id command. */
  55. static unsigned int mfg_id;
  56. static unsigned int prod_id;
  57. static unsigned char capabilities;
  58. static unsigned char ipmi_version;
  59. /* We use our own messages for this operation, we don't let the system
  60. allocate them, since we may be in a panic situation. The whole
  61. thing is single-threaded, anyway, so multiple messages are not
  62. required. */
  63. static void dummy_smi_free(struct ipmi_smi_msg *msg)
  64. {
  65. }
  66. static void dummy_recv_free(struct ipmi_recv_msg *msg)
  67. {
  68. }
  69. static struct ipmi_smi_msg halt_smi_msg =
  70. {
  71. .done = dummy_smi_free
  72. };
  73. static struct ipmi_recv_msg halt_recv_msg =
  74. {
  75. .done = dummy_recv_free
  76. };
  77. /*
  78. * Code to send a message and wait for the reponse.
  79. */
  80. static void receive_handler(struct ipmi_recv_msg *recv_msg, void *handler_data)
  81. {
  82. struct completion *comp = recv_msg->user_msg_data;
  83. if (comp)
  84. complete(comp);
  85. }
  86. static struct ipmi_user_hndl ipmi_poweroff_handler =
  87. {
  88. .ipmi_recv_hndl = receive_handler
  89. };
  90. static int ipmi_request_wait_for_response(ipmi_user_t user,
  91. struct ipmi_addr *addr,
  92. struct kernel_ipmi_msg *send_msg)
  93. {
  94. int rv;
  95. struct completion comp;
  96. init_completion(&comp);
  97. rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, &comp,
  98. &halt_smi_msg, &halt_recv_msg, 0);
  99. if (rv)
  100. return rv;
  101. wait_for_completion(&comp);
  102. return halt_recv_msg.msg.data[0];
  103. }
  104. /* We are in run-to-completion mode, no completion is desired. */
  105. static int ipmi_request_in_rc_mode(ipmi_user_t user,
  106. struct ipmi_addr *addr,
  107. struct kernel_ipmi_msg *send_msg)
  108. {
  109. int rv;
  110. rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, NULL,
  111. &halt_smi_msg, &halt_recv_msg, 0);
  112. if (rv)
  113. return rv;
  114. return halt_recv_msg.msg.data[0];
  115. }
  116. /*
  117. * ATCA Support
  118. */
  119. #define IPMI_NETFN_ATCA 0x2c
  120. #define IPMI_ATCA_SET_POWER_CMD 0x11
  121. #define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01
  122. #define IPMI_PICMG_ID 0
  123. static int ipmi_atca_detect (ipmi_user_t user)
  124. {
  125. struct ipmi_system_interface_addr smi_addr;
  126. struct kernel_ipmi_msg send_msg;
  127. int rv;
  128. unsigned char data[1];
  129. /*
  130. * Configure IPMI address for local access
  131. */
  132. smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  133. smi_addr.channel = IPMI_BMC_CHANNEL;
  134. smi_addr.lun = 0;
  135. /*
  136. * Use get address info to check and see if we are ATCA
  137. */
  138. send_msg.netfn = IPMI_NETFN_ATCA;
  139. send_msg.cmd = IPMI_ATCA_GET_ADDR_INFO_CMD;
  140. data[0] = IPMI_PICMG_ID;
  141. send_msg.data = data;
  142. send_msg.data_len = sizeof(data);
  143. rv = ipmi_request_wait_for_response(user,
  144. (struct ipmi_addr *) &smi_addr,
  145. &send_msg);
  146. return !rv;
  147. }
  148. static void ipmi_poweroff_atca (ipmi_user_t user)
  149. {
  150. struct ipmi_system_interface_addr smi_addr;
  151. struct kernel_ipmi_msg send_msg;
  152. int rv;
  153. unsigned char data[4];
  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. printk(KERN_INFO PFX "Powering down via ATCA power command\n");
  161. /*
  162. * Power down
  163. */
  164. send_msg.netfn = IPMI_NETFN_ATCA;
  165. send_msg.cmd = IPMI_ATCA_SET_POWER_CMD;
  166. data[0] = IPMI_PICMG_ID;
  167. data[1] = 0; /* FRU id */
  168. data[2] = 0; /* Power Level */
  169. data[3] = 0; /* Don't change saved presets */
  170. send_msg.data = data;
  171. send_msg.data_len = sizeof (data);
  172. rv = ipmi_request_in_rc_mode(user,
  173. (struct ipmi_addr *) &smi_addr,
  174. &send_msg);
  175. if (rv) {
  176. printk(KERN_ERR PFX "Unable to send ATCA powerdown message,"
  177. " IPMI error 0x%x\n", rv);
  178. goto out;
  179. }
  180. out:
  181. return;
  182. }
  183. /*
  184. * CPI1 Support
  185. */
  186. #define IPMI_NETFN_OEM_1 0xf8
  187. #define OEM_GRP_CMD_SET_RESET_STATE 0x84
  188. #define OEM_GRP_CMD_SET_POWER_STATE 0x82
  189. #define IPMI_NETFN_OEM_8 0xf8
  190. #define OEM_GRP_CMD_REQUEST_HOTSWAP_CTRL 0x80
  191. #define OEM_GRP_CMD_GET_SLOT_GA 0xa3
  192. #define IPMI_NETFN_SENSOR_EVT 0x10
  193. #define IPMI_CMD_GET_EVENT_RECEIVER 0x01
  194. #define IPMI_CPI1_PRODUCT_ID 0x000157
  195. #define IPMI_CPI1_MANUFACTURER_ID 0x0108
  196. static int ipmi_cpi1_detect (ipmi_user_t user)
  197. {
  198. return ((mfg_id == IPMI_CPI1_MANUFACTURER_ID)
  199. && (prod_id == IPMI_CPI1_PRODUCT_ID));
  200. }
  201. static void ipmi_poweroff_cpi1 (ipmi_user_t user)
  202. {
  203. struct ipmi_system_interface_addr smi_addr;
  204. struct ipmi_ipmb_addr ipmb_addr;
  205. struct kernel_ipmi_msg send_msg;
  206. int rv;
  207. unsigned char data[1];
  208. int slot;
  209. unsigned char hotswap_ipmb;
  210. unsigned char aer_addr;
  211. unsigned char aer_lun;
  212. /*
  213. * Configure IPMI address for local access
  214. */
  215. smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  216. smi_addr.channel = IPMI_BMC_CHANNEL;
  217. smi_addr.lun = 0;
  218. printk(KERN_INFO PFX "Powering down via CPI1 power command\n");
  219. /*
  220. * Get IPMI ipmb address
  221. */
  222. send_msg.netfn = IPMI_NETFN_OEM_8 >> 2;
  223. send_msg.cmd = OEM_GRP_CMD_GET_SLOT_GA;
  224. send_msg.data = NULL;
  225. send_msg.data_len = 0;
  226. rv = ipmi_request_in_rc_mode(user,
  227. (struct ipmi_addr *) &smi_addr,
  228. &send_msg);
  229. if (rv)
  230. goto out;
  231. slot = halt_recv_msg.msg.data[1];
  232. hotswap_ipmb = (slot > 9) ? (0xb0 + 2 * slot) : (0xae + 2 * slot);
  233. /*
  234. * Get active event receiver
  235. */
  236. send_msg.netfn = IPMI_NETFN_SENSOR_EVT >> 2;
  237. send_msg.cmd = IPMI_CMD_GET_EVENT_RECEIVER;
  238. send_msg.data = NULL;
  239. send_msg.data_len = 0;
  240. rv = ipmi_request_in_rc_mode(user,
  241. (struct ipmi_addr *) &smi_addr,
  242. &send_msg);
  243. if (rv)
  244. goto out;
  245. aer_addr = halt_recv_msg.msg.data[1];
  246. aer_lun = halt_recv_msg.msg.data[2];
  247. /*
  248. * Setup IPMB address target instead of local target
  249. */
  250. ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE;
  251. ipmb_addr.channel = 0;
  252. ipmb_addr.slave_addr = aer_addr;
  253. ipmb_addr.lun = aer_lun;
  254. /*
  255. * Send request hotswap control to remove blade from dpv
  256. */
  257. send_msg.netfn = IPMI_NETFN_OEM_8 >> 2;
  258. send_msg.cmd = OEM_GRP_CMD_REQUEST_HOTSWAP_CTRL;
  259. send_msg.data = &hotswap_ipmb;
  260. send_msg.data_len = 1;
  261. ipmi_request_in_rc_mode(user,
  262. (struct ipmi_addr *) &ipmb_addr,
  263. &send_msg);
  264. /*
  265. * Set reset asserted
  266. */
  267. send_msg.netfn = IPMI_NETFN_OEM_1 >> 2;
  268. send_msg.cmd = OEM_GRP_CMD_SET_RESET_STATE;
  269. send_msg.data = data;
  270. data[0] = 1; /* Reset asserted state */
  271. send_msg.data_len = 1;
  272. rv = ipmi_request_in_rc_mode(user,
  273. (struct ipmi_addr *) &smi_addr,
  274. &send_msg);
  275. if (rv)
  276. goto out;
  277. /*
  278. * Power down
  279. */
  280. send_msg.netfn = IPMI_NETFN_OEM_1 >> 2;
  281. send_msg.cmd = OEM_GRP_CMD_SET_POWER_STATE;
  282. send_msg.data = data;
  283. data[0] = 1; /* Power down state */
  284. send_msg.data_len = 1;
  285. rv = ipmi_request_in_rc_mode(user,
  286. (struct ipmi_addr *) &smi_addr,
  287. &send_msg);
  288. if (rv)
  289. goto out;
  290. out:
  291. return;
  292. }
  293. /*
  294. * ipmi_dell_chassis_detect()
  295. * Dell systems with IPMI < 1.5 don't set the chassis capability bit
  296. * but they can handle a chassis poweroff or powercycle command.
  297. */
  298. #define DELL_IANA_MFR_ID {0xA2, 0x02, 0x00}
  299. static int ipmi_dell_chassis_detect (ipmi_user_t user)
  300. {
  301. const char ipmi_version_major = ipmi_version & 0xF;
  302. const char ipmi_version_minor = (ipmi_version >> 4) & 0xF;
  303. const char mfr[3] = DELL_IANA_MFR_ID;
  304. if (!memcmp(mfr, &mfg_id, sizeof(mfr)) &&
  305. ipmi_version_major <= 1 &&
  306. ipmi_version_minor < 5)
  307. return 1;
  308. return 0;
  309. }
  310. /*
  311. * Standard chassis support
  312. */
  313. #define IPMI_NETFN_CHASSIS_REQUEST 0
  314. #define IPMI_CHASSIS_CONTROL_CMD 0x02
  315. static int ipmi_chassis_detect (ipmi_user_t user)
  316. {
  317. /* Chassis support, use it. */
  318. return (capabilities & 0x80);
  319. }
  320. static void ipmi_poweroff_chassis (ipmi_user_t user)
  321. {
  322. struct ipmi_system_interface_addr smi_addr;
  323. struct kernel_ipmi_msg send_msg;
  324. int rv;
  325. unsigned char data[1];
  326. /*
  327. * Configure IPMI address for local access
  328. */
  329. smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  330. smi_addr.channel = IPMI_BMC_CHANNEL;
  331. smi_addr.lun = 0;
  332. powercyclefailed:
  333. printk(KERN_INFO PFX "Powering %s via IPMI chassis control command\n",
  334. (poweroff_powercycle ? "cycle" : "down"));
  335. /*
  336. * Power down
  337. */
  338. send_msg.netfn = IPMI_NETFN_CHASSIS_REQUEST;
  339. send_msg.cmd = IPMI_CHASSIS_CONTROL_CMD;
  340. if (poweroff_powercycle)
  341. data[0] = IPMI_CHASSIS_POWER_CYCLE;
  342. else
  343. data[0] = IPMI_CHASSIS_POWER_DOWN;
  344. send_msg.data = data;
  345. send_msg.data_len = sizeof(data);
  346. rv = ipmi_request_in_rc_mode(user,
  347. (struct ipmi_addr *) &smi_addr,
  348. &send_msg);
  349. if (rv) {
  350. if (poweroff_powercycle) {
  351. /* power cycle failed, default to power down */
  352. printk(KERN_ERR PFX "Unable to send chassis power " \
  353. "cycle message, IPMI error 0x%x\n", rv);
  354. poweroff_powercycle = 0;
  355. goto powercyclefailed;
  356. }
  357. printk(KERN_ERR PFX "Unable to send chassis power " \
  358. "down message, IPMI error 0x%x\n", rv);
  359. }
  360. }
  361. /* Table of possible power off functions. */
  362. struct poweroff_function {
  363. char *platform_type;
  364. int (*detect)(ipmi_user_t user);
  365. void (*poweroff_func)(ipmi_user_t user);
  366. };
  367. static struct poweroff_function poweroff_functions[] = {
  368. { .platform_type = "ATCA",
  369. .detect = ipmi_atca_detect,
  370. .poweroff_func = ipmi_poweroff_atca },
  371. { .platform_type = "CPI1",
  372. .detect = ipmi_cpi1_detect,
  373. .poweroff_func = ipmi_poweroff_cpi1 },
  374. { .platform_type = "chassis",
  375. .detect = ipmi_dell_chassis_detect,
  376. .poweroff_func = ipmi_poweroff_chassis },
  377. /* Chassis should generally be last, other things should override
  378. it. */
  379. { .platform_type = "chassis",
  380. .detect = ipmi_chassis_detect,
  381. .poweroff_func = ipmi_poweroff_chassis },
  382. };
  383. #define NUM_PO_FUNCS (sizeof(poweroff_functions) \
  384. / sizeof(struct poweroff_function))
  385. /* Our local state. */
  386. static int ready = 0;
  387. static ipmi_user_t ipmi_user;
  388. static void (*specific_poweroff_func)(ipmi_user_t user) = NULL;
  389. /* Holds the old poweroff function so we can restore it on removal. */
  390. static void (*old_poweroff_func)(void);
  391. /* Called on a powerdown request. */
  392. static void ipmi_poweroff_function (void)
  393. {
  394. if (!ready)
  395. return;
  396. /* Use run-to-completion mode, since interrupts may be off. */
  397. ipmi_user_set_run_to_completion(ipmi_user, 1);
  398. specific_poweroff_func(ipmi_user);
  399. ipmi_user_set_run_to_completion(ipmi_user, 0);
  400. }
  401. /* Wait for an IPMI interface to be installed, the first one installed
  402. will be grabbed by this code and used to perform the powerdown. */
  403. static void ipmi_po_new_smi(int if_num, struct device *device)
  404. {
  405. struct ipmi_system_interface_addr smi_addr;
  406. struct kernel_ipmi_msg send_msg;
  407. int rv;
  408. int i;
  409. if (ready)
  410. return;
  411. rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL,
  412. &ipmi_user);
  413. if (rv) {
  414. printk(KERN_ERR PFX "could not create IPMI user, error %d\n",
  415. rv);
  416. return;
  417. }
  418. /*
  419. * Do a get device ide and store some results, since this is
  420. * used by several functions.
  421. */
  422. smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  423. smi_addr.channel = IPMI_BMC_CHANNEL;
  424. smi_addr.lun = 0;
  425. send_msg.netfn = IPMI_NETFN_APP_REQUEST;
  426. send_msg.cmd = IPMI_GET_DEVICE_ID_CMD;
  427. send_msg.data = NULL;
  428. send_msg.data_len = 0;
  429. rv = ipmi_request_wait_for_response(ipmi_user,
  430. (struct ipmi_addr *) &smi_addr,
  431. &send_msg);
  432. if (rv) {
  433. printk(KERN_ERR PFX "Unable to send IPMI get device id info,"
  434. " IPMI error 0x%x\n", rv);
  435. goto out_err;
  436. }
  437. if (halt_recv_msg.msg.data_len < 12) {
  438. printk(KERN_ERR PFX "(chassis) IPMI get device id info too,"
  439. " short, was %d bytes, needed %d bytes\n",
  440. halt_recv_msg.msg.data_len, 12);
  441. goto out_err;
  442. }
  443. mfg_id = (halt_recv_msg.msg.data[7]
  444. | (halt_recv_msg.msg.data[8] << 8)
  445. | (halt_recv_msg.msg.data[9] << 16));
  446. prod_id = (halt_recv_msg.msg.data[10]
  447. | (halt_recv_msg.msg.data[11] << 8));
  448. capabilities = halt_recv_msg.msg.data[6];
  449. ipmi_version = halt_recv_msg.msg.data[5];
  450. /* Scan for a poweroff method */
  451. for (i = 0; i < NUM_PO_FUNCS; i++) {
  452. if (poweroff_functions[i].detect(ipmi_user))
  453. goto found;
  454. }
  455. out_err:
  456. printk(KERN_ERR PFX "Unable to find a poweroff function that"
  457. " will work, giving up\n");
  458. ipmi_destroy_user(ipmi_user);
  459. return;
  460. found:
  461. printk(KERN_INFO PFX "Found a %s style poweroff function\n",
  462. poweroff_functions[i].platform_type);
  463. specific_poweroff_func = poweroff_functions[i].poweroff_func;
  464. old_poweroff_func = pm_power_off;
  465. pm_power_off = ipmi_poweroff_function;
  466. ready = 1;
  467. }
  468. static void ipmi_po_smi_gone(int if_num)
  469. {
  470. /* This can never be called, because once poweroff driver is
  471. registered, the interface can't go away until the power
  472. driver is unregistered. */
  473. }
  474. static struct ipmi_smi_watcher smi_watcher =
  475. {
  476. .owner = THIS_MODULE,
  477. .new_smi = ipmi_po_new_smi,
  478. .smi_gone = ipmi_po_smi_gone
  479. };
  480. #ifdef CONFIG_PROC_FS
  481. #include <linux/sysctl.h>
  482. static ctl_table ipmi_table[] = {
  483. { .ctl_name = DEV_IPMI_POWEROFF_POWERCYCLE,
  484. .procname = "poweroff_powercycle",
  485. .data = &poweroff_powercycle,
  486. .maxlen = sizeof(poweroff_powercycle),
  487. .mode = 0644,
  488. .proc_handler = &proc_dointvec },
  489. { }
  490. };
  491. static ctl_table ipmi_dir_table[] = {
  492. { .ctl_name = DEV_IPMI,
  493. .procname = "ipmi",
  494. .mode = 0555,
  495. .child = ipmi_table },
  496. { }
  497. };
  498. static ctl_table ipmi_root_table[] = {
  499. { .ctl_name = CTL_DEV,
  500. .procname = "dev",
  501. .mode = 0555,
  502. .child = ipmi_dir_table },
  503. { }
  504. };
  505. static struct ctl_table_header *ipmi_table_header;
  506. #endif /* CONFIG_PROC_FS */
  507. /*
  508. * Startup and shutdown functions.
  509. */
  510. static int ipmi_poweroff_init (void)
  511. {
  512. int rv;
  513. printk ("Copyright (C) 2004 MontaVista Software -"
  514. " IPMI Powerdown via sys_reboot.\n");
  515. if (poweroff_powercycle)
  516. printk(KERN_INFO PFX "Power cycle is enabled.\n");
  517. #ifdef CONFIG_PROC_FS
  518. ipmi_table_header = register_sysctl_table(ipmi_root_table, 1);
  519. if (!ipmi_table_header) {
  520. printk(KERN_ERR PFX "Unable to register powercycle sysctl\n");
  521. rv = -ENOMEM;
  522. goto out_err;
  523. }
  524. #endif
  525. rv = ipmi_smi_watcher_register(&smi_watcher);
  526. #ifdef CONFIG_PROC_FS
  527. if (rv) {
  528. unregister_sysctl_table(ipmi_table_header);
  529. printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
  530. goto out_err;
  531. }
  532. #endif
  533. out_err:
  534. return rv;
  535. }
  536. #ifdef MODULE
  537. static __exit void ipmi_poweroff_cleanup(void)
  538. {
  539. int rv;
  540. #ifdef CONFIG_PROC_FS
  541. unregister_sysctl_table(ipmi_table_header);
  542. #endif
  543. ipmi_smi_watcher_unregister(&smi_watcher);
  544. if (ready) {
  545. rv = ipmi_destroy_user(ipmi_user);
  546. if (rv)
  547. printk(KERN_ERR PFX "could not cleanup the IPMI"
  548. " user: 0x%x\n", rv);
  549. pm_power_off = old_poweroff_func;
  550. }
  551. }
  552. module_exit(ipmi_poweroff_cleanup);
  553. #endif
  554. module_init(ipmi_poweroff_init);
  555. MODULE_LICENSE("GPL");
  556. MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
  557. MODULE_DESCRIPTION("IPMI Poweroff extension to sys_reboot");