drv_xgbe_impl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. /**
  15. * @file drivers/xgbe/impl.h
  16. * Implementation details for the NetIO library.
  17. */
  18. #ifndef __DRV_XGBE_IMPL_H__
  19. #define __DRV_XGBE_IMPL_H__
  20. #include <hv/netio_errors.h>
  21. #include <hv/netio_intf.h>
  22. #include <hv/drv_xgbe_intf.h>
  23. /** How many groups we have (log2). */
  24. #define LOG2_NUM_GROUPS (12)
  25. /** How many groups we have. */
  26. #define NUM_GROUPS (1 << LOG2_NUM_GROUPS)
  27. /** Number of output requests we'll buffer per tile. */
  28. #define EPP_REQS_PER_TILE (32)
  29. /** Words used in an eDMA command without checksum acceleration. */
  30. #define EDMA_WDS_NO_CSUM 8
  31. /** Words used in an eDMA command with checksum acceleration. */
  32. #define EDMA_WDS_CSUM 10
  33. /** Total available words in the eDMA command FIFO. */
  34. #define EDMA_WDS_TOTAL 128
  35. /*
  36. * FIXME: These definitions are internal and should have underscores!
  37. * NOTE: The actual numeric values here are intentional and allow us to
  38. * optimize the concept "if small ... else if large ... else ...", by
  39. * checking for the low bit being set, and then for non-zero.
  40. * These are used as array indices, so they must have the values (0, 1, 2)
  41. * in some order.
  42. */
  43. #define SIZE_SMALL (1) /**< Small packet queue. */
  44. #define SIZE_LARGE (2) /**< Large packet queue. */
  45. #define SIZE_JUMBO (0) /**< Jumbo packet queue. */
  46. /** The number of "SIZE_xxx" values. */
  47. #define NETIO_NUM_SIZES 3
  48. /*
  49. * Default numbers of packets for IPP drivers. These values are chosen
  50. * such that CIPP1 will not overflow its L2 cache.
  51. */
  52. /** The default number of small packets. */
  53. #define NETIO_DEFAULT_SMALL_PACKETS 2750
  54. /** The default number of large packets. */
  55. #define NETIO_DEFAULT_LARGE_PACKETS 2500
  56. /** The default number of jumbo packets. */
  57. #define NETIO_DEFAULT_JUMBO_PACKETS 250
  58. /** Log2 of the size of a memory arena. */
  59. #define NETIO_ARENA_SHIFT 24 /* 16 MB */
  60. /** Size of a memory arena. */
  61. #define NETIO_ARENA_SIZE (1 << NETIO_ARENA_SHIFT)
  62. /** A queue of packets.
  63. *
  64. * This structure partially defines a queue of packets waiting to be
  65. * processed. The queue as a whole is written to by an interrupt handler and
  66. * read by non-interrupt code; this data structure is what's touched by the
  67. * interrupt handler. The other part of the queue state, the read offset, is
  68. * kept in user space, not in hypervisor space, so it is in a separate data
  69. * structure.
  70. *
  71. * The read offset (__packet_receive_read in the user part of the queue
  72. * structure) points to the next packet to be read. When the read offset is
  73. * equal to the write offset, the queue is empty; therefore the queue must
  74. * contain one more slot than the required maximum queue size.
  75. *
  76. * Here's an example of all 3 state variables and what they mean. All
  77. * pointers move left to right.
  78. *
  79. * @code
  80. * I I V V V V I I I I
  81. * 0 1 2 3 4 5 6 7 8 9 10
  82. * ^ ^ ^ ^
  83. * | | |
  84. * | | __last_packet_plus_one
  85. * | __buffer_write
  86. * __packet_receive_read
  87. * @endcode
  88. *
  89. * This queue has 10 slots, and thus can hold 9 packets (_last_packet_plus_one
  90. * = 10). The read pointer is at 2, and the write pointer is at 6; thus,
  91. * there are valid, unread packets in slots 2, 3, 4, and 5. The remaining
  92. * slots are invalid (do not contain a packet).
  93. */
  94. typedef struct {
  95. /** Byte offset of the next notify packet to be written: zero for the first
  96. * packet on the queue, sizeof (netio_pkt_t) for the second packet on the
  97. * queue, etc. */
  98. volatile uint32_t __packet_write;
  99. /** Offset of the packet after the last valid packet (i.e., when any
  100. * pointer is incremented to this value, it wraps back to zero). */
  101. uint32_t __last_packet_plus_one;
  102. }
  103. __netio_packet_queue_t;
  104. /** A queue of buffers.
  105. *
  106. * This structure partially defines a queue of empty buffers which have been
  107. * obtained via requests to the IPP. (The elements of the queue are packet
  108. * handles, which are transformed into a full netio_pkt_t when the buffer is
  109. * retrieved.) The queue as a whole is written to by an interrupt handler and
  110. * read by non-interrupt code; this data structure is what's touched by the
  111. * interrupt handler. The other parts of the queue state, the read offset and
  112. * requested write offset, are kept in user space, not in hypervisor space, so
  113. * they are in a separate data structure.
  114. *
  115. * The read offset (__buffer_read in the user part of the queue structure)
  116. * points to the next buffer to be read. When the read offset is equal to the
  117. * write offset, the queue is empty; therefore the queue must contain one more
  118. * slot than the required maximum queue size.
  119. *
  120. * The requested write offset (__buffer_requested_write in the user part of
  121. * the queue structure) points to the slot which will hold the next buffer we
  122. * request from the IPP, once we get around to sending such a request. When
  123. * the requested write offset is equal to the write offset, no requests for
  124. * new buffers are outstanding; when the requested write offset is one greater
  125. * than the read offset, no more requests may be sent.
  126. *
  127. * Note that, unlike the packet_queue, the buffer_queue places incoming
  128. * buffers at decreasing addresses. This makes the check for "is it time to
  129. * wrap the buffer pointer" cheaper in the assembly code which receives new
  130. * buffers, and means that the value which defines the queue size,
  131. * __last_buffer, is different than in the packet queue. Also, the offset
  132. * used in the packet_queue is already scaled by the size of a packet; here we
  133. * use unscaled slot indices for the offsets. (These differences are
  134. * historical, and in the future it's possible that the packet_queue will look
  135. * more like this queue.)
  136. *
  137. * @code
  138. * Here's an example of all 4 state variables and what they mean. Remember:
  139. * all pointers move right to left.
  140. *
  141. * V V V I I R R V V V
  142. * 0 1 2 3 4 5 6 7 8 9
  143. * ^ ^ ^ ^
  144. * | | | |
  145. * | | | __last_buffer
  146. * | | __buffer_write
  147. * | __buffer_requested_write
  148. * __buffer_read
  149. * @endcode
  150. *
  151. * This queue has 10 slots, and thus can hold 9 buffers (_last_buffer = 9).
  152. * The read pointer is at 2, and the write pointer is at 6; thus, there are
  153. * valid, unread buffers in slots 2, 1, 0, 9, 8, and 7. The requested write
  154. * pointer is at 4; thus, requests have been made to the IPP for buffers which
  155. * will be placed in slots 6 and 5 when they arrive. Finally, the remaining
  156. * slots are invalid (do not contain a buffer).
  157. */
  158. typedef struct
  159. {
  160. /** Ordinal number of the next buffer to be written: 0 for the first slot in
  161. * the queue, 1 for the second slot in the queue, etc. */
  162. volatile uint32_t __buffer_write;
  163. /** Ordinal number of the last buffer (i.e., when any pointer is decremented
  164. * below zero, it is reloaded with this value). */
  165. uint32_t __last_buffer;
  166. }
  167. __netio_buffer_queue_t;
  168. /**
  169. * An object for providing Ethernet packets to a process.
  170. */
  171. typedef struct __netio_queue_impl_t
  172. {
  173. /** The queue of packets waiting to be received. */
  174. __netio_packet_queue_t __packet_receive_queue;
  175. /** The intr bit mask that IDs this device. */
  176. unsigned int __intr_id;
  177. /** Offset to queues of empty buffers, one per size. */
  178. uint32_t __buffer_queue[NETIO_NUM_SIZES];
  179. /** The address of the first EPP tile, or -1 if no EPP. */
  180. /* ISSUE: Actually this is always "0" or "~0". */
  181. uint32_t __epp_location;
  182. /** The queue ID that this queue represents. */
  183. unsigned int __queue_id;
  184. /** Number of acknowledgements received. */
  185. volatile uint32_t __acks_received;
  186. /** Last completion number received for packet_sendv. */
  187. volatile uint32_t __last_completion_rcv;
  188. /** Number of packets allowed to be outstanding. */
  189. uint32_t __max_outstanding;
  190. /** First VA available for packets. */
  191. void* __va_0;
  192. /** First VA in second range available for packets. */
  193. void* __va_1;
  194. /** Padding to align the "__packets" field to the size of a netio_pkt_t. */
  195. uint32_t __padding[3];
  196. /** The packets themselves. */
  197. netio_pkt_t __packets[0];
  198. }
  199. netio_queue_impl_t;
  200. /**
  201. * An object for managing the user end of a NetIO queue.
  202. */
  203. typedef struct __netio_queue_user_impl_t
  204. {
  205. /** The next incoming packet to be read. */
  206. uint32_t __packet_receive_read;
  207. /** The next empty buffers to be read, one index per size. */
  208. uint8_t __buffer_read[NETIO_NUM_SIZES];
  209. /** Where the empty buffer we next request from the IPP will go, one index
  210. * per size. */
  211. uint8_t __buffer_requested_write[NETIO_NUM_SIZES];
  212. /** PCIe interface flag. */
  213. uint8_t __pcie;
  214. /** Number of packets left to be received before we send a credit update. */
  215. uint32_t __receive_credit_remaining;
  216. /** Value placed in __receive_credit_remaining when it reaches zero. */
  217. uint32_t __receive_credit_interval;
  218. /** First fast I/O routine index. */
  219. uint32_t __fastio_index;
  220. /** Number of acknowledgements expected. */
  221. uint32_t __acks_outstanding;
  222. /** Last completion number requested. */
  223. uint32_t __last_completion_req;
  224. /** File descriptor for driver. */
  225. int __fd;
  226. }
  227. netio_queue_user_impl_t;
  228. #define NETIO_GROUP_CHUNK_SIZE 64 /**< Max # groups in one IPP request */
  229. #define NETIO_BUCKET_CHUNK_SIZE 64 /**< Max # buckets in one IPP request */
  230. /** Internal structure used to convey packet send information to the
  231. * hypervisor. FIXME: Actually, it's not used for that anymore, but
  232. * netio_packet_send() still uses it internally.
  233. */
  234. typedef struct
  235. {
  236. uint16_t flags; /**< Packet flags (__NETIO_SEND_FLG_xxx) */
  237. uint16_t transfer_size; /**< Size of packet */
  238. uint32_t va; /**< VA of start of packet */
  239. __netio_pkt_handle_t handle; /**< Packet handle */
  240. uint32_t csum0; /**< First checksum word */
  241. uint32_t csum1; /**< Second checksum word */
  242. }
  243. __netio_send_cmd_t;
  244. /** Flags used in two contexts:
  245. * - As the "flags" member in the __netio_send_cmd_t, above; used only
  246. * for netio_pkt_send_{prepare,commit}.
  247. * - As part of the flags passed to the various send packet fast I/O calls.
  248. */
  249. /** Need acknowledgement on this packet. Note that some code in the
  250. * normal send_pkt fast I/O handler assumes that this is equal to 1. */
  251. #define __NETIO_SEND_FLG_ACK 0x1
  252. /** Do checksum on this packet. (Only used with the __netio_send_cmd_t;
  253. * normal packet sends use a special fast I/O index to denote checksumming,
  254. * and multi-segment sends test the checksum descriptor.) */
  255. #define __NETIO_SEND_FLG_CSUM 0x2
  256. /** Get a completion on this packet. Only used with multi-segment sends. */
  257. #define __NETIO_SEND_FLG_COMPLETION 0x4
  258. /** Position of the number-of-extra-segments value in the flags word.
  259. Only used with multi-segment sends. */
  260. #define __NETIO_SEND_FLG_XSEG_SHIFT 3
  261. /** Width of the number-of-extra-segments value in the flags word. */
  262. #define __NETIO_SEND_FLG_XSEG_WIDTH 2
  263. #endif /* __DRV_XGBE_IMPL_H__ */