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.
55 * 0 on success, a negative errno value otherwise and rte_errno is set.
58 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
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.
74 * pointer to callback routine
76 * opaque callback parameter
79 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
80 rte_intr_callback_fn cb_fn, void *cb_arg)
88 * DPDK callback to get flow control status.
91 * Pointer to Ethernet device structure.
93 * Flow control output buffer.
96 * 0 on success, a negative errno value otherwise and rte_errno is set.
99 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
102 RTE_SET_USED(fc_conf);
107 * DPDK callback to modify flow control parameters.
110 * Pointer to Ethernet device structure.
112 * Flow control parameters.
115 * 0 on success, a negative errno value otherwise and rte_errno is set.
118 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
121 RTE_SET_USED(fc_conf);
126 * Query the number of statistics provided by ETHTOOL.
129 * Pointer to Ethernet device.
132 * Number of statistics on success, negative errno value otherwise and
136 mlx5_os_get_stats_n(struct rte_eth_dev *dev)
143 * Init the structures to read device counters.
146 * Pointer to Ethernet device.
149 mlx5_os_stats_init(struct rte_eth_dev *dev)
155 * Read device counters table.
158 * Pointer to Ethernet device.
160 * Counters table output buffer.
163 * 0 on success and stats is filled, negative errno value otherwise and
167 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
175 * DPDK callback to retrieve physical link information.
178 * Pointer to Ethernet device structure.
179 * @param wait_to_complete
180 * Wait for request completion.
183 * 0 if link status was not updated, positive if it was, a negative errno
184 * value otherwise and rte_errno is set.
187 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
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;
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))
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)
214 dev->data->dev_link = dev_link;
219 * DPDK callback to bring the link DOWN.
222 * Pointer to Ethernet device structure.
225 * 0 on success, a negative errno value otherwise
228 mlx5_set_link_down(struct rte_eth_dev *dev)
235 * DPDK callback to bring the link UP.
238 * Pointer to Ethernet device structure.
241 * 0 on success, a negative errno value otherwise
244 mlx5_set_link_up(struct rte_eth_dev *dev)
251 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
254 * Pointer to Ethernet device structure.
255 * @param[out] modinfo
256 * Storage for plug-in module EEPROM information.
259 * 0 on success, a negative errno value otherwise and rte_errno is set.
262 mlx5_get_module_info(struct rte_eth_dev *dev,
263 struct rte_eth_dev_module_info *modinfo)
266 RTE_SET_USED(modinfo);
271 * DPDK callback to retrieve plug-in module EEPROM data.
274 * Pointer to Ethernet device structure.
276 * Storage for plug-in module EEPROM data.
279 * 0 on success, a negative errno value otherwise and rte_errno is set.
281 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
282 struct rte_dev_eeprom_info *info)
290 * Get device current raw clock counter
293 * Pointer to Ethernet device structure.
295 * Current raw clock counter of the device.
298 * 0 if the clock has correctly been read
299 * The value of errno in case of error
302 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
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;
309 err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
311 DRV_LOG(WARNING, "Could not query the clock");
314 *clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;