drv_xgbe_intf.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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 drv_xgbe_intf.h
  16. * Interface to the hypervisor XGBE driver.
  17. */
  18. #ifndef __DRV_XGBE_INTF_H__
  19. #define __DRV_XGBE_INTF_H__
  20. /**
  21. * An object for forwarding VAs and PAs to the hypervisor.
  22. * @ingroup types
  23. *
  24. * This allows the supervisor to specify a number of areas of memory to
  25. * store packet buffers.
  26. */
  27. typedef struct
  28. {
  29. /** The physical address of the memory. */
  30. HV_PhysAddr pa;
  31. /** Page table entry for the memory. This is only used to derive the
  32. * memory's caching mode; the PA bits are ignored. */
  33. HV_PTE pte;
  34. /** The virtual address of the memory. */
  35. HV_VirtAddr va;
  36. /** Size (in bytes) of the memory area. */
  37. int size;
  38. }
  39. netio_ipp_address_t;
  40. /** The various pread/pwrite offsets into the hypervisor-level driver.
  41. * @ingroup types
  42. */
  43. typedef enum
  44. {
  45. /** Inform the Linux driver of the address of the NetIO arena memory.
  46. * This offset is actually only used to convey information from netio
  47. * to the Linux driver; it never makes it from there to the hypervisor.
  48. * Write-only; takes a uint32_t specifying the VA address. */
  49. NETIO_FIXED_ADDR = 0x5000000000000000ULL,
  50. /** Inform the Linux driver of the size of the NetIO arena memory.
  51. * This offset is actually only used to convey information from netio
  52. * to the Linux driver; it never makes it from there to the hypervisor.
  53. * Write-only; takes a uint32_t specifying the VA size. */
  54. NETIO_FIXED_SIZE = 0x5100000000000000ULL,
  55. /** Register current tile with IPP. Write then read: write, takes a
  56. * netio_input_config_t, read returns a pointer to a netio_queue_impl_t. */
  57. NETIO_IPP_INPUT_REGISTER_OFF = 0x6000000000000000ULL,
  58. /** Unregister current tile from IPP. Write-only, takes a dummy argument. */
  59. NETIO_IPP_INPUT_UNREGISTER_OFF = 0x6100000000000000ULL,
  60. /** Start packets flowing. Write-only, takes a dummy argument. */
  61. NETIO_IPP_INPUT_INIT_OFF = 0x6200000000000000ULL,
  62. /** Stop packets flowing. Write-only, takes a dummy argument. */
  63. NETIO_IPP_INPUT_UNINIT_OFF = 0x6300000000000000ULL,
  64. /** Configure group (typically we group on VLAN). Write-only: takes an
  65. * array of netio_group_t's, low 24 bits of the offset is the base group
  66. * number times the size of a netio_group_t. */
  67. NETIO_IPP_INPUT_GROUP_CFG_OFF = 0x6400000000000000ULL,
  68. /** Configure bucket. Write-only: takes an array of netio_bucket_t's, low
  69. * 24 bits of the offset is the base bucket number times the size of a
  70. * netio_bucket_t. */
  71. NETIO_IPP_INPUT_BUCKET_CFG_OFF = 0x6500000000000000ULL,
  72. /** Get/set a parameter. Read or write: read or write data is the parameter
  73. * value, low 32 bits of the offset is a __netio_getset_offset_t. */
  74. NETIO_IPP_PARAM_OFF = 0x6600000000000000ULL,
  75. /** Get fast I/O index. Read-only; returns a 4-byte base index value. */
  76. NETIO_IPP_GET_FASTIO_OFF = 0x6700000000000000ULL,
  77. /** Configure hijack IP address. Packets with this IPv4 dest address
  78. * go to bucket NETIO_NUM_BUCKETS - 1. Write-only: takes an IP address
  79. * in some standard form. FIXME: Define the form! */
  80. NETIO_IPP_INPUT_HIJACK_CFG_OFF = 0x6800000000000000ULL,
  81. /**
  82. * Offsets beyond this point are reserved for the supervisor (although that
  83. * enforcement must be done by the supervisor driver itself).
  84. */
  85. NETIO_IPP_USER_MAX_OFF = 0x6FFFFFFFFFFFFFFFULL,
  86. /** Register I/O memory. Write-only, takes a netio_ipp_address_t. */
  87. NETIO_IPP_IOMEM_REGISTER_OFF = 0x7000000000000000ULL,
  88. /** Unregister I/O memory. Write-only, takes a netio_ipp_address_t. */
  89. NETIO_IPP_IOMEM_UNREGISTER_OFF = 0x7100000000000000ULL,
  90. /* Offsets greater than 0x7FFFFFFF can't be used directly from Linux
  91. * userspace code due to limitations in the pread/pwrite syscalls. */
  92. /** Drain LIPP buffers. */
  93. NETIO_IPP_DRAIN_OFF = 0xFA00000000000000ULL,
  94. /** Supply a netio_ipp_address_t to be used as shared memory for the
  95. * LEPP command queue. */
  96. NETIO_EPP_SHM_OFF = 0xFB00000000000000ULL,
  97. /* 0xFC... is currently unused. */
  98. /** Stop IPP/EPP tiles. Write-only, takes a dummy argument. */
  99. NETIO_IPP_STOP_SHIM_OFF = 0xFD00000000000000ULL,
  100. /** Start IPP/EPP tiles. Write-only, takes a dummy argument. */
  101. NETIO_IPP_START_SHIM_OFF = 0xFE00000000000000ULL,
  102. /** Supply packet arena. Write-only, takes an array of
  103. * netio_ipp_address_t values. */
  104. NETIO_IPP_ADDRESS_OFF = 0xFF00000000000000ULL,
  105. } netio_hv_offset_t;
  106. /** Extract the base offset from an offset */
  107. #define NETIO_BASE_OFFSET(off) ((off) & 0xFF00000000000000ULL)
  108. /** Extract the local offset from an offset */
  109. #define NETIO_LOCAL_OFFSET(off) ((off) & 0x00FFFFFFFFFFFFFFULL)
  110. /**
  111. * Get/set offset.
  112. */
  113. typedef union
  114. {
  115. struct
  116. {
  117. uint64_t addr:48; /**< Class-specific address */
  118. unsigned int class:8; /**< Class (e.g., NETIO_PARAM) */
  119. unsigned int opcode:8; /**< High 8 bits of NETIO_IPP_PARAM_OFF */
  120. }
  121. bits; /**< Bitfields */
  122. uint64_t word; /**< Aggregated value to use as the offset */
  123. }
  124. __netio_getset_offset_t;
  125. /**
  126. * Fast I/O index offsets (must be contiguous).
  127. */
  128. typedef enum
  129. {
  130. NETIO_FASTIO_ALLOCATE = 0, /**< Get empty packet buffer */
  131. NETIO_FASTIO_FREE_BUFFER = 1, /**< Give buffer back to IPP */
  132. NETIO_FASTIO_RETURN_CREDITS = 2, /**< Give credits to IPP */
  133. NETIO_FASTIO_SEND_PKT_NOCK = 3, /**< Send a packet, no checksum */
  134. NETIO_FASTIO_SEND_PKT_CK = 4, /**< Send a packet, with checksum */
  135. NETIO_FASTIO_SEND_PKT_VEC = 5, /**< Send a vector of packets */
  136. NETIO_FASTIO_SENDV_PKT = 6, /**< Sendv one packet */
  137. NETIO_FASTIO_NUM_INDEX = 7, /**< Total number of fast I/O indices */
  138. } netio_fastio_index_t;
  139. /** 3-word return type for Fast I/O call. */
  140. typedef struct
  141. {
  142. int err; /**< Error code. */
  143. uint32_t val0; /**< Value. Meaning depends upon the specific call. */
  144. uint32_t val1; /**< Value. Meaning depends upon the specific call. */
  145. } netio_fastio_rv3_t;
  146. /** 0-argument fast I/O call */
  147. int __netio_fastio0(uint32_t fastio_index);
  148. /** 1-argument fast I/O call */
  149. int __netio_fastio1(uint32_t fastio_index, uint32_t arg0);
  150. /** 3-argument fast I/O call, 2-word return value */
  151. netio_fastio_rv3_t __netio_fastio3_rv3(uint32_t fastio_index, uint32_t arg0,
  152. uint32_t arg1, uint32_t arg2);
  153. /** 4-argument fast I/O call */
  154. int __netio_fastio4(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
  155. uint32_t arg2, uint32_t arg3);
  156. /** 6-argument fast I/O call */
  157. int __netio_fastio6(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
  158. uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5);
  159. /** 9-argument fast I/O call */
  160. int __netio_fastio9(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
  161. uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5,
  162. uint32_t arg6, uint32_t arg7, uint32_t arg8);
  163. /** Allocate an empty packet.
  164. * @param fastio_index Fast I/O index.
  165. * @param size Size of the packet to allocate.
  166. */
  167. #define __netio_fastio_allocate(fastio_index, size) \
  168. __netio_fastio1((fastio_index) + NETIO_FASTIO_ALLOCATE, size)
  169. /** Free a buffer.
  170. * @param fastio_index Fast I/O index.
  171. * @param handle Handle for the packet to free.
  172. */
  173. #define __netio_fastio_free_buffer(fastio_index, handle) \
  174. __netio_fastio1((fastio_index) + NETIO_FASTIO_FREE_BUFFER, handle)
  175. /** Increment our receive credits.
  176. * @param fastio_index Fast I/O index.
  177. * @param credits Number of credits to add.
  178. */
  179. #define __netio_fastio_return_credits(fastio_index, credits) \
  180. __netio_fastio1((fastio_index) + NETIO_FASTIO_RETURN_CREDITS, credits)
  181. /** Send packet, no checksum.
  182. * @param fastio_index Fast I/O index.
  183. * @param ackflag Nonzero if we want an ack.
  184. * @param size Size of the packet.
  185. * @param va Virtual address of start of packet.
  186. * @param handle Packet handle.
  187. */
  188. #define __netio_fastio_send_pkt_nock(fastio_index, ackflag, size, va, handle) \
  189. __netio_fastio4((fastio_index) + NETIO_FASTIO_SEND_PKT_NOCK, ackflag, \
  190. size, va, handle)
  191. /** Send packet, calculate checksum.
  192. * @param fastio_index Fast I/O index.
  193. * @param ackflag Nonzero if we want an ack.
  194. * @param size Size of the packet.
  195. * @param va Virtual address of start of packet.
  196. * @param handle Packet handle.
  197. * @param csum0 Shim checksum header.
  198. * @param csum1 Checksum seed.
  199. */
  200. #define __netio_fastio_send_pkt_ck(fastio_index, ackflag, size, va, handle, \
  201. csum0, csum1) \
  202. __netio_fastio6((fastio_index) + NETIO_FASTIO_SEND_PKT_CK, ackflag, \
  203. size, va, handle, csum0, csum1)
  204. /** Format for the "csum0" argument to the __netio_fastio_send routines
  205. * and LEPP. Note that this is currently exactly identical to the
  206. * ShimProtocolOffloadHeader.
  207. */
  208. typedef union
  209. {
  210. struct
  211. {
  212. unsigned int start_byte:7; /**< The first byte to be checksummed */
  213. unsigned int count:14; /**< Number of bytes to be checksummed. */
  214. unsigned int destination_byte:7; /**< The byte to write the checksum to. */
  215. unsigned int reserved:4; /**< Reserved. */
  216. } bits; /**< Decomposed method of access. */
  217. unsigned int word; /**< To send out the IDN. */
  218. } __netio_checksum_header_t;
  219. /** Sendv packet with 1 or 2 segments.
  220. * @param fastio_index Fast I/O index.
  221. * @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
  222. * 1 in next 2 bits; expected checksum in high 16 bits.
  223. * @param confno Confirmation number to request, if notify flag set.
  224. * @param csum0 Checksum descriptor; if zero, no checksum.
  225. * @param va_F Virtual address of first segment.
  226. * @param va_L Virtual address of last segment, if 2 segments.
  227. * @param len_F_L Length of first segment in low 16 bits; length of last
  228. * segment, if 2 segments, in high 16 bits.
  229. */
  230. #define __netio_fastio_sendv_pkt_1_2(fastio_index, flags, confno, csum0, \
  231. va_F, va_L, len_F_L) \
  232. __netio_fastio6((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
  233. csum0, va_F, va_L, len_F_L)
  234. /** Send packet on PCIe interface.
  235. * @param fastio_index Fast I/O index.
  236. * @param flags Ack/csum/notify flags in low 3 bits.
  237. * @param confno Confirmation number to request, if notify flag set.
  238. * @param csum0 Checksum descriptor; Hard wired 0, not needed for PCIe.
  239. * @param va_F Virtual address of the packet buffer.
  240. * @param va_L Virtual address of last segment, if 2 segments. Hard wired 0.
  241. * @param len_F_L Length of the packet buffer in low 16 bits.
  242. */
  243. #define __netio_fastio_send_pcie_pkt(fastio_index, flags, confno, csum0, \
  244. va_F, va_L, len_F_L) \
  245. __netio_fastio6((fastio_index) + PCIE_FASTIO_SENDV_PKT, flags, confno, \
  246. csum0, va_F, va_L, len_F_L)
  247. /** Sendv packet with 3 or 4 segments.
  248. * @param fastio_index Fast I/O index.
  249. * @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
  250. * 1 in next 2 bits; expected checksum in high 16 bits.
  251. * @param confno Confirmation number to request, if notify flag set.
  252. * @param csum0 Checksum descriptor; if zero, no checksum.
  253. * @param va_F Virtual address of first segment.
  254. * @param va_L Virtual address of last segment (third segment if 3 segments,
  255. * fourth segment if 4 segments).
  256. * @param len_F_L Length of first segment in low 16 bits; length of last
  257. * segment in high 16 bits.
  258. * @param va_M0 Virtual address of "middle 0" segment; this segment is sent
  259. * second when there are three segments, and third if there are four.
  260. * @param va_M1 Virtual address of "middle 1" segment; this segment is sent
  261. * second when there are four segments.
  262. * @param len_M0_M1 Length of middle 0 segment in low 16 bits; length of middle
  263. * 1 segment, if 4 segments, in high 16 bits.
  264. */
  265. #define __netio_fastio_sendv_pkt_3_4(fastio_index, flags, confno, csum0, va_F, \
  266. va_L, len_F_L, va_M0, va_M1, len_M0_M1) \
  267. __netio_fastio9((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
  268. csum0, va_F, va_L, len_F_L, va_M0, va_M1, len_M0_M1)
  269. /** Send vector of packets.
  270. * @param fastio_index Fast I/O index.
  271. * @param seqno Number of packets transmitted so far on this interface;
  272. * used to decide which packets should be acknowledged.
  273. * @param nentries Number of entries in vector.
  274. * @param va Virtual address of start of vector entry array.
  275. * @return 3-word netio_fastio_rv3_t structure. The structure's err member
  276. * is an error code, or zero if no error. The val0 member is the
  277. * updated value of seqno; it has been incremented by 1 for each
  278. * packet sent. That increment may be less than nentries if an
  279. * error occurred, or if some of the entries in the vector contain
  280. * handles equal to NETIO_PKT_HANDLE_NONE. The val1 member is the
  281. * updated value of nentries; it has been decremented by 1 for each
  282. * vector entry processed. Again, that decrement may be less than
  283. * nentries (leaving the returned value positive) if an error
  284. * occurred.
  285. */
  286. #define __netio_fastio_send_pkt_vec(fastio_index, seqno, nentries, va) \
  287. __netio_fastio3_rv3((fastio_index) + NETIO_FASTIO_SEND_PKT_VEC, seqno, \
  288. nentries, va)
  289. /** An egress DMA command for LEPP. */
  290. typedef struct
  291. {
  292. /** Is this a TSO transfer?
  293. *
  294. * NOTE: This field is always 0, to distinguish it from
  295. * lepp_tso_cmd_t. It must come first!
  296. */
  297. uint8_t tso : 1;
  298. /** Unused padding bits. */
  299. uint8_t _unused : 3;
  300. /** Should this packet be sent directly from caches instead of DRAM,
  301. * using hash-for-home to locate the packet data?
  302. */
  303. uint8_t hash_for_home : 1;
  304. /** Should we compute a checksum? */
  305. uint8_t compute_checksum : 1;
  306. /** Is this the final buffer for this packet?
  307. *
  308. * A single packet can be split over several input buffers (a "gather"
  309. * operation). This flag indicates that this is the last buffer
  310. * in a packet.
  311. */
  312. uint8_t end_of_packet : 1;
  313. /** Should LEPP advance 'comp_busy' when this DMA is fully finished? */
  314. uint8_t send_completion : 1;
  315. /** High bits of Client Physical Address of the start of the buffer
  316. * to be egressed.
  317. *
  318. * NOTE: Only 6 bits are actually needed here, as CPAs are
  319. * currently 38 bits. So two bits could be scavenged from this.
  320. */
  321. uint8_t cpa_hi;
  322. /** The number of bytes to be egressed. */
  323. uint16_t length;
  324. /** Low 32 bits of Client Physical Address of the start of the buffer
  325. * to be egressed.
  326. */
  327. uint32_t cpa_lo;
  328. /** Checksum information (only used if 'compute_checksum'). */
  329. __netio_checksum_header_t checksum_data;
  330. } lepp_cmd_t;
  331. /** A chunk of physical memory for a TSO egress. */
  332. typedef struct
  333. {
  334. /** The low bits of the CPA. */
  335. uint32_t cpa_lo;
  336. /** The high bits of the CPA. */
  337. uint16_t cpa_hi : 15;
  338. /** Should this packet be sent directly from caches instead of DRAM,
  339. * using hash-for-home to locate the packet data?
  340. */
  341. uint16_t hash_for_home : 1;
  342. /** The length in bytes. */
  343. uint16_t length;
  344. } lepp_frag_t;
  345. /** An LEPP command that handles TSO. */
  346. typedef struct
  347. {
  348. /** Is this a TSO transfer?
  349. *
  350. * NOTE: This field is always 1, to distinguish it from
  351. * lepp_cmd_t. It must come first!
  352. */
  353. uint8_t tso : 1;
  354. /** Unused padding bits. */
  355. uint8_t _unused : 7;
  356. /** Size of the header[] array in bytes. It must be in the range
  357. * [40, 127], which are the smallest header for a TCP packet over
  358. * Ethernet and the maximum possible prepend size supported by
  359. * hardware, respectively. Note that the array storage must be
  360. * padded out to a multiple of four bytes so that the following
  361. * LEPP command is aligned properly.
  362. */
  363. uint8_t header_size;
  364. /** Byte offset of the IP header in header[]. */
  365. uint8_t ip_offset;
  366. /** Byte offset of the TCP header in header[]. */
  367. uint8_t tcp_offset;
  368. /** The number of bytes to use for the payload of each packet,
  369. * except of course the last one, which may not have enough bytes.
  370. * This means that each Ethernet packet except the last will have a
  371. * size of header_size + payload_size.
  372. */
  373. uint16_t payload_size;
  374. /** The length of the 'frags' array that follows this struct. */
  375. uint16_t num_frags;
  376. /** The actual frags. */
  377. lepp_frag_t frags[0 /* Variable-sized; num_frags entries. */];
  378. /*
  379. * The packet header template logically follows frags[],
  380. * but you can't declare that in C.
  381. *
  382. * uint32_t header[header_size_in_words_rounded_up];
  383. */
  384. } lepp_tso_cmd_t;
  385. /** An LEPP completion ring entry. */
  386. typedef void* lepp_comp_t;
  387. /** Maximum number of frags for one TSO command. This is adapted from
  388. * linux's "MAX_SKB_FRAGS", and presumably over-estimates by one, for
  389. * our page size of exactly 65536. We add one for a "body" fragment.
  390. */
  391. #define LEPP_MAX_FRAGS (65536 / HV_DEFAULT_PAGE_SIZE_SMALL + 2 + 1)
  392. /** Total number of bytes needed for an lepp_tso_cmd_t. */
  393. #define LEPP_TSO_CMD_SIZE(num_frags, header_size) \
  394. (sizeof(lepp_tso_cmd_t) + \
  395. (num_frags) * sizeof(lepp_frag_t) + \
  396. (((header_size) + 3) & -4))
  397. /** The size of the lepp "cmd" queue. */
  398. #define LEPP_CMD_QUEUE_BYTES \
  399. (((CHIP_L2_CACHE_SIZE() - 2 * CHIP_L2_LINE_SIZE()) / \
  400. (sizeof(lepp_cmd_t) + sizeof(lepp_comp_t))) * sizeof(lepp_cmd_t))
  401. /** The largest possible command that can go in lepp_queue_t::cmds[]. */
  402. #define LEPP_MAX_CMD_SIZE LEPP_TSO_CMD_SIZE(LEPP_MAX_FRAGS, 128)
  403. /** The largest possible value of lepp_queue_t::cmd_{head, tail} (inclusive).
  404. */
  405. #define LEPP_CMD_LIMIT \
  406. (LEPP_CMD_QUEUE_BYTES - LEPP_MAX_CMD_SIZE)
  407. /** The maximum number of completions in an LEPP queue. */
  408. #define LEPP_COMP_QUEUE_SIZE \
  409. ((LEPP_CMD_LIMIT + sizeof(lepp_cmd_t) - 1) / sizeof(lepp_cmd_t))
  410. /** Increment an index modulo the queue size. */
  411. #define LEPP_QINC(var) \
  412. (var = __insn_mnz(var - (LEPP_COMP_QUEUE_SIZE - 1), var + 1))
  413. /** A queue used to convey egress commands from the client to LEPP. */
  414. typedef struct
  415. {
  416. /** Index of first completion not yet processed by user code.
  417. * If this is equal to comp_busy, there are no such completions.
  418. *
  419. * NOTE: This is only read/written by the user.
  420. */
  421. unsigned int comp_head;
  422. /** Index of first completion record not yet completed.
  423. * If this is equal to comp_tail, there are no such completions.
  424. * This index gets advanced (modulo LEPP_QUEUE_SIZE) whenever
  425. * a command with the 'completion' bit set is finished.
  426. *
  427. * NOTE: This is only written by LEPP, only read by the user.
  428. */
  429. volatile unsigned int comp_busy;
  430. /** Index of the first empty slot in the completion ring.
  431. * Entries from this up to but not including comp_head (in ring order)
  432. * can be filled in with completion data.
  433. *
  434. * NOTE: This is only read/written by the user.
  435. */
  436. unsigned int comp_tail;
  437. /** Byte index of first command enqueued for LEPP but not yet processed.
  438. *
  439. * This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
  440. *
  441. * NOTE: LEPP advances this counter as soon as it no longer needs
  442. * the cmds[] storage for this entry, but the transfer is not actually
  443. * complete (i.e. the buffer pointed to by the command is no longer
  444. * needed) until comp_busy advances.
  445. *
  446. * If this is equal to cmd_tail, the ring is empty.
  447. *
  448. * NOTE: This is only written by LEPP, only read by the user.
  449. */
  450. volatile unsigned int cmd_head;
  451. /** Byte index of first empty slot in the command ring. This field can
  452. * be incremented up to but not equal to cmd_head (because that would
  453. * mean the ring is empty).
  454. *
  455. * This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
  456. *
  457. * NOTE: This is read/written by the user, only read by LEPP.
  458. */
  459. volatile unsigned int cmd_tail;
  460. /** A ring of variable-sized egress DMA commands.
  461. *
  462. * NOTE: Only written by the user, only read by LEPP.
  463. */
  464. char cmds[LEPP_CMD_QUEUE_BYTES]
  465. __attribute__((aligned(CHIP_L2_LINE_SIZE())));
  466. /** A ring of user completion data.
  467. * NOTE: Only read/written by the user.
  468. */
  469. lepp_comp_t comps[LEPP_COMP_QUEUE_SIZE]
  470. __attribute__((aligned(CHIP_L2_LINE_SIZE())));
  471. } lepp_queue_t;
  472. /** An internal helper function for determining the number of entries
  473. * available in a ring buffer, given that there is one sentinel.
  474. */
  475. static inline unsigned int
  476. _lepp_num_free_slots(unsigned int head, unsigned int tail)
  477. {
  478. /*
  479. * One entry is reserved for use as a sentinel, to distinguish
  480. * "empty" from "full". So we compute
  481. * (head - tail - 1) % LEPP_QUEUE_SIZE, but without using a slow % operation.
  482. */
  483. return (head - tail - 1) + ((head <= tail) ? LEPP_COMP_QUEUE_SIZE : 0);
  484. }
  485. /** Returns how many new comp entries can be enqueued. */
  486. static inline unsigned int
  487. lepp_num_free_comp_slots(const lepp_queue_t* q)
  488. {
  489. return _lepp_num_free_slots(q->comp_head, q->comp_tail);
  490. }
  491. static inline int
  492. lepp_qsub(int v1, int v2)
  493. {
  494. int delta = v1 - v2;
  495. return delta + ((delta >> 31) & LEPP_COMP_QUEUE_SIZE);
  496. }
  497. /** FIXME: Check this from linux, via a new "pwrite()" call. */
  498. #define LIPP_VERSION 1
  499. /** We use exactly two bytes of alignment padding. */
  500. #define LIPP_PACKET_PADDING 2
  501. /** The minimum size of a "small" buffer (including the padding). */
  502. #define LIPP_SMALL_PACKET_SIZE 128
  503. /*
  504. * NOTE: The following two values should total to less than around
  505. * 13582, to keep the total size used for "lipp_state_t" below 64K.
  506. */
  507. /** The maximum number of "small" buffers.
  508. * This is enough for 53 network cpus with 128 credits. Note that
  509. * if these are exhausted, we will fall back to using large buffers.
  510. */
  511. #define LIPP_SMALL_BUFFERS 6785
  512. /** The maximum number of "large" buffers.
  513. * This is enough for 53 network cpus with 128 credits.
  514. */
  515. #define LIPP_LARGE_BUFFERS 6785
  516. #endif /* __DRV_XGBE_INTF_H__ */