grukservices.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
  4. */
  5. #ifndef __GRU_KSERVICES_H_
  6. #define __GRU_KSERVICES_H_
  7. /*
  8. * Message queues using the GRU to send/receive messages.
  9. *
  10. * These function allow the user to create a message queue for
  11. * sending/receiving 1 or 2 cacheline messages using the GRU.
  12. *
  13. * Processes SENDING messages will use a kernel CBR/DSR to send
  14. * the message. This is transparent to the caller.
  15. *
  16. * The receiver does not use any GRU resources.
  17. *
  18. * The functions support:
  19. * - single receiver
  20. * - multiple senders
  21. * - cross partition message
  22. *
  23. * Missing features ZZZ:
  24. * - user options for dealing with timeouts, queue full, etc.
  25. * - gru_create_message_queue() needs interrupt vector info
  26. */
  27. struct gru_message_queue_desc {
  28. void *mq; /* message queue vaddress */
  29. unsigned long mq_gpa; /* global address of mq */
  30. int qlines; /* queue size in CL */
  31. int interrupt_vector; /* interrupt vector */
  32. int interrupt_pnode; /* pnode for interrupt */
  33. int interrupt_apicid; /* lapicid for interrupt */
  34. };
  35. /*
  36. * Initialize a user allocated chunk of memory to be used as
  37. * a message queue. The caller must ensure that the queue is
  38. * in contiguous physical memory and is cacheline aligned.
  39. *
  40. * Message queue size is the total number of bytes allocated
  41. * to the queue including a 2 cacheline header that is used
  42. * to manage the queue.
  43. *
  44. * Input:
  45. * mqd pointer to message queue descriptor
  46. * p pointer to user allocated mesq memory.
  47. * bytes size of message queue in bytes
  48. * vector interrupt vector (zero if no interrupts)
  49. * nasid nasid of blade where interrupt is delivered
  50. * apicid apicid of cpu for interrupt
  51. *
  52. * Errors:
  53. * 0 OK
  54. * >0 error
  55. */
  56. extern int gru_create_message_queue(struct gru_message_queue_desc *mqd,
  57. void *p, unsigned int bytes, int nasid, int vector, int apicid);
  58. /*
  59. * Send a message to a message queue.
  60. *
  61. * Note: The message queue transport mechanism uses the first 32
  62. * bits of the message. Users should avoid using these bits.
  63. *
  64. *
  65. * Input:
  66. * mqd pointer to message queue descriptor
  67. * mesg pointer to message. Must be 64-bit aligned
  68. * bytes size of message in bytes
  69. *
  70. * Output:
  71. * 0 message sent
  72. * >0 Send failure - see error codes below
  73. *
  74. */
  75. extern int gru_send_message_gpa(struct gru_message_queue_desc *mqd,
  76. void *mesg, unsigned int bytes);
  77. /* Status values for gru_send_message() */
  78. #define MQE_OK 0 /* message sent successfully */
  79. #define MQE_CONGESTION 1 /* temporary congestion, try again */
  80. #define MQE_QUEUE_FULL 2 /* queue is full */
  81. #define MQE_UNEXPECTED_CB_ERR 3 /* unexpected CB error */
  82. #define MQE_PAGE_OVERFLOW 10 /* BUG - queue overflowed a page */
  83. #define MQE_BUG_NO_RESOURCES 11 /* BUG - could not alloc GRU cb/dsr */
  84. /*
  85. * Advance the receive pointer for the message queue to the next message.
  86. * Note: current API requires messages to be gotten & freed in order. Future
  87. * API extensions may allow for out-of-order freeing.
  88. *
  89. * Input
  90. * mqd pointer to message queue descriptor
  91. * mesq message being freed
  92. */
  93. extern void gru_free_message(struct gru_message_queue_desc *mqd,
  94. void *mesq);
  95. /*
  96. * Get next message from message queue. Returns pointer to
  97. * message OR NULL if no message present.
  98. * User must call gru_free_message() after message is processed
  99. * in order to move the queue pointers to next message.
  100. *
  101. * Input
  102. * mqd pointer to message queue descriptor
  103. *
  104. * Output:
  105. * p pointer to message
  106. * NULL no message available
  107. */
  108. extern void *gru_get_next_message(struct gru_message_queue_desc *mqd);
  109. /*
  110. * Read a GRU global GPA. Source can be located in a remote partition.
  111. *
  112. * Input:
  113. * value memory address where MMR value is returned
  114. * gpa source numalink physical address of GPA
  115. *
  116. * Output:
  117. * 0 OK
  118. * >0 error
  119. */
  120. int gru_read_gpa(unsigned long *value, unsigned long gpa);
  121. /*
  122. * Copy data using the GRU. Source or destination can be located in a remote
  123. * partition.
  124. *
  125. * Input:
  126. * dest_gpa destination global physical address
  127. * src_gpa source global physical address
  128. * bytes number of bytes to copy
  129. *
  130. * Output:
  131. * 0 OK
  132. * >0 error
  133. */
  134. extern int gru_copy_gpa(unsigned long dest_gpa, unsigned long src_gpa,
  135. unsigned int bytes);
  136. /*
  137. * Reserve GRU resources to be used asynchronously.
  138. *
  139. * input:
  140. * blade_id - blade on which resources should be reserved
  141. * cbrs - number of CBRs
  142. * dsr_bytes - number of DSR bytes needed
  143. * cmp - completion structure for waiting for
  144. * async completions
  145. * output:
  146. * handle to identify resource
  147. * (0 = no resources)
  148. */
  149. extern unsigned long gru_reserve_async_resources(int blade_id, int cbrs, int dsr_bytes,
  150. struct completion *cmp);
  151. /*
  152. * Release async resources previously reserved.
  153. *
  154. * input:
  155. * han - handle to identify resources
  156. */
  157. extern void gru_release_async_resources(unsigned long han);
  158. /*
  159. * Wait for async GRU instructions to complete.
  160. *
  161. * input:
  162. * han - handle to identify resources
  163. */
  164. extern void gru_wait_async_cbr(unsigned long han);
  165. /*
  166. * Lock previous reserved async GRU resources
  167. *
  168. * input:
  169. * han - handle to identify resources
  170. * output:
  171. * cb - pointer to first CBR
  172. * dsr - pointer to first DSR
  173. */
  174. extern void gru_lock_async_resource(unsigned long han, void **cb, void **dsr);
  175. /*
  176. * Unlock previous reserved async GRU resources
  177. *
  178. * input:
  179. * han - handle to identify resources
  180. */
  181. extern void gru_unlock_async_resource(unsigned long han);
  182. #endif /* __GRU_KSERVICES_H_ */