xref: /dpdk/drivers/common/mlx5/mlx5_common_mp.h (revision e11bdd37745229bf26b557305c07d118c3dbaad7)
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 /* Verbs header. */
10 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
11 #ifdef PEDANTIC
12 #pragma GCC diagnostic ignored "-Wpedantic"
13 #endif
14 #include <infiniband/verbs.h>
15 #ifdef PEDANTIC
16 #pragma GCC diagnostic error "-Wpedantic"
17 #endif
18 
19 #include <rte_eal.h>
20 #include <rte_string_fns.h>
21 
22 /* Request types for IPC. */
23 enum mlx5_mp_req_type {
24 	MLX5_MP_REQ_VERBS_CMD_FD = 1,
25 	MLX5_MP_REQ_CREATE_MR,
26 	MLX5_MP_REQ_START_RXTX,
27 	MLX5_MP_REQ_STOP_RXTX,
28 	MLX5_MP_REQ_QUEUE_STATE_MODIFY,
29 };
30 
31 struct mlx5_mp_arg_queue_state_modify {
32 	uint8_t is_wq; /* Set if WQ. */
33 	uint16_t queue_id; /* DPDK queue ID. */
34 	enum ibv_wq_state state; /* WQ requested state. */
35 };
36 
37 /* Pameters for IPC. */
38 struct mlx5_mp_param {
39 	enum mlx5_mp_req_type type;
40 	int port_id;
41 	int result;
42 	RTE_STD_C11
43 	union {
44 		uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
45 		struct mlx5_mp_arg_queue_state_modify state_modify;
46 		/* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
47 	} args;
48 };
49 
50 /*  Identifier of a MP process */
51 struct mlx5_mp_id {
52 	char name[RTE_MP_MAX_NAME_LEN];
53 	uint16_t port_id;
54 };
55 
56 /** Request timeout for IPC. */
57 #define MLX5_MP_REQ_TIMEOUT_SEC 5
58 
59 /**
60  * Initialize IPC message.
61  *
62  * @param[in] port_id
63  *   Port ID of the device.
64  * @param[out] msg
65  *   Pointer to message to fill in.
66  * @param[in] type
67  *   Message type.
68  */
69 static inline void
70 mp_init_msg(struct mlx5_mp_id *mp_id, struct rte_mp_msg *msg,
71 	    enum mlx5_mp_req_type type)
72 {
73 	struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
74 
75 	memset(msg, 0, sizeof(*msg));
76 	strlcpy(msg->name, mp_id->name, sizeof(msg->name));
77 	msg->len_param = sizeof(*param);
78 	param->type = type;
79 	param->port_id = mp_id->port_id;
80 }
81 
82 __rte_experimental
83 int mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action);
84 __rte_experimental
85 void mlx5_mp_uninit_primary(const char *name);
86 __rte_experimental
87 int mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action);
88 __rte_experimental
89 void mlx5_mp_uninit_secondary(const char *name);
90 __rte_experimental
91 int mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr);
92 __rte_experimental
93 int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
94 				   struct mlx5_mp_arg_queue_state_modify *sm);
95 __rte_experimental
96 int mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id);
97 
98 #endif /* RTE_PMD_MLX5_COMMON_MP_H_ */
99