]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
sfc: support variable number of MAC stats
authorEdward Cree <ecree@solarflare.com>
Thu, 21 Dec 2017 09:00:26 +0000 (09:00 +0000)
committerSultan Alsawaf <sultan.alsawaf@canonical.com>
Wed, 24 Jul 2019 15:45:14 +0000 (09:45 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836635
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: Edward Cree <ecree@solarflare.com>
Signed-off-by: Bert Kenward <bkenward@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit c1be48214543c4e5267c43d2c00ac2d9bb671381)
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/net/ethernet/sfc/ef10.c
drivers/net/ethernet/sfc/efx.c
drivers/net/ethernet/sfc/mcdi_port.c
drivers/net/ethernet/sfc/net_driver.h
drivers/net/ethernet/sfc/siena.c

index 1f64c7f60943ae71828ae69df740e01b3c7c8ef3..27b981e7e786296572c751c019ce4f8451b631e0 100644 (file)
@@ -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)
 {
-       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;
        size_t outlen;
        int rc;
@@ -306,6 +306,19 @@ static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
                          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;
 }
 
@@ -1850,7 +1863,7 @@ static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
 
        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)
                return 0;
        rmb();
@@ -1898,7 +1911,7 @@ static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
        DECLARE_BITMAP(mask, EF10_STAT_COUNT);
        __le64 generation_start, generation_end;
        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;
        __le64 *dma_stats;
        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[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_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;
        }
 
-       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) {
                WARN_ON_ONCE(1);
                goto out;
index 7bcbedce07a540edd81a8d14f33e9f60adcaa247..3780161de5a1343b716c3f7f0a55934b48c7e551 100644 (file)
@@ -2983,6 +2983,8 @@ static int efx_init_struct(struct efx_nic *efx,
                efx->type->rx_ts_offset - efx->type->rx_prefix_size;
        spin_lock_init(&efx->stats_lock);
        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);
        efx->phy_op = &efx_dummy_phy_operations;
        efx->mdio.dev = net_dev;
index 6e1f282b29765ed7567ee6d51526bf1c2de09672..65ee1a4681703a7faadb0ba81bb9abd5b9b93b7c 100644 (file)
@@ -1087,7 +1087,7 @@ static int efx_mcdi_mac_stats(struct efx_nic *efx,
        int period = action == EFX_STATS_ENABLE ? 1000 : 0;
        dma_addr_t dma_addr = efx->stats_buffer.dma_addr;
        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);
 
@@ -1121,7 +1121,7 @@ void efx_mcdi_mac_start_stats(struct efx_nic *efx)
 {
        __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);
 }
@@ -1139,10 +1139,10 @@ void efx_mcdi_mac_pull_stats(struct efx_nic *efx)
        __le64 *dma_stats = efx->stats_buffer.addr;
        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);
 
-       while (dma_stats[MC_CMD_MAC_GENERATION_END] ==
+       while (dma_stats[efx->num_mac_stats - 1] ==
                                EFX_MC_STATS_GENERATION_INVALID &&
                        attempts-- != 0)
                udelay(EFX_MAC_STATS_WAIT_US);
@@ -1167,7 +1167,7 @@ int efx_mcdi_port_probe(struct efx_nic *efx)
 
        /* Allocate buffer for stats */
        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)
                return rc;
        netif_dbg(efx, probe, efx->net_dev,
index 6b8730a24513a8180e0c853c53ac4db9fc0436ad..4cedc5c4c6d9741faffe7cddbdc7b815ad7bfd3a 100644 (file)
@@ -774,6 +774,8 @@ struct vfdi_status;
  * @port_initialized: Port initialized?
  * @net_dev: Operating system network device. Consider holding the rtnl lock
  * @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
  * @phy_type: PHY type
  * @phy_op: PHY interface
@@ -922,6 +924,7 @@ struct efx_nic {
 
        netdev_features_t fixed_features;
 
+       u16 num_mac_stats;
        struct efx_buffer stats_buffer;
        u64 rx_nodesc_drops_total;
        u64 rx_nodesc_drops_while_down;
index 22d49ebb347c9bf75f9c59deb581acf134bb223a..ae8645ae4492527269615da0fd95402ae203d21d 100644 (file)
@@ -555,7 +555,7 @@ static int siena_try_update_nic_stats(struct efx_nic *efx)
 
        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)
                return 0;
        rmb();