4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
43 #pragma GCC diagnostic ignored "-pedantic"
45 #include <infiniband/verbs.h>
47 #pragma GCC diagnostic error "-pedantic"
50 /* DPDK headers don't like -pedantic. */
52 #pragma GCC diagnostic ignored "-pedantic"
54 #include <rte_ether.h>
55 #include <rte_malloc.h>
56 #include <rte_ethdev.h>
57 #include <rte_common.h>
59 #pragma GCC diagnostic error "-pedantic"
63 #include "mlx5_rxtx.h"
65 struct fdir_flow_desc {
72 enum hash_rxq_type type;
75 struct mlx5_fdir_filter {
76 LIST_ENTRY(mlx5_fdir_filter) next;
77 uint16_t queue; /* Queue assigned to if FDIR match. */
78 struct fdir_flow_desc desc;
79 struct ibv_exp_flow *flow;
82 LIST_HEAD(fdir_filter_list, mlx5_fdir_filter);
85 * Convert struct rte_eth_fdir_filter to mlx5 filter descriptor.
87 * @param[in] fdir_filter
88 * DPDK filter structure to convert.
90 * Resulting mlx5 filter descriptor.
95 fdir_filter_to_flow_desc(const struct rte_eth_fdir_filter *fdir_filter,
96 struct fdir_flow_desc *desc, enum rte_fdir_mode mode)
98 /* Initialize descriptor. */
99 memset(desc, 0, sizeof(*desc));
102 desc->vlan_tag = fdir_filter->input.flow_ext.vlan_tci;
104 /* Set MAC address. */
105 if (mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
106 rte_memcpy(desc->mac,
107 fdir_filter->input.flow.mac_vlan_flow.mac_addr.
110 desc->type = HASH_RXQ_ETH;
115 switch (fdir_filter->input.flow_type) {
116 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
117 desc->type = HASH_RXQ_UDPV4;
119 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
120 desc->type = HASH_RXQ_TCPV4;
122 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
123 desc->type = HASH_RXQ_IPV4;
125 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
126 desc->type = HASH_RXQ_UDPV6;
128 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
129 desc->type = HASH_RXQ_TCPV6;
131 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
132 desc->type = HASH_RXQ_IPV6;
138 /* Set flow values */
139 switch (fdir_filter->input.flow_type) {
140 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
141 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
142 desc->src_port = fdir_filter->input.flow.udp4_flow.src_port;
143 desc->dst_port = fdir_filter->input.flow.udp4_flow.dst_port;
144 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
145 desc->src_ip[0] = fdir_filter->input.flow.ip4_flow.src_ip;
146 desc->dst_ip[0] = fdir_filter->input.flow.ip4_flow.dst_ip;
148 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
149 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
150 desc->src_port = fdir_filter->input.flow.udp6_flow.src_port;
151 desc->dst_port = fdir_filter->input.flow.udp6_flow.dst_port;
153 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
154 rte_memcpy(desc->src_ip,
155 fdir_filter->input.flow.ipv6_flow.src_ip,
156 sizeof(desc->src_ip));
157 rte_memcpy(desc->dst_ip,
158 fdir_filter->input.flow.ipv6_flow.dst_ip,
159 sizeof(desc->dst_ip));
167 * Check if two flow descriptors overlap according to configured mask.
170 * Private structure that provides flow director mask.
172 * First flow descriptor to compare.
174 * Second flow descriptor to compare.
177 * Nonzero if descriptors overlap.
180 priv_fdir_overlap(const struct priv *priv,
181 const struct fdir_flow_desc *desc1,
182 const struct fdir_flow_desc *desc2)
184 const struct rte_eth_fdir_masks *mask =
185 &priv->dev->data->dev_conf.fdir_conf.mask;
188 if (desc1->type != desc2->type)
190 /* Ignore non masked bits. */
191 for (i = 0; i != RTE_DIM(desc1->mac); ++i)
192 if ((desc1->mac[i] & mask->mac_addr_byte_mask) !=
193 (desc2->mac[i] & mask->mac_addr_byte_mask))
195 if (((desc1->src_port & mask->src_port_mask) !=
196 (desc2->src_port & mask->src_port_mask)) ||
197 ((desc1->dst_port & mask->dst_port_mask) !=
198 (desc2->dst_port & mask->dst_port_mask)))
200 switch (desc1->type) {
204 if (((desc1->src_ip[0] & mask->ipv4_mask.src_ip) !=
205 (desc2->src_ip[0] & mask->ipv4_mask.src_ip)) ||
206 ((desc1->dst_ip[0] & mask->ipv4_mask.dst_ip) !=
207 (desc2->dst_ip[0] & mask->ipv4_mask.dst_ip)))
213 for (i = 0; i != RTE_DIM(desc1->src_ip); ++i)
214 if (((desc1->src_ip[i] & mask->ipv6_mask.src_ip[i]) !=
215 (desc2->src_ip[i] & mask->ipv6_mask.src_ip[i])) ||
216 ((desc1->dst_ip[i] & mask->ipv6_mask.dst_ip[i]) !=
217 (desc2->dst_ip[i] & mask->ipv6_mask.dst_ip[i])))
227 * Create flow director steering rule for a specific filter.
231 * @param mlx5_fdir_filter
232 * Filter to create a steering rule for.
234 * Flow director queue for matching packets.
237 * 0 on success, errno value on failure.
240 priv_fdir_flow_add(struct priv *priv,
241 struct mlx5_fdir_filter *mlx5_fdir_filter,
242 struct fdir_queue *fdir_queue)
244 struct ibv_exp_flow *flow;
245 struct fdir_flow_desc *desc = &mlx5_fdir_filter->desc;
246 enum rte_fdir_mode fdir_mode =
247 priv->dev->data->dev_conf.fdir_conf.mode;
248 struct rte_eth_fdir_masks *mask =
249 &priv->dev->data->dev_conf.fdir_conf.mask;
250 FLOW_ATTR_SPEC_ETH(data, priv_flow_attr(priv, NULL, 0, desc->type));
251 struct ibv_exp_flow_attr *attr = &data->attr;
252 uintptr_t spec_offset = (uintptr_t)&data->spec;
253 struct ibv_exp_flow_spec_eth *spec_eth;
254 struct ibv_exp_flow_spec_ipv4 *spec_ipv4;
255 struct ibv_exp_flow_spec_ipv6 *spec_ipv6;
256 struct ibv_exp_flow_spec_tcp_udp *spec_tcp_udp;
257 struct mlx5_fdir_filter *iter_fdir_filter;
260 /* Abort if an existing flow overlaps this one to avoid packet
261 * duplication, even if it targets another queue. */
262 LIST_FOREACH(iter_fdir_filter, priv->fdir_filter_list, next)
263 if ((iter_fdir_filter != mlx5_fdir_filter) &&
264 (iter_fdir_filter->flow != NULL) &&
265 (priv_fdir_overlap(priv,
266 &mlx5_fdir_filter->desc,
267 &iter_fdir_filter->desc)))
271 * No padding must be inserted by the compiler between attr and spec.
272 * This layout is expected by libibverbs.
274 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec_offset);
275 priv_flow_attr(priv, attr, sizeof(data), desc->type);
277 /* Set Ethernet spec */
278 spec_eth = (struct ibv_exp_flow_spec_eth *)spec_offset;
280 /* The first specification must be Ethernet. */
281 assert(spec_eth->type == IBV_EXP_FLOW_SPEC_ETH);
282 assert(spec_eth->size == sizeof(*spec_eth));
285 spec_eth->val.vlan_tag = desc->vlan_tag & mask->vlan_tci_mask;
286 spec_eth->mask.vlan_tag = mask->vlan_tci_mask;
288 /* Update priority */
291 if (fdir_mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
293 for (i = 0; i != RTE_DIM(spec_eth->mask.dst_mac); ++i) {
294 spec_eth->val.dst_mac[i] =
295 desc->mac[i] & mask->mac_addr_byte_mask;
296 spec_eth->mask.dst_mac[i] = mask->mac_addr_byte_mask;
301 switch (desc->type) {
305 spec_offset += spec_eth->size;
308 spec_ipv4 = (struct ibv_exp_flow_spec_ipv4 *)spec_offset;
310 /* The second specification must be IP. */
311 assert(spec_ipv4->type == IBV_EXP_FLOW_SPEC_IPV4);
312 assert(spec_ipv4->size == sizeof(*spec_ipv4));
314 spec_ipv4->val.src_ip =
315 desc->src_ip[0] & mask->ipv4_mask.src_ip;
316 spec_ipv4->val.dst_ip =
317 desc->dst_ip[0] & mask->ipv4_mask.dst_ip;
318 spec_ipv4->mask.src_ip = mask->ipv4_mask.src_ip;
319 spec_ipv4->mask.dst_ip = mask->ipv4_mask.dst_ip;
321 /* Update priority */
324 if (desc->type == HASH_RXQ_IPV4)
327 spec_offset += spec_ipv4->size;
332 spec_offset += spec_eth->size;
335 spec_ipv6 = (struct ibv_exp_flow_spec_ipv6 *)spec_offset;
337 /* The second specification must be IP. */
338 assert(spec_ipv6->type == IBV_EXP_FLOW_SPEC_IPV6);
339 assert(spec_ipv6->size == sizeof(*spec_ipv6));
341 for (i = 0; i != RTE_DIM(desc->src_ip); ++i) {
342 ((uint32_t *)spec_ipv6->val.src_ip)[i] =
343 desc->src_ip[i] & mask->ipv6_mask.src_ip[i];
344 ((uint32_t *)spec_ipv6->val.dst_ip)[i] =
345 desc->dst_ip[i] & mask->ipv6_mask.dst_ip[i];
347 rte_memcpy(spec_ipv6->mask.src_ip,
348 mask->ipv6_mask.src_ip,
349 sizeof(spec_ipv6->mask.src_ip));
350 rte_memcpy(spec_ipv6->mask.dst_ip,
351 mask->ipv6_mask.dst_ip,
352 sizeof(spec_ipv6->mask.dst_ip));
354 /* Update priority */
357 if (desc->type == HASH_RXQ_IPV6)
360 spec_offset += spec_ipv6->size;
363 ERROR("invalid flow attribute type");
367 /* Set TCP/UDP flow specification. */
368 spec_tcp_udp = (struct ibv_exp_flow_spec_tcp_udp *)spec_offset;
370 /* The third specification must be TCP/UDP. */
371 assert(spec_tcp_udp->type == IBV_EXP_FLOW_SPEC_TCP ||
372 spec_tcp_udp->type == IBV_EXP_FLOW_SPEC_UDP);
373 assert(spec_tcp_udp->size == sizeof(*spec_tcp_udp));
375 spec_tcp_udp->val.src_port = desc->src_port & mask->src_port_mask;
376 spec_tcp_udp->val.dst_port = desc->dst_port & mask->dst_port_mask;
377 spec_tcp_udp->mask.src_port = mask->src_port_mask;
378 spec_tcp_udp->mask.dst_port = mask->dst_port_mask;
380 /* Update priority */
386 flow = ibv_exp_create_flow(fdir_queue->qp, attr);
388 /* It's not clear whether errno is always set in this case. */
389 ERROR("%p: flow director configuration failed, errno=%d: %s",
391 (errno ? strerror(errno) : "Unknown error"));
397 DEBUG("%p: added flow director rule (%p)", (void *)priv, (void *)flow);
398 mlx5_fdir_filter->flow = flow;
403 * Get flow director queue for a specific RX queue, create it in case
412 * Related flow director queue on success, NULL otherwise.
414 static struct fdir_queue *
415 priv_get_fdir_queue(struct priv *priv, uint16_t idx)
417 struct rxq_ctrl *rxq_ctrl =
418 container_of((*priv->rxqs)[idx], struct rxq_ctrl, rxq);
419 struct fdir_queue *fdir_queue = &rxq_ctrl->fdir_queue;
420 struct ibv_exp_rwq_ind_table *ind_table = NULL;
421 struct ibv_qp *qp = NULL;
422 struct ibv_exp_rwq_ind_table_init_attr ind_init_attr;
423 struct ibv_exp_rx_hash_conf hash_conf;
424 struct ibv_exp_qp_init_attr qp_init_attr;
427 /* Return immediately if it has already been created. */
428 if (fdir_queue->qp != NULL)
431 ind_init_attr = (struct ibv_exp_rwq_ind_table_init_attr){
433 .log_ind_tbl_size = 0,
434 .ind_tbl = &((*priv->rxqs)[idx]->wq),
439 ind_table = ibv_exp_create_rwq_ind_table(priv->ctx,
441 if (ind_table == NULL) {
442 /* Not clear whether errno is set. */
443 err = (errno ? errno : EINVAL);
444 ERROR("RX indirection table creation failed with error %d: %s",
449 /* Create fdir_queue qp. */
450 hash_conf = (struct ibv_exp_rx_hash_conf){
451 .rx_hash_function = IBV_EXP_RX_HASH_FUNC_TOEPLITZ,
452 .rx_hash_key_len = rss_hash_default_key_len,
453 .rx_hash_key = rss_hash_default_key,
454 .rx_hash_fields_mask = 0,
455 .rwq_ind_tbl = ind_table,
457 qp_init_attr = (struct ibv_exp_qp_init_attr){
458 .max_inl_recv = 0, /* Currently not supported. */
459 .qp_type = IBV_QPT_RAW_PACKET,
460 .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD |
461 IBV_EXP_QP_INIT_ATTR_RX_HASH),
463 .rx_hash_conf = &hash_conf,
464 .port_num = priv->port,
467 qp = ibv_exp_create_qp(priv->ctx, &qp_init_attr);
469 err = (errno ? errno : EINVAL);
470 ERROR("hash RX QP creation failure: %s", strerror(err));
474 fdir_queue->ind_table = ind_table;
481 claim_zero(ibv_destroy_qp(qp));
483 if (ind_table != NULL)
484 claim_zero(ibv_exp_destroy_rwq_ind_table(ind_table));
490 * Enable flow director filter and create steering rules.
494 * @param mlx5_fdir_filter
495 * Filter to create steering rule for.
498 * 0 on success, errno value on failure.
501 priv_fdir_filter_enable(struct priv *priv,
502 struct mlx5_fdir_filter *mlx5_fdir_filter)
504 struct fdir_queue *fdir_queue;
506 /* Check if flow already exists. */
507 if (mlx5_fdir_filter->flow != NULL)
510 /* Get fdir_queue for specific queue. */
511 fdir_queue = priv_get_fdir_queue(priv, mlx5_fdir_filter->queue);
513 if (fdir_queue == NULL) {
514 ERROR("failed to create flow director rxq for queue %d",
515 mlx5_fdir_filter->queue);
520 return priv_fdir_flow_add(priv, mlx5_fdir_filter, fdir_queue);
524 * Initialize flow director filters list.
530 * 0 on success, errno value on failure.
533 fdir_init_filters_list(struct priv *priv)
535 /* Filter list initialization should be done only once. */
536 if (priv->fdir_filter_list)
539 /* Create filters list. */
540 priv->fdir_filter_list =
541 rte_calloc(__func__, 1, sizeof(*priv->fdir_filter_list), 0);
543 if (priv->fdir_filter_list == NULL) {
546 ERROR("cannot allocate flow director filter list: %s",
551 LIST_INIT(priv->fdir_filter_list);
563 priv_fdir_filter_flush(struct priv *priv)
565 struct mlx5_fdir_filter *mlx5_fdir_filter;
567 while ((mlx5_fdir_filter = LIST_FIRST(priv->fdir_filter_list))) {
568 struct ibv_exp_flow *flow = mlx5_fdir_filter->flow;
570 DEBUG("%p: flushing flow director filter %p",
571 (void *)priv, (void *)mlx5_fdir_filter);
572 LIST_REMOVE(mlx5_fdir_filter, next);
574 claim_zero(ibv_exp_destroy_flow(flow));
575 rte_free(mlx5_fdir_filter);
580 * Remove all flow director filters and delete list.
586 priv_fdir_delete_filters_list(struct priv *priv)
588 priv_fdir_filter_flush(priv);
589 rte_free(priv->fdir_filter_list);
590 priv->fdir_filter_list = NULL;
594 * Disable flow director, remove all steering rules.
600 priv_fdir_disable(struct priv *priv)
603 struct mlx5_fdir_filter *mlx5_fdir_filter;
604 struct fdir_queue *fdir_queue;
606 /* Run on every flow director filter and destroy flow handle. */
607 LIST_FOREACH(mlx5_fdir_filter, priv->fdir_filter_list, next) {
608 struct ibv_exp_flow *flow;
610 /* Only valid elements should be in the list */
611 assert(mlx5_fdir_filter != NULL);
612 flow = mlx5_fdir_filter->flow;
614 /* Destroy flow handle */
616 claim_zero(ibv_exp_destroy_flow(flow));
617 mlx5_fdir_filter->flow = NULL;
621 /* Run on every RX queue to destroy related flow director QP and
622 * indirection table. */
623 for (i = 0; (i != priv->rxqs_n); i++) {
624 struct rxq_ctrl *rxq_ctrl =
625 container_of((*priv->rxqs)[i], struct rxq_ctrl, rxq);
627 fdir_queue = &rxq_ctrl->fdir_queue;
628 if (fdir_queue->qp != NULL) {
629 claim_zero(ibv_destroy_qp(fdir_queue->qp));
630 fdir_queue->qp = NULL;
633 if (fdir_queue->ind_table != NULL) {
634 claim_zero(ibv_exp_destroy_rwq_ind_table
635 (fdir_queue->ind_table));
636 fdir_queue->ind_table = NULL;
642 * Enable flow director, create steering rules.
648 priv_fdir_enable(struct priv *priv)
650 struct mlx5_fdir_filter *mlx5_fdir_filter;
652 /* Run on every fdir filter and create flow handle */
653 LIST_FOREACH(mlx5_fdir_filter, priv->fdir_filter_list, next) {
654 /* Only valid elements should be in the list */
655 assert(mlx5_fdir_filter != NULL);
657 priv_fdir_filter_enable(priv, mlx5_fdir_filter);
662 * Find specific filter in list.
667 * Flow director filter to find.
670 * Filter element if found, otherwise NULL.
672 static struct mlx5_fdir_filter *
673 priv_find_filter_in_list(struct priv *priv,
674 const struct rte_eth_fdir_filter *fdir_filter)
676 struct fdir_flow_desc desc;
677 struct mlx5_fdir_filter *mlx5_fdir_filter;
678 enum rte_fdir_mode fdir_mode = priv->dev->data->dev_conf.fdir_conf.mode;
680 /* Get flow director filter to look for. */
681 fdir_filter_to_flow_desc(fdir_filter, &desc, fdir_mode);
683 /* Look for the requested element. */
684 LIST_FOREACH(mlx5_fdir_filter, priv->fdir_filter_list, next) {
685 /* Only valid elements should be in the list. */
686 assert(mlx5_fdir_filter != NULL);
688 /* Return matching filter. */
689 if (!memcmp(&desc, &mlx5_fdir_filter->desc, sizeof(desc)))
690 return mlx5_fdir_filter;
693 /* Filter not found */
698 * Add new flow director filter and store it in list.
703 * Flow director filter to add.
706 * 0 on success, errno value on failure.
709 priv_fdir_filter_add(struct priv *priv,
710 const struct rte_eth_fdir_filter *fdir_filter)
712 struct mlx5_fdir_filter *mlx5_fdir_filter;
713 enum rte_fdir_mode fdir_mode = priv->dev->data->dev_conf.fdir_conf.mode;
716 /* Validate queue number. */
717 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
718 ERROR("invalid queue number %d", fdir_filter->action.rx_queue);
722 /* Duplicate filters are currently unsupported. */
723 mlx5_fdir_filter = priv_find_filter_in_list(priv, fdir_filter);
724 if (mlx5_fdir_filter != NULL) {
725 ERROR("filter already exists");
729 /* Create new flow director filter. */
731 rte_calloc(__func__, 1, sizeof(*mlx5_fdir_filter), 0);
732 if (mlx5_fdir_filter == NULL) {
734 ERROR("cannot allocate flow director filter: %s",
740 mlx5_fdir_filter->queue = fdir_filter->action.rx_queue;
742 /* Convert to mlx5 filter descriptor. */
743 fdir_filter_to_flow_desc(fdir_filter,
744 &mlx5_fdir_filter->desc, fdir_mode);
746 /* Insert new filter into list. */
747 LIST_INSERT_HEAD(priv->fdir_filter_list, mlx5_fdir_filter, next);
749 DEBUG("%p: flow director filter %p added",
750 (void *)priv, (void *)mlx5_fdir_filter);
752 /* Enable filter immediately if device is started. */
754 err = priv_fdir_filter_enable(priv, mlx5_fdir_filter);
760 * Update queue for specific filter.
765 * Filter to be updated.
768 * 0 on success, errno value on failure.
771 priv_fdir_filter_update(struct priv *priv,
772 const struct rte_eth_fdir_filter *fdir_filter)
774 struct mlx5_fdir_filter *mlx5_fdir_filter;
776 /* Validate queue number. */
777 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
778 ERROR("invalid queue number %d", fdir_filter->action.rx_queue);
782 mlx5_fdir_filter = priv_find_filter_in_list(priv, fdir_filter);
783 if (mlx5_fdir_filter != NULL) {
784 struct ibv_exp_flow *flow = mlx5_fdir_filter->flow;
787 /* Update queue number. */
788 mlx5_fdir_filter->queue = fdir_filter->action.rx_queue;
790 /* Destroy flow handle. */
792 claim_zero(ibv_exp_destroy_flow(flow));
793 mlx5_fdir_filter->flow = NULL;
795 DEBUG("%p: flow director filter %p updated",
796 (void *)priv, (void *)mlx5_fdir_filter);
798 /* Enable filter if device is started. */
800 err = priv_fdir_filter_enable(priv, mlx5_fdir_filter);
805 /* Filter not found, create it. */
806 DEBUG("%p: filter not found for update, creating new filter",
808 return priv_fdir_filter_add(priv, fdir_filter);
812 * Delete specific filter.
817 * Filter to be deleted.
820 * 0 on success, errno value on failure.
823 priv_fdir_filter_delete(struct priv *priv,
824 const struct rte_eth_fdir_filter *fdir_filter)
826 struct mlx5_fdir_filter *mlx5_fdir_filter;
828 mlx5_fdir_filter = priv_find_filter_in_list(priv, fdir_filter);
829 if (mlx5_fdir_filter != NULL) {
830 struct ibv_exp_flow *flow = mlx5_fdir_filter->flow;
832 /* Remove element from list. */
833 LIST_REMOVE(mlx5_fdir_filter, next);
835 /* Destroy flow handle. */
837 claim_zero(ibv_exp_destroy_flow(flow));
838 mlx5_fdir_filter->flow = NULL;
841 DEBUG("%p: flow director filter %p deleted",
842 (void *)priv, (void *)mlx5_fdir_filter);
845 rte_free(mlx5_fdir_filter);
850 ERROR("%p: flow director delete failed, cannot find filter",
856 * Get flow director information.
860 * @param[out] fdir_info
861 * Resulting flow director information.
864 priv_fdir_info_get(struct priv *priv, struct rte_eth_fdir_info *fdir_info)
866 struct rte_eth_fdir_masks *mask =
867 &priv->dev->data->dev_conf.fdir_conf.mask;
869 fdir_info->mode = priv->dev->data->dev_conf.fdir_conf.mode;
870 fdir_info->guarant_spc = 0;
872 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
874 fdir_info->max_flexpayload = 0;
875 fdir_info->flow_types_mask[0] = 0;
877 fdir_info->flex_payload_unit = 0;
878 fdir_info->max_flex_payload_segment_num = 0;
879 fdir_info->flex_payload_limit = 0;
880 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
884 * Deal with flow director operations.
887 * Pointer to private structure.
889 * Operation to perform.
891 * Pointer to operation-specific structure.
894 * 0 on success, errno value on failure.
897 priv_fdir_ctrl_func(struct priv *priv, enum rte_filter_op filter_op, void *arg)
899 enum rte_fdir_mode fdir_mode =
900 priv->dev->data->dev_conf.fdir_conf.mode;
903 if (filter_op == RTE_ETH_FILTER_NOP)
906 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
907 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
908 ERROR("%p: flow director mode %d not supported",
909 (void *)priv, fdir_mode);
914 case RTE_ETH_FILTER_ADD:
915 ret = priv_fdir_filter_add(priv, arg);
917 case RTE_ETH_FILTER_UPDATE:
918 ret = priv_fdir_filter_update(priv, arg);
920 case RTE_ETH_FILTER_DELETE:
921 ret = priv_fdir_filter_delete(priv, arg);
923 case RTE_ETH_FILTER_FLUSH:
924 priv_fdir_filter_flush(priv);
926 case RTE_ETH_FILTER_INFO:
927 priv_fdir_info_get(priv, arg);
930 DEBUG("%p: unknown operation %u", (void *)priv, filter_op);
938 * Manage filter operations.
941 * Pointer to Ethernet device structure.
945 * Operation to perform.
947 * Pointer to operation-specific structure.
950 * 0 on success, negative errno value on failure.
953 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
954 enum rte_filter_type filter_type,
955 enum rte_filter_op filter_op,
959 struct priv *priv = dev->data->dev_private;
961 switch (filter_type) {
962 case RTE_ETH_FILTER_FDIR:
964 ret = priv_fdir_ctrl_func(priv, filter_op, arg);
968 ERROR("%p: filter type (%d) not supported",
969 (void *)dev, filter_type);