xref: /linux/drivers/net/dsa/vitesse-vsc73xx.h (revision 9410645520e9b820069761f3450ef6661418e279)
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 /**
186b783dedSPawel Dembicki  * struct vsc73xx_portinfo - port data structure: contains storage data
196b783dedSPawel Dembicki  * @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode
206b783dedSPawel Dembicki  * @pvid_tag_8021q: pvid vlan number used in tag_8021q mode
216b783dedSPawel Dembicki  * @pvid_vlan_filtering_configured: informs if port has configured pvid in vlan
226b783dedSPawel Dembicki  *	filtering mode
236b783dedSPawel Dembicki  * @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q
246b783dedSPawel Dembicki  *	mode
256b783dedSPawel Dembicki  */
266b783dedSPawel Dembicki struct vsc73xx_portinfo {
276b783dedSPawel Dembicki 	u16		pvid_vlan_filtering;
286b783dedSPawel Dembicki 	u16		pvid_tag_8021q;
296b783dedSPawel Dembicki 	bool		pvid_vlan_filtering_configured;
306b783dedSPawel Dembicki 	bool		pvid_tag_8021q_configured;
316b783dedSPawel Dembicki };
326b783dedSPawel Dembicki 
336b783dedSPawel 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
446b783dedSPawel Dembicki  * @portinfo: Storage table portinfo structructures
456b783dedSPawel Dembicki  * @vlans: List of configured vlans. Contains port mask and untagged status of
466b783dedSPawel Dembicki  *	every vlan configured in port vlan operation. It doesn't cover tag_8021q
476b783dedSPawel Dembicki  *	vlans.
48*075e3d30SPawel Dembicki  * @fdb_lock: Mutex protects fdb access
4995711cd5SPawel Dembicki  */
5095711cd5SPawel Dembicki struct vsc73xx {
5195711cd5SPawel Dembicki 	struct device			*dev;
5295711cd5SPawel Dembicki 	struct gpio_desc		*reset;
5395711cd5SPawel Dembicki 	struct dsa_switch		*ds;
5495711cd5SPawel Dembicki 	struct gpio_chip		gc;
5595711cd5SPawel Dembicki 	u16				chipid;
5695711cd5SPawel Dembicki 	u8				addr[ETH_ALEN];
5795711cd5SPawel Dembicki 	const struct vsc73xx_ops	*ops;
5895711cd5SPawel Dembicki 	void				*priv;
596b783dedSPawel Dembicki 	struct vsc73xx_portinfo		portinfo[VSC73XX_MAX_NUM_PORTS];
606b783dedSPawel Dembicki 	struct list_head		vlans;
61*075e3d30SPawel Dembicki 	struct mutex			fdb_lock;
6295711cd5SPawel Dembicki };
6395711cd5SPawel Dembicki 
6496944aafSPawel Dembicki /**
6596944aafSPawel Dembicki  * struct vsc73xx_ops - VSC73xx methods container
6696944aafSPawel Dembicki  * @read: Method for register reading over the hardware-dependent interface
6796944aafSPawel Dembicki  * @write: Method for register writing over the hardware-dependent interface
6896944aafSPawel Dembicki  */
6995711cd5SPawel Dembicki struct vsc73xx_ops {
7095711cd5SPawel Dembicki 	int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg,
7195711cd5SPawel Dembicki 		    u32 *val);
7295711cd5SPawel Dembicki 	int (*write)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg,
7395711cd5SPawel Dembicki 		     u32 val);
7495711cd5SPawel Dembicki };
7595711cd5SPawel Dembicki 
766b783dedSPawel Dembicki /**
776b783dedSPawel Dembicki  * struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan
786b783dedSPawel Dembicki  *	database copy
796b783dedSPawel Dembicki  * @vid: VLAN number
806b783dedSPawel Dembicki  * @portmask: each bit represents one port
816b783dedSPawel Dembicki  * @untagged: each bit represents one port configured with @vid untagged
826b783dedSPawel Dembicki  * @list: list structure
836b783dedSPawel Dembicki  */
846b783dedSPawel Dembicki struct vsc73xx_bridge_vlan {
856b783dedSPawel Dembicki 	u16 vid;
866b783dedSPawel Dembicki 	u8 portmask;
876b783dedSPawel Dembicki 	u8 untagged;
886b783dedSPawel Dembicki 	struct list_head list;
896b783dedSPawel Dembicki };
906b783dedSPawel Dembicki 
9195711cd5SPawel Dembicki int vsc73xx_is_addr_valid(u8 block, u8 subblock);
9295711cd5SPawel Dembicki int vsc73xx_probe(struct vsc73xx *vsc);
93e99fa423SUwe Kleine-König void vsc73xx_remove(struct vsc73xx *vsc);
940650bf52SVladimir Oltean void vsc73xx_shutdown(struct vsc73xx *vsc);
95