xref: /dpdk/drivers/net/sfc/sfc_rx.h (revision a9a238e9f57dd4363535bfb78c0c5c762522014a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2016-2019 Solarflare Communications Inc.
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 <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 primary process-only information.
54  */
55 struct sfc_rxq {
56 	struct sfc_evq		*evq;
57 	efx_rxq_t		*common;
58 	efsys_mem_t		mem;
59 	unsigned int		hw_index;
60 	uint16_t		buf_size;
61 };
62 
63 struct sfc_rxq *sfc_rxq_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
64 
65 /**
66  * Receive queue information used on libefx-based data path.
67  * Allocated on the socket specified on the queue setup.
68  */
69 struct sfc_efx_rxq {
70 	/* Used on data path */
71 	struct sfc_evq			*evq;
72 	unsigned int			flags;
73 #define SFC_EFX_RXQ_FLAG_STARTED	0x1
74 #define SFC_EFX_RXQ_FLAG_RUNNING	0x2
75 #define SFC_EFX_RXQ_FLAG_RSS_HASH	0x4
76 #define SFC_EFX_RXQ_FLAG_INTR_EN	0x8
77 	unsigned int			ptr_mask;
78 	unsigned int			pending;
79 	unsigned int			completed;
80 	uint16_t			batch_max;
81 	uint16_t			prefix_size;
82 	struct sfc_efx_rx_sw_desc	*sw_desc;
83 
84 	/* Used on refill */
85 	unsigned int			added;
86 	unsigned int			pushed;
87 	unsigned int			max_fill_level;
88 	unsigned int			refill_threshold;
89 	uint16_t			buf_size;
90 	struct rte_mempool		*refill_mb_pool;
91 	efx_rxq_t			*common;
92 
93 	/* Datapath receive queue anchor */
94 	struct sfc_dp_rxq		dp;
95 };
96 
97 static inline struct sfc_efx_rxq *
sfc_efx_rxq_by_dp_rxq(struct sfc_dp_rxq * dp_rxq)98 sfc_efx_rxq_by_dp_rxq(struct sfc_dp_rxq *dp_rxq)
99 {
100 	return container_of(dp_rxq, struct sfc_efx_rxq, dp);
101 }
102 
103 /**
104  * Receive queue information used during setup/release only.
105  * Allocated on the same socket as adapter data.
106  */
107 struct sfc_rxq_info {
108 	unsigned int		state;
109 	unsigned int		max_entries;
110 	unsigned int		entries;
111 	efx_rxq_type_t		type;
112 	unsigned int		type_flags;
113 	struct sfc_dp_rxq	*dp;
114 	boolean_t		deferred_start;
115 	boolean_t		deferred_started;
116 	unsigned int		refill_threshold;
117 	struct rte_mempool	*refill_mb_pool;
118 	unsigned int		rxq_flags;
119 };
120 
121 struct sfc_rxq_info *sfc_rxq_info_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
122 struct sfc_rxq_info *sfc_rxq_info_by_ethdev_qid(struct sfc_adapter_shared *sas,
123 						sfc_ethdev_qid_t ethdev_qid);
124 struct sfc_rxq *sfc_rxq_ctrl_by_ethdev_qid(struct sfc_adapter *sa,
125 					   sfc_ethdev_qid_t ethdev_qid);
126 
127 int sfc_rx_configure(struct sfc_adapter *sa);
128 void sfc_rx_close(struct sfc_adapter *sa);
129 int sfc_rx_start(struct sfc_adapter *sa);
130 void sfc_rx_stop(struct sfc_adapter *sa);
131 
132 int sfc_rx_qinit_info(struct sfc_adapter *sa, sfc_sw_index_t sw_index,
133 		      unsigned int extra_efx_type_flags);
134 int sfc_rx_qinit(struct sfc_adapter *sa, unsigned int rx_queue_id,
135 		 uint16_t nb_rx_desc, unsigned int socket_id,
136 		 const struct rte_eth_rxconf *rx_conf,
137 		 struct rte_mempool *mb_pool);
138 void sfc_rx_qfini(struct sfc_adapter *sa, sfc_sw_index_t sw_index);
139 int sfc_rx_qstart(struct sfc_adapter *sa, sfc_sw_index_t sw_index);
140 void sfc_rx_qstop(struct sfc_adapter *sa, sfc_sw_index_t sw_index);
141 
142 uint64_t sfc_rx_get_dev_offload_caps(struct sfc_adapter *sa);
143 uint64_t sfc_rx_get_queue_offload_caps(struct sfc_adapter *sa);
144 
145 void sfc_rx_qflush_done(struct sfc_rxq_info *rxq_info);
146 void sfc_rx_qflush_failed(struct sfc_rxq_info *rxq_info);
147 
148 unsigned int sfc_rx_get_pushed(struct sfc_adapter *sa,
149 			       struct sfc_dp_rxq *dp_rxq);
150 
151 int sfc_rx_hash_init(struct sfc_adapter *sa);
152 void sfc_rx_hash_fini(struct sfc_adapter *sa);
153 int sfc_rx_hf_rte_to_efx(struct sfc_adapter *sa, uint64_t rte,
154 			 efx_rx_hash_type_t *efx);
155 uint64_t sfc_rx_hf_efx_to_rte(struct sfc_rss *rss, efx_rx_hash_type_t efx);
156 boolean_t sfc_rx_check_scatter(size_t pdu, size_t rx_buf_size,
157 			       uint32_t rx_prefix_size,
158 			       boolean_t rx_scatter_enabled,
159 			       uint32_t rx_scatter_max,
160 			       const char **error);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 #endif  /* _SFC_RX_H */
166