/* Set the MAC address to handle and the vlan associated in a format * understood by the hardware.
*/
mach |= vid << 16;
mach |= mac[0] << 8;
mach |= mac[1] << 0;
macl |= mac[2] << 24;
macl |= mac[3] << 16;
macl |= mac[4] << 8;
macl |= mac[5] << 0;
/* Set MAC_CPU_COPY if the CPU port is used by a multicast entry */ if (type == ENTRYTYPE_MACv4)
mc_ports = (mac[1] << 8) | mac[2]; elseif (type == ENTRYTYPE_MACv6)
mc_ports = (mac[0] << 8) | mac[1]; else
mc_ports = 0;
if (mc_ports & BIT(ocelot->num_phys_ports))
cmd |= ANA_TABLES_MACACCESS_MAC_CPU_COPY;
ocelot_mact_select(ocelot, mac, vid);
/* Issue a write command */
ocelot_write(ocelot, cmd, ANA_TABLES_MACACCESS);
err = ocelot_mact_wait_for_completion(ocelot);
return err;
}
int ocelot_mact_learn(struct ocelot *ocelot, int port, constunsignedchar mac[ETH_ALEN], unsignedint vid, enum macaccess_entry_type type)
{ int ret;
mutex_lock(&ocelot->mact_lock);
ret = __ocelot_mact_learn(ocelot, port, mac, vid, type);
mutex_unlock(&ocelot->mact_lock);
return ret;
}
EXPORT_SYMBOL(ocelot_mact_learn);
int ocelot_mact_forget(struct ocelot *ocelot, constunsignedchar mac[ETH_ALEN], unsignedint vid)
{ int err;
mutex_lock(&ocelot->mact_lock);
ocelot_mact_select(ocelot, mac, vid);
/* Issue a forget command */
ocelot_write(ocelot,
ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_FORGET),
ANA_TABLES_MACACCESS);
err = ocelot_mact_wait_for_completion(ocelot);
mutex_unlock(&ocelot->mact_lock);
return err;
}
EXPORT_SYMBOL(ocelot_mact_forget);
int ocelot_mact_lookup(struct ocelot *ocelot, int *dst_idx, constunsignedchar mac[ETH_ALEN], unsignedint vid, enum macaccess_entry_type *type)
{ int val;
mutex_lock(&ocelot->mact_lock);
ocelot_mact_select(ocelot, mac, vid);
/* Issue a read command with MACACCESS_VALID=1. */
ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID |
ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ),
ANA_TABLES_MACACCESS);
if (ocelot_mact_wait_for_completion(ocelot)) {
mutex_unlock(&ocelot->mact_lock); return -ETIMEDOUT;
}
/* Read back the entry flags */
val = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
mutex_unlock(&ocelot->mact_lock);
if (!(val & ANA_TABLES_MACACCESS_VALID)) return -ENOENT;
int ocelot_mact_learn_streamdata(struct ocelot *ocelot, int dst_idx, constunsignedchar mac[ETH_ALEN], unsignedint vid, enum macaccess_entry_type type, int sfid, int ssid)
{ int ret;
staticvoid ocelot_mact_init(struct ocelot *ocelot)
{ /* Configure the learning mode entries attributes: * - Do not copy the frame to the CPU extraction queues. * - Use the vlan and mac_cpoy for dmac lookup.
*/
ocelot_rmw(ocelot, 0,
ANA_AGENCTRL_LEARN_CPU_COPY | ANA_AGENCTRL_IGNORE_DMAC_FLAGS
| ANA_AGENCTRL_LEARN_FWD_KILL
| ANA_AGENCTRL_LEARN_IGNORE_VLAN,
ANA_AGENCTRL);
/* Clear the MAC table. We are not concurrent with anyone, so * holding &ocelot->mact_lock is pointless.
*/
ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
}
void ocelot_pll5_init(struct ocelot *ocelot)
{ /* Configure PLL5. This will need a proper CCF driver * The values are coming from the VTSS API for Ocelot
*/
regmap_write(ocelot->targets[HSIO], HSIO_PLL5G_CFG4,
HSIO_PLL5G_CFG4_IB_CTRL(0x7600) |
HSIO_PLL5G_CFG4_IB_BIAS_CTRL(0x8));
regmap_write(ocelot->targets[HSIO], HSIO_PLL5G_CFG0,
HSIO_PLL5G_CFG0_CORE_CLK_DIV(0x11) |
HSIO_PLL5G_CFG0_CPU_CLK_DIV(2) |
HSIO_PLL5G_CFG0_ENA_BIAS |
HSIO_PLL5G_CFG0_ENA_VCO_BUF |
HSIO_PLL5G_CFG0_ENA_CP1 |
HSIO_PLL5G_CFG0_SELCPI(2) |
HSIO_PLL5G_CFG0_LOOP_BW_RES(0xe) |
HSIO_PLL5G_CFG0_SELBGV820(4) |
HSIO_PLL5G_CFG0_DIV4 |
HSIO_PLL5G_CFG0_ENA_CLKTREE |
HSIO_PLL5G_CFG0_ENA_LANE);
regmap_write(ocelot->targets[HSIO], HSIO_PLL5G_CFG2,
HSIO_PLL5G_CFG2_EN_RESET_FRQ_DET |
HSIO_PLL5G_CFG2_EN_RESET_OVERRUN |
HSIO_PLL5G_CFG2_GAIN_TEST(0x8) |
HSIO_PLL5G_CFG2_ENA_AMPCTRL |
HSIO_PLL5G_CFG2_PWD_AMPCTRL_N |
HSIO_PLL5G_CFG2_AMPC_SEL(0x10));
}
EXPORT_SYMBOL(ocelot_pll5_init);
staticint ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask)
{ /* Select the VID to configure */
ocelot_write(ocelot, ANA_TABLES_VLANTIDX_V_INDEX(vid),
ANA_TABLES_VLANTIDX); /* Set the vlan port members mask and issue a write command */
ocelot_write(ocelot, ANA_TABLES_VLANACCESS_VLAN_PORT_MASK(mask) |
ANA_TABLES_VLANACCESS_CMD_WRITE,
ANA_TABLES_VLANACCESS);
staticint ocelot_port_num_untagged_vlans(struct ocelot *ocelot, int port)
{ struct ocelot_bridge_vlan *vlan; int num_untagged = 0;
list_for_each_entry(vlan, &ocelot->vlans, list) { if (!(vlan->portmask & BIT(port))) continue;
/* Ignore the VLAN added by ocelot_add_vlan_unaware_pvid(), * because this is never active in hardware at the same time as * the bridge VLANs, which only matter in VLAN-aware mode.
*/ if (vlan->vid >= OCELOT_RSV_VLAN_RANGE_START) continue;
if (vlan->untagged & BIT(port))
num_untagged++;
}
return num_untagged;
}
staticint ocelot_port_num_tagged_vlans(struct ocelot *ocelot, int port)
{ struct ocelot_bridge_vlan *vlan; int num_tagged = 0;
list_for_each_entry(vlan, &ocelot->vlans, list) { if (!(vlan->portmask & BIT(port))) continue;
if (!(vlan->untagged & BIT(port)))
num_tagged++;
}
return num_tagged;
}
/* We use native VLAN when we have to mix egress-tagged VLANs with exactly * _one_ egress-untagged VLAN (_the_ native VLAN)
*/ staticbool ocelot_port_uses_native_vlan(struct ocelot *ocelot, int port)
{ return ocelot_port_num_tagged_vlans(ocelot, port) &&
ocelot_port_num_untagged_vlans(ocelot, port) == 1;
}
/* Keep in sync REW_TAG_CFG_TAG_CFG and, if applicable, * REW_PORT_VLAN_CFG_PORT_VID, with the bridge VLAN table and VLAN awareness * state of the port.
*/ staticvoid ocelot_port_manage_port_tag(struct ocelot *ocelot, int port)
{ struct ocelot_port *ocelot_port = ocelot->ports[port]; enum ocelot_port_tag_config tag_cfg; bool uses_native_vlan = false;
if (ocelot_port->vlan_aware) {
uses_native_vlan = ocelot_port_uses_native_vlan(ocelot, port);
if (uses_native_vlan) { struct ocelot_bridge_vlan *native_vlan;
/* Not having a native VLAN is impossible, because * ocelot_port_num_untagged_vlans has returned 1. * So there is no use in checking for NULL here.
*/
native_vlan = ocelot_port_find_native_vlan(ocelot, port);
/* Standalone ports use VID 0 */ if (!bridge) return 0;
bridge_num = ocelot_bridge_num_find(ocelot, bridge); if (WARN_ON(bridge_num < 0)) return 0;
/* VLAN-unaware bridges use a reserved VID going from 4095 downwards */ return VLAN_N_VID - bridge_num - 1;
}
/** * ocelot_update_vlan_reclassify_rule() - Make switch aware only to bridge VLAN TPID * * @ocelot: Switch private data structure * @port: Index of ingress port * * IEEE 802.1Q-2018 clauses "5.5 C-VLAN component conformance" and "5.6 S-VLAN * component conformance" suggest that a C-VLAN component should only recognize * and filter on C-Tags, and an S-VLAN component should only recognize and * process based on C-Tags. * * In Linux, as per commit 1a0b20b25732 ("Merge branch 'bridge-next'"), C-VLAN * components are largely represented by a bridge with vlan_protocol 802.1Q, * and S-VLAN components by a bridge with vlan_protocol 802.1ad. * * Currently the driver only offloads vlan_protocol 802.1Q, but the hardware * design is non-conformant, because the switch assigns each frame to a VLAN * based on an entirely different question, as detailed in figure "Basic VLAN * Classification Flow" from its manual and reproduced below. * * Set TAG_TYPE, PCP, DEI, VID to port-default values in VLAN_CFG register * if VLAN_AWARE_ENA[port] and frame has outer tag then: * if VLAN_INNER_TAG_ENA[port] and frame has inner tag then: * TAG_TYPE = (Frame.InnerTPID <> 0x8100) * Set PCP, DEI, VID to values from inner VLAN header * else: * TAG_TYPE = (Frame.OuterTPID <> 0x8100) * Set PCP, DEI, VID to values from outer VLAN header * if VID == 0 then: * VID = VLAN_CFG.VLAN_VID * * Summarized, the switch will recognize both 802.1Q and 802.1ad TPIDs as VLAN * "with equal rights", and just set the TAG_TYPE bit to 0 (if 802.1Q) or to 1 * (if 802.1ad). It will classify based on whichever of the tags is "outer", no * matter what TPID that may have (or "inner", if VLAN_INNER_TAG_ENA[port]). * * In the VLAN Table, the TAG_TYPE information is not accessible - just the * classified VID is - so it is as if each VLAN Table entry is for 2 VLANs: * C-VLAN X, and S-VLAN X. * * Whereas the Linux bridge behavior is to only filter on frames with a TPID * equal to the vlan_protocol, and treat everything else as VLAN-untagged. * * Consider an ingress packet tagged with 802.1ad VID=3 and 802.1Q VID=5, * received on a bridge vlan_filtering=1 vlan_protocol=802.1Q port. This frame * should be treated as 802.1Q-untagged, and classified to the PVID of that * bridge port. Not to VID=3, and not to VID=5. * * The VCAP IS1 TCAM has everything we need to overwrite the choices made in * the basic VLAN classification pipeline: it can match on TAG_TYPE in the key, * and it can modify the classified VID in the action. Thus, for each port * under a vlan_filtering bridge, we can insert a rule in VCAP IS1 lookup 0 to * match on 802.1ad tagged frames and modify their classified VID to the 802.1Q * PVID of the port. This effectively makes it appear to the outside world as * if those packets were processed as VLAN-untagged. * * The rule needs to be updated each time the bridge PVID changes, and needs * to be deleted if the bridge PVID is deleted, or if the port becomes * VLAN-unaware.
*/ staticint ocelot_update_vlan_reclassify_rule(struct ocelot *ocelot, int port)
{ unsignedlong cookie = OCELOT_VCAP_IS1_VLAN_RECLASSIFY(ocelot, port); struct ocelot_vcap_block *block_vcap_is1 = &ocelot->block[VCAP_IS1]; struct ocelot_port *ocelot_port = ocelot->ports[port]; conststruct ocelot_bridge_vlan *pvid_vlan; struct ocelot_vcap_filter *filter; int err, val, pcp, dei; bool vid_replace_ena;
u16 vid;
filter = ocelot_vcap_block_find_filter_by_id(block_vcap_is1, cookie, false); if (!vid_replace_ena) { /* If the reclassification filter doesn't need to exist, delete * it if it was previously installed, and exit doing nothing * otherwise.
*/ if (filter) return ocelot_vcap_filter_del(ocelot, filter);
return 0;
}
/* The reclassification rule must apply. See if it already exists * or if it must be created.
*/
/* Treating as VLAN-untagged means using as classified VID equal to * the bridge PVID, and PCP/DEI set to the port default QoS values.
*/
vid = pvid_vlan->vid;
val = ocelot_read_gix(ocelot, ANA_PORT_QOS_CFG, port);
pcp = ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL_X(val);
dei = !!(val & ANA_PORT_QOS_CFG_DP_DEFAULT_VAL);
if (filter) { bool changed = false;
/* Filter exists, just update it */ if (filter->action.vid != vid) {
filter->action.vid = vid;
changed = true;
} if (filter->action.pcp != pcp) {
filter->action.pcp = pcp;
changed = true;
} if (filter->action.dei != dei) {
filter->action.dei = dei;
changed = true;
}
/* If there's no pvid, we should drop not only untagged traffic (which * happens automatically), but also 802.1p traffic which gets * classified to VLAN 0, but that is always in our RX filter, so it * would get accepted were it not for this setting. * * Also, we only support the bridge 802.1Q VLAN protocol, so * 802.1ad-tagged frames (carrying S-Tags) should be considered * 802.1Q-untagged, and also dropped.
*/ if (!pvid_vlan && ocelot_port->vlan_aware)
val = ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA |
ANA_PORT_DROP_CFG_DROP_S_TAGGED_ENA;
if (vlan) {
portmask = vlan->portmask | BIT(port);
err = ocelot_vlant_set_mask(ocelot, vid, portmask); if (err) return err;
vlan->portmask = portmask; /* Bridge VLANs can be overwritten with a different * egress-tagging setting, so make sure to override an untagged * with a tagged VID if that's going on.
*/ if (untagged)
vlan->untagged |= BIT(port); else
vlan->untagged &= ~BIT(port);
return 0;
}
vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); if (!vlan) return -ENOMEM;
int ocelot_vlan_prepare(struct ocelot *ocelot, int port, u16 vid, bool pvid, bool untagged, struct netlink_ext_ack *extack)
{ if (untagged) { /* We are adding an egress-tagged VLAN */ if (ocelot_port_uses_native_vlan(ocelot, port)) {
NL_SET_ERR_MSG_MOD(extack, "Port with egress-tagged VLANs cannot have more than one egress-untagged (native) VLAN"); return -EBUSY;
}
} else { /* We are adding an egress-tagged VLAN */ if (ocelot_port_num_untagged_vlans(ocelot, port) > 1) {
NL_SET_ERR_MSG_MOD(extack, "Port with more than one egress-untagged VLAN cannot have egress-tagged VLANs"); return -EBUSY;
}
}
if (vid > OCELOT_RSV_VLAN_RANGE_START) {
NL_SET_ERR_MSG_MOD(extack, "VLAN range 4000-4095 reserved for VLAN-unaware bridging"); return -EBUSY;
}
return 0;
}
EXPORT_SYMBOL(ocelot_vlan_prepare);
int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, bool untagged)
{ struct ocelot_port *ocelot_port = ocelot->ports[port]; int err;
/* Ignore VID 0 added to our RX filter by the 8021q module, since * that collides with OCELOT_STANDALONE_PVID and changes it from * egress-untagged to egress-tagged.
*/ if (!vid) return 0;
err = ocelot_vlan_member_add(ocelot, port, vid, untagged); if (err) return err;
/* Clear VLAN table, by default all ports are members of all VLANs */
ocelot_write(ocelot, ANA_TABLES_VLANACCESS_CMD_INIT,
ANA_TABLES_VLANACCESS);
ocelot_vlant_wait_for_completion(ocelot);
/* Configure the port VLAN memberships */ for (vid = 1; vid < VLAN_N_VID; vid++)
ocelot_vlant_set_mask(ocelot, vid, 0);
/* We need VID 0 to get traffic on standalone ports. * It is added automatically if the 8021q module is loaded, but we * can't rely on that since it might not be.
*/
ocelot_vlant_set_mask(ocelot, OCELOT_STANDALONE_PVID, all_ports);
/* Set vlan ingress filter mask to all ports but the CPU port by * default.
*/
ocelot_write(ocelot, all_ports, ANA_VLANMASK);
for (port = 0; port < ocelot->num_phys_ports; port++) {
ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port);
ocelot_write_gix(ocelot, 0, REW_TAG_CFG, port);
}
}
/* Disable priority flow control */
ocelot_fields_write(ocelot, port,
QSYS_SWITCH_PORT_MODE_TX_PFC_ENA, 0);
/* Wait at least the time it takes to receive a frame of maximum length * at the port. * Worst-case delays for 10 kilobyte jumbo frames are: * 8 ms on a 10M port * 800 μs on a 100M port * 80 μs on a 1G port * 32 μs on a 2.5G port
*/
usleep_range(8000, 10000);
/* Re-enable flow control */
ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, pause_ena);
return err;
}
int ocelot_port_configure_serdes(struct ocelot *ocelot, int port, struct device_node *portnp)
{ struct ocelot_port *ocelot_port = ocelot->ports[port]; struct device *dev = ocelot->dev; int err;
/* Ensure clock signals and speed are set on all QSGMII links */ if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_QSGMII)
ocelot_port_rmwl(ocelot_port, 0,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_RX_RST,
DEV_CLOCK_CFG);
/* Disable HDX fast control */
ocelot_port_writel(ocelot_port, DEV_PORT_MISC_HDX_FAST_DIS,
DEV_PORT_MISC);
/* SGMII only for now */
ocelot_port_writel(ocelot_port, PCS1G_MODE_CFG_SGMII_MODE_ENA,
PCS1G_MODE_CFG);
ocelot_port_writel(ocelot_port, PCS1G_SD_CFG_SD_SEL, PCS1G_SD_CFG);
err = ocelot_port_flush(ocelot, port); if (err)
dev_err(ocelot->dev, "failed to flush port %d: %d\n",
port, err);
/* Put the port in reset. */ if (interface != PHY_INTERFACE_MODE_QSGMII ||
!(quirks & OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP))
ocelot_port_rmwl(ocelot_port,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_RX_RST,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_RX_RST,
DEV_CLOCK_CFG);
}
EXPORT_SYMBOL_GPL(ocelot_phylink_mac_link_down);
void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port, struct phy_device *phydev, unsignedint link_an_mode,
phy_interface_t interface, int speed, int duplex, bool tx_pause, bool rx_pause, unsignedlong quirks)
{ struct ocelot_port *ocelot_port = ocelot->ports[port]; int mac_speed, mode = 0;
u32 mac_fc_cfg;
ocelot_port->speed = speed;
/* The MAC might be integrated in systems where the MAC speed is fixed * and it's the PCS who is performing the rate adaptation, so we have * to write "1000Mbps" into the LINK_SPEED field of DEV_CLOCK_CFG * (which is also its default value).
*/ if ((quirks & OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION) ||
speed == SPEED_1000) {
mac_speed = OCELOT_SPEED_1000;
mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
} elseif (speed == SPEED_2500) {
mac_speed = OCELOT_SPEED_2500;
mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
} elseif (speed == SPEED_100) {
mac_speed = OCELOT_SPEED_100;
} else {
mac_speed = OCELOT_SPEED_10;
}
if (duplex == DUPLEX_FULL)
mode |= DEV_MAC_MODE_CFG_FDX_ENA;
/* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and * PORT_RST bits in DEV_CLOCK_CFG.
*/
ocelot_port_writel(ocelot_port, DEV_CLOCK_CFG_LINK_SPEED(mac_speed),
DEV_CLOCK_CFG);
switch (speed) { case SPEED_10:
mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_10); break; case SPEED_100:
mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_100); break; case SPEED_1000: case SPEED_2500:
mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_1000); break; default:
dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n",
port, speed); return;
}
if (rx_pause)
mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA;
/* Flow control. Link speed is only used here to evaluate the time * specification in incoming pause frames.
*/
ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port);
ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
/* Don't attempt to send PAUSE frames on the NPI port, it's broken */ if (port != ocelot->npi)
ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA,
tx_pause);
/* Undo the effects of ocelot_phylink_mac_link_down: * enable MAC module
*/
ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
/* If the port supports cut-through forwarding, update the masks before * enabling forwarding on the port.
*/ if (ocelot->ops->cut_through_fwd) {
mutex_lock(&ocelot->fwd_domain_lock); /* Workaround for hardware bug - FP doesn't work * at all link speeds for all PHY modes. The function * below also calls ocelot->ops->cut_through_fwd(), * so we don't need to do it twice.
*/
ocelot_port_update_active_preemptible_tcs(ocelot, port);
mutex_unlock(&ocelot->fwd_domain_lock);
}
/* Core: Enable port for frame transfer */
ocelot_fields_write(ocelot, port,
QSYS_SWITCH_PORT_MODE_PORT_ENA, 1);
}
EXPORT_SYMBOL_GPL(ocelot_phylink_mac_link_up);
val = ocelot_read_rix(ocelot, QS_XTR_RD, grp); if (val == XTR_NOT_READY) { if (ifh) return -EIO;
do {
val = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
} while (val == XTR_NOT_READY);
}
switch (val) { case XTR_ABORT: return -EIO; case XTR_EOF_0: case XTR_EOF_1: case XTR_EOF_2: case XTR_EOF_3: case XTR_PRUNED:
bytes_valid = XTR_VALID_BYTES(val);
val = ocelot_read_rix(ocelot, QS_XTR_RD, grp); if (val == XTR_ESCAPE)
*rval = ocelot_read_rix(ocelot, QS_XTR_RD, grp); else
*rval = val;
return bytes_valid; case XTR_ESCAPE:
*rval = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
return 4; default:
*rval = val;
return 4;
}
}
staticint ocelot_xtr_poll_xfh(struct ocelot *ocelot, int grp, u32 *xfh)
{ int i, err = 0;
for (i = 0; i < OCELOT_TAG_LEN / 4; i++) {
err = ocelot_rx_frame_word(ocelot, grp, true, &xfh[i]); if (err != 4) return (err < 0) ? err : -EIO;
}
if (ocelot->ptp)
ocelot_ptp_rx_timestamp(ocelot, skb, timestamp);
/* Everything we see on an interface that is in the HW bridge * has already been forwarded.
*/ if (ocelot->ports[src_port]->bridge)
skb->offload_fwd_mark = 1;
void ocelot_drain_cpu_queue(struct ocelot *ocelot, int grp)
{
lockdep_assert_held(&ocelot->xtr_lock);
while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp))
ocelot_read_rix(ocelot, QS_XTR_RD, grp);
}
EXPORT_SYMBOL(ocelot_drain_cpu_queue);
int ocelot_fdb_add(struct ocelot *ocelot, int port, constunsignedchar *addr,
u16 vid, conststruct net_device *bridge)
{ if (!vid)
vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
int ocelot_fdb_del(struct ocelot *ocelot, int port, constunsignedchar *addr,
u16 vid, conststruct net_device *bridge)
{ if (!vid)
vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
/* Caller must hold &ocelot->mact_lock */ staticint ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col, struct ocelot_mact_entry *entry)
{
u32 val, dst, macl, mach; char mac[ETH_ALEN];
/* Set row and column to read from */
ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row);
ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col);
/* Issue a read command */
ocelot_write(ocelot,
ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ),
ANA_TABLES_MACACCESS);
if (ocelot_mact_wait_for_completion(ocelot)) return -ETIMEDOUT;
/* Read the entry flags */
val = ocelot_read(ocelot, ANA_TABLES_MACACCESS); if (!(val & ANA_TABLES_MACACCESS_VALID)) return -EINVAL;
/* If the entry read has another port configured as its destination, * do not report it.
*/
dst = (val & ANA_TABLES_MACACCESS_DEST_IDX_M) >> 3; if (dst != port) return -EINVAL;
/* Get the entry's MAC address and VLAN id */
macl = ocelot_read(ocelot, ANA_TABLES_MACLDATA);
mach = ocelot_read(ocelot, ANA_TABLES_MACHDATA);
int ocelot_fdb_dump(struct ocelot *ocelot, int port,
dsa_fdb_dump_cb_t *cb, void *data)
{ int err = 0; int i, j;
/* We could take the lock just around ocelot_mact_read, but doing so * thousands of times in a row seems rather pointless and inefficient.
*/
mutex_lock(&ocelot->mact_lock);
/* Loop through all the mac tables entries. */ for (i = 0; i < ocelot->num_mact_rows; i++) { for (j = 0; j < 4; j++) { struct ocelot_mact_entry entry; bool is_static;
err = ocelot_mact_read(ocelot, port, i, j, &entry); /* If the entry is invalid (wrong port, invalid...), * skip it.
*/ if (err == -EINVAL) continue; elseif (err) break;
is_static = (entry.type == ENTRYTYPE_LOCKED);
/* Hide the reserved VLANs used for * VLAN-unaware bridging.
*/ if (entry.vid > OCELOT_RSV_VLAN_RANGE_START)
entry.vid = 0;
for (port = 0; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port];
if (!ocelot_port) continue;
if (ocelot_port->bond == bond)
mask |= BIT(port);
}
return mask;
}
/* The logical port number of a LAG is equal to the lowest numbered physical * port ID present in that LAG. It may change if that port ever leaves the LAG.
*/ int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond)
{ int bond_mask = ocelot_get_bond_mask(ocelot, bond);
/* Returns the mask of user ports assigned to this DSA tag_8021q CPU port. * Note that when CPU ports are in a LAG, the user ports are assigned to the * 'primary' CPU port, the one whose physical port number gives the logical * port number of the LAG. * * We leave PGID_SRC poorly configured for the 'secondary' CPU port in the LAG * (to which no user port is assigned), but it appears that forwarding from * this secondary CPU port looks at the PGID_SRC associated with the logical * port ID that it's assigned to, which *is* configured properly.
*/ static u32 ocelot_dsa_8021q_cpu_assigned_ports(struct ocelot *ocelot, struct ocelot_port *cpu)
{
u32 mask = 0; int port;
for (port = 0; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port];
if (!ocelot_port) continue;
if (ocelot_port->dsa_8021q_cpu == cpu)
mask |= BIT(port);
}
if (cpu->bond)
mask &= ~ocelot_get_bond_mask(ocelot, cpu->bond);
return mask;
}
/* Returns the DSA tag_8021q CPU port that the given port is assigned to, * or the bit mask of CPU ports if said CPU port is in a LAG.
*/
u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port)
{ struct ocelot_port *ocelot_port = ocelot->ports[port]; struct ocelot_port *cpu_port = ocelot_port->dsa_8021q_cpu;
if (!cpu_port) return 0;
if (cpu_port->bond) return ocelot_get_bond_mask(ocelot, cpu_port->bond);
staticvoid ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot, bool joining)
{ int port;
lockdep_assert_held(&ocelot->fwd_domain_lock);
/* If cut-through forwarding is supported, update the masks before a * port joins the forwarding domain, to avoid potential underruns if it * has the highest speed from the new domain.
*/ if (joining && ocelot->ops->cut_through_fwd)
ocelot->ops->cut_through_fwd(ocelot);
/* Apply FWD mask. The loop is needed to add/remove the current port as * a source for the other ports.
*/ for (port = 0; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port]; unsignedlong mask;
if (!ocelot_port) { /* Unused ports can't send anywhere */
mask = 0;
} elseif (ocelot_port->is_dsa_8021q_cpu) { /* The DSA tag_8021q CPU ports need to be able to * forward packets to all ports assigned to them.
*/
mask = ocelot_dsa_8021q_cpu_assigned_ports(ocelot,
ocelot_port);
} elseif (ocelot_port->bridge) { struct net_device *bond = ocelot_port->bond;
if (bond)
mask &= ~ocelot_get_bond_mask(ocelot, bond);
} else { /* Standalone ports forward only to DSA tag_8021q CPU * ports (if those exist), or to the hardware CPU port * module otherwise.
*/
mask = ocelot_port_assigned_dsa_8021q_cpu_mask(ocelot,
port);
}
/* If cut-through forwarding is supported and a port is leaving, there * is a chance that cut-through was disabled on the other ports due to * the port which is leaving (it has a higher link speed). We need to * update the cut-through masks of the remaining ports no earlier than * after the port has left, to prevent underruns from happening between * the cut-through update and the forwarding domain update.
*/ if (!joining && ocelot->ops->cut_through_fwd)
ocelot->ops->cut_through_fwd(ocelot);
}
/* Update PGID_CPU which is the destination port mask used for whitelisting * unicast addresses filtered towards the host. In the normal and NPI modes, * this points to the analyzer entry for the CPU port module, while in DSA * tag_8021q mode, it is a bit mask of all active CPU ports. * PGID_SRC will take care of forwarding a packet from one user port to * no more than a single CPU port.
*/ staticvoid ocelot_update_pgid_cpu(struct ocelot *ocelot)
{ int pgid_cpu = 0; int port;
for (port = 0; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port];
if (!ocelot_port || !ocelot_port->is_dsa_8021q_cpu) continue;
pgid_cpu |= BIT(port);
}
if (!pgid_cpu)
pgid_cpu = BIT(ocelot->num_phys_ports);
/* Setting AGE_PERIOD to zero effectively disables automatic aging, * which is clearly not what our intention is. So avoid that.
*/ if (!age_period)
age_period = 1;
/* According to VSC7514 datasheet 3.9.1.5 IPv4 Multicast Entries and * 3.9.1.6 IPv6 Multicast Entries, "Instead of a lookup in the * destination mask table (PGID), the destination set is programmed as * part of the entry MAC address.", and the DEST_IDX is set to 0.
*/ if (mc->entry_type == ENTRYTYPE_MACv4 ||
mc->entry_type == ENTRYTYPE_MACv6) return ocelot_pgid_alloc(ocelot, 0, mc->ports);
list_for_each_entry(pgid, &ocelot->pgids, list) { /* When searching for a nonreserved multicast PGID, ignore the * dummy PGID of zero that we have for MACv4/MACv6 entries
*/ if (pgid->index && pgid->ports == mc->ports) {
refcount_inc(&pgid->refcount); return pgid;
}
}
/* Search for a free index in the nonreserved multicast PGID area */
for_each_nonreserved_multicast_dest_pgid(ocelot, index) { bool used = false;
list_for_each_entry(pgid, &ocelot->pgids, list) { if (pgid->index == index) {
used = true; break;
}
}
if (!used) return ocelot_pgid_alloc(ocelot, index, mc->ports);
}
int ocelot_port_mdb_add(struct ocelot *ocelot, int port, conststruct switchdev_obj_port_mdb *mdb, conststruct net_device *bridge)
{ unsignedchar addr[ETH_ALEN]; struct ocelot_multicast *mc; struct ocelot_pgid *pgid;
u16 vid = mdb->vid;
if (!vid)
vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
mc = ocelot_multicast_get(ocelot, mdb->addr, vid); if (!mc) { /* New entry */
mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL); if (!mc) return -ENOMEM;
list_add_tail(&mc->list, &ocelot->multicast);
} else { /* Existing entry. Clean up the current port mask from * hardware now, because we'll be modifying it.
*/
ocelot_pgid_free(ocelot, mc->pgid);
ocelot_encode_ports_to_mdb(addr, mc);
ocelot_mact_forget(ocelot, addr, vid);
}
mc->ports |= BIT(port);
pgid = ocelot_mdb_get_pgid(ocelot, mc); if (IS_ERR(pgid)) {
dev_err(ocelot->dev, "Cannot allocate PGID for mdb %pM vid %d\n",
mc->addr, mc->vid);
devm_kfree(ocelot->dev, mc); return PTR_ERR(pgid);
}
mc->pgid = pgid;
/* The visited ports bitmask holds the list of ports offloading any * bonding interface. Initially we mark all these ports as unvisited, * then every time we visit a port in this bitmask, we know that it is * the lowest numbered port, i.e. the one whose logical ID == physical * port ID == LAG ID. So we mark as visited all further ports in the * bitmask that are offloading the same bonding interface. This way, * we set up the aggregation PGIDs only once per bonding interface.
*/ for (port = 0; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port];
if (!ocelot_port || !ocelot_port->bond) continue;
visited &= ~BIT(port);
}
/* Now, set PGIDs for each active LAG */ for (lag = 0; lag < ocelot->num_phys_ports; lag++) { struct net_device *bond = ocelot->ports[lag]->bond; int num_active_ports = 0; unsignedlong bond_mask;
u8 aggr_idx[16];
if (ocelot_port->lag_tx_active)
aggr_idx[num_active_ports++] = port;
}
for_each_aggr_pgid(ocelot, i) {
u32 ac;
ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
ac &= ~bond_mask; /* Don't do division by zero if there was no active * port. Just make all aggregation codes zero.
*/ if (num_active_ports)
ac |= BIT(aggr_idx[i % num_active_ports]);
ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i);
}
/* Mark all ports in the same LAG as visited to avoid applying * the same config again.
*/ for (port = lag; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port];
if (!ocelot_port) continue;
if (ocelot_port->bond == bond)
visited |= BIT(port);
}
}
}
/* When offloading a bonding interface, the switch ports configured under the * same bond must have the same logical port ID, equal to the physical port ID * of the lowest numbered physical port in that bond. Otherwise, in standalone/ * bridged mode, each port has a logical port ID equal to its physical port ID.
*/ staticvoid ocelot_setup_logical_port_ids(struct ocelot *ocelot)
{ int port;
for (port = 0; port < ocelot->num_phys_ports; port++) { struct ocelot_port *ocelot_port = ocelot->ports[port]; struct net_device *bond;
if (!ocelot_port) continue;
bond = ocelot_port->bond; if (bond) { int lag = ocelot_bond_get_id(ocelot, bond);
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.