Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2014-2018 Netronome Systems, Inc.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #ifndef __NFP_NET_COMMON_H__
7 : : #define __NFP_NET_COMMON_H__
8 : :
9 : : #include <bus_pci_driver.h>
10 : : #include <ethdev_driver.h>
11 : : #include <nfp_common.h>
12 : : #include <nfp_dev.h>
13 : : #include <rte_spinlock.h>
14 : :
15 : : #include "flower/nfp_flower_service.h"
16 : : #include "nfpcore/nfp_sync.h"
17 : : #include "nfp_net_ctrl.h"
18 : : #include "nfp_service.h"
19 : : #include "nfp_net_meta.h"
20 : :
21 : : /* Interrupt definitions */
22 : : #define NFP_NET_IRQ_LSC_IDX 0
23 : :
24 : : /* Default values for RX/TX configuration */
25 : : #define DEFAULT_RX_FREE_THRESH 32
26 : : #define DEFAULT_RX_PTHRESH 8
27 : : #define DEFAULT_RX_HTHRESH 8
28 : : #define DEFAULT_RX_WTHRESH 0
29 : :
30 : : #define DEFAULT_TX_RS_THRESH 32
31 : : #define DEFAULT_TX_FREE_THRESH 32
32 : : #define DEFAULT_TX_PTHRESH 32
33 : : #define DEFAULT_TX_HTHRESH 0
34 : : #define DEFAULT_TX_WTHRESH 0
35 : : #define DEFAULT_TX_RSBIT_THRESH 32
36 : :
37 : : /* Alignment for dma zones */
38 : : #define NFP_MEMZONE_ALIGN 128
39 : :
40 : : /* Number of supported physical ports */
41 : : #define NFP_MAX_PHYPORTS 12
42 : :
43 : : #define NFP_BEAT_LENGTH 8
44 : :
45 : : /* RSS capability*/
46 : : #define NFP_NET_RSS_CAP (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | \
47 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
48 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
49 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \
50 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
51 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
52 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
53 : :
54 : : /*
55 : : * Each PF has corresponding word to beat:
56 : : * Offset | Usage
57 : : * 0 | magic number
58 : : * 8 | beat of Pf0
59 : : * 16 | beat of Pf1
60 : : * 24 | beat of Pf2
61 : : * 32 | beat of Pf3
62 : : */
63 : : #define NFP_BEAT_OFFSET(_x) (((_x) + 1) * NFP_BEAT_LENGTH)
64 : :
65 : : /* Firmware application ID's */
66 : : enum nfp_app_fw_id {
67 : : NFP_APP_FW_CORE_NIC = 0x1,
68 : : NFP_APP_FW_FLOWER_NIC = 0x3,
69 : : };
70 : :
71 : : /* Parsed control BAR TLV capabilities */
72 : : struct nfp_net_tlv_caps {
73 : : uint32_t mbox_off; /**< VNIC mailbox area offset */
74 : : uint32_t mbox_len; /**< VNIC mailbox area length */
75 : : uint32_t mbox_cmsg_types; /**< Cmsgs which can be passed through the mailbox */
76 : : };
77 : :
78 : : struct nfp_multi_pf {
79 : : /** Support multiple PF */
80 : : bool enabled;
81 : : /** Function index */
82 : : uint8_t function_id;
83 : : /** Pointer to CPP area for beat to keepalive */
84 : : struct nfp_cpp_area *beat_area;
85 : : /** Pointer to mapped beat address used for keepalive */
86 : : uint8_t *beat_addr;
87 : : };
88 : :
89 : : struct nfp_process_share {
90 : : struct nfp_flower_service *fl_service;
91 : : };
92 : :
93 : : struct nfp_devargs {
94 : : /** Force reload firmware */
95 : : bool force_reload_fw;
96 : : };
97 : :
98 : : struct nfp_pf_dev {
99 : : /** Backpointer to associated pci device */
100 : : struct rte_pci_device *pci_dev;
101 : :
102 : : enum nfp_app_fw_id app_fw_id;
103 : :
104 : : /** Pointer to the app running on the PF */
105 : : void *app_fw_priv;
106 : :
107 : : /** The eth table reported by firmware */
108 : : struct nfp_eth_table *nfp_eth_table;
109 : :
110 : : uint8_t *ctrl_bar;
111 : :
112 : : struct nfp_cpp *cpp;
113 : : struct nfp_cpp_area *ctrl_area;
114 : : struct nfp_cpp_area *qc_area;
115 : :
116 : : uint8_t *qc_bar;
117 : :
118 : : struct nfp_hwinfo *hwinfo;
119 : : struct nfp_rtsym_table *sym_tbl;
120 : :
121 : : /** Service info of cpp bridge service */
122 : : struct nfp_service_info cpp_service_info;
123 : :
124 : : /** Multiple PF configuration */
125 : : struct nfp_multi_pf multi_pf;
126 : :
127 : : /** Supported speeds bitmap */
128 : : uint32_t speed_capa;
129 : :
130 : : /** Synchronized info */
131 : : struct nfp_sync *sync;
132 : : struct nfp_process_share process_share;
133 : :
134 : : /** NFP devarg param */
135 : : struct nfp_devargs devargs;
136 : : };
137 : :
138 : : #define NFP_NET_FLOW_LIMIT 1024
139 : :
140 : : struct nfp_net_priv {
141 : : uint32_t hash_seed; /**< Hash seed for hash tables in this structure. */
142 : : struct rte_hash *flow_table; /**< Hash table to store flow rules. */
143 : : uint16_t flow_count; /**< Flow count in hash table */
144 : : bool flow_position[NFP_NET_FLOW_LIMIT]; /**< Flow position array */
145 : : };
146 : :
147 : : struct nfp_app_fw_nic {
148 : : /** Backpointer to the PF device */
149 : : struct nfp_pf_dev *pf_dev;
150 : :
151 : : /**
152 : : * Array of physical ports belonging to this CoreNIC app.
153 : : * This is really a list of vNIC's, one for each physical port.
154 : : */
155 : : struct nfp_net_hw *ports[NFP_MAX_PHYPORTS];
156 : :
157 : : bool multiport;
158 : : uint8_t total_phyports;
159 : : };
160 : :
161 : : struct nfp_net_hw {
162 : : /** The parent class */
163 : : struct nfp_hw super;
164 : :
165 : : /** Backpointer to the PF this port belongs to */
166 : : struct nfp_pf_dev *pf_dev;
167 : :
168 : : /** Backpointer to the eth_dev of this port */
169 : : struct rte_eth_dev *eth_dev;
170 : :
171 : : /** Info from the firmware */
172 : : struct nfp_net_fw_ver ver;
173 : : uint32_t max_mtu;
174 : : uint32_t mtu;
175 : : uint32_t rx_offset;
176 : : enum nfp_net_meta_format meta_format;
177 : :
178 : : /** NFP ASIC params */
179 : : const struct nfp_dev_info *dev_info;
180 : :
181 : : uint8_t *tx_bar;
182 : : uint8_t *rx_bar;
183 : :
184 : : int stride_rx;
185 : : int stride_tx;
186 : :
187 : : uint16_t vxlan_ports[NFP_NET_N_VXLAN_PORTS];
188 : : uint8_t vxlan_usecnt[NFP_NET_N_VXLAN_PORTS];
189 : :
190 : : uint32_t max_tx_queues;
191 : : uint32_t max_rx_queues;
192 : : uint16_t flbufsz;
193 : : uint16_t device_id;
194 : : uint16_t vendor_id;
195 : : uint16_t subsystem_device_id;
196 : : uint16_t subsystem_vendor_id;
197 : :
198 : : /** Records starting point for counters */
199 : : struct rte_eth_stats eth_stats_base;
200 : : struct rte_eth_xstat *eth_xstats_base;
201 : :
202 : : struct nfp_cpp *cpp;
203 : : struct nfp_cpp_area *ctrl_area;
204 : : struct nfp_cpp_area *mac_stats_area;
205 : : uint8_t *mac_stats_bar;
206 : : uint8_t *mac_stats;
207 : :
208 : : /** Sequential physical port number, only valid for CoreNIC firmware */
209 : : uint8_t idx;
210 : : /** Internal port number as seen from NFP */
211 : : uint8_t nfp_idx;
212 : :
213 : : struct nfp_net_tlv_caps tlv_caps;
214 : :
215 : : struct nfp_net_ipsec_data *ipsec_data;
216 : :
217 : : /** Used for rte_flow of CoreNIC firmware */
218 : : struct nfp_net_priv *priv;
219 : : };
220 : :
221 : : static inline uint32_t
222 : : nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info,
223 : : uint16_t queue)
224 : : {
225 : 0 : return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ *
226 : 0 : (queue & dev_info->qc_idx_mask);
227 : : }
228 : :
229 : : /* Prototypes for common NFP functions */
230 : : int nfp_net_mbox_reconfig(struct nfp_net_hw *hw, uint32_t mbox_cmd);
231 : : int nfp_net_configure(struct rte_eth_dev *dev);
232 : : int nfp_net_common_init(struct rte_pci_device *pci_dev, struct nfp_net_hw *hw);
233 : : void nfp_net_log_device_information(const struct nfp_net_hw *hw);
234 : : void nfp_net_enable_queues(struct rte_eth_dev *dev);
235 : : void nfp_net_disable_queues(struct rte_eth_dev *dev);
236 : : void nfp_net_params_setup(struct nfp_net_hw *hw);
237 : : int nfp_net_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
238 : : int nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
239 : : struct rte_intr_handle *intr_handle);
240 : : uint32_t nfp_check_offloads(struct rte_eth_dev *dev);
241 : : int nfp_net_promisc_enable(struct rte_eth_dev *dev);
242 : : int nfp_net_promisc_disable(struct rte_eth_dev *dev);
243 : : int nfp_net_allmulticast_enable(struct rte_eth_dev *dev);
244 : : int nfp_net_allmulticast_disable(struct rte_eth_dev *dev);
245 : : int nfp_net_link_update_common(struct rte_eth_dev *dev,
246 : : struct nfp_net_hw *hw,
247 : : struct rte_eth_link *link,
248 : : uint32_t link_status);
249 : : int nfp_net_link_update(struct rte_eth_dev *dev,
250 : : __rte_unused int wait_to_complete);
251 : : int nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
252 : : int nfp_net_stats_reset(struct rte_eth_dev *dev);
253 : : uint32_t nfp_net_xstats_size(const struct rte_eth_dev *dev);
254 : : int nfp_net_xstats_get_names(struct rte_eth_dev *dev,
255 : : struct rte_eth_xstat_name *xstats_names,
256 : : unsigned int size __rte_unused);
257 : : int nfp_net_xstats_get(struct rte_eth_dev *dev,
258 : : struct rte_eth_xstat *xstats,
259 : : unsigned int n __rte_unused);
260 : : int nfp_net_xstats_get_names_by_id(struct rte_eth_dev *dev,
261 : : const uint64_t *ids,
262 : : struct rte_eth_xstat_name *xstats_names,
263 : : unsigned int size);
264 : : int nfp_net_xstats_get_by_id(struct rte_eth_dev *dev,
265 : : const uint64_t *ids,
266 : : uint64_t *values,
267 : : unsigned int n);
268 : : int nfp_net_xstats_reset(struct rte_eth_dev *dev);
269 : : int nfp_net_infos_get(struct rte_eth_dev *dev,
270 : : struct rte_eth_dev_info *dev_info);
271 : : const uint32_t *nfp_net_supported_ptypes_get(struct rte_eth_dev *dev,
272 : : size_t *no_of_elements);
273 : : int nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
274 : : int nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
275 : : void nfp_net_params_setup(struct nfp_net_hw *hw);
276 : : void nfp_net_cfg_queue_setup(struct nfp_net_hw *hw);
277 : : void nfp_net_irq_unmask(struct rte_eth_dev *dev);
278 : : void nfp_net_dev_interrupt_handler(void *param);
279 : : void nfp_net_dev_interrupt_delayed_handler(void *param);
280 : : int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
281 : : int nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask);
282 : : int nfp_net_reta_update(struct rte_eth_dev *dev,
283 : : struct rte_eth_rss_reta_entry64 *reta_conf,
284 : : uint16_t reta_size);
285 : : int nfp_net_reta_query(struct rte_eth_dev *dev,
286 : : struct rte_eth_rss_reta_entry64 *reta_conf,
287 : : uint16_t reta_size);
288 : : int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
289 : : struct rte_eth_rss_conf *rss_conf);
290 : : int nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev,
291 : : struct rte_eth_rss_conf *rss_conf);
292 : : int nfp_net_rss_config_default(struct rte_eth_dev *dev);
293 : : void nfp_net_stop_rx_queue(struct rte_eth_dev *dev);
294 : : void nfp_net_close_rx_queue(struct rte_eth_dev *dev);
295 : : void nfp_net_stop_tx_queue(struct rte_eth_dev *dev);
296 : : void nfp_net_close_tx_queue(struct rte_eth_dev *dev);
297 : : int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port);
298 : : void nfp_net_rx_desc_limits(struct nfp_net_hw *hw,
299 : : uint16_t *min_rx_desc,
300 : : uint16_t *max_rx_desc);
301 : : void nfp_net_tx_desc_limits(struct nfp_net_hw *hw,
302 : : uint16_t *min_tx_desc,
303 : : uint16_t *max_tx_desc);
304 : : int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name);
305 : : void nfp_net_cfg_read_version(struct nfp_net_hw *hw);
306 : : int nfp_net_firmware_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size);
307 : : bool nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version);
308 : : struct nfp_net_hw *nfp_net_get_hw(const struct rte_eth_dev *dev);
309 : : int nfp_net_stop(struct rte_eth_dev *dev);
310 : : int nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
311 : : struct rte_eth_fc_conf *fc_conf);
312 : : int nfp_net_flow_ctrl_set(struct rte_eth_dev *dev,
313 : : struct rte_eth_fc_conf *fc_conf);
314 : : void nfp_pf_uninit(struct nfp_pf_dev *pf_dev);
315 : : int nfp_net_fec_get_capability(struct rte_eth_dev *dev,
316 : : struct rte_eth_fec_capa *speed_fec_capa,
317 : : unsigned int num);
318 : : int nfp_net_fec_get(struct rte_eth_dev *dev,
319 : : uint32_t *fec_capa);
320 : : int nfp_net_fec_set(struct rte_eth_dev *dev,
321 : : uint32_t fec_capa);
322 : : void nfp_net_get_fw_version(struct nfp_net_hw *hw,
323 : : uint32_t *fw_version);
324 : :
325 : : #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
326 : : ((struct nfp_app_fw_nic *)app_fw_priv)
327 : :
328 : : #define NFP_PRIV_TO_APP_FW_FLOWER(app_fw_priv)\
329 : : ((struct nfp_app_fw_flower *)app_fw_priv)
330 : :
331 : : #endif /* __NFP_NET_COMMON_H__ */
|