1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
2 /* Copyright (c) 2017 Microsemi Corporation
5 #ifndef _SOC_MSCC_OCELOT_H
6 #define _SOC_MSCC_OCELOT_H
8 #include <linux/ptp_clock_kernel.h>
9 #include <linux/net_tstamp.h>
10 #include <linux/if_vlan.h>
11 #include <linux/regmap.h>
14 /* Port Group IDs (PGID) are masks of destination ports.
16 * For L2 forwarding, the switch performs 3 lookups in the PGID table for each
17 * frame, and forwards the frame to the ports that are present in the logical
20 * These PGID lookups are:
21 * - In one of PGID[0-63]: for the destination masks. There are 2 paths by
22 * which the switch selects a destination PGID:
23 * - The {DMAC, VID} is present in the MAC table. In that case, the
24 * destination PGID is given by the DEST_IDX field of the MAC table entry
26 * - The {DMAC, VID} is not present in the MAC table (it is unknown). The
27 * frame is disseminated as being either unicast, multicast or broadcast,
28 * and according to that, the destination PGID is chosen as being the
29 * value contained by ANA_FLOODING_FLD_UNICAST,
30 * ANA_FLOODING_FLD_MULTICAST or ANA_FLOODING_FLD_BROADCAST.
31 * The destination PGID can be an unicast set: the first PGIDs, 0 to
32 * ocelot->num_phys_ports - 1, or a multicast set: the PGIDs from
33 * ocelot->num_phys_ports to 63. By convention, a unicast PGID corresponds to
34 * a physical port and has a single bit set in the destination ports mask:
35 * that corresponding to the port number itself. In contrast, a multicast
36 * PGID will have potentially more than one single bit set in the destination
38 * - In one of PGID[64-79]: for the aggregation mask. The switch classifier
39 * dissects each frame and generates a 4-bit Link Aggregation Code which is
40 * used for this second PGID table lookup. The goal of link aggregation is to
41 * hash multiple flows within the same LAG on to different destination ports.
42 * The first lookup will result in a PGID with all the LAG members present in
43 * the destination ports mask, and the second lookup, by Link Aggregation
44 * Code, will ensure that each flow gets forwarded only to a single port out
45 * of that mask (there are no duplicates).
46 * - In one of PGID[80-90]: for the source mask. The third time, the PGID table
47 * is indexed with the ingress port (plus 80). These PGIDs answer the
48 * question "is port i allowed to forward traffic to port j?" If yes, then
49 * BIT(j) of PGID 80+i will be found set. The third PGID lookup can be used
50 * to enforce the L2 forwarding matrix imposed by e.g. a Linux bridge.
53 /* Reserve some destination PGIDs at the end of the range:
54 * PGID_BLACKHOLE: used for not forwarding the frames
55 * PGID_CPU: used for whitelisting certain MAC addresses, such as the addresses
56 * of the switch port net devices, towards the CPU port module.
57 * PGID_UC: the flooding destinations for unknown unicast traffic.
58 * PGID_MC: the flooding destinations for non-IP multicast traffic.
59 * PGID_MCIPV4: the flooding destinations for IPv4 multicast traffic.
60 * PGID_MCIPV6: the flooding destinations for IPv6 multicast traffic.
61 * PGID_BC: the flooding destinations for broadcast traffic.
63 #define PGID_BLACKHOLE 57
67 #define PGID_MCIPV4 61
68 #define PGID_MCIPV6 62
71 #define for_each_unicast_dest_pgid(ocelot, pgid) \
73 (pgid) < (ocelot)->num_phys_ports; \
76 #define for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) \
77 for ((pgid) = (ocelot)->num_phys_ports + 1; \
78 (pgid) < PGID_BLACKHOLE; \
81 #define for_each_aggr_pgid(ocelot, pgid) \
82 for ((pgid) = PGID_AGGR; \
86 /* Aggregation PGIDs, one per Link Aggregation Code */
89 /* Source PGIDs, one per physical port */
92 #define OCELOT_NUM_TC 8
94 #define OCELOT_SPEED_2500 0
95 #define OCELOT_SPEED_1000 1
96 #define OCELOT_SPEED_100 2
97 #define OCELOT_SPEED_10 3
99 #define OCELOT_PTP_PINS_NUM 4
101 #define TARGET_OFFSET 24
102 #define REG_MASK GENMASK(TARGET_OFFSET - 1, 0)
103 #define REG(reg, offset) [reg & REG_MASK] = offset
105 #define REG_RESERVED_ADDR 0xffffffff
106 #define REG_RESERVED(reg) REG(reg, REG_RESERVED_ADDR)
108 #define for_each_stat(ocelot, stat) \
109 for ((stat) = (ocelot)->stats_layout; \
110 ((stat)->name[0] != '\0'); \
131 ANA_ADVLEARN = ANA << TARGET_OFFSET,
136 ANA_STORMLIMIT_BURST,
155 ANA_TABLES_STREAMDATA,
156 ANA_TABLES_MACACCESS,
158 ANA_TABLES_VLANACCESS,
160 ANA_TABLES_ISDXACCESS,
163 ANA_TABLES_PTP_ID_HIGH,
164 ANA_TABLES_PTP_ID_LOW,
165 ANA_TABLES_STREAMACCESS,
166 ANA_TABLES_STREAMTIDX,
167 ANA_TABLES_SEQ_HISTORY,
169 ANA_TABLES_SFID_MASK,
170 ANA_TABLES_SFIDACCESS,
180 ANA_SG_GCL_GS_CONFIG,
181 ANA_SG_GCL_TI_CONFIG,
189 ANA_PORT_VCAP_S1_KEY_CFG,
190 ANA_PORT_VCAP_S2_CFG,
191 ANA_PORT_PCP_DEI_MAP,
192 ANA_PORT_CPU_FWD_CFG,
193 ANA_PORT_CPU_FWD_BPDU_CFG,
194 ANA_PORT_CPU_FWD_GARP_CFG,
195 ANA_PORT_CPU_FWD_CCM_CFG,
199 ANA_PORT_PTP_DLY1_CFG,
200 ANA_PORT_PTP_DLY2_CFG,
214 ANA_VCAP_RNG_TYPE_CFG,
215 ANA_VCAP_RNG_VAL_CFG,
230 QS_XTR_GRP_CFG = QS << TARGET_OFFSET,
242 QSYS_PORT_MODE = QSYS << TARGET_OFFSET,
243 QSYS_SWITCH_PORT_MODE,
255 QSYS_TIMED_FRAME_ENTRY,
258 QSYS_TFRM_TIMER_CFG_1,
259 QSYS_TFRM_TIMER_CFG_2,
260 QSYS_TFRM_TIMER_CFG_3,
261 QSYS_TFRM_TIMER_CFG_4,
262 QSYS_TFRM_TIMER_CFG_5,
263 QSYS_TFRM_TIMER_CFG_6,
264 QSYS_TFRM_TIMER_CFG_7,
265 QSYS_TFRM_TIMER_CFG_8,
293 QSYS_TAS_PARAM_CFG_CTRL,
295 QSYS_PARAM_CFG_REG_1,
296 QSYS_PARAM_CFG_REG_2,
297 QSYS_PARAM_CFG_REG_3,
298 QSYS_PARAM_CFG_REG_4,
299 QSYS_PARAM_CFG_REG_5,
302 QSYS_PARAM_STATUS_REG_1,
303 QSYS_PARAM_STATUS_REG_2,
304 QSYS_PARAM_STATUS_REG_3,
305 QSYS_PARAM_STATUS_REG_4,
306 QSYS_PARAM_STATUS_REG_5,
307 QSYS_PARAM_STATUS_REG_6,
308 QSYS_PARAM_STATUS_REG_7,
309 QSYS_PARAM_STATUS_REG_8,
310 QSYS_PARAM_STATUS_REG_9,
311 QSYS_GCL_STATUS_REG_1,
312 QSYS_GCL_STATUS_REG_2,
313 REW_PORT_VLAN_CFG = REW << TARGET_OFFSET,
317 REW_PCP_DEI_QOS_MAP_CFG,
321 REW_DSCP_REMAP_DP1_CFG,
326 SYS_COUNT_RX_OCTETS = SYS << TARGET_OFFSET,
327 SYS_COUNT_RX_UNICAST,
328 SYS_COUNT_RX_MULTICAST,
329 SYS_COUNT_RX_BROADCAST,
331 SYS_COUNT_RX_FRAGMENTS,
332 SYS_COUNT_RX_JABBERS,
333 SYS_COUNT_RX_CRC_ALIGN_ERRS,
334 SYS_COUNT_RX_SYM_ERRS,
337 SYS_COUNT_RX_128_255,
338 SYS_COUNT_RX_256_1023,
339 SYS_COUNT_RX_1024_1526,
340 SYS_COUNT_RX_1527_MAX,
342 SYS_COUNT_RX_CONTROL,
344 SYS_COUNT_RX_CLASSIFIED_DROPS,
346 SYS_COUNT_TX_UNICAST,
347 SYS_COUNT_TX_MULTICAST,
348 SYS_COUNT_TX_BROADCAST,
349 SYS_COUNT_TX_COLLISION,
354 SYS_COUNT_TX_128_511,
355 SYS_COUNT_TX_512_1023,
356 SYS_COUNT_TX_1024_1526,
357 SYS_COUNT_TX_1527_MAX,
368 SYS_REW_MAC_HIGH_CFG,
370 SYS_TIMESTAMP_OFFSET,
392 PTP_PIN_CFG = PTP << TARGET_OFFSET,
396 PTP_PIN_WF_HIGH_PERIOD,
397 PTP_PIN_WF_LOW_PERIOD,
400 PTP_CLK_CFG_ADJ_FREQ,
401 GCB_SOFT_RST = GCB << TARGET_OFFSET,
405 DEV_CLOCK_CFG = DEV_GMII << TARGET_OFFSET,
420 DEV_MAC_FC_MAC_LOW_CFG,
421 DEV_MAC_FC_MAC_HIGH_CFG,
432 PCS1G_ANEG_NP_STATUS,
438 PCS1G_LPI_WAKE_ERROR_CNT,
440 PCS1G_TSTPAT_MODE_CFG,
443 DEV_PCS_FX100_STATUS,
446 enum ocelot_regfield {
447 ANA_ADVLEARN_VLAN_CHK,
448 ANA_ADVLEARN_LEARN_MIRROR,
449 ANA_ANEVENTS_FLOOD_DISCARD,
450 ANA_ANEVENTS_MSTI_DROP,
451 ANA_ANEVENTS_ACLKILL,
452 ANA_ANEVENTS_ACLUSED,
453 ANA_ANEVENTS_AUTOAGE,
454 ANA_ANEVENTS_VS2TTL1,
455 ANA_ANEVENTS_STORM_DROP,
456 ANA_ANEVENTS_LEARN_DROP,
457 ANA_ANEVENTS_AGED_ENTRY,
458 ANA_ANEVENTS_CPU_LEARN_FAILED,
459 ANA_ANEVENTS_AUTO_LEARN_FAILED,
460 ANA_ANEVENTS_LEARN_REMOVE,
461 ANA_ANEVENTS_AUTO_LEARNED,
462 ANA_ANEVENTS_AUTO_MOVED,
463 ANA_ANEVENTS_DROPPED,
464 ANA_ANEVENTS_CLASSIFIED_DROP,
465 ANA_ANEVENTS_CLASSIFIED_COPY,
466 ANA_ANEVENTS_VLAN_DISCARD,
467 ANA_ANEVENTS_FWD_DISCARD,
468 ANA_ANEVENTS_MULTICAST_FLOOD,
469 ANA_ANEVENTS_UNICAST_FLOOD,
470 ANA_ANEVENTS_DEST_KNOWN,
471 ANA_ANEVENTS_BUCKET3_MATCH,
472 ANA_ANEVENTS_BUCKET2_MATCH,
473 ANA_ANEVENTS_BUCKET1_MATCH,
474 ANA_ANEVENTS_BUCKET0_MATCH,
475 ANA_ANEVENTS_CPU_OPERATION,
476 ANA_ANEVENTS_DMAC_LOOKUP,
477 ANA_ANEVENTS_SMAC_LOOKUP,
478 ANA_ANEVENTS_SEQ_GEN_ERR_0,
479 ANA_ANEVENTS_SEQ_GEN_ERR_1,
480 ANA_TABLES_MACACCESS_B_DOM,
481 ANA_TABLES_MACTINDX_BUCKET,
482 ANA_TABLES_MACTINDX_M_INDEX,
483 QSYS_SWITCH_PORT_MODE_PORT_ENA,
484 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG,
485 QSYS_SWITCH_PORT_MODE_YEL_RSRVD,
486 QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE,
487 QSYS_SWITCH_PORT_MODE_TX_PFC_ENA,
488 QSYS_SWITCH_PORT_MODE_TX_PFC_MODE,
489 QSYS_TIMED_FRAME_ENTRY_TFRM_VLD,
490 QSYS_TIMED_FRAME_ENTRY_TFRM_FP,
491 QSYS_TIMED_FRAME_ENTRY_TFRM_PORTNO,
492 QSYS_TIMED_FRAME_ENTRY_TFRM_TM_SEL,
493 QSYS_TIMED_FRAME_ENTRY_TFRM_TM_T,
494 SYS_PORT_MODE_DATA_WO_TS,
495 SYS_PORT_MODE_INCL_INJ_HDR,
496 SYS_PORT_MODE_INCL_XTR_HDR,
497 SYS_PORT_MODE_INCL_HDR_ERR,
498 SYS_RESET_CFG_CORE_ENA,
499 SYS_RESET_CFG_MEM_ENA,
500 SYS_RESET_CFG_MEM_INIT,
501 GCB_SOFT_RST_SWC_RST,
502 GCB_MIIM_MII_STATUS_PENDING,
503 GCB_MIIM_MII_STATUS_BUSY,
504 SYS_PAUSE_CFG_PAUSE_START,
505 SYS_PAUSE_CFG_PAUSE_STOP,
506 SYS_PAUSE_CFG_PAUSE_ENA,
512 VCAP_CORE_UPDATE_CTRL,
514 /* VCAP_CORE_CACHE */
515 VCAP_CACHE_ENTRY_DAT,
517 VCAP_CACHE_ACTION_DAT,
522 VCAP_CONST_ENTRY_WIDTH,
523 VCAP_CONST_ENTRY_CNT,
524 VCAP_CONST_ENTRY_SWCNT,
525 VCAP_CONST_ENTRY_TG_WIDTH,
526 VCAP_CONST_ACTION_DEF_CNT,
527 VCAP_CONST_ACTION_WIDTH,
528 VCAP_CONST_CNT_WIDTH,
533 enum ocelot_ptp_pins {
541 struct ocelot_stat_layout {
543 char name[ETH_GSTRING_LEN];
546 #define OCELOT_STAT_END { .name = "" }
548 struct ocelot_stats_region {
549 struct list_head node;
555 enum ocelot_tag_prefix {
556 OCELOT_TAG_PREFIX_DISABLED = 0,
557 OCELOT_TAG_PREFIX_NONE,
558 OCELOT_TAG_PREFIX_SHORT,
559 OCELOT_TAG_PREFIX_LONG,
565 struct net_device *(*port_to_netdev)(struct ocelot *ocelot, int port);
566 int (*netdev_to_port)(struct net_device *dev);
567 int (*reset)(struct ocelot *ocelot);
568 u16 (*wm_enc)(u16 value);
569 u16 (*wm_dec)(u16 value);
570 void (*wm_stat)(u32 val, u32 *inuse, u32 *maxuse);
571 void (*psfp_init)(struct ocelot *ocelot);
572 int (*psfp_filter_add)(struct ocelot *ocelot, int port,
573 struct flow_cls_offload *f);
574 int (*psfp_filter_del)(struct ocelot *ocelot, struct flow_cls_offload *f);
575 int (*psfp_stats_get)(struct ocelot *ocelot, struct flow_cls_offload *f,
576 struct flow_stats *stats);
577 void (*cut_through_fwd)(struct ocelot *ocelot);
578 void (*tas_clock_adjust)(struct ocelot *ocelot);
581 struct ocelot_vcap_policer {
582 struct list_head pol_list;
589 struct ocelot_vcap_block {
590 struct list_head rules;
594 struct ocelot_bridge_vlan {
596 unsigned long portmask;
597 unsigned long untagged;
598 struct list_head list;
601 enum ocelot_port_tag_config {
602 /* all VLANs are egress-untagged */
603 OCELOT_PORT_TAG_DISABLED = 0,
604 /* all VLANs except the native VLAN and VID 0 are egress-tagged */
605 OCELOT_PORT_TAG_NATIVE = 1,
606 /* all VLANs except VID 0 are egress-tagged */
607 OCELOT_PORT_TAG_TRUNK_NO_VID0 = 2,
608 /* all VLANs are egress-tagged */
609 OCELOT_PORT_TAG_TRUNK = 3,
612 struct ocelot_psfp_list {
613 struct list_head stream_list;
614 struct list_head sfi_list;
615 struct list_head sgi_list;
624 enum ocelot_sb_pool {
630 /* MAC table entry types.
631 * ENTRYTYPE_NORMAL is subject to aging.
632 * ENTRYTYPE_LOCKED is not subject to aging.
633 * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
634 * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
636 enum macaccess_entry_type {
637 ENTRYTYPE_NORMAL = 0,
643 #define OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION BIT(0)
644 #define OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP BIT(1)
646 struct ocelot_lag_fdb {
647 unsigned char addr[ETH_ALEN];
649 struct net_device *bond;
650 struct list_head list;
653 struct ocelot_mirror {
661 struct ocelot *ocelot;
663 struct regmap *target;
665 struct net_device *bond;
666 struct net_device *bridge;
668 struct ocelot_port *dsa_8021q_cpu;
670 /* VLAN that untagged frames are classified to, on ingress */
671 const struct ocelot_bridge_vlan *pvid_vlan;
673 struct tc_taprio_qopt_offload *taprio;
675 phy_interface_t phy_mode;
677 unsigned int ptp_skbs_in_flight;
678 struct sk_buff_head tx_skbs;
689 bool is_dsa_8021q_cpu;
701 struct devlink *devlink;
702 struct devlink_port *devlink_ports;
704 const struct ocelot_ops *ops;
705 struct regmap *targets[TARGET_MAX];
706 struct regmap_field *regfields[REGFIELD_MAX];
707 const u32 *const *map;
708 const struct ocelot_stat_layout *stats_layout;
709 struct list_head stats_regions;
710 unsigned int num_stats;
712 u32 pool_size[OCELOT_SB_NUM][OCELOT_SB_POOL_NUM];
713 int packet_buffer_size;
717 struct ocelot_port **ports;
719 u8 base_mac[ETH_ALEN];
721 struct list_head vlans;
722 struct list_head traps;
723 struct list_head lag_fdbs;
725 /* Switches like VSC9959 have flooding per traffic class */
726 int num_flooding_pgids;
728 /* In tables like ANA:PORT and the ANA:PGID:PGID mask,
729 * the CPU is located after the physical ports (at the
730 * num_phys_ports index).
736 enum ocelot_tag_prefix npi_inj_prefix;
737 enum ocelot_tag_prefix npi_xtr_prefix;
739 unsigned long bridges;
741 struct list_head multicast;
742 struct list_head pgids;
744 struct list_head dummy_rules;
745 struct ocelot_vcap_block block[3];
746 struct ocelot_vcap_policer vcap_pol;
747 struct vcap_props *vcap;
748 struct ocelot_mirror *mirror;
750 struct ocelot_psfp_list psfp;
752 /* Workqueue to check statistics for overflow with its lock */
753 struct mutex stats_lock;
755 struct delayed_work stats_work;
756 struct workqueue_struct *stats_queue;
758 /* Lock for serializing access to the MAC table */
759 struct mutex mact_lock;
760 /* Lock for serializing forwarding domain changes */
761 struct mutex fwd_domain_lock;
763 /* Lock for serializing Time-Aware Shaper changes */
764 struct mutex tas_lock;
766 struct workqueue_struct *owq;
769 struct ptp_clock *ptp_clock;
770 struct ptp_clock_info ptp_info;
771 struct hwtstamp_config hwtstamp_config;
772 unsigned int ptp_skbs_in_flight;
773 /* Protects the 2-step TX timestamp ID logic */
774 spinlock_t ts_id_lock;
775 /* Protects the PTP interface state */
776 struct mutex ptp_lock;
777 /* Protects the PTP clock */
778 spinlock_t ptp_clock_lock;
779 struct ptp_pin_desc ptp_pins[OCELOT_PTP_PINS_NUM];
781 struct ocelot_fdma *fdma;
784 struct ocelot_policer {
785 u32 rate; /* kilobit per second */
786 u32 burst; /* bytes */
789 #define ocelot_bulk_read_rix(ocelot, reg, ri, buf, count) \
790 __ocelot_bulk_read_ix(ocelot, reg, reg##_RSZ * (ri), buf, count)
792 #define ocelot_read_ix(ocelot, reg, gi, ri) \
793 __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
794 #define ocelot_read_gix(ocelot, reg, gi) \
795 __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
796 #define ocelot_read_rix(ocelot, reg, ri) \
797 __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
798 #define ocelot_read(ocelot, reg) \
799 __ocelot_read_ix(ocelot, reg, 0)
801 #define ocelot_write_ix(ocelot, val, reg, gi, ri) \
802 __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
803 #define ocelot_write_gix(ocelot, val, reg, gi) \
804 __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
805 #define ocelot_write_rix(ocelot, val, reg, ri) \
806 __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
807 #define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
809 #define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) \
810 __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
811 #define ocelot_rmw_gix(ocelot, val, m, reg, gi) \
812 __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
813 #define ocelot_rmw_rix(ocelot, val, m, reg, ri) \
814 __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
815 #define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
817 #define ocelot_field_write(ocelot, reg, val) \
818 regmap_field_write((ocelot)->regfields[(reg)], (val))
819 #define ocelot_field_read(ocelot, reg, val) \
820 regmap_field_read((ocelot)->regfields[(reg)], (val))
821 #define ocelot_fields_write(ocelot, id, reg, val) \
822 regmap_fields_write((ocelot)->regfields[(reg)], (id), (val))
823 #define ocelot_fields_read(ocelot, id, reg, val) \
824 regmap_fields_read((ocelot)->regfields[(reg)], (id), (val))
826 #define ocelot_target_read_ix(ocelot, target, reg, gi, ri) \
827 __ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
828 #define ocelot_target_read_gix(ocelot, target, reg, gi) \
829 __ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi))
830 #define ocelot_target_read_rix(ocelot, target, reg, ri) \
831 __ocelot_target_read_ix(ocelot, target, reg, reg##_RSZ * (ri))
832 #define ocelot_target_read(ocelot, target, reg) \
833 __ocelot_target_read_ix(ocelot, target, reg, 0)
835 #define ocelot_target_write_ix(ocelot, target, val, reg, gi, ri) \
836 __ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
837 #define ocelot_target_write_gix(ocelot, target, val, reg, gi) \
838 __ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi))
839 #define ocelot_target_write_rix(ocelot, target, val, reg, ri) \
840 __ocelot_target_write_ix(ocelot, target, val, reg, reg##_RSZ * (ri))
841 #define ocelot_target_write(ocelot, target, val, reg) \
842 __ocelot_target_write_ix(ocelot, target, val, reg, 0)
845 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
846 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
847 void ocelot_port_rmwl(struct ocelot_port *port, u32 val, u32 mask, u32 reg);
848 int __ocelot_bulk_read_ix(struct ocelot *ocelot, u32 reg, u32 offset, void *buf,
850 u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset);
851 void __ocelot_write_ix(struct ocelot *ocelot, u32 val, u32 reg, u32 offset);
852 void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask, u32 reg,
854 u32 __ocelot_target_read_ix(struct ocelot *ocelot, enum ocelot_target target,
855 u32 reg, u32 offset);
856 void __ocelot_target_write_ix(struct ocelot *ocelot, enum ocelot_target target,
857 u32 val, u32 reg, u32 offset);
860 bool ocelot_can_inject(struct ocelot *ocelot, int grp);
861 void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp,
862 u32 rew_op, struct sk_buff *skb);
863 void ocelot_ifh_port_set(void *ifh, int port, u32 rew_op, u32 vlan_tag);
864 int ocelot_xtr_poll_frame(struct ocelot *ocelot, int grp, struct sk_buff **skb);
865 void ocelot_drain_cpu_queue(struct ocelot *ocelot, int grp);
866 void ocelot_ptp_rx_timestamp(struct ocelot *ocelot, struct sk_buff *skb,
869 /* Hardware initialization */
870 int ocelot_regfields_init(struct ocelot *ocelot,
871 const struct reg_field *const regfields);
872 struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
873 int ocelot_init(struct ocelot *ocelot);
874 void ocelot_deinit(struct ocelot *ocelot);
875 void ocelot_init_port(struct ocelot *ocelot, int port);
876 void ocelot_deinit_port(struct ocelot *ocelot, int port);
878 void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port, int cpu);
879 void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port);
880 u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port);
883 void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
884 void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
885 int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
886 int ocelot_get_ts_info(struct ocelot *ocelot, int port,
887 struct ethtool_ts_info *info);
888 void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);
889 int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool enabled,
890 struct netlink_ext_ack *extack);
891 void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state);
892 u32 ocelot_get_bridge_fwd_mask(struct ocelot *ocelot, int src_port);
893 int ocelot_port_pre_bridge_flags(struct ocelot *ocelot, int port,
894 struct switchdev_brport_flags val);
895 void ocelot_port_bridge_flags(struct ocelot *ocelot, int port,
896 struct switchdev_brport_flags val);
897 int ocelot_port_get_default_prio(struct ocelot *ocelot, int port);
898 int ocelot_port_set_default_prio(struct ocelot *ocelot, int port, u8 prio);
899 int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp);
900 int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio);
901 int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio);
902 int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
903 struct net_device *bridge, int bridge_num,
904 struct netlink_ext_ack *extack);
905 void ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
906 struct net_device *bridge);
907 int ocelot_mact_flush(struct ocelot *ocelot, int port);
908 int ocelot_fdb_dump(struct ocelot *ocelot, int port,
909 dsa_fdb_dump_cb_t *cb, void *data);
910 int ocelot_fdb_add(struct ocelot *ocelot, int port, const unsigned char *addr,
911 u16 vid, const struct net_device *bridge);
912 int ocelot_fdb_del(struct ocelot *ocelot, int port, const unsigned char *addr,
913 u16 vid, const struct net_device *bridge);
914 int ocelot_lag_fdb_add(struct ocelot *ocelot, struct net_device *bond,
915 const unsigned char *addr, u16 vid,
916 const struct net_device *bridge);
917 int ocelot_lag_fdb_del(struct ocelot *ocelot, struct net_device *bond,
918 const unsigned char *addr, u16 vid,
919 const struct net_device *bridge);
920 int ocelot_vlan_prepare(struct ocelot *ocelot, int port, u16 vid, bool pvid,
921 bool untagged, struct netlink_ext_ack *extack);
922 int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
924 int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);
925 int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr);
926 int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);
927 int ocelot_port_txtstamp_request(struct ocelot *ocelot, int port,
929 struct sk_buff **clone);
930 void ocelot_get_txtstamp(struct ocelot *ocelot);
931 void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu);
932 int ocelot_get_max_mtu(struct ocelot *ocelot, int port);
933 int ocelot_port_policer_add(struct ocelot *ocelot, int port,
934 struct ocelot_policer *pol);
935 int ocelot_port_policer_del(struct ocelot *ocelot, int port);
936 int ocelot_port_mirror_add(struct ocelot *ocelot, int from, int to,
937 bool ingress, struct netlink_ext_ack *extack);
938 void ocelot_port_mirror_del(struct ocelot *ocelot, int from, bool ingress);
939 int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
940 struct flow_cls_offload *f, bool ingress);
941 int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
942 struct flow_cls_offload *f, bool ingress);
943 int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
944 struct flow_cls_offload *f, bool ingress);
945 int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
946 const struct switchdev_obj_port_mdb *mdb,
947 const struct net_device *bridge);
948 int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
949 const struct switchdev_obj_port_mdb *mdb,
950 const struct net_device *bridge);
951 int ocelot_port_lag_join(struct ocelot *ocelot, int port,
952 struct net_device *bond,
953 struct netdev_lag_upper_info *info);
954 void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
955 struct net_device *bond);
956 void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active);
958 int ocelot_devlink_sb_register(struct ocelot *ocelot);
959 void ocelot_devlink_sb_unregister(struct ocelot *ocelot);
960 int ocelot_sb_pool_get(struct ocelot *ocelot, unsigned int sb_index,
962 struct devlink_sb_pool_info *pool_info);
963 int ocelot_sb_pool_set(struct ocelot *ocelot, unsigned int sb_index,
964 u16 pool_index, u32 size,
965 enum devlink_sb_threshold_type threshold_type,
966 struct netlink_ext_ack *extack);
967 int ocelot_sb_port_pool_get(struct ocelot *ocelot, int port,
968 unsigned int sb_index, u16 pool_index,
970 int ocelot_sb_port_pool_set(struct ocelot *ocelot, int port,
971 unsigned int sb_index, u16 pool_index,
972 u32 threshold, struct netlink_ext_ack *extack);
973 int ocelot_sb_tc_pool_bind_get(struct ocelot *ocelot, int port,
974 unsigned int sb_index, u16 tc_index,
975 enum devlink_sb_pool_type pool_type,
976 u16 *p_pool_index, u32 *p_threshold);
977 int ocelot_sb_tc_pool_bind_set(struct ocelot *ocelot, int port,
978 unsigned int sb_index, u16 tc_index,
979 enum devlink_sb_pool_type pool_type,
980 u16 pool_index, u32 threshold,
981 struct netlink_ext_ack *extack);
982 int ocelot_sb_occ_snapshot(struct ocelot *ocelot, unsigned int sb_index);
983 int ocelot_sb_occ_max_clear(struct ocelot *ocelot, unsigned int sb_index);
984 int ocelot_sb_occ_port_pool_get(struct ocelot *ocelot, int port,
985 unsigned int sb_index, u16 pool_index,
986 u32 *p_cur, u32 *p_max);
987 int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port,
988 unsigned int sb_index, u16 tc_index,
989 enum devlink_sb_pool_type pool_type,
990 u32 *p_cur, u32 *p_max);
992 void ocelot_phylink_mac_link_down(struct ocelot *ocelot, int port,
993 unsigned int link_an_mode,
994 phy_interface_t interface,
995 unsigned long quirks);
996 void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port,
997 struct phy_device *phydev,
998 unsigned int link_an_mode,
999 phy_interface_t interface,
1000 int speed, int duplex,
1001 bool tx_pause, bool rx_pause,
1002 unsigned long quirks);
1004 int ocelot_mact_lookup(struct ocelot *ocelot, int *dst_idx,
1005 const unsigned char mac[ETH_ALEN],
1006 unsigned int vid, enum macaccess_entry_type *type);
1007 int ocelot_mact_learn_streamdata(struct ocelot *ocelot, int dst_idx,
1008 const unsigned char mac[ETH_ALEN],
1010 enum macaccess_entry_type type,
1011 int sfid, int ssid);
1013 int ocelot_migrate_mdbs(struct ocelot *ocelot, unsigned long from_mask,
1014 unsigned long to_mask);
1016 int ocelot_vcap_policer_add(struct ocelot *ocelot, u32 pol_ix,
1017 struct ocelot_policer *pol);
1018 int ocelot_vcap_policer_del(struct ocelot *ocelot, u32 pol_ix);
1020 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
1021 int ocelot_mrp_add(struct ocelot *ocelot, int port,
1022 const struct switchdev_obj_mrp *mrp);
1023 int ocelot_mrp_del(struct ocelot *ocelot, int port,
1024 const struct switchdev_obj_mrp *mrp);
1025 int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
1026 const struct switchdev_obj_ring_role_mrp *mrp);
1027 int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
1028 const struct switchdev_obj_ring_role_mrp *mrp);
1030 static inline int ocelot_mrp_add(struct ocelot *ocelot, int port,
1031 const struct switchdev_obj_mrp *mrp)
1036 static inline int ocelot_mrp_del(struct ocelot *ocelot, int port,
1037 const struct switchdev_obj_mrp *mrp)
1043 ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
1044 const struct switchdev_obj_ring_role_mrp *mrp)
1050 ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
1051 const struct switchdev_obj_ring_role_mrp *mrp)