net/mlx4: restore promisc and allmulti support
[dpdk.git] / drivers / net / mlx4 / mlx4.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2012 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 /**
35  * @file
36  * mlx4 driver initialization.
37  */
38
39 #include <assert.h>
40 #include <errno.h>
41 #include <inttypes.h>
42 #include <stddef.h>
43 #include <stdint.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47
48 /* Verbs headers do not support -pedantic. */
49 #ifdef PEDANTIC
50 #pragma GCC diagnostic ignored "-Wpedantic"
51 #endif
52 #include <infiniband/verbs.h>
53 #ifdef PEDANTIC
54 #pragma GCC diagnostic error "-Wpedantic"
55 #endif
56
57 #include <rte_common.h>
58 #include <rte_dev.h>
59 #include <rte_errno.h>
60 #include <rte_ethdev.h>
61 #include <rte_ethdev_pci.h>
62 #include <rte_ether.h>
63 #include <rte_flow.h>
64 #include <rte_interrupts.h>
65 #include <rte_kvargs.h>
66 #include <rte_malloc.h>
67 #include <rte_mbuf.h>
68
69 #include "mlx4.h"
70 #include "mlx4_flow.h"
71 #include "mlx4_rxtx.h"
72 #include "mlx4_utils.h"
73
74 /** Configuration structure for device arguments. */
75 struct mlx4_conf {
76         struct {
77                 uint32_t present; /**< Bit-field for existing ports. */
78                 uint32_t enabled; /**< Bit-field for user-enabled ports. */
79         } ports;
80 };
81
82 /* Available parameters list. */
83 const char *pmd_mlx4_init_params[] = {
84         MLX4_PMD_PORT_KVARG,
85         NULL,
86 };
87
88 /**
89  * DPDK callback for Ethernet device configuration.
90  *
91  * @param dev
92  *   Pointer to Ethernet device structure.
93  *
94  * @return
95  *   0 on success, negative errno value otherwise and rte_errno is set.
96  */
97 static int
98 mlx4_dev_configure(struct rte_eth_dev *dev)
99 {
100         struct priv *priv = dev->data->dev_private;
101         struct rte_flow_error error;
102         int ret;
103
104         /* Prepare internal flow rules. */
105         ret = mlx4_flow_sync(priv, &error);
106         if (ret) {
107                 ERROR("cannot set up internal flow rules (code %d, \"%s\"),"
108                       " flow error type %d, cause %p, message: %s",
109                       -ret, strerror(-ret), error.type, error.cause,
110                       error.message ? error.message : "(unspecified)");
111         }
112         return ret;
113 }
114
115 /**
116  * DPDK callback to start the device.
117  *
118  * Simulate device start by attaching all configured flows.
119  *
120  * @param dev
121  *   Pointer to Ethernet device structure.
122  *
123  * @return
124  *   0 on success, negative errno value otherwise and rte_errno is set.
125  */
126 static int
127 mlx4_dev_start(struct rte_eth_dev *dev)
128 {
129         struct priv *priv = dev->data->dev_private;
130         struct rte_flow_error error;
131         int ret;
132
133         if (priv->started)
134                 return 0;
135         DEBUG("%p: attaching configured flows to all RX queues", (void *)dev);
136         priv->started = 1;
137         ret = mlx4_intr_install(priv);
138         if (ret) {
139                 ERROR("%p: interrupt handler installation failed",
140                      (void *)dev);
141                 goto err;
142         }
143         ret = mlx4_flow_sync(priv, &error);
144         if (ret) {
145                 ERROR("%p: cannot attach flow rules (code %d, \"%s\"),"
146                       " flow error type %d, cause %p, message: %s",
147                       (void *)dev,
148                       -ret, strerror(-ret), error.type, error.cause,
149                       error.message ? error.message : "(unspecified)");
150                 goto err;
151         }
152         return 0;
153 err:
154         /* Rollback. */
155         priv->started = 0;
156         return ret;
157 }
158
159 /**
160  * DPDK callback to stop the device.
161  *
162  * Simulate device stop by detaching all configured flows.
163  *
164  * @param dev
165  *   Pointer to Ethernet device structure.
166  */
167 static void
168 mlx4_dev_stop(struct rte_eth_dev *dev)
169 {
170         struct priv *priv = dev->data->dev_private;
171
172         if (!priv->started)
173                 return;
174         DEBUG("%p: detaching flows from all RX queues", (void *)dev);
175         priv->started = 0;
176         mlx4_flow_sync(priv, NULL);
177         mlx4_intr_uninstall(priv);
178 }
179
180 /**
181  * DPDK callback to close the device.
182  *
183  * Destroy all queues and objects, free memory.
184  *
185  * @param dev
186  *   Pointer to Ethernet device structure.
187  */
188 static void
189 mlx4_dev_close(struct rte_eth_dev *dev)
190 {
191         struct priv *priv = dev->data->dev_private;
192         unsigned int i;
193
194         if (priv == NULL)
195                 return;
196         DEBUG("%p: closing device \"%s\"",
197               (void *)dev,
198               ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
199         mlx4_flow_clean(priv);
200         dev->rx_pkt_burst = mlx4_rx_burst_removed;
201         dev->tx_pkt_burst = mlx4_tx_burst_removed;
202         for (i = 0; i != dev->data->nb_rx_queues; ++i)
203                 mlx4_rx_queue_release(dev->data->rx_queues[i]);
204         for (i = 0; i != dev->data->nb_tx_queues; ++i)
205                 mlx4_tx_queue_release(dev->data->tx_queues[i]);
206         if (priv->pd != NULL) {
207                 assert(priv->ctx != NULL);
208                 claim_zero(ibv_dealloc_pd(priv->pd));
209                 claim_zero(ibv_close_device(priv->ctx));
210         } else
211                 assert(priv->ctx == NULL);
212         mlx4_intr_uninstall(priv);
213         memset(priv, 0, sizeof(*priv));
214 }
215
216 static const struct eth_dev_ops mlx4_dev_ops = {
217         .dev_configure = mlx4_dev_configure,
218         .dev_start = mlx4_dev_start,
219         .dev_stop = mlx4_dev_stop,
220         .dev_set_link_down = mlx4_dev_set_link_down,
221         .dev_set_link_up = mlx4_dev_set_link_up,
222         .dev_close = mlx4_dev_close,
223         .link_update = mlx4_link_update,
224         .promiscuous_enable = mlx4_promiscuous_enable,
225         .promiscuous_disable = mlx4_promiscuous_disable,
226         .allmulticast_enable = mlx4_allmulticast_enable,
227         .allmulticast_disable = mlx4_allmulticast_disable,
228         .mac_addr_remove = mlx4_mac_addr_remove,
229         .mac_addr_add = mlx4_mac_addr_add,
230         .mac_addr_set = mlx4_mac_addr_set,
231         .stats_get = mlx4_stats_get,
232         .stats_reset = mlx4_stats_reset,
233         .dev_infos_get = mlx4_dev_infos_get,
234         .vlan_filter_set = mlx4_vlan_filter_set,
235         .rx_queue_setup = mlx4_rx_queue_setup,
236         .tx_queue_setup = mlx4_tx_queue_setup,
237         .rx_queue_release = mlx4_rx_queue_release,
238         .tx_queue_release = mlx4_tx_queue_release,
239         .flow_ctrl_get = mlx4_flow_ctrl_get,
240         .flow_ctrl_set = mlx4_flow_ctrl_set,
241         .mtu_set = mlx4_mtu_set,
242         .filter_ctrl = mlx4_filter_ctrl,
243         .rx_queue_intr_enable = mlx4_rx_intr_enable,
244         .rx_queue_intr_disable = mlx4_rx_intr_disable,
245 };
246
247 /**
248  * Get PCI information from struct ibv_device.
249  *
250  * @param device
251  *   Pointer to Ethernet device structure.
252  * @param[out] pci_addr
253  *   PCI bus address output buffer.
254  *
255  * @return
256  *   0 on success, negative errno value otherwise and rte_errno is set.
257  */
258 static int
259 mlx4_ibv_device_to_pci_addr(const struct ibv_device *device,
260                             struct rte_pci_addr *pci_addr)
261 {
262         FILE *file;
263         char line[32];
264         MKSTR(path, "%s/device/uevent", device->ibdev_path);
265
266         file = fopen(path, "rb");
267         if (file == NULL) {
268                 rte_errno = errno;
269                 return -rte_errno;
270         }
271         while (fgets(line, sizeof(line), file) == line) {
272                 size_t len = strlen(line);
273                 int ret;
274
275                 /* Truncate long lines. */
276                 if (len == (sizeof(line) - 1))
277                         while (line[(len - 1)] != '\n') {
278                                 ret = fgetc(file);
279                                 if (ret == EOF)
280                                         break;
281                                 line[(len - 1)] = ret;
282                         }
283                 /* Extract information. */
284                 if (sscanf(line,
285                            "PCI_SLOT_NAME="
286                            "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n",
287                            &pci_addr->domain,
288                            &pci_addr->bus,
289                            &pci_addr->devid,
290                            &pci_addr->function) == 4) {
291                         ret = 0;
292                         break;
293                 }
294         }
295         fclose(file);
296         return 0;
297 }
298
299 /**
300  * Verify and store value for device argument.
301  *
302  * @param[in] key
303  *   Key argument to verify.
304  * @param[in] val
305  *   Value associated with key.
306  * @param[in, out] conf
307  *   Shared configuration data.
308  *
309  * @return
310  *   0 on success, negative errno value otherwise and rte_errno is set.
311  */
312 static int
313 mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf)
314 {
315         unsigned long tmp;
316
317         errno = 0;
318         tmp = strtoul(val, NULL, 0);
319         if (errno) {
320                 rte_errno = errno;
321                 WARN("%s: \"%s\" is not a valid integer", key, val);
322                 return -rte_errno;
323         }
324         if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {
325                 uint32_t ports = rte_log2_u32(conf->ports.present);
326
327                 if (tmp >= ports) {
328                         ERROR("port index %lu outside range [0,%" PRIu32 ")",
329                               tmp, ports);
330                         return -EINVAL;
331                 }
332                 if (!(conf->ports.present & (1 << tmp))) {
333                         rte_errno = EINVAL;
334                         ERROR("invalid port index %lu", tmp);
335                         return -rte_errno;
336                 }
337                 conf->ports.enabled |= 1 << tmp;
338         } else {
339                 rte_errno = EINVAL;
340                 WARN("%s: unknown parameter", key);
341                 return -rte_errno;
342         }
343         return 0;
344 }
345
346 /**
347  * Parse device parameters.
348  *
349  * @param devargs
350  *   Device arguments structure.
351  *
352  * @return
353  *   0 on success, negative errno value otherwise and rte_errno is set.
354  */
355 static int
356 mlx4_args(struct rte_devargs *devargs, struct mlx4_conf *conf)
357 {
358         struct rte_kvargs *kvlist;
359         unsigned int arg_count;
360         int ret = 0;
361         int i;
362
363         if (devargs == NULL)
364                 return 0;
365         kvlist = rte_kvargs_parse(devargs->args, pmd_mlx4_init_params);
366         if (kvlist == NULL) {
367                 rte_errno = EINVAL;
368                 ERROR("failed to parse kvargs");
369                 return -rte_errno;
370         }
371         /* Process parameters. */
372         for (i = 0; pmd_mlx4_init_params[i]; ++i) {
373                 arg_count = rte_kvargs_count(kvlist, MLX4_PMD_PORT_KVARG);
374                 while (arg_count-- > 0) {
375                         ret = rte_kvargs_process(kvlist,
376                                                  MLX4_PMD_PORT_KVARG,
377                                                  (int (*)(const char *,
378                                                           const char *,
379                                                           void *))
380                                                  mlx4_arg_parse,
381                                                  conf);
382                         if (ret != 0)
383                                 goto free_kvlist;
384                 }
385         }
386 free_kvlist:
387         rte_kvargs_free(kvlist);
388         return ret;
389 }
390
391 static struct rte_pci_driver mlx4_driver;
392
393 /**
394  * DPDK callback to register a PCI device.
395  *
396  * This function creates an Ethernet device for each port of a given
397  * PCI device.
398  *
399  * @param[in] pci_drv
400  *   PCI driver structure (mlx4_driver).
401  * @param[in] pci_dev
402  *   PCI device information.
403  *
404  * @return
405  *   0 on success, negative errno value otherwise and rte_errno is set.
406  */
407 static int
408 mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
409 {
410         struct ibv_device **list;
411         struct ibv_device *ibv_dev;
412         int err = 0;
413         struct ibv_context *attr_ctx = NULL;
414         struct ibv_device_attr device_attr;
415         struct mlx4_conf conf = {
416                 .ports.present = 0,
417         };
418         unsigned int vf;
419         int i;
420
421         (void)pci_drv;
422         assert(pci_drv == &mlx4_driver);
423         list = ibv_get_device_list(&i);
424         if (list == NULL) {
425                 rte_errno = errno;
426                 assert(rte_errno);
427                 if (rte_errno == ENOSYS)
428                         ERROR("cannot list devices, is ib_uverbs loaded?");
429                 return -rte_errno;
430         }
431         assert(i >= 0);
432         /*
433          * For each listed device, check related sysfs entry against
434          * the provided PCI ID.
435          */
436         while (i != 0) {
437                 struct rte_pci_addr pci_addr;
438
439                 --i;
440                 DEBUG("checking device \"%s\"", list[i]->name);
441                 if (mlx4_ibv_device_to_pci_addr(list[i], &pci_addr))
442                         continue;
443                 if ((pci_dev->addr.domain != pci_addr.domain) ||
444                     (pci_dev->addr.bus != pci_addr.bus) ||
445                     (pci_dev->addr.devid != pci_addr.devid) ||
446                     (pci_dev->addr.function != pci_addr.function))
447                         continue;
448                 vf = (pci_dev->id.device_id ==
449                       PCI_DEVICE_ID_MELLANOX_CONNECTX3VF);
450                 INFO("PCI information matches, using device \"%s\" (VF: %s)",
451                      list[i]->name, (vf ? "true" : "false"));
452                 attr_ctx = ibv_open_device(list[i]);
453                 err = errno;
454                 break;
455         }
456         if (attr_ctx == NULL) {
457                 ibv_free_device_list(list);
458                 switch (err) {
459                 case 0:
460                         rte_errno = ENODEV;
461                         ERROR("cannot access device, is mlx4_ib loaded?");
462                         return -rte_errno;
463                 case EINVAL:
464                         rte_errno = EINVAL;
465                         ERROR("cannot use device, are drivers up to date?");
466                         return -rte_errno;
467                 }
468                 assert(err > 0);
469                 rte_errno = err;
470                 return -rte_errno;
471         }
472         ibv_dev = list[i];
473         DEBUG("device opened");
474         if (ibv_query_device(attr_ctx, &device_attr)) {
475                 rte_errno = ENODEV;
476                 goto error;
477         }
478         INFO("%u port(s) detected", device_attr.phys_port_cnt);
479         conf.ports.present |= (UINT64_C(1) << device_attr.phys_port_cnt) - 1;
480         if (mlx4_args(pci_dev->device.devargs, &conf)) {
481                 ERROR("failed to process device arguments");
482                 rte_errno = EINVAL;
483                 goto error;
484         }
485         /* Use all ports when none are defined */
486         if (!conf.ports.enabled)
487                 conf.ports.enabled = conf.ports.present;
488         for (i = 0; i < device_attr.phys_port_cnt; i++) {
489                 uint32_t port = i + 1; /* ports are indexed from one */
490                 struct ibv_context *ctx = NULL;
491                 struct ibv_port_attr port_attr;
492                 struct ibv_pd *pd = NULL;
493                 struct priv *priv = NULL;
494                 struct rte_eth_dev *eth_dev = NULL;
495                 struct ether_addr mac;
496
497                 /* If port is not enabled, skip. */
498                 if (!(conf.ports.enabled & (1 << i)))
499                         continue;
500                 DEBUG("using port %u", port);
501                 ctx = ibv_open_device(ibv_dev);
502                 if (ctx == NULL) {
503                         rte_errno = ENODEV;
504                         goto port_error;
505                 }
506                 /* Check port status. */
507                 err = ibv_query_port(ctx, port, &port_attr);
508                 if (err) {
509                         rte_errno = err;
510                         ERROR("port query failed: %s", strerror(rte_errno));
511                         goto port_error;
512                 }
513                 if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
514                         rte_errno = ENOTSUP;
515                         ERROR("port %d is not configured in Ethernet mode",
516                               port);
517                         goto port_error;
518                 }
519                 if (port_attr.state != IBV_PORT_ACTIVE)
520                         DEBUG("port %d is not active: \"%s\" (%d)",
521                               port, ibv_port_state_str(port_attr.state),
522                               port_attr.state);
523                 /* Make asynchronous FD non-blocking to handle interrupts. */
524                 if (mlx4_fd_set_non_blocking(ctx->async_fd) < 0) {
525                         ERROR("cannot make asynchronous FD non-blocking: %s",
526                               strerror(rte_errno));
527                         goto port_error;
528                 }
529                 /* Allocate protection domain. */
530                 pd = ibv_alloc_pd(ctx);
531                 if (pd == NULL) {
532                         rte_errno = ENOMEM;
533                         ERROR("PD allocation failure");
534                         goto port_error;
535                 }
536                 /* from rte_ethdev.c */
537                 priv = rte_zmalloc("ethdev private structure",
538                                    sizeof(*priv),
539                                    RTE_CACHE_LINE_SIZE);
540                 if (priv == NULL) {
541                         rte_errno = ENOMEM;
542                         ERROR("priv allocation failure");
543                         goto port_error;
544                 }
545                 priv->ctx = ctx;
546                 priv->device_attr = device_attr;
547                 priv->port = port;
548                 priv->pd = pd;
549                 priv->mtu = ETHER_MTU;
550                 priv->vf = vf;
551                 /* Configure the first MAC address by default. */
552                 if (mlx4_get_mac(priv, &mac.addr_bytes)) {
553                         ERROR("cannot get MAC address, is mlx4_en loaded?"
554                               " (rte_errno: %s)", strerror(rte_errno));
555                         goto port_error;
556                 }
557                 INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x",
558                      priv->port,
559                      mac.addr_bytes[0], mac.addr_bytes[1],
560                      mac.addr_bytes[2], mac.addr_bytes[3],
561                      mac.addr_bytes[4], mac.addr_bytes[5]);
562                 /* Register MAC address. */
563                 priv->mac[0] = mac;
564 #ifndef NDEBUG
565                 {
566                         char ifname[IF_NAMESIZE];
567
568                         if (mlx4_get_ifname(priv, &ifname) == 0)
569                                 DEBUG("port %u ifname is \"%s\"",
570                                       priv->port, ifname);
571                         else
572                                 DEBUG("port %u ifname is unknown", priv->port);
573                 }
574 #endif
575                 /* Get actual MTU if possible. */
576                 mlx4_mtu_get(priv, &priv->mtu);
577                 DEBUG("port %u MTU is %u", priv->port, priv->mtu);
578                 /* from rte_ethdev.c */
579                 {
580                         char name[RTE_ETH_NAME_MAX_LEN];
581
582                         snprintf(name, sizeof(name), "%s port %u",
583                                  ibv_get_device_name(ibv_dev), port);
584                         eth_dev = rte_eth_dev_allocate(name);
585                 }
586                 if (eth_dev == NULL) {
587                         ERROR("can not allocate rte ethdev");
588                         rte_errno = ENOMEM;
589                         goto port_error;
590                 }
591                 eth_dev->data->dev_private = priv;
592                 eth_dev->data->mac_addrs = priv->mac;
593                 eth_dev->device = &pci_dev->device;
594                 rte_eth_copy_pci_info(eth_dev, pci_dev);
595                 eth_dev->device->driver = &mlx4_driver.driver;
596                 /* Initialize local interrupt handle for current port. */
597                 priv->intr_handle = (struct rte_intr_handle){
598                         .fd = -1,
599                         .type = RTE_INTR_HANDLE_EXT,
600                 };
601                 /*
602                  * Override ethdev interrupt handle pointer with private
603                  * handle instead of that of the parent PCI device used by
604                  * default. This prevents it from being shared between all
605                  * ports of the same PCI device since each of them is
606                  * associated its own Verbs context.
607                  *
608                  * Rx interrupts in particular require this as the PMD has
609                  * no control over the registration of queue interrupts
610                  * besides setting up eth_dev->intr_handle, the rest is
611                  * handled by rte_intr_rx_ctl().
612                  */
613                 eth_dev->intr_handle = &priv->intr_handle;
614                 priv->dev = eth_dev;
615                 eth_dev->dev_ops = &mlx4_dev_ops;
616                 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
617                 /* Bring Ethernet device up. */
618                 DEBUG("forcing Ethernet interface up");
619                 mlx4_dev_set_link_up(priv->dev);
620                 /* Update link status once if waiting for LSC. */
621                 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
622                         mlx4_link_update(eth_dev, 0);
623                 continue;
624 port_error:
625                 rte_free(priv);
626                 if (pd)
627                         claim_zero(ibv_dealloc_pd(pd));
628                 if (ctx)
629                         claim_zero(ibv_close_device(ctx));
630                 if (eth_dev)
631                         rte_eth_dev_release_port(eth_dev);
632                 break;
633         }
634         if (i == device_attr.phys_port_cnt)
635                 return 0;
636         /*
637          * XXX if something went wrong in the loop above, there is a resource
638          * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as
639          * long as the dpdk does not provide a way to deallocate a ethdev and a
640          * way to enumerate the registered ethdevs to free the previous ones.
641          */
642 error:
643         if (attr_ctx)
644                 claim_zero(ibv_close_device(attr_ctx));
645         if (list)
646                 ibv_free_device_list(list);
647         assert(rte_errno >= 0);
648         return -rte_errno;
649 }
650
651 static const struct rte_pci_id mlx4_pci_id_map[] = {
652         {
653                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
654                                PCI_DEVICE_ID_MELLANOX_CONNECTX3)
655         },
656         {
657                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
658                                PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO)
659         },
660         {
661                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
662                                PCI_DEVICE_ID_MELLANOX_CONNECTX3VF)
663         },
664         {
665                 .vendor_id = 0
666         }
667 };
668
669 static struct rte_pci_driver mlx4_driver = {
670         .driver = {
671                 .name = MLX4_DRIVER_NAME
672         },
673         .id_table = mlx4_pci_id_map,
674         .probe = mlx4_pci_probe,
675         .drv_flags = RTE_PCI_DRV_INTR_LSC |
676                      RTE_PCI_DRV_INTR_RMV,
677 };
678
679 /**
680  * Driver initialization routine.
681  */
682 RTE_INIT(rte_mlx4_pmd_init);
683 static void
684 rte_mlx4_pmd_init(void)
685 {
686         /*
687          * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
688          * huge pages. Calling ibv_fork_init() during init allows
689          * applications to use fork() safely for purposes other than
690          * using this PMD, which is not supported in forked processes.
691          */
692         setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
693         ibv_fork_init();
694         rte_pci_register(&mlx4_driver);
695 }
696
697 RTE_PMD_EXPORT_NAME(net_mlx4, __COUNTER__);
698 RTE_PMD_REGISTER_PCI_TABLE(net_mlx4, mlx4_pci_id_map);
699 RTE_PMD_REGISTER_KMOD_DEP(net_mlx4,
700         "* ib_uverbs & mlx4_en & mlx4_core & mlx4_ib");