New upstream version 16.11.3
[deb_dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index 4e4cd16..65e10f3 100644 (file)
@@ -1591,11 +1591,15 @@ i40e_parse_link_speeds(uint16_t link_speeds)
 static int
 i40e_phy_conf_link(struct i40e_hw *hw,
                   uint8_t abilities,
-                  uint8_t force_speed)
+                  uint8_t force_speed,
+                  bool is_up)
 {
        enum i40e_status_code status;
        struct i40e_aq_get_phy_abilities_resp phy_ab;
        struct i40e_aq_set_phy_config phy_conf;
+       enum i40e_aq_phy_type cnt;
+       uint32_t phy_type_mask = 0;
+
        const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
                        I40E_AQ_PHY_FLAG_PAUSE_RX |
                        I40E_AQ_PHY_FLAG_PAUSE_RX |
@@ -1613,6 +1617,10 @@ i40e_phy_conf_link(struct i40e_hw *hw,
        if (status)
                return ret;
 
+       /* If link already up, no need to set up again */
+       if (is_up && phy_ab.phy_type != 0)
+               return I40E_SUCCESS;
+
        memset(&phy_conf, 0, sizeof(phy_conf));
 
        /* bits 0-2 use the values from get_phy_abilities_resp */
@@ -1623,13 +1631,21 @@ i40e_phy_conf_link(struct i40e_hw *hw,
        if (abilities & I40E_AQ_PHY_AN_ENABLED)
                phy_conf.link_speed = advt;
        else
-               phy_conf.link_speed = force_speed;
+               phy_conf.link_speed = is_up ? force_speed : phy_ab.link_speed;
 
        phy_conf.abilities = abilities;
 
+
+
+       /* To enable link, phy_type mask needs to include each type */
+       for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_MAX; cnt++)
+               phy_type_mask |= 1 << cnt;
+
        /* use get_phy_abilities_resp value for the rest */
-       phy_conf.phy_type = phy_ab.phy_type;
-       phy_conf.phy_type_ext = phy_ab.phy_type_ext;
+       phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
+       phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
+               I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
+               I40E_AQ_PHY_TYPE_EXT_25G_LR) : 0;
        phy_conf.fec_config = phy_ab.mod_type_ext;
        phy_conf.eee_capability = phy_ab.eee_capability;
        phy_conf.eeer = phy_ab.eeer_val;
@@ -1661,13 +1677,7 @@ i40e_apply_link_speed(struct rte_eth_dev *dev)
                abilities |= I40E_AQ_PHY_AN_ENABLED;
        abilities |= I40E_AQ_PHY_LINK_ENABLED;
 
-       /* Skip changing speed on 40G interfaces, FW does not support */
-       if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
-               speed =  I40E_LINK_SPEED_UNKNOWN;
-               abilities |= I40E_AQ_PHY_AN_ENABLED;
-       }
-
-       return i40e_phy_conf_link(hw, abilities, speed);
+       return i40e_phy_conf_link(hw, abilities, speed, true);
 }
 
 static int
@@ -1992,7 +2002,7 @@ i40e_dev_set_link_down(struct rte_eth_dev *dev)
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
-       return i40e_phy_conf_link(hw, abilities, speed);
+       return i40e_phy_conf_link(hw, abilities, speed, false);
 }
 
 int
@@ -2096,6 +2106,10 @@ i40e_update_vsi_stats(struct i40e_vsi *vsi)
        i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
                            vsi->offset_loaded, &oes->rx_broadcast,
                            &nes->rx_broadcast);
+       /* exclude CRC bytes */
+       nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
+               nes->rx_broadcast) * ETHER_CRC_LEN;
+
        i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
                            &oes->rx_discards, &nes->rx_discards);
        /* GLV_REPC not supported */
@@ -2115,6 +2129,9 @@ i40e_update_vsi_stats(struct i40e_vsi *vsi)
        i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
                            vsi->offset_loaded,  &oes->tx_broadcast,
                            &nes->tx_broadcast);
+       /* exclude CRC bytes */
+       nes->tx_bytes -= (nes->tx_unicast + nes->tx_multicast +
+               nes->tx_broadcast) * ETHER_CRC_LEN;
        /* GLV_TDPC not supported */
        i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
                            &oes->tx_errors, &nes->tx_errors);
@@ -2146,6 +2163,19 @@ i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
        struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
        struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
 
+       /* Get rx/tx bytes of internal transfer packets */
+       i40e_stat_update_48(hw, I40E_GLV_GORCH(hw->port),
+                       I40E_GLV_GORCL(hw->port),
+                       pf->offset_loaded,
+                       &pf->internal_rx_bytes_offset,
+                       &pf->internal_rx_bytes);
+
+       i40e_stat_update_48(hw, I40E_GLV_GOTCH(hw->port),
+                       I40E_GLV_GOTCL(hw->port),
+                       pf->offset_loaded,
+                       &pf->internal_tx_bytes_offset,
+                       &pf->internal_tx_bytes);
+
        /* Get statistics of struct i40e_eth_stats */
        i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
                            I40E_GLPRT_GORCL(hw->port),
@@ -2167,7 +2197,7 @@ i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
         * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
         */
        ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
-               ns->eth.rx_broadcast) * ETHER_CRC_LEN;
+               ns->eth.rx_broadcast) * ETHER_CRC_LEN + pf->internal_rx_bytes;
 
        i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
                            pf->offset_loaded, &os->eth.rx_discards,
@@ -2195,7 +2225,7 @@ i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
                            pf->offset_loaded, &os->eth.tx_broadcast,
                            &ns->eth.tx_broadcast);
        ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
-               ns->eth.tx_broadcast) * ETHER_CRC_LEN;
+               ns->eth.tx_broadcast) * ETHER_CRC_LEN + pf->internal_tx_bytes;
        /* GLPRT_TEPC not supported */
 
        /* additional port specific stats */
@@ -3992,6 +4022,8 @@ i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
        for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
                if (enabled_tcmap & (1 << i))
                        total_tc++;
+       if (total_tc == 0)
+               total_tc = 1;
        vsi->enabled_tc = enabled_tcmap;
 
        /* Number of queues per enabled TC */
@@ -4920,6 +4952,10 @@ i40e_pf_setup(struct i40e_pf *pf)
        pf->offset_loaded = FALSE;
        memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
        memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
+       pf->internal_rx_bytes = 0;
+       pf->internal_tx_bytes = 0;
+       pf->internal_rx_bytes_offset = 0;
+       pf->internal_tx_bytes_offset = 0;
 
        ret = i40e_pf_get_switch_config(pf);
        if (ret != I40E_SUCCESS) {
@@ -8317,8 +8353,9 @@ i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype)
  */
 
 /* For both X710 and XL710 */
-#define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x10000200
-#define I40E_GL_SWR_PRI_JOIN_MAP_0       0x26CE00
+#define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1     0x10000200
+#define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2     0x20000200
+#define I40E_GL_SWR_PRI_JOIN_MAP_0             0x26CE00
 
 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
 #define I40E_GL_SWR_PRI_JOIN_MAP_2       0x26CE08
@@ -8370,8 +8407,12 @@ i40e_configure_registers(struct i40e_hw *hw)
                                reg_table[i].val =
                                        I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
                        else /* For X710/XL710/XXV710 */
-                               reg_table[i].val =
-                                       I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE;
+                               if (hw->aq.fw_maj_ver < 6)
+                                       reg_table[i].val =
+                                            I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
+                               else
+                                       reg_table[i].val =
+                                            I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
                }
 
                if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {