File: mlx5_ethdev_os.c

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (488 lines) | stat: -rw-r--r-- 10,946 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2020 Mellanox Technologies, Ltd
 */
#include <stdio.h>

#include <rte_errno.h>
#include <rte_ether.h>
#include <ethdev_driver.h>
#include <rte_interrupts.h>

#include <mlx5_glue.h>
#include <mlx5_devx_cmds.h>
#include <mlx5_common.h>
#include <mlx5_win_ext.h>
#include <mlx5_malloc.h>
#include <mlx5.h>
#include <mlx5_utils.h>

/**
 * Get MAC address by querying netdevice.
 *
 * @param[in] dev
 *   Pointer to Ethernet device.
 * @param[out] mac
 *   MAC address output buffer.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN])
{
	struct mlx5_priv *priv;
	mlx5_context_st *context_obj;

	if (!dev) {
		rte_errno = EINVAL;
		return -rte_errno;
	}
	priv = dev->data->dev_private;
	context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
	memcpy(mac, context_obj->mlx5_dev.eth_mac, RTE_ETHER_ADDR_LEN);
	return 0;
}

/**
 * Get interface name from private structure.
 *
 *
 * @param[in] dev
 *   Pointer to Ethernet device.
 * @param[out] ifname
 *   Interface name output buffer.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_get_ifname(const struct rte_eth_dev *dev, char ifname[MLX5_NAMESIZE])
{
	struct mlx5_priv *priv;
	mlx5_context_st *context_obj;

	if (!dev) {
		rte_errno = EINVAL;
		return -rte_errno;
	}
	priv = dev->data->dev_private;
	context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
	strncpy(ifname, context_obj->mlx5_dev.name, MLX5_NAMESIZE);
	return 0;
}

/**
 * Get device minimum and maximum allowed MTU.
 *
 * Windows API does not expose minimum and maximum allowed MTU.
 * In this case, this just returns (-ENOTSUP) to allow platform-independent code
 * to fallback to default values.
 *
 * @param dev
 *   Pointer to Ethernet device.
 * @param[out] min_mtu
 *   Minimum MTU value output buffer.
 * @param[out] max_mtu
 *   Maximum MTU value output buffer.
 *
 * @return
 *   (-ENOTSUP) - not supported on Windows
 */
int
mlx5_os_get_mtu_bounds(struct rte_eth_dev *dev, uint16_t *min_mtu, uint16_t *max_mtu)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(min_mtu);
	RTE_SET_USED(max_mtu);

	rte_errno = ENOTSUP;
	return -rte_errno;
}

/**
 * Get device MTU.
 *
 * @param dev
 *   Pointer to Ethernet device.
 * @param[out] mtu
 *   MTU value output buffer.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu)
{
	int err;
	uint32_t curr_mtu;
	struct mlx5_priv *priv;
	mlx5_context_st *context_obj;

	if (!dev) {
		rte_errno = EINVAL;
		return -rte_errno;
	}
	priv = dev->data->dev_private;
	context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;

	err = mlx5_glue->devx_get_mtu(context_obj, &curr_mtu);
	if (err != 0) {
		DRV_LOG(WARNING, "Could not get the MTU!");
		return err;
	}
	*mtu = (uint16_t)curr_mtu;

	return 0;
}

/**
 * Set device MTU.
 *
 * @param dev
 *   Pointer to Ethernet device.
 * @param mtu
 *   MTU value to set.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
{
	int err;
	struct mlx5_priv *priv;
	mlx5_context_st *context_obj;

	if (!dev) {
		rte_errno = EINVAL;
		return -rte_errno;
	}
	priv = dev->data->dev_private;
	context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;

	err = mlx5_glue->devx_set_mtu(context_obj, mtu);
	if (err != 0) {
		DRV_LOG(WARNING, "Could not set the MTU!");
		return err;
	}
	return 0;
}

/**
 * DPDK callback to get flow control status.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param[out] fc_conf
 *   Flow control output buffer.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(fc_conf);
	return -ENOTSUP;
}

/**
 * DPDK callback to modify flow control parameters.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param[in] fc_conf
 *   Flow control parameters.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(fc_conf);
	return -ENOTSUP;
}

/*
 * Query the number of statistics provided by ETHTOOL.
 *
 * @param dev
 *   Pointer to Ethernet device.
 * @param bond_master
 *   Indicate if the device is a bond master.
 * @param n_stats
 *   Pointer to number of stats to store.
 * @param n_stats_sec
 *   Pointer to number of stats to store for the 2nd port of the bond.
 *
 * @return
 *   0 on success, negative errno value otherwise and rte_errno is set.
 */
int
mlx5_os_get_stats_n(struct rte_eth_dev *dev, bool bond_master,
		    uint16_t *n_stats, uint16_t *n_stats_sec)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(bond_master);
	RTE_SET_USED(n_stats);
	RTE_SET_USED(n_stats_sec);
	return -ENOTSUP;
}

/**
 * Init the structures to read device counters.
 *
 * @param dev
 *   Pointer to Ethernet device.
 */
