aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/etherswitch/ar40xx/ar40xx_var.h
blob: 10ecdc40689e4f01e59f77a08fa0d6e3e2742461 (plain) (blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2022 Adrian Chadd <adrian@FreeBSD.org>.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#ifndef	__AR40XX_VAR_H__
#define	__AR40XX_VAR_H__

#define	AR40XX_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
#define	AR40XX_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
#define	AR40XX_LOCK_ASSERT(_sc)		mtx_assert(&(_sc)->sc_mtx, MA_OWNED)

/*
 * register space access macros
 */
#define	AR40XX_REG_WRITE(sc, reg, val)		do {		\
	    bus_write_4(sc->sc_ess_mem_res, (reg), (val));	\
	    } while (0)

#define	AR40XX_REG_READ(sc, reg)	bus_read_4(sc->sc_ess_mem_res, (reg))

#define	AR40XX_REG_BARRIER_WRITE(sc)	bus_barrier((sc)->sc_ess_mem_res,	\
	    0, (sc)->sc_ess_mem_size, BUS_SPACE_BARRIER_WRITE)
#define	AR40XX_REG_BARRIER_READ(sc)	bus_barrier((sc)->sc_ess_mem_res,	\
	    0, (sc)->sc_ess_mem_size, BUS_SPACE_BARRIER_READ)
#define	AR40XX_REG_BARRIER_RW(sc)	bus_barrier((sc)->sc_ess_mem_res,	\
	    0, (sc)->sc_ess_mem_size,					\
	    BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE)

/* Size of the VLAN table itself in hardware */
#define	AR40XX_NUM_VTU_ENTRIES		64
#define	AR40XX_NUM_PORTS		6
#define	AR40XX_NUM_PHYS			5
/* Size of the ATU table in hardware */
#define	AR40XX_NUM_ATU_ENTRIES		2048

struct ar40xx_softc {
	struct mtx	sc_mtx;		/* serialize access to softc */
	device_t	sc_dev;
	uint32_t	sc_debug;

	/* ess-switch memory resource */
	struct resource	*sc_ess_mem_res;
	int		sc_ess_mem_rid;
	size_t		sc_ess_mem_size;

	/* ess-switch clock resource */
	clk_t		sc_ess_clk;

	/* ess-switch reset resource */
	hwreset_t	sc_ess_rst;

	/* phy update callout timer */
	struct callout	sc_phy_callout;

	/* memory for the ess-psgmii config interface */
	bus_space_tag_t		sc_psgmii_mem_tag;
	bus_space_handle_t	sc_psgmii_mem_handle;
	bus_size_t		sc_psgmii_mem_size;

	/* reference to the ipq4019-mdio interface */
	phandle_t		sc_mdio_phandle;
	device_t		sc_mdio_dev;

	etherswitch_info_t	sc_info;

	struct {
		uint32_t	phy_t_status;
	} sc_psgmii;

	struct {
		uint32_t switch_mac_mode;
		uint32_t switch_cpu_bmp;
		uint32_t switch_lan_bmp;
		uint32_t switch_wan_bmp;
	} sc_config;

	/* VLAN table configuration */
	struct {
		/* Whether 802.1q VLANs are enabled or not */
		bool vlan;
		/* Map etherswitch vgroup to 802.1q vlan */
		uint16_t vlan_id[AR40XX_NUM_VTU_ENTRIES];
		/* VLAN port membership */
		uint8_t vlan_ports[AR40XX_NUM_VTU_ENTRIES];
		/* VLAN port membership - untagged ports */
		uint16_t vlan_untagged[AR40XX_NUM_VTU_ENTRIES];
		/* PVID for each port - index into vlan_id[] */
		uint16_t pvid[AR40XX_NUM_PORTS];
	} sc_vlan;

	struct {
		bool mirror_rx;
		bool mirror_tx;
		int source_port;
		int monitor_port;
	} sc_monitor;

	struct {
		char *ifname[AR40XX_NUM_PHYS];
		device_t miibus[AR40XX_NUM_PHYS];
		if_t ifp[AR40XX_NUM_PHYS];
	} sc_phys;

	/* ATU (address table unit) support */
	struct {
		int count;
		int size;
		etherswitch_atu_entry_t entries[AR40XX_NUM_ATU_ENTRIES];
	} atu;
};

#endif	/* __AR40XX_VAR_H__ */