ipmi_poweroff.c 18 KB

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