1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Marvell International Ltd.
13 #include <asm/types.h>
14 #include <asm/arch/board.h>
18 extern struct udevice *rvu_af_dev;
20 int rvu_pf_init(struct rvu_pf *rvu)
23 struct eth_pdata *pdata = dev_get_platdata(rvu->dev);
25 debug("%s: Allocating nix lf\n", __func__);
26 nix = nix_lf_alloc(rvu->dev);
28 printf("%s: Error allocating lf for pf %d\n",
34 /* to make post_probe happy */
35 if (is_valid_ethaddr(nix->lmac->mac_addr)) {
36 memcpy(pdata->enetaddr, nix->lmac->mac_addr, 6);
37 eth_env_set_enetaddr_by_index("eth", rvu->dev->seq,
44 static const struct eth_ops nix_eth_ops = {
48 .free_pkt = nix_lf_free_pkt,
50 .write_hwaddr = nix_lf_setup_mac,
53 int rvu_pf_probe(struct udevice *dev)
55 struct rvu_pf *rvu = dev_get_priv(dev);
59 debug("%s: name: %s\n", __func__, dev->name);
61 rvu->pf_base = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_2, PCI_REGION_MEM);
62 rvu->pfid = dev->seq + 1; // RVU PF's start from 1;
65 printf("%s: Error: Could not find RVU AF device\n",
69 rvu->afdev = rvu_af_dev;
71 debug("RVU PF %u BAR2 %p\n", rvu->pfid, rvu->pf_base);
73 rvu_get_lfid_for_pf(rvu->pfid, &rvu->nix_lfid, &rvu->npa_lfid);
75 err = rvu_pf_init(rvu);
77 printf("%s: Error %d adding nix\n", __func__, err);
80 * modify device name to include index/sequence number,
81 * for better readability, this is 1:1 mapping with eth0/1/2.. names.
83 sprintf(name, "rvu_pf#%d", dev->seq);
84 device_set_name(dev, name);
85 debug("%s: name: %s\n", __func__, dev->name);
89 int rvu_pf_remove(struct udevice *dev)
91 struct rvu_pf *rvu = dev_get_priv(dev);
93 nix_lf_shutdown(rvu->nix);
94 npa_lf_shutdown(rvu->nix);
96 debug("%s: rvu pf%d down --\n", __func__, rvu->pfid);
101 U_BOOT_DRIVER(rvu_pf) = {
104 .probe = rvu_pf_probe,
105 .remove = rvu_pf_remove,
107 .priv_auto_alloc_size = sizeof(struct rvu_pf),
108 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
111 static struct pci_device_id rvu_pf_supported[] = {
112 { PCI_VDEVICE(CAVIUM, PCI_DEVICE_ID_CAVIUM_RVU_PF) },
116 U_BOOT_PCI_DEVICE(rvu_pf, rvu_pf_supported);