1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
8 #include <ethdev_driver.h>
9 #include <rte_interrupts.h>
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>
17 #include <mlx5_utils.h>
20 * Get MAC address by querying netdevice.
23 * Pointer to Ethernet device.
25 * MAC address output buffer.
28 * 0 on success, a negative errno value otherwise and rte_errno is set.
31 mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN])
33 struct mlx5_priv *priv;
34 mlx5_context_st *context_obj;
40 priv = dev->data->dev_private;
41 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
42 memcpy(mac, context_obj->mlx5_dev.eth_mac, RTE_ETHER_ADDR_LEN);
47 * Get interface name from private structure.
51 * Pointer to Ethernet device.
53 * Interface name output buffer.
56 * 0 on success, a negative errno value otherwise and rte_errno is set.
59 mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
61 struct mlx5_priv *priv;
62 mlx5_context_st *context_obj;
68 priv = dev->data->dev_private;
69 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
70 strncpy(*ifname, context_obj->mlx5_dev.name, MLX5_NAMESIZE);
78 * Pointer to Ethernet device.
80 * MTU value output buffer.
83 * 0 on success, a negative errno value otherwise and rte_errno is set.
86 mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu)
88 struct mlx5_priv *priv;
89 mlx5_context_st *context_obj;
95 priv = dev->data->dev_private;
96 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
97 *mtu = context_obj->mlx5_dev.mtu_bytes;
105 * Pointer to Ethernet device.
110 * 0 on success, a negative errno value otherwise and rte_errno is set.
113 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
121 * Unregister callback handler safely. The handler may be active
122 * while we are trying to unregister it, in this case code -EAGAIN
123 * is returned by rte_intr_callback_unregister(). This routine checks
124 * the return code and tries to unregister handler again.
129 * pointer to callback routine
131 * opaque callback parameter
134 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
135 rte_intr_callback_fn cb_fn, void *cb_arg)
137 RTE_SET_USED(handle);
139 RTE_SET_USED(cb_arg);
143 * DPDK callback to get flow control status.
146 * Pointer to Ethernet device structure.
147 * @param[out] fc_conf
148 * Flow control output buffer.
151 * 0 on success, a negative errno value otherwise and rte_errno is set.
154 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
157 RTE_SET_USED(fc_conf);
162 * DPDK callback to modify flow control parameters.
165 * Pointer to Ethernet device structure.
167 * Flow control parameters.
170 * 0 on success, a negative errno value otherwise and rte_errno is set.
173 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
176 RTE_SET_USED(fc_conf);
181 * Query the number of statistics provided by ETHTOOL.
184 * Pointer to Ethernet device.
187 * Number of statistics on success, negative errno value otherwise and
191 mlx5_os_get_stats_n(struct rte_eth_dev *dev)
198 * Init the structures to read device counters.
201 * Pointer to Ethernet device.
204 mlx5_os_stats_init(struct rte_eth_dev *dev)
206 struct mlx5_priv *priv = dev->data->dev_private;
207 struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
210 /* Copy to base at first time. */
211 ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
213 DRV_LOG(ERR, "port %u cannot read device counters: %s",
214 dev->data->port_id, strerror(rte_errno));
215 stats_ctrl->imissed = 0;
219 * Read device counters table.
222 * Pointer to Ethernet device.
224 * Counters table output buffer.
227 * 0 on success and stats is filled, negative errno value otherwise and
231 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
239 * DPDK callback to retrieve physical link information.
242 * Pointer to Ethernet device structure.
243 * @param wait_to_complete
244 * Wait for request completion.
247 * 0 if link status was not updated, positive if it was, a negative errno
248 * value otherwise and rte_errno is set.
251 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
253 RTE_SET_USED(wait_to_complete);
254 struct mlx5_priv *priv;
255 mlx5_context_st *context_obj;
256 struct rte_eth_link dev_link;
264 priv = dev->data->dev_private;
265 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
266 dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1000 * 1000);
267 dev_link.link_status =
268 (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev))
270 dev_link.link_duplex = 1;
271 if (dev->data->dev_link.link_speed != dev_link.link_speed ||
272 dev->data->dev_link.link_duplex != dev_link.link_duplex ||
273 dev->data->dev_link.link_autoneg != dev_link.link_autoneg ||
274 dev->data->dev_link.link_status != dev_link.link_status)
278 dev->data->dev_link = dev_link;
283 * DPDK callback to bring the link DOWN.
286 * Pointer to Ethernet device structure.
289 * 0 on success, a negative errno value otherwise
292 mlx5_set_link_down(struct rte_eth_dev *dev)
299 * DPDK callback to bring the link UP.
302 * Pointer to Ethernet device structure.
305 * 0 on success, a negative errno value otherwise
308 mlx5_set_link_up(struct rte_eth_dev *dev)
315 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
318 * Pointer to Ethernet device structure.
319 * @param[out] modinfo
320 * Storage for plug-in module EEPROM information.
323 * 0 on success, a negative errno value otherwise and rte_errno is set.
326 mlx5_get_module_info(struct rte_eth_dev *dev,
327 struct rte_eth_dev_module_info *modinfo)
330 RTE_SET_USED(modinfo);
335 * DPDK callback to retrieve plug-in module EEPROM data.
338 * Pointer to Ethernet device structure.
340 * Storage for plug-in module EEPROM data.
343 * 0 on success, a negative errno value otherwise and rte_errno is set.
345 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
346 struct rte_dev_eeprom_info *info)
354 * Get device current raw clock counter
357 * Pointer to Ethernet device structure.
359 * Current raw clock counter of the device.
362 * 0 if the clock has correctly been read
363 * The value of errno in case of error
366 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
369 struct mlx5_devx_clock mlx5_clock;
370 struct mlx5_priv *priv = dev->data->dev_private;
371 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
373 err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
375 DRV_LOG(WARNING, "Could not query the clock");
378 *clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;
383 * Check if mlx5 device was removed.
386 * Pointer to Ethernet device structure.
389 * 1 when device is removed, otherwise 0.
392 mlx5_is_removed(struct rte_eth_dev *dev)
394 struct mlx5_priv *priv = dev->data->dev_private;
395 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
397 if (*context_obj->shutdown_event_obj.p_flag)
403 * Query dropless_rq private flag value provided by ETHTOOL.
406 * Pointer to Ethernet device.
409 * - 0 on success, flag is not set.
410 * - 1 on success, flag is set.
411 * - negative errno value otherwise and rte_errno is set.
413 int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)