Skip to content

Commit a4aa1f1

Browse files
baileyforrestdavem330
authored andcommitted
gve: Add DQO fields for core data structures
- Add new DQO datapath structures: - `gve_rx_buf_queue_dqo` - `gve_rx_compl_queue_dqo` - `gve_rx_buf_state_dqo` - `gve_tx_desc_dqo` - `gve_tx_pending_packet_dqo` - Incorporate these into the existing ring data structures: - `gve_rx_ring` - `gve_tx_ring` Noteworthy mentions: - `gve_rx_buf_state` represents an RX buffer which was posted to HW. Each RX queue has an array of these objects and the index into the array is used as the buffer_id when posted to HW. - `gve_tx_pending_packet_dqo` is treated similarly for TX queues. The completion_tag is the index into the array. - These two structures have links for linked lists which are represented by 16b indexes into a contiguous array of these structures. This reduces memory footprint compared to 64b pointers. - We use unions for the writeable datapath structures to reduce cache footprint. GQI specific members will renamed like DQO members in a future patch. Signed-off-by: Bailey Forrest <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: Catherine Sullivan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2231981 commit a4aa1f1

File tree

1 file changed

+251
-11
lines changed
  • drivers/net/ethernet/google/gve

1 file changed

+251
-11
lines changed

drivers/net/ethernet/google/gve/gve.h

Lines changed: 251 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/u64_stats_sync.h>
1414

1515
#include "gve_desc.h"
16+
#include "gve_desc_dqo.h"
1617

