ethdev: fix adding invalid MAC address
[dpdk.git] / drivers / net / ixgbe / ixgbe_ethdev.c
index 7b856bb..006203c 100644 (file)
@@ -183,18 +183,19 @@ static int ixgbe_dev_xstats_get(struct rte_eth_dev *dev,
 static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
                                  struct rte_eth_xstat *xstats, unsigned n);
 static int
-ixgbe_dev_xstats_get_by_ids(struct rte_eth_dev *dev, uint64_t *ids,
+ixgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
                uint64_t *values, unsigned int n);
 static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
 static void ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
 static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
-       struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit);
+       struct rte_eth_xstat_name *xstats_names,
+       __rte_unused unsigned int size);
 static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
        struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit);
-static int ixgbe_dev_xstats_get_names_by_ids(
+static int ixgbe_dev_xstats_get_names_by_id(
        __rte_unused struct rte_eth_dev *dev,
        struct rte_eth_xstat_name *xstats_names,
-       uint64_t *ids,
+       const uint64_t *ids,
        unsigned int limit);
 static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
                                             uint16_t queue_id,
@@ -247,8 +248,8 @@ static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
                                      struct rte_intr_handle *handle);
 static void ixgbe_dev_interrupt_handler(void *param);
 static void ixgbe_dev_interrupt_delayed_handler(void *param);
-static void ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
-               uint32_t index, uint32_t pool);
+static int ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
+                        uint32_t index, uint32_t pool);
 static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
 static void ixgbe_set_default_mac_addr(struct rte_eth_dev *dev,
                                           struct ether_addr *mac_addr);
@@ -304,9 +305,9 @@ static void ixgbe_configure_msix(struct rte_eth_dev *dev);
 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
                uint16_t queue_idx, uint16_t tx_rate);
 
-static void ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
-                                struct ether_addr *mac_addr,
-                                uint32_t index, uint32_t pool);
+static int ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
+                               struct ether_addr *mac_addr,
+                               uint32_t index, uint32_t pool);
 static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
 static void ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
                                             struct ether_addr *mac_addr);
@@ -531,11 +532,11 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {
        .link_update          = ixgbe_dev_link_update,
        .stats_get            = ixgbe_dev_stats_get,
        .xstats_get           = ixgbe_dev_xstats_get,
-       .xstats_get_by_ids    = ixgbe_dev_xstats_get_by_ids,
+       .xstats_get_by_id     = ixgbe_dev_xstats_get_by_id,
        .stats_reset          = ixgbe_dev_stats_reset,
        .xstats_reset         = ixgbe_dev_xstats_reset,
        .xstats_get_names     = ixgbe_dev_xstats_get_names,
-       .xstats_get_names_by_ids = ixgbe_dev_xstats_get_names_by_ids,
+       .xstats_get_names_by_id = ixgbe_dev_xstats_get_names_by_id,
        .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
        .fw_version_get       = ixgbe_fw_version_get,
        .dev_infos_get        = ixgbe_dev_info_get,
@@ -3137,7 +3138,7 @@ ixgbe_xstats_calc_num(void) {
 }
 
 static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
-       struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
+       struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned int size)
 {
        const unsigned cnt_stats = ixgbe_xstats_calc_num();
        unsigned stat, i, count;
@@ -3192,10 +3193,10 @@ static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
        return cnt_stats;
 }
 
