136
136
NETIF_MSG_IFUP | NETIF_MSG_PROBE | NETIF_MSG_IFDOWN | \
137
137
NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
138
138
139
+ #define AM65_CPSW_DEFAULT_TX_CHNS 8
140
+
139
141
static void am65_cpsw_port_set_sl_mac (struct am65_cpsw_port * slave ,
140
142
const u8 * dev_addr )
141
143
{
@@ -367,10 +369,81 @@ static void am65_cpsw_init_host_port_emac(struct am65_cpsw_common *common);
367
369
static void am65_cpsw_init_port_switch_ale (struct am65_cpsw_port * port );
368
370
static void am65_cpsw_init_port_emac_ale (struct am65_cpsw_port * port );
369
371
372
+ static void am65_cpsw_nuss_rx_cleanup (void * data , dma_addr_t desc_dma )
373
+ {
374
+ struct am65_cpsw_rx_chn * rx_chn = data ;
375
+ struct cppi5_host_desc_t * desc_rx ;
376
+ struct sk_buff * skb ;
377
+ dma_addr_t buf_dma ;
378
+ u32 buf_dma_len ;
379
+ void * * swdata ;
380
+
381
+ desc_rx = k3_cppi_desc_pool_dma2virt (rx_chn -> desc_pool , desc_dma );
382
+ swdata = cppi5_hdesc_get_swdata (desc_rx );
383
+ skb = * swdata ;
384
+ cppi5_hdesc_get_obuf (desc_rx , & buf_dma , & buf_dma_len );
385
+ k3_udma_glue_rx_cppi5_to_dma_addr (rx_chn -> rx_chn , & buf_dma );
386
+
387
+ dma_unmap_single (rx_chn -> dma_dev , buf_dma , buf_dma_len , DMA_FROM_DEVICE );
388
+ k3_cppi_desc_pool_free (rx_chn -> desc_pool , desc_rx );
389
+
390
+ dev_kfree_skb_any (skb );
391
+ }
392
+
393
+ static void am65_cpsw_nuss_xmit_free (struct am65_cpsw_tx_chn * tx_chn ,
394
+ struct cppi5_host_desc_t * desc )
395
+ {
396
+ struct cppi5_host_desc_t * first_desc , * next_desc ;
397
+ dma_addr_t buf_dma , next_desc_dma ;
398
+ u32 buf_dma_len ;
399
+
400
+ first_desc = desc ;
401
+ next_desc = first_desc ;
402
+
403
+ cppi5_hdesc_get_obuf (first_desc , & buf_dma , & buf_dma_len );
404
+ k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & buf_dma );
405
+
406
+ dma_unmap_single (tx_chn -> dma_dev , buf_dma , buf_dma_len , DMA_TO_DEVICE );
407
+
408
+ next_desc_dma = cppi5_hdesc_get_next_hbdesc (first_desc );
409
+ k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & next_desc_dma );
410
+ while (next_desc_dma ) {
411
+ next_desc = k3_cppi_desc_pool_dma2virt (tx_chn -> desc_pool ,
412
+ next_desc_dma );
413
+ cppi5_hdesc_get_obuf (next_desc , & buf_dma , & buf_dma_len );
414
+ k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & buf_dma );
415
+
416
+ dma_unmap_page (tx_chn -> dma_dev , buf_dma , buf_dma_len ,
417
+ DMA_TO_DEVICE );
418
+
419
+ next_desc_dma = cppi5_hdesc_get_next_hbdesc (next_desc );
420
+ k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & next_desc_dma );
421
+
422
+ k3_cppi_desc_pool_free (tx_chn -> desc_pool , next_desc );
423
+ }
424
+
425
+ k3_cppi_desc_pool_free (tx_chn -> desc_pool , first_desc );
426
+ }
427
+
428
+ static void am65_cpsw_nuss_tx_cleanup (void * data , dma_addr_t desc_dma )
429
+ {
430
+ struct am65_cpsw_tx_chn * tx_chn = data ;
431
+ struct cppi5_host_desc_t * desc_tx ;
432
+ struct sk_buff * skb ;
433
+ void * * swdata ;
434
+
435
+ desc_tx = k3_cppi_desc_pool_dma2virt (tx_chn -> desc_pool , desc_dma );
436
+ swdata = cppi5_hdesc_get_swdata (desc_tx );
437
+ skb = * (swdata );
438
+ am65_cpsw_nuss_xmit_free (tx_chn , desc_tx );
439
+
440
+ dev_kfree_skb_any (skb );
441
+ }
442
+
370
443
static int am65_cpsw_nuss_common_open (struct am65_cpsw_common * common )
371
444
{
372
445
struct am65_cpsw_host * host_p = am65_common_get_host (common );
373
- int port_idx , i , ret ;
446
+ int port_idx , i , ret , tx ;
374
447
struct sk_buff * skb ;
375
448
u32 val , port_mask ;
376
449
@@ -437,8 +510,12 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)
437
510
AM65_CPSW_MAX_PACKET_SIZE ,
438
511
GFP_KERNEL );
439
512
if (!skb ) {
513
+ ret = - ENOMEM ;
440
514
dev_err (common -> dev , "cannot allocate skb\n" );
441
- return - ENOMEM ;
515
+ if (i )
516
+ goto fail_rx ;
517
+
518
+ return ret ;
442
519
}
443
520
444
521
ret = am65_cpsw_nuss_rx_push (common , skb );
@@ -447,17 +524,28 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)
447
524
"cannot submit skb to channel rx, error %d\n" ,
448
525
ret );
449
526
kfree_skb (skb );
527
+ if (i )
528
+ goto fail_rx ;
529
+
450
530
return ret ;
451
531
}
452
- kmemleak_not_leak (skb );
453
532
}
454
- k3_udma_glue_enable_rx_chn (common -> rx_chns .rx_chn );
455
533
456
- for (i = 0 ; i < common -> tx_ch_num ; i ++ ) {
457
- ret = k3_udma_glue_enable_tx_chn (common -> tx_chns [i ].tx_chn );
458
- if (ret )
459
- return ret ;
460
- napi_enable (& common -> tx_chns [i ].napi_tx );
534
+ ret = k3_udma_glue_enable_rx_chn (common -> rx_chns .rx_chn );
535
+ if (ret ) {
536
+ dev_err (common -> dev , "couldn't enable rx chn: %d\n" , ret );
537
+ goto fail_rx ;
538
+ }
539
+
540
+ for (tx = 0 ; tx < common -> tx_ch_num ; tx ++ ) {
541
+ ret = k3_udma_glue_enable_tx_chn (common -> tx_chns [tx ].tx_chn );
542
+ if (ret ) {
543
+ dev_err (common -> dev , "couldn't enable tx chn %d: %d\n" ,
544
+ tx , ret );
545
+ tx -- ;
546
+ goto fail_tx ;
547
+ }
548
+ napi_enable (& common -> tx_chns [tx ].napi_tx );
461
549
}
462
550
463
551
napi_enable (& common -> napi_rx );
@@ -468,10 +556,22 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)
468
556
469
557
dev_dbg (common -> dev , "cpsw_nuss started\n" );
470
558
return 0 ;
471
- }
472
559
473
- static void am65_cpsw_nuss_tx_cleanup (void * data , dma_addr_t desc_dma );
474
- static void am65_cpsw_nuss_rx_cleanup (void * data , dma_addr_t desc_dma );
560
+ fail_tx :
561
+ while (tx >= 0 ) {
562
+ napi_disable (& common -> tx_chns [tx ].napi_tx );
563
+ k3_udma_glue_disable_tx_chn (common -> tx_chns [tx ].tx_chn );
564
+ tx -- ;
565
+ }
566
+
567
+ k3_udma_glue_disable_rx_chn (common -> rx_chns .rx_chn );
568
+
569
+ fail_rx :
570
+ k3_udma_glue_reset_rx_chn (common -> rx_chns .rx_chn , 0 ,
571
+ & common -> rx_chns ,
572
+ am65_cpsw_nuss_rx_cleanup , 0 );
573
+ return ret ;
574
+ }
475
575
476
576
static int am65_cpsw_nuss_common_stop (struct am65_cpsw_common * common )
477
577
{
@@ -646,27 +746,6 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)
646
746
return ret ;
647
747
}
648
748
649
- static void am65_cpsw_nuss_rx_cleanup (void * data , dma_addr_t desc_dma )
650
- {
651
- struct am65_cpsw_rx_chn * rx_chn = data ;
652
- struct cppi5_host_desc_t * desc_rx ;
653
- struct sk_buff * skb ;
654
- dma_addr_t buf_dma ;
655
- u32 buf_dma_len ;
656
- void * * swdata ;
657
-
658
- desc_rx = k3_cppi_desc_pool_dma2virt (rx_chn -> desc_pool , desc_dma );
659
- swdata = cppi5_hdesc_get_swdata (desc_rx );
660
- skb = * swdata ;
661
- cppi5_hdesc_get_obuf (desc_rx , & buf_dma , & buf_dma_len );
662
- k3_udma_glue_rx_cppi5_to_dma_addr (rx_chn -> rx_chn , & buf_dma );
663
-
664
- dma_unmap_single (rx_chn -> dma_dev , buf_dma , buf_dma_len , DMA_FROM_DEVICE );
665
- k3_cppi_desc_pool_free (rx_chn -> desc_pool , desc_rx );
666
-
667
- dev_kfree_skb_any (skb );
668
- }
669
-
670
749
static void am65_cpsw_nuss_rx_ts (struct sk_buff * skb , u32 * psdata )
671
750
{
672
751
struct skb_shared_hwtstamps * ssh ;
@@ -840,56 +919,6 @@ static int am65_cpsw_nuss_rx_poll(struct napi_struct *napi_rx, int budget)
840
919
return num_rx ;
841
920
}
842
921
843
- static void am65_cpsw_nuss_xmit_free (struct am65_cpsw_tx_chn * tx_chn ,
844
- struct cppi5_host_desc_t * desc )
845
- {
846
- struct cppi5_host_desc_t * first_desc , * next_desc ;
847
- dma_addr_t buf_dma , next_desc_dma ;
848
- u32 buf_dma_len ;
849
-
850
- first_desc = desc ;
851
- next_desc = first_desc ;
852
-
853
- cppi5_hdesc_get_obuf (first_desc , & buf_dma , & buf_dma_len );
854
- k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & buf_dma );
855
-
856
- dma_unmap_single (tx_chn -> dma_dev , buf_dma , buf_dma_len , DMA_TO_DEVICE );
857
-
858
- next_desc_dma = cppi5_hdesc_get_next_hbdesc (first_desc );
859
- k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & next_desc_dma );
860
- while (next_desc_dma ) {
861
- next_desc = k3_cppi_desc_pool_dma2virt (tx_chn -> desc_pool ,
862
- next_desc_dma );
863
- cppi5_hdesc_get_obuf (next_desc , & buf_dma , & buf_dma_len );
864
- k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & buf_dma );
865
-
866
- dma_unmap_page (tx_chn -> dma_dev , buf_dma , buf_dma_len ,
867
- DMA_TO_DEVICE );
868
-
869
- next_desc_dma = cppi5_hdesc_get_next_hbdesc (next_desc );
870
- k3_udma_glue_tx_cppi5_to_dma_addr (tx_chn -> tx_chn , & next_desc_dma );
871
-
872
- k3_cppi_desc_pool_free (tx_chn -> desc_pool , next_desc );
873
- }
874
-
875
- k3_cppi_desc_pool_free (tx_chn -> desc_pool , first_desc );
876
- }
877
-
878
- static void am65_cpsw_nuss_tx_cleanup (void * data , dma_addr_t desc_dma )
879
- {
880
- struct am65_cpsw_tx_chn * tx_chn = data ;
881
- struct cppi5_host_desc_t * desc_tx ;
882
- struct sk_buff * skb ;
883
- void * * swdata ;
884
-
885
- desc_tx = k3_cppi_desc_pool_dma2virt (tx_chn -> desc_pool , desc_dma );
886
- swdata = cppi5_hdesc_get_swdata (desc_tx );
887
- skb = * (swdata );
888
- am65_cpsw_nuss_xmit_free (tx_chn , desc_tx );
889
-
890
- dev_kfree_skb_any (skb );
891
- }
892
-
893
922
static struct sk_buff *
894
923
am65_cpsw_nuss_tx_compl_packet (struct am65_cpsw_tx_chn * tx_chn ,
895
924
dma_addr_t desc_dma )
@@ -2897,7 +2926,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
2897
2926
2898
2927
common -> rx_flow_id_base = -1 ;
2899
2928
init_completion (& common -> tdown_complete );
2900
- common -> tx_ch_num = 1 ;
2929
+ common -> tx_ch_num = AM65_CPSW_DEFAULT_TX_CHNS ;
2901
2930
common -> pf_p0_rx_ptype_rrobin = false;
2902
2931
common -> default_vlan = 1 ;
2903
2932
0 commit comments