drivers/net: do not use ethdev driver
[dpdk.git] / drivers / net / i40e / i40e_ethdev_vf.c
index b292d1d..cd9e51f 100644 (file)
@@ -55,6 +55,7 @@
 #include <rte_alarm.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_pci.h>
 #include <rte_atomic.h>
 #include <rte_malloc.h>
 #include <rte_dev.h>
@@ -152,6 +153,8 @@ static int i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
 static int i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
                                        struct rte_eth_rss_conf *rss_conf);
 static int i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
+static void i40evf_set_default_mac_addr(struct rte_eth_dev *dev,
+                                       struct ether_addr *mac_addr);
 static int
 i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
 static int
@@ -215,6 +218,8 @@ static const struct eth_dev_ops i40evf_eth_dev_ops = {
        .rx_queue_intr_enable = i40evf_dev_rx_queue_intr_enable,
        .rx_queue_intr_disable = i40evf_dev_rx_queue_intr_disable,
        .rx_descriptor_done   = i40e_dev_rx_descriptor_done,
+       .rx_descriptor_status = i40e_dev_rx_descriptor_status,
+       .tx_descriptor_status = i40e_dev_tx_descriptor_status,
        .tx_queue_setup       = i40e_dev_tx_queue_setup,
        .tx_queue_release     = i40e_dev_tx_queue_release,
        .rx_queue_count       = i40e_dev_rx_queue_count,
@@ -227,6 +232,7 @@ static const struct eth_dev_ops i40evf_eth_dev_ops = {
        .rss_hash_update      = i40evf_dev_rss_hash_update,
        .rss_hash_conf_get    = i40evf_dev_rss_hash_conf_get,
        .mtu_set              = i40evf_dev_mtu_set,
+       .mac_addr_set         = i40evf_set_default_mac_addr,
 };
 
 /*
@@ -642,7 +648,7 @@ i40evf_configure_vsi_queues(struct rte_eth_dev *dev)
        ret = i40evf_execute_vf_cmd(dev, &args);
        if (ret)
                PMD_DRV_LOG(ERR, "Failed to execute command of "
-                       "I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES\n");
+                       "I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES");
 
        return ret;
 }
@@ -695,7 +701,7 @@ i40evf_configure_vsi_queues_ext(struct rte_eth_dev *dev)
        ret = i40evf_execute_vf_cmd(dev, &args);
        if (ret)
                PMD_DRV_LOG(ERR, "Failed to execute command of "
-                       "I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT\n");
+                       "I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT");
 
        return ret;
 }
@@ -890,19 +896,16 @@ i40evf_add_mac_addr(struct rte_eth_dev *dev,
 }
 
 static void
-i40evf_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
+i40evf_del_mac_addr_by_addr(struct rte_eth_dev *dev,
+                           struct ether_addr *addr)
 {
        struct i40e_virtchnl_ether_addr_list *list;
        struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
-       struct rte_eth_dev_data *data = dev->data;
-       struct ether_addr *addr;
        uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
                        sizeof(struct i40e_virtchnl_ether_addr)];
        int err;
        struct vf_cmd_info args;
 
-       addr = &(data->mac_addrs[index]);
-
        if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
                PMD_DRV_LOG(ERR, "Invalid mac:%x-%x-%x-%x-%x-%x",
                            addr->addr_bytes[0], addr->addr_bytes[1],
@@ -929,6 +932,17 @@ i40evf_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
        return;
 }
 
+static void
+i40evf_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
+{
+       struct rte_eth_dev_data *data = dev->data;
+       struct ether_addr *addr;
+
+       addr = &data->mac_addrs[index];
+
+       i40evf_del_mac_addr_by_addr(dev, addr);
+}
+
 static int
 i40evf_update_stats(struct rte_eth_dev *dev, struct i40e_eth_stats **pstats)
 {
@@ -969,7 +983,7 @@ i40evf_get_statistics(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
                                                pstats->rx_broadcast;
        stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
                                                pstats->tx_unicast;
-       stats->ierrors = pstats->rx_discards;
+       stats->imissed = pstats->rx_discards;
        stats->oerrors = pstats->tx_errors + pstats->tx_discards;
        stats->ibytes = pstats->rx_bytes;
        stats->obytes = pstats->tx_bytes;
@@ -1184,7 +1198,6 @@ i40evf_init_vf(struct rte_eth_dev *dev)
        int i, err, bufsz;
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
-       struct ether_addr *p_mac_addr;
        uint16_t interval =
                i40e_calc_itr_interval(I40E_QUEUE_ITR_INTERVAL_MAX);
 
@@ -1261,9 +1274,8 @@ i40evf_init_vf(struct rte_eth_dev *dev)
        vf->vsi.adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
 
        /* Store the MAC address configured by host, or generate random one */
-       p_mac_addr = (struct ether_addr *)(vf->vsi_res->default_mac_addr);
-       if (is_valid_assigned_ether_addr(p_mac_addr)) /* Configured by host */
-               ether_addr_copy(p_mac_addr, (struct ether_addr *)hw->mac.addr);
+       if (is_valid_assigned_ether_addr((struct ether_addr *)hw->mac.addr))
+               vf->flags |= I40E_FLAG_VF_MAC_BY_PF;
        else
                eth_random_addr(hw->mac.addr); /* Generate a random one */
 
@@ -1316,16 +1328,16 @@ i40evf_handle_pf_event(__rte_unused struct rte_eth_dev *dev,
 
        switch (pf_msg->event) {
        case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
-               PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event\n");
+               PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
                _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET, NULL);
                break;
        case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
-               PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event\n");
+               PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
                vf->link_up = pf_msg->event_data.link_event.link_status;
                vf->link_speed = pf_msg->event_data.link_event.link_speed;
                break;
        case I40E_VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
-               PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event\n");
+               PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
                break;
        default:
                PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
@@ -1387,7 +1399,7 @@ i40evf_handle_aq_msg(struct rte_eth_dev *dev)
                                                "expect %u, get %u",
                                                vf->pend_cmd, msg_opc);
                                PMD_DRV_LOG(DEBUG, "adminq response is received,"
-                                            " opcode = %d\n", msg_opc);
+                                            " opcode = %d", msg_opc);
                        }
                        break;
                default:
