xref: /openbmc/linux/drivers/net/ethernet/mscc/ocelot.h (revision 82df5b73)
1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
2 /*
3  * Microsemi Ocelot Switch driver
4  *
5  * Copyright (c) 2017 Microsemi Corporation
6  */
7 
8 #ifndef _MSCC_OCELOT_H_
9 #define _MSCC_OCELOT_H_
10 
11 #include <linux/bitops.h>
12 #include <linux/etherdevice.h>
13 #include <linux/if_vlan.h>
14 #include <linux/net_tstamp.h>
15 #include <linux/phy.h>
16 #include <linux/phy/phy.h>
17 #include <linux/platform_device.h>
18 #include <linux/regmap.h>
19 
20 #include <soc/mscc/ocelot_qsys.h>
21 #include <soc/mscc/ocelot_sys.h>
22 #include <soc/mscc/ocelot_dev.h>
23 #include <soc/mscc/ocelot_ana.h>
24 #include <soc/mscc/ocelot_ptp.h>
25 #include <soc/mscc/ocelot.h>
26 #include "ocelot_rew.h"
27 #include "ocelot_qs.h"
28 #include "ocelot_tc.h"
29 
30 #define OCELOT_BUFFER_CELL_SZ 60
31 
32 #define OCELOT_STATS_CHECK_DELAY (2 * HZ)
33 
34 #define OCELOT_PTP_QUEUE_SZ	128
35 
36 struct frame_info {
37 	u32 len;
38 	u16 port;
39 	u16 vid;
40 	u8 tag_type;
41 	u16 rew_op;
42 	u32 timestamp;	/* rew_val */
43 };
44 
45 struct ocelot_multicast {
46 	struct list_head list;
47 	unsigned char addr[ETH_ALEN];
48 	u16 vid;
49 	u16 ports;
50 };
51 
52 struct ocelot_port_private {
53 	struct ocelot_port port;
54 	struct net_device *dev;
55 	struct phy_device *phy;
56 	u8 chip_port;
57 
58 	struct phy *serdes;
59 
60 	struct ocelot_port_tc tc;
61 };
62 
63 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
64 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
65 
66 #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
67 #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
68 
69 int ocelot_chip_init(struct ocelot *ocelot, const struct ocelot_ops *ops);
70 int ocelot_probe_port(struct ocelot *ocelot, u8 port,
71 		      void __iomem *regs,
72 		      struct phy_device *phy);
73 
74 void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu,
75 			 enum ocelot_tag_prefix injection,
76 			 enum ocelot_tag_prefix extraction);
77 
78 extern struct notifier_block ocelot_netdevice_nb;
79 extern struct notifier_block ocelot_switchdev_nb;
80 extern struct notifier_block ocelot_switchdev_blocking_nb;
81 
82 #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
83 #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
84 
85 #endif
86