drivers/net: do not use ethdev driver
[dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index 09c485e..ac5e181 100644 (file)
 #include <inttypes.h>
 #include <assert.h>
 
+#include <rte_eal.h>
 #include <rte_string_fns.h>
 #include <rte_pci.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_pci.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
@@ -327,8 +329,7 @@ static void i40e_stat_update_48(struct i40e_hw *hw,
                               uint64_t *offset,
                               uint64_t *stat);
 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
-static void i40e_dev_interrupt_handler(struct rte_intr_handle *handle,
-                                      void *param);
+static void i40e_dev_interrupt_handler(void *param);
 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
                                uint32_t base, uint32_t num);
 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
@@ -429,6 +430,9 @@ static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
 static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
 static void i40e_filter_restore(struct i40e_pf *pf);
 
+int i40e_logtype_init;
+int i40e_logtype_driver;
+
 static const struct rte_pci_id pci_id_i40e_map[] = {
        { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
        { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
@@ -639,16 +643,23 @@ static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
                sizeof(rte_i40e_txq_prio_strings[0]))
 
-static struct eth_driver rte_i40e_pmd = {
-       .pci_drv = {
-               .id_table = pci_id_i40e_map,
-               .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
-               .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,
-       .dev_private_size = sizeof(struct i40e_adapter),
+static int eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+       struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_probe(pci_dev,
+               sizeof(struct i40e_adapter), eth_i40e_dev_init);
+}
+
+static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev, eth_i40e_dev_uninit);
+}
+
+static struct rte_pci_driver rte_i40e_pmd = {
+       .id_table = pci_id_i40e_map,
+       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+       .probe = eth_i40e_pci_probe,
+       .remove = eth_i40e_pci_remove,
 };
 
 static inline int
@@ -679,7 +690,7 @@ rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
        return 0;
 }
 
-RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio");
 
@@ -5812,8 +5823,7 @@ i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
  *  void
  */
 static void
-i40e_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
-                          void *param)
+i40e_dev_interrupt_handler(void *param)
 {
        struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5830,7 +5840,6 @@ i40e_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
                PMD_DRV_LOG(INFO, "No interrupt event");
                goto done;
        }
-#ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
        if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
                PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
        if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
@@ -5845,7 +5854,6 @@ i40e_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
                PMD_DRV_LOG(ERR, "ICR0: HMC error");
        if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
                PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
-#endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
 
        if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
                PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
@@ -5859,7 +5867,7 @@ i40e_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
 done:
        /* Enable interrupt */
        i40e_pf_enable_irq0(hw);
-       rte_intr_enable(intr_handle);
+       rte_intr_enable(dev->intr_handle);
 }
 
 static int
@@ -7219,6 +7227,8 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
        /* Check if there is the filter in SW list */
        memset(&check_filter, 0, sizeof(check_filter));
        i40e_tunnel_filter_convert(cld_filter, &check_filter);
+       check_filter.is_to_vf = tunnel_filter->is_to_vf;
+       check_filter.vf_id = tunnel_filter->vf_id;
        node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
        if (add && node) {
                PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
@@ -10630,7 +10640,8 @@ static void
 i40e_tunnel_filter_restore(struct i40e_pf *pf)
 {
        struct i40e_hw *hw = I40E_PF_TO_HW(pf);
-       struct i40e_vsi *vsi = pf->main_vsi;
+       struct i40e_vsi *vsi;
+       struct i40e_pf_vf *vf;
        struct i40e_tunnel_filter_list
                *tunnel_list = &pf->tunnel.tunnel_list;
        struct i40e_tunnel_filter *f;
@@ -10638,6 +10649,12 @@ i40e_tunnel_filter_restore(struct i40e_pf *pf)
        bool big_buffer = 0;
 
        TAILQ_FOREACH(f, tunnel_list, rules) {
+               if (!f->is_to_vf)
+                       vsi = pf->main_vsi;
+               else {
+                       vf = &pf->vfs[f->vf_id];
+                       vsi = vf->vsi;
+               }
                memset(&cld_filter, 0, sizeof(cld_filter));
                ether_addr_copy((struct ether_addr *)&f->input.outer_mac,
                        (struct ether_addr *)&cld_filter.element.outer_mac);
@@ -10656,7 +10673,10 @@ i40e_tunnel_filter_restore(struct i40e_pf *pf)
                     I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoUDP) ||
                    ((f->input.flags &
                     I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE) ==
-                    I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE))
+                    I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE) ||
+                   ((f->input.flags &
+                    I40E_AQC_ADD_CLOUD_FILTER_CUSTOM_QINQ) ==
+                    I40E_AQC_ADD_CLOUD_FILTER_CUSTOM_QINQ))
                        big_buffer = 1;
 
                if (big_buffer)
