net/avp: remove resources when port is closed
[dpdk.git] / drivers / net / nfb / nfb_rxmode.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Cesnet
3  * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
4  * All rights reserved.
5  */
6
7 #include "nfb_rxmode.h"
8 #include "nfb.h"
9
10 void
11 nfb_eth_promiscuous_enable(struct rte_eth_dev *dev)
12 {
13         struct pmd_internals *internals = (struct pmd_internals *)
14                 dev->data->dev_private;
15         uint16_t i;
16
17         internals->rx_filter_original = RXMAC_MAC_FILTER_PROMISCUOUS;
18
19         for (i = 0; i < internals->max_rxmac; ++i) {
20                 nc_rxmac_mac_filter_enable(internals->rxmac[i],
21                         RXMAC_MAC_FILTER_PROMISCUOUS);
22         }
23 }
24
25 void
26 nfb_eth_promiscuous_disable(struct rte_eth_dev *dev)
27 {
28         struct pmd_internals *internals = (struct pmd_internals *)
29                 dev->data->dev_private;
30         uint16_t i;
31
32         internals->rx_filter_original = RXMAC_MAC_FILTER_TABLE;
33
34         /* if promisc is not enabled, do nothing */
35         if (!nfb_eth_promiscuous_get(dev))
36                 return;
37
38         for (i = 0; i < internals->max_rxmac; ++i) {
39                 nc_rxmac_mac_filter_enable(internals->rxmac[i],
40                         RXMAC_MAC_FILTER_TABLE);
41         }
42 }
43
44 int
45 nfb_eth_promiscuous_get(struct rte_eth_dev *dev)
46 {
47         struct pmd_internals *internals = (struct pmd_internals *)
48                 dev->data->dev_private;
49
50         struct nc_rxmac_status status;
51         status.mac_filter = RXMAC_MAC_FILTER_PROMISCUOUS;
52
53         nc_rxmac_read_status(internals->rxmac[0], &status);
54
55         return (status.mac_filter == RXMAC_MAC_FILTER_PROMISCUOUS);
56 }
57
58 void
59 nfb_eth_allmulticast_enable(struct rte_eth_dev *dev)
60 {
61         struct pmd_internals *internals = (struct pmd_internals *)
62                 dev->data->dev_private;
63
64         uint16_t i;
65         for (i = 0; i < internals->max_rxmac; ++i) {
66                 nc_rxmac_mac_filter_enable(internals->rxmac[i],
67                         RXMAC_MAC_FILTER_TABLE_BCAST_MCAST);
68         }
69 }
70
71 void
72 nfb_eth_allmulticast_disable(struct rte_eth_dev *dev)
73 {
74         struct pmd_internals *internals = (struct pmd_internals *)
75                 dev->data->dev_private;
76
77         uint16_t i;
78
79         /* if multicast is not enabled do nothing */
80         if (!nfb_eth_allmulticast_get(dev))
81                 return;
82
83         for (i = 0; i < internals->max_rxmac; ++i) {
84                 nc_rxmac_mac_filter_enable(internals->rxmac[i],
85                         internals->rx_filter_original);
86         }
87 }
88
89 int
90 nfb_eth_allmulticast_get(struct rte_eth_dev *dev)
91 {
92         struct pmd_internals *internals = (struct pmd_internals *)
93                 dev->data->dev_private;
94
95         struct nc_rxmac_status status;
96         status.mac_filter = RXMAC_MAC_FILTER_PROMISCUOUS;
97         nc_rxmac_read_status(internals->rxmac[0], &status);
98
99         return (status.mac_filter == RXMAC_MAC_FILTER_TABLE_BCAST_MCAST);
100 }