Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022 Corigine, Inc.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include "nfp_flower_representor.h"
7 : :
8 : : #include "../nfd3/nfp_nfd3.h"
9 : : #include "../nfpcore/nfp_nsp.h"
10 : : #include "../nfp_logs.h"
11 : : #include "../nfp_mtr.h"
12 : :
13 : : /* Type of representor */
14 : : enum nfp_repr_type {
15 : : NFP_REPR_TYPE_PHYS_PORT, /*<< External NIC port */
16 : : NFP_REPR_TYPE_PF, /*<< Physical function */
17 : : NFP_REPR_TYPE_VF, /*<< Virtual function */
18 : : NFP_REPR_TYPE_MAX, /*<< Number of representor types */
19 : : };
20 : :
21 : : static int
22 : 0 : nfp_flower_repr_link_update(struct rte_eth_dev *dev,
23 : : __rte_unused int wait_to_complete)
24 : : {
25 : : int ret;
26 : : uint32_t nn_link_status;
27 : : struct nfp_net_hw *pf_hw;
28 : : struct rte_eth_link *link;
29 : : struct nfp_flower_representor *repr;
30 : :
31 : 0 : repr = dev->data->dev_private;
32 : 0 : link = &repr->link;
33 : :
34 : 0 : pf_hw = repr->app_fw_flower->pf_hw;
35 : 0 : nn_link_status = nn_cfg_readw(&pf_hw->super, NFP_NET_CFG_STS);
36 : :
37 : 0 : ret = nfp_net_link_update_common(dev, pf_hw, link, nn_link_status);
38 : :
39 : 0 : return ret;
40 : : }
41 : :
42 : : static int
43 : 0 : nfp_flower_repr_dev_infos_get(__rte_unused struct rte_eth_dev *dev,
44 : : struct rte_eth_dev_info *dev_info)
45 : : {
46 : : /* Hardcoded pktlen and queues for now */
47 : 0 : dev_info->max_rx_queues = 1;
48 : 0 : dev_info->max_tx_queues = 1;
49 : 0 : dev_info->min_rx_bufsize = RTE_ETHER_MIN_MTU;
50 : 0 : dev_info->max_rx_pktlen = 9000;
51 : :
52 : : dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
53 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
54 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
55 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM;
56 : :
57 : : dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
58 : : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
59 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
60 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
61 : : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_TCP_TSO;
62 : 0 : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
63 : :
64 : 0 : dev_info->max_mac_addrs = 1;
65 : :
66 : 0 : return 0;
67 : : }
68 : :
69 : : static int
70 : 0 : nfp_flower_repr_dev_start(struct rte_eth_dev *dev)
71 : : {
72 : : struct nfp_flower_representor *repr;
73 : : struct nfp_app_fw_flower *app_fw_flower;
74 : : uint16_t i;
75 : :
76 : 0 : repr = dev->data->dev_private;
77 : 0 : app_fw_flower = repr->app_fw_flower;
78 : :
79 [ # # ]: 0 : if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT) {
80 : 0 : nfp_eth_set_configured(app_fw_flower->pf_hw->pf_dev->cpp,
81 : : repr->nfp_idx, 1);
82 : : }
83 : :
84 : 0 : nfp_flower_cmsg_port_mod(app_fw_flower, repr->port_id, true);
85 : :
86 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
87 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
88 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
89 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
90 : :
91 : 0 : return 0;
92 : : }
93 : :
94 : : static int
95 : 0 : nfp_flower_repr_dev_stop(struct rte_eth_dev *dev)
96 : : {
97 : : struct nfp_flower_representor *repr;
98 : : struct nfp_app_fw_flower *app_fw_flower;
99 : : uint16_t i;
100 : :
101 : 0 : repr = dev->data->dev_private;
102 : 0 : app_fw_flower = repr->app_fw_flower;
103 : :
104 : 0 : nfp_flower_cmsg_port_mod(app_fw_flower, repr->port_id, false);
105 : :
106 [ # # ]: 0 : if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT) {
107 : 0 : nfp_eth_set_configured(app_fw_flower->pf_hw->pf_dev->cpp,
108 : : repr->nfp_idx, 0);
109 : : }
110 : :
111 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
112 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
113 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
114 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
115 : :
116 : 0 : return 0;
117 : : }
118 : :
119 : : static int
120 : 0 : nfp_flower_repr_rx_queue_setup(struct rte_eth_dev *dev,
121 : : uint16_t rx_queue_id,
122 : : __rte_unused uint16_t nb_rx_desc,
123 : : unsigned int socket_id,
124 : : __rte_unused const struct rte_eth_rxconf *rx_conf,
125 : : __rte_unused struct rte_mempool *mb_pool)
126 : : {
127 : : struct nfp_net_rxq *rxq;
128 : : struct nfp_net_hw *pf_hw;
129 : : struct nfp_flower_representor *repr;
130 : :
131 : 0 : repr = dev->data->dev_private;
132 : 0 : pf_hw = repr->app_fw_flower->pf_hw;
133 : :
134 : : /* Allocating rx queue data structure */
135 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct nfp_net_rxq),
136 : : RTE_CACHE_LINE_SIZE, socket_id);
137 [ # # ]: 0 : if (rxq == NULL)
138 : : return -ENOMEM;
139 : :
140 : 0 : rxq->hw = pf_hw;
141 : 0 : rxq->qidx = rx_queue_id;
142 : 0 : rxq->port_id = dev->data->port_id;
143 : 0 : dev->data->rx_queues[rx_queue_id] = rxq;
144 : :
145 : 0 : return 0;
146 : : }
147 : :
148 : : static int
149 : 0 : nfp_flower_repr_tx_queue_setup(struct rte_eth_dev *dev,
150 : : uint16_t tx_queue_id,
151 : : __rte_unused uint16_t nb_tx_desc,
152 : : unsigned int socket_id,
153 : : __rte_unused const struct rte_eth_txconf *tx_conf)
154 : : {
155 : : struct nfp_net_txq *txq;
156 : : struct nfp_net_hw *pf_hw;
157 : : struct nfp_flower_representor *repr;
158 : :
159 : 0 : repr = dev->data->dev_private;
160 : 0 : pf_hw = repr->app_fw_flower->pf_hw;
161 : :
162 : : /* Allocating tx queue data structure */
163 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nfp_net_txq),
164 : : RTE_CACHE_LINE_SIZE, socket_id);
165 [ # # ]: 0 : if (txq == NULL)
166 : : return -ENOMEM;
167 : :
168 : 0 : txq->hw = pf_hw;
169 : 0 : txq->qidx = tx_queue_id;
170 : 0 : txq->port_id = dev->data->port_id;
171 : 0 : dev->data->tx_queues[tx_queue_id] = txq;
172 : :
173 : 0 : return 0;
174 : : }
175 : :
176 : : static int
177 : 0 : nfp_flower_repr_stats_get(struct rte_eth_dev *ethdev,
178 : : struct rte_eth_stats *stats)
179 : : {
180 : : struct nfp_flower_representor *repr;
181 : :
182 : 0 : repr = ethdev->data->dev_private;
183 [ # # ]: 0 : rte_memcpy(stats, &repr->repr_stats, sizeof(struct rte_eth_stats));
184 : :
185 : 0 : return 0;
186 : : }
187 : :
188 : : static int
189 : 0 : nfp_flower_repr_stats_reset(struct rte_eth_dev *ethdev)
190 : : {
191 : : struct nfp_flower_representor *repr;
192 : :
193 : 0 : repr = ethdev->data->dev_private;
194 : 0 : memset(&repr->repr_stats, 0, sizeof(struct rte_eth_stats));
195 : :
196 : 0 : return 0;
197 : : }
198 : :
199 : : static int
200 : 0 : nfp_flower_repr_mac_addr_set(struct rte_eth_dev *ethdev,
201 : : struct rte_ether_addr *mac_addr)
202 : : {
203 : : struct nfp_flower_representor *repr;
204 : :
205 : 0 : repr = ethdev->data->dev_private;
206 : : rte_ether_addr_copy(mac_addr, &repr->mac_addr);
207 : 0 : rte_ether_addr_copy(mac_addr, ethdev->data->mac_addrs);
208 : :
209 : 0 : return 0;
210 : : }
211 : :
212 : : static uint16_t
213 : 0 : nfp_flower_repr_rx_burst(void *rx_queue,
214 : : struct rte_mbuf **rx_pkts,
215 : : uint16_t nb_pkts)
216 : : {
217 : : unsigned int available = 0;
218 : : unsigned int total_dequeue;
219 : : struct nfp_net_rxq *rxq;
220 : : struct rte_eth_dev *dev;
221 : : struct nfp_flower_representor *repr;
222 : :
223 : : rxq = rx_queue;
224 [ # # ]: 0 : if (unlikely(rxq == NULL)) {
225 : : PMD_RX_LOG(ERR, "RX Bad queue");
226 : : return 0;
227 : : }
228 : :
229 : 0 : dev = &rte_eth_devices[rxq->port_id];
230 : 0 : repr = dev->data->dev_private;
231 [ # # ]: 0 : if (unlikely(repr->ring == NULL)) {
232 : : PMD_RX_LOG(ERR, "representor %s has no ring configured!",
233 : : repr->name);
234 : : return 0;
235 : : }
236 : :
237 [ # # # # : 0 : total_dequeue = rte_ring_dequeue_burst(repr->ring, (void *)rx_pkts,
# ]
238 : : nb_pkts, &available);
239 [ # # ]: 0 : if (total_dequeue != 0) {
240 : : PMD_RX_LOG(DEBUG, "Representor Rx burst for %s, port_id: %#x, "
241 : : "received: %u, available: %u", repr->name,
242 : : repr->port_id, total_dequeue, available);
243 : :
244 : 0 : repr->repr_stats.ipackets += total_dequeue;
245 : : }
246 : :
247 : 0 : return total_dequeue;
248 : : }
249 : :
250 : : static uint16_t
251 : 0 : nfp_flower_repr_tx_burst(void *tx_queue,
252 : : struct rte_mbuf **tx_pkts,
253 : : uint16_t nb_pkts)
254 : : {
255 : : uint16_t i;
256 : : uint16_t sent;
257 : : void *pf_tx_queue;
258 : : struct nfp_net_txq *txq;
259 : : struct nfp_net_hw *pf_hw;
260 : : struct rte_eth_dev *dev;
261 : : struct rte_eth_dev *repr_dev;
262 : : struct nfp_flower_representor *repr;
263 : :
264 : : txq = tx_queue;
265 [ # # ]: 0 : if (unlikely(txq == NULL)) {
266 : : PMD_TX_LOG(ERR, "TX Bad queue");
267 : : return 0;
268 : : }
269 : :
270 : : /* Grab a handle to the representor struct */
271 : 0 : repr_dev = &rte_eth_devices[txq->port_id];
272 : 0 : repr = repr_dev->data->dev_private;
273 : :
274 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++)
275 : 0 : nfp_flower_pkt_add_metadata(repr->app_fw_flower,
276 : 0 : tx_pkts[i], repr->port_id);
277 : :
278 : : /* This points to the PF vNIC that owns this representor */
279 : 0 : pf_hw = txq->hw;
280 : 0 : dev = pf_hw->eth_dev;
281 : :
282 : : /* Only using Tx queue 0 for now. */
283 : 0 : pf_tx_queue = dev->data->tx_queues[0];
284 : 0 : sent = nfp_flower_pf_xmit_pkts(pf_tx_queue, tx_pkts, nb_pkts);
285 [ # # ]: 0 : if (sent != 0) {
286 : : PMD_TX_LOG(DEBUG, "Representor Tx burst for %s, port_id: %#x transmitted: %hu",
287 : : repr->name, repr->port_id, sent);
288 : 0 : repr->repr_stats.opackets += sent;
289 : : }
290 : :
291 : : return sent;
292 : : }
293 : :
294 : : static const struct eth_dev_ops nfp_flower_pf_repr_dev_ops = {
295 : : .dev_infos_get = nfp_flower_repr_dev_infos_get,
296 : :
297 : : .dev_start = nfp_flower_pf_start,
298 : : .dev_configure = nfp_net_configure,
299 : : .dev_stop = nfp_net_stop,
300 : :
301 : : .rx_queue_setup = nfp_net_rx_queue_setup,
302 : : .tx_queue_setup = nfp_net_tx_queue_setup,
303 : :
304 : : .link_update = nfp_flower_repr_link_update,
305 : :
306 : : .stats_get = nfp_flower_repr_stats_get,
307 : : .stats_reset = nfp_flower_repr_stats_reset,
308 : :
309 : : .promiscuous_enable = nfp_net_promisc_enable,
310 : : .promiscuous_disable = nfp_net_promisc_disable,
311 : :
312 : : .mac_addr_set = nfp_flower_repr_mac_addr_set,
313 : : .fw_version_get = nfp_net_firmware_version_get,
314 : : };
315 : :
316 : : static const struct eth_dev_ops nfp_flower_repr_dev_ops = {
317 : : .dev_infos_get = nfp_flower_repr_dev_infos_get,
318 : :
319 : : .dev_start = nfp_flower_repr_dev_start,
320 : : .dev_configure = nfp_net_configure,
321 : : .dev_stop = nfp_flower_repr_dev_stop,
322 : :
323 : : .rx_queue_setup = nfp_flower_repr_rx_queue_setup,
324 : : .tx_queue_setup = nfp_flower_repr_tx_queue_setup,
325 : :
326 : : .link_update = nfp_flower_repr_link_update,
327 : :
328 : : .stats_get = nfp_flower_repr_stats_get,
329 : : .stats_reset = nfp_flower_repr_stats_reset,
330 : :
331 : : .promiscuous_enable = nfp_net_promisc_enable,
332 : : .promiscuous_disable = nfp_net_promisc_disable,
333 : :
334 : : .mac_addr_set = nfp_flower_repr_mac_addr_set,
335 : : .fw_version_get = nfp_net_firmware_version_get,
336 : :
337 : : .flow_ops_get = nfp_net_flow_ops_get,
338 : : .mtr_ops_get = nfp_net_mtr_ops_get,
339 : : };
340 : :
341 : : static uint32_t
342 : : nfp_flower_get_phys_port_id(uint8_t port)
343 : : {
344 : 0 : return (NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT << 28) | port;
345 : : }
346 : :
347 : : static uint32_t
348 : : nfp_get_pcie_port_id(struct nfp_cpp *cpp,
349 : : int type,
350 : : uint8_t vnic,
351 : : uint8_t queue)
352 : : {
353 : : uint8_t nfp_pcie;
354 : : uint32_t port_id;
355 : :
356 : 0 : nfp_pcie = NFP_CPP_INTERFACE_UNIT_of(nfp_cpp_interface(cpp));
357 : 0 : port_id = ((nfp_pcie & 0x3) << 14) |
358 : 0 : ((type & 0x3) << 12) |
359 : 0 : ((vnic & 0x3f) << 6) |
360 : 0 : (queue & 0x3f) |
361 : : ((NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT & 0xf) << 28);
362 : :
363 : : return port_id;
364 : : }
365 : :
366 : : static int
367 : 0 : nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev,
368 : : void *init_params)
369 : : {
370 : : struct nfp_flower_representor *repr;
371 : : struct nfp_flower_representor *init_repr_data;
372 : :
373 : : /* Cast the input representor data to the correct struct here */
374 : : init_repr_data = init_params;
375 : :
376 : : /* Memory has been allocated in the eth_dev_create() function */
377 : 0 : repr = eth_dev->data->dev_private;
378 : :
379 : : /* Copy data here from the input representor template */
380 : 0 : repr->vf_id = init_repr_data->vf_id;
381 : 0 : repr->switch_domain_id = init_repr_data->switch_domain_id;
382 : 0 : repr->repr_type = init_repr_data->repr_type;
383 : 0 : repr->app_fw_flower = init_repr_data->app_fw_flower;
384 : :
385 : 0 : snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
386 : :
387 : 0 : eth_dev->dev_ops = &nfp_flower_pf_repr_dev_ops;
388 : 0 : eth_dev->rx_pkt_burst = nfp_net_recv_pkts;
389 : 0 : eth_dev->tx_pkt_burst = nfp_flower_pf_xmit_pkts;
390 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
391 : :
392 : 0 : eth_dev->data->representor_id = 0;
393 : :
394 : : /* This backer port is that of the eth_device created for the PF vNIC */
395 : 0 : eth_dev->data->backer_port_id = 0;
396 : :
397 : : /* Only single queues for representor devices */
398 : 0 : eth_dev->data->nb_rx_queues = 1;
399 : 0 : eth_dev->data->nb_tx_queues = 1;
400 : :
401 : : /* Allocating memory for mac addr */
402 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", RTE_ETHER_ADDR_LEN, 0);
403 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
404 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for repr MAC");
405 : 0 : return -ENOMEM;
406 : : }
407 : :
408 : : rte_ether_addr_copy(&init_repr_data->mac_addr, &repr->mac_addr);
409 : : rte_ether_addr_copy(&init_repr_data->mac_addr, eth_dev->data->mac_addrs);
410 : :
411 : 0 : repr->app_fw_flower->pf_repr = repr;
412 : 0 : repr->app_fw_flower->pf_hw->eth_dev = eth_dev;
413 : :
414 : 0 : return 0;
415 : : }
416 : :
417 : : static int
418 : 0 : nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
419 : : void *init_params)
420 : : {
421 : : int ret;
422 : : uint16_t index;
423 : : unsigned int numa_node;
424 : : char ring_name[RTE_ETH_NAME_MAX_LEN];
425 : : struct nfp_app_fw_flower *app_fw_flower;
426 : : struct nfp_flower_representor *repr;
427 : : struct nfp_flower_representor *init_repr_data;
428 : :
429 : : /* Cast the input representor data to the correct struct here */
430 : : init_repr_data = init_params;
431 : 0 : app_fw_flower = init_repr_data->app_fw_flower;
432 : :
433 : : /* Memory has been allocated in the eth_dev_create() function */
434 : 0 : repr = eth_dev->data->dev_private;
435 : :
436 : : /*
437 : : * We need multiproduce rings as we can have multiple PF ports.
438 : : * On the other hand, we need single consumer rings, as just one
439 : : * representor PMD will try to read from the ring.
440 : : */
441 : 0 : snprintf(ring_name, sizeof(ring_name), "%s_%s", init_repr_data->name, "ring");
442 : 0 : numa_node = rte_socket_id();
443 : 0 : repr->ring = rte_ring_create(ring_name, 256, numa_node, RING_F_SC_DEQ);
444 [ # # ]: 0 : if (repr->ring == NULL) {
445 : 0 : PMD_DRV_LOG(ERR, "rte_ring_create failed for %s", ring_name);
446 : 0 : return -ENOMEM;
447 : : }
448 : :
449 : : /* Copy data here from the input representor template */
450 : 0 : repr->vf_id = init_repr_data->vf_id;
451 : 0 : repr->switch_domain_id = init_repr_data->switch_domain_id;
452 : 0 : repr->port_id = init_repr_data->port_id;
453 : 0 : repr->nfp_idx = init_repr_data->nfp_idx;
454 : 0 : repr->repr_type = init_repr_data->repr_type;
455 : 0 : repr->app_fw_flower = init_repr_data->app_fw_flower;
456 : :
457 [ # # ]: 0 : snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
458 : :
459 : 0 : eth_dev->dev_ops = &nfp_flower_repr_dev_ops;
460 : 0 : eth_dev->rx_pkt_burst = nfp_flower_repr_rx_burst;
461 : 0 : eth_dev->tx_pkt_burst = nfp_flower_repr_tx_burst;
462 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
463 : :
464 [ # # ]: 0 : if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT)
465 : 0 : eth_dev->data->representor_id = repr->vf_id;
466 : : else
467 : 0 : eth_dev->data->representor_id = repr->vf_id +
468 : 0 : app_fw_flower->num_phyport_reprs + 1;
469 : :
470 : : /* This backer port is that of the eth_device created for the PF vNIC */
471 : 0 : eth_dev->data->backer_port_id = 0;
472 : :
473 : : /* Only single queues for representor devices */
474 : 0 : eth_dev->data->nb_rx_queues = 1;
475 : 0 : eth_dev->data->nb_tx_queues = 1;
476 : :
477 : : /* Allocating memory for mac addr */
478 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", RTE_ETHER_ADDR_LEN, 0);
479 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
480 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for repr MAC");
481 : : ret = -ENOMEM;
482 : 0 : goto ring_cleanup;
483 : : }
484 : :
485 : : rte_ether_addr_copy(&init_repr_data->mac_addr, &repr->mac_addr);
486 : : rte_ether_addr_copy(&init_repr_data->mac_addr, eth_dev->data->mac_addrs);
487 : :
488 : : /* Send reify message to hardware to inform it about the new repr */
489 : 0 : ret = nfp_flower_cmsg_repr_reify(app_fw_flower, repr);
490 [ # # ]: 0 : if (ret != 0) {
491 : 0 : PMD_INIT_LOG(WARNING, "Failed to send repr reify message");
492 : 0 : goto mac_cleanup;
493 : : }
494 : :
495 : : /* Add repr to correct array */
496 [ # # ]: 0 : if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT) {
497 : 0 : index = NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM(repr->port_id);
498 : 0 : app_fw_flower->phy_reprs[index] = repr;
499 : : } else {
500 : 0 : index = repr->vf_id;
501 : 0 : app_fw_flower->vf_reprs[index] = repr;
502 : : }
503 : :
504 : : return 0;
505 : :
506 : : mac_cleanup:
507 : 0 : rte_free(eth_dev->data->mac_addrs);
508 : 0 : ring_cleanup:
509 : 0 : rte_ring_free(repr->ring);
510 : :
511 : 0 : return ret;
512 : : }
513 : :
514 : : static int
515 : 0 : nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower)
516 : : {
517 : : int i;
518 : : int ret;
519 : : const char *pci_name;
520 : : struct rte_eth_dev *eth_dev;
521 : : struct rte_pci_device *pci_dev;
522 : : struct nfp_eth_table *nfp_eth_table;
523 : : struct nfp_eth_table_port *eth_port;
524 : 0 : struct nfp_flower_representor flower_repr = {
525 : 0 : .switch_domain_id = app_fw_flower->switch_domain_id,
526 : : .app_fw_flower = app_fw_flower,
527 : : };
528 : :
529 : 0 : nfp_eth_table = app_fw_flower->pf_hw->pf_dev->nfp_eth_table;
530 : 0 : eth_dev = app_fw_flower->ctrl_hw->eth_dev;
531 : :
532 : : /* Send a NFP_FLOWER_CMSG_TYPE_MAC_REPR cmsg to hardware */
533 : 0 : ret = nfp_flower_cmsg_mac_repr(app_fw_flower);
534 [ # # ]: 0 : if (ret != 0) {
535 : 0 : PMD_INIT_LOG(ERR, "Cloud not send mac repr cmsgs");
536 : 0 : return ret;
537 : : }
538 : :
539 : : /* Create a rte_eth_dev for PF vNIC representor */
540 : 0 : flower_repr.repr_type = NFP_REPR_TYPE_PF;
541 : :
542 : : /* PF vNIC reprs get a random MAC address */
543 : 0 : rte_eth_random_addr(flower_repr.mac_addr.addr_bytes);
544 : :
545 : 0 : pci_dev = app_fw_flower->pf_hw->pf_dev->pci_dev;
546 : :
547 : 0 : pci_name = strchr(pci_dev->name, ':') + 1;
548 : :
549 : : snprintf(flower_repr.name, sizeof(flower_repr.name),
550 : : "%s_repr_pf", pci_name);
551 : :
552 : : /* Create a eth_dev for this representor */
553 : 0 : ret = rte_eth_dev_create(eth_dev->device, flower_repr.name,
554 : : sizeof(struct nfp_flower_representor),
555 : : NULL, NULL, nfp_flower_pf_repr_init, &flower_repr);
556 [ # # ]: 0 : if (ret != 0) {
557 : 0 : PMD_INIT_LOG(ERR, "Failed to init the pf repr");
558 : 0 : return -EINVAL;
559 : : }
560 : :
561 : : /* Create a rte_eth_dev for every phyport representor */
562 [ # # ]: 0 : for (i = 0; i < app_fw_flower->num_phyport_reprs; i++) {
563 : : eth_port = &nfp_eth_table->ports[i];
564 : 0 : flower_repr.repr_type = NFP_REPR_TYPE_PHYS_PORT;
565 : 0 : flower_repr.port_id = nfp_flower_get_phys_port_id(eth_port->index);
566 : 0 : flower_repr.nfp_idx = eth_port->eth_index;
567 : 0 : flower_repr.vf_id = i + 1;
568 : :
569 : : /* Copy the real mac of the interface to the representor struct */
570 : : rte_ether_addr_copy(ð_port->mac_addr, &flower_repr.mac_addr);
571 : : snprintf(flower_repr.name, sizeof(flower_repr.name),
572 : : "%s_repr_p%d", pci_name, i);
573 : :
574 : : /*
575 : : * Create a eth_dev for this representor.
576 : : * This will also allocate private memory for the device.
577 : : */
578 : 0 : ret = rte_eth_dev_create(eth_dev->device, flower_repr.name,
579 : : sizeof(struct nfp_flower_representor),
580 : : NULL, NULL, nfp_flower_repr_init, &flower_repr);
581 [ # # ]: 0 : if (ret != 0) {
582 : 0 : PMD_INIT_LOG(ERR, "Cloud not create eth_dev for repr");
583 : 0 : break;
584 : : }
585 : : }
586 : :
587 [ # # ]: 0 : if (i < app_fw_flower->num_phyport_reprs)
588 : : return ret;
589 : :
590 : : /*
591 : : * Now allocate eth_dev's for VF representors.
592 : : * Also send reify messages.
593 : : */
594 [ # # ]: 0 : for (i = 0; i < app_fw_flower->num_vf_reprs; i++) {
595 : 0 : flower_repr.repr_type = NFP_REPR_TYPE_VF;
596 : 0 : flower_repr.port_id = nfp_get_pcie_port_id(app_fw_flower->pf_hw->cpp,
597 : : NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF, i, 0);
598 : 0 : flower_repr.nfp_idx = 0;
599 : 0 : flower_repr.vf_id = i;
600 : :
601 : : /* VF reprs get a random MAC address */
602 : 0 : rte_eth_random_addr(flower_repr.mac_addr.addr_bytes);
603 : : snprintf(flower_repr.name, sizeof(flower_repr.name),
604 : : "%s_repr_vf%d", pci_name, i);
605 : :
606 : : /* This will also allocate private memory for the device */
607 : 0 : ret = rte_eth_dev_create(eth_dev->device, flower_repr.name,
608 : : sizeof(struct nfp_flower_representor),
609 : : NULL, NULL, nfp_flower_repr_init, &flower_repr);
610 [ # # ]: 0 : if (ret != 0) {
611 : 0 : PMD_INIT_LOG(ERR, "Cloud not create eth_dev for repr");
612 : 0 : break;
613 : : }
614 : : }
615 : :
616 [ # # ]: 0 : if (i < app_fw_flower->num_vf_reprs)
617 : 0 : return ret;
618 : :
619 : : return 0;
620 : : }
621 : :
622 : : int
623 : 0 : nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower)
624 : : {
625 : : int ret;
626 : : struct nfp_pf_dev *pf_dev;
627 : : struct rte_pci_device *pci_dev;
628 : : struct nfp_eth_table *nfp_eth_table;
629 : 0 : struct rte_eth_devargs eth_da = {
630 : : .nb_representor_ports = 0
631 : : };
632 : :
633 : 0 : pf_dev = app_fw_flower->pf_hw->pf_dev;
634 : 0 : pci_dev = pf_dev->pci_dev;
635 : :
636 : : /* Allocate a switch domain for the flower app */
637 [ # # # # ]: 0 : if (app_fw_flower->switch_domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID &&
638 : 0 : rte_eth_switch_domain_alloc(&app_fw_flower->switch_domain_id)) {
639 : 0 : PMD_INIT_LOG(WARNING, "failed to allocate switch domain for device");
640 : : }
641 : :
642 : : /* Now parse PCI device args passed for representor info */
643 [ # # ]: 0 : if (pci_dev->device.devargs != NULL) {
644 : 0 : ret = rte_eth_devargs_parse(pci_dev->device.devargs->args, ð_da);
645 [ # # ]: 0 : if (ret != 0) {
646 : 0 : PMD_INIT_LOG(ERR, "devarg parse failed");
647 : 0 : return -EINVAL;
648 : : }
649 : : }
650 : :
651 [ # # ]: 0 : if (eth_da.nb_representor_ports == 0) {
652 : 0 : PMD_INIT_LOG(DEBUG, "No representor port need to create.");
653 : 0 : return 0;
654 : : }
655 : :
656 : : /* There always exist phy repr */
657 : 0 : nfp_eth_table = pf_dev->nfp_eth_table;
658 [ # # ]: 0 : if (eth_da.nb_representor_ports < nfp_eth_table->count + 1) {
659 : 0 : PMD_INIT_LOG(ERR, "Should also create repr port for phy port and PF vNIC.");
660 : 0 : return -ERANGE;
661 : : }
662 : :
663 : : /* Only support VF representor creation via the command line */
664 [ # # ]: 0 : if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
665 : 0 : PMD_INIT_LOG(ERR, "Unsupported representor type: %d", eth_da.type);
666 : 0 : return -ENOTSUP;
667 : : }
668 : :
669 : : /* Fill in flower app with repr counts */
670 : 0 : app_fw_flower->num_phyport_reprs = (uint8_t)nfp_eth_table->count;
671 : 0 : app_fw_flower->num_vf_reprs = eth_da.nb_representor_ports -
672 : 0 : nfp_eth_table->count - 1;
673 : :
674 : 0 : PMD_INIT_LOG(INFO, "%d number of VF reprs", app_fw_flower->num_vf_reprs);
675 : 0 : PMD_INIT_LOG(INFO, "%d number of phyport reprs", app_fw_flower->num_phyport_reprs);
676 : :
677 : 0 : ret = nfp_flower_repr_alloc(app_fw_flower);
678 [ # # ]: 0 : if (ret != 0) {
679 : 0 : PMD_INIT_LOG(ERR, "representors allocation failed");
680 : 0 : return -EINVAL;
681 : : }
682 : :
683 : : return 0;
684 : : }
|