@@ -10677,10 +10697,10 @@ i40e_filter_restore(struct i40e_pf *pf)
 }
 
 static bool
-is_device_supported(struct rte_eth_dev *dev, struct eth_driver *drv)
+is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
 {
-       if (strcmp(dev->driver->pci_drv.driver.name,
-                  drv->pci_drv.driver.name))
+       if (strcmp(dev->data->drv_name,
+                  drv->driver.name))
                return false;
 
        return true;
@@ -11478,6 +11498,32 @@ int rte_pmd_i40e_set_vf_vlan_tag(uint8_t port, uint16_t vf_id, uint8_t on)
        return ret;
 }
 
+static int
+i40e_vlan_filter_count(struct i40e_vsi *vsi)
+{
+       uint32_t j, k;
+       uint16_t vlan_id;
+       int count = 0;
+
+       for (j = 0; j < I40E_VFTA_SIZE; j++) {
+               if (!vsi->vfta[j])
+                       continue;
+
+               for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
+                       if (!(vsi->vfta[j] & (1 << k)))
+                               continue;
+
+                       vlan_id = j * I40E_UINT32_BIT_SIZE + k;
+                       if (!vlan_id)
+                               continue;
+
+                       count++;
+               }
+       }
+
+       return count;
+}
+
 int rte_pmd_i40e_set_vf_vlan_filter(uint8_t port, uint16_t vlan_id,
                                    uint64_t vf_mask, uint8_t on)
 {
@@ -11495,7 +11541,7 @@ int rte_pmd_i40e_set_vf_vlan_filter(uint8_t port, uint16_t vlan_id,
        if (!is_device_supported(dev, &rte_i40e_pmd))
                return -ENOTSUP;
 
-       if (vlan_id > ETHER_MAX_VLAN_ID) {
+       if (vlan_id > ETHER_MAX_VLAN_ID || !vlan_id) {
                PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
                return -EINVAL;
        }
@@ -11529,15 +11575,25 @@ int rte_pmd_i40e_set_vf_vlan_filter(uint8_t port, uint16_t vlan_id,
                        if (on) {
                                if (!vsi->vlan_filter_on) {
                                        vsi->vlan_filter_on = true;
+                                       i40e_aq_set_vsi_vlan_promisc(hw,
+                                                                    vsi->seid,
+                                                                    false,
+                                                                    NULL);
                                        if (!vsi->vlan_anti_spoof_on)
                                                i40e_add_rm_all_vlan_filter(
                                                        vsi, true);
                                }
-                               i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
-                                                            false, NULL);
                                ret = i40e_vsi_add_vlan(vsi, vlan_id);
                        } else {
                                ret = i40e_vsi_delete_vlan(vsi, vlan_id);
+
+                               if (!i40e_vlan_filter_count(vsi)) {
+                                       vsi->vlan_filter_on = false;
+                                       i40e_aq_set_vsi_vlan_promisc(hw,
+                                                                    vsi->seid,
+                                                                    true,
+                                                                    NULL);
+                               }
                        }
                }
        }
@@ -12408,3 +12464,15 @@ i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
                        &filter_replace_buf);
        return ret;
 }
+
+RTE_INIT(i40e_init_log);
+static void
+i40e_init_log(void)
+{
+       i40e_logtype_init = rte_log_register("pmd.i40e.init");
+       if (i40e_logtype_init >= 0)
+               rte_log_set_level(i40e_logtype_init, RTE_LOG_NOTICE);
+       i40e_logtype_driver = rte_log_register("pmd.i40e.driver");
+       if (i40e_logtype_driver >= 0)
+               rte_log_set_level(i40e_logtype_driver, RTE_LOG_NOTICE);
+}