Lines Matching refs:pf
72 int nfp_pf_rtsym_read_optional(struct nfp_pf *pf, const char *format, in nfp_pf_rtsym_read_optional() argument
79 snprintf(name, sizeof(name), format, nfp_cppcore_pcie_unit(pf->cpp)); in nfp_pf_rtsym_read_optional()
81 val = nfp_rtsym_read_le(pf->rtbl, name, &err); in nfp_pf_rtsym_read_optional()
85 nfp_err(pf->cpp, "Unable to read symbol %s\n", name); in nfp_pf_rtsym_read_optional()
93 nfp_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt, in nfp_pf_map_rtsym() argument
99 nfp_cppcore_pcie_unit(pf->cpp)); in nfp_pf_map_rtsym()
101 return nfp_rtsym_map(pf->rtbl, pf_symbol, name, min_size, area); in nfp_pf_map_rtsym()
105 int nfp_mbox_cmd(struct nfp_pf *pf, u32 cmd, void *in_data, u64 in_length, in nfp_mbox_cmd() argument
113 if (!pf->mbox) in nfp_mbox_cmd()
116 max_data_sz = nfp_rtsym_size(pf->mbox) - NFP_MBOX_SYM_MIN_SIZE; in nfp_mbox_cmd()
119 err = nfp_rtsym_readl(pf->cpp, pf->mbox, NFP_MBOX_CMD, &val); in nfp_mbox_cmd()
121 nfp_warn(pf->cpp, "failed to issue command (%u): %u, err: %d\n", in nfp_mbox_cmd()
127 n = nfp_rtsym_write(pf->cpp, pf->mbox, NFP_MBOX_DATA, in_data, in nfp_mbox_cmd()
132 err = nfp_rtsym_writeq(pf->cpp, pf->mbox, NFP_MBOX_DATA_LEN, in_length); in nfp_mbox_cmd()
137 err = nfp_rtsym_readl(pf->cpp, pf->mbox, NFP_MBOX_DATA_LEN, &val); in nfp_mbox_cmd()
142 err = nfp_rtsym_writeq(pf->cpp, pf->mbox, NFP_MBOX_CMD, cmd); in nfp_mbox_cmd()
149 err = nfp_rtsym_readl(pf->cpp, pf->mbox, NFP_MBOX_CMD, &val); in nfp_mbox_cmd()
162 err = nfp_rtsym_readl(pf->cpp, pf->mbox, NFP_MBOX_DATA_LEN, &val); in nfp_mbox_cmd()
167 n = nfp_rtsym_read(pf->cpp, pf->mbox, NFP_MBOX_DATA, in nfp_mbox_cmd()
173 err = nfp_rtsym_readl(pf->cpp, pf->mbox, NFP_MBOX_RET, &val); in nfp_mbox_cmd()
182 static bool nfp_board_ready(struct nfp_pf *pf) in nfp_board_ready() argument
188 cp = nfp_hwinfo_lookup(pf->hwinfo, "board.state"); in nfp_board_ready()
199 static int nfp_pf_board_state_wait(struct nfp_pf *pf) in nfp_pf_board_state_wait() argument
203 while (!nfp_board_ready(pf)) { in nfp_pf_board_state_wait()
205 nfp_err(pf->cpp, "NFP board initialization timeout\n"); in nfp_pf_board_state_wait()
209 nfp_info(pf->cpp, "waiting for board initialization\n"); in nfp_pf_board_state_wait()
214 kfree(pf->hwinfo); in nfp_pf_board_state_wait()
215 pf->hwinfo = nfp_hwinfo_read(pf->cpp); in nfp_pf_board_state_wait()
221 static int nfp_pcie_sriov_read_nfd_limit(struct nfp_pf *pf) in nfp_pcie_sriov_read_nfd_limit() argument
225 pf->limit_vfs = nfp_rtsym_read_le(pf->rtbl, "nfd_vf_cfg_max_vfs", &err); in nfp_pcie_sriov_read_nfd_limit()
228 pf->limit_vfs = ~0; in nfp_pcie_sriov_read_nfd_limit()
232 nfp_warn(pf->cpp, "Warning: VF limit read failed: %d\n", err); in nfp_pcie_sriov_read_nfd_limit()
236 err = pci_sriov_set_totalvfs(pf->pdev, pf->limit_vfs); in nfp_pcie_sriov_read_nfd_limit()
238 nfp_warn(pf->cpp, "Failed to set VF count in sysfs: %d\n", err); in nfp_pcie_sriov_read_nfd_limit()
245 struct nfp_pf *pf = pci_get_drvdata(pdev); in nfp_pcie_sriov_enable() local
249 if (num_vfs > pf->limit_vfs) { in nfp_pcie_sriov_enable()
250 nfp_info(pf->cpp, "Firmware limits number of VFs to %u\n", in nfp_pcie_sriov_enable()
251 pf->limit_vfs); in nfp_pcie_sriov_enable()
261 devlink = priv_to_devlink(pf); in nfp_pcie_sriov_enable()
264 err = nfp_app_sriov_enable(pf->app, num_vfs); in nfp_pcie_sriov_enable()
272 pf->num_vfs = num_vfs; in nfp_pcie_sriov_enable()
274 dev_dbg(&pdev->dev, "Created %d VFs.\n", pf->num_vfs); in nfp_pcie_sriov_enable()
290 struct nfp_pf *pf = pci_get_drvdata(pdev); in nfp_pcie_sriov_disable() local
293 devlink = priv_to_devlink(pf); in nfp_pcie_sriov_disable()
306 nfp_app_sriov_disable(pf->app); in nfp_pcie_sriov_disable()
308 pf->num_vfs = 0; in nfp_pcie_sriov_disable()
329 int nfp_flash_update_common(struct nfp_pf *pf, const struct firmware *fw, in nfp_flash_update_common() argument
332 struct device *dev = &pf->pdev->dev; in nfp_flash_update_common()
336 nsp = nfp_nsp_open(pf->cpp); in nfp_flash_update_common()
358 nfp_net_fw_request(struct pci_dev *pdev, struct nfp_pf *pf, const char *name) in nfp_net_fw_request() argument
364 nfp_info(pf->cpp, " %s: %s\n", in nfp_net_fw_request()
380 nfp_net_fw_find(struct pci_dev *pdev, struct nfp_pf *pf) in nfp_net_fw_find() argument
390 nfp_info(pf->cpp, "Looking for firmware file in order of priority:\n"); in nfp_net_fw_find()
393 interface = nfp_cpp_interface(pf->cpp); in nfp_net_fw_find()
394 nfp_cpp_serial(pf->cpp, &serial); in nfp_net_fw_find()
397 fw = nfp_net_fw_request(pdev, pf, fw_name); in nfp_net_fw_find()
403 fw = nfp_net_fw_request(pdev, pf, fw_name); in nfp_net_fw_find()
408 if (!pf->eth_tbl) { in nfp_net_fw_find()
413 fw_model = nfp_hwinfo_lookup(pf->hwinfo, "nffw.partno"); in nfp_net_fw_find()
415 fw_model = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"); in nfp_net_fw_find()
424 for (i = 0; spc > 0 && i < pf->eth_tbl->count; i += j) { in nfp_net_fw_find()
425 port = &pf->eth_tbl->ports[i]; in nfp_net_fw_find()
427 while (i + j < pf->eth_tbl->count && in nfp_net_fw_find()
442 return nfp_net_fw_request(pdev, pf, fw_name); in nfp_net_fw_find()
481 nfp_fw_load(struct pci_dev *pdev, struct nfp_pf *pf, struct nfp_nsp *nsp) in nfp_fw_load() argument
496 interface = nfp_cpp_interface(pf->cpp); in nfp_fw_load()
531 fw = nfp_net_fw_find(pdev, pf); in nfp_fw_load()
581 pf->unload_fw_on_remove = true; in nfp_fw_load()
587 nfp_nsp_init_ports(struct pci_dev *pdev, struct nfp_pf *pf, in nfp_nsp_init_ports() argument
593 pf->eth_tbl = __nfp_eth_read_ports(pf->cpp, nsp); in nfp_nsp_init_ports()
594 if (!pf->eth_tbl) in nfp_nsp_init_ports()
600 for (i = 0; i < pf->eth_tbl->count; i++) in nfp_nsp_init_ports()
601 needs_reinit |= pf->eth_tbl->ports[i].override_changed; in nfp_nsp_init_ports()
605 kfree(pf->eth_tbl); in nfp_nsp_init_ports()
609 pf->eth_tbl = __nfp_eth_read_ports(pf->cpp, nsp); in nfp_nsp_init_ports()
612 static int nfp_nsp_init(struct pci_dev *pdev, struct nfp_pf *pf) in nfp_nsp_init() argument
617 err = nfp_resource_wait(pf->cpp, NFP_RESOURCE_NSP, 30); in nfp_nsp_init()
621 nsp = nfp_nsp_open(pf->cpp); in nfp_nsp_init()
632 nfp_nsp_init_ports(pdev, pf, nsp); in nfp_nsp_init()
634 pf->nspi = __nfp_nsp_identify(nsp); in nfp_nsp_init()
635 if (pf->nspi) in nfp_nsp_init()
636 dev_info(&pdev->dev, "BSP: %s\n", pf->nspi->version); in nfp_nsp_init()
638 err = nfp_fw_load(pdev, pf, nsp); in nfp_nsp_init()
640 kfree(pf->nspi); in nfp_nsp_init()
641 kfree(pf->eth_tbl); in nfp_nsp_init()
646 pf->fw_loaded = !!err; in nfp_nsp_init()
655 static void nfp_fw_unload(struct nfp_pf *pf) in nfp_fw_unload() argument
660 nsp = nfp_nsp_open(pf->cpp); in nfp_fw_unload()
662 nfp_err(pf->cpp, "Reset failed, can't open NSP\n"); in nfp_fw_unload()
668 dev_warn(&pf->pdev->dev, "Couldn't unload firmware: %d\n", err); in nfp_fw_unload()
670 dev_info(&pf->pdev->dev, "Firmware safely unloaded\n"); in nfp_fw_unload()
675 static int nfp_pf_find_rtsyms(struct nfp_pf *pf) in nfp_pf_find_rtsyms() argument
680 pf_id = nfp_cppcore_pcie_unit(pf->cpp); in nfp_pf_find_rtsyms()
684 pf->mbox = nfp_rtsym_lookup(pf->rtbl, pf_symbol); in nfp_pf_find_rtsyms()
685 if (pf->mbox && nfp_rtsym_size(pf->mbox) < NFP_MBOX_SYM_MIN_SIZE) { in nfp_pf_find_rtsyms()
686 nfp_err(pf->cpp, "PF mailbox symbol too small: %llu < %d\n", in nfp_pf_find_rtsyms()
687 nfp_rtsym_size(pf->mbox), NFP_MBOX_SYM_MIN_SIZE); in nfp_pf_find_rtsyms()
694 int nfp_net_pf_get_app_id(struct nfp_pf *pf) in nfp_net_pf_get_app_id() argument
696 return nfp_pf_rtsym_read_optional(pf, "_pf%u_net_app_id", in nfp_net_pf_get_app_id()
700 static u64 nfp_net_pf_get_app_cap(struct nfp_pf *pf) in nfp_net_pf_get_app_cap() argument
706 snprintf(name, sizeof(name), "_pf%u_net_app_cap", nfp_cppcore_pcie_unit(pf->cpp)); in nfp_net_pf_get_app_cap()
708 val = nfp_rtsym_read_le(pf->rtbl, name, &err); in nfp_net_pf_get_app_cap()
711 nfp_err(pf->cpp, "Unable to read symbol %s\n", name); in nfp_net_pf_get_app_cap()
719 static void nfp_pf_cfg_hwinfo(struct nfp_pf *pf) in nfp_pf_cfg_hwinfo() argument
726 nsp = nfp_nsp_open(pf->cpp); in nfp_pf_cfg_hwinfo()
733 sp_indiff = (nfp_net_pf_get_app_id(pf) == NFP_APP_FLOWER_NIC) || in nfp_pf_cfg_hwinfo()
734 (nfp_net_pf_get_app_cap(pf) & NFP_NET_APP_CAP_SP_INDIFF); in nfp_pf_cfg_hwinfo()
743 nfp_warn(pf->cpp, "HWinfo(sp_indiff=%d) set failed: %d\n", sp_indiff, err); in nfp_pf_cfg_hwinfo()
748 kfree(pf->eth_tbl); in nfp_pf_cfg_hwinfo()
749 pf->eth_tbl = __nfp_eth_read_ports(pf->cpp, nsp); in nfp_pf_cfg_hwinfo()
761 struct nfp_pf *pf; in nfp_pci_probe() local
788 devlink = devlink_alloc(&nfp_devlink_ops, sizeof(*pf), &pdev->dev); in nfp_pci_probe()
793 pf = devlink_priv(devlink); in nfp_pci_probe()
794 INIT_LIST_HEAD(&pf->vnics); in nfp_pci_probe()
795 INIT_LIST_HEAD(&pf->ports); in nfp_pci_probe()
796 pci_set_drvdata(pdev, pf); in nfp_pci_probe()
797 pf->pdev = pdev; in nfp_pci_probe()
798 pf->dev_info = dev_info; in nfp_pci_probe()
800 pf->wq = alloc_workqueue("nfp-%s", 0, 2, pci_name(pdev)); in nfp_pci_probe()
801 if (!pf->wq) { in nfp_pci_probe()
806 pf->cpp = nfp_cpp_from_nfp6000_pcie(pdev, dev_info); in nfp_pci_probe()
807 if (IS_ERR(pf->cpp)) { in nfp_pci_probe()
808 err = PTR_ERR(pf->cpp); in nfp_pci_probe()
812 err = nfp_resource_table_init(pf->cpp); in nfp_pci_probe()
816 pf->hwinfo = nfp_hwinfo_read(pf->cpp); in nfp_pci_probe()
819 nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"), in nfp_pci_probe()
820 nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"), in nfp_pci_probe()
821 nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"), in nfp_pci_probe()
822 nfp_hwinfo_lookup(pf->hwinfo, "assembly.revision"), in nfp_pci_probe()
823 nfp_hwinfo_lookup(pf->hwinfo, "cpld.version")); in nfp_pci_probe()
825 err = nfp_pf_board_state_wait(pf); in nfp_pci_probe()
829 err = nfp_nsp_init(pdev, pf); in nfp_pci_probe()
833 pf->mip = nfp_mip_open(pf->cpp); in nfp_pci_probe()
834 pf->rtbl = __nfp_rtsym_table_read(pf->cpp, pf->mip); in nfp_pci_probe()
836 err = nfp_pf_find_rtsyms(pf); in nfp_pci_probe()
840 pf->dump_flag = NFP_DUMP_NSP_DIAG; in nfp_pci_probe()
841 pf->dumpspec = nfp_net_dump_load_dumpspec(pf->cpp, pf->rtbl); in nfp_pci_probe()
843 err = nfp_pcie_sriov_read_nfd_limit(pf); in nfp_pci_probe()
847 pf->num_vfs = pci_num_vf(pdev); in nfp_pci_probe()
848 if (pf->num_vfs > pf->limit_vfs) { in nfp_pci_probe()
851 pf->num_vfs, pf->limit_vfs); in nfp_pci_probe()
856 nfp_pf_cfg_hwinfo(pf); in nfp_pci_probe()
858 err = nfp_net_pci_probe(pf); in nfp_pci_probe()
862 err = nfp_hwmon_register(pf); in nfp_pci_probe()
871 nfp_net_pci_remove(pf); in nfp_pci_probe()
873 kfree(pf->rtbl); in nfp_pci_probe()
874 nfp_mip_close(pf->mip); in nfp_pci_probe()
875 if (pf->unload_fw_on_remove) in nfp_pci_probe()
876 nfp_fw_unload(pf); in nfp_pci_probe()
877 kfree(pf->eth_tbl); in nfp_pci_probe()
878 kfree(pf->nspi); in nfp_pci_probe()
879 vfree(pf->dumpspec); in nfp_pci_probe()
881 kfree(pf->hwinfo); in nfp_pci_probe()
883 nfp_cpp_free(pf->cpp); in nfp_pci_probe()
885 destroy_workqueue(pf->wq); in nfp_pci_probe()
899 struct nfp_pf *pf; in __nfp_pci_shutdown() local
901 pf = pci_get_drvdata(pdev); in __nfp_pci_shutdown()
902 if (!pf) in __nfp_pci_shutdown()
905 nfp_hwmon_unregister(pf); in __nfp_pci_shutdown()
909 nfp_net_pci_remove(pf); in __nfp_pci_shutdown()
911 vfree(pf->dumpspec); in __nfp_pci_shutdown()
912 kfree(pf->rtbl); in __nfp_pci_shutdown()
913 nfp_mip_close(pf->mip); in __nfp_pci_shutdown()
914 if (unload_fw && pf->unload_fw_on_remove) in __nfp_pci_shutdown()
915 nfp_fw_unload(pf); in __nfp_pci_shutdown()
917 destroy_workqueue(pf->wq); in __nfp_pci_shutdown()
919 kfree(pf->hwinfo); in __nfp_pci_shutdown()
920 nfp_cpp_free(pf->cpp); in __nfp_pci_shutdown()
922 kfree(pf->eth_tbl); in __nfp_pci_shutdown()
923 kfree(pf->nspi); in __nfp_pci_shutdown()
924 devlink_free(priv_to_devlink(pf)); in __nfp_pci_shutdown()