- struct mlx5_priv *priv = dev->data->dev_private;
- const struct rte_eth_fdir_input *input = &fdir_filter->input;
- const struct rte_eth_fdir_masks *mask =
- &dev->data->dev_conf.fdir_conf.mask;
-
- /* Validate queue number. */
- if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
- DRV_LOG(ERR, "port %u invalid queue number %d",
- dev->data->port_id, fdir_filter->action.rx_queue);
- rte_errno = EINVAL;
- return -rte_errno;
- }
- attributes->attr.ingress = 1;
- attributes->items[0] = (struct rte_flow_item) {
- .type = RTE_FLOW_ITEM_TYPE_ETH,
- .spec = &attributes->l2,
- .mask = &attributes->l2_mask,
- };
- switch (fdir_filter->action.behavior) {
- case RTE_ETH_FDIR_ACCEPT:
- attributes->actions[0] = (struct rte_flow_action){
- .type = RTE_FLOW_ACTION_TYPE_QUEUE,
- .conf = &attributes->queue,
- };
- break;
- case RTE_ETH_FDIR_REJECT:
- attributes->actions[0] = (struct rte_flow_action){
- .type = RTE_FLOW_ACTION_TYPE_DROP,
- };
- break;
- default:
- DRV_LOG(ERR, "port %u invalid behavior %d",
- dev->data->port_id,
- fdir_filter->action.behavior);
- rte_errno = ENOTSUP;
- return -rte_errno;
- }
- attributes->queue.index = fdir_filter->action.rx_queue;
- /* Handle L3. */
- switch (fdir_filter->input.flow_type) {
- case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
- case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
- case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
- attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
- .src_addr = input->flow.ip4_flow.src_ip,
- .dst_addr = input->flow.ip4_flow.dst_ip,
- .time_to_live = input->flow.ip4_flow.ttl,
- .type_of_service = input->flow.ip4_flow.tos,
- };
- attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
- .src_addr = mask->ipv4_mask.src_ip,
- .dst_addr = mask->ipv4_mask.dst_ip,
- .time_to_live = mask->ipv4_mask.ttl,
- .type_of_service = mask->ipv4_mask.tos,
- .next_proto_id = mask->ipv4_mask.proto,
- };
- attributes->items[1] = (struct rte_flow_item){
- .type = RTE_FLOW_ITEM_TYPE_IPV4,
- .spec = &attributes->l3,
- .mask = &attributes->l3_mask,
- };
- break;
- case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
- case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
- case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
- attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
- .hop_limits = input->flow.ipv6_flow.hop_limits,
- .proto = input->flow.ipv6_flow.proto,
- };
-
- memcpy(attributes->l3.ipv6.hdr.src_addr,
- input->flow.ipv6_flow.src_ip,
- RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
- memcpy(attributes->l3.ipv6.hdr.dst_addr,
- input->flow.ipv6_flow.dst_ip,
- RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
- memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
- mask->ipv6_mask.src_ip,
- RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
- memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
- mask->ipv6_mask.dst_ip,
- RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
- attributes->items[1] = (struct rte_flow_item){
- .type = RTE_FLOW_ITEM_TYPE_IPV6,
- .spec = &attributes->l3,
- .mask = &attributes->l3_mask,
- };
- break;
- default:
- DRV_LOG(ERR, "port %u invalid flow type%d",
- dev->data->port_id, fdir_filter->input.flow_type);
- rte_errno = ENOTSUP;
- return -rte_errno;
- }
- /* Handle L4. */
- switch (fdir_filter->input.flow_type) {
- case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
- attributes->l4.udp.hdr = (struct rte_udp_hdr){
- .src_port = input->flow.udp4_flow.src_port,
- .dst_port = input->flow.udp4_flow.dst_port,
- };
- attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
- .src_port = mask->src_port_mask,
- .dst_port = mask->dst_port_mask,
- };
- attributes->items[2] = (struct rte_flow_item){
- .type = RTE_FLOW_ITEM_TYPE_UDP,
- .spec = &attributes->l4,
- .mask = &attributes->l4_mask,
- };
- break;
- case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
- attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
- .src_port = input->flow.tcp4_flow.src_port,
- .dst_port = input->flow.tcp4_flow.dst_port,
- };
- attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
- .src_port = mask->src_port_mask,
- .dst_port = mask->dst_port_mask,
- };
- attributes->items[2] = (struct rte_flow_item){
- .type = RTE_FLOW_ITEM_TYPE_TCP,
- .spec = &attributes->l4,
- .mask = &attributes->l4_mask,
- };
- break;
- case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
- attributes->l4.udp.hdr = (struct rte_udp_hdr){
- .src_port = input->flow.udp6_flow.src_port,
- .dst_port = input->flow.udp6_flow.dst_port,
- };
- attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
- .src_port = mask->src_port_mask,
- .dst_port = mask->dst_port_mask,
- };
- attributes->items[2] = (struct rte_flow_item){
- .type = RTE_FLOW_ITEM_TYPE_UDP,
- .spec = &attributes->l4,
- .mask = &attributes->l4_mask,
- };
- break;
- case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
- attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
- .src_port = input->flow.tcp6_flow.src_port,
- .dst_port = input->flow.tcp6_flow.dst_port,
- };
- attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
- .src_port = mask->src_port_mask,
- .dst_port = mask->dst_port_mask,
- };
- attributes->items[2] = (struct rte_flow_item){
- .type = RTE_FLOW_ITEM_TYPE_TCP,
- .spec = &attributes->l4,
- .mask = &attributes->l4_mask,
- };
- break;
- case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
- case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
- break;