Lines Matching refs:pf
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 void nfp_net_pf_free_vnic(struct nfp_pf *pf, struct nfp_net *nn) in nfp_net_pf_free_vnic() argument
82 nfp_app_vnic_free(pf->app, nn); in nfp_net_pf_free_vnic()
85 pf->num_vnics--; in nfp_net_pf_free_vnic()
89 static void nfp_net_pf_free_vnics(struct nfp_pf *pf) in nfp_net_pf_free_vnics() argument
93 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) in nfp_net_pf_free_vnics()
95 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pf_free_vnics()
99 nfp_net_pf_alloc_vnic(struct nfp_pf *pf, bool needs_netdev, in nfp_net_pf_alloc_vnic() argument
113 nn = nfp_net_alloc(pf->pdev, pf->dev_info, ctrl_bar, needs_netdev, in nfp_net_pf_alloc_vnic()
118 nn->app = pf->app; in nfp_net_pf_alloc_vnic()
126 err = nfp_app_vnic_alloc(pf->app, nn, id); in nfp_net_pf_alloc_vnic()
133 pf->num_vnics++; in nfp_net_pf_alloc_vnic()
134 list_add_tail(&nn->vnic_list, &pf->vnics); in nfp_net_pf_alloc_vnic()
140 nfp_net_pf_init_vnic(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id) in nfp_net_pf_init_vnic() argument
147 err = nfp_devlink_port_register(pf->app, nn->port); in nfp_net_pf_init_vnic()
156 nfp_net_debugfs_vnic_add(nn, pf->ddir); in nfp_net_pf_init_vnic()
161 err = nfp_app_vnic_init(pf->app, nn); in nfp_net_pf_init_vnic()
178 nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, in nfp_net_pf_alloc_vnics() argument
185 for (i = 0; i < pf->max_data_vnics; i++) { in nfp_net_pf_alloc_vnics()
186 nn = nfp_net_pf_alloc_vnic(pf, true, ctrl_bar, qc_bar, in nfp_net_pf_alloc_vnics()
200 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pf_alloc_vnics()
203 if (list_empty(&pf->vnics)) in nfp_net_pf_alloc_vnics()
209 nfp_net_pf_free_vnics(pf); in nfp_net_pf_alloc_vnics()
213 static void nfp_net_pf_clean_vnic(struct nfp_pf *pf, struct nfp_net *nn) in nfp_net_pf_clean_vnic() argument
216 nfp_app_vnic_clean(pf->app, nn); in nfp_net_pf_clean_vnic()
223 static int nfp_net_pf_alloc_irqs(struct nfp_pf *pf) in nfp_net_pf_alloc_irqs() argument
230 list_for_each_entry(nn, &pf->vnics, vnic_list) in nfp_net_pf_alloc_irqs()
232 pf->irq_entries = kcalloc(wanted_irqs, sizeof(*pf->irq_entries), in nfp_net_pf_alloc_irqs()
234 if (!pf->irq_entries) in nfp_net_pf_alloc_irqs()
237 num_irqs = nfp_net_irqs_alloc(pf->pdev, pf->irq_entries, in nfp_net_pf_alloc_irqs()
238 NFP_NET_MIN_VNIC_IRQS * pf->num_vnics, in nfp_net_pf_alloc_irqs()
241 nfp_warn(pf->cpp, "Unable to allocate MSI-X vectors\n"); in nfp_net_pf_alloc_irqs()
242 kfree(pf->irq_entries); in nfp_net_pf_alloc_irqs()
248 vnics_left = pf->num_vnics; in nfp_net_pf_alloc_irqs()
249 list_for_each_entry(nn, &pf->vnics, vnic_list) { in nfp_net_pf_alloc_irqs()
254 nfp_net_irqs_assign(nn, &pf->irq_entries[num_irqs - irqs_left], in nfp_net_pf_alloc_irqs()
263 static void nfp_net_pf_free_irqs(struct nfp_pf *pf) in nfp_net_pf_free_irqs() argument
265 nfp_net_irqs_disable(pf->pdev); in nfp_net_pf_free_irqs()
266 kfree(pf->irq_entries); in nfp_net_pf_free_irqs()
269 static int nfp_net_pf_init_vnics(struct nfp_pf *pf) in nfp_net_pf_init_vnics() argument
277 list_for_each_entry(nn, &pf->vnics, vnic_list) { in nfp_net_pf_init_vnics()
280 err = nfp_net_pf_init_vnic(pf, nn, id); in nfp_net_pf_init_vnics()
290 list_for_each_entry_continue_reverse(nn, &pf->vnics, vnic_list) in nfp_net_pf_init_vnics()
292 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_pf_init_vnics()
297 nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) in nfp_net_pf_app_init() argument
299 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pf_app_init()
303 pf->app = nfp_app_alloc(pf, nfp_net_pf_get_app_id(pf)); in nfp_net_pf_app_init()
304 if (IS_ERR(pf->app)) in nfp_net_pf_app_init()
305 return PTR_ERR(pf->app); in nfp_net_pf_app_init()
308 err = nfp_app_init(pf->app); in nfp_net_pf_app_init()
313 if (!nfp_app_needs_ctrl_vnic(pf->app)) in nfp_net_pf_app_init()
316 ctrl_bar = nfp_pf_map_rtsym(pf, "net.ctrl", "_pf%u_net_ctrl_bar", in nfp_net_pf_app_init()
317 NFP_PF_CSR_SLICE_SIZE, &pf->ctrl_vnic_bar); in nfp_net_pf_app_init()
319 nfp_err(pf->cpp, "Failed to find ctrl vNIC memory symbol\n"); in nfp_net_pf_app_init()
324 pf->ctrl_vnic = nfp_net_pf_alloc_vnic(pf, false, ctrl_bar, qc_bar, in nfp_net_pf_app_init()
326 if (IS_ERR(pf->ctrl_vnic)) { in nfp_net_pf_app_init()
327 err = PTR_ERR(pf->ctrl_vnic); in nfp_net_pf_app_init()
334 nfp_cpp_area_release_free(pf->ctrl_vnic_bar); in nfp_net_pf_app_init()
337 nfp_app_clean(pf->app); in nfp_net_pf_app_init()
340 nfp_app_free(pf->app); in nfp_net_pf_app_init()
341 pf->app = NULL; in nfp_net_pf_app_init()
345 static void nfp_net_pf_app_clean(struct nfp_pf *pf) in nfp_net_pf_app_clean() argument
347 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pf_app_clean()
349 if (pf->ctrl_vnic) { in nfp_net_pf_app_clean()
350 nfp_net_pf_free_vnic(pf, pf->ctrl_vnic); in nfp_net_pf_app_clean()
351 nfp_cpp_area_release_free(pf->ctrl_vnic_bar); in nfp_net_pf_app_clean()
355 nfp_app_clean(pf->app); in nfp_net_pf_app_clean()
358 nfp_app_free(pf->app); in nfp_net_pf_app_clean()
359 pf->app = NULL; in nfp_net_pf_app_clean()
362 static int nfp_net_pf_app_start_ctrl(struct nfp_pf *pf) in nfp_net_pf_app_start_ctrl() argument
366 if (!pf->ctrl_vnic) in nfp_net_pf_app_start_ctrl()
368 err = nfp_net_pf_init_vnic(pf, pf->ctrl_vnic, 0); in nfp_net_pf_app_start_ctrl()
372 err = nfp_ctrl_open(pf->ctrl_vnic); in nfp_net_pf_app_start_ctrl()
379 nfp_net_pf_clean_vnic(pf, pf->ctrl_vnic); in nfp_net_pf_app_start_ctrl()
383 static void nfp_net_pf_app_stop_ctrl(struct nfp_pf *pf) in nfp_net_pf_app_stop_ctrl() argument
385 if (!pf->ctrl_vnic) in nfp_net_pf_app_stop_ctrl()
387 nfp_ctrl_close(pf->ctrl_vnic); in nfp_net_pf_app_stop_ctrl()
388 nfp_net_pf_clean_vnic(pf, pf->ctrl_vnic); in nfp_net_pf_app_stop_ctrl()
391 static int nfp_net_pf_app_start(struct nfp_pf *pf) in nfp_net_pf_app_start() argument
395 err = nfp_net_pf_app_start_ctrl(pf); in nfp_net_pf_app_start()
399 err = nfp_app_start(pf->app, pf->ctrl_vnic); in nfp_net_pf_app_start()
403 if (pf->num_vfs) { in nfp_net_pf_app_start()
404 err = nfp_app_sriov_enable(pf->app, pf->num_vfs); in nfp_net_pf_app_start()
412 nfp_app_stop(pf->app); in nfp_net_pf_app_start()
414 nfp_net_pf_app_stop_ctrl(pf); in nfp_net_pf_app_start()
418 static void nfp_net_pf_app_stop(struct nfp_pf *pf) in nfp_net_pf_app_stop() argument
420 if (pf->num_vfs) in nfp_net_pf_app_stop()
421 nfp_app_sriov_disable(pf->app); in nfp_net_pf_app_stop()
422 nfp_app_stop(pf->app); in nfp_net_pf_app_stop()
423 nfp_net_pf_app_stop_ctrl(pf); in nfp_net_pf_app_stop()
426 static void nfp_net_pci_unmap_mem(struct nfp_pf *pf) in nfp_net_pci_unmap_mem() argument
428 if (pf->vfcfg_tbl2_area) in nfp_net_pci_unmap_mem()
429 nfp_cpp_area_release_free(pf->vfcfg_tbl2_area); in nfp_net_pci_unmap_mem()
430 if (pf->vf_cfg_bar) in nfp_net_pci_unmap_mem()
431 nfp_cpp_area_release_free(pf->vf_cfg_bar); in nfp_net_pci_unmap_mem()
432 if (pf->mac_stats_bar) in nfp_net_pci_unmap_mem()
433 nfp_cpp_area_release_free(pf->mac_stats_bar); in nfp_net_pci_unmap_mem()
434 nfp_cpp_area_release_free(pf->qc_area); in nfp_net_pci_unmap_mem()
435 nfp_cpp_area_release_free(pf->data_vnic_bar); in nfp_net_pci_unmap_mem()
438 static int nfp_net_pci_map_mem(struct nfp_pf *pf) in nfp_net_pci_map_mem() argument
444 min_size = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE; in nfp_net_pci_map_mem()
445 mem = nfp_pf_map_rtsym(pf, "net.bar0", "_pf%d_net_bar0", in nfp_net_pci_map_mem()
446 min_size, &pf->data_vnic_bar); in nfp_net_pci_map_mem()
448 nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n"); in nfp_net_pci_map_mem()
452 if (pf->eth_tbl) { in nfp_net_pci_map_mem()
453 min_size = NFP_MAC_STATS_SIZE * (pf->eth_tbl->max_index + 1); in nfp_net_pci_map_mem()
454 pf->mac_stats_mem = nfp_rtsym_map(pf->rtbl, "_mac_stats", in nfp_net_pci_map_mem()
456 &pf->mac_stats_bar); in nfp_net_pci_map_mem()
457 if (IS_ERR(pf->mac_stats_mem)) { in nfp_net_pci_map_mem()
458 if (PTR_ERR(pf->mac_stats_mem) != -ENOENT) { in nfp_net_pci_map_mem()
459 err = PTR_ERR(pf->mac_stats_mem); in nfp_net_pci_map_mem()
462 pf->mac_stats_mem = NULL; in nfp_net_pci_map_mem()
466 pf->vf_cfg_mem = nfp_pf_map_rtsym(pf, "net.vfcfg", "_pf%d_net_vf_bar", in nfp_net_pci_map_mem()
467 NFP_NET_CFG_BAR_SZ * pf->limit_vfs, in nfp_net_pci_map_mem()
468 &pf->vf_cfg_bar); in nfp_net_pci_map_mem()
469 if (IS_ERR(pf->vf_cfg_mem)) { in nfp_net_pci_map_mem()
470 if (PTR_ERR(pf->vf_cfg_mem) != -ENOENT) { in nfp_net_pci_map_mem()
471 err = PTR_ERR(pf->vf_cfg_mem); in nfp_net_pci_map_mem()
474 pf->vf_cfg_mem = NULL; in nfp_net_pci_map_mem()
477 min_size = NFP_NET_VF_CFG_SZ * pf->limit_vfs + NFP_NET_VF_CFG_MB_SZ; in nfp_net_pci_map_mem()
478 pf->vfcfg_tbl2 = nfp_pf_map_rtsym(pf, "net.vfcfg_tbl2", in nfp_net_pci_map_mem()
480 min_size, &pf->vfcfg_tbl2_area); in nfp_net_pci_map_mem()
481 if (IS_ERR(pf->vfcfg_tbl2)) { in nfp_net_pci_map_mem()
482 if (PTR_ERR(pf->vfcfg_tbl2) != -ENOENT) { in nfp_net_pci_map_mem()
483 err = PTR_ERR(pf->vfcfg_tbl2); in nfp_net_pci_map_mem()
486 pf->vfcfg_tbl2 = NULL; in nfp_net_pci_map_mem()
490 mem = nfp_cpp_map_area(pf->cpp, "net.qc", cpp_id, in nfp_net_pci_map_mem()
491 nfp_qcp_queue_offset(pf->dev_info, 0), in nfp_net_pci_map_mem()
492 pf->dev_info->qc_area_sz, &pf->qc_area); in nfp_net_pci_map_mem()
494 nfp_err(pf->cpp, "Failed to map Queue Controller area.\n"); in nfp_net_pci_map_mem()
502 if (pf->vfcfg_tbl2_area) in nfp_net_pci_map_mem()
503 nfp_cpp_area_release_free(pf->vfcfg_tbl2_area); in nfp_net_pci_map_mem()
505 if (pf->vf_cfg_bar) in nfp_net_pci_map_mem()
506 nfp_cpp_area_release_free(pf->vf_cfg_bar); in nfp_net_pci_map_mem()
508 if (pf->mac_stats_bar) in nfp_net_pci_map_mem()
509 nfp_cpp_area_release_free(pf->mac_stats_bar); in nfp_net_pci_map_mem()
511 nfp_cpp_area_release_free(pf->data_vnic_bar); in nfp_net_pci_map_mem()
592 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf) in nfp_net_refresh_port_table_sync() argument
594 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_refresh_port_table_sync()
603 if (list_empty(&pf->vnics)) in nfp_net_refresh_port_table_sync()
608 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
611 eth_table = nfp_eth_read_ports(pf->cpp); in nfp_net_refresh_port_table_sync()
613 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
617 nfp_err(pf->cpp, "Error refreshing port config!\n"); in nfp_net_refresh_port_table_sync()
621 list_for_each_entry(port, &pf->ports, port_list) in nfp_net_refresh_port_table_sync()
623 nfp_net_eth_port_update(pf->cpp, port, eth_table); in nfp_net_refresh_port_table_sync()
629 err = nfp_reprs_resync_phys_ports(pf->app); in nfp_net_refresh_port_table_sync()
634 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) { in nfp_net_refresh_port_table_sync()
638 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_refresh_port_table_sync()
639 nfp_net_pf_free_vnic(pf, nn); in nfp_net_refresh_port_table_sync()
647 struct nfp_pf *pf = container_of(work, struct nfp_pf, in nfp_net_refresh_vnics() local
649 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_refresh_vnics()
652 nfp_net_refresh_port_table_sync(pf); in nfp_net_refresh_vnics()
658 struct nfp_pf *pf = port->app->pf; in nfp_net_refresh_port_table() local
662 queue_work(pf->wq, &pf->port_refresh_work); in nfp_net_refresh_port_table()
690 int nfp_net_pci_probe(struct nfp_pf *pf) in nfp_net_pci_probe() argument
692 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pci_probe()
698 INIT_WORK(&pf->port_refresh_work, nfp_net_refresh_vnics); in nfp_net_pci_probe()
700 if (!pf->rtbl) { in nfp_net_pci_probe()
701 nfp_err(pf->cpp, "No %s, giving up.\n", in nfp_net_pci_probe()
702 pf->fw_loaded ? "symbol table" : "firmware found"); in nfp_net_pci_probe()
706 pf->max_data_vnics = nfp_net_pf_get_num_ports(pf); in nfp_net_pci_probe()
707 if ((int)pf->max_data_vnics < 0) in nfp_net_pci_probe()
708 return pf->max_data_vnics; in nfp_net_pci_probe()
710 err = nfp_net_pci_map_mem(pf); in nfp_net_pci_probe()
714 ctrl_bar = nfp_cpp_area_iomem(pf->data_vnic_bar); in nfp_net_pci_probe()
715 qc_bar = nfp_cpp_area_iomem(pf->qc_area); in nfp_net_pci_probe()
724 nfp_err(pf->cpp, "Unknown Firmware ABI %d.%d.%d.%d\n", in nfp_net_pci_probe()
734 nfp_warn(pf->cpp, "OBSOLETE Firmware detected - VF isolation not available\n"); in nfp_net_pci_probe()
741 nfp_err(pf->cpp, "Unsupported Firmware ABI %d.%d.%d.%d\n", in nfp_net_pci_probe()
749 err = nfp_net_pf_app_init(pf, qc_bar, stride); in nfp_net_pci_probe()
753 err = nfp_shared_buf_register(pf); in nfp_net_pci_probe()
758 err = nfp_devlink_params_register(pf); in nfp_net_pci_probe()
762 pf->ddir = nfp_net_debugfs_device_add(pf->pdev); in nfp_net_pci_probe()
765 err = nfp_net_pf_alloc_vnics(pf, ctrl_bar, qc_bar, stride); in nfp_net_pci_probe()
769 err = nfp_net_pf_alloc_irqs(pf); in nfp_net_pci_probe()
773 err = nfp_net_pf_app_start(pf); in nfp_net_pci_probe()
777 err = nfp_net_pf_init_vnics(pf); in nfp_net_pci_probe()
787 nfp_net_pf_app_stop(pf); in nfp_net_pci_probe()
789 nfp_net_pf_free_irqs(pf); in nfp_net_pci_probe()
791 nfp_net_pf_free_vnics(pf); in nfp_net_pci_probe()
793 nfp_net_debugfs_dir_clean(&pf->ddir); in nfp_net_pci_probe()
794 nfp_devlink_params_unregister(pf); in nfp_net_pci_probe()
797 nfp_shared_buf_unregister(pf); in nfp_net_pci_probe()
799 cancel_work_sync(&pf->port_refresh_work); in nfp_net_pci_probe()
800 nfp_net_pf_app_clean(pf); in nfp_net_pci_probe()
802 nfp_net_pci_unmap_mem(pf); in nfp_net_pci_probe()
806 void nfp_net_pci_remove(struct nfp_pf *pf) in nfp_net_pci_remove() argument
808 struct devlink *devlink = priv_to_devlink(pf); in nfp_net_pci_remove()
811 devlink_unregister(priv_to_devlink(pf)); in nfp_net_pci_remove()
813 list_for_each_entry_safe(nn, next, &pf->vnics, vnic_list) { in nfp_net_pci_remove()
816 nfp_net_pf_clean_vnic(pf, nn); in nfp_net_pci_remove()
817 nfp_net_pf_free_vnic(pf, nn); in nfp_net_pci_remove()
820 nfp_net_pf_app_stop(pf); in nfp_net_pci_remove()
822 nfp_net_debugfs_dir_clean(&pf->ddir); in nfp_net_pci_remove()
824 nfp_devlink_params_unregister(pf); in nfp_net_pci_remove()
828 nfp_shared_buf_unregister(pf); in nfp_net_pci_remove()
830 nfp_net_pf_free_irqs(pf); in nfp_net_pci_remove()
831 nfp_net_pf_app_clean(pf); in nfp_net_pci_remove()
832 nfp_net_pci_unmap_mem(pf); in nfp_net_pci_remove()
834 cancel_work_sync(&pf->port_refresh_work); in nfp_net_pci_remove()