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 * 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 u32 *request_pl; 49 size_t request_pl_sz; 50 u32 *response_pl; 51 size_t response_pl_sz; 52 int rv; 53 void (*complete)(struct pci_doe_task *task); 54 void *private; 55 56 /* No need for the user to initialize these fields */ 57 struct work_struct work; 58 struct pci_doe_mb *doe_mb; 59 }; 60 61 /** 62 * pci_doe_for_each_off - Iterate each DOE capability 63 * @pdev: struct pci_dev to iterate 64 * @off: u16 of config space offset of each mailbox capability found 65 */ 66 #define pci_doe_for_each_off(pdev, off) \ 67 for (off = pci_find_next_ext_capability(pdev, off, \ 68 PCI_EXT_CAP_ID_DOE); \ 69 off > 0; \ 70 off = pci_find_next_ext_capability(pdev, off, \ 71 PCI_EXT_CAP_ID_DOE)) 72 73 struct pci_doe_mb *pcim_doe_create_mb(struct pci_dev *pdev, u16 cap_offset); 74 bool pci_doe_supports_prot(struct pci_doe_mb *doe_mb, u16 vid, u8 type); 75 int pci_doe_submit_task(struct pci_doe_mb *doe_mb, struct pci_doe_task *task); 76 77 #endif 78