| 569 | } |
| 570 | |
| 571 | struct rte_flow_action_handle * |
| 572 | mlx5_quota_alloc(struct rte_eth_dev *dev, uint32_t queue, |
| 573 | const struct rte_flow_action_quota *conf, |
| 574 | struct mlx5_hw_q_job *job, bool push, |
| 575 | struct rte_flow_error *error) |
| 576 | { |
| 577 | struct mlx5_priv *priv = dev->data->dev_private; |
| 578 | struct mlx5_quota_ctx *qctx = &priv->quota_ctx; |
| 579 | uint32_t id; |
| 580 | struct mlx5_quota *qobj; |
| 581 | uintptr_t handle = (uintptr_t)MLX5_INDIRECT_ACTION_TYPE_QUOTA << |
| 582 | MLX5_INDIRECT_ACTION_TYPE_OFFSET; |
| 583 | uint32_t work_queue = !is_quota_sync_queue(priv, queue) ? |
| 584 | queue : quota_sync_queue(priv); |
| 585 | struct mlx5_hw_q_job sync_job; |
| 586 | uint8_t state = MLX5_QUOTA_STATE_FREE; |
| 587 | bool verdict; |
| 588 | int ret; |
| 589 | |
| 590 | qobj = mlx5_ipool_malloc(qctx->quota_ipool, &id); |
| 591 | if (!qobj) { |
| 592 | rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, |
| 593 | NULL, "quota: failed to allocate quota object"); |
| 594 | return NULL; |
| 595 | } |
| 596 | verdict = __atomic_compare_exchange_n |
| 597 | (&qobj->state, &state, MLX5_QUOTA_STATE_WAIT, false, |
| 598 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); |
| 599 | if (!verdict) { |
| 600 | rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, |
| 601 | NULL, "quota: new quota object has invalid state"); |
| 602 | return NULL; |
| 603 | } |
| 604 | switch (conf->mode) { |
| 605 | case RTE_FLOW_QUOTA_MODE_L2: |
| 606 | qobj->mode = MLX5_METER_MODE_L2_LEN; |
| 607 | break; |
| 608 | case RTE_FLOW_QUOTA_MODE_PACKET: |
| 609 | qobj->mode = MLX5_METER_MODE_PKT; |
| 610 | break; |
| 611 | default: |
| 612 | qobj->mode = MLX5_METER_MODE_IP_LEN; |
| 613 | } |
| 614 | ret = mlx5_quota_cmd_wqe(dev, qobj, mlx5_quota_set_init_wqe, id - 1, |
| 615 | work_queue, job ? job : &sync_job, push, |
| 616 | (void *)(uintptr_t)conf); |
| 617 | if (ret) { |
| 618 | mlx5_ipool_free(qctx->quota_ipool, id); |
| 619 | __atomic_store_n(&qobj->state, MLX5_QUOTA_STATE_FREE, |
| 620 | __ATOMIC_RELAXED); |
| 621 | rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, |
| 622 | NULL, "quota: WR failure"); |
| 623 | return 0; |
| 624 | } |
| 625 | return (struct rte_flow_action_handle *)(handle | id); |
| 626 | } |
| 627 | |
| 628 | int |
no test coverage detected