1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Cavium, Inc 3 */ 4 5 #include <inttypes.h> 6 7 #include <rte_common.h> 8 #include <rte_debug.h> 9 #include <rte_dev.h> 10 #include <rte_eal.h> 11 #include <rte_ethdev_driver.h> 12 #include <rte_event_eth_rx_adapter.h> 13 #include <rte_kvargs.h> 14 #include <rte_lcore.h> 15 #include <rte_log.h> 16 #include <rte_malloc.h> 17 #include <rte_memory.h> 18 #include <rte_bus_vdev.h> 19 20 #include "ssovf_evdev.h" 21 #include "timvf_evdev.h" 22 23 int otx_logtype_ssovf; 24 static uint8_t timvf_enable_stats; 25 26 RTE_INIT(otx_ssovf_init_log) 27 { 28 otx_logtype_ssovf = rte_log_register("pmd.event.octeontx"); 29 if (otx_logtype_ssovf >= 0) 30 rte_log_set_level(otx_logtype_ssovf, RTE_LOG_NOTICE); 31 } 32 33 /* SSOPF Mailbox messages */ 34 35 struct ssovf_mbox_dev_info { 36 uint64_t min_deq_timeout_ns; 37 uint64_t max_deq_timeout_ns; 38 uint32_t max_num_events; 39 }; 40 41 static int 42 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info) 43 { 44 struct octeontx_mbox_hdr hdr = {0}; 45 uint16_t len = sizeof(struct ssovf_mbox_dev_info); 46 47 hdr.coproc = SSO_COPROC; 48 hdr.msg = SSO_GET_DEV_INFO; 49 hdr.vfid = 0; 50 51 memset(info, 0, len); 52 return octeontx_mbox_send(&hdr, NULL, 0, info, len); 53 } 54 55 struct ssovf_mbox_getwork_wait { 56 uint64_t wait_ns; 57 }; 58 59 static int 60 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns) 61 { 62 struct octeontx_mbox_hdr hdr = {0}; 63 struct ssovf_mbox_getwork_wait tmo_set; 64 uint16_t len = sizeof(struct ssovf_mbox_getwork_wait); 65 int ret; 66 67 hdr.coproc = SSO_COPROC; 68 hdr.msg = SSO_SET_GETWORK_WAIT; 69 hdr.vfid = 0; 70 71 tmo_set.wait_ns = timeout_ns; 72 ret = octeontx_mbox_send(&hdr, &tmo_set, len, NULL, 0); 73 if (ret) 74 ssovf_log_err("Failed to set getwork timeout(%d)", ret); 75 76 return ret; 77 } 78 79 struct ssovf_mbox_grp_pri { 80 uint8_t wgt_left; /* Read only */ 81 uint8_t weight; 82 uint8_t affinity; 83 uint8_t priority; 84 }; 85 86 static int 87 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio) 88 { 89 struct octeontx_mbox_hdr hdr = {0}; 90 struct ssovf_mbox_grp_pri grp; 91 uint16_t len = sizeof(struct ssovf_mbox_grp_pri); 92 int ret; 93 94 hdr.coproc = SSO_COPROC; 95 hdr.msg = SSO_GRP_SET_PRIORITY; 96 hdr.vfid = queue; 97 98 grp.weight = 0xff; 99 grp.affinity = 0xff; 100 grp.priority = prio / 32; /* Normalize to 0 to 7 */ 101 102 ret = octeontx_mbox_send(&hdr, &grp, len, NULL, 0); 103 if (ret) 104 ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio); 105 106 return ret; 107 } 108 109 struct ssovf_mbox_convert_ns_getworks_iter { 110 uint64_t wait_ns; 111 uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */ 112 }; 113 114 static int 115 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks) 116 { 117 struct octeontx_mbox_hdr hdr = {0}; 118 struct ssovf_mbox_convert_ns_getworks_iter ns2iter; 119 uint16_t len = sizeof(ns2iter); 120 int ret; 121 122 hdr.coproc = SSO_COPROC; 123 hdr.msg = SSO_CONVERT_NS_GETWORK_ITER; 124 hdr.vfid = 0; 125 126 memset(&ns2iter, 0, len); 127 ns2iter.wait_ns = ns; 128 ret = octeontx_mbox_send(&hdr, &ns2iter, len, &ns2iter, len); 129 if (ret < 0 || (ret != len)) { 130 ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns); 131 return -EIO; 132 } 133 134 *tmo_ticks = ns2iter.getwork_iter; 135 return 0; 136 } 137 138 static void 139 ssovf_fastpath_fns_set(struct rte_eventdev *dev) 140 { 141 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 142 143 dev->enqueue = ssows_enq; 144 dev->enqueue_burst = ssows_enq_burst; 145 dev->enqueue_new_burst = ssows_enq_new_burst; 146 dev->enqueue_forward_burst = ssows_enq_fwd_burst; 147 dev->dequeue = ssows_deq; 148 dev->dequeue_burst = ssows_deq_burst; 149 dev->txa_enqueue = sso_event_tx_adapter_enqueue; 150 dev->txa_enqueue_same_dest = dev->txa_enqueue; 151 152 if (edev->is_timeout_deq) { 153 dev->dequeue = ssows_deq_timeout; 154 dev->dequeue_burst = ssows_deq_timeout_burst; 155 } 156 } 157 158 static void 159 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info) 160 { 161 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 162 163 dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX_PMD); 164 dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns; 165 dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns; 166 dev_info->max_event_queues = edev->max_event_queues; 167 dev_info->max_event_queue_flows = (1ULL << 20); 168 dev_info->max_event_queue_priority_levels = 8; 169 dev_info->max_event_priority_levels = 1; 170 dev_info->max_event_ports = edev->max_event_ports; 171 dev_info->max_event_port_dequeue_depth = 1; 172 dev_info->max_event_port_enqueue_depth = 1; 173 dev_info->max_num_events = edev->max_num_events; 174 dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS | 175 RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED | 176 RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES| 177 RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK | 178 RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT | 179 RTE_EVENT_DEV_CAP_NONSEQ_MODE; 180 181 } 182 183 static int 184 ssovf_configure(const struct rte_eventdev *dev) 185 { 186 struct rte_event_dev_config *conf = &dev->data->dev_conf; 187 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 188 uint64_t deq_tmo_ns; 189 190 ssovf_func_trace(); 191 deq_tmo_ns = conf->dequeue_timeout_ns; 192 if (deq_tmo_ns == 0) 193 deq_tmo_ns = edev->min_deq_timeout_ns; 194 195 if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) { 196 edev->is_timeout_deq = 1; 197 deq_tmo_ns = edev->min_deq_timeout_ns; 198 } 199 edev->nb_event_queues = conf->nb_event_queues; 200 edev->nb_event_ports = conf->nb_event_ports; 201 202 return ssovf_mbox_getwork_tmo_set(deq_tmo_ns); 203 } 204 205 static void 206 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id, 207 struct rte_event_queue_conf *queue_conf) 208 { 209 RTE_SET_USED(dev); 210 RTE_SET_USED(queue_id); 211 212 queue_conf->nb_atomic_flows = (1ULL << 20); 213 queue_conf->nb_atomic_order_sequences = (1ULL << 20); 214 queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES; 215 queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 216 } 217 218 static void 219 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id) 220 { 221 RTE_SET_USED(dev); 222 RTE_SET_USED(queue_id); 223 } 224 225 static int 226 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id, 227 const struct rte_event_queue_conf *queue_conf) 228 { 229 RTE_SET_USED(dev); 230 ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority); 231 232 return ssovf_mbox_priority_set(queue_id, queue_conf->priority); 233 } 234 235 static void 236 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id, 237 struct rte_event_port_conf *port_conf) 238 { 239 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 240 241 RTE_SET_USED(port_id); 242 port_conf->new_event_threshold = edev->max_num_events; 243 port_conf->dequeue_depth = 1; 244 port_conf->enqueue_depth = 1; 245 port_conf->disable_implicit_release = 0; 246 } 247 248 static void 249 ssovf_port_release(void *port) 250 { 251 rte_free(port); 252 } 253 254 static int 255 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id, 256 const struct rte_event_port_conf *port_conf) 257 { 258 struct ssows *ws; 259 uint32_t reg_off; 260 uint8_t q; 261 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 262 263 ssovf_func_trace("port=%d", port_id); 264 RTE_SET_USED(port_conf); 265 266 /* Free memory prior to re-allocation if needed */ 267 if (dev->data->ports[port_id] != NULL) { 268 ssovf_port_release(dev->data->ports[port_id]); 269 dev->data->ports[port_id] = NULL; 270 } 271 272 /* Allocate event port memory */ 273 ws = rte_zmalloc_socket("eventdev ssows", 274 sizeof(struct ssows), RTE_CACHE_LINE_SIZE, 275 dev->data->socket_id); 276 if (ws == NULL) { 277 ssovf_log_err("Failed to alloc memory for port=%d", port_id); 278 return -ENOMEM; 279 } 280 281 ws->base = ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0); 282 if (ws->base == NULL) { 283 rte_free(ws); 284 ssovf_log_err("Failed to get hws base addr port=%d", port_id); 285 return -EINVAL; 286 } 287 288 reg_off = SSOW_VHWS_OP_GET_WORK0; 289 reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */ 290 reg_off |= 1 << 16; /* Wait */ 291 ws->getwork = ws->base + reg_off; 292 ws->port = port_id; 293 294 for (q = 0; q < edev->nb_event_queues; q++) { 295 ws->grps[q] = ssovf_bar(OCTEONTX_SSO_GROUP, q, 2); 296 if (ws->grps[q] == NULL) { 297 rte_free(ws); 298 ssovf_log_err("Failed to get grp%d base addr", q); 299 return -EINVAL; 300 } 301 } 302 303 dev->data->ports[port_id] = ws; 304 ssovf_log_dbg("port=%d ws=%p", port_id, ws); 305 return 0; 306 } 307 308 static int 309 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[], 310 const uint8_t priorities[], uint16_t nb_links) 311 { 312 uint16_t link; 313 uint64_t val; 314 struct ssows *ws = port; 315 316 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links); 317 RTE_SET_USED(dev); 318 RTE_SET_USED(priorities); 319 320 for (link = 0; link < nb_links; link++) { 321 val = queues[link]; 322 val |= (1ULL << 24); /* Set membership */ 323 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0)); 324 } 325 return (int)nb_links; 326 } 327 328 static int 329 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[], 330 uint16_t nb_unlinks) 331 { 332 uint16_t unlink; 333 uint64_t val; 334 struct ssows *ws = port; 335 336 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks); 337 RTE_SET_USED(dev); 338 339 for (unlink = 0; unlink < nb_unlinks; unlink++) { 340 val = queues[unlink]; 341 val &= ~(1ULL << 24); /* Clear membership */ 342 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0)); 343 } 344 return (int)nb_unlinks; 345 } 346 347 static int 348 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks) 349 { 350 RTE_SET_USED(dev); 351 352 return ssovf_mbox_timeout_ticks(ns, tmo_ticks); 353 } 354 355 static void 356 ssows_dump(struct ssows *ws, FILE *f) 357 { 358 uint8_t *base = ws->base; 359 uint64_t val; 360 361 fprintf(f, "\t---------------port%d---------------\n", ws->port); 362 val = ssovf_read64(base + SSOW_VHWS_TAG); 363 fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n", 364 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3, 365 (int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1, 366 (int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff, 367 (int)(val >> 63) & 0x1); 368 369 val = ssovf_read64(base + SSOW_VHWS_WQP); 370 fprintf(f, "\twqp=0x%"PRIx64"\n", val); 371 372 val = ssovf_read64(base + SSOW_VHWS_LINKS); 373 fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n", 374 (int)(val & 0x3ff), (int)(val >> 10) & 0x1, 375 (int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1, 376 (int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff); 377 378 val = ssovf_read64(base + SSOW_VHWS_PENDTAG); 379 fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n", 380 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3, 381 (int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1, 382 (int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1, 383 (int)(val >> 63) & 0x1); 384 385 val = ssovf_read64(base + SSOW_VHWS_PENDWQP); 386 fprintf(f, "\tpwqp=0x%"PRIx64"\n", val); 387 } 388 389 static int 390 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev, 391 const struct rte_eth_dev *eth_dev, uint32_t *caps) 392 { 393 int ret; 394 RTE_SET_USED(dev); 395 396 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12); 397 if (ret) 398 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP; 399 else 400 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT; 401 402 return 0; 403 } 404 405 static int 406 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev, 407 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id, 408 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf) 409 { 410 int ret = 0; 411 const struct octeontx_nic *nic = eth_dev->data->dev_private; 412 pki_mod_qos_t pki_qos; 413 RTE_SET_USED(dev); 414 415 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12); 416 if (ret) 417 return -EINVAL; 418 419 if (rx_queue_id >= 0) 420 return -EINVAL; 421 422 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL) 423 return -ENOTSUP; 424 425 memset(&pki_qos, 0, sizeof(pki_mod_qos_t)); 426 427 pki_qos.port_type = 0; 428 pki_qos.index = 0; 429 pki_qos.mmask.f_tag_type = 1; 430 pki_qos.mmask.f_port_add = 1; 431 pki_qos.mmask.f_grp_ok = 1; 432 pki_qos.mmask.f_grp_bad = 1; 433 pki_qos.mmask.f_grptag_ok = 1; 434 pki_qos.mmask.f_grptag_bad = 1; 435 436 pki_qos.tag_type = queue_conf->ev.sched_type; 437 pki_qos.qos_entry.port_add = 0; 438 pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id; 439 pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id; 440 pki_qos.qos_entry.grptag_bad = 0; 441 pki_qos.qos_entry.grptag_ok = 0; 442 443 ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos); 444 if (ret < 0) 445 ssovf_log_err("failed to modify QOS, port=%d, q=%d", 446 nic->port_id, queue_conf->ev.queue_id); 447 448 return ret; 449 } 450 451 static int 452 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev, 453 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id) 454 { 455 int ret = 0; 456 const struct octeontx_nic *nic = eth_dev->data->dev_private; 457 pki_del_qos_t pki_qos; 458 RTE_SET_USED(dev); 459 460 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12); 461 if (ret) 462 return -EINVAL; 463 464 pki_qos.port_type = 0; 465 pki_qos.index = 0; 466 memset(&pki_qos, 0, sizeof(pki_del_qos_t)); 467 ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos); 468 if (ret < 0) 469 ssovf_log_err("Failed to delete QOS port=%d, q=%d", 470 nic->port_id, rx_queue_id); 471 return ret; 472 } 473 474 static int 475 ssovf_eth_rx_adapter_start(const struct rte_eventdev *dev, 476 const struct rte_eth_dev *eth_dev) 477 { 478 RTE_SET_USED(dev); 479 RTE_SET_USED(eth_dev); 480 481 return 0; 482 } 483 484 485 static int 486 ssovf_eth_rx_adapter_stop(const struct rte_eventdev *dev, 487 const struct rte_eth_dev *eth_dev) 488 { 489 RTE_SET_USED(dev); 490 RTE_SET_USED(eth_dev); 491 492 return 0; 493 } 494 495 static int 496 ssovf_eth_tx_adapter_caps_get(const struct rte_eventdev *dev, 497 const struct rte_eth_dev *eth_dev, uint32_t *caps) 498 { 499 int ret; 500 RTE_SET_USED(dev); 501 502 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12); 503 if (ret) 504 *caps = 0; 505 else 506 *caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT; 507 508 return 0; 509 } 510 511 static int 512 ssovf_eth_tx_adapter_create(uint8_t id, const struct rte_eventdev *dev) 513 { 514 RTE_SET_USED(id); 515 RTE_SET_USED(dev); 516 return 0; 517 } 518 519 static int 520 ssovf_eth_tx_adapter_free(uint8_t id, const struct rte_eventdev *dev) 521 { 522 RTE_SET_USED(id); 523 RTE_SET_USED(dev); 524 return 0; 525 } 526 527 static int 528 ssovf_eth_tx_adapter_queue_add(uint8_t id, const struct rte_eventdev *dev, 529 const struct rte_eth_dev *eth_dev, int32_t tx_queue_id) 530 { 531 RTE_SET_USED(id); 532 RTE_SET_USED(dev); 533 RTE_SET_USED(eth_dev); 534 RTE_SET_USED(tx_queue_id); 535 return 0; 536 } 537 538 static int 539 ssovf_eth_tx_adapter_queue_del(uint8_t id, const struct rte_eventdev *dev, 540 const struct rte_eth_dev *eth_dev, int32_t tx_queue_id) 541 { 542 RTE_SET_USED(id); 543 RTE_SET_USED(dev); 544 RTE_SET_USED(eth_dev); 545 RTE_SET_USED(tx_queue_id); 546 return 0; 547 } 548 549 static int 550 ssovf_eth_tx_adapter_start(uint8_t id, const struct rte_eventdev *dev) 551 { 552 RTE_SET_USED(id); 553 RTE_SET_USED(dev); 554 return 0; 555 } 556 557 static int 558 ssovf_eth_tx_adapter_stop(uint8_t id, const struct rte_eventdev *dev) 559 { 560 RTE_SET_USED(id); 561 RTE_SET_USED(dev); 562 return 0; 563 } 564 565 566 static void 567 ssovf_dump(struct rte_eventdev *dev, FILE *f) 568 { 569 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 570 uint8_t port; 571 572 /* Dump SSOWVF debug registers */ 573 for (port = 0; port < edev->nb_event_ports; port++) 574 ssows_dump(dev->data->ports[port], f); 575 } 576 577 static int 578 ssovf_start(struct rte_eventdev *dev) 579 { 580 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 581 struct ssows *ws; 582 uint8_t *base; 583 uint8_t i; 584 585 ssovf_func_trace(); 586 for (i = 0; i < edev->nb_event_ports; i++) { 587 ws = dev->data->ports[i]; 588 ssows_reset(ws); 589 ws->swtag_req = 0; 590 } 591 592 for (i = 0; i < edev->nb_event_queues; i++) { 593 /* Consume all the events through HWS0 */ 594 ssows_flush_events(dev->data->ports[0], i, NULL, NULL); 595 596 base = ssovf_bar(OCTEONTX_SSO_GROUP, i, 0); 597 base += SSO_VHGRP_QCTL; 598 ssovf_write64(1, base); /* Enable SSO group */ 599 } 600 601 ssovf_fastpath_fns_set(dev); 602 return 0; 603 } 604 605 static void 606 ssows_handle_event(void *arg, struct rte_event event) 607 { 608 struct rte_eventdev *dev = arg; 609 610 if (dev->dev_ops->dev_stop_flush != NULL) 611 dev->dev_ops->dev_stop_flush(dev->data->dev_id, event, 612 dev->data->dev_stop_flush_arg); 613 } 614 615 static void 616 ssovf_stop(struct rte_eventdev *dev) 617 { 618 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 619 struct ssows *ws; 620 uint8_t *base; 621 uint8_t i; 622 623 ssovf_func_trace(); 624 for (i = 0; i < edev->nb_event_ports; i++) { 625 ws = dev->data->ports[i]; 626 ssows_reset(ws); 627 ws->swtag_req = 0; 628 } 629 630 for (i = 0; i < edev->nb_event_queues; i++) { 631 /* Consume all the events through HWS0 */ 632 ssows_flush_events(dev->data->ports[0], i, 633 ssows_handle_event, dev); 634 635 base = ssovf_bar(OCTEONTX_SSO_GROUP, i, 0); 636 base += SSO_VHGRP_QCTL; 637 ssovf_write64(0, base); /* Disable SSO group */ 638 } 639 } 640 641 static int 642 ssovf_close(struct rte_eventdev *dev) 643 { 644 struct ssovf_evdev *edev = ssovf_pmd_priv(dev); 645 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV]; 646 uint8_t i; 647 648 for (i = 0; i < edev->nb_event_queues; i++) 649 all_queues[i] = i; 650 651 for (i = 0; i < edev->nb_event_ports; i++) 652 ssovf_port_unlink(dev, dev->data->ports[i], all_queues, 653 edev->nb_event_queues); 654 return 0; 655 } 656 657 static int 658 ssovf_selftest(const char *key __rte_unused, const char *value, 659 void *opaque) 660 { 661 int *flag = opaque; 662 *flag = !!atoi(value); 663 return 0; 664 } 665 666 static int 667 ssovf_timvf_caps_get(const struct rte_eventdev *dev, uint64_t flags, 668 uint32_t *caps, const struct rte_event_timer_adapter_ops **ops) 669 { 670 return timvf_timer_adapter_caps_get(dev, flags, caps, ops, 671 timvf_enable_stats); 672 } 673 674 /* Initialize and register event driver with DPDK Application */ 675 static struct rte_eventdev_ops ssovf_ops = { 676 .dev_infos_get = ssovf_info_get, 677 .dev_configure = ssovf_configure, 678 .queue_def_conf = ssovf_queue_def_conf, 679 .queue_setup = ssovf_queue_setup, 680 .queue_release = ssovf_queue_release, 681 .port_def_conf = ssovf_port_def_conf, 682 .port_setup = ssovf_port_setup, 683 .port_release = ssovf_port_release, 684 .port_link = ssovf_port_link, 685 .port_unlink = ssovf_port_unlink, 686 .timeout_ticks = ssovf_timeout_ticks, 687 688 .eth_rx_adapter_caps_get = ssovf_eth_rx_adapter_caps_get, 689 .eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add, 690 .eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del, 691 .eth_rx_adapter_start = ssovf_eth_rx_adapter_start, 692 .eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop, 693 694 .eth_tx_adapter_caps_get = ssovf_eth_tx_adapter_caps_get, 695 .eth_tx_adapter_create = ssovf_eth_tx_adapter_create, 696 .eth_tx_adapter_free = ssovf_eth_tx_adapter_free, 697 .eth_tx_adapter_queue_add = ssovf_eth_tx_adapter_queue_add, 698 .eth_tx_adapter_queue_del = ssovf_eth_tx_adapter_queue_del, 699 .eth_tx_adapter_start = ssovf_eth_tx_adapter_start, 700 .eth_tx_adapter_stop = ssovf_eth_tx_adapter_stop, 701 702 .timer_adapter_caps_get = ssovf_timvf_caps_get, 703 704 .dev_selftest = test_eventdev_octeontx, 705 706 .dump = ssovf_dump, 707 .dev_start = ssovf_start, 708 .dev_stop = ssovf_stop, 709 .dev_close = ssovf_close 710 }; 711 712 static int 713 ssovf_vdev_probe(struct rte_vdev_device *vdev) 714 { 715 struct ssovf_info oinfo; 716 struct ssovf_mbox_dev_info info; 717 struct ssovf_evdev *edev; 718 struct rte_eventdev *eventdev; 719 static int ssovf_init_once; 720 const char *name; 721 const char *params; 722 int ret; 723 int selftest = 0; 724 725 static const char *const args[] = { 726 SSOVF_SELFTEST_ARG, 727 TIMVF_ENABLE_STATS_ARG, 728 NULL 729 }; 730 731 name = rte_vdev_device_name(vdev); 732 /* More than one instance is not supported */ 733 if (ssovf_init_once) { 734 ssovf_log_err("Request to create >1 %s instance", name); 735 return -EINVAL; 736 } 737 738 params = rte_vdev_device_args(vdev); 739 if (params != NULL && params[0] != '\0') { 740 struct rte_kvargs *kvlist = rte_kvargs_parse(params, args); 741 742 if (!kvlist) { 743 ssovf_log_info( 744 "Ignoring unsupported params supplied '%s'", 745 name); 746 } else { 747 int ret = rte_kvargs_process(kvlist, 748 SSOVF_SELFTEST_ARG, 749 ssovf_selftest, &selftest); 750 if (ret != 0) { 751 ssovf_log_err("%s: Error in selftest", name); 752 rte_kvargs_free(kvlist); 753 return ret; 754 } 755 756 ret = rte_kvargs_process(kvlist, 757 TIMVF_ENABLE_STATS_ARG, 758 ssovf_selftest, &timvf_enable_stats); 759 if (ret != 0) { 760 ssovf_log_err("%s: Error in timvf stats", name); 761 rte_kvargs_free(kvlist); 762 return ret; 763 } 764 } 765 766 rte_kvargs_free(kvlist); 767 } 768 769 eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev), 770 rte_socket_id()); 771 if (eventdev == NULL) { 772 ssovf_log_err("Failed to create eventdev vdev %s", name); 773 return -ENOMEM; 774 } 775 eventdev->dev_ops = &ssovf_ops; 776 777 /* For secondary processes, the primary has done all the work */ 778 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 779 ssovf_fastpath_fns_set(eventdev); 780 return 0; 781 } 782 783 ret = ssovf_info(&oinfo); 784 if (ret) { 785 ssovf_log_err("Failed to probe and validate ssovfs %d", ret); 786 goto error; 787 } 788 789 edev = ssovf_pmd_priv(eventdev); 790 edev->max_event_ports = oinfo.total_ssowvfs; 791 edev->max_event_queues = oinfo.total_ssovfs; 792 edev->is_timeout_deq = 0; 793 794 ret = ssovf_mbox_dev_info(&info); 795 if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) { 796 ssovf_log_err("Failed to get mbox devinfo %d", ret); 797 goto error; 798 } 799 800 edev->min_deq_timeout_ns = info.min_deq_timeout_ns; 801 edev->max_deq_timeout_ns = info.max_deq_timeout_ns; 802 edev->max_num_events = info.max_num_events; 803 ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d", 804 info.min_deq_timeout_ns, info.max_deq_timeout_ns, 805 info.max_num_events); 806 807 if (!edev->max_event_ports || !edev->max_event_queues) { 808 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d", 809 edev->max_event_queues, edev->max_event_ports); 810 ret = -ENODEV; 811 goto error; 812 } 813 814 ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d", 815 name, oinfo.domain, edev->max_event_queues, 816 edev->max_event_ports); 817 818 ssovf_init_once = 1; 819 if (selftest) 820 test_eventdev_octeontx(); 821 return 0; 822 823 error: 824 rte_event_pmd_vdev_uninit(name); 825 return ret; 826 } 827 828 static int 829 ssovf_vdev_remove(struct rte_vdev_device *vdev) 830 { 831 const char *name; 832 833 name = rte_vdev_device_name(vdev); 834 ssovf_log_info("Closing %s", name); 835 return rte_event_pmd_vdev_uninit(name); 836 } 837 838 static struct rte_vdev_driver vdev_ssovf_pmd = { 839 .probe = ssovf_vdev_probe, 840 .remove = ssovf_vdev_remove 841 }; 842 843 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd); 844