aq_ring.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * aQuantia Corporation Network Driver
  3. * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. */
  9. /* File aq_ring.h: Declaration of functions for Rx/Tx rings. */
  10. #ifndef AQ_RING_H
  11. #define AQ_RING_H
  12. #include "aq_common.h"
  13. struct page;
  14. /* TxC SOP DX EOP
  15. * +----------+----------+----------+-----------
  16. * 8bytes|len l3,l4 | pa | pa | pa
  17. * +----------+----------+----------+-----------
  18. * 4/8bytes|len pkt |len pkt | | skb
  19. * +----------+----------+----------+-----------
  20. * 4/8bytes|is_txc |len,flags |len |len,is_eop
  21. * +----------+----------+----------+-----------
  22. *
  23. * This aq_ring_buff_s doesn't have endianness dependency.
  24. * It is __packed for cache line optimizations.
  25. */
  26. struct __packed aq_ring_buff_s {
  27. union {
  28. /* RX */
  29. struct {
  30. u32 rss_hash;
  31. u16 next;
  32. u8 is_hash_l4;
  33. u8 rsvd1;
  34. struct page *page;
  35. };
  36. /* EOP */
  37. struct {
  38. dma_addr_t pa_eop;
  39. struct sk_buff *skb;
  40. };
  41. /* DX */
  42. struct {
  43. dma_addr_t pa;
  44. };
  45. /* SOP */
  46. struct {
  47. dma_addr_t pa_sop;
  48. u32 len_pkt_sop;
  49. };
  50. /* TxC */
  51. struct {
  52. u32 mss;
  53. u8 len_l2;
  54. u8 len_l3;
  55. u8 len_l4;
  56. u8 is_ipv6:1;
  57. u8 rsvd2:7;
  58. u32 len_pkt;
  59. };
  60. };
  61. union {
  62. struct {
  63. u32 len:16;
  64. u32 is_ip_cso:1;
  65. u32 is_udp_cso:1;
  66. u32 is_tcp_cso:1;
  67. u32 is_cso_err:1;
  68. u32 is_sop:1;
  69. u32 is_eop:1;
  70. u32 is_txc:1;
  71. u32 is_mapped:1;
  72. u32 is_cleaned:1;
  73. u32 is_error:1;
  74. u32 rsvd3:6;
  75. };
  76. u32 flags;
  77. };
  78. };
  79. struct aq_ring_stats_rx_s {
  80. u64 errors;
  81. u64 packets;
  82. u64 bytes;
  83. u64 lro_packets;
  84. u64 jumbo_packets;
  85. };
  86. struct aq_ring_stats_tx_s {
  87. u64 errors;
  88. u64 packets;
  89. u64 bytes;
  90. };
  91. union aq_ring_stats_s {
  92. struct aq_ring_stats_rx_s rx;
  93. struct aq_ring_stats_tx_s tx;
  94. };
  95. struct aq_ring_s {
  96. struct aq_obj_s header;
  97. struct aq_ring_buff_s *buff_ring;
  98. u8 *dx_ring; /* descriptors ring, dma shared mem */
  99. struct aq_nic_s *aq_nic;
  100. unsigned int idx; /* for HW layer registers operations */
  101. unsigned int hw_head;
  102. unsigned int sw_head;
  103. unsigned int sw_tail;
  104. unsigned int size; /* descriptors number */
  105. unsigned int dx_size; /* TX or RX descriptor size, */
  106. /* stored here for fater math */
  107. union aq_ring_stats_s stats;
  108. dma_addr_t dx_ring_pa;
  109. };
  110. struct aq_ring_param_s {
  111. unsigned int vec_idx;
  112. unsigned int cpu;
  113. cpumask_t affinity_mask;
  114. };
  115. static inline unsigned int aq_ring_next_dx(struct aq_ring_s *self,
  116. unsigned int dx)
  117. {
  118. return (++dx >= self->size) ? 0U : dx;
  119. }
  120. static inline unsigned int aq_ring_avail_dx(struct aq_ring_s *self)
  121. {
  122. return (((self->sw_tail >= self->sw_head)) ?
  123. (self->size - 1) - self->sw_tail + self->sw_head :
  124. self->sw_head - self->sw_tail - 1);
  125. }
  126. struct aq_ring_s *aq_ring_tx_alloc(struct aq_ring_s *self,
  127. struct aq_nic_s *aq_nic,
  128. unsigned int idx,
  129. struct aq_nic_cfg_s *aq_nic_cfg);
  130. struct aq_ring_s *aq_ring_rx_alloc(struct aq_ring_s *self,
  131. struct aq_nic_s *aq_nic,
  132. unsigned int idx,
  133. struct aq_nic_cfg_s *aq_nic_cfg);
  134. int aq_ring_init(struct aq_ring_s *self);
  135. void aq_ring_rx_deinit(struct aq_ring_s *self);
  136. void aq_ring_free(struct aq_ring_s *self);
  137. void aq_ring_tx_clean(struct aq_ring_s *self);
  138. int aq_ring_rx_clean(struct aq_ring_s *self, int *work_done, int budget);
  139. int aq_ring_rx_fill(struct aq_ring_s *self);
  140. #endif /* AQ_RING_H */