xref: /linux/drivers/platform/x86/intel/pmt/telemetry.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _TELEMETRY_H
3 #define _TELEMETRY_H
4 
5 /* Telemetry types */
6 #define PMT_TELEM_TELEMETRY	0
7 #define PMT_TELEM_CRASHLOG	1
8 
9 struct telem_endpoint;
10 struct pci_dev;
11 
12 struct telem_header {
13 	u8	access_type;
14 	u16	size;
15 	u32	guid;
16 	u32	base_offset;
17 };
18 
19 struct telem_endpoint_info {
20 	struct pci_dev		*pdev;
21 	struct telem_header	header;
22 };
23 
24 /**
25  * pmt_telem_get_next_endpoint() - Get next device id for a telemetry endpoint
26  * @start:  starting devid to look from
27  *
28  * This functions can be used in a while loop predicate to retrieve the devid
29  * of all available telemetry endpoints. Functions pmt_telem_get_next_endpoint()
30  * and pmt_telem_register_endpoint() can be used inside of the loop to examine
31  * endpoint info and register to receive a pointer to the endpoint. The pointer
32  * is then usable in the telemetry read calls to access the telemetry data.
33  *
34  * Return:
35  * * devid       - devid of the next present endpoint from start
36  * * 0           - when no more endpoints are present after start
37  */
38 unsigned long pmt_telem_get_next_endpoint(unsigned long start);
39 
40 /**
41  * pmt_telem_register_endpoint() - Register a telemetry endpoint
42  * @devid: device id/handle of the telemetry endpoint
43  *
44  * Increments the kref usage counter for the endpoint.
45  *
46  * Return:
47  * * endpoint    - On success returns pointer to the telemetry endpoint
48  * * -ENXIO      - telemetry endpoint not found
49  */
50 struct telem_endpoint *pmt_telem_register_endpoint(int devid);
51 
52 /**
53  * pmt_telem_unregister_endpoint() - Unregister a telemetry endpoint
54  * @ep:   ep structure to populate.
55  *
56  * Decrements the kref usage counter for the endpoint.
57  */
58 void pmt_telem_unregister_endpoint(struct telem_endpoint *ep);
59 
60 /**
61  * pmt_telem_get_endpoint_info() - Get info for an endpoint from its devid
62  * @devid:  device id/handle of the telemetry endpoint
63  * @info:   Endpoint info structure to be populated
64  *
65  * Return:
66  * * 0           - Success
67  * * -ENXIO      - telemetry endpoint not found for the devid
68  * * -EINVAL     - @info is NULL
69  */
70 int pmt_telem_get_endpoint_info(int devid, struct telem_endpoint_info *info);
71 
72 /**
73  * pmt_telem_find_and_register_endpoint() - Get a telemetry endpoint from
74  * pci_dev device, guid and pos
75  * @pdev:   PCI device inside the Intel vsec
76  * @guid:   GUID of the telemetry space
77  * @pos:    Instance of the guid
78  *
79  * Return:
80  * * endpoint    - On success returns pointer to the telemetry endpoint
81  * * -ENXIO      - telemetry endpoint not found
82  */
83 struct telem_endpoint *pmt_telem_find_and_register_endpoint(struct pci_dev *pcidev,
84 				u32 guid, u16 pos);
85 
86 /**
87  * pmt_telem_read() - Read qwords from counter sram using sample id
88  * @ep:     Telemetry endpoint to be read
89  * @id:     The beginning sample id of the metric(s) to be read
90  * @data:   Allocated qword buffer
91  * @count:  Number of qwords requested
92  *
93  * Callers must ensure reads are aligned. When the call returns -ENODEV,
94  * the device has been removed and callers should unregister the telemetry
95  * endpoint.
96  *
97  * Return:
98  * * 0           - Success
99  * * -ENODEV     - The device is not present.
100  * * -EINVAL     - The offset is out bounds
101  * * -EPIPE      - The device was removed during the read. Data written
102  *                 but should be considered invalid.
103  */
104 int pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, u32 count);
105 
106 /**
107  * pmt_telem_read32() - Read qwords from counter sram using sample id
108  * @ep:     Telemetry endpoint to be read
109  * @id:     The beginning sample id of the metric(s) to be read
110  * @data:   Allocated dword buffer
111  * @count:  Number of dwords requested
112  *
113  * Callers must ensure reads are aligned. When the call returns -ENODEV,
114  * the device has been removed and callers should unregister the telemetry
115  * endpoint.
116  *
117  * Return:
118  * * 0           - Success
119  * * -ENODEV     - The device is not present.
120  * * -EINVAL     - The offset is out bounds
121  * * -EPIPE      - The device was removed during the read. Data written
122  *                 but should be considered invalid.
123  */
124 int pmt_telem_read32(struct telem_endpoint *ep, u32 id, u32 *data, u32 count);
125 
126 #endif
127