ibmasm.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * IBM ASM Service Processor Device Driver
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright (C) IBM Corporation, 2004
  19. *
  20. * Author: Max Asböck <amax@us.ibm.com>
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/types.h>
  25. #include <linux/errno.h>
  26. #include <linux/list.h>
  27. #include <linux/wait.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/slab.h>
  30. #include <linux/module.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/kref.h>
  33. #include <linux/device.h>
  34. #include <linux/input.h>
  35. /* Driver identification */
  36. #define DRIVER_NAME "ibmasm"
  37. #define DRIVER_VERSION "1.0"
  38. #define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
  39. #define DRIVER_DESC "IBM ASM Service Processor Driver"
  40. #define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
  41. #define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
  42. extern int ibmasm_debug;
  43. #define dbg(STR, ARGS...) \
  44. do { \
  45. if (ibmasm_debug) \
  46. printk(KERN_DEBUG STR , ##ARGS); \
  47. } while (0)
  48. static inline char *get_timestamp(char *buf)
  49. {
  50. struct timeval now;
  51. do_gettimeofday(&now);
  52. sprintf(buf, "%lu.%lu", now.tv_sec, now.tv_usec);
  53. return buf;
  54. }
  55. #define IBMASM_CMD_PENDING 0
  56. #define IBMASM_CMD_COMPLETE 1
  57. #define IBMASM_CMD_FAILED 2
  58. #define IBMASM_CMD_TIMEOUT_NORMAL 45
  59. #define IBMASM_CMD_TIMEOUT_EXTRA 240
  60. #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
  61. #define REVERSE_HEARTBEAT_TIMEOUT 120
  62. #define HEARTBEAT_BUFFER_SIZE 0x400
  63. #ifdef IA64
  64. #define IBMASM_DRIVER_VPD "Lin64 6.08 "
  65. #else
  66. #define IBMASM_DRIVER_VPD "Lin32 6.08 "
  67. #endif
  68. #define SYSTEM_STATE_OS_UP 5
  69. #define SYSTEM_STATE_OS_DOWN 4
  70. #define IBMASM_NAME_SIZE 16
  71. #define IBMASM_NUM_EVENTS 10
  72. #define IBMASM_EVENT_MAX_SIZE 2048u
  73. struct command {
  74. struct list_head queue_node;
  75. wait_queue_head_t wait;
  76. unsigned char *buffer;
  77. size_t buffer_size;
  78. int status;
  79. struct kref kref;
  80. spinlock_t *lock;
  81. };
  82. #define to_command(c) container_of(c, struct command, kref)
  83. void ibmasm_free_command(struct kref *kref);
  84. static inline void command_put(struct command *cmd)
  85. {
  86. unsigned long flags;
  87. spinlock_t *lock = cmd->lock;
  88. spin_lock_irqsave(lock, flags);
  89. kref_put(&cmd->kref, ibmasm_free_command);
  90. spin_unlock_irqrestore(lock, flags);
  91. }
  92. static inline void command_get(struct command *cmd)
  93. {
  94. kref_get(&cmd->kref);
  95. }
  96. struct ibmasm_event {
  97. unsigned int serial_number;
  98. unsigned int data_size;
  99. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  100. };
  101. struct event_buffer {
  102. struct ibmasm_event events[IBMASM_NUM_EVENTS];
  103. unsigned int next_serial_number;
  104. unsigned int next_index;
  105. struct list_head readers;
  106. };
  107. struct event_reader {
  108. int cancelled;
  109. unsigned int next_serial_number;
  110. wait_queue_head_t wait;
  111. struct list_head node;
  112. unsigned int data_size;
  113. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  114. };
  115. struct reverse_heartbeat {
  116. wait_queue_head_t wait;
  117. unsigned int stopped;
  118. };
  119. struct ibmasm_remote {
  120. struct input_dev *keybd_dev;
  121. struct input_dev *mouse_dev;
  122. };
  123. struct service_processor {
  124. struct list_head node;
  125. spinlock_t lock;
  126. void __iomem *base_address;
  127. unsigned int irq;
  128. struct command *current_command;
  129. struct command *heartbeat;
  130. struct list_head command_queue;
  131. struct event_buffer *event_buffer;
  132. char dirname[IBMASM_NAME_SIZE];
  133. char devname[IBMASM_NAME_SIZE];
  134. unsigned int number;
  135. struct ibmasm_remote remote;
  136. int serial_line;
  137. struct device *dev;
  138. };
  139. /* command processing */
  140. struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size);
  141. void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
  142. void ibmasm_wait_for_response(struct command *cmd, int timeout);
  143. void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size);
  144. /* event processing */
  145. int ibmasm_event_buffer_init(struct service_processor *sp);
  146. void ibmasm_event_buffer_exit(struct service_processor *sp);
  147. void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size);
  148. void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
  149. void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
  150. int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
  151. void ibmasm_cancel_next_event(struct event_reader *reader);
  152. /* heartbeat - from SP to OS */
  153. void ibmasm_register_panic_notifier(void);
  154. void ibmasm_unregister_panic_notifier(void);
  155. int ibmasm_heartbeat_init(struct service_processor *sp);
  156. void ibmasm_heartbeat_exit(struct service_processor *sp);
  157. void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size);
  158. /* reverse heartbeat - from OS to SP */
  159. void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  160. int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  161. void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
  162. /* dot commands */
  163. void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
  164. int ibmasm_send_driver_vpd(struct service_processor *sp);
  165. int ibmasm_send_os_state(struct service_processor *sp, int os_state);
  166. /* low level message processing */
  167. int ibmasm_send_i2o_message(struct service_processor *sp);
  168. irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id);
  169. /* remote console */
  170. void ibmasm_handle_mouse_interrupt(struct service_processor *sp);
  171. int ibmasm_init_remote_input_dev(struct service_processor *sp);
  172. void ibmasm_free_remote_input_dev(struct service_processor *sp);
  173. /* file system */
  174. int ibmasmfs_register(void);
  175. void ibmasmfs_unregister(void);
  176. void ibmasmfs_add_sp(struct service_processor *sp);
  177. /* uart */
  178. #ifdef CONFIG_SERIAL_8250
  179. void ibmasm_register_uart(struct service_processor *sp);
  180. void ibmasm_unregister_uart(struct service_processor *sp);
  181. #else
  182. #define ibmasm_register_uart(sp) do { } while(0)
  183. #define ibmasm_unregister_uart(sp) do { } while(0)
  184. #endif