Lines Matching full:ocelot
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
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
63 ocelot_mact_select(ocelot, mac, vid); in ocelot_mact_learn()
66 ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID | in ocelot_mact_learn()
72 return ocelot_mact_wait_for_completion(ocelot); in ocelot_mact_learn()
76 int ocelot_mact_forget(struct ocelot *ocelot, in ocelot_mact_forget() argument
79 ocelot_mact_select(ocelot, mac, vid); in ocelot_mact_forget()
82 ocelot_write(ocelot, in ocelot_mact_forget()
86 return ocelot_mact_wait_for_completion(ocelot); in ocelot_mact_forget()
90 static void ocelot_mact_init(struct ocelot *ocelot) in ocelot_mact_init() argument
96 ocelot_rmw(ocelot, 0, in ocelot_mact_init()
103 ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS); in ocelot_mact_init()
106 static void ocelot_vcap_enable(struct ocelot *ocelot, int port) in ocelot_vcap_enable() argument
108 ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA | in ocelot_vcap_enable()
112 ocelot_write_gix(ocelot, ANA_PORT_VCAP_CFG_S1_ENA, in ocelot_vcap_enable()
115 ocelot_rmw_gix(ocelot, REW_PORT_CFG_ES0_EN, in ocelot_vcap_enable()
120 static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot) in ocelot_vlant_read_vlanaccess() argument
122 return ocelot_read(ocelot, ANA_TABLES_VLANACCESS); in ocelot_vlant_read_vlanaccess()
125 static inline int ocelot_vlant_wait_for_completion(struct ocelot *ocelot) in ocelot_vlant_wait_for_completion() argument
130 ocelot, in ocelot_vlant_wait_for_completion()
137 static int ocelot_vlant_set_mask(struct ocelot *ocelot, u16 vid, u32 mask) in ocelot_vlant_set_mask() argument
140 ocelot_write(ocelot, ANA_TABLES_VLANTIDX_V_INDEX(vid), in ocelot_vlant_set_mask()
143 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_VLAN_PORT_MASK(mask) | in ocelot_vlant_set_mask()
147 return ocelot_vlant_wait_for_completion(ocelot); in ocelot_vlant_set_mask()
150 static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port, in ocelot_port_set_native_vlan() argument
153 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_native_vlan()
159 dev_err(ocelot->dev, in ocelot_port_set_native_vlan()
167 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid), in ocelot_port_set_native_vlan()
178 ocelot_rmw_gix(ocelot, val, in ocelot_port_set_native_vlan()
195 ocelot_rmw_gix(ocelot, val, in ocelot_port_set_native_vlan()
202 int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, in ocelot_port_vlan_filtering() argument
205 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_vlan_filtering()
209 struct ocelot_vcap_block *block = &ocelot->block[VCAP_IS1]; in ocelot_port_vlan_filtering()
215 dev_err(ocelot->dev, in ocelot_port_vlan_filtering()
231 ocelot_rmw_gix(ocelot, val, in ocelot_port_vlan_filtering()
236 ocelot_port_set_native_vlan(ocelot, port, ocelot_port->vid); in ocelot_port_vlan_filtering()
243 static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, u16 pvid) in ocelot_port_set_pvid() argument
245 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_pvid()
247 ocelot_rmw_gix(ocelot, in ocelot_port_set_pvid()
255 int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, in ocelot_vlan_add() argument
261 ocelot->vlan_mask[vid] |= BIT(port); in ocelot_vlan_add()
262 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); in ocelot_vlan_add()
268 ocelot_port_set_pvid(ocelot, port, vid); in ocelot_vlan_add()
272 ret = ocelot_port_set_native_vlan(ocelot, port, vid); in ocelot_vlan_add()
281 int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid) in ocelot_vlan_del() argument
283 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_vlan_del()
287 ocelot->vlan_mask[vid] &= ~BIT(port); in ocelot_vlan_del()
288 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); in ocelot_vlan_del()
294 ocelot_port_set_pvid(ocelot, port, 0); in ocelot_vlan_del()
298 ocelot_port_set_native_vlan(ocelot, port, 0); in ocelot_vlan_del()
304 static void ocelot_vlan_init(struct ocelot *ocelot) in ocelot_vlan_init() argument
309 ocelot_write(ocelot, ANA_TABLES_VLANACCESS_CMD_INIT, in ocelot_vlan_init()
311 ocelot_vlant_wait_for_completion(ocelot); in ocelot_vlan_init()
315 ocelot->vlan_mask[vid] = 0; in ocelot_vlan_init()
316 ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); in ocelot_vlan_init()
323 ocelot->vlan_mask[0] = GENMASK(ocelot->num_phys_ports - 1, 0); in ocelot_vlan_init()
324 ocelot_vlant_set_mask(ocelot, 0, ocelot->vlan_mask[0]); in ocelot_vlan_init()
329 ocelot_write(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), in ocelot_vlan_init()
332 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_vlan_init()
333 ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port); in ocelot_vlan_init()
334 ocelot_write_gix(ocelot, 0, REW_TAG_CFG, port); in ocelot_vlan_init()
338 void ocelot_adjust_link(struct ocelot *ocelot, int port, in ocelot_adjust_link() argument
341 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_adjust_link()
360 dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n", in ocelot_adjust_link()
402 ocelot_write_gix(ocelot, ANA_PFC_PFC_CFG_FC_LINK_SPEED(speed), in ocelot_adjust_link()
406 ocelot_fields_write(ocelot, port, in ocelot_adjust_link()
410 ocelot_write_rix(ocelot, SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) | in ocelot_adjust_link()
416 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port); in ocelot_adjust_link()
420 void ocelot_port_enable(struct ocelot *ocelot, int port, in ocelot_port_enable() argument
426 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO | in ocelot_port_enable()
433 void ocelot_port_disable(struct ocelot *ocelot, int port) in ocelot_port_disable() argument
435 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_disable()
438 ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); in ocelot_port_disable()
442 void ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port, in ocelot_port_add_txtstamp_skb() argument
445 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_add_txtstamp_skb()
459 static void ocelot_get_hwtimestamp(struct ocelot *ocelot, in ocelot_get_hwtimestamp() argument
465 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_get_hwtimestamp()
468 val = ocelot_read_rix(ocelot, PTP_PIN_CFG, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
472 ocelot_write_rix(ocelot, val, PTP_PIN_CFG, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
473 ts->tv_sec = ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
476 val = ocelot_read(ocelot, SYS_PTP_TXSTAMP); in ocelot_get_hwtimestamp()
483 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_get_hwtimestamp()
486 void ocelot_get_txtstamp(struct ocelot *ocelot) in ocelot_get_txtstamp() argument
498 val = ocelot_read(ocelot, SYS_PTP_STATUS); in ocelot_get_txtstamp()
511 port = ocelot->ports[txport]; in ocelot_get_txtstamp()
526 ocelot_get_hwtimestamp(ocelot, &ts); in ocelot_get_txtstamp()
537 ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT); in ocelot_get_txtstamp()
542 int ocelot_fdb_add(struct ocelot *ocelot, int port, in ocelot_fdb_add() argument
545 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_fdb_add()
548 if (port == ocelot->npi) in ocelot_fdb_add()
565 return ocelot_mact_learn(ocelot, pgid, addr, vid, ENTRYTYPE_LOCKED); in ocelot_fdb_add()
569 int ocelot_fdb_del(struct ocelot *ocelot, int port, in ocelot_fdb_del() argument
572 return ocelot_mact_forget(ocelot, addr, vid); in ocelot_fdb_del()
620 static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col, in ocelot_mact_read() argument
627 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row); in ocelot_mact_read()
628 ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col); in ocelot_mact_read()
631 ocelot_write(ocelot, in ocelot_mact_read()
635 if (ocelot_mact_wait_for_completion(ocelot)) in ocelot_mact_read()
639 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS); in ocelot_mact_read()
651 macl = ocelot_read(ocelot, ANA_TABLES_MACLDATA); in ocelot_mact_read()
652 mach = ocelot_read(ocelot, ANA_TABLES_MACHDATA); in ocelot_mact_read()
667 int ocelot_fdb_dump(struct ocelot *ocelot, int port, in ocelot_fdb_dump() argument
673 for (i = 0; i < ocelot->num_mact_rows; i++) { in ocelot_fdb_dump()
679 ret = ocelot_mact_read(ocelot, port, i, j, &entry); in ocelot_fdb_dump()
700 int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr) in ocelot_hwstamp_get() argument
702 return copy_to_user(ifr->ifr_data, &ocelot->hwtstamp_config, in ocelot_hwstamp_get()
703 sizeof(ocelot->hwtstamp_config)) ? -EFAULT : 0; in ocelot_hwstamp_get()
707 int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr) in ocelot_hwstamp_set() argument
709 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_hwstamp_set()
737 mutex_lock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
760 mutex_unlock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
765 memcpy(&ocelot->hwtstamp_config, &cfg, sizeof(cfg)); in ocelot_hwstamp_set()
766 mutex_unlock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
772 void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data) in ocelot_get_strings() argument
779 for (i = 0; i < ocelot->num_stats; i++) in ocelot_get_strings()
780 memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name, in ocelot_get_strings()
785 static void ocelot_update_stats(struct ocelot *ocelot) in ocelot_update_stats() argument
789 mutex_lock(&ocelot->stats_lock); in ocelot_update_stats()
791 for (i = 0; i < ocelot->num_phys_ports; i++) { in ocelot_update_stats()
793 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG); in ocelot_update_stats()
795 for (j = 0; j < ocelot->num_stats; j++) { in ocelot_update_stats()
797 unsigned int idx = i * ocelot->num_stats + j; in ocelot_update_stats()
799 val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS, in ocelot_update_stats()
800 ocelot->stats_layout[j].offset); in ocelot_update_stats()
802 if (val < (ocelot->stats[idx] & U32_MAX)) in ocelot_update_stats()
803 ocelot->stats[idx] += (u64)1 << 32; in ocelot_update_stats()
805 ocelot->stats[idx] = (ocelot->stats[idx] & in ocelot_update_stats()
810 mutex_unlock(&ocelot->stats_lock); in ocelot_update_stats()
816 struct ocelot *ocelot = container_of(del_work, struct ocelot, in ocelot_check_stats_work() local
819 ocelot_update_stats(ocelot); in ocelot_check_stats_work()
821 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, in ocelot_check_stats_work()
825 void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data) in ocelot_get_ethtool_stats() argument
830 ocelot_update_stats(ocelot); in ocelot_get_ethtool_stats()
833 for (i = 0; i < ocelot->num_stats; i++) in ocelot_get_ethtool_stats()
834 *data++ = ocelot->stats[port * ocelot->num_stats + i]; in ocelot_get_ethtool_stats()
838 int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset) in ocelot_get_sset_count() argument
843 return ocelot->num_stats; in ocelot_get_sset_count()
847 int ocelot_get_ts_info(struct ocelot *ocelot, int port, in ocelot_get_ts_info() argument
850 info->phc_index = ocelot->ptp_clock ? in ocelot_get_ts_info()
851 ptp_clock_index(ocelot->ptp_clock) : -1; in ocelot_get_ts_info()
872 void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) in ocelot_bridge_stp_state_set() argument
877 if (!(BIT(port) & ocelot->bridge_mask)) in ocelot_bridge_stp_state_set()
880 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); in ocelot_bridge_stp_state_set()
884 ocelot->bridge_fwd_mask |= BIT(port); in ocelot_bridge_stp_state_set()
892 ocelot->bridge_fwd_mask &= ~BIT(port); in ocelot_bridge_stp_state_set()
896 ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port); in ocelot_bridge_stp_state_set()
901 for (p = 0; p < ocelot->num_phys_ports; p++) { in ocelot_bridge_stp_state_set()
902 if (ocelot->bridge_fwd_mask & BIT(p)) { in ocelot_bridge_stp_state_set()
903 unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p); in ocelot_bridge_stp_state_set()
905 for (i = 0; i < ocelot->num_phys_ports; i++) { in ocelot_bridge_stp_state_set()
906 unsigned long bond_mask = ocelot->lags[i]; in ocelot_bridge_stp_state_set()
917 ocelot_write_rix(ocelot, mask, in ocelot_bridge_stp_state_set()
920 ocelot_write_rix(ocelot, 0, in ocelot_bridge_stp_state_set()
927 void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs) in ocelot_set_ageing_time() argument
937 ocelot_rmw(ocelot, age_period, ANA_AUTOAGE_AGE_PERIOD_M, ANA_AUTOAGE); in ocelot_set_ageing_time()
941 static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot, in ocelot_multicast_get() argument
947 list_for_each_entry(mc, &ocelot->multicast, list) { in ocelot_multicast_get()
964 static int ocelot_mdb_get_pgid(struct ocelot *ocelot, in ocelot_mdb_get_pgid() argument
978 for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) { in ocelot_mdb_get_pgid()
982 list_for_each_entry(mc, &ocelot->multicast, list) { in ocelot_mdb_get_pgid()
1012 int ocelot_port_mdb_add(struct ocelot *ocelot, int port, in ocelot_port_mdb_add() argument
1015 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_mdb_add()
1022 if (port == ocelot->npi) in ocelot_port_mdb_add()
1023 port = ocelot->num_phys_ports; in ocelot_port_mdb_add()
1030 mc = ocelot_multicast_get(ocelot, mdb->addr, vid); in ocelot_port_mdb_add()
1032 int pgid = ocelot_mdb_get_pgid(ocelot, entry_type); in ocelot_port_mdb_add()
1035 dev_err(ocelot->dev, in ocelot_port_mdb_add()
1041 mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL); in ocelot_port_mdb_add()
1049 list_add_tail(&mc->list, &ocelot->multicast); in ocelot_port_mdb_add()
1055 ocelot_mact_forget(ocelot, addr, vid); in ocelot_port_mdb_add()
1061 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type); in ocelot_port_mdb_add()
1065 int ocelot_port_mdb_del(struct ocelot *ocelot, int port, in ocelot_port_mdb_del() argument
1068 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_mdb_del()
1074 if (port == ocelot->npi) in ocelot_port_mdb_del()
1075 port = ocelot->num_phys_ports; in ocelot_port_mdb_del()
1080 mc = ocelot_multicast_get(ocelot, mdb->addr, vid); in ocelot_port_mdb_del()
1087 ocelot_mact_forget(ocelot, addr, vid); in ocelot_port_mdb_del()
1092 devm_kfree(ocelot->dev, mc); in ocelot_port_mdb_del()
1098 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type); in ocelot_port_mdb_del()
1102 int ocelot_port_bridge_join(struct ocelot *ocelot, int port, in ocelot_port_bridge_join() argument
1105 if (!ocelot->bridge_mask) { in ocelot_port_bridge_join()
1106 ocelot->hw_bridge_dev = bridge; in ocelot_port_bridge_join()
1108 if (ocelot->hw_bridge_dev != bridge) in ocelot_port_bridge_join()
1114 ocelot->bridge_mask |= BIT(port); in ocelot_port_bridge_join()
1120 int ocelot_port_bridge_leave(struct ocelot *ocelot, int port, in ocelot_port_bridge_leave() argument
1126 ocelot->bridge_mask &= ~BIT(port); in ocelot_port_bridge_leave()
1128 if (!ocelot->bridge_mask) in ocelot_port_bridge_leave()
1129 ocelot->hw_bridge_dev = NULL; in ocelot_port_bridge_leave()
1132 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans); in ocelot_port_bridge_leave()
1137 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans); in ocelot_port_bridge_leave()
1141 ocelot_port_set_pvid(ocelot, port, 0); in ocelot_port_bridge_leave()
1142 return ocelot_port_set_native_vlan(ocelot, port, 0); in ocelot_port_bridge_leave()
1146 static void ocelot_set_aggr_pgids(struct ocelot *ocelot) in ocelot_set_aggr_pgids() argument
1151 for_each_unicast_dest_pgid(ocelot, port) in ocelot_set_aggr_pgids()
1152 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); in ocelot_set_aggr_pgids()
1154 for_each_aggr_pgid(ocelot, i) in ocelot_set_aggr_pgids()
1155 ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), in ocelot_set_aggr_pgids()
1159 for (lag = 0; lag < ocelot->num_phys_ports; lag++) { in ocelot_set_aggr_pgids()
1164 bond_mask = ocelot->lags[lag]; in ocelot_set_aggr_pgids()
1168 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { in ocelot_set_aggr_pgids()
1170 ocelot_write_rix(ocelot, bond_mask, in ocelot_set_aggr_pgids()
1176 for_each_aggr_pgid(ocelot, i) { in ocelot_set_aggr_pgids()
1179 ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i); in ocelot_set_aggr_pgids()
1182 ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); in ocelot_set_aggr_pgids()
1187 static void ocelot_setup_lag(struct ocelot *ocelot, int lag) in ocelot_setup_lag() argument
1189 unsigned long bond_mask = ocelot->lags[lag]; in ocelot_setup_lag()
1192 for_each_set_bit(p, &bond_mask, ocelot->num_phys_ports) { in ocelot_setup_lag()
1193 u32 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p); in ocelot_setup_lag()
1198 ocelot_write_gix(ocelot, port_cfg | in ocelot_setup_lag()
1204 int ocelot_port_lag_join(struct ocelot *ocelot, int port, in ocelot_port_lag_join() argument
1226 ocelot->lags[port] = bond_mask; in ocelot_port_lag_join()
1230 ocelot->lags[lp] = 0; in ocelot_port_lag_join()
1234 ocelot->lags[lp] |= BIT(port); in ocelot_port_lag_join()
1237 ocelot_setup_lag(ocelot, lag); in ocelot_port_lag_join()
1238 ocelot_set_aggr_pgids(ocelot); in ocelot_port_lag_join()
1244 void ocelot_port_lag_leave(struct ocelot *ocelot, int port, in ocelot_port_lag_leave() argument
1251 for (i = 0; i < ocelot->num_phys_ports; i++) in ocelot_port_lag_leave()
1252 ocelot->lags[i] &= ~BIT(port); in ocelot_port_lag_leave()
1257 if (ocelot->lags[port]) { in ocelot_port_lag_leave()
1258 int n = __ffs(ocelot->lags[port]); in ocelot_port_lag_leave()
1260 ocelot->lags[n] = ocelot->lags[port]; in ocelot_port_lag_leave()
1261 ocelot->lags[port] = 0; in ocelot_port_lag_leave()
1263 ocelot_setup_lag(ocelot, n); in ocelot_port_lag_leave()
1266 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); in ocelot_port_lag_leave()
1268 ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port), in ocelot_port_lag_leave()
1271 ocelot_set_aggr_pgids(ocelot); in ocelot_port_lag_leave()
1281 void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu) in ocelot_port_set_maxlen() argument
1283 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_maxlen()
1288 if (port == ocelot->npi) { in ocelot_port_set_maxlen()
1291 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT) in ocelot_port_set_maxlen()
1293 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG) in ocelot_port_set_maxlen()
1302 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_START, in ocelot_port_set_maxlen()
1304 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_STOP, in ocelot_port_set_maxlen()
1308 atop_tot = (ocelot->shared_queue_sz - 9 * maxlen) / in ocelot_port_set_maxlen()
1311 ocelot_write_rix(ocelot, ocelot->ops->wm_enc(atop), SYS_ATOP, port); in ocelot_port_set_maxlen()
1312 ocelot_write(ocelot, ocelot->ops->wm_enc(atop_tot), SYS_ATOP_TOT_CFG); in ocelot_port_set_maxlen()
1316 int ocelot_get_max_mtu(struct ocelot *ocelot, int port) in ocelot_get_max_mtu() argument
1320 if (port == ocelot->npi) { in ocelot_get_max_mtu()
1323 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT) in ocelot_get_max_mtu()
1325 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG) in ocelot_get_max_mtu()
1333 void ocelot_init_port(struct ocelot *ocelot, int port) in ocelot_init_port() argument
1335 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_init_port()
1358 ocelot_port_set_maxlen(ocelot, port, ETH_DATA_LEN); in ocelot_init_port()
1370 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); in ocelot_init_port()
1373 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA, in ocelot_init_port()
1378 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q), in ocelot_init_port()
1383 ocelot_vcap_enable(ocelot, port); in ocelot_init_port()
1391 static void ocelot_cpu_port_init(struct ocelot *ocelot) in ocelot_cpu_port_init() argument
1393 int cpu = ocelot->num_phys_ports; in ocelot_cpu_port_init()
1396 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu); in ocelot_cpu_port_init()
1401 ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU); in ocelot_cpu_port_init()
1402 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA | in ocelot_cpu_port_init()
1407 ocelot_fields_write(ocelot, cpu, QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); in ocelot_cpu_port_init()
1409 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_XTR_HDR, in ocelot_cpu_port_init()
1410 ocelot->xtr_prefix); in ocelot_cpu_port_init()
1411 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_INJ_HDR, in ocelot_cpu_port_init()
1412 ocelot->inj_prefix); in ocelot_cpu_port_init()
1415 ocelot_write_gix(ocelot, ANA_PORT_VLAN_CFG_VLAN_VID(0) | in ocelot_cpu_port_init()
1421 int ocelot_init(struct ocelot *ocelot) in ocelot_init() argument
1427 if (ocelot->ops->reset) { in ocelot_init()
1428 ret = ocelot->ops->reset(ocelot); in ocelot_init()
1430 dev_err(ocelot->dev, "Switch reset failed\n"); in ocelot_init()
1435 ocelot->lags = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, in ocelot_init()
1437 if (!ocelot->lags) in ocelot_init()
1440 ocelot->stats = devm_kcalloc(ocelot->dev, in ocelot_init()
1441 ocelot->num_phys_ports * ocelot->num_stats, in ocelot_init()
1443 if (!ocelot->stats) in ocelot_init()
1446 mutex_init(&ocelot->stats_lock); in ocelot_init()
1447 mutex_init(&ocelot->ptp_lock); in ocelot_init()
1448 spin_lock_init(&ocelot->ptp_clock_lock); in ocelot_init()
1450 dev_name(ocelot->dev)); in ocelot_init()
1451 ocelot->stats_queue = create_singlethread_workqueue(queue_name); in ocelot_init()
1452 if (!ocelot->stats_queue) in ocelot_init()
1455 INIT_LIST_HEAD(&ocelot->multicast); in ocelot_init()
1456 ocelot_mact_init(ocelot); in ocelot_init()
1457 ocelot_vlan_init(ocelot); in ocelot_init()
1458 ocelot_vcap_init(ocelot); in ocelot_init()
1459 ocelot_cpu_port_init(ocelot); in ocelot_init()
1461 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_init()
1463 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) | in ocelot_init()
1469 ocelot_write(ocelot, ETH_P_8021AD, SYS_VLAN_ETYPE_CFG); in ocelot_init()
1472 ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA | in ocelot_init()
1480 ocelot_write(ocelot, in ocelot_init()
1485 regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1); in ocelot_init()
1488 ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA | in ocelot_init()
1492 for (i = 0; i < ocelot->num_flooding_pgids; i++) in ocelot_init()
1493 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) | in ocelot_init()
1497 ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) | in ocelot_init()
1503 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_init()
1505 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); in ocelot_init()
1507 ocelot_write_gix(ocelot, in ocelot_init()
1512 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port); in ocelot_init()
1516 for_each_nonreserved_multicast_dest_pgid(ocelot, i) { in ocelot_init()
1517 u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0)); in ocelot_init()
1519 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i); in ocelot_init()
1521 ocelot_write_rix(ocelot, in ocelot_init()
1522 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), in ocelot_init()
1524 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV4); in ocelot_init()
1525 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_MCIPV6); in ocelot_init()
1530 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_BYTE_SWAP | in ocelot_init()
1532 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_BYTE_SWAP | in ocelot_init()
1534 ocelot_write(ocelot, ANA_CPUQ_CFG_CPUQ_MIRROR(2) | in ocelot_init()
1544 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) | in ocelot_init()
1548 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work); in ocelot_init()
1549 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, in ocelot_init()
1556 void ocelot_deinit(struct ocelot *ocelot) in ocelot_deinit() argument
1558 cancel_delayed_work(&ocelot->stats_work); in ocelot_deinit()
1559 destroy_workqueue(ocelot->stats_queue); in ocelot_deinit()
1560 mutex_destroy(&ocelot->stats_lock); in ocelot_deinit()
1564 void ocelot_deinit_port(struct ocelot *ocelot, int port) in ocelot_deinit_port() argument
1566 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_deinit_port()