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