1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Microsemi Ocelot Switch driver
5 * Copyright (c) 2017 Microsemi Corporation
7 #include <linux/dsa/ocelot.h>
8 #include <linux/if_bridge.h>
9 #include <soc/mscc/ocelot_vcap.h>
11 #include "ocelot_vcap.h"
13 #define TABLE_UPDATE_SLEEP_US 10
14 #define TABLE_UPDATE_TIMEOUT_US 100000
15 #define OCELOT_RSV_VLAN_RANGE_START 4000
17 struct ocelot_mact_entry {
20 enum macaccess_entry_type type;
23 /* Caller must hold &ocelot->mact_lock */
24 static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot)
26 return ocelot_read(ocelot, ANA_TABLES_MACACCESS);
29 /* Caller must hold &ocelot->mact_lock */
30 static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot)
34 return readx_poll_timeout(ocelot_mact_read_macaccess,
36 (val & ANA_TABLES_MACACCESS_MAC_TABLE_CMD_M) ==
38 TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
41 /* Caller must hold &ocelot->mact_lock */
42 static void ocelot_mact_select(struct ocelot *ocelot,
43 const unsigned char mac[ETH_ALEN],
46 u32 macl = 0, mach = 0;
48 /* Set the MAC address to handle and the vlan associated in a format
49 * understood by the hardware.
59 ocelot_write(ocelot, macl, ANA_TABLES_MACLDATA);
60 ocelot_write(ocelot, mach, ANA_TABLES_MACHDATA);
64 static int __ocelot_mact_learn(struct ocelot *ocelot, int port,
65 const unsigned char mac[ETH_ALEN],
66 unsigned int vid, enum macaccess_entry_type type)
68 u32 cmd = ANA_TABLES_MACACCESS_VALID |
69 ANA_TABLES_MACACCESS_DEST_IDX(port) |
70 ANA_TABLES_MACACCESS_ENTRYTYPE(type) |
71 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_LEARN);
72 unsigned int mc_ports;
75 /* Set MAC_CPU_COPY if the CPU port is used by a multicast entry */
76 if (type == ENTRYTYPE_MACv4)
77 mc_ports = (mac[1] << 8) | mac[2];
78 else if (type == ENTRYTYPE_MACv6)
79 mc_ports = (mac[0] << 8) | mac[1];
83 if (mc_ports & BIT(ocelot->num_phys_ports))
84 cmd |= ANA_TABLES_MACACCESS_MAC_CPU_COPY;
86 ocelot_mact_select(ocelot, mac, vid);
88 /* Issue a write command */
89 ocelot_write(ocelot, cmd, ANA_TABLES_MACACCESS);
91 err = ocelot_mact_wait_for_completion(ocelot);
96 int ocelot_mact_learn(struct ocelot *ocelot, int port,
97 const unsigned char mac[ETH_ALEN],
98 unsigned int vid, enum macaccess_entry_type type)
102 mutex_lock(&ocelot->mact_lock);
103 ret = __ocelot_mact_learn(ocelot, port, mac, vid, type);
104 mutex_unlock(&ocelot->mact_lock);
108 EXPORT_SYMBOL(ocelot_mact_learn);
110 int ocelot_mact_forget(struct ocelot *ocelot,
111 const unsigned char mac[ETH_ALEN], unsigned int vid)
115 mutex_lock(&ocelot->mact_lock);
117 ocelot_mact_select(ocelot, mac, vid);
119 /* Issue a forget command */
121 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_FORGET),
122 ANA_TABLES_MACACCESS);
124 err = ocelot_mact_wait_for_completion(ocelot);
126 mutex_unlock(&ocelot->mact_lock);
130 EXPORT_SYMBOL(ocelot_mact_forget);
132 int ocelot_mact_lookup(struct ocelot *ocelot, int *dst_idx,
133 const unsigned char mac[ETH_ALEN],
134 unsigned int vid, enum macaccess_entry_type *type)
138 mutex_lock(&ocelot->mact_lock);
140 ocelot_mact_select(ocelot, mac, vid);
142 /* Issue a read command with MACACCESS_VALID=1. */
143 ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID |
144 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ),
145 ANA_TABLES_MACACCESS);
147 if (ocelot_mact_wait_for_completion(ocelot)) {
148 mutex_unlock(&ocelot->mact_lock);
152 /* Read back the entry flags */
153 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
155 mutex_unlock(&ocelot->mact_lock);
157 if (!(val & ANA_TABLES_MACACCESS_VALID))
160 *dst_idx = ANA_TABLES_MACACCESS_DEST_IDX_X(val);
161 *type = ANA_TABLES_MACACCESS_ENTRYTYPE_X(val);
165 EXPORT_SYMBOL(ocelot_mact_lookup);
167 int ocelot_mact_learn_streamdata(struct ocelot *ocelot, int dst_idx,
168 const unsigned char mac[ETH_ALEN],
170 enum macaccess_entry_type type,
175 mutex_lock(&ocelot->mact_lock);
178 (sfid < 0 ? 0 : ANA_TABLES_STREAMDATA_SFID_VALID) |
179 ANA_TABLES_STREAMDATA_SFID(sfid) |
180 (ssid < 0 ? 0 : ANA_TABLES_STREAMDATA_SSID_VALID) |
181 ANA_TABLES_STREAMDATA_SSID(ssid),
182 ANA_TABLES_STREAMDATA);
184 ret = __ocelot_mact_learn(ocelot, dst_idx, mac, vid, type);
186 mutex_unlock(&ocelot->mact_lock);
190 EXPORT_SYMBOL(ocelot_mact_learn_streamdata);
192 static void ocelot_mact_init(struct ocelot *ocelot)
194 /* Configure the learning mode entries attributes:
195 * - Do not copy the frame to the CPU extraction queues.
196 * - Use the vlan and mac_cpoy for dmac lookup.
198 ocelot_rmw(ocelot, 0,
199 ANA_AGENCTRL_LEARN_CPU_COPY | ANA_AGENCTRL_IGNORE_DMAC_FLAGS
200 | ANA_AGENCTRL_LEARN_FWD_KILL
201 | ANA_AGENCTRL_LEARN_IGNORE_VLAN,
204 /* Clear the MAC table. We are not concurrent with anyone, so
205 * holding &ocelot->mact_lock is pointless.
207 ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
210 static void ocelot_vcap_enable(struct ocelot *ocelot, int port)
212 ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA |
213 ANA_PORT_VCAP_S2_CFG_S2_IP6_CFG(0xa),
214 ANA_PORT_VCAP_S2_CFG, port);
216 ocelot_write_gix(ocelot, ANA_PORT_VCAP_CFG_S1_ENA,
217 ANA_PORT_VCAP_CFG, port);
219 ocelot_rmw_gix(ocelot, REW_PORT_CFG_ES0_EN,
224 static int ocelot_single_vlan_aware_bridge(struct ocelot *ocelot,
225 struct netlink_ext_ack *extack)
227 struct net_device *bridge = NULL;
230 for (port = 0; port < ocelot->num_phys_ports; port++) {
231 struct ocelot_port *ocelot_port = ocelot->ports[port];
233 if (!ocelot_port || !ocelot_port->bridge ||
234 !br_vlan_enabled(ocelot_port->bridge))
238 bridge = ocelot_port->bridge;
242 if (bridge == ocelot_port->bridge)
245 NL_SET_ERR_MSG_MOD(extack,
246 "Only one VLAN-aware bridge is supported");
253 static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot)
255 return ocelot_read(ocelot, ANA_TABLES_VLANACCESS);
258 static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot)
262 return readx_poll_timeout(ocelot_vlant_read_vlanaccess,
265 (val & ANA_TABLES_VLANACCESS_VLAN_TBL_CMD_M) ==
266 ANA_TABLES_VLANACCESS_CMD_IDLE,
267 TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
270 static int ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask)
272 /* Select the VID to configure */
273 ocelot_write(ocelot, ANA_TABLES_VLANTIDX_V_INDEX(vid),
274 ANA_TABLES_VLANTIDX);
275 /* Set the vlan port members mask and issue a write command */
276 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_VLAN_PORT_MASK(mask) |
277 ANA_TABLES_VLANACCESS_CMD_WRITE,
278 ANA_TABLES_VLANACCESS);
280 return ocelot_vlant_wait_for_completion(ocelot);
283 static int ocelot_port_num_untagged_vlans(struct ocelot *ocelot, int port)
285 struct ocelot_bridge_vlan *vlan;
286 int num_untagged = 0;
288 list_for_each_entry(vlan, &ocelot->vlans, list) {
289 if (!(vlan->portmask & BIT(port)))
292 /* Ignore the VLAN added by ocelot_add_vlan_unaware_pvid(),
293 * because this is never active in hardware at the same time as
294 * the bridge VLANs, which only matter in VLAN-aware mode.
296 if (vlan->vid >= OCELOT_RSV_VLAN_RANGE_START)
299 if (vlan->untagged & BIT(port))
306 static int ocelot_port_num_tagged_vlans(struct ocelot *ocelot, int port)
308 struct ocelot_bridge_vlan *vlan;
311 list_for_each_entry(vlan, &ocelot->vlans, list) {
312 if (!(vlan->portmask & BIT(port)))
315 if (!(vlan->untagged & BIT(port)))
322 /* We use native VLAN when we have to mix egress-tagged VLANs with exactly
323 * _one_ egress-untagged VLAN (_the_ native VLAN)
325 static bool ocelot_port_uses_native_vlan(struct ocelot *ocelot, int port)
327 return ocelot_port_num_tagged_vlans(ocelot, port) &&
328 ocelot_port_num_untagged_vlans(ocelot, port) == 1;
331 static struct ocelot_bridge_vlan *
332 ocelot_port_find_native_vlan(struct ocelot *ocelot, int port)
334 struct ocelot_bridge_vlan *vlan;
336 list_for_each_entry(vlan, &ocelot->vlans, list)
337 if (vlan->portmask & BIT(port) && vlan->untagged & BIT(port))
343 /* Keep in sync REW_TAG_CFG_TAG_CFG and, if applicable,
344 * REW_PORT_VLAN_CFG_PORT_VID, with the bridge VLAN table and VLAN awareness
347 static void ocelot_port_manage_port_tag(struct ocelot *ocelot, int port)
349 struct ocelot_port *ocelot_port = ocelot->ports[port];
350 enum ocelot_port_tag_config tag_cfg;
351 bool uses_native_vlan = false;
353 if (ocelot_port->vlan_aware) {
354 uses_native_vlan = ocelot_port_uses_native_vlan(ocelot, port);
356 if (uses_native_vlan)
357 tag_cfg = OCELOT_PORT_TAG_NATIVE;
358 else if (ocelot_port_num_untagged_vlans(ocelot, port))
359 tag_cfg = OCELOT_PORT_TAG_DISABLED;
361 tag_cfg = OCELOT_PORT_TAG_TRUNK;
363 tag_cfg = OCELOT_PORT_TAG_DISABLED;
366 ocelot_rmw_gix(ocelot, REW_TAG_CFG_TAG_CFG(tag_cfg),
367 REW_TAG_CFG_TAG_CFG_M,
370 if (uses_native_vlan) {
371 struct ocelot_bridge_vlan *native_vlan;
373 /* Not having a native VLAN is impossible, because
374 * ocelot_port_num_untagged_vlans has returned 1.
375 * So there is no use in checking for NULL here.
377 native_vlan = ocelot_port_find_native_vlan(ocelot, port);
379 ocelot_rmw_gix(ocelot,
380 REW_PORT_VLAN_CFG_PORT_VID(native_vlan->vid),
381 REW_PORT_VLAN_CFG_PORT_VID_M,
382 REW_PORT_VLAN_CFG, port);
386 int ocelot_bridge_num_find(struct ocelot *ocelot,
387 const struct net_device *bridge)
391 for (port = 0; port < ocelot->num_phys_ports; port++) {
392 struct ocelot_port *ocelot_port = ocelot->ports[port];
394 if (ocelot_port && ocelot_port->bridge == bridge)
395 return ocelot_port->bridge_num;
400 EXPORT_SYMBOL_GPL(ocelot_bridge_num_find);
402 static u16 ocelot_vlan_unaware_pvid(struct ocelot *ocelot,
403 const struct net_device *bridge)
407 /* Standalone ports use VID 0 */
411 bridge_num = ocelot_bridge_num_find(ocelot, bridge);
412 if (WARN_ON(bridge_num < 0))
415 /* VLAN-unaware bridges use a reserved VID going from 4095 downwards */
416 return VLAN_N_VID - bridge_num - 1;
419 /* Default vlan to clasify for untagged frames (may be zero) */
420 static void ocelot_port_set_pvid(struct ocelot *ocelot, int port,
421 const struct ocelot_bridge_vlan *pvid_vlan)
423 struct ocelot_port *ocelot_port = ocelot->ports[port];
424 u16 pvid = ocelot_vlan_unaware_pvid(ocelot, ocelot_port->bridge);
427 ocelot_port->pvid_vlan = pvid_vlan;
429 if (ocelot_port->vlan_aware && pvid_vlan)
430 pvid = pvid_vlan->vid;
432 ocelot_rmw_gix(ocelot,
433 ANA_PORT_VLAN_CFG_VLAN_VID(pvid),
434 ANA_PORT_VLAN_CFG_VLAN_VID_M,
435 ANA_PORT_VLAN_CFG, port);
437 /* If there's no pvid, we should drop not only untagged traffic (which
438 * happens automatically), but also 802.1p traffic which gets
439 * classified to VLAN 0, but that is always in our RX filter, so it
440 * would get accepted were it not for this setting.
442 if (!pvid_vlan && ocelot_port->vlan_aware)
443 val = ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
444 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
446 ocelot_rmw_gix(ocelot, val,
447 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
448 ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA,
449 ANA_PORT_DROP_CFG, port);
452 static struct ocelot_bridge_vlan *ocelot_bridge_vlan_find(struct ocelot *ocelot,
455 struct ocelot_bridge_vlan *vlan;
457 list_for_each_entry(vlan, &ocelot->vlans, list)
458 if (vlan->vid == vid)
464 static int ocelot_vlan_member_add(struct ocelot *ocelot, int port, u16 vid,
467 struct ocelot_bridge_vlan *vlan = ocelot_bridge_vlan_find(ocelot, vid);
468 unsigned long portmask;
472 portmask = vlan->portmask | BIT(port);
474 err = ocelot_vlant_set_mask(ocelot, vid, portmask);
478 vlan->portmask = portmask;
479 /* Bridge VLANs can be overwritten with a different
480 * egress-tagging setting, so make sure to override an untagged
481 * with a tagged VID if that's going on.
484 vlan->untagged |= BIT(port);
486 vlan->untagged &= ~BIT(port);
491 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
495 portmask = BIT(port);
497 err = ocelot_vlant_set_mask(ocelot, vid, portmask);
504 vlan->portmask = portmask;
506 vlan->untagged = BIT(port);
507 INIT_LIST_HEAD(&vlan->list);
508 list_add_tail(&vlan->list, &ocelot->vlans);
513 static int ocelot_vlan_member_del(struct ocelot *ocelot, int port, u16 vid)
515 struct ocelot_bridge_vlan *vlan = ocelot_bridge_vlan_find(ocelot, vid);
516 unsigned long portmask;
522 portmask = vlan->portmask & ~BIT(port);
524 err = ocelot_vlant_set_mask(ocelot, vid, portmask);
528 vlan->portmask = portmask;
532 list_del(&vlan->list);
538 static int ocelot_add_vlan_unaware_pvid(struct ocelot *ocelot, int port,
539 const struct net_device *bridge)
541 u16 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
543 return ocelot_vlan_member_add(ocelot, port, vid, true);
546 static int ocelot_del_vlan_unaware_pvid(struct ocelot *ocelot, int port,
547 const struct net_device *bridge)
549 u16 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
551 return ocelot_vlan_member_del(ocelot, port, vid);
554 int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
555 bool vlan_aware, struct netlink_ext_ack *extack)
557 struct ocelot_vcap_block *block = &ocelot->block[VCAP_IS1];
558 struct ocelot_port *ocelot_port = ocelot->ports[port];
559 struct ocelot_vcap_filter *filter;
563 list_for_each_entry(filter, &block->rules, list) {
564 if (filter->ingress_port_mask & BIT(port) &&
565 filter->action.vid_replace_ena) {
566 NL_SET_ERR_MSG_MOD(extack,
567 "Cannot change VLAN state with vlan modify rules active");
572 err = ocelot_single_vlan_aware_bridge(ocelot, extack);
577 err = ocelot_del_vlan_unaware_pvid(ocelot, port,
578 ocelot_port->bridge);
579 else if (ocelot_port->bridge)
580 err = ocelot_add_vlan_unaware_pvid(ocelot, port,
581 ocelot_port->bridge);
585 ocelot_port->vlan_aware = vlan_aware;
588 val = ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
589 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
592 ocelot_rmw_gix(ocelot, val,
593 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
594 ANA_PORT_VLAN_CFG_VLAN_POP_CNT_M,
595 ANA_PORT_VLAN_CFG, port);
597 ocelot_port_set_pvid(ocelot, port, ocelot_port->pvid_vlan);
598 ocelot_port_manage_port_tag(ocelot, port);
602 EXPORT_SYMBOL(ocelot_port_vlan_filtering);
604 int ocelot_vlan_prepare(struct ocelot *ocelot, int port, u16 vid, bool pvid,
605 bool untagged, struct netlink_ext_ack *extack)
608 /* We are adding an egress-tagged VLAN */
609 if (ocelot_port_uses_native_vlan(ocelot, port)) {
610 NL_SET_ERR_MSG_MOD(extack,
611 "Port with egress-tagged VLANs cannot have more than one egress-untagged (native) VLAN");
615 /* We are adding an egress-tagged VLAN */
616 if (ocelot_port_num_untagged_vlans(ocelot, port) > 1) {
617 NL_SET_ERR_MSG_MOD(extack,
618 "Port with more than one egress-untagged VLAN cannot have egress-tagged VLANs");
623 if (vid > OCELOT_RSV_VLAN_RANGE_START) {
624 NL_SET_ERR_MSG_MOD(extack,
625 "VLAN range 4000-4095 reserved for VLAN-unaware bridging");
631 EXPORT_SYMBOL(ocelot_vlan_prepare);
633 int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
638 /* Ignore VID 0 added to our RX filter by the 8021q module, since
639 * that collides with OCELOT_STANDALONE_PVID and changes it from
640 * egress-untagged to egress-tagged.
645 err = ocelot_vlan_member_add(ocelot, port, vid, untagged);
649 /* Default ingress vlan classification */
651 ocelot_port_set_pvid(ocelot, port,
652 ocelot_bridge_vlan_find(ocelot, vid));
654 /* Untagged egress vlan clasification */
655 ocelot_port_manage_port_tag(ocelot, port);
659 EXPORT_SYMBOL(ocelot_vlan_add);
661 int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
663 struct ocelot_port *ocelot_port = ocelot->ports[port];
664 bool del_pvid = false;
670 if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
673 err = ocelot_vlan_member_del(ocelot, port, vid);
679 ocelot_port_set_pvid(ocelot, port, NULL);
682 ocelot_port_manage_port_tag(ocelot, port);
686 EXPORT_SYMBOL(ocelot_vlan_del);
688 static void ocelot_vlan_init(struct ocelot *ocelot)
690 unsigned long all_ports = GENMASK(ocelot->num_phys_ports - 1, 0);
693 /* Clear VLAN table, by default all ports are members of all VLANs */
694 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_CMD_INIT,
695 ANA_TABLES_VLANACCESS);
696 ocelot_vlant_wait_for_completion(ocelot);
698 /* Configure the port VLAN memberships */
699 for (vid = 1; vid < VLAN_N_VID; vid++)
700 ocelot_vlant_set_mask(ocelot, vid, 0);
702 /* We need VID 0 to get traffic on standalone ports.
703 * It is added automatically if the 8021q module is loaded, but we
704 * can't rely on that since it might not be.
706 ocelot_vlant_set_mask(ocelot, OCELOT_STANDALONE_PVID, all_ports);
708 /* Set vlan ingress filter mask to all ports but the CPU port by
711 ocelot_write(ocelot, all_ports, ANA_VLANMASK);
713 for (port = 0; port < ocelot->num_phys_ports; port++) {
714 ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port);
715 ocelot_write_gix(ocelot, 0, REW_TAG_CFG, port);
719 static u32 ocelot_read_eq_avail(struct ocelot *ocelot, int port)
721 return ocelot_read_rix(ocelot, QSYS_SW_STATUS, port);
724 static int ocelot_port_flush(struct ocelot *ocelot, int port)
726 unsigned int pause_ena;
729 /* Disable dequeuing from the egress queues */
730 ocelot_rmw_rix(ocelot, QSYS_PORT_MODE_DEQUEUE_DIS,
731 QSYS_PORT_MODE_DEQUEUE_DIS,
732 QSYS_PORT_MODE, port);
734 /* Disable flow control */
735 ocelot_fields_read(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, &pause_ena);
736 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0);
738 /* Disable priority flow control */
739 ocelot_fields_write(ocelot, port,
740 QSYS_SWITCH_PORT_MODE_TX_PFC_ENA, 0);
742 /* Wait at least the time it takes to receive a frame of maximum length
744 * Worst-case delays for 10 kilobyte jumbo frames are:
746 * 800 μs on a 100M port
747 * 80 μs on a 1G port
748 * 32 μs on a 2.5G port
750 usleep_range(8000, 10000);
752 /* Disable half duplex backpressure. */
753 ocelot_rmw_rix(ocelot, 0, SYS_FRONT_PORT_MODE_HDX_MODE,
754 SYS_FRONT_PORT_MODE, port);
756 /* Flush the queues associated with the port. */
757 ocelot_rmw_gix(ocelot, REW_PORT_CFG_FLUSH_ENA, REW_PORT_CFG_FLUSH_ENA,
760 /* Enable dequeuing from the egress queues. */
761 ocelot_rmw_rix(ocelot, 0, QSYS_PORT_MODE_DEQUEUE_DIS, QSYS_PORT_MODE,
764 /* Wait until flushing is complete. */
765 err = read_poll_timeout(ocelot_read_eq_avail, val, !val,
766 100, 2000000, false, ocelot, port);
768 /* Clear flushing again. */
769 ocelot_rmw_gix(ocelot, 0, REW_PORT_CFG_FLUSH_ENA, REW_PORT_CFG, port);
771 /* Re-enable flow control */
772 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, pause_ena);
777 void ocelot_phylink_mac_link_down(struct ocelot *ocelot, int port,
778 unsigned int link_an_mode,
779 phy_interface_t interface,
780 unsigned long quirks)
782 struct ocelot_port *ocelot_port = ocelot->ports[port];
785 ocelot_port->speed = SPEED_UNKNOWN;
787 ocelot_port_rmwl(ocelot_port, 0, DEV_MAC_ENA_CFG_RX_ENA,
790 if (ocelot->ops->cut_through_fwd) {
791 mutex_lock(&ocelot->fwd_domain_lock);
792 ocelot->ops->cut_through_fwd(ocelot);
793 mutex_unlock(&ocelot->fwd_domain_lock);
796 ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0);
798 err = ocelot_port_flush(ocelot, port);
800 dev_err(ocelot->dev, "failed to flush port %d: %d\n",
803 /* Put the port in reset. */
804 if (interface != PHY_INTERFACE_MODE_QSGMII ||
805 !(quirks & OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP))
806 ocelot_port_rmwl(ocelot_port,
807 DEV_CLOCK_CFG_MAC_TX_RST |
808 DEV_CLOCK_CFG_MAC_RX_RST,
809 DEV_CLOCK_CFG_MAC_TX_RST |
810 DEV_CLOCK_CFG_MAC_RX_RST,
813 EXPORT_SYMBOL_GPL(ocelot_phylink_mac_link_down);
815 void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port,
816 struct phy_device *phydev,
817 unsigned int link_an_mode,
818 phy_interface_t interface,
819 int speed, int duplex,
820 bool tx_pause, bool rx_pause,
821 unsigned long quirks)
823 struct ocelot_port *ocelot_port = ocelot->ports[port];
824 int mac_speed, mode = 0;
827 ocelot_port->speed = speed;
829 /* The MAC might be integrated in systems where the MAC speed is fixed
830 * and it's the PCS who is performing the rate adaptation, so we have
831 * to write "1000Mbps" into the LINK_SPEED field of DEV_CLOCK_CFG
832 * (which is also its default value).
834 if ((quirks & OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION) ||
835 speed == SPEED_1000) {
836 mac_speed = OCELOT_SPEED_1000;
837 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
838 } else if (speed == SPEED_2500) {
839 mac_speed = OCELOT_SPEED_2500;
840 mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
841 } else if (speed == SPEED_100) {
842 mac_speed = OCELOT_SPEED_100;
844 mac_speed = OCELOT_SPEED_10;
847 if (duplex == DUPLEX_FULL)
848 mode |= DEV_MAC_MODE_CFG_FDX_ENA;
850 ocelot_port_writel(ocelot_port, mode, DEV_MAC_MODE_CFG);
852 /* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and
853 * PORT_RST bits in DEV_CLOCK_CFG.
855 ocelot_port_writel(ocelot_port, DEV_CLOCK_CFG_LINK_SPEED(mac_speed),
860 mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_10);
863 mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_100);
867 mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_1000);
870 dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n",
875 /* Handle RX pause in all cases, with 2500base-X this is used for rate
878 mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA;
881 mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA |
882 SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
883 SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
884 SYS_MAC_FC_CFG_ZERO_PAUSE_ENA;
886 /* Flow control. Link speed is only used here to evaluate the time
887 * specification in incoming pause frames.
889 ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port);
891 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
893 /* Don't attempt to send PAUSE frames on the NPI port, it's broken */
894 if (port != ocelot->npi)
895 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA,
898 /* Undo the effects of ocelot_phylink_mac_link_down:
901 ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
902 DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
904 /* If the port supports cut-through forwarding, update the masks before
905 * enabling forwarding on the port.
907 if (ocelot->ops->cut_through_fwd) {
908 mutex_lock(&ocelot->fwd_domain_lock);
909 ocelot->ops->cut_through_fwd(ocelot);
910 mutex_unlock(&ocelot->fwd_domain_lock);
913 /* Core: Enable port for frame transfer */
914 ocelot_fields_write(ocelot, port,
915 QSYS_SWITCH_PORT_MODE_PORT_ENA, 1);
917 EXPORT_SYMBOL_GPL(ocelot_phylink_mac_link_up);
919 static int ocelot_rx_frame_word(struct ocelot *ocelot, u8 grp, bool ifh,
922 u32 bytes_valid, val;
924 val = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
925 if (val == XTR_NOT_READY) {
930 val = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
931 } while (val == XTR_NOT_READY);
942 bytes_valid = XTR_VALID_BYTES(val);
943 val = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
944 if (val == XTR_ESCAPE)
945 *rval = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
951 *rval = ocelot_read_rix(ocelot, QS_XTR_RD, grp);
961 static int ocelot_xtr_poll_xfh(struct ocelot *ocelot, int grp, u32 *xfh)
965 for (i = 0; i < OCELOT_TAG_LEN / 4; i++) {
966 err = ocelot_rx_frame_word(ocelot, grp, true, &xfh[i]);
968 return (err < 0) ? err : -EIO;
974 void ocelot_ptp_rx_timestamp(struct ocelot *ocelot, struct sk_buff *skb,
977 struct skb_shared_hwtstamps *shhwtstamps;
978 u64 tod_in_ns, full_ts_in_ns;
979 struct timespec64 ts;
981 ocelot_ptp_gettime64(&ocelot->ptp_info, &ts);
983 tod_in_ns = ktime_set(ts.tv_sec, ts.tv_nsec);
984 if ((tod_in_ns & 0xffffffff) < timestamp)
985 full_ts_in_ns = (((tod_in_ns >> 32) - 1) << 32) |
988 full_ts_in_ns = (tod_in_ns & GENMASK_ULL(63, 32)) |
991 shhwtstamps = skb_hwtstamps(skb);
992 memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
993 shhwtstamps->hwtstamp = full_ts_in_ns;
995 EXPORT_SYMBOL(ocelot_ptp_rx_timestamp);
997 int ocelot_xtr_poll_frame(struct ocelot *ocelot, int grp, struct sk_buff **nskb)
999 u64 timestamp, src_port, len;
1000 u32 xfh[OCELOT_TAG_LEN / 4];
1001 struct net_device *dev;
1002 struct sk_buff *skb;
1007 err = ocelot_xtr_poll_xfh(ocelot, grp, xfh);
1011 ocelot_xfh_get_src_port(xfh, &src_port);
1012 ocelot_xfh_get_len(xfh, &len);
1013 ocelot_xfh_get_rew_val(xfh, ×tamp);
1015 if (WARN_ON(src_port >= ocelot->num_phys_ports))
1018 dev = ocelot->ops->port_to_netdev(ocelot, src_port);
1022 skb = netdev_alloc_skb(dev, len);
1023 if (unlikely(!skb)) {
1024 netdev_err(dev, "Unable to allocate sk_buff\n");
1028 buf_len = len - ETH_FCS_LEN;
1029 buf = (u32 *)skb_put(skb, buf_len);
1033 sz = ocelot_rx_frame_word(ocelot, grp, false, &val);
1040 } while (len < buf_len);
1043 sz = ocelot_rx_frame_word(ocelot, grp, false, &val);
1049 /* Update the statistics if part of the FCS was read before */
1050 len -= ETH_FCS_LEN - sz;
1052 if (unlikely(dev->features & NETIF_F_RXFCS)) {
1053 buf = (u32 *)skb_put(skb, ETH_FCS_LEN);
1058 ocelot_ptp_rx_timestamp(ocelot, skb, timestamp);
1060 /* Everything we see on an interface that is in the HW bridge
1061 * has already been forwarded.
1063 if (ocelot->ports[src_port]->bridge)
1064 skb->offload_fwd_mark = 1;
1066 skb->protocol = eth_type_trans(skb, dev);
1076 EXPORT_SYMBOL(ocelot_xtr_poll_frame);
1078 bool ocelot_can_inject(struct ocelot *ocelot, int grp)
1080 u32 val = ocelot_read(ocelot, QS_INJ_STATUS);
1082 if (!(val & QS_INJ_STATUS_FIFO_RDY(BIT(grp))))
1084 if (val & QS_INJ_STATUS_WMARK_REACHED(BIT(grp)))
1089 EXPORT_SYMBOL(ocelot_can_inject);
1091 void ocelot_ifh_port_set(void *ifh, int port, u32 rew_op, u32 vlan_tag)
1093 ocelot_ifh_set_bypass(ifh, 1);
1094 ocelot_ifh_set_dest(ifh, BIT_ULL(port));
1095 ocelot_ifh_set_tag_type(ifh, IFH_TAG_TYPE_C);
1097 ocelot_ifh_set_vlan_tci(ifh, vlan_tag);
1099 ocelot_ifh_set_rew_op(ifh, rew_op);
1101 EXPORT_SYMBOL(ocelot_ifh_port_set);
1103 void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp,
1104 u32 rew_op, struct sk_buff *skb)
1106 u32 ifh[OCELOT_TAG_LEN / 4] = {0};
1107 unsigned int i, count, last;
1109 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) |
1110 QS_INJ_CTRL_SOF, QS_INJ_CTRL, grp);
1112 ocelot_ifh_port_set(ifh, port, rew_op, skb_vlan_tag_get(skb));
1114 for (i = 0; i < OCELOT_TAG_LEN / 4; i++)
1115 ocelot_write_rix(ocelot, ifh[i], QS_INJ_WR, grp);
1117 count = DIV_ROUND_UP(skb->len, 4);
1118 last = skb->len % 4;
1119 for (i = 0; i < count; i++)
1120 ocelot_write_rix(ocelot, ((u32 *)skb->data)[i], QS_INJ_WR, grp);
1123 while (i < (OCELOT_BUFFER_CELL_SZ / 4)) {
1124 ocelot_write_rix(ocelot, 0, QS_INJ_WR, grp);
1128 /* Indicate EOF and valid bytes in last word */
1129 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) |
1130 QS_INJ_CTRL_VLD_BYTES(skb->len < OCELOT_BUFFER_CELL_SZ ? 0 : last) |
1135 ocelot_write_rix(ocelot, 0, QS_INJ_WR, grp);
1136 skb_tx_timestamp(skb);
1138 skb->dev->stats.tx_packets++;
1139 skb->dev->stats.tx_bytes += skb->len;
1141 EXPORT_SYMBOL(ocelot_port_inject_frame);
1143 void ocelot_drain_cpu_queue(struct ocelot *ocelot, int grp)
1145 while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp))
1146 ocelot_read_rix(ocelot, QS_XTR_RD, grp);
1148 EXPORT_SYMBOL(ocelot_drain_cpu_queue);
1150 int ocelot_fdb_add(struct ocelot *ocelot, int port, const unsigned char *addr,
1151 u16 vid, const struct net_device *bridge)
1154 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
1156 return ocelot_mact_learn(ocelot, port, addr, vid, ENTRYTYPE_LOCKED);
1158 EXPORT_SYMBOL(ocelot_fdb_add);
1160 int ocelot_fdb_del(struct ocelot *ocelot, int port, const unsigned char *addr,
1161 u16 vid, const struct net_device *bridge)
1164 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
1166 return ocelot_mact_forget(ocelot, addr, vid);
1168 EXPORT_SYMBOL(ocelot_fdb_del);
1170 /* Caller must hold &ocelot->mact_lock */
1171 static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col,
1172 struct ocelot_mact_entry *entry)
1174 u32 val, dst, macl, mach;
1177 /* Set row and column to read from */
1178 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row);
1179 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col);
1181 /* Issue a read command */
1182 ocelot_write(ocelot,
1183 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ),
1184 ANA_TABLES_MACACCESS);
1186 if (ocelot_mact_wait_for_completion(ocelot))
1189 /* Read the entry flags */
1190 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
1191 if (!(val & ANA_TABLES_MACACCESS_VALID))
1194 /* If the entry read has another port configured as its destination,
1197 dst = (val & ANA_TABLES_MACACCESS_DEST_IDX_M) >> 3;
1201 /* Get the entry's MAC address and VLAN id */
1202 macl = ocelot_read(ocelot, ANA_TABLES_MACLDATA);
1203 mach = ocelot_read(ocelot, ANA_TABLES_MACHDATA);
1205 mac[0] = (mach >> 8) & 0xff;
1206 mac[1] = (mach >> 0) & 0xff;
1207 mac[2] = (macl >> 24) & 0xff;
1208 mac[3] = (macl >> 16) & 0xff;
1209 mac[4] = (macl >> 8) & 0xff;
1210 mac[5] = (macl >> 0) & 0xff;
1212 entry->vid = (mach >> 16) & 0xfff;
1213 ether_addr_copy(entry->mac, mac);
1218 int ocelot_mact_flush(struct ocelot *ocelot, int port)
1222 mutex_lock(&ocelot->mact_lock);
1224 /* Program ageing filter for a single port */
1225 ocelot_write(ocelot, ANA_ANAGEFIL_PID_EN | ANA_ANAGEFIL_PID_VAL(port),
1228 /* Flushing dynamic FDB entries requires two successive age scans */
1229 ocelot_write(ocelot,
1230 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_AGE),
1231 ANA_TABLES_MACACCESS);
1233 err = ocelot_mact_wait_for_completion(ocelot);
1235 mutex_unlock(&ocelot->mact_lock);
1240 ocelot_write(ocelot,
1241 ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_AGE),
1242 ANA_TABLES_MACACCESS);
1244 err = ocelot_mact_wait_for_completion(ocelot);
1246 /* Restore ageing filter */
1247 ocelot_write(ocelot, 0, ANA_ANAGEFIL);
1249 mutex_unlock(&ocelot->mact_lock);
1253 EXPORT_SYMBOL_GPL(ocelot_mact_flush);
1255 int ocelot_fdb_dump(struct ocelot *ocelot, int port,
1256 dsa_fdb_dump_cb_t *cb, void *data)
1261 /* We could take the lock just around ocelot_mact_read, but doing so
1262 * thousands of times in a row seems rather pointless and inefficient.
1264 mutex_lock(&ocelot->mact_lock);
1266 /* Loop through all the mac tables entries. */
1267 for (i = 0; i < ocelot->num_mact_rows; i++) {
1268 for (j = 0; j < 4; j++) {
1269 struct ocelot_mact_entry entry;
1272 err = ocelot_mact_read(ocelot, port, i, j, &entry);
1273 /* If the entry is invalid (wrong port, invalid...),
1281 is_static = (entry.type == ENTRYTYPE_LOCKED);
1283 /* Hide the reserved VLANs used for
1284 * VLAN-unaware bridging.
1286 if (entry.vid > OCELOT_RSV_VLAN_RANGE_START)
1289 err = cb(entry.mac, entry.vid, is_static, data);
1295 mutex_unlock(&ocelot->mact_lock);
1299 EXPORT_SYMBOL(ocelot_fdb_dump);
1301 int ocelot_trap_add(struct ocelot *ocelot, int port,
1302 unsigned long cookie, bool take_ts,
1303 void (*populate)(struct ocelot_vcap_filter *f))
1305 struct ocelot_vcap_block *block_vcap_is2;
1306 struct ocelot_vcap_filter *trap;
1310 block_vcap_is2 = &ocelot->block[VCAP_IS2];
1312 trap = ocelot_vcap_block_find_filter_by_id(block_vcap_is2, cookie,
1315 trap = kzalloc(sizeof(*trap), GFP_KERNEL);
1321 trap->id.cookie = cookie;
1322 trap->id.tc_offload = false;
1323 trap->block_id = VCAP_IS2;
1324 trap->type = OCELOT_VCAP_FILTER_OFFLOAD;
1326 trap->action.cpu_copy_ena = true;
1327 trap->action.mask_mode = OCELOT_MASK_MODE_PERMIT_DENY;
1328 trap->action.port_mask = 0;
1329 trap->take_ts = take_ts;
1330 trap->is_trap = true;
1334 trap->ingress_port_mask |= BIT(port);
1337 err = ocelot_vcap_filter_add(ocelot, trap, NULL);
1339 err = ocelot_vcap_filter_replace(ocelot, trap);
1341 trap->ingress_port_mask &= ~BIT(port);
1342 if (!trap->ingress_port_mask)
1350 int ocelot_trap_del(struct ocelot *ocelot, int port, unsigned long cookie)
1352 struct ocelot_vcap_block *block_vcap_is2;
1353 struct ocelot_vcap_filter *trap;
1355 block_vcap_is2 = &ocelot->block[VCAP_IS2];
1357 trap = ocelot_vcap_block_find_filter_by_id(block_vcap_is2, cookie,
1362 trap->ingress_port_mask &= ~BIT(port);
1363 if (!trap->ingress_port_mask)
1364 return ocelot_vcap_filter_del(ocelot, trap);
1366 return ocelot_vcap_filter_replace(ocelot, trap);
1369 static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond)
1374 lockdep_assert_held(&ocelot->fwd_domain_lock);
1376 for (port = 0; port < ocelot->num_phys_ports; port++) {
1377 struct ocelot_port *ocelot_port = ocelot->ports[port];
1382 if (ocelot_port->bond == bond)
1389 /* The logical port number of a LAG is equal to the lowest numbered physical
1390 * port ID present in that LAG. It may change if that port ever leaves the LAG.
1392 int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond)
1394 int bond_mask = ocelot_get_bond_mask(ocelot, bond);
1399 return __ffs(bond_mask);
1401 EXPORT_SYMBOL_GPL(ocelot_bond_get_id);
1403 /* Returns the mask of user ports assigned to this DSA tag_8021q CPU port.
1404 * Note that when CPU ports are in a LAG, the user ports are assigned to the
1405 * 'primary' CPU port, the one whose physical port number gives the logical
1406 * port number of the LAG.
1408 * We leave PGID_SRC poorly configured for the 'secondary' CPU port in the LAG
1409 * (to which no user port is assigned), but it appears that forwarding from
1410 * this secondary CPU port looks at the PGID_SRC associated with the logical
1411 * port ID that it's assigned to, which *is* configured properly.
1413 static u32 ocelot_dsa_8021q_cpu_assigned_ports(struct ocelot *ocelot,
1414 struct ocelot_port *cpu)
1419 for (port = 0; port < ocelot->num_phys_ports; port++) {
1420 struct ocelot_port *ocelot_port = ocelot->ports[port];
1425 if (ocelot_port->dsa_8021q_cpu == cpu)
1430 mask &= ~ocelot_get_bond_mask(ocelot, cpu->bond);
1435 /* Returns the DSA tag_8021q CPU port that the given port is assigned to,
1436 * or the bit mask of CPU ports if said CPU port is in a LAG.
1438 u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port)
1440 struct ocelot_port *ocelot_port = ocelot->ports[port];
1441 struct ocelot_port *cpu_port = ocelot_port->dsa_8021q_cpu;
1447 return ocelot_get_bond_mask(ocelot, cpu_port->bond);
1449 return BIT(cpu_port->index);
1451 EXPORT_SYMBOL_GPL(ocelot_port_assigned_dsa_8021q_cpu_mask);
1453 u32 ocelot_get_bridge_fwd_mask(struct ocelot *ocelot, int src_port)
1455 struct ocelot_port *ocelot_port = ocelot->ports[src_port];
1456 const struct net_device *bridge;
1460 if (!ocelot_port || ocelot_port->stp_state != BR_STATE_FORWARDING)
1463 bridge = ocelot_port->bridge;
1467 for (port = 0; port < ocelot->num_phys_ports; port++) {
1468 ocelot_port = ocelot->ports[port];
1473 if (ocelot_port->stp_state == BR_STATE_FORWARDING &&
1474 ocelot_port->bridge == bridge)
1480 EXPORT_SYMBOL_GPL(ocelot_get_bridge_fwd_mask);
1482 static void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot, bool joining)
1486 lockdep_assert_held(&ocelot->fwd_domain_lock);
1488 /* If cut-through forwarding is supported, update the masks before a
1489 * port joins the forwarding domain, to avoid potential underruns if it
1490 * has the highest speed from the new domain.
1492 if (joining && ocelot->ops->cut_through_fwd)
1493 ocelot->ops->cut_through_fwd(ocelot);
1495 /* Apply FWD mask. The loop is needed to add/remove the current port as
1496 * a source for the other ports.
1498 for (port = 0; port < ocelot->num_phys_ports; port++) {
1499 struct ocelot_port *ocelot_port = ocelot->ports[port];
1503 /* Unused ports can't send anywhere */
1505 } else if (ocelot_port->is_dsa_8021q_cpu) {
1506 /* The DSA tag_8021q CPU ports need to be able to
1507 * forward packets to all ports assigned to them.
1509 mask = ocelot_dsa_8021q_cpu_assigned_ports(ocelot,
1511 } else if (ocelot_port->bridge) {
1512 struct net_device *bond = ocelot_port->bond;
1514 mask = ocelot_get_bridge_fwd_mask(ocelot, port);
1517 mask |= ocelot_port_assigned_dsa_8021q_cpu_mask(ocelot,
1521 mask &= ~ocelot_get_bond_mask(ocelot, bond);
1523 /* Standalone ports forward only to DSA tag_8021q CPU
1524 * ports (if those exist), or to the hardware CPU port
1527 mask = ocelot_port_assigned_dsa_8021q_cpu_mask(ocelot,
1531 ocelot_write_rix(ocelot, mask, ANA_PGID_PGID, PGID_SRC + port);
1534 /* If cut-through forwarding is supported and a port is leaving, there
1535 * is a chance that cut-through was disabled on the other ports due to
1536 * the port which is leaving (it has a higher link speed). We need to
1537 * update the cut-through masks of the remaining ports no earlier than
1538 * after the port has left, to prevent underruns from happening between
1539 * the cut-through update and the forwarding domain update.
1541 if (!joining && ocelot->ops->cut_through_fwd)
1542 ocelot->ops->cut_through_fwd(ocelot);
1545 /* Update PGID_CPU which is the destination port mask used for whitelisting
1546 * unicast addresses filtered towards the host. In the normal and NPI modes,
1547 * this points to the analyzer entry for the CPU port module, while in DSA
1548 * tag_8021q mode, it is a bit mask of all active CPU ports.
1549 * PGID_SRC will take care of forwarding a packet from one user port to
1550 * no more than a single CPU port.
1552 static void ocelot_update_pgid_cpu(struct ocelot *ocelot)
1557 for (port = 0; port < ocelot->num_phys_ports; port++) {
1558 struct ocelot_port *ocelot_port = ocelot->ports[port];
1560 if (!ocelot_port || !ocelot_port->is_dsa_8021q_cpu)
1563 pgid_cpu |= BIT(port);
1567 pgid_cpu = BIT(ocelot->num_phys_ports);
1569 ocelot_write_rix(ocelot, pgid_cpu, ANA_PGID_PGID, PGID_CPU);
1572 void ocelot_port_setup_dsa_8021q_cpu(struct ocelot *ocelot, int cpu)
1574 struct ocelot_port *cpu_port = ocelot->ports[cpu];
1577 mutex_lock(&ocelot->fwd_domain_lock);
1579 cpu_port->is_dsa_8021q_cpu = true;
1581 for (vid = OCELOT_RSV_VLAN_RANGE_START; vid < VLAN_N_VID; vid++)
1582 ocelot_vlan_member_add(ocelot, cpu, vid, true);
1584 ocelot_update_pgid_cpu(ocelot);
1586 mutex_unlock(&ocelot->fwd_domain_lock);
1588 EXPORT_SYMBOL_GPL(ocelot_port_setup_dsa_8021q_cpu);
1590 void ocelot_port_teardown_dsa_8021q_cpu(struct ocelot *ocelot, int cpu)
1592 struct ocelot_port *cpu_port = ocelot->ports[cpu];
1595 mutex_lock(&ocelot->fwd_domain_lock);
1597 cpu_port->is_dsa_8021q_cpu = false;
1599 for (vid = OCELOT_RSV_VLAN_RANGE_START; vid < VLAN_N_VID; vid++)
1600 ocelot_vlan_member_del(ocelot, cpu_port->index, vid);
1602 ocelot_update_pgid_cpu(ocelot);
1604 mutex_unlock(&ocelot->fwd_domain_lock);
1606 EXPORT_SYMBOL_GPL(ocelot_port_teardown_dsa_8021q_cpu);
1608 void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port,
1611 struct ocelot_port *cpu_port = ocelot->ports[cpu];
1613 mutex_lock(&ocelot->fwd_domain_lock);
1615 ocelot->ports[port]->dsa_8021q_cpu = cpu_port;
1616 ocelot_apply_bridge_fwd_mask(ocelot, true);
1618 mutex_unlock(&ocelot->fwd_domain_lock);
1620 EXPORT_SYMBOL_GPL(ocelot_port_assign_dsa_8021q_cpu);
1622 void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port)
1624 mutex_lock(&ocelot->fwd_domain_lock);
1626 ocelot->ports[port]->dsa_8021q_cpu = NULL;
1627 ocelot_apply_bridge_fwd_mask(ocelot, true);
1629 mutex_unlock(&ocelot->fwd_domain_lock);
1631 EXPORT_SYMBOL_GPL(ocelot_port_unassign_dsa_8021q_cpu);
1633 void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state)
1635 struct ocelot_port *ocelot_port = ocelot->ports[port];
1638 mutex_lock(&ocelot->fwd_domain_lock);
1640 ocelot_port->stp_state = state;
1642 if ((state == BR_STATE_LEARNING || state == BR_STATE_FORWARDING) &&
1643 ocelot_port->learn_ena)
1644 learn_ena = ANA_PORT_PORT_CFG_LEARN_ENA;
1646 ocelot_rmw_gix(ocelot, learn_ena, ANA_PORT_PORT_CFG_LEARN_ENA,
1647 ANA_PORT_PORT_CFG, port);
1649 ocelot_apply_bridge_fwd_mask(ocelot, state == BR_STATE_FORWARDING);
1651 mutex_unlock(&ocelot->fwd_domain_lock);
1653 EXPORT_SYMBOL(ocelot_bridge_stp_state_set);
1655 void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs)
1657 unsigned int age_period = ANA_AUTOAGE_AGE_PERIOD(msecs / 2000);
1659 /* Setting AGE_PERIOD to zero effectively disables automatic aging,
1660 * which is clearly not what our intention is. So avoid that.
1665 ocelot_rmw(ocelot, age_period, ANA_AUTOAGE_AGE_PERIOD_M, ANA_AUTOAGE);
1667 EXPORT_SYMBOL(ocelot_set_ageing_time);
1669 static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot,
1670 const unsigned char *addr,
1673 struct ocelot_multicast *mc;
1675 list_for_each_entry(mc, &ocelot->multicast, list) {
1676 if (ether_addr_equal(mc->addr, addr) && mc->vid == vid)
1683 static enum macaccess_entry_type ocelot_classify_mdb(const unsigned char *addr)
1685 if (addr[0] == 0x01 && addr[1] == 0x00 && addr[2] == 0x5e)
1686 return ENTRYTYPE_MACv4;
1687 if (addr[0] == 0x33 && addr[1] == 0x33)
1688 return ENTRYTYPE_MACv6;
1689 return ENTRYTYPE_LOCKED;
1692 static struct ocelot_pgid *ocelot_pgid_alloc(struct ocelot *ocelot, int index,
1693 unsigned long ports)
1695 struct ocelot_pgid *pgid;
1697 pgid = kzalloc(sizeof(*pgid), GFP_KERNEL);
1699 return ERR_PTR(-ENOMEM);
1701 pgid->ports = ports;
1702 pgid->index = index;
1703 refcount_set(&pgid->refcount, 1);
1704 list_add_tail(&pgid->list, &ocelot->pgids);
1709 static void ocelot_pgid_free(struct ocelot *ocelot, struct ocelot_pgid *pgid)
1711 if (!refcount_dec_and_test(&pgid->refcount))
1714 list_del(&pgid->list);
1718 static struct ocelot_pgid *ocelot_mdb_get_pgid(struct ocelot *ocelot,
1719 const struct ocelot_multicast *mc)
1721 struct ocelot_pgid *pgid;
1724 /* According to VSC7514 datasheet 3.9.1.5 IPv4 Multicast Entries and
1725 * 3.9.1.6 IPv6 Multicast Entries, "Instead of a lookup in the
1726 * destination mask table (PGID), the destination set is programmed as
1727 * part of the entry MAC address.", and the DEST_IDX is set to 0.
1729 if (mc->entry_type == ENTRYTYPE_MACv4 ||
1730 mc->entry_type == ENTRYTYPE_MACv6)
1731 return ocelot_pgid_alloc(ocelot, 0, mc->ports);
1733 list_for_each_entry(pgid, &ocelot->pgids, list) {
1734 /* When searching for a nonreserved multicast PGID, ignore the
1735 * dummy PGID of zero that we have for MACv4/MACv6 entries
1737 if (pgid->index && pgid->ports == mc->ports) {
1738 refcount_inc(&pgid->refcount);
1743 /* Search for a free index in the nonreserved multicast PGID area */
1744 for_each_nonreserved_multicast_dest_pgid(ocelot, index) {
1747 list_for_each_entry(pgid, &ocelot->pgids, list) {
1748 if (pgid->index == index) {
1755 return ocelot_pgid_alloc(ocelot, index, mc->ports);
1758 return ERR_PTR(-ENOSPC);
1761 static void ocelot_encode_ports_to_mdb(unsigned char *addr,
1762 struct ocelot_multicast *mc)
1764 ether_addr_copy(addr, mc->addr);
1766 if (mc->entry_type == ENTRYTYPE_MACv4) {
1768 addr[1] = mc->ports >> 8;
1769 addr[2] = mc->ports & 0xff;
1770 } else if (mc->entry_type == ENTRYTYPE_MACv6) {
1771 addr[0] = mc->ports >> 8;
1772 addr[1] = mc->ports & 0xff;
1776 int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
1777 const struct switchdev_obj_port_mdb *mdb,
1778 const struct net_device *bridge)
1780 unsigned char addr[ETH_ALEN];
1781 struct ocelot_multicast *mc;
1782 struct ocelot_pgid *pgid;
1786 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
1788 mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
1791 mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL);
1795 mc->entry_type = ocelot_classify_mdb(mdb->addr);
1796 ether_addr_copy(mc->addr, mdb->addr);
1799 list_add_tail(&mc->list, &ocelot->multicast);
1801 /* Existing entry. Clean up the current port mask from
1802 * hardware now, because we'll be modifying it.
1804 ocelot_pgid_free(ocelot, mc->pgid);
1805 ocelot_encode_ports_to_mdb(addr, mc);
1806 ocelot_mact_forget(ocelot, addr, vid);
1809 mc->ports |= BIT(port);
1811 pgid = ocelot_mdb_get_pgid(ocelot, mc);
1813 dev_err(ocelot->dev,
1814 "Cannot allocate PGID for mdb %pM vid %d\n",
1816 devm_kfree(ocelot->dev, mc);
1817 return PTR_ERR(pgid);
1821 ocelot_encode_ports_to_mdb(addr, mc);
1823 if (mc->entry_type != ENTRYTYPE_MACv4 &&
1824 mc->entry_type != ENTRYTYPE_MACv6)
1825 ocelot_write_rix(ocelot, pgid->ports, ANA_PGID_PGID,
1828 return ocelot_mact_learn(ocelot, pgid->index, addr, vid,
1831 EXPORT_SYMBOL(ocelot_port_mdb_add);
1833 int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
1834 const struct switchdev_obj_port_mdb *mdb,
1835 const struct net_device *bridge)
1837 unsigned char addr[ETH_ALEN];
1838 struct ocelot_multicast *mc;
1839 struct ocelot_pgid *pgid;
1843 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
1845 mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
1849 ocelot_encode_ports_to_mdb(addr, mc);
1850 ocelot_mact_forget(ocelot, addr, vid);
1852 ocelot_pgid_free(ocelot, mc->pgid);
1853 mc->ports &= ~BIT(port);
1855 list_del(&mc->list);
1856 devm_kfree(ocelot->dev, mc);
1860 /* We have a PGID with fewer ports now */
1861 pgid = ocelot_mdb_get_pgid(ocelot, mc);
1863 return PTR_ERR(pgid);
1866 ocelot_encode_ports_to_mdb(addr, mc);
1868 if (mc->entry_type != ENTRYTYPE_MACv4 &&
1869 mc->entry_type != ENTRYTYPE_MACv6)
1870 ocelot_write_rix(ocelot, pgid->ports, ANA_PGID_PGID,
1873 return ocelot_mact_learn(ocelot, pgid->index, addr, vid,
1876 EXPORT_SYMBOL(ocelot_port_mdb_del);
1878 int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
1879 struct net_device *bridge, int bridge_num,
1880 struct netlink_ext_ack *extack)
1882 struct ocelot_port *ocelot_port = ocelot->ports[port];
1885 err = ocelot_single_vlan_aware_bridge(ocelot, extack);
1889 mutex_lock(&ocelot->fwd_domain_lock);
1891 ocelot_port->bridge = bridge;
1892 ocelot_port->bridge_num = bridge_num;
1894 ocelot_apply_bridge_fwd_mask(ocelot, true);
1896 mutex_unlock(&ocelot->fwd_domain_lock);
1898 if (br_vlan_enabled(bridge))
1901 return ocelot_add_vlan_unaware_pvid(ocelot, port, bridge);
1903 EXPORT_SYMBOL(ocelot_port_bridge_join);
1905 void ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
1906 struct net_device *bridge)
1908 struct ocelot_port *ocelot_port = ocelot->ports[port];
1910 mutex_lock(&ocelot->fwd_domain_lock);
1912 if (!br_vlan_enabled(bridge))
1913 ocelot_del_vlan_unaware_pvid(ocelot, port, bridge);
1915 ocelot_port->bridge = NULL;
1916 ocelot_port->bridge_num = -1;
1918 ocelot_port_set_pvid(ocelot, port, NULL);
1919 ocelot_port_manage_port_tag(ocelot, port);
1920 ocelot_apply_bridge_fwd_mask(ocelot, false);
1922 mutex_unlock(&ocelot->fwd_domain_lock);
1924 EXPORT_SYMBOL(ocelot_port_bridge_leave);
1926 static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
1928 unsigned long visited = GENMASK(ocelot->num_phys_ports - 1, 0);
1931 /* Reset destination and aggregation PGIDS */
1932 for_each_unicast_dest_pgid(ocelot, port)
1933 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
1935 for_each_aggr_pgid(ocelot, i)
1936 ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
1939 /* The visited ports bitmask holds the list of ports offloading any
1940 * bonding interface. Initially we mark all these ports as unvisited,
1941 * then every time we visit a port in this bitmask, we know that it is
1942 * the lowest numbered port, i.e. the one whose logical ID == physical
1943 * port ID == LAG ID. So we mark as visited all further ports in the
1944 * bitmask that are offloading the same bonding interface. This way,
1945 * we set up the aggregation PGIDs only once per bonding interface.
1947 for (port = 0; port < ocelot->num_phys_ports; port++) {
1948 struct ocelot_port *ocelot_port = ocelot->ports[port];
1950 if (!ocelot_port || !ocelot_port->bond)
1953 visited &= ~BIT(port);
1956 /* Now, set PGIDs for each active LAG */
1957 for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
1958 struct net_device *bond = ocelot->ports[lag]->bond;
1959 int num_active_ports = 0;
1960 unsigned long bond_mask;
1963 if (!bond || (visited & BIT(lag)))
1966 bond_mask = ocelot_get_bond_mask(ocelot, bond);
1968 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
1969 struct ocelot_port *ocelot_port = ocelot->ports[port];
1972 ocelot_write_rix(ocelot, bond_mask,
1973 ANA_PGID_PGID, port);
1975 if (ocelot_port->lag_tx_active)
1976 aggr_idx[num_active_ports++] = port;
1979 for_each_aggr_pgid(ocelot, i) {
1982 ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
1984 /* Don't do division by zero if there was no active
1985 * port. Just make all aggregation codes zero.
1987 if (num_active_ports)
1988 ac |= BIT(aggr_idx[i % num_active_ports]);
1989 ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i);
1992 /* Mark all ports in the same LAG as visited to avoid applying
1993 * the same config again.
1995 for (port = lag; port < ocelot->num_phys_ports; port++) {
1996 struct ocelot_port *ocelot_port = ocelot->ports[port];
2001 if (ocelot_port->bond == bond)
2002 visited |= BIT(port);
2007 /* When offloading a bonding interface, the switch ports configured under the
2008 * same bond must have the same logical port ID, equal to the physical port ID
2009 * of the lowest numbered physical port in that bond. Otherwise, in standalone/
2010 * bridged mode, each port has a logical port ID equal to its physical port ID.
2012 static void ocelot_setup_logical_port_ids(struct ocelot *ocelot)
2016 for (port = 0; port < ocelot->num_phys_ports; port++) {
2017 struct ocelot_port *ocelot_port = ocelot->ports[port];
2018 struct net_device *bond;
2023 bond = ocelot_port->bond;
2025 int lag = ocelot_bond_get_id(ocelot, bond);
2027 ocelot_rmw_gix(ocelot,
2028 ANA_PORT_PORT_CFG_PORTID_VAL(lag),
2029 ANA_PORT_PORT_CFG_PORTID_VAL_M,
2030 ANA_PORT_PORT_CFG, port);
2032 ocelot_rmw_gix(ocelot,
2033 ANA_PORT_PORT_CFG_PORTID_VAL(port),
2034 ANA_PORT_PORT_CFG_PORTID_VAL_M,
2035 ANA_PORT_PORT_CFG, port);
2040 static int ocelot_migrate_mc(struct ocelot *ocelot, struct ocelot_multicast *mc,
2041 unsigned long from_mask, unsigned long to_mask)
2043 unsigned char addr[ETH_ALEN];
2044 struct ocelot_pgid *pgid;
2047 dev_dbg(ocelot->dev,
2048 "Migrating multicast %pM vid %d from port mask 0x%lx to 0x%lx\n",
2049 mc->addr, mc->vid, from_mask, to_mask);
2051 /* First clean up the current port mask from hardware, because
2052 * we'll be modifying it.
2054 ocelot_pgid_free(ocelot, mc->pgid);
2055 ocelot_encode_ports_to_mdb(addr, mc);
2056 ocelot_mact_forget(ocelot, addr, vid);
2058 mc->ports &= ~from_mask;
2059 mc->ports |= to_mask;
2061 pgid = ocelot_mdb_get_pgid(ocelot, mc);
2063 dev_err(ocelot->dev,
2064 "Cannot allocate PGID for mdb %pM vid %d\n",
2066 devm_kfree(ocelot->dev, mc);
2067 return PTR_ERR(pgid);
2071 ocelot_encode_ports_to_mdb(addr, mc);
2073 if (mc->entry_type != ENTRYTYPE_MACv4 &&
2074 mc->entry_type != ENTRYTYPE_MACv6)
2075 ocelot_write_rix(ocelot, pgid->ports, ANA_PGID_PGID,
2078 return ocelot_mact_learn(ocelot, pgid->index, addr, vid,
2082 int ocelot_migrate_mdbs(struct ocelot *ocelot, unsigned long from_mask,
2083 unsigned long to_mask)
2085 struct ocelot_multicast *mc;
2088 list_for_each_entry(mc, &ocelot->multicast, list) {
2089 if (!(mc->ports & from_mask))
2092 err = ocelot_migrate_mc(ocelot, mc, from_mask, to_mask);
2099 EXPORT_SYMBOL_GPL(ocelot_migrate_mdbs);
2101 /* Documentation for PORTID_VAL says:
2102 * Logical port number for front port. If port is not a member of a LLAG,
2103 * then PORTID must be set to the physical port number.
2104 * If port is a member of a LLAG, then PORTID must be set to the common
2105 * PORTID_VAL used for all member ports of the LLAG.
2106 * The value must not exceed the number of physical ports on the device.
2108 * This means we have little choice but to migrate FDB entries pointing towards
2109 * a logical port when that changes.
2111 static void ocelot_migrate_lag_fdbs(struct ocelot *ocelot,
2112 struct net_device *bond,
2115 struct ocelot_lag_fdb *fdb;
2118 lockdep_assert_held(&ocelot->fwd_domain_lock);
2120 list_for_each_entry(fdb, &ocelot->lag_fdbs, list) {
2121 if (fdb->bond != bond)
2124 err = ocelot_mact_forget(ocelot, fdb->addr, fdb->vid);
2126 dev_err(ocelot->dev,
2127 "failed to delete LAG %s FDB %pM vid %d: %pe\n",
2128 bond->name, fdb->addr, fdb->vid, ERR_PTR(err));
2131 err = ocelot_mact_learn(ocelot, lag, fdb->addr, fdb->vid,
2134 dev_err(ocelot->dev,
2135 "failed to migrate LAG %s FDB %pM vid %d: %pe\n",
2136 bond->name, fdb->addr, fdb->vid, ERR_PTR(err));
2141 int ocelot_port_lag_join(struct ocelot *ocelot, int port,
2142 struct net_device *bond,
2143 struct netdev_lag_upper_info *info,
2144 struct netlink_ext_ack *extack)
2146 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
2147 NL_SET_ERR_MSG_MOD(extack,
2148 "Can only offload LAG using hash TX type");
2152 mutex_lock(&ocelot->fwd_domain_lock);
2154 ocelot->ports[port]->bond = bond;
2156 ocelot_setup_logical_port_ids(ocelot);
2157 ocelot_apply_bridge_fwd_mask(ocelot, true);
2158 ocelot_set_aggr_pgids(ocelot);
2160 mutex_unlock(&ocelot->fwd_domain_lock);
2164 EXPORT_SYMBOL(ocelot_port_lag_join);
2166 void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
2167 struct net_device *bond)
2169 int old_lag_id, new_lag_id;
2171 mutex_lock(&ocelot->fwd_domain_lock);
2173 old_lag_id = ocelot_bond_get_id(ocelot, bond);
2175 ocelot->ports[port]->bond = NULL;
2177 ocelot_setup_logical_port_ids(ocelot);
2178 ocelot_apply_bridge_fwd_mask(ocelot, false);
2179 ocelot_set_aggr_pgids(ocelot);
2181 new_lag_id = ocelot_bond_get_id(ocelot, bond);
2183 if (new_lag_id >= 0 && old_lag_id != new_lag_id)
2184 ocelot_migrate_lag_fdbs(ocelot, bond, new_lag_id);
2186 mutex_unlock(&ocelot->fwd_domain_lock);
2188 EXPORT_SYMBOL(ocelot_port_lag_leave);
2190 void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active)
2192 struct ocelot_port *ocelot_port = ocelot->ports[port];
2194 mutex_lock(&ocelot->fwd_domain_lock);
2196 ocelot_port->lag_tx_active = lag_tx_active;
2198 /* Rebalance the LAGs */
2199 ocelot_set_aggr_pgids(ocelot);
2201 mutex_unlock(&ocelot->fwd_domain_lock);
2203 EXPORT_SYMBOL(ocelot_port_lag_change);
2205 int ocelot_lag_fdb_add(struct ocelot *ocelot, struct net_device *bond,
2206 const unsigned char *addr, u16 vid,
2207 const struct net_device *bridge)
2209 struct ocelot_lag_fdb *fdb;
2212 fdb = kzalloc(sizeof(*fdb), GFP_KERNEL);
2216 mutex_lock(&ocelot->fwd_domain_lock);
2219 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
2221 ether_addr_copy(fdb->addr, addr);
2225 lag = ocelot_bond_get_id(ocelot, bond);
2227 err = ocelot_mact_learn(ocelot, lag, addr, vid, ENTRYTYPE_LOCKED);
2229 mutex_unlock(&ocelot->fwd_domain_lock);
2234 list_add_tail(&fdb->list, &ocelot->lag_fdbs);
2235 mutex_unlock(&ocelot->fwd_domain_lock);
2239 EXPORT_SYMBOL_GPL(ocelot_lag_fdb_add);
2241 int ocelot_lag_fdb_del(struct ocelot *ocelot, struct net_device *bond,
2242 const unsigned char *addr, u16 vid,
2243 const struct net_device *bridge)
2245 struct ocelot_lag_fdb *fdb, *tmp;
2247 mutex_lock(&ocelot->fwd_domain_lock);
2250 vid = ocelot_vlan_unaware_pvid(ocelot, bridge);
2252 list_for_each_entry_safe(fdb, tmp, &ocelot->lag_fdbs, list) {
2253 if (!ether_addr_equal(fdb->addr, addr) || fdb->vid != vid ||
2257 ocelot_mact_forget(ocelot, addr, vid);
2258 list_del(&fdb->list);
2259 mutex_unlock(&ocelot->fwd_domain_lock);
2265 mutex_unlock(&ocelot->fwd_domain_lock);
2269 EXPORT_SYMBOL_GPL(ocelot_lag_fdb_del);
2271 /* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu.
2272 * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG.
2273 * In the special case that it's the NPI port that we're configuring, the
2274 * length of the tag and optional prefix needs to be accounted for privately,
2275 * in order to be able to sustain communication at the requested @sdu.
2277 void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu)
2279 struct ocelot_port *ocelot_port = ocelot->ports[port];
2280 int maxlen = sdu + ETH_HLEN + ETH_FCS_LEN;
2281 int pause_start, pause_stop;
2284 if (port == ocelot->npi) {
2285 maxlen += OCELOT_TAG_LEN;
2287 if (ocelot->npi_inj_prefix == OCELOT_TAG_PREFIX_SHORT)
2288 maxlen += OCELOT_SHORT_PREFIX_LEN;
2289 else if (ocelot->npi_inj_prefix == OCELOT_TAG_PREFIX_LONG)
2290 maxlen += OCELOT_LONG_PREFIX_LEN;
2293 ocelot_port_writel(ocelot_port, maxlen, DEV_MAC_MAXLEN_CFG);
2295 /* Set Pause watermark hysteresis */
2296 pause_start = 6 * maxlen / OCELOT_BUFFER_CELL_SZ;
2297 pause_stop = 4 * maxlen / OCELOT_BUFFER_CELL_SZ;
2298 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_START,
2300 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_STOP,
2303 /* Tail dropping watermarks */
2304 atop_tot = (ocelot->packet_buffer_size - 9 * maxlen) /
2305 OCELOT_BUFFER_CELL_SZ;
2306 atop = (9 * maxlen) / OCELOT_BUFFER_CELL_SZ;
2307 ocelot_write_rix(ocelot, ocelot->ops->wm_enc(atop), SYS_ATOP, port);
2308 ocelot_write(ocelot, ocelot->ops->wm_enc(atop_tot), SYS_ATOP_TOT_CFG);
2310 EXPORT_SYMBOL(ocelot_port_set_maxlen);
2312 int ocelot_get_max_mtu(struct ocelot *ocelot, int port)
2314 int max_mtu = 65535 - ETH_HLEN - ETH_FCS_LEN;
2316 if (port == ocelot->npi) {
2317 max_mtu -= OCELOT_TAG_LEN;
2319 if (ocelot->npi_inj_prefix == OCELOT_TAG_PREFIX_SHORT)
2320 max_mtu -= OCELOT_SHORT_PREFIX_LEN;
2321 else if (ocelot->npi_inj_prefix == OCELOT_TAG_PREFIX_LONG)
2322 max_mtu -= OCELOT_LONG_PREFIX_LEN;
2327 EXPORT_SYMBOL(ocelot_get_max_mtu);
2329 static void ocelot_port_set_learning(struct ocelot *ocelot, int port,
2332 struct ocelot_port *ocelot_port = ocelot->ports[port];
2336 val = ANA_PORT_PORT_CFG_LEARN_ENA;
2338 ocelot_rmw_gix(ocelot, val, ANA_PORT_PORT_CFG_LEARN_ENA,
2339 ANA_PORT_PORT_CFG, port);
2341 ocelot_port->learn_ena = enabled;
2344 static void ocelot_port_set_ucast_flood(struct ocelot *ocelot, int port,
2352 ocelot_rmw_rix(ocelot, val, BIT(port), ANA_PGID_PGID, PGID_UC);
2355 static void ocelot_port_set_mcast_flood(struct ocelot *ocelot, int port,
2363 ocelot_rmw_rix(ocelot, val, BIT(port), ANA_PGID_PGID, PGID_MC);
2364 ocelot_rmw_rix(ocelot, val, BIT(port), ANA_PGID_PGID, PGID_MCIPV4);
2365 ocelot_rmw_rix(ocelot, val, BIT(port), ANA_PGID_PGID, PGID_MCIPV6);
2368 static void ocelot_port_set_bcast_flood(struct ocelot *ocelot, int port,
2376 ocelot_rmw_rix(ocelot, val, BIT(port), ANA_PGID_PGID, PGID_BC);
2379 int ocelot_port_pre_bridge_flags(struct ocelot *ocelot, int port,
2380 struct switchdev_brport_flags flags)
2382 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
2388 EXPORT_SYMBOL(ocelot_port_pre_bridge_flags);
2390 void ocelot_port_bridge_flags(struct ocelot *ocelot, int port,
2391 struct switchdev_brport_flags flags)
2393 if (flags.mask & BR_LEARNING)
2394 ocelot_port_set_learning(ocelot, port,
2395 !!(flags.val & BR_LEARNING));
2397 if (flags.mask & BR_FLOOD)
2398 ocelot_port_set_ucast_flood(ocelot, port,
2399 !!(flags.val & BR_FLOOD));
2401 if (flags.mask & BR_MCAST_FLOOD)
2402 ocelot_port_set_mcast_flood(ocelot, port,
2403 !!(flags.val & BR_MCAST_FLOOD));
2405 if (flags.mask & BR_BCAST_FLOOD)
2406 ocelot_port_set_bcast_flood(ocelot, port,
2407 !!(flags.val & BR_BCAST_FLOOD));
2409 EXPORT_SYMBOL(ocelot_port_bridge_flags);
2411 int ocelot_port_get_default_prio(struct ocelot *ocelot, int port)
2413 int val = ocelot_read_gix(ocelot, ANA_PORT_QOS_CFG, port);
2415 return ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL_X(val);
2417 EXPORT_SYMBOL_GPL(ocelot_port_get_default_prio);
2419 int ocelot_port_set_default_prio(struct ocelot *ocelot, int port, u8 prio)
2421 if (prio >= OCELOT_NUM_TC)
2424 ocelot_rmw_gix(ocelot,
2425 ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL(prio),
2426 ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL_M,
2432 EXPORT_SYMBOL_GPL(ocelot_port_set_default_prio);
2434 int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp)
2436 int qos_cfg = ocelot_read_gix(ocelot, ANA_PORT_QOS_CFG, port);
2437 int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp);
2439 /* Return error if DSCP prioritization isn't enabled */
2440 if (!(qos_cfg & ANA_PORT_QOS_CFG_QOS_DSCP_ENA))
2443 if (qos_cfg & ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA) {
2444 dscp = ANA_DSCP_CFG_DSCP_TRANSLATE_VAL_X(dscp_cfg);
2445 /* Re-read ANA_DSCP_CFG for the translated DSCP */
2446 dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp);
2449 /* If the DSCP value is not trusted, the QoS classification falls back
2450 * to VLAN PCP or port-based default.
2452 if (!(dscp_cfg & ANA_DSCP_CFG_DSCP_TRUST_ENA))
2455 return ANA_DSCP_CFG_QOS_DSCP_VAL_X(dscp_cfg);
2457 EXPORT_SYMBOL_GPL(ocelot_port_get_dscp_prio);
2459 int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio)
2463 if (prio >= OCELOT_NUM_TC)
2466 /* There is at least one app table priority (this one), so we need to
2467 * make sure DSCP prioritization is enabled on the port.
2468 * Also make sure DSCP translation is disabled
2469 * (dcbnl doesn't support it).
2471 mask = ANA_PORT_QOS_CFG_QOS_DSCP_ENA |
2472 ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA;
2474 ocelot_rmw_gix(ocelot, ANA_PORT_QOS_CFG_QOS_DSCP_ENA, mask,
2475 ANA_PORT_QOS_CFG, port);
2477 /* Trust this DSCP value and map it to the given QoS class */
2478 val = ANA_DSCP_CFG_DSCP_TRUST_ENA | ANA_DSCP_CFG_QOS_DSCP_VAL(prio);
2480 ocelot_write_rix(ocelot, val, ANA_DSCP_CFG, dscp);
2484 EXPORT_SYMBOL_GPL(ocelot_port_add_dscp_prio);
2486 int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio)
2488 int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp);
2491 /* During a "dcb app replace" command, the new app table entry will be
2492 * added first, then the old one will be deleted. But the hardware only
2493 * supports one QoS class per DSCP value (duh), so if we blindly delete
2494 * the app table entry for this DSCP value, we end up deleting the
2495 * entry with the new priority. Avoid that by checking whether user
2496 * space wants to delete the priority which is currently configured, or
2497 * something else which is no longer current.
2499 if (ANA_DSCP_CFG_QOS_DSCP_VAL_X(dscp_cfg) != prio)
2502 /* Untrust this DSCP value */
2503 ocelot_write_rix(ocelot, 0, ANA_DSCP_CFG, dscp);
2505 for (i = 0; i < 64; i++) {
2506 int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, i);
2508 /* There are still app table entries on the port, so we need to
2509 * keep DSCP enabled, nothing to do.
2511 if (dscp_cfg & ANA_DSCP_CFG_DSCP_TRUST_ENA)
2515 /* Disable DSCP QoS classification if there isn't any trusted
2518 mask = ANA_PORT_QOS_CFG_QOS_DSCP_ENA |
2519 ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA;
2521 ocelot_rmw_gix(ocelot, 0, mask, ANA_PORT_QOS_CFG, port);
2525 EXPORT_SYMBOL_GPL(ocelot_port_del_dscp_prio);
2527 struct ocelot_mirror *ocelot_mirror_get(struct ocelot *ocelot, int to,
2528 struct netlink_ext_ack *extack)
2530 struct ocelot_mirror *m = ocelot->mirror;
2534 NL_SET_ERR_MSG_MOD(extack,
2535 "Mirroring already configured towards different egress port");
2536 return ERR_PTR(-EBUSY);
2539 refcount_inc(&m->refcount);
2543 m = kzalloc(sizeof(*m), GFP_KERNEL);
2545 return ERR_PTR(-ENOMEM);
2548 refcount_set(&m->refcount, 1);
2551 /* Program the mirror port to hardware */
2552 ocelot_write(ocelot, BIT(to), ANA_MIRRORPORTS);
2557 void ocelot_mirror_put(struct ocelot *ocelot)
2559 struct ocelot_mirror *m = ocelot->mirror;
2561 if (!refcount_dec_and_test(&m->refcount))
2564 ocelot_write(ocelot, 0, ANA_MIRRORPORTS);
2565 ocelot->mirror = NULL;
2569 int ocelot_port_mirror_add(struct ocelot *ocelot, int from, int to,
2570 bool ingress, struct netlink_ext_ack *extack)
2572 struct ocelot_mirror *m = ocelot_mirror_get(ocelot, to, extack);
2578 ocelot_rmw_gix(ocelot, ANA_PORT_PORT_CFG_SRC_MIRROR_ENA,
2579 ANA_PORT_PORT_CFG_SRC_MIRROR_ENA,
2580 ANA_PORT_PORT_CFG, from);
2582 ocelot_rmw(ocelot, BIT(from), BIT(from),
2588 EXPORT_SYMBOL_GPL(ocelot_port_mirror_add);
2590 void ocelot_port_mirror_del(struct ocelot *ocelot, int from, bool ingress)
2593 ocelot_rmw_gix(ocelot, 0, ANA_PORT_PORT_CFG_SRC_MIRROR_ENA,
2594 ANA_PORT_PORT_CFG, from);
2596 ocelot_rmw(ocelot, 0, BIT(from), ANA_EMIRRORPORTS);
2599 ocelot_mirror_put(ocelot);
2601 EXPORT_SYMBOL_GPL(ocelot_port_mirror_del);
2603 void ocelot_init_port(struct ocelot *ocelot, int port)
2605 struct ocelot_port *ocelot_port = ocelot->ports[port];
2607 skb_queue_head_init(&ocelot_port->tx_skbs);
2609 /* Basic L2 initialization */
2612 * FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 0
2613 * !FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 5
2615 ocelot_port_writel(ocelot_port, DEV_MAC_IFG_CFG_TX_IFG(5),
2618 /* Load seed (0) and set MAC HDX late collision */
2619 ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
2620 DEV_MAC_HDX_CFG_SEED_LOAD,
2623 ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
2626 /* Set Max Length and maximum tags allowed */
2627 ocelot_port_set_maxlen(ocelot, port, ETH_DATA_LEN);
2628 ocelot_port_writel(ocelot_port, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD) |
2629 DEV_MAC_TAGS_CFG_VLAN_AWR_ENA |
2630 DEV_MAC_TAGS_CFG_VLAN_DBL_AWR_ENA |
2631 DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA,
2634 /* Set SMAC of Pause frame (00:00:00:00:00:00) */
2635 ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_HIGH_CFG);
2636 ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_LOW_CFG);
2638 /* Enable transmission of pause frames */
2639 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1);
2641 /* Drop frames with multicast source address */
2642 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
2643 ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
2644 ANA_PORT_DROP_CFG, port);
2646 /* Set default VLAN and tag type to 8021Q. */
2647 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q),
2648 REW_PORT_VLAN_CFG_PORT_TPID_M,
2649 REW_PORT_VLAN_CFG, port);
2651 /* Disable source address learning for standalone mode */
2652 ocelot_port_set_learning(ocelot, port, false);
2654 /* Set the port's initial logical port ID value, enable receiving
2655 * frames on it, and configure the MAC address learning type to
2658 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO |
2659 ANA_PORT_PORT_CFG_RECV_ENA |
2660 ANA_PORT_PORT_CFG_PORTID_VAL(port),
2661 ANA_PORT_PORT_CFG, port);
2663 /* Enable vcap lookups */
2664 ocelot_vcap_enable(ocelot, port);
2666 EXPORT_SYMBOL(ocelot_init_port);
2668 /* Configure and enable the CPU port module, which is a set of queues
2669 * accessible through register MMIO, frame DMA or Ethernet (in case
2670 * NPI mode is used).
2672 static void ocelot_cpu_port_init(struct ocelot *ocelot)
2674 int cpu = ocelot->num_phys_ports;
2676 /* The unicast destination PGID for the CPU port module is unused */
2677 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu);
2678 /* Instead set up a multicast destination PGID for traffic copied to
2679 * the CPU. Whitelisted MAC addresses like the port netdevice MAC
2680 * addresses will be copied to the CPU via this PGID.
2682 ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU);
2683 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA |
2684 ANA_PORT_PORT_CFG_PORTID_VAL(cpu),
2685 ANA_PORT_PORT_CFG, cpu);
2687 /* Enable CPU port module */
2688 ocelot_fields_write(ocelot, cpu, QSYS_SWITCH_PORT_MODE_PORT_ENA, 1);
2689 /* CPU port Injection/Extraction configuration */
2690 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_XTR_HDR,
2691 OCELOT_TAG_PREFIX_NONE);
2692 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_INJ_HDR,
2693 OCELOT_TAG_PREFIX_NONE);
2695 /* Configure the CPU port to be VLAN aware */
2696 ocelot_write_gix(ocelot,
2697 ANA_PORT_VLAN_CFG_VLAN_VID(OCELOT_STANDALONE_PVID) |
2698 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
2699 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1),
2700 ANA_PORT_VLAN_CFG, cpu);
2703 static void ocelot_detect_features(struct ocelot *ocelot)
2707 /* For Ocelot, Felix, Seville, Serval etc, SYS:MMGT:MMGT:FREECNT holds
2708 * the number of 240-byte free memory words (aka 4-cell chunks) and not
2709 * 192 bytes as the documentation incorrectly says.
2711 mmgt = ocelot_read(ocelot, SYS_MMGT);
2712 ocelot->packet_buffer_size = 240 * SYS_MMGT_FREECNT(mmgt);
2714 eq_ctrl = ocelot_read(ocelot, QSYS_EQ_CTRL);
2715 ocelot->num_frame_refs = QSYS_MMGT_EQ_CTRL_FP_FREE_CNT(eq_ctrl);
2718 int ocelot_init(struct ocelot *ocelot)
2723 if (ocelot->ops->reset) {
2724 ret = ocelot->ops->reset(ocelot);
2726 dev_err(ocelot->dev, "Switch reset failed\n");
2731 mutex_init(&ocelot->ptp_lock);
2732 mutex_init(&ocelot->mact_lock);
2733 mutex_init(&ocelot->fwd_domain_lock);
2734 mutex_init(&ocelot->tas_lock);
2735 spin_lock_init(&ocelot->ptp_clock_lock);
2736 spin_lock_init(&ocelot->ts_id_lock);
2738 ocelot->owq = alloc_ordered_workqueue("ocelot-owq", 0);
2742 ret = ocelot_stats_init(ocelot);
2744 destroy_workqueue(ocelot->owq);
2748 INIT_LIST_HEAD(&ocelot->multicast);
2749 INIT_LIST_HEAD(&ocelot->pgids);
2750 INIT_LIST_HEAD(&ocelot->vlans);
2751 INIT_LIST_HEAD(&ocelot->lag_fdbs);
2752 ocelot_detect_features(ocelot);
2753 ocelot_mact_init(ocelot);
2754 ocelot_vlan_init(ocelot);
2755 ocelot_vcap_init(ocelot);
2756 ocelot_cpu_port_init(ocelot);
2758 if (ocelot->ops->psfp_init)
2759 ocelot->ops->psfp_init(ocelot);
2761 for (port = 0; port < ocelot->num_phys_ports; port++) {
2762 /* Clear all counters (5 groups) */
2763 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) |
2764 SYS_STAT_CFG_STAT_CLEAR_SHOT(0x7f),
2768 /* Only use S-Tag */
2769 ocelot_write(ocelot, ETH_P_8021AD, SYS_VLAN_ETYPE_CFG);
2771 /* Aggregation mode */
2772 ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA |
2773 ANA_AGGR_CFG_AC_DMAC_ENA |
2774 ANA_AGGR_CFG_AC_IP4_SIPDIP_ENA |
2775 ANA_AGGR_CFG_AC_IP4_TCPUDP_ENA |
2776 ANA_AGGR_CFG_AC_IP6_FLOW_LBL_ENA |
2777 ANA_AGGR_CFG_AC_IP6_TCPUDP_ENA,
2780 /* Set MAC age time to default value. The entry is aged after
2783 ocelot_write(ocelot,
2784 ANA_AUTOAGE_AGE_PERIOD(BR_DEFAULT_AGEING_TIME / 2 / HZ),
2787 /* Disable learning for frames discarded by VLAN ingress filtering */
2788 regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1);
2790 /* Setup frame ageing - fixed value "2 sec" - in 6.5 us units */
2791 ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA |
2792 SYS_FRM_AGING_MAX_AGE(307692), SYS_FRM_AGING);
2794 /* Setup flooding PGIDs */
2795 for (i = 0; i < ocelot->num_flooding_pgids; i++)
2796 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) |
2797 ANA_FLOODING_FLD_BROADCAST(PGID_BC) |
2798 ANA_FLOODING_FLD_UNICAST(PGID_UC),
2800 ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) |
2801 ANA_FLOODING_IPMC_FLD_MC6_CTRL(PGID_MC) |
2802 ANA_FLOODING_IPMC_FLD_MC4_DATA(PGID_MCIPV4) |
2803 ANA_FLOODING_IPMC_FLD_MC4_CTRL(PGID_MC),
2806 for (port = 0; port < ocelot->num_phys_ports; port++) {
2807 /* Transmit the frame to the local port. */
2808 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
2809 /* Do not forward BPDU frames to the front ports. */
2810 ocelot_write_gix(ocelot,
2811 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
2812 ANA_PORT_CPU_FWD_BPDU_CFG,
2814 /* Ensure bridging is disabled */
2815 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port);
2818 for_each_nonreserved_multicast_dest_pgid(ocelot, i) {
2819 u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0));
2821 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
2824 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_BLACKHOLE);
2826 /* Allow broadcast and unknown L2 multicast to the CPU. */
2827 ocelot_rmw_rix(ocelot, ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)),
2828 ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)),
2829 ANA_PGID_PGID, PGID_MC);
2830 ocelot_rmw_rix(ocelot, ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)),
2831 ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)),
2832 ANA_PGID_PGID, PGID_BC);
2833 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV4);
2834 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV6);
2836 /* Allow manual injection via DEVCPU_QS registers, and byte swap these
2837 * registers endianness.
2839 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_BYTE_SWAP |
2840 QS_INJ_GRP_CFG_MODE(1), QS_INJ_GRP_CFG, 0);
2841 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_BYTE_SWAP |
2842 QS_XTR_GRP_CFG_MODE(1), QS_XTR_GRP_CFG, 0);
2843 ocelot_write(ocelot, ANA_CPUQ_CFG_CPUQ_MIRROR(2) |
2844 ANA_CPUQ_CFG_CPUQ_LRN(2) |
2845 ANA_CPUQ_CFG_CPUQ_MAC_COPY(2) |
2846 ANA_CPUQ_CFG_CPUQ_SRC_COPY(2) |
2847 ANA_CPUQ_CFG_CPUQ_LOCKED_PORTMOVE(2) |
2848 ANA_CPUQ_CFG_CPUQ_ALLBRIDGE(6) |
2849 ANA_CPUQ_CFG_CPUQ_IPMC_CTRL(6) |
2850 ANA_CPUQ_CFG_CPUQ_IGMP(6) |
2851 ANA_CPUQ_CFG_CPUQ_MLD(6), ANA_CPUQ_CFG);
2852 for (i = 0; i < 16; i++)
2853 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) |
2854 ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
2855 ANA_CPUQ_8021_CFG, i);
2859 EXPORT_SYMBOL(ocelot_init);
2861 void ocelot_deinit(struct ocelot *ocelot)
2863 ocelot_stats_deinit(ocelot);
2864 destroy_workqueue(ocelot->owq);
2866 EXPORT_SYMBOL(ocelot_deinit);
2868 void ocelot_deinit_port(struct ocelot *ocelot, int port)
2870 struct ocelot_port *ocelot_port = ocelot->ports[port];
2872 skb_queue_purge(&ocelot_port->tx_skbs);
2874 EXPORT_SYMBOL(ocelot_deinit_port);
2876 MODULE_LICENSE("Dual MIT/GPL");