ethdev: query supported packet types
[dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index e7214e1..e91e966 100644 (file)
@@ -61,9 +61,8 @@
 #include "i40e_ethdev.h"
 #include "i40e_rxtx.h"
 #include "i40e_pf.h"
+#include "i40e_regs.h"
 
-/* Maximun number of MAC addresses */
-#define I40E_NUM_MACADDR_MAX       64
 #define I40E_CLEAR_PXE_WAIT_MS     200
 
 /* Maximun number of capability elements */
@@ -425,6 +424,18 @@ static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
                                          uint16_t queue_id);
 
+static int i40e_get_reg_length(struct rte_eth_dev *dev);
+
+static int i40e_get_regs(struct rte_eth_dev *dev,
+                        struct rte_dev_reg_info *regs);
+
+static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
+
+static int i40e_get_eeprom(struct rte_eth_dev *dev,
+                          struct rte_dev_eeprom_info *eeprom);
+
+static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
+                                     struct ether_addr *mac_addr);
 
 static const struct rte_pci_id pci_id_i40e_map[] = {
 #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
@@ -450,6 +461,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
        .xstats_reset                 = i40e_dev_stats_reset,
        .queue_stats_mapping_set      = i40e_dev_queue_stats_mapping_set,
        .dev_infos_get                = i40e_dev_info_get,
+       .dev_supported_ptypes_get     = i40e_dev_supported_ptypes_get,
        .vlan_filter_set              = i40e_vlan_filter_set,
        .vlan_tpid_set                = i40e_vlan_tpid_set,
        .vlan_offload_set             = i40e_vlan_offload_set,
@@ -493,6 +505,11 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
        .timesync_adjust_time         = i40e_timesync_adjust_time,
        .timesync_read_time           = i40e_timesync_read_time,
        .timesync_write_time          = i40e_timesync_write_time,
+       .get_reg_length               = i40e_get_reg_length,
+       .get_reg                      = i40e_get_regs,
+       .get_eeprom_length            = i40e_get_eeprom_length,
+       .get_eeprom                   = i40e_get_eeprom,
+       .mac_addr_set                 = i40e_set_default_mac_addr,
 };
 
 /* store statistics names and its offset in stats structure */
@@ -2076,8 +2093,7 @@ i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
                        pf->main_vsi->eth_stats.rx_discards;
        stats->ierrors  = ns->crc_errors +
                        ns->rx_length_errors + ns->rx_undersize +
-                       ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
-                       stats->imissed;
+                       ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
 
        PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
        PMD_DRV_LOG(DEBUG, "rx_bytes:            %"PRIu64"", ns->eth.rx_bytes);
@@ -3904,6 +3920,45 @@ i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
        return I40E_SUCCESS;
 }
 
+/* i40e_enable_pf_lb
+ * @pf: pointer to the pf structure
+ *
+ * allow loopback on pf
+ */
+static inline void
+i40e_enable_pf_lb(struct i40e_pf *pf)
+{
+       struct i40e_hw *hw = I40E_PF_TO_HW(pf);
+       struct i40e_vsi_context ctxt;
+       int ret;
+
+       /* Use the FW API if FW >= v5.0 */
+       if (hw->aq.fw_maj_ver < 5) {
+               PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
+               return;
+       }
+
+       memset(&ctxt, 0, sizeof(ctxt));
+       ctxt.seid = pf->main_vsi_seid;
+       ctxt.pf_num = hw->pf_id;
+       ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
+                           ret, hw->aq.asq_last_status);
+               return;
+       }
+       ctxt.flags = I40E_AQ_VSI_TYPE_PF;
+       ctxt.info.valid_sections =
+               rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
+       ctxt.info.switch_id |=
+               rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
+
+       ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
+       if (ret)
+               PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d\n",
+                           hw->aq.asq_last_status);
+}
+
 /* Setup a VSI */
 struct i40e_vsi *
 i40e_vsi_setup(struct i40e_pf *pf,
@@ -3939,6 +3994,8 @@ i40e_vsi_setup(struct i40e_pf *pf,
                        PMD_DRV_LOG(ERR, "VEB setup failed");
                        return NULL;
                }
+               /* set ALLOWLOOPBACk on pf, when veb is created */
+               i40e_enable_pf_lb(pf);
        }
 
        vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
