Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: airoha: npu: Add a NPU callback to initialize flow stats

Introduce a NPU callback to initialize flow stats and remove NPU stats
initialization from airoha_npu_get routine. Add num_stats_entries to
airoha_npu_ppe_stats_setup routine.
This patch makes the code more readable since NPU statistic are now
initialized on demand by the NPU consumer (at the moment NPU statistic
are configured just by the airoha_eth driver).
Moreover this patch allows the NPU consumer (PPE module) to explicitly
enable/disable NPU flow stats.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250924-airoha-npu-init-stats-callback-v1-1-88bdf3c941b2@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Lorenzo Bianconi and committed by
Jakub Kicinski
105ce7ad 20a2e46f

+23 -27
+6 -18
drivers/net/ethernet/airoha/airoha_npu.c
··· 379 379 return err; 380 380 } 381 381 382 - static int airoha_npu_stats_setup(struct airoha_npu *npu, 383 - dma_addr_t foe_stats_addr) 382 + static int airoha_npu_ppe_stats_setup(struct airoha_npu *npu, 383 + dma_addr_t foe_stats_addr, 384 + u32 num_stats_entries) 384 385 { 385 - int err, size = PPE_STATS_NUM_ENTRIES * sizeof(*npu->stats); 386 + int err, size = num_stats_entries * sizeof(*npu->stats); 386 387 struct ppe_mbox_data *ppe_data; 387 - 388 - if (!size) /* flow stats are disabled */ 389 - return 0; 390 388 391 389 ppe_data = kzalloc(sizeof(*ppe_data), GFP_ATOMIC); 392 390 if (!ppe_data) ··· 540 542 regmap_clear_bits(npu->regmap, REG_IRQ_RXDONE(q), NPU_IRQ_RX_MASK(q)); 541 543 } 542 544 543 - struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr) 545 + struct airoha_npu *airoha_npu_get(struct device *dev) 544 546 { 545 547 struct platform_device *pdev; 546 548 struct device_node *np; ··· 577 579 dev_name(dev)); 578 580 npu = ERR_PTR(-EINVAL); 579 581 goto error_module_put; 580 - } 581 - 582 - if (stats_addr) { 583 - int err; 584 - 585 - err = airoha_npu_stats_setup(npu, *stats_addr); 586 - if (err) { 587 - dev_err(dev, "failed to allocate npu stats buffer\n"); 588 - npu = ERR_PTR(err); 589 - goto error_module_put; 590 - } 591 582 } 592 583 593 584 return npu; ··· 630 643 npu->dev = dev; 631 644 npu->ops.ppe_init = airoha_npu_ppe_init; 632 645 npu->ops.ppe_deinit = airoha_npu_ppe_deinit; 646 + npu->ops.ppe_init_stats = airoha_npu_ppe_stats_setup; 633 647 npu->ops.ppe_flush_sram_entries = airoha_npu_ppe_flush_sram_entries; 634 648 npu->ops.ppe_foe_commit_entry = airoha_npu_foe_commit_entry; 635 649 npu->ops.wlan_init_reserved_memory = airoha_npu_wlan_init_memory;
+13 -6
drivers/net/ethernet/airoha/airoha_ppe.c
··· 1243 1243 1244 1244 static struct airoha_npu *airoha_ppe_npu_get(struct airoha_eth *eth) 1245 1245 { 1246 - struct airoha_npu *npu = airoha_npu_get(eth->dev, 1247 - &eth->ppe->foe_stats_dma); 1246 + struct airoha_npu *npu = airoha_npu_get(eth->dev); 1248 1247 1249 1248 if (IS_ERR(npu)) { 1250 1249 request_module("airoha-npu"); 1251 - npu = airoha_npu_get(eth->dev, &eth->ppe->foe_stats_dma); 1250 + npu = airoha_npu_get(eth->dev); 1252 1251 } 1253 1252 1254 1253 return npu; ··· 1256 1257 static int airoha_ppe_offload_setup(struct airoha_eth *eth) 1257 1258 { 1258 1259 struct airoha_npu *npu = airoha_ppe_npu_get(eth); 1260 + struct airoha_ppe *ppe = eth->ppe; 1259 1261 int err; 1260 1262 1261 1263 if (IS_ERR(npu)) ··· 1266 1266 if (err) 1267 1267 goto error_npu_put; 1268 1268 1269 - airoha_ppe_hw_init(eth->ppe); 1270 - err = airoha_ppe_flush_sram_entries(eth->ppe, npu); 1269 + if (PPE_STATS_NUM_ENTRIES) { 1270 + err = npu->ops.ppe_init_stats(npu, ppe->foe_stats_dma, 1271 + PPE_STATS_NUM_ENTRIES); 1272 + if (err) 1273 + goto error_npu_put; 1274 + } 1275 + 1276 + airoha_ppe_hw_init(ppe); 1277 + err = airoha_ppe_flush_sram_entries(ppe, npu); 1271 1278 if (err) 1272 1279 goto error_npu_put; 1273 1280 1274 - airoha_ppe_foe_flow_stats_reset(eth->ppe, npu); 1281 + airoha_ppe_foe_flow_stats_reset(ppe, npu); 1275 1282 1276 1283 rcu_assign_pointer(eth->npu, npu); 1277 1284 synchronize_rcu();
+4 -3
include/linux/soc/airoha/airoha_offload.h
··· 181 181 struct { 182 182 int (*ppe_init)(struct airoha_npu *npu); 183 183 int (*ppe_deinit)(struct airoha_npu *npu); 184 + int (*ppe_init_stats)(struct airoha_npu *npu, 185 + dma_addr_t addr, u32 num_stats_entries); 184 186 int (*ppe_flush_sram_entries)(struct airoha_npu *npu, 185 187 dma_addr_t foe_addr, 186 188 int sram_num_entries); ··· 208 206 }; 209 207 210 208 #if (IS_BUILTIN(CONFIG_NET_AIROHA_NPU) || IS_MODULE(CONFIG_NET_AIROHA_NPU)) 211 - struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr); 209 + struct airoha_npu *airoha_npu_get(struct device *dev); 212 210 void airoha_npu_put(struct airoha_npu *npu); 213 211 214 212 static inline int airoha_npu_wlan_init_reserved_memory(struct airoha_npu *npu) ··· 258 256 npu->ops.wlan_disable_irq(npu, q); 259 257 } 260 258 #else 261 - static inline struct airoha_npu *airoha_npu_get(struct device *dev, 262 - dma_addr_t *foe_stats_addr) 259 + static inline struct airoha_npu *airoha_npu_get(struct device *dev) 263 260 { 264 261 return NULL; 265 262 }