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