2018-01-10 09:17:10 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright 2008-2017 Cisco Systems, Inc. All rights reserved.
|
2016-03-04 21:09:00 +00:00
|
|
|
* Copyright 2007 Nuova Systems, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rte_mbuf.h>
|
2018-01-22 00:16:22 +00:00
|
|
|
#include <rte_ethdev_driver.h>
|
2018-01-23 01:05:29 +00:00
|
|
|
#include <rte_net.h>
|
2016-03-04 21:09:00 +00:00
|
|
|
#include <rte_prefetch.h>
|
|
|
|
|
|
|
|
#include "enic_compat.h"
|
|
|
|
#include "rq_enet_desc.h"
|
|
|
|
#include "enic.h"
|
2018-10-03 20:09:27 +00:00
|
|
|
#include "enic_rxtx_common.h"
|
2017-01-09 23:04:28 +00:00
|
|
|
#include <rte_ether.h>
|
|
|
|
#include <rte_ip.h>
|
|
|
|
#include <rte_tcp.h>
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
#define RTE_PMD_USE_PREFETCH
|
|
|
|
|
|
|
|
#ifdef RTE_PMD_USE_PREFETCH
|
2016-06-03 00:22:48 +00:00
|
|
|
/*Prefetch a cache line into all cache levels. */
|
2016-03-04 21:09:00 +00:00
|
|
|
#define rte_enic_prefetch(p) rte_prefetch0(p)
|
|
|
|
#else
|
|
|
|
#define rte_enic_prefetch(p) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RTE_PMD_PACKET_PREFETCH
|
|
|
|
#define rte_packet_prefetch(p) rte_prefetch1(p)
|
|
|
|
#else
|
|
|
|
#define rte_packet_prefetch(p) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2016-09-22 17:02:46 +00:00
|
|
|
/* dummy receive function to replace actual function in
|
|
|
|
* order to do safe reconfiguration operations.
|
|
|
|
*/
|
|
|
|
uint16_t
|
|
|
|
enic_dummy_recv_pkts(__rte_unused void *rx_queue,
|
|
|
|
__rte_unused struct rte_mbuf **rx_pkts,
|
|
|
|
__rte_unused uint16_t nb_pkts)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-04 21:09:00 +00:00
|
|
|
uint16_t
|
|
|
|
enic_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
|
|
|
|
uint16_t nb_pkts)
|
|
|
|
{
|
2016-06-16 19:19:05 +00:00
|
|
|
struct vnic_rq *sop_rq = rx_queue;
|
|
|
|
struct vnic_rq *data_rq;
|
|
|
|
struct vnic_rq *rq;
|
|
|
|
struct enic *enic = vnic_dev_priv(sop_rq->vdev);
|
|
|
|
uint16_t cq_idx;
|
2018-06-29 09:29:43 +00:00
|
|
|
uint16_t rq_idx, max_rx;
|
2016-06-16 19:19:05 +00:00
|
|
|
uint16_t rq_num;
|
2016-03-04 21:09:00 +00:00
|
|
|
struct rte_mbuf *nmb, *rxmb;
|
2016-06-16 19:19:05 +00:00
|
|
|
uint16_t nb_rx = 0;
|
2016-03-04 21:09:00 +00:00
|
|
|
struct vnic_cq *cq;
|
|
|
|
volatile struct cq_desc *cqd_ptr;
|
|
|
|
uint8_t color;
|
2018-04-16 21:49:10 +00:00
|
|
|
uint8_t tnl;
|
2016-06-16 19:19:05 +00:00
|
|
|
uint16_t seg_length;
|
|
|
|
struct rte_mbuf *first_seg = sop_rq->pkt_first_seg;
|
|
|
|
struct rte_mbuf *last_seg = sop_rq->pkt_last_seg;
|
2016-03-04 21:09:00 +00:00
|
|
|
|
2016-06-16 19:19:05 +00:00
|
|
|
cq = &enic->cq[enic_cq_rq(enic, sop_rq->index)];
|
|
|
|
cq_idx = cq->to_clean; /* index of cqd, rqd, mbuf_table */
|
|
|
|
cqd_ptr = (struct cq_desc *)(cq->ring.descs) + cq_idx;
|
2018-06-29 09:29:43 +00:00
|
|
|
color = cq->last_color;
|
2016-03-04 21:09:00 +00:00
|
|
|
|
2016-06-16 19:19:05 +00:00
|
|
|
data_rq = &enic->rq[sop_rq->data_queue_idx];
|
2016-03-04 21:09:00 +00:00
|
|
|
|
2018-06-29 09:29:43 +00:00
|
|
|
/* Receive until the end of the ring, at most. */
|
|
|
|
max_rx = RTE_MIN(nb_pkts, cq->ring.desc_count - cq_idx);
|
|
|
|
|
|
|
|
while (max_rx) {
|
2016-03-04 21:09:00 +00:00
|
|
|
volatile struct rq_enet_desc *rqd_ptr;
|
|
|
|
struct cq_desc cqd;
|
2016-03-17 22:57:06 +00:00
|
|
|
uint8_t packet_error;
|
2016-06-16 19:19:05 +00:00
|
|
|
uint16_t ciflags;
|
2016-03-04 21:09:00 +00:00
|
|
|
|
2018-06-29 09:29:43 +00:00
|
|
|
max_rx--;
|
|
|
|
|
2016-03-04 21:09:00 +00:00
|
|
|
/* Check for pkts available */
|
2018-06-29 09:29:43 +00:00
|
|
|
if ((cqd_ptr->type_color & CQ_DESC_COLOR_MASK_NOSHIFT) == color)
|
2016-03-04 21:09:00 +00:00
|
|
|
break;
|
|
|
|
|
2016-06-16 19:19:05 +00:00
|
|
|
/* Get the cq descriptor and extract rq info from it */
|
2016-03-04 21:09:00 +00:00
|
|
|
cqd = *cqd_ptr;
|
2016-06-16 19:19:05 +00:00
|
|
|
rq_num = cqd.q_number & CQ_DESC_Q_NUM_MASK;
|
|
|
|
rq_idx = cqd.completed_index & CQ_DESC_COMP_NDX_MASK;
|
|
|
|
|
|
|
|
rq = &enic->rq[rq_num];
|
|
|
|
rqd_ptr = ((struct rq_enet_desc *)rq->ring.descs) + rq_idx;
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
/* allocate a new mbuf */
|
2016-05-11 14:43:46 +00:00
|
|
|
nmb = rte_mbuf_raw_alloc(rq->mp);
|
2016-03-04 21:09:00 +00:00
|
|
|
if (nmb == NULL) {
|
2016-06-03 00:22:45 +00:00
|
|
|
rte_atomic64_inc(&enic->soft_stats.rx_nombuf);
|
2016-03-04 21:09:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-17 22:57:06 +00:00
|
|
|
/* A packet error means descriptor and data are untrusted */
|
2016-06-03 00:22:46 +00:00
|
|
|
packet_error = enic_cq_rx_check_err(&cqd);
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
/* Get the mbuf to return and replace with one just allocated */
|
2016-06-16 19:19:05 +00:00
|
|
|
rxmb = rq->mbuf_ring[rq_idx];
|
|
|
|
rq->mbuf_ring[rq_idx] = nmb;
|
|
|
|
cq_idx++;
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
/* Prefetch next mbuf & desc while processing current one */
|
2016-06-16 19:19:05 +00:00
|
|
|
cqd_ptr = (struct cq_desc *)(cq->ring.descs) + cq_idx;
|
2016-03-04 21:09:00 +00:00
|
|
|
rte_enic_prefetch(cqd_ptr);
|
2016-06-16 19:19:05 +00:00
|
|
|
|
|
|
|
ciflags = enic_cq_rx_desc_ciflags(
|
|
|
|
(struct cq_enet_rq_desc *)&cqd);
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
/* Push descriptor for newly allocated mbuf */
|
2016-07-19 22:42:43 +00:00
|
|
|
nmb->data_off = RTE_PKTMBUF_HEADROOM;
|
2018-01-10 09:17:08 +00:00
|
|
|
/*
|
|
|
|
* Only the address needs to be refilled. length_type of the
|
|
|
|
* descriptor it set during initialization
|
|
|
|
* (enic_alloc_rx_queue_mbufs) and does not change.
|
|
|
|
*/
|
|
|
|
rqd_ptr->address = rte_cpu_to_le_64(nmb->buf_iova +
|
|
|
|
RTE_PKTMBUF_HEADROOM);
|
2016-03-04 21:09:00 +00:00
|
|
|
|
2016-06-16 19:19:05 +00:00
|
|
|
/* Fill in the rest of the mbuf */
|
|
|
|
seg_length = enic_cq_rx_desc_n_bytes(&cqd);
|
|
|
|
|
|
|
|
if (rq->is_sop) {
|
|
|
|
first_seg = rxmb;
|
|
|
|
first_seg->pkt_len = seg_length;
|
|
|
|
} else {
|
|
|
|
first_seg->pkt_len = (uint16_t)(first_seg->pkt_len
|
|
|
|
+ seg_length);
|
|
|
|
first_seg->nb_segs++;
|
|
|
|
last_seg->next = rxmb;
|
2016-06-03 00:22:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 21:09:00 +00:00
|
|
|
rxmb->port = enic->port_id;
|
2016-06-16 19:19:05 +00:00
|
|
|
rxmb->data_len = seg_length;
|
|
|
|
|
|
|
|
rq->rx_nb_hold++;
|
|
|
|
|
|
|
|
if (!(enic_cq_rx_desc_eop(ciflags))) {
|
|
|
|
last_seg = rxmb;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:49:10 +00:00
|
|
|
/*
|
|
|
|
* When overlay offload is enabled, CQ.fcoe indicates the
|
|
|
|
* packet is tunnelled.
|
|
|
|
*/
|
|
|
|
tnl = enic->overlay_offload &&
|
|
|
|
(ciflags & CQ_ENET_RQ_DESC_FLAGS_FCOE) != 0;
|
2016-06-16 19:19:05 +00:00
|
|
|
/* cq rx flags are only valid if eop bit is set */
|
2018-04-16 21:49:10 +00:00
|
|
|
first_seg->packet_type =
|
|
|
|
enic_cq_rx_flags_to_pkt_type(&cqd, tnl);
|
2016-06-16 19:19:05 +00:00
|
|
|
enic_cq_rx_to_pkt_flags(&cqd, first_seg);
|
2018-06-29 09:29:43 +00:00
|
|
|
|
2018-04-16 21:49:10 +00:00
|
|
|
/* Wipe the outer types set by enic_cq_rx_flags_to_pkt_type() */
|
|
|
|
if (tnl) {
|
|
|
|
first_seg->packet_type &= ~(RTE_PTYPE_L3_MASK |
|
|
|
|
RTE_PTYPE_L4_MASK);
|
|
|
|
}
|
2016-06-16 19:19:05 +00:00
|
|
|
if (unlikely(packet_error)) {
|
|
|
|
rte_pktmbuf_free(first_seg);
|
|
|
|
rte_atomic64_inc(&enic->soft_stats.rx_packet_errors);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
/* prefetch mbuf data for caller */
|
2016-06-16 19:19:05 +00:00
|
|
|
rte_packet_prefetch(RTE_PTR_ADD(first_seg->buf_addr,
|
2016-03-04 21:09:00 +00:00
|
|
|
RTE_PKTMBUF_HEADROOM));
|
|
|
|
|
|
|
|
/* store the mbuf address into the next entry of the array */
|
2016-06-16 19:19:05 +00:00
|
|
|
rx_pkts[nb_rx++] = first_seg;
|
2016-03-04 21:09:00 +00:00
|
|
|
}
|
2018-06-29 09:29:43 +00:00
|
|
|
if (unlikely(cq_idx == cq->ring.desc_count)) {
|
|
|
|
cq_idx = 0;
|
|
|
|
cq->last_color ^= CQ_DESC_COLOR_MASK_NOSHIFT;
|
|
|
|
}
|
2016-03-04 21:09:00 +00:00
|
|
|
|
2016-06-16 19:19:05 +00:00
|
|
|
sop_rq->pkt_first_seg = first_seg;
|
|
|
|
sop_rq->pkt_last_seg = last_seg;
|
|
|
|
|
|
|
|
cq->to_clean = cq_idx;
|
|
|
|
|
|
|
|
if ((sop_rq->rx_nb_hold + data_rq->rx_nb_hold) >
|
|
|
|
sop_rq->rx_free_thresh) {
|
|
|
|
if (data_rq->in_use) {
|
|
|
|
data_rq->posted_index =
|
|
|
|
enic_ring_add(data_rq->ring.desc_count,
|
|
|
|
data_rq->posted_index,
|
|
|
|
data_rq->rx_nb_hold);
|
|
|
|
data_rq->rx_nb_hold = 0;
|
|
|
|
}
|
|
|
|
sop_rq->posted_index = enic_ring_add(sop_rq->ring.desc_count,
|
|
|
|
sop_rq->posted_index,
|
|
|
|
sop_rq->rx_nb_hold);
|
|
|
|
sop_rq->rx_nb_hold = 0;
|
2016-03-04 21:09:00 +00:00
|
|
|
|
|
|
|
rte_mb();
|
2016-06-16 19:19:05 +00:00
|
|
|
if (data_rq->in_use)
|
2017-01-18 01:21:33 +00:00
|
|
|
iowrite32_relaxed(data_rq->posted_index,
|
|
|
|
&data_rq->ctrl->posted_index);
|
2016-06-16 19:19:05 +00:00
|
|
|
rte_compiler_barrier();
|
2017-01-18 01:21:33 +00:00
|
|
|
iowrite32_relaxed(sop_rq->posted_index,
|
|
|
|
&sop_rq->ctrl->posted_index);
|
2016-03-04 21:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nb_rx;
|
|
|
|
}
|
2016-06-03 00:22:48 +00:00
|
|
|
|
2018-06-29 09:29:42 +00:00
|
|
|
uint16_t
|
|
|
|
enic_noscatter_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
|
|
|
|
uint16_t nb_pkts)
|
|
|
|
{
|
|
|
|
struct rte_mbuf *mb, **rx, **rxmb;
|
|
|
|
uint16_t cq_idx, nb_rx, max_rx;
|
|
|
|
struct cq_enet_rq_desc *cqd;
|
|
|
|
struct rq_enet_desc *rqd;
|
|
|
|
unsigned int port_id;
|
|
|
|
struct vnic_cq *cq;
|
|
|
|
struct vnic_rq *rq;
|
|
|
|
struct enic *enic;
|
|
|
|
uint8_t color;
|
|
|
|
bool overlay;
|
|
|
|
bool tnl;
|
|
|
|
|
|
|
|
rq = rx_queue;
|
|
|
|
enic = vnic_dev_priv(rq->vdev);
|
|
|
|
cq = &enic->cq[enic_cq_rq(enic, rq->index)];
|
|
|
|
cq_idx = cq->to_clean;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill up the reserve of free mbufs. Below, we restock the receive
|
|
|
|
* ring with these mbufs to avoid allocation failures.
|
|
|
|
*/
|
|
|
|
if (rq->num_free_mbufs == 0) {
|
|
|
|
if (rte_mempool_get_bulk(rq->mp, (void **)rq->free_mbufs,
|
|
|
|
ENIC_RX_BURST_MAX))
|
|
|
|
return 0;
|
|
|
|
rq->num_free_mbufs = ENIC_RX_BURST_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive until the end of the ring, at most. */
|
|
|
|
max_rx = RTE_MIN(nb_pkts, rq->num_free_mbufs);
|
|
|
|
max_rx = RTE_MIN(max_rx, cq->ring.desc_count - cq_idx);
|
|
|
|
|
|
|
|
cqd = (struct cq_enet_rq_desc *)(cq->ring.descs) + cq_idx;
|
|
|
|
color = cq->last_color;
|
|
|
|
rxmb = rq->mbuf_ring + cq_idx;
|
|
|
|
port_id = enic->port_id;
|
|
|
|
overlay = enic->overlay_offload;
|
|
|
|
|
|
|
|
rx = rx_pkts;
|
|
|
|
while (max_rx) {
|
|
|
|
max_rx--;
|
|
|
|
if ((cqd->type_color & CQ_DESC_COLOR_MASK_NOSHIFT) == color)
|
|
|
|
break;
|
|
|
|
if (unlikely(cqd->bytes_written_flags &
|
|
|
|
CQ_ENET_RQ_DESC_FLAGS_TRUNCATED)) {
|
|
|
|
rte_pktmbuf_free(*rxmb++);
|
|
|
|
rte_atomic64_inc(&enic->soft_stats.rx_packet_errors);
|
|
|
|
cqd++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb = *rxmb++;
|
|
|
|
/* prefetch mbuf data for caller */
|
|
|
|
rte_packet_prefetch(RTE_PTR_ADD(mb->buf_addr,
|
|
|
|
RTE_PKTMBUF_HEADROOM));
|
|
|
|
mb->data_len = cqd->bytes_written_flags &
|
|
|
|
CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK;
|
|
|
|
mb->pkt_len = mb->data_len;
|
|
|
|
mb->port = port_id;
|
|
|
|
tnl = overlay && (cqd->completed_index_flags &
|
|
|
|
CQ_ENET_RQ_DESC_FLAGS_FCOE) != 0;
|
|
|
|
mb->packet_type =
|
|
|
|
enic_cq_rx_flags_to_pkt_type((struct cq_desc *)cqd,
|
|
|
|
tnl);
|
|
|
|
enic_cq_rx_to_pkt_flags((struct cq_desc *)cqd, mb);
|
|
|
|
/* Wipe the outer types set by enic_cq_rx_flags_to_pkt_type() */
|
|
|
|
if (tnl) {
|
|
|
|
mb->packet_type &= ~(RTE_PTYPE_L3_MASK |
|
|
|
|
RTE_PTYPE_L4_MASK);
|
|
|
|
}
|
|
|
|
cqd++;
|
|
|
|
*rx++ = mb;
|
|
|
|
}
|
|
|
|
/* Number of descriptors visited */
|
|
|
|
nb_rx = cqd - (struct cq_enet_rq_desc *)(cq->ring.descs) - cq_idx;
|
|
|
|
if (nb_rx == 0)
|
|
|
|
return 0;
|
|
|
|
rqd = ((struct rq_enet_desc *)rq->ring.descs) + cq_idx;
|
|
|
|
rxmb = rq->mbuf_ring + cq_idx;
|
|
|
|
cq_idx += nb_rx;
|
|
|
|
rq->rx_nb_hold += nb_rx;
|
|
|
|
if (unlikely(cq_idx == cq->ring.desc_count)) {
|
|
|
|
cq_idx = 0;
|
|
|
|
cq->last_color ^= CQ_DESC_COLOR_MASK_NOSHIFT;
|
|
|
|
}
|
|
|
|
cq->to_clean = cq_idx;
|
|
|
|
|
|
|
|
memcpy(rxmb, rq->free_mbufs + ENIC_RX_BURST_MAX - rq->num_free_mbufs,
|
|
|
|
sizeof(struct rte_mbuf *) * nb_rx);
|
|
|
|
rq->num_free_mbufs -= nb_rx;
|
|
|
|
while (nb_rx) {
|
|
|
|
nb_rx--;
|
|
|
|
mb = *rxmb++;
|
|
|
|
mb->data_off = RTE_PKTMBUF_HEADROOM;
|
|
|
|
rqd->address = mb->buf_iova + RTE_PKTMBUF_HEADROOM;
|
|
|
|
rqd++;
|
|
|
|
}
|
|
|
|
if (rq->rx_nb_hold > rq->rx_free_thresh) {
|
|
|
|
rq->posted_index = enic_ring_add(rq->ring.desc_count,
|
|
|
|
rq->posted_index,
|
|
|
|
rq->rx_nb_hold);
|
|
|
|
rq->rx_nb_hold = 0;
|
|
|
|
rte_wmb();
|
|
|
|
iowrite32_relaxed(rq->posted_index,
|
|
|
|
&rq->ctrl->posted_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rx - rx_pkts;
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:22:52 +00:00
|
|
|
static inline void enic_free_wq_bufs(struct vnic_wq *wq, u16 completed_index)
|
2016-06-03 00:22:48 +00:00
|
|
|
{
|
2018-06-29 09:29:37 +00:00
|
|
|
struct rte_mbuf *buf;
|
2016-06-03 00:22:52 +00:00
|
|
|
struct rte_mbuf *m, *free[ENIC_MAX_WQ_DESCS];
|
|
|
|
unsigned int nb_to_free, nb_free = 0, i;
|
|
|
|
struct rte_mempool *pool;
|
|
|
|
unsigned int tail_idx;
|
|
|
|
unsigned int desc_count = wq->ring.desc_count;
|
|
|
|
|
|
|
|
nb_to_free = enic_ring_sub(desc_count, wq->tail_idx, completed_index)
|
|
|
|
+ 1;
|
|
|
|
tail_idx = wq->tail_idx;
|
2018-06-29 09:29:37 +00:00
|
|
|
pool = wq->bufs[tail_idx]->pool;
|
2016-06-03 00:22:52 +00:00
|
|
|
for (i = 0; i < nb_to_free; i++) {
|
2018-06-29 09:29:37 +00:00
|
|
|
buf = wq->bufs[tail_idx];
|
|
|
|
m = rte_pktmbuf_prefree_seg(buf);
|
2016-07-11 19:45:01 +00:00
|
|
|
if (unlikely(m == NULL)) {
|
|
|
|
tail_idx = enic_ring_incr(desc_count, tail_idx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:22:52 +00:00
|
|
|
if (likely(m->pool == pool)) {
|
2016-07-06 15:23:01 +00:00
|
|
|
RTE_ASSERT(nb_free < ENIC_MAX_WQ_DESCS);
|
2016-06-03 00:22:52 +00:00
|
|
|
free[nb_free++] = m;
|
|
|
|
} else {
|
|
|
|
rte_mempool_put_bulk(pool, (void *)free, nb_free);
|
|
|
|
free[0] = m;
|
|
|
|
nb_free = 1;
|
|
|
|
pool = m->pool;
|
|
|
|
}
|
|
|
|
tail_idx = enic_ring_incr(desc_count, tail_idx);
|
|
|
|
}
|
2016-06-03 00:22:48 +00:00
|
|
|
|
net/enic: fix crash when freeing 0 packet to mempool
Occasionally, the amount of packets to free from the work queue ends
perfectly on a boundary to have nb_free = 0 and pool = 0. This causes
a segfault as follows:
(gdb) bt
#0 rte_mempool_default_cache
#1 rte_mempool_put_bulk (n=0, obj_table=0x7f10deff2530, mp=0x0)
#2 enic_free_wq_bufs (wq=wq@entry=0x7efabffcd5b0,
completed_index=completed_index@entry=33)
#3 0x00007f11e9c86e17 in enic_cleanup_wq (enic=<optimized out>,
wq=wq@entry=0x7efabffcd5b0)
at /usr/src/debug/openvswitch-2.6.1/dpdk-16.11/drivers/net/enic/enic_rxtx.c:442
#4 0x00007f11e9c86e5f in enic_xmit_pkts (tx_queue=0x7efabffcd5b0,
tx_pkts=0x7f10deffb1a8, nb_pkts=<optimized out>)
at /usr/src/debug/openvswitch-2.6.1/dpdk-16.11/drivers/net/enic/enic_rxtx.c:470
#5 0x00007f11e9e147ad in rte_eth_tx_burst (nb_pkts=<optimized out>,
tx_pkts=0x7f10deffb1a8, queue_id=0, port_id=<optimized out>)
This commit makes the enic wq driver match other drivers who call the
bulk free, by checking that there are actual packets to free.
Fixes: 36935afbc53c ("net/enic: refactor Tx mbuf recycling")
CC: stable@dpdk.org
Reported-by: Vincent S. Cojot <vcojot@redhat.com>
Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=1468631
Signed-off-by: Aaron Conole <aconole@redhat.com>
Reviewed-by: John Daley <johndale@cisco.com>
2017-08-02 18:02:13 +00:00
|
|
|
if (nb_free > 0)
|
|
|
|
rte_mempool_put_bulk(pool, (void **)free, nb_free);
|
2016-06-03 00:22:48 +00:00
|
|
|
|
2016-06-03 00:22:52 +00:00
|
|
|
wq->tail_idx = tail_idx;
|
|
|
|
wq->ring.desc_avail += nb_to_free;
|
2016-06-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 00:22:52 +00:00
|
|
|
unsigned int enic_cleanup_wq(__rte_unused struct enic *enic, struct vnic_wq *wq)
|
2016-06-03 00:22:48 +00:00
|
|
|
{
|
2016-06-03 00:22:52 +00:00
|
|
|
u16 completed_index;
|
|
|
|
|
|
|
|
completed_index = *((uint32_t *)wq->cqmsg_rz->addr) & 0xffff;
|
2016-06-03 00:22:48 +00:00
|
|
|
|
2016-06-03 00:22:51 +00:00
|
|
|
if (wq->last_completed_index != completed_index) {
|
2018-07-26 02:30:28 +00:00
|
|
|
enic_free_wq_bufs(wq, completed_index);
|
2016-06-03 00:22:51 +00:00
|
|
|
wq->last_completed_index = completed_index;
|
|
|
|
}
|
|
|
|
return 0;
|
2016-06-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 21:49:10 +00:00
|
|
|
uint16_t enic_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
|
2018-01-23 01:05:29 +00:00
|
|
|
uint16_t nb_pkts)
|
|
|
|
{
|
2018-04-16 21:49:10 +00:00
|
|
|
struct vnic_wq *wq = (struct vnic_wq *)tx_queue;
|
2018-01-23 01:05:29 +00:00
|
|
|
int32_t ret;
|
|
|
|
uint16_t i;
|
|
|
|
uint64_t ol_flags;
|
|
|
|
struct rte_mbuf *m;
|
|
|
|
|
|
|
|
for (i = 0; i != nb_pkts; i++) {
|
|
|
|
m = tx_pkts[i];
|
|
|
|
ol_flags = m->ol_flags;
|
2018-11-13 15:38:10 +00:00
|
|
|
if (!(ol_flags & PKT_TX_TCP_SEG)) {
|
|
|
|
if (unlikely(m->pkt_len > ENIC_TX_MAX_PKT_SIZE)) {
|
|
|
|
rte_errno = EINVAL;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint16_t header_len;
|
|
|
|
|
|
|
|
header_len = m->l2_len + m->l3_len + m->l4_len;
|
|
|
|
if (m->tso_segsz + header_len > ENIC_TX_MAX_PKT_SIZE) {
|
|
|
|
rte_errno = EINVAL;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:49:10 +00:00
|
|
|
if (ol_flags & wq->tx_offload_notsup_mask) {
|
2018-05-03 19:37:10 +00:00
|
|
|
rte_errno = ENOTSUP;
|
2018-01-23 01:05:29 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
#ifdef RTE_LIBRTE_ETHDEV_DEBUG
|
|
|
|
ret = rte_validate_tx_offload(m);
|
|
|
|
if (ret != 0) {
|
|
|
|
rte_errno = ret;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ret = rte_net_intel_cksum_prepare(m);
|
|
|
|
if (ret != 0) {
|
|
|
|
rte_errno = ret;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:22:49 +00:00
|
|
|
uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
|
2016-06-03 00:22:48 +00:00
|
|
|
uint16_t nb_pkts)
|
|
|
|
{
|
|
|
|
uint16_t index;
|
2016-06-03 00:22:53 +00:00
|
|
|
unsigned int pkt_len, data_len;
|
2016-06-03 00:22:48 +00:00
|
|
|
unsigned int nb_segs;
|
2016-06-03 00:22:53 +00:00
|
|
|
struct rte_mbuf *tx_pkt;
|
2016-06-03 00:22:48 +00:00
|
|
|
struct vnic_wq *wq = (struct vnic_wq *)tx_queue;
|
|
|
|
struct enic *enic = vnic_dev_priv(wq->vdev);
|
|
|
|
unsigned short vlan_id;
|
2016-06-03 00:22:56 +00:00
|
|
|
uint64_t ol_flags;
|
2016-06-03 00:22:57 +00:00
|
|
|
uint64_t ol_flags_mask;
|
2016-06-03 00:22:53 +00:00
|
|
|
unsigned int wq_desc_avail;
|
|
|
|
int head_idx;
|
|
|
|
unsigned int desc_count;
|
|
|
|
struct wq_enet_desc *descs, *desc_p, desc_tmp;
|
|
|
|
uint16_t mss;
|
|
|
|
uint8_t vlan_tag_insert;
|
2018-06-29 09:29:39 +00:00
|
|
|
uint8_t eop, cq;
|
2016-06-03 00:22:53 +00:00
|
|
|
uint64_t bus_addr;
|
2017-01-09 23:04:28 +00:00
|
|
|
uint8_t offload_mode;
|
|
|
|
uint16_t header_len;
|
2017-11-02 05:47:10 +00:00
|
|
|
uint64_t tso;
|
|
|
|
rte_atomic64_t *tx_oversized;
|
2016-06-03 00:22:48 +00:00
|
|
|
|
2016-06-03 00:22:53 +00:00
|
|
|
enic_cleanup_wq(enic, wq);
|
|
|
|
wq_desc_avail = vnic_wq_desc_avail(wq);
|
|
|
|
head_idx = wq->head_idx;
|
|
|
|
desc_count = wq->ring.desc_count;
|
2018-09-26 02:54:20 +00:00
|
|
|
ol_flags_mask = PKT_TX_VLAN | PKT_TX_IP_CKSUM | PKT_TX_L4_MASK;
|
2017-11-02 05:47:10 +00:00
|
|
|
tx_oversized = &enic->soft_stats.tx_oversized;
|
2016-06-03 00:22:53 +00:00
|
|
|
|
|
|
|
nb_pkts = RTE_MIN(nb_pkts, ENIC_TX_XMIT_MAX);
|
|
|
|
|
2016-06-03 00:22:48 +00:00
|
|
|
for (index = 0; index < nb_pkts; index++) {
|
|
|
|
tx_pkt = *tx_pkts++;
|
2017-02-03 01:18:40 +00:00
|
|
|
pkt_len = tx_pkt->pkt_len;
|
|
|
|
data_len = tx_pkt->data_len;
|
|
|
|
ol_flags = tx_pkt->ol_flags;
|
2016-06-03 00:22:48 +00:00
|
|
|
nb_segs = tx_pkt->nb_segs;
|
2017-11-02 05:47:10 +00:00
|
|
|
tso = ol_flags & PKT_TX_TCP_SEG;
|
2017-02-03 01:18:40 +00:00
|
|
|
|
2017-11-02 05:47:10 +00:00
|
|
|
/* drop packet if it's too big to send */
|
|
|
|
if (unlikely(!tso && pkt_len > ENIC_TX_MAX_PKT_SIZE)) {
|
2017-02-03 01:18:40 +00:00
|
|
|
rte_pktmbuf_free(tx_pkt);
|
2017-11-02 05:47:10 +00:00
|
|
|
rte_atomic64_inc(tx_oversized);
|
2017-02-03 01:18:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:22:53 +00:00
|
|
|
if (nb_segs > wq_desc_avail) {
|
2016-06-03 00:22:48 +00:00
|
|
|
if (index > 0)
|
2016-06-03 00:22:53 +00:00
|
|
|
goto post;
|
|
|
|
goto done;
|
2016-06-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 00:22:53 +00:00
|
|
|
mss = 0;
|
2018-01-10 09:17:12 +00:00
|
|
|
vlan_id = tx_pkt->vlan_tci;
|
2018-09-26 02:54:20 +00:00
|
|
|
vlan_tag_insert = !!(ol_flags & PKT_TX_VLAN);
|
2016-06-03 00:22:53 +00:00
|
|
|
bus_addr = (dma_addr_t)
|
2017-10-20 12:31:32 +00:00
|
|
|
(tx_pkt->buf_iova + tx_pkt->data_off);
|
2016-06-03 00:22:53 +00:00
|
|
|
|
|
|
|
descs = (struct wq_enet_desc *)wq->ring.descs;
|
|
|
|
desc_p = descs + head_idx;
|
|
|
|
|
|
|
|
eop = (data_len == pkt_len);
|
2017-01-09 23:04:28 +00:00
|
|
|
offload_mode = WQ_ENET_OFFLOAD_MODE_CSUM;
|
|
|
|
header_len = 0;
|
|
|
|
|
2017-11-02 05:47:10 +00:00
|
|
|
if (tso) {
|
2018-01-10 09:17:11 +00:00
|
|
|
header_len = tx_pkt->l2_len + tx_pkt->l3_len +
|
|
|
|
tx_pkt->l4_len;
|
2017-11-02 05:47:10 +00:00
|
|
|
|
|
|
|
/* Drop if non-TCP packet or TSO seg size is too big */
|
|
|
|
if (unlikely(header_len == 0 || ((tx_pkt->tso_segsz +
|
|
|
|
header_len) > ENIC_TX_MAX_PKT_SIZE))) {
|
|
|
|
rte_pktmbuf_free(tx_pkt);
|
|
|
|
rte_atomic64_inc(tx_oversized);
|
|
|
|
continue;
|
2016-06-03 00:22:57 +00:00
|
|
|
}
|
2017-11-02 05:47:10 +00:00
|
|
|
|
|
|
|
offload_mode = WQ_ENET_OFFLOAD_MODE_TSO;
|
|
|
|
mss = tx_pkt->tso_segsz;
|
2018-04-16 21:49:10 +00:00
|
|
|
/* For tunnel, need the size of outer+inner headers */
|
|
|
|
if (ol_flags & PKT_TX_TUNNEL_MASK) {
|
|
|
|
header_len += tx_pkt->outer_l2_len +
|
|
|
|
tx_pkt->outer_l3_len;
|
|
|
|
}
|
2017-01-09 23:04:28 +00:00
|
|
|
}
|
2017-11-02 05:47:10 +00:00
|
|
|
|
2017-01-09 23:04:28 +00:00
|
|
|
if ((ol_flags & ol_flags_mask) && (header_len == 0)) {
|
2016-06-03 00:22:57 +00:00
|
|
|
if (ol_flags & PKT_TX_IP_CKSUM)
|
|
|
|
mss |= ENIC_CALC_IP_CKSUM;
|
2016-06-03 00:22:53 +00:00
|
|
|
|
2016-06-03 00:22:57 +00:00
|
|
|
/* Nic uses just 1 bit for UDP and TCP */
|
|
|
|
switch (ol_flags & PKT_TX_L4_MASK) {
|
|
|
|
case PKT_TX_TCP_CKSUM:
|
|
|
|
case PKT_TX_UDP_CKSUM:
|
|
|
|
mss |= ENIC_CALC_TCP_UDP_CKSUM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-29 09:29:39 +00:00
|
|
|
wq->cq_pend++;
|
|
|
|
cq = 0;
|
|
|
|
if (eop && wq->cq_pend >= ENIC_WQ_CQ_THRESH) {
|
|
|
|
cq = 1;
|
|
|
|
wq->cq_pend = 0;
|
|
|
|
}
|
2017-01-09 23:04:28 +00:00
|
|
|
wq_enet_desc_enc(&desc_tmp, bus_addr, data_len, mss, header_len,
|
2018-06-29 09:29:39 +00:00
|
|
|
offload_mode, eop, cq, 0, vlan_tag_insert,
|
2017-01-09 23:04:28 +00:00
|
|
|
vlan_id, 0);
|
2016-06-03 00:22:53 +00:00
|
|
|
|
|
|
|
*desc_p = desc_tmp;
|
2018-06-29 09:29:37 +00:00
|
|
|
wq->bufs[head_idx] = tx_pkt;
|
2016-06-03 00:22:53 +00:00
|
|
|
head_idx = enic_ring_incr(desc_count, head_idx);
|
|
|
|
wq_desc_avail--;
|
|
|
|
|
|
|
|
if (!eop) {
|
|
|
|
for (tx_pkt = tx_pkt->next; tx_pkt; tx_pkt =
|
|
|
|
tx_pkt->next) {
|
|
|
|
data_len = tx_pkt->data_len;
|
|
|
|
|
2018-06-29 09:29:39 +00:00
|
|
|
wq->cq_pend++;
|
|
|
|
cq = 0;
|
|
|
|
if (tx_pkt->next == NULL) {
|
2016-06-03 00:22:53 +00:00
|
|
|
eop = 1;
|
2018-06-29 09:29:39 +00:00
|
|
|
if (wq->cq_pend >= ENIC_WQ_CQ_THRESH) {
|
|
|
|
cq = 1;
|
|
|
|
wq->cq_pend = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-06-03 00:22:53 +00:00
|
|
|
desc_p = descs + head_idx;
|
2017-10-20 12:31:32 +00:00
|
|
|
bus_addr = (dma_addr_t)(tx_pkt->buf_iova
|
2016-06-03 00:22:53 +00:00
|
|
|
+ tx_pkt->data_off);
|
|
|
|
wq_enet_desc_enc((struct wq_enet_desc *)
|
|
|
|
&desc_tmp, bus_addr, data_len,
|
2018-06-29 09:29:39 +00:00
|
|
|
mss, 0, offload_mode, eop, cq,
|
2017-01-09 23:04:28 +00:00
|
|
|
0, vlan_tag_insert, vlan_id,
|
|
|
|
0);
|
2016-06-03 00:22:53 +00:00
|
|
|
|
|
|
|
*desc_p = desc_tmp;
|
2018-06-29 09:29:37 +00:00
|
|
|
wq->bufs[head_idx] = tx_pkt;
|
2016-06-03 00:22:53 +00:00
|
|
|
head_idx = enic_ring_incr(desc_count, head_idx);
|
|
|
|
wq_desc_avail--;
|
2016-06-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-03 00:22:53 +00:00
|
|
|
post:
|
|
|
|
rte_wmb();
|
2017-01-18 01:21:33 +00:00
|
|
|
iowrite32_relaxed(head_idx, &wq->ctrl->posted_index);
|
2016-06-03 00:22:53 +00:00
|
|
|
done:
|
|
|
|
wq->ring.desc_avail = wq_desc_avail;
|
|
|
|
wq->head_idx = head_idx;
|
2016-06-03 00:22:48 +00:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
2016-06-03 00:22:53 +00:00
|
|
|
|
2018-06-29 09:29:40 +00:00
|
|
|
static void enqueue_simple_pkts(struct rte_mbuf **pkts,
|
|
|
|
struct wq_enet_desc *desc,
|
|
|
|
uint16_t n,
|
|
|
|
struct enic *enic)
|
|
|
|
{
|
|
|
|
struct rte_mbuf *p;
|
2018-09-26 02:54:21 +00:00
|
|
|
uint16_t mss;
|
2018-06-29 09:29:40 +00:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
n--;
|
|
|
|
p = *pkts++;
|
|
|
|
desc->address = p->buf_iova + p->data_off;
|
|
|
|
desc->length = p->pkt_len;
|
2018-09-26 02:54:21 +00:00
|
|
|
/* VLAN insert */
|
|
|
|
desc->vlan_tag = p->vlan_tci;
|
|
|
|
desc->header_length_flags &=
|
|
|
|
((1 << WQ_ENET_FLAGS_EOP_SHIFT) |
|
|
|
|
(1 << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT));
|
|
|
|
if (p->ol_flags & PKT_TX_VLAN) {
|
|
|
|
desc->header_length_flags |=
|
|
|
|
1 << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Checksum offload. We use WQ_ENET_OFFLOAD_MODE_CSUM, which
|
|
|
|
* is 0, so no need to set offload_mode.
|
|
|
|
*/
|
|
|
|
mss = 0;
|
|
|
|
if (p->ol_flags & PKT_TX_IP_CKSUM)
|
|
|
|
mss |= ENIC_CALC_IP_CKSUM << WQ_ENET_MSS_SHIFT;
|
|
|
|
if (p->ol_flags & PKT_TX_L4_MASK)
|
|
|
|
mss |= ENIC_CALC_TCP_UDP_CKSUM << WQ_ENET_MSS_SHIFT;
|
|
|
|
desc->mss_loopback = mss;
|
|
|
|
|
2018-06-29 09:29:40 +00:00
|
|
|
/*
|
|
|
|
* The app should not send oversized
|
|
|
|
* packets. tx_pkt_prepare includes a check as
|
|
|
|
* well. But some apps ignore the device max size and
|
|
|
|
* tx_pkt_prepare. Oversized packets cause WQ errrors
|
|
|
|
* and the NIC ends up disabling the whole WQ. So
|
|
|
|
* truncate packets..
|
|
|
|
*/
|
|
|
|
if (unlikely(p->pkt_len > ENIC_TX_MAX_PKT_SIZE)) {
|
|
|
|
desc->length = ENIC_TX_MAX_PKT_SIZE;
|
|
|
|
rte_atomic64_inc(&enic->soft_stats.tx_oversized);
|
|
|
|
}
|
|
|
|
desc++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t enic_simple_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
|
|
|
|
uint16_t nb_pkts)
|
|
|
|
{
|
|
|
|
unsigned int head_idx, desc_count;
|
|
|
|
struct wq_enet_desc *desc;
|
|
|
|
struct vnic_wq *wq;
|
|
|
|
struct enic *enic;
|
|
|
|
uint16_t rem, n;
|
|
|
|
|
|
|
|
wq = (struct vnic_wq *)tx_queue;
|
|
|
|
enic = vnic_dev_priv(wq->vdev);
|
|
|
|
enic_cleanup_wq(enic, wq);
|
|
|
|
/* Will enqueue this many packets in this call */
|
|
|
|
nb_pkts = RTE_MIN(nb_pkts, wq->ring.desc_avail);
|
|
|
|
if (nb_pkts == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
head_idx = wq->head_idx;
|
|
|
|
desc_count = wq->ring.desc_count;
|
|
|
|
|
|
|
|
/* Descriptors until the end of the ring */
|
|
|
|
n = desc_count - head_idx;
|
|
|
|
n = RTE_MIN(nb_pkts, n);
|
2016-06-03 00:22:53 +00:00
|
|
|
|
2018-06-29 09:29:40 +00:00
|
|
|
/* Save mbuf pointers to free later */
|
|
|
|
memcpy(wq->bufs + head_idx, tx_pkts, sizeof(struct rte_mbuf *) * n);
|
|
|
|
|
|
|
|
/* Enqueue until the ring end */
|
|
|
|
rem = nb_pkts - n;
|
|
|
|
desc = ((struct wq_enet_desc *)wq->ring.descs) + head_idx;
|
|
|
|
enqueue_simple_pkts(tx_pkts, desc, n, enic);
|
|
|
|
|
|
|
|
/* Wrap to the start of the ring */
|
|
|
|
if (rem) {
|
|
|
|
tx_pkts += n;
|
|
|
|
memcpy(wq->bufs, tx_pkts, sizeof(struct rte_mbuf *) * rem);
|
|
|
|
desc = (struct wq_enet_desc *)wq->ring.descs;
|
|
|
|
enqueue_simple_pkts(tx_pkts, desc, rem, enic);
|
|
|
|
}
|
|
|
|
rte_wmb();
|
|
|
|
|
|
|
|
/* Update head_idx and desc_avail */
|
|
|
|
wq->ring.desc_avail -= nb_pkts;
|
|
|
|
head_idx += nb_pkts;
|
|
|
|
if (head_idx >= desc_count)
|
|
|
|
head_idx -= desc_count;
|
|
|
|
wq->head_idx = head_idx;
|
|
|
|
iowrite32_relaxed(head_idx, &wq->ctrl->posted_index);
|
|
|
|
return nb_pkts;
|
|
|
|
}
|