+
+void
+fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
+{
+ struct rte_port *port;
+ struct rte_eth_fdir_flex_conf *flex_conf;
+ int i, idx = 0;
+
+ port = &ports[port_id];
+ flex_conf = &port->dev_conf.fdir_conf.flex_conf;
+ for (i = 0; i < RTE_ETH_FLOW_TYPE_MAX; i++) {
+ if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
+ idx = i;
+ break;
+ }
+ }
+ if (i >= RTE_ETH_FLOW_TYPE_MAX) {
+ if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
+ idx = flex_conf->nb_flexmasks;
+ flex_conf->nb_flexmasks++;
+ } else {
+ printf("The flex mask table is full. Can not set flex"
+ " mask for flow_type(%u).", cfg->flow_type);
+ return;
+ }
+ }
+ (void)rte_memcpy(&flex_conf->flex_mask[idx],
+ cfg,
+ sizeof(struct rte_eth_fdir_flex_mask));
+}
+
+void
+fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
+{
+ struct rte_port *port;
+ struct rte_eth_fdir_flex_conf *flex_conf;
+ int i, idx = 0;
+
+ port = &ports[port_id];
+ flex_conf = &port->dev_conf.fdir_conf.flex_conf;
+ for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
+ if (cfg->type == flex_conf->flex_set[i].type) {
+ idx = i;
+ break;
+ }
+ }
+ if (i >= RTE_ETH_PAYLOAD_MAX) {
+ if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
+ idx = flex_conf->nb_payloads;
+ flex_conf->nb_payloads++;
+ } else {
+ printf("The flex payload table is full. Can not set"
+ " flex payload for type(%u).", cfg->type);
+ return;
+ }
+ }
+ (void)rte_memcpy(&flex_conf->flex_set[idx],
+ cfg,
+ sizeof(struct rte_eth_flex_payload_cfg));
+
+}
+
+void
+set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
+{
+ int diag;
+
+ if (port_id_is_invalid(port_id))
+ return;
+ if (is_rx)
+ diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
+ else
+ diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
+ if (diag == 0)
+ return;
+ if(is_rx)
+ printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
+ "diag=%d\n", port_id, diag);
+ else
+ printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
+ "diag=%d\n", port_id, diag);
+
+}
+
+void
+set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
+{
+ int diag;
+
+ if (port_id_is_invalid(port_id))
+ return;
+ if (vlan_id_is_invalid(vlan_id))
+ return;
+ diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
+ if (diag == 0)
+ return;
+ printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
+ "diag=%d\n", port_id, diag);
+}
+
+int
+set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
+{
+ int diag;
+ struct rte_eth_link link;
+
+ if (port_id_is_invalid(port_id))
+ return 1;
+ rte_eth_link_get_nowait(port_id, &link);
+ if (rate > link.link_speed) {
+ printf("Invalid rate value:%u bigger than link speed: %u\n",
+ rate, link.link_speed);
+ return 1;
+ }
+ diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
+ if (diag == 0)
+ return diag;
+ printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
+ port_id, diag);
+ return diag;
+}
+
+int
+set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
+{
+ int diag;
+ struct rte_eth_link link;
+
+ if (q_msk == 0)
+ return 0;
+
+ if (port_id_is_invalid(port_id))
+ return 1;
+ rte_eth_link_get_nowait(port_id, &link);
+ if (rate > link.link_speed) {
+ printf("Invalid rate value:%u bigger than link speed: %u\n",
+ rate, link.link_speed);
+ return 1;
+ }
+ diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
+ if (diag == 0)
+ return diag;
+ printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
+ port_id, diag);
+ return diag;
+}
+
+void
+get_syn_filter(uint8_t port_id)
+{
+ struct rte_syn_filter filter;
+ int ret = 0;
+ uint16_t rx_queue;
+
+ memset(&filter, 0, sizeof(filter));
+ ret = rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue);
+
+ if (ret < 0) {
+ if (ret == (-ENOENT))
+ printf("syn filter is not enabled\n");
+ else
+ printf("get syn filter fails(%s)\n", strerror(-ret));
+ return;
+ }
+ printf("syn filter: priority: %s, queue: %d\n",
+ filter.hig_pri ? "high" : "low",
+ rx_queue);
+}
+void
+get_2tuple_filter(uint8_t port_id, uint16_t index)
+{
+ struct rte_2tuple_filter filter;
+ int ret = 0;
+ uint16_t rx_queue;
+
+ memset(&filter, 0, sizeof(filter));
+ ret = rte_eth_dev_get_2tuple_filter(port_id, index,
+ &filter, &rx_queue);
+ if (ret < 0) {
+ if (ret == (-ENOENT))
+ printf("filter[%d] is not enabled\n", index);
+ else
+ printf("get 2tuple filter fails(%s)\n", strerror(-ret));
+ return;
+ } else {
+ printf("filter[%d]:\n", index);
+ printf(" Destination Port: 0x%04x mask: %d\n",
+ rte_be_to_cpu_16(filter.dst_port),
+ filter.dst_port_mask ? 0 : 1);
+ printf(" protocol: 0x%02x mask:%d tcp_flags: 0x%02x\n",
+ filter.protocol, filter.protocol_mask ? 0 : 1,
+ filter.tcp_flags);
+ printf(" priority: %d queue: %d\n",
+ filter.priority, rx_queue);
+ }
+}
+
+void
+get_5tuple_filter(uint8_t port_id, uint16_t index)
+{
+ struct rte_5tuple_filter filter;
+ int ret = 0;
+ uint16_t rx_queue;
+
+ memset(&filter, 0, sizeof(filter));
+ ret = rte_eth_dev_get_5tuple_filter(port_id, index,
+ &filter, &rx_queue);
+ if (ret < 0) {
+ if (ret == (-ENOENT))
+ printf("filter[%d] is not enabled\n", index);
+ else
+ printf("get 5tuple filter fails(%s)\n", strerror(-ret));
+ return;
+ } else {
+ printf("filter[%d]:\n", index);
+ printf(" Destination IP: 0x%08x mask: %d\n",
+ (unsigned)rte_be_to_cpu_32(filter.dst_ip),
+ filter.dst_ip_mask ? 0 : 1);
+ printf(" Source IP: 0x%08x mask: %d\n",
+ (unsigned)rte_be_to_cpu_32(filter.src_ip),
+ filter.src_ip_mask ? 0 : 1);
+ printf(" Destination Port: 0x%04x mask: %d\n",
+ rte_be_to_cpu_16(filter.dst_port),
+ filter.dst_port_mask ? 0 : 1);
+ printf(" Source Port: 0x%04x mask: %d\n",
+ rte_be_to_cpu_16(filter.src_port),
+ filter.src_port_mask ? 0 : 1);
+ printf(" protocol: 0x%02x mask: %d\n",
+ filter.protocol,
+ filter.protocol_mask ? 0 : 1);
+ printf(" priority: %d flags: 0x%02x queue: %d\n",
+ filter.priority, filter.tcp_flags, rx_queue);
+ }
+}
+void
+get_flex_filter(uint8_t port_id, uint16_t index)
+
+{
+ struct rte_flex_filter filter;
+ int ret = 0;
+ uint16_t rx_queue;
+ int i, j;
+
+ memset(&filter, 0, sizeof(filter));
+ ret = rte_eth_dev_get_flex_filter(port_id, index,
+ &filter, &rx_queue);
+ if (ret < 0) {
+ if (ret == (-ENOENT))
+ printf("filter[%d] is not enabled\n", index);
+ else
+ printf("get flex filter fails(%s)\n", strerror(-ret));
+ return;
+ } else {
+ printf("filter[%d]: ", index);
+ printf("\n length: %d", filter.len);
+ printf("\n dword[]: 0x");
+ for (i = 0; i < 32; i++)
+ printf("%08x ", (unsigned)rte_be_to_cpu_32(filter.dwords[i]));
+ printf("\n mask[]: 0b");
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 8; j++)
+ printf("%c", (filter.mask[i] & (1 << j)) ? '1' : '0');
+ }
+ printf("\n priority: %d queue: %d\n",
+ filter.priority, rx_queue);
+ }
+}