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->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->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->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)
210 * Read device counters table.
213 * Pointer to Ethernet device.
215 * Counters table output buffer.
218 * 0 on success and stats is filled, negative errno value otherwise and
222 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
230 * DPDK callback to retrieve physical link information.
233 * Pointer to Ethernet device structure.
234 * @param wait_to_complete
235 * Wait for request completion.
238 * 0 if link status was not updated, positive if it was, a negative errno
239 * value otherwise and rte_errno is set.
242 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
244 RTE_SET_USED(wait_to_complete);
245 struct mlx5_priv *priv;
246 mlx5_context_st *context_obj;
247 struct rte_eth_link dev_link;
255 priv = dev->data->dev_private;
256 context_obj = (mlx5_context_st *)priv->sh->ctx;
257 dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1000 * 1000);
258 dev_link.link_status =
259 (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev))
261 dev_link.link_duplex = 1;
262 if (dev->data->dev_link.link_speed != dev_link.link_speed ||
263 dev->data->dev_link.link_duplex != dev_link.link_duplex ||
264 dev->data->dev_link.link_autoneg != dev_link.link_autoneg ||
265 dev->data->dev_link.link_status != dev_link.link_status)
269 dev->data->dev_link = dev_link;
274 * DPDK callback to bring the link DOWN.
277 * Pointer to Ethernet device structure.
280 * 0 on success, a negative errno value otherwise
283 mlx5_set_link_down(struct rte_eth_dev *dev)
290 * DPDK callback to bring the link UP.
293 * Pointer to Ethernet device structure.
296 * 0 on success, a negative errno value otherwise
299 mlx5_set_link_up(struct rte_eth_dev *dev)
306 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
309 * Pointer to Ethernet device structure.
310 * @param[out] modinfo
311 * Storage for plug-in module EEPROM information.
314 * 0 on success, a negative errno value otherwise and rte_errno is set.
317 mlx5_get_module_info(struct rte_eth_dev *dev,
318 struct rte_eth_dev_module_info *modinfo)
321 RTE_SET_USED(modinfo);
326 * DPDK callback to retrieve plug-in module EEPROM data.
329 * Pointer to Ethernet device structure.
331 * Storage for plug-in module EEPROM data.
334 * 0 on success, a negative errno value otherwise and rte_errno is set.
336 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
337 struct rte_dev_eeprom_info *info)
345 * Get device current raw clock counter
348 * Pointer to Ethernet device structure.
350 * Current raw clock counter of the device.
353 * 0 if the clock has correctly been read
354 * The value of errno in case of error
357 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
360 struct mlx5_devx_clock mlx5_clock;
361 struct mlx5_priv *priv = dev->data->dev_private;
362 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->ctx;
364 err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
366 DRV_LOG(WARNING, "Could not query the clock");
369 *clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;
374 * Check if mlx5 device was removed.
377 * Pointer to Ethernet device structure.
380 * 1 when device is removed, otherwise 0.
383 mlx5_is_removed(struct rte_eth_dev *dev)
385 struct mlx5_priv *priv = dev->data->dev_private;
386 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->ctx;
388 if (*context_obj->shutdown_event_obj.p_flag)