diff options
author | Jiri Pirko <jiri@mellanox.com> | 2018-01-19 03:24:48 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-01-21 18:21:30 -0500 |
commit | c18c1e186ba872da73e944d9c54f027ea3899d39 (patch) | |
tree | bcf3bc571ae4c491f434b7bfe52c7e6c21fd4a4b | |
parent | 140ce421217e99f68a0108382e0789c1b1a15547 (diff) |
mlxsw: core: Make counter index allocated inside the action append
So far, the caller of mlxsw_afa_block_append_counter needed to allocate
counter index by hand. Benefit from the previously introduced resource
infra and counter_index_get/put callbacks, and allocate the counter
index in place where it is needed, inside the action append function.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
5 files changed, 82 insertions, 35 deletions
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c index 18ee66aac266..2e1a61c87c39 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c | |||
@@ -559,6 +559,53 @@ err_fwd_entry_get: | |||
559 | return ERR_PTR(err); | 559 | return ERR_PTR(err); |
560 | } | 560 | } |
561 | 561 | ||
562 | struct mlxsw_afa_counter { | ||
563 | struct mlxsw_afa_resource resource; | ||
564 | u32 counter_index; | ||
565 | }; | ||
566 | |||
567 | static void | ||
568 | mlxsw_afa_counter_destroy(struct mlxsw_afa_block *block, | ||
569 | struct mlxsw_afa_counter *counter) | ||
570 | { | ||
571 | block->afa->ops->counter_index_put(block->afa->ops_priv, | ||
572 | counter->counter_index); | ||
573 | kfree(counter); | ||
574 | } | ||
575 | |||
576 | static void | ||
577 | mlxsw_afa_counter_destructor(struct mlxsw_afa_block *block, | ||
578 | struct mlxsw_afa_resource *resource) | ||
579 | { | ||
580 | struct mlxsw_afa_counter *counter; | ||
581 | |||
582 | counter = container_of(resource, struct mlxsw_afa_counter, resource); | ||
583 | mlxsw_afa_counter_destroy(block, counter); | ||
584 | } | ||
585 | |||
586 | static struct mlxsw_afa_counter * | ||
587 | mlxsw_afa_counter_create(struct mlxsw_afa_block *block) | ||
588 | { | ||
589 | struct mlxsw_afa_counter *counter; | ||
590 | int err; | ||
591 | |||
592 | counter = kzalloc(sizeof(*counter), GFP_KERNEL); | ||
593 | if (!counter) | ||
594 | return ERR_PTR(-ENOMEM); | ||
595 | |||
596 | err = block->afa->ops->counter_index_get(block->afa->ops_priv, | ||
597 | &counter->counter_index); | ||
598 | if (err) | ||
599 | goto err_counter_index_get; | ||
600 | counter->resource.destructor = mlxsw_afa_counter_destructor; | ||
601 | mlxsw_afa_resource_add(block, &counter->resource); | ||
602 | return counter; | ||
603 | |||
604 | err_counter_index_get: | ||
605 | kfree(counter); | ||
606 | return ERR_PTR(err); | ||
607 | } | ||
608 | |||
562 | #define MLXSW_AFA_ONE_ACTION_LEN 32 | 609 | #define MLXSW_AFA_ONE_ACTION_LEN 32 |
563 | #define MLXSW_AFA_PAYLOAD_OFFSET 4 | 610 | #define MLXSW_AFA_PAYLOAD_OFFSET 4 |
564 | 611 | ||
@@ -876,11 +923,10 @@ mlxsw_afa_polcnt_pack(char *payload, | |||
876 | mlxsw_afa_polcnt_counter_index_set(payload, counter_index); | 923 | mlxsw_afa_polcnt_counter_index_set(payload, counter_index); |
877 | } | 924 | } |
878 | 925 | ||
879 | int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, | 926 | int mlxsw_afa_block_append_allocated_counter(struct mlxsw_afa_block *block, |
880 | u32 counter_index) | 927 | u32 counter_index) |
881 | { | 928 | { |
882 | char *act = mlxsw_afa_block_append_action(block, | 929 | char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_POLCNT_CODE, |
883 | MLXSW_AFA_POLCNT_CODE, | ||
884 | MLXSW_AFA_POLCNT_SIZE); | 930 | MLXSW_AFA_POLCNT_SIZE); |
885 | if (!act) | 931 | if (!act) |
886 | return -ENOBUFS; | 932 | return -ENOBUFS; |
@@ -888,6 +934,32 @@ int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, | |||
888 | counter_index); | 934 | counter_index); |
889 | return 0; | 935 | return 0; |
890 | } | 936 | } |
937 | EXPORT_SYMBOL(mlxsw_afa_block_append_allocated_counter); | ||
938 | |||
939 | int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, | ||
940 | u32 *p_counter_index) | ||
941 | { | ||
942 | struct mlxsw_afa_counter *counter; | ||
943 | u32 counter_index; | ||
944 | int err; | ||
945 | |||
946 | counter = mlxsw_afa_counter_create(block); | ||
947 | if (IS_ERR(counter)) | ||
948 | return PTR_ERR(counter); | ||
949 | counter_index = counter->counter_index; | ||
950 | |||
951 | err = mlxsw_afa_block_append_allocated_counter(block, counter_index); | ||
952 | if (err) | ||
953 | goto err_append_allocated_counter; | ||
954 | |||
955 | if (p_counter_index) | ||
956 | *p_counter_index = counter_index; | ||
957 | return 0; | ||
958 | |||
959 | err_append_allocated_counter: | ||
960 | mlxsw_afa_counter_destroy(block, counter); | ||
961 | return err; | ||
962 | } | ||
891 | EXPORT_SYMBOL(mlxsw_afa_block_append_counter); | 963 | EXPORT_SYMBOL(mlxsw_afa_block_append_counter); |
892 | 964 | ||
893 | /* Virtual Router and Forwarding Domain Action | 965 | /* Virtual Router and Forwarding Domain Action |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h index 89f977996ae2..a48c3d10688c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h | |||
@@ -69,8 +69,10 @@ int mlxsw_afa_block_append_fwd(struct mlxsw_afa_block *block, | |||
69 | u8 local_port, bool in_port); | 69 | u8 local_port, bool in_port); |
70 | int mlxsw_afa_block_append_vlan_modify(struct mlxsw_afa_block *block, | 70 | int mlxsw_afa_block_append_vlan_modify(struct mlxsw_afa_block *block, |
71 | u16 vid, u8 pcp, u8 et); | 71 | u16 vid, u8 pcp, u8 et); |
72 | int mlxsw_afa_block_append_allocated_counter(struct mlxsw_afa_block *block, | ||
73 | u32 counter_index); | ||
72 | int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, | 74 | int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, |
73 | u32 counter_index); | 75 | u32 *p_counter_index); |
74 | int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid); | 76 | int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid); |
75 | int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block, | 77 | int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block, |
76 | u16 expected_irif, u16 min_mtu, | 78 | u16 expected_irif, u16 min_mtu, |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index 58ff79211c09..8a30e76c99a9 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h | |||
@@ -457,7 +457,6 @@ struct mlxsw_sp_acl_rule_info { | |||
457 | struct mlxsw_afk_element_values values; | 457 | struct mlxsw_afk_element_values values; |
458 | struct mlxsw_afa_block *act_block; | 458 | struct mlxsw_afa_block *act_block; |
459 | unsigned int counter_index; | 459 | unsigned int counter_index; |
460 | bool counter_valid; | ||
461 | }; | 460 | }; |
462 | 461 | ||
463 | enum mlxsw_sp_acl_profile { | 462 | enum mlxsw_sp_acl_profile { |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c index 9439bfa4ecc2..fac7bf505466 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | |||
@@ -462,27 +462,6 @@ u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset) | |||
462 | return ops->ruleset_group_id(ruleset->priv); | 462 | return ops->ruleset_group_id(ruleset->priv); |
463 | } | 463 | } |
464 | 464 | ||
465 | static int | ||
466 | mlxsw_sp_acl_rulei_counter_alloc(struct mlxsw_sp *mlxsw_sp, | ||
467 | struct mlxsw_sp_acl_rule_info *rulei) | ||
468 | { | ||
469 | int err; | ||
470 | |||
471 | err = mlxsw_sp_flow_counter_alloc(mlxsw_sp, &rulei->counter_index); | ||
472 | if (err) | ||
473 | return err; | ||
474 | rulei->counter_valid = true; | ||
475 | return 0; | ||
476 | } | ||
477 | |||
478 | static void | ||
479 | mlxsw_sp_acl_rulei_counter_free(struct mlxsw_sp *mlxsw_sp, | ||
480 | struct mlxsw_sp_acl_rule_info *rulei) | ||
481 | { | ||
482 | rulei->counter_valid = false; | ||
483 | mlxsw_sp_flow_counter_free(mlxsw_sp, rulei->counter_index); | ||
484 | } | ||
485 | |||
486 | struct mlxsw_sp_acl_rule_info * | 465 | struct mlxsw_sp_acl_rule_info * |
487 | mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl) | 466 | mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl) |
488 | { | 467 | { |
@@ -619,7 +598,7 @@ int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp, | |||
619 | struct mlxsw_sp_acl_rule_info *rulei) | 598 | struct mlxsw_sp_acl_rule_info *rulei) |
620 | { | 599 | { |
621 | return mlxsw_afa_block_append_counter(rulei->act_block, | 600 | return mlxsw_afa_block_append_counter(rulei->act_block, |
622 | rulei->counter_index); | 601 | &rulei->counter_index); |
623 | } | 602 | } |
624 | 603 | ||
625 | int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp, | 604 | int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp, |
@@ -653,13 +632,8 @@ mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp, | |||
653 | goto err_rulei_create; | 632 | goto err_rulei_create; |
654 | } | 633 | } |
655 | 634 | ||
656 | err = mlxsw_sp_acl_rulei_counter_alloc(mlxsw_sp, rule->rulei); | ||
657 | if (err) | ||
658 | goto err_counter_alloc; | ||
659 | return rule; | 635 | return rule; |
660 | 636 | ||
661 | err_counter_alloc: | ||
662 | mlxsw_sp_acl_rulei_destroy(rule->rulei); | ||
663 | err_rulei_create: | 637 | err_rulei_create: |
664 | kfree(rule); | 638 | kfree(rule); |
665 | err_alloc: | 639 | err_alloc: |
@@ -672,7 +646,6 @@ void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp, | |||
672 | { | 646 | { |
673 | struct mlxsw_sp_acl_ruleset *ruleset = rule->ruleset; | 647 | struct mlxsw_sp_acl_ruleset *ruleset = rule->ruleset; |
674 | 648 | ||
675 | mlxsw_sp_acl_rulei_counter_free(mlxsw_sp, rule->rulei); | ||
676 | mlxsw_sp_acl_rulei_destroy(rule->rulei); | 649 | mlxsw_sp_acl_rulei_destroy(rule->rulei); |
677 | kfree(rule); | 650 | kfree(rule); |
678 | mlxsw_sp_acl_ruleset_ref_dec(mlxsw_sp, ruleset); | 651 | mlxsw_sp_acl_ruleset_ref_dec(mlxsw_sp, ruleset); |
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c index 34a0b632e5dd..4c7f32d4288d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c | |||
@@ -243,7 +243,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp, | |||
243 | if (!afa_block) | 243 | if (!afa_block) |
244 | return ERR_PTR(-ENOMEM); | 244 | return ERR_PTR(-ENOMEM); |
245 | 245 | ||
246 | err = mlxsw_afa_block_append_counter(afa_block, counter_index); | 246 | err = mlxsw_afa_block_append_allocated_counter(afa_block, |
247 | counter_index); | ||
247 | if (err) | 248 | if (err) |
248 | goto err; | 249 | goto err; |
249 | 250 | ||