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