1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #include <linux/device.h> 3 #include <linux/etherdevice.h> 4 #include <linux/gpio/driver.h> 5 6 /* The VSC7395 switch chips have 5+1 ports which means 5 ordinary ports and 7 * a sixth CPU port facing the processor with an RGMII interface. These ports 8 * are numbered 0..4 and 6, so they leave a "hole" in the port map for port 5, 9 * which is invalid. 10 * 11 * The VSC7398 has 8 ports, port 7 is again the CPU port. 12 * 13 * We allocate 8 ports and avoid access to the nonexistent ports. 14 */ 15 #define VSC73XX_MAX_NUM_PORTS 8 16 17 /** 18 * struct vsc73xx_portinfo - port data structure: contains storage data 19 * @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode 20 * @pvid_tag_8021q: pvid vlan number used in tag_8021q mode 21 * @pvid_vlan_filtering_configured: informs if port has configured pvid in vlan 22 * filtering mode 23 * @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q 24 * mode 25 */ 26 struct vsc73xx_portinfo { 27 u16 pvid_vlan_filtering; 28 u16 pvid_tag_8021q; 29 bool pvid_vlan_filtering_configured; 30 bool pvid_tag_8021q_configured; 31 }; 32 33 /** 34 * struct vsc73xx - VSC73xx state container: main data structure 35 * @dev: The device pointer 36 * @reset: The descriptor for the GPIO line tied to the reset pin 37 * @ds: Pointer to the DSA core structure 38 * @gc: Main structure of the GPIO controller 39 * @chipid: Storage for the Chip ID value read from the CHIPID register of the 40 * switch 41 * @addr: MAC address used in flow control frames 42 * @ops: Structure with hardware-dependent operations 43 * @priv: Pointer to the configuration interface structure 44 * @portinfo: Storage table portinfo structructures 45 * @vlans: List of configured vlans. Contains port mask and untagged status of 46 * every vlan configured in port vlan operation. It doesn't cover tag_8021q 47 * vlans. 48 */ 49 struct vsc73xx { 50 struct device *dev; 51 struct gpio_desc *reset; 52 struct dsa_switch *ds; 53 struct gpio_chip gc; 54 u16 chipid; 55 u8 addr[ETH_ALEN]; 56 const struct vsc73xx_ops *ops; 57 void *priv; 58 struct vsc73xx_portinfo portinfo[VSC73XX_MAX_NUM_PORTS]; 59 struct list_head vlans; 60 }; 61 62 /** 63 * struct vsc73xx_ops - VSC73xx methods container 64 * @read: Method for register reading over the hardware-dependent interface 65 * @write: Method for register writing over the hardware-dependent interface 66 */ 67 struct vsc73xx_ops { 68 int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg, 69 u32 *val); 70 int (*write)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg, 71 u32 val); 72 }; 73 74 /** 75 * struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan 76 * database copy 77 * @vid: VLAN number 78 * @portmask: each bit represents one port 79 * @untagged: each bit represents one port configured with @vid untagged 80 * @list: list structure 81 */ 82 struct vsc73xx_bridge_vlan { 83 u16 vid; 84 u8 portmask; 85 u8 untagged; 86 struct list_head list; 87 }; 88 89 int vsc73xx_is_addr_valid(u8 block, u8 subblock); 90 int vsc73xx_probe(struct vsc73xx *vsc); 91 void vsc73xx_remove(struct vsc73xx *vsc); 92 void vsc73xx_shutdown(struct vsc73xx *vsc); 93