@@ -1411,8 +1423,7 @@ i40evf_handle_aq_msg(struct rte_eth_dev *dev)
  *  void
  */
 static void
-i40evf_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
-                            void *param)
+i40evf_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);
@@ -1425,23 +1436,23 @@ i40evf_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
 
        /* No interrupt event indicated */
        if (!(icr0 & I40E_VFINT_ICR01_INTEVENT_MASK)) {
-               PMD_DRV_LOG(DEBUG, "No interrupt event, nothing to do\n");
+               PMD_DRV_LOG(DEBUG, "No interrupt event, nothing to do");
                goto done;
        }
 
        if (icr0 & I40E_VFINT_ICR01_ADMINQ_MASK) {
-               PMD_DRV_LOG(DEBUG, "ICR01_ADMINQ is reported\n");
+               PMD_DRV_LOG(DEBUG, "ICR01_ADMINQ is reported");
                i40evf_handle_aq_msg(dev);
        }
 
        /* Link Status Change interrupt */
        if (icr0 & I40E_VFINT_ICR01_LINK_STAT_CHANGE_MASK)
                PMD_DRV_LOG(DEBUG, "LINK_STAT_CHANGE is reported,"
-                                  " do nothing\n");
+                                  " do nothing");
 
 done:
        i40evf_enable_irq0(hw);
-       rte_intr_enable(intr_handle);
+       rte_intr_enable(dev->intr_handle);
 }
 
 static int
@@ -1469,7 +1480,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
        }
 
        rte_eth_copy_pci_info(eth_dev, pci_dev);
-       eth_dev->data->dev_flags = RTE_ETH_DEV_DETACHABLE;
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
 
        hw->vendor_id = pci_dev->id.vendor_id;
        hw->device_id = pci_dev->id.device_id;
@@ -1533,22 +1544,30 @@ i40evf_dev_uninit(struct rte_eth_dev *eth_dev)
 
        return 0;
 }
+
+static int eth_i40evf_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), i40evf_dev_init);
+}
+
+static int eth_i40evf_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev, i40evf_dev_uninit);
+}
+
 /*
  * virtual function driver struct
  */
