Skip to content

Commit e893768

Browse files
jacob-kellerdavem330
authored andcommitted
devlink: prepare to support region operations
Modify the devlink region code in preparation for adding new operations on regions. Create a devlink_region_ops structure, and move the name pointer from within the devlink_region structure into the ops structure (similar to the devlink_health_reporter_ops). This prepares the regions to enable support of additional operations in the future such as requesting snapshots, or accessing the region directly without a snapshot. In order to re-use the constant strings in the mlx4 driver their declaration must be changed to 'const char * const' to ensure the compiler realizes that both the data and the pointer cannot change. Signed-off-by: Jacob Keller <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6739ce8 commit e893768

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

drivers/net/ethernet/mellanox/mlx4/crdump.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@
3838
#define CR_ENABLE_BIT_OFFSET 0xF3F04
3939
#define MAX_NUM_OF_DUMPS_TO_STORE (8)
4040

41-
static const char *region_cr_space_str = "cr-space";
42-
static const char *region_fw_health_str = "fw-health";
41+
static const char * const region_cr_space_str = "cr-space";
42+
static const char * const region_fw_health_str = "fw-health";
43+
44+
static const struct devlink_region_ops region_cr_space_ops = {
45+
.name = region_cr_space_str,
46+
};
47+
48+
static const struct devlink_region_ops region_fw_health_ops = {
49+
.name = region_fw_health_str,
50+
};
4351

4452
/* Set to true in case cr enable bit was set to true before crdump */
4553
static bool crdump_enbale_bit_set;
@@ -205,7 +213,7 @@ int mlx4_crdump_init(struct mlx4_dev *dev)
205213
/* Create cr-space region */
206214
crdump->region_crspace =
207215
devlink_region_create(devlink,
208-
region_cr_space_str,
216+
&region_cr_space_ops,
209217
MAX_NUM_OF_DUMPS_TO_STORE,
210218
pci_resource_len(pdev, 0));
211219
if (IS_ERR(crdump->region_crspace))
@@ -216,7 +224,7 @@ int mlx4_crdump_init(struct mlx4_dev *dev)
216224
/* Create fw-health region */
217225
crdump->region_fw_health =
218226
devlink_region_create(devlink,
219-
region_fw_health_str,
227+
&region_fw_health_ops,
220228
MAX_NUM_OF_DUMPS_TO_STORE,
221229
HEALTH_BUFFER_SIZE);
222230
if (IS_ERR(crdump->region_fw_health))

drivers/net/netdevsim/dev.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,15 @@ static void nsim_devlink_param_load_driverinit_values(struct devlink *devlink)
340340

341341
#define NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX 16
342342

343+
static const struct devlink_region_ops dummy_region_ops = {
344+
.name = "dummy",
345+
};
346+
343347
static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev,
344348
struct devlink *devlink)
345349
{
346350
nsim_dev->dummy_region =
347-
devlink_region_create(devlink, "dummy",
351+
devlink_region_create(devlink, &dummy_region_ops,
348352
NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX,
349353
NSIM_DEV_DUMMY_REGION_SIZE);
350354
return PTR_ERR_OR_ZERO(nsim_dev->dummy_region);

include/net/devlink.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ struct devlink_info_req;
498498

499499
typedef void devlink_snapshot_data_dest_t(const void *data);
500500

501+
/**
502+
* struct devlink_region_ops - Region operations
503+
* @name: region name
504+
*/
505+
struct devlink_region_ops {
506+
const char *name;
507+
};
508+
501509
struct devlink_fmsg;
502510
struct devlink_health_reporter;
503511

@@ -963,10 +971,10 @@ void devlink_port_param_value_changed(struct devlink_port *devlink_port,
963971
u32 param_id);
964972
void devlink_param_value_str_fill(union devlink_param_value *dst_val,
965973
const char *src);
966-
struct devlink_region *devlink_region_create(struct devlink *devlink,
967-
const char *region_name,
968-
u32 region_max_snapshots,
969-
u64 region_size);
974+
struct devlink_region *
975+
devlink_region_create(struct devlink *devlink,
976+
const struct devlink_region_ops *ops,
977+
u32 region_max_snapshots, u64 region_size);
970978
void devlink_region_destroy(struct devlink_region *region);
971979
u32 devlink_region_snapshot_id_get(struct devlink *devlink);
972980
int devlink_region_snapshot_create(struct devlink_region *region,

net/core/devlink.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ devlink_sb_tc_index_get_from_info(struct devlink_sb *devlink_sb,
344344
struct devlink_region {
345345
struct devlink *devlink;
346346
struct list_head list;
347-
const char *name;
347+
const struct devlink_region_ops *ops;
348348
struct list_head snapshot_list;
349349
u32 max_snapshots;
350350
u32 cur_snapshots;
@@ -365,7 +365,7 @@ devlink_region_get_by_name(struct devlink *devlink, const char *region_name)
365365
struct devlink_region *region;
366366

367367
list_for_each_entry(region, &devlink->region_list, list)
368-
if (!strcmp(region->name, region_name))
368+
if (!strcmp(region->ops->name, region_name))
369369
return region;
370370

371371
return NULL;
@@ -3695,7 +3695,7 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,
36953695
if (err)
36963696
goto nla_put_failure;
36973697

3698-
err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME, region->name);
3698+
err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME, region->ops->name);
36993699
if (err)
37003700
goto nla_put_failure;
37013701

@@ -3741,7 +3741,7 @@ static void devlink_nl_region_notify(struct devlink_region *region,
37413741
goto out_cancel_msg;
37423742

37433743
err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME,
3744-
region->name);
3744+
region->ops->name);
37453745
if (err)
37463746
goto out_cancel_msg;
37473747

@@ -7648,21 +7648,21 @@ EXPORT_SYMBOL_GPL(devlink_param_value_str_fill);
76487648
* devlink_region_create - create a new address region
76497649
*
76507650
* @devlink: devlink
7651-
* @region_name: region name
7651+
* @ops: region operations and name
76527652
* @region_max_snapshots: Maximum supported number of snapshots for region
76537653
* @region_size: size of region
76547654
*/
7655-
struct devlink_region *devlink_region_create(struct devlink *devlink,
7656-
const char *region_name,
7657-
u32 region_max_snapshots,
7658-
u64 region_size)
7655+
struct devlink_region *
7656+
devlink_region_create(struct devlink *devlink,
7657+
const struct devlink_region_ops *ops,
7658+
u32 region_max_snapshots, u64 region_size)
76597659
{
76607660
struct devlink_region *region;
76617661
int err = 0;
76627662

76637663
mutex_lock(&devlink->lock);
76647664

7665-
if (devlink_region_get_by_name(devlink, region_name)) {
7665+
if (devlink_region_get_by_name(devlink, ops->name)) {
76667666
err = -EEXIST;
76677667
goto unlock;
76687668
}
@@ -7675,7 +7675,7 @@ struct devlink_region *devlink_region_create(struct devlink *devlink,
76757675

76767676
region->devlink = devlink;
76777677
region->max_snapshots = region_max_snapshots;
7678-
region->name = region_name;
7678+
region->ops = ops;
76797679
region->size = region_size;
76807680
INIT_LIST_HEAD(&region->snapshot_list);
76817681
list_add_tail(&region->list, &devlink->region_list);

0 commit comments

Comments
 (0)