Skip to content

Commit

Permalink
net/sfc: fix MAC stats update for stopped device
Browse files Browse the repository at this point in the history
[ upstream commit 1827b07 ]

Return the latest stats snapshot in stopped state
instead of returning an error.

Fixes: 1caab2f ("net/sfc: add basic statistics")

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
  • Loading branch information
ol-vanyaio authored and bluca committed Jul 26, 2021
1 parent b84a0eb commit 0cd4f7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion drivers/net/sfc/sfc.h
Expand Up @@ -399,7 +399,7 @@ int sfc_port_start(struct sfc_adapter *sa);
void sfc_port_stop(struct sfc_adapter *sa);
void sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
struct rte_eth_link *link_info);
int sfc_port_update_mac_stats(struct sfc_adapter *sa);
int sfc_port_update_mac_stats(struct sfc_adapter *sa, boolean_t manual_update);
int sfc_port_reset_mac_stats(struct sfc_adapter *sa);
int sfc_set_rx_mode(struct sfc_adapter *sa);
int sfc_set_rx_mode_unchecked(struct sfc_adapter *sa);
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/sfc/sfc_ethdev.c
Expand Up @@ -606,7 +606,7 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)

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;

Expand Down Expand Up @@ -724,7 +724,7 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,

sfc_adapter_lock(sa);

rc = sfc_port_update_mac_stats(sa);
rc = sfc_port_update_mac_stats(sa, B_FALSE);
if (rc != 0) {
SFC_ASSERT(rc > 0);
nstats = -rc;
Expand Down Expand Up @@ -788,7 +788,7 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,

sfc_adapter_lock(sa);

rc = sfc_port_update_mac_stats(sa);
rc = sfc_port_update_mac_stats(sa, B_FALSE);
if (rc != 0) {
SFC_ASSERT(rc > 0);
ret = -rc;
Expand Down
11 changes: 7 additions & 4 deletions drivers/net/sfc/sfc_port.c
Expand Up @@ -26,15 +26,16 @@
/**
* Update MAC statistics in the buffer.
*
* @param sa Adapter
* @param sa Adapter
* @param force_upload Flag to upload MAC stats in any case
*
* @return Status code
* @retval 0 Success
* @retval EAGAIN Try again
* @retval ENOMEM Memory allocation failure
*/
int
sfc_port_update_mac_stats(struct sfc_adapter *sa)
sfc_port_update_mac_stats(struct sfc_adapter *sa, boolean_t force_upload)
{
struct sfc_port *port = &sa->port;
efsys_mem_t *esmp = &port->mac_stats_dma_mem;
Expand All @@ -46,14 +47,14 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa)
SFC_ASSERT(sfc_adapter_is_locked(sa));

if (sa->state != SFC_ADAPTER_STARTED)
return EINVAL;
return 0;

/*
* If periodic statistics DMA'ing is off or if not supported,
* make a manual request and keep an eye on timer if need be
*/
if (!port->mac_stats_periodic_dma_supported ||
(port->mac_stats_update_period_ms == 0)) {
(port->mac_stats_update_period_ms == 0) || force_upload) {
if (port->mac_stats_update_period_ms != 0) {
uint64_t timestamp = sfc_get_system_msecs();

Expand Down Expand Up @@ -367,6 +368,8 @@ sfc_port_stop(struct sfc_adapter *sa)
(void)efx_mac_stats_periodic(sa->nic, &sa->port.mac_stats_dma_mem,
0, B_FALSE);

sfc_port_update_mac_stats(sa, B_TRUE);

efx_port_fini(sa->nic);
efx_filter_fini(sa->nic);

Expand Down

0 comments on commit 0cd4f7e

Please sign in to comment.