2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #define DPDK_NB_RX_DESC_DEFAULT 512
17 #define DPDK_NB_TX_DESC_DEFAULT 512
18 #define DPDK_NB_RX_DESC_VIRTIO 256
19 #define DPDK_NB_TX_DESC_VIRTIO 256
20 #define DPDK_NB_RX_DESC_10GE 2048
21 #define DPDK_NB_TX_DESC_10GE 2048
22 #define DPDK_NB_RX_DESC_40GE (4096-128)
23 #define DPDK_NB_TX_DESC_40GE 2048
24 #define DPDK_NB_RX_DESC_ENIC (4096+1024)
26 /* These args appear by themselves */
27 #define foreach_eal_double_hyphen_predicate_arg \
35 #define foreach_eal_single_hyphen_mandatory_arg \
39 #define foreach_eal_single_hyphen_arg \
41 _(mem-alloc-request, m) \
44 /* These args are preceeded by "--" and followed by a single string */
45 #define foreach_eal_double_hyphen_arg \
52 dpdk_rx_burst ( dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
58 n_left = VLIB_FRAME_SIZE;
61 if (PREDICT_TRUE(xd->dev_type == VNET_DPDK_DEV_ETH))
65 n_this_chunk = rte_eth_rx_burst (xd->device_index, queue_id,
66 xd->rx_vectors[queue_id] + n_buffers, n_left);
67 n_buffers += n_this_chunk;
68 n_left -= n_this_chunk;
70 /* Empirically, DPDK r1.8 produces vectors w/ 32 or fewer elts */
71 if (n_this_chunk < 32)
75 else if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
77 vlib_main_t * vm = vlib_get_main();
78 vlib_buffer_main_t * bm = vm->buffer_main;
79 unsigned socket_id = rte_socket_id();
82 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
83 offset = queue_id * VIRTIO_QNUM;
85 struct vhost_virtqueue *vq =
86 xd->vu_vhost_dev.virtqueue[offset + VIRTIO_TXQ];
88 if (PREDICT_FALSE(!vq->enabled))
91 if (PREDICT_FALSE(!xd->vu_is_running))
95 n_buffers = rte_vhost_dequeue_burst(&xd->vu_vhost_dev, offset + VIRTIO_TXQ,
96 bm->pktmbuf_pools[socket_id],
97 xd->rx_vectors[queue_id], VLIB_FRAME_SIZE);
100 struct rte_mbuf **pkts = xd->rx_vectors[queue_id];
101 for (i = 0; i < n_buffers; i++) {
102 struct rte_mbuf *buff = pkts[i];
103 bytes += rte_pktmbuf_data_len(buff);
106 f64 now = vlib_time_now (vm);
108 dpdk_vu_vring *vring = NULL;
109 /* send pending interrupts if needed */
110 if (dpdk_vhost_user_want_interrupt(xd, offset + VIRTIO_TXQ)) {
111 vring = &(xd->vu_intf->vrings[offset + VIRTIO_TXQ]);
112 vring->n_since_last_int += n_buffers;
114 if ((vring->n_since_last_int && (vring->int_deadline < now))
115 || (vring->n_since_last_int > dm->conf->vhost_coalesce_frames))
116 dpdk_vhost_user_send_interrupt(vm, xd, offset + VIRTIO_TXQ);
119 vring = &(xd->vu_intf->vrings[offset + VIRTIO_RXQ]);
120 vring->packets += n_buffers;
121 vring->bytes += bytes;
123 if (dpdk_vhost_user_want_interrupt(xd, offset + VIRTIO_RXQ)) {
124 if (vring->n_since_last_int && (vring->int_deadline < now))
125 dpdk_vhost_user_send_interrupt(vm, xd, offset + VIRTIO_RXQ);
129 #ifdef RTE_LIBRTE_KNI
130 else if (xd->dev_type == VNET_DPDK_DEV_KNI)
132 n_buffers = rte_kni_rx_burst(xd->kni, xd->rx_vectors[queue_id], VLIB_FRAME_SIZE);
133 rte_kni_handle_request(xd->kni);
146 dpdk_get_xstats (dpdk_device_t * xd)
149 if ((len = rte_eth_xstats_get(xd->device_index, NULL, 0)) > 0)
151 vec_validate(xd->xstats, len - 1);
152 vec_validate(xd->last_cleared_xstats, len - 1);
154 len = rte_eth_xstats_get(xd->device_index, xd->xstats, vec_len(xd->xstats));
156 ASSERT(vec_len(xd->xstats) == len);
157 ASSERT(vec_len(xd->last_cleared_xstats) == len);
159 _vec_len(xd->xstats) = len;
160 _vec_len(xd->last_cleared_xstats) = len;
167 dpdk_update_counters (dpdk_device_t * xd, f64 now)
169 vlib_simple_counter_main_t * cm;
170 vnet_main_t * vnm = vnet_get_main();
171 u32 my_cpu = os_get_cpu_number();
172 u64 rxerrors, last_rxerrors;
174 /* only update counters for PMD interfaces */
175 if (xd->dev_type != VNET_DPDK_DEV_ETH)
179 * DAW-FIXME: VMXNET3 device stop/start doesn't work,
180 * therefore fake the stop in the dpdk driver by
181 * silently dropping all of the incoming pkts instead of
182 * stopping the driver / hardware.
184 if (xd->admin_up != 0xff)
186 xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
187 clib_memcpy (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
188 rte_eth_stats_get (xd->device_index, &xd->stats);
190 /* maybe bump interface rx no buffer counter */
191 if (PREDICT_FALSE (xd->stats.rx_nombuf != xd->last_stats.rx_nombuf))
193 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
194 VNET_INTERFACE_COUNTER_RX_NO_BUF);
196 vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
197 xd->stats.rx_nombuf -
198 xd->last_stats.rx_nombuf);
201 /* missed pkt counter */
202 if (PREDICT_FALSE (xd->stats.imissed != xd->last_stats.imissed))
204 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
205 VNET_INTERFACE_COUNTER_RX_MISS);
207 vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
209 xd->last_stats.imissed);
211 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
212 rxerrors = xd->stats.ierrors;
213 last_rxerrors = xd->last_stats.ierrors;
215 rxerrors = xd->stats.ibadcrc
216 + xd->stats.ibadlen + xd->stats.ierrors;
217 last_rxerrors = xd->last_stats.ibadcrc
218 + xd->last_stats.ibadlen + xd->last_stats.ierrors;
221 if (PREDICT_FALSE (rxerrors != last_rxerrors))
223 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
224 VNET_INTERFACE_COUNTER_RX_ERROR);
226 vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
227 rxerrors - last_rxerrors);