95 lines · c
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 and7 * a sixth CPU port facing the processor with an RGMII interface. These ports8 * 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 816 17/**18 * struct vsc73xx_portinfo - port data structure: contains storage data19 * @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode20 * @pvid_tag_8021q: pvid vlan number used in tag_8021q mode21 * @pvid_vlan_filtering_configured: informs if port has configured pvid in vlan22 * filtering mode23 * @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q24 * mode25 */26struct 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 structure35 * @dev: The device pointer36 * @reset: The descriptor for the GPIO line tied to the reset pin37 * @ds: Pointer to the DSA core structure38 * @gc: Main structure of the GPIO controller39 * @chipid: Storage for the Chip ID value read from the CHIPID register of the40 * switch41 * @addr: MAC address used in flow control frames42 * @ops: Structure with hardware-dependent operations43 * @priv: Pointer to the configuration interface structure44 * @portinfo: Storage table portinfo structructures45 * @vlans: List of configured vlans. Contains port mask and untagged status of46 * every vlan configured in port vlan operation. It doesn't cover tag_8021q47 * vlans.48 * @fdb_lock: Mutex protects fdb access49 */50struct vsc73xx {51 struct device *dev;52 struct gpio_desc *reset;53 struct dsa_switch *ds;54 struct gpio_chip gc;55 u16 chipid;56 u8 addr[ETH_ALEN];57 const struct vsc73xx_ops *ops;58 void *priv;59 struct vsc73xx_portinfo portinfo[VSC73XX_MAX_NUM_PORTS];60 struct list_head vlans;61 struct mutex fdb_lock;62};63 64/**65 * struct vsc73xx_ops - VSC73xx methods container66 * @read: Method for register reading over the hardware-dependent interface67 * @write: Method for register writing over the hardware-dependent interface68 */69struct vsc73xx_ops {70 int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg,71 u32 *val);72 int (*write)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg,73 u32 val);74};75 76/**77 * struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan78 * database copy79 * @vid: VLAN number80 * @portmask: each bit represents one port81 * @untagged: each bit represents one port configured with @vid untagged82 * @list: list structure83 */84struct vsc73xx_bridge_vlan {85 u16 vid;86 u8 portmask;87 u8 untagged;88 struct list_head list;89};90 91int vsc73xx_is_addr_valid(u8 block, u8 subblock);92int vsc73xx_probe(struct vsc73xx *vsc);93void vsc73xx_remove(struct vsc73xx *vsc);94void vsc73xx_shutdown(struct vsc73xx *vsc);95