+ nsp = nfp_nsp_open(cpp);
+ if (!nsp) {
+ PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle");
+ return -EIO;
+ }
+
+ nfp_nsp_device_soft_reset(nsp);
+ err = nfp_fw_upload(dev, nsp, card_desc);
+
+ nfp_nsp_close(nsp);
+ return err;
+}
+
+static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
+{
+ struct nfp_net_hw *hw;
+ struct rte_eth_dev *eth_dev;
+ int ret = 0;
+ int i;
+
+ /* Loop through all physical ports on PF */
+ for (i = 0; i < pf_dev->total_phyports; i++) {
+ const unsigned int numa_node = rte_socket_id();
+ char port_name[RTE_ETH_NAME_MAX_LEN];
+
+ snprintf(port_name, sizeof(port_name), "%s_port%d",
+ pf_dev->pci_dev->device.name, i);
+
+ if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+ eth_dev = rte_eth_dev_attach_secondary(port_name);
+ if (!eth_dev) {
+ RTE_LOG(ERR, EAL,
+ "secondary process attach failed, "
+ "ethdev doesn't exist");
+ ret = -ENODEV;
+ goto error;
+ }
+
+ eth_dev->process_private = pf_dev->cpp;
+ goto nfp_net_init;
+ }
+
+ /* First port has already been initialized */
+ if (i == 0) {
+ eth_dev = pf_dev->eth_dev;
+ goto skip_dev_alloc;
+ }
+
+ /* Allocate a eth_dev for remaining ports */
+ eth_dev = rte_eth_dev_allocate(port_name);
+ if (!eth_dev) {
+ ret = -ENODEV;
+ goto port_cleanup;
+ }
+
+ /* Allocate memory for remaining ports */
+ eth_dev->data->dev_private =
+ rte_zmalloc_socket(port_name, sizeof(struct nfp_net_hw),
+ RTE_CACHE_LINE_SIZE, numa_node);
+ if (!eth_dev->data->dev_private) {
+ ret = -ENOMEM;
+ rte_eth_dev_release_port(eth_dev);
+ goto port_cleanup;
+ }
+
+skip_dev_alloc:
+ hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
+
+ /* Add this device to the PF's array of physical ports */
+ pf_dev->ports[i] = hw;
+
+ hw->pf_dev = pf_dev;
+ hw->cpp = pf_dev->cpp;
+ hw->eth_dev = eth_dev;
+ hw->idx = i;
+ hw->is_phyport = true;
+
+nfp_net_init:
+ eth_dev->device = &pf_dev->pci_dev->device;
+
+ /* ctrl/tx/rx BAR mappings and remaining init happens in
+ * nfp_net_init
+ */
+ ret = nfp_net_init(eth_dev);
+
+ if (ret) {
+ ret = -ENODEV;
+ goto port_cleanup;
+ }
+
+ rte_eth_dev_probing_finish(eth_dev);
+
+ } /* End loop, all ports on this PF */
+ return 0;
+
+port_cleanup:
+ for (i = 0; i < pf_dev->total_phyports; i++) {
+ if (pf_dev->ports[i] && pf_dev->ports[i]->eth_dev) {
+ struct rte_eth_dev *tmp_dev;
+ tmp_dev = pf_dev->ports[i]->eth_dev;
+ rte_eth_dev_release_port(tmp_dev);
+ pf_dev->ports[i] = NULL;
+ }
+ }
+error:
+ return ret;
+}
+
+static int nfp_pf_init(struct rte_eth_dev *eth_dev)
+{
+ struct rte_pci_device *pci_dev;
+ struct nfp_net_hw *hw = NULL;
+ struct nfp_pf_dev *pf_dev = NULL;
+ struct nfp_cpp *cpp;
+ struct nfp_hwinfo *hwinfo;
+ struct nfp_rtsym_table *sym_tbl;
+ struct nfp_eth_table *nfp_eth_table = NULL;
+ struct rte_service_spec service;
+ char name[RTE_ETH_NAME_MAX_LEN];
+ int total_ports;
+ int ret = -ENODEV;
+ int err;
+
+ pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+ hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev);
+
+ if (!pci_dev)
+ return ret;
+
+ /*
+ * When device bound to UIO, the device could be used, by mistake,
+ * by two DPDK apps, and the UIO driver does not avoid it. This
+ * could lead to a serious problem when configuring the NFP CPP
+ * interface. Here we avoid this telling to the CPP init code to
+ * use a lock file if UIO is being used.
+ */
+ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
+ cpp = nfp_cpp_from_device_name(pci_dev, 0);
+ else
+ cpp = nfp_cpp_from_device_name(pci_dev, 1);
+
+ if (!cpp) {
+ PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
+ ret = -EIO;
+ goto error;
+ }
+
+ hwinfo = nfp_hwinfo_read(cpp);
+ if (!hwinfo) {
+ PMD_INIT_LOG(ERR, "Error reading hwinfo table");
+ ret = -EIO;
+ goto error;
+ }
+
+ nfp_eth_table = nfp_eth_read_ports(cpp);
+ if (!nfp_eth_table) {
+ PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
+ ret = -EIO;
+ goto hwinfo_cleanup;
+ }
+
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo)) {
+ PMD_INIT_LOG(ERR, "Error when uploading firmware");
+ ret = -EIO;
+ goto eth_table_cleanup;
+ }
+ }
+
+ /* Now the symbol table should be there */
+ sym_tbl = nfp_rtsym_table_read(cpp);
+ if (!sym_tbl) {
+ PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
+ " symbol table");
+ ret = -EIO;
+ goto eth_table_cleanup;
+ }
+
+ total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
+ if (total_ports != (int)nfp_eth_table->count) {
+ PMD_DRV_LOG(ERR, "Inconsistent number of ports");
+ ret = -EIO;
+ goto sym_tbl_cleanup;
+ }
+
+ PMD_INIT_LOG(INFO, "Total physical ports: %d", total_ports);
+
+ if (total_ports <= 0 || total_ports > 8) {
+ PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value");
+ ret = -ENODEV;
+ goto sym_tbl_cleanup;
+ }
+ /* Allocate memory for the PF "device" */
+ snprintf(name, sizeof(name), "nfp_pf%d", eth_dev->data->port_id);
+ pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
+ if (!pf_dev) {
+ ret = -ENOMEM;
+ goto sym_tbl_cleanup;
+ }
+
+ /* Populate the newly created PF device */
+ pf_dev->cpp = cpp;
+ pf_dev->hwinfo = hwinfo;
+ pf_dev->sym_tbl = sym_tbl;
+ pf_dev->total_phyports = total_ports;
+
+ if (total_ports > 1)
+ pf_dev->multiport = true;
+
+ pf_dev->pci_dev = pci_dev;
+
+ /* The first eth_dev is part of the PF struct */
+ pf_dev->eth_dev = eth_dev;
+
+ /* Map the symbol table */
+ pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0",
+ pf_dev->total_phyports * 32768,
+ &pf_dev->ctrl_area);
+ if (!pf_dev->ctrl_bar) {
+ PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _pf0_net_ctrl_bar");
+ ret = -EIO;
+ goto pf_cleanup;
+ }
+
+ PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar);
+
+ /* configure access to tx/rx vNIC BARs */
+ pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0,
+ NFP_PCIE_QUEUE(0),
+ NFP_QCP_QUEUE_AREA_SZ,
+ &pf_dev->hwqueues_area);
+ if (!pf_dev->hw_queues) {
+ PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc");
+ ret = -EIO;
+ goto ctrl_area_cleanup;
+ }
+
+ PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues);
+
+ /* Initialize and prep physical ports now
+ * This will loop through all physical ports
+ */
+ ret = nfp_init_phyports(pf_dev);
+ if (ret) {
+ PMD_INIT_LOG(ERR, "Could not create physical ports");
+ goto hwqueues_cleanup;
+ }
+
+ /*
+ * The rte_service needs to be created just once per PMD.
+ * And the cpp handler needs to be linked to the service.
+ * Secondary processes will be used for debugging DPDK apps
+ * when requiring to use the CPP interface for accessing NFP
+ * components. And the cpp handler for secondary processes is
+ * available at this point.
+ */
+ memset(&service, 0, sizeof(struct rte_service_spec));
+ snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
+ service.callback = nfp_cpp_bridge_service_func;
+ service.callback_userdata = (void *)cpp;
+
+ if (rte_service_component_register(&service,
+ &hw->nfp_cpp_service_id))
+ RTE_LOG(ERR, PMD, "NFP CPP bridge service register() failed");
+ else
+ RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
+
+ return 0;
+
+hwqueues_cleanup:
+ nfp_cpp_area_free(pf_dev->hwqueues_area);
+ctrl_area_cleanup:
+ nfp_cpp_area_free(pf_dev->ctrl_area);
+pf_cleanup:
+ rte_free(pf_dev);
+sym_tbl_cleanup:
+ free(sym_tbl);
+eth_table_cleanup:
+ free(nfp_eth_table);
+hwinfo_cleanup:
+ free(hwinfo);
+error:
+ return ret;
+}
+
+static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *dev)
+{
+ return rte_eth_dev_pci_generic_probe(dev,
+ sizeof(struct nfp_net_hw), nfp_pf_init);