Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /* Realtek SMI interface driver defines
0003  *
0004  * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
0005  * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
0006  */
0007 
0008 #ifndef _REALTEK_H
0009 #define _REALTEK_H
0010 
0011 #include <linux/phy.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/gpio/consumer.h>
0014 #include <net/dsa.h>
0015 
0016 #define REALTEK_HW_STOP_DELAY       25  /* msecs */
0017 #define REALTEK_HW_START_DELAY      100 /* msecs */
0018 
0019 struct realtek_ops;
0020 struct dentry;
0021 struct inode;
0022 struct file;
0023 
0024 struct rtl8366_mib_counter {
0025     unsigned int    base;
0026     unsigned int    offset;
0027     unsigned int    length;
0028     const char  *name;
0029 };
0030 
0031 /*
0032  * struct rtl8366_vlan_mc - Virtual LAN member configuration
0033  */
0034 struct rtl8366_vlan_mc {
0035     u16 vid;
0036     u16 untag;
0037     u16 member;
0038     u8  fid;
0039     u8  priority;
0040 };
0041 
0042 struct rtl8366_vlan_4k {
0043     u16 vid;
0044     u16 untag;
0045     u16 member;
0046     u8  fid;
0047 };
0048 
0049 struct realtek_priv {
0050     struct device       *dev;
0051     struct gpio_desc    *reset;
0052     struct gpio_desc    *mdc;
0053     struct gpio_desc    *mdio;
0054     struct regmap       *map;
0055     struct regmap       *map_nolock;
0056     struct mutex        map_lock;
0057     struct mii_bus      *slave_mii_bus;
0058     struct mii_bus      *bus;
0059     int         mdio_addr;
0060 
0061     unsigned int        clk_delay;
0062     u8          cmd_read;
0063     u8          cmd_write;
0064     spinlock_t      lock; /* Locks around command writes */
0065     struct dsa_switch   *ds;
0066     struct irq_domain   *irqdomain;
0067     bool            leds_disabled;
0068 
0069     unsigned int        cpu_port;
0070     unsigned int        num_ports;
0071     unsigned int        num_vlan_mc;
0072     unsigned int        num_mib_counters;
0073     struct rtl8366_mib_counter *mib_counters;
0074 
0075     const struct realtek_ops *ops;
0076     int         (*setup_interface)(struct dsa_switch *ds);
0077     int         (*write_reg_noack)(void *ctx, u32 addr, u32 data);
0078 
0079     int         vlan_enabled;
0080     int         vlan4k_enabled;
0081 
0082     char            buf[4096];
0083     void            *chip_data; /* Per-chip extra variant data */
0084 };
0085 
0086 /*
0087  * struct realtek_ops - vtable for the per-SMI-chiptype operations
0088  * @detect: detects the chiptype
0089  */
0090 struct realtek_ops {
0091     int (*detect)(struct realtek_priv *priv);
0092     int (*reset_chip)(struct realtek_priv *priv);
0093     int (*setup)(struct realtek_priv *priv);
0094     void    (*cleanup)(struct realtek_priv *priv);
0095     int (*get_mib_counter)(struct realtek_priv *priv,
0096                    int port,
0097                    struct rtl8366_mib_counter *mib,
0098                    u64 *mibvalue);
0099     int (*get_vlan_mc)(struct realtek_priv *priv, u32 index,
0100                    struct rtl8366_vlan_mc *vlanmc);
0101     int (*set_vlan_mc)(struct realtek_priv *priv, u32 index,
0102                    const struct rtl8366_vlan_mc *vlanmc);
0103     int (*get_vlan_4k)(struct realtek_priv *priv, u32 vid,
0104                    struct rtl8366_vlan_4k *vlan4k);
0105     int (*set_vlan_4k)(struct realtek_priv *priv,
0106                    const struct rtl8366_vlan_4k *vlan4k);
0107     int (*get_mc_index)(struct realtek_priv *priv, int port, int *val);
0108     int (*set_mc_index)(struct realtek_priv *priv, int port, int index);
0109     bool    (*is_vlan_valid)(struct realtek_priv *priv, unsigned int vlan);
0110     int (*enable_vlan)(struct realtek_priv *priv, bool enable);
0111     int (*enable_vlan4k)(struct realtek_priv *priv, bool enable);
0112     int (*enable_port)(struct realtek_priv *priv, int port, bool enable);
0113     int (*phy_read)(struct realtek_priv *priv, int phy, int regnum);
0114     int (*phy_write)(struct realtek_priv *priv, int phy, int regnum,
0115                  u16 val);
0116 };
0117 
0118 struct realtek_variant {
0119     const struct dsa_switch_ops *ds_ops_smi;
0120     const struct dsa_switch_ops *ds_ops_mdio;
0121     const struct realtek_ops *ops;
0122     unsigned int clk_delay;
0123     u8 cmd_read;
0124     u8 cmd_write;
0125     size_t chip_data_sz;
0126 };
0127 
0128 /* RTL8366 library helpers */
0129 int rtl8366_mc_is_used(struct realtek_priv *priv, int mc_index, int *used);
0130 int rtl8366_set_vlan(struct realtek_priv *priv, int vid, u32 member,
0131              u32 untag, u32 fid);
0132 int rtl8366_set_pvid(struct realtek_priv *priv, unsigned int port,
0133              unsigned int vid);
0134 int rtl8366_enable_vlan4k(struct realtek_priv *priv, bool enable);
0135 int rtl8366_enable_vlan(struct realtek_priv *priv, bool enable);
0136 int rtl8366_reset_vlan(struct realtek_priv *priv);
0137 int rtl8366_vlan_add(struct dsa_switch *ds, int port,
0138              const struct switchdev_obj_port_vlan *vlan,
0139              struct netlink_ext_ack *extack);
0140 int rtl8366_vlan_del(struct dsa_switch *ds, int port,
0141              const struct switchdev_obj_port_vlan *vlan);
0142 void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset,
0143              uint8_t *data);
0144 int rtl8366_get_sset_count(struct dsa_switch *ds, int port, int sset);
0145 void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
0146 
0147 extern const struct realtek_variant rtl8366rb_variant;
0148 extern const struct realtek_variant rtl8365mb_variant;
0149 
0150 #endif /*  _REALTEK_H */