Skip to content

Commit f840399

Browse files
shinas-marvellkuba-moo
authored andcommitted
octeon_ep_vf: update tx/rx stats locally for persistence
Update tx/rx stats locally, so that ndo_get_stats64() can use that and not rely on per queue resources to obtain statistics. The latter used to cause race conditions when the device stopped. Signed-off-by: Shinas Rasheed <srasheed@marvell.com> Link: https://patch.msgid.link/20250117094653.2588578-5-srasheed@marvell.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent cc0e510 commit f840399

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_ethtool.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,9 @@ static void octep_vf_get_ethtool_stats(struct net_device *netdev,
114114
iface_tx_stats = &oct->iface_tx_stats;
115115
iface_rx_stats = &oct->iface_rx_stats;
116116

117-
for (q = 0; q < oct->num_oqs; q++) {
118-
struct octep_vf_iq *iq = oct->iq[q];
119-
struct octep_vf_oq *oq = oct->oq[q];
120-
121-
tx_busy_errors += iq->stats.tx_busy;
122-
rx_alloc_errors += oq->stats.alloc_failures;
117+
for (q = 0; q < OCTEP_VF_MAX_QUEUES; q++) {
118+
tx_busy_errors += oct->stats_iq[q].tx_busy;
119+
rx_alloc_errors += oct->stats_oq[q].alloc_failures;
123120
}
124121
i = 0;
125122
data[i++] = rx_alloc_errors;
@@ -134,22 +131,18 @@ static void octep_vf_get_ethtool_stats(struct net_device *netdev,
134131
data[i++] = iface_rx_stats->dropped_octets_fifo_full;
135132

136133
/* Per Tx Queue stats */
137-
for (q = 0; q < oct->num_iqs; q++) {
138-
struct octep_vf_iq *iq = oct->iq[q];
139-
140-
data[i++] = iq->stats.instr_posted;
141-
data[i++] = iq->stats.instr_completed;
142-
data[i++] = iq->stats.bytes_sent;
143-
data[i++] = iq->stats.tx_busy;
134+
for (q = 0; q < OCTEP_VF_MAX_QUEUES; q++) {
135+
data[i++] = oct->stats_iq[q].instr_posted;
136+
data[i++] = oct->stats_iq[q].instr_completed;
137+
data[i++] = oct->stats_iq[q].bytes_sent;
138+
data[i++] = oct->stats_iq[q].tx_busy;
144139
}
145140

146141
/* Per Rx Queue stats */
147142
for (q = 0; q < oct->num_oqs; q++) {
148-
struct octep_vf_oq *oq = oct->oq[q];
149-
150-
data[i++] = oq->stats.packets;
151-
data[i++] = oq->stats.bytes;
152-
data[i++] = oq->stats.alloc_failures;
143+
data[i++] = oct->stats_oq[q].packets;
144+
data[i++] = oct->stats_oq[q].bytes;
145+
data[i++] = oct->stats_oq[q].alloc_failures;
153146
}
154147
}
155148

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ static int octep_vf_iq_full_check(struct octep_vf_iq *iq)
574574
* caused queues to get re-enabled after
575575
* being stopped
576576
*/
577-
iq->stats.restart_cnt++;
577+
iq->stats->restart_cnt++;
578578
fallthrough;
579579
case 1: /* Queue left enabled, since IQ is not yet full*/
580580
return 0;
@@ -731,7 +731,7 @@ static netdev_tx_t octep_vf_start_xmit(struct sk_buff *skb,
731731
/* Flush the hw descriptors before writing to doorbell */
732732
smp_wmb();
733733
writel(iq->fill_cnt, iq->doorbell_reg);
734-
iq->stats.instr_posted += iq->fill_cnt;
734+
iq->stats->instr_posted += iq->fill_cnt;
735735
iq->fill_cnt = 0;
736736
return NETDEV_TX_OK;
737737
}
@@ -786,14 +786,11 @@ static void octep_vf_get_stats64(struct net_device *netdev,
786786
tx_bytes = 0;
787787
rx_packets = 0;
788788
rx_bytes = 0;
789-
for (q = 0; q < oct->num_oqs; q++) {
790-
struct octep_vf_iq *iq = oct->iq[q];
791-
struct octep_vf_oq *oq = oct->oq[q];
792-
793-
tx_packets += iq->stats.instr_completed;
794-
tx_bytes += iq->stats.bytes_sent;
795-
rx_packets += oq->stats.packets;
796-
rx_bytes += oq->stats.bytes;
789+
for (q = 0; q < OCTEP_VF_MAX_QUEUES; q++) {
790+
tx_packets += oct->stats_iq[q].instr_completed;
791+
tx_bytes += oct->stats_iq[q].bytes_sent;
792+
rx_packets += oct->stats_oq[q].packets;
793+
rx_bytes += oct->stats_oq[q].bytes;
797794
}
798795
stats->tx_packets = tx_packets;
799796
stats->tx_bytes = tx_bytes;

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,17 @@ struct octep_vf_device {
246246
/* Pointers to Octeon Tx queues */
247247
struct octep_vf_iq *iq[OCTEP_VF_MAX_IQ];
248248

249+
/* Per iq stats */
250+
struct octep_vf_iq_stats stats_iq[OCTEP_VF_MAX_IQ];
251+
249252
/* Rx queues (OQ: Output Queue) */
250253
u16 num_oqs;
251254
/* Pointers to Octeon Rx queues */
252255
struct octep_vf_oq *oq[OCTEP_VF_MAX_OQ];
253256

257+
/* Per oq stats */
258+
struct octep_vf_oq_stats stats_oq[OCTEP_VF_MAX_OQ];
259+
254260
/* Hardware port number of the PCIe interface */
255261
u16 pcie_port;
256262

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int octep_vf_oq_refill(struct octep_vf_device *oct, struct octep_vf_oq *o
8787
page = dev_alloc_page();
8888
if (unlikely(!page)) {
8989
dev_err(oq->dev, "refill: rx buffer alloc failed\n");
90-
oq->stats.alloc_failures++;
90+
oq->stats->alloc_failures++;
9191
break;
9292
}
9393

@@ -98,7 +98,7 @@ static int octep_vf_oq_refill(struct octep_vf_device *oct, struct octep_vf_oq *o
9898
"OQ-%d buffer refill: DMA mapping error!\n",
9999
oq->q_no);
100100
put_page(page);
101-
oq->stats.alloc_failures++;
101+
oq->stats->alloc_failures++;
102102
break;
103103
}
104104
oq->buff_info[refill_idx].page = page;
@@ -134,6 +134,7 @@ static int octep_vf_setup_oq(struct octep_vf_device *oct, int q_no)
134134
oq->netdev = oct->netdev;
135135
oq->dev = &oct->pdev->dev;
136136
oq->q_no = q_no;
137+
oq->stats = &oct->stats_oq[q_no];
137138
oq->max_count = CFG_GET_OQ_NUM_DESC(oct->conf);
138139
oq->ring_size_mask = oq->max_count - 1;
139140
oq->buffer_size = CFG_GET_OQ_BUF_SIZE(oct->conf);
@@ -458,8 +459,8 @@ static int __octep_vf_oq_process_rx(struct octep_vf_device *oct,
458459

459460
oq->host_read_idx = read_idx;
460461
oq->refill_count += desc_used;
461-
oq->stats.packets += pkt;
462-
oq->stats.bytes += rx_bytes;
462+
oq->stats->packets += pkt;
463+
oq->stats->bytes += rx_bytes;
463464

464465
return pkt;
465466
}

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ struct octep_vf_oq {
187187
u8 __iomem *pkts_sent_reg;
188188

189189
/* Statistics for this OQ. */
190-
struct octep_vf_oq_stats stats;
190+
struct octep_vf_oq_stats *stats;
191191

192192
/* Packets pending to be processed */
193193
u32 pkts_pending;

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ int octep_vf_iq_process_completions(struct octep_vf_iq *iq, u16 budget)
8282
}
8383

8484
iq->pkts_processed += compl_pkts;
85-
iq->stats.instr_completed += compl_pkts;
86-
iq->stats.bytes_sent += compl_bytes;
87-
iq->stats.sgentry_sent += compl_sg;
85+
iq->stats->instr_completed += compl_pkts;
86+
iq->stats->bytes_sent += compl_bytes;
87+
iq->stats->sgentry_sent += compl_sg;
8888
iq->flush_index = fi;
8989

9090
netif_subqueue_completed_wake(iq->netdev, iq->q_no, compl_pkts,
@@ -186,6 +186,7 @@ static int octep_vf_setup_iq(struct octep_vf_device *oct, int q_no)
186186
iq->netdev = oct->netdev;
187187
iq->dev = &oct->pdev->dev;
188188
iq->q_no = q_no;
189+
iq->stats = &oct->stats_iq[q_no];
189190
iq->max_count = CFG_GET_IQ_NUM_DESC(oct->conf);
190191
iq->ring_size_mask = iq->max_count - 1;
191192
iq->fill_threshold = CFG_GET_IQ_DB_MIN(oct->conf);

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct octep_vf_iq {
129129
u16 flush_index;
130130

131131
/* Statistics for this input queue. */
132-
struct octep_vf_iq_stats stats;
132+
struct octep_vf_iq_stats *stats;
133133

134134
/* Pointer to the Virtual Base addr of the input ring. */
135135
struct octep_vf_tx_desc_hw *desc_ring;

0 commit comments

Comments
 (0)