Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2014-2021 Netronome Systems, Inc.
3 : : * All rights reserved.
4 : : *
5 : : * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
6 : : */
7 : :
8 : : #include <unistd.h>
9 : :
10 : : #include <eal_firmware.h>
11 : : #include <rte_alarm.h>
12 : : #include <rte_kvargs.h>
13 : : #include <rte_pci.h>
14 : :
15 : : #include "flower/nfp_flower.h"
16 : : #include "nfd3/nfp_nfd3.h"
17 : : #include "nfdk/nfp_nfdk.h"
18 : : #include "nfpcore/nfp_cpp.h"
19 : : #include "nfpcore/nfp_elf.h"
20 : : #include "nfpcore/nfp_hwinfo.h"
21 : : #include "nfpcore/nfp_rtsym.h"
22 : : #include "nfpcore/nfp_nsp.h"
23 : : #include "nfpcore/nfp6000_pcie.h"
24 : : #include "nfpcore/nfp_resource.h"
25 : : #include "nfpcore/nfp_sync.h"
26 : :
27 : : #include "nfp_cpp_bridge.h"
28 : : #include "nfp_ipsec.h"
29 : : #include "nfp_logs.h"
30 : : #include "nfp_net_flow.h"
31 : : #include "nfp_rxtx_vec.h"
32 : :
33 : : /* 64-bit per app capabilities */
34 : : #define NFP_NET_APP_CAP_SP_INDIFF RTE_BIT64(0) /* Indifferent to port speed */
35 : :
36 : : #define NFP_PF_DRIVER_NAME net_nfp_pf
37 : : #define NFP_PF_FORCE_RELOAD_FW "force_reload_fw"
38 : : #define NFP_CPP_SERVICE_ENABLE "cpp_service_enable"
39 : : #define NFP_QUEUE_PER_VF 1
40 : :
41 : : struct nfp_net_init {
42 : : /** Sequential physical port number, only valid for CoreNIC firmware */
43 : : uint8_t idx;
44 : :
45 : : /** Internal port number as seen from NFP */
46 : : uint8_t nfp_idx;
47 : :
48 : : struct nfp_net_hw_priv *hw_priv;
49 : : };
50 : :
51 : : static int
52 : 0 : nfp_devarg_handle_int(const char *key,
53 : : const char *value,
54 : : void *extra_args)
55 : : {
56 : : char *end_ptr;
57 : : uint64_t *num = extra_args;
58 : :
59 [ # # ]: 0 : if (value == NULL)
60 : : return -EPERM;
61 : :
62 : 0 : *num = strtoul(value, &end_ptr, 10);
63 [ # # ]: 0 : if (*num == ULONG_MAX) {
64 : 0 : PMD_DRV_LOG(ERR, "%s: '%s' is not a valid param.", key, value);
65 : 0 : return -ERANGE;
66 [ # # ]: 0 : } else if (value == end_ptr) {
67 : 0 : return -EPERM;
68 : : }
69 : :
70 : : return 0;
71 : : }
72 : :
73 : : static int
74 : 0 : nfp_devarg_parse_bool_para(struct rte_kvargs *kvlist,
75 : : const char *key_match,
76 : : bool *value_ret)
77 : : {
78 : : int ret;
79 : : uint32_t count;
80 : : uint64_t value;
81 : :
82 : 0 : count = rte_kvargs_count(kvlist, key_match);
83 [ # # ]: 0 : if (count == 0)
84 : : return 0;
85 : :
86 [ # # ]: 0 : if (count > 1) {
87 : 0 : PMD_DRV_LOG(ERR, "Too much bool arguments: %s.", key_match);
88 : 0 : return -EINVAL;
89 : : }
90 : :
91 : 0 : ret = rte_kvargs_process(kvlist, key_match, &nfp_devarg_handle_int, &value);
92 [ # # ]: 0 : if (ret != 0)
93 : : return -EINVAL;
94 : :
95 [ # # ]: 0 : if (value == 1) {
96 : 0 : *value_ret = true;
97 [ # # ]: 0 : } else if (value == 0) {
98 : 0 : *value_ret = false;
99 : : } else {
100 : 0 : PMD_DRV_LOG(ERR, "The param does not work, the format is %s=0/1.",
101 : : key_match);
102 : 0 : return -EINVAL;
103 : : }
104 : :
105 : : return 0;
106 : : }
107 : :
108 : : static int
109 : 0 : nfp_devargs_parse(struct nfp_devargs *nfp_devargs_param,
110 : : const struct rte_devargs *devargs)
111 : : {
112 : : int ret;
113 : : struct rte_kvargs *kvlist;
114 : :
115 [ # # ]: 0 : if (devargs == NULL)
116 : : return 0;
117 : :
118 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
119 [ # # ]: 0 : if (kvlist == NULL)
120 : : return -EINVAL;
121 : :
122 : 0 : ret = nfp_devarg_parse_bool_para(kvlist, NFP_PF_FORCE_RELOAD_FW,
123 : : &nfp_devargs_param->force_reload_fw);
124 [ # # ]: 0 : if (ret != 0)
125 : 0 : goto exit;
126 : :
127 : 0 : ret = nfp_devarg_parse_bool_para(kvlist, NFP_CPP_SERVICE_ENABLE,
128 : : &nfp_devargs_param->cpp_service_enable);
129 [ # # ]: 0 : if (ret != 0)
130 : 0 : goto exit;
131 : :
132 : 0 : exit:
133 : 0 : rte_kvargs_free(kvlist);
134 : :
135 : 0 : return ret;
136 : : }
137 : :
138 : : static void
139 : : nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic,
140 : : uint16_t port,
141 : : struct nfp_net_hw_priv *hw_priv)
142 : : {
143 : : struct nfp_net_hw *hw;
144 : : struct nfp_eth_table *nfp_eth_table;
145 : :
146 : : /* Grab a pointer to the correct physical port */
147 : 0 : hw = app_fw_nic->ports[port];
148 : :
149 : 0 : nfp_eth_table = hw_priv->pf_dev->nfp_eth_table;
150 : :
151 : : rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->super.mac_addr);
152 : : }
153 : :
154 : : static uint32_t
155 : 0 : nfp_net_speed_bitmap2speed(uint32_t speeds_bitmap)
156 : : {
157 [ # # # # : 0 : switch (speeds_bitmap) {
# # # # #
# # # # #
# # ]
158 : : case RTE_ETH_LINK_SPEED_10M_HD:
159 : : return RTE_ETH_SPEED_NUM_10M;
160 : : case RTE_ETH_LINK_SPEED_10M:
161 : : return RTE_ETH_SPEED_NUM_10M;
162 : 0 : case RTE_ETH_LINK_SPEED_100M_HD:
163 : 0 : return RTE_ETH_SPEED_NUM_100M;
164 : 0 : case RTE_ETH_LINK_SPEED_100M:
165 : 0 : return RTE_ETH_SPEED_NUM_100M;
166 : 0 : case RTE_ETH_LINK_SPEED_1G:
167 : 0 : return RTE_ETH_SPEED_NUM_1G;
168 : 0 : case RTE_ETH_LINK_SPEED_2_5G:
169 : 0 : return RTE_ETH_SPEED_NUM_2_5G;
170 : 0 : case RTE_ETH_LINK_SPEED_5G:
171 : 0 : return RTE_ETH_SPEED_NUM_5G;
172 : 0 : case RTE_ETH_LINK_SPEED_10G:
173 : 0 : return RTE_ETH_SPEED_NUM_10G;
174 : 0 : case RTE_ETH_LINK_SPEED_20G:
175 : 0 : return RTE_ETH_SPEED_NUM_20G;
176 : 0 : case RTE_ETH_LINK_SPEED_25G:
177 : 0 : return RTE_ETH_SPEED_NUM_25G;
178 : 0 : case RTE_ETH_LINK_SPEED_40G:
179 : 0 : return RTE_ETH_SPEED_NUM_40G;
180 : 0 : case RTE_ETH_LINK_SPEED_50G:
181 : 0 : return RTE_ETH_SPEED_NUM_50G;
182 : 0 : case RTE_ETH_LINK_SPEED_56G:
183 : 0 : return RTE_ETH_SPEED_NUM_56G;
184 : 0 : case RTE_ETH_LINK_SPEED_100G:
185 : 0 : return RTE_ETH_SPEED_NUM_100G;
186 : 0 : case RTE_ETH_LINK_SPEED_200G:
187 : 0 : return RTE_ETH_SPEED_NUM_200G;
188 : 0 : case RTE_ETH_LINK_SPEED_400G:
189 : 0 : return RTE_ETH_SPEED_NUM_400G;
190 : 0 : default:
191 : 0 : return RTE_ETH_SPEED_NUM_NONE;
192 : : }
193 : : }
194 : :
195 : : static int
196 : 0 : nfp_net_nfp4000_speed_configure_check(uint16_t port_id,
197 : : uint32_t configure_speed,
198 : : struct nfp_eth_table *nfp_eth_table)
199 : : {
200 [ # # # ]: 0 : switch (port_id) {
201 : 0 : case 0:
202 [ # # ]: 0 : if (configure_speed == RTE_ETH_SPEED_NUM_25G &&
203 [ # # ]: 0 : nfp_eth_table->ports[1].speed == RTE_ETH_SPEED_NUM_10G) {
204 : 0 : PMD_DRV_LOG(ERR, "The speed configuration is not supported for NFP4000.");
205 : 0 : return -ENOTSUP;
206 : : }
207 : : break;
208 : 0 : case 1:
209 [ # # ]: 0 : if (configure_speed == RTE_ETH_SPEED_NUM_10G &&
210 [ # # ]: 0 : nfp_eth_table->ports[0].speed == RTE_ETH_SPEED_NUM_25G) {
211 : 0 : PMD_DRV_LOG(ERR, "The speed configuration is not supported for NFP4000.");
212 : 0 : return -ENOTSUP;
213 : : }
214 : : break;
215 : 0 : default:
216 : 0 : PMD_DRV_LOG(ERR, "The port id is invalid.");
217 : 0 : return -EINVAL;
218 : : }
219 : :
220 : : return 0;
221 : : }
222 : :
223 : : static int
224 : 0 : nfp_net_speed_autoneg_set(struct nfp_net_hw_priv *hw_priv,
225 : : struct nfp_eth_table_port *eth_port)
226 : : {
227 : : int ret;
228 : : struct nfp_nsp *nsp;
229 : :
230 : 0 : nsp = nfp_eth_config_start(hw_priv->pf_dev->cpp, eth_port->index);
231 [ # # ]: 0 : if (nsp == NULL) {
232 : 0 : PMD_DRV_LOG(ERR, "Could not get NSP.");
233 : 0 : return -EIO;
234 : : }
235 : :
236 : 0 : ret = nfp_eth_set_aneg(nsp, NFP_ANEG_AUTO);
237 [ # # ]: 0 : if (ret != 0) {
238 : 0 : PMD_DRV_LOG(ERR, "Failed to set ANEG enable.");
239 : 0 : nfp_eth_config_cleanup_end(nsp);
240 : 0 : return ret;
241 : : }
242 : :
243 : 0 : return nfp_eth_config_commit_end(nsp);
244 : : }
245 : :
246 : : static int
247 : 0 : nfp_net_speed_fixed_set(struct nfp_net_hw_priv *hw_priv,
248 : : struct nfp_eth_table_port *eth_port,
249 : : uint32_t configure_speed)
250 : : {
251 : : int ret;
252 : : struct nfp_nsp *nsp;
253 : :
254 : 0 : nsp = nfp_eth_config_start(hw_priv->pf_dev->cpp, eth_port->index);
255 [ # # ]: 0 : if (nsp == NULL) {
256 : 0 : PMD_DRV_LOG(ERR, "Could not get NSP.");
257 : 0 : return -EIO;
258 : : }
259 : :
260 : 0 : ret = nfp_eth_set_aneg(nsp, NFP_ANEG_DISABLED);
261 [ # # ]: 0 : if (ret != 0) {
262 : 0 : PMD_DRV_LOG(ERR, "Failed to set ANEG disable.");
263 : 0 : goto config_cleanup;
264 : : }
265 : :
266 : 0 : ret = nfp_eth_set_speed(nsp, configure_speed);
267 [ # # ]: 0 : if (ret != 0) {
268 : 0 : PMD_DRV_LOG(ERR, "Failed to set speed.");
269 : 0 : goto config_cleanup;
270 : : }
271 : :
272 : 0 : return nfp_eth_config_commit_end(nsp);
273 : :
274 : 0 : config_cleanup:
275 : 0 : nfp_eth_config_cleanup_end(nsp);
276 : :
277 : 0 : return ret;
278 : : }
279 : :
280 : : static int
281 : 0 : nfp_net_speed_configure(struct rte_eth_dev *dev)
282 : : {
283 : : int ret;
284 : : uint8_t idx;
285 : : uint32_t speed_capa;
286 : : uint32_t link_speeds;
287 : : uint32_t configure_speed;
288 : : struct nfp_eth_table_port *eth_port;
289 : : struct nfp_eth_table *nfp_eth_table;
290 : 0 : struct nfp_net_hw *net_hw = dev->data->dev_private;
291 : 0 : struct nfp_net_hw_priv *hw_priv = dev->process_private;
292 : :
293 : 0 : idx = nfp_net_get_idx(dev);
294 : 0 : nfp_eth_table = hw_priv->pf_dev->nfp_eth_table;
295 : 0 : eth_port = &nfp_eth_table->ports[idx];
296 : :
297 : 0 : speed_capa = hw_priv->pf_dev->speed_capa;
298 [ # # ]: 0 : if (speed_capa == 0) {
299 : 0 : PMD_DRV_LOG(ERR, "Speed_capa is invalid.");
300 : 0 : return -EINVAL;
301 : : }
302 : :
303 : 0 : link_speeds = dev->data->dev_conf.link_speeds;
304 : 0 : configure_speed = nfp_net_speed_bitmap2speed(speed_capa & link_speeds);
305 : 0 : if (configure_speed == RTE_ETH_SPEED_NUM_NONE &&
306 [ # # ]: 0 : link_speeds != RTE_ETH_LINK_SPEED_AUTONEG) {
307 : 0 : PMD_DRV_LOG(ERR, "Configured speed is invalid.");
308 : 0 : return -EINVAL;
309 : : }
310 : :
311 : : /* NFP4000 does not allow the port 0 25Gbps and port 1 10Gbps at the same time. */
312 [ # # ]: 0 : if (net_hw->device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) {
313 : 0 : ret = nfp_net_nfp4000_speed_configure_check(idx,
314 : : configure_speed, nfp_eth_table);
315 [ # # ]: 0 : if (ret != 0) {
316 : 0 : PMD_DRV_LOG(ERR, "Failed to configure speed for NFP4000.");
317 : 0 : return ret;
318 : : }
319 : : }
320 : :
321 [ # # ]: 0 : if (configure_speed == RTE_ETH_LINK_SPEED_AUTONEG) {
322 [ # # ]: 0 : if (!eth_port->supp_aneg)
323 : : return 0;
324 : :
325 [ # # ]: 0 : if (eth_port->aneg == NFP_ANEG_AUTO)
326 : : return 0;
327 : :
328 : 0 : ret = nfp_net_speed_autoneg_set(hw_priv, eth_port);
329 [ # # ]: 0 : if (ret != 0) {
330 : 0 : PMD_DRV_LOG(ERR, "Failed to set speed autoneg.");
331 : 0 : return ret;
332 : : }
333 : : } else {
334 [ # # # # ]: 0 : if (eth_port->aneg == NFP_ANEG_DISABLED && configure_speed == eth_port->speed)
335 : : return 0;
336 : :
337 : 0 : ret = nfp_net_speed_fixed_set(hw_priv, eth_port, configure_speed);
338 [ # # ]: 0 : if (ret != 0) {
339 : 0 : PMD_DRV_LOG(ERR, "Failed to set speed fixed.");
340 : 0 : return ret;
341 : : }
342 : : }
343 : :
344 : 0 : hw_priv->pf_dev->speed_updated = true;
345 : :
346 : 0 : return 0;
347 : : }
348 : :
349 : : static int
350 : 0 : nfp_net_start(struct rte_eth_dev *dev)
351 : : {
352 : : int ret;
353 : : uint16_t i;
354 : : struct nfp_hw *hw;
355 : : uint32_t new_ctrl;
356 : : uint32_t update = 0;
357 : : uint32_t cap_extend;
358 : : uint32_t intr_vector;
359 : : uint32_t ctrl_extend = 0;
360 : : struct nfp_net_hw *net_hw;
361 : : struct nfp_pf_dev *pf_dev;
362 : : struct rte_eth_rxmode *rxmode;
363 : : struct rte_eth_txmode *txmode;
364 : : struct nfp_net_hw_priv *hw_priv;
365 : : struct nfp_app_fw_nic *app_fw_nic;
366 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
367 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
368 : :
369 : 0 : net_hw = dev->data->dev_private;
370 : 0 : hw_priv = dev->process_private;
371 : 0 : pf_dev = hw_priv->pf_dev;
372 : 0 : app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv);
373 : 0 : hw = &net_hw->super;
374 : :
375 : : /* Disabling queues just in case... */
376 : 0 : nfp_net_disable_queues(dev);
377 : :
378 : : /* Enabling the required queues in the device */
379 : 0 : nfp_net_enable_queues(dev);
380 : :
381 : : /* Configure the port speed and the auto-negotiation mode. */
382 : 0 : ret = nfp_net_speed_configure(dev);
383 [ # # ]: 0 : if (ret < 0) {
384 : 0 : PMD_DRV_LOG(ERR, "Failed to set the speed and auto-negotiation mode.");
385 : 0 : return ret;
386 : : }
387 : :
388 : : /* Check and configure queue intr-vector mapping */
389 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0) {
390 [ # # ]: 0 : if (app_fw_nic->multiport) {
391 : 0 : PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
392 : : "with NFP multiport PF.");
393 : 0 : return -EINVAL;
394 : : }
395 : :
396 [ # # ]: 0 : if (rte_intr_type_get(intr_handle) == RTE_INTR_HANDLE_UIO) {
397 : : /*
398 : : * Better not to share LSC with RX interrupts.
399 : : * Unregistering LSC interrupt handler.
400 : : */
401 : 0 : rte_intr_callback_unregister(intr_handle,
402 : : nfp_net_dev_interrupt_handler, (void *)dev);
403 : :
404 [ # # ]: 0 : if (dev->data->nb_rx_queues > 1) {
405 : 0 : PMD_INIT_LOG(ERR, "PMD rx interrupt only "
406 : : "supports 1 queue with UIO.");
407 : 0 : return -EIO;
408 : : }
409 : : }
410 : :
411 : 0 : intr_vector = dev->data->nb_rx_queues;
412 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector) != 0)
413 : : return -1;
414 : :
415 : 0 : nfp_configure_rx_interrupt(dev, intr_handle);
416 : : update = NFP_NET_CFG_UPDATE_MSIX;
417 : : }
418 : :
419 : : /* Checking MTU set */
420 [ # # ]: 0 : if (dev->data->mtu > net_hw->flbufsz) {
421 : 0 : PMD_INIT_LOG(ERR, "MTU (%u) can not be larger than the current NFP_FRAME_SIZE (%u).",
422 : : dev->data->mtu, net_hw->flbufsz);
423 : 0 : return -ERANGE;
424 : : }
425 : :
426 : 0 : rte_intr_enable(intr_handle);
427 : :
428 : 0 : new_ctrl = nfp_check_offloads(dev);
429 : :
430 : : /* Writing configuration parameters in the device */
431 : 0 : nfp_net_params_setup(net_hw);
432 : :
433 : 0 : rxmode = &dev->data->dev_conf.rxmode;
434 [ # # ]: 0 : if ((rxmode->offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) != 0) {
435 : 0 : nfp_net_rss_config_default(dev);
436 : 0 : update |= NFP_NET_CFG_UPDATE_RSS;
437 [ # # ]: 0 : new_ctrl |= nfp_net_cfg_ctrl_rss(hw->cap);
438 : : }
439 : :
440 : : /* Enable device */
441 : 0 : new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
442 : :
443 : 0 : update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
444 : :
445 : 0 : txmode = &dev->data->dev_conf.txmode;
446 : :
447 [ # # ]: 0 : if ((hw->cap & NFP_NET_CFG_CTRL_RINGCFG) != 0)
448 : 0 : new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
449 : :
450 [ # # ]: 0 : if ((hw->cap & NFP_NET_CFG_CTRL_TXRWB) != 0)
451 : 0 : new_ctrl |= NFP_NET_CFG_CTRL_TXRWB;
452 : :
453 [ # # ]: 0 : if (nfp_reconfig(hw, new_ctrl, update) != 0)
454 : : return -EIO;
455 : :
456 : 0 : hw->ctrl = new_ctrl;
457 : :
458 : : /* Enable packet type offload by extend ctrl word1. */
459 : 0 : cap_extend = hw->cap_ext;
460 [ # # ]: 0 : if ((cap_extend & NFP_NET_CFG_CTRL_PKT_TYPE) != 0)
461 : : ctrl_extend = NFP_NET_CFG_CTRL_PKT_TYPE;
462 : :
463 [ # # ]: 0 : if ((rxmode->offloads & RTE_ETH_RX_OFFLOAD_SECURITY) != 0 ||
464 [ # # ]: 0 : (txmode->offloads & RTE_ETH_TX_OFFLOAD_SECURITY) != 0) {
465 [ # # ]: 0 : if ((cap_extend & NFP_NET_CFG_CTRL_IPSEC) != 0)
466 : 0 : ctrl_extend |= NFP_NET_CFG_CTRL_IPSEC |
467 : : NFP_NET_CFG_CTRL_IPSEC_SM_LOOKUP |
468 : : NFP_NET_CFG_CTRL_IPSEC_LM_LOOKUP;
469 : : }
470 : :
471 : : /* Enable flow steer by extend ctrl word1. */
472 [ # # ]: 0 : if ((cap_extend & NFP_NET_CFG_CTRL_FLOW_STEER) != 0)
473 : 0 : ctrl_extend |= NFP_NET_CFG_CTRL_FLOW_STEER;
474 : :
475 [ # # # # ]: 0 : if ((cap_extend & NFP_NET_CFG_CTRL_MULTI_PF) != 0 && pf_dev->multi_pf.enabled)
476 : 0 : ctrl_extend |= NFP_NET_CFG_CTRL_MULTI_PF;
477 : :
478 : : update = NFP_NET_CFG_UPDATE_GEN;
479 [ # # ]: 0 : if (nfp_ext_reconfig(hw, ctrl_extend, update) != 0)
480 : : return -EIO;
481 : :
482 : 0 : hw->ctrl_ext = ctrl_extend;
483 : :
484 : : /*
485 : : * Allocating rte mbufs for configured rx queues.
486 : : * This requires queues being enabled before.
487 : : */
488 [ # # ]: 0 : if (nfp_net_rx_freelist_setup(dev) != 0) {
489 : : ret = -ENOMEM;
490 : 0 : goto error;
491 : : }
492 : :
493 : : /* Configure the physical port up */
494 : 0 : ret = nfp_eth_set_configured(pf_dev->cpp, net_hw->nfp_idx, 1);
495 [ # # ]: 0 : if (ret < 0)
496 : 0 : goto error;
497 : :
498 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
499 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
500 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
501 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
502 : :
503 : : return 0;
504 : :
505 : 0 : error:
506 : : /*
507 : : * An error returned by this function should mean the app
508 : : * exiting and then the system releasing all the memory
509 : : * allocated even memory coming from hugepages.
510 : : *
511 : : * The device could be enabled at this point with some queues
512 : : * ready for getting packets. This is true if the call to
513 : : * nfp_net_rx_freelist_setup() succeeds for some queues but
514 : : * fails for subsequent queues.
515 : : *
516 : : * This should make the app exiting but better if we tell the
517 : : * device first.
518 : : */
519 : 0 : nfp_net_disable_queues(dev);
520 : :
521 : 0 : return ret;
522 : : }
523 : :
524 : : /* Set the link up. */
525 : : static int
526 : 0 : nfp_net_set_link_up(struct rte_eth_dev *dev)
527 : : {
528 : : int ret;
529 : : struct nfp_net_hw *hw;
530 : : struct nfp_net_hw_priv *hw_priv;
531 : :
532 : 0 : hw = dev->data->dev_private;
533 : 0 : hw_priv = dev->process_private;
534 : :
535 : 0 : ret = nfp_eth_set_configured(hw_priv->pf_dev->cpp, hw->nfp_idx, 1);
536 : : if (ret < 0)
537 : : return ret;
538 : :
539 : : return 0;
540 : : }
541 : :
542 : : /* Set the link down. */
543 : : static int
544 : 0 : nfp_net_set_link_down(struct rte_eth_dev *dev)
545 : : {
546 : : int ret;
547 : : struct nfp_net_hw *hw;
548 : : struct nfp_net_hw_priv *hw_priv;
549 : :
550 : 0 : hw = dev->data->dev_private;
551 : 0 : hw_priv = dev->process_private;
552 : :
553 : 0 : ret = nfp_eth_set_configured(hw_priv->pf_dev->cpp, hw->nfp_idx, 0);
554 : : if (ret < 0)
555 : : return ret;
556 : :
557 : : return 0;
558 : : }
559 : :
560 : : static void
561 : 0 : nfp_net_beat_timer(void *arg)
562 : : {
563 : : uint64_t cur_sec;
564 : : struct nfp_multi_pf *multi_pf = arg;
565 : :
566 : : cur_sec = rte_rdtsc();
567 : 0 : nn_writeq(cur_sec, multi_pf->beat_addr + NFP_BEAT_OFFSET(multi_pf->function_id));
568 : :
569 : : /* Beat once per second. */
570 [ # # ]: 0 : if (rte_eal_alarm_set(1000 * 1000, nfp_net_beat_timer,
571 : : (void *)multi_pf) < 0) {
572 : 0 : PMD_DRV_LOG(ERR, "Error setting alarm.");
573 : : }
574 : 0 : }
575 : :
576 : : static int
577 : 0 : nfp_net_keepalive_init(struct nfp_cpp *cpp,
578 : : struct nfp_multi_pf *multi_pf)
579 : : {
580 : : uint8_t *base;
581 : : uint64_t addr;
582 : : uint32_t size;
583 : : uint32_t cpp_id;
584 : : struct nfp_resource *res;
585 : :
586 : 0 : res = nfp_resource_acquire(cpp, NFP_RESOURCE_KEEPALIVE);
587 [ # # ]: 0 : if (res == NULL)
588 : : return -EIO;
589 : :
590 : 0 : cpp_id = nfp_resource_cpp_id(res);
591 : 0 : addr = nfp_resource_address(res);
592 : 0 : size = nfp_resource_size(res);
593 : :
594 : 0 : nfp_resource_release(res);
595 : :
596 : : /* Allocate a fixed area for keepalive. */
597 : 0 : base = nfp_cpp_map_area(cpp, cpp_id, addr, size, &multi_pf->beat_area);
598 [ # # ]: 0 : if (base == NULL) {
599 : 0 : PMD_DRV_LOG(ERR, "Failed to map area for keepalive.");
600 : 0 : return -EIO;
601 : : }
602 : :
603 : 0 : multi_pf->beat_addr = base;
604 : :
605 : 0 : return 0;
606 : : }
607 : :
608 : : static void
609 : : nfp_net_keepalive_uninit(struct nfp_multi_pf *multi_pf)
610 : : {
611 : 0 : nfp_cpp_area_release_free(multi_pf->beat_area);
612 : 0 : }
613 : :
614 : : static int
615 : 0 : nfp_net_keepalive_start(struct nfp_multi_pf *multi_pf)
616 : : {
617 [ # # ]: 0 : if (rte_eal_alarm_set(1000 * 1000, nfp_net_beat_timer,
618 : : (void *)multi_pf) < 0) {
619 : 0 : PMD_DRV_LOG(ERR, "Error setting alarm.");
620 : 0 : return -EIO;
621 : : }
622 : :
623 : : return 0;
624 : : }
625 : :
626 : : static void
627 : : nfp_net_keepalive_clear(uint8_t *beat_addr,
628 : : uint8_t function_id)
629 : : {
630 : 0 : nn_writeq(0, beat_addr + NFP_BEAT_OFFSET(function_id));
631 : 0 : }
632 : :
633 : : static void
634 : : nfp_net_keepalive_clear_others(const struct nfp_dev_info *dev_info,
635 : : struct nfp_multi_pf *multi_pf)
636 : : {
637 : : uint8_t port_num;
638 : :
639 [ # # ]: 0 : for (port_num = 0; port_num < dev_info->pf_num_per_unit; port_num++) {
640 [ # # ]: 0 : if (port_num == multi_pf->function_id)
641 : 0 : continue;
642 : :
643 : 0 : nfp_net_keepalive_clear(multi_pf->beat_addr, port_num);
644 : : }
645 : : }
646 : :
647 : : static void
648 : : nfp_net_keepalive_stop(struct nfp_multi_pf *multi_pf)
649 : : {
650 : : /* Cancel keepalive for multiple PF setup */
651 : 0 : rte_eal_alarm_cancel(nfp_net_beat_timer, (void *)multi_pf);
652 : 0 : }
653 : :
654 : : static int
655 : 0 : nfp_net_uninit(struct rte_eth_dev *eth_dev)
656 : : {
657 : : struct nfp_net_hw *net_hw;
658 : : struct nfp_net_hw_priv *hw_priv;
659 : :
660 : 0 : net_hw = eth_dev->data->dev_private;
661 : 0 : hw_priv = eth_dev->process_private;
662 : :
663 [ # # ]: 0 : if ((net_hw->super.cap_ext & NFP_NET_CFG_CTRL_FLOW_STEER) != 0)
664 : 0 : nfp_net_flow_priv_uninit(hw_priv->pf_dev, net_hw->idx);
665 : :
666 : 0 : rte_free(net_hw->eth_xstats_base);
667 [ # # ]: 0 : if ((net_hw->super.cap & NFP_NET_CFG_CTRL_TXRWB) != 0)
668 : 0 : nfp_net_txrwb_free(eth_dev);
669 : 0 : nfp_ipsec_uninit(eth_dev);
670 : :
671 : 0 : return 0;
672 : : }
673 : :
674 : : static void
675 : : nfp_cleanup_port_app_fw_nic(struct nfp_pf_dev *pf_dev,
676 : : uint8_t id,
677 : : struct rte_eth_dev *eth_dev)
678 : : {
679 : : struct nfp_app_fw_nic *app_fw_nic;
680 : :
681 : 0 : app_fw_nic = pf_dev->app_fw_priv;
682 : 0 : if (app_fw_nic->ports[id] != NULL) {
683 : 0 : nfp_net_uninit(eth_dev);
684 : 0 : app_fw_nic->ports[id] = NULL;
685 : : }
686 : : }
687 : :
688 : : static void
689 : : nfp_uninit_app_fw_nic(struct nfp_pf_dev *pf_dev)
690 : : {
691 : 0 : nfp_cpp_area_release_free(pf_dev->ctrl_area);
692 : 0 : rte_free(pf_dev->app_fw_priv);
693 : : }
694 : :
695 : : static void
696 : 0 : nfp_net_vf_config_uninit(struct nfp_pf_dev *pf_dev)
697 : : {
698 [ # # ]: 0 : if (pf_dev->sriov_vf == 0)
699 : : return;
700 : :
701 : 0 : nfp_cpp_area_release_free(pf_dev->vf_cfg_tbl_area);
702 : 0 : nfp_cpp_area_release_free(pf_dev->vf_area);
703 : : }
704 : :
705 : : void
706 : 0 : nfp_pf_uninit(struct nfp_net_hw_priv *hw_priv)
707 : : {
708 : 0 : struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
709 : :
710 [ # # ]: 0 : if (pf_dev->devargs.cpp_service_enable)
711 : 0 : nfp_disable_cpp_service(pf_dev);
712 : 0 : nfp_net_vf_config_uninit(pf_dev);
713 : 0 : nfp_cpp_area_release_free(pf_dev->mac_stats_area);
714 : 0 : nfp_cpp_area_release_free(pf_dev->qc_area);
715 : 0 : free(pf_dev->sym_tbl);
716 [ # # ]: 0 : if (pf_dev->multi_pf.enabled) {
717 : 0 : nfp_net_keepalive_stop(&pf_dev->multi_pf);
718 : 0 : nfp_net_keepalive_clear(pf_dev->multi_pf.beat_addr, pf_dev->multi_pf.function_id);
719 : : nfp_net_keepalive_uninit(&pf_dev->multi_pf);
720 : : }
721 : 0 : free(pf_dev->nfp_eth_table);
722 : 0 : free(pf_dev->hwinfo);
723 : 0 : nfp_cpp_free(pf_dev->cpp);
724 : 0 : nfp_sync_free(pf_dev->sync);
725 : 0 : rte_free(pf_dev);
726 : 0 : rte_free(hw_priv);
727 : 0 : }
728 : :
729 : : static int
730 : 0 : nfp_pf_secondary_uninit(struct nfp_net_hw_priv *hw_priv)
731 : : {
732 : 0 : struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
733 : :
734 : 0 : free(pf_dev->sym_tbl);
735 : 0 : nfp_cpp_free(pf_dev->cpp);
736 : 0 : nfp_sync_free(pf_dev->sync);
737 : 0 : rte_free(pf_dev);
738 : 0 : rte_free(hw_priv);
739 : :
740 : 0 : return 0;
741 : : }
742 : :
743 : : /* Reset and stop device. The device can not be restarted. */
744 : : static int
745 : 0 : nfp_net_close(struct rte_eth_dev *dev)
746 : : {
747 : : uint8_t i;
748 : : uint8_t id;
749 : : struct nfp_net_hw *hw;
750 : : struct nfp_pf_dev *pf_dev;
751 : : struct rte_pci_device *pci_dev;
752 : : struct nfp_net_hw_priv *hw_priv;
753 : : struct nfp_app_fw_nic *app_fw_nic;
754 : :
755 : 0 : hw_priv = dev->process_private;
756 : :
757 : : /*
758 : : * In secondary process, a released eth device can be found by its name
759 : : * in shared memory.
760 : : * If the state of the eth device is RTE_ETH_DEV_UNUSED, it means the
761 : : * eth device has been released.
762 : : */
763 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
764 [ # # ]: 0 : if (dev->state == RTE_ETH_DEV_UNUSED)
765 : : return 0;
766 : :
767 : 0 : nfp_pf_secondary_uninit(hw_priv);
768 : 0 : return 0;
769 : : }
770 : :
771 : 0 : hw = dev->data->dev_private;
772 : 0 : pf_dev = hw_priv->pf_dev;
773 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(dev);
774 : 0 : app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv);
775 : :
776 : : /*
777 : : * We assume that the DPDK application is stopping all the
778 : : * threads/queues before calling the device close function.
779 : : */
780 : 0 : nfp_net_disable_queues(dev);
781 : :
782 : : /* Clear queues */
783 : 0 : nfp_net_close_tx_queue(dev);
784 : 0 : nfp_net_close_rx_queue(dev);
785 : :
786 : : /* Cancel possible impending LSC work here before releasing the port */
787 : 0 : rte_eal_alarm_cancel(nfp_net_dev_interrupt_delayed_handler, (void *)dev);
788 : :
789 : : /* Only free PF resources after all physical ports have been closed */
790 : : /* Mark this port as unused and free device priv resources */
791 : : nn_cfg_writeb(&hw->super, NFP_NET_CFG_LSC, 0xff);
792 : :
793 [ # # ]: 0 : if (pf_dev->app_fw_id != NFP_APP_FW_CORE_NIC)
794 : : return -EINVAL;
795 : :
796 [ # # ]: 0 : nfp_cleanup_port_app_fw_nic(pf_dev, hw->idx, dev);
797 : :
798 [ # # ]: 0 : for (i = 0; i < pf_dev->total_phyports; i++) {
799 : 0 : id = nfp_function_id_get(pf_dev, i);
800 : :
801 : : /* Check to see if ports are still in use */
802 [ # # ]: 0 : if (app_fw_nic->ports[id] != NULL)
803 : : return 0;
804 : : }
805 : :
806 : : /* Enable in nfp_net_start() */
807 : 0 : rte_intr_disable(pci_dev->intr_handle);
808 : :
809 : : /* Register in nfp_net_init() */
810 : 0 : rte_intr_callback_unregister(pci_dev->intr_handle,
811 : : nfp_net_dev_interrupt_handler, (void *)dev);
812 : :
813 : : nfp_uninit_app_fw_nic(pf_dev);
814 : 0 : nfp_pf_uninit(hw_priv);
815 : :
816 : 0 : return 0;
817 : : }
818 : :
819 : : static int
820 : : nfp_net_find_vxlan_idx(struct nfp_net_hw *hw,
821 : : uint16_t port,
822 : : uint32_t *idx)
823 : : {
824 : : uint32_t i;
825 : : int free_idx = -1;
826 : :
827 [ # # # # ]: 0 : for (i = 0; i < NFP_NET_N_VXLAN_PORTS; i++) {
828 [ # # # # ]: 0 : if (hw->vxlan_ports[i] == port) {
829 : 0 : free_idx = i;
830 : 0 : break;
831 : : }
832 : :
833 [ # # # # ]: 0 : if (hw->vxlan_usecnt[i] == 0) {
834 : 0 : free_idx = i;
835 : 0 : break;
836 : : }
837 : : }
838 : :
839 [ # # # # ]: 0 : if (free_idx == -1)
840 : : return -EINVAL;
841 : :
842 : 0 : *idx = free_idx;
843 : :
844 : : return 0;
845 : : }
846 : :
847 : : static int
848 : 0 : nfp_udp_tunnel_port_add(struct rte_eth_dev *dev,
849 : : struct rte_eth_udp_tunnel *tunnel_udp)
850 : : {
851 : : int ret;
852 : : uint32_t idx;
853 : : uint32_t ctrl;
854 : : struct nfp_hw *hw;
855 : : uint16_t vxlan_port;
856 : : struct nfp_net_hw *net_hw;
857 : : enum rte_eth_tunnel_type tnl_type;
858 : :
859 : 0 : net_hw = dev->data->dev_private;
860 : 0 : vxlan_port = tunnel_udp->udp_port;
861 : 0 : tnl_type = tunnel_udp->prot_type;
862 : :
863 [ # # ]: 0 : if (tnl_type != RTE_ETH_TUNNEL_TYPE_VXLAN) {
864 : 0 : PMD_DRV_LOG(ERR, "Not VXLAN tunnel.");
865 : 0 : return -ENOTSUP;
866 : : }
867 : :
868 : 0 : ret = nfp_net_find_vxlan_idx(net_hw, vxlan_port, &idx);
869 : : if (ret != 0) {
870 : 0 : PMD_DRV_LOG(ERR, "Failed find valid vxlan idx.");
871 : 0 : return -EINVAL;
872 : : }
873 : :
874 [ # # ]: 0 : if (net_hw->vxlan_usecnt[idx] == 0) {
875 : : hw = &net_hw->super;
876 : 0 : ctrl = hw->ctrl | NFP_NET_CFG_CTRL_VXLAN;
877 : :
878 : 0 : ret = nfp_net_set_vxlan_port(net_hw, idx, vxlan_port, ctrl);
879 [ # # ]: 0 : if (ret != 0) {
880 : 0 : PMD_DRV_LOG(ERR, "Failed set vxlan port.");
881 : 0 : return -EINVAL;
882 : : }
883 : :
884 : 0 : hw->ctrl = ctrl;
885 : : }
886 : :
887 : 0 : net_hw->vxlan_usecnt[idx]++;
888 : :
889 : 0 : return 0;
890 : : }
891 : :
892 : : static int
893 : 0 : nfp_udp_tunnel_port_del(struct rte_eth_dev *dev,
894 : : struct rte_eth_udp_tunnel *tunnel_udp)
895 : : {
896 : : int ret;
897 : : uint32_t idx;
898 : : uint32_t ctrl;
899 : : struct nfp_hw *hw;
900 : : uint16_t vxlan_port;
901 : : struct nfp_net_hw *net_hw;
902 : : enum rte_eth_tunnel_type tnl_type;
903 : :
904 : 0 : net_hw = dev->data->dev_private;
905 : 0 : vxlan_port = tunnel_udp->udp_port;
906 : 0 : tnl_type = tunnel_udp->prot_type;
907 : :
908 [ # # ]: 0 : if (tnl_type != RTE_ETH_TUNNEL_TYPE_VXLAN) {
909 : 0 : PMD_DRV_LOG(ERR, "Not VXLAN tunnel.");
910 : 0 : return -ENOTSUP;
911 : : }
912 : :
913 : : ret = nfp_net_find_vxlan_idx(net_hw, vxlan_port, &idx);
914 [ # # ]: 0 : if (ret != 0 || net_hw->vxlan_usecnt[idx] == 0) {
915 : 0 : PMD_DRV_LOG(ERR, "Failed find valid vxlan idx.");
916 : 0 : return -EINVAL;
917 : : }
918 : :
919 : 0 : net_hw->vxlan_usecnt[idx]--;
920 : :
921 [ # # ]: 0 : if (net_hw->vxlan_usecnt[idx] == 0) {
922 : : hw = &net_hw->super;
923 : 0 : ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_VXLAN;
924 : :
925 : 0 : ret = nfp_net_set_vxlan_port(net_hw, idx, 0, ctrl);
926 [ # # ]: 0 : if (ret != 0) {
927 : 0 : PMD_DRV_LOG(ERR, "Failed set vxlan port.");
928 : 0 : return -EINVAL;
929 : : }
930 : :
931 : 0 : hw->ctrl = ctrl;
932 : : }
933 : :
934 : : return 0;
935 : : }
936 : :
937 : : /* Initialise and register driver with DPDK Application */
938 : : static const struct eth_dev_ops nfp_net_eth_dev_ops = {
939 : : .dev_configure = nfp_net_configure,
940 : : .dev_start = nfp_net_start,
941 : : .dev_stop = nfp_net_stop,
942 : : .dev_set_link_up = nfp_net_set_link_up,
943 : : .dev_set_link_down = nfp_net_set_link_down,
944 : : .dev_close = nfp_net_close,
945 : : .promiscuous_enable = nfp_net_promisc_enable,
946 : : .promiscuous_disable = nfp_net_promisc_disable,
947 : : .allmulticast_enable = nfp_net_allmulticast_enable,
948 : : .allmulticast_disable = nfp_net_allmulticast_disable,
949 : : .link_update = nfp_net_link_update,
950 : : .stats_get = nfp_net_stats_get,
951 : : .stats_reset = nfp_net_stats_reset,
952 : : .xstats_get = nfp_net_xstats_get,
953 : : .xstats_reset = nfp_net_xstats_reset,
954 : : .xstats_get_names = nfp_net_xstats_get_names,
955 : : .xstats_get_by_id = nfp_net_xstats_get_by_id,
956 : : .xstats_get_names_by_id = nfp_net_xstats_get_names_by_id,
957 : : .dev_infos_get = nfp_net_infos_get,
958 : : .dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
959 : : .dev_ptypes_set = nfp_net_ptypes_set,
960 : : .mtu_set = nfp_net_dev_mtu_set,
961 : : .mac_addr_set = nfp_net_set_mac_addr,
962 : : .vlan_offload_set = nfp_net_vlan_offload_set,
963 : : .reta_update = nfp_net_reta_update,
964 : : .reta_query = nfp_net_reta_query,
965 : : .rss_hash_update = nfp_net_rss_hash_update,
966 : : .rss_hash_conf_get = nfp_net_rss_hash_conf_get,
967 : : .rx_queue_setup = nfp_net_rx_queue_setup,
968 : : .rx_queue_release = nfp_net_rx_queue_release,
969 : : .rxq_info_get = nfp_net_rx_queue_info_get,
970 : : .tx_queue_setup = nfp_net_tx_queue_setup,
971 : : .tx_queue_release = nfp_net_tx_queue_release,
972 : : .txq_info_get = nfp_net_tx_queue_info_get,
973 : : .rx_queue_intr_enable = nfp_rx_queue_intr_enable,
974 : : .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
975 : : .udp_tunnel_port_add = nfp_udp_tunnel_port_add,
976 : : .udp_tunnel_port_del = nfp_udp_tunnel_port_del,
977 : : .fw_version_get = nfp_net_firmware_version_get,
978 : : .flow_ctrl_get = nfp_net_flow_ctrl_get,
979 : : .flow_ctrl_set = nfp_net_flow_ctrl_set,
980 : : .flow_ops_get = nfp_net_flow_ops_get,
981 : : .fec_get_capability = nfp_net_fec_get_capability,
982 : : .fec_get = nfp_net_fec_get,
983 : : .fec_set = nfp_net_fec_set,
984 : : .get_eeprom_length = nfp_net_get_eeprom_len,
985 : : .get_eeprom = nfp_net_get_eeprom,
986 : : .set_eeprom = nfp_net_set_eeprom,
987 : : .get_module_info = nfp_net_get_module_info,
988 : : .get_module_eeprom = nfp_net_get_module_eeprom,
989 : : .dev_led_on = nfp_net_led_on,
990 : : .dev_led_off = nfp_net_led_off,
991 : : .rx_burst_mode_get = nfp_net_rx_burst_mode_get,
992 : : .tx_burst_mode_get = nfp_net_tx_burst_mode_get,
993 : : };
994 : :
995 : : static inline void
996 : 0 : nfp_net_ethdev_ops_mount(struct nfp_pf_dev *pf_dev,
997 : : struct rte_eth_dev *eth_dev)
998 : : {
999 [ # # ]: 0 : if (pf_dev->ver.extend == NFP_NET_CFG_VERSION_DP_NFD3)
1000 : 0 : eth_dev->tx_pkt_burst = nfp_net_nfd3_xmit_pkts;
1001 : : else
1002 : 0 : nfp_net_nfdk_xmit_pkts_set(eth_dev);
1003 : :
1004 : 0 : eth_dev->dev_ops = &nfp_net_eth_dev_ops;
1005 : 0 : eth_dev->rx_queue_count = nfp_net_rx_queue_count;
1006 : 0 : nfp_net_recv_pkts_set(eth_dev);
1007 : 0 : }
1008 : :
1009 : : static int
1010 : 0 : nfp_net_init(struct rte_eth_dev *eth_dev,
1011 : : void *para)
1012 : : {
1013 : : int err;
1014 : : uint16_t port;
1015 : : uint64_t rx_base;
1016 : : uint64_t tx_base;
1017 : : struct nfp_hw *hw;
1018 : : struct nfp_net_hw *net_hw;
1019 : : struct nfp_pf_dev *pf_dev;
1020 : : struct nfp_net_init *hw_init;
1021 : : struct rte_pci_device *pci_dev;
1022 : : struct nfp_net_hw_priv *hw_priv;
1023 : : struct nfp_app_fw_nic *app_fw_nic;
1024 : :
1025 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1026 : 0 : net_hw = eth_dev->data->dev_private;
1027 : :
1028 : : hw_init = para;
1029 : 0 : net_hw->idx = hw_init->idx;
1030 : 0 : net_hw->nfp_idx = hw_init->nfp_idx;
1031 : 0 : eth_dev->process_private = hw_init->hw_priv;
1032 : :
1033 : : /* Use backpointer here to the PF of this eth_dev */
1034 : : hw_priv = eth_dev->process_private;
1035 : 0 : pf_dev = hw_priv->pf_dev;
1036 : :
1037 : : /* Use backpointer to the CoreNIC app struct */
1038 : 0 : app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv);
1039 : :
1040 : : /* Add this device to the PF's array of physical ports */
1041 : 0 : app_fw_nic->ports[net_hw->idx] = net_hw;
1042 : :
1043 : 0 : port = net_hw->idx;
1044 [ # # ]: 0 : if (port > 7) {
1045 : 0 : PMD_DRV_LOG(ERR, "Port value is wrong.");
1046 : 0 : return -ENODEV;
1047 : : }
1048 : :
1049 : 0 : hw = &net_hw->super;
1050 : :
1051 : 0 : PMD_INIT_LOG(DEBUG, "Working with physical port number: %hu, "
1052 : : "NFP internal port number: %d.", port, net_hw->nfp_idx);
1053 : :
1054 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
1055 : :
1056 [ # # ]: 0 : if (pf_dev->multi_pf.enabled)
1057 : 0 : hw->ctrl_bar = pf_dev->ctrl_bar;
1058 : : else
1059 : 0 : hw->ctrl_bar = pf_dev->ctrl_bar + (port * pf_dev->ctrl_bar_size);
1060 : :
1061 : 0 : net_hw->mac_stats = pf_dev->mac_stats_bar +
1062 : 0 : (net_hw->nfp_idx * NFP_MAC_STATS_SIZE);
1063 : :
1064 : 0 : PMD_INIT_LOG(DEBUG, "Ctrl bar: %p.", hw->ctrl_bar);
1065 : 0 : PMD_INIT_LOG(DEBUG, "MAC stats: %p.", net_hw->mac_stats);
1066 : :
1067 : 0 : err = nfp_net_common_init(pf_dev, net_hw);
1068 [ # # ]: 0 : if (err != 0)
1069 : : return err;
1070 : :
1071 : 0 : err = nfp_net_tlv_caps_parse(eth_dev);
1072 [ # # ]: 0 : if (err != 0) {
1073 : 0 : PMD_INIT_LOG(ERR, "Failed to parser TLV caps.");
1074 : 0 : return err;
1075 : : }
1076 : :
1077 : 0 : err = nfp_ipsec_init(eth_dev);
1078 [ # # ]: 0 : if (err != 0) {
1079 : 0 : PMD_INIT_LOG(ERR, "Failed to init IPsec module.");
1080 : 0 : return err;
1081 : : }
1082 : :
1083 : 0 : nfp_net_ethdev_ops_mount(pf_dev, eth_dev);
1084 : :
1085 : 0 : net_hw->eth_xstats_base = rte_malloc("rte_eth_xstat", sizeof(struct rte_eth_xstat) *
1086 : 0 : nfp_net_xstats_size(eth_dev), 0);
1087 [ # # ]: 0 : if (net_hw->eth_xstats_base == NULL) {
1088 : 0 : PMD_INIT_LOG(ERR, "No memory for xstats base values on device %s!",
1089 : : pci_dev->device.name);
1090 : : err = -ENOMEM;
1091 : 0 : goto ipsec_exit;
1092 : : }
1093 : :
1094 : : /* Work out where in the BAR the queues start. */
1095 : 0 : tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
1096 : 0 : rx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
1097 : :
1098 : 0 : net_hw->tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ;
1099 : 0 : net_hw->rx_bar = pf_dev->qc_bar + rx_base * NFP_QCP_QUEUE_ADDR_SZ;
1100 : :
1101 : 0 : PMD_INIT_LOG(DEBUG, "The ctrl_bar: %p, tx_bar: %p, rx_bar: %p.",
1102 : : hw->ctrl_bar, net_hw->tx_bar, net_hw->rx_bar);
1103 : :
1104 : 0 : nfp_net_cfg_queue_setup(net_hw);
1105 : 0 : net_hw->mtu = RTE_ETHER_MTU;
1106 : :
1107 : : /* VLAN insertion is incompatible with LSOv2 */
1108 [ # # ]: 0 : if ((hw->cap & NFP_NET_CFG_CTRL_LSO2) != 0)
1109 : 0 : hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
1110 : :
1111 : 0 : nfp_net_log_device_information(net_hw, pf_dev);
1112 : :
1113 : : /* Initializing spinlock for reconfigs */
1114 : : rte_spinlock_init(&hw->reconfig_lock);
1115 : :
1116 [ # # # # ]: 0 : if ((port == 0 || pf_dev->multi_pf.enabled)) {
1117 : 0 : err = nfp_net_vf_config_app_init(net_hw, pf_dev);
1118 [ # # ]: 0 : if (err != 0) {
1119 : 0 : PMD_INIT_LOG(ERR, "Failed to init sriov module.");
1120 : 0 : goto xstats_free;
1121 : : }
1122 : : }
1123 : :
1124 : : /* Allocating memory for mac addr */
1125 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", RTE_ETHER_ADDR_LEN, 0);
1126 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
1127 : 0 : PMD_INIT_LOG(ERR, "Failed to space for MAC address.");
1128 : : err = -ENOMEM;
1129 : 0 : goto xstats_free;
1130 : : }
1131 : :
1132 [ # # ]: 0 : if ((hw->cap & NFP_NET_CFG_CTRL_TXRWB) != 0) {
1133 : 0 : err = nfp_net_txrwb_alloc(eth_dev);
1134 [ # # ]: 0 : if (err != 0)
1135 : 0 : goto xstats_free;
1136 : : }
1137 : :
1138 : : nfp_net_pf_read_mac(app_fw_nic, port, hw_priv);
1139 : 0 : nfp_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
1140 : :
1141 : : if (rte_is_valid_assigned_ether_addr(&hw->mac_addr) == 0) {
1142 : 0 : PMD_INIT_LOG(INFO, "Using random mac address for port %d.", port);
1143 : : /* Using random mac addresses for VFs */
1144 : 0 : rte_eth_random_addr(&hw->mac_addr.addr_bytes[0]);
1145 : 0 : nfp_write_mac(hw, &hw->mac_addr.addr_bytes[0]);
1146 : : }
1147 : :
1148 : : /* Copying mac address to DPDK eth_dev struct */
1149 [ # # ]: 0 : rte_ether_addr_copy(&hw->mac_addr, eth_dev->data->mac_addrs);
1150 : :
1151 [ # # ]: 0 : if ((hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR) == 0)
1152 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
1153 : :
1154 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1155 : :
1156 : 0 : PMD_INIT_LOG(INFO, "Port %d VendorID=%#x DeviceID=%#x "
1157 : : "mac=" RTE_ETHER_ADDR_PRT_FMT,
1158 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
1159 : : pci_dev->id.device_id,
1160 : : RTE_ETHER_ADDR_BYTES(&hw->mac_addr));
1161 : :
1162 : : /* Registering LSC interrupt handler */
1163 : 0 : rte_intr_callback_register(pci_dev->intr_handle,
1164 : : nfp_net_dev_interrupt_handler, (void *)eth_dev);
1165 : : /* Telling the firmware about the LSC interrupt entry */
1166 : : nn_cfg_writeb(hw, NFP_NET_CFG_LSC, NFP_NET_IRQ_LSC_IDX);
1167 : : /* Unmask the LSC interrupt */
1168 : 0 : nfp_net_irq_unmask(eth_dev);
1169 : : /* Recording current stats counters values */
1170 : 0 : nfp_net_stats_reset(eth_dev);
1171 : :
1172 [ # # ]: 0 : if ((hw->cap_ext & NFP_NET_CFG_CTRL_FLOW_STEER) != 0) {
1173 : 0 : err = nfp_net_flow_priv_init(pf_dev, port);
1174 [ # # ]: 0 : if (err != 0) {
1175 : 0 : PMD_INIT_LOG(ERR, "Init net flow priv failed.");
1176 : 0 : goto txrwb_free;
1177 : : }
1178 : : }
1179 : :
1180 : : return 0;
1181 : :
1182 : : txrwb_free:
1183 [ # # ]: 0 : if ((hw->cap & NFP_NET_CFG_CTRL_TXRWB) != 0)
1184 : 0 : nfp_net_txrwb_free(eth_dev);
1185 : 0 : xstats_free:
1186 : 0 : rte_free(net_hw->eth_xstats_base);
1187 : 0 : ipsec_exit:
1188 : 0 : nfp_ipsec_uninit(eth_dev);
1189 : :
1190 : 0 : return err;
1191 : : }
1192 : :
1193 : : static int
1194 : 0 : nfp_net_device_activate(struct nfp_pf_dev *pf_dev)
1195 : : {
1196 : : int ret;
1197 : : struct nfp_nsp *nsp;
1198 : : struct nfp_multi_pf *multi_pf;
1199 : :
1200 : : multi_pf = &pf_dev->multi_pf;
1201 [ # # # # ]: 0 : if (multi_pf->enabled && multi_pf->function_id != 0) {
1202 : 0 : nsp = nfp_nsp_open(pf_dev->cpp);
1203 [ # # ]: 0 : if (nsp == NULL) {
1204 : 0 : PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle.");
1205 : 0 : return -EIO;
1206 : : }
1207 : :
1208 : 0 : ret = nfp_nsp_device_activate(nsp);
1209 : 0 : nfp_nsp_close(nsp);
1210 [ # # ]: 0 : if (ret != 0 && ret != -EOPNOTSUPP)
1211 : 0 : return ret;
1212 : : }
1213 : :
1214 : : return 0;
1215 : : }
1216 : :
1217 : : #define DEFAULT_FW_PATH "/lib/firmware/netronome"
1218 : :
1219 : : static int
1220 : 0 : nfp_fw_get_name(struct nfp_pf_dev *pf_dev,
1221 : : char *fw_name,
1222 : : size_t fw_size)
1223 : : {
1224 : : char serial[40];
1225 : : uint16_t interface;
1226 : : char card_desc[100];
1227 : : uint32_t cpp_serial_len;
1228 : : const char *nfp_fw_model;
1229 : : const uint8_t *cpp_serial;
1230 : :
1231 : 0 : cpp_serial_len = nfp_cpp_serial(pf_dev->cpp, &cpp_serial);
1232 [ # # ]: 0 : if (cpp_serial_len != NFP_SERIAL_LEN)
1233 : : return -ERANGE;
1234 : :
1235 : 0 : interface = nfp_cpp_interface(pf_dev->cpp);
1236 : :
1237 : : /* Looking for firmware file in order of priority */
1238 : :
1239 : : /* First try to find a firmware image specific for this device */
1240 : 0 : snprintf(serial, sizeof(serial),
1241 : : "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
1242 : 0 : cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3],
1243 : 0 : cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff);
1244 : : snprintf(fw_name, fw_size, "%s/%s.nffw", DEFAULT_FW_PATH, serial);
1245 : :
1246 : 0 : PMD_DRV_LOG(DEBUG, "Trying with fw file: %s.", fw_name);
1247 [ # # ]: 0 : if (access(fw_name, F_OK) == 0)
1248 : : return 0;
1249 : :
1250 : : /* Then try the PCI name */
1251 : : snprintf(fw_name, fw_size, "%s/pci-%s.nffw", DEFAULT_FW_PATH,
1252 : 0 : pf_dev->pci_dev->name);
1253 : :
1254 : 0 : PMD_DRV_LOG(DEBUG, "Trying with fw file: %s.", fw_name);
1255 [ # # ]: 0 : if (access(fw_name, F_OK) == 0)
1256 : : return 0;
1257 : :
1258 : 0 : nfp_fw_model = nfp_hwinfo_lookup(pf_dev->hwinfo, "nffw.partno");
1259 [ # # ]: 0 : if (nfp_fw_model == NULL) {
1260 : 0 : nfp_fw_model = nfp_hwinfo_lookup(pf_dev->hwinfo, "assembly.partno");
1261 [ # # ]: 0 : if (nfp_fw_model == NULL) {
1262 : 0 : PMD_DRV_LOG(ERR, "Firmware model NOT found.");
1263 : 0 : return -EIO;
1264 : : }
1265 : : }
1266 : :
1267 : : /* And then try the model name */
1268 : : snprintf(card_desc, sizeof(card_desc), "%s.nffw", nfp_fw_model);
1269 : : snprintf(fw_name, fw_size, "%s/%s", DEFAULT_FW_PATH, card_desc);
1270 : 0 : PMD_DRV_LOG(DEBUG, "Trying with fw file: %s.", fw_name);
1271 [ # # ]: 0 : if (access(fw_name, F_OK) == 0)
1272 : : return 0;
1273 : :
1274 : : /* Finally try the card type and media */
1275 : 0 : snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
1276 : : nfp_fw_model, pf_dev->nfp_eth_table->count,
1277 : 0 : pf_dev->nfp_eth_table->ports[0].speed / 1000);
1278 : : snprintf(fw_name, fw_size, "%s/%s", DEFAULT_FW_PATH, card_desc);
1279 : 0 : PMD_DRV_LOG(DEBUG, "Trying with fw file: %s.", fw_name);
1280 [ # # ]: 0 : if (access(fw_name, F_OK) == 0)
1281 : 0 : return 0;
1282 : :
1283 : : return -ENOENT;
1284 : : }
1285 : :
1286 : : static int
1287 : 0 : nfp_fw_upload(struct nfp_nsp *nsp,
1288 : : char *fw_name)
1289 : : {
1290 : : int err;
1291 : : void *fw_buf;
1292 : : size_t fsize;
1293 : :
1294 : 0 : err = rte_firmware_read(fw_name, &fw_buf, &fsize);
1295 [ # # ]: 0 : if (err != 0) {
1296 : 0 : PMD_DRV_LOG(ERR, "Firmware %s not found!", fw_name);
1297 : 0 : return -ENOENT;
1298 : : }
1299 : :
1300 : 0 : PMD_DRV_LOG(INFO, "Firmware file found at %s with size: %zu.",
1301 : : fw_name, fsize);
1302 : 0 : PMD_DRV_LOG(INFO, "Uploading the firmware ...");
1303 [ # # ]: 0 : if (nfp_nsp_load_fw(nsp, fw_buf, fsize) < 0) {
1304 : 0 : free(fw_buf);
1305 : 0 : PMD_DRV_LOG(ERR, "Firmware load failed.");
1306 : 0 : return -EIO;
1307 : : }
1308 : :
1309 : 0 : PMD_DRV_LOG(INFO, "Done.");
1310 : :
1311 : 0 : free(fw_buf);
1312 : :
1313 : 0 : return 0;
1314 : : }
1315 : :
1316 : : static void
1317 : 0 : nfp_fw_unload(struct nfp_cpp *cpp)
1318 : : {
1319 : : int err;
1320 : : struct nfp_nsp *nsp;
1321 : :
1322 : 0 : nsp = nfp_nsp_open(cpp);
1323 [ # # ]: 0 : if (nsp == NULL)
1324 : : return;
1325 : :
1326 : 0 : err = nfp_nsp_device_soft_reset(nsp);
1327 [ # # ]: 0 : if (err != 0)
1328 : 0 : PMD_DRV_LOG(WARNING, "Failed to do soft reset when nfp fw unload.");
1329 : :
1330 : 0 : nfp_nsp_close(nsp);
1331 : : }
1332 : :
1333 : : static int
1334 : 0 : nfp_fw_check_change(struct nfp_cpp *cpp,
1335 : : char *fw_name,
1336 : : bool *fw_changed)
1337 : : {
1338 : : int ret;
1339 : 0 : uint32_t new_version = 0;
1340 : 0 : uint32_t old_version = 0;
1341 : :
1342 : 0 : ret = nfp_elf_get_fw_version(&new_version, fw_name);
1343 [ # # ]: 0 : if (ret != 0)
1344 : : return ret;
1345 : :
1346 : 0 : nfp_net_get_fw_version(cpp, &old_version);
1347 : :
1348 [ # # ]: 0 : if (new_version != old_version) {
1349 : 0 : PMD_DRV_LOG(INFO, "FW version is changed, new %u, old %u.",
1350 : : new_version, old_version);
1351 : 0 : *fw_changed = true;
1352 : : } else {
1353 : 0 : PMD_DRV_LOG(INFO, "FW version is not changed and is %u.", new_version);
1354 : 0 : *fw_changed = false;
1355 : : }
1356 : :
1357 : : return 0;
1358 : : }
1359 : :
1360 : : static void
1361 : 0 : nfp_pcie_reg32_write_clear(struct rte_pci_device *pci_dev,
1362 : : int position)
1363 : : {
1364 : : int ret;
1365 : : uint32_t capability;
1366 : :
1367 : 0 : ret = rte_pci_read_config(pci_dev, &capability, 4, position);
1368 [ # # ]: 0 : if (ret < 0)
1369 : 0 : capability = 0xffffffff;
1370 : :
1371 : 0 : (void)rte_pci_write_config(pci_dev, &capability, 4, position);
1372 : 0 : }
1373 : :
1374 : : static void
1375 : 0 : nfp_pcie_aer_clear(struct rte_pci_device *pci_dev)
1376 : : {
1377 : : int pos;
1378 : :
1379 : 0 : pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_ERR);
1380 [ # # ]: 0 : if (pos <= 0)
1381 : : return;
1382 : :
1383 : 0 : nfp_pcie_reg32_write_clear(pci_dev, pos + RTE_PCI_ERR_UNCOR_STATUS);
1384 : 0 : nfp_pcie_reg32_write_clear(pci_dev, pos + RTE_PCI_ERR_COR_STATUS);
1385 : : }
1386 : :
1387 : : static int
1388 : 0 : nfp_fw_reload(struct nfp_nsp *nsp,
1389 : : char *fw_name,
1390 : : struct rte_pci_device *pci_dev,
1391 : : int reset)
1392 : : {
1393 : : int err;
1394 : : bool reset_flag;
1395 : :
1396 : 0 : reset_flag = (reset == NFP_NSP_DRV_RESET_ALWAYS) ||
1397 : : (reset == NFP_NSP_DRV_RESET_DISK);
1398 : :
1399 [ # # ]: 0 : if (reset_flag) {
1400 : 0 : err = nfp_nsp_device_soft_reset(nsp);
1401 [ # # ]: 0 : if (err != 0) {
1402 : 0 : PMD_DRV_LOG(ERR, "NFP firmware soft reset failed.");
1403 : 0 : return err;
1404 : : }
1405 : : }
1406 : :
1407 : : /*
1408 : : * Accessing device memory during soft reset may result in some
1409 : : * errors being recorded in PCIE's AER register, which is normal.
1410 : : * Therefore, after the soft reset is completed, these errors
1411 : : * should be cleared.
1412 : : */
1413 : 0 : nfp_pcie_aer_clear(pci_dev);
1414 : :
1415 : 0 : err = nfp_fw_upload(nsp, fw_name);
1416 [ # # ]: 0 : if (err != 0) {
1417 : 0 : PMD_DRV_LOG(ERR, "NFP firmware load failed.");
1418 : 0 : return err;
1419 : : }
1420 : :
1421 : : return 0;
1422 : : }
1423 : :
1424 : : static bool
1425 : 0 : nfp_fw_skip_load(const struct nfp_dev_info *dev_info,
1426 : : struct nfp_multi_pf *multi_pf,
1427 : : bool *reload_fw)
1428 : 0 : {
1429 : : uint8_t i;
1430 : : uint64_t tmp_beat;
1431 : : uint32_t port_num;
1432 : : uint8_t in_use = 0;
1433 : 0 : uint64_t beat[dev_info->pf_num_per_unit];
1434 : 0 : uint32_t offset[dev_info->pf_num_per_unit];
1435 : : uint8_t abnormal = dev_info->pf_num_per_unit;
1436 : :
1437 : 0 : sleep(1);
1438 [ # # ]: 0 : for (port_num = 0; port_num < dev_info->pf_num_per_unit; port_num++) {
1439 [ # # ]: 0 : if (port_num == multi_pf->function_id) {
1440 : 0 : abnormal--;
1441 : 0 : continue;
1442 : : }
1443 : :
1444 : 0 : offset[port_num] = NFP_BEAT_OFFSET(port_num);
1445 : 0 : beat[port_num] = nn_readq(multi_pf->beat_addr + offset[port_num]);
1446 [ # # ]: 0 : if (beat[port_num] == 0)
1447 : 0 : abnormal--;
1448 : : }
1449 : :
1450 [ # # ]: 0 : if (abnormal == 0)
1451 : : return true;
1452 : :
1453 [ # # ]: 0 : for (i = 0; i < 3; i++) {
1454 : 0 : sleep(1);
1455 [ # # ]: 0 : for (port_num = 0; port_num < dev_info->pf_num_per_unit; port_num++) {
1456 [ # # ]: 0 : if (port_num == multi_pf->function_id)
1457 : 0 : continue;
1458 : :
1459 [ # # ]: 0 : if (beat[port_num] == 0)
1460 : 0 : continue;
1461 : :
1462 : 0 : tmp_beat = nn_readq(multi_pf->beat_addr + offset[port_num]);
1463 [ # # ]: 0 : if (tmp_beat != beat[port_num]) {
1464 : 0 : in_use++;
1465 : 0 : abnormal--;
1466 : 0 : beat[port_num] = 0;
1467 [ # # ]: 0 : if (*reload_fw) {
1468 : 0 : *reload_fw = false;
1469 : 0 : PMD_DRV_LOG(ERR, "The param %s does not work.",
1470 : : NFP_PF_FORCE_RELOAD_FW);
1471 : : }
1472 : : }
1473 : : }
1474 : :
1475 [ # # ]: 0 : if (abnormal == 0)
1476 : : return true;
1477 : : }
1478 : :
1479 [ # # ]: 0 : if (in_use != 0) {
1480 : 0 : PMD_DRV_LOG(WARNING, "Abnormal %u != 0, the nic has port which is exit abnormally.",
1481 : : abnormal);
1482 : 0 : return true;
1483 : : }
1484 : :
1485 : : return false;
1486 : : }
1487 : :
1488 : : static int
1489 : 0 : nfp_fw_reload_from_flash(struct nfp_nsp *nsp)
1490 : : {
1491 : : int ret;
1492 : :
1493 : 0 : ret = nfp_nsp_load_stored_fw(nsp);
1494 [ # # ]: 0 : if (ret != 0) {
1495 : 0 : PMD_DRV_LOG(ERR, "Load firmware from flash failed.");
1496 : 0 : return -EACCES;
1497 : : }
1498 : :
1499 : : return 0;
1500 : : }
1501 : :
1502 : : static int
1503 : 0 : nfp_fw_reload_for_single_pf_from_disk(struct nfp_nsp *nsp,
1504 : : char *fw_name,
1505 : : struct nfp_pf_dev *pf_dev,
1506 : : int reset)
1507 : : {
1508 : : int ret;
1509 : 0 : bool fw_changed = true;
1510 : :
1511 [ # # # # ]: 0 : if (nfp_nsp_has_fw_loaded(nsp) && nfp_nsp_fw_loaded(nsp) &&
1512 [ # # ]: 0 : !pf_dev->devargs.force_reload_fw) {
1513 : 0 : ret = nfp_fw_check_change(pf_dev->cpp, fw_name, &fw_changed);
1514 [ # # ]: 0 : if (ret != 0)
1515 : : return ret;
1516 : : }
1517 : :
1518 [ # # ]: 0 : if (!fw_changed)
1519 : : return 0;
1520 : :
1521 : 0 : ret = nfp_fw_reload(nsp, fw_name, pf_dev->pci_dev, reset);
1522 [ # # ]: 0 : if (ret != 0)
1523 : 0 : return ret;
1524 : :
1525 : : return 0;
1526 : : }
1527 : :
1528 : : static int
1529 : 0 : nfp_fw_reload_for_single_pf(struct nfp_nsp *nsp,
1530 : : char *fw_name,
1531 : : struct nfp_pf_dev *pf_dev,
1532 : : int reset,
1533 : : int policy)
1534 : : {
1535 : : int ret;
1536 : :
1537 [ # # # # ]: 0 : if (fw_name[0] != 0 && policy != NFP_NSP_APP_FW_LOAD_FLASH) {
1538 : 0 : ret = nfp_fw_reload_for_single_pf_from_disk(nsp, fw_name, pf_dev, reset);
1539 [ # # ]: 0 : if (ret != 0) {
1540 : 0 : PMD_DRV_LOG(ERR, "Load single PF firmware from disk failed.");
1541 : 0 : return ret;
1542 : : }
1543 [ # # # # ]: 0 : } else if (policy != NFP_NSP_APP_FW_LOAD_DISK && nfp_nsp_has_stored_fw_load(nsp)) {
1544 : 0 : ret = nfp_fw_reload_from_flash(nsp);
1545 [ # # ]: 0 : if (ret != 0) {
1546 : 0 : PMD_DRV_LOG(ERR, "Load single PF firmware from flash failed.");
1547 : 0 : return ret;
1548 : : }
1549 : : } else {
1550 : 0 : PMD_DRV_LOG(ERR, "Not load firmware, please update flash or recofigure card.");
1551 : 0 : return -ENODATA;
1552 : : }
1553 : :
1554 : : return 0;
1555 : : }
1556 : :
1557 : : static int
1558 : 0 : nfp_fw_reload_for_multi_pf_from_disk(struct nfp_nsp *nsp,
1559 : : char *fw_name,
1560 : : const struct nfp_dev_info *dev_info,
1561 : : struct nfp_pf_dev *pf_dev,
1562 : : int reset)
1563 : : {
1564 : : int err;
1565 : 0 : bool fw_changed = true;
1566 : : bool skip_load_fw = false;
1567 : 0 : bool reload_fw = pf_dev->devargs.force_reload_fw;
1568 : :
1569 [ # # # # : 0 : if (nfp_nsp_has_fw_loaded(nsp) && nfp_nsp_fw_loaded(nsp) && !reload_fw) {
# # ]
1570 : 0 : err = nfp_fw_check_change(pf_dev->cpp, fw_name, &fw_changed);
1571 [ # # ]: 0 : if (err != 0)
1572 : : return err;
1573 : : }
1574 : :
1575 [ # # # # ]: 0 : if (!fw_changed || reload_fw)
1576 : 0 : skip_load_fw = nfp_fw_skip_load(dev_info, &pf_dev->multi_pf, &reload_fw);
1577 : :
1578 [ # # # # ]: 0 : if (skip_load_fw && !reload_fw)
1579 : : return 0;
1580 : :
1581 : 0 : err = nfp_fw_reload(nsp, fw_name, pf_dev->pci_dev, reset);
1582 [ # # ]: 0 : if (err != 0)
1583 : 0 : return err;
1584 : :
1585 : : return 0;
1586 : : }
1587 : :
1588 : : static int
1589 : 0 : nfp_fw_reload_for_multi_pf(struct nfp_nsp *nsp,
1590 : : char *fw_name,
1591 : : const struct nfp_dev_info *dev_info,
1592 : : struct nfp_pf_dev *pf_dev,
1593 : : int reset,
1594 : : int policy)
1595 : : {
1596 : : int err;
1597 : : struct nfp_multi_pf *multi_pf;
1598 : :
1599 : 0 : multi_pf = &pf_dev->multi_pf;
1600 : :
1601 : 0 : err = nfp_net_keepalive_init(pf_dev->cpp, multi_pf);
1602 [ # # ]: 0 : if (err != 0) {
1603 : 0 : PMD_DRV_LOG(ERR, "NFP init beat failed.");
1604 : 0 : return err;
1605 : : }
1606 : :
1607 : 0 : err = nfp_net_keepalive_start(multi_pf);
1608 [ # # ]: 0 : if (err != 0) {
1609 : 0 : PMD_DRV_LOG(ERR, "NFP write beat failed.");
1610 : 0 : goto keepalive_uninit;
1611 : : }
1612 : :
1613 [ # # # # ]: 0 : if (fw_name[0] != 0 && policy != NFP_NSP_APP_FW_LOAD_FLASH) {
1614 : 0 : err = nfp_fw_reload_for_multi_pf_from_disk(nsp, fw_name, dev_info,
1615 : : pf_dev, reset);
1616 [ # # ]: 0 : if (err != 0) {
1617 : 0 : PMD_DRV_LOG(ERR, "Load multi PF firmware from disk failed.");
1618 : 0 : goto keepalive_stop;
1619 : : }
1620 [ # # # # ]: 0 : } else if (policy != NFP_NSP_APP_FW_LOAD_DISK && nfp_nsp_has_stored_fw_load(nsp)) {
1621 : 0 : err = nfp_fw_reload_from_flash(nsp);
1622 [ # # ]: 0 : if (err != 0) {
1623 : 0 : PMD_DRV_LOG(ERR, "Load multi PF firmware from flash failed.");
1624 : 0 : goto keepalive_stop;
1625 : : }
1626 : : } else {
1627 : 0 : PMD_DRV_LOG(ERR, "Not load firmware, please update flash or recofigure card.");
1628 : : err = -ENODATA;
1629 : 0 : goto keepalive_stop;
1630 : : }
1631 : :
1632 : : nfp_net_keepalive_clear_others(dev_info, multi_pf);
1633 : :
1634 : : return 0;
1635 : :
1636 : 0 : keepalive_stop:
1637 : : nfp_net_keepalive_stop(multi_pf);
1638 : 0 : keepalive_uninit:
1639 : : nfp_net_keepalive_uninit(multi_pf);
1640 : :
1641 : 0 : return err;
1642 : : }
1643 : :
1644 : : static int
1645 : : nfp_strtol(const char *buf,
1646 : : int base,
1647 : : long *value)
1648 : : {
1649 : : long val;
1650 : : char *tmp;
1651 : :
1652 : : if (value == NULL)
1653 : : return -EINVAL;
1654 : :
1655 : 0 : val = strtol(buf, &tmp, base);
1656 [ # # # # : 0 : if (tmp == NULL || *tmp != 0)
# # # # ]
1657 : : return -EINVAL;
1658 : :
1659 : : *value = val;
1660 : :
1661 : : return 0;
1662 : : }
1663 : :
1664 : : static int
1665 : 0 : nfp_fw_policy_value_get(struct nfp_nsp *nsp,
1666 : : const char *key,
1667 : : const char *default_val,
1668 : : int max_val,
1669 : : int *value)
1670 : : {
1671 : : int ret;
1672 : : int64_t val;
1673 : : char buf[64];
1674 : :
1675 : : snprintf(buf, sizeof(buf), "%s", key);
1676 : 0 : ret = nfp_nsp_hwinfo_lookup_optional(nsp, buf, sizeof(buf), default_val);
1677 [ # # ]: 0 : if (ret != 0)
1678 : : return ret;
1679 : :
1680 : : ret = nfp_strtol(buf, 0, &val);
1681 [ # # # # ]: 0 : if (ret != 0 || val < 0 || val > max_val) {
1682 : 0 : PMD_DRV_LOG(WARNING, "Invalid value '%s' from '%s', ignoring.",
1683 : : buf, key);
1684 : : /* Fall back to the default value */
1685 : : ret = nfp_strtol(default_val, 0, &val);
1686 : : if (ret != 0)
1687 : 0 : return ret;
1688 : : }
1689 : :
1690 : 0 : *value = val;
1691 : :
1692 : 0 : return 0;
1693 : : }
1694 : :
1695 : : static int
1696 : 0 : nfp_fw_setup(struct nfp_pf_dev *pf_dev,
1697 : : const struct nfp_dev_info *dev_info)
1698 : : {
1699 : : int err;
1700 : : int reset;
1701 : : int policy;
1702 : : char fw_name[125];
1703 : : struct nfp_nsp *nsp;
1704 : :
1705 : 0 : nsp = nfp_nsp_open(pf_dev->cpp);
1706 [ # # ]: 0 : if (nsp == NULL) {
1707 : 0 : PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle.");
1708 : 0 : return -EIO;
1709 : : }
1710 : :
1711 : 0 : err = nfp_fw_policy_value_get(nsp, "abi_drv_reset",
1712 : : NFP_NSP_DRV_RESET_DEFAULT, NFP_NSP_DRV_RESET_NEVER,
1713 : : &reset);
1714 [ # # ]: 0 : if (err != 0) {
1715 : 0 : PMD_DRV_LOG(ERR, "Get 'abi_drv_reset' from HWinfo failed.");
1716 : 0 : goto close_nsp;
1717 : : }
1718 : :
1719 : 0 : err = nfp_fw_policy_value_get(nsp, "app_fw_from_flash",
1720 : : NFP_NSP_APP_FW_LOAD_DEFAULT, NFP_NSP_APP_FW_LOAD_PREF,
1721 : : &policy);
1722 [ # # ]: 0 : if (err != 0) {
1723 : 0 : PMD_DRV_LOG(ERR, "Get 'app_fw_from_flash' from HWinfo failed.");
1724 : 0 : goto close_nsp;
1725 : : }
1726 : :
1727 : 0 : fw_name[0] = 0;
1728 [ # # ]: 0 : if (policy != NFP_NSP_APP_FW_LOAD_FLASH) {
1729 : 0 : err = nfp_fw_get_name(pf_dev, fw_name, sizeof(fw_name));
1730 [ # # ]: 0 : if (err != 0) {
1731 : 0 : fw_name[0] = 0;
1732 : 0 : PMD_DRV_LOG(DEBUG, "Can not find suitable firmware.");
1733 : : }
1734 : : }
1735 : :
1736 [ # # ]: 0 : if (pf_dev->multi_pf.enabled)
1737 : 0 : err = nfp_fw_reload_for_multi_pf(nsp, fw_name, dev_info,
1738 : : pf_dev, reset, policy);
1739 : : else
1740 : 0 : err = nfp_fw_reload_for_single_pf(nsp, fw_name, pf_dev,
1741 : : reset, policy);
1742 : :
1743 : 0 : close_nsp:
1744 : 0 : nfp_nsp_close(nsp);
1745 : 0 : return err;
1746 : : }
1747 : :
1748 : : static inline bool
1749 : : nfp_check_multi_pf_from_fw(uint32_t total_vnics)
1750 : : {
1751 [ # # ]: 0 : if (total_vnics == 1)
1752 : 0 : return true;
1753 : :
1754 : : return false;
1755 : : }
1756 : :
1757 : : static inline int
1758 : 0 : nfp_check_multi_pf_from_nsp(struct rte_pci_device *pci_dev,
1759 : : struct nfp_cpp *cpp,
1760 : : bool *flag)
1761 : : {
1762 : : struct nfp_nsp *nsp;
1763 : :
1764 : 0 : nsp = nfp_nsp_open(cpp);
1765 [ # # ]: 0 : if (nsp == NULL) {
1766 : 0 : PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle.");
1767 : 0 : return -EIO;
1768 : : }
1769 : :
1770 [ # # ]: 0 : *flag = (nfp_nsp_get_abi_ver_major(nsp) > 0) &&
1771 [ # # ]: 0 : (pci_dev->id.device_id == PCI_DEVICE_ID_NFP3800_PF_NIC);
1772 : :
1773 : 0 : nfp_nsp_close(nsp);
1774 : :
1775 : 0 : return 0;
1776 : : }
1777 : :
1778 : : static int
1779 : 0 : nfp_enable_multi_pf(struct nfp_pf_dev *pf_dev)
1780 : : {
1781 : : int err = 0;
1782 : : uint64_t tx_base;
1783 : : uint8_t *ctrl_bar;
1784 : : struct nfp_hw *hw;
1785 : : uint32_t cap_extend;
1786 : : struct nfp_net_hw net_hw;
1787 : : struct nfp_cpp_area *area;
1788 : : char name[RTE_ETH_NAME_MAX_LEN];
1789 : :
1790 : : memset(&net_hw, 0, sizeof(struct nfp_net_hw));
1791 : :
1792 : : /* Map the symbol table */
1793 : 0 : pf_dev->ctrl_bar_size = NFP_NET_CFG_BAR_SZ_MIN;
1794 : 0 : snprintf(name, sizeof(name), "_pf%u_net_bar0",
1795 : 0 : pf_dev->multi_pf.function_id);
1796 : 0 : ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, name, pf_dev->ctrl_bar_size,
1797 : : &area);
1798 [ # # ]: 0 : if (ctrl_bar == NULL) {
1799 : 0 : PMD_INIT_LOG(ERR, "Failed to find data vNIC memory symbol.");
1800 : 0 : return -ENODEV;
1801 : : }
1802 : :
1803 : : hw = &net_hw.super;
1804 : 0 : hw->ctrl_bar = ctrl_bar;
1805 : :
1806 : : /* Check the version from firmware */
1807 [ # # ]: 0 : if (!nfp_net_version_check(hw, pf_dev)) {
1808 : 0 : PMD_INIT_LOG(ERR, "Not the valid version.");
1809 : : err = -EINVAL;
1810 : 0 : goto end;
1811 : : }
1812 : :
1813 : : /* Set the ctrl bar size */
1814 : 0 : nfp_net_ctrl_bar_size_set(pf_dev);
1815 : :
1816 [ # # ]: 0 : if (!pf_dev->multi_pf.enabled)
1817 : 0 : goto end;
1818 : :
1819 : : cap_extend = nn_cfg_readl(hw, NFP_NET_CFG_CAP_WORD1);
1820 [ # # ]: 0 : if ((cap_extend & NFP_NET_CFG_CTRL_MULTI_PF) == 0) {
1821 : 0 : PMD_INIT_LOG(ERR, "Loaded firmware does not support multiple PF.");
1822 : : err = -EINVAL;
1823 : 0 : goto end;
1824 : : }
1825 : :
1826 : 0 : tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
1827 : 0 : net_hw.tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ;
1828 : 0 : nfp_net_cfg_queue_setup(&net_hw);
1829 : : rte_spinlock_init(&hw->reconfig_lock);
1830 : 0 : err = nfp_ext_reconfig(&net_hw.super, NFP_NET_CFG_CTRL_MULTI_PF,
1831 : : NFP_NET_CFG_UPDATE_GEN);
1832 [ # # ]: 0 : if (err != 0) {
1833 : 0 : PMD_INIT_LOG(ERR, "Configure multiple PF failed.");
1834 : 0 : goto end;
1835 : : }
1836 : :
1837 : 0 : end:
1838 : 0 : nfp_cpp_area_release_free(area);
1839 : 0 : return err;
1840 : : }
1841 : :
1842 : : static bool
1843 : 0 : nfp_app_fw_nic_total_phyports_check(struct nfp_pf_dev *pf_dev)
1844 : : {
1845 : : uint8_t total_phyports;
1846 : :
1847 : 0 : total_phyports = nfp_net_get_phyports_from_fw(pf_dev);
1848 : :
1849 [ # # ]: 0 : if (pf_dev->multi_pf.enabled) {
1850 : : if (!nfp_check_multi_pf_from_fw(total_phyports)) {
1851 : 0 : PMD_INIT_LOG(ERR, "NSP report multipf, but FW report not multipf.");
1852 : 0 : return false;
1853 : : }
1854 : : } else {
1855 : : /*
1856 : : * For single PF the number of vNICs exposed should be the same as the
1857 : : * number of physical ports.
1858 : : */
1859 [ # # ]: 0 : if (total_phyports != pf_dev->nfp_eth_table->count) {
1860 : 0 : PMD_INIT_LOG(ERR, "Total physical ports do not match number of vNICs.");
1861 : 0 : return false;
1862 : : }
1863 : : }
1864 : :
1865 : : return true;
1866 : : }
1867 : :
1868 : : static void
1869 : 0 : nfp_port_name_generate(char *port_name,
1870 : : size_t length,
1871 : : int port_id,
1872 : : struct nfp_pf_dev *pf_dev)
1873 : : {
1874 : 0 : const char *name = pf_dev->pci_dev->device.name;
1875 : :
1876 [ # # ]: 0 : if (pf_dev->multi_pf.enabled)
1877 : : snprintf(port_name, length, "%s", name);
1878 : : else
1879 : : snprintf(port_name, length, "%s_port%u", name, port_id);
1880 : 0 : }
1881 : :
1882 : : static int
1883 : 0 : nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
1884 : : {
1885 : : uint8_t i;
1886 : : uint8_t id;
1887 : : int ret = 0;
1888 : : struct nfp_app_fw_nic *app_fw_nic;
1889 : : struct nfp_eth_table *nfp_eth_table;
1890 : : char bar_name[RTE_ETH_NAME_MAX_LEN];
1891 : : char port_name[RTE_ETH_NAME_MAX_LEN];
1892 : 0 : struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
1893 : 0 : struct nfp_net_init hw_init = {
1894 : : .hw_priv = hw_priv,
1895 : : };
1896 : :
1897 : 0 : nfp_eth_table = pf_dev->nfp_eth_table;
1898 : 0 : PMD_INIT_LOG(INFO, "Total physical ports: %d.", nfp_eth_table->count);
1899 : 0 : id = nfp_function_id_get(pf_dev, 0);
1900 : :
1901 : : /* Allocate memory for the CoreNIC app */
1902 : 0 : app_fw_nic = rte_zmalloc("nfp_app_fw_nic", sizeof(*app_fw_nic), 0);
1903 [ # # ]: 0 : if (app_fw_nic == NULL)
1904 : : return -ENOMEM;
1905 : :
1906 : : /* Point the app_fw_priv pointer in the PF to the coreNIC app */
1907 : 0 : pf_dev->app_fw_priv = app_fw_nic;
1908 : :
1909 : : /* Check the number of vNIC's created for the PF */
1910 [ # # ]: 0 : if (!nfp_app_fw_nic_total_phyports_check(pf_dev)) {
1911 : : ret = -ENODEV;
1912 : 0 : goto app_cleanup;
1913 : : }
1914 : :
1915 : : /* Populate coreNIC app properties */
1916 [ # # ]: 0 : if (pf_dev->total_phyports > 1)
1917 : 0 : app_fw_nic->multiport = true;
1918 : :
1919 : : /* Map the symbol table */
1920 : 0 : snprintf(bar_name, sizeof(bar_name), "_pf%u_net_bar0", id);
1921 : 0 : pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, bar_name,
1922 : 0 : pf_dev->total_phyports * pf_dev->ctrl_bar_size,
1923 : : &pf_dev->ctrl_area);
1924 [ # # ]: 0 : if (pf_dev->ctrl_bar == NULL) {
1925 : 0 : PMD_INIT_LOG(ERR, "The nfp_rtsym_map fails for %s.", bar_name);
1926 : : ret = -EIO;
1927 : 0 : goto app_cleanup;
1928 : : }
1929 : :
1930 : 0 : PMD_INIT_LOG(DEBUG, "Ctrl bar: %p.", pf_dev->ctrl_bar);
1931 : :
1932 : : /* Loop through all physical ports on PF */
1933 [ # # ]: 0 : for (i = 0; i < pf_dev->total_phyports; i++) {
1934 : 0 : nfp_port_name_generate(port_name, sizeof(port_name), i, pf_dev);
1935 : :
1936 : 0 : id = nfp_function_id_get(pf_dev, i);
1937 : 0 : hw_init.idx = id;
1938 : 0 : hw_init.nfp_idx = nfp_eth_table->ports[id].index;
1939 : 0 : ret = rte_eth_dev_create(&pf_dev->pci_dev->device, port_name,
1940 : : sizeof(struct nfp_net_hw), NULL, NULL,
1941 : : nfp_net_init, &hw_init);
1942 [ # # ]: 0 : if (ret != 0)
1943 : 0 : goto port_cleanup;
1944 : :
1945 : : } /* End loop, all ports on this PF */
1946 : :
1947 : : return 0;
1948 : :
1949 : : port_cleanup:
1950 [ # # ]: 0 : for (uint32_t j = 0; j < i; j++) {
1951 : : struct rte_eth_dev *eth_dev;
1952 : :
1953 : 0 : nfp_port_name_generate(port_name, sizeof(port_name), j, pf_dev);
1954 : 0 : eth_dev = rte_eth_dev_get_by_name(port_name);
1955 [ # # ]: 0 : if (eth_dev != NULL)
1956 : 0 : rte_eth_dev_destroy(eth_dev, nfp_net_uninit);
1957 : : }
1958 : 0 : nfp_cpp_area_release_free(pf_dev->ctrl_area);
1959 : 0 : app_cleanup:
1960 : 0 : rte_free(app_fw_nic);
1961 : :
1962 : 0 : return ret;
1963 : : }
1964 : :
1965 : : static int
1966 : 0 : nfp_net_hwinfo_set(uint8_t function_id,
1967 : : struct nfp_rtsym_table *sym_tbl,
1968 : : struct nfp_cpp *cpp,
1969 : : enum nfp_app_fw_id app_fw_id)
1970 : : {
1971 : 0 : int ret = 0;
1972 : : uint64_t app_cap;
1973 : : struct nfp_nsp *nsp;
1974 : : uint8_t sp_indiff = 1;
1975 : : char hw_info[RTE_ETH_NAME_MAX_LEN];
1976 : : char app_cap_name[RTE_ETH_NAME_MAX_LEN];
1977 : :
1978 [ # # ]: 0 : if (app_fw_id != NFP_APP_FW_FLOWER_NIC) {
1979 : : /* Read the app capabilities of the firmware loaded */
1980 : 0 : snprintf(app_cap_name, sizeof(app_cap_name), "_pf%u_net_app_cap", function_id);
1981 : 0 : app_cap = nfp_rtsym_read_le(sym_tbl, app_cap_name, &ret);
1982 [ # # ]: 0 : if (ret != 0) {
1983 : 0 : PMD_INIT_LOG(ERR, "Could not read app_fw_cap from firmware.");
1984 : 0 : return ret;
1985 : : }
1986 : :
1987 : : /* Calculate the value of sp_indiff and write to hw_info */
1988 : 0 : sp_indiff = app_cap & NFP_NET_APP_CAP_SP_INDIFF;
1989 : : }
1990 : :
1991 : 0 : snprintf(hw_info, sizeof(hw_info), "sp_indiff=%u", sp_indiff);
1992 : :
1993 : 0 : nsp = nfp_nsp_open(cpp);
1994 [ # # ]: 0 : if (nsp == NULL) {
1995 : 0 : PMD_INIT_LOG(ERR, "Could not get NSP.");
1996 : 0 : return -EIO;
1997 : : }
1998 : :
1999 : 0 : ret = nfp_nsp_hwinfo_set(nsp, hw_info, sizeof(hw_info));
2000 : 0 : nfp_nsp_close(nsp);
2001 [ # # ]: 0 : if (ret != 0) {
2002 : 0 : PMD_INIT_LOG(ERR, "Failed to set parameter to hwinfo.");
2003 : 0 : return ret;
2004 : : }
2005 : :
2006 : : return 0;
2007 : : }
2008 : :
2009 : : const uint32_t nfp_eth_media_table[NFP_MEDIA_LINK_MODES_NUMBER] = {
2010 : : [NFP_MEDIA_W0_RJ45_10M] = RTE_ETH_LINK_SPEED_10M,
2011 : : [NFP_MEDIA_W0_RJ45_10M_HD] = RTE_ETH_LINK_SPEED_10M_HD,
2012 : : [NFP_MEDIA_W0_RJ45_100M] = RTE_ETH_LINK_SPEED_100M,
2013 : : [NFP_MEDIA_W0_RJ45_100M_HD] = RTE_ETH_LINK_SPEED_100M_HD,
2014 : : [NFP_MEDIA_W0_RJ45_1G] = RTE_ETH_LINK_SPEED_1G,
2015 : : [NFP_MEDIA_W0_RJ45_2P5G] = RTE_ETH_LINK_SPEED_2_5G,
2016 : : [NFP_MEDIA_W0_RJ45_5G] = RTE_ETH_LINK_SPEED_5G,
2017 : : [NFP_MEDIA_W0_RJ45_10G] = RTE_ETH_LINK_SPEED_10G,
2018 : : [NFP_MEDIA_1000BASE_CX] = RTE_ETH_LINK_SPEED_1G,
2019 : : [NFP_MEDIA_1000BASE_KX] = RTE_ETH_LINK_SPEED_1G,
2020 : : [NFP_MEDIA_10GBASE_KX4] = RTE_ETH_LINK_SPEED_10G,
2021 : : [NFP_MEDIA_10GBASE_KR] = RTE_ETH_LINK_SPEED_10G,
2022 : : [NFP_MEDIA_10GBASE_CX4] = RTE_ETH_LINK_SPEED_10G,
2023 : : [NFP_MEDIA_10GBASE_CR] = RTE_ETH_LINK_SPEED_10G,
2024 : : [NFP_MEDIA_10GBASE_SR] = RTE_ETH_LINK_SPEED_10G,
2025 : : [NFP_MEDIA_10GBASE_ER] = RTE_ETH_LINK_SPEED_10G,
2026 : : [NFP_MEDIA_25GBASE_KR] = RTE_ETH_LINK_SPEED_25G,
2027 : : [NFP_MEDIA_25GBASE_KR_S] = RTE_ETH_LINK_SPEED_25G,
2028 : : [NFP_MEDIA_25GBASE_CR] = RTE_ETH_LINK_SPEED_25G,
2029 : : [NFP_MEDIA_25GBASE_CR_S] = RTE_ETH_LINK_SPEED_25G,
2030 : : [NFP_MEDIA_25GBASE_SR] = RTE_ETH_LINK_SPEED_25G,
2031 : : [NFP_MEDIA_40GBASE_CR4] = RTE_ETH_LINK_SPEED_40G,
2032 : : [NFP_MEDIA_40GBASE_KR4] = RTE_ETH_LINK_SPEED_40G,
2033 : : [NFP_MEDIA_40GBASE_SR4] = RTE_ETH_LINK_SPEED_40G,
2034 : : [NFP_MEDIA_40GBASE_LR4] = RTE_ETH_LINK_SPEED_40G,
2035 : : [NFP_MEDIA_50GBASE_KR] = RTE_ETH_LINK_SPEED_50G,
2036 : : [NFP_MEDIA_50GBASE_SR] = RTE_ETH_LINK_SPEED_50G,
2037 : : [NFP_MEDIA_50GBASE_CR] = RTE_ETH_LINK_SPEED_50G,
2038 : : [NFP_MEDIA_50GBASE_LR] = RTE_ETH_LINK_SPEED_50G,
2039 : : [NFP_MEDIA_50GBASE_ER] = RTE_ETH_LINK_SPEED_50G,
2040 : : [NFP_MEDIA_50GBASE_FR] = RTE_ETH_LINK_SPEED_50G,
2041 : : [NFP_MEDIA_100GBASE_KR4] = RTE_ETH_LINK_SPEED_100G,
2042 : : [NFP_MEDIA_100GBASE_SR4] = RTE_ETH_LINK_SPEED_100G,
2043 : : [NFP_MEDIA_100GBASE_CR4] = RTE_ETH_LINK_SPEED_100G,
2044 : : [NFP_MEDIA_100GBASE_KP4] = RTE_ETH_LINK_SPEED_100G,
2045 : : [NFP_MEDIA_100GBASE_CR10] = RTE_ETH_LINK_SPEED_100G,
2046 : : [NFP_MEDIA_10GBASE_LR] = RTE_ETH_LINK_SPEED_10G,
2047 : : [NFP_MEDIA_25GBASE_LR] = RTE_ETH_LINK_SPEED_25G,
2048 : : [NFP_MEDIA_25GBASE_ER] = RTE_ETH_LINK_SPEED_25G
2049 : : };
2050 : :
2051 : : static int
2052 : 0 : nfp_net_speed_capa_get_real(struct nfp_eth_media_buf *media_buf,
2053 : : struct nfp_pf_dev *pf_dev)
2054 : : {
2055 : : uint32_t i;
2056 : : uint32_t j;
2057 : : uint32_t offset;
2058 : : uint32_t speed_capa = 0;
2059 : : uint64_t supported_modes;
2060 : :
2061 [ # # ]: 0 : for (i = 0; i < RTE_DIM(media_buf->supported_modes); i++) {
2062 : 0 : supported_modes = media_buf->supported_modes[i];
2063 : 0 : offset = i * UINT64_BIT;
2064 [ # # ]: 0 : for (j = 0; j < UINT64_BIT; j++) {
2065 [ # # ]: 0 : if (supported_modes == 0)
2066 : : break;
2067 : :
2068 [ # # ]: 0 : if ((supported_modes & 1) != 0) {
2069 [ # # ]: 0 : if ((j + offset) >= NFP_MEDIA_LINK_MODES_NUMBER) {
2070 : 0 : PMD_DRV_LOG(ERR, "Invalid offset of media table.");
2071 : 0 : return -EINVAL;
2072 : : }
2073 : :
2074 : 0 : speed_capa |= nfp_eth_media_table[j + offset];
2075 : : }
2076 : :
2077 : 0 : supported_modes = supported_modes >> 1;
2078 : : }
2079 : : }
2080 : :
2081 : 0 : pf_dev->speed_capa = speed_capa;
2082 : :
2083 [ # # ]: 0 : return pf_dev->speed_capa == 0 ? -EINVAL : 0;
2084 : : }
2085 : :
2086 : : static int
2087 : 0 : nfp_net_speed_cap_get_one(struct nfp_pf_dev *pf_dev,
2088 : : uint32_t port_id)
2089 : : {
2090 : : int ret;
2091 : : struct nfp_nsp *nsp;
2092 : : struct nfp_eth_media_buf media_buf;
2093 : :
2094 : 0 : media_buf.eth_index = pf_dev->nfp_eth_table->ports[port_id].eth_index;
2095 : 0 : pf_dev->speed_capa = 0;
2096 : :
2097 : 0 : nsp = nfp_nsp_open(pf_dev->cpp);
2098 [ # # ]: 0 : if (nsp == NULL) {
2099 : 0 : PMD_DRV_LOG(ERR, "Could not get NSP.");
2100 : 0 : return -EIO;
2101 : : }
2102 : :
2103 : 0 : ret = nfp_nsp_read_media(nsp, &media_buf, sizeof(media_buf));
2104 : 0 : nfp_nsp_close(nsp);
2105 [ # # ]: 0 : if (ret != 0) {
2106 : 0 : PMD_DRV_LOG(ERR, "Failed to read media.");
2107 : 0 : return ret;
2108 : : }
2109 : :
2110 : 0 : ret = nfp_net_speed_capa_get_real(&media_buf, pf_dev);
2111 [ # # ]: 0 : if (ret < 0) {
2112 : 0 : PMD_DRV_LOG(ERR, "Speed capability is invalid.");
2113 : 0 : return ret;
2114 : : }
2115 : :
2116 : : return 0;
2117 : : }
2118 : :
2119 : : static int
2120 : 0 : nfp_net_speed_cap_get(struct nfp_pf_dev *pf_dev)
2121 : : {
2122 : : int ret;
2123 : : uint32_t i;
2124 : : uint32_t id;
2125 : : uint32_t count;
2126 : :
2127 : 0 : count = pf_dev->total_phyports;
2128 [ # # ]: 0 : for (i = 0; i < count; i++) {
2129 : 0 : id = nfp_function_id_get(pf_dev, i);
2130 : 0 : ret = nfp_net_speed_cap_get_one(pf_dev, id);
2131 [ # # ]: 0 : if (ret != 0) {
2132 : 0 : PMD_INIT_LOG(ERR, "Failed to get port %d speed capability.", id);
2133 : 0 : return ret;
2134 : : }
2135 : : }
2136 : :
2137 : : return 0;
2138 : : }
2139 : :
2140 : : /* Force the physical port down to clear the possible DMA error */
2141 : : static int
2142 : 0 : nfp_net_force_port_down(struct nfp_pf_dev *pf_dev)
2143 : : {
2144 : : int ret;
2145 : : uint32_t i;
2146 : : uint32_t id;
2147 : : uint32_t index;
2148 : : uint32_t count;
2149 : :
2150 : 0 : count = pf_dev->total_phyports;
2151 [ # # ]: 0 : for (i = 0; i < count; i++) {
2152 : 0 : id = nfp_function_id_get(pf_dev, i);
2153 : 0 : index = pf_dev->nfp_eth_table->ports[id].index;
2154 : 0 : ret = nfp_eth_set_configured(pf_dev->cpp, index, 0);
2155 [ # # ]: 0 : if (ret < 0)
2156 : 0 : return ret;
2157 : : }
2158 : :
2159 : : return 0;
2160 : : }
2161 : :
2162 : : static int
2163 : 0 : nfp_fw_app_primary_init(struct nfp_net_hw_priv *hw_priv)
2164 : : {
2165 : : int ret;
2166 : 0 : struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
2167 : :
2168 [ # # # ]: 0 : switch (pf_dev->app_fw_id) {
2169 : 0 : case NFP_APP_FW_CORE_NIC:
2170 : 0 : PMD_INIT_LOG(INFO, "Initializing coreNIC.");
2171 : 0 : ret = nfp_init_app_fw_nic(hw_priv);
2172 [ # # ]: 0 : if (ret != 0) {
2173 : 0 : PMD_INIT_LOG(ERR, "Could not initialize coreNIC!");
2174 : 0 : return ret;
2175 : : }
2176 : : break;
2177 : 0 : case NFP_APP_FW_FLOWER_NIC:
2178 : 0 : PMD_INIT_LOG(INFO, "Initializing Flower.");
2179 : 0 : ret = nfp_init_app_fw_flower(hw_priv);
2180 [ # # ]: 0 : if (ret != 0) {
2181 : 0 : PMD_INIT_LOG(ERR, "Could not initialize Flower!");
2182 : 0 : return ret;
2183 : : }
2184 : : break;
2185 : 0 : default:
2186 : 0 : PMD_INIT_LOG(ERR, "Unsupported Firmware loaded.");
2187 : : ret = -EINVAL;
2188 : 0 : return ret;
2189 : : }
2190 : :
2191 : : return 0;
2192 : : }
2193 : :
2194 : : static int
2195 : : nfp_pf_get_max_vf(struct nfp_pf_dev *pf_dev)
2196 : : {
2197 : : int ret;
2198 : : uint32_t max_vfs;
2199 : :
2200 : 0 : max_vfs = nfp_rtsym_read_le(pf_dev->sym_tbl, "nfd_vf_cfg_max_vfs", &ret);
2201 [ # # ]: 0 : if (ret != 0)
2202 : : return ret;
2203 : :
2204 : 0 : pf_dev->max_vfs = max_vfs;
2205 : :
2206 : : return 0;
2207 : : }
2208 : :
2209 : : static int
2210 : 0 : nfp_pf_get_sriov_vf(struct nfp_pf_dev *pf_dev,
2211 : : const struct nfp_dev_info *dev_info)
2212 : : {
2213 : : int ret;
2214 : : off_t pos;
2215 : : uint16_t offset;
2216 : : uint16_t sriov_vf;
2217 : :
2218 : : /* For 3800 single-PF and 4000 card */
2219 [ # # ]: 0 : if (!pf_dev->multi_pf.enabled) {
2220 : 0 : pf_dev->sriov_vf = pf_dev->max_vfs;
2221 : 0 : return 0;
2222 : : }
2223 : :
2224 : 0 : pos = rte_pci_find_ext_capability(pf_dev->pci_dev, RTE_PCI_EXT_CAP_ID_SRIOV);
2225 [ # # ]: 0 : if (pos == 0) {
2226 : 0 : PMD_INIT_LOG(ERR, "Can not get the pci sriov cap.");
2227 : 0 : return -EIO;
2228 : : }
2229 : :
2230 : : /*
2231 : : * Management firmware ensures that sriov capability registers
2232 : : * are initialized correctly.
2233 : : */
2234 : 0 : ret = rte_pci_read_config(pf_dev->pci_dev, &sriov_vf, sizeof(sriov_vf),
2235 : : pos + RTE_PCI_SRIOV_TOTAL_VF);
2236 [ # # ]: 0 : if (ret < 0) {
2237 : 0 : PMD_INIT_LOG(ERR, "Can not read the sriov toatl VF.");
2238 : 0 : return -EIO;
2239 : : }
2240 : :
2241 : : /* Offset of first VF is relative to its PF. */
2242 : 0 : ret = rte_pci_read_config(pf_dev->pci_dev, &offset, sizeof(offset),
2243 : : pos + RTE_PCI_SRIOV_VF_OFFSET);
2244 [ # # ]: 0 : if (ret < 0) {
2245 : 0 : PMD_INIT_LOG(ERR, "Can not get the VF offset.");
2246 : 0 : return -EIO;
2247 : : }
2248 : :
2249 : 0 : offset += pf_dev->multi_pf.function_id;
2250 [ # # ]: 0 : if (offset < dev_info->pf_num_per_unit)
2251 : : return -ERANGE;
2252 : :
2253 : 0 : offset -= dev_info->pf_num_per_unit;
2254 [ # # # # ]: 0 : if (offset >= pf_dev->max_vfs || offset + sriov_vf > pf_dev->max_vfs) {
2255 : 0 : PMD_INIT_LOG(ERR, "The pci allocate VF is more than the MAX VF.");
2256 : 0 : return -ERANGE;
2257 : : }
2258 : :
2259 : 0 : pf_dev->vf_base_id = offset;
2260 : 0 : pf_dev->sriov_vf = sriov_vf;
2261 : :
2262 : 0 : return 0;
2263 : : }
2264 : :
2265 : : static int
2266 : 0 : nfp_net_get_vf_info(struct nfp_pf_dev *pf_dev,
2267 : : const struct nfp_dev_info *dev_info)
2268 : : {
2269 : : int ret;
2270 : :
2271 : : ret = nfp_pf_get_max_vf(pf_dev);
2272 : : if (ret != 0) {
2273 [ # # ]: 0 : if (ret != -ENOENT) {
2274 : 0 : PMD_INIT_LOG(ERR, "Read max VFs failed.");
2275 : 0 : return ret;
2276 : : }
2277 : :
2278 : 0 : PMD_INIT_LOG(WARNING, "The firmware can not support read max VFs.");
2279 : 0 : return 0;
2280 : : }
2281 : :
2282 [ # # ]: 0 : if (pf_dev->max_vfs == 0)
2283 : : return 0;
2284 : :
2285 : 0 : ret = nfp_pf_get_sriov_vf(pf_dev, dev_info);
2286 [ # # ]: 0 : if (ret < 0)
2287 : : return ret;
2288 : :
2289 : 0 : pf_dev->queue_per_vf = NFP_QUEUE_PER_VF;
2290 : :
2291 : 0 : return 0;
2292 : : }
2293 : :
2294 : : static int
2295 : 0 : nfp_net_vf_config_init(struct nfp_pf_dev *pf_dev)
2296 : : {
2297 : : int ret = 0;
2298 : : uint32_t min_size;
2299 : : char vf_bar_name[RTE_ETH_NAME_MAX_LEN];
2300 : : char vf_cfg_name[RTE_ETH_NAME_MAX_LEN];
2301 : :
2302 [ # # ]: 0 : if (pf_dev->sriov_vf == 0)
2303 : : return 0;
2304 : :
2305 : 0 : min_size = pf_dev->ctrl_bar_size * pf_dev->sriov_vf;
2306 : 0 : snprintf(vf_bar_name, sizeof(vf_bar_name), "_pf%d_net_vf_bar",
2307 : 0 : pf_dev->multi_pf.function_id);
2308 : 0 : pf_dev->vf_bar = nfp_rtsym_map_offset(pf_dev->sym_tbl, vf_bar_name,
2309 : 0 : pf_dev->ctrl_bar_size * pf_dev->vf_base_id,
2310 : : min_size, &pf_dev->vf_area);
2311 [ # # ]: 0 : if (pf_dev->vf_bar == NULL) {
2312 : 0 : PMD_INIT_LOG(ERR, "Failed to get vf cfg.");
2313 : 0 : return -EIO;
2314 : : }
2315 : :
2316 : 0 : min_size = NFP_NET_VF_CFG_SZ * pf_dev->sriov_vf + NFP_NET_VF_CFG_MB_SZ;
2317 : 0 : snprintf(vf_cfg_name, sizeof(vf_cfg_name), "_pf%d_net_vf_cfg2",
2318 : 0 : pf_dev->multi_pf.function_id);
2319 : 0 : pf_dev->vf_cfg_tbl_bar = nfp_rtsym_map(pf_dev->sym_tbl, vf_cfg_name,
2320 : : min_size, &pf_dev->vf_cfg_tbl_area);
2321 [ # # ]: 0 : if (pf_dev->vf_cfg_tbl_bar == NULL) {
2322 : 0 : PMD_INIT_LOG(ERR, "Failed to get vf configure table.");
2323 : : ret = -EIO;
2324 : 0 : goto vf_bar_cleanup;
2325 : : }
2326 : :
2327 : : return 0;
2328 : :
2329 : : vf_bar_cleanup:
2330 : 0 : nfp_cpp_area_release_free(pf_dev->vf_area);
2331 : :
2332 : 0 : return ret;
2333 : : }
2334 : :
2335 : : static int
2336 : 0 : nfp_pf_init(struct rte_pci_device *pci_dev)
2337 : : {
2338 : : void *sync;
2339 : 0 : int ret = 0;
2340 : : uint64_t addr;
2341 : : uint32_t cpp_id;
2342 : : uint8_t function_id;
2343 : : struct nfp_cpp *cpp;
2344 : : struct nfp_pf_dev *pf_dev;
2345 : : struct nfp_hwinfo *hwinfo;
2346 : : enum nfp_app_fw_id app_fw_id;
2347 : : char name[RTE_ETH_NAME_MAX_LEN];
2348 : : struct nfp_rtsym_table *sym_tbl;
2349 : : struct nfp_net_hw_priv *hw_priv;
2350 : : char app_name[RTE_ETH_NAME_MAX_LEN];
2351 : : struct nfp_eth_table *nfp_eth_table;
2352 : : const struct nfp_dev_info *dev_info;
2353 : :
2354 [ # # ]: 0 : if (pci_dev == NULL)
2355 : : return -ENODEV;
2356 : :
2357 [ # # ]: 0 : if (pci_dev->mem_resource[0].addr == NULL) {
2358 : 0 : PMD_INIT_LOG(ERR, "The address of BAR0 is NULL.");
2359 : 0 : return -ENODEV;
2360 : : }
2361 : :
2362 : 0 : dev_info = nfp_dev_info_get(pci_dev->id.device_id);
2363 [ # # ]: 0 : if (dev_info == NULL) {
2364 : 0 : PMD_INIT_LOG(ERR, "Not supported device ID.");
2365 : 0 : return -ENODEV;
2366 : : }
2367 : :
2368 : 0 : hw_priv = rte_zmalloc(NULL, sizeof(*hw_priv), 0);
2369 [ # # ]: 0 : if (hw_priv == NULL) {
2370 : 0 : PMD_INIT_LOG(ERR, "Can not alloc memory for hw priv data.");
2371 : 0 : return -ENOMEM;
2372 : : }
2373 : :
2374 : : /* Allocate memory for the PF "device" */
2375 : 0 : function_id = (pci_dev->addr.function) & 0x07;
2376 : 0 : snprintf(name, sizeof(name), "nfp_pf%u", function_id);
2377 : 0 : pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
2378 [ # # ]: 0 : if (pf_dev == NULL) {
2379 : 0 : PMD_INIT_LOG(ERR, "Can not allocate memory for the PF device.");
2380 : 0 : ret = -ENOMEM;
2381 : 0 : goto hw_priv_free;
2382 : : }
2383 : :
2384 : 0 : hw_priv->dev_info = dev_info;
2385 : 0 : hw_priv->pf_dev = pf_dev;
2386 : :
2387 : 0 : sync = nfp_sync_alloc();
2388 [ # # ]: 0 : if (sync == NULL) {
2389 : 0 : PMD_INIT_LOG(ERR, "Failed to alloc sync zone.");
2390 : 0 : ret = -ENOMEM;
2391 : 0 : goto pf_cleanup;
2392 : : }
2393 : :
2394 : 0 : pf_dev->sync = sync;
2395 : :
2396 : : /*
2397 : : * When device bound to UIO, the device could be used, by mistake,
2398 : : * by two DPDK apps, and the UIO driver does not avoid it. This
2399 : : * could lead to a serious problem when configuring the NFP CPP
2400 : : * interface. Here we avoid this telling to the CPP init code to
2401 : : * use a lock file if UIO is being used.
2402 : : */
2403 [ # # ]: 0 : if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
2404 : 0 : cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false);
2405 : : else
2406 : 0 : cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true);
2407 : :
2408 [ # # ]: 0 : if (cpp == NULL) {
2409 : 0 : PMD_INIT_LOG(ERR, "A CPP handle can not be obtained.");
2410 : 0 : ret = -EIO;
2411 : 0 : goto sync_free;
2412 : : }
2413 : :
2414 : 0 : pf_dev->cpp = cpp;
2415 : 0 : pf_dev->pci_dev = pci_dev;
2416 : :
2417 : 0 : hwinfo = nfp_hwinfo_read(cpp);
2418 [ # # ]: 0 : if (hwinfo == NULL) {
2419 : 0 : PMD_INIT_LOG(ERR, "Error reading hwinfo table.");
2420 : 0 : ret = -EIO;
2421 : 0 : goto cpp_cleanup;
2422 : : }
2423 : :
2424 : 0 : pf_dev->hwinfo = hwinfo;
2425 : :
2426 : : /* Read the number of physical ports from hardware */
2427 : 0 : nfp_eth_table = nfp_eth_read_ports(cpp);
2428 [ # # ]: 0 : if (nfp_eth_table == NULL) {
2429 : 0 : PMD_INIT_LOG(ERR, "Error reading NFP ethernet table.");
2430 : 0 : ret = -EIO;
2431 : 0 : goto hwinfo_cleanup;
2432 : : }
2433 : :
2434 [ # # ]: 0 : if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
2435 : 0 : PMD_INIT_LOG(ERR, "NFP ethernet table reports wrong ports: %u.",
2436 : : nfp_eth_table->count);
2437 : 0 : ret = -EIO;
2438 : 0 : goto eth_table_cleanup;
2439 : : }
2440 : :
2441 : 0 : ret = nfp_check_multi_pf_from_nsp(pci_dev, cpp, &pf_dev->multi_pf.enabled);
2442 [ # # ]: 0 : if (ret != 0) {
2443 : 0 : PMD_INIT_LOG(ERR, "Failed to check multi pf from NSP.");
2444 : 0 : goto eth_table_cleanup;
2445 : : }
2446 : :
2447 : 0 : pf_dev->nfp_eth_table = nfp_eth_table;
2448 : 0 : pf_dev->multi_pf.function_id = function_id;
2449 : 0 : pf_dev->total_phyports = nfp_net_get_phyports_from_nsp(pf_dev);
2450 : :
2451 : 0 : ret = nfp_net_force_port_down(pf_dev);
2452 [ # # ]: 0 : if (ret != 0) {
2453 : 0 : PMD_INIT_LOG(ERR, "Failed to force port down.");
2454 : 0 : ret = -EIO;
2455 : 0 : goto eth_table_cleanup;
2456 : : }
2457 : :
2458 : 0 : ret = nfp_devargs_parse(&pf_dev->devargs, pci_dev->device.devargs);
2459 [ # # ]: 0 : if (ret != 0) {
2460 : 0 : PMD_INIT_LOG(ERR, "Error when parsing device args.");
2461 : 0 : ret = -EINVAL;
2462 : 0 : goto eth_table_cleanup;
2463 : : }
2464 : :
2465 : 0 : ret = nfp_net_device_activate(pf_dev);
2466 [ # # ]: 0 : if (ret != 0) {
2467 : 0 : PMD_INIT_LOG(ERR, "Failed to activate the NFP device.");
2468 : 0 : ret = -EIO;
2469 : 0 : goto eth_table_cleanup;
2470 : : }
2471 : :
2472 : 0 : ret = nfp_fw_setup(pf_dev, dev_info);
2473 [ # # ]: 0 : if (ret != 0) {
2474 : 0 : PMD_INIT_LOG(ERR, "Error when uploading firmware.");
2475 : 0 : ret = -EIO;
2476 : 0 : goto eth_table_cleanup;
2477 : : }
2478 : :
2479 : : /* Now the symbol table should be there */
2480 : 0 : sym_tbl = nfp_rtsym_table_read(cpp);
2481 [ # # ]: 0 : if (sym_tbl == NULL) {
2482 : 0 : PMD_INIT_LOG(ERR, "Something is wrong with the firmware symbol table.");
2483 : 0 : ret = -EIO;
2484 : 0 : goto fw_cleanup;
2485 : : }
2486 : :
2487 : 0 : pf_dev->sym_tbl = sym_tbl;
2488 : :
2489 : : /* Read the app ID of the firmware loaded */
2490 : : snprintf(app_name, sizeof(app_name), "_pf%u_net_app_id", function_id);
2491 : 0 : app_fw_id = nfp_rtsym_read_le(sym_tbl, app_name, &ret);
2492 [ # # ]: 0 : if (ret != 0) {
2493 : 0 : PMD_INIT_LOG(ERR, "Could not read %s from firmware.", app_name);
2494 : 0 : ret = -EIO;
2495 : 0 : goto sym_tbl_cleanup;
2496 : : }
2497 : :
2498 : 0 : pf_dev->app_fw_id = app_fw_id;
2499 : :
2500 : : /* Write sp_indiff to hw_info */
2501 : 0 : ret = nfp_net_hwinfo_set(function_id, sym_tbl, cpp, app_fw_id);
2502 [ # # ]: 0 : if (ret != 0) {
2503 : 0 : PMD_INIT_LOG(ERR, "Failed to set hwinfo.");
2504 : 0 : ret = -EIO;
2505 : 0 : goto sym_tbl_cleanup;
2506 : : }
2507 : :
2508 : 0 : ret = nfp_net_speed_cap_get(pf_dev);
2509 [ # # ]: 0 : if (ret != 0) {
2510 : 0 : PMD_INIT_LOG(ERR, "Failed to get speed capability.");
2511 : 0 : ret = -EIO;
2512 : 0 : goto sym_tbl_cleanup;
2513 : : }
2514 : :
2515 : : /* Get the VF info */
2516 : 0 : ret = nfp_net_get_vf_info(pf_dev, dev_info);
2517 [ # # ]: 0 : if (ret != 0) {
2518 : 0 : PMD_INIT_LOG(ERR, "Failed to get VF info.");
2519 : 0 : ret = -EIO;
2520 : 0 : goto sym_tbl_cleanup;
2521 : : }
2522 : :
2523 : : /* Configure access to tx/rx vNIC BARs */
2524 : 0 : addr = nfp_qcp_queue_offset(dev_info, 0);
2525 : : cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0);
2526 : :
2527 : 0 : pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id,
2528 : 0 : addr, dev_info->qc_area_sz, &pf_dev->qc_area);
2529 [ # # ]: 0 : if (pf_dev->qc_bar == NULL) {
2530 : 0 : PMD_INIT_LOG(ERR, "The nfp_rtsym_map fails for net.qc.");
2531 : 0 : ret = -EIO;
2532 : 0 : goto sym_tbl_cleanup;
2533 : : }
2534 : :
2535 : 0 : PMD_INIT_LOG(DEBUG, "The qc_bar address: %p.", pf_dev->qc_bar);
2536 : :
2537 : 0 : pf_dev->mac_stats_bar = nfp_rtsym_map(sym_tbl, "_mac_stats",
2538 : 0 : NFP_MAC_STATS_SIZE * nfp_eth_table->max_index,
2539 : : &pf_dev->mac_stats_area);
2540 [ # # ]: 0 : if (pf_dev->mac_stats_bar == NULL) {
2541 : 0 : PMD_INIT_LOG(ERR, "The nfp_rtsym_map fails for _mac_stats.");
2542 : 0 : goto hwqueues_cleanup;
2543 : : }
2544 : :
2545 : 0 : ret = nfp_enable_multi_pf(pf_dev);
2546 [ # # ]: 0 : if (ret != 0)
2547 : 0 : goto mac_stats_cleanup;
2548 : :
2549 : 0 : ret = nfp_net_vf_config_init(pf_dev);
2550 [ # # ]: 0 : if (ret != 0) {
2551 : 0 : PMD_INIT_LOG(ERR, "Failed to init VF config.");
2552 : 0 : goto vf_cfg_tbl_cleanup;
2553 : : }
2554 : :
2555 : 0 : hw_priv->is_pf = true;
2556 : :
2557 [ # # ]: 0 : if (!nfp_net_recv_pkt_meta_check_register(hw_priv)) {
2558 : 0 : PMD_INIT_LOG(ERR, "PF register meta check function failed.");
2559 : 0 : ret = -EIO;
2560 : 0 : goto hw_priv_free;
2561 : : }
2562 : :
2563 : : /*
2564 : : * PF initialization has been done at this point. Call app specific
2565 : : * init code now.
2566 : : */
2567 : 0 : ret = nfp_fw_app_primary_init(hw_priv);
2568 [ # # ]: 0 : if (ret != 0) {
2569 : 0 : PMD_INIT_LOG(ERR, "Failed to init hw app primary.");
2570 : 0 : goto vf_cfg_tbl_cleanup;
2571 : : }
2572 : :
2573 : : /* Register the CPP bridge service here for primary use */
2574 [ # # ]: 0 : if (pf_dev->devargs.cpp_service_enable) {
2575 : 0 : ret = nfp_enable_cpp_service(pf_dev);
2576 [ # # ]: 0 : if (ret != 0) {
2577 : 0 : PMD_INIT_LOG(ERR, "Enable CPP service failed.");
2578 : 0 : goto vf_cfg_tbl_cleanup;
2579 : : }
2580 : : }
2581 : :
2582 : : return 0;
2583 : :
2584 : 0 : vf_cfg_tbl_cleanup:
2585 : 0 : nfp_net_vf_config_uninit(pf_dev);
2586 : 0 : mac_stats_cleanup:
2587 : 0 : nfp_cpp_area_release_free(pf_dev->mac_stats_area);
2588 : 0 : hwqueues_cleanup:
2589 : 0 : nfp_cpp_area_release_free(pf_dev->qc_area);
2590 : 0 : sym_tbl_cleanup:
2591 : 0 : free(sym_tbl);
2592 : 0 : fw_cleanup:
2593 : 0 : nfp_fw_unload(cpp);
2594 [ # # ]: 0 : if (pf_dev->multi_pf.enabled) {
2595 : 0 : nfp_net_keepalive_stop(&pf_dev->multi_pf);
2596 : 0 : nfp_net_keepalive_clear(pf_dev->multi_pf.beat_addr, pf_dev->multi_pf.function_id);
2597 : : nfp_net_keepalive_uninit(&pf_dev->multi_pf);
2598 : : }
2599 : 0 : eth_table_cleanup:
2600 : 0 : free(nfp_eth_table);
2601 : 0 : hwinfo_cleanup:
2602 : 0 : free(hwinfo);
2603 : 0 : cpp_cleanup:
2604 : 0 : nfp_cpp_free(cpp);
2605 : 0 : sync_free:
2606 : 0 : nfp_sync_free(sync);
2607 : 0 : pf_cleanup:
2608 : 0 : rte_free(pf_dev);
2609 : 0 : hw_priv_free:
2610 : 0 : rte_free(hw_priv);
2611 : :
2612 : 0 : return ret;
2613 : : }
2614 : :
2615 : : static int
2616 : 0 : nfp_secondary_net_init(struct rte_eth_dev *eth_dev,
2617 : : void *para)
2618 : : {
2619 : : struct nfp_net_hw_priv *hw_priv;
2620 : :
2621 : : hw_priv = para;
2622 : 0 : nfp_net_ethdev_ops_mount(hw_priv->pf_dev, eth_dev);
2623 : :
2624 : 0 : eth_dev->process_private = para;
2625 : :
2626 : 0 : return 0;
2627 : : }
2628 : :
2629 : : static int
2630 : 0 : nfp_secondary_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
2631 : : {
2632 : : uint32_t i;
2633 : : int ret = 0;
2634 : : uint32_t total_vnics;
2635 : : char port_name[RTE_ETH_NAME_MAX_LEN];
2636 : 0 : struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
2637 : :
2638 : 0 : total_vnics = nfp_net_get_phyports_from_fw(pf_dev);
2639 : :
2640 [ # # ]: 0 : for (i = 0; i < total_vnics; i++) {
2641 : 0 : nfp_port_name_generate(port_name, sizeof(port_name), i, pf_dev);
2642 : :
2643 : 0 : PMD_INIT_LOG(DEBUG, "Secondary attaching to port %s.", port_name);
2644 : 0 : ret = rte_eth_dev_create(&pf_dev->pci_dev->device, port_name, 0,
2645 : : NULL, NULL, nfp_secondary_net_init, hw_priv);
2646 [ # # ]: 0 : if (ret != 0) {
2647 : 0 : PMD_INIT_LOG(ERR, "Secondary process attach to port %s failed.", port_name);
2648 : 0 : goto port_cleanup;
2649 : : }
2650 : : }
2651 : :
2652 : : return 0;
2653 : :
2654 : : port_cleanup:
2655 [ # # ]: 0 : for (uint32_t j = 0; j < i; j++) {
2656 : : struct rte_eth_dev *eth_dev;
2657 : :
2658 : 0 : nfp_port_name_generate(port_name, sizeof(port_name), j, pf_dev);
2659 : 0 : eth_dev = rte_eth_dev_get_by_name(port_name);
2660 [ # # ]: 0 : if (eth_dev != NULL)
2661 : 0 : rte_eth_dev_destroy(eth_dev, NULL);
2662 : : }
2663 : :
2664 : : return ret;
2665 : : }
2666 : :
2667 : : static int
2668 : 0 : nfp_fw_app_secondary_init(struct nfp_net_hw_priv *hw_priv)
2669 : : {
2670 : : int ret;
2671 : 0 : struct nfp_pf_dev *pf_dev = hw_priv->pf_dev;
2672 : :
2673 [ # # # ]: 0 : switch (pf_dev->app_fw_id) {
2674 : 0 : case NFP_APP_FW_CORE_NIC:
2675 : 0 : PMD_INIT_LOG(INFO, "Initializing coreNIC.");
2676 : 0 : ret = nfp_secondary_init_app_fw_nic(hw_priv);
2677 [ # # ]: 0 : if (ret != 0) {
2678 : 0 : PMD_INIT_LOG(ERR, "Could not initialize coreNIC!");
2679 : 0 : return ret;
2680 : : }
2681 : : break;
2682 : 0 : case NFP_APP_FW_FLOWER_NIC:
2683 : 0 : PMD_INIT_LOG(INFO, "Initializing Flower.");
2684 : 0 : ret = nfp_secondary_init_app_fw_flower(hw_priv);
2685 [ # # ]: 0 : if (ret != 0) {
2686 : 0 : PMD_INIT_LOG(ERR, "Could not initialize Flower!");
2687 : 0 : return ret;
2688 : : }
2689 : : break;
2690 : 0 : default:
2691 : 0 : PMD_INIT_LOG(ERR, "Unsupported Firmware loaded.");
2692 : : ret = -EINVAL;
2693 : 0 : return ret;
2694 : : }
2695 : :
2696 : : return 0;
2697 : : }
2698 : :
2699 : : /*
2700 : : * When attaching to the NFP4000/6000 PF on a secondary process there
2701 : : * is no need to initialise the PF again. Only minimal work is required
2702 : : * here.
2703 : : */
2704 : : static int
2705 : 0 : nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
2706 : : {
2707 : : void *sync;
2708 : 0 : int ret = 0;
2709 : : struct nfp_cpp *cpp;
2710 : : uint8_t function_id;
2711 : : struct nfp_pf_dev *pf_dev;
2712 : : enum nfp_app_fw_id app_fw_id;
2713 : : char name[RTE_ETH_NAME_MAX_LEN];
2714 : : struct nfp_rtsym_table *sym_tbl;
2715 : : struct nfp_net_hw_priv *hw_priv;
2716 : : const struct nfp_dev_info *dev_info;
2717 : : char app_name[RTE_ETH_NAME_MAX_LEN];
2718 : :
2719 [ # # ]: 0 : if (pci_dev == NULL)
2720 : : return -ENODEV;
2721 : :
2722 [ # # ]: 0 : if (pci_dev->mem_resource[0].addr == NULL) {
2723 : 0 : PMD_INIT_LOG(ERR, "The address of BAR0 is NULL.");
2724 : 0 : return -ENODEV;
2725 : : }
2726 : :
2727 : 0 : dev_info = nfp_dev_info_get(pci_dev->id.device_id);
2728 [ # # ]: 0 : if (dev_info == NULL) {
2729 : 0 : PMD_INIT_LOG(ERR, "Not supported device ID.");
2730 : 0 : return -ENODEV;
2731 : : }
2732 : :
2733 : 0 : hw_priv = rte_zmalloc(NULL, sizeof(*hw_priv), 0);
2734 [ # # ]: 0 : if (hw_priv == NULL) {
2735 : 0 : PMD_INIT_LOG(ERR, "Can not alloc memory for hw priv data.");
2736 : 0 : return -ENOMEM;
2737 : : }
2738 : :
2739 : : /* Allocate memory for the PF "device" */
2740 : 0 : function_id = pci_dev->addr.function & 0x7;
2741 : : snprintf(name, sizeof(name), "nfp_pf%d", 0);
2742 : 0 : pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
2743 [ # # ]: 0 : if (pf_dev == NULL) {
2744 : 0 : PMD_INIT_LOG(ERR, "Can not allocate memory for the PF device.");
2745 : 0 : ret = -ENOMEM;
2746 : 0 : goto hw_priv_free;
2747 : : }
2748 : :
2749 : 0 : hw_priv->pf_dev = pf_dev;
2750 : 0 : hw_priv->dev_info = dev_info;
2751 : :
2752 : 0 : sync = nfp_sync_alloc();
2753 [ # # ]: 0 : if (sync == NULL) {
2754 : 0 : PMD_INIT_LOG(ERR, "Failed to alloc sync zone.");
2755 : 0 : ret = -ENOMEM;
2756 : 0 : goto pf_cleanup;
2757 : : }
2758 : :
2759 : 0 : pf_dev->sync = sync;
2760 : :
2761 : : /*
2762 : : * When device bound to UIO, the device could be used, by mistake,
2763 : : * by two DPDK apps, and the UIO driver does not avoid it. This
2764 : : * could lead to a serious problem when configuring the NFP CPP
2765 : : * interface. Here we avoid this telling to the CPP init code to
2766 : : * use a lock file if UIO is being used.
2767 : : */
2768 [ # # ]: 0 : if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
2769 : 0 : cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false);
2770 : : else
2771 : 0 : cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true);
2772 : :
2773 [ # # ]: 0 : if (cpp == NULL) {
2774 : 0 : PMD_INIT_LOG(ERR, "A CPP handle can not be obtained.");
2775 : 0 : ret = -EIO;
2776 : 0 : goto sync_free;
2777 : : }
2778 : :
2779 : 0 : pf_dev->cpp = cpp;
2780 : 0 : pf_dev->pci_dev = pci_dev;
2781 : :
2782 : : /*
2783 : : * We don't have access to the PF created in the primary process
2784 : : * here so we have to read the number of ports from firmware.
2785 : : */
2786 : 0 : sym_tbl = nfp_rtsym_table_read(cpp);
2787 [ # # ]: 0 : if (sym_tbl == NULL) {
2788 : 0 : PMD_INIT_LOG(ERR, "Something is wrong with the firmware symbol table.");
2789 : 0 : ret = -EIO;
2790 : 0 : goto cpp_cleanup;
2791 : : }
2792 : :
2793 : 0 : pf_dev->sym_tbl = sym_tbl;
2794 : :
2795 : : /* Read the number of physical ports from firmware */
2796 : 0 : pf_dev->multi_pf.function_id = function_id;
2797 [ # # ]: 0 : pf_dev->total_phyports = nfp_net_get_phyports_from_fw(pf_dev);
2798 : 0 : pf_dev->multi_pf.enabled = nfp_check_multi_pf_from_fw(pf_dev->total_phyports);
2799 : :
2800 : : /* Read the app ID of the firmware loaded */
2801 : 0 : snprintf(app_name, sizeof(app_name), "_pf%u_net_app_id", function_id);
2802 : 0 : app_fw_id = nfp_rtsym_read_le(sym_tbl, app_name, &ret);
2803 [ # # ]: 0 : if (ret != 0) {
2804 : 0 : PMD_INIT_LOG(ERR, "Could not read %s from fw.", app_name);
2805 : 0 : ret = -EIO;
2806 : 0 : goto sym_tbl_cleanup;
2807 : : }
2808 : :
2809 : 0 : pf_dev->app_fw_id = app_fw_id;
2810 : :
2811 : 0 : hw_priv->is_pf = true;
2812 : :
2813 : : /* Call app specific init code now */
2814 : 0 : ret = nfp_fw_app_secondary_init(hw_priv);
2815 [ # # ]: 0 : if (ret != 0) {
2816 : 0 : PMD_INIT_LOG(ERR, "Failed to init hw app primary.");
2817 : 0 : goto sym_tbl_cleanup;
2818 : : }
2819 : :
2820 : : return 0;
2821 : :
2822 : 0 : sym_tbl_cleanup:
2823 : 0 : free(sym_tbl);
2824 : 0 : cpp_cleanup:
2825 : 0 : nfp_cpp_free(cpp);
2826 : 0 : sync_free:
2827 : 0 : nfp_sync_free(sync);
2828 : 0 : pf_cleanup:
2829 : 0 : rte_free(pf_dev);
2830 : 0 : hw_priv_free:
2831 : 0 : rte_free(hw_priv);
2832 : :
2833 : 0 : return ret;
2834 : : }
2835 : :
2836 : : static int
2837 : 0 : nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2838 : : struct rte_pci_device *dev)
2839 : : {
2840 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2841 : 0 : return nfp_pf_init(dev);
2842 : : else
2843 : 0 : return nfp_pf_secondary_init(dev);
2844 : : }
2845 : :
2846 : : static const struct rte_pci_id pci_id_nfp_pf_net_map[] = {
2847 : : {
2848 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2849 : : PCI_DEVICE_ID_NFP3800_PF_NIC)
2850 : : },
2851 : : {
2852 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2853 : : PCI_DEVICE_ID_NFP4000_PF_NIC)
2854 : : },
2855 : : {
2856 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2857 : : PCI_DEVICE_ID_NFP6000_PF_NIC)
2858 : : },
2859 : : {
2860 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_CORIGINE,
2861 : : PCI_DEVICE_ID_NFP3800_PF_NIC)
2862 : : },
2863 : : {
2864 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_CORIGINE,
2865 : : PCI_DEVICE_ID_NFP4000_PF_NIC)
2866 : : },
2867 : : {
2868 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_CORIGINE,
2869 : : PCI_DEVICE_ID_NFP6000_PF_NIC)
2870 : : },
2871 : : {
2872 : : .vendor_id = 0,
2873 : : },
2874 : : };
2875 : :
2876 : : static int
2877 : 0 : nfp_pci_uninit(struct rte_eth_dev *eth_dev)
2878 : : {
2879 : : uint16_t port_id;
2880 : : struct rte_pci_device *pci_dev;
2881 : :
2882 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2883 : :
2884 : : /* Free up all physical ports under PF */
2885 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
2886 : 0 : rte_eth_dev_close(port_id);
2887 : : /*
2888 : : * Ports can be closed and freed but hotplugging is not
2889 : : * currently supported.
2890 : : */
2891 : 0 : return -ENOTSUP;
2892 : : }
2893 : :
2894 : : static int
2895 : 0 : eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
2896 : : {
2897 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, nfp_pci_uninit);
2898 : : }
2899 : :
2900 : : static struct rte_pci_driver rte_nfp_net_pf_pmd = {
2901 : : .id_table = pci_id_nfp_pf_net_map,
2902 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2903 : : .probe = nfp_pf_pci_probe,
2904 : : .remove = eth_nfp_pci_remove,
2905 : : };
2906 : :
2907 : 252 : RTE_PMD_REGISTER_PCI(NFP_PF_DRIVER_NAME, rte_nfp_net_pf_pmd);
2908 : : RTE_PMD_REGISTER_PCI_TABLE(NFP_PF_DRIVER_NAME, pci_id_nfp_pf_net_map);
2909 : : RTE_PMD_REGISTER_KMOD_DEP(NFP_PF_DRIVER_NAME, "* igb_uio | uio_pci_generic | vfio");
2910 : : RTE_PMD_REGISTER_PARAM_STRING(NFP_PF_DRIVER_NAME,
2911 : : NFP_PF_FORCE_RELOAD_FW "=<0|1>"
2912 : : NFP_CPP_SERVICE_ENABLE "=<0|1>");
|