aq_ring.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. struct aq_nic_cfg_s;
  15. /* TxC SOP DX EOP
  16. * +----------+----------+----------+-----------
  17. * 8bytes|len l3,l4 | pa | pa | pa
  18. * +----------+----------+----------+-----------
  19. * 4/8bytes|len pkt |len pkt | | skb
  20. * +----------+----------+----------+-----------
  21. * 4/8bytes|is_txc |len,flags |len |len,is_eop
  22. * +----------+----------+----------+-----------
  23. *
  24. * This aq_ring_buff_s doesn't have endianness dependency.
  25. * It is __packed for cache line optimizations.
  26. */
  27. struct __packed aq_ring_buff_s {
  28. union {
  29. /* RX */
  30. struct {
  31. u32 rss_hash;
  32. u16 next;
  33. u8 is_hash_l4;
  34. u8 rsvd1;
  35. struct page *page;
  36. };
  37. /* EOP */
  38. struct {
  39. dma_addr_t pa_eop;
  40. struct sk_buff *skb;
  41. };
  42. /* DX */
  43. struct {
  44. dma_addr_t pa;
  45. };
  46. /* SOP */
  47. struct {
  48. dma_addr_t pa_sop;
  49. u32 len_pkt_sop;
  50. };
  51. /* TxC */
  52. struct {
  53. u32 mss;
  54. u8 len_l2;
  55. u8 len_l3;
  56. u8 len_l4;
  57. u8 is_ipv6:1;
  58. u8 rsvd2:7;
  59. u32 len_pkt;
  60. };
  61. };
  62. union {
  63. struct {
  64. u16 len;
  65. u32 is_ip_cso:1;
  66. u32 is_udp_cso:1;
  67. u32 is_tcp_cso:1;
  68. u32 is_cso_err:1;
  69. u32 is_sop:1;
  70. u32 is_eop:1;
  71. u32 is_txc:1;
  72. u32 is_mapped:1;
  73. u32 is_cleaned:1;
  74. u32 is_error:1;
  75. u32 rsvd3:6;
  76. u16 eop_index;
  77. u16 rsvd4;
  78. };
  79. u64 flags;
  80. };
  81. };
  82. struct aq_ring_stats_rx_s {
  83. u64 errors;
  84. u64 packets;
  85. u64 bytes;
  86. u64 lro_packets;
  87. u64 jumbo_packets;
  88. };
  89. struct aq_ring_stats_tx_s {
  90. u64 errors;
  91. u64 packets;
  92. u64 bytes;
  93. u64 queue_restarts;
  94. };
  95. union aq_ring_stats_s {
  96. struct aq_ring_stats_rx_s rx;
  97. struct aq_ring_stats_tx_s tx;
  98. };
  99. struct aq_ring_s {
  100. struct aq_ring_buff_s *buff_ring;
  101. u8 *dx_ring; /* descriptors ring, dma shared mem */
  102. struct aq_nic_s *aq_nic;
  103. unsigned int idx; /* for HW layer registers operations */
  104. unsigned int hw_head;
  105. unsigned int sw_head;
  106. unsigned int sw_tail;
  107. unsigned int size; /* descriptors number */
  108. unsigned int dx_size; /* TX or RX descriptor size, */
  109. /* stored here for fater math */
  110. union aq_ring_stats_s stats;
  111. dma_addr_t dx_ring_pa;
  112. };
  113. struct aq_ring_param_s {
  114. unsigned int vec_idx;
  115. unsigned int cpu;
  116. cpumask_t affinity_mask;
  117. };
  118. static inline unsigned int aq_ring_next_dx(struct aq_ring_s *self,
  119. unsigned int dx)
  120. {
  121. return (++dx >= self->size) ? 0U : dx;
  122. }
  123. static inline unsigned int aq_ring_avail_dx(struct aq_ring_s *self)
  124. {
  125. return (((self->sw_tail >= self->sw_head)) ?
  126. (self->size - 1) - self->sw_tail + self->sw_head :
  127. self->sw_head - self->sw_tail - 1);
  128. }
  129. struct aq_ring_s *aq_ring_tx_alloc(struct aq_ring_s *self,
  130. struct aq_nic_s *aq_nic,
  131. unsigned int idx,
  132. struct aq_nic_cfg_s *aq_nic_cfg);
  133. struct aq_ring_s *aq_ring_rx_alloc(struct aq_ring_s *self,
  134. struct aq_nic_s *aq_nic,
  135. unsigned int idx,
  136. struct aq_nic_cfg_s *aq_nic_cfg);
  137. int aq_ring_init(struct aq_ring_s *self);
  138. void aq_ring_rx_deinit(struct aq_ring_s *self);
  139. void aq_ring_free(struct aq_ring_s *self);
  140. void aq_ring_update_queue_state(struct aq_ring_s *ring);
  141. void aq_ring_queue_wake(struct aq_ring_s *ring);
  142. void aq_ring_queue_stop(struct aq_ring_s *ring);
  143. bool aq_ring_tx_clean(struct aq_ring_s *self);
  144. int aq_ring_rx_clean(struct aq_ring_s *self,
  145. struct napi_struct *napi,
  146. int *work_done,
  147. int budget);
  148. int aq_ring_rx_fill(struct aq_ring_s *self);
  149. #endif /* AQ_RING_H */