xref: /f-stack/dpdk/drivers/net/sfc/sfc_rx.h (revision 16d80a6d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2016-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9 
10 #ifndef _SFC_RX_H
11 #define _SFC_RX_H
12 
13 #include <rte_mbuf.h>
14 #include <rte_mempool.h>
15 #include <rte_ethdev_driver.h>
16 
17 #include "efx.h"
18 
19 #include "sfc_dp_rx.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 struct sfc_adapter;
26 struct sfc_evq;
27 
28 /**
29  * Software Rx descriptor information associated with hardware Rx
30  * descriptor.
31  */
32 struct sfc_efx_rx_sw_desc {
33 	struct rte_mbuf		*mbuf;
34 	unsigned int		flags;
35 	unsigned int		size;
36 };
37 
38 /** Receive queue state bits */
39 enum sfc_rxq_state_bit {
40 	SFC_RXQ_INITIALIZED_BIT = 0,
41 #define SFC_RXQ_INITIALIZED	(1 << SFC_RXQ_INITIALIZED_BIT)
42 	SFC_RXQ_STARTED_BIT,
43 #define SFC_RXQ_STARTED		(1 << SFC_RXQ_STARTED_BIT)
44 	SFC_RXQ_FLUSHING_BIT,
45 #define SFC_RXQ_FLUSHING	(1 << SFC_RXQ_FLUSHING_BIT)
46 	SFC_RXQ_FLUSHED_BIT,
47 #define SFC_RXQ_FLUSHED		(1 << SFC_RXQ_FLUSHED_BIT)
48 	SFC_RXQ_FLUSH_FAILED_BIT,
49 #define SFC_RXQ_FLUSH_FAILED	(1 << SFC_RXQ_FLUSH_FAILED_BIT)
50 };
51 
52 /**
53  * Receive queue control information.
54  * Allocated on the socket specified on the queue setup.
55  */
56 struct sfc_rxq {
57 	struct sfc_evq		*evq;
58 	efx_rxq_t		*common;
59 	efsys_mem_t		mem;
60 	unsigned int		hw_index;
61 	unsigned int		refill_threshold;
62 	struct rte_mempool	*refill_mb_pool;
63 	uint16_t		buf_size;
64 	struct sfc_dp_rxq	*dp;
65 	unsigned int		state;
66 };
67 
68 static inline unsigned int
69 sfc_rxq_sw_index_by_hw_index(unsigned int hw_index)
70 {
71 	return hw_index;
72 }
73 
74 static inline unsigned int
75 sfc_rxq_sw_index(const struct sfc_rxq *rxq)
76 {
77 	return sfc_rxq_sw_index_by_hw_index(rxq->hw_index);
78 }
79 
80 struct sfc_rxq *sfc_rxq_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
81 
82 /**
83  * Receive queue information used on libefx-based data path.
84  * Allocated on the socket specified on the queue setup.
85  */
86 struct sfc_efx_rxq {
87 	/* Used on data path */
88 	struct sfc_evq			*evq;
89 	unsigned int			flags;
90 #define SFC_EFX_RXQ_FLAG_STARTED	0x1
91 #define SFC_EFX_RXQ_FLAG_RUNNING	0x2
92 #define SFC_EFX_RXQ_FLAG_RSS_HASH	0x4
93 	unsigned int			ptr_mask;
94 	unsigned int			pending;
95 	unsigned int			completed;
96 	uint16_t			batch_max;
97 	uint16_t			prefix_size;
98 	struct sfc_efx_rx_sw_desc	*sw_desc;
99 
100 	/* Used on refill */
101 	unsigned int			added;
102 	unsigned int			pushed;
103 	unsigned int			max_fill_level;
104 	unsigned int			refill_threshold;
105 	uint16_t			buf_size;
106 	struct rte_mempool		*refill_mb_pool;
107 	efx_rxq_t			*common;
108 
109 	/* Datapath receive queue anchor */
110 	struct sfc_dp_rxq		dp;
111 };
112 
113 static inline struct sfc_efx_rxq *
114 sfc_efx_rxq_by_dp_rxq(struct sfc_dp_rxq *dp_rxq)
115 {
116 	return container_of(dp_rxq, struct sfc_efx_rxq, dp);
117 }
118 
119 /**
120  * Receive queue information used during setup/release only.
121  * Allocated on the same socket as adapter data.
122  */
123 struct sfc_rxq_info {
124 	unsigned int		max_entries;
125 	unsigned int		entries;
126 	efx_rxq_type_t		type;
127 	unsigned int		type_flags;
128 	struct sfc_rxq		*rxq;
129 	boolean_t		deferred_start;
130 	boolean_t		deferred_started;
131 };
132 
133 int sfc_rx_configure(struct sfc_adapter *sa);
134 void sfc_rx_close(struct sfc_adapter *sa);
135 int sfc_rx_start(struct sfc_adapter *sa);
136 void sfc_rx_stop(struct sfc_adapter *sa);
137 
138 int sfc_rx_qinit(struct sfc_adapter *sa, unsigned int rx_queue_id,
139 		 uint16_t nb_rx_desc, unsigned int socket_id,
140 		 const struct rte_eth_rxconf *rx_conf,
141 		 struct rte_mempool *mb_pool);
142 void sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index);
143 int sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index);
144 void sfc_rx_qstop(struct sfc_adapter *sa, unsigned int sw_index);
145 
146 uint64_t sfc_rx_get_dev_offload_caps(struct sfc_adapter *sa);
147 uint64_t sfc_rx_get_queue_offload_caps(struct sfc_adapter *sa);
148 
149 void sfc_rx_qflush_done(struct sfc_rxq *rxq);
150 void sfc_rx_qflush_failed(struct sfc_rxq *rxq);
151 
152 unsigned int sfc_rx_qdesc_npending(struct sfc_adapter *sa,
153 				   unsigned int sw_index);
154 int sfc_rx_qdesc_done(struct sfc_dp_rxq *dp_rxq, unsigned int offset);
155 
156 int sfc_rx_hash_init(struct sfc_adapter *sa);
157 void sfc_rx_hash_fini(struct sfc_adapter *sa);
158 int sfc_rx_hf_rte_to_efx(struct sfc_adapter *sa, uint64_t rte,
159 			 efx_rx_hash_type_t *efx);
160 uint64_t sfc_rx_hf_efx_to_rte(struct sfc_adapter *sa,
161 			      efx_rx_hash_type_t efx);
162 boolean_t sfc_rx_check_scatter(size_t pdu, size_t rx_buf_size,
163 			       uint32_t rx_prefix_size,
164 			       boolean_t rx_scatter_enabled,
165 			       const char **error);
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 #endif  /* _SFC_RX_H */
171