Suneel Garapati | 8666ae8 | 2020-08-26 14:37:42 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2018 Marvell International Ltd. |
| 4 | */ |
| 5 | |
| 6 | #include <dm.h> |
| 7 | #include <errno.h> |
| 8 | #include <malloc.h> |
| 9 | #include <misc.h> |
| 10 | #include <net.h> |
| 11 | #include <pci_ids.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/types.h> |
| 14 | #include <asm/arch/board.h> |
| 15 | #include "cgx.h" |
| 16 | #include "nix.h" |
| 17 | |
| 18 | extern struct udevice *rvu_af_dev; |
| 19 | |
| 20 | int rvu_pf_init(struct rvu_pf *rvu) |
| 21 | { |
| 22 | struct nix *nix; |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 23 | struct eth_pdata *pdata = dev_get_plat(rvu->dev); |
Suneel Garapati | 8666ae8 | 2020-08-26 14:37:42 +0200 | [diff] [blame] | 24 | |
| 25 | debug("%s: Allocating nix lf\n", __func__); |
| 26 | nix = nix_lf_alloc(rvu->dev); |
| 27 | if (!nix) { |
| 28 | printf("%s: Error allocating lf for pf %d\n", |
| 29 | __func__, rvu->pfid); |
| 30 | return -1; |
| 31 | } |
| 32 | rvu->nix = nix; |
| 33 | |
| 34 | /* to make post_probe happy */ |
| 35 | if (is_valid_ethaddr(nix->lmac->mac_addr)) { |
| 36 | memcpy(pdata->enetaddr, nix->lmac->mac_addr, 6); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 37 | eth_env_set_enetaddr_by_index("eth", dev_seq(rvu->dev), |
Suneel Garapati | 8666ae8 | 2020-08-26 14:37:42 +0200 | [diff] [blame] | 38 | pdata->enetaddr); |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static const struct eth_ops nix_eth_ops = { |
| 45 | .start = nix_lf_init, |
| 46 | .send = nix_lf_xmit, |
| 47 | .recv = nix_lf_recv, |
| 48 | .free_pkt = nix_lf_free_pkt, |
| 49 | .stop = nix_lf_halt, |
| 50 | .write_hwaddr = nix_lf_setup_mac, |
| 51 | }; |
| 52 | |
| 53 | int rvu_pf_probe(struct udevice *dev) |
| 54 | { |
| 55 | struct rvu_pf *rvu = dev_get_priv(dev); |
| 56 | int err; |
| 57 | char name[16]; |
| 58 | |
| 59 | debug("%s: name: %s\n", __func__, dev->name); |
| 60 | |
| 61 | rvu->pf_base = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_2, PCI_REGION_MEM); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 62 | rvu->pfid = dev_seq(dev) + 1; // RVU PF's start from 1; |
Suneel Garapati | 8666ae8 | 2020-08-26 14:37:42 +0200 | [diff] [blame] | 63 | rvu->dev = dev; |
| 64 | if (!rvu_af_dev) { |
| 65 | printf("%s: Error: Could not find RVU AF device\n", |
| 66 | __func__); |
| 67 | return -1; |
| 68 | } |
| 69 | rvu->afdev = rvu_af_dev; |
| 70 | |
| 71 | debug("RVU PF %u BAR2 %p\n", rvu->pfid, rvu->pf_base); |
| 72 | |
| 73 | rvu_get_lfid_for_pf(rvu->pfid, &rvu->nix_lfid, &rvu->npa_lfid); |
| 74 | |
| 75 | err = rvu_pf_init(rvu); |
| 76 | if (err) |
| 77 | printf("%s: Error %d adding nix\n", __func__, err); |
| 78 | |
| 79 | /* |
| 80 | * modify device name to include index/sequence number, |
| 81 | * for better readability, this is 1:1 mapping with eth0/1/2.. names. |
| 82 | */ |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 83 | sprintf(name, "rvu_pf#%d", dev_seq(dev)); |
Suneel Garapati | 8666ae8 | 2020-08-26 14:37:42 +0200 | [diff] [blame] | 84 | device_set_name(dev, name); |
| 85 | debug("%s: name: %s\n", __func__, dev->name); |
| 86 | return err; |
| 87 | } |
| 88 | |
| 89 | int rvu_pf_remove(struct udevice *dev) |
| 90 | { |
| 91 | struct rvu_pf *rvu = dev_get_priv(dev); |
| 92 | |
| 93 | nix_lf_shutdown(rvu->nix); |
| 94 | npa_lf_shutdown(rvu->nix); |
| 95 | |
| 96 | debug("%s: rvu pf%d down --\n", __func__, rvu->pfid); |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | U_BOOT_DRIVER(rvu_pf) = { |
| 102 | .name = "rvu_pf", |
| 103 | .id = UCLASS_ETH, |
| 104 | .probe = rvu_pf_probe, |
| 105 | .remove = rvu_pf_remove, |
| 106 | .ops = &nix_eth_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 107 | .priv_auto = sizeof(struct rvu_pf), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 108 | .plat_auto = sizeof(struct eth_pdata), |
Suneel Garapati | 8666ae8 | 2020-08-26 14:37:42 +0200 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | static struct pci_device_id rvu_pf_supported[] = { |
| 112 | { PCI_VDEVICE(CAVIUM, PCI_DEVICE_ID_CAVIUM_RVU_PF) }, |
| 113 | {} |
| 114 | }; |
| 115 | |
| 116 | U_BOOT_PCI_DEVICE(rvu_pf, rvu_pf_supported); |