Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2008-2017 Cisco Systems, Inc. All rights reserved.
3 : : * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 : : */
5 : :
6 : : #include <stdio.h>
7 : :
8 : : #include <sys/stat.h>
9 : : #include <sys/mman.h>
10 : : #include <fcntl.h>
11 : :
12 : : #include <rte_pci.h>
13 : : #include <bus_pci_driver.h>
14 : : #include <rte_memzone.h>
15 : : #include <rte_malloc.h>
16 : : #include <rte_mbuf.h>
17 : : #include <rte_string_fns.h>
18 : : #include <ethdev_driver.h>
19 : : #include <rte_geneve.h>
20 : :
21 : : #include "enic_compat.h"
22 : : #include "enic.h"
23 : : #include "enic_sriov.h"
24 : : #include "wq_enet_desc.h"
25 : : #include "rq_enet_desc.h"
26 : : #include "cq_enet_desc.h"
27 : : #include "vnic_enet.h"
28 : : #include "vnic_dev.h"
29 : : #include "vnic_wq.h"
30 : : #include "vnic_rq.h"
31 : : #include "vnic_cq.h"
32 : : #include "vnic_intr.h"
33 : : #include "vnic_nic.h"
34 : :
35 : : void
36 : 0 : enic_rxmbuf_queue_release(__rte_unused struct enic *enic, struct vnic_rq *rq)
37 : : {
38 : : uint16_t i;
39 : :
40 [ # # # # ]: 0 : if (!rq || !rq->mbuf_ring) {
41 : 0 : dev_debug(enic, "Pointer to rq or mbuf_ring is NULL");
42 : 0 : return;
43 : : }
44 : :
45 [ # # ]: 0 : for (i = 0; i < rq->ring.desc_count; i++) {
46 [ # # ]: 0 : if (rq->mbuf_ring[i]) {
47 : : rte_pktmbuf_free_seg(rq->mbuf_ring[i]);
48 : 0 : rq->mbuf_ring[i] = NULL;
49 : : }
50 : : }
51 : : }
52 : :
53 : 0 : void enic_free_wq_buf(struct rte_mbuf **buf)
54 : : {
55 : 0 : struct rte_mbuf *mbuf = *buf;
56 : :
57 : : rte_pktmbuf_free_seg(mbuf);
58 : 0 : *buf = NULL;
59 : 0 : }
60 : :
61 : 0 : static void enic_log_q_error(struct enic *enic)
62 : : {
63 : : unsigned int i;
64 : : uint32_t error_status;
65 : :
66 [ # # ]: 0 : for (i = 0; i < enic->wq_count; i++) {
67 : 0 : error_status = vnic_wq_error_status(&enic->wq[i]);
68 [ # # ]: 0 : if (error_status)
69 : 0 : dev_err(enic, "WQ[%d] error_status %d\n", i,
70 : : error_status);
71 : : }
72 : :
73 [ # # ]: 0 : for (i = 0; i < enic_vnic_rq_count(enic); i++) {
74 [ # # ]: 0 : if (!enic->rq[i].in_use)
75 : 0 : continue;
76 : 0 : error_status = vnic_rq_error_status(&enic->rq[i]);
77 [ # # ]: 0 : if (error_status)
78 : 0 : dev_err(enic, "RQ[%d] error_status %d\n", i,
79 : : error_status);
80 : : }
81 : 0 : }
82 : :
83 : : static void enic_clear_soft_stats(struct enic *enic)
84 : : {
85 : : struct enic_soft_stats *soft_stats = &enic->soft_stats;
86 : : rte_atomic64_clear(&soft_stats->rx_nombuf);
87 : : rte_atomic64_clear(&soft_stats->rx_packet_errors);
88 : : rte_atomic64_clear(&soft_stats->tx_oversized);
89 : : }
90 : :
91 : : static void enic_init_soft_stats(struct enic *enic)
92 : : {
93 : : struct enic_soft_stats *soft_stats = &enic->soft_stats;
94 : : rte_atomic64_init(&soft_stats->rx_nombuf);
95 : : rte_atomic64_init(&soft_stats->rx_packet_errors);
96 : : rte_atomic64_init(&soft_stats->tx_oversized);
97 : : enic_clear_soft_stats(enic);
98 : : }
99 : :
100 : 0 : int enic_dev_stats_clear(struct enic *enic)
101 : : {
102 : : int ret;
103 : :
104 : 0 : ret = vnic_dev_stats_clear(enic->vdev);
105 [ # # ]: 0 : if (ret != 0) {
106 : 0 : dev_err(enic, "Error in clearing stats\n");
107 : 0 : return ret;
108 : : }
109 : : enic_clear_soft_stats(enic);
110 : :
111 : 0 : return 0;
112 : : }
113 : :
114 : 0 : int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
115 : : {
116 : : struct vnic_stats *stats;
117 : : struct enic_soft_stats *soft_stats = &enic->soft_stats;
118 : : int64_t rx_truncated;
119 : : uint64_t rx_packet_errors;
120 : 0 : int ret = vnic_dev_stats_dump(enic->vdev, &stats);
121 : :
122 [ # # ]: 0 : if (ret) {
123 : 0 : dev_err(enic, "Error in getting stats\n");
124 : 0 : return ret;
125 : : }
126 : :
127 : : /* The number of truncated packets can only be calculated by
128 : : * subtracting a hardware counter from error packets received by
129 : : * the driver. Note: this causes transient inaccuracies in the
130 : : * ipackets count. Also, the length of truncated packets are
131 : : * counted in ibytes even though truncated packets are dropped
132 : : * which can make ibytes be slightly higher than it should be.
133 : : */
134 : 0 : rx_packet_errors = rte_atomic64_read(&soft_stats->rx_packet_errors);
135 : 0 : rx_truncated = rx_packet_errors - stats->rx.rx_errors;
136 : :
137 : 0 : r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;
138 : 0 : r_stats->opackets = stats->tx.tx_frames_ok;
139 : :
140 : 0 : r_stats->ibytes = stats->rx.rx_bytes_ok;
141 : 0 : r_stats->obytes = stats->tx.tx_bytes_ok;
142 : :
143 : 0 : r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop;
144 : 0 : r_stats->oerrors = stats->tx.tx_errors
145 : 0 : + rte_atomic64_read(&soft_stats->tx_oversized);
146 : :
147 : 0 : r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated;
148 : :
149 : 0 : r_stats->rx_nombuf = rte_atomic64_read(&soft_stats->rx_nombuf);
150 : 0 : return 0;
151 : : }
152 : :
153 : 0 : int enic_del_mac_address(struct enic *enic, int mac_index)
154 : : {
155 : 0 : struct rte_eth_dev *eth_dev = enic->rte_dev;
156 : 0 : uint8_t *mac_addr = eth_dev->data->mac_addrs[mac_index].addr_bytes;
157 : :
158 : 0 : return enic_dev_del_addr(enic, mac_addr);
159 : : }
160 : :
161 : 0 : int enic_set_mac_address(struct enic *enic, uint8_t *mac_addr)
162 : : {
163 : : int err;
164 : :
165 : 0 : err = enic_dev_add_addr(enic, mac_addr);
166 [ # # ]: 0 : if (err)
167 : 0 : dev_err(enic, "add mac addr failed\n");
168 : 0 : return err;
169 : : }
170 : :
171 : 0 : void enic_free_rq_buf(struct rte_mbuf **mbuf)
172 : : {
173 [ # # ]: 0 : if (*mbuf == NULL)
174 : : return;
175 : :
176 : 0 : rte_pktmbuf_free(*mbuf);
177 : 0 : *mbuf = NULL;
178 : : }
179 : :
180 : 0 : void enic_init_vnic_resources(struct enic *enic)
181 : : {
182 : : unsigned int error_interrupt_enable = 1;
183 : : unsigned int error_interrupt_offset = 0;
184 : : unsigned int rxq_interrupt_enable = 0;
185 : : unsigned int rxq_interrupt_offset = ENICPMD_RXQ_INTR_OFFSET;
186 : : unsigned int index = 0;
187 : : unsigned int cq_idx;
188 : : struct vnic_rq *data_rq;
189 : :
190 [ # # ]: 0 : if (enic->rte_dev->data->dev_conf.intr_conf.rxq)
191 : : rxq_interrupt_enable = 1;
192 : :
193 [ # # ]: 0 : for (index = 0; index < enic->rq_count; index++) {
194 : : cq_idx = enic_cq_rq(enic, enic_rte_rq_idx_to_sop_idx(index));
195 : :
196 : 0 : vnic_rq_init(&enic->rq[enic_rte_rq_idx_to_sop_idx(index)],
197 : : cq_idx,
198 : : error_interrupt_enable,
199 : : error_interrupt_offset);
200 : :
201 [ # # ]: 0 : data_rq = &enic->rq[enic_rte_rq_idx_to_data_idx(index, enic)];
202 [ # # ]: 0 : if (data_rq->in_use)
203 : 0 : vnic_rq_init(data_rq,
204 : : cq_idx,
205 : : error_interrupt_enable,
206 : : error_interrupt_offset);
207 : 0 : vnic_cq_init(&enic->cq[cq_idx],
208 : : 0 /* flow_control_enable */,
209 : : 1 /* color_enable */,
210 : : 0 /* cq_head */,
211 : : 0 /* cq_tail */,
212 : : 1 /* cq_tail_color */,
213 : : rxq_interrupt_enable,
214 : : 1 /* cq_entry_enable */,
215 : : 0 /* cq_message_enable */,
216 : : rxq_interrupt_offset,
217 : : 0 /* cq_message_addr */);
218 [ # # ]: 0 : if (rxq_interrupt_enable)
219 : 0 : rxq_interrupt_offset++;
220 : : }
221 : :
222 [ # # ]: 0 : for (index = 0; index < enic->wq_count; index++) {
223 : 0 : vnic_wq_init(&enic->wq[index],
224 : : enic_cq_wq(enic, index),
225 : : error_interrupt_enable,
226 : : error_interrupt_offset);
227 : : /* Compute unsupported ol flags for enic_prep_pkts() */
228 : 0 : enic->wq[index].tx_offload_notsup_mask =
229 : 0 : RTE_MBUF_F_TX_OFFLOAD_MASK ^ enic->tx_offload_mask;
230 : :
231 : : cq_idx = enic_cq_wq(enic, index);
232 : 0 : vnic_cq_init(&enic->cq[cq_idx],
233 : : 0 /* flow_control_enable */,
234 : : 1 /* color_enable */,
235 : : 0 /* cq_head */,
236 : : 0 /* cq_tail */,
237 : : 1 /* cq_tail_color */,
238 : : 0 /* interrupt_enable */,
239 : : 0 /* cq_entry_enable */,
240 : : 1 /* cq_message_enable */,
241 : : 0 /* interrupt offset */,
242 : 0 : (uint64_t)enic->wq[index].cqmsg_rz->iova);
243 : : }
244 : :
245 [ # # ]: 0 : for (index = 0; index < enic->intr_count; index++) {
246 : 0 : vnic_intr_init(&enic->intr[index],
247 : : enic->config.intr_timer_usec,
248 : 0 : enic->config.intr_timer_type,
249 : : /*mask_on_assertion*/1);
250 : : }
251 : 0 : }
252 : :
253 : :
254 : : int
255 : 0 : enic_alloc_rx_queue_mbufs(struct enic *enic, struct vnic_rq *rq)
256 : : {
257 : : struct rte_mbuf *mb;
258 : 0 : struct rq_enet_desc *rqd = rq->ring.descs;
259 : : unsigned i;
260 : : dma_addr_t dma_addr;
261 : : uint32_t max_rx_pktlen;
262 : : uint16_t rq_buf_len;
263 : :
264 [ # # ]: 0 : if (!rq->in_use)
265 : : return 0;
266 : :
267 : 0 : dev_debug(enic, "queue %u, allocating %u rx queue mbufs\n", rq->index,
268 : : rq->ring.desc_count);
269 : :
270 : : /*
271 : : * If *not* using scatter and the mbuf size is greater than the
272 : : * requested max packet size (mtu + eth overhead), then reduce the
273 : : * posted buffer size to max packet size. HW still receives packets
274 : : * larger than max packet size, but they will be truncated, which we
275 : : * drop in the rx handler. Not ideal, but better than returning
276 : : * large packets when the user is not expecting them.
277 : : */
278 [ # # ]: 0 : max_rx_pktlen = enic_mtu_to_max_rx_pktlen(enic->rte_dev->data->mtu);
279 [ # # ]: 0 : rq_buf_len = rte_pktmbuf_data_room_size(rq->mp) - RTE_PKTMBUF_HEADROOM;
280 [ # # # # ]: 0 : if (max_rx_pktlen < rq_buf_len && !rq->data_queue_enable)
281 : 0 : rq_buf_len = max_rx_pktlen;
282 [ # # ]: 0 : for (i = 0; i < rq->ring.desc_count; i++, rqd++) {
283 : 0 : mb = rte_mbuf_raw_alloc(rq->mp);
284 [ # # ]: 0 : if (mb == NULL) {
285 : 0 : dev_err(enic, "RX mbuf alloc failed queue_id=%u\n",
286 : : (unsigned)rq->index);
287 : 0 : return -ENOMEM;
288 : : }
289 : :
290 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
291 : 0 : dma_addr = (dma_addr_t)(mb->buf_iova
292 : : + RTE_PKTMBUF_HEADROOM);
293 : 0 : rq_enet_desc_enc(rqd, dma_addr,
294 : 0 : (rq->is_sop ? RQ_ENET_TYPE_ONLY_SOP
295 : : : RQ_ENET_TYPE_NOT_SOP),
296 : : rq_buf_len);
297 : 0 : rq->mbuf_ring[i] = mb;
298 : : }
299 : : /*
300 : : * Do not post the buffers to the NIC until we enable the RQ via
301 : : * enic_start_rq().
302 : : */
303 : 0 : rq->need_initial_post = true;
304 : : /* Initialize fetch index while RQ is disabled */
305 : 0 : iowrite32(0, &rq->ctrl->fetch_index);
306 : 0 : return 0;
307 : : }
308 : :
309 : : /*
310 : : * Post the Rx buffers for the first time. enic_alloc_rx_queue_mbufs() has
311 : : * allocated the buffers and filled the RQ descriptor ring. Just need to push
312 : : * the post index to the NIC.
313 : : */
314 : : static void
315 : 0 : enic_initial_post_rx(struct enic *enic, struct vnic_rq *rq)
316 : : {
317 [ # # # # ]: 0 : if (!rq->in_use || !rq->need_initial_post)
318 : : return;
319 : :
320 : : /* make sure all prior writes are complete before doing the PIO write */
321 : : rte_rmb();
322 : :
323 : : /* Post all but the last buffer to VIC. */
324 : 0 : rq->posted_index = rq->ring.desc_count - 1;
325 : :
326 : 0 : rq->rx_nb_hold = 0;
327 : :
328 : 0 : dev_debug(enic, "port=%u, qidx=%u, Write %u posted idx, %u sw held\n",
329 : : enic->port_id, rq->index, rq->posted_index, rq->rx_nb_hold);
330 : 0 : iowrite32(rq->posted_index, &rq->ctrl->posted_index);
331 : : rte_rmb();
332 : 0 : rq->need_initial_post = false;
333 : : }
334 : :
335 : : void *
336 : 0 : enic_alloc_consistent(void *priv, size_t size,
337 : : dma_addr_t *dma_handle, uint8_t *name)
338 : : {
339 : : void *vaddr;
340 : : const struct rte_memzone *rz;
341 : 0 : *dma_handle = 0;
342 : : struct enic *enic = (struct enic *)priv;
343 : : struct enic_memzone_entry *mze;
344 : :
345 : 0 : rz = rte_memzone_reserve_aligned((const char *)name, size,
346 : : SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG, ENIC_PAGE_SIZE);
347 [ # # ]: 0 : if (!rz) {
348 : 0 : pr_err("%s : Failed to allocate memory requested for %s\n",
349 : : __func__, name);
350 : 0 : return NULL;
351 : : }
352 : :
353 : 0 : vaddr = rz->addr;
354 : 0 : *dma_handle = (dma_addr_t)rz->iova;
355 : :
356 : 0 : mze = rte_malloc("enic memzone entry",
357 : : sizeof(struct enic_memzone_entry), 0);
358 : :
359 [ # # ]: 0 : if (!mze) {
360 : 0 : pr_err("%s : Failed to allocate memory for memzone list\n",
361 : : __func__);
362 : 0 : rte_memzone_free(rz);
363 : 0 : return NULL;
364 : : }
365 : :
366 : 0 : mze->rz = rz;
367 : :
368 : 0 : rte_spinlock_lock(&enic->memzone_list_lock);
369 [ # # ]: 0 : LIST_INSERT_HEAD(&enic->memzone_list, mze, entries);
370 : : rte_spinlock_unlock(&enic->memzone_list_lock);
371 : :
372 : 0 : return vaddr;
373 : : }
374 : :
375 : : void
376 : 0 : enic_free_consistent(void *priv,
377 : : __rte_unused size_t size,
378 : : void *vaddr,
379 : : dma_addr_t dma_handle)
380 : : {
381 : : struct enic_memzone_entry *mze;
382 : : struct enic *enic = (struct enic *)priv;
383 : :
384 : 0 : rte_spinlock_lock(&enic->memzone_list_lock);
385 [ # # ]: 0 : LIST_FOREACH(mze, &enic->memzone_list, entries) {
386 [ # # ]: 0 : if (mze->rz->addr == vaddr &&
387 [ # # ]: 0 : mze->rz->iova == dma_handle)
388 : : break;
389 : : }
390 [ # # ]: 0 : if (mze == NULL) {
391 : : rte_spinlock_unlock(&enic->memzone_list_lock);
392 : 0 : dev_warning(enic,
393 : : "Tried to free memory, but couldn't find it in the memzone list\n");
394 : 0 : return;
395 : : }
396 [ # # ]: 0 : LIST_REMOVE(mze, entries);
397 : : rte_spinlock_unlock(&enic->memzone_list_lock);
398 : 0 : rte_memzone_free(mze->rz);
399 : 0 : rte_free(mze);
400 : : }
401 : :
402 : 0 : int enic_link_update(struct rte_eth_dev *eth_dev)
403 : : {
404 : : struct enic *enic = pmd_priv(eth_dev);
405 : : struct rte_eth_link link;
406 : :
407 : : memset(&link, 0, sizeof(link));
408 : 0 : link.link_status = enic_get_link_status(enic);
409 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
410 [ # # ]: 0 : link.link_speed = vnic_dev_port_speed(enic->vdev);
411 : :
412 : 0 : return rte_eth_linkstatus_set(eth_dev, &link);
413 : : }
414 : :
415 : : static void
416 : 0 : enic_intr_handler(void *arg)
417 : : {
418 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)arg;
419 : : struct enic *enic = pmd_priv(dev);
420 : :
421 : 0 : ENICPMD_FUNC_TRACE();
422 : :
423 : 0 : vnic_intr_return_all_credits(&enic->intr[ENICPMD_LSC_INTR_OFFSET]);
424 : :
425 [ # # ]: 0 : if (enic_is_vf(enic)) {
426 : : /*
427 : : * When using the admin channel, VF receives link
428 : : * status changes from PF. enic_poll_vf_admin_chan()
429 : : * calls RTE_ETH_EVENT_INTR_LSC.
430 : : */
431 : 0 : enic_poll_vf_admin_chan(enic);
432 : 0 : return;
433 : : }
434 : :
435 : 0 : enic_link_update(dev);
436 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
437 : 0 : enic_log_q_error(enic);
438 : : /* Re-enable irq in case of INTx */
439 : 0 : rte_intr_ack(enic->pdev->intr_handle);
440 : : }
441 : :
442 : 0 : static int enic_rxq_intr_init(struct enic *enic)
443 : : {
444 : : struct rte_intr_handle *intr_handle;
445 : : uint32_t rxq_intr_count, i;
446 : : int err;
447 : :
448 : 0 : intr_handle = enic->rte_dev->intr_handle;
449 [ # # ]: 0 : if (!enic->rte_dev->data->dev_conf.intr_conf.rxq)
450 : : return 0;
451 : : /*
452 : : * Rx queue interrupts only work when we have MSI-X interrupts,
453 : : * one per queue. Sharing one interrupt is technically
454 : : * possible with VIC, but it is not worth the complications it brings.
455 : : */
456 [ # # ]: 0 : if (!rte_intr_cap_multiple(intr_handle)) {
457 : 0 : dev_err(enic, "Rx queue interrupts require MSI-X interrupts"
458 : : " (vfio-pci driver)\n");
459 : 0 : return -ENOTSUP;
460 : : }
461 : 0 : rxq_intr_count = enic->intr_count - ENICPMD_RXQ_INTR_OFFSET;
462 : 0 : err = rte_intr_efd_enable(intr_handle, rxq_intr_count);
463 [ # # ]: 0 : if (err) {
464 : 0 : dev_err(enic, "Failed to enable event fds for Rx queue"
465 : : " interrupts\n");
466 : 0 : return err;
467 : : }
468 : :
469 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "enic_intr_vec",
470 : : rxq_intr_count)) {
471 : 0 : dev_err(enic, "Failed to allocate intr_vec\n");
472 : 0 : return -ENOMEM;
473 : : }
474 [ # # ]: 0 : for (i = 0; i < rxq_intr_count; i++)
475 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle, i,
476 : 0 : i + ENICPMD_RXQ_INTR_OFFSET))
477 : 0 : return -rte_errno;
478 : : return 0;
479 : : }
480 : :
481 : : static void enic_rxq_intr_deinit(struct enic *enic)
482 : : {
483 : : struct rte_intr_handle *intr_handle;
484 : :
485 : 0 : intr_handle = enic->rte_dev->intr_handle;
486 : 0 : rte_intr_efd_disable(intr_handle);
487 : :
488 : 0 : rte_intr_vec_list_free(intr_handle);
489 : : }
490 : :
491 : : static void enic_prep_wq_for_simple_tx(struct enic *enic, uint16_t queue_idx)
492 : : {
493 : : struct wq_enet_desc *desc;
494 : : struct vnic_wq *wq;
495 : : unsigned int i;
496 : :
497 : : /*
498 : : * Fill WQ descriptor fields that never change. Every descriptor is
499 : : * one packet, so set EOP. Also set CQ_ENTRY every ENIC_WQ_CQ_THRESH
500 : : * descriptors (i.e. request one completion update every 32 packets).
501 : : */
502 : 0 : wq = &enic->wq[queue_idx];
503 : 0 : desc = (struct wq_enet_desc *)wq->ring.descs;
504 [ # # ]: 0 : for (i = 0; i < wq->ring.desc_count; i++, desc++) {
505 : 0 : desc->header_length_flags = 1 << WQ_ENET_FLAGS_EOP_SHIFT;
506 [ # # ]: 0 : if (i % ENIC_WQ_CQ_THRESH == ENIC_WQ_CQ_THRESH - 1)
507 : 0 : desc->header_length_flags |=
508 : : (1 << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT);
509 : : }
510 : : }
511 : :
512 : : #ifndef ENIC_RXTX_VEC
513 : : bool
514 : : enic_use_vector_rx_handler(__rte_unused struct rte_eth_dev *eth_dev)
515 : : {
516 : : return false;
517 : : }
518 : : #endif /* ENIC_RXTX_VEC */
519 : :
520 [ # # ]: 0 : void enic_pick_rx_handler(struct rte_eth_dev *eth_dev)
521 : : {
522 : : struct enic *enic = pmd_priv(eth_dev);
523 : :
524 [ # # ]: 0 : if (enic->cq64) {
525 : 0 : ENICPMD_LOG(DEBUG, " use the normal Rx handler for 64B CQ entry");
526 : 0 : eth_dev->rx_pkt_burst = &enic_recv_pkts_64;
527 : 0 : return;
528 : : }
529 : : /*
530 : : * Preference order:
531 : : * 1. The vectorized handler if possible and requested.
532 : : * 2. The non-scatter, simplified handler if scatter Rx is not used.
533 : : * 3. The default handler as a fallback.
534 : : */
535 [ # # ]: 0 : if (enic_use_vector_rx_handler(eth_dev))
536 : : return;
537 [ # # # # ]: 0 : if (enic->rq_count > 0 && enic->rq[0].data_queue_enable == 0) {
538 : 0 : ENICPMD_LOG(DEBUG, " use the non-scatter Rx handler");
539 : 0 : eth_dev->rx_pkt_burst = &enic_noscatter_recv_pkts;
540 : : } else {
541 : 0 : ENICPMD_LOG(DEBUG, " use the normal Rx handler");
542 : 0 : eth_dev->rx_pkt_burst = &enic_recv_pkts;
543 : : }
544 : : }
545 : :
546 : : /* Secondary process uses this to set the Tx handler */
547 [ # # ]: 0 : void enic_pick_tx_handler(struct rte_eth_dev *eth_dev)
548 : : {
549 : : struct enic *enic = pmd_priv(eth_dev);
550 : :
551 [ # # ]: 0 : if (enic->use_simple_tx_handler) {
552 : 0 : ENICPMD_LOG(DEBUG, " use the simple tx handler");
553 : 0 : eth_dev->tx_pkt_burst = &enic_simple_xmit_pkts;
554 : : } else {
555 : 0 : ENICPMD_LOG(DEBUG, " use the default tx handler");
556 : 0 : eth_dev->tx_pkt_burst = &enic_xmit_pkts;
557 : : }
558 : 0 : }
559 : :
560 : 0 : int enic_enable(struct enic *enic)
561 : : {
562 : : unsigned int index;
563 : : int err;
564 : 0 : struct rte_eth_dev *eth_dev = enic->rte_dev;
565 : : uint64_t simple_tx_offloads;
566 : : uintptr_t p;
567 : :
568 [ # # ]: 0 : if (enic->enable_avx2_rx) {
569 : 0 : struct rte_mbuf mb_def = { .buf_addr = 0 };
570 : :
571 : : /*
572 : : * mbuf_initializer contains const-after-init fields of
573 : : * receive mbufs (i.e. 64 bits of fields from rearm_data).
574 : : * It is currently used by the vectorized handler.
575 : : */
576 : 0 : mb_def.nb_segs = 1;
577 : 0 : mb_def.data_off = RTE_PKTMBUF_HEADROOM;
578 : 0 : mb_def.port = enic->port_id;
579 : : rte_mbuf_refcnt_set(&mb_def, 1);
580 : 0 : rte_compiler_barrier();
581 : : p = (uintptr_t)&mb_def.rearm_data;
582 : 0 : enic->mbuf_initializer = *(uint64_t *)p;
583 : : }
584 : :
585 : 0 : eth_dev->data->dev_link.link_speed = vnic_dev_port_speed(enic->vdev);
586 : 0 : eth_dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
587 : :
588 : : /* vnic notification of link status has already been turned on in
589 : : * enic_dev_init() which is called during probe time. Here we are
590 : : * just turning on interrupt vector 0 if needed.
591 : : */
592 [ # # ]: 0 : if (eth_dev->data->dev_conf.intr_conf.lsc)
593 : 0 : vnic_dev_notify_set(enic->vdev, 0);
594 : :
595 : 0 : err = enic_rxq_intr_init(enic);
596 [ # # ]: 0 : if (err)
597 : : return err;
598 : :
599 : : /* Initialize flowman if not already initialized during probe */
600 [ # # # # ]: 0 : if (enic->fm == NULL && enic_fm_init(enic))
601 : 0 : dev_warning(enic, "Init of flowman failed.\n");
602 : :
603 [ # # ]: 0 : for (index = 0; index < enic->rq_count; index++) {
604 : 0 : err = enic_alloc_rx_queue_mbufs(enic,
605 : 0 : &enic->rq[enic_rte_rq_idx_to_sop_idx(index)]);
606 [ # # ]: 0 : if (err) {
607 : 0 : dev_err(enic, "Failed to alloc sop RX queue mbufs\n");
608 : 0 : return err;
609 : : }
610 : 0 : err = enic_alloc_rx_queue_mbufs(enic,
611 : 0 : &enic->rq[enic_rte_rq_idx_to_data_idx(index, enic)]);
612 [ # # ]: 0 : if (err) {
613 : : /* release the allocated mbufs for the sop rq*/
614 : 0 : enic_rxmbuf_queue_release(enic,
615 : 0 : &enic->rq[enic_rte_rq_idx_to_sop_idx(index)]);
616 : :
617 : 0 : dev_err(enic, "Failed to alloc data RX queue mbufs\n");
618 : 0 : return err;
619 : : }
620 : : }
621 : :
622 : : /*
623 : : * Use the simple TX handler if possible. Only checksum offloads
624 : : * and vlan insertion are supported.
625 : : */
626 : 0 : simple_tx_offloads = enic->tx_offload_capa &
627 : : (RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
628 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
629 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
630 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
631 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM);
632 : 0 : if ((eth_dev->data->dev_conf.txmode.offloads &
633 [ # # ]: 0 : ~simple_tx_offloads) == 0) {
634 : 0 : ENICPMD_LOG(DEBUG, " use the simple tx handler");
635 : 0 : eth_dev->tx_pkt_burst = &enic_simple_xmit_pkts;
636 [ # # ]: 0 : for (index = 0; index < enic->wq_count; index++)
637 : 0 : enic_prep_wq_for_simple_tx(enic, index);
638 : 0 : enic->use_simple_tx_handler = 1;
639 : : } else {
640 : 0 : ENICPMD_LOG(DEBUG, " use the default tx handler");
641 : 0 : eth_dev->tx_pkt_burst = &enic_xmit_pkts;
642 : : }
643 : :
644 : 0 : enic_pick_rx_handler(eth_dev);
645 : :
646 [ # # ]: 0 : for (index = 0; index < enic->wq_count; index++)
647 : 0 : enic_start_wq(enic, index);
648 [ # # ]: 0 : for (index = 0; index < enic->rq_count; index++)
649 : 0 : enic_start_rq(enic, index);
650 : :
651 : 0 : enic_dev_add_addr(enic, enic->mac_addr);
652 : :
653 : 0 : vnic_dev_enable_wait(enic->vdev);
654 : :
655 : : /* Register and enable error interrupt */
656 : 0 : rte_intr_callback_register(enic->pdev->intr_handle,
657 : 0 : enic_intr_handler, (void *)enic->rte_dev);
658 : 0 : rte_intr_enable(enic->pdev->intr_handle);
659 : : /* Unmask LSC interrupt */
660 : 0 : vnic_intr_unmask(&enic->intr[ENICPMD_LSC_INTR_OFFSET]);
661 : :
662 : 0 : return 0;
663 : : }
664 : :
665 : 0 : int enic_alloc_intr_resources(struct enic *enic)
666 : : {
667 : : int err;
668 : : unsigned int i;
669 : :
670 : 0 : dev_info(enic, "vNIC resources used: "\
671 : : "wq %d rq %d cq %d intr %d\n",
672 : : enic->wq_count, enic_vnic_rq_count(enic),
673 : : enic->cq_count, enic->intr_count);
674 : :
675 [ # # ]: 0 : if (enic_is_vf(enic)) {
676 : 0 : dev_info(enic, "vNIC admin channel resources used: wq %d rq %d cq %d\n",
677 : : enic->conf_admin_wq_count, enic->conf_admin_rq_count,
678 : : enic->conf_admin_cq_count);
679 : : }
680 : :
681 [ # # ]: 0 : for (i = 0; i < enic->intr_count; i++) {
682 : 0 : err = vnic_intr_alloc(enic->vdev, &enic->intr[i], i);
683 [ # # ]: 0 : if (err) {
684 : 0 : enic_free_vnic_resources(enic);
685 : 0 : return err;
686 : : }
687 : : }
688 : :
689 : : return 0;
690 : : }
691 : :
692 : 0 : void enic_free_rq(void *rxq)
693 : : {
694 : : struct vnic_rq *rq_sop, *rq_data;
695 : : struct enic *enic;
696 : :
697 [ # # ]: 0 : if (rxq == NULL)
698 : : return;
699 : :
700 : : rq_sop = (struct vnic_rq *)rxq;
701 : 0 : enic = vnic_dev_priv(rq_sop->vdev);
702 : 0 : rq_data = &enic->rq[rq_sop->data_queue_idx];
703 : :
704 [ # # ]: 0 : if (rq_sop->free_mbufs) {
705 : : struct rte_mbuf **mb;
706 : : int i;
707 : :
708 : : mb = rq_sop->free_mbufs;
709 : 0 : for (i = ENIC_RX_BURST_MAX - rq_sop->num_free_mbufs;
710 [ # # ]: 0 : i < ENIC_RX_BURST_MAX; i++)
711 : 0 : rte_pktmbuf_free(mb[i]);
712 : 0 : rte_free(rq_sop->free_mbufs);
713 : 0 : rq_sop->free_mbufs = NULL;
714 : 0 : rq_sop->num_free_mbufs = 0;
715 : : }
716 : :
717 : 0 : enic_rxmbuf_queue_release(enic, rq_sop);
718 [ # # ]: 0 : if (rq_data->in_use)
719 : 0 : enic_rxmbuf_queue_release(enic, rq_data);
720 : :
721 : 0 : rte_free(rq_sop->mbuf_ring);
722 [ # # ]: 0 : if (rq_data->in_use)
723 : 0 : rte_free(rq_data->mbuf_ring);
724 : :
725 : 0 : rq_sop->mbuf_ring = NULL;
726 : 0 : rq_data->mbuf_ring = NULL;
727 : :
728 : 0 : vnic_rq_free(rq_sop);
729 [ # # ]: 0 : if (rq_data->in_use)
730 : 0 : vnic_rq_free(rq_data);
731 : :
732 : 0 : vnic_cq_free(&enic->cq[enic_sop_rq_idx_to_cq_idx(rq_sop->index)]);
733 : :
734 : 0 : rq_sop->in_use = 0;
735 : 0 : rq_data->in_use = 0;
736 : : }
737 : :
738 : 0 : void enic_start_wq(struct enic *enic, uint16_t queue_idx)
739 : : {
740 : 0 : struct rte_eth_dev_data *data = enic->dev_data;
741 : 0 : vnic_wq_enable(&enic->wq[queue_idx]);
742 : 0 : data->tx_queue_state[queue_idx] = RTE_ETH_QUEUE_STATE_STARTED;
743 : 0 : }
744 : :
745 : 0 : int enic_stop_wq(struct enic *enic, uint16_t queue_idx)
746 : : {
747 : 0 : struct rte_eth_dev_data *data = enic->dev_data;
748 : : int ret;
749 : :
750 : 0 : ret = vnic_wq_disable(&enic->wq[queue_idx]);
751 [ # # ]: 0 : if (ret)
752 : : return ret;
753 : :
754 : 0 : data->tx_queue_state[queue_idx] = RTE_ETH_QUEUE_STATE_STOPPED;
755 : 0 : return 0;
756 : : }
757 : :
758 : 0 : void enic_start_rq(struct enic *enic, uint16_t queue_idx)
759 : : {
760 : 0 : struct rte_eth_dev_data *data = enic->dev_data;
761 : : struct vnic_rq *rq_sop;
762 : : struct vnic_rq *rq_data;
763 : 0 : rq_sop = &enic->rq[enic_rte_rq_idx_to_sop_idx(queue_idx)];
764 : 0 : rq_data = &enic->rq[rq_sop->data_queue_idx];
765 : :
766 [ # # ]: 0 : if (rq_data->in_use) {
767 : 0 : vnic_rq_enable(rq_data);
768 : 0 : enic_initial_post_rx(enic, rq_data);
769 : : }
770 : : rte_mb();
771 : 0 : vnic_rq_enable(rq_sop);
772 : 0 : enic_initial_post_rx(enic, rq_sop);
773 : 0 : data->rx_queue_state[queue_idx] = RTE_ETH_QUEUE_STATE_STARTED;
774 : 0 : }
775 : :
776 : 0 : int enic_stop_rq(struct enic *enic, uint16_t queue_idx)
777 : : {
778 : 0 : struct rte_eth_dev_data *data = enic->dev_data;
779 : : int ret1 = 0, ret2 = 0;
780 : : struct vnic_rq *rq_sop;
781 : : struct vnic_rq *rq_data;
782 : 0 : rq_sop = &enic->rq[enic_rte_rq_idx_to_sop_idx(queue_idx)];
783 : 0 : rq_data = &enic->rq[rq_sop->data_queue_idx];
784 : :
785 : 0 : ret2 = vnic_rq_disable(rq_sop);
786 : : rte_mb();
787 [ # # ]: 0 : if (rq_data->in_use)
788 : 0 : ret1 = vnic_rq_disable(rq_data);
789 : :
790 [ # # ]: 0 : if (ret2)
791 : : return ret2;
792 [ # # ]: 0 : else if (ret1)
793 : : return ret1;
794 : :
795 : 0 : data->rx_queue_state[queue_idx] = RTE_ETH_QUEUE_STATE_STOPPED;
796 : 0 : return 0;
797 : : }
798 : :
799 : 0 : int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
800 : : unsigned int socket_id, struct rte_mempool *mp,
801 : : uint16_t nb_desc, uint16_t free_thresh)
802 : : {
803 : : struct enic_vf_representor *vf;
804 : : int rc;
805 : : uint16_t sop_queue_idx;
806 : : uint16_t data_queue_idx;
807 : : uint16_t cq_idx;
808 : : struct vnic_rq *rq_sop;
809 : : struct vnic_rq *rq_data;
810 : : unsigned int mbuf_size, mbufs_per_pkt;
811 : : unsigned int nb_sop_desc, nb_data_desc;
812 : : uint16_t min_sop, max_sop, min_data, max_data;
813 : : uint32_t max_rx_pktlen;
814 : :
815 : : /*
816 : : * Representor uses a reserved PF queue. Translate representor
817 : : * queue number to PF queue number.
818 : : */
819 [ # # ]: 0 : if (rte_eth_dev_is_repr(enic->rte_dev)) {
820 : : RTE_ASSERT(queue_idx == 0);
821 : : vf = VF_ENIC_TO_VF_REP(enic);
822 : 0 : sop_queue_idx = vf->pf_rq_sop_idx;
823 : 0 : data_queue_idx = vf->pf_rq_data_idx;
824 : 0 : enic = vf->pf;
825 : : queue_idx = sop_queue_idx;
826 : : } else {
827 : 0 : sop_queue_idx = enic_rte_rq_idx_to_sop_idx(queue_idx);
828 : 0 : data_queue_idx = enic_rte_rq_idx_to_data_idx(queue_idx, enic);
829 : : }
830 : 0 : cq_idx = enic_cq_rq(enic, sop_queue_idx);
831 : 0 : rq_sop = &enic->rq[sop_queue_idx];
832 : 0 : rq_data = &enic->rq[data_queue_idx];
833 : 0 : rq_sop->is_sop = 1;
834 : 0 : rq_sop->data_queue_idx = data_queue_idx;
835 : 0 : rq_data->is_sop = 0;
836 : 0 : rq_data->data_queue_idx = 0;
837 : 0 : rq_sop->socket_id = socket_id;
838 : 0 : rq_sop->mp = mp;
839 : 0 : rq_data->socket_id = socket_id;
840 : 0 : rq_data->mp = mp;
841 : 0 : rq_sop->in_use = 1;
842 : 0 : rq_sop->rx_free_thresh = free_thresh;
843 : 0 : rq_data->rx_free_thresh = free_thresh;
844 : 0 : dev_debug(enic, "Set queue_id:%u free thresh:%u\n", queue_idx,
845 : : free_thresh);
846 : :
847 : 0 : mbuf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
848 : : RTE_PKTMBUF_HEADROOM);
849 : : /* max_rx_pktlen includes the ethernet header and CRC. */
850 [ # # ]: 0 : max_rx_pktlen = enic_mtu_to_max_rx_pktlen(enic->rte_dev->data->mtu);
851 : :
852 [ # # ]: 0 : if (enic->rte_dev->data->dev_conf.rxmode.offloads &
853 : : RTE_ETH_RX_OFFLOAD_SCATTER) {
854 : 0 : dev_info(enic, "Rq %u Scatter rx mode enabled\n", queue_idx);
855 : : /* ceil((max pkt len)/mbuf_size) */
856 : 0 : mbufs_per_pkt = (max_rx_pktlen + mbuf_size - 1) / mbuf_size;
857 : : } else {
858 : 0 : dev_info(enic, "Scatter rx mode disabled\n");
859 : : mbufs_per_pkt = 1;
860 [ # # ]: 0 : if (max_rx_pktlen > mbuf_size) {
861 : 0 : dev_warning(enic, "The maximum Rx packet size (%u) is"
862 : : " larger than the mbuf size (%u), and"
863 : : " scatter is disabled. Larger packets will"
864 : : " be truncated.\n",
865 : : max_rx_pktlen, mbuf_size);
866 : : }
867 : : }
868 : :
869 [ # # ]: 0 : if (mbufs_per_pkt > 1) {
870 : 0 : dev_info(enic, "Rq %u Scatter rx mode in use\n", queue_idx);
871 : 0 : rq_sop->data_queue_enable = 1;
872 : 0 : rq_data->in_use = 1;
873 : : /*
874 : : * HW does not directly support MTU. HW always
875 : : * receives packet sizes up to the "max" MTU.
876 : : * If not using scatter, we can achieve the effect of dropping
877 : : * larger packets by reducing the size of posted buffers.
878 : : * See enic_alloc_rx_queue_mbufs().
879 : : */
880 [ # # ]: 0 : if (enic->rte_dev->data->mtu < enic->max_mtu) {
881 : 0 : dev_warning(enic,
882 : : "mtu is ignored when scatter rx mode is in use.\n");
883 : : }
884 : : } else {
885 : 0 : dev_info(enic, "Rq %u Scatter rx mode not being used\n",
886 : : queue_idx);
887 : 0 : rq_sop->data_queue_enable = 0;
888 : 0 : rq_data->in_use = 0;
889 : : }
890 : :
891 : : /* number of descriptors have to be a multiple of 32 */
892 : 0 : nb_sop_desc = (nb_desc / mbufs_per_pkt) & ENIC_ALIGN_DESCS_MASK;
893 : 0 : nb_data_desc = (nb_desc - nb_sop_desc) & ENIC_ALIGN_DESCS_MASK;
894 : :
895 : 0 : rq_sop->max_mbufs_per_pkt = mbufs_per_pkt;
896 : 0 : rq_data->max_mbufs_per_pkt = mbufs_per_pkt;
897 : :
898 [ # # ]: 0 : if (mbufs_per_pkt > 1) {
899 : : min_sop = ENIC_RX_BURST_MAX;
900 : 0 : max_sop = ((enic->config.rq_desc_count /
901 : 0 : (mbufs_per_pkt - 1)) & ENIC_ALIGN_DESCS_MASK);
902 : 0 : min_data = min_sop * (mbufs_per_pkt - 1);
903 : 0 : max_data = enic->config.rq_desc_count;
904 : : } else {
905 : : min_sop = ENIC_RX_BURST_MAX;
906 : 0 : max_sop = enic->config.rq_desc_count;
907 : : min_data = 0;
908 : : max_data = 0;
909 : : }
910 : :
911 [ # # ]: 0 : if (nb_desc < (min_sop + min_data)) {
912 : 0 : dev_warning(enic,
913 : : "Number of rx descs too low, adjusting to minimum\n");
914 : : nb_sop_desc = min_sop;
915 : 0 : nb_data_desc = min_data;
916 [ # # ]: 0 : } else if (nb_desc > (max_sop + max_data)) {
917 : 0 : dev_warning(enic,
918 : : "Number of rx_descs too high, adjusting to maximum\n");
919 : 0 : nb_sop_desc = max_sop;
920 : 0 : nb_data_desc = max_data;
921 : : }
922 [ # # ]: 0 : if (mbufs_per_pkt > 1) {
923 : 0 : dev_info(enic, "For max packet size %u and mbuf size %u valid"
924 : : " rx descriptor range is %u to %u\n",
925 : : max_rx_pktlen, mbuf_size, min_sop + min_data,
926 : : max_sop + max_data);
927 : : }
928 : 0 : dev_info(enic, "Using %d rx descriptors (sop %d, data %d)\n",
929 : : nb_sop_desc + nb_data_desc, nb_sop_desc, nb_data_desc);
930 : :
931 : : /* Allocate sop queue resources */
932 : 0 : rc = vnic_rq_alloc(enic->vdev, rq_sop, sop_queue_idx,
933 : : nb_sop_desc, sizeof(struct rq_enet_desc));
934 [ # # ]: 0 : if (rc) {
935 : 0 : dev_err(enic, "error in allocation of sop rq\n");
936 : 0 : goto err_exit;
937 : : }
938 : 0 : nb_sop_desc = rq_sop->ring.desc_count;
939 : :
940 [ # # ]: 0 : if (rq_data->in_use) {
941 : : /* Allocate data queue resources */
942 : 0 : rc = vnic_rq_alloc(enic->vdev, rq_data, data_queue_idx,
943 : : nb_data_desc,
944 : : sizeof(struct rq_enet_desc));
945 [ # # ]: 0 : if (rc) {
946 : 0 : dev_err(enic, "error in allocation of data rq\n");
947 : 0 : goto err_free_rq_sop;
948 : : }
949 : 0 : nb_data_desc = rq_data->ring.desc_count;
950 : : }
951 : : /* Enable 64B CQ entry if requested */
952 [ # # # # ]: 0 : if (enic->cq64 && vnic_dev_set_cq_entry_size(enic->vdev,
953 : : sop_queue_idx, VNIC_RQ_CQ_ENTRY_SIZE_64)) {
954 : 0 : dev_err(enic, "failed to enable 64B CQ entry on sop rq\n");
955 : 0 : goto err_free_rq_data;
956 : : }
957 [ # # # # : 0 : if (rq_data->in_use && enic->cq64 &&
# # ]
958 : 0 : vnic_dev_set_cq_entry_size(enic->vdev, data_queue_idx,
959 : : VNIC_RQ_CQ_ENTRY_SIZE_64)) {
960 : 0 : dev_err(enic, "failed to enable 64B CQ entry on data rq\n");
961 : 0 : goto err_free_rq_data;
962 : : }
963 : :
964 : 0 : rc = vnic_cq_alloc(enic->vdev, &enic->cq[cq_idx], cq_idx,
965 : : socket_id, nb_sop_desc + nb_data_desc,
966 [ # # ]: 0 : enic->cq64 ? sizeof(struct cq_enet_rq_desc_64) :
967 : : sizeof(struct cq_enet_rq_desc));
968 [ # # ]: 0 : if (rc) {
969 : 0 : dev_err(enic, "error in allocation of cq for rq\n");
970 : 0 : goto err_free_rq_data;
971 : : }
972 : :
973 : : /* Allocate the mbuf rings */
974 : 0 : rq_sop->mbuf_ring = (struct rte_mbuf **)
975 : 0 : rte_zmalloc_socket("rq->mbuf_ring",
976 : : sizeof(struct rte_mbuf *) * nb_sop_desc,
977 : 0 : RTE_CACHE_LINE_SIZE, rq_sop->socket_id);
978 [ # # ]: 0 : if (rq_sop->mbuf_ring == NULL)
979 : 0 : goto err_free_cq;
980 : :
981 [ # # ]: 0 : if (rq_data->in_use) {
982 : 0 : rq_data->mbuf_ring = (struct rte_mbuf **)
983 : 0 : rte_zmalloc_socket("rq->mbuf_ring",
984 : : sizeof(struct rte_mbuf *) * nb_data_desc,
985 : 0 : RTE_CACHE_LINE_SIZE, rq_sop->socket_id);
986 [ # # ]: 0 : if (rq_data->mbuf_ring == NULL)
987 : 0 : goto err_free_sop_mbuf;
988 : : }
989 : :
990 : 0 : rq_sop->free_mbufs = (struct rte_mbuf **)
991 : 0 : rte_zmalloc_socket("rq->free_mbufs",
992 : : sizeof(struct rte_mbuf *) *
993 : : ENIC_RX_BURST_MAX,
994 : 0 : RTE_CACHE_LINE_SIZE, rq_sop->socket_id);
995 [ # # ]: 0 : if (rq_sop->free_mbufs == NULL)
996 : 0 : goto err_free_data_mbuf;
997 : 0 : rq_sop->num_free_mbufs = 0;
998 : :
999 : 0 : rq_sop->tot_nb_desc = nb_desc; /* squirl away for MTU update function */
1000 : :
1001 : 0 : return 0;
1002 : :
1003 : : err_free_data_mbuf:
1004 : 0 : rte_free(rq_data->mbuf_ring);
1005 : 0 : err_free_sop_mbuf:
1006 : 0 : rte_free(rq_sop->mbuf_ring);
1007 : 0 : err_free_cq:
1008 : : /* cleanup on error */
1009 : 0 : vnic_cq_free(&enic->cq[cq_idx]);
1010 : 0 : err_free_rq_data:
1011 [ # # ]: 0 : if (rq_data->in_use)
1012 : 0 : vnic_rq_free(rq_data);
1013 : 0 : err_free_rq_sop:
1014 : 0 : vnic_rq_free(rq_sop);
1015 : : err_exit:
1016 : : return -ENOMEM;
1017 : : }
1018 : :
1019 : 0 : void enic_free_wq(void *txq)
1020 : : {
1021 : : struct vnic_wq *wq;
1022 : : struct enic *enic;
1023 : :
1024 [ # # ]: 0 : if (txq == NULL)
1025 : : return;
1026 : :
1027 : : wq = (struct vnic_wq *)txq;
1028 : 0 : enic = vnic_dev_priv(wq->vdev);
1029 : 0 : rte_memzone_free(wq->cqmsg_rz);
1030 : 0 : vnic_wq_free(wq);
1031 : 0 : vnic_cq_free(&enic->cq[enic->rq_count + wq->index]);
1032 : : }
1033 : :
1034 : 0 : int enic_alloc_wq(struct enic *enic, uint16_t queue_idx,
1035 : : unsigned int socket_id, uint16_t nb_desc)
1036 : : {
1037 : : struct enic_vf_representor *vf;
1038 : : int err;
1039 : : struct vnic_wq *wq;
1040 : : unsigned int cq_index;
1041 : : char name[RTE_MEMZONE_NAMESIZE];
1042 : : static int instance;
1043 : :
1044 : : /*
1045 : : * Representor uses a reserved PF queue. Translate representor
1046 : : * queue number to PF queue number.
1047 : : */
1048 [ # # ]: 0 : if (rte_eth_dev_is_repr(enic->rte_dev)) {
1049 : : RTE_ASSERT(queue_idx == 0);
1050 : : vf = VF_ENIC_TO_VF_REP(enic);
1051 : 0 : queue_idx = vf->pf_wq_idx;
1052 : 0 : cq_index = vf->pf_wq_cq_idx;
1053 : 0 : enic = vf->pf;
1054 : : } else {
1055 : 0 : cq_index = enic_cq_wq(enic, queue_idx);
1056 : : }
1057 : 0 : wq = &enic->wq[queue_idx];
1058 : 0 : wq->socket_id = socket_id;
1059 : : /*
1060 : : * rte_eth_tx_queue_setup() checks min, max, and alignment. So just
1061 : : * print an info message for diagnostics.
1062 : : */
1063 : 0 : dev_info(enic, "TX Queues - effective number of descs:%d\n", nb_desc);
1064 : :
1065 : : /* Allocate queue resources */
1066 : 0 : err = vnic_wq_alloc(enic->vdev, &enic->wq[queue_idx], queue_idx,
1067 : : nb_desc,
1068 : : sizeof(struct wq_enet_desc));
1069 [ # # ]: 0 : if (err) {
1070 : 0 : dev_err(enic, "error in allocation of wq\n");
1071 : 0 : return err;
1072 : : }
1073 : :
1074 : 0 : err = vnic_cq_alloc(enic->vdev, &enic->cq[cq_index], cq_index,
1075 : : socket_id, nb_desc,
1076 : : sizeof(struct cq_enet_wq_desc));
1077 [ # # ]: 0 : if (err) {
1078 : 0 : vnic_wq_free(wq);
1079 : 0 : dev_err(enic, "error in allocation of cq for wq\n");
1080 : : }
1081 : :
1082 : : /* setup up CQ message */
1083 : 0 : snprintf((char *)name, sizeof(name),
1084 : 0 : "vnic_cqmsg-%s-%d-%d", enic->bdf_name, queue_idx,
1085 : : instance++);
1086 : :
1087 : 0 : wq->cqmsg_rz = rte_memzone_reserve_aligned((const char *)name,
1088 : : sizeof(uint32_t), SOCKET_ID_ANY,
1089 : : RTE_MEMZONE_IOVA_CONTIG, ENIC_PAGE_SIZE);
1090 [ # # ]: 0 : if (!wq->cqmsg_rz)
1091 : 0 : return -ENOMEM;
1092 : :
1093 : : return err;
1094 : : }
1095 : :
1096 : 0 : int enic_disable(struct enic *enic)
1097 : : {
1098 : : unsigned int i;
1099 : : int err;
1100 : :
1101 [ # # ]: 0 : for (i = 0; i < enic->intr_count; i++) {
1102 : 0 : vnic_intr_mask(&enic->intr[i]);
1103 : 0 : (void)vnic_intr_masked(&enic->intr[i]); /* flush write */
1104 : : }
1105 : : enic_rxq_intr_deinit(enic);
1106 : 0 : rte_intr_disable(enic->pdev->intr_handle);
1107 : 0 : rte_intr_callback_unregister(enic->pdev->intr_handle,
1108 : : enic_intr_handler,
1109 : 0 : (void *)enic->rte_dev);
1110 : :
1111 : 0 : vnic_dev_disable(enic->vdev);
1112 : :
1113 : 0 : enic_fm_destroy(enic);
1114 : :
1115 : 0 : enic_dev_del_addr(enic, enic->mac_addr);
1116 : :
1117 [ # # ]: 0 : for (i = 0; i < enic->wq_count; i++) {
1118 : 0 : err = vnic_wq_disable(&enic->wq[i]);
1119 [ # # ]: 0 : if (err)
1120 : 0 : return err;
1121 : : }
1122 [ # # ]: 0 : for (i = 0; i < enic_vnic_rq_count(enic); i++) {
1123 [ # # ]: 0 : if (enic->rq[i].in_use) {
1124 : 0 : err = vnic_rq_disable(&enic->rq[i]);
1125 [ # # ]: 0 : if (err)
1126 : 0 : return err;
1127 : : }
1128 : : }
1129 : :
1130 : : /* If we were using interrupts, set the interrupt vector to -1
1131 : : * to disable interrupts. We are not disabling link notifications,
1132 : : * though, as we want the polling of link status to continue working.
1133 : : */
1134 [ # # ]: 0 : if (enic->rte_dev->data->dev_conf.intr_conf.lsc)
1135 : 0 : vnic_dev_notify_set(enic->vdev, -1);
1136 : :
1137 : 0 : vnic_dev_set_reset_flag(enic->vdev, 1);
1138 : :
1139 [ # # ]: 0 : for (i = 0; i < enic->wq_count; i++)
1140 : 0 : vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
1141 : :
1142 [ # # ]: 0 : for (i = 0; i < enic_vnic_rq_count(enic); i++)
1143 [ # # ]: 0 : if (enic->rq[i].in_use)
1144 : 0 : vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
1145 [ # # ]: 0 : for (i = 0; i < enic->cq_count; i++)
1146 : 0 : vnic_cq_clean(&enic->cq[i]);
1147 [ # # ]: 0 : for (i = 0; i < enic->intr_count; i++)
1148 : 0 : vnic_intr_clean(&enic->intr[i]);
1149 : :
1150 [ # # ]: 0 : if (enic_is_vf(enic))
1151 : 0 : enic_disable_vf_admin_chan(enic, true);
1152 : : return 0;
1153 : : }
1154 : :
1155 : 0 : static int enic_dev_wait(struct vnic_dev *vdev,
1156 : : int (*start)(struct vnic_dev *, int),
1157 : : int (*finished)(struct vnic_dev *, int *),
1158 : : int arg)
1159 : : {
1160 : : int done;
1161 : : int err;
1162 : : int i;
1163 : :
1164 : 0 : err = start(vdev, arg);
1165 [ # # ]: 0 : if (err)
1166 : : return err;
1167 : :
1168 : : /* Wait for func to complete...2 seconds max */
1169 [ # # ]: 0 : for (i = 0; i < 2000; i++) {
1170 : 0 : err = finished(vdev, &done);
1171 [ # # ]: 0 : if (err)
1172 : 0 : return err;
1173 [ # # ]: 0 : if (done)
1174 : : return 0;
1175 : 0 : usleep(1000);
1176 : : }
1177 : : return -ETIMEDOUT;
1178 : : }
1179 : :
1180 : 0 : static int enic_dev_open(struct enic *enic)
1181 : : {
1182 : : int err;
1183 : : int flags = CMD_OPENF_IG_DESCCACHE;
1184 : :
1185 : 0 : err = enic_dev_wait(enic->vdev, vnic_dev_open,
1186 : : vnic_dev_open_done, flags);
1187 [ # # ]: 0 : if (err)
1188 : 0 : dev_err(enic_get_dev(enic),
1189 : : "vNIC device open failed, err %d\n", err);
1190 : :
1191 : 0 : return err;
1192 : : }
1193 : :
1194 : 0 : static int enic_set_rsskey(struct enic *enic, uint8_t *user_key)
1195 : : {
1196 : : dma_addr_t rss_key_buf_pa;
1197 : : union vnic_rss_key *rss_key_buf_va = NULL;
1198 : : int err, i;
1199 : : uint8_t name[RTE_MEMZONE_NAMESIZE];
1200 : :
1201 : : RTE_ASSERT(user_key != NULL);
1202 : 0 : snprintf((char *)name, sizeof(name), "rss_key-%s", enic->bdf_name);
1203 : 0 : rss_key_buf_va = enic_alloc_consistent(enic, sizeof(union vnic_rss_key),
1204 : : &rss_key_buf_pa, name);
1205 [ # # ]: 0 : if (!rss_key_buf_va)
1206 : : return -ENOMEM;
1207 : :
1208 [ # # ]: 0 : for (i = 0; i < ENIC_RSS_HASH_KEY_SIZE; i++)
1209 : 0 : rss_key_buf_va->key[i / 10].b[i % 10] = user_key[i];
1210 : :
1211 : 0 : err = enic_set_rss_key(enic,
1212 : : rss_key_buf_pa,
1213 : : sizeof(union vnic_rss_key));
1214 : :
1215 : : /* Save for later queries */
1216 [ # # ]: 0 : if (!err) {
1217 [ # # ]: 0 : rte_memcpy(&enic->rss_key, rss_key_buf_va,
1218 : : sizeof(union vnic_rss_key));
1219 : : }
1220 : 0 : enic_free_consistent(enic, sizeof(union vnic_rss_key),
1221 : : rss_key_buf_va, rss_key_buf_pa);
1222 : :
1223 : 0 : return err;
1224 : : }
1225 : :
1226 : 0 : int enic_set_rss_reta(struct enic *enic, union vnic_rss_cpu *rss_cpu)
1227 : : {
1228 : : dma_addr_t rss_cpu_buf_pa;
1229 : : union vnic_rss_cpu *rss_cpu_buf_va = NULL;
1230 : : int err;
1231 : : uint8_t name[RTE_MEMZONE_NAMESIZE];
1232 : :
1233 : 0 : snprintf((char *)name, sizeof(name), "rss_cpu-%s", enic->bdf_name);
1234 : 0 : rss_cpu_buf_va = enic_alloc_consistent(enic, sizeof(union vnic_rss_cpu),
1235 : : &rss_cpu_buf_pa, name);
1236 [ # # ]: 0 : if (!rss_cpu_buf_va)
1237 : : return -ENOMEM;
1238 : :
1239 : : rte_memcpy(rss_cpu_buf_va, rss_cpu, sizeof(union vnic_rss_cpu));
1240 : :
1241 : 0 : err = enic_set_rss_cpu(enic,
1242 : : rss_cpu_buf_pa,
1243 : : sizeof(union vnic_rss_cpu));
1244 : :
1245 : 0 : enic_free_consistent(enic, sizeof(union vnic_rss_cpu),
1246 : : rss_cpu_buf_va, rss_cpu_buf_pa);
1247 : :
1248 : : /* Save for later queries */
1249 [ # # ]: 0 : if (!err)
1250 [ # # ]: 0 : rte_memcpy(&enic->rss_cpu, rss_cpu, sizeof(union vnic_rss_cpu));
1251 : : return err;
1252 : : }
1253 : :
1254 : : static int enic_set_niccfg(struct enic *enic, uint8_t rss_default_cpu,
1255 : : uint8_t rss_hash_type, uint8_t rss_hash_bits, uint8_t rss_base_cpu,
1256 : : uint8_t rss_enable)
1257 : : {
1258 : : const uint8_t tso_ipid_split_en = 0;
1259 : : int err;
1260 : :
1261 : 0 : err = enic_set_nic_cfg(enic,
1262 : : rss_default_cpu, rss_hash_type,
1263 : : rss_hash_bits, rss_base_cpu,
1264 : : rss_enable, tso_ipid_split_en,
1265 : 0 : enic->ig_vlan_strip_en);
1266 : :
1267 : : return err;
1268 : : }
1269 : :
1270 : : /* Initialize RSS with defaults, called from dev_configure */
1271 : 0 : int enic_init_rss_nic_cfg(struct enic *enic)
1272 : : {
1273 : : static uint8_t default_rss_key[] = {
1274 : : 85, 67, 83, 97, 119, 101, 115, 111, 109, 101,
1275 : : 80, 65, 76, 79, 117, 110, 105, 113, 117, 101,
1276 : : 76, 73, 78, 85, 88, 114, 111, 99, 107, 115,
1277 : : 69, 78, 73, 67, 105, 115, 99, 111, 111, 108,
1278 : : };
1279 : : struct rte_eth_rss_conf rss_conf;
1280 : : union vnic_rss_cpu rss_cpu;
1281 : : int ret, i;
1282 : :
1283 : 0 : rss_conf = enic->rte_dev->data->dev_conf.rx_adv_conf.rss_conf;
1284 : : /*
1285 : : * If setting key for the first time, and the user gives us none, then
1286 : : * push the default key to NIC.
1287 : : */
1288 [ # # ]: 0 : if (rss_conf.rss_key == NULL) {
1289 : 0 : rss_conf.rss_key = default_rss_key;
1290 : 0 : rss_conf.rss_key_len = ENIC_RSS_HASH_KEY_SIZE;
1291 : : }
1292 : 0 : ret = enic_set_rss_conf(enic, &rss_conf);
1293 [ # # ]: 0 : if (ret) {
1294 : 0 : dev_err(enic, "Failed to configure RSS\n");
1295 : 0 : return ret;
1296 : : }
1297 [ # # ]: 0 : if (enic->rss_enable) {
1298 : : /* If enabling RSS, use the default reta */
1299 [ # # ]: 0 : for (i = 0; i < ENIC_RSS_RETA_SIZE; i++) {
1300 : 0 : rss_cpu.cpu[i / 4].b[i % 4] =
1301 : 0 : enic_rte_rq_idx_to_sop_idx(i % enic->rq_count);
1302 : : }
1303 : 0 : ret = enic_set_rss_reta(enic, &rss_cpu);
1304 [ # # ]: 0 : if (ret)
1305 : 0 : dev_err(enic, "Failed to set RSS indirection table\n");
1306 : : }
1307 : : return ret;
1308 : : }
1309 : :
1310 : 0 : int enic_setup_finish(struct enic *enic)
1311 : : {
1312 : : int err;
1313 : :
1314 : 0 : ENICPMD_FUNC_TRACE();
1315 : : enic_init_soft_stats(enic);
1316 : :
1317 : : /*
1318 : : * Enable admin channel so we can perform certain devcmds
1319 : : * via admin channel. For example, vnic_dev_packet_filter()
1320 : : */
1321 [ # # ]: 0 : if (enic_is_vf(enic)) {
1322 : 0 : err = enic_enable_vf_admin_chan(enic);
1323 [ # # ]: 0 : if (err)
1324 : : return err;
1325 : : }
1326 : :
1327 : : /* switchdev: enable promisc mode on PF */
1328 [ # # ]: 0 : if (enic->switchdev_mode) {
1329 [ # # ]: 0 : RTE_VERIFY(!enic_is_vf(enic));
1330 : 0 : vnic_dev_packet_filter(enic->vdev,
1331 : : 0 /* directed */,
1332 : : 0 /* multicast */,
1333 : : 0 /* broadcast */,
1334 : : 1 /* promisc */,
1335 : : 0 /* allmulti */);
1336 : 0 : enic->promisc = 1;
1337 : 0 : enic->allmulti = 0;
1338 : 0 : return 0;
1339 : : }
1340 : : /* Default conf */
1341 : 0 : err = enic_dev_packet_filter(enic,
1342 : : 1 /* directed */,
1343 : : 1 /* multicast */,
1344 : : 1 /* broadcast */,
1345 : : 0 /* promisc */,
1346 : : 1 /* allmulti */);
1347 : :
1348 : 0 : enic->promisc = 0;
1349 : 0 : enic->allmulti = 1;
1350 : :
1351 : 0 : return err;
1352 : : }
1353 : :
1354 : 0 : static int enic_rss_conf_valid(struct enic *enic,
1355 : : struct rte_eth_rss_conf *rss_conf)
1356 : : {
1357 : : /* RSS is disabled per VIC settings. Ignore rss_conf. */
1358 [ # # ]: 0 : if (enic->flow_type_rss_offloads == 0)
1359 : : return 0;
1360 [ # # ]: 0 : if (rss_conf->rss_key != NULL &&
1361 [ # # ]: 0 : rss_conf->rss_key_len != ENIC_RSS_HASH_KEY_SIZE) {
1362 : 0 : dev_err(enic, "Given rss_key is %d bytes, it must be %d\n",
1363 : : rss_conf->rss_key_len, ENIC_RSS_HASH_KEY_SIZE);
1364 : 0 : return -EINVAL;
1365 : : }
1366 [ # # ]: 0 : if (rss_conf->rss_hf != 0 &&
1367 [ # # ]: 0 : (rss_conf->rss_hf & enic->flow_type_rss_offloads) == 0) {
1368 : 0 : dev_err(enic, "Given rss_hf contains none of the supported"
1369 : : " types\n");
1370 : 0 : return -EINVAL;
1371 : : }
1372 : : return 0;
1373 : : }
1374 : :
1375 : : /* Set hash type and key according to rss_conf */
1376 : 0 : int enic_set_rss_conf(struct enic *enic, struct rte_eth_rss_conf *rss_conf)
1377 : : {
1378 : : struct rte_eth_dev *eth_dev;
1379 : : uint64_t rss_hf;
1380 : : uint8_t rss_hash_type;
1381 : : uint8_t rss_enable;
1382 : : int ret;
1383 : :
1384 : : RTE_ASSERT(rss_conf != NULL);
1385 : 0 : ret = enic_rss_conf_valid(enic, rss_conf);
1386 [ # # ]: 0 : if (ret) {
1387 : 0 : dev_err(enic, "RSS configuration (rss_conf) is invalid\n");
1388 : 0 : return ret;
1389 : : }
1390 : :
1391 : 0 : eth_dev = enic->rte_dev;
1392 : : rss_hash_type = 0;
1393 : 0 : rss_hf = rss_conf->rss_hf & enic->flow_type_rss_offloads;
1394 [ # # ]: 0 : if (enic->rq_count > 1 &&
1395 [ # # # # ]: 0 : (eth_dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) &&
1396 : : rss_hf != 0) {
1397 : : rss_enable = 1;
1398 [ # # ]: 0 : if (rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
1399 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER))
1400 : : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_IPV4;
1401 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
1402 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV4;
1403 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
1404 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_UDP_IPV4;
1405 [ # # ]: 0 : if (enic->udp_rss_weak) {
1406 : : /*
1407 : : * 'TCP' is not a typo. The "weak" version of
1408 : : * UDP RSS requires both the TCP and UDP bits
1409 : : * be set. It does enable TCP RSS as well.
1410 : : */
1411 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV4;
1412 : : }
1413 : : }
1414 [ # # ]: 0 : if (rss_hf & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX |
1415 : : RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_OTHER))
1416 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_IPV6;
1417 [ # # ]: 0 : if (rss_hf & (RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_IPV6_TCP_EX))
1418 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV6;
1419 [ # # ]: 0 : if (rss_hf & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_IPV6_UDP_EX)) {
1420 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_UDP_IPV6;
1421 [ # # ]: 0 : if (enic->udp_rss_weak)
1422 : 0 : rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV6;
1423 : : }
1424 : : } else {
1425 : : rss_enable = 0;
1426 : : rss_hf = 0;
1427 : : }
1428 : :
1429 : : /* Set the hash key if provided */
1430 [ # # # # ]: 0 : if (rss_enable && rss_conf->rss_key) {
1431 : 0 : ret = enic_set_rsskey(enic, rss_conf->rss_key);
1432 [ # # ]: 0 : if (ret) {
1433 : 0 : dev_err(enic, "Failed to set RSS key\n");
1434 : 0 : return ret;
1435 : : }
1436 : : }
1437 : :
1438 : 0 : ret = enic_set_niccfg(enic, ENIC_RSS_DEFAULT_CPU, rss_hash_type,
1439 : : ENIC_RSS_HASH_BITS, ENIC_RSS_BASE_CPU,
1440 : : rss_enable);
1441 [ # # ]: 0 : if (!ret) {
1442 : 0 : enic->rss_hf = rss_hf;
1443 : 0 : enic->rss_hash_type = rss_hash_type;
1444 : 0 : enic->rss_enable = rss_enable;
1445 : : } else {
1446 : 0 : dev_err(enic, "Failed to update RSS configurations."
1447 : : " hash=0x%x\n", rss_hash_type);
1448 : : }
1449 : : return ret;
1450 : : }
1451 : :
1452 : 0 : int enic_set_vlan_strip(struct enic *enic)
1453 : : {
1454 : : /*
1455 : : * Unfortunately, VLAN strip on/off and RSS on/off are configured
1456 : : * together. So, re-do niccfg, preserving the current RSS settings.
1457 : : */
1458 : 0 : return enic_set_niccfg(enic, ENIC_RSS_DEFAULT_CPU, enic->rss_hash_type,
1459 : : ENIC_RSS_HASH_BITS, ENIC_RSS_BASE_CPU,
1460 : 0 : enic->rss_enable);
1461 : : }
1462 : :
1463 : 0 : int enic_add_packet_filter(struct enic *enic)
1464 : : {
1465 : 0 : ENICPMD_FUNC_TRACE();
1466 : : /* switchdev ignores packet filters */
1467 [ # # ]: 0 : if (enic->switchdev_mode) {
1468 : 0 : ENICPMD_LOG(DEBUG, " switchdev: ignore packet filter");
1469 : 0 : return 0;
1470 : : }
1471 : : /* Args -> directed, multicast, broadcast, promisc, allmulti */
1472 : 0 : return enic_dev_packet_filter(enic, 1, 1, 1,
1473 : : enic->promisc, enic->allmulti);
1474 : : }
1475 : :
1476 : 0 : int enic_get_link_status(struct enic *enic)
1477 : : {
1478 : 0 : return vnic_dev_link_status(enic->vdev);
1479 : : }
1480 : :
1481 : 0 : static void enic_dev_deinit(struct enic *enic)
1482 : : {
1483 : : /* stop link status checking */
1484 : 0 : vnic_dev_notify_unset(enic->vdev);
1485 : :
1486 : : /* mac_addrs is freed by rte_eth_dev_release_port() */
1487 : 0 : rte_free(enic->cq);
1488 : 0 : rte_free(enic->intr);
1489 : 0 : rte_free(enic->rq);
1490 : 0 : rte_free(enic->wq);
1491 : 0 : }
1492 : :
1493 : :
1494 : 0 : int enic_set_vnic_res(struct enic *enic)
1495 : : {
1496 : 0 : struct rte_eth_dev *eth_dev = enic->rte_dev;
1497 : : int rc = 0;
1498 : : unsigned int required_rq, required_wq, required_cq, required_intr;
1499 : :
1500 : : /* Always use two vNIC RQs per eth_dev RQ, regardless of Rx scatter. */
1501 : 0 : required_rq = eth_dev->data->nb_rx_queues * 2;
1502 : 0 : required_wq = eth_dev->data->nb_tx_queues;
1503 : 0 : required_cq = eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues;
1504 : : required_intr = 1; /* 1 for LSC even if intr_conf.lsc is 0 */
1505 [ # # ]: 0 : if (eth_dev->data->dev_conf.intr_conf.rxq) {
1506 : 0 : required_intr += eth_dev->data->nb_rx_queues;
1507 : : }
1508 : : /* FW adds 2 interrupts for admin chan. Use 1 for RQ */
1509 [ # # ]: 0 : if (enic_is_vf(enic))
1510 : 0 : required_intr += 1;
1511 : 0 : ENICPMD_LOG(DEBUG, "Required queues for PF: rq %u wq %u cq %u",
1512 : : required_rq, required_wq, required_cq);
1513 [ # # ]: 0 : if (enic->vf_required_rq) {
1514 : : /* Queues needed for VF representors */
1515 : 0 : required_rq += enic->vf_required_rq;
1516 : 0 : required_wq += enic->vf_required_wq;
1517 : 0 : required_cq += enic->vf_required_cq;
1518 : 0 : ENICPMD_LOG(DEBUG, "Required queues for VF representors: rq %u wq %u cq %u",
1519 : : enic->vf_required_rq, enic->vf_required_wq,
1520 : : enic->vf_required_cq);
1521 : : }
1522 : :
1523 [ # # ]: 0 : if (enic->conf_rq_count < required_rq) {
1524 : 0 : dev_err(dev, "Not enough Receive queues. Requested:%u which uses %d RQs on VIC, Configured:%u\n",
1525 : : eth_dev->data->nb_rx_queues,
1526 : : required_rq, enic->conf_rq_count);
1527 : : rc = -EINVAL;
1528 : : }
1529 [ # # ]: 0 : if (enic->conf_wq_count < required_wq) {
1530 : 0 : dev_err(dev, "Not enough Transmit queues. Requested:%u, Configured:%u\n",
1531 : : eth_dev->data->nb_tx_queues, enic->conf_wq_count);
1532 : : rc = -EINVAL;
1533 : : }
1534 : :
1535 [ # # ]: 0 : if (enic->conf_cq_count < required_cq) {
1536 : 0 : dev_err(dev, "Not enough Completion queues. Required:%u, Configured:%u\n",
1537 : : required_cq, enic->conf_cq_count);
1538 : : rc = -EINVAL;
1539 : : }
1540 [ # # ]: 0 : if (enic->conf_intr_count < required_intr) {
1541 : 0 : dev_err(dev, "Not enough Interrupts to support Rx queue"
1542 : : " interrupts. Required:%u, Configured:%u\n",
1543 : : required_intr, enic->conf_intr_count);
1544 : : rc = -EINVAL;
1545 : : }
1546 : :
1547 [ # # ]: 0 : if (rc == 0) {
1548 : 0 : enic->rq_count = eth_dev->data->nb_rx_queues;
1549 : 0 : enic->wq_count = eth_dev->data->nb_tx_queues;
1550 : 0 : enic->cq_count = enic->rq_count + enic->wq_count;
1551 : 0 : enic->intr_count = required_intr;
1552 : : }
1553 : :
1554 : 0 : return rc;
1555 : : }
1556 : :
1557 : : /* Initialize the completion queue for an RQ */
1558 : : static int
1559 : 0 : enic_reinit_rq(struct enic *enic, unsigned int rq_idx)
1560 : : {
1561 : : struct vnic_rq *sop_rq, *data_rq;
1562 : : unsigned int cq_idx;
1563 : : int rc = 0;
1564 : :
1565 : 0 : sop_rq = &enic->rq[enic_rte_rq_idx_to_sop_idx(rq_idx)];
1566 : 0 : data_rq = &enic->rq[enic_rte_rq_idx_to_data_idx(rq_idx, enic)];
1567 : : cq_idx = enic_cq_rq(enic, rq_idx);
1568 : :
1569 : 0 : vnic_cq_clean(&enic->cq[cq_idx]);
1570 : 0 : vnic_cq_init(&enic->cq[cq_idx],
1571 : : 0 /* flow_control_enable */,
1572 : : 1 /* color_enable */,
1573 : : 0 /* cq_head */,
1574 : : 0 /* cq_tail */,
1575 : : 1 /* cq_tail_color */,
1576 : : 0 /* interrupt_enable */,
1577 : : 1 /* cq_entry_enable */,
1578 : : 0 /* cq_message_enable */,
1579 : : 0 /* interrupt offset */,
1580 : : 0 /* cq_message_addr */);
1581 : :
1582 : :
1583 : 0 : vnic_rq_init_start(sop_rq, enic_cq_rq(enic,
1584 : : enic_rte_rq_idx_to_sop_idx(rq_idx)), 0,
1585 : 0 : sop_rq->ring.desc_count - 1, 1, 0);
1586 [ # # ]: 0 : if (data_rq->in_use) {
1587 : 0 : vnic_rq_init_start(data_rq,
1588 : : enic_cq_rq(enic,
1589 : : enic_rte_rq_idx_to_data_idx(rq_idx, enic)),
1590 : 0 : 0, data_rq->ring.desc_count - 1, 1, 0);
1591 : : }
1592 : :
1593 : 0 : rc = enic_alloc_rx_queue_mbufs(enic, sop_rq);
1594 [ # # ]: 0 : if (rc)
1595 : : return rc;
1596 : :
1597 [ # # ]: 0 : if (data_rq->in_use) {
1598 : 0 : rc = enic_alloc_rx_queue_mbufs(enic, data_rq);
1599 [ # # ]: 0 : if (rc) {
1600 : 0 : enic_rxmbuf_queue_release(enic, sop_rq);
1601 : 0 : return rc;
1602 : : }
1603 : : }
1604 : :
1605 : : return 0;
1606 : : }
1607 : :
1608 : : /* The Cisco NIC can send and receive packets up to a max packet size
1609 : : * determined by the NIC type and firmware. There is also an MTU
1610 : : * configured into the NIC via the CIMC/UCSM management interface
1611 : : * which can be overridden by this function (up to the max packet size).
1612 : : * Depending on the network setup, doing so may cause packet drops
1613 : : * and unexpected behavior.
1614 : : */
1615 : 0 : int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
1616 : : {
1617 : : unsigned int rq_idx;
1618 : : struct vnic_rq *rq;
1619 : : int rc = 0;
1620 : : uint16_t old_mtu; /* previous setting */
1621 : : uint16_t config_mtu; /* Value configured into NIC via CIMC/UCSM */
1622 : 0 : struct rte_eth_dev *eth_dev = enic->rte_dev;
1623 : :
1624 : 0 : old_mtu = eth_dev->data->mtu;
1625 : 0 : config_mtu = enic->config.mtu;
1626 : :
1627 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1628 : : return -E_RTE_SECONDARY;
1629 : :
1630 [ # # ]: 0 : if (new_mtu > enic->max_mtu) {
1631 : 0 : dev_err(enic,
1632 : : "MTU not updated: requested (%u) greater than max (%u)\n",
1633 : : new_mtu, enic->max_mtu);
1634 : 0 : return -EINVAL;
1635 : : }
1636 [ # # ]: 0 : if (new_mtu < ENIC_MIN_MTU) {
1637 : 0 : dev_info(enic,
1638 : : "MTU not updated: requested (%u) less than min (%u)\n",
1639 : : new_mtu, ENIC_MIN_MTU);
1640 : 0 : return -EINVAL;
1641 : : }
1642 [ # # ]: 0 : if (new_mtu > config_mtu)
1643 : 0 : dev_warning(enic,
1644 : : "MTU (%u) is greater than value configured in NIC (%u)\n",
1645 : : new_mtu, config_mtu);
1646 : :
1647 : : /*
1648 : : * If the device has not started (enic_enable), nothing to do.
1649 : : * Later, enic_enable() will set up RQs reflecting the new maximum
1650 : : * packet length.
1651 : : */
1652 [ # # ]: 0 : if (!eth_dev->data->dev_started)
1653 : : return rc;
1654 : :
1655 : : /*
1656 : : * The device has started, re-do RQs on the fly. In the process, we
1657 : : * pick up the new maximum packet length.
1658 : : *
1659 : : * Some applications rely on the ability to change MTU without stopping
1660 : : * the device. So keep this behavior for now.
1661 : : */
1662 : 0 : rte_spinlock_lock(&enic->mtu_lock);
1663 : :
1664 : : /* Stop traffic on all RQs */
1665 [ # # ]: 0 : for (rq_idx = 0; rq_idx < enic->rq_count * 2; rq_idx++) {
1666 : 0 : rq = &enic->rq[rq_idx];
1667 [ # # # # ]: 0 : if (rq->is_sop && rq->in_use) {
1668 : 0 : rc = enic_stop_rq(enic,
1669 : : enic_sop_rq_idx_to_rte_idx(rq_idx));
1670 [ # # ]: 0 : if (rc) {
1671 : 0 : dev_err(enic, "Failed to stop Rq %u\n", rq_idx);
1672 : 0 : goto set_mtu_done;
1673 : : }
1674 : : }
1675 : : }
1676 : :
1677 : : /* replace Rx function with a no-op to avoid getting stale pkts */
1678 : 0 : eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
1679 : 0 : rte_eth_fp_ops[enic->port_id].rx_pkt_burst = eth_dev->rx_pkt_burst;
1680 : : rte_mb();
1681 : :
1682 : : /* Allow time for threads to exit the real Rx function. */
1683 : 0 : usleep(100000);
1684 : :
1685 : : /* now it is safe to reconfigure the RQs */
1686 : :
1687 : :
1688 : : /* free and reallocate RQs with the new MTU */
1689 [ # # ]: 0 : for (rq_idx = 0; rq_idx < enic->rq_count; rq_idx++) {
1690 : 0 : rq = &enic->rq[enic_rte_rq_idx_to_sop_idx(rq_idx)];
1691 [ # # ]: 0 : if (!rq->in_use)
1692 : 0 : continue;
1693 : :
1694 : 0 : enic_free_rq(rq);
1695 : 0 : rc = enic_alloc_rq(enic, rq_idx, rq->socket_id, rq->mp,
1696 : 0 : rq->tot_nb_desc, rq->rx_free_thresh);
1697 [ # # ]: 0 : if (rc) {
1698 : 0 : dev_err(enic,
1699 : : "Fatal MTU alloc error- No traffic will pass\n");
1700 : 0 : goto set_mtu_done;
1701 : : }
1702 : :
1703 : 0 : rc = enic_reinit_rq(enic, rq_idx);
1704 [ # # ]: 0 : if (rc) {
1705 : 0 : dev_err(enic,
1706 : : "Fatal MTU RQ reinit- No traffic will pass\n");
1707 : 0 : goto set_mtu_done;
1708 : : }
1709 : : }
1710 : :
1711 : : /* put back the real receive function */
1712 : : rte_mb();
1713 : 0 : enic_pick_rx_handler(eth_dev);
1714 : 0 : rte_eth_fp_ops[enic->port_id].rx_pkt_burst = eth_dev->rx_pkt_burst;
1715 : : rte_mb();
1716 : :
1717 : : /* restart Rx traffic */
1718 [ # # ]: 0 : for (rq_idx = 0; rq_idx < enic->rq_count; rq_idx++) {
1719 : 0 : rq = &enic->rq[enic_rte_rq_idx_to_sop_idx(rq_idx)];
1720 [ # # # # ]: 0 : if (rq->is_sop && rq->in_use)
1721 : 0 : enic_start_rq(enic, rq_idx);
1722 : : }
1723 : :
1724 : 0 : set_mtu_done:
1725 : 0 : dev_info(enic, "MTU changed from %u to %u\n", old_mtu, new_mtu);
1726 : : rte_spinlock_unlock(&enic->mtu_lock);
1727 : 0 : return rc;
1728 : : }
1729 : :
1730 : : static void
1731 : 0 : enic_disable_overlay_offload(struct enic *enic)
1732 : : {
1733 : : /*
1734 : : * Disabling fails if the feature is provisioned but
1735 : : * not enabled. So ignore result and do not log error.
1736 : : */
1737 [ # # ]: 0 : if (enic->vxlan) {
1738 : 0 : vnic_dev_overlay_offload_ctrl(enic->vdev,
1739 : : OVERLAY_FEATURE_VXLAN, OVERLAY_OFFLOAD_DISABLE);
1740 : : }
1741 [ # # ]: 0 : if (enic->geneve) {
1742 : 0 : vnic_dev_overlay_offload_ctrl(enic->vdev,
1743 : : OVERLAY_FEATURE_GENEVE, OVERLAY_OFFLOAD_DISABLE);
1744 : : }
1745 : 0 : }
1746 : :
1747 : : static int
1748 : 0 : enic_enable_overlay_offload(struct enic *enic)
1749 : : {
1750 [ # # # # ]: 0 : if (enic->vxlan && vnic_dev_overlay_offload_ctrl(enic->vdev,
1751 : : OVERLAY_FEATURE_VXLAN, OVERLAY_OFFLOAD_ENABLE) != 0) {
1752 : 0 : dev_err(NULL, "failed to enable VXLAN offload\n");
1753 : 0 : return -EINVAL;
1754 : : }
1755 [ # # # # ]: 0 : if (enic->geneve && vnic_dev_overlay_offload_ctrl(enic->vdev,
1756 : : OVERLAY_FEATURE_GENEVE, OVERLAY_OFFLOAD_ENABLE) != 0) {
1757 : 0 : dev_err(NULL, "failed to enable Geneve offload\n");
1758 : 0 : return -EINVAL;
1759 : : }
1760 : 0 : enic->tx_offload_capa |=
1761 : 0 : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1762 [ # # ]: 0 : (enic->geneve ? RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO : 0) |
1763 [ # # ]: 0 : (enic->vxlan ? RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO : 0);
1764 : 0 : enic->tx_offload_mask |=
1765 : : RTE_MBUF_F_TX_OUTER_IPV6 |
1766 : : RTE_MBUF_F_TX_OUTER_IPV4 |
1767 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM |
1768 : : RTE_MBUF_F_TX_TUNNEL_MASK;
1769 : 0 : enic->overlay_offload = true;
1770 : :
1771 [ # # # # ]: 0 : if (enic->vxlan && enic->geneve)
1772 : 0 : dev_info(NULL, "Overlay offload is enabled (VxLAN, Geneve)\n");
1773 [ # # ]: 0 : else if (enic->vxlan)
1774 : 0 : dev_info(NULL, "Overlay offload is enabled (VxLAN)\n");
1775 : : else
1776 : 0 : dev_info(NULL, "Overlay offload is enabled (Geneve)\n");
1777 : :
1778 : : return 0;
1779 : : }
1780 : :
1781 : : static int
1782 : 0 : enic_reset_overlay_port(struct enic *enic)
1783 : : {
1784 [ # # ]: 0 : if (enic->vxlan) {
1785 : 0 : enic->vxlan_port = RTE_VXLAN_DEFAULT_PORT;
1786 : : /*
1787 : : * Reset the vxlan port to the default, as the NIC firmware
1788 : : * does not reset it automatically and keeps the old setting.
1789 : : */
1790 [ # # ]: 0 : if (vnic_dev_overlay_offload_cfg(enic->vdev,
1791 : : OVERLAY_CFG_VXLAN_PORT_UPDATE,
1792 : : RTE_VXLAN_DEFAULT_PORT)) {
1793 : 0 : dev_err(enic, "failed to update vxlan port\n");
1794 : 0 : return -EINVAL;
1795 : : }
1796 : : }
1797 [ # # ]: 0 : if (enic->geneve) {
1798 : 0 : enic->geneve_port = RTE_GENEVE_DEFAULT_PORT;
1799 [ # # ]: 0 : if (vnic_dev_overlay_offload_cfg(enic->vdev,
1800 : : OVERLAY_CFG_GENEVE_PORT_UPDATE,
1801 : : RTE_GENEVE_DEFAULT_PORT)) {
1802 : 0 : dev_err(enic, "failed to update vxlan port\n");
1803 : 0 : return -EINVAL;
1804 : : }
1805 : : }
1806 : : return 0;
1807 : : }
1808 : :
1809 : 0 : static int enic_dev_init(struct enic *enic)
1810 : : {
1811 : : int err;
1812 : 0 : struct rte_eth_dev *eth_dev = enic->rte_dev;
1813 : :
1814 : 0 : vnic_dev_intr_coal_timer_info_default(enic->vdev);
1815 : :
1816 : : /* Get vNIC configuration
1817 : : */
1818 : 0 : err = enic_get_vnic_config(enic);
1819 [ # # ]: 0 : if (err) {
1820 : 0 : dev_err(dev, "Get vNIC configuration failed, aborting\n");
1821 : 0 : return err;
1822 : : }
1823 : :
1824 : : /* Get available resource counts */
1825 : 0 : enic_get_res_counts(enic);
1826 [ # # ]: 0 : if (enic->conf_rq_count == 1) {
1827 : 0 : dev_err(enic, "Running with only 1 RQ configured in the vNIC is not supported.\n");
1828 : 0 : dev_err(enic, "Please configure 2 RQs in the vNIC for each Rx queue used by DPDK.\n");
1829 : 0 : dev_err(enic, "See the ENIC PMD guide for more information.\n");
1830 : 0 : return -EINVAL;
1831 : : }
1832 : : /* Queue counts may be zeros. rte_zmalloc returns NULL in that case. */
1833 : 0 : enic->cq = rte_zmalloc("enic_vnic_cq", sizeof(struct vnic_cq) *
1834 : 0 : enic->conf_cq_count, 8);
1835 : 0 : enic->intr = rte_zmalloc("enic_vnic_intr", sizeof(struct vnic_intr) *
1836 : 0 : enic->conf_intr_count, 8);
1837 : 0 : enic->rq = rte_zmalloc("enic_vnic_rq", sizeof(struct vnic_rq) *
1838 : 0 : enic->conf_rq_count, 8);
1839 : 0 : enic->wq = rte_zmalloc("enic_vnic_wq", sizeof(struct vnic_wq) *
1840 : 0 : enic->conf_wq_count, 8);
1841 [ # # # # ]: 0 : if (enic->conf_cq_count > 0 && enic->cq == NULL) {
1842 : 0 : dev_err(enic, "failed to allocate vnic_cq, aborting.\n");
1843 : 0 : return -1;
1844 : : }
1845 [ # # # # ]: 0 : if (enic->conf_intr_count > 0 && enic->intr == NULL) {
1846 : 0 : dev_err(enic, "failed to allocate vnic_intr, aborting.\n");
1847 : 0 : return -1;
1848 : : }
1849 [ # # # # ]: 0 : if (enic->conf_rq_count > 0 && enic->rq == NULL) {
1850 : 0 : dev_err(enic, "failed to allocate vnic_rq, aborting.\n");
1851 : 0 : return -1;
1852 : : }
1853 [ # # # # ]: 0 : if (enic->conf_wq_count > 0 && enic->wq == NULL) {
1854 : 0 : dev_err(enic, "failed to allocate vnic_wq, aborting.\n");
1855 : 0 : return -1;
1856 : : }
1857 : :
1858 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr",
1859 : : sizeof(struct rte_ether_addr) *
1860 : : ENIC_UNICAST_PERFECT_FILTERS, 0);
1861 [ # # ]: 0 : if (!eth_dev->data->mac_addrs) {
1862 : 0 : dev_err(enic, "mac addr storage alloc failed, aborting.\n");
1863 : 0 : return -1;
1864 : : }
1865 : :
1866 : : /*
1867 : : * If PF has not assigned any MAC address for VF, generate a random one.
1868 : : */
1869 [ # # ]: 0 : if (enic_is_vf(enic)) {
1870 : : struct rte_ether_addr ea;
1871 : :
1872 : : memcpy(ea.addr_bytes, enic->mac_addr, RTE_ETHER_ADDR_LEN);
1873 : : if (!rte_is_valid_assigned_ether_addr(&ea)) {
1874 : 0 : rte_eth_random_addr(ea.addr_bytes);
1875 : 0 : ENICPMD_LOG(INFO, "assigned random MAC address " RTE_ETHER_ADDR_PRT_FMT,
1876 : : RTE_ETHER_ADDR_BYTES(&ea));
1877 : 0 : memcpy(enic->mac_addr, ea.addr_bytes, RTE_ETHER_ADDR_LEN);
1878 : : }
1879 : : }
1880 : :
1881 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)enic->mac_addr,
1882 : 0 : eth_dev->data->mac_addrs);
1883 : :
1884 : 0 : vnic_dev_set_reset_flag(enic->vdev, 0);
1885 : :
1886 : 0 : LIST_INIT(&enic->flows);
1887 : :
1888 : : /* set up link status checking */
1889 : 0 : vnic_dev_notify_set(enic->vdev, -1); /* No Intr for notify */
1890 : :
1891 : 0 : enic->overlay_offload = false;
1892 : : /*
1893 : : * First, explicitly disable overlay offload as the setting is
1894 : : * sticky, and resetting vNIC may not disable it.
1895 : : */
1896 : 0 : enic_disable_overlay_offload(enic);
1897 : : /* Then, enable overlay offload according to vNIC flags */
1898 [ # # # # ]: 0 : if (!enic->disable_overlay && (enic->vxlan || enic->geneve)) {
1899 : 0 : err = enic_enable_overlay_offload(enic);
1900 [ # # ]: 0 : if (err) {
1901 : 0 : dev_info(NULL, "failed to enable overlay offload\n");
1902 : 0 : return err;
1903 : : }
1904 : : }
1905 : : /*
1906 : : * Reset the vxlan/geneve port if HW parsing is available. It
1907 : : * is always enabled regardless of overlay offload
1908 : : * enable/disable.
1909 : : */
1910 : 0 : err = enic_reset_overlay_port(enic);
1911 [ # # ]: 0 : if (err)
1912 : : return err;
1913 : :
1914 [ # # ]: 0 : if (enic_fm_init(enic))
1915 : 0 : dev_warning(enic, "Init of flowman failed.\n");
1916 : : return 0;
1917 : : }
1918 : :
1919 : 0 : static void lock_devcmd(void *priv)
1920 : : {
1921 : : struct enic *enic = priv;
1922 : :
1923 : 0 : rte_spinlock_lock(&enic->devcmd_lock);
1924 : 0 : }
1925 : :
1926 : 0 : static void unlock_devcmd(void *priv)
1927 : : {
1928 : : struct enic *enic = priv;
1929 : :
1930 : 0 : rte_spinlock_unlock(&enic->devcmd_lock);
1931 : 0 : }
1932 : :
1933 : 0 : int enic_probe(struct enic *enic)
1934 : : {
1935 : 0 : struct rte_pci_device *pdev = enic->pdev;
1936 : : int err = -1;
1937 : :
1938 : 0 : dev_debug(enic, "Initializing ENIC PMD\n");
1939 : :
1940 : : /* if this is a secondary process the hardware is already initialized */
1941 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1942 : : return 0;
1943 : :
1944 : 0 : enic->bar0.vaddr = (void *)pdev->mem_resource[0].addr;
1945 : 0 : enic->bar0.len = pdev->mem_resource[0].len;
1946 : :
1947 : : /* Register vNIC device */
1948 : 0 : enic->vdev = vnic_dev_register(NULL, enic, enic->pdev, &enic->bar0, 1);
1949 [ # # ]: 0 : if (!enic->vdev) {
1950 : 0 : dev_err(enic, "vNIC registration failed, aborting\n");
1951 : 0 : goto err_out;
1952 : : }
1953 : :
1954 : 0 : LIST_INIT(&enic->memzone_list);
1955 : : rte_spinlock_init(&enic->memzone_list_lock);
1956 : :
1957 : 0 : vnic_register_cbacks(enic->vdev,
1958 : : enic_alloc_consistent,
1959 : : enic_free_consistent);
1960 : :
1961 : : /*
1962 : : * Allocate the consistent memory for stats upfront so both primary and
1963 : : * secondary processes can dump stats.
1964 : : */
1965 : 0 : err = vnic_dev_alloc_stats_mem(enic->vdev);
1966 [ # # ]: 0 : if (err) {
1967 : 0 : dev_err(enic, "Failed to allocate cmd memory, aborting\n");
1968 : 0 : goto err_out_unregister;
1969 : : }
1970 : : /* Issue device open to get device in known state */
1971 : 0 : err = enic_dev_open(enic);
1972 [ # # ]: 0 : if (err) {
1973 : 0 : dev_err(enic, "vNIC dev open failed, aborting\n");
1974 : 0 : goto err_out_unregister;
1975 : : }
1976 : :
1977 : : /* Set ingress vlan rewrite mode before vnic initialization */
1978 : 0 : dev_debug(enic, "Set ig_vlan_rewrite_mode=%u\n",
1979 : : enic->ig_vlan_rewrite_mode);
1980 : 0 : err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
1981 : 0 : enic->ig_vlan_rewrite_mode);
1982 [ # # ]: 0 : if (err) {
1983 : 0 : dev_err(enic,
1984 : : "Failed to set ingress vlan rewrite mode, aborting.\n");
1985 : 0 : goto err_out_dev_close;
1986 : : }
1987 : :
1988 : : /* Issue device init to initialize the vnic-to-switch link.
1989 : : * We'll start with carrier off and wait for link UP
1990 : : * notification later to turn on carrier. We don't need
1991 : : * to wait here for the vnic-to-switch link initialization
1992 : : * to complete; link UP notification is the indication that
1993 : : * the process is complete.
1994 : : */
1995 : :
1996 : 0 : err = vnic_dev_init(enic->vdev, 0);
1997 [ # # ]: 0 : if (err) {
1998 : 0 : dev_err(enic, "vNIC dev init failed, aborting\n");
1999 : 0 : goto err_out_dev_close;
2000 : : }
2001 : :
2002 : 0 : err = enic_dev_init(enic);
2003 [ # # ]: 0 : if (err) {
2004 : 0 : dev_err(enic, "Device initialization failed, aborting\n");
2005 : 0 : goto err_out_dev_close;
2006 : : }
2007 : :
2008 : : /* Use a PF spinlock to serialize devcmd from PF and VF representors */
2009 [ # # ]: 0 : if (enic->switchdev_mode) {
2010 : : rte_spinlock_init(&enic->devcmd_lock);
2011 : 0 : vnic_register_lock(enic->vdev, lock_devcmd, unlock_devcmd);
2012 : : }
2013 : : return 0;
2014 : :
2015 : 0 : err_out_dev_close:
2016 : 0 : vnic_dev_close(enic->vdev);
2017 : 0 : err_out_unregister:
2018 : 0 : vnic_dev_unregister(enic->vdev);
2019 : : err_out:
2020 : : return err;
2021 : : }
2022 : :
2023 : 0 : void enic_remove(struct enic *enic)
2024 : : {
2025 : 0 : enic_dev_deinit(enic);
2026 : 0 : vnic_dev_close(enic->vdev);
2027 : 0 : vnic_dev_unregister(enic->vdev);
2028 : 0 : }
|