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)
90 struct mlx5_priv *priv;
91 mlx5_context_st *context_obj;
97 priv = dev->data->dev_private;
98 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
100 err = mlx5_glue->devx_get_mtu(context_obj, &curr_mtu);
102 DRV_LOG(WARNING, "Could not get the MTU!");
105 *mtu = (uint16_t)curr_mtu;
114 * Pointer to Ethernet device.
119 * 0 on success, a negative errno value otherwise and rte_errno is set.
122 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
125 struct mlx5_priv *priv;
126 mlx5_context_st *context_obj;
132 priv = dev->data->dev_private;
133 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
135 err = mlx5_glue->devx_set_mtu(context_obj, mtu);
137 DRV_LOG(WARNING, "Could not set the MTU!");
144 * Unregister callback handler safely. The handler may be active
145 * while we are trying to unregister it, in this case code -EAGAIN
146 * is returned by rte_intr_callback_unregister(). This routine checks
147 * the return code and tries to unregister handler again.
152 * pointer to callback routine
154 * opaque callback parameter
157 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
158 rte_intr_callback_fn cb_fn, void *cb_arg)
160 RTE_SET_USED(handle);
162 RTE_SET_USED(cb_arg);
166 * DPDK callback to get flow control status.
169 * Pointer to Ethernet device structure.
170 * @param[out] fc_conf
171 * Flow control output buffer.
174 * 0 on success, a negative errno value otherwise and rte_errno is set.
177 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
180 RTE_SET_USED(fc_conf);
185 * DPDK callback to modify flow control parameters.
188 * Pointer to Ethernet device structure.
190 * Flow control parameters.
193 * 0 on success, a negative errno value otherwise and rte_errno is set.
196 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
199 RTE_SET_USED(fc_conf);
204 * Query the number of statistics provided by ETHTOOL.
207 * Pointer to Ethernet device.
210 * Number of statistics on success, negative errno value otherwise and
214 mlx5_os_get_stats_n(struct rte_eth_dev *dev)
221 * Init the structures to read device counters.
224 * Pointer to Ethernet device.
227 mlx5_os_stats_init(struct rte_eth_dev *dev)
229 struct mlx5_priv *priv = dev->data->dev_private;
230 struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
233 /* Copy to base at first time. */
234 ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
236 DRV_LOG(ERR, "port %u cannot read device counters: %s",
237 dev->data->port_id, strerror(rte_errno));
238 stats_ctrl->imissed = 0;
242 * Read device counters table.
245 * Pointer to Ethernet device.
247 * Counters table output buffer.
250 * 0 on success and stats is filled, negative errno value otherwise and
254 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
262 * DPDK callback to retrieve physical link information.
265 * Pointer to Ethernet device structure.
266 * @param wait_to_complete
267 * Wait for request completion.
270 * 0 if link status was not updated, positive if it was, a negative errno
271 * value otherwise and rte_errno is set.
274 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
276 RTE_SET_USED(wait_to_complete);
277 struct mlx5_priv *priv;
278 mlx5_context_st *context_obj;
279 struct rte_eth_link dev_link;
287 priv = dev->data->dev_private;
288 context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
289 dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1000 * 1000);
290 dev_link.link_status =
291 (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev))
293 dev_link.link_duplex = 1;
294 if (dev->data->dev_link.link_speed != dev_link.link_speed ||
295 dev->data->dev_link.link_duplex != dev_link.link_duplex ||
296 dev->data->dev_link.link_autoneg != dev_link.link_autoneg ||
297 dev->data->dev_link.link_status != dev_link.link_status)
301 dev->data->dev_link = dev_link;
306 * DPDK callback to bring the link DOWN.
309 * Pointer to Ethernet device structure.
312 * 0 on success, a negative errno value otherwise
315 mlx5_set_link_down(struct rte_eth_dev *dev)
322 * DPDK callback to bring the link UP.
325 * Pointer to Ethernet device structure.
328 * 0 on success, a negative errno value otherwise
331 mlx5_set_link_up(struct rte_eth_dev *dev)
338 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
341 * Pointer to Ethernet device structure.
342 * @param[out] modinfo
343 * Storage for plug-in module EEPROM information.
346 * 0 on success, a negative errno value otherwise and rte_errno is set.
349 mlx5_get_module_info(struct rte_eth_dev *dev,
350 struct rte_eth_dev_module_info *modinfo)
353 RTE_SET_USED(modinfo);
358 * DPDK callback to retrieve plug-in module EEPROM data.
361 * Pointer to Ethernet device structure.
363 * Storage for plug-in module EEPROM data.
366 * 0 on success, a negative errno value otherwise and rte_errno is set.
368 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
369 struct rte_dev_eeprom_info *info)
377 * Get device current raw clock counter
380 * Pointer to Ethernet device structure.
382 * Current raw clock counter of the device.
385 * 0 if the clock has correctly been read
386 * The value of errno in case of error
389 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
392 struct mlx5_devx_clock mlx5_clock;
393 struct mlx5_priv *priv = dev->data->dev_private;
394 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
396 err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
398 DRV_LOG(WARNING, "Could not query the clock");
401 *clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;
406 * Check if mlx5 device was removed.
409 * Pointer to Ethernet device structure.
412 * 1 when device is removed, otherwise 0.
415 mlx5_is_removed(struct rte_eth_dev *dev)
417 struct mlx5_priv *priv = dev->data->dev_private;
418 mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
420 if (*context_obj->shutdown_event_obj.p_flag)
426 * Query dropless_rq private flag value provided by ETHTOOL.
429 * Pointer to Ethernet device.
432 * - 0 on success, flag is not set.
433 * - 1 on success, flag is set.
434 * - negative errno value otherwise and rte_errno is set.
436 int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)