X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fsfc%2Fsfc_ethdev.c;h=9dc5e5b3a3d4eda7747c05c93a48e07ad7132893;hb=7483341ae5533c5d5fa080a5d229e6f2daf03ea5;hp=2651c412888940189a050061087d9be0565cf14a;hpb=09cafbddbb4ca1f8c5f404223955f8c258e4149b;p=dpdk.git diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 2651c41288..9dc5e5b3a3 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -28,6 +28,10 @@ #include "sfc_flow.h" #include "sfc_dp.h" #include "sfc_dp_rx.h" +#include "sfc_sw_stats.h" + +#define SFC_XSTAT_ID_INVALID_VAL UINT64_MAX +#define SFC_XSTAT_ID_INVALID_NAME '\0' uint32_t sfc_logtype_driver; @@ -500,9 +504,9 @@ fail_rx_qinit: } static void -sfc_rx_queue_release(void *queue) +sfc_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid) { - struct sfc_dp_rxq *dp_rxq = queue; + struct sfc_dp_rxq *dp_rxq = dev->data->rx_queues[qid]; struct sfc_rxq *rxq; struct sfc_adapter *sa; sfc_sw_index_t sw_index; @@ -524,24 +528,28 @@ sfc_rx_queue_release(void *queue) } static int -sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, +sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid, uint16_t nb_tx_desc, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev); struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); + struct sfc_txq_info *txq_info; + sfc_sw_index_t sw_index; int rc; sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u", - tx_queue_id, nb_tx_desc, socket_id); + ethdev_qid, nb_tx_desc, socket_id); sfc_adapter_lock(sa); - rc = sfc_tx_qinit(sa, tx_queue_id, nb_tx_desc, socket_id, tx_conf); + sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid); + rc = sfc_tx_qinit(sa, sw_index, nb_tx_desc, socket_id, tx_conf); if (rc != 0) goto fail_tx_qinit; - dev->data->tx_queues[tx_queue_id] = sas->txq_info[tx_queue_id].dp; + txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid); + dev->data->tx_queues[ethdev_qid] = txq_info->dp; sfc_adapter_unlock(sa); return 0; @@ -553,11 +561,11 @@ fail_tx_qinit: } static void -sfc_tx_queue_release(void *queue) +sfc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid) { - struct sfc_dp_txq *dp_txq = queue; + struct sfc_dp_txq *dp_txq = dev->data->tx_queues[qid]; struct sfc_txq *txq; - unsigned int sw_index; + sfc_sw_index_t sw_index; struct sfc_adapter *sa; if (dp_txq == NULL) @@ -609,9 +617,9 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) uint64_t *mac_stats; int ret; - rte_spinlock_lock(&port->mac_stats_lock); + sfc_adapter_lock(sa); - ret = sfc_port_update_mac_stats(sa); + ret = sfc_port_update_mac_stats(sa, B_FALSE); if (ret != 0) goto unlock; @@ -682,7 +690,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) } unlock: - rte_spinlock_unlock(&port->mac_stats_lock); + sfc_adapter_unlock(sa); SFC_ASSERT(ret >= 0); return -ret; } @@ -694,12 +702,15 @@ sfc_stats_reset(struct rte_eth_dev *dev) struct sfc_port *port = &sa->port; int rc; + sfc_adapter_lock(sa); + if (sa->state != SFC_ADAPTER_STARTED) { /* * The operation cannot be done if port is not started; it * will be scheduled to be done during the next port start */ port->mac_stats_reset_pending = B_TRUE; + sfc_adapter_unlock(sa); return 0; } @@ -707,46 +718,49 @@ sfc_stats_reset(struct rte_eth_dev *dev) if (rc != 0) sfc_err(sa, "failed to reset statistics (rc = %d)", rc); + sfc_sw_xstats_reset(sa); + + sfc_adapter_unlock(sa); + SFC_ASSERT(rc >= 0); return -rc; } +static unsigned int +sfc_xstats_get_nb_supported(struct sfc_adapter *sa) +{ + struct sfc_port *port = &sa->port; + unsigned int nb_supported; + + sfc_adapter_lock(sa); + nb_supported = port->mac_stats_nb_supported + + sfc_sw_xstats_get_nb_supported(sa); + sfc_adapter_unlock(sa); + + return nb_supported; +} + static int sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, unsigned int xstats_count) { struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); - struct sfc_port *port = &sa->port; - uint64_t *mac_stats; + unsigned int nb_written = 0; + unsigned int nb_supported = 0; int rc; - unsigned int i; - int nstats = 0; - rte_spinlock_lock(&port->mac_stats_lock); + if (unlikely(xstats == NULL)) + return sfc_xstats_get_nb_supported(sa); - rc = sfc_port_update_mac_stats(sa); - if (rc != 0) { - SFC_ASSERT(rc > 0); - nstats = -rc; - goto unlock; - } + rc = sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written); + if (rc < 0) + return rc; - mac_stats = port->mac_stats_buf; + nb_supported = rc; + sfc_sw_xstats_get_vals(sa, xstats, xstats_count, &nb_written, + &nb_supported); - for (i = 0; i < EFX_MAC_NSTATS; ++i) { - if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) { - if (xstats != NULL && nstats < (int)xstats_count) { - xstats[nstats].id = nstats; - xstats[nstats].value = mac_stats[i]; - } - nstats++; - } - } - -unlock: - rte_spinlock_unlock(&port->mac_stats_lock); - - return nstats; + return nb_supported; } static int @@ -758,17 +772,31 @@ sfc_xstats_get_names(struct rte_eth_dev *dev, struct sfc_port *port = &sa->port; unsigned int i; unsigned int nstats = 0; + unsigned int nb_written = 0; + int ret; + + if (unlikely(xstats_names == NULL)) + return sfc_xstats_get_nb_supported(sa); for (i = 0; i < EFX_MAC_NSTATS; ++i) { if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) { - if (xstats_names != NULL && nstats < xstats_count) + if (nstats < xstats_count) { strlcpy(xstats_names[nstats].name, efx_mac_stat_name(sa->nic, i), sizeof(xstats_names[0].name)); + nb_written++; + } nstats++; } } + ret = sfc_sw_xstats_get_names(sa, xstats_names, xstats_count, + &nb_written, &nstats); + if (ret != 0) { + SFC_ASSERT(ret < 0); + return ret; + } + return nstats; } @@ -778,76 +806,94 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, { struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); struct sfc_port *port = &sa->port; - uint64_t *mac_stats; - unsigned int nb_supported = 0; - unsigned int nb_written = 0; + unsigned int nb_supported; unsigned int i; - int ret; int rc; - if (unlikely(values == NULL) || - unlikely((ids == NULL) && (n < port->mac_stats_nb_supported))) - return port->mac_stats_nb_supported; - - rte_spinlock_lock(&port->mac_stats_lock); - - rc = sfc_port_update_mac_stats(sa); - if (rc != 0) { - SFC_ASSERT(rc > 0); - ret = -rc; - goto unlock; - } + if (unlikely(ids == NULL || values == NULL)) + return -EINVAL; - mac_stats = port->mac_stats_buf; + /* + * Values array could be filled in nonsequential order. Fill values with + * constant indicating invalid ID first. + */ + for (i = 0; i < n; i++) + values[i] = SFC_XSTAT_ID_INVALID_VAL; - for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) { - if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) - continue; + rc = sfc_port_get_mac_stats_by_id(sa, ids, values, n); + if (rc != 0) + return rc; - if ((ids == NULL) || (ids[nb_written] == nb_supported)) - values[nb_written++] = mac_stats[i]; + nb_supported = port->mac_stats_nb_supported; + sfc_sw_xstats_get_vals_by_id(sa, ids, values, n, &nb_supported); - ++nb_supported; + /* Return number of written stats before invalid ID is encountered. */ + for (i = 0; i < n; i++) { + if (values[i] == SFC_XSTAT_ID_INVALID_VAL) + return i; } - ret = nb_written; - -unlock: - rte_spinlock_unlock(&port->mac_stats_lock); - - return ret; + return n; } static int sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, + const uint64_t *ids, struct rte_eth_xstat_name *xstats_names, - const uint64_t *ids, unsigned int size) + unsigned int size) { struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); struct sfc_port *port = &sa->port; - unsigned int nb_supported = 0; - unsigned int nb_written = 0; + unsigned int nb_supported; unsigned int i; + int ret; - if (unlikely(xstats_names == NULL) || - unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) - return port->mac_stats_nb_supported; + if (unlikely(xstats_names == NULL && ids != NULL) || + unlikely(xstats_names != NULL && ids == NULL)) + return -EINVAL; - for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) { - if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) - continue; + if (unlikely(xstats_names == NULL && ids == NULL)) + return sfc_xstats_get_nb_supported(sa); - if ((ids == NULL) || (ids[nb_written] == nb_supported)) { - char *name = xstats_names[nb_written++].name; + /* + * Names array could be filled in nonsequential order. Fill names with + * string indicating invalid ID first. + */ + for (i = 0; i < size; i++) + xstats_names[i].name[0] = SFC_XSTAT_ID_INVALID_NAME; + + sfc_adapter_lock(sa); - strlcpy(name, efx_mac_stat_name(sa->nic, i), + SFC_ASSERT(port->mac_stats_nb_supported <= + RTE_DIM(port->mac_stats_by_id)); + + for (i = 0; i < size; i++) { + if (ids[i] < port->mac_stats_nb_supported) { + strlcpy(xstats_names[i].name, + efx_mac_stat_name(sa->nic, + port->mac_stats_by_id[ids[i]]), sizeof(xstats_names[0].name)); } + } - ++nb_supported; + nb_supported = port->mac_stats_nb_supported; + + sfc_adapter_unlock(sa); + + ret = sfc_sw_xstats_get_names_by_id(sa, ids, xstats_names, size, + &nb_supported); + if (ret != 0) { + SFC_ASSERT(ret < 0); + return ret; + } + + /* Return number of written names before invalid ID is encountered. */ + for (i = 0; i < size; i++) { + if (xstats_names[i].name[0] == SFC_XSTAT_ID_INVALID_NAME) + return i; } - return nb_written; + return size; } static int @@ -1213,15 +1259,15 @@ sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid, * use any process-local pointers from the adapter data. */ static void -sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id, +sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid, struct rte_eth_txq_info *qinfo) { struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev); struct sfc_txq_info *txq_info; - SFC_ASSERT(tx_queue_id < sas->txq_count); + SFC_ASSERT(ethdev_qid < sas->ethdev_txq_count); - txq_info = &sas->txq_info[tx_queue_id]; + txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid); memset(qinfo, 0, sizeof(*qinfo)); @@ -1362,13 +1408,15 @@ sfc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid) } static int -sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) +sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid) { struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev); struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); + struct sfc_txq_info *txq_info; + sfc_sw_index_t sw_index; int rc; - sfc_log_init(sa, "TxQ = %u", tx_queue_id); + sfc_log_init(sa, "TxQ = %u", ethdev_qid); sfc_adapter_lock(sa); @@ -1376,14 +1424,16 @@ sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) if (sa->state != SFC_ADAPTER_STARTED) goto fail_not_started; - if (sas->txq_info[tx_queue_id].state != SFC_TXQ_INITIALIZED) + txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid); + if (txq_info->state != SFC_TXQ_INITIALIZED) goto fail_not_setup; - rc = sfc_tx_qstart(sa, tx_queue_id); + sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid); + rc = sfc_tx_qstart(sa, sw_index); if (rc != 0) goto fail_tx_qstart; - sas->txq_info[tx_queue_id].deferred_started = B_TRUE; + txq_info->deferred_started = B_TRUE; sfc_adapter_unlock(sa); return 0; @@ -1398,18 +1448,22 @@ fail_not_started: } static int -sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id) +sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid) { struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev); struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev); + struct sfc_txq_info *txq_info; + sfc_sw_index_t sw_index; - sfc_log_init(sa, "TxQ = %u", tx_queue_id); + sfc_log_init(sa, "TxQ = %u", ethdev_qid); sfc_adapter_lock(sa); - sfc_tx_qstop(sa, tx_queue_id); + sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid); + sfc_tx_qstop(sa, sw_index); - sas->txq_info[tx_queue_id].deferred_started = B_FALSE; + txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid); + txq_info->deferred_started = B_FALSE; sfc_adapter_unlock(sa); return 0;