Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2016 Cavium, Inc
3 : : */
4 : :
5 : : #include <assert.h>
6 : : #include <stdio.h>
7 : : #include <stdbool.h>
8 : : #include <errno.h>
9 : : #include <stdint.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : : #include <netinet/in.h>
15 : : #include <sys/queue.h>
16 : :
17 : : #include <rte_alarm.h>
18 : : #include <rte_branch_prediction.h>
19 : : #include <rte_byteorder.h>
20 : : #include <rte_common.h>
21 : : #include <rte_cycles.h>
22 : : #include <rte_debug.h>
23 : : #include <dev_driver.h>
24 : : #include <rte_eal.h>
25 : : #include <rte_ether.h>
26 : : #include <ethdev_driver.h>
27 : : #include <ethdev_pci.h>
28 : : #include <rte_interrupts.h>
29 : : #include <rte_log.h>
30 : : #include <rte_memory.h>
31 : : #include <rte_memzone.h>
32 : : #include <rte_malloc.h>
33 : : #include <rte_random.h>
34 : : #include <rte_pci.h>
35 : : #include <bus_pci_driver.h>
36 : : #include <rte_tailq.h>
37 : : #include <rte_devargs.h>
38 : : #include <rte_kvargs.h>
39 : :
40 : : #include "base/nicvf_plat.h"
41 : :
42 : : #include "nicvf_ethdev.h"
43 : : #include "nicvf_rxtx.h"
44 : : #include "nicvf_svf.h"
45 : : #include "nicvf_logs.h"
46 : :
47 : : static int nicvf_dev_stop(struct rte_eth_dev *dev);
48 : : static void nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup);
49 : : static void nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic,
50 : : bool cleanup);
51 : : static int nicvf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
52 : : static int nicvf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
53 : :
54 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_mbox, mbox, NOTICE);
55 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_init, init, NOTICE);
56 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_driver, driver, NOTICE);
57 : :
58 : : #define NICVF_QLM_MODE_SGMII 7
59 : : #define NICVF_QLM_MODE_XFI 12
60 : :
61 : : #define BCAST_ACCEPT 0x01
62 : : #define CAM_ACCEPT (1 << 3)
63 : : #define BGX_MCAST_MODE(x) ((x) << 1)
64 : :
65 : : enum nicvf_link_speed {
66 : : NICVF_LINK_SPEED_SGMII,
67 : : NICVF_LINK_SPEED_XAUI,
68 : : NICVF_LINK_SPEED_RXAUI,
69 : : NICVF_LINK_SPEED_10G_R,
70 : : NICVF_LINK_SPEED_40G_R,
71 : : NICVF_LINK_SPEED_RESERVE1,
72 : : NICVF_LINK_SPEED_QSGMII,
73 : : NICVF_LINK_SPEED_RESERVE2,
74 : : NICVF_LINK_SPEED_UNKNOWN = 255
75 : : };
76 : :
77 : : static inline uint32_t
78 : : nicvf_parse_link_speeds(uint32_t link_speeds)
79 : : {
80 : : uint32_t link_speed = NICVF_LINK_SPEED_UNKNOWN;
81 : :
82 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
83 : : link_speed = NICVF_LINK_SPEED_40G_R;
84 : :
85 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G) {
86 : : link_speed = NICVF_LINK_SPEED_XAUI;
87 : : link_speed |= NICVF_LINK_SPEED_RXAUI;
88 : : link_speed |= NICVF_LINK_SPEED_10G_R;
89 : : }
90 : :
91 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_5G)
92 : : link_speed = NICVF_LINK_SPEED_QSGMII;
93 : :
94 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
95 : : link_speed = NICVF_LINK_SPEED_SGMII;
96 : :
97 : : return link_speed;
98 : : }
99 : :
100 : : static inline uint8_t
101 : : nicvf_parse_eth_link_duplex(uint32_t link_speeds)
102 : : {
103 : 0 : if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) ||
104 : : (link_speeds & RTE_ETH_LINK_SPEED_100M_HD))
105 : : return RTE_ETH_LINK_HALF_DUPLEX;
106 : : else
107 : 0 : return RTE_ETH_LINK_FULL_DUPLEX;
108 : : }
109 : :
110 : : static int
111 [ # # ]: 0 : nicvf_apply_link_speed(struct rte_eth_dev *dev)
112 : : {
113 : : struct nicvf *nic = nicvf_pmd_priv(dev);
114 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
115 : : struct change_link_mode cfg;
116 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG)
117 : : /* TODO: Handle this case */
118 : : return 0;
119 : :
120 : 0 : cfg.speed = nicvf_parse_link_speeds(conf->link_speeds);
121 [ # # ]: 0 : cfg.autoneg = (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) ? 1 : 0;
122 : 0 : cfg.duplex = nicvf_parse_eth_link_duplex(conf->link_speeds);
123 [ # # # # ]: 0 : cfg.qlm_mode = ((conf->link_speeds & RTE_ETH_LINK_SPEED_1G) ?
124 : : NICVF_QLM_MODE_SGMII :
125 : : (conf->link_speeds & RTE_ETH_LINK_SPEED_10G) ?
126 : : NICVF_QLM_MODE_XFI : 0);
127 : :
128 [ # # ]: 0 : if (cfg.speed != NICVF_LINK_SPEED_UNKNOWN &&
129 [ # # # # ]: 0 : (cfg.speed != nic->speed || cfg.duplex != nic->duplex)) {
130 : 0 : nic->speed = cfg.speed;
131 : 0 : nic->duplex = cfg.duplex;
132 : 0 : return nicvf_mbox_change_mode(nic, &cfg);
133 : : } else {
134 : : return 0;
135 : : }
136 : : }
137 : :
138 : : static void
139 [ # # ]: 0 : nicvf_link_status_update(struct nicvf *nic,
140 : : struct rte_eth_link *link)
141 : : {
142 : : memset(link, 0, sizeof(*link));
143 : :
144 : 0 : link->link_status = nic->link_up ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
145 : :
146 [ # # ]: 0 : if (nic->duplex == NICVF_HALF_DUPLEX)
147 : : link->link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
148 [ # # ]: 0 : else if (nic->duplex == NICVF_FULL_DUPLEX)
149 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
150 : 0 : link->link_speed = nic->speed;
151 : 0 : link->link_autoneg = RTE_ETH_LINK_AUTONEG;
152 : 0 : }
153 : :
154 : : /*Poll for link status change by sending NIC_MBOX_MSG_BGX_LINK_CHANGE msg
155 : : * periodically to PF.
156 : : */
157 : : static void
158 : 0 : nicvf_interrupt(void *arg)
159 : : {
160 : : struct rte_eth_dev *dev = arg;
161 : : struct nicvf *nic = nicvf_pmd_priv(dev);
162 : : struct rte_eth_link link;
163 : :
164 : 0 : rte_eth_linkstatus_get(dev, &link);
165 : :
166 : 0 : nicvf_mbox_link_change(nic);
167 [ # # ]: 0 : if (nic->link_up != link.link_status) {
168 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc) {
169 : 0 : nicvf_link_status_update(nic, &link);
170 : 0 : rte_eth_linkstatus_set(dev, &link);
171 : :
172 : 0 : rte_eth_dev_callback_process(dev,
173 : : RTE_ETH_EVENT_INTR_LSC,
174 : : NULL);
175 : : }
176 : : }
177 : :
178 : 0 : rte_eal_alarm_set(NICVF_INTR_LINK_POLL_INTERVAL_MS * 1000,
179 : : nicvf_interrupt, dev);
180 : 0 : }
181 : :
182 : : static void
183 : 0 : nicvf_vf_interrupt(void *arg)
184 : : {
185 : : struct nicvf *nic = arg;
186 : :
187 : 0 : nicvf_reg_poll_interrupts(nic);
188 : :
189 : 0 : rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
190 : : nicvf_vf_interrupt, nic);
191 : 0 : }
192 : :
193 : : static int
194 : : nicvf_periodic_alarm_start(void (fn)(void *), void *arg)
195 : : {
196 : 0 : return rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000, fn, arg);
197 : : }
198 : :
199 : : static int
200 : : nicvf_periodic_alarm_stop(void (fn)(void *), void *arg)
201 : : {
202 : 0 : return rte_eal_alarm_cancel(fn, arg);
203 : : }
204 : :
205 : : /*
206 : : * Return 0 means link status changed, -1 means not changed
207 : : */
208 : : static int
209 : 0 : nicvf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
210 : : {
211 : : #define CHECK_INTERVAL 100 /* 100ms */
212 : : #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
213 : : struct rte_eth_link link;
214 : : struct nicvf *nic = nicvf_pmd_priv(dev);
215 : : int i;
216 : :
217 : 0 : PMD_INIT_FUNC_TRACE();
218 : :
219 [ # # ]: 0 : if (wait_to_complete) {
220 : : /* rte_eth_link_get() might need to wait up to 9 seconds */
221 [ # # ]: 0 : for (i = 0; i < MAX_CHECK_TIME; i++) {
222 : 0 : nicvf_link_status_update(nic, &link);
223 [ # # ]: 0 : if (link.link_status == RTE_ETH_LINK_UP)
224 : : break;
225 : : rte_delay_ms(CHECK_INTERVAL);
226 : : }
227 : : } else {
228 : 0 : nicvf_link_status_update(nic, &link);
229 : : }
230 : :
231 : 0 : return rte_eth_linkstatus_set(dev, &link);
232 : : }
233 : :
234 : : static int
235 : 0 : nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
236 : : {
237 : : struct nicvf *nic = nicvf_pmd_priv(dev);
238 : 0 : uint32_t buffsz, frame_size = mtu + NIC_HW_L2_OVERHEAD;
239 : : size_t i;
240 : :
241 : 0 : PMD_INIT_FUNC_TRACE();
242 : :
243 : 0 : buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
244 : :
245 : : /*
246 : : * Refuse mtu that requires the support of scattered packets
247 : : * when this feature has not been enabled before.
248 : : */
249 [ # # ]: 0 : if (dev->data->dev_started && !dev->data->scattered_rx &&
250 [ # # ]: 0 : (frame_size + 2 * VLAN_TAG_SIZE > buffsz))
251 : : return -EINVAL;
252 : :
253 : : /* check <seg size> * <max_seg> >= max_frame */
254 [ # # ]: 0 : if (dev->data->scattered_rx &&
255 [ # # ]: 0 : (frame_size + 2 * VLAN_TAG_SIZE > buffsz * NIC_HW_MAX_SEGS))
256 : : return -EINVAL;
257 : :
258 [ # # ]: 0 : if (nicvf_mbox_update_hw_max_frs(nic, mtu))
259 : : return -EINVAL;
260 : :
261 : 0 : nic->mtu = mtu;
262 : :
263 [ # # ]: 0 : for (i = 0; i < nic->sqs_count; i++)
264 : 0 : nic->snicvf[i]->mtu = mtu;
265 : :
266 : : return 0;
267 : : }
268 : :
269 : : static int
270 : 0 : nicvf_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
271 : : {
272 [ # # ]: 0 : uint64_t *data = regs->data;
273 : : struct nicvf *nic = nicvf_pmd_priv(dev);
274 : :
275 [ # # ]: 0 : if (data == NULL) {
276 : 0 : regs->length = nicvf_reg_get_count();
277 : 0 : regs->width = THUNDERX_REG_BYTES;
278 : 0 : return 0;
279 : : }
280 : :
281 : : /* Support only full register dump */
282 [ # # ]: 0 : if ((regs->length == 0) ||
283 [ # # ]: 0 : (regs->length == (uint32_t)nicvf_reg_get_count())) {
284 : 0 : regs->version = nic->vendor_id << 16 | nic->device_id;
285 : 0 : nicvf_reg_dump(nic, data);
286 : 0 : return 0;
287 : : }
288 : : return -ENOTSUP;
289 : : }
290 : :
291 : : static int
292 [ # # ]: 0 : nicvf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
293 : : struct eth_queue_stats *qstats)
294 : : {
295 : : uint16_t qidx;
296 : : struct nicvf_hw_rx_qstats rx_qstats;
297 : : struct nicvf_hw_tx_qstats tx_qstats;
298 : : struct nicvf_hw_stats port_stats;
299 : : struct nicvf *nic = nicvf_pmd_priv(dev);
300 : : uint16_t rx_start, rx_end;
301 : : uint16_t tx_start, tx_end;
302 : : size_t i;
303 : :
304 : : /* RX queue indices for the first VF */
305 : : nicvf_rx_range(dev, nic, &rx_start, &rx_end);
306 : :
307 : : /* Reading per RX ring stats */
308 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
309 [ # # ]: 0 : if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
310 : : break;
311 : :
312 : 0 : nicvf_hw_get_rx_qstats(nic, &rx_qstats, qidx);
313 [ # # ]: 0 : if (qstats != NULL) {
314 : 0 : qstats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
315 : 0 : qstats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
316 : : }
317 : : }
318 : :
319 : : /* TX queue indices for the first VF */
320 : : nicvf_tx_range(dev, nic, &tx_start, &tx_end);
321 : :
322 : : /* Reading per TX ring stats */
323 [ # # ]: 0 : for (qidx = tx_start; qidx <= tx_end; qidx++) {
324 [ # # ]: 0 : if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
325 : : break;
326 : :
327 : 0 : nicvf_hw_get_tx_qstats(nic, &tx_qstats, qidx);
328 [ # # ]: 0 : if (qstats != NULL) {
329 : 0 : qstats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
330 : 0 : qstats->q_opackets[qidx] = tx_qstats.q_tx_packets;
331 : : }
332 : : }
333 : :
334 [ # # ]: 0 : for (i = 0; i < nic->sqs_count; i++) {
335 : 0 : struct nicvf *snic = nic->snicvf[i];
336 : :
337 [ # # ]: 0 : if (snic == NULL)
338 : : break;
339 : :
340 : : /* RX queue indices for a secondary VF */
341 : : nicvf_rx_range(dev, snic, &rx_start, &rx_end);
342 : :
343 : : /* Reading per RX ring stats */
344 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
345 [ # # ]: 0 : if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
346 : : break;
347 : :
348 : 0 : nicvf_hw_get_rx_qstats(snic, &rx_qstats,
349 : 0 : qidx % MAX_RCV_QUEUES_PER_QS);
350 [ # # ]: 0 : if (qstats != NULL) {
351 : 0 : qstats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
352 : 0 : qstats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
353 : : }
354 : : }
355 : :
356 : : /* TX queue indices for a secondary VF */
357 : : nicvf_tx_range(dev, snic, &tx_start, &tx_end);
358 : : /* Reading per TX ring stats */
359 [ # # ]: 0 : for (qidx = tx_start; qidx <= tx_end; qidx++) {
360 [ # # ]: 0 : if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
361 : : break;
362 : :
363 : 0 : nicvf_hw_get_tx_qstats(snic, &tx_qstats,
364 : 0 : qidx % MAX_SND_QUEUES_PER_QS);
365 [ # # ]: 0 : if (qstats != NULL) {
366 : 0 : qstats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
367 : 0 : qstats->q_opackets[qidx] = tx_qstats.q_tx_packets;
368 : : }
369 : : }
370 : : }
371 : :
372 : 0 : nicvf_hw_get_stats(nic, &port_stats);
373 : 0 : stats->ibytes = port_stats.rx_bytes;
374 : 0 : stats->ipackets = port_stats.rx_ucast_frames;
375 : 0 : stats->ipackets += port_stats.rx_bcast_frames;
376 : 0 : stats->ipackets += port_stats.rx_mcast_frames;
377 : 0 : stats->ierrors = port_stats.rx_l2_errors;
378 : 0 : stats->imissed = port_stats.rx_drop_red;
379 : 0 : stats->imissed += port_stats.rx_drop_overrun;
380 : 0 : stats->imissed += port_stats.rx_drop_bcast;
381 : 0 : stats->imissed += port_stats.rx_drop_mcast;
382 : 0 : stats->imissed += port_stats.rx_drop_l3_bcast;
383 : 0 : stats->imissed += port_stats.rx_drop_l3_mcast;
384 : :
385 : 0 : stats->obytes = port_stats.tx_bytes_ok;
386 : 0 : stats->opackets = port_stats.tx_ucast_frames_ok;
387 : 0 : stats->opackets += port_stats.tx_bcast_frames_ok;
388 : 0 : stats->opackets += port_stats.tx_mcast_frames_ok;
389 : 0 : stats->oerrors = port_stats.tx_drops;
390 : :
391 : 0 : return 0;
392 : : }
393 : :
394 : : static const uint32_t *
395 [ # # ]: 0 : nicvf_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
396 : : {
397 : : size_t copied;
398 : : static uint32_t ptypes[32];
399 : : struct nicvf *nic = nicvf_pmd_priv(dev);
400 : : static const uint32_t ptypes_common[] = {
401 : : RTE_PTYPE_L3_IPV4,
402 : : RTE_PTYPE_L3_IPV4_EXT,
403 : : RTE_PTYPE_L3_IPV6,
404 : : RTE_PTYPE_L3_IPV6_EXT,
405 : : RTE_PTYPE_L4_TCP,
406 : : RTE_PTYPE_L4_UDP,
407 : : RTE_PTYPE_L4_FRAG,
408 : : };
409 : : static const uint32_t ptypes_tunnel[] = {
410 : : RTE_PTYPE_TUNNEL_GRE,
411 : : RTE_PTYPE_TUNNEL_GENEVE,
412 : : RTE_PTYPE_TUNNEL_VXLAN,
413 : : RTE_PTYPE_TUNNEL_NVGRE,
414 : : };
415 : :
416 : : copied = sizeof(ptypes_common);
417 : : memcpy(ptypes, ptypes_common, copied);
418 [ # # ]: 0 : if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
419 : : memcpy((char *)ptypes + copied, ptypes_tunnel,
420 : : sizeof(ptypes_tunnel));
421 : : copied += sizeof(ptypes_tunnel);
422 : : }
423 : :
424 : :
425 : : /* All Ptypes are supported in all Rx functions. */
426 : 0 : *no_of_elements = copied / sizeof(ptypes[0]);
427 : 0 : return ptypes;
428 : : }
429 : :
430 : : static int
431 [ # # ]: 0 : nicvf_dev_stats_reset(struct rte_eth_dev *dev)
432 : : {
433 : : int i;
434 : : uint16_t rxqs = 0, txqs = 0;
435 : : struct nicvf *nic = nicvf_pmd_priv(dev);
436 : : uint16_t rx_start, rx_end;
437 : : uint16_t tx_start, tx_end;
438 : : int ret;
439 : :
440 : : /* Reset all primary nic counters */
441 : : nicvf_rx_range(dev, nic, &rx_start, &rx_end);
442 [ # # ]: 0 : for (i = rx_start; i <= rx_end; i++)
443 : 0 : rxqs |= (0x3 << (i * 2));
444 : :
445 : : nicvf_tx_range(dev, nic, &tx_start, &tx_end);
446 [ # # ]: 0 : for (i = tx_start; i <= tx_end; i++)
447 : 0 : txqs |= (0x3 << (i * 2));
448 : :
449 : 0 : ret = nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, rxqs, txqs);
450 [ # # ]: 0 : if (ret != 0)
451 : : return ret;
452 : :
453 : : /* Reset secondary nic queue counters */
454 [ # # ]: 0 : for (i = 0; i < nic->sqs_count; i++) {
455 : 0 : struct nicvf *snic = nic->snicvf[i];
456 [ # # ]: 0 : if (snic == NULL)
457 : : break;
458 : :
459 : : nicvf_rx_range(dev, snic, &rx_start, &rx_end);
460 [ # # ]: 0 : for (i = rx_start; i <= rx_end; i++)
461 : 0 : rxqs |= (0x3 << ((i % MAX_CMP_QUEUES_PER_QS) * 2));
462 : :
463 : : nicvf_tx_range(dev, snic, &tx_start, &tx_end);
464 [ # # ]: 0 : for (i = tx_start; i <= tx_end; i++)
465 : 0 : txqs |= (0x3 << ((i % MAX_SND_QUEUES_PER_QS) * 2));
466 : :
467 : 0 : ret = nicvf_mbox_reset_stat_counters(snic, 0, 0, rxqs, txqs);
468 [ # # ]: 0 : if (ret != 0)
469 : 0 : return ret;
470 : : }
471 : :
472 : : return 0;
473 : : }
474 : :
475 : : /* Promiscuous mode enabled by default in LMAC to VF 1:1 map configuration */
476 : : static int
477 : 0 : nicvf_dev_promisc_enable(struct rte_eth_dev *dev __rte_unused)
478 : : {
479 : 0 : return 0;
480 : : }
481 : :
482 : : static inline uint64_t
483 : 0 : nicvf_rss_ethdev_to_nic(struct nicvf *nic, uint64_t ethdev_rss)
484 : : {
485 : : uint64_t nic_rss = 0;
486 : :
487 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_IPV4)
488 : : nic_rss |= RSS_IP_ENA;
489 : :
490 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_IPV6)
491 : : nic_rss |= RSS_IP_ENA;
492 : :
493 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
494 : : nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
495 : :
496 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
497 : 0 : nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
498 : :
499 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
500 : 0 : nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
501 : :
502 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
503 : 0 : nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
504 : :
505 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_PORT)
506 : 0 : nic_rss |= RSS_L2_EXTENDED_HASH_ENA;
507 : :
508 [ # # ]: 0 : if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
509 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_VXLAN)
510 : 0 : nic_rss |= RSS_TUN_VXLAN_ENA;
511 : :
512 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_GENEVE)
513 : 0 : nic_rss |= RSS_TUN_GENEVE_ENA;
514 : :
515 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_NVGRE)
516 : 0 : nic_rss |= RSS_TUN_NVGRE_ENA;
517 : : }
518 : :
519 : 0 : return nic_rss;
520 : : }
521 : :
522 : : static inline uint64_t
523 : 0 : nicvf_rss_nic_to_ethdev(struct nicvf *nic, uint64_t nic_rss)
524 : : {
525 : : uint64_t ethdev_rss = 0;
526 : :
527 [ # # ]: 0 : if (nic_rss & RSS_IP_ENA)
528 : : ethdev_rss |= (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6);
529 : :
530 [ # # ]: 0 : if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_TCP_ENA))
531 : 0 : ethdev_rss |= (RTE_ETH_RSS_NONFRAG_IPV4_TCP |
532 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP);
533 : :
534 [ # # ]: 0 : if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_UDP_ENA))
535 : 0 : ethdev_rss |= (RTE_ETH_RSS_NONFRAG_IPV4_UDP |
536 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP);
537 : :
538 [ # # ]: 0 : if (nic_rss & RSS_L2_EXTENDED_HASH_ENA)
539 : 0 : ethdev_rss |= RTE_ETH_RSS_PORT;
540 : :
541 [ # # ]: 0 : if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
542 [ # # ]: 0 : if (nic_rss & RSS_TUN_VXLAN_ENA)
543 : 0 : ethdev_rss |= RTE_ETH_RSS_VXLAN;
544 : :
545 [ # # ]: 0 : if (nic_rss & RSS_TUN_GENEVE_ENA)
546 : 0 : ethdev_rss |= RTE_ETH_RSS_GENEVE;
547 : :
548 [ # # ]: 0 : if (nic_rss & RSS_TUN_NVGRE_ENA)
549 : 0 : ethdev_rss |= RTE_ETH_RSS_NVGRE;
550 : : }
551 : 0 : return ethdev_rss;
552 : : }
553 : :
554 : : static int
555 [ # # ]: 0 : nicvf_dev_reta_query(struct rte_eth_dev *dev,
556 : : struct rte_eth_rss_reta_entry64 *reta_conf,
557 : : uint16_t reta_size)
558 : : {
559 : : struct nicvf *nic = nicvf_pmd_priv(dev);
560 : : uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
561 : : int ret, i, j;
562 : :
563 [ # # ]: 0 : if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
564 : 0 : PMD_DRV_LOG(ERR,
565 : : "The size of hash lookup table configured "
566 : : "(%u) doesn't match the number hardware can supported "
567 : : "(%u)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
568 : 0 : return -EINVAL;
569 : : }
570 : :
571 : 0 : ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
572 [ # # ]: 0 : if (ret)
573 : : return ret;
574 : :
575 : : /* Copy RETA table */
576 [ # # ]: 0 : for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_ETH_RETA_GROUP_SIZE); i++) {
577 [ # # ]: 0 : for (j = 0; j < RTE_ETH_RETA_GROUP_SIZE; j++)
578 [ # # ]: 0 : if ((reta_conf[i].mask >> j) & 0x01)
579 : 0 : reta_conf[i].reta[j] = tbl[j];
580 : : }
581 : :
582 : : return 0;
583 : : }
584 : :
585 : : static int
586 [ # # ]: 0 : nicvf_dev_reta_update(struct rte_eth_dev *dev,
587 : : struct rte_eth_rss_reta_entry64 *reta_conf,
588 : : uint16_t reta_size)
589 : : {
590 : : struct nicvf *nic = nicvf_pmd_priv(dev);
591 : : uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
592 : : int ret, i, j;
593 : :
594 [ # # ]: 0 : if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
595 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
596 : : "(%u) doesn't match the number hardware can supported "
597 : : "(%u)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
598 : 0 : return -EINVAL;
599 : : }
600 : :
601 : 0 : ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
602 [ # # ]: 0 : if (ret)
603 : : return ret;
604 : :
605 : : /* Copy RETA table */
606 [ # # ]: 0 : for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_ETH_RETA_GROUP_SIZE); i++) {
607 [ # # ]: 0 : for (j = 0; j < RTE_ETH_RETA_GROUP_SIZE; j++)
608 [ # # ]: 0 : if ((reta_conf[i].mask >> j) & 0x01)
609 : 0 : tbl[j] = reta_conf[i].reta[j];
610 : : }
611 : :
612 : 0 : return nicvf_rss_reta_update(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
613 : : }
614 : :
615 : : static int
616 [ # # ]: 0 : nicvf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
617 : : struct rte_eth_rss_conf *rss_conf)
618 : : {
619 : : struct nicvf *nic = nicvf_pmd_priv(dev);
620 : :
621 [ # # ]: 0 : if (rss_conf->rss_key)
622 : 0 : nicvf_rss_get_key(nic, rss_conf->rss_key);
623 : :
624 : 0 : rss_conf->rss_key_len = RSS_HASH_KEY_BYTE_SIZE;
625 : 0 : rss_conf->rss_hf = nicvf_rss_nic_to_ethdev(nic, nicvf_rss_get_cfg(nic));
626 : 0 : return 0;
627 : : }
628 : :
629 : : static int
630 [ # # ]: 0 : nicvf_dev_rss_hash_update(struct rte_eth_dev *dev,
631 : : struct rte_eth_rss_conf *rss_conf)
632 : : {
633 : : struct nicvf *nic = nicvf_pmd_priv(dev);
634 : : uint64_t nic_rss;
635 : :
636 [ # # ]: 0 : if (rss_conf->rss_key &&
637 [ # # ]: 0 : rss_conf->rss_key_len != RSS_HASH_KEY_BYTE_SIZE) {
638 : 0 : PMD_DRV_LOG(ERR, "Hash key size mismatch %u",
639 : : rss_conf->rss_key_len);
640 : 0 : return -EINVAL;
641 : : }
642 : :
643 [ # # ]: 0 : if (rss_conf->rss_key)
644 : 0 : nicvf_rss_set_key(nic, rss_conf->rss_key);
645 : :
646 : 0 : nic_rss = nicvf_rss_ethdev_to_nic(nic, rss_conf->rss_hf);
647 : 0 : nicvf_rss_set_cfg(nic, nic_rss);
648 : 0 : return 0;
649 : : }
650 : :
651 : : static int
652 : 0 : nicvf_qset_cq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
653 : : struct nicvf_rxq *rxq, uint16_t qidx, uint32_t desc_cnt)
654 : : {
655 : : const struct rte_memzone *rz;
656 : : uint32_t ring_size = CMP_QUEUE_SZ_MAX * sizeof(union cq_entry_t);
657 : :
658 : 0 : rz = rte_eth_dma_zone_reserve(dev, "cq_ring",
659 : : nicvf_netdev_qidx(nic, qidx), ring_size,
660 [ # # ]: 0 : NICVF_CQ_BASE_ALIGN_BYTES, nic->node);
661 [ # # ]: 0 : if (rz == NULL) {
662 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate mem for cq hw ring");
663 : 0 : return -ENOMEM;
664 : : }
665 : :
666 : 0 : memset(rz->addr, 0, ring_size);
667 : :
668 : 0 : rxq->phys = rz->iova;
669 : 0 : rxq->desc = rz->addr;
670 : 0 : rxq->qlen_mask = desc_cnt - 1;
671 : :
672 : 0 : return 0;
673 : : }
674 : :
675 : : static int
676 : 0 : nicvf_qset_sq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
677 : : struct nicvf_txq *sq, uint16_t qidx, uint32_t desc_cnt)
678 : : {
679 : : const struct rte_memzone *rz;
680 : : uint32_t ring_size = SND_QUEUE_SZ_MAX * sizeof(union sq_entry_t);
681 : :
682 : 0 : rz = rte_eth_dma_zone_reserve(dev, "sq",
683 : : nicvf_netdev_qidx(nic, qidx), ring_size,
684 [ # # ]: 0 : NICVF_SQ_BASE_ALIGN_BYTES, nic->node);
685 [ # # ]: 0 : if (rz == NULL) {
686 : 0 : PMD_INIT_LOG(ERR, "Failed allocate mem for sq hw ring");
687 : 0 : return -ENOMEM;
688 : : }
689 : :
690 : 0 : memset(rz->addr, 0, ring_size);
691 : :
692 : 0 : sq->phys = rz->iova;
693 : 0 : sq->desc = rz->addr;
694 : 0 : sq->qlen_mask = desc_cnt - 1;
695 : :
696 : 0 : return 0;
697 : : }
698 : :
699 : : static int
700 : 0 : nicvf_qset_rbdr_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
701 : : uint32_t desc_cnt, uint32_t buffsz)
702 : : {
703 : : struct nicvf_rbdr *rbdr;
704 : : const struct rte_memzone *rz;
705 : : uint32_t ring_size;
706 : :
707 [ # # ]: 0 : assert(nic->rbdr == NULL);
708 : 0 : rbdr = rte_zmalloc_socket("rbdr", sizeof(struct nicvf_rbdr),
709 : 0 : RTE_CACHE_LINE_SIZE, nic->node);
710 [ # # ]: 0 : if (rbdr == NULL) {
711 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr");
712 : 0 : return -ENOMEM;
713 : : }
714 : :
715 : : ring_size = sizeof(struct rbdr_entry_t) * RBDR_QUEUE_SZ_MAX;
716 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rbdr",
717 : : nicvf_netdev_qidx(nic, 0), ring_size,
718 [ # # ]: 0 : NICVF_RBDR_BASE_ALIGN_BYTES, nic->node);
719 [ # # ]: 0 : if (rz == NULL) {
720 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr desc ring");
721 : 0 : rte_free(rbdr);
722 : 0 : return -ENOMEM;
723 : : }
724 : :
725 : 0 : memset(rz->addr, 0, ring_size);
726 : :
727 : 0 : rbdr->phys = rz->iova;
728 : 0 : rbdr->tail = 0;
729 : 0 : rbdr->next_tail = 0;
730 : 0 : rbdr->desc = rz->addr;
731 : 0 : rbdr->buffsz = buffsz;
732 : 0 : rbdr->qlen_mask = desc_cnt - 1;
733 : 0 : rbdr->rbdr_status =
734 : 0 : nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_STATUS0;
735 : 0 : rbdr->rbdr_door =
736 : 0 : nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_DOOR;
737 : :
738 : 0 : nic->rbdr = rbdr;
739 : 0 : return 0;
740 : : }
741 : :
742 : : static void
743 [ # # ]: 0 : nicvf_rbdr_release_mbuf(struct rte_eth_dev *dev, struct nicvf *nic,
744 : : nicvf_iova_addr_t phy)
745 : : {
746 : : uint16_t qidx;
747 : : void *obj;
748 : : struct nicvf_rxq *rxq;
749 : : uint16_t rx_start, rx_end;
750 : :
751 : : /* Get queue ranges for this VF */
752 : : nicvf_rx_range(dev, nic, &rx_start, &rx_end);
753 : :
754 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
755 : 0 : rxq = dev->data->rx_queues[qidx];
756 [ # # ]: 0 : if (rxq->precharge_cnt) {
757 [ # # ]: 0 : obj = (void *)nicvf_mbuff_phy2virt(phy,
758 : : rxq->mbuf_phys_off);
759 [ # # ]: 0 : rte_mempool_put(rxq->pool, obj);
760 : 0 : rxq->precharge_cnt--;
761 : 0 : break;
762 : : }
763 : : }
764 : 0 : }
765 : :
766 : : static inline void
767 : 0 : nicvf_rbdr_release_mbufs(struct rte_eth_dev *dev, struct nicvf *nic)
768 : : {
769 : : uint32_t qlen_mask, head;
770 : : struct rbdr_entry_t *entry;
771 : 0 : struct nicvf_rbdr *rbdr = nic->rbdr;
772 : :
773 : 0 : qlen_mask = rbdr->qlen_mask;
774 : 0 : head = rbdr->head;
775 [ # # ]: 0 : while (head != rbdr->tail) {
776 : 0 : entry = rbdr->desc + head;
777 : 0 : nicvf_rbdr_release_mbuf(dev, nic, entry->full_addr);
778 : 0 : head++;
779 : 0 : head = head & qlen_mask;
780 : : }
781 : 0 : }
782 : :
783 : : static inline void
784 : 0 : nicvf_tx_queue_release_mbufs(struct nicvf_txq *txq)
785 : : {
786 : : uint32_t head;
787 : :
788 : 0 : head = txq->head;
789 [ # # ]: 0 : while (head != txq->tail) {
790 [ # # ]: 0 : if (txq->txbuffs[head]) {
791 : : rte_pktmbuf_free_seg(txq->txbuffs[head]);
792 : 0 : txq->txbuffs[head] = NULL;
793 : : }
794 : 0 : head++;
795 : 0 : head = head & txq->qlen_mask;
796 : : }
797 : 0 : }
798 : :
799 : : static void
800 : 0 : nicvf_tx_queue_reset(struct nicvf_txq *txq)
801 : : {
802 : 0 : uint32_t txq_desc_cnt = txq->qlen_mask + 1;
803 : :
804 : 0 : memset(txq->desc, 0, sizeof(union sq_entry_t) * txq_desc_cnt);
805 : 0 : memset(txq->txbuffs, 0, sizeof(struct rte_mbuf *) * txq_desc_cnt);
806 : 0 : txq->tail = 0;
807 : 0 : txq->head = 0;
808 : 0 : txq->xmit_bufs = 0;
809 : 0 : }
810 : :
811 : : static inline int
812 : 0 : nicvf_vf_start_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
813 : : uint16_t qidx)
814 : : {
815 : : struct nicvf_txq *txq;
816 : : int ret;
817 : :
818 [ # # ]: 0 : assert(qidx < MAX_SND_QUEUES_PER_QS);
819 : :
820 [ # # # # ]: 0 : if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
821 : : RTE_ETH_QUEUE_STATE_STARTED)
822 : : return 0;
823 : :
824 : 0 : txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
825 : 0 : txq->pool = NULL;
826 : 0 : ret = nicvf_qset_sq_config(nic, qidx, txq);
827 [ # # ]: 0 : if (ret) {
828 : 0 : PMD_INIT_LOG(ERR, "Failed to configure sq VF%d %d %d",
829 : : nic->vf_id, qidx, ret);
830 : 0 : goto config_sq_error;
831 : : }
832 : :
833 [ # # ]: 0 : dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
834 : : RTE_ETH_QUEUE_STATE_STARTED;
835 : 0 : return ret;
836 : :
837 : : config_sq_error:
838 : 0 : nicvf_qset_sq_reclaim(nic, qidx);
839 : 0 : return ret;
840 : : }
841 : :
842 : : static inline int
843 : 0 : nicvf_vf_stop_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
844 : : uint16_t qidx)
845 : : {
846 : : struct nicvf_txq *txq;
847 : : int ret;
848 : :
849 [ # # ]: 0 : assert(qidx < MAX_SND_QUEUES_PER_QS);
850 : :
851 [ # # # # ]: 0 : if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
852 : : RTE_ETH_QUEUE_STATE_STOPPED)
853 : : return 0;
854 : :
855 : 0 : ret = nicvf_qset_sq_reclaim(nic, qidx);
856 [ # # ]: 0 : if (ret)
857 : 0 : PMD_INIT_LOG(ERR, "Failed to reclaim sq VF%d %d %d",
858 : : nic->vf_id, qidx, ret);
859 : :
860 [ # # ]: 0 : txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
861 : 0 : nicvf_tx_queue_release_mbufs(txq);
862 : 0 : nicvf_tx_queue_reset(txq);
863 : :
864 [ # # ]: 0 : dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
865 : : RTE_ETH_QUEUE_STATE_STOPPED;
866 : 0 : return ret;
867 : : }
868 : :
869 : : static inline int
870 : 0 : nicvf_configure_cpi(struct rte_eth_dev *dev)
871 : : {
872 : : struct nicvf *nic = nicvf_pmd_priv(dev);
873 : : uint16_t qidx, qcnt;
874 : : int ret;
875 : :
876 : : /* Count started rx queues */
877 [ # # ]: 0 : for (qidx = qcnt = 0; qidx < dev->data->nb_rx_queues; qidx++)
878 [ # # ]: 0 : if (dev->data->rx_queue_state[qidx] ==
879 : : RTE_ETH_QUEUE_STATE_STARTED)
880 : 0 : qcnt++;
881 : :
882 : 0 : nic->cpi_alg = CPI_ALG_NONE;
883 : 0 : ret = nicvf_mbox_config_cpi(nic, qcnt);
884 [ # # ]: 0 : if (ret)
885 : 0 : PMD_INIT_LOG(ERR, "Failed to configure CPI %d", ret);
886 : :
887 : 0 : return ret;
888 : : }
889 : :
890 : : static inline int
891 : 0 : nicvf_configure_rss(struct rte_eth_dev *dev)
892 : : {
893 : : struct nicvf *nic = nicvf_pmd_priv(dev);
894 : : uint64_t rsshf;
895 : : int ret = -EINVAL;
896 : :
897 : 0 : rsshf = nicvf_rss_ethdev_to_nic(nic,
898 : : dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
899 : 0 : PMD_DRV_LOG(INFO, "mode=%d rx_queues=%d loopback=%d rsshf=0x%" PRIx64,
900 : : dev->data->dev_conf.rxmode.mq_mode,
901 : : dev->data->nb_rx_queues,
902 : : dev->data->dev_conf.lpbk_mode, rsshf);
903 : :
904 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_NONE)
905 : 0 : ret = nicvf_rss_term(nic);
906 [ # # ]: 0 : else if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS)
907 : 0 : ret = nicvf_rss_config(nic, dev->data->nb_rx_queues, rsshf);
908 [ # # ]: 0 : if (ret)
909 : 0 : PMD_INIT_LOG(ERR, "Failed to configure RSS %d", ret);
910 : :
911 : 0 : return ret;
912 : : }
913 : :
914 : : static int
915 [ # # ]: 0 : nicvf_configure_rss_reta(struct rte_eth_dev *dev)
916 : : {
917 : : struct nicvf *nic = nicvf_pmd_priv(dev);
918 : : unsigned int idx, qmap_size;
919 : : uint8_t qmap[RTE_MAX_QUEUES_PER_PORT];
920 : : uint8_t default_reta[NIC_MAX_RSS_IDR_TBL_SIZE];
921 : :
922 [ # # ]: 0 : if (nic->cpi_alg != CPI_ALG_NONE)
923 : : return -EINVAL;
924 : :
925 : : /* Prepare queue map */
926 [ # # ]: 0 : for (idx = 0, qmap_size = 0; idx < dev->data->nb_rx_queues; idx++) {
927 [ # # ]: 0 : if (dev->data->rx_queue_state[idx] ==
928 : : RTE_ETH_QUEUE_STATE_STARTED)
929 : 0 : qmap[qmap_size++] = idx;
930 : : }
931 : :
932 : : /* Update default RSS RETA */
933 [ # # ]: 0 : for (idx = 0; idx < NIC_MAX_RSS_IDR_TBL_SIZE; idx++)
934 : 0 : default_reta[idx] = qmap[idx % qmap_size];
935 : :
936 : 0 : return nicvf_rss_reta_update(nic, default_reta,
937 : : NIC_MAX_RSS_IDR_TBL_SIZE);
938 : : }
939 : :
940 : : static void
941 : 0 : nicvf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
942 : : {
943 : 0 : struct nicvf_txq *txq = dev->data->tx_queues[qid];
944 : :
945 : 0 : PMD_INIT_FUNC_TRACE();
946 : :
947 [ # # ]: 0 : if (txq) {
948 [ # # ]: 0 : if (txq->txbuffs != NULL) {
949 : 0 : nicvf_tx_queue_release_mbufs(txq);
950 : 0 : rte_free(txq->txbuffs);
951 : 0 : txq->txbuffs = NULL;
952 : : }
953 : 0 : rte_free(txq);
954 : 0 : dev->data->tx_queues[qid] = NULL;
955 : : }
956 : 0 : }
957 : :
958 : : static void
959 : 0 : nicvf_set_tx_function(struct rte_eth_dev *dev)
960 : : {
961 : : struct nicvf_txq *txq = NULL;
962 : : size_t i;
963 : : bool multiseg = false;
964 : :
965 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
966 : 0 : txq = dev->data->tx_queues[i];
967 [ # # ]: 0 : if (txq->offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS) {
968 : : multiseg = true;
969 : : break;
970 : : }
971 : : }
972 : :
973 : : /* Use a simple Tx queue (no offloads, no multi segs) if possible */
974 [ # # ]: 0 : if (multiseg) {
975 : 0 : PMD_DRV_LOG(DEBUG, "Using multi-segment tx callback");
976 : 0 : dev->tx_pkt_burst = nicvf_xmit_pkts_multiseg;
977 : : } else {
978 : 0 : PMD_DRV_LOG(DEBUG, "Using single-segment tx callback");
979 : 0 : dev->tx_pkt_burst = nicvf_xmit_pkts;
980 : : }
981 : :
982 [ # # ]: 0 : if (!txq)
983 : : return;
984 : :
985 [ # # ]: 0 : if (txq->pool_free == nicvf_single_pool_free_xmited_buffers)
986 : 0 : PMD_DRV_LOG(DEBUG, "Using single-mempool tx free method");
987 : : else
988 : 0 : PMD_DRV_LOG(DEBUG, "Using multi-mempool tx free method");
989 : : }
990 : :
991 : : static void
992 : 0 : nicvf_set_rx_function(struct rte_eth_dev *dev)
993 : : {
994 : : struct nicvf *nic = nicvf_pmd_priv(dev);
995 : :
996 : 0 : const eth_rx_burst_t rx_burst_func[2][2][2] = {
997 : : /* [NORMAL/SCATTER] [CKSUM/NO_CKSUM] [VLAN_STRIP/NO_VLAN_STRIP] */
998 : : [0][0][0] = nicvf_recv_pkts_no_offload,
999 : : [0][0][1] = nicvf_recv_pkts_vlan_strip,
1000 : : [0][1][0] = nicvf_recv_pkts_cksum,
1001 : : [0][1][1] = nicvf_recv_pkts_cksum_vlan_strip,
1002 : : [1][0][0] = nicvf_recv_pkts_multiseg_no_offload,
1003 : : [1][0][1] = nicvf_recv_pkts_multiseg_vlan_strip,
1004 : : [1][1][0] = nicvf_recv_pkts_multiseg_cksum,
1005 : : [1][1][1] = nicvf_recv_pkts_multiseg_cksum_vlan_strip,
1006 : : };
1007 : :
1008 : 0 : dev->rx_pkt_burst =
1009 : 0 : rx_burst_func[dev->data->scattered_rx]
1010 : 0 : [nic->offload_cksum][nic->vlan_strip];
1011 : 0 : }
1012 : :
1013 : : static int
1014 : 0 : nicvf_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1015 : : uint16_t nb_desc, unsigned int socket_id,
1016 : : const struct rte_eth_txconf *tx_conf)
1017 : : {
1018 : : uint16_t tx_free_thresh;
1019 : : bool is_single_pool;
1020 : : struct nicvf_txq *txq;
1021 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1022 : : uint64_t offloads;
1023 : :
1024 : 0 : PMD_INIT_FUNC_TRACE();
1025 : :
1026 [ # # ]: 0 : if (qidx >= MAX_SND_QUEUES_PER_QS)
1027 : 0 : nic = nic->snicvf[qidx / MAX_SND_QUEUES_PER_QS - 1];
1028 : :
1029 : 0 : qidx = qidx % MAX_SND_QUEUES_PER_QS;
1030 : :
1031 : : /* Socket id check */
1032 [ # # # # ]: 0 : if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
1033 : 0 : PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
1034 : : socket_id, nic->node);
1035 : :
1036 : : /* Tx deferred start is not supported */
1037 [ # # ]: 0 : if (tx_conf->tx_deferred_start) {
1038 : 0 : PMD_INIT_LOG(ERR, "Tx deferred start not supported");
1039 : 0 : return -EINVAL;
1040 : : }
1041 : :
1042 : : /* Roundup nb_desc to available qsize and validate max number of desc */
1043 : 0 : nb_desc = nicvf_qsize_sq_roundup(nb_desc);
1044 [ # # ]: 0 : if (nb_desc == 0) {
1045 : 0 : PMD_INIT_LOG(ERR, "Value of nb_desc beyond available sq qsize");
1046 : 0 : return -EINVAL;
1047 : : }
1048 : :
1049 : : /* Validate tx_free_thresh */
1050 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
1051 : : tx_conf->tx_free_thresh :
1052 : : NICVF_DEFAULT_TX_FREE_THRESH);
1053 : :
1054 [ # # ]: 0 : if (tx_free_thresh > (nb_desc) ||
1055 : : tx_free_thresh > NICVF_MAX_TX_FREE_THRESH) {
1056 : 0 : PMD_INIT_LOG(ERR,
1057 : : "tx_free_thresh must be less than the number of TX "
1058 : : "descriptors. (tx_free_thresh=%u port=%d "
1059 : : "queue=%d)", (unsigned int)tx_free_thresh,
1060 : : (int)dev->data->port_id, (int)qidx);
1061 : 0 : return -EINVAL;
1062 : : }
1063 : :
1064 : : /* Free memory prior to re-allocation if needed. */
1065 [ # # # # ]: 0 : if (dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
1066 : 0 : PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
1067 : : nicvf_netdev_qidx(nic, qidx));
1068 : 0 : nicvf_dev_tx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
1069 [ # # ]: 0 : dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
1070 : : }
1071 : :
1072 : : /* Allocating tx queue data structure */
1073 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nicvf_txq),
1074 : 0 : RTE_CACHE_LINE_SIZE, nic->node);
1075 [ # # ]: 0 : if (txq == NULL) {
1076 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate txq=%d",
1077 : : nicvf_netdev_qidx(nic, qidx));
1078 : 0 : return -ENOMEM;
1079 : : }
1080 : :
1081 : 0 : txq->nic = nic;
1082 : 0 : txq->queue_id = qidx;
1083 : 0 : txq->tx_free_thresh = tx_free_thresh;
1084 [ # # ]: 0 : txq->sq_head = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_HEAD;
1085 : 0 : txq->sq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_DOOR;
1086 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
1087 : 0 : txq->offloads = offloads;
1088 : :
1089 : 0 : is_single_pool = !!(offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE);
1090 : :
1091 : : /* Choose optimum free threshold value for multipool case */
1092 [ # # ]: 0 : if (!is_single_pool) {
1093 : 0 : txq->tx_free_thresh = (uint16_t)
1094 [ # # ]: 0 : (tx_conf->tx_free_thresh == NICVF_DEFAULT_TX_FREE_THRESH ?
1095 : : NICVF_TX_FREE_MPOOL_THRESH :
1096 : : tx_conf->tx_free_thresh);
1097 : 0 : txq->pool_free = nicvf_multi_pool_free_xmited_buffers;
1098 : : } else {
1099 : 0 : txq->pool_free = nicvf_single_pool_free_xmited_buffers;
1100 : : }
1101 : :
1102 [ # # ]: 0 : dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = txq;
1103 : :
1104 : : /* Allocate software ring */
1105 : 0 : txq->txbuffs = rte_zmalloc_socket("txq->txbuffs",
1106 : : nb_desc * sizeof(struct rte_mbuf *),
1107 : 0 : RTE_CACHE_LINE_SIZE, nic->node);
1108 : :
1109 [ # # ]: 0 : if (txq->txbuffs == NULL) {
1110 : 0 : nicvf_dev_tx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
1111 : 0 : return -ENOMEM;
1112 : : }
1113 : :
1114 [ # # ]: 0 : if (nicvf_qset_sq_alloc(dev, nic, txq, qidx, nb_desc)) {
1115 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate mem for sq %d", qidx);
1116 : 0 : nicvf_dev_tx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
1117 : 0 : return -ENOMEM;
1118 : : }
1119 : :
1120 : 0 : nicvf_tx_queue_reset(txq);
1121 : :
1122 [ # # ]: 0 : PMD_INIT_LOG(DEBUG, "[%d] txq=%p nb_desc=%d desc=%p"
1123 : : " phys=0x%" PRIx64 " offloads=0x%" PRIx64,
1124 : : nicvf_netdev_qidx(nic, qidx), txq, nb_desc, txq->desc,
1125 : : txq->phys, txq->offloads);
1126 : :
1127 [ # # ]: 0 : dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1128 : : RTE_ETH_QUEUE_STATE_STOPPED;
1129 : 0 : return 0;
1130 : : }
1131 : :
1132 : : static inline void
1133 : 0 : nicvf_rx_queue_release_mbufs(struct rte_eth_dev *dev, struct nicvf_rxq *rxq)
1134 : : {
1135 : : uint32_t rxq_cnt;
1136 : : uint32_t nb_pkts, released_pkts = 0;
1137 : : uint32_t refill_cnt = 0;
1138 : : struct rte_mbuf *rx_pkts[NICVF_MAX_RX_FREE_THRESH];
1139 : :
1140 [ # # ]: 0 : if (dev->rx_pkt_burst == NULL)
1141 : 0 : return;
1142 : :
1143 [ # # ]: 0 : while ((rxq_cnt = nicvf_dev_rx_queue_count(rxq))) {
1144 : 0 : nb_pkts = dev->rx_pkt_burst(rxq, rx_pkts,
1145 : : NICVF_MAX_RX_FREE_THRESH);
1146 : 0 : PMD_DRV_LOG(INFO, "nb_pkts=%d rxq_cnt=%d", nb_pkts, rxq_cnt);
1147 [ # # ]: 0 : while (nb_pkts) {
1148 [ # # ]: 0 : rte_pktmbuf_free_seg(rx_pkts[--nb_pkts]);
1149 : 0 : released_pkts++;
1150 : : }
1151 : : }
1152 : :
1153 : :
1154 : 0 : refill_cnt += nicvf_dev_rbdr_refill(dev,
1155 [ # # ]: 0 : nicvf_netdev_qidx(rxq->nic, rxq->queue_id));
1156 : :
1157 : 0 : PMD_DRV_LOG(INFO, "free_cnt=%d refill_cnt=%d",
1158 : : released_pkts, refill_cnt);
1159 : : }
1160 : :
1161 : : static void
1162 : : nicvf_rx_queue_reset(struct nicvf_rxq *rxq)
1163 : : {
1164 : 0 : rxq->head = 0;
1165 : 0 : rxq->available_space = 0;
1166 : 0 : rxq->recv_buffers = 0;
1167 : : }
1168 : :
1169 : : static inline int
1170 : 0 : nicvf_vf_start_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
1171 : : uint16_t qidx)
1172 : : {
1173 : : struct nicvf_rxq *rxq;
1174 : : int ret;
1175 : :
1176 [ # # ]: 0 : assert(qidx < MAX_RCV_QUEUES_PER_QS);
1177 : :
1178 [ # # # # ]: 0 : if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
1179 : : RTE_ETH_QUEUE_STATE_STARTED)
1180 : : return 0;
1181 : :
1182 : : /* Update rbdr pointer to all rxq */
1183 : 0 : rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
1184 : 0 : rxq->shared_rbdr = nic->rbdr;
1185 : :
1186 : 0 : ret = nicvf_qset_rq_config(nic, qidx, rxq);
1187 [ # # ]: 0 : if (ret) {
1188 : 0 : PMD_INIT_LOG(ERR, "Failed to configure rq VF%d %d %d",
1189 : : nic->vf_id, qidx, ret);
1190 : 0 : goto config_rq_error;
1191 : : }
1192 : 0 : ret = nicvf_qset_cq_config(nic, qidx, rxq);
1193 [ # # ]: 0 : if (ret) {
1194 : 0 : PMD_INIT_LOG(ERR, "Failed to configure cq VF%d %d %d",
1195 : : nic->vf_id, qidx, ret);
1196 : 0 : goto config_cq_error;
1197 : : }
1198 : :
1199 [ # # ]: 0 : dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1200 : : RTE_ETH_QUEUE_STATE_STARTED;
1201 : 0 : return 0;
1202 : :
1203 : : config_cq_error:
1204 : 0 : nicvf_qset_cq_reclaim(nic, qidx);
1205 : 0 : config_rq_error:
1206 : 0 : nicvf_qset_rq_reclaim(nic, qidx);
1207 : 0 : return ret;
1208 : : }
1209 : :
1210 : : static inline int
1211 : 0 : nicvf_vf_stop_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
1212 : : uint16_t qidx)
1213 : : {
1214 : : struct nicvf_rxq *rxq;
1215 : : int ret, other_error;
1216 : :
1217 [ # # # # ]: 0 : if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
1218 : : RTE_ETH_QUEUE_STATE_STOPPED)
1219 : : return 0;
1220 : :
1221 : 0 : ret = nicvf_qset_rq_reclaim(nic, qidx);
1222 [ # # ]: 0 : if (ret)
1223 : 0 : PMD_INIT_LOG(ERR, "Failed to reclaim rq VF%d %d %d",
1224 : : nic->vf_id, qidx, ret);
1225 : :
1226 : : other_error = ret;
1227 [ # # ]: 0 : rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
1228 : 0 : nicvf_rx_queue_release_mbufs(dev, rxq);
1229 : : nicvf_rx_queue_reset(rxq);
1230 : :
1231 : 0 : ret = nicvf_qset_cq_reclaim(nic, qidx);
1232 [ # # ]: 0 : if (ret)
1233 : 0 : PMD_INIT_LOG(ERR, "Failed to reclaim cq VF%d %d %d",
1234 : : nic->vf_id, qidx, ret);
1235 : :
1236 : 0 : other_error |= ret;
1237 [ # # ]: 0 : dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1238 : : RTE_ETH_QUEUE_STATE_STOPPED;
1239 : 0 : return other_error;
1240 : : }
1241 : :
1242 : : static void
1243 : 0 : nicvf_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1244 : : {
1245 : 0 : PMD_INIT_FUNC_TRACE();
1246 : :
1247 : 0 : rte_free(dev->data->rx_queues[qid]);
1248 : 0 : }
1249 : :
1250 : : static int
1251 [ # # ]: 0 : nicvf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1252 : : {
1253 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1254 : : int ret;
1255 : :
1256 [ # # ]: 0 : if (qidx >= MAX_RCV_QUEUES_PER_QS)
1257 : 0 : nic = nic->snicvf[(qidx / MAX_RCV_QUEUES_PER_QS - 1)];
1258 : :
1259 : 0 : qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1260 : :
1261 : 0 : ret = nicvf_vf_start_rx_queue(dev, nic, qidx);
1262 [ # # ]: 0 : if (ret)
1263 : : return ret;
1264 : :
1265 : 0 : ret = nicvf_configure_cpi(dev);
1266 [ # # ]: 0 : if (ret)
1267 : : return ret;
1268 : :
1269 : 0 : return nicvf_configure_rss_reta(dev);
1270 : : }
1271 : :
1272 : : static int
1273 [ # # ]: 0 : nicvf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1274 : : {
1275 : : int ret;
1276 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1277 : :
1278 [ # # ]: 0 : if (qidx >= MAX_SND_QUEUES_PER_QS)
1279 : 0 : nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1280 : :
1281 : 0 : qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1282 : :
1283 : 0 : ret = nicvf_vf_stop_rx_queue(dev, nic, qidx);
1284 : 0 : ret |= nicvf_configure_cpi(dev);
1285 : 0 : ret |= nicvf_configure_rss_reta(dev);
1286 : 0 : return ret;
1287 : : }
1288 : :
1289 : : static int
1290 [ # # ]: 0 : nicvf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1291 : : {
1292 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1293 : :
1294 [ # # ]: 0 : if (qidx >= MAX_SND_QUEUES_PER_QS)
1295 : 0 : nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1296 : :
1297 : 0 : qidx = qidx % MAX_SND_QUEUES_PER_QS;
1298 : :
1299 : 0 : return nicvf_vf_start_tx_queue(dev, nic, qidx);
1300 : : }
1301 : :
1302 : : static int
1303 [ # # ]: 0 : nicvf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1304 : : {
1305 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1306 : :
1307 [ # # ]: 0 : if (qidx >= MAX_SND_QUEUES_PER_QS)
1308 : 0 : nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1309 : :
1310 : 0 : qidx = qidx % MAX_SND_QUEUES_PER_QS;
1311 : :
1312 : 0 : return nicvf_vf_stop_tx_queue(dev, nic, qidx);
1313 : : }
1314 : :
1315 : : static inline void
1316 : 0 : nicvf_rxq_mbuf_setup(struct nicvf_rxq *rxq)
1317 : : {
1318 : : uintptr_t p;
1319 : : struct rte_mbuf mb_def;
1320 : 0 : struct nicvf *nic = rxq->nic;
1321 : :
1322 : : RTE_BUILD_BUG_ON(sizeof(union mbuf_initializer) != 8);
1323 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
1324 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
1325 : : offsetof(struct rte_mbuf, data_off) != 2);
1326 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
1327 : : offsetof(struct rte_mbuf, data_off) != 4);
1328 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
1329 : : offsetof(struct rte_mbuf, data_off) != 6);
1330 : : RTE_BUILD_BUG_ON(offsetof(struct nicvf_rxq, rxq_fastpath_data_end) -
1331 : : offsetof(struct nicvf_rxq,
1332 : : rxq_fastpath_data_start) > 128);
1333 : 0 : mb_def.nb_segs = 1;
1334 : 0 : mb_def.data_off = RTE_PKTMBUF_HEADROOM + (nic->skip_bytes);
1335 : 0 : mb_def.port = rxq->port_id;
1336 : : rte_mbuf_refcnt_set(&mb_def, 1);
1337 : :
1338 : : /* Prevent compiler reordering: rearm_data covers previous fields */
1339 : 0 : rte_compiler_barrier();
1340 : : p = (uintptr_t)&mb_def.rearm_data;
1341 : 0 : rxq->mbuf_initializer.value = *(uint64_t *)p;
1342 : 0 : }
1343 : :
1344 : : static int
1345 : 0 : nicvf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1346 : : uint16_t nb_desc, unsigned int socket_id,
1347 : : const struct rte_eth_rxconf *rx_conf,
1348 : : struct rte_mempool *mp)
1349 : : {
1350 : : uint16_t rx_free_thresh;
1351 : : struct nicvf_rxq *rxq;
1352 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1353 : : uint64_t offloads;
1354 : : uint32_t buffsz;
1355 : : struct rte_pktmbuf_pool_private *mbp_priv;
1356 : :
1357 : 0 : PMD_INIT_FUNC_TRACE();
1358 : :
1359 : : /* First skip check */
1360 : : mbp_priv = rte_mempool_get_priv(mp);
1361 : 0 : buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1362 [ # # ]: 0 : if (buffsz < (uint32_t)(nic->skip_bytes)) {
1363 : 0 : PMD_INIT_LOG(ERR, "First skip is more than configured buffer size");
1364 : 0 : return -EINVAL;
1365 : : }
1366 : :
1367 [ # # ]: 0 : if (qidx >= MAX_RCV_QUEUES_PER_QS)
1368 : 0 : nic = nic->snicvf[qidx / MAX_RCV_QUEUES_PER_QS - 1];
1369 : :
1370 : 0 : qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1371 : :
1372 : : /* Socket id check */
1373 [ # # # # ]: 0 : if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
1374 : 0 : PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
1375 : : socket_id, nic->node);
1376 : :
1377 : : /* Mempool memory must be contiguous, so must be one memory segment*/
1378 [ # # ]: 0 : if (mp->nb_mem_chunks != 1) {
1379 : 0 : PMD_INIT_LOG(ERR, "Non-contiguous mempool, add more huge pages");
1380 : 0 : return -EINVAL;
1381 : : }
1382 : :
1383 : : /* Mempool memory must be physically contiguous */
1384 [ # # ]: 0 : if (mp->flags & RTE_MEMPOOL_F_NO_IOVA_CONTIG) {
1385 : 0 : PMD_INIT_LOG(ERR, "Mempool memory must be physically contiguous");
1386 : 0 : return -EINVAL;
1387 : : }
1388 : :
1389 : : /* Rx deferred start is not supported */
1390 [ # # ]: 0 : if (rx_conf->rx_deferred_start) {
1391 : 0 : PMD_INIT_LOG(ERR, "Rx deferred start not supported");
1392 : 0 : return -EINVAL;
1393 : : }
1394 : :
1395 : : /* Roundup nb_desc to available qsize and validate max number of desc */
1396 : 0 : nb_desc = nicvf_qsize_cq_roundup(nb_desc);
1397 [ # # ]: 0 : if (nb_desc == 0) {
1398 : 0 : PMD_INIT_LOG(ERR, "Value nb_desc beyond available hw cq qsize");
1399 : 0 : return -EINVAL;
1400 : : }
1401 : :
1402 : :
1403 : : /* Check rx_free_thresh upper bound */
1404 [ # # ]: 0 : rx_free_thresh = (uint16_t)((rx_conf->rx_free_thresh) ?
1405 : : rx_conf->rx_free_thresh :
1406 : : NICVF_DEFAULT_RX_FREE_THRESH);
1407 [ # # ]: 0 : if (rx_free_thresh > NICVF_MAX_RX_FREE_THRESH ||
1408 [ # # ]: 0 : rx_free_thresh >= nb_desc * .75) {
1409 : 0 : PMD_INIT_LOG(ERR, "rx_free_thresh greater than expected %d",
1410 : : rx_free_thresh);
1411 : 0 : return -EINVAL;
1412 : : }
1413 : :
1414 : : /* Free memory prior to re-allocation if needed */
1415 [ # # # # ]: 0 : if (dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
1416 : 0 : PMD_RX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
1417 : : nicvf_netdev_qidx(nic, qidx));
1418 : 0 : nicvf_dev_rx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
1419 [ # # ]: 0 : dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
1420 : : }
1421 : :
1422 : : /* Allocate rxq memory */
1423 : 0 : rxq = rte_zmalloc_socket("ethdev rx queue", sizeof(struct nicvf_rxq),
1424 : 0 : RTE_CACHE_LINE_SIZE, nic->node);
1425 [ # # ]: 0 : if (rxq == NULL) {
1426 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate rxq=%d",
1427 : : nicvf_netdev_qidx(nic, qidx));
1428 : 0 : return -ENOMEM;
1429 : : }
1430 : :
1431 : 0 : rxq->nic = nic;
1432 : 0 : rxq->pool = mp;
1433 : 0 : rxq->queue_id = qidx;
1434 : 0 : rxq->port_id = dev->data->port_id;
1435 : 0 : rxq->rx_free_thresh = rx_free_thresh;
1436 : 0 : rxq->rx_drop_en = rx_conf->rx_drop_en;
1437 [ # # ]: 0 : rxq->cq_status = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_STATUS;
1438 : 0 : rxq->cq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_DOOR;
1439 [ # # ]: 0 : rxq->precharge_cnt = 0;
1440 : :
1441 [ # # ]: 0 : if (nicvf_hw_cap(nic) & NICVF_CAP_CQE_RX2)
1442 : 0 : rxq->rbptr_offset = NICVF_CQE_RX2_RBPTR_WORD;
1443 : : else
1444 : 0 : rxq->rbptr_offset = NICVF_CQE_RBPTR_WORD;
1445 : :
1446 [ # # ]: 0 : dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = rxq;
1447 : :
1448 : 0 : nicvf_rxq_mbuf_setup(rxq);
1449 : :
1450 : : /* Alloc completion queue */
1451 [ # # ]: 0 : if (nicvf_qset_cq_alloc(dev, nic, rxq, rxq->queue_id, nb_desc)) {
1452 : 0 : PMD_INIT_LOG(ERR, "failed to allocate cq %u", rxq->queue_id);
1453 : 0 : nicvf_dev_rx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
1454 : 0 : return -ENOMEM;
1455 : : }
1456 : :
1457 : : nicvf_rx_queue_reset(rxq);
1458 : :
1459 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1460 [ # # ]: 0 : PMD_INIT_LOG(DEBUG, "[%d] rxq=%p pool=%s nb_desc=(%d/%d)"
1461 : : " phy=0x%" PRIx64 " offloads=0x%" PRIx64,
1462 : : nicvf_netdev_qidx(nic, qidx), rxq, mp->name, nb_desc,
1463 : : rte_mempool_avail_count(mp), rxq->phys, offloads);
1464 : :
1465 [ # # ]: 0 : dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1466 : : RTE_ETH_QUEUE_STATE_STOPPED;
1467 : 0 : return 0;
1468 : : }
1469 : :
1470 : : static int
1471 : 0 : nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1472 : : {
1473 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1474 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1475 : :
1476 : 0 : PMD_INIT_FUNC_TRACE();
1477 : :
1478 : : /* Autonegotiation may be disabled */
1479 : : dev_info->speed_capa = RTE_ETH_LINK_SPEED_FIXED;
1480 [ # # ]: 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_10M | RTE_ETH_LINK_SPEED_100M |
1481 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
1482 [ # # ]: 0 : if (nicvf_hw_version(nic) != PCI_SUB_DEVICE_ID_CN81XX_NICVF)
1483 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_40G;
1484 : :
1485 : 0 : dev_info->min_rx_bufsize = RTE_ETHER_MIN_MTU;
1486 : 0 : dev_info->max_rx_pktlen = NIC_HW_MAX_MTU + RTE_ETHER_HDR_LEN;
1487 : 0 : dev_info->max_rx_queues =
1488 : : (uint16_t)MAX_RCV_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
1489 : 0 : dev_info->max_tx_queues =
1490 : : (uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
1491 : 0 : dev_info->max_mac_addrs = 1;
1492 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
1493 : :
1494 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen -
1495 : : (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN);
1496 : 0 : dev_info->min_mtu = dev_info->min_rx_bufsize - NIC_HW_L2_OVERHEAD;
1497 : :
1498 : 0 : dev_info->rx_offload_capa = NICVF_RX_OFFLOAD_CAPA;
1499 : 0 : dev_info->tx_offload_capa = NICVF_TX_OFFLOAD_CAPA;
1500 : 0 : dev_info->rx_queue_offload_capa = NICVF_RX_OFFLOAD_CAPA;
1501 : 0 : dev_info->tx_queue_offload_capa = NICVF_TX_OFFLOAD_CAPA;
1502 : :
1503 : 0 : dev_info->reta_size = nic->rss_info.rss_size;
1504 : 0 : dev_info->hash_key_size = RSS_HASH_KEY_BYTE_SIZE;
1505 [ # # ]: 0 : dev_info->flow_type_rss_offloads = NICVF_RSS_OFFLOAD_PASS1;
1506 [ # # ]: 0 : if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING)
1507 : 0 : dev_info->flow_type_rss_offloads |= NICVF_RSS_OFFLOAD_TUNNEL;
1508 : :
1509 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1510 : : .rx_free_thresh = NICVF_DEFAULT_RX_FREE_THRESH,
1511 : : .rx_drop_en = 0,
1512 : : };
1513 : :
1514 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1515 : : .tx_free_thresh = NICVF_DEFAULT_TX_FREE_THRESH,
1516 : : .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE |
1517 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1518 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1519 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM,
1520 : : };
1521 : :
1522 : 0 : return 0;
1523 : : }
1524 : :
1525 : : static nicvf_iova_addr_t
1526 [ # # ]: 0 : rbdr_rte_mempool_get(void *dev, void *opaque)
1527 : : {
1528 : : uint16_t qidx;
1529 : : uintptr_t mbuf;
1530 : : struct nicvf_rxq *rxq;
1531 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)dev;
1532 : : struct nicvf *nic = (struct nicvf *)opaque;
1533 : : uint16_t rx_start, rx_end;
1534 : :
1535 : : /* Get queue ranges for this VF */
1536 : : nicvf_rx_range(eth_dev, nic, &rx_start, &rx_end);
1537 : :
1538 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
1539 : 0 : rxq = eth_dev->data->rx_queues[qidx];
1540 : : /* Maintain equal buffer count across all pools */
1541 [ # # ]: 0 : if (rxq->precharge_cnt >= rxq->qlen_mask)
1542 : 0 : continue;
1543 : 0 : rxq->precharge_cnt++;
1544 : 0 : mbuf = (uintptr_t)rte_pktmbuf_alloc(rxq->pool);
1545 [ # # ]: 0 : if (mbuf)
1546 : 0 : return nicvf_mbuff_virt2phy(mbuf, rxq->mbuf_phys_off);
1547 : : }
1548 : : return 0;
1549 : : }
1550 : :
1551 : : static int
1552 : 0 : nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
1553 : : {
1554 : : int ret;
1555 : : uint16_t qidx, data_off;
1556 : : uint32_t total_rxq_desc, nb_rbdr_desc, exp_buffs;
1557 : : uint64_t mbuf_phys_off = 0;
1558 : : struct nicvf_rxq *rxq;
1559 : : struct rte_mbuf *mbuf;
1560 : : uint16_t rx_start, rx_end;
1561 : : uint16_t tx_start, tx_end;
1562 : : int mask;
1563 : :
1564 : 0 : PMD_INIT_FUNC_TRACE();
1565 : :
1566 : : /* Userspace process exited without proper shutdown in last run */
1567 [ # # ]: 0 : if (nicvf_qset_rbdr_active(nic, 0))
1568 : 0 : nicvf_vf_stop(dev, nic, false);
1569 : :
1570 : : /* Get queue ranges for this VF */
1571 : : nicvf_rx_range(dev, nic, &rx_start, &rx_end);
1572 : :
1573 : : /*
1574 : : * Thunderx nicvf PMD can support more than one pool per port only when
1575 : : * 1) Data payload size is same across all the pools in given port
1576 : : * AND
1577 : : * 2) All mbuffs in the pools are from the same hugepage
1578 : : * AND
1579 : : * 3) Mbuff metadata size is same across all the pools in given port
1580 : : *
1581 : : * This is to support existing application that uses multiple pool/port.
1582 : : * But, the purpose of using multipool for QoS will not be addressed.
1583 : : *
1584 : : */
1585 : :
1586 : : /* Validate mempool attributes */
1587 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
1588 : 0 : rxq = dev->data->rx_queues[qidx];
1589 : 0 : rxq->mbuf_phys_off = nicvf_mempool_phy_offset(rxq->pool);
1590 : 0 : mbuf = rte_pktmbuf_alloc(rxq->pool);
1591 [ # # ]: 0 : if (mbuf == NULL) {
1592 : 0 : PMD_INIT_LOG(ERR, "Failed allocate mbuf VF%d qid=%d "
1593 : : "pool=%s",
1594 : : nic->vf_id, qidx, rxq->pool->name);
1595 : 0 : return -ENOMEM;
1596 : : }
1597 : : data_off = nicvf_mbuff_meta_length(mbuf);
1598 : 0 : data_off += RTE_PKTMBUF_HEADROOM;
1599 : 0 : rte_pktmbuf_free(mbuf);
1600 : :
1601 [ # # ]: 0 : if (data_off % RTE_CACHE_LINE_SIZE) {
1602 : 0 : PMD_INIT_LOG(ERR, "%s: unaligned data_off=%d delta=%d",
1603 : : rxq->pool->name, data_off,
1604 : : data_off % RTE_CACHE_LINE_SIZE);
1605 : 0 : return -EINVAL;
1606 : : }
1607 : 0 : rxq->mbuf_phys_off -= data_off;
1608 : 0 : rxq->mbuf_phys_off -= nic->skip_bytes;
1609 : :
1610 [ # # ]: 0 : if (mbuf_phys_off == 0)
1611 : : mbuf_phys_off = rxq->mbuf_phys_off;
1612 [ # # ]: 0 : if (mbuf_phys_off != rxq->mbuf_phys_off) {
1613 : 0 : PMD_INIT_LOG(ERR, "pool params not same,%s VF%d %"
1614 : : PRIx64, rxq->pool->name, nic->vf_id,
1615 : : mbuf_phys_off);
1616 : 0 : return -EINVAL;
1617 : : }
1618 : : }
1619 : :
1620 : : /* Check the level of buffers in the pool */
1621 : : total_rxq_desc = 0;
1622 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
1623 : 0 : rxq = dev->data->rx_queues[qidx];
1624 : : /* Count total numbers of rxq descs */
1625 : 0 : total_rxq_desc += rxq->qlen_mask + 1;
1626 : 0 : exp_buffs = RTE_MEMPOOL_CACHE_MAX_SIZE + rxq->rx_free_thresh;
1627 : 0 : exp_buffs *= dev->data->nb_rx_queues;
1628 [ # # ]: 0 : if (rte_mempool_avail_count(rxq->pool) < exp_buffs) {
1629 : 0 : PMD_INIT_LOG(ERR, "Buff shortage in pool=%s (%d/%d)",
1630 : : rxq->pool->name,
1631 : : rte_mempool_avail_count(rxq->pool),
1632 : : exp_buffs);
1633 : 0 : return -ENOENT;
1634 : : }
1635 : : }
1636 : :
1637 : : /* Check RBDR desc overflow */
1638 : 0 : ret = nicvf_qsize_rbdr_roundup(total_rxq_desc);
1639 [ # # ]: 0 : if (ret == 0) {
1640 : 0 : PMD_INIT_LOG(ERR, "Reached RBDR desc limit, reduce nr desc "
1641 : : "VF%d", nic->vf_id);
1642 : 0 : return -ENOMEM;
1643 : : }
1644 : :
1645 : : /* Enable qset */
1646 : 0 : ret = nicvf_qset_config(nic);
1647 [ # # ]: 0 : if (ret) {
1648 : 0 : PMD_INIT_LOG(ERR, "Failed to enable qset %d VF%d", ret,
1649 : : nic->vf_id);
1650 : 0 : return ret;
1651 : : }
1652 : :
1653 : : /* Allocate RBDR and RBDR ring desc */
1654 : 0 : nb_rbdr_desc = nicvf_qsize_rbdr_roundup(total_rxq_desc);
1655 : 0 : ret = nicvf_qset_rbdr_alloc(dev, nic, nb_rbdr_desc, rbdrsz);
1656 [ # # ]: 0 : if (ret) {
1657 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for rbdr alloc "
1658 : : "VF%d", nic->vf_id);
1659 : 0 : goto qset_reclaim;
1660 : : }
1661 : :
1662 : : /* Enable and configure RBDR registers */
1663 : 0 : ret = nicvf_qset_rbdr_config(nic, 0);
1664 [ # # ]: 0 : if (ret) {
1665 : 0 : PMD_INIT_LOG(ERR, "Failed to configure rbdr %d VF%d", ret,
1666 : : nic->vf_id);
1667 : 0 : goto qset_rbdr_free;
1668 : : }
1669 : :
1670 : : /* Fill rte_mempool buffers in RBDR pool and precharge it */
1671 : 0 : ret = nicvf_qset_rbdr_precharge(dev, nic, 0, rbdr_rte_mempool_get,
1672 : : total_rxq_desc);
1673 [ # # ]: 0 : if (ret) {
1674 : 0 : PMD_INIT_LOG(ERR, "Failed to fill rbdr %d VF%d", ret,
1675 : : nic->vf_id);
1676 : 0 : goto qset_rbdr_reclaim;
1677 : : }
1678 : :
1679 : 0 : PMD_DRV_LOG(INFO, "Filled %d out of %d entries in RBDR VF%d",
1680 : : nic->rbdr->tail, nb_rbdr_desc, nic->vf_id);
1681 : :
1682 : : /* Configure VLAN Strip */
1683 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
1684 : : RTE_ETH_VLAN_EXTEND_MASK;
1685 : 0 : ret = nicvf_vlan_offload_config(dev, mask);
1686 : :
1687 : : /* Based on the packet type(IPv4 or IPv6), the nicvf HW aligns L3 data
1688 : : * to the 64bit memory address.
1689 : : * The alignment creates a hole in mbuf(between the end of headroom and
1690 : : * packet data start). The new revision of the HW provides an option to
1691 : : * disable the L3 alignment feature and make mbuf layout looks
1692 : : * more like other NICs. For better application compatibility, disabling
1693 : : * l3 alignment feature on the hardware revisions it supports
1694 : : */
1695 : 0 : nicvf_apad_config(nic, false);
1696 : :
1697 : : /* Get queue ranges for this VF */
1698 : : nicvf_tx_range(dev, nic, &tx_start, &tx_end);
1699 : :
1700 : : /* Configure TX queues */
1701 [ # # ]: 0 : for (qidx = tx_start; qidx <= tx_end; qidx++) {
1702 : 0 : ret = nicvf_vf_start_tx_queue(dev, nic,
1703 : : qidx % MAX_SND_QUEUES_PER_QS);
1704 [ # # ]: 0 : if (ret)
1705 : 0 : goto start_txq_error;
1706 : : }
1707 : :
1708 : : /* Configure RX queues */
1709 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++) {
1710 : 0 : ret = nicvf_vf_start_rx_queue(dev, nic,
1711 : : qidx % MAX_RCV_QUEUES_PER_QS);
1712 [ # # ]: 0 : if (ret)
1713 : 0 : goto start_rxq_error;
1714 : : }
1715 : :
1716 [ # # ]: 0 : if (!nic->sqs_mode) {
1717 : : /* Configure CPI algorithm */
1718 : 0 : ret = nicvf_configure_cpi(dev);
1719 [ # # ]: 0 : if (ret)
1720 : 0 : goto start_txq_error;
1721 : :
1722 : 0 : ret = nicvf_mbox_get_rss_size(nic);
1723 [ # # ]: 0 : if (ret) {
1724 : 0 : PMD_INIT_LOG(ERR, "Failed to get rss table size");
1725 : 0 : goto qset_rss_error;
1726 : : }
1727 : :
1728 : : /* Configure RSS */
1729 : 0 : ret = nicvf_configure_rss(dev);
1730 [ # # ]: 0 : if (ret)
1731 : 0 : goto qset_rss_error;
1732 : : }
1733 : :
1734 : : /* Done; Let PF make the BGX's RX and TX switches to ON position */
1735 : 0 : nicvf_mbox_cfg_done(nic);
1736 : 0 : return 0;
1737 : :
1738 : 0 : qset_rss_error:
1739 : 0 : nicvf_rss_term(nic);
1740 : 0 : start_rxq_error:
1741 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++)
1742 : 0 : nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
1743 : 0 : start_txq_error:
1744 [ # # ]: 0 : for (qidx = tx_start; qidx <= tx_end; qidx++)
1745 : 0 : nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
1746 : 0 : qset_rbdr_reclaim:
1747 : 0 : nicvf_qset_rbdr_reclaim(nic, 0);
1748 : 0 : nicvf_rbdr_release_mbufs(dev, nic);
1749 : 0 : qset_rbdr_free:
1750 [ # # ]: 0 : if (nic->rbdr) {
1751 : 0 : rte_free(nic->rbdr);
1752 : 0 : nic->rbdr = NULL;
1753 : : }
1754 : 0 : qset_reclaim:
1755 : 0 : nicvf_qset_reclaim(nic);
1756 : 0 : return ret;
1757 : : }
1758 : :
1759 : : static int
1760 : 0 : nicvf_dev_start(struct rte_eth_dev *dev)
1761 : : {
1762 : : uint16_t qidx;
1763 : : int ret;
1764 : : size_t i;
1765 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1766 : : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
1767 : : uint16_t mtu;
1768 : : uint32_t buffsz = 0, rbdrsz = 0;
1769 : : struct rte_pktmbuf_pool_private *mbp_priv;
1770 : : struct nicvf_rxq *rxq;
1771 : :
1772 : 0 : PMD_INIT_FUNC_TRACE();
1773 : :
1774 : : /* This function must be called for a primary device */
1775 [ # # ]: 0 : assert_primary(nic);
1776 : :
1777 : : /* Validate RBDR buff size */
1778 [ # # ]: 0 : for (qidx = 0; qidx < dev->data->nb_rx_queues; qidx++) {
1779 : 0 : rxq = dev->data->rx_queues[qidx];
1780 [ # # ]: 0 : mbp_priv = rte_mempool_get_priv(rxq->pool);
1781 : 0 : buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1782 [ # # ]: 0 : if (buffsz % 128) {
1783 : 0 : PMD_INIT_LOG(ERR, "rxbuf size must be multiply of 128");
1784 : 0 : return -EINVAL;
1785 : : }
1786 [ # # ]: 0 : if (rbdrsz == 0)
1787 : : rbdrsz = buffsz;
1788 [ # # ]: 0 : if (rbdrsz != buffsz) {
1789 : 0 : PMD_INIT_LOG(ERR, "buffsz not same, qidx=%d (%d/%d)",
1790 : : qidx, rbdrsz, buffsz);
1791 : 0 : return -EINVAL;
1792 : : }
1793 : : }
1794 : :
1795 : : /* Configure loopback */
1796 : 0 : ret = nicvf_loopback_config(nic, dev->data->dev_conf.lpbk_mode);
1797 [ # # ]: 0 : if (ret) {
1798 : 0 : PMD_INIT_LOG(ERR, "Failed to configure loopback %d", ret);
1799 : 0 : return ret;
1800 : : }
1801 : :
1802 : : /* Reset all statistics counters attached to this port */
1803 : 0 : ret = nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, 0xFFFF, 0xFFFF);
1804 [ # # ]: 0 : if (ret) {
1805 : 0 : PMD_INIT_LOG(ERR, "Failed to reset stat counters %d", ret);
1806 : 0 : return ret;
1807 : : }
1808 : :
1809 : : /* Setup scatter mode if needed by jumbo */
1810 [ # # ]: 0 : if (dev->data->mtu + (uint32_t)NIC_HW_L2_OVERHEAD + 2 * VLAN_TAG_SIZE > buffsz)
1811 : 0 : dev->data->scattered_rx = 1;
1812 [ # # ]: 0 : if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) != 0)
1813 : 0 : dev->data->scattered_rx = 1;
1814 : :
1815 : : /* Setup MTU */
1816 : : mtu = dev->data->mtu;
1817 : :
1818 [ # # ]: 0 : if (nicvf_dev_set_mtu(dev, mtu)) {
1819 : 0 : PMD_INIT_LOG(ERR, "Failed to set default mtu size");
1820 : 0 : return -EBUSY;
1821 : : }
1822 : :
1823 : : /* Apply new link configurations if changed */
1824 : 0 : ret = nicvf_apply_link_speed(dev);
1825 [ # # ]: 0 : if (ret) {
1826 : 0 : PMD_INIT_LOG(ERR, "Failed to set link configuration");
1827 : 0 : return ret;
1828 : : }
1829 : :
1830 : 0 : ret = nicvf_vf_start(dev, nic, rbdrsz);
1831 [ # # ]: 0 : if (ret != 0)
1832 : : return ret;
1833 : :
1834 [ # # ]: 0 : for (i = 0; i < nic->sqs_count; i++) {
1835 [ # # ]: 0 : assert(nic->snicvf[i]);
1836 : :
1837 : 0 : ret = nicvf_vf_start(dev, nic->snicvf[i], rbdrsz);
1838 [ # # ]: 0 : if (ret != 0)
1839 : 0 : return ret;
1840 : : }
1841 : :
1842 : : /* Configure callbacks based on offloads */
1843 : 0 : nicvf_set_tx_function(dev);
1844 : 0 : nicvf_set_rx_function(dev);
1845 : :
1846 : 0 : return 0;
1847 : : }
1848 : :
1849 : : static void
1850 : 0 : nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup)
1851 : : {
1852 : : size_t i;
1853 : : int ret;
1854 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1855 : :
1856 : 0 : PMD_INIT_FUNC_TRACE();
1857 : 0 : dev->data->dev_started = 0;
1858 : :
1859 : : /* Teardown secondary vf first */
1860 [ # # ]: 0 : for (i = 0; i < nic->sqs_count; i++) {
1861 [ # # ]: 0 : if (!nic->snicvf[i])
1862 : 0 : continue;
1863 : :
1864 : 0 : nicvf_vf_stop(dev, nic->snicvf[i], cleanup);
1865 : : }
1866 : :
1867 : : /* Stop the primary VF now */
1868 : 0 : nicvf_vf_stop(dev, nic, cleanup);
1869 : :
1870 : : /* Disable loopback */
1871 : 0 : ret = nicvf_loopback_config(nic, 0);
1872 [ # # ]: 0 : if (ret)
1873 : 0 : PMD_INIT_LOG(ERR, "Failed to disable loopback %d", ret);
1874 : :
1875 : : /* Reclaim CPI configuration */
1876 : 0 : ret = nicvf_mbox_config_cpi(nic, 0);
1877 [ # # ]: 0 : if (ret)
1878 : 0 : PMD_INIT_LOG(ERR, "Failed to reclaim CPI config %d", ret);
1879 : 0 : }
1880 : :
1881 : : static int
1882 : 0 : nicvf_dev_stop(struct rte_eth_dev *dev)
1883 : : {
1884 : 0 : PMD_INIT_FUNC_TRACE();
1885 : :
1886 : 0 : nicvf_dev_stop_cleanup(dev, false);
1887 : :
1888 : 0 : return 0;
1889 : : }
1890 : :
1891 : : static void
1892 : 0 : nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic, bool cleanup)
1893 : : {
1894 : : int ret;
1895 : : uint16_t qidx;
1896 : : uint16_t tx_start, tx_end;
1897 : : uint16_t rx_start, rx_end;
1898 : :
1899 : 0 : PMD_INIT_FUNC_TRACE();
1900 : :
1901 [ # # ]: 0 : if (cleanup) {
1902 : : /* Let PF make the BGX's RX and TX switches to OFF position */
1903 : 0 : nicvf_mbox_shutdown(nic);
1904 : : }
1905 : :
1906 : : /* Disable VLAN Strip */
1907 : 0 : nicvf_vlan_hw_strip(nic, 0);
1908 : :
1909 : : /* Get queue ranges for this VF */
1910 : : nicvf_tx_range(dev, nic, &tx_start, &tx_end);
1911 : :
1912 [ # # ]: 0 : for (qidx = tx_start; qidx <= tx_end; qidx++)
1913 : 0 : nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
1914 : :
1915 : : /* Get queue ranges for this VF */
1916 : : nicvf_rx_range(dev, nic, &rx_start, &rx_end);
1917 : :
1918 : : /* Reclaim rq */
1919 [ # # ]: 0 : for (qidx = rx_start; qidx <= rx_end; qidx++)
1920 : 0 : nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
1921 : :
1922 : : /* Reclaim RBDR */
1923 : 0 : ret = nicvf_qset_rbdr_reclaim(nic, 0);
1924 [ # # ]: 0 : if (ret)
1925 : 0 : PMD_INIT_LOG(ERR, "Failed to reclaim RBDR %d", ret);
1926 : :
1927 : : /* Move all charged buffers in RBDR back to pool */
1928 [ # # ]: 0 : if (nic->rbdr != NULL)
1929 : 0 : nicvf_rbdr_release_mbufs(dev, nic);
1930 : :
1931 : : /* Disable qset */
1932 : 0 : ret = nicvf_qset_reclaim(nic);
1933 [ # # ]: 0 : if (ret)
1934 : 0 : PMD_INIT_LOG(ERR, "Failed to disable qset %d", ret);
1935 : :
1936 : : /* Disable all interrupts */
1937 : : nicvf_disable_all_interrupts(nic);
1938 : :
1939 : : /* Free RBDR SW structure */
1940 [ # # ]: 0 : if (nic->rbdr) {
1941 : 0 : rte_free(nic->rbdr);
1942 : 0 : nic->rbdr = NULL;
1943 : : }
1944 : 0 : }
1945 : :
1946 : : static int
1947 : 0 : nicvf_dev_close(struct rte_eth_dev *dev)
1948 : : {
1949 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1950 : :
1951 : 0 : PMD_INIT_FUNC_TRACE();
1952 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1953 : : return 0;
1954 : :
1955 : 0 : nicvf_dev_stop_cleanup(dev, true);
1956 : : nicvf_periodic_alarm_stop(nicvf_interrupt, dev);
1957 : : nicvf_periodic_alarm_stop(nicvf_vf_interrupt, nic);
1958 : :
1959 : 0 : rte_intr_instance_free(nic->intr_handle);
1960 : :
1961 : 0 : return 0;
1962 : : }
1963 : :
1964 : : static int
1965 : 0 : nicvf_request_sqs(struct nicvf *nic)
1966 : : {
1967 : : size_t i;
1968 : :
1969 [ # # ]: 0 : assert_primary(nic);
1970 [ # # ]: 0 : assert(nic->sqs_count > 0);
1971 [ # # ]: 0 : assert(nic->sqs_count <= MAX_SQS_PER_VF);
1972 : :
1973 : : /* Set no of Rx/Tx queues in each of the SQsets */
1974 [ # # ]: 0 : for (i = 0; i < nic->sqs_count; i++) {
1975 [ # # ]: 0 : if (nicvf_svf_empty())
1976 : 0 : rte_panic("Cannot assign sufficient number of "
1977 : : "secondary queues to primary VF%" PRIu8 "\n",
1978 : : nic->vf_id);
1979 : :
1980 : 0 : nic->snicvf[i] = nicvf_svf_pop();
1981 : 0 : nic->snicvf[i]->sqs_id = i;
1982 : : }
1983 : :
1984 : 0 : return nicvf_mbox_request_sqs(nic);
1985 : : }
1986 : :
1987 : : static int
1988 : 0 : nicvf_dev_configure(struct rte_eth_dev *dev)
1989 : : {
1990 : 0 : struct rte_eth_dev_data *data = dev->data;
1991 : : struct rte_eth_conf *conf = &data->dev_conf;
1992 : : struct rte_eth_rxmode *rxmode = &conf->rxmode;
1993 : : struct rte_eth_txmode *txmode = &conf->txmode;
1994 : : struct nicvf *nic = nicvf_pmd_priv(dev);
1995 : : uint8_t cqcount;
1996 : :
1997 : 0 : PMD_INIT_FUNC_TRACE();
1998 : :
1999 [ # # ]: 0 : if (rxmode->mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
2000 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
2001 : :
2002 [ # # ]: 0 : if (!rte_eal_has_hugepages()) {
2003 : 0 : PMD_INIT_LOG(INFO, "Huge page is not configured");
2004 : 0 : return -EINVAL;
2005 : : }
2006 : :
2007 [ # # ]: 0 : if (txmode->mq_mode) {
2008 : 0 : PMD_INIT_LOG(INFO, "Tx mq_mode DCB or VMDq not supported");
2009 : 0 : return -EINVAL;
2010 : : }
2011 : :
2012 [ # # ]: 0 : if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE &&
2013 : : rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
2014 : 0 : PMD_INIT_LOG(INFO, "Unsupported rx qmode %d", rxmode->mq_mode);
2015 : 0 : return -EINVAL;
2016 : : }
2017 : :
2018 [ # # ]: 0 : if (conf->dcb_capability_en) {
2019 : 0 : PMD_INIT_LOG(INFO, "DCB enable not supported");
2020 : 0 : return -EINVAL;
2021 : : }
2022 : :
2023 [ # # ]: 0 : assert_primary(nic);
2024 : : NICVF_STATIC_ASSERT(MAX_RCV_QUEUES_PER_QS == MAX_SND_QUEUES_PER_QS);
2025 : 0 : cqcount = RTE_MAX(data->nb_tx_queues, data->nb_rx_queues);
2026 [ # # ]: 0 : if (cqcount > MAX_RCV_QUEUES_PER_QS) {
2027 : 0 : nic->sqs_count = RTE_ALIGN_CEIL(cqcount, MAX_RCV_QUEUES_PER_QS);
2028 : 0 : nic->sqs_count = (nic->sqs_count / MAX_RCV_QUEUES_PER_QS) - 1;
2029 : : } else {
2030 : 0 : nic->sqs_count = 0;
2031 : : }
2032 : :
2033 [ # # ]: 0 : assert(nic->sqs_count <= MAX_SQS_PER_VF);
2034 : :
2035 [ # # ]: 0 : if (nic->sqs_count > 0) {
2036 [ # # ]: 0 : if (nicvf_request_sqs(nic)) {
2037 : 0 : rte_panic("Cannot assign sufficient number of "
2038 : : "secondary queues to PORT%d VF%" PRIu8 "\n",
2039 : : dev->data->port_id, nic->vf_id);
2040 : : }
2041 : : }
2042 : :
2043 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
2044 : 0 : nic->offload_cksum = 1;
2045 : :
2046 : 0 : PMD_INIT_LOG(DEBUG, "Configured ethdev port%d hwcap=0x%" PRIx64,
2047 : : dev->data->port_id, nicvf_hw_cap(nic));
2048 : :
2049 : 0 : return 0;
2050 : : }
2051 : :
2052 : : static int
2053 : 0 : nicvf_dev_set_link_up(struct rte_eth_dev *dev)
2054 : : {
2055 : : struct nicvf *nic = nicvf_pmd_priv(dev);
2056 : : int rc, i;
2057 : :
2058 : 0 : rc = nicvf_mbox_set_link_up_down(nic, true);
2059 [ # # ]: 0 : if (rc)
2060 : 0 : goto done;
2061 : :
2062 : : /* Start tx queues */
2063 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2064 : 0 : nicvf_dev_tx_queue_start(dev, i);
2065 : :
2066 : 0 : done:
2067 : 0 : return rc;
2068 : : }
2069 : :
2070 : : static int
2071 : 0 : nicvf_dev_set_link_down(struct rte_eth_dev *dev)
2072 : : {
2073 : : struct nicvf *nic = nicvf_pmd_priv(dev);
2074 : : int i;
2075 : :
2076 : : /* Stop tx queues */
2077 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2078 : 0 : nicvf_dev_tx_queue_stop(dev, i);
2079 : :
2080 : 0 : return nicvf_mbox_set_link_up_down(nic, false);
2081 : : }
2082 : :
2083 : : /* Initialize and register driver with DPDK Application */
2084 : : static const struct eth_dev_ops nicvf_eth_dev_ops = {
2085 : : .dev_configure = nicvf_dev_configure,
2086 : : .dev_start = nicvf_dev_start,
2087 : : .dev_stop = nicvf_dev_stop,
2088 : : .link_update = nicvf_dev_link_update,
2089 : : .dev_close = nicvf_dev_close,
2090 : : .stats_get = nicvf_dev_stats_get,
2091 : : .stats_reset = nicvf_dev_stats_reset,
2092 : : .promiscuous_enable = nicvf_dev_promisc_enable,
2093 : : .dev_infos_get = nicvf_dev_info_get,
2094 : : .dev_supported_ptypes_get = nicvf_dev_supported_ptypes_get,
2095 : : .mtu_set = nicvf_dev_set_mtu,
2096 : : .vlan_offload_set = nicvf_vlan_offload_set,
2097 : : .reta_update = nicvf_dev_reta_update,
2098 : : .reta_query = nicvf_dev_reta_query,
2099 : : .rss_hash_update = nicvf_dev_rss_hash_update,
2100 : : .rss_hash_conf_get = nicvf_dev_rss_hash_conf_get,
2101 : : .rx_queue_start = nicvf_dev_rx_queue_start,
2102 : : .rx_queue_stop = nicvf_dev_rx_queue_stop,
2103 : : .tx_queue_start = nicvf_dev_tx_queue_start,
2104 : : .tx_queue_stop = nicvf_dev_tx_queue_stop,
2105 : : .rx_queue_setup = nicvf_dev_rx_queue_setup,
2106 : : .rx_queue_release = nicvf_dev_rx_queue_release,
2107 : : .tx_queue_setup = nicvf_dev_tx_queue_setup,
2108 : : .tx_queue_release = nicvf_dev_tx_queue_release,
2109 : : .dev_set_link_up = nicvf_dev_set_link_up,
2110 : : .dev_set_link_down = nicvf_dev_set_link_down,
2111 : : .get_reg = nicvf_dev_get_regs,
2112 : : };
2113 : :
2114 : : static int
2115 [ # # ]: 0 : nicvf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
2116 : : {
2117 : : struct rte_eth_rxmode *rxmode;
2118 : : struct nicvf *nic = nicvf_pmd_priv(dev);
2119 : : rxmode = &dev->data->dev_conf.rxmode;
2120 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
2121 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2122 : 0 : nicvf_vlan_hw_strip(nic, true);
2123 : : else
2124 : 0 : nicvf_vlan_hw_strip(nic, false);
2125 : : }
2126 : :
2127 : 0 : return 0;
2128 : : }
2129 : :
2130 : : static int
2131 : 0 : nicvf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2132 : : {
2133 : 0 : nicvf_vlan_offload_config(dev, mask);
2134 : :
2135 : 0 : return 0;
2136 : : }
2137 : :
2138 : : static inline int
2139 [ # # ]: 0 : nicvf_set_first_skip(struct rte_eth_dev *dev)
2140 : : {
2141 : : int bytes_to_skip = 0;
2142 : : int ret = 0;
2143 : : unsigned int i;
2144 : : struct rte_kvargs *kvlist;
2145 : : static const char *const skip[] = {
2146 : : SKIP_DATA_BYTES,
2147 : : NULL};
2148 : : struct nicvf *nic = nicvf_pmd_priv(dev);
2149 : :
2150 [ # # ]: 0 : if (!dev->device->devargs) {
2151 : 0 : nicvf_first_skip_config(nic, 0);
2152 : 0 : return ret;
2153 : : }
2154 : :
2155 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, skip);
2156 [ # # ]: 0 : if (!kvlist)
2157 : : return -EINVAL;
2158 : :
2159 [ # # ]: 0 : if (kvlist->count == 0)
2160 : 0 : goto exit;
2161 : :
2162 [ # # ]: 0 : for (i = 0; i != kvlist->count; ++i) {
2163 : : const struct rte_kvargs_pair *pair = &kvlist->pairs[i];
2164 : :
2165 [ # # ]: 0 : if (!strcmp(pair->key, SKIP_DATA_BYTES))
2166 : 0 : bytes_to_skip = atoi(pair->value);
2167 : : }
2168 : :
2169 : : /*128 bytes amounts to one cache line*/
2170 [ # # ]: 0 : if (bytes_to_skip >= 0 && bytes_to_skip < 128) {
2171 [ # # ]: 0 : if (!(bytes_to_skip % 8)) {
2172 : 0 : nicvf_first_skip_config(nic, (bytes_to_skip / 8));
2173 : 0 : nic->skip_bytes = bytes_to_skip;
2174 : 0 : goto kvlist_free;
2175 : : } else {
2176 : 0 : PMD_INIT_LOG(ERR, "skip_data_bytes should be multiple of 8");
2177 : : ret = -EINVAL;
2178 : 0 : goto exit;
2179 : : }
2180 : : } else {
2181 : 0 : PMD_INIT_LOG(ERR, "skip_data_bytes should be less than 128");
2182 : : ret = -EINVAL;
2183 : 0 : goto exit;
2184 : : }
2185 : 0 : exit:
2186 : 0 : nicvf_first_skip_config(nic, 0);
2187 : 0 : kvlist_free:
2188 : 0 : rte_kvargs_free(kvlist);
2189 : 0 : return ret;
2190 : : }
2191 : : static int
2192 : 0 : nicvf_eth_dev_uninit(struct rte_eth_dev *dev)
2193 : : {
2194 : 0 : PMD_INIT_FUNC_TRACE();
2195 : 0 : nicvf_dev_close(dev);
2196 : 0 : return 0;
2197 : : }
2198 : :
2199 : : static inline uint64_t ether_addr_to_u64(uint8_t *addr)
2200 : : {
2201 : : uint64_t u = 0;
2202 : : int i;
2203 : :
2204 [ # # ]: 0 : for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
2205 : 0 : u = u << 8 | addr[i];
2206 : :
2207 : : return u;
2208 : : }
2209 : :
2210 : : static int
2211 : 0 : nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
2212 : : {
2213 : : uint8_t dmac_ctrl_reg = 0;
2214 : : int ret;
2215 : : struct rte_pci_device *pci_dev;
2216 : : struct nicvf *nic = nicvf_pmd_priv(eth_dev);
2217 : :
2218 : 0 : PMD_INIT_FUNC_TRACE();
2219 : :
2220 : 0 : eth_dev->dev_ops = &nicvf_eth_dev_ops;
2221 : 0 : eth_dev->rx_queue_count = nicvf_dev_rx_queue_count;
2222 : :
2223 : : /* For secondary processes, the primary has done all the work */
2224 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2225 [ # # ]: 0 : if (nic) {
2226 : : /* Setup callbacks for secondary process */
2227 : 0 : nicvf_set_tx_function(eth_dev);
2228 : 0 : nicvf_set_rx_function(eth_dev);
2229 : 0 : return 0;
2230 : : } else {
2231 : : /* If nic == NULL than it is secondary function
2232 : : * so ethdev need to be released by caller */
2233 : : return ENOTSUP;
2234 : : }
2235 : : }
2236 : :
2237 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2238 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
2239 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2240 : :
2241 : 0 : nic->device_id = pci_dev->id.device_id;
2242 : 0 : nic->vendor_id = pci_dev->id.vendor_id;
2243 : 0 : nic->subsystem_device_id = pci_dev->id.subsystem_device_id;
2244 : 0 : nic->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2245 : :
2246 : 0 : PMD_INIT_LOG(DEBUG, "nicvf: device (%x:%x) " PCI_PRI_FMT,
2247 : : pci_dev->id.vendor_id, pci_dev->id.device_id,
2248 : : pci_dev->addr.domain, pci_dev->addr.bus,
2249 : : pci_dev->addr.devid, pci_dev->addr.function);
2250 : :
2251 : 0 : nic->reg_base = (uintptr_t)pci_dev->mem_resource[0].addr;
2252 [ # # ]: 0 : if (!nic->reg_base) {
2253 : 0 : PMD_INIT_LOG(ERR, "Failed to map BAR0");
2254 : : ret = -ENODEV;
2255 : 0 : goto fail;
2256 : : }
2257 : :
2258 : : /* Allocate interrupt instance */
2259 : 0 : nic->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
2260 [ # # ]: 0 : if (nic->intr_handle == NULL) {
2261 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate intr handle");
2262 : : ret = -ENODEV;
2263 : 0 : goto fail;
2264 : : }
2265 : :
2266 : : nicvf_disable_all_interrupts(nic);
2267 : :
2268 : : /* To read mbox messages */
2269 : : ret = nicvf_periodic_alarm_start(nicvf_vf_interrupt, nic);
2270 [ # # ]: 0 : if (ret) {
2271 : 0 : PMD_INIT_LOG(ERR, "Failed to start period alarm");
2272 : 0 : goto fail;
2273 : : }
2274 : :
2275 : : /* To poll link status change*/
2276 : : ret = nicvf_periodic_alarm_start(nicvf_interrupt, eth_dev);
2277 [ # # ]: 0 : if (ret) {
2278 : 0 : PMD_INIT_LOG(ERR, "Failed to start period alarm");
2279 : 0 : goto fail;
2280 : : }
2281 : :
2282 : 0 : ret = nicvf_mbox_check_pf_ready(nic);
2283 [ # # ]: 0 : if (ret) {
2284 : 0 : PMD_INIT_LOG(ERR, "Failed to get ready message from PF");
2285 : 0 : goto alarm_fail;
2286 : : } else {
2287 [ # # # # : 0 : PMD_INIT_LOG(INFO,
# # ]
2288 : : "node=%d vf=%d mode=%s sqs=%s loopback_supported=%s",
2289 : : nic->node, nic->vf_id,
2290 : : nic->tns_mode == NIC_TNS_MODE ? "tns" : "tns-bypass",
2291 : : nic->sqs_mode ? "true" : "false",
2292 : : nic->loopback_supported ? "true" : "false"
2293 : : );
2294 : : }
2295 : :
2296 : : /* To make sure RX DMAC register is set to default value (0x3) */
2297 : 0 : nicvf_mbox_reset_xcast(nic);
2298 : :
2299 : 0 : ret = nicvf_base_init(nic);
2300 [ # # ]: 0 : if (ret) {
2301 : 0 : PMD_INIT_LOG(ERR, "Failed to execute nicvf_base_init");
2302 : 0 : goto malloc_fail;
2303 : : }
2304 : :
2305 [ # # ]: 0 : if (nic->sqs_mode) {
2306 : : /* Push nic to stack of secondary vfs */
2307 : 0 : nicvf_svf_push(nic);
2308 : :
2309 : : /* Steal nic pointer from the device for further reuse */
2310 : 0 : eth_dev->data->dev_private = NULL;
2311 : :
2312 : : nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
2313 : :
2314 : : /* Detach port by returning positive error number */
2315 : 0 : return ENOTSUP;
2316 : : }
2317 : :
2318 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
2319 : : RTE_ETHER_ADDR_LEN, 0);
2320 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
2321 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for mac addr");
2322 : : ret = -ENOMEM;
2323 : 0 : goto alarm_fail;
2324 : : }
2325 [ # # ]: 0 : if (rte_is_zero_ether_addr((struct rte_ether_addr *)nic->mac_addr))
2326 : 0 : rte_eth_random_addr(&nic->mac_addr[0]);
2327 : :
2328 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)nic->mac_addr,
2329 : 0 : ð_dev->data->mac_addrs[0]);
2330 : :
2331 : 0 : ret = nicvf_mbox_set_mac_addr(nic, nic->mac_addr);
2332 [ # # ]: 0 : if (ret) {
2333 : 0 : PMD_INIT_LOG(ERR, "Failed to set mac addr");
2334 : 0 : goto malloc_fail;
2335 : : }
2336 : :
2337 : : /* set DMAC CTRL reg to allow MAC */
2338 : : dmac_ctrl_reg = BCAST_ACCEPT | BGX_MCAST_MODE(2) | CAM_ACCEPT;
2339 : 0 : ret = nicvf_mbox_set_xcast(nic, dmac_ctrl_reg,
2340 : : ether_addr_to_u64(nic->mac_addr));
2341 [ # # ]: 0 : if (ret) {
2342 : 0 : PMD_INIT_LOG(ERR, "Failed to set mac addr");
2343 : 0 : goto malloc_fail;
2344 : : }
2345 : :
2346 : 0 : ret = nicvf_set_first_skip(eth_dev);
2347 [ # # ]: 0 : if (ret) {
2348 : 0 : PMD_INIT_LOG(ERR, "Failed to configure first skip");
2349 : 0 : goto malloc_fail;
2350 : : }
2351 : 0 : PMD_INIT_LOG(INFO, "Port %d (%x:%x) mac=" RTE_ETHER_ADDR_PRT_FMT,
2352 : : eth_dev->data->port_id, nic->vendor_id, nic->device_id,
2353 : : nic->mac_addr[0], nic->mac_addr[1], nic->mac_addr[2],
2354 : : nic->mac_addr[3], nic->mac_addr[4], nic->mac_addr[5]);
2355 : :
2356 : 0 : return 0;
2357 : :
2358 : 0 : malloc_fail:
2359 : 0 : rte_free(eth_dev->data->mac_addrs);
2360 : 0 : eth_dev->data->mac_addrs = NULL;
2361 : 0 : alarm_fail:
2362 : : nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
2363 : : fail:
2364 : : return ret;
2365 : : }
2366 : :
2367 : : static const struct rte_pci_id pci_id_nicvf_map[] = {
2368 : : {
2369 : : .class_id = RTE_CLASS_ANY_ID,
2370 : : .vendor_id = PCI_VENDOR_ID_CAVIUM,
2371 : : .device_id = PCI_DEVICE_ID_THUNDERX_CN88XX_PASS1_NICVF,
2372 : : .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2373 : : .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS1_NICVF,
2374 : : },
2375 : : {
2376 : : .class_id = RTE_CLASS_ANY_ID,
2377 : : .vendor_id = PCI_VENDOR_ID_CAVIUM,
2378 : : .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2379 : : .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2380 : : .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS2_NICVF,
2381 : : },
2382 : : {
2383 : : .class_id = RTE_CLASS_ANY_ID,
2384 : : .vendor_id = PCI_VENDOR_ID_CAVIUM,
2385 : : .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2386 : : .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2387 : : .subsystem_device_id = PCI_SUB_DEVICE_ID_CN81XX_NICVF,
2388 : : },
2389 : : {
2390 : : .class_id = RTE_CLASS_ANY_ID,
2391 : : .vendor_id = PCI_VENDOR_ID_CAVIUM,
2392 : : .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2393 : : .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2394 : : .subsystem_device_id = PCI_SUB_DEVICE_ID_CN83XX_NICVF,
2395 : : },
2396 : : {
2397 : : .vendor_id = 0,
2398 : : },
2399 : : };
2400 : :
2401 : 0 : static int nicvf_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2402 : : struct rte_pci_device *pci_dev)
2403 : : {
2404 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct nicvf),
2405 : : nicvf_eth_dev_init);
2406 : : }
2407 : :
2408 : 0 : static int nicvf_eth_pci_remove(struct rte_pci_device *pci_dev)
2409 : : {
2410 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, nicvf_eth_dev_uninit);
2411 : : }
2412 : :
2413 : : static struct rte_pci_driver rte_nicvf_pmd = {
2414 : : .id_table = pci_id_nicvf_map,
2415 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_KEEP_MAPPED_RES |
2416 : : RTE_PCI_DRV_INTR_LSC,
2417 : : .probe = nicvf_eth_pci_probe,
2418 : : .remove = nicvf_eth_pci_remove,
2419 : : };
2420 : :
2421 : 253 : RTE_PMD_REGISTER_PCI(net_thunderx, rte_nicvf_pmd);
2422 : : RTE_PMD_REGISTER_PCI_TABLE(net_thunderx, pci_id_nicvf_map);
2423 : : RTE_PMD_REGISTER_KMOD_DEP(net_thunderx, "* igb_uio | uio_pci_generic | vfio-pci");
2424 : : RTE_PMD_REGISTER_PARAM_STRING(net_thunderx, SKIP_DATA_BYTES "=<int>");
|