net/i40e: update ptype and pctype info
[dpdk.git] / drivers / net / i40e / rte_pmd_i40e.c
index c08e07a..0cd2d7a 100644 (file)
@@ -1608,6 +1608,8 @@ rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
                return -EINVAL;
        }
 
+       i40e_update_customized_info(dev, buff, size);
+
        /* Find metadata segment */
        metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
                                                        pkg_hdr);
@@ -1706,6 +1708,27 @@ rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
        return status;
 }
 
+/* Get number of tvl records in the section */
+static unsigned int
+i40e_get_tlv_section_size(struct i40e_profile_section_header *sec)
+{
+       unsigned int i, nb_rec, nb_tlv = 0;
+       struct i40e_profile_tlv_section_record *tlv;
+
+       if (!sec)
+               return nb_tlv;
+
+       /* get number of records in the section */
+       nb_rec = sec->section.size /
+                               sizeof(struct i40e_profile_tlv_section_record);
+       for (i = 0; i < nb_rec; ) {
+               tlv = (struct i40e_profile_tlv_section_record *)&sec[1 + i];
+               i += tlv->len;
+               nb_tlv++;
+       }
+       return nb_tlv;
+}
+
 int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
        uint8_t *info_buff, uint32_t info_size,
        enum rte_pmd_i40e_package_info type)
@@ -1860,6 +1883,156 @@ int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
                return I40E_SUCCESS;
        }
 
