• Home
  • Raw
  • Download

Lines Matching +full:ocelot +full:- +full:1

1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Microsemi Ocelot Switch driver
9 #include "ocelot.h"
21 static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot) in ocelot_mact_read_macaccess() argument
23 return ocelot_read(ocelot, ANA_TABLES_MACACCESS); in ocelot_mact_read_macaccess()
26 static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot) in ocelot_mact_wait_for_completion() argument
31 ocelot, val, in ocelot_mact_wait_for_completion()
37 static void ocelot_mact_select(struct ocelot *ocelot, in ocelot_mact_select() argument
48 mach |= mac[1] << 0; in ocelot_mact_select()
54 ocelot_write(ocelot, macl, ANA_TABLES_MACLDATA); in ocelot_mact_select()
55 ocelot_write(ocelot, mach, ANA_TABLES_MACHDATA); in ocelot_mact_select()
59 int ocelot_mact_learn(struct ocelot *ocelot, int port, in ocelot_mact_learn() argument
71 mc_ports = (mac[1] << 8) | mac[2]; in ocelot_mact_learn()
73 mc_ports = (mac[0] << 8) | mac[1]; in ocelot_mact_learn()
77 if (mc_ports & BIT(ocelot->num_phys_ports)) in ocelot_mact_learn()
80 ocelot_mact_select(ocelot, mac, vid); in ocelot_mact_learn()
83 ocelot_write(ocelot, cmd, ANA_TABLES_MACACCESS); in ocelot_mact_learn()
85 return ocelot_mact_wait_for_completion(ocelot); in ocelot_mact_learn()
89 int ocelot_mact_forget(struct ocelot *ocelot, in ocelot_mact_forget() argument
92 ocelot_mact_select(ocelot, mac, vid); in ocelot_mact_forget()
95 ocelot_write(ocelot, in ocelot_mact_forget()
99 return ocelot_mact_wait_for_completion(ocelot); in ocelot_mact_forget()
103 static void ocelot_mact_init(struct ocelot *ocelot) in ocelot_mact_init() argument
106 * - Do not copy the frame to the CPU extraction queues. in ocelot_mact_init()
107 * - Use the vlan and mac_cpoy for dmac lookup. in ocelot_mact_init()
109 ocelot_rmw(ocelot, 0, in ocelot_mact_init()
116 ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS); in ocelot_mact_init()
119 static void ocelot_vcap_enable(struct ocelot *ocelot, int port) in ocelot_vcap_enable() argument
121 ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA | in ocelot_vcap_enable()
125 ocelot_write_gix(ocelot, ANA_PORT_VCAP_CFG_S1_ENA, in ocelot_vcap_enable()
128 ocelot_rmw_gix(ocelot, REW_PORT_CFG_ES0_EN, in ocelot_vcap_enable()
133 static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot) in ocelot_vlant_read_vlanaccess() argument
135 return ocelot_read(ocelot, ANA_TABLES_VLANACCESS); in ocelot_vlant_read_vlanaccess()
138 static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot) in ocelot_vlant_wait_for_completion() argument
143 ocelot, in ocelot_vlant_wait_for_completion()
150 static int ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask) in ocelot_vlant_set_mask() argument
153 ocelot_write(ocelot, ANA_TABLES_VLANTIDX_V_INDEX(vid), in ocelot_vlant_set_mask()
156 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_VLAN_PORT_MASK(mask) | in ocelot_vlant_set_mask()
160 return ocelot_vlant_wait_for_completion(ocelot); in ocelot_vlant_set_mask()
163 static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port, in ocelot_port_set_native_vlan() argument
166 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_native_vlan()
169 if (ocelot_port->vid != vid) { in ocelot_port_set_native_vlan()
171 if (ocelot_port->vid && vid) { in ocelot_port_set_native_vlan()
172 dev_err(ocelot->dev, in ocelot_port_set_native_vlan()
174 ocelot_port->vid); in ocelot_port_set_native_vlan()
175 return -EBUSY; in ocelot_port_set_native_vlan()
177 ocelot_port->vid = vid; in ocelot_port_set_native_vlan()
180 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid), in ocelot_port_set_native_vlan()
184 if (ocelot_port->vlan_aware && !ocelot_port->vid) in ocelot_port_set_native_vlan()
185 /* If port is vlan-aware and tagged, drop untagged and priority in ocelot_port_set_native_vlan()
191 ocelot_rmw_gix(ocelot, val, in ocelot_port_set_native_vlan()
197 if (ocelot_port->vlan_aware) { in ocelot_port_set_native_vlan()
198 if (ocelot_port->vid) in ocelot_port_set_native_vlan()
200 val = REW_TAG_CFG_TAG_CFG(1); in ocelot_port_set_native_vlan()
208 ocelot_rmw_gix(ocelot, val, in ocelot_port_set_native_vlan()
215 int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, in ocelot_port_vlan_filtering() argument
218 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_vlan_filtering()
222 struct ocelot_vcap_block *block = &ocelot->block[VCAP_IS1]; in ocelot_port_vlan_filtering()
225 list_for_each_entry(filter, &block->rules, list) { in ocelot_port_vlan_filtering()
226 if (filter->ingress_port_mask & BIT(port) && in ocelot_port_vlan_filtering()
227 filter->action.vid_replace_ena) { in ocelot_port_vlan_filtering()
228 dev_err(ocelot->dev, in ocelot_port_vlan_filtering()
230 return -EBUSY; in ocelot_port_vlan_filtering()
237 ocelot_port->vlan_aware = vlan_aware; in ocelot_port_vlan_filtering()
241 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1); in ocelot_port_vlan_filtering()
244 ocelot_rmw_gix(ocelot, val, in ocelot_port_vlan_filtering()
249 ocelot_port_set_native_vlan(ocelot, port, ocelot_port->vid); in ocelot_port_vlan_filtering()
256 static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, u16 pvid) in ocelot_port_set_pvid() argument
258 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_pvid()
260 ocelot_rmw_gix(ocelot, in ocelot_port_set_pvid()
265 ocelot_port->pvid = pvid; in ocelot_port_set_pvid()
268 int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, in ocelot_vlan_add() argument
274 ocelot->vlan_mask[vid] |= BIT(port); in ocelot_vlan_add()
275 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); in ocelot_vlan_add()
281 ocelot_port_set_pvid(ocelot, port, vid); in ocelot_vlan_add()
285 ret = ocelot_port_set_native_vlan(ocelot, port, vid); in ocelot_vlan_add()
294 int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid) in ocelot_vlan_del() argument
296 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_vlan_del()
300 ocelot->vlan_mask[vid] &= ~BIT(port); in ocelot_vlan_del()
301 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); in ocelot_vlan_del()
306 if (ocelot_port->pvid == vid) in ocelot_vlan_del()
307 ocelot_port_set_pvid(ocelot, port, 0); in ocelot_vlan_del()
310 if (ocelot_port->vid == vid) in ocelot_vlan_del()
311 ocelot_port_set_native_vlan(ocelot, port, 0); in ocelot_vlan_del()
317 static void ocelot_vlan_init(struct ocelot *ocelot) in ocelot_vlan_init() argument
322 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_CMD_INIT, in ocelot_vlan_init()
324 ocelot_vlant_wait_for_completion(ocelot); in ocelot_vlan_init()
327 for (vid = 1; vid < VLAN_N_VID; vid++) { in ocelot_vlan_init()
328 ocelot->vlan_mask[vid] = 0; in ocelot_vlan_init()
329 ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); in ocelot_vlan_init()
336 ocelot->vlan_mask[0] = GENMASK(ocelot->num_phys_ports - 1, 0); in ocelot_vlan_init()
337 ocelot_vlant_set_mask(ocelot, 0, ocelot->vlan_mask[0]); in ocelot_vlan_init()
342 ocelot_write(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), in ocelot_vlan_init()
345 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_vlan_init()
346 ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port); in ocelot_vlan_init()
347 ocelot_write_gix(ocelot, 0, REW_TAG_CFG, port); in ocelot_vlan_init()
351 static u32 ocelot_read_eq_avail(struct ocelot *ocelot, int port) in ocelot_read_eq_avail() argument
353 return ocelot_read_rix(ocelot, QSYS_SW_STATUS, port); in ocelot_read_eq_avail()
356 int ocelot_port_flush(struct ocelot *ocelot, int port) in ocelot_port_flush() argument
362 ocelot_rmw_rix(ocelot, QSYS_PORT_MODE_DEQUEUE_DIS, in ocelot_port_flush()
367 ocelot_fields_read(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, &pause_ena); in ocelot_port_flush()
368 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); in ocelot_port_flush()
371 ocelot_fields_write(ocelot, port, in ocelot_port_flush()
376 * Worst-case delays for 10 kilobyte jumbo frames are: in ocelot_port_flush()
379 * 80 μs on a 1G port in ocelot_port_flush()
385 ocelot_rmw_rix(ocelot, 0, SYS_FRONT_PORT_MODE_HDX_MODE, in ocelot_port_flush()
389 ocelot_rmw_gix(ocelot, REW_PORT_CFG_FLUSH_ENA, REW_PORT_CFG_FLUSH_ENA, in ocelot_port_flush()
393 ocelot_rmw_rix(ocelot, 0, QSYS_PORT_MODE_DEQUEUE_DIS, QSYS_PORT_MODE, in ocelot_port_flush()
398 100, 2000000, false, ocelot, port); in ocelot_port_flush()
401 ocelot_rmw_gix(ocelot, 0, REW_PORT_CFG_FLUSH_ENA, REW_PORT_CFG, port); in ocelot_port_flush()
403 /* Re-enable flow control */ in ocelot_port_flush()
404 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, pause_ena); in ocelot_port_flush()
410 void ocelot_adjust_link(struct ocelot *ocelot, int port, in ocelot_adjust_link() argument
413 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_adjust_link()
416 switch (phydev->speed) { in ocelot_adjust_link()
432 dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n", in ocelot_adjust_link()
433 port, phydev->speed); in ocelot_adjust_link()
439 if (!phydev->link) in ocelot_adjust_link()
474 ocelot_write_gix(ocelot, ANA_PFC_PFC_CFG_FC_LINK_SPEED(speed), in ocelot_adjust_link()
478 ocelot_fields_write(ocelot, port, in ocelot_adjust_link()
479 QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); in ocelot_adjust_link()
482 ocelot_write_rix(ocelot, SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) | in ocelot_adjust_link()
488 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port); in ocelot_adjust_link()
492 void ocelot_port_enable(struct ocelot *ocelot, int port, in ocelot_port_enable() argument
495 /* Enable receiving frames on the port, and activate auto-learning of in ocelot_port_enable()
498 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO | in ocelot_port_enable()
505 void ocelot_port_disable(struct ocelot *ocelot, int port) in ocelot_port_disable() argument
507 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_disable()
510 ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); in ocelot_port_disable()
514 void ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port, in ocelot_port_add_txtstamp_skb() argument
517 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_add_txtstamp_skb()
519 spin_lock(&ocelot_port->ts_id_lock); in ocelot_port_add_txtstamp_skb()
521 skb_shinfo(clone)->tx_flags |= SKBTX_IN_PROGRESS; in ocelot_port_add_txtstamp_skb()
523 clone->cb[0] = ocelot_port->ts_id; in ocelot_port_add_txtstamp_skb()
524 ocelot_port->ts_id = (ocelot_port->ts_id + 1) % 4; in ocelot_port_add_txtstamp_skb()
525 skb_queue_tail(&ocelot_port->tx_skbs, clone); in ocelot_port_add_txtstamp_skb()
527 spin_unlock(&ocelot_port->ts_id_lock); in ocelot_port_add_txtstamp_skb()
531 static void ocelot_get_hwtimestamp(struct ocelot *ocelot, in ocelot_get_hwtimestamp() argument
537 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_get_hwtimestamp()
540 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
544 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
545 ts->tv_sec = ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
548 val = ocelot_read(ocelot, SYS_PTP_TXSTAMP); in ocelot_get_hwtimestamp()
549 ts->tv_nsec = SYS_PTP_TXSTAMP_PTP_TXSTAMP(val); in ocelot_get_hwtimestamp()
552 if ((ts->tv_sec & 0x1) != !!(val & SYS_PTP_TXSTAMP_PTP_TXSTAMP_SEC)) in ocelot_get_hwtimestamp()
553 ts->tv_sec--; in ocelot_get_hwtimestamp()
555 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_get_hwtimestamp()
558 void ocelot_get_txtstamp(struct ocelot *ocelot) in ocelot_get_txtstamp() argument
562 while (budget--) { in ocelot_get_txtstamp()
570 val = ocelot_read(ocelot, SYS_PTP_STATUS); in ocelot_get_txtstamp()
583 port = ocelot->ports[txport]; in ocelot_get_txtstamp()
585 spin_lock_irqsave(&port->tx_skbs.lock, flags); in ocelot_get_txtstamp()
587 skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) { in ocelot_get_txtstamp()
588 if (skb->cb[0] != id) in ocelot_get_txtstamp()
590 __skb_unlink(skb, &port->tx_skbs); in ocelot_get_txtstamp()
595 spin_unlock_irqrestore(&port->tx_skbs.lock, flags); in ocelot_get_txtstamp()
601 ocelot_get_hwtimestamp(ocelot, &ts); in ocelot_get_txtstamp()
609 ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT); in ocelot_get_txtstamp()
614 int ocelot_fdb_add(struct ocelot *ocelot, int port, in ocelot_fdb_add() argument
617 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_fdb_add()
620 if (port == ocelot->npi) in ocelot_fdb_add()
624 if (!ocelot_port->vlan_aware) in ocelot_fdb_add()
629 vid = ocelot_port->pvid; in ocelot_fdb_add()
634 return -EINVAL; in ocelot_fdb_add()
637 return ocelot_mact_learn(ocelot, pgid, addr, vid, ENTRYTYPE_LOCKED); in ocelot_fdb_add()
641 int ocelot_fdb_del(struct ocelot *ocelot, int port, in ocelot_fdb_del() argument
644 return ocelot_mact_forget(ocelot, addr, vid); in ocelot_fdb_del()
652 u32 portid = NETLINK_CB(dump->cb->skb).portid; in ocelot_port_fdb_do_dump()
653 u32 seq = dump->cb->nlh->nlmsg_seq; in ocelot_port_fdb_do_dump()
657 if (dump->idx < dump->cb->args[2]) in ocelot_port_fdb_do_dump()
660 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, in ocelot_port_fdb_do_dump()
663 return -EMSGSIZE; in ocelot_port_fdb_do_dump()
666 ndm->ndm_family = AF_BRIDGE; in ocelot_port_fdb_do_dump()
667 ndm->ndm_pad1 = 0; in ocelot_port_fdb_do_dump()
668 ndm->ndm_pad2 = 0; in ocelot_port_fdb_do_dump()
669 ndm->ndm_flags = NTF_SELF; in ocelot_port_fdb_do_dump()
670 ndm->ndm_type = 0; in ocelot_port_fdb_do_dump()
671 ndm->ndm_ifindex = dump->dev->ifindex; in ocelot_port_fdb_do_dump()
672 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; in ocelot_port_fdb_do_dump()
674 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr)) in ocelot_port_fdb_do_dump()
677 if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid)) in ocelot_port_fdb_do_dump()
680 nlmsg_end(dump->skb, nlh); in ocelot_port_fdb_do_dump()
683 dump->idx++; in ocelot_port_fdb_do_dump()
687 nlmsg_cancel(dump->skb, nlh); in ocelot_port_fdb_do_dump()
688 return -EMSGSIZE; in ocelot_port_fdb_do_dump()
692 static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col, in ocelot_mact_read() argument
699 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row); in ocelot_mact_read()
700 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col); in ocelot_mact_read()
703 ocelot_write(ocelot, in ocelot_mact_read()
707 if (ocelot_mact_wait_for_completion(ocelot)) in ocelot_mact_read()
708 return -ETIMEDOUT; in ocelot_mact_read()
711 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS); in ocelot_mact_read()
713 return -EINVAL; in ocelot_mact_read()
720 return -EINVAL; in ocelot_mact_read()
723 macl = ocelot_read(ocelot, ANA_TABLES_MACLDATA); in ocelot_mact_read()
724 mach = ocelot_read(ocelot, ANA_TABLES_MACHDATA); in ocelot_mact_read()
727 mac[1] = (mach >> 0) & 0xff; in ocelot_mact_read()
733 entry->vid = (mach >> 16) & 0xfff; in ocelot_mact_read()
734 ether_addr_copy(entry->mac, mac); in ocelot_mact_read()
739 int ocelot_fdb_dump(struct ocelot *ocelot, int port, in ocelot_fdb_dump() argument
745 for (i = 0; i < ocelot->num_mact_rows; i++) { in ocelot_fdb_dump()
751 ret = ocelot_mact_read(ocelot, port, i, j, &entry); in ocelot_fdb_dump()
755 if (ret == -EINVAL) in ocelot_fdb_dump()
772 int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr) in ocelot_hwstamp_get() argument
774 return copy_to_user(ifr->ifr_data, &ocelot->hwtstamp_config, in ocelot_hwstamp_get()
775 sizeof(ocelot->hwtstamp_config)) ? -EFAULT : 0; in ocelot_hwstamp_get()
779 int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr) in ocelot_hwstamp_set() argument
781 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_hwstamp_set()
784 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) in ocelot_hwstamp_set()
785 return -EFAULT; in ocelot_hwstamp_set()
789 return -EINVAL; in ocelot_hwstamp_set()
794 ocelot_port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP; in ocelot_hwstamp_set()
800 ocelot_port->ptp_cmd = IFH_REW_OP_ORIGIN_PTP; in ocelot_hwstamp_set()
803 ocelot_port->ptp_cmd = 0; in ocelot_hwstamp_set()
806 return -ERANGE; in ocelot_hwstamp_set()
809 mutex_lock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
826 mutex_unlock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
827 return -ERANGE; in ocelot_hwstamp_set()
831 memcpy(&ocelot->hwtstamp_config, &cfg, sizeof(cfg)); in ocelot_hwstamp_set()
832 mutex_unlock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
834 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; in ocelot_hwstamp_set()
838 void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data) in ocelot_get_strings() argument
845 for (i = 0; i < ocelot->num_stats; i++) in ocelot_get_strings()
846 memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name, in ocelot_get_strings()
851 static void ocelot_update_stats(struct ocelot *ocelot) in ocelot_update_stats() argument
855 mutex_lock(&ocelot->stats_lock); in ocelot_update_stats()
857 for (i = 0; i < ocelot->num_phys_ports; i++) { in ocelot_update_stats()
859 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG); in ocelot_update_stats()
861 for (j = 0; j < ocelot->num_stats; j++) { in ocelot_update_stats()
863 unsigned int idx = i * ocelot->num_stats + j; in ocelot_update_stats()
865 val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS, in ocelot_update_stats()
866 ocelot->stats_layout[j].offset); in ocelot_update_stats()
868 if (val < (ocelot->stats[idx] & U32_MAX)) in ocelot_update_stats()
869 ocelot->stats[idx] += (u64)1 << 32; in ocelot_update_stats()
871 ocelot->stats[idx] = (ocelot->stats[idx] & in ocelot_update_stats()
876 mutex_unlock(&ocelot->stats_lock); in ocelot_update_stats()
882 struct ocelot *ocelot = container_of(del_work, struct ocelot, in ocelot_check_stats_work() local
885 ocelot_update_stats(ocelot); in ocelot_check_stats_work()
887 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, in ocelot_check_stats_work()
891 void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data) in ocelot_get_ethtool_stats() argument
896 ocelot_update_stats(ocelot); in ocelot_get_ethtool_stats()
899 for (i = 0; i < ocelot->num_stats; i++) in ocelot_get_ethtool_stats()
900 *data++ = ocelot->stats[port * ocelot->num_stats + i]; in ocelot_get_ethtool_stats()
904 int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset) in ocelot_get_sset_count() argument
907 return -EOPNOTSUPP; in ocelot_get_sset_count()
909 return ocelot->num_stats; in ocelot_get_sset_count()
913 int ocelot_get_ts_info(struct ocelot *ocelot, int port, in ocelot_get_ts_info() argument
916 info->phc_index = ocelot->ptp_clock ? in ocelot_get_ts_info()
917 ptp_clock_index(ocelot->ptp_clock) : -1; in ocelot_get_ts_info()
918 if (info->phc_index == -1) { in ocelot_get_ts_info()
919 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE | in ocelot_get_ts_info()
924 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE | in ocelot_get_ts_info()
930 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON) | in ocelot_get_ts_info()
932 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | in ocelot_get_ts_info()
941 void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) in ocelot_bridge_stp_state_set() argument
946 if (!(BIT(port) & ocelot->bridge_mask)) in ocelot_bridge_stp_state_set()
949 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); in ocelot_bridge_stp_state_set()
953 ocelot->bridge_fwd_mask |= BIT(port); in ocelot_bridge_stp_state_set()
961 ocelot->bridge_fwd_mask &= ~BIT(port); in ocelot_bridge_stp_state_set()
965 ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port); in ocelot_bridge_stp_state_set()
970 for (p = 0; p < ocelot->num_phys_ports; p++) { in ocelot_bridge_stp_state_set()
971 if (ocelot->bridge_fwd_mask & BIT(p)) { in ocelot_bridge_stp_state_set()
972 unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p); in ocelot_bridge_stp_state_set()
974 for (i = 0; i < ocelot->num_phys_ports; i++) { in ocelot_bridge_stp_state_set()
975 unsigned long bond_mask = ocelot->lags[i]; in ocelot_bridge_stp_state_set()
986 ocelot_write_rix(ocelot, mask, in ocelot_bridge_stp_state_set()
989 ocelot_write_rix(ocelot, 0, in ocelot_bridge_stp_state_set()
996 void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs) in ocelot_set_ageing_time() argument
1004 age_period = 1; in ocelot_set_ageing_time()
1006 ocelot_rmw(ocelot, age_period, ANA_AUTOAGE_AGE_PERIOD_M, ANA_AUTOAGE); in ocelot_set_ageing_time()
1010 static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot, in ocelot_multicast_get() argument
1016 list_for_each_entry(mc, &ocelot->multicast, list) { in ocelot_multicast_get()
1017 if (ether_addr_equal(mc->addr, addr) && mc->vid == vid) in ocelot_multicast_get()
1026 if (addr[0] == 0x01 && addr[1] == 0x00 && addr[2] == 0x5e) in ocelot_classify_mdb()
1028 if (addr[0] == 0x33 && addr[1] == 0x33) in ocelot_classify_mdb()
1033 static int ocelot_mdb_get_pgid(struct ocelot *ocelot, in ocelot_mdb_get_pgid() argument
1047 for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) { in ocelot_mdb_get_pgid()
1051 list_for_each_entry(mc, &ocelot->multicast, list) { in ocelot_mdb_get_pgid()
1052 if (mc->pgid == pgid) { in ocelot_mdb_get_pgid()
1062 return -1; in ocelot_mdb_get_pgid()
1069 memcpy(addr, mc->addr, ETH_ALEN); in ocelot_encode_ports_to_mdb()
1073 addr[1] = mc->ports >> 8; in ocelot_encode_ports_to_mdb()
1074 addr[2] = mc->ports & 0xff; in ocelot_encode_ports_to_mdb()
1076 addr[0] = mc->ports >> 8; in ocelot_encode_ports_to_mdb()
1077 addr[1] = mc->ports & 0xff; in ocelot_encode_ports_to_mdb()
1081 int ocelot_port_mdb_add(struct ocelot *ocelot, int port, in ocelot_port_mdb_add() argument
1084 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_mdb_add()
1088 u16 vid = mdb->vid; in ocelot_port_mdb_add()
1091 if (port == ocelot->npi) in ocelot_port_mdb_add()
1092 port = ocelot->num_phys_ports; in ocelot_port_mdb_add()
1095 vid = ocelot_port->pvid; in ocelot_port_mdb_add()
1097 entry_type = ocelot_classify_mdb(mdb->addr); in ocelot_port_mdb_add()
1099 mc = ocelot_multicast_get(ocelot, mdb->addr, vid); in ocelot_port_mdb_add()
1101 int pgid = ocelot_mdb_get_pgid(ocelot, entry_type); in ocelot_port_mdb_add()
1104 dev_err(ocelot->dev, in ocelot_port_mdb_add()
1106 mdb->addr, vid); in ocelot_port_mdb_add()
1107 return -ENOSPC; in ocelot_port_mdb_add()
1110 mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL); in ocelot_port_mdb_add()
1112 return -ENOMEM; in ocelot_port_mdb_add()
1114 memcpy(mc->addr, mdb->addr, ETH_ALEN); in ocelot_port_mdb_add()
1115 mc->vid = vid; in ocelot_port_mdb_add()
1116 mc->pgid = pgid; in ocelot_port_mdb_add()
1118 list_add_tail(&mc->list, &ocelot->multicast); in ocelot_port_mdb_add()
1124 ocelot_mact_forget(ocelot, addr, vid); in ocelot_port_mdb_add()
1127 mc->ports |= BIT(port); in ocelot_port_mdb_add()
1130 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type); in ocelot_port_mdb_add()
1134 int ocelot_port_mdb_del(struct ocelot *ocelot, int port, in ocelot_port_mdb_del() argument
1137 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_mdb_del()
1141 u16 vid = mdb->vid; in ocelot_port_mdb_del()
1143 if (port == ocelot->npi) in ocelot_port_mdb_del()
1144 port = ocelot->num_phys_ports; in ocelot_port_mdb_del()
1147 vid = ocelot_port->pvid; in ocelot_port_mdb_del()
1149 mc = ocelot_multicast_get(ocelot, mdb->addr, vid); in ocelot_port_mdb_del()
1151 return -ENOENT; in ocelot_port_mdb_del()
1153 entry_type = ocelot_classify_mdb(mdb->addr); in ocelot_port_mdb_del()
1156 ocelot_mact_forget(ocelot, addr, vid); in ocelot_port_mdb_del()
1158 mc->ports &= ~BIT(port); in ocelot_port_mdb_del()
1159 if (!mc->ports) { in ocelot_port_mdb_del()
1160 list_del(&mc->list); in ocelot_port_mdb_del()
1161 devm_kfree(ocelot->dev, mc); in ocelot_port_mdb_del()
1167 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type); in ocelot_port_mdb_del()
1171 int ocelot_port_bridge_join(struct ocelot *ocelot, int port, in ocelot_port_bridge_join() argument
1174 if (!ocelot->bridge_mask) { in ocelot_port_bridge_join()
1175 ocelot->hw_bridge_dev = bridge; in ocelot_port_bridge_join()
1177 if (ocelot->hw_bridge_dev != bridge) in ocelot_port_bridge_join()
1180 return -ENODEV; in ocelot_port_bridge_join()
1183 ocelot->bridge_mask |= BIT(port); in ocelot_port_bridge_join()
1189 int ocelot_port_bridge_leave(struct ocelot *ocelot, int port, in ocelot_port_bridge_leave() argument
1195 ocelot->bridge_mask &= ~BIT(port); in ocelot_port_bridge_leave()
1197 if (!ocelot->bridge_mask) in ocelot_port_bridge_leave()
1198 ocelot->hw_bridge_dev = NULL; in ocelot_port_bridge_leave()
1201 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans); in ocelot_port_bridge_leave()
1206 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans); in ocelot_port_bridge_leave()
1210 ocelot_port_set_pvid(ocelot, port, 0); in ocelot_port_bridge_leave()
1211 return ocelot_port_set_native_vlan(ocelot, port, 0); in ocelot_port_bridge_leave()
1215 static void ocelot_set_aggr_pgids(struct ocelot *ocelot) in ocelot_set_aggr_pgids() argument
1220 for_each_unicast_dest_pgid(ocelot, port) in ocelot_set_aggr_pgids()
1221 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); in ocelot_set_aggr_pgids()
1223 for_each_aggr_pgid(ocelot, i) in ocelot_set_aggr_pgids()
1224 ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), in ocelot_set_aggr_pgids()
1228 for (lag = 0; lag < ocelot->num_phys_ports; lag++) { in ocelot_set_aggr_pgids()
1233 bond_mask = ocelot->lags[lag]; in ocelot_set_aggr_pgids()
1237 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { in ocelot_set_aggr_pgids()
1239 ocelot_write_rix(ocelot, bond_mask, in ocelot_set_aggr_pgids()
1245 for_each_aggr_pgid(ocelot, i) { in ocelot_set_aggr_pgids()
1248 ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i); in ocelot_set_aggr_pgids()
1251 ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); in ocelot_set_aggr_pgids()
1256 static void ocelot_setup_lag(struct ocelot *ocelot, int lag) in ocelot_setup_lag() argument
1258 unsigned long bond_mask = ocelot->lags[lag]; in ocelot_setup_lag()
1261 for_each_set_bit(p, &bond_mask, ocelot->num_phys_ports) { in ocelot_setup_lag()
1262 u32 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p); in ocelot_setup_lag()
1267 ocelot_write_gix(ocelot, port_cfg | in ocelot_setup_lag()
1273 int ocelot_port_lag_join(struct ocelot *ocelot, int port, in ocelot_port_lag_join() argument
1284 bond_mask |= BIT(priv->chip_port); in ocelot_port_lag_join()
1295 ocelot->lags[port] = bond_mask; in ocelot_port_lag_join()
1299 ocelot->lags[lp] = 0; in ocelot_port_lag_join()
1303 ocelot->lags[lp] |= BIT(port); in ocelot_port_lag_join()
1306 ocelot_setup_lag(ocelot, lag); in ocelot_port_lag_join()
1307 ocelot_set_aggr_pgids(ocelot); in ocelot_port_lag_join()
1313 void ocelot_port_lag_leave(struct ocelot *ocelot, int port, in ocelot_port_lag_leave() argument
1320 for (i = 0; i < ocelot->num_phys_ports; i++) in ocelot_port_lag_leave()
1321 ocelot->lags[i] &= ~BIT(port); in ocelot_port_lag_leave()
1326 if (ocelot->lags[port]) { in ocelot_port_lag_leave()
1327 int n = __ffs(ocelot->lags[port]); in ocelot_port_lag_leave()
1329 ocelot->lags[n] = ocelot->lags[port]; in ocelot_port_lag_leave()
1330 ocelot->lags[port] = 0; in ocelot_port_lag_leave()
1332 ocelot_setup_lag(ocelot, n); in ocelot_port_lag_leave()
1335 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); in ocelot_port_lag_leave()
1337 ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port), in ocelot_port_lag_leave()
1340 ocelot_set_aggr_pgids(ocelot); in ocelot_port_lag_leave()
1350 void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu) in ocelot_port_set_maxlen() argument
1352 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_maxlen()
1357 if (port == ocelot->npi) { in ocelot_port_set_maxlen()
1360 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT) in ocelot_port_set_maxlen()
1362 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG) in ocelot_port_set_maxlen()
1371 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_START, in ocelot_port_set_maxlen()
1373 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_STOP, in ocelot_port_set_maxlen()
1377 atop_tot = (ocelot->shared_queue_sz - 9 * maxlen) / in ocelot_port_set_maxlen()
1380 ocelot_write_rix(ocelot, ocelot->ops->wm_enc(atop), SYS_ATOP, port); in ocelot_port_set_maxlen()
1381 ocelot_write(ocelot, ocelot->ops->wm_enc(atop_tot), SYS_ATOP_TOT_CFG); in ocelot_port_set_maxlen()
1385 int ocelot_get_max_mtu(struct ocelot *ocelot, int port) in ocelot_get_max_mtu() argument
1387 int max_mtu = 65535 - ETH_HLEN - ETH_FCS_LEN; in ocelot_get_max_mtu()
1389 if (port == ocelot->npi) { in ocelot_get_max_mtu()
1390 max_mtu -= OCELOT_TAG_LEN; in ocelot_get_max_mtu()
1392 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT) in ocelot_get_max_mtu()
1393 max_mtu -= OCELOT_SHORT_PREFIX_LEN; in ocelot_get_max_mtu()
1394 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG) in ocelot_get_max_mtu()
1395 max_mtu -= OCELOT_LONG_PREFIX_LEN; in ocelot_get_max_mtu()
1402 void ocelot_init_port(struct ocelot *ocelot, int port) in ocelot_init_port() argument
1404 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_init_port()
1406 skb_queue_head_init(&ocelot_port->tx_skbs); in ocelot_init_port()
1407 spin_lock_init(&ocelot_port->ts_id_lock); in ocelot_init_port()
1422 mdelay(1); in ocelot_init_port()
1427 ocelot_port_set_maxlen(ocelot, port, ETH_DATA_LEN); in ocelot_init_port()
1439 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); in ocelot_init_port()
1442 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA, in ocelot_init_port()
1447 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q), in ocelot_init_port()
1452 ocelot_vcap_enable(ocelot, port); in ocelot_init_port()
1460 static void ocelot_cpu_port_init(struct ocelot *ocelot) in ocelot_cpu_port_init() argument
1462 int cpu = ocelot->num_phys_ports; in ocelot_cpu_port_init()
1465 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu); in ocelot_cpu_port_init()
1470 ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU); in ocelot_cpu_port_init()
1471 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA | in ocelot_cpu_port_init()
1476 ocelot_fields_write(ocelot, cpu, QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); in ocelot_cpu_port_init()
1478 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_XTR_HDR, in ocelot_cpu_port_init()
1479 ocelot->xtr_prefix); in ocelot_cpu_port_init()
1480 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_INJ_HDR, in ocelot_cpu_port_init()
1481 ocelot->inj_prefix); in ocelot_cpu_port_init()
1484 ocelot_write_gix(ocelot, ANA_PORT_VLAN_CFG_VLAN_VID(0) | in ocelot_cpu_port_init()
1486 ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1), in ocelot_cpu_port_init()
1490 int ocelot_init(struct ocelot *ocelot) in ocelot_init() argument
1496 if (ocelot->ops->reset) { in ocelot_init()
1497 ret = ocelot->ops->reset(ocelot); in ocelot_init()
1499 dev_err(ocelot->dev, "Switch reset failed\n"); in ocelot_init()
1504 ocelot->lags = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, in ocelot_init()
1506 if (!ocelot->lags) in ocelot_init()
1507 return -ENOMEM; in ocelot_init()
1509 ocelot->stats = devm_kcalloc(ocelot->dev, in ocelot_init()
1510 ocelot->num_phys_ports * ocelot->num_stats, in ocelot_init()
1512 if (!ocelot->stats) in ocelot_init()
1513 return -ENOMEM; in ocelot_init()
1515 mutex_init(&ocelot->stats_lock); in ocelot_init()
1516 mutex_init(&ocelot->ptp_lock); in ocelot_init()
1517 spin_lock_init(&ocelot->ptp_clock_lock); in ocelot_init()
1518 snprintf(queue_name, sizeof(queue_name), "%s-stats", in ocelot_init()
1519 dev_name(ocelot->dev)); in ocelot_init()
1520 ocelot->stats_queue = create_singlethread_workqueue(queue_name); in ocelot_init()
1521 if (!ocelot->stats_queue) in ocelot_init()
1522 return -ENOMEM; in ocelot_init()
1524 INIT_LIST_HEAD(&ocelot->multicast); in ocelot_init()
1525 ocelot_mact_init(ocelot); in ocelot_init()
1526 ocelot_vlan_init(ocelot); in ocelot_init()
1527 ocelot_vcap_init(ocelot); in ocelot_init()
1528 ocelot_cpu_port_init(ocelot); in ocelot_init()
1530 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_init()
1532 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) | in ocelot_init()
1537 /* Only use S-Tag */ in ocelot_init()
1538 ocelot_write(ocelot, ETH_P_8021AD, SYS_VLAN_ETYPE_CFG); in ocelot_init()
1541 ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA | in ocelot_init()
1549 ocelot_write(ocelot, in ocelot_init()
1554 regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1); in ocelot_init()
1556 /* Setup frame ageing - fixed value "2 sec" - in 6.5 us units */ in ocelot_init()
1557 ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA | in ocelot_init()
1561 for (i = 0; i < ocelot->num_flooding_pgids; i++) in ocelot_init()
1562 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) | in ocelot_init()
1566 ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) | in ocelot_init()
1572 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_init()
1574 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); in ocelot_init()
1576 ocelot_write_gix(ocelot, in ocelot_init()
1581 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port); in ocelot_init()
1585 for_each_nonreserved_multicast_dest_pgid(ocelot, i) { in ocelot_init()
1586 u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0)); in ocelot_init()
1588 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i); in ocelot_init()
1590 ocelot_write_rix(ocelot, in ocelot_init()
1591 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), in ocelot_init()
1593 ocelot_write_rix(ocelot, in ocelot_init()
1594 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), in ocelot_init()
1596 ocelot_write_rix(ocelot, in ocelot_init()
1597 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), in ocelot_init()
1603 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_BYTE_SWAP | in ocelot_init()
1604 QS_INJ_GRP_CFG_MODE(1), QS_INJ_GRP_CFG, 0); in ocelot_init()
1605 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_BYTE_SWAP | in ocelot_init()
1606 QS_XTR_GRP_CFG_MODE(1), QS_XTR_GRP_CFG, 0); in ocelot_init()
1607 ocelot_write(ocelot, ANA_CPUQ_CFG_CPUQ_MIRROR(2) | in ocelot_init()
1617 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) | in ocelot_init()
1621 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work); in ocelot_init()
1622 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, in ocelot_init()
1629 void ocelot_deinit(struct ocelot *ocelot) in ocelot_deinit() argument
1631 cancel_delayed_work(&ocelot->stats_work); in ocelot_deinit()
1632 destroy_workqueue(ocelot->stats_queue); in ocelot_deinit()
1633 mutex_destroy(&ocelot->stats_lock); in ocelot_deinit()
1637 void ocelot_deinit_port(struct ocelot *ocelot, int port) in ocelot_deinit_port() argument
1639 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_deinit_port()
1641 skb_queue_purge(&ocelot_port->tx_skbs); in ocelot_deinit_port()