4 * Copyright 2012 6WIND S.A.
5 * Copyright 2012 Mellanox
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
46 #include <sys/ioctl.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <linux/ethtool.h>
50 #include <linux/sockios.h>
53 #include <rte_ether.h>
54 #include <rte_ethdev.h>
55 #include <rte_ethdev_pci.h>
58 #include <rte_errno.h>
59 #include <rte_mempool.h>
60 #include <rte_prefetch.h>
61 #include <rte_malloc.h>
62 #include <rte_spinlock.h>
64 #include <rte_alarm.h>
65 #include <rte_memory.h>
67 #include <rte_kvargs.h>
68 #include <rte_interrupts.h>
69 #include <rte_branch_prediction.h>
71 /* Generated configuration header. */
72 #include "mlx4_autoconf.h"
76 #include "mlx4_flow.h"
78 /* Convenience macros for accessing mbuf fields. */
79 #define NEXT(m) ((m)->next)
80 #define DATA_LEN(m) ((m)->data_len)
81 #define PKT_LEN(m) ((m)->pkt_len)
82 #define DATA_OFF(m) ((m)->data_off)
83 #define SET_DATA_OFF(m, o) ((m)->data_off = (o))
84 #define NB_SEGS(m) ((m)->nb_segs)
85 #define PORT(m) ((m)->port)
87 /* Work Request ID data type (64 bit). */
96 #define WR_ID(o) (((wr_id_t *)&(o))->data)
98 /** Configuration structure for device arguments. */
101 uint32_t present; /**< Bit-field for existing ports. */
102 uint32_t enabled; /**< Bit-field for user-enabled ports. */
106 /* Available parameters list. */
107 const char *pmd_mlx4_init_params[] = {
113 mlx4_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx);
116 mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx);
119 priv_rx_intr_vec_enable(struct priv *priv);
122 priv_rx_intr_vec_disable(struct priv *priv);
125 * Lock private structure to protect it from concurrent access in the
129 * Pointer to private structure.
131 void priv_lock(struct priv *priv)
133 rte_spinlock_lock(&priv->lock);
137 * Unlock private structure.
140 * Pointer to private structure.
142 void priv_unlock(struct priv *priv)
144 rte_spinlock_unlock(&priv->lock);
147 /* Allocate a buffer on the stack and fill it with a printf format string. */
148 #define MKSTR(name, ...) \
149 char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
151 snprintf(name, sizeof(name), __VA_ARGS__)
154 * Get interface name from private structure.
157 * Pointer to private structure.
159 * Interface name output buffer.
162 * 0 on success, -1 on failure and errno is set.
165 priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE])
169 unsigned int dev_type = 0;
170 unsigned int dev_port_prev = ~0u;
171 char match[IF_NAMESIZE] = "";
174 MKSTR(path, "%s/device/net", priv->ctx->device->ibdev_path);
180 while ((dent = readdir(dir)) != NULL) {
181 char *name = dent->d_name;
183 unsigned int dev_port;
186 if ((name[0] == '.') &&
187 ((name[1] == '\0') ||
188 ((name[1] == '.') && (name[2] == '\0'))))
191 MKSTR(path, "%s/device/net/%s/%s",
192 priv->ctx->device->ibdev_path, name,
193 (dev_type ? "dev_id" : "dev_port"));
195 file = fopen(path, "rb");
200 * Switch to dev_id when dev_port does not exist as
201 * is the case with Linux kernel versions < 3.15.
212 r = fscanf(file, (dev_type ? "%x" : "%u"), &dev_port);
217 * Switch to dev_id when dev_port returns the same value for
218 * all ports. May happen when using a MOFED release older than
219 * 3.0 with a Linux kernel >= 3.15.
221 if (dev_port == dev_port_prev)
223 dev_port_prev = dev_port;
224 if (dev_port == (priv->port - 1u))
225 snprintf(match, sizeof(match), "%s", name);
228 if (match[0] == '\0')
230 strncpy(*ifname, match, sizeof(*ifname));
235 * Read from sysfs entry.
238 * Pointer to private structure.
240 * Entry name relative to sysfs path.
242 * Data output buffer.
247 * 0 on success, -1 on failure and errno is set.
250 priv_sysfs_read(const struct priv *priv, const char *entry,
251 char *buf, size_t size)
253 char ifname[IF_NAMESIZE];
258 if (priv_get_ifname(priv, &ifname))
261 MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path,
264 file = fopen(path, "rb");
267 ret = fread(buf, 1, size, file);
269 if (((size_t)ret < size) && (ferror(file)))
279 * Write to sysfs entry.
282 * Pointer to private structure.
284 * Entry name relative to sysfs path.
291 * 0 on success, -1 on failure and errno is set.
294 priv_sysfs_write(const struct priv *priv, const char *entry,
295 char *buf, size_t size)
297 char ifname[IF_NAMESIZE];
302 if (priv_get_ifname(priv, &ifname))
305 MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path,
308 file = fopen(path, "wb");
311 ret = fwrite(buf, 1, size, file);
313 if (((size_t)ret < size) || (ferror(file)))
323 * Get unsigned long sysfs property.
326 * Pointer to private structure.
328 * Entry name relative to sysfs path.
330 * Value output buffer.
333 * 0 on success, -1 on failure and errno is set.
336 priv_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long *value)
339 unsigned long value_ret;
342 ret = priv_sysfs_read(priv, name, value_str, (sizeof(value_str) - 1));
344 DEBUG("cannot read %s value from sysfs: %s",
345 name, strerror(errno));
348 value_str[ret] = '\0';
350 value_ret = strtoul(value_str, NULL, 0);
352 DEBUG("invalid %s value `%s': %s", name, value_str,
361 * Set unsigned long sysfs property.
364 * Pointer to private structure.
366 * Entry name relative to sysfs path.
371 * 0 on success, -1 on failure and errno is set.
374 priv_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long value)
377 MKSTR(value_str, "%lu", value);
379 ret = priv_sysfs_write(priv, name, value_str, (sizeof(value_str) - 1));
381 DEBUG("cannot write %s `%s' (%lu) to sysfs: %s",
382 name, value_str, value, strerror(errno));
389 * Perform ifreq ioctl() on associated Ethernet device.
392 * Pointer to private structure.
394 * Request number to pass to ioctl().
396 * Interface request structure output buffer.
399 * 0 on success, -1 on failure and errno is set.
402 priv_ifreq(const struct priv *priv, int req, struct ifreq *ifr)
404 int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
409 if (priv_get_ifname(priv, &ifr->ifr_name) == 0)
410 ret = ioctl(sock, req, ifr);
419 * Pointer to private structure.
421 * MTU value output buffer.
424 * 0 on success, -1 on failure and errno is set.
427 priv_get_mtu(struct priv *priv, uint16_t *mtu)
429 unsigned long ulong_mtu;
431 if (priv_get_sysfs_ulong(priv, "mtu", &ulong_mtu) == -1)
441 * Pointer to private structure.
446 * 0 on success, -1 on failure and errno is set.
449 priv_set_mtu(struct priv *priv, uint16_t mtu)
453 if (priv_set_sysfs_ulong(priv, "mtu", mtu) ||
454 priv_get_mtu(priv, &new_mtu))
466 * Pointer to private structure.
468 * Bitmask for flags that must remain untouched.
470 * Bitmask for flags to modify.
473 * 0 on success, -1 on failure and errno is set.
476 priv_set_flags(struct priv *priv, unsigned int keep, unsigned int flags)
480 if (priv_get_sysfs_ulong(priv, "flags", &tmp) == -1)
483 tmp |= (flags & (~keep));
484 return priv_set_sysfs_ulong(priv, "flags", tmp);
487 /* Device configuration. */
490 txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc,
491 unsigned int socket, const struct rte_eth_txconf *conf);
494 txq_cleanup(struct txq *txq);
497 rxq_setup(struct rte_eth_dev *dev, struct rxq *rxq, uint16_t desc,
498 unsigned int socket, const struct rte_eth_rxconf *conf,
499 struct rte_mempool *mp);
502 rxq_cleanup(struct rxq *rxq);
505 priv_mac_addr_del(struct priv *priv);
508 * Ethernet device configuration.
510 * Prepare the driver for a given number of TX and RX queues.
513 * Pointer to Ethernet device structure.
516 * 0 on success, errno value on failure.
519 dev_configure(struct rte_eth_dev *dev)
521 struct priv *priv = dev->data->dev_private;
522 unsigned int rxqs_n = dev->data->nb_rx_queues;
523 unsigned int txqs_n = dev->data->nb_tx_queues;
525 priv->rxqs = (void *)dev->data->rx_queues;
526 priv->txqs = (void *)dev->data->tx_queues;
527 if (txqs_n != priv->txqs_n) {
528 INFO("%p: TX queues number update: %u -> %u",
529 (void *)dev, priv->txqs_n, txqs_n);
530 priv->txqs_n = txqs_n;
532 if (rxqs_n != priv->rxqs_n) {
533 INFO("%p: Rx queues number update: %u -> %u",
534 (void *)dev, priv->rxqs_n, rxqs_n);
535 priv->rxqs_n = rxqs_n;
541 * DPDK callback for Ethernet device configuration.
544 * Pointer to Ethernet device structure.
547 * 0 on success, negative errno value on failure.
550 mlx4_dev_configure(struct rte_eth_dev *dev)
552 struct priv *priv = dev->data->dev_private;
556 ret = dev_configure(dev);
562 static uint16_t mlx4_tx_burst(void *, struct rte_mbuf **, uint16_t);
563 static uint16_t removed_rx_burst(void *, struct rte_mbuf **, uint16_t);
565 /* TX queues handling. */
568 * Allocate TX queue elements.
571 * Pointer to TX queue structure.
573 * Number of elements to allocate.
576 * 0 on success, errno value on failure.
579 txq_alloc_elts(struct txq *txq, unsigned int elts_n)
582 struct txq_elt (*elts)[elts_n] =
583 rte_calloc_socket("TXQ", 1, sizeof(*elts), 0, txq->socket);
587 ERROR("%p: can't allocate packets array", (void *)txq);
591 for (i = 0; (i != elts_n); ++i) {
592 struct txq_elt *elt = &(*elts)[i];
596 DEBUG("%p: allocated and configured %u WRs", (void *)txq, elts_n);
597 txq->elts_n = elts_n;
602 /* Request send completion every MLX4_PMD_TX_PER_COMP_REQ packets or
603 * at least 4 times per ring. */
604 txq->elts_comp_cd_init =
605 ((MLX4_PMD_TX_PER_COMP_REQ < (elts_n / 4)) ?
606 MLX4_PMD_TX_PER_COMP_REQ : (elts_n / 4));
607 txq->elts_comp_cd = txq->elts_comp_cd_init;
613 DEBUG("%p: failed, freed everything", (void *)txq);
619 * Free TX queue elements.
622 * Pointer to TX queue structure.
625 txq_free_elts(struct txq *txq)
627 unsigned int elts_n = txq->elts_n;
628 unsigned int elts_head = txq->elts_head;
629 unsigned int elts_tail = txq->elts_tail;
630 struct txq_elt (*elts)[elts_n] = txq->elts;
632 DEBUG("%p: freeing WRs", (void *)txq);
637 txq->elts_comp_cd = 0;
638 txq->elts_comp_cd_init = 0;
642 while (elts_tail != elts_head) {
643 struct txq_elt *elt = &(*elts)[elts_tail];
645 assert(elt->buf != NULL);
646 rte_pktmbuf_free(elt->buf);
649 memset(elt, 0x77, sizeof(*elt));
651 if (++elts_tail == elts_n)
659 * Clean up a TX queue.
661 * Destroy objects, free allocated memory and reset the structure for reuse.
664 * Pointer to TX queue structure.
667 txq_cleanup(struct txq *txq)
669 struct ibv_exp_release_intf_params params;
672 DEBUG("cleaning up %p", (void *)txq);
674 if (txq->if_qp != NULL) {
675 assert(txq->priv != NULL);
676 assert(txq->priv->ctx != NULL);
677 assert(txq->qp != NULL);
678 params = (struct ibv_exp_release_intf_params){
681 claim_zero(ibv_exp_release_intf(txq->priv->ctx,
685 if (txq->if_cq != NULL) {
686 assert(txq->priv != NULL);
687 assert(txq->priv->ctx != NULL);
688 assert(txq->cq != NULL);
689 params = (struct ibv_exp_release_intf_params){
692 claim_zero(ibv_exp_release_intf(txq->priv->ctx,
697 claim_zero(ibv_destroy_qp(txq->qp));
699 claim_zero(ibv_destroy_cq(txq->cq));
700 if (txq->rd != NULL) {
701 struct ibv_exp_destroy_res_domain_attr attr = {
705 assert(txq->priv != NULL);
706 assert(txq->priv->ctx != NULL);
707 claim_zero(ibv_exp_destroy_res_domain(txq->priv->ctx,
711 for (i = 0; (i != elemof(txq->mp2mr)); ++i) {
712 if (txq->mp2mr[i].mp == NULL)
714 assert(txq->mp2mr[i].mr != NULL);
715 claim_zero(ibv_dereg_mr(txq->mp2mr[i].mr));
717 memset(txq, 0, sizeof(*txq));
721 * Manage TX completions.
723 * When sending a burst, mlx4_tx_burst() posts several WRs.
724 * To improve performance, a completion event is only required once every
725 * MLX4_PMD_TX_PER_COMP_REQ sends. Doing so discards completion information
726 * for other WRs, but this information would not be used anyway.
729 * Pointer to TX queue structure.
732 * 0 on success, -1 on failure.
735 txq_complete(struct txq *txq)
737 unsigned int elts_comp = txq->elts_comp;
738 unsigned int elts_tail = txq->elts_tail;
739 const unsigned int elts_n = txq->elts_n;
742 if (unlikely(elts_comp == 0))
744 wcs_n = txq->if_cq->poll_cnt(txq->cq, elts_comp);
745 if (unlikely(wcs_n == 0))
747 if (unlikely(wcs_n < 0)) {
748 DEBUG("%p: ibv_poll_cq() failed (wcs_n=%d)",
753 assert(elts_comp <= txq->elts_comp);
755 * Assume WC status is successful as nothing can be done about it
758 elts_tail += wcs_n * txq->elts_comp_cd_init;
759 if (elts_tail >= elts_n)
761 txq->elts_tail = elts_tail;
762 txq->elts_comp = elts_comp;
766 struct mlx4_check_mempool_data {
772 /* Called by mlx4_check_mempool() when iterating the memory chunks. */
773 static void mlx4_check_mempool_cb(struct rte_mempool *mp,
774 void *opaque, struct rte_mempool_memhdr *memhdr,
777 struct mlx4_check_mempool_data *data = opaque;
782 /* It already failed, skip the next chunks. */
785 /* It is the first chunk. */
786 if (data->start == NULL && data->end == NULL) {
787 data->start = memhdr->addr;
788 data->end = data->start + memhdr->len;
791 if (data->end == memhdr->addr) {
792 data->end += memhdr->len;
795 if (data->start == (char *)memhdr->addr + memhdr->len) {
796 data->start -= memhdr->len;
799 /* Error, mempool is not virtually contigous. */
804 * Check if a mempool can be used: it must be virtually contiguous.
807 * Pointer to memory pool.
809 * Pointer to the start address of the mempool virtual memory area
811 * Pointer to the end address of the mempool virtual memory area
814 * 0 on success (mempool is virtually contiguous), -1 on error.
816 static int mlx4_check_mempool(struct rte_mempool *mp, uintptr_t *start,
819 struct mlx4_check_mempool_data data;
821 memset(&data, 0, sizeof(data));
822 rte_mempool_mem_iter(mp, mlx4_check_mempool_cb, &data);
823 *start = (uintptr_t)data.start;
824 *end = (uintptr_t)data.end;
829 /* For best performance, this function should not be inlined. */
830 static struct ibv_mr *mlx4_mp2mr(struct ibv_pd *, struct rte_mempool *)
834 * Register mempool as a memory region.
837 * Pointer to protection domain.
839 * Pointer to memory pool.
842 * Memory region pointer, NULL in case of error.
844 static struct ibv_mr *
845 mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp)
847 const struct rte_memseg *ms = rte_eal_get_physmem_layout();
852 if (mlx4_check_mempool(mp, &start, &end) != 0) {
853 ERROR("mempool %p: not virtually contiguous",
858 DEBUG("mempool %p area start=%p end=%p size=%zu",
859 (void *)mp, (void *)start, (void *)end,
860 (size_t)(end - start));
861 /* Round start and end to page boundary if found in memory segments. */
862 for (i = 0; (i < RTE_MAX_MEMSEG) && (ms[i].addr != NULL); ++i) {
863 uintptr_t addr = (uintptr_t)ms[i].addr;
864 size_t len = ms[i].len;
865 unsigned int align = ms[i].hugepage_sz;
867 if ((start > addr) && (start < addr + len))
868 start = RTE_ALIGN_FLOOR(start, align);
869 if ((end > addr) && (end < addr + len))
870 end = RTE_ALIGN_CEIL(end, align);
872 DEBUG("mempool %p using start=%p end=%p size=%zu for MR",
873 (void *)mp, (void *)start, (void *)end,
874 (size_t)(end - start));
875 return ibv_reg_mr(pd,
878 IBV_ACCESS_LOCAL_WRITE);
882 * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which
883 * the cloned mbuf is allocated is returned instead.
889 * Memory pool where data is located for given mbuf.
891 static struct rte_mempool *
892 txq_mb2mp(struct rte_mbuf *buf)
894 if (unlikely(RTE_MBUF_INDIRECT(buf)))
895 return rte_mbuf_from_indirect(buf)->pool;
900 * Get Memory Region (MR) <-> Memory Pool (MP) association from txq->mp2mr[].
901 * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full,
902 * remove an entry first.
905 * Pointer to TX queue structure.
907 * Memory Pool for which a Memory Region lkey must be returned.
910 * mr->lkey on success, (uint32_t)-1 on failure.
913 txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
918 for (i = 0; (i != elemof(txq->mp2mr)); ++i) {
919 if (unlikely(txq->mp2mr[i].mp == NULL)) {
920 /* Unknown MP, add a new MR for it. */
923 if (txq->mp2mr[i].mp == mp) {
924 assert(txq->mp2mr[i].lkey != (uint32_t)-1);
925 assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey);
926 return txq->mp2mr[i].lkey;
929 /* Add a new entry, register MR first. */
930 DEBUG("%p: discovered new memory pool \"%s\" (%p)",
931 (void *)txq, mp->name, (void *)mp);
932 mr = mlx4_mp2mr(txq->priv->pd, mp);
933 if (unlikely(mr == NULL)) {
934 DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.",
938 if (unlikely(i == elemof(txq->mp2mr))) {
939 /* Table is full, remove oldest entry. */
940 DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
943 claim_zero(ibv_dereg_mr(txq->mp2mr[0].mr));
944 memmove(&txq->mp2mr[0], &txq->mp2mr[1],
945 (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0])));
947 /* Store the new entry. */
948 txq->mp2mr[i].mp = mp;
949 txq->mp2mr[i].mr = mr;
950 txq->mp2mr[i].lkey = mr->lkey;
951 DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32,
952 (void *)txq, mp->name, (void *)mp, txq->mp2mr[i].lkey);
953 return txq->mp2mr[i].lkey;
956 struct txq_mp2mr_mbuf_check_data {
961 * Callback function for rte_mempool_obj_iter() to check whether a given
962 * mempool object looks like a mbuf.
965 * The mempool pointer
967 * Context data (struct txq_mp2mr_mbuf_check_data). Contains the
972 * Object index, unused.
975 txq_mp2mr_mbuf_check(struct rte_mempool *mp, void *arg, void *obj,
976 uint32_t index __rte_unused)
978 struct txq_mp2mr_mbuf_check_data *data = arg;
979 struct rte_mbuf *buf = obj;
981 /* Check whether mbuf structure fits element size and whether mempool
982 * pointer is valid. */
983 if (sizeof(*buf) > mp->elt_size || buf->pool != mp)
988 * Iterator function for rte_mempool_walk() to register existing mempools and
989 * fill the MP to MR cache of a TX queue.
992 * Memory Pool to register.
994 * Pointer to TX queue structure.
997 txq_mp2mr_iter(struct rte_mempool *mp, void *arg)
999 struct txq *txq = arg;
1000 struct txq_mp2mr_mbuf_check_data data = {
1004 /* Register mempool only if the first element looks like a mbuf. */
1005 if (rte_mempool_obj_iter(mp, txq_mp2mr_mbuf_check, &data) == 0 ||
1012 * DPDK callback for TX.
1015 * Generic pointer to TX queue structure.
1017 * Packets to transmit.
1019 * Number of packets in array.
1022 * Number of packets successfully transmitted (<= pkts_n).
1025 mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
1027 struct txq *txq = (struct txq *)dpdk_txq;
1028 unsigned int elts_head = txq->elts_head;
1029 const unsigned int elts_n = txq->elts_n;
1030 unsigned int elts_comp_cd = txq->elts_comp_cd;
1031 unsigned int elts_comp = 0;
1036 assert(elts_comp_cd != 0);
1038 max = (elts_n - (elts_head - txq->elts_tail));
1042 assert(max <= elts_n);
1043 /* Always leave one free entry in the ring. */
1049 for (i = 0; (i != max); ++i) {
1050 struct rte_mbuf *buf = pkts[i];
1051 unsigned int elts_head_next =
1052 (((elts_head + 1) == elts_n) ? 0 : elts_head + 1);
1053 struct txq_elt *elt_next = &(*txq->elts)[elts_head_next];
1054 struct txq_elt *elt = &(*txq->elts)[elts_head];
1055 unsigned int segs = NB_SEGS(buf);
1056 unsigned int sent_size = 0;
1057 uint32_t send_flags = 0;
1059 /* Clean up old buffer. */
1060 if (likely(elt->buf != NULL)) {
1061 struct rte_mbuf *tmp = elt->buf;
1065 memset(elt, 0x66, sizeof(*elt));
1067 /* Faster than rte_pktmbuf_free(). */
1069 struct rte_mbuf *next = NEXT(tmp);
1071 rte_pktmbuf_free_seg(tmp);
1073 } while (tmp != NULL);
1075 /* Request TX completion. */
1076 if (unlikely(--elts_comp_cd == 0)) {
1077 elts_comp_cd = txq->elts_comp_cd_init;
1079 send_flags |= IBV_EXP_QP_BURST_SIGNALED;
1081 if (likely(segs == 1)) {
1086 /* Retrieve buffer information. */
1087 addr = rte_pktmbuf_mtod(buf, uintptr_t);
1088 length = DATA_LEN(buf);
1089 /* Retrieve Memory Region key for this memory pool. */
1090 lkey = txq_mp2mr(txq, txq_mb2mp(buf));
1091 if (unlikely(lkey == (uint32_t)-1)) {
1092 /* MR does not exist. */
1093 DEBUG("%p: unable to get MP <-> MR"
1094 " association", (void *)txq);
1095 /* Clean up TX element. */
1099 /* Update element. */
1102 rte_prefetch0((volatile void *)
1104 RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf);
1105 /* Put packet into send queue. */
1106 if (length <= txq->max_inline)
1107 err = txq->if_qp->send_pending_inline
1113 err = txq->if_qp->send_pending
1121 sent_size += length;
1126 elts_head = elts_head_next;
1127 /* Increment sent bytes counter. */
1128 txq->stats.obytes += sent_size;
1131 /* Take a shortcut if nothing must be sent. */
1132 if (unlikely(i == 0))
1134 /* Increment sent packets counter. */
1135 txq->stats.opackets += i;
1136 /* Ring QP doorbell. */
1137 err = txq->if_qp->send_flush(txq->qp);
1138 if (unlikely(err)) {
1139 /* A nonzero value is not supposed to be returned.
1140 * Nothing can be done about it. */
1141 DEBUG("%p: send_flush() failed with error %d",
1144 txq->elts_head = elts_head;
1145 txq->elts_comp += elts_comp;
1146 txq->elts_comp_cd = elts_comp_cd;
1151 * Configure a TX queue.
1154 * Pointer to Ethernet device structure.
1156 * Pointer to TX queue structure.
1158 * Number of descriptors to configure in queue.
1160 * NUMA socket on which memory must be allocated.
1162 * Thresholds parameters.
1165 * 0 on success, errno value on failure.
1168 txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc,
1169 unsigned int socket, const struct rte_eth_txconf *conf)
1171 struct priv *priv = dev->data->dev_private;
1177 struct ibv_exp_query_intf_params params;
1178 struct ibv_exp_qp_init_attr init;
1179 struct ibv_exp_res_domain_init_attr rd;
1180 struct ibv_exp_cq_init_attr cq;
1181 struct ibv_exp_qp_attr mod;
1183 enum ibv_exp_query_intf_status status;
1186 (void)conf; /* Thresholds configuration (ignored). */
1190 ERROR("%p: invalid number of Tx descriptors", (void *)dev);
1193 /* MRs will be registered in mp2mr[] later. */
1194 attr.rd = (struct ibv_exp_res_domain_init_attr){
1195 .comp_mask = (IBV_EXP_RES_DOMAIN_THREAD_MODEL |
1196 IBV_EXP_RES_DOMAIN_MSG_MODEL),
1197 .thread_model = IBV_EXP_THREAD_SINGLE,
1198 .msg_model = IBV_EXP_MSG_HIGH_BW,
1200 tmpl.rd = ibv_exp_create_res_domain(priv->ctx, &attr.rd);
1201 if (tmpl.rd == NULL) {
1203 ERROR("%p: RD creation failure: %s",
1204 (void *)dev, strerror(ret));
1207 attr.cq = (struct ibv_exp_cq_init_attr){
1208 .comp_mask = IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN,
1209 .res_domain = tmpl.rd,
1211 tmpl.cq = ibv_exp_create_cq(priv->ctx, desc, NULL, NULL, 0, &attr.cq);
1212 if (tmpl.cq == NULL) {
1214 ERROR("%p: CQ creation failure: %s",
1215 (void *)dev, strerror(ret));
1218 DEBUG("priv->device_attr.max_qp_wr is %d",
1219 priv->device_attr.max_qp_wr);
1220 DEBUG("priv->device_attr.max_sge is %d",
1221 priv->device_attr.max_sge);
1222 attr.init = (struct ibv_exp_qp_init_attr){
1223 /* CQ to be associated with the send queue. */
1225 /* CQ to be associated with the receive queue. */
1228 /* Max number of outstanding WRs. */
1229 .max_send_wr = ((priv->device_attr.max_qp_wr < desc) ?
1230 priv->device_attr.max_qp_wr :
1232 /* Max number of scatter/gather elements in a WR. */
1234 .max_inline_data = MLX4_PMD_MAX_INLINE,
1236 .qp_type = IBV_QPT_RAW_PACKET,
1237 /* Do *NOT* enable this, completions events are managed per
1241 .res_domain = tmpl.rd,
1242 .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD |
1243 IBV_EXP_QP_INIT_ATTR_RES_DOMAIN),
1245 tmpl.qp = ibv_exp_create_qp(priv->ctx, &attr.init);
1246 if (tmpl.qp == NULL) {
1247 ret = (errno ? errno : EINVAL);
1248 ERROR("%p: QP creation failure: %s",
1249 (void *)dev, strerror(ret));
1252 /* ibv_create_qp() updates this value. */
1253 tmpl.max_inline = attr.init.cap.max_inline_data;
1254 attr.mod = (struct ibv_exp_qp_attr){
1255 /* Move the QP to this state. */
1256 .qp_state = IBV_QPS_INIT,
1257 /* Primary port number. */
1258 .port_num = priv->port
1260 ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod,
1261 (IBV_EXP_QP_STATE | IBV_EXP_QP_PORT));
1263 ERROR("%p: QP state to IBV_QPS_INIT failed: %s",
1264 (void *)dev, strerror(ret));
1267 ret = txq_alloc_elts(&tmpl, desc);
1269 ERROR("%p: TXQ allocation failed: %s",
1270 (void *)dev, strerror(ret));
1273 attr.mod = (struct ibv_exp_qp_attr){
1274 .qp_state = IBV_QPS_RTR
1276 ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, IBV_EXP_QP_STATE);
1278 ERROR("%p: QP state to IBV_QPS_RTR failed: %s",
1279 (void *)dev, strerror(ret));
1282 attr.mod.qp_state = IBV_QPS_RTS;
1283 ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, IBV_EXP_QP_STATE);
1285 ERROR("%p: QP state to IBV_QPS_RTS failed: %s",
1286 (void *)dev, strerror(ret));
1289 attr.params = (struct ibv_exp_query_intf_params){
1290 .intf_scope = IBV_EXP_INTF_GLOBAL,
1291 .intf = IBV_EXP_INTF_CQ,
1294 tmpl.if_cq = ibv_exp_query_intf(priv->ctx, &attr.params, &status);
1295 if (tmpl.if_cq == NULL) {
1296 ERROR("%p: CQ interface family query failed with status %d",
1297 (void *)dev, status);
1300 attr.params = (struct ibv_exp_query_intf_params){
1301 .intf_scope = IBV_EXP_INTF_GLOBAL,
1302 .intf = IBV_EXP_INTF_QP_BURST,
1304 #ifdef HAVE_EXP_QP_BURST_CREATE_DISABLE_ETH_LOOPBACK
1305 /* MC loopback must be disabled when not using a VF. */
1308 IBV_EXP_QP_BURST_CREATE_DISABLE_ETH_LOOPBACK :
1312 tmpl.if_qp = ibv_exp_query_intf(priv->ctx, &attr.params, &status);
1313 if (tmpl.if_qp == NULL) {
1314 ERROR("%p: QP interface family query failed with status %d",
1315 (void *)dev, status);
1318 /* Clean up txq in case we're reinitializing it. */
1319 DEBUG("%p: cleaning-up old txq just in case", (void *)txq);
1322 DEBUG("%p: txq updated with %p", (void *)txq, (void *)&tmpl);
1323 /* Pre-register known mempools. */
1324 rte_mempool_walk(txq_mp2mr_iter, txq);
1334 * DPDK callback to configure a TX queue.
1337 * Pointer to Ethernet device structure.
1341 * Number of descriptors to configure in queue.
1343 * NUMA socket on which memory must be allocated.
1345 * Thresholds parameters.
1348 * 0 on success, negative errno value on failure.
1351 mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
1352 unsigned int socket, const struct rte_eth_txconf *conf)
1354 struct priv *priv = dev->data->dev_private;
1355 struct txq *txq = (*priv->txqs)[idx];
1359 DEBUG("%p: configuring queue %u for %u descriptors",
1360 (void *)dev, idx, desc);
1361 if (idx >= priv->txqs_n) {
1362 ERROR("%p: queue index out of range (%u >= %u)",
1363 (void *)dev, idx, priv->txqs_n);
1368 DEBUG("%p: reusing already allocated queue index %u (%p)",
1369 (void *)dev, idx, (void *)txq);
1370 if (priv->started) {
1374 (*priv->txqs)[idx] = NULL;
1377 txq = rte_calloc_socket("TXQ", 1, sizeof(*txq), 0, socket);
1379 ERROR("%p: unable to allocate queue index %u",
1385 ret = txq_setup(dev, txq, desc, socket, conf);
1389 txq->stats.idx = idx;
1390 DEBUG("%p: adding TX queue %p to list",
1391 (void *)dev, (void *)txq);
1392 (*priv->txqs)[idx] = txq;
1393 /* Update send callback. */
1394 dev->tx_pkt_burst = mlx4_tx_burst;
1401 * DPDK callback to release a TX queue.
1404 * Generic TX queue pointer.
1407 mlx4_tx_queue_release(void *dpdk_txq)
1409 struct txq *txq = (struct txq *)dpdk_txq;
1417 for (i = 0; (i != priv->txqs_n); ++i)
1418 if ((*priv->txqs)[i] == txq) {
1419 DEBUG("%p: removing TX queue %p from list",
1420 (void *)priv->dev, (void *)txq);
1421 (*priv->txqs)[i] = NULL;
1429 /* RX queues handling. */
1432 * Allocate RX queue elements.
1435 * Pointer to RX queue structure.
1437 * Number of elements to allocate.
1440 * 0 on success, errno value on failure.
1443 rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n)
1446 struct rxq_elt (*elts)[elts_n] =
1447 rte_calloc_socket("RXQ elements", 1, sizeof(*elts), 0,
1452 ERROR("%p: can't allocate packets array", (void *)rxq);
1456 /* For each WR (packet). */
1457 for (i = 0; (i != elts_n); ++i) {
1458 struct rxq_elt *elt = &(*elts)[i];
1459 struct ibv_recv_wr *wr = &elt->wr;
1460 struct ibv_sge *sge = &(*elts)[i].sge;
1461 struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
1464 ERROR("%p: empty mbuf pool", (void *)rxq);
1468 /* Configure WR. Work request ID contains its own index in
1469 * the elts array and the offset between SGE buffer header and
1471 WR_ID(wr->wr_id).id = i;
1472 WR_ID(wr->wr_id).offset =
1473 (((uintptr_t)buf->buf_addr + RTE_PKTMBUF_HEADROOM) -
1475 wr->next = &(*elts)[(i + 1)].wr;
1478 /* Headroom is reserved by rte_pktmbuf_alloc(). */
1479 assert(DATA_OFF(buf) == RTE_PKTMBUF_HEADROOM);
1480 /* Buffer is supposed to be empty. */
1481 assert(rte_pktmbuf_data_len(buf) == 0);
1482 assert(rte_pktmbuf_pkt_len(buf) == 0);
1483 /* sge->addr must be able to store a pointer. */
1484 assert(sizeof(sge->addr) >= sizeof(uintptr_t));
1485 /* SGE keeps its headroom. */
1486 sge->addr = (uintptr_t)
1487 ((uint8_t *)buf->buf_addr + RTE_PKTMBUF_HEADROOM);
1488 sge->length = (buf->buf_len - RTE_PKTMBUF_HEADROOM);
1489 sge->lkey = rxq->mr->lkey;
1490 /* Redundant check for tailroom. */
1491 assert(sge->length == rte_pktmbuf_tailroom(buf));
1492 /* Make sure elts index and SGE mbuf pointer can be deduced
1494 if ((WR_ID(wr->wr_id).id != i) ||
1495 ((void *)((uintptr_t)sge->addr -
1496 WR_ID(wr->wr_id).offset) != buf)) {
1497 ERROR("%p: cannot store index and offset in WR ID",
1500 rte_pktmbuf_free(buf);
1505 /* The last WR pointer must be NULL. */
1506 (*elts)[(i - 1)].wr.next = NULL;
1507 DEBUG("%p: allocated and configured %u single-segment WRs",
1508 (void *)rxq, elts_n);
1509 rxq->elts_n = elts_n;
1516 for (i = 0; (i != elemof(*elts)); ++i) {
1517 struct rxq_elt *elt = &(*elts)[i];
1518 struct rte_mbuf *buf;
1520 if (elt->sge.addr == 0)
1522 assert(WR_ID(elt->wr.wr_id).id == i);
1523 buf = (void *)((uintptr_t)elt->sge.addr -
1524 WR_ID(elt->wr.wr_id).offset);
1525 rte_pktmbuf_free_seg(buf);
1529 DEBUG("%p: failed, freed everything", (void *)rxq);
1535 * Free RX queue elements.
1538 * Pointer to RX queue structure.
1541 rxq_free_elts(struct rxq *rxq)
1544 unsigned int elts_n = rxq->elts_n;
1545 struct rxq_elt (*elts)[elts_n] = rxq->elts;
1547 DEBUG("%p: freeing WRs", (void *)rxq);
1552 for (i = 0; (i != elemof(*elts)); ++i) {
1553 struct rxq_elt *elt = &(*elts)[i];
1554 struct rte_mbuf *buf;
1556 if (elt->sge.addr == 0)
1558 assert(WR_ID(elt->wr.wr_id).id == i);
1559 buf = (void *)((uintptr_t)elt->sge.addr -
1560 WR_ID(elt->wr.wr_id).offset);
1561 rte_pktmbuf_free_seg(buf);
1567 * Unregister a MAC address.
1570 * Pointer to private structure.
1573 priv_mac_addr_del(struct priv *priv)
1576 uint8_t (*mac)[ETHER_ADDR_LEN] = &priv->mac.addr_bytes;
1579 if (!priv->mac_flow)
1581 DEBUG("%p: removing MAC address %02x:%02x:%02x:%02x:%02x:%02x",
1583 (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5]);
1584 claim_zero(ibv_destroy_flow(priv->mac_flow));
1585 priv->mac_flow = NULL;
1589 * Register a MAC address.
1591 * The MAC address is registered in queue 0.
1594 * Pointer to private structure.
1597 * 0 on success, errno value on failure.
1600 priv_mac_addr_add(struct priv *priv)
1602 uint8_t (*mac)[ETHER_ADDR_LEN] = &priv->mac.addr_bytes;
1604 struct ibv_flow *flow;
1606 /* If device isn't started, this is all we need to do. */
1611 if (*priv->rxqs && (*priv->rxqs)[0])
1612 rxq = (*priv->rxqs)[0];
1616 /* Allocate flow specification on the stack. */
1617 struct __attribute__((packed)) {
1618 struct ibv_flow_attr attr;
1619 struct ibv_flow_spec_eth spec;
1621 struct ibv_flow_attr *attr = &data.attr;
1622 struct ibv_flow_spec_eth *spec = &data.spec;
1625 priv_mac_addr_del(priv);
1627 * No padding must be inserted by the compiler between attr and spec.
1628 * This layout is expected by libibverbs.
1630 assert(((uint8_t *)attr + sizeof(*attr)) == (uint8_t *)spec);
1631 *attr = (struct ibv_flow_attr){
1632 .type = IBV_FLOW_ATTR_NORMAL,
1638 *spec = (struct ibv_flow_spec_eth){
1639 .type = IBV_FLOW_SPEC_ETH,
1640 .size = sizeof(*spec),
1643 (*mac)[0], (*mac)[1], (*mac)[2],
1644 (*mac)[3], (*mac)[4], (*mac)[5]
1648 .dst_mac = "\xff\xff\xff\xff\xff\xff",
1651 DEBUG("%p: adding MAC address %02x:%02x:%02x:%02x:%02x:%02x",
1653 (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5]);
1654 /* Create related flow. */
1656 flow = ibv_create_flow(rxq->qp, attr);
1658 /* It's not clear whether errno is always set in this case. */
1659 ERROR("%p: flow configuration failed, errno=%d: %s",
1661 (errno ? strerror(errno) : "Unknown error"));
1666 assert(priv->mac_flow == NULL);
1667 priv->mac_flow = flow;
1672 * Clean up a RX queue.
1674 * Destroy objects, free allocated memory and reset the structure for reuse.
1677 * Pointer to RX queue structure.
1680 rxq_cleanup(struct rxq *rxq)
1682 struct ibv_exp_release_intf_params params;
1684 DEBUG("cleaning up %p", (void *)rxq);
1686 if (rxq->if_qp != NULL) {
1687 assert(rxq->priv != NULL);
1688 assert(rxq->priv->ctx != NULL);
1689 assert(rxq->qp != NULL);
1690 params = (struct ibv_exp_release_intf_params){
1693 claim_zero(ibv_exp_release_intf(rxq->priv->ctx,
1697 if (rxq->if_cq != NULL) {
1698 assert(rxq->priv != NULL);
1699 assert(rxq->priv->ctx != NULL);
1700 assert(rxq->cq != NULL);
1701 params = (struct ibv_exp_release_intf_params){
1704 claim_zero(ibv_exp_release_intf(rxq->priv->ctx,
1708 if (rxq->qp != NULL)
1709 claim_zero(ibv_destroy_qp(rxq->qp));
1710 if (rxq->cq != NULL)
1711 claim_zero(ibv_destroy_cq(rxq->cq));
1712 if (rxq->channel != NULL)
1713 claim_zero(ibv_destroy_comp_channel(rxq->channel));
1714 if (rxq->rd != NULL) {
1715 struct ibv_exp_destroy_res_domain_attr attr = {
1719 assert(rxq->priv != NULL);
1720 assert(rxq->priv->ctx != NULL);
1721 claim_zero(ibv_exp_destroy_res_domain(rxq->priv->ctx,
1725 if (rxq->mr != NULL)
1726 claim_zero(ibv_dereg_mr(rxq->mr));
1727 memset(rxq, 0, sizeof(*rxq));
1731 * DPDK callback for RX.
1733 * The following function doesn't manage scattered packets.
1736 * Generic pointer to RX queue structure.
1738 * Array to store received packets.
1740 * Maximum number of packets in array.
1743 * Number of packets successfully received (<= pkts_n).
1746 mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1748 struct rxq *rxq = (struct rxq *)dpdk_rxq;
1749 struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts;
1750 const unsigned int elts_n = rxq->elts_n;
1751 unsigned int elts_head = rxq->elts_head;
1752 struct ibv_sge sges[pkts_n];
1754 unsigned int pkts_ret = 0;
1757 for (i = 0; (i != pkts_n); ++i) {
1758 struct rxq_elt *elt = &(*elts)[elts_head];
1759 struct ibv_recv_wr *wr = &elt->wr;
1760 uint64_t wr_id = wr->wr_id;
1762 struct rte_mbuf *seg = (void *)((uintptr_t)elt->sge.addr -
1763 WR_ID(wr_id).offset);
1764 struct rte_mbuf *rep;
1767 /* Sanity checks. */
1768 assert(WR_ID(wr_id).id < rxq->elts_n);
1769 assert(wr->sg_list == &elt->sge);
1770 assert(wr->num_sge == 1);
1771 assert(elts_head < rxq->elts_n);
1772 assert(rxq->elts_head < rxq->elts_n);
1774 * Fetch initial bytes of packet descriptor into a
1775 * cacheline while allocating rep.
1777 rte_mbuf_prefetch_part1(seg);
1778 rte_mbuf_prefetch_part2(seg);
1779 ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL,
1781 if (unlikely(ret < 0)) {
1785 DEBUG("rxq=%p, poll_length() failed (ret=%d)",
1787 /* ibv_poll_cq() must be used in case of failure. */
1788 wcs_n = ibv_poll_cq(rxq->cq, 1, &wc);
1789 if (unlikely(wcs_n == 0))
1791 if (unlikely(wcs_n < 0)) {
1792 DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)",
1793 (void *)rxq, wcs_n);
1797 if (unlikely(wc.status != IBV_WC_SUCCESS)) {
1798 /* Whatever, just repost the offending WR. */
1799 DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work"
1800 " completion status (%d): %s",
1801 (void *)rxq, wc.wr_id, wc.status,
1802 ibv_wc_status_str(wc.status));
1803 /* Increment dropped packets counter. */
1804 ++rxq->stats.idropped;
1805 /* Add SGE to array for repost. */
1814 rep = rte_mbuf_raw_alloc(rxq->mp);
1815 if (unlikely(rep == NULL)) {
1817 * Unable to allocate a replacement mbuf,
1820 DEBUG("rxq=%p, wr_id=%" PRIu32 ":"
1821 " can't allocate a new mbuf",
1822 (void *)rxq, WR_ID(wr_id).id);
1823 /* Increase out of memory counters. */
1824 ++rxq->stats.rx_nombuf;
1825 ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
1826 /* Add SGE to array for repost. */
1831 /* Reconfigure sge to use rep instead of seg. */
1832 elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
1833 assert(elt->sge.lkey == rxq->mr->lkey);
1834 WR_ID(wr->wr_id).offset =
1835 (((uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM) -
1837 assert(WR_ID(wr->wr_id).id == WR_ID(wr_id).id);
1839 /* Add SGE to array for repost. */
1842 /* Update seg information. */
1843 SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
1845 PORT(seg) = rxq->port_id;
1848 DATA_LEN(seg) = len;
1849 seg->packet_type = 0;
1852 /* Return packet. */
1855 /* Increase bytes counter. */
1856 rxq->stats.ibytes += len;
1858 if (++elts_head >= elts_n)
1862 if (unlikely(i == 0))
1865 ret = rxq->if_qp->recv_burst(rxq->qp, sges, i);
1866 if (unlikely(ret)) {
1867 /* Inability to repost WRs is fatal. */
1868 DEBUG("%p: recv_burst(): failed (ret=%d)",
1873 rxq->elts_head = elts_head;
1874 /* Increase packets counter. */
1875 rxq->stats.ipackets += pkts_ret;
1880 * Allocate a Queue Pair.
1881 * Optionally setup inline receive if supported.
1884 * Pointer to private structure.
1886 * Completion queue to associate with QP.
1888 * Number of descriptors in QP (hint only).
1891 * QP pointer or NULL in case of error.
1893 static struct ibv_qp *
1894 rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, uint16_t desc,
1895 struct ibv_exp_res_domain *rd)
1897 struct ibv_exp_qp_init_attr attr = {
1898 /* CQ to be associated with the send queue. */
1900 /* CQ to be associated with the receive queue. */
1903 /* Max number of outstanding WRs. */
1904 .max_recv_wr = ((priv->device_attr.max_qp_wr < desc) ?
1905 priv->device_attr.max_qp_wr :
1907 /* Max number of scatter/gather elements in a WR. */
1910 .qp_type = IBV_QPT_RAW_PACKET,
1911 .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD |
1912 IBV_EXP_QP_INIT_ATTR_RES_DOMAIN),
1917 return ibv_exp_create_qp(priv->ctx, &attr);
1921 * Configure a RX queue.
1924 * Pointer to Ethernet device structure.
1926 * Pointer to RX queue structure.
1928 * Number of descriptors to configure in queue.
1930 * NUMA socket on which memory must be allocated.
1932 * Thresholds parameters.
1934 * Memory pool for buffer allocations.
1937 * 0 on success, errno value on failure.
1940 rxq_setup(struct rte_eth_dev *dev, struct rxq *rxq, uint16_t desc,
1941 unsigned int socket, const struct rte_eth_rxconf *conf,
1942 struct rte_mempool *mp)
1944 struct priv *priv = dev->data->dev_private;
1950 struct ibv_exp_qp_attr mod;
1952 struct ibv_exp_query_intf_params params;
1953 struct ibv_exp_cq_init_attr cq;
1954 struct ibv_exp_res_domain_init_attr rd;
1956 enum ibv_exp_query_intf_status status;
1957 struct ibv_recv_wr *bad_wr;
1958 unsigned int mb_len;
1961 (void)conf; /* Thresholds configuration (ignored). */
1962 mb_len = rte_pktmbuf_data_room_size(mp);
1964 ERROR("%p: invalid number of Rx descriptors", (void *)dev);
1967 /* Enable scattered packets support for this queue if necessary. */
1968 assert(mb_len >= RTE_PKTMBUF_HEADROOM);
1969 if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
1970 (mb_len - RTE_PKTMBUF_HEADROOM)) {
1972 } else if (dev->data->dev_conf.rxmode.enable_scatter) {
1973 WARN("%p: scattered mode has been requested but is"
1974 " not supported, this may lead to packet loss",
1977 WARN("%p: the requested maximum Rx packet size (%u) is"
1978 " larger than a single mbuf (%u) and scattered"
1979 " mode has not been requested",
1981 dev->data->dev_conf.rxmode.max_rx_pkt_len,
1982 mb_len - RTE_PKTMBUF_HEADROOM);
1984 /* Use the entire RX mempool as the memory region. */
1985 tmpl.mr = mlx4_mp2mr(priv->pd, mp);
1986 if (tmpl.mr == NULL) {
1988 ERROR("%p: MR creation failure: %s",
1989 (void *)dev, strerror(ret));
1992 attr.rd = (struct ibv_exp_res_domain_init_attr){
1993 .comp_mask = (IBV_EXP_RES_DOMAIN_THREAD_MODEL |
1994 IBV_EXP_RES_DOMAIN_MSG_MODEL),
1995 .thread_model = IBV_EXP_THREAD_SINGLE,
1996 .msg_model = IBV_EXP_MSG_HIGH_BW,
1998 tmpl.rd = ibv_exp_create_res_domain(priv->ctx, &attr.rd);
1999 if (tmpl.rd == NULL) {
2001 ERROR("%p: RD creation failure: %s",
2002 (void *)dev, strerror(ret));
2005 if (dev->data->dev_conf.intr_conf.rxq) {
2006 tmpl.channel = ibv_create_comp_channel(priv->ctx);
2007 if (tmpl.channel == NULL) {
2009 ERROR("%p: Rx interrupt completion channel creation"
2011 (void *)dev, strerror(ret));
2015 attr.cq = (struct ibv_exp_cq_init_attr){
2016 .comp_mask = IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN,
2017 .res_domain = tmpl.rd,
2019 tmpl.cq = ibv_exp_create_cq(priv->ctx, desc, NULL, tmpl.channel, 0,
2021 if (tmpl.cq == NULL) {
2023 ERROR("%p: CQ creation failure: %s",
2024 (void *)dev, strerror(ret));
2027 DEBUG("priv->device_attr.max_qp_wr is %d",
2028 priv->device_attr.max_qp_wr);
2029 DEBUG("priv->device_attr.max_sge is %d",
2030 priv->device_attr.max_sge);
2031 tmpl.qp = rxq_setup_qp(priv, tmpl.cq, desc, tmpl.rd);
2032 if (tmpl.qp == NULL) {
2033 ret = (errno ? errno : EINVAL);
2034 ERROR("%p: QP creation failure: %s",
2035 (void *)dev, strerror(ret));
2038 mod = (struct ibv_exp_qp_attr){
2039 /* Move the QP to this state. */
2040 .qp_state = IBV_QPS_INIT,
2041 /* Primary port number. */
2042 .port_num = priv->port
2044 ret = ibv_exp_modify_qp(tmpl.qp, &mod,
2048 ERROR("%p: QP state to IBV_QPS_INIT failed: %s",
2049 (void *)dev, strerror(ret));
2052 ret = rxq_alloc_elts(&tmpl, desc);
2054 ERROR("%p: RXQ allocation failed: %s",
2055 (void *)dev, strerror(ret));
2058 ret = ibv_post_recv(tmpl.qp, &(*tmpl.elts)[0].wr, &bad_wr);
2060 ERROR("%p: ibv_post_recv() failed for WR %p: %s",
2066 mod = (struct ibv_exp_qp_attr){
2067 .qp_state = IBV_QPS_RTR
2069 ret = ibv_exp_modify_qp(tmpl.qp, &mod, IBV_EXP_QP_STATE);
2071 ERROR("%p: QP state to IBV_QPS_RTR failed: %s",
2072 (void *)dev, strerror(ret));
2076 tmpl.port_id = dev->data->port_id;
2077 DEBUG("%p: RTE port ID: %u", (void *)rxq, tmpl.port_id);
2078 attr.params = (struct ibv_exp_query_intf_params){
2079 .intf_scope = IBV_EXP_INTF_GLOBAL,
2080 .intf = IBV_EXP_INTF_CQ,
2083 tmpl.if_cq = ibv_exp_query_intf(priv->ctx, &attr.params, &status);
2084 if (tmpl.if_cq == NULL) {
2085 ERROR("%p: CQ interface family query failed with status %d",
2086 (void *)dev, status);
2089 attr.params = (struct ibv_exp_query_intf_params){
2090 .intf_scope = IBV_EXP_INTF_GLOBAL,
2091 .intf = IBV_EXP_INTF_QP_BURST,
2094 tmpl.if_qp = ibv_exp_query_intf(priv->ctx, &attr.params, &status);
2095 if (tmpl.if_qp == NULL) {
2096 ERROR("%p: QP interface family query failed with status %d",
2097 (void *)dev, status);
2100 /* Clean up rxq in case we're reinitializing it. */
2101 DEBUG("%p: cleaning-up old rxq just in case", (void *)rxq);
2104 DEBUG("%p: rxq updated with %p", (void *)rxq, (void *)&tmpl);
2114 * DPDK callback to configure a RX queue.
2117 * Pointer to Ethernet device structure.
2121 * Number of descriptors to configure in queue.
2123 * NUMA socket on which memory must be allocated.
2125 * Thresholds parameters.
2127 * Memory pool for buffer allocations.
2130 * 0 on success, negative errno value on failure.
2133 mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
2134 unsigned int socket, const struct rte_eth_rxconf *conf,
2135 struct rte_mempool *mp)
2137 struct priv *priv = dev->data->dev_private;
2138 struct rxq *rxq = (*priv->rxqs)[idx];
2142 DEBUG("%p: configuring queue %u for %u descriptors",
2143 (void *)dev, idx, desc);
2144 if (idx >= priv->rxqs_n) {
2145 ERROR("%p: queue index out of range (%u >= %u)",
2146 (void *)dev, idx, priv->rxqs_n);
2151 DEBUG("%p: reusing already allocated queue index %u (%p)",
2152 (void *)dev, idx, (void *)rxq);
2153 if (priv->started) {
2157 (*priv->rxqs)[idx] = NULL;
2159 priv_mac_addr_del(priv);
2162 rxq = rte_calloc_socket("RXQ", 1, sizeof(*rxq), 0, socket);
2164 ERROR("%p: unable to allocate queue index %u",
2170 ret = rxq_setup(dev, rxq, desc, socket, conf, mp);
2174 rxq->stats.idx = idx;
2175 DEBUG("%p: adding RX queue %p to list",
2176 (void *)dev, (void *)rxq);
2177 (*priv->rxqs)[idx] = rxq;
2178 /* Update receive callback. */
2179 dev->rx_pkt_burst = mlx4_rx_burst;
2186 * DPDK callback to release a RX queue.
2189 * Generic RX queue pointer.
2192 mlx4_rx_queue_release(void *dpdk_rxq)
2194 struct rxq *rxq = (struct rxq *)dpdk_rxq;
2202 for (i = 0; (i != priv->rxqs_n); ++i)
2203 if ((*priv->rxqs)[i] == rxq) {
2204 DEBUG("%p: removing RX queue %p from list",
2205 (void *)priv->dev, (void *)rxq);
2206 (*priv->rxqs)[i] = NULL;
2208 priv_mac_addr_del(priv);
2217 priv_dev_interrupt_handler_install(struct priv *, struct rte_eth_dev *);
2220 priv_dev_removal_interrupt_handler_install(struct priv *, struct rte_eth_dev *);
2223 priv_dev_link_interrupt_handler_install(struct priv *, struct rte_eth_dev *);
2226 * DPDK callback to start the device.
2228 * Simulate device start by attaching all configured flows.
2231 * Pointer to Ethernet device structure.
2234 * 0 on success, negative errno value on failure.
2237 mlx4_dev_start(struct rte_eth_dev *dev)
2239 struct priv *priv = dev->data->dev_private;
2243 if (priv->started) {
2247 DEBUG("%p: attaching configured flows to all RX queues", (void *)dev);
2249 ret = priv_mac_addr_add(priv);
2252 ret = priv_dev_link_interrupt_handler_install(priv, dev);
2254 ERROR("%p: LSC handler install failed",
2258 ret = priv_dev_removal_interrupt_handler_install(priv, dev);
2260 ERROR("%p: RMV handler install failed",
2264 ret = priv_rx_intr_vec_enable(priv);
2266 ERROR("%p: Rx interrupt vector creation failed",
2270 ret = mlx4_priv_flow_start(priv);
2272 ERROR("%p: flow start failed: %s",
2273 (void *)dev, strerror(ret));
2280 priv_mac_addr_del(priv);
2287 * DPDK callback to stop the device.
2289 * Simulate device stop by detaching all configured flows.
2292 * Pointer to Ethernet device structure.
2295 mlx4_dev_stop(struct rte_eth_dev *dev)
2297 struct priv *priv = dev->data->dev_private;
2300 if (!priv->started) {
2304 DEBUG("%p: detaching flows from all RX queues", (void *)dev);
2306 mlx4_priv_flow_stop(priv);
2307 priv_mac_addr_del(priv);
2312 * Dummy DPDK callback for TX.
2314 * This function is used to temporarily replace the real callback during
2315 * unsafe control operations on the queue, or in case of error.
2318 * Generic pointer to TX queue structure.
2320 * Packets to transmit.
2322 * Number of packets in array.
2325 * Number of packets successfully transmitted (<= pkts_n).
2328 removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
2337 * Dummy DPDK callback for RX.
2339 * This function is used to temporarily replace the real callback during
2340 * unsafe control operations on the queue, or in case of error.
2343 * Generic pointer to RX queue structure.
2345 * Array to store received packets.
2347 * Maximum number of packets in array.
2350 * Number of packets successfully received (<= pkts_n).
2353 removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
2362 priv_dev_interrupt_handler_uninstall(struct priv *, struct rte_eth_dev *);
2365 priv_dev_removal_interrupt_handler_uninstall(struct priv *,
2366 struct rte_eth_dev *);
2369 priv_dev_link_interrupt_handler_uninstall(struct priv *, struct rte_eth_dev *);
2372 * DPDK callback to close the device.
2374 * Destroy all queues and objects, free memory.
2377 * Pointer to Ethernet device structure.
2380 mlx4_dev_close(struct rte_eth_dev *dev)
2382 struct priv *priv = dev->data->dev_private;
2389 DEBUG("%p: closing device \"%s\"",
2391 ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
2392 priv_mac_addr_del(priv);
2393 /* Prevent crashes when queues are still in use. This is unfortunately
2394 * still required for DPDK 1.3 because some programs (such as testpmd)
2395 * never release them before closing the device. */
2396 dev->rx_pkt_burst = removed_rx_burst;
2397 dev->tx_pkt_burst = removed_tx_burst;
2398 if (priv->rxqs != NULL) {
2399 /* XXX race condition if mlx4_rx_burst() is still running. */
2401 for (i = 0; (i != priv->rxqs_n); ++i) {
2402 tmp = (*priv->rxqs)[i];
2405 (*priv->rxqs)[i] = NULL;
2412 if (priv->txqs != NULL) {
2413 /* XXX race condition if mlx4_tx_burst() is still running. */
2415 for (i = 0; (i != priv->txqs_n); ++i) {
2416 tmp = (*priv->txqs)[i];
2419 (*priv->txqs)[i] = NULL;
2426 if (priv->pd != NULL) {
2427 assert(priv->ctx != NULL);
2428 claim_zero(ibv_dealloc_pd(priv->pd));
2429 claim_zero(ibv_close_device(priv->ctx));
2431 assert(priv->ctx == NULL);
2432 priv_dev_removal_interrupt_handler_uninstall(priv, dev);
2433 priv_dev_link_interrupt_handler_uninstall(priv, dev);
2434 priv_rx_intr_vec_disable(priv);
2436 memset(priv, 0, sizeof(*priv));
2440 * Change the link state (UP / DOWN).
2443 * Pointer to Ethernet device private data.
2445 * Nonzero for link up, otherwise link down.
2448 * 0 on success, errno value on failure.
2451 priv_set_link(struct priv *priv, int up)
2453 struct rte_eth_dev *dev = priv->dev;
2457 err = priv_set_flags(priv, ~IFF_UP, IFF_UP);
2460 dev->rx_pkt_burst = mlx4_rx_burst;
2462 err = priv_set_flags(priv, ~IFF_UP, ~IFF_UP);
2465 dev->rx_pkt_burst = removed_rx_burst;
2466 dev->tx_pkt_burst = removed_tx_burst;
2472 * DPDK callback to bring the link DOWN.
2475 * Pointer to Ethernet device structure.
2478 * 0 on success, errno value on failure.
2481 mlx4_set_link_down(struct rte_eth_dev *dev)
2483 struct priv *priv = dev->data->dev_private;
2487 err = priv_set_link(priv, 0);
2493 * DPDK callback to bring the link UP.
2496 * Pointer to Ethernet device structure.
2499 * 0 on success, errno value on failure.
2502 mlx4_set_link_up(struct rte_eth_dev *dev)
2504 struct priv *priv = dev->data->dev_private;
2508 err = priv_set_link(priv, 1);
2513 * DPDK callback to get information about the device.
2516 * Pointer to Ethernet device structure.
2518 * Info structure output buffer.
2521 mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
2523 struct priv *priv = dev->data->dev_private;
2525 char ifname[IF_NAMESIZE];
2527 info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2532 /* FIXME: we should ask the device for these values. */
2533 info->min_rx_bufsize = 32;
2534 info->max_rx_pktlen = 65536;
2536 * Since we need one CQ per QP, the limit is the minimum number
2537 * between the two values.
2539 max = ((priv->device_attr.max_cq > priv->device_attr.max_qp) ?
2540 priv->device_attr.max_qp : priv->device_attr.max_cq);
2541 /* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
2544 info->max_rx_queues = max;
2545 info->max_tx_queues = max;
2546 /* Last array entry is reserved for broadcast. */
2547 info->max_mac_addrs = 1;
2548 info->rx_offload_capa = 0;
2549 info->tx_offload_capa = 0;
2550 if (priv_get_ifname(priv, &ifname) == 0)
2551 info->if_index = if_nametoindex(ifname);
2554 ETH_LINK_SPEED_10G |
2555 ETH_LINK_SPEED_20G |
2556 ETH_LINK_SPEED_40G |
2562 * DPDK callback to get device statistics.
2565 * Pointer to Ethernet device structure.
2567 * Stats structure output buffer.
2570 mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2572 struct priv *priv = dev->data->dev_private;
2573 struct rte_eth_stats tmp = {0};
2580 /* Add software counters. */
2581 for (i = 0; (i != priv->rxqs_n); ++i) {
2582 struct rxq *rxq = (*priv->rxqs)[i];
2586 idx = rxq->stats.idx;
2587 if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2588 tmp.q_ipackets[idx] += rxq->stats.ipackets;
2589 tmp.q_ibytes[idx] += rxq->stats.ibytes;
2590 tmp.q_errors[idx] += (rxq->stats.idropped +
2591 rxq->stats.rx_nombuf);
2593 tmp.ipackets += rxq->stats.ipackets;
2594 tmp.ibytes += rxq->stats.ibytes;
2595 tmp.ierrors += rxq->stats.idropped;
2596 tmp.rx_nombuf += rxq->stats.rx_nombuf;
2598 for (i = 0; (i != priv->txqs_n); ++i) {
2599 struct txq *txq = (*priv->txqs)[i];
2603 idx = txq->stats.idx;
2604 if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2605 tmp.q_opackets[idx] += txq->stats.opackets;
2606 tmp.q_obytes[idx] += txq->stats.obytes;
2607 tmp.q_errors[idx] += txq->stats.odropped;
2609 tmp.opackets += txq->stats.opackets;
2610 tmp.obytes += txq->stats.obytes;
2611 tmp.oerrors += txq->stats.odropped;
2618 * DPDK callback to clear device statistics.
2621 * Pointer to Ethernet device structure.
2624 mlx4_stats_reset(struct rte_eth_dev *dev)
2626 struct priv *priv = dev->data->dev_private;
2633 for (i = 0; (i != priv->rxqs_n); ++i) {
2634 if ((*priv->rxqs)[i] == NULL)
2636 idx = (*priv->rxqs)[i]->stats.idx;
2637 (*priv->rxqs)[i]->stats =
2638 (struct mlx4_rxq_stats){ .idx = idx };
2640 for (i = 0; (i != priv->txqs_n); ++i) {
2641 if ((*priv->txqs)[i] == NULL)
2643 idx = (*priv->txqs)[i]->stats.idx;
2644 (*priv->txqs)[i]->stats =
2645 (struct mlx4_txq_stats){ .idx = idx };
2651 * DPDK callback to retrieve physical link information.
2654 * Pointer to Ethernet device structure.
2655 * @param wait_to_complete
2656 * Wait for request completion (ignored).
2659 mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2661 const struct priv *priv = dev->data->dev_private;
2662 struct ethtool_cmd edata = {
2666 struct rte_eth_link dev_link;
2669 /* priv_lock() is not taken to allow concurrent calls. */
2673 (void)wait_to_complete;
2674 if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) {
2675 WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno));
2678 memset(&dev_link, 0, sizeof(dev_link));
2679 dev_link.link_status = ((ifr.ifr_flags & IFF_UP) &&
2680 (ifr.ifr_flags & IFF_RUNNING));
2681 ifr.ifr_data = (void *)&edata;
2682 if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
2683 WARN("ioctl(SIOCETHTOOL, ETHTOOL_GSET) failed: %s",
2687 link_speed = ethtool_cmd_speed(&edata);
2688 if (link_speed == -1)
2689 dev_link.link_speed = 0;
2691 dev_link.link_speed = link_speed;
2692 dev_link.link_duplex = ((edata.duplex == DUPLEX_HALF) ?
2693 ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX);
2694 dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2695 ETH_LINK_SPEED_FIXED);
2696 if (memcmp(&dev_link, &dev->data->dev_link, sizeof(dev_link))) {
2697 /* Link status changed. */
2698 dev->data->dev_link = dev_link;
2701 /* Link status is still the same. */
2706 * DPDK callback to change the MTU.
2709 * Pointer to Ethernet device structure.
2714 * 0 on success, negative errno value on failure.
2717 mlx4_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
2719 struct priv *priv = dev->data->dev_private;
2723 /* Set kernel interface MTU first. */
2724 if (priv_set_mtu(priv, mtu)) {
2726 WARN("cannot set port %u MTU to %u: %s", priv->port, mtu,
2730 DEBUG("adapter port %u MTU set to %u", priv->port, mtu);
2739 * DPDK callback to get flow control status.
2742 * Pointer to Ethernet device structure.
2743 * @param[out] fc_conf
2744 * Flow control output buffer.
2747 * 0 on success, negative errno value on failure.
2750 mlx4_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2752 struct priv *priv = dev->data->dev_private;
2754 struct ethtool_pauseparam ethpause = {
2755 .cmd = ETHTOOL_GPAUSEPARAM
2759 ifr.ifr_data = (void *)ðpause;
2761 if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
2763 WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)"
2769 fc_conf->autoneg = ethpause.autoneg;
2770 if (ethpause.rx_pause && ethpause.tx_pause)
2771 fc_conf->mode = RTE_FC_FULL;
2772 else if (ethpause.rx_pause)
2773 fc_conf->mode = RTE_FC_RX_PAUSE;
2774 else if (ethpause.tx_pause)
2775 fc_conf->mode = RTE_FC_TX_PAUSE;
2777 fc_conf->mode = RTE_FC_NONE;
2787 * DPDK callback to modify flow control parameters.
2790 * Pointer to Ethernet device structure.
2791 * @param[in] fc_conf
2792 * Flow control parameters.
2795 * 0 on success, negative errno value on failure.
2798 mlx4_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2800 struct priv *priv = dev->data->dev_private;
2802 struct ethtool_pauseparam ethpause = {
2803 .cmd = ETHTOOL_SPAUSEPARAM
2807 ifr.ifr_data = (void *)ðpause;
2808 ethpause.autoneg = fc_conf->autoneg;
2809 if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
2810 (fc_conf->mode & RTE_FC_RX_PAUSE))
2811 ethpause.rx_pause = 1;
2813 ethpause.rx_pause = 0;
2815 if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
2816 (fc_conf->mode & RTE_FC_TX_PAUSE))
2817 ethpause.tx_pause = 1;
2819 ethpause.tx_pause = 0;
2822 if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
2824 WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
2837 const struct rte_flow_ops mlx4_flow_ops = {
2838 .validate = mlx4_flow_validate,
2839 .create = mlx4_flow_create,
2840 .destroy = mlx4_flow_destroy,
2841 .flush = mlx4_flow_flush,
2843 .isolate = mlx4_flow_isolate,
2847 * Manage filter operations.
2850 * Pointer to Ethernet device structure.
2851 * @param filter_type
2854 * Operation to perform.
2856 * Pointer to operation-specific structure.
2859 * 0 on success, negative errno value on failure.
2862 mlx4_dev_filter_ctrl(struct rte_eth_dev *dev,
2863 enum rte_filter_type filter_type,
2864 enum rte_filter_op filter_op,
2869 switch (filter_type) {
2870 case RTE_ETH_FILTER_GENERIC:
2871 if (filter_op != RTE_ETH_FILTER_GET)
2873 *(const void **)arg = &mlx4_flow_ops;
2876 ERROR("%p: filter type (%d) not supported",
2877 (void *)dev, filter_type);
2883 static const struct eth_dev_ops mlx4_dev_ops = {
2884 .dev_configure = mlx4_dev_configure,
2885 .dev_start = mlx4_dev_start,
2886 .dev_stop = mlx4_dev_stop,
2887 .dev_set_link_down = mlx4_set_link_down,
2888 .dev_set_link_up = mlx4_set_link_up,
2889 .dev_close = mlx4_dev_close,
2890 .link_update = mlx4_link_update,
2891 .stats_get = mlx4_stats_get,
2892 .stats_reset = mlx4_stats_reset,
2893 .dev_infos_get = mlx4_dev_infos_get,
2894 .rx_queue_setup = mlx4_rx_queue_setup,
2895 .tx_queue_setup = mlx4_tx_queue_setup,
2896 .rx_queue_release = mlx4_rx_queue_release,
2897 .tx_queue_release = mlx4_tx_queue_release,
2898 .flow_ctrl_get = mlx4_dev_get_flow_ctrl,
2899 .flow_ctrl_set = mlx4_dev_set_flow_ctrl,
2900 .mtu_set = mlx4_dev_set_mtu,
2901 .filter_ctrl = mlx4_dev_filter_ctrl,
2902 .rx_queue_intr_enable = mlx4_rx_intr_enable,
2903 .rx_queue_intr_disable = mlx4_rx_intr_disable,
2907 * Get PCI information from struct ibv_device.
2910 * Pointer to Ethernet device structure.
2911 * @param[out] pci_addr
2912 * PCI bus address output buffer.
2915 * 0 on success, -1 on failure and errno is set.
2918 mlx4_ibv_device_to_pci_addr(const struct ibv_device *device,
2919 struct rte_pci_addr *pci_addr)
2923 MKSTR(path, "%s/device/uevent", device->ibdev_path);
2925 file = fopen(path, "rb");
2928 while (fgets(line, sizeof(line), file) == line) {
2929 size_t len = strlen(line);
2932 /* Truncate long lines. */
2933 if (len == (sizeof(line) - 1))
2934 while (line[(len - 1)] != '\n') {
2938 line[(len - 1)] = ret;
2940 /* Extract information. */
2943 "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n",
2947 &pci_addr->function) == 4) {
2957 * Get MAC address by querying netdevice.
2960 * struct priv for the requested device.
2962 * MAC address output buffer.
2965 * 0 on success, -1 on failure and errno is set.
2968 priv_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN])
2970 struct ifreq request;
2972 if (priv_ifreq(priv, SIOCGIFHWADDR, &request))
2974 memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
2979 mlx4_dev_link_status_handler(void *);
2981 mlx4_dev_interrupt_handler(void *);
2984 * Link/device status handler.
2987 * Pointer to private structure.
2989 * Pointer to the rte_eth_dev structure.
2991 * Pointer to event flags holder.
2997 priv_dev_status_handler(struct priv *priv, struct rte_eth_dev *dev,
3000 struct ibv_async_event event;
3001 int port_change = 0;
3002 struct rte_eth_link *link = &dev->data->dev_link;
3006 /* Read all message and acknowledge them. */
3008 if (ibv_get_async_event(priv->ctx, &event))
3010 if ((event.event_type == IBV_EVENT_PORT_ACTIVE ||
3011 event.event_type == IBV_EVENT_PORT_ERR) &&
3012 (priv->intr_conf.lsc == 1)) {
3015 } else if (event.event_type == IBV_EVENT_DEVICE_FATAL &&
3016 priv->intr_conf.rmv == 1) {
3017 *events |= (1 << RTE_ETH_EVENT_INTR_RMV);
3020 DEBUG("event type %d on port %d not handled",
3021 event.event_type, event.element.port_num);
3022 ibv_ack_async_event(&event);
3026 mlx4_link_update(dev, 0);
3027 if (((link->link_speed == 0) && link->link_status) ||
3028 ((link->link_speed != 0) && !link->link_status)) {
3029 if (!priv->pending_alarm) {
3030 /* Inconsistent status, check again later. */
3031 priv->pending_alarm = 1;
3032 rte_eal_alarm_set(MLX4_ALARM_TIMEOUT_US,
3033 mlx4_dev_link_status_handler,
3037 *events |= (1 << RTE_ETH_EVENT_INTR_LSC);
3043 * Handle delayed link status event.
3046 * Registered argument.
3049 mlx4_dev_link_status_handler(void *arg)
3051 struct rte_eth_dev *dev = arg;
3052 struct priv *priv = dev->data->dev_private;
3057 assert(priv->pending_alarm == 1);
3058 priv->pending_alarm = 0;
3059 ret = priv_dev_status_handler(priv, dev, &events);
3061 if (ret > 0 && events & (1 << RTE_ETH_EVENT_INTR_LSC))
3062 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL,
3067 * Handle interrupts from the NIC.
3069 * @param[in] intr_handle
3070 * Interrupt handler.
3072 * Callback argument.
3075 mlx4_dev_interrupt_handler(void *cb_arg)
3077 struct rte_eth_dev *dev = cb_arg;
3078 struct priv *priv = dev->data->dev_private;
3084 ret = priv_dev_status_handler(priv, dev, &ev);
3087 for (i = RTE_ETH_EVENT_UNKNOWN;
3088 i < RTE_ETH_EVENT_MAX;
3090 if (ev & (1 << i)) {
3092 _rte_eth_dev_callback_process(dev, i, NULL,
3098 WARN("%d event%s not processed", ret,
3099 (ret > 1 ? "s were" : " was"));
3104 * Uninstall interrupt handler.
3107 * Pointer to private structure.
3109 * Pointer to the rte_eth_dev structure.
3111 * 0 on success, negative errno value on failure.
3114 priv_dev_interrupt_handler_uninstall(struct priv *priv, struct rte_eth_dev *dev)
3118 if (priv->intr_conf.lsc ||
3119 priv->intr_conf.rmv)
3121 ret = rte_intr_callback_unregister(&priv->intr_handle,
3122 mlx4_dev_interrupt_handler,
3125 ERROR("rte_intr_callback_unregister failed with %d"
3127 (errno ? " (errno: " : ""),
3128 (errno ? strerror(errno) : ""),
3129 (errno ? ")" : ""));
3131 priv->intr_handle.fd = 0;
3132 priv->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
3137 * Install interrupt handler.
3140 * Pointer to private structure.
3142 * Pointer to the rte_eth_dev structure.
3144 * 0 on success, negative errno value on failure.
3147 priv_dev_interrupt_handler_install(struct priv *priv,
3148 struct rte_eth_dev *dev)
3153 /* Check whether the interrupt handler has already been installed
3154 * for either type of interrupt
3156 if (priv->intr_conf.lsc &&
3157 priv->intr_conf.rmv &&
3158 priv->intr_handle.fd)
3160 assert(priv->ctx->async_fd > 0);
3161 flags = fcntl(priv->ctx->async_fd, F_GETFL);
3162 rc = fcntl(priv->ctx->async_fd, F_SETFL, flags | O_NONBLOCK);
3164 INFO("failed to change file descriptor async event queue");
3165 dev->data->dev_conf.intr_conf.lsc = 0;
3166 dev->data->dev_conf.intr_conf.rmv = 0;
3169 priv->intr_handle.fd = priv->ctx->async_fd;
3170 priv->intr_handle.type = RTE_INTR_HANDLE_EXT;
3171 rc = rte_intr_callback_register(&priv->intr_handle,
3172 mlx4_dev_interrupt_handler,
3175 ERROR("rte_intr_callback_register failed "
3176 " (errno: %s)", strerror(errno));
3184 * Uninstall interrupt handler.
3187 * Pointer to private structure.
3189 * Pointer to the rte_eth_dev structure.
3191 * 0 on success, negative value on error.
3194 priv_dev_removal_interrupt_handler_uninstall(struct priv *priv,
3195 struct rte_eth_dev *dev)
3197 if (dev->data->dev_conf.intr_conf.rmv) {
3198 priv->intr_conf.rmv = 0;
3199 return priv_dev_interrupt_handler_uninstall(priv, dev);
3205 * Uninstall interrupt handler.
3208 * Pointer to private structure.
3210 * Pointer to the rte_eth_dev structure.
3212 * 0 on success, negative value on error,
3215 priv_dev_link_interrupt_handler_uninstall(struct priv *priv,
3216 struct rte_eth_dev *dev)
3220 if (dev->data->dev_conf.intr_conf.lsc) {
3221 priv->intr_conf.lsc = 0;
3222 ret = priv_dev_interrupt_handler_uninstall(priv, dev);
3226 if (priv->pending_alarm)
3227 if (rte_eal_alarm_cancel(mlx4_dev_link_status_handler,
3229 ERROR("rte_eal_alarm_cancel failed "
3230 " (errno: %s)", strerror(rte_errno));
3233 priv->pending_alarm = 0;
3238 * Install link interrupt handler.
3241 * Pointer to private structure.
3243 * Pointer to the rte_eth_dev structure.
3245 * 0 on success, negative value on error.
3248 priv_dev_link_interrupt_handler_install(struct priv *priv,
3249 struct rte_eth_dev *dev)
3253 if (dev->data->dev_conf.intr_conf.lsc) {
3254 ret = priv_dev_interrupt_handler_install(priv, dev);
3257 priv->intr_conf.lsc = 1;
3263 * Install removal interrupt handler.
3266 * Pointer to private structure.
3268 * Pointer to the rte_eth_dev structure.
3270 * 0 on success, negative value on error.
3273 priv_dev_removal_interrupt_handler_install(struct priv *priv,
3274 struct rte_eth_dev *dev)
3278 if (dev->data->dev_conf.intr_conf.rmv) {
3279 ret = priv_dev_interrupt_handler_install(priv, dev);
3282 priv->intr_conf.rmv = 1;
3288 * Allocate queue vector and fill epoll fd list for Rx interrupts.
3291 * Pointer to private structure.
3294 * 0 on success, negative on failure.
3297 priv_rx_intr_vec_enable(struct priv *priv)
3300 unsigned int rxqs_n = priv->rxqs_n;
3301 unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
3302 unsigned int count = 0;
3303 struct rte_intr_handle *intr_handle = priv->dev->intr_handle;
3305 if (!priv->dev->data->dev_conf.intr_conf.rxq)
3307 priv_rx_intr_vec_disable(priv);
3308 intr_handle->intr_vec = malloc(sizeof(intr_handle->intr_vec[rxqs_n]));
3309 if (intr_handle->intr_vec == NULL) {
3310 ERROR("failed to allocate memory for interrupt vector,"
3311 " Rx interrupts will not be supported");
3314 intr_handle->type = RTE_INTR_HANDLE_EXT;
3315 for (i = 0; i != n; ++i) {
3316 struct rxq *rxq = (*priv->rxqs)[i];
3321 /* Skip queues that cannot request interrupts. */
3322 if (!rxq || !rxq->channel) {
3323 /* Use invalid intr_vec[] index to disable entry. */
3324 intr_handle->intr_vec[i] =
3325 RTE_INTR_VEC_RXTX_OFFSET +
3326 RTE_MAX_RXTX_INTR_VEC_ID;
3329 if (count >= RTE_MAX_RXTX_INTR_VEC_ID) {
3330 ERROR("too many Rx queues for interrupt vector size"
3331 " (%d), Rx interrupts cannot be enabled",
3332 RTE_MAX_RXTX_INTR_VEC_ID);
3333 priv_rx_intr_vec_disable(priv);
3336 fd = rxq->channel->fd;
3337 flags = fcntl(fd, F_GETFL);
3338 rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
3340 ERROR("failed to make Rx interrupt file descriptor"
3341 " %d non-blocking for queue index %d", fd, i);
3342 priv_rx_intr_vec_disable(priv);
3345 intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + count;
3346 intr_handle->efds[count] = fd;
3350 priv_rx_intr_vec_disable(priv);
3352 intr_handle->nb_efd = count;
3357 * Clean up Rx interrupts handler.
3360 * Pointer to private structure.
3363 priv_rx_intr_vec_disable(struct priv *priv)
3365 struct rte_intr_handle *intr_handle = priv->dev->intr_handle;
3367 rte_intr_free_epoll_fd(intr_handle);
3368 free(intr_handle->intr_vec);
3369 intr_handle->nb_efd = 0;
3370 intr_handle->intr_vec = NULL;
3374 * DPDK callback for Rx queue interrupt enable.
3377 * Pointer to Ethernet device structure.
3382 * 0 on success, negative on failure.
3385 mlx4_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
3387 struct priv *priv = dev->data->dev_private;
3388 struct rxq *rxq = (*priv->rxqs)[idx];
3391 if (!rxq || !rxq->channel)
3394 ret = ibv_req_notify_cq(rxq->cq, 0);
3396 WARN("unable to arm interrupt on rx queue %d", idx);
3401 * DPDK callback for Rx queue interrupt disable.
3404 * Pointer to Ethernet device structure.
3409 * 0 on success, negative on failure.
3412 mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
3414 struct priv *priv = dev->data->dev_private;
3415 struct rxq *rxq = (*priv->rxqs)[idx];
3416 struct ibv_cq *ev_cq;
3420 if (!rxq || !rxq->channel) {
3423 ret = ibv_get_cq_event(rxq->cq->channel, &ev_cq, &ev_ctx);
3424 if (ret || ev_cq != rxq->cq)
3428 WARN("unable to disable interrupt on rx queue %d",
3431 ibv_ack_cq_events(rxq->cq, 1);
3436 * Verify and store value for device argument.
3439 * Key argument to verify.
3441 * Value associated with key.
3442 * @param[in, out] conf
3443 * Shared configuration data.
3446 * 0 on success, negative errno value on failure.
3449 mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf)
3454 tmp = strtoul(val, NULL, 0);
3456 WARN("%s: \"%s\" is not a valid integer", key, val);
3459 if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {
3460 uint32_t ports = rte_log2_u32(conf->ports.present);
3463 ERROR("port index %lu outside range [0,%" PRIu32 ")",
3467 if (!(conf->ports.present & (1 << tmp))) {
3468 ERROR("invalid port index %lu", tmp);
3471 conf->ports.enabled |= 1 << tmp;
3473 WARN("%s: unknown parameter", key);
3480 * Parse device parameters.
3483 * Device arguments structure.
3486 * 0 on success, negative errno value on failure.
3489 mlx4_args(struct rte_devargs *devargs, struct mlx4_conf *conf)
3491 struct rte_kvargs *kvlist;
3492 unsigned int arg_count;
3496 if (devargs == NULL)
3498 kvlist = rte_kvargs_parse(devargs->args, pmd_mlx4_init_params);
3499 if (kvlist == NULL) {
3500 ERROR("failed to parse kvargs");
3503 /* Process parameters. */
3504 for (i = 0; pmd_mlx4_init_params[i]; ++i) {
3505 arg_count = rte_kvargs_count(kvlist, MLX4_PMD_PORT_KVARG);
3506 while (arg_count-- > 0) {
3507 ret = rte_kvargs_process(kvlist,
3508 MLX4_PMD_PORT_KVARG,
3509 (int (*)(const char *,
3519 rte_kvargs_free(kvlist);
3523 static struct rte_pci_driver mlx4_driver;
3526 * DPDK callback to register a PCI device.
3528 * This function creates an Ethernet device for each port of a given
3531 * @param[in] pci_drv
3532 * PCI driver structure (mlx4_driver).
3533 * @param[in] pci_dev
3534 * PCI device information.
3537 * 0 on success, negative errno value on failure.
3540 mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
3542 struct ibv_device **list;
3543 struct ibv_device *ibv_dev;
3545 struct ibv_context *attr_ctx = NULL;
3546 struct ibv_device_attr device_attr;
3547 struct mlx4_conf conf = {
3554 assert(pci_drv == &mlx4_driver);
3556 list = ibv_get_device_list(&i);
3559 if (errno == ENOSYS)
3560 ERROR("cannot list devices, is ib_uverbs loaded?");
3565 * For each listed device, check related sysfs entry against
3566 * the provided PCI ID.
3569 struct rte_pci_addr pci_addr;
3572 DEBUG("checking device \"%s\"", list[i]->name);
3573 if (mlx4_ibv_device_to_pci_addr(list[i], &pci_addr))
3575 if ((pci_dev->addr.domain != pci_addr.domain) ||
3576 (pci_dev->addr.bus != pci_addr.bus) ||
3577 (pci_dev->addr.devid != pci_addr.devid) ||
3578 (pci_dev->addr.function != pci_addr.function))
3580 vf = (pci_dev->id.device_id ==
3581 PCI_DEVICE_ID_MELLANOX_CONNECTX3VF);
3582 INFO("PCI information matches, using device \"%s\" (VF: %s)",
3583 list[i]->name, (vf ? "true" : "false"));
3584 attr_ctx = ibv_open_device(list[i]);
3588 if (attr_ctx == NULL) {
3589 ibv_free_device_list(list);
3592 ERROR("cannot access device, is mlx4_ib loaded?");
3595 ERROR("cannot use device, are drivers up to date?");
3603 DEBUG("device opened");
3604 if (ibv_query_device(attr_ctx, &device_attr)) {
3608 INFO("%u port(s) detected", device_attr.phys_port_cnt);
3610 conf.ports.present |= (UINT64_C(1) << device_attr.phys_port_cnt) - 1;
3611 if (mlx4_args(pci_dev->device.devargs, &conf)) {
3612 ERROR("failed to process device arguments");
3616 /* Use all ports when none are defined */
3617 if (!conf.ports.enabled)
3618 conf.ports.enabled = conf.ports.present;
3619 for (i = 0; i < device_attr.phys_port_cnt; i++) {
3620 uint32_t port = i + 1; /* ports are indexed from one */
3621 struct ibv_context *ctx = NULL;
3622 struct ibv_port_attr port_attr;
3623 struct ibv_pd *pd = NULL;
3624 struct priv *priv = NULL;
3625 struct rte_eth_dev *eth_dev = NULL;
3626 struct ether_addr mac;
3628 /* If port is not enabled, skip. */
3629 if (!(conf.ports.enabled & (1 << i)))
3632 DEBUG("using port %u", port);
3634 ctx = ibv_open_device(ibv_dev);
3640 /* Check port status. */
3641 err = ibv_query_port(ctx, port, &port_attr);
3643 ERROR("port query failed: %s", strerror(err));
3648 if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
3649 ERROR("port %d is not configured in Ethernet mode",
3655 if (port_attr.state != IBV_PORT_ACTIVE)
3656 DEBUG("port %d is not active: \"%s\" (%d)",
3657 port, ibv_port_state_str(port_attr.state),
3660 /* Allocate protection domain. */
3661 pd = ibv_alloc_pd(ctx);
3663 ERROR("PD allocation failure");
3668 /* from rte_ethdev.c */
3669 priv = rte_zmalloc("ethdev private structure",
3671 RTE_CACHE_LINE_SIZE);
3673 ERROR("priv allocation failure");
3679 priv->device_attr = device_attr;
3682 priv->mtu = ETHER_MTU;
3685 /* Configure the first MAC address by default. */
3686 if (priv_get_mac(priv, &mac.addr_bytes)) {
3687 ERROR("cannot get MAC address, is mlx4_en loaded?"
3688 " (errno: %s)", strerror(errno));
3692 INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x",
3694 mac.addr_bytes[0], mac.addr_bytes[1],
3695 mac.addr_bytes[2], mac.addr_bytes[3],
3696 mac.addr_bytes[4], mac.addr_bytes[5]);
3697 /* Register MAC address. */
3699 if (priv_mac_addr_add(priv))
3703 char ifname[IF_NAMESIZE];
3705 if (priv_get_ifname(priv, &ifname) == 0)
3706 DEBUG("port %u ifname is \"%s\"",
3707 priv->port, ifname);
3709 DEBUG("port %u ifname is unknown", priv->port);
3712 /* Get actual MTU if possible. */
3713 priv_get_mtu(priv, &priv->mtu);
3714 DEBUG("port %u MTU is %u", priv->port, priv->mtu);
3716 /* from rte_ethdev.c */
3718 char name[RTE_ETH_NAME_MAX_LEN];
3720 snprintf(name, sizeof(name), "%s port %u",
3721 ibv_get_device_name(ibv_dev), port);
3722 eth_dev = rte_eth_dev_allocate(name);
3724 if (eth_dev == NULL) {
3725 ERROR("can not allocate rte ethdev");
3730 eth_dev->data->dev_private = priv;
3731 eth_dev->data->mac_addrs = &priv->mac;
3732 eth_dev->device = &pci_dev->device;
3734 rte_eth_copy_pci_info(eth_dev, pci_dev);
3736 eth_dev->device->driver = &mlx4_driver.driver;
3739 * Copy and override interrupt handle to prevent it from
3740 * being shared between all ethdev instances of a given PCI
3741 * device. This is required to properly handle Rx interrupts
3744 priv->intr_handle_dev = *eth_dev->intr_handle;
3745 eth_dev->intr_handle = &priv->intr_handle_dev;
3747 priv->dev = eth_dev;
3748 eth_dev->dev_ops = &mlx4_dev_ops;
3749 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3751 /* Bring Ethernet device up. */
3752 DEBUG("forcing Ethernet interface up");
3753 priv_set_flags(priv, ~IFF_UP, IFF_UP);
3754 /* Update link status once if waiting for LSC. */
3755 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
3756 mlx4_link_update(eth_dev, 0);
3762 claim_zero(ibv_dealloc_pd(pd));
3764 claim_zero(ibv_close_device(ctx));
3766 rte_eth_dev_release_port(eth_dev);
3769 if (i == device_attr.phys_port_cnt)
3773 * XXX if something went wrong in the loop above, there is a resource
3774 * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as
3775 * long as the dpdk does not provide a way to deallocate a ethdev and a
3776 * way to enumerate the registered ethdevs to free the previous ones.
3781 claim_zero(ibv_close_device(attr_ctx));
3783 ibv_free_device_list(list);
3788 static const struct rte_pci_id mlx4_pci_id_map[] = {
3790 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3791 PCI_DEVICE_ID_MELLANOX_CONNECTX3)
3794 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3795 PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO)
3798 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3799 PCI_DEVICE_ID_MELLANOX_CONNECTX3VF)
3806 static struct rte_pci_driver mlx4_driver = {
3808 .name = MLX4_DRIVER_NAME
3810 .id_table = mlx4_pci_id_map,
3811 .probe = mlx4_pci_probe,
3812 .drv_flags = RTE_PCI_DRV_INTR_LSC |
3813 RTE_PCI_DRV_INTR_RMV,
3817 * Driver initialization routine.
3819 RTE_INIT(rte_mlx4_pmd_init);
3821 rte_mlx4_pmd_init(void)
3823 RTE_BUILD_BUG_ON(sizeof(wr_id_t) != sizeof(uint64_t));
3825 * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
3826 * huge pages. Calling ibv_fork_init() during init allows
3827 * applications to use fork() safely for purposes other than
3828 * using this PMD, which is not supported in forked processes.
3830 setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
3832 rte_pci_register(&mlx4_driver);
3835 RTE_PMD_EXPORT_NAME(net_mlx4, __COUNTER__);
3836 RTE_PMD_REGISTER_PCI_TABLE(net_mlx4, mlx4_pci_id_map);
3837 RTE_PMD_REGISTER_KMOD_DEP(net_mlx4,
3838 "* ib_uverbs & mlx4_en & mlx4_core & mlx4_ib");