summaryrefslogtreecommitdiffstats
path: root/drivers/hid/intel-ish-hid/ishtp/loader.h
blob: 308b96085a4db4bd6fb23314c5e4d07b5c4df336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * ISHTP firmware loader header
 *
 * Copyright (c) 2024, Intel Corporation.
 */

#ifndef _ISHTP_LOADER_H_
#define _ISHTP_LOADER_H_

#include <linux/bits.h>
#include <linux/jiffies.h>
#include <linux/types.h>

#include "ishtp-dev.h"

struct work_struct;

#define LOADER_MSG_SIZE \
	(IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr))

/*
 * ISHTP firmware loader protocol definition
 */
#define LOADER_CMD_XFER_QUERY		0	/* SW -> FW */
#define LOADER_CMD_XFER_FRAGMENT	1	/* SW -> FW */
#define LOADER_CMD_START		2	/* SW -> FW */

/* Only support DMA mode */
#define LOADER_XFER_MODE_DMA BIT(0)

/**
 * union loader_msg_header - ISHTP firmware loader message header
 * @command: Command type
 * @is_response: Indicates if the message is a response
 * @has_next: Indicates if there is a next message
 * @reserved: Reserved for future use
 * @status: Status of the message
 * @val32: entire header as a 32-bit value
 */
union loader_msg_header {
	struct {
		__u32 command:7;
		__u32 is_response:1;
		__u32 has_next:1;
		__u32 reserved:15;
		__u32 status:8;
	};
	__u32 val32;
};

/**
 * struct loader_xfer_query - ISHTP firmware loader transfer query packet
 * @header: Header of the message
 * @image_size: Size of the image
 */
struct loader_xfer_query {
	__le32 header;
	__le32 image_size;
};

/**
 * struct loader_version - ISHTP firmware loader version
 * @value: Value of the version
 * @major: Major version
 * @minor: Minor version
 * @hotfix: Hotfix version
 * @build: Build version
 */
struct loader_version {
	union {
		__le32 value;
		struct {
			__u8 major;
			__u8 minor;
			__u8 hotfix;
			__u8 build;
		};
	};
};

/**
 * struct loader_capability - ISHTP firmware loader capability
 * @max_fw_image_size: Maximum firmware image size
 * @support_mode: Support mode
 * @reserved: Reserved for future use
 * @platform: Platform
 * @max_dma_buf_size: Maximum DMA buffer size, multiples of 4096
 */
struct loader_capability {
	__le32 max_fw_image_size;
	__le16 support_mode;
	__u8 reserved;
	__u8 platform;
	__le32 max_dma_buf_size;
};

/**
 * struct loader_xfer_query_ack - ISHTP firmware loader transfer query acknowledgment
 * @header: Header of the message
 * @version_major: ISH Major version
 * @version_minor: ISH Minor version
 * @version_hotfix: ISH Hotfix version
 * @version_build: ISH Build version
 * @protocol_version: Protocol version
 * @loader_version: Loader version
 * @capability: Loader capability
 */
struct loader_xfer_query_ack {
	__le32 header;
	__le16 version_major;
	__le16 version_minor;
	__le16 version_hotfix;
	__le16 version_build;
	__le32 protocol_version;
	struct loader_version loader_version;
	struct loader_capability capability;
};

/**
 * struct loader_xfer_fragment - ISHTP firmware loader transfer fragment
 * @header: Header of the message
 * @xfer_mode: Transfer mode
 * @offset: Offset
 * @size: Size
 * @is_last: Is last
 */
struct loader_xfer_fragment {
	__le32 header;
	__le32 xfer_mode;
	__le32 offset;
	__le32 size;
	__le32 is_last;
};

/**
 * struct loader_xfer_fragment_ack - ISHTP firmware loader transfer fragment acknowledgment
 * @header: Header of the message
 */
struct loader_xfer_fragment_ack {
	__le32 header;
};

/**
 * struct fragment_dscrpt - ISHTP firmware loader fragment descriptor
 * @ddr_adrs: The address in host DDR
 * @fw_off: The offset of the fragment in the fw image
 * @length: The length of the fragment
 */
struct fragment_dscrpt {
	__le64 ddr_adrs;
	__le32 fw_off;
	__le32 length;
};

#define FRAGMENT_MAX_NUM \
	((LOADER_MSG_SIZE - sizeof(struct loader_xfer_dma_fragment)) / \
	 sizeof(struct fragment_dscrpt))

/**
 * struct loader_xfer_dma_fragment - ISHTP firmware loader transfer DMA fragment
 * @fragment: Fragment
 * @fragment_cnt: How many descriptors in the fragment_tbl
 * @fragment_tbl: Fragment table
 */
struct loader_xfer_dma_fragment {
	struct loader_xfer_fragment fragment;
	__le32 fragment_cnt;
	struct fragment_dscrpt fragment_tbl[] __counted_by(fragment_cnt);
};

/**
 * struct loader_start - ISHTP firmware loader start
 * @header: Header of the message
 */
struct loader_start {
	__le32 header;
};

/**
 * struct loader_start_ack - ISHTP firmware loader start acknowledgment
 * @header: Header of the message
 */
struct loader_start_ack {
	__le32 header;
};

union loader_recv_message {
	__le32 header;
	struct loader_xfer_query_ack query_ack;
	struct loader_xfer_fragment_ack fragment_ack;
	struct loader_start_ack start_ack;
	__u8 raw_data[LOADER_MSG_SIZE];
};

/*
 * ISHTP firmware loader internal use
 */
/* ISHTP firmware loader command timeout */
#define ISHTP_LOADER_TIMEOUT msecs_to_jiffies(100)

/* ISHTP firmware loader retry times */
#define ISHTP_LOADER_RETRY_TIMES 3

/**
 * struct ish_firmware_variant - ISH firmware variant
 * @device: PCI Device ID
 * @filename: The firmware file name
 */
struct ish_firmware_variant {
	unsigned short device;
	const char *filename;
};

/*
 * ISHTP firmware loader API for ISHTP hbm
 */

/* ISHTP capability bit for firmware loader */
#define ISHTP_SUPPORT_CAP_LOADER BIT(4)

/* Firmware loader address */
#define ISHTP_LOADER_CLIENT_ADDR 16

/**
 * ishtp_loader_work - The work function to start the firmware loading process
 * @work: The work structure
 */
void ishtp_loader_work(struct work_struct *work);

#endif /* _ISHTP_LOADER_H_ */