#include <rte_mempool.h>
#include <rte_prefetch.h>
#include <rte_malloc.h>
-#include <rte_spinlock.h>
#include <rte_log.h>
#include <rte_alarm.h>
#include <rte_memory.h>
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]; \
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);
- priv_unlock(priv);
- return ret;
+ return dev_configure(dev);
}
static uint16_t mlx4_tx_burst(void *, struct rte_mbuf **, uint16_t);
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 -rte_errno;
}
if (txq != NULL) {
(void *)dev, idx, (void *)txq);
if (priv->started) {
rte_errno = EEXIST;
- priv_unlock(priv);
return -rte_errno;
}
(*priv->txqs)[idx] = NULL;
rte_errno = ENOMEM;
ERROR("%p: unable to allocate queue index %u",
(void *)dev, idx);
- priv_unlock(priv);
return -rte_errno;
}
}
/* Update send callback. */
dev->tx_pkt_burst = mlx4_tx_burst;
}
- priv_unlock(priv);
return ret;
}
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",
}
txq_cleanup(txq);
rte_free(txq);
- priv_unlock(priv);
}
/* RX queues handling. */
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 -rte_errno;
}
if (rxq != NULL) {
(void *)dev, idx, (void *)rxq);
if (priv->started) {
rte_errno = EEXIST;
- priv_unlock(priv);
return -rte_errno;
}
(*priv->rxqs)[idx] = NULL;
rte_errno = ENOMEM;
ERROR("%p: unable to allocate queue index %u",
(void *)dev, idx);
- priv_unlock(priv);
return -rte_errno;
}
}
/* Update receive callback. */
dev->rx_pkt_burst = mlx4_rx_burst;
}
- priv_unlock(priv);
return ret;
}
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",
}
rxq_cleanup(rxq);
rte_free(rxq);
- priv_unlock(priv);
}
static int
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);
(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;
}
{
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);
priv_mac_addr_del(priv);
- priv_unlock(priv);
}
/**
if (priv == NULL)
return;
- priv_lock(priv);
DEBUG("%p: closing device \"%s\"",
(void *)dev,
((priv->ctx != NULL) ? priv->ctx->device->name : ""));
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);
memset(priv, 0, sizeof(*priv));
}
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);
}
/**
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);
}
/**
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;
ETH_LINK_SPEED_20G |
ETH_LINK_SPEED_40G |
ETH_LINK_SPEED_56G;
- priv_unlock(priv);
}
/**
if (priv == NULL)
return;
- priv_lock(priv);
/* Add software counters. */
for (i = 0; (i != priv->rxqs_n); ++i) {
struct rxq *rxq = (*priv->rxqs)[i];
tmp.oerrors += txq->stats.odropped;
}
*stats = tmp;
- priv_unlock(priv);
}
/**
if (priv == NULL)
return;
- priv_lock(priv);
for (i = 0; (i != priv->rxqs_n); ++i) {
if ((*priv->rxqs)[i] == NULL)
continue;
(*priv->txqs)[i]->stats =
(struct mlx4_txq_stats){ .idx = idx };
}
- priv_unlock(priv);
}
/**
struct rte_eth_link dev_link;
int link_speed = 0;
- /* priv_lock() is not taken to allow concurrent calls. */
if (priv == NULL) {
rte_errno = EINVAL;
return -rte_errno;
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 = rte_errno;
DEBUG("adapter port %u MTU set to %u", priv->port, mtu);
priv->mtu = mtu;
out:
- priv_unlock(priv);
assert(ret >= 0);
return -ret;
}
int ret;
ifr.ifr_data = (void *)ðpause;
- priv_lock(priv);
if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
ret = rte_errno;
WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)"
fc_conf->mode = RTE_FC_NONE;
ret = 0;
out:
- priv_unlock(priv);
assert(ret >= 0);
return -ret;
}
ethpause.tx_pause = 1;
else
ethpause.tx_pause = 0;
- priv_lock(priv);
if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
ret = rte_errno;
WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
}
ret = 0;
out:
- priv_unlock(priv);
assert(ret >= 0);
return -ret;
}
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);
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;
struct rte_flow_error *error)
{
struct priv *priv = dev->data->dev_private;
- int ret;
struct mlx4_flow flow = { .offset = sizeof(struct ibv_flow_attr) };
- priv_lock(priv);
- ret = priv_flow_validate(priv, attr, items, actions, error, &flow);
- priv_unlock(priv);
- return ret;
+ return priv_flow_validate(priv, attr, items, actions, error, &flow);
}
/**
struct priv *priv = dev->data->dev_private;
struct rte_flow *flow;
- priv_lock(priv);
flow = priv_flow_create(priv, attr, items, actions, error);
if (flow) {
LIST_INSERT_HEAD(&priv->flows, flow, next);
DEBUG("Flow created %p", (void *)flow);
}
- priv_unlock(priv);
return flow;
}
{
struct priv *priv = dev->data->dev_private;
- priv_lock(priv);
if (priv->rxqs) {
rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
NULL, "isolated mode must be set"
" before configuring the device");
- priv_unlock(priv);
return -rte_errno;
}
priv->isolated = !!enable;
- priv_unlock(priv);
return 0;
}
struct priv *priv = dev->data->dev_private;
(void)error;
- priv_lock(priv);
priv_flow_destroy(priv, flow);
- priv_unlock(priv);
return 0;
}
struct priv *priv = dev->data->dev_private;
(void)error;
- priv_lock(priv);
priv_flow_flush(priv);
- priv_unlock(priv);
return 0;
}