xref: /dpdk/drivers/common/mlx5/mlx5_common_mp.h (revision 971d2b57972919527e27ed683032a71864a2eb56)
1a4de9586SVu Pham /* SPDX-License-Identifier: BSD-3-Clause
2a4de9586SVu Pham  * Copyright 2018 6WIND S.A.
3a4de9586SVu Pham  * Copyright 2018 Mellanox Technologies, Ltd
4a4de9586SVu Pham  */
5a4de9586SVu Pham 
6a4de9586SVu Pham #ifndef RTE_PMD_MLX5_COMMON_MP_H_
7a4de9586SVu Pham #define RTE_PMD_MLX5_COMMON_MP_H_
8a4de9586SVu Pham 
99d60f545SOphir Munk #include <mlx5_glue.h>
10*1094dd94SDavid Marchand #include <rte_compat.h>
11a4de9586SVu Pham #include <rte_eal.h>
12a4de9586SVu Pham #include <rte_string_fns.h>
13a4de9586SVu Pham 
14a4de9586SVu Pham /* Request types for IPC. */
15a4de9586SVu Pham enum mlx5_mp_req_type {
16a4de9586SVu Pham 	MLX5_MP_REQ_VERBS_CMD_FD = 1,
17a4de9586SVu Pham 	MLX5_MP_REQ_CREATE_MR,
18690b2a88SDmitry Kozlyuk 	MLX5_MP_REQ_MEMPOOL_REGISTER,
19690b2a88SDmitry Kozlyuk 	MLX5_MP_REQ_MEMPOOL_UNREGISTER,
20a4de9586SVu Pham 	MLX5_MP_REQ_START_RXTX,
21a4de9586SVu Pham 	MLX5_MP_REQ_STOP_RXTX,
22a4de9586SVu Pham 	MLX5_MP_REQ_QUEUE_STATE_MODIFY,
23161d103bSViacheslav Ovsiienko 	MLX5_MP_REQ_QUEUE_RX_STOP,
24161d103bSViacheslav Ovsiienko 	MLX5_MP_REQ_QUEUE_RX_START,
25161d103bSViacheslav Ovsiienko 	MLX5_MP_REQ_QUEUE_TX_STOP,
26161d103bSViacheslav Ovsiienko 	MLX5_MP_REQ_QUEUE_TX_START,
27a4de9586SVu Pham };
28a4de9586SVu Pham 
29a4de9586SVu Pham struct mlx5_mp_arg_queue_state_modify {
30a4de9586SVu Pham 	uint8_t is_wq; /* Set if WQ. */
31a4de9586SVu Pham 	uint16_t queue_id; /* DPDK queue ID. */
32a4de9586SVu Pham 	enum ibv_wq_state state; /* WQ requested state. */
33a4de9586SVu Pham };
34a4de9586SVu Pham 
35161d103bSViacheslav Ovsiienko struct mlx5_mp_arg_queue_id {
36161d103bSViacheslav Ovsiienko 	uint16_t queue_id; /* DPDK queue ID. */
37161d103bSViacheslav Ovsiienko };
38161d103bSViacheslav Ovsiienko 
3920489176SMichael Baum struct mlx5_mp_arg_mr_manage {
4020489176SMichael Baum 	struct mlx5_common_device *cdev;
4120489176SMichael Baum 	union {
4208ac0358SDmitry Kozlyuk 		struct {
43690b2a88SDmitry Kozlyuk 			struct rte_mempool *mempool;
4408ac0358SDmitry Kozlyuk 			bool is_extmem;
4508ac0358SDmitry Kozlyuk 		}; /* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER */
4620489176SMichael Baum 		uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
4720489176SMichael Baum 	};
48690b2a88SDmitry Kozlyuk };
49690b2a88SDmitry Kozlyuk 
5020489176SMichael Baum /* Parameters for IPC. */
51a4de9586SVu Pham struct mlx5_mp_param {
52a4de9586SVu Pham 	enum mlx5_mp_req_type type;
53a4de9586SVu Pham 	int port_id;
54a4de9586SVu Pham 	int result;
55a4de9586SVu Pham 	union {
5620489176SMichael Baum 		struct mlx5_mp_arg_mr_manage mr_manage;
5720489176SMichael Baum 		/* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER, MLX5_MP_REQ_CREATE_MR */
58a4de9586SVu Pham 		struct mlx5_mp_arg_queue_state_modify state_modify;
59a4de9586SVu Pham 		/* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
60161d103bSViacheslav Ovsiienko 		struct mlx5_mp_arg_queue_id queue_id;
61161d103bSViacheslav Ovsiienko 		/* MLX5_MP_REQ_QUEUE_RX/TX_START/STOP */
62a4de9586SVu Pham 	} args;
63a4de9586SVu Pham };
64a4de9586SVu Pham 
65a4de9586SVu Pham /*  Identifier of a MP process */
66a4de9586SVu Pham struct mlx5_mp_id {
67a4de9586SVu Pham 	char name[RTE_MP_MAX_NAME_LEN];
68a4de9586SVu Pham 	uint16_t port_id;
69a4de9586SVu Pham };
70a4de9586SVu Pham 
71fc59a1ecSMichael Baum /** Key string for IPC. */
72fc59a1ecSMichael Baum #define MLX5_MP_NAME "common_mlx5_mp"
73fc59a1ecSMichael Baum 
74fc59a1ecSMichael Baum /** Initialize a multi-process ID. */
75fc59a1ecSMichael Baum static inline void
mlx5_mp_id_init(struct mlx5_mp_id * mp_id,uint16_t port_id)76fc59a1ecSMichael Baum mlx5_mp_id_init(struct mlx5_mp_id *mp_id, uint16_t port_id)
77fc59a1ecSMichael Baum {
78fc59a1ecSMichael Baum 	mp_id->port_id = port_id;
79fc59a1ecSMichael Baum 	strlcpy(mp_id->name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
80fc59a1ecSMichael Baum }
81fc59a1ecSMichael Baum 
82a4de9586SVu Pham /** Request timeout for IPC. */
83a4de9586SVu Pham #define MLX5_MP_REQ_TIMEOUT_SEC 5
84a4de9586SVu Pham 
85a4de9586SVu Pham /**
86a4de9586SVu Pham  * Initialize IPC message.
87a4de9586SVu Pham  *
88a4de9586SVu Pham  * @param[in] port_id
89a4de9586SVu Pham  *   Port ID of the device.
90a4de9586SVu Pham  * @param[out] msg
91a4de9586SVu Pham  *   Pointer to message to fill in.
92a4de9586SVu Pham  * @param[in] type
93a4de9586SVu Pham  *   Message type.
94a4de9586SVu Pham  */
95a4de9586SVu Pham static inline void
mp_init_msg(struct mlx5_mp_id * mp_id,struct rte_mp_msg * msg,enum mlx5_mp_req_type type)96a4de9586SVu Pham mp_init_msg(struct mlx5_mp_id *mp_id, struct rte_mp_msg *msg,
97a4de9586SVu Pham 	    enum mlx5_mp_req_type type)
98a4de9586SVu Pham {
99a4de9586SVu Pham 	struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
100a4de9586SVu Pham 
101a4de9586SVu Pham 	memset(msg, 0, sizeof(*msg));
102a4de9586SVu Pham 	strlcpy(msg->name, mp_id->name, sizeof(msg->name));
103a4de9586SVu Pham 	msg->len_param = sizeof(*param);
104a4de9586SVu Pham 	param->type = type;
105a4de9586SVu Pham 	param->port_id = mp_id->port_id;
106a4de9586SVu Pham }
107a4de9586SVu Pham 
10820489176SMichael Baum /**
10920489176SMichael Baum  * Initialize IPC port-agnostic message.
11020489176SMichael Baum  *
11120489176SMichael Baum  * @param[out] msg
11220489176SMichael Baum  *   Pointer to message to fill in.
11320489176SMichael Baum  * @param[in] type
11420489176SMichael Baum  *   Message type.
11520489176SMichael Baum  */
11620489176SMichael Baum static inline void
mp_init_port_agnostic_msg(struct rte_mp_msg * msg,enum mlx5_mp_req_type type)11720489176SMichael Baum mp_init_port_agnostic_msg(struct rte_mp_msg *msg, enum mlx5_mp_req_type type)
11820489176SMichael Baum {
11920489176SMichael Baum 	struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
12020489176SMichael Baum 
12120489176SMichael Baum 	memset(msg, 0, sizeof(*msg));
12220489176SMichael Baum 	strlcpy(msg->name, MLX5_MP_NAME, sizeof(msg->name));
12320489176SMichael Baum 	msg->len_param = sizeof(*param);
12420489176SMichael Baum 	param->type = type;
12520489176SMichael Baum }
12620489176SMichael Baum 
12764c563f8SOphir Munk __rte_internal
128a4de9586SVu Pham int mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action);
12964c563f8SOphir Munk __rte_internal
130a4de9586SVu Pham void mlx5_mp_uninit_primary(const char *name);
13164c563f8SOphir Munk __rte_internal
132a4de9586SVu Pham int mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action);
13364c563f8SOphir Munk __rte_internal
134a4de9586SVu Pham void mlx5_mp_uninit_secondary(const char *name);
13564c563f8SOphir Munk __rte_internal
13620489176SMichael Baum int mlx5_mp_req_mr_create(struct mlx5_common_device *cdev, uintptr_t addr);
13764c563f8SOphir Munk __rte_internal
13820489176SMichael Baum int mlx5_mp_req_mempool_reg(struct mlx5_common_device *cdev,
13908ac0358SDmitry Kozlyuk 			    struct rte_mempool *mempool, bool reg,
14008ac0358SDmitry Kozlyuk 			    bool is_extmem);
141690b2a88SDmitry Kozlyuk __rte_internal
142a4de9586SVu Pham int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
143a4de9586SVu Pham 				   struct mlx5_mp_arg_queue_state_modify *sm);
14464c563f8SOphir Munk __rte_internal
145a4de9586SVu Pham int mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id);
146a4de9586SVu Pham 
147a4de9586SVu Pham #endif /* RTE_PMD_MLX5_COMMON_MP_H_ */
148