Skip to content

Commit

Permalink
Merge pull request #716 from zhangtengfei-oppo/devel
Browse files Browse the repository at this point in the history
feature: mtu config
  • Loading branch information
ywc689 authored Mar 31, 2021
2 parents af149ad + 00025f0 commit 64c4ec2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
10 changes: 7 additions & 3 deletions conf/dpvs.bond.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
! kni_name dpdk0.kni
! kni_name dpdk0.kni
}

<init> device dpdk1 {
Expand All @@ -57,6 +58,7 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
! kni_name dpdk1.kni
}
Expand All @@ -77,8 +79,9 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
! kni_name dpdk2.kni
! kni_name dpdk2.kni
}

<init> device dpdk3 {
Expand All @@ -96,8 +99,9 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
! kni_name dpdk3.kni
! kni_name dpdk3.kni
}

<init> bonding bond0 {
Expand Down
2 changes: 2 additions & 0 deletions conf/dpvs.conf.items
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ netif_defs {
pballoc 64k <64k, 64k|128k|256k>
status matched <matched, close|matched|always>
}
! mtu 1500 <1500,0-9000>
! promisc_mode <disable>
! kni_name dpdk0.kni <char[32]>
}
Expand All @@ -55,6 +56,7 @@ netif_defs {
queue_number 4
descriptor_number 256
}
! mtu 1500
! promisc_mode
! kni_name dpdk1.kni
}
Expand Down
2 changes: 2 additions & 0 deletions conf/dpvs.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
kni_name dpdk0.kni
}
Expand All @@ -57,6 +58,7 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
kni_name dpdk1.kni
}
Expand Down
6 changes: 4 additions & 2 deletions conf/dpvs.conf.single-bond.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
! kni_name dpdk0.kni
! kni_name dpdk0.kni
}

<init> device dpdk2 {
Expand All @@ -56,8 +57,9 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
! kni_name dpdk2.kni
! kni_name dpdk2.kni
}

<init> bonding bond0 {
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.single-nic.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ netif_defs {
pballoc 64k
status matched
}
! mtu 1500
! promisc_mode
kni_name dpdk0.kni
}
Expand Down
4 changes: 4 additions & 0 deletions include/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ enum {
/* maximum number of DPDK rte device */
#define NETIF_MAX_RTE_PORTS 64

#define NETIF_MAX_ETH_MTU 9000
#define NETIF_DEFAULT_ETH_MTU 1500


#define NETIF_ALIGN 32

#define NETIF_PORT_ID_INVALID 0xFF
Expand Down
35 changes: 35 additions & 0 deletions src/netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct port_conf_stream {
int rx_queue_nb;
int rx_desc_nb;
char rss[32];
int mtu;

int tx_queue_nb;
int tx_desc_nb;
Expand Down Expand Up @@ -268,6 +269,8 @@ static void device_handler(vector_t tokens)
port_cfg->tx_queue_nb = -1;
port_cfg->rx_desc_nb = NETIF_NB_RX_DESC_DEF;
port_cfg->tx_desc_nb = NETIF_NB_TX_DESC_DEF;
port_cfg->mtu = NETIF_DEFAULT_ETH_MTU;

port_cfg->promisc_mode = false;
strncpy(port_cfg->rss, "tcp", sizeof(port_cfg->rss));
port_cfg->fdir_mode = RTE_FDIR_MODE_PERFECT;
Expand Down Expand Up @@ -509,6 +512,28 @@ static void promisc_mode_handler(vector_t tokens)
current_device->promisc_mode = true;
}

static void custom_mtu_handler(vector_t tokens)
{
char *str = set_value(tokens);
int mtu = 0;
struct port_conf_stream *current_device = list_entry(port_list.next,
struct port_conf_stream, port_list_node);

assert(str);
mtu = atoi(str);
if (mtu <= 0 || mtu > NETIF_MAX_ETH_MTU) {
RTE_LOG(WARNING, NETIF, "invalid %s:MTU %s, using default %d\n",
current_device->name, str, NETIF_DEFAULT_ETH_MTU);
current_device->mtu= NETIF_DEFAULT_ETH_MTU;
} else {
RTE_LOG(INFO, NETIF, "%s:mtu = %d\n",
current_device->name, mtu);
current_device->mtu = mtu;
}

FREE_PTR(str);

}
static void kni_name_handler(vector_t tokens)
{
char *str = set_value(tokens);
Expand Down Expand Up @@ -877,6 +902,7 @@ void install_netif_keywords(void)
install_keyword("filter", fdir_filter_handler, KW_TYPE_INIT);
install_sublevel_end();
install_keyword("promisc_mode", promisc_mode_handler, KW_TYPE_INIT);
install_keyword("mtu", custom_mtu_handler,KW_TYPE_INIT);
install_keyword("kni_name", kni_name_handler, KW_TYPE_INIT);
install_sublevel_end();
install_keyword("bonding", bonding_handler, KW_TYPE_INIT);
Expand Down Expand Up @@ -3385,6 +3411,9 @@ static inline void port_mtu_set(struct netif_port *port)
mtu = t_mtu;
}
port->mtu = mtu;

rte_eth_dev_set_mtu((uint8_t)port->id,port->mtu);

}

/*
Expand Down Expand Up @@ -3516,6 +3545,7 @@ static void fill_port_config(struct netif_port *port, char *promisc_on)
port->dev_conf.fdir_conf.mode = cfg_stream->fdir_mode;
port->dev_conf.fdir_conf.pballoc = cfg_stream->fdir_pballoc;
port->dev_conf.fdir_conf.status = cfg_stream->fdir_status;
port->mtu = cfg_stream->mtu;

if (cfg_stream->rx_queue_nb > 0 && port->nrxq > cfg_stream->rx_queue_nb) {
RTE_LOG(WARNING, NETIF, "%s: rx-queues(%d) configured in workers != "
Expand All @@ -3535,6 +3565,7 @@ static void fill_port_config(struct netif_port *port, char *promisc_on)
/* using default configurations */
port->rxq_desc_nb = NETIF_NB_RX_DESC_DEF;
port->txq_desc_nb = NETIF_NB_TX_DESC_DEF;
port->mtu = NETIF_DEFAULT_ETH_MTU;
}

if (port->type == PORT_TYPE_BOND_MASTER) {
Expand All @@ -3557,9 +3588,11 @@ static void fill_port_config(struct netif_port *port, char *promisc_on)
if (cfg_stream) {
port->rxq_desc_nb = cfg_stream->rx_desc_nb;
port->txq_desc_nb = cfg_stream->tx_desc_nb;
port->mtu = cfg_stream->mtu;
} else {
port->rxq_desc_nb = NETIF_NB_RX_DESC_DEF;
port->txq_desc_nb = NETIF_NB_TX_DESC_DEF;
port->mtu = NETIF_DEFAULT_ETH_MTU;
}
}
/* enable promicuous mode if configured */
Expand Down Expand Up @@ -3662,6 +3695,8 @@ int netif_port_start(struct netif_port *port)
// device configure
if ((ret = netif_port_fdir_dstport_mask_set(port)) != EDPVS_OK)
return ret;
if ((ret = rte_eth_dev_set_mtu(port->id,port->mtu)) != EDPVS_OK)
return ret;

if (port->flag & NETIF_PORT_FLAG_TX_IP_CSUM_OFFLOAD)
port->dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
Expand Down

0 comments on commit 64c4ec2

Please sign in to comment.