Skip to content

Commit

Permalink
iokernel: support mlx5
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuafried committed Jan 31, 2019
1 parent 254e82f commit 9bd9ef6
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*.a
[._]*.sw[a-p]
iokerneld
iokerenld-noht
iokerneld-noht
*~
.cproject
.project
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ LD = gcc
CC = gcc
AR = ar
SPARSE = sparse
MLX=$(shell lspci | grep 'ConnectX-3' || echo "")
# uncomment to autodetect MLX5
# MLX5=$(shell lspci | grep 'ConnectX-5' || echo "")
MLX4=$(shell lspci | grep 'ConnectX-3' || echo "")

CHECKFLAGS = -D__CHECKER__ -Waddress-space

Expand All @@ -21,8 +23,12 @@ ifneq ($(TCP_RX_STATS),)
CFLAGS += -DTCP_RX_STATS
endif

ifneq ($(MLX),)
CFLAGS += -DMLX
ifneq ($(MLX5),)
CFLAGS += -DMLX5
else
ifneq ($(MLX4),)
CFLAGS += -DMLX4
endif
endif

# handy for debugging
Expand Down Expand Up @@ -71,9 +77,13 @@ DPDK_LIBS += -lrte_mempool
DPDK_LIBS += -lrte_mempool_stack
DPDK_LIBS += -lrte_ring
# additional libs for running with Mellanox NICs
ifneq ($(MLX),)
ifneq ($(MLX5),)
DPDK_LIBS += -lrte_pmd_mlx5 -libverbs -lmlx5 -lmnl
else
ifneq ($(MLX4),)
DPDK_LIBS += -lrte_pmd_mlx4 -libverbs -lmlx4
endif
endif

# must be first
all: libbase.a libdune.a libnet.a libruntime.a iokerneld iokerneld-noht $(test_targets)
Expand Down
5 changes: 4 additions & 1 deletion dpdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ git submodule update --recursive
# Apply driver patches
patch -p 1 -d dpdk/ < ixgbe_18_11.patch

if lspci | grep -q 'ConnectX-3'; then

if lspci | grep -q 'ConnectX-5'; then
patch -p 1 -d dpdk/ < mlx5_18_11.patch
elif lspci | grep -q 'ConnectX-3'; then
patch -p 1 -d dpdk/ < mlx4_18_11.patch
sed -i 's/CONFIG_RTE_LIBRTE_MLX4_PMD=n/CONFIG_RTE_LIBRTE_MLX4_PMD=y/g' dpdk/config/common_base
fi
Expand Down
1 change: 1 addition & 0 deletions iokernel/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <iokernel/control.h>
#include <net/ethernet.h>

#include "mlx.h"
#include "ref.h"

/* #define STATS 1 */
Expand Down
8 changes: 2 additions & 6 deletions iokernel/dp_clients.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

#include "defs.h"

#ifdef MLX
#include <mlx4_custom.h>
#endif

#define MAC_TO_PROC_ENTRIES 128

static struct lrpc_chan_out lrpc_data_to_control;
Expand All @@ -36,7 +32,7 @@ static void dp_clients_add_client(struct proc *p)
log_err("dp_clients: failed to add MAC to hash table in add_client");

#ifdef MLX
p->mr = mlx4_manual_reg_mr(dp.port, p->region.base, p->region.len, &p->lkey);
p->mr = mlx_reg_mem(dp.port, p->region.base, p->region.len, &p->lkey);
if (!p->mr)
log_err("dp clients: failed to register memory with MLX nic");
#endif
Expand Down Expand Up @@ -78,7 +74,7 @@ static void dp_clients_remove_client(struct proc *p)
log_err("dp_clients: failed to remove MAC from hash table in remove "
"client");
#ifdef MLX
mlx4_manual_dereg_mr(p->mr);
mlx_dereg_mem(p->mr);
#endif

