Commit 5353599a authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: enetc: refactor enetc_setup_tc_taprio() to have a switch/case for cmd

Make enetc_setup_tc_taprio() more amenable to future extensions, like
reporting statistics.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6c1adb65
...@@ -2624,7 +2624,7 @@ static void enetc_debug_tx_ring_prios(struct enetc_ndev_priv *priv) ...@@ -2624,7 +2624,7 @@ static void enetc_debug_tx_ring_prios(struct enetc_ndev_priv *priv)
priv->tx_ring[i]->prio); priv->tx_ring[i]->prio);
} }
static void enetc_reset_tc_mqprio(struct net_device *ndev) void enetc_reset_tc_mqprio(struct net_device *ndev)
{ {
struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_ndev_priv *priv = netdev_priv(ndev);
struct enetc_hw *hw = &priv->si->hw; struct enetc_hw *hw = &priv->si->hw;
...@@ -2649,6 +2649,7 @@ static void enetc_reset_tc_mqprio(struct net_device *ndev) ...@@ -2649,6 +2649,7 @@ static void enetc_reset_tc_mqprio(struct net_device *ndev)
enetc_change_preemptible_tcs(priv, 0); enetc_change_preemptible_tcs(priv, 0);
} }
EXPORT_SYMBOL_GPL(enetc_reset_tc_mqprio);
int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data) int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
{ {
......
...@@ -429,6 +429,7 @@ struct net_device_stats *enetc_get_stats(struct net_device *ndev); ...@@ -429,6 +429,7 @@ struct net_device_stats *enetc_get_stats(struct net_device *ndev);
void enetc_set_features(struct net_device *ndev, netdev_features_t features); void enetc_set_features(struct net_device *ndev, netdev_features_t features);
int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd); int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd);
int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data); int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data);
void enetc_reset_tc_mqprio(struct net_device *ndev);
int enetc_setup_bpf(struct net_device *ndev, struct netdev_bpf *bpf); int enetc_setup_bpf(struct net_device *ndev, struct netdev_bpf *bpf);
int enetc_xdp_xmit(struct net_device *ndev, int num_frames, int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
struct xdp_frame **frames, u32 flags); struct xdp_frame **frames, u32 flags);
......
...@@ -43,10 +43,9 @@ void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed) ...@@ -43,10 +43,9 @@ void enetc_sched_speed_set(struct enetc_ndev_priv *priv, int speed)
enetc_port_wr(hw, ENETC_PMR, (tmp & ~ENETC_PMR_PSPEED_MASK) | pspeed); enetc_port_wr(hw, ENETC_PMR, (tmp & ~ENETC_PMR_PSPEED_MASK) | pspeed);
} }
static int enetc_setup_taprio(struct net_device *ndev, static int enetc_setup_taprio(struct enetc_ndev_priv *priv,
struct tc_taprio_qopt_offload *admin_conf) struct tc_taprio_qopt_offload *admin_conf)
{ {
struct enetc_ndev_priv *priv = netdev_priv(ndev);
struct enetc_hw *hw = &priv->si->hw; struct enetc_hw *hw = &priv->si->hw;
struct enetc_cbd cbd = {.cmd = 0}; struct enetc_cbd cbd = {.cmd = 0};
struct tgs_gcl_conf *gcl_config; struct tgs_gcl_conf *gcl_config;
...@@ -60,19 +59,13 @@ static int enetc_setup_taprio(struct net_device *ndev, ...@@ -60,19 +59,13 @@ static int enetc_setup_taprio(struct net_device *ndev,
int err; int err;
int i; int i;
/* TSD and Qbv are mutually exclusive in hardware */
for (i = 0; i < priv->num_tx_rings; i++)
if (priv->tx_ring[i]->tsd_enable)
return -EBUSY;
if (admin_conf->num_entries > enetc_get_max_gcl_len(hw)) if (admin_conf->num_entries > enetc_get_max_gcl_len(hw))
return -EINVAL; return -EINVAL;
gcl_len = admin_conf->num_entries;
tge = enetc_rd(hw, ENETC_PTGCR);
if (admin_conf->cmd == TAPRIO_CMD_DESTROY) {
enetc_wr(hw, ENETC_PTGCR, tge & ~ENETC_PTGCR_TGE);
enetc_reset_ptcmsdur(hw);
priv->active_offloads &= ~ENETC_F_QBV;
return 0;
}
if (admin_conf->cycle_time > U32_MAX || if (admin_conf->cycle_time > U32_MAX ||
admin_conf->cycle_time_extension > U32_MAX) admin_conf->cycle_time_extension > U32_MAX)
...@@ -82,6 +75,7 @@ static int enetc_setup_taprio(struct net_device *ndev, ...@@ -82,6 +75,7 @@ static int enetc_setup_taprio(struct net_device *ndev,
* control BD descriptor. * control BD descriptor.
*/ */
gcl_config = &cbd.gcl_conf; gcl_config = &cbd.gcl_conf;
gcl_len = admin_conf->num_entries;
data_size = struct_size(gcl_data, entry, gcl_len); data_size = struct_size(gcl_data, entry, gcl_len);
tmp = enetc_cbd_alloc_data_mem(priv->si, &cbd, data_size, tmp = enetc_cbd_alloc_data_mem(priv->si, &cbd, data_size,
...@@ -115,6 +109,7 @@ static int enetc_setup_taprio(struct net_device *ndev, ...@@ -115,6 +109,7 @@ static int enetc_setup_taprio(struct net_device *ndev,
cbd.cls = BDCR_CMD_PORT_GCL; cbd.cls = BDCR_CMD_PORT_GCL;
cbd.status_flags = 0; cbd.status_flags = 0;
tge = enetc_rd(hw, ENETC_PTGCR);
enetc_wr(hw, ENETC_PTGCR, tge | ENETC_PTGCR_TGE); enetc_wr(hw, ENETC_PTGCR, tge | ENETC_PTGCR_TGE);
err = enetc_send_cmd(priv->si, &cbd); err = enetc_send_cmd(priv->si, &cbd);
...@@ -132,29 +127,57 @@ static int enetc_setup_taprio(struct net_device *ndev, ...@@ -132,29 +127,57 @@ static int enetc_setup_taprio(struct net_device *ndev,
return 0; return 0;
} }
int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data) static void enetc_reset_taprio(struct enetc_ndev_priv *priv)
{
struct enetc_hw *hw = &priv->si->hw;
u32 val;
val = enetc_rd(hw, ENETC_PTGCR);
enetc_wr(hw, ENETC_PTGCR, val & ~ENETC_PTGCR_TGE);
enetc_reset_ptcmsdur(hw);
priv->active_offloads &= ~ENETC_F_QBV;
}
static void enetc_taprio_destroy(struct net_device *ndev)
{ {
struct tc_taprio_qopt_offload *taprio = type_data;
struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_ndev_priv *priv = netdev_priv(ndev);
int err, i;
if (taprio->cmd != TAPRIO_CMD_REPLACE && enetc_reset_taprio(priv);
taprio->cmd != TAPRIO_CMD_DESTROY) enetc_reset_tc_mqprio(ndev);
return -EOPNOTSUPP; }
/* TSD and Qbv are mutually exclusive in hardware */ static int enetc_taprio_replace(struct net_device *ndev,
for (i = 0; i < priv->num_tx_rings; i++) struct tc_taprio_qopt_offload *offload)
if (priv->tx_ring[i]->tsd_enable) {
return -EBUSY; struct enetc_ndev_priv *priv = netdev_priv(ndev);
int err;
err = enetc_setup_tc_mqprio(ndev, &taprio->mqprio); err = enetc_setup_tc_mqprio(ndev, &offload->mqprio);
if (err) if (err)
return err; return err;
err = enetc_setup_taprio(ndev, taprio); err = enetc_setup_taprio(priv, offload);
if (err) { if (err)
taprio->mqprio.qopt.num_tc = 0; enetc_reset_tc_mqprio(ndev);
enetc_setup_tc_mqprio(ndev, &taprio->mqprio);
return err;
}
int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data)
{
struct tc_taprio_qopt_offload *offload = type_data;
int err = 0;
switch (offload->cmd) {
case TAPRIO_CMD_REPLACE:
err = enetc_taprio_replace(ndev, offload);
break;
case TAPRIO_CMD_DESTROY:
enetc_taprio_destroy(ndev);
break;
default:
err = -EOPNOTSUPP;
} }
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment