From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8F0AB4414E; Tue, 4 Jun 2024 10:50:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C4024435A9; Tue, 4 Jun 2024 10:49:11 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by mails.dpdk.org (Postfix) with ESMTP id 9235143571 for ; Tue, 4 Jun 2024 10:49:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717490950; x=1749026950; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4Ho1G78AnPsRdV5yeZ+iS6c7yUrSN+mf1jedhYq+QEc=; b=kUQCVE4Szp9GhGEP9c3LQLt8nkrRgRoPffcX7f0m47MzHB3uy3e76yHV vho9S/OtLYdDCPZrVHHG8wFSdTV/k5wFoy7GA066PBcfrnwNfwGeLPT/z 4mYHlvg+kCNJvth+EMkJeeU/QIQDq8AB8/yIDOJQCtNLNamteXE3+mD47 oikYBgySAQOQN6ziNGWcsxlrOe47DmAVy71BAEX+B6aZbtRJ6YEZ9JFOg kaeKnW7wCrH+VGmWl1Vhy69PwXhyojqaNHS8CUzah+Ap1gtRXd3Ji5cbJ P6Y9Bjfd9HmDtew23ke0OL3YYo8tmpSpQBw5s3f22To8PXx7/5ghNzSYw A==; X-CSE-ConnectionGUID: XFhWdul/QRqqOpz8kK6Hnw== X-CSE-MsgGUID: 3X+XosvXT/GtSfHCXSHthw== X-IronPort-AV: E=McAfee;i="6600,9927,11092"; a="13971729" X-IronPort-AV: E=Sophos;i="6.08,213,1712646000"; d="scan'208";a="13971729" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jun 2024 01:49:09 -0700 X-CSE-ConnectionGUID: Ovihs+WPTBKDdE71ftgMuA== X-CSE-MsgGUID: 033mffduSVKwos4O+4x0Gw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,213,1712646000"; d="scan'208";a="42268725" Received: from unknown (HELO npf-hyd-clx-03..) ([10.145.170.182]) by orviesa004.jf.intel.com with ESMTP; 04 Jun 2024 01:49:07 -0700 From: Soumyadeep Hore To: bruce.richardson@intel.com, anatoly.burakov@intel.com Cc: dev@dpdk.org Subject: [PATCH v2 17/21] drivers: add flex array support and fix issues Date: Tue, 4 Jun 2024 08:06:07 +0000 Message-ID: <20240604080611.2197835-18-soumyadeep.hore@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604080611.2197835-1-soumyadeep.hore@intel.com> References: <20240528072839.867100-1-soumyadeep.hore@intel.com> <20240604080611.2197835-1-soumyadeep.hore@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org With the internal Linux upstream feedback that is received on IDPF driver and also some references available online, it is discouraged to use 1-sized array fields in the structures, especially in the new Linux drivers that are going to be upstreamed. Instead, it is recommended to use flex array fields for the dynamic sized structures. Some fixes based on code change is introduced to compile dpdk. Signed-off-by: Soumyadeep Hore --- drivers/common/idpf/base/virtchnl2.h | 466 ++++----------------- drivers/common/idpf/idpf_common_virtchnl.c | 2 +- drivers/net/cpfl/cpfl_ethdev.c | 28 +- 3 files changed, 86 insertions(+), 410 deletions(-) diff --git a/drivers/common/idpf/base/virtchnl2.h b/drivers/common/idpf/base/virtchnl2.h index 468b8f355d..fb017b1306 100644 --- a/drivers/common/idpf/base/virtchnl2.h +++ b/drivers/common/idpf/base/virtchnl2.h @@ -63,6 +63,10 @@ enum virtchnl2_status { #define VIRTCHNL2_CHECK_STRUCT_LEN(n, X) \ static_assert((n) == sizeof(struct X), \ "Structure length does not match with the expected value") +#define VIRTCHNL2_CHECK_STRUCT_VAR_LEN(n, X, T) \ + VIRTCHNL2_CHECK_STRUCT_LEN(n, X) + +#define STRUCT_VAR_LEN 1 /** * New major set of opcodes introduced and so leaving room for @@ -696,10 +700,9 @@ VIRTCHNL2_CHECK_STRUCT_LEN(32, virtchnl2_queue_reg_chunk); struct virtchnl2_queue_reg_chunks { __le16 num_chunks; u8 pad[6]; - struct virtchnl2_queue_reg_chunk chunks[1]; + struct virtchnl2_queue_reg_chunk chunks[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(40, virtchnl2_queue_reg_chunks); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(40, virtchnl2_queue_reg_chunks, chunks); /** * enum virtchnl2_vport_flags - Vport flags @@ -773,7 +776,7 @@ struct virtchnl2_create_vport { u8 pad[20]; struct virtchnl2_queue_reg_chunks chunks; }; -VIRTCHNL2_CHECK_STRUCT_LEN(192, virtchnl2_create_vport); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(192, virtchnl2_create_vport, chunks.chunks); /** * struct virtchnl2_vport - Vport identifier information @@ -859,10 +862,9 @@ struct virtchnl2_config_tx_queues { __le32 vport_id; __le16 num_qinfo; u8 pad[10]; - struct virtchnl2_txq_info qinfo[1]; + struct virtchnl2_txq_info qinfo[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(72, virtchnl2_config_tx_queues); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(72, virtchnl2_config_tx_queues, qinfo); /** * struct virtchnl2_rxq_info - Receive queue config info @@ -940,10 +942,9 @@ struct virtchnl2_config_rx_queues { __le32 vport_id; __le16 num_qinfo; u8 pad[18]; - struct virtchnl2_rxq_info qinfo[1]; + struct virtchnl2_rxq_info qinfo[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(112, virtchnl2_config_rx_queues); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(112, virtchnl2_config_rx_queues, qinfo); /** * struct virtchnl2_add_queues - Data for VIRTCHNL2_OP_ADD_QUEUES @@ -973,16 +974,15 @@ struct virtchnl2_add_queues { struct virtchnl2_queue_reg_chunks chunks; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(56, virtchnl2_add_queues); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(56, virtchnl2_add_queues, chunks.chunks); /* Queue Groups Extension */ /** * struct virtchnl2_rx_queue_group_info - RX queue group info - * @rss_lut_size: IN/OUT, user can ask to update rss_lut size originally - * allocated by CreateVport command. New size will be returned - * if allocation succeeded, otherwise original rss_size from - * CreateVport will be returned. + * @rss_lut_size: User can ask to update rss_lut size originally allocated by + * CreateVport command. New size will be returned if allocation + * succeeded, otherwise original rss_size from CreateVport + * will be returned. * @pad: Padding for future extensions */ struct virtchnl2_rx_queue_group_info { @@ -1010,7 +1010,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_rx_queue_group_info); * @cir_pad: Future extension purpose for CIR only * @pad2: Padding for future extensions */ -struct virtchnl2_tx_queue_group_info { /* IN */ +struct virtchnl2_tx_queue_group_info { u8 tx_tc; u8 priority; u8 is_sp; @@ -1043,19 +1043,17 @@ VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_group_id); /** * struct virtchnl2_queue_group_info - Queue group info * @qg_id: Queue group ID - * @num_tx_q: Number of TX queues - * @num_tx_complq: Number of completion queues - * @num_rx_q: Number of RX queues - * @num_rx_bufq: Number of RX buffer queues + * @num_tx_q: Number of TX queues requested + * @num_tx_complq: Number of completion queues requested + * @num_rx_q: Number of RX queues requested + * @num_rx_bufq: Number of RX buffer queues requested * @tx_q_grp_info: TX queue group info * @rx_q_grp_info: RX queue group info * @pad: Padding for future extensions - * @chunks: Queue register chunks + * @chunks: Queue register chunks from CP */ struct virtchnl2_queue_group_info { - /* IN */ struct virtchnl2_queue_group_id qg_id; - /* IN, Number of queue of different types in the group. */ __le16 num_tx_q; __le16 num_tx_complq; __le16 num_rx_q; @@ -1064,56 +1062,52 @@ struct virtchnl2_queue_group_info { struct virtchnl2_tx_queue_group_info tx_q_grp_info; struct virtchnl2_rx_queue_group_info rx_q_grp_info; u8 pad[40]; - struct virtchnl2_queue_reg_chunks chunks; /* OUT */ -}; - -VIRTCHNL2_CHECK_STRUCT_LEN(120, virtchnl2_queue_group_info); - -/** - * struct virtchnl2_queue_groups - Queue groups list - * @num_queue_groups: Total number of queue groups - * @pad: Padding for future extensions - * @groups: Array of queue group info - */ -struct virtchnl2_queue_groups { - __le16 num_queue_groups; - u8 pad[6]; - struct virtchnl2_queue_group_info groups[1]; + struct virtchnl2_queue_reg_chunks chunks; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(128, virtchnl2_queue_groups); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(120, virtchnl2_queue_group_info, chunks.chunks); /** * struct virtchnl2_add_queue_groups - Add queue groups - * @vport_id: IN, vport_id to add queue group to, same as allocated by + * @vport_id: Vport_id to add queue group to, same as allocated by * CreateVport. NA for mailbox and other types not assigned to vport. + * @num_queue_groups: Total number of queue groups * @pad: Padding for future extensions - * @qg_info: IN/OUT. List of all the queue groups +#ifndef FLEX_ARRAY_SUPPORT + * @groups: List of all the queue group info structures +#endif * * PF sends this message to request additional transmit/receive queue groups * beyond the ones that were assigned via CREATE_VPORT request. * virtchnl2_add_queue_groups structure is used to specify the number of each * type of queues. CP responds with the same structure with the actual number of - * groups and queues assigned followed by num_queue_groups and num_chunks of - * virtchnl2_queue_groups and virtchnl2_queue_chunk structures. + * groups and queues assigned followed by num_queue_groups and groups of + * virtchnl2_queue_group_info and virtchnl2_queue_chunk structures. +#ifdef FLEX_ARRAY_SUPPORT + * (Note: There is no specific field for the queue group info but are added at + * the end of the add queue groups message. Receiver of this message is expected + * to extract the queue group info accordingly. Reason for doing this is because + * compiler doesn't allow nested flexible array fields). +#endif * * Associated with VIRTCHNL2_OP_ADD_QUEUE_GROUPS. */ struct virtchnl2_add_queue_groups { __le32 vport_id; - u8 pad[4]; - struct virtchnl2_queue_groups qg_info; + __le16 num_queue_groups; + u8 pad[10]; + struct virtchnl2_queue_group_info groups[STRUCT_VAR_LEN]; + }; VIRTCHNL2_CHECK_STRUCT_LEN(136, virtchnl2_add_queue_groups); /** * struct virtchnl2_delete_queue_groups - Delete queue groups - * @vport_id: IN, vport_id to delete queue group from, same as allocated by + * @vport_id: Vport ID to delete queue group from, same as allocated by * CreateVport. - * @num_queue_groups: IN/OUT, Defines number of groups provided + * @num_queue_groups: Defines number of groups provided * @pad: Padding - * @qg_ids: IN, IDs & types of Queue Groups to delete + * @qg_ids: IDs & types of Queue Groups to delete * * PF sends this message to delete queue groups. * PF sends virtchnl2_delete_queue_groups struct to specify the queue groups @@ -1127,10 +1121,9 @@ struct virtchnl2_delete_queue_groups { __le16 num_queue_groups; u8 pad[2]; - struct virtchnl2_queue_group_id qg_ids[1]; + struct virtchnl2_queue_group_id qg_ids[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_delete_queue_groups); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(16, virtchnl2_delete_queue_groups, qg_ids); /** * struct virtchnl2_vector_chunk - Structure to specify a chunk of contiguous @@ -1188,10 +1181,9 @@ struct virtchnl2_vector_chunks { __le16 num_vchunks; u8 pad[14]; - struct virtchnl2_vector_chunk vchunks[1]; + struct virtchnl2_vector_chunk vchunks[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(48, virtchnl2_vector_chunks); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(48, virtchnl2_vector_chunks, vchunks); /** * struct virtchnl2_alloc_vectors - Vector allocation info @@ -1213,8 +1205,7 @@ struct virtchnl2_alloc_vectors { struct virtchnl2_vector_chunks vchunks; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(64, virtchnl2_alloc_vectors); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(64, virtchnl2_alloc_vectors, vchunks.vchunks); /** * struct virtchnl2_rss_lut - RSS LUT info @@ -1235,10 +1226,9 @@ struct virtchnl2_rss_lut { __le16 lut_entries_start; __le16 lut_entries; u8 pad[4]; - __le32 lut[1]; + __le32 lut[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_rss_lut); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(16, virtchnl2_rss_lut, lut); /** * struct virtchnl2_rss_hash - RSS hash info @@ -1387,10 +1377,9 @@ struct virtchnl2_ptype { u8 ptype_id_8; u8 proto_id_count; __le16 pad; - __le16 proto_id[1]; + __le16 proto_id[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_ptype); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(8, virtchnl2_ptype, proto_id); /** * struct virtchnl2_get_ptype_info - Packet type info @@ -1426,7 +1415,7 @@ struct virtchnl2_get_ptype_info { __le16 start_ptype_id; __le16 num_ptypes; __le32 pad; - struct virtchnl2_ptype ptype[1]; + struct virtchnl2_ptype ptype[STRUCT_VAR_LEN]; }; VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_get_ptype_info); @@ -1627,10 +1616,9 @@ VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_queue_chunk); struct virtchnl2_queue_chunks { __le16 num_chunks; u8 pad[6]; - struct virtchnl2_queue_chunk chunks[1]; + struct virtchnl2_queue_chunk chunks[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(24, virtchnl2_queue_chunks); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(24, virtchnl2_queue_chunks, chunks); /** * struct virtchnl2_del_ena_dis_queues - Enable/disable queues info @@ -1652,8 +1640,7 @@ struct virtchnl2_del_ena_dis_queues { struct virtchnl2_queue_chunks chunks; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(32, virtchnl2_del_ena_dis_queues); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(32, virtchnl2_del_ena_dis_queues, chunks.chunks); /** * struct virtchnl2_queue_vector - Queue to vector mapping @@ -1697,10 +1684,10 @@ struct virtchnl2_queue_vector_maps { __le32 vport_id; __le16 num_qv_maps; u8 pad[10]; - struct virtchnl2_queue_vector qv_maps[1]; -}; -VIRTCHNL2_CHECK_STRUCT_LEN(40, virtchnl2_queue_vector_maps); + struct virtchnl2_queue_vector qv_maps[STRUCT_VAR_LEN]; +}; +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(40, virtchnl2_queue_vector_maps, qv_maps); /** * struct virtchnl2_loopback - Loopback info @@ -1752,10 +1739,10 @@ struct virtchnl2_mac_addr_list { __le32 vport_id; __le16 num_mac_addr; u8 pad[2]; - struct virtchnl2_mac_addr mac_addr_list[1]; -}; -VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_mac_addr_list); + struct virtchnl2_mac_addr mac_addr_list[STRUCT_VAR_LEN]; +}; +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(16, virtchnl2_mac_addr_list, mac_addr_list); /** * struct virtchnl2_promisc_info - Promiscuous type information @@ -1854,10 +1841,10 @@ struct virtchnl2_ptp_tx_tstamp { __le16 num_latches; __le16 latch_size; u8 pad[4]; - struct virtchnl2_ptp_tx_tstamp_entry ptp_tx_tstamp_entries[1]; + struct virtchnl2_ptp_tx_tstamp_entry ptp_tx_tstamp_entries[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(24, virtchnl2_ptp_tx_tstamp); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(24, virtchnl2_ptp_tx_tstamp, + ptp_tx_tstamp_entries); /** * struct virtchnl2_get_ptp_caps - Get PTP capabilities @@ -1882,8 +1869,8 @@ struct virtchnl2_get_ptp_caps { struct virtchnl2_ptp_device_clock_control device_clock_control; struct virtchnl2_ptp_tx_tstamp tx_tstamp; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(88, virtchnl2_get_ptp_caps); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(88, virtchnl2_get_ptp_caps, + tx_tstamp.ptp_tx_tstamp_entries); /** * struct virtchnl2_ptp_tx_tstamp_latch - Structure that describes tx tstamp @@ -1918,13 +1905,12 @@ VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_ptp_tx_tstamp_latch); */ struct virtchnl2_ptp_tx_tstamp_latches { __le16 num_latches; - /* latch size expressed in bits */ __le16 latch_size; u8 pad[4]; - struct virtchnl2_ptp_tx_tstamp_latch tstamp_latches[1]; + struct virtchnl2_ptp_tx_tstamp_latch tstamp_latches[STRUCT_VAR_LEN]; }; - -VIRTCHNL2_CHECK_STRUCT_LEN(24, virtchnl2_ptp_tx_tstamp_latches); +VIRTCHNL2_CHECK_STRUCT_VAR_LEN(24, virtchnl2_ptp_tx_tstamp_latches, + tstamp_latches); static inline const char *virtchnl2_op_str(__le32 v_opcode) { @@ -2002,314 +1988,4 @@ static inline const char *virtchnl2_op_str(__le32 v_opcode) } } -/** - * virtchnl2_vc_validate_vf_msg - * @ver: Virtchnl2 version info - * @v_opcode: Opcode for the message - * @msg: pointer to the msg buffer - * @msglen: msg length - * - * Validate msg format against struct for each opcode. - */ -static inline int -virtchnl2_vc_validate_vf_msg(__rte_unused struct virtchnl2_version_info *ver, u32 v_opcode, - u8 *msg, __le16 msglen) -{ - bool err_msg_format = false; - __le32 valid_len = 0; - - /* Validate message length */ - switch (v_opcode) { - case VIRTCHNL2_OP_VERSION: - valid_len = sizeof(struct virtchnl2_version_info); - break; - case VIRTCHNL2_OP_GET_CAPS: - valid_len = sizeof(struct virtchnl2_get_capabilities); - break; - case VIRTCHNL2_OP_CREATE_VPORT: - valid_len = sizeof(struct virtchnl2_create_vport); - if (msglen >= valid_len) { - struct virtchnl2_create_vport *cvport = - (struct virtchnl2_create_vport *)msg; - - if (cvport->chunks.num_chunks == 0) { - /* Zero chunks is allowed as input */ - break; - } - - valid_len += (cvport->chunks.num_chunks - 1) * - sizeof(struct virtchnl2_queue_reg_chunk); - } - break; - case VIRTCHNL2_OP_NON_FLEX_CREATE_ADI: - valid_len = sizeof(struct virtchnl2_non_flex_create_adi); - if (msglen >= valid_len) { - struct virtchnl2_non_flex_create_adi *cadi = - (struct virtchnl2_non_flex_create_adi *)msg; - - if (cadi->chunks.num_chunks == 0) { - /* Zero chunks is allowed as input */ - break; - } - - if (cadi->vchunks.num_vchunks == 0) { - err_msg_format = true; - break; - } - valid_len += (cadi->chunks.num_chunks - 1) * - sizeof(struct virtchnl2_queue_reg_chunk); - valid_len += (cadi->vchunks.num_vchunks - 1) * - sizeof(struct virtchnl2_vector_chunk); - } - break; - case VIRTCHNL2_OP_NON_FLEX_DESTROY_ADI: - valid_len = sizeof(struct virtchnl2_non_flex_destroy_adi); - break; - case VIRTCHNL2_OP_DESTROY_VPORT: - case VIRTCHNL2_OP_ENABLE_VPORT: - case VIRTCHNL2_OP_DISABLE_VPORT: - valid_len = sizeof(struct virtchnl2_vport); - break; - case VIRTCHNL2_OP_CONFIG_TX_QUEUES: - valid_len = sizeof(struct virtchnl2_config_tx_queues); - if (msglen >= valid_len) { - struct virtchnl2_config_tx_queues *ctq = - (struct virtchnl2_config_tx_queues *)msg; - if (ctq->num_qinfo == 0) { - err_msg_format = true; - break; - } - valid_len += (ctq->num_qinfo - 1) * - sizeof(struct virtchnl2_txq_info); - } - break; - case VIRTCHNL2_OP_CONFIG_RX_QUEUES: - valid_len = sizeof(struct virtchnl2_config_rx_queues); - if (msglen >= valid_len) { - struct virtchnl2_config_rx_queues *crq = - (struct virtchnl2_config_rx_queues *)msg; - if (crq->num_qinfo == 0) { - err_msg_format = true; - break; - } - valid_len += (crq->num_qinfo - 1) * - sizeof(struct virtchnl2_rxq_info); - } - break; - case VIRTCHNL2_OP_ADD_QUEUES: - valid_len = sizeof(struct virtchnl2_add_queues); - if (msglen >= valid_len) { - struct virtchnl2_add_queues *add_q = - (struct virtchnl2_add_queues *)msg; - - if (add_q->chunks.num_chunks == 0) { - /* Zero chunks is allowed as input */ - break; - } - - valid_len += (add_q->chunks.num_chunks - 1) * - sizeof(struct virtchnl2_queue_reg_chunk); - } - break; - case VIRTCHNL2_OP_ENABLE_QUEUES: - case VIRTCHNL2_OP_DISABLE_QUEUES: - case VIRTCHNL2_OP_DEL_QUEUES: - valid_len = sizeof(struct virtchnl2_del_ena_dis_queues); - if (msglen >= valid_len) { - struct virtchnl2_del_ena_dis_queues *qs = - (struct virtchnl2_del_ena_dis_queues *)msg; - if (qs->chunks.num_chunks == 0 || - qs->chunks.num_chunks > VIRTCHNL2_OP_DEL_ENABLE_DISABLE_QUEUES_MAX) { - err_msg_format = true; - break; - } - valid_len += (qs->chunks.num_chunks - 1) * - sizeof(struct virtchnl2_queue_chunk); - } - break; - case VIRTCHNL2_OP_ADD_QUEUE_GROUPS: - valid_len = sizeof(struct virtchnl2_add_queue_groups); - if (msglen != valid_len) { - __le64 offset; - __le32 i; - struct virtchnl2_add_queue_groups *add_queue_grp = - (struct virtchnl2_add_queue_groups *)msg; - struct virtchnl2_queue_groups *groups = &(add_queue_grp->qg_info); - struct virtchnl2_queue_group_info *grp_info; - __le32 chunk_size = sizeof(struct virtchnl2_queue_reg_chunk); - __le32 group_size = sizeof(struct virtchnl2_queue_group_info); - __le32 total_chunks_size; - - if (groups->num_queue_groups == 0) { - err_msg_format = true; - break; - } - valid_len += (groups->num_queue_groups - 1) * - sizeof(struct virtchnl2_queue_group_info); - offset = (u8 *)(&groups->groups[0]) - (u8 *)groups; - - for (i = 0; i < groups->num_queue_groups; i++) { - grp_info = (struct virtchnl2_queue_group_info *) - ((u8 *)groups + offset); - if (grp_info->chunks.num_chunks == 0) { - offset += group_size; - continue; - } - total_chunks_size = (grp_info->chunks.num_chunks - 1) * chunk_size; - offset += group_size + total_chunks_size; - valid_len += total_chunks_size; - } - } - break; - case VIRTCHNL2_OP_DEL_QUEUE_GROUPS: - valid_len = sizeof(struct virtchnl2_delete_queue_groups); - if (msglen != valid_len) { - struct virtchnl2_delete_queue_groups *del_queue_grp = - (struct virtchnl2_delete_queue_groups *)msg; - - if (del_queue_grp->num_queue_groups == 0) { - err_msg_format = true; - break; - } - - valid_len += (del_queue_grp->num_queue_groups - 1) * - sizeof(struct virtchnl2_queue_group_id); - } - break; - case VIRTCHNL2_OP_MAP_QUEUE_VECTOR: - case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR: - valid_len = sizeof(struct virtchnl2_queue_vector_maps); - if (msglen >= valid_len) { - struct virtchnl2_queue_vector_maps *v_qp = - (struct virtchnl2_queue_vector_maps *)msg; - if (v_qp->num_qv_maps == 0 || - v_qp->num_qv_maps > VIRTCHNL2_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) { - err_msg_format = true; - break; - } - valid_len += (v_qp->num_qv_maps - 1) * - sizeof(struct virtchnl2_queue_vector); - } - break; - case VIRTCHNL2_OP_ALLOC_VECTORS: - valid_len = sizeof(struct virtchnl2_alloc_vectors); - if (msglen >= valid_len) { - struct virtchnl2_alloc_vectors *v_av = - (struct virtchnl2_alloc_vectors *)msg; - - if (v_av->vchunks.num_vchunks == 0) { - /* Zero chunks is allowed as input */ - break; - } - - valid_len += (v_av->vchunks.num_vchunks - 1) * - sizeof(struct virtchnl2_vector_chunk); - } - break; - case VIRTCHNL2_OP_DEALLOC_VECTORS: - valid_len = sizeof(struct virtchnl2_vector_chunks); - if (msglen >= valid_len) { - struct virtchnl2_vector_chunks *v_chunks = - (struct virtchnl2_vector_chunks *)msg; - if (v_chunks->num_vchunks == 0) { - err_msg_format = true; - break; - } - valid_len += (v_chunks->num_vchunks - 1) * - sizeof(struct virtchnl2_vector_chunk); - } - break; - case VIRTCHNL2_OP_GET_RSS_KEY: - case VIRTCHNL2_OP_SET_RSS_KEY: - valid_len = sizeof(struct virtchnl2_rss_key); - if (msglen >= valid_len) { - struct virtchnl2_rss_key *vrk = - (struct virtchnl2_rss_key *)msg; - - if (vrk->key_len == 0) { - /* Zero length is allowed as input */ - break; - } - - valid_len += vrk->key_len - 1; - } - break; - case VIRTCHNL2_OP_GET_RSS_LUT: - case VIRTCHNL2_OP_SET_RSS_LUT: - valid_len = sizeof(struct virtchnl2_rss_lut); - if (msglen >= valid_len) { - struct virtchnl2_rss_lut *vrl = - (struct virtchnl2_rss_lut *)msg; - - if (vrl->lut_entries == 0) { - /* Zero entries is allowed as input */ - break; - } - - valid_len += (vrl->lut_entries - 1) * sizeof(vrl->lut); - } - break; - case VIRTCHNL2_OP_GET_RSS_HASH: - case VIRTCHNL2_OP_SET_RSS_HASH: - valid_len = sizeof(struct virtchnl2_rss_hash); - break; - case VIRTCHNL2_OP_SET_SRIOV_VFS: - valid_len = sizeof(struct virtchnl2_sriov_vfs_info); - break; - case VIRTCHNL2_OP_GET_PTYPE_INFO: - valid_len = sizeof(struct virtchnl2_get_ptype_info); - break; - case VIRTCHNL2_OP_GET_STATS: - valid_len = sizeof(struct virtchnl2_vport_stats); - break; - case VIRTCHNL2_OP_GET_PORT_STATS: - valid_len = sizeof(struct virtchnl2_port_stats); - break; - case VIRTCHNL2_OP_RESET_VF: - break; - case VIRTCHNL2_OP_GET_PTP_CAPS: - valid_len = sizeof(struct virtchnl2_get_ptp_caps); - - if (msglen > valid_len) { - struct virtchnl2_get_ptp_caps *ptp_caps = - (struct virtchnl2_get_ptp_caps *)msg; - - if (ptp_caps->tx_tstamp.num_latches == 0) { - err_msg_format = true; - break; - } - - valid_len += ((ptp_caps->tx_tstamp.num_latches - 1) * - sizeof(struct virtchnl2_ptp_tx_tstamp_entry)); - } - break; - case VIRTCHNL2_OP_GET_PTP_TX_TSTAMP_LATCHES: - valid_len = sizeof(struct virtchnl2_ptp_tx_tstamp_latches); - - if (msglen > valid_len) { - struct virtchnl2_ptp_tx_tstamp_latches *tx_tstamp_latches = - (struct virtchnl2_ptp_tx_tstamp_latches *)msg; - - if (tx_tstamp_latches->num_latches == 0) { - err_msg_format = true; - break; - } - - valid_len += ((tx_tstamp_latches->num_latches - 1) * - sizeof(struct virtchnl2_ptp_tx_tstamp_latch)); - } - break; - /* These are always errors coming from the VF */ - case VIRTCHNL2_OP_EVENT: - case VIRTCHNL2_OP_UNKNOWN: - default: - return VIRTCHNL2_STATUS_ERR_ESRCH; - } - /* Few more checks */ - if (err_msg_format || valid_len != msglen) - return VIRTCHNL2_STATUS_ERR_EINVAL; - - return 0; -} - #endif /* _VIRTCHNL_2_H_ */ diff --git a/drivers/common/idpf/idpf_common_virtchnl.c b/drivers/common/idpf/idpf_common_virtchnl.c index c46ed50eb5..f00202f43c 100644 --- a/drivers/common/idpf/idpf_common_virtchnl.c +++ b/drivers/common/idpf/idpf_common_virtchnl.c @@ -366,7 +366,7 @@ idpf_vc_queue_grps_add(struct idpf_vport *vport, int err = -1; size = sizeof(*p2p_queue_grps_info) + - (p2p_queue_grps_info->qg_info.num_queue_groups - 1) * + (p2p_queue_grps_info->num_queue_groups - 1) * sizeof(struct virtchnl2_queue_group_info); memset(&args, 0, sizeof(args)); diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c index 7e718e9e19..e707043bf7 100644 --- a/drivers/net/cpfl/cpfl_ethdev.c +++ b/drivers/net/cpfl/cpfl_ethdev.c @@ -2393,18 +2393,18 @@ cpfl_p2p_q_grps_add(struct idpf_vport *vport, int ret; p2p_queue_grps_info->vport_id = vport->vport_id; - p2p_queue_grps_info->qg_info.num_queue_groups = CPFL_P2P_NB_QUEUE_GRPS; - p2p_queue_grps_info->qg_info.groups[0].num_rx_q = CPFL_MAX_P2P_NB_QUEUES; - p2p_queue_grps_info->qg_info.groups[0].num_rx_bufq = CPFL_P2P_NB_RX_BUFQ; - p2p_queue_grps_info->qg_info.groups[0].num_tx_q = CPFL_MAX_P2P_NB_QUEUES; - p2p_queue_grps_info->qg_info.groups[0].num_tx_complq = CPFL_P2P_NB_TX_COMPLQ; - p2p_queue_grps_info->qg_info.groups[0].qg_id.queue_group_id = CPFL_P2P_QUEUE_GRP_ID; - p2p_queue_grps_info->qg_info.groups[0].qg_id.queue_group_type = VIRTCHNL2_QUEUE_GROUP_P2P; - p2p_queue_grps_info->qg_info.groups[0].rx_q_grp_info.rss_lut_size = 0; - p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.tx_tc = 0; - p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.priority = 0; - p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.is_sp = 0; - p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.pir_weight = 0; + p2p_queue_grps_info->num_queue_groups = CPFL_P2P_NB_QUEUE_GRPS; + p2p_queue_grps_info->groups[0].num_rx_q = CPFL_MAX_P2P_NB_QUEUES; + p2p_queue_grps_info->groups[0].num_rx_bufq = CPFL_P2P_NB_RX_BUFQ; + p2p_queue_grps_info->groups[0].num_tx_q = CPFL_MAX_P2P_NB_QUEUES; + p2p_queue_grps_info->groups[0].num_tx_complq = CPFL_P2P_NB_TX_COMPLQ; + p2p_queue_grps_info->groups[0].qg_id.queue_group_id = CPFL_P2P_QUEUE_GRP_ID; + p2p_queue_grps_info->groups[0].qg_id.queue_group_type = VIRTCHNL2_QUEUE_GROUP_P2P; + p2p_queue_grps_info->groups[0].rx_q_grp_info.rss_lut_size = 0; + p2p_queue_grps_info->groups[0].tx_q_grp_info.tx_tc = 0; + p2p_queue_grps_info->groups[0].tx_q_grp_info.priority = 0; + p2p_queue_grps_info->groups[0].tx_q_grp_info.is_sp = 0; + p2p_queue_grps_info->groups[0].tx_q_grp_info.pir_weight = 0; ret = idpf_vc_queue_grps_add(vport, p2p_queue_grps_info, p2p_q_vc_out_info); if (ret != 0) { @@ -2423,13 +2423,13 @@ cpfl_p2p_queue_info_init(struct cpfl_vport *cpfl_vport, struct virtchnl2_queue_reg_chunks *vc_chunks_out; int i, type; - if (p2p_q_vc_out_info->qg_info.groups[0].qg_id.queue_group_type != + if (p2p_q_vc_out_info->groups[0].qg_id.queue_group_type != VIRTCHNL2_QUEUE_GROUP_P2P) { PMD_DRV_LOG(ERR, "Add queue group response mismatch."); return -EINVAL; } - vc_chunks_out = &p2p_q_vc_out_info->qg_info.groups[0].chunks; + vc_chunks_out = &p2p_q_vc_out_info->groups[0].chunks; for (i = 0; i < vc_chunks_out->num_chunks; i++) { type = vc_chunks_out->chunks[i].type; -- 2.43.0