drivers: use PCI registration macro
[dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index 1e54dfc..56bd2c6 100644 (file)
@@ -31,7 +31,6 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/queue.h>
 #include <stdio.h>
 #include <errno.h>
 #include <stdint.h>
@@ -51,6 +50,7 @@
 #include <rte_alarm.h>
 #include <rte_dev.h>
 #include <rte_eth_ctrl.h>
+#include <rte_tailq.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
@@ -454,9 +454,28 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
 
 static const struct rte_pci_id pci_id_i40e_map[] = {
-#define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
-#include "rte_pci_dev_ids.h"
-{ .vendor_id = 0, /* sentinel */ },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
+       { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_I_X722) },
+       { .vendor_id = 0, /* sentinel */ },
 };
 
 static const struct eth_dev_ops i40e_eth_dev_ops = {
@@ -648,6 +667,8 @@ static struct eth_driver rte_i40e_pmd = {
                .id_table = pci_id_i40e_map,
                .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
                        RTE_PCI_DRV_DETACHABLE,
+               .probe = rte_eth_dev_pci_probe,
+               .remove = rte_eth_dev_pci_remove,
        },
        .eth_dev_init = eth_i40e_dev_init,
        .eth_dev_uninit = eth_i40e_dev_uninit,
@@ -682,28 +703,8 @@ rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
        return 0;
 }
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
- */
-static int
-rte_i40e_pmd_init(const char *name __rte_unused,
-                 const char *params __rte_unused)
-{
-       PMD_INIT_FUNC_TRACE();
-       rte_eth_driver_register(&rte_i40e_pmd);
-
-       return 0;
-}
-
-static struct rte_driver rte_i40e_driver = {
-       .type = PMD_PDEV,
-       .init = rte_i40e_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_i40e_driver, i40e);
-DRIVER_REGISTER_PCI_TABLE(i40e, pci_id_i40e_map);
+DRIVER_REGISTER_PCI(net_i40e, rte_i40e_pmd.pci_drv);
+DRIVER_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
 
 /*
  * Initialize registers for flexible payload, which should be set by NVM.
@@ -2609,10 +2610,10 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
        if (i40e_is_40G_device(hw->device_id))
                /* For XL710 */
-               dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
+               dev_info->speed_capa = ETH_LINK_SPEED_40G;
        else
                /* For X710 */
-               dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_40G;
+               dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
 }
 
 static int
