1a556c76aSAlexandre Belloni /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ 2a556c76aSAlexandre Belloni /* 3a556c76aSAlexandre Belloni * Microsemi Ocelot Switch driver 4a556c76aSAlexandre Belloni * 5a556c76aSAlexandre Belloni * Copyright (c) 2017 Microsemi Corporation 6a556c76aSAlexandre Belloni */ 7a556c76aSAlexandre Belloni 8a556c76aSAlexandre Belloni #ifndef _MSCC_OCELOT_H_ 9a556c76aSAlexandre Belloni #define _MSCC_OCELOT_H_ 10a556c76aSAlexandre Belloni 11a556c76aSAlexandre Belloni #include <linux/bitops.h> 12a556c76aSAlexandre Belloni #include <linux/etherdevice.h> 13a556c76aSAlexandre Belloni #include <linux/if_vlan.h> 144e3b0468SAntoine Tenart #include <linux/net_tstamp.h> 1571e32a20SQuentin Schulz #include <linux/phy.h> 1671e32a20SQuentin Schulz #include <linux/phy/phy.h> 17a556c76aSAlexandre Belloni #include <linux/platform_device.h> 18a556c76aSAlexandre Belloni #include <linux/regmap.h> 19a556c76aSAlexandre Belloni 20964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_qsys.h> 21a030dfe1SVladimir Oltean #include <soc/mscc/ocelot_sys.h> 22964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_dev.h> 23964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_ana.h> 242b49d128SYangbo Lu #include <soc/mscc/ocelot_ptp.h> 255e256365SVladimir Oltean #include <soc/mscc/ocelot.h> 26a556c76aSAlexandre Belloni #include "ocelot_rew.h" 27a556c76aSAlexandre Belloni #include "ocelot_qs.h" 28a556c76aSAlexandre Belloni 29a556c76aSAlexandre Belloni #define OCELOT_BUFFER_CELL_SZ 60 30a556c76aSAlexandre Belloni 31a556c76aSAlexandre Belloni #define OCELOT_STATS_CHECK_DELAY (2 * HZ) 32a556c76aSAlexandre Belloni 334e3b0468SAntoine Tenart #define OCELOT_PTP_QUEUE_SZ 128 344e3b0468SAntoine Tenart 35a556c76aSAlexandre Belloni struct frame_info { 36a556c76aSAlexandre Belloni u32 len; 37a556c76aSAlexandre Belloni u16 port; 38a556c76aSAlexandre Belloni u16 vid; 39a556c76aSAlexandre Belloni u8 tag_type; 404e3b0468SAntoine Tenart u16 rew_op; 414e3b0468SAntoine Tenart u32 timestamp; /* rew_val */ 42a556c76aSAlexandre Belloni }; 43a556c76aSAlexandre Belloni 44a556c76aSAlexandre Belloni struct ocelot_multicast { 45a556c76aSAlexandre Belloni struct list_head list; 46a556c76aSAlexandre Belloni unsigned char addr[ETH_ALEN]; 47a556c76aSAlexandre Belloni u16 vid; 48a556c76aSAlexandre Belloni u16 ports; 499403c158SVladimir Oltean int pgid; 50a556c76aSAlexandre Belloni }; 51a556c76aSAlexandre Belloni 529c90eea3SVladimir Oltean struct ocelot_port_tc { 539c90eea3SVladimir Oltean bool block_shared; 549c90eea3SVladimir Oltean unsigned long offload_cnt; 559c90eea3SVladimir Oltean 569c90eea3SVladimir Oltean unsigned long police_id; 579c90eea3SVladimir Oltean }; 589c90eea3SVladimir Oltean 59004d44f6SVladimir Oltean struct ocelot_port_private { 60004d44f6SVladimir Oltean struct ocelot_port port; 61004d44f6SVladimir Oltean struct net_device *dev; 62004d44f6SVladimir Oltean struct phy_device *phy; 63004d44f6SVladimir Oltean u8 chip_port; 64004d44f6SVladimir Oltean 6571e32a20SQuentin Schulz struct phy *serdes; 662c1d029aSJoergen Andreasen 672c1d029aSJoergen Andreasen struct ocelot_port_tc tc; 684e3b0468SAntoine Tenart }; 694e3b0468SAntoine Tenart 709c90eea3SVladimir Oltean struct ocelot_dump_ctx { 719c90eea3SVladimir Oltean struct net_device *dev; 729c90eea3SVladimir Oltean struct sk_buff *skb; 739c90eea3SVladimir Oltean struct netlink_callback *cb; 749c90eea3SVladimir Oltean int idx; 759c90eea3SVladimir Oltean }; 769c90eea3SVladimir Oltean 779c90eea3SVladimir Oltean /* MAC table entry types. 789c90eea3SVladimir Oltean * ENTRYTYPE_NORMAL is subject to aging. 799c90eea3SVladimir Oltean * ENTRYTYPE_LOCKED is not subject to aging. 809c90eea3SVladimir Oltean * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast. 819c90eea3SVladimir Oltean * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast. 829c90eea3SVladimir Oltean */ 839c90eea3SVladimir Oltean enum macaccess_entry_type { 849c90eea3SVladimir Oltean ENTRYTYPE_NORMAL = 0, 859c90eea3SVladimir Oltean ENTRYTYPE_LOCKED, 869c90eea3SVladimir Oltean ENTRYTYPE_MACv4, 879c90eea3SVladimir Oltean ENTRYTYPE_MACv6, 889c90eea3SVladimir Oltean }; 899c90eea3SVladimir Oltean 909c90eea3SVladimir Oltean int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, 919c90eea3SVladimir Oltean bool is_static, void *data); 929c90eea3SVladimir Oltean int ocelot_mact_learn(struct ocelot *ocelot, int port, 939c90eea3SVladimir Oltean const unsigned char mac[ETH_ALEN], 949c90eea3SVladimir Oltean unsigned int vid, enum macaccess_entry_type type); 959c90eea3SVladimir Oltean int ocelot_mact_forget(struct ocelot *ocelot, 969c90eea3SVladimir Oltean const unsigned char mac[ETH_ALEN], unsigned int vid); 979c90eea3SVladimir Oltean int ocelot_port_lag_join(struct ocelot *ocelot, int port, 989c90eea3SVladimir Oltean struct net_device *bond); 999c90eea3SVladimir Oltean void ocelot_port_lag_leave(struct ocelot *ocelot, int port, 1009c90eea3SVladimir Oltean struct net_device *bond); 1019c90eea3SVladimir Oltean 102a556c76aSAlexandre Belloni u32 ocelot_port_readl(struct ocelot_port *port, u32 reg); 103a556c76aSAlexandre Belloni void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg); 104a556c76aSAlexandre Belloni 105a556c76aSAlexandre Belloni #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val)) 106a556c76aSAlexandre Belloni #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val)) 107a556c76aSAlexandre Belloni 10891c724cfSVladimir Oltean int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, 109a556c76aSAlexandre Belloni struct phy_device *phy); 110a556c76aSAlexandre Belloni 11121468199SVladimir Oltean void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu, 11221468199SVladimir Oltean enum ocelot_tag_prefix injection, 11321468199SVladimir Oltean enum ocelot_tag_prefix extraction); 11421468199SVladimir Oltean 115a556c76aSAlexandre Belloni extern struct notifier_block ocelot_netdevice_nb; 11656da64bcSFlorian Fainelli extern struct notifier_block ocelot_switchdev_nb; 1170e332c85SPetr Machata extern struct notifier_block ocelot_switchdev_blocking_nb; 118a556c76aSAlexandre Belloni 1195e256365SVladimir Oltean #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val)) 1205e256365SVladimir Oltean #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val)) 1214e3b0468SAntoine Tenart 122a556c76aSAlexandre Belloni #endif 123