void
mlx5_os_stats_init(struct rte_eth_dev *dev)
{
	struct mlx5_priv *priv = dev->data->dev_private;
	struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
	int ret;

	/* Copy to base at first time. */
	ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
	if (ret)
		DRV_LOG(ERR, "port %u cannot read device counters: %s",
			dev->data->port_id, strerror(rte_errno));
	stats_ctrl->imissed = 0;
}

/**
 * Read device counters table.
 *
 * @param dev
 *   Pointer to Ethernet device.
 * @param bond_master
 *   Indicate if the device is a bond master.
 * @param[out] stats
 *   Counters table output buffer.
 *
 * @return
 *   0 on success and stats is filled, negative errno value otherwise and
 *   rte_errno is set.
 */
int
mlx5_os_read_dev_counters(struct rte_eth_dev *dev, bool bond_master, uint64_t *stats)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(bond_master);
	RTE_SET_USED(stats);
	return -ENOTSUP;
}

/**
 * DPDK callback to retrieve physical link information.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param wait_to_complete
 *   Wait for request completion.
 *
 * @return
 *   0 if link status was not updated, positive if it was, a negative errno
 *   value otherwise and rte_errno is set.
 */
int
mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
{
	RTE_SET_USED(wait_to_complete);
	struct mlx5_priv *priv;
	mlx5_context_st *context_obj;
	struct rte_eth_link dev_link;
	int ret;

	ret = 0;
	if (!dev) {
		rte_errno = EINVAL;
		return -rte_errno;
	}
	priv = dev->data->dev_private;
	context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
	dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1000 * 1000);
	dev_link.link_status =
	      (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev))
	      ? 1 : 0;
	dev_link.link_duplex = 1;
	if (dev->data->dev_link.link_speed != dev_link.link_speed ||
	    dev->data->dev_link.link_duplex != dev_link.link_duplex ||
	    dev->data->dev_link.link_status != dev_link.link_status)
		ret = 1;
	else
		ret = 0;
	dev_link.link_autoneg = dev->data->dev_link.link_autoneg;
	dev->data->dev_link = dev_link;
	return ret;
}

/**
 * DPDK callback to bring the link DOWN.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 *
 * @return
 *   0 on success, a negative errno value otherwise
 */
int
mlx5_set_link_down(struct rte_eth_dev *dev)
{
	RTE_SET_USED(dev);
	return -ENOTSUP;
}

/**
 * DPDK callback to bring the link UP.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 *
 * @return
 *   0 on success, a negative errno value otherwise
 */
int
mlx5_set_link_up(struct rte_eth_dev *dev)
{
	RTE_SET_USED(dev);
	return -ENOTSUP;
}

/**
 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param[out] modinfo
 *   Storage for plug-in module EEPROM information.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int
mlx5_get_module_info(struct rte_eth_dev *dev,
		     struct rte_eth_dev_module_info *modinfo)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(modinfo);
	return -ENOTSUP;
}

/**
 * DPDK callback to retrieve plug-in module EEPROM data.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param[out] info
 *   Storage for plug-in module EEPROM data.
 *
 * @return
 *   0 on success, a negative errno value otherwise and rte_errno is set.
 */
int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
			   struct rte_dev_eeprom_info *info)
{
	RTE_SET_USED(dev);
	RTE_SET_USED(info);
	return -ENOTSUP;
}

/**
 * Get device current raw clock counter
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param[out] time
 *   Current raw clock counter of the device.
 *
 * @return
 *   0 if the clock has correctly been read
 *   The value of errno in case of error
 */
int
mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
{
	int err;
	struct mlx5_devx_clock mlx5_clock;
	struct mlx5_priv *priv = dev->data->dev_private;
	mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;

	err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
	if (err != 0) {
		DRV_LOG(WARNING, "Could not query the clock");
		return err;
	}
	*clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;
	return 0;
}

/**
 * Check if mlx5 device was removed.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 *
 * @return
 *   1 when device is removed, otherwise 0.
 */
int
mlx5_is_removed(struct rte_eth_dev *dev)
{
	struct mlx5_priv *priv = dev->data->dev_private;
	mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;

	if (*context_obj->shutdown_event_obj.p_flag)
		return 1;
	return 0;
}

/*
 * Query dropless_rq private flag value provided by ETHTOOL.
 *
 * @param dev
 *   Pointer to Ethernet device.
 *
 * @return
 *   - 0 on success, flag is not set.
 *   - 1 on success, flag is set.
 *   - negative errno value otherwise and rte_errno is set.
 */
int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)
{
	RTE_SET_USED(dev);
	return -ENOTSUP;
}

/**
 * Unmaps HCA PCI BAR from the current process address space.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 */
void mlx5_txpp_unmap_hca_bar(struct rte_eth_dev *dev)
{
	RTE_SET_USED(dev);
}

/**
 * Maps HCA PCI BAR to the current process address space.
 * Stores pointer in the process private structure allowing
 * to read internal and real time counter directly from the HW.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 *
 * @return
 *   0 on success and not NULL pointer to mapped area in process structure.
 *   negative otherwise and NULL pointer
 */
int mlx5_txpp_map_hca_bar(struct rte_eth_dev *dev)
{
	RTE_SET_USED(dev);
	rte_errno = ENOTSUP;
	return -ENOTSUP;
}