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