xref: /linux/drivers/net/dsa/vitesse-vsc73xx.h (revision 6b783ded364ad037dd526c0be5860f58a51ca084)
195711cd5SPawel Dembicki /* SPDX-License-Identifier: GPL-2.0 */
295711cd5SPawel Dembicki #include <linux/device.h>
395711cd5SPawel Dembicki #include <linux/etherdevice.h>
495711cd5SPawel Dembicki #include <linux/gpio/driver.h>
595711cd5SPawel Dembicki 
66cc5280aSPawel Dembicki /* The VSC7395 switch chips have 5+1 ports which means 5 ordinary ports and
76cc5280aSPawel Dembicki  * a sixth CPU port facing the processor with an RGMII interface. These ports
86cc5280aSPawel Dembicki  * are numbered 0..4 and 6, so they leave a "hole" in the port map for port 5,
96cc5280aSPawel Dembicki  * which is invalid.
106cc5280aSPawel Dembicki  *
116cc5280aSPawel Dembicki  * The VSC7398 has 8 ports, port 7 is again the CPU port.
126cc5280aSPawel Dembicki  *
136cc5280aSPawel Dembicki  * We allocate 8 ports and avoid access to the nonexistent ports.
146cc5280aSPawel Dembicki  */
156cc5280aSPawel Dembicki #define VSC73XX_MAX_NUM_PORTS	8
166cc5280aSPawel Dembicki 
1795711cd5SPawel Dembicki /**
18*6b783dedSPawel Dembicki  * struct vsc73xx_portinfo - port data structure: contains storage data
19*6b783dedSPawel Dembicki  * @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode
20*6b783dedSPawel Dembicki  * @pvid_tag_8021q: pvid vlan number used in tag_8021q mode
21*6b783dedSPawel Dembicki  * @pvid_vlan_filtering_configured: informs if port has configured pvid in vlan
22*6b783dedSPawel Dembicki  *	filtering mode
23*6b783dedSPawel Dembicki  * @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q
24*6b783dedSPawel Dembicki  *	mode
25*6b783dedSPawel Dembicki  */
26*6b783dedSPawel Dembicki struct vsc73xx_portinfo {
27*6b783dedSPawel Dembicki 	u16		pvid_vlan_filtering;
28*6b783dedSPawel Dembicki 	u16		pvid_tag_8021q;
29*6b783dedSPawel Dembicki 	bool		pvid_vlan_filtering_configured;
30*6b783dedSPawel Dembicki 	bool		pvid_tag_8021q_configured;
31*6b783dedSPawel Dembicki };
32*6b783dedSPawel Dembicki 
33*6b783dedSPawel Dembicki /**
3496944aafSPawel Dembicki  * struct vsc73xx - VSC73xx state container: main data structure
3596944aafSPawel Dembicki  * @dev: The device pointer
3696944aafSPawel Dembicki  * @reset: The descriptor for the GPIO line tied to the reset pin
3796944aafSPawel Dembicki  * @ds: Pointer to the DSA core structure
3896944aafSPawel Dembicki  * @gc: Main structure of the GPIO controller
3996944aafSPawel Dembicki  * @chipid: Storage for the Chip ID value read from the CHIPID register of the
4096944aafSPawel Dembicki  *	switch
4196944aafSPawel Dembicki  * @addr: MAC address used in flow control frames
4296944aafSPawel Dembicki  * @ops: Structure with hardware-dependent operations
4396944aafSPawel Dembicki  * @priv: Pointer to the configuration interface structure
44*6b783dedSPawel Dembicki  * @portinfo: Storage table portinfo structructures
45*6b783dedSPawel Dembicki  * @vlans: List of configured vlans. Contains port mask and untagged status of
46*6b783dedSPawel Dembicki  *	every vlan configured in port vlan operation. It doesn't cover tag_8021q
47*6b783dedSPawel Dembicki  *	vlans.
4895711cd5SPawel Dembicki  */
4995711cd5SPawel Dembicki struct vsc73xx {
5095711cd5SPawel Dembicki 	struct device			*dev;
5195711cd5SPawel Dembicki 	struct gpio_desc		*reset;
5295711cd5SPawel Dembicki 	struct dsa_switch		*ds;
5395711cd5SPawel Dembicki 	struct gpio_chip		gc;
5495711cd5SPawel Dembicki 	u16				chipid;
5595711cd5SPawel Dembicki 	u8				addr[ETH_ALEN];
5695711cd5SPawel Dembicki 	const struct vsc73xx_ops	*ops;
5795711cd5SPawel Dembicki 	void				*priv;
58*6b783dedSPawel Dembicki 	struct vsc73xx_portinfo		portinfo[VSC73XX_MAX_NUM_PORTS];
59*6b783dedSPawel Dembicki 	struct list_head		vlans;
6095711cd5SPawel Dembicki };
6195711cd5SPawel Dembicki 
6296944aafSPawel Dembicki /**
6396944aafSPawel Dembicki  * struct vsc73xx_ops - VSC73xx methods container
6496944aafSPawel Dembicki  * @read: Method for register reading over the hardware-dependent interface
6596944aafSPawel Dembicki  * @write: Method for register writing over the hardware-dependent interface
6696944aafSPawel Dembicki  */
6795711cd5SPawel Dembicki struct vsc73xx_ops {
6895711cd5SPawel Dembicki 	int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg,
6995711cd5SPawel Dembicki 		    u32 *val);
7095711cd5SPawel Dembicki 	int (*write)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg,
7195711cd5SPawel Dembicki 		     u32 val);
7295711cd5SPawel Dembicki };
7395711cd5SPawel Dembicki 
74*6b783dedSPawel Dembicki /**
75*6b783dedSPawel Dembicki  * struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan
76*6b783dedSPawel Dembicki  *	database copy
77*6b783dedSPawel Dembicki  * @vid: VLAN number
78*6b783dedSPawel Dembicki  * @portmask: each bit represents one port
79*6b783dedSPawel Dembicki  * @untagged: each bit represents one port configured with @vid untagged
80*6b783dedSPawel Dembicki  * @list: list structure
81*6b783dedSPawel Dembicki  */
82*6b783dedSPawel Dembicki struct vsc73xx_bridge_vlan {
83*6b783dedSPawel Dembicki 	u16 vid;
84*6b783dedSPawel Dembicki 	u8 portmask;
85*6b783dedSPawel Dembicki 	u8 untagged;
86*6b783dedSPawel Dembicki 	struct list_head list;
87*6b783dedSPawel Dembicki };
88*6b783dedSPawel Dembicki 
8995711cd5SPawel Dembicki int vsc73xx_is_addr_valid(u8 block, u8 subblock);
9095711cd5SPawel Dembicki int vsc73xx_probe(struct vsc73xx *vsc);
91e99fa423SUwe Kleine-König void vsc73xx_remove(struct vsc73xx *vsc);
920650bf52SVladimir Oltean void vsc73xx_shutdown(struct vsc73xx *vsc);
93