pci-doe.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Data Object Exchange
  4. * PCIe r6.0, sec 6.30 DOE
  5. *
  6. * Copyright (C) 2021 Huawei
  7. * Jonathan Cameron <[email protected]>
  8. *
  9. * Copyright (C) 2022 Intel Corporation
  10. * Ira Weiny <[email protected]>
  11. */
  12. #ifndef LINUX_PCI_DOE_H
  13. #define LINUX_PCI_DOE_H
  14. struct pci_doe_protocol {
  15. u16 vid;
  16. u8 type;
  17. };
  18. struct pci_doe_mb;
  19. /**
  20. * struct pci_doe_task - represents a single query/response
  21. *
  22. * @prot: DOE Protocol
  23. * @request_pl: The request payload
  24. * @request_pl_sz: Size of the request payload (bytes)
  25. * @response_pl: The response payload
  26. * @response_pl_sz: Size of the response payload (bytes)
  27. * @rv: Return value. Length of received response or error (bytes)
  28. * @complete: Called when task is complete
  29. * @private: Private data for the consumer
  30. * @work: Used internally by the mailbox
  31. * @doe_mb: Used internally by the mailbox
  32. *
  33. * Payloads are treated as opaque byte streams which are transmitted verbatim,
  34. * without byte-swapping. If payloads contain little-endian register values,
  35. * the caller is responsible for conversion with cpu_to_le32() / le32_to_cpu().
  36. *
  37. * The payload sizes and rv are specified in bytes with the following
  38. * restrictions concerning the protocol.
  39. *
  40. * 1) The request_pl_sz must be a multiple of double words (4 bytes)
  41. * 2) The response_pl_sz must be >= a single double word (4 bytes)
  42. * 3) rv is returned as bytes but it will be a multiple of double words
  43. *
  44. * NOTE there is no need for the caller to initialize work or doe_mb.
  45. */
  46. struct pci_doe_task {
  47. struct pci_doe_protocol prot;
  48. __le32 *request_pl;
  49. size_t request_pl_sz;
  50. __le32 *response_pl;
  51. size_t response_pl_sz;
  52. int rv;
  53. void (*complete)(struct pci_doe_task *task);
  54. void *private;
  55. /* No need for the user to initialize these fields */
  56. struct work_struct work;
  57. struct pci_doe_mb *doe_mb;
  58. };
  59. /**
  60. * pci_doe_for_each_off - Iterate each DOE capability
  61. * @pdev: struct pci_dev to iterate
  62. * @off: u16 of config space offset of each mailbox capability found
  63. */
  64. #define pci_doe_for_each_off(pdev, off) \
  65. for (off = pci_find_next_ext_capability(pdev, off, \
  66. PCI_EXT_CAP_ID_DOE); \
  67. off > 0; \
  68. off = pci_find_next_ext_capability(pdev, off, \
  69. PCI_EXT_CAP_ID_DOE))
  70. struct pci_doe_mb *pcim_doe_create_mb(struct pci_dev *pdev, u16 cap_offset);
  71. bool pci_doe_supports_prot(struct pci_doe_mb *doe_mb, u16 vid, u8 type);
  72. int pci_doe_submit_task(struct pci_doe_mb *doe_mb, struct pci_doe_task *task);
  73. #endif