5454/* Default highest priority queue for multi queue support */
5555#define GENET_Q0_PRIORITY 0
5656
57- #define GENET_DEFAULT_BD_CNT \
58- (TOTAL_DESC - priv->hw_params->tx_queues * priv->hw_params->bds_cnt )
57+ #define GENET_Q16_TX_BD_CNT \
58+ (TOTAL_DESC - priv->hw_params->tx_queues * priv->hw_params->tx_bds_per_q )
5959
6060#define RX_BUF_LENGTH 2048
6161#define SKB_ALIGNMENT 32
@@ -920,7 +920,7 @@ static struct enet_cb *bcmgenet_get_txcb(struct bcmgenet_priv *priv,
920920
921921 tx_cb_ptr = ring -> cbs ;
922922 tx_cb_ptr += ring -> write_ptr - ring -> cb_ptr ;
923- tx_cb_ptr -> bd_addr = priv -> tx_bds + ring -> write_ptr * DMA_DESC_SIZE ;
923+
924924 /* Advancing local write pointer */
925925 if (ring -> write_ptr == ring -> end_ptr )
926926 ring -> write_ptr = ring -> cb_ptr ;
@@ -1680,17 +1680,14 @@ static int init_umac(struct bcmgenet_priv *priv)
16801680 return 0 ;
16811681}
16821682
1683- /* Initialize all house-keeping variables for a TX ring, along
1684- * with corresponding hardware registers
1685- */
1683+ /* Initialize a Tx ring along with corresponding hardware registers */
16861684static void bcmgenet_init_tx_ring (struct bcmgenet_priv * priv ,
16871685 unsigned int index , unsigned int size ,
1688- unsigned int write_ptr , unsigned int end_ptr )
1686+ unsigned int start_ptr , unsigned int end_ptr )
16891687{
16901688 struct bcmgenet_tx_ring * ring = & priv -> tx_rings [index ];
16911689 u32 words_per_bd = WORDS_PER_BD (priv );
16921690 u32 flow_period_val = 0 ;
1693- unsigned int first_bd ;
16941691
16951692 spin_lock_init (& ring -> lock );
16961693 ring -> index = index ;
@@ -1703,12 +1700,12 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
17031700 ring -> int_enable = bcmgenet_tx_ring_int_enable ;
17041701 ring -> int_disable = bcmgenet_tx_ring_int_disable ;
17051702 }
1706- ring -> cbs = priv -> tx_cbs + write_ptr ;
1703+ ring -> cbs = priv -> tx_cbs + start_ptr ;
17071704 ring -> size = size ;
17081705 ring -> c_index = 0 ;
17091706 ring -> free_bds = size ;
1710- ring -> write_ptr = write_ptr ;
1711- ring -> cb_ptr = write_ptr ;
1707+ ring -> write_ptr = start_ptr ;
1708+ ring -> cb_ptr = start_ptr ;
17121709 ring -> end_ptr = end_ptr - 1 ;
17131710 ring -> prod_index = 0 ;
17141711
@@ -1722,19 +1719,16 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
17221719 /* Disable rate control for now */
17231720 bcmgenet_tdma_ring_writel (priv , index , flow_period_val ,
17241721 TDMA_FLOW_PERIOD );
1725- /* Unclassified traffic goes to ring 16 */
17261722 bcmgenet_tdma_ring_writel (priv , index ,
17271723 ((size << DMA_RING_SIZE_SHIFT ) |
17281724 RX_BUF_LENGTH ), DMA_RING_BUF_SIZE );
17291725
1730- first_bd = write_ptr ;
1731-
17321726 /* Set start and end address, read and write pointers */
1733- bcmgenet_tdma_ring_writel (priv , index , first_bd * words_per_bd ,
1727+ bcmgenet_tdma_ring_writel (priv , index , start_ptr * words_per_bd ,
17341728 DMA_START_ADDR );
1735- bcmgenet_tdma_ring_writel (priv , index , first_bd * words_per_bd ,
1729+ bcmgenet_tdma_ring_writel (priv , index , start_ptr * words_per_bd ,
17361730 TDMA_READ_PTR );
1737- bcmgenet_tdma_ring_writel (priv , index , first_bd ,
1731+ bcmgenet_tdma_ring_writel (priv , index , start_ptr * words_per_bd ,
17381732 TDMA_WRITE_PTR );
17391733 bcmgenet_tdma_ring_writel (priv , index , end_ptr * words_per_bd - 1 ,
17401734 DMA_END_ADDR );
@@ -1782,78 +1776,73 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
17821776 return ret ;
17831777}
17841778
1785- /* init multi xmit queues, only available for GENET2+
1786- * the queue is partitioned as follows:
1779+ /* Initialize Tx queues
17871780 *
1788- * queue 0 - 3 is priority based, each one has 32 descriptors,
1781+ * Queues 0-3 are priority- based, each one has 32 descriptors,
17891782 * with queue 0 being the highest priority queue.
17901783 *
1791- * queue 16 is the default tx queue with GENET_DEFAULT_BD_CNT
1792- * descriptors: 256 - (number of tx queues * bds per queues) = 128
1793- * descriptors.
1784+ * Queue 16 is the default Tx queue with
1785+ * GENET_Q16_TX_BD_CNT = 256 - 4 * 32 = 128 descriptors.
17941786 *
1795- * The transmit control block pool is then partitioned as following :
1796- * - tx_cbs[0...127] are for queue 16
1797- * - tx_ring_cbs[0] points to tx_cbs[128..159 ]
1798- * - tx_ring_cbs[1] points to tx_cbs[160..191 ]
1799- * - tx_ring_cbs[2] points to tx_cbs[192..223 ]
1800- * - tx_ring_cbs[3] points to tx_cbs[224 ..255]
1787+ * The transmit control block pool is then partitioned as follows :
1788+ * - Tx queue 0 uses tx_cbs[0..31]
1789+ * - Tx queue 1 uses tx_cbs[32..63 ]
1790+ * - Tx queue 2 uses tx_cbs[64..95 ]
1791+ * - Tx queue 3 uses tx_cbs[96..127 ]
1792+ * - Tx queue 16 uses tx_cbs[128 ..255]
18011793 */
1802- static void bcmgenet_init_multiq (struct net_device * dev )
1794+ static void bcmgenet_init_tx_queues (struct net_device * dev )
18031795{
18041796 struct bcmgenet_priv * priv = netdev_priv (dev );
1805- unsigned int i , dma_enable ;
1806- u32 reg , dma_ctrl , ring_cfg = 0 ;
1797+ u32 i , dma_enable ;
1798+ u32 dma_ctrl , ring_cfg ;
18071799 u32 dma_priority [3 ] = {0 , 0 , 0 };
18081800
1809- if (!netif_is_multiqueue (dev )) {
1810- netdev_warn (dev , "called with non multi queue aware HW\n" );
1811- return ;
1812- }
1813-
18141801 dma_ctrl = bcmgenet_tdma_readl (priv , DMA_CTRL );
18151802 dma_enable = dma_ctrl & DMA_EN ;
18161803 dma_ctrl &= ~DMA_EN ;
18171804 bcmgenet_tdma_writel (priv , dma_ctrl , DMA_CTRL );
18181805
1806+ dma_ctrl = 0 ;
1807+ ring_cfg = 0 ;
1808+
18191809 /* Enable strict priority arbiter mode */
18201810 bcmgenet_tdma_writel (priv , DMA_ARBITER_SP , DMA_ARB_CTRL );
18211811
1812+ /* Initialize Tx priority queues */
18221813 for (i = 0 ; i < priv -> hw_params -> tx_queues ; i ++ ) {
1823- /* first 64 tx_cbs are reserved for default tx queue
1824- * (ring 16)
1825- */
1826- bcmgenet_init_tx_ring (priv , i , priv -> hw_params -> bds_cnt ,
1827- i * priv -> hw_params -> bds_cnt ,
1828- (i + 1 ) * priv -> hw_params -> bds_cnt );
1829-
1830- /* Configure ring as descriptor ring and setup priority */
1831- ring_cfg |= 1 << i ;
1832- dma_ctrl |= 1 << (i + DMA_RING_BUF_EN_SHIFT );
1833-
1814+ bcmgenet_init_tx_ring (priv , i , priv -> hw_params -> tx_bds_per_q ,
1815+ i * priv -> hw_params -> tx_bds_per_q ,
1816+ (i + 1 ) * priv -> hw_params -> tx_bds_per_q );
1817+ ring_cfg |= (1 << i );
1818+ dma_ctrl |= (1 << (i + DMA_RING_BUF_EN_SHIFT ));
18341819 dma_priority [DMA_PRIO_REG_INDEX (i )] |=
18351820 ((GENET_Q0_PRIORITY + i ) << DMA_PRIO_REG_SHIFT (i ));
18361821 }
18371822
1838- /* Set ring 16 priority and program the hardware registers */
1823+ /* Initialize Tx default queue 16 */
1824+ bcmgenet_init_tx_ring (priv , DESC_INDEX , GENET_Q16_TX_BD_CNT ,
1825+ priv -> hw_params -> tx_queues *
1826+ priv -> hw_params -> tx_bds_per_q ,
1827+ TOTAL_DESC );
1828+ ring_cfg |= (1 << DESC_INDEX );
1829+ dma_ctrl |= (1 << (DESC_INDEX + DMA_RING_BUF_EN_SHIFT ));
18391830 dma_priority [DMA_PRIO_REG_INDEX (DESC_INDEX )] |=
18401831 ((GENET_Q0_PRIORITY + priv -> hw_params -> tx_queues ) <<
18411832 DMA_PRIO_REG_SHIFT (DESC_INDEX ));
1833+
1834+ /* Set Tx queue priorities */
18421835 bcmgenet_tdma_writel (priv , dma_priority [0 ], DMA_PRIORITY_0 );
18431836 bcmgenet_tdma_writel (priv , dma_priority [1 ], DMA_PRIORITY_1 );
18441837 bcmgenet_tdma_writel (priv , dma_priority [2 ], DMA_PRIORITY_2 );
18451838
1846- /* Enable rings */
1847- reg = bcmgenet_tdma_readl (priv , DMA_RING_CFG );
1848- reg |= ring_cfg ;
1849- bcmgenet_tdma_writel (priv , reg , DMA_RING_CFG );
1839+ /* Enable Tx queues */
1840+ bcmgenet_tdma_writel (priv , ring_cfg , DMA_RING_CFG );
18501841
1851- /* Configure ring as descriptor ring and re-enable DMA if enabled */
1852- reg = bcmgenet_tdma_readl (priv , DMA_CTRL );
1853- reg |= dma_ctrl ;
1842+ /* Enable Tx DMA */
18541843 if (dma_enable )
1855- reg |= DMA_EN ;
1856- bcmgenet_tdma_writel (priv , reg , DMA_CTRL );
1844+ dma_ctrl |= DMA_EN ;
1845+ bcmgenet_tdma_writel (priv , dma_ctrl , DMA_CTRL );
18571846}
18581847
18591848static int bcmgenet_dma_teardown (struct bcmgenet_priv * priv )
@@ -1930,6 +1919,8 @@ static void bcmgenet_fini_dma(struct bcmgenet_priv *priv)
19301919static int bcmgenet_init_dma (struct bcmgenet_priv * priv )
19311920{
19321921 int ret ;
1922+ unsigned int i ;
1923+ struct enet_cb * cb ;
19331924
19341925 netif_dbg (priv , hw , priv -> dev , "bcmgenet: init_edma\n" );
19351926
@@ -1956,14 +1947,13 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv)
19561947 return - ENOMEM ;
19571948 }
19581949
1959- /* initialize multi xmit queue */
1960- bcmgenet_init_multiq (priv -> dev );
1950+ for (i = 0 ; i < priv -> num_tx_bds ; i ++ ) {
1951+ cb = priv -> tx_cbs + i ;
1952+ cb -> bd_addr = priv -> tx_bds + i * DMA_DESC_SIZE ;
1953+ }
19611954
1962- /* initialize special ring 16 */
1963- bcmgenet_init_tx_ring (priv , DESC_INDEX , GENET_DEFAULT_BD_CNT ,
1964- priv -> hw_params -> tx_queues *
1965- priv -> hw_params -> bds_cnt ,
1966- TOTAL_DESC );
1955+ /* Initialize Tx queues */
1956+ bcmgenet_init_tx_queues (priv -> dev );
19671957
19681958 return 0 ;
19691959}
@@ -2437,8 +2427,8 @@ static const struct net_device_ops bcmgenet_netdev_ops = {
24372427static struct bcmgenet_hw_params bcmgenet_hw_params [] = {
24382428 [GENET_V1 ] = {
24392429 .tx_queues = 0 ,
2430+ .tx_bds_per_q = 0 ,
24402431 .rx_queues = 0 ,
2441- .bds_cnt = 0 ,
24422432 .bp_in_en_shift = 16 ,
24432433 .bp_in_mask = 0xffff ,
24442434 .hfb_filter_cnt = 16 ,
@@ -2450,8 +2440,8 @@ static struct bcmgenet_hw_params bcmgenet_hw_params[] = {
24502440 },
24512441 [GENET_V2 ] = {
24522442 .tx_queues = 4 ,
2443+ .tx_bds_per_q = 32 ,
24532444 .rx_queues = 4 ,
2454- .bds_cnt = 32 ,
24552445 .bp_in_en_shift = 16 ,
24562446 .bp_in_mask = 0xffff ,
24572447 .hfb_filter_cnt = 16 ,
@@ -2466,8 +2456,8 @@ static struct bcmgenet_hw_params bcmgenet_hw_params[] = {
24662456 },
24672457 [GENET_V3 ] = {
24682458 .tx_queues = 4 ,
2459+ .tx_bds_per_q = 32 ,
24692460 .rx_queues = 4 ,
2470- .bds_cnt = 32 ,
24712461 .bp_in_en_shift = 17 ,
24722462 .bp_in_mask = 0x1ffff ,
24732463 .hfb_filter_cnt = 48 ,
@@ -2482,8 +2472,8 @@ static struct bcmgenet_hw_params bcmgenet_hw_params[] = {
24822472 },
24832473 [GENET_V4 ] = {
24842474 .tx_queues = 4 ,
2475+ .tx_bds_per_q = 32 ,
24852476 .rx_queues = 4 ,
2486- .bds_cnt = 32 ,
24872477 .bp_in_en_shift = 17 ,
24882478 .bp_in_mask = 0x1ffff ,
24892479 .hfb_filter_cnt = 48 ,
@@ -2583,14 +2573,15 @@ static void bcmgenet_set_hw_params(struct bcmgenet_priv *priv)
25832573#endif
25842574
25852575 pr_debug ("Configuration for version: %d\n"
2586- "TXq: %1d, RXq : %1d, BDs : %1d\n"
2576+ "TXq: %1d, TXqBDs : %1d, RXq : %1d\n"
25872577 "BP << en: %2d, BP msk: 0x%05x\n"
25882578 "HFB count: %2d, QTAQ msk: 0x%05x\n"
25892579 "TBUF: 0x%04x, HFB: 0x%04x, HFBreg: 0x%04x\n"
25902580 "RDMA: 0x%05x, TDMA: 0x%05x\n"
25912581 "Words/BD: %d\n" ,
25922582 priv -> version ,
2593- params -> tx_queues , params -> rx_queues , params -> bds_cnt ,
2583+ params -> tx_queues , params -> tx_bds_per_q ,
2584+ params -> rx_queues ,
25942585 params -> bp_in_en_shift , params -> bp_in_mask ,
25952586 params -> hfb_filter_cnt , params -> qtag_mask ,
25962587 params -> tbuf_offset , params -> hfb_offset ,
0 commit comments