@@ -16,5 +16,8 @@ int ice_vc_cfg_q_bw(struct ice_vf *vf, u8 *msg);
int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg);
int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg);
int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg);
+int ice_vc_ena_qs_v2_msg(struct ice_vf *vf, u8 *msg, u16 msglen);
+int ice_vc_dis_qs_v2_msg(struct ice_vf *vf, u8 *msg, u16 msglen);
+int ice_vc_map_q_vector_msg(struct ice_vf *vf, u8 *msg, u16 msglen);
#endif /* _ICE_VIRT_QUEUES_H_ */
@@ -1046,3 +1046,342 @@ int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
v_ret, (u8 *)vfres, sizeof(*vfres));
}
+static bool ice_vc_supported_queue_type(s32 queue_type)
+{
+ return queue_type == VIRTCHNL_QUEUE_TYPE_RX ||
+ queue_type == VIRTCHNL_QUEUE_TYPE_TX;
+}
+
+/**
+ * ice_vc_validate_qs_v2_msg - validate all qs_msg parameters
+ * @vf: VF the message was received from
+ * @qs_msg: contents of the message from the VF
+ * @msglen: length of @qs_msg
+ *
+ * Used to validate both the VIRTCHNL_OP_ENABLE_QUEUES_V2 and
+ * VIRTCHNL_OP_DISABLE_QUEUES_V2 messages. This should always be called before
+ * attempting to enable and/or disable queues on behalf of a VF in response to
+ * the previously mentioned opcodes.
+ *
+ * Return: If all checks succeed, then return true. Otherwise return
+ * false, indicating to the caller that the qs_msg is invalid.
+ */
+static bool ice_vc_validate_qs_v2_msg(struct ice_vf *vf,
+ struct virtchnl_del_ena_dis_queues *qs_msg,
+ u16 msglen)
+{
+ u32 max_qs = min_t(u32, vf->num_vf_qs, ICE_MAX_QS_PER_VF);
+
+ if (msglen < virtchnl_struct_size(qs_msg, chunks, 0))
+ return false;
+
+ if (msglen < virtchnl_struct_size(qs_msg, chunks, qs_msg->num_chunks))
+ return false;
+
+ if (!qs_msg->num_chunks)
+ return false;
+
+ if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
+ return false;
+
+ if (!ice_vc_isvalid_vsi_id(vf, qs_msg->vport_id))
+ return false;
+
+ for (int i = 0; i < qs_msg->num_chunks; i++) {
+ struct virtchnl_queue_chunk *chunk = &qs_msg->chunks[i];
+ u32 end;
+
+ if (!ice_vc_supported_queue_type(chunk->type))
+ return false;
+
+ if (!chunk->num_queues)
+ return false;
+
+ end = chunk->start_queue_id + chunk->num_queues;
+ if (end > max_qs)
+ return false;
+ }
+
+ return true;
+}
+
+#define ice_for_each_q_in_chunk(chunk, q_id) \
+ for ((q_id) = (chunk)->start_queue_id; \
+ (q_id) < (chunk)->start_queue_id + (chunk)->num_queues; \
+ (q_id)++)
+
+static int
+ice_vc_ena_rxq_chunk(struct ice_vf *vf, struct ice_vsi *vsi,
+ struct virtchnl_queue_chunk *chunk)
+{
+ u32 vf_qid;
+
+ ice_for_each_q_in_chunk(chunk, vf_qid) {
+ int err;
+
+ err = ice_vf_vsi_ena_single_rxq(vf, vsi, vf_qid);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
+static void
+ice_vc_ena_txq_chunk(struct ice_vf *vf, struct ice_vsi *vsi,
+ struct virtchnl_queue_chunk *chunk)
+{
+ u32 vf_qid;
+
+ ice_for_each_q_in_chunk(chunk, vf_qid)
+ ice_vf_vsi_ena_single_txq(vf, vsi, vf_qid);
+}
+
+/**
+ * ice_vc_ena_qs_v2_msg - message handling for VIRTCHNL_OP_ENABLE_QUEUES_V2
+ * @vf: source of the request
+ * @msg: message to handle
+ * @msglen: length of the @msg
+ *
+ * Return: 0 on success or negative on error.
+ */
+int ice_vc_ena_qs_v2_msg(struct ice_vf *vf, u8 *msg, u16 msglen)
+{
+ struct virtchnl_del_ena_dis_queues *ena_qs_msg =
+ (struct virtchnl_del_ena_dis_queues *)msg;
+ enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+ struct ice_vsi *vsi;
+
+ if (!ice_vc_validate_qs_v2_msg(vf, ena_qs_msg, msglen))
+ goto error_param;
+
+ vsi = ice_get_vf_vsi(vf);
+ if (!vsi)
+ goto error_param;
+
+ for (int i = 0; i < ena_qs_msg->num_chunks; i++) {
+ struct virtchnl_queue_chunk *chunk = &ena_qs_msg->chunks[i];
+
+ if (chunk->type == VIRTCHNL_QUEUE_TYPE_RX &&
+ ice_vc_ena_rxq_chunk(vf, vsi, chunk))
+ goto error_param;
+ else if (chunk->type == VIRTCHNL_QUEUE_TYPE_TX)
+ ice_vc_ena_txq_chunk(vf, vsi, chunk);
+ }
+
+ v_ret = VIRTCHNL_STATUS_SUCCESS;
+ set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
+
+error_param:
+ return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES_V2,
+ v_ret, NULL, 0);
+}
+
+static int
+ice_vc_dis_rxq_chunk(struct ice_vf *vf, struct ice_vsi *vsi,
+ struct virtchnl_queue_chunk *chunk)
+{
+ u32 vf_qid;
+
+ ice_for_each_q_in_chunk(chunk, vf_qid) {
+ int err;
+
+ err = ice_vf_vsi_dis_single_rxq(vf, vsi, vf_qid);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
+static int
+ice_vc_dis_txq_chunk(struct ice_vf *vf, struct ice_vsi *vsi,
+ struct virtchnl_queue_chunk *chunk)
+{
+ u32 vf_qid;
+
+ ice_for_each_q_in_chunk(chunk, vf_qid) {
+ int err;
+
+ err = ice_vf_vsi_dis_single_txq(vf, vsi, vf_qid);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
+/**
+ * ice_vc_dis_qs_v2_msg - message handling for VIRTCHNL_OP_DISABLE_QUEUES_V2
+ * @vf: source of the request
+ * @msg: message to handle
+ * @msglen: length of @msg
+ *
+ * Return: 0 on success or negative on error.
+ */
+int ice_vc_dis_qs_v2_msg(struct ice_vf *vf, u8 *msg, u16 msglen)
+{
+ struct virtchnl_del_ena_dis_queues *dis_qs_msg =
+ (struct virtchnl_del_ena_dis_queues *)msg;
+ enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+ struct ice_vsi *vsi;
+
+ if (!ice_vc_validate_qs_v2_msg(vf, dis_qs_msg, msglen))
+ goto error_param;
+
+ vsi = ice_get_vf_vsi(vf);
+ if (!vsi)
+ goto error_param;
+
+ for (int i = 0; i < dis_qs_msg->num_chunks; i++) {
+ struct virtchnl_queue_chunk *chunk = &dis_qs_msg->chunks[i];
+
+ if (chunk->type == VIRTCHNL_QUEUE_TYPE_RX &&
+ ice_vc_dis_rxq_chunk(vf, vsi, chunk))
+ goto error_param;
+ else if (chunk->type == VIRTCHNL_QUEUE_TYPE_TX &&
+ ice_vc_dis_txq_chunk(vf, vsi, chunk))
+ goto error_param;
+ }
+
+ v_ret = VIRTCHNL_STATUS_SUCCESS;
+ if (ice_vf_has_no_qs_ena(vf))
+ clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
+
+error_param:
+ return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES_V2,
+ v_ret, NULL, 0);
+}
+
+/**
+ * ice_vc_validate_qv_maps - validate parameters sent in the qs_msg structure
+ * @vf: VF the message was received from
+ * @qv_maps: contents of the message from the VF
+ * @msglen: length of the @qv_maps
+ *
+ * Used to validate VIRTCHNL_OP_MAP_QUEUE_VECTOR messages. This should always
+ * be called before attempting map interrupts to queues. If all checks succeed,
+ * then return success indicating to the caller that the qv_maps are valid.
+ * Otherwise return false, indicating to the caller that the qv_maps are
+ * invalid.
+ *
+ * Return: true if parameters are valid, false otherwise.
+ */
+static bool ice_vc_validate_qv_maps(struct ice_vf *vf,
+ struct virtchnl_queue_vector_maps *qv_maps,
+ u16 msglen)
+{
+ struct ice_vsi *vsi;
+ int total_vectors;
+
+ vsi = ice_get_vf_vsi(vf);
+ if (!vsi)
+ return false;
+
+ if (msglen < virtchnl_struct_size(qv_maps, qv_maps, 0))
+ return false;
+
+ if (msglen < virtchnl_struct_size(qv_maps, qv_maps, qv_maps->num_qv_maps))
+ return false;
+
+ if (!qv_maps->num_qv_maps)
+ return false;
+
+ if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
+ return false;
+
+ if (!ice_vc_isvalid_vsi_id(vf, qv_maps->vport_id))
+ return false;
+
+ total_vectors = vsi->num_q_vectors + ICE_NONQ_VECS_VF;
+
+ for (int i = 0; i < qv_maps->num_qv_maps; i++) {
+ if (!ice_vc_supported_queue_type(qv_maps->qv_maps[i].queue_type))
+ return false;
+
+ if (qv_maps->qv_maps[i].queue_id >= vf->num_vf_qs)
+ return false;
+
+ if (qv_maps->qv_maps[i].vector_id >= total_vectors ||
+ qv_maps->qv_maps[i].vector_id < ICE_NONQ_VECS_VF)
+ return false;
+
+ if (qv_maps->qv_maps[i].itr_idx < ICE_IDX_ITR0 ||
+ qv_maps->qv_maps[i].itr_idx > ICE_ITR_NONE)
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * ice_vc_map_q_vector_msg - message handling for VIRTCHNL_OP_MAP_QUEUE_VECTOR
+ * @vf: source of the request
+ * @msg: message to handle
+ * @msglen: length of @msg
+ *
+ * Return: 0 on success or negative on error
+ */
+int ice_vc_map_q_vector_msg(struct ice_vf *vf, u8 *msg, u16 msglen)
+{
+ enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+ struct virtchnl_queue_vector_maps *qv_maps;
+ struct ice_vsi *vsi;
+
+ qv_maps = (struct virtchnl_queue_vector_maps *)msg;
+
+ if (!ice_vc_validate_qv_maps(vf, qv_maps, msglen))
+ goto error_param;
+
+ vsi = ice_get_vf_vsi(vf);
+ if (!vsi)
+ goto error_param;
+
+ for (int i = 0; i < qv_maps->num_qv_maps; i++) {
+ struct virtchnl_queue_vector *qv_map = &qv_maps->qv_maps[i];
+ struct ice_q_vector *q_vector;
+ u16 vector_id;
+ int vsi_q_id;
+
+ vsi_q_id = qv_map->queue_id;
+ vector_id = qv_map->vector_id;
+
+ q_vector = vf->vf_ops->get_q_vector(vsi, vector_id);
+ if (!q_vector)
+ goto error_param;
+
+ if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
+ goto error_param;
+
+ /* keep SW state in sync with HW, as ice_cfg_interrupt() does */
+ if (qv_map->queue_type == VIRTCHNL_QUEUE_TYPE_RX) {
+ struct ice_rx_ring *ring = vsi->rx_rings[vsi_q_id];
+
+ if (ring->q_vector && ring->q_vector->num_ring_rx)
+ ring->q_vector->num_ring_rx--;
+ ring->q_vector = q_vector;
+ q_vector->num_ring_rx++;
+ q_vector->rx.itr_idx = qv_map->itr_idx;
+ ice_cfg_rxq_interrupt(vsi, vsi_q_id,
+ q_vector->vf_reg_idx,
+ qv_map->itr_idx);
+ } else if (qv_map->queue_type == VIRTCHNL_QUEUE_TYPE_TX) {
+ struct ice_tx_ring *ring = vsi->tx_rings[vsi_q_id];
+
+ if (ring->q_vector && ring->q_vector->num_ring_tx)
+ ring->q_vector->num_ring_tx--;
+ ring->q_vector = q_vector;
+ q_vector->num_ring_tx++;
+ q_vector->tx.itr_idx = qv_map->itr_idx;
+ ice_cfg_txq_interrupt(vsi, vsi_q_id,
+ q_vector->vf_reg_idx,
+ qv_map->itr_idx);
+ }
+ }
+
+ v_ret = VIRTCHNL_STATUS_SUCCESS;
+
+error_param:
+ return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_MAP_QUEUE_VECTOR,
+ v_ret, NULL, 0);
+}