diff options
Diffstat (limited to 'drivers/char/ipmi/ipmi_poweroff.c')
-rw-r--r-- | drivers/char/ipmi/ipmi_poweroff.c | 114 |
1 files changed, 100 insertions, 14 deletions
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c index 8d941db83457..9d23136e598a 100644 --- a/drivers/char/ipmi/ipmi_poweroff.c +++ b/drivers/char/ipmi/ipmi_poweroff.c | |||
@@ -43,6 +43,9 @@ | |||
43 | 43 | ||
44 | #define PFX "IPMI poweroff: " | 44 | #define PFX "IPMI poweroff: " |
45 | 45 | ||
46 | static void ipmi_po_smi_gone(int if_num); | ||
47 | static void ipmi_po_new_smi(int if_num, struct device *device); | ||
48 | |||
46 | /* Definitions for controlling power off (if the system supports it). It | 49 | /* Definitions for controlling power off (if the system supports it). It |
47 | * conveniently matches the IPMI chassis control values. */ | 50 | * conveniently matches the IPMI chassis control values. */ |
48 | #define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */ | 51 | #define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */ |
@@ -51,6 +54,37 @@ | |||
51 | /* the IPMI data command */ | 54 | /* the IPMI data command */ |
52 | static int poweroff_powercycle; | 55 | static int poweroff_powercycle; |
53 | 56 | ||
57 | /* Which interface to use, -1 means the first we see. */ | ||
58 | static int ifnum_to_use = -1; | ||
59 | |||
60 | /* Our local state. */ | ||
61 | static int ready; | ||
62 | static ipmi_user_t ipmi_user; | ||
63 | static int ipmi_ifnum; | ||
64 | static void (*specific_poweroff_func)(ipmi_user_t user); | ||
65 | |||
66 | /* Holds the old poweroff function so we can restore it on removal. */ | ||
67 | static void (*old_poweroff_func)(void); | ||
68 | |||
69 | static int set_param_ifnum(const char *val, struct kernel_param *kp) | ||
70 | { | ||
71 | int rv = param_set_int(val, kp); | ||
72 | if (rv) | ||
73 | return rv; | ||
74 | if ((ifnum_to_use < 0) || (ifnum_to_use == ipmi_ifnum)) | ||
75 | return 0; | ||
76 | |||
77 | ipmi_po_smi_gone(ipmi_ifnum); | ||
78 | ipmi_po_new_smi(ifnum_to_use, NULL); | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | module_param_call(ifnum_to_use, set_param_ifnum, param_get_int, | ||
83 | &ifnum_to_use, 0644); | ||
84 | MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog " | ||
85 | "timer. Setting to -1 defaults to the first registered " | ||
86 | "interface"); | ||
87 | |||
54 | /* parameter definition to allow user to flag power cycle */ | 88 | /* parameter definition to allow user to flag power cycle */ |
55 | module_param(poweroff_powercycle, int, 0644); | 89 | module_param(poweroff_powercycle, int, 0644); |
56 | 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."); | 90 | 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."); |
@@ -142,6 +176,42 @@ static int ipmi_request_in_rc_mode(ipmi_user_t user, | |||
142 | #define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01 | 176 | #define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01 |
143 | #define IPMI_PICMG_ID 0 | 177 | #define IPMI_PICMG_ID 0 |
144 | 178 | ||
179 | #define IPMI_NETFN_OEM 0x2e | ||
180 | #define IPMI_ATCA_PPS_GRACEFUL_RESTART 0x11 | ||
181 | #define IPMI_ATCA_PPS_IANA "\x00\x40\x0A" | ||
182 | #define IPMI_MOTOROLA_MANUFACTURER_ID 0x0000A1 | ||
183 | #define IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID 0x0051 | ||
184 | |||
185 | static void (*atca_oem_poweroff_hook)(ipmi_user_t user); | ||
186 | |||
187 | static void pps_poweroff_atca (ipmi_user_t user) | ||
188 | { | ||
189 | struct ipmi_system_interface_addr smi_addr; | ||
190 | struct kernel_ipmi_msg send_msg; | ||
191 | int rv; | ||
192 | /* | ||
193 | * Configure IPMI address for local access | ||
194 | */ | ||
195 | smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | ||
196 | smi_addr.channel = IPMI_BMC_CHANNEL; | ||
197 | smi_addr.lun = 0; | ||
198 | |||
199 | printk(KERN_INFO PFX "PPS powerdown hook used"); | ||
200 | |||
201 | send_msg.netfn = IPMI_NETFN_OEM; | ||
202 | send_msg.cmd = IPMI_ATCA_PPS_GRACEFUL_RESTART; | ||
203 | send_msg.data = IPMI_ATCA_PPS_IANA; | ||
204 | send_msg.data_len = 3; | ||
205 | rv = ipmi_request_in_rc_mode(user, | ||
206 | (struct ipmi_addr *) &smi_addr, | ||
207 | &send_msg); | ||
208 | if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) { | ||
209 | printk(KERN_ERR PFX "Unable to send ATCA ," | ||
210 | " IPMI error 0x%x\n", rv); | ||
211 | } | ||
212 | return; | ||
213 | } | ||
214 | |||
145 | static int ipmi_atca_detect (ipmi_user_t user) | 215 | static int ipmi_atca_detect (ipmi_user_t user) |
146 | { | 216 | { |
147 | struct ipmi_system_interface_addr smi_addr; | 217 | struct ipmi_system_interface_addr smi_addr; |
@@ -167,6 +237,13 @@ static int ipmi_atca_detect (ipmi_user_t user) | |||
167 | rv = ipmi_request_wait_for_response(user, | 237 | rv = ipmi_request_wait_for_response(user, |
168 | (struct ipmi_addr *) &smi_addr, | 238 | (struct ipmi_addr *) &smi_addr, |
169 | &send_msg); | 239 | &send_msg); |
240 | |||
241 | printk(KERN_INFO PFX "ATCA Detect mfg 0x%X prod 0x%X\n", mfg_id, prod_id); | ||
242 | if((mfg_id == IPMI_MOTOROLA_MANUFACTURER_ID) | ||
243 | && (prod_id == IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID)) { | ||
244 | printk(KERN_INFO PFX "Installing Pigeon Point Systems Poweroff Hook\n"); | ||
245 | atca_oem_poweroff_hook = pps_poweroff_atca; | ||
246 | } | ||
170 | return !rv; | 247 | return !rv; |
171 | } | 248 | } |
172 | 249 | ||
@@ -200,12 +277,19 @@ static void ipmi_poweroff_atca (ipmi_user_t user) | |||
200 | rv = ipmi_request_in_rc_mode(user, | 277 | rv = ipmi_request_in_rc_mode(user, |
201 | (struct ipmi_addr *) &smi_addr, | 278 | (struct ipmi_addr *) &smi_addr, |
202 | &send_msg); | 279 | &send_msg); |
203 | if (rv) { | 280 | /** At this point, the system may be shutting down, and most |
281 | ** serial drivers (if used) will have interrupts turned off | ||
282 | ** it may be better to ignore IPMI_UNKNOWN_ERR_COMPLETION_CODE | ||
283 | ** return code | ||
284 | **/ | ||
285 | if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) { | ||
204 | printk(KERN_ERR PFX "Unable to send ATCA powerdown message," | 286 | printk(KERN_ERR PFX "Unable to send ATCA powerdown message," |
205 | " IPMI error 0x%x\n", rv); | 287 | " IPMI error 0x%x\n", rv); |
206 | goto out; | 288 | goto out; |
207 | } | 289 | } |
208 | 290 | ||
291 | if(atca_oem_poweroff_hook) | ||
292 | return atca_oem_poweroff_hook(user); | ||
209 | out: | 293 | out: |
210 | return; | 294 | return; |
211 | } | 295 | } |
@@ -440,15 +524,6 @@ static struct poweroff_function poweroff_functions[] = { | |||
440 | / sizeof(struct poweroff_function)) | 524 | / sizeof(struct poweroff_function)) |
441 | 525 | ||
442 | 526 | ||
443 | /* Our local state. */ | ||
444 | static int ready = 0; | ||
445 | static ipmi_user_t ipmi_user; | ||
446 | static void (*specific_poweroff_func)(ipmi_user_t user) = NULL; | ||
447 | |||
448 | /* Holds the old poweroff function so we can restore it on removal. */ | ||
449 | static void (*old_poweroff_func)(void); | ||
450 | |||
451 | |||
452 | /* Called on a powerdown request. */ | 527 | /* Called on a powerdown request. */ |
453 | static void ipmi_poweroff_function (void) | 528 | static void ipmi_poweroff_function (void) |
454 | { | 529 | { |
@@ -473,6 +548,9 @@ static void ipmi_po_new_smi(int if_num, struct device *device) | |||
473 | if (ready) | 548 | if (ready) |
474 | return; | 549 | return; |
475 | 550 | ||
551 | if ((ifnum_to_use >= 0) && (ifnum_to_use != if_num)) | ||
552 | return; | ||
553 | |||
476 | rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL, | 554 | rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL, |
477 | &ipmi_user); | 555 | &ipmi_user); |
478 | if (rv) { | 556 | if (rv) { |
@@ -481,6 +559,8 @@ static void ipmi_po_new_smi(int if_num, struct device *device) | |||
481 | return; | 559 | return; |
482 | } | 560 | } |
483 | 561 | ||
562 | ipmi_ifnum = if_num; | ||
563 | |||
484 | /* | 564 | /* |
485 | * Do a get device ide and store some results, since this is | 565 | * Do a get device ide and store some results, since this is |
486 | * used by several functions. | 566 | * used by several functions. |
@@ -541,9 +621,15 @@ static void ipmi_po_new_smi(int if_num, struct device *device) | |||
541 | 621 | ||
542 | static void ipmi_po_smi_gone(int if_num) | 622 | static void ipmi_po_smi_gone(int if_num) |
543 | { | 623 | { |
544 | /* This can never be called, because once poweroff driver is | 624 | if (!ready) |
545 | registered, the interface can't go away until the power | 625 | return; |
546 | driver is unregistered. */ | 626 | |
627 | if (ipmi_ifnum != if_num) | ||
628 | return; | ||
629 | |||
630 | ready = 0; | ||
631 | ipmi_destroy_user(ipmi_user); | ||
632 | pm_power_off = old_poweroff_func; | ||
547 | } | 633 | } |
548 | 634 | ||
549 | static struct ipmi_smi_watcher smi_watcher = | 635 | static struct ipmi_smi_watcher smi_watcher = |
@@ -616,9 +702,9 @@ static int ipmi_poweroff_init (void) | |||
616 | printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); | 702 | printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); |
617 | goto out_err; | 703 | goto out_err; |
618 | } | 704 | } |
619 | #endif | ||
620 | 705 | ||
621 | out_err: | 706 | out_err: |
707 | #endif | ||
622 | return rv; | 708 | return rv; |
623 | } | 709 | } |
624 | 710 | ||