1 From 0d1866b8c6f17a55207be651a3b3b93879fbdf1f Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Sat, 9 Nov 2019 15:02:49 +0200
4 Subject: [PATCH] net: mscc: ocelot: break out fdb operations into abstract
7 To be able to implement a DSA front-end over ocelot_fdb_add,
8 ocelot_fdb_del, ocelot_fdb_dump, these need to have a simple function
9 prototype that is independent of struct net_device, netlink skb, etc.
11 So rename the ndo ops of the ocelot driver into
12 ocelot_port_fdb_{add,del,dump}, and have them all call the abstract
13 implementations. At the same time, refactor ocelot_port_fdb_do_dump into
14 a function whose prototype is compatible with dsa_fdb_dump_cb_t, so that
15 the do_dump implementations can live together and be called by the
16 ocelot_fdb_dump through a function pointer.
18 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
21 drivers/net/ethernet/mscc/ocelot.c | 124 +++++++++++++++++++++++--------------
22 1 file changed, 78 insertions(+), 46 deletions(-)
24 --- a/drivers/net/ethernet/mscc/ocelot.c
25 +++ b/drivers/net/ethernet/mscc/ocelot.c
27 #include <net/netevent.h>
28 #include <net/rtnetlink.h>
29 #include <net/switchdev.h>
33 #include "ocelot_ace.h"
34 @@ -814,21 +815,18 @@ static void ocelot_get_stats64(struct ne
35 stats->collisions = ocelot_read(ocelot, SYS_COUNT_TX_COLLISION);
38 -static int ocelot_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
39 - struct net_device *dev, const unsigned char *addr,
41 - struct netlink_ext_ack *extack)
42 +static int ocelot_fdb_add(struct ocelot *ocelot, int port,
43 + const unsigned char *addr, u16 vid)
45 - struct ocelot_port *port = netdev_priv(dev);
46 - struct ocelot *ocelot = port->ocelot;
47 + struct ocelot_port *ocelot_port = ocelot->ports[port];
50 - if (!port->vlan_aware)
51 + if (!ocelot_port->vlan_aware)
52 /* If the bridge is not VLAN aware and no VID was
53 * provided, set it to pvid to ensure the MAC entry
54 * matches incoming untagged packets
57 + vid = ocelot_port->pvid;
59 /* If the bridge is VLAN aware a VID must be provided as
60 * otherwise the learnt entry wouldn't match any frame.
61 @@ -836,20 +834,37 @@ static int ocelot_fdb_add(struct ndmsg *
65 - return ocelot_mact_learn(ocelot, port->chip_port, addr, vid,
67 + return ocelot_mact_learn(ocelot, port, addr, vid, ENTRYTYPE_LOCKED);
70 -static int ocelot_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
71 - struct net_device *dev,
72 - const unsigned char *addr, u16 vid)
73 +static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
74 + struct net_device *dev,
75 + const unsigned char *addr,
77 + struct netlink_ext_ack *extack)
79 - struct ocelot_port *port = netdev_priv(dev);
80 - struct ocelot *ocelot = port->ocelot;
81 + struct ocelot_port *ocelot_port = netdev_priv(dev);
82 + struct ocelot *ocelot = ocelot_port->ocelot;
84 + return ocelot_fdb_add(ocelot, ocelot_port->chip_port, addr, vid);
87 +static int ocelot_fdb_del(struct ocelot *ocelot, int port,
88 + const unsigned char *addr, u16 vid)
90 return ocelot_mact_forget(ocelot, addr, vid);
93 +static int ocelot_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
94 + struct net_device *dev,
95 + const unsigned char *addr, u16 vid)
97 + struct ocelot_port *ocelot_port = netdev_priv(dev);
98 + struct ocelot *ocelot = ocelot_port->ocelot;
100 + return ocelot_fdb_del(ocelot, ocelot_port->chip_port, addr, vid);
103 struct ocelot_dump_ctx {
104 struct net_device *dev;
106 @@ -857,9 +872,10 @@ struct ocelot_dump_ctx {
110 -static int ocelot_fdb_do_dump(struct ocelot_mact_entry *entry,
111 - struct ocelot_dump_ctx *dump)
112 +static int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid,
113 + bool is_static, void *data)
115 + struct ocelot_dump_ctx *dump = data;
116 u32 portid = NETLINK_CB(dump->cb->skb).portid;
117 u32 seq = dump->cb->nlh->nlmsg_seq;
118 struct nlmsghdr *nlh;
119 @@ -880,12 +896,12 @@ static int ocelot_fdb_do_dump(struct oce
120 ndm->ndm_flags = NTF_SELF;
122 ndm->ndm_ifindex = dump->dev->ifindex;
123 - ndm->ndm_state = NUD_REACHABLE;
124 + ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
126 - if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, entry->mac))
127 + if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
128 goto nla_put_failure;
130 - if (entry->vid && nla_put_u16(dump->skb, NDA_VLAN, entry->vid))
131 + if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
132 goto nla_put_failure;
134 nlmsg_end(dump->skb, nlh);
135 @@ -899,12 +915,11 @@ nla_put_failure:
139 -static inline int ocelot_mact_read(struct ocelot_port *port, int row, int col,
140 - struct ocelot_mact_entry *entry)
141 +static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col,
142 + struct ocelot_mact_entry *entry)
144 - struct ocelot *ocelot = port->ocelot;
145 - char mac[ETH_ALEN];
146 u32 val, dst, macl, mach;
147 + char mac[ETH_ALEN];
149 /* Set row and column to read from */
150 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row);
151 @@ -927,7 +942,7 @@ static inline int ocelot_mact_read(struc
154 dst = (val & ANA_TABLES_MACACCESS_DEST_IDX_M) >> 3;
155 - if (dst != port->chip_port)
159 /* Get the entry's MAC address and VLAN id */
160 @@ -947,43 +962,60 @@ static inline int ocelot_mact_read(struc
164 -static int ocelot_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
165 - struct net_device *dev,
166 - struct net_device *filter_dev, int *idx)
167 +static int ocelot_fdb_dump(struct ocelot *ocelot, int port,
168 + dsa_fdb_dump_cb_t *cb, void *data)
170 - struct ocelot_port *port = netdev_priv(dev);
172 - struct ocelot_dump_ctx dump = {
179 - struct ocelot_mact_entry entry;
182 /* Loop through all the mac tables entries. There are 1024 rows of 4
185 for (i = 0; i < 1024; i++) {
186 for (j = 0; j < 4; j++) {
187 - ret = ocelot_mact_read(port, i, j, &entry);
188 + struct ocelot_mact_entry entry;
192 + ret = ocelot_mact_read(ocelot, port, i, j, &entry);
193 /* If the entry is invalid (wrong port, invalid...),
202 + is_static = (entry.type == ENTRYTYPE_LOCKED);
204 - ret = ocelot_fdb_do_dump(&entry, &dump);
205 + ret = cb(entry.mac, entry.vid, is_static, data);
216 +static int ocelot_port_fdb_dump(struct sk_buff *skb,
217 + struct netlink_callback *cb,
218 + struct net_device *dev,
219 + struct net_device *filter_dev, int *idx)
221 + struct ocelot_port *ocelot_port = netdev_priv(dev);
222 + struct ocelot *ocelot = ocelot_port->ocelot;
223 + struct ocelot_dump_ctx dump = {
231 + ret = ocelot_fdb_dump(ocelot, ocelot_port->chip_port,
232 + ocelot_port_fdb_do_dump, &dump);
239 @@ -1123,9 +1155,9 @@ static const struct net_device_ops ocelo
240 .ndo_get_phys_port_name = ocelot_port_get_phys_port_name,
241 .ndo_set_mac_address = ocelot_port_set_mac_address,
242 .ndo_get_stats64 = ocelot_get_stats64,
243 - .ndo_fdb_add = ocelot_fdb_add,
244 - .ndo_fdb_del = ocelot_fdb_del,
245 - .ndo_fdb_dump = ocelot_fdb_dump,
246 + .ndo_fdb_add = ocelot_port_fdb_add,
247 + .ndo_fdb_del = ocelot_port_fdb_del,
248 + .ndo_fdb_dump = ocelot_port_fdb_dump,
249 .ndo_vlan_rx_add_vid = ocelot_vlan_rx_add_vid,
250 .ndo_vlan_rx_kill_vid = ocelot_vlan_rx_kill_vid,
251 .ndo_set_features = ocelot_set_features,