ibmasm.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. #include <linux/time64.h>
  36. /* Driver identification */
  37. #define DRIVER_NAME "ibmasm"
  38. #define DRIVER_VERSION "1.0"
  39. #define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
  40. #define DRIVER_DESC "IBM ASM Service Processor Driver"
  41. #define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
  42. #define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
  43. extern int ibmasm_debug;
  44. #define dbg(STR, ARGS...) \
  45. do { \
  46. if (ibmasm_debug) \
  47. printk(KERN_DEBUG STR , ##ARGS); \
  48. } while (0)
  49. static inline char *get_timestamp(char *buf)
  50. {
  51. struct timespec64 now;
  52. ktime_get_real_ts64(&now);
  53. sprintf(buf, "%llu.%.08lu", (long long)now.tv_sec,
  54. now.tv_nsec / NSEC_PER_USEC);
  55. return buf;
  56. }
  57. #define IBMASM_CMD_PENDING 0
  58. #define IBMASM_CMD_COMPLETE 1
  59. #define IBMASM_CMD_FAILED 2
  60. #define IBMASM_CMD_TIMEOUT_NORMAL 45
  61. #define IBMASM_CMD_TIMEOUT_EXTRA 240
  62. #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
  63. #define REVERSE_HEARTBEAT_TIMEOUT 120
  64. #define HEARTBEAT_BUFFER_SIZE 0x400
  65. #ifdef IA64
  66. #define IBMASM_DRIVER_VPD "Lin64 6.08 "
  67. #else
  68. #define IBMASM_DRIVER_VPD "Lin32 6.08 "
  69. #endif
  70. #define SYSTEM_STATE_OS_UP 5
  71. #define SYSTEM_STATE_OS_DOWN 4
  72. #define IBMASM_NAME_SIZE 16
  73. #define IBMASM_NUM_EVENTS 10
  74. #define IBMASM_EVENT_MAX_SIZE 2048u
  75. struct command {
  76. struct list_head queue_node;
  77. wait_queue_head_t wait;
  78. unsigned char *buffer;
  79. size_t buffer_size;
  80. int status;
  81. struct kref kref;
  82. spinlock_t *lock;
  83. };
  84. #define to_command(c) container_of(c, struct command, kref)
  85. void ibmasm_free_command(struct kref *kref);
  86. static inline void command_put(struct command *cmd)
  87. {
  88. unsigned long flags;
  89. spinlock_t *lock = cmd->lock;
  90. spin_lock_irqsave(lock, flags);
  91. kref_put(&cmd->kref, ibmasm_free_command);
  92. spin_unlock_irqrestore(lock, flags);
  93. }
  94. static inline void command_get(struct command *cmd)
  95. {
  96. kref_get(&cmd->kref);
  97. }
  98. struct ibmasm_event {
  99. unsigned int serial_number;
  100. unsigned int data_size;
  101. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  102. };
  103. struct event_buffer {
  104. struct ibmasm_event events[IBMASM_NUM_EVENTS];
  105. unsigned int next_serial_number;
  106. unsigned int next_index;
  107. struct list_head readers;
  108. };
  109. struct event_reader {
  110. int cancelled;
  111. unsigned int next_serial_number;
  112. wait_queue_head_t wait;
  113. struct list_head node;
  114. unsigned int data_size;
  115. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  116. };
  117. struct reverse_heartbeat {
  118. wait_queue_head_t wait;
  119. unsigned int stopped;
  120. };
  121. struct ibmasm_remote {
  122. struct input_dev *keybd_dev;
  123. struct input_dev *mouse_dev;
  124. };
  125. struct service_processor {
  126. struct list_head node;
  127. spinlock_t lock;
  128. void __iomem *base_address;
  129. unsigned int irq;
  130. struct command *current_command;
  131. struct command *heartbeat;
  132. struct list_head command_queue;
  133. struct event_buffer *event_buffer;
  134. char dirname[IBMASM_NAME_SIZE];
  135. char devname[IBMASM_NAME_SIZE];
  136. unsigned int number;
  137. struct ibmasm_remote remote;
  138. int serial_line;
  139. struct device *dev;
  140. };
  141. /* command processing */
  142. struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size);
  143. void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
  144. void ibmasm_wait_for_response(struct command *cmd, int timeout);
  145. void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size);
  146. /* event processing */
  147. int ibmasm_event_buffer_init(struct service_processor *sp);
  148. void ibmasm_event_buffer_exit(struct service_processor *sp);
  149. void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size);
  150. void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
  151. void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
  152. int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
  153. void ibmasm_cancel_next_event(struct event_reader *reader);
  154. /* heartbeat - from SP to OS */
  155. void ibmasm_register_panic_notifier(void);
  156. void ibmasm_unregister_panic_notifier(void);
  157. int ibmasm_heartbeat_init(struct service_processor *sp);
  158. void ibmasm_heartbeat_exit(struct service_processor *sp);
  159. void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size);
  160. /* reverse heartbeat - from OS to SP */
  161. void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  162. int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  163. void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
  164. /* dot commands */
  165. void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
  166. int ibmasm_send_driver_vpd(struct service_processor *sp);
  167. int ibmasm_send_os_state(struct service_processor *sp, int os_state);
  168. /* low level message processing */
  169. int ibmasm_send_i2o_message(struct service_processor *sp);
  170. irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id);
  171. /* remote console */
  172. void ibmasm_handle_mouse_interrupt(struct service_processor *sp);
  173. int ibmasm_init_remote_input_dev(struct service_processor *sp);
  174. void ibmasm_free_remote_input_dev(struct service_processor *sp);
  175. /* file system */
  176. int ibmasmfs_register(void);
  177. void ibmasmfs_unregister(void);
  178. void ibmasmfs_add_sp(struct service_processor *sp);
  179. /* uart */
  180. #if IS_ENABLED(CONFIG_SERIAL_8250)
  181. void ibmasm_register_uart(struct service_processor *sp);
  182. void ibmasm_unregister_uart(struct service_processor *sp);
  183. #else
  184. #define ibmasm_register_uart(sp) do { } while(0)
  185. #define ibmasm_unregister_uart(sp) do { } while(0)
  186. #endif