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