]>
Commit | Line | Data |
---|---|---|
bb1b0133 TW |
1 | /* |
2 | * | |
3 | * Intel Management Engine Interface (Intel MEI) Linux driver | |
4 | * Copyright (c) 2003-2012, Intel Corporation. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | */ | |
16 | ||
4fcbc99b | 17 | #include <linux/export.h> |
bb1b0133 TW |
18 | #include <linux/sched.h> |
19 | #include <linux/wait.h> | |
180ea05b | 20 | #include <linux/pm_runtime.h> |
1f180359 TW |
21 | #include <linux/slab.h> |
22 | ||
23 | #include <linux/mei.h> | |
bb1b0133 TW |
24 | |
25 | #include "mei_dev.h" | |
0edb23fc | 26 | #include "hbm.h" |
12d00665 | 27 | #include "client.h" |
bb1b0133 | 28 | |
89778d6e TW |
29 | static const char *mei_hbm_status_str(enum mei_hbm_status status) |
30 | { | |
31 | #define MEI_HBM_STATUS(status) case MEI_HBMS_##status: return #status | |
32 | switch (status) { | |
33 | MEI_HBM_STATUS(SUCCESS); | |
34 | MEI_HBM_STATUS(CLIENT_NOT_FOUND); | |
35 | MEI_HBM_STATUS(ALREADY_EXISTS); | |
36 | MEI_HBM_STATUS(REJECTED); | |
37 | MEI_HBM_STATUS(INVALID_PARAMETER); | |
38 | MEI_HBM_STATUS(NOT_ALLOWED); | |
39 | MEI_HBM_STATUS(ALREADY_STARTED); | |
40 | MEI_HBM_STATUS(NOT_STARTED); | |
41 | default: return "unknown"; | |
42 | } | |
43 | #undef MEI_HBM_STATUS | |
44 | }; | |
45 | ||
285e2996 AU |
46 | static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status) |
47 | { | |
48 | #define MEI_CL_CS(status) case MEI_CL_CONN_##status: return #status | |
49 | switch (status) { | |
50 | MEI_CL_CS(SUCCESS); | |
51 | MEI_CL_CS(NOT_FOUND); | |
52 | MEI_CL_CS(ALREADY_STARTED); | |
53 | MEI_CL_CS(OUT_OF_RESOURCES); | |
54 | MEI_CL_CS(MESSAGE_SMALL); | |
71e117f2 | 55 | MEI_CL_CS(NOT_ALLOWED); |
285e2996 AU |
56 | default: return "unknown"; |
57 | } | |
58 | #undef MEI_CL_CCS | |
59 | } | |
60 | ||
1beeb4b9 AU |
61 | const char *mei_hbm_state_str(enum mei_hbm_state state) |
62 | { | |
63 | #define MEI_HBM_STATE(state) case MEI_HBM_##state: return #state | |
64 | switch (state) { | |
65 | MEI_HBM_STATE(IDLE); | |
66 | MEI_HBM_STATE(STARTING); | |
67 | MEI_HBM_STATE(STARTED); | |
68 | MEI_HBM_STATE(ENUM_CLIENTS); | |
69 | MEI_HBM_STATE(CLIENT_PROPERTIES); | |
70 | MEI_HBM_STATE(STOPPED); | |
71 | default: | |
72 | return "unknown"; | |
73 | } | |
74 | #undef MEI_HBM_STATE | |
75 | } | |
76 | ||
285e2996 AU |
77 | /** |
78 | * mei_cl_conn_status_to_errno - convert client connect response | |
79 | * status to error code | |
80 | * | |
81 | * @status: client connect response status | |
82 | * | |
a8605ea2 | 83 | * Return: corresponding error code |
285e2996 AU |
84 | */ |
85 | static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status) | |
86 | { | |
87 | switch (status) { | |
88 | case MEI_CL_CONN_SUCCESS: return 0; | |
89 | case MEI_CL_CONN_NOT_FOUND: return -ENOTTY; | |
90 | case MEI_CL_CONN_ALREADY_STARTED: return -EBUSY; | |
91 | case MEI_CL_CONN_OUT_OF_RESOURCES: return -EBUSY; | |
92 | case MEI_CL_CONN_MESSAGE_SMALL: return -EINVAL; | |
71e117f2 | 93 | case MEI_CL_CONN_NOT_ALLOWED: return -EBUSY; |
285e2996 AU |
94 | default: return -EINVAL; |
95 | } | |
96 | } | |
97 | ||
84b3294a TW |
98 | /** |
99 | * mei_hbm_idle - set hbm to idle state | |
100 | * | |
101 | * @dev: the device structure | |
102 | */ | |
103 | void mei_hbm_idle(struct mei_device *dev) | |
104 | { | |
105 | dev->init_clients_timer = 0; | |
106 | dev->hbm_state = MEI_HBM_IDLE; | |
107 | } | |
108 | ||
25ca6472 TW |
109 | /** |
110 | * mei_hbm_reset - reset hbm counters and book keeping data structurs | |
111 | * | |
112 | * @dev: the device structure | |
113 | */ | |
114 | void mei_hbm_reset(struct mei_device *dev) | |
115 | { | |
79563db9 | 116 | mei_me_cl_rm_all(dev); |
84b3294a TW |
117 | |
118 | mei_hbm_idle(dev); | |
119 | } | |
120 | ||
2190fe2a TW |
121 | /** |
122 | * mei_hbm_hdr - construct hbm header | |
123 | * | |
124 | * @hdr: hbm header | |
125 | * @length: payload length | |
126 | */ | |
127 | ||
128 | static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length) | |
129 | { | |
130 | hdr->host_addr = 0; | |
131 | hdr->me_addr = 0; | |
132 | hdr->length = length; | |
133 | hdr->msg_complete = 1; | |
134 | hdr->reserved = 0; | |
c0ff9019 | 135 | hdr->internal = 0; |
2190fe2a TW |
136 | } |
137 | ||
cd51ed64 TW |
138 | /** |
139 | * mei_hbm_cl_hdr - construct client hbm header | |
393b148f | 140 | * |
68d1aa65 | 141 | * @cl: client |
cd51ed64 TW |
142 | * @hbm_cmd: host bus message command |
143 | * @buf: buffer for cl header | |
144 | * @len: buffer length | |
145 | */ | |
146 | static inline | |
147 | void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len) | |
148 | { | |
149 | struct mei_hbm_cl_cmd *cmd = buf; | |
150 | ||
151 | memset(cmd, 0, len); | |
152 | ||
153 | cmd->hbm_cmd = hbm_cmd; | |
1df629ef | 154 | cmd->host_addr = mei_cl_host_addr(cl); |
d49ed64a | 155 | cmd->me_addr = mei_cl_me_id(cl); |
cd51ed64 TW |
156 | } |
157 | ||
68d1aa65 TW |
158 | /** |
159 | * mei_hbm_cl_write - write simple hbm client message | |
160 | * | |
161 | * @dev: the device structure | |
162 | * @cl: client | |
163 | * @hbm_cmd: host bus message command | |
041330d9 | 164 | * @buf: message buffer |
68d1aa65 | 165 | * @len: buffer length |
ce23139c AU |
166 | * |
167 | * Return: 0 on success, <0 on failure. | |
68d1aa65 | 168 | */ |
3fcbab6c TW |
169 | static inline int mei_hbm_cl_write(struct mei_device *dev, struct mei_cl *cl, |
170 | u8 hbm_cmd, void *buf, size_t len) | |
68d1aa65 | 171 | { |
c0ff9019 | 172 | struct mei_msg_hdr mei_hdr; |
68d1aa65 | 173 | |
c0ff9019 AU |
174 | mei_hbm_hdr(&mei_hdr, len); |
175 | mei_hbm_cl_hdr(cl, hbm_cmd, buf, len); | |
68d1aa65 | 176 | |
c0ff9019 | 177 | return mei_write_message(dev, &mei_hdr, buf); |
68d1aa65 TW |
178 | } |
179 | ||
cd51ed64 | 180 | /** |
2af89db1 TW |
181 | * mei_hbm_cl_addr_equal - check if the client's and |
182 | * the message address match | |
cd51ed64 | 183 | * |
2af89db1 TW |
184 | * @cl: client |
185 | * @cmd: hbm client message | |
cd51ed64 | 186 | * |
a8605ea2 | 187 | * Return: true if addresses are the same |
cd51ed64 TW |
188 | */ |
189 | static inline | |
2af89db1 | 190 | bool mei_hbm_cl_addr_equal(struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) |
cd51ed64 | 191 | { |
1df629ef | 192 | return mei_cl_host_addr(cl) == cmd->host_addr && |
d49ed64a | 193 | mei_cl_me_id(cl) == cmd->me_addr; |
cd51ed64 TW |
194 | } |
195 | ||
2af89db1 TW |
196 | /** |
197 | * mei_hbm_cl_find_by_cmd - find recipient client | |
198 | * | |
199 | * @dev: the device structure | |
200 | * @buf: a buffer with hbm cl command | |
201 | * | |
a8605ea2 | 202 | * Return: the recipient client or NULL if not found |
2af89db1 TW |
203 | */ |
204 | static inline | |
205 | struct mei_cl *mei_hbm_cl_find_by_cmd(struct mei_device *dev, void *buf) | |
206 | { | |
207 | struct mei_hbm_cl_cmd *cmd = (struct mei_hbm_cl_cmd *)buf; | |
208 | struct mei_cl *cl; | |
209 | ||
210 | list_for_each_entry(cl, &dev->file_list, link) | |
211 | if (mei_hbm_cl_addr_equal(cl, cmd)) | |
212 | return cl; | |
213 | return NULL; | |
214 | } | |
215 | ||
216 | ||
cb02efc3 AU |
217 | /** |
218 | * mei_hbm_start_wait - wait for start response message. | |
219 | * | |
220 | * @dev: the device structure | |
221 | * | |
a8605ea2 | 222 | * Return: 0 on success and < 0 on failure |
cb02efc3 | 223 | */ |
9b0d5efc TW |
224 | int mei_hbm_start_wait(struct mei_device *dev) |
225 | { | |
226 | int ret; | |
cb02efc3 AU |
227 | |
228 | if (dev->hbm_state > MEI_HBM_STARTING) | |
9b0d5efc TW |
229 | return 0; |
230 | ||
231 | mutex_unlock(&dev->device_lock); | |
cb02efc3 AU |
232 | ret = wait_event_timeout(dev->wait_hbm_start, |
233 | dev->hbm_state != MEI_HBM_STARTING, | |
7d93e58d | 234 | mei_secs_to_jiffies(MEI_HBM_TIMEOUT)); |
9b0d5efc TW |
235 | mutex_lock(&dev->device_lock); |
236 | ||
cb02efc3 | 237 | if (ret == 0 && (dev->hbm_state <= MEI_HBM_STARTING)) { |
9b0d5efc | 238 | dev->hbm_state = MEI_HBM_IDLE; |
2bf94cab | 239 | dev_err(dev->dev, "waiting for mei start failed\n"); |
7ca96aa2 | 240 | return -ETIME; |
9b0d5efc TW |
241 | } |
242 | return 0; | |
243 | } | |
244 | ||
bb1b0133 | 245 | /** |
8120e720 | 246 | * mei_hbm_start_req - sends start request message. |
bb1b0133 TW |
247 | * |
248 | * @dev: the device structure | |
544f9460 | 249 | * |
a8605ea2 | 250 | * Return: 0 on success and < 0 on failure |
bb1b0133 | 251 | */ |
9b0d5efc | 252 | int mei_hbm_start_req(struct mei_device *dev) |
bb1b0133 | 253 | { |
c0ff9019 AU |
254 | struct mei_msg_hdr mei_hdr; |
255 | struct hbm_host_version_request start_req; | |
bb1b0133 | 256 | const size_t len = sizeof(struct hbm_host_version_request); |
544f9460 | 257 | int ret; |
bb1b0133 | 258 | |
5ca2d388 TW |
259 | mei_hbm_reset(dev); |
260 | ||
c0ff9019 | 261 | mei_hbm_hdr(&mei_hdr, len); |
bb1b0133 TW |
262 | |
263 | /* host start message */ | |
c0ff9019 AU |
264 | memset(&start_req, 0, len); |
265 | start_req.hbm_cmd = HOST_START_REQ_CMD; | |
266 | start_req.host_version.major_version = HBM_MAJOR_VERSION; | |
267 | start_req.host_version.minor_version = HBM_MINOR_VERSION; | |
bb1b0133 | 268 | |
9b0d5efc | 269 | dev->hbm_state = MEI_HBM_IDLE; |
c0ff9019 | 270 | ret = mei_write_message(dev, &mei_hdr, &start_req); |
544f9460 | 271 | if (ret) { |
2bf94cab | 272 | dev_err(dev->dev, "version message write failed: ret = %d\n", |
544f9460 TW |
273 | ret); |
274 | return ret; | |
bb1b0133 | 275 | } |
544f9460 | 276 | |
cb02efc3 | 277 | dev->hbm_state = MEI_HBM_STARTING; |
bb1b0133 | 278 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
1892fc2e | 279 | mei_schedule_stall_timer(dev); |
9b0d5efc | 280 | return 0; |
bb1b0133 TW |
281 | } |
282 | ||
99c2658f | 283 | /** |
8120e720 | 284 | * mei_hbm_enum_clients_req - sends enumeration client request message. |
bb1b0133 TW |
285 | * |
286 | * @dev: the device structure | |
287 | * | |
a8605ea2 | 288 | * Return: 0 on success and < 0 on failure |
bb1b0133 | 289 | */ |
544f9460 | 290 | static int mei_hbm_enum_clients_req(struct mei_device *dev) |
bb1b0133 | 291 | { |
c0ff9019 AU |
292 | struct mei_msg_hdr mei_hdr; |
293 | struct hbm_host_enum_request enum_req; | |
bb1b0133 | 294 | const size_t len = sizeof(struct hbm_host_enum_request); |
544f9460 TW |
295 | int ret; |
296 | ||
bb1b0133 | 297 | /* enumerate clients */ |
c0ff9019 | 298 | mei_hbm_hdr(&mei_hdr, len); |
bb1b0133 | 299 | |
c0ff9019 AU |
300 | memset(&enum_req, 0, len); |
301 | enum_req.hbm_cmd = HOST_ENUM_REQ_CMD; | |
302 | enum_req.flags |= dev->hbm_f_dc_supported ? | |
303 | MEI_HBM_ENUM_F_ALLOW_ADD : 0; | |
304 | enum_req.flags |= dev->hbm_f_ie_supported ? | |
305 | MEI_HBM_ENUM_F_IMMEDIATE_ENUM : 0; | |
bb1b0133 | 306 | |
c0ff9019 | 307 | ret = mei_write_message(dev, &mei_hdr, &enum_req); |
544f9460 | 308 | if (ret) { |
2bf94cab | 309 | dev_err(dev->dev, "enumeration request write failed: ret = %d.\n", |
544f9460 TW |
310 | ret); |
311 | return ret; | |
bb1b0133 | 312 | } |
9b0d5efc | 313 | dev->hbm_state = MEI_HBM_ENUM_CLIENTS; |
bb1b0133 | 314 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
1892fc2e | 315 | mei_schedule_stall_timer(dev); |
544f9460 | 316 | return 0; |
bb1b0133 TW |
317 | } |
318 | ||
99c2658f | 319 | /** |
5ca2d388 TW |
320 | * mei_hbm_me_cl_add - add new me client to the list |
321 | * | |
322 | * @dev: the device structure | |
323 | * @res: hbm property response | |
324 | * | |
a8605ea2 | 325 | * Return: 0 on success and -ENOMEM on allocation failure |
5ca2d388 TW |
326 | */ |
327 | ||
328 | static int mei_hbm_me_cl_add(struct mei_device *dev, | |
329 | struct hbm_props_response *res) | |
330 | { | |
331 | struct mei_me_client *me_cl; | |
79563db9 TW |
332 | const uuid_le *uuid = &res->client_properties.protocol_name; |
333 | ||
334 | mei_me_cl_rm_by_uuid(dev, uuid); | |
5ca2d388 TW |
335 | |
336 | me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL); | |
337 | if (!me_cl) | |
338 | return -ENOMEM; | |
339 | ||
79563db9 TW |
340 | mei_me_cl_init(me_cl); |
341 | ||
5ca2d388 TW |
342 | me_cl->props = res->client_properties; |
343 | me_cl->client_id = res->me_addr; | |
4034b81b | 344 | me_cl->tx_flow_ctrl_creds = 0; |
5ca2d388 | 345 | |
b7d88514 TW |
346 | mei_me_cl_add(dev, me_cl); |
347 | ||
5ca2d388 TW |
348 | return 0; |
349 | } | |
350 | ||
70ef835c TW |
351 | /** |
352 | * mei_hbm_add_cl_resp - send response to fw on client add request | |
353 | * | |
354 | * @dev: the device structure | |
355 | * @addr: me address | |
356 | * @status: response status | |
357 | * | |
358 | * Return: 0 on success and < 0 on failure | |
359 | */ | |
360 | static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) | |
361 | { | |
c0ff9019 AU |
362 | struct mei_msg_hdr mei_hdr; |
363 | struct hbm_add_client_response resp; | |
70ef835c TW |
364 | const size_t len = sizeof(struct hbm_add_client_response); |
365 | int ret; | |
366 | ||
367 | dev_dbg(dev->dev, "adding client response\n"); | |
368 | ||
c0ff9019 | 369 | mei_hbm_hdr(&mei_hdr, len); |
70ef835c | 370 | |
c0ff9019 AU |
371 | memset(&resp, 0, sizeof(struct hbm_add_client_response)); |
372 | resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD; | |
373 | resp.me_addr = addr; | |
374 | resp.status = status; | |
70ef835c | 375 | |
c0ff9019 | 376 | ret = mei_write_message(dev, &mei_hdr, &resp); |
70ef835c TW |
377 | if (ret) |
378 | dev_err(dev->dev, "add client response write failed: ret = %d\n", | |
379 | ret); | |
380 | return ret; | |
381 | } | |
382 | ||
383 | /** | |
384 | * mei_hbm_fw_add_cl_req - request from the fw to add a client | |
385 | * | |
386 | * @dev: the device structure | |
387 | * @req: add client request | |
388 | * | |
389 | * Return: 0 on success and < 0 on failure | |
390 | */ | |
391 | static int mei_hbm_fw_add_cl_req(struct mei_device *dev, | |
392 | struct hbm_add_client_request *req) | |
393 | { | |
394 | int ret; | |
395 | u8 status = MEI_HBMS_SUCCESS; | |
396 | ||
397 | BUILD_BUG_ON(sizeof(struct hbm_add_client_request) != | |
398 | sizeof(struct hbm_props_response)); | |
399 | ||
400 | ret = mei_hbm_me_cl_add(dev, (struct hbm_props_response *)req); | |
401 | if (ret) | |
402 | status = !MEI_HBMS_SUCCESS; | |
403 | ||
a816a00e AU |
404 | if (dev->dev_state == MEI_DEV_ENABLED) |
405 | schedule_work(&dev->bus_rescan_work); | |
406 | ||
70ef835c TW |
407 | return mei_hbm_add_cl_resp(dev, req->me_addr, status); |
408 | } | |
409 | ||
965ae37a TW |
410 | /** |
411 | * mei_hbm_cl_notify_req - send notification request | |
412 | * | |
413 | * @dev: the device structure | |
414 | * @cl: a client to disconnect from | |
415 | * @start: true for start false for stop | |
416 | * | |
417 | * Return: 0 on success and -EIO on write failure | |
418 | */ | |
419 | int mei_hbm_cl_notify_req(struct mei_device *dev, | |
420 | struct mei_cl *cl, u8 start) | |
421 | { | |
422 | ||
c0ff9019 AU |
423 | struct mei_msg_hdr mei_hdr; |
424 | struct hbm_notification_request req; | |
965ae37a TW |
425 | const size_t len = sizeof(struct hbm_notification_request); |
426 | int ret; | |
427 | ||
c0ff9019 AU |
428 | mei_hbm_hdr(&mei_hdr, len); |
429 | mei_hbm_cl_hdr(cl, MEI_HBM_NOTIFY_REQ_CMD, &req, len); | |
965ae37a | 430 | |
c0ff9019 | 431 | req.start = start; |
965ae37a | 432 | |
c0ff9019 | 433 | ret = mei_write_message(dev, &mei_hdr, &req); |
965ae37a TW |
434 | if (ret) |
435 | dev_err(dev->dev, "notify request failed: ret = %d\n", ret); | |
436 | ||
437 | return ret; | |
438 | } | |
439 | ||
440 | /** | |
441 | * notify_res_to_fop - convert notification response to the proper | |
442 | * notification FOP | |
443 | * | |
444 | * @cmd: client notification start response command | |
445 | * | |
446 | * Return: MEI_FOP_NOTIFY_START or MEI_FOP_NOTIFY_STOP; | |
447 | */ | |
448 | static inline enum mei_cb_file_ops notify_res_to_fop(struct mei_hbm_cl_cmd *cmd) | |
449 | { | |
450 | struct hbm_notification_response *rs = | |
451 | (struct hbm_notification_response *)cmd; | |
452 | ||
51678ccb | 453 | return mei_cl_notify_req2fop(rs->start); |
965ae37a TW |
454 | } |
455 | ||
456 | /** | |
457 | * mei_hbm_cl_notify_start_res - update the client state according | |
458 | * notify start response | |
459 | * | |
460 | * @dev: the device structure | |
461 | * @cl: mei host client | |
462 | * @cmd: client notification start response command | |
463 | */ | |
464 | static void mei_hbm_cl_notify_start_res(struct mei_device *dev, | |
465 | struct mei_cl *cl, | |
466 | struct mei_hbm_cl_cmd *cmd) | |
467 | { | |
468 | struct hbm_notification_response *rs = | |
469 | (struct hbm_notification_response *)cmd; | |
470 | ||
471 | cl_dbg(dev, cl, "hbm: notify start response status=%d\n", rs->status); | |
472 | ||
473 | if (rs->status == MEI_HBMS_SUCCESS || | |
474 | rs->status == MEI_HBMS_ALREADY_STARTED) { | |
475 | cl->notify_en = true; | |
476 | cl->status = 0; | |
477 | } else { | |
478 | cl->status = -EINVAL; | |
479 | } | |
480 | } | |
481 | ||
482 | /** | |
483 | * mei_hbm_cl_notify_stop_res - update the client state according | |
484 | * notify stop response | |
485 | * | |
486 | * @dev: the device structure | |
487 | * @cl: mei host client | |
488 | * @cmd: client notification stop response command | |
489 | */ | |
490 | static void mei_hbm_cl_notify_stop_res(struct mei_device *dev, | |
491 | struct mei_cl *cl, | |
492 | struct mei_hbm_cl_cmd *cmd) | |
493 | { | |
494 | struct hbm_notification_response *rs = | |
495 | (struct hbm_notification_response *)cmd; | |
496 | ||
497 | cl_dbg(dev, cl, "hbm: notify stop response status=%d\n", rs->status); | |
498 | ||
499 | if (rs->status == MEI_HBMS_SUCCESS || | |
500 | rs->status == MEI_HBMS_NOT_STARTED) { | |
501 | cl->notify_en = false; | |
502 | cl->status = 0; | |
503 | } else { | |
504 | /* TODO: spec is not clear yet about other possible issues */ | |
505 | cl->status = -EINVAL; | |
506 | } | |
507 | } | |
508 | ||
509 | /** | |
510 | * mei_hbm_cl_notify - signal notification event | |
511 | * | |
512 | * @dev: the device structure | |
513 | * @cmd: notification client message | |
514 | */ | |
515 | static void mei_hbm_cl_notify(struct mei_device *dev, | |
516 | struct mei_hbm_cl_cmd *cmd) | |
517 | { | |
518 | struct mei_cl *cl; | |
519 | ||
520 | cl = mei_hbm_cl_find_by_cmd(dev, cmd); | |
237092bf TW |
521 | if (cl) |
522 | mei_cl_notify(cl); | |
965ae37a TW |
523 | } |
524 | ||
8120e720 | 525 | /** |
393b148f | 526 | * mei_hbm_prop_req - request property for a single client |
8120e720 TW |
527 | * |
528 | * @dev: the device structure | |
cc25aa94 | 529 | * @start_idx: client index to start search |
8120e720 | 530 | * |
a8605ea2 | 531 | * Return: 0 on success and < 0 on failure |
8120e720 | 532 | */ |
cc25aa94 | 533 | static int mei_hbm_prop_req(struct mei_device *dev, unsigned long start_idx) |
bb1b0133 | 534 | { |
c0ff9019 AU |
535 | struct mei_msg_hdr mei_hdr; |
536 | struct hbm_props_request prop_req; | |
bb1b0133 | 537 | const size_t len = sizeof(struct hbm_props_request); |
cc25aa94 | 538 | unsigned long addr; |
544f9460 | 539 | int ret; |
bb1b0133 | 540 | |
cc25aa94 | 541 | addr = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX, start_idx); |
bb1b0133 TW |
542 | |
543 | /* We got all client properties */ | |
cc25aa94 | 544 | if (addr == MEI_CLIENTS_MAX) { |
9b0d5efc | 545 | dev->hbm_state = MEI_HBM_STARTED; |
025fb792 | 546 | mei_host_client_init(dev); |
bb1b0133 TW |
547 | |
548 | return 0; | |
549 | } | |
550 | ||
c0ff9019 | 551 | mei_hbm_hdr(&mei_hdr, len); |
bb1b0133 | 552 | |
c0ff9019 | 553 | memset(&prop_req, 0, sizeof(struct hbm_props_request)); |
bb1b0133 | 554 | |
c0ff9019 AU |
555 | prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; |
556 | prop_req.me_addr = addr; | |
bb1b0133 | 557 | |
c0ff9019 | 558 | ret = mei_write_message(dev, &mei_hdr, &prop_req); |
544f9460 | 559 | if (ret) { |
2bf94cab | 560 | dev_err(dev->dev, "properties request write failed: ret = %d\n", |
544f9460 TW |
561 | ret); |
562 | return ret; | |
bb1b0133 TW |
563 | } |
564 | ||
565 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; | |
1892fc2e | 566 | mei_schedule_stall_timer(dev); |
bb1b0133 TW |
567 | |
568 | return 0; | |
569 | } | |
570 | ||
99c2658f | 571 | /** |
4fcbc99b TW |
572 | * mei_hbm_pg - sends pg command |
573 | * | |
574 | * @dev: the device structure | |
575 | * @pg_cmd: the pg command code | |
576 | * | |
a8605ea2 | 577 | * Return: -EIO on write failure |
bae1cc7d | 578 | * -EOPNOTSUPP if the operation is not supported by the protocol |
4fcbc99b TW |
579 | */ |
580 | int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd) | |
581 | { | |
c0ff9019 AU |
582 | struct mei_msg_hdr mei_hdr; |
583 | struct hbm_power_gate req; | |
4fcbc99b TW |
584 | const size_t len = sizeof(struct hbm_power_gate); |
585 | int ret; | |
586 | ||
bae1cc7d TW |
587 | if (!dev->hbm_f_pg_supported) |
588 | return -EOPNOTSUPP; | |
589 | ||
c0ff9019 | 590 | mei_hbm_hdr(&mei_hdr, len); |
4fcbc99b | 591 | |
c0ff9019 AU |
592 | memset(&req, 0, len); |
593 | req.hbm_cmd = pg_cmd; | |
4fcbc99b | 594 | |
c0ff9019 | 595 | ret = mei_write_message(dev, &mei_hdr, &req); |
4fcbc99b | 596 | if (ret) |
2bf94cab | 597 | dev_err(dev->dev, "power gate command write failed.\n"); |
4fcbc99b TW |
598 | return ret; |
599 | } | |
600 | EXPORT_SYMBOL_GPL(mei_hbm_pg); | |
601 | ||
e46f1874 | 602 | /** |
6bb948c9 | 603 | * mei_hbm_stop_req - send stop request message |
e46f1874 | 604 | * |
a8605ea2 | 605 | * @dev: mei device |
6bb948c9 | 606 | * |
a8605ea2 | 607 | * Return: -EIO on write failure |
e46f1874 | 608 | */ |
6bb948c9 | 609 | static int mei_hbm_stop_req(struct mei_device *dev) |
e46f1874 | 610 | { |
c0ff9019 AU |
611 | struct mei_msg_hdr mei_hdr; |
612 | struct hbm_host_stop_request req; | |
e46f1874 TW |
613 | const size_t len = sizeof(struct hbm_host_stop_request); |
614 | ||
c0ff9019 | 615 | mei_hbm_hdr(&mei_hdr, len); |
e46f1874 | 616 | |
c0ff9019 AU |
617 | memset(&req, 0, len); |
618 | req.hbm_cmd = HOST_STOP_REQ_CMD; | |
619 | req.reason = DRIVER_STOP_REQUEST; | |
6bb948c9 | 620 | |
c0ff9019 | 621 | return mei_write_message(dev, &mei_hdr, &req); |
e46f1874 TW |
622 | } |
623 | ||
bb1b0133 | 624 | /** |
83ce0741 | 625 | * mei_hbm_cl_flow_control_req - sends flow control request. |
bb1b0133 TW |
626 | * |
627 | * @dev: the device structure | |
8120e720 | 628 | * @cl: client info |
bb1b0133 | 629 | * |
a8605ea2 | 630 | * Return: -EIO on write failure |
bb1b0133 | 631 | */ |
8120e720 | 632 | int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl) |
bb1b0133 | 633 | { |
3fcbab6c | 634 | struct hbm_flow_control req; |
92db1555 | 635 | |
46922186 | 636 | cl_dbg(dev, cl, "sending flow control\n"); |
3fcbab6c TW |
637 | return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, |
638 | &req, sizeof(req)); | |
bb1b0133 TW |
639 | } |
640 | ||
6bbda15f | 641 | /** |
4034b81b | 642 | * mei_hbm_add_single_tx_flow_ctrl_creds - adds single buffer credentials. |
6bbda15f | 643 | * |
393b148f | 644 | * @dev: the device structure |
4034b81b | 645 | * @fctrl: flow control response bus message |
12d00665 | 646 | * |
a8605ea2 | 647 | * Return: 0 on success, < 0 otherwise |
6bbda15f | 648 | */ |
4034b81b TW |
649 | static int mei_hbm_add_single_tx_flow_ctrl_creds(struct mei_device *dev, |
650 | struct hbm_flow_control *fctrl) | |
6bbda15f | 651 | { |
12d00665 | 652 | struct mei_me_client *me_cl; |
79563db9 | 653 | int rets; |
12d00665 | 654 | |
4034b81b | 655 | me_cl = mei_me_cl_by_id(dev, fctrl->me_addr); |
d320832f | 656 | if (!me_cl) { |
4034b81b | 657 | dev_err(dev->dev, "no such me client %d\n", fctrl->me_addr); |
d320832f | 658 | return -ENOENT; |
12d00665 AU |
659 | } |
660 | ||
79563db9 TW |
661 | if (WARN_ON(me_cl->props.single_recv_buf == 0)) { |
662 | rets = -EINVAL; | |
663 | goto out; | |
664 | } | |
d320832f | 665 | |
4034b81b | 666 | me_cl->tx_flow_ctrl_creds++; |
2bf94cab | 667 | dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n", |
4034b81b | 668 | fctrl->me_addr, me_cl->tx_flow_ctrl_creds); |
12d00665 | 669 | |
79563db9 TW |
670 | rets = 0; |
671 | out: | |
672 | mei_me_cl_put(me_cl); | |
673 | return rets; | |
6bbda15f TW |
674 | } |
675 | ||
676 | /** | |
677 | * mei_hbm_cl_flow_control_res - flow control response from me | |
678 | * | |
679 | * @dev: the device structure | |
4034b81b | 680 | * @fctrl: flow control response bus message |
6bbda15f | 681 | */ |
4034b81b TW |
682 | static void mei_hbm_cl_tx_flow_ctrl_creds_res(struct mei_device *dev, |
683 | struct hbm_flow_control *fctrl) | |
6bbda15f | 684 | { |
31f88f57 | 685 | struct mei_cl *cl; |
6bbda15f | 686 | |
4034b81b | 687 | if (!fctrl->host_addr) { |
6bbda15f | 688 | /* single receive buffer */ |
4034b81b | 689 | mei_hbm_add_single_tx_flow_ctrl_creds(dev, fctrl); |
6bbda15f TW |
690 | return; |
691 | } | |
692 | ||
4034b81b | 693 | cl = mei_hbm_cl_find_by_cmd(dev, fctrl); |
2af89db1 | 694 | if (cl) { |
4034b81b | 695 | cl->tx_flow_ctrl_creds++; |
2af89db1 | 696 | cl_dbg(dev, cl, "flow control creds = %d.\n", |
4034b81b | 697 | cl->tx_flow_ctrl_creds); |
6bbda15f TW |
698 | } |
699 | } | |
700 | ||
701 | ||
bb1b0133 | 702 | /** |
8120e720 | 703 | * mei_hbm_cl_disconnect_req - sends disconnect message to fw. |
bb1b0133 TW |
704 | * |
705 | * @dev: the device structure | |
8120e720 | 706 | * @cl: a client to disconnect from |
bb1b0133 | 707 | * |
a8605ea2 | 708 | * Return: -EIO on write failure |
bb1b0133 | 709 | */ |
8120e720 | 710 | int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl) |
bb1b0133 | 711 | { |
3fcbab6c | 712 | struct hbm_client_connect_request req; |
92db1555 | 713 | |
3fcbab6c TW |
714 | return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, |
715 | &req, sizeof(req)); | |
bb1b0133 TW |
716 | } |
717 | ||
6bb948c9 TW |
718 | /** |
719 | * mei_hbm_cl_disconnect_rsp - sends disconnect respose to the FW | |
720 | * | |
721 | * @dev: the device structure | |
722 | * @cl: a client to disconnect from | |
723 | * | |
a8605ea2 | 724 | * Return: -EIO on write failure |
6bb948c9 TW |
725 | */ |
726 | int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) | |
727 | { | |
3fcbab6c | 728 | struct hbm_client_connect_response resp; |
92db1555 | 729 | |
3fcbab6c TW |
730 | return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, |
731 | &resp, sizeof(resp)); | |
6bb948c9 TW |
732 | } |
733 | ||
6bbda15f | 734 | /** |
12f45ed4 TW |
735 | * mei_hbm_cl_disconnect_res - update the client state according |
736 | * disconnect response | |
6bbda15f | 737 | * |
d512c209 | 738 | * @dev: the device structure |
12f45ed4 TW |
739 | * @cl: mei host client |
740 | * @cmd: disconnect client response host bus message | |
6bbda15f | 741 | */ |
d512c209 | 742 | static void mei_hbm_cl_disconnect_res(struct mei_device *dev, struct mei_cl *cl, |
12f45ed4 | 743 | struct mei_hbm_cl_cmd *cmd) |
6bbda15f | 744 | { |
12f45ed4 TW |
745 | struct hbm_client_connect_response *rs = |
746 | (struct hbm_client_connect_response *)cmd; | |
6bbda15f | 747 | |
d512c209 | 748 | cl_dbg(dev, cl, "hbm: disconnect response status=%d\n", rs->status); |
6bbda15f | 749 | |
12f45ed4 | 750 | if (rs->status == MEI_CL_DISCONN_SUCCESS) |
3c666182 | 751 | cl->state = MEI_FILE_DISCONNECT_REPLY; |
12f45ed4 | 752 | cl->status = 0; |
6bbda15f TW |
753 | } |
754 | ||
bb1b0133 | 755 | /** |
8120e720 | 756 | * mei_hbm_cl_connect_req - send connection request to specific me client |
bb1b0133 TW |
757 | * |
758 | * @dev: the device structure | |
8120e720 | 759 | * @cl: a client to connect to |
bb1b0133 | 760 | * |
a8605ea2 | 761 | * Return: -EIO on write failure |
bb1b0133 | 762 | */ |
8120e720 | 763 | int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl) |
bb1b0133 | 764 | { |
3fcbab6c | 765 | struct hbm_client_connect_request req; |
92db1555 | 766 | |
3fcbab6c TW |
767 | return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, |
768 | &req, sizeof(req)); | |
bb1b0133 TW |
769 | } |
770 | ||
6bbda15f | 771 | /** |
12f45ed4 TW |
772 | * mei_hbm_cl_connect_res - update the client state according |
773 | * connection response | |
6bbda15f | 774 | * |
d512c209 | 775 | * @dev: the device structure |
12f45ed4 TW |
776 | * @cl: mei host client |
777 | * @cmd: connect client response host bus message | |
6bbda15f | 778 | */ |
d512c209 | 779 | static void mei_hbm_cl_connect_res(struct mei_device *dev, struct mei_cl *cl, |
12f45ed4 | 780 | struct mei_hbm_cl_cmd *cmd) |
6bbda15f | 781 | { |
12f45ed4 TW |
782 | struct hbm_client_connect_response *rs = |
783 | (struct hbm_client_connect_response *)cmd; | |
6bbda15f | 784 | |
d512c209 | 785 | cl_dbg(dev, cl, "hbm: connect response status=%s\n", |
285e2996 | 786 | mei_cl_conn_status_str(rs->status)); |
6bbda15f | 787 | |
12f45ed4 TW |
788 | if (rs->status == MEI_CL_CONN_SUCCESS) |
789 | cl->state = MEI_FILE_CONNECTED; | |
70ef835c | 790 | else { |
3c666182 | 791 | cl->state = MEI_FILE_DISCONNECT_REPLY; |
a816a00e | 792 | if (rs->status == MEI_CL_CONN_NOT_FOUND) { |
70ef835c | 793 | mei_me_cl_del(dev, cl->me_cl); |
a816a00e AU |
794 | if (dev->dev_state == MEI_DEV_ENABLED) |
795 | schedule_work(&dev->bus_rescan_work); | |
796 | } | |
70ef835c | 797 | } |
12f45ed4 TW |
798 | cl->status = mei_cl_conn_status_to_errno(rs->status); |
799 | } | |
800 | ||
801 | /** | |
802 | * mei_hbm_cl_res - process hbm response received on behalf | |
803 | * an client | |
804 | * | |
805 | * @dev: the device structure | |
806 | * @rs: hbm client message | |
807 | * @fop_type: file operation type | |
808 | */ | |
809 | static void mei_hbm_cl_res(struct mei_device *dev, | |
810 | struct mei_hbm_cl_cmd *rs, | |
811 | enum mei_cb_file_ops fop_type) | |
812 | { | |
813 | struct mei_cl *cl; | |
814 | struct mei_cl_cb *cb, *next; | |
6bbda15f | 815 | |
12f45ed4 | 816 | cl = NULL; |
962ff7bc | 817 | list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list, list) { |
6bbda15f | 818 | |
64092858 | 819 | cl = cb->cl; |
6bbda15f | 820 | |
12f45ed4 | 821 | if (cb->fop_type != fop_type) |
64092858 | 822 | continue; |
6bbda15f | 823 | |
64092858 | 824 | if (mei_hbm_cl_addr_equal(cl, rs)) { |
928fa666 | 825 | list_del_init(&cb->list); |
64092858 | 826 | break; |
6bbda15f TW |
827 | } |
828 | } | |
64092858 TW |
829 | |
830 | if (!cl) | |
831 | return; | |
832 | ||
12f45ed4 TW |
833 | switch (fop_type) { |
834 | case MEI_FOP_CONNECT: | |
d512c209 | 835 | mei_hbm_cl_connect_res(dev, cl, rs); |
12f45ed4 TW |
836 | break; |
837 | case MEI_FOP_DISCONNECT: | |
d512c209 | 838 | mei_hbm_cl_disconnect_res(dev, cl, rs); |
12f45ed4 | 839 | break; |
965ae37a TW |
840 | case MEI_FOP_NOTIFY_START: |
841 | mei_hbm_cl_notify_start_res(dev, cl, rs); | |
842 | break; | |
843 | case MEI_FOP_NOTIFY_STOP: | |
844 | mei_hbm_cl_notify_stop_res(dev, cl, rs); | |
845 | break; | |
12f45ed4 TW |
846 | default: |
847 | return; | |
848 | } | |
849 | ||
64092858 | 850 | cl->timer_count = 0; |
12f45ed4 | 851 | wake_up(&cl->wait); |
6bbda15f TW |
852 | } |
853 | ||
854 | ||
bb1b0133 | 855 | /** |
83ce0741 AU |
856 | * mei_hbm_fw_disconnect_req - disconnect request initiated by ME firmware |
857 | * host sends disconnect response | |
bb1b0133 TW |
858 | * |
859 | * @dev: the device structure. | |
8120e720 | 860 | * @disconnect_req: disconnect request bus message from the me |
6bb948c9 | 861 | * |
a8605ea2 | 862 | * Return: -ENOMEM on allocation failure |
bb1b0133 | 863 | */ |
6bb948c9 | 864 | static int mei_hbm_fw_disconnect_req(struct mei_device *dev, |
bb1b0133 TW |
865 | struct hbm_client_connect_request *disconnect_req) |
866 | { | |
31f88f57 | 867 | struct mei_cl *cl; |
6bb948c9 | 868 | struct mei_cl_cb *cb; |
bb1b0133 | 869 | |
2af89db1 TW |
870 | cl = mei_hbm_cl_find_by_cmd(dev, disconnect_req); |
871 | if (cl) { | |
6938c192 | 872 | cl_warn(dev, cl, "fw disconnect request received\n"); |
3c666182 | 873 | cl->state = MEI_FILE_DISCONNECTING; |
2af89db1 TW |
874 | cl->timer_count = 0; |
875 | ||
3030dc05 TW |
876 | cb = mei_cl_enqueue_ctrl_wr_cb(cl, 0, MEI_FOP_DISCONNECT_RSP, |
877 | NULL); | |
2af89db1 TW |
878 | if (!cb) |
879 | return -ENOMEM; | |
bb1b0133 | 880 | } |
6bb948c9 | 881 | return 0; |
bb1b0133 TW |
882 | } |
883 | ||
63f75232 AU |
884 | /** |
885 | * mei_hbm_pg_enter_res - PG enter response received | |
886 | * | |
887 | * @dev: the device structure. | |
888 | * | |
889 | * Return: 0 on success, -EPROTO on state mismatch | |
890 | */ | |
891 | static int mei_hbm_pg_enter_res(struct mei_device *dev) | |
892 | { | |
893 | if (mei_pg_state(dev) != MEI_PG_OFF || | |
894 | dev->pg_event != MEI_PG_EVENT_WAIT) { | |
895 | dev_err(dev->dev, "hbm: pg entry response: state mismatch [%s, %d]\n", | |
896 | mei_pg_state_str(mei_pg_state(dev)), dev->pg_event); | |
897 | return -EPROTO; | |
898 | } | |
899 | ||
900 | dev->pg_event = MEI_PG_EVENT_RECEIVED; | |
901 | wake_up(&dev->wait_pg); | |
902 | ||
903 | return 0; | |
904 | } | |
905 | ||
859ef2ff AU |
906 | /** |
907 | * mei_hbm_pg_resume - process with PG resume | |
908 | * | |
909 | * @dev: the device structure. | |
910 | */ | |
911 | void mei_hbm_pg_resume(struct mei_device *dev) | |
912 | { | |
913 | pm_request_resume(dev->dev); | |
914 | } | |
915 | EXPORT_SYMBOL_GPL(mei_hbm_pg_resume); | |
916 | ||
63f75232 AU |
917 | /** |
918 | * mei_hbm_pg_exit_res - PG exit response received | |
919 | * | |
920 | * @dev: the device structure. | |
921 | * | |
922 | * Return: 0 on success, -EPROTO on state mismatch | |
923 | */ | |
924 | static int mei_hbm_pg_exit_res(struct mei_device *dev) | |
925 | { | |
926 | if (mei_pg_state(dev) != MEI_PG_ON || | |
927 | (dev->pg_event != MEI_PG_EVENT_WAIT && | |
928 | dev->pg_event != MEI_PG_EVENT_IDLE)) { | |
929 | dev_err(dev->dev, "hbm: pg exit response: state mismatch [%s, %d]\n", | |
930 | mei_pg_state_str(mei_pg_state(dev)), dev->pg_event); | |
931 | return -EPROTO; | |
932 | } | |
933 | ||
934 | switch (dev->pg_event) { | |
935 | case MEI_PG_EVENT_WAIT: | |
936 | dev->pg_event = MEI_PG_EVENT_RECEIVED; | |
937 | wake_up(&dev->wait_pg); | |
938 | break; | |
939 | case MEI_PG_EVENT_IDLE: | |
940 | /* | |
941 | * If the driver is not waiting on this then | |
942 | * this is HW initiated exit from PG. | |
943 | * Start runtime pm resume sequence to exit from PG. | |
944 | */ | |
945 | dev->pg_event = MEI_PG_EVENT_RECEIVED; | |
859ef2ff | 946 | mei_hbm_pg_resume(dev); |
63f75232 AU |
947 | break; |
948 | default: | |
949 | WARN(1, "hbm: pg exit response: unexpected pg event = %d\n", | |
950 | dev->pg_event); | |
951 | return -EPROTO; | |
952 | } | |
953 | ||
954 | return 0; | |
955 | } | |
956 | ||
bae1cc7d | 957 | /** |
a8605ea2 | 958 | * mei_hbm_config_features - check what hbm features and commands |
bae1cc7d TW |
959 | * are supported by the fw |
960 | * | |
961 | * @dev: the device structure | |
962 | */ | |
963 | static void mei_hbm_config_features(struct mei_device *dev) | |
964 | { | |
965 | /* Power Gating Isolation Support */ | |
966 | dev->hbm_f_pg_supported = 0; | |
967 | if (dev->version.major_version > HBM_MAJOR_VERSION_PGI) | |
968 | dev->hbm_f_pg_supported = 1; | |
969 | ||
970 | if (dev->version.major_version == HBM_MAJOR_VERSION_PGI && | |
971 | dev->version.minor_version >= HBM_MINOR_VERSION_PGI) | |
972 | dev->hbm_f_pg_supported = 1; | |
70ef835c TW |
973 | |
974 | if (dev->version.major_version >= HBM_MAJOR_VERSION_DC) | |
975 | dev->hbm_f_dc_supported = 1; | |
18901357 | 976 | |
27f476ea AU |
977 | if (dev->version.major_version >= HBM_MAJOR_VERSION_IE) |
978 | dev->hbm_f_ie_supported = 1; | |
979 | ||
18901357 AU |
980 | /* disconnect on connect timeout instead of link reset */ |
981 | if (dev->version.major_version >= HBM_MAJOR_VERSION_DOT) | |
982 | dev->hbm_f_dot_supported = 1; | |
4d99877d TW |
983 | |
984 | /* Notification Event Support */ | |
985 | if (dev->version.major_version >= HBM_MAJOR_VERSION_EV) | |
986 | dev->hbm_f_ev_supported = 1; | |
f4e06246 AU |
987 | |
988 | /* Fixed Address Client Support */ | |
989 | if (dev->version.major_version >= HBM_MAJOR_VERSION_FA) | |
990 | dev->hbm_f_fa_supported = 1; | |
7ee7f45a AU |
991 | |
992 | /* OS ver message Support */ | |
993 | if (dev->version.major_version >= HBM_MAJOR_VERSION_OS) | |
994 | dev->hbm_f_os_supported = 1; | |
bae1cc7d | 995 | } |
bb1b0133 | 996 | |
2c9b48ac TW |
997 | /** |
998 | * mei_hbm_version_is_supported - checks whether the driver can | |
999 | * support the hbm version of the device | |
1000 | * | |
1001 | * @dev: the device structure | |
a8605ea2 | 1002 | * Return: true if driver can support hbm version of the device |
2c9b48ac TW |
1003 | */ |
1004 | bool mei_hbm_version_is_supported(struct mei_device *dev) | |
1005 | { | |
1006 | return (dev->version.major_version < HBM_MAJOR_VERSION) || | |
1007 | (dev->version.major_version == HBM_MAJOR_VERSION && | |
1008 | dev->version.minor_version <= HBM_MINOR_VERSION); | |
1009 | } | |
1010 | ||
bb1b0133 TW |
1011 | /** |
1012 | * mei_hbm_dispatch - bottom half read routine after ISR to | |
1013 | * handle the read bus message cmd processing. | |
1014 | * | |
1015 | * @dev: the device structure | |
a8605ea2 | 1016 | * @hdr: header of bus message |
544f9460 | 1017 | * |
a8605ea2 | 1018 | * Return: 0 on success and < 0 on failure |
bb1b0133 | 1019 | */ |
544f9460 | 1020 | int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) |
bb1b0133 TW |
1021 | { |
1022 | struct mei_bus_message *mei_msg; | |
bb1b0133 | 1023 | struct hbm_host_version_response *version_res; |
bb1b0133 TW |
1024 | struct hbm_props_response *props_res; |
1025 | struct hbm_host_enum_response *enum_res; | |
70ef835c TW |
1026 | struct hbm_add_client_request *add_cl_req; |
1027 | int ret; | |
bb1b0133 | 1028 | |
12f45ed4 TW |
1029 | struct mei_hbm_cl_cmd *cl_cmd; |
1030 | struct hbm_client_connect_request *disconnect_req; | |
4034b81b | 1031 | struct hbm_flow_control *fctrl; |
12f45ed4 | 1032 | |
bb1b0133 TW |
1033 | /* read the message to our buffer */ |
1034 | BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf)); | |
1035 | mei_read_slots(dev, dev->rd_msg_buf, hdr->length); | |
1036 | mei_msg = (struct mei_bus_message *)dev->rd_msg_buf; | |
12f45ed4 | 1037 | cl_cmd = (struct mei_hbm_cl_cmd *)mei_msg; |
bb1b0133 | 1038 | |
66ae460b TW |
1039 | /* ignore spurious message and prevent reset nesting |
1040 | * hbm is put to idle during system reset | |
1041 | */ | |
1042 | if (dev->hbm_state == MEI_HBM_IDLE) { | |
2bf94cab | 1043 | dev_dbg(dev->dev, "hbm: state is idle ignore spurious messages\n"); |
66ae460b TW |
1044 | return 0; |
1045 | } | |
1046 | ||
bb1b0133 TW |
1047 | switch (mei_msg->hbm_cmd) { |
1048 | case HOST_START_RES_CMD: | |
2bf94cab | 1049 | dev_dbg(dev->dev, "hbm: start: response message received.\n"); |
544f9460 TW |
1050 | |
1051 | dev->init_clients_timer = 0; | |
1052 | ||
bb1b0133 | 1053 | version_res = (struct hbm_host_version_response *)mei_msg; |
2c9b48ac | 1054 | |
2bf94cab | 1055 | dev_dbg(dev->dev, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n", |
2c9b48ac TW |
1056 | HBM_MAJOR_VERSION, HBM_MINOR_VERSION, |
1057 | version_res->me_max_version.major_version, | |
1058 | version_res->me_max_version.minor_version); | |
1059 | ||
1060 | if (version_res->host_version_supported) { | |
1061 | dev->version.major_version = HBM_MAJOR_VERSION; | |
1062 | dev->version.minor_version = HBM_MINOR_VERSION; | |
1063 | } else { | |
1064 | dev->version.major_version = | |
1065 | version_res->me_max_version.major_version; | |
1066 | dev->version.minor_version = | |
1067 | version_res->me_max_version.minor_version; | |
1068 | } | |
1069 | ||
1070 | if (!mei_hbm_version_is_supported(dev)) { | |
2bf94cab | 1071 | dev_warn(dev->dev, "hbm: start: version mismatch - stopping the driver.\n"); |
bb1b0133 | 1072 | |
544f9460 | 1073 | dev->hbm_state = MEI_HBM_STOPPED; |
6bb948c9 | 1074 | if (mei_hbm_stop_req(dev)) { |
2bf94cab | 1075 | dev_err(dev->dev, "hbm: start: failed to send stop request\n"); |
544f9460 TW |
1076 | return -EIO; |
1077 | } | |
1078 | break; | |
1079 | } | |
9b0d5efc | 1080 | |
bae1cc7d TW |
1081 | mei_hbm_config_features(dev); |
1082 | ||
544f9460 | 1083 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || |
cb02efc3 | 1084 | dev->hbm_state != MEI_HBM_STARTING) { |
2bf94cab | 1085 | dev_err(dev->dev, "hbm: start: state mismatch, [%d, %d]\n", |
544f9460 TW |
1086 | dev->dev_state, dev->hbm_state); |
1087 | return -EPROTO; | |
e46f1874 | 1088 | } |
bb1b0133 | 1089 | |
544f9460 | 1090 | if (mei_hbm_enum_clients_req(dev)) { |
2bf94cab | 1091 | dev_err(dev->dev, "hbm: start: failed to send enumeration request\n"); |
544f9460 | 1092 | return -EIO; |
bb1b0133 TW |
1093 | } |
1094 | ||
cb02efc3 | 1095 | wake_up(&dev->wait_hbm_start); |
bb1b0133 TW |
1096 | break; |
1097 | ||
1098 | case CLIENT_CONNECT_RES_CMD: | |
2bf94cab | 1099 | dev_dbg(dev->dev, "hbm: client connect response: message received.\n"); |
12f45ed4 | 1100 | mei_hbm_cl_res(dev, cl_cmd, MEI_FOP_CONNECT); |
bb1b0133 TW |
1101 | break; |
1102 | ||
1103 | case CLIENT_DISCONNECT_RES_CMD: | |
2bf94cab | 1104 | dev_dbg(dev->dev, "hbm: client disconnect response: message received.\n"); |
12f45ed4 | 1105 | mei_hbm_cl_res(dev, cl_cmd, MEI_FOP_DISCONNECT); |
bb1b0133 TW |
1106 | break; |
1107 | ||
1108 | case MEI_FLOW_CONTROL_CMD: | |
2bf94cab | 1109 | dev_dbg(dev->dev, "hbm: client flow control response: message received.\n"); |
544f9460 | 1110 | |
4034b81b TW |
1111 | fctrl = (struct hbm_flow_control *)mei_msg; |
1112 | mei_hbm_cl_tx_flow_ctrl_creds_res(dev, fctrl); | |
bb1b0133 TW |
1113 | break; |
1114 | ||
4fcbc99b | 1115 | case MEI_PG_ISOLATION_ENTRY_RES_CMD: |
63f75232 AU |
1116 | dev_dbg(dev->dev, "hbm: power gate isolation entry response received\n"); |
1117 | ret = mei_hbm_pg_enter_res(dev); | |
1118 | if (ret) | |
1119 | return ret; | |
4fcbc99b TW |
1120 | break; |
1121 | ||
1122 | case MEI_PG_ISOLATION_EXIT_REQ_CMD: | |
63f75232 AU |
1123 | dev_dbg(dev->dev, "hbm: power gate isolation exit request received\n"); |
1124 | ret = mei_hbm_pg_exit_res(dev); | |
1125 | if (ret) | |
1126 | return ret; | |
4fcbc99b TW |
1127 | break; |
1128 | ||
bb1b0133 | 1129 | case HOST_CLIENT_PROPERTIES_RES_CMD: |
2bf94cab | 1130 | dev_dbg(dev->dev, "hbm: properties response: message received.\n"); |
544f9460 TW |
1131 | |
1132 | dev->init_clients_timer = 0; | |
1133 | ||
5ca2d388 TW |
1134 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || |
1135 | dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) { | |
2bf94cab | 1136 | dev_err(dev->dev, "hbm: properties response: state mismatch, [%d, %d]\n", |
5ca2d388 | 1137 | dev->dev_state, dev->hbm_state); |
544f9460 TW |
1138 | return -EPROTO; |
1139 | } | |
1140 | ||
bb1b0133 | 1141 | props_res = (struct hbm_props_response *)mei_msg; |
bb1b0133 | 1142 | |
544f9460 | 1143 | if (props_res->status) { |
2bf94cab | 1144 | dev_err(dev->dev, "hbm: properties response: wrong status = %d %s\n", |
89778d6e TW |
1145 | props_res->status, |
1146 | mei_hbm_status_str(props_res->status)); | |
544f9460 | 1147 | return -EPROTO; |
bb1b0133 TW |
1148 | } |
1149 | ||
5ca2d388 | 1150 | mei_hbm_me_cl_add(dev, props_res); |
bb1b0133 | 1151 | |
8120e720 | 1152 | /* request property for the next client */ |
cc25aa94 | 1153 | if (mei_hbm_prop_req(dev, props_res->me_addr + 1)) |
544f9460 | 1154 | return -EIO; |
bb1b0133 TW |
1155 | |
1156 | break; | |
1157 | ||
1158 | case HOST_ENUM_RES_CMD: | |
2bf94cab | 1159 | dev_dbg(dev->dev, "hbm: enumeration response: message received\n"); |
544f9460 TW |
1160 | |
1161 | dev->init_clients_timer = 0; | |
1162 | ||
bb1b0133 | 1163 | enum_res = (struct hbm_host_enum_response *) mei_msg; |
23f5a322 TW |
1164 | BUILD_BUG_ON(sizeof(dev->me_clients_map) |
1165 | < sizeof(enum_res->valid_addresses)); | |
1166 | memcpy(dev->me_clients_map, enum_res->valid_addresses, | |
5ca2d388 | 1167 | sizeof(enum_res->valid_addresses)); |
544f9460 TW |
1168 | |
1169 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || | |
1170 | dev->hbm_state != MEI_HBM_ENUM_CLIENTS) { | |
2bf94cab | 1171 | dev_err(dev->dev, "hbm: enumeration response: state mismatch, [%d, %d]\n", |
544f9460 TW |
1172 | dev->dev_state, dev->hbm_state); |
1173 | return -EPROTO; | |
bb1b0133 | 1174 | } |
544f9460 | 1175 | |
544f9460 TW |
1176 | dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES; |
1177 | ||
1178 | /* first property request */ | |
cc25aa94 | 1179 | if (mei_hbm_prop_req(dev, 0)) |
544f9460 TW |
1180 | return -EIO; |
1181 | ||
bb1b0133 TW |
1182 | break; |
1183 | ||
1184 | case HOST_STOP_RES_CMD: | |
2bf94cab | 1185 | dev_dbg(dev->dev, "hbm: stop response: message received\n"); |
544f9460 TW |
1186 | |
1187 | dev->init_clients_timer = 0; | |
1188 | ||
1189 | if (dev->hbm_state != MEI_HBM_STOPPED) { | |
2bf94cab | 1190 | dev_err(dev->dev, "hbm: stop response: state mismatch, [%d, %d]\n", |
544f9460 TW |
1191 | dev->dev_state, dev->hbm_state); |
1192 | return -EPROTO; | |
1193 | } | |
9b0d5efc | 1194 | |
33ec0826 | 1195 | dev->dev_state = MEI_DEV_POWER_DOWN; |
2bf94cab | 1196 | dev_info(dev->dev, "hbm: stop response: resetting.\n"); |
544f9460 TW |
1197 | /* force the reset */ |
1198 | return -EPROTO; | |
bb1b0133 TW |
1199 | break; |
1200 | ||
1201 | case CLIENT_DISCONNECT_REQ_CMD: | |
2bf94cab | 1202 | dev_dbg(dev->dev, "hbm: disconnect request: message received\n"); |
544f9460 | 1203 | |
bb1b0133 | 1204 | disconnect_req = (struct hbm_client_connect_request *)mei_msg; |
8120e720 | 1205 | mei_hbm_fw_disconnect_req(dev, disconnect_req); |
bb1b0133 TW |
1206 | break; |
1207 | ||
1208 | case ME_STOP_REQ_CMD: | |
2bf94cab | 1209 | dev_dbg(dev->dev, "hbm: stop request: message received\n"); |
544f9460 | 1210 | dev->hbm_state = MEI_HBM_STOPPED; |
6bb948c9 | 1211 | if (mei_hbm_stop_req(dev)) { |
2bf94cab | 1212 | dev_err(dev->dev, "hbm: stop request: failed to send stop request\n"); |
6bb948c9 TW |
1213 | return -EIO; |
1214 | } | |
bb1b0133 | 1215 | break; |
70ef835c TW |
1216 | |
1217 | case MEI_HBM_ADD_CLIENT_REQ_CMD: | |
1218 | dev_dbg(dev->dev, "hbm: add client request received\n"); | |
1219 | /* | |
1220 | * after the host receives the enum_resp | |
1221 | * message clients may be added or removed | |
1222 | */ | |
84dfe03a | 1223 | if (dev->hbm_state <= MEI_HBM_ENUM_CLIENTS || |
70ef835c TW |
1224 | dev->hbm_state >= MEI_HBM_STOPPED) { |
1225 | dev_err(dev->dev, "hbm: add client: state mismatch, [%d, %d]\n", | |
1226 | dev->dev_state, dev->hbm_state); | |
1227 | return -EPROTO; | |
1228 | } | |
1229 | add_cl_req = (struct hbm_add_client_request *)mei_msg; | |
1230 | ret = mei_hbm_fw_add_cl_req(dev, add_cl_req); | |
1231 | if (ret) { | |
1232 | dev_err(dev->dev, "hbm: add client: failed to send response %d\n", | |
1233 | ret); | |
1234 | return -EIO; | |
1235 | } | |
1236 | dev_dbg(dev->dev, "hbm: add client request processed\n"); | |
1237 | break; | |
1238 | ||
965ae37a TW |
1239 | case MEI_HBM_NOTIFY_RES_CMD: |
1240 | dev_dbg(dev->dev, "hbm: notify response received\n"); | |
1241 | mei_hbm_cl_res(dev, cl_cmd, notify_res_to_fop(cl_cmd)); | |
1242 | break; | |
1243 | ||
1244 | case MEI_HBM_NOTIFICATION_CMD: | |
1245 | dev_dbg(dev->dev, "hbm: notification\n"); | |
1246 | mei_hbm_cl_notify(dev, cl_cmd); | |
1247 | break; | |
1248 | ||
bb1b0133 TW |
1249 | default: |
1250 | BUG(); | |
1251 | break; | |
1252 | ||
1253 | } | |
544f9460 | 1254 | return 0; |
bb1b0133 TW |
1255 | } |
1256 |