Skip to content

Commit

Permalink
mtcp: add dpdk 19.11 support.
Browse files Browse the repository at this point in the history
- dpdk 19.11 added rte_ to some variables and struct.
- change it to support this.
  • Loading branch information
qingmin-liu authored and Qingmin Liu committed Jan 17, 2020
1 parent 0feda65 commit 8d725bf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
4 changes: 4 additions & 0 deletions dpdk-iface-kmod/dpdk_iface_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
typedef struct {
PciDevice pd;
struct rte_eth_dev_info dev_details;
#if RTE_VERSION < RTE_VERSION_NUM(19, 8, 0, 0)
struct ether_addr ports_eth_addr;
#else
struct rte_ether_addr ports_eth_addr;
#endif
} DevInfo;

static DevInfo di[RTE_MAX_ETHPORTS];
Expand Down
30 changes: 15 additions & 15 deletions mtcp/src/dpdk_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

#define ETHER_IFG 12
#define ETHER_PREAMBLE 8
#define ETHER_OVR (ETHER_CRC_LEN + ETHER_PREAMBLE + ETHER_IFG)
#define ETHER_OVR (MTCP_ETHER_CRC_LEN + ETHER_PREAMBLE + ETHER_IFG)

static const uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
static const uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
Expand All @@ -98,15 +98,15 @@ static struct rte_mempool *pktmbuf_pool[MAX_CPUS] = {NULL};
//#define DEBUG 1
#ifdef DEBUG
/* ethernet addresses of ports */
static struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
static MTCP_ETHER_ADDR ports_eth_addr[RTE_MAX_ETHPORTS];
#endif

static struct rte_eth_dev_info dev_info[RTE_MAX_ETHPORTS];

