Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Lantiq / Intel GSWIP switch driver for VRX200 SoCs |
| 4 | * |
| 5 | * Copyright (C) 2010 Lantiq Deutschland |
| 6 | * Copyright (C) 2012 John Crispin <john@phrozen.org> |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 7 | * Copyright (C) 2017 - 2019 Hauke Mehrtens <hauke@hauke-m.de> |
| 8 | * |
| 9 | * The VLAN and bridge model the GSWIP hardware uses does not directly |
| 10 | * matches the model DSA uses. |
| 11 | * |
| 12 | * The hardware has 64 possible table entries for bridges with one VLAN |
| 13 | * ID, one flow id and a list of ports for each bridge. All entries which |
| 14 | * match the same flow ID are combined in the mac learning table, they |
| 15 | * act as one global bridge. |
| 16 | * The hardware does not support VLAN filter on the port, but on the |
| 17 | * bridge, this driver converts the DSA model to the hardware. |
| 18 | * |
| 19 | * The CPU gets all the exception frames which do not match any forwarding |
| 20 | * rule and the CPU port is also added to all bridges. This makes it possible |
| 21 | * to handle all the special cases easily in software. |
| 22 | * At the initialization the driver allocates one bridge table entry for |
| 23 | * each switch port which is used when the port is used without an |
| 24 | * explicit bridge. This prevents the frames from being forwarded |
| 25 | * between all LAN ports by default. |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <linux/clk.h> |
| 29 | #include <linux/etherdevice.h> |
| 30 | #include <linux/firmware.h> |
| 31 | #include <linux/if_bridge.h> |
| 32 | #include <linux/if_vlan.h> |
| 33 | #include <linux/iopoll.h> |
| 34 | #include <linux/mfd/syscon.h> |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/of_mdio.h> |
| 37 | #include <linux/of_net.h> |
| 38 | #include <linux/of_platform.h> |
| 39 | #include <linux/phy.h> |
| 40 | #include <linux/phylink.h> |
| 41 | #include <linux/platform_device.h> |
| 42 | #include <linux/regmap.h> |
| 43 | #include <linux/reset.h> |
| 44 | #include <net/dsa.h> |
| 45 | #include <dt-bindings/mips/lantiq_rcu_gphy.h> |
| 46 | |
| 47 | #include "lantiq_pce.h" |
| 48 | |
| 49 | /* GSWIP MDIO Registers */ |
| 50 | #define GSWIP_MDIO_GLOB 0x00 |
| 51 | #define GSWIP_MDIO_GLOB_ENABLE BIT(15) |
| 52 | #define GSWIP_MDIO_CTRL 0x08 |
| 53 | #define GSWIP_MDIO_CTRL_BUSY BIT(12) |
| 54 | #define GSWIP_MDIO_CTRL_RD BIT(11) |
| 55 | #define GSWIP_MDIO_CTRL_WR BIT(10) |
| 56 | #define GSWIP_MDIO_CTRL_PHYAD_MASK 0x1f |
| 57 | #define GSWIP_MDIO_CTRL_PHYAD_SHIFT 5 |
| 58 | #define GSWIP_MDIO_CTRL_REGAD_MASK 0x1f |
| 59 | #define GSWIP_MDIO_READ 0x09 |
| 60 | #define GSWIP_MDIO_WRITE 0x0A |
| 61 | #define GSWIP_MDIO_MDC_CFG0 0x0B |
| 62 | #define GSWIP_MDIO_MDC_CFG1 0x0C |
| 63 | #define GSWIP_MDIO_PHYp(p) (0x15 - (p)) |
| 64 | #define GSWIP_MDIO_PHY_LINK_MASK 0x6000 |
| 65 | #define GSWIP_MDIO_PHY_LINK_AUTO 0x0000 |
| 66 | #define GSWIP_MDIO_PHY_LINK_DOWN 0x4000 |
| 67 | #define GSWIP_MDIO_PHY_LINK_UP 0x2000 |
| 68 | #define GSWIP_MDIO_PHY_SPEED_MASK 0x1800 |
| 69 | #define GSWIP_MDIO_PHY_SPEED_AUTO 0x1800 |
| 70 | #define GSWIP_MDIO_PHY_SPEED_M10 0x0000 |
| 71 | #define GSWIP_MDIO_PHY_SPEED_M100 0x0800 |
| 72 | #define GSWIP_MDIO_PHY_SPEED_G1 0x1000 |
| 73 | #define GSWIP_MDIO_PHY_FDUP_MASK 0x0600 |
| 74 | #define GSWIP_MDIO_PHY_FDUP_AUTO 0x0000 |
| 75 | #define GSWIP_MDIO_PHY_FDUP_EN 0x0200 |
| 76 | #define GSWIP_MDIO_PHY_FDUP_DIS 0x0600 |
| 77 | #define GSWIP_MDIO_PHY_FCONTX_MASK 0x0180 |
| 78 | #define GSWIP_MDIO_PHY_FCONTX_AUTO 0x0000 |
| 79 | #define GSWIP_MDIO_PHY_FCONTX_EN 0x0100 |
| 80 | #define GSWIP_MDIO_PHY_FCONTX_DIS 0x0180 |
| 81 | #define GSWIP_MDIO_PHY_FCONRX_MASK 0x0060 |
| 82 | #define GSWIP_MDIO_PHY_FCONRX_AUTO 0x0000 |
| 83 | #define GSWIP_MDIO_PHY_FCONRX_EN 0x0020 |
| 84 | #define GSWIP_MDIO_PHY_FCONRX_DIS 0x0060 |
| 85 | #define GSWIP_MDIO_PHY_ADDR_MASK 0x001f |
| 86 | #define GSWIP_MDIO_PHY_MASK (GSWIP_MDIO_PHY_ADDR_MASK | \ |
| 87 | GSWIP_MDIO_PHY_FCONRX_MASK | \ |
| 88 | GSWIP_MDIO_PHY_FCONTX_MASK | \ |
| 89 | GSWIP_MDIO_PHY_LINK_MASK | \ |
| 90 | GSWIP_MDIO_PHY_SPEED_MASK | \ |
| 91 | GSWIP_MDIO_PHY_FDUP_MASK) |
| 92 | |
| 93 | /* GSWIP MII Registers */ |
| 94 | #define GSWIP_MII_CFG0 0x00 |
| 95 | #define GSWIP_MII_CFG1 0x02 |
| 96 | #define GSWIP_MII_CFG5 0x04 |
| 97 | #define GSWIP_MII_CFG_EN BIT(14) |
| 98 | #define GSWIP_MII_CFG_LDCLKDIS BIT(12) |
| 99 | #define GSWIP_MII_CFG_MODE_MIIP 0x0 |
| 100 | #define GSWIP_MII_CFG_MODE_MIIM 0x1 |
| 101 | #define GSWIP_MII_CFG_MODE_RMIIP 0x2 |
| 102 | #define GSWIP_MII_CFG_MODE_RMIIM 0x3 |
| 103 | #define GSWIP_MII_CFG_MODE_RGMII 0x4 |
| 104 | #define GSWIP_MII_CFG_MODE_MASK 0xf |
| 105 | #define GSWIP_MII_CFG_RATE_M2P5 0x00 |
| 106 | #define GSWIP_MII_CFG_RATE_M25 0x10 |
| 107 | #define GSWIP_MII_CFG_RATE_M125 0x20 |
| 108 | #define GSWIP_MII_CFG_RATE_M50 0x30 |
| 109 | #define GSWIP_MII_CFG_RATE_AUTO 0x40 |
| 110 | #define GSWIP_MII_CFG_RATE_MASK 0x70 |
| 111 | #define GSWIP_MII_PCDU0 0x01 |
| 112 | #define GSWIP_MII_PCDU1 0x03 |
| 113 | #define GSWIP_MII_PCDU5 0x05 |
| 114 | #define GSWIP_MII_PCDU_TXDLY_MASK GENMASK(2, 0) |
| 115 | #define GSWIP_MII_PCDU_RXDLY_MASK GENMASK(9, 7) |
| 116 | |
| 117 | /* GSWIP Core Registers */ |
| 118 | #define GSWIP_SWRES 0x000 |
| 119 | #define GSWIP_SWRES_R1 BIT(1) /* GSWIP Software reset */ |
| 120 | #define GSWIP_SWRES_R0 BIT(0) /* GSWIP Hardware reset */ |
| 121 | #define GSWIP_VERSION 0x013 |
| 122 | #define GSWIP_VERSION_REV_SHIFT 0 |
| 123 | #define GSWIP_VERSION_REV_MASK GENMASK(7, 0) |
| 124 | #define GSWIP_VERSION_MOD_SHIFT 8 |
| 125 | #define GSWIP_VERSION_MOD_MASK GENMASK(15, 8) |
| 126 | #define GSWIP_VERSION_2_0 0x100 |
| 127 | #define GSWIP_VERSION_2_1 0x021 |
| 128 | #define GSWIP_VERSION_2_2 0x122 |
| 129 | #define GSWIP_VERSION_2_2_ETC 0x022 |
| 130 | |
| 131 | #define GSWIP_BM_RAM_VAL(x) (0x043 - (x)) |
| 132 | #define GSWIP_BM_RAM_ADDR 0x044 |
| 133 | #define GSWIP_BM_RAM_CTRL 0x045 |
| 134 | #define GSWIP_BM_RAM_CTRL_BAS BIT(15) |
| 135 | #define GSWIP_BM_RAM_CTRL_OPMOD BIT(5) |
| 136 | #define GSWIP_BM_RAM_CTRL_ADDR_MASK GENMASK(4, 0) |
| 137 | #define GSWIP_BM_QUEUE_GCTRL 0x04A |
| 138 | #define GSWIP_BM_QUEUE_GCTRL_GL_MOD BIT(10) |
| 139 | /* buffer management Port Configuration Register */ |
| 140 | #define GSWIP_BM_PCFGp(p) (0x080 + ((p) * 2)) |
| 141 | #define GSWIP_BM_PCFG_CNTEN BIT(0) /* RMON Counter Enable */ |
| 142 | #define GSWIP_BM_PCFG_IGCNT BIT(1) /* Ingres Special Tag RMON count */ |
| 143 | /* buffer management Port Control Register */ |
| 144 | #define GSWIP_BM_RMON_CTRLp(p) (0x81 + ((p) * 2)) |
| 145 | #define GSWIP_BM_CTRL_RMON_RAM1_RES BIT(0) /* Software Reset for RMON RAM 1 */ |
| 146 | #define GSWIP_BM_CTRL_RMON_RAM2_RES BIT(1) /* Software Reset for RMON RAM 2 */ |
| 147 | |
| 148 | /* PCE */ |
| 149 | #define GSWIP_PCE_TBL_KEY(x) (0x447 - (x)) |
| 150 | #define GSWIP_PCE_TBL_MASK 0x448 |
| 151 | #define GSWIP_PCE_TBL_VAL(x) (0x44D - (x)) |
| 152 | #define GSWIP_PCE_TBL_ADDR 0x44E |
| 153 | #define GSWIP_PCE_TBL_CTRL 0x44F |
| 154 | #define GSWIP_PCE_TBL_CTRL_BAS BIT(15) |
| 155 | #define GSWIP_PCE_TBL_CTRL_TYPE BIT(13) |
| 156 | #define GSWIP_PCE_TBL_CTRL_VLD BIT(12) |
| 157 | #define GSWIP_PCE_TBL_CTRL_KEYFORM BIT(11) |
| 158 | #define GSWIP_PCE_TBL_CTRL_GMAP_MASK GENMASK(10, 7) |
| 159 | #define GSWIP_PCE_TBL_CTRL_OPMOD_MASK GENMASK(6, 5) |
| 160 | #define GSWIP_PCE_TBL_CTRL_OPMOD_ADRD 0x00 |
| 161 | #define GSWIP_PCE_TBL_CTRL_OPMOD_ADWR 0x20 |
| 162 | #define GSWIP_PCE_TBL_CTRL_OPMOD_KSRD 0x40 |
| 163 | #define GSWIP_PCE_TBL_CTRL_OPMOD_KSWR 0x60 |
| 164 | #define GSWIP_PCE_TBL_CTRL_ADDR_MASK GENMASK(4, 0) |
| 165 | #define GSWIP_PCE_PMAP1 0x453 /* Monitoring port map */ |
| 166 | #define GSWIP_PCE_PMAP2 0x454 /* Default Multicast port map */ |
| 167 | #define GSWIP_PCE_PMAP3 0x455 /* Default Unknown Unicast port map */ |
| 168 | #define GSWIP_PCE_GCTRL_0 0x456 |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 169 | #define GSWIP_PCE_GCTRL_0_MTFL BIT(0) /* MAC Table Flushing */ |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 170 | #define GSWIP_PCE_GCTRL_0_MC_VALID BIT(3) |
| 171 | #define GSWIP_PCE_GCTRL_0_VLAN BIT(14) /* VLAN aware Switching */ |
| 172 | #define GSWIP_PCE_GCTRL_1 0x457 |
| 173 | #define GSWIP_PCE_GCTRL_1_MAC_GLOCK BIT(2) /* MAC Address table lock */ |
| 174 | #define GSWIP_PCE_GCTRL_1_MAC_GLOCK_MOD BIT(3) /* Mac address table lock forwarding mode */ |
| 175 | #define GSWIP_PCE_PCTRL_0p(p) (0x480 + ((p) * 0xA)) |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 176 | #define GSWIP_PCE_PCTRL_0_TVM BIT(5) /* Transparent VLAN mode */ |
| 177 | #define GSWIP_PCE_PCTRL_0_VREP BIT(6) /* VLAN Replace Mode */ |
| 178 | #define GSWIP_PCE_PCTRL_0_INGRESS BIT(11) /* Accept special tag in ingress */ |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 179 | #define GSWIP_PCE_PCTRL_0_PSTATE_LISTEN 0x0 |
| 180 | #define GSWIP_PCE_PCTRL_0_PSTATE_RX 0x1 |
| 181 | #define GSWIP_PCE_PCTRL_0_PSTATE_TX 0x2 |
| 182 | #define GSWIP_PCE_PCTRL_0_PSTATE_LEARNING 0x3 |
| 183 | #define GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING 0x7 |
| 184 | #define GSWIP_PCE_PCTRL_0_PSTATE_MASK GENMASK(2, 0) |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 185 | #define GSWIP_PCE_VCTRL(p) (0x485 + ((p) * 0xA)) |
| 186 | #define GSWIP_PCE_VCTRL_UVR BIT(0) /* Unknown VLAN Rule */ |
| 187 | #define GSWIP_PCE_VCTRL_VIMR BIT(3) /* VLAN Ingress Member violation rule */ |
| 188 | #define GSWIP_PCE_VCTRL_VEMR BIT(4) /* VLAN Egress Member violation rule */ |
| 189 | #define GSWIP_PCE_VCTRL_VSR BIT(5) /* VLAN Security */ |
| 190 | #define GSWIP_PCE_VCTRL_VID0 BIT(6) /* Priority Tagged Rule */ |
| 191 | #define GSWIP_PCE_DEFPVID(p) (0x486 + ((p) * 0xA)) |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 192 | |
| 193 | #define GSWIP_MAC_FLEN 0x8C5 |
| 194 | #define GSWIP_MAC_CTRL_2p(p) (0x905 + ((p) * 0xC)) |
| 195 | #define GSWIP_MAC_CTRL_2_MLEN BIT(3) /* Maximum Untagged Frame Lnegth */ |
| 196 | |
| 197 | /* Ethernet Switch Fetch DMA Port Control Register */ |
| 198 | #define GSWIP_FDMA_PCTRLp(p) (0xA80 + ((p) * 0x6)) |
| 199 | #define GSWIP_FDMA_PCTRL_EN BIT(0) /* FDMA Port Enable */ |
| 200 | #define GSWIP_FDMA_PCTRL_STEN BIT(1) /* Special Tag Insertion Enable */ |
| 201 | #define GSWIP_FDMA_PCTRL_VLANMOD_MASK GENMASK(4, 3) /* VLAN Modification Control */ |
| 202 | #define GSWIP_FDMA_PCTRL_VLANMOD_SHIFT 3 /* VLAN Modification Control */ |
| 203 | #define GSWIP_FDMA_PCTRL_VLANMOD_DIS (0x0 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT) |
| 204 | #define GSWIP_FDMA_PCTRL_VLANMOD_PRIO (0x1 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT) |
| 205 | #define GSWIP_FDMA_PCTRL_VLANMOD_ID (0x2 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT) |
| 206 | #define GSWIP_FDMA_PCTRL_VLANMOD_BOTH (0x3 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT) |
| 207 | |
| 208 | /* Ethernet Switch Store DMA Port Control Register */ |
| 209 | #define GSWIP_SDMA_PCTRLp(p) (0xBC0 + ((p) * 0x6)) |
| 210 | #define GSWIP_SDMA_PCTRL_EN BIT(0) /* SDMA Port Enable */ |
| 211 | #define GSWIP_SDMA_PCTRL_FCEN BIT(1) /* Flow Control Enable */ |
| 212 | #define GSWIP_SDMA_PCTRL_PAUFWD BIT(1) /* Pause Frame Forwarding */ |
| 213 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 214 | #define GSWIP_TABLE_ACTIVE_VLAN 0x01 |
| 215 | #define GSWIP_TABLE_VLAN_MAPPING 0x02 |
| 216 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 217 | #define XRX200_GPHY_FW_ALIGN (16 * 1024) |
| 218 | |
| 219 | struct gswip_hw_info { |
| 220 | int max_ports; |
| 221 | int cpu_port; |
| 222 | }; |
| 223 | |
| 224 | struct xway_gphy_match_data { |
| 225 | char *fe_firmware_name; |
| 226 | char *ge_firmware_name; |
| 227 | }; |
| 228 | |
| 229 | struct gswip_gphy_fw { |
| 230 | struct clk *clk_gate; |
| 231 | struct reset_control *reset; |
| 232 | u32 fw_addr_offset; |
| 233 | char *fw_name; |
| 234 | }; |
| 235 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 236 | struct gswip_vlan { |
| 237 | struct net_device *bridge; |
| 238 | u16 vid; |
| 239 | u8 fid; |
| 240 | }; |
| 241 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 242 | struct gswip_priv { |
| 243 | __iomem void *gswip; |
| 244 | __iomem void *mdio; |
| 245 | __iomem void *mii; |
| 246 | const struct gswip_hw_info *hw_info; |
| 247 | const struct xway_gphy_match_data *gphy_fw_name_cfg; |
| 248 | struct dsa_switch *ds; |
| 249 | struct device *dev; |
| 250 | struct regmap *rcu_regmap; |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 251 | struct gswip_vlan vlans[64]; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 252 | int num_gphy_fw; |
| 253 | struct gswip_gphy_fw *gphy_fw; |
| 254 | }; |
| 255 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 256 | struct gswip_pce_table_entry { |
| 257 | u16 index; // PCE_TBL_ADDR.ADDR = pData->table_index |
| 258 | u16 table; // PCE_TBL_CTRL.ADDR = pData->table |
| 259 | u16 key[8]; |
| 260 | u16 val[5]; |
| 261 | u16 mask; |
| 262 | u8 gmap; |
| 263 | bool type; |
| 264 | bool valid; |
| 265 | bool key_mode; |
| 266 | }; |
| 267 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 268 | struct gswip_rmon_cnt_desc { |
| 269 | unsigned int size; |
| 270 | unsigned int offset; |
| 271 | const char *name; |
| 272 | }; |
| 273 | |
| 274 | #define MIB_DESC(_size, _offset, _name) {.size = _size, .offset = _offset, .name = _name} |
| 275 | |
| 276 | static const struct gswip_rmon_cnt_desc gswip_rmon_cnt[] = { |
| 277 | /** Receive Packet Count (only packets that are accepted and not discarded). */ |
| 278 | MIB_DESC(1, 0x1F, "RxGoodPkts"), |
| 279 | MIB_DESC(1, 0x23, "RxUnicastPkts"), |
| 280 | MIB_DESC(1, 0x22, "RxMulticastPkts"), |
| 281 | MIB_DESC(1, 0x21, "RxFCSErrorPkts"), |
| 282 | MIB_DESC(1, 0x1D, "RxUnderSizeGoodPkts"), |
| 283 | MIB_DESC(1, 0x1E, "RxUnderSizeErrorPkts"), |
| 284 | MIB_DESC(1, 0x1B, "RxOversizeGoodPkts"), |
| 285 | MIB_DESC(1, 0x1C, "RxOversizeErrorPkts"), |
| 286 | MIB_DESC(1, 0x20, "RxGoodPausePkts"), |
| 287 | MIB_DESC(1, 0x1A, "RxAlignErrorPkts"), |
| 288 | MIB_DESC(1, 0x12, "Rx64BytePkts"), |
| 289 | MIB_DESC(1, 0x13, "Rx127BytePkts"), |
| 290 | MIB_DESC(1, 0x14, "Rx255BytePkts"), |
| 291 | MIB_DESC(1, 0x15, "Rx511BytePkts"), |
| 292 | MIB_DESC(1, 0x16, "Rx1023BytePkts"), |
| 293 | /** Receive Size 1024-1522 (or more, if configured) Packet Count. */ |
| 294 | MIB_DESC(1, 0x17, "RxMaxBytePkts"), |
| 295 | MIB_DESC(1, 0x18, "RxDroppedPkts"), |
| 296 | MIB_DESC(1, 0x19, "RxFilteredPkts"), |
| 297 | MIB_DESC(2, 0x24, "RxGoodBytes"), |
| 298 | MIB_DESC(2, 0x26, "RxBadBytes"), |
| 299 | MIB_DESC(1, 0x11, "TxAcmDroppedPkts"), |
| 300 | MIB_DESC(1, 0x0C, "TxGoodPkts"), |
| 301 | MIB_DESC(1, 0x06, "TxUnicastPkts"), |
| 302 | MIB_DESC(1, 0x07, "TxMulticastPkts"), |
| 303 | MIB_DESC(1, 0x00, "Tx64BytePkts"), |
| 304 | MIB_DESC(1, 0x01, "Tx127BytePkts"), |
| 305 | MIB_DESC(1, 0x02, "Tx255BytePkts"), |
| 306 | MIB_DESC(1, 0x03, "Tx511BytePkts"), |
| 307 | MIB_DESC(1, 0x04, "Tx1023BytePkts"), |
| 308 | /** Transmit Size 1024-1522 (or more, if configured) Packet Count. */ |
| 309 | MIB_DESC(1, 0x05, "TxMaxBytePkts"), |
| 310 | MIB_DESC(1, 0x08, "TxSingleCollCount"), |
| 311 | MIB_DESC(1, 0x09, "TxMultCollCount"), |
| 312 | MIB_DESC(1, 0x0A, "TxLateCollCount"), |
| 313 | MIB_DESC(1, 0x0B, "TxExcessCollCount"), |
| 314 | MIB_DESC(1, 0x0D, "TxPauseCount"), |
| 315 | MIB_DESC(1, 0x10, "TxDroppedPkts"), |
| 316 | MIB_DESC(2, 0x0E, "TxGoodBytes"), |
| 317 | }; |
| 318 | |
| 319 | static u32 gswip_switch_r(struct gswip_priv *priv, u32 offset) |
| 320 | { |
| 321 | return __raw_readl(priv->gswip + (offset * 4)); |
| 322 | } |
| 323 | |
| 324 | static void gswip_switch_w(struct gswip_priv *priv, u32 val, u32 offset) |
| 325 | { |
| 326 | __raw_writel(val, priv->gswip + (offset * 4)); |
| 327 | } |
| 328 | |
| 329 | static void gswip_switch_mask(struct gswip_priv *priv, u32 clear, u32 set, |
| 330 | u32 offset) |
| 331 | { |
| 332 | u32 val = gswip_switch_r(priv, offset); |
| 333 | |
| 334 | val &= ~(clear); |
| 335 | val |= set; |
| 336 | gswip_switch_w(priv, val, offset); |
| 337 | } |
| 338 | |
| 339 | static u32 gswip_switch_r_timeout(struct gswip_priv *priv, u32 offset, |
| 340 | u32 cleared) |
| 341 | { |
| 342 | u32 val; |
| 343 | |
| 344 | return readx_poll_timeout(__raw_readl, priv->gswip + (offset * 4), val, |
| 345 | (val & cleared) == 0, 20, 50000); |
| 346 | } |
| 347 | |
| 348 | static u32 gswip_mdio_r(struct gswip_priv *priv, u32 offset) |
| 349 | { |
| 350 | return __raw_readl(priv->mdio + (offset * 4)); |
| 351 | } |
| 352 | |
| 353 | static void gswip_mdio_w(struct gswip_priv *priv, u32 val, u32 offset) |
| 354 | { |
| 355 | __raw_writel(val, priv->mdio + (offset * 4)); |
| 356 | } |
| 357 | |
| 358 | static void gswip_mdio_mask(struct gswip_priv *priv, u32 clear, u32 set, |
| 359 | u32 offset) |
| 360 | { |
| 361 | u32 val = gswip_mdio_r(priv, offset); |
| 362 | |
| 363 | val &= ~(clear); |
| 364 | val |= set; |
| 365 | gswip_mdio_w(priv, val, offset); |
| 366 | } |
| 367 | |
| 368 | static u32 gswip_mii_r(struct gswip_priv *priv, u32 offset) |
| 369 | { |
| 370 | return __raw_readl(priv->mii + (offset * 4)); |
| 371 | } |
| 372 | |
| 373 | static void gswip_mii_w(struct gswip_priv *priv, u32 val, u32 offset) |
| 374 | { |
| 375 | __raw_writel(val, priv->mii + (offset * 4)); |
| 376 | } |
| 377 | |
| 378 | static void gswip_mii_mask(struct gswip_priv *priv, u32 clear, u32 set, |
| 379 | u32 offset) |
| 380 | { |
| 381 | u32 val = gswip_mii_r(priv, offset); |
| 382 | |
| 383 | val &= ~(clear); |
| 384 | val |= set; |
| 385 | gswip_mii_w(priv, val, offset); |
| 386 | } |
| 387 | |
| 388 | static void gswip_mii_mask_cfg(struct gswip_priv *priv, u32 clear, u32 set, |
| 389 | int port) |
| 390 | { |
| 391 | switch (port) { |
| 392 | case 0: |
| 393 | gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG0); |
| 394 | break; |
| 395 | case 1: |
| 396 | gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG1); |
| 397 | break; |
| 398 | case 5: |
| 399 | gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG5); |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | static void gswip_mii_mask_pcdu(struct gswip_priv *priv, u32 clear, u32 set, |
| 405 | int port) |
| 406 | { |
| 407 | switch (port) { |
| 408 | case 0: |
| 409 | gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU0); |
| 410 | break; |
| 411 | case 1: |
| 412 | gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU1); |
| 413 | break; |
| 414 | case 5: |
| 415 | gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU5); |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | static int gswip_mdio_poll(struct gswip_priv *priv) |
| 421 | { |
| 422 | int cnt = 100; |
| 423 | |
| 424 | while (likely(cnt--)) { |
| 425 | u32 ctrl = gswip_mdio_r(priv, GSWIP_MDIO_CTRL); |
| 426 | |
| 427 | if ((ctrl & GSWIP_MDIO_CTRL_BUSY) == 0) |
| 428 | return 0; |
| 429 | usleep_range(20, 40); |
| 430 | } |
| 431 | |
| 432 | return -ETIMEDOUT; |
| 433 | } |
| 434 | |
| 435 | static int gswip_mdio_wr(struct mii_bus *bus, int addr, int reg, u16 val) |
| 436 | { |
| 437 | struct gswip_priv *priv = bus->priv; |
| 438 | int err; |
| 439 | |
| 440 | err = gswip_mdio_poll(priv); |
| 441 | if (err) { |
| 442 | dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n"); |
| 443 | return err; |
| 444 | } |
| 445 | |
| 446 | gswip_mdio_w(priv, val, GSWIP_MDIO_WRITE); |
| 447 | gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_WR | |
| 448 | ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) | |
| 449 | (reg & GSWIP_MDIO_CTRL_REGAD_MASK), |
| 450 | GSWIP_MDIO_CTRL); |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg) |
| 456 | { |
| 457 | struct gswip_priv *priv = bus->priv; |
| 458 | int err; |
| 459 | |
| 460 | err = gswip_mdio_poll(priv); |
| 461 | if (err) { |
| 462 | dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n"); |
| 463 | return err; |
| 464 | } |
| 465 | |
| 466 | gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_RD | |
| 467 | ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) | |
| 468 | (reg & GSWIP_MDIO_CTRL_REGAD_MASK), |
| 469 | GSWIP_MDIO_CTRL); |
| 470 | |
| 471 | err = gswip_mdio_poll(priv); |
| 472 | if (err) { |
| 473 | dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n"); |
| 474 | return err; |
| 475 | } |
| 476 | |
| 477 | return gswip_mdio_r(priv, GSWIP_MDIO_READ); |
| 478 | } |
| 479 | |
| 480 | static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np) |
| 481 | { |
| 482 | struct dsa_switch *ds = priv->ds; |
| 483 | |
| 484 | ds->slave_mii_bus = devm_mdiobus_alloc(priv->dev); |
| 485 | if (!ds->slave_mii_bus) |
| 486 | return -ENOMEM; |
| 487 | |
| 488 | ds->slave_mii_bus->priv = priv; |
| 489 | ds->slave_mii_bus->read = gswip_mdio_rd; |
| 490 | ds->slave_mii_bus->write = gswip_mdio_wr; |
| 491 | ds->slave_mii_bus->name = "lantiq,xrx200-mdio"; |
| 492 | snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "%s-mii", |
| 493 | dev_name(priv->dev)); |
| 494 | ds->slave_mii_bus->parent = priv->dev; |
| 495 | ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask; |
| 496 | |
| 497 | return of_mdiobus_register(ds->slave_mii_bus, mdio_np); |
| 498 | } |
| 499 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 500 | static int gswip_pce_table_entry_read(struct gswip_priv *priv, |
| 501 | struct gswip_pce_table_entry *tbl) |
| 502 | { |
| 503 | int i; |
| 504 | int err; |
| 505 | u16 crtl; |
| 506 | u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSRD : |
| 507 | GSWIP_PCE_TBL_CTRL_OPMOD_ADRD; |
| 508 | |
| 509 | err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, |
| 510 | GSWIP_PCE_TBL_CTRL_BAS); |
| 511 | if (err) |
| 512 | return err; |
| 513 | |
| 514 | gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR); |
| 515 | gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | |
| 516 | GSWIP_PCE_TBL_CTRL_OPMOD_MASK, |
| 517 | tbl->table | addr_mode | GSWIP_PCE_TBL_CTRL_BAS, |
| 518 | GSWIP_PCE_TBL_CTRL); |
| 519 | |
| 520 | err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, |
| 521 | GSWIP_PCE_TBL_CTRL_BAS); |
| 522 | if (err) |
| 523 | return err; |
| 524 | |
| 525 | for (i = 0; i < ARRAY_SIZE(tbl->key); i++) |
| 526 | tbl->key[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_KEY(i)); |
| 527 | |
| 528 | for (i = 0; i < ARRAY_SIZE(tbl->val); i++) |
| 529 | tbl->val[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_VAL(i)); |
| 530 | |
| 531 | tbl->mask = gswip_switch_r(priv, GSWIP_PCE_TBL_MASK); |
| 532 | |
| 533 | crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL); |
| 534 | |
| 535 | tbl->type = !!(crtl & GSWIP_PCE_TBL_CTRL_TYPE); |
| 536 | tbl->valid = !!(crtl & GSWIP_PCE_TBL_CTRL_VLD); |
| 537 | tbl->gmap = (crtl & GSWIP_PCE_TBL_CTRL_GMAP_MASK) >> 7; |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static int gswip_pce_table_entry_write(struct gswip_priv *priv, |
| 543 | struct gswip_pce_table_entry *tbl) |
| 544 | { |
| 545 | int i; |
| 546 | int err; |
| 547 | u16 crtl; |
| 548 | u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSWR : |
| 549 | GSWIP_PCE_TBL_CTRL_OPMOD_ADWR; |
| 550 | |
| 551 | err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, |
| 552 | GSWIP_PCE_TBL_CTRL_BAS); |
| 553 | if (err) |
| 554 | return err; |
| 555 | |
| 556 | gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR); |
| 557 | gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | |
| 558 | GSWIP_PCE_TBL_CTRL_OPMOD_MASK, |
| 559 | tbl->table | addr_mode, |
| 560 | GSWIP_PCE_TBL_CTRL); |
| 561 | |
| 562 | for (i = 0; i < ARRAY_SIZE(tbl->key); i++) |
| 563 | gswip_switch_w(priv, tbl->key[i], GSWIP_PCE_TBL_KEY(i)); |
| 564 | |
| 565 | for (i = 0; i < ARRAY_SIZE(tbl->val); i++) |
| 566 | gswip_switch_w(priv, tbl->val[i], GSWIP_PCE_TBL_VAL(i)); |
| 567 | |
| 568 | gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | |
| 569 | GSWIP_PCE_TBL_CTRL_OPMOD_MASK, |
| 570 | tbl->table | addr_mode, |
| 571 | GSWIP_PCE_TBL_CTRL); |
| 572 | |
| 573 | gswip_switch_w(priv, tbl->mask, GSWIP_PCE_TBL_MASK); |
| 574 | |
| 575 | crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL); |
| 576 | crtl &= ~(GSWIP_PCE_TBL_CTRL_TYPE | GSWIP_PCE_TBL_CTRL_VLD | |
| 577 | GSWIP_PCE_TBL_CTRL_GMAP_MASK); |
| 578 | if (tbl->type) |
| 579 | crtl |= GSWIP_PCE_TBL_CTRL_TYPE; |
| 580 | if (tbl->valid) |
| 581 | crtl |= GSWIP_PCE_TBL_CTRL_VLD; |
| 582 | crtl |= (tbl->gmap << 7) & GSWIP_PCE_TBL_CTRL_GMAP_MASK; |
| 583 | crtl |= GSWIP_PCE_TBL_CTRL_BAS; |
| 584 | gswip_switch_w(priv, crtl, GSWIP_PCE_TBL_CTRL); |
| 585 | |
| 586 | return gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, |
| 587 | GSWIP_PCE_TBL_CTRL_BAS); |
| 588 | } |
| 589 | |
| 590 | /* Add the LAN port into a bridge with the CPU port by |
| 591 | * default. This prevents automatic forwarding of |
| 592 | * packages between the LAN ports when no explicit |
| 593 | * bridge is configured. |
| 594 | */ |
| 595 | static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add) |
| 596 | { |
| 597 | struct gswip_pce_table_entry vlan_active = {0,}; |
| 598 | struct gswip_pce_table_entry vlan_mapping = {0,}; |
| 599 | unsigned int cpu_port = priv->hw_info->cpu_port; |
| 600 | unsigned int max_ports = priv->hw_info->max_ports; |
| 601 | int err; |
| 602 | |
| 603 | if (port >= max_ports) { |
| 604 | dev_err(priv->dev, "single port for %i supported\n", port); |
| 605 | return -EIO; |
| 606 | } |
| 607 | |
| 608 | vlan_active.index = port + 1; |
| 609 | vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN; |
| 610 | vlan_active.key[0] = 0; /* vid */ |
| 611 | vlan_active.val[0] = port + 1 /* fid */; |
| 612 | vlan_active.valid = add; |
| 613 | err = gswip_pce_table_entry_write(priv, &vlan_active); |
| 614 | if (err) { |
| 615 | dev_err(priv->dev, "failed to write active VLAN: %d\n", err); |
| 616 | return err; |
| 617 | } |
| 618 | |
| 619 | if (!add) |
| 620 | return 0; |
| 621 | |
| 622 | vlan_mapping.index = port + 1; |
| 623 | vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; |
| 624 | vlan_mapping.val[0] = 0 /* vid */; |
| 625 | vlan_mapping.val[1] = BIT(port) | BIT(cpu_port); |
| 626 | vlan_mapping.val[2] = 0; |
| 627 | err = gswip_pce_table_entry_write(priv, &vlan_mapping); |
| 628 | if (err) { |
| 629 | dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); |
| 630 | return err; |
| 631 | } |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 636 | static int gswip_port_enable(struct dsa_switch *ds, int port, |
| 637 | struct phy_device *phydev) |
| 638 | { |
| 639 | struct gswip_priv *priv = ds->priv; |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 640 | int err; |
| 641 | |
| 642 | if (!dsa_is_cpu_port(ds, port)) { |
| 643 | err = gswip_add_single_port_br(priv, port, true); |
| 644 | if (err) |
| 645 | return err; |
| 646 | } |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 647 | |
| 648 | /* RMON Counter Enable for port */ |
| 649 | gswip_switch_w(priv, GSWIP_BM_PCFG_CNTEN, GSWIP_BM_PCFGp(port)); |
| 650 | |
| 651 | /* enable port fetch/store dma & VLAN Modification */ |
| 652 | gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_EN | |
| 653 | GSWIP_FDMA_PCTRL_VLANMOD_BOTH, |
| 654 | GSWIP_FDMA_PCTRLp(port)); |
| 655 | gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN, |
| 656 | GSWIP_SDMA_PCTRLp(port)); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 657 | |
| 658 | if (!dsa_is_cpu_port(ds, port)) { |
| 659 | u32 macconf = GSWIP_MDIO_PHY_LINK_AUTO | |
| 660 | GSWIP_MDIO_PHY_SPEED_AUTO | |
| 661 | GSWIP_MDIO_PHY_FDUP_AUTO | |
| 662 | GSWIP_MDIO_PHY_FCONTX_AUTO | |
| 663 | GSWIP_MDIO_PHY_FCONRX_AUTO | |
| 664 | (phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK); |
| 665 | |
| 666 | gswip_mdio_w(priv, macconf, GSWIP_MDIO_PHYp(port)); |
| 667 | /* Activate MDIO auto polling */ |
| 668 | gswip_mdio_mask(priv, 0, BIT(port), GSWIP_MDIO_MDC_CFG0); |
| 669 | } |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 674 | static void gswip_port_disable(struct dsa_switch *ds, int port) |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 675 | { |
| 676 | struct gswip_priv *priv = ds->priv; |
| 677 | |
| 678 | if (!dsa_is_cpu_port(ds, port)) { |
| 679 | gswip_mdio_mask(priv, GSWIP_MDIO_PHY_LINK_DOWN, |
| 680 | GSWIP_MDIO_PHY_LINK_MASK, |
| 681 | GSWIP_MDIO_PHYp(port)); |
| 682 | /* Deactivate MDIO auto polling */ |
| 683 | gswip_mdio_mask(priv, BIT(port), 0, GSWIP_MDIO_MDC_CFG0); |
| 684 | } |
| 685 | |
| 686 | gswip_switch_mask(priv, GSWIP_FDMA_PCTRL_EN, 0, |
| 687 | GSWIP_FDMA_PCTRLp(port)); |
| 688 | gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0, |
| 689 | GSWIP_SDMA_PCTRLp(port)); |
| 690 | } |
| 691 | |
| 692 | static int gswip_pce_load_microcode(struct gswip_priv *priv) |
| 693 | { |
| 694 | int i; |
| 695 | int err; |
| 696 | |
| 697 | gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | |
| 698 | GSWIP_PCE_TBL_CTRL_OPMOD_MASK, |
| 699 | GSWIP_PCE_TBL_CTRL_OPMOD_ADWR, GSWIP_PCE_TBL_CTRL); |
| 700 | gswip_switch_w(priv, 0, GSWIP_PCE_TBL_MASK); |
| 701 | |
| 702 | for (i = 0; i < ARRAY_SIZE(gswip_pce_microcode); i++) { |
| 703 | gswip_switch_w(priv, i, GSWIP_PCE_TBL_ADDR); |
| 704 | gswip_switch_w(priv, gswip_pce_microcode[i].val_0, |
| 705 | GSWIP_PCE_TBL_VAL(0)); |
| 706 | gswip_switch_w(priv, gswip_pce_microcode[i].val_1, |
| 707 | GSWIP_PCE_TBL_VAL(1)); |
| 708 | gswip_switch_w(priv, gswip_pce_microcode[i].val_2, |
| 709 | GSWIP_PCE_TBL_VAL(2)); |
| 710 | gswip_switch_w(priv, gswip_pce_microcode[i].val_3, |
| 711 | GSWIP_PCE_TBL_VAL(3)); |
| 712 | |
| 713 | /* start the table access: */ |
| 714 | gswip_switch_mask(priv, 0, GSWIP_PCE_TBL_CTRL_BAS, |
| 715 | GSWIP_PCE_TBL_CTRL); |
| 716 | err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, |
| 717 | GSWIP_PCE_TBL_CTRL_BAS); |
| 718 | if (err) |
| 719 | return err; |
| 720 | } |
| 721 | |
| 722 | /* tell the switch that the microcode is loaded */ |
| 723 | gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MC_VALID, |
| 724 | GSWIP_PCE_GCTRL_0); |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 729 | static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port, |
| 730 | bool vlan_filtering) |
| 731 | { |
| 732 | struct gswip_priv *priv = ds->priv; |
| 733 | |
| 734 | if (vlan_filtering) { |
| 735 | /* Use port based VLAN tag */ |
| 736 | gswip_switch_mask(priv, |
| 737 | GSWIP_PCE_VCTRL_VSR, |
| 738 | GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR | |
| 739 | GSWIP_PCE_VCTRL_VEMR, |
| 740 | GSWIP_PCE_VCTRL(port)); |
| 741 | gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_TVM, 0, |
| 742 | GSWIP_PCE_PCTRL_0p(port)); |
| 743 | } else { |
| 744 | /* Use port based VLAN tag */ |
| 745 | gswip_switch_mask(priv, |
| 746 | GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR | |
| 747 | GSWIP_PCE_VCTRL_VEMR, |
| 748 | GSWIP_PCE_VCTRL_VSR, |
| 749 | GSWIP_PCE_VCTRL(port)); |
| 750 | gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_TVM, |
| 751 | GSWIP_PCE_PCTRL_0p(port)); |
| 752 | } |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 757 | static int gswip_setup(struct dsa_switch *ds) |
| 758 | { |
| 759 | struct gswip_priv *priv = ds->priv; |
| 760 | unsigned int cpu_port = priv->hw_info->cpu_port; |
| 761 | int i; |
| 762 | int err; |
| 763 | |
| 764 | gswip_switch_w(priv, GSWIP_SWRES_R0, GSWIP_SWRES); |
| 765 | usleep_range(5000, 10000); |
| 766 | gswip_switch_w(priv, 0, GSWIP_SWRES); |
| 767 | |
| 768 | /* disable port fetch/store dma on all ports */ |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 769 | for (i = 0; i < priv->hw_info->max_ports; i++) { |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 770 | gswip_port_disable(ds, i); |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 771 | gswip_port_vlan_filtering(ds, i, false); |
| 772 | } |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 773 | |
| 774 | /* enable Switch */ |
| 775 | gswip_mdio_mask(priv, 0, GSWIP_MDIO_GLOB_ENABLE, GSWIP_MDIO_GLOB); |
| 776 | |
| 777 | err = gswip_pce_load_microcode(priv); |
| 778 | if (err) { |
| 779 | dev_err(priv->dev, "writing PCE microcode failed, %i", err); |
| 780 | return err; |
| 781 | } |
| 782 | |
| 783 | /* Default unknown Broadcast/Multicast/Unicast port maps */ |
| 784 | gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP1); |
| 785 | gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP2); |
| 786 | gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP3); |
| 787 | |
| 788 | /* disable PHY auto polling */ |
| 789 | gswip_mdio_w(priv, 0x0, GSWIP_MDIO_MDC_CFG0); |
| 790 | /* Configure the MDIO Clock 2.5 MHz */ |
| 791 | gswip_mdio_mask(priv, 0xff, 0x09, GSWIP_MDIO_MDC_CFG1); |
| 792 | |
| 793 | /* Disable the xMII link */ |
| 794 | gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, 0); |
| 795 | gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, 1); |
| 796 | gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, 5); |
| 797 | |
| 798 | /* enable special tag insertion on cpu port */ |
| 799 | gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_STEN, |
| 800 | GSWIP_FDMA_PCTRLp(cpu_port)); |
| 801 | |
Hauke Mehrtens | 30d89383 | 2019-05-06 00:25:06 +0200 | [diff] [blame] | 802 | /* accept special tag in ingress direction */ |
| 803 | gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_INGRESS, |
| 804 | GSWIP_PCE_PCTRL_0p(cpu_port)); |
| 805 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 806 | gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN, |
| 807 | GSWIP_MAC_CTRL_2p(cpu_port)); |
| 808 | gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8, GSWIP_MAC_FLEN); |
| 809 | gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD, |
| 810 | GSWIP_BM_QUEUE_GCTRL); |
| 811 | |
| 812 | /* VLAN aware Switching */ |
| 813 | gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_VLAN, GSWIP_PCE_GCTRL_0); |
| 814 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 815 | /* Flush MAC Table */ |
| 816 | gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MTFL, GSWIP_PCE_GCTRL_0); |
| 817 | |
| 818 | err = gswip_switch_r_timeout(priv, GSWIP_PCE_GCTRL_0, |
| 819 | GSWIP_PCE_GCTRL_0_MTFL); |
| 820 | if (err) { |
| 821 | dev_err(priv->dev, "MAC flushing didn't finish\n"); |
| 822 | return err; |
| 823 | } |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 824 | |
| 825 | gswip_port_enable(ds, cpu_port, NULL); |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | static enum dsa_tag_protocol gswip_get_tag_protocol(struct dsa_switch *ds, |
| 830 | int port) |
| 831 | { |
| 832 | return DSA_TAG_PROTO_GSWIP; |
| 833 | } |
| 834 | |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 835 | static int gswip_vlan_active_create(struct gswip_priv *priv, |
| 836 | struct net_device *bridge, |
| 837 | int fid, u16 vid) |
| 838 | { |
| 839 | struct gswip_pce_table_entry vlan_active = {0,}; |
| 840 | unsigned int max_ports = priv->hw_info->max_ports; |
| 841 | int idx = -1; |
| 842 | int err; |
| 843 | int i; |
| 844 | |
| 845 | /* Look for a free slot */ |
| 846 | for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { |
| 847 | if (!priv->vlans[i].bridge) { |
| 848 | idx = i; |
| 849 | break; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (idx == -1) |
| 854 | return -ENOSPC; |
| 855 | |
| 856 | if (fid == -1) |
| 857 | fid = idx; |
| 858 | |
| 859 | vlan_active.index = idx; |
| 860 | vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN; |
| 861 | vlan_active.key[0] = vid; |
| 862 | vlan_active.val[0] = fid; |
| 863 | vlan_active.valid = true; |
| 864 | |
| 865 | err = gswip_pce_table_entry_write(priv, &vlan_active); |
| 866 | if (err) { |
| 867 | dev_err(priv->dev, "failed to write active VLAN: %d\n", err); |
| 868 | return err; |
| 869 | } |
| 870 | |
| 871 | priv->vlans[idx].bridge = bridge; |
| 872 | priv->vlans[idx].vid = vid; |
| 873 | priv->vlans[idx].fid = fid; |
| 874 | |
| 875 | return idx; |
| 876 | } |
| 877 | |
| 878 | static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx) |
| 879 | { |
| 880 | struct gswip_pce_table_entry vlan_active = {0,}; |
| 881 | int err; |
| 882 | |
| 883 | vlan_active.index = idx; |
| 884 | vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN; |
| 885 | vlan_active.valid = false; |
| 886 | err = gswip_pce_table_entry_write(priv, &vlan_active); |
| 887 | if (err) |
| 888 | dev_err(priv->dev, "failed to delete active VLAN: %d\n", err); |
| 889 | priv->vlans[idx].bridge = NULL; |
| 890 | |
| 891 | return err; |
| 892 | } |
| 893 | |
| 894 | static int gswip_vlan_add_unaware(struct gswip_priv *priv, |
| 895 | struct net_device *bridge, int port) |
| 896 | { |
| 897 | struct gswip_pce_table_entry vlan_mapping = {0,}; |
| 898 | unsigned int max_ports = priv->hw_info->max_ports; |
| 899 | unsigned int cpu_port = priv->hw_info->cpu_port; |
| 900 | bool active_vlan_created = false; |
| 901 | int idx = -1; |
| 902 | int i; |
| 903 | int err; |
| 904 | |
| 905 | /* Check if there is already a page for this bridge */ |
| 906 | for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { |
| 907 | if (priv->vlans[i].bridge == bridge) { |
| 908 | idx = i; |
| 909 | break; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | /* If this bridge is not programmed yet, add a Active VLAN table |
| 914 | * entry in a free slot and prepare the VLAN mapping table entry. |
| 915 | */ |
| 916 | if (idx == -1) { |
| 917 | idx = gswip_vlan_active_create(priv, bridge, -1, 0); |
| 918 | if (idx < 0) |
| 919 | return idx; |
| 920 | active_vlan_created = true; |
| 921 | |
| 922 | vlan_mapping.index = idx; |
| 923 | vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; |
| 924 | /* VLAN ID byte, maps to the VLAN ID of vlan active table */ |
| 925 | vlan_mapping.val[0] = 0; |
| 926 | } else { |
| 927 | /* Read the existing VLAN mapping entry from the switch */ |
| 928 | vlan_mapping.index = idx; |
| 929 | vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; |
| 930 | err = gswip_pce_table_entry_read(priv, &vlan_mapping); |
| 931 | if (err) { |
| 932 | dev_err(priv->dev, "failed to read VLAN mapping: %d\n", |
| 933 | err); |
| 934 | return err; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /* Update the VLAN mapping entry and write it to the switch */ |
| 939 | vlan_mapping.val[1] |= BIT(cpu_port); |
| 940 | vlan_mapping.val[1] |= BIT(port); |
| 941 | err = gswip_pce_table_entry_write(priv, &vlan_mapping); |
| 942 | if (err) { |
| 943 | dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); |
| 944 | /* In case an Active VLAN was creaetd delete it again */ |
| 945 | if (active_vlan_created) |
| 946 | gswip_vlan_active_remove(priv, idx); |
| 947 | return err; |
| 948 | } |
| 949 | |
| 950 | gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port)); |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static int gswip_vlan_remove(struct gswip_priv *priv, |
| 955 | struct net_device *bridge, int port, |
| 956 | u16 vid, bool pvid, bool vlan_aware) |
| 957 | { |
| 958 | struct gswip_pce_table_entry vlan_mapping = {0,}; |
| 959 | unsigned int max_ports = priv->hw_info->max_ports; |
| 960 | unsigned int cpu_port = priv->hw_info->cpu_port; |
| 961 | int idx = -1; |
| 962 | int i; |
| 963 | int err; |
| 964 | |
| 965 | /* Check if there is already a page for this bridge */ |
| 966 | for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { |
| 967 | if (priv->vlans[i].bridge == bridge && |
| 968 | (!vlan_aware || priv->vlans[i].vid == vid)) { |
| 969 | idx = i; |
| 970 | break; |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | if (idx == -1) { |
| 975 | dev_err(priv->dev, "bridge to leave does not exists\n"); |
| 976 | return -ENOENT; |
| 977 | } |
| 978 | |
| 979 | vlan_mapping.index = idx; |
| 980 | vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; |
| 981 | err = gswip_pce_table_entry_read(priv, &vlan_mapping); |
| 982 | if (err) { |
| 983 | dev_err(priv->dev, "failed to read VLAN mapping: %d\n", err); |
| 984 | return err; |
| 985 | } |
| 986 | |
| 987 | vlan_mapping.val[1] &= ~BIT(port); |
| 988 | vlan_mapping.val[2] &= ~BIT(port); |
| 989 | err = gswip_pce_table_entry_write(priv, &vlan_mapping); |
| 990 | if (err) { |
| 991 | dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); |
| 992 | return err; |
| 993 | } |
| 994 | |
| 995 | /* In case all ports are removed from the bridge, remove the VLAN */ |
| 996 | if ((vlan_mapping.val[1] & ~BIT(cpu_port)) == 0) { |
| 997 | err = gswip_vlan_active_remove(priv, idx); |
| 998 | if (err) { |
| 999 | dev_err(priv->dev, "failed to write active VLAN: %d\n", |
| 1000 | err); |
| 1001 | return err; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | /* GSWIP 2.2 (GRX300) and later program here the VID directly. */ |
| 1006 | if (pvid) |
| 1007 | gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port)); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static int gswip_port_bridge_join(struct dsa_switch *ds, int port, |
| 1013 | struct net_device *bridge) |
| 1014 | { |
| 1015 | struct gswip_priv *priv = ds->priv; |
| 1016 | int err; |
| 1017 | |
| 1018 | err = gswip_vlan_add_unaware(priv, bridge, port); |
| 1019 | if (err) |
| 1020 | return err; |
| 1021 | return gswip_add_single_port_br(priv, port, false); |
| 1022 | } |
| 1023 | |
| 1024 | static void gswip_port_bridge_leave(struct dsa_switch *ds, int port, |
| 1025 | struct net_device *bridge) |
| 1026 | { |
| 1027 | struct gswip_priv *priv = ds->priv; |
| 1028 | |
| 1029 | gswip_add_single_port_br(priv, port, true); |
| 1030 | |
| 1031 | gswip_vlan_remove(priv, bridge, port, 0, true, false); |
| 1032 | } |
| 1033 | |
| 1034 | static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) |
| 1035 | { |
| 1036 | struct gswip_priv *priv = ds->priv; |
| 1037 | u32 stp_state; |
| 1038 | |
| 1039 | switch (state) { |
| 1040 | case BR_STATE_DISABLED: |
| 1041 | gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0, |
| 1042 | GSWIP_SDMA_PCTRLp(port)); |
| 1043 | return; |
| 1044 | case BR_STATE_BLOCKING: |
| 1045 | case BR_STATE_LISTENING: |
| 1046 | stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LISTEN; |
| 1047 | break; |
| 1048 | case BR_STATE_LEARNING: |
| 1049 | stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LEARNING; |
| 1050 | break; |
| 1051 | case BR_STATE_FORWARDING: |
| 1052 | stp_state = GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING; |
| 1053 | break; |
| 1054 | default: |
| 1055 | dev_err(priv->dev, "invalid STP state: %d\n", state); |
| 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN, |
| 1060 | GSWIP_SDMA_PCTRLp(port)); |
| 1061 | gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_PSTATE_MASK, stp_state, |
| 1062 | GSWIP_PCE_PCTRL_0p(port)); |
| 1063 | } |
| 1064 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1065 | static void gswip_phylink_validate(struct dsa_switch *ds, int port, |
| 1066 | unsigned long *supported, |
| 1067 | struct phylink_link_state *state) |
| 1068 | { |
| 1069 | __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; |
| 1070 | |
| 1071 | switch (port) { |
| 1072 | case 0: |
| 1073 | case 1: |
| 1074 | if (!phy_interface_mode_is_rgmii(state->interface) && |
| 1075 | state->interface != PHY_INTERFACE_MODE_MII && |
| 1076 | state->interface != PHY_INTERFACE_MODE_REVMII && |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1077 | state->interface != PHY_INTERFACE_MODE_RMII) |
| 1078 | goto unsupported; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1079 | break; |
| 1080 | case 2: |
| 1081 | case 3: |
| 1082 | case 4: |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1083 | if (state->interface != PHY_INTERFACE_MODE_INTERNAL) |
| 1084 | goto unsupported; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1085 | break; |
| 1086 | case 5: |
| 1087 | if (!phy_interface_mode_is_rgmii(state->interface) && |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1088 | state->interface != PHY_INTERFACE_MODE_INTERNAL) |
| 1089 | goto unsupported; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1090 | break; |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1091 | default: |
| 1092 | bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 1093 | dev_err(ds->dev, "Unsupported port: %i\n", port); |
| 1094 | return; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /* Allow all the expected bits */ |
| 1098 | phylink_set(mask, Autoneg); |
| 1099 | phylink_set_port_modes(mask); |
| 1100 | phylink_set(mask, Pause); |
| 1101 | phylink_set(mask, Asym_Pause); |
| 1102 | |
| 1103 | /* With the exclusion of MII and Reverse MII, we support Gigabit, |
| 1104 | * including Half duplex |
| 1105 | */ |
| 1106 | if (state->interface != PHY_INTERFACE_MODE_MII && |
| 1107 | state->interface != PHY_INTERFACE_MODE_REVMII) { |
| 1108 | phylink_set(mask, 1000baseT_Full); |
| 1109 | phylink_set(mask, 1000baseT_Half); |
| 1110 | } |
| 1111 | |
| 1112 | phylink_set(mask, 10baseT_Half); |
| 1113 | phylink_set(mask, 10baseT_Full); |
| 1114 | phylink_set(mask, 100baseT_Half); |
| 1115 | phylink_set(mask, 100baseT_Full); |
| 1116 | |
| 1117 | bitmap_and(supported, supported, mask, |
| 1118 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 1119 | bitmap_and(state->advertising, state->advertising, mask, |
| 1120 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1121 | return; |
| 1122 | |
| 1123 | unsupported: |
| 1124 | bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 1125 | dev_err(ds->dev, "Unsupported interface: %d\n", state->interface); |
| 1126 | return; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static void gswip_phylink_mac_config(struct dsa_switch *ds, int port, |
| 1130 | unsigned int mode, |
| 1131 | const struct phylink_link_state *state) |
| 1132 | { |
| 1133 | struct gswip_priv *priv = ds->priv; |
| 1134 | u32 miicfg = 0; |
| 1135 | |
| 1136 | miicfg |= GSWIP_MII_CFG_LDCLKDIS; |
| 1137 | |
| 1138 | switch (state->interface) { |
| 1139 | case PHY_INTERFACE_MODE_MII: |
| 1140 | case PHY_INTERFACE_MODE_INTERNAL: |
| 1141 | miicfg |= GSWIP_MII_CFG_MODE_MIIM; |
| 1142 | break; |
| 1143 | case PHY_INTERFACE_MODE_REVMII: |
| 1144 | miicfg |= GSWIP_MII_CFG_MODE_MIIP; |
| 1145 | break; |
| 1146 | case PHY_INTERFACE_MODE_RMII: |
| 1147 | miicfg |= GSWIP_MII_CFG_MODE_RMIIM; |
| 1148 | break; |
| 1149 | case PHY_INTERFACE_MODE_RGMII: |
| 1150 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 1151 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 1152 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 1153 | miicfg |= GSWIP_MII_CFG_MODE_RGMII; |
| 1154 | break; |
| 1155 | default: |
| 1156 | dev_err(ds->dev, |
| 1157 | "Unsupported interface: %d\n", state->interface); |
| 1158 | return; |
| 1159 | } |
| 1160 | gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_MODE_MASK, miicfg, port); |
| 1161 | |
| 1162 | switch (state->interface) { |
| 1163 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 1164 | gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK | |
| 1165 | GSWIP_MII_PCDU_RXDLY_MASK, 0, port); |
| 1166 | break; |
| 1167 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 1168 | gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_RXDLY_MASK, 0, port); |
| 1169 | break; |
| 1170 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 1171 | gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK, 0, port); |
| 1172 | break; |
| 1173 | default: |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | static void gswip_phylink_mac_link_down(struct dsa_switch *ds, int port, |
| 1179 | unsigned int mode, |
| 1180 | phy_interface_t interface) |
| 1181 | { |
| 1182 | struct gswip_priv *priv = ds->priv; |
| 1183 | |
| 1184 | gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, port); |
| 1185 | } |
| 1186 | |
| 1187 | static void gswip_phylink_mac_link_up(struct dsa_switch *ds, int port, |
| 1188 | unsigned int mode, |
| 1189 | phy_interface_t interface, |
| 1190 | struct phy_device *phydev) |
| 1191 | { |
| 1192 | struct gswip_priv *priv = ds->priv; |
| 1193 | |
| 1194 | /* Enable the xMII interface only for the external PHY */ |
| 1195 | if (interface != PHY_INTERFACE_MODE_INTERNAL) |
| 1196 | gswip_mii_mask_cfg(priv, 0, GSWIP_MII_CFG_EN, port); |
| 1197 | } |
| 1198 | |
| 1199 | static void gswip_get_strings(struct dsa_switch *ds, int port, u32 stringset, |
| 1200 | uint8_t *data) |
| 1201 | { |
| 1202 | int i; |
| 1203 | |
| 1204 | if (stringset != ETH_SS_STATS) |
| 1205 | return; |
| 1206 | |
| 1207 | for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) |
| 1208 | strncpy(data + i * ETH_GSTRING_LEN, gswip_rmon_cnt[i].name, |
| 1209 | ETH_GSTRING_LEN); |
| 1210 | } |
| 1211 | |
| 1212 | static u32 gswip_bcm_ram_entry_read(struct gswip_priv *priv, u32 table, |
| 1213 | u32 index) |
| 1214 | { |
| 1215 | u32 result; |
| 1216 | int err; |
| 1217 | |
| 1218 | gswip_switch_w(priv, index, GSWIP_BM_RAM_ADDR); |
| 1219 | gswip_switch_mask(priv, GSWIP_BM_RAM_CTRL_ADDR_MASK | |
| 1220 | GSWIP_BM_RAM_CTRL_OPMOD, |
| 1221 | table | GSWIP_BM_RAM_CTRL_BAS, |
| 1222 | GSWIP_BM_RAM_CTRL); |
| 1223 | |
| 1224 | err = gswip_switch_r_timeout(priv, GSWIP_BM_RAM_CTRL, |
| 1225 | GSWIP_BM_RAM_CTRL_BAS); |
| 1226 | if (err) { |
| 1227 | dev_err(priv->dev, "timeout while reading table: %u, index: %u", |
| 1228 | table, index); |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | result = gswip_switch_r(priv, GSWIP_BM_RAM_VAL(0)); |
| 1233 | result |= gswip_switch_r(priv, GSWIP_BM_RAM_VAL(1)) << 16; |
| 1234 | |
| 1235 | return result; |
| 1236 | } |
| 1237 | |
| 1238 | static void gswip_get_ethtool_stats(struct dsa_switch *ds, int port, |
| 1239 | uint64_t *data) |
| 1240 | { |
| 1241 | struct gswip_priv *priv = ds->priv; |
| 1242 | const struct gswip_rmon_cnt_desc *rmon_cnt; |
| 1243 | int i; |
| 1244 | u64 high; |
| 1245 | |
| 1246 | for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) { |
| 1247 | rmon_cnt = &gswip_rmon_cnt[i]; |
| 1248 | |
| 1249 | data[i] = gswip_bcm_ram_entry_read(priv, port, |
| 1250 | rmon_cnt->offset); |
| 1251 | if (rmon_cnt->size == 2) { |
| 1252 | high = gswip_bcm_ram_entry_read(priv, port, |
| 1253 | rmon_cnt->offset + 1); |
| 1254 | data[i] |= high << 32; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | static int gswip_get_sset_count(struct dsa_switch *ds, int port, int sset) |
| 1260 | { |
| 1261 | if (sset != ETH_SS_STATS) |
| 1262 | return 0; |
| 1263 | |
| 1264 | return ARRAY_SIZE(gswip_rmon_cnt); |
| 1265 | } |
| 1266 | |
| 1267 | static const struct dsa_switch_ops gswip_switch_ops = { |
| 1268 | .get_tag_protocol = gswip_get_tag_protocol, |
| 1269 | .setup = gswip_setup, |
| 1270 | .port_enable = gswip_port_enable, |
| 1271 | .port_disable = gswip_port_disable, |
Hauke Mehrtens | 8206e0c | 2019-05-06 00:25:07 +0200 | [diff] [blame^] | 1272 | .port_bridge_join = gswip_port_bridge_join, |
| 1273 | .port_bridge_leave = gswip_port_bridge_leave, |
| 1274 | .port_stp_state_set = gswip_port_stp_state_set, |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1275 | .phylink_validate = gswip_phylink_validate, |
| 1276 | .phylink_mac_config = gswip_phylink_mac_config, |
| 1277 | .phylink_mac_link_down = gswip_phylink_mac_link_down, |
| 1278 | .phylink_mac_link_up = gswip_phylink_mac_link_up, |
| 1279 | .get_strings = gswip_get_strings, |
| 1280 | .get_ethtool_stats = gswip_get_ethtool_stats, |
| 1281 | .get_sset_count = gswip_get_sset_count, |
| 1282 | }; |
| 1283 | |
| 1284 | static const struct xway_gphy_match_data xrx200a1x_gphy_data = { |
| 1285 | .fe_firmware_name = "lantiq/xrx200_phy22f_a14.bin", |
| 1286 | .ge_firmware_name = "lantiq/xrx200_phy11g_a14.bin", |
| 1287 | }; |
| 1288 | |
| 1289 | static const struct xway_gphy_match_data xrx200a2x_gphy_data = { |
| 1290 | .fe_firmware_name = "lantiq/xrx200_phy22f_a22.bin", |
| 1291 | .ge_firmware_name = "lantiq/xrx200_phy11g_a22.bin", |
| 1292 | }; |
| 1293 | |
| 1294 | static const struct xway_gphy_match_data xrx300_gphy_data = { |
| 1295 | .fe_firmware_name = "lantiq/xrx300_phy22f_a21.bin", |
| 1296 | .ge_firmware_name = "lantiq/xrx300_phy11g_a21.bin", |
| 1297 | }; |
| 1298 | |
| 1299 | static const struct of_device_id xway_gphy_match[] = { |
| 1300 | { .compatible = "lantiq,xrx200-gphy-fw", .data = NULL }, |
| 1301 | { .compatible = "lantiq,xrx200a1x-gphy-fw", .data = &xrx200a1x_gphy_data }, |
| 1302 | { .compatible = "lantiq,xrx200a2x-gphy-fw", .data = &xrx200a2x_gphy_data }, |
| 1303 | { .compatible = "lantiq,xrx300-gphy-fw", .data = &xrx300_gphy_data }, |
| 1304 | { .compatible = "lantiq,xrx330-gphy-fw", .data = &xrx300_gphy_data }, |
| 1305 | {}, |
| 1306 | }; |
| 1307 | |
| 1308 | static int gswip_gphy_fw_load(struct gswip_priv *priv, struct gswip_gphy_fw *gphy_fw) |
| 1309 | { |
| 1310 | struct device *dev = priv->dev; |
| 1311 | const struct firmware *fw; |
| 1312 | void *fw_addr; |
| 1313 | dma_addr_t dma_addr; |
| 1314 | dma_addr_t dev_addr; |
| 1315 | size_t size; |
| 1316 | int ret; |
| 1317 | |
| 1318 | ret = clk_prepare_enable(gphy_fw->clk_gate); |
| 1319 | if (ret) |
| 1320 | return ret; |
| 1321 | |
| 1322 | reset_control_assert(gphy_fw->reset); |
| 1323 | |
| 1324 | ret = request_firmware(&fw, gphy_fw->fw_name, dev); |
| 1325 | if (ret) { |
| 1326 | dev_err(dev, "failed to load firmware: %s, error: %i\n", |
| 1327 | gphy_fw->fw_name, ret); |
| 1328 | return ret; |
| 1329 | } |
| 1330 | |
| 1331 | /* GPHY cores need the firmware code in a persistent and contiguous |
| 1332 | * memory area with a 16 kB boundary aligned start address. |
| 1333 | */ |
| 1334 | size = fw->size + XRX200_GPHY_FW_ALIGN; |
| 1335 | |
| 1336 | fw_addr = dmam_alloc_coherent(dev, size, &dma_addr, GFP_KERNEL); |
| 1337 | if (fw_addr) { |
| 1338 | fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN); |
| 1339 | dev_addr = ALIGN(dma_addr, XRX200_GPHY_FW_ALIGN); |
| 1340 | memcpy(fw_addr, fw->data, fw->size); |
| 1341 | } else { |
| 1342 | dev_err(dev, "failed to alloc firmware memory\n"); |
| 1343 | release_firmware(fw); |
| 1344 | return -ENOMEM; |
| 1345 | } |
| 1346 | |
| 1347 | release_firmware(fw); |
| 1348 | |
| 1349 | ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, dev_addr); |
| 1350 | if (ret) |
| 1351 | return ret; |
| 1352 | |
| 1353 | reset_control_deassert(gphy_fw->reset); |
| 1354 | |
| 1355 | return ret; |
| 1356 | } |
| 1357 | |
| 1358 | static int gswip_gphy_fw_probe(struct gswip_priv *priv, |
| 1359 | struct gswip_gphy_fw *gphy_fw, |
| 1360 | struct device_node *gphy_fw_np, int i) |
| 1361 | { |
| 1362 | struct device *dev = priv->dev; |
| 1363 | u32 gphy_mode; |
| 1364 | int ret; |
| 1365 | char gphyname[10]; |
| 1366 | |
| 1367 | snprintf(gphyname, sizeof(gphyname), "gphy%d", i); |
| 1368 | |
| 1369 | gphy_fw->clk_gate = devm_clk_get(dev, gphyname); |
| 1370 | if (IS_ERR(gphy_fw->clk_gate)) { |
| 1371 | dev_err(dev, "Failed to lookup gate clock\n"); |
| 1372 | return PTR_ERR(gphy_fw->clk_gate); |
| 1373 | } |
| 1374 | |
| 1375 | ret = of_property_read_u32(gphy_fw_np, "reg", &gphy_fw->fw_addr_offset); |
| 1376 | if (ret) |
| 1377 | return ret; |
| 1378 | |
| 1379 | ret = of_property_read_u32(gphy_fw_np, "lantiq,gphy-mode", &gphy_mode); |
| 1380 | /* Default to GE mode */ |
| 1381 | if (ret) |
| 1382 | gphy_mode = GPHY_MODE_GE; |
| 1383 | |
| 1384 | switch (gphy_mode) { |
| 1385 | case GPHY_MODE_FE: |
| 1386 | gphy_fw->fw_name = priv->gphy_fw_name_cfg->fe_firmware_name; |
| 1387 | break; |
| 1388 | case GPHY_MODE_GE: |
| 1389 | gphy_fw->fw_name = priv->gphy_fw_name_cfg->ge_firmware_name; |
| 1390 | break; |
| 1391 | default: |
| 1392 | dev_err(dev, "Unknown GPHY mode %d\n", gphy_mode); |
| 1393 | return -EINVAL; |
| 1394 | } |
| 1395 | |
| 1396 | gphy_fw->reset = of_reset_control_array_get_exclusive(gphy_fw_np); |
Wei Yongjun | f592e0b | 2018-09-15 01:33:38 +0000 | [diff] [blame] | 1397 | if (IS_ERR(gphy_fw->reset)) { |
| 1398 | if (PTR_ERR(gphy_fw->reset) != -EPROBE_DEFER) |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1399 | dev_err(dev, "Failed to lookup gphy reset\n"); |
Wei Yongjun | f592e0b | 2018-09-15 01:33:38 +0000 | [diff] [blame] | 1400 | return PTR_ERR(gphy_fw->reset); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | return gswip_gphy_fw_load(priv, gphy_fw); |
| 1404 | } |
| 1405 | |
| 1406 | static void gswip_gphy_fw_remove(struct gswip_priv *priv, |
| 1407 | struct gswip_gphy_fw *gphy_fw) |
| 1408 | { |
| 1409 | int ret; |
| 1410 | |
| 1411 | /* check if the device was fully probed */ |
| 1412 | if (!gphy_fw->fw_name) |
| 1413 | return; |
| 1414 | |
| 1415 | ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, 0); |
| 1416 | if (ret) |
| 1417 | dev_err(priv->dev, "can not reset GPHY FW pointer"); |
| 1418 | |
| 1419 | clk_disable_unprepare(gphy_fw->clk_gate); |
| 1420 | |
| 1421 | reset_control_put(gphy_fw->reset); |
| 1422 | } |
| 1423 | |
| 1424 | static int gswip_gphy_fw_list(struct gswip_priv *priv, |
| 1425 | struct device_node *gphy_fw_list_np, u32 version) |
| 1426 | { |
| 1427 | struct device *dev = priv->dev; |
| 1428 | struct device_node *gphy_fw_np; |
| 1429 | const struct of_device_id *match; |
| 1430 | int err; |
| 1431 | int i = 0; |
| 1432 | |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1433 | /* The VRX200 rev 1.1 uses the GSWIP 2.0 and needs the older |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1434 | * GPHY firmware. The VRX200 rev 1.2 uses the GSWIP 2.1 and also |
| 1435 | * needs a different GPHY firmware. |
| 1436 | */ |
| 1437 | if (of_device_is_compatible(gphy_fw_list_np, "lantiq,xrx200-gphy-fw")) { |
| 1438 | switch (version) { |
| 1439 | case GSWIP_VERSION_2_0: |
| 1440 | priv->gphy_fw_name_cfg = &xrx200a1x_gphy_data; |
| 1441 | break; |
| 1442 | case GSWIP_VERSION_2_1: |
| 1443 | priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data; |
| 1444 | break; |
| 1445 | default: |
| 1446 | dev_err(dev, "unknown GSWIP version: 0x%x", version); |
| 1447 | return -ENOENT; |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | match = of_match_node(xway_gphy_match, gphy_fw_list_np); |
| 1452 | if (match && match->data) |
| 1453 | priv->gphy_fw_name_cfg = match->data; |
| 1454 | |
| 1455 | if (!priv->gphy_fw_name_cfg) { |
| 1456 | dev_err(dev, "GPHY compatible type not supported"); |
| 1457 | return -ENOENT; |
| 1458 | } |
| 1459 | |
| 1460 | priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np); |
| 1461 | if (!priv->num_gphy_fw) |
| 1462 | return -ENOENT; |
| 1463 | |
| 1464 | priv->rcu_regmap = syscon_regmap_lookup_by_phandle(gphy_fw_list_np, |
| 1465 | "lantiq,rcu"); |
| 1466 | if (IS_ERR(priv->rcu_regmap)) |
| 1467 | return PTR_ERR(priv->rcu_regmap); |
| 1468 | |
| 1469 | priv->gphy_fw = devm_kmalloc_array(dev, priv->num_gphy_fw, |
| 1470 | sizeof(*priv->gphy_fw), |
| 1471 | GFP_KERNEL | __GFP_ZERO); |
| 1472 | if (!priv->gphy_fw) |
| 1473 | return -ENOMEM; |
| 1474 | |
| 1475 | for_each_available_child_of_node(gphy_fw_list_np, gphy_fw_np) { |
| 1476 | err = gswip_gphy_fw_probe(priv, &priv->gphy_fw[i], |
| 1477 | gphy_fw_np, i); |
| 1478 | if (err) |
| 1479 | goto remove_gphy; |
| 1480 | i++; |
| 1481 | } |
| 1482 | |
| 1483 | return 0; |
| 1484 | |
| 1485 | remove_gphy: |
| 1486 | for (i = 0; i < priv->num_gphy_fw; i++) |
| 1487 | gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); |
| 1488 | return err; |
| 1489 | } |
| 1490 | |
| 1491 | static int gswip_probe(struct platform_device *pdev) |
| 1492 | { |
| 1493 | struct gswip_priv *priv; |
| 1494 | struct resource *gswip_res, *mdio_res, *mii_res; |
| 1495 | struct device_node *mdio_np, *gphy_fw_np; |
| 1496 | struct device *dev = &pdev->dev; |
| 1497 | int err; |
| 1498 | int i; |
| 1499 | u32 version; |
| 1500 | |
| 1501 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 1502 | if (!priv) |
| 1503 | return -ENOMEM; |
| 1504 | |
| 1505 | gswip_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1506 | priv->gswip = devm_ioremap_resource(dev, gswip_res); |
Wei Yongjun | f5de8bf | 2018-09-15 01:33:21 +0000 | [diff] [blame] | 1507 | if (IS_ERR(priv->gswip)) |
| 1508 | return PTR_ERR(priv->gswip); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1509 | |
| 1510 | mdio_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1511 | priv->mdio = devm_ioremap_resource(dev, mdio_res); |
Wei Yongjun | f5de8bf | 2018-09-15 01:33:21 +0000 | [diff] [blame] | 1512 | if (IS_ERR(priv->mdio)) |
| 1513 | return PTR_ERR(priv->mdio); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1514 | |
| 1515 | mii_res = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
| 1516 | priv->mii = devm_ioremap_resource(dev, mii_res); |
Wei Yongjun | f5de8bf | 2018-09-15 01:33:21 +0000 | [diff] [blame] | 1517 | if (IS_ERR(priv->mii)) |
| 1518 | return PTR_ERR(priv->mii); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1519 | |
| 1520 | priv->hw_info = of_device_get_match_data(dev); |
| 1521 | if (!priv->hw_info) |
| 1522 | return -EINVAL; |
| 1523 | |
| 1524 | priv->ds = dsa_switch_alloc(dev, priv->hw_info->max_ports); |
| 1525 | if (!priv->ds) |
| 1526 | return -ENOMEM; |
| 1527 | |
| 1528 | priv->ds->priv = priv; |
| 1529 | priv->ds->ops = &gswip_switch_ops; |
| 1530 | priv->dev = dev; |
| 1531 | version = gswip_switch_r(priv, GSWIP_VERSION); |
| 1532 | |
| 1533 | /* bring up the mdio bus */ |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1534 | gphy_fw_np = of_get_compatible_child(dev->of_node, "lantiq,gphy-fw"); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1535 | if (gphy_fw_np) { |
| 1536 | err = gswip_gphy_fw_list(priv, gphy_fw_np, version); |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1537 | of_node_put(gphy_fw_np); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1538 | if (err) { |
| 1539 | dev_err(dev, "gphy fw probe failed\n"); |
| 1540 | return err; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | /* bring up the mdio bus */ |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1545 | mdio_np = of_get_compatible_child(dev->of_node, "lantiq,xrx200-mdio"); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1546 | if (mdio_np) { |
| 1547 | err = gswip_mdio(priv, mdio_np); |
| 1548 | if (err) { |
| 1549 | dev_err(dev, "mdio probe failed\n"); |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1550 | goto put_mdio_node; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | err = dsa_register_switch(priv->ds); |
| 1555 | if (err) { |
| 1556 | dev_err(dev, "dsa switch register failed: %i\n", err); |
| 1557 | goto mdio_bus; |
| 1558 | } |
Hauke Mehrtens | 0e630b5 | 2018-09-15 14:08:48 +0200 | [diff] [blame] | 1559 | if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) { |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1560 | dev_err(dev, "wrong CPU port defined, HW only supports port: %i", |
| 1561 | priv->hw_info->cpu_port); |
| 1562 | err = -EINVAL; |
Johan Hovold | aed13f2 | 2019-01-16 11:23:33 +0100 | [diff] [blame] | 1563 | goto disable_switch; |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | platform_set_drvdata(pdev, priv); |
| 1567 | |
| 1568 | dev_info(dev, "probed GSWIP version %lx mod %lx\n", |
| 1569 | (version & GSWIP_VERSION_REV_MASK) >> GSWIP_VERSION_REV_SHIFT, |
| 1570 | (version & GSWIP_VERSION_MOD_MASK) >> GSWIP_VERSION_MOD_SHIFT); |
| 1571 | return 0; |
| 1572 | |
Johan Hovold | aed13f2 | 2019-01-16 11:23:33 +0100 | [diff] [blame] | 1573 | disable_switch: |
| 1574 | gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); |
| 1575 | dsa_unregister_switch(priv->ds); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1576 | mdio_bus: |
| 1577 | if (mdio_np) |
| 1578 | mdiobus_unregister(priv->ds->slave_mii_bus); |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1579 | put_mdio_node: |
| 1580 | of_node_put(mdio_np); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1581 | for (i = 0; i < priv->num_gphy_fw; i++) |
| 1582 | gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); |
| 1583 | return err; |
| 1584 | } |
| 1585 | |
| 1586 | static int gswip_remove(struct platform_device *pdev) |
| 1587 | { |
| 1588 | struct gswip_priv *priv = platform_get_drvdata(pdev); |
| 1589 | int i; |
| 1590 | |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1591 | /* disable the switch */ |
| 1592 | gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); |
| 1593 | |
| 1594 | dsa_unregister_switch(priv->ds); |
| 1595 | |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1596 | if (priv->ds->slave_mii_bus) { |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1597 | mdiobus_unregister(priv->ds->slave_mii_bus); |
Johan Hovold | c8cbcb0 | 2019-01-16 11:23:34 +0100 | [diff] [blame] | 1598 | of_node_put(priv->ds->slave_mii_bus->dev.of_node); |
| 1599 | } |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1600 | |
| 1601 | for (i = 0; i < priv->num_gphy_fw; i++) |
| 1602 | gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); |
| 1603 | |
| 1604 | return 0; |
| 1605 | } |
| 1606 | |
| 1607 | static const struct gswip_hw_info gswip_xrx200 = { |
| 1608 | .max_ports = 7, |
| 1609 | .cpu_port = 6, |
| 1610 | }; |
| 1611 | |
| 1612 | static const struct of_device_id gswip_of_match[] = { |
| 1613 | { .compatible = "lantiq,xrx200-gswip", .data = &gswip_xrx200 }, |
| 1614 | {}, |
| 1615 | }; |
| 1616 | MODULE_DEVICE_TABLE(of, gswip_of_match); |
| 1617 | |
| 1618 | static struct platform_driver gswip_driver = { |
| 1619 | .probe = gswip_probe, |
| 1620 | .remove = gswip_remove, |
| 1621 | .driver = { |
| 1622 | .name = "gswip", |
| 1623 | .of_match_table = gswip_of_match, |
| 1624 | }, |
| 1625 | }; |
| 1626 | |
| 1627 | module_platform_driver(gswip_driver); |
| 1628 | |
Hauke Mehrtens | cffde20 | 2019-02-22 20:11:13 +0100 | [diff] [blame] | 1629 | MODULE_FIRMWARE("lantiq/xrx300_phy11g_a21.bin"); |
| 1630 | MODULE_FIRMWARE("lantiq/xrx300_phy22f_a21.bin"); |
| 1631 | MODULE_FIRMWARE("lantiq/xrx200_phy11g_a14.bin"); |
| 1632 | MODULE_FIRMWARE("lantiq/xrx200_phy11g_a22.bin"); |
| 1633 | MODULE_FIRMWARE("lantiq/xrx200_phy22f_a14.bin"); |
| 1634 | MODULE_FIRMWARE("lantiq/xrx200_phy22f_a22.bin"); |
Hauke Mehrtens | 14fceff | 2018-09-09 22:20:39 +0200 | [diff] [blame] | 1635 | MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>"); |
| 1636 | MODULE_DESCRIPTION("Lantiq / Intel GSWIP driver"); |
| 1637 | MODULE_LICENSE("GPL v2"); |