+       /* get number of protocols */
+       if (type == RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM) {
+               struct i40e_profile_section_header *proto;
+
+               if (info_size < sizeof(uint32_t)) {
+                       PMD_DRV_LOG(ERR, "Invalid information buffer size");
+                       return -EINVAL;
+               }
+               proto = i40e_find_section_in_profile(SECTION_TYPE_PROTO,
+                               (struct i40e_profile_segment *)i40e_seg_hdr);
+               *(uint32_t *)info_buff = i40e_get_tlv_section_size(proto);
+               return I40E_SUCCESS;
+       }
+
+       /* get list of protocols */
+       if (type == RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST) {
+               uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
+               struct rte_pmd_i40e_proto_info *pinfo;
+               struct i40e_profile_section_header *proto;
+               struct i40e_profile_tlv_section_record *tlv;
+
+               pinfo = (struct rte_pmd_i40e_proto_info *)info_buff;
+               nb_proto_info = info_size /
+                                       sizeof(struct rte_pmd_i40e_proto_info);
+               for (i = 0; i < nb_proto_info; i++) {
+                       pinfo[i].proto_id = RTE_PMD_I40E_PROTO_UNUSED;
+                       memset(pinfo[i].name, 0, RTE_PMD_I40E_DDP_NAME_SIZE);
+               }
+               proto = i40e_find_section_in_profile(SECTION_TYPE_PROTO,
+                               (struct i40e_profile_segment *)i40e_seg_hdr);
+               nb_tlv = i40e_get_tlv_section_size(proto);
+               if (nb_tlv == 0)
+                       return I40E_SUCCESS;
+               if (nb_proto_info < nb_tlv) {
+                       PMD_DRV_LOG(ERR, "Invalid information buffer size");
+                       return -EINVAL;
+               }
+               /* get number of records in the section */
+               nb_rec = proto->section.size /
+                               sizeof(struct i40e_profile_tlv_section_record);
+               tlv = (struct i40e_profile_tlv_section_record *)&proto[1];
+               for (i = j = 0; i < nb_rec; j++) {
+                       pinfo[j].proto_id = tlv->data[0];
+                       strncpy(pinfo[j].name, (const char *)&tlv->data[1],
+                               I40E_DDP_NAME_SIZE);
+                       i += tlv->len;
+                       tlv = &tlv[tlv->len];
+               }
+               return I40E_SUCCESS;
+       }
+
+       /* get number of packet classification types */
+       if (type == RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM) {
+               struct i40e_profile_section_header *pctype;
+
+               if (info_size < sizeof(uint32_t)) {
+                       PMD_DRV_LOG(ERR, "Invalid information buffer size");
+                       return -EINVAL;
+               }
+               pctype = i40e_find_section_in_profile(SECTION_TYPE_PCTYPE,
+                               (struct i40e_profile_segment *)i40e_seg_hdr);
+               *(uint32_t *)info_buff = i40e_get_tlv_section_size(pctype);
+               return I40E_SUCCESS;
+       }
+
+       /* get list of packet classification types */
+       if (type == RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST) {
+               uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
+               struct rte_pmd_i40e_ptype_info *pinfo;
+               struct i40e_profile_section_header *pctype;
+               struct i40e_profile_tlv_section_record *tlv;
+
+               pinfo = (struct rte_pmd_i40e_ptype_info *)info_buff;
+               nb_proto_info = info_size /
+                                       sizeof(struct rte_pmd_i40e_ptype_info);
+               for (i = 0; i < nb_proto_info; i++)
+                       memset(&pinfo[i], RTE_PMD_I40E_PROTO_UNUSED,
+                              sizeof(struct rte_pmd_i40e_ptype_info));
+               pctype = i40e_find_section_in_profile(SECTION_TYPE_PCTYPE,
+                               (struct i40e_profile_segment *)i40e_seg_hdr);
+               nb_tlv = i40e_get_tlv_section_size(pctype);
+               if (nb_tlv == 0)
+                       return I40E_SUCCESS;
+               if (nb_proto_info < nb_tlv) {
+                       PMD_DRV_LOG(ERR, "Invalid information buffer size");
+                       return -EINVAL;
+               }
+
+               /* get number of records in the section */
+               nb_rec = pctype->section.size /
+                               sizeof(struct i40e_profile_tlv_section_record);
+               tlv = (struct i40e_profile_tlv_section_record *)&pctype[1];
+               for (i = j = 0; i < nb_rec; j++) {
+                       memcpy(&pinfo[j], tlv->data,
+                              sizeof(struct rte_pmd_i40e_ptype_info));
+                       i += tlv->len;
+                       tlv = &tlv[tlv->len];
+               }
+               return I40E_SUCCESS;
+       }
+
+       /* get number of packet types */
+       if (type == RTE_PMD_I40E_PKG_INFO_PTYPE_NUM) {
+               struct i40e_profile_section_header *ptype;
+
+               if (info_size < sizeof(uint32_t)) {
+                       PMD_DRV_LOG(ERR, "Invalid information buffer size");
+                       return -EINVAL;
+               }
+               ptype = i40e_find_section_in_profile(SECTION_TYPE_PTYPE,
+                               (struct i40e_profile_segment *)i40e_seg_hdr);
+               *(uint32_t *)info_buff = i40e_get_tlv_section_size(ptype);
+               return I40E_SUCCESS;
+       }
+
+       /* get list of packet types */
+       if (type == RTE_PMD_I40E_PKG_INFO_PTYPE_LIST) {
+               uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
+               struct rte_pmd_i40e_ptype_info *pinfo;
+               struct i40e_profile_section_header *ptype;
+               struct i40e_profile_tlv_section_record *tlv;
+
+               pinfo = (struct rte_pmd_i40e_ptype_info *)info_buff;
+               nb_proto_info = info_size /
+                                       sizeof(struct rte_pmd_i40e_ptype_info);
+               for (i = 0; i < nb_proto_info; i++)
+                       memset(&pinfo[i], RTE_PMD_I40E_PROTO_UNUSED,
+                              sizeof(struct rte_pmd_i40e_ptype_info));
+               ptype = i40e_find_section_in_profile(SECTION_TYPE_PTYPE,
+                               (struct i40e_profile_segment *)i40e_seg_hdr);
+               nb_tlv = i40e_get_tlv_section_size(ptype);
+               if (nb_tlv == 0)
+                       return I40E_SUCCESS;
+               if (nb_proto_info < nb_tlv) {
+                       PMD_DRV_LOG(ERR, "Invalid information buffer size");
+                       return -EINVAL;
+               }
+               /* get number of records in the section */
+               nb_rec = ptype->section.size /
+                               sizeof(struct i40e_profile_tlv_section_record);
+               for (i = j = 0; i < nb_rec; j++) {
+                       tlv = (struct i40e_profile_tlv_section_record *)
+                                                               &ptype[1 + i];
+                       memcpy(&pinfo[j], tlv->data,
+                              sizeof(struct rte_pmd_i40e_ptype_info));
+                       i += tlv->len;
+               }
+               return I40E_SUCCESS;
+       }
+
        PMD_DRV_LOG(ERR, "Info type %u is invalid.", type);
        return -EINVAL;
 }
