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