1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
3 * Microsemi Ocelot Switch driver
5 * Copyright (c) 2017 Microsemi Corporation
8 #ifndef _MSCC_OCELOT_H_
9 #define _MSCC_OCELOT_H_
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>
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"
29 #define OCELOT_BUFFER_CELL_SZ 60
31 #define OCELOT_STATS_CHECK_DELAY (2 * HZ)
33 #define OCELOT_PTP_QUEUE_SZ 128
41 u32 timestamp
; /* rew_val */
44 struct ocelot_port_tc
{
46 unsigned long offload_cnt
;
48 unsigned long police_id
;
51 struct ocelot_port_private
{
52 struct ocelot_port port
;
53 struct net_device
*dev
;
54 struct phy_device
*phy
;
59 struct ocelot_port_tc tc
;
62 struct ocelot_dump_ctx
{
63 struct net_device
*dev
;
65 struct netlink_callback
*cb
;
69 /* MAC table entry types.
70 * ENTRYTYPE_NORMAL is subject to aging.
71 * ENTRYTYPE_LOCKED is not subject to aging.
72 * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
73 * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
75 enum macaccess_entry_type
{
82 /* A (PGID) port mask structure, encoding the 2^ocelot->num_phys_ports
83 * possibilities of egress port masks for L2 multicast traffic.
84 * For a switch with 9 user ports, there are 512 possible port masks, but the
85 * hardware only has 46 individual PGIDs that it can forward multicast traffic
86 * to. So we need a structure that maps the limited PGID indices to the port
87 * destinations requested by the user for L2 multicast.
93 struct list_head list
;
96 struct ocelot_multicast
{
97 struct list_head list
;
98 enum macaccess_entry_type entry_type
;
99 unsigned char addr
[ETH_ALEN
];
102 struct ocelot_pgid
*pgid
;
105 int ocelot_port_fdb_do_dump(const unsigned char *addr
, u16 vid
,
106 bool is_static
, void *data
);
107 int ocelot_mact_learn(struct ocelot
*ocelot
, int port
,
108 const unsigned char mac
[ETH_ALEN
],
109 unsigned int vid
, enum macaccess_entry_type type
);
110 int ocelot_mact_forget(struct ocelot
*ocelot
,
111 const unsigned char mac
[ETH_ALEN
], unsigned int vid
);
112 int ocelot_port_lag_join(struct ocelot
*ocelot
, int port
,
113 struct net_device
*bond
);
114 void ocelot_port_lag_leave(struct ocelot
*ocelot
, int port
,
115 struct net_device
*bond
);
116 struct net_device
*ocelot_port_to_netdev(struct ocelot
*ocelot
, int port
);
117 int ocelot_netdev_to_port(struct net_device
*dev
);
119 u32
ocelot_port_readl(struct ocelot_port
*port
, u32 reg
);
120 void ocelot_port_writel(struct ocelot_port
*port
, u32 val
, u32 reg
);
122 int ocelot_probe_port(struct ocelot
*ocelot
, int port
, struct regmap
*target
,
123 struct phy_device
*phy
);
125 void ocelot_set_cpu_port(struct ocelot
*ocelot
, int cpu
,
126 enum ocelot_tag_prefix injection
,
127 enum ocelot_tag_prefix extraction
);
129 extern struct notifier_block ocelot_netdevice_nb
;
130 extern struct notifier_block ocelot_switchdev_nb
;
131 extern struct notifier_block ocelot_switchdev_blocking_nb
;