1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
8 static inline struct mbox *
9 get_mbox(struct roc_nix *roc_nix)
11 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
12 struct dev *dev = &nix->dev;
18 roc_nix_vlan_mcam_entry_read(struct roc_nix *roc_nix, uint32_t index,
19 struct npc_mcam_read_entry_rsp **rsp)
21 struct mbox *mbox = get_mbox(roc_nix);
22 struct npc_mcam_read_entry_req *req;
25 req = mbox_alloc_msg_npc_mcam_read_entry(mbox);
30 return mbox_process_msg(mbox, (void **)rsp);
34 roc_nix_vlan_mcam_entry_write(struct roc_nix *roc_nix, uint32_t index,
35 struct mcam_entry *entry, uint8_t intf,
38 struct mbox *mbox = get_mbox(roc_nix);
39 struct npc_mcam_write_entry_req *req;
43 req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
48 req->enable_entry = enable;
49 mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
51 return mbox_process_msg(mbox, (void *)&rsp);
55 roc_nix_vlan_mcam_entry_alloc_and_write(struct roc_nix *roc_nix,
56 struct mcam_entry *entry, uint8_t intf,
57 uint8_t priority, uint8_t ref_entry)
59 struct npc_mcam_alloc_and_write_entry_req *req;
60 struct npc_mcam_alloc_and_write_entry_rsp *rsp;
61 struct mbox *mbox = get_mbox(roc_nix);
64 req = mbox_alloc_msg_npc_mcam_alloc_and_write_entry(mbox);
67 req->priority = priority;
68 req->ref_entry = ref_entry;
70 req->enable_entry = true;
71 mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
73 rc = mbox_process_msg(mbox, (void *)&rsp);
81 roc_nix_vlan_mcam_entry_free(struct roc_nix *roc_nix, uint32_t index)
83 struct mbox *mbox = get_mbox(roc_nix);
84 struct npc_mcam_free_entry_req *req;
87 req = mbox_alloc_msg_npc_mcam_free_entry(mbox);
92 return mbox_process_msg(mbox, NULL);
96 roc_nix_vlan_mcam_entry_ena_dis(struct roc_nix *roc_nix, uint32_t index,
99 struct npc_mcam_ena_dis_entry_req *req;
100 struct mbox *mbox = get_mbox(roc_nix);
104 req = mbox_alloc_msg_npc_mcam_ena_entry(mbox);
108 req = mbox_alloc_msg_npc_mcam_dis_entry(mbox);
114 return mbox_process_msg(mbox, NULL);
118 roc_nix_vlan_strip_vtag_ena_dis(struct roc_nix *roc_nix, bool enable)
120 struct mbox *mbox = get_mbox(roc_nix);
121 struct nix_vtag_config *vtag_cfg;
124 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
125 if (vtag_cfg == NULL)
127 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
128 vtag_cfg->cfg_type = 1; /* Rx VLAN configuration */
129 vtag_cfg->rx.capture_vtag = 1; /* Always capture */
130 vtag_cfg->rx.vtag_type = 0; /* Use index 0 */
133 vtag_cfg->rx.strip_vtag = 1;
135 vtag_cfg->rx.strip_vtag = 0;
137 return mbox_process(mbox);
141 roc_nix_vlan_insert_ena_dis(struct roc_nix *roc_nix,
142 struct roc_nix_vlan_config *vlan_cfg,
143 uint64_t *mcam_index, bool enable)
145 struct mbox *mbox = get_mbox(roc_nix);
146 struct nix_vtag_config *vtag_cfg;
147 struct nix_vtag_config_rsp *rsp;
150 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
151 if (vtag_cfg == NULL)
153 vtag_cfg->cfg_type = 0; /* Tx VLAN configuration */
154 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
157 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
158 vtag_cfg->tx.vtag0 = vlan_cfg->vlan.vtag_inner;
159 vtag_cfg->tx.cfg_vtag0 = true;
161 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
162 vtag_cfg->tx.vtag1 = vlan_cfg->vlan.vtag_outer;
163 vtag_cfg->tx.cfg_vtag1 = true;
166 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
167 vtag_cfg->tx.vtag0_idx = vlan_cfg->mcam.idx_inner;
168 vtag_cfg->tx.free_vtag0 = true;
170 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
171 vtag_cfg->tx.vtag1_idx = vlan_cfg->mcam.idx_outer;
172 vtag_cfg->tx.free_vtag1 = true;
176 rc = mbox_process_msg(mbox, (void *)&rsp);
182 (((uint64_t)rsp->vtag1_idx << 32) | rsp->vtag0_idx);
188 roc_nix_vlan_tpid_set(struct roc_nix *roc_nix, uint32_t type, uint16_t tpid)
190 struct mbox *mbox = get_mbox(roc_nix);
191 struct nix_set_vlan_tpid *tpid_cfg;
194 tpid_cfg = mbox_alloc_msg_nix_set_vlan_tpid(mbox);
195 if (tpid_cfg == NULL)
197 tpid_cfg->tpid = tpid;
199 if (type & ROC_NIX_VLAN_TYPE_OUTER)
200 tpid_cfg->vlan_type = NIX_VLAN_TYPE_OUTER;
202 tpid_cfg->vlan_type = NIX_VLAN_TYPE_INNER;
204 return mbox_process(mbox);