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