/* TODO: free queued packets/commands? */
Expand Down
17 changes: 17 additions & 0 deletions iokernel/mlx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#ifdef MLX4

#include <mlx4_custom.h>
#define MLX
#define mlx_reg_mem mlx4_manual_reg_mr
#define mlx_dereg_mem mlx4_manual_dereg_mr


#elif defined(MLX5)
#include <mlx5_custom.h>
#define MLX
#define mlx_reg_mem mlx5_manual_reg_mr
#define mlx_dereg_mem mlx5_manual_dereg_mr

#endif
150 changes: 150 additions & 0 deletions mlx5_18_11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
From 970312d4e39fad07a67683e24b0870efd9d7b3e1 Mon Sep 17 00:00:00 2001
From: Josh Fried <joshuafried@gmail.com>
Date: Thu, 31 Jan 2019 12:53:00 -0500
Subject: [PATCH] MLX5 support for the iokernel

---
config/common_base | 2 +-
drivers/net/mlx5/Makefile | 2 ++
drivers/net/mlx5/mlx5_custom.h | 8 ++++++++
drivers/net/mlx5/mlx5_mr.c | 17 +++++++++++++++++
drivers/net/mlx5/mlx5_mr.h | 2 ++
drivers/net/mlx5/mlx5_rxtx.h | 22 +++++++---------------
drivers/net/mlx5/rte_pmd_mlx5_version.map | 4 ++++
7 files changed, 41 insertions(+), 16 deletions(-)
create mode 100644 drivers/net/mlx5/mlx5_custom.h

diff --git a/config/common_base b/config/common_base
index d12ae98bc..616b15fed 100644
--- a/config/common_base
+++ b/config/common_base
@@ -317,7 +317,7 @@ CONFIG_RTE_LIBRTE_MLX4_DLOPEN_DEPS=n
# Compile burst-oriented Mellanox ConnectX-4, ConnectX-5 & Bluefield
# (MLX5) PMD
#
-CONFIG_RTE_LIBRTE_MLX5_PMD=n
+CONFIG_RTE_LIBRTE_MLX5_PMD=y
CONFIG_RTE_LIBRTE_MLX5_DEBUG=n
CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS=n

diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile
index 895cdfeed..a9f25ff5c 100644
--- a/drivers/net/mlx5/Makefile
+++ b/drivers/net/mlx5/Makefile
@@ -10,6 +10,8 @@ LIB_GLUE = $(LIB_GLUE_BASE).$(LIB_GLUE_VERSION)
LIB_GLUE_BASE = librte_pmd_mlx5_glue.so
LIB_GLUE_VERSION = 18.11.0

+SYMLINK-$(CONFIG_RTE_LIBRTE_MLX5_PMD)-include += mlx5_custom.h
+
# Sources.
SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5.c
ifneq ($(CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS),y)
diff --git a/drivers/net/mlx5/mlx5_custom.h b/drivers/net/mlx5/mlx5_custom.h
new file mode 100644
index 000000000..925721de9
--- /dev/null
+++ b/drivers/net/mlx5/mlx5_custom.h
@@ -0,0 +1,8 @@
+
+#ifndef RTE_PMD_MLX5_CUSTOM_H
+#define RTE_PMD_MLX5_CUSTOM_H
+
+void *mlx5_manual_reg_mr(uint8_t port_id, void *addr, size_t length, uint32_t *lkey_out);
+void mlx5_manual_dereg_mr(void *ibv_mr);
+
+#endif /* RTE_PMD_MLX5_CUSTOM_H */
diff --git a/drivers/net/mlx5/mlx5_mr.c b/drivers/net/mlx5/mlx5_mr.c
index 442b2d232..00ef98ab6 100644
--- a/drivers/net/mlx5/mlx5_mr.c
+++ b/drivers/net/mlx5/mlx5_mr.c
@@ -1368,3 +1368,20 @@ mlx5_mr_release(struct rte_eth_dev *dev)
/* Free all remaining MRs. */
mlx5_mr_garbage_collect(dev);
}
+
+void *
+mlx5_manual_reg_mr(uint8_t port_id, void *addr, size_t length, uint32_t *lkey_out)
+{
+ struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+ struct priv *priv = dev->data->dev_private;
+ struct ibv_mr *ibv_mr = mlx5_glue->reg_mr(priv->pd, addr, length, IBV_ACCESS_LOCAL_WRITE);
+ if (ibv_mr && lkey_out) *lkey_out = rte_cpu_to_be_32(ibv_mr->lkey);
+
+ return ibv_mr;
+}
+
+void
+mlx5_manual_dereg_mr(void *ibv_mr)
+{
+ mlx5_glue->dereg_mr(ibv_mr);
+}
diff --git a/drivers/net/mlx5/mlx5_mr.h b/drivers/net/mlx5/mlx5_mr.h
index a57003fe9..9db10045e 100644
--- a/drivers/net/mlx5/mlx5_mr.h
+++ b/drivers/net/mlx5/mlx5_mr.h
@@ -26,6 +26,8 @@
#include <rte_rwlock.h>
#include <rte_bitmap.h>

