Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2019 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #ifndef RTE_PMD_MLX5_COMMON_H_
6 : : #define RTE_PMD_MLX5_COMMON_H_
7 : :
8 : : #include <stdio.h>
9 : :
10 : : #include <rte_compat.h>
11 : : #include <rte_pci.h>
12 : : #include <bus_pci_driver.h>
13 : : #include <rte_debug.h>
14 : : #include <rte_atomic.h>
15 : : #include <rte_rwlock.h>
16 : : #include <rte_log.h>
17 : : #include <rte_kvargs.h>
18 : : #include <rte_devargs.h>
19 : : #include <rte_bitops.h>
20 : : #include <rte_lcore.h>
21 : : #include <rte_spinlock.h>
22 : : #include <rte_os_shim.h>
23 : :
24 : : #include "mlx5_prm.h"
25 : : #include "mlx5_devx_cmds.h"
26 : : #include "mlx5_common_os.h"
27 : : #include "mlx5_common_mr.h"
28 : :
29 : : /* Reported driver name. */
30 : : #define MLX5_PCI_DRIVER_NAME "mlx5_pci"
31 : : #define MLX5_AUXILIARY_DRIVER_NAME "mlx5_auxiliary"
32 : :
33 : : /* Bit-field manipulation. */
34 : : #define BITFIELD_DECLARE(bf, type, size) \
35 : : type bf[(((size_t)(size) / (sizeof(type) * CHAR_BIT)) + \
36 : : !!((size_t)(size) % (sizeof(type) * CHAR_BIT)))]
37 : : #define BITFIELD_DEFINE(bf, type, size) \
38 : : BITFIELD_DECLARE((bf), type, (size)) = { 0 }
39 : : #define BITFIELD_SET(bf, b) \
40 : : (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] |= \
41 : : ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))
42 : : #define BITFIELD_RESET(bf, b) \
43 : : (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] &= \
44 : : ~((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))
45 : : #define BITFIELD_ISSET(bf, b) \
46 : : !!(((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] & \
47 : : ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
48 : :
49 : : /*
50 : : * Helper macros to work around __VA_ARGS__ limitations in a C99 compliant
51 : : * manner.
52 : : */
53 : : #define PMD_DRV_LOG_STRIP(a, b) a
54 : : #define PMD_DRV_LOG_OPAREN (
55 : : #define PMD_DRV_LOG_CPAREN )
56 : : #define PMD_DRV_LOG_COMMA ,
57 : :
58 : : /* Return the file name part of a path. */
59 : : static inline const char *
60 : : pmd_drv_log_basename(const char *s)
61 : : {
62 : : const char *n = s;
63 : :
64 : : while (*n)
65 : : if (*(n++) == '/')
66 : : s = n;
67 : : return s;
68 : : }
69 : :
70 : : #define PMD_DRV_LOG___(level, type, name, ...) \
71 : : rte_log(RTE_LOG_ ## level, \
72 : : type, \
73 : : RTE_FMT(name ": " \
74 : : RTE_FMT_HEAD(__VA_ARGS__,), \
75 : : RTE_FMT_TAIL(__VA_ARGS__,)))
76 : :
77 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
78 : :
79 : : #define PMD_DRV_LOG__(level, type, name, ...) \
80 : : PMD_DRV_LOG___(level, type, name, "%s:%u: %s(): " __VA_ARGS__)
81 : : #define PMD_DRV_LOG_(level, type, name, s, ...) \
82 : : PMD_DRV_LOG__(level, type, name,\
83 : : s "\n" PMD_DRV_LOG_COMMA \
84 : : pmd_drv_log_basename(__FILE__) PMD_DRV_LOG_COMMA \
85 : : __LINE__ PMD_DRV_LOG_COMMA \
86 : : __func__, \
87 : : __VA_ARGS__)
88 : :
89 : : #else /* RTE_LIBRTE_MLX5_DEBUG */
90 : : #define PMD_DRV_LOG__(level, type, name, ...) \
91 : : PMD_DRV_LOG___(level, type, name, __VA_ARGS__)
92 : : #define PMD_DRV_LOG_(level, type, name, s, ...) \
93 : : PMD_DRV_LOG__(level, type, name, s "\n", __VA_ARGS__)
94 : :
95 : : #endif /* RTE_LIBRTE_MLX5_DEBUG */
96 : :
97 : : /* claim_zero() does not perform any check when debugging is disabled. */
98 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
99 : :
100 : : #define MLX5_ASSERT(exp) RTE_VERIFY(exp)
101 : : #define claim_zero(...) MLX5_ASSERT((__VA_ARGS__) == 0)
102 : : #define claim_nonzero(...) MLX5_ASSERT((__VA_ARGS__) != 0)
103 : :
104 : : #else /* RTE_LIBRTE_MLX5_DEBUG */
105 : :
106 : : #define MLX5_ASSERT(exp) RTE_ASSERT(exp)
107 : : #define claim_zero(...) (__VA_ARGS__)
108 : : #define claim_nonzero(...) (__VA_ARGS__)
109 : :
110 : : #endif /* RTE_LIBRTE_MLX5_DEBUG */
111 : :
112 : : /**
113 : : * Returns true if debug mode is enabled for fast path operations.
114 : : */
115 : : static inline bool
116 : 0 : mlx5_fp_debug_enabled(void)
117 : : {
118 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
119 : : return true;
120 : : #else
121 : 0 : return false;
122 : : #endif
123 : : }
124 : :
125 : : /* Allocate a buffer on the stack and fill it with a printf format string. */
126 : : #define MKSTR(name, ...) \
127 : : int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
128 : : char *name = alloca(mkstr_size_##name + 1); \
129 : : \
130 : : memset(name, 0, mkstr_size_##name + 1); \
131 : : snprintf(name, mkstr_size_##name + 1, "" __VA_ARGS__)
132 : :
133 : : enum {
134 : : PCI_VENDOR_ID_MELLANOX = 0x15b3,
135 : : };
136 : :
137 : : enum {
138 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4 = 0x1013,
139 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4VF = 0x1014,
140 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4LX = 0x1015,
141 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF = 0x1016,
142 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5 = 0x1017,
143 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5VF = 0x1018,
144 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5EX = 0x1019,
145 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF = 0x101a,
146 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD = 0xa2d2,
147 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELDVF = 0xa2d3,
148 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6 = 0x101b,
149 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6VF = 0x101c,
150 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6DX = 0x101d,
151 : : PCI_DEVICE_ID_MELLANOX_CONNECTXVF = 0x101e,
152 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD2 = 0xa2d6,
153 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6LX = 0x101f,
154 : : PCI_DEVICE_ID_MELLANOX_CONNECTX7 = 0x1021,
155 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD3 = 0Xa2dc,
156 : : };
157 : :
158 : : /* Maximum number of simultaneous unicast MAC addresses. */
159 : : #define MLX5_MAX_UC_MAC_ADDRESSES 128
160 : : /* Maximum number of simultaneous Multicast MAC addresses. */
161 : : #define MLX5_MAX_MC_MAC_ADDRESSES 128
162 : : /* Maximum number of simultaneous MAC addresses. */
163 : : #define MLX5_MAX_MAC_ADDRESSES \
164 : : (MLX5_MAX_UC_MAC_ADDRESSES + MLX5_MAX_MC_MAC_ADDRESSES)
165 : :
166 : : /* Recognized Infiniband device physical port name types. */
167 : : enum mlx5_nl_phys_port_name_type {
168 : : MLX5_PHYS_PORT_NAME_TYPE_NOTSET = 0, /* Not set. */
169 : : MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 */
170 : : MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */
171 : : MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */
172 : : MLX5_PHYS_PORT_NAME_TYPE_PFHPF, /* pf0, kernel ver >= 5.7, HPF rep */
173 : : MLX5_PHYS_PORT_NAME_TYPE_PFSF, /* pf0sf0, kernel ver >= 5.0 */
174 : : MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */
175 : : };
176 : :
177 : : struct mlx5_port_nl_info {
178 : : uint32_t ifindex;
179 : : uint8_t valid;
180 : : };
181 : :
182 : : struct mlx5_dev_info {
183 : : uint32_t port_num;
184 : : uint32_t ibindex;
185 : : char ibname[MLX5_FS_NAME_MAX];
186 : : uint8_t probe_opt;
187 : : struct mlx5_port_nl_info *port_info;
188 : : };
189 : :
190 : : /** Switch information returned by mlx5_nl_switch_info(). */
191 : : struct mlx5_switch_info {
192 : : uint32_t master:1; /**< Master device. */
193 : : uint32_t representor:1; /**< Representor device. */
194 : : enum mlx5_nl_phys_port_name_type name_type; /** < Port name type. */
195 : : int32_t ctrl_num; /**< Controller number (valid for c#pf#vf# format). */
196 : : int32_t pf_num; /**< PF number (valid for pfxvfx format only). */
197 : : int32_t port_name; /**< Representor port name. */
198 : : int32_t mpesw_owner; /**< MPESW owner port number. */
199 : : uint64_t switch_id; /**< Switch identifier. */
200 : : };
201 : :
202 : : /* CQE status. */
203 : : enum mlx5_cqe_status {
204 : : MLX5_CQE_STATUS_SW_OWN = -1,
205 : : MLX5_CQE_STATUS_HW_OWN = -2,
206 : : MLX5_CQE_STATUS_ERR = -3,
207 : : };
208 : :
209 : : /**
210 : : * Check whether CQE has an error opcode.
211 : : *
212 : : * @param op_code
213 : : * Opcode to check.
214 : : *
215 : : * @return
216 : : * The CQE status.
217 : : */
218 : : static __rte_always_inline enum mlx5_cqe_status
219 : : check_cqe_error(const uint8_t op_code)
220 : : {
221 : : /* Prevent speculative reading of other fields in CQE until
222 : : * CQE is valid.
223 : : */
224 : : rte_atomic_thread_fence(rte_memory_order_acquire);
225 : :
226 [ # # # # : 0 : if (unlikely(op_code == MLX5_CQE_RESP_ERR ||
# # # # #
# # # # #
# # ]
227 : : op_code == MLX5_CQE_REQ_ERR))
228 : 0 : return MLX5_CQE_STATUS_ERR;
229 : : return MLX5_CQE_STATUS_SW_OWN;
230 : : }
231 : :
232 : : /**
233 : : * Check whether CQE is valid using owner bit.
234 : : *
235 : : * @param cqe
236 : : * Pointer to CQE.
237 : : * @param cqes_n
238 : : * Size of completion queue.
239 : : * @param ci
240 : : * Consumer index.
241 : : *
242 : : * @return
243 : : * The CQE status.
244 : : */
245 : : static __rte_always_inline enum mlx5_cqe_status
246 : : check_cqe(volatile struct mlx5_cqe *cqe, const uint16_t cqes_n,
247 : : const uint16_t ci)
248 : : {
249 : 0 : const uint16_t idx = ci & cqes_n;
250 : 0 : const uint8_t op_own = cqe->op_own;
251 : 0 : const uint8_t op_owner = MLX5_CQE_OWNER(op_own);
252 : 0 : const uint8_t op_code = MLX5_CQE_OPCODE(op_own);
253 : :
254 [ # # # # : 0 : if (unlikely((op_owner != (!!(idx))) ||
# # # # #
# # # # #
# # # # #
# ]
255 : : (op_code == MLX5_CQE_INVALID)))
256 : : return MLX5_CQE_STATUS_HW_OWN;
257 : : return check_cqe_error(op_code);
258 : : }
259 : :
260 : : /**
261 : : * Check whether CQE is valid using validity iteration count.
262 : : *
263 : : * @param cqe
264 : : * Pointer to CQE.
265 : : * @param cqes_n
266 : : * Log 2 of completion queue size.
267 : : * @param ci
268 : : * Consumer index.
269 : : *
270 : : * @return
271 : : * The CQE status.
272 : : */
273 : : static __rte_always_inline enum mlx5_cqe_status
274 : : check_cqe_iteration(volatile struct mlx5_cqe *cqe, const uint16_t cqes_n,
275 : : const uint32_t ci)
276 : : {
277 : 0 : const uint8_t op_own = cqe->op_own;
278 : 0 : const uint8_t op_code = MLX5_CQE_OPCODE(op_own);
279 : 0 : const uint8_t vic = ci >> cqes_n;
280 : :
281 [ # # # # : 0 : if (unlikely((cqe->validity_iteration_count != vic) ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
282 : : (op_code == MLX5_CQE_INVALID)))
283 : : return MLX5_CQE_STATUS_HW_OWN;
284 : : return check_cqe_error(op_code);
285 : : }
286 : :
287 : : /*
288 : : * Get PCI address <DBDF> string from EAL device.
289 : : *
290 : : * @param[out] addr
291 : : * The output address buffer string
292 : : * @param[in] size
293 : : * The output buffer size
294 : : * @return
295 : : * - 0 on success.
296 : : * - Negative value and rte_errno is set otherwise.
297 : : */
298 : : __rte_internal
299 : : int mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size);
300 : :
301 : : /*
302 : : * Get PCI address from sysfs of a PCI-related device.
303 : : *
304 : : * @param[in] dev_path
305 : : * The sysfs path should not point to the direct plain PCI device.
306 : : * Instead, the node "/device/" is used to access the real device.
307 : : * @param[out] pci_addr
308 : : * Parsed PCI address.
309 : : *
310 : : * @return
311 : : * - 0 on success.
312 : : * - Negative value and rte_errno is set otherwise.
313 : : */
314 : : __rte_internal
315 : : int mlx5_get_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr);
316 : :
317 : : /*
318 : : * Get kernel network interface name from sysfs IB device path.
319 : : *
320 : : * @param[in] ibdev_path
321 : : * The sysfs path to IB device.
322 : : * @param[out] ifname
323 : : * Interface name output of size IF_NAMESIZE.
324 : : *
325 : : * @return
326 : : * - 0 on success.
327 : : * - Negative value and rte_errno is set otherwise.
328 : : */
329 : : __rte_internal
330 : : int mlx5_get_ifname_sysfs(const char *ibdev_path, char *ifname);
331 : :
332 : : __rte_internal
333 : : int mlx5_auxiliary_get_child_name(const char *dev, const char *node,
334 : : char *child, size_t size);
335 : :
336 : : enum mlx5_class {
337 : : MLX5_CLASS_INVALID,
338 : : MLX5_CLASS_ETH = RTE_BIT64(0),
339 : : MLX5_CLASS_VDPA = RTE_BIT64(1),
340 : : MLX5_CLASS_REGEX = RTE_BIT64(2),
341 : : MLX5_CLASS_COMPRESS = RTE_BIT64(3),
342 : : MLX5_CLASS_CRYPTO = RTE_BIT64(4),
343 : : };
344 : :
345 : : #define MLX5_DBR_SIZE RTE_CACHE_LINE_SIZE
346 : :
347 : : /* devX creation object */
348 : : struct mlx5_devx_obj {
349 : : void *obj; /* The DV object. */
350 : : int id; /* The object ID. */
351 : : };
352 : :
353 : : /* UMR memory buffer used to define 1 entry in indirect mkey. */
354 : : struct mlx5_klm {
355 : : uint32_t byte_count;
356 : : uint32_t mkey;
357 : : uint64_t address;
358 : : };
359 : :
360 : : /** Control for key/values list. */
361 : : struct mlx5_kvargs_ctrl {
362 : : struct rte_kvargs *kvlist; /* Structure containing list of key/values.*/
363 : : bool is_used[RTE_KVARGS_MAX]; /* Indicator which devargs were used. */
364 : : };
365 : :
366 : : /**
367 : : * Call a handler function for each key/value in the list of keys.
368 : : *
369 : : * For each key/value association that matches the given key, calls the
370 : : * handler function with the for a given arg_name passing the value on the
371 : : * dictionary for that key and a given extra argument.
372 : : *
373 : : * @param mkvlist
374 : : * The mlx5_kvargs structure.
375 : : * @param keys
376 : : * A list of keys to process (table of const char *, the last must be NULL).
377 : : * @param handler
378 : : * The function to call for each matching key.
379 : : * @param opaque_arg
380 : : * A pointer passed unchanged to the handler.
381 : : *
382 : : * @return
383 : : * - 0 on success
384 : : * - Negative on error
385 : : */
386 : : __rte_internal
387 : : int
388 : : mlx5_kvargs_process(struct mlx5_kvargs_ctrl *mkvlist, const char *const keys[],
389 : : arg_handler_t handler, void *opaque_arg);
390 : :
391 : : /* All UAR arguments using doorbell register in datapath. */
392 : : struct mlx5_uar_data {
393 : : uint64_t *db;
394 : : /* The doorbell's virtual address mapped to the relevant HW UAR space.*/
395 : : #ifndef RTE_ARCH_64
396 : : rte_spinlock_t *sl_p;
397 : : /* Pointer to UAR access lock required for 32bit implementations. */
398 : : #endif /* RTE_ARCH_64 */
399 : : };
400 : :
401 : : /* DevX UAR control structure. */
402 : : struct mlx5_uar {
403 : : struct mlx5_uar_data bf_db; /* UAR data for Blueflame register. */
404 : : struct mlx5_uar_data cq_db; /* UAR data for CQ arm db register. */
405 : : void *obj; /* DevX UAR object. */
406 : : bool dbnc; /* Doorbell mapped to non-cached region. */
407 : : #ifndef RTE_ARCH_64
408 : : rte_spinlock_t bf_sl;
409 : : rte_spinlock_t cq_sl;
410 : : /* UAR access locks required for 32bit implementations. */
411 : : #endif /* RTE_ARCH_64 */
412 : : };
413 : :
414 : : /**
415 : : * Ring a doorbell and flush the update if requested.
416 : : *
417 : : * @param uar
418 : : * Pointer to UAR data structure.
419 : : * @param val
420 : : * value to write in big endian format.
421 : : * @param index
422 : : * Index of doorbell record.
423 : : * @param db_rec
424 : : * Address of doorbell record.
425 : : * @param flash
426 : : * Decide whether to flush the DB writing using a memory barrier.
427 : : */
428 : : static __rte_always_inline void
429 : : mlx5_doorbell_ring(struct mlx5_uar_data *uar, uint64_t val, uint32_t index,
430 : : volatile uint32_t *db_rec, bool flash)
431 : : {
432 : 0 : rte_io_wmb();
433 [ # # # # : 0 : *db_rec = rte_cpu_to_be_32(index);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
434 : : /* Ensure ordering between DB record actual update and UAR access. */
435 : : rte_wmb();
436 : : #ifdef RTE_ARCH_64
437 : 0 : *uar->db = val;
438 : : #else /* !RTE_ARCH_64 */
439 : : rte_spinlock_lock(uar->sl_p);
440 : : *(volatile uint32_t *)uar->db = val;
441 : : rte_io_wmb();
442 : : *((volatile uint32_t *)uar->db + 1) = val >> 32;
443 : : rte_spinlock_unlock(uar->sl_p);
444 : : #endif
445 [ # # # # : 0 : if (flash)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
446 : : rte_wmb();
447 : : }
448 : :
449 : : /**
450 : : * Get the doorbell register mapping type.
451 : : *
452 : : * @param uar_mmap_offset
453 : : * Mmap offset of Verbs/DevX UAR.
454 : : * @param page_size
455 : : * System page size
456 : : *
457 : : * @return
458 : : * 1 for non-cached, 0 otherwise.
459 : : */
460 : : static inline uint16_t
461 : : mlx5_db_map_type_get(off_t uar_mmap_offset, size_t page_size)
462 : : {
463 : 0 : off_t cmd = uar_mmap_offset / page_size;
464 : :
465 : 0 : cmd >>= MLX5_UAR_MMAP_CMD_SHIFT;
466 : 0 : cmd &= MLX5_UAR_MMAP_CMD_MASK;
467 [ # # ]: 0 : if (cmd == MLX5_MMAP_GET_NC_PAGES_CMD)
468 : 0 : return 1;
469 : : return 0;
470 : : }
471 : :
472 : : __rte_internal
473 : : void mlx5_translate_port_name(const char *port_name_in,
474 : : struct mlx5_switch_info *port_info_out);
475 : : void mlx5_glue_constructor(void);
476 : : extern uint8_t haswell_broadwell_cpu;
477 : :
478 : : __rte_internal
479 : : void mlx5_common_init(void);
480 : :
481 : : /*
482 : : * Common Driver Interface
483 : : *
484 : : * ConnectX common driver supports multiple classes: net, vDPA, regex, crypto
485 : : * and compress devices. This layer enables creating such multiple classes
486 : : * on a single device by allowing to bind multiple class-specific device
487 : : * drivers to attach to the common driver.
488 : : *
489 : : * ------------ ------------- -------------- ----------------- ------------
490 : : * | mlx5 net | | mlx5 vdpa | | mlx5 regex | | mlx5 compress | | mlx5 ... |
491 : : * | driver | | driver | | driver | | driver | | drivers |
492 : : * ------------ ------------- -------------- ----------------- ------------
493 : : * ||
494 : : * -----------------
495 : : * | mlx5 |
496 : : * | common driver |
497 : : * -----------------
498 : : * | |
499 : : * ----------- -----------------
500 : : * | mlx5 | | mlx5 |
501 : : * | pci dev | | auxiliary dev |
502 : : * ----------- -----------------
503 : : *
504 : : * - mlx5 PCI bus driver binds to mlx5 PCI devices defined by PCI ID table
505 : : * of all related devices.
506 : : * - mlx5 class driver such as net, vDPA, regex defines its specific
507 : : * PCI ID table and mlx5 bus driver probes matching class drivers.
508 : : * - mlx5 common driver is central place that validates supported
509 : : * class combinations.
510 : : * - mlx5 common driver hides bus difference by resolving device address
511 : : * from devargs, locating target RDMA device and probing with it.
512 : : */
513 : :
514 : : /*
515 : : * Device configuration structure.
516 : : *
517 : : * Merged configuration from:
518 : : *
519 : : * - Device capabilities,
520 : : * - User device parameters disabled features.
521 : : */
522 : : struct mlx5_common_dev_config {
523 : : struct mlx5_hca_attr hca_attr; /* HCA attributes. */
524 : : int dbnc; /* Skip doorbell register write barrier. */
525 : : int device_fd; /* Device file descriptor for importation. */
526 : : int pd_handle; /* Protection Domain handle for importation. */
527 : : unsigned int devx:1; /* Whether devx interface is available or not. */
528 : : unsigned int sys_mem_en:1; /* The default memory allocator. */
529 : : unsigned int probe_opt:1; /* Optimize probing . */
530 : : unsigned int mr_mempool_reg_en:1;
531 : : /* Allow/prevent implicit mempool memory registration. */
532 : : unsigned int mr_ext_memseg_en:1;
533 : : /* Whether memseg should be extended for MR creation. */
534 : : };
535 : :
536 : : struct mlx5_common_device {
537 : : struct rte_device *dev;
538 : : TAILQ_ENTRY(mlx5_common_device) next;
539 : : uint32_t classes_loaded;
540 : : void *ctx; /* Verbs/DV/DevX context. */
541 : : void *pd; /* Protection Domain. */
542 : : struct mlx5_dev_info dev_info; /* Device port info queried via netlink. */
543 : : uint32_t pdn; /* Protection Domain Number. */
544 : : struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
545 : : struct mlx5_common_dev_config config; /* Device configuration. */
546 : : };
547 : :
548 : : /**
549 : : * Indicates whether PD and CTX are imported from another process,
550 : : * or created by this process.
551 : : *
552 : : * @param cdev
553 : : * Pointer to common device.
554 : : *
555 : : * @return
556 : : * True if PD and CTX are imported from another process, False otherwise.
557 : : */
558 : : static inline bool
559 : : mlx5_imported_pd_and_ctx(struct mlx5_common_device *cdev)
560 : : {
561 [ # # # # ]: 0 : return cdev->config.device_fd != MLX5_ARG_UNSET &&
562 [ # # ]: 0 : cdev->config.pd_handle != MLX5_ARG_UNSET;
563 : : }
564 : :
565 : : /**
566 : : * Initialization function for the driver called during device probing.
567 : : */
568 : : typedef int (mlx5_class_driver_probe_t)(struct mlx5_common_device *cdev,
569 : : struct mlx5_kvargs_ctrl *mkvlist);
570 : :
571 : : /**
572 : : * Uninitialization function for the driver called during hot-unplugging.
573 : : */
574 : : typedef int (mlx5_class_driver_remove_t)(struct mlx5_common_device *cdev);
575 : :
576 : : /** Device already probed can be probed again to check for new ports. */
577 : : #define MLX5_DRV_PROBE_AGAIN 0x0004
578 : :
579 : : /**
580 : : * A structure describing a mlx5 common class driver.
581 : : */
582 : : struct mlx5_class_driver {
583 : : TAILQ_ENTRY(mlx5_class_driver) next;
584 : : enum mlx5_class drv_class; /**< Class of this driver. */
585 : : const char *name; /**< Driver name. */
586 : : mlx5_class_driver_probe_t *probe; /**< Device probe function. */
587 : : mlx5_class_driver_remove_t *remove; /**< Device remove function. */
588 : : const struct rte_pci_id *id_table; /**< ID table, NULL terminated. */
589 : : uint32_t probe_again:1;
590 : : /**< Device already probed can be probed again to check new device. */
591 : : uint32_t intr_lsc:1; /**< Supports link state interrupt. */
592 : : uint32_t intr_rmv:1; /**< Supports device remove interrupt. */
593 : : };
594 : :
595 : : /**
596 : : * Register a mlx5 device driver.
597 : : *
598 : : * @param driver
599 : : * A pointer to a mlx5_driver structure describing the driver
600 : : * to be registered.
601 : : */
602 : : __rte_internal
603 : : void
604 : : mlx5_class_driver_register(struct mlx5_class_driver *driver);
605 : :
606 : : /**
607 : : * Test device is a PCI bus device.
608 : : *
609 : : * @param dev
610 : : * Pointer to device.
611 : : *
612 : : * @return
613 : : * - True on device devargs is a PCI bus device.
614 : : * - False otherwise.
615 : : */
616 : : __rte_internal
617 : : bool
618 : : mlx5_dev_is_pci(const struct rte_device *dev);
619 : :
620 : : /**
621 : : * Test PCI device is a VF device.
622 : : *
623 : : * @param pci_dev
624 : : * Pointer to PCI device.
625 : : *
626 : : * @return
627 : : * - True on PCI device is a VF device.
628 : : * - False otherwise.
629 : : */
630 : : __rte_internal
631 : : bool
632 : : mlx5_dev_is_vf_pci(const struct rte_pci_device *pci_dev);
633 : :
634 : : __rte_internal
635 : : int
636 : : mlx5_dev_mempool_subscribe(struct mlx5_common_device *cdev);
637 : :
638 : : __rte_internal
639 : : void
640 : : mlx5_dev_mempool_unregister(struct mlx5_common_device *cdev,
641 : : struct rte_mempool *mp);
642 : :
643 : : __rte_internal
644 : : int
645 : : mlx5_devx_uar_prepare(struct mlx5_common_device *cdev, struct mlx5_uar *uar);
646 : :
647 : : __rte_internal
648 : : void
649 : : mlx5_devx_uar_release(struct mlx5_uar *uar);
650 : :
651 : : /* mlx5_common_os.c */
652 : :
653 : : int mlx5_os_open_device(struct mlx5_common_device *cdev, uint32_t classes);
654 : : int mlx5_os_pd_prepare(struct mlx5_common_device *cdev);
655 : : int mlx5_os_pd_release(struct mlx5_common_device *cdev);
656 : : int mlx5_os_remote_pd_and_ctx_validate(struct mlx5_common_dev_config *config);
657 : :
658 : : /* mlx5 PMD wrapped MR struct. */
659 : : struct mlx5_pmd_wrapped_mr {
660 : : uint32_t lkey;
661 : : void *addr;
662 : : size_t len;
663 : : void *obj; /* verbs mr object or devx umem object. */
664 : : void *imkey; /* DevX indirect mkey object. */
665 : : };
666 : :
667 : : __rte_internal
668 : : int
669 : : mlx5_os_wrapped_mkey_create(void *ctx, void *pd, uint32_t pdn, void *addr,
670 : : size_t length, struct mlx5_pmd_wrapped_mr *pmd_mr);
671 : :
672 : : __rte_internal
673 : : void
674 : : mlx5_os_wrapped_mkey_destroy(struct mlx5_pmd_wrapped_mr *pmd_mr);
675 : :
676 : : #endif /* RTE_PMD_MLX5_COMMON_H_ */
|