1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
8 #include <rte_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);
50 * Pointer to Ethernet device.
52 * MTU value output buffer.
55 * 0 on success, a negative errno value otherwise and rte_errno is set.
58 mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu)
60 struct mlx5_priv *priv;
61 mlx5_context_st *context_obj;
67 priv = dev->data->dev_private;
68 context_obj = (mlx5_context_st *)priv->sh->ctx;
69 *mtu = context_obj->mlx5_dev.mtu_bytes;
77 * Pointer to Ethernet device.
82 * 0 on success, a negative errno value otherwise and rte_errno is set.
85 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
93 * Unregister callback handler safely. The handler may be active
94 * while we are trying to unregister it, in this case code -EAGAIN
95 * is returned by rte_intr_callback_unregister(). This routine checks
96 * the return code and tries to unregister handler again.
101 * pointer to callback routine
103 * opaque callback parameter
106 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
107 rte_intr_callback_fn cb_fn, void *cb_arg)
109 RTE_SET_USED(handle);
111 RTE_SET_USED(cb_arg);
115 * DPDK callback to get flow control status.
118 * Pointer to Ethernet device structure.
119 * @param[out] fc_conf
120 * Flow control output buffer.
123 * 0 on success, a negative errno value otherwise and rte_errno is set.
126 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
129 RTE_SET_USED(fc_conf);
134 * DPDK callback to modify flow control parameters.
137 * Pointer to Ethernet device structure.
139 * Flow control parameters.
142 * 0 on success, a negative errno value otherwise and rte_errno is set.
145 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
148 RTE_SET_USED(fc_conf);
153 * Query the number of statistics provided by ETHTOOL.
156 * Pointer to Ethernet device.
159 * Number of statistics on success, negative errno value otherwise and
163 mlx5_os_get_stats_n(struct rte_eth_dev *dev)
170 * Init the structures to read device counters.
173 * Pointer to Ethernet device.
176 mlx5_os_stats_init(struct rte_eth_dev *dev)
182 * Read device counters table.
185 * Pointer to Ethernet device.
187 * Counters table output buffer.
190 * 0 on success and stats is filled, negative errno value otherwise and
194 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
202 * DPDK callback to retrieve physical link information.
205 * Pointer to Ethernet device structure.
206 * @param wait_to_complete
207 * Wait for request completion.
210 * 0 if link status was not updated, positive if it was, a negative errno
211 * value otherwise and rte_errno is set.
214 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
216 RTE_SET_USED(wait_to_complete);
217 struct mlx5_priv *priv;
218 mlx5_context_st *context_obj;
219 struct rte_eth_link dev_link;
227 priv = dev->data->dev_private;
228 context_obj = (mlx5_context_st *)priv->sh->ctx;
229 dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1024 * 1024);
230 dev_link.link_status =
231 (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev))
233 dev_link.link_duplex = 1;
234 if (dev->data->dev_link.link_speed != dev_link.link_speed ||
235 dev->data->dev_link.link_duplex != dev_link.link_duplex ||
236 dev->data->dev_link.link_autoneg != dev_link.link_autoneg ||
237 dev->data->dev_link.link_status != dev_link.link_status)
241 dev->data->dev_link = dev_link;
246 * DPDK callback to bring the link DOWN.
249 * Pointer to Ethernet device structure.
252 * 0 on success, a negative errno value otherwise
255 mlx5_set_link_down(struct rte_eth_dev *dev)
262 * DPDK callback to bring the link UP.
265 * Pointer to Ethernet device structure.
268 * 0 on success, a negative errno value otherwise
271 mlx5_set_link_up(struct rte_eth_dev *dev)
278 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
281 * Pointer to Ethernet device structure.
282 * @param[out] modinfo
283 * Storage for plug-in module EEPROM information.
286 * 0 on success, a negative errno value otherwise and rte_errno is set.
289 mlx5_get_module_info(struct rte_eth_dev *dev,
290 struct rte_eth_dev_module_info *modinfo)
293 RTE_SET_USED(modinfo);
298 * DPDK callback to retrieve plug-in module EEPROM data.
301 * Pointer to Ethernet device structure.
303 * Storage for plug-in module EEPROM data.
306 * 0 on success, a negative errno value otherwise and rte_errno is set.
308 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
309 struct rte_dev_eeprom_info *info)
317 * Get device current raw clock counter
320 * Pointer to Ethernet device structure.
322 * Current raw clock counter of the device.
325 * 0 if the clock has correctly been read
326 * The value of errno in case of error
329 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
332 struct mlx5_devx_clock mlx5_clock;
333 struct mlx5_priv *priv = dev->data->dev_private;
334 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->ctx;
336 err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
338 DRV_LOG(WARNING, "Could not query the clock");
341 *clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;