1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */
6 * Authors: Jakub Kicinski <jakub.kicinski@netronome.com>
7 * Alejandro Lucero <alejandro.lucero@netronome.com>
8 * Jason McMullan <jason.mcmullan@netronome.com>
9 * Rolf Neugebauer <rolf.neugebauer@netronome.com>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/mutex.h>
15 #include <linux/pci.h>
16 #include <linux/firmware.h>
17 #include <linux/vmalloc.h>
18 #include <net/devlink.h>
20 #include "nfpcore/nfp.h"
21 #include "nfpcore/nfp_cpp.h"
22 #include "nfpcore/nfp_dev.h"
23 #include "nfpcore/nfp_nffw.h"
24 #include "nfpcore/nfp_nsp.h"
26 #include "nfpcore/nfp6000_pcie.h"
33 static const char nfp_driver_name
[] = "nfp";
35 static const struct pci_device_id nfp_pci_device_ids
[] = {
36 { PCI_VENDOR_ID_NETRONOME
, PCI_DEVICE_ID_NFP3800
,
37 PCI_VENDOR_ID_NETRONOME
, PCI_ANY_ID
,
38 PCI_ANY_ID
, 0, NFP_DEV_NFP3800
,
40 { PCI_VENDOR_ID_NETRONOME
, PCI_DEVICE_ID_NFP4000
,
41 PCI_VENDOR_ID_NETRONOME
, PCI_ANY_ID
,
42 PCI_ANY_ID
, 0, NFP_DEV_NFP6000
,
44 { PCI_VENDOR_ID_NETRONOME
, PCI_DEVICE_ID_NFP5000
,
45 PCI_VENDOR_ID_NETRONOME
, PCI_ANY_ID
,
46 PCI_ANY_ID
, 0, NFP_DEV_NFP6000
,
48 { PCI_VENDOR_ID_NETRONOME
, PCI_DEVICE_ID_NFP6000
,
49 PCI_VENDOR_ID_NETRONOME
, PCI_ANY_ID
,
50 PCI_ANY_ID
, 0, NFP_DEV_NFP6000
,
52 { PCI_VENDOR_ID_CORIGINE
, PCI_DEVICE_ID_NFP3800
,
53 PCI_VENDOR_ID_CORIGINE
, PCI_ANY_ID
,
54 PCI_ANY_ID
, 0, NFP_DEV_NFP3800
,
56 { PCI_VENDOR_ID_CORIGINE
, PCI_DEVICE_ID_NFP4000
,
57 PCI_VENDOR_ID_CORIGINE
, PCI_ANY_ID
,
58 PCI_ANY_ID
, 0, NFP_DEV_NFP6000
,
60 { PCI_VENDOR_ID_CORIGINE
, PCI_DEVICE_ID_NFP5000
,
61 PCI_VENDOR_ID_CORIGINE
, PCI_ANY_ID
,
62 PCI_ANY_ID
, 0, NFP_DEV_NFP6000
,
64 { PCI_VENDOR_ID_CORIGINE
, PCI_DEVICE_ID_NFP6000
,
65 PCI_VENDOR_ID_CORIGINE
, PCI_ANY_ID
,
66 PCI_ANY_ID
, 0, NFP_DEV_NFP6000
,
68 { 0, } /* Required last entry. */
70 MODULE_DEVICE_TABLE(pci
, nfp_pci_device_ids
);
72 int nfp_pf_rtsym_read_optional(struct nfp_pf
*pf
, const char *format
,
73 unsigned int default_val
)
79 snprintf(name
, sizeof(name
), format
, nfp_cppcore_pcie_unit(pf
->cpp
));
81 val
= nfp_rtsym_read_le(pf
->rtbl
, name
, &err
);
85 nfp_err(pf
->cpp
, "Unable to read symbol %s\n", name
);
93 nfp_pf_map_rtsym(struct nfp_pf
*pf
, const char *name
, const char *sym_fmt
,
94 unsigned int min_size
, struct nfp_cpp_area
**area
)
98 snprintf(pf_symbol
, sizeof(pf_symbol
), sym_fmt
,
99 nfp_cppcore_pcie_unit(pf
->cpp
));
101 return nfp_rtsym_map(pf
->rtbl
, pf_symbol
, name
, min_size
, area
);
104 /* Callers should hold the devlink instance lock */
105 int nfp_mbox_cmd(struct nfp_pf
*pf
, u32 cmd
, void *in_data
, u64 in_length
,
106 void *out_data
, u64 out_length
)
108 unsigned long err_at
;
116 max_data_sz
= nfp_rtsym_size(pf
->mbox
) - NFP_MBOX_SYM_MIN_SIZE
;
118 /* Check if cmd field is clear */
119 err
= nfp_rtsym_readl(pf
->cpp
, pf
->mbox
, NFP_MBOX_CMD
, &val
);
121 nfp_warn(pf
->cpp
, "failed to issue command (%u): %u, err: %d\n",
123 return err
?: -EBUSY
;
126 in_length
= min(in_length
, max_data_sz
);
127 n
= nfp_rtsym_write(pf
->cpp
, pf
->mbox
, NFP_MBOX_DATA
, in_data
,
131 /* Write data_len and wipe reserved */
132 err
= nfp_rtsym_writeq(pf
->cpp
, pf
->mbox
, NFP_MBOX_DATA_LEN
, in_length
);
136 /* Read back for ordering */
137 err
= nfp_rtsym_readl(pf
->cpp
, pf
->mbox
, NFP_MBOX_DATA_LEN
, &val
);
141 /* Write cmd and wipe return value */
142 err
= nfp_rtsym_writeq(pf
->cpp
, pf
->mbox
, NFP_MBOX_CMD
, cmd
);
146 err_at
= jiffies
+ 5 * HZ
;
148 /* Wait for command to go to 0 (NFP_MBOX_NO_CMD) */
149 err
= nfp_rtsym_readl(pf
->cpp
, pf
->mbox
, NFP_MBOX_CMD
, &val
);
155 if (time_is_before_eq_jiffies(err_at
))
161 /* Copy output if any (could be error info, do it before reading ret) */
162 err
= nfp_rtsym_readl(pf
->cpp
, pf
->mbox
, NFP_MBOX_DATA_LEN
, &val
);
166 out_length
= min_t(u32
, val
, min(out_length
, max_data_sz
));
167 n
= nfp_rtsym_read(pf
->cpp
, pf
->mbox
, NFP_MBOX_DATA
,
168 out_data
, out_length
);
172 /* Check if there is an error */
173 err
= nfp_rtsym_readl(pf
->cpp
, pf
->mbox
, NFP_MBOX_RET
, &val
);
182 static bool nfp_board_ready(struct nfp_pf
*pf
)
188 cp
= nfp_hwinfo_lookup(pf
->hwinfo
, "board.state");
192 err
= kstrtol(cp
, 0, &state
);
199 static int nfp_pf_board_state_wait(struct nfp_pf
*pf
)
201 const unsigned long wait_until
= jiffies
+ 10 * HZ
;
203 while (!nfp_board_ready(pf
)) {
204 if (time_is_before_eq_jiffies(wait_until
)) {
205 nfp_err(pf
->cpp
, "NFP board initialization timeout\n");
209 nfp_info(pf
->cpp
, "waiting for board initialization\n");
210 if (msleep_interruptible(500))
213 /* Refresh cached information */
215 pf
->hwinfo
= nfp_hwinfo_read(pf
->cpp
);
221 static int nfp_pcie_sriov_read_nfd_limit(struct nfp_pf
*pf
)
225 pf
->limit_vfs
= nfp_rtsym_read_le(pf
->rtbl
, "nfd_vf_cfg_max_vfs", &err
);
227 /* For backwards compatibility if symbol not found allow all */
232 nfp_warn(pf
->cpp
, "Warning: VF limit read failed: %d\n", err
);
236 err
= pci_sriov_set_totalvfs(pf
->pdev
, pf
->limit_vfs
);
238 nfp_warn(pf
->cpp
, "Failed to set VF count in sysfs: %d\n", err
);
242 static int nfp_pcie_sriov_enable(struct pci_dev
*pdev
, int num_vfs
)
244 #ifdef CONFIG_PCI_IOV
245 struct nfp_pf
*pf
= pci_get_drvdata(pdev
);
246 struct devlink
*devlink
;
249 if (num_vfs
> pf
->limit_vfs
) {
250 nfp_info(pf
->cpp
, "Firmware limits number of VFs to %u\n",
255 err
= pci_enable_sriov(pdev
, num_vfs
);
257 dev_warn(&pdev
->dev
, "Failed to enable PCI SR-IOV: %d\n", err
);
261 devlink
= priv_to_devlink(pf
);
264 err
= nfp_app_sriov_enable(pf
->app
, num_vfs
);
267 "App specific PCI SR-IOV configuration failed: %d\n",
269 goto err_sriov_disable
;
272 pf
->num_vfs
= num_vfs
;
274 dev_dbg(&pdev
->dev
, "Created %d VFs.\n", pf
->num_vfs
);
276 devl_unlock(devlink
);
280 devl_unlock(devlink
);
281 pci_disable_sriov(pdev
);
287 static int nfp_pcie_sriov_disable(struct pci_dev
*pdev
)
289 #ifdef CONFIG_PCI_IOV
290 struct nfp_pf
*pf
= pci_get_drvdata(pdev
);
291 struct devlink
*devlink
;
293 devlink
= priv_to_devlink(pf
);
296 /* If the VFs are assigned we cannot shut down SR-IOV without
297 * causing issues, so just leave the hardware available but
300 if (pci_vfs_assigned(pdev
)) {
301 dev_warn(&pdev
->dev
, "Disabling while VFs assigned - VFs will not be deallocated\n");
302 devl_unlock(devlink
);
306 nfp_app_sriov_disable(pf
->app
);
310 devl_unlock(devlink
);
312 pci_disable_sriov(pdev
);
313 dev_dbg(&pdev
->dev
, "Removed VFs.\n");
318 static int nfp_pcie_sriov_configure(struct pci_dev
*pdev
, int num_vfs
)
320 if (!pci_get_drvdata(pdev
))
324 return nfp_pcie_sriov_disable(pdev
);
326 return nfp_pcie_sriov_enable(pdev
, num_vfs
);
329 int nfp_flash_update_common(struct nfp_pf
*pf
, const struct firmware
*fw
,
330 struct netlink_ext_ack
*extack
)
332 struct device
*dev
= &pf
->pdev
->dev
;
336 nsp
= nfp_nsp_open(pf
->cpp
);
340 NL_SET_ERR_MSG_MOD(extack
, "can't access NSP");
342 dev_err(dev
, "Failed to access the NSP: %d\n", err
);
346 err
= nfp_nsp_write_flash(nsp
, fw
);
349 dev_info(dev
, "Finished writing flash image\n");
357 static const struct firmware
*
358 nfp_net_fw_request(struct pci_dev
*pdev
, struct nfp_pf
*pf
, const char *name
)
360 const struct firmware
*fw
= NULL
;
363 err
= request_firmware_direct(&fw
, name
, &pdev
->dev
);
364 nfp_info(pf
->cpp
, " %s: %s\n",
365 name
, err
? "not found" : "found");
373 * nfp_net_fw_find() - Find the correct firmware image for netdev mode
374 * @pdev: PCI Device structure
375 * @pf: NFP PF Device structure
377 * Return: firmware if found and requested successfully.
379 static const struct firmware
*
380 nfp_net_fw_find(struct pci_dev
*pdev
, struct nfp_pf
*pf
)
382 struct nfp_eth_table_port
*port
;
383 const struct firmware
*fw
;
384 const char *fw_model
;
390 nfp_info(pf
->cpp
, "Looking for firmware file in order of priority:\n");
392 /* First try to find a firmware image specific for this device */
393 interface
= nfp_cpp_interface(pf
->cpp
);
394 nfp_cpp_serial(pf
->cpp
, &serial
);
395 sprintf(fw_name
, "netronome/serial-%pMF-%02x-%02x.nffw",
396 serial
, interface
>> 8, interface
& 0xff);
397 fw
= nfp_net_fw_request(pdev
, pf
, fw_name
);
401 /* Then try the PCI name */
402 sprintf(fw_name
, "netronome/pci-%s.nffw", pci_name(pdev
));
403 fw
= nfp_net_fw_request(pdev
, pf
, fw_name
);
407 /* Finally try the card type and media */
409 dev_err(&pdev
->dev
, "Error: can't identify media config\n");
413 fw_model
= nfp_hwinfo_lookup(pf
->hwinfo
, "nffw.partno");
415 fw_model
= nfp_hwinfo_lookup(pf
->hwinfo
, "assembly.partno");
417 dev_err(&pdev
->dev
, "Error: can't read part number\n");
421 spc
= ARRAY_SIZE(fw_name
);
422 spc
-= snprintf(fw_name
, spc
, "netronome/nic_%s", fw_model
);
424 for (i
= 0; spc
> 0 && i
< pf
->eth_tbl
->count
; i
+= j
) {
425 port
= &pf
->eth_tbl
->ports
[i
];
427 while (i
+ j
< pf
->eth_tbl
->count
&&
428 port
->speed
== port
[j
].speed
)
431 spc
-= snprintf(&fw_name
[ARRAY_SIZE(fw_name
) - spc
], spc
,
432 "_%dx%d", j
, port
->speed
/ 1000);
438 spc
-= snprintf(&fw_name
[ARRAY_SIZE(fw_name
) - spc
], spc
, ".nffw");
442 return nfp_net_fw_request(pdev
, pf
, fw_name
);
446 nfp_get_fw_policy_value(struct pci_dev
*pdev
, struct nfp_nsp
*nsp
,
447 const char *key
, const char *default_val
, int max_val
,
454 snprintf(hwinfo
, sizeof(hwinfo
), key
);
455 err
= nfp_nsp_hwinfo_lookup_optional(nsp
, hwinfo
, sizeof(hwinfo
),
460 err
= kstrtol(hwinfo
, 0, &hi_val
);
461 if (err
|| hi_val
< 0 || hi_val
> max_val
) {
463 "Invalid value '%s' from '%s', ignoring\n",
465 err
= kstrtol(default_val
, 0, &hi_val
);
473 * nfp_fw_load() - Load the firmware image
474 * @pdev: PCI Device structure
475 * @pf: NFP PF Device structure
476 * @nsp: NFP SP handle
478 * Return: -ERRNO, 0 for no firmware loaded, 1 for firmware loaded
481 nfp_fw_load(struct pci_dev
*pdev
, struct nfp_pf
*pf
, struct nfp_nsp
*nsp
)
483 bool do_reset
, fw_loaded
= false;
484 const struct firmware
*fw
= NULL
;
485 int err
, reset
, policy
, ifcs
= 0;
490 snprintf(hwinfo
, sizeof(hwinfo
), "abi_drv_load_ifc");
491 err
= nfp_nsp_hwinfo_lookup_optional(nsp
, hwinfo
, sizeof(hwinfo
),
492 NFP_NSP_DRV_LOAD_IFC_DEFAULT
);
496 interface
= nfp_cpp_interface(pf
->cpp
);
498 while ((token
= strsep(&ptr
, ","))) {
499 unsigned long interface_hi
;
501 err
= kstrtoul(token
, 0, &interface_hi
);
504 "Failed to parse interface '%s': %d\n",
510 if (interface
== interface_hi
)
515 dev_info(&pdev
->dev
, "Firmware will be loaded by partner\n");
519 err
= nfp_get_fw_policy_value(pdev
, nsp
, "abi_drv_reset",
520 NFP_NSP_DRV_RESET_DEFAULT
,
521 NFP_NSP_DRV_RESET_NEVER
, &reset
);
525 err
= nfp_get_fw_policy_value(pdev
, nsp
, "app_fw_from_flash",
526 NFP_NSP_APP_FW_LOAD_DEFAULT
,
527 NFP_NSP_APP_FW_LOAD_PREF
, &policy
);
531 fw
= nfp_net_fw_find(pdev
, pf
);
532 do_reset
= reset
== NFP_NSP_DRV_RESET_ALWAYS
||
533 (fw
&& reset
== NFP_NSP_DRV_RESET_DISK
);
536 dev_info(&pdev
->dev
, "Soft-resetting the NFP\n");
537 err
= nfp_nsp_device_soft_reset(nsp
);
540 "Failed to soft reset the NFP: %d\n", err
);
541 goto exit_release_fw
;
545 if (fw
&& policy
!= NFP_NSP_APP_FW_LOAD_FLASH
) {
546 if (nfp_nsp_has_fw_loaded(nsp
) && nfp_nsp_fw_loaded(nsp
))
547 goto exit_release_fw
;
549 err
= nfp_nsp_load_fw(nsp
, fw
);
551 dev_err(&pdev
->dev
, "FW loading failed: %d\n",
553 goto exit_release_fw
;
555 dev_info(&pdev
->dev
, "Finished loading FW image\n");
557 } else if (policy
!= NFP_NSP_APP_FW_LOAD_DISK
&&
558 nfp_nsp_has_stored_fw_load(nsp
)) {
560 /* Don't propagate this error to stick with legacy driver
561 * behavior, failure will be detected later during init.
563 if (!nfp_nsp_load_stored_fw(nsp
))
564 dev_info(&pdev
->dev
, "Finished loading stored FW image\n");
566 /* Don't flag the fw_loaded in this case since other devices
567 * may reuse the firmware when configured this way
570 dev_warn(&pdev
->dev
, "Didn't load firmware, please update flash or reconfigure card\n");
574 release_firmware(fw
);
576 /* We don't want to unload firmware when other devices may still be
577 * dependent on it, which could be the case if there are multiple
578 * devices that could load firmware.
580 if (fw_loaded
&& ifcs
== 1)
581 pf
->unload_fw_on_remove
= true;
583 return err
< 0 ? err
: fw_loaded
;
587 nfp_nsp_init_ports(struct pci_dev
*pdev
, struct nfp_pf
*pf
,
590 bool needs_reinit
= false;
593 pf
->eth_tbl
= __nfp_eth_read_ports(pf
->cpp
, nsp
);
597 if (!nfp_nsp_has_mac_reinit(nsp
))
600 for (i
= 0; i
< pf
->eth_tbl
->count
; i
++)
601 needs_reinit
|= pf
->eth_tbl
->ports
[i
].override_changed
;
606 if (nfp_nsp_mac_reinit(nsp
))
607 dev_warn(&pdev
->dev
, "MAC reinit failed\n");
609 pf
->eth_tbl
= __nfp_eth_read_ports(pf
->cpp
, nsp
);
612 static int nfp_nsp_init(struct pci_dev
*pdev
, struct nfp_pf
*pf
)
617 err
= nfp_resource_wait(pf
->cpp
, NFP_RESOURCE_NSP
, 30);
621 nsp
= nfp_nsp_open(pf
->cpp
);
624 dev_err(&pdev
->dev
, "Failed to access the NSP: %d\n", err
);
628 err
= nfp_nsp_wait(nsp
);
632 nfp_nsp_init_ports(pdev
, pf
, nsp
);
634 pf
->nspi
= __nfp_nsp_identify(nsp
);
636 dev_info(&pdev
->dev
, "BSP: %s\n", pf
->nspi
->version
);
638 err
= nfp_fw_load(pdev
, pf
, nsp
);
642 dev_err(&pdev
->dev
, "Failed to load FW\n");
646 pf
->fw_loaded
= !!err
;
655 static void nfp_fw_unload(struct nfp_pf
*pf
)
660 nsp
= nfp_nsp_open(pf
->cpp
);
662 nfp_err(pf
->cpp
, "Reset failed, can't open NSP\n");
666 err
= nfp_nsp_device_soft_reset(nsp
);
668 dev_warn(&pf
->pdev
->dev
, "Couldn't unload firmware: %d\n", err
);
670 dev_info(&pf
->pdev
->dev
, "Firmware safely unloaded\n");
675 static int nfp_pf_find_rtsyms(struct nfp_pf
*pf
)
680 pf_id
= nfp_cppcore_pcie_unit(pf
->cpp
);
682 /* Optional per-PCI PF mailbox */
683 snprintf(pf_symbol
, sizeof(pf_symbol
), NFP_MBOX_SYM_NAME
, pf_id
);
684 pf
->mbox
= nfp_rtsym_lookup(pf
->rtbl
, pf_symbol
);
685 if (pf
->mbox
&& nfp_rtsym_size(pf
->mbox
) < NFP_MBOX_SYM_MIN_SIZE
) {
686 nfp_err(pf
->cpp
, "PF mailbox symbol too small: %llu < %d\n",
687 nfp_rtsym_size(pf
->mbox
), NFP_MBOX_SYM_MIN_SIZE
);
694 int nfp_net_pf_get_app_id(struct nfp_pf
*pf
)
696 return nfp_pf_rtsym_read_optional(pf
, "_pf%u_net_app_id",
700 static u64
nfp_net_pf_get_app_cap(struct nfp_pf
*pf
)
706 snprintf(name
, sizeof(name
), "_pf%u_net_app_cap", nfp_cppcore_pcie_unit(pf
->cpp
));
708 val
= nfp_rtsym_read_le(pf
->rtbl
, name
, &err
);
711 nfp_err(pf
->cpp
, "Unable to read symbol %s\n", name
);
719 static void nfp_pf_cfg_hwinfo(struct nfp_pf
*pf
)
726 nsp
= nfp_nsp_open(pf
->cpp
);
730 if (!nfp_nsp_has_hwinfo_set(nsp
))
733 sp_indiff
= (nfp_net_pf_get_app_id(pf
) == NFP_APP_FLOWER_NIC
) ||
734 (nfp_net_pf_get_app_cap(pf
) & NFP_NET_APP_CAP_SP_INDIFF
);
736 /* No need to clean `sp_indiff` in driver, management firmware
737 * will do it when application firmware is unloaded.
739 snprintf(hwinfo
, sizeof(hwinfo
), "sp_indiff=%d", sp_indiff
);
740 err
= nfp_nsp_hwinfo_set(nsp
, hwinfo
, sizeof(hwinfo
));
741 /* Not a fatal error, no need to return error to stop driver from loading */
743 nfp_warn(pf
->cpp
, "HWinfo(sp_indiff=%d) set failed: %d\n", sp_indiff
, err
);
745 /* Need reinit eth_tbl since the eth table state may change
746 * after sp_indiff is configured.
749 pf
->eth_tbl
= __nfp_eth_read_ports(pf
->cpp
, nsp
);
756 static int nfp_pci_probe(struct pci_dev
*pdev
,
757 const struct pci_device_id
*pci_id
)
759 const struct nfp_dev_info
*dev_info
;
760 struct devlink
*devlink
;
764 if ((pdev
->vendor
== PCI_VENDOR_ID_NETRONOME
||
765 pdev
->vendor
== PCI_VENDOR_ID_CORIGINE
) &&
766 (pdev
->device
== PCI_DEVICE_ID_NFP3800_VF
||
767 pdev
->device
== PCI_DEVICE_ID_NFP6000_VF
))
768 dev_warn(&pdev
->dev
, "Binding NFP VF device to the NFP PF driver, the VF driver is called 'nfp_netvf'\n");
770 dev_info
= &nfp_dev_info
[pci_id
->driver_data
];
772 err
= pci_enable_device(pdev
);
776 pci_set_master(pdev
);
778 err
= dma_set_mask_and_coherent(&pdev
->dev
, dev_info
->dma_mask
);
780 goto err_pci_disable
;
782 err
= pci_request_regions(pdev
, nfp_driver_name
);
784 dev_err(&pdev
->dev
, "Unable to reserve pci resources.\n");
785 goto err_pci_disable
;
788 devlink
= devlink_alloc(&nfp_devlink_ops
, sizeof(*pf
), &pdev
->dev
);
791 goto err_rel_regions
;
793 pf
= devlink_priv(devlink
);
794 INIT_LIST_HEAD(&pf
->vnics
);
795 INIT_LIST_HEAD(&pf
->ports
);
796 pci_set_drvdata(pdev
, pf
);
798 pf
->dev_info
= dev_info
;
800 pf
->wq
= alloc_workqueue("nfp-%s", 0, 2, pci_name(pdev
));
803 goto err_pci_priv_unset
;
806 pf
->cpp
= nfp_cpp_from_nfp6000_pcie(pdev
, dev_info
);
807 if (IS_ERR(pf
->cpp
)) {
808 err
= PTR_ERR(pf
->cpp
);
809 goto err_disable_msix
;
812 err
= nfp_resource_table_init(pf
->cpp
);
816 pf
->hwinfo
= nfp_hwinfo_read(pf
->cpp
);
818 dev_info(&pdev
->dev
, "Assembly: %s%s%s-%s CPLD: %s\n",
819 nfp_hwinfo_lookup(pf
->hwinfo
, "assembly.vendor"),
820 nfp_hwinfo_lookup(pf
->hwinfo
, "assembly.partno"),
821 nfp_hwinfo_lookup(pf
->hwinfo
, "assembly.serial"),
822 nfp_hwinfo_lookup(pf
->hwinfo
, "assembly.revision"),
823 nfp_hwinfo_lookup(pf
->hwinfo
, "cpld.version"));
825 err
= nfp_pf_board_state_wait(pf
);
827 goto err_hwinfo_free
;
829 err
= nfp_nsp_init(pdev
, pf
);
831 goto err_hwinfo_free
;
833 pf
->mip
= nfp_mip_open(pf
->cpp
);
834 pf
->rtbl
= __nfp_rtsym_table_read(pf
->cpp
, pf
->mip
);
836 err
= nfp_pf_find_rtsyms(pf
);
840 pf
->dump_flag
= NFP_DUMP_NSP_DIAG
;
841 pf
->dumpspec
= nfp_net_dump_load_dumpspec(pf
->cpp
, pf
->rtbl
);
843 err
= nfp_pcie_sriov_read_nfd_limit(pf
);
847 pf
->num_vfs
= pci_num_vf(pdev
);
848 if (pf
->num_vfs
> pf
->limit_vfs
) {
850 "Error: %d VFs already enabled, but loaded FW can only support %d\n",
851 pf
->num_vfs
, pf
->limit_vfs
);
856 nfp_pf_cfg_hwinfo(pf
);
858 err
= nfp_net_pci_probe(pf
);
862 err
= nfp_hwmon_register(pf
);
864 dev_err(&pdev
->dev
, "Failed to register hwmon info\n");
871 nfp_net_pci_remove(pf
);
874 nfp_mip_close(pf
->mip
);
875 if (pf
->unload_fw_on_remove
)
883 nfp_cpp_free(pf
->cpp
);
885 destroy_workqueue(pf
->wq
);
887 pci_set_drvdata(pdev
, NULL
);
888 devlink_free(devlink
);
890 pci_release_regions(pdev
);
892 pci_disable_device(pdev
);
897 static void __nfp_pci_shutdown(struct pci_dev
*pdev
, bool unload_fw
)
901 pf
= pci_get_drvdata(pdev
);
905 nfp_hwmon_unregister(pf
);
907 nfp_pcie_sriov_disable(pdev
);
909 nfp_net_pci_remove(pf
);
913 nfp_mip_close(pf
->mip
);
914 if (unload_fw
&& pf
->unload_fw_on_remove
)
917 destroy_workqueue(pf
->wq
);
918 pci_set_drvdata(pdev
, NULL
);
920 nfp_cpp_free(pf
->cpp
);
924 devlink_free(priv_to_devlink(pf
));
925 pci_release_regions(pdev
);
926 pci_disable_device(pdev
);
929 static void nfp_pci_remove(struct pci_dev
*pdev
)
931 __nfp_pci_shutdown(pdev
, true);
934 static void nfp_pci_shutdown(struct pci_dev
*pdev
)
936 __nfp_pci_shutdown(pdev
, false);
939 static struct pci_driver nfp_pci_driver
= {
940 .name
= nfp_driver_name
,
941 .id_table
= nfp_pci_device_ids
,
942 .probe
= nfp_pci_probe
,
943 .remove
= nfp_pci_remove
,
944 .shutdown
= nfp_pci_shutdown
,
945 .sriov_configure
= nfp_pcie_sriov_configure
,
948 static int __init
nfp_main_init(void)
952 pr_info("%s: NFP PCIe Driver, Copyright (C) 2014-2020 Netronome Systems\n",
954 pr_info("%s: NFP PCIe Driver, Copyright (C) 2021-2022 Corigine Inc.\n",
957 nfp_net_debugfs_create();
959 err
= pci_register_driver(&nfp_pci_driver
);
961 goto err_destroy_debugfs
;
963 err
= pci_register_driver(&nfp_netvf_pci_driver
);
970 pci_unregister_driver(&nfp_pci_driver
);
972 nfp_net_debugfs_destroy();
976 static void __exit
nfp_main_exit(void)
978 pci_unregister_driver(&nfp_netvf_pci_driver
);
979 pci_unregister_driver(&nfp_pci_driver
);
980 nfp_net_debugfs_destroy();
983 module_init(nfp_main_init
);
984 module_exit(nfp_main_exit
);
986 MODULE_FIRMWARE("netronome/nic_AMDA0058-0011_2x40.nffw");
987 MODULE_FIRMWARE("netronome/nic_AMDA0058-0012_2x40.nffw");
988 MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_1x40.nffw");
989 MODULE_FIRMWARE("netronome/nic_AMDA0081-0001_4x10.nffw");
990 MODULE_FIRMWARE("netronome/nic_AMDA0096-0001_2x10.nffw");
991 MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_2x40.nffw");
992 MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_4x10_1x40.nffw");
993 MODULE_FIRMWARE("netronome/nic_AMDA0097-0001_8x10.nffw");
994 MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x10.nffw");
995 MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_2x25.nffw");
996 MODULE_FIRMWARE("netronome/nic_AMDA0099-0001_1x10_1x25.nffw");
998 MODULE_AUTHOR("Corigine, Inc. <oss-drivers@corigine.com>");
999 MODULE_LICENSE("GPL");
1000 MODULE_DESCRIPTION("The Network Flow Processor (NFP) driver.");