@@ -1065,23 +1065,18 @@ static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
10651065
10661066static int airoha_qdma_init_hfwd_queues (struct airoha_qdma * qdma )
10671067{
1068+ int size , index , num_desc = HW_DSCP_NUM ;
10681069 struct airoha_eth * eth = qdma -> eth ;
10691070 int id = qdma - & eth -> qdma [0 ];
1071+ u32 status , buf_size ;
10701072 dma_addr_t dma_addr ;
10711073 const char * name ;
1072- int size , index ;
1073- u32 status ;
1074-
1075- size = HW_DSCP_NUM * sizeof (struct airoha_qdma_fwd_desc );
1076- if (!dmam_alloc_coherent (eth -> dev , size , & dma_addr , GFP_KERNEL ))
1077- return - ENOMEM ;
1078-
1079- airoha_qdma_wr (qdma , REG_FWD_DSCP_BASE , dma_addr );
10801074
10811075 name = devm_kasprintf (eth -> dev , GFP_KERNEL , "qdma%d-buf" , id );
10821076 if (!name )
10831077 return - ENOMEM ;
10841078
1079+ buf_size = id ? AIROHA_MAX_PACKET_SIZE / 2 : AIROHA_MAX_PACKET_SIZE ;
10851080 index = of_property_match_string (eth -> dev -> of_node ,
10861081 "memory-region-names" , name );
10871082 if (index >= 0 ) {
@@ -1099,24 +1094,34 @@ static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
10991094 rmem = of_reserved_mem_lookup (np );
11001095 of_node_put (np );
11011096 dma_addr = rmem -> base ;
1097+ /* Compute the number of hw descriptors according to the
1098+ * reserved memory size and the payload buffer size
1099+ */
1100+ num_desc = div_u64 (rmem -> size , buf_size );
11021101 } else {
1103- size = AIROHA_MAX_PACKET_SIZE * HW_DSCP_NUM ;
1102+ size = buf_size * num_desc ;
11041103 if (!dmam_alloc_coherent (eth -> dev , size , & dma_addr ,
11051104 GFP_KERNEL ))
11061105 return - ENOMEM ;
11071106 }
11081107
11091108 airoha_qdma_wr (qdma , REG_FWD_BUF_BASE , dma_addr );
11101109
1110+ size = num_desc * sizeof (struct airoha_qdma_fwd_desc );
1111+ if (!dmam_alloc_coherent (eth -> dev , size , & dma_addr , GFP_KERNEL ))
1112+ return - ENOMEM ;
1113+
1114+ airoha_qdma_wr (qdma , REG_FWD_DSCP_BASE , dma_addr );
1115+ /* QDMA0: 2KB. QDMA1: 1KB */
11111116 airoha_qdma_rmw (qdma , REG_HW_FWD_DSCP_CFG ,
11121117 HW_FWD_DSCP_PAYLOAD_SIZE_MASK ,
1113- FIELD_PREP (HW_FWD_DSCP_PAYLOAD_SIZE_MASK , 0 ));
1118+ FIELD_PREP (HW_FWD_DSCP_PAYLOAD_SIZE_MASK , !! id ));
11141119 airoha_qdma_rmw (qdma , REG_FWD_DSCP_LOW_THR , FWD_DSCP_LOW_THR_MASK ,
11151120 FIELD_PREP (FWD_DSCP_LOW_THR_MASK , 128 ));
11161121 airoha_qdma_rmw (qdma , REG_LMGR_INIT_CFG ,
11171122 LMGR_INIT_START | LMGR_SRAM_MODE_MASK |
11181123 HW_FWD_DESC_NUM_MASK ,
1119- FIELD_PREP (HW_FWD_DESC_NUM_MASK , HW_DSCP_NUM ) |
1124+ FIELD_PREP (HW_FWD_DESC_NUM_MASK , num_desc ) |
11201125 LMGR_INIT_START | LMGR_SRAM_MODE_MASK );
11211126
11221127 return read_poll_timeout (airoha_qdma_rr , status ,
0 commit comments