1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2020 Mellanox Technologies, Ltd 3 */ 4 #include <stdio.h> 5 6 #include <rte_errno.h> 7 #include <rte_ether.h> 8 #include <rte_ethdev_driver.h> 9 #include <rte_interrupts.h> 10 11 #include <mlx5_glue.h> 12 #include <mlx5_devx_cmds.h> 13 #include <mlx5_common.h> 14 #include <mlx5_win_ext.h> 15 #include <mlx5_malloc.h> 16 #include <mlx5.h> 17 #include <mlx5_utils.h> 18 19 /** 20 * Get MAC address by querying netdevice. 21 * 22 * @param[in] dev 23 * Pointer to Ethernet device. 24 * @param[out] mac 25 * MAC address output buffer. 26 * 27 * @return 28 * 0 on success, a negative errno value otherwise and rte_errno is set. 29 */ 30 int 31 mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]) 32 { 33 struct mlx5_priv *priv; 34 mlx5_context_st *context_obj; 35 36 if (!dev) { 37 rte_errno = EINVAL; 38 return -rte_errno; 39 } 40 priv = dev->data->dev_private; 41 context_obj = (mlx5_context_st *)priv->sh->ctx; 42 memcpy(mac, context_obj->mlx5_dev.eth_mac, RTE_ETHER_ADDR_LEN); 43 return 0; 44 } 45 46 /** 47 * Set device MTU. 48 * 49 * @param dev 50 * Pointer to Ethernet device. 51 * @param mtu 52 * MTU value to set. 53 * 54 * @return 55 * 0 on success, a negative errno value otherwise and rte_errno is set. 56 */ 57 int 58 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) 59 { 60 RTE_SET_USED(dev); 61 RTE_SET_USED(mtu); 62 return -ENOTSUP; 63 } 64 65 /* 66 * Unregister callback handler safely. The handler may be active 67 * while we are trying to unregister it, in this case code -EAGAIN 68 * is returned by rte_intr_callback_unregister(). This routine checks 69 * the return code and tries to unregister handler again. 70 * 71 * @param handle 72 * interrupt handle 73 * @param cb_fn 74 * pointer to callback routine 75 * @cb_arg 76 * opaque callback parameter 77 */ 78 void 79 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle, 80 rte_intr_callback_fn cb_fn, void *cb_arg) 81 { 82 RTE_SET_USED(handle); 83 RTE_SET_USED(cb_fn); 84 RTE_SET_USED(cb_arg); 85 } 86 87 /** 88 * DPDK callback to get flow control status. 89 * 90 * @param dev 91 * Pointer to Ethernet device structure. 92 * @param[out] fc_conf 93 * Flow control output buffer. 94 * 95 * @return 96 * 0 on success, a negative errno value otherwise and rte_errno is set. 97 */ 98 int 99 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 100 { 101 RTE_SET_USED(dev); 102 RTE_SET_USED(fc_conf); 103 return -ENOTSUP; 104 } 105 106 /** 107 * DPDK callback to modify flow control parameters. 108 * 109 * @param dev 110 * Pointer to Ethernet device structure. 111 * @param[in] fc_conf 112 * Flow control parameters. 113 * 114 * @return 115 * 0 on success, a negative errno value otherwise and rte_errno is set. 116 */ 117 int 118 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 119 { 120 RTE_SET_USED(dev); 121 RTE_SET_USED(fc_conf); 122 return -ENOTSUP; 123 } 124 125 /** 126 * Query the number of statistics provided by ETHTOOL. 127 * 128 * @param dev 129 * Pointer to Ethernet device. 130 * 131 * @return 132 * Number of statistics on success, negative errno value otherwise and 133 * rte_errno is set. 134 */ 135 int 136 mlx5_os_get_stats_n(struct rte_eth_dev *dev) 137 { 138 RTE_SET_USED(dev); 139 return -ENOTSUP; 140 } 141 142 /** 143 * Init the structures to read device counters. 144 * 145 * @param dev 146 * Pointer to Ethernet device. 147 */ 148 void 149 mlx5_os_stats_init(struct rte_eth_dev *dev) 150 { 151 RTE_SET_USED(dev); 152 } 153 154 /** 155 * Read device counters table. 156 * 157 * @param dev 158 * Pointer to Ethernet device. 159 * @param[out] stats 160 * Counters table output buffer. 161 * 162 * @return 163 * 0 on success and stats is filled, negative errno value otherwise and 164 * rte_errno is set. 165 */ 166 int 167 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats) 168 { 169 RTE_SET_USED(dev); 170 RTE_SET_USED(stats); 171 return -ENOTSUP; 172 } 173 174 /** 175 * DPDK callback to retrieve physical link information. 176 * 177 * @param dev 178 * Pointer to Ethernet device structure. 179 * @param wait_to_complete 180 * Wait for request completion. 181 * 182 * @return 183 * 0 if link status was not updated, positive if it was, a negative errno 184 * value otherwise and rte_errno is set. 185 */ 186 int 187 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete) 188 { 189 RTE_SET_USED(wait_to_complete); 190 struct mlx5_priv *priv; 191 mlx5_context_st *context_obj; 192 struct rte_eth_link dev_link; 193 int ret; 194 195 ret = 0; 196 if (!dev) { 197 rte_errno = EINVAL; 198 return -rte_errno; 199 } 200 priv = dev->data->dev_private; 201 context_obj = (mlx5_context_st *)priv->sh->ctx; 202 dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1024 * 1024); 203 dev_link.link_status = 204 (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev)) 205 ? 1 : 0; 206 dev_link.link_duplex = 1; 207 if (dev->data->dev_link.link_speed != dev_link.link_speed || 208 dev->data->dev_link.link_duplex != dev_link.link_duplex || 209 dev->data->dev_link.link_autoneg != dev_link.link_autoneg || 210 dev->data->dev_link.link_status != dev_link.link_status) 211 ret = 1; 212 else 213 ret = 0; 214 dev->data->dev_link = dev_link; 215 return ret; 216 } 217 218 /** 219 * DPDK callback to bring the link DOWN. 220 * 221 * @param dev 222 * Pointer to Ethernet device structure. 223 * 224 * @return 225 * 0 on success, a negative errno value otherwise 226 */ 227 int 228 mlx5_set_link_down(struct rte_eth_dev *dev) 229 { 230 RTE_SET_USED(dev); 231 return -ENOTSUP; 232 } 233 234 /** 235 * DPDK callback to bring the link UP. 236 * 237 * @param dev 238 * Pointer to Ethernet device structure. 239 * 240 * @return 241 * 0 on success, a negative errno value otherwise 242 */ 243 int 244 mlx5_set_link_up(struct rte_eth_dev *dev) 245 { 246 RTE_SET_USED(dev); 247 return -ENOTSUP; 248 } 249 250 /** 251 * DPDK callback to retrieve plug-in module EEPROM information (type and size). 252 * 253 * @param dev 254 * Pointer to Ethernet device structure. 255 * @param[out] modinfo 256 * Storage for plug-in module EEPROM information. 257 * 258 * @return 259 * 0 on success, a negative errno value otherwise and rte_errno is set. 260 */ 261 int 262 mlx5_get_module_info(struct rte_eth_dev *dev, 263 struct rte_eth_dev_module_info *modinfo) 264 { 265 RTE_SET_USED(dev); 266 RTE_SET_USED(modinfo); 267 return -ENOTSUP; 268 } 269 270 /** 271 * DPDK callback to retrieve plug-in module EEPROM data. 272 * 273 * @param dev 274 * Pointer to Ethernet device structure. 275 * @param[out] info 276 * Storage for plug-in module EEPROM data. 277 * 278 * @return 279 * 0 on success, a negative errno value otherwise and rte_errno is set. 280 */ 281 int mlx5_get_module_eeprom(struct rte_eth_dev *dev, 282 struct rte_dev_eeprom_info *info) 283 { 284 RTE_SET_USED(dev); 285 RTE_SET_USED(info); 286 return -ENOTSUP; 287 } 288 289 /** 290 * Get device current raw clock counter 291 * 292 * @param dev 293 * Pointer to Ethernet device structure. 294 * @param[out] time 295 * Current raw clock counter of the device. 296 * 297 * @return 298 * 0 if the clock has correctly been read 299 * The value of errno in case of error 300 */ 301 int 302 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock) 303 { 304 int err; 305 struct mlx5_devx_clock mlx5_clock; 306 struct mlx5_priv *priv = dev->data->dev_private; 307 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->ctx; 308 309 err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock); 310 if (err != 0) { 311 DRV_LOG(WARNING, "Could not query the clock"); 312 return err; 313 } 314 *clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer; 315 return 0; 316 } 317