Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2021 Marvell. 3 : : */ 4 : : 5 : : #include "roc_api.h" 6 : : #include "roc_priv.h" 7 : : 8 : : int 9 : 0 : roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start) 10 : : { 11 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 12 : : struct dev *dev = &nix->dev; 13 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 14 : : int rc; 15 : : 16 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 17 : : rc = NIX_ERR_OP_NOTSUP; 18 : 0 : goto exit; 19 : : } 20 : : 21 [ # # ]: 0 : if (start) 22 : 0 : mbox_alloc_msg_cgx_start_rxtx(mbox); 23 : : else 24 : 0 : mbox_alloc_msg_cgx_stop_rxtx(mbox); 25 : : 26 : 0 : rc = mbox_process(mbox); 27 : 0 : exit: 28 : : mbox_put(mbox); 29 : 0 : return rc; 30 : : } 31 : : 32 : : int 33 : 0 : roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix, bool start) 34 : : { 35 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 36 : : struct dev *dev = &nix->dev; 37 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 38 : : int rc; 39 : : 40 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 41 : : rc = NIX_ERR_OP_NOTSUP; 42 : 0 : goto exit; 43 : : } 44 : : 45 [ # # ]: 0 : if (start) 46 : 0 : mbox_alloc_msg_cgx_start_linkevents(mbox); 47 : : else 48 : 0 : mbox_alloc_msg_cgx_stop_linkevents(mbox); 49 : : 50 : 0 : rc = mbox_process(mbox); 51 : 0 : exit: 52 : : mbox_put(mbox); 53 : 0 : return rc; 54 : : } 55 : : 56 : : int 57 : 0 : roc_nix_mac_loopback_enable(struct roc_nix *roc_nix, bool enable) 58 : : { 59 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 60 : : struct dev *dev = &nix->dev; 61 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 62 : : int rc; 63 : : 64 [ # # # # ]: 0 : if (enable && roc_nix_is_vf_or_sdp(roc_nix)) { 65 : : rc = NIX_ERR_OP_NOTSUP; 66 : 0 : goto exit; 67 : : } 68 : : 69 [ # # ]: 0 : if (enable) 70 : 0 : mbox_alloc_msg_cgx_intlbk_enable(mbox); 71 : : else 72 : 0 : mbox_alloc_msg_cgx_intlbk_disable(mbox); 73 : : 74 : 0 : rc = mbox_process(mbox); 75 : 0 : exit: 76 : : mbox_put(mbox); 77 : 0 : return rc; 78 : : } 79 : : 80 : : int 81 : 0 : roc_nix_mac_addr_set(struct roc_nix *roc_nix, const uint8_t addr[]) 82 : : { 83 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 84 : : struct cgx_mac_addr_set_or_get *req, *rsp; 85 : : struct dev *dev = &nix->dev; 86 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 87 : : int rc = -ENOSPC; 88 : : 89 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 90 : : rc = NIX_ERR_OP_NOTSUP; 91 : 0 : goto exit; 92 : : } 93 : : 94 : 0 : req = mbox_alloc_msg_cgx_mac_addr_set(mbox); 95 [ # # ]: 0 : if (req == NULL) 96 : 0 : goto exit; 97 : : 98 : 0 : req->index = nix->dmac_flt_idx; 99 [ # # ]: 0 : mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN); 100 : : 101 : : rc = mbox_process_msg(mbox, (void *)&rsp); 102 [ # # ]: 0 : if (rc) 103 : 0 : goto exit; 104 : 0 : nix->dmac_flt_idx = rsp->index; 105 : 0 : exit: 106 : : mbox_put(mbox); 107 : 0 : return rc; 108 : : } 109 : : 110 : : int 111 : 0 : roc_nix_mac_max_entries_get(struct roc_nix *roc_nix) 112 : : { 113 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 114 : : struct cgx_max_dmac_entries_get_rsp *rsp; 115 : : struct dev *dev = &nix->dev; 116 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 117 : : int rc; 118 : : 119 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 120 : : rc = NIX_ERR_OP_NOTSUP; 121 : 0 : goto exit; 122 : : } 123 : : 124 : 0 : mbox_alloc_msg_cgx_mac_max_entries_get(mbox); 125 : : rc = mbox_process_msg(mbox, (void *)&rsp); 126 [ # # ]: 0 : if (rc) 127 : 0 : goto exit; 128 : : 129 [ # # ]: 0 : rc = rsp->max_dmac_filters ? rsp->max_dmac_filters : 1; 130 : 0 : exit: 131 : : mbox_put(mbox); 132 : 0 : return rc; 133 : : } 134 : : 135 : : int 136 : 0 : roc_nix_mac_addr_add(struct roc_nix *roc_nix, uint8_t addr[]) 137 : : { 138 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 139 : : struct cgx_mac_addr_add_req *req; 140 : : struct cgx_mac_addr_add_rsp *rsp; 141 : : struct dev *dev = &nix->dev; 142 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 143 : : int rc; 144 : : 145 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 146 : : rc = NIX_ERR_OP_NOTSUP; 147 : 0 : goto exit; 148 : : } 149 : : 150 : 0 : req = mbox_alloc_msg_cgx_mac_addr_add(mbox); 151 [ # # ]: 0 : mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN); 152 : : 153 : : rc = mbox_process_msg(mbox, (void *)&rsp); 154 [ # # ]: 0 : if (rc < 0) 155 : 0 : goto exit; 156 : : 157 : 0 : rc = rsp->index; 158 : 0 : exit: 159 : : mbox_put(mbox); 160 : 0 : return rc; 161 : : } 162 : : 163 : : int 164 : 0 : roc_nix_mac_addr_del(struct roc_nix *roc_nix, uint32_t index) 165 : : { 166 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 167 : : struct dev *dev = &nix->dev; 168 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 169 : : struct cgx_mac_addr_del_req *req; 170 : : int rc = -ENOSPC; 171 : : 172 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 173 : : rc = NIX_ERR_OP_NOTSUP; 174 : 0 : goto exit; 175 : : } 176 : : 177 : 0 : req = mbox_alloc_msg_cgx_mac_addr_del(mbox); 178 [ # # ]: 0 : if (req == NULL) 179 : 0 : goto exit; 180 : 0 : req->index = index; 181 : : 182 : 0 : rc = mbox_process(mbox); 183 : 0 : exit: 184 : : mbox_put(mbox); 185 : 0 : return rc; 186 : : } 187 : : 188 : : int 189 : 0 : roc_nix_mac_promisc_mode_enable(struct roc_nix *roc_nix, int enable) 190 : : { 191 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 192 : : struct dev *dev = &nix->dev; 193 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 194 : : int rc; 195 : : 196 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 197 : : rc = NIX_ERR_OP_NOTSUP; 198 : 0 : goto exit; 199 : : } 200 : : 201 [ # # ]: 0 : if (enable) 202 : 0 : mbox_alloc_msg_cgx_promisc_enable(mbox); 203 : : else 204 : 0 : mbox_alloc_msg_cgx_promisc_disable(mbox); 205 : : 206 : 0 : rc = mbox_process(mbox); 207 : 0 : exit: 208 : : mbox_put(mbox); 209 : 0 : return rc; 210 : : } 211 : : 212 : : int 213 : 0 : roc_nix_mac_link_info_get(struct roc_nix *roc_nix, 214 : : struct roc_nix_link_info *link_info) 215 : : { 216 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 217 : : struct dev *dev = &nix->dev; 218 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 219 : : struct cgx_link_info_msg *rsp; 220 : : int rc; 221 : : 222 : 0 : mbox_alloc_msg_cgx_get_linkinfo(mbox); 223 : : rc = mbox_process_msg(mbox, (void *)&rsp); 224 [ # # ]: 0 : if (rc) 225 : 0 : goto exit; 226 : : 227 : 0 : link_info->status = rsp->link_info.link_up; 228 : 0 : link_info->full_duplex = rsp->link_info.full_duplex; 229 : 0 : link_info->lmac_type_id = rsp->link_info.lmac_type_id; 230 : 0 : link_info->speed = rsp->link_info.speed; 231 : 0 : link_info->autoneg = rsp->link_info.an; 232 : 0 : link_info->fec = rsp->link_info.fec; 233 : 0 : link_info->port = rsp->link_info.port; 234 : : 235 : : rc = 0; 236 : 0 : exit: 237 : : mbox_put(mbox); 238 : 0 : return rc; 239 : : } 240 : : 241 : : int 242 : 0 : roc_nix_mac_link_state_set(struct roc_nix *roc_nix, uint8_t up) 243 : : { 244 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 245 : : struct dev *dev = &nix->dev; 246 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 247 : : struct cgx_set_link_state_msg *req; 248 : : int rc = -ENOSPC; 249 : : 250 : 0 : req = mbox_alloc_msg_cgx_set_link_state(mbox); 251 [ # # ]: 0 : if (req == NULL) 252 : 0 : goto exit; 253 : 0 : req->enable = up; 254 : 0 : rc = mbox_process(mbox); 255 : 0 : exit: 256 : : mbox_put(mbox); 257 : 0 : return rc; 258 : : } 259 : : 260 : : int 261 : 0 : roc_nix_mac_fec_set(struct roc_nix *roc_nix, int fec) 262 : : { 263 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 264 : : struct dev *dev = &nix->dev; 265 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 266 : : struct fec_mode *req; 267 : : int rc = -ENOSPC; 268 : : 269 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 270 : : rc = NIX_ERR_OP_NOTSUP; 271 : 0 : goto exit; 272 : : } 273 : : 274 : 0 : req = mbox_alloc_msg_cgx_set_fec_param(mbox); 275 [ # # ]: 0 : if (req == NULL) 276 : 0 : goto exit; 277 : 0 : req->fec = fec; 278 : : 279 : 0 : rc = mbox_process(mbox); 280 : 0 : exit: 281 : : mbox_put(mbox); 282 : 0 : return rc; 283 : : } 284 : : 285 : : int 286 : 0 : roc_nix_mac_fec_supported_get(struct roc_nix *roc_nix, uint64_t *supported_fec) 287 : : { 288 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 289 : : struct dev *dev = &nix->dev; 290 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 291 : 0 : struct cgx_fw_data *rsp = NULL; 292 : : int rc; 293 : : 294 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 295 : : rc = NIX_ERR_OP_NOTSUP; 296 : 0 : goto exit; 297 : : } 298 : : 299 : 0 : mbox_alloc_msg_cgx_get_aux_link_info(mbox); 300 : : rc = mbox_process_msg(mbox, (void *)&rsp); 301 [ # # ]: 0 : if (rc) 302 : 0 : goto exit; 303 : : 304 : 0 : *supported_fec = rsp->fwdata.supported_fec; 305 : : rc = 0; 306 : 0 : exit: 307 : : mbox_put(mbox); 308 : 0 : return rc; 309 : : } 310 : : 311 : : int 312 : 0 : roc_nix_mac_link_info_set(struct roc_nix *roc_nix, 313 : : struct roc_nix_link_info *link_info) 314 : : { 315 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 316 : : struct dev *dev = &nix->dev; 317 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 318 : : struct cgx_set_link_mode_req *req; 319 : : int rc; 320 : : 321 : 0 : req = mbox_alloc_msg_cgx_set_link_mode(mbox); 322 [ # # ]: 0 : if (req == NULL) { 323 : : rc = -ENOSPC; 324 : 0 : goto exit; 325 : : } 326 : : 327 : 0 : req->args.advertising = link_info->advertising; 328 : 0 : req->args.speed = link_info->speed; 329 : 0 : req->args.duplex = link_info->full_duplex; 330 : 0 : req->args.an = link_info->autoneg; 331 : : 332 : : /* Link mode changes takes more time. */ 333 : 0 : rc = mbox_process_tmo(mbox, mbox->rsp_tmo * 4); 334 : 0 : exit: 335 : : mbox_put(mbox); 336 : 0 : return rc; 337 : : 338 : : } 339 : : 340 : : int 341 : 0 : roc_nix_mac_mtu_set(struct roc_nix *roc_nix, uint16_t mtu) 342 : : { 343 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 344 : : struct dev *dev = &nix->dev; 345 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 346 : : struct nix_frs_cfg *req; 347 : : bool sdp_link = false; 348 : : int rc = -ENOSPC; 349 : : 350 [ # # ]: 0 : if (roc_nix_is_sdp(roc_nix)) 351 : : sdp_link = true; 352 : : 353 : 0 : req = mbox_alloc_msg_nix_set_hw_frs(mbox); 354 [ # # ]: 0 : if (req == NULL) 355 : 0 : goto exit; 356 : 0 : req->maxlen = mtu; 357 : 0 : req->update_smq = true; 358 : 0 : req->sdp_link = sdp_link; 359 : : 360 : 0 : rc = mbox_process(mbox); 361 [ # # ]: 0 : if (rc) 362 : 0 : goto exit; 363 : : 364 : : /* Save MTU for later use */ 365 : 0 : nix->mtu = mtu; 366 : : rc = 0; 367 : 0 : exit: 368 : : mbox_put(mbox); 369 : 0 : return rc; 370 : : } 371 : : 372 : : int 373 : 0 : roc_nix_mac_max_rx_len_set(struct roc_nix *roc_nix, uint16_t maxlen) 374 : : { 375 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 376 : : struct dev *dev = &nix->dev; 377 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 378 : : struct nix_frs_cfg *req; 379 : : bool sdp_link = false; 380 : : int rc = -ENOSPC; 381 : : 382 [ # # ]: 0 : if (roc_nix_is_sdp(roc_nix)) 383 : : sdp_link = true; 384 : : 385 : 0 : req = mbox_alloc_msg_nix_set_hw_frs(mbox); 386 [ # # ]: 0 : if (req == NULL) 387 : 0 : goto exit; 388 : 0 : req->sdp_link = sdp_link; 389 : 0 : req->maxlen = maxlen; 390 : : 391 : 0 : rc = mbox_process(mbox); 392 : 0 : exit: 393 : : mbox_put(mbox); 394 : 0 : return rc; 395 : : } 396 : : 397 : : int 398 : 0 : roc_nix_mac_stats_reset(struct roc_nix *roc_nix) 399 : : { 400 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 401 : : struct dev *dev = &nix->dev; 402 : 0 : struct mbox *mbox = mbox_get(dev->mbox); 403 : : struct msg_req *req; 404 : : int rc = -ENOSPC; 405 : : 406 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(roc_nix)) { 407 : : rc = 0; 408 : 0 : goto exit; 409 : : } 410 : : 411 : 0 : req = mbox_alloc_msg_cgx_stats_rst(mbox); 412 [ # # ]: 0 : if (req == NULL) 413 : 0 : goto exit; 414 : : 415 : 0 : rc = mbox_process(mbox); 416 : 0 : exit: 417 : : mbox_put(mbox); 418 : 0 : return rc; 419 : : } 420 : : 421 : : int 422 : 0 : roc_nix_mac_link_cb_register(struct roc_nix *roc_nix, link_status_t link_update) 423 : : { 424 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 425 : : struct dev *dev = &nix->dev; 426 : : 427 [ # # ]: 0 : if (link_update == NULL) 428 : : return NIX_ERR_PARAM; 429 : : 430 : 0 : dev->ops->link_status_update = (link_info_t)link_update; 431 : 0 : return 0; 432 : : } 433 : : 434 : : void 435 : 0 : roc_nix_mac_link_cb_unregister(struct roc_nix *roc_nix) 436 : : { 437 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 438 : : struct dev *dev = &nix->dev; 439 : : 440 : 0 : dev->ops->link_status_update = NULL; 441 : 0 : } 442 : : 443 : : int 444 : 0 : roc_nix_mac_link_info_get_cb_register(struct roc_nix *roc_nix, 445 : : link_info_get_t link_info_get) 446 : : { 447 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 448 : : struct dev *dev = &nix->dev; 449 : : 450 [ # # ]: 0 : if (link_info_get == NULL) 451 : : return NIX_ERR_PARAM; 452 : : 453 : 0 : dev->ops->link_status_get = (link_info_t)link_info_get; 454 : 0 : return 0; 455 : : } 456 : : 457 : : void 458 : 0 : roc_nix_mac_link_info_get_cb_unregister(struct roc_nix *roc_nix) 459 : : { 460 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 461 : : struct dev *dev = &nix->dev; 462 : : 463 : 0 : dev->ops->link_status_get = NULL; 464 : 0 : } 465 : : 466 : : int 467 : 0 : roc_nix_mac_fwdata_get(struct roc_nix *roc_nix, struct roc_nix_mac_fwdata *data) 468 : : { 469 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix); 470 : : struct cgx_fw_data *fw_data; 471 : : struct dev *dev = &nix->dev; 472 : : struct mbox *mbox; 473 : : int rc; 474 : : 475 [ # # ]: 0 : if (roc_nix_is_sdp(roc_nix)) 476 : : return 0; 477 : : 478 : 0 : mbox = mbox_get(dev->mbox); 479 : : 480 : 0 : mbox_alloc_msg_cgx_get_aux_link_info(mbox); 481 : : rc = mbox_process_msg(mbox, (void *)&fw_data); 482 [ # # ]: 0 : if (rc) 483 : 0 : goto exit; 484 : : 485 : 0 : nix->supported_link_modes = fw_data->fwdata.supported_link_modes; 486 : 0 : nix->advertised_link_modes = fw_data->fwdata.advertised_link_modes; 487 : 0 : data->supported_link_modes = nix->supported_link_modes; 488 : 0 : data->advertised_link_modes = nix->advertised_link_modes; 489 : 0 : data->supported_an = fw_data->fwdata.supported_an; 490 : 0 : data->port_type = fw_data->fwdata.port; 491 : 0 : exit: 492 : : mbox_put(mbox); 493 : 0 : return rc; 494 : : }