1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Microsemi Ocelot Switch driver
5 * Copyright (c) 2017 Microsemi Corporation
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>
17 #include <linux/ptp_clock_kernel.h>
18 #include <linux/skbuff.h>
19 #include <linux/iopoll.h>
21 #include <net/netevent.h>
22 #include <net/rtnetlink.h>
23 #include <net/switchdev.h>
26 #include "ocelot_ace.h"
28 #define TABLE_UPDATE_SLEEP_US 10
29 #define TABLE_UPDATE_TIMEOUT_US 100000
31 /* 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.
37 enum macaccess_entry_type
{
44 struct ocelot_mact_entry
{
47 enum macaccess_entry_type type
;
50 static inline u32
ocelot_mact_read_macaccess(struct ocelot
*ocelot
)
52 return ocelot_read(ocelot
, ANA_TABLES_MACACCESS
);
55 static inline int ocelot_mact_wait_for_completion(struct ocelot
*ocelot
)
59 return readx_poll_timeout(ocelot_mact_read_macaccess
,
61 (val
& ANA_TABLES_MACACCESS_MAC_TABLE_CMD_M
) ==
63 TABLE_UPDATE_SLEEP_US
, TABLE_UPDATE_TIMEOUT_US
);
66 static void ocelot_mact_select(struct ocelot
*ocelot
,
67 const unsigned char mac
[ETH_ALEN
],
70 u32 macl
= 0, mach
= 0;
72 /* Set the MAC address to handle and the vlan associated in a format
73 * understood by the hardware.
83 ocelot_write(ocelot
, macl
, ANA_TABLES_MACLDATA
);
84 ocelot_write(ocelot
, mach
, ANA_TABLES_MACHDATA
);
88 static int ocelot_mact_learn(struct ocelot
*ocelot
, int port
,
89 const unsigned char mac
[ETH_ALEN
],
91 enum macaccess_entry_type type
)
93 ocelot_mact_select(ocelot
, mac
, vid
);
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
);
102 return ocelot_mact_wait_for_completion(ocelot
);
105 static int ocelot_mact_forget(struct ocelot
*ocelot
,
106 const unsigned char mac
[ETH_ALEN
],
109 ocelot_mact_select(ocelot
, mac
, vid
);
111 /* Issue a forget command */
113 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_FORGET
),
114 ANA_TABLES_MACACCESS
);
116 return ocelot_mact_wait_for_completion(ocelot
);
119 static void ocelot_mact_init(struct ocelot
*ocelot
)
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.
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
,
131 /* Clear the MAC table */
132 ocelot_write(ocelot
, MACACCESS_CMD_INIT
, ANA_TABLES_MACACCESS
);
135 static void ocelot_vcap_enable(struct ocelot
*ocelot
, int port
)
137 ocelot_write_gix(ocelot
, ANA_PORT_VCAP_S2_CFG_S2_ENA
|
138 ANA_PORT_VCAP_S2_CFG_S2_IP6_CFG(0xa),
139 ANA_PORT_VCAP_S2_CFG
, port
);
142 static inline u32
ocelot_vlant_read_vlanaccess(struct ocelot
*ocelot
)
144 return ocelot_read(ocelot
, ANA_TABLES_VLANACCESS
);
147 static inline int ocelot_vlant_wait_for_completion(struct ocelot
*ocelot
)
151 return readx_poll_timeout(ocelot_vlant_read_vlanaccess
,
154 (val
& ANA_TABLES_VLANACCESS_VLAN_TBL_CMD_M
) ==
155 ANA_TABLES_VLANACCESS_CMD_IDLE
,
156 TABLE_UPDATE_SLEEP_US
, TABLE_UPDATE_TIMEOUT_US
);
159 static int ocelot_vlant_set_mask(struct ocelot
*ocelot
, u16 vid
, u32 mask
)
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
);
169 return ocelot_vlant_wait_for_completion(ocelot
);
172 static void ocelot_vlan_mode(struct ocelot
*ocelot
, int port
,
173 netdev_features_t features
)
178 val
= ocelot_read(ocelot
, ANA_VLANMASK
);
179 if (features
& NETIF_F_HW_VLAN_CTAG_FILTER
)
183 ocelot_write(ocelot
, val
, ANA_VLANMASK
);
186 static int ocelot_port_set_native_vlan(struct ocelot
*ocelot
, int port
,
189 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
192 if (ocelot_port
->vid
!= vid
) {
193 /* Always permit deleting the native VLAN (vid = 0) */
194 if (ocelot_port
->vid
&& vid
) {
196 "Port already has a native VLAN: %d\n",
200 ocelot_port
->vid
= vid
;
203 ocelot_rmw_gix(ocelot
, REW_PORT_VLAN_CFG_PORT_VID(vid
),
204 REW_PORT_VLAN_CFG_PORT_VID_M
,
205 REW_PORT_VLAN_CFG
, port
);
207 if (ocelot_port
->vlan_aware
&& !ocelot_port
->vid
)
208 /* If port is vlan-aware and tagged, drop untagged and priority
211 val
= ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA
|
212 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA
|
213 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA
;
214 ocelot_rmw_gix(ocelot
, val
,
215 ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA
|
216 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA
|
217 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA
,
218 ANA_PORT_DROP_CFG
, port
);
220 if (ocelot_port
->vlan_aware
) {
221 if (ocelot_port
->vid
)
222 /* Tag all frames except when VID == DEFAULT_VLAN */
223 val
= REW_TAG_CFG_TAG_CFG(1);
226 val
= REW_TAG_CFG_TAG_CFG(3);
228 /* Port tagging disabled. */
229 val
= REW_TAG_CFG_TAG_CFG(0);
231 ocelot_rmw_gix(ocelot
, val
,
232 REW_TAG_CFG_TAG_CFG_M
,
238 void ocelot_port_vlan_filtering(struct ocelot
*ocelot
, int port
,
241 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
244 ocelot_port
->vlan_aware
= vlan_aware
;
247 val
= ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA
|
248 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
251 ocelot_rmw_gix(ocelot
, val
,
252 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA
|
253 ANA_PORT_VLAN_CFG_VLAN_POP_CNT_M
,
254 ANA_PORT_VLAN_CFG
, port
);
256 ocelot_port_set_native_vlan(ocelot
, port
, ocelot_port
->vid
);
258 EXPORT_SYMBOL(ocelot_port_vlan_filtering
);
260 /* Default vlan to clasify for untagged frames (may be zero) */
261 static void ocelot_port_set_pvid(struct ocelot
*ocelot
, int port
, u16 pvid
)
263 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
265 ocelot_rmw_gix(ocelot
,
266 ANA_PORT_VLAN_CFG_VLAN_VID(pvid
),
267 ANA_PORT_VLAN_CFG_VLAN_VID_M
,
268 ANA_PORT_VLAN_CFG
, port
);
270 ocelot_port
->pvid
= pvid
;
273 int ocelot_vlan_add(struct ocelot
*ocelot
, int port
, u16 vid
, bool pvid
,
278 /* Make the port a member of the VLAN */
279 ocelot
->vlan_mask
[vid
] |= BIT(port
);
280 ret
= ocelot_vlant_set_mask(ocelot
, vid
, ocelot
->vlan_mask
[vid
]);
284 /* Default ingress vlan classification */
286 ocelot_port_set_pvid(ocelot
, port
, vid
);
288 /* Untagged egress vlan clasification */
290 ret
= ocelot_port_set_native_vlan(ocelot
, port
, vid
);
297 EXPORT_SYMBOL(ocelot_vlan_add
);
299 static int ocelot_vlan_vid_add(struct net_device
*dev
, u16 vid
, bool pvid
,
302 struct ocelot_port_private
*priv
= netdev_priv(dev
);
303 struct ocelot_port
*ocelot_port
= &priv
->port
;
304 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
305 int port
= priv
->chip_port
;
308 ret
= ocelot_vlan_add(ocelot
, port
, vid
, pvid
, untagged
);
312 /* Add the port MAC address to with the right VLAN information */
313 ocelot_mact_learn(ocelot
, PGID_CPU
, dev
->dev_addr
, vid
,
319 int ocelot_vlan_del(struct ocelot
*ocelot
, int port
, u16 vid
)
321 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
324 /* Stop the port from being a member of the vlan */
325 ocelot
->vlan_mask
[vid
] &= ~BIT(port
);
326 ret
= ocelot_vlant_set_mask(ocelot
, vid
, ocelot
->vlan_mask
[vid
]);
331 if (ocelot_port
->pvid
== vid
)
332 ocelot_port_set_pvid(ocelot
, port
, 0);
335 if (ocelot_port
->vid
== vid
)
336 ocelot_port_set_native_vlan(ocelot
, port
, 0);
340 EXPORT_SYMBOL(ocelot_vlan_del
);
342 static int ocelot_vlan_vid_del(struct net_device
*dev
, u16 vid
)
344 struct ocelot_port_private
*priv
= netdev_priv(dev
);
345 struct ocelot
*ocelot
= priv
->port
.ocelot
;
346 int port
= priv
->chip_port
;
349 /* 8021q removes VID 0 on module unload for all interfaces
350 * with VLAN filtering feature. We need to keep it to receive
356 ret
= ocelot_vlan_del(ocelot
, port
, vid
);
360 /* Del the port MAC address to with the right VLAN information */
361 ocelot_mact_forget(ocelot
, dev
->dev_addr
, vid
);
366 static void ocelot_vlan_init(struct ocelot
*ocelot
)
370 /* Clear VLAN table, by default all ports are members of all VLANs */
371 ocelot_write(ocelot
, ANA_TABLES_VLANACCESS_CMD_INIT
,
372 ANA_TABLES_VLANACCESS
);
373 ocelot_vlant_wait_for_completion(ocelot
);
375 /* Configure the port VLAN memberships */
376 for (vid
= 1; vid
< VLAN_N_VID
; vid
++) {
377 ocelot
->vlan_mask
[vid
] = 0;
378 ocelot_vlant_set_mask(ocelot
, vid
, ocelot
->vlan_mask
[vid
]);
381 /* Because VLAN filtering is enabled, we need VID 0 to get untagged
382 * traffic. It is added automatically if 8021q module is loaded, but
383 * we can't rely on it since module may be not loaded.
385 ocelot
->vlan_mask
[0] = GENMASK(ocelot
->num_phys_ports
- 1, 0);
386 ocelot_vlant_set_mask(ocelot
, 0, ocelot
->vlan_mask
[0]);
388 /* Set vlan ingress filter mask to all ports but the CPU port by
391 ocelot_write(ocelot
, GENMASK(ocelot
->num_phys_ports
- 1, 0),
394 for (port
= 0; port
< ocelot
->num_phys_ports
; port
++) {
395 ocelot_write_gix(ocelot
, 0, REW_PORT_VLAN_CFG
, port
);
396 ocelot_write_gix(ocelot
, 0, REW_TAG_CFG
, port
);
401 * Bit 8: Unit; 0:1, 1:16
402 * Bit 7-0: Value to be multiplied with unit
404 static u16
ocelot_wm_enc(u16 value
)
407 return BIT(8) | (value
/ 16);
412 void ocelot_adjust_link(struct ocelot
*ocelot
, int port
,
413 struct phy_device
*phydev
)
415 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
418 switch (phydev
->speed
) {
420 speed
= OCELOT_SPEED_10
;
423 speed
= OCELOT_SPEED_100
;
426 speed
= OCELOT_SPEED_1000
;
427 mode
= DEV_MAC_MODE_CFG_GIGA_MODE_ENA
;
430 speed
= OCELOT_SPEED_2500
;
431 mode
= DEV_MAC_MODE_CFG_GIGA_MODE_ENA
;
434 dev_err(ocelot
->dev
, "Unsupported PHY speed on port %d: %d\n",
435 port
, phydev
->speed
);
439 phy_print_status(phydev
);
444 /* Only full duplex supported for now */
445 ocelot_port_writel(ocelot_port
, DEV_MAC_MODE_CFG_FDX_ENA
|
446 mode
, DEV_MAC_MODE_CFG
);
448 /* Disable HDX fast control */
449 ocelot_port_writel(ocelot_port
, DEV_PORT_MISC_HDX_FAST_DIS
,
452 /* SGMII only for now */
453 ocelot_port_writel(ocelot_port
, PCS1G_MODE_CFG_SGMII_MODE_ENA
,
455 ocelot_port_writel(ocelot_port
, PCS1G_SD_CFG_SD_SEL
, PCS1G_SD_CFG
);
458 ocelot_port_writel(ocelot_port
, PCS1G_CFG_PCS_ENA
, PCS1G_CFG
);
460 /* No aneg on SGMII */
461 ocelot_port_writel(ocelot_port
, 0, PCS1G_ANEG_CFG
);
464 ocelot_port_writel(ocelot_port
, 0, PCS1G_LB_CFG
);
466 /* Enable MAC module */
467 ocelot_port_writel(ocelot_port
, DEV_MAC_ENA_CFG_RX_ENA
|
468 DEV_MAC_ENA_CFG_TX_ENA
, DEV_MAC_ENA_CFG
);
470 /* Take MAC, Port, Phy (intern) and PCS (SGMII/Serdes) clock out of
472 ocelot_port_writel(ocelot_port
, DEV_CLOCK_CFG_LINK_SPEED(speed
),
476 ocelot_write_gix(ocelot
, ANA_PFC_PFC_CFG_FC_LINK_SPEED(speed
),
477 ANA_PFC_PFC_CFG
, port
);
479 /* Core: Enable port for frame transfer */
480 ocelot_write_rix(ocelot
, QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE
|
481 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG(1) |
482 QSYS_SWITCH_PORT_MODE_PORT_ENA
,
483 QSYS_SWITCH_PORT_MODE
, port
);
486 ocelot_write_rix(ocelot
, SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
487 SYS_MAC_FC_CFG_RX_FC_ENA
| SYS_MAC_FC_CFG_TX_FC_ENA
|
488 SYS_MAC_FC_CFG_ZERO_PAUSE_ENA
|
489 SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
490 SYS_MAC_FC_CFG_FC_LINK_SPEED(speed
),
491 SYS_MAC_FC_CFG
, port
);
492 ocelot_write_rix(ocelot
, 0, ANA_POL_FLOWC
, port
);
494 EXPORT_SYMBOL(ocelot_adjust_link
);
496 static void ocelot_port_adjust_link(struct net_device
*dev
)
498 struct ocelot_port_private
*priv
= netdev_priv(dev
);
499 struct ocelot
*ocelot
= priv
->port
.ocelot
;
500 int port
= priv
->chip_port
;
502 ocelot_adjust_link(ocelot
, port
, dev
->phydev
);
505 void ocelot_port_enable(struct ocelot
*ocelot
, int port
,
506 struct phy_device
*phy
)
508 /* Enable receiving frames on the port, and activate auto-learning of
511 ocelot_write_gix(ocelot
, ANA_PORT_PORT_CFG_LEARNAUTO
|
512 ANA_PORT_PORT_CFG_RECV_ENA
|
513 ANA_PORT_PORT_CFG_PORTID_VAL(port
),
514 ANA_PORT_PORT_CFG
, port
);
516 EXPORT_SYMBOL(ocelot_port_enable
);
518 static int ocelot_port_open(struct net_device
*dev
)
520 struct ocelot_port_private
*priv
= netdev_priv(dev
);
521 struct ocelot_port
*ocelot_port
= &priv
->port
;
522 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
523 int port
= priv
->chip_port
;
527 err
= phy_set_mode_ext(priv
->serdes
, PHY_MODE_ETHERNET
,
528 ocelot_port
->phy_mode
);
530 netdev_err(dev
, "Could not set mode of SerDes\n");
535 err
= phy_connect_direct(dev
, priv
->phy
, &ocelot_port_adjust_link
,
536 ocelot_port
->phy_mode
);
538 netdev_err(dev
, "Could not attach to PHY\n");
542 dev
->phydev
= priv
->phy
;
544 phy_attached_info(priv
->phy
);
545 phy_start(priv
->phy
);
547 ocelot_port_enable(ocelot
, port
, priv
->phy
);
552 void ocelot_port_disable(struct ocelot
*ocelot
, int port
)
554 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
556 ocelot_port_writel(ocelot_port
, 0, DEV_MAC_ENA_CFG
);
557 ocelot_rmw_rix(ocelot
, 0, QSYS_SWITCH_PORT_MODE_PORT_ENA
,
558 QSYS_SWITCH_PORT_MODE
, port
);
560 EXPORT_SYMBOL(ocelot_port_disable
);
562 static int ocelot_port_stop(struct net_device
*dev
)
564 struct ocelot_port_private
*priv
= netdev_priv(dev
);
565 struct ocelot
*ocelot
= priv
->port
.ocelot
;
566 int port
= priv
->chip_port
;
568 phy_disconnect(priv
->phy
);
572 ocelot_port_disable(ocelot
, port
);
577 /* Generate the IFH for frame injection
579 * The IFH is a 128bit-value
580 * bit 127: bypass the analyzer processing
581 * bit 56-67: destination mask
582 * bit 28-29: pop_cnt: 3 disables all rewriting of the frame
583 * bit 20-27: cpu extraction queue mask
584 * bit 16: tag type 0: C-tag, 1: S-tag
587 static int ocelot_gen_ifh(u32
*ifh
, struct frame_info
*info
)
589 ifh
[0] = IFH_INJ_BYPASS
| ((0x1ff & info
->rew_op
) << 21);
590 ifh
[1] = (0xf00 & info
->port
) >> 8;
591 ifh
[2] = (0xff & info
->port
) << 24;
592 ifh
[3] = (info
->tag_type
<< 16) | info
->vid
;
597 int ocelot_port_add_txtstamp_skb(struct ocelot_port
*ocelot_port
,
600 struct skb_shared_info
*shinfo
= skb_shinfo(skb
);
601 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
603 if (ocelot
->ptp
&& shinfo
->tx_flags
& SKBTX_HW_TSTAMP
&&
604 ocelot_port
->ptp_cmd
== IFH_REW_OP_TWO_STEP_PTP
) {
605 shinfo
->tx_flags
|= SKBTX_IN_PROGRESS
;
606 /* Store timestamp ID in cb[0] of sk_buff */
607 skb
->cb
[0] = ocelot_port
->ts_id
% 4;
608 skb_queue_tail(&ocelot_port
->tx_skbs
, skb
);
613 EXPORT_SYMBOL(ocelot_port_add_txtstamp_skb
);
615 static int ocelot_port_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
617 struct ocelot_port_private
*priv
= netdev_priv(dev
);
618 struct skb_shared_info
*shinfo
= skb_shinfo(skb
);
619 struct ocelot_port
*ocelot_port
= &priv
->port
;
620 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
621 u32 val
, ifh
[OCELOT_TAG_LEN
/ 4];
622 struct frame_info info
= {};
623 u8 grp
= 0; /* Send everything on CPU group 0 */
624 unsigned int i
, count
, last
;
625 int port
= priv
->chip_port
;
627 val
= ocelot_read(ocelot
, QS_INJ_STATUS
);
628 if (!(val
& QS_INJ_STATUS_FIFO_RDY(BIT(grp
))) ||
629 (val
& QS_INJ_STATUS_WMARK_REACHED(BIT(grp
))))
630 return NETDEV_TX_BUSY
;
632 ocelot_write_rix(ocelot
, QS_INJ_CTRL_GAP_SIZE(1) |
633 QS_INJ_CTRL_SOF
, QS_INJ_CTRL
, grp
);
635 info
.port
= BIT(port
);
636 info
.tag_type
= IFH_TAG_TYPE_C
;
637 info
.vid
= skb_vlan_tag_get(skb
);
639 /* Check if timestamping is needed */
640 if (ocelot
->ptp
&& shinfo
->tx_flags
& SKBTX_HW_TSTAMP
) {
641 info
.rew_op
= ocelot_port
->ptp_cmd
;
642 if (ocelot_port
->ptp_cmd
== IFH_REW_OP_TWO_STEP_PTP
)
643 info
.rew_op
|= (ocelot_port
->ts_id
% 4) << 3;
646 ocelot_gen_ifh(ifh
, &info
);
648 for (i
= 0; i
< OCELOT_TAG_LEN
/ 4; i
++)
649 ocelot_write_rix(ocelot
, (__force u32
)cpu_to_be32(ifh
[i
]),
652 count
= (skb
->len
+ 3) / 4;
654 for (i
= 0; i
< count
; i
++) {
655 ocelot_write_rix(ocelot
, ((u32
*)skb
->data
)[i
], QS_INJ_WR
, grp
);
659 while (i
< (OCELOT_BUFFER_CELL_SZ
/ 4)) {
660 ocelot_write_rix(ocelot
, 0, QS_INJ_WR
, grp
);
664 /* Indicate EOF and valid bytes in last word */
665 ocelot_write_rix(ocelot
, QS_INJ_CTRL_GAP_SIZE(1) |
666 QS_INJ_CTRL_VLD_BYTES(skb
->len
< OCELOT_BUFFER_CELL_SZ
? 0 : last
) |
671 ocelot_write_rix(ocelot
, 0, QS_INJ_WR
, grp
);
672 skb_tx_timestamp(skb
);
674 dev
->stats
.tx_packets
++;
675 dev
->stats
.tx_bytes
+= skb
->len
;
677 if (!ocelot_port_add_txtstamp_skb(ocelot_port
, skb
)) {
678 ocelot_port
->ts_id
++;
682 dev_kfree_skb_any(skb
);
686 static void ocelot_get_hwtimestamp(struct ocelot
*ocelot
,
687 struct timespec64
*ts
)
692 spin_lock_irqsave(&ocelot
->ptp_clock_lock
, flags
);
694 /* Read current PTP time to get seconds */
695 val
= ocelot_read_rix(ocelot
, PTP_PIN_CFG
, TOD_ACC_PIN
);
697 val
&= ~(PTP_PIN_CFG_SYNC
| PTP_PIN_CFG_ACTION_MASK
| PTP_PIN_CFG_DOM
);
698 val
|= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_SAVE
);
699 ocelot_write_rix(ocelot
, val
, PTP_PIN_CFG
, TOD_ACC_PIN
);
700 ts
->tv_sec
= ocelot_read_rix(ocelot
, PTP_PIN_TOD_SEC_LSB
, TOD_ACC_PIN
);
702 /* Read packet HW timestamp from FIFO */
703 val
= ocelot_read(ocelot
, SYS_PTP_TXSTAMP
);
704 ts
->tv_nsec
= SYS_PTP_TXSTAMP_PTP_TXSTAMP(val
);
706 /* Sec has incremented since the ts was registered */
707 if ((ts
->tv_sec
& 0x1) != !!(val
& SYS_PTP_TXSTAMP_PTP_TXSTAMP_SEC
))
710 spin_unlock_irqrestore(&ocelot
->ptp_clock_lock
, flags
);
713 void ocelot_get_txtstamp(struct ocelot
*ocelot
)
715 int budget
= OCELOT_PTP_QUEUE_SZ
;
718 struct sk_buff
*skb
, *skb_tmp
, *skb_match
= NULL
;
719 struct skb_shared_hwtstamps shhwtstamps
;
720 struct ocelot_port
*port
;
721 struct timespec64 ts
;
725 val
= ocelot_read(ocelot
, SYS_PTP_STATUS
);
727 /* Check if a timestamp can be retrieved */
728 if (!(val
& SYS_PTP_STATUS_PTP_MESS_VLD
))
731 WARN_ON(val
& SYS_PTP_STATUS_PTP_OVFL
);
733 /* Retrieve the ts ID and Tx port */
734 id
= SYS_PTP_STATUS_PTP_MESS_ID_X(val
);
735 txport
= SYS_PTP_STATUS_PTP_MESS_TXPORT_X(val
);
737 /* Retrieve its associated skb */
738 port
= ocelot
->ports
[txport
];
740 spin_lock_irqsave(&port
->tx_skbs
.lock
, flags
);
742 skb_queue_walk_safe(&port
->tx_skbs
, skb
, skb_tmp
) {
743 if (skb
->cb
[0] != id
)
745 __skb_unlink(skb
, &port
->tx_skbs
);
750 spin_unlock_irqrestore(&port
->tx_skbs
.lock
, flags
);
753 ocelot_write(ocelot
, SYS_PTP_NXT_PTP_NXT
, SYS_PTP_NXT
);
755 if (unlikely(!skb_match
))
758 /* Get the h/w timestamp */
759 ocelot_get_hwtimestamp(ocelot
, &ts
);
761 /* Set the timestamp into the skb */
762 memset(&shhwtstamps
, 0, sizeof(shhwtstamps
));
763 shhwtstamps
.hwtstamp
= ktime_set(ts
.tv_sec
, ts
.tv_nsec
);
764 skb_tstamp_tx(skb_match
, &shhwtstamps
);
766 dev_kfree_skb_any(skb_match
);
769 EXPORT_SYMBOL(ocelot_get_txtstamp
);
771 static int ocelot_mc_unsync(struct net_device
*dev
, const unsigned char *addr
)
773 struct ocelot_port_private
*priv
= netdev_priv(dev
);
774 struct ocelot_port
*ocelot_port
= &priv
->port
;
775 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
777 return ocelot_mact_forget(ocelot
, addr
, ocelot_port
->pvid
);
780 static int ocelot_mc_sync(struct net_device
*dev
, const unsigned char *addr
)
782 struct ocelot_port_private
*priv
= netdev_priv(dev
);
783 struct ocelot_port
*ocelot_port
= &priv
->port
;
784 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
786 return ocelot_mact_learn(ocelot
, PGID_CPU
, addr
, ocelot_port
->pvid
,
790 static void ocelot_set_rx_mode(struct net_device
*dev
)
792 struct ocelot_port_private
*priv
= netdev_priv(dev
);
793 struct ocelot
*ocelot
= priv
->port
.ocelot
;
797 /* This doesn't handle promiscuous mode because the bridge core is
798 * setting IFF_PROMISC on all slave interfaces and all frames would be
799 * forwarded to the CPU port.
801 val
= GENMASK(ocelot
->num_phys_ports
- 1, 0);
802 for (i
= ocelot
->num_phys_ports
+ 1; i
< PGID_CPU
; i
++)
803 ocelot_write_rix(ocelot
, val
, ANA_PGID_PGID
, i
);
805 __dev_mc_sync(dev
, ocelot_mc_sync
, ocelot_mc_unsync
);
808 static int ocelot_port_get_phys_port_name(struct net_device
*dev
,
809 char *buf
, size_t len
)
811 struct ocelot_port_private
*priv
= netdev_priv(dev
);
812 int port
= priv
->chip_port
;
815 ret
= snprintf(buf
, len
, "p%d", port
);
822 static int ocelot_port_set_mac_address(struct net_device
*dev
, void *p
)
824 struct ocelot_port_private
*priv
= netdev_priv(dev
);
825 struct ocelot_port
*ocelot_port
= &priv
->port
;
826 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
827 const struct sockaddr
*addr
= p
;
829 /* Learn the new net device MAC address in the mac table. */
830 ocelot_mact_learn(ocelot
, PGID_CPU
, addr
->sa_data
, ocelot_port
->pvid
,
832 /* Then forget the previous one. */
833 ocelot_mact_forget(ocelot
, dev
->dev_addr
, ocelot_port
->pvid
);
835 ether_addr_copy(dev
->dev_addr
, addr
->sa_data
);
839 static void ocelot_get_stats64(struct net_device
*dev
,
840 struct rtnl_link_stats64
*stats
)
842 struct ocelot_port_private
*priv
= netdev_priv(dev
);
843 struct ocelot
*ocelot
= priv
->port
.ocelot
;
844 int port
= priv
->chip_port
;
846 /* Configure the port to read the stats from */
847 ocelot_write(ocelot
, SYS_STAT_CFG_STAT_VIEW(port
),
851 stats
->rx_bytes
= ocelot_read(ocelot
, SYS_COUNT_RX_OCTETS
);
852 stats
->rx_packets
= ocelot_read(ocelot
, SYS_COUNT_RX_SHORTS
) +
853 ocelot_read(ocelot
, SYS_COUNT_RX_FRAGMENTS
) +
854 ocelot_read(ocelot
, SYS_COUNT_RX_JABBERS
) +
855 ocelot_read(ocelot
, SYS_COUNT_RX_LONGS
) +
856 ocelot_read(ocelot
, SYS_COUNT_RX_64
) +
857 ocelot_read(ocelot
, SYS_COUNT_RX_65_127
) +
858 ocelot_read(ocelot
, SYS_COUNT_RX_128_255
) +
859 ocelot_read(ocelot
, SYS_COUNT_RX_256_1023
) +
860 ocelot_read(ocelot
, SYS_COUNT_RX_1024_1526
) +
861 ocelot_read(ocelot
, SYS_COUNT_RX_1527_MAX
);
862 stats
->multicast
= ocelot_read(ocelot
, SYS_COUNT_RX_MULTICAST
);
863 stats
->rx_dropped
= dev
->stats
.rx_dropped
;
866 stats
->tx_bytes
= ocelot_read(ocelot
, SYS_COUNT_TX_OCTETS
);
867 stats
->tx_packets
= ocelot_read(ocelot
, SYS_COUNT_TX_64
) +
868 ocelot_read(ocelot
, SYS_COUNT_TX_65_127
) +
869 ocelot_read(ocelot
, SYS_COUNT_TX_128_511
) +
870 ocelot_read(ocelot
, SYS_COUNT_TX_512_1023
) +
871 ocelot_read(ocelot
, SYS_COUNT_TX_1024_1526
) +
872 ocelot_read(ocelot
, SYS_COUNT_TX_1527_MAX
);
873 stats
->tx_dropped
= ocelot_read(ocelot
, SYS_COUNT_TX_DROPS
) +
874 ocelot_read(ocelot
, SYS_COUNT_TX_AGING
);
875 stats
->collisions
= ocelot_read(ocelot
, SYS_COUNT_TX_COLLISION
);
878 int ocelot_fdb_add(struct ocelot
*ocelot
, int port
,
879 const unsigned char *addr
, u16 vid
)
881 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
884 if (!ocelot_port
->vlan_aware
)
885 /* If the bridge is not VLAN aware and no VID was
886 * provided, set it to pvid to ensure the MAC entry
887 * matches incoming untagged packets
889 vid
= ocelot_port
->pvid
;
891 /* If the bridge is VLAN aware a VID must be provided as
892 * otherwise the learnt entry wouldn't match any frame.
897 return ocelot_mact_learn(ocelot
, port
, addr
, vid
, ENTRYTYPE_LOCKED
);
899 EXPORT_SYMBOL(ocelot_fdb_add
);
901 static int ocelot_port_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
902 struct net_device
*dev
,
903 const unsigned char *addr
,
905 struct netlink_ext_ack
*extack
)
907 struct ocelot_port_private
*priv
= netdev_priv(dev
);
908 struct ocelot
*ocelot
= priv
->port
.ocelot
;
909 int port
= priv
->chip_port
;
911 return ocelot_fdb_add(ocelot
, port
, addr
, vid
);
914 int ocelot_fdb_del(struct ocelot
*ocelot
, int port
,
915 const unsigned char *addr
, u16 vid
)
917 return ocelot_mact_forget(ocelot
, addr
, vid
);
919 EXPORT_SYMBOL(ocelot_fdb_del
);
921 static int ocelot_port_fdb_del(struct ndmsg
*ndm
, struct nlattr
*tb
[],
922 struct net_device
*dev
,
923 const unsigned char *addr
, u16 vid
)
925 struct ocelot_port_private
*priv
= netdev_priv(dev
);
926 struct ocelot
*ocelot
= priv
->port
.ocelot
;
927 int port
= priv
->chip_port
;
929 return ocelot_fdb_del(ocelot
, port
, addr
, vid
);
932 struct ocelot_dump_ctx
{
933 struct net_device
*dev
;
935 struct netlink_callback
*cb
;
939 static int ocelot_port_fdb_do_dump(const unsigned char *addr
, u16 vid
,
940 bool is_static
, void *data
)
942 struct ocelot_dump_ctx
*dump
= data
;
943 u32 portid
= NETLINK_CB(dump
->cb
->skb
).portid
;
944 u32 seq
= dump
->cb
->nlh
->nlmsg_seq
;
945 struct nlmsghdr
*nlh
;
948 if (dump
->idx
< dump
->cb
->args
[2])
951 nlh
= nlmsg_put(dump
->skb
, portid
, seq
, RTM_NEWNEIGH
,
952 sizeof(*ndm
), NLM_F_MULTI
);
956 ndm
= nlmsg_data(nlh
);
957 ndm
->ndm_family
= AF_BRIDGE
;
960 ndm
->ndm_flags
= NTF_SELF
;
962 ndm
->ndm_ifindex
= dump
->dev
->ifindex
;
963 ndm
->ndm_state
= is_static
? NUD_NOARP
: NUD_REACHABLE
;
965 if (nla_put(dump
->skb
, NDA_LLADDR
, ETH_ALEN
, addr
))
966 goto nla_put_failure
;
968 if (vid
&& nla_put_u16(dump
->skb
, NDA_VLAN
, vid
))
969 goto nla_put_failure
;
971 nlmsg_end(dump
->skb
, nlh
);
978 nlmsg_cancel(dump
->skb
, nlh
);
982 static int ocelot_mact_read(struct ocelot
*ocelot
, int port
, int row
, int col
,
983 struct ocelot_mact_entry
*entry
)
985 u32 val
, dst
, macl
, mach
;
988 /* Set row and column to read from */
989 ocelot_field_write(ocelot
, ANA_TABLES_MACTINDX_M_INDEX
, row
);
990 ocelot_field_write(ocelot
, ANA_TABLES_MACTINDX_BUCKET
, col
);
992 /* Issue a read command */
994 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ
),
995 ANA_TABLES_MACACCESS
);
997 if (ocelot_mact_wait_for_completion(ocelot
))
1000 /* Read the entry flags */
1001 val
= ocelot_read(ocelot
, ANA_TABLES_MACACCESS
);
1002 if (!(val
& ANA_TABLES_MACACCESS_VALID
))
1005 /* If the entry read has another port configured as its destination,
1008 dst
= (val
& ANA_TABLES_MACACCESS_DEST_IDX_M
) >> 3;
1012 /* Get the entry's MAC address and VLAN id */
1013 macl
= ocelot_read(ocelot
, ANA_TABLES_MACLDATA
);
1014 mach
= ocelot_read(ocelot
, ANA_TABLES_MACHDATA
);
1016 mac
[0] = (mach
>> 8) & 0xff;
1017 mac
[1] = (mach
>> 0) & 0xff;
1018 mac
[2] = (macl
>> 24) & 0xff;
1019 mac
[3] = (macl
>> 16) & 0xff;
1020 mac
[4] = (macl
>> 8) & 0xff;
1021 mac
[5] = (macl
>> 0) & 0xff;
1023 entry
->vid
= (mach
>> 16) & 0xfff;
1024 ether_addr_copy(entry
->mac
, mac
);
1029 int ocelot_fdb_dump(struct ocelot
*ocelot
, int port
,
1030 dsa_fdb_dump_cb_t
*cb
, void *data
)
1034 /* Loop through all the mac tables entries. There are 1024 rows of 4
1037 for (i
= 0; i
< 1024; i
++) {
1038 for (j
= 0; j
< 4; j
++) {
1039 struct ocelot_mact_entry entry
;
1043 ret
= ocelot_mact_read(ocelot
, port
, i
, j
, &entry
);
1044 /* If the entry is invalid (wrong port, invalid...),
1052 is_static
= (entry
.type
== ENTRYTYPE_LOCKED
);
1054 ret
= cb(entry
.mac
, entry
.vid
, is_static
, data
);
1062 EXPORT_SYMBOL(ocelot_fdb_dump
);
1064 static int ocelot_port_fdb_dump(struct sk_buff
*skb
,
1065 struct netlink_callback
*cb
,
1066 struct net_device
*dev
,
1067 struct net_device
*filter_dev
, int *idx
)
1069 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1070 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1071 struct ocelot_dump_ctx dump
= {
1077 int port
= priv
->chip_port
;
1080 ret
= ocelot_fdb_dump(ocelot
, port
, ocelot_port_fdb_do_dump
, &dump
);
1087 static int ocelot_vlan_rx_add_vid(struct net_device
*dev
, __be16 proto
,
1090 return ocelot_vlan_vid_add(dev
, vid
, false, false);
1093 static int ocelot_vlan_rx_kill_vid(struct net_device
*dev
, __be16 proto
,
1096 return ocelot_vlan_vid_del(dev
, vid
);
1099 static int ocelot_set_features(struct net_device
*dev
,
1100 netdev_features_t features
)
1102 netdev_features_t changed
= dev
->features
^ features
;
1103 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1104 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1105 int port
= priv
->chip_port
;
1107 if ((dev
->features
& NETIF_F_HW_TC
) > (features
& NETIF_F_HW_TC
) &&
1108 priv
->tc
.offload_cnt
) {
1110 "Cannot disable HW TC offload while offloads active\n");
1114 if (changed
& NETIF_F_HW_VLAN_CTAG_FILTER
)
1115 ocelot_vlan_mode(ocelot
, port
, features
);
1120 static int ocelot_get_port_parent_id(struct net_device
*dev
,
1121 struct netdev_phys_item_id
*ppid
)
1123 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1124 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1126 ppid
->id_len
= sizeof(ocelot
->base_mac
);
1127 memcpy(&ppid
->id
, &ocelot
->base_mac
, ppid
->id_len
);
1132 int ocelot_hwstamp_get(struct ocelot
*ocelot
, int port
, struct ifreq
*ifr
)
1134 return copy_to_user(ifr
->ifr_data
, &ocelot
->hwtstamp_config
,
1135 sizeof(ocelot
->hwtstamp_config
)) ? -EFAULT
: 0;
1137 EXPORT_SYMBOL(ocelot_hwstamp_get
);
1139 int ocelot_hwstamp_set(struct ocelot
*ocelot
, int port
, struct ifreq
*ifr
)
1141 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
1142 struct hwtstamp_config cfg
;
1144 if (copy_from_user(&cfg
, ifr
->ifr_data
, sizeof(cfg
)))
1147 /* reserved for future extensions */
1151 /* Tx type sanity check */
1152 switch (cfg
.tx_type
) {
1153 case HWTSTAMP_TX_ON
:
1154 ocelot_port
->ptp_cmd
= IFH_REW_OP_TWO_STEP_PTP
;
1156 case HWTSTAMP_TX_ONESTEP_SYNC
:
1157 /* IFH_REW_OP_ONE_STEP_PTP updates the correctional field, we
1158 * need to update the origin time.
1160 ocelot_port
->ptp_cmd
= IFH_REW_OP_ORIGIN_PTP
;
1162 case HWTSTAMP_TX_OFF
:
1163 ocelot_port
->ptp_cmd
= 0;
1169 mutex_lock(&ocelot
->ptp_lock
);
1171 switch (cfg
.rx_filter
) {
1172 case HWTSTAMP_FILTER_NONE
:
1174 case HWTSTAMP_FILTER_ALL
:
1175 case HWTSTAMP_FILTER_SOME
:
1176 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
1177 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
1178 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
1179 case HWTSTAMP_FILTER_NTP_ALL
:
1180 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
1181 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
1182 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
1183 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
1184 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
1185 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
1186 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
1187 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
1188 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
1189 cfg
.rx_filter
= HWTSTAMP_FILTER_PTP_V2_EVENT
;
1192 mutex_unlock(&ocelot
->ptp_lock
);
1196 /* Commit back the result & save it */
1197 memcpy(&ocelot
->hwtstamp_config
, &cfg
, sizeof(cfg
));
1198 mutex_unlock(&ocelot
->ptp_lock
);
1200 return copy_to_user(ifr
->ifr_data
, &cfg
, sizeof(cfg
)) ? -EFAULT
: 0;
1202 EXPORT_SYMBOL(ocelot_hwstamp_set
);
1204 static int ocelot_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1206 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1207 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1208 int port
= priv
->chip_port
;
1210 /* The function is only used for PTP operations for now */
1216 return ocelot_hwstamp_set(ocelot
, port
, ifr
);
1218 return ocelot_hwstamp_get(ocelot
, port
, ifr
);
1224 static const struct net_device_ops ocelot_port_netdev_ops
= {
1225 .ndo_open
= ocelot_port_open
,
1226 .ndo_stop
= ocelot_port_stop
,
1227 .ndo_start_xmit
= ocelot_port_xmit
,
1228 .ndo_set_rx_mode
= ocelot_set_rx_mode
,
1229 .ndo_get_phys_port_name
= ocelot_port_get_phys_port_name
,
1230 .ndo_set_mac_address
= ocelot_port_set_mac_address
,
1231 .ndo_get_stats64
= ocelot_get_stats64
,
1232 .ndo_fdb_add
= ocelot_port_fdb_add
,
1233 .ndo_fdb_del
= ocelot_port_fdb_del
,
1234 .ndo_fdb_dump
= ocelot_port_fdb_dump
,
1235 .ndo_vlan_rx_add_vid
= ocelot_vlan_rx_add_vid
,
1236 .ndo_vlan_rx_kill_vid
= ocelot_vlan_rx_kill_vid
,
1237 .ndo_set_features
= ocelot_set_features
,
1238 .ndo_get_port_parent_id
= ocelot_get_port_parent_id
,
1239 .ndo_setup_tc
= ocelot_setup_tc
,
1240 .ndo_do_ioctl
= ocelot_ioctl
,
1243 void ocelot_get_strings(struct ocelot
*ocelot
, int port
, u32 sset
, u8
*data
)
1247 if (sset
!= ETH_SS_STATS
)
1250 for (i
= 0; i
< ocelot
->num_stats
; i
++)
1251 memcpy(data
+ i
* ETH_GSTRING_LEN
, ocelot
->stats_layout
[i
].name
,
1254 EXPORT_SYMBOL(ocelot_get_strings
);
1256 static void ocelot_port_get_strings(struct net_device
*netdev
, u32 sset
,
1259 struct ocelot_port_private
*priv
= netdev_priv(netdev
);
1260 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1261 int port
= priv
->chip_port
;
1263 ocelot_get_strings(ocelot
, port
, sset
, data
);
1266 static void ocelot_update_stats(struct ocelot
*ocelot
)
1270 mutex_lock(&ocelot
->stats_lock
);
1272 for (i
= 0; i
< ocelot
->num_phys_ports
; i
++) {
1273 /* Configure the port to read the stats from */
1274 ocelot_write(ocelot
, SYS_STAT_CFG_STAT_VIEW(i
), SYS_STAT_CFG
);
1276 for (j
= 0; j
< ocelot
->num_stats
; j
++) {
1278 unsigned int idx
= i
* ocelot
->num_stats
+ j
;
1280 val
= ocelot_read_rix(ocelot
, SYS_COUNT_RX_OCTETS
,
1281 ocelot
->stats_layout
[j
].offset
);
1283 if (val
< (ocelot
->stats
[idx
] & U32_MAX
))
1284 ocelot
->stats
[idx
] += (u64
)1 << 32;
1286 ocelot
->stats
[idx
] = (ocelot
->stats
[idx
] &
1287 ~(u64
)U32_MAX
) + val
;
1291 mutex_unlock(&ocelot
->stats_lock
);
1294 static void ocelot_check_stats_work(struct work_struct
*work
)
1296 struct delayed_work
*del_work
= to_delayed_work(work
);
1297 struct ocelot
*ocelot
= container_of(del_work
, struct ocelot
,
1300 ocelot_update_stats(ocelot
);
1302 queue_delayed_work(ocelot
->stats_queue
, &ocelot
->stats_work
,
1303 OCELOT_STATS_CHECK_DELAY
);
1306 void ocelot_get_ethtool_stats(struct ocelot
*ocelot
, int port
, u64
*data
)
1310 /* check and update now */
1311 ocelot_update_stats(ocelot
);
1313 /* Copy all counters */
1314 for (i
= 0; i
< ocelot
->num_stats
; i
++)
1315 *data
++ = ocelot
->stats
[port
* ocelot
->num_stats
+ i
];
1317 EXPORT_SYMBOL(ocelot_get_ethtool_stats
);
1319 static void ocelot_port_get_ethtool_stats(struct net_device
*dev
,
1320 struct ethtool_stats
*stats
,
1323 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1324 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1325 int port
= priv
->chip_port
;
1327 ocelot_get_ethtool_stats(ocelot
, port
, data
);
1330 int ocelot_get_sset_count(struct ocelot
*ocelot
, int port
, int sset
)
1332 if (sset
!= ETH_SS_STATS
)
1335 return ocelot
->num_stats
;
1337 EXPORT_SYMBOL(ocelot_get_sset_count
);
1339 static int ocelot_port_get_sset_count(struct net_device
*dev
, int sset
)
1341 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1342 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1343 int port
= priv
->chip_port
;
1345 return ocelot_get_sset_count(ocelot
, port
, sset
);
1348 int ocelot_get_ts_info(struct ocelot
*ocelot
, int port
,
1349 struct ethtool_ts_info
*info
)
1351 info
->phc_index
= ocelot
->ptp_clock
?
1352 ptp_clock_index(ocelot
->ptp_clock
) : -1;
1353 info
->so_timestamping
|= SOF_TIMESTAMPING_TX_SOFTWARE
|
1354 SOF_TIMESTAMPING_RX_SOFTWARE
|
1355 SOF_TIMESTAMPING_SOFTWARE
|
1356 SOF_TIMESTAMPING_TX_HARDWARE
|
1357 SOF_TIMESTAMPING_RX_HARDWARE
|
1358 SOF_TIMESTAMPING_RAW_HARDWARE
;
1359 info
->tx_types
= BIT(HWTSTAMP_TX_OFF
) | BIT(HWTSTAMP_TX_ON
) |
1360 BIT(HWTSTAMP_TX_ONESTEP_SYNC
);
1361 info
->rx_filters
= BIT(HWTSTAMP_FILTER_NONE
) | BIT(HWTSTAMP_FILTER_ALL
);
1365 EXPORT_SYMBOL(ocelot_get_ts_info
);
1367 static int ocelot_port_get_ts_info(struct net_device
*dev
,
1368 struct ethtool_ts_info
*info
)
1370 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1371 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1372 int port
= priv
->chip_port
;
1375 return ethtool_op_get_ts_info(dev
, info
);
1377 return ocelot_get_ts_info(ocelot
, port
, info
);
1380 static const struct ethtool_ops ocelot_ethtool_ops
= {
1381 .get_strings
= ocelot_port_get_strings
,
1382 .get_ethtool_stats
= ocelot_port_get_ethtool_stats
,
1383 .get_sset_count
= ocelot_port_get_sset_count
,
1384 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
1385 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
1386 .get_ts_info
= ocelot_port_get_ts_info
,
1389 void ocelot_bridge_stp_state_set(struct ocelot
*ocelot
, int port
, u8 state
)
1394 if (!(BIT(port
) & ocelot
->bridge_mask
))
1397 port_cfg
= ocelot_read_gix(ocelot
, ANA_PORT_PORT_CFG
, port
);
1400 case BR_STATE_FORWARDING
:
1401 ocelot
->bridge_fwd_mask
|= BIT(port
);
1403 case BR_STATE_LEARNING
:
1404 port_cfg
|= ANA_PORT_PORT_CFG_LEARN_ENA
;
1408 port_cfg
&= ~ANA_PORT_PORT_CFG_LEARN_ENA
;
1409 ocelot
->bridge_fwd_mask
&= ~BIT(port
);
1413 ocelot_write_gix(ocelot
, port_cfg
, ANA_PORT_PORT_CFG
, port
);
1415 /* Apply FWD mask. The loop is needed to add/remove the current port as
1416 * a source for the other ports.
1418 for (p
= 0; p
< ocelot
->num_phys_ports
; p
++) {
1419 if (ocelot
->bridge_fwd_mask
& BIT(p
)) {
1420 unsigned long mask
= ocelot
->bridge_fwd_mask
& ~BIT(p
);
1422 for (i
= 0; i
< ocelot
->num_phys_ports
; i
++) {
1423 unsigned long bond_mask
= ocelot
->lags
[i
];
1428 if (bond_mask
& BIT(p
)) {
1434 ocelot_write_rix(ocelot
, mask
,
1435 ANA_PGID_PGID
, PGID_SRC
+ p
);
1437 ocelot_write_rix(ocelot
, 0,
1438 ANA_PGID_PGID
, PGID_SRC
+ p
);
1442 EXPORT_SYMBOL(ocelot_bridge_stp_state_set
);
1444 static void ocelot_port_attr_stp_state_set(struct ocelot
*ocelot
, int port
,
1445 struct switchdev_trans
*trans
,
1448 if (switchdev_trans_ph_prepare(trans
))
1451 ocelot_bridge_stp_state_set(ocelot
, port
, state
);
1454 void ocelot_set_ageing_time(struct ocelot
*ocelot
, unsigned int msecs
)
1456 ocelot_write(ocelot
, ANA_AUTOAGE_AGE_PERIOD(msecs
/ 2),
1459 EXPORT_SYMBOL(ocelot_set_ageing_time
);
1461 static void ocelot_port_attr_ageing_set(struct ocelot
*ocelot
, int port
,
1462 unsigned long ageing_clock_t
)
1464 unsigned long ageing_jiffies
= clock_t_to_jiffies(ageing_clock_t
);
1465 u32 ageing_time
= jiffies_to_msecs(ageing_jiffies
) / 1000;
1467 ocelot_set_ageing_time(ocelot
, ageing_time
);
1470 static void ocelot_port_attr_mc_set(struct ocelot
*ocelot
, int port
, bool mc
)
1472 u32 cpu_fwd_mcast
= ANA_PORT_CPU_FWD_CFG_CPU_IGMP_REDIR_ENA
|
1473 ANA_PORT_CPU_FWD_CFG_CPU_MLD_REDIR_ENA
|
1474 ANA_PORT_CPU_FWD_CFG_CPU_IPMC_CTRL_COPY_ENA
;
1478 val
= cpu_fwd_mcast
;
1480 ocelot_rmw_gix(ocelot
, val
, cpu_fwd_mcast
,
1481 ANA_PORT_CPU_FWD_CFG
, port
);
1484 static int ocelot_port_attr_set(struct net_device
*dev
,
1485 const struct switchdev_attr
*attr
,
1486 struct switchdev_trans
*trans
)
1488 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1489 struct ocelot
*ocelot
= priv
->port
.ocelot
;
1490 int port
= priv
->chip_port
;
1494 case SWITCHDEV_ATTR_ID_PORT_STP_STATE
:
1495 ocelot_port_attr_stp_state_set(ocelot
, port
, trans
,
1498 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME
:
1499 ocelot_port_attr_ageing_set(ocelot
, port
, attr
->u
.ageing_time
);
1501 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING
:
1502 ocelot_port_vlan_filtering(ocelot
, port
,
1503 attr
->u
.vlan_filtering
);
1505 case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED
:
1506 ocelot_port_attr_mc_set(ocelot
, port
, !attr
->u
.mc_disabled
);
1516 static int ocelot_port_obj_add_vlan(struct net_device
*dev
,
1517 const struct switchdev_obj_port_vlan
*vlan
,
1518 struct switchdev_trans
*trans
)
1523 for (vid
= vlan
->vid_begin
; vid
<= vlan
->vid_end
; vid
++) {
1524 ret
= ocelot_vlan_vid_add(dev
, vid
,
1525 vlan
->flags
& BRIDGE_VLAN_INFO_PVID
,
1526 vlan
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
);
1534 static int ocelot_port_vlan_del_vlan(struct net_device
*dev
,
1535 const struct switchdev_obj_port_vlan
*vlan
)
1540 for (vid
= vlan
->vid_begin
; vid
<= vlan
->vid_end
; vid
++) {
1541 ret
= ocelot_vlan_vid_del(dev
, vid
);
1550 static struct ocelot_multicast
*ocelot_multicast_get(struct ocelot
*ocelot
,
1551 const unsigned char *addr
,
1554 struct ocelot_multicast
*mc
;
1556 list_for_each_entry(mc
, &ocelot
->multicast
, list
) {
1557 if (ether_addr_equal(mc
->addr
, addr
) && mc
->vid
== vid
)
1564 static int ocelot_port_obj_add_mdb(struct net_device
*dev
,
1565 const struct switchdev_obj_port_mdb
*mdb
,
1566 struct switchdev_trans
*trans
)
1568 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1569 struct ocelot_port
*ocelot_port
= &priv
->port
;
1570 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
1571 unsigned char addr
[ETH_ALEN
];
1572 struct ocelot_multicast
*mc
;
1573 int port
= priv
->chip_port
;
1578 vid
= ocelot_port
->pvid
;
1580 mc
= ocelot_multicast_get(ocelot
, mdb
->addr
, vid
);
1582 mc
= devm_kzalloc(ocelot
->dev
, sizeof(*mc
), GFP_KERNEL
);
1586 memcpy(mc
->addr
, mdb
->addr
, ETH_ALEN
);
1589 list_add_tail(&mc
->list
, &ocelot
->multicast
);
1593 memcpy(addr
, mc
->addr
, ETH_ALEN
);
1597 addr
[2] = mc
->ports
<< 0;
1598 addr
[1] = mc
->ports
<< 8;
1599 ocelot_mact_forget(ocelot
, addr
, vid
);
1602 mc
->ports
|= BIT(port
);
1603 addr
[2] = mc
->ports
<< 0;
1604 addr
[1] = mc
->ports
<< 8;
1606 return ocelot_mact_learn(ocelot
, 0, addr
, vid
, ENTRYTYPE_MACv4
);
1609 static int ocelot_port_obj_del_mdb(struct net_device
*dev
,
1610 const struct switchdev_obj_port_mdb
*mdb
)
1612 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1613 struct ocelot_port
*ocelot_port
= &priv
->port
;
1614 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
1615 unsigned char addr
[ETH_ALEN
];
1616 struct ocelot_multicast
*mc
;
1617 int port
= priv
->chip_port
;
1621 vid
= ocelot_port
->pvid
;
1623 mc
= ocelot_multicast_get(ocelot
, mdb
->addr
, vid
);
1627 memcpy(addr
, mc
->addr
, ETH_ALEN
);
1628 addr
[2] = mc
->ports
<< 0;
1629 addr
[1] = mc
->ports
<< 8;
1631 ocelot_mact_forget(ocelot
, addr
, vid
);
1633 mc
->ports
&= ~BIT(port
);
1635 list_del(&mc
->list
);
1636 devm_kfree(ocelot
->dev
, mc
);
1640 addr
[2] = mc
->ports
<< 0;
1641 addr
[1] = mc
->ports
<< 8;
1643 return ocelot_mact_learn(ocelot
, 0, addr
, vid
, ENTRYTYPE_MACv4
);
1646 static int ocelot_port_obj_add(struct net_device
*dev
,
1647 const struct switchdev_obj
*obj
,
1648 struct switchdev_trans
*trans
,
1649 struct netlink_ext_ack
*extack
)
1654 case SWITCHDEV_OBJ_ID_PORT_VLAN
:
1655 ret
= ocelot_port_obj_add_vlan(dev
,
1656 SWITCHDEV_OBJ_PORT_VLAN(obj
),
1659 case SWITCHDEV_OBJ_ID_PORT_MDB
:
1660 ret
= ocelot_port_obj_add_mdb(dev
, SWITCHDEV_OBJ_PORT_MDB(obj
),
1670 static int ocelot_port_obj_del(struct net_device
*dev
,
1671 const struct switchdev_obj
*obj
)
1676 case SWITCHDEV_OBJ_ID_PORT_VLAN
:
1677 ret
= ocelot_port_vlan_del_vlan(dev
,
1678 SWITCHDEV_OBJ_PORT_VLAN(obj
));
1680 case SWITCHDEV_OBJ_ID_PORT_MDB
:
1681 ret
= ocelot_port_obj_del_mdb(dev
, SWITCHDEV_OBJ_PORT_MDB(obj
));
1690 int ocelot_port_bridge_join(struct ocelot
*ocelot
, int port
,
1691 struct net_device
*bridge
)
1693 if (!ocelot
->bridge_mask
) {
1694 ocelot
->hw_bridge_dev
= bridge
;
1696 if (ocelot
->hw_bridge_dev
!= bridge
)
1697 /* This is adding the port to a second bridge, this is
1702 ocelot
->bridge_mask
|= BIT(port
);
1706 EXPORT_SYMBOL(ocelot_port_bridge_join
);
1708 int ocelot_port_bridge_leave(struct ocelot
*ocelot
, int port
,
1709 struct net_device
*bridge
)
1711 ocelot
->bridge_mask
&= ~BIT(port
);
1713 if (!ocelot
->bridge_mask
)
1714 ocelot
->hw_bridge_dev
= NULL
;
1716 ocelot_port_vlan_filtering(ocelot
, port
, 0);
1717 ocelot_port_set_pvid(ocelot
, port
, 0);
1718 return ocelot_port_set_native_vlan(ocelot
, port
, 0);
1720 EXPORT_SYMBOL(ocelot_port_bridge_leave
);
1722 static void ocelot_set_aggr_pgids(struct ocelot
*ocelot
)
1726 /* Reset destination and aggregation PGIDS */
1727 for (port
= 0; port
< ocelot
->num_phys_ports
; port
++)
1728 ocelot_write_rix(ocelot
, BIT(port
), ANA_PGID_PGID
, port
);
1730 for (i
= PGID_AGGR
; i
< PGID_SRC
; i
++)
1731 ocelot_write_rix(ocelot
, GENMASK(ocelot
->num_phys_ports
- 1, 0),
1734 /* Now, set PGIDs for each LAG */
1735 for (lag
= 0; lag
< ocelot
->num_phys_ports
; lag
++) {
1736 unsigned long bond_mask
;
1740 bond_mask
= ocelot
->lags
[lag
];
1744 for_each_set_bit(port
, &bond_mask
, ocelot
->num_phys_ports
) {
1746 ocelot_write_rix(ocelot
, bond_mask
,
1747 ANA_PGID_PGID
, port
);
1748 aggr_idx
[aggr_count
] = port
;
1752 for (i
= PGID_AGGR
; i
< PGID_SRC
; i
++) {
1755 ac
= ocelot_read_rix(ocelot
, ANA_PGID_PGID
, i
);
1757 ac
|= BIT(aggr_idx
[i
% aggr_count
]);
1758 ocelot_write_rix(ocelot
, ac
, ANA_PGID_PGID
, i
);
1763 static void ocelot_setup_lag(struct ocelot
*ocelot
, int lag
)
1765 unsigned long bond_mask
= ocelot
->lags
[lag
];
1768 for_each_set_bit(p
, &bond_mask
, ocelot
->num_phys_ports
) {
1769 u32 port_cfg
= ocelot_read_gix(ocelot
, ANA_PORT_PORT_CFG
, p
);
1771 port_cfg
&= ~ANA_PORT_PORT_CFG_PORTID_VAL_M
;
1773 /* Use lag port as logical port for port i */
1774 ocelot_write_gix(ocelot
, port_cfg
|
1775 ANA_PORT_PORT_CFG_PORTID_VAL(lag
),
1776 ANA_PORT_PORT_CFG
, p
);
1780 static int ocelot_port_lag_join(struct ocelot
*ocelot
, int port
,
1781 struct net_device
*bond
)
1783 struct net_device
*ndev
;
1788 for_each_netdev_in_bond_rcu(bond
, ndev
) {
1789 struct ocelot_port_private
*priv
= netdev_priv(ndev
);
1791 bond_mask
|= BIT(priv
->chip_port
);
1795 lp
= __ffs(bond_mask
);
1797 /* If the new port is the lowest one, use it as the logical port from
1802 ocelot
->lags
[port
] = bond_mask
;
1803 bond_mask
&= ~BIT(port
);
1805 lp
= __ffs(bond_mask
);
1806 ocelot
->lags
[lp
] = 0;
1810 ocelot
->lags
[lp
] |= BIT(port
);
1813 ocelot_setup_lag(ocelot
, lag
);
1814 ocelot_set_aggr_pgids(ocelot
);
1819 static void ocelot_port_lag_leave(struct ocelot
*ocelot
, int port
,
1820 struct net_device
*bond
)
1825 /* Remove port from any lag */
1826 for (i
= 0; i
< ocelot
->num_phys_ports
; i
++)
1827 ocelot
->lags
[i
] &= ~BIT(port
);
1829 /* if it was the logical port of the lag, move the lag config to the
1832 if (ocelot
->lags
[port
]) {
1833 int n
= __ffs(ocelot
->lags
[port
]);
1835 ocelot
->lags
[n
] = ocelot
->lags
[port
];
1836 ocelot
->lags
[port
] = 0;
1838 ocelot_setup_lag(ocelot
, n
);
1841 port_cfg
= ocelot_read_gix(ocelot
, ANA_PORT_PORT_CFG
, port
);
1842 port_cfg
&= ~ANA_PORT_PORT_CFG_PORTID_VAL_M
;
1843 ocelot_write_gix(ocelot
, port_cfg
| ANA_PORT_PORT_CFG_PORTID_VAL(port
),
1844 ANA_PORT_PORT_CFG
, port
);
1846 ocelot_set_aggr_pgids(ocelot
);
1849 /* Checks if the net_device instance given to us originate from our driver. */
1850 static bool ocelot_netdevice_dev_check(const struct net_device
*dev
)
1852 return dev
->netdev_ops
== &ocelot_port_netdev_ops
;
1855 static int ocelot_netdevice_port_event(struct net_device
*dev
,
1856 unsigned long event
,
1857 struct netdev_notifier_changeupper_info
*info
)
1859 struct ocelot_port_private
*priv
= netdev_priv(dev
);
1860 struct ocelot_port
*ocelot_port
= &priv
->port
;
1861 struct ocelot
*ocelot
= ocelot_port
->ocelot
;
1862 int port
= priv
->chip_port
;
1866 case NETDEV_CHANGEUPPER
:
1867 if (netif_is_bridge_master(info
->upper_dev
)) {
1868 if (info
->linking
) {
1869 err
= ocelot_port_bridge_join(ocelot
, port
,
1872 err
= ocelot_port_bridge_leave(ocelot
, port
,
1876 if (netif_is_lag_master(info
->upper_dev
)) {
1878 err
= ocelot_port_lag_join(ocelot
, port
,
1881 ocelot_port_lag_leave(ocelot
, port
,
1892 static int ocelot_netdevice_event(struct notifier_block
*unused
,
1893 unsigned long event
, void *ptr
)
1895 struct netdev_notifier_changeupper_info
*info
= ptr
;
1896 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
1899 if (!ocelot_netdevice_dev_check(dev
))
1902 if (event
== NETDEV_PRECHANGEUPPER
&&
1903 netif_is_lag_master(info
->upper_dev
)) {
1904 struct netdev_lag_upper_info
*lag_upper_info
= info
->upper_info
;
1905 struct netlink_ext_ack
*extack
;
1907 if (lag_upper_info
&&
1908 lag_upper_info
->tx_type
!= NETDEV_LAG_TX_TYPE_HASH
) {
1909 extack
= netdev_notifier_info_to_extack(&info
->info
);
1910 NL_SET_ERR_MSG_MOD(extack
, "LAG device using unsupported Tx type");
1917 if (netif_is_lag_master(dev
)) {
1918 struct net_device
*slave
;
1919 struct list_head
*iter
;
1921 netdev_for_each_lower_dev(dev
, slave
, iter
) {
1922 ret
= ocelot_netdevice_port_event(slave
, event
, info
);
1927 ret
= ocelot_netdevice_port_event(dev
, event
, info
);
1931 return notifier_from_errno(ret
);
1934 struct notifier_block ocelot_netdevice_nb __read_mostly
= {
1935 .notifier_call
= ocelot_netdevice_event
,
1937 EXPORT_SYMBOL(ocelot_netdevice_nb
);
1939 static int ocelot_switchdev_event(struct notifier_block
*unused
,
1940 unsigned long event
, void *ptr
)
1942 struct net_device
*dev
= switchdev_notifier_info_to_dev(ptr
);
1946 case SWITCHDEV_PORT_ATTR_SET
:
1947 err
= switchdev_handle_port_attr_set(dev
, ptr
,
1948 ocelot_netdevice_dev_check
,
1949 ocelot_port_attr_set
);
1950 return notifier_from_errno(err
);
1956 struct notifier_block ocelot_switchdev_nb __read_mostly
= {
1957 .notifier_call
= ocelot_switchdev_event
,
1959 EXPORT_SYMBOL(ocelot_switchdev_nb
);
1961 static int ocelot_switchdev_blocking_event(struct notifier_block
*unused
,
1962 unsigned long event
, void *ptr
)
1964 struct net_device
*dev
= switchdev_notifier_info_to_dev(ptr
);
1968 /* Blocking events. */
1969 case SWITCHDEV_PORT_OBJ_ADD
:
1970 err
= switchdev_handle_port_obj_add(dev
, ptr
,
1971 ocelot_netdevice_dev_check
,
1972 ocelot_port_obj_add
);
1973 return notifier_from_errno(err
);
1974 case SWITCHDEV_PORT_OBJ_DEL
:
1975 err
= switchdev_handle_port_obj_del(dev
, ptr
,
1976 ocelot_netdevice_dev_check
,
1977 ocelot_port_obj_del
);
1978 return notifier_from_errno(err
);
1979 case SWITCHDEV_PORT_ATTR_SET
:
1980 err
= switchdev_handle_port_attr_set(dev
, ptr
,
1981 ocelot_netdevice_dev_check
,
1982 ocelot_port_attr_set
);
1983 return notifier_from_errno(err
);
1989 struct notifier_block ocelot_switchdev_blocking_nb __read_mostly
= {
1990 .notifier_call
= ocelot_switchdev_blocking_event
,
1992 EXPORT_SYMBOL(ocelot_switchdev_blocking_nb
);
1994 int ocelot_ptp_gettime64(struct ptp_clock_info
*ptp
, struct timespec64
*ts
)
1996 struct ocelot
*ocelot
= container_of(ptp
, struct ocelot
, ptp_info
);
1997 unsigned long flags
;
2002 spin_lock_irqsave(&ocelot
->ptp_clock_lock
, flags
);
2004 val
= ocelot_read_rix(ocelot
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2005 val
&= ~(PTP_PIN_CFG_SYNC
| PTP_PIN_CFG_ACTION_MASK
| PTP_PIN_CFG_DOM
);
2006 val
|= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_SAVE
);
2007 ocelot_write_rix(ocelot
, val
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2009 s
= ocelot_read_rix(ocelot
, PTP_PIN_TOD_SEC_MSB
, TOD_ACC_PIN
) & 0xffff;
2011 s
+= ocelot_read_rix(ocelot
, PTP_PIN_TOD_SEC_LSB
, TOD_ACC_PIN
);
2012 ns
= ocelot_read_rix(ocelot
, PTP_PIN_TOD_NSEC
, TOD_ACC_PIN
);
2014 spin_unlock_irqrestore(&ocelot
->ptp_clock_lock
, flags
);
2016 /* Deal with negative values */
2017 if (ns
>= 0x3ffffff0 && ns
<= 0x3fffffff) {
2023 set_normalized_timespec64(ts
, s
, ns
);
2026 EXPORT_SYMBOL(ocelot_ptp_gettime64
);
2028 static int ocelot_ptp_settime64(struct ptp_clock_info
*ptp
,
2029 const struct timespec64
*ts
)
2031 struct ocelot
*ocelot
= container_of(ptp
, struct ocelot
, ptp_info
);
2032 unsigned long flags
;
2035 spin_lock_irqsave(&ocelot
->ptp_clock_lock
, flags
);
2037 val
= ocelot_read_rix(ocelot
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2038 val
&= ~(PTP_PIN_CFG_SYNC
| PTP_PIN_CFG_ACTION_MASK
| PTP_PIN_CFG_DOM
);
2039 val
|= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_IDLE
);
2041 ocelot_write_rix(ocelot
, val
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2043 ocelot_write_rix(ocelot
, lower_32_bits(ts
->tv_sec
), PTP_PIN_TOD_SEC_LSB
,
2045 ocelot_write_rix(ocelot
, upper_32_bits(ts
->tv_sec
), PTP_PIN_TOD_SEC_MSB
,
2047 ocelot_write_rix(ocelot
, ts
->tv_nsec
, PTP_PIN_TOD_NSEC
, TOD_ACC_PIN
);
2049 val
= ocelot_read_rix(ocelot
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2050 val
&= ~(PTP_PIN_CFG_SYNC
| PTP_PIN_CFG_ACTION_MASK
| PTP_PIN_CFG_DOM
);
2051 val
|= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_LOAD
);
2053 ocelot_write_rix(ocelot
, val
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2055 spin_unlock_irqrestore(&ocelot
->ptp_clock_lock
, flags
);
2059 static int ocelot_ptp_adjtime(struct ptp_clock_info
*ptp
, s64 delta
)
2061 if (delta
> -(NSEC_PER_SEC
/ 2) && delta
< (NSEC_PER_SEC
/ 2)) {
2062 struct ocelot
*ocelot
= container_of(ptp
, struct ocelot
, ptp_info
);
2063 unsigned long flags
;
2066 spin_lock_irqsave(&ocelot
->ptp_clock_lock
, flags
);
2068 val
= ocelot_read_rix(ocelot
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2069 val
&= ~(PTP_PIN_CFG_SYNC
| PTP_PIN_CFG_ACTION_MASK
| PTP_PIN_CFG_DOM
);
2070 val
|= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_IDLE
);
2072 ocelot_write_rix(ocelot
, val
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2074 ocelot_write_rix(ocelot
, 0, PTP_PIN_TOD_SEC_LSB
, TOD_ACC_PIN
);
2075 ocelot_write_rix(ocelot
, 0, PTP_PIN_TOD_SEC_MSB
, TOD_ACC_PIN
);
2076 ocelot_write_rix(ocelot
, delta
, PTP_PIN_TOD_NSEC
, TOD_ACC_PIN
);
2078 val
= ocelot_read_rix(ocelot
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2079 val
&= ~(PTP_PIN_CFG_SYNC
| PTP_PIN_CFG_ACTION_MASK
| PTP_PIN_CFG_DOM
);
2080 val
|= PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_DELTA
);
2082 ocelot_write_rix(ocelot
, val
, PTP_PIN_CFG
, TOD_ACC_PIN
);
2084 spin_unlock_irqrestore(&ocelot
->ptp_clock_lock
, flags
);
2086 /* Fall back using ocelot_ptp_settime64 which is not exact. */
2087 struct timespec64 ts
;
2090 ocelot_ptp_gettime64(ptp
, &ts
);
2092 now
= ktime_to_ns(timespec64_to_ktime(ts
));
2093 ts
= ns_to_timespec64(now
+ delta
);
2095 ocelot_ptp_settime64(ptp
, &ts
);
2100 static int ocelot_ptp_adjfine(struct ptp_clock_info
*ptp
, long scaled_ppm
)
2102 struct ocelot
*ocelot
= container_of(ptp
, struct ocelot
, ptp_info
);
2103 u32 unit
= 0, direction
= 0;
2104 unsigned long flags
;
2107 spin_lock_irqsave(&ocelot
->ptp_clock_lock
, flags
);
2112 if (scaled_ppm
< 0) {
2113 direction
= PTP_CFG_CLK_ADJ_CFG_DIR
;
2114 scaled_ppm
= -scaled_ppm
;
2117 adj
= PSEC_PER_SEC
<< 16;
2118 do_div(adj
, scaled_ppm
);
2121 /* If the adjustment value is too large, use ns instead */
2122 if (adj
>= (1L << 30)) {
2123 unit
= PTP_CFG_CLK_ADJ_FREQ_NS
;
2128 if (adj
>= (1L << 30))
2131 ocelot_write(ocelot
, unit
| adj
, PTP_CLK_CFG_ADJ_FREQ
);
2132 ocelot_write(ocelot
, PTP_CFG_CLK_ADJ_CFG_ENA
| direction
,
2133 PTP_CLK_CFG_ADJ_CFG
);
2135 spin_unlock_irqrestore(&ocelot
->ptp_clock_lock
, flags
);
2139 ocelot_write(ocelot
, 0, PTP_CLK_CFG_ADJ_CFG
);
2141 spin_unlock_irqrestore(&ocelot
->ptp_clock_lock
, flags
);
2145 static struct ptp_clock_info ocelot_ptp_clock_info
= {
2146 .owner
= THIS_MODULE
,
2147 .name
= "ocelot ptp",
2148 .max_adj
= 0x7fffffff,
2154 .gettime64
= ocelot_ptp_gettime64
,
2155 .settime64
= ocelot_ptp_settime64
,
2156 .adjtime
= ocelot_ptp_adjtime
,
2157 .adjfine
= ocelot_ptp_adjfine
,
2160 static int ocelot_init_timestamp(struct ocelot
*ocelot
)
2162 struct ptp_clock
*ptp_clock
;
2164 ocelot
->ptp_info
= ocelot_ptp_clock_info
;
2165 ptp_clock
= ptp_clock_register(&ocelot
->ptp_info
, ocelot
->dev
);
2166 if (IS_ERR(ptp_clock
))
2167 return PTR_ERR(ptp_clock
);
2168 /* Check if PHC support is missing at the configuration level */
2172 ocelot
->ptp_clock
= ptp_clock
;
2174 ocelot_write(ocelot
, SYS_PTP_CFG_PTP_STAMP_WID(30), SYS_PTP_CFG
);
2175 ocelot_write(ocelot
, 0xffffffff, ANA_TABLES_PTP_ID_LOW
);
2176 ocelot_write(ocelot
, 0xffffffff, ANA_TABLES_PTP_ID_HIGH
);
2178 ocelot_write(ocelot
, PTP_CFG_MISC_PTP_EN
, PTP_CFG_MISC
);
2180 /* There is no device reconfiguration, PTP Rx stamping is always
2183 ocelot
->hwtstamp_config
.rx_filter
= HWTSTAMP_FILTER_PTP_V2_EVENT
;
2188 /* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu.
2189 * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG.
2190 * In the special case that it's the NPI port that we're configuring, the
2191 * length of the tag and optional prefix needs to be accounted for privately,
2192 * in order to be able to sustain communication at the requested @sdu.
2194 void ocelot_port_set_maxlen(struct ocelot
*ocelot
, int port
, size_t sdu
)
2196 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
2197 int maxlen
= sdu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2200 if (port
== ocelot
->npi
) {
2201 maxlen
+= OCELOT_TAG_LEN
;
2203 if (ocelot
->inj_prefix
== OCELOT_TAG_PREFIX_SHORT
)
2204 maxlen
+= OCELOT_SHORT_PREFIX_LEN
;
2205 else if (ocelot
->inj_prefix
== OCELOT_TAG_PREFIX_LONG
)
2206 maxlen
+= OCELOT_LONG_PREFIX_LEN
;
2209 ocelot_port_writel(ocelot_port
, maxlen
, DEV_MAC_MAXLEN_CFG
);
2211 /* Set Pause WM hysteresis
2212 * 152 = 6 * maxlen / OCELOT_BUFFER_CELL_SZ
2213 * 101 = 4 * maxlen / OCELOT_BUFFER_CELL_SZ
2215 ocelot_write_rix(ocelot
, SYS_PAUSE_CFG_PAUSE_ENA
|
2216 SYS_PAUSE_CFG_PAUSE_STOP(101) |
2217 SYS_PAUSE_CFG_PAUSE_START(152), SYS_PAUSE_CFG
, port
);
2219 /* Tail dropping watermark */
2220 atop_wm
= (ocelot
->shared_queue_sz
- 9 * maxlen
) /
2221 OCELOT_BUFFER_CELL_SZ
;
2222 ocelot_write_rix(ocelot
, ocelot_wm_enc(9 * maxlen
),
2224 ocelot_write(ocelot
, ocelot_wm_enc(atop_wm
), SYS_ATOP_TOT_CFG
);
2226 EXPORT_SYMBOL(ocelot_port_set_maxlen
);
2228 int ocelot_get_max_mtu(struct ocelot
*ocelot
, int port
)
2230 int max_mtu
= 65535 - ETH_HLEN
- ETH_FCS_LEN
;
2232 if (port
== ocelot
->npi
) {
2233 max_mtu
-= OCELOT_TAG_LEN
;
2235 if (ocelot
->inj_prefix
== OCELOT_TAG_PREFIX_SHORT
)
2236 max_mtu
-= OCELOT_SHORT_PREFIX_LEN
;
2237 else if (ocelot
->inj_prefix
== OCELOT_TAG_PREFIX_LONG
)
2238 max_mtu
-= OCELOT_LONG_PREFIX_LEN
;
2243 EXPORT_SYMBOL(ocelot_get_max_mtu
);
2245 void ocelot_init_port(struct ocelot
*ocelot
, int port
)
2247 struct ocelot_port
*ocelot_port
= ocelot
->ports
[port
];
2249 skb_queue_head_init(&ocelot_port
->tx_skbs
);
2251 /* Basic L2 initialization */
2254 * FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 0
2255 * !FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 5
2257 ocelot_port_writel(ocelot_port
, DEV_MAC_IFG_CFG_TX_IFG(5),
2260 /* Load seed (0) and set MAC HDX late collision */
2261 ocelot_port_writel(ocelot_port
, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
2262 DEV_MAC_HDX_CFG_SEED_LOAD
,
2265 ocelot_port_writel(ocelot_port
, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
2268 /* Set Max Length and maximum tags allowed */
2269 ocelot_port_set_maxlen(ocelot
, port
, ETH_DATA_LEN
);
2270 ocelot_port_writel(ocelot_port
, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD
) |
2271 DEV_MAC_TAGS_CFG_VLAN_AWR_ENA
|
2272 DEV_MAC_TAGS_CFG_VLAN_DBL_AWR_ENA
|
2273 DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA
,
2276 /* Set SMAC of Pause frame (00:00:00:00:00:00) */
2277 ocelot_port_writel(ocelot_port
, 0, DEV_MAC_FC_MAC_HIGH_CFG
);
2278 ocelot_port_writel(ocelot_port
, 0, DEV_MAC_FC_MAC_LOW_CFG
);
2280 /* Drop frames with multicast source address */
2281 ocelot_rmw_gix(ocelot
, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA
,
2282 ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA
,
2283 ANA_PORT_DROP_CFG
, port
);
2285 /* Set default VLAN and tag type to 8021Q. */
2286 ocelot_rmw_gix(ocelot
, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q
),
2287 REW_PORT_VLAN_CFG_PORT_TPID_M
,
2288 REW_PORT_VLAN_CFG
, port
);
2290 /* Enable vcap lookups */
2291 ocelot_vcap_enable(ocelot
, port
);
2293 EXPORT_SYMBOL(ocelot_init_port
);
2295 int ocelot_probe_port(struct ocelot
*ocelot
, u8 port
,
2297 struct phy_device
*phy
)
2299 struct ocelot_port_private
*priv
;
2300 struct ocelot_port
*ocelot_port
;
2301 struct net_device
*dev
;
2304 dev
= alloc_etherdev(sizeof(struct ocelot_port_private
));
2307 SET_NETDEV_DEV(dev
, ocelot
->dev
);
2308 priv
= netdev_priv(dev
);
2311 priv
->chip_port
= port
;
2312 ocelot_port
= &priv
->port
;
2313 ocelot_port
->ocelot
= ocelot
;
2314 ocelot_port
->regs
= regs
;
2315 ocelot
->ports
[port
] = ocelot_port
;
2317 dev
->netdev_ops
= &ocelot_port_netdev_ops
;
2318 dev
->ethtool_ops
= &ocelot_ethtool_ops
;
2320 dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_FILTER
| NETIF_F_RXFCS
|
2322 dev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
| NETIF_F_HW_TC
;
2324 memcpy(dev
->dev_addr
, ocelot
->base_mac
, ETH_ALEN
);
2325 dev
->dev_addr
[ETH_ALEN
- 1] += port
;
2326 ocelot_mact_learn(ocelot
, PGID_CPU
, dev
->dev_addr
, ocelot_port
->pvid
,
2329 ocelot_init_port(ocelot
, port
);
2331 err
= register_netdev(dev
);
2333 dev_err(ocelot
->dev
, "register_netdev failed\n");
2339 EXPORT_SYMBOL(ocelot_probe_port
);
2341 /* Configure and enable the CPU port module, which is a set of queues.
2342 * If @npi contains a valid port index, the CPU port module is connected
2343 * to the Node Processor Interface (NPI). This is the mode through which
2344 * frames can be injected from and extracted to an external CPU,
2347 void ocelot_configure_cpu(struct ocelot
*ocelot
, int npi
,
2348 enum ocelot_tag_prefix injection
,
2349 enum ocelot_tag_prefix extraction
)
2351 int cpu
= ocelot
->num_phys_ports
;
2354 ocelot
->inj_prefix
= injection
;
2355 ocelot
->xtr_prefix
= extraction
;
2357 /* The unicast destination PGID for the CPU port module is unused */
2358 ocelot_write_rix(ocelot
, 0, ANA_PGID_PGID
, cpu
);
2359 /* Instead set up a multicast destination PGID for traffic copied to
2360 * the CPU. Whitelisted MAC addresses like the port netdevice MAC
2361 * addresses will be copied to the CPU via this PGID.
2363 ocelot_write_rix(ocelot
, BIT(cpu
), ANA_PGID_PGID
, PGID_CPU
);
2364 ocelot_write_gix(ocelot
, ANA_PORT_PORT_CFG_RECV_ENA
|
2365 ANA_PORT_PORT_CFG_PORTID_VAL(cpu
),
2366 ANA_PORT_PORT_CFG
, cpu
);
2368 if (npi
>= 0 && npi
< ocelot
->num_phys_ports
) {
2369 ocelot_write(ocelot
, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M
|
2370 QSYS_EXT_CPU_CFG_EXT_CPU_PORT(npi
),
2373 /* Enable NPI port */
2374 ocelot_write_rix(ocelot
,
2375 QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE
|
2376 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG(1) |
2377 QSYS_SWITCH_PORT_MODE_PORT_ENA
,
2378 QSYS_SWITCH_PORT_MODE
, npi
);
2379 /* NPI port Injection/Extraction configuration */
2380 ocelot_write_rix(ocelot
,
2381 SYS_PORT_MODE_INCL_XTR_HDR(extraction
) |
2382 SYS_PORT_MODE_INCL_INJ_HDR(injection
),
2383 SYS_PORT_MODE
, npi
);
2386 /* Enable CPU port module */
2387 ocelot_write_rix(ocelot
, QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE
|
2388 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG(1) |
2389 QSYS_SWITCH_PORT_MODE_PORT_ENA
,
2390 QSYS_SWITCH_PORT_MODE
, cpu
);
2391 /* CPU port Injection/Extraction configuration */
2392 ocelot_write_rix(ocelot
, SYS_PORT_MODE_INCL_XTR_HDR(extraction
) |
2393 SYS_PORT_MODE_INCL_INJ_HDR(injection
),
2394 SYS_PORT_MODE
, cpu
);
2396 /* Configure the CPU port to be VLAN aware */
2397 ocelot_write_gix(ocelot
, ANA_PORT_VLAN_CFG_VLAN_VID(0) |
2398 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA
|
2399 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1),
2400 ANA_PORT_VLAN_CFG
, cpu
);
2402 EXPORT_SYMBOL(ocelot_configure_cpu
);
2404 int ocelot_init(struct ocelot
*ocelot
)
2406 char queue_name
[32];
2410 if (ocelot
->ops
->reset
) {
2411 ret
= ocelot
->ops
->reset(ocelot
);
2413 dev_err(ocelot
->dev
, "Switch reset failed\n");
2418 ocelot
->lags
= devm_kcalloc(ocelot
->dev
, ocelot
->num_phys_ports
,
2419 sizeof(u32
), GFP_KERNEL
);
2423 ocelot
->stats
= devm_kcalloc(ocelot
->dev
,
2424 ocelot
->num_phys_ports
* ocelot
->num_stats
,
2425 sizeof(u64
), GFP_KERNEL
);
2429 mutex_init(&ocelot
->stats_lock
);
2430 mutex_init(&ocelot
->ptp_lock
);
2431 spin_lock_init(&ocelot
->ptp_clock_lock
);
2432 snprintf(queue_name
, sizeof(queue_name
), "%s-stats",
2433 dev_name(ocelot
->dev
));
2434 ocelot
->stats_queue
= create_singlethread_workqueue(queue_name
);
2435 if (!ocelot
->stats_queue
)
2438 INIT_LIST_HEAD(&ocelot
->multicast
);
2439 ocelot_mact_init(ocelot
);
2440 ocelot_vlan_init(ocelot
);
2441 ocelot_ace_init(ocelot
);
2443 for (port
= 0; port
< ocelot
->num_phys_ports
; port
++) {
2444 /* Clear all counters (5 groups) */
2445 ocelot_write(ocelot
, SYS_STAT_CFG_STAT_VIEW(port
) |
2446 SYS_STAT_CFG_STAT_CLEAR_SHOT(0x7f),
2450 /* Only use S-Tag */
2451 ocelot_write(ocelot
, ETH_P_8021AD
, SYS_VLAN_ETYPE_CFG
);
2453 /* Aggregation mode */
2454 ocelot_write(ocelot
, ANA_AGGR_CFG_AC_SMAC_ENA
|
2455 ANA_AGGR_CFG_AC_DMAC_ENA
|
2456 ANA_AGGR_CFG_AC_IP4_SIPDIP_ENA
|
2457 ANA_AGGR_CFG_AC_IP4_TCPUDP_ENA
, ANA_AGGR_CFG
);
2459 /* Set MAC age time to default value. The entry is aged after
2462 ocelot_write(ocelot
,
2463 ANA_AUTOAGE_AGE_PERIOD(BR_DEFAULT_AGEING_TIME
/ 2 / HZ
),
2466 /* Disable learning for frames discarded by VLAN ingress filtering */
2467 regmap_field_write(ocelot
->regfields
[ANA_ADVLEARN_VLAN_CHK
], 1);
2469 /* Setup frame ageing - fixed value "2 sec" - in 6.5 us units */
2470 ocelot_write(ocelot
, SYS_FRM_AGING_AGE_TX_ENA
|
2471 SYS_FRM_AGING_MAX_AGE(307692), SYS_FRM_AGING
);
2473 /* Setup flooding PGIDs */
2474 ocelot_write_rix(ocelot
, ANA_FLOODING_FLD_MULTICAST(PGID_MC
) |
2475 ANA_FLOODING_FLD_BROADCAST(PGID_MC
) |
2476 ANA_FLOODING_FLD_UNICAST(PGID_UC
),
2478 ocelot_write(ocelot
, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6
) |
2479 ANA_FLOODING_IPMC_FLD_MC6_CTRL(PGID_MC
) |
2480 ANA_FLOODING_IPMC_FLD_MC4_DATA(PGID_MCIPV4
) |
2481 ANA_FLOODING_IPMC_FLD_MC4_CTRL(PGID_MC
),
2484 for (port
= 0; port
< ocelot
->num_phys_ports
; port
++) {
2485 /* Transmit the frame to the local port. */
2486 ocelot_write_rix(ocelot
, BIT(port
), ANA_PGID_PGID
, port
);
2487 /* Do not forward BPDU frames to the front ports. */
2488 ocelot_write_gix(ocelot
,
2489 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
2490 ANA_PORT_CPU_FWD_BPDU_CFG
,
2492 /* Ensure bridging is disabled */
2493 ocelot_write_rix(ocelot
, 0, ANA_PGID_PGID
, PGID_SRC
+ port
);
2496 /* Allow broadcast MAC frames. */
2497 for (i
= ocelot
->num_phys_ports
+ 1; i
< PGID_CPU
; i
++) {
2498 u32 val
= ANA_PGID_PGID_PGID(GENMASK(ocelot
->num_phys_ports
- 1, 0));
2500 ocelot_write_rix(ocelot
, val
, ANA_PGID_PGID
, i
);
2502 ocelot_write_rix(ocelot
,
2503 ANA_PGID_PGID_PGID(GENMASK(ocelot
->num_phys_ports
, 0)),
2504 ANA_PGID_PGID
, PGID_MC
);
2505 ocelot_write_rix(ocelot
, 0, ANA_PGID_PGID
, PGID_MCIPV4
);
2506 ocelot_write_rix(ocelot
, 0, ANA_PGID_PGID
, PGID_MCIPV6
);
2508 /* Allow manual injection via DEVCPU_QS registers, and byte swap these
2509 * registers endianness.
2511 ocelot_write_rix(ocelot
, QS_INJ_GRP_CFG_BYTE_SWAP
|
2512 QS_INJ_GRP_CFG_MODE(1), QS_INJ_GRP_CFG
, 0);
2513 ocelot_write_rix(ocelot
, QS_XTR_GRP_CFG_BYTE_SWAP
|
2514 QS_XTR_GRP_CFG_MODE(1), QS_XTR_GRP_CFG
, 0);
2515 ocelot_write(ocelot
, ANA_CPUQ_CFG_CPUQ_MIRROR(2) |
2516 ANA_CPUQ_CFG_CPUQ_LRN(2) |
2517 ANA_CPUQ_CFG_CPUQ_MAC_COPY(2) |
2518 ANA_CPUQ_CFG_CPUQ_SRC_COPY(2) |
2519 ANA_CPUQ_CFG_CPUQ_LOCKED_PORTMOVE(2) |
2520 ANA_CPUQ_CFG_CPUQ_ALLBRIDGE(6) |
2521 ANA_CPUQ_CFG_CPUQ_IPMC_CTRL(6) |
2522 ANA_CPUQ_CFG_CPUQ_IGMP(6) |
2523 ANA_CPUQ_CFG_CPUQ_MLD(6), ANA_CPUQ_CFG
);
2524 for (i
= 0; i
< 16; i
++)
2525 ocelot_write_rix(ocelot
, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) |
2526 ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
2527 ANA_CPUQ_8021_CFG
, i
);
2529 INIT_DELAYED_WORK(&ocelot
->stats_work
, ocelot_check_stats_work
);
2530 queue_delayed_work(ocelot
->stats_queue
, &ocelot
->stats_work
,
2531 OCELOT_STATS_CHECK_DELAY
);
2534 ret
= ocelot_init_timestamp(ocelot
);
2536 dev_err(ocelot
->dev
,
2537 "Timestamp initialization failed\n");
2544 EXPORT_SYMBOL(ocelot_init
);
2546 void ocelot_deinit(struct ocelot
*ocelot
)
2548 struct ocelot_port
*port
;
2551 cancel_delayed_work(&ocelot
->stats_work
);
2552 destroy_workqueue(ocelot
->stats_queue
);
2553 mutex_destroy(&ocelot
->stats_lock
);
2554 if (ocelot
->ptp_clock
)
2555 ptp_clock_unregister(ocelot
->ptp_clock
);
2557 for (i
= 0; i
< ocelot
->num_phys_ports
; i
++) {
2558 port
= ocelot
->ports
[i
];
2559 skb_queue_purge(&port
->tx_skbs
);
2562 EXPORT_SYMBOL(ocelot_deinit
);
2564 MODULE_LICENSE("Dual MIT/GPL");