]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/drivers/net/mlx4/mlx4.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / dpdk / drivers / net / mlx4 / mlx4.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright 2012-2015 6WIND S.A.
5 * Copyright 2012 Mellanox.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef RTE_PMD_MLX4_H_
35 #define RTE_PMD_MLX4_H_
36
37 #include <stddef.h>
38 #include <stdint.h>
39 #include <limits.h>
40
41 /*
42 * Maximum number of simultaneous MAC addresses supported.
43 *
44 * According to ConnectX's Programmer Reference Manual:
45 * The L2 Address Match is implemented by comparing a MAC/VLAN combination
46 * of 128 MAC addresses and 127 VLAN values, comprising 128x127 possible
47 * L2 addresses.
48 */
49 #define MLX4_MAX_MAC_ADDRESSES 128
50
51 /* Maximum number of simultaneous VLAN filters supported. See above. */
52 #define MLX4_MAX_VLAN_IDS 127
53
54 /* Request send completion once in every 64 sends, might be less. */
55 #define MLX4_PMD_TX_PER_COMP_REQ 64
56
57 /* Maximum number of Scatter/Gather Elements per Work Request. */
58 #ifndef MLX4_PMD_SGE_WR_N
59 #define MLX4_PMD_SGE_WR_N 4
60 #endif
61
62 /* Maximum size for inline data. */
63 #ifndef MLX4_PMD_MAX_INLINE
64 #define MLX4_PMD_MAX_INLINE 0
65 #endif
66
67 /*
68 * Maximum number of cached Memory Pools (MPs) per TX queue. Each RTE MP
69 * from which buffers are to be transmitted will have to be mapped by this
70 * driver to their own Memory Region (MR). This is a slow operation.
71 *
72 * This value is always 1 for RX queues.
73 */
74 #ifndef MLX4_PMD_TX_MP_CACHE
75 #define MLX4_PMD_TX_MP_CACHE 8
76 #endif
77
78 /*
79 * If defined, only use software counters. The PMD will never ask the hardware
80 * for these, and many of them won't be available.
81 */
82 #ifndef MLX4_PMD_SOFT_COUNTERS
83 #define MLX4_PMD_SOFT_COUNTERS 1
84 #endif
85
86 /* Alarm timeout. */
87 #define MLX4_ALARM_TIMEOUT_US 100000
88
89 enum {
90 PCI_VENDOR_ID_MELLANOX = 0x15b3,
91 };
92
93 enum {
94 PCI_DEVICE_ID_MELLANOX_CONNECTX3 = 0x1003,
95 PCI_DEVICE_ID_MELLANOX_CONNECTX3VF = 0x1004,
96 PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO = 0x1007,
97 };
98
99 #define MLX4_DRIVER_NAME "net_mlx4"
100
101 /* Bit-field manipulation. */
102 #define BITFIELD_DECLARE(bf, type, size) \
103 type bf[(((size_t)(size) / (sizeof(type) * CHAR_BIT)) + \
104 !!((size_t)(size) % (sizeof(type) * CHAR_BIT)))]
105 #define BITFIELD_DEFINE(bf, type, size) \
106 BITFIELD_DECLARE((bf), type, (size)) = { 0 }
107 #define BITFIELD_SET(bf, b) \
108 (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \
109 (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] |= \
110 ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
111 #define BITFIELD_RESET(bf, b) \
112 (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \
113 (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] &= \
114 ~((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
115 #define BITFIELD_ISSET(bf, b) \
116 (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \
117 !!(((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] & \
118 ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))))
119
120 /* Number of elements in array. */
121 #define elemof(a) (sizeof(a) / sizeof((a)[0]))
122
123 /* Cast pointer p to structure member m to its parent structure of type t. */
124 #define containerof(p, t, m) ((t *)((uint8_t *)(p) - offsetof(t, m)))
125
126 /* Branch prediction helpers. */
127 #ifndef likely
128 #define likely(c) __builtin_expect(!!(c), 1)
129 #endif
130 #ifndef unlikely
131 #define unlikely(c) __builtin_expect(!!(c), 0)
132 #endif
133
134 /* Debugging */
135 #ifndef NDEBUG
136 #include <stdio.h>
137 #define DEBUG__(m, ...) \
138 (fprintf(stderr, "%s:%d: %s(): " m "%c", \
139 __FILE__, __LINE__, __func__, __VA_ARGS__), \
140 fflush(stderr), \
141 (void)0)
142 /*
143 * Save/restore errno around DEBUG__().
144 * XXX somewhat undefined behavior, but works.
145 */
146 #define DEBUG_(...) \
147 (errno = ((int []){ \
148 *(volatile int *)&errno, \
149 (DEBUG__(__VA_ARGS__), 0) \
150 })[0])
151 #define DEBUG(...) DEBUG_(__VA_ARGS__, '\n')
152 #define claim_zero(...) assert((__VA_ARGS__) == 0)
153 #define claim_nonzero(...) assert((__VA_ARGS__) != 0)
154 #define claim_positive(...) assert((__VA_ARGS__) >= 0)
155 #else /* NDEBUG */
156 /* No-ops. */
157 #define DEBUG(...) (void)0
158 #define claim_zero(...) (__VA_ARGS__)
159 #define claim_nonzero(...) (__VA_ARGS__)
160 #define claim_positive(...) (__VA_ARGS__)
161 #endif /* NDEBUG */
162
163 #endif /* RTE_PMD_MLX4_H_ */