Skip to content

Commit b81e0f2

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: airoha: Add FLOW_CLS_STATS callback support
Introduce per-flow stats accounting to the flowtable hw offload in the airoha_eth driver. Flow stats are split in the PPE and NPU modules: - PPE: accounts for high 32bit of per-flow stats - NPU: accounts for low 32bit of per-flow stats FLOW_CLS_STATS can be enabled or disabled at compile time. Signed-off-by: Lorenzo Bianconi <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c529187 commit b81e0f2

File tree

6 files changed

+354
-20
lines changed

6 files changed

+354
-20
lines changed

drivers/net/ethernet/airoha/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ config NET_AIROHA
2424
This driver supports the gigabit ethernet MACs in the
2525
Airoha SoC family.
2626

27+
config NET_AIROHA_FLOW_STATS
28+
default y
29+
bool "Airoha flow stats"
30+
depends on NET_AIROHA && NET_AIROHA_NPU
31+
help
32+
Enable Aiorha flowtable statistic counters.
33+
2734
endif #NET_VENDOR_AIROHA

drivers/net/ethernet/airoha/airoha_eth.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
#define PPE_NUM 2
5151
#define PPE1_SRAM_NUM_ENTRIES (8 * 1024)
5252
#define PPE_SRAM_NUM_ENTRIES (2 * PPE1_SRAM_NUM_ENTRIES)
53+
#ifdef CONFIG_NET_AIROHA_FLOW_STATS
54+
#define PPE1_STATS_NUM_ENTRIES (4 * 1024)
55+
#else
56+
#define PPE1_STATS_NUM_ENTRIES 0
57+
#endif /* CONFIG_NET_AIROHA_FLOW_STATS */
58+
#define PPE_STATS_NUM_ENTRIES (2 * PPE1_STATS_NUM_ENTRIES)
59+
#define PPE1_SRAM_NUM_DATA_ENTRIES (PPE1_SRAM_NUM_ENTRIES - PPE1_STATS_NUM_ENTRIES)
60+
#define PPE_SRAM_NUM_DATA_ENTRIES (2 * PPE1_SRAM_NUM_DATA_ENTRIES)
5361
#define PPE_DRAM_NUM_ENTRIES (16 * 1024)
5462
#define PPE_NUM_ENTRIES (PPE_SRAM_NUM_ENTRIES + PPE_DRAM_NUM_ENTRIES)
5563
#define PPE_HASH_MASK (PPE_NUM_ENTRIES - 1)
@@ -261,6 +269,8 @@ struct airoha_foe_mac_info {
261269

262270
u16 pppoe_id;
263271
u16 src_mac_lo;
272+
273+
u32 meter;
264274
};
265275

