Commit 177a6cde authored by Michael Chan's avatar Michael Chan Committed by David S. Miller

bnxt_en: Refactor statistics code and structures.

The driver manages multiple statistics structures of different sizes.
They are all allocated, freed, and handled practically the same.  Define
a new bnxt_stats_mem structure and common allocation and free functions
for all staistics memory blocks.
Reviewed-by: default avatarVasundhara Volam <vasundhara-v.volam@broadcom.com>
Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 24c93443
...@@ -3711,61 +3711,55 @@ static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp) ...@@ -3711,61 +3711,55 @@ static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
return 0; return 0;
} }
static void bnxt_free_port_stats(struct bnxt *bp) static void bnxt_free_stats_mem(struct bnxt *bp, struct bnxt_stats_mem *stats)
{ {
struct pci_dev *pdev = bp->pdev; if (stats->hw_stats) {
dma_free_coherent(&bp->pdev->dev, stats->len, stats->hw_stats,
stats->hw_stats_map);
stats->hw_stats = NULL;
}
}
bp->flags &= ~BNXT_FLAG_PORT_STATS; static int bnxt_alloc_stats_mem(struct bnxt *bp, struct bnxt_stats_mem *stats)
bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT; {
stats->hw_stats = dma_alloc_coherent(&bp->pdev->dev, stats->len,
&stats->hw_stats_map, GFP_KERNEL);
if (!stats->hw_stats)
return -ENOMEM;
if (bp->hw_rx_port_stats) { memset(stats->hw_stats, 0, stats->len);
dma_free_coherent(&pdev->dev, bp->hw_port_stats_size, return 0;
bp->hw_rx_port_stats, }
bp->hw_rx_port_stats_map);
bp->hw_rx_port_stats = NULL;
}
if (bp->hw_tx_port_stats_ext) { static void bnxt_free_port_stats(struct bnxt *bp)
dma_free_coherent(&pdev->dev, sizeof(struct tx_port_stats_ext), {
bp->hw_tx_port_stats_ext, bp->flags &= ~BNXT_FLAG_PORT_STATS;
bp->hw_tx_port_stats_ext_map); bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
bp->hw_tx_port_stats_ext = NULL;
}
if (bp->hw_rx_port_stats_ext) { bnxt_free_stats_mem(bp, &bp->port_stats);
dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext), bnxt_free_stats_mem(bp, &bp->rx_port_stats_ext);
bp->hw_rx_port_stats_ext, bnxt_free_stats_mem(bp, &bp->tx_port_stats_ext);
bp->hw_rx_port_stats_ext_map);
bp->hw_rx_port_stats_ext = NULL;
}
} }
static void bnxt_free_ring_stats(struct bnxt *bp) static void bnxt_free_ring_stats(struct bnxt *bp)
{ {
struct pci_dev *pdev = bp->pdev; int i;
int size, i;
if (!bp->bnapi) if (!bp->bnapi)
return; return;
size = bp->hw_ring_stats_size;
for (i = 0; i < bp->cp_nr_rings; i++) { for (i = 0; i < bp->cp_nr_rings; i++) {
struct bnxt_napi *bnapi = bp->bnapi[i]; struct bnxt_napi *bnapi = bp->bnapi[i];
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
if (cpr->hw_stats) { bnxt_free_stats_mem(bp, &cpr->stats);
dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
cpr->hw_stats_map);
cpr->hw_stats = NULL;
}
} }
} }
static int bnxt_alloc_stats(struct bnxt *bp) static int bnxt_alloc_stats(struct bnxt *bp)
{ {
u32 size, i; u32 size, i;
struct pci_dev *pdev = bp->pdev; int rc;
size = bp->hw_ring_stats_size; size = bp->hw_ring_stats_size;
...@@ -3773,11 +3767,10 @@ static int bnxt_alloc_stats(struct bnxt *bp) ...@@ -3773,11 +3767,10 @@ static int bnxt_alloc_stats(struct bnxt *bp)
struct bnxt_napi *bnapi = bp->bnapi[i]; struct bnxt_napi *bnapi = bp->bnapi[i];
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size, cpr->stats.len = size;
&cpr->hw_stats_map, rc = bnxt_alloc_stats_mem(bp, &cpr->stats);
GFP_KERNEL); if (rc)
if (!cpr->hw_stats) return rc;
return -ENOMEM;
cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
} }
...@@ -3785,22 +3778,14 @@ static int bnxt_alloc_stats(struct bnxt *bp) ...@@ -3785,22 +3778,14 @@ static int bnxt_alloc_stats(struct bnxt *bp)
if (BNXT_VF(bp) || bp->chip_num == CHIP_NUM_58700) if (BNXT_VF(bp) || bp->chip_num == CHIP_NUM_58700)
return 0; return 0;
if (bp->hw_rx_port_stats) if (bp->port_stats.hw_stats)
goto alloc_ext_stats; goto alloc_ext_stats;
bp->hw_port_stats_size = BNXT_PORT_STATS_SIZE; bp->port_stats.len = BNXT_PORT_STATS_SIZE;
rc = bnxt_alloc_stats_mem(bp, &bp->port_stats);
bp->hw_rx_port_stats = if (rc)
dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size, return rc;
&bp->hw_rx_port_stats_map,
GFP_KERNEL);
if (!bp->hw_rx_port_stats)
return -ENOMEM;
bp->hw_tx_port_stats = (void *)bp->hw_rx_port_stats +
BNXT_TX_PORT_STATS_BYTE_OFFSET;
bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
BNXT_TX_PORT_STATS_BYTE_OFFSET;
bp->flags |= BNXT_FLAG_PORT_STATS; bp->flags |= BNXT_FLAG_PORT_STATS;
alloc_ext_stats: alloc_ext_stats:
...@@ -3809,26 +3794,26 @@ static int bnxt_alloc_stats(struct bnxt *bp) ...@@ -3809,26 +3794,26 @@ static int bnxt_alloc_stats(struct bnxt *bp)
if (!(bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED)) if (!(bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED))
return 0; return 0;
if (bp->hw_rx_port_stats_ext) if (bp->rx_port_stats_ext.hw_stats)
goto alloc_tx_ext_stats; goto alloc_tx_ext_stats;
bp->hw_rx_port_stats_ext = bp->rx_port_stats_ext.len = sizeof(struct rx_port_stats_ext);
dma_alloc_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext), rc = bnxt_alloc_stats_mem(bp, &bp->rx_port_stats_ext);
&bp->hw_rx_port_stats_ext_map, GFP_KERNEL); /* Extended stats are optional */
if (!bp->hw_rx_port_stats_ext) if (rc)
return 0; return 0;
alloc_tx_ext_stats: alloc_tx_ext_stats:
if (bp->hw_tx_port_stats_ext) if (bp->tx_port_stats_ext.hw_stats)
return 0; return 0;
if (bp->hwrm_spec_code >= 0x10902 || if (bp->hwrm_spec_code >= 0x10902 ||
(bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED)) { (bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED)) {
bp->hw_tx_port_stats_ext = bp->tx_port_stats_ext.len = sizeof(struct tx_port_stats_ext);
dma_alloc_coherent(&pdev->dev, rc = bnxt_alloc_stats_mem(bp, &bp->tx_port_stats_ext);
sizeof(struct tx_port_stats_ext), /* Extended stats are optional */
&bp->hw_tx_port_stats_ext_map, if (rc)
GFP_KERNEL); return 0;
} }
bp->flags |= BNXT_FLAG_PORT_STATS_EXT; bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
return 0; return 0;
...@@ -6439,7 +6424,7 @@ static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp) ...@@ -6439,7 +6424,7 @@ static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
struct bnxt_napi *bnapi = bp->bnapi[i]; struct bnxt_napi *bnapi = bp->bnapi[i];
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map); req.stats_dma_addr = cpu_to_le64(cpr->stats.hw_stats_map);
rc = _hwrm_send_message(bp, &req, sizeof(req), rc = _hwrm_send_message(bp, &req, sizeof(req),
HWRM_CMD_TIMEOUT); HWRM_CMD_TIMEOUT);
...@@ -7480,8 +7465,9 @@ static int bnxt_hwrm_port_qstats(struct bnxt *bp) ...@@ -7480,8 +7465,9 @@ static int bnxt_hwrm_port_qstats(struct bnxt *bp)
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1); bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
req.port_id = cpu_to_le16(pf->port_id); req.port_id = cpu_to_le16(pf->port_id);
req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map); req.tx_stat_host_addr = cpu_to_le64(bp->port_stats.hw_stats_map +
req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map); BNXT_TX_PORT_STATS_BYTE_OFFSET);
req.rx_stat_host_addr = cpu_to_le64(bp->port_stats.hw_stats_map);
return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
} }
...@@ -7500,11 +7486,11 @@ static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp) ...@@ -7500,11 +7486,11 @@ static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp)
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1); bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1);
req.port_id = cpu_to_le16(pf->port_id); req.port_id = cpu_to_le16(pf->port_id);
req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext)); req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map); req.rx_stat_host_addr = cpu_to_le64(bp->rx_port_stats_ext.hw_stats_map);
tx_stat_size = bp->hw_tx_port_stats_ext ? tx_stat_size = bp->tx_port_stats_ext.hw_stats ?
sizeof(*bp->hw_tx_port_stats_ext) : 0; sizeof(struct tx_port_stats_ext) : 0;
req.tx_stat_size = cpu_to_le16(tx_stat_size); req.tx_stat_size = cpu_to_le16(tx_stat_size);
req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_ext_map); req.tx_stat_host_addr = cpu_to_le64(bp->tx_port_stats_ext.hw_stats_map);
mutex_lock(&bp->hwrm_cmd_lock); mutex_lock(&bp->hwrm_cmd_lock);
rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
if (!rc) { if (!rc) {
...@@ -9582,7 +9568,7 @@ static void bnxt_get_ring_stats(struct bnxt *bp, ...@@ -9582,7 +9568,7 @@ static void bnxt_get_ring_stats(struct bnxt *bp,
for (i = 0; i < bp->cp_nr_rings; i++) { for (i = 0; i < bp->cp_nr_rings; i++) {
struct bnxt_napi *bnapi = bp->bnapi[i]; struct bnxt_napi *bnapi = bp->bnapi[i];
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
struct ctx_hw_stats *hw_stats = cpr->hw_stats; struct ctx_hw_stats *hw_stats = cpr->stats.hw_stats;
stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts); stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts); stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
...@@ -9643,8 +9629,9 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) ...@@ -9643,8 +9629,9 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
bnxt_add_prev_stats(bp, stats); bnxt_add_prev_stats(bp, stats);
if (bp->flags & BNXT_FLAG_PORT_STATS) { if (bp->flags & BNXT_FLAG_PORT_STATS) {
struct rx_port_stats *rx = bp->hw_rx_port_stats; struct rx_port_stats *rx = bp->port_stats.hw_stats;
struct tx_port_stats *tx = bp->hw_tx_port_stats; struct tx_port_stats *tx = bp->port_stats.hw_stats +
BNXT_TX_PORT_STATS_BYTE_OFFSET;
stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames); stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames); stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
......
...@@ -919,6 +919,12 @@ struct bnxt_sw_stats { ...@@ -919,6 +919,12 @@ struct bnxt_sw_stats {
struct bnxt_cmn_sw_stats cmn; struct bnxt_cmn_sw_stats cmn;
}; };
struct bnxt_stats_mem {
void *hw_stats;
dma_addr_t hw_stats_map;
int len;
};
struct bnxt_cp_ring_info { struct bnxt_cp_ring_info {
struct bnxt_napi *bnapi; struct bnxt_napi *bnapi;
u32 cp_raw_cons; u32 cp_raw_cons;
...@@ -943,8 +949,7 @@ struct bnxt_cp_ring_info { ...@@ -943,8 +949,7 @@ struct bnxt_cp_ring_info {
dma_addr_t cp_desc_mapping[MAX_CP_PAGES]; dma_addr_t cp_desc_mapping[MAX_CP_PAGES];
struct ctx_hw_stats *hw_stats; struct bnxt_stats_mem stats;
dma_addr_t hw_stats_map;
u32 hw_stats_ctx_id; u32 hw_stats_ctx_id;
struct bnxt_sw_stats sw_stats; struct bnxt_sw_stats sw_stats;
...@@ -1776,15 +1781,9 @@ struct bnxt { ...@@ -1776,15 +1781,9 @@ struct bnxt {
dma_addr_t hwrm_cmd_kong_resp_dma_addr; dma_addr_t hwrm_cmd_kong_resp_dma_addr;
struct rtnl_link_stats64 net_stats_prev; struct rtnl_link_stats64 net_stats_prev;
struct rx_port_stats *hw_rx_port_stats; struct bnxt_stats_mem port_stats;
struct tx_port_stats *hw_tx_port_stats; struct bnxt_stats_mem rx_port_stats_ext;
struct rx_port_stats_ext *hw_rx_port_stats_ext; struct bnxt_stats_mem tx_port_stats_ext;
struct tx_port_stats_ext *hw_tx_port_stats_ext;
dma_addr_t hw_rx_port_stats_map;
dma_addr_t hw_tx_port_stats_map;
dma_addr_t hw_rx_port_stats_ext_map;
dma_addr_t hw_tx_port_stats_ext_map;
int hw_port_stats_size;
u16 fw_rx_stats_ext_size; u16 fw_rx_stats_ext_size;
u16 fw_tx_stats_ext_size; u16 fw_tx_stats_ext_size;
u16 hw_ring_stats_size; u16 hw_ring_stats_size;
......
...@@ -544,7 +544,7 @@ static int bnxt_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets) ...@@ -544,7 +544,7 @@ static int bnxt_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
static int bnxt_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc) static int bnxt_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc)
{ {
struct bnxt *bp = netdev_priv(dev); struct bnxt *bp = netdev_priv(dev);
__le64 *stats = (__le64 *)bp->hw_rx_port_stats; __le64 *stats = bp->port_stats.hw_stats;
struct ieee_pfc *my_pfc = bp->ieee_pfc; struct ieee_pfc *my_pfc = bp->ieee_pfc;
long rx_off, tx_off; long rx_off, tx_off;
int i, rc; int i, rc;
......
...@@ -559,7 +559,8 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, ...@@ -559,7 +559,8 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,
for (i = 0; i < bp->cp_nr_rings; i++) { for (i = 0; i < bp->cp_nr_rings; i++) {
struct bnxt_napi *bnapi = bp->bnapi[i]; struct bnxt_napi *bnapi = bp->bnapi[i];
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
__le64 *hw_stats = (__le64 *)cpr->hw_stats; struct ctx_hw_stats *hw = cpr->stats.hw_stats;
__le64 *hw_stats = cpr->stats.hw_stats;
u64 *sw; u64 *sw;
int k; int k;
...@@ -593,9 +594,9 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, ...@@ -593,9 +594,9 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,
buf[j] = sw[k]; buf[j] = sw[k];
bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter +=
le64_to_cpu(cpr->hw_stats->rx_discard_pkts); le64_to_cpu(hw->rx_discard_pkts);
bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter +=
le64_to_cpu(cpr->hw_stats->tx_discard_pkts); le64_to_cpu(hw->tx_discard_pkts);
} }
for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++)
...@@ -603,7 +604,7 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, ...@@ -603,7 +604,7 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,
skip_ring_stats: skip_ring_stats:
if (bp->flags & BNXT_FLAG_PORT_STATS) { if (bp->flags & BNXT_FLAG_PORT_STATS) {
__le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; __le64 *port_stats = bp->port_stats.hw_stats;
for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
buf[j] = le64_to_cpu(*(port_stats + buf[j] = le64_to_cpu(*(port_stats +
...@@ -611,8 +612,8 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, ...@@ -611,8 +612,8 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,
} }
} }
if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
__le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext; __le64 *rx_port_stats_ext = bp->rx_port_stats_ext.hw_stats;
__le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext; __le64 *tx_port_stats_ext = bp->tx_port_stats_ext.hw_stats;
for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) {
buf[j] = le64_to_cpu(*(rx_port_stats_ext + buf[j] = le64_to_cpu(*(rx_port_stats_ext +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment