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