1718
#ifndef PCI_VENDOR_ID_GOOGLE
1819
#define PCI_VENDOR_ID_GOOGLE 0x1ae0
@@ -80,17 +81,117 @@ struct gve_rx_data_queue {
8081

8182
struct gve_priv;
8283

83-
/* An RX ring that contains a power-of-two sized desc and data ring. */
84+
/* RX buffer queue for posting buffers to HW.
85+
* Each RX (completion) queue has a corresponding buffer queue.
86+
*/
87+
struct gve_rx_buf_queue_dqo {
88+
struct gve_rx_desc_dqo *desc_ring;
89+
dma_addr_t bus;
90+
u32 head; /* Pointer to start cleaning buffers at. */
91+
u32 tail; /* Last posted buffer index + 1 */
92+
u32 mask; /* Mask for indices to the size of the ring */
93+
};
94+
95+
/* RX completion queue to receive packets from HW. */
96+
struct gve_rx_compl_queue_dqo {
97+
struct gve_rx_compl_desc_dqo *desc_ring;
98+
dma_addr_t bus;
99+
100+
/* Number of slots which did not have a buffer posted yet. We should not
101+
* post more buffers than the queue size to avoid HW overrunning the
102+
* queue.
103+
*/
104+
int num_free_slots;
105+
106+
/* HW uses a "generation bit" to notify SW of new descriptors. When a
107+
* descriptor's generation bit is different from the current generation,
108+
* that descriptor is ready to be consumed by SW.
109+
*/
110+
u8 cur_gen_bit;
111+
112+
/* Pointer into desc_ring where the next completion descriptor will be
113+
* received.
114+
*/
115+
u32 head;
116+
u32 mask; /* Mask for indices to the size of the ring */
117+
};
118+
119+
/* Stores state for tracking buffers posted to HW */
120+
struct gve_rx_buf_state_dqo {
121+
/* The page posted to HW. */
122+
struct gve_rx_slot_page_info page_info;
123+
124+
/* The DMA address corresponding to `page_info`. */
125+
dma_addr_t addr;
126+
127+
/* Last offset into the page when it only had a single reference, at
128+
* which point every other offset is free to be reused.
129+
*/
130+
u32 last_single_ref_offset;
131+
132+
/* Linked list index to next element in the list, or -1 if none */
133+
s16 next;
134+
};
135+
136+
/* `head` and `tail` are indices into an array, or -1 if empty. */
137+
struct gve_index_list {
138+
s16 head;
139+
s16 tail;
140+
};
141+
142+
/* Contains datapath state used to represent an RX queue. */
84143
struct gve_rx_ring {
85144
struct gve_priv *gve;
86-
struct gve_rx_desc_queue desc;
87-
struct gve_rx_data_queue data;
145+
union {
146+
/* GQI fields */
147+
struct {
148+
struct gve_rx_desc_queue desc;
149+
struct gve_rx_data_queue data;
150+
151+
/* threshold for posting new buffs and descs */
152+
u32 db_threshold;
153+
};
154+
155+
/* DQO fields. */
156+
struct {
157+
struct gve_rx_buf_queue_dqo bufq;
158+
struct gve_rx_compl_queue_dqo complq;
159+
160+
struct gve_rx_buf_state_dqo *buf_states;
161+
u16 num_buf_states;
162+
163+
/* Linked list of gve_rx_buf_state_dqo. Index into
164+
* buf_states, or -1 if empty.
165+
*/
166+
s16 free_buf_states;
167+
168+
/* Linked list of gve_rx_buf_state_dqo. Indexes into
169+
* buf_states, or -1 if empty.
170+
*
171+
* This list contains buf_states which are pointing to
172+
* valid buffers.
173+
*
174+
* We use a FIFO here in order to increase the
175+
* probability that buffers can be reused by increasing
176+
* the time between usages.
177+
*/
178+
struct gve_index_list recycled_buf_states;
179+
180+
/* Linked list of gve_rx_buf_state_dqo. Indexes into
181+
* buf_states, or -1 if empty.
182+
*
183+
* This list contains buf_states which have buffers
184+
* which cannot be reused yet.
185+
*/
186+
struct gve_index_list used_buf_states;
187+
} dqo;
188+
};
189+
88190
u64 rbytes; /* free-running bytes received */
89191
u64 rpackets; /* free-running packets received */
90192
u32 cnt; /* free-running total number of completed packets */
91193
u32 fill_cnt; /* free-running total number of descs and buffs posted */
92194
u32 mask; /* masks the cnt and fill_cnt to the size of the ring */
93-
u32 db_threshold; /* threshold for posting new buffs and descs */
94195
u64 rx_copybreak_pkt; /* free-running count of copybreak packets */
95196
u64 rx_copied_pkt; /* free-running total number of copied packets */
96197
u64 rx_skb_alloc_fail; /* free-running count of skb alloc fails */
@@ -141,23 +242,161 @@ struct gve_tx_fifo {
141242
struct gve_queue_page_list *qpl; /* QPL mapped into this FIFO */
142243
};
143244

144-
/* A TX ring that contains a power-of-two sized desc ring and a FIFO buffer */
245+
/* TX descriptor for DQO format */
246+
union gve_tx_desc_dqo {
247+
struct gve_tx_pkt_desc_dqo pkt;
248+
struct gve_tx_tso_context_desc_dqo tso_ctx;
249+
struct gve_tx_general_context_desc_dqo general_ctx;
250+
};
251+
252+
enum gve_packet_state {
253+
/* Packet is in free list, available to be allocated.
254+
* This should always be zero since state is not explicitly initialized.
255+
*/
256+
GVE_PACKET_STATE_UNALLOCATED,
257+
/* Packet is expecting a regular data completion or miss completion */
258+
GVE_PACKET_STATE_PENDING_DATA_COMPL,
259+
/* Packet has received a miss completion and is expecting a
260+
* re-injection completion.
261+
*/
262+
GVE_PACKET_STATE_PENDING_REINJECT_COMPL,
263+
/* No valid completion received within the specified timeout. */
264+
GVE_PACKET_STATE_TIMED_OUT_COMPL,
265+
};
266+
267+
struct gve_tx_pending_packet_dqo {
268+
struct sk_buff *skb; /* skb for this packet */
269+
270+
/* 0th element corresponds to the linear portion of `skb`, should be
271+
* unmapped with `dma_unmap_single`.
272+
*
273+
* All others correspond to `skb`'s frags and should be unmapped with
274+
* `dma_unmap_page`.
275+
*/
276+
struct gve_tx_dma_buf bufs[MAX_SKB_FRAGS + 1];
277+
u16 num_bufs;
278+
279+
/* Linked list index to next element in the list, or -1 if none */
280+
s16 next;
281+
282+
/* Linked list index to prev element in the list, or -1 if none.
283+
* Used for tracking either outstanding miss completions or prematurely
284+
* freed packets.
285+
*/
286+
s16 prev;
287+
288+
/* Identifies the current state of the packet as defined in
289+
* `enum gve_packet_state`.
290+
*/
291+
u8 state;
292+
293+
/* If packet is an outstanding miss completion, then the packet is
294+
* freed if the corresponding re-injection completion is not received
295+
* before kernel jiffies exceeds timeout_jiffies.
296+
*/
297+
unsigned long timeout_jiffies;
298+
};
299+
300+
/* Contains datapath state used to represent a TX queue. */
145301
struct gve_tx_ring {
146302
/* Cacheline 0 -- Accessed & dirtied during transmit */
147-
struct gve_tx_fifo tx_fifo;
148-
u32 req; /* driver tracked head pointer */
149-
u32 done; /* driver tracked tail pointer */
303+
union {
304+
/* GQI fields */
305+
struct {
306+
struct gve_tx_fifo tx_fifo;
307+
u32 req; /* driver tracked head pointer */
308+
u32 done; /* driver tracked tail pointer */
309+
};
310+
311+
/* DQO fields. */
312+
struct {
313+
/* Linked list of gve_tx_pending_packet_dqo. Index into
314+
* pending_packets, or -1 if empty.
315+
*
316+
* This is a consumer list owned by the TX path. When it
317+
* runs out, the producer list is stolen from the
318+
* completion handling path
319+
* (dqo_compl.free_pending_packets).
320+
*/
321+
s16 free_pending_packets;
322+
323+
/* Cached value of `dqo_compl.hw_tx_head` */
324+
u32 head;
325+
u32 tail; /* Last posted buffer index + 1 */
326+
327+
/* Index of the last descriptor with "report event" bit
328+
* set.
329+
*/
330+
u32 last_re_idx;
331+
} dqo_tx;
332+
};
150333

151334
/* Cacheline 1 -- Accessed & dirtied during gve_clean_tx_done */
152-
__be32 last_nic_done ____cacheline_aligned; /* NIC tail pointer */
335+
union {
336+
/* GQI fields */
337+
struct {
338+
/* NIC tail pointer */
339+
__be32 last_nic_done;
340+
};
341+
342+
/* DQO fields. */
343+
struct {
344+
u32 head; /* Last read on compl_desc */
345+
346+
/* Tracks the current gen bit of compl_q */
347+
u8 cur_gen_bit;
348+
349+
/* Linked list of gve_tx_pending_packet_dqo. Index into
350+
* pending_packets, or -1 if empty.
351+
*
352+
* This is the producer list, owned by the completion
353+
* handling path. When the consumer list
354+
* (dqo_tx.free_pending_packets) is runs out, this list
355+
* will be stolen.
356+
*/
357+
atomic_t free_pending_packets;
358+
359+
/* Last TX ring index fetched by HW */
360+
atomic_t hw_tx_head;
361+
362+
/* List to track pending packets which received a miss
363+
* completion but not a corresponding reinjection.
364+
*/
365+
struct gve_index_list miss_completions;
366+
367+
/* List to track pending packets that were completed
368+
* before receiving a valid completion because they
369+
* reached a specified timeout.
370+
*/
371+
struct gve_index_list timed_out_completions;
372+
} dqo_compl;
373+
} ____cacheline_aligned;
153374
u64 pkt_done; /* free-running - total packets completed */
154375
u64 bytes_done; /* free-running - total bytes completed */
155376
u64 dropped_pkt; /* free-running - total packets dropped */
156377
u64 dma_mapping_error; /* count of dma mapping errors */
157378

158379
/* Cacheline 2 -- Read-mostly fields */
159-
union gve_tx_desc *desc ____cacheline_aligned;
160-
struct gve_tx_buffer_state *info; /* Maps 1:1 to a desc */
380+
union {
381+
/* GQI fields */
382+
struct {
383+
union gve_tx_desc *desc;
384+
385+
/* Maps 1:1 to a desc */
386+
struct gve_tx_buffer_state *info;
387+
};
388+
389+
/* DQO fields. */
390+
struct {
391+
union gve_tx_desc_dqo *tx_ring;
392+
struct gve_tx_compl_desc *compl_ring;
393+
394+
struct gve_tx_pending_packet_dqo *pending_packets;
395+
s16 num_pending_packets;
396+
397+
u32 complq_mask; /* complq size is complq_mask + 1 */
398+
} dqo;
399+
} ____cacheline_aligned;
161400
struct netdev_queue *netdev_txq;
162401
struct gve_queue_resources *q_resources; /* head and tail pointer idx */
163402
struct device *dev;
@@ -171,6 +410,7 @@ struct gve_tx_ring {
171410
u32 ntfy_id; /* notification block index */
172411
dma_addr_t bus; /* dma address of the descr ring */
173412
dma_addr_t q_resources_bus; /* dma address of the queue resources */
413+
dma_addr_t complq_bus_dqo; /* dma address of the dqo.compl_ring */
174414
struct u64_stats_sync statss; /* sync stats for 32bit archs */
175415
} ____cacheline_aligned;
176416

0 commit comments

Comments
 (0)