blob: a53bd36b11c60460c2e0548e664789c354d0b4d0 [file] [log] [blame]
Alexandre Bellonia556c762018-05-14 22:04:57 +02001// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * Microsemi Ocelot Switch driver
4 *
5 * Copyright (c) 2017 Microsemi Corporation
6 */
Alexandre Bellonia556c762018-05-14 22:04:57 +02007#include <linux/if_bridge.h>
Vladimir Oltean20968052020-09-30 01:27:26 +03008#include <soc/mscc/ocelot_vcap.h>
Alexandre Bellonia556c762018-05-14 22:04:57 +02009#include "ocelot.h"
Vladimir Oltean3c836542020-06-20 18:43:45 +030010#include "ocelot_vcap.h"
Alexandre Bellonia556c762018-05-14 22:04:57 +020011
Steen Hegelund639c1b22018-12-20 14:16:31 +010012#define TABLE_UPDATE_SLEEP_US 10
13#define TABLE_UPDATE_TIMEOUT_US 100000
14
Alexandre Bellonia556c762018-05-14 22:04:57 +020015struct ocelot_mact_entry {
16 u8 mac[ETH_ALEN];
17 u16 vid;
18 enum macaccess_entry_type type;
19};
20
Steen Hegelund639c1b22018-12-20 14:16:31 +010021static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot)
22{
23 return ocelot_read(ocelot, ANA_TABLES_MACACCESS);
24}
25
Alexandre Bellonia556c762018-05-14 22:04:57 +020026static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot)
27{
Steen Hegelund639c1b22018-12-20 14:16:31 +010028 u32 val;
Alexandre Bellonia556c762018-05-14 22:04:57 +020029
Steen Hegelund639c1b22018-12-20 14:16:31 +010030 return readx_poll_timeout(ocelot_mact_read_macaccess,
31 ocelot, val,
32 (val & ANA_TABLES_MACACCESS_MAC_TABLE_CMD_M) ==
33 MACACCESS_CMD_IDLE,
34 TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
Alexandre Bellonia556c762018-05-14 22:04:57 +020035}
36
37static void ocelot_mact_select(struct ocelot *ocelot,
38 const unsigned char mac[ETH_ALEN],
39 unsigned int vid)
40{
41 u32 macl = 0, mach = 0;
42
43 /* Set the MAC address to handle and the vlan associated in a format
44 * understood by the hardware.
45 */
46 mach |= vid << 16;
47 mach |= mac[0] << 8;
48 mach |= mac[1] << 0;
49 macl |= mac[2] << 24;
50 macl |= mac[3] << 16;
51 macl |= mac[4] << 8;
52 macl |= mac[5] << 0;
53
54 ocelot_write(ocelot, macl, ANA_TABLES_MACLDATA);
55 ocelot_write(ocelot, mach, ANA_TABLES_MACHDATA);
56
57}
58
Vladimir Oltean9c90eea2020-06-20 18:43:44 +030059int ocelot_mact_learn(struct ocelot *ocelot, int port,
60 const unsigned char mac[ETH_ALEN],
61 unsigned int vid, enum macaccess_entry_type type)
Alexandre Bellonia556c762018-05-14 22:04:57 +020062{
63 ocelot_mact_select(ocelot, mac, vid);
64
65 /* Issue a write command */
66 ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID |
67 ANA_TABLES_MACACCESS_DEST_IDX(port) |
68 ANA_TABLES_MACACCESS_ENTRYTYPE(type) |
69 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_LEARN),
70 ANA_TABLES_MACACCESS);
71
72 return ocelot_mact_wait_for_completion(ocelot);
73}
Vladimir Oltean9c90eea2020-06-20 18:43:44 +030074EXPORT_SYMBOL(ocelot_mact_learn);
Alexandre Bellonia556c762018-05-14 22:04:57 +020075
Vladimir Oltean9c90eea2020-06-20 18:43:44 +030076int ocelot_mact_forget(struct ocelot *ocelot,
77 const unsigned char mac[ETH_ALEN], unsigned int vid)
Alexandre Bellonia556c762018-05-14 22:04:57 +020078{
79 ocelot_mact_select(ocelot, mac, vid);
80
81 /* Issue a forget command */
82 ocelot_write(ocelot,
83 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_FORGET),
84 ANA_TABLES_MACACCESS);
85
86 return ocelot_mact_wait_for_completion(ocelot);
87}
Vladimir Oltean9c90eea2020-06-20 18:43:44 +030088EXPORT_SYMBOL(ocelot_mact_forget);
Alexandre Bellonia556c762018-05-14 22:04:57 +020089
90static void ocelot_mact_init(struct ocelot *ocelot)
91{
92 /* Configure the learning mode entries attributes:
93 * - Do not copy the frame to the CPU extraction queues.
94 * - Use the vlan and mac_cpoy for dmac lookup.
95 */
96 ocelot_rmw(ocelot, 0,
97 ANA_AGENCTRL_LEARN_CPU_COPY | ANA_AGENCTRL_IGNORE_DMAC_FLAGS
98 | ANA_AGENCTRL_LEARN_FWD_KILL
99 | ANA_AGENCTRL_LEARN_IGNORE_VLAN,
100 ANA_AGENCTRL);
101
102 /* Clear the MAC table */
103 ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
104}
105
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200106static void ocelot_vcap_enable(struct ocelot *ocelot, int port)
Horatiu Vulturb5962292019-05-31 09:16:56 +0200107{
108 ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA |
109 ANA_PORT_VCAP_S2_CFG_S2_IP6_CFG(0xa),
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200110 ANA_PORT_VCAP_S2_CFG, port);
Xiaoliang Yang75944fd2020-10-02 15:02:23 +0300111
112 ocelot_write_gix(ocelot, ANA_PORT_VCAP_CFG_S1_ENA,
113 ANA_PORT_VCAP_CFG, port);
Xiaoliang Yang2f17c052020-10-02 15:02:24 +0300114
115 ocelot_rmw_gix(ocelot, REW_PORT_CFG_ES0_EN,
116 REW_PORT_CFG_ES0_EN,
117 REW_PORT_CFG, port);
Horatiu Vulturb5962292019-05-31 09:16:56 +0200118}
119
Steen Hegelund639c1b22018-12-20 14:16:31 +0100120static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot)
121{
122 return ocelot_read(ocelot, ANA_TABLES_VLANACCESS);
123}
124
Alexandre Bellonia556c762018-05-14 22:04:57 +0200125static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot)
126{
Steen Hegelund639c1b22018-12-20 14:16:31 +0100127 u32 val;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200128
Steen Hegelund639c1b22018-12-20 14:16:31 +0100129 return readx_poll_timeout(ocelot_vlant_read_vlanaccess,
130 ocelot,
131 val,
132 (val & ANA_TABLES_VLANACCESS_VLAN_TBL_CMD_M) ==
133 ANA_TABLES_VLANACCESS_CMD_IDLE,
134 TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200135}
136
Antoine Tenart71425292018-06-26 14:28:49 +0200137static int ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask)
138{
139 /* Select the VID to configure */
140 ocelot_write(ocelot, ANA_TABLES_VLANTIDX_V_INDEX(vid),
141 ANA_TABLES_VLANTIDX);
142 /* Set the vlan port members mask and issue a write command */
143 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_VLAN_PORT_MASK(mask) |
144 ANA_TABLES_VLANACCESS_CMD_WRITE,
145 ANA_TABLES_VLANACCESS);
146
147 return ocelot_vlant_wait_for_completion(ocelot);
148}
149
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200150static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
151 u16 vid)
152{
153 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300154 u32 val = 0;
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200155
156 if (ocelot_port->vid != vid) {
157 /* Always permit deleting the native VLAN (vid = 0) */
158 if (ocelot_port->vid && vid) {
159 dev_err(ocelot->dev,
160 "Port already has a native VLAN: %d\n",
161 ocelot_port->vid);
162 return -EBUSY;
163 }
164 ocelot_port->vid = vid;
165 }
166
167 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid),
Antoine Tenart71425292018-06-26 14:28:49 +0200168 REW_PORT_VLAN_CFG_PORT_VID_M,
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200169 REW_PORT_VLAN_CFG, port);
170
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300171 if (ocelot_port->vlan_aware && !ocelot_port->vid)
172 /* If port is vlan-aware and tagged, drop untagged and priority
173 * tagged frames.
174 */
175 val = ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
176 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
177 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
178 ocelot_rmw_gix(ocelot, val,
179 ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
180 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
181 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA,
182 ANA_PORT_DROP_CFG, port);
183
184 if (ocelot_port->vlan_aware) {
185 if (ocelot_port->vid)
186 /* Tag all frames except when VID == DEFAULT_VLAN */
187 val = REW_TAG_CFG_TAG_CFG(1);
188 else
189 /* Tag all frames */
190 val = REW_TAG_CFG_TAG_CFG(3);
191 } else {
192 /* Port tagging disabled. */
193 val = REW_TAG_CFG_TAG_CFG(0);
194 }
195 ocelot_rmw_gix(ocelot, val,
196 REW_TAG_CFG_TAG_CFG_M,
197 REW_TAG_CFG, port);
198
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200199 return 0;
200}
201
Vladimir Oltean2e554a72020-10-03 01:06:46 +0300202int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
203 bool vlan_aware, struct switchdev_trans *trans)
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300204{
205 struct ocelot_port *ocelot_port = ocelot->ports[port];
206 u32 val;
207
Vladimir Oltean70edfae2020-10-08 14:56:58 +0300208 if (switchdev_trans_ph_prepare(trans)) {
209 struct ocelot_vcap_block *block = &ocelot->block[VCAP_IS1];
210 struct ocelot_vcap_filter *filter;
211
212 list_for_each_entry(filter, &block->rules, list) {
213 if (filter->ingress_port_mask & BIT(port) &&
214 filter->action.vid_replace_ena) {
215 dev_err(ocelot->dev,
216 "Cannot change VLAN state with vlan modify rules active\n");
217 return -EBUSY;
218 }
219 }
220
Vladimir Oltean2e554a72020-10-03 01:06:46 +0300221 return 0;
Vladimir Oltean70edfae2020-10-08 14:56:58 +0300222 }
Vladimir Oltean2e554a72020-10-03 01:06:46 +0300223
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300224 ocelot_port->vlan_aware = vlan_aware;
225
226 if (vlan_aware)
227 val = ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
228 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
229 else
230 val = 0;
231 ocelot_rmw_gix(ocelot, val,
232 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
233 ANA_PORT_VLAN_CFG_VLAN_POP_CNT_M,
234 ANA_PORT_VLAN_CFG, port);
235
236 ocelot_port_set_native_vlan(ocelot, port, ocelot_port->vid);
Vladimir Oltean2e554a72020-10-03 01:06:46 +0300237
238 return 0;
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300239}
240EXPORT_SYMBOL(ocelot_port_vlan_filtering);
241
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200242/* Default vlan to clasify for untagged frames (may be zero) */
243static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, u16 pvid)
244{
245 struct ocelot_port *ocelot_port = ocelot->ports[port];
246
247 ocelot_rmw_gix(ocelot,
248 ANA_PORT_VLAN_CFG_VLAN_VID(pvid),
249 ANA_PORT_VLAN_CFG_VLAN_VID_M,
250 ANA_PORT_VLAN_CFG, port);
251
252 ocelot_port->pvid = pvid;
Antoine Tenart71425292018-06-26 14:28:49 +0200253}
254
Vladimir Oltean5e256362019-11-14 17:03:27 +0200255int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
256 bool untagged)
Antoine Tenart71425292018-06-26 14:28:49 +0200257{
Antoine Tenart71425292018-06-26 14:28:49 +0200258 int ret;
259
Antoine Tenart71425292018-06-26 14:28:49 +0200260 /* Make the port a member of the VLAN */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200261 ocelot->vlan_mask[vid] |= BIT(port);
Antoine Tenart71425292018-06-26 14:28:49 +0200262 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
263 if (ret)
264 return ret;
265
266 /* Default ingress vlan classification */
267 if (pvid)
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200268 ocelot_port_set_pvid(ocelot, port, vid);
Antoine Tenart71425292018-06-26 14:28:49 +0200269
270 /* Untagged egress vlan clasification */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200271 if (untagged) {
272 ret = ocelot_port_set_native_vlan(ocelot, port, vid);
273 if (ret)
274 return ret;
Vladimir Olteanb9cd75e2019-10-26 21:04:27 +0300275 }
Antoine Tenart71425292018-06-26 14:28:49 +0200276
Antoine Tenart71425292018-06-26 14:28:49 +0200277 return 0;
278}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200279EXPORT_SYMBOL(ocelot_vlan_add);
Antoine Tenart71425292018-06-26 14:28:49 +0200280
Vladimir Oltean5e256362019-11-14 17:03:27 +0200281int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
Vladimir Oltean98559342019-11-09 15:02:48 +0200282{
283 struct ocelot_port *ocelot_port = ocelot->ports[port];
284 int ret;
Antoine Tenart71425292018-06-26 14:28:49 +0200285
286 /* Stop the port from being a member of the vlan */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200287 ocelot->vlan_mask[vid] &= ~BIT(port);
Antoine Tenart71425292018-06-26 14:28:49 +0200288 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
289 if (ret)
290 return ret;
291
292 /* Ingress */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200293 if (ocelot_port->pvid == vid)
294 ocelot_port_set_pvid(ocelot, port, 0);
Antoine Tenart71425292018-06-26 14:28:49 +0200295
296 /* Egress */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200297 if (ocelot_port->vid == vid)
298 ocelot_port_set_native_vlan(ocelot, port, 0);
Antoine Tenart71425292018-06-26 14:28:49 +0200299
300 return 0;
301}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200302EXPORT_SYMBOL(ocelot_vlan_del);
Antoine Tenart71425292018-06-26 14:28:49 +0200303
Alexandre Bellonia556c762018-05-14 22:04:57 +0200304static void ocelot_vlan_init(struct ocelot *ocelot)
305{
Antoine Tenart71425292018-06-26 14:28:49 +0200306 u16 port, vid;
307
Alexandre Bellonia556c762018-05-14 22:04:57 +0200308 /* Clear VLAN table, by default all ports are members of all VLANs */
309 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_CMD_INIT,
310 ANA_TABLES_VLANACCESS);
311 ocelot_vlant_wait_for_completion(ocelot);
Antoine Tenart71425292018-06-26 14:28:49 +0200312
313 /* Configure the port VLAN memberships */
314 for (vid = 1; vid < VLAN_N_VID; vid++) {
315 ocelot->vlan_mask[vid] = 0;
316 ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
317 }
318
319 /* Because VLAN filtering is enabled, we need VID 0 to get untagged
320 * traffic. It is added automatically if 8021q module is loaded, but
321 * we can't rely on it since module may be not loaded.
322 */
323 ocelot->vlan_mask[0] = GENMASK(ocelot->num_phys_ports - 1, 0);
324 ocelot_vlant_set_mask(ocelot, 0, ocelot->vlan_mask[0]);
325
Antoine Tenart71425292018-06-26 14:28:49 +0200326 /* Set vlan ingress filter mask to all ports but the CPU port by
327 * default.
328 */
Vladimir Oltean714d0ff2019-11-09 15:02:55 +0200329 ocelot_write(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
330 ANA_VLANMASK);
Antoine Tenart71425292018-06-26 14:28:49 +0200331
332 for (port = 0; port < ocelot->num_phys_ports; port++) {
333 ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port);
334 ocelot_write_gix(ocelot, 0, REW_TAG_CFG, port);
335 }
Alexandre Bellonia556c762018-05-14 22:04:57 +0200336}
337
Vladimir Oltean5e256362019-11-14 17:03:27 +0200338void ocelot_adjust_link(struct ocelot *ocelot, int port,
339 struct phy_device *phydev)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200340{
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200341 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +0200342 int speed, mode = 0;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200343
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200344 switch (phydev->speed) {
Alexandre Bellonia556c762018-05-14 22:04:57 +0200345 case SPEED_10:
346 speed = OCELOT_SPEED_10;
347 break;
348 case SPEED_100:
349 speed = OCELOT_SPEED_100;
350 break;
351 case SPEED_1000:
352 speed = OCELOT_SPEED_1000;
353 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
354 break;
355 case SPEED_2500:
356 speed = OCELOT_SPEED_2500;
357 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
358 break;
359 default:
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200360 dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n",
361 port, phydev->speed);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200362 return;
363 }
364
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200365 phy_print_status(phydev);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200366
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200367 if (!phydev->link)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200368 return;
369
370 /* Only full duplex supported for now */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200371 ocelot_port_writel(ocelot_port, DEV_MAC_MODE_CFG_FDX_ENA |
Alexandre Bellonia556c762018-05-14 22:04:57 +0200372 mode, DEV_MAC_MODE_CFG);
373
Vladimir Oltean1ba8f652020-02-29 16:31:11 +0200374 /* Disable HDX fast control */
375 ocelot_port_writel(ocelot_port, DEV_PORT_MISC_HDX_FAST_DIS,
376 DEV_PORT_MISC);
377
378 /* SGMII only for now */
379 ocelot_port_writel(ocelot_port, PCS1G_MODE_CFG_SGMII_MODE_ENA,
380 PCS1G_MODE_CFG);
381 ocelot_port_writel(ocelot_port, PCS1G_SD_CFG_SD_SEL, PCS1G_SD_CFG);
382
383 /* Enable PCS */
384 ocelot_port_writel(ocelot_port, PCS1G_CFG_PCS_ENA, PCS1G_CFG);
385
386 /* No aneg on SGMII */
387 ocelot_port_writel(ocelot_port, 0, PCS1G_ANEG_CFG);
388
389 /* No loopback */
390 ocelot_port_writel(ocelot_port, 0, PCS1G_LB_CFG);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200391
Alexandre Bellonia556c762018-05-14 22:04:57 +0200392 /* Enable MAC module */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200393 ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
Alexandre Bellonia556c762018-05-14 22:04:57 +0200394 DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
395
396 /* Take MAC, Port, Phy (intern) and PCS (SGMII/Serdes) clock out of
397 * reset */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200398 ocelot_port_writel(ocelot_port, DEV_CLOCK_CFG_LINK_SPEED(speed),
Alexandre Bellonia556c762018-05-14 22:04:57 +0200399 DEV_CLOCK_CFG);
400
Alexandre Bellonia556c762018-05-14 22:04:57 +0200401 /* No PFC */
402 ocelot_write_gix(ocelot, ANA_PFC_PFC_CFG_FC_LINK_SPEED(speed),
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200403 ANA_PFC_PFC_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200404
Alexandre Bellonia556c762018-05-14 22:04:57 +0200405 /* Core: Enable port for frame transfer */
Vladimir Oltean886e1382020-07-13 19:57:03 +0300406 ocelot_fields_write(ocelot, port,
407 QSYS_SWITCH_PORT_MODE_PORT_ENA, 1);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200408
409 /* Flow control */
410 ocelot_write_rix(ocelot, SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
411 SYS_MAC_FC_CFG_RX_FC_ENA | SYS_MAC_FC_CFG_TX_FC_ENA |
412 SYS_MAC_FC_CFG_ZERO_PAUSE_ENA |
413 SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
414 SYS_MAC_FC_CFG_FC_LINK_SPEED(speed),
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200415 SYS_MAC_FC_CFG, port);
416 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200417}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200418EXPORT_SYMBOL(ocelot_adjust_link);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200419
Vladimir Oltean5e256362019-11-14 17:03:27 +0200420void ocelot_port_enable(struct ocelot *ocelot, int port,
421 struct phy_device *phy)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200422{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200423 /* Enable receiving frames on the port, and activate auto-learning of
424 * MAC addresses.
425 */
426 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO |
427 ANA_PORT_PORT_CFG_RECV_ENA |
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200428 ANA_PORT_PORT_CFG_PORTID_VAL(port),
429 ANA_PORT_PORT_CFG, port);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200430}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200431EXPORT_SYMBOL(ocelot_port_enable);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200432
Vladimir Oltean5e256362019-11-14 17:03:27 +0200433void ocelot_port_disable(struct ocelot *ocelot, int port)
Vladimir Oltean889b8952019-11-09 15:02:57 +0200434{
435 struct ocelot_port *ocelot_port = ocelot->ports[port];
436
437 ocelot_port_writel(ocelot_port, 0, DEV_MAC_ENA_CFG);
Vladimir Oltean886e1382020-07-13 19:57:03 +0300438 ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200439}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200440EXPORT_SYMBOL(ocelot_port_disable);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200441
Vladimir Olteane2f9a8f2020-09-23 14:24:20 +0300442void ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port,
443 struct sk_buff *clone)
Yangbo Lu400928b2019-11-20 16:23:16 +0800444{
Vladimir Olteane2f9a8f2020-09-23 14:24:20 +0300445 struct ocelot_port *ocelot_port = ocelot->ports[port];
Yangbo Lu400928b2019-11-20 16:23:16 +0800446
Vladimir Olteane2f9a8f2020-09-23 14:24:20 +0300447 spin_lock(&ocelot_port->ts_id_lock);
Vladimir Oltean65652432020-09-18 04:07:24 +0300448
Vladimir Olteane2f9a8f2020-09-23 14:24:20 +0300449 skb_shinfo(clone)->tx_flags |= SKBTX_IN_PROGRESS;
450 /* Store timestamp ID in cb[0] of sk_buff */
451 clone->cb[0] = ocelot_port->ts_id;
452 ocelot_port->ts_id = (ocelot_port->ts_id + 1) % 4;
453 skb_queue_tail(&ocelot_port->tx_skbs, clone);
Vladimir Oltean65652432020-09-18 04:07:24 +0300454
Vladimir Olteane2f9a8f2020-09-23 14:24:20 +0300455 spin_unlock(&ocelot_port->ts_id_lock);
Yangbo Lu400928b2019-11-20 16:23:16 +0800456}
457EXPORT_SYMBOL(ocelot_port_add_txtstamp_skb);
458
Yangbo Lue23a7b32019-11-20 16:23:15 +0800459static void ocelot_get_hwtimestamp(struct ocelot *ocelot,
460 struct timespec64 *ts)
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200461{
462 unsigned long flags;
463 u32 val;
464
465 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
466
467 /* Read current PTP time to get seconds */
468 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
469
470 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
471 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_SAVE);
472 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
473 ts->tv_sec = ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN);
474
475 /* Read packet HW timestamp from FIFO */
476 val = ocelot_read(ocelot, SYS_PTP_TXSTAMP);
477 ts->tv_nsec = SYS_PTP_TXSTAMP_PTP_TXSTAMP(val);
478
479 /* Sec has incremented since the ts was registered */
480 if ((ts->tv_sec & 0x1) != !!(val & SYS_PTP_TXSTAMP_PTP_TXSTAMP_SEC))
481 ts->tv_sec--;
482
483 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
484}
Yangbo Lue23a7b32019-11-20 16:23:15 +0800485
486void ocelot_get_txtstamp(struct ocelot *ocelot)
487{
488 int budget = OCELOT_PTP_QUEUE_SZ;
489
490 while (budget--) {
Yangbo Lub049da12019-11-27 15:27:57 +0800491 struct sk_buff *skb, *skb_tmp, *skb_match = NULL;
Yangbo Lue23a7b32019-11-20 16:23:15 +0800492 struct skb_shared_hwtstamps shhwtstamps;
Yangbo Lue23a7b32019-11-20 16:23:15 +0800493 struct ocelot_port *port;
494 struct timespec64 ts;
Yangbo Lub049da12019-11-27 15:27:57 +0800495 unsigned long flags;
Yangbo Lue23a7b32019-11-20 16:23:15 +0800496 u32 val, id, txport;
497
498 val = ocelot_read(ocelot, SYS_PTP_STATUS);
499
500 /* Check if a timestamp can be retrieved */
501 if (!(val & SYS_PTP_STATUS_PTP_MESS_VLD))
502 break;
503
504 WARN_ON(val & SYS_PTP_STATUS_PTP_OVFL);
505
506 /* Retrieve the ts ID and Tx port */
507 id = SYS_PTP_STATUS_PTP_MESS_ID_X(val);
508 txport = SYS_PTP_STATUS_PTP_MESS_TXPORT_X(val);
509
510 /* Retrieve its associated skb */
511 port = ocelot->ports[txport];
512
Yangbo Lub049da12019-11-27 15:27:57 +0800513 spin_lock_irqsave(&port->tx_skbs.lock, flags);
514
515 skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
516 if (skb->cb[0] != id)
Yangbo Lue23a7b32019-11-20 16:23:15 +0800517 continue;
Yangbo Lub049da12019-11-27 15:27:57 +0800518 __skb_unlink(skb, &port->tx_skbs);
519 skb_match = skb;
Yangbo Lufc62c092019-11-27 15:27:56 +0800520 break;
Yangbo Lue23a7b32019-11-20 16:23:15 +0800521 }
522
Yangbo Lub049da12019-11-27 15:27:57 +0800523 spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
524
laurent brando5fd82202020-07-27 18:26:14 +0800525 /* Get the h/w timestamp */
526 ocelot_get_hwtimestamp(ocelot, &ts);
Yangbo Lue23a7b32019-11-20 16:23:15 +0800527
Yangbo Lub049da12019-11-27 15:27:57 +0800528 if (unlikely(!skb_match))
Yangbo Lue23a7b32019-11-20 16:23:15 +0800529 continue;
530
Yangbo Lue23a7b32019-11-20 16:23:15 +0800531 /* Set the timestamp into the skb */
532 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
533 shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
Vladimir Olteane2f9a8f2020-09-23 14:24:20 +0300534 skb_complete_tx_timestamp(skb_match, &shhwtstamps);
laurent brando5fd82202020-07-27 18:26:14 +0800535
536 /* Next ts */
537 ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
Yangbo Lue23a7b32019-11-20 16:23:15 +0800538 }
539}
540EXPORT_SYMBOL(ocelot_get_txtstamp);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200541
Vladimir Oltean5e256362019-11-14 17:03:27 +0200542int ocelot_fdb_add(struct ocelot *ocelot, int port,
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300543 const unsigned char *addr, u16 vid)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200544{
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200545 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean471beb12020-06-21 14:46:00 +0300546 int pgid = port;
547
548 if (port == ocelot->npi)
549 pgid = PGID_CPU;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200550
Antoine Tenart71425292018-06-26 14:28:49 +0200551 if (!vid) {
Vladimir Oltean87b0f982020-04-14 22:36:15 +0300552 if (!ocelot_port->vlan_aware)
Antoine Tenart71425292018-06-26 14:28:49 +0200553 /* If the bridge is not VLAN aware and no VID was
554 * provided, set it to pvid to ensure the MAC entry
555 * matches incoming untagged packets
556 */
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200557 vid = ocelot_port->pvid;
Antoine Tenart71425292018-06-26 14:28:49 +0200558 else
559 /* If the bridge is VLAN aware a VID must be provided as
560 * otherwise the learnt entry wouldn't match any frame.
561 */
562 return -EINVAL;
563 }
564
Vladimir Oltean471beb12020-06-21 14:46:00 +0300565 return ocelot_mact_learn(ocelot, pgid, addr, vid, ENTRYTYPE_LOCKED);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200566}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200567EXPORT_SYMBOL(ocelot_fdb_add);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200568
Vladimir Oltean5e256362019-11-14 17:03:27 +0200569int ocelot_fdb_del(struct ocelot *ocelot, int port,
570 const unsigned char *addr, u16 vid)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200571{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200572 return ocelot_mact_forget(ocelot, addr, vid);
573}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200574EXPORT_SYMBOL(ocelot_fdb_del);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200575
Vladimir Oltean9c90eea2020-06-20 18:43:44 +0300576int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid,
577 bool is_static, void *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200578{
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200579 struct ocelot_dump_ctx *dump = data;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200580 u32 portid = NETLINK_CB(dump->cb->skb).portid;
581 u32 seq = dump->cb->nlh->nlmsg_seq;
582 struct nlmsghdr *nlh;
583 struct ndmsg *ndm;
584
585 if (dump->idx < dump->cb->args[2])
586 goto skip;
587
588 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
589 sizeof(*ndm), NLM_F_MULTI);
590 if (!nlh)
591 return -EMSGSIZE;
592
593 ndm = nlmsg_data(nlh);
594 ndm->ndm_family = AF_BRIDGE;
595 ndm->ndm_pad1 = 0;
596 ndm->ndm_pad2 = 0;
597 ndm->ndm_flags = NTF_SELF;
598 ndm->ndm_type = 0;
599 ndm->ndm_ifindex = dump->dev->ifindex;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200600 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200601
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200602 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
Alexandre Bellonia556c762018-05-14 22:04:57 +0200603 goto nla_put_failure;
604
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200605 if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
Alexandre Bellonia556c762018-05-14 22:04:57 +0200606 goto nla_put_failure;
607
608 nlmsg_end(dump->skb, nlh);
609
610skip:
611 dump->idx++;
612 return 0;
613
614nla_put_failure:
615 nlmsg_cancel(dump->skb, nlh);
616 return -EMSGSIZE;
617}
Vladimir Oltean9c90eea2020-06-20 18:43:44 +0300618EXPORT_SYMBOL(ocelot_port_fdb_do_dump);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200619
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200620static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col,
621 struct ocelot_mact_entry *entry)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200622{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200623 u32 val, dst, macl, mach;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200624 char mac[ETH_ALEN];
Alexandre Bellonia556c762018-05-14 22:04:57 +0200625
626 /* Set row and column to read from */
627 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row);
628 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col);
629
630 /* Issue a read command */
631 ocelot_write(ocelot,
632 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ),
633 ANA_TABLES_MACACCESS);
634
635 if (ocelot_mact_wait_for_completion(ocelot))
636 return -ETIMEDOUT;
637
638 /* Read the entry flags */
639 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
640 if (!(val & ANA_TABLES_MACACCESS_VALID))
641 return -EINVAL;
642
643 /* If the entry read has another port configured as its destination,
644 * do not report it.
645 */
646 dst = (val & ANA_TABLES_MACACCESS_DEST_IDX_M) >> 3;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200647 if (dst != port)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200648 return -EINVAL;
649
650 /* Get the entry's MAC address and VLAN id */
651 macl = ocelot_read(ocelot, ANA_TABLES_MACLDATA);
652 mach = ocelot_read(ocelot, ANA_TABLES_MACHDATA);
653
654 mac[0] = (mach >> 8) & 0xff;
655 mac[1] = (mach >> 0) & 0xff;
656 mac[2] = (macl >> 24) & 0xff;
657 mac[3] = (macl >> 16) & 0xff;
658 mac[4] = (macl >> 8) & 0xff;
659 mac[5] = (macl >> 0) & 0xff;
660
661 entry->vid = (mach >> 16) & 0xfff;
662 ether_addr_copy(entry->mac, mac);
663
664 return 0;
665}
666
Vladimir Oltean5e256362019-11-14 17:03:27 +0200667int ocelot_fdb_dump(struct ocelot *ocelot, int port,
668 dsa_fdb_dump_cb_t *cb, void *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200669{
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200670 int i, j;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200671
Vladimir Oltean21ce7f32020-05-04 01:20:26 +0300672 /* Loop through all the mac tables entries. */
673 for (i = 0; i < ocelot->num_mact_rows; i++) {
Alexandre Bellonia556c762018-05-14 22:04:57 +0200674 for (j = 0; j < 4; j++) {
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200675 struct ocelot_mact_entry entry;
676 bool is_static;
677 int ret;
678
679 ret = ocelot_mact_read(ocelot, port, i, j, &entry);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200680 /* If the entry is invalid (wrong port, invalid...),
681 * skip it.
682 */
683 if (ret == -EINVAL)
684 continue;
685 else if (ret)
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200686 return ret;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200687
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200688 is_static = (entry.type == ENTRYTYPE_LOCKED);
689
690 ret = cb(entry.mac, entry.vid, is_static, data);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200691 if (ret)
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200692 return ret;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200693 }
694 }
695
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200696 return 0;
697}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200698EXPORT_SYMBOL(ocelot_fdb_dump);
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200699
Yangbo Luf1459222019-11-20 16:23:14 +0800700int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr)
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200701{
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200702 return copy_to_user(ifr->ifr_data, &ocelot->hwtstamp_config,
703 sizeof(ocelot->hwtstamp_config)) ? -EFAULT : 0;
704}
Yangbo Luf1459222019-11-20 16:23:14 +0800705EXPORT_SYMBOL(ocelot_hwstamp_get);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200706
Yangbo Luf1459222019-11-20 16:23:14 +0800707int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200708{
Vladimir Oltean306fd442019-11-09 15:02:50 +0200709 struct ocelot_port *ocelot_port = ocelot->ports[port];
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200710 struct hwtstamp_config cfg;
711
712 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
713 return -EFAULT;
714
715 /* reserved for future extensions */
716 if (cfg.flags)
717 return -EINVAL;
718
719 /* Tx type sanity check */
720 switch (cfg.tx_type) {
721 case HWTSTAMP_TX_ON:
Vladimir Oltean306fd442019-11-09 15:02:50 +0200722 ocelot_port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP;
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200723 break;
724 case HWTSTAMP_TX_ONESTEP_SYNC:
725 /* IFH_REW_OP_ONE_STEP_PTP updates the correctional field, we
726 * need to update the origin time.
727 */
Vladimir Oltean306fd442019-11-09 15:02:50 +0200728 ocelot_port->ptp_cmd = IFH_REW_OP_ORIGIN_PTP;
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200729 break;
730 case HWTSTAMP_TX_OFF:
Vladimir Oltean306fd442019-11-09 15:02:50 +0200731 ocelot_port->ptp_cmd = 0;
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200732 break;
733 default:
734 return -ERANGE;
735 }
736
737 mutex_lock(&ocelot->ptp_lock);
738
739 switch (cfg.rx_filter) {
740 case HWTSTAMP_FILTER_NONE:
741 break;
742 case HWTSTAMP_FILTER_ALL:
743 case HWTSTAMP_FILTER_SOME:
744 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
745 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
746 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
747 case HWTSTAMP_FILTER_NTP_ALL:
748 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
749 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
750 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
751 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
752 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
753 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
754 case HWTSTAMP_FILTER_PTP_V2_EVENT:
755 case HWTSTAMP_FILTER_PTP_V2_SYNC:
756 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
757 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
758 break;
759 default:
760 mutex_unlock(&ocelot->ptp_lock);
761 return -ERANGE;
762 }
763
764 /* Commit back the result & save it */
765 memcpy(&ocelot->hwtstamp_config, &cfg, sizeof(cfg));
766 mutex_unlock(&ocelot->ptp_lock);
767
768 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
769}
Yangbo Luf1459222019-11-20 16:23:14 +0800770EXPORT_SYMBOL(ocelot_hwstamp_set);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200771
Vladimir Oltean5e256362019-11-14 17:03:27 +0200772void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200773{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200774 int i;
775
776 if (sset != ETH_SS_STATS)
777 return;
778
779 for (i = 0; i < ocelot->num_stats; i++)
780 memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name,
781 ETH_GSTRING_LEN);
782}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200783EXPORT_SYMBOL(ocelot_get_strings);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200784
Claudiu Manoil1e1caa92019-04-16 17:51:59 +0300785static void ocelot_update_stats(struct ocelot *ocelot)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200786{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200787 int i, j;
788
789 mutex_lock(&ocelot->stats_lock);
790
791 for (i = 0; i < ocelot->num_phys_ports; i++) {
792 /* Configure the port to read the stats from */
793 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG);
794
795 for (j = 0; j < ocelot->num_stats; j++) {
796 u32 val;
797 unsigned int idx = i * ocelot->num_stats + j;
798
799 val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS,
800 ocelot->stats_layout[j].offset);
801
802 if (val < (ocelot->stats[idx] & U32_MAX))
803 ocelot->stats[idx] += (u64)1 << 32;
804
805 ocelot->stats[idx] = (ocelot->stats[idx] &
806 ~(u64)U32_MAX) + val;
807 }
808 }
809
Claudiu Manoil1e1caa92019-04-16 17:51:59 +0300810 mutex_unlock(&ocelot->stats_lock);
811}
812
813static void ocelot_check_stats_work(struct work_struct *work)
814{
815 struct delayed_work *del_work = to_delayed_work(work);
816 struct ocelot *ocelot = container_of(del_work, struct ocelot,
817 stats_work);
818
819 ocelot_update_stats(ocelot);
820
Alexandre Bellonia556c762018-05-14 22:04:57 +0200821 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
822 OCELOT_STATS_CHECK_DELAY);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200823}
824
Vladimir Oltean5e256362019-11-14 17:03:27 +0200825void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200826{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200827 int i;
828
829 /* check and update now */
Claudiu Manoil1e1caa92019-04-16 17:51:59 +0300830 ocelot_update_stats(ocelot);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200831
832 /* Copy all counters */
833 for (i = 0; i < ocelot->num_stats; i++)
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200834 *data++ = ocelot->stats[port * ocelot->num_stats + i];
Alexandre Bellonia556c762018-05-14 22:04:57 +0200835}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200836EXPORT_SYMBOL(ocelot_get_ethtool_stats);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200837
Vladimir Oltean5e256362019-11-14 17:03:27 +0200838int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
Vladimir Olteanc7282d32019-11-09 15:02:54 +0200839{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200840 if (sset != ETH_SS_STATS)
841 return -EOPNOTSUPP;
Vladimir Olteanc7282d32019-11-09 15:02:54 +0200842
Alexandre Bellonia556c762018-05-14 22:04:57 +0200843 return ocelot->num_stats;
844}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200845EXPORT_SYMBOL(ocelot_get_sset_count);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200846
Vladimir Oltean5e256362019-11-14 17:03:27 +0200847int ocelot_get_ts_info(struct ocelot *ocelot, int port,
848 struct ethtool_ts_info *info)
Vladimir Olteanc7282d32019-11-09 15:02:54 +0200849{
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200850 info->phc_index = ocelot->ptp_clock ?
851 ptp_clock_index(ocelot->ptp_clock) : -1;
Yangbo Lud2b09a82020-04-20 10:46:46 +0800852 if (info->phc_index == -1) {
853 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
854 SOF_TIMESTAMPING_RX_SOFTWARE |
855 SOF_TIMESTAMPING_SOFTWARE;
856 return 0;
857 }
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200858 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
859 SOF_TIMESTAMPING_RX_SOFTWARE |
860 SOF_TIMESTAMPING_SOFTWARE |
861 SOF_TIMESTAMPING_TX_HARDWARE |
862 SOF_TIMESTAMPING_RX_HARDWARE |
863 SOF_TIMESTAMPING_RAW_HARDWARE;
864 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON) |
865 BIT(HWTSTAMP_TX_ONESTEP_SYNC);
866 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
867
868 return 0;
869}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200870EXPORT_SYMBOL(ocelot_get_ts_info);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200871
Vladimir Oltean5e256362019-11-14 17:03:27 +0200872void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200873{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200874 u32 port_cfg;
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200875 int p, i;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200876
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200877 if (!(BIT(port) & ocelot->bridge_mask))
878 return;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200879
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200880 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200881
882 switch (state) {
883 case BR_STATE_FORWARDING:
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200884 ocelot->bridge_fwd_mask |= BIT(port);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500885 fallthrough;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200886 case BR_STATE_LEARNING:
887 port_cfg |= ANA_PORT_PORT_CFG_LEARN_ENA;
888 break;
889
890 default:
891 port_cfg &= ~ANA_PORT_PORT_CFG_LEARN_ENA;
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200892 ocelot->bridge_fwd_mask &= ~BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200893 break;
894 }
895
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200896 ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200897
898 /* Apply FWD mask. The loop is needed to add/remove the current port as
899 * a source for the other ports.
900 */
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200901 for (p = 0; p < ocelot->num_phys_ports; p++) {
Vladimir Oltean69df5782020-02-29 16:50:02 +0200902 if (ocelot->bridge_fwd_mask & BIT(p)) {
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200903 unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200904
905 for (i = 0; i < ocelot->num_phys_ports; i++) {
906 unsigned long bond_mask = ocelot->lags[i];
907
908 if (!bond_mask)
909 continue;
910
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200911 if (bond_mask & BIT(p)) {
Alexandre Bellonia556c762018-05-14 22:04:57 +0200912 mask &= ~bond_mask;
913 break;
914 }
915 }
916
Vladimir Olteanc9d22032019-11-09 15:03:01 +0200917 ocelot_write_rix(ocelot, mask,
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200918 ANA_PGID_PGID, PGID_SRC + p);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200919 } else {
Vladimir Oltean69df5782020-02-29 16:50:02 +0200920 ocelot_write_rix(ocelot, 0,
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200921 ANA_PGID_PGID, PGID_SRC + p);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200922 }
923 }
Alexandre Bellonia556c762018-05-14 22:04:57 +0200924}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200925EXPORT_SYMBOL(ocelot_bridge_stp_state_set);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200926
Vladimir Oltean5e256362019-11-14 17:03:27 +0200927void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs)
Vladimir Oltean4bda1412019-11-09 15:02:51 +0200928{
Vladimir Olteanc0d7ecc2020-05-04 01:20:27 +0300929 unsigned int age_period = ANA_AUTOAGE_AGE_PERIOD(msecs / 2000);
930
931 /* Setting AGE_PERIOD to zero effectively disables automatic aging,
932 * which is clearly not what our intention is. So avoid that.
933 */
934 if (!age_period)
935 age_period = 1;
936
937 ocelot_rmw(ocelot, age_period, ANA_AUTOAGE_AGE_PERIOD_M, ANA_AUTOAGE);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200938}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200939EXPORT_SYMBOL(ocelot_set_ageing_time);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200940
Alexandre Bellonia556c762018-05-14 22:04:57 +0200941static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot,
942 const unsigned char *addr,
943 u16 vid)
944{
945 struct ocelot_multicast *mc;
946
947 list_for_each_entry(mc, &ocelot->multicast, list) {
948 if (ether_addr_equal(mc->addr, addr) && mc->vid == vid)
949 return mc;
950 }
951
952 return NULL;
953}
954
Vladimir Oltean9403c152020-06-21 14:46:03 +0300955static enum macaccess_entry_type ocelot_classify_mdb(const unsigned char *addr)
956{
957 if (addr[0] == 0x01 && addr[1] == 0x00 && addr[2] == 0x5e)
958 return ENTRYTYPE_MACv4;
959 if (addr[0] == 0x33 && addr[1] == 0x33)
960 return ENTRYTYPE_MACv6;
961 return ENTRYTYPE_NORMAL;
962}
963
964static int ocelot_mdb_get_pgid(struct ocelot *ocelot,
965 enum macaccess_entry_type entry_type)
966{
967 int pgid;
968
969 /* According to VSC7514 datasheet 3.9.1.5 IPv4 Multicast Entries and
970 * 3.9.1.6 IPv6 Multicast Entries, "Instead of a lookup in the
971 * destination mask table (PGID), the destination set is programmed as
972 * part of the entry MAC address.", and the DEST_IDX is set to 0.
973 */
974 if (entry_type == ENTRYTYPE_MACv4 ||
975 entry_type == ENTRYTYPE_MACv6)
976 return 0;
977
978 for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) {
979 struct ocelot_multicast *mc;
980 bool used = false;
981
982 list_for_each_entry(mc, &ocelot->multicast, list) {
983 if (mc->pgid == pgid) {
984 used = true;
985 break;
986 }
987 }
988
989 if (!used)
990 return pgid;
991 }
992
993 return -1;
994}
995
996static void ocelot_encode_ports_to_mdb(unsigned char *addr,
997 struct ocelot_multicast *mc,
998 enum macaccess_entry_type entry_type)
999{
1000 memcpy(addr, mc->addr, ETH_ALEN);
1001
1002 if (entry_type == ENTRYTYPE_MACv4) {
1003 addr[0] = 0;
1004 addr[1] = mc->ports >> 8;
1005 addr[2] = mc->ports & 0xff;
1006 } else if (entry_type == ENTRYTYPE_MACv6) {
1007 addr[0] = mc->ports >> 8;
1008 addr[1] = mc->ports & 0xff;
1009 }
1010}
1011
Vladimir Oltean209edf92020-06-21 14:46:01 +03001012int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
1013 const struct switchdev_obj_port_mdb *mdb)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001014{
Vladimir Oltean209edf92020-06-21 14:46:01 +03001015 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean9403c152020-06-21 14:46:03 +03001016 enum macaccess_entry_type entry_type;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001017 unsigned char addr[ETH_ALEN];
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001018 struct ocelot_multicast *mc;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001019 u16 vid = mdb->vid;
1020 bool new = false;
1021
Vladimir Oltean471beb12020-06-21 14:46:00 +03001022 if (port == ocelot->npi)
1023 port = ocelot->num_phys_ports;
1024
Alexandre Bellonia556c762018-05-14 22:04:57 +02001025 if (!vid)
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001026 vid = ocelot_port->pvid;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001027
Vladimir Oltean9403c152020-06-21 14:46:03 +03001028 entry_type = ocelot_classify_mdb(mdb->addr);
1029
Alexandre Bellonia556c762018-05-14 22:04:57 +02001030 mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
1031 if (!mc) {
Vladimir Oltean9403c152020-06-21 14:46:03 +03001032 int pgid = ocelot_mdb_get_pgid(ocelot, entry_type);
1033
1034 if (pgid < 0) {
1035 dev_err(ocelot->dev,
1036 "No more PGIDs available for mdb %pM vid %d\n",
1037 mdb->addr, vid);
1038 return -ENOSPC;
1039 }
1040
Alexandre Bellonia556c762018-05-14 22:04:57 +02001041 mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL);
1042 if (!mc)
1043 return -ENOMEM;
1044
1045 memcpy(mc->addr, mdb->addr, ETH_ALEN);
1046 mc->vid = vid;
Vladimir Oltean9403c152020-06-21 14:46:03 +03001047 mc->pgid = pgid;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001048
1049 list_add_tail(&mc->list, &ocelot->multicast);
1050 new = true;
1051 }
1052
Alexandre Bellonia556c762018-05-14 22:04:57 +02001053 if (!new) {
Vladimir Oltean9403c152020-06-21 14:46:03 +03001054 ocelot_encode_ports_to_mdb(addr, mc, entry_type);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001055 ocelot_mact_forget(ocelot, addr, vid);
1056 }
1057
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001058 mc->ports |= BIT(port);
Vladimir Oltean9403c152020-06-21 14:46:03 +03001059 ocelot_encode_ports_to_mdb(addr, mc, entry_type);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001060
Vladimir Oltean9403c152020-06-21 14:46:03 +03001061 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001062}
Vladimir Oltean209edf92020-06-21 14:46:01 +03001063EXPORT_SYMBOL(ocelot_port_mdb_add);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001064
Vladimir Oltean209edf92020-06-21 14:46:01 +03001065int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
1066 const struct switchdev_obj_port_mdb *mdb)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001067{
Vladimir Oltean209edf92020-06-21 14:46:01 +03001068 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean9403c152020-06-21 14:46:03 +03001069 enum macaccess_entry_type entry_type;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001070 unsigned char addr[ETH_ALEN];
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001071 struct ocelot_multicast *mc;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001072 u16 vid = mdb->vid;
1073
Vladimir Oltean471beb12020-06-21 14:46:00 +03001074 if (port == ocelot->npi)
1075 port = ocelot->num_phys_ports;
1076
Alexandre Bellonia556c762018-05-14 22:04:57 +02001077 if (!vid)
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001078 vid = ocelot_port->pvid;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001079
1080 mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
1081 if (!mc)
1082 return -ENOENT;
1083
Vladimir Oltean9403c152020-06-21 14:46:03 +03001084 entry_type = ocelot_classify_mdb(mdb->addr);
1085
1086 ocelot_encode_ports_to_mdb(addr, mc, entry_type);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001087 ocelot_mact_forget(ocelot, addr, vid);
1088
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001089 mc->ports &= ~BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001090 if (!mc->ports) {
1091 list_del(&mc->list);
1092 devm_kfree(ocelot->dev, mc);
1093 return 0;
1094 }
1095
Vladimir Oltean9403c152020-06-21 14:46:03 +03001096 ocelot_encode_ports_to_mdb(addr, mc, entry_type);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001097
Vladimir Oltean9403c152020-06-21 14:46:03 +03001098 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001099}
Vladimir Oltean209edf92020-06-21 14:46:01 +03001100EXPORT_SYMBOL(ocelot_port_mdb_del);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001101
Vladimir Oltean5e256362019-11-14 17:03:27 +02001102int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
1103 struct net_device *bridge)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001104{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001105 if (!ocelot->bridge_mask) {
1106 ocelot->hw_bridge_dev = bridge;
1107 } else {
1108 if (ocelot->hw_bridge_dev != bridge)
1109 /* This is adding the port to a second bridge, this is
1110 * unsupported */
1111 return -ENODEV;
1112 }
1113
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001114 ocelot->bridge_mask |= BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001115
1116 return 0;
1117}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001118EXPORT_SYMBOL(ocelot_port_bridge_join);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001119
Vladimir Oltean5e256362019-11-14 17:03:27 +02001120int ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
1121 struct net_device *bridge)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001122{
Vladimir Oltean2e554a72020-10-03 01:06:46 +03001123 struct switchdev_trans trans;
1124 int ret;
1125
Vladimir Oltean97bb69e2019-11-09 15:02:47 +02001126 ocelot->bridge_mask &= ~BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001127
1128 if (!ocelot->bridge_mask)
1129 ocelot->hw_bridge_dev = NULL;
Antoine Tenart71425292018-06-26 14:28:49 +02001130
Vladimir Oltean2e554a72020-10-03 01:06:46 +03001131 trans.ph_prepare = true;
1132 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans);
1133 if (ret)
1134 return ret;
1135
1136 trans.ph_prepare = false;
1137 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans);
1138 if (ret)
1139 return ret;
1140
Vladimir Oltean97bb69e2019-11-09 15:02:47 +02001141 ocelot_port_set_pvid(ocelot, port, 0);
1142 return ocelot_port_set_native_vlan(ocelot, port, 0);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001143}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001144EXPORT_SYMBOL(ocelot_port_bridge_leave);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001145
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001146static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
1147{
1148 int i, port, lag;
1149
1150 /* Reset destination and aggregation PGIDS */
Vladimir Oltean96b029b2020-06-21 14:46:02 +03001151 for_each_unicast_dest_pgid(ocelot, port)
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001152 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
1153
Vladimir Oltean96b029b2020-06-21 14:46:02 +03001154 for_each_aggr_pgid(ocelot, i)
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001155 ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
1156 ANA_PGID_PGID, i);
1157
1158 /* Now, set PGIDs for each LAG */
1159 for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
1160 unsigned long bond_mask;
1161 int aggr_count = 0;
1162 u8 aggr_idx[16];
1163
1164 bond_mask = ocelot->lags[lag];
1165 if (!bond_mask)
1166 continue;
1167
1168 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
1169 // Destination mask
1170 ocelot_write_rix(ocelot, bond_mask,
1171 ANA_PGID_PGID, port);
1172 aggr_idx[aggr_count] = port;
1173 aggr_count++;
1174 }
1175
Vladimir Oltean96b029b2020-06-21 14:46:02 +03001176 for_each_aggr_pgid(ocelot, i) {
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001177 u32 ac;
1178
1179 ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
1180 ac &= ~bond_mask;
1181 ac |= BIT(aggr_idx[i % aggr_count]);
1182 ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i);
1183 }
1184 }
1185}
1186
1187static void ocelot_setup_lag(struct ocelot *ocelot, int lag)
1188{
1189 unsigned long bond_mask = ocelot->lags[lag];
1190 unsigned int p;
1191
1192 for_each_set_bit(p, &bond_mask, ocelot->num_phys_ports) {
1193 u32 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p);
1194
1195 port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M;
1196
1197 /* Use lag port as logical port for port i */
1198 ocelot_write_gix(ocelot, port_cfg |
1199 ANA_PORT_PORT_CFG_PORTID_VAL(lag),
1200 ANA_PORT_PORT_CFG, p);
1201 }
1202}
1203
Vladimir Oltean9c90eea2020-06-20 18:43:44 +03001204int ocelot_port_lag_join(struct ocelot *ocelot, int port,
1205 struct net_device *bond)
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001206{
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001207 struct net_device *ndev;
1208 u32 bond_mask = 0;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001209 int lag, lp;
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001210
1211 rcu_read_lock();
1212 for_each_netdev_in_bond_rcu(bond, ndev) {
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001213 struct ocelot_port_private *priv = netdev_priv(ndev);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001214
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001215 bond_mask |= BIT(priv->chip_port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001216 }
1217 rcu_read_unlock();
1218
1219 lp = __ffs(bond_mask);
1220
1221 /* If the new port is the lowest one, use it as the logical port from
1222 * now on
1223 */
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001224 if (port == lp) {
1225 lag = port;
1226 ocelot->lags[port] = bond_mask;
1227 bond_mask &= ~BIT(port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001228 if (bond_mask) {
1229 lp = __ffs(bond_mask);
1230 ocelot->lags[lp] = 0;
1231 }
1232 } else {
1233 lag = lp;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001234 ocelot->lags[lp] |= BIT(port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001235 }
1236
1237 ocelot_setup_lag(ocelot, lag);
1238 ocelot_set_aggr_pgids(ocelot);
1239
1240 return 0;
1241}
Vladimir Oltean9c90eea2020-06-20 18:43:44 +03001242EXPORT_SYMBOL(ocelot_port_lag_join);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001243
Vladimir Oltean9c90eea2020-06-20 18:43:44 +03001244void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
1245 struct net_device *bond)
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001246{
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001247 u32 port_cfg;
1248 int i;
1249
1250 /* Remove port from any lag */
1251 for (i = 0; i < ocelot->num_phys_ports; i++)
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001252 ocelot->lags[i] &= ~BIT(port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001253
1254 /* if it was the logical port of the lag, move the lag config to the
1255 * next port
1256 */
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001257 if (ocelot->lags[port]) {
1258 int n = __ffs(ocelot->lags[port]);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001259
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001260 ocelot->lags[n] = ocelot->lags[port];
1261 ocelot->lags[port] = 0;
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001262
1263 ocelot_setup_lag(ocelot, n);
1264 }
1265
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001266 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001267 port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001268 ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port),
1269 ANA_PORT_PORT_CFG, port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001270
1271 ocelot_set_aggr_pgids(ocelot);
1272}
Vladimir Oltean9c90eea2020-06-20 18:43:44 +03001273EXPORT_SYMBOL(ocelot_port_lag_leave);
Petr Machata0e332c82018-11-22 23:30:11 +00001274
Vladimir Olteana8015de2020-03-10 03:28:18 +02001275/* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu.
1276 * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG.
Vladimir Oltean0b912fc2020-03-27 21:55:47 +02001277 * In the special case that it's the NPI port that we're configuring, the
1278 * length of the tag and optional prefix needs to be accounted for privately,
1279 * in order to be able to sustain communication at the requested @sdu.
Vladimir Olteana8015de2020-03-10 03:28:18 +02001280 */
Vladimir Oltean0b912fc2020-03-27 21:55:47 +02001281void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu)
Vladimir Oltean31350d72019-11-09 15:02:56 +02001282{
1283 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Olteana8015de2020-03-10 03:28:18 +02001284 int maxlen = sdu + ETH_HLEN + ETH_FCS_LEN;
Vladimir Olteane8e6e732020-07-13 19:57:05 +03001285 int pause_start, pause_stop;
Vladimir Oltean601e9842020-10-05 12:09:11 +03001286 int atop, atop_tot;
Vladimir Oltean31350d72019-11-09 15:02:56 +02001287
Vladimir Oltean0b912fc2020-03-27 21:55:47 +02001288 if (port == ocelot->npi) {
1289 maxlen += OCELOT_TAG_LEN;
1290
1291 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT)
1292 maxlen += OCELOT_SHORT_PREFIX_LEN;
1293 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG)
1294 maxlen += OCELOT_LONG_PREFIX_LEN;
1295 }
1296
Vladimir Olteana8015de2020-03-10 03:28:18 +02001297 ocelot_port_writel(ocelot_port, maxlen, DEV_MAC_MAXLEN_CFG);
Vladimir Olteanfa914e92019-11-14 17:03:23 +02001298
Vladimir Olteane8e6e732020-07-13 19:57:05 +03001299 /* Set Pause watermark hysteresis */
1300 pause_start = 6 * maxlen / OCELOT_BUFFER_CELL_SZ;
1301 pause_stop = 4 * maxlen / OCELOT_BUFFER_CELL_SZ;
Maxim Kochetkov541132f2020-07-13 19:57:07 +03001302 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_START,
1303 pause_start);
1304 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_STOP,
1305 pause_stop);
Vladimir Olteanfa914e92019-11-14 17:03:23 +02001306
Vladimir Oltean601e9842020-10-05 12:09:11 +03001307 /* Tail dropping watermarks */
1308 atop_tot = (ocelot->shared_queue_sz - 9 * maxlen) /
Vladimir Olteana8015de2020-03-10 03:28:18 +02001309 OCELOT_BUFFER_CELL_SZ;
Vladimir Oltean601e9842020-10-05 12:09:11 +03001310 atop = (9 * maxlen) / OCELOT_BUFFER_CELL_SZ;
1311 ocelot_write_rix(ocelot, ocelot->ops->wm_enc(atop), SYS_ATOP, port);
1312 ocelot_write(ocelot, ocelot->ops->wm_enc(atop_tot), SYS_ATOP_TOT_CFG);
Vladimir Olteanfa914e92019-11-14 17:03:23 +02001313}
Vladimir Oltean0b912fc2020-03-27 21:55:47 +02001314EXPORT_SYMBOL(ocelot_port_set_maxlen);
1315
1316int ocelot_get_max_mtu(struct ocelot *ocelot, int port)
1317{
1318 int max_mtu = 65535 - ETH_HLEN - ETH_FCS_LEN;
1319
1320 if (port == ocelot->npi) {
1321 max_mtu -= OCELOT_TAG_LEN;
1322
1323 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT)
1324 max_mtu -= OCELOT_SHORT_PREFIX_LEN;
1325 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG)
1326 max_mtu -= OCELOT_LONG_PREFIX_LEN;
1327 }
1328
1329 return max_mtu;
1330}
1331EXPORT_SYMBOL(ocelot_get_max_mtu);
Vladimir Olteanfa914e92019-11-14 17:03:23 +02001332
Vladimir Oltean5e256362019-11-14 17:03:27 +02001333void ocelot_init_port(struct ocelot *ocelot, int port)
Vladimir Olteanfa914e92019-11-14 17:03:23 +02001334{
1335 struct ocelot_port *ocelot_port = ocelot->ports[port];
1336
Yangbo Lub049da12019-11-27 15:27:57 +08001337 skb_queue_head_init(&ocelot_port->tx_skbs);
Vladimir Oltean65652432020-09-18 04:07:24 +03001338 spin_lock_init(&ocelot_port->ts_id_lock);
Vladimir Oltean31350d72019-11-09 15:02:56 +02001339
1340 /* Basic L2 initialization */
1341
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +02001342 /* Set MAC IFG Gaps
1343 * FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 0
1344 * !FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 5
1345 */
1346 ocelot_port_writel(ocelot_port, DEV_MAC_IFG_CFG_TX_IFG(5),
1347 DEV_MAC_IFG_CFG);
1348
1349 /* Load seed (0) and set MAC HDX late collision */
1350 ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
1351 DEV_MAC_HDX_CFG_SEED_LOAD,
1352 DEV_MAC_HDX_CFG);
1353 mdelay(1);
1354 ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
1355 DEV_MAC_HDX_CFG);
1356
1357 /* Set Max Length and maximum tags allowed */
Vladimir Olteana8015de2020-03-10 03:28:18 +02001358 ocelot_port_set_maxlen(ocelot, port, ETH_DATA_LEN);
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +02001359 ocelot_port_writel(ocelot_port, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD) |
1360 DEV_MAC_TAGS_CFG_VLAN_AWR_ENA |
Vladimir Olteana8015de2020-03-10 03:28:18 +02001361 DEV_MAC_TAGS_CFG_VLAN_DBL_AWR_ENA |
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +02001362 DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA,
1363 DEV_MAC_TAGS_CFG);
1364
1365 /* Set SMAC of Pause frame (00:00:00:00:00:00) */
1366 ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_HIGH_CFG);
1367 ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_LOW_CFG);
1368
Vladimir Olteane8e6e732020-07-13 19:57:05 +03001369 /* Enable transmission of pause frames */
Maxim Kochetkov541132f2020-07-13 19:57:07 +03001370 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1);
Vladimir Olteane8e6e732020-07-13 19:57:05 +03001371
Vladimir Oltean31350d72019-11-09 15:02:56 +02001372 /* Drop frames with multicast source address */
1373 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
1374 ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
1375 ANA_PORT_DROP_CFG, port);
1376
1377 /* Set default VLAN and tag type to 8021Q. */
1378 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q),
1379 REW_PORT_VLAN_CFG_PORT_TPID_M,
1380 REW_PORT_VLAN_CFG, port);
1381
1382 /* Enable vcap lookups */
1383 ocelot_vcap_enable(ocelot, port);
1384}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001385EXPORT_SYMBOL(ocelot_init_port);
Vladimir Oltean31350d72019-11-09 15:02:56 +02001386
Vladimir Oltean2d44b092020-09-26 22:32:01 +03001387/* Configure and enable the CPU port module, which is a set of queues
1388 * accessible through register MMIO, frame DMA or Ethernet (in case
1389 * NPI mode is used).
Vladimir Oltean69df5782020-02-29 16:50:02 +02001390 */
Vladimir Oltean2d44b092020-09-26 22:32:01 +03001391static void ocelot_cpu_port_init(struct ocelot *ocelot)
Vladimir Oltean21468192019-11-09 15:03:00 +02001392{
Vladimir Oltean69df5782020-02-29 16:50:02 +02001393 int cpu = ocelot->num_phys_ports;
1394
1395 /* The unicast destination PGID for the CPU port module is unused */
Vladimir Oltean21468192019-11-09 15:03:00 +02001396 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu);
Vladimir Oltean69df5782020-02-29 16:50:02 +02001397 /* Instead set up a multicast destination PGID for traffic copied to
1398 * the CPU. Whitelisted MAC addresses like the port netdevice MAC
1399 * addresses will be copied to the CPU via this PGID.
1400 */
Vladimir Oltean21468192019-11-09 15:03:00 +02001401 ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU);
1402 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA |
1403 ANA_PORT_PORT_CFG_PORTID_VAL(cpu),
1404 ANA_PORT_PORT_CFG, cpu);
1405
Vladimir Oltean69df5782020-02-29 16:50:02 +02001406 /* Enable CPU port module */
Vladimir Oltean886e1382020-07-13 19:57:03 +03001407 ocelot_fields_write(ocelot, cpu, QSYS_SWITCH_PORT_MODE_PORT_ENA, 1);
Vladimir Oltean69df5782020-02-29 16:50:02 +02001408 /* CPU port Injection/Extraction configuration */
Vladimir Oltean886e1382020-07-13 19:57:03 +03001409 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_XTR_HDR,
Vladimir Oltean2d44b092020-09-26 22:32:01 +03001410 ocelot->xtr_prefix);
Vladimir Oltean886e1382020-07-13 19:57:03 +03001411 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_INJ_HDR,
Vladimir Oltean2d44b092020-09-26 22:32:01 +03001412 ocelot->inj_prefix);
Vladimir Oltean21468192019-11-09 15:03:00 +02001413
1414 /* Configure the CPU port to be VLAN aware */
1415 ocelot_write_gix(ocelot, ANA_PORT_VLAN_CFG_VLAN_VID(0) |
1416 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
1417 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1),
1418 ANA_PORT_VLAN_CFG, cpu);
Vladimir Oltean21468192019-11-09 15:03:00 +02001419}
Vladimir Oltean21468192019-11-09 15:03:00 +02001420
Alexandre Bellonia556c762018-05-14 22:04:57 +02001421int ocelot_init(struct ocelot *ocelot)
1422{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001423 char queue_name[32];
Vladimir Oltean21468192019-11-09 15:03:00 +02001424 int i, ret;
1425 u32 port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001426
Vladimir Oltean3a77b592019-11-14 17:03:26 +02001427 if (ocelot->ops->reset) {
1428 ret = ocelot->ops->reset(ocelot);
1429 if (ret) {
1430 dev_err(ocelot->dev, "Switch reset failed\n");
1431 return ret;
1432 }
1433 }
1434
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001435 ocelot->lags = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports,
1436 sizeof(u32), GFP_KERNEL);
1437 if (!ocelot->lags)
1438 return -ENOMEM;
1439
Alexandre Bellonia556c762018-05-14 22:04:57 +02001440 ocelot->stats = devm_kcalloc(ocelot->dev,
1441 ocelot->num_phys_ports * ocelot->num_stats,
1442 sizeof(u64), GFP_KERNEL);
1443 if (!ocelot->stats)
1444 return -ENOMEM;
1445
1446 mutex_init(&ocelot->stats_lock);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001447 mutex_init(&ocelot->ptp_lock);
1448 spin_lock_init(&ocelot->ptp_clock_lock);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001449 snprintf(queue_name, sizeof(queue_name), "%s-stats",
1450 dev_name(ocelot->dev));
1451 ocelot->stats_queue = create_singlethread_workqueue(queue_name);
1452 if (!ocelot->stats_queue)
1453 return -ENOMEM;
1454
Claudiu Manoil2b120dd2019-11-09 15:02:58 +02001455 INIT_LIST_HEAD(&ocelot->multicast);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001456 ocelot_mact_init(ocelot);
1457 ocelot_vlan_init(ocelot);
Vladimir Olteanaae4e502020-06-20 18:43:46 +03001458 ocelot_vcap_init(ocelot);
Vladimir Oltean2d44b092020-09-26 22:32:01 +03001459 ocelot_cpu_port_init(ocelot);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001460
1461 for (port = 0; port < ocelot->num_phys_ports; port++) {
1462 /* Clear all counters (5 groups) */
1463 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) |
1464 SYS_STAT_CFG_STAT_CLEAR_SHOT(0x7f),
1465 SYS_STAT_CFG);
1466 }
1467
1468 /* Only use S-Tag */
1469 ocelot_write(ocelot, ETH_P_8021AD, SYS_VLAN_ETYPE_CFG);
1470
1471 /* Aggregation mode */
1472 ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA |
1473 ANA_AGGR_CFG_AC_DMAC_ENA |
1474 ANA_AGGR_CFG_AC_IP4_SIPDIP_ENA |
1475 ANA_AGGR_CFG_AC_IP4_TCPUDP_ENA, ANA_AGGR_CFG);
1476
1477 /* Set MAC age time to default value. The entry is aged after
1478 * 2*AGE_PERIOD
1479 */
1480 ocelot_write(ocelot,
1481 ANA_AUTOAGE_AGE_PERIOD(BR_DEFAULT_AGEING_TIME / 2 / HZ),
1482 ANA_AUTOAGE);
1483
1484 /* Disable learning for frames discarded by VLAN ingress filtering */
1485 regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1);
1486
1487 /* Setup frame ageing - fixed value "2 sec" - in 6.5 us units */
1488 ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA |
1489 SYS_FRM_AGING_MAX_AGE(307692), SYS_FRM_AGING);
1490
1491 /* Setup flooding PGIDs */
Vladimir Olteanedd24102020-12-04 19:54:16 +02001492 for (i = 0; i < ocelot->num_flooding_pgids; i++)
1493 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) |
1494 ANA_FLOODING_FLD_BROADCAST(PGID_MC) |
1495 ANA_FLOODING_FLD_UNICAST(PGID_UC),
1496 ANA_FLOODING, i);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001497 ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) |
1498 ANA_FLOODING_IPMC_FLD_MC6_CTRL(PGID_MC) |
1499 ANA_FLOODING_IPMC_FLD_MC4_DATA(PGID_MCIPV4) |
1500 ANA_FLOODING_IPMC_FLD_MC4_CTRL(PGID_MC),
1501 ANA_FLOODING_IPMC);
1502
1503 for (port = 0; port < ocelot->num_phys_ports; port++) {
1504 /* Transmit the frame to the local port. */
1505 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
1506 /* Do not forward BPDU frames to the front ports. */
1507 ocelot_write_gix(ocelot,
1508 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
1509 ANA_PORT_CPU_FWD_BPDU_CFG,
1510 port);
1511 /* Ensure bridging is disabled */
1512 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port);
1513 }
1514
Alexandre Bellonia556c762018-05-14 22:04:57 +02001515 /* Allow broadcast MAC frames. */
Vladimir Oltean96b029b2020-06-21 14:46:02 +03001516 for_each_nonreserved_multicast_dest_pgid(ocelot, i) {
Alexandre Bellonia556c762018-05-14 22:04:57 +02001517 u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0));
1518
1519 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
1520 }
1521 ocelot_write_rix(ocelot,
1522 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)),
1523 ANA_PGID_PGID, PGID_MC);
1524 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV4);
1525 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV6);
1526
Alexandre Bellonia556c762018-05-14 22:04:57 +02001527 /* Allow manual injection via DEVCPU_QS registers, and byte swap these
1528 * registers endianness.
1529 */
1530 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_BYTE_SWAP |
1531 QS_INJ_GRP_CFG_MODE(1), QS_INJ_GRP_CFG, 0);
1532 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_BYTE_SWAP |
1533 QS_XTR_GRP_CFG_MODE(1), QS_XTR_GRP_CFG, 0);
1534 ocelot_write(ocelot, ANA_CPUQ_CFG_CPUQ_MIRROR(2) |
1535 ANA_CPUQ_CFG_CPUQ_LRN(2) |
1536 ANA_CPUQ_CFG_CPUQ_MAC_COPY(2) |
1537 ANA_CPUQ_CFG_CPUQ_SRC_COPY(2) |
1538 ANA_CPUQ_CFG_CPUQ_LOCKED_PORTMOVE(2) |
1539 ANA_CPUQ_CFG_CPUQ_ALLBRIDGE(6) |
1540 ANA_CPUQ_CFG_CPUQ_IPMC_CTRL(6) |
1541 ANA_CPUQ_CFG_CPUQ_IGMP(6) |
1542 ANA_CPUQ_CFG_CPUQ_MLD(6), ANA_CPUQ_CFG);
1543 for (i = 0; i < 16; i++)
1544 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) |
1545 ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
1546 ANA_CPUQ_8021_CFG, i);
1547
Claudiu Manoil1e1caa92019-04-16 17:51:59 +03001548 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001549 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
1550 OCELOT_STATS_CHECK_DELAY);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001551
Alexandre Bellonia556c762018-05-14 22:04:57 +02001552 return 0;
1553}
1554EXPORT_SYMBOL(ocelot_init);
1555
1556void ocelot_deinit(struct ocelot *ocelot)
1557{
Claudiu Manoilc5d13962019-07-25 16:33:18 +03001558 cancel_delayed_work(&ocelot->stats_work);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001559 destroy_workqueue(ocelot->stats_queue);
1560 mutex_destroy(&ocelot->stats_lock);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001561}
1562EXPORT_SYMBOL(ocelot_deinit);
1563
Vladimir Olteane5fb5122020-09-18 04:07:30 +03001564void ocelot_deinit_port(struct ocelot *ocelot, int port)
1565{
1566 struct ocelot_port *ocelot_port = ocelot->ports[port];
1567
1568 skb_queue_purge(&ocelot_port->tx_skbs);
1569}
1570EXPORT_SYMBOL(ocelot_deinit_port);
1571
Alexandre Bellonia556c762018-05-14 22:04:57 +02001572MODULE_LICENSE("Dual MIT/GPL");