714-v6.0-net-ethernet-mtk_eth_soc-move-ppe-table-hash-offset-.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. From patchwork Thu Sep 8 19:33:38 2022
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. X-Patchwork-Submitter: Lorenzo Bianconi <[email protected]>
  6. X-Patchwork-Id: 12970557
  7. X-Patchwork-Delegate: [email protected]
  8. From: Lorenzo Bianconi <[email protected]>
  9. To: [email protected]
  10. Cc: [email protected], [email protected], [email protected],
  11. [email protected], [email protected], [email protected],
  12. [email protected], [email protected], [email protected],
  13. [email protected], [email protected],
  14. [email protected], [email protected],
  15. [email protected], [email protected],
  16. [email protected], [email protected]
  17. Subject: [PATCH net-next 04/12] net: ethernet: mtk_eth_soc: move ppe table
  18. hash offset to mtk_soc_data structure
  19. Date: Thu, 8 Sep 2022 21:33:38 +0200
  20. Message-Id:
  21. <cc263ffeaa3e1d7314e36a4f941e96d38e41a6bf.1662661555.git.lorenzo@kernel.org>
  22. X-Mailer: git-send-email 2.37.3
  23. In-Reply-To: <[email protected]>
  24. References: <[email protected]>
  25. MIME-Version: 1.0
  26. Precedence: bulk
  27. List-ID: <netdev.vger.kernel.org>
  28. X-Mailing-List: [email protected]
  29. X-Patchwork-Delegate: [email protected]
  30. This is a preliminary patch to introduce mt7986 hw packet engine.
  31. Co-developed-by: Bo Jiao <[email protected]>
  32. Signed-off-by: Bo Jiao <[email protected]>
  33. Co-developed-by: Sujuan Chen <[email protected]>
  34. Signed-off-by: Sujuan Chen <[email protected]>
  35. Signed-off-by: Lorenzo Bianconi <[email protected]>
  36. ---
  37. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
  38. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
  39. drivers/net/ethernet/mediatek/mtk_ppe.c | 24 +++++++++++++++------
  40. drivers/net/ethernet/mediatek/mtk_ppe.h | 2 +-
  41. 4 files changed, 25 insertions(+), 7 deletions(-)
  42. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  43. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  44. @@ -4146,6 +4146,7 @@ static const struct mtk_soc_data mt7621_
  45. .required_clks = MT7621_CLKS_BITMAP,
  46. .required_pctl = false,
  47. .offload_version = 2,
  48. + .hash_offset = 2,
  49. .txrx = {
  50. .txd_size = sizeof(struct mtk_tx_dma),
  51. .rxd_size = sizeof(struct mtk_rx_dma),
  52. @@ -4164,6 +4165,7 @@ static const struct mtk_soc_data mt7622_
  53. .required_clks = MT7622_CLKS_BITMAP,
  54. .required_pctl = false,
  55. .offload_version = 2,
  56. + .hash_offset = 2,
  57. .txrx = {
  58. .txd_size = sizeof(struct mtk_tx_dma),
  59. .rxd_size = sizeof(struct mtk_rx_dma),
  60. @@ -4181,6 +4183,7 @@ static const struct mtk_soc_data mt7623_
  61. .required_clks = MT7623_CLKS_BITMAP,
  62. .required_pctl = true,
  63. .offload_version = 2,
  64. + .hash_offset = 2,
  65. .txrx = {
  66. .txd_size = sizeof(struct mtk_tx_dma),
  67. .rxd_size = sizeof(struct mtk_rx_dma),
  68. @@ -4214,6 +4217,7 @@ static const struct mtk_soc_data mt7986_
  69. .caps = MT7986_CAPS,
  70. .required_clks = MT7986_CLKS_BITMAP,
  71. .required_pctl = false,
  72. + .hash_offset = 4,
  73. .txrx = {
  74. .txd_size = sizeof(struct mtk_tx_dma_v2),
  75. .rxd_size = sizeof(struct mtk_rx_dma_v2),
  76. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  77. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  78. @@ -967,6 +967,7 @@ struct mtk_reg_map {
  79. * the target SoC
  80. * @required_pctl A bool value to show whether the SoC requires
  81. * the extra setup for those pins used by GMAC.
  82. + * @hash_offset Flow table hash offset.
  83. * @txd_size Tx DMA descriptor size.
  84. * @rxd_size Rx DMA descriptor size.
  85. * @rx_irq_done_mask Rx irq done register mask.
  86. @@ -981,6 +982,7 @@ struct mtk_soc_data {
  87. u32 required_clks;
  88. bool required_pctl;
  89. u8 offload_version;
  90. + u8 hash_offset;
  91. netdev_features_t hw_features;
  92. struct {
  93. u32 txd_size;
  94. --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
  95. +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
  96. @@ -88,7 +88,7 @@ static void mtk_ppe_cache_enable(struct
  97. enable * MTK_PPE_CACHE_CTL_EN);
  98. }
  99. -static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
  100. +static u32 mtk_ppe_hash_entry(struct mtk_eth *eth, struct mtk_foe_entry *e)
  101. {
  102. u32 hv1, hv2, hv3;
  103. u32 hash;
  104. @@ -122,7 +122,7 @@ static u32 mtk_ppe_hash_entry(struct mtk
  105. hash = (hash >> 24) | ((hash & 0xffffff) << 8);
  106. hash ^= hv1 ^ hv2 ^ hv3;
  107. hash ^= hash >> 16;
  108. - hash <<= 1;
  109. + hash <<= (ffs(eth->soc->hash_offset) - 1);
  110. hash &= MTK_PPE_ENTRIES - 1;
  111. return hash;
  112. @@ -540,15 +540,16 @@ mtk_foe_entry_commit_l2(struct mtk_ppe *
  113. int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
  114. {
  115. int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->data.ib1);
  116. + const struct mtk_soc_data *soc = ppe->eth->soc;
  117. u32 hash;
  118. if (type == MTK_PPE_PKT_TYPE_BRIDGE)
  119. return mtk_foe_entry_commit_l2(ppe, entry);
  120. - hash = mtk_ppe_hash_entry(&entry->data);
  121. + hash = mtk_ppe_hash_entry(ppe->eth, &entry->data);
  122. entry->hash = 0xffff;
  123. spin_lock_bh(&ppe_lock);
  124. - hlist_add_head(&entry->list, &ppe->foe_flow[hash / 2]);
  125. + hlist_add_head(&entry->list, &ppe->foe_flow[hash / soc->hash_offset]);
  126. spin_unlock_bh(&ppe_lock);
  127. return 0;
  128. @@ -558,6 +559,7 @@ static void
  129. mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
  130. u16 hash)
  131. {
  132. + const struct mtk_soc_data *soc = ppe->eth->soc;
  133. struct mtk_flow_entry *flow_info;
  134. struct mtk_foe_entry foe, *hwe;
  135. struct mtk_foe_mac_info *l2;
  136. @@ -572,7 +574,8 @@ mtk_foe_entry_commit_subflow(struct mtk_
  137. flow_info->l2_data.base_flow = entry;
  138. flow_info->type = MTK_FLOW_TYPE_L2_SUBFLOW;
  139. flow_info->hash = hash;
  140. - hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / 2]);
  141. + hlist_add_head(&flow_info->list,
  142. + &ppe->foe_flow[hash / soc->hash_offset]);
  143. hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
  144. hwe = &ppe->foe_table[hash];
  145. @@ -596,7 +599,8 @@ mtk_foe_entry_commit_subflow(struct mtk_
  146. void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
  147. {
  148. - struct hlist_head *head = &ppe->foe_flow[hash / 2];
  149. + const struct mtk_soc_data *soc = ppe->eth->soc;
  150. + struct hlist_head *head = &ppe->foe_flow[hash / soc->hash_offset];
  151. struct mtk_foe_entry *hwe = &ppe->foe_table[hash];
  152. struct mtk_flow_entry *entry;
  153. struct mtk_foe_bridge key = {};
  154. @@ -680,9 +684,11 @@ int mtk_foe_entry_idle_time(struct mtk_p
  155. struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
  156. int version)
  157. {
  158. + const struct mtk_soc_data *soc = eth->soc;
  159. struct device *dev = eth->dev;
  160. struct mtk_foe_entry *foe;
  161. struct mtk_ppe *ppe;
  162. + u32 foe_flow_size;
  163. ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
  164. if (!ppe)
  165. @@ -705,6 +711,12 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
  166. ppe->foe_table = foe;
  167. + foe_flow_size = (MTK_PPE_ENTRIES / soc->hash_offset) *
  168. + sizeof(*ppe->foe_flow);
  169. + ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL);
  170. + if (!ppe->foe_flow)
  171. + return NULL;
  172. +
  173. mtk_ppe_debugfs_init(ppe);
  174. return ppe;
  175. --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
  176. +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
  177. @@ -270,7 +270,7 @@ struct mtk_ppe {
  178. dma_addr_t foe_phys;
  179. u16 foe_check_time[MTK_PPE_ENTRIES];
  180. - struct hlist_head foe_flow[MTK_PPE_ENTRIES / 2];
  181. + struct hlist_head *foe_flow;
  182. struct rhashtable l2_flows;