From: "Wu, Jingjing" <jingjing.wu@intel.com>
To: "Li, Xiaoyun" <xiaoyun.li@intel.com>,
"Wiles, Keith" <keith.wiles@intel.com>,
"Maslekar, Omkar" <omkar.maslekar@intel.com>,
"Liang, Cunming" <cunming.liang@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH v4 1/4] raw/ntb: setup ntb queue
Date: Mon, 23 Sep 2019 02:50:07 +0000 [thread overview]
Message-ID: <9BB6961774997848B5B42BEC655768F81151CAF1@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <20190909032730.29718-2-xiaoyun.li@intel.com>
<...>
> +static void
> +ntb_rxq_release(struct ntb_rx_queue *rxq)
> +{
> + if (!rxq) {
> + NTB_LOG(ERR, "Pointer to rxq is NULL");
> + return;
> + }
> +
> + ntb_rxq_release_mbufs(rxq);
> +
> + rte_free(rxq->sw_ring);
> + rte_free(rxq);
It' better to free rxq out of this function, as the point of param "rxq" cannot be set to NULL in this func.
> +}
> +
> +static int
> +ntb_rxq_setup(struct rte_rawdev *dev,
> + uint16_t qp_id,
> + rte_rawdev_obj_t queue_conf)
> +{
> + struct ntb_queue_conf *rxq_conf = queue_conf;
> + struct ntb_hw *hw = dev->dev_private;
> + struct ntb_rx_queue *rxq;
> +
> + /* Allocate the rx queue data structure */
> + rxq = rte_zmalloc_socket("ntb rx queue",
> + sizeof(struct ntb_rx_queue),
> + RTE_CACHE_LINE_SIZE,
> + dev->socket_id);
> + if (!rxq) {
> + NTB_LOG(ERR, "Failed to allocate memory for "
> + "rx queue data structure.");
> + return -ENOMEM;
Need to free rxq here.
<...>
> +static void
> +ntb_txq_release(struct ntb_tx_queue *txq)
> {
> + if (!txq) {
> + NTB_LOG(ERR, "Pointer to txq is NULL");
> + return;
> + }
> +
> + ntb_txq_release_mbufs(txq);
> +
> + rte_free(txq->sw_ring);
> + rte_free(txq);
The same as above "ntb_rxq_release".
<...>
> +static int
> +ntb_queue_setup(struct rte_rawdev *dev,
> + uint16_t queue_id,
> + rte_rawdev_obj_t queue_conf)
> +{
> + struct ntb_hw *hw = dev->dev_private;
> + int ret;
> +
> + if (queue_id > hw->queue_pairs)
Should be ">=" ?
> + return -EINVAL;
> +
> + ret = ntb_txq_setup(dev, queue_id, queue_conf);
> + if (ret < 0)
> + return ret;
> +
> + ret = ntb_rxq_setup(dev, queue_id, queue_conf);
> +
> + return ret;
> +}
> +
> static int
> -ntb_queue_release(struct rte_rawdev *dev __rte_unused,
> - uint16_t queue_id __rte_unused)
> +ntb_queue_release(struct rte_rawdev *dev, uint16_t queue_id)
> {
> + struct ntb_hw *hw = dev->dev_private;
> + struct ntb_tx_queue *txq;
> + struct ntb_rx_queue *rxq;
> +
> + if (queue_id > hw->queue_pairs)
Should be ">=" ?
> + return -EINVAL;
> +
> + txq = hw->tx_queues[queue_id];
> + rxq = hw->rx_queues[queue_id];
> + ntb_txq_release(txq);
> + ntb_rxq_release(rxq);
> +
> return 0;
> }
>
> @@ -234,6 +470,77 @@ ntb_queue_count(struct rte_rawdev *dev)
> return hw->queue_pairs;
> }
>
> +static int
> +ntb_queue_init(struct rte_rawdev *dev, uint16_t qp_id)
> +{
> + struct ntb_hw *hw = dev->dev_private;
> + struct ntb_rx_queue *rxq = hw->rx_queues[qp_id];
> + struct ntb_tx_queue *txq = hw->tx_queues[qp_id];
> + volatile struct ntb_header *local_hdr;
> + struct ntb_header *remote_hdr;
> + uint16_t q_size = hw->queue_size;
> + uint32_t hdr_offset;
> + void *bar_addr;
> + uint16_t i;
> +
> + if (hw->ntb_ops->get_peer_mw_addr == NULL) {
> + NTB_LOG(ERR, "Failed to get mapped peer addr.");
Would it be better to log as "XX ops is not supported" to keep consistent as others?
> + return -EINVAL;
> + }
> +
> + /* Put queue info into the start of shared memory. */
> + hdr_offset = hw->hdr_size_per_queue * qp_id;
> + local_hdr = (volatile struct ntb_header *)
> + ((size_t)hw->mz[0]->addr + hdr_offset);
> + bar_addr = (*hw->ntb_ops->get_peer_mw_addr)(dev, 0);
> + if (bar_addr == NULL)
> + return -EINVAL;
> + remote_hdr = (struct ntb_header *)
> + ((size_t)bar_addr + hdr_offset);
> +
> + /* rxq init. */
> + rxq->rx_desc_ring = (struct ntb_desc *)
> + (&remote_hdr->desc_ring);
> + rxq->rx_used_ring = (volatile struct ntb_used *)
> + (&local_hdr->desc_ring[q_size]);
> + rxq->avail_cnt = &remote_hdr->avail_cnt;
> + rxq->used_cnt = &local_hdr->used_cnt;
> +
> + for (i = 0; i < rxq->nb_rx_desc - 1; i++) {
> + struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mpool);
> + if (unlikely(!mbuf)) {
> + NTB_LOG(ERR, "Failed to allocate mbuf for RX");
Need release mbufs allocated here or in " ntb_dev_start".
<...>
> + hw->hdr_size_per_queue = RTE_ALIGN(sizeof(struct ntb_header) +
> + hw->queue_size * sizeof(struct ntb_desc) +
> + hw->queue_size * sizeof(struct ntb_used),
> + RTE_CACHE_LINE_SIZE);
hw->hdr_size_per_queue is internal information, why put the assignment in ntb_dev_info_get?
> + info->ntb_hdr_size = hw->hdr_size_per_queue * hw->queue_pairs;
> }
>
> static int
> -ntb_dev_configure(const struct rte_rawdev *dev __rte_unused,
> - rte_rawdev_obj_t config __rte_unused)
> +ntb_dev_configure(const struct rte_rawdev *dev, rte_rawdev_obj_t config)
> {
> + struct ntb_dev_config *conf = config;
> + struct ntb_hw *hw = dev->dev_private;
> + int ret;
> +
> + hw->queue_pairs = conf->num_queues;
> + hw->queue_size = conf->queue_size;
> + hw->used_mw_num = conf->mz_num;
> + hw->mz = conf->mz_list;
> + hw->rx_queues = rte_zmalloc("ntb_rx_queues",
> + sizeof(struct ntb_rx_queue *) * hw->queue_pairs, 0);
> + hw->tx_queues = rte_zmalloc("ntb_tx_queues",
> + sizeof(struct ntb_tx_queue *) * hw->queue_pairs, 0);
> +
> + /* Start handshake with the peer. */
> + ret = ntb_handshake_work(dev);
> + if (ret < 0)
Free?
> + return ret;
> +
> return 0;
> }
>
> @@ -337,21 +637,52 @@ static int
> ntb_dev_start(struct rte_rawdev *dev)
> {
> struct ntb_hw *hw = dev->dev_private;
> - int ret, i;
> + uint32_t peer_base_l, peer_val;
> + uint64_t peer_base_h;
> + uint32_t i;
> + int ret;
>
> - /* TODO: init queues and start queues. */
> + if (!hw->link_status || !hw->peer_dev_up)
> + return -EINVAL;
>
> - /* Map memory of bar_size to remote. */
> - hw->mz = rte_zmalloc("struct rte_memzone *",
> - hw->mw_cnt * sizeof(struct rte_memzone *), 0);
> - for (i = 0; i < hw->mw_cnt; i++) {
> - ret = ntb_set_mw(dev, i, hw->mw_size[i]);
> + for (i = 0; i < hw->queue_pairs; i++) {
> + ret = ntb_queue_init(dev, i);
> if (ret) {
> - NTB_LOG(ERR, "Fail to set mw.");
> + NTB_LOG(ERR, "Failed to init queue.");
Free when error.
<...>
> +struct ntb_used {
> + uint16_t len; /* buffer length */
> +#define NTB_FLAG_EOP 1 /* end of packet */
Better to
> + uint16_t flags; /* flags */
> +};
> +
> +struct ntb_rx_entry {
> + struct rte_mbuf *mbuf;
> +};
> +
> +struct ntb_rx_queue {
> + struct ntb_desc *rx_desc_ring;
> + volatile struct ntb_used *rx_used_ring;
> + uint16_t *avail_cnt;
> + volatile uint16_t *used_cnt;
> + uint16_t last_avail;
> + uint16_t last_used;
> + uint16_t nb_rx_desc;
> +
> + uint16_t rx_free_thresh;
> +
> + struct rte_mempool *mpool; /**< mempool for mbuf allocation */
Generally comments: comments in internal header doesn't need to be wrapped with "/**< */", keep consistent in one file would be nice.
next prev parent reply other threads:[~2019-09-23 2:50 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-05 5:39 [dpdk-dev] [PATCH 0/4] enable FIFO for NTB Xiaoyun Li
2019-09-05 5:39 ` [dpdk-dev] [PATCH 1/4] raw/ntb: setup ntb queue Xiaoyun Li
2019-09-05 5:39 ` [dpdk-dev] [PATCH 2/4] raw/ntb: add xstats support Xiaoyun Li
2019-09-05 5:39 ` [dpdk-dev] [PATCH 3/4] raw/ntb: add enqueue and dequeue functions Xiaoyun Li
2019-09-05 5:39 ` [dpdk-dev] [PATCH 4/4] examples/ntb: support more functions for NTB Xiaoyun Li
2019-09-05 18:34 ` [dpdk-dev] [PATCH 0/4] enable FIFO " Maslekar, Omkar
2019-09-06 3:02 ` [dpdk-dev] [PATCH v2 " Xiaoyun Li
2019-09-06 3:02 ` [dpdk-dev] [PATCH v2 1/4] raw/ntb: setup ntb queue Xiaoyun Li
2019-09-06 3:02 ` [dpdk-dev] [PATCH v2 2/4] raw/ntb: add xstats support Xiaoyun Li
2019-09-06 3:02 ` [dpdk-dev] [PATCH v2 3/4] raw/ntb: add enqueue and dequeue functions Xiaoyun Li
2019-09-06 3:02 ` [dpdk-dev] [PATCH v2 4/4] examples/ntb: support more functions for NTB Xiaoyun Li
2019-09-06 7:53 ` [dpdk-dev] [PATCH v3 0/4] enable FIFO " Xiaoyun Li
2019-09-06 7:53 ` [dpdk-dev] [PATCH v3 1/4] raw/ntb: setup ntb queue Xiaoyun Li
2019-09-06 7:54 ` [dpdk-dev] [PATCH v3 2/4] raw/ntb: add xstats support Xiaoyun Li
2019-09-06 7:54 ` [dpdk-dev] [PATCH v3 3/4] raw/ntb: add enqueue and dequeue functions Xiaoyun Li
2019-09-06 7:54 ` [dpdk-dev] [PATCH v3 4/4] examples/ntb: support more functions for NTB Xiaoyun Li
2019-09-09 3:27 ` [dpdk-dev] [PATCH v4 0/4] enable FIFO " Xiaoyun Li
2019-09-09 3:27 ` [dpdk-dev] [PATCH v4 1/4] raw/ntb: setup ntb queue Xiaoyun Li
2019-09-23 2:50 ` Wu, Jingjing [this message]
2019-09-23 3:28 ` Li, Xiaoyun
2019-09-09 3:27 ` [dpdk-dev] [PATCH v4 2/4] raw/ntb: add xstats support Xiaoyun Li
2019-09-23 3:30 ` Wu, Jingjing
2019-09-09 3:27 ` [dpdk-dev] [PATCH v4 3/4] raw/ntb: add enqueue and dequeue functions Xiaoyun Li
2019-09-23 5:25 ` Wu, Jingjing
2019-09-09 3:27 ` [dpdk-dev] [PATCH v4 4/4] examples/ntb: support more functions for NTB Xiaoyun Li
2019-09-23 7:18 ` Wu, Jingjing
2019-09-23 7:26 ` Li, Xiaoyun
2019-09-24 8:24 ` Li, Xiaoyun
2019-09-24 8:43 ` [dpdk-dev] [PATCH v5 0/4] enable FIFO " Xiaoyun Li
2019-09-24 8:43 ` [dpdk-dev] [PATCH v5 1/4] raw/ntb: setup ntb queue Xiaoyun Li
2019-09-24 8:43 ` [dpdk-dev] [PATCH v5 2/4] raw/ntb: add xstats support Xiaoyun Li
2019-09-24 8:43 ` [dpdk-dev] [PATCH v5 3/4] raw/ntb: add enqueue and dequeue functions Xiaoyun Li
2019-09-24 8:43 ` [dpdk-dev] [PATCH v5 4/4] examples/ntb: support more functions for NTB Xiaoyun Li
2019-09-26 3:20 ` [dpdk-dev] [PATCH v6 0/4] enable FIFO " Xiaoyun Li
2019-09-26 3:20 ` [dpdk-dev] [PATCH v6 1/4] raw/ntb: setup ntb queue Xiaoyun Li
2019-09-26 3:20 ` [dpdk-dev] [PATCH v6 2/4] raw/ntb: add xstats support Xiaoyun Li
2019-09-26 3:20 ` [dpdk-dev] [PATCH v6 3/4] raw/ntb: add enqueue and dequeue functions Xiaoyun Li
2019-09-26 3:20 ` [dpdk-dev] [PATCH v6 4/4] examples/ntb: support more functions for NTB Xiaoyun Li
2019-09-26 4:04 ` [dpdk-dev] [PATCH v6 0/4] enable FIFO " Wu, Jingjing
2019-10-21 13:43 ` Thomas Monjalon
2019-10-21 15:54 ` David Marchand
2019-10-22 1:12 ` Li, Xiaoyun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9BB6961774997848B5B42BEC655768F81151CAF1@SHSMSX103.ccr.corp.intel.com \
--to=jingjing.wu@intel.com \
--cc=cunming.liang@intel.com \
--cc=dev@dpdk.org \
--cc=keith.wiles@intel.com \
--cc=omkar.maslekar@intel.com \
--cc=xiaoyun.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).