Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1be4821 authored by Edward Cree's avatar Edward Cree Committed by David S. Miller
Browse files

sfc: support variable number of MAC stats



Medford2 NICs support more than MC_CMD_MAC_NSTATS stats, and report the new
 count in a field of MC_CMD_GET_CAPABILITIES_V4.  This also means that the
 end generation count moves (it is, as before, the last 64 bits of the DMA
 buffer, but that is no longer MC_CMD_MAC_GENERATION_END).
So read num_mac_stats from the GET_CAPABILITIES response, if present;
 otherwise assume MC_CMD_MAC_NSTATS; and always use num_mac_stats - 1 rather
 than MC_CMD_MAC_GENERATION_END.

Signed-off-by: default avatarEdward Cree <ecree@solarflare.com>
Signed-off-by: default avatarBert Kenward <bkenward@solarflare.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d31a5966
Loading
Loading
Loading
Loading
+18 −5
Original line number Original line Diff line number Diff line
@@ -233,7 +233,7 @@ static int efx_ef10_get_vf_index(struct efx_nic *efx)


static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
{
{
	MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V3_OUT_LEN);
	MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V4_OUT_LEN);
	struct efx_ef10_nic_data *nic_data = efx->nic_data;
	struct efx_ef10_nic_data *nic_data = efx->nic_data;
	size_t outlen;
	size_t outlen;
	int rc;
	int rc;
@@ -306,6 +306,19 @@ static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
			  efx->vi_stride);
			  efx->vi_stride);
	}
	}


	if (outlen >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
		efx->num_mac_stats = MCDI_WORD(outbuf,
				GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
		netif_dbg(efx, probe, efx->net_dev,
			  "firmware reports num_mac_stats = %u\n",
			  efx->num_mac_stats);
	} else {
		/* leave num_mac_stats as the default value, MC_CMD_MAC_NSTATS */
		netif_dbg(efx, probe, efx->net_dev,
			  "firmware did not report num_mac_stats, assuming %u\n",
			  efx->num_mac_stats);
	}

	return 0;
	return 0;
}
}


@@ -1850,7 +1863,7 @@ static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)


	dma_stats = efx->stats_buffer.addr;
	dma_stats = efx->stats_buffer.addr;


	generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
	generation_end = dma_stats[efx->num_mac_stats - 1];
	if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
	if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
		return 0;
		return 0;
	rmb();
	rmb();
@@ -1898,7 +1911,7 @@ static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
	DECLARE_BITMAP(mask, EF10_STAT_COUNT);
	DECLARE_BITMAP(mask, EF10_STAT_COUNT);
	__le64 generation_start, generation_end;
	__le64 generation_start, generation_end;
	u64 *stats = nic_data->stats;
	u64 *stats = nic_data->stats;
	u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
	u32 dma_len = efx->num_mac_stats * sizeof(u64);
	struct efx_buffer stats_buf;
	struct efx_buffer stats_buf;
	__le64 *dma_stats;
	__le64 *dma_stats;
	int rc;
	int rc;
@@ -1923,7 +1936,7 @@ static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
	}
	}


	dma_stats = stats_buf.addr;
	dma_stats = stats_buf.addr;
	dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
	dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;


	MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
	MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
	MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
	MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
@@ -1942,7 +1955,7 @@ static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
		goto out;
		goto out;
	}
	}


	generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
	generation_end = dma_stats[efx->num_mac_stats - 1];
	if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
	if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
		WARN_ON_ONCE(1);
		WARN_ON_ONCE(1);
		goto out;
		goto out;
+2 −0
Original line number Original line Diff line number Diff line
@@ -2983,6 +2983,8 @@ static int efx_init_struct(struct efx_nic *efx,
		efx->type->rx_ts_offset - efx->type->rx_prefix_size;
		efx->type->rx_ts_offset - efx->type->rx_prefix_size;
	spin_lock_init(&efx->stats_lock);
	spin_lock_init(&efx->stats_lock);
	efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
	efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
	efx->num_mac_stats = MC_CMD_MAC_NSTATS;
	BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END);
	mutex_init(&efx->mac_lock);
	mutex_init(&efx->mac_lock);
	efx->phy_op = &efx_dummy_phy_operations;
	efx->phy_op = &efx_dummy_phy_operations;
	efx->mdio.dev = net_dev;
	efx->mdio.dev = net_dev;
