developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 1 | From e2277f2ea6c9657b727b082f7baa967ef94861dc Mon Sep 17 00:00:00 2001 |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 2 | From: Bo-Cun Chen <bc-bocun.chen@mediatek.com> |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 3 | Date: Sat, 26 Aug 2023 00:38:09 +0800 |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 4 | Subject: [PATCH] 999-3014-flow-offload-add-mtkhnat-qdma-qos |
| 5 | |
| 6 | --- |
| 7 | drivers/net/ethernet/mediatek/Makefile | 2 +- |
| 8 | drivers/net/ethernet/mediatek/mtk_eth_soc.c | 10 + |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 9 | drivers/net/ethernet/mediatek/mtk_eth_soc.h | 63 ++- |
| 10 | drivers/net/ethernet/mediatek/mtk_ppe.c | 48 +- |
| 11 | drivers/net/ethernet/mediatek/mtk_ppe.h | 4 + |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 12 | .../net/ethernet/mediatek/mtk_ppe_offload.c | 28 +- |
| 13 | .../net/ethernet/mediatek/mtk_qdma_debugfs.c | 439 ++++++++++++++++++ |
| 14 | include/net/flow_offload.h | 1 + |
| 15 | net/netfilter/nf_flow_table_offload.c | 4 +- |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 16 | 9 files changed, 593 insertions(+), 6 deletions(-) |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 17 | create mode 100644 drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c |
| 18 | |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 19 | diff --git a/drivers/net/ethernet/mediatek/Makefile b/drivers/net/ethernet/mediatek/Makefile |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 20 | index fdbb90f..c7d2296 100644 |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 21 | --- a/drivers/net/ethernet/mediatek/Makefile |
| 22 | +++ b/drivers/net/ethernet/mediatek/Makefile |
| 23 | @@ -5,7 +5,7 @@ |
| 24 | |
| 25 | obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o |
developer | 6883854 | 2022-10-03 23:42:21 +0800 | [diff] [blame] | 26 | mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_usxgmii.o mtk_eth_path.o mtk_eth_dbg.o mtk_eth_reset.o \ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 27 | - mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o |
| 28 | + mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o mtk_qdma_debugfs.o |
| 29 | mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o |
| 30 | ifdef CONFIG_DEBUG_FS |
| 31 | mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o |
| 32 | diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 33 | index 9102144..a370547 100644 |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 34 | --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c |
| 35 | +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 36 | @@ -5085,6 +5085,8 @@ static int mtk_probe(struct platform_device *pdev) |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 37 | } |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 38 | |
| 39 | mtk_ppe_debugfs_init(eth); |
| 40 | + |
| 41 | + mtk_qdma_debugfs_init(eth); |
| 42 | } |
| 43 | |
| 44 | for (i = 0; i < MTK_MAX_DEVS; i++) { |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 45 | @@ -5197,6 +5199,7 @@ static const struct mtk_soc_data mt2701_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 46 | .rx_dma_l4_valid = RX_DMA_L4_VALID, |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 47 | .dma_max_len = MTK_TX_DMA_BUF_LEN, |
| 48 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT, |
| 49 | + .qdma_tx_sch = 2, |
| 50 | }, |
| 51 | }; |
| 52 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 53 | @@ -5217,6 +5220,7 @@ static const struct mtk_soc_data mt7621_data = { |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 54 | .rxd_size = sizeof(struct mtk_rx_dma), |
| 55 | .dma_max_len = MTK_TX_DMA_BUF_LEN, |
| 56 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT, |
| 57 | + .qdma_tx_sch = 2, |
| 58 | }, |
| 59 | }; |
| 60 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 61 | @@ -5238,6 +5242,7 @@ static const struct mtk_soc_data mt7622_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 62 | .rx_dma_l4_valid = RX_DMA_L4_VALID, |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 63 | .dma_max_len = MTK_TX_DMA_BUF_LEN, |
| 64 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT, |
| 65 | + .qdma_tx_sch = 2, |
| 66 | }, |
| 67 | }; |
| 68 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 69 | @@ -5258,6 +5263,7 @@ static const struct mtk_soc_data mt7623_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 70 | .rx_dma_l4_valid = RX_DMA_L4_VALID, |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 71 | .dma_max_len = MTK_TX_DMA_BUF_LEN, |
| 72 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT, |
| 73 | + .qdma_tx_sch = 2, |
| 74 | }, |
| 75 | }; |
| 76 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 77 | @@ -5298,6 +5304,7 @@ static const struct mtk_soc_data mt7986_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 78 | .rx_dma_l4_valid = RX_DMA_L4_VALID_V2, |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 79 | .dma_max_len = MTK_TX_DMA_BUF_LEN_V2, |
| 80 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2, |
| 81 | + .qdma_tx_sch = 4, |
| 82 | }, |
| 83 | }; |
| 84 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 85 | @@ -5319,6 +5326,7 @@ static const struct mtk_soc_data mt7981_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 86 | .rx_dma_l4_valid = RX_DMA_L4_VALID_V2, |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 87 | .dma_max_len = MTK_TX_DMA_BUF_LEN_V2, |
| 88 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2, |
| 89 | + .qdma_tx_sch = 4, |
| 90 | }, |
| 91 | }; |
| 92 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 93 | @@ -5337,6 +5345,7 @@ static const struct mtk_soc_data mt7988_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 94 | .rx_dma_l4_valid = RX_DMA_L4_VALID_V2, |
| 95 | .dma_max_len = MTK_TX_DMA_BUF_LEN_V2, |
| 96 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT_V2, |
| 97 | + .qdma_tx_sch = 4, |
| 98 | }, |
| 99 | }; |
| 100 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 101 | @@ -5355,6 +5364,7 @@ static const struct mtk_soc_data rt5350_data = { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 102 | .rx_dma_l4_valid = RX_DMA_L4_VALID_PDMA, |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 103 | .dma_max_len = MTK_TX_DMA_BUF_LEN, |
| 104 | .dma_len_offset = MTK_TX_DMA_BUF_SHIFT, |
| 105 | + .qdma_tx_sch = 4, |
| 106 | }, |
| 107 | }; |
| 108 | |
| 109 | diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 110 | index db139a1..a7892e2 100644 |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 111 | --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h |
| 112 | +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 113 | @@ -398,10 +398,21 @@ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 114 | |
| 115 | /* QDMA TX Queue Configuration Registers */ |
| 116 | #define MTK_QTX_CFG(x) (QDMA_BASE + (x * 0x10)) |
| 117 | +#define MTK_QTX_CFG_HW_RESV_CNT_OFFSET GENMASK(15, 8) |
| 118 | +#define MTK_QTX_CFG_SW_RESV_CNT_OFFSET GENMASK(7, 0) |
| 119 | #define QDMA_RES_THRES 4 |
| 120 | |
| 121 | /* QDMA TX Queue Scheduler Registers */ |
| 122 | #define MTK_QTX_SCH(x) (QDMA_BASE + 4 + (x * 0x10)) |
| 123 | +#define MTK_QTX_SCH_TX_SCH_SEL BIT(31) |
| 124 | +#define MTK_QTX_SCH_TX_SCH_SEL_V2 GENMASK(31, 30) |
| 125 | +#define MTK_QTX_SCH_MIN_RATE_EN BIT(27) |
| 126 | +#define MTK_QTX_SCH_MIN_RATE_MAN GENMASK(26, 20) |
| 127 | +#define MTK_QTX_SCH_MIN_RATE_EXP GENMASK(19, 16) |
| 128 | +#define MTK_QTX_SCH_MAX_RATE_WGHT GENMASK(15, 12) |
| 129 | +#define MTK_QTX_SCH_MAX_RATE_EN BIT(11) |
| 130 | +#define MTK_QTX_SCH_MAX_RATE_MAN GENMASK(10, 4) |
| 131 | +#define MTK_QTX_SCH_MAX_RATE_EXP GENMASK(3, 0) |
| 132 | |
| 133 | /* QDMA RX Base Pointer Register */ |
| 134 | #define MTK_QRX_BASE_PTR0 (QDMA_BASE + 0x100) |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 135 | @@ -419,7 +430,9 @@ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 136 | #define MTK_QRX_DRX_IDX0 (QDMA_BASE + 0x10c) |
| 137 | |
| 138 | /* QDMA Page Configuration Register */ |
| 139 | -#define MTK_QDMA_PAGE (QDMA_BASE + 0x1f0) |
| 140 | +#define MTK_QDMA_PAGE (QDMA_BASE + 0x1f0) |
| 141 | +#define MTK_QTX_CFG_PAGE GENMASK(3, 0) |
| 142 | +#define MTK_QTX_PER_PAGE (16) |
| 143 | |
| 144 | /* QDMA Global Configuration Register */ |
| 145 | #define MTK_QDMA_GLO_CFG (QDMA_BASE + 0x204) |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 146 | @@ -456,6 +469,9 @@ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 147 | #define FC_THRES_DROP_EN (7 << 16) |
| 148 | #define FC_THRES_MIN 0x4444 |
| 149 | |
| 150 | +/* QDMA TX Scheduler Rate Control Register */ |
| 151 | +#define MTK_QDMA_TX_2SCH_BASE (QDMA_BASE + 0x214) |
| 152 | + |
| 153 | /* QDMA Interrupt Status Register */ |
| 154 | #define MTK_QDMA_INT_STATUS (QDMA_BASE + 0x218) |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 155 | #if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3) |
| 156 | @@ -492,6 +508,11 @@ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 157 | /* QDMA Interrupt Mask Register */ |
| 158 | #define MTK_QDMA_HRED2 (QDMA_BASE + 0x244) |
| 159 | |
| 160 | +/* QDMA TX Queue MIB Interface Register */ |
| 161 | +#define MTK_QTX_MIB_IF (QDMA_BASE + 0x2bc) |
| 162 | +#define MTK_MIB_ON_QTX_CFG BIT(31) |
| 163 | +#define MTK_VQTX_MIB_EN BIT(28) |
| 164 | + |
| 165 | /* QDMA TX Forward CPU Pointer Register */ |
| 166 | #define MTK_QTX_CTX_PTR (QDMA_BASE +0x300) |
| 167 | |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 168 | @@ -519,6 +540,14 @@ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 169 | /* QDMA FQ Free Page Buffer Length Register */ |
| 170 | #define MTK_QDMA_FQ_BLEN (QDMA_BASE +0x32c) |
| 171 | |
| 172 | +/* QDMA TX Scheduler Rate Control Register */ |
| 173 | +#define MTK_QDMA_TX_4SCH_BASE(x) (QDMA_BASE + 0x398 + (((x) >> 1) * 0x4)) |
| 174 | +#define MTK_QDMA_TX_SCH_MASK GENMASK(15, 0) |
| 175 | +#define MTK_QDMA_TX_SCH_MAX_WFQ BIT(15) |
| 176 | +#define MTK_QDMA_TX_SCH_RATE_EN BIT(11) |
| 177 | +#define MTK_QDMA_TX_SCH_RATE_MAN GENMASK(10, 4) |
| 178 | +#define MTK_QDMA_TX_SCH_RATE_EXP GENMASK(3, 0) |
| 179 | + |
| 180 | /* WDMA Registers */ |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 181 | #define MTK_WDMA_CTX_PTR(x) (WDMA_BASE(x) + 0x8) |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 182 | #define MTK_WDMA_DTX_PTR(x) (WDMA_BASE(x) + 0xC) |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 183 | @@ -1682,6 +1711,7 @@ struct mtk_soc_data { |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 184 | u32 rx_dma_l4_valid; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 185 | u32 dma_max_len; |
| 186 | u32 dma_len_offset; |
| 187 | + u32 qdma_tx_sch; |
| 188 | } txrx; |
| 189 | }; |
| 190 | |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 191 | @@ -1868,6 +1898,7 @@ struct mtk_eth { |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 192 | spinlock_t syscfg0_lock; |
| 193 | struct timer_list mtk_dma_monitor_timer; |
| 194 | |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 195 | + u8 qos_toggle; |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 196 | u8 ppe_num; |
| 197 | struct mtk_ppe *ppe[MTK_MAX_PPE_NUM]; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 198 | struct rhashtable flow_table; |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 199 | @@ -1906,6 +1937,34 @@ extern const struct of_device_id of_mtk_match[]; |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 200 | extern u32 mtk_hwlro_stats_ebl; |
| 201 | extern u32 dbg_show_level; |
| 202 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 203 | +static inline void mtk_set_ib1_sp(struct mtk_eth *eth, struct mtk_foe_entry *foe, u32 val) |
| 204 | +{ |
| 205 | + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) |
| 206 | + foe->ib1 |= FIELD_PREP(MTK_FOE_IB1_UNBIND_SRC_PORT, val); |
| 207 | +} |
| 208 | + |
| 209 | +static inline u32 mtk_get_ib1_sp(struct mtk_eth *eth, struct mtk_foe_entry *foe) |
| 210 | +{ |
| 211 | + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) |
| 212 | + return FIELD_GET(MTK_FOE_IB1_UNBIND_SRC_PORT, foe->ib1); |
| 213 | + |
| 214 | + return 0; |
| 215 | +} |
| 216 | + |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 217 | +static inline int |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 218 | +mtk_ppe_check_pppq_path(struct mtk_eth *eth, struct mtk_foe_entry *foe, int dsa_port) |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 219 | +{ |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 220 | + u32 sp = mtk_get_ib1_sp(eth, foe); |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 221 | + |
| 222 | + if ((dsa_port >= 0 && dsa_port <= 4) || |
| 223 | + (dsa_port == 5 && (sp == PSE_WDMA0_PORT || |
| 224 | + sp == PSE_WDMA1_PORT || |
| 225 | + sp == PSE_WDMA2_PORT))) |
| 226 | + return 1; |
| 227 | + |
| 228 | + return 0; |
| 229 | +} |
| 230 | + |
| 231 | /* read the hardware status register */ |
| 232 | void mtk_stats_update_mac(struct mtk_mac *mac); |
| 233 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 234 | @@ -1938,4 +1997,6 @@ void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev); |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 235 | u32 mtk_rss_indr_table(struct mtk_rss_params *rss_params, int index); |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 236 | |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 237 | int mtk_ppe_debugfs_init(struct mtk_eth *eth); |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 238 | + |
developer | 1fb19c9 | 2023-03-07 23:45:23 +0800 | [diff] [blame] | 239 | +int mtk_qdma_debugfs_init(struct mtk_eth *eth); |
| 240 | #endif /* MTK_ETH_H */ |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 241 | diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 242 | index 107f5a1..0d4ae28 100755 |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 243 | --- a/drivers/net/ethernet/mediatek/mtk_ppe.c |
| 244 | +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 245 | @@ -128,7 +128,7 @@ static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable) |
| 246 | enable * MTK_PPE_CACHE_CTL_EN); |
| 247 | } |
| 248 | |
| 249 | -static u32 mtk_ppe_hash_entry(struct mtk_ppe *ppe, struct mtk_foe_entry *e) |
| 250 | +u32 mtk_ppe_hash_entry(struct mtk_ppe *ppe, struct mtk_foe_entry *e) |
| 251 | { |
| 252 | u32 hv1, hv2, hv3; |
| 253 | u32 hash; |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 254 | @@ -420,12 +420,58 @@ int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq, |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | +int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid) |
| 259 | +{ |
| 260 | + u32 *ib2 = mtk_foe_entry_ib2(entry); |
| 261 | + |
| 262 | + *ib2 &= ~MTK_FOE_IB2_QID; |
| 263 | + *ib2 |= FIELD_PREP(MTK_FOE_IB2_QID, qid); |
| 264 | + *ib2 |= MTK_FOE_IB2_PSE_QOS; |
| 265 | + |
| 266 | + return 0; |
| 267 | +} |
| 268 | static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry) |
| 269 | { |
| 270 | return !(entry->ib1 & MTK_FOE_IB1_STATIC) && |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 271 | FIELD_GET(MTK_FOE_IB1_STATE, entry->ib1) != MTK_FOE_STATE_BIND; |
| 272 | } |
| 273 | |
| 274 | +bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data) |
| 275 | +{ |
| 276 | + int type, len; |
| 277 | + |
| 278 | + if ((data->ib1 ^ entry->ib1) & MTK_FOE_IB1_UDP) |
| 279 | + return false; |
| 280 | + |
| 281 | + type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1); |
| 282 | + if (type > MTK_PPE_PKT_TYPE_IPV4_DSLITE) |
| 283 | + len = offsetof(struct mtk_foe_entry, ipv6._rsv); |
| 284 | + else |
| 285 | + len = offsetof(struct mtk_foe_entry, ipv4.ib2); |
| 286 | + |
| 287 | + return !memcmp(&entry->data, &data->data, len - 4); |
| 288 | +} |
| 289 | + |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 290 | +int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry) |
| 291 | +{ |
| 292 | + struct mtk_foe_entry *hwe; |
| 293 | + u32 hash, sp = 0; |
| 294 | + int i; |
| 295 | + |
| 296 | + hash = mtk_ppe_hash_entry(ppe, entry); |
| 297 | + for (i = 0; i < ppe->way; i++) { |
| 298 | + hwe = &ppe->foe_table[hash + i]; |
| 299 | + if (mtk_foe_entry_match(hwe, entry)) { |
| 300 | + sp = mtk_get_ib1_sp(ppe->eth, hwe); |
| 301 | + break; |
| 302 | + } |
| 303 | + } |
| 304 | + |
| 305 | + mtk_set_ib1_sp(ppe->eth, entry, sp); |
| 306 | + |
| 307 | + return 0; |
| 308 | +} |
| 309 | + |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 310 | static bool |
| 311 | mtk_flow_entry_match(struct mtk_flow_entry *entry, struct mtk_foe_entry *data) |
| 312 | { |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 313 | diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 314 | index 86288b0..5ab864f 100644 |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 315 | --- a/drivers/net/ethernet/mediatek/mtk_ppe.h |
| 316 | +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 317 | @@ -403,9 +403,13 @@ int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid); |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 318 | int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid); |
| 319 | int mtk_foe_entry_set_wdma(struct mtk_foe_entry *entry, int wdma_idx, int txq, |
| 320 | int bss, int wcid); |
| 321 | +int mtk_foe_entry_set_qid(struct mtk_foe_entry *entry, int qid); |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 322 | +bool mtk_foe_entry_match(struct mtk_foe_entry *entry, struct mtk_foe_entry *data); |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 323 | +int mtk_foe_entry_set_sp(struct mtk_ppe *ppe, struct mtk_foe_entry *entry); |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 324 | int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry); |
| 325 | void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry); |
| 326 | int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry); |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 327 | struct mtk_foe_accounting *mtk_foe_entry_get_mib(struct mtk_ppe *ppe, u32 index, struct mtk_foe_accounting *diff); |
| 328 | +u32 mtk_ppe_hash_entry(struct mtk_ppe *ppe, struct mtk_foe_entry *e); |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 329 | |
| 330 | #endif |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 331 | diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 332 | index b80f72d..3bc50a4 100755 |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 333 | --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c |
| 334 | +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 335 | @@ -9,6 +9,8 @@ |
| 336 | #include <linux/ipv6.h> |
| 337 | #include <net/flow_offload.h> |
| 338 | #include <net/pkt_cls.h> |
| 339 | +#include <net/netfilter/nf_conntrack.h> |
| 340 | +#include <net/netfilter/nf_flow_table.h> |
| 341 | #include <net/dsa.h> |
| 342 | #include "mtk_eth_soc.h" |
| 343 | #include "mtk_wed.h" |
| 344 | @@ -183,7 +185,7 @@ mtk_flow_get_dsa_port(struct net_device **dev) |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 345 | |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 346 | static int |
| 347 | mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe, |
| 348 | - struct net_device *dev, const u8 *dest_mac, |
| 349 | + struct net_device *dev, struct nf_conn *ct, const u8 *dest_mac, |
| 350 | int *wed_index) |
| 351 | { |
| 352 | struct mtk_wdma_info info = {}; |
developer | f52eda0 | 2023-07-14 09:40:17 +0800 | [diff] [blame] | 353 | @@ -209,6 +211,9 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe, |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 354 | if (dsa_port >= 0) |
developer | f52eda0 | 2023-07-14 09:40:17 +0800 | [diff] [blame] | 355 | mtk_foe_entry_set_dsa(foe, dsa_port); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 356 | |
developer | 64b431b | 2023-08-26 01:04:45 +0800 | [diff] [blame^] | 357 | + if (eth->qos_toggle == 2 && mtk_ppe_check_pppq_path(eth, foe, dsa_port)) |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 358 | + mtk_foe_entry_set_qid(foe, dsa_port & MTK_QDMA_TX_MASK); |
| 359 | + |
| 360 | if (dev == eth->netdev[0]) |
| 361 | pse_port = PSE_GDM1_PORT; |
| 362 | else if (dev == eth->netdev[1]) |
developer | f52eda0 | 2023-07-14 09:40:17 +0800 | [diff] [blame] | 363 | @@ -217,6 +222,23 @@ mtk_flow_set_output_device(struct mtk_eth *eth, struct mtk_foe_entry *foe, |
| 364 | return -EOPNOTSUPP; |
| 365 | |
| 366 | out: |
| 367 | + if (eth->qos_toggle == 1 || (ct->mark & MTK_QDMA_TX_MASK) >= 6) { |
| 368 | + u8 qos_ul_toggle; |
| 369 | + |
| 370 | + if (eth->qos_toggle == 2) |
| 371 | + qos_ul_toggle = ((ct->mark >> 16) & MTK_QDMA_TX_MASK) >= 6 ? 1 : 0; |
| 372 | + else |
| 373 | + qos_ul_toggle = ((ct->mark >> 16) & MTK_QDMA_TX_MASK) >= 1 ? 1 : 0; |
| 374 | + |
| 375 | + if (qos_ul_toggle == 1) { |
| 376 | + if (dev == eth->netdev[1]) |
| 377 | + mtk_foe_entry_set_qid(foe, (ct->mark >> 16) & MTK_QDMA_TX_MASK); |
| 378 | + else |
| 379 | + mtk_foe_entry_set_qid(foe, ct->mark & MTK_QDMA_TX_MASK); |
| 380 | + } else |
| 381 | + mtk_foe_entry_set_qid(foe, ct->mark & MTK_QDMA_TX_MASK); |
| 382 | + } |
| 383 | + |
| 384 | mtk_foe_entry_set_pse_port(foe, pse_port); |
| 385 | |
| 386 | return 0; |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 387 | @@ -447,7 +469,9 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f) |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 388 | if (data.pppoe.num == 1) |
developer | ee39bcf | 2023-06-16 08:03:30 +0800 | [diff] [blame] | 389 | mtk_foe_entry_set_pppoe(&foe, data.pppoe.sid); |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 390 | |
| 391 | - err = mtk_flow_set_output_device(eth, &foe, odev, data.eth.h_dest, |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 392 | + mtk_foe_entry_set_sp(eth->ppe[ppe_index], &foe); |
| 393 | + |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 394 | + err = mtk_flow_set_output_device(eth, &foe, odev, f->flow->ct, data.eth.h_dest, |
| 395 | &wed_index); |
| 396 | if (err) |
| 397 | return err; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 398 | diff --git a/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c b/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c |
| 399 | new file mode 100644 |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 400 | index 0000000..3a7c585 |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 401 | --- /dev/null |
| 402 | +++ b/drivers/net/ethernet/mediatek/mtk_qdma_debugfs.c |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 403 | @@ -0,0 +1,439 @@ |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 404 | +/* SPDX-License-Identifier: GPL-2.0 |
| 405 | + * |
| 406 | + * Copyright (c) 2022 MediaTek Inc. |
| 407 | + * Author: Henry Yen <henry.yen@mediatek.com> |
| 408 | + * Bo-Cun Chen <bc-bocun.chen@mediatek.com> |
| 409 | + */ |
| 410 | + |
| 411 | +#include <linux/kernel.h> |
| 412 | +#include <linux/debugfs.h> |
| 413 | +#include "mtk_eth_soc.h" |
| 414 | + |
| 415 | +#define MAX_PPPQ_PORT_NUM 6 |
| 416 | + |
| 417 | +static struct mtk_eth *_eth; |
| 418 | + |
| 419 | +static void mtk_qdma_qos_shaper_ebl(struct mtk_eth *eth, u32 id, u32 enable) |
| 420 | +{ |
| 421 | + u32 val; |
| 422 | + |
| 423 | + if (enable) { |
| 424 | + val = MTK_QTX_SCH_MIN_RATE_EN | MTK_QTX_SCH_MAX_RATE_EN; |
| 425 | + val |= FIELD_PREP(MTK_QTX_SCH_MIN_RATE_MAN, 1) | |
| 426 | + FIELD_PREP(MTK_QTX_SCH_MIN_RATE_EXP, 4) | |
| 427 | + FIELD_PREP(MTK_QTX_SCH_MAX_RATE_MAN, 25) | |
| 428 | + FIELD_PREP(MTK_QTX_SCH_MAX_RATE_EXP, 5) | |
| 429 | + FIELD_PREP(MTK_QTX_SCH_MAX_RATE_WGHT, 4); |
| 430 | + |
| 431 | + writel(val, eth->base + MTK_QTX_SCH(id % MTK_QTX_PER_PAGE)); |
| 432 | + } else { |
| 433 | + writel(0, eth->base + MTK_QTX_SCH(id % MTK_QTX_PER_PAGE)); |
| 434 | + } |
| 435 | +} |
| 436 | + |
| 437 | +static void mtk_qdma_qos_disable(struct mtk_eth *eth) |
| 438 | +{ |
| 439 | + u32 id, val; |
| 440 | + |
| 441 | + for (id = 0; id < MAX_PPPQ_PORT_NUM; id++) { |
| 442 | + mtk_qdma_qos_shaper_ebl(eth, id, 0); |
| 443 | + |
| 444 | + writel(FIELD_PREP(MTK_QTX_CFG_HW_RESV_CNT_OFFSET, 4) | |
| 445 | + FIELD_PREP(MTK_QTX_CFG_SW_RESV_CNT_OFFSET, 4), |
| 446 | + eth->base + MTK_QTX_CFG(id % MTK_QTX_PER_PAGE)); |
| 447 | + } |
| 448 | + |
| 449 | + val = (MTK_QDMA_TX_SCH_MAX_WFQ) | (MTK_QDMA_TX_SCH_MAX_WFQ << 16); |
| 450 | + for (id = 0; id < eth->soc->txrx.qdma_tx_sch; id += 2) { |
| 451 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
| 452 | + writel(val, eth->base + MTK_QDMA_TX_4SCH_BASE(id)); |
| 453 | + else |
| 454 | + writel(val, eth->base + MTK_QDMA_TX_2SCH_BASE); |
| 455 | + } |
| 456 | +} |
| 457 | + |
| 458 | +static void mtk_qdma_qos_pppq_enable(struct mtk_eth *eth) |
| 459 | +{ |
| 460 | + u32 id, val; |
| 461 | + |
| 462 | + for (id = 0; id < MAX_PPPQ_PORT_NUM; id++) { |
| 463 | + mtk_qdma_qos_shaper_ebl(eth, id, 1); |
| 464 | + |
| 465 | + writel(FIELD_PREP(MTK_QTX_CFG_HW_RESV_CNT_OFFSET, 4) | |
| 466 | + FIELD_PREP(MTK_QTX_CFG_SW_RESV_CNT_OFFSET, 4), |
| 467 | + eth->base + MTK_QTX_CFG(id % MTK_QTX_PER_PAGE)); |
| 468 | + } |
| 469 | + |
| 470 | + val = (MTK_QDMA_TX_SCH_MAX_WFQ) | (MTK_QDMA_TX_SCH_MAX_WFQ << 16); |
| 471 | + for (id = 0; id < eth->soc->txrx.qdma_tx_sch; id+= 2) { |
| 472 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
| 473 | + writel(val, eth->base + MTK_QDMA_TX_4SCH_BASE(id)); |
| 474 | + else |
| 475 | + writel(val, eth->base + MTK_QDMA_TX_2SCH_BASE); |
| 476 | + } |
| 477 | +} |
| 478 | + |
| 479 | + static ssize_t mtk_qmda_debugfs_write_qos(struct file *file, const char __user *buffer, |
| 480 | + size_t count, loff_t *data) |
| 481 | +{ |
| 482 | + struct seq_file *m = file->private_data; |
| 483 | + struct mtk_eth *eth = m->private; |
| 484 | + char buf[8]; |
| 485 | + int len = count; |
| 486 | + |
| 487 | + if ((len > 8) || copy_from_user(buf, buffer, len)) |
| 488 | + return -EFAULT; |
| 489 | + |
| 490 | + if (buf[0] == '0') { |
| 491 | + pr_info("HQoS is going to be disabled !\n"); |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 492 | + eth->qos_toggle = 0; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 493 | + mtk_qdma_qos_disable(eth); |
| 494 | + } else if (buf[0] == '1') { |
| 495 | + pr_info("HQoS mode is going to be enabled !\n"); |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 496 | + eth->qos_toggle = 1; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 497 | + } else if (buf[0] == '2') { |
| 498 | + pr_info("Per-port-per-queue mode is going to be enabled !\n"); |
| 499 | + pr_info("PPPQ use qid 0~5 (scheduler 0).\n"); |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 500 | + eth->qos_toggle = 2; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 501 | + mtk_qdma_qos_pppq_enable(eth); |
| 502 | + } |
| 503 | + |
| 504 | + return len; |
| 505 | +} |
| 506 | + |
| 507 | +static int mtk_qmda_debugfs_read_qos(struct seq_file *m, void *private) |
| 508 | +{ |
| 509 | + struct mtk_eth *eth = m->private; |
| 510 | + |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 511 | + if (eth->qos_toggle == 0) |
| 512 | + pr_info("HQoS is disabled now!\n"); |
| 513 | + else if (eth->qos_toggle == 1) |
| 514 | + pr_info("HQoS is enabled now!\n"); |
| 515 | + else if (eth->qos_toggle == 2) |
| 516 | + pr_info("Per-port-per-queue mode is enabled!\n"); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 517 | + |
| 518 | + return 0; |
| 519 | +} |
| 520 | + |
| 521 | +static int mtk_qmda_debugfs_open_qos(struct inode *inode, struct file *file) |
| 522 | +{ |
| 523 | + return single_open(file, mtk_qmda_debugfs_read_qos, |
| 524 | + inode->i_private); |
| 525 | +} |
| 526 | + |
| 527 | +static ssize_t mtk_qmda_debugfs_read_qos_sched(struct file *file, char __user *user_buf, |
| 528 | + size_t count, loff_t *ppos) |
| 529 | +{ |
| 530 | + struct mtk_eth *eth = _eth; |
| 531 | + long id = (long)file->private_data; |
| 532 | + char *buf; |
| 533 | + unsigned int len = 0, buf_len = 1500; |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 534 | + int enable, scheduling, max_rate, exp, scheduler, i; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 535 | + ssize_t ret_cnt; |
| 536 | + u32 val; |
| 537 | + |
| 538 | + buf = kzalloc(buf_len, GFP_KERNEL); |
| 539 | + if (!buf) |
| 540 | + return -ENOMEM; |
| 541 | + |
| 542 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
| 543 | + val = readl(eth->base + MTK_QDMA_TX_4SCH_BASE(id)); |
| 544 | + else |
| 545 | + val = readl(eth->base + MTK_QDMA_TX_2SCH_BASE); |
| 546 | + |
| 547 | + if (id & 0x1) |
| 548 | + val >>= 16; |
| 549 | + |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 550 | + val &= MTK_QDMA_TX_SCH_MASK; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 551 | + enable = FIELD_GET(MTK_QDMA_TX_SCH_RATE_EN, val); |
| 552 | + scheduling = FIELD_GET(MTK_QDMA_TX_SCH_MAX_WFQ, val); |
| 553 | + max_rate = FIELD_GET(MTK_QDMA_TX_SCH_RATE_MAN, val); |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 554 | + exp = FIELD_GET(MTK_QDMA_TX_SCH_RATE_EXP, val); |
| 555 | + while (exp--) |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 556 | + max_rate *= 10; |
| 557 | + |
| 558 | + len += scnprintf(buf + len, buf_len - len, |
| 559 | + "EN\tScheduling\tMAX\tQueue#\n%d\t%s%16d\t", enable, |
| 560 | + (scheduling == 1) ? "WRR" : "SP", max_rate); |
| 561 | + |
| 562 | + for (i = 0; i < MTK_QDMA_TX_NUM; i++) { |
| 563 | + val = readl(eth->base + MTK_QDMA_PAGE) & ~MTK_QTX_CFG_PAGE; |
| 564 | + val |= FIELD_PREP(MTK_QTX_CFG_PAGE, i / MTK_QTX_PER_PAGE); |
| 565 | + writel(val, eth->base + MTK_QDMA_PAGE); |
| 566 | + |
| 567 | + val = readl(eth->base + MTK_QTX_SCH(i % MTK_QTX_PER_PAGE)); |
| 568 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
| 569 | + scheduler = FIELD_GET(MTK_QTX_SCH_TX_SCH_SEL_V2, val); |
| 570 | + else |
| 571 | + scheduler = FIELD_GET(MTK_QTX_SCH_TX_SCH_SEL, val); |
| 572 | + if (id == scheduler) |
| 573 | + len += scnprintf(buf + len, buf_len - len, "%d ", i); |
| 574 | + } |
| 575 | + |
| 576 | + len += scnprintf(buf + len, buf_len - len, "\n"); |
| 577 | + if (len > buf_len) |
| 578 | + len = buf_len; |
| 579 | + |
| 580 | + ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 581 | + |
| 582 | + kfree(buf); |
| 583 | + return ret_cnt; |
| 584 | +} |
| 585 | + |
| 586 | +static ssize_t mtk_qmda_debugfs_write_qos_sched(struct file *file, const char __user *buf, |
| 587 | + size_t length, loff_t *offset) |
| 588 | +{ |
| 589 | + struct mtk_eth *eth = _eth; |
| 590 | + long id = (long)file->private_data; |
| 591 | + char line[64] = {0}, scheduling[32]; |
| 592 | + int enable, rate, exp = 0, shift = 0; |
| 593 | + size_t size; |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 594 | + u32 sch, val = 0; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 595 | + |
| 596 | + if (length >= sizeof(line)) |
| 597 | + return -EINVAL; |
| 598 | + |
| 599 | + if (copy_from_user(line, buf, length)) |
| 600 | + return -EFAULT; |
| 601 | + |
| 602 | + if (sscanf(line, "%d %s %d", &enable, scheduling, &rate) != 3) |
| 603 | + return -EFAULT; |
| 604 | + |
| 605 | + while (rate > 127) { |
| 606 | + rate /= 10; |
| 607 | + exp++; |
| 608 | + } |
| 609 | + |
| 610 | + line[length] = '\0'; |
| 611 | + |
| 612 | + if (enable) |
| 613 | + val |= FIELD_PREP(MTK_QDMA_TX_SCH_RATE_EN, 1); |
| 614 | + if (strcmp(scheduling, "sp") != 0) |
| 615 | + val |= FIELD_PREP(MTK_QDMA_TX_SCH_MAX_WFQ, 1); |
| 616 | + val |= FIELD_PREP(MTK_QDMA_TX_SCH_RATE_MAN, rate); |
| 617 | + val |= FIELD_PREP(MTK_QDMA_TX_SCH_RATE_EXP, exp); |
| 618 | + |
| 619 | + if (id & 0x1) |
| 620 | + shift = 16; |
| 621 | + |
| 622 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 623 | + sch = readl(eth->base + MTK_QDMA_TX_4SCH_BASE(id)); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 624 | + else |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 625 | + sch = readl(eth->base + MTK_QDMA_TX_2SCH_BASE); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 626 | + |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 627 | + sch &= ~(MTK_QDMA_TX_SCH_MASK << shift); |
| 628 | + sch |= val << shift; |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 629 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 630 | + writel(sch, eth->base + MTK_QDMA_TX_4SCH_BASE(id)); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 631 | + else |
developer | c66b215 | 2023-01-11 15:20:04 +0800 | [diff] [blame] | 632 | + writel(sch, eth->base + MTK_QDMA_TX_2SCH_BASE); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 633 | + |
| 634 | + size = strlen(line); |
| 635 | + *offset += size; |
| 636 | + |
| 637 | + return length; |
| 638 | +} |
| 639 | + |
| 640 | +static ssize_t mtk_qmda_debugfs_read_qos_queue(struct file *file, char __user *user_buf, |
| 641 | + size_t count, loff_t *ppos) |
| 642 | +{ |
| 643 | + struct mtk_eth *eth = _eth; |
| 644 | + long id = (long)file->private_data; |
| 645 | + char *buf; |
| 646 | + unsigned int len = 0, buf_len = 1500; |
| 647 | + int min_rate_en, min_rate, min_rate_exp; |
| 648 | + int max_rate_en, max_weight, max_rate, max_rate_exp; |
| 649 | + u32 qtx_sch, qtx_cfg, scheduler, val; |
| 650 | + ssize_t ret_cnt; |
| 651 | + |
| 652 | + buf = kzalloc(buf_len, GFP_KERNEL); |
| 653 | + if (!buf) |
| 654 | + return -ENOMEM; |
| 655 | + |
| 656 | + val = readl(eth->base + MTK_QDMA_PAGE) & ~MTK_QTX_CFG_PAGE; |
| 657 | + val |= FIELD_PREP(MTK_QTX_CFG_PAGE, id / MTK_QTX_PER_PAGE); |
| 658 | + writel(val, eth->base + MTK_QDMA_PAGE); |
| 659 | + |
| 660 | + qtx_cfg = readl(eth->base + MTK_QTX_CFG(id % MTK_QTX_PER_PAGE)); |
| 661 | + qtx_sch = readl(eth->base + MTK_QTX_SCH(id % MTK_QTX_PER_PAGE)); |
| 662 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
| 663 | + scheduler = FIELD_GET(MTK_QTX_SCH_TX_SCH_SEL_V2, qtx_sch); |
| 664 | + else |
| 665 | + scheduler = FIELD_GET(MTK_QTX_SCH_TX_SCH_SEL, qtx_sch); |
| 666 | + |
| 667 | + min_rate_en = FIELD_GET(MTK_QTX_SCH_MIN_RATE_EN, qtx_sch); |
| 668 | + min_rate = FIELD_GET(MTK_QTX_SCH_MIN_RATE_MAN, qtx_sch); |
| 669 | + min_rate_exp = FIELD_GET(MTK_QTX_SCH_MIN_RATE_EXP, qtx_sch); |
| 670 | + max_rate_en = FIELD_GET(MTK_QTX_SCH_MAX_RATE_EN, qtx_sch); |
| 671 | + max_weight = FIELD_GET(MTK_QTX_SCH_MAX_RATE_WGHT, qtx_sch); |
| 672 | + max_rate = FIELD_GET(MTK_QTX_SCH_MAX_RATE_MAN, qtx_sch); |
| 673 | + max_rate_exp = FIELD_GET(MTK_QTX_SCH_MAX_RATE_EXP, qtx_sch); |
| 674 | + while (min_rate_exp--) |
| 675 | + min_rate *= 10; |
| 676 | + |
| 677 | + while (max_rate_exp--) |
| 678 | + max_rate *= 10; |
| 679 | + |
| 680 | + len += scnprintf(buf + len, buf_len - len, |
| 681 | + "scheduler: %d\nhw resv: %d\nsw resv: %d\n", scheduler, |
| 682 | + (qtx_cfg >> 8) & 0xff, qtx_cfg & 0xff); |
| 683 | + |
| 684 | + /* Switch to debug mode */ |
| 685 | + val = readl(eth->base + MTK_QTX_MIB_IF) & ~MTK_MIB_ON_QTX_CFG; |
| 686 | + val |= MTK_MIB_ON_QTX_CFG; |
| 687 | + writel(val, eth->base + MTK_QTX_MIB_IF); |
| 688 | + |
| 689 | + val = readl(eth->base + MTK_QTX_MIB_IF) & ~MTK_VQTX_MIB_EN; |
| 690 | + val |= MTK_VQTX_MIB_EN; |
| 691 | + writel(val, eth->base + MTK_QTX_MIB_IF); |
| 692 | + |
| 693 | + qtx_cfg = readl(eth->base + MTK_QTX_CFG(id % MTK_QTX_PER_PAGE)); |
| 694 | + qtx_sch = readl(eth->base + MTK_QTX_SCH(id % MTK_QTX_PER_PAGE)); |
| 695 | + |
| 696 | + len += scnprintf(buf + len, buf_len - len, |
| 697 | + "packet count: %u\n", qtx_cfg); |
| 698 | + len += scnprintf(buf + len, buf_len - len, |
| 699 | + "packet drop: %u\n\n", qtx_sch); |
| 700 | + |
| 701 | + /* Recover to normal mode */ |
| 702 | + val = readl(eth->base + MTK_QTX_MIB_IF); |
| 703 | + val &= ~MTK_MIB_ON_QTX_CFG; |
| 704 | + writel(val, eth->base + MTK_QTX_MIB_IF); |
| 705 | + |
| 706 | + val = readl(eth->base + MTK_QTX_MIB_IF); |
| 707 | + val &= ~MTK_VQTX_MIB_EN; |
| 708 | + writel(val, eth->base + MTK_QTX_MIB_IF); |
| 709 | + |
| 710 | + len += scnprintf(buf + len, buf_len - len, |
| 711 | + " EN RATE WEIGHT\n"); |
| 712 | + len += scnprintf(buf + len, buf_len - len, |
| 713 | + "----------------------------\n"); |
| 714 | + len += scnprintf(buf + len, buf_len - len, |
| 715 | + "max%5d%9d%9d\n", max_rate_en, max_rate, max_weight); |
| 716 | + len += scnprintf(buf + len, buf_len - len, |
| 717 | + "min%5d%9d -\n", min_rate_en, min_rate); |
| 718 | + |
| 719 | + if (len > buf_len) |
| 720 | + len = buf_len; |
| 721 | + |
| 722 | + ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 723 | + |
| 724 | + kfree(buf); |
| 725 | + |
| 726 | + return ret_cnt; |
| 727 | +} |
| 728 | + |
| 729 | +static ssize_t mtk_qmda_debugfs_write_qos_queue(struct file *file, const char __user *buf, |
| 730 | + size_t length, loff_t *offset) |
| 731 | +{ |
| 732 | + struct mtk_eth *eth = _eth; |
| 733 | + long id = (long)file->private_data; |
| 734 | + char line[64] = {0}; |
| 735 | + int max_enable, max_rate, max_exp = 0; |
| 736 | + int min_enable, min_rate, min_exp = 0; |
| 737 | + int scheduler, weight, resv; |
| 738 | + size_t size; |
| 739 | + u32 val; |
| 740 | + |
| 741 | + if (length >= sizeof(line)) |
| 742 | + return -EINVAL; |
| 743 | + |
| 744 | + if (copy_from_user(line, buf, length)) |
| 745 | + return -EFAULT; |
| 746 | + |
| 747 | + if (sscanf(line, "%d %d %d %d %d %d %d", &scheduler, &min_enable, &min_rate, |
| 748 | + &max_enable, &max_rate, &weight, &resv) != 7) |
| 749 | + return -EFAULT; |
| 750 | + |
| 751 | + line[length] = '\0'; |
| 752 | + |
| 753 | + while (max_rate > 127) { |
| 754 | + max_rate /= 10; |
| 755 | + max_exp++; |
| 756 | + } |
| 757 | + |
| 758 | + while (min_rate > 127) { |
| 759 | + min_rate /= 10; |
| 760 | + min_exp++; |
| 761 | + } |
| 762 | + |
| 763 | + val = readl(eth->base + MTK_QDMA_PAGE) & ~MTK_QTX_CFG_PAGE; |
| 764 | + val |= FIELD_PREP(MTK_QTX_CFG_PAGE, id / MTK_QTX_PER_PAGE); |
| 765 | + writel(val, eth->base + MTK_QDMA_PAGE); |
| 766 | + |
| 767 | + if (eth->soc->txrx.qdma_tx_sch == 4) |
| 768 | + val = FIELD_PREP(MTK_QTX_SCH_TX_SCH_SEL_V2, scheduler); |
| 769 | + else |
| 770 | + val = FIELD_PREP(MTK_QTX_SCH_TX_SCH_SEL, scheduler); |
| 771 | + if (min_enable) |
| 772 | + val |= MTK_QTX_SCH_MIN_RATE_EN; |
| 773 | + val |= FIELD_PREP(MTK_QTX_SCH_MIN_RATE_MAN, min_rate); |
| 774 | + val |= FIELD_PREP(MTK_QTX_SCH_MIN_RATE_EXP, min_exp); |
| 775 | + if (max_enable) |
| 776 | + val |= MTK_QTX_SCH_MAX_RATE_EN; |
| 777 | + val |= FIELD_PREP(MTK_QTX_SCH_MAX_RATE_WGHT, weight); |
| 778 | + val |= FIELD_PREP(MTK_QTX_SCH_MAX_RATE_MAN, max_rate); |
| 779 | + val |= FIELD_PREP(MTK_QTX_SCH_MAX_RATE_EXP, max_exp); |
| 780 | + writel(val, eth->base + MTK_QTX_SCH(id % MTK_QTX_PER_PAGE)); |
| 781 | + |
| 782 | + val = readl(eth->base + MTK_QTX_CFG(id % MTK_QTX_PER_PAGE)); |
| 783 | + val |= FIELD_PREP(MTK_QTX_CFG_HW_RESV_CNT_OFFSET, resv); |
| 784 | + val |= FIELD_PREP(MTK_QTX_CFG_SW_RESV_CNT_OFFSET, resv); |
| 785 | + writel(val, eth->base + MTK_QTX_CFG(id % MTK_QTX_PER_PAGE)); |
| 786 | + |
| 787 | + size = strlen(line); |
| 788 | + *offset += size; |
| 789 | + |
| 790 | + return length; |
| 791 | +} |
| 792 | + |
| 793 | +int mtk_qdma_debugfs_init(struct mtk_eth *eth) |
| 794 | +{ |
| 795 | + static const struct file_operations fops_qos = { |
| 796 | + .open = mtk_qmda_debugfs_open_qos, |
| 797 | + .read = seq_read, |
| 798 | + .llseek = seq_lseek, |
| 799 | + .write = mtk_qmda_debugfs_write_qos, |
| 800 | + .release = single_release, |
| 801 | + }; |
| 802 | + |
| 803 | + static const struct file_operations fops_qos_sched = { |
| 804 | + .open = simple_open, |
| 805 | + .read = mtk_qmda_debugfs_read_qos_sched, |
| 806 | + .write = mtk_qmda_debugfs_write_qos_sched, |
| 807 | + .llseek = default_llseek, |
| 808 | + }; |
| 809 | + |
| 810 | + static const struct file_operations fops_qos_queue = { |
| 811 | + .open = simple_open, |
| 812 | + .read = mtk_qmda_debugfs_read_qos_queue, |
| 813 | + .write = mtk_qmda_debugfs_write_qos_queue, |
| 814 | + .llseek = default_llseek, |
| 815 | + }; |
| 816 | + |
| 817 | + struct dentry *root; |
| 818 | + long i; |
| 819 | + char name[16]; |
| 820 | + |
| 821 | + _eth = eth; |
| 822 | + |
| 823 | + root = debugfs_lookup("mtk_ppe", NULL); |
| 824 | + if (!root) |
| 825 | + return -ENOMEM; |
| 826 | + |
developer | 0a32014 | 2022-09-21 23:18:01 +0800 | [diff] [blame] | 827 | + debugfs_create_file("qos_toggle", S_IRUGO, root, eth, &fops_qos); |
developer | 73cb4d5 | 2022-09-06 15:15:57 +0800 | [diff] [blame] | 828 | + |
| 829 | + for (i = 0; i < eth->soc->txrx.qdma_tx_sch; i++) { |
| 830 | + snprintf(name, sizeof(name), "qdma_sch%ld", i); |
| 831 | + debugfs_create_file(name, S_IRUGO, root, (void *)i, |
| 832 | + &fops_qos_sched); |
| 833 | + } |
| 834 | + |
| 835 | + for (i = 0; i < MTK_QDMA_TX_NUM; i++) { |
| 836 | + snprintf(name, sizeof(name), "qdma_txq%ld", i); |
| 837 | + debugfs_create_file(name, S_IRUGO, root, (void *)i, |
| 838 | + &fops_qos_queue); |
| 839 | + } |
| 840 | + |
| 841 | + return 0; |
| 842 | +} |
developer | 0aaf79d | 2023-08-21 14:10:16 +0800 | [diff] [blame] | 843 | diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h |
| 844 | index 59b8736..c4eb45c 100644 |
| 845 | --- a/include/net/flow_offload.h |
| 846 | +++ b/include/net/flow_offload.h |
| 847 | @@ -365,6 +365,7 @@ struct flow_cls_offload { |
| 848 | struct flow_cls_common_offload common; |
| 849 | enum flow_cls_command command; |
| 850 | unsigned long cookie; |
| 851 | + struct flow_offload *flow; |
| 852 | struct flow_rule *rule; |
| 853 | struct flow_stats stats; |
| 854 | u32 classid; |
| 855 | diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c |
| 856 | index 50f2f2e..ba34572 100644 |
| 857 | --- a/net/netfilter/nf_flow_table_offload.c |
| 858 | +++ b/net/netfilter/nf_flow_table_offload.c |
| 859 | @@ -810,11 +810,13 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload, |
| 860 | } |
| 861 | |
| 862 | static void nf_flow_offload_init(struct flow_cls_offload *cls_flow, |
| 863 | + struct flow_offload *flow, |
| 864 | __be16 proto, int priority, |
| 865 | enum flow_cls_command cmd, |
| 866 | const struct flow_offload_tuple *tuple, |
| 867 | struct netlink_ext_ack *extack) |
| 868 | { |
| 869 | + cls_flow->flow = flow; |
| 870 | cls_flow->common.protocol = proto; |
| 871 | cls_flow->common.prio = priority; |
| 872 | cls_flow->common.extack = extack; |
| 873 | @@ -836,7 +838,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable, |
| 874 | __be16 proto = ETH_P_ALL; |
| 875 | int err, i = 0; |
| 876 | |
| 877 | - nf_flow_offload_init(&cls_flow, proto, priority, cmd, |
| 878 | + nf_flow_offload_init(&cls_flow, flow, proto, priority, cmd, |
| 879 | &flow->tuplehash[dir].tuple, &extack); |
| 880 | if (cmd == FLOW_CLS_REPLACE) |
| 881 | cls_flow.rule = flow_rule->rule; |
| 882 | -- |
| 883 | 2.18.0 |
| 884 | |