@@ -4111,14 +4168,14 @@ i40e_vsi_setup(struct i40e_pf *pf,
                ctxt.connection_type = 0x1;
                ctxt.flags = I40E_AQ_VSI_TYPE_VF;
 
-               /**
-                * Do not configure switch ID to enable VEB switch by
-                * I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB. Because in Fortville,
-                * if the source mac address of packet sent from VF is not
-                * listed in the VEB's mac table, the VEB will switch the
-                * packet back to the VF. Need to enable it when HW issue
-                * is fixed.
-                */
+               /* Use the VEB configuration if FW >= v5.0 */
+               if (hw->aq.fw_maj_ver >= 5) {
+                       /* Configure switch ID */
+                       ctxt.info.valid_sections |=
+                       rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
+                       ctxt.info.switch_id =
+                       rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
+               }
 
                /* Configure port/vlan */
                ctxt.info.valid_sections |=
@@ -8851,3 +8908,101 @@ i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 
        return 0;
 }
+
+static int i40e_get_reg_length(__rte_unused struct rte_eth_dev *dev)
+{
+       /* Highest base addr + 32-bit word */
+       return I40E_GLGEN_STAT_CLEAR + 4;
+}
+
+static int i40e_get_regs(struct rte_eth_dev *dev,
+                        struct rte_dev_reg_info *regs)
+{
+       struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       uint32_t *ptr_data = regs->data;
+       uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
+       const struct i40e_reg_info *reg_info;
+
+       /* The first few registers have to be read using AQ operations */
+       reg_idx = 0;
+       while (i40e_regs_adminq[reg_idx].name) {
+               reg_info = &i40e_regs_adminq[reg_idx++];
+               for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
+                       for (arr_idx2 = 0;
+                                       arr_idx2 <= reg_info->count2;
+                                       arr_idx2++) {
+                               reg_offset = arr_idx * reg_info->stride1 +
+                                       arr_idx2 * reg_info->stride2;
+                               ptr_data[reg_offset >> 2] =
+                                       i40e_read_rx_ctl(hw, reg_offset);
+                       }
+       }
+
+       /* The remaining registers can be read using primitives */
+       reg_idx = 0;
+       while (i40e_regs_others[reg_idx].name) {
+               reg_info = &i40e_regs_others[reg_idx++];
+               for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
+                       for (arr_idx2 = 0;
+                                       arr_idx2 <= reg_info->count2;
+                                       arr_idx2++) {
+                               reg_offset = arr_idx * reg_info->stride1 +
+                                       arr_idx2 * reg_info->stride2;
+                               ptr_data[reg_offset >> 2] =
+                                       I40E_READ_REG(hw, reg_offset);
+                       }
+       }
+
+       return 0;
+}
+
+static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
+{
+       struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       /* Convert word count to byte count */
+       return hw->nvm.sr_size << 1;
+}
+
+static int i40e_get_eeprom(struct rte_eth_dev *dev,
+                          struct rte_dev_eeprom_info *eeprom)
+{
+       struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       uint16_t *data = eeprom->data;
+       uint16_t offset, length, cnt_words;
+       int ret_code;
+
+       offset = eeprom->offset >> 1;
+       length = eeprom->length >> 1;
+       cnt_words = length;
+
+       if (offset > hw->nvm.sr_size ||
+               offset + length > hw->nvm.sr_size) {
+               PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
+               return -EINVAL;
+       }
+
+       eeprom->magic = hw->vendor_id | (hw->device_id << 16);
+
+       ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
+       if (ret_code != I40E_SUCCESS || cnt_words != length) {
+               PMD_DRV_LOG(ERR, "EEPROM read failed.");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
+                                     struct ether_addr *mac_addr)
+{
+       struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       if (!is_valid_assigned_ether_addr(mac_addr)) {
+               PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
+               return;
+       }
+
+       /* Flags: 0x3 updates port address */
+       i40e_aq_mac_address_write(hw, 0x3, mac_addr->addr_bytes, NULL);
+}