Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-mlx5-hws-single-flow-counter-support'

Tariq Toukan says:

====================
net/mlx5: HWS single flow counter support

This small series refactors the flow counter bulk initialization code
and extends it so that single flow counters are also usable by hardware
steering (HWS) rules.

Patches 1-2 refactor the bulk init path: first by factoring out common
flow counter bulk initialization into mlx5_fc_bulk_init(), then by
splitting the bitmap allocation into mlx5_fs_bulk_bitmap_alloc(), with
no functional changes.

Patch 3 initializes bulk data for counters allocated via
mlx5_fc_single_alloc(), so they can be safely used by HWS rules.
====================

Link: https://patch.msgid.link/1768210825-1598472-1-git-send-email-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+55 -24
+2 -1
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
··· 308 308 }; 309 309 310 310 enum mlx5_fc_type { 311 - MLX5_FC_TYPE_ACQUIRED = 0, 311 + MLX5_FC_TYPE_POOL_ACQUIRED = 0, 312 + MLX5_FC_TYPE_SINGLE, 312 313 MLX5_FC_TYPE_LOCAL, 313 314 }; 314 315
+34 -13
drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
··· 153 153 static void mlx5_fc_free(struct mlx5_core_dev *dev, struct mlx5_fc *counter) 154 154 { 155 155 mlx5_cmd_fc_free(dev, counter->id); 156 + kfree(counter->bulk); 156 157 kfree(counter); 157 158 } 158 159 ··· 164 163 if (WARN_ON(counter->type == MLX5_FC_TYPE_LOCAL)) 165 164 return; 166 165 167 - if (counter->bulk) 166 + if (counter->type == MLX5_FC_TYPE_POOL_ACQUIRED) 168 167 mlx5_fc_pool_release_counter(&fc_stats->fc_pool, counter); 169 168 else 170 169 mlx5_fc_free(dev, counter); ··· 221 220 mlx5_fc_stats_query_all_counters(dev); 222 221 } 223 222 223 + static void mlx5_fc_bulk_init(struct mlx5_fc_bulk *fc_bulk, u32 base_id) 224 + { 225 + fc_bulk->base_id = base_id; 226 + refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0); 227 + mutex_init(&fc_bulk->hws_data.lock); 228 + } 229 + 224 230 static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev) 225 231 { 232 + struct mlx5_fc_bulk *fc_bulk; 226 233 struct mlx5_fc *counter; 227 234 int err; 228 235 ··· 238 229 if (!counter) 239 230 return ERR_PTR(-ENOMEM); 240 231 241 - err = mlx5_cmd_fc_alloc(dev, &counter->id); 242 - if (err) { 243 - kfree(counter); 244 - return ERR_PTR(err); 232 + fc_bulk = kzalloc(sizeof(*fc_bulk), GFP_KERNEL); 233 + if (!fc_bulk) { 234 + err = -ENOMEM; 235 + goto free_counter; 245 236 } 237 + err = mlx5_cmd_fc_alloc(dev, &counter->id); 238 + if (err) 239 + goto free_bulk; 246 240 241 + counter->type = MLX5_FC_TYPE_SINGLE; 242 + mlx5_fs_bulk_init(&fc_bulk->fs_bulk, 1); 243 + mlx5_fc_bulk_init(fc_bulk, counter->id); 244 + counter->bulk = fc_bulk; 247 245 return counter; 246 + 247 + free_bulk: 248 + kfree(fc_bulk); 249 + free_counter: 250 + kfree(counter); 251 + return ERR_PTR(err); 248 252 } 249 253 250 254 static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging) ··· 464 442 if (!fc_bulk) 465 443 return NULL; 466 444 467 - if (mlx5_fs_bulk_init(dev, &fc_bulk->fs_bulk, bulk_len)) 445 + mlx5_fs_bulk_init(&fc_bulk->fs_bulk, bulk_len); 446 + 447 + if (mlx5_fs_bulk_bitmap_alloc(dev, &fc_bulk->fs_bulk)) 468 448 goto fc_bulk_free; 469 449 470 450 if (mlx5_cmd_fc_bulk_alloc(dev, alloc_bitmask, &base_id)) 471 451 goto fs_bulk_cleanup; 472 - fc_bulk->base_id = base_id; 452 + 453 + mlx5_fc_bulk_init(fc_bulk, base_id); 473 454 for (i = 0; i < bulk_len; i++) 474 455 mlx5_fc_init(&fc_bulk->fcs[i], fc_bulk, base_id + i); 475 456 476 - refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0); 477 - mutex_init(&fc_bulk->hws_data.lock); 478 457 return &fc_bulk->fs_bulk; 479 458 480 459 fs_bulk_cleanup: ··· 583 560 584 561 counter->type = MLX5_FC_TYPE_LOCAL; 585 562 counter->id = counter_id; 586 - fc_bulk->base_id = counter_id - offset; 587 - fc_bulk->fs_bulk.bulk_len = bulk_size; 588 - refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0); 589 - mutex_init(&fc_bulk->hws_data.lock); 563 + mlx5_fs_bulk_init(&fc_bulk->fs_bulk, bulk_size); 564 + mlx5_fc_bulk_init(fc_bulk, counter_id - offset); 590 565 counter->bulk = fc_bulk; 591 566 refcount_set(&counter->fc_local_refcount, 1); 592 567 return counter;
+10 -6
drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c
··· 4 4 #include <mlx5_core.h> 5 5 #include "fs_pool.h" 6 6 7 - int mlx5_fs_bulk_init(struct mlx5_core_dev *dev, struct mlx5_fs_bulk *fs_bulk, 8 - int bulk_len) 7 + int mlx5_fs_bulk_bitmap_alloc(struct mlx5_core_dev *dev, 8 + struct mlx5_fs_bulk *fs_bulk) 9 9 { 10 10 int i; 11 11 12 - fs_bulk->bitmask = kvcalloc(BITS_TO_LONGS(bulk_len), sizeof(unsigned long), 13 - GFP_KERNEL); 12 + fs_bulk->bitmask = kvcalloc(BITS_TO_LONGS(fs_bulk->bulk_len), 13 + sizeof(unsigned long), GFP_KERNEL); 14 14 if (!fs_bulk->bitmask) 15 15 return -ENOMEM; 16 16 17 - fs_bulk->bulk_len = bulk_len; 18 - for (i = 0; i < bulk_len; i++) 17 + for (i = 0; i < fs_bulk->bulk_len; i++) 19 18 set_bit(i, fs_bulk->bitmask); 20 19 21 20 return 0; 21 + } 22 + 23 + void mlx5_fs_bulk_init(struct mlx5_fs_bulk *fs_bulk, int bulk_len) 24 + { 25 + fs_bulk->bulk_len = bulk_len; 22 26 } 23 27 24 28 void mlx5_fs_bulk_cleanup(struct mlx5_fs_bulk *fs_bulk)
+3 -2
drivers/net/ethernet/mellanox/mlx5/core/fs_pool.h
··· 39 39 int threshold; 40 40 }; 41 41 42 - int mlx5_fs_bulk_init(struct mlx5_core_dev *dev, struct mlx5_fs_bulk *fs_bulk, 43 - int bulk_len); 42 + void mlx5_fs_bulk_init(struct mlx5_fs_bulk *fs_bulk, int bulk_len); 43 + int mlx5_fs_bulk_bitmap_alloc(struct mlx5_core_dev *dev, 44 + struct mlx5_fs_bulk *fs_bulk); 44 45 void mlx5_fs_bulk_cleanup(struct mlx5_fs_bulk *fs_bulk); 45 46 int mlx5_fs_bulk_get_free_amount(struct mlx5_fs_bulk *bulk); 46 47
+6 -2
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c
··· 121 121 if (!pr_bulk) 122 122 return NULL; 123 123 124 - if (mlx5_fs_bulk_init(dev, &pr_bulk->fs_bulk, bulk_len)) 124 + mlx5_fs_bulk_init(&pr_bulk->fs_bulk, bulk_len); 125 + 126 + if (mlx5_fs_bulk_bitmap_alloc(dev, &pr_bulk->fs_bulk)) 125 127 goto free_pr_bulk; 126 128 127 129 for (i = 0; i < bulk_len; i++) { ··· 277 275 if (!mh_bulk) 278 276 return NULL; 279 277 280 - if (mlx5_fs_bulk_init(dev, &mh_bulk->fs_bulk, bulk_len)) 278 + mlx5_fs_bulk_init(&mh_bulk->fs_bulk, bulk_len); 279 + 280 + if (mlx5_fs_bulk_bitmap_alloc(dev, &mh_bulk->fs_bulk)) 281 281 goto free_mh_bulk; 282 282 283 283 for (int i = 0; i < bulk_len; i++) {