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