aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/dsa/bcm_sf2.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/dsa/bcm_sf2.h')
-rw-r--r--drivers/net/dsa/bcm_sf2.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/drivers/net/dsa/bcm_sf2.h b/drivers/net/dsa/bcm_sf2.h
index 789d7b7737da..cc98abc0aaf3 100644
--- a/drivers/net/dsa/bcm_sf2.h
+++ b/drivers/net/dsa/bcm_sf2.h
@@ -19,6 +19,8 @@
19#include <linux/mutex.h> 19#include <linux/mutex.h>
20#include <linux/mii.h> 20#include <linux/mii.h>
21#include <linux/ethtool.h> 21#include <linux/ethtool.h>
22#include <linux/types.h>
23#include <linux/bitops.h>
22 24
23#include <net/dsa.h> 25#include <net/dsa.h>
24 26
@@ -50,6 +52,60 @@ struct bcm_sf2_port_status {
50 u32 vlan_ctl_mask; 52 u32 vlan_ctl_mask;
51}; 53};
52 54
55struct bcm_sf2_arl_entry {
56 u8 port;
57 u8 mac[ETH_ALEN];
58 u16 vid;
59 u8 is_valid:1;
60 u8 is_age:1;
61 u8 is_static:1;
62};
63
64static inline void bcm_sf2_mac_from_u64(u64 src, u8 *dst)
65{
66 unsigned int i;
67
68 for (i = 0; i < ETH_ALEN; i++)
69 dst[ETH_ALEN - 1 - i] = (src >> (8 * i)) & 0xff;
70}
71
72static inline u64 bcm_sf2_mac_to_u64(const u8 *src)
73{
74 unsigned int i;
75 u64 dst = 0;
76
77 for (i = 0; i < ETH_ALEN; i++)
78 dst |= (u64)src[ETH_ALEN - 1 - i] << (8 * i);
79
80 return dst;
81}
82
83static inline void bcm_sf2_arl_to_entry(struct bcm_sf2_arl_entry *ent,
84 u64 mac_vid, u32 fwd_entry)
85{
86 memset(ent, 0, sizeof(*ent));
87 ent->port = fwd_entry & PORTID_MASK;
88 ent->is_valid = !!(fwd_entry & ARL_VALID);
89 ent->is_age = !!(fwd_entry & ARL_AGE);
90 ent->is_static = !!(fwd_entry & ARL_STATIC);
91 bcm_sf2_mac_from_u64(mac_vid, ent->mac);
92 ent->vid = mac_vid >> VID_SHIFT;
93}
94
95static inline void bcm_sf2_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
96 const struct bcm_sf2_arl_entry *ent)
97{
98 *mac_vid = bcm_sf2_mac_to_u64(ent->mac);
99 *mac_vid |= (u64)(ent->vid & VID_MASK) << VID_SHIFT;
100 *fwd_entry = ent->port & PORTID_MASK;
101 if (ent->is_valid)
102 *fwd_entry |= ARL_VALID;
103 if (ent->is_static)
104 *fwd_entry |= ARL_STATIC;
105 if (ent->is_age)
106 *fwd_entry |= ARL_AGE;
107}
108
53struct bcm_sf2_priv { 109struct bcm_sf2_priv {
54 /* Base registers, keep those in order with BCM_SF2_REGS_NAME */ 110 /* Base registers, keep those in order with BCM_SF2_REGS_NAME */
55 void __iomem *core; 111 void __iomem *core;