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/phylink.h> 16 #include <linux/platform_device.h> 17 #include <linux/regmap.h> 18 19 #include <soc/mscc/ocelot_qsys.h> 20 #include <soc/mscc/ocelot_sys.h> 21 #include <soc/mscc/ocelot_dev.h> 22 #include <soc/mscc/ocelot_ana.h> 23 #include <soc/mscc/ocelot_ptp.h> 24 #include <soc/mscc/ocelot.h> 25 #include "ocelot_rew.h" 26 #include "ocelot_qs.h" 27 28 #define OCELOT_VLAN_UNAWARE_PVID 0 29 #define OCELOT_BUFFER_CELL_SZ 60 30 31 #define OCELOT_STATS_CHECK_DELAY (2 * HZ) 32 33 #define OCELOT_PTP_QUEUE_SZ 128 34 35 #define OCELOT_JUMBO_MTU 9000 36 37 struct ocelot_port_tc { 38 bool block_shared; 39 unsigned long offload_cnt; 40 41 unsigned long police_id; 42 }; 43 44 struct ocelot_port_private { 45 struct ocelot_port port; 46 struct net_device *dev; 47 struct phylink *phylink; 48 struct phylink_config phylink_config; 49 u8 chip_port; 50 struct ocelot_port_tc tc; 51 }; 52 53 struct ocelot_dump_ctx { 54 struct net_device *dev; 55 struct sk_buff *skb; 56 struct netlink_callback *cb; 57 int idx; 58 }; 59 60 /* A (PGID) port mask structure, encoding the 2^ocelot->num_phys_ports 61 * possibilities of egress port masks for L2 multicast traffic. 62 * For a switch with 9 user ports, there are 512 possible port masks, but the 63 * hardware only has 46 individual PGIDs that it can forward multicast traffic 64 * to. So we need a structure that maps the limited PGID indices to the port 65 * destinations requested by the user for L2 multicast. 66 */ 67 struct ocelot_pgid { 68 unsigned long ports; 69 int index; 70 refcount_t refcount; 71 struct list_head list; 72 }; 73 74 struct ocelot_multicast { 75 struct list_head list; 76 enum macaccess_entry_type entry_type; 77 unsigned char addr[ETH_ALEN]; 78 u16 vid; 79 u16 ports; 80 struct ocelot_pgid *pgid; 81 }; 82 83 int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, 84 bool is_static, void *data); 85 int ocelot_mact_learn(struct ocelot *ocelot, int port, 86 const unsigned char mac[ETH_ALEN], 87 unsigned int vid, enum macaccess_entry_type type); 88 int ocelot_mact_forget(struct ocelot *ocelot, 89 const unsigned char mac[ETH_ALEN], unsigned int vid); 90 struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); 91 int ocelot_netdev_to_port(struct net_device *dev); 92 93 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg); 94 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg); 95 96 int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, 97 struct device_node *portnp); 98 void ocelot_release_port(struct ocelot_port *ocelot_port); 99 int ocelot_devlink_init(struct ocelot *ocelot); 100 void ocelot_devlink_teardown(struct ocelot *ocelot); 101 int ocelot_port_devlink_init(struct ocelot *ocelot, int port, 102 enum devlink_port_flavour flavour); 103 void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port); 104 105 extern struct notifier_block ocelot_netdevice_nb; 106 extern struct notifier_block ocelot_switchdev_nb; 107 extern struct notifier_block ocelot_switchdev_blocking_nb; 108 extern const struct devlink_ops ocelot_devlink_ops; 109 110 #endif 111