+5 −5
Original line number Original line Diff line number Diff line
@@ -1087,7 +1087,7 @@ static int efx_mcdi_mac_stats(struct efx_nic *efx,
	int period = action == EFX_STATS_ENABLE ? 1000 : 0;
	int period = action == EFX_STATS_ENABLE ? 1000 : 0;
	dma_addr_t dma_addr = efx->stats_buffer.dma_addr;
	dma_addr_t dma_addr = efx->stats_buffer.dma_addr;
	u32 dma_len = action != EFX_STATS_DISABLE ?
	u32 dma_len = action != EFX_STATS_DISABLE ?
		MC_CMD_MAC_NSTATS * sizeof(u64) : 0;
		efx->num_mac_stats * sizeof(u64) : 0;


	BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
	BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);


@@ -1121,7 +1121,7 @@ void efx_mcdi_mac_start_stats(struct efx_nic *efx)
{
{
	__le64 *dma_stats = efx->stats_buffer.addr;
	__le64 *dma_stats = efx->stats_buffer.addr;


	dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
	dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;


	efx_mcdi_mac_stats(efx, EFX_STATS_ENABLE, 0);
	efx_mcdi_mac_stats(efx, EFX_STATS_ENABLE, 0);
}
}
@@ -1139,10 +1139,10 @@ void efx_mcdi_mac_pull_stats(struct efx_nic *efx)
	__le64 *dma_stats = efx->stats_buffer.addr;
	__le64 *dma_stats = efx->stats_buffer.addr;
	int attempts = EFX_MAC_STATS_WAIT_ATTEMPTS;
	int attempts = EFX_MAC_STATS_WAIT_ATTEMPTS;


	dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
	dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
	efx_mcdi_mac_stats(efx, EFX_STATS_PULL, 0);
	efx_mcdi_mac_stats(efx, EFX_STATS_PULL, 0);


	while (dma_stats[MC_CMD_MAC_GENERATION_END] ==
	while (dma_stats[efx->num_mac_stats - 1] ==
				EFX_MC_STATS_GENERATION_INVALID &&
				EFX_MC_STATS_GENERATION_INVALID &&
			attempts-- != 0)
			attempts-- != 0)
		udelay(EFX_MAC_STATS_WAIT_US);
		udelay(EFX_MAC_STATS_WAIT_US);
@@ -1167,7 +1167,7 @@ int efx_mcdi_port_probe(struct efx_nic *efx)


	/* Allocate buffer for stats */
	/* Allocate buffer for stats */
	rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
	rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
				  MC_CMD_MAC_NSTATS * sizeof(u64), GFP_KERNEL);
				  efx->num_mac_stats * sizeof(u64), GFP_KERNEL);
	if (rc)
	if (rc)
		return rc;
		return rc;
	netif_dbg(efx, probe, efx->net_dev,
	netif_dbg(efx, probe, efx->net_dev,
+3 −0
Original line number Original line Diff line number Diff line
@@ -774,6 +774,8 @@ struct vfdi_status;
 * @port_initialized: Port initialized?
 * @port_initialized: Port initialized?
 * @net_dev: Operating system network device. Consider holding the rtnl lock
 * @net_dev: Operating system network device. Consider holding the rtnl lock
 * @fixed_features: Features which cannot be turned off
 * @fixed_features: Features which cannot be turned off
 * @num_mac_stats: Number of MAC stats reported by firmware (MAC_STATS_NUM_STATS
 *	field of %MC_CMD_GET_CAPABILITIES_V4 response, or %MC_CMD_MAC_NSTATS)
 * @stats_buffer: DMA buffer for statistics
 * @stats_buffer: DMA buffer for statistics
 * @phy_type: PHY type
 * @phy_type: PHY type
 * @phy_op: PHY interface
 * @phy_op: PHY interface
@@ -922,6 +924,7 @@ struct efx_nic {


	netdev_features_t fixed_features;
	netdev_features_t fixed_features;


	u16 num_mac_stats;
	struct efx_buffer stats_buffer;
	struct efx_buffer stats_buffer;
	u64 rx_nodesc_drops_total;
	u64 rx_nodesc_drops_total;
	u64 rx_nodesc_drops_while_down;
	u64 rx_nodesc_drops_while_down;
+1 −1
Original line number Original line Diff line number Diff line
@@ -555,7 +555,7 @@ static int siena_try_update_nic_stats(struct efx_nic *efx)


	dma_stats = efx->stats_buffer.addr;
	dma_stats = efx->stats_buffer.addr;


	generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
	generation_end = dma_stats[efx->num_mac_stats - 1];
	if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
	if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
		return 0;
		return 0;
	rmb();
	rmb();