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 7E3BBA034F; Fri, 8 Oct 2021 12:58:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3AEC411F3; Fri, 8 Oct 2021 12:56:34 +0200 (CEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 42FB5411E0 for ; Thu, 7 Oct 2021 20:45:44 +0200 (CEST) Received: by mail-pg1-f171.google.com with SMTP id s75so654753pgs.5 for ; Thu, 07 Oct 2021 11:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bvXw9srbEcSwqNdCiOug/Djjidp5l/z4oRCLDfhT8pY=; b=OC2Oqd/5/+jBDEsEBHXAdp/M6YYEzEsrwgJyfqsUqLuFYnzsk+RJH4+8F4dYsjS4DC e9tJi0kCx/RRLx7s2pbK73OQz/wl1XQf+BKBViQFGpkzo34gi+p2C5FWvetbAvG713NU 3+c/whkxiD3N0PIlp+7H0X0Nd0gaGsJGIQw6Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bvXw9srbEcSwqNdCiOug/Djjidp5l/z4oRCLDfhT8pY=; b=eNxlGFIWdcI0Eu0gsPa/fCrmLbslSL8vLPw0Ck9oHNJSodZ9sBkwj+WdnOP4lc5a0d lxzU1XUSWXqzPG++4AQgnBsaY4/d5TC3g6TiyYWWCJux08nhrKulZyy0otnTPH7rh/It 74LV086HChy5A+QKX+zQ915ojmOLM8gFS8QQXTHuYA3tYlF8xpfTdc2uU6ZP19A51RFA dNlrrNN9Hn1xk9oGVoNaCtjgo/1EejFf/7y2tNMxuiP52KOj4mHZlK+aRv/mEA2j4EHz torxpHb/4jm+h1ldjsqyTArdQKbvVsIkMPo3uwtvj1RGifScM7AV1S/J09UhzY8fqCV8 r4dw== X-Gm-Message-State: AOAM530aMBOf+7tN0hYqbV+39bgkrzV5wNevu8Q2WkCN7hwPK/dAS3gy kkQJEZkgvCxEZaMBBh3BuIvOiw== X-Google-Smtp-Source: ABdhPJyhzDmIc1qAaEt8+Pi1Y6dHhQNbg/S2XwzcTab5T88cYX7TKX3Etu0U4mP5kJOJIjV4DUO6wg== X-Received: by 2002:a05:6a00:14c2:b0:44c:d483:4df3 with SMTP id w2-20020a056a0014c200b0044cd4834df3mr849476pfu.52.1633632343430; Thu, 07 Oct 2021 11:45:43 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([136.185.113.102]) by smtp.gmail.com with ESMTPSA id c11sm3311586pji.38.2021.10.07.11.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:45:42 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Fri, 8 Oct 2021 00:13:42 +0530 Message-Id: <20211007184350.73858-34-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com> References: <20211007184350.73858-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 08 Oct 2021 12:55:54 +0200 Subject: [dpdk-dev] [PATCH v2 33/41] net/mlx5: add initialization routines 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" The mlx5_init_once() and mlx5_init_shared_data() are equivalent to their Linux counterparts Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/net/mlx5/freebsd/mlx5_os.c | 139 +++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/drivers/net/mlx5/freebsd/mlx5_os.c b/drivers/net/mlx5/freebsd/mlx5_os.c index 9a7c7e4b95..389b45b694 100644 --- a/drivers/net/mlx5/freebsd/mlx5_os.c +++ b/drivers/net/mlx5/freebsd/mlx5_os.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -32,6 +34,14 @@ #include "mlx5_inet.h" #include "mlx5_devx.h" +static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data"; + +/* Spinlock for mlx5_shared_data allocation. */ +static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER; + +/* Process local data for secondary processes. */ +static struct mlx5_local_data mlx5_local_data; + /** * Get mlx5 device attributes. The glue function query_device_ex() is called * with out parameter of type 'struct ibv_device_attr_ex *'. Then fill in mlx5 @@ -150,6 +160,135 @@ mlx5_free_verbs_buf(void *ptr, void *data __rte_unused) mlx5_free(ptr); } +/** + * Initialize shared data between primary and secondary process. + * + * A memzone is reserved by primary process and secondary processes attach to + * the memzone. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_init_shared_data(void) +{ + const struct rte_memzone *mz; + int ret = 0; + + rte_spinlock_lock(&mlx5_shared_data_lock); + if (mlx5_shared_data == NULL) { + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* Allocate shared memory. */ + mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA, + sizeof(*mlx5_shared_data), + SOCKET_ID_ANY, 0); + if (mz == NULL) { + DRV_LOG(ERR, + "Cannot allocate mlx5 shared data"); + ret = -rte_errno; + goto error; + } + mlx5_shared_data = mz->addr; + memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data)); + rte_spinlock_init(&mlx5_shared_data->lock); + } else { + /* Lookup allocated shared memory. */ + mz = rte_memzone_lookup(MZ_MLX5_PMD_SHARED_DATA); + if (mz == NULL) { + DRV_LOG(ERR, + "Cannot attach mlx5 shared data"); + ret = -rte_errno; + goto error; + } + mlx5_shared_data = mz->addr; + memset(&mlx5_local_data, 0, sizeof(mlx5_local_data)); + } + } +error: + rte_spinlock_unlock(&mlx5_shared_data_lock); + return ret; +} + +/** + * PMD global initialization. + * + * Independent from individual device, this function initializes global + * per-PMD data structures distinguishing primary and secondary processes. + * Hence, each initialization is called once per a process. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_init_once(void) +{ + struct mlx5_shared_data *sd; + struct mlx5_local_data *ld = &mlx5_local_data; + int ret = 0; + + if (mlx5_init_shared_data()) + return -rte_errno; + sd = mlx5_shared_data; + MLX5_ASSERT(sd); + rte_spinlock_lock(&sd->lock); + switch (rte_eal_process_type()) { + case RTE_PROC_PRIMARY: + if (sd->init_done) + break; + LIST_INIT(&sd->mem_event_cb_list); + rte_rwlock_init(&sd->mem_event_rwlock); + rte_mem_event_callback_register("MLX5_MEM_EVENT_CB", + mlx5_mr_mem_event_cb, NULL); + ret = mlx5_mp_init_primary(MLX5_MP_NAME, + mlx5_mp_os_primary_handle); + if (ret) + goto out; + sd->init_done = true; + break; + case RTE_PROC_SECONDARY: + if (ld->init_done) + break; + ret = mlx5_mp_init_secondary(MLX5_MP_NAME, + mlx5_mp_os_secondary_handle); + if (ret) + goto out; + ++sd->secondary_cnt; + ld->init_done = true; + break; + default: + break; + } +out: + rte_spinlock_unlock(&sd->lock); + return ret; +} + +/** + * Net class driver callback to probe a device. + * + * This function probe PCI bus device(s) + * + * @param[in] dev + * Pointer to the generic device. + * + * @return + * 0 on success, the function cannot fail. + */ +int +mlx5_os_net_probe(struct rte_device *dev) +{ + int ret; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + mlx5_pmd_socket_init(); + ret = mlx5_init_once(); + if (ret) { + DRV_LOG(ERR, "unable to init PMD global data: %s", + strerror(rte_errno)); + return -rte_errno; + } +} + static int mlx5_config_doorbell_mapping_env(const struct mlx5_dev_config *config) { -- 2.30.2