266276
#define AIROHA_FOE_IB1_UNBIND_PREBIND BIT(24)
@@ -296,6 +306,11 @@ struct airoha_foe_mac_info {
296306
#define AIROHA_FOE_TUNNEL BIT(6)
297307
#define AIROHA_FOE_TUNNEL_ID GENMASK(5, 0)
298308

309+
#define AIROHA_FOE_TUNNEL_MTU GENMASK(31, 16)
310+
#define AIROHA_FOE_ACNT_GRP3 GENMASK(15, 9)
311+
#define AIROHA_FOE_METER_GRP3 GENMASK(8, 5)
312+
#define AIROHA_FOE_METER_GRP2 GENMASK(4, 0)
313+
299314
struct airoha_foe_bridge {
300315
u32 dest_mac_hi;
301316

@@ -379,6 +394,8 @@ struct airoha_foe_ipv6 {
379394
u32 ib2;
380395

381396
struct airoha_foe_mac_info_common l2;
397+
398+
u32 meter;
382399
};
383400

384401
struct airoha_foe_entry {
@@ -397,6 +414,16 @@ struct airoha_foe_entry {
397414
};
398415
};
399416

417+
struct airoha_foe_stats {
418+
u32 bytes;
419+
u32 packets;
420+
};
421+
422+
struct airoha_foe_stats64 {
423+
u64 bytes;
424+
u64 packets;
425+
};
426+
400427
struct airoha_flow_data {
401428
struct ethhdr eth;
402429

@@ -447,6 +474,7 @@ struct airoha_flow_table_entry {
447474
struct hlist_node l2_subflow_node; /* PPE L2 subflow entry */
448475
u32 hash;
449476

477+
struct airoha_foe_stats64 stats;
450478
enum airoha_flow_entry_type type;
451479

452480
struct rhash_head node;
@@ -523,6 +551,9 @@ struct airoha_ppe {
523551
struct hlist_head *foe_flow;
524552
u16 foe_check_time[PPE_NUM_ENTRIES];
525553

554+
struct airoha_foe_stats *foe_stats;
555+
dma_addr_t foe_stats_dma;
556+
526557
struct dentry *debugfs_dir;
527558
};
528559

@@ -582,6 +613,8 @@ int airoha_ppe_init(struct airoha_eth *eth);
582613
void airoha_ppe_deinit(struct airoha_eth *eth);
583614
struct airoha_foe_entry *airoha_ppe_foe_get_entry(struct airoha_ppe *ppe,
584615
u32 hash);
616+
void airoha_ppe_foe_entry_get_stats(struct airoha_ppe *ppe, u32 hash,
617+
struct airoha_foe_stats64 *stats);
585618

586619
#ifdef CONFIG_DEBUG_FS
587620
int airoha_ppe_debugfs_init(struct airoha_ppe *ppe);

drivers/net/ethernet/airoha/airoha_npu.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/of_reserved_mem.h>
1313
#include <linux/regmap.h>
1414

15+
#include "airoha_eth.h"
1516
#include "airoha_npu.h"
1617

1718
#define NPU_EN7581_FIRMWARE_DATA "airoha/en7581_npu_data.bin"
@@ -72,6 +73,7 @@ enum {
7273
PPE_FUNC_SET_WAIT_HWNAT_INIT,
7374
PPE_FUNC_SET_WAIT_HWNAT_DEINIT,
7475
PPE_FUNC_SET_WAIT_API,
76+
PPE_FUNC_SET_WAIT_FLOW_STATS_SETUP,
7577
};
7678

7779
enum {
@@ -115,6 +117,10 @@ struct ppe_mbox_data {
115117
u32 size;
116118
u32 data;
117119
} set_info;
120+
struct {
121+
u32 npu_stats_addr;
122+
u32 foe_stats_addr;
123+
} stats_info;
118124
};
119125
};
120126

@@ -351,7 +357,40 @@ static int airoha_npu_foe_commit_entry(struct airoha_npu *npu,
351357
return err;
352358
}
353359

354-
struct airoha_npu *airoha_npu_get(struct device *dev)
360+
static int airoha_npu_stats_setup(struct airoha_npu *npu,
361+
dma_addr_t foe_stats_addr)
362+
{
363+
int err, size = PPE_STATS_NUM_ENTRIES * sizeof(*npu->stats);
364+
struct ppe_mbox_data *ppe_data;
365+
366+
if (!size) /* flow stats are disabled */
367+
return 0;
368+
369+
ppe_data = kzalloc(sizeof(*ppe_data), GFP_ATOMIC);
370+
if (!ppe_data)
371+
return -ENOMEM;
372+
373+
ppe_data->func_type = NPU_OP_SET;
374+
ppe_data->func_id = PPE_FUNC_SET_WAIT_FLOW_STATS_SETUP;
375+
ppe_data->stats_info.foe_stats_addr = foe_stats_addr;
376+
377+
err = airoha_npu_send_msg(npu, NPU_FUNC_PPE, ppe_data,
378+
sizeof(*ppe_data));
379+
if (err)
380+
goto out;
381+
382+
npu->stats = devm_ioremap(npu->dev,
383+
ppe_data->stats_info.npu_stats_addr,
384+
size);
385+
if (!npu->stats)
386+
err = -ENOMEM;
387+
out:
388+
kfree(ppe_data);
389+
390+
return err;
391+
}
392+
393+
struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr)
355394
{
356395
struct platform_device *pdev;
357396
struct device_node *np;
@@ -389,6 +428,17 @@ struct airoha_npu *airoha_npu_get(struct device *dev)
389428
goto error_module_put;
390429
}
391430

431+
if (stats_addr) {
432+
int err;
433+
434+
err = airoha_npu_stats_setup(npu, *stats_addr);
435+
if (err) {
436+
dev_err(dev, "failed to allocate npu stats buffer\n");
437+
npu = ERR_PTR(err);
438+
goto error_module_put;
439+
}
440+
}
441+
392442
return npu;
393443

394444
error_module_put:

drivers/net/ethernet/airoha/airoha_npu.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct airoha_npu {
1717
struct work_struct wdt_work;
1818
} cores[NPU_NUM_CORES];
1919

20+
struct airoha_foe_stats __iomem *stats;
21+
2022
struct {
2123
int (*ppe_init)(struct airoha_npu *npu);
2224
int (*ppe_deinit)(struct airoha_npu *npu);
@@ -30,5 +32,5 @@ struct airoha_npu {
3032
} ops;
3133
};
3234

33-
struct airoha_npu *airoha_npu_get(struct device *dev);
35+
struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr);
3436
void airoha_npu_put(struct airoha_npu *npu);

0 commit comments

Comments
 (0)