1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ 2 /* 3 * Copyright 2025-2026 NXP 4 */ 5 6 #ifndef _NETC_SWITCH_H 7 #define _NETC_SWITCH_H 8 9 #include <linux/dsa/tag_netc.h> 10 #include <linux/fsl/netc_global.h> 11 #include <linux/fsl/ntmp.h> 12 #include <linux/of_device.h> 13 #include <linux/of_net.h> 14 #include <linux/pci.h> 15 16 #include "netc_switch_hw.h" 17 18 #define NETC_REGS_BAR 0 19 #define NETC_REGS_SIZE 0x80000 20 #define NETC_MSIX_TBL_BAR 2 21 #define NETC_REGS_PORT_BASE 0x4000 22 /* register block size per port */ 23 #define NETC_REGS_PORT_SIZE 0x4000 24 #define PORT_IOBASE(p) (NETC_REGS_PORT_SIZE * (p)) 25 #define NETC_REGS_GLOBAL_BASE 0x70000 26 27 #define NETC_SWITCH_REV_4_3 0x0403 28 29 #define NETC_TC_NUM 8 30 #define NETC_CBDR_NUM 2 31 #define NETC_IPV_NUM 8 32 33 #define NETC_MAX_FRAME_LEN 9600 34 35 #define NETC_STANDALONE_PVID 0 36 37 /* Threshold format: MANT (bits 11:4) * 2^EXP (bits 3:0) 38 * Unit: Memory words (average of 20 bytes each) 39 * NETC_BP_THRESH = 0x8c3, MANT = 0x8c, EXP = 3. Threshold: 1120 words 40 * NETC_FC_THRESH_ON = 0x733, MANT = 0x73, EXP = 3. Threshold: 920 words 41 * NETC_FC_THRESH_OFF = 0x263, MANT = 0x26, EXP = 3. Threshold: 304 words 42 */ 43 #define NETC_BP_THRESH 0x8c3 44 #define NETC_FC_THRESH_ON 0x733 45 #define NETC_FC_THRESH_OFF 0x263 46 47 /* PAUSE quanta: 0xFFFF = 65535 quanta (each quanta = 512 bit times) */ 48 #define NETC_PAUSE_QUANTA 0xFFFF 49 /* PAUSE refresh threshold: send refresh when timer reaches this value */ 50 #define NETC_PAUSE_THRESH 0x7FFF 51 52 struct netc_switch; 53 54 struct netc_switch_info { 55 u32 num_ports; 56 void (*phylink_get_caps)(int port, struct phylink_config *config); 57 }; 58 59 struct netc_port_caps { 60 u32 half_duplex:1; /* indicates whether the port support half-duplex */ 61 u32 pmac:1; /* indicates whether the port has preemption MAC */ 62 u32 pseudo_link:1; 63 }; 64 65 enum netc_host_reason { 66 /* Software defined host reasons */ 67 NETC_HR_HOST_FLOOD = 8, 68 }; 69 70 struct netc_port { 71 void __iomem *iobase; 72 struct netc_switch *switch_priv; 73 struct netc_port_caps caps; 74 struct dsa_port *dp; 75 struct clk *ref_clk; /* RGMII/RMII reference clock */ 76 struct mii_bus *emdio; 77 78 u16 enable:1; 79 u16 uc:1; 80 u16 mc:1; 81 struct ipft_entry_data *host_flood; 82 }; 83 84 struct netc_switch_regs { 85 void __iomem *base; 86 void __iomem *port; 87 void __iomem *global; 88 }; 89 90 struct netc_fdb_entry { 91 u32 entry_id; 92 struct fdbt_cfge_data cfge; 93 struct fdbt_keye_data keye; 94 struct hlist_node node; 95 }; 96 97 struct netc_port_stat { 98 int reg; 99 char name[ETH_GSTRING_LEN] __nonstring; 100 }; 101 102 struct netc_switch { 103 struct pci_dev *pdev; 104 struct device *dev; 105 struct dsa_switch *ds; 106 u16 revision; 107 108 const struct netc_switch_info *info; 109 struct netc_switch_regs regs; 110 struct netc_port **ports; 111 112 struct ntmp_user ntmp; 113 struct hlist_head fdb_list; 114 struct mutex fdbt_lock; /* FDB table lock */ 115 116 /* Switch hardware capabilities */ 117 u32 htmcapr_num_words; 118 u32 num_bp; 119 120 struct bpt_cfge_data *bpt_list; 121 }; 122 123 #define NETC_PRIV(ds) ((struct netc_switch *)((ds)->priv)) 124 #define NETC_PORT(ds, port_id) (NETC_PRIV(ds)->ports[(port_id)]) 125 126 /* Write/Read Switch base registers */ 127 #define netc_base_rd(r, o) netc_read((r)->base + (o)) 128 #define netc_base_wr(r, o, v) netc_write((r)->base + (o), v) 129 130 /* Write/Read registers of Switch Port (including pseudo MAC port) */ 131 #define netc_port_rd(p, o) netc_read((p)->iobase + (o)) 132 #define netc_port_rd64(p, o) netc_read64((p)->iobase + (o)) 133 #define netc_port_wr(p, o, v) netc_write((p)->iobase + (o), v) 134 135 /* Write/Read Switch global registers */ 136 #define netc_glb_rd(r, o) netc_read((r)->global + (o)) 137 #define netc_glb_wr(r, o, v) netc_write((r)->global + (o), v) 138 139 static inline bool is_netc_pseudo_port(struct netc_port *np) 140 { 141 return np->caps.pseudo_link; 142 } 143 144 static inline void netc_add_fdb_entry(struct netc_switch *priv, 145 struct netc_fdb_entry *entry) 146 { 147 hlist_add_head(&entry->node, &priv->fdb_list); 148 } 149 150 static inline void netc_del_fdb_entry(struct netc_fdb_entry *entry) 151 { 152 hlist_del(&entry->node); 153 kfree(entry); 154 } 155 156 int netc_switch_platform_probe(struct netc_switch *priv); 157 158 /* ethtool APIs */ 159 void netc_port_get_pause_stats(struct dsa_switch *ds, int port, 160 struct ethtool_pause_stats *pause_stats); 161 void netc_port_get_rmon_stats(struct dsa_switch *ds, int port, 162 struct ethtool_rmon_stats *rmon_stats, 163 const struct ethtool_rmon_hist_range **ranges); 164 void netc_port_get_eth_ctrl_stats(struct dsa_switch *ds, int port, 165 struct ethtool_eth_ctrl_stats *ctrl_stats); 166 void netc_port_get_eth_mac_stats(struct dsa_switch *ds, int port, 167 struct ethtool_eth_mac_stats *mac_stats); 168 int netc_port_get_sset_count(struct dsa_switch *ds, int port, int sset); 169 void netc_port_get_strings(struct dsa_switch *ds, int port, 170 u32 sset, u8 *data); 171 void netc_port_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data); 172 173 #endif 174