net/ice/base: add VSI queue context framework
[dpdk.git] / drivers / net / ice / base / ice_sched.c
index 237bf73..ab60972 100644 (file)
@@ -575,6 +575,48 @@ ice_sched_suspend_resume_elems(struct ice_hw *hw, u8 num_nodes, u32 *node_teids,
        return status;
 }
 
+/**
+ * ice_alloc_lan_q_ctx - allocate LAN queue contexts for the given VSI and TC
+ * @hw: pointer to the HW struct
+ * @vsi_handle: VSI handle
+ * @tc: TC number
+ * @new_numqs: number of queues
+ */
+static enum ice_status
+ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs)
+{
+       struct ice_vsi_ctx *vsi_ctx;
+       struct ice_q_ctx *q_ctx;
+
+       vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
+       if (!vsi_ctx)
+               return ICE_ERR_PARAM;
+       /* allocate LAN queue contexts */
+       if (!vsi_ctx->lan_q_ctx[tc]) {
+               vsi_ctx->lan_q_ctx[tc] = (struct ice_q_ctx *)
+                       ice_calloc(hw, new_numqs, sizeof(*q_ctx));
+               if (!vsi_ctx->lan_q_ctx[tc])
+                       return ICE_ERR_NO_MEMORY;
+               vsi_ctx->num_lan_q_entries[tc] = new_numqs;
+               return ICE_SUCCESS;
+       }
+       /* num queues are increased, update the queue contexts */
+       if (new_numqs > vsi_ctx->num_lan_q_entries[tc]) {
+               u16 prev_num = vsi_ctx->num_lan_q_entries[tc];
+
+               q_ctx = (struct ice_q_ctx *)
+                       ice_calloc(hw, new_numqs, sizeof(*q_ctx));
+               if (!q_ctx)
+                       return ICE_ERR_NO_MEMORY;
+               ice_memcpy(q_ctx, vsi_ctx->lan_q_ctx[tc],
+                          prev_num * sizeof(*q_ctx), ICE_DMA_TO_NONDMA);
+               ice_free(hw, vsi_ctx->lan_q_ctx[tc]);
+               vsi_ctx->lan_q_ctx[tc] = q_ctx;
+               vsi_ctx->num_lan_q_entries[tc] = new_numqs;
+       }
+       return ICE_SUCCESS;
+}
+
 /**
  * ice_aq_rl_profile - performs a rate limiting task
  * @hw: pointer to the HW struct
@@ -1717,14 +1759,14 @@ ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
        if (!vsi_ctx)
                return ICE_ERR_PARAM;
 
-       if (owner == ICE_SCHED_NODE_OWNER_LAN)
-               prev_numqs = vsi_ctx->sched.max_lanq[tc];
-       else
-               return ICE_ERR_PARAM;
-
+       prev_numqs = vsi_ctx->sched.max_lanq[tc];
        /* num queues are not changed or less than the previous number */
        if (new_numqs <= prev_numqs)
                return status;
+       status = ice_alloc_lan_q_ctx(hw, vsi_handle, tc, new_numqs);
+       if (status)
+               return status;
+
        if (new_numqs)
                ice_sched_calc_vsi_child_nodes(hw, new_numqs, new_num_nodes);
        /* Keep the max number of queue configuration all the time. Update the