1cb477c30SDaniel Golle // SPDX-License-Identifier: GPL-2.0 2cb477c30SDaniel Golle /* 3cb477c30SDaniel Golle * Lantiq / Intel GSWIP switch driver for VRX200, xRX300 and xRX330 SoCs 4cb477c30SDaniel Golle * 5cb477c30SDaniel Golle * Copyright (C) 2010 Lantiq Deutschland 6cb477c30SDaniel Golle * Copyright (C) 2012 John Crispin <john@phrozen.org> 7cb477c30SDaniel Golle * Copyright (C) 2017 - 2019 Hauke Mehrtens <hauke@hauke-m.de> 8cb477c30SDaniel Golle * 9cb477c30SDaniel Golle * The VLAN and bridge model the GSWIP hardware uses does not directly 10cb477c30SDaniel Golle * matches the model DSA uses. 11cb477c30SDaniel Golle * 12cb477c30SDaniel Golle * The hardware has 64 possible table entries for bridges with one VLAN 13cb477c30SDaniel Golle * ID, one flow id and a list of ports for each bridge. All entries which 14cb477c30SDaniel Golle * match the same flow ID are combined in the mac learning table, they 15cb477c30SDaniel Golle * act as one global bridge. 16cb477c30SDaniel Golle * The hardware does not support VLAN filter on the port, but on the 17cb477c30SDaniel Golle * bridge, this driver converts the DSA model to the hardware. 18cb477c30SDaniel Golle * 19cb477c30SDaniel Golle * The CPU gets all the exception frames which do not match any forwarding 20cb477c30SDaniel Golle * rule and the CPU port is also added to all bridges. This makes it possible 21cb477c30SDaniel Golle * to handle all the special cases easily in software. 22cb477c30SDaniel Golle * At the initialization the driver allocates one bridge table entry for 23cb477c30SDaniel Golle * each switch port which is used when the port is used without an 24cb477c30SDaniel Golle * explicit bridge. This prevents the frames from being forwarded 25cb477c30SDaniel Golle * between all LAN ports by default. 26cb477c30SDaniel Golle */ 27cb477c30SDaniel Golle 28cb477c30SDaniel Golle #include "lantiq_gswip.h" 29cb477c30SDaniel Golle #include "lantiq_pce.h" 30cb477c30SDaniel Golle 31cb477c30SDaniel Golle #include <linux/delay.h> 32cb477c30SDaniel Golle #include <linux/etherdevice.h> 33cb477c30SDaniel Golle #include <linux/firmware.h> 34cb477c30SDaniel Golle #include <linux/if_bridge.h> 35cb477c30SDaniel Golle #include <linux/if_vlan.h> 36cb477c30SDaniel Golle #include <linux/iopoll.h> 37cb477c30SDaniel Golle #include <linux/mfd/syscon.h> 38cb477c30SDaniel Golle #include <linux/module.h> 39cb477c30SDaniel Golle #include <linux/of_mdio.h> 40cb477c30SDaniel Golle #include <linux/of_net.h> 41cb477c30SDaniel Golle #include <linux/of_platform.h> 42cb477c30SDaniel Golle #include <linux/phy.h> 43cb477c30SDaniel Golle #include <linux/phylink.h> 44cb477c30SDaniel Golle #include <dt-bindings/mips/lantiq_rcu_gphy.h> 45cb477c30SDaniel Golle 46cb477c30SDaniel Golle struct xway_gphy_match_data { 47cb477c30SDaniel Golle char *fe_firmware_name; 48cb477c30SDaniel Golle char *ge_firmware_name; 49cb477c30SDaniel Golle }; 50cb477c30SDaniel Golle 51cb477c30SDaniel Golle struct gswip_pce_table_entry { 52cb477c30SDaniel Golle u16 index; // PCE_TBL_ADDR.ADDR = pData->table_index 53cb477c30SDaniel Golle u16 table; // PCE_TBL_CTRL.ADDR = pData->table 54cb477c30SDaniel Golle u16 key[8]; 55cb477c30SDaniel Golle u16 val[5]; 56cb477c30SDaniel Golle u16 mask; 57cb477c30SDaniel Golle u8 gmap; 58cb477c30SDaniel Golle bool type; 59cb477c30SDaniel Golle bool valid; 60cb477c30SDaniel Golle bool key_mode; 61cb477c30SDaniel Golle }; 62cb477c30SDaniel Golle 63cb477c30SDaniel Golle struct gswip_rmon_cnt_desc { 64cb477c30SDaniel Golle unsigned int size; 65cb477c30SDaniel Golle unsigned int offset; 66cb477c30SDaniel Golle const char *name; 67cb477c30SDaniel Golle }; 68cb477c30SDaniel Golle 69cb477c30SDaniel Golle #define MIB_DESC(_size, _offset, _name) {.size = _size, .offset = _offset, .name = _name} 70cb477c30SDaniel Golle 71cb477c30SDaniel Golle static const struct gswip_rmon_cnt_desc gswip_rmon_cnt[] = { 72cb477c30SDaniel Golle /** Receive Packet Count (only packets that are accepted and not discarded). */ 73cb477c30SDaniel Golle MIB_DESC(1, 0x1F, "RxGoodPkts"), 74cb477c30SDaniel Golle MIB_DESC(1, 0x23, "RxUnicastPkts"), 75cb477c30SDaniel Golle MIB_DESC(1, 0x22, "RxMulticastPkts"), 76cb477c30SDaniel Golle MIB_DESC(1, 0x21, "RxFCSErrorPkts"), 77cb477c30SDaniel Golle MIB_DESC(1, 0x1D, "RxUnderSizeGoodPkts"), 78cb477c30SDaniel Golle MIB_DESC(1, 0x1E, "RxUnderSizeErrorPkts"), 79cb477c30SDaniel Golle MIB_DESC(1, 0x1B, "RxOversizeGoodPkts"), 80cb477c30SDaniel Golle MIB_DESC(1, 0x1C, "RxOversizeErrorPkts"), 81cb477c30SDaniel Golle MIB_DESC(1, 0x20, "RxGoodPausePkts"), 82cb477c30SDaniel Golle MIB_DESC(1, 0x1A, "RxAlignErrorPkts"), 83cb477c30SDaniel Golle MIB_DESC(1, 0x12, "Rx64BytePkts"), 84cb477c30SDaniel Golle MIB_DESC(1, 0x13, "Rx127BytePkts"), 85cb477c30SDaniel Golle MIB_DESC(1, 0x14, "Rx255BytePkts"), 86cb477c30SDaniel Golle MIB_DESC(1, 0x15, "Rx511BytePkts"), 87cb477c30SDaniel Golle MIB_DESC(1, 0x16, "Rx1023BytePkts"), 88cb477c30SDaniel Golle /** Receive Size 1024-1522 (or more, if configured) Packet Count. */ 89cb477c30SDaniel Golle MIB_DESC(1, 0x17, "RxMaxBytePkts"), 90cb477c30SDaniel Golle MIB_DESC(1, 0x18, "RxDroppedPkts"), 91cb477c30SDaniel Golle MIB_DESC(1, 0x19, "RxFilteredPkts"), 92cb477c30SDaniel Golle MIB_DESC(2, 0x24, "RxGoodBytes"), 93cb477c30SDaniel Golle MIB_DESC(2, 0x26, "RxBadBytes"), 94cb477c30SDaniel Golle MIB_DESC(1, 0x11, "TxAcmDroppedPkts"), 95cb477c30SDaniel Golle MIB_DESC(1, 0x0C, "TxGoodPkts"), 96cb477c30SDaniel Golle MIB_DESC(1, 0x06, "TxUnicastPkts"), 97cb477c30SDaniel Golle MIB_DESC(1, 0x07, "TxMulticastPkts"), 98cb477c30SDaniel Golle MIB_DESC(1, 0x00, "Tx64BytePkts"), 99cb477c30SDaniel Golle MIB_DESC(1, 0x01, "Tx127BytePkts"), 100cb477c30SDaniel Golle MIB_DESC(1, 0x02, "Tx255BytePkts"), 101cb477c30SDaniel Golle MIB_DESC(1, 0x03, "Tx511BytePkts"), 102cb477c30SDaniel Golle MIB_DESC(1, 0x04, "Tx1023BytePkts"), 103cb477c30SDaniel Golle /** Transmit Size 1024-1522 (or more, if configured) Packet Count. */ 104cb477c30SDaniel Golle MIB_DESC(1, 0x05, "TxMaxBytePkts"), 105cb477c30SDaniel Golle MIB_DESC(1, 0x08, "TxSingleCollCount"), 106cb477c30SDaniel Golle MIB_DESC(1, 0x09, "TxMultCollCount"), 107cb477c30SDaniel Golle MIB_DESC(1, 0x0A, "TxLateCollCount"), 108cb477c30SDaniel Golle MIB_DESC(1, 0x0B, "TxExcessCollCount"), 109cb477c30SDaniel Golle MIB_DESC(1, 0x0D, "TxPauseCount"), 110cb477c30SDaniel Golle MIB_DESC(1, 0x10, "TxDroppedPkts"), 111cb477c30SDaniel Golle MIB_DESC(2, 0x0E, "TxGoodBytes"), 112cb477c30SDaniel Golle }; 113cb477c30SDaniel Golle 114cb477c30SDaniel Golle static u32 gswip_switch_r(struct gswip_priv *priv, u32 offset) 115cb477c30SDaniel Golle { 116cb477c30SDaniel Golle return __raw_readl(priv->gswip + (offset * 4)); 117cb477c30SDaniel Golle } 118cb477c30SDaniel Golle 119cb477c30SDaniel Golle static void gswip_switch_w(struct gswip_priv *priv, u32 val, u32 offset) 120cb477c30SDaniel Golle { 121cb477c30SDaniel Golle __raw_writel(val, priv->gswip + (offset * 4)); 122cb477c30SDaniel Golle } 123cb477c30SDaniel Golle 124cb477c30SDaniel Golle static void gswip_switch_mask(struct gswip_priv *priv, u32 clear, u32 set, 125cb477c30SDaniel Golle u32 offset) 126cb477c30SDaniel Golle { 127cb477c30SDaniel Golle u32 val = gswip_switch_r(priv, offset); 128cb477c30SDaniel Golle 129cb477c30SDaniel Golle val &= ~(clear); 130cb477c30SDaniel Golle val |= set; 131cb477c30SDaniel Golle gswip_switch_w(priv, val, offset); 132cb477c30SDaniel Golle } 133cb477c30SDaniel Golle 134cb477c30SDaniel Golle static u32 gswip_switch_r_timeout(struct gswip_priv *priv, u32 offset, 135cb477c30SDaniel Golle u32 cleared) 136cb477c30SDaniel Golle { 137cb477c30SDaniel Golle u32 val; 138cb477c30SDaniel Golle 139cb477c30SDaniel Golle return readx_poll_timeout(__raw_readl, priv->gswip + (offset * 4), val, 140cb477c30SDaniel Golle (val & cleared) == 0, 20, 50000); 141cb477c30SDaniel Golle } 142cb477c30SDaniel Golle 143cb477c30SDaniel Golle static u32 gswip_mdio_r(struct gswip_priv *priv, u32 offset) 144cb477c30SDaniel Golle { 145cb477c30SDaniel Golle return __raw_readl(priv->mdio + (offset * 4)); 146cb477c30SDaniel Golle } 147cb477c30SDaniel Golle 148cb477c30SDaniel Golle static void gswip_mdio_w(struct gswip_priv *priv, u32 val, u32 offset) 149cb477c30SDaniel Golle { 150cb477c30SDaniel Golle __raw_writel(val, priv->mdio + (offset * 4)); 151cb477c30SDaniel Golle } 152cb477c30SDaniel Golle 153cb477c30SDaniel Golle static void gswip_mdio_mask(struct gswip_priv *priv, u32 clear, u32 set, 154cb477c30SDaniel Golle u32 offset) 155cb477c30SDaniel Golle { 156cb477c30SDaniel Golle u32 val = gswip_mdio_r(priv, offset); 157cb477c30SDaniel Golle 158cb477c30SDaniel Golle val &= ~(clear); 159cb477c30SDaniel Golle val |= set; 160cb477c30SDaniel Golle gswip_mdio_w(priv, val, offset); 161cb477c30SDaniel Golle } 162cb477c30SDaniel Golle 163cb477c30SDaniel Golle static u32 gswip_mii_r(struct gswip_priv *priv, u32 offset) 164cb477c30SDaniel Golle { 165cb477c30SDaniel Golle return __raw_readl(priv->mii + (offset * 4)); 166cb477c30SDaniel Golle } 167cb477c30SDaniel Golle 168cb477c30SDaniel Golle static void gswip_mii_w(struct gswip_priv *priv, u32 val, u32 offset) 169cb477c30SDaniel Golle { 170cb477c30SDaniel Golle __raw_writel(val, priv->mii + (offset * 4)); 171cb477c30SDaniel Golle } 172cb477c30SDaniel Golle 173cb477c30SDaniel Golle static void gswip_mii_mask(struct gswip_priv *priv, u32 clear, u32 set, 174cb477c30SDaniel Golle u32 offset) 175cb477c30SDaniel Golle { 176cb477c30SDaniel Golle u32 val = gswip_mii_r(priv, offset); 177cb477c30SDaniel Golle 178cb477c30SDaniel Golle val &= ~(clear); 179cb477c30SDaniel Golle val |= set; 180cb477c30SDaniel Golle gswip_mii_w(priv, val, offset); 181cb477c30SDaniel Golle } 182cb477c30SDaniel Golle 183cb477c30SDaniel Golle static void gswip_mii_mask_cfg(struct gswip_priv *priv, u32 clear, u32 set, 184cb477c30SDaniel Golle int port) 185cb477c30SDaniel Golle { 186*51578203SDaniel Golle int reg_port; 187*51578203SDaniel Golle 188cb477c30SDaniel Golle /* MII_CFG register only exists for MII ports */ 189cb477c30SDaniel Golle if (!(priv->hw_info->mii_ports & BIT(port))) 190cb477c30SDaniel Golle return; 191cb477c30SDaniel Golle 192*51578203SDaniel Golle reg_port = port + priv->hw_info->mii_port_reg_offset; 193*51578203SDaniel Golle 194*51578203SDaniel Golle gswip_mii_mask(priv, clear, set, GSWIP_MII_CFGp(reg_port)); 195cb477c30SDaniel Golle } 196cb477c30SDaniel Golle 197cb477c30SDaniel Golle static void gswip_mii_mask_pcdu(struct gswip_priv *priv, u32 clear, u32 set, 198cb477c30SDaniel Golle int port) 199cb477c30SDaniel Golle { 200*51578203SDaniel Golle int reg_port; 201*51578203SDaniel Golle 202cb477c30SDaniel Golle /* MII_PCDU register only exists for MII ports */ 203cb477c30SDaniel Golle if (!(priv->hw_info->mii_ports & BIT(port))) 204cb477c30SDaniel Golle return; 205cb477c30SDaniel Golle 206*51578203SDaniel Golle reg_port = port + priv->hw_info->mii_port_reg_offset; 207*51578203SDaniel Golle 208*51578203SDaniel Golle switch (reg_port) { 209cb477c30SDaniel Golle case 0: 210cb477c30SDaniel Golle gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU0); 211cb477c30SDaniel Golle break; 212cb477c30SDaniel Golle case 1: 213cb477c30SDaniel Golle gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU1); 214cb477c30SDaniel Golle break; 215cb477c30SDaniel Golle case 5: 216cb477c30SDaniel Golle gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU5); 217cb477c30SDaniel Golle break; 218cb477c30SDaniel Golle } 219cb477c30SDaniel Golle } 220cb477c30SDaniel Golle 221cb477c30SDaniel Golle static int gswip_mdio_poll(struct gswip_priv *priv) 222cb477c30SDaniel Golle { 223cb477c30SDaniel Golle int cnt = 100; 224cb477c30SDaniel Golle 225cb477c30SDaniel Golle while (likely(cnt--)) { 226cb477c30SDaniel Golle u32 ctrl = gswip_mdio_r(priv, GSWIP_MDIO_CTRL); 227cb477c30SDaniel Golle 228cb477c30SDaniel Golle if ((ctrl & GSWIP_MDIO_CTRL_BUSY) == 0) 229cb477c30SDaniel Golle return 0; 230cb477c30SDaniel Golle usleep_range(20, 40); 231cb477c30SDaniel Golle } 232cb477c30SDaniel Golle 233cb477c30SDaniel Golle return -ETIMEDOUT; 234cb477c30SDaniel Golle } 235cb477c30SDaniel Golle 236cb477c30SDaniel Golle static int gswip_mdio_wr(struct mii_bus *bus, int addr, int reg, u16 val) 237cb477c30SDaniel Golle { 238cb477c30SDaniel Golle struct gswip_priv *priv = bus->priv; 239cb477c30SDaniel Golle int err; 240cb477c30SDaniel Golle 241cb477c30SDaniel Golle err = gswip_mdio_poll(priv); 242cb477c30SDaniel Golle if (err) { 243cb477c30SDaniel Golle dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n"); 244cb477c30SDaniel Golle return err; 245cb477c30SDaniel Golle } 246cb477c30SDaniel Golle 247cb477c30SDaniel Golle gswip_mdio_w(priv, val, GSWIP_MDIO_WRITE); 248cb477c30SDaniel Golle gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_WR | 249cb477c30SDaniel Golle ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) | 250cb477c30SDaniel Golle (reg & GSWIP_MDIO_CTRL_REGAD_MASK), 251cb477c30SDaniel Golle GSWIP_MDIO_CTRL); 252cb477c30SDaniel Golle 253cb477c30SDaniel Golle return 0; 254cb477c30SDaniel Golle } 255cb477c30SDaniel Golle 256cb477c30SDaniel Golle static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg) 257cb477c30SDaniel Golle { 258cb477c30SDaniel Golle struct gswip_priv *priv = bus->priv; 259cb477c30SDaniel Golle int err; 260cb477c30SDaniel Golle 261cb477c30SDaniel Golle err = gswip_mdio_poll(priv); 262cb477c30SDaniel Golle if (err) { 263cb477c30SDaniel Golle dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n"); 264cb477c30SDaniel Golle return err; 265cb477c30SDaniel Golle } 266cb477c30SDaniel Golle 267cb477c30SDaniel Golle gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_RD | 268cb477c30SDaniel Golle ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) | 269cb477c30SDaniel Golle (reg & GSWIP_MDIO_CTRL_REGAD_MASK), 270cb477c30SDaniel Golle GSWIP_MDIO_CTRL); 271cb477c30SDaniel Golle 272cb477c30SDaniel Golle err = gswip_mdio_poll(priv); 273cb477c30SDaniel Golle if (err) { 274cb477c30SDaniel Golle dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n"); 275cb477c30SDaniel Golle return err; 276cb477c30SDaniel Golle } 277cb477c30SDaniel Golle 278cb477c30SDaniel Golle return gswip_mdio_r(priv, GSWIP_MDIO_READ); 279cb477c30SDaniel Golle } 280cb477c30SDaniel Golle 281cb477c30SDaniel Golle static int gswip_mdio(struct gswip_priv *priv) 282cb477c30SDaniel Golle { 283cb477c30SDaniel Golle struct device_node *mdio_np, *switch_np = priv->dev->of_node; 284cb477c30SDaniel Golle struct device *dev = priv->dev; 285cb477c30SDaniel Golle struct mii_bus *bus; 286cb477c30SDaniel Golle int err = 0; 287cb477c30SDaniel Golle 288cb477c30SDaniel Golle mdio_np = of_get_compatible_child(switch_np, "lantiq,xrx200-mdio"); 289cb477c30SDaniel Golle if (!of_device_is_available(mdio_np)) 290cb477c30SDaniel Golle goto out_put_node; 291cb477c30SDaniel Golle 292cb477c30SDaniel Golle bus = devm_mdiobus_alloc(dev); 293cb477c30SDaniel Golle if (!bus) { 294cb477c30SDaniel Golle err = -ENOMEM; 295cb477c30SDaniel Golle goto out_put_node; 296cb477c30SDaniel Golle } 297cb477c30SDaniel Golle 298cb477c30SDaniel Golle bus->priv = priv; 299cb477c30SDaniel Golle bus->read = gswip_mdio_rd; 300cb477c30SDaniel Golle bus->write = gswip_mdio_wr; 301cb477c30SDaniel Golle bus->name = "lantiq,xrx200-mdio"; 302cb477c30SDaniel Golle snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(priv->dev)); 303cb477c30SDaniel Golle bus->parent = priv->dev; 304cb477c30SDaniel Golle 305cb477c30SDaniel Golle err = devm_of_mdiobus_register(dev, bus, mdio_np); 306cb477c30SDaniel Golle 307cb477c30SDaniel Golle out_put_node: 308cb477c30SDaniel Golle of_node_put(mdio_np); 309cb477c30SDaniel Golle 310cb477c30SDaniel Golle return err; 311cb477c30SDaniel Golle } 312cb477c30SDaniel Golle 313cb477c30SDaniel Golle static int gswip_pce_table_entry_read(struct gswip_priv *priv, 314cb477c30SDaniel Golle struct gswip_pce_table_entry *tbl) 315cb477c30SDaniel Golle { 316cb477c30SDaniel Golle int i; 317cb477c30SDaniel Golle int err; 318cb477c30SDaniel Golle u16 crtl; 319cb477c30SDaniel Golle u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSRD : 320cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_ADRD; 321cb477c30SDaniel Golle 322cb477c30SDaniel Golle mutex_lock(&priv->pce_table_lock); 323cb477c30SDaniel Golle 324cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, 325cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_BAS); 326cb477c30SDaniel Golle if (err) { 327cb477c30SDaniel Golle mutex_unlock(&priv->pce_table_lock); 328cb477c30SDaniel Golle return err; 329cb477c30SDaniel Golle } 330cb477c30SDaniel Golle 331cb477c30SDaniel Golle gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR); 332cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | 333cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_MASK, 334cb477c30SDaniel Golle tbl->table | addr_mode | GSWIP_PCE_TBL_CTRL_BAS, 335cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL); 336cb477c30SDaniel Golle 337cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, 338cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_BAS); 339cb477c30SDaniel Golle if (err) { 340cb477c30SDaniel Golle mutex_unlock(&priv->pce_table_lock); 341cb477c30SDaniel Golle return err; 342cb477c30SDaniel Golle } 343cb477c30SDaniel Golle 344cb477c30SDaniel Golle for (i = 0; i < ARRAY_SIZE(tbl->key); i++) 345cb477c30SDaniel Golle tbl->key[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_KEY(i)); 346cb477c30SDaniel Golle 347cb477c30SDaniel Golle for (i = 0; i < ARRAY_SIZE(tbl->val); i++) 348cb477c30SDaniel Golle tbl->val[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_VAL(i)); 349cb477c30SDaniel Golle 350cb477c30SDaniel Golle tbl->mask = gswip_switch_r(priv, GSWIP_PCE_TBL_MASK); 351cb477c30SDaniel Golle 352cb477c30SDaniel Golle crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL); 353cb477c30SDaniel Golle 354cb477c30SDaniel Golle tbl->type = !!(crtl & GSWIP_PCE_TBL_CTRL_TYPE); 355cb477c30SDaniel Golle tbl->valid = !!(crtl & GSWIP_PCE_TBL_CTRL_VLD); 356cb477c30SDaniel Golle tbl->gmap = (crtl & GSWIP_PCE_TBL_CTRL_GMAP_MASK) >> 7; 357cb477c30SDaniel Golle 358cb477c30SDaniel Golle mutex_unlock(&priv->pce_table_lock); 359cb477c30SDaniel Golle 360cb477c30SDaniel Golle return 0; 361cb477c30SDaniel Golle } 362cb477c30SDaniel Golle 363cb477c30SDaniel Golle static int gswip_pce_table_entry_write(struct gswip_priv *priv, 364cb477c30SDaniel Golle struct gswip_pce_table_entry *tbl) 365cb477c30SDaniel Golle { 366cb477c30SDaniel Golle int i; 367cb477c30SDaniel Golle int err; 368cb477c30SDaniel Golle u16 crtl; 369cb477c30SDaniel Golle u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSWR : 370cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_ADWR; 371cb477c30SDaniel Golle 372cb477c30SDaniel Golle mutex_lock(&priv->pce_table_lock); 373cb477c30SDaniel Golle 374cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, 375cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_BAS); 376cb477c30SDaniel Golle if (err) { 377cb477c30SDaniel Golle mutex_unlock(&priv->pce_table_lock); 378cb477c30SDaniel Golle return err; 379cb477c30SDaniel Golle } 380cb477c30SDaniel Golle 381cb477c30SDaniel Golle gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR); 382cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | 383cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_MASK, 384cb477c30SDaniel Golle tbl->table | addr_mode, 385cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL); 386cb477c30SDaniel Golle 387cb477c30SDaniel Golle for (i = 0; i < ARRAY_SIZE(tbl->key); i++) 388cb477c30SDaniel Golle gswip_switch_w(priv, tbl->key[i], GSWIP_PCE_TBL_KEY(i)); 389cb477c30SDaniel Golle 390cb477c30SDaniel Golle for (i = 0; i < ARRAY_SIZE(tbl->val); i++) 391cb477c30SDaniel Golle gswip_switch_w(priv, tbl->val[i], GSWIP_PCE_TBL_VAL(i)); 392cb477c30SDaniel Golle 393cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | 394cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_MASK, 395cb477c30SDaniel Golle tbl->table | addr_mode, 396cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL); 397cb477c30SDaniel Golle 398cb477c30SDaniel Golle gswip_switch_w(priv, tbl->mask, GSWIP_PCE_TBL_MASK); 399cb477c30SDaniel Golle 400cb477c30SDaniel Golle crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL); 401cb477c30SDaniel Golle crtl &= ~(GSWIP_PCE_TBL_CTRL_TYPE | GSWIP_PCE_TBL_CTRL_VLD | 402cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_GMAP_MASK); 403cb477c30SDaniel Golle if (tbl->type) 404cb477c30SDaniel Golle crtl |= GSWIP_PCE_TBL_CTRL_TYPE; 405cb477c30SDaniel Golle if (tbl->valid) 406cb477c30SDaniel Golle crtl |= GSWIP_PCE_TBL_CTRL_VLD; 407cb477c30SDaniel Golle crtl |= (tbl->gmap << 7) & GSWIP_PCE_TBL_CTRL_GMAP_MASK; 408cb477c30SDaniel Golle crtl |= GSWIP_PCE_TBL_CTRL_BAS; 409cb477c30SDaniel Golle gswip_switch_w(priv, crtl, GSWIP_PCE_TBL_CTRL); 410cb477c30SDaniel Golle 411cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, 412cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_BAS); 413cb477c30SDaniel Golle 414cb477c30SDaniel Golle mutex_unlock(&priv->pce_table_lock); 415cb477c30SDaniel Golle 416cb477c30SDaniel Golle return err; 417cb477c30SDaniel Golle } 418cb477c30SDaniel Golle 419cb477c30SDaniel Golle /* Add the LAN port into a bridge with the CPU port by 420cb477c30SDaniel Golle * default. This prevents automatic forwarding of 421cb477c30SDaniel Golle * packages between the LAN ports when no explicit 422cb477c30SDaniel Golle * bridge is configured. 423cb477c30SDaniel Golle */ 424cb477c30SDaniel Golle static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add) 425cb477c30SDaniel Golle { 426cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_active = {0,}; 427cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_mapping = {0,}; 428cb477c30SDaniel Golle int err; 429cb477c30SDaniel Golle 430cb477c30SDaniel Golle vlan_active.index = port + 1; 431cb477c30SDaniel Golle vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN; 432cb477c30SDaniel Golle vlan_active.key[0] = 0; /* vid */ 433cb477c30SDaniel Golle vlan_active.val[0] = port + 1 /* fid */; 434cb477c30SDaniel Golle vlan_active.valid = add; 435cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_active); 436cb477c30SDaniel Golle if (err) { 437cb477c30SDaniel Golle dev_err(priv->dev, "failed to write active VLAN: %d\n", err); 438cb477c30SDaniel Golle return err; 439cb477c30SDaniel Golle } 440cb477c30SDaniel Golle 441cb477c30SDaniel Golle if (!add) 442cb477c30SDaniel Golle return 0; 443cb477c30SDaniel Golle 444cb477c30SDaniel Golle vlan_mapping.index = port + 1; 445cb477c30SDaniel Golle vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; 446cb477c30SDaniel Golle vlan_mapping.val[0] = 0 /* vid */; 447cb477c30SDaniel Golle vlan_mapping.val[1] = BIT(port) | dsa_cpu_ports(priv->ds); 448cb477c30SDaniel Golle vlan_mapping.val[2] = 0; 449cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_mapping); 450cb477c30SDaniel Golle if (err) { 451cb477c30SDaniel Golle dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); 452cb477c30SDaniel Golle return err; 453cb477c30SDaniel Golle } 454cb477c30SDaniel Golle 455cb477c30SDaniel Golle return 0; 456cb477c30SDaniel Golle } 457cb477c30SDaniel Golle 458cb477c30SDaniel Golle static int gswip_port_enable(struct dsa_switch *ds, int port, 459cb477c30SDaniel Golle struct phy_device *phydev) 460cb477c30SDaniel Golle { 461cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 462cb477c30SDaniel Golle int err; 463cb477c30SDaniel Golle 464cb477c30SDaniel Golle if (!dsa_is_cpu_port(ds, port)) { 465cb477c30SDaniel Golle u32 mdio_phy = 0; 466cb477c30SDaniel Golle 467cb477c30SDaniel Golle err = gswip_add_single_port_br(priv, port, true); 468cb477c30SDaniel Golle if (err) 469cb477c30SDaniel Golle return err; 470cb477c30SDaniel Golle 471cb477c30SDaniel Golle if (phydev) 472cb477c30SDaniel Golle mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK; 473cb477c30SDaniel Golle 474cb477c30SDaniel Golle gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy, 475cb477c30SDaniel Golle GSWIP_MDIO_PHYp(port)); 476cb477c30SDaniel Golle } 477cb477c30SDaniel Golle 478cb477c30SDaniel Golle /* RMON Counter Enable for port */ 479cb477c30SDaniel Golle gswip_switch_w(priv, GSWIP_BM_PCFG_CNTEN, GSWIP_BM_PCFGp(port)); 480cb477c30SDaniel Golle 481cb477c30SDaniel Golle /* enable port fetch/store dma & VLAN Modification */ 482cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_EN | 483cb477c30SDaniel Golle GSWIP_FDMA_PCTRL_VLANMOD_BOTH, 484cb477c30SDaniel Golle GSWIP_FDMA_PCTRLp(port)); 485cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN, 486cb477c30SDaniel Golle GSWIP_SDMA_PCTRLp(port)); 487cb477c30SDaniel Golle 488cb477c30SDaniel Golle return 0; 489cb477c30SDaniel Golle } 490cb477c30SDaniel Golle 491cb477c30SDaniel Golle static void gswip_port_disable(struct dsa_switch *ds, int port) 492cb477c30SDaniel Golle { 493cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 494cb477c30SDaniel Golle 495cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_FDMA_PCTRL_EN, 0, 496cb477c30SDaniel Golle GSWIP_FDMA_PCTRLp(port)); 497cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0, 498cb477c30SDaniel Golle GSWIP_SDMA_PCTRLp(port)); 499cb477c30SDaniel Golle } 500cb477c30SDaniel Golle 501cb477c30SDaniel Golle static int gswip_pce_load_microcode(struct gswip_priv *priv) 502cb477c30SDaniel Golle { 503cb477c30SDaniel Golle int i; 504cb477c30SDaniel Golle int err; 505cb477c30SDaniel Golle 506cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | 507cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_MASK, 508cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_OPMOD_ADWR, GSWIP_PCE_TBL_CTRL); 509cb477c30SDaniel Golle gswip_switch_w(priv, 0, GSWIP_PCE_TBL_MASK); 510cb477c30SDaniel Golle 511cb477c30SDaniel Golle for (i = 0; i < priv->hw_info->pce_microcode_size; i++) { 512cb477c30SDaniel Golle gswip_switch_w(priv, i, GSWIP_PCE_TBL_ADDR); 513cb477c30SDaniel Golle gswip_switch_w(priv, (*priv->hw_info->pce_microcode)[i].val_0, 514cb477c30SDaniel Golle GSWIP_PCE_TBL_VAL(0)); 515cb477c30SDaniel Golle gswip_switch_w(priv, (*priv->hw_info->pce_microcode)[i].val_1, 516cb477c30SDaniel Golle GSWIP_PCE_TBL_VAL(1)); 517cb477c30SDaniel Golle gswip_switch_w(priv, (*priv->hw_info->pce_microcode)[i].val_2, 518cb477c30SDaniel Golle GSWIP_PCE_TBL_VAL(2)); 519cb477c30SDaniel Golle gswip_switch_w(priv, (*priv->hw_info->pce_microcode)[i].val_3, 520cb477c30SDaniel Golle GSWIP_PCE_TBL_VAL(3)); 521cb477c30SDaniel Golle 522cb477c30SDaniel Golle /* start the table access: */ 523cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_PCE_TBL_CTRL_BAS, 524cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL); 525cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, 526cb477c30SDaniel Golle GSWIP_PCE_TBL_CTRL_BAS); 527cb477c30SDaniel Golle if (err) 528cb477c30SDaniel Golle return err; 529cb477c30SDaniel Golle } 530cb477c30SDaniel Golle 531cb477c30SDaniel Golle /* tell the switch that the microcode is loaded */ 532cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MC_VALID, 533cb477c30SDaniel Golle GSWIP_PCE_GCTRL_0); 534cb477c30SDaniel Golle 535cb477c30SDaniel Golle return 0; 536cb477c30SDaniel Golle } 537cb477c30SDaniel Golle 538cb477c30SDaniel Golle static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port, 539cb477c30SDaniel Golle bool vlan_filtering, 540cb477c30SDaniel Golle struct netlink_ext_ack *extack) 541cb477c30SDaniel Golle { 542cb477c30SDaniel Golle struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port)); 543cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 544cb477c30SDaniel Golle 545cb477c30SDaniel Golle /* Do not allow changing the VLAN filtering options while in bridge */ 546cb477c30SDaniel Golle if (bridge && !!(priv->port_vlan_filter & BIT(port)) != vlan_filtering) { 547cb477c30SDaniel Golle NL_SET_ERR_MSG_MOD(extack, 548cb477c30SDaniel Golle "Dynamic toggling of vlan_filtering not supported"); 549cb477c30SDaniel Golle return -EIO; 550cb477c30SDaniel Golle } 551cb477c30SDaniel Golle 552cb477c30SDaniel Golle if (vlan_filtering) { 553cb477c30SDaniel Golle /* Use tag based VLAN */ 554cb477c30SDaniel Golle gswip_switch_mask(priv, 555cb477c30SDaniel Golle GSWIP_PCE_VCTRL_VSR, 556cb477c30SDaniel Golle GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR | 557cb477c30SDaniel Golle GSWIP_PCE_VCTRL_VEMR, 558cb477c30SDaniel Golle GSWIP_PCE_VCTRL(port)); 559cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_TVM, 0, 560cb477c30SDaniel Golle GSWIP_PCE_PCTRL_0p(port)); 561cb477c30SDaniel Golle } else { 562cb477c30SDaniel Golle /* Use port based VLAN */ 563cb477c30SDaniel Golle gswip_switch_mask(priv, 564cb477c30SDaniel Golle GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR | 565cb477c30SDaniel Golle GSWIP_PCE_VCTRL_VEMR, 566cb477c30SDaniel Golle GSWIP_PCE_VCTRL_VSR, 567cb477c30SDaniel Golle GSWIP_PCE_VCTRL(port)); 568cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_TVM, 569cb477c30SDaniel Golle GSWIP_PCE_PCTRL_0p(port)); 570cb477c30SDaniel Golle } 571cb477c30SDaniel Golle 572cb477c30SDaniel Golle return 0; 573cb477c30SDaniel Golle } 574cb477c30SDaniel Golle 575cb477c30SDaniel Golle static int gswip_setup(struct dsa_switch *ds) 576cb477c30SDaniel Golle { 577cb477c30SDaniel Golle unsigned int cpu_ports = dsa_cpu_ports(ds); 578cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 579cb477c30SDaniel Golle struct dsa_port *cpu_dp; 580cb477c30SDaniel Golle int err, i; 581cb477c30SDaniel Golle 582cb477c30SDaniel Golle gswip_switch_w(priv, GSWIP_SWRES_R0, GSWIP_SWRES); 583cb477c30SDaniel Golle usleep_range(5000, 10000); 584cb477c30SDaniel Golle gswip_switch_w(priv, 0, GSWIP_SWRES); 585cb477c30SDaniel Golle 586cb477c30SDaniel Golle /* disable port fetch/store dma on all ports */ 587cb477c30SDaniel Golle for (i = 0; i < priv->hw_info->max_ports; i++) { 588cb477c30SDaniel Golle gswip_port_disable(ds, i); 589cb477c30SDaniel Golle gswip_port_vlan_filtering(ds, i, false, NULL); 590cb477c30SDaniel Golle } 591cb477c30SDaniel Golle 592cb477c30SDaniel Golle /* enable Switch */ 593cb477c30SDaniel Golle gswip_mdio_mask(priv, 0, GSWIP_MDIO_GLOB_ENABLE, GSWIP_MDIO_GLOB); 594cb477c30SDaniel Golle 595cb477c30SDaniel Golle err = gswip_pce_load_microcode(priv); 596cb477c30SDaniel Golle if (err) { 597cb477c30SDaniel Golle dev_err(priv->dev, "writing PCE microcode failed, %i\n", err); 598cb477c30SDaniel Golle return err; 599cb477c30SDaniel Golle } 600cb477c30SDaniel Golle 601cb477c30SDaniel Golle /* Default unknown Broadcast/Multicast/Unicast port maps */ 602cb477c30SDaniel Golle gswip_switch_w(priv, cpu_ports, GSWIP_PCE_PMAP1); 603cb477c30SDaniel Golle gswip_switch_w(priv, cpu_ports, GSWIP_PCE_PMAP2); 604cb477c30SDaniel Golle gswip_switch_w(priv, cpu_ports, GSWIP_PCE_PMAP3); 605cb477c30SDaniel Golle 606cb477c30SDaniel Golle /* Deactivate MDIO PHY auto polling. Some PHYs as the AR8030 have an 607cb477c30SDaniel Golle * interoperability problem with this auto polling mechanism because 608cb477c30SDaniel Golle * their status registers think that the link is in a different state 609cb477c30SDaniel Golle * than it actually is. For the AR8030 it has the BMSR_ESTATEN bit set 610cb477c30SDaniel Golle * as well as ESTATUS_1000_TFULL and ESTATUS_1000_XFULL. This makes the 611cb477c30SDaniel Golle * auto polling state machine consider the link being negotiated with 612cb477c30SDaniel Golle * 1Gbit/s. Since the PHY itself is a Fast Ethernet RMII PHY this leads 613cb477c30SDaniel Golle * to the switch port being completely dead (RX and TX are both not 614cb477c30SDaniel Golle * working). 615cb477c30SDaniel Golle * Also with various other PHY / port combinations (PHY11G GPHY, PHY22F 616cb477c30SDaniel Golle * GPHY, external RGMII PEF7071/7072) any traffic would stop. Sometimes 617cb477c30SDaniel Golle * it would work fine for a few minutes to hours and then stop, on 618cb477c30SDaniel Golle * other device it would no traffic could be sent or received at all. 619cb477c30SDaniel Golle * Testing shows that when PHY auto polling is disabled these problems 620cb477c30SDaniel Golle * go away. 621cb477c30SDaniel Golle */ 622cb477c30SDaniel Golle gswip_mdio_w(priv, 0x0, GSWIP_MDIO_MDC_CFG0); 623cb477c30SDaniel Golle 624cb477c30SDaniel Golle /* Configure the MDIO Clock 2.5 MHz */ 625cb477c30SDaniel Golle gswip_mdio_mask(priv, 0xff, 0x09, GSWIP_MDIO_MDC_CFG1); 626cb477c30SDaniel Golle 627cb477c30SDaniel Golle /* Disable the xMII interface and clear it's isolation bit */ 628cb477c30SDaniel Golle for (i = 0; i < priv->hw_info->max_ports; i++) 629cb477c30SDaniel Golle gswip_mii_mask_cfg(priv, 630cb477c30SDaniel Golle GSWIP_MII_CFG_EN | GSWIP_MII_CFG_ISOLATE, 631cb477c30SDaniel Golle 0, i); 632cb477c30SDaniel Golle 633cb477c30SDaniel Golle dsa_switch_for_each_cpu_port(cpu_dp, ds) { 634cb477c30SDaniel Golle /* enable special tag insertion on cpu port */ 635cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_STEN, 636cb477c30SDaniel Golle GSWIP_FDMA_PCTRLp(cpu_dp->index)); 637cb477c30SDaniel Golle 638cb477c30SDaniel Golle /* accept special tag in ingress direction */ 639cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_INGRESS, 640cb477c30SDaniel Golle GSWIP_PCE_PCTRL_0p(cpu_dp->index)); 641cb477c30SDaniel Golle } 642cb477c30SDaniel Golle 643cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD, 644cb477c30SDaniel Golle GSWIP_BM_QUEUE_GCTRL); 645cb477c30SDaniel Golle 646cb477c30SDaniel Golle /* VLAN aware Switching */ 647cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_VLAN, GSWIP_PCE_GCTRL_0); 648cb477c30SDaniel Golle 649cb477c30SDaniel Golle /* Flush MAC Table */ 650cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MTFL, GSWIP_PCE_GCTRL_0); 651cb477c30SDaniel Golle 652cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_PCE_GCTRL_0, 653cb477c30SDaniel Golle GSWIP_PCE_GCTRL_0_MTFL); 654cb477c30SDaniel Golle if (err) { 655cb477c30SDaniel Golle dev_err(priv->dev, "MAC flushing didn't finish\n"); 656cb477c30SDaniel Golle return err; 657cb477c30SDaniel Golle } 658cb477c30SDaniel Golle 659cb477c30SDaniel Golle ds->mtu_enforcement_ingress = true; 660cb477c30SDaniel Golle 661cb477c30SDaniel Golle ds->configure_vlan_while_not_filtering = false; 662cb477c30SDaniel Golle 663cb477c30SDaniel Golle return 0; 664cb477c30SDaniel Golle } 665cb477c30SDaniel Golle 666cb477c30SDaniel Golle static enum dsa_tag_protocol gswip_get_tag_protocol(struct dsa_switch *ds, 667cb477c30SDaniel Golle int port, 668cb477c30SDaniel Golle enum dsa_tag_protocol mp) 669cb477c30SDaniel Golle { 670cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 671cb477c30SDaniel Golle 672cb477c30SDaniel Golle return priv->hw_info->tag_protocol; 673cb477c30SDaniel Golle } 674cb477c30SDaniel Golle 675cb477c30SDaniel Golle static int gswip_vlan_active_create(struct gswip_priv *priv, 676cb477c30SDaniel Golle struct net_device *bridge, 677cb477c30SDaniel Golle int fid, u16 vid) 678cb477c30SDaniel Golle { 679cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_active = {0,}; 680cb477c30SDaniel Golle unsigned int max_ports = priv->hw_info->max_ports; 681cb477c30SDaniel Golle int idx = -1; 682cb477c30SDaniel Golle int err; 683cb477c30SDaniel Golle int i; 684cb477c30SDaniel Golle 685cb477c30SDaniel Golle /* Look for a free slot */ 686cb477c30SDaniel Golle for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { 687cb477c30SDaniel Golle if (!priv->vlans[i].bridge) { 688cb477c30SDaniel Golle idx = i; 689cb477c30SDaniel Golle break; 690cb477c30SDaniel Golle } 691cb477c30SDaniel Golle } 692cb477c30SDaniel Golle 693cb477c30SDaniel Golle if (idx == -1) 694cb477c30SDaniel Golle return -ENOSPC; 695cb477c30SDaniel Golle 696cb477c30SDaniel Golle if (fid == -1) 697cb477c30SDaniel Golle fid = idx; 698cb477c30SDaniel Golle 699cb477c30SDaniel Golle vlan_active.index = idx; 700cb477c30SDaniel Golle vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN; 701cb477c30SDaniel Golle vlan_active.key[0] = vid; 702cb477c30SDaniel Golle vlan_active.val[0] = fid; 703cb477c30SDaniel Golle vlan_active.valid = true; 704cb477c30SDaniel Golle 705cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_active); 706cb477c30SDaniel Golle if (err) { 707cb477c30SDaniel Golle dev_err(priv->dev, "failed to write active VLAN: %d\n", err); 708cb477c30SDaniel Golle return err; 709cb477c30SDaniel Golle } 710cb477c30SDaniel Golle 711cb477c30SDaniel Golle priv->vlans[idx].bridge = bridge; 712cb477c30SDaniel Golle priv->vlans[idx].vid = vid; 713cb477c30SDaniel Golle priv->vlans[idx].fid = fid; 714cb477c30SDaniel Golle 715cb477c30SDaniel Golle return idx; 716cb477c30SDaniel Golle } 717cb477c30SDaniel Golle 718cb477c30SDaniel Golle static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx) 719cb477c30SDaniel Golle { 720cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_active = {0,}; 721cb477c30SDaniel Golle int err; 722cb477c30SDaniel Golle 723cb477c30SDaniel Golle vlan_active.index = idx; 724cb477c30SDaniel Golle vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN; 725cb477c30SDaniel Golle vlan_active.valid = false; 726cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_active); 727cb477c30SDaniel Golle if (err) 728cb477c30SDaniel Golle dev_err(priv->dev, "failed to delete active VLAN: %d\n", err); 729cb477c30SDaniel Golle priv->vlans[idx].bridge = NULL; 730cb477c30SDaniel Golle 731cb477c30SDaniel Golle return err; 732cb477c30SDaniel Golle } 733cb477c30SDaniel Golle 734cb477c30SDaniel Golle static int gswip_vlan_add_unaware(struct gswip_priv *priv, 735cb477c30SDaniel Golle struct net_device *bridge, int port) 736cb477c30SDaniel Golle { 737cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_mapping = {0,}; 738cb477c30SDaniel Golle unsigned int max_ports = priv->hw_info->max_ports; 739cb477c30SDaniel Golle bool active_vlan_created = false; 740cb477c30SDaniel Golle int idx = -1; 741cb477c30SDaniel Golle int i; 742cb477c30SDaniel Golle int err; 743cb477c30SDaniel Golle 744cb477c30SDaniel Golle /* Check if there is already a page for this bridge */ 745cb477c30SDaniel Golle for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { 746cb477c30SDaniel Golle if (priv->vlans[i].bridge == bridge) { 747cb477c30SDaniel Golle idx = i; 748cb477c30SDaniel Golle break; 749cb477c30SDaniel Golle } 750cb477c30SDaniel Golle } 751cb477c30SDaniel Golle 752cb477c30SDaniel Golle /* If this bridge is not programmed yet, add a Active VLAN table 753cb477c30SDaniel Golle * entry in a free slot and prepare the VLAN mapping table entry. 754cb477c30SDaniel Golle */ 755cb477c30SDaniel Golle if (idx == -1) { 756cb477c30SDaniel Golle idx = gswip_vlan_active_create(priv, bridge, -1, 0); 757cb477c30SDaniel Golle if (idx < 0) 758cb477c30SDaniel Golle return idx; 759cb477c30SDaniel Golle active_vlan_created = true; 760cb477c30SDaniel Golle 761cb477c30SDaniel Golle vlan_mapping.index = idx; 762cb477c30SDaniel Golle vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; 763cb477c30SDaniel Golle /* VLAN ID byte, maps to the VLAN ID of vlan active table */ 764cb477c30SDaniel Golle vlan_mapping.val[0] = 0; 765cb477c30SDaniel Golle } else { 766cb477c30SDaniel Golle /* Read the existing VLAN mapping entry from the switch */ 767cb477c30SDaniel Golle vlan_mapping.index = idx; 768cb477c30SDaniel Golle vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; 769cb477c30SDaniel Golle err = gswip_pce_table_entry_read(priv, &vlan_mapping); 770cb477c30SDaniel Golle if (err) { 771cb477c30SDaniel Golle dev_err(priv->dev, "failed to read VLAN mapping: %d\n", 772cb477c30SDaniel Golle err); 773cb477c30SDaniel Golle return err; 774cb477c30SDaniel Golle } 775cb477c30SDaniel Golle } 776cb477c30SDaniel Golle 777cb477c30SDaniel Golle /* Update the VLAN mapping entry and write it to the switch */ 778cb477c30SDaniel Golle vlan_mapping.val[1] |= dsa_cpu_ports(priv->ds); 779cb477c30SDaniel Golle vlan_mapping.val[1] |= BIT(port); 780cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_mapping); 781cb477c30SDaniel Golle if (err) { 782cb477c30SDaniel Golle dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); 783cb477c30SDaniel Golle /* In case an Active VLAN was creaetd delete it again */ 784cb477c30SDaniel Golle if (active_vlan_created) 785cb477c30SDaniel Golle gswip_vlan_active_remove(priv, idx); 786cb477c30SDaniel Golle return err; 787cb477c30SDaniel Golle } 788cb477c30SDaniel Golle 789cb477c30SDaniel Golle gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port)); 790cb477c30SDaniel Golle return 0; 791cb477c30SDaniel Golle } 792cb477c30SDaniel Golle 793cb477c30SDaniel Golle static int gswip_vlan_add_aware(struct gswip_priv *priv, 794cb477c30SDaniel Golle struct net_device *bridge, int port, 795cb477c30SDaniel Golle u16 vid, bool untagged, 796cb477c30SDaniel Golle bool pvid) 797cb477c30SDaniel Golle { 798cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_mapping = {0,}; 799cb477c30SDaniel Golle unsigned int max_ports = priv->hw_info->max_ports; 800cb477c30SDaniel Golle unsigned int cpu_ports = dsa_cpu_ports(priv->ds); 801cb477c30SDaniel Golle bool active_vlan_created = false; 802cb477c30SDaniel Golle int idx = -1; 803cb477c30SDaniel Golle int fid = -1; 804cb477c30SDaniel Golle int i; 805cb477c30SDaniel Golle int err; 806cb477c30SDaniel Golle 807cb477c30SDaniel Golle /* Check if there is already a page for this bridge */ 808cb477c30SDaniel Golle for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { 809cb477c30SDaniel Golle if (priv->vlans[i].bridge == bridge) { 810cb477c30SDaniel Golle if (fid != -1 && fid != priv->vlans[i].fid) 811cb477c30SDaniel Golle dev_err(priv->dev, "one bridge with multiple flow ids\n"); 812cb477c30SDaniel Golle fid = priv->vlans[i].fid; 813cb477c30SDaniel Golle if (priv->vlans[i].vid == vid) { 814cb477c30SDaniel Golle idx = i; 815cb477c30SDaniel Golle break; 816cb477c30SDaniel Golle } 817cb477c30SDaniel Golle } 818cb477c30SDaniel Golle } 819cb477c30SDaniel Golle 820cb477c30SDaniel Golle /* If this bridge is not programmed yet, add a Active VLAN table 821cb477c30SDaniel Golle * entry in a free slot and prepare the VLAN mapping table entry. 822cb477c30SDaniel Golle */ 823cb477c30SDaniel Golle if (idx == -1) { 824cb477c30SDaniel Golle idx = gswip_vlan_active_create(priv, bridge, fid, vid); 825cb477c30SDaniel Golle if (idx < 0) 826cb477c30SDaniel Golle return idx; 827cb477c30SDaniel Golle active_vlan_created = true; 828cb477c30SDaniel Golle 829cb477c30SDaniel Golle vlan_mapping.index = idx; 830cb477c30SDaniel Golle vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; 831cb477c30SDaniel Golle /* VLAN ID byte, maps to the VLAN ID of vlan active table */ 832cb477c30SDaniel Golle vlan_mapping.val[0] = vid; 833cb477c30SDaniel Golle } else { 834cb477c30SDaniel Golle /* Read the existing VLAN mapping entry from the switch */ 835cb477c30SDaniel Golle vlan_mapping.index = idx; 836cb477c30SDaniel Golle vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; 837cb477c30SDaniel Golle err = gswip_pce_table_entry_read(priv, &vlan_mapping); 838cb477c30SDaniel Golle if (err) { 839cb477c30SDaniel Golle dev_err(priv->dev, "failed to read VLAN mapping: %d\n", 840cb477c30SDaniel Golle err); 841cb477c30SDaniel Golle return err; 842cb477c30SDaniel Golle } 843cb477c30SDaniel Golle } 844cb477c30SDaniel Golle 845cb477c30SDaniel Golle vlan_mapping.val[0] = vid; 846cb477c30SDaniel Golle /* Update the VLAN mapping entry and write it to the switch */ 847cb477c30SDaniel Golle vlan_mapping.val[1] |= cpu_ports; 848cb477c30SDaniel Golle vlan_mapping.val[2] |= cpu_ports; 849cb477c30SDaniel Golle vlan_mapping.val[1] |= BIT(port); 850cb477c30SDaniel Golle if (untagged) 851cb477c30SDaniel Golle vlan_mapping.val[2] &= ~BIT(port); 852cb477c30SDaniel Golle else 853cb477c30SDaniel Golle vlan_mapping.val[2] |= BIT(port); 854cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_mapping); 855cb477c30SDaniel Golle if (err) { 856cb477c30SDaniel Golle dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); 857cb477c30SDaniel Golle /* In case an Active VLAN was creaetd delete it again */ 858cb477c30SDaniel Golle if (active_vlan_created) 859cb477c30SDaniel Golle gswip_vlan_active_remove(priv, idx); 860cb477c30SDaniel Golle return err; 861cb477c30SDaniel Golle } 862cb477c30SDaniel Golle 863cb477c30SDaniel Golle if (pvid) 864cb477c30SDaniel Golle gswip_switch_w(priv, idx, GSWIP_PCE_DEFPVID(port)); 865cb477c30SDaniel Golle 866cb477c30SDaniel Golle return 0; 867cb477c30SDaniel Golle } 868cb477c30SDaniel Golle 869cb477c30SDaniel Golle static int gswip_vlan_remove(struct gswip_priv *priv, 870cb477c30SDaniel Golle struct net_device *bridge, int port, 871cb477c30SDaniel Golle u16 vid, bool pvid, bool vlan_aware) 872cb477c30SDaniel Golle { 873cb477c30SDaniel Golle struct gswip_pce_table_entry vlan_mapping = {0,}; 874cb477c30SDaniel Golle unsigned int max_ports = priv->hw_info->max_ports; 875cb477c30SDaniel Golle int idx = -1; 876cb477c30SDaniel Golle int i; 877cb477c30SDaniel Golle int err; 878cb477c30SDaniel Golle 879cb477c30SDaniel Golle /* Check if there is already a page for this bridge */ 880cb477c30SDaniel Golle for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { 881cb477c30SDaniel Golle if (priv->vlans[i].bridge == bridge && 882cb477c30SDaniel Golle (!vlan_aware || priv->vlans[i].vid == vid)) { 883cb477c30SDaniel Golle idx = i; 884cb477c30SDaniel Golle break; 885cb477c30SDaniel Golle } 886cb477c30SDaniel Golle } 887cb477c30SDaniel Golle 888cb477c30SDaniel Golle if (idx == -1) { 889cb477c30SDaniel Golle dev_err(priv->dev, "bridge to leave does not exists\n"); 890cb477c30SDaniel Golle return -ENOENT; 891cb477c30SDaniel Golle } 892cb477c30SDaniel Golle 893cb477c30SDaniel Golle vlan_mapping.index = idx; 894cb477c30SDaniel Golle vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING; 895cb477c30SDaniel Golle err = gswip_pce_table_entry_read(priv, &vlan_mapping); 896cb477c30SDaniel Golle if (err) { 897cb477c30SDaniel Golle dev_err(priv->dev, "failed to read VLAN mapping: %d\n", err); 898cb477c30SDaniel Golle return err; 899cb477c30SDaniel Golle } 900cb477c30SDaniel Golle 901cb477c30SDaniel Golle vlan_mapping.val[1] &= ~BIT(port); 902cb477c30SDaniel Golle vlan_mapping.val[2] &= ~BIT(port); 903cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &vlan_mapping); 904cb477c30SDaniel Golle if (err) { 905cb477c30SDaniel Golle dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err); 906cb477c30SDaniel Golle return err; 907cb477c30SDaniel Golle } 908cb477c30SDaniel Golle 909cb477c30SDaniel Golle /* In case all ports are removed from the bridge, remove the VLAN */ 910cb477c30SDaniel Golle if (!(vlan_mapping.val[1] & ~dsa_cpu_ports(priv->ds))) { 911cb477c30SDaniel Golle err = gswip_vlan_active_remove(priv, idx); 912cb477c30SDaniel Golle if (err) { 913cb477c30SDaniel Golle dev_err(priv->dev, "failed to write active VLAN: %d\n", 914cb477c30SDaniel Golle err); 915cb477c30SDaniel Golle return err; 916cb477c30SDaniel Golle } 917cb477c30SDaniel Golle } 918cb477c30SDaniel Golle 919cb477c30SDaniel Golle /* GSWIP 2.2 (GRX300) and later program here the VID directly. */ 920cb477c30SDaniel Golle if (pvid) 921cb477c30SDaniel Golle gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port)); 922cb477c30SDaniel Golle 923cb477c30SDaniel Golle return 0; 924cb477c30SDaniel Golle } 925cb477c30SDaniel Golle 926cb477c30SDaniel Golle static int gswip_port_bridge_join(struct dsa_switch *ds, int port, 927cb477c30SDaniel Golle struct dsa_bridge bridge, 928cb477c30SDaniel Golle bool *tx_fwd_offload, 929cb477c30SDaniel Golle struct netlink_ext_ack *extack) 930cb477c30SDaniel Golle { 931cb477c30SDaniel Golle struct net_device *br = bridge.dev; 932cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 933cb477c30SDaniel Golle int err; 934cb477c30SDaniel Golle 935cb477c30SDaniel Golle /* When the bridge uses VLAN filtering we have to configure VLAN 936cb477c30SDaniel Golle * specific bridges. No bridge is configured here. 937cb477c30SDaniel Golle */ 938cb477c30SDaniel Golle if (!br_vlan_enabled(br)) { 939cb477c30SDaniel Golle err = gswip_vlan_add_unaware(priv, br, port); 940cb477c30SDaniel Golle if (err) 941cb477c30SDaniel Golle return err; 942cb477c30SDaniel Golle priv->port_vlan_filter &= ~BIT(port); 943cb477c30SDaniel Golle } else { 944cb477c30SDaniel Golle priv->port_vlan_filter |= BIT(port); 945cb477c30SDaniel Golle } 946cb477c30SDaniel Golle return gswip_add_single_port_br(priv, port, false); 947cb477c30SDaniel Golle } 948cb477c30SDaniel Golle 949cb477c30SDaniel Golle static void gswip_port_bridge_leave(struct dsa_switch *ds, int port, 950cb477c30SDaniel Golle struct dsa_bridge bridge) 951cb477c30SDaniel Golle { 952cb477c30SDaniel Golle struct net_device *br = bridge.dev; 953cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 954cb477c30SDaniel Golle 955cb477c30SDaniel Golle gswip_add_single_port_br(priv, port, true); 956cb477c30SDaniel Golle 957cb477c30SDaniel Golle /* When the bridge uses VLAN filtering we have to configure VLAN 958cb477c30SDaniel Golle * specific bridges. No bridge is configured here. 959cb477c30SDaniel Golle */ 960cb477c30SDaniel Golle if (!br_vlan_enabled(br)) 961cb477c30SDaniel Golle gswip_vlan_remove(priv, br, port, 0, true, false); 962cb477c30SDaniel Golle } 963cb477c30SDaniel Golle 964cb477c30SDaniel Golle static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port, 965cb477c30SDaniel Golle const struct switchdev_obj_port_vlan *vlan, 966cb477c30SDaniel Golle struct netlink_ext_ack *extack) 967cb477c30SDaniel Golle { 968cb477c30SDaniel Golle struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port)); 969cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 970cb477c30SDaniel Golle unsigned int max_ports = priv->hw_info->max_ports; 971cb477c30SDaniel Golle int pos = max_ports; 972cb477c30SDaniel Golle int i, idx = -1; 973cb477c30SDaniel Golle 974cb477c30SDaniel Golle /* We only support VLAN filtering on bridges */ 975cb477c30SDaniel Golle if (!dsa_is_cpu_port(ds, port) && !bridge) 976cb477c30SDaniel Golle return -EOPNOTSUPP; 977cb477c30SDaniel Golle 978cb477c30SDaniel Golle /* Check if there is already a page for this VLAN */ 979cb477c30SDaniel Golle for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { 980cb477c30SDaniel Golle if (priv->vlans[i].bridge == bridge && 981cb477c30SDaniel Golle priv->vlans[i].vid == vlan->vid) { 982cb477c30SDaniel Golle idx = i; 983cb477c30SDaniel Golle break; 984cb477c30SDaniel Golle } 985cb477c30SDaniel Golle } 986cb477c30SDaniel Golle 987cb477c30SDaniel Golle /* If this VLAN is not programmed yet, we have to reserve 988cb477c30SDaniel Golle * one entry in the VLAN table. Make sure we start at the 989cb477c30SDaniel Golle * next position round. 990cb477c30SDaniel Golle */ 991cb477c30SDaniel Golle if (idx == -1) { 992cb477c30SDaniel Golle /* Look for a free slot */ 993cb477c30SDaniel Golle for (; pos < ARRAY_SIZE(priv->vlans); pos++) { 994cb477c30SDaniel Golle if (!priv->vlans[pos].bridge) { 995cb477c30SDaniel Golle idx = pos; 996cb477c30SDaniel Golle pos++; 997cb477c30SDaniel Golle break; 998cb477c30SDaniel Golle } 999cb477c30SDaniel Golle } 1000cb477c30SDaniel Golle 1001cb477c30SDaniel Golle if (idx == -1) { 1002cb477c30SDaniel Golle NL_SET_ERR_MSG_MOD(extack, "No slot in VLAN table"); 1003cb477c30SDaniel Golle return -ENOSPC; 1004cb477c30SDaniel Golle } 1005cb477c30SDaniel Golle } 1006cb477c30SDaniel Golle 1007cb477c30SDaniel Golle return 0; 1008cb477c30SDaniel Golle } 1009cb477c30SDaniel Golle 1010cb477c30SDaniel Golle static int gswip_port_vlan_add(struct dsa_switch *ds, int port, 1011cb477c30SDaniel Golle const struct switchdev_obj_port_vlan *vlan, 1012cb477c30SDaniel Golle struct netlink_ext_ack *extack) 1013cb477c30SDaniel Golle { 1014cb477c30SDaniel Golle struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port)); 1015cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1016cb477c30SDaniel Golle bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1017cb477c30SDaniel Golle bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1018cb477c30SDaniel Golle int err; 1019cb477c30SDaniel Golle 1020cb477c30SDaniel Golle err = gswip_port_vlan_prepare(ds, port, vlan, extack); 1021cb477c30SDaniel Golle if (err) 1022cb477c30SDaniel Golle return err; 1023cb477c30SDaniel Golle 1024cb477c30SDaniel Golle /* We have to receive all packets on the CPU port and should not 1025cb477c30SDaniel Golle * do any VLAN filtering here. This is also called with bridge 1026cb477c30SDaniel Golle * NULL and then we do not know for which bridge to configure 1027cb477c30SDaniel Golle * this. 1028cb477c30SDaniel Golle */ 1029cb477c30SDaniel Golle if (dsa_is_cpu_port(ds, port)) 1030cb477c30SDaniel Golle return 0; 1031cb477c30SDaniel Golle 1032cb477c30SDaniel Golle return gswip_vlan_add_aware(priv, bridge, port, vlan->vid, 1033cb477c30SDaniel Golle untagged, pvid); 1034cb477c30SDaniel Golle } 1035cb477c30SDaniel Golle 1036cb477c30SDaniel Golle static int gswip_port_vlan_del(struct dsa_switch *ds, int port, 1037cb477c30SDaniel Golle const struct switchdev_obj_port_vlan *vlan) 1038cb477c30SDaniel Golle { 1039cb477c30SDaniel Golle struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port)); 1040cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1041cb477c30SDaniel Golle bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1042cb477c30SDaniel Golle 1043cb477c30SDaniel Golle /* We have to receive all packets on the CPU port and should not 1044cb477c30SDaniel Golle * do any VLAN filtering here. This is also called with bridge 1045cb477c30SDaniel Golle * NULL and then we do not know for which bridge to configure 1046cb477c30SDaniel Golle * this. 1047cb477c30SDaniel Golle */ 1048cb477c30SDaniel Golle if (dsa_is_cpu_port(ds, port)) 1049cb477c30SDaniel Golle return 0; 1050cb477c30SDaniel Golle 1051cb477c30SDaniel Golle return gswip_vlan_remove(priv, bridge, port, vlan->vid, pvid, true); 1052cb477c30SDaniel Golle } 1053cb477c30SDaniel Golle 1054cb477c30SDaniel Golle static void gswip_port_fast_age(struct dsa_switch *ds, int port) 1055cb477c30SDaniel Golle { 1056cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1057cb477c30SDaniel Golle struct gswip_pce_table_entry mac_bridge = {0,}; 1058cb477c30SDaniel Golle int i; 1059cb477c30SDaniel Golle int err; 1060cb477c30SDaniel Golle 1061cb477c30SDaniel Golle for (i = 0; i < 2048; i++) { 1062cb477c30SDaniel Golle mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE; 1063cb477c30SDaniel Golle mac_bridge.index = i; 1064cb477c30SDaniel Golle 1065cb477c30SDaniel Golle err = gswip_pce_table_entry_read(priv, &mac_bridge); 1066cb477c30SDaniel Golle if (err) { 1067cb477c30SDaniel Golle dev_err(priv->dev, "failed to read mac bridge: %d\n", 1068cb477c30SDaniel Golle err); 1069cb477c30SDaniel Golle return; 1070cb477c30SDaniel Golle } 1071cb477c30SDaniel Golle 1072cb477c30SDaniel Golle if (!mac_bridge.valid) 1073cb477c30SDaniel Golle continue; 1074cb477c30SDaniel Golle 1075cb477c30SDaniel Golle if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC) 1076cb477c30SDaniel Golle continue; 1077cb477c30SDaniel Golle 1078cb477c30SDaniel Golle if (port != FIELD_GET(GSWIP_TABLE_MAC_BRIDGE_VAL0_PORT, 1079cb477c30SDaniel Golle mac_bridge.val[0])) 1080cb477c30SDaniel Golle continue; 1081cb477c30SDaniel Golle 1082cb477c30SDaniel Golle mac_bridge.valid = false; 1083cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &mac_bridge); 1084cb477c30SDaniel Golle if (err) { 1085cb477c30SDaniel Golle dev_err(priv->dev, "failed to write mac bridge: %d\n", 1086cb477c30SDaniel Golle err); 1087cb477c30SDaniel Golle return; 1088cb477c30SDaniel Golle } 1089cb477c30SDaniel Golle } 1090cb477c30SDaniel Golle } 1091cb477c30SDaniel Golle 1092cb477c30SDaniel Golle static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) 1093cb477c30SDaniel Golle { 1094cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1095cb477c30SDaniel Golle u32 stp_state; 1096cb477c30SDaniel Golle 1097cb477c30SDaniel Golle switch (state) { 1098cb477c30SDaniel Golle case BR_STATE_DISABLED: 1099cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0, 1100cb477c30SDaniel Golle GSWIP_SDMA_PCTRLp(port)); 1101cb477c30SDaniel Golle return; 1102cb477c30SDaniel Golle case BR_STATE_BLOCKING: 1103cb477c30SDaniel Golle case BR_STATE_LISTENING: 1104cb477c30SDaniel Golle stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LISTEN; 1105cb477c30SDaniel Golle break; 1106cb477c30SDaniel Golle case BR_STATE_LEARNING: 1107cb477c30SDaniel Golle stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LEARNING; 1108cb477c30SDaniel Golle break; 1109cb477c30SDaniel Golle case BR_STATE_FORWARDING: 1110cb477c30SDaniel Golle stp_state = GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING; 1111cb477c30SDaniel Golle break; 1112cb477c30SDaniel Golle default: 1113cb477c30SDaniel Golle dev_err(priv->dev, "invalid STP state: %d\n", state); 1114cb477c30SDaniel Golle return; 1115cb477c30SDaniel Golle } 1116cb477c30SDaniel Golle 1117cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN, 1118cb477c30SDaniel Golle GSWIP_SDMA_PCTRLp(port)); 1119cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_PSTATE_MASK, stp_state, 1120cb477c30SDaniel Golle GSWIP_PCE_PCTRL_0p(port)); 1121cb477c30SDaniel Golle } 1122cb477c30SDaniel Golle 1123cb477c30SDaniel Golle static int gswip_port_fdb(struct dsa_switch *ds, int port, 1124cb477c30SDaniel Golle const unsigned char *addr, u16 vid, bool add) 1125cb477c30SDaniel Golle { 1126cb477c30SDaniel Golle struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port)); 1127cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1128cb477c30SDaniel Golle struct gswip_pce_table_entry mac_bridge = {0,}; 1129cb477c30SDaniel Golle unsigned int max_ports = priv->hw_info->max_ports; 1130cb477c30SDaniel Golle int fid = -1; 1131cb477c30SDaniel Golle int i; 1132cb477c30SDaniel Golle int err; 1133cb477c30SDaniel Golle 1134cb477c30SDaniel Golle if (!bridge) 1135cb477c30SDaniel Golle return -EINVAL; 1136cb477c30SDaniel Golle 1137cb477c30SDaniel Golle for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) { 1138cb477c30SDaniel Golle if (priv->vlans[i].bridge == bridge) { 1139cb477c30SDaniel Golle fid = priv->vlans[i].fid; 1140cb477c30SDaniel Golle break; 1141cb477c30SDaniel Golle } 1142cb477c30SDaniel Golle } 1143cb477c30SDaniel Golle 1144cb477c30SDaniel Golle if (fid == -1) { 1145cb477c30SDaniel Golle dev_err(priv->dev, "no FID found for bridge %s\n", 1146cb477c30SDaniel Golle bridge->name); 1147cb477c30SDaniel Golle return -EINVAL; 1148cb477c30SDaniel Golle } 1149cb477c30SDaniel Golle 1150cb477c30SDaniel Golle mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE; 1151cb477c30SDaniel Golle mac_bridge.key_mode = true; 1152cb477c30SDaniel Golle mac_bridge.key[0] = addr[5] | (addr[4] << 8); 1153cb477c30SDaniel Golle mac_bridge.key[1] = addr[3] | (addr[2] << 8); 1154cb477c30SDaniel Golle mac_bridge.key[2] = addr[1] | (addr[0] << 8); 1155cb477c30SDaniel Golle mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_KEY3_FID, fid); 1156cb477c30SDaniel Golle mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */ 1157cb477c30SDaniel Golle mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC; 1158cb477c30SDaniel Golle mac_bridge.valid = add; 1159cb477c30SDaniel Golle 1160cb477c30SDaniel Golle err = gswip_pce_table_entry_write(priv, &mac_bridge); 1161cb477c30SDaniel Golle if (err) 1162cb477c30SDaniel Golle dev_err(priv->dev, "failed to write mac bridge: %d\n", err); 1163cb477c30SDaniel Golle 1164cb477c30SDaniel Golle return err; 1165cb477c30SDaniel Golle } 1166cb477c30SDaniel Golle 1167cb477c30SDaniel Golle static int gswip_port_fdb_add(struct dsa_switch *ds, int port, 1168cb477c30SDaniel Golle const unsigned char *addr, u16 vid, 1169cb477c30SDaniel Golle struct dsa_db db) 1170cb477c30SDaniel Golle { 1171cb477c30SDaniel Golle return gswip_port_fdb(ds, port, addr, vid, true); 1172cb477c30SDaniel Golle } 1173cb477c30SDaniel Golle 1174cb477c30SDaniel Golle static int gswip_port_fdb_del(struct dsa_switch *ds, int port, 1175cb477c30SDaniel Golle const unsigned char *addr, u16 vid, 1176cb477c30SDaniel Golle struct dsa_db db) 1177cb477c30SDaniel Golle { 1178cb477c30SDaniel Golle return gswip_port_fdb(ds, port, addr, vid, false); 1179cb477c30SDaniel Golle } 1180cb477c30SDaniel Golle 1181cb477c30SDaniel Golle static int gswip_port_fdb_dump(struct dsa_switch *ds, int port, 1182cb477c30SDaniel Golle dsa_fdb_dump_cb_t *cb, void *data) 1183cb477c30SDaniel Golle { 1184cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1185cb477c30SDaniel Golle struct gswip_pce_table_entry mac_bridge = {0,}; 1186cb477c30SDaniel Golle unsigned char addr[ETH_ALEN]; 1187cb477c30SDaniel Golle int i; 1188cb477c30SDaniel Golle int err; 1189cb477c30SDaniel Golle 1190cb477c30SDaniel Golle for (i = 0; i < 2048; i++) { 1191cb477c30SDaniel Golle mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE; 1192cb477c30SDaniel Golle mac_bridge.index = i; 1193cb477c30SDaniel Golle 1194cb477c30SDaniel Golle err = gswip_pce_table_entry_read(priv, &mac_bridge); 1195cb477c30SDaniel Golle if (err) { 1196cb477c30SDaniel Golle dev_err(priv->dev, 1197cb477c30SDaniel Golle "failed to read mac bridge entry %d: %d\n", 1198cb477c30SDaniel Golle i, err); 1199cb477c30SDaniel Golle return err; 1200cb477c30SDaniel Golle } 1201cb477c30SDaniel Golle 1202cb477c30SDaniel Golle if (!mac_bridge.valid) 1203cb477c30SDaniel Golle continue; 1204cb477c30SDaniel Golle 1205cb477c30SDaniel Golle addr[5] = mac_bridge.key[0] & 0xff; 1206cb477c30SDaniel Golle addr[4] = (mac_bridge.key[0] >> 8) & 0xff; 1207cb477c30SDaniel Golle addr[3] = mac_bridge.key[1] & 0xff; 1208cb477c30SDaniel Golle addr[2] = (mac_bridge.key[1] >> 8) & 0xff; 1209cb477c30SDaniel Golle addr[1] = mac_bridge.key[2] & 0xff; 1210cb477c30SDaniel Golle addr[0] = (mac_bridge.key[2] >> 8) & 0xff; 1211cb477c30SDaniel Golle if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC) { 1212cb477c30SDaniel Golle if (mac_bridge.val[0] & BIT(port)) { 1213cb477c30SDaniel Golle err = cb(addr, 0, true, data); 1214cb477c30SDaniel Golle if (err) 1215cb477c30SDaniel Golle return err; 1216cb477c30SDaniel Golle } 1217cb477c30SDaniel Golle } else { 1218cb477c30SDaniel Golle if (port == FIELD_GET(GSWIP_TABLE_MAC_BRIDGE_VAL0_PORT, 1219cb477c30SDaniel Golle mac_bridge.val[0])) { 1220cb477c30SDaniel Golle err = cb(addr, 0, false, data); 1221cb477c30SDaniel Golle if (err) 1222cb477c30SDaniel Golle return err; 1223cb477c30SDaniel Golle } 1224cb477c30SDaniel Golle } 1225cb477c30SDaniel Golle } 1226cb477c30SDaniel Golle return 0; 1227cb477c30SDaniel Golle } 1228cb477c30SDaniel Golle 1229cb477c30SDaniel Golle static int gswip_port_max_mtu(struct dsa_switch *ds, int port) 1230cb477c30SDaniel Golle { 1231cb477c30SDaniel Golle /* Includes 8 bytes for special header. */ 1232cb477c30SDaniel Golle return GSWIP_MAX_PACKET_LENGTH - VLAN_ETH_HLEN - ETH_FCS_LEN; 1233cb477c30SDaniel Golle } 1234cb477c30SDaniel Golle 1235cb477c30SDaniel Golle static int gswip_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 1236cb477c30SDaniel Golle { 1237cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1238cb477c30SDaniel Golle 1239cb477c30SDaniel Golle /* CPU port always has maximum mtu of user ports, so use it to set 1240cb477c30SDaniel Golle * switch frame size, including 8 byte special header. 1241cb477c30SDaniel Golle */ 1242cb477c30SDaniel Golle if (dsa_is_cpu_port(ds, port)) { 1243cb477c30SDaniel Golle new_mtu += 8; 1244cb477c30SDaniel Golle gswip_switch_w(priv, VLAN_ETH_HLEN + new_mtu + ETH_FCS_LEN, 1245cb477c30SDaniel Golle GSWIP_MAC_FLEN); 1246cb477c30SDaniel Golle } 1247cb477c30SDaniel Golle 1248cb477c30SDaniel Golle /* Enable MLEN for ports with non-standard MTUs, including the special 1249cb477c30SDaniel Golle * header on the CPU port added above. 1250cb477c30SDaniel Golle */ 1251cb477c30SDaniel Golle if (new_mtu != ETH_DATA_LEN) 1252cb477c30SDaniel Golle gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN, 1253cb477c30SDaniel Golle GSWIP_MAC_CTRL_2p(port)); 1254cb477c30SDaniel Golle else 1255cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_MAC_CTRL_2_MLEN, 0, 1256cb477c30SDaniel Golle GSWIP_MAC_CTRL_2p(port)); 1257cb477c30SDaniel Golle 1258cb477c30SDaniel Golle return 0; 1259cb477c30SDaniel Golle } 1260cb477c30SDaniel Golle 1261cb477c30SDaniel Golle static void gswip_xrx200_phylink_get_caps(struct dsa_switch *ds, int port, 1262cb477c30SDaniel Golle struct phylink_config *config) 1263cb477c30SDaniel Golle { 1264cb477c30SDaniel Golle switch (port) { 1265cb477c30SDaniel Golle case 0: 1266cb477c30SDaniel Golle case 1: 1267cb477c30SDaniel Golle phy_interface_set_rgmii(config->supported_interfaces); 1268cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_MII, 1269cb477c30SDaniel Golle config->supported_interfaces); 1270cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_REVMII, 1271cb477c30SDaniel Golle config->supported_interfaces); 1272cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_RMII, 1273cb477c30SDaniel Golle config->supported_interfaces); 1274cb477c30SDaniel Golle break; 1275cb477c30SDaniel Golle 1276cb477c30SDaniel Golle case 2: 1277cb477c30SDaniel Golle case 3: 1278cb477c30SDaniel Golle case 4: 1279cb477c30SDaniel Golle case 6: 1280cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_INTERNAL, 1281cb477c30SDaniel Golle config->supported_interfaces); 1282cb477c30SDaniel Golle break; 1283cb477c30SDaniel Golle 1284cb477c30SDaniel Golle case 5: 1285cb477c30SDaniel Golle phy_interface_set_rgmii(config->supported_interfaces); 1286cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_INTERNAL, 1287cb477c30SDaniel Golle config->supported_interfaces); 1288cb477c30SDaniel Golle break; 1289cb477c30SDaniel Golle } 1290cb477c30SDaniel Golle 1291cb477c30SDaniel Golle config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | 1292cb477c30SDaniel Golle MAC_10 | MAC_100 | MAC_1000; 1293cb477c30SDaniel Golle } 1294cb477c30SDaniel Golle 1295cb477c30SDaniel Golle static void gswip_xrx300_phylink_get_caps(struct dsa_switch *ds, int port, 1296cb477c30SDaniel Golle struct phylink_config *config) 1297cb477c30SDaniel Golle { 1298cb477c30SDaniel Golle switch (port) { 1299cb477c30SDaniel Golle case 0: 1300cb477c30SDaniel Golle phy_interface_set_rgmii(config->supported_interfaces); 1301cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_GMII, 1302cb477c30SDaniel Golle config->supported_interfaces); 1303cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_RMII, 1304cb477c30SDaniel Golle config->supported_interfaces); 1305cb477c30SDaniel Golle break; 1306cb477c30SDaniel Golle 1307cb477c30SDaniel Golle case 1: 1308cb477c30SDaniel Golle case 2: 1309cb477c30SDaniel Golle case 3: 1310cb477c30SDaniel Golle case 4: 1311cb477c30SDaniel Golle case 6: 1312cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_INTERNAL, 1313cb477c30SDaniel Golle config->supported_interfaces); 1314cb477c30SDaniel Golle break; 1315cb477c30SDaniel Golle 1316cb477c30SDaniel Golle case 5: 1317cb477c30SDaniel Golle phy_interface_set_rgmii(config->supported_interfaces); 1318cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_INTERNAL, 1319cb477c30SDaniel Golle config->supported_interfaces); 1320cb477c30SDaniel Golle __set_bit(PHY_INTERFACE_MODE_RMII, 1321cb477c30SDaniel Golle config->supported_interfaces); 1322cb477c30SDaniel Golle break; 1323cb477c30SDaniel Golle } 1324cb477c30SDaniel Golle 1325cb477c30SDaniel Golle config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | 1326cb477c30SDaniel Golle MAC_10 | MAC_100 | MAC_1000; 1327cb477c30SDaniel Golle } 1328cb477c30SDaniel Golle 1329cb477c30SDaniel Golle static void gswip_phylink_get_caps(struct dsa_switch *ds, int port, 1330cb477c30SDaniel Golle struct phylink_config *config) 1331cb477c30SDaniel Golle { 1332cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1333cb477c30SDaniel Golle 1334cb477c30SDaniel Golle priv->hw_info->phylink_get_caps(ds, port, config); 1335cb477c30SDaniel Golle } 1336cb477c30SDaniel Golle 1337cb477c30SDaniel Golle static void gswip_port_set_link(struct gswip_priv *priv, int port, bool link) 1338cb477c30SDaniel Golle { 1339cb477c30SDaniel Golle u32 mdio_phy; 1340cb477c30SDaniel Golle 1341cb477c30SDaniel Golle if (link) 1342cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_LINK_UP; 1343cb477c30SDaniel Golle else 1344cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_LINK_DOWN; 1345cb477c30SDaniel Golle 1346cb477c30SDaniel Golle gswip_mdio_mask(priv, GSWIP_MDIO_PHY_LINK_MASK, mdio_phy, 1347cb477c30SDaniel Golle GSWIP_MDIO_PHYp(port)); 1348cb477c30SDaniel Golle } 1349cb477c30SDaniel Golle 1350cb477c30SDaniel Golle static void gswip_port_set_speed(struct gswip_priv *priv, int port, int speed, 1351cb477c30SDaniel Golle phy_interface_t interface) 1352cb477c30SDaniel Golle { 1353cb477c30SDaniel Golle u32 mdio_phy = 0, mii_cfg = 0, mac_ctrl_0 = 0; 1354cb477c30SDaniel Golle 1355cb477c30SDaniel Golle switch (speed) { 1356cb477c30SDaniel Golle case SPEED_10: 1357cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_SPEED_M10; 1358cb477c30SDaniel Golle 1359cb477c30SDaniel Golle if (interface == PHY_INTERFACE_MODE_RMII) 1360cb477c30SDaniel Golle mii_cfg = GSWIP_MII_CFG_RATE_M50; 1361cb477c30SDaniel Golle else 1362cb477c30SDaniel Golle mii_cfg = GSWIP_MII_CFG_RATE_M2P5; 1363cb477c30SDaniel Golle 1364cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_GMII_MII; 1365cb477c30SDaniel Golle break; 1366cb477c30SDaniel Golle 1367cb477c30SDaniel Golle case SPEED_100: 1368cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_SPEED_M100; 1369cb477c30SDaniel Golle 1370cb477c30SDaniel Golle if (interface == PHY_INTERFACE_MODE_RMII) 1371cb477c30SDaniel Golle mii_cfg = GSWIP_MII_CFG_RATE_M50; 1372cb477c30SDaniel Golle else 1373cb477c30SDaniel Golle mii_cfg = GSWIP_MII_CFG_RATE_M25; 1374cb477c30SDaniel Golle 1375cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_GMII_MII; 1376cb477c30SDaniel Golle break; 1377cb477c30SDaniel Golle 1378cb477c30SDaniel Golle case SPEED_1000: 1379cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_SPEED_G1; 1380cb477c30SDaniel Golle 1381cb477c30SDaniel Golle mii_cfg = GSWIP_MII_CFG_RATE_M125; 1382cb477c30SDaniel Golle 1383cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_GMII_RGMII; 1384cb477c30SDaniel Golle break; 1385cb477c30SDaniel Golle } 1386cb477c30SDaniel Golle 1387cb477c30SDaniel Golle gswip_mdio_mask(priv, GSWIP_MDIO_PHY_SPEED_MASK, mdio_phy, 1388cb477c30SDaniel Golle GSWIP_MDIO_PHYp(port)); 1389cb477c30SDaniel Golle gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_RATE_MASK, mii_cfg, port); 1390cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_MAC_CTRL_0_GMII_MASK, mac_ctrl_0, 1391cb477c30SDaniel Golle GSWIP_MAC_CTRL_0p(port)); 1392cb477c30SDaniel Golle } 1393cb477c30SDaniel Golle 1394cb477c30SDaniel Golle static void gswip_port_set_duplex(struct gswip_priv *priv, int port, int duplex) 1395cb477c30SDaniel Golle { 1396cb477c30SDaniel Golle u32 mac_ctrl_0, mdio_phy; 1397cb477c30SDaniel Golle 1398cb477c30SDaniel Golle if (duplex == DUPLEX_FULL) { 1399cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_FDUP_EN; 1400cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_FDUP_EN; 1401cb477c30SDaniel Golle } else { 1402cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_FDUP_DIS; 1403cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_FDUP_DIS; 1404cb477c30SDaniel Golle } 1405cb477c30SDaniel Golle 1406cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_MAC_CTRL_0_FDUP_MASK, mac_ctrl_0, 1407cb477c30SDaniel Golle GSWIP_MAC_CTRL_0p(port)); 1408cb477c30SDaniel Golle gswip_mdio_mask(priv, GSWIP_MDIO_PHY_FDUP_MASK, mdio_phy, 1409cb477c30SDaniel Golle GSWIP_MDIO_PHYp(port)); 1410cb477c30SDaniel Golle } 1411cb477c30SDaniel Golle 1412cb477c30SDaniel Golle static void gswip_port_set_pause(struct gswip_priv *priv, int port, 1413cb477c30SDaniel Golle bool tx_pause, bool rx_pause) 1414cb477c30SDaniel Golle { 1415cb477c30SDaniel Golle u32 mac_ctrl_0, mdio_phy; 1416cb477c30SDaniel Golle 1417cb477c30SDaniel Golle if (tx_pause && rx_pause) { 1418cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_RXTX; 1419cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_FCONTX_EN | 1420cb477c30SDaniel Golle GSWIP_MDIO_PHY_FCONRX_EN; 1421cb477c30SDaniel Golle } else if (tx_pause) { 1422cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_TX; 1423cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_FCONTX_EN | 1424cb477c30SDaniel Golle GSWIP_MDIO_PHY_FCONRX_DIS; 1425cb477c30SDaniel Golle } else if (rx_pause) { 1426cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_RX; 1427cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_FCONTX_DIS | 1428cb477c30SDaniel Golle GSWIP_MDIO_PHY_FCONRX_EN; 1429cb477c30SDaniel Golle } else { 1430cb477c30SDaniel Golle mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_NONE; 1431cb477c30SDaniel Golle mdio_phy = GSWIP_MDIO_PHY_FCONTX_DIS | 1432cb477c30SDaniel Golle GSWIP_MDIO_PHY_FCONRX_DIS; 1433cb477c30SDaniel Golle } 1434cb477c30SDaniel Golle 1435cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_MAC_CTRL_0_FCON_MASK, 1436cb477c30SDaniel Golle mac_ctrl_0, GSWIP_MAC_CTRL_0p(port)); 1437cb477c30SDaniel Golle gswip_mdio_mask(priv, 1438cb477c30SDaniel Golle GSWIP_MDIO_PHY_FCONTX_MASK | 1439cb477c30SDaniel Golle GSWIP_MDIO_PHY_FCONRX_MASK, 1440cb477c30SDaniel Golle mdio_phy, GSWIP_MDIO_PHYp(port)); 1441cb477c30SDaniel Golle } 1442cb477c30SDaniel Golle 1443cb477c30SDaniel Golle static void gswip_phylink_mac_config(struct phylink_config *config, 1444cb477c30SDaniel Golle unsigned int mode, 1445cb477c30SDaniel Golle const struct phylink_link_state *state) 1446cb477c30SDaniel Golle { 1447cb477c30SDaniel Golle struct dsa_port *dp = dsa_phylink_to_port(config); 1448cb477c30SDaniel Golle struct gswip_priv *priv = dp->ds->priv; 1449cb477c30SDaniel Golle int port = dp->index; 1450cb477c30SDaniel Golle u32 miicfg = 0; 1451cb477c30SDaniel Golle 1452cb477c30SDaniel Golle miicfg |= GSWIP_MII_CFG_LDCLKDIS; 1453cb477c30SDaniel Golle 1454cb477c30SDaniel Golle switch (state->interface) { 145517420a7fSDaniel Golle case PHY_INTERFACE_MODE_SGMII: 145617420a7fSDaniel Golle case PHY_INTERFACE_MODE_1000BASEX: 145717420a7fSDaniel Golle case PHY_INTERFACE_MODE_2500BASEX: 145817420a7fSDaniel Golle return; 1459cb477c30SDaniel Golle case PHY_INTERFACE_MODE_MII: 1460cb477c30SDaniel Golle case PHY_INTERFACE_MODE_INTERNAL: 1461cb477c30SDaniel Golle miicfg |= GSWIP_MII_CFG_MODE_MIIM; 1462cb477c30SDaniel Golle break; 1463cb477c30SDaniel Golle case PHY_INTERFACE_MODE_REVMII: 1464cb477c30SDaniel Golle miicfg |= GSWIP_MII_CFG_MODE_MIIP; 1465cb477c30SDaniel Golle break; 1466cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RMII: 1467cb477c30SDaniel Golle miicfg |= GSWIP_MII_CFG_MODE_RMIIM; 1468cb477c30SDaniel Golle break; 1469cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII: 1470cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII_ID: 1471cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII_RXID: 1472cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII_TXID: 1473cb477c30SDaniel Golle miicfg |= GSWIP_MII_CFG_MODE_RGMII; 1474cb477c30SDaniel Golle break; 1475cb477c30SDaniel Golle case PHY_INTERFACE_MODE_GMII: 1476cb477c30SDaniel Golle miicfg |= GSWIP_MII_CFG_MODE_GMII; 1477cb477c30SDaniel Golle break; 1478cb477c30SDaniel Golle default: 1479cb477c30SDaniel Golle dev_err(dp->ds->dev, 1480cb477c30SDaniel Golle "Unsupported interface: %d\n", state->interface); 1481cb477c30SDaniel Golle return; 1482cb477c30SDaniel Golle } 1483cb477c30SDaniel Golle 1484cb477c30SDaniel Golle gswip_mii_mask_cfg(priv, 1485cb477c30SDaniel Golle GSWIP_MII_CFG_MODE_MASK | GSWIP_MII_CFG_RMII_CLK | 1486cb477c30SDaniel Golle GSWIP_MII_CFG_RGMII_IBS | GSWIP_MII_CFG_LDCLKDIS, 1487cb477c30SDaniel Golle miicfg, port); 1488cb477c30SDaniel Golle 1489cb477c30SDaniel Golle switch (state->interface) { 1490cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII_ID: 1491cb477c30SDaniel Golle gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK | 1492cb477c30SDaniel Golle GSWIP_MII_PCDU_RXDLY_MASK, 0, port); 1493cb477c30SDaniel Golle break; 1494cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII_RXID: 1495cb477c30SDaniel Golle gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_RXDLY_MASK, 0, port); 1496cb477c30SDaniel Golle break; 1497cb477c30SDaniel Golle case PHY_INTERFACE_MODE_RGMII_TXID: 1498cb477c30SDaniel Golle gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK, 0, port); 1499cb477c30SDaniel Golle break; 1500cb477c30SDaniel Golle default: 1501cb477c30SDaniel Golle break; 1502cb477c30SDaniel Golle } 1503cb477c30SDaniel Golle } 1504cb477c30SDaniel Golle 1505cb477c30SDaniel Golle static void gswip_phylink_mac_link_down(struct phylink_config *config, 1506cb477c30SDaniel Golle unsigned int mode, 1507cb477c30SDaniel Golle phy_interface_t interface) 1508cb477c30SDaniel Golle { 1509cb477c30SDaniel Golle struct dsa_port *dp = dsa_phylink_to_port(config); 1510cb477c30SDaniel Golle struct gswip_priv *priv = dp->ds->priv; 1511cb477c30SDaniel Golle int port = dp->index; 1512cb477c30SDaniel Golle 1513cb477c30SDaniel Golle gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, port); 1514cb477c30SDaniel Golle 1515cb477c30SDaniel Golle if (!dsa_port_is_cpu(dp)) 1516cb477c30SDaniel Golle gswip_port_set_link(priv, port, false); 1517cb477c30SDaniel Golle } 1518cb477c30SDaniel Golle 1519cb477c30SDaniel Golle static void gswip_phylink_mac_link_up(struct phylink_config *config, 1520cb477c30SDaniel Golle struct phy_device *phydev, 1521cb477c30SDaniel Golle unsigned int mode, 1522cb477c30SDaniel Golle phy_interface_t interface, 1523cb477c30SDaniel Golle int speed, int duplex, 1524cb477c30SDaniel Golle bool tx_pause, bool rx_pause) 1525cb477c30SDaniel Golle { 1526cb477c30SDaniel Golle struct dsa_port *dp = dsa_phylink_to_port(config); 1527cb477c30SDaniel Golle struct gswip_priv *priv = dp->ds->priv; 1528cb477c30SDaniel Golle int port = dp->index; 1529cb477c30SDaniel Golle 1530cb477c30SDaniel Golle if (!dsa_port_is_cpu(dp)) { 1531cb477c30SDaniel Golle gswip_port_set_link(priv, port, true); 1532cb477c30SDaniel Golle gswip_port_set_speed(priv, port, speed, interface); 1533cb477c30SDaniel Golle gswip_port_set_duplex(priv, port, duplex); 1534cb477c30SDaniel Golle gswip_port_set_pause(priv, port, tx_pause, rx_pause); 1535cb477c30SDaniel Golle } 1536cb477c30SDaniel Golle 1537cb477c30SDaniel Golle gswip_mii_mask_cfg(priv, 0, GSWIP_MII_CFG_EN, port); 1538cb477c30SDaniel Golle } 1539cb477c30SDaniel Golle 1540cb477c30SDaniel Golle static void gswip_get_strings(struct dsa_switch *ds, int port, u32 stringset, 1541cb477c30SDaniel Golle uint8_t *data) 1542cb477c30SDaniel Golle { 1543cb477c30SDaniel Golle int i; 1544cb477c30SDaniel Golle 1545cb477c30SDaniel Golle if (stringset != ETH_SS_STATS) 1546cb477c30SDaniel Golle return; 1547cb477c30SDaniel Golle 1548cb477c30SDaniel Golle for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) 1549cb477c30SDaniel Golle ethtool_puts(&data, gswip_rmon_cnt[i].name); 1550cb477c30SDaniel Golle } 1551cb477c30SDaniel Golle 1552cb477c30SDaniel Golle static u32 gswip_bcm_ram_entry_read(struct gswip_priv *priv, u32 table, 1553cb477c30SDaniel Golle u32 index) 1554cb477c30SDaniel Golle { 1555cb477c30SDaniel Golle u32 result; 1556cb477c30SDaniel Golle int err; 1557cb477c30SDaniel Golle 1558cb477c30SDaniel Golle gswip_switch_w(priv, index, GSWIP_BM_RAM_ADDR); 1559cb477c30SDaniel Golle gswip_switch_mask(priv, GSWIP_BM_RAM_CTRL_ADDR_MASK | 1560cb477c30SDaniel Golle GSWIP_BM_RAM_CTRL_OPMOD, 1561cb477c30SDaniel Golle table | GSWIP_BM_RAM_CTRL_BAS, 1562cb477c30SDaniel Golle GSWIP_BM_RAM_CTRL); 1563cb477c30SDaniel Golle 1564cb477c30SDaniel Golle err = gswip_switch_r_timeout(priv, GSWIP_BM_RAM_CTRL, 1565cb477c30SDaniel Golle GSWIP_BM_RAM_CTRL_BAS); 1566cb477c30SDaniel Golle if (err) { 1567cb477c30SDaniel Golle dev_err(priv->dev, "timeout while reading table: %u, index: %u\n", 1568cb477c30SDaniel Golle table, index); 1569cb477c30SDaniel Golle return 0; 1570cb477c30SDaniel Golle } 1571cb477c30SDaniel Golle 1572cb477c30SDaniel Golle result = gswip_switch_r(priv, GSWIP_BM_RAM_VAL(0)); 1573cb477c30SDaniel Golle result |= gswip_switch_r(priv, GSWIP_BM_RAM_VAL(1)) << 16; 1574cb477c30SDaniel Golle 1575cb477c30SDaniel Golle return result; 1576cb477c30SDaniel Golle } 1577cb477c30SDaniel Golle 1578cb477c30SDaniel Golle static void gswip_get_ethtool_stats(struct dsa_switch *ds, int port, 1579cb477c30SDaniel Golle uint64_t *data) 1580cb477c30SDaniel Golle { 1581cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1582cb477c30SDaniel Golle const struct gswip_rmon_cnt_desc *rmon_cnt; 1583cb477c30SDaniel Golle int i; 1584cb477c30SDaniel Golle u64 high; 1585cb477c30SDaniel Golle 1586cb477c30SDaniel Golle for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) { 1587cb477c30SDaniel Golle rmon_cnt = &gswip_rmon_cnt[i]; 1588cb477c30SDaniel Golle 1589cb477c30SDaniel Golle data[i] = gswip_bcm_ram_entry_read(priv, port, 1590cb477c30SDaniel Golle rmon_cnt->offset); 1591cb477c30SDaniel Golle if (rmon_cnt->size == 2) { 1592cb477c30SDaniel Golle high = gswip_bcm_ram_entry_read(priv, port, 1593cb477c30SDaniel Golle rmon_cnt->offset + 1); 1594cb477c30SDaniel Golle data[i] |= high << 32; 1595cb477c30SDaniel Golle } 1596cb477c30SDaniel Golle } 1597cb477c30SDaniel Golle } 1598cb477c30SDaniel Golle 1599cb477c30SDaniel Golle static int gswip_get_sset_count(struct dsa_switch *ds, int port, int sset) 1600cb477c30SDaniel Golle { 1601cb477c30SDaniel Golle if (sset != ETH_SS_STATS) 1602cb477c30SDaniel Golle return 0; 1603cb477c30SDaniel Golle 1604cb477c30SDaniel Golle return ARRAY_SIZE(gswip_rmon_cnt); 1605cb477c30SDaniel Golle } 1606cb477c30SDaniel Golle 16077a1eaef0SDaniel Golle static struct phylink_pcs *gswip_phylink_mac_select_pcs(struct phylink_config *config, 16087a1eaef0SDaniel Golle phy_interface_t interface) 16097a1eaef0SDaniel Golle { 16107a1eaef0SDaniel Golle struct dsa_port *dp = dsa_phylink_to_port(config); 16117a1eaef0SDaniel Golle struct gswip_priv *priv = dp->ds->priv; 16127a1eaef0SDaniel Golle 16137a1eaef0SDaniel Golle if (priv->hw_info->mac_select_pcs) 16147a1eaef0SDaniel Golle return priv->hw_info->mac_select_pcs(config, interface); 16157a1eaef0SDaniel Golle 16167a1eaef0SDaniel Golle return NULL; 16177a1eaef0SDaniel Golle } 16187a1eaef0SDaniel Golle 1619cb477c30SDaniel Golle static const struct phylink_mac_ops gswip_phylink_mac_ops = { 1620cb477c30SDaniel Golle .mac_config = gswip_phylink_mac_config, 1621cb477c30SDaniel Golle .mac_link_down = gswip_phylink_mac_link_down, 1622cb477c30SDaniel Golle .mac_link_up = gswip_phylink_mac_link_up, 16237a1eaef0SDaniel Golle .mac_select_pcs = gswip_phylink_mac_select_pcs, 1624cb477c30SDaniel Golle }; 1625cb477c30SDaniel Golle 1626cb477c30SDaniel Golle static const struct dsa_switch_ops gswip_switch_ops = { 1627cb477c30SDaniel Golle .get_tag_protocol = gswip_get_tag_protocol, 1628cb477c30SDaniel Golle .setup = gswip_setup, 1629cb477c30SDaniel Golle .port_enable = gswip_port_enable, 1630cb477c30SDaniel Golle .port_disable = gswip_port_disable, 1631cb477c30SDaniel Golle .port_bridge_join = gswip_port_bridge_join, 1632cb477c30SDaniel Golle .port_bridge_leave = gswip_port_bridge_leave, 1633cb477c30SDaniel Golle .port_fast_age = gswip_port_fast_age, 1634cb477c30SDaniel Golle .port_vlan_filtering = gswip_port_vlan_filtering, 1635cb477c30SDaniel Golle .port_vlan_add = gswip_port_vlan_add, 1636cb477c30SDaniel Golle .port_vlan_del = gswip_port_vlan_del, 1637cb477c30SDaniel Golle .port_stp_state_set = gswip_port_stp_state_set, 1638cb477c30SDaniel Golle .port_fdb_add = gswip_port_fdb_add, 1639cb477c30SDaniel Golle .port_fdb_del = gswip_port_fdb_del, 1640cb477c30SDaniel Golle .port_fdb_dump = gswip_port_fdb_dump, 1641cb477c30SDaniel Golle .port_change_mtu = gswip_port_change_mtu, 1642cb477c30SDaniel Golle .port_max_mtu = gswip_port_max_mtu, 1643cb477c30SDaniel Golle .phylink_get_caps = gswip_phylink_get_caps, 1644cb477c30SDaniel Golle .get_strings = gswip_get_strings, 1645cb477c30SDaniel Golle .get_ethtool_stats = gswip_get_ethtool_stats, 1646cb477c30SDaniel Golle .get_sset_count = gswip_get_sset_count, 1647cb477c30SDaniel Golle }; 1648cb477c30SDaniel Golle 1649cb477c30SDaniel Golle static const struct xway_gphy_match_data xrx200a1x_gphy_data = { 1650cb477c30SDaniel Golle .fe_firmware_name = "lantiq/xrx200_phy22f_a14.bin", 1651cb477c30SDaniel Golle .ge_firmware_name = "lantiq/xrx200_phy11g_a14.bin", 1652cb477c30SDaniel Golle }; 1653cb477c30SDaniel Golle 1654cb477c30SDaniel Golle static const struct xway_gphy_match_data xrx200a2x_gphy_data = { 1655cb477c30SDaniel Golle .fe_firmware_name = "lantiq/xrx200_phy22f_a22.bin", 1656cb477c30SDaniel Golle .ge_firmware_name = "lantiq/xrx200_phy11g_a22.bin", 1657cb477c30SDaniel Golle }; 1658cb477c30SDaniel Golle 1659cb477c30SDaniel Golle static const struct xway_gphy_match_data xrx300_gphy_data = { 1660cb477c30SDaniel Golle .fe_firmware_name = "lantiq/xrx300_phy22f_a21.bin", 1661cb477c30SDaniel Golle .ge_firmware_name = "lantiq/xrx300_phy11g_a21.bin", 1662cb477c30SDaniel Golle }; 1663cb477c30SDaniel Golle 1664cb477c30SDaniel Golle static const struct of_device_id xway_gphy_match[] __maybe_unused = { 1665cb477c30SDaniel Golle { .compatible = "lantiq,xrx200-gphy-fw", .data = NULL }, 1666cb477c30SDaniel Golle { .compatible = "lantiq,xrx200a1x-gphy-fw", .data = &xrx200a1x_gphy_data }, 1667cb477c30SDaniel Golle { .compatible = "lantiq,xrx200a2x-gphy-fw", .data = &xrx200a2x_gphy_data }, 1668cb477c30SDaniel Golle { .compatible = "lantiq,xrx300-gphy-fw", .data = &xrx300_gphy_data }, 1669cb477c30SDaniel Golle { .compatible = "lantiq,xrx330-gphy-fw", .data = &xrx300_gphy_data }, 1670cb477c30SDaniel Golle {}, 1671cb477c30SDaniel Golle }; 1672cb477c30SDaniel Golle 1673cb477c30SDaniel Golle static int gswip_gphy_fw_load(struct gswip_priv *priv, struct gswip_gphy_fw *gphy_fw) 1674cb477c30SDaniel Golle { 1675cb477c30SDaniel Golle struct device *dev = priv->dev; 1676cb477c30SDaniel Golle const struct firmware *fw; 1677cb477c30SDaniel Golle void *fw_addr; 1678cb477c30SDaniel Golle dma_addr_t dma_addr; 1679cb477c30SDaniel Golle dma_addr_t dev_addr; 1680cb477c30SDaniel Golle size_t size; 1681cb477c30SDaniel Golle int ret; 1682cb477c30SDaniel Golle 1683cb477c30SDaniel Golle ret = clk_prepare_enable(gphy_fw->clk_gate); 1684cb477c30SDaniel Golle if (ret) 1685cb477c30SDaniel Golle return ret; 1686cb477c30SDaniel Golle 1687cb477c30SDaniel Golle reset_control_assert(gphy_fw->reset); 1688cb477c30SDaniel Golle 1689cb477c30SDaniel Golle /* The vendor BSP uses a 200ms delay after asserting the reset line. 1690cb477c30SDaniel Golle * Without this some users are observing that the PHY is not coming up 1691cb477c30SDaniel Golle * on the MDIO bus. 1692cb477c30SDaniel Golle */ 1693cb477c30SDaniel Golle msleep(200); 1694cb477c30SDaniel Golle 1695cb477c30SDaniel Golle ret = request_firmware(&fw, gphy_fw->fw_name, dev); 1696cb477c30SDaniel Golle if (ret) 1697cb477c30SDaniel Golle return dev_err_probe(dev, ret, "failed to load firmware: %s\n", 1698cb477c30SDaniel Golle gphy_fw->fw_name); 1699cb477c30SDaniel Golle 1700cb477c30SDaniel Golle /* GPHY cores need the firmware code in a persistent and contiguous 1701cb477c30SDaniel Golle * memory area with a 16 kB boundary aligned start address. 1702cb477c30SDaniel Golle */ 1703cb477c30SDaniel Golle size = fw->size + XRX200_GPHY_FW_ALIGN; 1704cb477c30SDaniel Golle 1705cb477c30SDaniel Golle fw_addr = dmam_alloc_coherent(dev, size, &dma_addr, GFP_KERNEL); 1706cb477c30SDaniel Golle if (fw_addr) { 1707cb477c30SDaniel Golle fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN); 1708cb477c30SDaniel Golle dev_addr = ALIGN(dma_addr, XRX200_GPHY_FW_ALIGN); 1709cb477c30SDaniel Golle memcpy(fw_addr, fw->data, fw->size); 1710cb477c30SDaniel Golle } else { 1711cb477c30SDaniel Golle release_firmware(fw); 1712cb477c30SDaniel Golle return -ENOMEM; 1713cb477c30SDaniel Golle } 1714cb477c30SDaniel Golle 1715cb477c30SDaniel Golle release_firmware(fw); 1716cb477c30SDaniel Golle 1717cb477c30SDaniel Golle ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, dev_addr); 1718cb477c30SDaniel Golle if (ret) 1719cb477c30SDaniel Golle return ret; 1720cb477c30SDaniel Golle 1721cb477c30SDaniel Golle reset_control_deassert(gphy_fw->reset); 1722cb477c30SDaniel Golle 1723cb477c30SDaniel Golle return ret; 1724cb477c30SDaniel Golle } 1725cb477c30SDaniel Golle 1726cb477c30SDaniel Golle static int gswip_gphy_fw_probe(struct gswip_priv *priv, 1727cb477c30SDaniel Golle struct gswip_gphy_fw *gphy_fw, 1728cb477c30SDaniel Golle struct device_node *gphy_fw_np, int i) 1729cb477c30SDaniel Golle { 1730cb477c30SDaniel Golle struct device *dev = priv->dev; 1731cb477c30SDaniel Golle u32 gphy_mode; 1732cb477c30SDaniel Golle int ret; 1733cb477c30SDaniel Golle char gphyname[10]; 1734cb477c30SDaniel Golle 1735cb477c30SDaniel Golle snprintf(gphyname, sizeof(gphyname), "gphy%d", i); 1736cb477c30SDaniel Golle 1737cb477c30SDaniel Golle gphy_fw->clk_gate = devm_clk_get(dev, gphyname); 1738cb477c30SDaniel Golle if (IS_ERR(gphy_fw->clk_gate)) { 1739cb477c30SDaniel Golle return dev_err_probe(dev, PTR_ERR(gphy_fw->clk_gate), 1740cb477c30SDaniel Golle "Failed to lookup gate clock\n"); 1741cb477c30SDaniel Golle } 1742cb477c30SDaniel Golle 1743cb477c30SDaniel Golle ret = of_property_read_u32(gphy_fw_np, "reg", &gphy_fw->fw_addr_offset); 1744cb477c30SDaniel Golle if (ret) 1745cb477c30SDaniel Golle return ret; 1746cb477c30SDaniel Golle 1747cb477c30SDaniel Golle ret = of_property_read_u32(gphy_fw_np, "lantiq,gphy-mode", &gphy_mode); 1748cb477c30SDaniel Golle /* Default to GE mode */ 1749cb477c30SDaniel Golle if (ret) 1750cb477c30SDaniel Golle gphy_mode = GPHY_MODE_GE; 1751cb477c30SDaniel Golle 1752cb477c30SDaniel Golle switch (gphy_mode) { 1753cb477c30SDaniel Golle case GPHY_MODE_FE: 1754cb477c30SDaniel Golle gphy_fw->fw_name = priv->gphy_fw_name_cfg->fe_firmware_name; 1755cb477c30SDaniel Golle break; 1756cb477c30SDaniel Golle case GPHY_MODE_GE: 1757cb477c30SDaniel Golle gphy_fw->fw_name = priv->gphy_fw_name_cfg->ge_firmware_name; 1758cb477c30SDaniel Golle break; 1759cb477c30SDaniel Golle default: 1760cb477c30SDaniel Golle return dev_err_probe(dev, -EINVAL, "Unknown GPHY mode %d\n", 1761cb477c30SDaniel Golle gphy_mode); 1762cb477c30SDaniel Golle } 1763cb477c30SDaniel Golle 1764cb477c30SDaniel Golle gphy_fw->reset = of_reset_control_array_get_exclusive(gphy_fw_np); 1765cb477c30SDaniel Golle if (IS_ERR(gphy_fw->reset)) 1766cb477c30SDaniel Golle return dev_err_probe(dev, PTR_ERR(gphy_fw->reset), 1767cb477c30SDaniel Golle "Failed to lookup gphy reset\n"); 1768cb477c30SDaniel Golle 1769cb477c30SDaniel Golle return gswip_gphy_fw_load(priv, gphy_fw); 1770cb477c30SDaniel Golle } 1771cb477c30SDaniel Golle 1772cb477c30SDaniel Golle static void gswip_gphy_fw_remove(struct gswip_priv *priv, 1773cb477c30SDaniel Golle struct gswip_gphy_fw *gphy_fw) 1774cb477c30SDaniel Golle { 1775cb477c30SDaniel Golle int ret; 1776cb477c30SDaniel Golle 1777cb477c30SDaniel Golle /* check if the device was fully probed */ 1778cb477c30SDaniel Golle if (!gphy_fw->fw_name) 1779cb477c30SDaniel Golle return; 1780cb477c30SDaniel Golle 1781cb477c30SDaniel Golle ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, 0); 1782cb477c30SDaniel Golle if (ret) 1783cb477c30SDaniel Golle dev_err(priv->dev, "can not reset GPHY FW pointer\n"); 1784cb477c30SDaniel Golle 1785cb477c30SDaniel Golle clk_disable_unprepare(gphy_fw->clk_gate); 1786cb477c30SDaniel Golle 1787cb477c30SDaniel Golle reset_control_put(gphy_fw->reset); 1788cb477c30SDaniel Golle } 1789cb477c30SDaniel Golle 1790cb477c30SDaniel Golle static int gswip_gphy_fw_list(struct gswip_priv *priv, 1791cb477c30SDaniel Golle struct device_node *gphy_fw_list_np, u32 version) 1792cb477c30SDaniel Golle { 1793cb477c30SDaniel Golle struct device *dev = priv->dev; 1794cb477c30SDaniel Golle struct device_node *gphy_fw_np; 1795cb477c30SDaniel Golle const struct of_device_id *match; 1796cb477c30SDaniel Golle int err; 1797cb477c30SDaniel Golle int i = 0; 1798cb477c30SDaniel Golle 1799cb477c30SDaniel Golle /* The VRX200 rev 1.1 uses the GSWIP 2.0 and needs the older 1800cb477c30SDaniel Golle * GPHY firmware. The VRX200 rev 1.2 uses the GSWIP 2.1 and also 1801cb477c30SDaniel Golle * needs a different GPHY firmware. 1802cb477c30SDaniel Golle */ 1803cb477c30SDaniel Golle if (of_device_is_compatible(gphy_fw_list_np, "lantiq,xrx200-gphy-fw")) { 1804cb477c30SDaniel Golle switch (version) { 1805cb477c30SDaniel Golle case GSWIP_VERSION_2_0: 1806cb477c30SDaniel Golle priv->gphy_fw_name_cfg = &xrx200a1x_gphy_data; 1807cb477c30SDaniel Golle break; 1808cb477c30SDaniel Golle case GSWIP_VERSION_2_1: 1809cb477c30SDaniel Golle priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data; 1810cb477c30SDaniel Golle break; 1811cb477c30SDaniel Golle default: 1812cb477c30SDaniel Golle return dev_err_probe(dev, -ENOENT, 1813cb477c30SDaniel Golle "unknown GSWIP version: 0x%x\n", 1814cb477c30SDaniel Golle version); 1815cb477c30SDaniel Golle } 1816cb477c30SDaniel Golle } 1817cb477c30SDaniel Golle 1818cb477c30SDaniel Golle match = of_match_node(xway_gphy_match, gphy_fw_list_np); 1819cb477c30SDaniel Golle if (match && match->data) 1820cb477c30SDaniel Golle priv->gphy_fw_name_cfg = match->data; 1821cb477c30SDaniel Golle 1822cb477c30SDaniel Golle if (!priv->gphy_fw_name_cfg) 1823cb477c30SDaniel Golle return dev_err_probe(dev, -ENOENT, 1824cb477c30SDaniel Golle "GPHY compatible type not supported\n"); 1825cb477c30SDaniel Golle 1826cb477c30SDaniel Golle priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np); 1827cb477c30SDaniel Golle if (!priv->num_gphy_fw) 1828cb477c30SDaniel Golle return -ENOENT; 1829cb477c30SDaniel Golle 1830cb477c30SDaniel Golle priv->rcu_regmap = syscon_regmap_lookup_by_phandle(gphy_fw_list_np, 1831cb477c30SDaniel Golle "lantiq,rcu"); 1832cb477c30SDaniel Golle if (IS_ERR(priv->rcu_regmap)) 1833cb477c30SDaniel Golle return PTR_ERR(priv->rcu_regmap); 1834cb477c30SDaniel Golle 1835cb477c30SDaniel Golle priv->gphy_fw = devm_kmalloc_array(dev, priv->num_gphy_fw, 1836cb477c30SDaniel Golle sizeof(*priv->gphy_fw), 1837cb477c30SDaniel Golle GFP_KERNEL | __GFP_ZERO); 1838cb477c30SDaniel Golle if (!priv->gphy_fw) 1839cb477c30SDaniel Golle return -ENOMEM; 1840cb477c30SDaniel Golle 1841cb477c30SDaniel Golle for_each_available_child_of_node(gphy_fw_list_np, gphy_fw_np) { 1842cb477c30SDaniel Golle err = gswip_gphy_fw_probe(priv, &priv->gphy_fw[i], 1843cb477c30SDaniel Golle gphy_fw_np, i); 1844cb477c30SDaniel Golle if (err) { 1845cb477c30SDaniel Golle of_node_put(gphy_fw_np); 1846cb477c30SDaniel Golle goto remove_gphy; 1847cb477c30SDaniel Golle } 1848cb477c30SDaniel Golle i++; 1849cb477c30SDaniel Golle } 1850cb477c30SDaniel Golle 1851cb477c30SDaniel Golle /* The standalone PHY11G requires 300ms to be fully 1852cb477c30SDaniel Golle * initialized and ready for any MDIO communication after being 1853cb477c30SDaniel Golle * taken out of reset. For the SoC-internal GPHY variant there 1854cb477c30SDaniel Golle * is no (known) documentation for the minimum time after a 1855cb477c30SDaniel Golle * reset. Use the same value as for the standalone variant as 1856cb477c30SDaniel Golle * some users have reported internal PHYs not being detected 1857cb477c30SDaniel Golle * without any delay. 1858cb477c30SDaniel Golle */ 1859cb477c30SDaniel Golle msleep(300); 1860cb477c30SDaniel Golle 1861cb477c30SDaniel Golle return 0; 1862cb477c30SDaniel Golle 1863cb477c30SDaniel Golle remove_gphy: 1864cb477c30SDaniel Golle for (i = 0; i < priv->num_gphy_fw; i++) 1865cb477c30SDaniel Golle gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); 1866cb477c30SDaniel Golle return err; 1867cb477c30SDaniel Golle } 1868cb477c30SDaniel Golle 1869cb477c30SDaniel Golle static int gswip_validate_cpu_port(struct dsa_switch *ds) 1870cb477c30SDaniel Golle { 1871cb477c30SDaniel Golle struct gswip_priv *priv = ds->priv; 1872cb477c30SDaniel Golle struct dsa_port *cpu_dp; 1873cb477c30SDaniel Golle int cpu_port = -1; 1874cb477c30SDaniel Golle 1875cb477c30SDaniel Golle dsa_switch_for_each_cpu_port(cpu_dp, ds) { 1876cb477c30SDaniel Golle if (cpu_port != -1) 1877cb477c30SDaniel Golle return dev_err_probe(ds->dev, -EINVAL, 1878cb477c30SDaniel Golle "only a single CPU port is supported\n"); 1879cb477c30SDaniel Golle 1880cb477c30SDaniel Golle cpu_port = cpu_dp->index; 1881cb477c30SDaniel Golle } 1882cb477c30SDaniel Golle 1883cb477c30SDaniel Golle if (cpu_port == -1) 1884cb477c30SDaniel Golle return dev_err_probe(ds->dev, -EINVAL, "no CPU port defined\n"); 1885cb477c30SDaniel Golle 1886cb477c30SDaniel Golle if (BIT(cpu_port) & ~priv->hw_info->allowed_cpu_ports) 1887cb477c30SDaniel Golle return dev_err_probe(ds->dev, -EINVAL, 1888cb477c30SDaniel Golle "unsupported CPU port defined\n"); 1889cb477c30SDaniel Golle 1890cb477c30SDaniel Golle return 0; 1891cb477c30SDaniel Golle } 1892cb477c30SDaniel Golle 1893cb477c30SDaniel Golle static int gswip_probe(struct platform_device *pdev) 1894cb477c30SDaniel Golle { 1895cb477c30SDaniel Golle struct device_node *np, *gphy_fw_np; 1896cb477c30SDaniel Golle struct device *dev = &pdev->dev; 1897cb477c30SDaniel Golle struct gswip_priv *priv; 1898cb477c30SDaniel Golle int err; 1899cb477c30SDaniel Golle int i; 1900cb477c30SDaniel Golle u32 version; 1901cb477c30SDaniel Golle 1902cb477c30SDaniel Golle priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 1903cb477c30SDaniel Golle if (!priv) 1904cb477c30SDaniel Golle return -ENOMEM; 1905cb477c30SDaniel Golle 1906cb477c30SDaniel Golle priv->gswip = devm_platform_ioremap_resource(pdev, 0); 1907cb477c30SDaniel Golle if (IS_ERR(priv->gswip)) 1908cb477c30SDaniel Golle return PTR_ERR(priv->gswip); 1909cb477c30SDaniel Golle 1910cb477c30SDaniel Golle priv->mdio = devm_platform_ioremap_resource(pdev, 1); 1911cb477c30SDaniel Golle if (IS_ERR(priv->mdio)) 1912cb477c30SDaniel Golle return PTR_ERR(priv->mdio); 1913cb477c30SDaniel Golle 1914cb477c30SDaniel Golle priv->mii = devm_platform_ioremap_resource(pdev, 2); 1915cb477c30SDaniel Golle if (IS_ERR(priv->mii)) 1916cb477c30SDaniel Golle return PTR_ERR(priv->mii); 1917cb477c30SDaniel Golle 1918cb477c30SDaniel Golle priv->hw_info = of_device_get_match_data(dev); 1919cb477c30SDaniel Golle if (!priv->hw_info) 1920cb477c30SDaniel Golle return -EINVAL; 1921cb477c30SDaniel Golle 1922cb477c30SDaniel Golle priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); 1923cb477c30SDaniel Golle if (!priv->ds) 1924cb477c30SDaniel Golle return -ENOMEM; 1925cb477c30SDaniel Golle 1926cb477c30SDaniel Golle priv->ds->dev = dev; 1927cb477c30SDaniel Golle priv->ds->num_ports = priv->hw_info->max_ports; 1928cb477c30SDaniel Golle priv->ds->priv = priv; 1929cb477c30SDaniel Golle priv->ds->ops = &gswip_switch_ops; 1930cb477c30SDaniel Golle priv->ds->phylink_mac_ops = &gswip_phylink_mac_ops; 1931cb477c30SDaniel Golle priv->dev = dev; 1932cb477c30SDaniel Golle mutex_init(&priv->pce_table_lock); 1933cb477c30SDaniel Golle version = gswip_switch_r(priv, GSWIP_VERSION); 1934cb477c30SDaniel Golle 1935cb477c30SDaniel Golle /* The hardware has the 'major/minor' version bytes in the wrong order 1936cb477c30SDaniel Golle * preventing numerical comparisons. Construct a 16-bit unsigned integer 1937cb477c30SDaniel Golle * having the REV field as most significant byte and the MOD field as 1938cb477c30SDaniel Golle * least significant byte. This is effectively swapping the two bytes of 1939cb477c30SDaniel Golle * the version variable, but other than using swab16 it doesn't affect 1940cb477c30SDaniel Golle * the source variable. 1941cb477c30SDaniel Golle */ 1942cb477c30SDaniel Golle priv->version = GSWIP_VERSION_REV(version) << 8 | 1943cb477c30SDaniel Golle GSWIP_VERSION_MOD(version); 1944cb477c30SDaniel Golle 1945cb477c30SDaniel Golle np = dev->of_node; 1946cb477c30SDaniel Golle switch (version) { 1947cb477c30SDaniel Golle case GSWIP_VERSION_2_0: 1948cb477c30SDaniel Golle case GSWIP_VERSION_2_1: 1949cb477c30SDaniel Golle if (!of_device_is_compatible(np, "lantiq,xrx200-gswip")) 1950cb477c30SDaniel Golle return -EINVAL; 1951cb477c30SDaniel Golle break; 1952cb477c30SDaniel Golle case GSWIP_VERSION_2_2: 1953cb477c30SDaniel Golle case GSWIP_VERSION_2_2_ETC: 1954cb477c30SDaniel Golle if (!of_device_is_compatible(np, "lantiq,xrx300-gswip") && 1955cb477c30SDaniel Golle !of_device_is_compatible(np, "lantiq,xrx330-gswip")) 1956cb477c30SDaniel Golle return -EINVAL; 1957cb477c30SDaniel Golle break; 1958cb477c30SDaniel Golle default: 1959cb477c30SDaniel Golle return dev_err_probe(dev, -ENOENT, 1960cb477c30SDaniel Golle "unknown GSWIP version: 0x%x\n", version); 1961cb477c30SDaniel Golle } 1962cb477c30SDaniel Golle 1963cb477c30SDaniel Golle /* bring up the mdio bus */ 1964cb477c30SDaniel Golle gphy_fw_np = of_get_compatible_child(dev->of_node, "lantiq,gphy-fw"); 1965cb477c30SDaniel Golle if (gphy_fw_np) { 1966cb477c30SDaniel Golle err = gswip_gphy_fw_list(priv, gphy_fw_np, version); 1967cb477c30SDaniel Golle of_node_put(gphy_fw_np); 1968cb477c30SDaniel Golle if (err) 1969cb477c30SDaniel Golle return dev_err_probe(dev, err, 1970cb477c30SDaniel Golle "gphy fw probe failed\n"); 1971cb477c30SDaniel Golle } 1972cb477c30SDaniel Golle 1973cb477c30SDaniel Golle /* bring up the mdio bus */ 1974cb477c30SDaniel Golle err = gswip_mdio(priv); 1975cb477c30SDaniel Golle if (err) { 1976cb477c30SDaniel Golle dev_err_probe(dev, err, "mdio probe failed\n"); 1977cb477c30SDaniel Golle goto gphy_fw_remove; 1978cb477c30SDaniel Golle } 1979cb477c30SDaniel Golle 1980cb477c30SDaniel Golle err = dsa_register_switch(priv->ds); 1981cb477c30SDaniel Golle if (err) { 1982cb477c30SDaniel Golle dev_err_probe(dev, err, "dsa switch registration failed\n"); 1983cb477c30SDaniel Golle goto gphy_fw_remove; 1984cb477c30SDaniel Golle } 1985cb477c30SDaniel Golle 1986cb477c30SDaniel Golle err = gswip_validate_cpu_port(priv->ds); 1987cb477c30SDaniel Golle if (err) 1988cb477c30SDaniel Golle goto disable_switch; 1989cb477c30SDaniel Golle 1990cb477c30SDaniel Golle platform_set_drvdata(pdev, priv); 1991cb477c30SDaniel Golle 1992cb477c30SDaniel Golle dev_info(dev, "probed GSWIP version %lx mod %lx\n", 1993cb477c30SDaniel Golle GSWIP_VERSION_REV(version), GSWIP_VERSION_MOD(version)); 1994cb477c30SDaniel Golle return 0; 1995cb477c30SDaniel Golle 1996cb477c30SDaniel Golle disable_switch: 1997cb477c30SDaniel Golle gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); 1998cb477c30SDaniel Golle dsa_unregister_switch(priv->ds); 1999cb477c30SDaniel Golle gphy_fw_remove: 2000cb477c30SDaniel Golle for (i = 0; i < priv->num_gphy_fw; i++) 2001cb477c30SDaniel Golle gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); 2002cb477c30SDaniel Golle return err; 2003cb477c30SDaniel Golle } 2004cb477c30SDaniel Golle 2005cb477c30SDaniel Golle static void gswip_remove(struct platform_device *pdev) 2006cb477c30SDaniel Golle { 2007cb477c30SDaniel Golle struct gswip_priv *priv = platform_get_drvdata(pdev); 2008cb477c30SDaniel Golle int i; 2009cb477c30SDaniel Golle 2010cb477c30SDaniel Golle if (!priv) 2011cb477c30SDaniel Golle return; 2012cb477c30SDaniel Golle 2013cb477c30SDaniel Golle /* disable the switch */ 2014cb477c30SDaniel Golle gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); 2015cb477c30SDaniel Golle 2016cb477c30SDaniel Golle dsa_unregister_switch(priv->ds); 2017cb477c30SDaniel Golle 2018cb477c30SDaniel Golle for (i = 0; i < priv->num_gphy_fw; i++) 2019cb477c30SDaniel Golle gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); 2020cb477c30SDaniel Golle } 2021cb477c30SDaniel Golle 2022cb477c30SDaniel Golle static void gswip_shutdown(struct platform_device *pdev) 2023cb477c30SDaniel Golle { 2024cb477c30SDaniel Golle struct gswip_priv *priv = platform_get_drvdata(pdev); 2025cb477c30SDaniel Golle 2026cb477c30SDaniel Golle if (!priv) 2027cb477c30SDaniel Golle return; 2028cb477c30SDaniel Golle 2029cb477c30SDaniel Golle dsa_switch_shutdown(priv->ds); 2030cb477c30SDaniel Golle 2031cb477c30SDaniel Golle platform_set_drvdata(pdev, NULL); 2032cb477c30SDaniel Golle } 2033cb477c30SDaniel Golle 2034cb477c30SDaniel Golle static const struct gswip_hw_info gswip_xrx200 = { 2035cb477c30SDaniel Golle .max_ports = 7, 2036cb477c30SDaniel Golle .allowed_cpu_ports = BIT(6), 2037cb477c30SDaniel Golle .mii_ports = BIT(0) | BIT(1) | BIT(5), 2038*51578203SDaniel Golle .mii_port_reg_offset = 0, 2039cb477c30SDaniel Golle .phylink_get_caps = gswip_xrx200_phylink_get_caps, 2040cb477c30SDaniel Golle .pce_microcode = &gswip_pce_microcode, 2041cb477c30SDaniel Golle .pce_microcode_size = ARRAY_SIZE(gswip_pce_microcode), 2042cb477c30SDaniel Golle .tag_protocol = DSA_TAG_PROTO_GSWIP, 2043cb477c30SDaniel Golle }; 2044cb477c30SDaniel Golle 2045cb477c30SDaniel Golle static const struct gswip_hw_info gswip_xrx300 = { 2046cb477c30SDaniel Golle .max_ports = 7, 2047cb477c30SDaniel Golle .allowed_cpu_ports = BIT(6), 2048cb477c30SDaniel Golle .mii_ports = BIT(0) | BIT(5), 2049*51578203SDaniel Golle .mii_port_reg_offset = 0, 2050cb477c30SDaniel Golle .phylink_get_caps = gswip_xrx300_phylink_get_caps, 2051cb477c30SDaniel Golle .pce_microcode = &gswip_pce_microcode, 2052cb477c30SDaniel Golle .pce_microcode_size = ARRAY_SIZE(gswip_pce_microcode), 2053cb477c30SDaniel Golle .tag_protocol = DSA_TAG_PROTO_GSWIP, 2054cb477c30SDaniel Golle }; 2055cb477c30SDaniel Golle 2056cb477c30SDaniel Golle static const struct of_device_id gswip_of_match[] = { 2057cb477c30SDaniel Golle { .compatible = "lantiq,xrx200-gswip", .data = &gswip_xrx200 }, 2058cb477c30SDaniel Golle { .compatible = "lantiq,xrx300-gswip", .data = &gswip_xrx300 }, 2059cb477c30SDaniel Golle { .compatible = "lantiq,xrx330-gswip", .data = &gswip_xrx300 }, 2060cb477c30SDaniel Golle {}, 2061cb477c30SDaniel Golle }; 2062cb477c30SDaniel Golle MODULE_DEVICE_TABLE(of, gswip_of_match); 2063cb477c30SDaniel Golle 2064cb477c30SDaniel Golle static struct platform_driver gswip_driver = { 2065cb477c30SDaniel Golle .probe = gswip_probe, 2066cb477c30SDaniel Golle .remove = gswip_remove, 2067cb477c30SDaniel Golle .shutdown = gswip_shutdown, 2068cb477c30SDaniel Golle .driver = { 2069cb477c30SDaniel Golle .name = "gswip", 2070cb477c30SDaniel Golle .of_match_table = gswip_of_match, 2071cb477c30SDaniel Golle }, 2072cb477c30SDaniel Golle }; 2073cb477c30SDaniel Golle 2074cb477c30SDaniel Golle module_platform_driver(gswip_driver); 2075cb477c30SDaniel Golle 2076cb477c30SDaniel Golle MODULE_FIRMWARE("lantiq/xrx300_phy11g_a21.bin"); 2077cb477c30SDaniel Golle MODULE_FIRMWARE("lantiq/xrx300_phy22f_a21.bin"); 2078cb477c30SDaniel Golle MODULE_FIRMWARE("lantiq/xrx200_phy11g_a14.bin"); 2079cb477c30SDaniel Golle MODULE_FIRMWARE("lantiq/xrx200_phy11g_a22.bin"); 2080cb477c30SDaniel Golle MODULE_FIRMWARE("lantiq/xrx200_phy22f_a14.bin"); 2081cb477c30SDaniel Golle MODULE_FIRMWARE("lantiq/xrx200_phy22f_a22.bin"); 2082cb477c30SDaniel Golle MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>"); 2083cb477c30SDaniel Golle MODULE_DESCRIPTION("Lantiq / Intel GSWIP driver"); 2084cb477c30SDaniel Golle MODULE_LICENSE("GPL v2"); 2085