Skip to content

Commit 23df6ae

Browse files
bmarreddykuba-moo
authored andcommitted
bng_en: Allocate stat contexts
Allocate the hardware statistics context with the firmware and register DMA memory required for ring statistics. This helps the driver to collect ring statistics provided by the firmware. Signed-off-by: Bhargava Marreddy <[email protected]> Reviewed-by: Vikas Gupta <[email protected]> Reviewed-by: Rajashekar Hudumula <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2fe6e77 commit 23df6ae

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,59 @@ int bnge_hwrm_queue_qportcfg(struct bnge_dev *bd)
701701
bnge_hwrm_req_drop(bd, req);
702702
return rc;
703703
}
704+
705+
void bnge_hwrm_stat_ctx_free(struct bnge_net *bn)
706+
{
707+
struct hwrm_stat_ctx_free_input *req;
708+
struct bnge_dev *bd = bn->bd;
709+
int i;
710+
711+
if (bnge_hwrm_req_init(bd, req, HWRM_STAT_CTX_FREE))
712+
return;
713+
714+
bnge_hwrm_req_hold(bd, req);
715+
for (i = 0; i < bd->nq_nr_rings; i++) {
716+
struct bnge_napi *bnapi = bn->bnapi[i];
717+
struct bnge_nq_ring_info *nqr = &bnapi->nq_ring;
718+
719+
if (nqr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
720+
req->stat_ctx_id = cpu_to_le32(nqr->hw_stats_ctx_id);
721+
bnge_hwrm_req_send(bd, req);
722+
723+
nqr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
724+
}
725+
}
726+
bnge_hwrm_req_drop(bd, req);
727+
}
728+
729+
int bnge_hwrm_stat_ctx_alloc(struct bnge_net *bn)
730+
{
731+
struct hwrm_stat_ctx_alloc_output *resp;
732+
struct hwrm_stat_ctx_alloc_input *req;
733+
struct bnge_dev *bd = bn->bd;
734+
int rc, i;
735+
736+
rc = bnge_hwrm_req_init(bd, req, HWRM_STAT_CTX_ALLOC);
737+
if (rc)
738+
return rc;
739+
740+
req->stats_dma_length = cpu_to_le16(bd->hw_ring_stats_size);
741+
req->update_period_ms = cpu_to_le32(bn->stats_coal_ticks / 1000);
742+
743+
resp = bnge_hwrm_req_hold(bd, req);
744+
for (i = 0; i < bd->nq_nr_rings; i++) {
745+
struct bnge_napi *bnapi = bn->bnapi[i];
746+
struct bnge_nq_ring_info *nqr = &bnapi->nq_ring;
747+
748+
req->stats_dma_addr = cpu_to_le64(nqr->stats.hw_stats_map);
749+
750+
rc = bnge_hwrm_req_send(bd, req);
751+
if (rc)
752+
break;
753+
754+
nqr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
755+
bn->grp_info[i].fw_stats_ctx = nqr->hw_stats_ctx_id;
756+
}
757+
bnge_hwrm_req_drop(bd, req);
758+
return rc;
759+
}

drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ int bnge_hwrm_func_qcfg(struct bnge_dev *bd);
2424
int bnge_hwrm_func_resc_qcaps(struct bnge_dev *bd);
2525
int bnge_hwrm_queue_qportcfg(struct bnge_dev *bd);
2626

27+
void bnge_hwrm_stat_ctx_free(struct bnge_net *bn);
28+
int bnge_hwrm_stat_ctx_alloc(struct bnge_net *bn);
2729
#endif /* _BNGE_HWRM_LIB_H_ */

drivers/net/ethernet/broadcom/bnge/bnge_netdev.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,73 @@
3030
#define BNGE_TC_TO_RING_BASE(bd, tc) \
3131
((tc) * (bd)->tx_nr_rings_per_tc)
3232

