forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk-tool.c
....@@ -9,6 +9,7 @@
99 #include <linux/if_ether.h>
1010 #include <linux/if.h>
1111 #include <linux/dma-mapping.h>
12
+#include <linux/of_device.h>
1213 #include <linux/slab.h>
1314 #include <linux/prefetch.h>
1415 #include <linux/regmap.h>
....@@ -85,6 +86,7 @@
8586 int rx;
8687 int final_tx;
8788 int final_rx;
89
+ int max_delay;
8890 };
8991
9092 #define DMA_CONTROL_OSP BIT(4)
....@@ -99,6 +101,7 @@
99101
100102 #define STMMAC_ALIGN(x) __ALIGN_KERNEL(x, SMP_CACHE_BYTES)
101103 #define MAX_DELAYLINE 0x7f
104
+#define RK3588_MAX_DELAYLINE 0xc7
102105 #define SCAN_STEP 0x5
103106 #define SCAN_VALID_RANGE 0xA
104107
....@@ -119,7 +122,8 @@
119122 .size = 1024,
120123 };
121124
122
-static int dwmac_rk_enable_mac_loopback(struct stmmac_priv *priv, int speed)
125
+static int dwmac_rk_enable_mac_loopback(struct stmmac_priv *priv, int speed,
126
+ int addr, bool phy)
123127 {
124128 u32 ctrl;
125129 int phy_val;
....@@ -128,25 +132,30 @@
128132 ctrl &= ~priv->hw->link.speed_mask;
129133 ctrl |= GMAC_CONTROL_LM;
130134
131
- phy_val = mdiobus_read(priv->mii, priv->plat->phy_addr, MII_BMCR);
135
+ if (phy)
136
+ phy_val = mdiobus_read(priv->mii, addr, MII_BMCR);
132137
133138 switch (speed) {
134139 case LOOPBACK_SPEED1000:
135140 ctrl |= priv->hw->link.speed1000;
136
- phy_val |= BMCR_ANENABLE;
137
- phy_val |= BMCR_SPEED1000;
141
+ if (phy) {
142
+ phy_val &= ~BMCR_SPEED100;
143
+ phy_val |= BMCR_SPEED1000;
144
+ }
138145 break;
139146 case LOOPBACK_SPEED100:
140147 ctrl |= priv->hw->link.speed100;
141
- phy_val &= ~BMCR_ANENABLE;
142
- phy_val &= ~BMCR_SPEED1000;
143
- phy_val |= BMCR_SPEED100;
148
+ if (phy) {
149
+ phy_val &= ~BMCR_SPEED1000;
150
+ phy_val |= BMCR_SPEED100;
151
+ }
144152 break;
145153 case LOOPBACK_SPEED10:
146154 ctrl |= priv->hw->link.speed10;
147
- phy_val &= ~BMCR_ANENABLE;
148
- phy_val &= ~BMCR_SPEED1000;
149
- phy_val &= ~BMCR_SPEED100;
155
+ if (phy) {
156
+ phy_val &= ~BMCR_SPEED1000;
157
+ phy_val &= ~BMCR_SPEED100;
158
+ }
150159 break;
151160 default:
152161 return -EPERM;
....@@ -155,9 +164,14 @@
155164 ctrl |= priv->hw->link.duplex;
156165 writel(ctrl, priv->ioaddr + GMAC_CONTROL);
157166
158
- phy_val |= BMCR_FULLDPLX;
159
- mdiobus_write(priv->mii, priv->plat->phy_addr, MII_BMCR, phy_val);
160
- phy_val = mdiobus_read(priv->mii, priv->plat->phy_addr, MII_BMCR);
167
+ if (phy) {
168
+ phy_val &= ~BMCR_PDOWN;
169
+ phy_val &= ~BMCR_ANENABLE;
170
+ phy_val &= ~BMCR_PDOWN;
171
+ phy_val |= BMCR_FULLDPLX;
172
+ mdiobus_write(priv->mii, addr, MII_BMCR, phy_val);
173
+ phy_val = mdiobus_read(priv->mii, addr, MII_BMCR);
174
+ }
161175
162176 if (likely(priv->plat->fix_mac_speed))
163177 priv->plat->fix_mac_speed(priv->plat->bsp_priv, speed);
....@@ -165,7 +179,7 @@
165179 return 0;
166180 }
167181
168
-static int dwmac_rk_disable_mac_loopback(struct stmmac_priv *priv)
182
+static int dwmac_rk_disable_mac_loopback(struct stmmac_priv *priv, int addr)
169183 {
170184 u32 ctrl;
171185 int phy_val;
....@@ -174,25 +188,27 @@
174188 ctrl &= ~GMAC_CONTROL_LM;
175189 writel(ctrl, priv->ioaddr + GMAC_CONTROL);
176190
177
- phy_val = mdiobus_read(priv->mii, priv->plat->phy_addr, MII_BMCR);
191
+ phy_val = mdiobus_read(priv->mii, addr, MII_BMCR);
178192 phy_val |= BMCR_ANENABLE;
179193
180
- mdiobus_write(priv->mii, priv->plat->phy_addr, MII_BMCR, phy_val);
181
- phy_val = mdiobus_read(priv->mii, priv->plat->phy_addr, MII_BMCR);
194
+ mdiobus_write(priv->mii, addr, MII_BMCR, phy_val);
195
+ phy_val = mdiobus_read(priv->mii, addr, MII_BMCR);
182196
183197 return 0;
184198 }
185199
186200 static int dwmac_rk_set_mac_loopback(struct stmmac_priv *priv,
187
- int speed, bool enable)
201
+ int speed, bool enable,
202
+ int addr, bool phy)
188203 {
189204 if (enable)
190
- return dwmac_rk_enable_mac_loopback(priv, speed);
205
+ return dwmac_rk_enable_mac_loopback(priv, speed, addr, phy);
191206 else
192
- return dwmac_rk_disable_mac_loopback(priv);
207
+ return dwmac_rk_disable_mac_loopback(priv, addr);
193208 }
194209
195
-static int dwmac_rk_enable_phy_loopback(struct stmmac_priv *priv, int speed)
210
+static int dwmac_rk_enable_phy_loopback(struct stmmac_priv *priv, int speed,
211
+ int addr, bool phy)
196212 {
197213 u32 ctrl;
198214 int val;
....@@ -200,25 +216,30 @@
200216 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
201217 ctrl &= ~priv->hw->link.speed_mask;
202218
203
- val = mdiobus_read(priv->mii, 0, MII_BMCR);
204
-
205
- val &= ~BMCR_ANENABLE;
206
- val |= BMCR_LOOPBACK;
219
+ if (phy)
220
+ val = mdiobus_read(priv->mii, addr, MII_BMCR);
207221
208222 switch (speed) {
209223 case LOOPBACK_SPEED1000:
210224 ctrl |= priv->hw->link.speed1000;
211
- val |= BMCR_SPEED1000;
225
+ if (phy) {
226
+ val &= ~BMCR_SPEED100;
227
+ val |= BMCR_SPEED1000;
228
+ }
212229 break;
213230 case LOOPBACK_SPEED100:
214231 ctrl |= priv->hw->link.speed100;
215
- val &= ~BMCR_SPEED1000;
216
- val |= BMCR_SPEED100;
232
+ if (phy) {
233
+ val &= ~BMCR_SPEED1000;
234
+ val |= BMCR_SPEED100;
235
+ }
217236 break;
218237 case LOOPBACK_SPEED10:
219238 ctrl |= priv->hw->link.speed10;
220
- val &= ~BMCR_SPEED1000;
221
- val &= ~BMCR_SPEED100;
239
+ if (phy) {
240
+ val &= ~BMCR_SPEED1000;
241
+ val &= ~BMCR_SPEED100;
242
+ }
222243 break;
223244 default:
224245 return -EPERM;
....@@ -227,9 +248,14 @@
227248 ctrl |= priv->hw->link.duplex;
228249 writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
229250
230
- val |= BMCR_FULLDPLX;
231
- mdiobus_write(priv->mii, 0, MII_BMCR, val);
232
- val = mdiobus_read(priv->mii, 0, MII_BMCR);
251
+ if (phy) {
252
+ val |= BMCR_FULLDPLX;
253
+ val &= ~BMCR_PDOWN;
254
+ val &= ~BMCR_ANENABLE;
255
+ val |= BMCR_LOOPBACK;
256
+ mdiobus_write(priv->mii, addr, MII_BMCR, val);
257
+ val = mdiobus_read(priv->mii, addr, MII_BMCR);
258
+ }
233259
234260 if (likely(priv->plat->fix_mac_speed))
235261 priv->plat->fix_mac_speed(priv->plat->bsp_priv, speed);
....@@ -237,40 +263,43 @@
237263 return 0;
238264 }
239265
240
-static int dwmac_rk_disable_phy_loopback(struct stmmac_priv *priv)
266
+static int dwmac_rk_disable_phy_loopback(struct stmmac_priv *priv, int addr)
241267 {
242268 int val;
243269
244
- val = mdiobus_read(priv->mii, 0, MII_BMCR);
270
+ val = mdiobus_read(priv->mii, addr, MII_BMCR);
245271 val |= BMCR_ANENABLE;
246272 val &= ~BMCR_LOOPBACK;
247273
248
- mdiobus_write(priv->mii, 0, MII_BMCR, val);
249
- val = mdiobus_read(priv->mii, priv->plat->phy_addr, MII_BMCR);
274
+ mdiobus_write(priv->mii, addr, MII_BMCR, val);
275
+ val = mdiobus_read(priv->mii, addr, MII_BMCR);
250276
251277 return 0;
252278 }
253279
254280 static int dwmac_rk_set_phy_loopback(struct stmmac_priv *priv,
255
- int speed, bool enable)
281
+ int speed, bool enable,
282
+ int addr, bool phy)
256283 {
257284 if (enable)
258
- return dwmac_rk_enable_phy_loopback(priv, speed);
285
+ return dwmac_rk_enable_phy_loopback(priv, speed,
286
+ addr, phy);
259287 else
260
- return dwmac_rk_disable_phy_loopback(priv);
288
+ return dwmac_rk_disable_phy_loopback(priv, addr);
261289 }
262290
263291 static int dwmac_rk_set_loopback(struct stmmac_priv *priv,
264
- int type, int speed, bool enable)
292
+ int type, int speed, bool enable,
293
+ int addr, bool phy)
265294 {
266295 int ret;
267296
268297 switch (type) {
269298 case LOOPBACK_TYPE_PHY:
270
- ret = dwmac_rk_set_phy_loopback(priv, speed, enable);
299
+ ret = dwmac_rk_set_phy_loopback(priv, speed, enable, addr, phy);
271300 break;
272301 case LOOPBACK_TYPE_GMAC:
273
- ret = dwmac_rk_set_mac_loopback(priv, speed, enable);
302
+ ret = dwmac_rk_set_mac_loopback(priv, speed, enable, addr, phy);
274303 break;
275304 default:
276305 ret = -EOPNOTSUPP;
....@@ -545,15 +574,15 @@
545574 static void dwmac_rk_rx_clean(struct stmmac_priv *priv,
546575 struct dwmac_rk_lb_priv *lb_priv)
547576 {
548
- struct sk_buff *skb;
549
-
550
- skb = lb_priv->rx_skbuff;
551
-
552
- if (likely(lb_priv->rx_skbuff)) {
577
+ if (likely(lb_priv->rx_skbuff_dma)) {
553578 dma_unmap_single(priv->device,
554579 lb_priv->rx_skbuff_dma,
555580 lb_priv->dma_buf_sz, DMA_FROM_DEVICE);
556
- dev_kfree_skb(skb);
581
+ lb_priv->rx_skbuff_dma = 0;
582
+ }
583
+
584
+ if (likely(lb_priv->rx_skbuff)) {
585
+ dev_consume_skb_any(lb_priv->rx_skbuff);
557586 lb_priv->rx_skbuff = NULL;
558587 }
559588 }
....@@ -582,7 +611,12 @@
582611 }
583612
584613 frame_len -= ETH_FCS_LEN;
614
+ prefetch(skb->data - NET_IP_ALIGN);
585615 skb_put(skb, frame_len);
616
+ dma_unmap_single(priv->device,
617
+ lb_priv->rx_skbuff_dma,
618
+ lb_priv->dma_buf_sz,
619
+ DMA_FROM_DEVICE);
586620
587621 return dwmac_rk_loopback_validate(priv, lb_priv, skb);
588622 }
....@@ -616,10 +650,9 @@
616650 static void dwmac_rk_tx_clean(struct stmmac_priv *priv,
617651 struct dwmac_rk_lb_priv *lb_priv)
618652 {
619
- struct sk_buff *skb;
653
+ struct sk_buff *skb = lb_priv->tx_skbuff;
620654 struct dma_desc *p;
621655
622
- skb = lb_priv->tx_skbuff;
623656 p = lb_priv->dma_tx;
624657
625658 if (likely(lb_priv->tx_skbuff_dma)) {
....@@ -631,7 +664,7 @@
631664 }
632665
633666 if (likely(skb)) {
634
- dev_kfree_skb(skb);
667
+ dev_consume_skb_any(skb);
635668 lb_priv->tx_skbuff = NULL;
636669 }
637670
....@@ -655,9 +688,10 @@
655688 lb_priv->tx_skbuff = skb;
656689
657690 des = dma_map_single(priv->device, skb->data,
658
- nopaged_len, DMA_TO_DEVICE);
691
+ nopaged_len, DMA_TO_DEVICE);
659692 if (dma_mapping_error(priv->device, des))
660693 goto dma_map_err;
694
+ lb_priv->tx_skbuff_dma = des;
661695
662696 stmmac_set_desc_addr(priv, desc, des);
663697 lb_priv->tx_skbuff_dma_len = nopaged_len;
....@@ -771,9 +805,20 @@
771805 return __dwmac_rk_loopback_run(priv, lb_priv);
772806 }
773807
774
-static inline bool dwmac_rk_delayline_is_valid(int tx, int rx)
808
+static inline bool dwmac_rk_delayline_is_txvalid(struct dwmac_rk_lb_priv *lb_priv,
809
+ int tx)
775810 {
776
- if ((tx > 0 && tx < MAX_DELAYLINE) && (rx > 0 && rx < MAX_DELAYLINE))
811
+ if (tx > 0 && tx < lb_priv->max_delay)
812
+ return true;
813
+ else
814
+ return false;
815
+}
816
+
817
+static inline bool dwmac_rk_delayline_is_valid(struct dwmac_rk_lb_priv *lb_priv,
818
+ int tx, int rx)
819
+{
820
+ if ((tx > 0 && tx < lb_priv->max_delay) &&
821
+ (rx > 0 && rx < lb_priv->max_delay))
777822 return true;
778823 else
779824 return false;
....@@ -784,7 +829,7 @@
784829 {
785830 int tx_left, tx_right, rx_up, rx_down;
786831 int i, j, tx_index, rx_index;
787
- int tx_mid, rx_mid;
832
+ int tx_mid = 0, rx_mid = 0;
788833
789834 /* initiation */
790835 tx_index = SCAN_STEP;
....@@ -792,12 +837,12 @@
792837
793838 re_scan:
794839 /* start from rx based on the experience */
795
- for (i = rx_index; i <= (MAX_DELAYLINE - SCAN_STEP); i += SCAN_STEP) {
840
+ for (i = rx_index; i <= (lb_priv->max_delay - SCAN_STEP); i += SCAN_STEP) {
796841 tx_left = 0;
797842 tx_right = 0;
798843 tx_mid = 0;
799844
800
- for (j = tx_index; j <= (MAX_DELAYLINE - SCAN_STEP);
845
+ for (j = tx_index; j <= (lb_priv->max_delay - SCAN_STEP);
801846 j += SCAN_STEP) {
802847 if (!dwmac_rk_loopback_with_identify(priv,
803848 lb_priv, j, i)) {
....@@ -815,14 +860,14 @@
815860 }
816861
817862 /* Worst case: reach the end */
818
- if (i >= (MAX_DELAYLINE - SCAN_STEP))
863
+ if (i >= (lb_priv->max_delay - SCAN_STEP))
819864 goto end;
820865
821866 rx_up = 0;
822867 rx_down = 0;
823868
824869 /* look for rx_mid base on the tx_mid */
825
- for (i = SCAN_STEP; i <= (MAX_DELAYLINE - SCAN_STEP);
870
+ for (i = SCAN_STEP; i <= (lb_priv->max_delay - SCAN_STEP);
826871 i += SCAN_STEP) {
827872 if (!dwmac_rk_loopback_with_identify(priv, lb_priv,
828873 tx_mid, i)) {
....@@ -841,23 +886,24 @@
841886 goto re_scan;
842887 }
843888
844
- if (dwmac_rk_delayline_is_valid(tx_mid, rx_mid)) {
889
+ if (dwmac_rk_delayline_is_valid(lb_priv, tx_mid, rx_mid)) {
845890 lb_priv->final_tx = tx_mid;
846891 lb_priv->final_rx = rx_mid;
847892
848
- pr_info("Find suitable tx_delay = 0x%02x, rx_delay = 0x%02x\n",
893
+ pr_info("Find available tx_delay = 0x%02x, rx_delay = 0x%02x\n",
849894 lb_priv->final_tx, lb_priv->final_rx);
850895
851896 return 0;
852897 }
853898 end:
854
- pr_err("Can't find suitable delayline\n");
899
+ pr_err("Can't find available delayline\n");
855900 return -ENXIO;
856901 }
857902
858903 static int dwmac_rk_delayline_scan(struct stmmac_priv *priv,
859904 struct dwmac_rk_lb_priv *lb_priv)
860905 {
906
+ int phy_iface = dwmac_rk_get_phy_interface(priv);
861907 int tx, rx, tx_sum, rx_sum, count;
862908 int tx_mid, rx_mid;
863909 int ret = -ENXIO;
....@@ -866,9 +912,11 @@
866912 rx_sum = 0;
867913 count = 0;
868914
869
- for (rx = 0x0; rx <= MAX_DELAYLINE; rx++) {
870
- printk(KERN_CONT "RX(0x%02x):", rx);
871
- for (tx = 0x0; tx <= MAX_DELAYLINE; tx++) {
915
+ for (rx = 0x0; rx <= lb_priv->max_delay; rx++) {
916
+ if (phy_iface == PHY_INTERFACE_MODE_RGMII_RXID)
917
+ rx = -1;
918
+ printk(KERN_CONT "RX(%03d):", rx);
919
+ for (tx = 0x0; tx <= lb_priv->max_delay; tx++) {
872920 if (!dwmac_rk_loopback_with_identify(priv,
873921 lb_priv, tx, rx)) {
874922 tx_sum += tx;
....@@ -880,24 +928,40 @@
880928 }
881929 }
882930 printk(KERN_CONT "\n");
931
+
932
+ if (phy_iface == PHY_INTERFACE_MODE_RGMII_RXID)
933
+ break;
883934 }
884935
885936 if (tx_sum && rx_sum && count) {
886937 tx_mid = tx_sum / count;
887938 rx_mid = rx_sum / count;
888939
889
- if (dwmac_rk_delayline_is_valid(tx_mid, rx_mid)) {
890
- lb_priv->final_tx = tx_mid;
891
- lb_priv->final_rx = rx_mid;
892
- ret = 0;
940
+ if (phy_iface == PHY_INTERFACE_MODE_RGMII_RXID) {
941
+ if (dwmac_rk_delayline_is_txvalid(lb_priv, tx_mid)) {
942
+ lb_priv->final_tx = tx_mid;
943
+ lb_priv->final_rx = -1;
944
+ ret = 0;
945
+ }
946
+ } else {
947
+ if (dwmac_rk_delayline_is_valid(lb_priv, tx_mid, rx_mid)) {
948
+ lb_priv->final_tx = tx_mid;
949
+ lb_priv->final_rx = rx_mid;
950
+ ret = 0;
951
+ }
893952 }
894953 }
895954
896
- if (ret)
955
+ if (ret) {
897956 pr_err("\nCan't find suitable delayline\n");
898
- else
899
- pr_info("\nFind suitable tx_delay = 0x%02x, rx_delay = 0x%02x\n",
900
- lb_priv->final_tx, lb_priv->final_rx);
957
+ } else {
958
+ if (phy_iface == PHY_INTERFACE_MODE_RGMII_RXID)
959
+ pr_info("Find available tx_delay = 0x%02x, rx_delay = disable\n",
960
+ lb_priv->final_tx);
961
+ else
962
+ pr_info("\nFind suitable tx_delay = 0x%02x, rx_delay = 0x%02x\n",
963
+ lb_priv->final_tx, lb_priv->final_rx);
964
+ }
901965
902966 return ret;
903967 }
....@@ -969,17 +1033,17 @@
9691033 int ret = -ENOMEM;
9701034
9711035 /* desc dma map */
972
- lb_priv->dma_rx = dma_zalloc_coherent(priv->device,
973
- sizeof(struct dma_desc),
974
- &lb_priv->dma_rx_phy,
975
- GFP_KERNEL);
1036
+ lb_priv->dma_rx = dma_alloc_coherent(priv->device,
1037
+ sizeof(struct dma_desc),
1038
+ &lb_priv->dma_rx_phy,
1039
+ GFP_KERNEL);
9761040 if (!lb_priv->dma_rx)
9771041 return ret;
9781042
979
- lb_priv->dma_tx = dma_zalloc_coherent(priv->device,
980
- sizeof(struct dma_desc),
981
- &lb_priv->dma_tx_phy,
982
- GFP_KERNEL);
1043
+ lb_priv->dma_tx = dma_alloc_coherent(priv->device,
1044
+ sizeof(struct dma_desc),
1045
+ &lb_priv->dma_tx_phy,
1046
+ GFP_KERNEL);
9831047 if (!lb_priv->dma_tx) {
9841048 dma_free_coherent(priv->device,
9851049 sizeof(struct dma_desc),
....@@ -1090,6 +1154,54 @@
10901154 }
10911155 }
10921156
1157
+static void dwmac_rk_rx_queue_dma_chan_map(struct stmmac_priv *priv)
1158
+{
1159
+ u32 rx_queues_count = min_t(u32, priv->plat->rx_queues_to_use, 1);
1160
+ u32 queue;
1161
+ u32 chan;
1162
+
1163
+ for (queue = 0; queue < rx_queues_count; queue++) {
1164
+ chan = priv->plat->rx_queues_cfg[queue].chan;
1165
+ stmmac_map_mtl_to_dma(priv, priv->hw, queue, chan);
1166
+ }
1167
+}
1168
+
1169
+static void dwmac_rk_mac_enable_rx_queues(struct stmmac_priv *priv)
1170
+{
1171
+ u32 rx_queues_count = min_t(u32, priv->plat->rx_queues_to_use, 1);
1172
+ int queue;
1173
+ u8 mode;
1174
+
1175
+ for (queue = 0; queue < rx_queues_count; queue++) {
1176
+ mode = priv->plat->rx_queues_cfg[queue].mode_to_use;
1177
+ stmmac_rx_queue_enable(priv, priv->hw, mode, queue);
1178
+ }
1179
+}
1180
+
1181
+static void dwmac_rk_mtl_configuration(struct stmmac_priv *priv)
1182
+{
1183
+ /* Map RX MTL to DMA channels */
1184
+ dwmac_rk_rx_queue_dma_chan_map(priv);
1185
+
1186
+ /* Enable MAC RX Queues */
1187
+ dwmac_rk_mac_enable_rx_queues(priv);
1188
+}
1189
+
1190
+static void dwmac_rk_mmc_setup(struct stmmac_priv *priv)
1191
+{
1192
+ unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
1193
+ MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
1194
+
1195
+ stmmac_mmc_intr_all_mask(priv, priv->mmcaddr);
1196
+
1197
+ if (priv->dma_cap.rmon) {
1198
+ stmmac_mmc_ctrl(priv, priv->mmcaddr, mode);
1199
+ memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
1200
+ } else {
1201
+ netdev_info(priv->dev, "No MAC Management Counters available\n");
1202
+ }
1203
+}
1204
+
10931205 static int dwmac_rk_init(struct net_device *dev,
10941206 struct dwmac_rk_lb_priv *lb_priv)
10951207 {
....@@ -1129,6 +1241,10 @@
11291241 /* Initialize the MAC Core */
11301242 stmmac_core_init(priv, priv->hw, dev);
11311243
1244
+ dwmac_rk_mtl_configuration(priv);
1245
+
1246
+ dwmac_rk_mmc_setup(priv);
1247
+
11321248 ret = priv->hw->mac->rx_ipc(priv->hw);
11331249 if (!ret) {
11341250 pr_warn(" RX IPC Checksum Offload disabled\n");
....@@ -1150,7 +1266,7 @@
11501266 writel((mode & ~DMA_CONTROL_OSF), priv->ioaddr + DMA_CONTROL);
11511267 }
11521268
1153
- stmmac_enable_dma_irq(priv, priv->ioaddr, 0);
1269
+ stmmac_enable_dma_irq(priv, priv->ioaddr, 0, 1, 1);
11541270
11551271 if (priv->hw->pcs)
11561272 stmmac_pcs_ctrl_ane(priv, priv->hw, 1, priv->hw->ps, 0);
....@@ -1167,10 +1283,41 @@
11671283 {
11681284 struct stmmac_priv *priv = netdev_priv(dev);
11691285
1170
- stmmac_disable_dma_irq(priv, priv->ioaddr, 0);
1286
+ stmmac_disable_dma_irq(priv, priv->ioaddr, 0, 0, 0);
11711287
11721288 /* Release and free the Rx/Tx resources */
11731289 dwmac_rk_free_dma_desc_resources(priv, lb_priv);
1290
+}
1291
+
1292
+static int dwmac_rk_get_max_delayline(struct stmmac_priv *priv)
1293
+{
1294
+ if (of_device_is_compatible(priv->device->of_node,
1295
+ "rockchip,rk3588-gmac"))
1296
+ return RK3588_MAX_DELAYLINE;
1297
+ else
1298
+ return MAX_DELAYLINE;
1299
+}
1300
+
1301
+static int dwmac_rk_phy_poll_reset(struct stmmac_priv *priv, int addr)
1302
+{
1303
+ /* Poll until the reset bit clears (50ms per retry == 0.6 sec) */
1304
+ unsigned int val, retries = 12;
1305
+ int ret;
1306
+
1307
+ val = mdiobus_read(priv->mii, addr, MII_BMCR);
1308
+ mdiobus_write(priv->mii, addr, MII_BMCR, val | BMCR_RESET);
1309
+
1310
+ do {
1311
+ msleep(50);
1312
+ ret = mdiobus_read(priv->mii, addr, MII_BMCR);
1313
+ if (ret < 0)
1314
+ return ret;
1315
+ } while (ret & BMCR_RESET && --retries);
1316
+ if (ret & BMCR_RESET)
1317
+ return -ETIMEDOUT;
1318
+
1319
+ msleep(1);
1320
+ return 0;
11741321 }
11751322
11761323 static int dwmac_rk_loopback_run(struct stmmac_priv *priv,
....@@ -1178,11 +1325,14 @@
11781325 {
11791326 struct net_device *ndev = priv->dev;
11801327 int phy_iface = dwmac_rk_get_phy_interface(priv);
1181
- int ndev_up;
1328
+ int ndev_up, phy_addr;
11821329 int ret = -EINVAL;
11831330
11841331 if (!ndev || !priv->mii)
11851332 return -EINVAL;
1333
+
1334
+ phy_addr = priv->dev->phydev->mdio.addr;
1335
+ lb_priv->max_delay = dwmac_rk_get_max_delayline(priv);
11861336
11871337 rtnl_lock();
11881338 /* check the netdevice up or not */
....@@ -1206,25 +1356,29 @@
12061356
12071357 if (priv->plat->stmmac_rst)
12081358 reset_control_assert(priv->plat->stmmac_rst);
1209
-
1210
- if (priv->mii)
1211
- priv->mii->reset(priv->mii);
1212
-
1359
+ dwmac_rk_phy_poll_reset(priv, phy_addr);
12131360 if (priv->plat->stmmac_rst)
12141361 reset_control_deassert(priv->plat->stmmac_rst);
12151362 }
12161363 /* wait for phy and controller ready */
12171364 usleep_range(100000, 200000);
12181365
1366
+ dwmac_rk_set_loopback(priv, lb_priv->type, lb_priv->speed,
1367
+ true, phy_addr, true);
1368
+
12191369 ret = dwmac_rk_init(ndev, lb_priv);
12201370 if (ret)
12211371 goto exit_init;
1222
- dwmac_rk_set_loopback(priv, lb_priv->type, lb_priv->speed, true);
1372
+
1373
+ dwmac_rk_set_loopback(priv, lb_priv->type, lb_priv->speed,
1374
+ true, phy_addr, false);
12231375
12241376 if (lb_priv->scan) {
12251377 /* scan only support for rgmii mode */
12261378 if (phy_iface != PHY_INTERFACE_MODE_RGMII &&
1227
- phy_iface != PHY_INTERFACE_MODE_RGMII_ID) {
1379
+ phy_iface != PHY_INTERFACE_MODE_RGMII_ID &&
1380
+ phy_iface != PHY_INTERFACE_MODE_RGMII_RXID &&
1381
+ phy_iface != PHY_INTERFACE_MODE_RGMII_TXID) {
12281382 ret = -EINVAL;
12291383 goto out;
12301384 }
....@@ -1240,8 +1394,8 @@
12401394
12411395 out:
12421396 dwmac_rk_release(ndev, lb_priv);
1243
- dwmac_rk_set_loopback(priv, lb_priv->type, lb_priv->speed, false);
1244
-
1397
+ dwmac_rk_set_loopback(priv, lb_priv->type, lb_priv->speed,
1398
+ false, phy_addr, false);
12451399 exit_init:
12461400 if (ndev_up)
12471401 ndev->netdev_ops->ndo_open(ndev);
....@@ -1286,10 +1440,10 @@
12861440 *data = 0;
12871441 data++;
12881442
1289
- if (kstrtoint(tmp, 0, &tx) || tx > MAX_DELAYLINE)
1443
+ if (kstrtoint(tmp, 0, &tx) || tx > dwmac_rk_get_max_delayline(priv))
12901444 goto out;
12911445
1292
- if (kstrtoint(data, 0, &rx) || rx > MAX_DELAYLINE)
1446
+ if (kstrtoint(data, 0, &rx) || rx > dwmac_rk_get_max_delayline(priv))
12931447 goto out;
12941448
12951449 dwmac_rk_set_rgmii_delayline(priv, tx, rx);