|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Texas Instruments 3-Port Ethernet Switch Address Lookup Engine
|
|
|
+ * Texas Instruments N-Port Ethernet Switch Address Lookup Engine
|
|
|
*
|
|
|
* Copyright (C) 2012 Texas Instruments
|
|
|
*
|
|
@@ -27,11 +27,14 @@
|
|
|
|
|
|
#define BITMASK(bits) (BIT(bits) - 1)
|
|
|
|
|
|
-#define ALE_VERSION_MAJOR(rev) ((rev >> 8) & 0xff)
|
|
|
+#define ALE_VERSION_MAJOR(rev, mask) (((rev) >> 8) & (mask))
|
|
|
#define ALE_VERSION_MINOR(rev) (rev & 0xff)
|
|
|
+#define ALE_VERSION_1R3 0x0103
|
|
|
+#define ALE_VERSION_1R4 0x0104
|
|
|
|
|
|
/* ALE Registers */
|
|
|
#define ALE_IDVER 0x00
|
|
|
+#define ALE_STATUS 0x04
|
|
|
#define ALE_CONTROL 0x08
|
|
|
#define ALE_PRESCALE 0x10
|
|
|
#define ALE_UNKNOWNVLAN 0x18
|
|
@@ -39,6 +42,13 @@
|
|
|
#define ALE_TABLE 0x34
|
|
|
#define ALE_PORTCTL 0x40
|
|
|
|
|
|
+/* ALE NetCP NU switch specific Registers */
|
|
|
+#define ALE_UNKNOWNVLAN_MEMBER 0x90
|
|
|
+#define ALE_UNKNOWNVLAN_UNREG_MCAST_FLOOD 0x94
|
|
|
+#define ALE_UNKNOWNVLAN_REG_MCAST_FLOOD 0x98
|
|
|
+#define ALE_UNKNOWNVLAN_FORCE_UNTAG_EGRESS 0x9C
|
|
|
+#define ALE_VLAN_MASK_MUX(reg) (0xc0 + (0x4 * (reg)))
|
|
|
+
|
|
|
#define ALE_TABLE_WRITE BIT(31)
|
|
|
|
|
|
#define ALE_TYPE_FREE 0
|
|
@@ -51,6 +61,10 @@
|
|
|
#define ALE_UCAST_OUI 2
|
|
|
#define ALE_UCAST_TOUCHED 3
|
|
|
|
|
|
+#define ALE_TABLE_SIZE_MULTIPLIER 1024
|
|
|
+#define ALE_STATUS_SIZE_MASK 0x1f
|
|
|
+#define ALE_TABLE_SIZE_DEFAULT 64
|
|
|
+
|
|
|
static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits)
|
|
|
{
|
|
|
int idx;
|
|
@@ -84,20 +98,34 @@ static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value) \
|
|
|
cpsw_ale_set_field(ale_entry, start, bits, value); \
|
|
|
}
|
|
|
|
|
|
+#define DEFINE_ALE_FIELD1(name, start) \
|
|
|
+static inline int cpsw_ale_get_##name(u32 *ale_entry, u32 bits) \
|
|
|
+{ \
|
|
|
+ return cpsw_ale_get_field(ale_entry, start, bits); \
|
|
|
+} \
|
|
|
+static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value, \
|
|
|
+ u32 bits) \
|
|
|
+{ \
|
|
|
+ cpsw_ale_set_field(ale_entry, start, bits, value); \
|
|
|
+}
|
|
|
+
|
|
|
DEFINE_ALE_FIELD(entry_type, 60, 2)
|
|
|
DEFINE_ALE_FIELD(vlan_id, 48, 12)
|
|
|
DEFINE_ALE_FIELD(mcast_state, 62, 2)
|
|
|
-DEFINE_ALE_FIELD(port_mask, 66, 3)
|
|
|
+DEFINE_ALE_FIELD1(port_mask, 66)
|
|
|
DEFINE_ALE_FIELD(super, 65, 1)
|
|
|
DEFINE_ALE_FIELD(ucast_type, 62, 2)
|
|
|
-DEFINE_ALE_FIELD(port_num, 66, 2)
|
|
|
+DEFINE_ALE_FIELD1(port_num, 66)
|
|
|
DEFINE_ALE_FIELD(blocked, 65, 1)
|
|
|
DEFINE_ALE_FIELD(secure, 64, 1)
|
|
|
-DEFINE_ALE_FIELD(vlan_untag_force, 24, 3)
|
|
|
-DEFINE_ALE_FIELD(vlan_reg_mcast, 16, 3)
|
|
|
-DEFINE_ALE_FIELD(vlan_unreg_mcast, 8, 3)
|
|
|
-DEFINE_ALE_FIELD(vlan_member_list, 0, 3)
|
|
|
+DEFINE_ALE_FIELD1(vlan_untag_force, 24)
|
|
|
+DEFINE_ALE_FIELD1(vlan_reg_mcast, 16)
|
|
|
+DEFINE_ALE_FIELD1(vlan_unreg_mcast, 8)
|
|
|
+DEFINE_ALE_FIELD1(vlan_member_list, 0)
|
|
|
DEFINE_ALE_FIELD(mcast, 40, 1)
|
|
|
+/* ALE NetCP nu switch specific */
|
|
|
+DEFINE_ALE_FIELD(vlan_unreg_mcast_idx, 20, 3)
|
|
|
+DEFINE_ALE_FIELD(vlan_reg_mcast_idx, 44, 3)
|
|
|
|
|
|
/* The MAC address field in the ALE entry cannot be macroized as above */
|
|
|
static inline void cpsw_ale_get_addr(u32 *ale_entry, u8 *addr)
|
|
@@ -223,14 +251,16 @@ static void cpsw_ale_flush_mcast(struct cpsw_ale *ale, u32 *ale_entry,
|
|
|
{
|
|
|
int mask;
|
|
|
|
|
|
- mask = cpsw_ale_get_port_mask(ale_entry);
|
|
|
+ mask = cpsw_ale_get_port_mask(ale_entry,
|
|
|
+ ale->port_mask_bits);
|
|
|
if ((mask & port_mask) == 0)
|
|
|
return; /* ports dont intersect, not interested */
|
|
|
mask &= ~port_mask;
|
|
|
|
|
|
/* free if only remaining port is host port */
|
|
|
if (mask)
|
|
|
- cpsw_ale_set_port_mask(ale_entry, mask);
|
|
|
+ cpsw_ale_set_port_mask(ale_entry, mask,
|
|
|
+ ale->port_mask_bits);
|
|
|
else
|
|
|
cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
|
|
|
}
|
|
@@ -291,7 +321,7 @@ int cpsw_ale_add_ucast(struct cpsw_ale *ale, u8 *addr, int port,
|
|
|
cpsw_ale_set_ucast_type(ale_entry, ALE_UCAST_PERSISTANT);
|
|
|
cpsw_ale_set_secure(ale_entry, (flags & ALE_SECURE) ? 1 : 0);
|
|
|
cpsw_ale_set_blocked(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0);
|
|
|
- cpsw_ale_set_port_num(ale_entry, port);
|
|
|
+ cpsw_ale_set_port_num(ale_entry, port, ale->port_num_bits);
|
|
|
|
|
|
idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
|
|
|
if (idx < 0)
|
|
@@ -338,9 +368,11 @@ int cpsw_ale_add_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask,
|
|
|
cpsw_ale_set_super(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0);
|
|
|
cpsw_ale_set_mcast_state(ale_entry, mcast_state);
|
|
|
|
|
|
- mask = cpsw_ale_get_port_mask(ale_entry);
|
|
|
+ mask = cpsw_ale_get_port_mask(ale_entry,
|
|
|
+ ale->port_mask_bits);
|
|
|
port_mask |= mask;
|
|
|
- cpsw_ale_set_port_mask(ale_entry, port_mask);
|
|
|
+ cpsw_ale_set_port_mask(ale_entry, port_mask,
|
|
|
+ ale->port_mask_bits);
|
|
|
|
|
|
if (idx < 0)
|
|
|
idx = cpsw_ale_match_free(ale);
|
|
@@ -367,7 +399,8 @@ int cpsw_ale_del_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask,
|
|
|
cpsw_ale_read(ale, idx, ale_entry);
|
|
|
|
|
|
if (port_mask)
|
|
|
- cpsw_ale_set_port_mask(ale_entry, port_mask);
|
|
|
+ cpsw_ale_set_port_mask(ale_entry, port_mask,
|
|
|
+ ale->port_mask_bits);
|
|
|
else
|
|
|
cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
|
|
|
|
|
@@ -376,6 +409,21 @@ int cpsw_ale_del_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask,
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(cpsw_ale_del_mcast);
|
|
|
|
|
|
+/* ALE NetCP NU switch specific vlan functions */
|
|
|
+static void cpsw_ale_set_vlan_mcast(struct cpsw_ale *ale, u32 *ale_entry,
|
|
|
+ int reg_mcast, int unreg_mcast)
|
|
|
+{
|
|
|
+ int idx;
|
|
|
+
|
|
|
+ /* Set VLAN registered multicast flood mask */
|
|
|
+ idx = cpsw_ale_get_vlan_reg_mcast_idx(ale_entry);
|
|
|
+ writel(reg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx));
|
|
|
+
|
|
|
+ /* Set VLAN unregistered multicast flood mask */
|
|
|
+ idx = cpsw_ale_get_vlan_unreg_mcast_idx(ale_entry);
|
|
|
+ writel(unreg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx));
|
|
|
+}
|
|
|
+
|
|
|
int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag,
|
|
|
int reg_mcast, int unreg_mcast)
|
|
|
{
|
|
@@ -389,10 +437,16 @@ int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag,
|
|
|
cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_VLAN);
|
|
|
cpsw_ale_set_vlan_id(ale_entry, vid);
|
|
|
|
|
|
- cpsw_ale_set_vlan_untag_force(ale_entry, untag);
|
|
|
- cpsw_ale_set_vlan_reg_mcast(ale_entry, reg_mcast);
|
|
|
- cpsw_ale_set_vlan_unreg_mcast(ale_entry, unreg_mcast);
|
|
|
- cpsw_ale_set_vlan_member_list(ale_entry, port);
|
|
|
+ cpsw_ale_set_vlan_untag_force(ale_entry, untag, ale->vlan_field_bits);
|
|
|
+ if (!ale->params.nu_switch_ale) {
|
|
|
+ cpsw_ale_set_vlan_reg_mcast(ale_entry, reg_mcast,
|
|
|
+ ale->vlan_field_bits);
|
|
|
+ cpsw_ale_set_vlan_unreg_mcast(ale_entry, unreg_mcast,
|
|
|
+ ale->vlan_field_bits);
|
|
|
+ } else {
|
|
|
+ cpsw_ale_set_vlan_mcast(ale, ale_entry, reg_mcast, unreg_mcast);
|
|
|
+ }
|
|
|
+ cpsw_ale_set_vlan_member_list(ale_entry, port, ale->vlan_field_bits);
|
|
|
|
|
|
if (idx < 0)
|
|
|
idx = cpsw_ale_match_free(ale);
|
|
@@ -418,7 +472,8 @@ int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask)
|
|
|
cpsw_ale_read(ale, idx, ale_entry);
|
|
|
|
|
|
if (port_mask)
|
|
|
- cpsw_ale_set_vlan_member_list(ale_entry, port_mask);
|
|
|
+ cpsw_ale_set_vlan_member_list(ale_entry, port_mask,
|
|
|
+ ale->vlan_field_bits);
|
|
|
else
|
|
|
cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
|
|
|
|
|
@@ -446,12 +501,15 @@ void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti)
|
|
|
if (type != ALE_TYPE_VLAN)
|
|
|
continue;
|
|
|
|
|
|
- unreg_mcast = cpsw_ale_get_vlan_unreg_mcast(ale_entry);
|
|
|
+ unreg_mcast =
|
|
|
+ cpsw_ale_get_vlan_unreg_mcast(ale_entry,
|
|
|
+ ale->vlan_field_bits);
|
|
|
if (allmulti)
|
|
|
unreg_mcast |= 1;
|
|
|
else
|
|
|
unreg_mcast &= ~1;
|
|
|
- cpsw_ale_set_vlan_unreg_mcast(ale_entry, unreg_mcast);
|
|
|
+ cpsw_ale_set_vlan_unreg_mcast(ale_entry, unreg_mcast,
|
|
|
+ ale->vlan_field_bits);
|
|
|
cpsw_ale_write(ale, idx, ale_entry);
|
|
|
}
|
|
|
}
|
|
@@ -464,7 +522,7 @@ struct ale_control_info {
|
|
|
int bits;
|
|
|
};
|
|
|
|
|
|
-static const struct ale_control_info ale_controls[ALE_NUM_CONTROLS] = {
|
|
|
+static struct ale_control_info ale_controls[ALE_NUM_CONTROLS] = {
|
|
|
[ALE_ENABLE] = {
|
|
|
.name = "enable",
|
|
|
.offset = ALE_CONTROL,
|
|
@@ -721,11 +779,83 @@ static void cpsw_ale_timer(unsigned long arg)
|
|
|
|
|
|
void cpsw_ale_start(struct cpsw_ale *ale)
|
|
|
{
|
|
|
- u32 rev;
|
|
|
+ u32 rev, ale_entries;
|
|
|
|
|
|
rev = __raw_readl(ale->params.ale_regs + ALE_IDVER);
|
|
|
- dev_dbg(ale->params.dev, "initialized cpsw ale revision %d.%d\n",
|
|
|
- ALE_VERSION_MAJOR(rev), ALE_VERSION_MINOR(rev));
|
|
|
+ if (!ale->params.major_ver_mask)
|
|
|
+ ale->params.major_ver_mask = 0xff;
|
|
|
+ ale->version =
|
|
|
+ (ALE_VERSION_MAJOR(rev, ale->params.major_ver_mask) << 8) |
|
|
|
+ ALE_VERSION_MINOR(rev);
|
|
|
+ dev_info(ale->params.dev, "initialized cpsw ale version %d.%d\n",
|
|
|
+ ALE_VERSION_MAJOR(rev, ale->params.major_ver_mask),
|
|
|
+ ALE_VERSION_MINOR(rev));
|
|
|
+
|
|
|
+ if (!ale->params.ale_entries) {
|
|
|
+ ale_entries =
|
|
|
+ __raw_readl(ale->params.ale_regs + ALE_STATUS) &
|
|
|
+ ALE_STATUS_SIZE_MASK;
|
|
|
+ /* ALE available on newer NetCP switches has introduced
|
|
|
+ * a register, ALE_STATUS, to indicate the size of ALE
|
|
|
+ * table which shows the size as a multiple of 1024 entries.
|
|
|
+ * For these, params.ale_entries will be set to zero. So
|
|
|
+ * read the register and update the value of ale_entries.
|
|
|
+ * ALE table on NetCP lite, is much smaller and is indicated
|
|
|
+ * by a value of zero in ALE_STATUS. So use a default value
|
|
|
+ * of ALE_TABLE_SIZE_DEFAULT for this. Caller is expected
|
|
|
+ * to set the value of ale_entries for all other versions
|
|
|
+ * of ALE.
|
|
|
+ */
|
|
|
+ if (!ale_entries)
|
|
|
+ ale_entries = ALE_TABLE_SIZE_DEFAULT;
|
|
|
+ else
|
|
|
+ ale_entries *= ALE_TABLE_SIZE_MULTIPLIER;
|
|
|
+ ale->params.ale_entries = ale_entries;
|
|
|
+ }
|
|
|
+ dev_info(ale->params.dev,
|
|
|
+ "ALE Table size %ld\n", ale->params.ale_entries);
|
|
|
+
|
|
|
+ /* set default bits for existing h/w */
|
|
|
+ ale->port_mask_bits = 3;
|
|
|
+ ale->port_num_bits = 2;
|
|
|
+ ale->vlan_field_bits = 3;
|
|
|
+
|
|
|
+ /* Set defaults override for ALE on NetCP NU switch and for version
|
|
|
+ * 1R3
|
|
|
+ */
|
|
|
+ if (ale->params.nu_switch_ale) {
|
|
|
+ /* Separate registers for unknown vlan configuration.
|
|
|
+ * Also there are N bits, where N is number of ale
|
|
|
+ * ports and shift value should be 0
|
|
|
+ */
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_VLAN_MEMBER].bits =
|
|
|
+ ale->params.ale_ports;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_VLAN_MEMBER].offset =
|
|
|
+ ALE_UNKNOWNVLAN_MEMBER;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_MCAST_FLOOD].bits =
|
|
|
+ ale->params.ale_ports;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_MCAST_FLOOD].shift = 0;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_MCAST_FLOOD].offset =
|
|
|
+ ALE_UNKNOWNVLAN_UNREG_MCAST_FLOOD;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_REG_MCAST_FLOOD].bits =
|
|
|
+ ale->params.ale_ports;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_REG_MCAST_FLOOD].shift = 0;
|
|
|
+ ale_controls[ALE_PORT_UNKNOWN_REG_MCAST_FLOOD].offset =
|
|
|
+ ALE_UNKNOWNVLAN_REG_MCAST_FLOOD;
|
|
|
+ ale_controls[ALE_PORT_UNTAGGED_EGRESS].bits =
|
|
|
+ ale->params.ale_ports;
|
|
|
+ ale_controls[ALE_PORT_UNTAGGED_EGRESS].shift = 0;
|
|
|
+ ale_controls[ALE_PORT_UNTAGGED_EGRESS].offset =
|
|
|
+ ALE_UNKNOWNVLAN_FORCE_UNTAG_EGRESS;
|
|
|
+ ale->port_mask_bits = ale->params.ale_ports;
|
|
|
+ ale->port_num_bits = ale->params.ale_ports - 1;
|
|
|
+ ale->vlan_field_bits = ale->params.ale_ports;
|
|
|
+ } else if (ale->version == ALE_VERSION_1R3) {
|
|
|
+ ale->port_mask_bits = ale->params.ale_ports;
|
|
|
+ ale->port_num_bits = 3;
|
|
|
+ ale->vlan_field_bits = ale->params.ale_ports;
|
|
|
+ }
|
|
|
+
|
|
|
cpsw_ale_control_set(ale, 0, ALE_ENABLE, 1);
|
|
|
cpsw_ale_control_set(ale, 0, ALE_CLEAR, 1);
|
|
|
|