1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
8 static inline struct mbox *
9 nix_to_mbox(struct nix *nix)
11 struct dev *dev = &nix->dev;
17 roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start)
19 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
20 struct mbox *mbox = nix_to_mbox(nix);
22 if (roc_nix_is_vf_or_sdp(roc_nix))
23 return NIX_ERR_OP_NOTSUP;
26 mbox_alloc_msg_cgx_start_rxtx(mbox);
28 mbox_alloc_msg_cgx_stop_rxtx(mbox);
30 return mbox_process(mbox);
34 roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix, bool start)
36 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
37 struct mbox *mbox = nix_to_mbox(nix);
39 if (roc_nix_is_vf_or_sdp(roc_nix))
40 return NIX_ERR_OP_NOTSUP;
43 mbox_alloc_msg_cgx_start_linkevents(mbox);
45 mbox_alloc_msg_cgx_stop_linkevents(mbox);
47 return mbox_process(mbox);
51 roc_nix_mac_loopback_enable(struct roc_nix *roc_nix, bool enable)
53 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
54 struct mbox *mbox = nix_to_mbox(nix);
56 if (enable && roc_nix_is_vf_or_sdp(roc_nix))
57 return NIX_ERR_OP_NOTSUP;
60 mbox_alloc_msg_cgx_intlbk_enable(mbox);
62 mbox_alloc_msg_cgx_intlbk_disable(mbox);
64 return mbox_process(mbox);
68 roc_nix_mac_addr_set(struct roc_nix *roc_nix, const uint8_t addr[])
70 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
71 struct mbox *mbox = nix_to_mbox(nix);
72 struct cgx_mac_addr_set_or_get *req;
74 if (roc_nix_is_vf_or_sdp(roc_nix))
75 return NIX_ERR_OP_NOTSUP;
77 if (dev_active_vfs(&nix->dev))
78 return NIX_ERR_OP_NOTSUP;
80 req = mbox_alloc_msg_cgx_mac_addr_set(mbox);
81 mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN);
83 return mbox_process(mbox);
87 roc_nix_mac_max_entries_get(struct roc_nix *roc_nix)
89 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
90 struct cgx_max_dmac_entries_get_rsp *rsp;
91 struct mbox *mbox = nix_to_mbox(nix);
94 if (roc_nix_is_vf_or_sdp(roc_nix))
95 return NIX_ERR_OP_NOTSUP;
97 mbox_alloc_msg_cgx_mac_max_entries_get(mbox);
98 rc = mbox_process_msg(mbox, (void *)&rsp);
102 return rsp->max_dmac_filters ? rsp->max_dmac_filters : 1;
106 roc_nix_mac_addr_add(struct roc_nix *roc_nix, uint8_t addr[])
108 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
109 struct mbox *mbox = nix_to_mbox(nix);
110 struct cgx_mac_addr_add_req *req;
111 struct cgx_mac_addr_add_rsp *rsp;
114 if (roc_nix_is_vf_or_sdp(roc_nix))
115 return NIX_ERR_OP_NOTSUP;
117 if (dev_active_vfs(&nix->dev))
118 return NIX_ERR_OP_NOTSUP;
120 req = mbox_alloc_msg_cgx_mac_addr_add(mbox);
121 mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN);
123 rc = mbox_process_msg(mbox, (void *)&rsp);
131 roc_nix_mac_addr_del(struct roc_nix *roc_nix, uint32_t index)
133 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
134 struct mbox *mbox = nix_to_mbox(nix);
135 struct cgx_mac_addr_del_req *req;
138 if (roc_nix_is_vf_or_sdp(roc_nix))
139 return NIX_ERR_OP_NOTSUP;
141 req = mbox_alloc_msg_cgx_mac_addr_del(mbox);
146 return mbox_process(mbox);
150 roc_nix_mac_promisc_mode_enable(struct roc_nix *roc_nix, int enable)
152 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
153 struct mbox *mbox = nix_to_mbox(nix);
155 if (roc_nix_is_vf_or_sdp(roc_nix))
156 return NIX_ERR_OP_NOTSUP;
159 mbox_alloc_msg_cgx_promisc_enable(mbox);
161 mbox_alloc_msg_cgx_promisc_disable(mbox);
163 return mbox_process(mbox);
167 roc_nix_mac_link_info_get(struct roc_nix *roc_nix,
168 struct roc_nix_link_info *link_info)
170 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
171 struct mbox *mbox = nix_to_mbox(nix);
172 struct cgx_link_info_msg *rsp;
175 mbox_alloc_msg_cgx_get_linkinfo(mbox);
176 rc = mbox_process_msg(mbox, (void *)&rsp);
180 link_info->status = rsp->link_info.link_up;
181 link_info->full_duplex = rsp->link_info.full_duplex;
182 link_info->lmac_type_id = rsp->link_info.lmac_type_id;
183 link_info->speed = rsp->link_info.speed;
184 link_info->autoneg = rsp->link_info.an;
185 link_info->fec = rsp->link_info.fec;
186 link_info->port = rsp->link_info.port;
192 roc_nix_mac_link_state_set(struct roc_nix *roc_nix, uint8_t up)
194 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
195 struct mbox *mbox = nix_to_mbox(nix);
196 struct cgx_set_link_state_msg *req;
199 req = mbox_alloc_msg_cgx_set_link_state(mbox);
203 return mbox_process(mbox);
207 roc_nix_mac_link_info_set(struct roc_nix *roc_nix,
208 struct roc_nix_link_info *link_info)
210 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
211 struct mbox *mbox = nix_to_mbox(nix);
212 struct cgx_set_link_mode_req *req;
215 rc = roc_nix_mac_link_state_set(roc_nix, link_info->status);
219 req = mbox_alloc_msg_cgx_set_link_mode(mbox);
222 req->args.speed = link_info->speed;
223 req->args.duplex = link_info->full_duplex;
224 req->args.an = link_info->autoneg;
226 return mbox_process(mbox);
230 roc_nix_mac_mtu_set(struct roc_nix *roc_nix, uint16_t mtu)
232 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
233 struct mbox *mbox = nix_to_mbox(nix);
234 struct nix_frs_cfg *req;
235 bool sdp_link = false;
238 if (roc_nix_is_sdp(roc_nix))
241 req = mbox_alloc_msg_nix_set_hw_frs(mbox);
245 req->update_smq = true;
246 req->sdp_link = sdp_link;
248 rc = mbox_process(mbox);
252 /* Save MTU for later use */
258 roc_nix_mac_max_rx_len_set(struct roc_nix *roc_nix, uint16_t maxlen)
260 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
261 struct mbox *mbox = nix_to_mbox(nix);
262 struct nix_frs_cfg *req;
263 bool sdp_link = false;
266 if (roc_nix_is_sdp(roc_nix))
269 req = mbox_alloc_msg_nix_set_hw_frs(mbox);
272 req->sdp_link = sdp_link;
273 req->maxlen = maxlen;
275 return mbox_process(mbox);
279 roc_nix_mac_link_cb_register(struct roc_nix *roc_nix, link_status_t link_update)
281 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
282 struct dev *dev = &nix->dev;
284 if (link_update == NULL)
285 return NIX_ERR_PARAM;
287 dev->ops->link_status_update = (link_info_t)link_update;
292 roc_nix_mac_link_cb_unregister(struct roc_nix *roc_nix)
294 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
295 struct dev *dev = &nix->dev;
297 dev->ops->link_status_update = NULL;
301 roc_nix_mac_link_info_get_cb_register(struct roc_nix *roc_nix,
302 link_info_get_t link_info_get)
304 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
305 struct dev *dev = &nix->dev;
307 if (link_info_get == NULL)
308 return NIX_ERR_PARAM;
310 dev->ops->link_status_get = (link_info_t)link_info_get;
315 roc_nix_mac_link_info_get_cb_unregister(struct roc_nix *roc_nix)
317 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
318 struct dev *dev = &nix->dev;
320 dev->ops->link_status_get = NULL;