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/ptp_clock_kernel.h>
19 #include <linux/regmap.h>
21 #include "ocelot_ana.h"
22 #include "ocelot_dev.h"
23 #include "ocelot_qsys.h"
24 #include "ocelot_rew.h"
25 #include "ocelot_sys.h"
26 #include "ocelot_qs.h"
27 #include "ocelot_tc.h"
28 #include "ocelot_ptp.h"
34 #define PGID_CPU (PGID_AGGR - 5)
35 #define PGID_UC (PGID_AGGR - 4)
36 #define PGID_MC (PGID_AGGR - 3)
37 #define PGID_MCIPV4 (PGID_AGGR - 2)
38 #define PGID_MCIPV6 (PGID_AGGR - 1)
40 #define OCELOT_BUFFER_CELL_SZ 60
42 #define OCELOT_STATS_CHECK_DELAY (2 * HZ)
44 #define OCELOT_PTP_QUEUE_SZ 128
52 u32 timestamp; /* rew_val */
55 #define IFH_INJ_BYPASS BIT(31)
56 #define IFH_INJ_POP_CNT_DISABLE (3 << 28)
58 #define IFH_TAG_TYPE_C 0
59 #define IFH_TAG_TYPE_S 1
61 #define IFH_REW_OP_NOOP 0x0
62 #define IFH_REW_OP_DSCP 0x1
63 #define IFH_REW_OP_ONE_STEP_PTP 0x2
64 #define IFH_REW_OP_TWO_STEP_PTP 0x3
65 #define IFH_REW_OP_ORIGIN_PTP 0x5
67 #define OCELOT_TAG_LEN 16
68 #define OCELOT_SHORT_PREFIX_LEN 4
69 #define OCELOT_LONG_PREFIX_LEN 16
71 #define OCELOT_SPEED_2500 0
72 #define OCELOT_SPEED_1000 1
73 #define OCELOT_SPEED_100 2
74 #define OCELOT_SPEED_10 3
76 #define TARGET_OFFSET 24
77 #define REG_MASK GENMASK(TARGET_OFFSET - 1, 0)
78 #define REG(reg, offset) [reg & REG_MASK] = offset
93 ANA_ADVLEARN = ANA << TARGET_OFFSET,
117 ANA_TABLES_STREAMDATA,
118 ANA_TABLES_MACACCESS,
120 ANA_TABLES_VLANACCESS,
122 ANA_TABLES_ISDXACCESS,
125 ANA_TABLES_PTP_ID_HIGH,
126 ANA_TABLES_PTP_ID_LOW,
127 ANA_TABLES_STREAMACCESS,
128 ANA_TABLES_STREAMTIDX,
129 ANA_TABLES_SEQ_HISTORY,
131 ANA_TABLES_SFID_MASK,
132 ANA_TABLES_SFIDACCESS,
142 ANA_SG_GCL_GS_CONFIG,
143 ANA_SG_GCL_TI_CONFIG,
151 ANA_PORT_VCAP_S1_KEY_CFG,
152 ANA_PORT_VCAP_S2_CFG,
153 ANA_PORT_PCP_DEI_MAP,
154 ANA_PORT_CPU_FWD_CFG,
155 ANA_PORT_CPU_FWD_BPDU_CFG,
156 ANA_PORT_CPU_FWD_GARP_CFG,
157 ANA_PORT_CPU_FWD_CCM_CFG,
161 ANA_PORT_PTP_DLY1_CFG,
162 ANA_PORT_PTP_DLY2_CFG,
176 ANA_VCAP_RNG_TYPE_CFG,
177 ANA_VCAP_RNG_VAL_CFG,
192 QS_XTR_GRP_CFG = QS << TARGET_OFFSET,
204 QSYS_PORT_MODE = QSYS << TARGET_OFFSET,
205 QSYS_SWITCH_PORT_MODE,
217 QSYS_TIMED_FRAME_ENTRY,
220 QSYS_TFRM_TIMER_CFG_1,
221 QSYS_TFRM_TIMER_CFG_2,
222 QSYS_TFRM_TIMER_CFG_3,
223 QSYS_TFRM_TIMER_CFG_4,
224 QSYS_TFRM_TIMER_CFG_5,
225 QSYS_TFRM_TIMER_CFG_6,
226 QSYS_TFRM_TIMER_CFG_7,
227 QSYS_TFRM_TIMER_CFG_8,
255 QSYS_TAS_PARAM_CFG_CTRL,
257 QSYS_PARAM_CFG_REG_1,
258 QSYS_PARAM_CFG_REG_2,
259 QSYS_PARAM_CFG_REG_3,
260 QSYS_PARAM_CFG_REG_4,
261 QSYS_PARAM_CFG_REG_5,
264 QSYS_PARAM_STATUS_REG_1,
265 QSYS_PARAM_STATUS_REG_2,
266 QSYS_PARAM_STATUS_REG_3,
267 QSYS_PARAM_STATUS_REG_4,
268 QSYS_PARAM_STATUS_REG_5,
269 QSYS_PARAM_STATUS_REG_6,
270 QSYS_PARAM_STATUS_REG_7,
271 QSYS_PARAM_STATUS_REG_8,
272 QSYS_PARAM_STATUS_REG_9,
273 QSYS_GCL_STATUS_REG_1,
274 QSYS_GCL_STATUS_REG_2,
275 REW_PORT_VLAN_CFG = REW << TARGET_OFFSET,
279 REW_PCP_DEI_QOS_MAP_CFG,
283 REW_DSCP_REMAP_DP1_CFG,
288 SYS_COUNT_RX_OCTETS = SYS << TARGET_OFFSET,
289 SYS_COUNT_RX_UNICAST,
290 SYS_COUNT_RX_MULTICAST,
291 SYS_COUNT_RX_BROADCAST,
293 SYS_COUNT_RX_FRAGMENTS,
294 SYS_COUNT_RX_JABBERS,
295 SYS_COUNT_RX_CRC_ALIGN_ERRS,
296 SYS_COUNT_RX_SYM_ERRS,
299 SYS_COUNT_RX_128_255,
300 SYS_COUNT_RX_256_1023,
301 SYS_COUNT_RX_1024_1526,
302 SYS_COUNT_RX_1527_MAX,
304 SYS_COUNT_RX_CONTROL,
306 SYS_COUNT_RX_CLASSIFIED_DROPS,
308 SYS_COUNT_TX_UNICAST,
309 SYS_COUNT_TX_MULTICAST,
310 SYS_COUNT_TX_BROADCAST,
311 SYS_COUNT_TX_COLLISION,
316 SYS_COUNT_TX_128_511,
317 SYS_COUNT_TX_512_1023,
318 SYS_COUNT_TX_1024_1526,
319 SYS_COUNT_TX_1527_MAX,
330 SYS_REW_MAC_HIGH_CFG,
332 SYS_TIMESTAMP_OFFSET,
354 S2_CORE_UPDATE_CTRL = S2 << TARGET_OFFSET,
361 PTP_PIN_CFG = PTP << TARGET_OFFSET,
367 PTP_CLK_CFG_ADJ_FREQ,
370 enum ocelot_regfield {
371 ANA_ADVLEARN_VLAN_CHK,
372 ANA_ADVLEARN_LEARN_MIRROR,
373 ANA_ANEVENTS_FLOOD_DISCARD,
374 ANA_ANEVENTS_MSTI_DROP,
375 ANA_ANEVENTS_ACLKILL,
376 ANA_ANEVENTS_ACLUSED,
377 ANA_ANEVENTS_AUTOAGE,
378 ANA_ANEVENTS_VS2TTL1,
379 ANA_ANEVENTS_STORM_DROP,
380 ANA_ANEVENTS_LEARN_DROP,
381 ANA_ANEVENTS_AGED_ENTRY,
382 ANA_ANEVENTS_CPU_LEARN_FAILED,
383 ANA_ANEVENTS_AUTO_LEARN_FAILED,
384 ANA_ANEVENTS_LEARN_REMOVE,
385 ANA_ANEVENTS_AUTO_LEARNED,
386 ANA_ANEVENTS_AUTO_MOVED,
387 ANA_ANEVENTS_DROPPED,
388 ANA_ANEVENTS_CLASSIFIED_DROP,
389 ANA_ANEVENTS_CLASSIFIED_COPY,
390 ANA_ANEVENTS_VLAN_DISCARD,
391 ANA_ANEVENTS_FWD_DISCARD,
392 ANA_ANEVENTS_MULTICAST_FLOOD,
393 ANA_ANEVENTS_UNICAST_FLOOD,
394 ANA_ANEVENTS_DEST_KNOWN,
395 ANA_ANEVENTS_BUCKET3_MATCH,
396 ANA_ANEVENTS_BUCKET2_MATCH,
397 ANA_ANEVENTS_BUCKET1_MATCH,
398 ANA_ANEVENTS_BUCKET0_MATCH,
399 ANA_ANEVENTS_CPU_OPERATION,
400 ANA_ANEVENTS_DMAC_LOOKUP,
401 ANA_ANEVENTS_SMAC_LOOKUP,
402 ANA_ANEVENTS_SEQ_GEN_ERR_0,
403 ANA_ANEVENTS_SEQ_GEN_ERR_1,
404 ANA_TABLES_MACACCESS_B_DOM,
405 ANA_TABLES_MACTINDX_BUCKET,
406 ANA_TABLES_MACTINDX_M_INDEX,
407 QSYS_TIMED_FRAME_ENTRY_TFRM_VLD,
408 QSYS_TIMED_FRAME_ENTRY_TFRM_FP,
409 QSYS_TIMED_FRAME_ENTRY_TFRM_PORTNO,
410 QSYS_TIMED_FRAME_ENTRY_TFRM_TM_SEL,
411 QSYS_TIMED_FRAME_ENTRY_TFRM_TM_T,
412 SYS_RESET_CFG_CORE_ENA,
413 SYS_RESET_CFG_MEM_ENA,
414 SYS_RESET_CFG_MEM_INIT,
418 enum ocelot_clk_pins {
425 struct ocelot_multicast {
426 struct list_head list;
427 unsigned char addr[ETH_ALEN];
432 enum ocelot_tag_prefix {
433 OCELOT_TAG_PREFIX_DISABLED = 0,
434 OCELOT_TAG_PREFIX_NONE,
435 OCELOT_TAG_PREFIX_SHORT,
436 OCELOT_TAG_PREFIX_LONG,
442 struct ocelot_stat_layout {
444 char name[ETH_GSTRING_LEN];
448 void (*pcs_init)(struct ocelot *ocelot, int port);
452 const struct ocelot_ops *ops;
455 struct regmap *targets[TARGET_MAX];
456 struct regmap_field *regfields[REGFIELD_MAX];
457 const u32 *const *map;
458 const struct ocelot_stat_layout *stats_layout;
459 unsigned int num_stats;
461 u8 base_mac[ETH_ALEN];
463 struct net_device *hw_bridge_dev;
467 struct workqueue_struct *ocelot_owq;
474 struct ocelot_port **ports;
478 /* Keep track of the vlan port masks */
479 u32 vlan_mask[VLAN_N_VID];
481 struct list_head multicast;
483 /* Workqueue to check statistics for overflow with its lock */
484 struct mutex stats_lock;
486 struct delayed_work stats_work;
487 struct workqueue_struct *stats_queue;
490 struct ptp_clock *ptp_clock;
491 struct ptp_clock_info ptp_info;
492 struct hwtstamp_config hwtstamp_config;
493 struct mutex ptp_lock; /* Protects the PTP interface state */
494 spinlock_t ptp_clock_lock; /* Protects the PTP clock */
498 struct ocelot *ocelot;
502 /* Ingress default VLAN (pvid) */
505 /* Egress default VLAN (vid) */
509 struct list_head skbs;
513 struct ocelot_port_private {
514 struct ocelot_port port;
515 struct net_device *dev;
516 struct phy_device *phy;
521 phy_interface_t phy_mode;
524 struct ocelot_port_tc tc;
528 struct list_head head;
533 u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset);
534 #define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
535 #define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
536 #define ocelot_read_rix(ocelot, reg, ri) __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
537 #define ocelot_read(ocelot, reg) __ocelot_read_ix(ocelot, reg, 0)
539 void __ocelot_write_ix(struct ocelot *ocelot, u32 val, u32 reg, u32 offset);
540 #define ocelot_write_ix(ocelot, val, reg, gi, ri) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
541 #define ocelot_write_gix(ocelot, val, reg, gi) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
542 #define ocelot_write_rix(ocelot, val, reg, ri) __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
543 #define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
545 void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask, u32 reg,
547 #define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
548 #define ocelot_rmw_gix(ocelot, val, m, reg, gi) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
549 #define ocelot_rmw_rix(ocelot, val, m, reg, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
550 #define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
552 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
553 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
555 int ocelot_regfields_init(struct ocelot *ocelot,
556 const struct reg_field *const regfields);
557 struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
559 #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
560 #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
562 int ocelot_init(struct ocelot *ocelot);
563 void ocelot_deinit(struct ocelot *ocelot);
564 int ocelot_chip_init(struct ocelot *ocelot, const struct ocelot_ops *ops);
565 int ocelot_probe_port(struct ocelot *ocelot, u8 port,
567 struct phy_device *phy);
569 void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu,
570 enum ocelot_tag_prefix injection,
571 enum ocelot_tag_prefix extraction);
573 extern struct notifier_block ocelot_netdevice_nb;
574 extern struct notifier_block ocelot_switchdev_nb;
575 extern struct notifier_block ocelot_switchdev_blocking_nb;
577 int ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
578 void ocelot_get_hwtimestamp(struct ocelot *ocelot, struct timespec64 *ts);