* Create meter rules. * * @param[in] dev * Pointer to Ethernet device. * @param[in] mtr_id * Meter id. * @param[in] params * Pointer to rte meter parameters. * @param[in] shared * Meter shared with other flow or not. * @param[out] error * Pointer to rte meter error structure. * * @return * 0 on success, a negative value otherwise and rte_errno is set. */
| 668 | * 0 on success, a negative value otherwise and rte_errno is set. |
| 669 | */ |
| 670 | static int |
| 671 | nfp_mtr_create(struct rte_eth_dev *dev, |
| 672 | uint32_t mtr_id, |
| 673 | struct rte_mtr_params *params, |
| 674 | int shared, |
| 675 | struct rte_mtr_error *error) |
| 676 | { |
| 677 | int ret; |
| 678 | struct nfp_mtr *mtr; |
| 679 | struct nfp_mtr_priv *priv; |
| 680 | struct nfp_mtr_policy *mtr_policy; |
| 681 | struct nfp_mtr_profile *mtr_profile; |
| 682 | struct nfp_flower_representor *representor; |
| 683 | |
| 684 | representor = dev->data->dev_private; |
| 685 | priv = representor->app_fw_flower->mtr_priv; |
| 686 | |
| 687 | /* Check if meter id exist */ |
| 688 | mtr = nfp_mtr_find_by_mtr_id(priv, mtr_id); |
| 689 | if (mtr != NULL) { |
| 690 | return -rte_mtr_error_set(error, EEXIST, |
| 691 | RTE_MTR_ERROR_TYPE_MTR_ID, |
| 692 | NULL, "Meter already exist"); |
| 693 | } |
| 694 | |
| 695 | /* Check input meter params */ |
| 696 | ret = nfp_mtr_validate(mtr_id, params, error); |
| 697 | if (ret != 0) |
| 698 | return ret; |
| 699 | |
| 700 | mtr_profile = nfp_mtr_profile_search(priv, params->meter_profile_id); |
| 701 | if (mtr_profile == NULL) { |
| 702 | return -rte_mtr_error_set(error, EINVAL, |
| 703 | RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, |
| 704 | NULL, "Request meter profile not exist"); |
| 705 | } |
| 706 | |
| 707 | if (mtr_profile->in_use) { |
| 708 | return -rte_mtr_error_set(error, EINVAL, |
| 709 | RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, |
| 710 | NULL, "Request meter profile is been used"); |
| 711 | } |
| 712 | |
| 713 | mtr_policy = nfp_mtr_policy_search(priv, params->meter_policy_id); |
| 714 | if (mtr_policy == NULL) { |
| 715 | return -rte_mtr_error_set(error, EINVAL, |
| 716 | RTE_MTR_ERROR_TYPE_METER_POLICY_ID, |
| 717 | NULL, "Request meter policy not exist"); |
| 718 | } |
| 719 | |
| 720 | /* Meter param memory alloc */ |
| 721 | mtr = rte_zmalloc(NULL, sizeof(struct nfp_mtr), 0); |
| 722 | if (mtr == NULL) { |
| 723 | return -rte_mtr_error_set(error, ENOMEM, |
| 724 | RTE_MTR_ERROR_TYPE_UNSPECIFIED, |
| 725 | NULL, "Meter param alloc failed"); |
| 726 | } |
| 727 |
nothing calls this directly
no test coverage detected