-static struct eth_driver rte_i40evf_pmd = {
-       .pci_drv = {
-               .id_table = pci_id_i40evf_map,
-               .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
-               .probe = rte_eth_dev_pci_probe,
-               .remove = rte_eth_dev_pci_remove,
-       },
-       .eth_dev_init = i40evf_dev_init,
-       .eth_dev_uninit = i40evf_dev_uninit,
-       .dev_private_size = sizeof(struct i40e_adapter),
+static struct rte_pci_driver rte_i40evf_pmd = {
+       .id_table = pci_id_i40evf_map,
+       .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+       .probe = eth_i40evf_pci_probe,
+       .remove = eth_i40evf_pci_remove,
 };
 
-RTE_PMD_REGISTER_PCI(net_i40e_vf, rte_i40evf_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI(net_i40e_vf, rte_i40evf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_i40e_vf, pci_id_i40evf_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_i40e_vf, "* igb_uio | vfio");
 
@@ -2066,7 +2085,7 @@ i40evf_dev_start(struct rte_eth_dev *dev)
                                    dev->data->nb_rx_queues * sizeof(int), 0);
                if (!intr_handle->intr_vec) {
                        PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
-                                    " intr_vec\n", dev->data->nb_rx_queues);
+                                    " intr_vec", dev->data->nb_rx_queues);
                        return -ENOMEM;
                }
        }
@@ -2394,7 +2413,7 @@ i40evf_dev_rss_reta_update(struct rte_eth_dev *dev,
        if (reta_size != ETH_RSS_RETA_SIZE_64) {
                PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
                        "(%d) doesn't match the number of hardware can "
-                       "support (%d)\n", reta_size, ETH_RSS_RETA_SIZE_64);
+                       "support (%d)", reta_size, ETH_RSS_RETA_SIZE_64);
                return -EINVAL;
        }
 
@@ -2433,7 +2452,7 @@ i40evf_dev_rss_reta_query(struct rte_eth_dev *dev,
        if (reta_size != ETH_RSS_RETA_SIZE_64) {
                PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
                        "(%d) doesn't match the number of hardware can "
-                       "support (%d)\n", reta_size, ETH_RSS_RETA_SIZE_64);
+                       "support (%d)", reta_size, ETH_RSS_RETA_SIZE_64);
                return -EINVAL;
        }
 
@@ -2578,7 +2597,7 @@ i40evf_config_rss(struct i40e_vf *vf)
 
        if (vf->dev_data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
                i40evf_disable_rss(vf);
-               PMD_DRV_LOG(DEBUG, "RSS not configured\n");
+               PMD_DRV_LOG(DEBUG, "RSS not configured");
                return 0;
        }
 
@@ -2595,7 +2614,7 @@ i40evf_config_rss(struct i40e_vf *vf)
        rss_conf = vf->dev_data->dev_conf.rx_adv_conf.rss_conf;
        if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
                i40evf_disable_rss(vf);
-               PMD_DRV_LOG(DEBUG, "No hash flag is set\n");
+               PMD_DRV_LOG(DEBUG, "No hash flag is set");
                return 0;
        }
 
@@ -2671,8 +2690,7 @@ i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
        /* mtu setting is forbidden if port is start */
        if (dev_data->dev_started) {
-               PMD_DRV_LOG(ERR,
-                           "port %d must be stopped before configuration\n",
+               PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
                            dev_data->port_id);
                return -EBUSY;
        }
@@ -2686,3 +2704,25 @@ i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
        return ret;
 }
+
+static void
+i40evf_set_default_mac_addr(struct rte_eth_dev *dev,
+                           struct ether_addr *mac_addr)
+{
+       struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+
+       if (!is_valid_assigned_ether_addr(mac_addr)) {
+               PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
+               return;
+       }
+
+       if (is_same_ether_addr(mac_addr, dev->data->mac_addrs))
+               return;
+
+       if (vf->flags & I40E_FLAG_VF_MAC_BY_PF)
+               return;
+
+       i40evf_del_mac_addr_by_addr(dev, dev->data->mac_addrs);
+
+       i40evf_add_mac_addr(dev, mac_addr, 0, 0);
+}