Branch data Line data Source code
1 : : /*
2 : : * SPDX-License-Identifier: BSD-3-Clause
3 : : * Copyright(c) 2023 Napatech A/S
4 : : */
5 : :
6 : : #include <stdint.h>
7 : : #include <stdarg.h>
8 : :
9 : : #include <signal.h>
10 : :
11 : : #include <rte_eal.h>
12 : : #include <rte_dev.h>
13 : : #include <rte_vfio.h>
14 : : #include <rte_ethdev.h>
15 : : #include <rte_bus_pci.h>
16 : : #include <ethdev_pci.h>
17 : : #include <rte_kvargs.h>
18 : :
19 : : #include <sys/queue.h>
20 : :
21 : : #include "rte_spinlock.h"
22 : : #include "ntlog.h"
23 : : #include "ntdrv_4ga.h"
24 : : #include "ntos_drv.h"
25 : : #include "ntos_system.h"
26 : : #include "nthw_fpga_instances.h"
27 : : #include "ntnic_vfio.h"
28 : : #include "ntnic_mod_reg.h"
29 : : #include "nt_util.h"
30 : : #include "flow_hsh_cfg.h"
31 : : #include "profile_inline/flm_age_queue.h"
32 : : #include "profile_inline/flm_evt_queue.h"
33 : : #include "rte_pmd_ntnic.h"
34 : :
35 : : const rte_thread_attr_t thread_attr = { .priority = RTE_THREAD_PRIORITY_NORMAL };
36 : : #define THREAD_CREATE(a, b, c) rte_thread_create(a, &thread_attr, b, c)
37 : : #define THREAD_CTRL_CREATE(a, b, c, d) rte_thread_create_internal_control(a, b, c, d)
38 : : #define THREAD_JOIN(a) rte_thread_join(a, NULL)
39 : : #define THREAD_FUNC static uint32_t
40 : : #define THREAD_RETURN (0)
41 : : #define HW_MAX_PKT_LEN (10000)
42 : : #define MAX_MTU (HW_MAX_PKT_LEN - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN)
43 : : #define MIN_MTU_INLINE 512
44 : :
45 : : #define EXCEPTION_PATH_HID 0
46 : :
47 : : #define MAX_TOTAL_QUEUES 128
48 : :
49 : : #define SG_NB_HW_RX_DESCRIPTORS 1024
50 : : #define SG_NB_HW_TX_DESCRIPTORS 1024
51 : : #define SG_HW_RX_PKT_BUFFER_SIZE (1024 << 1)
52 : : #define SG_HW_TX_PKT_BUFFER_SIZE (1024 << 1)
53 : :
54 : : #define NUM_VQ_SEGS(_data_size_) \
55 : : ({ \
56 : : size_t _size = (_data_size_); \
57 : : size_t _segment_count = ((_size + SG_HDR_SIZE) > SG_HW_TX_PKT_BUFFER_SIZE) \
58 : : ? (((_size + SG_HDR_SIZE) + SG_HW_TX_PKT_BUFFER_SIZE - 1) / \
59 : : SG_HW_TX_PKT_BUFFER_SIZE) \
60 : : : 1; \
61 : : _segment_count; \
62 : : })
63 : :
64 : : #define VIRTQ_DESCR_IDX(_tx_pkt_idx_) \
65 : : (((_tx_pkt_idx_) + first_vq_descr_idx) % SG_NB_HW_TX_DESCRIPTORS)
66 : :
67 : : #define VIRTQ_DESCR_IDX_NEXT(_vq_descr_idx_) (((_vq_descr_idx_) + 1) % SG_NB_HW_TX_DESCRIPTORS)
68 : :
69 : : #define ONE_G_SIZE 0x40000000
70 : : #define ONE_G_MASK (ONE_G_SIZE - 1)
71 : :
72 : : #define MAX_RX_PACKETS 128
73 : : #define MAX_TX_PACKETS 128
74 : :
75 : : #define MTUINITVAL 1500
76 : :
77 : : uint64_t rte_tsc_freq;
78 : :
79 : :
80 : : #define ETH_DEV_NTNIC_HELP_ARG "help"
81 : : #define ETH_DEV_NTHW_RXQUEUES_ARG "rxqs"
82 : : #define ETH_DEV_NTHW_TXQUEUES_ARG "txqs"
83 : :
84 : : static const char *const valid_arguments[] = {
85 : : ETH_DEV_NTNIC_HELP_ARG,
86 : : ETH_DEV_NTHW_RXQUEUES_ARG,
87 : : ETH_DEV_NTHW_TXQUEUES_ARG,
88 : : NULL,
89 : : };
90 : :
91 : :
92 : : static const struct rte_pci_id nthw_pci_id_map[] = {
93 : : { RTE_PCI_DEVICE(NT_HW_PCI_VENDOR_ID, NT_HW_PCI_DEVICE_ID_NT200A02) },
94 : : { RTE_PCI_DEVICE(NT_HW_PCI_VENDOR_ID, NT_HW_PCI_DEVICE_ID_NT400D13) },
95 : : {
96 : : .vendor_id = 0,
97 : : }, /* sentinel */
98 : : };
99 : :
100 : : static const struct sg_ops_s *sg_ops;
101 : :
102 : : rte_spinlock_t hwlock = RTE_SPINLOCK_INITIALIZER;
103 : :
104 : : /*
105 : : * Store and get adapter info
106 : : */
107 : :
108 : : static struct drv_s *_g_p_drv[NUM_ADAPTER_MAX] = { NULL };
109 : :
110 : : static void
111 : 0 : store_pdrv(struct drv_s *p_drv)
112 : : {
113 [ # # ]: 0 : if (p_drv->adapter_no >= NUM_ADAPTER_MAX) {
114 : 0 : NT_LOG(ERR, NTNIC,
115 : : "Internal error adapter number %u out of range. Max number of adapters: %u",
116 : : p_drv->adapter_no, NUM_ADAPTER_MAX);
117 : 0 : return;
118 : : }
119 : :
120 [ # # ]: 0 : if (_g_p_drv[p_drv->adapter_no] != 0) {
121 : 0 : NT_LOG(WRN, NTNIC,
122 : : "Overwriting adapter structure for PCI " PCIIDENT_PRINT_STR
123 : : " with adapter structure for PCI " PCIIDENT_PRINT_STR,
124 : : PCIIDENT_TO_DOMAIN(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident),
125 : : PCIIDENT_TO_BUSNR(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident),
126 : : PCIIDENT_TO_DEVNR(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident),
127 : : PCIIDENT_TO_FUNCNR(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident),
128 : : PCIIDENT_TO_DOMAIN(p_drv->ntdrv.pciident),
129 : : PCIIDENT_TO_BUSNR(p_drv->ntdrv.pciident),
130 : : PCIIDENT_TO_DEVNR(p_drv->ntdrv.pciident),
131 : : PCIIDENT_TO_FUNCNR(p_drv->ntdrv.pciident));
132 : : }
133 : :
134 : : rte_spinlock_lock(&hwlock);
135 : 0 : _g_p_drv[p_drv->adapter_no] = p_drv;
136 : : rte_spinlock_unlock(&hwlock);
137 : : }
138 : :
139 : 0 : static void clear_pdrv(struct drv_s *p_drv)
140 : : {
141 [ # # ]: 0 : if (p_drv->adapter_no >= NUM_ADAPTER_MAX)
142 : : return;
143 : :
144 : : rte_spinlock_lock(&hwlock);
145 : 0 : _g_p_drv[p_drv->adapter_no] = NULL;
146 : : rte_spinlock_unlock(&hwlock);
147 : : }
148 : :
149 : : static struct drv_s *
150 : 0 : get_pdrv_from_pci(struct rte_pci_addr addr)
151 : : {
152 : : int i;
153 : : struct drv_s *p_drv = NULL;
154 : : rte_spinlock_lock(&hwlock);
155 : :
156 [ # # ]: 0 : for (i = 0; i < NUM_ADAPTER_MAX; i++) {
157 [ # # ]: 0 : if (_g_p_drv[i]) {
158 [ # # ]: 0 : if (PCIIDENT_TO_DOMAIN(_g_p_drv[i]->ntdrv.pciident) == addr.domain &&
159 [ # # ]: 0 : PCIIDENT_TO_BUSNR(_g_p_drv[i]->ntdrv.pciident) == addr.bus) {
160 : : p_drv = _g_p_drv[i];
161 : : break;
162 : : }
163 : : }
164 : : }
165 : :
166 : : rte_spinlock_unlock(&hwlock);
167 : 0 : return p_drv;
168 : : }
169 : :
170 : 0 : static int dpdk_stats_collect(struct pmd_internals *internals, struct rte_eth_stats *stats)
171 : : {
172 : 0 : const struct ntnic_filter_ops *ntnic_filter_ops = get_ntnic_filter_ops();
173 : :
174 [ # # ]: 0 : if (ntnic_filter_ops == NULL) {
175 : 0 : NT_LOG_DBGX(ERR, NTNIC, "ntnic_filter_ops uninitialized");
176 : 0 : return -1;
177 : : }
178 : :
179 : : unsigned int i;
180 : 0 : struct drv_s *p_drv = internals->p_drv;
181 : : struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv;
182 : : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
183 : 0 : nthw_stat_t *p_nthw_stat = p_nt4ga_stat->mp_nthw_stat;
184 : 0 : const int if_index = internals->n_intf_no;
185 : : uint64_t rx_total = 0;
186 : : uint64_t rx_total_b = 0;
187 : : uint64_t tx_total = 0;
188 : : uint64_t tx_total_b = 0;
189 : : uint64_t tx_err_total = 0;
190 : :
191 [ # # # # : 0 : if (!p_nthw_stat || !p_nt4ga_stat || !stats || if_index < 0 ||
# # ]
192 : : if_index > NUM_ADAPTER_PORTS_MAX) {
193 : 0 : NT_LOG_DBGX(WRN, NTNIC, "error exit");
194 : 0 : return -1;
195 : : }
196 : :
197 : : /*
198 : : * Pull the latest port statistic numbers (Rx/Tx pkts and bytes)
199 : : * Return values are in the "internals->rxq_scg[]" and "internals->txq_scg[]" arrays
200 : : */
201 : 0 : ntnic_filter_ops->poll_statistics(internals);
202 : :
203 : : memset(stats, 0, sizeof(*stats));
204 : :
205 [ # # # # ]: 0 : for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < internals->nb_rx_queues; i++) {
206 : 0 : stats->q_ipackets[i] = internals->rxq_scg[i].rx_pkts;
207 : 0 : stats->q_ibytes[i] = internals->rxq_scg[i].rx_bytes;
208 : 0 : rx_total += stats->q_ipackets[i];
209 : 0 : rx_total_b += stats->q_ibytes[i];
210 : : }
211 : :
212 [ # # # # ]: 0 : for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < internals->nb_tx_queues; i++) {
213 : 0 : stats->q_opackets[i] = internals->txq_scg[i].tx_pkts;
214 : 0 : stats->q_obytes[i] = internals->txq_scg[i].tx_bytes;
215 : 0 : stats->q_errors[i] = internals->txq_scg[i].err_pkts;
216 : 0 : tx_total += stats->q_opackets[i];
217 : 0 : tx_total_b += stats->q_obytes[i];
218 : 0 : tx_err_total += stats->q_errors[i];
219 : : }
220 : :
221 : 0 : stats->imissed = internals->rx_missed;
222 : 0 : stats->ipackets = rx_total;
223 : 0 : stats->ibytes = rx_total_b;
224 : 0 : stats->opackets = tx_total;
225 : 0 : stats->obytes = tx_total_b;
226 : 0 : stats->oerrors = tx_err_total;
227 : :
228 : 0 : return 0;
229 : : }
230 : :
231 : 0 : static int dpdk_stats_reset(struct pmd_internals *internals, struct ntdrv_4ga_s *p_nt_drv,
232 : : int n_intf_no)
233 : : {
234 : : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
235 : 0 : nthw_stat_t *p_nthw_stat = p_nt4ga_stat->mp_nthw_stat;
236 : : unsigned int i;
237 : :
238 [ # # # # ]: 0 : if (!p_nthw_stat || !p_nt4ga_stat || n_intf_no < 0 || n_intf_no > NUM_ADAPTER_PORTS_MAX)
239 : : return -1;
240 : :
241 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
242 : :
243 : : /* Rx */
244 [ # # ]: 0 : for (i = 0; i < internals->nb_rx_queues; i++) {
245 : 0 : internals->rxq_scg[i].rx_pkts = 0;
246 : 0 : internals->rxq_scg[i].rx_bytes = 0;
247 : 0 : internals->rxq_scg[i].err_pkts = 0;
248 : : }
249 : :
250 : 0 : internals->rx_missed = 0;
251 : :
252 : : /* Tx */
253 [ # # ]: 0 : for (i = 0; i < internals->nb_tx_queues; i++) {
254 : 0 : internals->txq_scg[i].tx_pkts = 0;
255 : 0 : internals->txq_scg[i].tx_bytes = 0;
256 : 0 : internals->txq_scg[i].err_pkts = 0;
257 : : }
258 : :
259 : 0 : p_nt4ga_stat->n_totals_reset_timestamp = time(NULL);
260 : :
261 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
262 : :
263 : 0 : return 0;
264 : : }
265 : :
266 : : static int
267 : 0 : eth_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete __rte_unused)
268 : : {
269 : 0 : const struct port_ops *port_ops = get_port_ops();
270 : :
271 [ # # ]: 0 : if (port_ops == NULL) {
272 : 0 : NT_LOG(ERR, NTNIC, "Link management module uninitialized");
273 : 0 : return -1;
274 : : }
275 : :
276 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
277 : :
278 : 0 : const int n_intf_no = internals->n_intf_no;
279 : 0 : struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
280 : :
281 [ # # ]: 0 : if (eth_dev->data->dev_started) {
282 : 0 : const bool port_link_status = port_ops->get_link_status(p_adapter_info, n_intf_no);
283 : 0 : eth_dev->data->dev_link.link_status =
284 : : port_link_status ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
285 : :
286 : : nt_link_speed_t port_link_speed =
287 : 0 : port_ops->get_link_speed(p_adapter_info, n_intf_no);
288 : 0 : eth_dev->data->dev_link.link_speed =
289 : 0 : nt_link_speed_to_eth_speed_num(port_link_speed);
290 : :
291 : : nt_link_duplex_t nt_link_duplex =
292 : 0 : port_ops->get_link_duplex(p_adapter_info, n_intf_no);
293 : 0 : eth_dev->data->dev_link.link_duplex = nt_link_duplex_to_eth_duplex(nt_link_duplex);
294 : :
295 : : } else {
296 : 0 : eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;
297 : 0 : eth_dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
298 : 0 : eth_dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
299 : : }
300 : :
301 : : return 0;
302 : : }
303 : :
304 : 0 : static int eth_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *stats)
305 : : {
306 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
307 : 0 : dpdk_stats_collect(internals, stats);
308 : 0 : return 0;
309 : : }
310 : :
311 : 0 : static int eth_stats_reset(struct rte_eth_dev *eth_dev)
312 : : {
313 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
314 : 0 : struct drv_s *p_drv = internals->p_drv;
315 : 0 : struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv;
316 : 0 : const int if_index = internals->n_intf_no;
317 : 0 : dpdk_stats_reset(internals, p_nt_drv, if_index);
318 : 0 : return 0;
319 : : }
320 : :
321 : : static int
322 : 0 : eth_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *dev_info)
323 : : {
324 : 0 : const struct port_ops *port_ops = get_port_ops();
325 : :
326 [ # # ]: 0 : if (port_ops == NULL) {
327 : 0 : NT_LOG(ERR, NTNIC, "Link management module uninitialized");
328 : 0 : return -1;
329 : : }
330 : :
331 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
332 : :
333 : 0 : const int n_intf_no = internals->n_intf_no;
334 : 0 : struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
335 : :
336 : 0 : dev_info->driver_name = internals->name;
337 : 0 : dev_info->max_mac_addrs = NUM_MAC_ADDRS_PER_PORT;
338 : 0 : dev_info->max_rx_pktlen = HW_MAX_PKT_LEN;
339 : 0 : dev_info->max_mtu = MAX_MTU;
340 : :
341 [ # # ]: 0 : if (p_adapter_info->fpga_info.profile == FPGA_INFO_PROFILE_INLINE) {
342 : 0 : dev_info->min_mtu = MIN_MTU_INLINE;
343 : 0 : dev_info->flow_type_rss_offloads = NT_ETH_RSS_OFFLOAD_MASK;
344 : 0 : dev_info->hash_key_size = MAX_RSS_KEY_LEN;
345 : :
346 : 0 : dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT) |
347 : : RTE_ETH_HASH_ALGO_CAPA_MASK(TOEPLITZ);
348 : : }
349 : :
350 : : if (internals->p_drv) {
351 : 0 : dev_info->max_rx_queues = internals->nb_rx_queues;
352 : 0 : dev_info->max_tx_queues = internals->nb_tx_queues;
353 : :
354 : 0 : dev_info->min_rx_bufsize = 64;
355 : :
356 : : const uint32_t nt_port_speed_capa =
357 : 0 : port_ops->get_link_speed_capabilities(p_adapter_info, n_intf_no);
358 : 0 : dev_info->speed_capa = nt_link_speed_capa_to_eth_speed_capa(nt_port_speed_capa);
359 : : }
360 : :
361 : 0 : return 0;
362 : : }
363 : :
364 : : static __rte_always_inline int copy_virtqueue_to_mbuf(struct rte_mbuf *mbuf,
365 : : struct rte_mempool *mb_pool,
366 : : struct nthw_received_packets *hw_recv,
367 : : int max_segs,
368 : : uint16_t data_len)
369 : : {
370 : : int src_pkt = 0;
371 : : /*
372 : : * 1. virtqueue packets may be segmented
373 : : * 2. the mbuf size may be too small and may need to be segmented
374 : : */
375 : 0 : char *data = (char *)hw_recv->addr + SG_HDR_SIZE;
376 : 0 : char *dst = (char *)mbuf->buf_addr + RTE_PKTMBUF_HEADROOM;
377 : :
378 : : /* set packet length */
379 : 0 : mbuf->pkt_len = data_len - SG_HDR_SIZE;
380 : :
381 : : int remain = mbuf->pkt_len;
382 : : /* First cpy_size is without header */
383 : : int cpy_size = (data_len > SG_HW_RX_PKT_BUFFER_SIZE)
384 : : ? SG_HW_RX_PKT_BUFFER_SIZE - SG_HDR_SIZE
385 : 0 : : remain;
386 : :
387 : : struct rte_mbuf *m = mbuf; /* if mbuf segmentation is needed */
388 : :
389 [ # # ]: 0 : while (++src_pkt <= max_segs) {
390 : : /* keep track of space in dst */
391 : 0 : int cpto_size = rte_pktmbuf_tailroom(m);
392 : :
393 [ # # ]: 0 : if (cpy_size > cpto_size) {
394 : : int new_cpy_size = cpto_size;
395 : :
396 [ # # ]: 0 : rte_memcpy((void *)dst, (void *)data, new_cpy_size);
397 : 0 : m->data_len += new_cpy_size;
398 : 0 : remain -= new_cpy_size;
399 : 0 : cpy_size -= new_cpy_size;
400 : :
401 : 0 : data += new_cpy_size;
402 : :
403 : : /*
404 : : * loop if remaining data from this virtqueue seg
405 : : * cannot fit in one extra mbuf
406 : : */
407 : : do {
408 : 0 : m->next = rte_pktmbuf_alloc(mb_pool);
409 : :
410 [ # # ]: 0 : if (unlikely(!m->next))
411 : : return -1;
412 : :
413 : : m = m->next;
414 : :
415 : : /* Headroom is not needed in chained mbufs */
416 : 0 : rte_pktmbuf_prepend(m, rte_pktmbuf_headroom(m));
417 : 0 : dst = (char *)m->buf_addr;
418 : 0 : m->data_len = 0;
419 [ # # ]: 0 : m->pkt_len = 0;
420 : :
421 : 0 : cpto_size = rte_pktmbuf_tailroom(m);
422 : :
423 : 0 : int actual_cpy_size =
424 : : (cpy_size > cpto_size) ? cpto_size : cpy_size;
425 : :
426 [ # # ]: 0 : rte_memcpy((void *)dst, (void *)data, actual_cpy_size);
427 : 0 : m->pkt_len += actual_cpy_size;
428 : 0 : m->data_len += actual_cpy_size;
429 : :
430 : 0 : remain -= actual_cpy_size;
431 : 0 : cpy_size -= actual_cpy_size;
432 : :
433 : 0 : data += actual_cpy_size;
434 : :
435 : 0 : mbuf->nb_segs++;
436 : :
437 [ # # ]: 0 : } while (cpy_size && remain);
438 : :
439 : : } else {
440 : : /* all data from this virtqueue segment can fit in current mbuf */
441 [ # # ]: 0 : rte_memcpy((void *)dst, (void *)data, cpy_size);
442 : 0 : m->data_len += cpy_size;
443 : :
444 [ # # ]: 0 : if (mbuf->nb_segs > 1)
445 : 0 : m->pkt_len += cpy_size;
446 : :
447 : 0 : remain -= cpy_size;
448 : : }
449 : :
450 : : /* packet complete - all data from current virtqueue packet has been copied */
451 [ # # ]: 0 : if (remain == 0)
452 : : break;
453 : :
454 : : /* increment dst to data end */
455 : 0 : dst = rte_pktmbuf_mtod_offset(m, char *, m->data_len);
456 : : /* prepare for next virtqueue segment */
457 : 0 : data = (char *)hw_recv[src_pkt].addr; /* following packets are full data */
458 : :
459 : 0 : cpy_size = (remain > SG_HW_RX_PKT_BUFFER_SIZE) ? SG_HW_RX_PKT_BUFFER_SIZE : remain;
460 : : };
461 : :
462 [ # # ]: 0 : if (src_pkt > max_segs) {
463 : 0 : NT_LOG(ERR, NTNIC,
464 : : "Did not receive correct number of segment for a whole packet");
465 : : return -1;
466 : : }
467 : :
468 : : return src_pkt;
469 : : }
470 : :
471 : 0 : static uint16_t eth_dev_rx_scg(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
472 : : {
473 : : unsigned int i;
474 : : struct rte_mbuf *mbuf;
475 : : struct ntnic_rx_queue *rx_q = queue;
476 : : uint16_t num_rx = 0;
477 : :
478 : : struct nthw_received_packets hw_recv[MAX_RX_PACKETS];
479 : :
480 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
481 : : return 0;
482 : :
483 : : if (nb_pkts > MAX_RX_PACKETS)
484 : : nb_pkts = MAX_RX_PACKETS;
485 : :
486 : 0 : uint16_t whole_pkts = 0;
487 : : uint16_t hw_recv_pkt_segs = 0;
488 : :
489 [ # # ]: 0 : if (sg_ops != NULL) {
490 : : hw_recv_pkt_segs =
491 : 0 : sg_ops->nthw_get_rx_packets(rx_q->vq, nb_pkts, hw_recv, &whole_pkts);
492 : :
493 [ # # ]: 0 : if (!hw_recv_pkt_segs)
494 : : return 0;
495 : : }
496 : :
497 : 0 : nb_pkts = whole_pkts;
498 : :
499 : : int src_pkt = 0;/* from 0 to hw_recv_pkt_segs */
500 : :
501 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
502 : 0 : bufs[i] = rte_pktmbuf_alloc(rx_q->mb_pool);
503 : :
504 [ # # ]: 0 : if (!bufs[i]) {
505 : 0 : NT_LOG(ERR, NTNIC, "ERROR - no more buffers mbuf in mempool");
506 : 0 : goto err_exit;
507 : : }
508 : :
509 : : mbuf = bufs[i];
510 : :
511 : 0 : struct _pkt_hdr_rx *phdr = (struct _pkt_hdr_rx *)hw_recv[src_pkt].addr;
512 : :
513 [ # # ]: 0 : if (phdr->cap_len < SG_HDR_SIZE) {
514 : 0 : NT_LOG(ERR, NTNIC,
515 : : "Pkt len of zero received. No header!! - dropping packets");
516 : 0 : rte_pktmbuf_free(mbuf);
517 : 0 : goto err_exit;
518 : : }
519 : :
520 : : {
521 [ # # # # ]: 0 : if (phdr->cap_len <= SG_HW_RX_PKT_BUFFER_SIZE &&
522 [ # # ]: 0 : (phdr->cap_len - SG_HDR_SIZE) <= rte_pktmbuf_tailroom(mbuf)) {
523 : 0 : mbuf->data_len = phdr->cap_len - SG_HDR_SIZE;
524 [ # # ]: 0 : rte_memcpy(rte_pktmbuf_mtod(mbuf, char *),
525 : : (char *)hw_recv[src_pkt].addr + SG_HDR_SIZE,
526 : : mbuf->data_len);
527 : :
528 : 0 : mbuf->pkt_len = mbuf->data_len;
529 : 0 : src_pkt++;
530 : :
531 : : } else {
532 [ # # ]: 0 : int cpy_segs = copy_virtqueue_to_mbuf(mbuf, rx_q->mb_pool,
533 : : &hw_recv[src_pkt],
534 : : hw_recv_pkt_segs - src_pkt,
535 : : phdr->cap_len);
536 : :
537 [ # # ]: 0 : if (cpy_segs < 0) {
538 : : /* Error */
539 : 0 : rte_pktmbuf_free(mbuf);
540 : 0 : goto err_exit;
541 : : }
542 : :
543 : 0 : src_pkt += cpy_segs;
544 : : }
545 : :
546 : 0 : num_rx++;
547 : :
548 : 0 : mbuf->ol_flags &= ~(RTE_MBUF_F_RX_FDIR_ID | RTE_MBUF_F_RX_FDIR);
549 : 0 : mbuf->port = (uint16_t)-1;
550 : : }
551 : : }
552 : :
553 : 0 : err_exit:
554 : :
555 [ # # ]: 0 : if (sg_ops != NULL)
556 : 0 : sg_ops->nthw_release_rx_packets(rx_q->vq, hw_recv_pkt_segs);
557 : :
558 : : return num_rx;
559 : : }
560 : :
561 : 0 : static int copy_mbuf_to_virtqueue(struct nthw_cvirtq_desc *cvq_desc,
562 : : uint16_t vq_descr_idx,
563 : : struct nthw_memory_descriptor *vq_bufs,
564 : : int max_segs,
565 : : struct rte_mbuf *mbuf)
566 : : {
567 : : /*
568 : : * 1. mbuf packet may be segmented
569 : : * 2. the virtqueue buffer size may be too small and may need to be segmented
570 : : */
571 : :
572 : 0 : char *data = rte_pktmbuf_mtod(mbuf, char *);
573 : 0 : char *dst = (char *)vq_bufs[vq_descr_idx].virt_addr + SG_HDR_SIZE;
574 : :
575 : 0 : int remain = mbuf->pkt_len;
576 : 0 : int cpy_size = mbuf->data_len;
577 : :
578 : : struct rte_mbuf *m = mbuf;
579 : : int cpto_size = SG_HW_TX_PKT_BUFFER_SIZE - SG_HDR_SIZE;
580 : :
581 : 0 : cvq_desc->b[vq_descr_idx].len = SG_HDR_SIZE;
582 : :
583 : : int cur_seg_num = 0; /* start from 0 */
584 : :
585 [ # # ]: 0 : while (m) {
586 : : /* Can all data in current src segment be in current dest segment */
587 [ # # ]: 0 : if (cpy_size > cpto_size) {
588 : : int new_cpy_size = cpto_size;
589 : :
590 [ # # ]: 0 : rte_memcpy((void *)dst, (void *)data, new_cpy_size);
591 : :
592 : 0 : cvq_desc->b[vq_descr_idx].len += new_cpy_size;
593 : :
594 : 0 : remain -= new_cpy_size;
595 : 0 : cpy_size -= new_cpy_size;
596 : :
597 : 0 : data += new_cpy_size;
598 : :
599 : : /*
600 : : * Loop if remaining data from this virtqueue seg cannot fit in one extra
601 : : * mbuf
602 : : */
603 : : do {
604 [ # # # # ]: 0 : vq_add_flags(cvq_desc, vq_descr_idx, VIRTQ_DESC_F_NEXT);
605 : :
606 : 0 : int next_vq_descr_idx = VIRTQ_DESCR_IDX_NEXT(vq_descr_idx);
607 : :
608 [ # # ]: 0 : vq_set_next(cvq_desc, vq_descr_idx, next_vq_descr_idx);
609 : :
610 : 0 : vq_descr_idx = next_vq_descr_idx;
611 : :
612 [ # # # # ]: 0 : vq_set_flags(cvq_desc, vq_descr_idx, 0);
613 [ # # ]: 0 : vq_set_next(cvq_desc, vq_descr_idx, 0);
614 : :
615 [ # # ]: 0 : if (++cur_seg_num > max_segs)
616 : : break;
617 : :
618 : 0 : dst = (char *)vq_bufs[vq_descr_idx].virt_addr;
619 : : cpto_size = SG_HW_TX_PKT_BUFFER_SIZE;
620 : :
621 : 0 : int actual_cpy_size =
622 : : (cpy_size > cpto_size) ? cpto_size : cpy_size;
623 [ # # ]: 0 : rte_memcpy((void *)dst, (void *)data, actual_cpy_size);
624 : :
625 : 0 : cvq_desc->b[vq_descr_idx].len = actual_cpy_size;
626 : :
627 : 0 : remain -= actual_cpy_size;
628 : 0 : cpy_size -= actual_cpy_size;
629 : 0 : cpto_size -= actual_cpy_size;
630 : :
631 : 0 : data += actual_cpy_size;
632 : :
633 [ # # ]: 0 : } while (cpy_size && remain);
634 : :
635 : : } else {
636 : : /* All data from this segment can fit in current virtqueue buffer */
637 [ # # ]: 0 : rte_memcpy((void *)dst, (void *)data, cpy_size);
638 : :
639 : 0 : cvq_desc->b[vq_descr_idx].len += cpy_size;
640 : :
641 : 0 : remain -= cpy_size;
642 : 0 : cpto_size -= cpy_size;
643 : : }
644 : :
645 : : /* Packet complete - all segments from current mbuf has been copied */
646 [ # # ]: 0 : if (remain == 0)
647 : : break;
648 : :
649 : : /* increment dst to data end */
650 : 0 : dst = (char *)vq_bufs[vq_descr_idx].virt_addr + cvq_desc->b[vq_descr_idx].len;
651 : :
652 : 0 : m = m->next;
653 : :
654 [ # # ]: 0 : if (!m) {
655 : 0 : NT_LOG(ERR, NTNIC, "ERROR: invalid packet size");
656 : 0 : break;
657 : : }
658 : :
659 : : /* Prepare for next mbuf segment */
660 : 0 : data = rte_pktmbuf_mtod(m, char *);
661 : 0 : cpy_size = m->data_len;
662 : : };
663 : :
664 : 0 : cur_seg_num++;
665 : :
666 [ # # ]: 0 : if (cur_seg_num > max_segs) {
667 : 0 : NT_LOG(ERR, NTNIC,
668 : : "Did not receive correct number of segment for a whole packet");
669 : 0 : return -1;
670 : : }
671 : :
672 : : return cur_seg_num;
673 : : }
674 : :
675 : 0 : static uint16_t eth_dev_tx_scg(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
676 : : {
677 : : uint16_t pkt;
678 : 0 : uint16_t first_vq_descr_idx = 0;
679 : :
680 : : struct nthw_cvirtq_desc cvq_desc;
681 : :
682 : : struct nthw_memory_descriptor *vq_bufs;
683 : :
684 : : struct ntnic_tx_queue *tx_q = queue;
685 : :
686 : : int nb_segs = 0, i;
687 : : int pkts_sent = 0;
688 : : uint16_t nb_segs_arr[MAX_TX_PACKETS];
689 : :
690 : : if (nb_pkts > MAX_TX_PACKETS)
691 : : nb_pkts = MAX_TX_PACKETS;
692 : :
693 : : /*
694 : : * count all segments needed to contain all packets in vq buffers
695 : : */
696 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
697 : : /* build the num segments array for segmentation control and release function */
698 [ # # ]: 0 : int vq_segs = NUM_VQ_SEGS(bufs[i]->pkt_len);
699 : 0 : nb_segs_arr[i] = vq_segs;
700 : 0 : nb_segs += vq_segs;
701 : : }
702 : :
703 [ # # ]: 0 : if (!nb_segs)
704 : 0 : goto exit_out;
705 : :
706 [ # # ]: 0 : if (sg_ops == NULL)
707 : 0 : goto exit_out;
708 : :
709 : 0 : int got_nb_segs = sg_ops->nthw_get_tx_packets(tx_q->vq, nb_segs, &first_vq_descr_idx,
710 : : &cvq_desc /*&vq_descr,*/, &vq_bufs);
711 : :
712 [ # # ]: 0 : if (!got_nb_segs)
713 : 0 : goto exit_out;
714 : :
715 : : /*
716 : : * we may get less vq buffers than we have asked for
717 : : * calculate last whole packet that can fit into what
718 : : * we have got
719 : : */
720 [ # # ]: 0 : while (got_nb_segs < nb_segs) {
721 [ # # ]: 0 : if (!--nb_pkts)
722 : 0 : goto exit_out;
723 : :
724 [ # # ]: 0 : nb_segs -= NUM_VQ_SEGS(bufs[nb_pkts]->pkt_len);
725 : :
726 [ # # ]: 0 : if (nb_segs <= 0)
727 : 0 : goto exit_out;
728 : : }
729 : :
730 : : /*
731 : : * nb_pkts & nb_segs, got it all, ready to copy
732 : : */
733 : : int seg_idx = 0;
734 : : int last_seg_idx = seg_idx;
735 : :
736 [ # # ]: 0 : for (pkt = 0; pkt < nb_pkts; ++pkt) {
737 : 0 : uint16_t vq_descr_idx = VIRTQ_DESCR_IDX(seg_idx);
738 : :
739 [ # # # # ]: 0 : vq_set_flags(&cvq_desc, vq_descr_idx, 0);
740 [ # # ]: 0 : vq_set_next(&cvq_desc, vq_descr_idx, 0);
741 : :
742 [ # # # # ]: 0 : if (bufs[pkt]->nb_segs == 1 && nb_segs_arr[pkt] == 1) {
743 : 0 : rte_memcpy((void *)((char *)vq_bufs[vq_descr_idx].virt_addr + SG_HDR_SIZE),
744 [ # # ]: 0 : rte_pktmbuf_mtod(bufs[pkt], void *), bufs[pkt]->pkt_len);
745 : :
746 : 0 : cvq_desc.b[vq_descr_idx].len = bufs[pkt]->pkt_len + SG_HDR_SIZE;
747 : :
748 : 0 : seg_idx++;
749 : :
750 : : } else {
751 : 0 : int cpy_segs = copy_mbuf_to_virtqueue(&cvq_desc, vq_descr_idx, vq_bufs,
752 : : nb_segs - last_seg_idx, bufs[pkt]);
753 : :
754 [ # # ]: 0 : if (cpy_segs < 0)
755 : : break;
756 : :
757 : 0 : seg_idx += cpy_segs;
758 : : }
759 : :
760 : : last_seg_idx = seg_idx;
761 : 0 : rte_pktmbuf_free(bufs[pkt]);
762 : 0 : pkts_sent++;
763 : : }
764 : :
765 : 0 : exit_out:
766 : :
767 [ # # ]: 0 : if (sg_ops != NULL) {
768 [ # # ]: 0 : if (pkts_sent)
769 : 0 : sg_ops->nthw_release_tx_packets(tx_q->vq, pkts_sent, nb_segs_arr);
770 : : }
771 : :
772 : 0 : return pkts_sent;
773 : : }
774 : :
775 : 0 : static int allocate_hw_virtio_queues(struct rte_eth_dev *eth_dev, int vf_num, struct hwq_s *hwq,
776 : : int num_descr, int buf_size)
777 : : {
778 : : int i, res;
779 : : uint32_t size;
780 : : uint64_t iova_addr;
781 : :
782 : 0 : NT_LOG(DBG, NTNIC, "***** Configure IOMMU for HW queues on VF %i *****", vf_num);
783 : :
784 : : /* Just allocate 1MB to hold all combined descr rings */
785 : 0 : uint64_t tot_alloc_size = 0x100000 + (uint64_t)buf_size * (uint64_t)num_descr;
786 : :
787 : : void *virt =
788 : 0 : rte_malloc_socket("VirtQDescr", tot_alloc_size, nt_util_align_size(tot_alloc_size),
789 : 0 : eth_dev->data->numa_node);
790 : :
791 [ # # ]: 0 : if (!virt)
792 : : return -1;
793 : :
794 : 0 : uint64_t gp_offset = (uint64_t)virt & ONE_G_MASK;
795 : 0 : rte_iova_t hpa = rte_malloc_virt2iova(virt);
796 : :
797 : 0 : NT_LOG(DBG, NTNIC, "Allocated virtio descr rings : virt "
798 : : "%p [0x%" PRIX64 "],hpa %" PRIX64 " [0x%" PRIX64 "]",
799 : : virt, gp_offset, hpa, hpa & ONE_G_MASK);
800 : :
801 : : /*
802 : : * Same offset on both HPA and IOVA
803 : : * Make sure 1G boundary is never crossed
804 : : */
805 [ # # ]: 0 : if (((hpa & ONE_G_MASK) != gp_offset) ||
806 [ # # ]: 0 : (((uint64_t)virt + tot_alloc_size) & ~ONE_G_MASK) !=
807 : : ((uint64_t)virt & ~ONE_G_MASK)) {
808 : 0 : NT_LOG(ERR, NTNIC, "*********************************************************");
809 : 0 : NT_LOG(ERR, NTNIC, "ERROR, no optimal IOMMU mapping available hpa: %016" PRIX64
810 : : "(%016" PRIX64 "), gp_offset: %016" PRIX64 " size: %" PRIu64,
811 : : hpa, hpa & ONE_G_MASK, gp_offset, tot_alloc_size);
812 : 0 : NT_LOG(ERR, NTNIC, "*********************************************************");
813 : :
814 : 0 : rte_free(virt);
815 : :
816 : : /* Just allocate 1MB to hold all combined descr rings */
817 : : size = 0x100000;
818 : 0 : void *virt = rte_malloc_socket("VirtQDescr", size, 4096, eth_dev->data->numa_node);
819 : :
820 [ # # ]: 0 : if (!virt)
821 : : return -1;
822 : :
823 : 0 : res = nt_vfio_dma_map(vf_num, virt, &iova_addr, size);
824 : :
825 : 0 : NT_LOG(DBG, NTNIC, "VFIO MMAP res %i, vf_num %i", res, vf_num);
826 : :
827 [ # # ]: 0 : if (res != 0)
828 : : return -1;
829 : :
830 : 0 : hwq->vf_num = vf_num;
831 : 0 : hwq->virt_queues_ctrl.virt_addr = virt;
832 : 0 : hwq->virt_queues_ctrl.phys_addr = (void *)iova_addr;
833 : 0 : hwq->virt_queues_ctrl.len = size;
834 : :
835 : 0 : NT_LOG(DBG, NTNIC,
836 : : "Allocated for virtio descr rings combined 1MB : %p, IOVA %016" PRIX64 "",
837 : : virt, iova_addr);
838 : :
839 : 0 : size = num_descr * sizeof(struct nthw_memory_descriptor);
840 : 0 : hwq->pkt_buffers =
841 : 0 : rte_zmalloc_socket("rx_pkt_buffers", size, 64, eth_dev->data->numa_node);
842 : :
843 [ # # ]: 0 : if (!hwq->pkt_buffers) {
844 : 0 : NT_LOG(ERR, NTNIC,
845 : : "Failed to allocated buffer array for hw-queue %p, total size %i, elements %i",
846 : : hwq->pkt_buffers, size, num_descr);
847 : 0 : rte_free(virt);
848 : 0 : return -1;
849 : : }
850 : :
851 : 0 : size = buf_size * num_descr;
852 : : void *virt_addr =
853 : 0 : rte_malloc_socket("pkt_buffer_pkts", size, 4096, eth_dev->data->numa_node);
854 : :
855 [ # # ]: 0 : if (!virt_addr) {
856 : 0 : NT_LOG(ERR, NTNIC,
857 : : "Failed allocate packet buffers for hw-queue %p, buf size %i, elements %i",
858 : : hwq->pkt_buffers, buf_size, num_descr);
859 : 0 : rte_free(hwq->pkt_buffers);
860 : 0 : rte_free(virt);
861 : 0 : return -1;
862 : : }
863 : :
864 : 0 : res = nt_vfio_dma_map(vf_num, virt_addr, &iova_addr, size);
865 : :
866 : 0 : NT_LOG(DBG, NTNIC,
867 : : "VFIO MMAP res %i, virt %p, iova %016" PRIX64 ", vf_num %i, num pkt bufs %i, tot size %i",
868 : : res, virt_addr, iova_addr, vf_num, num_descr, size);
869 : :
870 [ # # ]: 0 : if (res != 0)
871 : : return -1;
872 : :
873 [ # # ]: 0 : for (i = 0; i < num_descr; i++) {
874 : 0 : hwq->pkt_buffers[i].virt_addr =
875 : 0 : (void *)((char *)virt_addr + ((uint64_t)(i) * buf_size));
876 : 0 : hwq->pkt_buffers[i].phys_addr =
877 : 0 : (void *)(iova_addr + ((uint64_t)(i) * buf_size));
878 : 0 : hwq->pkt_buffers[i].len = buf_size;
879 : : }
880 : :
881 : : return 0;
882 : : } /* End of: no optimal IOMMU mapping available */
883 : :
884 : 0 : res = nt_vfio_dma_map(vf_num, virt, &iova_addr, ONE_G_SIZE);
885 : :
886 [ # # ]: 0 : if (res != 0) {
887 : 0 : NT_LOG(ERR, NTNIC, "VFIO MMAP FAILED! res %i, vf_num %i", res, vf_num);
888 : 0 : return -1;
889 : : }
890 : :
891 : 0 : hwq->vf_num = vf_num;
892 : 0 : hwq->virt_queues_ctrl.virt_addr = virt;
893 : 0 : hwq->virt_queues_ctrl.phys_addr = (void *)(iova_addr);
894 : 0 : hwq->virt_queues_ctrl.len = 0x100000;
895 : 0 : iova_addr += 0x100000;
896 : :
897 : 0 : NT_LOG(DBG, NTNIC,
898 : : "VFIO MMAP: virt_addr=%p phys_addr=%p size=%" PRIX32 " hpa=%" PRIX64 "",
899 : : hwq->virt_queues_ctrl.virt_addr, hwq->virt_queues_ctrl.phys_addr,
900 : : hwq->virt_queues_ctrl.len, rte_malloc_virt2iova(hwq->virt_queues_ctrl.virt_addr));
901 : :
902 : 0 : size = num_descr * sizeof(struct nthw_memory_descriptor);
903 : 0 : hwq->pkt_buffers =
904 : 0 : rte_zmalloc_socket("rx_pkt_buffers", size, 64, eth_dev->data->numa_node);
905 : :
906 [ # # ]: 0 : if (!hwq->pkt_buffers) {
907 : 0 : NT_LOG(ERR, NTNIC,
908 : : "Failed to allocated buffer array for hw-queue %p, total size %i, elements %i",
909 : : hwq->pkt_buffers, size, num_descr);
910 : 0 : rte_free(virt);
911 : 0 : return -1;
912 : : }
913 : :
914 : 0 : void *virt_addr = (void *)((uint64_t)virt + 0x100000);
915 : :
916 [ # # ]: 0 : for (i = 0; i < num_descr; i++) {
917 : 0 : hwq->pkt_buffers[i].virt_addr =
918 : 0 : (void *)((char *)virt_addr + ((uint64_t)(i) * buf_size));
919 : 0 : hwq->pkt_buffers[i].phys_addr = (void *)(iova_addr + ((uint64_t)(i) * buf_size));
920 : 0 : hwq->pkt_buffers[i].len = buf_size;
921 : : }
922 : :
923 : : return 0;
924 : : }
925 : :
926 : : static void release_hw_virtio_queues(struct hwq_s *hwq)
927 : : {
928 [ # # # # : 0 : if (!hwq || hwq->vf_num == 0)
# # ]
929 : : return;
930 : :
931 : 0 : hwq->vf_num = 0;
932 : : }
933 : :
934 : 0 : static int deallocate_hw_virtio_queues(struct hwq_s *hwq)
935 : : {
936 : 0 : int vf_num = hwq->vf_num;
937 : :
938 : 0 : void *virt = hwq->virt_queues_ctrl.virt_addr;
939 : :
940 : 0 : int res = nt_vfio_dma_unmap(vf_num, hwq->virt_queues_ctrl.virt_addr,
941 : 0 : (uint64_t)hwq->virt_queues_ctrl.phys_addr, ONE_G_SIZE);
942 : :
943 [ # # ]: 0 : if (res != 0) {
944 : 0 : NT_LOG(ERR, NTNIC, "VFIO UNMMAP FAILED! res %i, vf_num %i", res, vf_num);
945 : 0 : return -1;
946 : : }
947 : :
948 : : release_hw_virtio_queues(hwq);
949 : 0 : rte_free(hwq->pkt_buffers);
950 : 0 : rte_free(virt);
951 : 0 : return 0;
952 : : }
953 : :
954 : 0 : static void eth_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t queue_id)
955 : : {
956 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
957 : 0 : struct ntnic_tx_queue *tx_q = &internals->txq_scg[queue_id];
958 : 0 : deallocate_hw_virtio_queues(&tx_q->hwq);
959 : 0 : }
960 : :
961 : 0 : static void eth_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t queue_id)
962 : : {
963 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
964 : 0 : struct ntnic_rx_queue *rx_q = &internals->rxq_scg[queue_id];
965 : 0 : deallocate_hw_virtio_queues(&rx_q->hwq);
966 : 0 : }
967 : :
968 : : static int num_queues_alloced;
969 : :
970 : : /* Returns num queue starting at returned queue num or -1 on fail */
971 : 0 : static int allocate_queue(int num)
972 : : {
973 : 0 : int next_free = num_queues_alloced;
974 : 0 : NT_LOG_DBGX(DBG, NTNIC, "num_queues_alloced=%u, New queues=%u, Max queues=%u",
975 : : num_queues_alloced, num, MAX_TOTAL_QUEUES);
976 : :
977 [ # # ]: 0 : if (num_queues_alloced + num > MAX_TOTAL_QUEUES)
978 : : return -1;
979 : :
980 : 0 : num_queues_alloced += num;
981 : 0 : return next_free;
982 : : }
983 : :
984 : 0 : static int eth_rx_scg_queue_setup(struct rte_eth_dev *eth_dev,
985 : : uint16_t rx_queue_id,
986 : : uint16_t nb_rx_desc __rte_unused,
987 : : unsigned int socket_id __rte_unused,
988 : : const struct rte_eth_rxconf *rx_conf __rte_unused,
989 : : struct rte_mempool *mb_pool)
990 : : {
991 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Rx queue setup");
992 : : struct rte_pktmbuf_pool_private *mbp_priv;
993 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
994 : 0 : struct ntnic_rx_queue *rx_q = &internals->rxq_scg[rx_queue_id];
995 : 0 : struct drv_s *p_drv = internals->p_drv;
996 : : struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv;
997 : :
998 [ # # ]: 0 : if (sg_ops == NULL) {
999 : 0 : NT_LOG_DBGX(DBG, NTNIC, "SG module is not initialized");
1000 : 0 : return 0;
1001 : : }
1002 : :
1003 [ # # ]: 0 : if (internals->type == PORT_TYPE_OVERRIDE) {
1004 : 0 : rx_q->mb_pool = mb_pool;
1005 : 0 : eth_dev->data->rx_queues[rx_queue_id] = rx_q;
1006 [ # # ]: 0 : mbp_priv = rte_mempool_get_priv(rx_q->mb_pool);
1007 : 0 : rx_q->buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
1008 : 0 : rx_q->enabled = 1;
1009 : 0 : return 0;
1010 : : }
1011 : :
1012 : 0 : NT_LOG(DBG, NTNIC, "(%i) NTNIC RX OVS-SW queue setup: queue id %i, hw queue index %i",
1013 : : internals->port, rx_queue_id, rx_q->queue.hw_id);
1014 : :
1015 : 0 : rx_q->mb_pool = mb_pool;
1016 : :
1017 : 0 : eth_dev->data->rx_queues[rx_queue_id] = rx_q;
1018 : :
1019 [ # # ]: 0 : mbp_priv = rte_mempool_get_priv(rx_q->mb_pool);
1020 : 0 : rx_q->buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
1021 : 0 : rx_q->enabled = 1;
1022 : :
1023 [ # # ]: 0 : if (allocate_hw_virtio_queues(eth_dev, EXCEPTION_PATH_HID, &rx_q->hwq,
1024 : : SG_NB_HW_RX_DESCRIPTORS, SG_HW_RX_PKT_BUFFER_SIZE) < 0)
1025 : : return -1;
1026 : :
1027 : 0 : rx_q->nb_hw_rx_descr = SG_NB_HW_RX_DESCRIPTORS;
1028 : :
1029 : 0 : rx_q->profile = p_drv->ntdrv.adapter_info.fpga_info.profile;
1030 : :
1031 : 0 : rx_q->vq =
1032 : 0 : sg_ops->nthw_setup_mngd_rx_virt_queue(p_nt_drv->adapter_info.fpga_info.mp_nthw_dbs,
1033 : 0 : rx_q->queue.hw_id, /* index */
1034 : : rx_q->nb_hw_rx_descr,
1035 : : EXCEPTION_PATH_HID, /* host_id */
1036 : : 1, /* header NT DVIO header for exception path */
1037 : : &rx_q->hwq.virt_queues_ctrl,
1038 : : rx_q->hwq.pkt_buffers,
1039 : : SPLIT_RING,
1040 : : -1);
1041 : :
1042 : 0 : NT_LOG(DBG, NTNIC, "(%i) NTNIC RX OVS-SW queues successfully setup", internals->port);
1043 : :
1044 : 0 : return 0;
1045 : : }
1046 : :
1047 : 0 : static int eth_tx_scg_queue_setup(struct rte_eth_dev *eth_dev,
1048 : : uint16_t tx_queue_id,
1049 : : uint16_t nb_tx_desc __rte_unused,
1050 : : unsigned int socket_id __rte_unused,
1051 : : const struct rte_eth_txconf *tx_conf __rte_unused)
1052 : : {
1053 : 0 : const struct port_ops *port_ops = get_port_ops();
1054 : :
1055 [ # # ]: 0 : if (port_ops == NULL) {
1056 : 0 : NT_LOG_DBGX(ERR, NTNIC, "Link management module uninitialized");
1057 : 0 : return -1;
1058 : : }
1059 : :
1060 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Tx queue setup");
1061 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1062 : 0 : struct drv_s *p_drv = internals->p_drv;
1063 : : struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv;
1064 : 0 : struct ntnic_tx_queue *tx_q = &internals->txq_scg[tx_queue_id];
1065 : :
1066 [ # # ]: 0 : if (internals->type == PORT_TYPE_OVERRIDE) {
1067 : 0 : eth_dev->data->tx_queues[tx_queue_id] = tx_q;
1068 : 0 : return 0;
1069 : : }
1070 : :
1071 [ # # ]: 0 : if (sg_ops == NULL) {
1072 : 0 : NT_LOG_DBGX(DBG, NTNIC, "SG module is not initialized");
1073 : 0 : return 0;
1074 : : }
1075 : :
1076 : 0 : NT_LOG(DBG, NTNIC, "(%i) NTNIC TX OVS-SW queue setup: queue id %i, hw queue index %i",
1077 : : tx_q->port, tx_queue_id, tx_q->queue.hw_id);
1078 : :
1079 [ # # ]: 0 : if (tx_queue_id > internals->nb_tx_queues) {
1080 : 0 : NT_LOG(ERR, NTNIC, "Error invalid tx queue id");
1081 : 0 : return -1;
1082 : : }
1083 : :
1084 : 0 : eth_dev->data->tx_queues[tx_queue_id] = tx_q;
1085 : :
1086 : : /* Calculate target ID for HW - to be used in NTDVIO0 header bypass_port */
1087 [ # # ]: 0 : if (tx_q->rss_target_id >= 0) {
1088 : : /* bypass to a multiqueue port - qsl-hsh index */
1089 : 0 : tx_q->target_id = tx_q->rss_target_id + 0x90;
1090 : :
1091 [ # # ]: 0 : } else if (internals->vpq[tx_queue_id].hw_id > -1) {
1092 : : /* virtual port - queue index */
1093 : 0 : tx_q->target_id = internals->vpq[tx_queue_id].hw_id;
1094 : :
1095 : : } else {
1096 : : /* Phy port - phy port identifier */
1097 : : /* output/bypass to MAC */
1098 : 0 : tx_q->target_id = (int)(tx_q->port + 0x80);
1099 : : }
1100 : :
1101 [ # # ]: 0 : if (allocate_hw_virtio_queues(eth_dev, EXCEPTION_PATH_HID, &tx_q->hwq,
1102 : : SG_NB_HW_TX_DESCRIPTORS, SG_HW_TX_PKT_BUFFER_SIZE) < 0) {
1103 : : return -1;
1104 : : }
1105 : :
1106 : 0 : tx_q->nb_hw_tx_descr = SG_NB_HW_TX_DESCRIPTORS;
1107 : :
1108 : 0 : tx_q->profile = p_drv->ntdrv.adapter_info.fpga_info.profile;
1109 : :
1110 : : uint32_t port, header;
1111 : 0 : port = tx_q->port; /* transmit port */
1112 : : header = 0; /* header type VirtIO-Net */
1113 : :
1114 : 0 : tx_q->vq =
1115 : 0 : sg_ops->nthw_setup_mngd_tx_virt_queue(p_nt_drv->adapter_info.fpga_info.mp_nthw_dbs,
1116 : 0 : tx_q->queue.hw_id, /* index */
1117 : : tx_q->nb_hw_tx_descr, /* queue size */
1118 : : EXCEPTION_PATH_HID, /* host_id always VF4 */
1119 : : port,
1120 : : /*
1121 : : * in_port - in vswitch mode has
1122 : : * to move tx port from OVS excep.
1123 : : * away from VM tx port,
1124 : : * because of QoS is matched by port id!
1125 : : */
1126 : : tx_q->port + 128,
1127 : : header,
1128 : : &tx_q->hwq.virt_queues_ctrl,
1129 : : tx_q->hwq.pkt_buffers,
1130 : : SPLIT_RING,
1131 : : -1,
1132 : : IN_ORDER);
1133 : :
1134 : 0 : tx_q->enabled = 1;
1135 : :
1136 : 0 : NT_LOG(DBG, NTNIC, "(%i) NTNIC TX OVS-SW queues successfully setup", internals->port);
1137 : :
1138 [ # # ]: 0 : if (internals->type == PORT_TYPE_PHYSICAL) {
1139 : 0 : struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
1140 : 0 : NT_LOG(DBG, NTNIC, "Port %i is ready for data. Enable port",
1141 : : internals->n_intf_no);
1142 : 0 : port_ops->set_adm_state(p_adapter_info, internals->n_intf_no, true);
1143 : : }
1144 : :
1145 : : return 0;
1146 : : }
1147 : :
1148 : 0 : static int dev_set_mtu_inline(struct rte_eth_dev *eth_dev, uint16_t mtu)
1149 : : {
1150 : 0 : const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
1151 : :
1152 [ # # ]: 0 : if (profile_inline_ops == NULL) {
1153 : 0 : NT_LOG_DBGX(ERR, NTNIC, "profile_inline module uninitialized");
1154 : 0 : return -1;
1155 : : }
1156 : :
1157 : 0 : struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
1158 : :
1159 : 0 : struct flow_eth_dev *flw_dev = internals->flw_dev;
1160 : : int ret = -1;
1161 : :
1162 [ # # # # ]: 0 : if (internals->type == PORT_TYPE_PHYSICAL && mtu >= MIN_MTU_INLINE && mtu <= MAX_MTU)
1163 : 0 : ret = profile_inline_ops->flow_set_mtu_inline(flw_dev, internals->port, mtu);
1164 : :
1165 [ # # ]: 0 : return ret ? -EINVAL : 0;
1166 : : }
1167 : :
1168 : 0 : static int eth_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
1169 : : {
1170 : 0 : eth_dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1171 : 0 : return 0;
1172 : : }
1173 : :
1174 : 0 : static int eth_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
1175 : : {
1176 : 0 : eth_dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1177 : 0 : return 0;
1178 : : }
1179 : :
1180 : 0 : static int eth_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
1181 : : {
1182 : 0 : eth_dev->data->tx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1183 : 0 : return 0;
1184 : : }
1185 : :
1186 : 0 : static int eth_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
1187 : : {
1188 : 0 : eth_dev->data->tx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1189 : 0 : return 0;
1190 : : }
1191 : :
1192 : : static int
1193 : 0 : eth_mac_addr_add(struct rte_eth_dev *eth_dev,
1194 : : struct rte_ether_addr *mac_addr,
1195 : : uint32_t index,
1196 : : uint32_t vmdq __rte_unused)
1197 : : {
1198 : 0 : struct rte_ether_addr *const eth_addrs = eth_dev->data->mac_addrs;
1199 : :
1200 : : RTE_ASSERT(index < NUM_MAC_ADDRS_PER_PORT);
1201 : :
1202 [ # # ]: 0 : if (index >= NUM_MAC_ADDRS_PER_PORT) {
1203 : 0 : const struct pmd_internals *const internals =
1204 : : eth_dev->data->dev_private;
1205 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Port %i: illegal index %u (>= %u)",
1206 : : internals->n_intf_no, index, NUM_MAC_ADDRS_PER_PORT);
1207 : 0 : return -1;
1208 : : }
1209 : :
1210 : 0 : eth_addrs[index] = *mac_addr;
1211 : :
1212 : 0 : return 0;
1213 : : }
1214 : :
1215 : : static int
1216 : 0 : eth_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1217 : : {
1218 : 0 : struct rte_ether_addr *const eth_addrs = dev->data->mac_addrs;
1219 : :
1220 : 0 : eth_addrs[0U] = *mac_addr;
1221 : :
1222 : 0 : return 0;
1223 : : }
1224 : :
1225 : : static int
1226 : 0 : eth_set_mc_addr_list(struct rte_eth_dev *eth_dev,
1227 : : struct rte_ether_addr *mc_addr_set,
1228 : : uint32_t nb_mc_addr)
1229 : : {
1230 : 0 : struct pmd_internals *const internals = eth_dev->data->dev_private;
1231 : 0 : struct rte_ether_addr *const mc_addrs = internals->mc_addrs;
1232 : : size_t i;
1233 : :
1234 [ # # ]: 0 : if (nb_mc_addr >= NUM_MULTICAST_ADDRS_PER_PORT) {
1235 : 0 : NT_LOG_DBGX(DBG, NTNIC,
1236 : : "Port %i: too many multicast addresses %u (>= %u)",
1237 : : internals->n_intf_no, nb_mc_addr, NUM_MULTICAST_ADDRS_PER_PORT);
1238 : 0 : return -1;
1239 : : }
1240 : :
1241 [ # # ]: 0 : for (i = 0U; i < NUM_MULTICAST_ADDRS_PER_PORT; i++)
1242 [ # # ]: 0 : if (i < nb_mc_addr)
1243 : 0 : mc_addrs[i] = mc_addr_set[i];
1244 : :
1245 : : else
1246 : 0 : (void)memset(&mc_addrs[i], 0, sizeof(mc_addrs[i]));
1247 : :
1248 : : return 0;
1249 : : }
1250 : :
1251 : : static int
1252 : 0 : eth_dev_configure(struct rte_eth_dev *eth_dev)
1253 : : {
1254 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Called for eth_dev %p", eth_dev);
1255 : :
1256 : : /* The device is ALWAYS running promiscuous mode. */
1257 : 0 : eth_dev->data->promiscuous ^= ~eth_dev->data->promiscuous;
1258 : 0 : return 0;
1259 : : }
1260 : :
1261 : : static int
1262 : 0 : eth_dev_start(struct rte_eth_dev *eth_dev)
1263 : : {
1264 : 0 : const struct port_ops *port_ops = get_port_ops();
1265 : :
1266 [ # # ]: 0 : if (port_ops == NULL) {
1267 : 0 : NT_LOG(ERR, NTNIC, "Link management module uninitialized");
1268 : 0 : return -1;
1269 : : }
1270 : :
1271 : 0 : eth_dev->flow_fp_ops = get_dev_fp_flow_ops();
1272 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1273 : :
1274 : 0 : const int n_intf_no = internals->n_intf_no;
1275 : 0 : struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
1276 : :
1277 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Port %u", internals->n_intf_no);
1278 : :
1279 : : /* Start queues */
1280 : : uint q;
1281 : :
1282 [ # # ]: 0 : for (q = 0; q < internals->nb_rx_queues; q++)
1283 : 0 : eth_rx_queue_start(eth_dev, q);
1284 : :
1285 [ # # ]: 0 : for (q = 0; q < internals->nb_tx_queues; q++)
1286 : 0 : eth_tx_queue_start(eth_dev, q);
1287 : :
1288 [ # # ]: 0 : if (internals->type == PORT_TYPE_VIRTUAL || internals->type == PORT_TYPE_OVERRIDE) {
1289 : 0 : eth_dev->data->dev_link.link_status = RTE_ETH_LINK_UP;
1290 : :
1291 : : } else {
1292 : : /* Enable the port */
1293 : 0 : port_ops->set_adm_state(p_adapter_info, internals->n_intf_no, true);
1294 : :
1295 : : /*
1296 : : * wait for link on port
1297 : : * If application starts sending too soon before FPGA port is ready, garbage is
1298 : : * produced
1299 : : */
1300 : : int loop = 0;
1301 : :
1302 [ # # ]: 0 : while (port_ops->get_link_status(p_adapter_info, n_intf_no) == RTE_ETH_LINK_DOWN) {
1303 : : /* break out after 5 sec */
1304 [ # # ]: 0 : if (++loop >= 50) {
1305 : 0 : NT_LOG_DBGX(DBG, NTNIC,
1306 : : "TIMEOUT No link on port %i (5sec timeout)",
1307 : : internals->n_intf_no);
1308 : 0 : break;
1309 : : }
1310 : :
1311 : 0 : nt_os_wait_usec(100 * 1000);
1312 : : }
1313 : :
1314 [ # # ]: 0 : if (internals->lpbk_mode) {
1315 [ # # ]: 0 : if (internals->lpbk_mode & 1 << 0) {
1316 : 0 : port_ops->set_loopback_mode(p_adapter_info, n_intf_no,
1317 : : NT_LINK_LOOPBACK_HOST);
1318 : : }
1319 : :
1320 [ # # ]: 0 : if (internals->lpbk_mode & 1 << 1) {
1321 : 0 : port_ops->set_loopback_mode(p_adapter_info, n_intf_no,
1322 : : NT_LINK_LOOPBACK_LINE);
1323 : : }
1324 : : }
1325 : : }
1326 : :
1327 : : return 0;
1328 : : }
1329 : :
1330 : : static int
1331 : 0 : eth_dev_stop(struct rte_eth_dev *eth_dev)
1332 : : {
1333 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1334 : :
1335 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Port %u", internals->n_intf_no);
1336 : :
1337 [ # # ]: 0 : if (internals->type != PORT_TYPE_VIRTUAL) {
1338 : : uint q;
1339 : :
1340 [ # # ]: 0 : for (q = 0; q < internals->nb_rx_queues; q++)
1341 : 0 : eth_rx_queue_stop(eth_dev, q);
1342 : :
1343 [ # # ]: 0 : for (q = 0; q < internals->nb_tx_queues; q++)
1344 : 0 : eth_tx_queue_stop(eth_dev, q);
1345 : : }
1346 : :
1347 : 0 : eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;
1348 : 0 : return 0;
1349 : : }
1350 : :
1351 : : static int
1352 : 0 : eth_dev_set_link_up(struct rte_eth_dev *eth_dev)
1353 : : {
1354 : 0 : const struct port_ops *port_ops = get_port_ops();
1355 : :
1356 [ # # ]: 0 : if (port_ops == NULL) {
1357 : 0 : NT_LOG(ERR, NTNIC, "Link management module uninitialized");
1358 : 0 : return -1;
1359 : : }
1360 : :
1361 : 0 : struct pmd_internals *const internals = eth_dev->data->dev_private;
1362 : :
1363 : 0 : struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
1364 : 0 : const int port = internals->n_intf_no;
1365 : :
1366 [ # # ]: 0 : if (internals->type == PORT_TYPE_VIRTUAL || internals->type == PORT_TYPE_OVERRIDE)
1367 : : return 0;
1368 : :
1369 : : RTE_ASSERT(port >= 0 && port < NUM_ADAPTER_PORTS_MAX);
1370 : : RTE_ASSERT(port == internals->n_intf_no);
1371 : :
1372 : 0 : port_ops->set_adm_state(p_adapter_info, port, true);
1373 : :
1374 : 0 : return 0;
1375 : : }
1376 : :
1377 : : static int
1378 : 0 : eth_dev_set_link_down(struct rte_eth_dev *eth_dev)
1379 : : {
1380 : 0 : const struct port_ops *port_ops = get_port_ops();
1381 : :
1382 [ # # ]: 0 : if (port_ops == NULL) {
1383 : 0 : NT_LOG(ERR, NTNIC, "Link management module uninitialized");
1384 : 0 : return -1;
1385 : : }
1386 : :
1387 : 0 : struct pmd_internals *const internals = eth_dev->data->dev_private;
1388 : :
1389 : 0 : struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
1390 : 0 : const int port = internals->n_intf_no;
1391 : :
1392 [ # # ]: 0 : if (internals->type == PORT_TYPE_VIRTUAL || internals->type == PORT_TYPE_OVERRIDE)
1393 : : return 0;
1394 : :
1395 : : RTE_ASSERT(port >= 0 && port < NUM_ADAPTER_PORTS_MAX);
1396 : : RTE_ASSERT(port == internals->n_intf_no);
1397 : :
1398 : 0 : port_ops->set_link_status(p_adapter_info, port, false);
1399 : :
1400 : 0 : return 0;
1401 : : }
1402 : :
1403 : : static void
1404 : 0 : drv_deinit(struct drv_s *p_drv)
1405 : : {
1406 : 0 : const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
1407 : :
1408 [ # # ]: 0 : if (profile_inline_ops == NULL) {
1409 : 0 : NT_LOG_DBGX(ERR, NTNIC, "profile_inline module uninitialized");
1410 : 0 : return;
1411 : : }
1412 : :
1413 : 0 : const struct adapter_ops *adapter_ops = get_adapter_ops();
1414 : :
1415 [ # # ]: 0 : if (adapter_ops == NULL) {
1416 : 0 : NT_LOG(ERR, NTNIC, "Adapter module uninitialized");
1417 : 0 : return;
1418 : : }
1419 : :
1420 [ # # ]: 0 : if (p_drv == NULL)
1421 : : return;
1422 : :
1423 : 0 : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1424 : : fpga_info_t *fpga_info = &p_nt_drv->adapter_info.fpga_info;
1425 : :
1426 : : /*
1427 : : * Mark the global pdrv for cleared. Used by some threads to terminate.
1428 : : * 1 second to give the threads a chance to see the termonation.
1429 : : */
1430 : 0 : clear_pdrv(p_drv);
1431 : 0 : nt_os_wait_usec(1000000);
1432 : :
1433 : : /* stop statistics threads */
1434 : 0 : p_drv->ntdrv.b_shutdown = true;
1435 : 0 : THREAD_JOIN(p_nt_drv->stat_thread);
1436 : :
1437 [ # # ]: 0 : if (fpga_info->profile == FPGA_INFO_PROFILE_INLINE) {
1438 : 0 : THREAD_JOIN(p_nt_drv->flm_thread);
1439 : 0 : profile_inline_ops->flm_free_queues();
1440 : 0 : THREAD_JOIN(p_nt_drv->port_event_thread);
1441 : : /* Free all local flm event queues */
1442 : 0 : nthw_flm_inf_sta_queue_free_all(FLM_INFO_LOCAL);
1443 : : /* Free all remote flm event queues */
1444 : 0 : nthw_flm_inf_sta_queue_free_all(FLM_INFO_REMOTE);
1445 : : /* Free all aged flow event queues */
1446 : 0 : flm_age_queue_free_all();
1447 : : }
1448 : :
1449 : : /* stop adapter */
1450 : 0 : adapter_ops->deinit(&p_nt_drv->adapter_info);
1451 : :
1452 : : /* clean memory */
1453 : 0 : rte_free(p_drv);
1454 : : p_drv = NULL;
1455 : : }
1456 : :
1457 : : static int
1458 : 0 : eth_dev_close(struct rte_eth_dev *eth_dev)
1459 : : {
1460 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1461 : 0 : struct drv_s *p_drv = internals->p_drv;
1462 : :
1463 [ # # ]: 0 : if (internals->type != PORT_TYPE_VIRTUAL) {
1464 : 0 : struct ntnic_rx_queue *rx_q = internals->rxq_scg;
1465 : 0 : struct ntnic_tx_queue *tx_q = internals->txq_scg;
1466 : :
1467 : : uint q;
1468 : :
1469 [ # # ]: 0 : if (sg_ops != NULL) {
1470 [ # # ]: 0 : for (q = 0; q < internals->nb_rx_queues; q++)
1471 : 0 : sg_ops->nthw_release_mngd_rx_virt_queue(rx_q[q].vq);
1472 : :
1473 [ # # ]: 0 : for (q = 0; q < internals->nb_tx_queues; q++)
1474 : 0 : sg_ops->nthw_release_mngd_tx_virt_queue(tx_q[q].vq);
1475 : : }
1476 : : }
1477 : :
1478 : 0 : internals->p_drv = NULL;
1479 : :
1480 [ # # ]: 0 : if (p_drv) {
1481 : : /* decrease initialized ethernet devices */
1482 : 0 : p_drv->n_eth_dev_init_count--;
1483 : :
1484 : : /*
1485 : : * rte_pci_dev has no private member for p_drv
1486 : : * wait until all rte_eth_dev's are closed - then close adapters via p_drv
1487 : : */
1488 [ # # ]: 0 : if (!p_drv->n_eth_dev_init_count)
1489 : 0 : drv_deinit(p_drv);
1490 : : }
1491 : :
1492 : 0 : return 0;
1493 : : }
1494 : :
1495 : : static int
1496 : 0 : eth_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version, size_t fw_size)
1497 : : {
1498 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1499 : :
1500 [ # # ]: 0 : if (internals->type == PORT_TYPE_VIRTUAL || internals->type == PORT_TYPE_OVERRIDE)
1501 : : return 0;
1502 : :
1503 : 0 : fpga_info_t *fpga_info = &internals->p_drv->ntdrv.adapter_info.fpga_info;
1504 [ # # ]: 0 : const int length = snprintf(fw_version, fw_size, "%03d-%04d-%02d-%02d",
1505 : : fpga_info->n_fpga_type_id, fpga_info->n_fpga_prod_id,
1506 : : fpga_info->n_fpga_ver_id, fpga_info->n_fpga_rev_id);
1507 : :
1508 [ # # ]: 0 : if ((size_t)length < fw_size) {
1509 : : /* We have space for the version string */
1510 : : return 0;
1511 : :
1512 : : } else {
1513 : : /* We do not have space for the version string -return the needed space */
1514 : 0 : return length + 1;
1515 : : }
1516 : : }
1517 : :
1518 : 0 : static int dev_flow_ops_get(struct rte_eth_dev *dev __rte_unused, const struct rte_flow_ops **ops)
1519 : : {
1520 : 0 : *ops = get_dev_flow_ops();
1521 : 0 : return 0;
1522 : : }
1523 : :
1524 : 0 : static int eth_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *stats, unsigned int n)
1525 : : {
1526 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1527 : 0 : struct drv_s *p_drv = internals->p_drv;
1528 : : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1529 : 0 : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1530 : 0 : int if_index = internals->n_intf_no;
1531 : : int nb_xstats;
1532 : :
1533 : 0 : const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops();
1534 : :
1535 [ # # ]: 0 : if (ntnic_xstats_ops == NULL) {
1536 : 0 : NT_LOG(INF, NTNIC, "ntnic_xstats module not included");
1537 : 0 : return -1;
1538 : : }
1539 : :
1540 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
1541 : 0 : nb_xstats = ntnic_xstats_ops->nthw_xstats_get(p_nt4ga_stat, stats, n, if_index);
1542 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
1543 : 0 : return nb_xstats;
1544 : : }
1545 : :
1546 : 0 : static int eth_xstats_get_by_id(struct rte_eth_dev *eth_dev,
1547 : : const uint64_t *ids,
1548 : : uint64_t *values,
1549 : : unsigned int n)
1550 : : {
1551 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1552 : 0 : struct drv_s *p_drv = internals->p_drv;
1553 : : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1554 : 0 : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1555 : 0 : int if_index = internals->n_intf_no;
1556 : : int nb_xstats;
1557 : :
1558 : 0 : const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops();
1559 : :
1560 [ # # ]: 0 : if (ntnic_xstats_ops == NULL) {
1561 : 0 : NT_LOG(INF, NTNIC, "ntnic_xstats module not included");
1562 : 0 : return -1;
1563 : : }
1564 : :
1565 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
1566 : : nb_xstats =
1567 : 0 : ntnic_xstats_ops->nthw_xstats_get_by_id(p_nt4ga_stat, ids, values, n, if_index);
1568 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
1569 : 0 : return nb_xstats;
1570 : : }
1571 : :
1572 : 0 : static int eth_xstats_reset(struct rte_eth_dev *eth_dev)
1573 : : {
1574 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1575 : 0 : struct drv_s *p_drv = internals->p_drv;
1576 : 0 : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1577 : 0 : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1578 : 0 : int if_index = internals->n_intf_no;
1579 : :
1580 : 0 : struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops();
1581 : :
1582 [ # # ]: 0 : if (ntnic_xstats_ops == NULL) {
1583 : 0 : NT_LOG(INF, NTNIC, "ntnic_xstats module not included");
1584 : 0 : return -1;
1585 : : }
1586 : :
1587 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
1588 : 0 : ntnic_xstats_ops->nthw_xstats_reset(p_nt4ga_stat, if_index);
1589 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
1590 : 0 : return dpdk_stats_reset(internals, p_nt_drv, if_index);
1591 : : }
1592 : :
1593 : 0 : static int eth_xstats_get_names(struct rte_eth_dev *eth_dev,
1594 : : struct rte_eth_xstat_name *xstats_names, unsigned int size)
1595 : : {
1596 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1597 : 0 : struct drv_s *p_drv = internals->p_drv;
1598 : : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1599 : 0 : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1600 : :
1601 : 0 : const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops();
1602 : :
1603 [ # # ]: 0 : if (ntnic_xstats_ops == NULL) {
1604 : 0 : NT_LOG(INF, NTNIC, "ntnic_xstats module not included");
1605 : 0 : return -1;
1606 : : }
1607 : :
1608 : 0 : return ntnic_xstats_ops->nthw_xstats_get_names(p_nt4ga_stat, xstats_names, size);
1609 : : }
1610 : :
1611 : 0 : static int eth_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
1612 : : const uint64_t *ids,
1613 : : struct rte_eth_xstat_name *xstats_names,
1614 : : unsigned int size)
1615 : : {
1616 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1617 : 0 : struct drv_s *p_drv = internals->p_drv;
1618 : : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1619 : 0 : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1620 : 0 : const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops();
1621 : :
1622 [ # # ]: 0 : if (ntnic_xstats_ops == NULL) {
1623 : 0 : NT_LOG(INF, NTNIC, "ntnic_xstats module not included");
1624 : 0 : return -1;
1625 : : }
1626 : :
1627 : 0 : return ntnic_xstats_ops->nthw_xstats_get_names_by_id(p_nt4ga_stat, xstats_names, ids,
1628 : : size);
1629 : : }
1630 : :
1631 : : static int
1632 : 0 : promiscuous_enable(struct rte_eth_dev __rte_unused(*dev))
1633 : : {
1634 : 0 : NT_LOG(DBG, NTHW, "The device always run promiscuous mode");
1635 : 0 : return 0;
1636 : : }
1637 : :
1638 : 0 : static int eth_dev_rss_hash_update(struct rte_eth_dev *eth_dev, struct rte_eth_rss_conf *rss_conf)
1639 : : {
1640 : 0 : const struct flow_filter_ops *flow_filter_ops = get_flow_filter_ops();
1641 : :
1642 [ # # ]: 0 : if (flow_filter_ops == NULL) {
1643 : 0 : NT_LOG_DBGX(ERR, NTNIC, "flow_filter module uninitialized");
1644 : 0 : return -1;
1645 : : }
1646 : :
1647 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1648 : :
1649 : 0 : struct flow_nic_dev *ndev = internals->flw_dev->ndev;
1650 : 0 : struct nt_eth_rss_conf tmp_rss_conf = { 0 };
1651 : : const int hsh_idx = 0; /* hsh index 0 means the default receipt in HSH module */
1652 : :
1653 [ # # ]: 0 : if (rss_conf->rss_key != NULL) {
1654 [ # # ]: 0 : if (rss_conf->rss_key_len > MAX_RSS_KEY_LEN) {
1655 : 0 : NT_LOG(ERR, NTNIC,
1656 : : "ERROR: - RSS hash key length %u exceeds maximum value %u",
1657 : : rss_conf->rss_key_len, MAX_RSS_KEY_LEN);
1658 : 0 : return -1;
1659 : : }
1660 : :
1661 [ # # ]: 0 : rte_memcpy(&tmp_rss_conf.rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
1662 : : }
1663 : :
1664 : 0 : tmp_rss_conf.algorithm = rss_conf->algorithm;
1665 : :
1666 : 0 : tmp_rss_conf.rss_hf = rss_conf->rss_hf;
1667 : 0 : int res = hsh_set(ndev, hsh_idx, tmp_rss_conf);
1668 : :
1669 [ # # ]: 0 : if (res == 0) {
1670 : 0 : flow_filter_ops->hw_mod_hsh_rcp_flush(&ndev->be, hsh_idx, 1);
1671 [ # # ]: 0 : rte_memcpy(&ndev->rss_conf, &tmp_rss_conf, sizeof(struct nt_eth_rss_conf));
1672 : :
1673 : : } else {
1674 : 0 : NT_LOG(ERR, NTNIC, "ERROR: - RSS hash update failed with error %i", res);
1675 : : }
1676 : :
1677 : : return res;
1678 : : }
1679 : :
1680 : 0 : static int rss_hash_conf_get(struct rte_eth_dev *eth_dev, struct rte_eth_rss_conf *rss_conf)
1681 : : {
1682 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
1683 : 0 : struct flow_nic_dev *ndev = internals->flw_dev->ndev;
1684 : :
1685 : 0 : rss_conf->algorithm = (enum rte_eth_hash_function)ndev->rss_conf.algorithm;
1686 : :
1687 : 0 : rss_conf->rss_hf = ndev->rss_conf.rss_hf;
1688 : :
1689 : : /*
1690 : : * copy full stored key into rss_key and pad it with
1691 : : * zeros up to rss_key_len / MAX_RSS_KEY_LEN
1692 : : */
1693 [ # # ]: 0 : if (rss_conf->rss_key != NULL) {
1694 : 0 : int key_len = RTE_MIN(rss_conf->rss_key_len, MAX_RSS_KEY_LEN);
1695 [ # # ]: 0 : memset(rss_conf->rss_key, 0, rss_conf->rss_key_len);
1696 [ # # ]: 0 : rte_memcpy(rss_conf->rss_key, &ndev->rss_conf.rss_key, key_len);
1697 : 0 : rss_conf->rss_key_len = key_len;
1698 : : }
1699 : :
1700 : 0 : return 0;
1701 : : }
1702 : :
1703 : : static struct eth_dev_ops nthw_eth_dev_ops = {
1704 : : .dev_configure = eth_dev_configure,
1705 : : .dev_start = eth_dev_start,
1706 : : .dev_stop = eth_dev_stop,
1707 : : .dev_set_link_up = eth_dev_set_link_up,
1708 : : .dev_set_link_down = eth_dev_set_link_down,
1709 : : .dev_close = eth_dev_close,
1710 : : .link_update = eth_link_update,
1711 : : .stats_get = eth_stats_get,
1712 : : .stats_reset = eth_stats_reset,
1713 : : .dev_infos_get = eth_dev_infos_get,
1714 : : .fw_version_get = eth_fw_version_get,
1715 : : .rx_queue_setup = eth_rx_scg_queue_setup,
1716 : : .rx_queue_start = eth_rx_queue_start,
1717 : : .rx_queue_stop = eth_rx_queue_stop,
1718 : : .rx_queue_release = eth_rx_queue_release,
1719 : : .tx_queue_setup = eth_tx_scg_queue_setup,
1720 : : .tx_queue_start = eth_tx_queue_start,
1721 : : .tx_queue_stop = eth_tx_queue_stop,
1722 : : .tx_queue_release = eth_tx_queue_release,
1723 : : .mac_addr_add = eth_mac_addr_add,
1724 : : .mac_addr_set = eth_mac_addr_set,
1725 : : .set_mc_addr_list = eth_set_mc_addr_list,
1726 : : .mtr_ops_get = NULL,
1727 : : .flow_ops_get = dev_flow_ops_get,
1728 : : .xstats_get = eth_xstats_get,
1729 : : .xstats_get_names = eth_xstats_get_names,
1730 : : .xstats_reset = eth_xstats_reset,
1731 : : .xstats_get_by_id = eth_xstats_get_by_id,
1732 : : .xstats_get_names_by_id = eth_xstats_get_names_by_id,
1733 : : .mtu_set = NULL,
1734 : : .promiscuous_enable = promiscuous_enable,
1735 : : .rss_hash_update = eth_dev_rss_hash_update,
1736 : : .rss_hash_conf_get = rss_hash_conf_get,
1737 : : };
1738 : :
1739 : : /*
1740 : : * Port event thread
1741 : : */
1742 : 0 : THREAD_FUNC port_event_thread_fn(void *context)
1743 : : {
1744 : : struct pmd_internals *internals = context;
1745 : 0 : struct drv_s *p_drv = internals->p_drv;
1746 : : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1747 : : struct adapter_info_s *p_adapter_info = &p_nt_drv->adapter_info;
1748 : 0 : struct flow_nic_dev *ndev = p_adapter_info->nt4ga_filter.mp_flow_device;
1749 : :
1750 : : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1751 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[internals->port_id];
1752 : 0 : uint8_t port_no = internals->port;
1753 : :
1754 : : ntnic_flm_load_t flmdata;
1755 : : ntnic_port_load_t portdata;
1756 : :
1757 : : memset(&flmdata, 0, sizeof(flmdata));
1758 : : memset(&portdata, 0, sizeof(portdata));
1759 : :
1760 [ # # # # ]: 0 : while (ndev != NULL && ndev->eth_base == NULL)
1761 : 0 : nt_os_wait_usec(1 * 1000 * 1000);
1762 : :
1763 [ # # ]: 0 : while (!p_drv->ntdrv.b_shutdown) {
1764 : : /*
1765 : : * FLM load measurement
1766 : : * Do only send event, if there has been a change
1767 : : */
1768 [ # # # # ]: 0 : if (p_nt4ga_stat->flm_stat_ver > 22 && p_nt4ga_stat->mp_stat_structs_flm) {
1769 [ # # ]: 0 : if (flmdata.lookup != p_nt4ga_stat->mp_stat_structs_flm->load_lps ||
1770 [ # # ]: 0 : flmdata.access != p_nt4ga_stat->mp_stat_structs_flm->load_aps) {
1771 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
1772 : 0 : flmdata.lookup = p_nt4ga_stat->mp_stat_structs_flm->load_lps;
1773 : 0 : flmdata.access = p_nt4ga_stat->mp_stat_structs_flm->load_aps;
1774 : 0 : flmdata.lookup_maximum =
1775 : 0 : p_nt4ga_stat->mp_stat_structs_flm->max_lps;
1776 : 0 : flmdata.access_maximum =
1777 : 0 : p_nt4ga_stat->mp_stat_structs_flm->max_aps;
1778 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
1779 : :
1780 [ # # # # ]: 0 : if (eth_dev && eth_dev->data && eth_dev->data->dev_private) {
1781 : 0 : rte_eth_dev_callback_process(eth_dev,
1782 : : (enum rte_eth_event_type)RTE_NTNIC_FLM_LOAD_EVENT,
1783 : : &flmdata);
1784 : : }
1785 : : }
1786 : : }
1787 : :
1788 : : /*
1789 : : * Port load measurement
1790 : : * Do only send event, if there has been a change.
1791 : : */
1792 [ # # ]: 0 : if (p_nt4ga_stat->mp_port_load) {
1793 [ # # ]: 0 : if (portdata.rx_bps != p_nt4ga_stat->mp_port_load[port_no].rx_bps ||
1794 [ # # ]: 0 : portdata.tx_bps != p_nt4ga_stat->mp_port_load[port_no].tx_bps) {
1795 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
1796 : 0 : portdata.rx_bps = p_nt4ga_stat->mp_port_load[port_no].rx_bps;
1797 : 0 : portdata.tx_bps = p_nt4ga_stat->mp_port_load[port_no].tx_bps;
1798 : 0 : portdata.rx_pps = p_nt4ga_stat->mp_port_load[port_no].rx_pps;
1799 : 0 : portdata.tx_pps = p_nt4ga_stat->mp_port_load[port_no].tx_pps;
1800 : 0 : portdata.rx_pps_maximum =
1801 : 0 : p_nt4ga_stat->mp_port_load[port_no].rx_pps_max;
1802 : 0 : portdata.tx_pps_maximum =
1803 : 0 : p_nt4ga_stat->mp_port_load[port_no].tx_pps_max;
1804 : 0 : portdata.rx_bps_maximum =
1805 : 0 : p_nt4ga_stat->mp_port_load[port_no].rx_bps_max;
1806 : 0 : portdata.tx_bps_maximum =
1807 : 0 : p_nt4ga_stat->mp_port_load[port_no].tx_bps_max;
1808 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
1809 : :
1810 [ # # # # ]: 0 : if (eth_dev && eth_dev->data && eth_dev->data->dev_private) {
1811 : 0 : rte_eth_dev_callback_process(eth_dev,
1812 : : (enum rte_eth_event_type)RTE_NTNIC_PORT_LOAD_EVENT,
1813 : : &portdata);
1814 : : }
1815 : : }
1816 : : }
1817 : :
1818 : : /* Process events */
1819 : : {
1820 : : int count = 0;
1821 : : bool do_wait = true;
1822 : :
1823 [ # # ]: 0 : while (count < 5000) {
1824 : : /* Local FLM statistic events */
1825 : : struct flm_info_event_s data;
1826 : :
1827 [ # # ]: 0 : if (nthw_flm_inf_queue_get(port_no, FLM_INFO_LOCAL, &data) == 0) {
1828 [ # # ]: 0 : if (eth_dev && eth_dev->data &&
1829 [ # # ]: 0 : eth_dev->data->dev_private) {
1830 : : struct ntnic_flm_statistic_s event_data;
1831 : 0 : event_data.bytes = data.bytes;
1832 : 0 : event_data.packets = data.packets;
1833 : 0 : event_data.cause = data.cause;
1834 : 0 : event_data.id = data.id;
1835 : 0 : event_data.timestamp = data.timestamp;
1836 : 0 : rte_eth_dev_callback_process(eth_dev,
1837 : : (enum rte_eth_event_type)
1838 : : RTE_NTNIC_FLM_STATS_EVENT,
1839 : : &event_data);
1840 : : do_wait = false;
1841 : : }
1842 : : }
1843 : :
1844 : : /* AGED event */
1845 : : /* Note: RTE_FLOW_PORT_FLAG_STRICT_QUEUE flag is not supported so
1846 : : * event is always generated
1847 : : */
1848 : 0 : int aged_event_count = flm_age_event_get(port_no);
1849 : :
1850 [ # # # # ]: 0 : if (aged_event_count > 0 && eth_dev && eth_dev->data &&
1851 [ # # ]: 0 : eth_dev->data->dev_private) {
1852 : 0 : rte_eth_dev_callback_process(eth_dev,
1853 : : RTE_ETH_EVENT_FLOW_AGED,
1854 : : NULL);
1855 : 0 : flm_age_event_clear(port_no);
1856 : : do_wait = false;
1857 : : }
1858 : :
1859 [ # # ]: 0 : if (do_wait)
1860 : 0 : nt_os_wait_usec(10);
1861 : :
1862 : 0 : count++;
1863 : : do_wait = true;
1864 : : }
1865 : : }
1866 : : }
1867 : :
1868 : 0 : return THREAD_RETURN;
1869 : : }
1870 : :
1871 : : /*
1872 : : * Adapter flm stat thread
1873 : : */
1874 : 0 : THREAD_FUNC adapter_flm_update_thread_fn(void *context)
1875 : : {
1876 : 0 : const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
1877 : :
1878 [ # # ]: 0 : if (profile_inline_ops == NULL) {
1879 : 0 : NT_LOG(ERR, NTNIC, "%s: profile_inline module uninitialized", __func__);
1880 : 0 : return THREAD_RETURN;
1881 : : }
1882 : :
1883 : : struct drv_s *p_drv = context;
1884 : :
1885 : : struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv;
1886 : : struct adapter_info_s *p_adapter_info = &p_nt_drv->adapter_info;
1887 : : struct nt4ga_filter_s *p_nt4ga_filter = &p_adapter_info->nt4ga_filter;
1888 : 0 : struct flow_nic_dev *p_flow_nic_dev = p_nt4ga_filter->mp_flow_device;
1889 : :
1890 : 0 : NT_LOG(DBG, NTNIC, "%s: %s: waiting for port configuration",
1891 : : p_adapter_info->mp_adapter_id_str, __func__);
1892 : :
1893 [ # # ]: 0 : while (p_flow_nic_dev->eth_base == NULL)
1894 : 0 : nt_os_wait_usec(1 * 1000 * 1000);
1895 : :
1896 : : struct flow_eth_dev *dev = p_flow_nic_dev->eth_base;
1897 : :
1898 : 0 : NT_LOG(DBG, NTNIC, "%s: %s: begin", p_adapter_info->mp_adapter_id_str, __func__);
1899 : :
1900 [ # # ]: 0 : while (!p_drv->ntdrv.b_shutdown)
1901 [ # # ]: 0 : if (profile_inline_ops->flm_update(dev) == 0)
1902 : 0 : nt_os_wait_usec(10);
1903 : :
1904 : 0 : NT_LOG(DBG, NTNIC, "%s: %s: end", p_adapter_info->mp_adapter_id_str, __func__);
1905 : 0 : return THREAD_RETURN;
1906 : : }
1907 : :
1908 : : /*
1909 : : * Adapter stat thread
1910 : : */
1911 : 0 : THREAD_FUNC adapter_stat_thread_fn(void *context)
1912 : : {
1913 : 0 : const struct nt4ga_stat_ops *nt4ga_stat_ops = get_nt4ga_stat_ops();
1914 : :
1915 [ # # ]: 0 : if (nt4ga_stat_ops == NULL) {
1916 : 0 : NT_LOG_DBGX(ERR, NTNIC, "Statistics module uninitialized");
1917 : 0 : return THREAD_RETURN;
1918 : : }
1919 : :
1920 : : struct drv_s *p_drv = context;
1921 : :
1922 : : ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv;
1923 : 0 : nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat;
1924 : 0 : nthw_stat_t *p_nthw_stat = p_nt4ga_stat->mp_nthw_stat;
1925 : 0 : const char *const p_adapter_id_str = p_nt_drv->adapter_info.mp_adapter_id_str;
1926 : : (void)p_adapter_id_str;
1927 : :
1928 [ # # ]: 0 : if (!p_nthw_stat)
1929 : : return THREAD_RETURN;
1930 : :
1931 : 0 : NT_LOG_DBGX(DBG, NTNIC, "%s: begin", p_adapter_id_str);
1932 : :
1933 : : RTE_ASSERT(p_nthw_stat);
1934 : :
1935 [ # # ]: 0 : while (!p_drv->ntdrv.b_shutdown) {
1936 : 0 : nt_os_wait_usec(10 * 1000);
1937 : :
1938 : 0 : nthw_stat_trigger(p_nthw_stat);
1939 : :
1940 : : uint32_t loop = 0;
1941 : :
1942 [ # # ]: 0 : while ((!p_drv->ntdrv.b_shutdown) &&
1943 [ # # ]: 0 : (*p_nthw_stat->mp_timestamp == (uint64_t)-1)) {
1944 : 0 : nt_os_wait_usec(1 * 100);
1945 : :
1946 [ # # ]: 0 : if (rte_log_get_level(nt_log_ntnic) == RTE_LOG_DEBUG &&
1947 [ # # ]: 0 : (++loop & 0x3fff) == 0) {
1948 [ # # ]: 0 : if (p_nt4ga_stat->mp_nthw_rpf) {
1949 : 0 : NT_LOG(ERR, NTNIC, "Statistics DMA frozen");
1950 : :
1951 [ # # ]: 0 : } else if (p_nt4ga_stat->mp_nthw_rmc) {
1952 : : uint32_t sf_ram_of =
1953 : 0 : nthw_rmc_get_status_sf_ram_of(p_nt4ga_stat
1954 : : ->mp_nthw_rmc);
1955 : : uint32_t descr_fifo_of =
1956 : 0 : nthw_rmc_get_status_descr_fifo_of(p_nt4ga_stat
1957 : : ->mp_nthw_rmc);
1958 : :
1959 : : uint32_t dbg_merge =
1960 : 0 : nthw_rmc_get_dbg_merge(p_nt4ga_stat->mp_nthw_rmc);
1961 : : uint32_t mac_if_err =
1962 : 0 : nthw_rmc_get_mac_if_err(p_nt4ga_stat->mp_nthw_rmc);
1963 : :
1964 : 0 : NT_LOG(ERR, NTNIC, "Statistics DMA frozen");
1965 : 0 : NT_LOG(ERR, NTNIC, "SF RAM Overflow : %08x",
1966 : : sf_ram_of);
1967 : 0 : NT_LOG(ERR, NTNIC, "Descr Fifo Overflow : %08x",
1968 : : descr_fifo_of);
1969 : 0 : NT_LOG(ERR, NTNIC, "DBG Merge : %08x",
1970 : : dbg_merge);
1971 : 0 : NT_LOG(ERR, NTNIC, "MAC If Errors : %08x",
1972 : : mac_if_err);
1973 : : }
1974 : : }
1975 : : }
1976 : :
1977 : : /* Check then collect */
1978 : : {
1979 : 0 : rte_spinlock_lock(&p_nt_drv->stat_lck);
1980 : 0 : nt4ga_stat_ops->nt4ga_stat_collect(&p_nt_drv->adapter_info, p_nt4ga_stat);
1981 : : rte_spinlock_unlock(&p_nt_drv->stat_lck);
1982 : : }
1983 : : }
1984 : :
1985 : 0 : NT_LOG_DBGX(DBG, NTNIC, "%s: end", p_adapter_id_str);
1986 : 0 : return THREAD_RETURN;
1987 : : }
1988 : :
1989 : : static int
1990 : 0 : nthw_pci_dev_init(struct rte_pci_device *pci_dev)
1991 : : {
1992 : 0 : const struct flow_filter_ops *flow_filter_ops = get_flow_filter_ops();
1993 : :
1994 [ # # ]: 0 : if (flow_filter_ops == NULL) {
1995 : 0 : NT_LOG_DBGX(ERR, NTNIC, "flow_filter module uninitialized");
1996 : : /* Return statement is not necessary here to allow traffic processing by SW */
1997 : : }
1998 : :
1999 : 0 : const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
2000 : :
2001 [ # # ]: 0 : if (profile_inline_ops == NULL) {
2002 : 0 : NT_LOG_DBGX(ERR, NTNIC, "profile_inline module uninitialized");
2003 : : /* Return statement is not necessary here to allow traffic processing by SW */
2004 : : }
2005 : :
2006 : 0 : nt_vfio_init();
2007 : 0 : const struct port_ops *port_ops = get_port_ops();
2008 : :
2009 [ # # ]: 0 : if (port_ops == NULL) {
2010 : 0 : NT_LOG(ERR, NTNIC, "Link management module uninitialized");
2011 : 0 : return -1;
2012 : : }
2013 : :
2014 : 0 : const struct adapter_ops *adapter_ops = get_adapter_ops();
2015 : :
2016 [ # # ]: 0 : if (adapter_ops == NULL) {
2017 : 0 : NT_LOG(ERR, NTNIC, "Adapter module uninitialized");
2018 : 0 : return -1;
2019 : : }
2020 : :
2021 : : int res;
2022 : : struct drv_s *p_drv;
2023 : : ntdrv_4ga_t *p_nt_drv;
2024 : : hw_info_t *p_hw_info;
2025 : : fpga_info_t *fpga_info;
2026 : : uint32_t n_port_mask = -1; /* All ports enabled by default */
2027 : 0 : uint32_t nb_rx_queues = 1;
2028 : 0 : uint32_t nb_tx_queues = 1;
2029 : : uint32_t exception_path = 0;
2030 : : struct flow_queue_id_s queue_ids[MAX_QUEUES];
2031 : : int n_phy_ports;
2032 : : enum flow_eth_dev_profile profile = FLOW_ETH_DEV_PROFILE_INLINE;
2033 : :
2034 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Dev %s PF #%i Init : %02x:%02x:%i", pci_dev->name,
2035 : : pci_dev->addr.function, pci_dev->addr.bus, pci_dev->addr.devid,
2036 : : pci_dev->addr.function);
2037 : :
2038 : : /*
2039 : : * Process options/arguments
2040 : : */
2041 [ # # # # ]: 0 : if (pci_dev->device.devargs && pci_dev->device.devargs->args) {
2042 : : int kvargs_count;
2043 : : struct rte_kvargs *kvlist =
2044 : 0 : rte_kvargs_parse(pci_dev->device.devargs->args, valid_arguments);
2045 : :
2046 [ # # ]: 0 : if (kvlist == NULL)
2047 : : return -1;
2048 : :
2049 : : /*
2050 : : * Argument: help
2051 : : * NOTE: this argument/option check should be the first as it will stop
2052 : : * execution after producing its output
2053 : : */
2054 : : {
2055 [ # # ]: 0 : if (rte_kvargs_get(kvlist, ETH_DEV_NTNIC_HELP_ARG)) {
2056 : : size_t i;
2057 : :
2058 : : for (i = 0; i < RTE_DIM(valid_arguments); i++)
2059 : : if (valid_arguments[i] == NULL)
2060 : : break;
2061 : :
2062 : 0 : exit(0);
2063 : : }
2064 : : }
2065 : :
2066 : : /*
2067 : : * rxq option/argument
2068 : : * The number of rxq (hostbuffers) allocated in memory.
2069 : : * Default is 32 RX Hostbuffers
2070 : : */
2071 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_DEV_NTHW_RXQUEUES_ARG);
2072 : :
2073 [ # # ]: 0 : if (kvargs_count != 0) {
2074 : : RTE_ASSERT(kvargs_count == 1);
2075 : 0 : res = rte_kvargs_process(kvlist, ETH_DEV_NTHW_RXQUEUES_ARG,
2076 : : &nthw_string_to_u32,
2077 : : &nb_rx_queues);
2078 : :
2079 [ # # ]: 0 : if (res < 0) {
2080 : 0 : NT_LOG_DBGX(ERR, NTNIC,
2081 : : "problem with command line arguments: res=%d",
2082 : : res);
2083 : 0 : free(kvlist);
2084 : 0 : return -1;
2085 : : }
2086 : :
2087 : 0 : NT_LOG_DBGX(DBG, NTNIC, "devargs: %s=%u",
2088 : : ETH_DEV_NTHW_RXQUEUES_ARG, nb_rx_queues);
2089 : : }
2090 : :
2091 : : /*
2092 : : * txq option/argument
2093 : : * The number of txq (hostbuffers) allocated in memory.
2094 : : * Default is 32 TX Hostbuffers
2095 : : */
2096 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_DEV_NTHW_TXQUEUES_ARG);
2097 : :
2098 [ # # ]: 0 : if (kvargs_count != 0) {
2099 : : RTE_ASSERT(kvargs_count == 1);
2100 : 0 : res = rte_kvargs_process(kvlist, ETH_DEV_NTHW_TXQUEUES_ARG,
2101 : : &nthw_string_to_u32,
2102 : : &nb_tx_queues);
2103 : :
2104 [ # # ]: 0 : if (res < 0) {
2105 : 0 : NT_LOG_DBGX(ERR, NTNIC,
2106 : : "problem with command line arguments: res=%d",
2107 : : res);
2108 : 0 : free(kvlist);
2109 : 0 : return -1;
2110 : : }
2111 : :
2112 : 0 : NT_LOG_DBGX(DBG, NTNIC, "devargs: %s=%u",
2113 : : ETH_DEV_NTHW_TXQUEUES_ARG, nb_tx_queues);
2114 : : }
2115 : : }
2116 : :
2117 : :
2118 : : /* alloc */
2119 : 0 : p_drv = rte_zmalloc_socket(pci_dev->name, sizeof(struct drv_s), RTE_CACHE_LINE_SIZE,
2120 : : pci_dev->device.numa_node);
2121 : :
2122 [ # # ]: 0 : if (!p_drv) {
2123 [ # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: error %d",
2124 : : (pci_dev->name[0] ? pci_dev->name : "NA"), -1);
2125 : 0 : return -1;
2126 : : }
2127 : :
2128 : : /* Setup VFIO context */
2129 : 0 : int vfio = nt_vfio_setup(pci_dev);
2130 : :
2131 [ # # ]: 0 : if (vfio < 0) {
2132 [ # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: vfio_setup error %d",
2133 : : (pci_dev->name[0] ? pci_dev->name : "NA"), -1);
2134 : 0 : rte_free(p_drv);
2135 : 0 : return -1;
2136 : : }
2137 : :
2138 : : /* context */
2139 : : p_nt_drv = &p_drv->ntdrv;
2140 : : p_hw_info = &p_nt_drv->adapter_info.hw_info;
2141 : 0 : fpga_info = &p_nt_drv->adapter_info.fpga_info;
2142 : :
2143 : 0 : p_drv->p_dev = pci_dev;
2144 : :
2145 : : /* Set context for NtDrv */
2146 : 0 : p_nt_drv->pciident = BDF_TO_PCIIDENT(pci_dev->addr.domain, pci_dev->addr.bus,
2147 : : pci_dev->addr.devid, pci_dev->addr.function);
2148 : 0 : p_nt_drv->adapter_info.n_rx_host_buffers = nb_rx_queues;
2149 : 0 : p_nt_drv->adapter_info.n_tx_host_buffers = nb_tx_queues;
2150 : :
2151 : 0 : fpga_info->bar0_addr = (void *)pci_dev->mem_resource[0].addr;
2152 : 0 : fpga_info->bar0_size = pci_dev->mem_resource[0].len;
2153 : 0 : fpga_info->numa_node = pci_dev->device.numa_node;
2154 : 0 : fpga_info->pciident = p_nt_drv->pciident;
2155 : 0 : fpga_info->adapter_no = p_drv->adapter_no;
2156 : :
2157 : 0 : p_nt_drv->adapter_info.hw_info.pci_class_id = pci_dev->id.class_id;
2158 : 0 : p_nt_drv->adapter_info.hw_info.pci_vendor_id = pci_dev->id.vendor_id;
2159 : 0 : p_nt_drv->adapter_info.hw_info.pci_device_id = pci_dev->id.device_id;
2160 : 0 : p_nt_drv->adapter_info.hw_info.pci_sub_vendor_id = pci_dev->id.subsystem_vendor_id;
2161 : 0 : p_nt_drv->adapter_info.hw_info.pci_sub_device_id = pci_dev->id.subsystem_device_id;
2162 : :
2163 : 0 : NT_LOG(DBG, NTNIC, "%s: " PCIIDENT_PRINT_STR " %04X:%04X: %04X:%04X:",
2164 : : p_nt_drv->adapter_info.mp_adapter_id_str, PCIIDENT_TO_DOMAIN(p_nt_drv->pciident),
2165 : : PCIIDENT_TO_BUSNR(p_nt_drv->pciident), PCIIDENT_TO_DEVNR(p_nt_drv->pciident),
2166 : : PCIIDENT_TO_FUNCNR(p_nt_drv->pciident),
2167 : : p_nt_drv->adapter_info.hw_info.pci_vendor_id,
2168 : : p_nt_drv->adapter_info.hw_info.pci_device_id,
2169 : : p_nt_drv->adapter_info.hw_info.pci_sub_vendor_id,
2170 : : p_nt_drv->adapter_info.hw_info.pci_sub_device_id);
2171 : :
2172 : 0 : p_nt_drv->b_shutdown = false;
2173 : 0 : p_nt_drv->adapter_info.pb_shutdown = &p_nt_drv->b_shutdown;
2174 : :
2175 : : /* store context */
2176 : 0 : store_pdrv(p_drv);
2177 : :
2178 : : /* initialize nt4ga nthw fpga module instance in drv */
2179 : 0 : int err = adapter_ops->init(&p_nt_drv->adapter_info);
2180 : :
2181 [ # # ]: 0 : if (err != 0) {
2182 : 0 : NT_LOG(ERR, NTNIC, "%s: Cannot initialize the adapter instance",
2183 : : p_nt_drv->adapter_info.mp_adapter_id_str);
2184 : 0 : return -1;
2185 : : }
2186 : :
2187 : 0 : const struct meter_ops_s *meter_ops = get_meter_ops();
2188 : :
2189 [ # # ]: 0 : if (meter_ops != NULL)
2190 : 0 : nthw_eth_dev_ops.mtr_ops_get = meter_ops->eth_mtr_ops_get;
2191 : :
2192 : : else
2193 : 0 : NT_LOG(DBG, NTNIC, "Meter module is not initialized");
2194 : :
2195 : : /* Initialize the queue system */
2196 : : if (err == 0) {
2197 : 0 : sg_ops = get_sg_ops();
2198 : :
2199 [ # # ]: 0 : if (sg_ops != NULL) {
2200 : 0 : err = sg_ops->nthw_virt_queue_init(fpga_info);
2201 : :
2202 [ # # ]: 0 : if (err != 0) {
2203 : 0 : NT_LOG(ERR, NTNIC,
2204 : : "%s: Cannot initialize scatter-gather queues",
2205 : : p_nt_drv->adapter_info.mp_adapter_id_str);
2206 : :
2207 : : } else {
2208 : 0 : NT_LOG(DBG, NTNIC, "%s: Initialized scatter-gather queues",
2209 : : p_nt_drv->adapter_info.mp_adapter_id_str);
2210 : : }
2211 : :
2212 : : } else {
2213 : 0 : NT_LOG_DBGX(DBG, NTNIC, "SG module is not initialized");
2214 : : }
2215 : : }
2216 : :
2217 : : /* Start ctrl, monitor, stat thread only for primary process. */
2218 [ # # ]: 0 : if (err == 0) {
2219 : : /* mp_adapter_id_str is initialized after nt4ga_adapter_init(p_nt_drv) */
2220 : 0 : const char *const p_adapter_id_str = p_nt_drv->adapter_info.mp_adapter_id_str;
2221 : : (void)p_adapter_id_str;
2222 [ # # ]: 0 : NT_LOG(DBG, NTNIC,
2223 : : "%s: %s: AdapterPCI=" PCIIDENT_PRINT_STR " Hw=0x%02X_rev%d PhyPorts=%d",
2224 : : (pci_dev->name[0] ? pci_dev->name : "NA"), p_adapter_id_str,
2225 : : PCIIDENT_TO_DOMAIN(p_nt_drv->adapter_info.fpga_info.pciident),
2226 : : PCIIDENT_TO_BUSNR(p_nt_drv->adapter_info.fpga_info.pciident),
2227 : : PCIIDENT_TO_DEVNR(p_nt_drv->adapter_info.fpga_info.pciident),
2228 : : PCIIDENT_TO_FUNCNR(p_nt_drv->adapter_info.fpga_info.pciident),
2229 : : p_hw_info->hw_platform_id, fpga_info->nthw_hw_info.hw_id,
2230 : : fpga_info->n_phy_ports);
2231 : :
2232 : : } else {
2233 [ # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: error=%d",
2234 : : (pci_dev->name[0] ? pci_dev->name : "NA"), err);
2235 : 0 : return -1;
2236 : : }
2237 : :
2238 [ # # # # ]: 0 : if (profile_inline_ops != NULL && fpga_info->profile == FPGA_INFO_PROFILE_INLINE) {
2239 : 0 : profile_inline_ops->flm_setup_queues();
2240 : 0 : res = THREAD_CTRL_CREATE(&p_nt_drv->flm_thread, "ntnic-nt_flm_update_thr",
2241 : : adapter_flm_update_thread_fn, (void *)p_drv);
2242 : :
2243 [ # # ]: 0 : if (res) {
2244 [ # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: error=%d",
2245 : : (pci_dev->name[0] ? pci_dev->name : "NA"), res);
2246 : 0 : return -1;
2247 : : }
2248 : : }
2249 : :
2250 : : rte_spinlock_init(&p_nt_drv->stat_lck);
2251 : 0 : res = THREAD_CTRL_CREATE(&p_nt_drv->stat_thread, "nt4ga_stat_thr", adapter_stat_thread_fn,
2252 : : (void *)p_drv);
2253 : :
2254 [ # # ]: 0 : if (res) {
2255 [ # # ]: 0 : NT_LOG(ERR, NTNIC, "%s: error=%d",
2256 : : (pci_dev->name[0] ? pci_dev->name : "NA"), res);
2257 : 0 : return -1;
2258 : : }
2259 : :
2260 : 0 : n_phy_ports = fpga_info->n_phy_ports;
2261 : :
2262 [ # # ]: 0 : for (int n_intf_no = 0; n_intf_no < n_phy_ports; n_intf_no++) {
2263 [ # # ]: 0 : const char *const p_port_id_str = p_nt_drv->adapter_info.mp_port_id_str[n_intf_no];
2264 : : (void)p_port_id_str;
2265 : : struct pmd_internals *internals = NULL;
2266 : : struct rte_eth_dev *eth_dev = NULL;
2267 : : char name[32];
2268 : : int i;
2269 : :
2270 : : if ((1 << n_intf_no) & ~n_port_mask) {
2271 : : NT_LOG_DBGX(DBG, NTNIC,
2272 : : "%s: interface #%d: skipping due to portmask 0x%02X",
2273 : : p_port_id_str, n_intf_no, n_port_mask);
2274 : : continue;
2275 : : }
2276 : :
2277 : : snprintf(name, sizeof(name), "ntnic%d", n_intf_no);
2278 [ # # ]: 0 : NT_LOG_DBGX(DBG, NTNIC, "%s: interface #%d: %s: '%s'", p_port_id_str,
2279 : : n_intf_no, (pci_dev->name[0] ? pci_dev->name : "NA"), name);
2280 : :
2281 : 0 : internals = rte_zmalloc_socket(name, sizeof(struct pmd_internals),
2282 : : RTE_CACHE_LINE_SIZE, pci_dev->device.numa_node);
2283 : :
2284 [ # # ]: 0 : if (!internals) {
2285 [ # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: %s: error=%d",
2286 : : (pci_dev->name[0] ? pci_dev->name : "NA"), name, -1);
2287 : 0 : return -1;
2288 : : }
2289 : :
2290 : 0 : internals->pci_dev = pci_dev;
2291 : 0 : internals->n_intf_no = n_intf_no;
2292 : 0 : internals->type = PORT_TYPE_PHYSICAL;
2293 : 0 : internals->port = n_intf_no;
2294 : 0 : internals->nb_rx_queues = nb_rx_queues;
2295 : 0 : internals->nb_tx_queues = nb_tx_queues;
2296 : :
2297 : : /* Not used queue index as dest port in bypass - use 0x80 + port nr */
2298 [ # # ]: 0 : for (i = 0; i < MAX_QUEUES; i++)
2299 : 0 : internals->vpq[i].hw_id = -1;
2300 : :
2301 : :
2302 : : /* Setup queue_ids */
2303 [ # # ]: 0 : if (nb_rx_queues > 1) {
2304 : 0 : NT_LOG(DBG, NTNIC,
2305 : : "(%i) NTNIC configured with Rx multi queues. %i queues",
2306 : : internals->n_intf_no, nb_rx_queues);
2307 : : }
2308 : :
2309 [ # # ]: 0 : if (nb_tx_queues > 1) {
2310 : 0 : NT_LOG(DBG, NTNIC,
2311 : : "(%i) NTNIC configured with Tx multi queues. %i queues",
2312 : : internals->n_intf_no, nb_tx_queues);
2313 : : }
2314 : :
2315 : 0 : int max_num_queues = (nb_rx_queues > nb_tx_queues) ? nb_rx_queues : nb_tx_queues;
2316 : 0 : int start_queue = allocate_queue(max_num_queues);
2317 : :
2318 [ # # ]: 0 : if (start_queue < 0)
2319 : : return -1;
2320 : :
2321 [ # # ]: 0 : for (i = 0; i < (int)max_num_queues; i++) {
2322 : 0 : queue_ids[i].id = i;
2323 : 0 : queue_ids[i].hw_id = start_queue + i;
2324 : :
2325 : 0 : internals->rxq_scg[i].queue = queue_ids[i];
2326 : : /* use same index in Rx and Tx rings */
2327 : 0 : internals->txq_scg[i].queue = queue_ids[i];
2328 : 0 : internals->rxq_scg[i].enabled = 0;
2329 : 0 : internals->txq_scg[i].type = internals->type;
2330 : 0 : internals->rxq_scg[i].type = internals->type;
2331 : 0 : internals->rxq_scg[i].port = internals->port;
2332 : : }
2333 : :
2334 : : /* no tx queues - tx data goes out on phy */
2335 : 0 : internals->vpq_nb_vq = 0;
2336 : :
2337 [ # # ]: 0 : for (i = 0; i < (int)nb_tx_queues; i++) {
2338 : 0 : internals->txq_scg[i].port = internals->port;
2339 : 0 : internals->txq_scg[i].enabled = 0;
2340 : : }
2341 : :
2342 : : /* Set MAC address (but only if the MAC address is permitted) */
2343 [ # # ]: 0 : if (n_intf_no < fpga_info->nthw_hw_info.vpd_info.mn_mac_addr_count) {
2344 : 0 : const uint64_t mac =
2345 : 0 : fpga_info->nthw_hw_info.vpd_info.mn_mac_addr_value + n_intf_no;
2346 : 0 : internals->eth_addrs[0].addr_bytes[0] = (mac >> 40) & 0xFFu;
2347 : 0 : internals->eth_addrs[0].addr_bytes[1] = (mac >> 32) & 0xFFu;
2348 : 0 : internals->eth_addrs[0].addr_bytes[2] = (mac >> 24) & 0xFFu;
2349 : 0 : internals->eth_addrs[0].addr_bytes[3] = (mac >> 16) & 0xFFu;
2350 : 0 : internals->eth_addrs[0].addr_bytes[4] = (mac >> 8) & 0xFFu;
2351 : 0 : internals->eth_addrs[0].addr_bytes[5] = (mac >> 0) & 0xFFu;
2352 : : }
2353 : :
2354 : 0 : eth_dev = rte_eth_dev_allocate(name);
2355 : :
2356 [ # # ]: 0 : if (!eth_dev) {
2357 [ # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: %s: error=%d",
2358 : : (pci_dev->name[0] ? pci_dev->name : "NA"), name, -1);
2359 : 0 : return -1;
2360 : : }
2361 : :
2362 [ # # ]: 0 : if (flow_filter_ops != NULL) {
2363 : 0 : internals->flw_dev = flow_filter_ops->flow_get_eth_dev(0, n_intf_no,
2364 : 0 : eth_dev->data->port_id, nb_rx_queues, queue_ids,
2365 : : &internals->txq_scg[0].rss_target_id, profile, exception_path);
2366 : :
2367 [ # # ]: 0 : if (!internals->flw_dev) {
2368 : 0 : NT_LOG(ERR, NTNIC,
2369 : : "Error creating port. Resource exhaustion in HW");
2370 : 0 : return -1;
2371 : : }
2372 : : }
2373 : :
2374 : : /* connect structs */
2375 : 0 : internals->p_drv = p_drv;
2376 : 0 : eth_dev->data->dev_private = internals;
2377 : 0 : eth_dev->data->mac_addrs = rte_malloc(NULL,
2378 : : NUM_MAC_ADDRS_PER_PORT * sizeof(struct rte_ether_addr), 0);
2379 : 0 : rte_memcpy(ð_dev->data->mac_addrs[0],
2380 [ # # ]: 0 : &internals->eth_addrs[0], RTE_ETHER_ADDR_LEN);
2381 : :
2382 : 0 : NT_LOG_DBGX(DBG, NTNIC, "Setting up RX functions for SCG");
2383 : 0 : eth_dev->rx_pkt_burst = eth_dev_rx_scg;
2384 : 0 : eth_dev->tx_pkt_burst = eth_dev_tx_scg;
2385 : 0 : eth_dev->tx_pkt_prepare = NULL;
2386 : :
2387 : : struct rte_eth_link pmd_link;
2388 : : pmd_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
2389 : : pmd_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2390 : : pmd_link.link_status = RTE_ETH_LINK_DOWN;
2391 : : pmd_link.link_autoneg = RTE_ETH_LINK_AUTONEG;
2392 : :
2393 : 0 : eth_dev->device = &pci_dev->device;
2394 : 0 : eth_dev->data->dev_link = pmd_link;
2395 : 0 : eth_dev->dev_ops = &nthw_eth_dev_ops;
2396 : :
2397 : : eth_dev_pci_specific_init(eth_dev, pci_dev);
2398 : 0 : rte_eth_dev_probing_finish(eth_dev);
2399 : :
2400 : : /* increase initialized ethernet devices - PF */
2401 : 0 : p_drv->n_eth_dev_init_count++;
2402 : :
2403 [ # # ]: 0 : if (get_flow_filter_ops() != NULL) {
2404 [ # # ]: 0 : if (fpga_info->profile == FPGA_INFO_PROFILE_INLINE &&
2405 [ # # ]: 0 : internals->flw_dev->ndev->be.tpe.ver >= 2) {
2406 : : RTE_ASSERT(nthw_eth_dev_ops.mtu_set == dev_set_mtu_inline ||
2407 : : nthw_eth_dev_ops.mtu_set == NULL);
2408 : 0 : nthw_eth_dev_ops.mtu_set = dev_set_mtu_inline;
2409 : 0 : dev_set_mtu_inline(eth_dev, MTUINITVAL);
2410 : 0 : NT_LOG_DBGX(DBG, NTNIC, "INLINE MTU supported, tpe version %d",
2411 : : internals->flw_dev->ndev->be.tpe.ver);
2412 : :
2413 : : } else {
2414 : 0 : NT_LOG(DBG, NTNIC, "INLINE MTU not supported");
2415 : : }
2416 : : }
2417 : :
2418 : : /* Port event thread */
2419 [ # # ]: 0 : if (fpga_info->profile == FPGA_INFO_PROFILE_INLINE) {
2420 : 0 : res = THREAD_CTRL_CREATE(&p_nt_drv->port_event_thread, "nt_port_event_thr",
2421 : : port_event_thread_fn, (void *)internals);
2422 : :
2423 [ # # ]: 0 : if (res) {
2424 [ # # ]: 0 : NT_LOG(ERR, NTNIC, "%s: error=%d",
2425 : : (pci_dev->name[0] ? pci_dev->name : "NA"), res);
2426 : 0 : return -1;
2427 : : }
2428 : : }
2429 : : }
2430 : :
2431 : : return 0;
2432 : : }
2433 : :
2434 : : static int
2435 : 0 : nthw_pci_dev_deinit(struct rte_eth_dev *eth_dev __rte_unused)
2436 : : {
2437 : 0 : NT_LOG_DBGX(DBG, NTNIC, "PCI device deinitialization");
2438 : :
2439 : : int i;
2440 : : char name[32];
2441 : :
2442 : 0 : struct pmd_internals *internals = eth_dev->data->dev_private;
2443 : 0 : ntdrv_4ga_t *p_ntdrv = &internals->p_drv->ntdrv;
2444 : : fpga_info_t *fpga_info = &p_ntdrv->adapter_info.fpga_info;
2445 : 0 : const int n_phy_ports = fpga_info->n_phy_ports;
2446 : :
2447 : : /* let running threads end Rx and Tx activity */
2448 [ # # ]: 0 : if (sg_ops != NULL) {
2449 : 0 : nt_os_wait_usec(1 * 1000 * 1000);
2450 : :
2451 [ # # ]: 0 : while (internals) {
2452 [ # # ]: 0 : for (i = internals->nb_tx_queues - 1; i >= 0; i--) {
2453 : 0 : sg_ops->nthw_release_mngd_tx_virt_queue(internals->txq_scg[i].vq);
2454 : : release_hw_virtio_queues(&internals->txq_scg[i].hwq);
2455 : : }
2456 : :
2457 [ # # ]: 0 : for (i = internals->nb_rx_queues - 1; i >= 0; i--) {
2458 : 0 : sg_ops->nthw_release_mngd_rx_virt_queue(internals->rxq_scg[i].vq);
2459 : : release_hw_virtio_queues(&internals->rxq_scg[i].hwq);
2460 : : }
2461 : :
2462 : 0 : internals = internals->next;
2463 : : }
2464 : : }
2465 : :
2466 [ # # ]: 0 : for (i = 0; i < n_phy_ports; i++) {
2467 : : sprintf(name, "ntnic%d", i);
2468 : 0 : eth_dev = rte_eth_dev_allocated(name);
2469 [ # # ]: 0 : if (eth_dev == NULL)
2470 : 0 : continue; /* port already released */
2471 : 0 : rte_eth_dev_release_port(eth_dev);
2472 : : }
2473 : :
2474 : 0 : nt_vfio_remove(EXCEPTION_PATH_HID);
2475 : 0 : return 0;
2476 : : }
2477 : :
2478 : : static int
2479 : 0 : nthw_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2480 : : struct rte_pci_device *pci_dev)
2481 : : {
2482 : : int ret;
2483 : :
2484 : 0 : NT_LOG_DBGX(DBG, NTNIC, "pcidev: name: '%s'", pci_dev->name);
2485 : 0 : NT_LOG_DBGX(DBG, NTNIC, "devargs: name: '%s'", pci_dev->device.name);
2486 : :
2487 [ # # ]: 0 : if (pci_dev->device.devargs) {
2488 [ # # ]: 0 : NT_LOG_DBGX(DBG, NTNIC, "devargs: args: '%s'",
2489 : : (pci_dev->device.devargs->args ? pci_dev->device.devargs->args : "NULL"));
2490 [ # # ]: 0 : NT_LOG_DBGX(DBG, NTNIC, "devargs: data: '%s'",
2491 : : (pci_dev->device.devargs->data ? pci_dev->device.devargs->data : "NULL"));
2492 : : }
2493 : :
2494 : 0 : const int n_rte_vfio_no_io_mmu_enabled = rte_vfio_noiommu_is_enabled();
2495 : 0 : NT_LOG(DBG, NTNIC, "vfio_no_iommu_enabled=%d", n_rte_vfio_no_io_mmu_enabled);
2496 : :
2497 [ # # ]: 0 : if (n_rte_vfio_no_io_mmu_enabled) {
2498 : 0 : NT_LOG(ERR, NTNIC, "vfio_no_iommu_enabled=%d: this PMD needs VFIO IOMMU",
2499 : : n_rte_vfio_no_io_mmu_enabled);
2500 : 0 : return -1;
2501 : : }
2502 : :
2503 : 0 : const enum rte_iova_mode n_rte_io_va_mode = rte_eal_iova_mode();
2504 : 0 : NT_LOG(DBG, NTNIC, "iova mode=%d", n_rte_io_va_mode);
2505 : :
2506 [ # # # # : 0 : NT_LOG(DBG, NTNIC,
# # ]
2507 : : "busid=" PCI_PRI_FMT
2508 : : " pciid=%04x:%04x_%04x:%04x locstr=%s @ numanode=%d: drv=%s drvalias=%s",
2509 : : pci_dev->addr.domain, pci_dev->addr.bus, pci_dev->addr.devid,
2510 : : pci_dev->addr.function, pci_dev->id.vendor_id, pci_dev->id.device_id,
2511 : : pci_dev->id.subsystem_vendor_id, pci_dev->id.subsystem_device_id,
2512 : : pci_dev->name[0] ? pci_dev->name : "NA",
2513 : : pci_dev->device.numa_node,
2514 : : pci_dev->driver->driver.name ? pci_dev->driver->driver.name : "NA",
2515 : : pci_dev->driver->driver.alias ? pci_dev->driver->driver.alias : "NA");
2516 : :
2517 : :
2518 : 0 : ret = nthw_pci_dev_init(pci_dev);
2519 : :
2520 : : /*
2521 : : * 1 time calculation of 1 sec stat update rtc cycles to prevent stat poll
2522 : : * flooding by OVS from multiple virtual port threads - no need to be precise
2523 : : */
2524 : : uint64_t now_rtc = rte_get_tsc_cycles();
2525 : 0 : nt_os_wait_usec(10 * 1000);
2526 : 0 : rte_tsc_freq = 100 * (rte_get_tsc_cycles() - now_rtc);
2527 : :
2528 : 0 : NT_LOG_DBGX(DBG, NTNIC, "leave: ret=%d", ret);
2529 : 0 : return ret;
2530 : : }
2531 : :
2532 : : static int
2533 : 0 : nthw_pci_remove(struct rte_pci_device *pci_dev)
2534 : : {
2535 : 0 : NT_LOG_DBGX(DBG, NTNIC);
2536 : :
2537 : 0 : struct drv_s *p_drv = get_pdrv_from_pci(pci_dev->addr);
2538 : 0 : drv_deinit(p_drv);
2539 : :
2540 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, nthw_pci_dev_deinit);
2541 : : }
2542 : :
2543 : : static struct rte_pci_driver rte_nthw_pmd = {
2544 : : .id_table = nthw_pci_id_map,
2545 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2546 : : .probe = nthw_pci_probe,
2547 : : .remove = nthw_pci_remove,
2548 : : };
2549 : :
2550 : 252 : RTE_PMD_REGISTER_PCI(net_ntnic, rte_nthw_pmd);
2551 : : RTE_PMD_REGISTER_PCI_TABLE(net_ntnic, nthw_pci_id_map);
2552 : : RTE_PMD_REGISTER_KMOD_DEP(net_ntnic, "* vfio-pci");
2553 : :
2554 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(nt_log_general, general, INFO);
2555 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(nt_log_nthw, nthw, INFO);
2556 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(nt_log_filter, filter, INFO);
2557 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(nt_log_ntnic, ntnic, INFO);
|