Skip to content

Commit 5db81bd

Browse files
rogerqdavem330
authored andcommitted
net: ethernet: am65-cpsw: cleanup TAPRIO handling
Handle offloading commands using switch-case in am65_cpsw_setup_taprio(). Move checks to am65_cpsw_taprio_replace(). Use NL_SET_ERR_MSG_MOD for error messages. Change error message from "Failed to set cycle time extension" to "cycle time extension not supported" Signed-off-by: Roger Quadros <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d0f9535 commit 5db81bd

File tree

1 file changed

+71
-80
lines changed

1 file changed

+71
-80
lines changed

drivers/net/ethernet/ti/am65-cpsw-qos.c

Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static void am65_cpsw_stop_est(struct net_device *ndev)
428428
am65_cpsw_timer_stop(ndev);
429429
}
430430

431-
static void am65_cpsw_purge_est(struct net_device *ndev)
431+
static void am65_cpsw_taprio_destroy(struct net_device *ndev)
432432
{
433433
struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
434434

@@ -441,29 +441,66 @@ static void am65_cpsw_purge_est(struct net_device *ndev)
441441
port->qos.est_admin = NULL;
442442
}
443443

444-
static int am65_cpsw_configure_taprio(struct net_device *ndev,
445-
struct am65_cpsw_est *est_new)
444+
static void am65_cpsw_cp_taprio(struct tc_taprio_qopt_offload *from,
445+
struct tc_taprio_qopt_offload *to)
446+
{
447+
int i;
448+
449+
*to = *from;
450+
for (i = 0; i < from->num_entries; i++)
451+
to->entries[i] = from->entries[i];
452+
}
453+
454+
static int am65_cpsw_taprio_replace(struct net_device *ndev,
455+
struct tc_taprio_qopt_offload *taprio)
446456
{
447457
struct am65_cpsw_common *common = am65_ndev_to_common(ndev);
458+
struct netlink_ext_ack *extack = taprio->mqprio.extack;
459+
struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
448460
struct am65_cpts *cpts = common->cpts;
449-
int ret = 0, tact = TACT_PROG;
461+
struct am65_cpsw_est *est_new;
462+
int ret, tact;
450463

451-
am65_cpsw_est_update_state(ndev);
464+
if (!netif_running(ndev)) {
465+
NL_SET_ERR_MSG_MOD(extack, "interface is down, link speed unknown");
466+
return -ENETDOWN;
467+
}
452468

453-
if (est_new->taprio.cmd == TAPRIO_CMD_DESTROY) {
454-
am65_cpsw_stop_est(ndev);
455-
return ret;
469+
if (common->pf_p0_rx_ptype_rrobin) {
470+
NL_SET_ERR_MSG_MOD(extack,
471+
"p0-rx-ptype-rrobin flag conflicts with taprio qdisc");
472+
return -EINVAL;
473+
}
474+
475+
if (port->qos.link_speed == SPEED_UNKNOWN)
476+
return -ENOLINK;
477+
478+
if (taprio->cycle_time_extension) {
479+
NL_SET_ERR_MSG_MOD(extack,
480+
"cycle time extension not supported");
481+
return -EOPNOTSUPP;
456482
}
457483

484+
est_new = devm_kzalloc(&ndev->dev,
485+
struct_size(est_new, taprio.entries, taprio->num_entries),
486+
GFP_KERNEL);
487+
if (!est_new)
488+
return -ENOMEM;
489+
490+
am65_cpsw_cp_taprio(taprio, &est_new->taprio);
491+
492+
am65_cpsw_est_update_state(ndev);
493+
458494
ret = am65_cpsw_est_check_scheds(ndev, est_new);
459495
if (ret < 0)
460-
return ret;
496+
goto fail;
461497

462498
tact = am65_cpsw_timer_act(ndev, est_new);
463499
if (tact == TACT_NEED_STOP) {
464-
dev_err(&ndev->dev,
465-
"Can't toggle estf timer, stop taprio first");
466-
return -EINVAL;
500+
NL_SET_ERR_MSG_MOD(extack,
501+
"Can't toggle estf timer, stop taprio first");
502+
ret = -EINVAL;
503+
goto fail;
467504
}
468505

469506
if (tact == TACT_PROG)
@@ -476,62 +513,24 @@ static int am65_cpsw_configure_taprio(struct net_device *ndev,
476513
am65_cpsw_est_set_sched_list(ndev, est_new);
477514
am65_cpsw_port_est_assign_buf_num(ndev, est_new->buf);
478515

479-
am65_cpsw_est_set(ndev, est_new->taprio.cmd == TAPRIO_CMD_REPLACE);
516+
am65_cpsw_est_set(ndev, 1);
480517

481518
if (tact == TACT_PROG) {
482519
ret = am65_cpsw_timer_set(ndev, est_new);
483520
if (ret) {
484-
dev_err(&ndev->dev, "Failed to set cycle time");
485-
return ret;
521+
NL_SET_ERR_MSG_MOD(extack,
522+
"Failed to set cycle time");
523+
goto fail;
486524
}
487525
}
488526

489-
return ret;
490-
}
491-
492-
static void am65_cpsw_cp_taprio(struct tc_taprio_qopt_offload *from,
493-
struct tc_taprio_qopt_offload *to)
494-
{
495-
int i;
496-
497-
*to = *from;
498-
for (i = 0; i < from->num_entries; i++)
499-
to->entries[i] = from->entries[i];
500-
}
501-
502-
static int am65_cpsw_set_taprio(struct net_device *ndev, void *type_data)
503-
{
504-
struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
505-
struct tc_taprio_qopt_offload *taprio = type_data;
506-
struct am65_cpsw_est *est_new;
507-
int ret = 0;
508-
509-
if (taprio->cycle_time_extension) {
510-
dev_err(&ndev->dev, "Failed to set cycle time extension");
511-
return -EOPNOTSUPP;
512-
}
513-
514-
est_new = devm_kzalloc(&ndev->dev,
515-
struct_size(est_new, taprio.entries, taprio->num_entries),
516-
GFP_KERNEL);
517-
if (!est_new)
518-
return -ENOMEM;
519-
520-
am65_cpsw_cp_taprio(taprio, &est_new->taprio);
521-
ret = am65_cpsw_configure_taprio(ndev, est_new);
522-
if (!ret) {
523-
if (taprio->cmd == TAPRIO_CMD_REPLACE) {
524-
devm_kfree(&ndev->dev, port->qos.est_admin);
527+
devm_kfree(&ndev->dev, port->qos.est_admin);
528+
port->qos.est_admin = est_new;
525529

526-
port->qos.est_admin = est_new;
527-
} else {
528-
devm_kfree(&ndev->dev, est_new);
529-
am65_cpsw_purge_est(ndev);
530-
}
531-
} else {
532-
devm_kfree(&ndev->dev, est_new);
533-
}
530+
return 0;
534531

532+
fail:
533+
devm_kfree(&ndev->dev, est_new);
535534
return ret;
536535
}
537536

@@ -558,34 +557,26 @@ static void am65_cpsw_est_link_up(struct net_device *ndev, int link_speed)
558557
return;
559558

560559
purge_est:
561-
am65_cpsw_purge_est(ndev);
560+
am65_cpsw_taprio_destroy(ndev);
562561
}
563562

564563
static int am65_cpsw_setup_taprio(struct net_device *ndev, void *type_data)
565564
{
566-
struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
567565
struct tc_taprio_qopt_offload *taprio = type_data;
568-
struct am65_cpsw_common *common = port->common;
569-
570-
if (taprio->cmd != TAPRIO_CMD_REPLACE &&
571-
taprio->cmd != TAPRIO_CMD_DESTROY)
572-
return -EOPNOTSUPP;
573-
574-
if (!netif_running(ndev)) {
575-
dev_err(&ndev->dev, "interface is down, link speed unknown\n");
576-
return -ENETDOWN;
577-
}
578-
579-
if (common->pf_p0_rx_ptype_rrobin) {
580-
dev_err(&ndev->dev,
581-
"p0-rx-ptype-rrobin flag conflicts with taprio qdisc\n");
582-
return -EINVAL;
566+
int err = 0;
567+
568+
switch (taprio->cmd) {
569+
case TAPRIO_CMD_REPLACE:
570+
err = am65_cpsw_taprio_replace(ndev, taprio);
571+
break;
572+
case TAPRIO_CMD_DESTROY:
573+
am65_cpsw_taprio_destroy(ndev);
574+
break;
575+
default:
576+
err = -EOPNOTSUPP;
583577
}
584578

585-
if (port->qos.link_speed == SPEED_UNKNOWN)
586-
return -ENOLINK;
587-
588-
return am65_cpsw_set_taprio(ndev, type_data);
579+
return err;
589580
}
590581

591582
static int am65_cpsw_tc_query_caps(struct net_device *ndev, void *type_data)

0 commit comments

Comments
 (0)