diff options
| author | Florian Fainelli <f.fainelli@gmail.com> | 2016-06-09 21:23:55 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2016-06-10 01:21:29 -0400 |
| commit | 1da6df85c6fbed8f39c56eadcae7fa75a7a0c635 (patch) | |
| tree | 8f21c5b0f21b58b0b9ea27ffa3b8613ce6d9d9aa /drivers/net/dsa/b53 | |
| parent | 0830c9802e33d8c94b9b2f89b3db4aae92e55bf6 (diff) | |
net: dsa: b53: Implement ARL add/del/dump operations
Adds support for FDB add/delete/dump using the ARL read/write logic and
the ARL search logic for faster dumps. The code is made flexible enough
it could support devices with a different register layout like BCM5325
and BCM5365 which have fewer number of entries or pack values into a
single 64 bits register.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/dsa/b53')
| -rw-r--r-- | drivers/net/dsa/b53/b53_common.c | 261 | ||||
| -rw-r--r-- | drivers/net/dsa/b53/b53_priv.h | 57 | ||||
| -rw-r--r-- | drivers/net/dsa/b53/b53_regs.h | 64 |
3 files changed, 382 insertions, 0 deletions
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 6f0337d6dfa4..a9f1de407f57 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c | |||
| @@ -26,7 +26,9 @@ | |||
| 26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
| 27 | #include <linux/platform_data/b53.h> | 27 | #include <linux/platform_data/b53.h> |
| 28 | #include <linux/phy.h> | 28 | #include <linux/phy.h> |
| 29 | #include <linux/etherdevice.h> | ||
| 29 | #include <net/dsa.h> | 30 | #include <net/dsa.h> |
| 31 | #include <net/switchdev.h> | ||
| 30 | 32 | ||
| 31 | #include "b53_regs.h" | 33 | #include "b53_regs.h" |
| 32 | #include "b53_priv.h" | 34 | #include "b53_priv.h" |
| @@ -777,6 +779,246 @@ static void b53_adjust_link(struct dsa_switch *ds, int port, | |||
| 777 | } | 779 | } |
| 778 | } | 780 | } |
| 779 | 781 | ||
| 782 | /* Address Resolution Logic routines */ | ||
| 783 | static int b53_arl_op_wait(struct b53_device *dev) | ||
| 784 | { | ||
| 785 | unsigned int timeout = 10; | ||
| 786 | u8 reg; | ||
| 787 | |||
| 788 | do { | ||
| 789 | b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); | ||
| 790 | if (!(reg & ARLTBL_START_DONE)) | ||
| 791 | return 0; | ||
| 792 | |||
| 793 | usleep_range(1000, 2000); | ||
| 794 | } while (timeout--); | ||
| 795 | |||
| 796 | dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); | ||
| 797 | |||
| 798 | return -ETIMEDOUT; | ||
| 799 | } | ||
| 800 | |||
| 801 | static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) | ||
| 802 | { | ||
| 803 | u8 reg; | ||
| 804 | |||
| 805 | if (op > ARLTBL_RW) | ||
| 806 | return -EINVAL; | ||
| 807 | |||
| 808 | b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); | ||
| 809 | reg |= ARLTBL_START_DONE; | ||
| 810 | if (op) | ||
| 811 | reg |= ARLTBL_RW; | ||
| 812 | else | ||
| 813 | reg &= ~ARLTBL_RW; | ||
| 814 | b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); | ||
| 815 | |||
| 816 | return b53_arl_op_wait(dev); | ||
| 817 | } | ||
| 818 | |||
| 819 | static int b53_arl_read(struct b53_device *dev, u64 mac, | ||
| 820 | u16 vid, struct b53_arl_entry *ent, u8 *idx, | ||
| 821 | bool is_valid) | ||
| 822 | { | ||
| 823 | unsigned int i; | ||
| 824 | int ret; | ||
| 825 | |||
| 826 | ret = b53_arl_op_wait(dev); | ||
| 827 | if (ret) | ||
| 828 | return ret; | ||
| 829 | |||
| 830 | /* Read the bins */ | ||
| 831 | for (i = 0; i < dev->num_arl_entries; i++) { | ||
| 832 | u64 mac_vid; | ||
| 833 | u32 fwd_entry; | ||
| 834 | |||
| 835 | b53_read64(dev, B53_ARLIO_PAGE, | ||
| 836 | B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); | ||
| 837 | b53_read32(dev, B53_ARLIO_PAGE, | ||
| 838 | B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); | ||
| 839 | b53_arl_to_entry(ent, mac_vid, fwd_entry); | ||
| 840 | |||
| 841 | if (!(fwd_entry & ARLTBL_VALID)) | ||
| 842 | continue; | ||
| 843 | if ((mac_vid & ARLTBL_MAC_MASK) != mac) | ||
| 844 | continue; | ||
| 845 | *idx = i; | ||
| 846 | } | ||
| 847 | |||
| 848 | return -ENOENT; | ||
| 849 | } | ||
| 850 | |||
| 851 | static int b53_arl_op(struct b53_device *dev, int op, int port, | ||
| 852 | const unsigned char *addr, u16 vid, bool is_valid) | ||
| 853 | { | ||
| 854 | struct b53_arl_entry ent; | ||
| 855 | u32 fwd_entry; | ||
| 856 | u64 mac, mac_vid = 0; | ||
| 857 | u8 idx = 0; | ||
| 858 | int ret; | ||
| 859 | |||
| 860 | /* Convert the array into a 64-bit MAC */ | ||
| 861 | mac = b53_mac_to_u64(addr); | ||
| 862 | |||
| 863 | /* Perform a read for the given MAC and VID */ | ||
| 864 | b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); | ||
| 865 | b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); | ||
| 866 | |||
| 867 | /* Issue a read operation for this MAC */ | ||
| 868 | ret = b53_arl_rw_op(dev, 1); | ||
| 869 | if (ret) | ||
| 870 | return ret; | ||
| 871 | |||
| 872 | ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid); | ||
| 873 | /* If this is a read, just finish now */ | ||
| 874 | if (op) | ||
| 875 | return ret; | ||
| 876 | |||
| 877 | /* We could not find a matching MAC, so reset to a new entry */ | ||
| 878 | if (ret) { | ||
| 879 | fwd_entry = 0; | ||
| 880 | idx = 1; | ||
| 881 | } | ||
| 882 | |||
| 883 | memset(&ent, 0, sizeof(ent)); | ||
| 884 | ent.port = port; | ||
| 885 | ent.is_valid = is_valid; | ||
| 886 | ent.vid = vid; | ||
| 887 | ent.is_static = true; | ||
| 888 | memcpy(ent.mac, addr, ETH_ALEN); | ||
| 889 | b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); | ||
| 890 | |||
| 891 | b53_write64(dev, B53_ARLIO_PAGE, | ||
| 892 | B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); | ||
| 893 | b53_write32(dev, B53_ARLIO_PAGE, | ||
| 894 | B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); | ||
| 895 | |||
| 896 | return b53_arl_rw_op(dev, 0); | ||
| 897 | } | ||
| 898 | |||
| 899 | static int b53_fdb_prepare(struct dsa_switch *ds, int port, | ||
| 900 | const struct switchdev_obj_port_fdb *fdb, | ||
| 901 | struct switchdev_trans *trans) | ||
| 902 | { | ||
| 903 | struct b53_device *priv = ds_to_priv(ds); | ||
| 904 | |||
| 905 | /* 5325 and 5365 require some more massaging, but could | ||
| 906 | * be supported eventually | ||
| 907 | */ | ||
| 908 | if (is5325(priv) || is5365(priv)) | ||
| 909 | return -EOPNOTSUPP; | ||
| 910 | |||
| 911 | return 0; | ||
| 912 | } | ||
| 913 | |||
| 914 | static void b53_fdb_add(struct dsa_switch *ds, int port, | ||
| 915 | const struct switchdev_obj_port_fdb *fdb, | ||
| 916 | struct switchdev_trans *trans) | ||
| 917 | { | ||
| 918 | struct b53_device *priv = ds_to_priv(ds); | ||
| 919 | |||
| 920 | if (b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, true)) | ||
| 921 | pr_err("%s: failed to add MAC address\n", __func__); | ||
| 922 | } | ||
| 923 | |||
| 924 | static int b53_fdb_del(struct dsa_switch *ds, int port, | ||
| 925 | const struct switchdev_obj_port_fdb *fdb) | ||
| 926 | { | ||
| 927 | struct b53_device *priv = ds_to_priv(ds); | ||
| 928 | |||
| 929 | return b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, false); | ||
| 930 | } | ||
| 931 | |||
| 932 | static int b53_arl_search_wait(struct b53_device *dev) | ||
| 933 | { | ||
| 934 | unsigned int timeout = 1000; | ||
| 935 | u8 reg; | ||
| 936 | |||
| 937 | do { | ||
| 938 | b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); | ||
| 939 | if (!(reg & ARL_SRCH_STDN)) | ||
| 940 | return 0; | ||
| 941 | |||
| 942 | if (reg & ARL_SRCH_VLID) | ||
| 943 | return 0; | ||
| 944 | |||
| 945 | usleep_range(1000, 2000); | ||
| 946 | } while (timeout--); | ||
| 947 | |||
| 948 | return -ETIMEDOUT; | ||
| 949 | } | ||
| 950 | |||
| 951 | static void b53_arl_search_rd(struct b53_device *dev, u8 idx, | ||
| 952 | struct b53_arl_entry *ent) | ||
| 953 | { | ||
| 954 | u64 mac_vid; | ||
| 955 | u32 fwd_entry; | ||
| 956 | |||
| 957 | b53_read64(dev, B53_ARLIO_PAGE, | ||
| 958 | B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); | ||
| 959 | b53_read32(dev, B53_ARLIO_PAGE, | ||
| 960 | B53_ARL_SRCH_RSTL(idx), &fwd_entry); | ||
| 961 | b53_arl_to_entry(ent, mac_vid, fwd_entry); | ||
| 962 | } | ||
| 963 | |||
| 964 | static int b53_fdb_copy(struct net_device *dev, int port, | ||
| 965 | const struct b53_arl_entry *ent, | ||
| 966 | struct switchdev_obj_port_fdb *fdb, | ||
| 967 | int (*cb)(struct switchdev_obj *obj)) | ||
| 968 | { | ||
| 969 | if (!ent->is_valid) | ||
| 970 | return 0; | ||
| 971 | |||
| 972 | if (port != ent->port) | ||
| 973 | return 0; | ||
| 974 | |||
| 975 | ether_addr_copy(fdb->addr, ent->mac); | ||
| 976 | fdb->vid = ent->vid; | ||
| 977 | fdb->ndm_state = ent->is_static ? NUD_NOARP : NUD_REACHABLE; | ||
| 978 | |||
| 979 | return cb(&fdb->obj); | ||
| 980 | } | ||
| 981 | |||
| 982 | static int b53_fdb_dump(struct dsa_switch *ds, int port, | ||
| 983 | struct switchdev_obj_port_fdb *fdb, | ||
| 984 | int (*cb)(struct switchdev_obj *obj)) | ||
| 985 | { | ||
| 986 | struct b53_device *priv = ds_to_priv(ds); | ||
| 987 | struct net_device *dev = ds->ports[port].netdev; | ||
| 988 | struct b53_arl_entry results[2]; | ||
| 989 | unsigned int count = 0; | ||
| 990 | int ret; | ||
| 991 | u8 reg; | ||
| 992 | |||
| 993 | /* Start search operation */ | ||
| 994 | reg = ARL_SRCH_STDN; | ||
| 995 | b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); | ||
| 996 | |||
| 997 | do { | ||
| 998 | ret = b53_arl_search_wait(priv); | ||
| 999 | if (ret) | ||
| 1000 | return ret; | ||
| 1001 | |||
| 1002 | b53_arl_search_rd(priv, 0, &results[0]); | ||
| 1003 | ret = b53_fdb_copy(dev, port, &results[0], fdb, cb); | ||
| 1004 | if (ret) | ||
| 1005 | return ret; | ||
| 1006 | |||
| 1007 | if (priv->num_arl_entries > 2) { | ||
| 1008 | b53_arl_search_rd(priv, 1, &results[1]); | ||
| 1009 | ret = b53_fdb_copy(dev, port, &results[1], fdb, cb); | ||
| 1010 | if (ret) | ||
| 1011 | return ret; | ||
| 1012 | |||
| 1013 | if (!results[0].is_valid && !results[1].is_valid) | ||
| 1014 | break; | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | } while (count++ < 1024); | ||
| 1018 | |||
| 1019 | return 0; | ||
| 1020 | } | ||
| 1021 | |||
| 780 | static struct dsa_switch_driver b53_switch_ops = { | 1022 | static struct dsa_switch_driver b53_switch_ops = { |
| 781 | .tag_protocol = DSA_TAG_PROTO_NONE, | 1023 | .tag_protocol = DSA_TAG_PROTO_NONE, |
| 782 | .setup = b53_setup, | 1024 | .setup = b53_setup, |
| @@ -789,6 +1031,10 @@ static struct dsa_switch_driver b53_switch_ops = { | |||
| 789 | .adjust_link = b53_adjust_link, | 1031 | .adjust_link = b53_adjust_link, |
| 790 | .port_enable = b53_enable_port, | 1032 | .port_enable = b53_enable_port, |
| 791 | .port_disable = b53_disable_port, | 1033 | .port_disable = b53_disable_port, |
| 1034 | .port_fdb_prepare = b53_fdb_prepare, | ||
| 1035 | .port_fdb_dump = b53_fdb_dump, | ||
| 1036 | .port_fdb_add = b53_fdb_add, | ||
| 1037 | .port_fdb_del = b53_fdb_del, | ||
| 792 | }; | 1038 | }; |
| 793 | 1039 | ||
| 794 | struct b53_chip_data { | 1040 | struct b53_chip_data { |
| @@ -798,6 +1044,7 @@ struct b53_chip_data { | |||
| 798 | u16 enabled_ports; | 1044 | u16 enabled_ports; |
| 799 | u8 cpu_port; | 1045 | u8 cpu_port; |
| 800 | u8 vta_regs[3]; | 1046 | u8 vta_regs[3]; |
| 1047 | u8 arl_entries; | ||
| 801 | u8 duplex_reg; | 1048 | u8 duplex_reg; |
| 802 | u8 jumbo_pm_reg; | 1049 | u8 jumbo_pm_reg; |
| 803 | u8 jumbo_size_reg; | 1050 | u8 jumbo_size_reg; |
| @@ -816,6 +1063,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 816 | .dev_name = "BCM5325", | 1063 | .dev_name = "BCM5325", |
| 817 | .vlans = 16, | 1064 | .vlans = 16, |
| 818 | .enabled_ports = 0x1f, | 1065 | .enabled_ports = 0x1f, |
| 1066 | .arl_entries = 2, | ||
| 819 | .cpu_port = B53_CPU_PORT_25, | 1067 | .cpu_port = B53_CPU_PORT_25, |
| 820 | .duplex_reg = B53_DUPLEX_STAT_FE, | 1068 | .duplex_reg = B53_DUPLEX_STAT_FE, |
| 821 | }, | 1069 | }, |
| @@ -824,6 +1072,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 824 | .dev_name = "BCM5365", | 1072 | .dev_name = "BCM5365", |
| 825 | .vlans = 256, | 1073 | .vlans = 256, |
| 826 | .enabled_ports = 0x1f, | 1074 | .enabled_ports = 0x1f, |
| 1075 | .arl_entries = 2, | ||
| 827 | .cpu_port = B53_CPU_PORT_25, | 1076 | .cpu_port = B53_CPU_PORT_25, |
| 828 | .duplex_reg = B53_DUPLEX_STAT_FE, | 1077 | .duplex_reg = B53_DUPLEX_STAT_FE, |
| 829 | }, | 1078 | }, |
| @@ -832,6 +1081,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 832 | .dev_name = "BCM5395", | 1081 | .dev_name = "BCM5395", |
| 833 | .vlans = 4096, | 1082 | .vlans = 4096, |
| 834 | .enabled_ports = 0x1f, | 1083 | .enabled_ports = 0x1f, |
| 1084 | .arl_entries = 4, | ||
| 835 | .cpu_port = B53_CPU_PORT, | 1085 | .cpu_port = B53_CPU_PORT, |
| 836 | .vta_regs = B53_VTA_REGS, | 1086 | .vta_regs = B53_VTA_REGS, |
| 837 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1087 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -843,6 +1093,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 843 | .dev_name = "BCM5397", | 1093 | .dev_name = "BCM5397", |
| 844 | .vlans = 4096, | 1094 | .vlans = 4096, |
| 845 | .enabled_ports = 0x1f, | 1095 | .enabled_ports = 0x1f, |
| 1096 | .arl_entries = 4, | ||
| 846 | .cpu_port = B53_CPU_PORT, | 1097 | .cpu_port = B53_CPU_PORT, |
| 847 | .vta_regs = B53_VTA_REGS_9798, | 1098 | .vta_regs = B53_VTA_REGS_9798, |
| 848 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1099 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -854,6 +1105,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 854 | .dev_name = "BCM5398", | 1105 | .dev_name = "BCM5398", |
| 855 | .vlans = 4096, | 1106 | .vlans = 4096, |
| 856 | .enabled_ports = 0x7f, | 1107 | .enabled_ports = 0x7f, |
| 1108 | .arl_entries = 4, | ||
| 857 | .cpu_port = B53_CPU_PORT, | 1109 | .cpu_port = B53_CPU_PORT, |
| 858 | .vta_regs = B53_VTA_REGS_9798, | 1110 | .vta_regs = B53_VTA_REGS_9798, |
| 859 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1111 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -865,6 +1117,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 865 | .dev_name = "BCM53115", | 1117 | .dev_name = "BCM53115", |
| 866 | .vlans = 4096, | 1118 | .vlans = 4096, |
| 867 | .enabled_ports = 0x1f, | 1119 | .enabled_ports = 0x1f, |
| 1120 | .arl_entries = 4, | ||
| 868 | .vta_regs = B53_VTA_REGS, | 1121 | .vta_regs = B53_VTA_REGS, |
| 869 | .cpu_port = B53_CPU_PORT, | 1122 | .cpu_port = B53_CPU_PORT, |
| 870 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1123 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -887,6 +1140,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 887 | .dev_name = "BCM53128", | 1140 | .dev_name = "BCM53128", |
| 888 | .vlans = 4096, | 1141 | .vlans = 4096, |
| 889 | .enabled_ports = 0x1ff, | 1142 | .enabled_ports = 0x1ff, |
| 1143 | .arl_entries = 4, | ||
| 890 | .cpu_port = B53_CPU_PORT, | 1144 | .cpu_port = B53_CPU_PORT, |
| 891 | .vta_regs = B53_VTA_REGS, | 1145 | .vta_regs = B53_VTA_REGS, |
| 892 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1146 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -898,6 +1152,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 898 | .dev_name = "BCM63xx", | 1152 | .dev_name = "BCM63xx", |
| 899 | .vlans = 4096, | 1153 | .vlans = 4096, |
| 900 | .enabled_ports = 0, /* pdata must provide them */ | 1154 | .enabled_ports = 0, /* pdata must provide them */ |
| 1155 | .arl_entries = 4, | ||
| 901 | .cpu_port = B53_CPU_PORT, | 1156 | .cpu_port = B53_CPU_PORT, |
| 902 | .vta_regs = B53_VTA_REGS_63XX, | 1157 | .vta_regs = B53_VTA_REGS_63XX, |
| 903 | .duplex_reg = B53_DUPLEX_STAT_63XX, | 1158 | .duplex_reg = B53_DUPLEX_STAT_63XX, |
| @@ -909,6 +1164,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 909 | .dev_name = "BCM53010", | 1164 | .dev_name = "BCM53010", |
| 910 | .vlans = 4096, | 1165 | .vlans = 4096, |
| 911 | .enabled_ports = 0x1f, | 1166 | .enabled_ports = 0x1f, |
| 1167 | .arl_entries = 4, | ||
| 912 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ | 1168 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ |
| 913 | .vta_regs = B53_VTA_REGS, | 1169 | .vta_regs = B53_VTA_REGS, |
| 914 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1170 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -920,6 +1176,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 920 | .dev_name = "BCM53011", | 1176 | .dev_name = "BCM53011", |
| 921 | .vlans = 4096, | 1177 | .vlans = 4096, |
| 922 | .enabled_ports = 0x1bf, | 1178 | .enabled_ports = 0x1bf, |
| 1179 | .arl_entries = 4, | ||
| 923 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ | 1180 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ |
| 924 | .vta_regs = B53_VTA_REGS, | 1181 | .vta_regs = B53_VTA_REGS, |
| 925 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1182 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -931,6 +1188,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 931 | .dev_name = "BCM53012", | 1188 | .dev_name = "BCM53012", |
| 932 | .vlans = 4096, | 1189 | .vlans = 4096, |
| 933 | .enabled_ports = 0x1bf, | 1190 | .enabled_ports = 0x1bf, |
| 1191 | .arl_entries = 4, | ||
| 934 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ | 1192 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ |
| 935 | .vta_regs = B53_VTA_REGS, | 1193 | .vta_regs = B53_VTA_REGS, |
| 936 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1194 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -942,6 +1200,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 942 | .dev_name = "BCM53018", | 1200 | .dev_name = "BCM53018", |
| 943 | .vlans = 4096, | 1201 | .vlans = 4096, |
| 944 | .enabled_ports = 0x1f, | 1202 | .enabled_ports = 0x1f, |
| 1203 | .arl_entries = 4, | ||
| 945 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ | 1204 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ |
| 946 | .vta_regs = B53_VTA_REGS, | 1205 | .vta_regs = B53_VTA_REGS, |
| 947 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1206 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -953,6 +1212,7 @@ static const struct b53_chip_data b53_switch_chips[] = { | |||
| 953 | .dev_name = "BCM53019", | 1212 | .dev_name = "BCM53019", |
| 954 | .vlans = 4096, | 1213 | .vlans = 4096, |
| 955 | .enabled_ports = 0x1f, | 1214 | .enabled_ports = 0x1f, |
| 1215 | .arl_entries = 4, | ||
| 956 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ | 1216 | .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ |
| 957 | .vta_regs = B53_VTA_REGS, | 1217 | .vta_regs = B53_VTA_REGS, |
| 958 | .duplex_reg = B53_DUPLEX_STAT_GE, | 1218 | .duplex_reg = B53_DUPLEX_STAT_GE, |
| @@ -982,6 +1242,7 @@ static int b53_switch_init(struct b53_device *dev) | |||
| 982 | ds->drv = &b53_switch_ops; | 1242 | ds->drv = &b53_switch_ops; |
| 983 | dev->cpu_port = chip->cpu_port; | 1243 | dev->cpu_port = chip->cpu_port; |
| 984 | dev->num_vlans = chip->vlans; | 1244 | dev->num_vlans = chip->vlans; |
| 1245 | dev->num_arl_entries = chip->arl_entries; | ||
| 985 | break; | 1246 | break; |
| 986 | } | 1247 | } |
| 987 | } | 1248 | } |
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h index c4844155546b..1ee4e8016642 100644 --- a/drivers/net/dsa/b53/b53_priv.h +++ b/drivers/net/dsa/b53/b53_priv.h | |||
| @@ -24,6 +24,8 @@ | |||
| 24 | #include <linux/phy.h> | 24 | #include <linux/phy.h> |
| 25 | #include <net/dsa.h> | 25 | #include <net/dsa.h> |
| 26 | 26 | ||
| 27 | #include "b53_regs.h" | ||
| 28 | |||
| 27 | struct b53_device; | 29 | struct b53_device; |
| 28 | 30 | ||
| 29 | struct b53_io_ops { | 31 | struct b53_io_ops { |
| @@ -81,6 +83,7 @@ struct b53_device { | |||
| 81 | u8 jumbo_pm_reg; | 83 | u8 jumbo_pm_reg; |
| 82 | u8 jumbo_size_reg; | 84 | u8 jumbo_size_reg; |
| 83 | int reset_gpio; | 85 | int reset_gpio; |
| 86 | u8 num_arl_entries; | ||
| 84 | 87 | ||
| 85 | /* used ports mask */ | 88 | /* used ports mask */ |
| 86 | u16 enabled_ports; | 89 | u16 enabled_ports; |
| @@ -296,6 +299,60 @@ static inline int b53_write64(struct b53_device *dev, u8 page, u8 reg, | |||
| 296 | return ret; | 299 | return ret; |
| 297 | } | 300 | } |
| 298 | 301 | ||
| 302 | struct b53_arl_entry { | ||
| 303 | u8 port; | ||
| 304 | u8 mac[ETH_ALEN]; | ||
| 305 | u16 vid; | ||
| 306 | u8 is_valid:1; | ||
| 307 | u8 is_age:1; | ||
| 308 | u8 is_static:1; | ||
| 309 | }; | ||
| 310 | |||
| 311 | static inline void b53_mac_from_u64(u64 src, u8 *dst) | ||
| 312 | { | ||
| 313 | unsigned int i; | ||
| 314 | |||
| 315 | for (i = 0; i < ETH_ALEN; i++) | ||
| 316 | dst[ETH_ALEN - 1 - i] = (src >> (8 * i)) & 0xff; | ||
| 317 | } | ||
| 318 | |||
| 319 | static inline u64 b53_mac_to_u64(const u8 *src) | ||
| 320 | { | ||
| 321 | unsigned int i; | ||
| 322 | u64 dst = 0; | ||
| 323 | |||
| 324 | for (i = 0; i < ETH_ALEN; i++) | ||
| 325 | dst |= (u64)src[ETH_ALEN - 1 - i] << (8 * i); | ||
| 326 | |||
| 327 | return dst; | ||
| 328 | } | ||
| 329 | |||
| 330 | static inline void b53_arl_to_entry(struct b53_arl_entry *ent, | ||
| 331 | u64 mac_vid, u32 fwd_entry) | ||
| 332 | { | ||
| 333 | memset(ent, 0, sizeof(*ent)); | ||
| 334 | ent->port = fwd_entry & ARLTBL_DATA_PORT_ID_MASK; | ||
| 335 | ent->is_valid = !!(fwd_entry & ARLTBL_VALID); | ||
| 336 | ent->is_age = !!(fwd_entry & ARLTBL_AGE); | ||
| 337 | ent->is_static = !!(fwd_entry & ARLTBL_STATIC); | ||
| 338 | b53_mac_from_u64(mac_vid, ent->mac); | ||
| 339 | ent->vid = mac_vid >> ARLTBL_VID_S; | ||
| 340 | } | ||
| 341 | |||
| 342 | static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry, | ||
| 343 | const struct b53_arl_entry *ent) | ||
| 344 | { | ||
| 345 | *mac_vid = b53_mac_to_u64(ent->mac); | ||
| 346 | *mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK) << ARLTBL_VID_S; | ||
| 347 | *fwd_entry = ent->port & ARLTBL_DATA_PORT_ID_MASK; | ||
| 348 | if (ent->is_valid) | ||
| 349 | *fwd_entry |= ARLTBL_VALID; | ||
| 350 | if (ent->is_static) | ||
| 351 | *fwd_entry |= ARLTBL_STATIC; | ||
| 352 | if (ent->is_age) | ||
| 353 | *fwd_entry |= ARLTBL_AGE; | ||
| 354 | } | ||
| 355 | |||
| 299 | #ifdef CONFIG_BCM47XX | 356 | #ifdef CONFIG_BCM47XX |
| 300 | 357 | ||
| 301 | #include <linux/version.h> | 358 | #include <linux/version.h> |
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h index ccf8af7717d3..441d2b4121c4 100644 --- a/drivers/net/dsa/b53/b53_regs.h +++ b/drivers/net/dsa/b53/b53_regs.h | |||
| @@ -227,6 +227,70 @@ | |||
| 227 | #define VTE_UNTAG (0x1ff << 9) | 227 | #define VTE_UNTAG (0x1ff << 9) |
| 228 | 228 | ||
| 229 | /************************************************************************* | 229 | /************************************************************************* |
| 230 | * ARL I/O Registers | ||
| 231 | *************************************************************************/ | ||
| 232 | |||
| 233 | /* ARL Table Read/Write Register (8 bit) */ | ||
| 234 | #define B53_ARLTBL_RW_CTRL 0x00 | ||
| 235 | #define ARLTBL_RW BIT(0) | ||
| 236 | #define ARLTBL_START_DONE BIT(7) | ||
| 237 | |||
| 238 | /* MAC Address Index Register (48 bit) */ | ||
| 239 | #define B53_MAC_ADDR_IDX 0x02 | ||
| 240 | |||
| 241 | /* VLAN ID Index Register (16 bit) */ | ||
| 242 | #define B53_VLAN_ID_IDX 0x08 | ||
| 243 | |||
| 244 | /* ARL Table MAC/VID Entry N Registers (64 bit) | ||
| 245 | * | ||
| 246 | * BCM5325 and BCM5365 share most definitions below | ||
| 247 | */ | ||
| 248 | #define B53_ARLTBL_MAC_VID_ENTRY(n) (0x10 * (n)) | ||
| 249 | #define ARLTBL_MAC_MASK 0xffffffffffff | ||
| 250 | #define ARLTBL_VID_S 48 | ||
| 251 | #define ARLTBL_VID_MASK_25 0xff | ||
| 252 | #define ARLTBL_VID_MASK 0xfff | ||
| 253 | #define ARLTBL_DATA_PORT_ID_S_25 48 | ||
| 254 | #define ARLTBL_DATA_PORT_ID_MASK_25 0xf | ||
| 255 | #define ARLTBL_AGE_25 BIT(61) | ||
| 256 | #define ARLTBL_STATIC_25 BIT(62) | ||
| 257 | #define ARLTBL_VALID_25 BIT(63) | ||
| 258 | |||
| 259 | /* ARL Table Data Entry N Registers (32 bit) */ | ||
| 260 | #define B53_ARLTBL_DATA_ENTRY(n) ((0x10 * (n)) + 0x08) | ||
| 261 | #define ARLTBL_DATA_PORT_ID_MASK 0x1ff | ||
| 262 | #define ARLTBL_TC(tc) ((3 & tc) << 11) | ||
| 263 | #define ARLTBL_AGE BIT(14) | ||
| 264 | #define ARLTBL_STATIC BIT(15) | ||
| 265 | #define ARLTBL_VALID BIT(16) | ||
| 266 | |||
| 267 | /* ARL Search Control Register (8 bit) */ | ||
| 268 | #define B53_ARL_SRCH_CTL 0x50 | ||
| 269 | #define B53_ARL_SRCH_CTL_25 0x20 | ||
| 270 | #define ARL_SRCH_VLID BIT(0) | ||
| 271 | #define ARL_SRCH_STDN BIT(7) | ||
| 272 | |||
| 273 | /* ARL Search Address Register (16 bit) */ | ||
| 274 | #define B53_ARL_SRCH_ADDR 0x51 | ||
| 275 | #define B53_ARL_SRCH_ADDR_25 0x22 | ||
| 276 | #define B53_ARL_SRCH_ADDR_65 0x24 | ||
| 277 | #define ARL_ADDR_MASK GENMASK(14, 0) | ||
| 278 | |||
| 279 | /* ARL Search MAC/VID Result (64 bit) */ | ||
| 280 | #define B53_ARL_SRCH_RSTL_0_MACVID 0x60 | ||
| 281 | |||
| 282 | /* Single register search result on 5325 */ | ||
| 283 | #define B53_ARL_SRCH_RSTL_0_MACVID_25 0x24 | ||
| 284 | /* Single register search result on 5365 */ | ||
| 285 | #define B53_ARL_SRCH_RSTL_0_MACVID_65 0x30 | ||
| 286 | |||
| 287 | /* ARL Search Data Result (32 bit) */ | ||
| 288 | #define B53_ARL_SRCH_RSTL_0 0x68 | ||
| 289 | |||
| 290 | #define B53_ARL_SRCH_RSTL_MACVID(x) (B53_ARL_SRCH_RSTL_0_MACVID + ((x) * 0x10)) | ||
| 291 | #define B53_ARL_SRCH_RSTL(x) (B53_ARL_SRCH_RSTL_0 + ((x) * 0x10)) | ||
| 292 | |||
| 293 | /************************************************************************* | ||
| 230 | * Port VLAN Registers | 294 | * Port VLAN Registers |
| 231 | *************************************************************************/ | 295 | *************************************************************************/ |
| 232 | 296 | ||
