Skip to content

Commit

Permalink
net/mlx5: SF_DEV Add SF device trace points
Browse files Browse the repository at this point in the history
Add SF device add and delete specific trace points.

echo mlx5:mlx5_sf_dev_add >> /sys/kernel/debug/tracing/set_event
echo mlx5:mlx5_sf_dev_del >> /sys/kernel/debug/tracing/set_event
echo mlx5:mlx5_sf_vhca_event >> /sys/kernel/debug/tracing/set_event

Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
  • Loading branch information
Parav Pandit authored and Saeed Mahameed committed Oct 25, 2021
1 parent b3ccada commit d67ab0a
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 6 deletions.
21 changes: 21 additions & 0 deletions Documentation/networking/device_drivers/ethernet/mellanox/mlx5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,24 @@ SF tracepoints:
$ cat /sys/kernel/debug/tracing/trace
...
devlink-9519 [046] ..... 24624.400271: mlx5_sf_hwc_deferred_free: (0000:06:00.0) hw_id=0x8000

- mlx5_sf_vhca_event: trace SF vhca event and state::

$ echo mlx5:mlx5_sf_vhca_event >> /sys/kernel/debug/tracing/set_event
$ cat /sys/kernel/debug/tracing/trace
...
kworker/u128:3-9093 [046] ..... 24625.365525: mlx5_sf_vhca_event: (0000:06:00.0) hw_id=0x8000 sfnum=88 vhca_state=1

- mlx5_sf_dev_add : trace SF device add event::

$ echo mlx5:mlx5_sf_dev_add>> /sys/kernel/debug/tracing/set_event
$ cat /sys/kernel/debug/tracing/trace
...
kworker/u128:3-9093 [000] ..... 24616.524495: mlx5_sf_dev_add: (0000:06:00.0) sfdev=00000000fc5d96fd aux_id=4 hw_id=0x8000 sfnum=88

- mlx5_sf_dev_del : trace SF device delete event::

$ echo mlx5:mlx5_sf_dev_del >> /sys/kernel/debug/tracing/set_event
$ cat /sys/kernel/debug/tracing/trace
...
kworker/u128:3-9093 [044] ..... 24624.400749: mlx5_sf_dev_del: (0000:06:00.0) sfdev=00000000fc5d96fd aux_id=4 hw_id=0x8000 sfnum=88
23 changes: 17 additions & 6 deletions drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "sf/sf.h"
#include "sf/mlx5_ifc_vhca_event.h"
#include "ecpf.h"
#define CREATE_TRACE_POINTS
#include "diag/dev_tracepoint.h"

struct mlx5_sf_dev_table {
struct xarray devices;
Expand Down Expand Up @@ -66,13 +68,18 @@ static void mlx5_sf_dev_release(struct device *device)
kfree(sf_dev);
}

static void mlx5_sf_dev_remove(struct mlx5_sf_dev *sf_dev)
static void mlx5_sf_dev_remove(struct mlx5_core_dev *dev, struct mlx5_sf_dev *sf_dev)
{
int id;

id = sf_dev->adev.id;
trace_mlx5_sf_dev_del(dev, sf_dev, id);

auxiliary_device_delete(&sf_dev->adev);
auxiliary_device_uninit(&sf_dev->adev);
}

static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u32 sfnum)
static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u16 fn_id, u32 sfnum)
{
struct mlx5_sf_dev_table *table = dev->priv.sf_dev_table;
struct mlx5_sf_dev *sf_dev;
Expand Down Expand Up @@ -100,6 +107,7 @@ static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u32 sfnum)
sf_dev->adev.dev.groups = sf_attr_groups;
sf_dev->sfnum = sfnum;
sf_dev->parent_mdev = dev;
sf_dev->fn_id = fn_id;

if (!table->max_sfs) {
mlx5_adev_idx_free(id);
Expand All @@ -109,6 +117,8 @@ static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u32 sfnum)
}
sf_dev->bar_base_addr = table->base_address + (sf_index * table->sf_bar_length);

trace_mlx5_sf_dev_add(dev, sf_dev, id);

err = auxiliary_device_init(&sf_dev->adev);
if (err) {
mlx5_adev_idx_free(id);
Expand All @@ -128,7 +138,7 @@ static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u32 sfnum)
return;

xa_err:
mlx5_sf_dev_remove(sf_dev);
mlx5_sf_dev_remove(dev, sf_dev);
add_err:
mlx5_core_err(dev, "SF DEV: fail device add for index=%d sfnum=%d err=%d\n",
sf_index, sfnum, err);
Expand All @@ -139,7 +149,7 @@ static void mlx5_sf_dev_del(struct mlx5_core_dev *dev, struct mlx5_sf_dev *sf_de
struct mlx5_sf_dev_table *table = dev->priv.sf_dev_table;

xa_erase(&table->devices, sf_index);
mlx5_sf_dev_remove(sf_dev);
mlx5_sf_dev_remove(dev, sf_dev);
}

