xref: /dpdk/drivers/common/mlx5/mlx5_common_mp.h (revision fb360c75062d71014c1bba90db64f493fb0ae9e2)
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_compat.h>
11 #include <rte_eal.h>
12 #include <rte_string_fns.h>
13 
14 /* Request types for IPC. */
15 enum mlx5_mp_req_type {
16 	MLX5_MP_REQ_VERBS_CMD_FD = 1,
17 	MLX5_MP_REQ_CREATE_MR,
18 	MLX5_MP_REQ_MEMPOOL_REGISTER,
19 	MLX5_MP_REQ_MEMPOOL_UNREGISTER,
20 	MLX5_MP_REQ_START_RXTX,
21 	MLX5_MP_REQ_STOP_RXTX,
22 	MLX5_MP_REQ_QUEUE_STATE_MODIFY,
23 	MLX5_MP_REQ_QUEUE_RX_STOP,
24 	MLX5_MP_REQ_QUEUE_RX_START,
25 	MLX5_MP_REQ_QUEUE_TX_STOP,
26 	MLX5_MP_REQ_QUEUE_TX_START,
27 };
28 
29 struct mlx5_mp_arg_queue_state_modify {
30 	uint8_t is_wq; /* Set if WQ. */
31 	uint16_t queue_id; /* DPDK queue ID. */
32 	enum ibv_wq_state state; /* WQ requested state. */
33 };
34 
35 struct mlx5_mp_arg_queue_id {
36 	uint16_t queue_id; /* DPDK queue ID. */
37 };
38 
39 struct mlx5_mp_arg_mr_manage {
40 	struct mlx5_common_device *cdev;
41 	RTE_STD_C11
42 	union {
43 		struct {
44 			struct rte_mempool *mempool;
45 			bool is_extmem;
46 		}; /* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER */
47 		uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
48 	};
49 };
50 
51 /* Parameters for IPC. */
52 struct mlx5_mp_param {
53 	enum mlx5_mp_req_type type;
54 	int port_id;
55 	int result;
56 	RTE_STD_C11
57 	union {
58 		struct mlx5_mp_arg_mr_manage mr_manage;
59 		/* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER, MLX5_MP_REQ_CREATE_MR */
60 		struct mlx5_mp_arg_queue_state_modify state_modify;
61 		/* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
62 		struct mlx5_mp_arg_queue_id queue_id;
63 		/* MLX5_MP_REQ_QUEUE_RX/TX_START/STOP */
64 	} args;
65 };
66 
67 /*  Identifier of a MP process */
68 struct mlx5_mp_id {
69 	char name[RTE_MP_MAX_NAME_LEN];
70 	uint16_t port_id;
71 };
72 
73 /** Key string for IPC. */
74 #define MLX5_MP_NAME "common_mlx5_mp"
75 
76 /** Initialize a multi-process ID. */
77 static inline void
78 mlx5_mp_id_init(struct mlx5_mp_id *mp_id, uint16_t port_id)
79 {
80 	mp_id->port_id = port_id;
81 	strlcpy(mp_id->name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
82 }
83 
84 /** Request timeout for IPC. */
85 #define MLX5_MP_REQ_TIMEOUT_SEC 5
86 
87 /**
88  * Initialize IPC message.
89  *
90  * @param[in] port_id
91  *   Port ID of the device.
92  * @param[out] msg
93  *   Pointer to message to fill in.
94  * @param[in] type
95  *   Message type.
96  */
97 static inline void
98 mp_init_msg(struct mlx5_mp_id *mp_id, struct rte_mp_msg *msg,
99 	    enum mlx5_mp_req_type type)
100 {
101 	struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
102 
103 	memset(msg, 0, sizeof(*msg));
104 	strlcpy(msg->name, mp_id->name, sizeof(msg->name));
105 	msg->len_param = sizeof(*param);
106 	param->type = type;
107 	param->port_id = mp_id->port_id;
108 }
109 
110 /**
111  * Initialize IPC port-agnostic message.
112  *
113  * @param[out] msg
114  *   Pointer to message to fill in.
115  * @param[in] type
116  *   Message type.
117  */
118 static inline void
119 mp_init_port_agnostic_msg(struct rte_mp_msg *msg, enum mlx5_mp_req_type type)
120 {
121 	struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
122 
123 	memset(msg, 0, sizeof(*msg));
124 	strlcpy(msg->name, MLX5_MP_NAME, sizeof(msg->name));
125 	msg->len_param = sizeof(*param);
126 	param->type = type;
127 }
128 
129 __rte_internal
130 int mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action);
131 __rte_internal
132 void mlx5_mp_uninit_primary(const char *name);
133 __rte_internal
134 int mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action);
135 __rte_internal
136 void mlx5_mp_uninit_secondary(const char *name);
137 __rte_internal
138 int mlx5_mp_req_mr_create(struct mlx5_common_device *cdev, uintptr_t addr);
139 __rte_internal
140 int mlx5_mp_req_mempool_reg(struct mlx5_common_device *cdev,
141 			    struct rte_mempool *mempool, bool reg,
142 			    bool is_extmem);
143 __rte_internal
144 int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
145 				   struct mlx5_mp_arg_queue_state_modify *sm);
146 __rte_internal
147 int mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id);
148 
149 #endif /* RTE_PMD_MLX5_COMMON_MP_H_ */
150