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
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
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()
172 dev_err(ocelot->dev, in ocelot_port_set_native_vlan()
180 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid), in ocelot_port_set_native_vlan()
191 ocelot_rmw_gix(ocelot, val, 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()
228 dev_err(ocelot->dev, 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()
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()
307 ocelot_port_set_pvid(ocelot, port, 0); 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()
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()
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()
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()
432 dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n", 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()
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
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()
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()
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
570 val = ocelot_read(ocelot, SYS_PTP_STATUS); in ocelot_get_txtstamp()
583 port = ocelot->ports[txport]; 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()
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()
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()
711 val = ocelot_read(ocelot, ANA_TABLES_MACACCESS); 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()
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()
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()
809 mutex_lock(&ocelot->ptp_lock); in ocelot_hwstamp_set()
826 mutex_unlock(&ocelot->ptp_lock); 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()
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 /* Caller must hold &ocelot->stats_lock */
852 static void ocelot_update_stats(struct ocelot *ocelot) in ocelot_update_stats() argument
856 for (i = 0; i < ocelot->num_phys_ports; i++) { in ocelot_update_stats()
858 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG); in ocelot_update_stats()
860 for (j = 0; j < ocelot->num_stats; j++) { in ocelot_update_stats()
862 unsigned int idx = i * ocelot->num_stats + j; in ocelot_update_stats()
864 val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS, in ocelot_update_stats()
865 ocelot->stats_layout[j].offset); in ocelot_update_stats()
867 if (val < (ocelot->stats[idx] & U32_MAX)) in ocelot_update_stats()
868 ocelot->stats[idx] += (u64)1 << 32; in ocelot_update_stats()
870 ocelot->stats[idx] = (ocelot->stats[idx] & in ocelot_update_stats()
879 struct ocelot *ocelot = container_of(del_work, struct ocelot, in ocelot_check_stats_work() local
882 mutex_lock(&ocelot->stats_lock); in ocelot_check_stats_work()
883 ocelot_update_stats(ocelot); in ocelot_check_stats_work()
884 mutex_unlock(&ocelot->stats_lock); in ocelot_check_stats_work()
886 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, in ocelot_check_stats_work()
890 void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data) in ocelot_get_ethtool_stats() argument
894 mutex_lock(&ocelot->stats_lock); in ocelot_get_ethtool_stats()
897 ocelot_update_stats(ocelot); in ocelot_get_ethtool_stats()
900 for (i = 0; i < ocelot->num_stats; i++) in ocelot_get_ethtool_stats()
901 *data++ = ocelot->stats[port * ocelot->num_stats + i]; in ocelot_get_ethtool_stats()
903 mutex_unlock(&ocelot->stats_lock); in ocelot_get_ethtool_stats()
907 int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset) in ocelot_get_sset_count() argument
912 return ocelot->num_stats; in ocelot_get_sset_count()
916 int ocelot_get_ts_info(struct ocelot *ocelot, int port, in ocelot_get_ts_info() argument
919 info->phc_index = ocelot->ptp_clock ? in ocelot_get_ts_info()
920 ptp_clock_index(ocelot->ptp_clock) : -1; in ocelot_get_ts_info()
944 void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) in ocelot_bridge_stp_state_set() argument
949 if (!(BIT(port) & ocelot->bridge_mask)) in ocelot_bridge_stp_state_set()
952 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); in ocelot_bridge_stp_state_set()
956 ocelot->bridge_fwd_mask |= BIT(port); in ocelot_bridge_stp_state_set()
964 ocelot->bridge_fwd_mask &= ~BIT(port); in ocelot_bridge_stp_state_set()
968 ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port); in ocelot_bridge_stp_state_set()
973 for (p = 0; p < ocelot->num_phys_ports; p++) { in ocelot_bridge_stp_state_set()
974 if (ocelot->bridge_fwd_mask & BIT(p)) { in ocelot_bridge_stp_state_set()
975 unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p); in ocelot_bridge_stp_state_set()
977 for (i = 0; i < ocelot->num_phys_ports; i++) { in ocelot_bridge_stp_state_set()
978 unsigned long bond_mask = ocelot->lags[i]; in ocelot_bridge_stp_state_set()
989 ocelot_write_rix(ocelot, mask, in ocelot_bridge_stp_state_set()
992 ocelot_write_rix(ocelot, 0, in ocelot_bridge_stp_state_set()
999 void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs) in ocelot_set_ageing_time() argument
1009 ocelot_rmw(ocelot, age_period, ANA_AUTOAGE_AGE_PERIOD_M, ANA_AUTOAGE); in ocelot_set_ageing_time()
1013 static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot, in ocelot_multicast_get() argument
1019 list_for_each_entry(mc, &ocelot->multicast, list) { in ocelot_multicast_get()
1036 static int ocelot_mdb_get_pgid(struct ocelot *ocelot, in ocelot_mdb_get_pgid() argument
1050 for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) { in ocelot_mdb_get_pgid()
1054 list_for_each_entry(mc, &ocelot->multicast, list) { in ocelot_mdb_get_pgid()
1084 int ocelot_port_mdb_add(struct ocelot *ocelot, int port, in ocelot_port_mdb_add() argument
1087 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_mdb_add()
1094 if (port == ocelot->npi) in ocelot_port_mdb_add()
1095 port = ocelot->num_phys_ports; in ocelot_port_mdb_add()
1102 mc = ocelot_multicast_get(ocelot, mdb->addr, vid); in ocelot_port_mdb_add()
1104 int pgid = ocelot_mdb_get_pgid(ocelot, entry_type); in ocelot_port_mdb_add()
1107 dev_err(ocelot->dev, in ocelot_port_mdb_add()
1113 mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL); in ocelot_port_mdb_add()
1121 list_add_tail(&mc->list, &ocelot->multicast); in ocelot_port_mdb_add()
1127 ocelot_mact_forget(ocelot, addr, vid); in ocelot_port_mdb_add()
1133 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type); in ocelot_port_mdb_add()
1137 int ocelot_port_mdb_del(struct ocelot *ocelot, int port, in ocelot_port_mdb_del() argument
1140 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_mdb_del()
1146 if (port == ocelot->npi) in ocelot_port_mdb_del()
1147 port = ocelot->num_phys_ports; in ocelot_port_mdb_del()
1152 mc = ocelot_multicast_get(ocelot, mdb->addr, vid); in ocelot_port_mdb_del()
1159 ocelot_mact_forget(ocelot, addr, vid); in ocelot_port_mdb_del()
1164 devm_kfree(ocelot->dev, mc); in ocelot_port_mdb_del()
1170 return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type); in ocelot_port_mdb_del()
1174 int ocelot_port_bridge_join(struct ocelot *ocelot, int port, in ocelot_port_bridge_join() argument
1177 if (!ocelot->bridge_mask) { in ocelot_port_bridge_join()
1178 ocelot->hw_bridge_dev = bridge; in ocelot_port_bridge_join()
1180 if (ocelot->hw_bridge_dev != bridge) in ocelot_port_bridge_join()
1186 ocelot->bridge_mask |= BIT(port); in ocelot_port_bridge_join()
1192 int ocelot_port_bridge_leave(struct ocelot *ocelot, int port, in ocelot_port_bridge_leave() argument
1198 ocelot->bridge_mask &= ~BIT(port); in ocelot_port_bridge_leave()
1200 if (!ocelot->bridge_mask) in ocelot_port_bridge_leave()
1201 ocelot->hw_bridge_dev = NULL; in ocelot_port_bridge_leave()
1204 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans); in ocelot_port_bridge_leave()
1209 ret = ocelot_port_vlan_filtering(ocelot, port, false, &trans); in ocelot_port_bridge_leave()
1213 ocelot_port_set_pvid(ocelot, port, 0); in ocelot_port_bridge_leave()
1214 return ocelot_port_set_native_vlan(ocelot, port, 0); in ocelot_port_bridge_leave()
1218 static void ocelot_set_aggr_pgids(struct ocelot *ocelot) in ocelot_set_aggr_pgids() argument
1223 for_each_unicast_dest_pgid(ocelot, port) in ocelot_set_aggr_pgids()
1224 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); in ocelot_set_aggr_pgids()
1226 for_each_aggr_pgid(ocelot, i) in ocelot_set_aggr_pgids()
1227 ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), in ocelot_set_aggr_pgids()
1231 for (lag = 0; lag < ocelot->num_phys_ports; lag++) { in ocelot_set_aggr_pgids()
1236 bond_mask = ocelot->lags[lag]; in ocelot_set_aggr_pgids()
1240 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { in ocelot_set_aggr_pgids()
1242 ocelot_write_rix(ocelot, bond_mask, in ocelot_set_aggr_pgids()
1248 for_each_aggr_pgid(ocelot, i) { in ocelot_set_aggr_pgids()
1251 ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i); in ocelot_set_aggr_pgids()
1254 ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); in ocelot_set_aggr_pgids()
1259 static void ocelot_setup_lag(struct ocelot *ocelot, int lag) in ocelot_setup_lag() argument
1261 unsigned long bond_mask = ocelot->lags[lag]; in ocelot_setup_lag()
1264 for_each_set_bit(p, &bond_mask, ocelot->num_phys_ports) { in ocelot_setup_lag()
1265 u32 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p); in ocelot_setup_lag()
1270 ocelot_write_gix(ocelot, port_cfg | in ocelot_setup_lag()
1276 int ocelot_port_lag_join(struct ocelot *ocelot, int port, in ocelot_port_lag_join() argument
1298 ocelot->lags[port] = bond_mask; in ocelot_port_lag_join()
1302 ocelot->lags[lp] = 0; in ocelot_port_lag_join()
1306 ocelot->lags[lp] |= BIT(port); in ocelot_port_lag_join()
1309 ocelot_setup_lag(ocelot, lag); in ocelot_port_lag_join()
1310 ocelot_set_aggr_pgids(ocelot); in ocelot_port_lag_join()
1316 void ocelot_port_lag_leave(struct ocelot *ocelot, int port, in ocelot_port_lag_leave() argument
1323 for (i = 0; i < ocelot->num_phys_ports; i++) in ocelot_port_lag_leave()
1324 ocelot->lags[i] &= ~BIT(port); in ocelot_port_lag_leave()
1329 if (ocelot->lags[port]) { in ocelot_port_lag_leave()
1330 int n = __ffs(ocelot->lags[port]); in ocelot_port_lag_leave()
1332 ocelot->lags[n] = ocelot->lags[port]; in ocelot_port_lag_leave()
1333 ocelot->lags[port] = 0; in ocelot_port_lag_leave()
1335 ocelot_setup_lag(ocelot, n); in ocelot_port_lag_leave()
1338 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); in ocelot_port_lag_leave()
1340 ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port), in ocelot_port_lag_leave()
1343 ocelot_set_aggr_pgids(ocelot); in ocelot_port_lag_leave()
1353 void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu) in ocelot_port_set_maxlen() argument
1355 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_set_maxlen()
1360 if (port == ocelot->npi) { in ocelot_port_set_maxlen()
1363 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT) in ocelot_port_set_maxlen()
1365 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG) in ocelot_port_set_maxlen()
1374 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_START, in ocelot_port_set_maxlen()
1376 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_STOP, in ocelot_port_set_maxlen()
1380 atop_tot = (ocelot->shared_queue_sz - 9 * maxlen) / in ocelot_port_set_maxlen()
1383 ocelot_write_rix(ocelot, ocelot->ops->wm_enc(atop), SYS_ATOP, port); in ocelot_port_set_maxlen()
1384 ocelot_write(ocelot, ocelot->ops->wm_enc(atop_tot), SYS_ATOP_TOT_CFG); in ocelot_port_set_maxlen()
1388 int ocelot_get_max_mtu(struct ocelot *ocelot, int port) in ocelot_get_max_mtu() argument
1392 if (port == ocelot->npi) { in ocelot_get_max_mtu()
1395 if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_SHORT) in ocelot_get_max_mtu()
1397 else if (ocelot->inj_prefix == OCELOT_TAG_PREFIX_LONG) in ocelot_get_max_mtu()
1405 void ocelot_init_port(struct ocelot *ocelot, int port) in ocelot_init_port() argument
1407 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_init_port()
1430 ocelot_port_set_maxlen(ocelot, port, ETH_DATA_LEN); in ocelot_init_port()
1442 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); in ocelot_init_port()
1445 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA, in ocelot_init_port()
1450 ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q), in ocelot_init_port()
1455 ocelot_vcap_enable(ocelot, port); in ocelot_init_port()
1463 static void ocelot_cpu_port_init(struct ocelot *ocelot) in ocelot_cpu_port_init() argument
1465 int cpu = ocelot->num_phys_ports; in ocelot_cpu_port_init()
1468 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, cpu); in ocelot_cpu_port_init()
1473 ocelot_write_rix(ocelot, BIT(cpu), ANA_PGID_PGID, PGID_CPU); in ocelot_cpu_port_init()
1474 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_RECV_ENA | in ocelot_cpu_port_init()
1479 ocelot_fields_write(ocelot, cpu, QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); in ocelot_cpu_port_init()
1481 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_XTR_HDR, in ocelot_cpu_port_init()
1482 ocelot->xtr_prefix); in ocelot_cpu_port_init()
1483 ocelot_fields_write(ocelot, cpu, SYS_PORT_MODE_INCL_INJ_HDR, in ocelot_cpu_port_init()
1484 ocelot->inj_prefix); in ocelot_cpu_port_init()
1487 ocelot_write_gix(ocelot, ANA_PORT_VLAN_CFG_VLAN_VID(0) | in ocelot_cpu_port_init()
1493 int ocelot_init(struct ocelot *ocelot) in ocelot_init() argument
1499 if (ocelot->ops->reset) { in ocelot_init()
1500 ret = ocelot->ops->reset(ocelot); in ocelot_init()
1502 dev_err(ocelot->dev, "Switch reset failed\n"); in ocelot_init()
1507 ocelot->lags = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, in ocelot_init()
1509 if (!ocelot->lags) in ocelot_init()
1512 ocelot->stats = devm_kcalloc(ocelot->dev, in ocelot_init()
1513 ocelot->num_phys_ports * ocelot->num_stats, in ocelot_init()
1515 if (!ocelot->stats) in ocelot_init()
1518 mutex_init(&ocelot->stats_lock); in ocelot_init()
1519 mutex_init(&ocelot->ptp_lock); in ocelot_init()
1520 spin_lock_init(&ocelot->ptp_clock_lock); in ocelot_init()
1522 dev_name(ocelot->dev)); in ocelot_init()
1523 ocelot->stats_queue = create_singlethread_workqueue(queue_name); in ocelot_init()
1524 if (!ocelot->stats_queue) in ocelot_init()
1527 INIT_LIST_HEAD(&ocelot->multicast); in ocelot_init()
1528 ocelot_mact_init(ocelot); in ocelot_init()
1529 ocelot_vlan_init(ocelot); in ocelot_init()
1530 ocelot_vcap_init(ocelot); in ocelot_init()
1531 ocelot_cpu_port_init(ocelot); in ocelot_init()
1533 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_init()
1535 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) | in ocelot_init()
1541 ocelot_write(ocelot, ETH_P_8021AD, SYS_VLAN_ETYPE_CFG); in ocelot_init()
1544 ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA | in ocelot_init()
1552 ocelot_write(ocelot, in ocelot_init()
1557 regmap_field_write(ocelot->regfields[ANA_ADVLEARN_VLAN_CHK], 1); in ocelot_init()
1560 ocelot_write(ocelot, SYS_FRM_AGING_AGE_TX_ENA | in ocelot_init()
1564 for (i = 0; i < ocelot->num_flooding_pgids; i++) in ocelot_init()
1565 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) | in ocelot_init()
1569 ocelot_write(ocelot, ANA_FLOODING_IPMC_FLD_MC6_DATA(PGID_MCIPV6) | in ocelot_init()
1575 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_init()
1577 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); in ocelot_init()
1579 ocelot_write_gix(ocelot, in ocelot_init()
1584 ocelot_write_rix(ocelot, 0, ANA_PGID_PGID, PGID_SRC + port); in ocelot_init()
1588 for_each_nonreserved_multicast_dest_pgid(ocelot, i) { in ocelot_init()
1589 u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0)); in ocelot_init()
1591 ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i); 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()
1599 ocelot_write_rix(ocelot, in ocelot_init()
1600 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), in ocelot_init()
1606 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_BYTE_SWAP | in ocelot_init()
1608 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_BYTE_SWAP | in ocelot_init()
1610 ocelot_write(ocelot, ANA_CPUQ_CFG_CPUQ_MIRROR(2) | in ocelot_init()
1620 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) | in ocelot_init()
1624 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work); in ocelot_init()
1625 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, in ocelot_init()
1632 void ocelot_deinit(struct ocelot *ocelot) in ocelot_deinit() argument
1634 cancel_delayed_work(&ocelot->stats_work); in ocelot_deinit()
1635 destroy_workqueue(ocelot->stats_queue); in ocelot_deinit()
1636 mutex_destroy(&ocelot->stats_lock); in ocelot_deinit()
1640 void ocelot_deinit_port(struct ocelot *ocelot, int port) in ocelot_deinit_port() argument
1642 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_deinit_port()