@@ -2699,16 +2700,12 @@ i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
 {
        struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        struct i40e_vsi *vsi = pf->main_vsi;
-       struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        if (mask & ETH_VLAN_FILTER_MASK) {
-               if (dev->data->dev_conf.rxmode.hw_vlan_filter) {
-                       i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid, false, NULL);
+               if (dev->data->dev_conf.rxmode.hw_vlan_filter)
                        i40e_vsi_config_vlan_filter(vsi, TRUE);
-               } else {
-                       i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid, true, NULL);
+               else
                        i40e_vsi_config_vlan_filter(vsi, FALSE);
-               }
        }
 
        if (mask & ETH_VLAN_STRIP_MASK) {
@@ -4079,6 +4076,7 @@ i40e_vsi_release(struct i40e_vsi *vsi)
        struct i40e_pf *pf;
        struct i40e_hw *hw;
        struct i40e_vsi_list *vsi_list;
+       void *temp;
        int ret;
        struct i40e_mac_filter *f;
        uint16_t user_param = vsi->user_param;
@@ -4091,25 +4089,23 @@ i40e_vsi_release(struct i40e_vsi *vsi)
 
        /* VSI has child to attach, release child first */
        if (vsi->veb) {
-               TAILQ_FOREACH(vsi_list, &vsi->veb->head, list) {
+               TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
                        if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
                                return -1;
-                       TAILQ_REMOVE(&vsi->veb->head, vsi_list, list);
                }
                i40e_veb_release(vsi->veb);
        }
 
        if (vsi->floating_veb) {
-               TAILQ_FOREACH(vsi_list, &vsi->floating_veb->head, list) {
+               TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head, list, temp) {
                        if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
                                return -1;
-                       TAILQ_REMOVE(&vsi->floating_veb->head, vsi_list, list);
                }
        }
 
        /* Remove all macvlan filters of the VSI */
        i40e_vsi_remove_all_macvlan_filter(vsi);
-       TAILQ_FOREACH(f, &vsi->mac_list, next)
+       TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
                rte_free(f);
 
        if (vsi->type != I40E_VSI_MAIN &&
@@ -4667,6 +4663,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
 {
        int i, num;
        struct i40e_mac_filter *f;
+       void *temp;
        struct i40e_mac_filter_info *mac_filter;
        enum rte_mac_filter_type desired_filter;
        int ret = I40E_SUCCESS;
@@ -4691,7 +4688,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
        i = 0;
 
        /* Remove all existing mac */
-       TAILQ_FOREACH(f, &vsi->mac_list, next) {
+       TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
                mac_filter[i] = f->mac_info;
                ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
                if (ret) {
@@ -5758,28 +5755,17 @@ i40e_set_vlan_filter(struct i40e_vsi *vsi,
                         uint16_t vlan_id, bool on)
 {
        uint32_t vid_idx, vid_bit;
-       struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
-       struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
-       int ret;
 
        if (vlan_id > ETH_VLAN_ID_MAX)
                return;
 
        vid_idx = I40E_VFTA_IDX(vlan_id);
        vid_bit = I40E_VFTA_BIT(vlan_id);
-       vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
 
-       if (on) {
-               ret = i40e_aq_add_vlan(hw, vsi->seid, &vlan_data, 1, NULL);
-               if (ret != I40E_SUCCESS)
-                       PMD_DRV_LOG(ERR, "Failed to add vlan filter");
+       if (on)
                vsi->vfta[vid_idx] |= vid_bit;
-       } else {
-               ret = i40e_aq_remove_vlan(hw, vsi->seid, &vlan_data, 1, NULL);
-               if (ret != I40E_SUCCESS)
-                       PMD_DRV_LOG(ERR, "Failed to remove vlan filter");
+       else
                vsi->vfta[vid_idx] &= ~vid_bit;
-       }
 }
 
 /**
@@ -6921,6 +6907,9 @@ i40e_get_hash_filter_global_config(struct i40e_hw *hw,
                mask &= ~(1UL << i);
                /* Bit set indicats the coresponding flow type is supported */
                g_cfg->valid_bit_mask[0] |= (1UL << i);
+               /* if flowtype is invalid, continue */
+               if (!I40E_VALID_FLOW(i))
+                       continue;
                pctype = i40e_flowtype_to_pctype(i);
                reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(pctype));
                if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK)
@@ -6992,6 +6981,9 @@ i40e_set_hash_filter_global_config(struct i40e_hw *hw,
                if (!(mask0 & (1UL << i)))
                        continue;
                mask0 &= ~(1UL << i);
+               /* if flowtype is invalid, continue */
+               if (!I40E_VALID_FLOW(i))
+                       continue;
                pctype = i40e_flowtype_to_pctype(i);
                reg = (g_cfg->sym_hash_enable_mask[0] & (1UL << i)) ?
                                I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
@@ -7554,13 +7546,11 @@ i40e_hash_filter_inset_select(struct i40e_hw *hw,
                return -EINVAL;
        }
 
-       pctype = i40e_flowtype_to_pctype(conf->flow_type);
-       if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
-               PMD_DRV_LOG(ERR, "Not supported flow type (%u)",
-                           conf->flow_type);
+       if (!I40E_VALID_FLOW(conf->flow_type)) {
+               PMD_DRV_LOG(ERR, "invalid flow_type input.");
                return -EINVAL;
        }
-
+       pctype = i40e_flowtype_to_pctype(conf->flow_type);
        ret = i40e_parse_input_set(&input_set, pctype, conf->field,
                                   conf->inset_size);
        if (ret) {
@@ -7625,12 +7615,11 @@ i40e_fdir_filter_inset_select(struct i40e_pf *pf,
                return -EINVAL;
        }
 
-       pctype = i40e_flowtype_to_pctype(conf->flow_type);
-       if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
-               PMD_DRV_LOG(ERR, "Not supported flow type (%u)",
-                           conf->flow_type);
+       if (!I40E_VALID_FLOW(conf->flow_type)) {
+               PMD_DRV_LOG(ERR, "invalid flow_type input.");
                return -EINVAL;
        }
+       pctype = i40e_flowtype_to_pctype(conf->flow_type);
        ret = i40e_parse_input_set(&input_set, pctype, conf->field,
                                   conf->inset_size);
        if (ret) {