Lines Matching full:pf

40  * @pf:       NFP PF handle
48 nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev, in nfp_net_get_mac_addr() argument
75 static int nfp_net_pf_get_num_ports(struct nfp_pf *pf) in nfp_net_pf_get_num_ports() argument
77 return nfp_pf_rtsym_read_optional(pf, "nfd_cfg_pf%u_num_ports", 1); in nfp_net_pf_get_num_ports()
80 static void nfp_net_pf_free_vnic(struct nfp_pf *pf, struct nfp_net *nn) in nfp_net_pf_free_vnic() argument
83 nfp_app_vnic_free(pf->app, nn); in nfp_net_pf_free_vnic()
86 pf->num_vnics--; in nfp_net_pf_free_vnic()
90 static void nfp_net_pf_free_vnics(struct nfp_pf *pf) in nfp_net_pf_free_vnics() argument
94 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) in nfp_net_pf_free_vnics()
96 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pf_free_vnics()
100 nfp_net_pf_alloc_vnic(struct nfp_pf *pf, bool needs_netdev, in nfp_net_pf_alloc_vnic() argument
114 nn = nfp_net_alloc(pf->pdev, pf->dev_info, ctrl_bar, needs_netdev, in nfp_net_pf_alloc_vnic()
119 nn->app = pf->app; in nfp_net_pf_alloc_vnic()
127 err = nfp_app_vnic_alloc(pf->app, nn, id); in nfp_net_pf_alloc_vnic()
134 pf->num_vnics++; in nfp_net_pf_alloc_vnic()
135 list_add_tail(&nn->vnic_list, &pf->vnics); in nfp_net_pf_alloc_vnic()
141 nfp_net_pf_init_vnic(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id) in nfp_net_pf_init_vnic() argument
148 err = nfp_devlink_port_register(pf->app, nn->port); in nfp_net_pf_init_vnic()
157 nfp_net_debugfs_vnic_add(nn, pf->ddir); in nfp_net_pf_init_vnic()
165 err = nfp_app_vnic_init(pf->app, nn); in nfp_net_pf_init_vnic()
184 nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, in nfp_net_pf_alloc_vnics() argument
191 for (i = 0; i < pf->max_data_vnics; i++) { in nfp_net_pf_alloc_vnics()
192 nn = nfp_net_pf_alloc_vnic(pf, true, ctrl_bar, qc_bar, in nfp_net_pf_alloc_vnics()
206 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pf_alloc_vnics()
209 if (list_empty(&pf->vnics)) in nfp_net_pf_alloc_vnics()
215 nfp_net_pf_free_vnics(pf); in nfp_net_pf_alloc_vnics()
219 static void nfp_net_pf_clean_vnic(struct nfp_pf *pf, struct nfp_net *nn) in nfp_net_pf_clean_vnic() argument
222 nfp_app_vnic_clean(pf->app, nn); in nfp_net_pf_clean_vnic()
231 static int nfp_net_pf_alloc_irqs(struct nfp_pf *pf) in nfp_net_pf_alloc_irqs() argument
238 list_for_each_entry(nn, &pf->vnics, vnic_list) in nfp_net_pf_alloc_irqs()
240 pf->irq_entries = kcalloc(wanted_irqs, sizeof(*pf->irq_entries), in nfp_net_pf_alloc_irqs()
242 if (!pf->irq_entries) in nfp_net_pf_alloc_irqs()
245 num_irqs = nfp_net_irqs_alloc(pf->pdev, pf->irq_entries, in nfp_net_pf_alloc_irqs()
246 NFP_NET_MIN_VNIC_IRQS * pf->num_vnics, in nfp_net_pf_alloc_irqs()
249 nfp_warn(pf->cpp, "Unable to allocate MSI-X vectors\n"); in nfp_net_pf_alloc_irqs()
250 kfree(pf->irq_entries); in nfp_net_pf_alloc_irqs()
256 vnics_left = pf->num_vnics; in nfp_net_pf_alloc_irqs()
257 list_for_each_entry(nn, &pf->vnics, vnic_list) { in nfp_net_pf_alloc_irqs()
262 nfp_net_irqs_assign(nn, &pf->irq_entries[num_irqs - irqs_left], in nfp_net_pf_alloc_irqs()
271 static void nfp_net_pf_free_irqs(struct nfp_pf *pf) in nfp_net_pf_free_irqs() argument
273 nfp_net_irqs_disable(pf->pdev); in nfp_net_pf_free_irqs()
274 kfree(pf->irq_entries); in nfp_net_pf_free_irqs()
277 static int nfp_net_pf_init_vnics(struct nfp_pf *pf) in nfp_net_pf_init_vnics() argument
285 list_for_each_entry(nn, &pf->vnics, vnic_list) { in nfp_net_pf_init_vnics()
288 err = nfp_net_pf_init_vnic(pf, nn, id); in nfp_net_pf_init_vnics()
298 list_for_each_entry_continue_reverse(nn, &pf->vnics, vnic_list) in nfp_net_pf_init_vnics()
300 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_pf_init_vnics()
305 nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) in nfp_net_pf_app_init() argument
307 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pf_app_init()
311 pf->app = nfp_app_alloc(pf, nfp_net_pf_get_app_id(pf)); in nfp_net_pf_app_init()
312 if (IS_ERR(pf->app)) in nfp_net_pf_app_init()
313 return PTR_ERR(pf->app); in nfp_net_pf_app_init()
316 err = nfp_app_init(pf->app); in nfp_net_pf_app_init()
321 if (!nfp_app_needs_ctrl_vnic(pf->app)) in nfp_net_pf_app_init()
324 ctrl_bar = nfp_pf_map_rtsym(pf, "net.ctrl", "_pf%u_net_ctrl_bar", in nfp_net_pf_app_init()
325 NFP_PF_CSR_SLICE_SIZE, &pf->ctrl_vnic_bar); in nfp_net_pf_app_init()
327 nfp_err(pf->cpp, "Failed to find ctrl vNIC memory symbol\n"); in nfp_net_pf_app_init()
332 pf->ctrl_vnic = nfp_net_pf_alloc_vnic(pf, false, ctrl_bar, qc_bar, in nfp_net_pf_app_init()
334 if (IS_ERR(pf->ctrl_vnic)) { in nfp_net_pf_app_init()
335 err = PTR_ERR(pf->ctrl_vnic); in nfp_net_pf_app_init()
342 nfp_cpp_area_release_free(pf->ctrl_vnic_bar); in nfp_net_pf_app_init()
345 nfp_app_clean(pf->app); in nfp_net_pf_app_init()
348 nfp_app_free(pf->app); in nfp_net_pf_app_init()
349 pf->app = NULL; in nfp_net_pf_app_init()
353 static void nfp_net_pf_app_clean(struct nfp_pf *pf) in nfp_net_pf_app_clean() argument
355 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pf_app_clean()
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()
363 nfp_app_clean(pf->app); 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, in nfp_net_pci_map_mem()
499 nfp_qcp_queue_offset(pf->dev_info, 0), in nfp_net_pci_map_mem()
500 pf->dev_info->qc_area_sz, &pf->qc_area); in nfp_net_pci_map_mem()
502 nfp_err(pf->cpp, "Failed to map Queue Controller area.\n"); in nfp_net_pci_map_mem()
510 if (pf->vfcfg_tbl2_area) in nfp_net_pci_map_mem()
511 nfp_cpp_area_release_free(pf->vfcfg_tbl2_area); in nfp_net_pci_map_mem()
513 if (pf->vf_cfg_bar) in nfp_net_pci_map_mem()
514 nfp_cpp_area_release_free(pf->vf_cfg_bar); in nfp_net_pci_map_mem()
516 if (pf->mac_stats_bar) in nfp_net_pci_map_mem()
517 nfp_cpp_area_release_free(pf->mac_stats_bar); in nfp_net_pci_map_mem()
519 nfp_cpp_area_release_free(pf->data_vnic_bar); in nfp_net_pci_map_mem()
600 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf) in nfp_net_refresh_port_table_sync() argument
602 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_refresh_port_table_sync()
611 if (list_empty(&pf->vnics)) in nfp_net_refresh_port_table_sync()
616 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
619 eth_table = nfp_eth_read_ports(pf->cpp); in nfp_net_refresh_port_table_sync()
621 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
625 nfp_err(pf->cpp, "Error refreshing port config!\n"); in nfp_net_refresh_port_table_sync()
629 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
631 nfp_net_eth_port_update(pf->cpp, port, eth_table); in nfp_net_refresh_port_table_sync()
637 err = nfp_reprs_resync_phys_ports(pf->app); in nfp_net_refresh_port_table_sync()
642 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) { in nfp_net_refresh_port_table_sync()
646 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_refresh_port_table_sync()
647 nfp_net_pf_free_vnic(pf, nn); in nfp_net_refresh_port_table_sync()
655 struct nfp_pf *pf = container_of(work, struct nfp_pf, in nfp_net_refresh_vnics() local
657 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_refresh_vnics()
660 nfp_net_refresh_port_table_sync(pf); in nfp_net_refresh_vnics()
666 struct nfp_pf *pf = port->app->pf; in nfp_net_refresh_port_table() local
670 queue_work(pf->wq, &pf->port_refresh_work); in nfp_net_refresh_port_table()
698 int nfp_net_pci_probe(struct nfp_pf *pf) in nfp_net_pci_probe() argument
700 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pci_probe()
706 INIT_WORK(&pf->port_refresh_work, nfp_net_refresh_vnics); in nfp_net_pci_probe()
708 if (!pf->rtbl) { in nfp_net_pci_probe()
709 nfp_err(pf->cpp, "No %s, giving up.\n", in nfp_net_pci_probe()
710 pf->fw_loaded ? "symbol table" : "firmware found"); in nfp_net_pci_probe()
714 pf->max_data_vnics = nfp_net_pf_get_num_ports(pf); in nfp_net_pci_probe()
715 if ((int)pf->max_data_vnics < 0) in nfp_net_pci_probe()
716 return pf->max_data_vnics; in nfp_net_pci_probe()
718 err = nfp_net_pci_map_mem(pf); in nfp_net_pci_probe()
722 ctrl_bar = nfp_cpp_area_iomem(pf->data_vnic_bar); in nfp_net_pci_probe()
723 qc_bar = nfp_cpp_area_iomem(pf->qc_area); in nfp_net_pci_probe()
732 nfp_err(pf->cpp, "Unknown Firmware ABI %d.%d.%d.%d\n", in nfp_net_pci_probe()
742 nfp_warn(pf->cpp, "OBSOLETE Firmware detected - VF isolation not available\n"); in nfp_net_pci_probe()
749 nfp_err(pf->cpp, "Unsupported Firmware ABI %d.%d.%d.%d\n", in nfp_net_pci_probe()
757 err = nfp_net_pf_app_init(pf, qc_bar, stride); in nfp_net_pci_probe()
761 err = nfp_shared_buf_register(pf); in nfp_net_pci_probe()
765 err = nfp_devlink_params_register(pf); in nfp_net_pci_probe()
770 pf->ddir = nfp_net_debugfs_device_add(pf->pdev); in nfp_net_pci_probe()
773 err = nfp_net_pf_alloc_vnics(pf, ctrl_bar, qc_bar, stride); in nfp_net_pci_probe()
777 err = nfp_net_pf_alloc_irqs(pf); in nfp_net_pci_probe()
781 err = nfp_net_pf_app_start(pf); in nfp_net_pci_probe()
785 err = nfp_net_pf_init_vnics(pf); in nfp_net_pci_probe()
795 nfp_net_pf_app_stop(pf); in nfp_net_pci_probe()
797 nfp_net_pf_free_irqs(pf); in nfp_net_pci_probe()
799 nfp_net_pf_free_vnics(pf); in nfp_net_pci_probe()
801 nfp_net_debugfs_dir_clean(&pf->ddir); in nfp_net_pci_probe()
803 nfp_devlink_params_unregister(pf); in nfp_net_pci_probe()
805 nfp_shared_buf_unregister(pf); in nfp_net_pci_probe()
807 cancel_work_sync(&pf->port_refresh_work); in nfp_net_pci_probe()
808 nfp_net_pf_app_clean(pf); in nfp_net_pci_probe()
810 nfp_net_pci_unmap_mem(pf); in nfp_net_pci_probe()
814 void nfp_net_pci_remove(struct nfp_pf *pf) in nfp_net_pci_remove() argument
816 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pci_remove()
819 devlink_unregister(priv_to_devlink(pf)); in nfp_net_pci_remove()
821 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) { in nfp_net_pci_remove()
824 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_pci_remove()
825 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pci_remove()
828 nfp_net_pf_app_stop(pf); in nfp_net_pci_remove()
830 nfp_net_debugfs_dir_clean(&pf->ddir); in nfp_net_pci_remove()
834 nfp_devlink_params_unregister(pf); in nfp_net_pci_remove()
835 nfp_shared_buf_unregister(pf); in nfp_net_pci_remove()
837 nfp_net_pf_free_irqs(pf); in nfp_net_pci_remove()
838 nfp_net_pf_app_clean(pf); in nfp_net_pci_remove()
839 nfp_net_pci_unmap_mem(pf); in nfp_net_pci_remove()
841 cancel_work_sync(&pf->port_refresh_work); in nfp_net_pci_remove()