New upstream version 17.11.5
[deb_dpdk.git] / drivers / net / mlx5 / mlx5.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2015 6WIND S.A.
5  *   Copyright 2015 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_MLX5_H_
35 #define RTE_PMD_MLX5_H_
36
37 #include <stddef.h>
38 #include <stdint.h>
39 #include <limits.h>
40 #include <net/if.h>
41 #include <netinet/in.h>
42 #include <sys/queue.h>
43
44 /* Verbs header. */
45 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
46 #ifdef PEDANTIC
47 #pragma GCC diagnostic ignored "-Wpedantic"
48 #endif
49 #include <infiniband/verbs.h>
50 #ifdef PEDANTIC
51 #pragma GCC diagnostic error "-Wpedantic"
52 #endif
53
54 #include <rte_pci.h>
55 #include <rte_ether.h>
56 #include <rte_ethdev.h>
57 #include <rte_spinlock.h>
58 #include <rte_interrupts.h>
59 #include <rte_errno.h>
60 #include <rte_flow.h>
61
62 #include "mlx5_utils.h"
63 #include "mlx5_rxtx.h"
64 #include "mlx5_autoconf.h"
65 #include "mlx5_defs.h"
66
67 enum {
68         PCI_VENDOR_ID_MELLANOX = 0x15b3,
69 };
70
71 enum {
72         PCI_DEVICE_ID_MELLANOX_CONNECTX4 = 0x1013,
73         PCI_DEVICE_ID_MELLANOX_CONNECTX4VF = 0x1014,
74         PCI_DEVICE_ID_MELLANOX_CONNECTX4LX = 0x1015,
75         PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF = 0x1016,
76         PCI_DEVICE_ID_MELLANOX_CONNECTX5 = 0x1017,
77         PCI_DEVICE_ID_MELLANOX_CONNECTX5VF = 0x1018,
78         PCI_DEVICE_ID_MELLANOX_CONNECTX5EX = 0x1019,
79         PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF = 0x101a,
80         PCI_DEVICE_ID_MELLANOX_CONNECTX5BF = 0xa2d2,
81 };
82
83 struct mlx5_xstats_ctrl {
84         /* Number of device stats. */
85         uint16_t stats_n;
86         /* Index in the device counters table. */
87         uint16_t dev_table_idx[MLX5_MAX_XSTATS];
88         uint64_t base[MLX5_MAX_XSTATS];
89 };
90
91 /* Flow list . */
92 TAILQ_HEAD(mlx5_flows, rte_flow);
93
94 /**
95  * Type of objet being allocated.
96  */
97 enum mlx5_verbs_alloc_type {
98         MLX5_VERBS_ALLOC_TYPE_NONE,
99         MLX5_VERBS_ALLOC_TYPE_TX_QUEUE,
100         MLX5_VERBS_ALLOC_TYPE_RX_QUEUE,
101 };
102
103 /**
104  * Verbs allocator needs a context to know in the callback which kind of
105  * resources it is allocating.
106  */
107 struct mlx5_verbs_alloc_ctx {
108         enum mlx5_verbs_alloc_type type; /* Kind of object being allocated. */
109         const void *obj; /* Pointer to the DPDK object. */
110 };
111
112 struct priv {
113         struct rte_eth_dev_data *dev_data;  /* Pointer to device data. */
114         struct ibv_context *ctx; /* Verbs context. */
115         struct ibv_device_attr_ex device_attr; /* Device properties. */
116         struct ibv_pd *pd; /* Protection Domain. */
117         char ibdev_path[IBV_SYSFS_PATH_MAX]; /* IB device path for secondary */
118         struct ether_addr mac[MLX5_MAX_MAC_ADDRESSES]; /* MAC addresses. */
119         uint16_t vlan_filter[MLX5_MAX_VLAN_IDS]; /* VLAN filters table. */
120         unsigned int vlan_filter_n; /* Number of configured VLAN filters. */
121         /* Device properties. */
122         uint16_t mtu; /* Configured MTU. */
123         uint8_t port; /* Physical port number. */
124         unsigned int hw_csum:1; /* Checksum offload is supported. */
125         unsigned int hw_csum_l2tun:1; /* Same for L2 tunnels. */
126         unsigned int hw_vlan_strip:1; /* VLAN stripping is supported. */
127         unsigned int hw_fcs_strip:1; /* FCS stripping is supported. */
128         unsigned int hw_padding:1; /* End alignment padding is supported. */
129         unsigned int mps:2; /* Multi-packet send mode (0: disabled). */
130         unsigned int mpw_hdr_dseg:1; /* Enable DSEGs in the title WQEBB. */
131         unsigned int cqe_comp:1; /* Whether CQE compression is enabled. */
132         unsigned int tso:1; /* Whether TSO is supported. */
133         unsigned int tunnel_en:1;
134         unsigned int isolated:1; /* Whether isolated mode is enabled. */
135         unsigned int tx_vec_en:1; /* Whether Tx vector is enabled. */
136         unsigned int rx_vec_en:1; /* Whether Rx vector is enabled. */
137         unsigned int counter_set_supported:1; /* Counter set is supported. */
138         /* Whether Tx offloads for tunneled packets are supported. */
139         unsigned int max_tso_payload_sz; /* Maximum TCP payload for TSO. */
140         unsigned int txq_inline; /* Maximum packet size for inlining. */
141         unsigned int txqs_inline; /* Queue number threshold for inlining. */
142         unsigned int txqs_vec; /* Queue number threshold for vectorized Tx. */
143         unsigned int inline_max_packet_sz; /* Max packet size for inlining. */
144         /* RX/TX queues. */
145         unsigned int rxqs_n; /* RX queues array size. */
146         unsigned int txqs_n; /* TX queues array size. */
147         struct mlx5_rxq_data *(*rxqs)[]; /* RX queues. */
148         struct mlx5_txq_data *(*txqs)[]; /* TX queues. */
149         unsigned int ind_table_max_size; /* Maximum indirection table size. */
150         struct rte_eth_rss_conf rss_conf; /* RSS configuration. */
151         struct rte_intr_handle intr_handle; /* Interrupt handler. */
152         unsigned int (*reta_idx)[]; /* RETA index table. */
153         unsigned int reta_idx_n; /* RETA index size. */
154         struct mlx5_hrxq_drop *flow_drop_queue; /* Flow drop queue. */
155         struct mlx5_flows flows; /* RTE Flow rules. */
156         struct mlx5_flows ctrl_flows; /* Control flow rules. */
157         struct mlx5_mr (*mr)[]; /* Static MR table. */
158         struct mlx5_mr_cache (*mr_cache)[]; /* Global MR cache table. */
159         unsigned int mr_n; /* Size of static MR table. */
160         LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */
161         LIST_HEAD(rxqibv, mlx5_rxq_ibv) rxqsibv; /* Verbs Rx queues. */
162         LIST_HEAD(hrxq, mlx5_hrxq) hrxqs; /* Verbs Hash Rx queues. */
163         LIST_HEAD(txq, mlx5_txq_ctrl) txqsctrl; /* DPDK Tx queues. */
164         LIST_HEAD(txqibv, mlx5_txq_ibv) txqsibv; /* Verbs Tx queues. */
165         /* Verbs Indirection tables. */
166         LIST_HEAD(ind_tables, mlx5_ind_table_ibv) ind_tbls;
167         uint32_t link_speed_capa; /* Link speed capabilities. */
168         struct mlx5_xstats_ctrl xstats_ctrl; /* Extended stats control. */
169         rte_spinlock_t mr_lock; /* MR Lock. */
170         int primary_socket; /* Unix socket for primary process. */
171         void *uar_base; /* Reserved address space for UAR mapping */
172         struct rte_intr_handle intr_handle_socket; /* Interrupt handler. */
173         struct mlx5_verbs_alloc_ctx verbs_alloc_ctx;
174         /* Context for Verbs allocator. */
175 };
176
177 #define PORT_ID(priv) ((priv)->dev_data->port_id)
178 #define ETH_DEV(priv) (&rte_eth_devices[PORT_ID(priv)])
179
180 /* mlx5.c */
181
182 int mlx5_getenv_int(const char *);
183
184 /* mlx5_ethdev.c */
185
186 int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]);
187 int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr);
188 int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);
189 int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep,
190                    unsigned int flags);
191 int mlx5_dev_configure(struct rte_eth_dev *dev);
192 void mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info);
193 const uint32_t *mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev);
194 int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete);
195 int mlx5_force_link_status_change(struct rte_eth_dev *dev, int status);
196 int mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
197 int mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev,
198                            struct rte_eth_fc_conf *fc_conf);
199 int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev,
200                            struct rte_eth_fc_conf *fc_conf);
201 int mlx5_ibv_device_to_pci_addr(const struct ibv_device *device,
202                                 struct rte_pci_addr *pci_addr);
203 void mlx5_dev_link_status_handler(void *arg);
204 void mlx5_dev_interrupt_handler(void *arg);
205 void mlx5_dev_interrupt_handler_uninstall(struct rte_eth_dev *dev);
206 void mlx5_dev_interrupt_handler_install(struct rte_eth_dev *dev);
207 int mlx5_set_link_down(struct rte_eth_dev *dev);
208 int mlx5_set_link_up(struct rte_eth_dev *dev);
209 eth_tx_burst_t mlx5_select_tx_function(struct rte_eth_dev *dev);
210 eth_rx_burst_t mlx5_select_rx_function(struct rte_eth_dev *dev);
211
212 /* mlx5_mac.c */
213
214 int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[ETHER_ADDR_LEN]);
215 void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
216 int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
217                       uint32_t index, uint32_t vmdq);
218 void mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr);
219
220 /* mlx5_rss.c */
221
222 int mlx5_rss_hash_update(struct rte_eth_dev *dev,
223                          struct rte_eth_rss_conf *rss_conf);
224 int mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
225                            struct rte_eth_rss_conf *rss_conf);
226 int mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size);
227 int mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
228                             struct rte_eth_rss_reta_entry64 *reta_conf,
229                             uint16_t reta_size);
230 int mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
231                              struct rte_eth_rss_reta_entry64 *reta_conf,
232                              uint16_t reta_size);
233
234 /* mlx5_rxmode.c */
235
236 void mlx5_promiscuous_enable(struct rte_eth_dev *dev);
237 void mlx5_promiscuous_disable(struct rte_eth_dev *dev);
238 void mlx5_allmulticast_enable(struct rte_eth_dev *dev);
239 void mlx5_allmulticast_disable(struct rte_eth_dev *dev);
240
241 /* mlx5_stats.c */
242
243 void mlx5_xstats_init(struct rte_eth_dev *dev);
244 int mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
245 void mlx5_stats_reset(struct rte_eth_dev *dev);
246 int mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
247                     unsigned int n);
248 void mlx5_xstats_reset(struct rte_eth_dev *dev);
249 int mlx5_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
250                           struct rte_eth_xstat_name *xstats_names,
251                           unsigned int n);
252
253 /* mlx5_vlan.c */
254
255 int mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
256 void mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on);
257 int mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask);
258
259 /* mlx5_trigger.c */
260
261 int mlx5_dev_start(struct rte_eth_dev *dev);
262 void mlx5_dev_stop(struct rte_eth_dev *dev);
263 int mlx5_traffic_enable(struct rte_eth_dev *dev);
264 void mlx5_traffic_disable(struct rte_eth_dev *dev);
265 int mlx5_traffic_restart(struct rte_eth_dev *dev);
266
267 /* mlx5_flow.c */
268
269 int mlx5_flow_validate(struct rte_eth_dev *dev,
270                        const struct rte_flow_attr *attr,
271                        const struct rte_flow_item items[],
272                        const struct rte_flow_action actions[],
273                        struct rte_flow_error *error);
274 struct rte_flow *mlx5_flow_create(struct rte_eth_dev *dev,
275                                   const struct rte_flow_attr *attr,
276                                   const struct rte_flow_item items[],
277                                   const struct rte_flow_action actions[],
278                                   struct rte_flow_error *error);
279 int mlx5_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
280                       struct rte_flow_error *error);
281 void mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list);
282 int mlx5_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
283 int mlx5_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow,
284                     enum rte_flow_action_type action, void *data,
285                     struct rte_flow_error *error);
286 int mlx5_flow_isolate(struct rte_eth_dev *dev, int enable,
287                       struct rte_flow_error *error);
288 int mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
289                          enum rte_filter_type filter_type,
290                          enum rte_filter_op filter_op,
291                          void *arg);
292 int mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list);
293 void mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list);
294 int mlx5_flow_verify(struct rte_eth_dev *dev);
295 int mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
296                         struct rte_flow_item_eth *eth_spec,
297                         struct rte_flow_item_eth *eth_mask,
298                         struct rte_flow_item_vlan *vlan_spec,
299                         struct rte_flow_item_vlan *vlan_mask);
300 int mlx5_ctrl_flow(struct rte_eth_dev *dev,
301                    struct rte_flow_item_eth *eth_spec,
302                    struct rte_flow_item_eth *eth_mask);
303 int mlx5_flow_create_drop_queue(struct rte_eth_dev *dev);
304 void mlx5_flow_delete_drop_queue(struct rte_eth_dev *dev);
305
306 /* mlx5_socket.c */
307
308 int mlx5_socket_init(struct rte_eth_dev *dev);
309 void mlx5_socket_uninit(struct rte_eth_dev *dev);
310 void mlx5_socket_handle(struct rte_eth_dev *dev);
311 int mlx5_socket_connect(struct rte_eth_dev *dev);
312
313 /* mlx5_mr.c */
314
315 int mlx5_mr_register_memseg(struct rte_eth_dev *dev);
316 void mlx5_mr_deregister_memseg(struct rte_eth_dev *dev);
317
318 #endif /* RTE_PMD_MLX5_H_ */