net/sched: taprio: replace tc_taprio_qopt_offload :: enable with a "cmd" enum
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 30 May 2023 09:19:45 +0000 (12:19 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 May 2023 09:00:30 +0000 (10:00 +0100)
Inspired from struct flow_cls_offload :: cmd, in order for taprio to be
able to report statistics (which is future work), it seems that we need
to drill one step further with the ndo_setup_tc(TC_SETUP_QDISC_TAPRIO)
multiplexing, and pass the command as part of the common portion of the
muxed structure.

Since we already have an "enable" variable in tc_taprio_qopt_offload,
refactor all drivers to check for "cmd" instead of "enable", and reject
every other command except "replace" and "destroy" - to be future proof.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com> # for lan966x
Acked-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Reviewed-by: Muhammad Husaini Zulkifli <muhammad.husaini.zulkifli@intel.com>
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
12 files changed:
drivers/net/dsa/hirschmann/hellcreek.c
drivers/net/dsa/ocelot/felix_vsc9959.c
drivers/net/dsa/sja1105/sja1105_tas.c
drivers/net/ethernet/engleder/tsnep_selftests.c
drivers/net/ethernet/engleder/tsnep_tc.c
drivers/net/ethernet/freescale/enetc/enetc_qos.c
drivers/net/ethernet/intel/igc/igc_main.c
drivers/net/ethernet/microchip/lan966x/lan966x_tc.c
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
drivers/net/ethernet/ti/am65-cpsw-qos.c
include/net/pkt_sched.h
net/sched/sch_taprio.c

index 595a548..af50001 100644 (file)
@@ -1885,13 +1885,17 @@ static int hellcreek_port_setup_tc(struct dsa_switch *ds, int port,
        case TC_SETUP_QDISC_TAPRIO: {
                struct tc_taprio_qopt_offload *taprio = type_data;
 
-               if (!hellcreek_validate_schedule(hellcreek, taprio))
-                       return -EOPNOTSUPP;
+               switch (taprio->cmd) {
+               case TAPRIO_CMD_REPLACE:
+                       if (!hellcreek_validate_schedule(hellcreek, taprio))
+                               return -EOPNOTSUPP;
 
-               if (taprio->enable)
                        return hellcreek_port_set_schedule(ds, port, taprio);
-
-               return hellcreek_port_del_schedule(ds, port);
+               case TAPRIO_CMD_DESTROY:
+                       return hellcreek_port_del_schedule(ds, port);
+               default:
+                       return -EOPNOTSUPP;
+               }
        }
        default:
                return -EOPNOTSUPP;
index 030738f..5de6a27 100644 (file)
@@ -1411,7 +1411,7 @@ static int vsc9959_qos_port_tas_set(struct ocelot *ocelot, int port,
 
        mutex_lock(&ocelot->tas_lock);
 
-       if (!taprio->enable) {
+       if (taprio->cmd == TAPRIO_CMD_DESTROY) {
                ocelot_port_mqprio(ocelot, port, &taprio->mqprio);
                ocelot_rmw_rix(ocelot, 0, QSYS_TAG_CONFIG_ENABLE,
                               QSYS_TAG_CONFIG, port);
@@ -1423,6 +1423,8 @@ static int vsc9959_qos_port_tas_set(struct ocelot *ocelot, int port,
 
                mutex_unlock(&ocelot->tas_lock);
                return 0;
+       } else if (taprio->cmd != TAPRIO_CMD_REPLACE) {
+               return -EOPNOTSUPP;
        }
 
        ret = ocelot_port_mqprio(ocelot, port, &taprio->mqprio);
index e615384..d781871 100644 (file)
@@ -516,10 +516,11 @@ int sja1105_setup_tc_taprio(struct dsa_switch *ds, int port,
        /* Can't change an already configured port (must delete qdisc first).
         * Can't delete the qdisc from an unconfigured port.
         */
-       if (!!tas_data->offload[port] == admin->enable)
+       if ((!!tas_data->offload[port] && admin->cmd == TAPRIO_CMD_REPLACE) ||
+           (!tas_data->offload[port] && admin->cmd == TAPRIO_CMD_DESTROY))
                return -EINVAL;
 
-       if (!admin->enable) {
+       if (admin->cmd == TAPRIO_CMD_DESTROY) {
                taprio_offload_free(tas_data->offload[port]);
                tas_data->offload[port] = NULL;
 
@@ -528,6 +529,8 @@ int sja1105_setup_tc_taprio(struct dsa_switch *ds, int port,
                        return rc;
 
                return sja1105_static_config_reload(priv, SJA1105_SCHEDULING);
+       } else if (admin->cmd != TAPRIO_CMD_REPLACE) {
+               return -EOPNOTSUPP;
        }
 
        /* The cycle time extension is the amount of time the last cycle from
index 1581d6b..8a9145f 100644 (file)
@@ -329,7 +329,7 @@ static bool disable_taprio(struct tsnep_adapter *adapter)
        int retval;
 
        memset(&qopt, 0, sizeof(qopt));
-       qopt.enable = 0;
+       qopt.cmd = TAPRIO_CMD_DESTROY;
        retval = tsnep_tc_setup(adapter->netdev, TC_SETUP_QDISC_TAPRIO, &qopt);
        if (retval)
                return false;
@@ -360,7 +360,7 @@ static bool tsnep_test_taprio(struct tsnep_adapter *adapter)
        for (i = 0; i < 255; i++)
                qopt->entries[i].command = TC_TAPRIO_CMD_SET_GATES;
 
-       qopt->enable = 1;
+       qopt->cmd = TAPRIO_CMD_REPLACE;
        qopt->base_time = ktime_set(0, 0);
        qopt->cycle_time = 1500000;
        qopt->cycle_time_extension = 0;
@@ -382,7 +382,7 @@ static bool tsnep_test_taprio(struct tsnep_adapter *adapter)
        if (!run_taprio(adapter, qopt, 100))
                goto failed;
 
-       qopt->enable = 1;
+       qopt->cmd = TAPRIO_CMD_REPLACE;
        qopt->base_time = ktime_set(0, 0);
        qopt->cycle_time = 411854;
        qopt->cycle_time_extension = 0;
@@ -406,7 +406,7 @@ static bool tsnep_test_taprio(struct tsnep_adapter *adapter)
        if (!run_taprio(adapter, qopt, 100))
                goto failed;
 
-       qopt->enable = 1;
+       qopt->cmd = TAPRIO_CMD_REPLACE;
        qopt->base_time = ktime_set(0, 0);
        delay_base_time(adapter, qopt, 12);
        qopt->cycle_time = 125000;
@@ -457,7 +457,7 @@ static bool tsnep_test_taprio_change(struct tsnep_adapter *adapter)
        for (i = 0; i < 255; i++)
                qopt->entries[i].command = TC_TAPRIO_CMD_SET_GATES;
 
-       qopt->enable = 1;
+       qopt->cmd = TAPRIO_CMD_REPLACE;
        qopt->base_time = ktime_set(0, 0);
        qopt->cycle_time = 100000;
        qopt->cycle_time_extension = 0;
@@ -610,7 +610,7 @@ static bool tsnep_test_taprio_extension(struct tsnep_adapter *adapter)
        for (i = 0; i < 255; i++)
                qopt->entries[i].command = TC_TAPRIO_CMD_SET_GATES;
 
-       qopt->enable = 1;
+       qopt->cmd = TAPRIO_CMD_REPLACE;
        qopt->base_time = ktime_set(0, 0);
        qopt->cycle_time = 100000;
        qopt->cycle_time_extension = 50000;
index d083e66..745b191 100644 (file)
@@ -325,7 +325,7 @@ static int tsnep_taprio(struct tsnep_adapter *adapter,
        if (!adapter->gate_control)
                return -EOPNOTSUPP;
 
-       if (!qopt->enable) {
+       if (qopt->cmd == TAPRIO_CMD_DESTROY) {
                /* disable gate control if active */
                mutex_lock(&adapter->gate_control_lock);
 
@@ -337,6 +337,8 @@ static int tsnep_taprio(struct tsnep_adapter *adapter,
                mutex_unlock(&adapter->gate_control_lock);
 
                return 0;
+       } else if (qopt->cmd != TAPRIO_CMD_REPLACE) {
+               return -EOPNOTSUPP;
        }
 
        retval = tsnep_validate_gcl(qopt);
index 83c27bb..7aad824 100644 (file)
@@ -65,7 +65,7 @@ static int enetc_setup_taprio(struct net_device *ndev,
        gcl_len = admin_conf->num_entries;
 
        tge = enetc_rd(hw, ENETC_PTGCR);
-       if (!admin_conf->enable) {
+       if (admin_conf->cmd == TAPRIO_CMD_DESTROY) {
                enetc_wr(hw, ENETC_PTGCR, tge & ~ENETC_PTGCR_TGE);
                enetc_reset_ptcmsdur(hw);
 
@@ -138,6 +138,10 @@ int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data)
        struct enetc_ndev_priv *priv = netdev_priv(ndev);
        int err, i;
 
+       if (taprio->cmd != TAPRIO_CMD_REPLACE &&
+           taprio->cmd != TAPRIO_CMD_DESTROY)
+               return -EOPNOTSUPP;
+
        /* TSD and Qbv are mutually exclusive in hardware */
        for (i = 0; i < priv->num_tx_rings; i++)
                if (priv->tx_ring[i]->tsd_enable)
index c5ef1ed..88145c3 100644 (file)
@@ -6113,9 +6113,18 @@ static int igc_save_qbv_schedule(struct igc_adapter *adapter,
        size_t n;
        int i;
 
-       adapter->qbv_enable = qopt->enable;
+       switch (qopt->cmd) {
+       case TAPRIO_CMD_REPLACE:
+               adapter->qbv_enable = true;
+               break;
+       case TAPRIO_CMD_DESTROY:
+               adapter->qbv_enable = false;
+               break;
+       default:
+               return -EOPNOTSUPP;
+       }
 
-       if (!qopt->enable)
+       if (!adapter->qbv_enable)
                return igc_tsn_clear_schedule(adapter);
 
        if (qopt->base_time < 0)
index cf0cc75..ee652f2 100644 (file)
@@ -21,8 +21,14 @@ static int lan966x_tc_setup_qdisc_mqprio(struct lan966x_port *port,
 static int lan966x_tc_setup_qdisc_taprio(struct lan966x_port *port,
                                         struct tc_taprio_qopt_offload *taprio)
 {
-       return taprio->enable ? lan966x_taprio_add(port, taprio) :
-                               lan966x_taprio_del(port);
+       switch (taprio->cmd) {
+       case TAPRIO_CMD_REPLACE:
+               return lan966x_taprio_add(port, taprio);
+       case TAPRIO_CMD_DESTROY:
+               return lan966x_taprio_del(port);
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static int lan966x_tc_setup_qdisc_tbf(struct lan966x_port *port,
index 9d55226..ac41ef4 100644 (file)
@@ -966,8 +966,11 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
                return -EOPNOTSUPP;
        }
 
-       if (!qopt->enable)
+       if (qopt->cmd == TAPRIO_CMD_DESTROY)
                goto disable;
+       else if (qopt->cmd != TAPRIO_CMD_REPLACE)
+               return -EOPNOTSUPP;
+
        if (qopt->num_entries >= dep)
                return -EINVAL;
        if (!qopt->cycle_time)
@@ -988,7 +991,7 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
 
        mutex_lock(&priv->plat->est->lock);
        priv->plat->est->gcl_size = size;
-       priv->plat->est->enable = qopt->enable;
+       priv->plat->est->enable = qopt->cmd == TAPRIO_CMD_REPLACE;
        mutex_unlock(&priv->plat->est->lock);
 
        for (i = 0; i < size; i++) {
index 3a908db..eced87f 100644 (file)
@@ -450,7 +450,7 @@ static int am65_cpsw_configure_taprio(struct net_device *ndev,
 
        am65_cpsw_est_update_state(ndev);
 
-       if (!est_new->taprio.enable) {
+       if (est_new->taprio.cmd == TAPRIO_CMD_DESTROY) {
                am65_cpsw_stop_est(ndev);
                return ret;
        }
@@ -476,7 +476,7 @@ static int am65_cpsw_configure_taprio(struct net_device *ndev,
        am65_cpsw_est_set_sched_list(ndev, est_new);
        am65_cpsw_port_est_assign_buf_num(ndev, est_new->buf);
 
-       am65_cpsw_est_set(ndev, est_new->taprio.enable);
+       am65_cpsw_est_set(ndev, est_new->taprio.cmd == TAPRIO_CMD_REPLACE);
 
        if (tact == TACT_PROG) {
                ret = am65_cpsw_timer_set(ndev, est_new);
@@ -520,7 +520,7 @@ static int am65_cpsw_set_taprio(struct net_device *ndev, void *type_data)
        am65_cpsw_cp_taprio(taprio, &est_new->taprio);
        ret = am65_cpsw_configure_taprio(ndev, est_new);
        if (!ret) {
-               if (taprio->enable) {
+               if (taprio->cmd == TAPRIO_CMD_REPLACE) {
                        devm_kfree(&ndev->dev, port->qos.est_admin);
 
                        port->qos.est_admin = est_new;
@@ -564,8 +564,13 @@ purge_est:
 static int am65_cpsw_setup_taprio(struct net_device *ndev, void *type_data)
 {
        struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
+       struct tc_taprio_qopt_offload *taprio = type_data;
        struct am65_cpsw_common *common = port->common;
 
+       if (taprio->cmd != TAPRIO_CMD_REPLACE &&
+           taprio->cmd != TAPRIO_CMD_DESTROY)
+               return -EOPNOTSUPP;
+
        if (!IS_ENABLED(CONFIG_TI_AM65_CPSW_TAS))
                return -ENODEV;
 
index f436688..f5fb11d 100644 (file)
@@ -185,6 +185,11 @@ struct tc_taprio_caps {
        bool broken_mqprio:1;
 };
 
+enum tc_taprio_qopt_cmd {
+       TAPRIO_CMD_REPLACE,
+       TAPRIO_CMD_DESTROY,
+};
+
 struct tc_taprio_sched_entry {
        u8 command; /* TC_TAPRIO_CMD_* */
 
@@ -196,7 +201,7 @@ struct tc_taprio_sched_entry {
 struct tc_taprio_qopt_offload {
        struct tc_mqprio_qopt_offload mqprio;
        struct netlink_ext_ack *extack;
-       u8 enable;
+       enum tc_taprio_qopt_cmd cmd;
        ktime_t base_time;
        u64 cycle_time;
        u64 cycle_time_extension;
index d29e678..06bf4c6 100644 (file)
@@ -1524,7 +1524,7 @@ static int taprio_enable_offload(struct net_device *dev,
                               "Not enough memory for enabling offload mode");
                return -ENOMEM;
        }
-       offload->enable = 1;
+       offload->cmd = TAPRIO_CMD_REPLACE;
        offload->extack = extack;
        mqprio_qopt_reconstruct(dev, &offload->mqprio.qopt);
        offload->mqprio.extack = extack;
@@ -1572,7 +1572,7 @@ static int taprio_disable_offload(struct net_device *dev,
                               "Not enough memory to disable offload mode");
                return -ENOMEM;
        }
-       offload->enable = 0;
+       offload->cmd = TAPRIO_CMD_DESTROY;
 
        err = ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TAPRIO, offload);
        if (err < 0) {