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 union {
42 struct {
43 struct rte_mempool *mempool;
44 bool is_extmem;
45 }; /* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER */
46 uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
47 };
48 };
49
50 /* Parameters for IPC. */
51 struct mlx5_mp_param {
52 enum mlx5_mp_req_type type;
53 int port_id;
54 int result;
55 union {
56 struct mlx5_mp_arg_mr_manage mr_manage;
57 /* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER, MLX5_MP_REQ_CREATE_MR */
58 struct mlx5_mp_arg_queue_state_modify state_modify;
59 /* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
60 struct mlx5_mp_arg_queue_id queue_id;
61 /* MLX5_MP_REQ_QUEUE_RX/TX_START/STOP */
62 } args;
63 };
64
65 /* Identifier of a MP process */
66 struct mlx5_mp_id {
67 char name[RTE_MP_MAX_NAME_LEN];
68 uint16_t port_id;
69 };
70
71 /** Key string for IPC. */
72 #define MLX5_MP_NAME "common_mlx5_mp"
73
74 /** Initialize a multi-process ID. */
75 static inline void
mlx5_mp_id_init(struct mlx5_mp_id * mp_id,uint16_t port_id)76 mlx5_mp_id_init(struct mlx5_mp_id *mp_id, uint16_t port_id)
77 {
78 mp_id->port_id = port_id;
79 strlcpy(mp_id->name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
80 }
81
82 /** Request timeout for IPC. */
83 #define MLX5_MP_REQ_TIMEOUT_SEC 5
84
85 /**
86 * Initialize IPC message.
87 *
88 * @param[in] port_id
89 * Port ID of the device.
90 * @param[out] msg
91 * Pointer to message to fill in.
92 * @param[in] type
93 * Message type.
94 */
95 static inline void
mp_init_msg(struct mlx5_mp_id * mp_id,struct rte_mp_msg * msg,enum mlx5_mp_req_type type)96 mp_init_msg(struct mlx5_mp_id *mp_id, struct rte_mp_msg *msg,
97 enum mlx5_mp_req_type type)
98 {
99 struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
100
101 memset(msg, 0, sizeof(*msg));
102 strlcpy(msg->name, mp_id->name, sizeof(msg->name));
103 msg->len_param = sizeof(*param);
104 param->type = type;
105 param->port_id = mp_id->port_id;
106 }
107
108 /**
109 * Initialize IPC port-agnostic message.
110 *
111 * @param[out] msg
112 * Pointer to message to fill in.
113 * @param[in] type
114 * Message type.
115 */
116 static inline void
mp_init_port_agnostic_msg(struct rte_mp_msg * msg,enum mlx5_mp_req_type type)117 mp_init_port_agnostic_msg(struct rte_mp_msg *msg, enum mlx5_mp_req_type type)
118 {
119 struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
120
121 memset(msg, 0, sizeof(*msg));
122 strlcpy(msg->name, MLX5_MP_NAME, sizeof(msg->name));
123 msg->len_param = sizeof(*param);
124 param->type = type;
125 }
126
127 __rte_internal
128 int mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action);
129 __rte_internal
130 void mlx5_mp_uninit_primary(const char *name);
131 __rte_internal
132 int mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action);
133 __rte_internal
134 void mlx5_mp_uninit_secondary(const char *name);
135 __rte_internal
136 int mlx5_mp_req_mr_create(struct mlx5_common_device *cdev, uintptr_t addr);
137 __rte_internal
138 int mlx5_mp_req_mempool_reg(struct mlx5_common_device *cdev,
139 struct rte_mempool *mempool, bool reg,
140 bool is_extmem);
141 __rte_internal
142 int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
143 struct mlx5_mp_arg_queue_state_modify *sm);
144 __rte_internal
145 int mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id);
146
147 #endif /* RTE_PMD_MLX5_COMMON_MP_H_ */
148