@@ -278,92 +278,6 @@ static void ftgmac100_stop_hw(struct ftgmac100 *priv)
278
278
iowrite32 (0 , priv -> base + FTGMAC100_OFFSET_MACCR );
279
279
}
280
280
281
- static bool ftgmac100_rxdes_first_segment (struct ftgmac100_rxdes * rxdes )
282
- {
283
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_FRS );
284
- }
285
-
286
- static bool ftgmac100_rxdes_last_segment (struct ftgmac100_rxdes * rxdes )
287
- {
288
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_LRS );
289
- }
290
-
291
- static bool ftgmac100_rxdes_packet_ready (struct ftgmac100_rxdes * rxdes )
292
- {
293
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_RXPKT_RDY );
294
- }
295
-
296
- #define RXDES0_ANY_ERROR ( \
297
- FTGMAC100_RXDES0_RX_ERR | \
298
- FTGMAC100_RXDES0_CRC_ERR | \
299
- FTGMAC100_RXDES0_FTL | \
300
- FTGMAC100_RXDES0_RUNT | \
301
- FTGMAC100_RXDES0_RX_ODD_NB)
302
-
303
- static inline bool ftgmac100_rxdes_any_error (struct ftgmac100_rxdes * rxdes )
304
- {
305
- return rxdes -> rxdes0 & cpu_to_le32 (RXDES0_ANY_ERROR );
306
- }
307
-
308
- static bool ftgmac100_rxdes_rx_error (struct ftgmac100_rxdes * rxdes )
309
- {
310
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_RX_ERR );
311
- }
312
-
313
- static bool ftgmac100_rxdes_crc_error (struct ftgmac100_rxdes * rxdes )
314
- {
315
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_CRC_ERR );
316
- }
317
-
318
- static bool ftgmac100_rxdes_frame_too_long (struct ftgmac100_rxdes * rxdes )
319
- {
320
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_FTL );
321
- }
322
-
323
- static bool ftgmac100_rxdes_runt (struct ftgmac100_rxdes * rxdes )
324
- {
325
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_RUNT );
326
- }
327
-
328
- static bool ftgmac100_rxdes_odd_nibble (struct ftgmac100_rxdes * rxdes )
329
- {
330
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_RX_ODD_NB );
331
- }
332
-
333
- static unsigned int ftgmac100_rxdes_data_length (struct ftgmac100_rxdes * rxdes )
334
- {
335
- return le32_to_cpu (rxdes -> rxdes0 ) & FTGMAC100_RXDES0_VDBC ;
336
- }
337
-
338
- static bool ftgmac100_rxdes_multicast (struct ftgmac100_rxdes * rxdes )
339
- {
340
- return rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_MULTICAST );
341
- }
342
-
343
- static void ftgmac100_rxdes_set_end_of_ring (const struct ftgmac100 * priv ,
344
- struct ftgmac100_rxdes * rxdes )
345
- {
346
- rxdes -> rxdes0 |= cpu_to_le32 (priv -> rxdes0_edorr_mask );
347
- }
348
-
349
- static void ftgmac100_rxdes_set_dma_addr (struct ftgmac100_rxdes * rxdes ,
350
- dma_addr_t addr )
351
- {
352
- rxdes -> rxdes3 = cpu_to_le32 (addr );
353
- }
354
-
355
- static dma_addr_t ftgmac100_rxdes_get_dma_addr (struct ftgmac100_rxdes * rxdes )
356
- {
357
- return le32_to_cpu (rxdes -> rxdes3 );
358
- }
359
-
360
- static inline bool ftgmac100_rxdes_csum_err (struct ftgmac100_rxdes * rxdes )
361
- {
362
- return !!(rxdes -> rxdes1 & cpu_to_le32 (FTGMAC100_RXDES1_TCP_CHKSUM_ERR |
363
- FTGMAC100_RXDES1_UDP_CHKSUM_ERR |
364
- FTGMAC100_RXDES1_IP_CHKSUM_ERR ));
365
- }
366
-
367
281
static int ftgmac100_alloc_rx_buf (struct ftgmac100 * priv , unsigned int entry ,
368
282
struct ftgmac100_rxdes * rxdes , gfp_t gfp )
369
283
{
@@ -395,13 +309,16 @@ static int ftgmac100_alloc_rx_buf(struct ftgmac100 *priv, unsigned int entry,
395
309
priv -> rx_skbs [entry ] = skb ;
396
310
397
311
/* Store DMA address into RX desc */
398
- ftgmac100_rxdes_set_dma_addr ( rxdes , map );
312
+ rxdes -> rxdes3 = cpu_to_le32 ( map );
399
313
400
314
/* Ensure the above is ordered vs clearing the OWN bit */
401
315
dma_wmb ();
402
316
403
- /* Clean rxdes0 (which resets own bit) */
404
- rxdes -> rxdes0 &= cpu_to_le32 (priv -> rxdes0_edorr_mask );
317
+ /* Clean status (which resets own bit) */
318
+ if (entry == (RX_QUEUE_ENTRIES - 1 ))
319
+ rxdes -> rxdes0 = cpu_to_le32 (priv -> rxdes0_edorr_mask );
320
+ else
321
+ rxdes -> rxdes0 = 0 ;
405
322
406
323
return 0 ;
407
324
}
@@ -411,20 +328,19 @@ static int ftgmac100_next_rx_pointer(int pointer)
411
328
return (pointer + 1 ) & (RX_QUEUE_ENTRIES - 1 );
412
329
}
413
330
414
- static void ftgmac100_rx_packet_error (struct ftgmac100 * priv ,
415
- struct ftgmac100_rxdes * rxdes )
331
+ static void ftgmac100_rx_packet_error (struct ftgmac100 * priv , u32 status )
416
332
{
417
333
struct net_device * netdev = priv -> netdev ;
418
334
419
- if (ftgmac100_rxdes_rx_error ( rxdes ) )
335
+ if (status & FTGMAC100_RXDES0_RX_ERR )
420
336
netdev -> stats .rx_errors ++ ;
421
337
422
- if (ftgmac100_rxdes_crc_error ( rxdes ) )
338
+ if (status & FTGMAC100_RXDES0_CRC_ERR )
423
339
netdev -> stats .rx_crc_errors ++ ;
424
340
425
- if (ftgmac100_rxdes_frame_too_long ( rxdes ) | |
426
- ftgmac100_rxdes_runt ( rxdes ) | |
427
- ftgmac100_rxdes_odd_nibble ( rxdes ))
341
+ if (status & ( FTGMAC100_RXDES0_FTL |
342
+ FTGMAC100_RXDES0_RUNT |
343
+ FTGMAC100_RXDES0_RX_ODD_NB ))
428
344
netdev -> stats .rx_length_errors ++ ;
429
345
}
430
346
@@ -434,27 +350,31 @@ static bool ftgmac100_rx_packet(struct ftgmac100 *priv, int *processed)
434
350
struct ftgmac100_rxdes * rxdes ;
435
351
struct sk_buff * skb ;
436
352
unsigned int pointer , size ;
353
+ u32 status ;
437
354
dma_addr_t map ;
438
355
439
356
/* Grab next RX descriptor */
440
357
pointer = priv -> rx_pointer ;
441
358
rxdes = & priv -> descs -> rxdes [pointer ];
442
359
360
+ /* Grab descriptor status */
361
+ status = le32_to_cpu (rxdes -> rxdes0 );
362
+
443
363
/* Do we have a packet ? */
444
- if (!ftgmac100_rxdes_packet_ready ( rxdes ))
364
+ if (!( status & FTGMAC100_RXDES0_RXPKT_RDY ))
445
365
return false;
446
366
447
367
/* Order subsequent reads with the test for the ready bit */
448
368
dma_rmb ();
449
369
450
370
/* We don't cope with fragmented RX packets */
451
- if (unlikely (!ftgmac100_rxdes_first_segment ( rxdes ) ||
452
- !ftgmac100_rxdes_last_segment ( rxdes )))
371
+ if (unlikely (!( status & FTGMAC100_RXDES0_FRS ) ||
372
+ !( status & FTGMAC100_RXDES0_LRS )))
453
373
goto drop ;
454
374
455
375
/* Any error (other than csum offload) flagged ? */
456
- if (unlikely (ftgmac100_rxdes_any_error ( rxdes ) )) {
457
- ftgmac100_rx_packet_error (priv , rxdes );
376
+ if (unlikely (status & RXDES0_ANY_ERROR )) {
377
+ ftgmac100_rx_packet_error (priv , status );
458
378
goto drop ;
459
379
}
460
380
@@ -467,7 +387,7 @@ static bool ftgmac100_rx_packet(struct ftgmac100 *priv, int *processed)
467
387
goto drop ;
468
388
}
469
389
470
- if (unlikely (ftgmac100_rxdes_multicast ( rxdes ) ))
390
+ if (unlikely (status & FTGMAC100_RXDES0_MULTICAST ))
471
391
netdev -> stats .multicast ++ ;
472
392
473
393
/* If the HW found checksum errors, bounce it to software.
@@ -489,11 +409,12 @@ static bool ftgmac100_rx_packet(struct ftgmac100 *priv, int *processed)
489
409
}
490
410
491
411
/* Grab received size annd transfer to skb */
492
- size = ftgmac100_rxdes_data_length ( rxdes ) ;
412
+ size = status & FTGMAC100_RXDES0_VDBC ;
493
413
skb_put (skb , size );
494
414
495
415
/* Tear down DMA mapping, do necessary cache management */
496
- map = ftgmac100_rxdes_get_dma_addr (rxdes );
416
+ map = le32_to_cpu (rxdes -> rxdes3 );
417
+
497
418
#if defined(CONFIG_ARM ) && !defined(CONFIG_ARM_DMA_USE_IOMMU )
498
419
/* When we don't have an iommu, we can save cycles by not
499
420
* invalidating the cache for the part of the packet that
@@ -525,7 +446,7 @@ static bool ftgmac100_rx_packet(struct ftgmac100 *priv, int *processed)
525
446
526
447
drop :
527
448
/* Clean rxdes0 (which resets own bit) */
528
- rxdes -> rxdes0 & = cpu_to_le32 (priv -> rxdes0_edorr_mask );
449
+ rxdes -> rxdes0 = cpu_to_le32 (status & priv -> rxdes0_edorr_mask );
529
450
priv -> rx_pointer = ftgmac100_next_rx_pointer (pointer );
530
451
netdev -> stats .rx_dropped ++ ;
531
452
return true;
@@ -747,7 +668,7 @@ static void ftgmac100_free_buffers(struct ftgmac100 *priv)
747
668
for (i = 0 ; i < RX_QUEUE_ENTRIES ; i ++ ) {
748
669
struct ftgmac100_rxdes * rxdes = & priv -> descs -> rxdes [i ];
749
670
struct sk_buff * skb = priv -> rx_skbs [i ];
750
- dma_addr_t map = ftgmac100_rxdes_get_dma_addr (rxdes );
671
+ dma_addr_t map = le32_to_cpu (rxdes -> rxdes3 );
751
672
752
673
if (!skb )
753
674
continue ;
@@ -806,15 +727,17 @@ static int ftgmac100_alloc_rings(struct ftgmac100 *priv)
806
727
807
728
static void ftgmac100_init_rings (struct ftgmac100 * priv )
808
729
{
730
+ struct ftgmac100_rxdes * rxdes ;
809
731
int i ;
810
732
811
733
/* Initialize RX ring */
812
734
for (i = 0 ; i < RX_QUEUE_ENTRIES ; i ++ ) {
813
- struct ftgmac100_rxdes * rxdes = & priv -> descs -> rxdes [i ];
814
- ftgmac100_rxdes_set_dma_addr (rxdes , priv -> rx_scratch_dma );
735
+ rxdes = & priv -> descs -> rxdes [i ];
815
736
rxdes -> rxdes0 = 0 ;
737
+ rxdes -> rxdes3 = cpu_to_le32 (priv -> rx_scratch_dma );
816
738
}
817
- ftgmac100_rxdes_set_end_of_ring (priv , & priv -> descs -> rxdes [i - 1 ]);
739
+ /* Mark the end of the ring */
740
+ rxdes -> rxdes0 |= cpu_to_le32 (priv -> rxdes0_edorr_mask );
818
741
819
742
/* Initialize TX ring */
820
743
for (i = 0 ; i < TX_QUEUE_ENTRIES ; i ++ )
@@ -1030,6 +953,14 @@ static irqreturn_t ftgmac100_interrupt(int irq, void *dev_id)
1030
953
return IRQ_HANDLED ;
1031
954
}
1032
955
956
+ static bool ftgmac100_check_rx (struct ftgmac100 * priv )
957
+ {
958
+ struct ftgmac100_rxdes * rxdes = & priv -> descs -> rxdes [priv -> rx_pointer ];
959
+
960
+ /* Do we have a packet ? */
961
+ return !!(rxdes -> rxdes0 & cpu_to_le32 (FTGMAC100_RXDES0_RXPKT_RDY ));
962
+ }
963
+
1033
964
static int ftgmac100_poll (struct napi_struct * napi , int budget )
1034
965
{
1035
966
struct ftgmac100 * priv = container_of (napi , struct ftgmac100 , napi );
@@ -1069,8 +1000,7 @@ static int ftgmac100_poll(struct napi_struct *napi, int budget)
1069
1000
*/
1070
1001
iowrite32 (FTGMAC100_INT_RXTX ,
1071
1002
priv -> base + FTGMAC100_OFFSET_ISR );
1072
- if (ftgmac100_rxdes_packet_ready
1073
- (ftgmac100_current_rxdes (priv )) || priv -> tx_pending )
1003
+ if (ftgmac100_check_rx (priv ) || priv -> tx_pending )
1074
1004
return budget ;
1075
1005
1076
1006
/* deschedule NAPI */
0 commit comments