net/mlx5: update prerequisites for upcoming enhancements
[dpdk.git] / drivers / net / mlx5 / mlx5.c
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 #include <stddef.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <assert.h>
38 #include <stdint.h>
39 #include <stdlib.h>
40 #include <net/if.h>
41
42 /* Verbs header. */
43 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
44 #ifdef PEDANTIC
45 #pragma GCC diagnostic ignored "-pedantic"
46 #endif
47 #include <infiniband/verbs.h>
48 #ifdef PEDANTIC
49 #pragma GCC diagnostic error "-pedantic"
50 #endif
51
52 /* DPDK headers don't like -pedantic. */
53 #ifdef PEDANTIC
54 #pragma GCC diagnostic ignored "-pedantic"
55 #endif
56 #include <rte_malloc.h>
57 #include <rte_ethdev.h>
58 #include <rte_pci.h>
59 #include <rte_common.h>
60 #ifdef PEDANTIC
61 #pragma GCC diagnostic error "-pedantic"
62 #endif
63
64 #include "mlx5.h"
65 #include "mlx5_utils.h"
66 #include "mlx5_rxtx.h"
67 #include "mlx5_autoconf.h"
68 #include "mlx5_defs.h"
69
70 /**
71  * Retrieve integer value from environment variable.
72  *
73  * @param[in] name
74  *   Environment variable name.
75  *
76  * @return
77  *   Integer value, 0 if the variable is not set.
78  */
79 int
80 mlx5_getenv_int(const char *name)
81 {
82         const char *val = getenv(name);
83
84         if (val == NULL)
85                 return 0;
86         return atoi(val);
87 }
88
89 /**
90  * DPDK callback to close the device.
91  *
92  * Destroy all queues and objects, free memory.
93  *
94  * @param dev
95  *   Pointer to Ethernet device structure.
96  */
97 static void
98 mlx5_dev_close(struct rte_eth_dev *dev)
99 {
100         struct priv *priv = mlx5_get_priv(dev);
101         unsigned int i;
102
103         priv_lock(priv);
104         DEBUG("%p: closing device \"%s\"",
105               (void *)dev,
106               ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
107         /* In case mlx5_dev_stop() has not been called. */
108         priv_dev_interrupt_handler_uninstall(priv, dev);
109         priv_special_flow_disable_all(priv);
110         priv_mac_addrs_disable(priv);
111         priv_destroy_hash_rxqs(priv);
112
113         /* Remove flow director elements. */
114         priv_fdir_disable(priv);
115         priv_fdir_delete_filters_list(priv);
116
117         /* Prevent crashes when queues are still in use. */
118         dev->rx_pkt_burst = removed_rx_burst;
119         dev->tx_pkt_burst = removed_tx_burst;
120         if (priv->rxqs != NULL) {
121                 /* XXX race condition if mlx5_rx_burst() is still running. */
122                 usleep(1000);
123                 for (i = 0; (i != priv->rxqs_n); ++i) {
124                         struct rxq *rxq = (*priv->rxqs)[i];
125                         struct rxq_ctrl *rxq_ctrl;
126
127                         if (rxq == NULL)
128                                 continue;
129                         rxq_ctrl = container_of(rxq, struct rxq_ctrl, rxq);
130                         (*priv->rxqs)[i] = NULL;
131                         rxq_cleanup(rxq_ctrl);
132                         rte_free(rxq_ctrl);
133                 }
134                 priv->rxqs_n = 0;
135                 priv->rxqs = NULL;
136         }
137         if (priv->txqs != NULL) {
138                 /* XXX race condition if mlx5_tx_burst() is still running. */
139                 usleep(1000);
140                 for (i = 0; (i != priv->txqs_n); ++i) {
141                         struct txq *txq = (*priv->txqs)[i];
142                         struct txq_ctrl *txq_ctrl;
143
144                         if (txq == NULL)
145                                 continue;
146                         txq_ctrl = container_of(txq, struct txq_ctrl, txq);
147                         (*priv->txqs)[i] = NULL;
148                         txq_cleanup(txq_ctrl);
149                         rte_free(txq_ctrl);
150                 }
151                 priv->txqs_n = 0;
152                 priv->txqs = NULL;
153         }
154         if (priv->pd != NULL) {
155                 assert(priv->ctx != NULL);
156                 claim_zero(ibv_dealloc_pd(priv->pd));
157                 claim_zero(ibv_close_device(priv->ctx));
158         } else
159                 assert(priv->ctx == NULL);
160         if (priv->rss_conf != NULL) {
161                 for (i = 0; (i != hash_rxq_init_n); ++i)
162                         rte_free((*priv->rss_conf)[i]);
163                 rte_free(priv->rss_conf);
164         }
165         if (priv->reta_idx != NULL)
166                 rte_free(priv->reta_idx);
167         priv_unlock(priv);
168         memset(priv, 0, sizeof(*priv));
169 }
170
171 static const struct eth_dev_ops mlx5_dev_ops = {
172         .dev_configure = mlx5_dev_configure,
173         .dev_start = mlx5_dev_start,
174         .dev_stop = mlx5_dev_stop,
175         .dev_set_link_down = mlx5_set_link_down,
176         .dev_set_link_up = mlx5_set_link_up,
177         .dev_close = mlx5_dev_close,
178         .promiscuous_enable = mlx5_promiscuous_enable,
179         .promiscuous_disable = mlx5_promiscuous_disable,
180         .allmulticast_enable = mlx5_allmulticast_enable,
181         .allmulticast_disable = mlx5_allmulticast_disable,
182         .link_update = mlx5_link_update,
183         .stats_get = mlx5_stats_get,
184         .stats_reset = mlx5_stats_reset,
185         .dev_infos_get = mlx5_dev_infos_get,
186         .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
187         .vlan_filter_set = mlx5_vlan_filter_set,
188         .rx_queue_setup = mlx5_rx_queue_setup,
189         .tx_queue_setup = mlx5_tx_queue_setup,
190         .rx_queue_release = mlx5_rx_queue_release,
191         .tx_queue_release = mlx5_tx_queue_release,
192         .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
193         .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
194         .mac_addr_remove = mlx5_mac_addr_remove,
195         .mac_addr_add = mlx5_mac_addr_add,
196         .mac_addr_set = mlx5_mac_addr_set,
197         .mtu_set = mlx5_dev_set_mtu,
198         .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
199         .vlan_offload_set = mlx5_vlan_offload_set,
200         .reta_update = mlx5_dev_rss_reta_update,
201         .reta_query = mlx5_dev_rss_reta_query,
202         .rss_hash_update = mlx5_rss_hash_update,
203         .rss_hash_conf_get = mlx5_rss_hash_conf_get,
204         .filter_ctrl = mlx5_dev_filter_ctrl,
205 };
206
207 static struct {
208         struct rte_pci_addr pci_addr; /* associated PCI address */
209         uint32_t ports; /* physical ports bitfield. */
210 } mlx5_dev[32];
211
212 /**
213  * Get device index in mlx5_dev[] from PCI bus address.
214  *
215  * @param[in] pci_addr
216  *   PCI bus address to look for.
217  *
218  * @return
219  *   mlx5_dev[] index on success, -1 on failure.
220  */
221 static int
222 mlx5_dev_idx(struct rte_pci_addr *pci_addr)
223 {
224         unsigned int i;
225         int ret = -1;
226
227         assert(pci_addr != NULL);
228         for (i = 0; (i != RTE_DIM(mlx5_dev)); ++i) {
229                 if ((mlx5_dev[i].pci_addr.domain == pci_addr->domain) &&
230                     (mlx5_dev[i].pci_addr.bus == pci_addr->bus) &&
231                     (mlx5_dev[i].pci_addr.devid == pci_addr->devid) &&
232                     (mlx5_dev[i].pci_addr.function == pci_addr->function))
233                         return i;
234                 if ((mlx5_dev[i].ports == 0) && (ret == -1))
235                         ret = i;
236         }
237         return ret;
238 }
239
240 static struct eth_driver mlx5_driver;
241
242 /**
243  * DPDK callback to register a PCI device.
244  *
245  * This function creates an Ethernet device for each port of a given
246  * PCI device.
247  *
248  * @param[in] pci_drv
249  *   PCI driver structure (mlx5_driver).
250  * @param[in] pci_dev
251  *   PCI device information.
252  *
253  * @return
254  *   0 on success, negative errno value on failure.
255  */
256 static int
257 mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
258 {
259         struct ibv_device **list;
260         struct ibv_device *ibv_dev;
261         int err = 0;
262         struct ibv_context *attr_ctx = NULL;
263         struct ibv_device_attr device_attr;
264         unsigned int sriov;
265         unsigned int mps;
266         int idx;
267         int i;
268
269         (void)pci_drv;
270         assert(pci_drv == &mlx5_driver.pci_drv);
271         /* Get mlx5_dev[] index. */
272         idx = mlx5_dev_idx(&pci_dev->addr);
273         if (idx == -1) {
274                 ERROR("this driver cannot support any more adapters");
275                 return -ENOMEM;
276         }
277         DEBUG("using driver device index %d", idx);
278
279         /* Save PCI address. */
280         mlx5_dev[idx].pci_addr = pci_dev->addr;
281         list = ibv_get_device_list(&i);
282         if (list == NULL) {
283                 assert(errno);
284                 if (errno == ENOSYS) {
285                         WARN("cannot list devices, is ib_uverbs loaded?");
286                         return 0;
287                 }
288                 return -errno;
289         }
290         assert(i >= 0);
291         /*
292          * For each listed device, check related sysfs entry against
293          * the provided PCI ID.
294          */
295         while (i != 0) {
296                 struct rte_pci_addr pci_addr;
297
298                 --i;
299                 DEBUG("checking device \"%s\"", list[i]->name);
300                 if (mlx5_ibv_device_to_pci_addr(list[i], &pci_addr))
301                         continue;
302                 if ((pci_dev->addr.domain != pci_addr.domain) ||
303                     (pci_dev->addr.bus != pci_addr.bus) ||
304                     (pci_dev->addr.devid != pci_addr.devid) ||
305                     (pci_dev->addr.function != pci_addr.function))
306                         continue;
307                 sriov = ((pci_dev->id.device_id ==
308                        PCI_DEVICE_ID_MELLANOX_CONNECTX4VF) ||
309                       (pci_dev->id.device_id ==
310                        PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF));
311                 /* Multi-packet send is only supported by ConnectX-4 Lx PF. */
312                 mps = (pci_dev->id.device_id ==
313                        PCI_DEVICE_ID_MELLANOX_CONNECTX4LX);
314                 INFO("PCI information matches, using device \"%s\""
315                      " (SR-IOV: %s, MPS: %s)",
316                      list[i]->name,
317                      sriov ? "true" : "false",
318                      mps ? "true" : "false");
319                 attr_ctx = ibv_open_device(list[i]);
320                 err = errno;
321                 break;
322         }
323         if (attr_ctx == NULL) {
324                 ibv_free_device_list(list);
325                 switch (err) {
326                 case 0:
327                         WARN("cannot access device, is mlx5_ib loaded?");
328                         return 0;
329                 case EINVAL:
330                         WARN("cannot use device, are drivers up to date?");
331                         return 0;
332                 }
333                 assert(err > 0);
334                 return -err;
335         }
336         ibv_dev = list[i];
337
338         DEBUG("device opened");
339         if (ibv_query_device(attr_ctx, &device_attr))
340                 goto error;
341         INFO("%u port(s) detected", device_attr.phys_port_cnt);
342
343         for (i = 0; i < device_attr.phys_port_cnt; i++) {
344                 uint32_t port = i + 1; /* ports are indexed from one */
345                 uint32_t test = (1 << i);
346                 struct ibv_context *ctx = NULL;
347                 struct ibv_port_attr port_attr;
348                 struct ibv_pd *pd = NULL;
349                 struct priv *priv = NULL;
350                 struct rte_eth_dev *eth_dev;
351                 struct ibv_exp_device_attr exp_device_attr;
352                 struct ether_addr mac;
353                 uint16_t num_vfs = 0;
354
355                 exp_device_attr.comp_mask =
356                         IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS |
357                         IBV_EXP_DEVICE_ATTR_RX_HASH |
358                         IBV_EXP_DEVICE_ATTR_VLAN_OFFLOADS |
359                         IBV_EXP_DEVICE_ATTR_RX_PAD_END_ALIGN |
360                         0;
361
362                 DEBUG("using port %u (%08" PRIx32 ")", port, test);
363
364                 ctx = ibv_open_device(ibv_dev);
365                 if (ctx == NULL)
366                         goto port_error;
367
368                 /* Check port status. */
369                 err = ibv_query_port(ctx, port, &port_attr);
370                 if (err) {
371                         ERROR("port query failed: %s", strerror(err));
372                         goto port_error;
373                 }
374
375                 if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
376                         ERROR("port %d is not configured in Ethernet mode",
377                               port);
378                         goto port_error;
379                 }
380
381                 if (port_attr.state != IBV_PORT_ACTIVE)
382                         DEBUG("port %d is not active: \"%s\" (%d)",
383                               port, ibv_port_state_str(port_attr.state),
384                               port_attr.state);
385
386                 /* Allocate protection domain. */
387                 pd = ibv_alloc_pd(ctx);
388                 if (pd == NULL) {
389                         ERROR("PD allocation failure");
390                         err = ENOMEM;
391                         goto port_error;
392                 }
393
394                 mlx5_dev[idx].ports |= test;
395
396                 /* from rte_ethdev.c */
397                 priv = rte_zmalloc("ethdev private structure",
398                                    sizeof(*priv),
399                                    RTE_CACHE_LINE_SIZE);
400                 if (priv == NULL) {
401                         ERROR("priv allocation failure");
402                         err = ENOMEM;
403                         goto port_error;
404                 }
405
406                 priv->ctx = ctx;
407                 priv->device_attr = device_attr;
408                 priv->port = port;
409                 priv->pd = pd;
410                 priv->mtu = ETHER_MTU;
411                 if (ibv_exp_query_device(ctx, &exp_device_attr)) {
412                         ERROR("ibv_exp_query_device() failed");
413                         goto port_error;
414                 }
415
416                 priv->hw_csum =
417                         ((exp_device_attr.exp_device_cap_flags &
418                           IBV_EXP_DEVICE_RX_CSUM_TCP_UDP_PKT) &&
419                          (exp_device_attr.exp_device_cap_flags &
420                           IBV_EXP_DEVICE_RX_CSUM_IP_PKT));
421                 DEBUG("checksum offloading is %ssupported",
422                       (priv->hw_csum ? "" : "not "));
423
424                 priv->hw_csum_l2tun = !!(exp_device_attr.exp_device_cap_flags &
425                                          IBV_EXP_DEVICE_VXLAN_SUPPORT);
426                 DEBUG("L2 tunnel checksum offloads are %ssupported",
427                       (priv->hw_csum_l2tun ? "" : "not "));
428
429                 priv->ind_table_max_size = exp_device_attr.rx_hash_caps.max_rwq_indirection_table_size;
430                 /* Remove this check once DPDK supports larger/variable
431                  * indirection tables. */
432                 if (priv->ind_table_max_size > (unsigned int)RSS_INDIRECTION_TABLE_SIZE)
433                         priv->ind_table_max_size = RSS_INDIRECTION_TABLE_SIZE;
434                 DEBUG("maximum RX indirection table size is %u",
435                       priv->ind_table_max_size);
436                 priv->hw_vlan_strip = !!(exp_device_attr.wq_vlan_offloads_cap &
437                                          IBV_EXP_RECEIVE_WQ_CVLAN_STRIP);
438                 DEBUG("VLAN stripping is %ssupported",
439                       (priv->hw_vlan_strip ? "" : "not "));
440
441                 priv->hw_fcs_strip = !!(exp_device_attr.exp_device_cap_flags &
442                                         IBV_EXP_DEVICE_SCATTER_FCS);
443                 DEBUG("FCS stripping configuration is %ssupported",
444                       (priv->hw_fcs_strip ? "" : "not "));
445
446                 priv->hw_padding = !!exp_device_attr.rx_pad_end_addr_align;
447                 DEBUG("hardware RX end alignment padding is %ssupported",
448                       (priv->hw_padding ? "" : "not "));
449
450                 priv_get_num_vfs(priv, &num_vfs);
451                 priv->sriov = (num_vfs || sriov);
452                 priv->mps = mps;
453                 /* Allocate and register default RSS hash keys. */
454                 priv->rss_conf = rte_calloc(__func__, hash_rxq_init_n,
455                                             sizeof((*priv->rss_conf)[0]), 0);
456                 if (priv->rss_conf == NULL) {
457                         err = ENOMEM;
458                         goto port_error;
459                 }
460                 err = rss_hash_rss_conf_new_key(priv,
461                                                 rss_hash_default_key,
462                                                 rss_hash_default_key_len,
463                                                 ETH_RSS_PROTO_MASK);
464                 if (err)
465                         goto port_error;
466                 /* Configure the first MAC address by default. */
467                 if (priv_get_mac(priv, &mac.addr_bytes)) {
468                         ERROR("cannot get MAC address, is mlx5_en loaded?"
469                               " (errno: %s)", strerror(errno));
470                         goto port_error;
471                 }
472                 INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x",
473                      priv->port,
474                      mac.addr_bytes[0], mac.addr_bytes[1],
475                      mac.addr_bytes[2], mac.addr_bytes[3],
476                      mac.addr_bytes[4], mac.addr_bytes[5]);
477                 /* Register MAC address. */
478                 claim_zero(priv_mac_addr_add(priv, 0,
479                                              (const uint8_t (*)[ETHER_ADDR_LEN])
480                                              mac.addr_bytes));
481                 /* Initialize FD filters list. */
482                 err = fdir_init_filters_list(priv);
483                 if (err)
484                         goto port_error;
485 #ifndef NDEBUG
486                 {
487                         char ifname[IF_NAMESIZE];
488
489                         if (priv_get_ifname(priv, &ifname) == 0)
490                                 DEBUG("port %u ifname is \"%s\"",
491                                       priv->port, ifname);
492                         else
493                                 DEBUG("port %u ifname is unknown", priv->port);
494                 }
495 #endif
496                 /* Get actual MTU if possible. */
497                 priv_get_mtu(priv, &priv->mtu);
498                 DEBUG("port %u MTU is %u", priv->port, priv->mtu);
499
500                 /* from rte_ethdev.c */
501                 {
502                         char name[RTE_ETH_NAME_MAX_LEN];
503
504                         snprintf(name, sizeof(name), "%s port %u",
505                                  ibv_get_device_name(ibv_dev), port);
506                         eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
507                 }
508                 if (eth_dev == NULL) {
509                         ERROR("can not allocate rte ethdev");
510                         err = ENOMEM;
511                         goto port_error;
512                 }
513
514                 /* Secondary processes have to use local storage for their
515                  * private data as well as a copy of eth_dev->data, but this
516                  * pointer must not be modified before burst functions are
517                  * actually called. */
518                 if (mlx5_is_secondary()) {
519                         struct mlx5_secondary_data *sd =
520                                 &mlx5_secondary_data[eth_dev->data->port_id];
521                         sd->primary_priv = eth_dev->data->dev_private;
522                         if (sd->primary_priv == NULL) {
523                                 ERROR("no private data for port %u",
524                                                 eth_dev->data->port_id);
525                                 err = EINVAL;
526                                 goto port_error;
527                         }
528                         sd->shared_dev_data = eth_dev->data;
529                         rte_spinlock_init(&sd->lock);
530                         memcpy(sd->data.name, sd->shared_dev_data->name,
531                                    sizeof(sd->data.name));
532                         sd->data.dev_private = priv;
533                         sd->data.rx_mbuf_alloc_failed = 0;
534                         sd->data.mtu = ETHER_MTU;
535                         sd->data.port_id = sd->shared_dev_data->port_id;
536                         sd->data.mac_addrs = priv->mac;
537                         eth_dev->tx_pkt_burst = mlx5_tx_burst_secondary_setup;
538                         eth_dev->rx_pkt_burst = mlx5_rx_burst_secondary_setup;
539                 } else {
540                         eth_dev->data->dev_private = priv;
541                         eth_dev->data->rx_mbuf_alloc_failed = 0;
542                         eth_dev->data->mtu = ETHER_MTU;
543                         eth_dev->data->mac_addrs = priv->mac;
544                 }
545
546                 eth_dev->pci_dev = pci_dev;
547                 rte_eth_copy_pci_info(eth_dev, pci_dev);
548                 eth_dev->driver = &mlx5_driver;
549                 priv->dev = eth_dev;
550                 eth_dev->dev_ops = &mlx5_dev_ops;
551
552                 TAILQ_INIT(&eth_dev->link_intr_cbs);
553
554                 /* Bring Ethernet device up. */
555                 DEBUG("forcing Ethernet interface up");
556                 priv_set_flags(priv, ~IFF_UP, IFF_UP);
557                 continue;
558
559 port_error:
560                 if (priv) {
561                         rte_free(priv->rss_conf);
562                         rte_free(priv);
563                 }
564                 if (pd)
565                         claim_zero(ibv_dealloc_pd(pd));
566                 if (ctx)
567                         claim_zero(ibv_close_device(ctx));
568                 break;
569         }
570
571         /*
572          * XXX if something went wrong in the loop above, there is a resource
573          * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as
574          * long as the dpdk does not provide a way to deallocate a ethdev and a
575          * way to enumerate the registered ethdevs to free the previous ones.
576          */
577
578         /* no port found, complain */
579         if (!mlx5_dev[idx].ports) {
580                 err = ENODEV;
581                 goto error;
582         }
583
584 error:
585         if (attr_ctx)
586                 claim_zero(ibv_close_device(attr_ctx));
587         if (list)
588                 ibv_free_device_list(list);
589         assert(err >= 0);
590         return -err;
591 }
592
593 static const struct rte_pci_id mlx5_pci_id_map[] = {
594         {
595                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
596                                PCI_DEVICE_ID_MELLANOX_CONNECTX4)
597         },
598         {
599                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
600                                PCI_DEVICE_ID_MELLANOX_CONNECTX4VF)
601         },
602         {
603                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
604                                PCI_DEVICE_ID_MELLANOX_CONNECTX4LX)
605         },
606         {
607                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
608                                PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF)
609         },
610         {
611                 .vendor_id = 0
612         }
613 };
614
615 static struct eth_driver mlx5_driver = {
616         .pci_drv = {
617                 .name = MLX5_DRIVER_NAME,
618                 .id_table = mlx5_pci_id_map,
619                 .devinit = mlx5_pci_devinit,
620                 .drv_flags = RTE_PCI_DRV_INTR_LSC,
621         },
622         .dev_private_size = sizeof(struct priv)
623 };
624
625 /**
626  * Driver initialization routine.
627  */
628 static int
629 rte_mlx5_pmd_init(const char *name, const char *args)
630 {
631         (void)name;
632         (void)args;
633         /*
634          * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
635          * huge pages. Calling ibv_fork_init() during init allows
636          * applications to use fork() safely for purposes other than
637          * using this PMD, which is not supported in forked processes.
638          */
639         setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
640         ibv_fork_init();
641         rte_eal_pci_register(&mlx5_driver.pci_drv);
642         return 0;
643 }
644
645 static struct rte_driver rte_mlx5_driver = {
646         .type = PMD_PDEV,
647         .name = MLX5_DRIVER_NAME,
648         .init = rte_mlx5_pmd_init,
649 };
650
651 PMD_REGISTER_DRIVER(rte_mlx5_driver)