ipmi_poweroff.c 17 KB

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