@@ -124,30 +124,51 @@ static int tsnep_mdiobus_write(struct mii_bus *bus, int addr, int regnum,
124
124
return 0 ;
125
125
}
126
126
127
+ static void tsnep_set_link_mode (struct tsnep_adapter * adapter )
128
+ {
129
+ u32 mode ;
130
+
131
+ switch (adapter -> phydev -> speed ) {
132
+ case SPEED_100 :
133
+ mode = ECM_LINK_MODE_100 ;
134
+ break ;
135
+ case SPEED_1000 :
136
+ mode = ECM_LINK_MODE_1000 ;
137
+ break ;
138
+ default :
139
+ mode = ECM_LINK_MODE_OFF ;
140
+ break ;
141
+ }
142
+ iowrite32 (mode , adapter -> addr + ECM_STATUS );
143
+ }
144
+
127
145
static void tsnep_phy_link_status_change (struct net_device * netdev )
128
146
{
129
147
struct tsnep_adapter * adapter = netdev_priv (netdev );
130
148
struct phy_device * phydev = netdev -> phydev ;
131
- u32 mode ;
132
149
133
- if (phydev -> link ) {
134
- switch (phydev -> speed ) {
135
- case SPEED_100 :
136
- mode = ECM_LINK_MODE_100 ;
137
- break ;
138
- case SPEED_1000 :
139
- mode = ECM_LINK_MODE_1000 ;
140
- break ;
141
- default :
142
- mode = ECM_LINK_MODE_OFF ;
143
- break ;
144
- }
145
- iowrite32 (mode , adapter -> addr + ECM_STATUS );
146
- }
150
+ if (phydev -> link )
151
+ tsnep_set_link_mode (adapter );
147
152
148
153
phy_print_status (netdev -> phydev );
149
154
}
150
155
156
+ static int tsnep_phy_loopback (struct tsnep_adapter * adapter , bool enable )
157
+ {
158
+ int retval ;
159
+
160
+ retval = phy_loopback (adapter -> phydev , enable );
161
+
162
+ /* PHY link state change is not signaled if loopback is enabled, it
163
+ * would delay a working loopback anyway, let's ensure that loopback
164
+ * is working immediately by setting link mode directly
165
+ */
166
+ if (!retval && enable )
167
+ tsnep_set_link_mode (adapter );
168
+
169
+ return retval ;
170
+ }
171
+
151
172
static int tsnep_phy_open (struct tsnep_adapter * adapter )
152
173
{
153
174
struct phy_device * phydev ;
@@ -241,14 +262,14 @@ static int tsnep_tx_ring_init(struct tsnep_tx *tx)
241
262
return retval ;
242
263
}
243
264
244
- static void tsnep_tx_activate (struct tsnep_tx * tx , int index , bool last )
265
+ static void tsnep_tx_activate (struct tsnep_tx * tx , int index , int length ,
266
+ bool last )
245
267
{
246
268
struct tsnep_tx_entry * entry = & tx -> entry [index ];
247
269
248
270
entry -> properties = 0 ;
249
271
if (entry -> skb ) {
250
- entry -> properties =
251
- skb_pagelen (entry -> skb ) & TSNEP_DESC_LENGTH_MASK ;
272
+ entry -> properties = length & TSNEP_DESC_LENGTH_MASK ;
252
273
entry -> properties |= TSNEP_DESC_INTERRUPT_FLAG ;
253
274
if (skb_shinfo (entry -> skb )-> tx_flags & SKBTX_IN_PROGRESS )
254
275
entry -> properties |= TSNEP_DESC_EXTENDED_WRITEBACK_FLAG ;
@@ -313,6 +334,7 @@ static int tsnep_tx_map(struct sk_buff *skb, struct tsnep_tx *tx, int count)
313
334
struct tsnep_tx_entry * entry ;
314
335
unsigned int len ;
315
336
dma_addr_t dma ;
337
+ int map_len = 0 ;
316
338
int i ;
317
339
318
340
for (i = 0 ; i < count ; i ++ ) {
@@ -335,15 +357,18 @@ static int tsnep_tx_map(struct sk_buff *skb, struct tsnep_tx *tx, int count)
335
357
dma_unmap_addr_set (entry , dma , dma );
336
358
337
359
entry -> desc -> tx = __cpu_to_le64 (dma );
360
+
361
+ map_len += len ;
338
362
}
339
363
340
- return 0 ;
364
+ return map_len ;
341
365
}
342
366
343
- static void tsnep_tx_unmap (struct tsnep_tx * tx , int index , int count )
367
+ static int tsnep_tx_unmap (struct tsnep_tx * tx , int index , int count )
344
368
{
345
369
struct device * dmadev = tx -> adapter -> dmadev ;
346
370
struct tsnep_tx_entry * entry ;
371
+ int map_len = 0 ;
347
372
int i ;
348
373
349
374
for (i = 0 ; i < count ; i ++ ) {
@@ -360,9 +385,12 @@ static void tsnep_tx_unmap(struct tsnep_tx *tx, int index, int count)
360
385
dma_unmap_addr (entry , dma ),
361
386
dma_unmap_len (entry , len ),
362
387
DMA_TO_DEVICE );
388
+ map_len += entry -> len ;
363
389
entry -> len = 0 ;
364
390
}
365
391
}
392
+
393
+ return map_len ;
366
394
}
367
395
368
396
static netdev_tx_t tsnep_xmit_frame_ring (struct sk_buff * skb ,
@@ -371,6 +399,7 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
371
399
unsigned long flags ;
372
400
int count = 1 ;
373
401
struct tsnep_tx_entry * entry ;
402
+ int length ;
374
403
int i ;
375
404
int retval ;
376
405
@@ -394,7 +423,7 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
394
423
entry -> skb = skb ;
395
424
396
425
retval = tsnep_tx_map (skb , tx , count );
397
- if (retval != 0 ) {
426
+ if (retval < 0 ) {
398
427
tsnep_tx_unmap (tx , tx -> write , count );
399
428
dev_kfree_skb_any (entry -> skb );
400
429
entry -> skb = NULL ;
@@ -407,12 +436,13 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
407
436
408
437
return NETDEV_TX_OK ;
409
438
}
439
+ length = retval ;
410
440
411
441
if (skb_shinfo (skb )-> tx_flags & SKBTX_HW_TSTAMP )
412
442
skb_shinfo (skb )-> tx_flags |= SKBTX_IN_PROGRESS ;
413
443
414
444
for (i = 0 ; i < count ; i ++ )
415
- tsnep_tx_activate (tx , (tx -> write + i ) % TSNEP_RING_SIZE ,
445
+ tsnep_tx_activate (tx , (tx -> write + i ) % TSNEP_RING_SIZE , length ,
416
446
i == (count - 1 ));
417
447
tx -> write = (tx -> write + count ) % TSNEP_RING_SIZE ;
418
448
@@ -428,9 +458,6 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,
428
458
netif_stop_queue (tx -> adapter -> netdev );
429
459
}
430
460
431
- tx -> packets ++ ;
432
- tx -> bytes += skb_pagelen (entry -> skb ) + ETH_FCS_LEN ;
433
-
434
461
spin_unlock_irqrestore (& tx -> lock , flags );
435
462
436
463
return NETDEV_TX_OK ;
@@ -442,6 +469,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)
442
469
int budget = 128 ;
443
470
struct tsnep_tx_entry * entry ;
444
471
int count ;
472
+ int length ;
445
473
446
474
spin_lock_irqsave (& tx -> lock , flags );
447
475
@@ -464,7 +492,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)
464
492
if (skb_shinfo (entry -> skb )-> nr_frags > 0 )
465
493
count += skb_shinfo (entry -> skb )-> nr_frags ;
466
494
467
- tsnep_tx_unmap (tx , tx -> read , count );
495
+ length = tsnep_tx_unmap (tx , tx -> read , count );
468
496
469
497
if ((skb_shinfo (entry -> skb )-> tx_flags & SKBTX_IN_PROGRESS ) &&
470
498
(__le32_to_cpu (entry -> desc_wb -> properties ) &
@@ -491,6 +519,9 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)
491
519
492
520
tx -> read = (tx -> read + count ) % TSNEP_RING_SIZE ;
493
521
522
+ tx -> packets ++ ;
523
+ tx -> bytes += length + ETH_FCS_LEN ;
524
+
494
525
budget -- ;
495
526
} while (likely (budget ));
496
527
@@ -718,6 +749,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,
718
749
hwtstamps -> netdev_data = rx_inline ;
719
750
}
720
751
skb_pull (skb , TSNEP_RX_INLINE_METADATA_SIZE );
752
+ skb_record_rx_queue (skb , rx -> queue_index );
721
753
skb -> protocol = eth_type_trans (skb ,
722
754
rx -> adapter -> netdev );
723
755
@@ -752,7 +784,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,
752
784
}
753
785
754
786
static int tsnep_rx_open (struct tsnep_adapter * adapter , void __iomem * addr ,
755
- struct tsnep_rx * rx )
787
+ int queue_index , struct tsnep_rx * rx )
756
788
{
757
789
dma_addr_t dma ;
758
790
int i ;
@@ -761,6 +793,7 @@ static int tsnep_rx_open(struct tsnep_adapter *adapter, void __iomem *addr,
761
793
memset (rx , 0 , sizeof (* rx ));
762
794
rx -> adapter = adapter ;
763
795
rx -> addr = addr ;
796
+ rx -> queue_index = queue_index ;
764
797
765
798
retval = tsnep_rx_ring_init (rx );
766
799
if (retval )
@@ -847,6 +880,7 @@ static int tsnep_netdev_open(struct net_device *netdev)
847
880
if (adapter -> queue [i ].rx ) {
848
881
addr = adapter -> addr + TSNEP_QUEUE (rx_queue_index );
849
882
retval = tsnep_rx_open (adapter , addr ,
883
+ rx_queue_index ,
850
884
adapter -> queue [i ].rx );
851
885
if (retval )
852
886
goto failed ;
@@ -1017,6 +1051,22 @@ static int tsnep_netdev_set_mac_address(struct net_device *netdev, void *addr)
1017
1051
return 0 ;
1018
1052
}
1019
1053
1054
+ static int tsnep_netdev_set_features (struct net_device * netdev ,
1055
+ netdev_features_t features )
1056
+ {
1057
+ struct tsnep_adapter * adapter = netdev_priv (netdev );
1058
+ netdev_features_t changed = netdev -> features ^ features ;
1059
+ bool enable ;
1060
+ int retval = 0 ;
1061
+
1062
+ if (changed & NETIF_F_LOOPBACK ) {
1063
+ enable = !!(features & NETIF_F_LOOPBACK );
1064
+ retval = tsnep_phy_loopback (adapter , enable );
1065
+ }
1066
+
1067
+ return retval ;
1068
+ }
1069
+
1020
1070
static ktime_t tsnep_netdev_get_tstamp (struct net_device * netdev ,
1021
1071
const struct skb_shared_hwtstamps * hwtstamps ,
1022
1072
bool cycles )
@@ -1038,9 +1088,9 @@ static const struct net_device_ops tsnep_netdev_ops = {
1038
1088
.ndo_start_xmit = tsnep_netdev_xmit_frame ,
1039
1089
.ndo_eth_ioctl = tsnep_netdev_ioctl ,
1040
1090
.ndo_set_rx_mode = tsnep_netdev_set_multicast ,
1041
-
1042
1091
.ndo_get_stats64 = tsnep_netdev_get_stats64 ,
1043
1092
.ndo_set_mac_address = tsnep_netdev_set_mac_address ,
1093
+ .ndo_set_features = tsnep_netdev_set_features ,
1044
1094
.ndo_get_tstamp = tsnep_netdev_get_tstamp ,
1045
1095
.ndo_setup_tc = tsnep_tc_setup ,
1046
1096
};
@@ -1192,6 +1242,13 @@ static int tsnep_probe(struct platform_device *pdev)
1192
1242
adapter -> queue [0 ].rx = & adapter -> rx [0 ];
1193
1243
adapter -> queue [0 ].irq_mask = ECM_INT_TX_0 | ECM_INT_RX_0 ;
1194
1244
1245
+ retval = dma_set_mask_and_coherent (& adapter -> pdev -> dev ,
1246
+ DMA_BIT_MASK (64 ));
1247
+ if (retval ) {
1248
+ dev_err (& adapter -> pdev -> dev , "no usable DMA configuration.\n" );
1249
+ return retval ;
1250
+ }
1251
+
1195
1252
tsnep_disable_irq (adapter , ECM_INT_ALL );
1196
1253
retval = devm_request_irq (& adapter -> pdev -> dev , adapter -> irq , tsnep_irq ,
1197
1254
0 , TSNEP , adapter );
@@ -1225,7 +1282,7 @@ static int tsnep_probe(struct platform_device *pdev)
1225
1282
netdev -> netdev_ops = & tsnep_netdev_ops ;
1226
1283
netdev -> ethtool_ops = & tsnep_ethtool_ops ;
1227
1284
netdev -> features = NETIF_F_SG ;
1228
- netdev -> hw_features = netdev -> features ;
1285
+ netdev -> hw_features = netdev -> features | NETIF_F_LOOPBACK ;
1229
1286
1230
1287
/* carrier off reporting is important to ethtool even BEFORE open */
1231
1288
netif_carrier_off (netdev );
0 commit comments