summaryrefslogtreecommitdiff
path: root/drivers/net/mvneta/mvneta_ethdev.c
diff options
context:
space:
mode:
authorZyta Szpak <zr@semihalf.com>2018-10-03 09:22:11 +0200
committerFerruh Yigit <ferruh.yigit@intel.com>2018-10-11 18:53:48 +0200
commit112ef72539610e867c7b4ac94cb4c2fbb8c646b0 (patch)
tree04dad50a00ddbec5a752a095d6b66d37b749153e /drivers/net/mvneta/mvneta_ethdev.c
parentce7ea764597ef9da0a8699c0250a37e1670c9e52 (diff)
downloaddpdk-112ef72539610e867c7b4ac94cb4c2fbb8c646b0.zip
dpdk-112ef72539610e867c7b4ac94cb4c2fbb8c646b0.tar.gz
dpdk-112ef72539610e867c7b4ac94cb4c2fbb8c646b0.tar.xz
net/mvneta: support setting MTU
Add callback for setting of MTU. Signed-off-by: Natalie Samsonov <nsamsono@marvell.com> Signed-off-by: Zyta Szpak <zr@semihalf.com> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'drivers/net/mvneta/mvneta_ethdev.c')
-rw-r--r--drivers/net/mvneta/mvneta_ethdev.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/drivers/net/mvneta/mvneta_ethdev.c b/drivers/net/mvneta/mvneta_ethdev.c
index 146b249..24f87e2 100644
--- a/drivers/net/mvneta/mvneta_ethdev.c
+++ b/drivers/net/mvneta/mvneta_ethdev.c
@@ -218,6 +218,77 @@ mvneta_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
}
/**
+ * DPDK callback to change the MTU.
+ *
+ * Setting the MTU affects hardware MRU (packets larger than the MRU
+ * will be dropped).
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param mtu
+ * New MTU.
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int
+mvneta_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+ struct mvneta_priv *priv = dev->data->dev_private;
+ uint16_t mbuf_data_size = 0; /* SW buffer size */
+ uint16_t mru;
+ int ret;
+
+ mru = MRVL_NETA_MTU_TO_MRU(mtu);
+ /*
+ * min_rx_buf_size is equal to mbuf data size
+ * if pmd didn't set it differently
+ */
+ mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
+ /* Prevent PMD from:
+ * - setting mru greater than the mbuf size resulting in
+ * hw and sw buffer size mismatch
+ * - setting mtu that requires the support of scattered packets
+ * when this feature has not been enabled/supported so far.
+ */
+ if (!dev->data->scattered_rx &&
+ (mru + MRVL_NETA_PKT_OFFS > mbuf_data_size)) {
+ mru = mbuf_data_size - MRVL_NETA_PKT_OFFS;
+ mtu = MRVL_NETA_MRU_TO_MTU(mru);
+ MVNETA_LOG(WARNING, "MTU too big, max MTU possible limitted by"
+ " current mbuf size: %u. Set MTU to %u, MRU to %u",
+ mbuf_data_size, mtu, mru);
+ }
+
+ if (mtu < ETHER_MIN_MTU || mru > MVNETA_PKT_SIZE_MAX) {
+ MVNETA_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru);
+ return -EINVAL;
+ }
+
+ dev->data->mtu = mtu;
+ dev->data->dev_conf.rxmode.max_rx_pkt_len = mru - MV_MH_SIZE;
+
+ if (!priv->ppio)
+ /* It is OK. New MTU will be set later on mvneta_dev_start */
+ return 0;
+
+ ret = neta_ppio_set_mru(priv->ppio, mru);
+ if (ret) {
+ MVNETA_LOG(ERR, "Failed to change MRU");
+ return ret;
+ }
+
+ ret = neta_ppio_set_mtu(priv->ppio, mtu);
+ if (ret) {
+ MVNETA_LOG(ERR, "Failed to change MTU");
+ return ret;
+ }
+ MVNETA_LOG(INFO, "MTU changed to %u, MRU = %u", mtu, mru);
+
+ return 0;
+}
+
+/**
* DPDK callback to bring the link up.
*
* @param dev
@@ -307,6 +378,12 @@ mvneta_dev_start(struct rte_eth_dev *dev)
if (ret)
goto out;
+ ret = mvneta_mtu_set(dev, dev->data->mtu);
+ if (ret) {
+ MVNETA_LOG(ERR, "Failed to set MTU %d", dev->data->mtu);
+ goto out;
+ }
+
ret = mvneta_dev_set_link_up(dev);
if (ret) {
MVNETA_LOG(ERR, "Failed to set link up");
@@ -408,6 +485,7 @@ static const struct eth_dev_ops mvneta_ops = {
.dev_set_link_down = mvneta_dev_set_link_down,
.dev_close = mvneta_dev_close,
.mac_addr_set = mvneta_mac_addr_set,
+ .mtu_set = mvneta_mtu_set,
.dev_infos_get = mvneta_dev_infos_get,
.dev_supported_ptypes_get = mvneta_dev_supported_ptypes_get,
.rxq_info_get = mvneta_rxq_info_get,