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 MLX5_MP_REQ_QUEUE_RX_STOP,
21 MLX5_MP_REQ_QUEUE_RX_START,
22 MLX5_MP_REQ_QUEUE_TX_STOP,
23 MLX5_MP_REQ_QUEUE_TX_START,
24 };
25
26 struct mlx5_mp_arg_queue_state_modify {
27 uint8_t is_wq; /* Set if WQ. */
28 uint16_t queue_id; /* DPDK queue ID. */
29 enum ibv_wq_state state; /* WQ requested state. */
30 };
31
32 struct mlx5_mp_arg_queue_id {
33 uint16_t queue_id; /* DPDK queue ID. */
34 };
35
36 /* Pameters for IPC. */
37 struct mlx5_mp_param {
38 enum mlx5_mp_req_type type;
39 int port_id;
40 int result;
41 RTE_STD_C11
42 union {
43 uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
44 struct mlx5_mp_arg_queue_state_modify state_modify;
45 /* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
46 struct mlx5_mp_arg_queue_id queue_id;
47 /* MLX5_MP_REQ_QUEUE_RX/TX_START/STOP */
48 } args;
49 };
50
51 /* Identifier of a MP process */
52 struct mlx5_mp_id {
53 char name[RTE_MP_MAX_NAME_LEN];
54 uint16_t port_id;
55 };
56
57 /** Request timeout for IPC. */
58 #define MLX5_MP_REQ_TIMEOUT_SEC 5
59
60 /**
61 * Initialize IPC message.
62 *
63 * @param[in] port_id
64 * Port ID of the device.
65 * @param[out] msg
66 * Pointer to message to fill in.
67 * @param[in] type
68 * Message type.
69 */
70 static inline void
mp_init_msg(struct mlx5_mp_id * mp_id,struct rte_mp_msg * msg,enum mlx5_mp_req_type type)71 mp_init_msg(struct mlx5_mp_id *mp_id, struct rte_mp_msg *msg,
72 enum mlx5_mp_req_type type)
73 {
74 struct mlx5_mp_param *param = (struct mlx5_mp_param *)msg->param;
75
76 memset(msg, 0, sizeof(*msg));
77 strlcpy(msg->name, mp_id->name, sizeof(msg->name));
78 msg->len_param = sizeof(*param);
79 param->type = type;
80 param->port_id = mp_id->port_id;
81 }
82
83 __rte_internal
84 int mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action);
85 __rte_internal
86 void mlx5_mp_uninit_primary(const char *name);
87 __rte_internal
88 int mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action);
89 __rte_internal
90 void mlx5_mp_uninit_secondary(const char *name);
91 __rte_internal
92 int mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr);
93 __rte_internal
94 int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
95 struct mlx5_mp_arg_queue_state_modify *sm);
96 __rte_internal
97 int mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id);
98
99 #endif /* RTE_PMD_MLX5_COMMON_MP_H_ */
100