xref: /openbmc/linux/drivers/net/ethernet/mscc/ocelot.h (revision 15e3ae36)
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/ptp_clock_kernel.h>
19 #include <linux/regmap.h>
20 
21 #include <soc/mscc/ocelot_qsys.h>
22 #include <soc/mscc/ocelot_sys.h>
23 #include <soc/mscc/ocelot_dev.h>
24 #include <soc/mscc/ocelot_ana.h>
25 #include <soc/mscc/ocelot.h>
26 #include "ocelot_rew.h"
27 #include "ocelot_qs.h"
28 #include "ocelot_tc.h"
29 #include "ocelot_ptp.h"
30 
31 #define OCELOT_BUFFER_CELL_SZ 60
32 
33 #define OCELOT_STATS_CHECK_DELAY (2 * HZ)
34 
35 #define OCELOT_PTP_QUEUE_SZ	128
36 
37 struct frame_info {
38 	u32 len;
39 	u16 port;
40 	u16 vid;
41 	u8 tag_type;
42 	u16 rew_op;
43 	u32 timestamp;	/* rew_val */
44 };
45 
46 struct ocelot_multicast {
47 	struct list_head list;
48 	unsigned char addr[ETH_ALEN];
49 	u16 vid;
50 	u16 ports;
51 };
52 
53 struct ocelot_port_private {
54 	struct ocelot_port port;
55 	struct net_device *dev;
56 	struct phy_device *phy;
57 	u8 chip_port;
58 
59 	u8 vlan_aware;
60 
61 	struct phy *serdes;
62 
63 	struct ocelot_port_tc tc;
64 };
65 
66 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
67 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
68 
69 #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
70 #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
71 
72 int ocelot_chip_init(struct ocelot *ocelot, const struct ocelot_ops *ops);
73 int ocelot_probe_port(struct ocelot *ocelot, u8 port,
74 		      void __iomem *regs,
75 		      struct phy_device *phy);
76 
77 void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu,
78 			 enum ocelot_tag_prefix injection,
79 			 enum ocelot_tag_prefix extraction);
80 
81 extern struct notifier_block ocelot_netdevice_nb;
82 extern struct notifier_block ocelot_switchdev_nb;
83 extern struct notifier_block ocelot_switchdev_blocking_nb;
84 
85 #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
86 #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
87 
88 #endif
89