33+
static void bnge_free_stats_mem(struct bnge_net *bn,
34+
struct bnge_stats_mem *stats)
35+
{
36+
struct bnge_dev *bd = bn->bd;
37+
38+
if (stats->hw_stats) {
39+
dma_free_coherent(bd->dev, stats->len, stats->hw_stats,
40+
stats->hw_stats_map);
41+
stats->hw_stats = NULL;
42+
}
43+
}
44+
45+
static int bnge_alloc_stats_mem(struct bnge_net *bn,
46+
struct bnge_stats_mem *stats)
47+
{
48+
struct bnge_dev *bd = bn->bd;
49+
50+
stats->hw_stats = dma_alloc_coherent(bd->dev, stats->len,
51+
&stats->hw_stats_map, GFP_KERNEL);
52+
if (!stats->hw_stats)
53+
return -ENOMEM;
54+
55+
return 0;
56+
}
57+
58+
static void bnge_free_ring_stats(struct bnge_net *bn)
59+
{
60+
struct bnge_dev *bd = bn->bd;
61+
int i;
62+
63+
if (!bn->bnapi)
64+
return;
65+
66+
for (i = 0; i < bd->nq_nr_rings; i++) {
67+
struct bnge_napi *bnapi = bn->bnapi[i];
68+
struct bnge_nq_ring_info *nqr = &bnapi->nq_ring;
69+
70+
bnge_free_stats_mem(bn, &nqr->stats);
71+
}
72+
}
73+
74+
static int bnge_alloc_ring_stats(struct bnge_net *bn)
75+
{
76+
struct bnge_dev *bd = bn->bd;
77+
u32 size, i;
78+
int rc;
79+
80+
size = bd->hw_ring_stats_size;
81+
82+
for (i = 0; i < bd->nq_nr_rings; i++) {
83+
struct bnge_napi *bnapi = bn->bnapi[i];
84+
struct bnge_nq_ring_info *nqr = &bnapi->nq_ring;
85+
86+
nqr->stats.len = size;
87+
rc = bnge_alloc_stats_mem(bn, &nqr->stats);
88+
if (rc)
89+
goto err_free_ring_stats;
90+
91+
nqr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
92+
}
93+
return 0;
94+
95+
err_free_ring_stats:
96+
bnge_free_ring_stats(bn);
97+
return rc;
98+
}
99+
33100
static void bnge_free_nq_desc_arr(struct bnge_nq_ring_info *nqr)
34101
{
35102
struct bnge_ring_struct *ring = &nqr->ring_struct;
@@ -651,6 +718,7 @@ static void bnge_free_core(struct bnge_net *bn)
651718
bnge_free_rx_rings(bn);
652719
bnge_free_nq_tree(bn);
653720
bnge_free_nq_arrays(bn);
721+
bnge_free_ring_stats(bn);
654722
bnge_free_ring_grps(bn);
655723
bnge_free_vnics(bn);
656724
kfree(bn->tx_ring_map);
@@ -739,6 +807,10 @@ static int bnge_alloc_core(struct bnge_net *bn)
739807
txr->bnapi = bnapi2;
740808
}
741809

810+
rc = bnge_alloc_ring_stats(bn);
811+
if (rc)
812+
goto err_free_core;
813+
742814
rc = bnge_alloc_vnics(bn);
743815
if (rc)
744816
goto err_free_core;
@@ -1189,6 +1261,11 @@ static int bnge_setup_interrupts(struct bnge_net *bn)
11891261
return netif_set_real_num_queues(dev, bd->tx_nr_rings, bd->rx_nr_rings);
11901262
}
11911263

1264+
static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path)
1265+
{
1266+
bnge_hwrm_stat_ctx_free(bn);
1267+
}
1268+
11921269
static void bnge_free_irq(struct bnge_net *bn)
11931270
{
11941271
struct bnge_dev *bd = bn->bd;
@@ -1256,6 +1333,25 @@ static int bnge_request_irq(struct bnge_net *bn)
12561333
return rc;
12571334
}
12581335

1336+
static int bnge_init_chip(struct bnge_net *bn)
1337+
{
1338+
int rc;
1339+
1340+
#define BNGE_DEF_STATS_COAL_TICKS 1000000
1341+
bn->stats_coal_ticks = BNGE_DEF_STATS_COAL_TICKS;
1342+
1343+
rc = bnge_hwrm_stat_ctx_alloc(bn);
1344+
if (rc) {
1345+
netdev_err(bn->netdev, "hwrm stat ctx alloc failure rc: %d\n", rc);
1346+
goto err_out;
1347+
}
1348+
return 0;
1349+
1350+
err_out:
1351+
bnge_hwrm_resource_free(bn, 0);
1352+
return rc;
1353+
}
1354+
12591355
static int bnge_napi_poll(struct napi_struct *napi, int budget)
12601356
{
12611357
int work_done = 0;
@@ -1317,6 +1413,14 @@ static int bnge_init_nic(struct bnge_net *bn)
13171413
goto err_free_rx_ring_pair_bufs;
13181414

13191415
bnge_init_vnics(bn);
1416+
1417+
rc = bnge_init_chip(bn);
1418+
if (rc)
1419+
goto err_free_ring_grps;
1420+
return rc;
1421+
1422+
err_free_ring_grps:
1423+
bnge_free_ring_grps(bn);
13201424
return rc;
13211425

13221426
err_free_rx_ring_pair_bufs:

drivers/net/ethernet/broadcom/bnge/bnge_netdev.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct bnge_net {
225225
u8 rss_hash_key[HW_HASH_KEY_SIZE];
226226
u8 rss_hash_key_valid:1;
227227
u8 rss_hash_key_updated:1;
228+
u32 stats_coal_ticks;
228229
};
229230

230231
#define BNGE_DEFAULT_RX_RING_SIZE 511
@@ -271,6 +272,14 @@ void bnge_set_ring_params(struct bnge_dev *bd);
271272
txr = (iter < BNGE_MAX_TXR_PER_NAPI - 1) ? \
272273
(bnapi)->tx_ring[++iter] : NULL)
273274

275+
struct bnge_stats_mem {
276+
u64 *sw_stats;
277+
u64 *hw_masks;
278+
void *hw_stats;
279+
dma_addr_t hw_stats_map;
280+
int len;
281+
};
282+
274283
struct bnge_cp_ring_info {
275284
struct bnge_napi *bnapi;
276285
dma_addr_t *desc_mapping;
@@ -286,6 +295,9 @@ struct bnge_nq_ring_info {
286295
struct nqe_cn **desc_ring;
287296
struct bnge_ring_struct ring_struct;
288297

298+
struct bnge_stats_mem stats;
299+
u32 hw_stats_ctx_id;
300+
289301
int cp_ring_count;
290302
struct bnge_cp_ring_info *cp_ring_arr;
291303
};

0 commit comments

Comments
 (0)