blob: a58d2ed5b590fd620351911fae13e421140d6f68 [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 */
7#include <linux/etherdevice.h>
8#include <linux/ethtool.h>
9#include <linux/if_bridge.h>
10#include <linux/if_ether.h>
11#include <linux/if_vlan.h>
12#include <linux/interrupt.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/netdevice.h>
16#include <linux/phy.h>
Antoine Tenart4e3b0462019-08-12 16:45:37 +020017#include <linux/ptp_clock_kernel.h>
Alexandre Bellonia556c762018-05-14 22:04:57 +020018#include <linux/skbuff.h>
Steen Hegelund639c1b22018-12-20 14:16:31 +010019#include <linux/iopoll.h>
Alexandre Bellonia556c762018-05-14 22:04:57 +020020#include <net/arp.h>
21#include <net/netevent.h>
22#include <net/rtnetlink.h>
23#include <net/switchdev.h>
24
25#include "ocelot.h"
Horatiu Vulturb5962292019-05-31 09:16:56 +020026#include "ocelot_ace.h"
Alexandre Bellonia556c762018-05-14 22:04:57 +020027
Steen Hegelund639c1b22018-12-20 14:16:31 +010028#define TABLE_UPDATE_SLEEP_US 10
29#define TABLE_UPDATE_TIMEOUT_US 100000
30
Alexandre Bellonia556c762018-05-14 22:04:57 +020031/* MAC table entry types.
32 * ENTRYTYPE_NORMAL is subject to aging.
33 * ENTRYTYPE_LOCKED is not subject to aging.
34 * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
35 * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
36 */
37enum macaccess_entry_type {
38 ENTRYTYPE_NORMAL = 0,
39 ENTRYTYPE_LOCKED,
40 ENTRYTYPE_MACv4,
41 ENTRYTYPE_MACv6,
42};
43
44struct ocelot_mact_entry {
45 u8 mac[ETH_ALEN];
46 u16 vid;
47 enum macaccess_entry_type type;
48};
49
Steen Hegelund639c1b22018-12-20 14:16:31 +010050static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot)
51{
52 return ocelot_read(ocelot, ANA_TABLES_MACACCESS);
53}
54
Alexandre Bellonia556c762018-05-14 22:04:57 +020055static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot)
56{
Steen Hegelund639c1b22018-12-20 14:16:31 +010057 u32 val;
Alexandre Bellonia556c762018-05-14 22:04:57 +020058
Steen Hegelund639c1b22018-12-20 14:16:31 +010059 return readx_poll_timeout(ocelot_mact_read_macaccess,
60 ocelot, val,
61 (val & ANA_TABLES_MACACCESS_MAC_TABLE_CMD_M) ==
62 MACACCESS_CMD_IDLE,
63 TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
Alexandre Bellonia556c762018-05-14 22:04:57 +020064}
65
66static void ocelot_mact_select(struct ocelot *ocelot,
67 const unsigned char mac[ETH_ALEN],
68 unsigned int vid)
69{
70 u32 macl = 0, mach = 0;
71
72 /* Set the MAC address to handle and the vlan associated in a format
73 * understood by the hardware.
74 */
75 mach |= vid << 16;
76 mach |= mac[0] << 8;
77 mach |= mac[1] << 0;
78 macl |= mac[2] << 24;
79 macl |= mac[3] << 16;
80 macl |= mac[4] << 8;
81 macl |= mac[5] << 0;
82
83 ocelot_write(ocelot, macl, ANA_TABLES_MACLDATA);
84 ocelot_write(ocelot, mach, ANA_TABLES_MACHDATA);
85
86}
87
88static int ocelot_mact_learn(struct ocelot *ocelot, int port,
89 const unsigned char mac[ETH_ALEN],
90 unsigned int vid,
91 enum macaccess_entry_type type)
92{
93 ocelot_mact_select(ocelot, mac, vid);
94
95 /* Issue a write command */
96 ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID |
97 ANA_TABLES_MACACCESS_DEST_IDX(port) |
98 ANA_TABLES_MACACCESS_ENTRYTYPE(type) |
99 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_LEARN),
100 ANA_TABLES_MACACCESS);
101
102 return ocelot_mact_wait_for_completion(ocelot);
103}
104
105static int ocelot_mact_forget(struct ocelot *ocelot,
106 const unsigned char mac[ETH_ALEN],
107 unsigned int vid)
108{
109 ocelot_mact_select(ocelot, mac, vid);
110
111 /* Issue a forget command */
112 ocelot_write(ocelot,
113 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_FORGET),
114 ANA_TABLES_MACACCESS);
115
116 return ocelot_mact_wait_for_completion(ocelot);
117}
118
119static void ocelot_mact_init(struct ocelot *ocelot)
120{
121 /* Configure the learning mode entries attributes:
122 * - Do not copy the frame to the CPU extraction queues.
123 * - Use the vlan and mac_cpoy for dmac lookup.
124 */
125 ocelot_rmw(ocelot, 0,
126 ANA_AGENCTRL_LEARN_CPU_COPY | ANA_AGENCTRL_IGNORE_DMAC_FLAGS
127 | ANA_AGENCTRL_LEARN_FWD_KILL
128 | ANA_AGENCTRL_LEARN_IGNORE_VLAN,
129 ANA_AGENCTRL);
130
131 /* Clear the MAC table */
132 ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
133}
134
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200135static void ocelot_vcap_enable(struct ocelot *ocelot, int port)
Horatiu Vulturb5962292019-05-31 09:16:56 +0200136{
137 ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA |
138 ANA_PORT_VCAP_S2_CFG_S2_IP6_CFG(0xa),
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200139 ANA_PORT_VCAP_S2_CFG, port);
Horatiu Vulturb5962292019-05-31 09:16:56 +0200140}
141
Steen Hegelund639c1b22018-12-20 14:16:31 +0100142static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot)
143{
144 return ocelot_read(ocelot, ANA_TABLES_VLANACCESS);
145}
146
Alexandre Bellonia556c762018-05-14 22:04:57 +0200147static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot)
148{
Steen Hegelund639c1b22018-12-20 14:16:31 +0100149 u32 val;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200150
Steen Hegelund639c1b22018-12-20 14:16:31 +0100151 return readx_poll_timeout(ocelot_vlant_read_vlanaccess,
152 ocelot,
153 val,
154 (val & ANA_TABLES_VLANACCESS_VLAN_TBL_CMD_M) ==
155 ANA_TABLES_VLANACCESS_CMD_IDLE,
156 TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200157}
158
Antoine Tenart71425292018-06-26 14:28:49 +0200159static int ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask)
160{
161 /* Select the VID to configure */
162 ocelot_write(ocelot, ANA_TABLES_VLANTIDX_V_INDEX(vid),
163 ANA_TABLES_VLANTIDX);
164 /* Set the vlan port members mask and issue a write command */
165 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_VLAN_PORT_MASK(mask) |
166 ANA_TABLES_VLANACCESS_CMD_WRITE,
167 ANA_TABLES_VLANACCESS);
168
169 return ocelot_vlant_wait_for_completion(ocelot);
170}
171
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200172static void ocelot_vlan_mode(struct ocelot *ocelot, int port,
Antoine Tenart71425292018-06-26 14:28:49 +0200173 netdev_features_t features)
174{
Antoine Tenart71425292018-06-26 14:28:49 +0200175 u32 val;
176
177 /* Filtering */
178 val = ocelot_read(ocelot, ANA_VLANMASK);
179 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200180 val |= BIT(port);
Antoine Tenart71425292018-06-26 14:28:49 +0200181 else
Vladimir Olteanf270dbf2019-11-09 15:02:52 +0200182 val &= ~BIT(port);
Antoine Tenart71425292018-06-26 14:28:49 +0200183 ocelot_write(ocelot, val, ANA_VLANMASK);
184}
185
Vladimir Oltean5e256362019-11-14 17:03:27 +0200186void ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
187 bool vlan_aware)
Antoine Tenart71425292018-06-26 14:28:49 +0200188{
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200189 struct ocelot_port *ocelot_port = ocelot->ports[port];
Antoine Tenart71425292018-06-26 14:28:49 +0200190 u32 val;
191
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200192 if (vlan_aware)
193 val = ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
194 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
195 else
196 val = 0;
Antoine Tenart71425292018-06-26 14:28:49 +0200197 ocelot_rmw_gix(ocelot, val,
Antoine Tenart71425292018-06-26 14:28:49 +0200198 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
199 ANA_PORT_VLAN_CFG_VLAN_POP_CNT_M,
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200200 ANA_PORT_VLAN_CFG, port);
Antoine Tenart71425292018-06-26 14:28:49 +0200201
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200202 if (vlan_aware && !ocelot_port->vid)
Antoine Tenart71425292018-06-26 14:28:49 +0200203 /* If port is vlan-aware and tagged, drop untagged and priority
204 * tagged frames.
205 */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200206 val = ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
207 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
208 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
209 else
210 val = 0;
211 ocelot_rmw_gix(ocelot, val,
212 ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
Antoine Tenart71425292018-06-26 14:28:49 +0200213 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200214 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA,
215 ANA_PORT_DROP_CFG, port);
Antoine Tenart71425292018-06-26 14:28:49 +0200216
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200217 if (vlan_aware) {
218 if (ocelot_port->vid)
Antoine Tenart71425292018-06-26 14:28:49 +0200219 /* Tag all frames except when VID == DEFAULT_VLAN */
220 val |= REW_TAG_CFG_TAG_CFG(1);
221 else
222 /* Tag all frames */
223 val |= REW_TAG_CFG_TAG_CFG(3);
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200224 } else {
225 /* Port tagging disabled. */
226 val = REW_TAG_CFG_TAG_CFG(0);
Antoine Tenart71425292018-06-26 14:28:49 +0200227 }
228 ocelot_rmw_gix(ocelot, val,
Antoine Tenart71425292018-06-26 14:28:49 +0200229 REW_TAG_CFG_TAG_CFG_M,
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200230 REW_TAG_CFG, port);
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200231}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200232EXPORT_SYMBOL(ocelot_port_vlan_filtering);
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200233
234static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
235 u16 vid)
236{
237 struct ocelot_port *ocelot_port = ocelot->ports[port];
238
239 if (ocelot_port->vid != vid) {
240 /* Always permit deleting the native VLAN (vid = 0) */
241 if (ocelot_port->vid && vid) {
242 dev_err(ocelot->dev,
243 "Port already has a native VLAN: %d\n",
244 ocelot_port->vid);
245 return -EBUSY;
246 }
247 ocelot_port->vid = vid;
248 }
249
250 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid),
Antoine Tenart71425292018-06-26 14:28:49 +0200251 REW_PORT_VLAN_CFG_PORT_VID_M,
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200252 REW_PORT_VLAN_CFG, port);
253
254 return 0;
255}
256
257/* Default vlan to clasify for untagged frames (may be zero) */
258static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, u16 pvid)
259{
260 struct ocelot_port *ocelot_port = ocelot->ports[port];
261
262 ocelot_rmw_gix(ocelot,
263 ANA_PORT_VLAN_CFG_VLAN_VID(pvid),
264 ANA_PORT_VLAN_CFG_VLAN_VID_M,
265 ANA_PORT_VLAN_CFG, port);
266
267 ocelot_port->pvid = pvid;
Antoine Tenart71425292018-06-26 14:28:49 +0200268}
269
Vladimir Oltean5e256362019-11-14 17:03:27 +0200270int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
271 bool untagged)
Antoine Tenart71425292018-06-26 14:28:49 +0200272{
Antoine Tenart71425292018-06-26 14:28:49 +0200273 int ret;
274
Antoine Tenart71425292018-06-26 14:28:49 +0200275 /* Make the port a member of the VLAN */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200276 ocelot->vlan_mask[vid] |= BIT(port);
Antoine Tenart71425292018-06-26 14:28:49 +0200277 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
278 if (ret)
279 return ret;
280
281 /* Default ingress vlan classification */
282 if (pvid)
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200283 ocelot_port_set_pvid(ocelot, port, vid);
Antoine Tenart71425292018-06-26 14:28:49 +0200284
285 /* Untagged egress vlan clasification */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200286 if (untagged) {
287 ret = ocelot_port_set_native_vlan(ocelot, port, vid);
288 if (ret)
289 return ret;
Vladimir Olteanb9cd75e2019-10-26 21:04:27 +0300290 }
Antoine Tenart71425292018-06-26 14:28:49 +0200291
Antoine Tenart71425292018-06-26 14:28:49 +0200292 return 0;
293}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200294EXPORT_SYMBOL(ocelot_vlan_add);
Antoine Tenart71425292018-06-26 14:28:49 +0200295
Vladimir Oltean98559342019-11-09 15:02:48 +0200296static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid,
297 bool untagged)
Antoine Tenart71425292018-06-26 14:28:49 +0200298{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200299 struct ocelot_port_private *priv = netdev_priv(dev);
300 struct ocelot_port *ocelot_port = &priv->port;
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200301 struct ocelot *ocelot = ocelot_port->ocelot;
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200302 int port = priv->chip_port;
Antoine Tenart71425292018-06-26 14:28:49 +0200303 int ret;
304
Vladimir Oltean98559342019-11-09 15:02:48 +0200305 ret = ocelot_vlan_add(ocelot, port, vid, pvid, untagged);
306 if (ret)
307 return ret;
Antoine Tenart71425292018-06-26 14:28:49 +0200308
Vladimir Oltean98559342019-11-09 15:02:48 +0200309 /* Add the port MAC address to with the right VLAN information */
310 ocelot_mact_learn(ocelot, PGID_CPU, dev->dev_addr, vid,
311 ENTRYTYPE_LOCKED);
312
313 return 0;
314}
315
Vladimir Oltean5e256362019-11-14 17:03:27 +0200316int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
Vladimir Oltean98559342019-11-09 15:02:48 +0200317{
318 struct ocelot_port *ocelot_port = ocelot->ports[port];
319 int ret;
Antoine Tenart71425292018-06-26 14:28:49 +0200320
321 /* Stop the port from being a member of the vlan */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200322 ocelot->vlan_mask[vid] &= ~BIT(port);
Antoine Tenart71425292018-06-26 14:28:49 +0200323 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
324 if (ret)
325 return ret;
326
327 /* Ingress */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200328 if (ocelot_port->pvid == vid)
329 ocelot_port_set_pvid(ocelot, port, 0);
Antoine Tenart71425292018-06-26 14:28:49 +0200330
331 /* Egress */
Vladimir Oltean97bb69e2019-11-09 15:02:47 +0200332 if (ocelot_port->vid == vid)
333 ocelot_port_set_native_vlan(ocelot, port, 0);
Antoine Tenart71425292018-06-26 14:28:49 +0200334
335 return 0;
336}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200337EXPORT_SYMBOL(ocelot_vlan_del);
Antoine Tenart71425292018-06-26 14:28:49 +0200338
Vladimir Oltean98559342019-11-09 15:02:48 +0200339static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid)
340{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200341 struct ocelot_port_private *priv = netdev_priv(dev);
342 struct ocelot *ocelot = priv->port.ocelot;
343 int port = priv->chip_port;
Vladimir Oltean98559342019-11-09 15:02:48 +0200344 int ret;
345
346 /* 8021q removes VID 0 on module unload for all interfaces
347 * with VLAN filtering feature. We need to keep it to receive
348 * untagged traffic.
349 */
350 if (vid == 0)
351 return 0;
352
353 ret = ocelot_vlan_del(ocelot, port, vid);
354 if (ret)
355 return ret;
356
357 /* Del the port MAC address to with the right VLAN information */
358 ocelot_mact_forget(ocelot, dev->dev_addr, vid);
359
360 return 0;
361}
362
Alexandre Bellonia556c762018-05-14 22:04:57 +0200363static void ocelot_vlan_init(struct ocelot *ocelot)
364{
Antoine Tenart71425292018-06-26 14:28:49 +0200365 u16 port, vid;
366
Alexandre Bellonia556c762018-05-14 22:04:57 +0200367 /* Clear VLAN table, by default all ports are members of all VLANs */
368 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_CMD_INIT,
369 ANA_TABLES_VLANACCESS);
370 ocelot_vlant_wait_for_completion(ocelot);
Antoine Tenart71425292018-06-26 14:28:49 +0200371
372 /* Configure the port VLAN memberships */
373 for (vid = 1; vid < VLAN_N_VID; vid++) {
374 ocelot->vlan_mask[vid] = 0;
375 ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
376 }
377
378 /* Because VLAN filtering is enabled, we need VID 0 to get untagged
379 * traffic. It is added automatically if 8021q module is loaded, but
380 * we can't rely on it since module may be not loaded.
381 */
382 ocelot->vlan_mask[0] = GENMASK(ocelot->num_phys_ports - 1, 0);
383 ocelot_vlant_set_mask(ocelot, 0, ocelot->vlan_mask[0]);
384
Antoine Tenart71425292018-06-26 14:28:49 +0200385 /* Set vlan ingress filter mask to all ports but the CPU port by
386 * default.
387 */
Vladimir Oltean714d0ff2019-11-09 15:02:55 +0200388 ocelot_write(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
389 ANA_VLANMASK);
Antoine Tenart71425292018-06-26 14:28:49 +0200390
391 for (port = 0; port < ocelot->num_phys_ports; port++) {
392 ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port);
393 ocelot_write_gix(ocelot, 0, REW_TAG_CFG, port);
394 }
Alexandre Bellonia556c762018-05-14 22:04:57 +0200395}
396
397/* Watermark encode
398 * Bit 8: Unit; 0:1, 1:16
399 * Bit 7-0: Value to be multiplied with unit
400 */
401static u16 ocelot_wm_enc(u16 value)
402{
403 if (value >= BIT(8))
404 return BIT(8) | (value / 16);
405
406 return value;
407}
408
Vladimir Oltean5e256362019-11-14 17:03:27 +0200409void ocelot_adjust_link(struct ocelot *ocelot, int port,
410 struct phy_device *phydev)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200411{
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200412 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +0200413 int speed, mode = 0;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200414
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200415 switch (phydev->speed) {
Alexandre Bellonia556c762018-05-14 22:04:57 +0200416 case SPEED_10:
417 speed = OCELOT_SPEED_10;
418 break;
419 case SPEED_100:
420 speed = OCELOT_SPEED_100;
421 break;
422 case SPEED_1000:
423 speed = OCELOT_SPEED_1000;
424 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
425 break;
426 case SPEED_2500:
427 speed = OCELOT_SPEED_2500;
428 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
429 break;
430 default:
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200431 dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n",
432 port, phydev->speed);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200433 return;
434 }
435
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200436 phy_print_status(phydev);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200437
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200438 if (!phydev->link)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200439 return;
440
441 /* Only full duplex supported for now */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200442 ocelot_port_writel(ocelot_port, DEV_MAC_MODE_CFG_FDX_ENA |
Alexandre Bellonia556c762018-05-14 22:04:57 +0200443 mode, DEV_MAC_MODE_CFG);
444
Claudiu Manoildc3de2a2019-11-14 17:03:21 +0200445 if (ocelot->ops->pcs_init)
446 ocelot->ops->pcs_init(ocelot, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200447
Alexandre Bellonia556c762018-05-14 22:04:57 +0200448 /* Enable MAC module */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200449 ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
Alexandre Bellonia556c762018-05-14 22:04:57 +0200450 DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
451
452 /* Take MAC, Port, Phy (intern) and PCS (SGMII/Serdes) clock out of
453 * reset */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200454 ocelot_port_writel(ocelot_port, DEV_CLOCK_CFG_LINK_SPEED(speed),
Alexandre Bellonia556c762018-05-14 22:04:57 +0200455 DEV_CLOCK_CFG);
456
Alexandre Bellonia556c762018-05-14 22:04:57 +0200457 /* No PFC */
458 ocelot_write_gix(ocelot, ANA_PFC_PFC_CFG_FC_LINK_SPEED(speed),
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200459 ANA_PFC_PFC_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200460
Alexandre Bellonia556c762018-05-14 22:04:57 +0200461 /* Core: Enable port for frame transfer */
462 ocelot_write_rix(ocelot, QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE |
463 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG(1) |
464 QSYS_SWITCH_PORT_MODE_PORT_ENA,
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200465 QSYS_SWITCH_PORT_MODE, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200466
467 /* Flow control */
468 ocelot_write_rix(ocelot, SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
469 SYS_MAC_FC_CFG_RX_FC_ENA | SYS_MAC_FC_CFG_TX_FC_ENA |
470 SYS_MAC_FC_CFG_ZERO_PAUSE_ENA |
471 SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
472 SYS_MAC_FC_CFG_FC_LINK_SPEED(speed),
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200473 SYS_MAC_FC_CFG, port);
474 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200475}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200476EXPORT_SYMBOL(ocelot_adjust_link);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200477
Vladimir Oltean26f4dba2019-11-09 15:02:59 +0200478static void ocelot_port_adjust_link(struct net_device *dev)
479{
480 struct ocelot_port_private *priv = netdev_priv(dev);
481 struct ocelot *ocelot = priv->port.ocelot;
482 int port = priv->chip_port;
483
484 ocelot_adjust_link(ocelot, port, dev->phydev);
485}
486
Vladimir Oltean5e256362019-11-14 17:03:27 +0200487void ocelot_port_enable(struct ocelot *ocelot, int port,
488 struct phy_device *phy)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200489{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200490 /* Enable receiving frames on the port, and activate auto-learning of
491 * MAC addresses.
492 */
493 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO |
494 ANA_PORT_PORT_CFG_RECV_ENA |
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200495 ANA_PORT_PORT_CFG_PORTID_VAL(port),
496 ANA_PORT_PORT_CFG, port);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200497}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200498EXPORT_SYMBOL(ocelot_port_enable);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200499
500static int ocelot_port_open(struct net_device *dev)
501{
502 struct ocelot_port_private *priv = netdev_priv(dev);
503 struct ocelot *ocelot = priv->port.ocelot;
504 int port = priv->chip_port;
505 int err;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200506
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200507 if (priv->serdes) {
508 err = phy_set_mode_ext(priv->serdes, PHY_MODE_ETHERNET,
509 priv->phy_mode);
Quentin Schulz71e32a202018-10-04 14:22:08 +0200510 if (err) {
511 netdev_err(dev, "Could not set mode of SerDes\n");
512 return err;
513 }
514 }
515
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200516 err = phy_connect_direct(dev, priv->phy, &ocelot_port_adjust_link,
517 priv->phy_mode);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200518 if (err) {
519 netdev_err(dev, "Could not attach to PHY\n");
520 return err;
521 }
522
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200523 dev->phydev = priv->phy;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200524
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200525 phy_attached_info(priv->phy);
526 phy_start(priv->phy);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200527
528 ocelot_port_enable(ocelot, port, priv->phy);
529
Alexandre Bellonia556c762018-05-14 22:04:57 +0200530 return 0;
531}
532
Vladimir Oltean5e256362019-11-14 17:03:27 +0200533void ocelot_port_disable(struct ocelot *ocelot, int port)
Vladimir Oltean889b8952019-11-09 15:02:57 +0200534{
535 struct ocelot_port *ocelot_port = ocelot->ports[port];
536
537 ocelot_port_writel(ocelot_port, 0, DEV_MAC_ENA_CFG);
538 ocelot_rmw_rix(ocelot, 0, QSYS_SWITCH_PORT_MODE_PORT_ENA,
539 QSYS_SWITCH_PORT_MODE, port);
540}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200541EXPORT_SYMBOL(ocelot_port_disable);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200542
Alexandre Bellonia556c762018-05-14 22:04:57 +0200543static int ocelot_port_stop(struct net_device *dev)
544{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200545 struct ocelot_port_private *priv = netdev_priv(dev);
Vladimir Oltean889b8952019-11-09 15:02:57 +0200546 struct ocelot *ocelot = priv->port.ocelot;
547 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200548
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200549 phy_disconnect(priv->phy);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200550
551 dev->phydev = NULL;
552
Vladimir Oltean889b8952019-11-09 15:02:57 +0200553 ocelot_port_disable(ocelot, port);
554
Alexandre Bellonia556c762018-05-14 22:04:57 +0200555 return 0;
556}
557
558/* Generate the IFH for frame injection
559 *
560 * The IFH is a 128bit-value
561 * bit 127: bypass the analyzer processing
562 * bit 56-67: destination mask
563 * bit 28-29: pop_cnt: 3 disables all rewriting of the frame
564 * bit 20-27: cpu extraction queue mask
565 * bit 16: tag type 0: C-tag, 1: S-tag
566 * bit 0-11: VID
567 */
568static int ocelot_gen_ifh(u32 *ifh, struct frame_info *info)
569{
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200570 ifh[0] = IFH_INJ_BYPASS | ((0x1ff & info->rew_op) << 21);
Antoine Tenart08d02362018-06-20 10:50:46 +0200571 ifh[1] = (0xf00 & info->port) >> 8;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200572 ifh[2] = (0xff & info->port) << 24;
Antoine Tenart08d02362018-06-20 10:50:46 +0200573 ifh[3] = (info->tag_type << 16) | info->vid;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200574
575 return 0;
576}
577
578static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
579{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200580 struct ocelot_port_private *priv = netdev_priv(dev);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200581 struct skb_shared_info *shinfo = skb_shinfo(skb);
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200582 struct ocelot_port *ocelot_port = &priv->port;
583 struct ocelot *ocelot = ocelot_port->ocelot;
Vladimir Olteanf24711f2019-11-14 17:03:24 +0200584 u32 val, ifh[OCELOT_TAG_LEN / 4];
Alexandre Bellonia556c762018-05-14 22:04:57 +0200585 struct frame_info info = {};
586 u8 grp = 0; /* Send everything on CPU group 0 */
587 unsigned int i, count, last;
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200588 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200589
590 val = ocelot_read(ocelot, QS_INJ_STATUS);
591 if (!(val & QS_INJ_STATUS_FIFO_RDY(BIT(grp))) ||
592 (val & QS_INJ_STATUS_WMARK_REACHED(BIT(grp))))
593 return NETDEV_TX_BUSY;
594
595 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) |
596 QS_INJ_CTRL_SOF, QS_INJ_CTRL, grp);
597
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200598 info.port = BIT(port);
Antoine Tenart08d02362018-06-20 10:50:46 +0200599 info.tag_type = IFH_TAG_TYPE_C;
600 info.vid = skb_vlan_tag_get(skb);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200601
602 /* Check if timestamping is needed */
603 if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP) {
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200604 info.rew_op = ocelot_port->ptp_cmd;
605 if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP)
606 info.rew_op |= (ocelot_port->ts_id % 4) << 3;
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200607 }
608
Alexandre Bellonia556c762018-05-14 22:04:57 +0200609 ocelot_gen_ifh(ifh, &info);
610
Vladimir Olteanf24711f2019-11-14 17:03:24 +0200611 for (i = 0; i < OCELOT_TAG_LEN / 4; i++)
Antoine Tenartc2cd6502018-06-22 11:50:52 +0200612 ocelot_write_rix(ocelot, (__force u32)cpu_to_be32(ifh[i]),
613 QS_INJ_WR, grp);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200614
615 count = (skb->len + 3) / 4;
616 last = skb->len % 4;
617 for (i = 0; i < count; i++) {
618 ocelot_write_rix(ocelot, ((u32 *)skb->data)[i], QS_INJ_WR, grp);
619 }
620
621 /* Add padding */
622 while (i < (OCELOT_BUFFER_CELL_SZ / 4)) {
623 ocelot_write_rix(ocelot, 0, QS_INJ_WR, grp);
624 i++;
625 }
626
627 /* Indicate EOF and valid bytes in last word */
628 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) |
629 QS_INJ_CTRL_VLD_BYTES(skb->len < OCELOT_BUFFER_CELL_SZ ? 0 : last) |
630 QS_INJ_CTRL_EOF,
631 QS_INJ_CTRL, grp);
632
633 /* Add dummy CRC */
634 ocelot_write_rix(ocelot, 0, QS_INJ_WR, grp);
635 skb_tx_timestamp(skb);
636
637 dev->stats.tx_packets++;
638 dev->stats.tx_bytes += skb->len;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200639
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200640 if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP &&
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200641 ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200642 struct ocelot_skb *oskb =
643 kzalloc(sizeof(struct ocelot_skb), GFP_ATOMIC);
644
645 if (unlikely(!oskb))
646 goto out;
647
648 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
649
650 oskb->skb = skb;
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200651 oskb->id = ocelot_port->ts_id % 4;
652 ocelot_port->ts_id++;
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200653
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200654 list_add_tail(&oskb->head, &ocelot_port->skbs);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200655
656 return NETDEV_TX_OK;
657 }
658
659out:
660 dev_kfree_skb_any(skb);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200661 return NETDEV_TX_OK;
662}
663
Yangbo Lue23a7b32019-11-20 16:23:15 +0800664static void ocelot_get_hwtimestamp(struct ocelot *ocelot,
665 struct timespec64 *ts)
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200666{
667 unsigned long flags;
668 u32 val;
669
670 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
671
672 /* Read current PTP time to get seconds */
673 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
674
675 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
676 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_SAVE);
677 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
678 ts->tv_sec = ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN);
679
680 /* Read packet HW timestamp from FIFO */
681 val = ocelot_read(ocelot, SYS_PTP_TXSTAMP);
682 ts->tv_nsec = SYS_PTP_TXSTAMP_PTP_TXSTAMP(val);
683
684 /* Sec has incremented since the ts was registered */
685 if ((ts->tv_sec & 0x1) != !!(val & SYS_PTP_TXSTAMP_PTP_TXSTAMP_SEC))
686 ts->tv_sec--;
687
688 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
689}
Yangbo Lue23a7b32019-11-20 16:23:15 +0800690
691void ocelot_get_txtstamp(struct ocelot *ocelot)
692{
693 int budget = OCELOT_PTP_QUEUE_SZ;
694
695 while (budget--) {
696 struct skb_shared_hwtstamps shhwtstamps;
697 struct list_head *pos, *tmp;
698 struct sk_buff *skb = NULL;
699 struct ocelot_skb *entry;
700 struct ocelot_port *port;
701 struct timespec64 ts;
702 u32 val, id, txport;
703
704 val = ocelot_read(ocelot, SYS_PTP_STATUS);
705
706 /* Check if a timestamp can be retrieved */
707 if (!(val & SYS_PTP_STATUS_PTP_MESS_VLD))
708 break;
709
710 WARN_ON(val & SYS_PTP_STATUS_PTP_OVFL);
711
712 /* Retrieve the ts ID and Tx port */
713 id = SYS_PTP_STATUS_PTP_MESS_ID_X(val);
714 txport = SYS_PTP_STATUS_PTP_MESS_TXPORT_X(val);
715
716 /* Retrieve its associated skb */
717 port = ocelot->ports[txport];
718
719 list_for_each_safe(pos, tmp, &port->skbs) {
720 entry = list_entry(pos, struct ocelot_skb, head);
721 if (entry->id != id)
722 continue;
723
724 skb = entry->skb;
725
726 list_del(pos);
727 kfree(entry);
728 }
729
730 /* Next ts */
731 ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
732
733 if (unlikely(!skb))
734 continue;
735
736 /* Get the h/w timestamp */
737 ocelot_get_hwtimestamp(ocelot, &ts);
738
739 /* Set the timestamp into the skb */
740 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
741 shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
742 skb_tstamp_tx(skb, &shhwtstamps);
743
744 dev_kfree_skb_any(skb);
745 }
746}
747EXPORT_SYMBOL(ocelot_get_txtstamp);
Antoine Tenart4e3b0462019-08-12 16:45:37 +0200748
Claudiu Manoil40a15782019-05-21 19:52:55 +0300749static int ocelot_mc_unsync(struct net_device *dev, const unsigned char *addr)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200750{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200751 struct ocelot_port_private *priv = netdev_priv(dev);
752 struct ocelot_port *ocelot_port = &priv->port;
753 struct ocelot *ocelot = ocelot_port->ocelot;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200754
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200755 return ocelot_mact_forget(ocelot, addr, ocelot_port->pvid);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200756}
757
Claudiu Manoil40a15782019-05-21 19:52:55 +0300758static int ocelot_mc_sync(struct net_device *dev, const unsigned char *addr)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200759{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200760 struct ocelot_port_private *priv = netdev_priv(dev);
761 struct ocelot_port *ocelot_port = &priv->port;
762 struct ocelot *ocelot = ocelot_port->ocelot;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200763
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200764 return ocelot_mact_learn(ocelot, PGID_CPU, addr, ocelot_port->pvid,
Claudiu Manoil40a15782019-05-21 19:52:55 +0300765 ENTRYTYPE_LOCKED);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200766}
767
768static void ocelot_set_rx_mode(struct net_device *dev)
769{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200770 struct ocelot_port_private *priv = netdev_priv(dev);
771 struct ocelot *ocelot = priv->port.ocelot;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200772 u32 val;
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200773 int i;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200774
775 /* This doesn't handle promiscuous mode because the bridge core is
776 * setting IFF_PROMISC on all slave interfaces and all frames would be
777 * forwarded to the CPU port.
778 */
779 val = GENMASK(ocelot->num_phys_ports - 1, 0);
780 for (i = ocelot->num_phys_ports + 1; i < PGID_CPU; i++)
781 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
782
Claudiu Manoil40a15782019-05-21 19:52:55 +0300783 __dev_mc_sync(dev, ocelot_mc_sync, ocelot_mc_unsync);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200784}
785
786static int ocelot_port_get_phys_port_name(struct net_device *dev,
787 char *buf, size_t len)
788{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200789 struct ocelot_port_private *priv = netdev_priv(dev);
790 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200791 int ret;
792
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200793 ret = snprintf(buf, len, "p%d", port);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200794 if (ret >= len)
795 return -EINVAL;
796
797 return 0;
798}
799
800static int ocelot_port_set_mac_address(struct net_device *dev, void *p)
801{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200802 struct ocelot_port_private *priv = netdev_priv(dev);
803 struct ocelot_port *ocelot_port = &priv->port;
804 struct ocelot *ocelot = ocelot_port->ocelot;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200805 const struct sockaddr *addr = p;
806
807 /* Learn the new net device MAC address in the mac table. */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200808 ocelot_mact_learn(ocelot, PGID_CPU, addr->sa_data, ocelot_port->pvid,
Alexandre Bellonia556c762018-05-14 22:04:57 +0200809 ENTRYTYPE_LOCKED);
810 /* Then forget the previous one. */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200811 ocelot_mact_forget(ocelot, dev->dev_addr, ocelot_port->pvid);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200812
813 ether_addr_copy(dev->dev_addr, addr->sa_data);
814 return 0;
815}
816
817static void ocelot_get_stats64(struct net_device *dev,
818 struct rtnl_link_stats64 *stats)
819{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200820 struct ocelot_port_private *priv = netdev_priv(dev);
821 struct ocelot *ocelot = priv->port.ocelot;
822 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200823
824 /* Configure the port to read the stats from */
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200825 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port),
Alexandre Bellonia556c762018-05-14 22:04:57 +0200826 SYS_STAT_CFG);
827
828 /* Get Rx stats */
829 stats->rx_bytes = ocelot_read(ocelot, SYS_COUNT_RX_OCTETS);
830 stats->rx_packets = ocelot_read(ocelot, SYS_COUNT_RX_SHORTS) +
831 ocelot_read(ocelot, SYS_COUNT_RX_FRAGMENTS) +
832 ocelot_read(ocelot, SYS_COUNT_RX_JABBERS) +
833 ocelot_read(ocelot, SYS_COUNT_RX_LONGS) +
834 ocelot_read(ocelot, SYS_COUNT_RX_64) +
835 ocelot_read(ocelot, SYS_COUNT_RX_65_127) +
836 ocelot_read(ocelot, SYS_COUNT_RX_128_255) +
837 ocelot_read(ocelot, SYS_COUNT_RX_256_1023) +
838 ocelot_read(ocelot, SYS_COUNT_RX_1024_1526) +
839 ocelot_read(ocelot, SYS_COUNT_RX_1527_MAX);
840 stats->multicast = ocelot_read(ocelot, SYS_COUNT_RX_MULTICAST);
841 stats->rx_dropped = dev->stats.rx_dropped;
842
843 /* Get Tx stats */
844 stats->tx_bytes = ocelot_read(ocelot, SYS_COUNT_TX_OCTETS);
845 stats->tx_packets = ocelot_read(ocelot, SYS_COUNT_TX_64) +
846 ocelot_read(ocelot, SYS_COUNT_TX_65_127) +
847 ocelot_read(ocelot, SYS_COUNT_TX_128_511) +
848 ocelot_read(ocelot, SYS_COUNT_TX_512_1023) +
849 ocelot_read(ocelot, SYS_COUNT_TX_1024_1526) +
850 ocelot_read(ocelot, SYS_COUNT_TX_1527_MAX);
851 stats->tx_dropped = ocelot_read(ocelot, SYS_COUNT_TX_DROPS) +
852 ocelot_read(ocelot, SYS_COUNT_TX_AGING);
853 stats->collisions = ocelot_read(ocelot, SYS_COUNT_TX_COLLISION);
854}
855
Vladimir Oltean5e256362019-11-14 17:03:27 +0200856int ocelot_fdb_add(struct ocelot *ocelot, int port,
857 const unsigned char *addr, u16 vid, bool vlan_aware)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200858{
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200859 struct ocelot_port *ocelot_port = ocelot->ports[port];
Alexandre Bellonia556c762018-05-14 22:04:57 +0200860
Antoine Tenart71425292018-06-26 14:28:49 +0200861 if (!vid) {
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200862 if (!vlan_aware)
Antoine Tenart71425292018-06-26 14:28:49 +0200863 /* If the bridge is not VLAN aware and no VID was
864 * provided, set it to pvid to ensure the MAC entry
865 * matches incoming untagged packets
866 */
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200867 vid = ocelot_port->pvid;
Antoine Tenart71425292018-06-26 14:28:49 +0200868 else
869 /* If the bridge is VLAN aware a VID must be provided as
870 * otherwise the learnt entry wouldn't match any frame.
871 */
872 return -EINVAL;
873 }
874
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200875 return ocelot_mact_learn(ocelot, port, addr, vid, ENTRYTYPE_LOCKED);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200876}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200877EXPORT_SYMBOL(ocelot_fdb_add);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200878
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200879static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
880 struct net_device *dev,
881 const unsigned char *addr,
882 u16 vid, u16 flags,
883 struct netlink_ext_ack *extack)
884{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200885 struct ocelot_port_private *priv = netdev_priv(dev);
886 struct ocelot *ocelot = priv->port.ocelot;
887 int port = priv->chip_port;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200888
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200889 return ocelot_fdb_add(ocelot, port, addr, vid, priv->vlan_aware);
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200890}
891
Vladimir Oltean5e256362019-11-14 17:03:27 +0200892int ocelot_fdb_del(struct ocelot *ocelot, int port,
893 const unsigned char *addr, u16 vid)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200894{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200895 return ocelot_mact_forget(ocelot, addr, vid);
896}
Vladimir Oltean5e256362019-11-14 17:03:27 +0200897EXPORT_SYMBOL(ocelot_fdb_del);
Alexandre Bellonia556c762018-05-14 22:04:57 +0200898
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200899static int ocelot_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
900 struct net_device *dev,
901 const unsigned char *addr, u16 vid)
902{
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200903 struct ocelot_port_private *priv = netdev_priv(dev);
904 struct ocelot *ocelot = priv->port.ocelot;
905 int port = priv->chip_port;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200906
Vladimir Oltean004d44f2019-11-09 15:02:53 +0200907 return ocelot_fdb_del(ocelot, port, addr, vid);
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200908}
909
Alexandre Bellonia556c762018-05-14 22:04:57 +0200910struct ocelot_dump_ctx {
911 struct net_device *dev;
912 struct sk_buff *skb;
913 struct netlink_callback *cb;
914 int idx;
915};
916
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200917static int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid,
918 bool is_static, void *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200919{
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200920 struct ocelot_dump_ctx *dump = data;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200921 u32 portid = NETLINK_CB(dump->cb->skb).portid;
922 u32 seq = dump->cb->nlh->nlmsg_seq;
923 struct nlmsghdr *nlh;
924 struct ndmsg *ndm;
925
926 if (dump->idx < dump->cb->args[2])
927 goto skip;
928
929 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
930 sizeof(*ndm), NLM_F_MULTI);
931 if (!nlh)
932 return -EMSGSIZE;
933
934 ndm = nlmsg_data(nlh);
935 ndm->ndm_family = AF_BRIDGE;
936 ndm->ndm_pad1 = 0;
937 ndm->ndm_pad2 = 0;
938 ndm->ndm_flags = NTF_SELF;
939 ndm->ndm_type = 0;
940 ndm->ndm_ifindex = dump->dev->ifindex;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200941 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
Alexandre Bellonia556c762018-05-14 22:04:57 +0200942
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200943 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
Alexandre Bellonia556c762018-05-14 22:04:57 +0200944 goto nla_put_failure;
945
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200946 if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
Alexandre Bellonia556c762018-05-14 22:04:57 +0200947 goto nla_put_failure;
948
949 nlmsg_end(dump->skb, nlh);
950
951skip:
952 dump->idx++;
953 return 0;
954
955nla_put_failure:
956 nlmsg_cancel(dump->skb, nlh);
957 return -EMSGSIZE;
958}
959
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200960static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col,
961 struct ocelot_mact_entry *entry)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200962{
Alexandre Bellonia556c762018-05-14 22:04:57 +0200963 u32 val, dst, macl, mach;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200964 char mac[ETH_ALEN];
Alexandre Bellonia556c762018-05-14 22:04:57 +0200965
966 /* Set row and column to read from */
967 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row);
968 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col);
969
970 /* Issue a read command */
971 ocelot_write(ocelot,
972 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ),
973 ANA_TABLES_MACACCESS);
974
975 if (ocelot_mact_wait_for_completion(ocelot))
976 return -ETIMEDOUT;
977
978 /* Read the entry flags */
979 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
980 if (!(val & ANA_TABLES_MACACCESS_VALID))
981 return -EINVAL;
982
983 /* If the entry read has another port configured as its destination,
984 * do not report it.
985 */
986 dst = (val & ANA_TABLES_MACACCESS_DEST_IDX_M) >> 3;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +0200987 if (dst != port)
Alexandre Bellonia556c762018-05-14 22:04:57 +0200988 return -EINVAL;
989
990 /* Get the entry's MAC address and VLAN id */
991 macl = ocelot_read(ocelot, ANA_TABLES_MACLDATA);
992 mach = ocelot_read(ocelot, ANA_TABLES_MACHDATA);
993
994 mac[0] = (mach >> 8) & 0xff;
995 mac[1] = (mach >> 0) & 0xff;
996 mac[2] = (macl >> 24) & 0xff;
997 mac[3] = (macl >> 16) & 0xff;
998 mac[4] = (macl >> 8) & 0xff;
999 mac[5] = (macl >> 0) & 0xff;
1000
1001 entry->vid = (mach >> 16) & 0xfff;
1002 ether_addr_copy(entry->mac, mac);
1003
1004 return 0;
1005}
1006
Vladimir Oltean5e256362019-11-14 17:03:27 +02001007int ocelot_fdb_dump(struct ocelot *ocelot, int port,
1008 dsa_fdb_dump_cb_t *cb, void *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001009{
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001010 int i, j;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001011
1012 /* Loop through all the mac tables entries. There are 1024 rows of 4
1013 * entries.
1014 */
1015 for (i = 0; i < 1024; i++) {
1016 for (j = 0; j < 4; j++) {
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001017 struct ocelot_mact_entry entry;
1018 bool is_static;
1019 int ret;
1020
1021 ret = ocelot_mact_read(ocelot, port, i, j, &entry);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001022 /* If the entry is invalid (wrong port, invalid...),
1023 * skip it.
1024 */
1025 if (ret == -EINVAL)
1026 continue;
1027 else if (ret)
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001028 return ret;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001029
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001030 is_static = (entry.type == ENTRYTYPE_LOCKED);
1031
1032 ret = cb(entry.mac, entry.vid, is_static, data);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001033 if (ret)
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001034 return ret;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001035 }
1036 }
1037
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001038 return 0;
1039}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001040EXPORT_SYMBOL(ocelot_fdb_dump);
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001041
1042static int ocelot_port_fdb_dump(struct sk_buff *skb,
1043 struct netlink_callback *cb,
1044 struct net_device *dev,
1045 struct net_device *filter_dev, int *idx)
1046{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001047 struct ocelot_port_private *priv = netdev_priv(dev);
1048 struct ocelot *ocelot = priv->port.ocelot;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001049 struct ocelot_dump_ctx dump = {
1050 .dev = dev,
1051 .skb = skb,
1052 .cb = cb,
1053 .idx = *idx,
1054 };
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001055 int port = priv->chip_port;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001056 int ret;
1057
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001058 ret = ocelot_fdb_dump(ocelot, port, ocelot_port_fdb_do_dump, &dump);
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001059
Alexandre Bellonia556c762018-05-14 22:04:57 +02001060 *idx = dump.idx;
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001061
Alexandre Bellonia556c762018-05-14 22:04:57 +02001062 return ret;
1063}
1064
Antoine Tenart71425292018-06-26 14:28:49 +02001065static int ocelot_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
1066 u16 vid)
1067{
Vladimir Oltean1c44ce52019-10-26 21:04:26 +03001068 return ocelot_vlan_vid_add(dev, vid, false, false);
Antoine Tenart71425292018-06-26 14:28:49 +02001069}
1070
1071static int ocelot_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
1072 u16 vid)
1073{
1074 return ocelot_vlan_vid_del(dev, vid);
1075}
1076
1077static int ocelot_set_features(struct net_device *dev,
1078 netdev_features_t features)
1079{
Antoine Tenart71425292018-06-26 14:28:49 +02001080 netdev_features_t changed = dev->features ^ features;
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001081 struct ocelot_port_private *priv = netdev_priv(dev);
1082 struct ocelot *ocelot = priv->port.ocelot;
1083 int port = priv->chip_port;
Antoine Tenart71425292018-06-26 14:28:49 +02001084
Joergen Andreasen2c1d0292019-05-28 14:49:17 +02001085 if ((dev->features & NETIF_F_HW_TC) > (features & NETIF_F_HW_TC) &&
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001086 priv->tc.offload_cnt) {
Joergen Andreasen2c1d0292019-05-28 14:49:17 +02001087 netdev_err(dev,
1088 "Cannot disable HW TC offload while offloads active\n");
1089 return -EBUSY;
1090 }
1091
Antoine Tenart71425292018-06-26 14:28:49 +02001092 if (changed & NETIF_F_HW_VLAN_CTAG_FILTER)
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001093 ocelot_vlan_mode(ocelot, port, features);
Antoine Tenart71425292018-06-26 14:28:49 +02001094
1095 return 0;
1096}
1097
Florian Fainelli751302c2019-02-06 09:45:40 -08001098static int ocelot_get_port_parent_id(struct net_device *dev,
1099 struct netdev_phys_item_id *ppid)
1100{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001101 struct ocelot_port_private *priv = netdev_priv(dev);
1102 struct ocelot *ocelot = priv->port.ocelot;
Florian Fainelli751302c2019-02-06 09:45:40 -08001103
1104 ppid->id_len = sizeof(ocelot->base_mac);
1105 memcpy(&ppid->id, &ocelot->base_mac, ppid->id_len);
1106
1107 return 0;
1108}
1109
Yangbo Luf1459222019-11-20 16:23:14 +08001110int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr)
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001111{
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001112 return copy_to_user(ifr->ifr_data, &ocelot->hwtstamp_config,
1113 sizeof(ocelot->hwtstamp_config)) ? -EFAULT : 0;
1114}
Yangbo Luf1459222019-11-20 16:23:14 +08001115EXPORT_SYMBOL(ocelot_hwstamp_get);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001116
Yangbo Luf1459222019-11-20 16:23:14 +08001117int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr)
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001118{
Vladimir Oltean306fd442019-11-09 15:02:50 +02001119 struct ocelot_port *ocelot_port = ocelot->ports[port];
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001120 struct hwtstamp_config cfg;
1121
1122 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
1123 return -EFAULT;
1124
1125 /* reserved for future extensions */
1126 if (cfg.flags)
1127 return -EINVAL;
1128
1129 /* Tx type sanity check */
1130 switch (cfg.tx_type) {
1131 case HWTSTAMP_TX_ON:
Vladimir Oltean306fd442019-11-09 15:02:50 +02001132 ocelot_port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP;
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001133 break;
1134 case HWTSTAMP_TX_ONESTEP_SYNC:
1135 /* IFH_REW_OP_ONE_STEP_PTP updates the correctional field, we
1136 * need to update the origin time.
1137 */
Vladimir Oltean306fd442019-11-09 15:02:50 +02001138 ocelot_port->ptp_cmd = IFH_REW_OP_ORIGIN_PTP;
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001139 break;
1140 case HWTSTAMP_TX_OFF:
Vladimir Oltean306fd442019-11-09 15:02:50 +02001141 ocelot_port->ptp_cmd = 0;
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001142 break;
1143 default:
1144 return -ERANGE;
1145 }
1146
1147 mutex_lock(&ocelot->ptp_lock);
1148
1149 switch (cfg.rx_filter) {
1150 case HWTSTAMP_FILTER_NONE:
1151 break;
1152 case HWTSTAMP_FILTER_ALL:
1153 case HWTSTAMP_FILTER_SOME:
1154 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
1155 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
1156 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
1157 case HWTSTAMP_FILTER_NTP_ALL:
1158 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
1159 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
1160 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
1161 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
1162 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
1163 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
1164 case HWTSTAMP_FILTER_PTP_V2_EVENT:
1165 case HWTSTAMP_FILTER_PTP_V2_SYNC:
1166 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
1167 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
1168 break;
1169 default:
1170 mutex_unlock(&ocelot->ptp_lock);
1171 return -ERANGE;
1172 }
1173
1174 /* Commit back the result & save it */
1175 memcpy(&ocelot->hwtstamp_config, &cfg, sizeof(cfg));
1176 mutex_unlock(&ocelot->ptp_lock);
1177
1178 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
1179}
Yangbo Luf1459222019-11-20 16:23:14 +08001180EXPORT_SYMBOL(ocelot_hwstamp_set);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001181
1182static int ocelot_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1183{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001184 struct ocelot_port_private *priv = netdev_priv(dev);
1185 struct ocelot *ocelot = priv->port.ocelot;
1186 int port = priv->chip_port;
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001187
1188 /* The function is only used for PTP operations for now */
1189 if (!ocelot->ptp)
1190 return -EOPNOTSUPP;
1191
1192 switch (cmd) {
1193 case SIOCSHWTSTAMP:
Vladimir Oltean306fd442019-11-09 15:02:50 +02001194 return ocelot_hwstamp_set(ocelot, port, ifr);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001195 case SIOCGHWTSTAMP:
Vladimir Oltean306fd442019-11-09 15:02:50 +02001196 return ocelot_hwstamp_get(ocelot, port, ifr);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001197 default:
1198 return -EOPNOTSUPP;
1199 }
1200}
1201
Alexandre Bellonia556c762018-05-14 22:04:57 +02001202static const struct net_device_ops ocelot_port_netdev_ops = {
1203 .ndo_open = ocelot_port_open,
1204 .ndo_stop = ocelot_port_stop,
1205 .ndo_start_xmit = ocelot_port_xmit,
1206 .ndo_set_rx_mode = ocelot_set_rx_mode,
1207 .ndo_get_phys_port_name = ocelot_port_get_phys_port_name,
1208 .ndo_set_mac_address = ocelot_port_set_mac_address,
1209 .ndo_get_stats64 = ocelot_get_stats64,
Vladimir Oltean531ee1a2019-11-09 15:02:49 +02001210 .ndo_fdb_add = ocelot_port_fdb_add,
1211 .ndo_fdb_del = ocelot_port_fdb_del,
1212 .ndo_fdb_dump = ocelot_port_fdb_dump,
Antoine Tenart71425292018-06-26 14:28:49 +02001213 .ndo_vlan_rx_add_vid = ocelot_vlan_rx_add_vid,
1214 .ndo_vlan_rx_kill_vid = ocelot_vlan_rx_kill_vid,
1215 .ndo_set_features = ocelot_set_features,
Florian Fainelli751302c2019-02-06 09:45:40 -08001216 .ndo_get_port_parent_id = ocelot_get_port_parent_id,
Joergen Andreasen2c1d0292019-05-28 14:49:17 +02001217 .ndo_setup_tc = ocelot_setup_tc,
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001218 .ndo_do_ioctl = ocelot_ioctl,
Alexandre Bellonia556c762018-05-14 22:04:57 +02001219};
1220
Vladimir Oltean5e256362019-11-14 17:03:27 +02001221void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001222{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001223 int i;
1224
1225 if (sset != ETH_SS_STATS)
1226 return;
1227
1228 for (i = 0; i < ocelot->num_stats; i++)
1229 memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name,
1230 ETH_GSTRING_LEN);
1231}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001232EXPORT_SYMBOL(ocelot_get_strings);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001233
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001234static void ocelot_port_get_strings(struct net_device *netdev, u32 sset,
1235 u8 *data)
1236{
1237 struct ocelot_port_private *priv = netdev_priv(netdev);
1238 struct ocelot *ocelot = priv->port.ocelot;
1239 int port = priv->chip_port;
1240
1241 ocelot_get_strings(ocelot, port, sset, data);
1242}
1243
Claudiu Manoil1e1caa92019-04-16 17:51:59 +03001244static void ocelot_update_stats(struct ocelot *ocelot)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001245{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001246 int i, j;
1247
1248 mutex_lock(&ocelot->stats_lock);
1249
1250 for (i = 0; i < ocelot->num_phys_ports; i++) {
1251 /* Configure the port to read the stats from */
1252 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG);
1253
1254 for (j = 0; j < ocelot->num_stats; j++) {
1255 u32 val;
1256 unsigned int idx = i * ocelot->num_stats + j;
1257
1258 val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS,
1259 ocelot->stats_layout[j].offset);
1260
1261 if (val < (ocelot->stats[idx] & U32_MAX))
1262 ocelot->stats[idx] += (u64)1 << 32;
1263
1264 ocelot->stats[idx] = (ocelot->stats[idx] &
1265 ~(u64)U32_MAX) + val;
1266 }
1267 }
1268
Claudiu Manoil1e1caa92019-04-16 17:51:59 +03001269 mutex_unlock(&ocelot->stats_lock);
1270}
1271
1272static void ocelot_check_stats_work(struct work_struct *work)
1273{
1274 struct delayed_work *del_work = to_delayed_work(work);
1275 struct ocelot *ocelot = container_of(del_work, struct ocelot,
1276 stats_work);
1277
1278 ocelot_update_stats(ocelot);
1279
Alexandre Bellonia556c762018-05-14 22:04:57 +02001280 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
1281 OCELOT_STATS_CHECK_DELAY);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001282}
1283
Vladimir Oltean5e256362019-11-14 17:03:27 +02001284void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001285{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001286 int i;
1287
1288 /* check and update now */
Claudiu Manoil1e1caa92019-04-16 17:51:59 +03001289 ocelot_update_stats(ocelot);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001290
1291 /* Copy all counters */
1292 for (i = 0; i < ocelot->num_stats; i++)
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001293 *data++ = ocelot->stats[port * ocelot->num_stats + i];
Alexandre Bellonia556c762018-05-14 22:04:57 +02001294}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001295EXPORT_SYMBOL(ocelot_get_ethtool_stats);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001296
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001297static void ocelot_port_get_ethtool_stats(struct net_device *dev,
1298 struct ethtool_stats *stats,
1299 u64 *data)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001300{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001301 struct ocelot_port_private *priv = netdev_priv(dev);
1302 struct ocelot *ocelot = priv->port.ocelot;
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001303 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001304
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001305 ocelot_get_ethtool_stats(ocelot, port, data);
1306}
1307
Vladimir Oltean5e256362019-11-14 17:03:27 +02001308int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001309{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001310 if (sset != ETH_SS_STATS)
1311 return -EOPNOTSUPP;
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001312
Alexandre Bellonia556c762018-05-14 22:04:57 +02001313 return ocelot->num_stats;
1314}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001315EXPORT_SYMBOL(ocelot_get_sset_count);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001316
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001317static int ocelot_port_get_sset_count(struct net_device *dev, int sset)
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001318{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001319 struct ocelot_port_private *priv = netdev_priv(dev);
1320 struct ocelot *ocelot = priv->port.ocelot;
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001321 int port = priv->chip_port;
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001322
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001323 return ocelot_get_sset_count(ocelot, port, sset);
1324}
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001325
Vladimir Oltean5e256362019-11-14 17:03:27 +02001326int ocelot_get_ts_info(struct ocelot *ocelot, int port,
1327 struct ethtool_ts_info *info)
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001328{
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001329 info->phc_index = ocelot->ptp_clock ?
1330 ptp_clock_index(ocelot->ptp_clock) : -1;
1331 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
1332 SOF_TIMESTAMPING_RX_SOFTWARE |
1333 SOF_TIMESTAMPING_SOFTWARE |
1334 SOF_TIMESTAMPING_TX_HARDWARE |
1335 SOF_TIMESTAMPING_RX_HARDWARE |
1336 SOF_TIMESTAMPING_RAW_HARDWARE;
1337 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON) |
1338 BIT(HWTSTAMP_TX_ONESTEP_SYNC);
1339 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
1340
1341 return 0;
1342}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001343EXPORT_SYMBOL(ocelot_get_ts_info);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001344
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001345static int ocelot_port_get_ts_info(struct net_device *dev,
1346 struct ethtool_ts_info *info)
1347{
1348 struct ocelot_port_private *priv = netdev_priv(dev);
1349 struct ocelot *ocelot = priv->port.ocelot;
1350 int port = priv->chip_port;
1351
1352 if (!ocelot->ptp)
1353 return ethtool_op_get_ts_info(dev, info);
1354
1355 return ocelot_get_ts_info(ocelot, port, info);
1356}
1357
Alexandre Bellonia556c762018-05-14 22:04:57 +02001358static const struct ethtool_ops ocelot_ethtool_ops = {
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001359 .get_strings = ocelot_port_get_strings,
1360 .get_ethtool_stats = ocelot_port_get_ethtool_stats,
1361 .get_sset_count = ocelot_port_get_sset_count,
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001362 .get_link_ksettings = phy_ethtool_get_link_ksettings,
1363 .set_link_ksettings = phy_ethtool_set_link_ksettings,
Vladimir Olteanc7282d32019-11-09 15:02:54 +02001364 .get_ts_info = ocelot_port_get_ts_info,
Alexandre Bellonia556c762018-05-14 22:04:57 +02001365};
1366
Vladimir Oltean5e256362019-11-14 17:03:27 +02001367void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001368{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001369 u32 port_cfg;
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001370 int p, i;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001371
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001372 if (!(BIT(port) & ocelot->bridge_mask))
1373 return;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001374
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001375 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001376
1377 switch (state) {
1378 case BR_STATE_FORWARDING:
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001379 ocelot->bridge_fwd_mask |= BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001380 /* Fallthrough */
1381 case BR_STATE_LEARNING:
1382 port_cfg |= ANA_PORT_PORT_CFG_LEARN_ENA;
1383 break;
1384
1385 default:
1386 port_cfg &= ~ANA_PORT_PORT_CFG_LEARN_ENA;
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001387 ocelot->bridge_fwd_mask &= ~BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001388 break;
1389 }
1390
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001391 ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001392
1393 /* Apply FWD mask. The loop is needed to add/remove the current port as
1394 * a source for the other ports.
1395 */
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001396 for (p = 0; p < ocelot->num_phys_ports; p++) {
Vladimir Olteanc9d22032019-11-09 15:03:01 +02001397 if (p == ocelot->cpu || (ocelot->bridge_fwd_mask & BIT(p))) {
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001398 unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001399
1400 for (i = 0; i < ocelot->num_phys_ports; i++) {
1401 unsigned long bond_mask = ocelot->lags[i];
1402
1403 if (!bond_mask)
1404 continue;
1405
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001406 if (bond_mask & BIT(p)) {
Alexandre Bellonia556c762018-05-14 22:04:57 +02001407 mask &= ~bond_mask;
1408 break;
1409 }
1410 }
1411
Vladimir Olteanc9d22032019-11-09 15:03:01 +02001412 /* Avoid the NPI port from looping back to itself */
1413 if (p != ocelot->cpu)
1414 mask |= BIT(ocelot->cpu);
1415
1416 ocelot_write_rix(ocelot, mask,
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001417 ANA_PGID_PGID, PGID_SRC + p);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001418 } else {
1419 /* Only the CPU port, this is compatible with link
1420 * aggregation.
1421 */
1422 ocelot_write_rix(ocelot,
Vladimir Olteanc9d22032019-11-09 15:03:01 +02001423 BIT(ocelot->cpu),
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001424 ANA_PGID_PGID, PGID_SRC + p);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001425 }
1426 }
Alexandre Bellonia556c762018-05-14 22:04:57 +02001427}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001428EXPORT_SYMBOL(ocelot_bridge_stp_state_set);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001429
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001430static void ocelot_port_attr_stp_state_set(struct ocelot *ocelot, int port,
1431 struct switchdev_trans *trans,
1432 u8 state)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001433{
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001434 if (switchdev_trans_ph_prepare(trans))
1435 return;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001436
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001437 ocelot_bridge_stp_state_set(ocelot, port, state);
1438}
1439
Vladimir Oltean5e256362019-11-14 17:03:27 +02001440void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs)
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001441{
1442 ocelot_write(ocelot, ANA_AUTOAGE_AGE_PERIOD(msecs / 2),
Alexandre Bellonia556c762018-05-14 22:04:57 +02001443 ANA_AUTOAGE);
1444}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001445EXPORT_SYMBOL(ocelot_set_ageing_time);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001446
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001447static void ocelot_port_attr_ageing_set(struct ocelot *ocelot, int port,
1448 unsigned long ageing_clock_t)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001449{
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001450 unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t);
1451 u32 ageing_time = jiffies_to_msecs(ageing_jiffies) / 1000;
1452
1453 ocelot_set_ageing_time(ocelot, ageing_time);
1454}
1455
1456static void ocelot_port_attr_mc_set(struct ocelot *ocelot, int port, bool mc)
1457{
1458 u32 cpu_fwd_mcast = ANA_PORT_CPU_FWD_CFG_CPU_IGMP_REDIR_ENA |
1459 ANA_PORT_CPU_FWD_CFG_CPU_MLD_REDIR_ENA |
1460 ANA_PORT_CPU_FWD_CFG_CPU_IPMC_CTRL_COPY_ENA;
1461 u32 val = 0;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001462
1463 if (mc)
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001464 val = cpu_fwd_mcast;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001465
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001466 ocelot_rmw_gix(ocelot, val, cpu_fwd_mcast,
1467 ANA_PORT_CPU_FWD_CFG, port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001468}
1469
1470static int ocelot_port_attr_set(struct net_device *dev,
1471 const struct switchdev_attr *attr,
1472 struct switchdev_trans *trans)
1473{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001474 struct ocelot_port_private *priv = netdev_priv(dev);
1475 struct ocelot *ocelot = priv->port.ocelot;
1476 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001477 int err = 0;
1478
1479 switch (attr->id) {
1480 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001481 ocelot_port_attr_stp_state_set(ocelot, port, trans,
Alexandre Bellonia556c762018-05-14 22:04:57 +02001482 attr->u.stp_state);
1483 break;
1484 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001485 ocelot_port_attr_ageing_set(ocelot, port, attr->u.ageing_time);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001486 break;
Antoine Tenart71425292018-06-26 14:28:49 +02001487 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001488 priv->vlan_aware = attr->u.vlan_filtering;
1489 ocelot_port_vlan_filtering(ocelot, port, priv->vlan_aware);
Antoine Tenart71425292018-06-26 14:28:49 +02001490 break;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001491 case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
Vladimir Oltean4bda1412019-11-09 15:02:51 +02001492 ocelot_port_attr_mc_set(ocelot, port, !attr->u.mc_disabled);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001493 break;
1494 default:
1495 err = -EOPNOTSUPP;
1496 break;
1497 }
1498
1499 return err;
1500}
1501
Antoine Tenart71425292018-06-26 14:28:49 +02001502static int ocelot_port_obj_add_vlan(struct net_device *dev,
1503 const struct switchdev_obj_port_vlan *vlan,
1504 struct switchdev_trans *trans)
1505{
1506 int ret;
1507 u16 vid;
1508
1509 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
1510 ret = ocelot_vlan_vid_add(dev, vid,
1511 vlan->flags & BRIDGE_VLAN_INFO_PVID,
1512 vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED);
1513 if (ret)
1514 return ret;
1515 }
1516
1517 return 0;
1518}
1519
1520static int ocelot_port_vlan_del_vlan(struct net_device *dev,
1521 const struct switchdev_obj_port_vlan *vlan)
1522{
1523 int ret;
1524 u16 vid;
1525
1526 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
1527 ret = ocelot_vlan_vid_del(dev, vid);
1528
1529 if (ret)
1530 return ret;
1531 }
1532
1533 return 0;
1534}
1535
Alexandre Bellonia556c762018-05-14 22:04:57 +02001536static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot,
1537 const unsigned char *addr,
1538 u16 vid)
1539{
1540 struct ocelot_multicast *mc;
1541
1542 list_for_each_entry(mc, &ocelot->multicast, list) {
1543 if (ether_addr_equal(mc->addr, addr) && mc->vid == vid)
1544 return mc;
1545 }
1546
1547 return NULL;
1548}
1549
1550static int ocelot_port_obj_add_mdb(struct net_device *dev,
1551 const struct switchdev_obj_port_mdb *mdb,
1552 struct switchdev_trans *trans)
1553{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001554 struct ocelot_port_private *priv = netdev_priv(dev);
1555 struct ocelot_port *ocelot_port = &priv->port;
1556 struct ocelot *ocelot = ocelot_port->ocelot;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001557 unsigned char addr[ETH_ALEN];
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001558 struct ocelot_multicast *mc;
1559 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001560 u16 vid = mdb->vid;
1561 bool new = false;
1562
1563 if (!vid)
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001564 vid = ocelot_port->pvid;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001565
1566 mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
1567 if (!mc) {
1568 mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL);
1569 if (!mc)
1570 return -ENOMEM;
1571
1572 memcpy(mc->addr, mdb->addr, ETH_ALEN);
1573 mc->vid = vid;
1574
1575 list_add_tail(&mc->list, &ocelot->multicast);
1576 new = true;
1577 }
1578
1579 memcpy(addr, mc->addr, ETH_ALEN);
1580 addr[0] = 0;
1581
1582 if (!new) {
1583 addr[2] = mc->ports << 0;
1584 addr[1] = mc->ports << 8;
1585 ocelot_mact_forget(ocelot, addr, vid);
1586 }
1587
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001588 mc->ports |= BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001589 addr[2] = mc->ports << 0;
1590 addr[1] = mc->ports << 8;
1591
1592 return ocelot_mact_learn(ocelot, 0, addr, vid, ENTRYTYPE_MACv4);
1593}
1594
1595static int ocelot_port_obj_del_mdb(struct net_device *dev,
1596 const struct switchdev_obj_port_mdb *mdb)
1597{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001598 struct ocelot_port_private *priv = netdev_priv(dev);
1599 struct ocelot_port *ocelot_port = &priv->port;
1600 struct ocelot *ocelot = ocelot_port->ocelot;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001601 unsigned char addr[ETH_ALEN];
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001602 struct ocelot_multicast *mc;
1603 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001604 u16 vid = mdb->vid;
1605
1606 if (!vid)
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001607 vid = ocelot_port->pvid;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001608
1609 mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
1610 if (!mc)
1611 return -ENOENT;
1612
1613 memcpy(addr, mc->addr, ETH_ALEN);
1614 addr[2] = mc->ports << 0;
1615 addr[1] = mc->ports << 8;
1616 addr[0] = 0;
1617 ocelot_mact_forget(ocelot, addr, vid);
1618
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001619 mc->ports &= ~BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001620 if (!mc->ports) {
1621 list_del(&mc->list);
1622 devm_kfree(ocelot->dev, mc);
1623 return 0;
1624 }
1625
1626 addr[2] = mc->ports << 0;
1627 addr[1] = mc->ports << 8;
1628
1629 return ocelot_mact_learn(ocelot, 0, addr, vid, ENTRYTYPE_MACv4);
1630}
1631
1632static int ocelot_port_obj_add(struct net_device *dev,
1633 const struct switchdev_obj *obj,
Petr Machata69213512018-12-12 17:02:56 +00001634 struct switchdev_trans *trans,
1635 struct netlink_ext_ack *extack)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001636{
1637 int ret = 0;
1638
1639 switch (obj->id) {
Antoine Tenart71425292018-06-26 14:28:49 +02001640 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1641 ret = ocelot_port_obj_add_vlan(dev,
1642 SWITCHDEV_OBJ_PORT_VLAN(obj),
1643 trans);
1644 break;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001645 case SWITCHDEV_OBJ_ID_PORT_MDB:
1646 ret = ocelot_port_obj_add_mdb(dev, SWITCHDEV_OBJ_PORT_MDB(obj),
1647 trans);
1648 break;
1649 default:
1650 return -EOPNOTSUPP;
1651 }
1652
1653 return ret;
1654}
1655
1656static int ocelot_port_obj_del(struct net_device *dev,
1657 const struct switchdev_obj *obj)
1658{
1659 int ret = 0;
1660
1661 switch (obj->id) {
Antoine Tenart71425292018-06-26 14:28:49 +02001662 case SWITCHDEV_OBJ_ID_PORT_VLAN:
1663 ret = ocelot_port_vlan_del_vlan(dev,
1664 SWITCHDEV_OBJ_PORT_VLAN(obj));
1665 break;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001666 case SWITCHDEV_OBJ_ID_PORT_MDB:
1667 ret = ocelot_port_obj_del_mdb(dev, SWITCHDEV_OBJ_PORT_MDB(obj));
1668 break;
1669 default:
1670 return -EOPNOTSUPP;
1671 }
1672
1673 return ret;
1674}
1675
Vladimir Oltean5e256362019-11-14 17:03:27 +02001676int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
1677 struct net_device *bridge)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001678{
Alexandre Bellonia556c762018-05-14 22:04:57 +02001679 if (!ocelot->bridge_mask) {
1680 ocelot->hw_bridge_dev = bridge;
1681 } else {
1682 if (ocelot->hw_bridge_dev != bridge)
1683 /* This is adding the port to a second bridge, this is
1684 * unsupported */
1685 return -ENODEV;
1686 }
1687
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001688 ocelot->bridge_mask |= BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001689
1690 return 0;
1691}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001692EXPORT_SYMBOL(ocelot_port_bridge_join);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001693
Vladimir Oltean5e256362019-11-14 17:03:27 +02001694int ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
1695 struct net_device *bridge)
Alexandre Bellonia556c762018-05-14 22:04:57 +02001696{
Vladimir Oltean97bb69e2019-11-09 15:02:47 +02001697 ocelot->bridge_mask &= ~BIT(port);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001698
1699 if (!ocelot->bridge_mask)
1700 ocelot->hw_bridge_dev = NULL;
Antoine Tenart71425292018-06-26 14:28:49 +02001701
Vladimir Oltean97bb69e2019-11-09 15:02:47 +02001702 ocelot_port_vlan_filtering(ocelot, port, 0);
1703 ocelot_port_set_pvid(ocelot, port, 0);
1704 return ocelot_port_set_native_vlan(ocelot, port, 0);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001705}
Vladimir Oltean5e256362019-11-14 17:03:27 +02001706EXPORT_SYMBOL(ocelot_port_bridge_leave);
Alexandre Bellonia556c762018-05-14 22:04:57 +02001707
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001708static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
1709{
1710 int i, port, lag;
1711
1712 /* Reset destination and aggregation PGIDS */
1713 for (port = 0; port < ocelot->num_phys_ports; port++)
1714 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
1715
1716 for (i = PGID_AGGR; i < PGID_SRC; i++)
1717 ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
1718 ANA_PGID_PGID, i);
1719
1720 /* Now, set PGIDs for each LAG */
1721 for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
1722 unsigned long bond_mask;
1723 int aggr_count = 0;
1724 u8 aggr_idx[16];
1725
1726 bond_mask = ocelot->lags[lag];
1727 if (!bond_mask)
1728 continue;
1729
1730 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
1731 // Destination mask
1732 ocelot_write_rix(ocelot, bond_mask,
1733 ANA_PGID_PGID, port);
1734 aggr_idx[aggr_count] = port;
1735 aggr_count++;
1736 }
1737
1738 for (i = PGID_AGGR; i < PGID_SRC; i++) {
1739 u32 ac;
1740
1741 ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
1742 ac &= ~bond_mask;
1743 ac |= BIT(aggr_idx[i % aggr_count]);
1744 ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i);
1745 }
1746 }
1747}
1748
1749static void ocelot_setup_lag(struct ocelot *ocelot, int lag)
1750{
1751 unsigned long bond_mask = ocelot->lags[lag];
1752 unsigned int p;
1753
1754 for_each_set_bit(p, &bond_mask, ocelot->num_phys_ports) {
1755 u32 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p);
1756
1757 port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M;
1758
1759 /* Use lag port as logical port for port i */
1760 ocelot_write_gix(ocelot, port_cfg |
1761 ANA_PORT_PORT_CFG_PORTID_VAL(lag),
1762 ANA_PORT_PORT_CFG, p);
1763 }
1764}
1765
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001766static int ocelot_port_lag_join(struct ocelot *ocelot, int port,
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001767 struct net_device *bond)
1768{
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001769 struct net_device *ndev;
1770 u32 bond_mask = 0;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001771 int lag, lp;
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001772
1773 rcu_read_lock();
1774 for_each_netdev_in_bond_rcu(bond, ndev) {
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001775 struct ocelot_port_private *priv = netdev_priv(ndev);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001776
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001777 bond_mask |= BIT(priv->chip_port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001778 }
1779 rcu_read_unlock();
1780
1781 lp = __ffs(bond_mask);
1782
1783 /* If the new port is the lowest one, use it as the logical port from
1784 * now on
1785 */
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001786 if (port == lp) {
1787 lag = port;
1788 ocelot->lags[port] = bond_mask;
1789 bond_mask &= ~BIT(port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001790 if (bond_mask) {
1791 lp = __ffs(bond_mask);
1792 ocelot->lags[lp] = 0;
1793 }
1794 } else {
1795 lag = lp;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001796 ocelot->lags[lp] |= BIT(port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001797 }
1798
1799 ocelot_setup_lag(ocelot, lag);
1800 ocelot_set_aggr_pgids(ocelot);
1801
1802 return 0;
1803}
1804
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001805static void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001806 struct net_device *bond)
1807{
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001808 u32 port_cfg;
1809 int i;
1810
1811 /* Remove port from any lag */
1812 for (i = 0; i < ocelot->num_phys_ports; i++)
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001813 ocelot->lags[i] &= ~BIT(port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001814
1815 /* if it was the logical port of the lag, move the lag config to the
1816 * next port
1817 */
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001818 if (ocelot->lags[port]) {
1819 int n = __ffs(ocelot->lags[port]);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001820
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001821 ocelot->lags[n] = ocelot->lags[port];
1822 ocelot->lags[port] = 0;
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001823
1824 ocelot_setup_lag(ocelot, n);
1825 }
1826
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001827 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001828 port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001829 ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port),
1830 ANA_PORT_PORT_CFG, port);
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001831
1832 ocelot_set_aggr_pgids(ocelot);
1833}
1834
Alexandre Bellonia556c762018-05-14 22:04:57 +02001835/* Checks if the net_device instance given to us originate from our driver. */
1836static bool ocelot_netdevice_dev_check(const struct net_device *dev)
1837{
1838 return dev->netdev_ops == &ocelot_port_netdev_ops;
1839}
1840
1841static int ocelot_netdevice_port_event(struct net_device *dev,
1842 unsigned long event,
1843 struct netdev_notifier_changeupper_info *info)
1844{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001845 struct ocelot_port_private *priv = netdev_priv(dev);
1846 struct ocelot_port *ocelot_port = &priv->port;
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001847 struct ocelot *ocelot = ocelot_port->ocelot;
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001848 int port = priv->chip_port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001849 int err = 0;
1850
Alexandre Bellonia556c762018-05-14 22:04:57 +02001851 switch (event) {
1852 case NETDEV_CHANGEUPPER:
1853 if (netif_is_bridge_master(info->upper_dev)) {
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001854 if (info->linking) {
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001855 err = ocelot_port_bridge_join(ocelot, port,
Alexandre Bellonia556c762018-05-14 22:04:57 +02001856 info->upper_dev);
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001857 } else {
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001858 err = ocelot_port_bridge_leave(ocelot, port,
Vladimir Oltean97bb69e2019-11-09 15:02:47 +02001859 info->upper_dev);
Vladimir Oltean004d44f2019-11-09 15:02:53 +02001860 priv->vlan_aware = false;
1861 }
Alexandre Bellonia556c762018-05-14 22:04:57 +02001862 }
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001863 if (netif_is_lag_master(info->upper_dev)) {
1864 if (info->linking)
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001865 err = ocelot_port_lag_join(ocelot, port,
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001866 info->upper_dev);
1867 else
Vladimir Olteanf270dbf2019-11-09 15:02:52 +02001868 ocelot_port_lag_leave(ocelot, port,
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001869 info->upper_dev);
1870 }
Alexandre Bellonia556c762018-05-14 22:04:57 +02001871 break;
1872 default:
1873 break;
1874 }
1875
1876 return err;
1877}
1878
1879static int ocelot_netdevice_event(struct notifier_block *unused,
1880 unsigned long event, void *ptr)
1881{
1882 struct netdev_notifier_changeupper_info *info = ptr;
1883 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Geert Uytterhoeven2ac0e152018-06-07 15:10:30 +02001884 int ret = 0;
Alexandre Bellonia556c762018-05-14 22:04:57 +02001885
Claudiu Manoil7afb3e52019-11-05 23:50:13 +02001886 if (!ocelot_netdevice_dev_check(dev))
1887 return 0;
1888
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001889 if (event == NETDEV_PRECHANGEUPPER &&
1890 netif_is_lag_master(info->upper_dev)) {
1891 struct netdev_lag_upper_info *lag_upper_info = info->upper_info;
1892 struct netlink_ext_ack *extack;
1893
Claudiu Manoil3b3eed82019-11-05 23:50:14 +02001894 if (lag_upper_info &&
1895 lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02001896 extack = netdev_notifier_info_to_extack(&info->info);
1897 NL_SET_ERR_MSG_MOD(extack, "LAG device using unsupported Tx type");
1898
1899 ret = -EINVAL;
1900 goto notify;
1901 }
1902 }
1903
Alexandre Bellonia556c762018-05-14 22:04:57 +02001904 if (netif_is_lag_master(dev)) {
1905 struct net_device *slave;
1906 struct list_head *iter;
1907
1908 netdev_for_each_lower_dev(dev, slave, iter) {
1909 ret = ocelot_netdevice_port_event(slave, event, info);
1910 if (ret)
1911 goto notify;
1912 }
1913 } else {
1914 ret = ocelot_netdevice_port_event(dev, event, info);
1915 }
1916
1917notify:
1918 return notifier_from_errno(ret);
1919}
1920
1921struct notifier_block ocelot_netdevice_nb __read_mostly = {
1922 .notifier_call = ocelot_netdevice_event,
1923};
1924EXPORT_SYMBOL(ocelot_netdevice_nb);
1925
Florian Fainelli56da64b2019-02-27 11:44:29 -08001926static int ocelot_switchdev_event(struct notifier_block *unused,
1927 unsigned long event, void *ptr)
1928{
1929 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1930 int err;
1931
1932 switch (event) {
1933 case SWITCHDEV_PORT_ATTR_SET:
1934 err = switchdev_handle_port_attr_set(dev, ptr,
1935 ocelot_netdevice_dev_check,
1936 ocelot_port_attr_set);
1937 return notifier_from_errno(err);
1938 }
1939
1940 return NOTIFY_DONE;
1941}
1942
1943struct notifier_block ocelot_switchdev_nb __read_mostly = {
1944 .notifier_call = ocelot_switchdev_event,
1945};
1946EXPORT_SYMBOL(ocelot_switchdev_nb);
1947
Petr Machata0e332c82018-11-22 23:30:11 +00001948static int ocelot_switchdev_blocking_event(struct notifier_block *unused,
1949 unsigned long event, void *ptr)
1950{
1951 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1952 int err;
1953
1954 switch (event) {
1955 /* Blocking events. */
1956 case SWITCHDEV_PORT_OBJ_ADD:
1957 err = switchdev_handle_port_obj_add(dev, ptr,
1958 ocelot_netdevice_dev_check,
1959 ocelot_port_obj_add);
1960 return notifier_from_errno(err);
1961 case SWITCHDEV_PORT_OBJ_DEL:
1962 err = switchdev_handle_port_obj_del(dev, ptr,
1963 ocelot_netdevice_dev_check,
1964 ocelot_port_obj_del);
1965 return notifier_from_errno(err);
Florian Fainelli56da64b2019-02-27 11:44:29 -08001966 case SWITCHDEV_PORT_ATTR_SET:
1967 err = switchdev_handle_port_attr_set(dev, ptr,
1968 ocelot_netdevice_dev_check,
1969 ocelot_port_attr_set);
1970 return notifier_from_errno(err);
Petr Machata0e332c82018-11-22 23:30:11 +00001971 }
1972
1973 return NOTIFY_DONE;
1974}
1975
1976struct notifier_block ocelot_switchdev_blocking_nb __read_mostly = {
1977 .notifier_call = ocelot_switchdev_blocking_event,
1978};
1979EXPORT_SYMBOL(ocelot_switchdev_blocking_nb);
1980
Antoine Tenart4e3b0462019-08-12 16:45:37 +02001981int ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts)
1982{
1983 struct ocelot *ocelot = container_of(ptp, struct ocelot, ptp_info);
1984 unsigned long flags;
1985 time64_t s;
1986 u32 val;
1987 s64 ns;
1988
1989 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
1990
1991 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
1992 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
1993 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_SAVE);
1994 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
1995
1996 s = ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_MSB, TOD_ACC_PIN) & 0xffff;
1997 s <<= 32;
1998 s += ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN);
1999 ns = ocelot_read_rix(ocelot, PTP_PIN_TOD_NSEC, TOD_ACC_PIN);
2000
2001 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
2002
2003 /* Deal with negative values */
2004 if (ns >= 0x3ffffff0 && ns <= 0x3fffffff) {
2005 s--;
2006 ns &= 0xf;
2007 ns += 999999984;
2008 }
2009
2010 set_normalized_timespec64(ts, s, ns);
2011 return 0;
2012}
2013EXPORT_SYMBOL(ocelot_ptp_gettime64);
2014
2015static int ocelot_ptp_settime64(struct ptp_clock_info *ptp,
2016 const struct timespec64 *ts)
2017{
2018 struct ocelot *ocelot = container_of(ptp, struct ocelot, ptp_info);
2019 unsigned long flags;
2020 u32 val;
2021
2022 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
2023
2024 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
2025 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
2026 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_IDLE);
2027
2028 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
2029
2030 ocelot_write_rix(ocelot, lower_32_bits(ts->tv_sec), PTP_PIN_TOD_SEC_LSB,
2031 TOD_ACC_PIN);
2032 ocelot_write_rix(ocelot, upper_32_bits(ts->tv_sec), PTP_PIN_TOD_SEC_MSB,
2033 TOD_ACC_PIN);
2034 ocelot_write_rix(ocelot, ts->tv_nsec, PTP_PIN_TOD_NSEC, TOD_ACC_PIN);
2035
2036 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
2037 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
2038 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_LOAD);
2039
2040 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
2041
2042 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
2043 return 0;
2044}
2045
2046static int ocelot_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
2047{
2048 if (delta > -(NSEC_PER_SEC / 2) && delta < (NSEC_PER_SEC / 2)) {
2049 struct ocelot *ocelot = container_of(ptp, struct ocelot, ptp_info);
2050 unsigned long flags;
2051 u32 val;
2052
2053 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
2054
2055 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
2056 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
2057 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_IDLE);
2058
2059 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
2060
2061 ocelot_write_rix(ocelot, 0, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN);
2062 ocelot_write_rix(ocelot, 0, PTP_PIN_TOD_SEC_MSB, TOD_ACC_PIN);
2063 ocelot_write_rix(ocelot, delta, PTP_PIN_TOD_NSEC, TOD_ACC_PIN);
2064
2065 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN);
2066 val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM);
2067 val |= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_DELTA);
2068
2069 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN);
2070
2071 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
2072 } else {
2073 /* Fall back using ocelot_ptp_settime64 which is not exact. */
2074 struct timespec64 ts;
2075 u64 now;
2076
2077 ocelot_ptp_gettime64(ptp, &ts);
2078
2079 now = ktime_to_ns(timespec64_to_ktime(ts));
2080 ts = ns_to_timespec64(now + delta);
2081
2082 ocelot_ptp_settime64(ptp, &ts);
2083 }
2084 return 0;
2085}
2086
2087static int ocelot_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
2088{
2089 struct ocelot *ocelot = container_of(ptp, struct ocelot, ptp_info);
2090 u32 unit = 0, direction = 0;
2091 unsigned long flags;
2092 u64 adj = 0;
2093
2094 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
2095
2096 if (!scaled_ppm)
2097 goto disable_adj;
2098
2099 if (scaled_ppm < 0) {
2100 direction = PTP_CFG_CLK_ADJ_CFG_DIR;
2101 scaled_ppm = -scaled_ppm;
2102 }
2103
2104 adj = PSEC_PER_SEC << 16;
2105 do_div(adj, scaled_ppm);
2106 do_div(adj, 1000);
2107
2108 /* If the adjustment value is too large, use ns instead */
2109 if (adj >= (1L << 30)) {
2110 unit = PTP_CFG_CLK_ADJ_FREQ_NS;
2111 do_div(adj, 1000);
2112 }
2113
2114 /* Still too big */
2115 if (adj >= (1L << 30))
2116 goto disable_adj;
2117
2118 ocelot_write(ocelot, unit | adj, PTP_CLK_CFG_ADJ_FREQ);
2119 ocelot_write(ocelot, PTP_CFG_CLK_ADJ_CFG_ENA | direction,
2120 PTP_CLK_CFG_ADJ_CFG);
2121
2122 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
2123 return 0;
2124
2125disable_adj:
2126 ocelot_write(ocelot, 0, PTP_CLK_CFG_ADJ_CFG);
2127
2128 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
2129 return 0;
2130}
2131
2132static struct ptp_clock_info ocelot_ptp_clock_info = {
2133 .owner = THIS_MODULE,
2134 .name = "ocelot ptp",
2135 .max_adj = 0x7fffffff,
2136 .n_alarm = 0,
2137 .n_ext_ts = 0,
2138 .n_per_out = 0,
2139 .n_pins = 0,
2140 .pps = 0,
2141 .gettime64 = ocelot_ptp_gettime64,
2142 .settime64 = ocelot_ptp_settime64,
2143 .adjtime = ocelot_ptp_adjtime,
2144 .adjfine = ocelot_ptp_adjfine,
2145};
2146
2147static int ocelot_init_timestamp(struct ocelot *ocelot)
2148{
2149 ocelot->ptp_info = ocelot_ptp_clock_info;
2150 ocelot->ptp_clock = ptp_clock_register(&ocelot->ptp_info, ocelot->dev);
2151 if (IS_ERR(ocelot->ptp_clock))
2152 return PTR_ERR(ocelot->ptp_clock);
2153 /* Check if PHC support is missing at the configuration level */
2154 if (!ocelot->ptp_clock)
2155 return 0;
2156
2157 ocelot_write(ocelot, SYS_PTP_CFG_PTP_STAMP_WID(30), SYS_PTP_CFG);
2158 ocelot_write(ocelot, 0xffffffff, ANA_TABLES_PTP_ID_LOW);
2159 ocelot_write(ocelot, 0xffffffff, ANA_TABLES_PTP_ID_HIGH);
2160
2161 ocelot_write(ocelot, PTP_CFG_MISC_PTP_EN, PTP_CFG_MISC);
2162
2163 /* There is no device reconfiguration, PTP Rx stamping is always
2164 * enabled.
2165 */
2166 ocelot->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
2167
2168 return 0;
2169}
2170
Vladimir Olteanfa914e92019-11-14 17:03:23 +02002171static void ocelot_port_set_mtu(struct ocelot *ocelot, int port, size_t mtu)
Vladimir Oltean31350d72019-11-09 15:02:56 +02002172{
2173 struct ocelot_port *ocelot_port = ocelot->ports[port];
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +02002174 int atop_wm;
Vladimir Oltean31350d72019-11-09 15:02:56 +02002175
Vladimir Olteanfa914e92019-11-14 17:03:23 +02002176 ocelot_port_writel(ocelot_port, mtu, DEV_MAC_MAXLEN_CFG);
2177
2178 /* Set Pause WM hysteresis
2179 * 152 = 6 * mtu / OCELOT_BUFFER_CELL_SZ
2180 * 101 = 4 * mtu / OCELOT_BUFFER_CELL_SZ
2181 */
2182 ocelot_write_rix(ocelot, SYS_PAUSE_CFG_PAUSE_ENA |
2183 SYS_PAUSE_CFG_PAUSE_STOP(101) |
2184 SYS_PAUSE_CFG_PAUSE_START(152), SYS_PAUSE_CFG, port);
2185
2186 /* Tail dropping watermark */
2187 atop_wm = (ocelot->shared_queue_sz - 9 * mtu) / OCELOT_BUFFER_CELL_SZ;
2188 ocelot_write_rix(ocelot, ocelot_wm_enc(9 * mtu),
2189 SYS_ATOP, port);
2190 ocelot_write(ocelot, ocelot_wm_enc(atop_wm), SYS_ATOP_TOT_CFG);
2191}
2192
Vladimir Oltean5e256362019-11-14 17:03:27 +02002193void ocelot_init_port(struct ocelot *ocelot, int port)
Vladimir Olteanfa914e92019-11-14 17:03:23 +02002194{
2195 struct ocelot_port *ocelot_port = ocelot->ports[port];
2196
Vladimir Oltean31350d72019-11-09 15:02:56 +02002197 INIT_LIST_HEAD(&ocelot_port->skbs);
2198
2199 /* Basic L2 initialization */
2200
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +02002201 /* Set MAC IFG Gaps
2202 * FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 0
2203 * !FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 5
2204 */
2205 ocelot_port_writel(ocelot_port, DEV_MAC_IFG_CFG_TX_IFG(5),
2206 DEV_MAC_IFG_CFG);
2207
2208 /* Load seed (0) and set MAC HDX late collision */
2209 ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
2210 DEV_MAC_HDX_CFG_SEED_LOAD,
2211 DEV_MAC_HDX_CFG);
2212 mdelay(1);
2213 ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
2214 DEV_MAC_HDX_CFG);
2215
2216 /* Set Max Length and maximum tags allowed */
Vladimir Olteanfa914e92019-11-14 17:03:23 +02002217 ocelot_port_set_mtu(ocelot, port, VLAN_ETH_FRAME_LEN);
Vladimir Oltean5bc9d2e2019-11-14 17:03:22 +02002218 ocelot_port_writel(ocelot_port, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD) |
2219 DEV_MAC_TAGS_CFG_VLAN_AWR_ENA |
2220 DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA,
2221 DEV_MAC_TAGS_CFG);
2222
2223 /* Set SMAC of Pause frame (00:00:00:00:00:00) */
2224 ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_HIGH_CFG);
2225 ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_LOW_CFG);
2226
Vladimir Oltean31350d72019-11-09 15:02:56 +02002227 /* Drop frames with multicast source address */
2228 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
2229 ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
2230 ANA_PORT_DROP_CFG, port);
2231
2232 /* Set default VLAN and tag type to 8021Q. */
2233 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q),
2234 REW_PORT_VLAN_CFG_PORT_TPID_M,
2235 REW_PORT_VLAN_CFG, port);
2236
2237 /* Enable vcap lookups */
2238 ocelot_vcap_enable(ocelot, port);
2239}
Vladimir Oltean5e256362019-11-14 17:03:27 +02002240EXPORT_SYMBOL(ocelot_init_port);
Vladimir Oltean31350d72019-11-09 15:02:56 +02002241
Alexandre Bellonia556c762018-05-14 22:04:57 +02002242int ocelot_probe_port(struct ocelot *ocelot, u8 port,
2243 void __iomem *regs,
2244 struct phy_device *phy)
2245{
Vladimir Oltean004d44f2019-11-09 15:02:53 +02002246 struct ocelot_port_private *priv;
Alexandre Bellonia556c762018-05-14 22:04:57 +02002247 struct ocelot_port *ocelot_port;
2248 struct net_device *dev;
2249 int err;
2250
Vladimir Oltean004d44f2019-11-09 15:02:53 +02002251 dev = alloc_etherdev(sizeof(struct ocelot_port_private));
Alexandre Bellonia556c762018-05-14 22:04:57 +02002252 if (!dev)
2253 return -ENOMEM;
2254 SET_NETDEV_DEV(dev, ocelot->dev);
Vladimir Oltean004d44f2019-11-09 15:02:53 +02002255 priv = netdev_priv(dev);
2256 priv->dev = dev;
2257 priv->phy = phy;
2258 priv->chip_port = port;
2259 ocelot_port = &priv->port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02002260 ocelot_port->ocelot = ocelot;
2261 ocelot_port->regs = regs;
Alexandre Bellonia556c762018-05-14 22:04:57 +02002262 ocelot->ports[port] = ocelot_port;
2263
2264 dev->netdev_ops = &ocelot_port_netdev_ops;
2265 dev->ethtool_ops = &ocelot_ethtool_ops;
Alexandre Bellonia556c762018-05-14 22:04:57 +02002266
Joergen Andreasen2c1d0292019-05-28 14:49:17 +02002267 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXFCS |
2268 NETIF_F_HW_TC;
2269 dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_TC;
Antoine Tenart71425292018-06-26 14:28:49 +02002270
Alexandre Bellonia556c762018-05-14 22:04:57 +02002271 memcpy(dev->dev_addr, ocelot->base_mac, ETH_ALEN);
2272 dev->dev_addr[ETH_ALEN - 1] += port;
2273 ocelot_mact_learn(ocelot, PGID_CPU, dev->dev_addr, ocelot_port->pvid,
2274 ENTRYTYPE_LOCKED);
2275
Vladimir Oltean31350d72019-11-09 15:02:56 +02002276 ocelot_init_port(ocelot, port);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02002277
Alexandre Bellonia556c762018-05-14 22:04:57 +02002278 err = register_netdev(dev);
2279 if (err) {
2280 dev_err(ocelot->dev, "register_netdev failed\n");
Vladimir Oltean31350d72019-11-09 15:02:56 +02002281 free_netdev(dev);
Alexandre Bellonia556c762018-05-14 22:04:57 +02002282 }
2283
Alexandre Bellonia556c762018-05-14 22:04:57 +02002284 return err;
2285}
2286EXPORT_SYMBOL(ocelot_probe_port);
2287
Vladimir Oltean21468192019-11-09 15:03:00 +02002288void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu,
2289 enum ocelot_tag_prefix injection,
2290 enum ocelot_tag_prefix extraction)
2291{
2292 /* Configure and enable the CPU port. */
2293 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu);
2294 ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU);
2295 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA |
2296 ANA_PORT_PORT_CFG_PORTID_VAL(cpu),
2297 ANA_PORT_PORT_CFG, cpu);
2298
2299 /* If the CPU port is a physical port, set up the port in Node
2300 * Processor Interface (NPI) mode. This is the mode through which
2301 * frames can be injected from and extracted to an external CPU.
2302 * Only one port can be an NPI at the same time.
2303 */
2304 if (cpu < ocelot->num_phys_ports) {
Vladimir Olteanba551bc2019-11-14 17:03:25 +02002305 int mtu = VLAN_ETH_FRAME_LEN + OCELOT_TAG_LEN;
2306
Vladimir Oltean21468192019-11-09 15:03:00 +02002307 ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M |
2308 QSYS_EXT_CPU_CFG_EXT_CPU_PORT(cpu),
2309 QSYS_EXT_CPU_CFG);
Vladimir Olteanba551bc2019-11-14 17:03:25 +02002310
2311 if (injection == OCELOT_TAG_PREFIX_SHORT)
2312 mtu += OCELOT_SHORT_PREFIX_LEN;
2313 else if (injection == OCELOT_TAG_PREFIX_LONG)
2314 mtu += OCELOT_LONG_PREFIX_LEN;
2315
2316 ocelot_port_set_mtu(ocelot, cpu, mtu);
Vladimir Oltean21468192019-11-09 15:03:00 +02002317 }
2318
2319 /* CPU port Injection/Extraction configuration */
2320 ocelot_write_rix(ocelot, QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE |
2321 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG(1) |
2322 QSYS_SWITCH_PORT_MODE_PORT_ENA,
2323 QSYS_SWITCH_PORT_MODE, cpu);
2324 ocelot_write_rix(ocelot, SYS_PORT_MODE_INCL_XTR_HDR(extraction) |
2325 SYS_PORT_MODE_INCL_INJ_HDR(injection),
2326 SYS_PORT_MODE, cpu);
2327
2328 /* Configure the CPU port to be VLAN aware */
2329 ocelot_write_gix(ocelot, ANA_PORT_VLAN_CFG_VLAN_VID(0) |
2330 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
2331 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1),
2332 ANA_PORT_VLAN_CFG, cpu);
2333
2334 ocelot->cpu = cpu;
2335}
2336EXPORT_SYMBOL(ocelot_set_cpu_port);
2337
Alexandre Bellonia556c762018-05-14 22:04:57 +02002338int ocelot_init(struct ocelot *ocelot)
2339{
Alexandre Bellonia556c762018-05-14 22:04:57 +02002340 char queue_name[32];
Vladimir Oltean21468192019-11-09 15:03:00 +02002341 int i, ret;
2342 u32 port;
Alexandre Bellonia556c762018-05-14 22:04:57 +02002343
Vladimir Oltean3a77b592019-11-14 17:03:26 +02002344 if (ocelot->ops->reset) {
2345 ret = ocelot->ops->reset(ocelot);
2346 if (ret) {
2347 dev_err(ocelot->dev, "Switch reset failed\n");
2348 return ret;
2349 }
2350 }
2351
Alexandre Bellonidc96ee32018-06-26 14:28:48 +02002352 ocelot->lags = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports,
2353 sizeof(u32), GFP_KERNEL);
2354 if (!ocelot->lags)
2355 return -ENOMEM;
2356
Alexandre Bellonia556c762018-05-14 22:04:57 +02002357 ocelot->stats = devm_kcalloc(ocelot->dev,
2358 ocelot->num_phys_ports * ocelot->num_stats,
2359 sizeof(u64), GFP_KERNEL);
2360 if (!ocelot->stats)
2361 return -ENOMEM;
2362
2363 mutex_init(&ocelot->stats_lock);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02002364 mutex_init(&ocelot->ptp_lock);
2365 spin_lock_init(&ocelot->ptp_clock_lock);
Alexandre Bellonia556c762018-05-14 22:04:57 +02002366 snprintf(queue_name, sizeof(queue_name), "%s-stats",
2367 dev_name(ocelot->dev));
2368 ocelot->stats_queue = create_singlethread_workqueue(queue_name);
2369 if (!ocelot->stats_queue)
2370 return -ENOMEM;
2371
Claudiu Manoil2b120dd2019-11-09 15:02:58 +02002372 INIT_LIST_HEAD(&ocelot->multicast);
Alexandre Bellonia556c762018-05-14 22:04:57 +02002373 ocelot_mact_init(ocelot);
2374 ocelot_vlan_init(ocelot);
Horatiu Vulturb5962292019-05-31 09:16:56 +02002375 ocelot_ace_init(ocelot);
Alexandre Bellonia556c762018-05-14 22:04:57 +02002376
2377 for (port = 0; port < ocelot->num_phys_ports; port++) {
2378 /* Clear all counters (5 groups) */
2379 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) |
2380 SYS_STAT_CFG_STAT_CLEAR_SHOT(0x7f),
2381 SYS_STAT_CFG);
2382 }
2383
2384 /* Only use S-Tag */
2385 ocelot_write(ocelot, ETH_P_8021AD, SYS_VLAN_ETYPE_CFG);
2386
2387 /* Aggregation mode */
2388 ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA |
2389 ANA_AGGR_CFG_AC_DMAC_ENA |
2390 ANA_AGGR_CFG_AC_IP4_SIPDIP_ENA |
2391 ANA_AGGR_CFG_AC_IP4_TCPUDP_ENA, ANA_AGGR_CFG);
2392
2393 /* Set MAC age time to default value. The entry is aged after
2394 * 2*AGE_PERIOD
2395 */
2396 ocelot_write(ocelot,
2397 ANA_AUTOAGE_AGE_PERIOD(BR_DEFAULT_AGEING_TIME / 2 / HZ),
2398 ANA_AUTOAGE);
2399
2400 /* Disable learning for frames discarded by VLAN ingress filtering */
2401 regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1);
2402
2403 /* Setup frame ageing - fixed value "2 sec" - in 6.5 us units */
2404 ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA |
2405 SYS_FRM_AGING_MAX_AGE(307692), SYS_FRM_AGING);
2406
2407 /* Setup flooding PGIDs */
2408 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) |
2409 ANA_FLOODING_FLD_BROADCAST(PGID_MC) |
2410 ANA_FLOODING_FLD_UNICAST(PGID_UC),
2411 ANA_FLOODING, 0);
2412 ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) |
2413 ANA_FLOODING_IPMC_FLD_MC6_CTRL(PGID_MC) |
2414 ANA_FLOODING_IPMC_FLD_MC4_DATA(PGID_MCIPV4) |
2415 ANA_FLOODING_IPMC_FLD_MC4_CTRL(PGID_MC),
2416 ANA_FLOODING_IPMC);
2417
2418 for (port = 0; port < ocelot->num_phys_ports; port++) {
2419 /* Transmit the frame to the local port. */
2420 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
2421 /* Do not forward BPDU frames to the front ports. */
2422 ocelot_write_gix(ocelot,
2423 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
2424 ANA_PORT_CPU_FWD_BPDU_CFG,
2425 port);
2426 /* Ensure bridging is disabled */
2427 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port);
2428 }
2429
Alexandre Bellonia556c762018-05-14 22:04:57 +02002430 /* Allow broadcast MAC frames. */
2431 for (i = ocelot->num_phys_ports + 1; i < PGID_CPU; i++) {
2432 u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0));
2433
2434 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
2435 }
2436 ocelot_write_rix(ocelot,
2437 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)),
2438 ANA_PGID_PGID, PGID_MC);
2439 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV4);
2440 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV6);
2441
Alexandre Bellonia556c762018-05-14 22:04:57 +02002442 /* Allow manual injection via DEVCPU_QS registers, and byte swap these
2443 * registers endianness.
2444 */
2445 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_BYTE_SWAP |
2446 QS_INJ_GRP_CFG_MODE(1), QS_INJ_GRP_CFG, 0);
2447 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_BYTE_SWAP |
2448 QS_XTR_GRP_CFG_MODE(1), QS_XTR_GRP_CFG, 0);
2449 ocelot_write(ocelot, ANA_CPUQ_CFG_CPUQ_MIRROR(2) |
2450 ANA_CPUQ_CFG_CPUQ_LRN(2) |
2451 ANA_CPUQ_CFG_CPUQ_MAC_COPY(2) |
2452 ANA_CPUQ_CFG_CPUQ_SRC_COPY(2) |
2453 ANA_CPUQ_CFG_CPUQ_LOCKED_PORTMOVE(2) |
2454 ANA_CPUQ_CFG_CPUQ_ALLBRIDGE(6) |
2455 ANA_CPUQ_CFG_CPUQ_IPMC_CTRL(6) |
2456 ANA_CPUQ_CFG_CPUQ_IGMP(6) |
2457 ANA_CPUQ_CFG_CPUQ_MLD(6), ANA_CPUQ_CFG);
2458 for (i = 0; i < 16; i++)
2459 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) |
2460 ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
2461 ANA_CPUQ_8021_CFG, i);
2462
Claudiu Manoil1e1caa92019-04-16 17:51:59 +03002463 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work);
Alexandre Bellonia556c762018-05-14 22:04:57 +02002464 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
2465 OCELOT_STATS_CHECK_DELAY);
Antoine Tenart4e3b0462019-08-12 16:45:37 +02002466
2467 if (ocelot->ptp) {
2468 ret = ocelot_init_timestamp(ocelot);
2469 if (ret) {
2470 dev_err(ocelot->dev,
2471 "Timestamp initialization failed\n");
2472 return ret;
2473 }
2474 }
2475
Alexandre Bellonia556c762018-05-14 22:04:57 +02002476 return 0;
2477}
2478EXPORT_SYMBOL(ocelot_init);
2479
2480void ocelot_deinit(struct ocelot *ocelot)
2481{
Antoine Tenart4e3b0462019-08-12 16:45:37 +02002482 struct list_head *pos, *tmp;
2483 struct ocelot_port *port;
2484 struct ocelot_skb *entry;
2485 int i;
2486
Claudiu Manoilc5d13962019-07-25 16:33:18 +03002487 cancel_delayed_work(&ocelot->stats_work);
Alexandre Bellonia556c762018-05-14 22:04:57 +02002488 destroy_workqueue(ocelot->stats_queue);
2489 mutex_destroy(&ocelot->stats_lock);
Horatiu Vulturb5962292019-05-31 09:16:56 +02002490 ocelot_ace_deinit();
Antoine Tenart4e3b0462019-08-12 16:45:37 +02002491
2492 for (i = 0; i < ocelot->num_phys_ports; i++) {
2493 port = ocelot->ports[i];
2494
2495 list_for_each_safe(pos, tmp, &port->skbs) {
2496 entry = list_entry(pos, struct ocelot_skb, head);
2497
2498 list_del(pos);
2499 dev_kfree_skb_any(entry->skb);
2500 kfree(entry);
2501 }
2502 }
Alexandre Bellonia556c762018-05-14 22:04:57 +02002503}
2504EXPORT_SYMBOL(ocelot_deinit);
2505
2506MODULE_LICENSE("Dual MIT/GPL");