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

1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Copyright 2018-2019 NXP
13 #include <soc/mscc/ocelot.h>
14 #include <linux/dsa/ocelot.h>
15 #include <linux/pcs-lynx.h>
587 [ANA_ANEVENTS_SEQ_GEN_ERR_0] = REG_FIELD(ANA_ANEVENTS, 1, 1),
599 [QSYS_SWITCH_PORT_MODE_TX_PFC_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 1, 8, 7, 4),
603 [SYS_PORT_MODE_INCL_XTR_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 1, 2, 7, 4),
606 [SYS_PAUSE_CFG_PAUSE_STOP] = REG_FIELD_ID(SYS_PAUSE_CFG, 1, 9, 7, 4),
607 [SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 7, 4),
614 [VCAP_ES0_L2_MC] = { 8, 1},
615 [VCAP_ES0_L2_BC] = { 9, 1},
617 [VCAP_ES0_DP] = { 22, 1},
623 [VCAP_ES0_ACT_PUSH_INNER_TAG] = { 2, 1},
625 [VCAP_ES0_ACT_TAG_A_VID_SEL] = { 5, 1},
629 [VCAP_ES0_ACT_TAG_B_VID_SEL] = { 12, 1},
634 [VCAP_ES0_ACT_DEI_A_VAL] = { 32, 1},
637 [VCAP_ES0_ACT_DEI_B_VAL] = { 48, 1},
639 [VCAP_ES0_ACT_HIT_STICKY] = { 72, 1},
643 [VCAP_IS1_HK_TYPE] = { 0, 1},
644 [VCAP_IS1_HK_LOOKUP] = { 1, 2},
647 [VCAP_IS1_HK_OAM_Y1731] = { 19, 1},
648 [VCAP_IS1_HK_L2_MC] = { 20, 1},
649 [VCAP_IS1_HK_L2_BC] = { 21, 1},
650 [VCAP_IS1_HK_IP_MC] = { 22, 1},
651 [VCAP_IS1_HK_VLAN_TAGGED] = { 23, 1},
652 [VCAP_IS1_HK_VLAN_DBL_TAGGED] = { 24, 1},
653 [VCAP_IS1_HK_TPID] = { 25, 1},
655 [VCAP_IS1_HK_DEI] = { 38, 1},
659 [VCAP_IS1_HK_ETYPE_LEN] = { 90, 1},
661 [VCAP_IS1_HK_IP_SNAP] = {107, 1},
662 [VCAP_IS1_HK_IP4] = {108, 1},
663 /* Layer-3 Information */
664 [VCAP_IS1_HK_L3_FRAGMENT] = {109, 1},
665 [VCAP_IS1_HK_L3_FRAG_OFS_GT0] = {110, 1},
666 [VCAP_IS1_HK_L3_OPTIONS] = {111, 1},
669 /* Layer-4 Information */
670 [VCAP_IS1_HK_TCP_UDP] = {150, 1},
671 [VCAP_IS1_HK_TCP] = {151, 1},
675 [VCAP_IS1_HK_IP4_INNER_TPID] = { 42, 1},
677 [VCAP_IS1_HK_IP4_INNER_DEI] = { 55, 1},
679 [VCAP_IS1_HK_IP4_IP4] = { 59, 1},
680 [VCAP_IS1_HK_IP4_L3_FRAGMENT] = { 60, 1},
681 [VCAP_IS1_HK_IP4_L3_FRAG_OFS_GT0] = { 61, 1},
682 [VCAP_IS1_HK_IP4_L3_OPTIONS] = { 62, 1},
687 [VCAP_IS1_HK_IP4_TCP_UDP] = {141, 1},
688 [VCAP_IS1_HK_IP4_TCP] = {142, 1},
694 [VCAP_IS1_ACT_DSCP_ENA] = { 0, 1},
695 [VCAP_IS1_ACT_DSCP_VAL] = { 1, 6},
696 [VCAP_IS1_ACT_QOS_ENA] = { 7, 1},
698 [VCAP_IS1_ACT_DP_ENA] = { 11, 1},
699 [VCAP_IS1_ACT_DP_VAL] = { 12, 1},
704 [VCAP_IS1_ACT_VID_REPLACE_ENA] = { 38, 1},
708 [VCAP_IS1_ACT_PCP_DEI_ENA] = { 66, 1},
710 [VCAP_IS1_ACT_DEI_VAL] = { 70, 1},
711 [VCAP_IS1_ACT_VLAN_POP_CNT_ENA] = { 71, 1},
714 [VCAP_IS1_ACT_HIT_STICKY] = { 78, 1},
720 [VCAP_IS2_HK_FIRST] = { 4, 1},
723 [VCAP_IS2_HK_RSV2] = { 20, 1},
724 [VCAP_IS2_HK_HOST_MATCH] = { 21, 1},
725 [VCAP_IS2_HK_L2_MC] = { 22, 1},
726 [VCAP_IS2_HK_L2_BC] = { 23, 1},
727 [VCAP_IS2_HK_VLAN_TAGGED] = { 24, 1},
729 [VCAP_IS2_HK_DEI] = { 37, 1},
745 [VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK] = { 89, 1},
746 [VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK] = { 90, 1},
747 [VCAP_IS2_HK_MAC_ARP_LEN_OK] = { 91, 1},
748 [VCAP_IS2_HK_MAC_ARP_TARGET_MATCH] = { 92, 1},
749 [VCAP_IS2_HK_MAC_ARP_SENDER_MATCH] = { 93, 1},
750 [VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN] = { 94, 1},
754 [VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP] = {161, 1},
756 [VCAP_IS2_HK_IP4] = { 41, 1},
757 [VCAP_IS2_HK_L3_FRAGMENT] = { 42, 1},
758 [VCAP_IS2_HK_L3_FRAG_OFS_GT0] = { 43, 1},
759 [VCAP_IS2_HK_L3_OPTIONS] = { 44, 1},
760 [VCAP_IS2_HK_IP4_L3_TTL_GT0] = { 45, 1},
764 [VCAP_IS2_HK_DIP_EQ_SIP] = {118, 1},
766 [VCAP_IS2_HK_TCP] = {119, 1},
770 [VCAP_IS2_HK_L4_SPORT_EQ_DPORT] = {160, 1},
771 [VCAP_IS2_HK_L4_SEQUENCE_EQ0] = {161, 1},
772 [VCAP_IS2_HK_L4_FIN] = {162, 1},
773 [VCAP_IS2_HK_L4_SYN] = {163, 1},
774 [VCAP_IS2_HK_L4_RST] = {164, 1},
775 [VCAP_IS2_HK_L4_PSH] = {165, 1},
776 [VCAP_IS2_HK_L4_ACK] = {166, 1},
777 [VCAP_IS2_HK_L4_URG] = {167, 1},
784 [VCAP_IS2_HK_IP6_L3_TTL_GT0] = { 41, 1},
793 [VCAP_IS2_HK_OAM_CCM_CNTS_EQ0] = {181, 1},
794 [VCAP_IS2_HK_OAM_IS_Y1731] = {182, 1},
798 [VCAP_IS2_ACT_HIT_ME_ONCE] = { 0, 1},
799 [VCAP_IS2_ACT_CPU_COPY_ENA] = { 1, 1},
802 [VCAP_IS2_ACT_MIRROR_ENA] = { 7, 1},
803 [VCAP_IS2_ACT_LRN_DIS] = { 8, 1},
804 [VCAP_IS2_ACT_POLICE_ENA] = { 9, 1},
806 [VCAP_IS2_ACT_POLICE_VCAP_ONLY] = { 19, 1},
809 [VCAP_IS2_ACT_SMAC_REPLACE_ENA] = { 35, 1},
821 .count = 1,
841 .action_type_width = 1,
879 static int vsc9959_gcb_soft_rst_status(struct ocelot *ocelot) in vsc9959_gcb_soft_rst_status() argument
883 ocelot_field_read(ocelot, GCB_SOFT_RST_SWC_RST, &val); in vsc9959_gcb_soft_rst_status()
888 static int vsc9959_sys_ram_init_status(struct ocelot *ocelot) in vsc9959_sys_ram_init_status() argument
890 return ocelot_read(ocelot, SYS_RAM_INIT); in vsc9959_sys_ram_init_status()
896 static int vsc9959_reset(struct ocelot *ocelot) in vsc9959_reset() argument
900 /* soft-reset the switch core */ in vsc9959_reset()
901 ocelot_field_write(ocelot, GCB_SOFT_RST_SWC_RST, 1); in vsc9959_reset()
903 err = readx_poll_timeout(vsc9959_gcb_soft_rst_status, ocelot, val, !val, in vsc9959_reset()
906 dev_err(ocelot->dev, "timeout: switch core reset\n"); in vsc9959_reset()
911 ocelot_write(ocelot, SYS_RAM_INIT_RAM_INIT, SYS_RAM_INIT); in vsc9959_reset()
912 err = readx_poll_timeout(vsc9959_sys_ram_init_status, ocelot, val, !val, in vsc9959_reset()
916 dev_err(ocelot->dev, "timeout: switch sram init\n"); in vsc9959_reset()
921 ocelot_field_write(ocelot, SYS_RESET_CFG_CORE_ENA, 1); in vsc9959_reset()
927 * Bit 8: Unit; 0:1, 1:16
928 * Bit 7-0: Value to be multiplied with unit
956 static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot) in vsc9959_mdio_bus_alloc() argument
958 struct pci_dev *pdev = to_pci_dev(ocelot->dev); in vsc9959_mdio_bus_alloc()
959 struct felix *felix = ocelot_to_felix(ocelot); in vsc9959_mdio_bus_alloc()
961 struct device *dev = ocelot->dev; in vsc9959_mdio_bus_alloc()
970 felix->pcs = devm_kcalloc(dev, felix->info->num_ports, in vsc9959_mdio_bus_alloc()
973 if (!felix->pcs) { in vsc9959_mdio_bus_alloc()
975 return -ENOMEM; in vsc9959_mdio_bus_alloc()
996 return -ENOMEM; in vsc9959_mdio_bus_alloc()
998 bus->name = "VSC9959 internal MDIO bus"; in vsc9959_mdio_bus_alloc()
999 bus->read = enetc_mdio_read_c22; in vsc9959_mdio_bus_alloc()
1000 bus->write = enetc_mdio_write_c22; in vsc9959_mdio_bus_alloc()
1001 bus->read_c45 = enetc_mdio_read_c45; in vsc9959_mdio_bus_alloc()
1002 bus->write_c45 = enetc_mdio_write_c45; in vsc9959_mdio_bus_alloc()
1003 bus->parent = dev; in vsc9959_mdio_bus_alloc()
1004 mdio_priv = bus->priv; in vsc9959_mdio_bus_alloc()
1005 mdio_priv->hw = hw; in vsc9959_mdio_bus_alloc()
1009 mdio_priv->mdio_base = 0; in vsc9959_mdio_bus_alloc()
1010 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev)); in vsc9959_mdio_bus_alloc()
1020 felix->imdio = bus; in vsc9959_mdio_bus_alloc()
1022 for (port = 0; port < felix->info->num_ports; port++) { in vsc9959_mdio_bus_alloc()
1023 struct ocelot_port *ocelot_port = ocelot->ports[port]; in vsc9959_mdio_bus_alloc()
1026 if (dsa_is_unused_port(felix->ds, port)) in vsc9959_mdio_bus_alloc()
1029 if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL) in vsc9959_mdio_bus_alloc()
1032 phylink_pcs = lynx_pcs_create_mdiodev(felix->imdio, port); in vsc9959_mdio_bus_alloc()
1036 felix->pcs[port] = phylink_pcs; in vsc9959_mdio_bus_alloc()
1044 static void vsc9959_mdio_bus_free(struct ocelot *ocelot) in vsc9959_mdio_bus_free() argument
1046 struct felix *felix = ocelot_to_felix(ocelot); in vsc9959_mdio_bus_free()
1049 for (port = 0; port < ocelot->num_phys_ports; port++) { in vsc9959_mdio_bus_free()
1050 struct phylink_pcs *phylink_pcs = felix->pcs[port]; in vsc9959_mdio_bus_free()
1055 mdiobus_unregister(felix->imdio); in vsc9959_mdio_bus_free()
1056 mdiobus_free(felix->imdio); in vsc9959_mdio_bus_free()
1076 return (gate_len_ns - VSC9959_TAS_MIN_GATE_LEN_NS) * PSEC_PER_NSEC; in vsc9959_tas_remaining_gate_len_ps()
1080 * of a cyclic tc-taprio schedule. If a gate is always open, the duration is
1101 n = taprio->num_entries; in vsc9959_tas_min_gate_lengths()
1111 entry = &taprio->entries[i % n]; in vsc9959_tas_min_gate_lengths()
1114 if (entry->gate_mask & BIT(tc)) { in vsc9959_tas_min_gate_lengths()
1115 gate_len[tc] += entry->interval; in vsc9959_tas_min_gate_lengths()
1144 static void vsc9959_port_qmaxsdu_set(struct ocelot *ocelot, int port, int tc, in vsc9959_port_qmaxsdu_set() argument
1149 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_0, in vsc9959_port_qmaxsdu_set()
1152 case 1: in vsc9959_port_qmaxsdu_set()
1153 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_1, in vsc9959_port_qmaxsdu_set()
1157 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_2, in vsc9959_port_qmaxsdu_set()
1161 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_3, in vsc9959_port_qmaxsdu_set()
1165 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_4, in vsc9959_port_qmaxsdu_set()
1169 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_5, in vsc9959_port_qmaxsdu_set()
1173 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_6, in vsc9959_port_qmaxsdu_set()
1177 ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_7, in vsc9959_port_qmaxsdu_set()
1183 static u32 vsc9959_port_qmaxsdu_get(struct ocelot *ocelot, int port, int tc) in vsc9959_port_qmaxsdu_get() argument
1186 case 0: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_0, port); in vsc9959_port_qmaxsdu_get()
1187 case 1: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_1, port); in vsc9959_port_qmaxsdu_get()
1188 case 2: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_2, port); in vsc9959_port_qmaxsdu_get()
1189 case 3: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_3, port); in vsc9959_port_qmaxsdu_get()
1190 case 4: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_4, port); in vsc9959_port_qmaxsdu_get()
1191 case 5: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_5, port); in vsc9959_port_qmaxsdu_get()
1192 case 6: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_6, port); in vsc9959_port_qmaxsdu_get()
1193 case 7: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_7, port); in vsc9959_port_qmaxsdu_get()
1201 if (!taprio || !taprio->max_sdu[tc]) in vsc9959_tas_tc_max_sdu()
1204 return taprio->max_sdu[tc] + ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN; in vsc9959_tas_tc_max_sdu()
1213 static void vsc9959_tas_guard_bands_update(struct ocelot *ocelot, int port) in vsc9959_tas_guard_bands_update() argument
1215 struct ocelot_port *ocelot_port = ocelot->ports[port]; in vsc9959_tas_guard_bands_update()
1216 struct ocelot_mm_state *mm = &ocelot->mm[port]; in vsc9959_tas_guard_bands_update()
1226 lockdep_assert_held(&ocelot->fwd_domain_lock); in vsc9959_tas_guard_bands_update()
1228 taprio = ocelot_port->taprio; in vsc9959_tas_guard_bands_update()
1230 val = ocelot_read_rix(ocelot, QSYS_TAG_CONFIG, port); in vsc9959_tas_guard_bands_update()
1265 val = ocelot_read_rix(ocelot, QSYS_PREEMPTION_CFG, port); in vsc9959_tas_guard_bands_update()
1270 dev_dbg(ocelot->dev, in vsc9959_tas_guard_bands_update()
1285 if ((mm->active_preemptible_tcs & BIT(tc)) ? in vsc9959_tas_guard_bands_update()
1292 dev_dbg(ocelot->dev, in vsc9959_tas_guard_bands_update()
1303 * per-tc static guard band lengths, so it reduces the in vsc9959_tas_guard_bands_update()
1314 max_sdu = 1; in vsc9959_tas_guard_bands_update()
1321 max_sdu -= 20; in vsc9959_tas_guard_bands_update()
1326 dev_info(ocelot->dev, in vsc9959_tas_guard_bands_update()
1335 vsc9959_port_qmaxsdu_set(ocelot, port, tc, max_sdu); in vsc9959_tas_guard_bands_update()
1338 ocelot_write_rix(ocelot, maxlen, QSYS_PORT_MAX_SDU, port); in vsc9959_tas_guard_bands_update()
1340 ocelot->ops->cut_through_fwd(ocelot); in vsc9959_tas_guard_bands_update()
1343 static void vsc9959_sched_speed_set(struct ocelot *ocelot, int port, in vsc9959_sched_speed_set() argument
1346 struct ocelot_port *ocelot_port = ocelot->ports[port]; in vsc9959_sched_speed_set()
1367 mutex_lock(&ocelot->fwd_domain_lock); in vsc9959_sched_speed_set()
1369 ocelot_rmw_rix(ocelot, in vsc9959_sched_speed_set()
1374 if (ocelot_port->taprio) in vsc9959_sched_speed_set()
1375 vsc9959_tas_guard_bands_update(ocelot, port); in vsc9959_sched_speed_set()
1377 mutex_unlock(&ocelot->fwd_domain_lock); in vsc9959_sched_speed_set()
1380 static void vsc9959_new_base_time(struct ocelot *ocelot, ktime_t base_time, in vsc9959_new_base_time() argument
1388 ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); in vsc9959_new_base_time()
1393 u64 nr_of_cycles = current_time - base_time; in vsc9959_new_base_time()
1396 new_base_time += cycle_time * (nr_of_cycles + 1); in vsc9959_new_base_time()
1402 static u32 vsc9959_tas_read_cfg_status(struct ocelot *ocelot) in vsc9959_tas_read_cfg_status() argument
1404 return ocelot_read(ocelot, QSYS_TAS_PARAM_CFG_CTRL); in vsc9959_tas_read_cfg_status()
1407 static void vsc9959_tas_gcl_set(struct ocelot *ocelot, const u32 gcl_ix, in vsc9959_tas_gcl_set() argument
1410 ocelot_write(ocelot, in vsc9959_tas_gcl_set()
1412 QSYS_GCL_CFG_REG_1_GATE_STATE(entry->gate_mask), in vsc9959_tas_gcl_set()
1414 ocelot_write(ocelot, entry->interval, QSYS_GCL_CFG_REG_2); in vsc9959_tas_gcl_set()
1417 static int vsc9959_qos_port_tas_set(struct ocelot *ocelot, int port, in vsc9959_qos_port_tas_set() argument
1420 struct ocelot_port *ocelot_port = ocelot->ports[port]; in vsc9959_qos_port_tas_set()
1425 mutex_lock(&ocelot->fwd_domain_lock); in vsc9959_qos_port_tas_set()
1427 if (taprio->cmd == TAPRIO_CMD_DESTROY) { in vsc9959_qos_port_tas_set()
1428 ocelot_port_mqprio(ocelot, port, &taprio->mqprio); in vsc9959_qos_port_tas_set()
1429 ocelot_rmw_rix(ocelot, 0, QSYS_TAG_CONFIG_ENABLE, in vsc9959_qos_port_tas_set()
1432 taprio_offload_free(ocelot_port->taprio); in vsc9959_qos_port_tas_set()
1433 ocelot_port->taprio = NULL; in vsc9959_qos_port_tas_set()
1435 vsc9959_tas_guard_bands_update(ocelot, port); in vsc9959_qos_port_tas_set()
1437 mutex_unlock(&ocelot->fwd_domain_lock); in vsc9959_qos_port_tas_set()
1439 } else if (taprio->cmd != TAPRIO_CMD_REPLACE) { in vsc9959_qos_port_tas_set()
1440 ret = -EOPNOTSUPP; in vsc9959_qos_port_tas_set()
1444 ret = ocelot_port_mqprio(ocelot, port, &taprio->mqprio); in vsc9959_qos_port_tas_set()
1448 if (taprio->cycle_time > NSEC_PER_SEC || in vsc9959_qos_port_tas_set()
1449 taprio->cycle_time_extension >= NSEC_PER_SEC) { in vsc9959_qos_port_tas_set()
1450 ret = -EINVAL; in vsc9959_qos_port_tas_set()
1454 if (taprio->num_entries > VSC9959_TAS_GCL_ENTRY_MAX) { in vsc9959_qos_port_tas_set()
1455 ret = -ERANGE; in vsc9959_qos_port_tas_set()
1468 ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM(port) | in vsc9959_qos_port_tas_set()
1474 /* Hardware errata - Admin config could not be overwritten if in vsc9959_qos_port_tas_set()
1477 val = ocelot_read(ocelot, QSYS_PARAM_STATUS_REG_8); in vsc9959_qos_port_tas_set()
1479 ret = -EBUSY; in vsc9959_qos_port_tas_set()
1483 ocelot_rmw_rix(ocelot, in vsc9959_qos_port_tas_set()
1492 vsc9959_new_base_time(ocelot, taprio->base_time, in vsc9959_qos_port_tas_set()
1493 taprio->cycle_time, &base_ts); in vsc9959_qos_port_tas_set()
1494 ocelot_write(ocelot, base_ts.tv_nsec, QSYS_PARAM_CFG_REG_1); in vsc9959_qos_port_tas_set()
1495 ocelot_write(ocelot, lower_32_bits(base_ts.tv_sec), QSYS_PARAM_CFG_REG_2); in vsc9959_qos_port_tas_set()
1497 ocelot_write(ocelot, in vsc9959_qos_port_tas_set()
1499 QSYS_PARAM_CFG_REG_3_LIST_LENGTH(taprio->num_entries), in vsc9959_qos_port_tas_set()
1501 ocelot_write(ocelot, taprio->cycle_time, QSYS_PARAM_CFG_REG_4); in vsc9959_qos_port_tas_set()
1502 ocelot_write(ocelot, taprio->cycle_time_extension, QSYS_PARAM_CFG_REG_5); in vsc9959_qos_port_tas_set()
1504 for (i = 0; i < taprio->num_entries; i++) in vsc9959_qos_port_tas_set()
1505 vsc9959_tas_gcl_set(ocelot, i, &taprio->entries[i]); in vsc9959_qos_port_tas_set()
1507 ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE, in vsc9959_qos_port_tas_set()
1511 ret = readx_poll_timeout(vsc9959_tas_read_cfg_status, ocelot, val, in vsc9959_qos_port_tas_set()
1517 ocelot_port->taprio = taprio_offload_get(taprio); in vsc9959_qos_port_tas_set()
1518 vsc9959_tas_guard_bands_update(ocelot, port); in vsc9959_qos_port_tas_set()
1520 mutex_unlock(&ocelot->fwd_domain_lock); in vsc9959_qos_port_tas_set()
1525 taprio->mqprio.qopt.num_tc = 0; in vsc9959_qos_port_tas_set()
1526 ocelot_port_mqprio(ocelot, port, &taprio->mqprio); in vsc9959_qos_port_tas_set()
1528 mutex_unlock(&ocelot->fwd_domain_lock); in vsc9959_qos_port_tas_set()
1533 static void vsc9959_tas_clock_adjust(struct ocelot *ocelot) in vsc9959_tas_clock_adjust() argument
1541 mutex_lock(&ocelot->fwd_domain_lock); in vsc9959_tas_clock_adjust()
1543 for (port = 0; port < ocelot->num_phys_ports; port++) { in vsc9959_tas_clock_adjust()
1544 ocelot_port = ocelot->ports[port]; in vsc9959_tas_clock_adjust()
1545 taprio = ocelot_port->taprio; in vsc9959_tas_clock_adjust()
1549 ocelot_rmw(ocelot, in vsc9959_tas_clock_adjust()
1554 /* Disable time-aware shaper */ in vsc9959_tas_clock_adjust()
1555 ocelot_rmw_rix(ocelot, 0, QSYS_TAG_CONFIG_ENABLE, in vsc9959_tas_clock_adjust()
1558 vsc9959_new_base_time(ocelot, taprio->base_time, in vsc9959_tas_clock_adjust()
1559 taprio->cycle_time, &base_ts); in vsc9959_tas_clock_adjust()
1561 ocelot_write(ocelot, base_ts.tv_nsec, QSYS_PARAM_CFG_REG_1); in vsc9959_tas_clock_adjust()
1562 ocelot_write(ocelot, lower_32_bits(base_ts.tv_sec), in vsc9959_tas_clock_adjust()
1565 ocelot_rmw(ocelot, in vsc9959_tas_clock_adjust()
1570 ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE, in vsc9959_tas_clock_adjust()
1574 /* Re-enable time-aware shaper */ in vsc9959_tas_clock_adjust()
1575 ocelot_rmw_rix(ocelot, QSYS_TAG_CONFIG_ENABLE, in vsc9959_tas_clock_adjust()
1579 mutex_unlock(&ocelot->fwd_domain_lock); in vsc9959_tas_clock_adjust()
1585 struct ocelot *ocelot = ds->priv; in vsc9959_qos_port_cbs_set() local
1586 int port_ix = port * 8 + cbs_qopt->queue; in vsc9959_qos_port_cbs_set()
1589 if (cbs_qopt->queue >= ds->num_tx_queues) in vsc9959_qos_port_cbs_set()
1590 return -EINVAL; in vsc9959_qos_port_cbs_set()
1592 if (!cbs_qopt->enable) { in vsc9959_qos_port_cbs_set()
1593 ocelot_write_gix(ocelot, QSYS_CIR_CFG_CIR_RATE(0) | in vsc9959_qos_port_cbs_set()
1597 ocelot_rmw_gix(ocelot, 0, QSYS_SE_CFG_SE_AVB_ENA, in vsc9959_qos_port_cbs_set()
1604 rate = DIV_ROUND_UP(cbs_qopt->idleslope, 100); in vsc9959_qos_port_cbs_set()
1606 rate = clamp_t(u32, rate, 1, GENMASK(14, 0)); in vsc9959_qos_port_cbs_set()
1608 burst = DIV_ROUND_UP(cbs_qopt->hicredit, 4096); in vsc9959_qos_port_cbs_set()
1610 burst = clamp_t(u32, burst, 1, GENMASK(5, 0)); in vsc9959_qos_port_cbs_set()
1611 ocelot_write_gix(ocelot, in vsc9959_qos_port_cbs_set()
1617 ocelot_rmw_gix(ocelot, in vsc9959_qos_port_cbs_set()
1630 switch (base->type) { in vsc9959_qos_query_caps()
1632 struct tc_mqprio_caps *caps = base->caps; in vsc9959_qos_query_caps()
1634 caps->validate_queue_counts = true; in vsc9959_qos_query_caps()
1639 struct tc_taprio_caps *caps = base->caps; in vsc9959_qos_query_caps()
1641 caps->supports_queue_max_sdu = true; in vsc9959_qos_query_caps()
1646 return -EOPNOTSUPP; in vsc9959_qos_query_caps()
1650 static int vsc9959_qos_port_mqprio(struct ocelot *ocelot, int port, in vsc9959_qos_port_mqprio() argument
1655 mutex_lock(&ocelot->fwd_domain_lock); in vsc9959_qos_port_mqprio()
1656 ret = ocelot_port_mqprio(ocelot, port, mqprio); in vsc9959_qos_port_mqprio()
1657 mutex_unlock(&ocelot->fwd_domain_lock); in vsc9959_qos_port_mqprio()
1666 struct ocelot *ocelot = ds->priv; in vsc9959_port_setup_tc() local
1672 return vsc9959_qos_port_tas_set(ocelot, port, type_data); in vsc9959_port_setup_tc()
1674 return vsc9959_qos_port_mqprio(ocelot, port, type_data); in vsc9959_port_setup_tc()
1678 return -EOPNOTSUPP; in vsc9959_port_setup_tc()
1749 struct flow_dissector *dissector = rule->match.dissector; in vsc9959_stream_identify()
1751 if (dissector->used_keys & in vsc9959_stream_identify()
1756 return -EOPNOTSUPP; in vsc9959_stream_identify()
1762 ether_addr_copy(stream->dmac, match.key->dst); in vsc9959_stream_identify()
1763 if (!is_zero_ether_addr(match.mask->src)) in vsc9959_stream_identify()
1764 return -EOPNOTSUPP; in vsc9959_stream_identify()
1766 return -EOPNOTSUPP; in vsc9959_stream_identify()
1773 if (match.mask->vlan_priority) in vsc9959_stream_identify()
1774 stream->prio = match.key->vlan_priority; in vsc9959_stream_identify()
1776 stream->prio = -1; in vsc9959_stream_identify()
1778 if (!match.mask->vlan_id) in vsc9959_stream_identify()
1779 return -EOPNOTSUPP; in vsc9959_stream_identify()
1780 stream->vid = match.key->vlan_id; in vsc9959_stream_identify()
1782 return -EOPNOTSUPP; in vsc9959_stream_identify()
1785 stream->id = f->cookie; in vsc9959_stream_identify()
1790 static int vsc9959_mact_stream_set(struct ocelot *ocelot, in vsc9959_mact_stream_set() argument
1799 ether_addr_copy(mac, stream->dmac); in vsc9959_mact_stream_set()
1800 vid = stream->vid; in vsc9959_mact_stream_set()
1805 ret = ocelot_mact_lookup(ocelot, &dst_idx, mac, vid, &type); in vsc9959_mact_stream_set()
1809 return -EOPNOTSUPP; in vsc9959_mact_stream_set()
1812 if ((stream->sfid_valid || stream->ssid_valid) && in vsc9959_mact_stream_set()
1816 sfid = stream->sfid_valid ? stream->sfid : -1; in vsc9959_mact_stream_set()
1817 ssid = stream->ssid_valid ? stream->ssid : -1; in vsc9959_mact_stream_set()
1819 ret = ocelot_mact_learn_streamdata(ocelot, dst_idx, mac, vid, type, in vsc9959_mact_stream_set()
1832 if (ether_addr_equal(tmp->dmac, stream->dmac) && in vsc9959_stream_table_lookup()
1833 tmp->vid == stream->vid) in vsc9959_stream_table_lookup()
1839 static int vsc9959_stream_table_add(struct ocelot *ocelot, in vsc9959_stream_table_add() argument
1849 return -ENOMEM; in vsc9959_stream_table_add()
1851 if (!stream->dummy) { in vsc9959_stream_table_add()
1852 ret = vsc9959_mact_stream_set(ocelot, stream_entry, extack); in vsc9959_stream_table_add()
1859 list_add_tail(&stream_entry->list, stream_list); in vsc9959_stream_table_add()
1870 if (tmp->id == id) in vsc9959_stream_table_get()
1876 static void vsc9959_stream_table_del(struct ocelot *ocelot, in vsc9959_stream_table_del() argument
1879 if (!stream->dummy) in vsc9959_stream_table_del()
1880 vsc9959_mact_stream_set(ocelot, stream, NULL); in vsc9959_stream_table_del()
1882 list_del(&stream->list); in vsc9959_stream_table_del()
1886 static u32 vsc9959_sfi_access_status(struct ocelot *ocelot) in vsc9959_sfi_access_status() argument
1888 return ocelot_read(ocelot, ANA_TABLES_SFIDACCESS); in vsc9959_sfi_access_status()
1891 static int vsc9959_psfp_sfi_set(struct ocelot *ocelot, in vsc9959_psfp_sfi_set() argument
1896 if (sfi->index > VSC9959_PSFP_SFID_MAX) in vsc9959_psfp_sfi_set()
1897 return -EINVAL; in vsc9959_psfp_sfi_set()
1899 if (!sfi->enable) { in vsc9959_psfp_sfi_set()
1900 ocelot_write(ocelot, ANA_TABLES_SFIDTIDX_SFID_INDEX(sfi->index), in vsc9959_psfp_sfi_set()
1904 ocelot_write(ocelot, val, ANA_TABLES_SFIDACCESS); in vsc9959_psfp_sfi_set()
1906 return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val, in vsc9959_psfp_sfi_set()
1911 if (sfi->sgid > VSC9959_PSFP_GATE_ID_MAX || in vsc9959_psfp_sfi_set()
1912 sfi->fmid > VSC9959_PSFP_POLICER_MAX) in vsc9959_psfp_sfi_set()
1913 return -EINVAL; in vsc9959_psfp_sfi_set()
1915 ocelot_write(ocelot, in vsc9959_psfp_sfi_set()
1916 (sfi->sg_valid ? ANA_TABLES_SFIDTIDX_SGID_VALID : 0) | in vsc9959_psfp_sfi_set()
1917 ANA_TABLES_SFIDTIDX_SGID(sfi->sgid) | in vsc9959_psfp_sfi_set()
1918 (sfi->fm_valid ? ANA_TABLES_SFIDTIDX_POL_ENA : 0) | in vsc9959_psfp_sfi_set()
1919 ANA_TABLES_SFIDTIDX_POL_IDX(sfi->fmid) | in vsc9959_psfp_sfi_set()
1920 ANA_TABLES_SFIDTIDX_SFID_INDEX(sfi->index), in vsc9959_psfp_sfi_set()
1923 ocelot_write(ocelot, in vsc9959_psfp_sfi_set()
1924 (sfi->prio_valid ? ANA_TABLES_SFIDACCESS_IGR_PRIO_MATCH_ENA : 0) | in vsc9959_psfp_sfi_set()
1925 ANA_TABLES_SFIDACCESS_IGR_PRIO(sfi->prio) | in vsc9959_psfp_sfi_set()
1926 ANA_TABLES_SFIDACCESS_MAX_SDU_LEN(sfi->maxsdu) | in vsc9959_psfp_sfi_set()
1930 return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val, in vsc9959_psfp_sfi_set()
1935 static int vsc9959_psfp_sfidmask_set(struct ocelot *ocelot, u32 sfid, int ports) in vsc9959_psfp_sfidmask_set() argument
1939 ocelot_rmw(ocelot, in vsc9959_psfp_sfidmask_set()
1944 ocelot_write(ocelot, in vsc9959_psfp_sfidmask_set()
1949 ocelot_rmw(ocelot, in vsc9959_psfp_sfidmask_set()
1954 return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val, in vsc9959_psfp_sfidmask_set()
1959 static int vsc9959_psfp_sfi_list_add(struct ocelot *ocelot, in vsc9959_psfp_sfi_list_add() argument
1968 return -ENOMEM; in vsc9959_psfp_sfi_list_add()
1970 refcount_set(&sfi_entry->refcount, 1); in vsc9959_psfp_sfi_list_add()
1972 ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry); in vsc9959_psfp_sfi_list_add()
1978 vsc9959_psfp_sfidmask_set(ocelot, sfi->index, sfi->portmask); in vsc9959_psfp_sfi_list_add()
1980 list_add(&sfi_entry->list, pos); in vsc9959_psfp_sfi_list_add()
1985 static int vsc9959_psfp_sfi_table_add(struct ocelot *ocelot, in vsc9959_psfp_sfi_table_add() argument
1993 psfp = &ocelot->psfp; in vsc9959_psfp_sfi_table_add()
1994 last = &psfp->sfi_list; in vsc9959_psfp_sfi_table_add()
1996 list_for_each_safe(pos, q, &psfp->sfi_list) { in vsc9959_psfp_sfi_table_add()
1998 if (sfi->sg_valid == tmp->sg_valid && in vsc9959_psfp_sfi_table_add()
1999 sfi->fm_valid == tmp->fm_valid && in vsc9959_psfp_sfi_table_add()
2000 sfi->portmask == tmp->portmask && in vsc9959_psfp_sfi_table_add()
2001 tmp->sgid == sfi->sgid && in vsc9959_psfp_sfi_table_add()
2002 tmp->fmid == sfi->fmid) { in vsc9959_psfp_sfi_table_add()
2003 sfi->index = tmp->index; in vsc9959_psfp_sfi_table_add()
2004 refcount_inc(&tmp->refcount); in vsc9959_psfp_sfi_table_add()
2008 if (tmp->index == insert) { in vsc9959_psfp_sfi_table_add()
2013 sfi->index = insert; in vsc9959_psfp_sfi_table_add()
2015 return vsc9959_psfp_sfi_list_add(ocelot, sfi, last); in vsc9959_psfp_sfi_table_add()
2018 static int vsc9959_psfp_sfi_table_add2(struct ocelot *ocelot, in vsc9959_psfp_sfi_table_add2() argument
2028 psfp = &ocelot->psfp; in vsc9959_psfp_sfi_table_add2()
2029 last = &psfp->sfi_list; in vsc9959_psfp_sfi_table_add2()
2031 list_for_each_safe(pos, q, &psfp->sfi_list) { in vsc9959_psfp_sfi_table_add2()
2034 if (tmp->index >= insert + 2) in vsc9959_psfp_sfi_table_add2()
2037 insert = tmp->index + 1; in vsc9959_psfp_sfi_table_add2()
2040 sfi->index = insert; in vsc9959_psfp_sfi_table_add2()
2042 ret = vsc9959_psfp_sfi_list_add(ocelot, sfi, last); in vsc9959_psfp_sfi_table_add2()
2046 sfi2->index = insert + 1; in vsc9959_psfp_sfi_table_add2()
2048 return vsc9959_psfp_sfi_list_add(ocelot, sfi2, last->next); in vsc9959_psfp_sfi_table_add2()
2057 if (tmp->index == index) in vsc9959_psfp_sfi_table_get()
2063 static void vsc9959_psfp_sfi_table_del(struct ocelot *ocelot, u32 index) in vsc9959_psfp_sfi_table_del() argument
2069 psfp = &ocelot->psfp; in vsc9959_psfp_sfi_table_del()
2071 list_for_each_entry_safe(tmp, n, &psfp->sfi_list, list) in vsc9959_psfp_sfi_table_del()
2072 if (tmp->index == index) { in vsc9959_psfp_sfi_table_del()
2073 z = refcount_dec_and_test(&tmp->refcount); in vsc9959_psfp_sfi_table_del()
2075 tmp->enable = 0; in vsc9959_psfp_sfi_table_del()
2076 vsc9959_psfp_sfi_set(ocelot, tmp); in vsc9959_psfp_sfi_table_del()
2077 list_del(&tmp->list); in vsc9959_psfp_sfi_table_del()
2087 sgi->index = entry->hw_index; in vsc9959_psfp_parse_gate()
2088 sgi->ipv_valid = (entry->gate.prio < 0) ? 0 : 1; in vsc9959_psfp_parse_gate()
2089 sgi->init_ipv = (sgi->ipv_valid) ? entry->gate.prio : 0; in vsc9959_psfp_parse_gate()
2090 sgi->basetime = entry->gate.basetime; in vsc9959_psfp_parse_gate()
2091 sgi->cycletime = entry->gate.cycletime; in vsc9959_psfp_parse_gate()
2092 sgi->num_entries = entry->gate.num_entries; in vsc9959_psfp_parse_gate()
2093 sgi->enable = 1; in vsc9959_psfp_parse_gate()
2095 memcpy(sgi->entries, entry->gate.entries, in vsc9959_psfp_parse_gate()
2096 entry->gate.num_entries * sizeof(struct action_gate_entry)); in vsc9959_psfp_parse_gate()
2099 static u32 vsc9959_sgi_cfg_status(struct ocelot *ocelot) in vsc9959_sgi_cfg_status() argument
2101 return ocelot_read(ocelot, ANA_SG_ACCESS_CTRL); in vsc9959_sgi_cfg_status()
2104 static int vsc9959_psfp_sgi_set(struct ocelot *ocelot, in vsc9959_psfp_sgi_set() argument
2113 if (sgi->index > VSC9959_PSFP_GATE_ID_MAX) in vsc9959_psfp_sgi_set()
2114 return -EINVAL; in vsc9959_psfp_sgi_set()
2116 ocelot_write(ocelot, ANA_SG_ACCESS_CTRL_SGID(sgi->index), in vsc9959_psfp_sgi_set()
2119 if (!sgi->enable) { in vsc9959_psfp_sgi_set()
2120 ocelot_rmw(ocelot, ANA_SG_CONFIG_REG_3_INIT_GATE_STATE, in vsc9959_psfp_sgi_set()
2128 if (sgi->cycletime < VSC9959_PSFP_GATE_CYCLETIME_MIN || in vsc9959_psfp_sgi_set()
2129 sgi->cycletime > NSEC_PER_SEC) in vsc9959_psfp_sgi_set()
2130 return -EINVAL; in vsc9959_psfp_sgi_set()
2132 if (sgi->num_entries > VSC9959_PSFP_GATE_LIST_NUM) in vsc9959_psfp_sgi_set()
2133 return -EINVAL; in vsc9959_psfp_sgi_set()
2135 vsc9959_new_base_time(ocelot, sgi->basetime, sgi->cycletime, &base_ts); in vsc9959_psfp_sgi_set()
2136 ocelot_write(ocelot, base_ts.tv_nsec, ANA_SG_CONFIG_REG_1); in vsc9959_psfp_sgi_set()
2138 ocelot_write(ocelot, val, ANA_SG_CONFIG_REG_2); in vsc9959_psfp_sgi_set()
2141 ocelot_write(ocelot, in vsc9959_psfp_sgi_set()
2142 (sgi->ipv_valid ? ANA_SG_CONFIG_REG_3_IPV_VALID : 0) | in vsc9959_psfp_sgi_set()
2143 ANA_SG_CONFIG_REG_3_INIT_IPV(sgi->init_ipv) | in vsc9959_psfp_sgi_set()
2145 ANA_SG_CONFIG_REG_3_LIST_LENGTH(sgi->num_entries) | in vsc9959_psfp_sgi_set()
2150 ocelot_write(ocelot, sgi->cycletime, ANA_SG_CONFIG_REG_4); in vsc9959_psfp_sgi_set()
2152 e = sgi->entries; in vsc9959_psfp_sgi_set()
2153 for (i = 0; i < sgi->num_entries; i++) { in vsc9959_psfp_sgi_set()
2156 ocelot_write_rix(ocelot, ANA_SG_GCL_GS_CONFIG_IPS(ips) | in vsc9959_psfp_sgi_set()
2162 ocelot_write_rix(ocelot, interval_sum, ANA_SG_GCL_TI_CONFIG, i); in vsc9959_psfp_sgi_set()
2165 ocelot_rmw(ocelot, ANA_SG_ACCESS_CTRL_CONFIG_CHANGE, in vsc9959_psfp_sgi_set()
2169 return readx_poll_timeout(vsc9959_sgi_cfg_status, ocelot, val, in vsc9959_psfp_sgi_set()
2174 static int vsc9959_psfp_sgi_table_add(struct ocelot *ocelot, in vsc9959_psfp_sgi_table_add() argument
2181 psfp = &ocelot->psfp; in vsc9959_psfp_sgi_table_add()
2183 list_for_each_entry(tmp, &psfp->sgi_list, list) in vsc9959_psfp_sgi_table_add()
2184 if (tmp->index == sgi->index) { in vsc9959_psfp_sgi_table_add()
2185 refcount_inc(&tmp->refcount); in vsc9959_psfp_sgi_table_add()
2191 return -ENOMEM; in vsc9959_psfp_sgi_table_add()
2193 ret = vsc9959_psfp_sgi_set(ocelot, sgi); in vsc9959_psfp_sgi_table_add()
2199 tmp->index = sgi->index; in vsc9959_psfp_sgi_table_add()
2200 refcount_set(&tmp->refcount, 1); in vsc9959_psfp_sgi_table_add()
2201 list_add_tail(&tmp->list, &psfp->sgi_list); in vsc9959_psfp_sgi_table_add()
2206 static void vsc9959_psfp_sgi_table_del(struct ocelot *ocelot, in vsc9959_psfp_sgi_table_del() argument
2214 psfp = &ocelot->psfp; in vsc9959_psfp_sgi_table_del()
2216 list_for_each_entry_safe(tmp, n, &psfp->sgi_list, list) in vsc9959_psfp_sgi_table_del()
2217 if (tmp->index == index) { in vsc9959_psfp_sgi_table_del()
2218 z = refcount_dec_and_test(&tmp->refcount); in vsc9959_psfp_sgi_table_del()
2222 vsc9959_psfp_sgi_set(ocelot, &sgi); in vsc9959_psfp_sgi_table_del()
2223 list_del(&tmp->list); in vsc9959_psfp_sgi_table_del()
2230 static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port, in vsc9959_psfp_filter_add() argument
2233 struct netlink_ext_ack *extack = f->common.extack; in vsc9959_psfp_filter_add()
2246 psfp = &ocelot->psfp; in vsc9959_psfp_filter_add()
2254 mutex_lock(&psfp->lock); in vsc9959_psfp_filter_add()
2256 flow_action_for_each(i, a, &f->rule->action) { in vsc9959_psfp_filter_add()
2257 switch (a->id) { in vsc9959_psfp_filter_add()
2259 size = struct_size(sgi, entries, a->gate.num_entries); in vsc9959_psfp_filter_add()
2262 ret = -ENOMEM; in vsc9959_psfp_filter_add()
2266 ret = vsc9959_psfp_sgi_table_add(ocelot, sgi); in vsc9959_psfp_filter_add()
2271 sfi.sg_valid = 1; in vsc9959_psfp_filter_add()
2272 sfi.sgid = sgi->index; in vsc9959_psfp_filter_add()
2276 index = a->hw_index + VSC9959_PSFP_POLICER_BASE; in vsc9959_psfp_filter_add()
2278 ret = -EINVAL; in vsc9959_psfp_filter_add()
2282 rate = a->police.rate_bytes_ps; in vsc9959_psfp_filter_add()
2283 burst = rate * PSCHED_NS2TICKS(a->police.burst); in vsc9959_psfp_filter_add()
2288 ret = ocelot_vcap_policer_add(ocelot, index, &pol); in vsc9959_psfp_filter_add()
2292 sfi.fm_valid = 1; in vsc9959_psfp_filter_add()
2294 sfi.maxsdu = a->police.mtu; in vsc9959_psfp_filter_add()
2297 mutex_unlock(&psfp->lock); in vsc9959_psfp_filter_add()
2298 return -EOPNOTSUPP; in vsc9959_psfp_filter_add()
2306 sfi.prio_valid = (stream.prio < 0 ? 0 : 1); in vsc9959_psfp_filter_add()
2308 sfi.enable = 1; in vsc9959_psfp_filter_add()
2311 stream_entry = vsc9959_stream_table_lookup(&psfp->stream_list, &stream); in vsc9959_psfp_filter_add()
2313 if (stream_entry->ports & BIT(port)) { in vsc9959_psfp_filter_add()
2316 ret = -EEXIST; in vsc9959_psfp_filter_add()
2320 if (stream_entry->ports != BIT(stream_entry->port)) { in vsc9959_psfp_filter_add()
2323 ret = -EEXIST; in vsc9959_psfp_filter_add()
2327 stream_entry->ports |= BIT(port); in vsc9959_psfp_filter_add()
2328 stream.ports = stream_entry->ports; in vsc9959_psfp_filter_add()
2330 sfi_entry = vsc9959_psfp_sfi_table_get(&psfp->sfi_list, in vsc9959_psfp_filter_add()
2331 stream_entry->sfid); in vsc9959_psfp_filter_add()
2334 vsc9959_psfp_sfi_table_del(ocelot, stream_entry->sfid); in vsc9959_psfp_filter_add()
2336 old_sfi.portmask = stream_entry->ports; in vsc9959_psfp_filter_add()
2339 if (stream_entry->port > port) { in vsc9959_psfp_filter_add()
2340 ret = vsc9959_psfp_sfi_table_add2(ocelot, &sfi, in vsc9959_psfp_filter_add()
2342 stream_entry->dummy = true; in vsc9959_psfp_filter_add()
2344 ret = vsc9959_psfp_sfi_table_add2(ocelot, &old_sfi, in vsc9959_psfp_filter_add()
2351 stream_entry->sfid = old_sfi.index; in vsc9959_psfp_filter_add()
2353 ret = vsc9959_psfp_sfi_table_add(ocelot, &sfi); in vsc9959_psfp_filter_add()
2359 stream.sfid_valid = 1; in vsc9959_psfp_filter_add()
2360 ret = vsc9959_stream_table_add(ocelot, &psfp->stream_list, in vsc9959_psfp_filter_add()
2363 vsc9959_psfp_sfi_table_del(ocelot, stream.sfid); in vsc9959_psfp_filter_add()
2367 mutex_unlock(&psfp->lock); in vsc9959_psfp_filter_add()
2373 vsc9959_psfp_sgi_table_del(ocelot, sfi.sgid); in vsc9959_psfp_filter_add()
2376 ocelot_vcap_policer_del(ocelot, sfi.fmid); in vsc9959_psfp_filter_add()
2378 mutex_unlock(&psfp->lock); in vsc9959_psfp_filter_add()
2383 static int vsc9959_psfp_filter_del(struct ocelot *ocelot, in vsc9959_psfp_filter_del() argument
2387 struct ocelot_psfp_list *psfp = &ocelot->psfp; in vsc9959_psfp_filter_del()
2390 mutex_lock(&psfp->lock); in vsc9959_psfp_filter_del()
2392 stream = vsc9959_stream_table_get(&psfp->stream_list, f->cookie); in vsc9959_psfp_filter_del()
2394 mutex_unlock(&psfp->lock); in vsc9959_psfp_filter_del()
2395 return -ENOMEM; in vsc9959_psfp_filter_del()
2398 sfi = vsc9959_psfp_sfi_table_get(&psfp->sfi_list, stream->sfid); in vsc9959_psfp_filter_del()
2400 mutex_unlock(&psfp->lock); in vsc9959_psfp_filter_del()
2401 return -ENOMEM; in vsc9959_psfp_filter_del()
2404 if (sfi->sg_valid) in vsc9959_psfp_filter_del()
2405 vsc9959_psfp_sgi_table_del(ocelot, sfi->sgid); in vsc9959_psfp_filter_del()
2407 if (sfi->fm_valid) in vsc9959_psfp_filter_del()
2408 ocelot_vcap_policer_del(ocelot, sfi->fmid); in vsc9959_psfp_filter_del()
2410 vsc9959_psfp_sfi_table_del(ocelot, stream->sfid); in vsc9959_psfp_filter_del()
2414 stream->sfid_valid = 0; in vsc9959_psfp_filter_del()
2415 vsc9959_stream_table_del(ocelot, stream); in vsc9959_psfp_filter_del()
2417 stream_entry = vsc9959_stream_table_lookup(&psfp->stream_list, &tmp); in vsc9959_psfp_filter_del()
2419 stream_entry->ports = BIT(stream_entry->port); in vsc9959_psfp_filter_del()
2420 if (stream_entry->dummy) { in vsc9959_psfp_filter_del()
2421 stream_entry->dummy = false; in vsc9959_psfp_filter_del()
2422 vsc9959_mact_stream_set(ocelot, stream_entry, NULL); in vsc9959_psfp_filter_del()
2424 vsc9959_psfp_sfidmask_set(ocelot, stream_entry->sfid, in vsc9959_psfp_filter_del()
2425 stream_entry->ports); in vsc9959_psfp_filter_del()
2428 mutex_unlock(&psfp->lock); in vsc9959_psfp_filter_del()
2433 static void vsc9959_update_sfid_stats(struct ocelot *ocelot, in vsc9959_update_sfid_stats() argument
2436 struct felix_stream_filter_counters *s = &sfi->stats; in vsc9959_update_sfid_stats()
2438 u32 sfid = sfi->index; in vsc9959_update_sfid_stats()
2440 lockdep_assert_held(&ocelot->stat_view_lock); in vsc9959_update_sfid_stats()
2442 ocelot_rmw(ocelot, SYS_STAT_CFG_STAT_VIEW(sfid), in vsc9959_update_sfid_stats()
2446 match = ocelot_read(ocelot, SYS_COUNT_SF_MATCHING_FRAMES); in vsc9959_update_sfid_stats()
2447 not_pass_gate = ocelot_read(ocelot, SYS_COUNT_SF_NOT_PASSING_FRAMES); in vsc9959_update_sfid_stats()
2448 not_pass_sdu = ocelot_read(ocelot, SYS_COUNT_SF_NOT_PASSING_SDU); in vsc9959_update_sfid_stats()
2449 red = ocelot_read(ocelot, SYS_COUNT_SF_RED_FRAMES); in vsc9959_update_sfid_stats()
2452 ocelot_write(ocelot, in vsc9959_update_sfid_stats()
2457 s->match += match; in vsc9959_update_sfid_stats()
2458 s->not_pass_gate += not_pass_gate; in vsc9959_update_sfid_stats()
2459 s->not_pass_sdu += not_pass_sdu; in vsc9959_update_sfid_stats()
2460 s->red += red; in vsc9959_update_sfid_stats()
2463 /* Caller must hold &ocelot->stat_view_lock */
2464 static void vsc9959_update_stats(struct ocelot *ocelot) in vsc9959_update_stats() argument
2466 struct ocelot_psfp_list *psfp = &ocelot->psfp; in vsc9959_update_stats()
2469 mutex_lock(&psfp->lock); in vsc9959_update_stats()
2471 list_for_each_entry(sfi, &psfp->sfi_list, list) in vsc9959_update_stats()
2472 vsc9959_update_sfid_stats(ocelot, sfi); in vsc9959_update_stats()
2474 mutex_unlock(&psfp->lock); in vsc9959_update_stats()
2477 static int vsc9959_psfp_stats_get(struct ocelot *ocelot, in vsc9959_psfp_stats_get() argument
2481 struct ocelot_psfp_list *psfp = &ocelot->psfp; in vsc9959_psfp_stats_get()
2486 stream = vsc9959_stream_table_get(&psfp->stream_list, f->cookie); in vsc9959_psfp_stats_get()
2488 return -ENOMEM; in vsc9959_psfp_stats_get()
2490 sfi = vsc9959_psfp_sfi_table_get(&psfp->sfi_list, stream->sfid); in vsc9959_psfp_stats_get()
2492 return -EINVAL; in vsc9959_psfp_stats_get()
2494 mutex_lock(&ocelot->stat_view_lock); in vsc9959_psfp_stats_get()
2496 vsc9959_update_sfid_stats(ocelot, sfi); in vsc9959_psfp_stats_get()
2498 s = &sfi->stats; in vsc9959_psfp_stats_get()
2499 stats->pkts = s->match; in vsc9959_psfp_stats_get()
2500 stats->drops = s->not_pass_gate + s->not_pass_sdu + s->red; in vsc9959_psfp_stats_get()
2504 mutex_unlock(&ocelot->stat_view_lock); in vsc9959_psfp_stats_get()
2509 static void vsc9959_psfp_init(struct ocelot *ocelot) in vsc9959_psfp_init() argument
2511 struct ocelot_psfp_list *psfp = &ocelot->psfp; in vsc9959_psfp_init()
2513 INIT_LIST_HEAD(&psfp->stream_list); in vsc9959_psfp_init()
2514 INIT_LIST_HEAD(&psfp->sfi_list); in vsc9959_psfp_init()
2515 INIT_LIST_HEAD(&psfp->sgi_list); in vsc9959_psfp_init()
2516 mutex_init(&psfp->lock); in vsc9959_psfp_init()
2519 /* When using cut-through forwarding and the egress port runs at a higher data
2522 * The Felix switch implementation of cut-through forwarding does not check in
2524 * list of ports that have cut-through forwarding enabled on egress to only be
2528 static void vsc9959_cut_through_fwd(struct ocelot *ocelot) in vsc9959_cut_through_fwd() argument
2530 struct felix *felix = ocelot_to_felix(ocelot); in vsc9959_cut_through_fwd()
2531 struct dsa_switch *ds = felix->ds; in vsc9959_cut_through_fwd()
2534 lockdep_assert_held(&ocelot->fwd_domain_lock); in vsc9959_cut_through_fwd()
2536 for (port = 0; port < ocelot->num_phys_ports; port++) { in vsc9959_cut_through_fwd()
2537 struct ocelot_port *ocelot_port = ocelot->ports[port]; in vsc9959_cut_through_fwd()
2538 struct ocelot_mm_state *mm = &ocelot->mm[port]; in vsc9959_cut_through_fwd()
2539 int min_speed = ocelot_port->speed; in vsc9959_cut_through_fwd()
2543 /* Disable cut-through on ports that are down */ in vsc9959_cut_through_fwd()
2544 if (ocelot_port->speed <= 0) in vsc9959_cut_through_fwd()
2548 /* Ocelot switches forward from the NPI port towards in vsc9959_cut_through_fwd()
2554 mask = ocelot_get_bridge_fwd_mask(ocelot, port); in vsc9959_cut_through_fwd()
2556 if (ocelot->npi >= 0) in vsc9959_cut_through_fwd()
2557 mask |= BIT(ocelot->npi); in vsc9959_cut_through_fwd()
2559 mask |= ocelot_port_assigned_dsa_8021q_cpu_mask(ocelot, in vsc9959_cut_through_fwd()
2566 for_each_set_bit(other_port, &mask, ocelot->num_phys_ports) { in vsc9959_cut_through_fwd()
2569 other_ocelot_port = ocelot->ports[other_port]; in vsc9959_cut_through_fwd()
2570 if (other_ocelot_port->speed <= 0) in vsc9959_cut_through_fwd()
2573 if (min_speed > other_ocelot_port->speed) in vsc9959_cut_through_fwd()
2574 min_speed = other_ocelot_port->speed; in vsc9959_cut_through_fwd()
2577 /* Enable cut-through forwarding for all traffic classes that in vsc9959_cut_through_fwd()
2579 * bypassed in cut-through mode. Also exclude preemptible in vsc9959_cut_through_fwd()
2581 * reason, if sent as cut-through. in vsc9959_cut_through_fwd()
2583 if (ocelot_port->speed == min_speed) { in vsc9959_cut_through_fwd()
2584 val = GENMASK(7, 0) & ~mm->active_preemptible_tcs; in vsc9959_cut_through_fwd()
2587 if (vsc9959_port_qmaxsdu_get(ocelot, port, tc)) in vsc9959_cut_through_fwd()
2592 tmp = ocelot_read_rix(ocelot, ANA_CUT_THRU_CFG, port); in vsc9959_cut_through_fwd()
2596 dev_dbg(ocelot->dev, in vsc9959_cut_through_fwd()
2597 "port %d fwd mask 0x%lx speed %d min_speed %d, %s cut-through forwarding on TC mask 0x%x\n", in vsc9959_cut_through_fwd()
2598 port, mask, ocelot_port->speed, min_speed, in vsc9959_cut_through_fwd()
2601 ocelot_write_rix(ocelot, val, ANA_CUT_THRU_CFG, port); in vsc9959_cut_through_fwd()
2652 struct ocelot *ocelot = (struct ocelot *)data; in felix_irq_handler() local
2654 ocelot_get_txtstamp(ocelot); in felix_irq_handler()
2655 ocelot_mm_irq(ocelot); in felix_irq_handler()
2664 struct ocelot *ocelot; in felix_pci_probe() local
2668 if (pdev->dev.of_node && !of_device_is_available(pdev->dev.of_node)) { in felix_pci_probe()
2669 dev_info(&pdev->dev, "device is disabled, skipping\n"); in felix_pci_probe()
2670 return -ENODEV; in felix_pci_probe()
2675 dev_err(&pdev->dev, "device enable failed\n"); in felix_pci_probe()
2681 err = -ENOMEM; in felix_pci_probe()
2682 dev_err(&pdev->dev, "Failed to allocate driver memory\n"); in felix_pci_probe()
2687 ocelot = &felix->ocelot; in felix_pci_probe()
2688 ocelot->dev = &pdev->dev; in felix_pci_probe()
2689 ocelot->num_flooding_pgids = OCELOT_NUM_TC; in felix_pci_probe()
2690 felix->info = &felix_info_vsc9959; in felix_pci_probe()
2691 felix->switch_base = pci_resource_start(pdev, VSC9959_SWITCH_PCI_BAR); in felix_pci_probe()
2695 err = devm_request_threaded_irq(&pdev->dev, pdev->irq, NULL, in felix_pci_probe()
2697 "felix-intb", ocelot); in felix_pci_probe()
2699 dev_err(&pdev->dev, "Failed to request irq\n"); in felix_pci_probe()
2703 ocelot->ptp = 1; in felix_pci_probe()
2704 ocelot->mm_supported = true; in felix_pci_probe()
2708 err = -ENOMEM; in felix_pci_probe()
2709 dev_err(&pdev->dev, "Failed to allocate DSA switch\n"); in felix_pci_probe()
2713 ds->dev = &pdev->dev; in felix_pci_probe()
2714 ds->num_ports = felix->info->num_ports; in felix_pci_probe()
2715 ds->num_tx_queues = felix->info->num_tx_queues; in felix_pci_probe()
2716 ds->ops = &felix_switch_ops; in felix_pci_probe()
2717 ds->priv = ocelot; in felix_pci_probe()
2718 felix->ds = ds; in felix_pci_probe()
2719 felix->tag_proto = DSA_TAG_PROTO_OCELOT; in felix_pci_probe()
2723 dev_err_probe(&pdev->dev, err, "Failed to register DSA switch\n"); in felix_pci_probe()
2747 dsa_unregister_switch(felix->ds); in felix_pci_remove()
2749 kfree(felix->ds); in felix_pci_remove()
2762 dsa_switch_shutdown(felix->ds); in felix_pci_shutdown()