702-v5.19-07-net-ethernet-mtk_eth_soc-allocate-struct-mtk_ppe-sep.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. From: Felix Fietkau <[email protected]>
  2. Date: Mon, 21 Feb 2022 15:38:20 +0100
  3. Subject: [PATCH] net: ethernet: mtk_eth_soc: allocate struct mtk_ppe
  4. separately
  5. Preparation for adding more data to it, which will increase its size.
  6. Signed-off-by: Felix Fietkau <[email protected]>
  7. ---
  8. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  9. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  10. @@ -2348,7 +2348,7 @@ static int mtk_open(struct net_device *d
  11. return err;
  12. }
  13. - if (eth->soc->offload_version && mtk_ppe_start(&eth->ppe) == 0)
  14. + if (eth->soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
  15. gdm_config = MTK_GDMA_TO_PPE;
  16. mtk_gdm_config(eth, gdm_config);
  17. @@ -2422,7 +2422,7 @@ static int mtk_stop(struct net_device *d
  18. mtk_dma_free(eth);
  19. if (eth->soc->offload_version)
  20. - mtk_ppe_stop(&eth->ppe);
  21. + mtk_ppe_stop(eth->ppe);
  22. return 0;
  23. }
  24. @@ -3307,10 +3307,11 @@ static int mtk_probe(struct platform_dev
  25. }
  26. if (eth->soc->offload_version) {
  27. - err = mtk_ppe_init(&eth->ppe, eth->dev,
  28. - eth->base + MTK_ETH_PPE_BASE, 2);
  29. - if (err)
  30. + eth->ppe = mtk_ppe_init(eth->dev, eth->base + MTK_ETH_PPE_BASE, 2);
  31. + if (!eth->ppe) {
  32. + err = -ENOMEM;
  33. goto err_free_dev;
  34. + }
  35. err = mtk_eth_offload_init(eth);
  36. if (err)
  37. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  38. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  39. @@ -983,7 +983,7 @@ struct mtk_eth {
  40. u32 rx_dma_l4_valid;
  41. int ip_align;
  42. - struct mtk_ppe ppe;
  43. + struct mtk_ppe *ppe;
  44. struct rhashtable flow_table;
  45. };
  46. --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
  47. +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
  48. @@ -384,10 +384,15 @@ int mtk_foe_entry_commit(struct mtk_ppe
  49. return hash;
  50. }
  51. -int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
  52. +struct mtk_ppe *mtk_ppe_init(struct device *dev, void __iomem *base,
  53. int version)
  54. {
  55. struct mtk_foe_entry *foe;
  56. + struct mtk_ppe *ppe;
  57. +
  58. + ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
  59. + if (!ppe)
  60. + return NULL;
  61. /* need to allocate a separate device, since it PPE DMA access is
  62. * not coherent.
  63. @@ -399,13 +404,13 @@ int mtk_ppe_init(struct mtk_ppe *ppe, st
  64. foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
  65. &ppe->foe_phys, GFP_KERNEL);
  66. if (!foe)
  67. - return -ENOMEM;
  68. + return NULL;
  69. ppe->foe_table = foe;
  70. mtk_ppe_debugfs_init(ppe);
  71. - return 0;
  72. + return ppe;
  73. }
  74. static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
  75. --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
  76. +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
  77. @@ -246,8 +246,7 @@ struct mtk_ppe {
  78. void *acct_table;
  79. };
  80. -int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
  81. - int version);
  82. +struct mtk_ppe *mtk_ppe_init(struct device *dev, void __iomem *base, int version);
  83. int mtk_ppe_start(struct mtk_ppe *ppe);
  84. int mtk_ppe_stop(struct mtk_ppe *ppe);
  85. --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
  86. +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
  87. @@ -411,7 +411,7 @@ mtk_flow_offload_replace(struct mtk_eth
  88. entry->cookie = f->cookie;
  89. timestamp = mtk_eth_timestamp(eth);
  90. - hash = mtk_foe_entry_commit(&eth->ppe, &foe, timestamp);
  91. + hash = mtk_foe_entry_commit(eth->ppe, &foe, timestamp);
  92. if (hash < 0) {
  93. err = hash;
  94. goto free;
  95. @@ -426,7 +426,7 @@ mtk_flow_offload_replace(struct mtk_eth
  96. return 0;
  97. clear_flow:
  98. - mtk_foe_entry_clear(&eth->ppe, hash);
  99. + mtk_foe_entry_clear(eth->ppe, hash);
  100. free:
  101. kfree(entry);
  102. if (wed_index >= 0)
  103. @@ -444,7 +444,7 @@ mtk_flow_offload_destroy(struct mtk_eth
  104. if (!entry)
  105. return -ENOENT;
  106. - mtk_foe_entry_clear(&eth->ppe, entry->hash);
  107. + mtk_foe_entry_clear(eth->ppe, entry->hash);
  108. rhashtable_remove_fast(&eth->flow_table, &entry->node,
  109. mtk_flow_ht_params);
  110. if (entry->wed_index >= 0)
  111. @@ -466,7 +466,7 @@ mtk_flow_offload_stats(struct mtk_eth *e
  112. if (!entry)
  113. return -ENOENT;
  114. - timestamp = mtk_foe_entry_timestamp(&eth->ppe, entry->hash);
  115. + timestamp = mtk_foe_entry_timestamp(eth->ppe, entry->hash);
  116. if (timestamp < 0)
  117. return -ETIMEDOUT;
  118. @@ -522,7 +522,7 @@ mtk_eth_setup_tc_block(struct net_device
  119. struct flow_block_cb *block_cb;
  120. flow_setup_cb_t *cb;
  121. - if (!eth->ppe.foe_table)
  122. + if (!eth->ppe || !eth->ppe->foe_table)
  123. return -EOPNOTSUPP;
  124. if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  125. @@ -575,7 +575,7 @@ int mtk_eth_setup_tc(struct net_device *
  126. int mtk_eth_offload_init(struct mtk_eth *eth)
  127. {
  128. - if (!eth->ppe.foe_table)
  129. + if (!eth->ppe || !eth->ppe->foe_table)
  130. return 0;
  131. return rhashtable_init(&eth->flow_table, &mtk_flow_ht_params);