3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
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.
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
17 #include <linux/export.h>
18 #include <linux/sched.h>
19 #include <linux/wait.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/slab.h>
23 #include <linux/mei.h>
29 static const char *mei_hbm_status_str(enum mei_hbm_status status
)
31 #define MEI_HBM_STATUS(status) case MEI_HBMS_##status: return #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";
46 static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status
)
48 #define MEI_CL_CS(status) case MEI_CL_CONN_##status: return #status
52 MEI_CL_CS(ALREADY_STARTED
);
53 MEI_CL_CS(OUT_OF_RESOURCES
);
54 MEI_CL_CS(MESSAGE_SMALL
);
55 MEI_CL_CS(NOT_ALLOWED
);
56 default: return "unknown";
61 const char *mei_hbm_state_str(enum mei_hbm_state state
)
63 #define MEI_HBM_STATE(state) case MEI_HBM_##state: return #state
66 MEI_HBM_STATE(STARTING
);
67 MEI_HBM_STATE(STARTED
);
68 MEI_HBM_STATE(DR_SETUP
);
69 MEI_HBM_STATE(ENUM_CLIENTS
);
70 MEI_HBM_STATE(CLIENT_PROPERTIES
);
71 MEI_HBM_STATE(STOPPED
);
79 * mei_cl_conn_status_to_errno - convert client connect response
80 * status to error code
82 * @status: client connect response status
84 * Return: corresponding error code
86 static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status
)
89 case MEI_CL_CONN_SUCCESS
: return 0;
90 case MEI_CL_CONN_NOT_FOUND
: return -ENOTTY
;
91 case MEI_CL_CONN_ALREADY_STARTED
: return -EBUSY
;
92 case MEI_CL_CONN_OUT_OF_RESOURCES
: return -EBUSY
;
93 case MEI_CL_CONN_MESSAGE_SMALL
: return -EINVAL
;
94 case MEI_CL_CONN_NOT_ALLOWED
: return -EBUSY
;
95 default: return -EINVAL
;
100 * mei_hbm_write_message - wrapper for sending hbm messages.
106 static inline int mei_hbm_write_message(struct mei_device
*dev
,
107 struct mei_msg_hdr
*hdr
,
110 return mei_write_message(dev
, hdr
, sizeof(*hdr
), data
, hdr
->length
);
114 * mei_hbm_idle - set hbm to idle state
116 * @dev: the device structure
118 void mei_hbm_idle(struct mei_device
*dev
)
120 dev
->init_clients_timer
= 0;
121 dev
->hbm_state
= MEI_HBM_IDLE
;
125 * mei_hbm_reset - reset hbm counters and book keeping data structurs
127 * @dev: the device structure
129 void mei_hbm_reset(struct mei_device
*dev
)
131 mei_me_cl_rm_all(dev
);
137 * mei_hbm_hdr - construct hbm header
140 * @length: payload length
143 static inline void mei_hbm_hdr(struct mei_msg_hdr
*hdr
, size_t length
)
147 hdr
->length
= length
;
148 hdr
->msg_complete
= 1;
155 * mei_hbm_cl_hdr - construct client hbm header
158 * @hbm_cmd: host bus message command
159 * @buf: buffer for cl header
160 * @len: buffer length
163 void mei_hbm_cl_hdr(struct mei_cl
*cl
, u8 hbm_cmd
, void *buf
, size_t len
)
165 struct mei_hbm_cl_cmd
*cmd
= buf
;
169 cmd
->hbm_cmd
= hbm_cmd
;
170 cmd
->host_addr
= mei_cl_host_addr(cl
);
171 cmd
->me_addr
= mei_cl_me_id(cl
);
175 * mei_hbm_cl_write - write simple hbm client message
177 * @dev: the device structure
179 * @hbm_cmd: host bus message command
180 * @buf: message buffer
181 * @len: buffer length
183 * Return: 0 on success, <0 on failure.
185 static inline int mei_hbm_cl_write(struct mei_device
*dev
, struct mei_cl
*cl
,
186 u8 hbm_cmd
, void *buf
, size_t len
)
188 struct mei_msg_hdr mei_hdr
;
190 mei_hbm_hdr(&mei_hdr
, len
);
191 mei_hbm_cl_hdr(cl
, hbm_cmd
, buf
, len
);
193 return mei_hbm_write_message(dev
, &mei_hdr
, buf
);
197 * mei_hbm_cl_addr_equal - check if the client's and
198 * the message address match
201 * @cmd: hbm client message
203 * Return: true if addresses are the same
206 bool mei_hbm_cl_addr_equal(struct mei_cl
*cl
, struct mei_hbm_cl_cmd
*cmd
)
208 return mei_cl_host_addr(cl
) == cmd
->host_addr
&&
209 mei_cl_me_id(cl
) == cmd
->me_addr
;
213 * mei_hbm_cl_find_by_cmd - find recipient client
215 * @dev: the device structure
216 * @buf: a buffer with hbm cl command
218 * Return: the recipient client or NULL if not found
221 struct mei_cl
*mei_hbm_cl_find_by_cmd(struct mei_device
*dev
, void *buf
)
223 struct mei_hbm_cl_cmd
*cmd
= (struct mei_hbm_cl_cmd
*)buf
;
226 list_for_each_entry(cl
, &dev
->file_list
, link
)
227 if (mei_hbm_cl_addr_equal(cl
, cmd
))
234 * mei_hbm_start_wait - wait for start response message.
236 * @dev: the device structure
238 * Return: 0 on success and < 0 on failure
240 int mei_hbm_start_wait(struct mei_device
*dev
)
244 if (dev
->hbm_state
> MEI_HBM_STARTING
)
247 mutex_unlock(&dev
->device_lock
);
248 ret
= wait_event_timeout(dev
->wait_hbm_start
,
249 dev
->hbm_state
!= MEI_HBM_STARTING
,
250 mei_secs_to_jiffies(MEI_HBM_TIMEOUT
));
251 mutex_lock(&dev
->device_lock
);
253 if (ret
== 0 && (dev
->hbm_state
<= MEI_HBM_STARTING
)) {
254 dev
->hbm_state
= MEI_HBM_IDLE
;
255 dev_err(dev
->dev
, "waiting for mei start failed\n");
262 * mei_hbm_start_req - sends start request message.
264 * @dev: the device structure
266 * Return: 0 on success and < 0 on failure
268 int mei_hbm_start_req(struct mei_device
*dev
)
270 struct mei_msg_hdr mei_hdr
;
271 struct hbm_host_version_request start_req
;
272 const size_t len
= sizeof(struct hbm_host_version_request
);
277 mei_hbm_hdr(&mei_hdr
, len
);
279 /* host start message */
280 memset(&start_req
, 0, len
);
281 start_req
.hbm_cmd
= HOST_START_REQ_CMD
;
282 start_req
.host_version
.major_version
= HBM_MAJOR_VERSION
;
283 start_req
.host_version
.minor_version
= HBM_MINOR_VERSION
;
285 dev
->hbm_state
= MEI_HBM_IDLE
;
286 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &start_req
);
288 dev_err(dev
->dev
, "version message write failed: ret = %d\n",
293 dev
->hbm_state
= MEI_HBM_STARTING
;
294 dev
->init_clients_timer
= MEI_CLIENTS_INIT_TIMEOUT
;
295 mei_schedule_stall_timer(dev
);
300 * mei_hbm_dma_setup_req() - setup DMA request
301 * @dev: the device structure
303 * Return: 0 on success and < 0 on failure
305 static int mei_hbm_dma_setup_req(struct mei_device
*dev
)
307 struct mei_msg_hdr mei_hdr
;
308 struct hbm_dma_setup_request req
;
309 const size_t len
= sizeof(struct hbm_dma_setup_request
);
313 mei_hbm_hdr(&mei_hdr
, len
);
315 memset(&req
, 0, len
);
316 req
.hbm_cmd
= MEI_HBM_DMA_SETUP_REQ_CMD
;
317 for (i
= 0; i
< DMA_DSCR_NUM
; i
++) {
320 paddr
= dev
->dr_dscr
[i
].daddr
;
321 req
.dma_dscr
[i
].addr_hi
= upper_32_bits(paddr
);
322 req
.dma_dscr
[i
].addr_lo
= lower_32_bits(paddr
);
323 req
.dma_dscr
[i
].size
= dev
->dr_dscr
[i
].size
;
326 mei_dma_ring_reset(dev
);
328 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
330 dev_err(dev
->dev
, "dma setup request write failed: ret = %d.\n",
335 dev
->hbm_state
= MEI_HBM_DR_SETUP
;
336 dev
->init_clients_timer
= MEI_CLIENTS_INIT_TIMEOUT
;
337 mei_schedule_stall_timer(dev
);
342 * mei_hbm_enum_clients_req - sends enumeration client request message.
344 * @dev: the device structure
346 * Return: 0 on success and < 0 on failure
348 static int mei_hbm_enum_clients_req(struct mei_device
*dev
)
350 struct mei_msg_hdr mei_hdr
;
351 struct hbm_host_enum_request enum_req
;
352 const size_t len
= sizeof(struct hbm_host_enum_request
);
355 /* enumerate clients */
356 mei_hbm_hdr(&mei_hdr
, len
);
358 memset(&enum_req
, 0, len
);
359 enum_req
.hbm_cmd
= HOST_ENUM_REQ_CMD
;
360 enum_req
.flags
|= dev
->hbm_f_dc_supported
?
361 MEI_HBM_ENUM_F_ALLOW_ADD
: 0;
362 enum_req
.flags
|= dev
->hbm_f_ie_supported
?
363 MEI_HBM_ENUM_F_IMMEDIATE_ENUM
: 0;
365 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &enum_req
);
367 dev_err(dev
->dev
, "enumeration request write failed: ret = %d.\n",
371 dev
->hbm_state
= MEI_HBM_ENUM_CLIENTS
;
372 dev
->init_clients_timer
= MEI_CLIENTS_INIT_TIMEOUT
;
373 mei_schedule_stall_timer(dev
);
378 * mei_hbm_me_cl_add - add new me client to the list
380 * @dev: the device structure
381 * @res: hbm property response
383 * Return: 0 on success and -ENOMEM on allocation failure
386 static int mei_hbm_me_cl_add(struct mei_device
*dev
,
387 struct hbm_props_response
*res
)
389 struct mei_me_client
*me_cl
;
390 const uuid_le
*uuid
= &res
->client_properties
.protocol_name
;
392 mei_me_cl_rm_by_uuid(dev
, uuid
);
394 me_cl
= kzalloc(sizeof(struct mei_me_client
), GFP_KERNEL
);
398 mei_me_cl_init(me_cl
);
400 me_cl
->props
= res
->client_properties
;
401 me_cl
->client_id
= res
->me_addr
;
402 me_cl
->tx_flow_ctrl_creds
= 0;
404 mei_me_cl_add(dev
, me_cl
);
410 * mei_hbm_add_cl_resp - send response to fw on client add request
412 * @dev: the device structure
414 * @status: response status
416 * Return: 0 on success and < 0 on failure
418 static int mei_hbm_add_cl_resp(struct mei_device
*dev
, u8 addr
, u8 status
)
420 struct mei_msg_hdr mei_hdr
;
421 struct hbm_add_client_response resp
;
422 const size_t len
= sizeof(struct hbm_add_client_response
);
425 dev_dbg(dev
->dev
, "adding client response\n");
427 mei_hbm_hdr(&mei_hdr
, len
);
429 memset(&resp
, 0, sizeof(struct hbm_add_client_response
));
430 resp
.hbm_cmd
= MEI_HBM_ADD_CLIENT_RES_CMD
;
432 resp
.status
= status
;
434 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &resp
);
436 dev_err(dev
->dev
, "add client response write failed: ret = %d\n",
442 * mei_hbm_fw_add_cl_req - request from the fw to add a client
444 * @dev: the device structure
445 * @req: add client request
447 * Return: 0 on success and < 0 on failure
449 static int mei_hbm_fw_add_cl_req(struct mei_device
*dev
,
450 struct hbm_add_client_request
*req
)
453 u8 status
= MEI_HBMS_SUCCESS
;
455 BUILD_BUG_ON(sizeof(struct hbm_add_client_request
) !=
456 sizeof(struct hbm_props_response
));
458 ret
= mei_hbm_me_cl_add(dev
, (struct hbm_props_response
*)req
);
460 status
= !MEI_HBMS_SUCCESS
;
462 if (dev
->dev_state
== MEI_DEV_ENABLED
)
463 schedule_work(&dev
->bus_rescan_work
);
465 return mei_hbm_add_cl_resp(dev
, req
->me_addr
, status
);
469 * mei_hbm_cl_notify_req - send notification request
471 * @dev: the device structure
472 * @cl: a client to disconnect from
473 * @start: true for start false for stop
475 * Return: 0 on success and -EIO on write failure
477 int mei_hbm_cl_notify_req(struct mei_device
*dev
,
478 struct mei_cl
*cl
, u8 start
)
481 struct mei_msg_hdr mei_hdr
;
482 struct hbm_notification_request req
;
483 const size_t len
= sizeof(struct hbm_notification_request
);
486 mei_hbm_hdr(&mei_hdr
, len
);
487 mei_hbm_cl_hdr(cl
, MEI_HBM_NOTIFY_REQ_CMD
, &req
, len
);
491 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
493 dev_err(dev
->dev
, "notify request failed: ret = %d\n", ret
);
499 * notify_res_to_fop - convert notification response to the proper
502 * @cmd: client notification start response command
504 * Return: MEI_FOP_NOTIFY_START or MEI_FOP_NOTIFY_STOP;
506 static inline enum mei_cb_file_ops
notify_res_to_fop(struct mei_hbm_cl_cmd
*cmd
)
508 struct hbm_notification_response
*rs
=
509 (struct hbm_notification_response
*)cmd
;
511 return mei_cl_notify_req2fop(rs
->start
);
515 * mei_hbm_cl_notify_start_res - update the client state according
516 * notify start response
518 * @dev: the device structure
519 * @cl: mei host client
520 * @cmd: client notification start response command
522 static void mei_hbm_cl_notify_start_res(struct mei_device
*dev
,
524 struct mei_hbm_cl_cmd
*cmd
)
526 struct hbm_notification_response
*rs
=
527 (struct hbm_notification_response
*)cmd
;
529 cl_dbg(dev
, cl
, "hbm: notify start response status=%d\n", rs
->status
);
531 if (rs
->status
== MEI_HBMS_SUCCESS
||
532 rs
->status
== MEI_HBMS_ALREADY_STARTED
) {
533 cl
->notify_en
= true;
536 cl
->status
= -EINVAL
;
541 * mei_hbm_cl_notify_stop_res - update the client state according
542 * notify stop response
544 * @dev: the device structure
545 * @cl: mei host client
546 * @cmd: client notification stop response command
548 static void mei_hbm_cl_notify_stop_res(struct mei_device
*dev
,
550 struct mei_hbm_cl_cmd
*cmd
)
552 struct hbm_notification_response
*rs
=
553 (struct hbm_notification_response
*)cmd
;
555 cl_dbg(dev
, cl
, "hbm: notify stop response status=%d\n", rs
->status
);
557 if (rs
->status
== MEI_HBMS_SUCCESS
||
558 rs
->status
== MEI_HBMS_NOT_STARTED
) {
559 cl
->notify_en
= false;
562 /* TODO: spec is not clear yet about other possible issues */
563 cl
->status
= -EINVAL
;
568 * mei_hbm_cl_notify - signal notification event
570 * @dev: the device structure
571 * @cmd: notification client message
573 static void mei_hbm_cl_notify(struct mei_device
*dev
,
574 struct mei_hbm_cl_cmd
*cmd
)
578 cl
= mei_hbm_cl_find_by_cmd(dev
, cmd
);
584 * mei_hbm_prop_req - request property for a single client
586 * @dev: the device structure
587 * @start_idx: client index to start search
589 * Return: 0 on success and < 0 on failure
591 static int mei_hbm_prop_req(struct mei_device
*dev
, unsigned long start_idx
)
593 struct mei_msg_hdr mei_hdr
;
594 struct hbm_props_request prop_req
;
595 const size_t len
= sizeof(struct hbm_props_request
);
599 addr
= find_next_bit(dev
->me_clients_map
, MEI_CLIENTS_MAX
, start_idx
);
601 /* We got all client properties */
602 if (addr
== MEI_CLIENTS_MAX
) {
603 dev
->hbm_state
= MEI_HBM_STARTED
;
604 mei_host_client_init(dev
);
609 mei_hbm_hdr(&mei_hdr
, len
);
611 memset(&prop_req
, 0, sizeof(struct hbm_props_request
));
613 prop_req
.hbm_cmd
= HOST_CLIENT_PROPERTIES_REQ_CMD
;
614 prop_req
.me_addr
= addr
;
616 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &prop_req
);
618 dev_err(dev
->dev
, "properties request write failed: ret = %d\n",
623 dev
->init_clients_timer
= MEI_CLIENTS_INIT_TIMEOUT
;
624 mei_schedule_stall_timer(dev
);
630 * mei_hbm_pg - sends pg command
632 * @dev: the device structure
633 * @pg_cmd: the pg command code
635 * Return: -EIO on write failure
636 * -EOPNOTSUPP if the operation is not supported by the protocol
638 int mei_hbm_pg(struct mei_device
*dev
, u8 pg_cmd
)
640 struct mei_msg_hdr mei_hdr
;
641 struct hbm_power_gate req
;
642 const size_t len
= sizeof(struct hbm_power_gate
);
645 if (!dev
->hbm_f_pg_supported
)
648 mei_hbm_hdr(&mei_hdr
, len
);
650 memset(&req
, 0, len
);
651 req
.hbm_cmd
= pg_cmd
;
653 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
655 dev_err(dev
->dev
, "power gate command write failed.\n");
658 EXPORT_SYMBOL_GPL(mei_hbm_pg
);
661 * mei_hbm_stop_req - send stop request message
665 * Return: -EIO on write failure
667 static int mei_hbm_stop_req(struct mei_device
*dev
)
669 struct mei_msg_hdr mei_hdr
;
670 struct hbm_host_stop_request req
;
671 const size_t len
= sizeof(struct hbm_host_stop_request
);
673 mei_hbm_hdr(&mei_hdr
, len
);
675 memset(&req
, 0, len
);
676 req
.hbm_cmd
= HOST_STOP_REQ_CMD
;
677 req
.reason
= DRIVER_STOP_REQUEST
;
679 return mei_hbm_write_message(dev
, &mei_hdr
, &req
);
683 * mei_hbm_cl_flow_control_req - sends flow control request.
685 * @dev: the device structure
688 * Return: -EIO on write failure
690 int mei_hbm_cl_flow_control_req(struct mei_device
*dev
, struct mei_cl
*cl
)
692 struct hbm_flow_control req
;
694 cl_dbg(dev
, cl
, "sending flow control\n");
695 return mei_hbm_cl_write(dev
, cl
, MEI_FLOW_CONTROL_CMD
,
700 * mei_hbm_add_single_tx_flow_ctrl_creds - adds single buffer credentials.
702 * @dev: the device structure
703 * @fctrl: flow control response bus message
705 * Return: 0 on success, < 0 otherwise
707 static int mei_hbm_add_single_tx_flow_ctrl_creds(struct mei_device
*dev
,
708 struct hbm_flow_control
*fctrl
)
710 struct mei_me_client
*me_cl
;
713 me_cl
= mei_me_cl_by_id(dev
, fctrl
->me_addr
);
715 dev_err(dev
->dev
, "no such me client %d\n", fctrl
->me_addr
);
719 if (WARN_ON(me_cl
->props
.single_recv_buf
== 0)) {
724 me_cl
->tx_flow_ctrl_creds
++;
725 dev_dbg(dev
->dev
, "recv flow ctrl msg ME %d (single) creds = %d.\n",
726 fctrl
->me_addr
, me_cl
->tx_flow_ctrl_creds
);
730 mei_me_cl_put(me_cl
);
735 * mei_hbm_cl_flow_control_res - flow control response from me
737 * @dev: the device structure
738 * @fctrl: flow control response bus message
740 static void mei_hbm_cl_tx_flow_ctrl_creds_res(struct mei_device
*dev
,
741 struct hbm_flow_control
*fctrl
)
745 if (!fctrl
->host_addr
) {
746 /* single receive buffer */
747 mei_hbm_add_single_tx_flow_ctrl_creds(dev
, fctrl
);
751 cl
= mei_hbm_cl_find_by_cmd(dev
, fctrl
);
753 cl
->tx_flow_ctrl_creds
++;
754 cl_dbg(dev
, cl
, "flow control creds = %d.\n",
755 cl
->tx_flow_ctrl_creds
);
761 * mei_hbm_cl_disconnect_req - sends disconnect message to fw.
763 * @dev: the device structure
764 * @cl: a client to disconnect from
766 * Return: -EIO on write failure
768 int mei_hbm_cl_disconnect_req(struct mei_device
*dev
, struct mei_cl
*cl
)
770 struct hbm_client_connect_request req
;
772 return mei_hbm_cl_write(dev
, cl
, CLIENT_DISCONNECT_REQ_CMD
,
777 * mei_hbm_cl_disconnect_rsp - sends disconnect respose to the FW
779 * @dev: the device structure
780 * @cl: a client to disconnect from
782 * Return: -EIO on write failure
784 int mei_hbm_cl_disconnect_rsp(struct mei_device
*dev
, struct mei_cl
*cl
)
786 struct hbm_client_connect_response resp
;
788 return mei_hbm_cl_write(dev
, cl
, CLIENT_DISCONNECT_RES_CMD
,
789 &resp
, sizeof(resp
));
793 * mei_hbm_cl_disconnect_res - update the client state according
794 * disconnect response
796 * @dev: the device structure
797 * @cl: mei host client
798 * @cmd: disconnect client response host bus message
800 static void mei_hbm_cl_disconnect_res(struct mei_device
*dev
, struct mei_cl
*cl
,
801 struct mei_hbm_cl_cmd
*cmd
)
803 struct hbm_client_connect_response
*rs
=
804 (struct hbm_client_connect_response
*)cmd
;
806 cl_dbg(dev
, cl
, "hbm: disconnect response status=%d\n", rs
->status
);
808 if (rs
->status
== MEI_CL_DISCONN_SUCCESS
)
809 cl
->state
= MEI_FILE_DISCONNECT_REPLY
;
814 * mei_hbm_cl_connect_req - send connection request to specific me client
816 * @dev: the device structure
817 * @cl: a client to connect to
819 * Return: -EIO on write failure
821 int mei_hbm_cl_connect_req(struct mei_device
*dev
, struct mei_cl
*cl
)
823 struct hbm_client_connect_request req
;
825 return mei_hbm_cl_write(dev
, cl
, CLIENT_CONNECT_REQ_CMD
,
830 * mei_hbm_cl_connect_res - update the client state according
831 * connection response
833 * @dev: the device structure
834 * @cl: mei host client
835 * @cmd: connect client response host bus message
837 static void mei_hbm_cl_connect_res(struct mei_device
*dev
, struct mei_cl
*cl
,
838 struct mei_hbm_cl_cmd
*cmd
)
840 struct hbm_client_connect_response
*rs
=
841 (struct hbm_client_connect_response
*)cmd
;
843 cl_dbg(dev
, cl
, "hbm: connect response status=%s\n",
844 mei_cl_conn_status_str(rs
->status
));
846 if (rs
->status
== MEI_CL_CONN_SUCCESS
)
847 cl
->state
= MEI_FILE_CONNECTED
;
849 cl
->state
= MEI_FILE_DISCONNECT_REPLY
;
850 if (rs
->status
== MEI_CL_CONN_NOT_FOUND
) {
851 mei_me_cl_del(dev
, cl
->me_cl
);
852 if (dev
->dev_state
== MEI_DEV_ENABLED
)
853 schedule_work(&dev
->bus_rescan_work
);
856 cl
->status
= mei_cl_conn_status_to_errno(rs
->status
);
860 * mei_hbm_cl_res - process hbm response received on behalf
863 * @dev: the device structure
864 * @rs: hbm client message
865 * @fop_type: file operation type
867 static void mei_hbm_cl_res(struct mei_device
*dev
,
868 struct mei_hbm_cl_cmd
*rs
,
869 enum mei_cb_file_ops fop_type
)
872 struct mei_cl_cb
*cb
, *next
;
875 list_for_each_entry_safe(cb
, next
, &dev
->ctrl_rd_list
, list
) {
879 if (cb
->fop_type
!= fop_type
)
882 if (mei_hbm_cl_addr_equal(cl
, rs
)) {
883 list_del_init(&cb
->list
);
892 case MEI_FOP_CONNECT
:
893 mei_hbm_cl_connect_res(dev
, cl
, rs
);
895 case MEI_FOP_DISCONNECT
:
896 mei_hbm_cl_disconnect_res(dev
, cl
, rs
);
898 case MEI_FOP_NOTIFY_START
:
899 mei_hbm_cl_notify_start_res(dev
, cl
, rs
);
901 case MEI_FOP_NOTIFY_STOP
:
902 mei_hbm_cl_notify_stop_res(dev
, cl
, rs
);
914 * mei_hbm_fw_disconnect_req - disconnect request initiated by ME firmware
915 * host sends disconnect response
917 * @dev: the device structure.
918 * @disconnect_req: disconnect request bus message from the me
920 * Return: -ENOMEM on allocation failure
922 static int mei_hbm_fw_disconnect_req(struct mei_device
*dev
,
923 struct hbm_client_connect_request
*disconnect_req
)
926 struct mei_cl_cb
*cb
;
928 cl
= mei_hbm_cl_find_by_cmd(dev
, disconnect_req
);
930 cl_warn(dev
, cl
, "fw disconnect request received\n");
931 cl
->state
= MEI_FILE_DISCONNECTING
;
934 cb
= mei_cl_enqueue_ctrl_wr_cb(cl
, 0, MEI_FOP_DISCONNECT_RSP
,
943 * mei_hbm_pg_enter_res - PG enter response received
945 * @dev: the device structure.
947 * Return: 0 on success, -EPROTO on state mismatch
949 static int mei_hbm_pg_enter_res(struct mei_device
*dev
)
951 if (mei_pg_state(dev
) != MEI_PG_OFF
||
952 dev
->pg_event
!= MEI_PG_EVENT_WAIT
) {
953 dev_err(dev
->dev
, "hbm: pg entry response: state mismatch [%s, %d]\n",
954 mei_pg_state_str(mei_pg_state(dev
)), dev
->pg_event
);
958 dev
->pg_event
= MEI_PG_EVENT_RECEIVED
;
959 wake_up(&dev
->wait_pg
);
965 * mei_hbm_pg_resume - process with PG resume
967 * @dev: the device structure.
969 void mei_hbm_pg_resume(struct mei_device
*dev
)
971 pm_request_resume(dev
->dev
);
973 EXPORT_SYMBOL_GPL(mei_hbm_pg_resume
);
976 * mei_hbm_pg_exit_res - PG exit response received
978 * @dev: the device structure.
980 * Return: 0 on success, -EPROTO on state mismatch
982 static int mei_hbm_pg_exit_res(struct mei_device
*dev
)
984 if (mei_pg_state(dev
) != MEI_PG_ON
||
985 (dev
->pg_event
!= MEI_PG_EVENT_WAIT
&&
986 dev
->pg_event
!= MEI_PG_EVENT_IDLE
)) {
987 dev_err(dev
->dev
, "hbm: pg exit response: state mismatch [%s, %d]\n",
988 mei_pg_state_str(mei_pg_state(dev
)), dev
->pg_event
);
992 switch (dev
->pg_event
) {
993 case MEI_PG_EVENT_WAIT
:
994 dev
->pg_event
= MEI_PG_EVENT_RECEIVED
;
995 wake_up(&dev
->wait_pg
);
997 case MEI_PG_EVENT_IDLE
:
999 * If the driver is not waiting on this then
1000 * this is HW initiated exit from PG.
1001 * Start runtime pm resume sequence to exit from PG.
1003 dev
->pg_event
= MEI_PG_EVENT_RECEIVED
;
1004 mei_hbm_pg_resume(dev
);
1007 WARN(1, "hbm: pg exit response: unexpected pg event = %d\n",
1016 * mei_hbm_config_features - check what hbm features and commands
1017 * are supported by the fw
1019 * @dev: the device structure
1021 static void mei_hbm_config_features(struct mei_device
*dev
)
1023 /* Power Gating Isolation Support */
1024 dev
->hbm_f_pg_supported
= 0;
1025 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_PGI
)
1026 dev
->hbm_f_pg_supported
= 1;
1028 if (dev
->version
.major_version
== HBM_MAJOR_VERSION_PGI
&&
1029 dev
->version
.minor_version
>= HBM_MINOR_VERSION_PGI
)
1030 dev
->hbm_f_pg_supported
= 1;
1032 dev
->hbm_f_dc_supported
= 0;
1033 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_DC
)
1034 dev
->hbm_f_dc_supported
= 1;
1036 dev
->hbm_f_ie_supported
= 0;
1037 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_IE
)
1038 dev
->hbm_f_ie_supported
= 1;
1040 /* disconnect on connect timeout instead of link reset */
1041 dev
->hbm_f_dot_supported
= 0;
1042 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_DOT
)
1043 dev
->hbm_f_dot_supported
= 1;
1045 /* Notification Event Support */
1046 dev
->hbm_f_ev_supported
= 0;
1047 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_EV
)
1048 dev
->hbm_f_ev_supported
= 1;
1050 /* Fixed Address Client Support */
1051 dev
->hbm_f_fa_supported
= 0;
1052 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_FA
)
1053 dev
->hbm_f_fa_supported
= 1;
1055 /* OS ver message Support */
1056 dev
->hbm_f_os_supported
= 0;
1057 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_OS
)
1058 dev
->hbm_f_os_supported
= 1;
1060 /* DMA Ring Support */
1061 dev
->hbm_f_dr_supported
= 0;
1062 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_DR
||
1063 (dev
->version
.major_version
== HBM_MAJOR_VERSION_DR
&&
1064 dev
->version
.minor_version
>= HBM_MINOR_VERSION_DR
))
1065 dev
->hbm_f_dr_supported
= 1;
1069 * mei_hbm_version_is_supported - checks whether the driver can
1070 * support the hbm version of the device
1072 * @dev: the device structure
1073 * Return: true if driver can support hbm version of the device
1075 bool mei_hbm_version_is_supported(struct mei_device
*dev
)
1077 return (dev
->version
.major_version
< HBM_MAJOR_VERSION
) ||
1078 (dev
->version
.major_version
== HBM_MAJOR_VERSION
&&
1079 dev
->version
.minor_version
<= HBM_MINOR_VERSION
);
1083 * mei_hbm_dispatch - bottom half read routine after ISR to
1084 * handle the read bus message cmd processing.
1086 * @dev: the device structure
1087 * @hdr: header of bus message
1089 * Return: 0 on success and < 0 on failure
1091 int mei_hbm_dispatch(struct mei_device
*dev
, struct mei_msg_hdr
*hdr
)
1093 struct mei_bus_message
*mei_msg
;
1094 struct hbm_host_version_response
*version_res
;
1095 struct hbm_props_response
*props_res
;
1096 struct hbm_host_enum_response
*enum_res
;
1097 struct hbm_dma_setup_response
*dma_setup_res
;
1098 struct hbm_add_client_request
*add_cl_req
;
1101 struct mei_hbm_cl_cmd
*cl_cmd
;
1102 struct hbm_client_connect_request
*disconnect_req
;
1103 struct hbm_flow_control
*fctrl
;
1105 /* read the message to our buffer */
1106 BUG_ON(hdr
->length
>= sizeof(dev
->rd_msg_buf
));
1107 mei_read_slots(dev
, dev
->rd_msg_buf
, hdr
->length
);
1108 mei_msg
= (struct mei_bus_message
*)dev
->rd_msg_buf
;
1109 cl_cmd
= (struct mei_hbm_cl_cmd
*)mei_msg
;
1111 /* ignore spurious message and prevent reset nesting
1112 * hbm is put to idle during system reset
1114 if (dev
->hbm_state
== MEI_HBM_IDLE
) {
1115 dev_dbg(dev
->dev
, "hbm: state is idle ignore spurious messages\n");
1119 switch (mei_msg
->hbm_cmd
) {
1120 case HOST_START_RES_CMD
:
1121 dev_dbg(dev
->dev
, "hbm: start: response message received.\n");
1123 dev
->init_clients_timer
= 0;
1125 version_res
= (struct hbm_host_version_response
*)mei_msg
;
1127 dev_dbg(dev
->dev
, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n",
1128 HBM_MAJOR_VERSION
, HBM_MINOR_VERSION
,
1129 version_res
->me_max_version
.major_version
,
1130 version_res
->me_max_version
.minor_version
);
1132 if (version_res
->host_version_supported
) {
1133 dev
->version
.major_version
= HBM_MAJOR_VERSION
;
1134 dev
->version
.minor_version
= HBM_MINOR_VERSION
;
1136 dev
->version
.major_version
=
1137 version_res
->me_max_version
.major_version
;
1138 dev
->version
.minor_version
=
1139 version_res
->me_max_version
.minor_version
;
1142 if (!mei_hbm_version_is_supported(dev
)) {
1143 dev_warn(dev
->dev
, "hbm: start: version mismatch - stopping the driver.\n");
1145 dev
->hbm_state
= MEI_HBM_STOPPED
;
1146 if (mei_hbm_stop_req(dev
)) {
1147 dev_err(dev
->dev
, "hbm: start: failed to send stop request\n");
1153 mei_hbm_config_features(dev
);
1155 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1156 dev
->hbm_state
!= MEI_HBM_STARTING
) {
1157 dev_err(dev
->dev
, "hbm: start: state mismatch, [%d, %d]\n",
1158 dev
->dev_state
, dev
->hbm_state
);
1162 if (dev
->hbm_f_dr_supported
) {
1163 if (mei_dmam_ring_alloc(dev
))
1164 dev_info(dev
->dev
, "running w/o dma ring\n");
1165 if (mei_dma_ring_is_allocated(dev
)) {
1166 if (mei_hbm_dma_setup_req(dev
))
1169 wake_up(&dev
->wait_hbm_start
);
1174 dev
->hbm_f_dr_supported
= 0;
1175 mei_dmam_ring_free(dev
);
1177 if (mei_hbm_enum_clients_req(dev
))
1180 wake_up(&dev
->wait_hbm_start
);
1183 case MEI_HBM_DMA_SETUP_RES_CMD
:
1184 dev_dbg(dev
->dev
, "hbm: dma setup response: message received.\n");
1186 dev
->init_clients_timer
= 0;
1188 if (dev
->hbm_state
!= MEI_HBM_DR_SETUP
) {
1189 dev_err(dev
->dev
, "hbm: dma setup response: state mismatch, [%d, %d]\n",
1190 dev
->dev_state
, dev
->hbm_state
);
1194 dma_setup_res
= (struct hbm_dma_setup_response
*)mei_msg
;
1196 if (dma_setup_res
->status
) {
1197 u8 status
= dma_setup_res
->status
;
1199 if (status
== MEI_HBMS_NOT_ALLOWED
) {
1200 dev_dbg(dev
->dev
, "hbm: dma setup not allowed\n");
1202 dev_info(dev
->dev
, "hbm: dma setup response: failure = %d %s\n",
1204 mei_hbm_status_str(status
));
1206 dev
->hbm_f_dr_supported
= 0;
1207 mei_dmam_ring_free(dev
);
1210 if (mei_hbm_enum_clients_req(dev
))
1214 case CLIENT_CONNECT_RES_CMD
:
1215 dev_dbg(dev
->dev
, "hbm: client connect response: message received.\n");
1216 mei_hbm_cl_res(dev
, cl_cmd
, MEI_FOP_CONNECT
);
1219 case CLIENT_DISCONNECT_RES_CMD
:
1220 dev_dbg(dev
->dev
, "hbm: client disconnect response: message received.\n");
1221 mei_hbm_cl_res(dev
, cl_cmd
, MEI_FOP_DISCONNECT
);
1224 case MEI_FLOW_CONTROL_CMD
:
1225 dev_dbg(dev
->dev
, "hbm: client flow control response: message received.\n");
1227 fctrl
= (struct hbm_flow_control
*)mei_msg
;
1228 mei_hbm_cl_tx_flow_ctrl_creds_res(dev
, fctrl
);
1231 case MEI_PG_ISOLATION_ENTRY_RES_CMD
:
1232 dev_dbg(dev
->dev
, "hbm: power gate isolation entry response received\n");
1233 ret
= mei_hbm_pg_enter_res(dev
);
1238 case MEI_PG_ISOLATION_EXIT_REQ_CMD
:
1239 dev_dbg(dev
->dev
, "hbm: power gate isolation exit request received\n");
1240 ret
= mei_hbm_pg_exit_res(dev
);
1245 case HOST_CLIENT_PROPERTIES_RES_CMD
:
1246 dev_dbg(dev
->dev
, "hbm: properties response: message received.\n");
1248 dev
->init_clients_timer
= 0;
1250 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1251 dev
->hbm_state
!= MEI_HBM_CLIENT_PROPERTIES
) {
1252 dev_err(dev
->dev
, "hbm: properties response: state mismatch, [%d, %d]\n",
1253 dev
->dev_state
, dev
->hbm_state
);
1257 props_res
= (struct hbm_props_response
*)mei_msg
;
1259 if (props_res
->status
== MEI_HBMS_CLIENT_NOT_FOUND
) {
1260 dev_dbg(dev
->dev
, "hbm: properties response: %d CLIENT_NOT_FOUND\n",
1261 props_res
->me_addr
);
1262 } else if (props_res
->status
) {
1263 dev_err(dev
->dev
, "hbm: properties response: wrong status = %d %s\n",
1265 mei_hbm_status_str(props_res
->status
));
1268 mei_hbm_me_cl_add(dev
, props_res
);
1271 /* request property for the next client */
1272 if (mei_hbm_prop_req(dev
, props_res
->me_addr
+ 1))
1277 case HOST_ENUM_RES_CMD
:
1278 dev_dbg(dev
->dev
, "hbm: enumeration response: message received\n");
1280 dev
->init_clients_timer
= 0;
1282 enum_res
= (struct hbm_host_enum_response
*) mei_msg
;
1283 BUILD_BUG_ON(sizeof(dev
->me_clients_map
)
1284 < sizeof(enum_res
->valid_addresses
));
1285 memcpy(dev
->me_clients_map
, enum_res
->valid_addresses
,
1286 sizeof(enum_res
->valid_addresses
));
1288 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1289 dev
->hbm_state
!= MEI_HBM_ENUM_CLIENTS
) {
1290 dev_err(dev
->dev
, "hbm: enumeration response: state mismatch, [%d, %d]\n",
1291 dev
->dev_state
, dev
->hbm_state
);
1295 dev
->hbm_state
= MEI_HBM_CLIENT_PROPERTIES
;
1297 /* first property request */
1298 if (mei_hbm_prop_req(dev
, 0))
1303 case HOST_STOP_RES_CMD
:
1304 dev_dbg(dev
->dev
, "hbm: stop response: message received\n");
1306 dev
->init_clients_timer
= 0;
1308 if (dev
->hbm_state
!= MEI_HBM_STOPPED
) {
1309 dev_err(dev
->dev
, "hbm: stop response: state mismatch, [%d, %d]\n",
1310 dev
->dev_state
, dev
->hbm_state
);
1314 dev
->dev_state
= MEI_DEV_POWER_DOWN
;
1315 dev_info(dev
->dev
, "hbm: stop response: resetting.\n");
1316 /* force the reset */
1320 case CLIENT_DISCONNECT_REQ_CMD
:
1321 dev_dbg(dev
->dev
, "hbm: disconnect request: message received\n");
1323 disconnect_req
= (struct hbm_client_connect_request
*)mei_msg
;
1324 mei_hbm_fw_disconnect_req(dev
, disconnect_req
);
1327 case ME_STOP_REQ_CMD
:
1328 dev_dbg(dev
->dev
, "hbm: stop request: message received\n");
1329 dev
->hbm_state
= MEI_HBM_STOPPED
;
1330 if (mei_hbm_stop_req(dev
)) {
1331 dev_err(dev
->dev
, "hbm: stop request: failed to send stop request\n");
1336 case MEI_HBM_ADD_CLIENT_REQ_CMD
:
1337 dev_dbg(dev
->dev
, "hbm: add client request received\n");
1339 * after the host receives the enum_resp
1340 * message clients may be added or removed
1342 if (dev
->hbm_state
<= MEI_HBM_ENUM_CLIENTS
||
1343 dev
->hbm_state
>= MEI_HBM_STOPPED
) {
1344 dev_err(dev
->dev
, "hbm: add client: state mismatch, [%d, %d]\n",
1345 dev
->dev_state
, dev
->hbm_state
);
1348 add_cl_req
= (struct hbm_add_client_request
*)mei_msg
;
1349 ret
= mei_hbm_fw_add_cl_req(dev
, add_cl_req
);
1351 dev_err(dev
->dev
, "hbm: add client: failed to send response %d\n",
1355 dev_dbg(dev
->dev
, "hbm: add client request processed\n");
1358 case MEI_HBM_NOTIFY_RES_CMD
:
1359 dev_dbg(dev
->dev
, "hbm: notify response received\n");
1360 mei_hbm_cl_res(dev
, cl_cmd
, notify_res_to_fop(cl_cmd
));
1363 case MEI_HBM_NOTIFICATION_CMD
:
1364 dev_dbg(dev
->dev
, "hbm: notification\n");
1365 mei_hbm_cl_notify(dev
, cl_cmd
);
1369 WARN(1, "hbm: wrong command %d\n", mei_msg
->hbm_cmd
);