162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci==============
462306a36Sopenharmony_ciDevlink Region
562306a36Sopenharmony_ci==============
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci``devlink`` regions enable access to driver defined address regions using
862306a36Sopenharmony_cidevlink.
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciEach device can create and register its own supported address regions. The
1162306a36Sopenharmony_ciregion can then be accessed via the devlink region interface.
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciRegion snapshots are collected by the driver, and can be accessed via read
1462306a36Sopenharmony_cior dump commands. This allows future analysis on the created snapshots.
1562306a36Sopenharmony_ciRegions may optionally support triggering snapshots on demand.
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciSnapshot identifiers are scoped to the devlink instance, not a region.
1862306a36Sopenharmony_ciAll snapshots with the same snapshot id within a devlink instance
1962306a36Sopenharmony_cicorrespond to the same event.
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciThe major benefit to creating a region is to provide access to internal
2262306a36Sopenharmony_ciaddress regions that are otherwise inaccessible to the user.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciRegions may also be used to provide an additional way to debug complex error
2562306a36Sopenharmony_cistates, but see also Documentation/networking/devlink/devlink-health.rst
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciRegions may optionally support capturing a snapshot on demand via the
2862306a36Sopenharmony_ci``DEVLINK_CMD_REGION_NEW`` netlink message. A driver wishing to allow
2962306a36Sopenharmony_cirequested snapshots must implement the ``.snapshot`` callback for the region
3062306a36Sopenharmony_ciin its ``devlink_region_ops`` structure. If snapshot id is not set in
3162306a36Sopenharmony_cithe ``DEVLINK_CMD_REGION_NEW`` request kernel will allocate one and send
3262306a36Sopenharmony_cithe snapshot information to user space.
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciRegions may optionally allow directly reading from their contents without a
3562306a36Sopenharmony_cisnapshot. Direct read requests are not atomic. In particular a read request
3662306a36Sopenharmony_ciof size 256 bytes or larger will be split into multiple chunks. If atomic
3762306a36Sopenharmony_ciaccess is required, use a snapshot. A driver wishing to enable this for a
3862306a36Sopenharmony_ciregion should implement the ``.read`` callback in the ``devlink_region_ops``
3962306a36Sopenharmony_cistructure. User space can request a direct read by using the
4062306a36Sopenharmony_ci``DEVLINK_ATTR_REGION_DIRECT`` attribute instead of specifying a snapshot
4162306a36Sopenharmony_ciid.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciexample usage
4462306a36Sopenharmony_ci-------------
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci.. code:: shell
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci    $ devlink region help
4962306a36Sopenharmony_ci    $ devlink region show [ DEV/REGION ]
5062306a36Sopenharmony_ci    $ devlink region del DEV/REGION snapshot SNAPSHOT_ID
5162306a36Sopenharmony_ci    $ devlink region dump DEV/REGION [ snapshot SNAPSHOT_ID ]
5262306a36Sopenharmony_ci    $ devlink region read DEV/REGION [ snapshot SNAPSHOT_ID ] address ADDRESS length length
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci    # Show all of the exposed regions with region sizes:
5562306a36Sopenharmony_ci    $ devlink region show
5662306a36Sopenharmony_ci    pci/0000:00:05.0/cr-space: size 1048576 snapshot [1 2] max 8
5762306a36Sopenharmony_ci    pci/0000:00:05.0/fw-health: size 64 snapshot [1 2] max 8
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci    # Delete a snapshot using:
6062306a36Sopenharmony_ci    $ devlink region del pci/0000:00:05.0/cr-space snapshot 1
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci    # Request an immediate snapshot, if supported by the region
6362306a36Sopenharmony_ci    $ devlink region new pci/0000:00:05.0/cr-space
6462306a36Sopenharmony_ci    pci/0000:00:05.0/cr-space: snapshot 5
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci    # Dump a snapshot:
6762306a36Sopenharmony_ci    $ devlink region dump pci/0000:00:05.0/fw-health snapshot 1
6862306a36Sopenharmony_ci    0000000000000000 0014 95dc 0014 9514 0035 1670 0034 db30
6962306a36Sopenharmony_ci    0000000000000010 0000 0000 ffff ff04 0029 8c00 0028 8cc8
7062306a36Sopenharmony_ci    0000000000000020 0016 0bb8 0016 1720 0000 0000 c00f 3ffc
7162306a36Sopenharmony_ci    0000000000000030 bada cce5 bada cce5 bada cce5 bada cce5
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci    # Read a specific part of a snapshot:
7462306a36Sopenharmony_ci    $ devlink region read pci/0000:00:05.0/fw-health snapshot 1 address 0 length 16
7562306a36Sopenharmony_ci    0000000000000000 0014 95dc 0014 9514 0035 1670 0034 db30
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci    # Read from the region without a snapshot
7862306a36Sopenharmony_ci    $ devlink region read pci/0000:00:05.0/fw-health address 16 length 16
7962306a36Sopenharmony_ci    0000000000000010 0000 0000 ffff ff04 0029 8c00 0028 8cc8
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ciAs regions are likely very device or driver specific, no generic regions are
8262306a36Sopenharmony_cidefined. See the driver-specific documentation files for information on the
8362306a36Sopenharmony_cispecific regions a driver supports.
84