net/hinic: set link down and up
[dpdk.git] / drivers / net / hinic / hinic_pmd_ethdev.c
index f2f0fa9..ea39ff0 100644 (file)
@@ -341,6 +341,9 @@ static int hinic_dev_configure(struct rte_eth_dev *dev)
                return err;
        }
 
+       /*clear fdir filter flag in function table*/
+       hinic_free_fdir_filter(nic_dev);
+
        return HINIC_OK;
 }
 
@@ -879,6 +882,66 @@ out:
        return rc;
 }
 
+/**
+ * DPDK callback to bring the link UP.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   0 on success, negative errno value on failure.
+ */
+static int hinic_dev_set_link_up(struct rte_eth_dev *dev)
+{
+       struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+       int ret;
+
+       ret = hinic_set_xsfp_tx_status(nic_dev->hwdev, true);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "Enable port tx xsfp failed, dev_name: %s, port_id: %d",
+                           nic_dev->proc_dev_name, dev->data->port_id);
+               return ret;
+       }
+
+       /* link status follow phy port status, up will open pma */
+       ret = hinic_set_port_enable(nic_dev->hwdev, true);
+       if (ret)
+               PMD_DRV_LOG(ERR, "Set mac link up failed, dev_name: %s, port_id: %d",
+                           nic_dev->proc_dev_name, dev->data->port_id);
+
+       return ret;
+}
+
+/**
+ * DPDK callback to bring the link DOWN.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   0 on success, negative errno value on failure.
+ */
+static int hinic_dev_set_link_down(struct rte_eth_dev *dev)
+{
+       struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+       int ret;
+
+       ret = hinic_set_xsfp_tx_status(nic_dev->hwdev, false);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "Disable port tx xsfp failed, dev_name: %s, port_id: %d",
+                           nic_dev->proc_dev_name, dev->data->port_id);
+               return ret;
+       }
+
+       /* link status follow phy port status, up will close pma */
+       ret = hinic_set_port_enable(nic_dev->hwdev, false);
+       if (ret)
+               PMD_DRV_LOG(ERR, "Set mac link down failed, dev_name: %s, port_id: %d",
+                           nic_dev->proc_dev_name, dev->data->port_id);
+
+       return ret;
+}
+
 /**
  * DPDK callback to start the device.
  *
@@ -1115,6 +1178,8 @@ static void hinic_dev_stop(struct rte_eth_dev *dev)
        /* clean root context */
        hinic_free_qp_ctxts(nic_dev->hwdev);
 
+       hinic_free_fdir_filter(nic_dev);
+
        /* free mbuf */
        hinic_free_all_rx_mbuf(dev);
        hinic_free_all_tx_mbuf(dev);
@@ -2751,6 +2816,8 @@ static const struct eth_dev_ops hinic_pmd_ops = {
        .rx_queue_setup                = hinic_rx_queue_setup,
        .tx_queue_setup                = hinic_tx_queue_setup,
        .dev_start                     = hinic_dev_start,
+       .dev_set_link_up               = hinic_dev_set_link_up,
+       .dev_set_link_down             = hinic_dev_set_link_down,
        .link_update                   = hinic_link_update,
        .rx_queue_release              = hinic_rx_queue_release,
        .tx_queue_release              = hinic_tx_queue_release,
@@ -2816,6 +2883,7 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev)
        struct rte_pci_device *pci_dev;
        struct rte_ether_addr *eth_addr;
        struct hinic_nic_dev *nic_dev;
+       struct hinic_filter_info *filter_info;
        u32 mac_size;
        int rc;
 
@@ -2907,6 +2975,16 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev)
        }
        hinic_set_bit(HINIC_DEV_INTR_EN, &nic_dev->dev_status);
 
+       /* initialize filter info */
+       filter_info = &nic_dev->filter;
+       memset(filter_info, 0, sizeof(struct hinic_filter_info));
+       /* initialize 5tuple filter list */
+       TAILQ_INIT(&filter_info->fivetuple_list);
+       TAILQ_INIT(&nic_dev->filter_ntuple_list);
+       TAILQ_INIT(&nic_dev->filter_ethertype_list);
+       TAILQ_INIT(&nic_dev->filter_fdir_rule_list);
+       TAILQ_INIT(&nic_dev->hinic_flow_list);
+
        hinic_set_bit(HINIC_DEV_INIT, &nic_dev->dev_status);
        PMD_DRV_LOG(INFO, "Initialize %s in primary successfully",
                    eth_dev->data->name);