ipmi_poweroff.c 17 KB

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