| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 |  | 
|  | 2 | /* | 
|  | 3 | * IBM ASM Service Processor Device Driver | 
|  | 4 | * | 
|  | 5 | * This program is free software; you can redistribute it and/or modify | 
|  | 6 | * it under the terms of the GNU General Public License as published by | 
|  | 7 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 8 | * (at your option) any later version. | 
|  | 9 | * | 
|  | 10 | * This program is distributed in the hope that it will be useful, | 
|  | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 13 | * GNU General Public License for more details. | 
|  | 14 | * | 
|  | 15 | * You should have received a copy of the GNU General Public License | 
|  | 16 | * along with this program; if not, write to the Free Software | 
|  | 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 
|  | 18 | * | 
|  | 19 | * Copyright (C) IBM Corporation, 2004 | 
|  | 20 | * | 
| Dmitry Torokhov | 3110dc7 | 2007-07-17 04:03:58 -0700 | [diff] [blame] | 21 | * Author: Max Asböck <amax@us.ibm.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * | 
|  | 23 | */ | 
|  | 24 |  | 
|  | 25 | #include <linux/notifier.h> | 
|  | 26 | #include "ibmasm.h" | 
|  | 27 | #include "dot_command.h" | 
| Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 28 | #include "lowlevel.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 |  | 
|  | 30 | static int suspend_heartbeats = 0; | 
|  | 31 |  | 
|  | 32 | /* | 
|  | 33 | * Once the driver indicates to the service processor that it is running | 
|  | 34 | * - see send_os_state() - the service processor sends periodic heartbeats | 
|  | 35 | * to the driver. The driver must respond to the heartbeats or else the OS | 
|  | 36 | * will be rebooted. | 
|  | 37 | * In the case of a panic the interrupt handler continues to work and thus | 
|  | 38 | * continues to respond to heartbeats, making the service processor believe | 
|  | 39 | * the OS is still running and thus preventing a reboot. | 
|  | 40 | * To prevent this from happening a callback is added the panic_notifier_list. | 
|  | 41 | * Before responding to a heartbeat the driver checks if a panic has happened, | 
|  | 42 | * if yes it suspends heartbeat, causing the service processor to reboot as | 
|  | 43 | * expected. | 
|  | 44 | */ | 
|  | 45 | static int panic_happened(struct notifier_block *n, unsigned long val, void *v) | 
|  | 46 | { | 
|  | 47 | suspend_heartbeats = 1; | 
|  | 48 | return 0; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | static struct notifier_block panic_notifier = { panic_happened, NULL, 1 }; | 
|  | 52 |  | 
|  | 53 | void ibmasm_register_panic_notifier(void) | 
|  | 54 | { | 
| Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 55 | atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
|  | 58 | void ibmasm_unregister_panic_notifier(void) | 
|  | 59 | { | 
| Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 60 | atomic_notifier_chain_unregister(&panic_notifier_list, | 
|  | 61 | &panic_notifier); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
|  | 64 |  | 
|  | 65 | int ibmasm_heartbeat_init(struct service_processor *sp) | 
|  | 66 | { | 
| Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 67 | sp->heartbeat = ibmasm_new_command(sp, HEARTBEAT_BUFFER_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | if (sp->heartbeat == NULL) | 
|  | 69 | return -ENOMEM; | 
|  | 70 |  | 
|  | 71 | return 0; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | void ibmasm_heartbeat_exit(struct service_processor *sp) | 
|  | 75 | { | 
| Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 76 | char tsbuf[32]; | 
|  | 77 |  | 
|  | 78 | dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf)); | 
|  | 79 | ibmasm_wait_for_response(sp->heartbeat, IBMASM_CMD_TIMEOUT_NORMAL); | 
|  | 80 | dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf)); | 
|  | 81 | suspend_heartbeats = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | command_put(sp->heartbeat); | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | void ibmasm_receive_heartbeat(struct service_processor *sp,  void *message, size_t size) | 
|  | 86 | { | 
|  | 87 | struct command *cmd = sp->heartbeat; | 
|  | 88 | struct dot_command_header *header = (struct dot_command_header *)cmd->buffer; | 
| Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 89 | char tsbuf[32]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
| Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 91 | dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (suspend_heartbeats) | 
|  | 93 | return; | 
|  | 94 |  | 
|  | 95 | /* return the received dot command to sender */ | 
|  | 96 | cmd->status = IBMASM_CMD_PENDING; | 
|  | 97 | size = min(size, cmd->buffer_size); | 
| Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 98 | memcpy_fromio(cmd->buffer, message, size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | header->type = sp_write; | 
|  | 100 | ibmasm_exec_command(sp, cmd); | 
|  | 101 | } |