ethdev: fix max Rx packet length
[dpdk.git] / drivers / net / ixgbe / ixgbe_pf.c
index ed5f96b..4ceb5bf 100644 (file)
@@ -15,7 +15,7 @@
 #include <rte_debug.h>
 #include <rte_eal.h>
 #include <rte_ether.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_memcpy.h>
 #include <rte_malloc.h>
 #include <rte_random.h>
@@ -66,33 +66,41 @@ ixgbe_mb_intr_setup(struct rte_eth_dev *dev)
        return 0;
 }
 
-void ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
+int ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
 {
        struct ixgbe_vf_info **vfinfo =
                IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
-       struct ixgbe_mirror_info *mirror_info =
-       IXGBE_DEV_PRIVATE_TO_PFDATA(eth_dev->data->dev_private);
        struct ixgbe_uta_info *uta_info =
        IXGBE_DEV_PRIVATE_TO_UTA(eth_dev->data->dev_private);
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
        uint16_t vf_num;
        uint8_t nb_queue;
+       int ret = 0;
 
        PMD_INIT_FUNC_TRACE();
 
        RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
        vf_num = dev_num_vf(eth_dev);
        if (vf_num == 0)
-               return;
+               return ret;
 
        *vfinfo = rte_zmalloc("vf_info", sizeof(struct ixgbe_vf_info) * vf_num, 0);
-       if (*vfinfo == NULL)
-               rte_panic("Cannot allocate memory for private VF data\n");
+       if (*vfinfo == NULL) {
+               PMD_INIT_LOG(ERR,
+                       "Cannot allocate memory for private VF data");
+               return -ENOMEM;
+       }
 
-       rte_eth_switch_domain_alloc(&(*vfinfo)->switch_domain_id);
+       ret = rte_eth_switch_domain_alloc(&(*vfinfo)->switch_domain_id);
+       if (ret) {
+               PMD_INIT_LOG(ERR,
+                       "failed to allocate switch domain for device %d", ret);
+               rte_free(*vfinfo);
+               *vfinfo = NULL;
+               return ret;
+       }
 
-       memset(mirror_info, 0, sizeof(struct ixgbe_mirror_info));
        memset(uta_info, 0, sizeof(struct ixgbe_uta_info));
        hw->mac.mc_filter_type = 0;
 
@@ -118,6 +126,8 @@ void ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
 
        /* set mb interrupt mask */
        ixgbe_mb_intr_setup(eth_dev);
+
+       return ret;
 }
 
 void ixgbe_pf_host_uninit(struct rte_eth_dev *eth_dev)
@@ -539,20 +549,45 @@ ixgbe_vf_set_vlan(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
 }
 
 static int
-ixgbe_set_vf_lpe(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *msgbuf)
+ixgbe_set_vf_lpe(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
 {
        struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       uint32_t new_mtu = msgbuf[1];
+       uint32_t max_frame = msgbuf[1];
        uint32_t max_frs;
        uint32_t hlreg0;
-       int max_frame = new_mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
 
        /* X540 and X550 support jumbo frames in IOV mode */
        if (hw->mac.type != ixgbe_mac_X540 &&
                hw->mac.type != ixgbe_mac_X550 &&
                hw->mac.type != ixgbe_mac_X550EM_x &&
-               hw->mac.type != ixgbe_mac_X550EM_a)
-               return -1;
+               hw->mac.type != ixgbe_mac_X550EM_a) {
+               struct ixgbe_vf_info *vfinfo =
+                       *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
+
+               switch (vfinfo[vf].api_version) {
+               case ixgbe_mbox_api_11:
+               case ixgbe_mbox_api_12:
+               case ixgbe_mbox_api_13:
+                        /**
+                         * Version 1.1&1.2&1.3 supports jumbo frames on VFs
+                         * if PF has jumbo frames enabled which means legacy
+                         * VFs are disabled.
+                         */
+                       if (dev->data->mtu > RTE_ETHER_MTU)
+                               break;
+                       /* fall through */
+               default:
+                       /**
+                        * If the PF or VF are running w/ jumbo frames enabled,
+                        * we return -1 as we cannot support jumbo frames on
+                        * legacy VFs.
+                        */
+                       if (max_frame > IXGBE_ETH_MAX_LEN ||
+                                       dev->data->mtu > RTE_ETHER_MTU)
+                               return -1;
+                       break;
+               }
+       }
 
        if (max_frame < RTE_ETHER_MIN_LEN ||
                        max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
@@ -560,9 +595,9 @@ ixgbe_set_vf_lpe(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *ms
 
        max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
                   IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
-       if (max_frs < new_mtu) {
+       if (max_frs < max_frame) {
                hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
-               if (new_mtu > RTE_ETHER_MAX_LEN) {
+               if (max_frame > IXGBE_ETH_MAX_LEN) {
                        dev->data->dev_conf.rxmode.offloads |=
                                DEV_RX_OFFLOAD_JUMBO_FRAME;
                        hlreg0 |= IXGBE_HLREG0_JUMBOEN;
@@ -573,7 +608,7 @@ ixgbe_set_vf_lpe(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *ms
                }
                IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
 
-               max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
+               max_frs = max_frame << IXGBE_MHADD_MFS_SHIFT;
                IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
        }