grukservices.h 6.1 KB

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