fwctl.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /* Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES.
  3. */
  4. #ifndef _UAPI_FWCTL_H
  5. #define _UAPI_FWCTL_H
  6. #include <linux/types.h>
  7. #include <linux/ioctl.h>
  8. #define FWCTL_TYPE 0x9A
  9. /**
  10. * DOC: General ioctl format
  11. *
  12. * The ioctl interface follows a general format to allow for extensibility. Each
  13. * ioctl is passed a structure pointer as the argument providing the size of
  14. * the structure in the first u32. The kernel checks that any structure space
  15. * beyond what it understands is 0. This allows userspace to use the backward
  16. * compatible portion while consistently using the newer, larger, structures.
  17. *
  18. * ioctls use a standard meaning for common errnos:
  19. *
  20. * - ENOTTY: The IOCTL number itself is not supported at all
  21. * - E2BIG: The IOCTL number is supported, but the provided structure has
  22. * non-zero in a part the kernel does not understand.
  23. * - EOPNOTSUPP: The IOCTL number is supported, and the structure is
  24. * understood, however a known field has a value the kernel does not
  25. * understand or support.
  26. * - EINVAL: Everything about the IOCTL was understood, but a field is not
  27. * correct.
  28. * - ENOMEM: Out of memory.
  29. * - ENODEV: The underlying device has been hot-unplugged and the FD is
  30. * orphaned.
  31. *
  32. * As well as additional errnos, within specific ioctls.
  33. */
  34. enum {
  35. FWCTL_CMD_BASE = 0,
  36. FWCTL_CMD_INFO = 0,
  37. FWCTL_CMD_RPC = 1,
  38. };
  39. enum fwctl_device_type {
  40. FWCTL_DEVICE_TYPE_ERROR = 0,
  41. FWCTL_DEVICE_TYPE_MLX5 = 1,
  42. FWCTL_DEVICE_TYPE_CXL = 2,
  43. FWCTL_DEVICE_TYPE_PDS = 4,
  44. };
  45. /**
  46. * struct fwctl_info - ioctl(FWCTL_INFO)
  47. * @size: sizeof(struct fwctl_info)
  48. * @flags: Must be 0
  49. * @out_device_type: Returns the type of the device from enum fwctl_device_type
  50. * @device_data_len: On input the length of the out_device_data memory. On
  51. * output the size of the kernel's device_data which may be larger or
  52. * smaller than the input. Maybe 0 on input.
  53. * @out_device_data: Pointer to a memory of device_data_len bytes. Kernel will
  54. * fill the entire memory, zeroing as required.
  55. *
  56. * Returns basic information about this fwctl instance, particularly what driver
  57. * is being used to define the device_data format.
  58. */
  59. struct fwctl_info {
  60. __u32 size;
  61. __u32 flags;
  62. __u32 out_device_type;
  63. __u32 device_data_len;
  64. __aligned_u64 out_device_data;
  65. };
  66. #define FWCTL_INFO _IO(FWCTL_TYPE, FWCTL_CMD_INFO)
  67. /**
  68. * enum fwctl_rpc_scope - Scope of access for the RPC
  69. *
  70. * Refer to fwctl.rst for a more detailed discussion of these scopes.
  71. */
  72. enum fwctl_rpc_scope {
  73. /**
  74. * @FWCTL_RPC_CONFIGURATION: Device configuration access scope
  75. *
  76. * Read/write access to device configuration. When configuration
  77. * is written to the device it remains in a fully supported state.
  78. */
  79. FWCTL_RPC_CONFIGURATION = 0,
  80. /**
  81. * @FWCTL_RPC_DEBUG_READ_ONLY: Read only access to debug information
  82. *
  83. * Readable debug information. Debug information is compatible with
  84. * kernel lockdown, and does not disclose any sensitive information. For
  85. * instance exposing any encryption secrets from this information is
  86. * forbidden.
  87. */
  88. FWCTL_RPC_DEBUG_READ_ONLY = 1,
  89. /**
  90. * @FWCTL_RPC_DEBUG_WRITE: Writable access to lockdown compatible debug information
  91. *
  92. * Allows write access to data in the device which may leave a fully
  93. * supported state. This is intended to permit intensive and possibly
  94. * invasive debugging. This scope will taint the kernel.
  95. */
  96. FWCTL_RPC_DEBUG_WRITE = 2,
  97. /**
  98. * @FWCTL_RPC_DEBUG_WRITE_FULL: Write access to all debug information
  99. *
  100. * Allows read/write access to everything. Requires CAP_SYS_RAW_IO, so
  101. * it is not required to follow lockdown principals. If in doubt
  102. * debugging should be placed in this scope. This scope will taint the
  103. * kernel.
  104. */
  105. FWCTL_RPC_DEBUG_WRITE_FULL = 3,
  106. };
  107. /**
  108. * struct fwctl_rpc - ioctl(FWCTL_RPC)
  109. * @size: sizeof(struct fwctl_rpc)
  110. * @scope: One of enum fwctl_rpc_scope, required scope for the RPC
  111. * @in_len: Length of the in memory
  112. * @out_len: Length of the out memory
  113. * @in: Request message in device specific format
  114. * @out: Response message in device specific format
  115. *
  116. * Deliver a Remote Procedure Call to the device FW and return the response. The
  117. * call's parameters and return are marshaled into linear buffers of memory. Any
  118. * errno indicates that delivery of the RPC to the device failed. Return status
  119. * originating in the device during a successful delivery must be encoded into
  120. * out.
  121. *
  122. * The format of the buffers matches the out_device_type from FWCTL_INFO.
  123. */
  124. struct fwctl_rpc {
  125. __u32 size;
  126. __u32 scope;
  127. __u32 in_len;
  128. __u32 out_len;
  129. __aligned_u64 in;
  130. __aligned_u64 out;
  131. };
  132. #define FWCTL_RPC _IO(FWCTL_TYPE, FWCTL_CMD_RPC)
  133. #endif