static int
Expand Down Expand Up @@ -178,7 +188,8 @@ mlx5_sf_dev_state_change_handler(struct notifier_block *nb, unsigned long event_
break;
case MLX5_VHCA_STATE_ACTIVE:
if (!sf_dev)
mlx5_sf_dev_add(table->dev, sf_index, event->sw_function_id);
mlx5_sf_dev_add(table->dev, sf_index, event->function_id,
event->sw_function_id);
break;
default:
break;
Expand Down Expand Up @@ -260,7 +271,7 @@ static void mlx5_sf_dev_destroy_all(struct mlx5_sf_dev_table *table)

xa_for_each(&table->devices, index, sf_dev) {
xa_erase(&table->devices, index);
mlx5_sf_dev_remove(sf_dev);
mlx5_sf_dev_remove(table->dev, sf_dev);
}
}

Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct mlx5_sf_dev {
struct mlx5_core_dev *mdev;
phys_addr_t bar_base_addr;
u32 sfnum;
u16 fn_id;
};

void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */

#undef TRACE_SYSTEM
#define TRACE_SYSTEM mlx5

#if !defined(_MLX5_SF_DEV_TP_) || defined(TRACE_HEADER_MULTI_READ)
#define _MLX5_SF_DEV_TP_

#include <linux/tracepoint.h>
#include <linux/mlx5/driver.h>
#include "../../dev/dev.h"

DECLARE_EVENT_CLASS(mlx5_sf_dev_template,
TP_PROTO(const struct mlx5_core_dev *dev,
const struct mlx5_sf_dev *sfdev,
int aux_id),
TP_ARGS(dev, sfdev, aux_id),
TP_STRUCT__entry(__string(devname, dev_name(dev->device))
__field(const struct mlx5_sf_dev*, sfdev)
__field(int, aux_id)
__field(u16, hw_fn_id)
__field(u32, sfnum)
),
TP_fast_assign(__assign_str(devname, dev_name(dev->device));
__entry->sfdev = sfdev;
__entry->aux_id = aux_id;
__entry->hw_fn_id = sfdev->fn_id;
__entry->sfnum = sfdev->sfnum;
),
TP_printk("(%s) sfdev=%pK aux_id=%d hw_id=0x%x sfnum=%u\n",
__get_str(devname), __entry->sfdev,
__entry->aux_id, __entry->hw_fn_id,
__entry->sfnum)
);

DEFINE_EVENT(mlx5_sf_dev_template, mlx5_sf_dev_add,
TP_PROTO(const struct mlx5_core_dev *dev,
const struct mlx5_sf_dev *sfdev,
int aux_id),
TP_ARGS(dev, sfdev, aux_id)
);

DEFINE_EVENT(mlx5_sf_dev_template, mlx5_sf_dev_del,
TP_PROTO(const struct mlx5_core_dev *dev,
const struct mlx5_sf_dev *sfdev,
int aux_id),
TP_ARGS(dev, sfdev, aux_id)
);

#endif /* _MLX5_SF_DEV_TP_ */

/* This part must be outside protection */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH sf/dev/diag
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE dev_tracepoint
#include <trace/define_trace.h>
40 changes: 40 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/sf/diag/vhca_tracepoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */

#undef TRACE_SYSTEM
#define TRACE_SYSTEM mlx5

#if !defined(_MLX5_SF_VHCA_TP_) || defined(TRACE_HEADER_MULTI_READ)
#define _MLX5_SF_VHCA_TP_

#include <linux/tracepoint.h>
#include <linux/mlx5/driver.h>
#include "sf/vhca_event.h"

TRACE_EVENT(mlx5_sf_vhca_event,
TP_PROTO(const struct mlx5_core_dev *dev,
const struct mlx5_vhca_state_event *event),
TP_ARGS(dev, event),
TP_STRUCT__entry(__string(devname, dev_name(dev->device))
__field(u16, hw_fn_id)
__field(u32, sfnum)
__field(u8, vhca_state)
),
TP_fast_assign(__assign_str(devname, dev_name(dev->device));
__entry->hw_fn_id = event->function_id;
__entry->sfnum = event->sw_function_id;
__entry->vhca_state = event->new_vhca_state;
),
TP_printk("(%s) hw_id=0x%x sfnum=%u vhca_state=%d\n",
__get_str(devname), __entry->hw_fn_id,
__entry->sfnum, __entry->vhca_state)
);

#endif /* _MLX5_SF_VHCA_TP_ */

/* This part must be outside protection */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH sf/diag
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE vhca_tracepoint
#include <trace/define_trace.h>
3 changes: 3 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/sf/vhca_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "mlx5_core.h"
#include "vhca_event.h"
#include "ecpf.h"
#define CREATE_TRACE_POINTS
#include "diag/vhca_tracepoint.h"

struct mlx5_vhca_state_notifier {
struct mlx5_core_dev *dev;
Expand Down Expand Up @@ -82,6 +84,7 @@ mlx5_vhca_event_notify(struct mlx5_core_dev *dev, struct mlx5_vhca_state_event *
vhca_state_context.vhca_state);

mlx5_vhca_event_arm(dev, event->function_id);
trace_mlx5_sf_vhca_event(dev, event);

blocking_notifier_call_chain(&dev->priv.vhca_state_notifier->n_head, 0, event);
}
Expand Down

0 comments on commit d67ab0a

Please sign in to comment.