+#include "mlx5_custom.h"
+
/* Memory Region object. */
struct mlx5_mr {
LIST_ENTRY(mlx5_mr) mr; /**< Pointer to the prev/next entry. */
diff --git a/drivers/net/mlx5/mlx5_rxtx.h b/drivers/net/mlx5/mlx5_rxtx.h
index f47d327cf..18612cc2d 100644
--- a/drivers/net/mlx5/mlx5_rxtx.h
+++ b/drivers/net/mlx5/mlx5_rxtx.h
@@ -656,6 +656,10 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr)

#define mlx5_rx_mb2mr(rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))

+struct mem_info {
+ uint32_t lkey;
+};
+
/**
* Query LKey from a packet buffer for Tx. If not found, add the mempool.
*
@@ -668,22 +672,10 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr)
* Searched LKey on success, UINT32_MAX on no match.
*/
static __rte_always_inline uint32_t
-mlx5_tx_mb2mr(struct mlx5_txq_data *txq, struct rte_mbuf *mb)
+mlx5_tx_mb2mr(struct mlx5_txq_data *txq __rte_unused, struct rte_mbuf *mb)
{
- struct mlx5_mr_ctrl *mr_ctrl = &txq->mr_ctrl;
- uintptr_t addr = (uintptr_t)mb->buf_addr;
- uint32_t lkey;
-
- /* Check generation bit to see if there's any change on existing MRs. */
- if (unlikely(*mr_ctrl->dev_gen_ptr != mr_ctrl->cur_gen))
- mlx5_mr_flush_local_cache(mr_ctrl);
- /* Linear search on MR cache array. */
- lkey = mlx5_mr_lookup_cache(mr_ctrl->cache, &mr_ctrl->mru,
- MLX5_MR_CACHE_N, addr);
- if (likely(lkey != UINT32_MAX))
- return lkey;
- /* Take slower bottom-half on miss. */
- return mlx5_tx_mb2mr_bh(txq, mb);
+ struct mem_info *m = (struct mem_info *)(((char *) mb) + sizeof(struct rte_mbuf));
+ return m->lkey;
}

/**
diff --git a/drivers/net/mlx5/rte_pmd_mlx5_version.map b/drivers/net/mlx5/rte_pmd_mlx5_version.map
index ad607bbed..eb819010c 100644
--- a/drivers/net/mlx5/rte_pmd_mlx5_version.map
+++ b/drivers/net/mlx5/rte_pmd_mlx5_version.map
@@ -1,3 +1,7 @@
DPDK_2.2 {
local: *;
+
+ global:
+ mlx5_manual_reg_mr;
+ mlx5_manual_dereg_mr;
};
--
2.17.1

0 comments on commit 9bd9ef6

Please sign in to comment.