fm10k/base: wrap long lines
[dpdk.git] / drivers / net / vmxnet3 / vmxnet3_ethdev.c
index 3caa4c0..c363bf6 100644 (file)
@@ -70,6 +70,7 @@
 #define PROCESS_SYS_EVENTS 0
 
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
+static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
 static int vmxnet3_dev_start(struct rte_eth_dev *dev);
 static void vmxnet3_dev_stop(struct rte_eth_dev *dev);
@@ -155,9 +156,36 @@ gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size,
  *   - On success, zero.
  *   - On failure, negative value.
  */
-static inline int
-rte_vmxnet3_dev_atomic_write_link_status(struct rte_eth_dev *dev,
-                               struct rte_eth_link *link)
+
+static int
+vmxnet3_dev_atomic_read_link_status(struct rte_eth_dev *dev,
+                                   struct rte_eth_link *link)
+{
+       struct rte_eth_link *dst = link;
+       struct rte_eth_link *src = &(dev->data->dev_link);
+
+       if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
+                               *(uint64_t *)src) == 0)
+               return -1;
+
+       return 0;
+}
+
+/**
+ * Atomically writes the link status information into global
+ * structure rte_eth_dev.
+ *
+ * @param dev
+ *   - Pointer to the structure rte_eth_dev to write to.
+ *   - Pointer to the buffer to be saved with the link status.
+ *
+ * @return
+ *   - On success, zero.
+ *   - On failure, negative value.
+ */
+static int
+vmxnet3_dev_atomic_write_link_status(struct rte_eth_dev *dev,
+                                    struct rte_eth_link *link)
 {
        struct rte_eth_link *dst = &(dev->data->dev_link);
        struct rte_eth_link *src = link;
@@ -208,6 +236,8 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
+       rte_eth_copy_pci_info(eth_dev, pci_dev);
+
        /* Vendor and Device ID need to be set before init of shared code */
        hw->device_id = pci_dev->id.device_id;
        hw->vendor_id = pci_dev->id.vendor_id;
@@ -216,7 +246,6 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 
        hw->num_rx_queues = 1;
        hw->num_tx_queues = 1;
-       hw->cur_mtu = ETHER_MTU;
        hw->bufs_per_pkt = 1;
 
        /* Check h/w version compatibility with driver. */
@@ -268,13 +297,37 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
+static int
+eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev)
+{
+       struct vmxnet3_hw *hw = eth_dev->data->dev_private;
+
+       PMD_INIT_FUNC_TRACE();
+
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
+       if (hw->adapter_stopped == 0)
+               vmxnet3_dev_close(eth_dev);
+
+       eth_dev->dev_ops = NULL;
+       eth_dev->rx_pkt_burst = NULL;
+       eth_dev->tx_pkt_burst = NULL;
+
+       rte_free(eth_dev->data->mac_addrs);
+       eth_dev->data->mac_addrs = NULL;
+
+       return 0;
+}
+
 static struct eth_driver rte_vmxnet3_pmd = {
        .pci_drv = {
                .name = "rte_vmxnet3_pmd",
                .id_table = pci_id_vmxnet3_map,
-               .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+               .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
        },
        .eth_dev_init = eth_vmxnet3_dev_init,
+       .eth_dev_uninit = eth_vmxnet3_dev_uninit,
        .dev_private_size = sizeof(struct vmxnet3_hw),
 };
 
@@ -389,9 +442,9 @@ vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
        devRead->misc.driverInfo.vmxnet3RevSpt = 1;
        devRead->misc.driverInfo.uptVerSpt     = 1;
 
+       devRead->misc.mtu = rte_le_to_cpu_32(dev->data->mtu);
        devRead->misc.queueDescPA  = hw->queueDescPA;
        devRead->misc.queueDescLen = hw->queue_desc_len;
-       devRead->misc.mtu          = hw->cur_mtu;
        devRead->misc.numTxQueues  = hw->num_tx_queues;
        devRead->misc.numRxQueues  = hw->num_rx_queues;
 
@@ -553,7 +606,7 @@ vmxnet3_dev_stop(struct rte_eth_dev *dev)
 
        PMD_INIT_FUNC_TRACE();
 
-       if (hw->adapter_stopped == TRUE) {
+       if (hw->adapter_stopped == 1) {
                PMD_INIT_LOG(DEBUG, "Device already closed.");
                return;
        }
@@ -569,13 +622,13 @@ vmxnet3_dev_stop(struct rte_eth_dev *dev)
        /* reset the device */
        VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
        PMD_INIT_LOG(DEBUG, "Device reset.");
-       hw->adapter_stopped = FALSE;
+       hw->adapter_stopped = 0;
 
        vmxnet3_dev_clear_queues(dev);
 
        /* Clear recorded link status */
        memset(&link, 0, sizeof(link));
-       rte_vmxnet3_dev_atomic_write_link_status(dev, &link);
+       vmxnet3_dev_atomic_write_link_status(dev, &link);
 }
 
 /*
@@ -589,7 +642,7 @@ vmxnet3_dev_close(struct rte_eth_dev *dev)
        PMD_INIT_FUNC_TRACE();
 
        vmxnet3_dev_stop(dev);
-       hw->adapter_stopped = TRUE;
+       hw->adapter_stopped = 1;
 }
 
 static void
@@ -651,6 +704,18 @@ vmxnet3_dev_info_get(__attribute__((unused))struct rte_eth_dev *dev, struct rte_
        dev_info->default_txconf.txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
                                                ETH_TXQ_FLAGS_NOOFFLOADS;
        dev_info->flow_type_rss_offloads = VMXNET3_RSS_OFFLOAD_ALL;
+
+       dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
+               .nb_max = VMXNET3_RX_RING_MAX_SIZE,
+               .nb_min = VMXNET3_DEF_RX_RING_SIZE,
+               .nb_align = 1,
+       };
+
+       dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
+               .nb_max = VMXNET3_TX_RING_MAX_SIZE,
+               .nb_min = VMXNET3_DEF_TX_RING_SIZE,
+               .nb_align = 1,
+       };
 }
 
 /* return 0 means link status changed, -1 means not changed */
@@ -658,28 +723,27 @@ static int
 vmxnet3_dev_link_update(struct rte_eth_dev *dev, __attribute__((unused)) int wait_to_complete)
 {
        struct vmxnet3_hw *hw = dev->data->dev_private;
-       struct rte_eth_link link;
+       struct rte_eth_link old, link;
        uint32_t ret;
 
+       if (dev->data->dev_started == 0)
+               return -1; /* Link status doesn't change for stopped dev */
+
+       memset(&link, 0, sizeof(link));
+       vmxnet3_dev_atomic_read_link_status(dev, &old);
+
        VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
        ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
 
-       if (!ret) {
-               PMD_INIT_LOG(ERR, "Link Status Negative : %s()", __func__);
-               return -1;
-       }
-
        if (ret & 0x1) {
                link.link_status = 1;
                link.link_duplex = ETH_LINK_FULL_DUPLEX;
                link.link_speed = ETH_LINK_SPEED_10000;
-
-               rte_vmxnet3_dev_atomic_write_link_status(dev, &link);
-
-               return 0;
        }
 
-       return -1;
+       vmxnet3_dev_atomic_write_link_status(dev, &link);
+
+       return (old.link_status == link.link_status) ? -1 : 0;
 }
 
 /* Updating rxmode through Vmxnet3_DriverShared structure in adapter */