1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
3 */
4
5 #include <rte_common.h>
6
7 #include "otx2_dev.h"
8 #include "otx2_ethdev.h"
9
10 int
otx2_cgx_mac_addr_set(struct rte_eth_dev * eth_dev,struct rte_ether_addr * addr)11 otx2_cgx_mac_addr_set(struct rte_eth_dev *eth_dev, struct rte_ether_addr *addr)
12 {
13 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
14 struct cgx_mac_addr_set_or_get *req;
15 struct otx2_mbox *mbox = dev->mbox;
16 int rc;
17
18 if (otx2_dev_is_vf_or_sdp(dev))
19 return -ENOTSUP;
20
21 if (otx2_dev_active_vfs(dev))
22 return -ENOTSUP;
23
24 req = otx2_mbox_alloc_msg_cgx_mac_addr_set(mbox);
25 otx2_mbox_memcpy(req->mac_addr, addr->addr_bytes, RTE_ETHER_ADDR_LEN);
26
27 rc = otx2_mbox_process(mbox);
28 if (rc)
29 otx2_err("Failed to set mac address in CGX, rc=%d", rc);
30
31 return 0;
32 }
33
34 int
otx2_cgx_mac_max_entries_get(struct otx2_eth_dev * dev)35 otx2_cgx_mac_max_entries_get(struct otx2_eth_dev *dev)
36 {
37 struct cgx_max_dmac_entries_get_rsp *rsp;
38 struct otx2_mbox *mbox = dev->mbox;
39 int rc;
40
41 if (otx2_dev_is_vf_or_sdp(dev))
42 return 0;
43
44 otx2_mbox_alloc_msg_cgx_mac_max_entries_get(mbox);
45 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
46 if (rc)
47 return rc;
48
49 return rsp->max_dmac_filters;
50 }
51
52 int
otx2_nix_mac_addr_add(struct rte_eth_dev * eth_dev,struct rte_ether_addr * addr,uint32_t index __rte_unused,uint32_t pool __rte_unused)53 otx2_nix_mac_addr_add(struct rte_eth_dev *eth_dev, struct rte_ether_addr *addr,
54 uint32_t index __rte_unused, uint32_t pool __rte_unused)
55 {
56 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
57 struct otx2_mbox *mbox = dev->mbox;
58 struct cgx_mac_addr_add_req *req;
59 struct cgx_mac_addr_add_rsp *rsp;
60 int rc;
61
62 if (otx2_dev_is_vf_or_sdp(dev))
63 return -ENOTSUP;
64
65 if (otx2_dev_active_vfs(dev))
66 return -ENOTSUP;
67
68 req = otx2_mbox_alloc_msg_cgx_mac_addr_add(mbox);
69 otx2_mbox_memcpy(req->mac_addr, addr->addr_bytes, RTE_ETHER_ADDR_LEN);
70
71 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
72 if (rc) {
73 otx2_err("Failed to add mac address, rc=%d", rc);
74 goto done;
75 }
76
77 /* Enable promiscuous mode at NIX level */
78 otx2_nix_promisc_config(eth_dev, 1);
79 dev->dmac_filter_enable = true;
80 eth_dev->data->promiscuous = 0;
81
82 done:
83 return rc;
84 }
85
86 void
otx2_nix_mac_addr_del(struct rte_eth_dev * eth_dev,uint32_t index)87 otx2_nix_mac_addr_del(struct rte_eth_dev *eth_dev, uint32_t index)
88 {
89 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
90 struct otx2_mbox *mbox = dev->mbox;
91 struct cgx_mac_addr_del_req *req;
92 int rc;
93
94 if (otx2_dev_is_vf_or_sdp(dev))
95 return;
96
97 req = otx2_mbox_alloc_msg_cgx_mac_addr_del(mbox);
98 req->index = index;
99
100 rc = otx2_mbox_process(mbox);
101 if (rc)
102 otx2_err("Failed to delete mac address, rc=%d", rc);
103 }
104
105 int
otx2_nix_mac_addr_set(struct rte_eth_dev * eth_dev,struct rte_ether_addr * addr)106 otx2_nix_mac_addr_set(struct rte_eth_dev *eth_dev, struct rte_ether_addr *addr)
107 {
108 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
109 struct otx2_mbox *mbox = dev->mbox;
110 struct nix_set_mac_addr *req;
111 int rc;
112
113 req = otx2_mbox_alloc_msg_nix_set_mac_addr(mbox);
114 otx2_mbox_memcpy(req->mac_addr, addr->addr_bytes, RTE_ETHER_ADDR_LEN);
115
116 rc = otx2_mbox_process(mbox);
117 if (rc) {
118 otx2_err("Failed to set mac address, rc=%d", rc);
119 goto done;
120 }
121
122 otx2_mbox_memcpy(dev->mac_addr, addr->addr_bytes, RTE_ETHER_ADDR_LEN);
123
124 /* Install the same entry into CGX DMAC filter table too. */
125 otx2_cgx_mac_addr_set(eth_dev, addr);
126
127 done:
128 return rc;
129 }
130
131 int
otx2_nix_mac_addr_get(struct rte_eth_dev * eth_dev,uint8_t * addr)132 otx2_nix_mac_addr_get(struct rte_eth_dev *eth_dev, uint8_t *addr)
133 {
134 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
135 struct otx2_mbox *mbox = dev->mbox;
136 struct nix_get_mac_addr_rsp *rsp;
137 int rc;
138
139 otx2_mbox_alloc_msg_nix_get_mac_addr(mbox);
140 otx2_mbox_msg_send(mbox, 0);
141 rc = otx2_mbox_get_rsp(mbox, 0, (void *)&rsp);
142 if (rc) {
143 otx2_err("Failed to get mac address, rc=%d", rc);
144 goto done;
145 }
146
147 otx2_mbox_memcpy(addr, rsp->mac_addr, RTE_ETHER_ADDR_LEN);
148
149 done:
150 return rc;
151 }
152