// SPDX-License-Identifier: GPL-2.0-only // Copyright (c) 2019 Pengutronix, Oleksij Rempel <kernel@pengutronix.de> /* * +----------------------+ * GMAC1----RGMII----|--MAC0 | * \---MDIO1----|--REGs |----MDIO3----\ * | | | +------+ * | | +--| | * | MAC1-|----RMII--M-----| PHY0 |-o P0 * | | | | +------+ * | | | +--| | * | MAC2-|----RMII--------| PHY1 |-o P1 * | | | | +------+ * | | | +--| | * | MAC3-|----RMII--------| PHY2 |-o P2 * | | | | +------+ * | | | +--| | * | MAC4-|----RMII--------| PHY3 |-o P3 * | | | | +------+ * | | | +--| | * | MAC5-|--+-RMII--M-----|-PHY4-|-o P4 * | | | | +------+ * +----------------------+ | \--CFG_SW_PHY_SWAP * GMAC0---------------RMII--------------------/ \-CFG_SW_PHY_ADDR_SWAP * \---MDIO0--NC * * GMAC0 and MAC5 are connected together and use same PHY. Depending on * configuration it can be PHY4 (default) or PHY0. Only GMAC0 or MAC5 can be * used at same time. If GMAC0 is used (default) then MAC5 should be disabled. * * CFG_SW_PHY_SWAP - swap connections of PHY0 and PHY4. If this bit is not set * PHY4 is connected to GMAC0/MAC5 bundle and PHY0 is connected to MAC1. If this * bit is set, PHY4 is connected to MAC1 and PHY0 is connected to GMAC0/MAC5 * bundle. * * CFG_SW_PHY_ADDR_SWAP - swap addresses of PHY0 and PHY4 * * CFG_SW_PHY_SWAP and CFG_SW_PHY_ADDR_SWAP are part of SoC specific register * set and not related to switch internal registers.
*/
/* FLOW_LINK_EN - enable mac flow control config auto-neg with phy. * If not set, mac can be config by software.
*/ #define AR9331_SW_PORT_STATUS_FLOW_LINK_EN BIT(12)
/* LINK_EN - If set, MAC is configured from PHY link status. * If not set, MAC should be configured by software.
*/ #define AR9331_SW_PORT_STATUS_LINK_EN BIT(9) #define AR9331_SW_PORT_STATUS_DUPLEX_MODE BIT(6) #define AR9331_SW_PORT_STATUS_RX_FLOW_EN BIT(5) #define AR9331_SW_PORT_STATUS_TX_FLOW_EN BIT(4) #define AR9331_SW_PORT_STATUS_RXMAC BIT(3) #define AR9331_SW_PORT_STATUS_TXMAC BIT(2) #define AR9331_SW_PORT_STATUS_SPEED_M GENMASK(1, 0) #define AR9331_SW_PORT_STATUS_SPEED_1000 2 #define AR9331_SW_PORT_STATUS_SPEED_100 1 #define AR9331_SW_PORT_STATUS_SPEED_10 0
/* The interval should be small enough to avoid overflow of 32bit MIBs */ /* * FIXME: until we can read MIBs from stats64 call directly (i.e. sleep * there), we have to poll stats more frequently then it is actually needed. * For overflow protection, normally, 100 sec interval should have been OK.
*/ #define STATS_INTERVAL_JIFFIES (3 * HZ)
/* Warning: switch reset will reset last AR9331_SW_MDIO_PHY_MODE_PAGE request * If some kind of optimization is used, the request should be repeated.
*/ staticint ar9331_sw_reset(struct ar9331_sw_priv *priv)
{ int ret;
ret = reset_control_assert(priv->sw_reset); if (ret) goto error;
/* AR9331 doc do not provide any information about proper reset * sequence. The AR8136 (the closes switch to the AR9331) doc says: * reset duration should be greater than 10ms. So, let's use this value * for now.
*/
usleep_range(10000, 15000);
ret = reset_control_deassert(priv->sw_reset); if (ret) goto error; /* There is no information on how long should we wait after reset. * AR8136 has an EEPROM and there is an Interrupt for EEPROM load * status. AR9331 has no EEPROM support. * For now, do not wait. In case AR8136 will be needed, the after * reset delay can be added as well.
*/
/* Generate default port settings */
port_ctrl = FIELD_PREP(AR9331_SW_PORT_CTRL_PORT_STATE,
AR9331_SW_PORT_CTRL_PORT_STATE_FORWARD);
if (dsa_is_cpu_port(ds, port)) { /* CPU port should be allowed to communicate with all user * ports.
*/
port_mask = dsa_user_ports(ds); /* Enable Atheros header on CPU port. This will allow us * communicate with each port separately
*/
port_ctrl |= AR9331_SW_PORT_CTRL_HEAD_EN;
} elseif (dsa_is_user_port(ds, port)) { /* User ports should communicate only with the CPU port.
*/
port_mask = BIT(dsa_upstream_port(ds, port));
} else { /* Other ports do not need to communicate at all */
port_mask = 0;
}
val = FIELD_PREP(AR9331_SW_PORT_VLAN_8021Q_MODE,
AR9331_SW_8021Q_MODE_NONE) |
FIELD_PREP(AR9331_SW_PORT_VLAN_PORT_VID_MEMBER, port_mask);
ret = regmap_write(regmap, AR9331_SW_REG_PORT_VLAN(port), val); if (ret) goto error;
ret = regmap_write(regmap, AR9331_SW_REG_PORT_CTRL(port), port_ctrl); if (ret) goto error;
/* Reset will set proper defaults. CPU - Port0 will be enabled and * configured. All other ports (ports 1 - 5) are disabled
*/
ret = ar9331_sw_mbus_init(priv); if (ret) return ret;
/* Do not drop broadcast frames */
ret = regmap_write_bits(regmap, AR9331_SW_REG_FLOOD_MASK,
AR9331_SW_FLOOD_MASK_BROAD_TO_CPU,
AR9331_SW_FLOOD_MASK_BROAD_TO_CPU); if (ret) goto error;
/* Set max frame size to the maximum supported value */
ret = regmap_write_bits(regmap, AR9331_SW_REG_GLOBAL_CTRL,
AR9331_SW_GLOBAL_CTRL_MFS_M,
AR9331_SW_GLOBAL_CTRL_MFS_M); if (ret) goto error;
for (i = 0; i < ds->num_ports; i++) {
ret = ar9331_sw_setup_port(ds, i); if (ret) goto error;
}
switch (port) { case 0:
__set_bit(PHY_INTERFACE_MODE_GMII,
config->supported_interfaces);
config->mac_capabilities |= MAC_1000; break; case 1: case 2: case 3: case 4: case 5:
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
config->supported_interfaces); break;
}
}
val = AR9331_SW_PORT_STATUS_MAC_MASK; switch (speed) { case SPEED_1000:
val |= AR9331_SW_PORT_STATUS_SPEED_1000; break; case SPEED_100:
val |= AR9331_SW_PORT_STATUS_SPEED_100; break; case SPEED_10:
val |= AR9331_SW_PORT_STATUS_SPEED_10; break; default: return;
}
if (duplex)
val |= AR9331_SW_PORT_STATUS_DUPLEX_MODE;
if (tx_pause)
val |= AR9331_SW_PORT_STATUS_TX_FLOW_EN;
if (rx_pause)
val |= AR9331_SW_PORT_STATUS_RX_FLOW_EN;
ret = regmap_update_bits(regmap, AR9331_SW_REG_PORT_STATUS(port),
AR9331_SW_PORT_STATUS_MAC_MASK |
AR9331_SW_PORT_STATUS_LINK_MASK,
val); if (ret)
dev_err_ratelimited(priv->dev, "%s: %i\n", __func__, ret);
}
/* Do the slowest part first, to avoid needless locking for long time */
ret = regmap_bulk_read(priv->regmap, AR9331_MIB_COUNTER(port->idx),
&raw, sizeof(raw) / sizeof(u32)); if (ret) {
dev_err_ratelimited(priv->dev, "%s: %i\n", __func__, ret); return;
} /* All MIB counters are cleared automatically on read */
ret = regmap_update_bits(regmap, AR9331_SW_REG_GINT_MASK,
AR9331_SW_GINT_PHY_INT, priv->irq_mask); if (ret)
dev_err(priv->dev, "failed to change IRQ mask\n");
if (reg == AR9331_SW_REG_PAGE) { /* We cannot read the page selector register from hardware and * we cache its value in regmap. Return all bits set here, * that regmap will always write the page on first use.
*/
*(u32 *)val_buf = GENMASK(9, 0); return 0;
}
mutex_lock_nested(&sbus->mdio_lock, MDIO_MUTEX_NESTED); if (reg == AR9331_SW_REG_PAGE) {
ret = __ar9331_mdio_write(sbus, AR9331_SW_MDIO_PHY_MODE_PAGE,
0, val); if (ret < 0) goto error;
mutex_unlock(&sbus->mdio_lock);
return 0;
}
/* In case of this switch we work with 32bit registers on top of 16bit * bus. Some registers (for example access to forwarding database) have * trigger bit on the first 16bit half of request, the result and * configuration of request in the second half. * To make it work properly, we should do the second part of transfer * before the first one is done.
*/
ret = __ar9331_mdio_write(sbus, AR9331_SW_MDIO_PHY_MODE_REG, reg + 2,
val >> 16); if (ret < 0) goto error;
ret = __ar9331_mdio_write(sbus, AR9331_SW_MDIO_PHY_MODE_REG, reg, val); if (ret < 0) goto error;
mutex_unlock(&sbus->mdio_lock);
return 0;
error:
mutex_unlock(&sbus->mdio_lock);
dev_err_ratelimited(&sbus->dev, "Bus error. Failed to write register.\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.