#include <sys/socket.h>
#include <linux/if.h>
+#include <rte_bus_pci.h>
#include <rte_config.h>
#include <rte_cycles.h>
#include <rte_errno.h>
#include <rte_meter.h>
#include <rte_pci.h>
#include <rte_vhost.h>
+#include <rte_version.h>
#include "dirs.h"
#include "dp-packet.h"
#define DPDK_ETH_PORT_ID_INVALID RTE_MAX_ETHPORTS
-/* DPDK library uses uint8_t for port_id. */
-typedef uint8_t dpdk_port_t;
+/* DPDK library uses uint16_t for port_id. */
+typedef uint16_t dpdk_port_t;
#define VHOST_ENQ_RETRY_NUM 8
#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
NETDEV_RX_CHECKSUM_OFFLOAD = 1 << 0,
};
+/*
+ * In order to avoid confusion in variables names, following naming convention
+ * should be used, if possible:
+ *
+ * 'struct netdev' : 'netdev'
+ * 'struct netdev_dpdk' : 'dev'
+ * 'struct netdev_rxq' : 'rxq'
+ * 'struct netdev_rxq_dpdk' : 'rx'
+ *
+ * Example:
+ * struct netdev *netdev = netdev_from_name(name);
+ * struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ *
+ * Also, 'netdev' should be used instead of 'dev->up', where 'netdev' was
+ * already defined.
+ */
+
struct netdev_dpdk {
PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0,
dpdk_port_t port_id;
char *name = xmemdup0(devargs, strcspn(devargs, ","));
dpdk_port_t new_port_id = DPDK_ETH_PORT_ID_INVALID;
- if (!rte_eth_dev_count()
- || rte_eth_dev_get_port_by_name(name, &new_port_id)
+ if (rte_eth_dev_get_port_by_name(name, &new_port_id)
|| !rte_eth_dev_is_valid_port(new_port_id)) {
/* Device not found in DPDK, attempt to attach it */
if (!rte_eth_dev_attach(devargs, &new_port_id)) {
dropped += batch_cnt - cnt;
}
- dp_packet_batch_apply_cutlen(batch);
-
uint32_t txcnt = 0;
for (uint32_t i = 0; i < cnt; i++) {
static int
netdev_dpdk_vhost_send(struct netdev *netdev, int qid,
struct dp_packet_batch *batch,
- bool may_steal, bool concurrent_txq OVS_UNUSED)
+ bool concurrent_txq OVS_UNUSED)
{
- if (OVS_UNLIKELY(!may_steal || batch->packets[0]->source != DPBUF_DPDK)) {
+ if (OVS_UNLIKELY(batch->packets[0]->source != DPBUF_DPDK)) {
dpdk_do_tx_copy(netdev, qid, batch);
- dp_packet_delete_batch(batch, may_steal);
+ dp_packet_delete_batch(batch, true);
} else {
- dp_packet_batch_apply_cutlen(batch);
__netdev_dpdk_vhost_send(netdev, qid, batch->packets, batch->count);
}
return 0;
static inline void
netdev_dpdk_send__(struct netdev_dpdk *dev, int qid,
- struct dp_packet_batch *batch, bool may_steal,
+ struct dp_packet_batch *batch,
bool concurrent_txq)
{
if (OVS_UNLIKELY(!(dev->flags & NETDEV_UP))) {
- dp_packet_delete_batch(batch, may_steal);
+ dp_packet_delete_batch(batch, true);
return;
}
rte_spinlock_lock(&dev->tx_q[qid].tx_lock);
}
- if (OVS_UNLIKELY(!may_steal ||
- batch->packets[0]->source != DPBUF_DPDK)) {
+ if (OVS_UNLIKELY(batch->packets[0]->source != DPBUF_DPDK)) {
struct netdev *netdev = &dev->up;
dpdk_do_tx_copy(netdev, qid, batch);
- dp_packet_delete_batch(batch, may_steal);
+ dp_packet_delete_batch(batch, true);
} else {
int tx_cnt, dropped;
int batch_cnt = dp_packet_batch_size(batch);
struct rte_mbuf **pkts = (struct rte_mbuf **) batch->packets;
- dp_packet_batch_apply_cutlen(batch);
-
tx_cnt = netdev_dpdk_filter_packet_len(dev, pkts, batch_cnt);
tx_cnt = netdev_dpdk_qos_run(dev, pkts, tx_cnt, true);
dropped = batch_cnt - tx_cnt;
static int
netdev_dpdk_eth_send(struct netdev *netdev, int qid,
- struct dp_packet_batch *batch, bool may_steal,
- bool concurrent_txq)
+ struct dp_packet_batch *batch, bool concurrent_txq)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- netdev_dpdk_send__(dev, qid, batch, may_steal, concurrent_txq);
+ netdev_dpdk_send__(dev, qid, batch, concurrent_txq);
return 0;
}
smap_add_format(args, "max_vfs", "%u", dev_info.max_vfs);
smap_add_format(args, "max_vmdq_pools", "%u", dev_info.max_vmdq_pools);
+ /* Querying the DPDK library for iftype may be done in future, pending
+ * support; cf. RFC 3635 Section 3.2.4. */
+ enum { IF_TYPE_ETHERNETCSMACD = 6 };
+
+ smap_add_format(args, "if_type", "%"PRIu32, IF_TYPE_ETHERNETCSMACD);
+ smap_add_format(args, "if_descr", "%s %s", rte_version(),
+ dev_info.driver_name);
+
if (dev_info.pci_dev) {
smap_add_format(args, "pci-vendor_id", "0x%u",
dev_info.pci_dev->id.vendor_id);
if (argc > 2) {
struct netdev *netdev = netdev_from_name(argv[1]);
+
if (netdev && is_dpdk_class(netdev->netdev_class)) {
- struct netdev_dpdk *dpdk_dev = netdev_dpdk_cast(netdev);
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- ovs_mutex_lock(&dpdk_dev->mutex);
- netdev_dpdk_set_admin_state__(dpdk_dev, up);
- ovs_mutex_unlock(&dpdk_dev->mutex);
+ ovs_mutex_lock(&dev->mutex);
+ netdev_dpdk_set_admin_state__(dev, up);
+ ovs_mutex_unlock(&dev->mutex);
netdev_close(netdev);
} else {
return;
}
} else {
- struct netdev_dpdk *netdev;
+ struct netdev_dpdk *dev;
ovs_mutex_lock(&dpdk_mutex);
- LIST_FOR_EACH (netdev, list_node, &dpdk_list) {
- ovs_mutex_lock(&netdev->mutex);
- netdev_dpdk_set_admin_state__(netdev, up);
- ovs_mutex_unlock(&netdev->mutex);
+ LIST_FOR_EACH (dev, list_node, &dpdk_list) {
+ ovs_mutex_lock(&dev->mutex);
+ netdev_dpdk_set_admin_state__(dev, up);
+ ovs_mutex_unlock(&dev->mutex);
}
ovs_mutex_unlock(&dpdk_mutex);
}
ovs_mutex_lock(&dpdk_mutex);
- if (!rte_eth_dev_count() || rte_eth_dev_get_port_by_name(argv[1],
- &port_id)) {
+ if (rte_eth_dev_get_port_by_name(argv[1], &port_id)) {
response = xasprintf("Device '%s' not found in DPDK", argv[1]);
goto error;
}
free(response);
}
+static void
+netdev_dpdk_get_mempool_info(struct unixctl_conn *conn,
+ int argc, const char *argv[],
+ void *aux OVS_UNUSED)
+{
+ size_t size;
+ FILE *stream;
+ char *response = NULL;
+ struct netdev *netdev = NULL;
+
+ if (argc == 2) {
+ netdev = netdev_from_name(argv[1]);
+ if (!netdev || !is_dpdk_class(netdev->netdev_class)) {
+ unixctl_command_reply_error(conn, "Not a DPDK Interface");
+ goto out;
+ }
+ }
+
+ stream = open_memstream(&response, &size);
+ if (!stream) {
+ response = xasprintf("Unable to open memstream: %s.",
+ ovs_strerror(errno));
+ unixctl_command_reply_error(conn, response);
+ goto out;
+ }
+
+ if (netdev) {
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+
+ ovs_mutex_lock(&dev->mutex);
+ ovs_mutex_lock(&dpdk_mp_mutex);
+
+ rte_mempool_dump(stream, dev->mp);
+
+ ovs_mutex_unlock(&dpdk_mp_mutex);
+ ovs_mutex_unlock(&dev->mutex);
+ } else {
+ ovs_mutex_lock(&dpdk_mp_mutex);
+ rte_mempool_list_dump(stream);
+ ovs_mutex_unlock(&dpdk_mp_mutex);
+ }
+
+ fclose(stream);
+
+ unixctl_command_reply(conn, response);
+out:
+ free(response);
+ netdev_close(netdev);
+}
+
/*
* Set virtqueue flags so that we do not receive interrupts.
*/
"pci address of device", 1, 1,
netdev_dpdk_detach, NULL);
+ unixctl_command_register("netdev-dpdk/get-mempool-info",
+ "[netdev]", 0, 1,
+ netdev_dpdk_get_mempool_info, NULL);
+
ovsthread_once_done(&once);
}
static int
netdev_dpdk_ring_send(struct netdev *netdev, int qid,
- struct dp_packet_batch *batch, bool may_steal,
- bool concurrent_txq)
+ struct dp_packet_batch *batch, bool concurrent_txq)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
struct dp_packet *packet;
dp_packet_mbuf_rss_flag_reset(packet);
}
- netdev_dpdk_send__(dev, qid, batch, may_steal, concurrent_txq);
+ netdev_dpdk_send__(dev, qid, batch, concurrent_txq);
return 0;
}
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
int err;
+ uint64_t vhost_flags = 0;
ovs_mutex_lock(&dev->mutex);
*/
if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT)
&& strlen(dev->vhost_id)) {
- /* Register client-mode device */
- err = rte_vhost_driver_register(dev->vhost_id,
- RTE_VHOST_USER_CLIENT);
+ /* Register client-mode device. */
+ vhost_flags |= RTE_VHOST_USER_CLIENT;
+
+ /* Enable IOMMU support, if explicitly requested. */
+ if (dpdk_vhost_iommu_enabled()) {
+ vhost_flags |= RTE_VHOST_USER_IOMMU_SUPPORT;
+ }
+ err = rte_vhost_driver_register(dev->vhost_id, vhost_flags);
if (err) {
VLOG_ERR("vhost-user device setup failure for device %s\n",
dev->vhost_id);
goto unlock;
} else {
/* Configuration successful */
- dev->vhost_driver_flags |= RTE_VHOST_USER_CLIENT;
+ dev->vhost_driver_flags |= vhost_flags;
VLOG_INFO("vHost User device '%s' created in 'client' mode, "
"using client socket '%s'",
dev->up.name, dev->vhost_id);