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