net/mlx4: simplify trigger code for flow rules
[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         .stats_get = mlx4_stats_get,
225         .stats_reset = mlx4_stats_reset,
226         .dev_infos_get = mlx4_dev_infos_get,
227         .rx_queue_setup = mlx4_rx_queue_setup,
228         .tx_queue_setup = mlx4_tx_queue_setup,
229         .rx_queue_release = mlx4_rx_queue_release,
230         .tx_queue_release = mlx4_tx_queue_release,
231         .flow_ctrl_get = mlx4_flow_ctrl_get,
232         .flow_ctrl_set = mlx4_flow_ctrl_set,
233         .mtu_set = mlx4_mtu_set,
234         .filter_ctrl = mlx4_filter_ctrl,
235         .rx_queue_intr_enable = mlx4_rx_intr_enable,
236         .rx_queue_intr_disable = mlx4_rx_intr_disable,
237 };
238
239 /**
240  * Get PCI information from struct ibv_device.
241  *
242  * @param device
243  *   Pointer to Ethernet device structure.
244  * @param[out] pci_addr
245  *   PCI bus address output buffer.
246  *
247  * @return
248  *   0 on success, negative errno value otherwise and rte_errno is set.
249  */
250 static int
251 mlx4_ibv_device_to_pci_addr(const struct ibv_device *device,
252                             struct rte_pci_addr *pci_addr)
253 {
254         FILE *file;
255         char line[32];
256         MKSTR(path, "%s/device/uevent", device->ibdev_path);
257
258         file = fopen(path, "rb");
259         if (file == NULL) {
260                 rte_errno = errno;
261                 return -rte_errno;
262         }
263         while (fgets(line, sizeof(line), file) == line) {
264                 size_t len = strlen(line);
265                 int ret;
266
267                 /* Truncate long lines. */
268                 if (len == (sizeof(line) - 1))
269                         while (line[(len - 1)] != '\n') {
270                                 ret = fgetc(file);
271                                 if (ret == EOF)
272                                         break;
273                                 line[(len - 1)] = ret;
274                         }
275                 /* Extract information. */
276                 if (sscanf(line,
277                            "PCI_SLOT_NAME="
278                            "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n",
279                            &pci_addr->domain,
280                            &pci_addr->bus,
281                            &pci_addr->devid,
282                            &pci_addr->function) == 4) {
283                         ret = 0;
284                         break;
285                 }
286         }
287         fclose(file);
288         return 0;
289 }
290
291 /**
292  * Verify and store value for device argument.
293  *
294  * @param[in] key
295  *   Key argument to verify.
296  * @param[in] val
297  *   Value associated with key.
298  * @param[in, out] conf
299  *   Shared configuration data.
300  *
301  * @return
302  *   0 on success, negative errno value otherwise and rte_errno is set.
303  */
304 static int
305 mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf)
306 {
307         unsigned long tmp;
308
309         errno = 0;
310         tmp = strtoul(val, NULL, 0);
311         if (errno) {
312                 rte_errno = errno;
313                 WARN("%s: \"%s\" is not a valid integer", key, val);
314                 return -rte_errno;
315         }
316         if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {
317                 uint32_t ports = rte_log2_u32(conf->ports.present);
318
319                 if (tmp >= ports) {
320                         ERROR("port index %lu outside range [0,%" PRIu32 ")",
321                               tmp, ports);
322                         return -EINVAL;
323                 }
324                 if (!(conf->ports.present & (1 << tmp))) {
325                         rte_errno = EINVAL;
326                         ERROR("invalid port index %lu", tmp);
327                         return -rte_errno;
328                 }
329                 conf->ports.enabled |= 1 << tmp;
330         } else {
331                 rte_errno = EINVAL;
332                 WARN("%s: unknown parameter", key);
333                 return -rte_errno;
334         }
335         return 0;
336 }
337
338 /**
339  * Parse device parameters.
340  *
341  * @param devargs
342  *   Device arguments structure.
343  *
344  * @return
345  *   0 on success, negative errno value otherwise and rte_errno is set.
346  */
347 static int
348 mlx4_args(struct rte_devargs *devargs, struct mlx4_conf *conf)
349 {
350         struct rte_kvargs *kvlist;
351         unsigned int arg_count;
352         int ret = 0;
353         int i;
354
355         if (devargs == NULL)
356                 return 0;
357         kvlist = rte_kvargs_parse(devargs->args, pmd_mlx4_init_params);
358         if (kvlist == NULL) {
359                 rte_errno = EINVAL;
360                 ERROR("failed to parse kvargs");
361                 return -rte_errno;
362         }
363         /* Process parameters. */
364         for (i = 0; pmd_mlx4_init_params[i]; ++i) {
365                 arg_count = rte_kvargs_count(kvlist, MLX4_PMD_PORT_KVARG);
366                 while (arg_count-- > 0) {
367                         ret = rte_kvargs_process(kvlist,
368                                                  MLX4_PMD_PORT_KVARG,
369                                                  (int (*)(const char *,
370                                                           const char *,
371                                                           void *))
372                                                  mlx4_arg_parse,
373                                                  conf);
374                         if (ret != 0)
375                                 goto free_kvlist;
376                 }
377         }
378 free_kvlist:
379         rte_kvargs_free(kvlist);
380         return ret;
381 }
382
383 static struct rte_pci_driver mlx4_driver;
384
385 /**
386  * DPDK callback to register a PCI device.
387  *
388  * This function creates an Ethernet device for each port of a given
389  * PCI device.
390  *
391  * @param[in] pci_drv
392  *   PCI driver structure (mlx4_driver).
393  * @param[in] pci_dev
394  *   PCI device information.
395  *
396  * @return
397  *   0 on success, negative errno value otherwise and rte_errno is set.
398  */
399 static int
400 mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
401 {
402         struct ibv_device **list;
403         struct ibv_device *ibv_dev;
404         int err = 0;
405         struct ibv_context *attr_ctx = NULL;
406         struct ibv_device_attr device_attr;
407         struct mlx4_conf conf = {
408                 .ports.present = 0,
409         };
410         unsigned int vf;
411         int i;
412
413         (void)pci_drv;
414         assert(pci_drv == &mlx4_driver);
415         list = ibv_get_device_list(&i);
416         if (list == NULL) {
417                 rte_errno = errno;
418                 assert(rte_errno);
419                 if (rte_errno == ENOSYS)
420                         ERROR("cannot list devices, is ib_uverbs loaded?");
421                 return -rte_errno;
422         }
423         assert(i >= 0);
424         /*
425          * For each listed device, check related sysfs entry against
426          * the provided PCI ID.
427          */
428         while (i != 0) {
429                 struct rte_pci_addr pci_addr;
430
431                 --i;
432                 DEBUG("checking device \"%s\"", list[i]->name);
433                 if (mlx4_ibv_device_to_pci_addr(list[i], &pci_addr))
434                         continue;
435                 if ((pci_dev->addr.domain != pci_addr.domain) ||
436                     (pci_dev->addr.bus != pci_addr.bus) ||
437                     (pci_dev->addr.devid != pci_addr.devid) ||
438                     (pci_dev->addr.function != pci_addr.function))
439                         continue;
440                 vf = (pci_dev->id.device_id ==
441                       PCI_DEVICE_ID_MELLANOX_CONNECTX3VF);
442                 INFO("PCI information matches, using device \"%s\" (VF: %s)",
443                      list[i]->name, (vf ? "true" : "false"));
444                 attr_ctx = ibv_open_device(list[i]);
445                 err = errno;
446                 break;
447         }
448         if (attr_ctx == NULL) {
449                 ibv_free_device_list(list);
450                 switch (err) {
451                 case 0:
452                         rte_errno = ENODEV;
453                         ERROR("cannot access device, is mlx4_ib loaded?");
454                         return -rte_errno;
455                 case EINVAL:
456                         rte_errno = EINVAL;
457                         ERROR("cannot use device, are drivers up to date?");
458                         return -rte_errno;
459                 }
460                 assert(err > 0);
461                 rte_errno = err;
462                 return -rte_errno;
463         }
464         ibv_dev = list[i];
465         DEBUG("device opened");
466         if (ibv_query_device(attr_ctx, &device_attr)) {
467                 rte_errno = ENODEV;
468                 goto error;
469         }
470         INFO("%u port(s) detected", device_attr.phys_port_cnt);
471         conf.ports.present |= (UINT64_C(1) << device_attr.phys_port_cnt) - 1;
472         if (mlx4_args(pci_dev->device.devargs, &conf)) {
473                 ERROR("failed to process device arguments");
474                 rte_errno = EINVAL;
475                 goto error;
476         }
477         /* Use all ports when none are defined */
478         if (!conf.ports.enabled)
479                 conf.ports.enabled = conf.ports.present;
480         for (i = 0; i < device_attr.phys_port_cnt; i++) {
481                 uint32_t port = i + 1; /* ports are indexed from one */
482                 struct ibv_context *ctx = NULL;
483                 struct ibv_port_attr port_attr;
484                 struct ibv_pd *pd = NULL;
485                 struct priv *priv = NULL;
486                 struct rte_eth_dev *eth_dev = NULL;
487                 struct ether_addr mac;
488
489                 /* If port is not enabled, skip. */
490                 if (!(conf.ports.enabled & (1 << i)))
491                         continue;
492                 DEBUG("using port %u", port);
493                 ctx = ibv_open_device(ibv_dev);
494                 if (ctx == NULL) {
495                         rte_errno = ENODEV;
496                         goto port_error;
497                 }
498                 /* Check port status. */
499                 err = ibv_query_port(ctx, port, &port_attr);
500                 if (err) {
501                         rte_errno = err;
502                         ERROR("port query failed: %s", strerror(rte_errno));
503                         goto port_error;
504                 }
505                 if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
506                         rte_errno = ENOTSUP;
507                         ERROR("port %d is not configured in Ethernet mode",
508                               port);
509                         goto port_error;
510                 }
511                 if (port_attr.state != IBV_PORT_ACTIVE)
512                         DEBUG("port %d is not active: \"%s\" (%d)",
513                               port, ibv_port_state_str(port_attr.state),
514                               port_attr.state);
515                 /* Make asynchronous FD non-blocking to handle interrupts. */
516                 if (mlx4_fd_set_non_blocking(ctx->async_fd) < 0) {
517                         ERROR("cannot make asynchronous FD non-blocking: %s",
518                               strerror(rte_errno));
519                         goto port_error;
520                 }
521                 /* Allocate protection domain. */
522                 pd = ibv_alloc_pd(ctx);
523                 if (pd == NULL) {
524                         rte_errno = ENOMEM;
525                         ERROR("PD allocation failure");
526                         goto port_error;
527                 }
528                 /* from rte_ethdev.c */
529                 priv = rte_zmalloc("ethdev private structure",
530                                    sizeof(*priv),
531                                    RTE_CACHE_LINE_SIZE);
532                 if (priv == NULL) {
533                         rte_errno = ENOMEM;
534                         ERROR("priv allocation failure");
535                         goto port_error;
536                 }
537                 priv->ctx = ctx;
538                 priv->device_attr = device_attr;
539                 priv->port = port;
540                 priv->pd = pd;
541                 priv->mtu = ETHER_MTU;
542                 priv->vf = vf;
543                 /* Configure the first MAC address by default. */
544                 if (mlx4_get_mac(priv, &mac.addr_bytes)) {
545                         ERROR("cannot get MAC address, is mlx4_en loaded?"
546                               " (rte_errno: %s)", strerror(rte_errno));
547                         goto port_error;
548                 }
549                 INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x",
550                      priv->port,
551                      mac.addr_bytes[0], mac.addr_bytes[1],
552                      mac.addr_bytes[2], mac.addr_bytes[3],
553                      mac.addr_bytes[4], mac.addr_bytes[5]);
554                 /* Register MAC address. */
555                 priv->mac = mac;
556 #ifndef NDEBUG
557                 {
558                         char ifname[IF_NAMESIZE];
559
560                         if (mlx4_get_ifname(priv, &ifname) == 0)
561                                 DEBUG("port %u ifname is \"%s\"",
562                                       priv->port, ifname);
563                         else
564                                 DEBUG("port %u ifname is unknown", priv->port);
565                 }
566 #endif
567                 /* Get actual MTU if possible. */
568                 mlx4_mtu_get(priv, &priv->mtu);
569                 DEBUG("port %u MTU is %u", priv->port, priv->mtu);
570                 /* from rte_ethdev.c */
571                 {
572                         char name[RTE_ETH_NAME_MAX_LEN];
573
574                         snprintf(name, sizeof(name), "%s port %u",
575                                  ibv_get_device_name(ibv_dev), port);
576                         eth_dev = rte_eth_dev_allocate(name);
577                 }
578                 if (eth_dev == NULL) {
579                         ERROR("can not allocate rte ethdev");
580                         rte_errno = ENOMEM;
581                         goto port_error;
582                 }
583                 eth_dev->data->dev_private = priv;
584                 eth_dev->data->mac_addrs = &priv->mac;
585                 eth_dev->device = &pci_dev->device;
586                 rte_eth_copy_pci_info(eth_dev, pci_dev);
587                 eth_dev->device->driver = &mlx4_driver.driver;
588                 /* Initialize local interrupt handle for current port. */
589                 priv->intr_handle = (struct rte_intr_handle){
590                         .fd = -1,
591                         .type = RTE_INTR_HANDLE_EXT,
592                 };
593                 /*
594                  * Override ethdev interrupt handle pointer with private
595                  * handle instead of that of the parent PCI device used by
596                  * default. This prevents it from being shared between all
597                  * ports of the same PCI device since each of them is
598                  * associated its own Verbs context.
599                  *
600                  * Rx interrupts in particular require this as the PMD has
601                  * no control over the registration of queue interrupts
602                  * besides setting up eth_dev->intr_handle, the rest is
603                  * handled by rte_intr_rx_ctl().
604                  */
605                 eth_dev->intr_handle = &priv->intr_handle;
606                 priv->dev = eth_dev;
607                 eth_dev->dev_ops = &mlx4_dev_ops;
608                 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
609                 /* Bring Ethernet device up. */
610                 DEBUG("forcing Ethernet interface up");
611                 mlx4_dev_set_link_up(priv->dev);
612                 /* Update link status once if waiting for LSC. */
613                 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
614                         mlx4_link_update(eth_dev, 0);
615                 continue;
616 port_error:
617                 rte_free(priv);
618                 if (pd)
619                         claim_zero(ibv_dealloc_pd(pd));
620                 if (ctx)
621                         claim_zero(ibv_close_device(ctx));
622                 if (eth_dev)
623                         rte_eth_dev_release_port(eth_dev);
624                 break;
625         }
626         if (i == device_attr.phys_port_cnt)
627                 return 0;
628         /*
629          * XXX if something went wrong in the loop above, there is a resource
630          * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as
631          * long as the dpdk does not provide a way to deallocate a ethdev and a
632          * way to enumerate the registered ethdevs to free the previous ones.
633          */
634 error:
635         if (attr_ctx)
636                 claim_zero(ibv_close_device(attr_ctx));
637         if (list)
638                 ibv_free_device_list(list);
639         assert(rte_errno >= 0);
640         return -rte_errno;
641 }
642
643 static const struct rte_pci_id mlx4_pci_id_map[] = {
644         {
645                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
646                                PCI_DEVICE_ID_MELLANOX_CONNECTX3)
647         },
648         {
649                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
650                                PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO)
651         },
652         {
653                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
654                                PCI_DEVICE_ID_MELLANOX_CONNECTX3VF)
655         },
656         {
657                 .vendor_id = 0
658         }
659 };
660
661 static struct rte_pci_driver mlx4_driver = {
662         .driver = {
663                 .name = MLX4_DRIVER_NAME
664         },
665         .id_table = mlx4_pci_id_map,
666         .probe = mlx4_pci_probe,
667         .drv_flags = RTE_PCI_DRV_INTR_LSC |
668                      RTE_PCI_DRV_INTR_RMV,
669 };
670
671 /**
672  * Driver initialization routine.
673  */
674 RTE_INIT(rte_mlx4_pmd_init);
675 static void
676 rte_mlx4_pmd_init(void)
677 {
678         /*
679          * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
680          * huge pages. Calling ibv_fork_init() during init allows
681          * applications to use fork() safely for purposes other than
682          * using this PMD, which is not supported in forked processes.
683          */
684         setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
685         ibv_fork_init();
686         rte_pci_register(&mlx4_driver);
687 }
688
689 RTE_PMD_EXPORT_NAME(net_mlx4, __COUNTER__);
690 RTE_PMD_REGISTER_PCI_TABLE(net_mlx4, mlx4_pci_id_map);
691 RTE_PMD_REGISTER_KMOD_DEP(net_mlx4,
692         "* ib_uverbs & mlx4_en & mlx4_core & mlx4_ib");