@@ -1935,7 +2108,9 @@ static int check_invalid_pkt_type(uint32_t pkt_type)
            tnl != RTE_PTYPE_TUNNEL_VXLAN &&
            tnl != RTE_PTYPE_TUNNEL_NVGRE &&
            tnl != RTE_PTYPE_TUNNEL_GENEVE &&
-           tnl != RTE_PTYPE_TUNNEL_GRENAT)
+           tnl != RTE_PTYPE_TUNNEL_GRENAT &&
+           tnl != RTE_PTYPE_TUNNEL_GTPC &&
+           tnl != RTE_PTYPE_TUNNEL_GTPU)
                return -1;
 
        if (il2 &&
@@ -2161,3 +2336,97 @@ rte_pmd_i40e_add_vf_mac_addr(uint8_t port, uint16_t vf_id,
 
        return 0;
 }
+
+int rte_pmd_i40e_flow_type_mapping_reset(uint8_t port)
+{
+       struct rte_eth_dev *dev;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+       dev = &rte_eth_devices[port];
+
+       if (!is_i40e_supported(dev))
+               return -ENOTSUP;
+
+       i40e_set_default_pctype_table(dev);
+
+       return 0;
+}
+
+int rte_pmd_i40e_flow_type_mapping_get(
+                       uint8_t port,
+                       struct rte_pmd_i40e_flow_type_mapping *mapping_items)
+{
+       struct rte_eth_dev *dev;
+       struct i40e_adapter *ad;
+       uint16_t i;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+       dev = &rte_eth_devices[port];
+
+       if (!is_i40e_supported(dev))
+               return -ENOTSUP;
+
+       ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+       for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
+               mapping_items[i].flow_type = i;
+               mapping_items[i].pctype = ad->pctypes_tbl[i];
+       }
+
+       return 0;
+}
+
+int
+rte_pmd_i40e_flow_type_mapping_update(
+                       uint8_t port,
+                       struct rte_pmd_i40e_flow_type_mapping *mapping_items,
+                       uint16_t count,
+                       uint8_t exclusive)
+{
+       struct rte_eth_dev *dev;
+       struct i40e_adapter *ad;
+       int i;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+       dev = &rte_eth_devices[port];
+
+       if (!is_i40e_supported(dev))
+               return -ENOTSUP;
+
+       if (count > I40E_FLOW_TYPE_MAX)
+               return -EINVAL;
+
+       for (i = 0; i < count; i++)
+               if (mapping_items[i].flow_type >= I40E_FLOW_TYPE_MAX ||
+                   mapping_items[i].flow_type == RTE_ETH_FLOW_UNKNOWN ||
+                   (mapping_items[i].pctype &
+                   (1ULL << I40E_FILTER_PCTYPE_INVALID)))
+                       return -EINVAL;
+
+       ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+       if (exclusive) {
+               for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
+                       ad->pctypes_tbl[i] = 0ULL;
+               ad->flow_types_mask = 0ULL;
+       }
+
+       for (i = 0; i < count; i++) {
+               ad->pctypes_tbl[mapping_items[i].flow_type] =
+                                               mapping_items[i].pctype;
+               if (mapping_items[i].pctype)
+                       ad->flow_types_mask |=
+                                       (1ULL << mapping_items[i].flow_type);
+               else
+                       ad->flow_types_mask &=
+                                       ~(1ULL << mapping_items[i].flow_type);
+       }
+
+       for (i = 0, ad->pctypes_mask = 0ULL; i < I40E_FLOW_TYPE_MAX; i++)
+               ad->pctypes_mask |= ad->pctypes_tbl[i];
+
+       return 0;
+}