net/hns3: support traffic management
[dpdk.git] / drivers / net / hns3 / hns3_ethdev.c
index 7c34e38..2bc28ef 100644 (file)
@@ -5,7 +5,6 @@
 #include <rte_alarm.h>
 #include <rte_bus_pci.h>
 #include <rte_ethdev_pci.h>
-#include <rte_io.h>
 #include <rte_pci.h>
 
 #include "hns3_ethdev.h"
@@ -1017,7 +1016,7 @@ hns3_init_vlan_config(struct hns3_adapter *hns)
         * ensure that the hardware configuration remains unchanged before and
         * after reset.
         */
-       if (rte_atomic16_read(&hw->reset.resetting) == 0) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED) == 0) {
                hw->port_base_vlan_cfg.state = HNS3_PORT_BASE_VLAN_DISABLE;
                hw->port_base_vlan_cfg.pvid = HNS3_INVALID_PVID;
        }
@@ -1041,7 +1040,7 @@ hns3_init_vlan_config(struct hns3_adapter *hns)
         * we will restore configurations to hardware in hns3_restore_vlan_table
         * and hns3_restore_vlan_conf later.
         */
-       if (rte_atomic16_read(&hw->reset.resetting) == 0) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED) == 0) {
                ret = hns3_vlan_pvid_configure(hns, HNS3_INVALID_PVID, 0);
                if (ret) {
                        hns3_err(hw, "pvid set fail in pf, ret =%d", ret);
@@ -2467,7 +2466,7 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        }
 
        rte_spinlock_lock(&hw->lock);
-       is_jumbo_frame = frame_size > RTE_ETHER_MAX_LEN ? true : false;
+       is_jumbo_frame = frame_size > HNS3_DEFAULT_FRAME_LEN ? true : false;
        frame_size = RTE_MAX(frame_size, HNS3_DEFAULT_FRAME_LEN);
 
        /*
@@ -2494,7 +2493,7 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        return 0;
 }
 
-static int
+int
 hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
 {
        struct hns3_adapter *hns = eth_dev->data->dev_private;
@@ -4679,6 +4678,8 @@ hns3_init_pf(struct rte_eth_dev *eth_dev)
                goto err_enable_intr;
        }
 
+       hns3_tm_conf_init(eth_dev);
+
        return 0;
 
 err_enable_intr:
@@ -4712,6 +4713,7 @@ hns3_uninit_pf(struct rte_eth_dev *eth_dev)
 
        PMD_INIT_FUNC_TRACE();
 
+       hns3_tm_conf_uninit(eth_dev);
        hns3_enable_hw_error_intr(hns, false);
        hns3_rss_uninit(hns);
        (void)hns3_config_gro(hw, false);
@@ -4739,6 +4741,16 @@ hns3_do_start(struct hns3_adapter *hns, bool reset_queue)
        if (ret)
                return ret;
 
+       /*
+        * The hns3_dcb_cfg_update may configure TM module, so
+        * hns3_tm_conf_update must called later.
+        */
+       ret = hns3_tm_conf_update(hw);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "failed to update tm conf, ret = %d.", ret);
+               return ret;
+       }
+
        ret = hns3_init_queues(hns, reset_queue);
        if (ret) {
                PMD_INIT_LOG(ERR, "failed to init queues, ret = %d.", ret);
@@ -4872,7 +4884,7 @@ hns3_dev_start(struct rte_eth_dev *dev)
        int ret;
 
        PMD_INIT_FUNC_TRACE();
-       if (rte_atomic16_read(&hw->reset.resetting))
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED))
                return -EBUSY;
 
        rte_spinlock_lock(&hw->lock);
@@ -4936,6 +4948,8 @@ hns3_dev_start(struct rte_eth_dev *dev)
         */
        hns3_start_tqps(hw);
 
+       hns3_tm_dev_start_proc(hw);
+
        hns3_info(hw, "hns3 dev start successful!");
        return 0;
 }
@@ -5018,7 +5032,8 @@ hns3_dev_stop(struct rte_eth_dev *dev)
        rte_delay_ms(hw->tqps_num);
 
        rte_spinlock_lock(&hw->lock);
-       if (rte_atomic16_read(&hw->reset.resetting) == 0) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED) == 0) {
+               hns3_tm_dev_stop_proc(hw);
                hns3_stop_tqps(hw);
                hns3_do_stop(hns);
                hns3_unmap_rx_interrupt(dev);
@@ -5821,10 +5836,9 @@ get_current_fec_auto_state(struct hns3_hw *hw, uint8_t *state)
 }
 
 static int
-hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
+hns3_fec_get_internal(struct hns3_hw *hw, uint32_t *fec_capa)
 {
 #define QUERY_ACTIVE_SPEED     1
-       struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct hns3_sfp_speed_cmd *resp;
        uint32_t tmp_fec_capa;
        uint8_t auto_state;
@@ -5884,6 +5898,14 @@ hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
        return 0;
 }
 
+static int
+hns3_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
+{
+       struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       return hns3_fec_get_internal(hw, fec_capa);
+}
+
 static int
 hns3_set_fec_hw(struct hns3_hw *hw, uint32_t mode)
 {
@@ -6017,10 +6039,9 @@ hns3_query_dev_fec_info(struct hns3_hw *hw)
 {
        struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
        struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(hns);
-       struct rte_eth_dev *eth_dev = hns->eth_dev;
        int ret;
 
-       ret = hns3_fec_get(eth_dev, &pf->fec_mode);
+       ret = hns3_fec_get_internal(hw, &pf->fec_mode);
        if (ret)
                hns3_err(hw, "query device FEC info failed, ret = %d", ret);
 
@@ -6083,6 +6104,7 @@ static const struct eth_dev_ops hns3_eth_dev_ops = {
        .fec_get_capability     = hns3_fec_get_capability,
        .fec_get                = hns3_fec_get,
        .fec_set                = hns3_fec_set,
+       .tm_ops_get             = hns3_tm_ops_get,
 };
 
 static const struct hns3_reset_ops hns3_reset_ops = {
@@ -6106,8 +6128,6 @@ hns3_dev_init(struct rte_eth_dev *eth_dev)
 
        PMD_INIT_FUNC_TRACE();
 
-       hns->eth_dev = eth_dev;
-
        eth_dev->process_private = (struct hns3_process_private *)
            rte_zmalloc_socket("hns3_filter_list",
                               sizeof(struct hns3_process_private),