e0646670a32cd8b5d6596132e35b381e12476c04
[dpdk.git] / drivers / net / mlx5 / windows / mlx5_os.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #include <errno.h>
6 #include <stdalign.h>
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10
11 #include <rte_windows.h>
12
13 #include <mlx5_glue.h>
14 #include <mlx5_devx_cmds.h>
15 #include <mlx5_common.h>
16
17 #include "mlx5_defs.h"
18 #include "mlx5.h"
19 #include "mlx5_autoconf.h"
20
21 /**
22  * Get mlx5 device attributes.
23  *
24  * @param ctx
25  *   Pointer to device context.
26  *
27  * @param device_attr
28  *   Pointer to mlx5 device attributes.
29  *
30  * @return
31  *   0 on success, non zero error number otherwise
32  */
33 int
34 mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr)
35 {
36         struct mlx5_context *mlx5_ctx;
37         struct mlx5_hca_attr hca_attr;
38         void *pv_iseg = NULL;
39         u32 cb_iseg = 0;
40         int err = 0;
41
42         if (!ctx)
43                 return -EINVAL;
44         mlx5_ctx = (struct mlx5_context *)ctx;
45         memset(device_attr, 0, sizeof(*device_attr));
46         err = mlx5_devx_cmd_query_hca_attr(mlx5_ctx, &hca_attr);
47         if (err) {
48                 DRV_LOG(ERR, "Failed to get device hca_cap");
49                 return err;
50         }
51         device_attr->max_cq = 1 << hca_attr.log_max_cq;
52         device_attr->max_qp = 1 << hca_attr.log_max_qp;
53         device_attr->max_qp_wr = 1 << hca_attr.log_max_qp_sz;
54         device_attr->max_cqe = 1 << hca_attr.log_max_cq_sz;
55         device_attr->max_mr = 1 << hca_attr.log_max_mrw_sz;
56         device_attr->max_pd = 1 << hca_attr.log_max_pd;
57         device_attr->max_srq = 1 << hca_attr.log_max_srq;
58         device_attr->max_srq_wr = 1 << hca_attr.log_max_srq_sz;
59         if (hca_attr.rss_ind_tbl_cap) {
60                 device_attr->max_rwq_indirection_table_size =
61                         1 << hca_attr.rss_ind_tbl_cap;
62         }
63         pv_iseg = mlx5_glue->query_hca_iseg(mlx5_ctx, &cb_iseg);
64         if (pv_iseg == NULL) {
65                 DRV_LOG(ERR, "Failed to get device hca_iseg");
66                 return errno;
67         }
68         if (!err) {
69                 snprintf(device_attr->fw_ver, 64, "%x.%x.%04x",
70                         MLX5_GET(initial_seg, pv_iseg, fw_rev_major),
71                         MLX5_GET(initial_seg, pv_iseg, fw_rev_minor),
72                         MLX5_GET(initial_seg, pv_iseg, fw_rev_subminor));
73         }
74         return err;
75 }