/* 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;
/* Clear the MAC table. We are not concurrent with anyone, so *holding&ocelot->mact_lockispointless.
*/
ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
}
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(), *becausethisisneveractiveinhardwareatthesametimeas *thebridgeVLANs,whichonlymatterinVLAN-awaremode.
*/ 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-untaggedVLAN(_the_nativeVLAN)
*/ 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;
}
if (uses_native_vlan) { struct ocelot_bridge_vlan *native_vlan;
/* Not having a native VLAN is impossible, because *ocelot_port_num_untagged_vlanshasreturned1. *SothereisnouseincheckingforNULLhere.
*/
native_vlan = ocelot_port_find_native_vlan(ocelot, port);
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 *itifitwaspreviouslyinstalled,andexitdoingnothing *otherwise.
*/ if (filter) return ocelot_vcap_filter_del(ocelot, filter);
return0;
}
/* The reclassification rule must apply. See if it already exists *orifitmustbecreated.
*/
/* Treating as VLAN-untagged means using as classified VID equal to *thebridgePVID,andPCP/DEIsettotheportdefaultQoSvalues.
*/
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 *happensautomatically),butalso802.1ptrafficwhichgets *classifiedtoVLAN0,butthatisalwaysinourRXfilter,soit *wouldgetacceptedwereitnotforthissetting. * *Also,weonlysupportthebridge802.1QVLANprotocol,so *802.1ad-taggedframes(carryingS-Tags)shouldbeconsidered *802.1Q-untagged,andalsodropped.
*/ 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-taggingsetting,somakesuretooverrideanuntagged *withataggedVIDifthat'sgoingon.
*/ if (untagged)
vlan->untagged |= BIT(port); else
vlan->untagged &= ~BIT(port);
return0;
}
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;
}
return0;
}
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 *thatcollideswithOCELOT_STANDALONE_PVIDandchangesitfrom *egress-untaggedtoegress-tagged.
*/ if (!vid) return0;
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. *Itisaddedautomaticallyifthe8021qmoduleisloaded,butwe *can'trelyonthatsinceitmightnotbe.
*/
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 *attheport. *Worst-casedelaysfor10kilobytejumboframesare: *8msona10Mport *800μsona100Mport *80μsona1Gport *32μsona2.5Gport
*/
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 *andit'sthePCSwhoisperformingtherateadaptation,sowehave *towrite"1000Mbps"intotheLINK_SPEEDfieldofDEV_CLOCK_CFG *(whichisalsoitsdefaultvalue).
*/ 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_RSTbitsinDEV_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 *specificationinincomingpauseframes.
*/
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: *enableMACmodule
*/
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 *enablingforwardingontheport.
*/ if (ocelot->ops->cut_through_fwd) {
mutex_lock(&ocelot->fwd_domain_lock); /* Workaround for hardware bug - FP doesn't work *atalllinkspeedsforallPHYmodes.Thefunction *belowalsocallsocelot->ops->cut_through_fwd(), *sowedon'tneedtodoittwice.
*/
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);
return4; default:
*rval = val;
return4;
}
}
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 *hasalreadybeenforwarded.
*/ 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, *donotreportit.
*/
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 *thousandsoftimesinarowseemsratherpointlessandinefficient.
*/
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...), *skipit.
*/ if (err == -EINVAL) continue; elseif (err) break;
is_static = (entry.type == ENTRYTYPE_LOCKED);
/* Hide the reserved VLANs used for *VLAN-unawarebridging.
*/ 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 *portIDpresentinthatLAG.ItmaychangeifthatporteverleavestheLAG.
*/ 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. *NotethatwhenCPUportsareinaLAG,theuserportsareassignedtothe *'primary'CPUport,theonewhosephysicalportnumbergivesthelogical *portnumberoftheLAG. * *WeleavePGID_SRCpoorlyconfiguredforthe'secondary'CPUportintheLAG *(towhichnouserportisassigned),butitappearsthatforwardingfrom *thissecondaryCPUportlooksatthePGID_SRCassociatedwiththelogical *portIDthatit'sassignedto,which*is*configuredproperly.
*/ 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, *orthebitmaskofCPUportsifsaidCPUportisinaLAG.
*/
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) return0;
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 *portjoinstheforwardingdomain,toavoidpotentialunderrunsifit *hasthehighestspeedfromthenewdomain.
*/ 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 *asourcefortheotherports.
*/ 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 *forwardpacketstoallportsassignedtothem.
*/
mask = ocelot_dsa_8021q_cpu_assigned_ports(ocelot,
ocelot_port);
} elseif (ocelot_port->bridge) { struct net_device *bond = ocelot_port->bond;
/* If cut-through forwarding is supported and a port is leaving, there *isachancethatcut-throughwasdisabledontheotherportsdueto *theportwhichisleaving(ithasahigherlinkspeed).Weneedto *updatethecut-throughmasksoftheremainingportsnoearlierthan *aftertheporthasleft,topreventunderrunsfromhappeningbetween *thecut-throughupdateandtheforwardingdomainupdate.
*/ 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 *unicastaddressesfilteredtowardsthehost.InthenormalandNPImodes, *thispointstotheanalyzerentryfortheCPUportmodule,whileinDSA *tag_8021qmode,itisabitmaskofallactiveCPUports. *PGID_SRCwilltakecareofforwardingapacketfromoneuserportto *nomorethanasingleCPUport.
*/ 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);
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 *hardwarenow,becausewe'llbemodifyingit.
*/
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 *bondinginterface.Initiallywemarkalltheseportsasunvisited, *theneverytimewevisitaportinthisbitmask,weknowthatitis *thelowestnumberedport,i.e.theonewhoselogicalID==physical *portID==LAGID.Sowemarkasvisitedallfurtherportsinthe *bitmaskthatareoffloadingthesamebondinginterface.Thisway, *wesetuptheaggregationPGIDsonlyonceperbondinginterface.
*/ 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.Justmakeallaggregationcodeszero.
*/ 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 *thesameconfigagain.
*/ 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 *samebondmusthavethesamelogicalportID,equaltothephysicalportID *ofthelowestnumberedphysicalportinthatbond.Otherwise,instandalone/ *bridgedmode,eachporthasalogicalportIDequaltoitsphysicalportID.
*/ 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);
dev_dbg(ocelot->dev, "Migrating multicast %pM vid %d from port mask 0x%lx to 0x%lx\n",
mc->addr, mc->vid, from_mask, to_mask);
/* First clean up the current port mask from hardware, because *we'llbemodifyingit.
*/
ocelot_pgid_free(ocelot, mc->pgid);
ocelot_encode_ports_to_mdb(addr, mc);
ocelot_mact_forget(ocelot, addr, vid);
mc->ports &= ~from_mask;
mc->ports |= to_mask;
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;
/* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu. *ThelengthofVLANtagsisaccountedforautomaticallyviaDEV_MAC_TAGS_CFG. *Inthespecialcasethatit'stheNPIportthatwe'reconfiguring,the *lengthofthetagandoptionalprefixneedstobeaccountedforprivately, *inordertobeabletosustaincommunicationattherequested@sdu.
*/ void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu)
{ struct ocelot_port *ocelot_port = ocelot->ports[port]; int maxlen = sdu + ETH_HLEN + ETH_FCS_LEN; int pause_start, pause_stop; int atop, atop_tot;
if (port == ocelot->npi) {
maxlen += OCELOT_TAG_LEN;
int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp)
{ int qos_cfg = ocelot_read_gix(ocelot, ANA_PORT_QOS_CFG, port); int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp);
/* Return error if DSCP prioritization isn't enabled */ if (!(qos_cfg & ANA_PORT_QOS_CFG_QOS_DSCP_ENA)) return -EOPNOTSUPP;
if (qos_cfg & ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA) {
dscp = ANA_DSCP_CFG_DSCP_TRANSLATE_VAL_X(dscp_cfg); /* Re-read ANA_DSCP_CFG for the translated DSCP */
dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp);
}
/* If the DSCP value is not trusted, the QoS classification falls back *toVLANPCPorport-baseddefault.
*/ if (!(dscp_cfg & ANA_DSCP_CFG_DSCP_TRUST_ENA)) return -EOPNOTSUPP;
int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio)
{ int mask, val;
if (prio >= OCELOT_NUM_TC) return -ERANGE;
/* There is at least one app table priority (this one), so we need to *makesureDSCPprioritizationisenabledontheport. *AlsomakesureDSCPtranslationisdisabled *(dcbnldoesn'tsupportit).
*/
mask = ANA_PORT_QOS_CFG_QOS_DSCP_ENA |
ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA;
int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio)
{ int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp); int mask, i;
/* During a "dcb app replace" command, the new app table entry will be *addedfirst,thentheoldonewillbedeleted.Butthehardwareonly *supportsoneQoSclassperDSCPvalue(duh),soifweblindlydelete *theapptableentryforthisDSCPvalue,weendupdeletingthe *entrywiththenewpriority.Avoidthatbycheckingwhetheruser *spacewantstodeletetheprioritywhichiscurrentlyconfigured,or *somethingelsewhichisnolongercurrent.
*/ if (ANA_DSCP_CFG_QOS_DSCP_VAL_X(dscp_cfg) != prio) return0;
/* Untrust this DSCP value */
ocelot_write_rix(ocelot, 0, ANA_DSCP_CFG, dscp);
for (i = 0; i < 64; i++) { int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, i);
/* There are still app table entries on the port, so we need to *keepDSCPenabled,nothingtodo.
*/ if (dscp_cfg & ANA_DSCP_CFG_DSCP_TRUST_ENA) return0;
}
/* Disable DSCP QoS classification if there isn't any trusted *DSCPvalueleft.
*/
mask = ANA_PORT_QOS_CFG_QOS_DSCP_ENA |
ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA;
int ocelot_port_mirror_add(struct ocelot *ocelot, int from, int to, bool ingress, struct netlink_ext_ack *extack)
{ struct ocelot_mirror *m = ocelot_mirror_get(ocelot, to, extack);
/* Set MAC IFG Gaps *FDX:TX_IFG=5,RX_IFG1=RX_IFG2=0 *!FDX:TX_IFG=5,RX_IFG1=RX_IFG2=5
*/
ocelot_port_writel(ocelot_port, DEV_MAC_IFG_CFG_TX_IFG(5),
DEV_MAC_IFG_CFG);
/* Load seed (0) and set MAC HDX late collision */
ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
DEV_MAC_HDX_CFG_SEED_LOAD,
DEV_MAC_HDX_CFG);
mdelay(1);
ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
DEV_MAC_HDX_CFG);
/* Set Max Length and maximum tags allowed */
ocelot_port_set_maxlen(ocelot, port, ETH_DATA_LEN);
ocelot_port_writel(ocelot_port, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD) |
DEV_MAC_TAGS_CFG_VLAN_AWR_ENA |
DEV_MAC_TAGS_CFG_VLAN_DBL_AWR_ENA |
DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA,
DEV_MAC_TAGS_CFG);
/* Set SMAC of Pause frame (00:00:00:00:00:00) */
ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_HIGH_CFG);
ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_LOW_CFG);
/* Drop frames with multicast source address */
ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
ANA_PORT_DROP_CFG, port);
/* Set default VLAN and tag type to 8021Q. */
ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q),
REW_PORT_VLAN_CFG_PORT_TPID_M,
REW_PORT_VLAN_CFG, port);
/* Configure and enable the CPU port module, which is a set of queues *accessiblethroughregisterMMIO,frameDMAorEthernet(incase *NPImodeisused).
*/ staticvoid ocelot_cpu_port_init(struct ocelot *ocelot)
{ int cpu = ocelot->num_phys_ports;
/* The unicast destination PGID for the CPU port module is unused */
ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu); /* Instead set up a multicast destination PGID for traffic copied to *theCPU.WhitelistedMACaddressesliketheportnetdeviceMAC *addresseswillbecopiedtotheCPUviathisPGID.
*/
ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU);
ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA |
ANA_PORT_PORT_CFG_PORTID_VAL(cpu),
ANA_PORT_PORT_CFG, cpu);
/* Enable CPU port module */
ocelot_fields_write(ocelot, cpu, QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); /* CPU port Injection/Extraction configuration */
ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_XTR_HDR,
OCELOT_TAG_PREFIX_NONE);
ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_INJ_HDR,
OCELOT_TAG_PREFIX_NONE);
/* Configure the CPU port to be VLAN aware */
ocelot_write_gix(ocelot,
ANA_PORT_VLAN_CFG_VLAN_VID(OCELOT_STANDALONE_PVID) |
ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1),
ANA_PORT_VLAN_CFG, cpu);
}
staticvoid ocelot_detect_features(struct ocelot *ocelot)
{ int mmgt, eq_ctrl;
int ocelot_reset(struct ocelot *ocelot)
{ int err;
u32 val;
err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_INIT], 1); if (err) return err;
err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1); if (err) return err;
/* MEM_INIT is a self-clearing bit. Wait for it to be cleared (should be *100us)beforeenablingtheswitchcore.
*/
err = readx_poll_timeout(ocelot_mem_init_status, ocelot, val, !val,
MEM_INIT_SLEEP_US, MEM_INIT_TIMEOUT_US); if (err) return err;
err = regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1); if (err) return err;
/* Set MAC age time to default value. The entry is aged after *2*AGE_PERIOD
*/
ocelot_write(ocelot,
ANA_AUTOAGE_AGE_PERIOD(BR_DEFAULT_AGEING_TIME / 2 / HZ),
ANA_AUTOAGE);
/* Disable learning for frames discarded by VLAN ingress filtering */
regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1);
/* Setup frame ageing - fixed value "2 sec" - in 6.5 us units */
ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA |
SYS_FRM_AGING_MAX_AGE(307692), SYS_FRM_AGING);
/* Setup flooding PGIDs */ for (i = 0; i < ocelot->num_flooding_pgids; i++)
ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) |
ANA_FLOODING_FLD_BROADCAST(PGID_BC) |
ANA_FLOODING_FLD_UNICAST(PGID_UC),
ANA_FLOODING, i);
ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) |
ANA_FLOODING_IPMC_FLD_MC6_CTRL(PGID_MC) |
ANA_FLOODING_IPMC_FLD_MC4_DATA(PGID_MCIPV4) |
ANA_FLOODING_IPMC_FLD_MC4_CTRL(PGID_MC),
ANA_FLOODING_IPMC);
for (port = 0; port < ocelot->num_phys_ports; port++) { /* Transmit the frame to the local port. */
ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); /* Do not forward BPDU frames to the front ports. */
ocelot_write_gix(ocelot,
ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
ANA_PORT_CPU_FWD_BPDU_CFG,
port); /* Ensure bridging is disabled */
ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port);
}
for_each_nonreserved_multicast_dest_pgid(ocelot, i) {
u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0));
MODULE_DESCRIPTION("Microsemi Ocelot switch family library");
MODULE_LICENSE("Dual MIT/GPL");
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.92Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-01)
¤
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.