aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/octeontx2/rvu_pf.c
blob: 246fca26a44615479b7324d0c4239222f53edc29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier:    GPL-2.0
/*
 * Copyright (C) 2018 Marvell International Ltd.
 */

#include <dm.h>
#include <errno.h>
#include <malloc.h>
#include <misc.h>
#include <net.h>
#include <pci_ids.h>
#include <asm/io.h>
#include <asm/types.h>
#include <asm/arch/board.h>
#include "cgx.h"
#include "nix.h"

extern struct udevice *rvu_af_dev;

int rvu_pf_init(struct rvu_pf *rvu)
{
	struct nix *nix;
	struct eth_pdata *pdata = dev_get_platdata(rvu->dev);

	debug("%s: Allocating nix lf\n", __func__);
	nix = nix_lf_alloc(rvu->dev);
	if (!nix) {
		printf("%s: Error allocating lf for pf %d\n",
		       __func__, rvu->pfid);
		return -1;
	}
	rvu->nix = nix;

	/* to make post_probe happy */
	if (is_valid_ethaddr(nix->lmac->mac_addr)) {
		memcpy(pdata->enetaddr, nix->lmac->mac_addr, 6);
		eth_env_set_enetaddr_by_index("eth", rvu->dev->seq,
					      pdata->enetaddr);
	}

	return 0;
}

static const struct eth_ops nix_eth_ops = {
	.start			= nix_lf_init,
	.send			= nix_lf_xmit,
	.recv			= nix_lf_recv,
	.free_pkt		= nix_lf_free_pkt,
	.stop			= nix_lf_halt,
	.write_hwaddr		= nix_lf_setup_mac,
};

int rvu_pf_probe(struct udevice *dev)
{
	struct rvu_pf *rvu = dev_get_priv(dev);
	int err;
	char name[16];

	debug("%s: name: %s\n", __func__, dev->name);

	rvu->pf_base = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_2, PCI_REGION_MEM);
	rvu->pfid = dev->seq + 1; // RVU PF's start from 1;
	rvu->dev = dev;
	if (!rvu_af_dev) {
		printf("%s: Error: Could not find RVU AF device\n",
		       __func__);
		return -1;
	}
	rvu->afdev = rvu_af_dev;

	debug("RVU PF %u BAR2 %p\n", rvu->pfid, rvu->pf_base);

	rvu_get_lfid_for_pf(rvu->pfid, &rvu->nix_lfid, &rvu->npa_lfid);

	err = rvu_pf_init(rvu);
	if (err)
		printf("%s: Error %d adding nix\n", __func__, err);

	/*
	 * modify device name to include index/sequence number,
	 * for better readability, this is 1:1 mapping with eth0/1/2.. names.
	 */
	sprintf(name, "rvu_pf#%d", dev->seq);
	device_set_name(dev, name);
	debug("%s: name: %s\n", __func__, dev->name);
	return err;
}

int rvu_pf_remove(struct udevice *dev)
{
	struct rvu_pf *rvu = dev_get_priv(dev);

	nix_lf_shutdown(rvu->nix);
	npa_lf_shutdown(rvu->nix);

	debug("%s: rvu pf%d down --\n", __func__,  rvu->pfid);

	return 0;
}

U_BOOT_DRIVER(rvu_pf) = {
	.name   = "rvu_pf",
	.id     = UCLASS_ETH,
	.probe	= rvu_pf_probe,
	.remove = rvu_pf_remove,
	.ops    = &nix_eth_ops,
	.priv_auto	= sizeof(struct rvu_pf),
	.plat_auto	= sizeof(struct eth_pdata),
};

static struct pci_device_id rvu_pf_supported[] = {
	{ PCI_VDEVICE(CAVIUM, PCI_DEVICE_ID_CAVIUM_RVU_PF) },
	{}
};

U_BOOT_PCI_DEVICE(rvu_pf, rvu_pf_supported);