net/ice/base: refactor VSI node scheduler
[dpdk.git] / drivers / net / ice / base / ice_common.c
index 81eab7e..199430e 100644 (file)
@@ -449,11 +449,7 @@ ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
 {
        u16 fc_threshold_val, tx_timer_val;
        struct ice_aqc_set_mac_cfg *cmd;
-       struct ice_port_info *pi;
        struct ice_aq_desc desc;
-       enum ice_status status;
-       u8 port_num = 0;
-       bool link_up;
        u32 reg_val;
 
        cmd = &desc.params.set_mac_cfg;
@@ -465,21 +461,6 @@ ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
 
        cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
 
-       /* Retrieve the current data_pacing value in FW*/
-       pi = &hw->port_info[port_num];
-
-       /* We turn on the get_link_info so that ice_update_link_info(...)
-        * can be called.
-        */
-       pi->phy.get_link_info = 1;
-
-       status = ice_get_link_status(pi, &link_up);
-
-       if (status)
-               return status;
-
-       cmd->params = pi->phy.link_info.pacing;
-
        /* We read back the transmit timer and fc threshold value of
         * LFC. Thus, we will use index =
         * PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX.
@@ -544,7 +525,15 @@ static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
        }
        recps = hw->switch_info->recp_list;
        for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
+               struct ice_recp_grp_entry *rg_entry, *tmprg_entry;
+
                recps[i].root_rid = i;
+               LIST_FOR_EACH_ENTRY_SAFE(rg_entry, tmprg_entry,
+                                        &recps[i].rg_list, ice_recp_grp_entry,
+                                        l_entry) {
+                       LIST_DEL(&rg_entry->l_entry);
+                       ice_free(hw, rg_entry);
+               }
 
                if (recps[i].adv_rule) {
                        struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
@@ -571,6 +560,8 @@ static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
                                ice_free(hw, lst_itr);
                        }
                }
+               if (recps[i].root_buf)
+                       ice_free(hw, recps[i].root_buf);
        }
        ice_rm_all_sw_replay_rule_info(hw);
        ice_free(hw, sw->recp_list);
@@ -789,10 +780,10 @@ out:
  */
 void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf)
 {
-       ice_debug(hw, ICE_DBG_AQ_MSG, "[ FW Log Msg Start ]\n");
-       ice_debug_array(hw, ICE_DBG_AQ_MSG, 16, 1, (u8 *)buf,
+       ice_debug(hw, ICE_DBG_FW_LOG, "[ FW Log Msg Start ]\n");
+       ice_debug_array(hw, ICE_DBG_FW_LOG, 16, 1, (u8 *)buf,
                        LE16_TO_CPU(desc->datalen));
-       ice_debug(hw, ICE_DBG_AQ_MSG, "[ FW Log Msg End ]\n");
+       ice_debug(hw, ICE_DBG_FW_LOG, "[ FW Log Msg End ]\n");
 }
 
 /**
@@ -1213,6 +1204,7 @@ static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
        ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena,        1,      195),
        ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena,        1,      196),
        ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh,         3,      198),
+       ICE_CTX_STORE(ice_rlan_ctx, prefena,            1,      201),
        { 0 }
 };
 
@@ -1223,7 +1215,8 @@ static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
  * @rxq_index: the index of the Rx queue
  *
  * Converts rxq context from sparse to dense structure and then writes
- * it to HW register space
+ * it to HW register space and enables the hardware to prefetch descriptors
+ * instead of only fetching them on demand
  */
 enum ice_status
 ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
@@ -1231,6 +1224,11 @@ ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
 {
        u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
 
+       if (!rlan_ctx)
+               return ICE_ERR_BAD_PTR;
+
+       rlan_ctx->prefena = 1;
+
        ice_set_ctx((u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
        return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
 }
@@ -2416,10 +2414,10 @@ void
 ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
                    u16 link_speeds_bitmap)
 {
-       u16 speed = ICE_AQ_LINK_SPEED_UNKNOWN;
        u64 pt_high;
        u64 pt_low;
        int index;
+       u16 speed;
 
        /* We first check with low part of phy_type */
        for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
@@ -2500,38 +2498,38 @@ ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
  */
 enum ice_status ice_update_link_info(struct ice_port_info *pi)
 {
-       struct ice_aqc_get_phy_caps_data *pcaps;
-       struct ice_phy_info *phy_info;
+       struct ice_link_status *li;
        enum ice_status status;
-       struct ice_hw *hw;
 
        if (!pi)
                return ICE_ERR_PARAM;
 
-       hw = pi->hw;
-
-       pcaps = (struct ice_aqc_get_phy_caps_data *)
-               ice_malloc(hw, sizeof(*pcaps));
-       if (!pcaps)
-               return ICE_ERR_NO_MEMORY;
+       li = &pi->phy.link_info;
 
-       phy_info = &pi->phy;
        status = ice_aq_get_link_info(pi, true, NULL, NULL);
        if (status)
-               goto out;
+               return status;
+
+       if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
+               struct ice_aqc_get_phy_caps_data *pcaps;
+               struct ice_hw *hw;
+
+               hw = pi->hw;
+               pcaps = (struct ice_aqc_get_phy_caps_data *)
+                       ice_malloc(hw, sizeof(*pcaps));
+               if (!pcaps)
+                       return ICE_ERR_NO_MEMORY;
 
-       if (phy_info->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
-               status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
+               status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
                                             pcaps, NULL);
-               if (status)
-                       goto out;
+               if (status == ICE_SUCCESS)
+                       ice_memcpy(li->module_type, &pcaps->module_type,
+                                  sizeof(li->module_type),
+                                  ICE_NONDMA_TO_NONDMA);
 
-               ice_memcpy(phy_info->link_info.module_type, &pcaps->module_type,
-                          sizeof(phy_info->link_info.module_type),
-                          ICE_NONDMA_TO_NONDMA);
+               ice_free(hw, pcaps);
        }
-out:
-       ice_free(hw, pcaps);
+
        return status;
 }
 
@@ -2711,27 +2709,24 @@ ice_cfg_phy_fec(struct ice_aqc_set_phy_cfg_data *cfg, enum ice_fec_mode fec)
 {
        switch (fec) {
        case ICE_FEC_BASER:
-               /* Clear auto FEC and RS bits, and AND BASE-R ability
+               /* Clear RS bits, and AND BASE-R ability
                 * bits and OR request bits.
                 */
-               cfg->caps &= ~ICE_AQC_PHY_EN_AUTO_FEC;
                cfg->link_fec_opt &= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
                                     ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN;
                cfg->link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
                                     ICE_AQC_PHY_FEC_25G_KR_REQ;
                break;
        case ICE_FEC_RS:
-               /* Clear auto FEC and BASE-R bits, and AND RS ability
+               /* Clear BASE-R bits, and AND RS ability
                 * bits and OR request bits.
                 */
-               cfg->caps &= ~ICE_AQC_PHY_EN_AUTO_FEC;
                cfg->link_fec_opt &= ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN;
                cfg->link_fec_opt |= ICE_AQC_PHY_FEC_25G_RS_528_REQ |
                                     ICE_AQC_PHY_FEC_25G_RS_544_REQ;
                break;
        case ICE_FEC_NONE:
-               /* Clear auto FEC and all FEC option bits. */
-               cfg->caps &= ~ICE_AQC_PHY_EN_AUTO_FEC;
+               /* Clear all FEC option bits. */
                cfg->link_fec_opt &= ~ICE_AQC_PHY_FEC_MASK;
                break;
        case ICE_FEC_AUTO:
@@ -3831,7 +3826,6 @@ ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
        if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
                return ICE_ERR_CFG;
 
-
        if (!num_queues) {
                /* if queue is disabled already yet the disable queue command
                 * has to be sent to complete the VF reset, then call
@@ -4010,40 +4004,44 @@ void ice_replay_post(struct ice_hw *hw)
 /**
  * ice_stat_update40 - read 40 bit stat from the chip and update stat values
  * @hw: ptr to the hardware info
- * @hireg: high 32 bit HW register to read from
- * @loreg: low 32 bit HW register to read from
+ * @reg: offset of 64 bit HW register to read from
  * @prev_stat_loaded: bool to specify if previous stats are loaded
  * @prev_stat: ptr to previous loaded stat value
  * @cur_stat: ptr to current stat value
  */
 void
-ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
-                 bool prev_stat_loaded, u64 *prev_stat, u64 *cur_stat)
+ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
+                 u64 *prev_stat, u64 *cur_stat)
 {
-       u64 new_data;
-
-       new_data = rd32(hw, loreg);
-       new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
+       u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
 
        /* device stats are not reset at PFR, they likely will not be zeroed
-        * when the driver starts. So save the first values read and use them as
-        * offsets to be subtracted from the raw values in order to report stats
-        * that count from zero.
+        * when the driver starts. Thus, save the value from the first read
+        * without adding to the statistic value so that we report stats which
+        * count up from zero.
         */
-       if (!prev_stat_loaded)
+       if (!prev_stat_loaded) {
                *prev_stat = new_data;
+               return;
+       }
+
+       /* Calculate the difference between the new and old values, and then
+        * add it to the software stat value.
+        */
        if (new_data >= *prev_stat)
-               *cur_stat = new_data - *prev_stat;
+               *cur_stat += new_data - *prev_stat;
        else
                /* to manage the potential roll-over */
-               *cur_stat = (new_data + BIT_ULL(40)) - *prev_stat;
-       *cur_stat &= 0xFFFFFFFFFFULL;
+               *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
+
+       /* Update the previously stored value to prepare for next read */
+       *prev_stat = new_data;
 }
 
 /**
  * ice_stat_update32 - read 32 bit stat from the chip and update stat values
  * @hw: ptr to the hardware info
- * @reg: HW register to read from
+ * @reg: offset of HW register to read from
  * @prev_stat_loaded: bool to specify if previous stats are loaded
  * @prev_stat: ptr to previous loaded stat value
  * @cur_stat: ptr to current stat value
@@ -4057,17 +4055,26 @@ ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
        new_data = rd32(hw, reg);
 
        /* device stats are not reset at PFR, they likely will not be zeroed
-        * when the driver starts. So save the first values read and use them as
-        * offsets to be subtracted from the raw values in order to report stats
-        * that count from zero.
+        * when the driver starts. Thus, save the value from the first read
+        * without adding to the statistic value so that we report stats which
+        * count up from zero.
         */
-       if (!prev_stat_loaded)
+       if (!prev_stat_loaded) {
                *prev_stat = new_data;
+               return;
+       }
+
+       /* Calculate the difference between the new and old values, and then
+        * add it to the software stat value.
+        */
        if (new_data >= *prev_stat)
-               *cur_stat = new_data - *prev_stat;
+               *cur_stat += new_data - *prev_stat;
        else
                /* to manage the potential roll-over */
-               *cur_stat = (new_data + BIT_ULL(32)) - *prev_stat;
+               *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
+
+       /* Update the previously stored value to prepare for next read */
+       *prev_stat = new_data;
 }