64260c06028dc23da54291778f095cdf13adf097
[dpdk.git] / drivers / common / mlx5 / mlx5_common_mp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 6WIND S.A.
3  * Copyright 2018 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_PMD_MLX5_COMMON_MP_H_
7 #define RTE_PMD_MLX5_COMMON_MP_H_
8
9 #include <mlx5_glue.h>
10 #include <rte_eal.h>
11 #include <rte_string_fns.h>
12
13 /* Request types for IPC. */
14 enum mlx5_mp_req_type {
15         MLX5_MP_REQ_VERBS_CMD_FD = 1,
16         MLX5_MP_REQ_CREATE_MR,
17         MLX5_MP_REQ_START_RXTX,
18         MLX5_MP_REQ_STOP_RXTX,
19         MLX5_MP_REQ_QUEUE_STATE_MODIFY,
20 };
21
22 struct mlx5_mp_arg_queue_state_modify {
23         uint8_t is_wq; /* Set if WQ. */
24         uint16_t queue_id; /* DPDK queue ID. */
25         enum ibv_wq_state state; /* WQ requested state. */
26 };
27
28 /* Pameters for IPC. */
29 struct mlx5_mp_param {
30         enum mlx5_mp_req_type type;
31         int port_id;
32         int result;
33         RTE_STD_C11
34         union {
35                 uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
36                 struct mlx5_mp_arg_queue_state_modify state_modify;
37                 /* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
38         } args;
39 };
40
41 /*  Identifier of a MP process */
42 struct mlx5_mp_id {
43         char name[RTE_MP_MAX_NAME_LEN];
44         uint16_t port_id;
45 };
46
47 /** Request timeout for IPC. */
48 #define MLX5_MP_REQ_TIMEOUT_SEC 5
49
50 /**
51  * Initialize IPC message.
52  *
53  * @param[in] port_id
54  *   Port ID of the device.
55  * @param[out] msg
56  *   Pointer to message to fill in.
57  * @param[in] type
58  *   Message type.
59  */
60 static inline void
61 mp_init_msg(struct mlx5_mp_id *mp_id, struct rte_mp_msg *msg,
62             enum mlx5_mp_req_type type)
63 {
64         struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
65
66         memset(msg, 0, sizeof(*msg));
67         strlcpy(msg->name, mp_id->name, sizeof(msg->name));
68         msg->len_param = sizeof(*param);
69         param->type = type;
70         param->port_id = mp_id->port_id;
71 }
72
73 __rte_internal
74 int mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action);
75 __rte_internal
76 void mlx5_mp_uninit_primary(const char *name);
77 __rte_internal
78 int mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action);
79 __rte_internal
80 void mlx5_mp_uninit_secondary(const char *name);
81 __rte_internal
82 int mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr);
83 __rte_internal
84 int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
85                                    struct mlx5_mp_arg_queue_state_modify *sm);
86 __rte_internal
87 int mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id);
88
89 #endif /* RTE_PMD_MLX5_COMMON_MP_H_ */