summaryrefslogtreecommitdiff
path: root/sys/arch/octeon/dev/ogxnexus.c
blob: 186b1a1671a43d91911650e46e23d7030fc79e91 (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
/*	$OpenBSD: ogxnexus.c,v 1.1 2019/11/04 14:58:40 visa Exp $	*/

/*
 * Copyright (c) 2019 Visa Hankala
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * Driver for OCTEON BGX nexus.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <dev/ofw/fdt.h>
#include <dev/ofw/openfirm.h>

#include <machine/bus.h>
#include <machine/fdt.h>

#include <octeon/dev/ogxreg.h>
#include <octeon/dev/ogxvar.h>

struct ogxnexus_softc {
	struct device		 sc_dev;
	bus_space_tag_t		 sc_iot;
	bus_space_handle_t	 sc_ioh;
	int			 sc_bgxid;
};

#define NEXUS_RD_8(sc, reg) \
	bus_space_write_8((sc)->sc_iot, (sc)->sc_ioh, (reg))
#define NEXUS_WR_8(sc, reg, val) \
	bus_space_write_8((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))

int	ogxnexus_match(struct device *, void *, void *);
void	ogxnexus_attach(struct device *, struct device *, void *);

const struct cfattach ogxnexus_ca = {
	sizeof(struct ogxnexus_softc), ogxnexus_match, ogxnexus_attach
};

struct cfdriver ogxnexus_cd = {
	NULL, "ogxnexus", DV_DULL
};

int
ogxnexus_match(struct device *parent, void *match, void *aux)
{
	struct fdt_attach_args *faa = aux;

	return OF_is_compatible(faa->fa_node, "cavium,octeon-7890-bgx");
}

void
ogxnexus_attach(struct device *parent, struct device *self, void *aux)
{
	struct ogx_attach_args oaa;
	struct fdt_attach_args *faa = aux;
	struct ogxnexus_softc *sc = (struct ogxnexus_softc *)self;
	int i, node;

	if (faa->fa_nreg < 1) {
		printf(": no registers\n");
		return;
	}

	sc->sc_bgxid = (faa->fa_reg[0].addr >> 24) & 7;

	sc->sc_iot = faa->fa_iot;
	if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size,
	    0, &sc->sc_ioh)) {
		printf(": can't map IO space\n");
		return;
	}

	/* Disable all CAM entries. */
	for (i = 0; i < BGX_NCAM; i++)
		NEXUS_WR_8(sc, BGX_CMR_RX_ADR_CAM(i), 0);

	/* Set the number of LMACs per BGX. */
	NEXUS_WR_8(sc, BGX_CMR_RX_LMACS, BGX_NLMAC);
	NEXUS_WR_8(sc, BGX_CMR_TX_LMACS, BGX_NLMAC);

	printf("\n");

	for (node = OF_child(faa->fa_node); node != 0; node = OF_peer(node)) {
		memset(&oaa, 0, sizeof(oaa));
		oaa.oaa_node = node;
		oaa.oaa_bgxid = sc->sc_bgxid;
		oaa.oaa_iot = sc->sc_iot;
		oaa.oaa_ioh = sc->sc_ioh;
		oaa.oaa_dmat = faa->fa_dmat;

		config_found(&sc->sc_dev, &oaa, NULL);
	}
}