Lines Matching full:pf
39 * @pf: NFP PF handle
47 nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev, in nfp_net_get_mac_addr() argument
74 static int nfp_net_pf_get_num_ports(struct nfp_pf *pf) in nfp_net_pf_get_num_ports() argument
76 return nfp_pf_rtsym_read_optional(pf, "nfd_cfg_pf%u_num_ports", 1); in nfp_net_pf_get_num_ports()
79 static int nfp_net_pf_get_app_id(struct nfp_pf *pf) in nfp_net_pf_get_app_id() argument
81 return nfp_pf_rtsym_read_optional(pf, "_pf%u_net_app_id", in nfp_net_pf_get_app_id()
85 static void nfp_net_pf_free_vnic(struct nfp_pf *pf, struct nfp_net *nn) in nfp_net_pf_free_vnic() argument
88 nfp_app_vnic_free(pf->app, nn); in nfp_net_pf_free_vnic()
91 pf->num_vnics--; in nfp_net_pf_free_vnic()
95 static void nfp_net_pf_free_vnics(struct nfp_pf *pf) in nfp_net_pf_free_vnics() argument
99 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) in nfp_net_pf_free_vnics()
101 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pf_free_vnics()
105 nfp_net_pf_alloc_vnic(struct nfp_pf *pf, bool needs_netdev, in nfp_net_pf_alloc_vnic() argument
119 nn = nfp_net_alloc(pf->pdev, ctrl_bar, needs_netdev, in nfp_net_pf_alloc_vnic()
124 nn->app = pf->app; in nfp_net_pf_alloc_vnic()
133 err = nfp_app_vnic_alloc(pf->app, nn, id); in nfp_net_pf_alloc_vnic()
140 pf->num_vnics++; in nfp_net_pf_alloc_vnic()
141 list_add_tail(&nn->vnic_list, &pf->vnics); in nfp_net_pf_alloc_vnic()
147 nfp_net_pf_init_vnic(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id) in nfp_net_pf_init_vnic() argument
154 err = nfp_devlink_port_register(pf->app, nn->port); in nfp_net_pf_init_vnic()
163 nfp_net_debugfs_vnic_add(nn, pf->ddir); in nfp_net_pf_init_vnic()
171 err = nfp_app_vnic_init(pf->app, nn); in nfp_net_pf_init_vnic()
190 nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, in nfp_net_pf_alloc_vnics() argument
197 for (i = 0; i < pf->max_data_vnics; i++) { in nfp_net_pf_alloc_vnics()
198 nn = nfp_net_pf_alloc_vnic(pf, true, ctrl_bar, qc_bar, in nfp_net_pf_alloc_vnics()
209 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pf_alloc_vnics()
212 if (list_empty(&pf->vnics)) in nfp_net_pf_alloc_vnics()
218 nfp_net_pf_free_vnics(pf); in nfp_net_pf_alloc_vnics()
222 static void nfp_net_pf_clean_vnic(struct nfp_pf *pf, struct nfp_net *nn) in nfp_net_pf_clean_vnic() argument
225 nfp_app_vnic_clean(pf->app, nn); in nfp_net_pf_clean_vnic()
234 static int nfp_net_pf_alloc_irqs(struct nfp_pf *pf) in nfp_net_pf_alloc_irqs() argument
241 list_for_each_entry(nn, &pf->vnics, vnic_list) in nfp_net_pf_alloc_irqs()
243 pf->irq_entries = kcalloc(wanted_irqs, sizeof(*pf->irq_entries), in nfp_net_pf_alloc_irqs()
245 if (!pf->irq_entries) in nfp_net_pf_alloc_irqs()
248 num_irqs = nfp_net_irqs_alloc(pf->pdev, pf->irq_entries, in nfp_net_pf_alloc_irqs()
249 NFP_NET_MIN_VNIC_IRQS * pf->num_vnics, in nfp_net_pf_alloc_irqs()
252 nfp_warn(pf->cpp, "Unable to allocate MSI-X vectors\n"); in nfp_net_pf_alloc_irqs()
253 kfree(pf->irq_entries); in nfp_net_pf_alloc_irqs()
259 vnics_left = pf->num_vnics; in nfp_net_pf_alloc_irqs()
260 list_for_each_entry(nn, &pf->vnics, vnic_list) { in nfp_net_pf_alloc_irqs()
265 nfp_net_irqs_assign(nn, &pf->irq_entries[num_irqs - irqs_left], in nfp_net_pf_alloc_irqs()
274 static void nfp_net_pf_free_irqs(struct nfp_pf *pf) in nfp_net_pf_free_irqs() argument
276 nfp_net_irqs_disable(pf->pdev); in nfp_net_pf_free_irqs()
277 kfree(pf->irq_entries); in nfp_net_pf_free_irqs()
280 static int nfp_net_pf_init_vnics(struct nfp_pf *pf) in nfp_net_pf_init_vnics() argument
288 list_for_each_entry(nn, &pf->vnics, vnic_list) { in nfp_net_pf_init_vnics()
291 err = nfp_net_pf_init_vnic(pf, nn, id); in nfp_net_pf_init_vnics()
301 list_for_each_entry_continue_reverse(nn, &pf->vnics, vnic_list) in nfp_net_pf_init_vnics()
303 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_pf_init_vnics()
308 nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) in nfp_net_pf_app_init() argument
313 pf->app = nfp_app_alloc(pf, nfp_net_pf_get_app_id(pf)); in nfp_net_pf_app_init()
314 if (IS_ERR(pf->app)) in nfp_net_pf_app_init()
315 return PTR_ERR(pf->app); in nfp_net_pf_app_init()
317 mutex_lock(&pf->lock); in nfp_net_pf_app_init()
318 err = nfp_app_init(pf->app); in nfp_net_pf_app_init()
319 mutex_unlock(&pf->lock); in nfp_net_pf_app_init()
323 if (!nfp_app_needs_ctrl_vnic(pf->app)) in nfp_net_pf_app_init()
326 ctrl_bar = nfp_pf_map_rtsym(pf, "net.ctrl", "_pf%u_net_ctrl_bar", in nfp_net_pf_app_init()
327 NFP_PF_CSR_SLICE_SIZE, &pf->ctrl_vnic_bar); in nfp_net_pf_app_init()
329 nfp_err(pf->cpp, "Failed to find ctrl vNIC memory symbol\n"); in nfp_net_pf_app_init()
334 pf->ctrl_vnic = nfp_net_pf_alloc_vnic(pf, false, ctrl_bar, qc_bar, in nfp_net_pf_app_init()
336 if (IS_ERR(pf->ctrl_vnic)) { in nfp_net_pf_app_init()
337 err = PTR_ERR(pf->ctrl_vnic); in nfp_net_pf_app_init()
344 nfp_cpp_area_release_free(pf->ctrl_vnic_bar); in nfp_net_pf_app_init()
346 mutex_lock(&pf->lock); in nfp_net_pf_app_init()
347 nfp_app_clean(pf->app); in nfp_net_pf_app_init()
348 mutex_unlock(&pf->lock); in nfp_net_pf_app_init()
350 nfp_app_free(pf->app); in nfp_net_pf_app_init()
351 pf->app = NULL; in nfp_net_pf_app_init()
355 static void nfp_net_pf_app_clean(struct nfp_pf *pf) in nfp_net_pf_app_clean() argument
357 if (pf->ctrl_vnic) { in nfp_net_pf_app_clean()
358 nfp_net_pf_free_vnic(pf, pf->ctrl_vnic); in nfp_net_pf_app_clean()
359 nfp_cpp_area_release_free(pf->ctrl_vnic_bar); in nfp_net_pf_app_clean()
362 mutex_lock(&pf->lock); in nfp_net_pf_app_clean()
363 nfp_app_clean(pf->app); in nfp_net_pf_app_clean()
364 mutex_unlock(&pf->lock); in nfp_net_pf_app_clean()
366 nfp_app_free(pf->app); in nfp_net_pf_app_clean()
367 pf->app = NULL; in nfp_net_pf_app_clean()
370 static int nfp_net_pf_app_start_ctrl(struct nfp_pf *pf) in nfp_net_pf_app_start_ctrl() argument
374 if (!pf->ctrl_vnic) in nfp_net_pf_app_start_ctrl()
376 err = nfp_net_pf_init_vnic(pf, pf->ctrl_vnic, 0); in nfp_net_pf_app_start_ctrl()
380 err = nfp_ctrl_open(pf->ctrl_vnic); in nfp_net_pf_app_start_ctrl()
387 nfp_net_pf_clean_vnic(pf, pf->ctrl_vnic); in nfp_net_pf_app_start_ctrl()
391 static void nfp_net_pf_app_stop_ctrl(struct nfp_pf *pf) in nfp_net_pf_app_stop_ctrl() argument
393 if (!pf->ctrl_vnic) in nfp_net_pf_app_stop_ctrl()
395 nfp_ctrl_close(pf->ctrl_vnic); in nfp_net_pf_app_stop_ctrl()
396 nfp_net_pf_clean_vnic(pf, pf->ctrl_vnic); in nfp_net_pf_app_stop_ctrl()
399 static int nfp_net_pf_app_start(struct nfp_pf *pf) in nfp_net_pf_app_start() argument
403 err = nfp_net_pf_app_start_ctrl(pf); in nfp_net_pf_app_start()
407 err = nfp_app_start(pf->app, pf->ctrl_vnic); in nfp_net_pf_app_start()
411 if (pf->num_vfs) { in nfp_net_pf_app_start()
412 err = nfp_app_sriov_enable(pf->app, pf->num_vfs); in nfp_net_pf_app_start()
420 nfp_app_stop(pf->app); in nfp_net_pf_app_start()
422 nfp_net_pf_app_stop_ctrl(pf); in nfp_net_pf_app_start()
426 static void nfp_net_pf_app_stop(struct nfp_pf *pf) in nfp_net_pf_app_stop() argument
428 if (pf->num_vfs) in nfp_net_pf_app_stop()
429 nfp_app_sriov_disable(pf->app); in nfp_net_pf_app_stop()
430 nfp_app_stop(pf->app); in nfp_net_pf_app_stop()
431 nfp_net_pf_app_stop_ctrl(pf); in nfp_net_pf_app_stop()
434 static void nfp_net_pci_unmap_mem(struct nfp_pf *pf) in nfp_net_pci_unmap_mem() argument
436 if (pf->vfcfg_tbl2_area) in nfp_net_pci_unmap_mem()
437 nfp_cpp_area_release_free(pf->vfcfg_tbl2_area); in nfp_net_pci_unmap_mem()
438 if (pf->vf_cfg_bar) in nfp_net_pci_unmap_mem()
439 nfp_cpp_area_release_free(pf->vf_cfg_bar); in nfp_net_pci_unmap_mem()
440 if (pf->mac_stats_bar) in nfp_net_pci_unmap_mem()
441 nfp_cpp_area_release_free(pf->mac_stats_bar); in nfp_net_pci_unmap_mem()
442 nfp_cpp_area_release_free(pf->qc_area); in nfp_net_pci_unmap_mem()
443 nfp_cpp_area_release_free(pf->data_vnic_bar); in nfp_net_pci_unmap_mem()
446 static int nfp_net_pci_map_mem(struct nfp_pf *pf) in nfp_net_pci_map_mem() argument
452 min_size = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE; in nfp_net_pci_map_mem()
453 mem = nfp_pf_map_rtsym(pf, "net.bar0", "_pf%d_net_bar0", in nfp_net_pci_map_mem()
454 min_size, &pf->data_vnic_bar); in nfp_net_pci_map_mem()
456 nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n"); in nfp_net_pci_map_mem()
460 if (pf->eth_tbl) { in nfp_net_pci_map_mem()
461 min_size = NFP_MAC_STATS_SIZE * (pf->eth_tbl->max_index + 1); in nfp_net_pci_map_mem()
462 pf->mac_stats_mem = nfp_rtsym_map(pf->rtbl, "_mac_stats", in nfp_net_pci_map_mem()
464 &pf->mac_stats_bar); in nfp_net_pci_map_mem()
465 if (IS_ERR(pf->mac_stats_mem)) { in nfp_net_pci_map_mem()
466 if (PTR_ERR(pf->mac_stats_mem) != -ENOENT) { in nfp_net_pci_map_mem()
467 err = PTR_ERR(pf->mac_stats_mem); in nfp_net_pci_map_mem()
470 pf->mac_stats_mem = NULL; in nfp_net_pci_map_mem()
474 pf->vf_cfg_mem = nfp_pf_map_rtsym(pf, "net.vfcfg", "_pf%d_net_vf_bar", in nfp_net_pci_map_mem()
475 NFP_NET_CFG_BAR_SZ * pf->limit_vfs, in nfp_net_pci_map_mem()
476 &pf->vf_cfg_bar); in nfp_net_pci_map_mem()
477 if (IS_ERR(pf->vf_cfg_mem)) { in nfp_net_pci_map_mem()
478 if (PTR_ERR(pf->vf_cfg_mem) != -ENOENT) { in nfp_net_pci_map_mem()
479 err = PTR_ERR(pf->vf_cfg_mem); in nfp_net_pci_map_mem()
482 pf->vf_cfg_mem = NULL; in nfp_net_pci_map_mem()
485 min_size = NFP_NET_VF_CFG_SZ * pf->limit_vfs + NFP_NET_VF_CFG_MB_SZ; in nfp_net_pci_map_mem()
486 pf->vfcfg_tbl2 = nfp_pf_map_rtsym(pf, "net.vfcfg_tbl2", in nfp_net_pci_map_mem()
488 min_size, &pf->vfcfg_tbl2_area); in nfp_net_pci_map_mem()
489 if (IS_ERR(pf->vfcfg_tbl2)) { in nfp_net_pci_map_mem()
490 if (PTR_ERR(pf->vfcfg_tbl2) != -ENOENT) { in nfp_net_pci_map_mem()
491 err = PTR_ERR(pf->vfcfg_tbl2); in nfp_net_pci_map_mem()
494 pf->vfcfg_tbl2 = NULL; in nfp_net_pci_map_mem()
498 mem = nfp_cpp_map_area(pf->cpp, "net.qc", cpp_id, NFP_PCIE_QUEUE(0), in nfp_net_pci_map_mem()
499 NFP_QCP_QUEUE_AREA_SZ, &pf->qc_area); in nfp_net_pci_map_mem()
501 nfp_err(pf->cpp, "Failed to map Queue Controller area.\n"); in nfp_net_pci_map_mem()
509 if (pf->vfcfg_tbl2_area) in nfp_net_pci_map_mem()
510 nfp_cpp_area_release_free(pf->vfcfg_tbl2_area); in nfp_net_pci_map_mem()
512 if (pf->vf_cfg_bar) in nfp_net_pci_map_mem()
513 nfp_cpp_area_release_free(pf->vf_cfg_bar); in nfp_net_pci_map_mem()
515 if (pf->mac_stats_bar) in nfp_net_pci_map_mem()
516 nfp_cpp_area_release_free(pf->mac_stats_bar); in nfp_net_pci_map_mem()
518 nfp_cpp_area_release_free(pf->data_vnic_bar); in nfp_net_pci_map_mem()
547 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf) in nfp_net_refresh_port_table_sync() argument
554 lockdep_assert_held(&pf->lock); in nfp_net_refresh_port_table_sync()
557 if (list_empty(&pf->vnics)) in nfp_net_refresh_port_table_sync()
562 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
565 eth_table = nfp_eth_read_ports(pf->cpp); in nfp_net_refresh_port_table_sync()
567 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
571 nfp_err(pf->cpp, "Error refreshing port config!\n"); in nfp_net_refresh_port_table_sync()
575 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
577 nfp_net_eth_port_update(pf->cpp, port, eth_table); in nfp_net_refresh_port_table_sync()
583 err = nfp_reprs_resync_phys_ports(pf->app); in nfp_net_refresh_port_table_sync()
588 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) { in nfp_net_refresh_port_table_sync()
592 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_refresh_port_table_sync()
593 nfp_net_pf_free_vnic(pf, nn); in nfp_net_refresh_port_table_sync()
601 struct nfp_pf *pf = container_of(work, struct nfp_pf, in nfp_net_refresh_vnics() local
604 mutex_lock(&pf->lock); in nfp_net_refresh_vnics()
605 nfp_net_refresh_port_table_sync(pf); in nfp_net_refresh_vnics()
606 mutex_unlock(&pf->lock); in nfp_net_refresh_vnics()
611 struct nfp_pf *pf = port->app->pf; in nfp_net_refresh_port_table() local
615 queue_work(pf->wq, &pf->port_refresh_work); in nfp_net_refresh_port_table()
643 int nfp_net_pci_probe(struct nfp_pf *pf) in nfp_net_pci_probe() argument
645 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pci_probe()
651 INIT_WORK(&pf->port_refresh_work, nfp_net_refresh_vnics); in nfp_net_pci_probe()
653 if (!pf->rtbl) { in nfp_net_pci_probe()
654 nfp_err(pf->cpp, "No %s, giving up.\n", in nfp_net_pci_probe()
655 pf->fw_loaded ? "symbol table" : "firmware found"); in nfp_net_pci_probe()
659 pf->max_data_vnics = nfp_net_pf_get_num_ports(pf); in nfp_net_pci_probe()
660 if ((int)pf->max_data_vnics < 0) in nfp_net_pci_probe()
661 return pf->max_data_vnics; in nfp_net_pci_probe()
663 err = nfp_net_pci_map_mem(pf); in nfp_net_pci_probe()
667 ctrl_bar = nfp_cpp_area_iomem(pf->data_vnic_bar); in nfp_net_pci_probe()
668 qc_bar = nfp_cpp_area_iomem(pf->qc_area); in nfp_net_pci_probe()
676 nfp_err(pf->cpp, "Unknown Firmware ABI %d.%d.%d.%d\n", in nfp_net_pci_probe()
685 nfp_warn(pf->cpp, "OBSOLETE Firmware detected - VF isolation not available\n"); in nfp_net_pci_probe()
692 nfp_err(pf->cpp, "Unsupported Firmware ABI %d.%d.%d.%d\n", in nfp_net_pci_probe()
700 err = nfp_net_pf_app_init(pf, qc_bar, stride); in nfp_net_pci_probe()
704 err = devlink_register(devlink, &pf->pdev->dev); in nfp_net_pci_probe()
708 err = nfp_shared_buf_register(pf); in nfp_net_pci_probe()
712 err = nfp_devlink_params_register(pf); in nfp_net_pci_probe()
716 mutex_lock(&pf->lock); in nfp_net_pci_probe()
717 pf->ddir = nfp_net_debugfs_device_add(pf->pdev); in nfp_net_pci_probe()
720 err = nfp_net_pf_alloc_vnics(pf, ctrl_bar, qc_bar, stride); in nfp_net_pci_probe()
724 err = nfp_net_pf_alloc_irqs(pf); in nfp_net_pci_probe()
728 err = nfp_net_pf_app_start(pf); in nfp_net_pci_probe()
732 err = nfp_net_pf_init_vnics(pf); in nfp_net_pci_probe()
736 mutex_unlock(&pf->lock); in nfp_net_pci_probe()
741 nfp_net_pf_app_stop(pf); in nfp_net_pci_probe()
743 nfp_net_pf_free_irqs(pf); in nfp_net_pci_probe()
745 nfp_net_pf_free_vnics(pf); in nfp_net_pci_probe()
747 nfp_net_debugfs_dir_clean(&pf->ddir); in nfp_net_pci_probe()
748 mutex_unlock(&pf->lock); in nfp_net_pci_probe()
749 nfp_devlink_params_unregister(pf); in nfp_net_pci_probe()
751 nfp_shared_buf_unregister(pf); in nfp_net_pci_probe()
753 cancel_work_sync(&pf->port_refresh_work); in nfp_net_pci_probe()
756 nfp_net_pf_app_clean(pf); in nfp_net_pci_probe()
758 nfp_net_pci_unmap_mem(pf); in nfp_net_pci_probe()
762 void nfp_net_pci_remove(struct nfp_pf *pf) in nfp_net_pci_remove() argument
766 mutex_lock(&pf->lock); in nfp_net_pci_remove()
767 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) { in nfp_net_pci_remove()
770 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_pci_remove()
771 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pci_remove()
774 nfp_net_pf_app_stop(pf); in nfp_net_pci_remove()
776 nfp_net_debugfs_dir_clean(&pf->ddir); in nfp_net_pci_remove()
778 mutex_unlock(&pf->lock); in nfp_net_pci_remove()
780 nfp_devlink_params_unregister(pf); in nfp_net_pci_remove()
781 nfp_shared_buf_unregister(pf); in nfp_net_pci_remove()
782 devlink_unregister(priv_to_devlink(pf)); in nfp_net_pci_remove()
784 nfp_net_pf_free_irqs(pf); in nfp_net_pci_remove()
785 nfp_net_pf_app_clean(pf); in nfp_net_pci_remove()
786 nfp_net_pci_unmap_mem(pf); in nfp_net_pci_remove()
788 cancel_work_sync(&pf->port_refresh_work); in nfp_net_pci_remove()