From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AECC6A0A0C; Fri, 2 Jul 2021 18:39:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A0F641363; Fri, 2 Jul 2021 18:39:28 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id B830341353 for ; Fri, 2 Jul 2021 18:39:26 +0200 (CEST) Received: from [192.168.38.17] (aros.oktetlabs.ru [192.168.38.17]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id 49B8A7F52A; Fri, 2 Jul 2021 19:39:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 49B8A7F52A DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1625243966; bh=1/PxHNNY9bLovZ1x4opdivvrjnGvipW81spC8ODQhxQ=; h=Subject:To:References:From:Date:In-Reply-To; b=tPQG8+KUmkeIu488Z+ZcWQwxaw6rZqZls8tNuoekXTrlWKguM4qQaG9r0QdX4AB8P R9pDJHoO83ph2jN9r2I6hqL4gokKJPAW+ItJGnz+orDt0zdGhug6pZifqtths3Tyzj zPOkZD0TvRvpVI1KAYKJwB3C4iZkpi4ZmYO285Jk= To: Jiawen Wu , dev@dpdk.org References: <20210617110005.4132926-1-jiawenwu@trustnetic.com> <20210617110005.4132926-14-jiawenwu@trustnetic.com> From: Andrew Rybchenko Organization: OKTET Labs Message-ID: <2d25c03f-8f1a-11d4-7ecb-440cf4502e53@oktetlabs.ru> Date: Fri, 2 Jul 2021 19:39:26 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210617110005.4132926-14-jiawenwu@trustnetic.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v6 13/19] net/ngbe: add Tx queue setup and release X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 6/17/21 1:59 PM, Jiawen Wu wrote: > Setup device Tx queue and release Tx queue. > > Signed-off-by: Jiawen Wu [snip] > +int __rte_cold > +ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev, > + uint16_t queue_idx, > + uint16_t nb_desc, > + unsigned int socket_id, > + const struct rte_eth_txconf *tx_conf) > +{ > + const struct rte_memzone *tz; > + struct ngbe_tx_queue *txq; > + struct ngbe_hw *hw; > + uint16_t tx_free_thresh; > + > + PMD_INIT_FUNC_TRACE(); > + hw = ngbe_dev_hw(dev); > + > + /* > + * Validate number of transmit descriptors. > + * It must not exceed hardware maximum, and must be multiple > + * of NGBE_ALIGN. > + */ > + if (nb_desc % NGBE_TXD_ALIGN != 0 || > + nb_desc > NGBE_RING_DESC_MAX || > + nb_desc < NGBE_RING_DESC_MIN) { > + return -EINVAL; > + } rte_eth_tx_queue_setup cares about it > + > + /* > + * The Tx descriptor ring will be cleaned after txq->tx_free_thresh > + * descriptors are used or if the number of descriptors required > + * to transmit a packet is greater than the number of free Tx > + * descriptors. > + * One descriptor in the Tx ring is used as a sentinel to avoid a > + * H/W race condition, hence the maximum threshold constraints. > + * When set to zero use default values. > + */ > + tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ? > + tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH); > + if (tx_free_thresh >= (nb_desc - 3)) { > + PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the number of " > + "TX descriptors minus 3. (tx_free_thresh=%u " > + "port=%d queue=%d)", Do not split format string. > + (unsigned int)tx_free_thresh, > + (int)dev->data->port_id, (int)queue_idx); > + return -(EINVAL); > + } > + > + if (nb_desc % tx_free_thresh != 0) { > + PMD_INIT_LOG(ERR, "tx_free_thresh must be a divisor of the " > + "number of Tx descriptors. (tx_free_thresh=%u " > + "port=%d queue=%d)", (unsigned int)tx_free_thresh, Do not split format string. > + (int)dev->data->port_id, (int)queue_idx); > + return -(EINVAL); > + } > + > + /* Free memory prior to re-allocation if needed... */ > + if (dev->data->tx_queues[queue_idx] != NULL) { > + ngbe_tx_queue_release(dev->data->tx_queues[queue_idx]); > + dev->data->tx_queues[queue_idx] = NULL; > + } > + > + /* First allocate the Tx queue data structure */ > + txq = rte_zmalloc_socket("ethdev Tx queue", > + sizeof(struct ngbe_tx_queue), > + RTE_CACHE_LINE_SIZE, socket_id); > + if (txq == NULL) > + return -ENOMEM; > + > + /* > + * Allocate Tx ring hardware descriptors. A memzone large enough to > + * handle the maximum ring size is allocated in order to allow for > + * resizing in later calls to the queue setup function. > + */ > + tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, > + sizeof(struct ngbe_tx_desc) * NGBE_RING_DESC_MAX, > + NGBE_ALIGN, socket_id); > + if (tz == NULL) { > + ngbe_tx_queue_release(txq); > + return -ENOMEM; > + } > + > + txq->nb_tx_desc = nb_desc; > + txq->tx_free_thresh = tx_free_thresh; > + txq->pthresh = tx_conf->tx_thresh.pthresh; > + txq->hthresh = tx_conf->tx_thresh.hthresh; > + txq->wthresh = tx_conf->tx_thresh.wthresh; > + txq->queue_id = queue_idx; > + txq->reg_idx = queue_idx; > + txq->port_id = dev->data->port_id; > + txq->ops = &def_txq_ops; > + txq->tx_deferred_start = tx_conf->tx_deferred_start; > + > + txq->tdt_reg_addr = NGBE_REG_ADDR(hw, NGBE_TXWP(txq->reg_idx)); > + txq->tdc_reg_addr = NGBE_REG_ADDR(hw, NGBE_TXCFG(txq->reg_idx)); > + > + txq->tx_ring_phys_addr = TMZ_PADDR(tz); > + txq->tx_ring = (struct ngbe_tx_desc *)TMZ_VADDR(tz); > + > + /* Allocate software ring */ > + txq->sw_ring = rte_zmalloc_socket("txq->sw_ring", > + sizeof(struct ngbe_tx_entry) * nb_desc, > + RTE_CACHE_LINE_SIZE, socket_id); > + if (txq->sw_ring == NULL) { > + ngbe_tx_queue_release(txq); > + return -ENOMEM; > + } > + PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64, > + txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr); > + > + txq->ops->reset(txq); > + > + dev->data->tx_queues[queue_idx] = txq; > + > + return 0; > +} > + > /** > * ngbe_free_sc_cluster - free the not-yet-completed scattered cluster [snip]