mlx4: move to drivers/net/
[dpdk.git] / 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 /* Maximum number of Scatter/Gather Elements per Work Request. */
55 #ifndef MLX4_PMD_SGE_WR_N
56 #define MLX4_PMD_SGE_WR_N 4
57 #endif
58
59 /* Maximum size for inline data. */
60 #ifndef MLX4_PMD_MAX_INLINE
61 #define MLX4_PMD_MAX_INLINE 0
62 #endif
63
64 /*
65  * Maximum number of cached Memory Pools (MPs) per TX queue. Each RTE MP
66  * from which buffers are to be transmitted will have to be mapped by this
67  * driver to their own Memory Region (MR). This is a slow operation.
68  *
69  * This value is always 1 for RX queues.
70  */
71 #ifndef MLX4_PMD_TX_MP_CACHE
72 #define MLX4_PMD_TX_MP_CACHE 8
73 #endif
74
75 /*
76  * If defined, only use software counters. The PMD will never ask the hardware
77  * for these, and many of them won't be available.
78  */
79 #ifndef MLX4_PMD_SOFT_COUNTERS
80 #define MLX4_PMD_SOFT_COUNTERS 1
81 #endif
82
83 enum {
84         PCI_VENDOR_ID_MELLANOX = 0x15b3,
85 };
86
87 enum {
88         PCI_DEVICE_ID_MELLANOX_CONNECTX3 = 0x1003,
89         PCI_DEVICE_ID_MELLANOX_CONNECTX3VF = 0x1004,
90         PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO = 0x1007,
91 };
92
93 #define MLX4_DRIVER_NAME "librte_pmd_mlx4"
94
95 /* Bit-field manipulation. */
96 #define BITFIELD_DECLARE(bf, type, size)                                \
97         type bf[(((size_t)(size) / (sizeof(type) * CHAR_BIT)) +         \
98                  !!((size_t)(size) % (sizeof(type) * CHAR_BIT)))]
99 #define BITFIELD_DEFINE(bf, type, size)                                 \
100         BITFIELD_DECLARE((bf), type, (size)) = { 0 }
101 #define BITFIELD_SET(bf, b)                                             \
102         (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)),                 \
103          (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] |=           \
104                 ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
105 #define BITFIELD_RESET(bf, b)                                           \
106         (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)),                 \
107          (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] &=           \
108                 ~((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
109 #define BITFIELD_ISSET(bf, b)                                           \
110         (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)),                 \
111          !!(((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] &               \
112              ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))))
113
114 /* Number of elements in array. */
115 #define elemof(a) (sizeof(a) / sizeof((a)[0]))
116
117 /* Cast pointer p to structure member m to its parent structure of type t. */
118 #define containerof(p, t, m) ((t *)((uint8_t *)(p) - offsetof(t, m)))
119
120 /* Branch prediction helpers. */
121 #ifndef likely
122 #define likely(c) __builtin_expect(!!(c), 1)
123 #endif
124 #ifndef unlikely
125 #define unlikely(c) __builtin_expect(!!(c), 0)
126 #endif
127
128 /* Debugging */
129 #ifndef NDEBUG
130 #include <stdio.h>
131 #define DEBUG__(m, ...)                                         \
132         (fprintf(stderr, "%s:%d: %s(): " m "%c",                \
133                  __FILE__, __LINE__, __func__, __VA_ARGS__),    \
134          fflush(stderr),                                        \
135          (void)0)
136 /*
137  * Save/restore errno around DEBUG__().
138  * XXX somewhat undefined behavior, but works.
139  */
140 #define DEBUG_(...)                             \
141         (errno = ((int []){                     \
142                 *(volatile int *)&errno,        \
143                 (DEBUG__(__VA_ARGS__), 0)       \
144         })[0])
145 #define DEBUG(...) DEBUG_(__VA_ARGS__, '\n')
146 #define claim_zero(...) assert((__VA_ARGS__) == 0)
147 #define claim_nonzero(...) assert((__VA_ARGS__) != 0)
148 #define claim_positive(...) assert((__VA_ARGS__) >= 0)
149 #else /* NDEBUG */
150 /* No-ops. */
151 #define DEBUG(...) (void)0
152 #define claim_zero(...) (__VA_ARGS__)
153 #define claim_nonzero(...) (__VA_ARGS__)
154 #define claim_positive(...) (__VA_ARGS__)
155 #endif /* NDEBUG */
156
157 #endif /* RTE_PMD_MLX4_H_ */