-static int ixgbe_dev_xstats_get_names_by_ids(
+static int ixgbe_dev_xstats_get_names_by_id(
        __rte_unused struct rte_eth_dev *dev,
        struct rte_eth_xstat_name *xstats_names,
-       uint64_t *ids,
+       const uint64_t *ids,
        unsigned int limit)
 {
        if (!ids) {
@@ -3256,7 +3257,7 @@ static int ixgbe_dev_xstats_get_names_by_ids(
        uint16_t size = ixgbe_xstats_calc_num();
        struct rte_eth_xstat_name xstats_names_copy[size];
 
-       ixgbe_dev_xstats_get_names_by_ids(dev, xstats_names_copy, NULL,
+       ixgbe_dev_xstats_get_names_by_id(dev, xstats_names_copy, NULL,
                        size);
 
        for (i = 0; i < limit; i++) {
@@ -3361,7 +3362,7 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 }
 
 static int
-ixgbe_dev_xstats_get_by_ids(struct rte_eth_dev *dev, uint64_t *ids,
+ixgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
                uint64_t *values, unsigned int n)
 {
        if (!ids) {
@@ -3439,7 +3440,7 @@ ixgbe_dev_xstats_get_by_ids(struct rte_eth_dev *dev, uint64_t *ids,
        uint16_t size = ixgbe_xstats_calc_num();
        uint64_t values_copy[size];
 
-       ixgbe_dev_xstats_get_by_ids(dev, NULL, values_copy, size);
+       ixgbe_dev_xstats_get_by_id(dev, NULL, values_copy, size);
 
        for (i = 0; i < n; i++) {
                if (ids[i] >= size) {
@@ -3782,8 +3783,12 @@ ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
        struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct rte_eth_link link, old;
        ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
+       struct ixgbe_interrupt *intr =
+               IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
        int link_up;
        int diag;
+       u32 speed = 0;
+       bool autoneg = false;
 
        link.link_status = ETH_LINK_DOWN;
        link.link_speed = 0;
@@ -3793,6 +3798,14 @@ ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
 
        hw->mac.get_link_status = true;
 
+       if ((intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG) &&
+               hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
+               speed = hw->phy.autoneg_advertised;
+               if (!speed)
+                       ixgbe_get_link_capabilities(hw, &speed, &autoneg);
+               ixgbe_setup_link(hw, speed, true);
+       }
+
        /* check if it needs to wait to complete, if lsc interrupt is enabled */
        if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
                diag = ixgbe_check_link(hw, &link_speed, &link_up, 0);
@@ -3810,10 +3823,12 @@ ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
 
        if (link_up == 0) {
                rte_ixgbe_dev_atomic_write_link_status(dev, &link);
+               intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
                if (link.link_status == old.link_status)
                        return -1;
                return 0;
        }
+       intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
        link.link_status = ETH_LINK_UP;
        link.link_duplex = ETH_LINK_FULL_DUPLEX;
 
@@ -4622,14 +4637,15 @@ ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
        return 0;
 }
 
-static void
+static int
 ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
                                uint32_t index, uint32_t pool)
 {
        struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        uint32_t enable_addr = 1;
 
-       ixgbe_set_rar(hw, index, mac_addr->addr_bytes, pool, enable_addr);
+       return ixgbe_set_rar(hw, index, mac_addr->addr_bytes,
+                            pool, enable_addr);
 }
 
 static void
@@ -5625,7 +5641,7 @@ static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
        return 0;
 }
 
-static void
+static int
 ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
                     __attribute__((unused)) uint32_t index,
                     __attribute__((unused)) uint32_t pool)
@@ -5639,11 +5655,19 @@ ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
         * set of PF resources used to store VF MAC addresses.
         */
        if (memcmp(hw->mac.perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
-               return;
+               return -1;
        diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
-       if (diag == 0)
-               return;
-       PMD_DRV_LOG(ERR, "Unable to add MAC address - diag=%d", diag);
+       if (diag != 0)
+               PMD_DRV_LOG(ERR, "Unable to add MAC address "
+                           "%02x:%02x:%02x:%02x:%02x:%02x - diag=%d",
+                           mac_addr->addr_bytes[0],
+                           mac_addr->addr_bytes[1],
+                           mac_addr->addr_bytes[2],
+                           mac_addr->addr_bytes[3],
+                           mac_addr->addr_bytes[4],
+                           mac_addr->addr_bytes[5],
+                           diag);
+       return diag;
 }
 
 static void