ibmasm.h 5.9 KB

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