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 8AB29A0543; Tue, 21 Jun 2022 10:10:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EE55242B92; Tue, 21 Jun 2022 10:09:25 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2112.outbound.protection.outlook.com [40.107.243.112]) by mails.dpdk.org (Postfix) with ESMTP id F285942B8B for ; Tue, 21 Jun 2022 10:09:23 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h59bq3vAXjlphEHYm1W79+m2z9UJKtd/DZSkXrvRBJhVXTWUHGwRZOBJdbHVUluqSFYTQHjgidwqs7Sspxmh6xlzWP5gug5Ew2nqo1/Ikimm0WYAlrHyK/FixS9lccs9h2BCqLML+ImoiHDlnLeO8+daFd4ohZgCOp8msiM35IMC0duuiv5oH8DHGEtqO5RXQ1XGSeDYtmqGBae4bCVHgT1WXsRmPtop0qORm6rGk+nOix/s9axBHlwmLdMdDnZG0hJ3qz3xbJ48BXgRR9PByaB7SnEBWTKDOXkP6qoekhU1K/tvPsGjXYi+P6gRqNBrUDpjB98+JPRoxJnqAfzQtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZFvN8wSuV0Q6wtdTXcZht1tdO4+KGwvrQZMBFDO6S0U=; b=k2lDKy1gcEdBpy7bbEvN3X7xAY2N/EYsnY1dNoSIB60FmZvlk3UJ+RUhq/e6gVIjtUmONKdg2ddIlesAtgki/hRqfX30aI6LYO1487aTilPgKNHAXXK1+CdW/FBcQrzzNNLDU3uEO4dhxxFkeHwoPtvT3a9D38aGqj8ENTsdPxV289Usa7YGnrx/18q978aEX+CoqLCKkYQaUd4d8PQaR7wprG8Pp22dOiJu0s1affO6DVV5hml2g2VymC7L7jteyYX3Yieia+TijSn6+Sd42Zy4/EJMjx3ZJcTVk1xZtBJqkwLjdmUFa1EjF8LNNcI2Jx+oIx+g+Z/mJVJHFAtiiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZFvN8wSuV0Q6wtdTXcZht1tdO4+KGwvrQZMBFDO6S0U=; b=JfS1an/gsn/EyWDSvb/yvZGBpbHYgwAyjUz4EuIcR7f6W3tVgcBnMhsc2Rqp8k8kRSPicdIQS9z1grtsLiZV/6Ndnu6Tdt6flLI4WrmBsAAkwKtsQuNXLeWUnK8IeSOeQXlG6p9E92vcAOh5rkRhdIZmTopcAKwx0lW7rwKEXoQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by DM5PR13MB1756.namprd13.prod.outlook.com (2603:10b6:3:12f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Tue, 21 Jun 2022 08:09:22 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5d9e:9ce5:51d1:2021]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5d9e:9ce5:51d1:2021%7]) with mapi id 15.20.5373.015; Tue, 21 Jun 2022 08:09:22 +0000 From: Chaoyong He To: dev@dpdk.org Cc: niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH 07/12] net/nfp: add flower ctrl VNIC related logics Date: Tue, 21 Jun 2022 16:08:34 +0800 Message-Id: <1655798919-38659-8-git-send-email-chaoyong.he@corigine.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1655798919-38659-1-git-send-email-chaoyong.he@corigine.com> References: <1655798919-38659-1-git-send-email-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: OS0P286CA0009.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:9c::14) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c22ec812-b031-4431-5a8e-08da535d5972 X-MS-TrafficTypeDiagnostic: DM5PR13MB1756:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yEvwreUrCBV+7saJtU5O7a+lploqnHqr4g2dkRA4iV3hueSiftAc85ZQdHYeB/95CpAvg1LoervijAdQ9Pb1VX1qlhHKiCEPihJmFhWCTRu5GsP/iECoJmmxAL9sERoWX/yis9LWkHuNEvJxrYloOX/UNS//UjlgAoB7NY8uyKgEGvPVsNk3f97xM2wdB8upw3bLpVr82dtFwwEfGUGEDC2OuZ34UDJzC0UqauoCr71SRk9EJyThwt8U415LCUeOzbcQmdimNZXfYX1Y1QR8YQSN5fku3e+xpee3f1Gj+2qm0FKpLqb75EwMgdR43NtoqU0ENi/P7ht9pjunInsgMCgNvviW40emyeqivTvzny9sGo1Ix4NYXqqlCqp5niXoVNx0aMN1TdS1L8tTgI28yqT4RDDeNe7Zv6fd2lDJR8zojhDebfmBJH+oXiWCp6XNx/HvWxIqY7JXL6tBawJr97WiZbCO9cbojy5j4sJ02CYSZr4EZ0woFJMjugARch/8ugIBEHHTqxmv+yH+mhM0uqmzgHkbUWXfk7ekAqWyCuDdXb5DAq+BMOqplMDe+/2J+S4SMio/5Uy0JN4Idm/O5YXKeB9Onx2eD7ZmyzbAJrdBVHDxq7nwC6b69y1nuqu7nVuzWms1R7E+Xr3ruWZaVWSsTMqgO4F5F9fjIjN8fSnIfcA3wq9cw/VX2OlWxBPjpGuAnWv/3OB9ZSOx6XCbBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(366004)(396003)(39840400004)(346002)(26005)(2906002)(6666004)(6512007)(8936002)(36756003)(107886003)(83380400001)(44832011)(5660300002)(66574015)(186003)(86362001)(30864003)(4326008)(2616005)(6916009)(316002)(6486002)(8676002)(41300700001)(66476007)(66556008)(66946007)(478600001)(52116002)(38100700002)(6506007)(38350700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VXhUWFNQb3RvS3pHZFFENlhrb2I0RGhTWGZYL0dBd0Z1RWV0V05TbGQ2NFdm?= =?utf-8?B?d2xTOE94U0lOMU1kTXRSOVJLZTZZOGNETVdpNEpBOTlFR0tZMHRLYVRtNW5U?= =?utf-8?B?bWhQbWtDOGxERmIrcGt5UzB5V2Fka3JIVlQ2N1BFNUF3eVBaWGZKUlRFbit2?= =?utf-8?B?bXFOSFpOSWdiMDhOTWh6eDBDUGJaSEtxN3dMNGFMa000VUNRQ28xNXVEakpw?= =?utf-8?B?YkVWOG53Z0lRUGJwbFd0VkxoL2xDaWlabDdMSG40amtyYkU4VUlCSVJIRkE0?= =?utf-8?B?Vk84K0NQSjZTVVRRT2RCL2UzSG1FYW1zMFl6Nm8xKzJEbHA2Q3NMbUd5NkNW?=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PcUJPN28vcHZ2VWNDR0Nj?= =?utf-8?B?L1RlTWlMWVlHbUlXT3J1bEttOWV0WFFmeUR2UU9JWjBlMmFZTkkzZVR5eUlu?= =?utf-8?B?UlN2ZXRlUWxLbFNWWG82WWQxVlhzS0tFelVjQU9DeWt2U1pOc3JTV011cnpv?= =?utf-8?B?WExwcHA3Sk9Ocjc0dWZ1VmE3RVdYNHprd1BXalJnNU4vU2ZUQ3R3MHF3OEg5?= =?utf-8?Q?zGatpGBiCUyNnOx0=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: c22ec812-b031-4431-5a8e-08da535d5972 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 08:09:22.5170 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sQtmZRHTO7+lGP0JNM0e9wlUpCiX8t4xse0zjVrhkEBYkdUsymZ2HEg/rd7qt9uMK1ne58iBO0ecS36PgupWWxvyOF9dYpdGZjWYjT2n1GY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR13MB1756 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 This commit adds the setup/start logic for the ctrl vNIC. This vNIC is used by the PMD and flower firmware as a communication channel between driver and firmware. In the case of OVS it is also used to communicate flow statistics from hardware to the driver. A rte_eth device is not exposed to DPDK for this vNIC as it is strictly used internally by flower logic. Rx and Tx logic will be added later for this vNIC. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/flower/nfp_flower.c | 391 +++++++++++++++++++++++++++++++++++- drivers/net/nfp/flower/nfp_flower.h | 6 + 2 files changed, 394 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 417155e..6cdec87 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -26,6 +26,10 @@ #define MEMPOOL_CACHE_SIZE 512 #define DEFAULT_FLBUF_SIZE 9216 +#define CTRL_VNIC_NB_DESC 64 +#define CTRL_VNIC_RX_FREE_THRESH 32 +#define CTRL_VNIC_TX_FREE_THRESH 32 + /* * Simple dev ops functions for the flower PF. Because a rte_device is exposed * to DPDK the flower logic also makes use of helper functions like @@ -549,6 +553,308 @@ return ret; } +static void +nfp_flower_cleanup_ctrl_vnic(struct nfp_net_hw *hw) +{ + uint32_t i; + struct nfp_net_rxq *rxq; + struct nfp_net_txq *txq; + struct rte_eth_dev *eth_dev; + + eth_dev = hw->eth_dev; + + for (i = 0; i < hw->max_tx_queues; i++) { + txq = eth_dev->data->tx_queues[i]; + if (txq) { + rte_free(txq->txbufs); + rte_eth_dma_zone_free(eth_dev, "ctrl_tx_ring", i); + rte_free(txq); + } + } + + for (i = 0; i < hw->max_rx_queues; i++) { + rxq = eth_dev->data->rx_queues[i]; + if (rxq) { + rte_free(rxq->rxbufs); + rte_eth_dma_zone_free(eth_dev, "ctrl_rx_ring", i); + rte_free(rxq); + } + } + + rte_free(eth_dev->data->tx_queues); + rte_free(eth_dev->data->rx_queues); + rte_free(eth_dev->data); + rte_free(eth_dev); +} + +static int +nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) +{ + uint32_t i; + int ret = 0; + uint16_t nb_desc; + unsigned int numa_node; + struct rte_mempool *mp; + uint16_t rx_free_thresh; + uint16_t tx_free_thresh; + struct nfp_net_rxq *rxq; + struct nfp_net_txq *txq; + struct nfp_pf_dev *pf_dev; + struct rte_eth_dev *eth_dev; + const struct rte_memzone *tz; + struct nfp_app_flower *app_flower; + + /* Hardcoded values for now */ + nb_desc = CTRL_VNIC_NB_DESC; + rx_free_thresh = CTRL_VNIC_RX_FREE_THRESH; + tx_free_thresh = CTRL_VNIC_TX_FREE_THRESH; + numa_node = rte_socket_id(); + + /* Set up some pointers here for ease of use */ + pf_dev = hw->pf_dev; + app_flower = NFP_APP_PRIV_TO_APP_FLOWER(pf_dev->app_priv); + + ret = nfp_flower_init_vnic_common(hw, "ctrl_vnic"); + if (ret) + goto done; + + /* Allocate memory for the eth_dev of the vNIC */ + hw->eth_dev = rte_zmalloc("ctrl_vnic_eth_dev", + sizeof(struct rte_eth_dev), RTE_CACHE_LINE_SIZE); + if (hw->eth_dev == NULL) { + ret = -ENOMEM; + goto done; + } + + /* Grab the pointer to the newly created rte_eth_dev here */ + eth_dev = hw->eth_dev; + + /* Also allocate memory for the data part of the eth_dev */ + eth_dev->data = rte_zmalloc("ctrl_vnic_eth_dev_data", + sizeof(struct rte_eth_dev_data), RTE_CACHE_LINE_SIZE); + if (eth_dev->data == NULL) { + ret = -ENOMEM; + goto eth_dev_cleanup; + } + + eth_dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues", + sizeof(eth_dev->data->rx_queues[0]) * hw->max_rx_queues, + RTE_CACHE_LINE_SIZE); + if (eth_dev->data->rx_queues == NULL) { + PMD_INIT_LOG(ERR, "rte_zmalloc failed for ctrl vnic rx queues"); + ret = -ENOMEM; + goto dev_data_cleanup; + } + + eth_dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues", + sizeof(eth_dev->data->tx_queues[0]) * hw->max_tx_queues, + RTE_CACHE_LINE_SIZE); + if (eth_dev->data->tx_queues == NULL) { + PMD_INIT_LOG(ERR, "rte_zmalloc failed for ctrl vnic tx queues"); + ret = -ENOMEM; + goto rx_queue_cleanup; + } + + eth_dev->device = &pf_dev->pci_dev->device; + eth_dev->data->nb_tx_queues = hw->max_tx_queues; + eth_dev->data->nb_rx_queues = hw->max_rx_queues; + eth_dev->data->dev_private = hw; + + /* Create a mbuf pool for the vNIC */ + app_flower->ctrl_pktmbuf_pool = rte_pktmbuf_pool_create("ctrl_mbuf_pool", + 2 * nb_desc, 64, 0, 9216, numa_node); + if (app_flower->ctrl_pktmbuf_pool == NULL) { + PMD_INIT_LOG(ERR, "create mbuf pool for ctrl vnic failed"); + ret = -ENOMEM; + goto tx_queue_cleanup; + } + + mp = app_flower->ctrl_pktmbuf_pool; + + /* Set up the Rx queues */ + PMD_INIT_LOG(INFO, "Configuring flower ctrl vNIC Rx queue"); + for (i = 0; i < hw->max_rx_queues; i++) { + /* Hardcoded number of desc to 64 */ + rxq = rte_zmalloc_socket("ethdev RX queue", + sizeof(struct nfp_net_rxq), RTE_CACHE_LINE_SIZE, + numa_node); + if (rxq == NULL) { + PMD_DRV_LOG(ERR, "Error allocating rxq"); + ret = -ENOMEM; + goto rx_queue_setup_cleanup; + } + + eth_dev->data->rx_queues[i] = rxq; + + /* Hw queues mapping based on firmware configuration */ + rxq->qidx = i; + rxq->fl_qcidx = i * hw->stride_rx; + rxq->rx_qcidx = rxq->fl_qcidx + (hw->stride_rx - 1); + rxq->qcp_fl = hw->rx_bar + NFP_QCP_QUEUE_OFF(rxq->fl_qcidx); + rxq->qcp_rx = hw->rx_bar + NFP_QCP_QUEUE_OFF(rxq->rx_qcidx); + + /* + * Tracking mbuf size for detecting a potential mbuf overflow due to + * RX offset + */ + rxq->mem_pool = mp; + rxq->mbuf_size = rxq->mem_pool->elt_size; + rxq->mbuf_size -= (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM); + hw->flbufsz = rxq->mbuf_size; + + rxq->rx_count = nb_desc; + rxq->rx_free_thresh = rx_free_thresh; + rxq->drop_en = 1; + + /* + * Allocate RX 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(eth_dev, "ctrl_rx_ring", i, + sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + NFP_MEMZONE_ALIGN, numa_node); + if (tz == NULL) { + PMD_DRV_LOG(ERR, "Error allocating rx dma"); + rte_free(rxq); + ret = -ENOMEM; + goto rx_queue_setup_cleanup; + } + + /* Saving physical and virtual addresses for the RX ring */ + rxq->dma = (uint64_t)tz->iova; + rxq->rxds = (struct nfp_net_rx_desc *)tz->addr; + + /* mbuf pointers array for referencing mbufs linked to RX descriptors */ + rxq->rxbufs = rte_zmalloc_socket("rxq->rxbufs", + sizeof(*rxq->rxbufs) * nb_desc, RTE_CACHE_LINE_SIZE, + numa_node); + if (rxq->rxbufs == NULL) { + rte_eth_dma_zone_free(eth_dev, "ctrl_rx_ring", i); + rte_free(rxq); + ret = -ENOMEM; + goto rx_queue_setup_cleanup; + } + + PMD_RX_LOG(DEBUG, "rxbufs=%p hw_ring=%p dma_addr=0x%llx", + rxq->rxbufs, rxq->rxds, rxq->dma); + + nfp_net_reset_rx_queue(rxq); + + rxq->hw = hw; + + /* + * Telling the HW about the physical address of the RX ring and number + * of descriptors in log2 format + */ + nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(i), rxq->dma); + nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(i), rte_log2_u32(nb_desc)); + } + + /* Now the Tx queues */ + PMD_INIT_LOG(INFO, "Configuring flower ctrl vNIC Tx queue"); + for (i = 0; i < hw->max_tx_queues; i++) { + /* Hardcoded number of desc to 64 */ + /* Allocating tx queue data structure */ + txq = rte_zmalloc_socket("ethdev TX queue", + sizeof(struct nfp_net_txq), RTE_CACHE_LINE_SIZE, + numa_node); + if (txq == NULL) { + PMD_DRV_LOG(ERR, "Error allocating txq"); + ret = -ENOMEM; + goto tx_queue_setup_cleanup; + } + + eth_dev->data->tx_queues[i] = txq; + + /* + * 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(eth_dev, "ctrl_tx_ring", i, + sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + NFP_MEMZONE_ALIGN, numa_node); + if (tz == NULL) { + PMD_DRV_LOG(ERR, "Error allocating tx dma"); + rte_free(txq); + ret = -ENOMEM; + goto tx_queue_setup_cleanup; + } + + txq->tx_count = nb_desc; + txq->tx_free_thresh = tx_free_thresh; + txq->tx_pthresh = DEFAULT_TX_PTHRESH; + txq->tx_hthresh = DEFAULT_TX_HTHRESH; + txq->tx_wthresh = DEFAULT_TX_WTHRESH; + + /* queue mapping based on firmware configuration */ + txq->qidx = i; + txq->tx_qcidx = i * hw->stride_tx; + txq->qcp_q = hw->tx_bar + NFP_QCP_QUEUE_OFF(txq->tx_qcidx); + + /* Saving physical and virtual addresses for the TX ring */ + txq->dma = (uint64_t)tz->iova; + txq->txds = (struct nfp_net_nfd3_tx_desc *)tz->addr; + + /* mbuf pointers array for referencing mbufs linked to TX descriptors */ + txq->txbufs = rte_zmalloc_socket("txq->txbufs", + sizeof(*txq->txbufs) * nb_desc, RTE_CACHE_LINE_SIZE, + numa_node); + if (txq->txbufs == NULL) { + rte_eth_dma_zone_free(eth_dev, "ctrl_tx_ring", i); + rte_free(txq); + ret = -ENOMEM; + goto tx_queue_setup_cleanup; + } + + PMD_TX_LOG(DEBUG, "txbufs=%p hw_ring=%p dma_addr=0x%llx", + txq->txbufs, txq->txds, txq->dma); + + nfp_net_reset_tx_queue(txq); + + txq->hw = hw; + + /* + * Telling the HW about the physical address of the TX ring and number + * of descriptors in log2 format + */ + nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(i), txq->dma); + nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(i), rte_log2_u32(nb_desc)); + } + + return 0; + +tx_queue_setup_cleanup: + for (i = 0; i < hw->max_tx_queues; i++) { + txq = eth_dev->data->tx_queues[i]; + if (txq) { + rte_free(txq->txbufs); + rte_eth_dma_zone_free(eth_dev, "ctrl_tx_ring", i); + rte_free(txq); + } + } +rx_queue_setup_cleanup: + for (i = 0; i < hw->max_rx_queues; i++) { + rxq = eth_dev->data->rx_queues[i]; + if (rxq) { + rte_free(rxq->rxbufs); + rte_eth_dma_zone_free(eth_dev, "ctrl_rx_ring", i); + rte_free(rxq); + } + } +tx_queue_cleanup: + rte_free(eth_dev->data->tx_queues); +rx_queue_cleanup: + rte_free(eth_dev->data->rx_queues); +dev_data_cleanup: + rte_free(eth_dev->data); +eth_dev_cleanup: + rte_free(eth_dev); +done: + return ret; +} + static int nfp_flower_start_pf_vnic(struct nfp_net_hw *hw) { @@ -567,12 +873,57 @@ return 0; } +static int +nfp_flower_start_ctrl_vnic(struct nfp_net_hw *hw) +{ + int ret; + uint32_t update; + uint32_t new_ctrl; + struct rte_eth_dev *dev; + + dev = hw->eth_dev; + + /* Disabling queues just in case... */ + nfp_net_disable_queues(dev); + + /* Enabling the required queues in the device */ + nfp_net_enable_queues(dev); + + /* Writing configuration parameters in the device */ + nfp_net_params_setup(hw); + + new_ctrl = NFP_NET_CFG_CTRL_ENABLE; + update = NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING | + NFP_NET_CFG_UPDATE_MSIX; + + rte_wmb(); + + /* If an error when reconfig we avoid to change hw state */ + ret = nfp_net_reconfig(hw, new_ctrl, update); + if (ret) { + PMD_INIT_LOG(ERR, "Failed to reconfig ctrl vnic"); + return -EIO; + } + + hw->ctrl = new_ctrl; + + /* Setup the freelist ring */ + ret = nfp_net_rx_freelist_setup(dev); + if (ret) { + PMD_INIT_LOG(ERR, "Error with flower ctrl vNIC freelist setup"); + return -EIO; + } + + return 0; +} + int nfp_init_app_flower(struct nfp_pf_dev *pf_dev) { int ret; unsigned int numa_node; struct nfp_net_hw *pf_hw; + struct nfp_net_hw *ctrl_hw; struct nfp_app_flower *app_flower; numa_node = rte_socket_id(); @@ -618,29 +969,63 @@ pf_hw->pf_dev = pf_dev; pf_hw->cpp = pf_dev->cpp; + /* The ctrl vNIC struct comes directly after the PF one */ + app_flower->ctrl_hw = pf_hw + 1; + ctrl_hw = app_flower->ctrl_hw; + + /* Map the ctrl vNIC ctrl bar */ + ctrl_hw->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_ctrl_bar", + 32768, &ctrl_hw->ctrl_area); + if (ctrl_hw->ctrl_bar == NULL) { + PMD_INIT_LOG(ERR, "Cloud not map the ctrl vNIC ctrl bar"); + ret = -ENODEV; + goto pf_cpp_area_cleanup; + } + + /* Now populate the ctrl vNIC */ + ctrl_hw->pf_dev = pf_dev; + ctrl_hw->cpp = pf_dev->cpp; + ret = nfp_flower_init_pf_vnic(app_flower->pf_hw); if (ret) { PMD_INIT_LOG(ERR, "Could not initialize flower PF vNIC"); - goto pf_cpp_area_cleanup; + goto ctrl_cpp_area_cleanup; + } + + ret = nfp_flower_init_ctrl_vnic(app_flower->ctrl_hw); + if (ret) { + PMD_INIT_LOG(ERR, "Could not initialize flower ctrl vNIC"); + goto pf_vnic_cleanup; } /* Start the PF vNIC */ ret = nfp_flower_start_pf_vnic(app_flower->pf_hw); if (ret) { PMD_INIT_LOG(ERR, "Could not start flower PF vNIC"); - goto pf_vnic_cleanup; + goto ctrl_vnic_cleanup; + } + + /* Start the ctrl vNIC */ + ret = nfp_flower_start_ctrl_vnic(app_flower->ctrl_hw); + if (ret) { + PMD_INIT_LOG(ERR, "Could not start flower ctrl vNIC"); + goto ctrl_vnic_cleanup; } /* Start up flower services */ if (nfp_flower_enable_services(app_flower)) { ret = -ESRCH; - goto pf_vnic_cleanup; + goto ctrl_vnic_cleanup; } return 0; +ctrl_vnic_cleanup: + nfp_flower_cleanup_ctrl_vnic(app_flower->ctrl_hw); pf_vnic_cleanup: nfp_flower_cleanup_pf_vnic(app_flower->pf_hw); +ctrl_cpp_area_cleanup: + nfp_cpp_area_free(ctrl_hw->ctrl_area); pf_cpp_area_cleanup: nfp_cpp_area_free(pf_dev->ctrl_area); eth_tbl_cleanup: diff --git a/drivers/net/nfp/flower/nfp_flower.h b/drivers/net/nfp/flower/nfp_flower.h index f6fd4eb..f11ef6d 100644 --- a/drivers/net/nfp/flower/nfp_flower.h +++ b/drivers/net/nfp/flower/nfp_flower.h @@ -21,6 +21,12 @@ struct nfp_app_flower { /* Pointer to the PF vNIC */ struct nfp_net_hw *pf_hw; + /* Pointer to a mempool for the ctrlvNIC */ + struct rte_mempool *ctrl_pktmbuf_pool; + + /* Pointer to the ctrl vNIC */ + struct nfp_net_hw *ctrl_hw; + /* the eth table as reported by firmware */ struct nfp_eth_table *nfp_eth_table; }; -- 1.8.3.1