From: Alexander Kozyrev Date: Thu, 30 Jan 2020 16:14:38 +0000 (+0200) Subject: net/mlx4: improve assert control X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=8e08df22f0ab07c44efcdd2ee5d867d30af77028;p=dpdk.git net/mlx4: improve assert control Use the MLX4_ASSERT macros instead of the standard assert clause. Depends on the RTE_LIBRTE_MLX4_DEBUG configuration option to define it. If RTE_LIBRTE_MLX4_DEBUG is enabled MLX4_ASSERT is equal to RTE_VERIFY to bypass the global CONFIG_RTE_ENABLE_ASSERT option. If RTE_LIBRTE_MLX4_DEBUG is disabled, the global CONFIG_RTE_ENABLE_ASSERT can still make this assert active by calling RTE_VERIFY inside RTE_ASSERT. Signed-off-by: Alexander Kozyrev Acked-by: Viacheslav Ovsiienko --- diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 122d37c7f9..5522eb595c 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -8,7 +8,6 @@ * mlx4 driver initialization. */ -#include #include #include #include @@ -162,7 +161,7 @@ mlx4_alloc_verbs_buf(size_t size, void *data) socket = rxq->socket; } - assert(data != NULL); + MLX4_ASSERT(data != NULL); ret = rte_malloc_socket(__func__, size, alignment, socket); if (!ret && size) rte_errno = ENOMEM; @@ -180,7 +179,7 @@ mlx4_alloc_verbs_buf(size_t size, void *data) static void mlx4_free_verbs_buf(void *ptr, void *data __rte_unused) { - assert(data != NULL); + MLX4_ASSERT(data != NULL); rte_free(ptr); } #endif @@ -392,11 +391,11 @@ mlx4_dev_close(struct rte_eth_dev *dev) mlx4_proc_priv_uninit(dev); mlx4_mr_release(dev); if (priv->pd != NULL) { - assert(priv->ctx != NULL); + MLX4_ASSERT(priv->ctx != NULL); claim_zero(mlx4_glue->dealloc_pd(priv->pd)); claim_zero(mlx4_glue->close_device(priv->ctx)); } else - assert(priv->ctx == NULL); + MLX4_ASSERT(priv->ctx == NULL); mlx4_intr_uninstall(priv); memset(priv, 0, sizeof(*priv)); } @@ -705,7 +704,7 @@ mlx4_init_once(void) if (mlx4_init_shared_data()) return -rte_errno; sd = mlx4_shared_data; - assert(sd); + MLX4_ASSERT(sd); rte_spinlock_lock(&sd->lock); switch (rte_eal_process_type()) { case RTE_PROC_PRIMARY: @@ -775,16 +774,16 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) strerror(rte_errno)); return -rte_errno; } - assert(pci_drv == &mlx4_driver); + MLX4_ASSERT(pci_drv == &mlx4_driver); list = mlx4_glue->get_device_list(&i); if (list == NULL) { rte_errno = errno; - assert(rte_errno); + MLX4_ASSERT(rte_errno); if (rte_errno == ENOSYS) ERROR("cannot list devices, is ib_uverbs loaded?"); return -rte_errno; } - assert(i >= 0); + MLX4_ASSERT(i >= 0); /* * For each listed device, check related sysfs entry against * the provided PCI ID. @@ -821,7 +820,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) ERROR("cannot use device, are drivers up to date?"); return -rte_errno; } - assert(err > 0); + MLX4_ASSERT(err > 0); rte_errno = err; return -rte_errno; } @@ -846,7 +845,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) err = ENODEV; goto error; } - assert(device_attr.max_sge >= MLX4_MAX_SGE); + MLX4_ASSERT(device_attr.max_sge >= MLX4_MAX_SGE); for (i = 0; i < device_attr.phys_port_cnt; i++) { uint32_t port = i + 1; /* ports are indexed from one */ struct ibv_context *ctx = NULL; @@ -1303,7 +1302,7 @@ RTE_INIT(rte_mlx4_pmd_init) #ifdef RTE_IBVERBS_LINK_DLOPEN if (mlx4_glue_init()) return; - assert(mlx4_glue); + MLX4_ASSERT(mlx4_glue); #endif #ifdef RTE_LIBRTE_MLX4_DEBUG /* Glue structure must not contain any NULL pointers. */ @@ -1311,7 +1310,7 @@ RTE_INIT(rte_mlx4_pmd_init) unsigned int i; for (i = 0; i != sizeof(*mlx4_glue) / sizeof(void *); ++i) - assert(((const void *const *)mlx4_glue)[i]); + MLX4_ASSERT(((const void *const *)mlx4_glue)[i]); } #endif if (strcmp(mlx4_glue->version, MLX4_GLUE_VERSION)) { diff --git a/drivers/net/mlx4/mlx4_ethdev.c b/drivers/net/mlx4/mlx4_ethdev.c index dfb24c22d0..e500ec422c 100644 --- a/drivers/net/mlx4/mlx4_ethdev.c +++ b/drivers/net/mlx4/mlx4_ethdev.c @@ -8,7 +8,6 @@ * Miscellaneous control operations for mlx4 driver. */ -#include #include #include #include @@ -874,7 +873,7 @@ mlx4_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) fc_conf->mode = RTE_FC_NONE; ret = 0; out: - assert(ret >= 0); + MLX4_ASSERT(ret >= 0); return -ret; } @@ -920,7 +919,7 @@ mlx4_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) } ret = 0; out: - assert(ret >= 0); + MLX4_ASSERT(ret >= 0); return -ret; } diff --git a/drivers/net/mlx4/mlx4_flow.c b/drivers/net/mlx4/mlx4_flow.c index 96479b83dd..793f0b090e 100644 --- a/drivers/net/mlx4/mlx4_flow.c +++ b/drivers/net/mlx4/mlx4_flow.c @@ -9,7 +9,6 @@ */ #include -#include #include #include #include @@ -547,7 +546,7 @@ mlx4_flow_item_check(const struct rte_flow_item *item, mask = item->mask ? (const uint8_t *)item->mask : (const uint8_t *)proc->mask_default; - assert(mask); + MLX4_ASSERT(mask); /* * Single-pass check to make sure that: * - Mask is supported, no bits are set outside proc->mask_support. @@ -954,8 +953,8 @@ mlx4_drop_get(struct mlx4_priv *priv) struct mlx4_drop *drop = priv->drop; if (drop) { - assert(drop->refcnt); - assert(drop->priv == priv); + MLX4_ASSERT(drop->refcnt); + MLX4_ASSERT(drop->priv == priv); ++drop->refcnt; return drop; } @@ -1000,7 +999,7 @@ error: static void mlx4_drop_put(struct mlx4_drop *drop) { - assert(drop->refcnt); + MLX4_ASSERT(drop->refcnt); if (--drop->refcnt) return; drop->priv->drop = NULL; @@ -1045,7 +1044,7 @@ mlx4_flow_toggle(struct mlx4_priv *priv, mlx4_rss_detach(flow->rss); return 0; } - assert(flow->ibv_attr); + MLX4_ASSERT(flow->ibv_attr); if (!flow->internal && !priv->isolated && flow->ibv_attr->priority == MLX4_FLOW_PRIORITY_LAST) { @@ -1111,7 +1110,7 @@ mlx4_flow_toggle(struct mlx4_priv *priv, } qp = priv->drop->qp; } - assert(qp); + MLX4_ASSERT(qp); if (flow->ibv_flow) return 0; flow->ibv_flow = mlx4_glue->create_flow(qp, flow->ibv_attr); @@ -1411,10 +1410,11 @@ next_vlan: if (!flow->mac) continue; - assert(flow->ibv_attr->type == IBV_FLOW_ATTR_NORMAL); - assert(flow->ibv_attr->num_of_specs == 1); - assert(eth->type == IBV_FLOW_SPEC_ETH); - assert(flow->rss); + MLX4_ASSERT(flow->ibv_attr->type == + IBV_FLOW_ATTR_NORMAL); + MLX4_ASSERT(flow->ibv_attr->num_of_specs == 1); + MLX4_ASSERT(eth->type == IBV_FLOW_SPEC_ETH); + MLX4_ASSERT(flow->rss); if (rule_vlan && (eth->val.vlan_tag != *rule_vlan || eth->mask.vlan_tag != RTE_BE16(0x0fff))) @@ -1463,13 +1463,13 @@ next_vlan: if (flow->promisc) break; } else { - assert(ETH_DEV(priv)->data->all_multicast); + MLX4_ASSERT(ETH_DEV(priv)->data->all_multicast); if (flow->allmulti) break; } } if (flow && flow->internal) { - assert(flow->rss); + MLX4_ASSERT(flow->rss); if (flow->rss->queues != queues || memcmp(flow->rss->queue_id, action_rss.queue, queues * sizeof(flow->rss->queue_id[0]))) @@ -1481,7 +1481,7 @@ next_vlan: pattern[1].spec = NULL; pattern[1].mask = NULL; } else { - assert(ETH_DEV(priv)->data->all_multicast); + MLX4_ASSERT(ETH_DEV(priv)->data->all_multicast); pattern[1].spec = ð_allmulti; pattern[1].mask = ð_allmulti; } @@ -1493,7 +1493,7 @@ next_vlan: goto error; } } - assert(flow->promisc || flow->allmulti); + MLX4_ASSERT(flow->promisc || flow->allmulti); flow->select = 1; } error: @@ -1557,7 +1557,7 @@ mlx4_flow_sync(struct mlx4_priv *priv, struct rte_flow_error *error) return ret; } if (!priv->started) - assert(!priv->drop); + MLX4_ASSERT(!priv->drop); return 0; } @@ -1577,7 +1577,7 @@ mlx4_flow_clean(struct mlx4_priv *priv) while ((flow = LIST_FIRST(&priv->flows))) mlx4_flow_destroy(ETH_DEV(priv), flow, NULL); - assert(LIST_EMPTY(&priv->rss)); + MLX4_ASSERT(LIST_EMPTY(&priv->rss)); } static const struct rte_flow_ops mlx4_flow_ops = { diff --git a/drivers/net/mlx4/mlx4_intr.c b/drivers/net/mlx4/mlx4_intr.c index 4f33526755..020fc254aa 100644 --- a/drivers/net/mlx4/mlx4_intr.c +++ b/drivers/net/mlx4/mlx4_intr.c @@ -8,7 +8,6 @@ * Interrupts handling for mlx4 driver. */ -#include #include #include #include @@ -122,7 +121,7 @@ mlx4_link_status_alarm(struct mlx4_priv *priv) const struct rte_intr_conf *const intr_conf = Ð_DEV(priv)->data->dev_conf.intr_conf; - assert(priv->intr_alarm == 1); + MLX4_ASSERT(priv->intr_alarm == 1); priv->intr_alarm = 0; if (intr_conf->lsc && !mlx4_link_status_check(priv)) _rte_eth_dev_callback_process(ETH_DEV(priv), diff --git a/drivers/net/mlx4/mlx4_mp.c b/drivers/net/mlx4/mlx4_mp.c index cdb648517a..eca0c20a8a 100644 --- a/drivers/net/mlx4/mlx4_mp.c +++ b/drivers/net/mlx4/mlx4_mp.c @@ -3,7 +3,6 @@ * Copyright 2019 Mellanox Technologies, Ltd */ -#include #include #include @@ -62,7 +61,7 @@ mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer) uint32_t lkey; int ret; - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); if (!rte_eth_dev_is_valid_port(param->port_id)) { rte_errno = ENODEV; ERROR("port %u invalid port ID", param->port_id); @@ -114,7 +113,7 @@ mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer) struct rte_eth_dev *dev; int ret; - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); if (!rte_eth_dev_is_valid_port(param->port_id)) { rte_errno = ENODEV; ERROR("port %u invalid port ID", param->port_id); @@ -167,7 +166,7 @@ mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx4_mp_req_type type) int ret; int i; - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); if (!mlx4_shared_data->secondary_cnt) return; if (type != MLX4_MP_REQ_START_RXTX && type != MLX4_MP_REQ_STOP_RXTX) { @@ -249,7 +248,7 @@ mlx4_mp_req_mr_create(struct rte_eth_dev *dev, uintptr_t addr) struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0}; int ret; - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); mp_init_msg(dev, &mp_req, MLX4_MP_REQ_CREATE_MR); req->args.addr = addr; ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts); @@ -258,7 +257,7 @@ mlx4_mp_req_mr_create(struct rte_eth_dev *dev, uintptr_t addr) dev->data->port_id); return -rte_errno; } - assert(mp_rep.nb_received == 1); + MLX4_ASSERT(mp_rep.nb_received == 1); mp_res = &mp_rep.msgs[0]; res = (struct mlx4_mp_param *)mp_res->param; ret = res->result; @@ -287,7 +286,7 @@ mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev) struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0}; int ret; - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); mp_init_msg(dev, &mp_req, MLX4_MP_REQ_VERBS_CMD_FD); ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts); if (ret) { @@ -295,7 +294,7 @@ mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev) dev->data->port_id); return -rte_errno; } - assert(mp_rep.nb_received == 1); + MLX4_ASSERT(mp_rep.nb_received == 1); mp_res = &mp_rep.msgs[0]; res = (struct mlx4_mp_param *)mp_res->param; if (res->result) { @@ -305,7 +304,7 @@ mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev) ret = -rte_errno; goto exit; } - assert(mp_res->num_fds == 1); + MLX4_ASSERT(mp_res->num_fds == 1); ret = mp_res->fds[0]; DEBUG("port %u command FD from primary is %d", dev->data->port_id, ret); @@ -322,7 +321,7 @@ mlx4_mp_init_primary(void) { int ret; - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); /* primary is allowed to not support IPC */ ret = rte_mp_action_register(MLX4_MP_NAME, mp_primary_handle); @@ -337,7 +336,7 @@ mlx4_mp_init_primary(void) void mlx4_mp_uninit_primary(void) { - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); rte_mp_action_unregister(MLX4_MP_NAME); } @@ -347,7 +346,7 @@ mlx4_mp_uninit_primary(void) int mlx4_mp_init_secondary(void) { - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); return rte_mp_action_register(MLX4_MP_NAME, mp_secondary_handle); } @@ -357,6 +356,6 @@ mlx4_mp_init_secondary(void) void mlx4_mp_uninit_secondary(void) { - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); rte_mp_action_unregister(MLX4_MP_NAME); } diff --git a/drivers/net/mlx4/mlx4_mr.c b/drivers/net/mlx4/mlx4_mr.c index 4b2e8fe6c9..6b2f0cf187 100644 --- a/drivers/net/mlx4/mlx4_mr.c +++ b/drivers/net/mlx4/mlx4_mr.c @@ -8,7 +8,6 @@ * Memory management functions for mlx4 driver. */ -#include #include #include #include @@ -113,12 +112,12 @@ mr_btree_lookup(struct mlx4_mr_btree *bt, uint16_t *idx, uintptr_t addr) uint16_t n; uint16_t base = 0; - assert(bt != NULL); + MLX4_ASSERT(bt != NULL); lkp_tbl = *bt->table; n = bt->len; /* First entry must be NULL for comparison. */ - assert(bt->len > 0 || (lkp_tbl[0].start == 0 && - lkp_tbl[0].lkey == UINT32_MAX)); + MLX4_ASSERT(bt->len > 0 || (lkp_tbl[0].start == 0 && + lkp_tbl[0].lkey == UINT32_MAX)); /* Binary search. */ do { register uint16_t delta = n >> 1; @@ -130,7 +129,7 @@ mr_btree_lookup(struct mlx4_mr_btree *bt, uint16_t *idx, uintptr_t addr) n -= delta; } } while (n > 1); - assert(addr >= lkp_tbl[base].start); + MLX4_ASSERT(addr >= lkp_tbl[base].start); *idx = base; if (addr < lkp_tbl[base].end) return lkp_tbl[base].lkey; @@ -156,9 +155,9 @@ mr_btree_insert(struct mlx4_mr_btree *bt, struct mlx4_mr_cache *entry) uint16_t idx = 0; size_t shift; - assert(bt != NULL); - assert(bt->len <= bt->size); - assert(bt->len > 0); + MLX4_ASSERT(bt != NULL); + MLX4_ASSERT(bt->len <= bt->size); + MLX4_ASSERT(bt->len > 0); lkp_tbl = *bt->table; /* Find out the slot for insertion. */ if (mr_btree_lookup(bt, &idx, entry->start) != UINT32_MAX) { @@ -294,9 +293,9 @@ mr_find_next_chunk(struct mlx4_mr *mr, struct mlx4_mr_cache *entry, if (mr->msl == NULL) { struct ibv_mr *ibv_mr = mr->ibv_mr; - assert(mr->ms_bmp_n == 1); - assert(mr->ms_n == 1); - assert(base_idx == 0); + MLX4_ASSERT(mr->ms_bmp_n == 1); + MLX4_ASSERT(mr->ms_n == 1); + MLX4_ASSERT(base_idx == 0); /* * Can't search it from memseg list but get it directly from * verbs MR as there's only one chunk. @@ -315,7 +314,7 @@ mr_find_next_chunk(struct mlx4_mr *mr, struct mlx4_mr_cache *entry, msl = mr->msl; ms = rte_fbarray_get(&msl->memseg_arr, mr->ms_base_idx + idx); - assert(msl->page_sz == ms->hugepage_sz); + MLX4_ASSERT(msl->page_sz == ms->hugepage_sz); if (!start) start = ms->addr_64; end = ms->addr_64 + ms->hugepage_sz; @@ -452,8 +451,8 @@ mr_lookup_dev(struct rte_eth_dev *dev, struct mlx4_mr_cache *entry, if (mr != NULL) lkey = entry->lkey; } - assert(lkey == UINT32_MAX || (addr >= entry->start && - addr < entry->end)); + MLX4_ASSERT(lkey == UINT32_MAX || (addr >= entry->start && + addr < entry->end)); return lkey; } @@ -491,7 +490,7 @@ mlx4_mr_garbage_collect(struct rte_eth_dev *dev) struct mlx4_mr_list free_list = LIST_HEAD_INITIALIZER(free_list); /* Must be called from the primary process. */ - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); /* * MR can't be freed with holding the lock because rte_free() could call * memory free callback function. This will be a deadlock situation. @@ -564,7 +563,7 @@ mlx4_mr_create_secondary(struct rte_eth_dev *dev, struct mlx4_mr_cache *entry, /* Fill in output data. */ mr_lookup_dev(dev, entry, addr); /* Lookup can't fail. */ - assert(entry->lkey != UINT32_MAX); + MLX4_ASSERT(entry->lkey != UINT32_MAX); rte_rwlock_read_unlock(&priv->mr.rwlock); DEBUG("port %u MR CREATED by primary process for %p:\n" " [0x%" PRIxPTR ", 0x%" PRIxPTR "), lkey=0x%x", @@ -646,12 +645,12 @@ mlx4_mr_create_primary(struct rte_eth_dev *dev, struct mlx4_mr_cache *entry, } alloc_resources: /* Addresses must be page-aligned. */ - assert(rte_is_aligned((void *)data.start, data.msl->page_sz)); - assert(rte_is_aligned((void *)data.end, data.msl->page_sz)); + MLX4_ASSERT(rte_is_aligned((void *)data.start, data.msl->page_sz)); + MLX4_ASSERT(rte_is_aligned((void *)data.end, data.msl->page_sz)); msl = data.msl; ms = rte_mem_virt2memseg((void *)data.start, msl); len = data.end - data.start; - assert(msl->page_sz == ms->hugepage_sz); + MLX4_ASSERT(msl->page_sz == ms->hugepage_sz); /* Number of memsegs in the range. */ ms_n = len / msl->page_sz; DEBUG("port %u extending %p to [0x%" PRIxPTR ", 0x%" PRIxPTR ")," @@ -718,7 +717,7 @@ alloc_resources: mr_free(mr); goto alloc_resources; } - assert(data.msl == data_re.msl); + MLX4_ASSERT(data.msl == data_re.msl); rte_rwlock_write_lock(&priv->mr.rwlock); /* * Check the address is really missing. If other thread already created @@ -771,7 +770,7 @@ alloc_resources: } len = data.end - data.start; mr->ms_bmp_n = len / msl->page_sz; - assert(ms_idx_shift + mr->ms_bmp_n <= ms_n); + MLX4_ASSERT(ms_idx_shift + mr->ms_bmp_n <= ms_n); /* * Finally create a verbs MR for the memory chunk. ibv_reg_mr() can be * called with holding the memory lock because it doesn't use @@ -786,8 +785,8 @@ alloc_resources: rte_errno = EINVAL; goto err_mrlock; } - assert((uintptr_t)mr->ibv_mr->addr == data.start); - assert(mr->ibv_mr->length == len); + MLX4_ASSERT((uintptr_t)mr->ibv_mr->addr == data.start); + MLX4_ASSERT(mr->ibv_mr->length == len); LIST_INSERT_HEAD(&priv->mr.mr_list, mr, mr); DEBUG("port %u MR CREATED (%p) for %p:\n" " [0x%" PRIxPTR ", 0x%" PRIxPTR ")," @@ -800,7 +799,7 @@ alloc_resources: /* Fill in output data. */ mr_lookup_dev(dev, entry, addr); /* Lookup can't fail. */ - assert(entry->lkey != UINT32_MAX); + MLX4_ASSERT(entry->lkey != UINT32_MAX); rte_rwlock_write_unlock(&priv->mr.rwlock); rte_mcfg_mem_read_unlock(); return entry->lkey; @@ -905,8 +904,9 @@ mlx4_mr_mem_event_free_cb(struct rte_eth_dev *dev, const void *addr, size_t len) dev->data->port_id, addr, len); msl = rte_mem_virt2memseg_list(addr); /* addr and len must be page-aligned. */ - assert((uintptr_t)addr == RTE_ALIGN((uintptr_t)addr, msl->page_sz)); - assert(len == RTE_ALIGN(len, msl->page_sz)); + MLX4_ASSERT((uintptr_t)addr == + RTE_ALIGN((uintptr_t)addr, msl->page_sz)); + MLX4_ASSERT(len == RTE_ALIGN(len, msl->page_sz)); ms_n = len / msl->page_sz; rte_rwlock_write_lock(&priv->mr.rwlock); /* Clear bits of freed memsegs from MR. */ @@ -922,14 +922,14 @@ mlx4_mr_mem_event_free_cb(struct rte_eth_dev *dev, const void *addr, size_t len) mr = mr_lookup_dev_list(dev, &entry, start); if (mr == NULL) continue; - assert(mr->msl); /* Can't be external memory. */ + MLX4_ASSERT(mr->msl); /* Can't be external memory. */ ms = rte_mem_virt2memseg((void *)start, msl); - assert(ms != NULL); - assert(msl->page_sz == ms->hugepage_sz); + MLX4_ASSERT(ms != NULL); + MLX4_ASSERT(msl->page_sz == ms->hugepage_sz); ms_idx = rte_fbarray_find_idx(&msl->memseg_arr, ms); pos = ms_idx - mr->ms_base_idx; - assert(rte_bitmap_get(mr->ms_bmp, pos)); - assert(pos < mr->ms_bmp_n); + MLX4_ASSERT(rte_bitmap_get(mr->ms_bmp, pos)); + MLX4_ASSERT(pos < mr->ms_bmp_n); DEBUG("port %u MR(%p): clear bitmap[%u] for addr %p", dev->data->port_id, (void *)mr, pos, (void *)start); rte_bitmap_clear(mr->ms_bmp, pos); @@ -986,7 +986,7 @@ mlx4_mr_mem_event_cb(enum rte_mem_event event_type, const void *addr, struct mlx4_dev_list *dev_list = &mlx4_shared_data->mem_event_cb_list; /* Must be called from the primary process. */ - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); switch (event_type) { case RTE_MEM_EVENT_FREE: rte_rwlock_read_lock(&mlx4_shared_data->mem_event_rwlock); @@ -1222,7 +1222,7 @@ mlx4_mr_update_ext_mp_cb(struct rte_mempool *mp, void *opaque, struct mlx4_mr_cache entry; uint32_t lkey; - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); /* If already registered, it should return. */ rte_rwlock_read_lock(&priv->mr.rwlock); lkey = mr_lookup_dev(dev, &entry, addr); diff --git a/drivers/net/mlx4/mlx4_rxq.c b/drivers/net/mlx4/mlx4_rxq.c index 4a6fbd922c..0699bdd5f2 100644 --- a/drivers/net/mlx4/mlx4_rxq.c +++ b/drivers/net/mlx4/mlx4_rxq.c @@ -8,7 +8,6 @@ * Rx queues configuration for mlx4 driver. */ -#include #include #include #include @@ -140,12 +139,12 @@ error: void mlx4_rss_put(struct mlx4_rss *rss) { - assert(rss->refcnt); + MLX4_ASSERT(rss->refcnt); if (--rss->refcnt) return; - assert(!rss->usecnt); - assert(!rss->qp); - assert(!rss->ind); + MLX4_ASSERT(!rss->usecnt); + MLX4_ASSERT(!rss->qp); + MLX4_ASSERT(!rss->ind); LIST_REMOVE(rss, next); rte_free(rss); } @@ -167,10 +166,10 @@ mlx4_rss_put(struct mlx4_rss *rss) int mlx4_rss_attach(struct mlx4_rss *rss) { - assert(rss->refcnt); + MLX4_ASSERT(rss->refcnt); if (rss->usecnt++) { - assert(rss->qp); - assert(rss->ind); + MLX4_ASSERT(rss->qp); + MLX4_ASSERT(rss->ind); return 0; } @@ -295,9 +294,9 @@ mlx4_rss_detach(struct mlx4_rss *rss) struct rte_eth_dev *dev = ETH_DEV(priv); unsigned int i; - assert(rss->refcnt); - assert(rss->qp); - assert(rss->ind); + MLX4_ASSERT(rss->refcnt); + MLX4_ASSERT(rss->qp); + MLX4_ASSERT(rss->ind); if (--rss->usecnt) return; claim_zero(mlx4_glue->destroy_qp(rss->qp)); @@ -366,7 +365,7 @@ mlx4_rss_init(struct mlx4_priv *priv) /* Attach the configured Rx queues. */ if (rxq) { - assert(!rxq->usecnt); + MLX4_ASSERT(!rxq->usecnt); ret = mlx4_rxq_attach(rxq); if (!ret) { wq_num = rxq->wq->wq_num; @@ -463,7 +462,7 @@ mlx4_rss_deinit(struct mlx4_priv *priv) struct rxq *rxq = ETH_DEV(priv)->data->rx_queues[i]; if (rxq) { - assert(rxq->usecnt == 1); + MLX4_ASSERT(rxq->usecnt == 1); mlx4_rxq_detach(rxq); } } @@ -488,10 +487,10 @@ int mlx4_rxq_attach(struct rxq *rxq) { if (rxq->usecnt++) { - assert(rxq->cq); - assert(rxq->wq); - assert(rxq->wqes); - assert(rxq->rq_db); + MLX4_ASSERT(rxq->cq); + MLX4_ASSERT(rxq->wq); + MLX4_ASSERT(rxq->wqes); + MLX4_ASSERT(rxq->rq_db); return 0; } @@ -512,7 +511,7 @@ mlx4_rxq_attach(struct rxq *rxq) unsigned int i; int ret; - assert(rte_is_power_of_2(elts_n)); + MLX4_ASSERT(rte_is_power_of_2(elts_n)); priv->verbs_alloc_ctx.type = MLX4_VERBS_ALLOC_TYPE_RX_QUEUE; priv->verbs_alloc_ctx.obj = rxq; cq = mlx4_glue->create_cq(priv->ctx, elts_n / sges_n, NULL, @@ -584,10 +583,10 @@ mlx4_rxq_attach(struct rxq *rxq) goto error; } /* Headroom is reserved by rte_pktmbuf_alloc(). */ - assert(buf->data_off == RTE_PKTMBUF_HEADROOM); + MLX4_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); + MLX4_ASSERT(rte_pktmbuf_data_len(buf) == 0); + MLX4_ASSERT(rte_pktmbuf_pkt_len(buf) == 0); /* Only the first segment keeps headroom. */ if (i % sges_n) buf->data_off = 0; @@ -828,7 +827,7 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, .socket = socket, }; /* Enable scattered packets support for this queue if necessary. */ - assert(mb_len >= RTE_PKTMBUF_HEADROOM); + MLX4_ASSERT(mb_len >= RTE_PKTMBUF_HEADROOM); if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= (mb_len - RTE_PKTMBUF_HEADROOM)) { ; @@ -904,7 +903,7 @@ error: ret = rte_errno; mlx4_rx_queue_release(rxq); rte_errno = ret; - assert(rte_errno > 0); + MLX4_ASSERT(rte_errno > 0); return -rte_errno; } @@ -931,10 +930,10 @@ mlx4_rx_queue_release(void *dpdk_rxq) ETH_DEV(priv)->data->rx_queues[i] = NULL; break; } - assert(!rxq->cq); - assert(!rxq->wq); - assert(!rxq->wqes); - assert(!rxq->rq_db); + MLX4_ASSERT(!rxq->cq); + MLX4_ASSERT(!rxq->wq); + MLX4_ASSERT(!rxq->wqes); + MLX4_ASSERT(!rxq->rq_db); if (rxq->channel) claim_zero(mlx4_glue->destroy_comp_channel(rxq->channel)); mlx4_mr_btree_free(&rxq->mr_ctrl.cache_bh); diff --git a/drivers/net/mlx4/mlx4_rxtx.c b/drivers/net/mlx4/mlx4_rxtx.c index b56436e886..adc1c9bf81 100644 --- a/drivers/net/mlx4/mlx4_rxtx.c +++ b/drivers/net/mlx4/mlx4_rxtx.c @@ -8,7 +8,6 @@ * Data plane functions for mlx4 driver. */ -#include #include #include #include @@ -264,7 +263,7 @@ mlx4_txq_stamp_freed_wqe(struct mlx4_sq *sq, volatile uint32_t *start, uint32_t stamp = sq->stamp; int32_t size = (intptr_t)end - (intptr_t)start; - assert(start != end); + MLX4_ASSERT(start != end); /* Hold SQ ring wrap around. */ if (size < 0) { size = (int32_t)sq->size + size; @@ -891,12 +890,12 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) volatile struct mlx4_wqe_ctrl_seg *ctrl; struct txq_elt *elt; - assert(txq->elts_comp_cd != 0); + MLX4_ASSERT(txq->elts_comp_cd != 0); if (likely(max >= txq->elts_comp_cd_init)) mlx4_txq_complete(txq, elts_m, sq); max = elts_n - max; - assert(max >= 1); - assert(max <= elts_n); + MLX4_ASSERT(max >= 1); + MLX4_ASSERT(max <= elts_n); /* Always leave one free entry in the ring. */ --max; if (max > pkts_n) @@ -1194,9 +1193,9 @@ mlx4_cq_poll_one(struct rxq *rxq, volatile struct mlx4_cqe **out) * ownership bit. */ rte_rmb(); - assert(!(cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK)); - assert((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) != - MLX4_CQE_OPCODE_ERROR); + MLX4_ASSERT(!(cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK)); + MLX4_ASSERT((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) != + MLX4_CQE_OPCODE_ERROR); ret = rte_be_to_cpu_32(cqe->byte_cnt); ++cq->cons_index; out: @@ -1252,7 +1251,7 @@ mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) break; } while (pkt != seg) { - assert(pkt != (*rxq->elts)[idx]); + MLX4_ASSERT(pkt != (*rxq->elts)[idx]); rep = pkt->next; pkt->next = NULL; pkt->nb_segs = 1; @@ -1275,7 +1274,7 @@ mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) goto skip; } pkt = seg; - assert(len >= (rxq->crc_present << 2)); + MLX4_ASSERT(len >= (rxq->crc_present << 2)); /* Update packet information. */ pkt->packet_type = rxq_cq_to_pkt_type(cqe, rxq->l2tun_offload); diff --git a/drivers/net/mlx4/mlx4_txq.c b/drivers/net/mlx4/mlx4_txq.c index 01a5efd80d..37b84413fb 100644 --- a/drivers/net/mlx4/mlx4_txq.c +++ b/drivers/net/mlx4/mlx4_txq.c @@ -8,7 +8,6 @@ * Tx queues configuration for mlx4 driver. */ -#include #include #include #include @@ -51,8 +50,8 @@ txq_uar_init(struct txq *txq) struct mlx4_priv *priv = txq->priv; struct mlx4_proc_priv *ppriv = MLX4_PROC_PRIV(PORT_ID(priv)); - assert(rte_eal_process_type() == RTE_PROC_PRIMARY); - assert(ppriv); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); + MLX4_ASSERT(ppriv); ppriv->uar_table[txq->stats.idx] = txq->msq.db; } @@ -81,7 +80,7 @@ txq_uar_init_secondary(struct txq *txq, int fd) uintptr_t offset; const size_t page_size = sysconf(_SC_PAGESIZE); - assert(ppriv); + MLX4_ASSERT(ppriv); /* * As rdma-core, UARs are mapped in size of OS page * size. Ref to libmlx4 function: mlx4_init_context() @@ -137,12 +136,12 @@ mlx4_tx_uar_init_secondary(struct rte_eth_dev *dev, int fd) unsigned int i; int ret; - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); for (i = 0; i != txqs_n; ++i) { txq = dev->data->tx_queues[i]; if (!txq) continue; - assert(txq->stats.idx == (uint16_t)i); + MLX4_ASSERT(txq->stats.idx == (uint16_t)i); ret = txq_uar_init_secondary(txq, fd); if (ret) goto error; @@ -163,7 +162,7 @@ int mlx4_tx_uar_init_secondary(struct rte_eth_dev *dev __rte_unused, int fd __rte_unused) { - assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + MLX4_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY); ERROR("UAR remap is not supported"); rte_errno = ENOTSUP; return -rte_errno; @@ -188,7 +187,7 @@ mlx4_txq_free_elts(struct txq *txq) while (elts_tail != elts_head) { struct txq_elt *elt = &(*elts)[elts_tail++ & elts_m]; - assert(elt->buf != NULL); + MLX4_ASSERT(elt->buf != NULL); rte_pktmbuf_free(elt->buf); elt->buf = NULL; elt->wqe = NULL; @@ -489,7 +488,7 @@ error: ret = rte_errno; mlx4_tx_queue_release(txq); rte_errno = ret; - assert(rte_errno > 0); + MLX4_ASSERT(rte_errno > 0); priv->verbs_alloc_ctx.type = MLX4_VERBS_ALLOC_TYPE_NONE; return -rte_errno; } diff --git a/drivers/net/mlx4/mlx4_utils.c b/drivers/net/mlx4/mlx4_utils.c index a727d70365..614dc197d9 100644 --- a/drivers/net/mlx4/mlx4_utils.c +++ b/drivers/net/mlx4/mlx4_utils.c @@ -8,7 +8,6 @@ * Utility functions used by the mlx4 driver. */ -#include #include #include #include @@ -36,7 +35,7 @@ mlx4_fd_set_non_blocking(int fd) if (ret != -1 && !fcntl(fd, F_SETFL, ret | O_NONBLOCK)) return 0; - assert(errno); + MLX4_ASSERT(errno); rte_errno = errno; return -rte_errno; } diff --git a/drivers/net/mlx4/mlx4_utils.h b/drivers/net/mlx4/mlx4_utils.h index a84a9ab6f7..b8769562ab 100644 --- a/drivers/net/mlx4/mlx4_utils.h +++ b/drivers/net/mlx4/mlx4_utils.h @@ -6,7 +6,6 @@ #ifndef MLX4_UTILS_H_ #define MLX4_UTILS_H_ -#include #include #include @@ -54,12 +53,13 @@ pmd_drv_log_basename(const char *s) __func__, \ RTE_FMT_TAIL(__VA_ARGS__,))) #define DEBUG(...) PMD_DRV_LOG(DEBUG, __VA_ARGS__) -#define claim_zero(...) assert((__VA_ARGS__) == 0) +#define MLX4_ASSERT(exp) RTE_VERIFY(exp) +#define claim_zero(...) MLX4_ASSERT((__VA_ARGS__) == 0) #else /* RTE_LIBRTE_MLX4_DEBUG */ /* - * Like assert(), DEBUG() becomes a no-op and claim_zero() does not perform + * Like MLX4_ASSERT(), DEBUG() becomes a no-op and claim_zero() does not perform * any check when debugging is disabled. */ @@ -69,6 +69,7 @@ pmd_drv_log_basename(const char *s) RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ RTE_FMT_TAIL(__VA_ARGS__,))) #define DEBUG(...) (void)0 +#define MLX4_ASSERT(exp) RTE_ASSERT(exp) #define claim_zero(...) (__VA_ARGS__) #endif /* RTE_LIBRTE_MLX4_DEBUG */