c615d2a81dd52752ce167b816d599a02a6206fca
[linux-2.6-microblaze.git] / drivers / net / dsa / microchip / ksz_priv.h
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * Microchip KSZ series switch common definitions
4  *
5  * Copyright (C) 2017-2019 Microchip Technology Inc.
6  */
7
8 #ifndef __KSZ_PRIV_H
9 #define __KSZ_PRIV_H
10
11 #include <linux/kernel.h>
12 #include <linux/mutex.h>
13 #include <linux/phy.h>
14 #include <linux/etherdevice.h>
15 #include <net/dsa.h>
16
17 struct ksz_io_ops;
18
19 struct vlan_table {
20         u32 table[3];
21 };
22
23 struct ksz_port_mib {
24         struct mutex cnt_mutex;         /* structure access */
25         u8 cnt_ptr;
26         u64 *counters;
27 };
28
29 struct ksz_port {
30         u16 member;
31         u16 vid_member;
32         int stp_state;
33         struct phy_device phydev;
34
35         u32 on:1;                       /* port is not disabled by hardware */
36         u32 phy:1;                      /* port has a PHY */
37         u32 fiber:1;                    /* port is fiber */
38         u32 sgmii:1;                    /* port is SGMII */
39         u32 force:1;
40         u32 read:1;                     /* read MIB counters in background */
41         u32 freeze:1;                   /* MIB counter freeze is enabled */
42
43         struct ksz_port_mib mib;
44 };
45
46 struct ksz_device {
47         struct dsa_switch *ds;
48         struct ksz_platform_data *pdata;
49         const char *name;
50
51         struct mutex dev_mutex;         /* device access */
52         struct mutex reg_mutex;         /* register access */
53         struct mutex stats_mutex;       /* status access */
54         struct mutex alu_mutex;         /* ALU access */
55         struct mutex vlan_mutex;        /* vlan access */
56         const struct ksz_io_ops *ops;
57         const struct ksz_dev_ops *dev_ops;
58
59         struct device *dev;
60
61         void *priv;
62
63         struct gpio_desc *reset_gpio;   /* Optional reset GPIO */
64
65         /* chip specific data */
66         u32 chip_id;
67         int num_vlans;
68         int num_alus;
69         int num_statics;
70         int cpu_port;                   /* port connected to CPU */
71         int cpu_ports;                  /* port bitmap can be cpu port */
72         int phy_port_cnt;
73         int port_cnt;
74         int reg_mib_cnt;
75         int mib_cnt;
76         int mib_port_cnt;
77         int last_port;                  /* ports after that not used */
78         phy_interface_t interface;
79         u32 regs_size;
80         bool phy_errata_9477;
81         bool synclko_125;
82
83         struct vlan_table *vlan_cache;
84
85         u8 *txbuf;
86
87         struct ksz_port *ports;
88         struct timer_list mib_read_timer;
89         struct work_struct mib_read;
90         unsigned long mib_read_interval;
91         u16 br_member;
92         u16 member;
93         u16 live_ports;
94         u16 on_ports;                   /* ports enabled by DSA */
95         u16 rx_ports;
96         u16 tx_ports;
97         u16 mirror_rx;
98         u16 mirror_tx;
99         u32 features;                   /* chip specific features */
100         u32 overrides;                  /* chip functions set by user */
101         u16 host_mask;
102         u16 port_mask;
103 };
104
105 struct ksz_io_ops {
106         int (*read8)(struct ksz_device *dev, u32 reg, u8 *value);
107         int (*read16)(struct ksz_device *dev, u32 reg, u16 *value);
108         int (*read24)(struct ksz_device *dev, u32 reg, u32 *value);
109         int (*read32)(struct ksz_device *dev, u32 reg, u32 *value);
110         int (*write8)(struct ksz_device *dev, u32 reg, u8 value);
111         int (*write16)(struct ksz_device *dev, u32 reg, u16 value);
112         int (*write24)(struct ksz_device *dev, u32 reg, u32 value);
113         int (*write32)(struct ksz_device *dev, u32 reg, u32 value);
114         int (*get)(struct ksz_device *dev, u32 reg, void *data, size_t len);
115         int (*set)(struct ksz_device *dev, u32 reg, void *data, size_t len);
116 };
117
118 struct alu_struct {
119         /* entry 1 */
120         u8      is_static:1;
121         u8      is_src_filter:1;
122         u8      is_dst_filter:1;
123         u8      prio_age:3;
124         u32     _reserv_0_1:23;
125         u8      mstp:3;
126         /* entry 2 */
127         u8      is_override:1;
128         u8      is_use_fid:1;
129         u32     _reserv_1_1:23;
130         u8      port_forward:7;
131         /* entry 3 & 4*/
132         u32     _reserv_2_1:9;
133         u8      fid:7;
134         u8      mac[ETH_ALEN];
135 };
136
137 struct ksz_dev_ops {
138         u32 (*get_port_addr)(int port, int offset);
139         void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
140         void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
141         void (*phy_setup)(struct ksz_device *dev, int port,
142                           struct phy_device *phy);
143         void (*port_cleanup)(struct ksz_device *dev, int port);
144         void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
145         void (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
146         void (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
147         int (*r_dyn_mac_table)(struct ksz_device *dev, u16 addr, u8 *mac_addr,
148                                u8 *fid, u8 *src_port, u8 *timestamp,
149                                u16 *entries);
150         int (*r_sta_mac_table)(struct ksz_device *dev, u16 addr,
151                                struct alu_struct *alu);
152         void (*w_sta_mac_table)(struct ksz_device *dev, u16 addr,
153                                 struct alu_struct *alu);
154         void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
155                           u64 *cnt);
156         void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
157                           u64 *dropped, u64 *cnt);
158         void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
159         void (*port_init_cnt)(struct ksz_device *dev, int port);
160         int (*shutdown)(struct ksz_device *dev);
161         int (*detect)(struct ksz_device *dev);
162         int (*init)(struct ksz_device *dev);
163         void (*exit)(struct ksz_device *dev);
164 };
165
166 struct ksz_device *ksz_switch_alloc(struct device *base,
167                                     const struct ksz_io_ops *ops, void *priv);
168 int ksz_switch_register(struct ksz_device *dev,
169                         const struct ksz_dev_ops *ops);
170 void ksz_switch_remove(struct ksz_device *dev);
171
172 int ksz9477_switch_register(struct ksz_device *dev);
173
174 #endif