X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fmlx4%2Fmlx4.c;h=ba060753c33ce5f1de8aa6a212c0ff497efaf9fb;hb=3d555728c9332551efacf0b93307d475a456834c;hp=30c70ee5df46c6111b14d9d20eef090fe6847345;hpb=056eaf2e6d55baeca7ca2b47b29b28d6a174964a;p=dpdk.git diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 30c70ee5df..ba060753c3 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include @@ -59,14 +58,12 @@ #include #include #include -#include -#include -#include #include #include #include #include #include +#include /* Generated configuration header. */ #include "mlx4_autoconf.h" @@ -74,26 +71,8 @@ /* PMD headers. */ #include "mlx4.h" #include "mlx4_flow.h" - -/* Convenience macros for accessing mbuf fields. */ -#define NEXT(m) ((m)->next) -#define DATA_LEN(m) ((m)->data_len) -#define PKT_LEN(m) ((m)->pkt_len) -#define DATA_OFF(m) ((m)->data_off) -#define SET_DATA_OFF(m, o) ((m)->data_off = (o)) -#define NB_SEGS(m) ((m)->nb_segs) -#define PORT(m) ((m)->port) - -/* Work Request ID data type (64 bit). */ -typedef union { - struct { - uint32_t id; - uint16_t offset; - } data; - uint64_t raw; -} wr_id_t; - -#define WR_ID(o) (((wr_id_t *)&(o))->data) +#include "mlx4_rxtx.h" +#include "mlx4_utils.h" /** Configuration structure for device arguments. */ struct mlx4_conf { @@ -109,41 +88,6 @@ const char *pmd_mlx4_init_params[] = { NULL, }; -static int -mlx4_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx); - -static int -mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx); - -static int -priv_rx_intr_vec_enable(struct priv *priv); - -static void -priv_rx_intr_vec_disable(struct priv *priv); - -/** - * Lock private structure to protect it from concurrent access in the - * control path. - * - * @param priv - * Pointer to private structure. - */ -void priv_lock(struct priv *priv) -{ - rte_spinlock_lock(&priv->lock); -} - -/** - * Unlock private structure. - * - * @param priv - * Pointer to private structure. - */ -void priv_unlock(struct priv *priv) -{ - rte_spinlock_unlock(&priv->lock); -} - /* Allocate a buffer on the stack and fill it with a printf format string. */ #define MKSTR(name, ...) \ char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \ @@ -159,7 +103,7 @@ void priv_unlock(struct priv *priv) * Interface name output buffer. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]) @@ -174,8 +118,10 @@ priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]) MKSTR(path, "%s/device/net", priv->ctx->device->ibdev_path); dir = opendir(path); - if (dir == NULL) - return -1; + if (dir == NULL) { + rte_errno = errno; + return -rte_errno; + } } while ((dent = readdir(dir)) != NULL) { char *name = dent->d_name; @@ -225,8 +171,10 @@ try_dev_id: snprintf(match, sizeof(match), "%s", name); } closedir(dir); - if (match[0] == '\0') - return -1; + if (match[0] == '\0') { + rte_errno = ENODEV; + return -rte_errno; + } strncpy(*ifname, match, sizeof(*ifname)); return 0; } @@ -244,7 +192,8 @@ try_dev_id: * Buffer size. * * @return - * 0 on success, -1 on failure and errno is set. + * Number of bytes read on success, negative errno value otherwise and + * rte_errno is set. */ static int priv_sysfs_read(const struct priv *priv, const char *entry, @@ -253,25 +202,27 @@ priv_sysfs_read(const struct priv *priv, const char *entry, char ifname[IF_NAMESIZE]; FILE *file; int ret; - int err; - if (priv_get_ifname(priv, &ifname)) - return -1; + ret = priv_get_ifname(priv, &ifname); + if (ret) + return ret; MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path, ifname, entry); file = fopen(path, "rb"); - if (file == NULL) - return -1; + if (file == NULL) { + rte_errno = errno; + return -rte_errno; + } ret = fread(buf, 1, size, file); - err = errno; - if (((size_t)ret < size) && (ferror(file))) - ret = -1; - else + if ((size_t)ret < size && ferror(file)) { + rte_errno = EIO; + ret = -rte_errno; + } else { ret = size; + } fclose(file); - errno = err; return ret; } @@ -288,7 +239,8 @@ priv_sysfs_read(const struct priv *priv, const char *entry, * Buffer size. * * @return - * 0 on success, -1 on failure and errno is set. + * Number of bytes written on success, negative errno value otherwise and + * rte_errno is set. */ static int priv_sysfs_write(const struct priv *priv, const char *entry, @@ -297,25 +249,27 @@ priv_sysfs_write(const struct priv *priv, const char *entry, char ifname[IF_NAMESIZE]; FILE *file; int ret; - int err; - if (priv_get_ifname(priv, &ifname)) - return -1; + ret = priv_get_ifname(priv, &ifname); + if (ret) + return ret; MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path, ifname, entry); file = fopen(path, "wb"); - if (file == NULL) - return -1; + if (file == NULL) { + rte_errno = errno; + return -rte_errno; + } ret = fwrite(buf, 1, size, file); - err = errno; - if (((size_t)ret < size) || (ferror(file))) - ret = -1; - else + if ((size_t)ret < size || ferror(file)) { + rte_errno = EIO; + ret = -rte_errno; + } else { ret = size; + } fclose(file); - errno = err; return ret; } @@ -330,7 +284,7 @@ priv_sysfs_write(const struct priv *priv, const char *entry, * Value output buffer. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long *value) @@ -340,18 +294,19 @@ priv_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long *value) char value_str[32]; ret = priv_sysfs_read(priv, name, value_str, (sizeof(value_str) - 1)); - if (ret == -1) { + if (ret < 0) { DEBUG("cannot read %s value from sysfs: %s", - name, strerror(errno)); - return -1; + name, strerror(rte_errno)); + return ret; } value_str[ret] = '\0'; errno = 0; value_ret = strtoul(value_str, NULL, 0); if (errno) { + rte_errno = errno; DEBUG("invalid %s value `%s': %s", name, value_str, - strerror(errno)); - return -1; + strerror(rte_errno)); + return -rte_errno; } *value = value_ret; return 0; @@ -368,7 +323,7 @@ priv_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long *value) * Value to set. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long value) @@ -377,10 +332,10 @@ priv_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long value) MKSTR(value_str, "%lu", value); ret = priv_sysfs_write(priv, name, value_str, (sizeof(value_str) - 1)); - if (ret == -1) { + if (ret < 0) { DEBUG("cannot write %s `%s' (%lu) to sysfs: %s", - name, value_str, value, strerror(errno)); - return -1; + name, value_str, value, strerror(rte_errno)); + return ret; } return 0; } @@ -396,18 +351,23 @@ priv_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long value) * Interface request structure output buffer. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_ifreq(const struct priv *priv, int req, struct ifreq *ifr) { int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); - int ret = -1; + int ret; - if (sock == -1) - return ret; - if (priv_get_ifname(priv, &ifr->ifr_name) == 0) - ret = ioctl(sock, req, ifr); + if (sock == -1) { + rte_errno = errno; + return -rte_errno; + } + ret = priv_get_ifname(priv, &ifr->ifr_name); + if (!ret && ioctl(sock, req, ifr) == -1) { + rte_errno = errno; + ret = -rte_errno; + } close(sock); return ret; } @@ -421,42 +381,49 @@ priv_ifreq(const struct priv *priv, int req, struct ifreq *ifr) * MTU value output buffer. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_get_mtu(struct priv *priv, uint16_t *mtu) { - unsigned long ulong_mtu; + unsigned long ulong_mtu = 0; + int ret = priv_get_sysfs_ulong(priv, "mtu", &ulong_mtu); - if (priv_get_sysfs_ulong(priv, "mtu", &ulong_mtu) == -1) - return -1; + if (ret) + return ret; *mtu = ulong_mtu; return 0; } /** - * Set device MTU. + * DPDK callback to change the MTU. * * @param priv - * Pointer to private structure. + * Pointer to Ethernet device structure. * @param mtu * MTU value to set. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int -priv_set_mtu(struct priv *priv, uint16_t mtu) +mlx4_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) { + struct priv *priv = dev->data->dev_private; uint16_t new_mtu; + int ret = priv_set_sysfs_ulong(priv, "mtu", mtu); - if (priv_set_sysfs_ulong(priv, "mtu", mtu) || - priv_get_mtu(priv, &new_mtu)) - return -1; - if (new_mtu == mtu) + if (ret) + return ret; + ret = priv_get_mtu(priv, &new_mtu); + if (ret) + return ret; + if (new_mtu == mtu) { + priv->mtu = mtu; return 0; - errno = EINVAL; - return -1; + } + rte_errno = EINVAL; + return -rte_errno; } /** @@ -470,15 +437,16 @@ priv_set_mtu(struct priv *priv, uint16_t mtu) * Bitmask for flags to modify. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_set_flags(struct priv *priv, unsigned int keep, unsigned int flags) { - unsigned long tmp; + unsigned long tmp = 0; + int ret = priv_get_sysfs_ulong(priv, "flags", &tmp); - if (priv_get_sysfs_ulong(priv, "flags", &tmp) == -1) - return -1; + if (ret) + return ret; tmp &= keep; tmp |= (flags & (~keep)); return priv_set_sysfs_ulong(priv, "flags", tmp); @@ -505,7 +473,7 @@ static void priv_mac_addr_del(struct priv *priv); /** - * Ethernet device configuration. + * DPDK callback for Ethernet device configuration. * * Prepare the driver for a given number of TX and RX queues. * @@ -513,10 +481,10 @@ priv_mac_addr_del(struct priv *priv); * Pointer to Ethernet device structure. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int -dev_configure(struct rte_eth_dev *dev) +mlx4_dev_configure(struct rte_eth_dev *dev) { struct priv *priv = dev->data->dev_private; unsigned int rxqs_n = dev->data->nb_rx_queues; @@ -537,28 +505,6 @@ dev_configure(struct rte_eth_dev *dev) return 0; } -/** - * DPDK callback for Ethernet device configuration. - * - * @param dev - * Pointer to Ethernet device structure. - * - * @return - * 0 on success, negative errno value on failure. - */ -static int -mlx4_dev_configure(struct rte_eth_dev *dev) -{ - struct priv *priv = dev->data->dev_private; - int ret; - - priv_lock(priv); - ret = dev_configure(dev); - assert(ret >= 0); - priv_unlock(priv); - return -ret; -} - static uint16_t mlx4_tx_burst(void *, struct rte_mbuf **, uint16_t); static uint16_t removed_rx_burst(void *, struct rte_mbuf **, uint16_t); @@ -573,7 +519,7 @@ static uint16_t removed_rx_burst(void *, struct rte_mbuf **, uint16_t); * Number of elements to allocate. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int txq_alloc_elts(struct txq *txq, unsigned int elts_n) @@ -599,8 +545,10 @@ txq_alloc_elts(struct txq *txq, unsigned int elts_n) txq->elts_head = 0; txq->elts_tail = 0; txq->elts_comp = 0; - /* Request send completion every MLX4_PMD_TX_PER_COMP_REQ packets or - * at least 4 times per ring. */ + /* + * Request send completion every MLX4_PMD_TX_PER_COMP_REQ packets or + * at least 4 times per ring. + */ txq->elts_comp_cd_init = ((MLX4_PMD_TX_PER_COMP_REQ < (elts_n / 4)) ? MLX4_PMD_TX_PER_COMP_REQ : (elts_n / 4)); @@ -609,10 +557,10 @@ txq_alloc_elts(struct txq *txq, unsigned int elts_n) return 0; error: rte_free(elts); - DEBUG("%p: failed, freed everything", (void *)txq); assert(ret > 0); - return ret; + rte_errno = ret; + return -rte_errno; } /** @@ -654,7 +602,6 @@ txq_free_elts(struct txq *txq) rte_free(elts); } - /** * Clean up a TX queue. * @@ -666,49 +613,15 @@ txq_free_elts(struct txq *txq) static void txq_cleanup(struct txq *txq) { - struct ibv_exp_release_intf_params params; size_t i; DEBUG("cleaning up %p", (void *)txq); txq_free_elts(txq); - if (txq->if_qp != NULL) { - assert(txq->priv != NULL); - assert(txq->priv->ctx != NULL); - assert(txq->qp != NULL); - params = (struct ibv_exp_release_intf_params){ - .comp_mask = 0, - }; - claim_zero(ibv_exp_release_intf(txq->priv->ctx, - txq->if_qp, - ¶ms)); - } - if (txq->if_cq != NULL) { - assert(txq->priv != NULL); - assert(txq->priv->ctx != NULL); - assert(txq->cq != NULL); - params = (struct ibv_exp_release_intf_params){ - .comp_mask = 0, - }; - claim_zero(ibv_exp_release_intf(txq->priv->ctx, - txq->if_cq, - ¶ms)); - } if (txq->qp != NULL) claim_zero(ibv_destroy_qp(txq->qp)); if (txq->cq != NULL) claim_zero(ibv_destroy_cq(txq->cq)); - if (txq->rd != NULL) { - struct ibv_exp_destroy_res_domain_attr attr = { - .comp_mask = 0, - }; - - assert(txq->priv != NULL); - assert(txq->priv->ctx != NULL); - claim_zero(ibv_exp_destroy_res_domain(txq->priv->ctx, - txq->rd, - &attr)); - } - for (i = 0; (i != elemof(txq->mp2mr)); ++i) { + for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) { if (txq->mp2mr[i].mp == NULL) break; assert(txq->mp2mr[i].mr != NULL); @@ -737,11 +650,12 @@ txq_complete(struct txq *txq) unsigned int elts_comp = txq->elts_comp; unsigned int elts_tail = txq->elts_tail; const unsigned int elts_n = txq->elts_n; + struct ibv_wc wcs[elts_comp]; int wcs_n; if (unlikely(elts_comp == 0)) return 0; - wcs_n = txq->if_cq->poll_cnt(txq->cq, elts_comp); + wcs_n = ibv_poll_cq(txq->cq, elts_comp, wcs); if (unlikely(wcs_n == 0)) return 0; if (unlikely(wcs_n < 0)) { @@ -778,7 +692,6 @@ static void mlx4_check_mempool_cb(struct rte_mempool *mp, (void)mp; (void)mem_idx; - /* It already failed, skip the next chunks. */ if (data->ret != 0) return; @@ -822,7 +735,6 @@ static int mlx4_check_mempool(struct rte_mempool *mp, uintptr_t *start, rte_mempool_mem_iter(mp, mlx4_check_mempool_cb, &data); *start = (uintptr_t)data.start; *end = (uintptr_t)data.end; - return data.ret; } @@ -839,7 +751,7 @@ static struct ibv_mr *mlx4_mp2mr(struct ibv_pd *, struct rte_mempool *) * Pointer to memory pool. * * @return - * Memory region pointer, NULL in case of error. + * Memory region pointer, NULL in case of error and rte_errno is set. */ static struct ibv_mr * mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp) @@ -848,13 +760,14 @@ mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp) uintptr_t start; uintptr_t end; unsigned int i; + struct ibv_mr *mr; if (mlx4_check_mempool(mp, &start, &end) != 0) { + rte_errno = EINVAL; ERROR("mempool %p: not virtually contiguous", (void *)mp); return NULL; } - DEBUG("mempool %p area start=%p end=%p size=%zu", (void *)mp, (void *)start, (void *)end, (size_t)(end - start)); @@ -872,10 +785,13 @@ mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp) DEBUG("mempool %p using start=%p end=%p size=%zu for MR", (void *)mp, (void *)start, (void *)end, (size_t)(end - start)); - return ibv_reg_mr(pd, - (void *)start, - end - start, - IBV_ACCESS_LOCAL_WRITE); + mr = ibv_reg_mr(pd, + (void *)start, + end - start, + IBV_ACCESS_LOCAL_WRITE); + if (!mr) + rte_errno = errno ? errno : EINVAL; + return mr; } /** @@ -915,7 +831,7 @@ txq_mp2mr(struct txq *txq, struct rte_mempool *mp) unsigned int i; struct ibv_mr *mr; - for (i = 0; (i != elemof(txq->mp2mr)); ++i) { + for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) { if (unlikely(txq->mp2mr[i].mp == NULL)) { /* Unknown MP, add a new MR for it. */ break; @@ -935,7 +851,7 @@ txq_mp2mr(struct txq *txq, struct rte_mempool *mp) (void *)txq); return (uint32_t)-1; } - if (unlikely(i == elemof(txq->mp2mr))) { + if (unlikely(i == RTE_DIM(txq->mp2mr))) { /* Table is full, remove oldest entry. */ DEBUG("%p: MR <-> MP table full, dropping oldest entry.", (void *)txq); @@ -978,8 +894,10 @@ txq_mp2mr_mbuf_check(struct rte_mempool *mp, void *arg, void *obj, struct txq_mp2mr_mbuf_check_data *data = arg; struct rte_mbuf *buf = obj; - /* Check whether mbuf structure fits element size and whether mempool - * pointer is valid. */ + /* + * Check whether mbuf structure fits element size and whether mempool + * pointer is valid. + */ if (sizeof(*buf) > mp->elt_size || buf->pool != mp) data->ret = -1; } @@ -1025,6 +943,9 @@ static uint16_t mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) { struct txq *txq = (struct txq *)dpdk_txq; + struct ibv_send_wr *wr_head = NULL; + struct ibv_send_wr **wr_next = &wr_head; + struct ibv_send_wr *wr_bad = NULL; unsigned int elts_head = txq->elts_head; const unsigned int elts_n = txq->elts_n; unsigned int elts_comp_cd = txq->elts_comp_cd; @@ -1052,7 +973,8 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) (((elts_head + 1) == elts_n) ? 0 : elts_head + 1); struct txq_elt *elt_next = &(*txq->elts)[elts_head_next]; struct txq_elt *elt = &(*txq->elts)[elts_head]; - unsigned int segs = NB_SEGS(buf); + struct ibv_send_wr *wr = &elt->wr; + unsigned int segs = buf->nb_segs; unsigned int sent_size = 0; uint32_t send_flags = 0; @@ -1066,7 +988,7 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) #endif /* Faster than rte_pktmbuf_free(). */ do { - struct rte_mbuf *next = NEXT(tmp); + struct rte_mbuf *next = tmp->next; rte_pktmbuf_free_seg(tmp); tmp = next; @@ -1076,16 +998,17 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) if (unlikely(--elts_comp_cd == 0)) { elts_comp_cd = txq->elts_comp_cd_init; ++elts_comp; - send_flags |= IBV_EXP_QP_BURST_SIGNALED; + send_flags |= IBV_SEND_SIGNALED; } if (likely(segs == 1)) { + struct ibv_sge *sge = &elt->sge; uintptr_t addr; uint32_t length; uint32_t lkey; /* Retrieve buffer information. */ addr = rte_pktmbuf_mtod(buf, uintptr_t); - length = DATA_LEN(buf); + length = buf->data_len; /* Retrieve Memory Region key for this memory pool. */ lkey = txq_mp2mr(txq, txq_mb2mp(buf)); if (unlikely(lkey == (uint32_t)-1)) { @@ -1102,30 +1025,26 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) rte_prefetch0((volatile void *) (uintptr_t)addr); RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf); - /* Put packet into send queue. */ - if (length <= txq->max_inline) - err = txq->if_qp->send_pending_inline - (txq->qp, - (void *)addr, - length, - send_flags); - else - err = txq->if_qp->send_pending - (txq->qp, - addr, - length, - lkey, - send_flags); - if (unlikely(err)) - goto stop; + sge->addr = addr; + sge->length = length; + sge->lkey = lkey; sent_size += length; } else { err = -1; goto stop; } + if (sent_size <= txq->max_inline) + send_flags |= IBV_SEND_INLINE; elts_head = elts_head_next; /* Increment sent bytes counter. */ txq->stats.obytes += sent_size; + /* Set up WR. */ + wr->sg_list = &elt->sge; + wr->num_sge = segs; + wr->opcode = IBV_WR_SEND; + wr->send_flags = send_flags; + *wr_next = wr; + wr_next = &wr->next; } stop: /* Take a shortcut if nothing must be sent. */ @@ -1134,12 +1053,37 @@ stop: /* Increment sent packets counter. */ txq->stats.opackets += i; /* Ring QP doorbell. */ - err = txq->if_qp->send_flush(txq->qp); + *wr_next = NULL; + assert(wr_head); + err = ibv_post_send(txq->qp, wr_head, &wr_bad); if (unlikely(err)) { - /* A nonzero value is not supposed to be returned. - * Nothing can be done about it. */ - DEBUG("%p: send_flush() failed with error %d", - (void *)txq, err); + uint64_t obytes = 0; + uint64_t opackets = 0; + + /* Rewind bad WRs. */ + while (wr_bad != NULL) { + int j; + + /* Force completion request if one was lost. */ + if (wr_bad->send_flags & IBV_SEND_SIGNALED) { + elts_comp_cd = 1; + --elts_comp; + } + ++opackets; + for (j = 0; j < wr_bad->num_sge; ++j) + obytes += wr_bad->sg_list[j].length; + elts_head = (elts_head ? elts_head : elts_n) - 1; + wr_bad = wr_bad->next; + } + txq->stats.opackets -= opackets; + txq->stats.obytes -= obytes; + i -= opackets; + DEBUG("%p: ibv_post_send() failed, %" PRIu64 " packets" + " (%" PRIu64 " bytes) rejected: %s", + (void *)txq, + opackets, + obytes, + (err <= -1) ? "Internal error" : strerror(err)); } txq->elts_head = elts_head; txq->elts_comp += elts_comp; @@ -1162,7 +1106,7 @@ stop: * Thresholds parameters. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc, @@ -1174,52 +1118,34 @@ txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc, .socket = socket }; union { - struct ibv_exp_query_intf_params params; - struct ibv_exp_qp_init_attr init; - struct ibv_exp_res_domain_init_attr rd; - struct ibv_exp_cq_init_attr cq; - struct ibv_exp_qp_attr mod; + struct ibv_qp_init_attr init; + struct ibv_qp_attr mod; } attr; - enum ibv_exp_query_intf_status status; - int ret = 0; + int ret; (void)conf; /* Thresholds configuration (ignored). */ - if (priv == NULL) - return EINVAL; + if (priv == NULL) { + rte_errno = EINVAL; + goto error; + } if (desc == 0) { + rte_errno = EINVAL; ERROR("%p: invalid number of Tx descriptors", (void *)dev); - return EINVAL; - } - /* MRs will be registered in mp2mr[] later. */ - attr.rd = (struct ibv_exp_res_domain_init_attr){ - .comp_mask = (IBV_EXP_RES_DOMAIN_THREAD_MODEL | - IBV_EXP_RES_DOMAIN_MSG_MODEL), - .thread_model = IBV_EXP_THREAD_SINGLE, - .msg_model = IBV_EXP_MSG_HIGH_BW, - }; - tmpl.rd = ibv_exp_create_res_domain(priv->ctx, &attr.rd); - if (tmpl.rd == NULL) { - ret = ENOMEM; - ERROR("%p: RD creation failure: %s", - (void *)dev, strerror(ret)); goto error; } - attr.cq = (struct ibv_exp_cq_init_attr){ - .comp_mask = IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN, - .res_domain = tmpl.rd, - }; - tmpl.cq = ibv_exp_create_cq(priv->ctx, desc, NULL, NULL, 0, &attr.cq); + /* MRs will be registered in mp2mr[] later. */ + tmpl.cq = ibv_create_cq(priv->ctx, desc, NULL, NULL, 0); if (tmpl.cq == NULL) { - ret = ENOMEM; + rte_errno = ENOMEM; ERROR("%p: CQ creation failure: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } DEBUG("priv->device_attr.max_qp_wr is %d", priv->device_attr.max_qp_wr); DEBUG("priv->device_attr.max_sge is %d", priv->device_attr.max_sge); - attr.init = (struct ibv_exp_qp_init_attr){ + attr.init = (struct ibv_qp_init_attr){ /* CQ to be associated with the send queue. */ .send_cq = tmpl.cq, /* CQ to be associated with the receive queue. */ @@ -1234,85 +1160,57 @@ txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc, .max_inline_data = MLX4_PMD_MAX_INLINE, }, .qp_type = IBV_QPT_RAW_PACKET, - /* Do *NOT* enable this, completions events are managed per - * TX burst. */ + /* + * Do *NOT* enable this, completions events are managed per + * Tx burst. + */ .sq_sig_all = 0, - .pd = priv->pd, - .res_domain = tmpl.rd, - .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD | - IBV_EXP_QP_INIT_ATTR_RES_DOMAIN), }; - tmpl.qp = ibv_exp_create_qp(priv->ctx, &attr.init); + tmpl.qp = ibv_create_qp(priv->pd, &attr.init); if (tmpl.qp == NULL) { - ret = (errno ? errno : EINVAL); + rte_errno = errno ? errno : EINVAL; ERROR("%p: QP creation failure: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } /* ibv_create_qp() updates this value. */ tmpl.max_inline = attr.init.cap.max_inline_data; - attr.mod = (struct ibv_exp_qp_attr){ + attr.mod = (struct ibv_qp_attr){ /* Move the QP to this state. */ .qp_state = IBV_QPS_INIT, /* Primary port number. */ .port_num = priv->port }; - ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, - (IBV_EXP_QP_STATE | IBV_EXP_QP_PORT)); + ret = ibv_modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE | IBV_QP_PORT); if (ret) { + rte_errno = ret; ERROR("%p: QP state to IBV_QPS_INIT failed: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } ret = txq_alloc_elts(&tmpl, desc); if (ret) { + rte_errno = ret; ERROR("%p: TXQ allocation failed: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } - attr.mod = (struct ibv_exp_qp_attr){ + attr.mod = (struct ibv_qp_attr){ .qp_state = IBV_QPS_RTR }; - ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, IBV_EXP_QP_STATE); + ret = ibv_modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE); if (ret) { + rte_errno = ret; ERROR("%p: QP state to IBV_QPS_RTR failed: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } attr.mod.qp_state = IBV_QPS_RTS; - ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, IBV_EXP_QP_STATE); + ret = ibv_modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE); if (ret) { + rte_errno = ret; ERROR("%p: QP state to IBV_QPS_RTS failed: %s", - (void *)dev, strerror(ret)); - goto error; - } - attr.params = (struct ibv_exp_query_intf_params){ - .intf_scope = IBV_EXP_INTF_GLOBAL, - .intf = IBV_EXP_INTF_CQ, - .obj = tmpl.cq, - }; - tmpl.if_cq = ibv_exp_query_intf(priv->ctx, &attr.params, &status); - if (tmpl.if_cq == NULL) { - ERROR("%p: CQ interface family query failed with status %d", - (void *)dev, status); - goto error; - } - attr.params = (struct ibv_exp_query_intf_params){ - .intf_scope = IBV_EXP_INTF_GLOBAL, - .intf = IBV_EXP_INTF_QP_BURST, - .obj = tmpl.qp, -#ifdef HAVE_EXP_QP_BURST_CREATE_DISABLE_ETH_LOOPBACK - /* MC loopback must be disabled when not using a VF. */ - .family_flags = - (!priv->vf ? - IBV_EXP_QP_BURST_CREATE_DISABLE_ETH_LOOPBACK : - 0), -#endif - }; - tmpl.if_qp = ibv_exp_query_intf(priv->ctx, &attr.params, &status); - if (tmpl.if_qp == NULL) { - ERROR("%p: QP interface family query failed with status %d", - (void *)dev, status); + (void *)dev, strerror(rte_errno)); goto error; } /* Clean up txq in case we're reinitializing it. */ @@ -1322,12 +1220,13 @@ txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc, DEBUG("%p: txq updated with %p", (void *)txq, (void *)&tmpl); /* Pre-register known mempools. */ rte_mempool_walk(txq_mp2mr_iter, txq); - assert(ret == 0); return 0; error: + ret = rte_errno; txq_cleanup(&tmpl); - assert(ret > 0); - return ret; + rte_errno = ret; + assert(rte_errno > 0); + return -rte_errno; } /** @@ -1345,7 +1244,7 @@ error: * Thresholds parameters. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, @@ -1355,31 +1254,30 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, struct txq *txq = (*priv->txqs)[idx]; int ret; - priv_lock(priv); DEBUG("%p: configuring queue %u for %u descriptors", (void *)dev, idx, desc); if (idx >= priv->txqs_n) { + rte_errno = EOVERFLOW; ERROR("%p: queue index out of range (%u >= %u)", (void *)dev, idx, priv->txqs_n); - priv_unlock(priv); - return -EOVERFLOW; + return -rte_errno; } if (txq != NULL) { DEBUG("%p: reusing already allocated queue index %u (%p)", (void *)dev, idx, (void *)txq); if (priv->started) { - priv_unlock(priv); - return -EEXIST; + rte_errno = EEXIST; + return -rte_errno; } (*priv->txqs)[idx] = NULL; txq_cleanup(txq); } else { txq = rte_calloc_socket("TXQ", 1, sizeof(*txq), 0, socket); if (txq == NULL) { + rte_errno = ENOMEM; ERROR("%p: unable to allocate queue index %u", (void *)dev, idx); - priv_unlock(priv); - return -ENOMEM; + return -rte_errno; } } ret = txq_setup(dev, txq, desc, socket, conf); @@ -1393,8 +1291,7 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, /* Update send callback. */ dev->tx_pkt_burst = mlx4_tx_burst; } - priv_unlock(priv); - return -ret; + return ret; } /** @@ -1413,7 +1310,6 @@ mlx4_tx_queue_release(void *dpdk_txq) if (txq == NULL) return; priv = txq->priv; - priv_lock(priv); for (i = 0; (i != priv->txqs_n); ++i) if ((*priv->txqs)[i] == txq) { DEBUG("%p: removing TX queue %p from list", @@ -1423,7 +1319,6 @@ mlx4_tx_queue_release(void *dpdk_txq) } txq_cleanup(txq); rte_free(txq); - priv_unlock(priv); } /* RX queues handling. */ @@ -1437,7 +1332,7 @@ mlx4_tx_queue_release(void *dpdk_txq) * Number of elements to allocate. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n) @@ -1446,11 +1341,10 @@ rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n) struct rxq_elt (*elts)[elts_n] = rte_calloc_socket("RXQ elements", 1, sizeof(*elts), 0, rxq->socket); - int ret = 0; if (elts == NULL) { + rte_errno = ENOMEM; ERROR("%p: can't allocate packets array", (void *)rxq); - ret = ENOMEM; goto error; } /* For each WR (packet). */ @@ -1461,22 +1355,16 @@ rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n) struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp); if (buf == NULL) { + rte_errno = ENOMEM; ERROR("%p: empty mbuf pool", (void *)rxq); - ret = ENOMEM; goto error; } - /* Configure WR. Work request ID contains its own index in - * the elts array and the offset between SGE buffer header and - * its data. */ - WR_ID(wr->wr_id).id = i; - WR_ID(wr->wr_id).offset = - (((uintptr_t)buf->buf_addr + RTE_PKTMBUF_HEADROOM) - - (uintptr_t)buf); + elt->buf = buf; wr->next = &(*elts)[(i + 1)].wr; wr->sg_list = sge; wr->num_sge = 1; /* Headroom is reserved by rte_pktmbuf_alloc(). */ - assert(DATA_OFF(buf) == RTE_PKTMBUF_HEADROOM); + assert(buf->data_off == RTE_PKTMBUF_HEADROOM); /* Buffer is supposed to be empty. */ assert(rte_pktmbuf_data_len(buf) == 0); assert(rte_pktmbuf_pkt_len(buf) == 0); @@ -1489,18 +1377,6 @@ rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n) sge->lkey = rxq->mr->lkey; /* Redundant check for tailroom. */ assert(sge->length == rte_pktmbuf_tailroom(buf)); - /* Make sure elts index and SGE mbuf pointer can be deduced - * from WR ID. */ - if ((WR_ID(wr->wr_id).id != i) || - ((void *)((uintptr_t)sge->addr - - WR_ID(wr->wr_id).offset) != buf)) { - ERROR("%p: cannot store index and offset in WR ID", - (void *)rxq); - sge->addr = 0; - rte_pktmbuf_free(buf); - ret = EOVERFLOW; - goto error; - } } /* The last WR pointer must be NULL. */ (*elts)[(i - 1)].wr.next = NULL; @@ -1509,26 +1385,16 @@ rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n) rxq->elts_n = elts_n; rxq->elts_head = 0; rxq->elts = elts; - assert(ret == 0); return 0; error: if (elts != NULL) { - for (i = 0; (i != elemof(*elts)); ++i) { - struct rxq_elt *elt = &(*elts)[i]; - struct rte_mbuf *buf; - - if (elt->sge.addr == 0) - continue; - assert(WR_ID(elt->wr.wr_id).id == i); - buf = (void *)((uintptr_t)elt->sge.addr - - WR_ID(elt->wr.wr_id).offset); - rte_pktmbuf_free_seg(buf); - } + for (i = 0; (i != RTE_DIM(*elts)); ++i) + rte_pktmbuf_free_seg((*elts)[i].buf); rte_free(elts); } DEBUG("%p: failed, freed everything", (void *)rxq); - assert(ret > 0); - return ret; + assert(rte_errno > 0); + return -rte_errno; } /** @@ -1549,17 +1415,8 @@ rxq_free_elts(struct rxq *rxq) rxq->elts = NULL; if (elts == NULL) return; - for (i = 0; (i != elemof(*elts)); ++i) { - struct rxq_elt *elt = &(*elts)[i]; - struct rte_mbuf *buf; - - if (elt->sge.addr == 0) - continue; - assert(WR_ID(elt->wr.wr_id).id == i); - buf = (void *)((uintptr_t)elt->sge.addr - - WR_ID(elt->wr.wr_id).offset); - rte_pktmbuf_free_seg(buf); - } + for (i = 0; (i != RTE_DIM(*elts)); ++i) + rte_pktmbuf_free_seg((*elts)[i].buf); rte_free(elts); } @@ -1594,7 +1451,7 @@ priv_mac_addr_del(struct priv *priv) * Pointer to private structure. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_mac_addr_add(struct priv *priv) @@ -1652,16 +1509,12 @@ priv_mac_addr_add(struct priv *priv) (void *)priv, (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5]); /* Create related flow. */ - errno = 0; flow = ibv_create_flow(rxq->qp, attr); if (flow == NULL) { - /* It's not clear whether errno is always set in this case. */ + rte_errno = errno ? errno : EINVAL; ERROR("%p: flow configuration failed, errno=%d: %s", - (void *)rxq, errno, - (errno ? strerror(errno) : "Unknown error")); - if (errno) - return errno; - return EINVAL; + (void *)rxq, rte_errno, strerror(errno)); + return -rte_errno; } assert(priv->mac_flow == NULL); priv->mac_flow = flow; @@ -1679,49 +1532,14 @@ priv_mac_addr_add(struct priv *priv) static void rxq_cleanup(struct rxq *rxq) { - struct ibv_exp_release_intf_params params; - DEBUG("cleaning up %p", (void *)rxq); rxq_free_elts(rxq); - if (rxq->if_qp != NULL) { - assert(rxq->priv != NULL); - assert(rxq->priv->ctx != NULL); - assert(rxq->qp != NULL); - params = (struct ibv_exp_release_intf_params){ - .comp_mask = 0, - }; - claim_zero(ibv_exp_release_intf(rxq->priv->ctx, - rxq->if_qp, - ¶ms)); - } - if (rxq->if_cq != NULL) { - assert(rxq->priv != NULL); - assert(rxq->priv->ctx != NULL); - assert(rxq->cq != NULL); - params = (struct ibv_exp_release_intf_params){ - .comp_mask = 0, - }; - claim_zero(ibv_exp_release_intf(rxq->priv->ctx, - rxq->if_cq, - ¶ms)); - } if (rxq->qp != NULL) claim_zero(ibv_destroy_qp(rxq->qp)); if (rxq->cq != NULL) claim_zero(ibv_destroy_cq(rxq->cq)); if (rxq->channel != NULL) claim_zero(ibv_destroy_comp_channel(rxq->channel)); - if (rxq->rd != NULL) { - struct ibv_exp_destroy_res_domain_attr attr = { - .comp_mask = 0, - }; - - assert(rxq->priv != NULL); - assert(rxq->priv->ctx != NULL); - claim_zero(ibv_exp_destroy_res_domain(rxq->priv->ctx, - rxq->rd, - &attr)); - } if (rxq->mr != NULL) claim_zero(ibv_dereg_mr(rxq->mr)); memset(rxq, 0, sizeof(*rxq)); @@ -1749,23 +1567,33 @@ mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts; const unsigned int elts_n = rxq->elts_n; unsigned int elts_head = rxq->elts_head; - struct ibv_sge sges[pkts_n]; + struct ibv_wc wcs[pkts_n]; + struct ibv_recv_wr *wr_head = NULL; + struct ibv_recv_wr **wr_next = &wr_head; + struct ibv_recv_wr *wr_bad = NULL; unsigned int i; unsigned int pkts_ret = 0; int ret; - for (i = 0; (i != pkts_n); ++i) { + ret = ibv_poll_cq(rxq->cq, pkts_n, wcs); + if (unlikely(ret == 0)) + return 0; + if (unlikely(ret < 0)) { + DEBUG("rxq=%p, ibv_poll_cq() failed (wc_n=%d)", + (void *)rxq, ret); + return 0; + } + assert(ret <= (int)pkts_n); + /* For each work completion. */ + for (i = 0; i != (unsigned int)ret; ++i) { + struct ibv_wc *wc = &wcs[i]; struct rxq_elt *elt = &(*elts)[elts_head]; struct ibv_recv_wr *wr = &elt->wr; - uint64_t wr_id = wr->wr_id; - unsigned int len; - struct rte_mbuf *seg = (void *)((uintptr_t)elt->sge.addr - - WR_ID(wr_id).offset); + uint32_t len = wc->byte_len; + struct rte_mbuf *seg = elt->buf; struct rte_mbuf *rep; - uint32_t flags; /* Sanity checks. */ - assert(WR_ID(wr_id).id < rxq->elts_n); assert(wr->sg_list == &elt->sge); assert(wr->num_sge == 1); assert(elts_head < rxq->elts_n); @@ -1776,79 +1604,44 @@ mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) */ rte_mbuf_prefetch_part1(seg); rte_mbuf_prefetch_part2(seg); - ret = rxq->if_cq->poll_length_flags(rxq->cq, NULL, NULL, - &flags); - if (unlikely(ret < 0)) { - struct ibv_wc wc; - int wcs_n; - - DEBUG("rxq=%p, poll_length() failed (ret=%d)", - (void *)rxq, ret); - /* ibv_poll_cq() must be used in case of failure. */ - wcs_n = ibv_poll_cq(rxq->cq, 1, &wc); - if (unlikely(wcs_n == 0)) - break; - if (unlikely(wcs_n < 0)) { - DEBUG("rxq=%p, ibv_poll_cq() failed (wcs_n=%d)", - (void *)rxq, wcs_n); - break; - } - assert(wcs_n == 1); - if (unlikely(wc.status != IBV_WC_SUCCESS)) { - /* Whatever, just repost the offending WR. */ - DEBUG("rxq=%p, wr_id=%" PRIu64 ": bad work" - " completion status (%d): %s", - (void *)rxq, wc.wr_id, wc.status, - ibv_wc_status_str(wc.status)); - /* Increment dropped packets counter. */ - ++rxq->stats.idropped; - /* Add SGE to array for repost. */ - sges[i] = elt->sge; - goto repost; - } - ret = wc.byte_len; + /* Link completed WRs together for repost. */ + *wr_next = wr; + wr_next = &wr->next; + if (unlikely(wc->status != IBV_WC_SUCCESS)) { + /* Whatever, just repost the offending WR. */ + DEBUG("rxq=%p: bad work completion status (%d): %s", + (void *)rxq, wc->status, + ibv_wc_status_str(wc->status)); + /* Increment dropped packets counter. */ + ++rxq->stats.idropped; + goto repost; } - if (ret == 0) - break; - len = ret; rep = rte_mbuf_raw_alloc(rxq->mp); if (unlikely(rep == NULL)) { /* * Unable to allocate a replacement mbuf, * repost WR. */ - DEBUG("rxq=%p, wr_id=%" PRIu32 ":" - " can't allocate a new mbuf", - (void *)rxq, WR_ID(wr_id).id); + DEBUG("rxq=%p: can't allocate a new mbuf", + (void *)rxq); /* Increase out of memory counters. */ ++rxq->stats.rx_nombuf; ++rxq->priv->dev->data->rx_mbuf_alloc_failed; - /* Add SGE to array for repost. */ - sges[i] = elt->sge; goto repost; } - /* Reconfigure sge to use rep instead of seg. */ elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM; assert(elt->sge.lkey == rxq->mr->lkey); - WR_ID(wr->wr_id).offset = - (((uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM) - - (uintptr_t)rep); - assert(WR_ID(wr->wr_id).id == WR_ID(wr_id).id); - - /* Add SGE to array for repost. */ - sges[i] = elt->sge; - + elt->buf = rep; /* Update seg information. */ - SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM); - NB_SEGS(seg) = 1; - PORT(seg) = rxq->port_id; - NEXT(seg) = NULL; - PKT_LEN(seg) = len; - DATA_LEN(seg) = len; + seg->data_off = RTE_PKTMBUF_HEADROOM; + seg->nb_segs = 1; + seg->port = rxq->port_id; + seg->next = NULL; + seg->pkt_len = len; + seg->data_len = len; seg->packet_type = 0; seg->ol_flags = 0; - /* Return packet. */ *(pkts++) = seg; ++pkts_ret; @@ -1862,7 +1655,9 @@ repost: if (unlikely(i == 0)) return 0; /* Repost WRs. */ - ret = rxq->if_qp->recv_burst(rxq->qp, sges, i); + *wr_next = NULL; + assert(wr_head); + ret = ibv_post_recv(rxq->qp, wr_head, &wr_bad); if (unlikely(ret)) { /* Inability to repost WRs is fatal. */ DEBUG("%p: recv_burst(): failed (ret=%d)", @@ -1888,13 +1683,13 @@ repost: * Number of descriptors in QP (hint only). * * @return - * QP pointer or NULL in case of error. + * QP pointer or NULL in case of error and rte_errno is set. */ static struct ibv_qp * -rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, uint16_t desc, - struct ibv_exp_res_domain *rd) +rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, uint16_t desc) { - struct ibv_exp_qp_init_attr attr = { + struct ibv_qp *qp; + struct ibv_qp_init_attr attr = { /* CQ to be associated with the send queue. */ .send_cq = cq, /* CQ to be associated with the receive queue. */ @@ -1908,13 +1703,12 @@ rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, uint16_t desc, .max_recv_sge = 1, }, .qp_type = IBV_QPT_RAW_PACKET, - .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD | - IBV_EXP_QP_INIT_ATTR_RES_DOMAIN), - .pd = priv->pd, - .res_domain = rd, }; - return ibv_exp_create_qp(priv->ctx, &attr); + qp = ibv_create_qp(priv->pd, &attr); + if (!qp) + rte_errno = errno ? errno : EINVAL; + return qp; } /** @@ -1934,7 +1728,7 @@ rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, uint16_t desc, * Memory pool for buffer allocations. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int rxq_setup(struct rte_eth_dev *dev, struct rxq *rxq, uint16_t desc, @@ -1947,22 +1741,17 @@ rxq_setup(struct rte_eth_dev *dev, struct rxq *rxq, uint16_t desc, .mp = mp, .socket = socket }; - struct ibv_exp_qp_attr mod; - union { - struct ibv_exp_query_intf_params params; - struct ibv_exp_cq_init_attr cq; - struct ibv_exp_res_domain_init_attr rd; - } attr; - enum ibv_exp_query_intf_status status; + struct ibv_qp_attr mod; struct ibv_recv_wr *bad_wr; unsigned int mb_len; - int ret = 0; + int ret; (void)conf; /* Thresholds configuration (ignored). */ mb_len = rte_pktmbuf_data_room_size(mp); if (desc == 0) { + rte_errno = EINVAL; ERROR("%p: invalid number of Rx descriptors", (void *)dev); - return EINVAL; + goto error; } /* Enable scattered packets support for this queue if necessary. */ assert(mb_len >= RTE_PKTMBUF_HEADROOM); @@ -1984,130 +1773,97 @@ rxq_setup(struct rte_eth_dev *dev, struct rxq *rxq, uint16_t desc, /* Use the entire RX mempool as the memory region. */ tmpl.mr = mlx4_mp2mr(priv->pd, mp); if (tmpl.mr == NULL) { - ret = EINVAL; + rte_errno = EINVAL; ERROR("%p: MR creation failure: %s", - (void *)dev, strerror(ret)); - goto error; - } - attr.rd = (struct ibv_exp_res_domain_init_attr){ - .comp_mask = (IBV_EXP_RES_DOMAIN_THREAD_MODEL | - IBV_EXP_RES_DOMAIN_MSG_MODEL), - .thread_model = IBV_EXP_THREAD_SINGLE, - .msg_model = IBV_EXP_MSG_HIGH_BW, - }; - tmpl.rd = ibv_exp_create_res_domain(priv->ctx, &attr.rd); - if (tmpl.rd == NULL) { - ret = ENOMEM; - ERROR("%p: RD creation failure: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } if (dev->data->dev_conf.intr_conf.rxq) { tmpl.channel = ibv_create_comp_channel(priv->ctx); if (tmpl.channel == NULL) { - ret = ENOMEM; + rte_errno = ENOMEM; ERROR("%p: Rx interrupt completion channel creation" " failure: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); + goto error; + } + if (mlx4_fd_set_non_blocking(tmpl.channel->fd) < 0) { + ERROR("%p: unable to make Rx interrupt completion" + " channel non-blocking: %s", + (void *)dev, strerror(rte_errno)); goto error; } } - attr.cq = (struct ibv_exp_cq_init_attr){ - .comp_mask = IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN, - .res_domain = tmpl.rd, - }; - tmpl.cq = ibv_exp_create_cq(priv->ctx, desc, NULL, tmpl.channel, 0, - &attr.cq); + tmpl.cq = ibv_create_cq(priv->ctx, desc, NULL, tmpl.channel, 0); if (tmpl.cq == NULL) { - ret = ENOMEM; + rte_errno = ENOMEM; ERROR("%p: CQ creation failure: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } DEBUG("priv->device_attr.max_qp_wr is %d", priv->device_attr.max_qp_wr); DEBUG("priv->device_attr.max_sge is %d", priv->device_attr.max_sge); - tmpl.qp = rxq_setup_qp(priv, tmpl.cq, desc, tmpl.rd); + tmpl.qp = rxq_setup_qp(priv, tmpl.cq, desc); if (tmpl.qp == NULL) { - ret = (errno ? errno : EINVAL); ERROR("%p: QP creation failure: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } - mod = (struct ibv_exp_qp_attr){ + mod = (struct ibv_qp_attr){ /* Move the QP to this state. */ .qp_state = IBV_QPS_INIT, /* Primary port number. */ .port_num = priv->port }; - ret = ibv_exp_modify_qp(tmpl.qp, &mod, - IBV_EXP_QP_STATE | - IBV_EXP_QP_PORT); + ret = ibv_modify_qp(tmpl.qp, &mod, IBV_QP_STATE | IBV_QP_PORT); if (ret) { + rte_errno = ret; ERROR("%p: QP state to IBV_QPS_INIT failed: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } ret = rxq_alloc_elts(&tmpl, desc); if (ret) { ERROR("%p: RXQ allocation failed: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } ret = ibv_post_recv(tmpl.qp, &(*tmpl.elts)[0].wr, &bad_wr); if (ret) { + rte_errno = ret; ERROR("%p: ibv_post_recv() failed for WR %p: %s", (void *)dev, (void *)bad_wr, - strerror(ret)); + strerror(rte_errno)); goto error; } - mod = (struct ibv_exp_qp_attr){ + mod = (struct ibv_qp_attr){ .qp_state = IBV_QPS_RTR }; - ret = ibv_exp_modify_qp(tmpl.qp, &mod, IBV_EXP_QP_STATE); + ret = ibv_modify_qp(tmpl.qp, &mod, IBV_QP_STATE); if (ret) { + rte_errno = ret; ERROR("%p: QP state to IBV_QPS_RTR failed: %s", - (void *)dev, strerror(ret)); + (void *)dev, strerror(rte_errno)); goto error; } /* Save port ID. */ tmpl.port_id = dev->data->port_id; DEBUG("%p: RTE port ID: %u", (void *)rxq, tmpl.port_id); - attr.params = (struct ibv_exp_query_intf_params){ - .intf_scope = IBV_EXP_INTF_GLOBAL, - .intf = IBV_EXP_INTF_CQ, - .obj = tmpl.cq, - }; - tmpl.if_cq = ibv_exp_query_intf(priv->ctx, &attr.params, &status); - if (tmpl.if_cq == NULL) { - ERROR("%p: CQ interface family query failed with status %d", - (void *)dev, status); - goto error; - } - attr.params = (struct ibv_exp_query_intf_params){ - .intf_scope = IBV_EXP_INTF_GLOBAL, - .intf = IBV_EXP_INTF_QP_BURST, - .obj = tmpl.qp, - }; - tmpl.if_qp = ibv_exp_query_intf(priv->ctx, &attr.params, &status); - if (tmpl.if_qp == NULL) { - ERROR("%p: QP interface family query failed with status %d", - (void *)dev, status); - goto error; - } /* Clean up rxq in case we're reinitializing it. */ DEBUG("%p: cleaning-up old rxq just in case", (void *)rxq); rxq_cleanup(rxq); *rxq = tmpl; DEBUG("%p: rxq updated with %p", (void *)rxq, (void *)&tmpl); - assert(ret == 0); return 0; error: + ret = rte_errno; rxq_cleanup(&tmpl); - assert(ret > 0); - return ret; + rte_errno = ret; + assert(rte_errno > 0); + return -rte_errno; } /** @@ -2127,7 +1883,7 @@ error: * Memory pool for buffer allocations. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, @@ -2138,21 +1894,20 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, struct rxq *rxq = (*priv->rxqs)[idx]; int ret; - priv_lock(priv); DEBUG("%p: configuring queue %u for %u descriptors", (void *)dev, idx, desc); if (idx >= priv->rxqs_n) { + rte_errno = EOVERFLOW; ERROR("%p: queue index out of range (%u >= %u)", (void *)dev, idx, priv->rxqs_n); - priv_unlock(priv); - return -EOVERFLOW; + return -rte_errno; } if (rxq != NULL) { DEBUG("%p: reusing already allocated queue index %u (%p)", (void *)dev, idx, (void *)rxq); if (priv->started) { - priv_unlock(priv); - return -EEXIST; + rte_errno = EEXIST; + return -rte_errno; } (*priv->rxqs)[idx] = NULL; if (idx == 0) @@ -2161,10 +1916,10 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, } else { rxq = rte_calloc_socket("RXQ", 1, sizeof(*rxq), 0, socket); if (rxq == NULL) { + rte_errno = ENOMEM; ERROR("%p: unable to allocate queue index %u", (void *)dev, idx); - priv_unlock(priv); - return -ENOMEM; + return -rte_errno; } } ret = rxq_setup(dev, rxq, desc, socket, conf, mp); @@ -2178,8 +1933,7 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, /* Update receive callback. */ dev->rx_pkt_burst = mlx4_rx_burst; } - priv_unlock(priv); - return -ret; + return ret; } /** @@ -2198,7 +1952,6 @@ mlx4_rx_queue_release(void *dpdk_rxq) if (rxq == NULL) return; priv = rxq->priv; - priv_lock(priv); for (i = 0; (i != priv->rxqs_n); ++i) if ((*priv->rxqs)[i] == rxq) { DEBUG("%p: removing RX queue %p from list", @@ -2210,18 +1963,8 @@ mlx4_rx_queue_release(void *dpdk_rxq) } rxq_cleanup(rxq); rte_free(rxq); - priv_unlock(priv); } -static int -priv_dev_interrupt_handler_install(struct priv *, struct rte_eth_dev *); - -static int -priv_dev_removal_interrupt_handler_install(struct priv *, struct rte_eth_dev *); - -static int -priv_dev_link_interrupt_handler_install(struct priv *, struct rte_eth_dev *); - /** * DPDK callback to start the device. * @@ -2231,7 +1974,7 @@ priv_dev_link_interrupt_handler_install(struct priv *, struct rte_eth_dev *); * Pointer to Ethernet device structure. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_dev_start(struct rte_eth_dev *dev) @@ -2239,48 +1982,31 @@ mlx4_dev_start(struct rte_eth_dev *dev) struct priv *priv = dev->data->dev_private; int ret; - priv_lock(priv); - if (priv->started) { - priv_unlock(priv); + if (priv->started) return 0; - } DEBUG("%p: attaching configured flows to all RX queues", (void *)dev); priv->started = 1; ret = priv_mac_addr_add(priv); if (ret) goto err; - ret = priv_dev_link_interrupt_handler_install(priv, dev); - if (ret) { - ERROR("%p: LSC handler install failed", - (void *)dev); - goto err; - } - ret = priv_dev_removal_interrupt_handler_install(priv, dev); + ret = mlx4_intr_install(priv); if (ret) { - ERROR("%p: RMV handler install failed", + ERROR("%p: interrupt handler installation failed", (void *)dev); goto err; } - ret = priv_rx_intr_vec_enable(priv); - if (ret) { - ERROR("%p: Rx interrupt vector creation failed", - (void *)dev); - goto err; - } ret = mlx4_priv_flow_start(priv); if (ret) { ERROR("%p: flow start failed: %s", (void *)dev, strerror(ret)); goto err; } - priv_unlock(priv); return 0; err: /* Rollback. */ priv_mac_addr_del(priv); priv->started = 0; - priv_unlock(priv); - return -ret; + return ret; } /** @@ -2296,16 +2022,13 @@ mlx4_dev_stop(struct rte_eth_dev *dev) { struct priv *priv = dev->data->dev_private; - priv_lock(priv); - if (!priv->started) { - priv_unlock(priv); + if (!priv->started) return; - } DEBUG("%p: detaching flows from all RX queues", (void *)dev); priv->started = 0; mlx4_priv_flow_stop(priv); + mlx4_intr_uninstall(priv); priv_mac_addr_del(priv); - priv_unlock(priv); } /** @@ -2358,16 +2081,6 @@ removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) return 0; } -static int -priv_dev_interrupt_handler_uninstall(struct priv *, struct rte_eth_dev *); - -static int -priv_dev_removal_interrupt_handler_uninstall(struct priv *, - struct rte_eth_dev *); - -static int -priv_dev_link_interrupt_handler_uninstall(struct priv *, struct rte_eth_dev *); - /** * DPDK callback to close the device. * @@ -2385,14 +2098,15 @@ mlx4_dev_close(struct rte_eth_dev *dev) if (priv == NULL) return; - priv_lock(priv); DEBUG("%p: closing device \"%s\"", (void *)dev, ((priv->ctx != NULL) ? priv->ctx->device->name : "")); priv_mac_addr_del(priv); - /* Prevent crashes when queues are still in use. This is unfortunately + /* + * Prevent crashes when queues are still in use. This is unfortunately * still required for DPDK 1.3 because some programs (such as testpmd) - * never release them before closing the device. */ + * never release them before closing the device. + */ dev->rx_pkt_burst = removed_rx_burst; dev->tx_pkt_burst = removed_tx_burst; if (priv->rxqs != NULL) { @@ -2429,10 +2143,7 @@ mlx4_dev_close(struct rte_eth_dev *dev) claim_zero(ibv_close_device(priv->ctx)); } else assert(priv->ctx == NULL); - priv_dev_removal_interrupt_handler_uninstall(priv, dev); - priv_dev_link_interrupt_handler_uninstall(priv, dev); - priv_rx_intr_vec_disable(priv); - priv_unlock(priv); + mlx4_intr_uninstall(priv); memset(priv, 0, sizeof(*priv)); } @@ -2445,7 +2156,7 @@ mlx4_dev_close(struct rte_eth_dev *dev) * Nonzero for link up, otherwise link down. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_set_link(struct priv *priv, int up) @@ -2475,18 +2186,14 @@ priv_set_link(struct priv *priv, int up) * Pointer to Ethernet device structure. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_set_link_down(struct rte_eth_dev *dev) { struct priv *priv = dev->data->dev_private; - int err; - priv_lock(priv); - err = priv_set_link(priv, 0); - priv_unlock(priv); - return err; + return priv_set_link(priv, 0); } /** @@ -2496,19 +2203,16 @@ mlx4_set_link_down(struct rte_eth_dev *dev) * Pointer to Ethernet device structure. * * @return - * 0 on success, errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_set_link_up(struct rte_eth_dev *dev) { struct priv *priv = dev->data->dev_private; - int err; - priv_lock(priv); - err = priv_set_link(priv, 1); - priv_unlock(priv); - return err; + return priv_set_link(priv, 1); } + /** * DPDK callback to get information about the device. * @@ -2525,10 +2229,8 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) char ifname[IF_NAMESIZE]; info->pci_dev = RTE_ETH_DEV_TO_PCI(dev); - if (priv == NULL) return; - priv_lock(priv); /* FIXME: we should ask the device for these values. */ info->min_rx_bufsize = 32; info->max_rx_pktlen = 65536; @@ -2555,7 +2257,6 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) ETH_LINK_SPEED_20G | ETH_LINK_SPEED_40G | ETH_LINK_SPEED_56G; - priv_unlock(priv); } /** @@ -2576,7 +2277,6 @@ mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) if (priv == NULL) return; - priv_lock(priv); /* Add software counters. */ for (i = 0; (i != priv->rxqs_n); ++i) { struct rxq *rxq = (*priv->rxqs)[i]; @@ -2611,7 +2311,6 @@ mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) tmp.oerrors += txq->stats.odropped; } *stats = tmp; - priv_unlock(priv); } /** @@ -2629,7 +2328,6 @@ mlx4_stats_reset(struct rte_eth_dev *dev) if (priv == NULL) return; - priv_lock(priv); for (i = 0; (i != priv->rxqs_n); ++i) { if ((*priv->rxqs)[i] == NULL) continue; @@ -2644,7 +2342,6 @@ mlx4_stats_reset(struct rte_eth_dev *dev) (*priv->txqs)[i]->stats = (struct mlx4_txq_stats){ .idx = idx }; } - priv_unlock(priv); } /** @@ -2654,8 +2351,11 @@ mlx4_stats_reset(struct rte_eth_dev *dev) * Pointer to Ethernet device structure. * @param wait_to_complete * Wait for request completion (ignored). + * + * @return + * 0 on success, negative errno value otherwise and rte_errno is set. */ -static int +int mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete) { const struct priv *priv = dev->data->dev_private; @@ -2666,14 +2366,14 @@ mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete) struct rte_eth_link dev_link; int link_speed = 0; - /* priv_lock() is not taken to allow concurrent calls. */ - - if (priv == NULL) - return -EINVAL; + if (priv == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } (void)wait_to_complete; if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) { - WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno)); - return -1; + WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(rte_errno)); + return -rte_errno; } memset(&dev_link, 0, sizeof(dev_link)); dev_link.link_status = ((ifr.ifr_flags & IFF_UP) && @@ -2681,8 +2381,8 @@ mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete) ifr.ifr_data = (void *)&edata; if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) { WARN("ioctl(SIOCETHTOOL, ETHTOOL_GSET) failed: %s", - strerror(errno)); - return -1; + strerror(rte_errno)); + return -rte_errno; } link_speed = ethtool_cmd_speed(&edata); if (link_speed == -1) @@ -2693,46 +2393,8 @@ mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete) ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX); dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED); - if (memcmp(&dev_link, &dev->data->dev_link, sizeof(dev_link))) { - /* Link status changed. */ - dev->data->dev_link = dev_link; - return 0; - } - /* Link status is still the same. */ - return -1; -} - -/** - * DPDK callback to change the MTU. - * - * @param dev - * Pointer to Ethernet device structure. - * @param in_mtu - * New MTU. - * - * @return - * 0 on success, negative errno value on failure. - */ -static int -mlx4_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) -{ - struct priv *priv = dev->data->dev_private; - int ret = 0; - - priv_lock(priv); - /* Set kernel interface MTU first. */ - if (priv_set_mtu(priv, mtu)) { - ret = errno; - WARN("cannot set port %u MTU to %u: %s", priv->port, mtu, - strerror(ret)); - goto out; - } else - DEBUG("adapter port %u MTU set to %u", priv->port, mtu); - priv->mtu = mtu; -out: - priv_unlock(priv); - assert(ret >= 0); - return -ret; + dev->data->dev_link = dev_link; + return 0; } /** @@ -2744,7 +2406,7 @@ out: * Flow control output buffer. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) @@ -2757,15 +2419,13 @@ mlx4_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) int ret; ifr.ifr_data = (void *)ðpause; - priv_lock(priv); if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) { - ret = errno; + ret = rte_errno; WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)" " failed: %s", - strerror(ret)); + strerror(rte_errno)); goto out; } - fc_conf->autoneg = ethpause.autoneg; if (ethpause.rx_pause && ethpause.tx_pause) fc_conf->mode = RTE_FC_FULL; @@ -2776,9 +2436,7 @@ mlx4_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) else fc_conf->mode = RTE_FC_NONE; ret = 0; - out: - priv_unlock(priv); assert(ret >= 0); return -ret; } @@ -2792,7 +2450,7 @@ out: * Flow control parameters. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) @@ -2811,25 +2469,20 @@ mlx4_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) ethpause.rx_pause = 1; else ethpause.rx_pause = 0; - if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) || (fc_conf->mode & RTE_FC_TX_PAUSE)) ethpause.tx_pause = 1; else ethpause.tx_pause = 0; - - priv_lock(priv); if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) { - ret = errno; + ret = rte_errno; WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)" " failed: %s", - strerror(ret)); + strerror(rte_errno)); goto out; } ret = 0; - out: - priv_unlock(priv); assert(ret >= 0); return -ret; } @@ -2856,7 +2509,7 @@ const struct rte_flow_ops mlx4_flow_ops = { * Pointer to operation-specific structure. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_dev_filter_ctrl(struct rte_eth_dev *dev, @@ -2864,12 +2517,10 @@ mlx4_dev_filter_ctrl(struct rte_eth_dev *dev, enum rte_filter_op filter_op, void *arg) { - int ret = EINVAL; - switch (filter_type) { case RTE_ETH_FILTER_GENERIC: if (filter_op != RTE_ETH_FILTER_GET) - return -EINVAL; + break; *(const void **)arg = &mlx4_flow_ops; return 0; default: @@ -2877,7 +2528,8 @@ mlx4_dev_filter_ctrl(struct rte_eth_dev *dev, (void *)dev, filter_type); break; } - return -ret; + rte_errno = ENOTSUP; + return -rte_errno; } static const struct eth_dev_ops mlx4_dev_ops = { @@ -2912,7 +2564,7 @@ static const struct eth_dev_ops mlx4_dev_ops = { * PCI bus address output buffer. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_ibv_device_to_pci_addr(const struct ibv_device *device, @@ -2923,8 +2575,10 @@ mlx4_ibv_device_to_pci_addr(const struct ibv_device *device, MKSTR(path, "%s/device/uevent", device->ibdev_path); file = fopen(path, "rb"); - if (file == NULL) - return -1; + if (file == NULL) { + rte_errno = errno; + return -rte_errno; + } while (fgets(line, sizeof(line), file) == line) { size_t len = strlen(line); int ret; @@ -2962,476 +2616,20 @@ mlx4_ibv_device_to_pci_addr(const struct ibv_device *device, * MAC address output buffer. * * @return - * 0 on success, -1 on failure and errno is set. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int priv_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN]) { struct ifreq request; + int ret = priv_ifreq(priv, SIOCGIFHWADDR, &request); - if (priv_ifreq(priv, SIOCGIFHWADDR, &request)) - return -1; - memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); - return 0; -} - -static void -mlx4_dev_link_status_handler(void *); -static void -mlx4_dev_interrupt_handler(void *); - -/** - * Link/device status handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @param events - * Pointer to event flags holder. - * - * @return - * Number of events - */ -static int -priv_dev_status_handler(struct priv *priv, struct rte_eth_dev *dev, - uint32_t *events) -{ - struct ibv_async_event event; - int port_change = 0; - struct rte_eth_link *link = &dev->data->dev_link; - int ret = 0; - - *events = 0; - /* Read all message and acknowledge them. */ - for (;;) { - if (ibv_get_async_event(priv->ctx, &event)) - break; - if ((event.event_type == IBV_EVENT_PORT_ACTIVE || - event.event_type == IBV_EVENT_PORT_ERR) && - (priv->intr_conf.lsc == 1)) { - port_change = 1; - ret++; - } else if (event.event_type == IBV_EVENT_DEVICE_FATAL && - priv->intr_conf.rmv == 1) { - *events |= (1 << RTE_ETH_EVENT_INTR_RMV); - ret++; - } else - DEBUG("event type %d on port %d not handled", - event.event_type, event.element.port_num); - ibv_ack_async_event(&event); - } - if (!port_change) + if (ret) return ret; - mlx4_link_update(dev, 0); - if (((link->link_speed == 0) && link->link_status) || - ((link->link_speed != 0) && !link->link_status)) { - if (!priv->pending_alarm) { - /* Inconsistent status, check again later. */ - priv->pending_alarm = 1; - rte_eal_alarm_set(MLX4_ALARM_TIMEOUT_US, - mlx4_dev_link_status_handler, - dev); - } - } else { - *events |= (1 << RTE_ETH_EVENT_INTR_LSC); - } - return ret; -} - -/** - * Handle delayed link status event. - * - * @param arg - * Registered argument. - */ -static void -mlx4_dev_link_status_handler(void *arg) -{ - struct rte_eth_dev *dev = arg; - struct priv *priv = dev->data->dev_private; - uint32_t events; - int ret; - - priv_lock(priv); - assert(priv->pending_alarm == 1); - priv->pending_alarm = 0; - ret = priv_dev_status_handler(priv, dev, &events); - priv_unlock(priv); - if (ret > 0 && events & (1 << RTE_ETH_EVENT_INTR_LSC)) - _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL, - NULL); -} - -/** - * Handle interrupts from the NIC. - * - * @param[in] intr_handle - * Interrupt handler. - * @param cb_arg - * Callback argument. - */ -static void -mlx4_dev_interrupt_handler(void *cb_arg) -{ - struct rte_eth_dev *dev = cb_arg; - struct priv *priv = dev->data->dev_private; - int ret; - uint32_t ev; - int i; - - priv_lock(priv); - ret = priv_dev_status_handler(priv, dev, &ev); - priv_unlock(priv); - if (ret > 0) { - for (i = RTE_ETH_EVENT_UNKNOWN; - i < RTE_ETH_EVENT_MAX; - i++) { - if (ev & (1 << i)) { - ev &= ~(1 << i); - _rte_eth_dev_callback_process(dev, i, NULL, - NULL); - ret--; - } - } - if (ret) - WARN("%d event%s not processed", ret, - (ret > 1 ? "s were" : " was")); - } -} - -/** - * Uninstall interrupt handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @return - * 0 on success, negative errno value on failure. - */ -static int -priv_dev_interrupt_handler_uninstall(struct priv *priv, struct rte_eth_dev *dev) -{ - int ret; - - if (priv->intr_conf.lsc || - priv->intr_conf.rmv) - return 0; - ret = rte_intr_callback_unregister(&priv->intr_handle, - mlx4_dev_interrupt_handler, - dev); - if (ret < 0) { - ERROR("rte_intr_callback_unregister failed with %d" - "%s%s%s", ret, - (errno ? " (errno: " : ""), - (errno ? strerror(errno) : ""), - (errno ? ")" : "")); - } - priv->intr_handle.fd = 0; - priv->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; - return ret; -} - -/** - * Install interrupt handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @return - * 0 on success, negative errno value on failure. - */ -static int -priv_dev_interrupt_handler_install(struct priv *priv, - struct rte_eth_dev *dev) -{ - int flags; - int rc; - - /* Check whether the interrupt handler has already been installed - * for either type of interrupt - */ - if (priv->intr_conf.lsc && - priv->intr_conf.rmv && - priv->intr_handle.fd) - return 0; - assert(priv->ctx->async_fd > 0); - flags = fcntl(priv->ctx->async_fd, F_GETFL); - rc = fcntl(priv->ctx->async_fd, F_SETFL, flags | O_NONBLOCK); - if (rc < 0) { - INFO("failed to change file descriptor async event queue"); - dev->data->dev_conf.intr_conf.lsc = 0; - dev->data->dev_conf.intr_conf.rmv = 0; - return -errno; - } else { - priv->intr_handle.fd = priv->ctx->async_fd; - priv->intr_handle.type = RTE_INTR_HANDLE_EXT; - rc = rte_intr_callback_register(&priv->intr_handle, - mlx4_dev_interrupt_handler, - dev); - if (rc) { - ERROR("rte_intr_callback_register failed " - " (errno: %s)", strerror(errno)); - return rc; - } - } - return 0; -} - -/** - * Uninstall interrupt handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @return - * 0 on success, negative value on error. - */ -static int -priv_dev_removal_interrupt_handler_uninstall(struct priv *priv, - struct rte_eth_dev *dev) -{ - if (dev->data->dev_conf.intr_conf.rmv) { - priv->intr_conf.rmv = 0; - return priv_dev_interrupt_handler_uninstall(priv, dev); - } - return 0; -} - -/** - * Uninstall interrupt handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @return - * 0 on success, negative value on error, - */ -static int -priv_dev_link_interrupt_handler_uninstall(struct priv *priv, - struct rte_eth_dev *dev) -{ - int ret = 0; - - if (dev->data->dev_conf.intr_conf.lsc) { - priv->intr_conf.lsc = 0; - ret = priv_dev_interrupt_handler_uninstall(priv, dev); - if (ret) - return ret; - } - if (priv->pending_alarm) - if (rte_eal_alarm_cancel(mlx4_dev_link_status_handler, - dev)) { - ERROR("rte_eal_alarm_cancel failed " - " (errno: %s)", strerror(rte_errno)); - return -rte_errno; - } - priv->pending_alarm = 0; - return 0; -} - -/** - * Install link interrupt handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @return - * 0 on success, negative value on error. - */ -static int -priv_dev_link_interrupt_handler_install(struct priv *priv, - struct rte_eth_dev *dev) -{ - int ret; - - if (dev->data->dev_conf.intr_conf.lsc) { - ret = priv_dev_interrupt_handler_install(priv, dev); - if (ret) - return ret; - priv->intr_conf.lsc = 1; - } - return 0; -} - -/** - * Install removal interrupt handler. - * - * @param priv - * Pointer to private structure. - * @param dev - * Pointer to the rte_eth_dev structure. - * @return - * 0 on success, negative value on error. - */ -static int -priv_dev_removal_interrupt_handler_install(struct priv *priv, - struct rte_eth_dev *dev) -{ - int ret; - - if (dev->data->dev_conf.intr_conf.rmv) { - ret = priv_dev_interrupt_handler_install(priv, dev); - if (ret) - return ret; - priv->intr_conf.rmv = 1; - } - return 0; -} - -/** - * Allocate queue vector and fill epoll fd list for Rx interrupts. - * - * @param priv - * Pointer to private structure. - * - * @return - * 0 on success, negative on failure. - */ -static int -priv_rx_intr_vec_enable(struct priv *priv) -{ - unsigned int i; - unsigned int rxqs_n = priv->rxqs_n; - unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID); - unsigned int count = 0; - struct rte_intr_handle *intr_handle = priv->dev->intr_handle; - - if (!priv->dev->data->dev_conf.intr_conf.rxq) - return 0; - priv_rx_intr_vec_disable(priv); - intr_handle->intr_vec = malloc(sizeof(intr_handle->intr_vec[rxqs_n])); - if (intr_handle->intr_vec == NULL) { - ERROR("failed to allocate memory for interrupt vector," - " Rx interrupts will not be supported"); - return -ENOMEM; - } - intr_handle->type = RTE_INTR_HANDLE_EXT; - for (i = 0; i != n; ++i) { - struct rxq *rxq = (*priv->rxqs)[i]; - int fd; - int flags; - int rc; - - /* Skip queues that cannot request interrupts. */ - if (!rxq || !rxq->channel) { - /* Use invalid intr_vec[] index to disable entry. */ - intr_handle->intr_vec[i] = - RTE_INTR_VEC_RXTX_OFFSET + - RTE_MAX_RXTX_INTR_VEC_ID; - continue; - } - if (count >= RTE_MAX_RXTX_INTR_VEC_ID) { - ERROR("too many Rx queues for interrupt vector size" - " (%d), Rx interrupts cannot be enabled", - RTE_MAX_RXTX_INTR_VEC_ID); - priv_rx_intr_vec_disable(priv); - return -1; - } - fd = rxq->channel->fd; - flags = fcntl(fd, F_GETFL); - rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK); - if (rc < 0) { - ERROR("failed to make Rx interrupt file descriptor" - " %d non-blocking for queue index %d", fd, i); - priv_rx_intr_vec_disable(priv); - return rc; - } - intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + count; - intr_handle->efds[count] = fd; - count++; - } - if (!count) - priv_rx_intr_vec_disable(priv); - else - intr_handle->nb_efd = count; + memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); return 0; } -/** - * Clean up Rx interrupts handler. - * - * @param priv - * Pointer to private structure. - */ -static void -priv_rx_intr_vec_disable(struct priv *priv) -{ - struct rte_intr_handle *intr_handle = priv->dev->intr_handle; - - rte_intr_free_epoll_fd(intr_handle); - free(intr_handle->intr_vec); - intr_handle->nb_efd = 0; - intr_handle->intr_vec = NULL; -} - -/** - * DPDK callback for Rx queue interrupt enable. - * - * @param dev - * Pointer to Ethernet device structure. - * @param idx - * Rx queue index. - * - * @return - * 0 on success, negative on failure. - */ -static int -mlx4_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx) -{ - struct priv *priv = dev->data->dev_private; - struct rxq *rxq = (*priv->rxqs)[idx]; - int ret; - - if (!rxq || !rxq->channel) - ret = EINVAL; - else - ret = ibv_req_notify_cq(rxq->cq, 0); - if (ret) - WARN("unable to arm interrupt on rx queue %d", idx); - return -ret; -} - -/** - * DPDK callback for Rx queue interrupt disable. - * - * @param dev - * Pointer to Ethernet device structure. - * @param idx - * Rx queue index. - * - * @return - * 0 on success, negative on failure. - */ -static int -mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx) -{ - struct priv *priv = dev->data->dev_private; - struct rxq *rxq = (*priv->rxqs)[idx]; - struct ibv_cq *ev_cq; - void *ev_ctx; - int ret; - - if (!rxq || !rxq->channel) { - ret = EINVAL; - } else { - ret = ibv_get_cq_event(rxq->cq->channel, &ev_cq, &ev_ctx); - if (ret || ev_cq != rxq->cq) - ret = EINVAL; - } - if (ret) - WARN("unable to disable interrupt on rx queue %d", - idx); - else - ibv_ack_cq_events(rxq->cq, 1); - return -ret; -} - /** * Verify and store value for device argument. * @@ -3443,7 +2641,7 @@ mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx) * Shared configuration data. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf) @@ -3453,8 +2651,9 @@ mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf) errno = 0; tmp = strtoul(val, NULL, 0); if (errno) { + rte_errno = errno; WARN("%s: \"%s\" is not a valid integer", key, val); - return -errno; + return -rte_errno; } if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) { uint32_t ports = rte_log2_u32(conf->ports.present); @@ -3465,13 +2664,15 @@ mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf) return -EINVAL; } if (!(conf->ports.present & (1 << tmp))) { + rte_errno = EINVAL; ERROR("invalid port index %lu", tmp); - return -EINVAL; + return -rte_errno; } conf->ports.enabled |= 1 << tmp; } else { + rte_errno = EINVAL; WARN("%s: unknown parameter", key); - return -EINVAL; + return -rte_errno; } return 0; } @@ -3483,7 +2684,7 @@ mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf) * Device arguments structure. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_args(struct rte_devargs *devargs, struct mlx4_conf *conf) @@ -3497,8 +2698,9 @@ mlx4_args(struct rte_devargs *devargs, struct mlx4_conf *conf) return 0; kvlist = rte_kvargs_parse(devargs->args, pmd_mlx4_init_params); if (kvlist == NULL) { + rte_errno = EINVAL; ERROR("failed to parse kvargs"); - return -EINVAL; + return -rte_errno; } /* Process parameters. */ for (i = 0; pmd_mlx4_init_params[i]; ++i) { @@ -3534,7 +2736,7 @@ static struct rte_pci_driver mlx4_driver; * PCI device information. * * @return - * 0 on success, negative errno value on failure. + * 0 on success, negative errno value otherwise and rte_errno is set. */ static int mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) @@ -3552,13 +2754,13 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) (void)pci_drv; assert(pci_drv == &mlx4_driver); - list = ibv_get_device_list(&i); if (list == NULL) { - assert(errno); - if (errno == ENOSYS) + rte_errno = errno; + assert(rte_errno); + if (rte_errno == ENOSYS) ERROR("cannot list devices, is ib_uverbs loaded?"); - return -errno; + return -rte_errno; } assert(i >= 0); /* @@ -3589,28 +2791,29 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) ibv_free_device_list(list); switch (err) { case 0: + rte_errno = ENODEV; ERROR("cannot access device, is mlx4_ib loaded?"); - return -ENODEV; + return -rte_errno; case EINVAL: + rte_errno = EINVAL; ERROR("cannot use device, are drivers up to date?"); - return -EINVAL; + return -rte_errno; } assert(err > 0); - return -err; + rte_errno = err; + return -rte_errno; } ibv_dev = list[i]; - DEBUG("device opened"); if (ibv_query_device(attr_ctx, &device_attr)) { - err = ENODEV; + rte_errno = ENODEV; goto error; } INFO("%u port(s) detected", device_attr.phys_port_cnt); - conf.ports.present |= (UINT64_C(1) << device_attr.phys_port_cnt) - 1; if (mlx4_args(pci_dev->device.devargs, &conf)) { ERROR("failed to process device arguments"); - err = EINVAL; + rte_errno = EINVAL; goto error; } /* Use all ports when none are defined */ @@ -3628,65 +2831,61 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) /* If port is not enabled, skip. */ if (!(conf.ports.enabled & (1 << i))) continue; - DEBUG("using port %u", port); - ctx = ibv_open_device(ibv_dev); if (ctx == NULL) { - err = ENODEV; + rte_errno = ENODEV; goto port_error; } - /* Check port status. */ err = ibv_query_port(ctx, port, &port_attr); if (err) { - ERROR("port query failed: %s", strerror(err)); - err = ENODEV; + rte_errno = err; + ERROR("port query failed: %s", strerror(rte_errno)); goto port_error; } - if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) { + rte_errno = ENOTSUP; ERROR("port %d is not configured in Ethernet mode", port); - err = EINVAL; goto port_error; } - if (port_attr.state != IBV_PORT_ACTIVE) DEBUG("port %d is not active: \"%s\" (%d)", port, ibv_port_state_str(port_attr.state), port_attr.state); - + /* Make asynchronous FD non-blocking to handle interrupts. */ + if (mlx4_fd_set_non_blocking(ctx->async_fd) < 0) { + ERROR("cannot make asynchronous FD non-blocking: %s", + strerror(rte_errno)); + goto port_error; + } /* Allocate protection domain. */ pd = ibv_alloc_pd(ctx); if (pd == NULL) { + rte_errno = ENOMEM; ERROR("PD allocation failure"); - err = ENOMEM; goto port_error; } - /* from rte_ethdev.c */ priv = rte_zmalloc("ethdev private structure", sizeof(*priv), RTE_CACHE_LINE_SIZE); if (priv == NULL) { + rte_errno = ENOMEM; ERROR("priv allocation failure"); - err = ENOMEM; goto port_error; } - priv->ctx = ctx; priv->device_attr = device_attr; priv->port = port; priv->pd = pd; priv->mtu = ETHER_MTU; - priv->vf = vf; /* Configure the first MAC address by default. */ if (priv_get_mac(priv, &mac.addr_bytes)) { ERROR("cannot get MAC address, is mlx4_en loaded?" - " (errno: %s)", strerror(errno)); - err = ENODEV; + " (rte_errno: %s)", strerror(rte_errno)); goto port_error; } INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x", @@ -3712,7 +2911,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) /* Get actual MTU if possible. */ priv_get_mtu(priv, &priv->mtu); DEBUG("port %u MTU is %u", priv->port, priv->mtu); - /* from rte_ethdev.c */ { char name[RTE_ETH_NAME_MAX_LEN]; @@ -3723,31 +2921,35 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) } if (eth_dev == NULL) { ERROR("can not allocate rte ethdev"); - err = ENOMEM; + rte_errno = ENOMEM; goto port_error; } - eth_dev->data->dev_private = priv; eth_dev->data->mac_addrs = &priv->mac; eth_dev->device = &pci_dev->device; - rte_eth_copy_pci_info(eth_dev, pci_dev); - eth_dev->device->driver = &mlx4_driver.driver; - + /* Initialize local interrupt handle for current port. */ + priv->intr_handle = (struct rte_intr_handle){ + .fd = -1, + .type = RTE_INTR_HANDLE_EXT, + }; /* - * Copy and override interrupt handle to prevent it from - * being shared between all ethdev instances of a given PCI - * device. This is required to properly handle Rx interrupts - * on all ports. + * Override ethdev interrupt handle pointer with private + * handle instead of that of the parent PCI device used by + * default. This prevents it from being shared between all + * ports of the same PCI device since each of them is + * associated its own Verbs context. + * + * Rx interrupts in particular require this as the PMD has + * no control over the registration of queue interrupts + * besides setting up eth_dev->intr_handle, the rest is + * handled by rte_intr_rx_ctl(). */ - priv->intr_handle_dev = *eth_dev->intr_handle; - eth_dev->intr_handle = &priv->intr_handle_dev; - + eth_dev->intr_handle = &priv->intr_handle; priv->dev = eth_dev; eth_dev->dev_ops = &mlx4_dev_ops; eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE; - /* Bring Ethernet device up. */ DEBUG("forcing Ethernet interface up"); priv_set_flags(priv, ~IFF_UP, IFF_UP); @@ -3755,7 +2957,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) mlx4_link_update(eth_dev, 0); continue; - port_error: rte_free(priv); if (pd) @@ -3768,21 +2969,19 @@ port_error: } if (i == device_attr.phys_port_cnt) return 0; - /* * XXX if something went wrong in the loop above, there is a resource * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as * long as the dpdk does not provide a way to deallocate a ethdev and a * way to enumerate the registered ethdevs to free the previous ones. */ - error: if (attr_ctx) claim_zero(ibv_close_device(attr_ctx)); if (list) ibv_free_device_list(list); - assert(err >= 0); - return -err; + assert(rte_errno >= 0); + return -rte_errno; } static const struct rte_pci_id mlx4_pci_id_map[] = { @@ -3820,7 +3019,6 @@ RTE_INIT(rte_mlx4_pmd_init); static void rte_mlx4_pmd_init(void) { - RTE_BUILD_BUG_ON(sizeof(wr_id_t) != sizeof(uint64_t)); /* * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use * huge pages. Calling ibv_fork_init() during init allows