static struct rte_eth_conf port_conf = {
.rxmode = {
.mq_mode = ETH_MQ_RX_RSS,
.max_rx_pkt_len = ETHER_MAX_LEN,
.max_rx_pkt_len = MTCP_ETHER_MAX_LEN,
#if RTE_VERSION > RTE_VERSION_NUM(17, 8, 0, 0)
.offloads = (
#if RTE_VERSION < RTE_VERSION_NUM(18, 5, 0, 0)
Expand Down Expand Up @@ -412,7 +412,7 @@ dpdk_get_wptr(struct mtcp_thread_context *ctxt, int ifidx, uint16_t pktsize)
m = dpc->wmbufs[ifidx].m_table[len_of_mbuf];

/* retrieve the right write offset */
ptr = (void *)rte_pktmbuf_mtod(m, struct ether_hdr *);
ptr = (void *)rte_pktmbuf_mtod(m, MTCP_ETHER_ADDR *);
m->pkt_len = m->data_len = pktsize;
m->nb_segs = 1;
m->next = NULL;
Expand Down Expand Up @@ -467,16 +467,16 @@ dpdk_recv_pkts(struct mtcp_thread_context *ctxt, int ifidx)
struct rte_mbuf *
ip_reassemble(struct dpdk_private_context *dpc, struct rte_mbuf *m)
{
struct ether_hdr *eth_hdr;
MTCP_ETHER_ADDR *eth_hdr;
struct rte_ip_frag_tbl *tbl;
struct rte_ip_frag_death_row *dr;

/* if packet is IPv4 */
if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
struct ipv4_hdr *ip_hdr;
MTCP_IPV4_HDR *ip_hdr;

eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
ip_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
eth_hdr = rte_pktmbuf_mtod(m, MTCP_ETHER_ADDR*);
ip_hdr = (MTCP_IPV4_HDR *)(eth_hdr + 1);

/* if it is a fragmented packet, then try to reassemble. */
if (rte_ipv4_frag_pkt_is_fragmented(ip_hdr)) {
Expand Down Expand Up @@ -826,7 +826,7 @@ dpdk_dev_ioctl(struct mtcp_thread_context *ctx, int nif, int cmd, void *argp)
goto dev_ioctl_err;
m = dpc->wmbufs[eidx].m_table[len_of_mbuf - 1];
m->ol_flags = PKT_TX_IP_CKSUM | PKT_TX_IPV4;
m->l2_len = sizeof(struct ether_hdr);
m->l2_len = sizeof(MTCP_ETHER_ADDR);
m->l3_len = (iph->ihl<<2);
break;
case PKT_TX_TCP_CSUM:
Expand All @@ -835,19 +835,19 @@ dpdk_dev_ioctl(struct mtcp_thread_context *ctx, int nif, int cmd, void *argp)
m = dpc->wmbufs[eidx].m_table[len_of_mbuf - 1];
tcph = (struct tcphdr *)((unsigned char *)iph + (iph->ihl<<2));
m->ol_flags |= PKT_TX_TCP_CKSUM;
tcph->check = rte_ipv4_phdr_cksum((struct ipv4_hdr *)iph, m->ol_flags);
tcph->check = rte_ipv4_phdr_cksum((MTCP_IPV4_HDR *)iph, m->ol_flags);
break;
#ifdef ENABLELRO
case PKT_RX_TCP_LROSEG:
m = dpc->cur_rx_m;
//if (m->next != NULL)
// rte_prefetch0(rte_pktmbuf_mtod(m->next, void *));
iph = rte_pktmbuf_mtod_offset(m, struct iphdr *, sizeof(struct ether_hdr));
iph = rte_pktmbuf_mtod_offset(m, struct iphdr *, sizeof(MTCP_ETHER_ADDR));
tcph = (struct tcphdr *)((u_char *)iph + (iph->ihl << 2));
payload = (uint8_t *)tcph + (tcph->doff << 2);

seg_off = m->data_len -
sizeof(struct ether_hdr) - (iph->ihl << 2) -
sizeof(MTCP_ETHER_ADDR) - (iph->ihl << 2) -
(tcph->doff << 2);

to = (uint8_t *) argp;
Expand All @@ -870,13 +870,13 @@ dpdk_dev_ioctl(struct mtcp_thread_context *ctx, int nif, int cmd, void *argp)
if ((dev_info[nif].tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0)
goto dev_ioctl_err;
m = dpc->wmbufs[eidx].m_table[len_of_mbuf - 1];
iph = rte_pktmbuf_mtod_offset(m, struct iphdr *, sizeof(struct ether_hdr));
iph = rte_pktmbuf_mtod_offset(m, struct iphdr *, sizeof(MTCP_ETHER_ADDR));
tcph = (struct tcphdr *)((uint8_t *)iph + (iph->ihl<<2));
m->l2_len = sizeof(struct ether_hdr);
m->l2_len = sizeof(MTCP_ETHER_ADDR);
m->l3_len = (iph->ihl<<2);
m->l4_len = (tcph->doff<<2);
m->ol_flags = PKT_TX_TCP_CKSUM | PKT_TX_IP_CKSUM | PKT_TX_IPV4;
tcph->check = rte_ipv4_phdr_cksum((struct ipv4_hdr *)iph, m->ol_flags);
tcph->check = rte_ipv4_phdr_cksum((MTCP_IPV4_HDR *)iph, m->ol_flags);
break;
case PKT_RX_IP_CSUM:
if ((dev_info[nif].rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) == 0)
Expand Down
13 changes: 13 additions & 0 deletions mtcp/src/include/mtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
#define ERROR (-1)
#endif

#if RTE_VERSION < RTE_VERSION_NUM(19, 8, 0, 0)
typedef struct ether_addr MTCP_ETHER_ADDR;
typedef struct ipv4_hdr MTCP_IPV4_HDR;

#define MTCP_ETHER_MAX_LEN ETHER_MAX_LEN
#define MTCP_ETHER_CRC_LEN ETHER_CRC_LEN
#else
typedef struct rte_ether_addr MTCP_ETHER_ADDR;
typedef struct rte_ipv4_hdr MTCP_IPV4_HDR;
#define MTCP_ETHER_MAX_LEN RTE_ETHER_MAX_LEN
#define MTCP_ETHER_CRC_LEN RTE_ETHER_CRC_LEN
#endif

#define ETHERNET_HEADER_LEN 14 // sizeof(struct ethhdr)
#define IP_HEADER_LEN 20 // sizeof(struct iphdr)
#define TCP_HEADER_LEN 20 // sizeof(struct tcphdr)
Expand Down
4 changes: 4 additions & 0 deletions mtcp/src/io_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ SetNetEnv(char *dev_name_list, char *port_stat_list)
char socket_mem_str[32] = "";
// int i;
int ret, socket_mem;
#if RTE_VERSION < RTE_VERSION_NUM(19, 8, 0, 0)
static struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
#else
static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
#endif

/* STEP 1: first determine CPU mask */
mpz_init(_cpumask);
Expand Down
4 changes: 4 additions & 0 deletions mtcp/src/onvm_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ static struct rte_mempool *pktmbuf_pool = NULL;
//#define DEBUG 1
#ifdef DEBUG
/* ethernet addresses of ports */
#if RTE_VERSION < RTE_VERSION_NUM(19, 8, 0, 0)
static struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
#else
static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
#endif
#endif

static struct rte_eth_dev_info dev_info[RTE_MAX_ETHPORTS];
Expand Down

0 comments on commit 8d725bf

Please sign in to comment.