dpdk l2fwd (2)


回到l2fwd的main函数中

 argc,  ** lcore_queue_conf *= = (ret < -=+== (ret < =( (l2fwd_pktmbuf_pool ==
     (rte_pmd_init_all() <  (rte_eal_pci_probe() < = (nb_ports ==  (nb_ports >=
     (portid = ; portid < RTE_MAX_ETHPORTS; portid++= = 
    
     (portid = ; portid < nb_ports; portid++
         ((l2fwd_enabled_port_mask & ( << portid)) ==  (nb_ports_in_mask % ===++& (nb_ports_in_mask % == =
    
     (portid = ; portid < nb_ports; portid++
         ((l2fwd_enabled_port_mask & ( << portid)) == 
         (rte_lcore_is_enabled(rx_lcore_id) ==  ||==++ (rx_lcore_id >= (qconf != &= &->rx_port_list[qconf->n_rx_port] =->n_rx_port++=
    
     (portid = ; portid < nb_ports; portid++
         ((l2fwd_enabled_port_mask & ( << portid)) == --= rte_eth_dev_configure(portid, , , & (ret < &= rte_eth_rx_queue_setup(portid, & (ret < = rte_eth_tx_queue_setup(portid, & (ret < = (ret < &port_statistics, ,  (!
     (rte_eal_wait_lcore(lcore_id) <  - 

 

以下详细分析端口初始化过程; 对于每个port, 首先调用rte_eth_dev_configure配置端口的收发包队列个数,并初始化收发包队列控制块;

  rte_eth_conf * rte_eth_dev *
    - (port_id >= nb_ports || port_id >= (-= &*dev->dev_ops->dev_infos_get, -*dev->dev_ops->dev_configure, -
     (dev->data-> (-
    *dev->dev_ops->dev_infos_get)(dev, & (nb_rx_q > (- (nb_rx_q ==  (- (nb_tx_q > (- (nb_tx_q ==  (-
    &dev->data->dev_conf, dev_conf, (dev->data->
    
     (dev_conf->rxmode.jumbo_frame ==  (dev_conf->rxmode.max_rx_pkt_len >
                -> (-  (dev_conf->rxmode.max_rx_pkt_len <
                -> (-
        ->data->dev_conf.rxmode.max_rx_pkt_len =
    = (diag != 
    = (diag != = (diag != = (*dev->dev_ops-> (diag !=  

RX queue setup

  rte_eth_rxconf * rte_mempool * rte_eth_dev * rte_pktmbuf_pool_private *- (port_id >= (-= & (rx_queue_id >= dev->data-> (- (dev->data-> -*dev->dev_ops->dev_infos_get, -*dev->dev_ops->rx_queue_setup, -*dev->dev_ops->dev_infos_get)(dev, & (mp->private_data_size < (->name, () mp->) ( (-= ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
                
                ->)mbp_priv->)(RTE_PKTMBUF_HEADROOM + (-
     (*dev->dev_ops->

 

 rte_eth_dev *  rte_eth_rxconf * rte_mempool *  rte_memzone * em_rx_queue * e1000_hw     *= E1000_DEV_PRIVATE_TO_HW(dev->data->
     (((nb_desc * (rxq->rx_ring[])) % EM_ALIGN) !=  ||> EM_MAX_RING_DESC) ||< (-
     (rx_conf-> (-
    
     (dev->data->rx_queues[queue_idx] !=->data->->data->rx_queues[queue_idx] =
    =  (rxq->rx_ring[]) * ((rz = ring_dma_zone_reserve(dev, == (-
    
     ((rxq = rte_zmalloc(, (*== (-
    
     ((rxq->sw_ring = rte_zmalloc( (rxq->sw_ring[]) *== (-->mb_pool =->nb_rx_desc =->pthresh = rx_conf->->hthresh = rx_conf->->wthresh = rx_conf->->rx_free_thresh = rx_conf->->queue_id =->port_id = dev->data->->crc_len = (uint8_t) ((dev->data->dev_conf.rxmode.hw_strip_crc) ?
                ->rdt_reg_addr =->rdh_reg_addr =->rx_ring_phys_addr = (uint64_t) rz->->rx_ring_phys_addr = rte_mem_phy2mch(rz->memseg_id, rz-> ->rx_ring = ( e1000_rx_desc *) rz->PRIx64->sw_ring, rxq->rx_ring, rxq->->data->rx_queues[queue_idx] = (

 

TX queue setup

  rte_eth_txconf * rte_eth_dev *- (port_id >= RTE_MAX_ETHPORTS || port_id >= (-= & (tx_queue_id >= dev->data-> (-
     (dev->data-> -*dev->dev_ops->tx_queue_setup, - (*dev->dev_ops->

 

 rte_eth_dev *  rte_eth_txconf *  rte_memzone * em_tx_queue * e1000_hw     *= E1000_DEV_PRIVATE_TO_HW(dev->data->
    
     (((nb_desc * (*txq->tx_ring)) % EM_ALIGN) !=  ||> EM_MAX_RING_DESC) ||< -= tx_conf-> (tx_free_thresh == = (uint16_t)RTE_MIN(nb_desc / = tx_conf-> (tx_rs_thresh == = (tx_free_thresh >= (nb_desc - 
            
            , (unsigned )dev->data->port_id, ( - (tx_rs_thresh >
            
            , (unsigned )tx_rs_thresh, ()dev->data-> -
     (tx_conf->tx_thresh.wthresh !=  && tx_rs_thresh != 
            
            , (unsigned )dev->data->port_id, ( -
    
     (dev->data->tx_queues[queue_idx] !=->data->->data->tx_queues[queue_idx] =
    =  (txq->tx_ring[]) * ((tz = ring_dma_zone_reserve(dev, == (-
    
     ((txq = rte_zmalloc(, (*== (-
    
     ((txq->sw_ring = rte_zmalloc((txq->sw_ring[]) *== (-->nb_tx_desc =->tx_free_thresh =->tx_rs_thresh =->pthresh = tx_conf->->hthresh = tx_conf->->wthresh = tx_conf->->queue_id =->port_id = dev->data->->tdt_reg_addr =->tx_ring_phys_addr = (uint64_t) tz->   ->tx_ring_phys_addr = rte_mem_phy2mch(tz->memseg_id, tz->
    ->tx_ring = ( e1000_data_desc *) tz->PRIx64->sw_ring, txq->tx_ring, txq->->data->tx_queues[queue_idx] = (

端口初始化的最后一步是使能端口收发包功能,其中主要是通知E1000驱动tx ring和rx ring的地址, 细节就不再跟进

 rte_eth_dev * e1000_hw     * em_tx_queue *= E1000_DEV_PRIVATE_TO_HW(dev->data->
    
     (i = ; i < dev->data->nb_tx_queues; i++= dev->data->= txq->->nb_tx_desc *
                (*txq->>> =&=|= txq->pthresh & |= (txq->hthresh & ) << |= (txq->wthresh & ) << |==&= ~|= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |<<

 

 rte_eth_dev * e1000_hw * em_rx_queue *= E1000_DEV_PRIVATE_TO_HW(dev->data->=& ~=&= ~
     (hw->mac.type ==|=
     (hw->mac.type ==->rx_pkt_burst =
    = (i = ; i < dev->data->nb_rx_queues; i++ rte_pktmbuf_pool_private *= dev->data->= rte_mempool_get_priv(rxq->= mbp_priv->mbuf_data_room_size -=|= em_rctl_bsize(hw->mac.type, &
     (i = ; i < dev->data->nb_rx_queues; i++= dev->data->
        =

        ->crc_len =->data->dev_conf.rxmode.hw_strip_crc ?
                            = rxq->->nb_rx_desc *
                (*rxq->>> ->nb_rx_desc - = E1000_READ_REG(hw, E1000_RXDCTL(&= |= rxq->pthresh & |= (rxq->hthresh & ) << |= (rxq->wthresh & ) << |=
        
         (dev->data->dev_conf.rxmode.jumbo_frame ||<->rx_pkt_burst =->data->scattered_rx =  

 

到此端口初始化完成,比启动,回到main函数中, 在每个lcore上启动循环收包函数

lcore的主线程处理如下


  rte_mbuf * rte_mbuf * lcore_queue_conf * uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - ) / US_PER_S *= = == & (qconf->n_rx_port == 
     (i = ; i < qconf->n_rx_port; i++= qconf-> (== cur_tsc -
         (unlikely(diff_tsc > (portid = ; portid < RTE_MAX_ETHPORTS; portid++
                 (qconf->tx_mbufs[portid].len == &->->tx_mbufs[portid].len = 
             (timer_period > +=
                 (unlikely(timer_tsc >=
                     (lcore_id === =
        
         (i = ; i < qconf->n_rx_port; i++= qconf->= rte_eth_rx_burst((uint8_t) portid, +=
             (j = ; j < nb_rx; j++= *

 

首先看报文是如何收上来的, 调用device的rx_pkt_burst

 rte_mbuf ** rte_eth_dev *= & (*dev->rx_pkt_burst)(dev->data->

PMD的收包函数如下:

 *rx_queue,  rte_mbuf **
      e1000_rx_desc *  e1000_rx_desc * em_rx_queue * em_rx_entry * em_rx_entry * rte_mbuf * rte_mbuf *== = = rxq->rx_tail;       = rxq->rx_ring;     = rxq->sw_ring;     

    
     (nb_rx <
        
        = &= rxdp-> (! (status &= *
            ->port_id, (unsigned) rxq->= rte_rxmbuf_alloc(rxq-> (nmb ==
                ->->->port_id].data->rx_mbuf_alloc_failed++++= &++ (rx_id == rxq->= 
        
        
        
         ((rx_id & ) == &&

        = rxe->->mbuf ==->buffer_addr =->status = = (uint16_t) (rte_le_to_cpu_16(rxd.length) -->->pkt.data = (*) rxm->buf_addr +->->pkt.nb_segs = ->pkt.next =->pkt.pkt_len =->pkt.data_len =->pkt.in_port = rxq->->ol_flags =->ol_flags = (uint16_t)(rxm->ol_flags |->pkt.vlan_macip.f.vlan_tci =
        ++] =->rx_tail =
    = (uint16_t) (nb_hold + rxq-> (nb_hold > rxq->
            ->port_id, (unsigned) rxq->= (uint16_t) ((rx_id == ) ?->nb_rx_desc - ) : (rx_id - ->= ->nb_rx_hold =

 

发包函数

 rte_mbuf ** rte_eth_dev *= & (*dev->tx_pkt_burst)(dev->data->

调用的PMD的发包函数

 *tx_queue,  rte_mbuf ** em_tx_queue * em_tx_entry * em_tx_entry *txe, *  e1000_data_desc *  e1000_data_desc * rte_mbuf     * rte_mbuf     *== txq->= txq->= txq->= &
    
     ((txq->nb_tx_desc - txq->nb_tx_free) > txq->
    
     (nb_tx = ; nb_tx < nb_pkts; nb_tx++= = *tx_pkts++->= tx_pkt->= (uint16_t)(ol_flags & (PKT_TX_IP_CKSUM |= tx_pkt->
            == (ctx ==
        = (uint16_t)(tx_pkt->pkt.nb_segs +
        = (uint16_t) (tx_id + nb_used - 
        
         (tx_last >= txq->= (uint16_t) (tx_last - txq->
            ->->->
         (unlikely (nb_used > txq->
                    
                    ->->port_id, txq-> (em_xmit_cleanup(txq) != 
                 (nb_tx ==  (

        = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |= 
         (ol_flags &|== tx_pkt->pkt.vlan_macip.f.vlan_tci <<
              e1000_context_desc *= (  e1000_context_desc *&= &sw_ring[txe->-> (txe->mbuf !=->->mbuf =->last_id == txe->=|=== &= &sw_ring[txe->
             (txe->mbuf !=->->mbuf == m_seg->=->buffer_addr =->lower.data = rte_cpu_to_le_32(cmd_type_len |->upper.data =->last_id == txe->== m_seg-> (m_seg !=
        |=->nb_tx_used = (uint16_t)(txq->nb_tx_used +->nb_tx_free = (uint16_t)(txq->nb_tx_free -
         (txq->nb_tx_used >= txq->
                    ->port_id, txq->|=->nb_tx_used = ->lower.data |=
    ->port_id, (unsigned) txq->->->tx_tail =

 

至于驱动(E1000)中的处理等需要了再分析吧.

相关内容