ice: Audit hotpath structures with pahole
[linux-2.6-microblaze.git] / drivers / net / ethernet / intel / ice / ice_txrx.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3
4 #ifndef _ICE_TXRX_H_
5 #define _ICE_TXRX_H_
6
7 #define ICE_DFLT_IRQ_WORK       256
8 #define ICE_RXBUF_2048          2048
9 #define ICE_MAX_CHAINED_RX_BUFS 5
10 #define ICE_MAX_BUF_TXD         8
11 #define ICE_MIN_TX_LEN          17
12
13 /* The size limit for a transmit buffer in a descriptor is (16K - 1).
14  * In order to align with the read requests we will align the value to
15  * the nearest 4K which represents our maximum read request size.
16  */
17 #define ICE_MAX_READ_REQ_SIZE   4096
18 #define ICE_MAX_DATA_PER_TXD    (16 * 1024 - 1)
19 #define ICE_MAX_DATA_PER_TXD_ALIGNED \
20         (~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD)
21
22 #define ICE_RX_BUF_WRITE        16      /* Must be power of 2 */
23 #define ICE_MAX_TXQ_PER_TXQG    128
24
25 /* We are assuming that the cache line is always 64 Bytes here for ice.
26  * In order to make sure that is a correct assumption there is a check in probe
27  * to print a warning if the read from GLPCI_CNF2 tells us that the cache line
28  * size is 128 bytes. We do it this way because we do not want to read the
29  * GLPCI_CNF2 register or a variable containing the value on every pass through
30  * the Tx path.
31  */
32 #define ICE_CACHE_LINE_BYTES            64
33 #define ICE_DESCS_PER_CACHE_LINE        (ICE_CACHE_LINE_BYTES / \
34                                          sizeof(struct ice_tx_desc))
35 #define ICE_DESCS_FOR_CTX_DESC          1
36 #define ICE_DESCS_FOR_SKB_DATA_PTR      1
37 /* Tx descriptors needed, worst case */
38 #define DESC_NEEDED (MAX_SKB_FRAGS + ICE_DESCS_FOR_CTX_DESC + \
39                      ICE_DESCS_PER_CACHE_LINE + ICE_DESCS_FOR_SKB_DATA_PTR)
40 #define ICE_DESC_UNUSED(R)      \
41         ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
42         (R)->next_to_clean - (R)->next_to_use - 1)
43
44 #define ICE_TX_FLAGS_TSO        BIT(0)
45 #define ICE_TX_FLAGS_HW_VLAN    BIT(1)
46 #define ICE_TX_FLAGS_SW_VLAN    BIT(2)
47 #define ICE_TX_FLAGS_VLAN_M     0xffff0000
48 #define ICE_TX_FLAGS_VLAN_S     16
49
50 #define ICE_RX_DMA_ATTR \
51         (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
52
53 struct ice_tx_buf {
54         struct ice_tx_desc *next_to_watch;
55         struct sk_buff *skb;
56         unsigned int bytecount;
57         unsigned short gso_segs;
58         u32 tx_flags;
59         DEFINE_DMA_UNMAP_ADDR(dma);
60         DEFINE_DMA_UNMAP_LEN(len);
61 };
62
63 struct ice_tx_offload_params {
64         u8 header_len;
65         u32 td_cmd;
66         u32 td_offset;
67         u32 td_l2tag1;
68         u16 cd_l2tag2;
69         u32 cd_tunnel_params;
70         u64 cd_qw1;
71         struct ice_ring *tx_ring;
72 };
73
74 struct ice_rx_buf {
75         struct sk_buff *skb;
76         dma_addr_t dma;
77         struct page *page;
78         unsigned int page_offset;
79         u16 pagecnt_bias;
80 };
81
82 struct ice_q_stats {
83         u64 pkts;
84         u64 bytes;
85 };
86
87 struct ice_txq_stats {
88         u64 restart_q;
89         u64 tx_busy;
90         u64 tx_linearize;
91         int prev_pkt; /* negative if no pending Tx descriptors */
92 };
93
94 struct ice_rxq_stats {
95         u64 non_eop_descs;
96         u64 alloc_page_failed;
97         u64 alloc_buf_failed;
98         u64 page_reuse_count;
99 };
100
101 /* this enum matches hardware bits and is meant to be used by DYN_CTLN
102  * registers and QINT registers or more generally anywhere in the manual
103  * mentioning ITR_INDX, ITR_NONE cannot be used as an index 'n' into any
104  * register but instead is a special value meaning "don't update" ITR0/1/2.
105  */
106 enum ice_dyn_idx_t {
107         ICE_IDX_ITR0 = 0,
108         ICE_IDX_ITR1 = 1,
109         ICE_IDX_ITR2 = 2,
110         ICE_ITR_NONE = 3        /* ITR_NONE must not be used as an index */
111 };
112
113 /* Header split modes defined by DTYPE field of Rx RLAN context */
114 enum ice_rx_dtype {
115         ICE_RX_DTYPE_NO_SPLIT           = 0,
116         ICE_RX_DTYPE_HEADER_SPLIT       = 1,
117         ICE_RX_DTYPE_SPLIT_ALWAYS       = 2,
118 };
119
120 /* indices into GLINT_ITR registers */
121 #define ICE_RX_ITR      ICE_IDX_ITR0
122 #define ICE_TX_ITR      ICE_IDX_ITR1
123 #define ICE_ITR_8K      124
124 #define ICE_ITR_20K     50
125 #define ICE_ITR_MAX     8160
126 #define ICE_DFLT_TX_ITR (ICE_ITR_20K | ICE_ITR_DYNAMIC)
127 #define ICE_DFLT_RX_ITR (ICE_ITR_20K | ICE_ITR_DYNAMIC)
128 #define ICE_ITR_DYNAMIC 0x8000  /* used as flag for itr_setting */
129 #define ITR_IS_DYNAMIC(setting) (!!((setting) & ICE_ITR_DYNAMIC))
130 #define ITR_TO_REG(setting)     ((setting) & ~ICE_ITR_DYNAMIC)
131 #define ICE_ITR_GRAN_S          1       /* Assume ITR granularity is 2us */
132 #define ICE_ITR_GRAN_US         BIT(ICE_ITR_GRAN_S)
133 #define ICE_ITR_MASK            0x1FFE  /* ITR register value alignment mask */
134 #define ITR_REG_ALIGN(setting)  __ALIGN_MASK(setting, ~ICE_ITR_MASK)
135
136 #define ICE_ITR_ADAPTIVE_MIN_INC        0x0002
137 #define ICE_ITR_ADAPTIVE_MIN_USECS      0x0002
138 #define ICE_ITR_ADAPTIVE_MAX_USECS      0x00FA
139 #define ICE_ITR_ADAPTIVE_LATENCY        0x8000
140 #define ICE_ITR_ADAPTIVE_BULK           0x0000
141
142 #define ICE_DFLT_INTRL  0
143
144 /* Legacy or Advanced Mode Queue */
145 #define ICE_TX_ADVANCED 0
146 #define ICE_TX_LEGACY   1
147
148 /* descriptor ring, associated with a VSI */
149 struct ice_ring {
150         struct ice_ring *next;          /* pointer to next ring in q_vector */
151         void *desc;                     /* Descriptor ring memory */
152         struct device *dev;             /* Used for DMA mapping */
153         struct net_device *netdev;      /* netdev ring maps to */
154         struct ice_vsi *vsi;            /* Backreference to associated VSI */
155         struct ice_q_vector *q_vector;  /* Backreference to associated vector */
156         u8 __iomem *tail;
157         union {
158                 struct ice_tx_buf *tx_buf;
159                 struct ice_rx_buf *rx_buf;
160         };
161         u16 q_index;                    /* Queue number of ring */
162         u32 txq_teid;                   /* Added Tx queue TEID */
163
164         u16 count;                      /* Number of descriptors */
165         u16 reg_idx;                    /* HW register index of the ring */
166
167         /* used in interrupt processing */
168         u16 next_to_use;
169         u16 next_to_clean;
170
171         u8 ring_active;                 /* is ring online or not */
172
173         /* stats structs */
174         struct ice_q_stats      stats;
175         struct u64_stats_sync syncp;
176         union {
177                 struct ice_txq_stats tx_stats;
178                 struct ice_rxq_stats rx_stats;
179         };
180
181         unsigned int size;              /* length of descriptor ring in bytes */
182         dma_addr_t dma;                 /* physical address of ring */
183         struct rcu_head rcu;            /* to avoid race on free */
184         u16 next_to_alloc;
185 } ____cacheline_internodealigned_in_smp;
186
187 struct ice_ring_container {
188         /* head of linked-list of rings */
189         struct ice_ring *ring;
190         unsigned long next_update;      /* jiffies value of next queue update */
191         unsigned int total_bytes;       /* total bytes processed this int */
192         unsigned int total_pkts;        /* total packets processed this int */
193         u16 itr_idx;            /* index in the interrupt vector */
194         u16 target_itr;         /* value in usecs divided by the hw->itr_gran */
195         u16 current_itr;        /* value in usecs divided by the hw->itr_gran */
196         /* high bit set means dynamic ITR, rest is used to store user
197          * readable ITR value in usecs and must be converted before programming
198          * to a register.
199          */
200         u16 itr_setting;
201 };
202
203 /* iterator for handling rings in ring container */
204 #define ice_for_each_ring(pos, head) \
205         for (pos = (head).ring; pos; pos = pos->next)
206
207 bool ice_alloc_rx_bufs(struct ice_ring *rxr, u16 cleaned_count);
208 netdev_tx_t ice_start_xmit(struct sk_buff *skb, struct net_device *netdev);
209 void ice_clean_tx_ring(struct ice_ring *tx_ring);
210 void ice_clean_rx_ring(struct ice_ring *rx_ring);
211 int ice_setup_tx_ring(struct ice_ring *tx_ring);
212 int ice_setup_rx_ring(struct ice_ring *rx_ring);
213 void ice_free_tx_ring(struct ice_ring *tx_ring);
214 void ice_free_rx_ring(struct ice_ring *rx_ring);
215 int ice_napi_poll(struct napi_struct *napi, int budget);
216
217 #endif /* _ICE_TXRX_H_ */