ipmi_poweroff.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. #define IPMI_POWEROFF_VERSION "v33"
  45. /* Where to we insert our poweroff function? */
  46. extern void (*pm_power_off)(void);
  47. /* Definitions for controlling power off (if the system supports it). It
  48. * conveniently matches the IPMI chassis control values. */
  49. #define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */
  50. #define IPMI_CHASSIS_POWER_CYCLE 0x02 /* power cycle */
  51. /* the IPMI data command */
  52. static int poweroff_control = IPMI_CHASSIS_POWER_DOWN;
  53. /* parameter definition to allow user to flag power cycle */
  54. module_param(poweroff_control, int, IPMI_CHASSIS_POWER_DOWN);
  55. MODULE_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.");
  56. /* Stuff from the get device id command. */
  57. static unsigned int mfg_id;
  58. static unsigned int prod_id;
  59. static unsigned char capabilities;
  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. * Standard chassis support
  296. */
  297. #define IPMI_NETFN_CHASSIS_REQUEST 0
  298. #define IPMI_CHASSIS_CONTROL_CMD 0x02
  299. static int ipmi_chassis_detect (ipmi_user_t user)
  300. {
  301. /* Chassis support, use it. */
  302. return (capabilities & 0x80);
  303. }
  304. static void ipmi_poweroff_chassis (ipmi_user_t user)
  305. {
  306. struct ipmi_system_interface_addr smi_addr;
  307. struct kernel_ipmi_msg send_msg;
  308. int rv;
  309. unsigned char data[1];
  310. /*
  311. * Configure IPMI address for local access
  312. */
  313. smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  314. smi_addr.channel = IPMI_BMC_CHANNEL;
  315. smi_addr.lun = 0;
  316. powercyclefailed:
  317. printk(KERN_INFO PFX "Powering %s via IPMI chassis control command\n",
  318. ((poweroff_control != IPMI_CHASSIS_POWER_CYCLE) ? "down" : "cycle"));
  319. /*
  320. * Power down
  321. */
  322. send_msg.netfn = IPMI_NETFN_CHASSIS_REQUEST;
  323. send_msg.cmd = IPMI_CHASSIS_CONTROL_CMD;
  324. data[0] = poweroff_control;
  325. send_msg.data = data;
  326. send_msg.data_len = sizeof(data);
  327. rv = ipmi_request_in_rc_mode(user,
  328. (struct ipmi_addr *) &smi_addr,
  329. &send_msg);
  330. if (rv) {
  331. switch (poweroff_control) {
  332. case IPMI_CHASSIS_POWER_CYCLE:
  333. /* power cycle failed, default to power down */
  334. printk(KERN_ERR PFX "Unable to send chassis power " \
  335. "cycle message, IPMI error 0x%x\n", rv);
  336. poweroff_control = IPMI_CHASSIS_POWER_DOWN;
  337. goto powercyclefailed;
  338. case IPMI_CHASSIS_POWER_DOWN:
  339. default:
  340. printk(KERN_ERR PFX "Unable to send chassis power " \
  341. "down message, IPMI error 0x%x\n", rv);
  342. break;
  343. }
  344. }
  345. return;
  346. }
  347. /* Table of possible power off functions. */
  348. struct poweroff_function {
  349. char *platform_type;
  350. int (*detect)(ipmi_user_t user);
  351. void (*poweroff_func)(ipmi_user_t user);
  352. };
  353. static struct poweroff_function poweroff_functions[] = {
  354. { .platform_type = "ATCA",
  355. .detect = ipmi_atca_detect,
  356. .poweroff_func = ipmi_poweroff_atca },
  357. { .platform_type = "CPI1",
  358. .detect = ipmi_cpi1_detect,
  359. .poweroff_func = ipmi_poweroff_cpi1 },
  360. /* Chassis should generally be last, other things should override
  361. it. */
  362. { .platform_type = "chassis",
  363. .detect = ipmi_chassis_detect,
  364. .poweroff_func = ipmi_poweroff_chassis },
  365. };
  366. #define NUM_PO_FUNCS (sizeof(poweroff_functions) \
  367. / sizeof(struct poweroff_function))
  368. /* Our local state. */
  369. static int ready = 0;
  370. static ipmi_user_t ipmi_user;
  371. static void (*specific_poweroff_func)(ipmi_user_t user) = NULL;
  372. /* Holds the old poweroff function so we can restore it on removal. */
  373. static void (*old_poweroff_func)(void);
  374. /* Called on a powerdown request. */
  375. static void ipmi_poweroff_function (void)
  376. {
  377. if (!ready)
  378. return;
  379. /* Use run-to-completion mode, since interrupts may be off. */
  380. ipmi_user_set_run_to_completion(ipmi_user, 1);
  381. specific_poweroff_func(ipmi_user);
  382. ipmi_user_set_run_to_completion(ipmi_user, 0);
  383. }
  384. /* Wait for an IPMI interface to be installed, the first one installed
  385. will be grabbed by this code and used to perform the powerdown. */
  386. static void ipmi_po_new_smi(int if_num)
  387. {
  388. struct ipmi_system_interface_addr smi_addr;
  389. struct kernel_ipmi_msg send_msg;
  390. int rv;
  391. int i;
  392. if (ready)
  393. return;
  394. rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL,
  395. &ipmi_user);
  396. if (rv) {
  397. printk(KERN_ERR PFX "could not create IPMI user, error %d\n",
  398. rv);
  399. return;
  400. }
  401. /*
  402. * Do a get device ide and store some results, since this is
  403. * used by several functions.
  404. */
  405. smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  406. smi_addr.channel = IPMI_BMC_CHANNEL;
  407. smi_addr.lun = 0;
  408. send_msg.netfn = IPMI_NETFN_APP_REQUEST;
  409. send_msg.cmd = IPMI_GET_DEVICE_ID_CMD;
  410. send_msg.data = NULL;
  411. send_msg.data_len = 0;
  412. rv = ipmi_request_wait_for_response(ipmi_user,
  413. (struct ipmi_addr *) &smi_addr,
  414. &send_msg);
  415. if (rv) {
  416. printk(KERN_ERR PFX "Unable to send IPMI get device id info,"
  417. " IPMI error 0x%x\n", rv);
  418. goto out_err;
  419. }
  420. if (halt_recv_msg.msg.data_len < 12) {
  421. printk(KERN_ERR PFX "(chassis) IPMI get device id info too,"
  422. " short, was %d bytes, needed %d bytes\n",
  423. halt_recv_msg.msg.data_len, 12);
  424. goto out_err;
  425. }
  426. mfg_id = (halt_recv_msg.msg.data[7]
  427. | (halt_recv_msg.msg.data[8] << 8)
  428. | (halt_recv_msg.msg.data[9] << 16));
  429. prod_id = (halt_recv_msg.msg.data[10]
  430. | (halt_recv_msg.msg.data[11] << 8));
  431. capabilities = halt_recv_msg.msg.data[6];
  432. /* Scan for a poweroff method */
  433. for (i=0; i<NUM_PO_FUNCS; i++) {
  434. if (poweroff_functions[i].detect(ipmi_user))
  435. goto found;
  436. }
  437. out_err:
  438. printk(KERN_ERR PFX "Unable to find a poweroff function that"
  439. " will work, giving up\n");
  440. ipmi_destroy_user(ipmi_user);
  441. return;
  442. found:
  443. printk(KERN_INFO PFX "Found a %s style poweroff function\n",
  444. poweroff_functions[i].platform_type);
  445. specific_poweroff_func = poweroff_functions[i].poweroff_func;
  446. old_poweroff_func = pm_power_off;
  447. pm_power_off = ipmi_poweroff_function;
  448. ready = 1;
  449. }
  450. static void ipmi_po_smi_gone(int if_num)
  451. {
  452. /* This can never be called, because once poweroff driver is
  453. registered, the interface can't go away until the power
  454. driver is unregistered. */
  455. }
  456. static struct ipmi_smi_watcher smi_watcher =
  457. {
  458. .owner = THIS_MODULE,
  459. .new_smi = ipmi_po_new_smi,
  460. .smi_gone = ipmi_po_smi_gone
  461. };
  462. #ifdef CONFIG_PROC_FS
  463. /* displays properties to proc */
  464. static int proc_read_chassctrl(char *page, char **start, off_t off, int count,
  465. int *eof, void *data)
  466. {
  467. return sprintf(page, "%d\t[ 0=powerdown 2=powercycle ]\n",
  468. poweroff_control);
  469. }
  470. /* process property writes from proc */
  471. static int proc_write_chassctrl(struct file *file, const char *buffer,
  472. unsigned long count, void *data)
  473. {
  474. int rv = count;
  475. unsigned int newval = 0;
  476. sscanf(buffer, "%d", &newval);
  477. switch (newval) {
  478. case IPMI_CHASSIS_POWER_CYCLE:
  479. printk(KERN_INFO PFX "power cycle is now enabled\n");
  480. poweroff_control = newval;
  481. break;
  482. case IPMI_CHASSIS_POWER_DOWN:
  483. poweroff_control = IPMI_CHASSIS_POWER_DOWN;
  484. break;
  485. default:
  486. rv = -EINVAL;
  487. break;
  488. }
  489. return rv;
  490. }
  491. #endif /* CONFIG_PROC_FS */
  492. /*
  493. * Startup and shutdown functions.
  494. */
  495. static int ipmi_poweroff_init (void)
  496. {
  497. int rv;
  498. struct proc_dir_entry *file;
  499. printk ("Copyright (C) 2004 MontaVista Software -"
  500. " IPMI Powerdown via sys_reboot version "
  501. IPMI_POWEROFF_VERSION ".\n");
  502. switch (poweroff_control) {
  503. case IPMI_CHASSIS_POWER_CYCLE:
  504. printk(KERN_INFO PFX "Power cycle is enabled.\n");
  505. break;
  506. case IPMI_CHASSIS_POWER_DOWN:
  507. default:
  508. poweroff_control = IPMI_CHASSIS_POWER_DOWN;
  509. break;
  510. }
  511. rv = ipmi_smi_watcher_register(&smi_watcher);
  512. if (rv) {
  513. printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
  514. goto out_err;
  515. }
  516. #ifdef CONFIG_PROC_FS
  517. file = create_proc_entry("poweroff_control", 0, proc_ipmi_root);
  518. if (!file) {
  519. printk(KERN_ERR PFX "Unable to create proc power control\n");
  520. } else {
  521. file->nlink = 1;
  522. file->read_proc = proc_read_chassctrl;
  523. file->write_proc = proc_write_chassctrl;
  524. file->owner = THIS_MODULE;
  525. }
  526. #endif
  527. out_err:
  528. return rv;
  529. }
  530. #ifdef MODULE
  531. static __exit void ipmi_poweroff_cleanup(void)
  532. {
  533. int rv;
  534. #ifdef CONFIG_PROC_FS
  535. remove_proc_entry("poweroff_control", proc_ipmi_root);
  536. #endif
  537. ipmi_smi_watcher_unregister(&smi_watcher);
  538. if (ready) {
  539. rv = ipmi_destroy_user(ipmi_user);
  540. if (rv)
  541. printk(KERN_ERR PFX "could not cleanup the IPMI"
  542. " user: 0x%x\n", rv);
  543. pm_power_off = old_poweroff_func;
  544. }
  545. }
  546. module_exit(ipmi_poweroff_cleanup);
  547. #endif
  548. module_init(ipmi_poweroff_init);
  549. MODULE_LICENSE("GPL");