+int
+rte_table_action_meter_profile_delete(struct rte_table_action *action,
+ uint32_t meter_profile_id)
+{
+ struct meter_profile_data *mp_data;
+
+ /* Check input arguments */
+ if ((action == NULL) ||
+ ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0))
+ return -EINVAL;
+
+ mp_data = meter_profile_data_find(action->mp,
+ RTE_DIM(action->mp),
+ meter_profile_id);
+ if (!mp_data)
+ return 0;
+
+ /* Uninstall profile */
+ mp_data->valid = 0;
+
+ return 0;
+}
+
+int
+rte_table_action_meter_read(struct rte_table_action *action,
+ void *data,
+ uint32_t tc_mask,
+ struct rte_table_action_mtr_counters *stats,
+ int clear)
+{
+ struct mtr_trtcm_data *mtr_data;
+ uint32_t i;
+
+ /* Check input arguments */
+ if ((action == NULL) ||
+ ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
+ (data == NULL) ||
+ (tc_mask > RTE_LEN2MASK(action->cfg.mtr.n_tc, uint32_t)))
+ return -EINVAL;
+
+ mtr_data = action_data_get(data, action, RTE_TABLE_ACTION_MTR);
+
+ /* Read */
+ if (stats) {
+ for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
+ struct rte_table_action_mtr_counters_tc *dst =
+ &stats->stats[i];
+ struct mtr_trtcm_data *src = &mtr_data[i];
+
+ if ((tc_mask & (1 << i)) == 0)
+ continue;
+
+ dst->n_packets[e_RTE_METER_GREEN] =
+ mtr_trtcm_data_stats_get(src, e_RTE_METER_GREEN);
+
+ dst->n_packets[e_RTE_METER_YELLOW] =
+ mtr_trtcm_data_stats_get(src, e_RTE_METER_YELLOW);
+
+ dst->n_packets[e_RTE_METER_RED] =
+ mtr_trtcm_data_stats_get(src, e_RTE_METER_RED);
+
+ dst->n_packets_valid = 1;
+ dst->n_bytes_valid = 0;
+ }
+
+ stats->tc_mask = tc_mask;
+ }
+
+ /* Clear */
+ if (clear)
+ for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
+ struct mtr_trtcm_data *src = &mtr_data[i];
+
+ if ((tc_mask & (1 << i)) == 0)
+ continue;
+
+ mtr_trtcm_data_stats_reset(src, e_RTE_METER_GREEN);
+ mtr_trtcm_data_stats_reset(src, e_RTE_METER_YELLOW);
+ mtr_trtcm_data_stats_reset(src, e_RTE_METER_RED);
+ }
+
+
+ return 0;
+}
+
+static __rte_always_inline uint64_t
+pkt_work(struct rte_mbuf *mbuf,
+ struct rte_pipeline_table_entry *table_entry,
+ uint64_t time,
+ struct rte_table_action *action,
+ struct ap_config *cfg)
+{
+ uint64_t drop_mask = 0;
+
+ uint32_t ip_offset = action->cfg.common.ip_offset;
+ void *ip = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ip_offset);
+
+ uint32_t dscp;
+ uint16_t total_length;
+
+ if (cfg->common.ip_version) {
+ struct ipv4_hdr *hdr = ip;
+
+ dscp = hdr->type_of_service >> 2;
+ total_length = rte_ntohs(hdr->total_length);
+ } else {
+ struct ipv6_hdr *hdr = ip;
+
+ dscp = (rte_ntohl(hdr->vtc_flow) & 0x0F600000) >> 18;
+ total_length =
+ rte_ntohs(hdr->payload_len) + sizeof(struct ipv6_hdr);
+ }
+
+ if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
+ void *data =
+ action_data_get(table_entry, action, RTE_TABLE_ACTION_MTR);
+
+ drop_mask |= pkt_work_mtr(mbuf,
+ data,
+ &action->dscp_table,
+ action->mp,
+ time,
+ dscp,
+ total_length);
+ }
+
+ return drop_mask;
+}
+
+static __rte_always_inline uint64_t
+pkt4_work(struct rte_mbuf **mbufs,
+ struct rte_pipeline_table_entry **table_entries,
+ uint64_t time,
+ struct rte_table_action *action,
+ struct ap_config *cfg)
+{
+ uint64_t drop_mask0 = 0;
+ uint64_t drop_mask1 = 0;
+ uint64_t drop_mask2 = 0;
+ uint64_t drop_mask3 = 0;
+
+ struct rte_mbuf *mbuf0 = mbufs[0];
+ struct rte_mbuf *mbuf1 = mbufs[1];
+ struct rte_mbuf *mbuf2 = mbufs[2];
+ struct rte_mbuf *mbuf3 = mbufs[3];
+
+ struct rte_pipeline_table_entry *table_entry0 = table_entries[0];
+ struct rte_pipeline_table_entry *table_entry1 = table_entries[1];
+ struct rte_pipeline_table_entry *table_entry2 = table_entries[2];
+ struct rte_pipeline_table_entry *table_entry3 = table_entries[3];
+
+ uint32_t ip_offset = action->cfg.common.ip_offset;
+ void *ip0 = RTE_MBUF_METADATA_UINT32_PTR(mbuf0, ip_offset);
+ void *ip1 = RTE_MBUF_METADATA_UINT32_PTR(mbuf1, ip_offset);
+ void *ip2 = RTE_MBUF_METADATA_UINT32_PTR(mbuf2, ip_offset);
+ void *ip3 = RTE_MBUF_METADATA_UINT32_PTR(mbuf3, ip_offset);
+
+ uint32_t dscp0, dscp1, dscp2, dscp3;
+ uint16_t total_length0, total_length1, total_length2, total_length3;
+
+ if (cfg->common.ip_version) {
+ struct ipv4_hdr *hdr0 = ip0;
+ struct ipv4_hdr *hdr1 = ip1;
+ struct ipv4_hdr *hdr2 = ip2;
+ struct ipv4_hdr *hdr3 = ip3;
+
+ dscp0 = hdr0->type_of_service >> 2;
+ dscp1 = hdr1->type_of_service >> 2;
+ dscp2 = hdr2->type_of_service >> 2;
+ dscp3 = hdr3->type_of_service >> 2;
+
+ total_length0 = rte_ntohs(hdr0->total_length);
+ total_length1 = rte_ntohs(hdr1->total_length);
+ total_length2 = rte_ntohs(hdr2->total_length);
+ total_length3 = rte_ntohs(hdr3->total_length);
+ } else {
+ struct ipv6_hdr *hdr0 = ip0;
+ struct ipv6_hdr *hdr1 = ip1;
+ struct ipv6_hdr *hdr2 = ip2;
+ struct ipv6_hdr *hdr3 = ip3;
+
+ dscp0 = (rte_ntohl(hdr0->vtc_flow) & 0x0F600000) >> 18;
+ dscp1 = (rte_ntohl(hdr1->vtc_flow) & 0x0F600000) >> 18;
+ dscp2 = (rte_ntohl(hdr2->vtc_flow) & 0x0F600000) >> 18;
+ dscp3 = (rte_ntohl(hdr3->vtc_flow) & 0x0F600000) >> 18;
+
+ total_length0 =
+ rte_ntohs(hdr0->payload_len) + sizeof(struct ipv6_hdr);
+ total_length1 =
+ rte_ntohs(hdr1->payload_len) + sizeof(struct ipv6_hdr);
+ total_length2 =
+ rte_ntohs(hdr2->payload_len) + sizeof(struct ipv6_hdr);
+ total_length3 =
+ rte_ntohs(hdr3->payload_len) + sizeof(struct ipv6_hdr);
+ }
+
+ if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
+ void *data0 =
+ action_data_get(table_entry0, action, RTE_TABLE_ACTION_MTR);
+ void *data1 =
+ action_data_get(table_entry1, action, RTE_TABLE_ACTION_MTR);
+ void *data2 =
+ action_data_get(table_entry2, action, RTE_TABLE_ACTION_MTR);
+ void *data3 =
+ action_data_get(table_entry3, action, RTE_TABLE_ACTION_MTR);
+
+ drop_mask0 |= pkt_work_mtr(mbuf0,
+ data0,
+ &action->dscp_table,
+ action->mp,
+ time,
+ dscp0,
+ total_length0);
+
+ drop_mask1 |= pkt_work_mtr(mbuf1,
+ data1,
+ &action->dscp_table,
+ action->mp,
+ time,
+ dscp1,
+ total_length1);
+
+ drop_mask2 |= pkt_work_mtr(mbuf2,
+ data2,
+ &action->dscp_table,
+ action->mp,
+ time,
+ dscp2,
+ total_length2);
+
+ drop_mask3 |= pkt_work_mtr(mbuf3,
+ data3,
+ &action->dscp_table,
+ action->mp,
+ time,
+ dscp3,
+ total_length3);
+ }
+
+ return drop_mask0 |
+ (drop_mask1 << 1) |
+ (drop_mask2 << 2) |
+ (drop_mask3 << 3);
+}
+