net/i40e: update ptype and pctype info
[dpdk.git] / drivers / net / i40e / rte_pmd_i40e.c
index 4672388..0cd2d7a 100644 (file)
 #include "i40e_rxtx.h"
 #include "rte_pmd_i40e.h"
 
-/* The max bandwidth of i40e is 40Gbps. */
-#define I40E_QOS_BW_MAX 40000
-/* The bandwidth should be the multiple of 50Mbps. */
-#define I40E_QOS_BW_GRANULARITY 50
-/* The min bandwidth weight is 1. */
-#define I40E_QOS_BW_WEIGHT_MIN 1
-/* The max bandwidth weight is 127. */
-#define I40E_QOS_BW_WEIGHT_MAX 127
-
 int
 rte_pmd_i40e_ping_vfs(uint8_t port, uint16_t vf)
 {
@@ -126,7 +117,7 @@ rte_pmd_i40e_set_vf_mac_anti_spoof(uint8_t port, uint16_t vf_id, uint8_t on)
                vsi->info.sec_flags &= ~I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
 
        memset(&ctxt, 0, sizeof(ctxt));
-       (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
+       rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
        ctxt.seid = vsi->seid;
 
        hw = I40E_VSI_TO_HW(vsi);
@@ -228,7 +219,7 @@ rte_pmd_i40e_set_vf_vlan_anti_spoof(uint8_t port, uint16_t vf_id, uint8_t on)
                vsi->info.sec_flags &= ~I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK;
 
        memset(&ctxt, 0, sizeof(ctxt));
-       (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
+       rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
        ctxt.seid = vsi->seid;
 
        hw = I40E_VSI_TO_HW(vsi);
@@ -273,7 +264,7 @@ i40e_vsi_rm_mac_filter(struct i40e_vsi *vsi)
 
                for (i = 0; i < vlan_num; i++) {
                        mv_f[i].filter_type = filter_type;
-                       (void)rte_memcpy(&mv_f[i].macaddr,
+                       rte_memcpy(&mv_f[i].macaddr,
                                         &f->mac_info.mac_addr,
                                         ETH_ADDR_LEN);
                }
@@ -334,7 +325,7 @@ i40e_vsi_restore_mac_filter(struct i40e_vsi *vsi)
 
                for (i = 0; i < vlan_num; i++) {
                        mv_f[i].filter_type = f->mac_info.filter_type;
-                       (void)rte_memcpy(&mv_f[i].macaddr,
+                       rte_memcpy(&mv_f[i].macaddr,
                                         &f->mac_info.mac_addr,
                                         ETH_ADDR_LEN);
                }
@@ -416,7 +407,7 @@ i40e_vsi_set_tx_loopback(struct i40e_vsi *vsi, uint8_t on)
                vsi->info.switch_id &= ~I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
 
        memset(&ctxt, 0, sizeof(ctxt));
-       (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
+       rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
        ctxt.seid = vsi->seid;
 
        ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
@@ -600,7 +591,9 @@ rte_pmd_i40e_set_vf_mac_addr(uint8_t port, uint16_t vf_id,
 
        /* Remove all existing mac */
        TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
-               i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
+               if (i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr)
+                               != I40E_SUCCESS)
+                       PMD_DRV_LOG(WARNING, "Delete MAC failed");
 
        return 0;
 }
@@ -694,7 +687,7 @@ int rte_pmd_i40e_set_vf_vlan_insert(uint8_t port, uint16_t vf_id,
                vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_INSERT_PVID;
 
        memset(&ctxt, 0, sizeof(ctxt));
-       (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
+       rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
        ctxt.seid = vsi->seid;
 
        hw = I40E_VSI_TO_HW(vsi);
@@ -756,7 +749,7 @@ int rte_pmd_i40e_set_vf_broadcast(uint8_t port, uint16_t vf_id,
        }
 
        if (on) {
-               (void)rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
+               rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
                filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
                ret = i40e_vsi_add_mac(vsi, &filter);
        } else {
@@ -828,7 +821,7 @@ int rte_pmd_i40e_set_vf_vlan_tag(uint8_t port, uint16_t vf_id, uint8_t on)
        }
 
        memset(&ctxt, 0, sizeof(ctxt));
-       (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
+       rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
        ctxt.seid = vsi->seid;
 
        hw = I40E_VSI_TO_HW(vsi);
@@ -1615,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);
@@ -1713,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)
@@ -1867,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;
 }
@@ -1942,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 &&
@@ -2124,3 +2292,141 @@ int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
 
        return 0;
 }
+
+int
+rte_pmd_i40e_add_vf_mac_addr(uint8_t port, uint16_t vf_id,
+                            struct ether_addr *mac_addr)
+{
+       struct rte_eth_dev *dev;
+       struct i40e_pf_vf *vf;
+       struct i40e_vsi *vsi;
+       struct i40e_pf *pf;
+       struct i40e_mac_filter_info mac_filter;
+       int ret;
+
+       if (i40e_validate_mac_addr((u8 *)mac_addr) != I40E_SUCCESS)
+               return -EINVAL;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+       dev = &rte_eth_devices[port];
+
+       if (!is_i40e_supported(dev))
+               return -ENOTSUP;
+
+       pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+       if (vf_id >= pf->vf_num || !pf->vfs)
+               return -EINVAL;
+
+       vf = &pf->vfs[vf_id];
+       vsi = vf->vsi;
+       if (!vsi) {
+               PMD_DRV_LOG(ERR, "Invalid VSI.");
+               return -EINVAL;
+       }
+
+       mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
+       ether_addr_copy(mac_addr, &mac_filter.mac_addr);
+       ret = i40e_vsi_add_mac(vsi, &mac_filter);
+       if (ret != I40E_SUCCESS) {
+               PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
+               return -1;
+       }
+
+       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;
+}