From: Olivier Matz Date: Wed, 22 Apr 2015 09:57:20 +0000 (+0200) Subject: mbuf: add accessors for data room and private size X-Git-Tag: spdx-start~9268 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c511a96a34d7c3e6954c1a634bae5e7208b7b3f2;p=dpdk.git mbuf: add accessors for data room and private size This code retrieving the pool private area is duplicated in many places, we can use of function for it. Signed-off-by: Olivier Matz Acked-by: Neil Horman Acked-by: Konstantin Ananyev --- diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 4d842f8e56..024fe8b2cc 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1439,7 +1439,6 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id, int ret; uint32_t mbp_buf_size; struct rte_eth_dev *dev; - struct rte_pktmbuf_pool_private *mbp_priv; struct rte_eth_dev_info dev_info; /* This function is only safe when called from the primary process @@ -1478,8 +1477,7 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id, (int) sizeof(struct rte_pktmbuf_pool_private)); return -ENOSPC; } - mbp_priv = rte_mempool_get_priv(mp); - mbp_buf_size = mbp_priv->mbuf_data_room_size; + mbp_buf_size = rte_pktmbuf_data_room_size(mp); if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) { PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d " diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 13fd6269fd..a4146fa48b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -641,6 +641,47 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg, */ void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg); +/** + * Get the data room size of mbufs stored in a pktmbuf_pool + * + * The data room size is the amount of data that can be stored in a + * mbuf including the headroom (RTE_PKTMBUF_HEADROOM). + * + * @param mp + * The packet mbuf pool. + * @return + * The data room size of mbufs stored in this mempool. + */ +static inline uint16_t +rte_pktmbuf_data_room_size(struct rte_mempool *mp) +{ + struct rte_pktmbuf_pool_private *mbp_priv; + + mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp); + return mbp_priv->mbuf_data_room_size; +} + +/** + * Get the application private size of mbufs stored in a pktmbuf_pool + * + * The private size of mbuf is a zone located between the rte_mbuf + * structure and the data buffer where an application can store data + * associated to a packet. + * + * @param mp + * The packet mbuf pool. + * @return + * The private size of mbufs stored in this mempool. + */ +static inline uint16_t +rte_pktmbuf_priv_size(struct rte_mempool *mp) +{ + struct rte_pktmbuf_pool_private *mbp_priv; + + mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp); + return mbp_priv->mbuf_priv_size; +} + /** * Reset the fields of a packet mbuf to their default values. * diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c index f7e9ec9197..bdd9628674 100644 --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c @@ -348,15 +348,13 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, { struct pmd_internals *internals = dev->data->dev_private; struct pkt_rx_queue *pkt_q = &internals->rx_queue[rx_queue_id]; - struct rte_pktmbuf_pool_private *mbp_priv; uint16_t buf_size; pkt_q->mb_pool = mb_pool; /* Now get the space available for data in the mbuf */ - mbp_priv = rte_mempool_get_priv(pkt_q->mb_pool); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(pkt_q->mb_pool) - + RTE_PKTMBUF_HEADROOM); if (ETH_FRAME_LEN > buf_size) { RTE_LOG(ERR, PMD, diff --git a/lib/librte_pmd_e1000/em_rxtx.c b/lib/librte_pmd_e1000/em_rxtx.c index 8e20920b61..64d067c0a5 100644 --- a/lib/librte_pmd_e1000/em_rxtx.c +++ b/lib/librte_pmd_e1000/em_rxtx.c @@ -1668,12 +1668,11 @@ eth_em_rx_init(struct rte_eth_dev *dev) /* Determine RX bufsize. */ rctl_bsize = EM_MAX_BUF_SIZE; for (i = 0; i < dev->data->nb_rx_queues; i++) { - struct rte_pktmbuf_pool_private *mbp_priv; uint32_t buf_size; rxq = dev->data->rx_queues[i]; - mbp_priv = rte_mempool_get_priv(rxq->mb_pool); - buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM; + buf_size = rte_pktmbuf_data_room_size(rxq->mb_pool) - + RTE_PKTMBUF_HEADROOM; rctl_bsize = RTE_MIN(rctl_bsize, buf_size); } diff --git a/lib/librte_pmd_e1000/igb_rxtx.c b/lib/librte_pmd_e1000/igb_rxtx.c index 084e45a459..80d05c06a7 100644 --- a/lib/librte_pmd_e1000/igb_rxtx.c +++ b/lib/librte_pmd_e1000/igb_rxtx.c @@ -1921,7 +1921,6 @@ eth_igb_rx_init(struct rte_eth_dev *dev) { struct e1000_hw *hw; struct igb_rx_queue *rxq; - struct rte_pktmbuf_pool_private *mbp_priv; uint32_t rctl; uint32_t rxcsum; uint32_t srrctl; @@ -1991,9 +1990,8 @@ eth_igb_rx_init(struct rte_eth_dev *dev) /* * Configure RX buffer size. */ - mbp_priv = rte_mempool_get_priv(rxq->mb_pool); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) - + RTE_PKTMBUF_HEADROOM); if (buf_size >= 1024) { /* * Configure the BSIZEPACKET field of the SRRCTL @@ -2221,7 +2219,6 @@ eth_igbvf_rx_init(struct rte_eth_dev *dev) { struct e1000_hw *hw; struct igb_rx_queue *rxq; - struct rte_pktmbuf_pool_private *mbp_priv; uint32_t srrctl; uint16_t buf_size; uint16_t rctl_bsize; @@ -2262,9 +2259,8 @@ eth_igbvf_rx_init(struct rte_eth_dev *dev) /* * Configure RX buffer size. */ - mbp_priv = rte_mempool_get_priv(rxq->mb_pool); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) - + RTE_PKTMBUF_HEADROOM); if (buf_size >= 1024) { /* * Configure the BSIZEPACKET field of the SRRCTL diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c b/lib/librte_pmd_fm10k/fm10k_ethdev.c index d716881631..275c19ccd2 100644 --- a/lib/librte_pmd_fm10k/fm10k_ethdev.c +++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c @@ -397,7 +397,6 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev) uint32_t size; uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY; uint16_t buf_size; - struct rte_pktmbuf_pool_private *mbp_priv; /* Disable RXINT to avoid possible interrupt */ for (i = 0; i < hw->mac.max_queues; i++) @@ -425,9 +424,8 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev) FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size); /* Configure the Rx buffer size for one buff without split */ - mbp_priv = rte_mempool_get_priv(rxq->mp); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) - + RTE_PKTMBUF_HEADROOM); FM10K_WRITE_REG(hw, FM10K_SRRCTL(i), buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT); diff --git a/lib/librte_pmd_i40e/i40e_ethdev_vf.c b/lib/librte_pmd_i40e/i40e_ethdev_vf.c index 8910bdf334..a0d808fd1a 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev_vf.c +++ b/lib/librte_pmd_i40e/i40e_ethdev_vf.c @@ -571,13 +571,11 @@ i40evf_fill_virtchnl_vsi_rxq_info(struct i40e_virtchnl_rxq_info *rxq_info, rxq_info->queue_id = queue_id; rxq_info->max_pkt_size = max_pkt_size; if (queue_id < nb_rxq) { - struct rte_pktmbuf_pool_private *mbp_priv; - rxq_info->ring_len = rxq->nb_rx_desc; rxq_info->dma_ring_addr = rxq->rx_ring_phys_addr; - mbp_priv = rte_mempool_get_priv(rxq->mp); rxq_info->databuffer_size = - mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM; + (rte_pktmbuf_data_room_size(rxq->mp) - + RTE_PKTMBUF_HEADROOM); } } diff --git a/lib/librte_pmd_i40e/i40e_rxtx.c b/lib/librte_pmd_i40e/i40e_rxtx.c index abe68f4060..493cfa30d0 100644 --- a/lib/librte_pmd_i40e/i40e_rxtx.c +++ b/lib/librte_pmd_i40e/i40e_rxtx.c @@ -2444,11 +2444,10 @@ i40e_rx_queue_config(struct i40e_rx_queue *rxq) struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi); struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi); struct rte_eth_dev_data *data = pf->dev_data; - struct rte_pktmbuf_pool_private *mbp_priv = - rte_mempool_get_priv(rxq->mp); - uint16_t buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); - uint16_t len; + uint16_t buf_size, len; + + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) - + RTE_PKTMBUF_HEADROOM); switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED | I40E_FLAG_HEADER_SPLIT_ENABLED)) { @@ -2506,7 +2505,6 @@ i40e_rx_queue_init(struct i40e_rx_queue *rxq) uint16_t pf_q = rxq->reg_idx; uint16_t buf_size; struct i40e_hmc_obj_rxq rx_ctx; - struct rte_pktmbuf_pool_private *mbp_priv; err = i40e_rx_queue_config(rxq); if (err < 0) { @@ -2553,9 +2551,8 @@ i40e_rx_queue_init(struct i40e_rx_queue *rxq) rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); - mbp_priv = rte_mempool_get_priv(rxq->mp); - buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) - + RTE_PKTMBUF_HEADROOM); /* Check if scattered RX needs to be used. */ if ((rxq->max_pkt_len + 2 * I40E_VLAN_TAG_SIZE) > buf_size) { diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c index 3c61d1c43d..7f15f1541a 100644 --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c @@ -4203,7 +4203,6 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev) { struct ixgbe_hw *hw; struct ixgbe_rx_queue *rxq; - struct rte_pktmbuf_pool_private *mbp_priv; uint64_t bus_addr; uint32_t rxctrl; uint32_t fctrl; @@ -4320,9 +4319,8 @@ ixgbe_dev_rx_init(struct rte_eth_dev *dev) * The value is in 1 KB resolution. Valid values can be from * 1 KB to 16 KB. */ - mbp_priv = rte_mempool_get_priv(rxq->mb_pool); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) - + RTE_PKTMBUF_HEADROOM); srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) & IXGBE_SRRCTL_BSIZEPKT_MASK); @@ -4738,7 +4736,6 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev) { struct ixgbe_hw *hw; struct ixgbe_rx_queue *rxq; - struct rte_pktmbuf_pool_private *mbp_priv; uint64_t bus_addr; uint32_t srrctl, psrtype = 0; uint16_t buf_size; @@ -4825,9 +4822,8 @@ ixgbevf_dev_rx_init(struct rte_eth_dev *dev) * The value is in 1 KB resolution. Valid values can be from * 1 KB to 16 KB. */ - mbp_priv = rte_mempool_get_priv(rxq->mb_pool); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) - + RTE_PKTMBUF_HEADROOM); srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) & IXGBE_SRRCTL_BSIZEPKT_MASK); diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c index e5d227944e..815d4ca0a1 100644 --- a/lib/librte_pmd_pcap/rte_eth_pcap.c +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c @@ -136,7 +136,6 @@ eth_pcap_rx(void *queue, const u_char *packet; struct rte_mbuf *mbuf; struct pcap_rx_queue *pcap_q = queue; - struct rte_pktmbuf_pool_private *mbp_priv; uint16_t num_rx = 0; uint16_t buf_size; @@ -157,8 +156,7 @@ eth_pcap_rx(void *queue, break; /* Now get the space available for data in the mbuf */ - mbp_priv = rte_mempool_get_priv(pcap_q->mb_pool); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(pcap_q->mb_pool) - RTE_PKTMBUF_HEADROOM); if (header.len <= buf_size) { diff --git a/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c b/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c index a530c804c8..d8019f53ee 100644 --- a/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c +++ b/lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c @@ -838,14 +838,11 @@ vmxnet3_dev_rx_queue_setup(struct rte_eth_dev *dev, uint8_t i; char mem_name[32]; uint16_t buf_size; - struct rte_pktmbuf_pool_private *mbp_priv; PMD_INIT_FUNC_TRACE(); - mbp_priv = (struct rte_pktmbuf_pool_private *) - rte_mempool_get_priv(mp); - buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size - - RTE_PKTMBUF_HEADROOM); + buf_size = rte_pktmbuf_data_room_size(mp) - + RTE_PKTMBUF_HEADROOM; if (dev->data->dev_conf.rxmode.max_rx_pkt_len > buf_size) { PMD_INIT_LOG(ERR, "buf_size = %u, max_pkt_len = %u, "