From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 30579A0A02; Tue, 27 Apr 2021 17:39:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 65BD541294; Tue, 27 Apr 2021 17:39:11 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2058.outbound.protection.outlook.com [40.107.94.58]) by mails.dpdk.org (Postfix) with ESMTP id 94E2D41260 for ; Tue, 27 Apr 2021 17:39:08 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VPdtw/7WkYSMFjAOdDceb4lZ9pl/TzNiPi92mYa7Kg20L8Qeonp9tERTtGh/0fCL0L+rxp01zstBcy2NosQBICmjRjsrU6B4SOwT1JI0Xxuo9Z9N2saXNPBwLU7FC1QEeLgUwEuoIqEY7r0EXYKwfmmBr69qMzkbM8JBThhmNNDoRWAkOPHKVDkyIeC8CueW4H6zfQyshQ754DGW1itZDKLGIavA0MkS0edfczobX85tcIG29nMJ4CaKyBn+Qvo2EcIidhx0VG1FkH4vf+omn/18brvXMHk+V2xAwDniOTLqeiQCofLMlllpvhNt775JVqde8XAYK17FGeJUriv7tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/KDmYONwBusmj4jN995KRSfUm9QqRA8xs5oF/Tln/0Q=; b=c/G8QPnKuJcQ2uZJvY1ZQNMIoVRRxAffFX7n15Isot7a3IHb9wZU3ItI/NGwwWXySH6pddo15igxnn1OBruIl80Umi1OLu8ezOY0/BgvLYqz1ddS12iuPzJbAufxL0CyY6qTF8gbkZTRcMzDgEAYUATAjtSoUbqr7uyHmwAY6Y0DsbMA9u/iODv3TPuPiuLT6gA3rkspbdxOWDrQS234qZbZcFtQYNfbXbTt3D4iYbAkAgNsl90mJG7xeIMvKhO3x/V4MN4vBZK+vMA0wesDUpVwOWsxLIRlrX6m0oIsDe13NL21lXgffEmUkkPf8mjOMLT23uvkgFvms1Tn90wV7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/KDmYONwBusmj4jN995KRSfUm9QqRA8xs5oF/Tln/0Q=; b=EClJZqIbzNuXL0UThKZO3nXEUjDT9ke9K/RD1S4/TGbEzcyoUkqnDlkjf1Z09odeF+9/a/2dbh2+oKmcl/gDb/jUfvSvKGqn4hsCe9Qt+eDZKTL+9OdOyTkckeQmXZh5Zl2CrYS+v682lVmEsCkZlklDBlhasDwDegts+sw3KtpKDG+BbtJD6KjEQWfZMP4lPiulRM98sTpno3SOLI1xvMsEcrzpe+6QOATeysLQXmQCbZRa5s0k1HOtJ6DWbnkVmf17jemMYv6vp25R3azKez5WZUlivLftSZqMSUfbdP1T0L4awgyAZNGMsTy4FGmBZKXQJGp1uRTzcZ9LOX1xpQ== Received: from MWHPR01CA0046.prod.exchangelabs.com (2603:10b6:300:101::32) by BYAPR12MB3335.namprd12.prod.outlook.com (2603:10b6:a03:dd::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Tue, 27 Apr 2021 15:39:07 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:300:101:cafe::2) by MWHPR01CA0046.outlook.office365.com (2603:10b6:300:101::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.25 via Frontend Transport; Tue, 27 Apr 2021 15:39:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Tue, 27 Apr 2021 15:39:06 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 27 Apr 2021 15:39:04 +0000 From: Bing Zhao To: , CC: , , Date: Tue, 27 Apr 2021 18:38:05 +0300 Message-ID: <20210427153811.11554-12-bingz@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210427153811.11554-1-bingz@nvidia.com> References: <20210427153811.11554-1-bingz@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7fe431f3-9cdc-489e-d73f-08d9099297f9 X-MS-TrafficTypeDiagnostic: BYAPR12MB3335: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X6UieBFCqCbp46yOgsj7lzDVaysPR24ZlpJfORFMYT6C1qJhX9tILX/lDcOqQpDBAIeH9fBFgp6gu4+gebMmJyaBV6Gf0vydXAgfdXX5fV3exzgp8x95+5AXj0SIDHOjTM47SaKIJnIXVDi/+chbnNoalyCQisIDAVMOAGRjDAC3w2l1JBmXoeluOTOx7i21vmI/FEm+5Lf64Fq3dn8x4SyH59YL0qn+QUAvW+E0UBY9i1Zva4SQhbZ2UNx7vyneLZ3adusmOyVFwR8QE2HzLaE0gV3HsWL245pRFEGO2lTUPOb7Vbax+jEtXvSNcHHKG3cuStThh9ZnM7ZsAbtQ5Sq35VJDnIOZp2vK8GqKgaMZOMtdLuicyeSUCks8cui3Q3rmDxqhvqimdDHEsmrWo5akjLsEID8E5OHhXIZUb+nuB2szsvRrWXseqHp/AdcMJ4l9eH1bCIZbmvcAghWnARuUJpV83d90SmKmv20RYIIkZ/5o/+1tEtQPkjUBNP3AwBwBaVZ8P2Z2yL2Q789tphiYOIRZ5ZgSHQFSOXKcj5FKjV5m593MLREdcEn25YKwmUl1ci7RHbYwW2ZEKJyWfk2Rx0MSiKxVTwlcA8XF6XHjlQKNdcQuQBrcKbm9WRPYroCD18LuDSQo20zNtXGGbW/dodxbQ7Wb5t7vSAoklz2HNR2j/2JaJQGHTSTFQ8Lc X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(136003)(346002)(396003)(39860400002)(46966006)(36840700001)(336012)(8676002)(54906003)(82310400003)(36756003)(47076005)(6286002)(36906005)(7636003)(316002)(5660300002)(110136005)(478600001)(70206006)(2616005)(83380400001)(6636002)(82740400003)(70586007)(8936002)(426003)(2906002)(107886003)(356005)(36860700001)(16526019)(55016002)(186003)(4326008)(26005)(7696005)(86362001)(1076003)(309714004); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2021 15:39:06.7755 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fe431f3-9cdc-489e-d73f-08d9099297f9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3335 Subject: [dpdk-dev] [PATCH 11/17] net/mlx5: add translation for CT action X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When creating a flow with this action context for CT, it needs to be translated in 2 levels. First, retrieve from action context to RTE_FLOW action. Second, translate it to the correct DR action with traffic direction. Before using the DR action in a flow, the CT context should be available to use in the hardware. Signed-off-by: Bing Zhao --- drivers/net/mlx5/mlx5.h | 3 ++- drivers/net/mlx5/mlx5_flow.c | 9 +++++++++ drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_aso.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_dv.c | 18 ++++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index f999828..3b67706 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1716,6 +1716,7 @@ int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh, int mlx5_aso_ct_query_by_wqe(struct mlx5_dev_ctx_shared *sh, struct mlx5_aso_ct_action *ct, struct rte_flow_action_conntrack *profile); - +int mlx5_aso_ct_available(struct mlx5_dev_ctx_shared *sh, + struct mlx5_aso_ct_action *ct); #endif /* RTE_PMD_MLX5_H_ */ diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 1c28b63..7b9f055 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -3552,6 +3552,15 @@ flow_action_handles_translate(struct rte_eth_dev *dev, break; } /* Fall-through */ + case MLX5_INDIRECT_ACTION_TYPE_CT: + if (priv->sh->ct_aso_en) { + translated[handle->index].type = + RTE_FLOW_ACTION_TYPE_CONNTRACK; + translated[handle->index].conf = + (void *)(uintptr_t)idx; + break; + } + /* Fall-through */ default: mlx5_free(translated); return rte_flow_error_set diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 988b171..ddfc517 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -226,6 +226,7 @@ enum mlx5_feature_name { #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38) #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39) #define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) +#define MLX5_FLOW_ACTION_CT (1ull << 41) #define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \ diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c index 12e8dc7..21de855 100644 --- a/drivers/net/mlx5/mlx5_flow_aso.c +++ b/drivers/net/mlx5/mlx5_flow_aso.c @@ -1394,3 +1394,43 @@ mlx5_aso_ct_query_by_wqe(struct mlx5_dev_ctx_shared *sh, mlx5_aso_ct_obj_analyze(profile, out_data); return ret; } + +/* + * Make sure the conntrack context is synchronized with hardware before + * creating a flow rule that uses it. + * + * @param[in] sh + * Pointer to shared device context. + * @param[in] ct + * Pointer to connection tracking offload object. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_aso_ct_available(struct mlx5_dev_ctx_shared *sh, + struct mlx5_aso_ct_action *ct) +{ + struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng; + uint32_t poll_cqe_times = MLX5_CT_POLL_WQE_CQE_TIMES; + uint8_t state = __atomic_load_n(&ct->state, __ATOMIC_RELAXED); + + if (state == ASO_CONNTRACK_FREE) { + rte_errno = ENXIO; + return -rte_errno; + } else if (state == ASO_CONNTRACK_READY || + state == ASO_CONNTRACK_QUERY) { + return 0; + } + do { + mlx5_aso_ct_completion_handle(mng); + state = __atomic_load_n(&ct->state, __ATOMIC_RELAXED); + if (state == ASO_CONNTRACK_READY || + state == ASO_CONNTRACK_QUERY) + return 0; + /* Waiting for CQE ready, consider should block or sleep. */ + rte_delay_us_sleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY); + } while (--poll_cqe_times); + rte_errno = EBUSY; + return -rte_errno; +} diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index f4fa3a0..3ebeb58 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -11373,6 +11373,7 @@ flow_dv_translate_create_conntrack(struct rte_eth_dev *dev, return rte_flow_error_set(error, EBUSY, RTE_FLOW_ERROR_TYPE_ACTION, NULL, "Failed to update CT"); + ct->is_original = !!pro->is_original_dir; return idx; } @@ -11529,6 +11530,8 @@ flow_dv_translate(struct rte_eth_dev *dev, const struct rte_flow_action *found_action = NULL; uint32_t jump_group = 0; struct mlx5_flow_counter *cnt; + uint32_t ct_idx; + struct mlx5_aso_ct_action *ct; if (!mlx5_flow_os_action_supported(action_type)) return rte_flow_error_set(error, ENOTSUP, @@ -12002,6 +12005,21 @@ flow_dv_translate(struct rte_eth_dev *dev, return -rte_errno; action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD; break; + case RTE_FLOW_ACTION_TYPE_CONNTRACK: + ct_idx = (uint32_t)(uintptr_t)action->conf; + ct = flow_aso_ct_get_by_idx(dev, ct_idx); + if (mlx5_aso_ct_available(priv->sh, ct)) + return -rte_errno; + if (ct->is_original) + dev_flow->dv.actions[actions_n] = + ct->dr_action_orig; + else + dev_flow->dv.actions[actions_n] = + ct->dr_action_rply; + __atomic_fetch_add(&ct->refcnt, 1, __ATOMIC_RELAXED); + actions_n++; + action_flags |= MLX5_FLOW_ACTION_CT; + break; case RTE_FLOW_ACTION_TYPE_END: actions_end = true; if (mhdr_res->actions_num) { -- 2.5.5