4 * Copyright 2012-2015 6WIND S.A.
5 * Copyright 2012 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #ifndef RTE_PMD_MLX4_H_
35 #define RTE_PMD_MLX4_H_
42 * Maximum number of simultaneous MAC addresses supported.
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
49 #define MLX4_MAX_MAC_ADDRESSES 128
51 /* Maximum number of simultaneous VLAN filters supported. See above. */
52 #define MLX4_MAX_VLAN_IDS 127
54 /* Request send completion once in every 64 sends, might be less. */
55 #define MLX4_PMD_TX_PER_COMP_REQ 64
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
62 /* Maximum size for inline data. */
63 #ifndef MLX4_PMD_MAX_INLINE
64 #define MLX4_PMD_MAX_INLINE 0
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.
72 * This value is always 1 for RX queues.
74 #ifndef MLX4_PMD_TX_MP_CACHE
75 #define MLX4_PMD_TX_MP_CACHE 8
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.
82 #ifndef MLX4_PMD_SOFT_COUNTERS
83 #define MLX4_PMD_SOFT_COUNTERS 1
87 #define MLX4_ALARM_TIMEOUT_US 100000
90 PCI_VENDOR_ID_MELLANOX = 0x15b3,
94 PCI_DEVICE_ID_MELLANOX_CONNECTX3 = 0x1003,
95 PCI_DEVICE_ID_MELLANOX_CONNECTX3VF = 0x1004,
96 PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO = 0x1007,
99 #define MLX4_DRIVER_NAME "librte_pmd_mlx4"
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))))))
120 /* Number of elements in array. */
121 #define elemof(a) (sizeof(a) / sizeof((a)[0]))
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)))
126 /* Branch prediction helpers. */
128 #define likely(c) __builtin_expect(!!(c), 1)
131 #define unlikely(c) __builtin_expect(!!(c), 0)
137 #define DEBUG__(m, ...) \
138 (fprintf(stderr, "%s:%d: %s(): " m "%c", \
139 __FILE__, __LINE__, __func__, __VA_ARGS__), \
143 * Save/restore errno around DEBUG__().
144 * XXX somewhat undefined behavior, but works.
146 #define DEBUG_(...) \
147 (errno = ((int []){ \
148 *(volatile int *)&errno, \
149 (DEBUG__(__VA_ARGS__), 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)
157 #define DEBUG(...) (void)0
158 #define claim_zero(...) (__VA_ARGS__)
159 #define claim_nonzero(...) (__VA_ARGS__)
160 #define claim_positive(...) (__VA_ARGS__)
163 #endif /* RTE_PMD_MLX4_H_ */