cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

realtek.h (4476B)


      1/* SPDX-License-Identifier: GPL-2.0+ */
      2/* Realtek SMI interface driver defines
      3 *
      4 * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
      5 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
      6 */
      7
      8#ifndef _REALTEK_H
      9#define _REALTEK_H
     10
     11#include <linux/phy.h>
     12#include <linux/platform_device.h>
     13#include <linux/gpio/consumer.h>
     14#include <net/dsa.h>
     15
     16#define REALTEK_HW_STOP_DELAY		25	/* msecs */
     17#define REALTEK_HW_START_DELAY		100	/* msecs */
     18
     19struct realtek_ops;
     20struct dentry;
     21struct inode;
     22struct file;
     23
     24struct rtl8366_mib_counter {
     25	unsigned int	base;
     26	unsigned int	offset;
     27	unsigned int	length;
     28	const char	*name;
     29};
     30
     31/*
     32 * struct rtl8366_vlan_mc - Virtual LAN member configuration
     33 */
     34struct rtl8366_vlan_mc {
     35	u16	vid;
     36	u16	untag;
     37	u16	member;
     38	u8	fid;
     39	u8	priority;
     40};
     41
     42struct rtl8366_vlan_4k {
     43	u16	vid;
     44	u16	untag;
     45	u16	member;
     46	u8	fid;
     47};
     48
     49struct realtek_priv {
     50	struct device		*dev;
     51	struct gpio_desc	*reset;
     52	struct gpio_desc	*mdc;
     53	struct gpio_desc	*mdio;
     54	struct regmap		*map;
     55	struct regmap		*map_nolock;
     56	struct mutex		map_lock;
     57	struct mii_bus		*slave_mii_bus;
     58	struct mii_bus		*bus;
     59	int			mdio_addr;
     60
     61	unsigned int		clk_delay;
     62	u8			cmd_read;
     63	u8			cmd_write;
     64	spinlock_t		lock; /* Locks around command writes */
     65	struct dsa_switch	*ds;
     66	struct irq_domain	*irqdomain;
     67	bool			leds_disabled;
     68
     69	unsigned int		cpu_port;
     70	unsigned int		num_ports;
     71	unsigned int		num_vlan_mc;
     72	unsigned int		num_mib_counters;
     73	struct rtl8366_mib_counter *mib_counters;
     74
     75	const struct realtek_ops *ops;
     76	int			(*setup_interface)(struct dsa_switch *ds);
     77	int			(*write_reg_noack)(void *ctx, u32 addr, u32 data);
     78
     79	int			vlan_enabled;
     80	int			vlan4k_enabled;
     81
     82	char			buf[4096];
     83	void			*chip_data; /* Per-chip extra variant data */
     84};
     85
     86/*
     87 * struct realtek_ops - vtable for the per-SMI-chiptype operations
     88 * @detect: detects the chiptype
     89 */
     90struct realtek_ops {
     91	int	(*detect)(struct realtek_priv *priv);
     92	int	(*reset_chip)(struct realtek_priv *priv);
     93	int	(*setup)(struct realtek_priv *priv);
     94	void	(*cleanup)(struct realtek_priv *priv);
     95	int	(*get_mib_counter)(struct realtek_priv *priv,
     96				   int port,
     97				   struct rtl8366_mib_counter *mib,
     98				   u64 *mibvalue);
     99	int	(*get_vlan_mc)(struct realtek_priv *priv, u32 index,
    100			       struct rtl8366_vlan_mc *vlanmc);
    101	int	(*set_vlan_mc)(struct realtek_priv *priv, u32 index,
    102			       const struct rtl8366_vlan_mc *vlanmc);
    103	int	(*get_vlan_4k)(struct realtek_priv *priv, u32 vid,
    104			       struct rtl8366_vlan_4k *vlan4k);
    105	int	(*set_vlan_4k)(struct realtek_priv *priv,
    106			       const struct rtl8366_vlan_4k *vlan4k);
    107	int	(*get_mc_index)(struct realtek_priv *priv, int port, int *val);
    108	int	(*set_mc_index)(struct realtek_priv *priv, int port, int index);
    109	bool	(*is_vlan_valid)(struct realtek_priv *priv, unsigned int vlan);
    110	int	(*enable_vlan)(struct realtek_priv *priv, bool enable);
    111	int	(*enable_vlan4k)(struct realtek_priv *priv, bool enable);
    112	int	(*enable_port)(struct realtek_priv *priv, int port, bool enable);
    113	int	(*phy_read)(struct realtek_priv *priv, int phy, int regnum);
    114	int	(*phy_write)(struct realtek_priv *priv, int phy, int regnum,
    115			     u16 val);
    116};
    117
    118struct realtek_variant {
    119	const struct dsa_switch_ops *ds_ops_smi;
    120	const struct dsa_switch_ops *ds_ops_mdio;
    121	const struct realtek_ops *ops;
    122	unsigned int clk_delay;
    123	u8 cmd_read;
    124	u8 cmd_write;
    125	size_t chip_data_sz;
    126};
    127
    128/* RTL8366 library helpers */
    129int rtl8366_mc_is_used(struct realtek_priv *priv, int mc_index, int *used);
    130int rtl8366_set_vlan(struct realtek_priv *priv, int vid, u32 member,
    131		     u32 untag, u32 fid);
    132int rtl8366_set_pvid(struct realtek_priv *priv, unsigned int port,
    133		     unsigned int vid);
    134int rtl8366_enable_vlan4k(struct realtek_priv *priv, bool enable);
    135int rtl8366_enable_vlan(struct realtek_priv *priv, bool enable);
    136int rtl8366_reset_vlan(struct realtek_priv *priv);
    137int rtl8366_vlan_add(struct dsa_switch *ds, int port,
    138		     const struct switchdev_obj_port_vlan *vlan,
    139		     struct netlink_ext_ack *extack);
    140int rtl8366_vlan_del(struct dsa_switch *ds, int port,
    141		     const struct switchdev_obj_port_vlan *vlan);
    142void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset,
    143			 uint8_t *data);
    144int rtl8366_get_sset_count(struct dsa_switch *ds, int port, int sset);
    145void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
    146
    147extern const struct realtek_variant rtl8366rb_variant;
    148extern const struct realtek_variant rtl8365mb_variant;
    149
    150#endif /*  _REALTEK_H */