1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell OcteonTx2 RVU Physcial Function ethernet driver
4 * Copyright (C) 2021 Marvell.
7 #include "otx2_common.h"
9 static int otx2_dmacflt_do_add(struct otx2_nic *pf, const u8 *mac,
12 struct cgx_mac_addr_add_req *req;
13 struct cgx_mac_addr_add_rsp *rsp;
16 mutex_lock(&pf->mbox.lock);
18 req = otx2_mbox_alloc_msg_cgx_mac_addr_add(&pf->mbox);
20 mutex_unlock(&pf->mbox.lock);
24 ether_addr_copy(req->mac_addr, mac);
25 err = otx2_sync_mbox_msg(&pf->mbox);
28 rsp = (struct cgx_mac_addr_add_rsp *)
29 otx2_mbox_get_rsp(&pf->mbox.mbox, 0, &req->hdr);
30 *dmac_index = rsp->index;
33 mutex_unlock(&pf->mbox.lock);
37 static int otx2_dmacflt_add_pfmac(struct otx2_nic *pf)
39 struct cgx_mac_addr_set_or_get *req;
42 mutex_lock(&pf->mbox.lock);
44 req = otx2_mbox_alloc_msg_cgx_mac_addr_set(&pf->mbox);
46 mutex_unlock(&pf->mbox.lock);
50 ether_addr_copy(req->mac_addr, pf->netdev->dev_addr);
51 err = otx2_sync_mbox_msg(&pf->mbox);
53 mutex_unlock(&pf->mbox.lock);
57 int otx2_dmacflt_add(struct otx2_nic *pf, const u8 *mac, u8 bit_pos)
61 /* Store dmacindex returned by CGX/RPM driver which will
62 * be used for macaddr update/remove
64 dmacindex = &pf->flow_cfg->bmap_to_dmacindex[bit_pos];
66 if (ether_addr_equal(mac, pf->netdev->dev_addr))
67 return otx2_dmacflt_add_pfmac(pf);
69 return otx2_dmacflt_do_add(pf, mac, dmacindex);
72 static int otx2_dmacflt_do_remove(struct otx2_nic *pfvf, const u8 *mac,
75 struct cgx_mac_addr_del_req *req;
78 mutex_lock(&pfvf->mbox.lock);
79 req = otx2_mbox_alloc_msg_cgx_mac_addr_del(&pfvf->mbox);
81 mutex_unlock(&pfvf->mbox.lock);
85 req->index = dmac_index;
87 err = otx2_sync_mbox_msg(&pfvf->mbox);
88 mutex_unlock(&pfvf->mbox.lock);
93 static int otx2_dmacflt_remove_pfmac(struct otx2_nic *pf)
98 mutex_lock(&pf->mbox.lock);
99 req = otx2_mbox_alloc_msg_cgx_mac_addr_reset(&pf->mbox);
101 mutex_unlock(&pf->mbox.lock);
105 err = otx2_sync_mbox_msg(&pf->mbox);
107 mutex_unlock(&pf->mbox.lock);
111 int otx2_dmacflt_remove(struct otx2_nic *pf, const u8 *mac,
114 u8 dmacindex = pf->flow_cfg->bmap_to_dmacindex[bit_pos];
116 if (ether_addr_equal(mac, pf->netdev->dev_addr))
117 return otx2_dmacflt_remove_pfmac(pf);
119 return otx2_dmacflt_do_remove(pf, mac, dmacindex);
122 /* CGX/RPM blocks support max unicast entries of 32.
123 * on typical configuration MAC block associated
124 * with 4 lmacs, each lmac will have 8 dmac entries
126 int otx2_dmacflt_get_max_cnt(struct otx2_nic *pf)
128 struct cgx_max_dmac_entries_get_rsp *rsp;
132 mutex_lock(&pf->mbox.lock);
133 msg = otx2_mbox_alloc_msg_cgx_mac_max_entries_get(&pf->mbox);
136 mutex_unlock(&pf->mbox.lock);
140 err = otx2_sync_mbox_msg(&pf->mbox);
144 rsp = (struct cgx_max_dmac_entries_get_rsp *)
145 otx2_mbox_get_rsp(&pf->mbox.mbox, 0, &msg->hdr);
146 pf->flow_cfg->dmacflt_max_flows = rsp->max_dmac_filters;
149 mutex_unlock(&pf->mbox.lock);
153 int otx2_dmacflt_update(struct otx2_nic *pf, u8 *mac, u8 bit_pos)
155 struct cgx_mac_addr_update_req *req;
158 mutex_lock(&pf->mbox.lock);
160 req = otx2_mbox_alloc_msg_cgx_mac_addr_update(&pf->mbox);
163 mutex_unlock(&pf->mbox.lock);
167 ether_addr_copy(req->mac_addr, mac);
168 req->index = pf->flow_cfg->bmap_to_dmacindex[bit_pos];
169 rc = otx2_sync_mbox_msg(&pf->mbox);
171 mutex_unlock(&pf->mbox.lock);