1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2003-2022, Intel Corporation. All rights reserved.
4 * Intel Management Engine Interface (Intel MEI) Linux driver
6 #include <linux/export.h>
7 #include <linux/sched.h>
8 #include <linux/wait.h>
9 #include <linux/pm_runtime.h>
10 #include <linux/slab.h>
12 #include <linux/mei.h>
18 static const char *mei_hbm_status_str(enum mei_hbm_status status
)
20 #define MEI_HBM_STATUS(status) case MEI_HBMS_##status: return #status
22 MEI_HBM_STATUS(SUCCESS
);
23 MEI_HBM_STATUS(CLIENT_NOT_FOUND
);
24 MEI_HBM_STATUS(ALREADY_EXISTS
);
25 MEI_HBM_STATUS(REJECTED
);
26 MEI_HBM_STATUS(INVALID_PARAMETER
);
27 MEI_HBM_STATUS(NOT_ALLOWED
);
28 MEI_HBM_STATUS(ALREADY_STARTED
);
29 MEI_HBM_STATUS(NOT_STARTED
);
30 default: return "unknown";
35 static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status
)
37 #define MEI_CL_CS(status) case MEI_CL_CONN_##status: return #status
41 MEI_CL_CS(ALREADY_STARTED
);
42 MEI_CL_CS(OUT_OF_RESOURCES
);
43 MEI_CL_CS(MESSAGE_SMALL
);
44 MEI_CL_CS(NOT_ALLOWED
);
45 default: return "unknown";
50 const char *mei_hbm_state_str(enum mei_hbm_state state
)
52 #define MEI_HBM_STATE(state) case MEI_HBM_##state: return #state
55 MEI_HBM_STATE(STARTING
);
56 MEI_HBM_STATE(STARTED
);
57 MEI_HBM_STATE(DR_SETUP
);
58 MEI_HBM_STATE(ENUM_CLIENTS
);
59 MEI_HBM_STATE(CLIENT_PROPERTIES
);
60 MEI_HBM_STATE(STOPPED
);
68 * mei_cl_conn_status_to_errno - convert client connect response
69 * status to error code
71 * @status: client connect response status
73 * Return: corresponding error code
75 static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status
)
78 case MEI_CL_CONN_SUCCESS
: return 0;
79 case MEI_CL_CONN_NOT_FOUND
: return -ENOTTY
;
80 case MEI_CL_CONN_ALREADY_STARTED
: return -EBUSY
;
81 case MEI_CL_CONN_OUT_OF_RESOURCES
: return -EBUSY
;
82 case MEI_CL_CONN_MESSAGE_SMALL
: return -EINVAL
;
83 case MEI_CL_CONN_NOT_ALLOWED
: return -EBUSY
;
84 default: return -EINVAL
;
89 * mei_hbm_write_message - wrapper for sending hbm messages.
95 * Return: >=0 on success, <0 on error
97 static inline int mei_hbm_write_message(struct mei_device
*dev
,
98 struct mei_msg_hdr
*hdr
,
101 return mei_write_message(dev
, hdr
, sizeof(*hdr
), data
, hdr
->length
);
105 * mei_hbm_idle - set hbm to idle state
107 * @dev: the device structure
109 void mei_hbm_idle(struct mei_device
*dev
)
111 dev
->init_clients_timer
= 0;
112 dev
->hbm_state
= MEI_HBM_IDLE
;
116 * mei_hbm_reset - reset hbm counters and book keeping data structures
118 * @dev: the device structure
120 void mei_hbm_reset(struct mei_device
*dev
)
122 mei_me_cl_rm_all(dev
);
128 * mei_hbm_hdr - construct hbm header
130 * @mei_hdr: hbm header
131 * @length: payload length
134 static inline void mei_hbm_hdr(struct mei_msg_hdr
*mei_hdr
, size_t length
)
136 memset(mei_hdr
, 0, sizeof(*mei_hdr
));
137 mei_hdr
->length
= length
;
138 mei_hdr
->msg_complete
= 1;
142 * mei_hbm_cl_hdr - construct client hbm header
145 * @hbm_cmd: host bus message command
146 * @buf: buffer for cl header
147 * @len: buffer length
150 void mei_hbm_cl_hdr(struct mei_cl
*cl
, u8 hbm_cmd
, void *buf
, size_t len
)
152 struct mei_hbm_cl_cmd
*cmd
= buf
;
156 cmd
->hbm_cmd
= hbm_cmd
;
157 cmd
->host_addr
= mei_cl_host_addr(cl
);
158 cmd
->me_addr
= mei_cl_me_id(cl
);
162 * mei_hbm_cl_write - write simple hbm client message
164 * @dev: the device structure
166 * @hbm_cmd: host bus message command
167 * @buf: message buffer
168 * @len: buffer length
170 * Return: 0 on success, <0 on failure.
172 static inline int mei_hbm_cl_write(struct mei_device
*dev
, struct mei_cl
*cl
,
173 u8 hbm_cmd
, void *buf
, size_t len
)
175 struct mei_msg_hdr mei_hdr
;
177 mei_hbm_hdr(&mei_hdr
, len
);
178 mei_hbm_cl_hdr(cl
, hbm_cmd
, buf
, len
);
180 return mei_hbm_write_message(dev
, &mei_hdr
, buf
);
184 * mei_hbm_cl_addr_equal - check if the client's and
185 * the message address match
188 * @cmd: hbm client message
190 * Return: true if addresses are the same
193 bool mei_hbm_cl_addr_equal(struct mei_cl
*cl
, struct mei_hbm_cl_cmd
*cmd
)
195 return mei_cl_host_addr(cl
) == cmd
->host_addr
&&
196 mei_cl_me_id(cl
) == cmd
->me_addr
;
200 * mei_hbm_cl_find_by_cmd - find recipient client
202 * @dev: the device structure
203 * @buf: a buffer with hbm cl command
205 * Return: the recipient client or NULL if not found
208 struct mei_cl
*mei_hbm_cl_find_by_cmd(struct mei_device
*dev
, void *buf
)
210 struct mei_hbm_cl_cmd
*cmd
= (struct mei_hbm_cl_cmd
*)buf
;
213 list_for_each_entry(cl
, &dev
->file_list
, link
)
214 if (mei_hbm_cl_addr_equal(cl
, cmd
))
221 * mei_hbm_start_wait - wait for start response message.
223 * @dev: the device structure
225 * Return: 0 on success and < 0 on failure
227 int mei_hbm_start_wait(struct mei_device
*dev
)
231 if (dev
->hbm_state
> MEI_HBM_STARTING
)
234 mutex_unlock(&dev
->device_lock
);
235 ret
= wait_event_timeout(dev
->wait_hbm_start
,
236 dev
->hbm_state
!= MEI_HBM_STARTING
,
238 mutex_lock(&dev
->device_lock
);
240 if (ret
== 0 && (dev
->hbm_state
<= MEI_HBM_STARTING
)) {
241 dev
->hbm_state
= MEI_HBM_IDLE
;
242 dev_err(dev
->dev
, "waiting for mei start failed\n");
249 * mei_hbm_start_req - sends start request message.
251 * @dev: the device structure
253 * Return: 0 on success and < 0 on failure
255 int mei_hbm_start_req(struct mei_device
*dev
)
257 struct mei_msg_hdr mei_hdr
;
258 struct hbm_host_version_request req
;
263 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
265 /* host start message */
266 memset(&req
, 0, sizeof(req
));
267 req
.hbm_cmd
= HOST_START_REQ_CMD
;
268 req
.host_version
.major_version
= HBM_MAJOR_VERSION
;
269 req
.host_version
.minor_version
= HBM_MINOR_VERSION
;
271 dev
->hbm_state
= MEI_HBM_IDLE
;
272 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
274 dev_err(dev
->dev
, "version message write failed: ret = %d\n",
279 dev
->hbm_state
= MEI_HBM_STARTING
;
280 dev
->init_clients_timer
= dev
->timeouts
.client_init
;
281 mei_schedule_stall_timer(dev
);
286 * mei_hbm_dma_setup_req() - setup DMA request
287 * @dev: the device structure
289 * Return: 0 on success and < 0 on failure
291 static int mei_hbm_dma_setup_req(struct mei_device
*dev
)
293 struct mei_msg_hdr mei_hdr
;
294 struct hbm_dma_setup_request req
;
298 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
300 memset(&req
, 0, sizeof(req
));
301 req
.hbm_cmd
= MEI_HBM_DMA_SETUP_REQ_CMD
;
302 for (i
= 0; i
< DMA_DSCR_NUM
; i
++) {
305 paddr
= dev
->dr_dscr
[i
].daddr
;
306 req
.dma_dscr
[i
].addr_hi
= upper_32_bits(paddr
);
307 req
.dma_dscr
[i
].addr_lo
= lower_32_bits(paddr
);
308 req
.dma_dscr
[i
].size
= dev
->dr_dscr
[i
].size
;
311 mei_dma_ring_reset(dev
);
313 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
315 dev_err(dev
->dev
, "dma setup request write failed: ret = %d.\n",
320 dev
->hbm_state
= MEI_HBM_DR_SETUP
;
321 dev
->init_clients_timer
= dev
->timeouts
.client_init
;
322 mei_schedule_stall_timer(dev
);
327 * mei_hbm_capabilities_req - request capabilities
329 * @dev: the device structure
331 * Return: 0 on success and < 0 on failure
333 static int mei_hbm_capabilities_req(struct mei_device
*dev
)
335 struct mei_msg_hdr mei_hdr
;
336 struct hbm_capability_request req
;
339 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
341 memset(&req
, 0, sizeof(req
));
342 req
.hbm_cmd
= MEI_HBM_CAPABILITIES_REQ_CMD
;
343 if (dev
->hbm_f_vt_supported
)
344 req
.capability_requested
[0] |= HBM_CAP_VT
;
346 if (dev
->hbm_f_cd_supported
)
347 req
.capability_requested
[0] |= HBM_CAP_CD
;
349 if (dev
->hbm_f_gsc_supported
)
350 req
.capability_requested
[0] |= HBM_CAP_GSC
;
352 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
355 "capabilities request write failed: ret = %d.\n", ret
);
359 dev
->hbm_state
= MEI_HBM_CAP_SETUP
;
360 dev
->init_clients_timer
= dev
->timeouts
.client_init
;
361 mei_schedule_stall_timer(dev
);
366 * mei_hbm_enum_clients_req - sends enumeration client request message.
368 * @dev: the device structure
370 * Return: 0 on success and < 0 on failure
372 static int mei_hbm_enum_clients_req(struct mei_device
*dev
)
374 struct mei_msg_hdr mei_hdr
;
375 struct hbm_host_enum_request req
;
378 /* enumerate clients */
379 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
381 memset(&req
, 0, sizeof(req
));
382 req
.hbm_cmd
= HOST_ENUM_REQ_CMD
;
383 req
.flags
|= dev
->hbm_f_dc_supported
? MEI_HBM_ENUM_F_ALLOW_ADD
: 0;
384 req
.flags
|= dev
->hbm_f_ie_supported
?
385 MEI_HBM_ENUM_F_IMMEDIATE_ENUM
: 0;
387 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
389 dev_err(dev
->dev
, "enumeration request write failed: ret = %d.\n",
393 dev
->hbm_state
= MEI_HBM_ENUM_CLIENTS
;
394 dev
->init_clients_timer
= dev
->timeouts
.client_init
;
395 mei_schedule_stall_timer(dev
);
400 * mei_hbm_me_cl_add - add new me client to the list
402 * @dev: the device structure
403 * @res: hbm property response
405 * Return: 0 on success and -ENOMEM on allocation failure
408 static int mei_hbm_me_cl_add(struct mei_device
*dev
,
409 struct hbm_props_response
*res
)
411 struct mei_me_client
*me_cl
;
412 const uuid_le
*uuid
= &res
->client_properties
.protocol_name
;
414 mei_me_cl_rm_by_uuid(dev
, uuid
);
416 me_cl
= kzalloc(sizeof(*me_cl
), GFP_KERNEL
);
420 mei_me_cl_init(me_cl
);
422 me_cl
->props
= res
->client_properties
;
423 me_cl
->client_id
= res
->me_addr
;
424 me_cl
->tx_flow_ctrl_creds
= 0;
426 mei_me_cl_add(dev
, me_cl
);
432 * mei_hbm_add_cl_resp - send response to fw on client add request
434 * @dev: the device structure
436 * @status: response status
438 * Return: 0 on success and < 0 on failure
440 static int mei_hbm_add_cl_resp(struct mei_device
*dev
, u8 addr
, u8 status
)
442 struct mei_msg_hdr mei_hdr
;
443 struct hbm_add_client_response resp
;
446 dev_dbg(dev
->dev
, "adding client response\n");
448 mei_hbm_hdr(&mei_hdr
, sizeof(resp
));
450 memset(&resp
, 0, sizeof(resp
));
451 resp
.hbm_cmd
= MEI_HBM_ADD_CLIENT_RES_CMD
;
453 resp
.status
= status
;
455 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &resp
);
457 dev_err(dev
->dev
, "add client response write failed: ret = %d\n",
463 * mei_hbm_fw_add_cl_req - request from the fw to add a client
465 * @dev: the device structure
466 * @req: add client request
468 * Return: 0 on success and < 0 on failure
470 static int mei_hbm_fw_add_cl_req(struct mei_device
*dev
,
471 struct hbm_add_client_request
*req
)
474 u8 status
= MEI_HBMS_SUCCESS
;
476 BUILD_BUG_ON(sizeof(struct hbm_add_client_request
) !=
477 sizeof(struct hbm_props_response
));
479 ret
= mei_hbm_me_cl_add(dev
, (struct hbm_props_response
*)req
);
481 status
= !MEI_HBMS_SUCCESS
;
483 if (dev
->dev_state
== MEI_DEV_ENABLED
)
484 schedule_work(&dev
->bus_rescan_work
);
486 return mei_hbm_add_cl_resp(dev
, req
->me_addr
, status
);
490 * mei_hbm_cl_notify_req - send notification request
492 * @dev: the device structure
493 * @cl: a client to disconnect from
494 * @start: true for start false for stop
496 * Return: 0 on success and -EIO on write failure
498 int mei_hbm_cl_notify_req(struct mei_device
*dev
,
499 struct mei_cl
*cl
, u8 start
)
502 struct mei_msg_hdr mei_hdr
;
503 struct hbm_notification_request req
;
506 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
507 mei_hbm_cl_hdr(cl
, MEI_HBM_NOTIFY_REQ_CMD
, &req
, sizeof(req
));
511 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
513 dev_err(dev
->dev
, "notify request failed: ret = %d\n", ret
);
519 * notify_res_to_fop - convert notification response to the proper
522 * @cmd: client notification start response command
524 * Return: MEI_FOP_NOTIFY_START or MEI_FOP_NOTIFY_STOP;
526 static inline enum mei_cb_file_ops
notify_res_to_fop(struct mei_hbm_cl_cmd
*cmd
)
528 struct hbm_notification_response
*rs
=
529 (struct hbm_notification_response
*)cmd
;
531 return mei_cl_notify_req2fop(rs
->start
);
535 * mei_hbm_cl_notify_start_res - update the client state according
536 * notify start response
538 * @dev: the device structure
539 * @cl: mei host client
540 * @cmd: client notification start response command
542 static void mei_hbm_cl_notify_start_res(struct mei_device
*dev
,
544 struct mei_hbm_cl_cmd
*cmd
)
546 struct hbm_notification_response
*rs
=
547 (struct hbm_notification_response
*)cmd
;
549 cl_dbg(dev
, cl
, "hbm: notify start response status=%d\n", rs
->status
);
551 if (rs
->status
== MEI_HBMS_SUCCESS
||
552 rs
->status
== MEI_HBMS_ALREADY_STARTED
) {
553 cl
->notify_en
= true;
556 cl
->status
= -EINVAL
;
561 * mei_hbm_cl_notify_stop_res - update the client state according
562 * notify stop response
564 * @dev: the device structure
565 * @cl: mei host client
566 * @cmd: client notification stop response command
568 static void mei_hbm_cl_notify_stop_res(struct mei_device
*dev
,
570 struct mei_hbm_cl_cmd
*cmd
)
572 struct hbm_notification_response
*rs
=
573 (struct hbm_notification_response
*)cmd
;
575 cl_dbg(dev
, cl
, "hbm: notify stop response status=%d\n", rs
->status
);
577 if (rs
->status
== MEI_HBMS_SUCCESS
||
578 rs
->status
== MEI_HBMS_NOT_STARTED
) {
579 cl
->notify_en
= false;
582 /* TODO: spec is not clear yet about other possible issues */
583 cl
->status
= -EINVAL
;
588 * mei_hbm_cl_notify - signal notification event
590 * @dev: the device structure
591 * @cmd: notification client message
593 static void mei_hbm_cl_notify(struct mei_device
*dev
,
594 struct mei_hbm_cl_cmd
*cmd
)
598 cl
= mei_hbm_cl_find_by_cmd(dev
, cmd
);
604 * mei_hbm_cl_dma_map_req - send client dma map request
606 * @dev: the device structure
607 * @cl: mei host client
609 * Return: 0 on success and -EIO on write failure
611 int mei_hbm_cl_dma_map_req(struct mei_device
*dev
, struct mei_cl
*cl
)
613 struct mei_msg_hdr mei_hdr
;
614 struct hbm_client_dma_map_request req
;
617 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
619 memset(&req
, 0, sizeof(req
));
621 req
.hbm_cmd
= MEI_HBM_CLIENT_DMA_MAP_REQ_CMD
;
622 req
.client_buffer_id
= cl
->dma
.buffer_id
;
623 req
.address_lsb
= lower_32_bits(cl
->dma
.daddr
);
624 req
.address_msb
= upper_32_bits(cl
->dma
.daddr
);
625 req
.size
= cl
->dma
.size
;
627 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
629 dev_err(dev
->dev
, "dma map request failed: ret = %d\n", ret
);
635 * mei_hbm_cl_dma_unmap_req - send client dma unmap request
637 * @dev: the device structure
638 * @cl: mei host client
640 * Return: 0 on success and -EIO on write failure
642 int mei_hbm_cl_dma_unmap_req(struct mei_device
*dev
, struct mei_cl
*cl
)
644 struct mei_msg_hdr mei_hdr
;
645 struct hbm_client_dma_unmap_request req
;
648 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
650 memset(&req
, 0, sizeof(req
));
652 req
.hbm_cmd
= MEI_HBM_CLIENT_DMA_UNMAP_REQ_CMD
;
653 req
.client_buffer_id
= cl
->dma
.buffer_id
;
655 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
657 dev_err(dev
->dev
, "dma unmap request failed: ret = %d\n", ret
);
662 static void mei_hbm_cl_dma_map_res(struct mei_device
*dev
,
663 struct hbm_client_dma_response
*res
)
666 struct mei_cl_cb
*cb
, *next
;
669 list_for_each_entry_safe(cb
, next
, &dev
->ctrl_rd_list
, list
) {
670 if (cb
->fop_type
!= MEI_FOP_DMA_MAP
)
672 if (!cb
->cl
->dma
.buffer_id
|| cb
->cl
->dma_mapped
)
682 dev_err(dev
->dev
, "cl dma map failed %d\n", res
->status
);
683 cl
->status
= -EFAULT
;
685 dev_dbg(dev
->dev
, "cl dma map succeeded\n");
692 static void mei_hbm_cl_dma_unmap_res(struct mei_device
*dev
,
693 struct hbm_client_dma_response
*res
)
696 struct mei_cl_cb
*cb
, *next
;
699 list_for_each_entry_safe(cb
, next
, &dev
->ctrl_rd_list
, list
) {
700 if (cb
->fop_type
!= MEI_FOP_DMA_UNMAP
)
702 if (!cb
->cl
->dma
.buffer_id
|| !cb
->cl
->dma_mapped
)
712 dev_err(dev
->dev
, "cl dma unmap failed %d\n", res
->status
);
713 cl
->status
= -EFAULT
;
715 dev_dbg(dev
->dev
, "cl dma unmap succeeded\n");
723 * mei_hbm_prop_req - request property for a single client
725 * @dev: the device structure
726 * @start_idx: client index to start search
728 * Return: 0 on success and < 0 on failure
730 static int mei_hbm_prop_req(struct mei_device
*dev
, unsigned long start_idx
)
732 struct mei_msg_hdr mei_hdr
;
733 struct hbm_props_request req
;
737 addr
= find_next_bit(dev
->me_clients_map
, MEI_CLIENTS_MAX
, start_idx
);
739 /* We got all client properties */
740 if (addr
== MEI_CLIENTS_MAX
) {
741 dev
->hbm_state
= MEI_HBM_STARTED
;
742 mei_host_client_init(dev
);
746 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
748 memset(&req
, 0, sizeof(req
));
750 req
.hbm_cmd
= HOST_CLIENT_PROPERTIES_REQ_CMD
;
753 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
755 dev_err(dev
->dev
, "properties request write failed: ret = %d\n",
760 dev
->init_clients_timer
= dev
->timeouts
.client_init
;
761 mei_schedule_stall_timer(dev
);
767 * mei_hbm_pg - sends pg command
769 * @dev: the device structure
770 * @pg_cmd: the pg command code
772 * Return: -EIO on write failure
773 * -EOPNOTSUPP if the operation is not supported by the protocol
775 int mei_hbm_pg(struct mei_device
*dev
, u8 pg_cmd
)
777 struct mei_msg_hdr mei_hdr
;
778 struct hbm_power_gate req
;
781 if (!dev
->hbm_f_pg_supported
)
784 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
786 memset(&req
, 0, sizeof(req
));
787 req
.hbm_cmd
= pg_cmd
;
789 ret
= mei_hbm_write_message(dev
, &mei_hdr
, &req
);
791 dev_err(dev
->dev
, "power gate command write failed.\n");
794 EXPORT_SYMBOL_GPL(mei_hbm_pg
);
797 * mei_hbm_stop_req - send stop request message
801 * Return: -EIO on write failure
803 static int mei_hbm_stop_req(struct mei_device
*dev
)
805 struct mei_msg_hdr mei_hdr
;
806 struct hbm_host_stop_request req
;
808 mei_hbm_hdr(&mei_hdr
, sizeof(req
));
810 memset(&req
, 0, sizeof(req
));
811 req
.hbm_cmd
= HOST_STOP_REQ_CMD
;
812 req
.reason
= DRIVER_STOP_REQUEST
;
814 return mei_hbm_write_message(dev
, &mei_hdr
, &req
);
818 * mei_hbm_cl_flow_control_req - sends flow control request.
820 * @dev: the device structure
823 * Return: -EIO on write failure
825 int mei_hbm_cl_flow_control_req(struct mei_device
*dev
, struct mei_cl
*cl
)
827 struct hbm_flow_control req
;
829 cl_dbg(dev
, cl
, "sending flow control\n");
830 return mei_hbm_cl_write(dev
, cl
, MEI_FLOW_CONTROL_CMD
,
835 * mei_hbm_add_single_tx_flow_ctrl_creds - adds single buffer credentials.
837 * @dev: the device structure
838 * @fctrl: flow control response bus message
840 * Return: 0 on success, < 0 otherwise
842 static int mei_hbm_add_single_tx_flow_ctrl_creds(struct mei_device
*dev
,
843 struct hbm_flow_control
*fctrl
)
845 struct mei_me_client
*me_cl
;
848 me_cl
= mei_me_cl_by_id(dev
, fctrl
->me_addr
);
850 dev_err(dev
->dev
, "no such me client %d\n", fctrl
->me_addr
);
854 if (WARN_ON(me_cl
->props
.single_recv_buf
== 0)) {
859 me_cl
->tx_flow_ctrl_creds
++;
860 dev_dbg(dev
->dev
, "recv flow ctrl msg ME %d (single) creds = %d.\n",
861 fctrl
->me_addr
, me_cl
->tx_flow_ctrl_creds
);
865 mei_me_cl_put(me_cl
);
870 * mei_hbm_cl_tx_flow_ctrl_creds_res - flow control response from me
872 * @dev: the device structure
873 * @fctrl: flow control response bus message
875 static void mei_hbm_cl_tx_flow_ctrl_creds_res(struct mei_device
*dev
,
876 struct hbm_flow_control
*fctrl
)
880 if (!fctrl
->host_addr
) {
881 /* single receive buffer */
882 mei_hbm_add_single_tx_flow_ctrl_creds(dev
, fctrl
);
886 cl
= mei_hbm_cl_find_by_cmd(dev
, fctrl
);
888 cl
->tx_flow_ctrl_creds
++;
889 cl_dbg(dev
, cl
, "flow control creds = %d.\n",
890 cl
->tx_flow_ctrl_creds
);
896 * mei_hbm_cl_disconnect_req - sends disconnect message to fw.
898 * @dev: the device structure
899 * @cl: a client to disconnect from
901 * Return: -EIO on write failure
903 int mei_hbm_cl_disconnect_req(struct mei_device
*dev
, struct mei_cl
*cl
)
905 struct hbm_client_connect_request req
;
907 return mei_hbm_cl_write(dev
, cl
, CLIENT_DISCONNECT_REQ_CMD
,
912 * mei_hbm_cl_disconnect_rsp - sends disconnect response to the FW
914 * @dev: the device structure
915 * @cl: a client to disconnect from
917 * Return: -EIO on write failure
919 int mei_hbm_cl_disconnect_rsp(struct mei_device
*dev
, struct mei_cl
*cl
)
921 struct hbm_client_connect_response resp
;
923 return mei_hbm_cl_write(dev
, cl
, CLIENT_DISCONNECT_RES_CMD
,
924 &resp
, sizeof(resp
));
928 * mei_hbm_cl_disconnect_res - update the client state according
929 * disconnect response
931 * @dev: the device structure
932 * @cl: mei host client
933 * @cmd: disconnect client response host bus message
935 static void mei_hbm_cl_disconnect_res(struct mei_device
*dev
, struct mei_cl
*cl
,
936 struct mei_hbm_cl_cmd
*cmd
)
938 struct hbm_client_connect_response
*rs
=
939 (struct hbm_client_connect_response
*)cmd
;
941 cl_dbg(dev
, cl
, "hbm: disconnect response status=%d\n", rs
->status
);
943 if (rs
->status
== MEI_CL_DISCONN_SUCCESS
)
944 cl
->state
= MEI_FILE_DISCONNECT_REPLY
;
949 * mei_hbm_cl_connect_req - send connection request to specific me client
951 * @dev: the device structure
952 * @cl: a client to connect to
954 * Return: -EIO on write failure
956 int mei_hbm_cl_connect_req(struct mei_device
*dev
, struct mei_cl
*cl
)
958 struct hbm_client_connect_request req
;
960 return mei_hbm_cl_write(dev
, cl
, CLIENT_CONNECT_REQ_CMD
,
965 * mei_hbm_cl_connect_res - update the client state according
966 * connection response
968 * @dev: the device structure
969 * @cl: mei host client
970 * @cmd: connect client response host bus message
972 static void mei_hbm_cl_connect_res(struct mei_device
*dev
, struct mei_cl
*cl
,
973 struct mei_hbm_cl_cmd
*cmd
)
975 struct hbm_client_connect_response
*rs
=
976 (struct hbm_client_connect_response
*)cmd
;
978 cl_dbg(dev
, cl
, "hbm: connect response status=%s\n",
979 mei_cl_conn_status_str(rs
->status
));
981 if (rs
->status
== MEI_CL_CONN_SUCCESS
)
982 cl
->state
= MEI_FILE_CONNECTED
;
984 cl
->state
= MEI_FILE_DISCONNECT_REPLY
;
985 if (rs
->status
== MEI_CL_CONN_NOT_FOUND
) {
986 mei_me_cl_del(dev
, cl
->me_cl
);
987 if (dev
->dev_state
== MEI_DEV_ENABLED
)
988 schedule_work(&dev
->bus_rescan_work
);
991 cl
->status
= mei_cl_conn_status_to_errno(rs
->status
);
995 * mei_hbm_cl_res - process hbm response received on behalf
998 * @dev: the device structure
999 * @rs: hbm client message
1000 * @fop_type: file operation type
1002 static void mei_hbm_cl_res(struct mei_device
*dev
,
1003 struct mei_hbm_cl_cmd
*rs
,
1004 enum mei_cb_file_ops fop_type
)
1007 struct mei_cl_cb
*cb
, *next
;
1010 list_for_each_entry_safe(cb
, next
, &dev
->ctrl_rd_list
, list
) {
1014 if (cb
->fop_type
!= fop_type
)
1017 if (mei_hbm_cl_addr_equal(cl
, rs
)) {
1018 list_del_init(&cb
->list
);
1027 case MEI_FOP_CONNECT
:
1028 mei_hbm_cl_connect_res(dev
, cl
, rs
);
1030 case MEI_FOP_DISCONNECT
:
1031 mei_hbm_cl_disconnect_res(dev
, cl
, rs
);
1033 case MEI_FOP_NOTIFY_START
:
1034 mei_hbm_cl_notify_start_res(dev
, cl
, rs
);
1036 case MEI_FOP_NOTIFY_STOP
:
1037 mei_hbm_cl_notify_stop_res(dev
, cl
, rs
);
1043 cl
->timer_count
= 0;
1049 * mei_hbm_fw_disconnect_req - disconnect request initiated by ME firmware
1050 * host sends disconnect response
1052 * @dev: the device structure.
1053 * @disconnect_req: disconnect request bus message from the me
1055 * Return: -ENOMEM on allocation failure
1057 static int mei_hbm_fw_disconnect_req(struct mei_device
*dev
,
1058 struct hbm_client_connect_request
*disconnect_req
)
1061 struct mei_cl_cb
*cb
;
1063 cl
= mei_hbm_cl_find_by_cmd(dev
, disconnect_req
);
1065 cl_warn(dev
, cl
, "fw disconnect request received\n");
1066 cl
->state
= MEI_FILE_DISCONNECTING
;
1067 cl
->timer_count
= 0;
1069 cb
= mei_cl_enqueue_ctrl_wr_cb(cl
, 0, MEI_FOP_DISCONNECT_RSP
,
1078 * mei_hbm_pg_enter_res - PG enter response received
1080 * @dev: the device structure.
1082 * Return: 0 on success, -EPROTO on state mismatch
1084 static int mei_hbm_pg_enter_res(struct mei_device
*dev
)
1086 if (mei_pg_state(dev
) != MEI_PG_OFF
||
1087 dev
->pg_event
!= MEI_PG_EVENT_WAIT
) {
1088 dev_err(dev
->dev
, "hbm: pg entry response: state mismatch [%s, %d]\n",
1089 mei_pg_state_str(mei_pg_state(dev
)), dev
->pg_event
);
1093 dev
->pg_event
= MEI_PG_EVENT_RECEIVED
;
1094 wake_up(&dev
->wait_pg
);
1100 * mei_hbm_pg_resume - process with PG resume
1102 * @dev: the device structure.
1104 void mei_hbm_pg_resume(struct mei_device
*dev
)
1106 pm_request_resume(dev
->dev
);
1108 EXPORT_SYMBOL_GPL(mei_hbm_pg_resume
);
1111 * mei_hbm_pg_exit_res - PG exit response received
1113 * @dev: the device structure.
1115 * Return: 0 on success, -EPROTO on state mismatch
1117 static int mei_hbm_pg_exit_res(struct mei_device
*dev
)
1119 if (mei_pg_state(dev
) != MEI_PG_ON
||
1120 (dev
->pg_event
!= MEI_PG_EVENT_WAIT
&&
1121 dev
->pg_event
!= MEI_PG_EVENT_IDLE
)) {
1122 dev_err(dev
->dev
, "hbm: pg exit response: state mismatch [%s, %d]\n",
1123 mei_pg_state_str(mei_pg_state(dev
)), dev
->pg_event
);
1127 switch (dev
->pg_event
) {
1128 case MEI_PG_EVENT_WAIT
:
1129 dev
->pg_event
= MEI_PG_EVENT_RECEIVED
;
1130 wake_up(&dev
->wait_pg
);
1132 case MEI_PG_EVENT_IDLE
:
1134 * If the driver is not waiting on this then
1135 * this is HW initiated exit from PG.
1136 * Start runtime pm resume sequence to exit from PG.
1138 dev
->pg_event
= MEI_PG_EVENT_RECEIVED
;
1139 mei_hbm_pg_resume(dev
);
1142 WARN(1, "hbm: pg exit response: unexpected pg event = %d\n",
1151 * mei_hbm_config_features - check what hbm features and commands
1152 * are supported by the fw
1154 * @dev: the device structure
1156 static void mei_hbm_config_features(struct mei_device
*dev
)
1158 /* Power Gating Isolation Support */
1159 dev
->hbm_f_pg_supported
= 0;
1160 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_PGI
)
1161 dev
->hbm_f_pg_supported
= 1;
1163 if (dev
->version
.major_version
== HBM_MAJOR_VERSION_PGI
&&
1164 dev
->version
.minor_version
>= HBM_MINOR_VERSION_PGI
)
1165 dev
->hbm_f_pg_supported
= 1;
1167 dev
->hbm_f_dc_supported
= 0;
1168 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_DC
)
1169 dev
->hbm_f_dc_supported
= 1;
1171 dev
->hbm_f_ie_supported
= 0;
1172 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_IE
)
1173 dev
->hbm_f_ie_supported
= 1;
1175 /* disconnect on connect timeout instead of link reset */
1176 dev
->hbm_f_dot_supported
= 0;
1177 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_DOT
)
1178 dev
->hbm_f_dot_supported
= 1;
1180 /* Notification Event Support */
1181 dev
->hbm_f_ev_supported
= 0;
1182 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_EV
)
1183 dev
->hbm_f_ev_supported
= 1;
1185 /* Fixed Address Client Support */
1186 dev
->hbm_f_fa_supported
= 0;
1187 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_FA
)
1188 dev
->hbm_f_fa_supported
= 1;
1190 /* OS ver message Support */
1191 dev
->hbm_f_os_supported
= 0;
1192 if (dev
->version
.major_version
>= HBM_MAJOR_VERSION_OS
)
1193 dev
->hbm_f_os_supported
= 1;
1195 /* DMA Ring Support */
1196 dev
->hbm_f_dr_supported
= 0;
1197 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_DR
||
1198 (dev
->version
.major_version
== HBM_MAJOR_VERSION_DR
&&
1199 dev
->version
.minor_version
>= HBM_MINOR_VERSION_DR
))
1200 dev
->hbm_f_dr_supported
= 1;
1203 dev
->hbm_f_vt_supported
= 0;
1204 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_VT
||
1205 (dev
->version
.major_version
== HBM_MAJOR_VERSION_VT
&&
1206 dev
->version
.minor_version
>= HBM_MINOR_VERSION_VT
))
1207 dev
->hbm_f_vt_supported
= 1;
1210 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_GSC
||
1211 (dev
->version
.major_version
== HBM_MAJOR_VERSION_GSC
&&
1212 dev
->version
.minor_version
>= HBM_MINOR_VERSION_GSC
))
1213 dev
->hbm_f_gsc_supported
= 1;
1215 /* Capability message Support */
1216 dev
->hbm_f_cap_supported
= 0;
1217 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_CAP
||
1218 (dev
->version
.major_version
== HBM_MAJOR_VERSION_CAP
&&
1219 dev
->version
.minor_version
>= HBM_MINOR_VERSION_CAP
))
1220 dev
->hbm_f_cap_supported
= 1;
1222 /* Client DMA Support */
1223 dev
->hbm_f_cd_supported
= 0;
1224 if (dev
->version
.major_version
> HBM_MAJOR_VERSION_CD
||
1225 (dev
->version
.major_version
== HBM_MAJOR_VERSION_CD
&&
1226 dev
->version
.minor_version
>= HBM_MINOR_VERSION_CD
))
1227 dev
->hbm_f_cd_supported
= 1;
1231 * mei_hbm_version_is_supported - checks whether the driver can
1232 * support the hbm version of the device
1234 * @dev: the device structure
1235 * Return: true if driver can support hbm version of the device
1237 bool mei_hbm_version_is_supported(struct mei_device
*dev
)
1239 return (dev
->version
.major_version
< HBM_MAJOR_VERSION
) ||
1240 (dev
->version
.major_version
== HBM_MAJOR_VERSION
&&
1241 dev
->version
.minor_version
<= HBM_MINOR_VERSION
);
1245 * mei_hbm_dispatch - bottom half read routine after ISR to
1246 * handle the read bus message cmd processing.
1248 * @dev: the device structure
1249 * @hdr: header of bus message
1251 * Return: 0 on success and < 0 on failure
1253 int mei_hbm_dispatch(struct mei_device
*dev
, struct mei_msg_hdr
*hdr
)
1255 struct mei_bus_message
*mei_msg
;
1256 struct hbm_host_version_response
*version_res
;
1257 struct hbm_props_response
*props_res
;
1258 struct hbm_host_enum_response
*enum_res
;
1259 struct hbm_dma_setup_response
*dma_setup_res
;
1260 struct hbm_add_client_request
*add_cl_req
;
1261 struct hbm_capability_response
*capability_res
;
1264 struct mei_hbm_cl_cmd
*cl_cmd
;
1265 struct hbm_client_connect_request
*disconnect_req
;
1266 struct hbm_flow_control
*fctrl
;
1267 struct hbm_client_dma_response
*client_dma_res
;
1269 /* read the message to our buffer */
1270 BUG_ON(hdr
->length
>= sizeof(dev
->rd_msg_buf
));
1271 mei_read_slots(dev
, dev
->rd_msg_buf
, hdr
->length
);
1272 mei_msg
= (struct mei_bus_message
*)dev
->rd_msg_buf
;
1273 cl_cmd
= (struct mei_hbm_cl_cmd
*)mei_msg
;
1275 /* ignore spurious message and prevent reset nesting
1276 * hbm is put to idle during system reset
1278 if (dev
->hbm_state
== MEI_HBM_IDLE
) {
1279 dev_dbg(dev
->dev
, "hbm: state is idle ignore spurious messages\n");
1283 switch (mei_msg
->hbm_cmd
) {
1284 case HOST_START_RES_CMD
:
1285 dev_dbg(dev
->dev
, "hbm: start: response message received.\n");
1287 dev
->init_clients_timer
= 0;
1289 version_res
= (struct hbm_host_version_response
*)mei_msg
;
1291 dev_dbg(dev
->dev
, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n",
1292 HBM_MAJOR_VERSION
, HBM_MINOR_VERSION
,
1293 version_res
->me_max_version
.major_version
,
1294 version_res
->me_max_version
.minor_version
);
1296 if (version_res
->host_version_supported
) {
1297 dev
->version
.major_version
= HBM_MAJOR_VERSION
;
1298 dev
->version
.minor_version
= HBM_MINOR_VERSION
;
1300 dev
->version
.major_version
=
1301 version_res
->me_max_version
.major_version
;
1302 dev
->version
.minor_version
=
1303 version_res
->me_max_version
.minor_version
;
1306 if (!mei_hbm_version_is_supported(dev
)) {
1307 dev_warn(dev
->dev
, "hbm: start: version mismatch - stopping the driver.\n");
1309 dev
->hbm_state
= MEI_HBM_STOPPED
;
1310 if (mei_hbm_stop_req(dev
)) {
1311 dev_err(dev
->dev
, "hbm: start: failed to send stop request\n");
1317 mei_hbm_config_features(dev
);
1319 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1320 dev
->hbm_state
!= MEI_HBM_STARTING
) {
1321 if (dev
->dev_state
== MEI_DEV_POWER_DOWN
||
1322 dev
->dev_state
== MEI_DEV_POWERING_DOWN
) {
1323 dev_dbg(dev
->dev
, "hbm: start: on shutdown, ignoring\n");
1326 dev_err(dev
->dev
, "hbm: start: state mismatch, [%d, %d]\n",
1327 dev
->dev_state
, dev
->hbm_state
);
1331 if (dev
->hbm_f_cap_supported
) {
1332 if (mei_hbm_capabilities_req(dev
))
1334 wake_up(&dev
->wait_hbm_start
);
1338 if (dev
->hbm_f_dr_supported
) {
1339 if (mei_dmam_ring_alloc(dev
))
1340 dev_info(dev
->dev
, "running w/o dma ring\n");
1341 if (mei_dma_ring_is_allocated(dev
)) {
1342 if (mei_hbm_dma_setup_req(dev
))
1345 wake_up(&dev
->wait_hbm_start
);
1350 dev
->hbm_f_dr_supported
= 0;
1351 mei_dmam_ring_free(dev
);
1353 if (mei_hbm_enum_clients_req(dev
))
1356 wake_up(&dev
->wait_hbm_start
);
1359 case MEI_HBM_CAPABILITIES_RES_CMD
:
1360 dev_dbg(dev
->dev
, "hbm: capabilities response: message received.\n");
1362 dev
->init_clients_timer
= 0;
1364 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1365 dev
->hbm_state
!= MEI_HBM_CAP_SETUP
) {
1366 if (dev
->dev_state
== MEI_DEV_POWER_DOWN
||
1367 dev
->dev_state
== MEI_DEV_POWERING_DOWN
) {
1368 dev_dbg(dev
->dev
, "hbm: capabilities response: on shutdown, ignoring\n");
1371 dev_err(dev
->dev
, "hbm: capabilities response: state mismatch, [%d, %d]\n",
1372 dev
->dev_state
, dev
->hbm_state
);
1376 capability_res
= (struct hbm_capability_response
*)mei_msg
;
1377 if (!(capability_res
->capability_granted
[0] & HBM_CAP_VT
))
1378 dev
->hbm_f_vt_supported
= 0;
1379 if (!(capability_res
->capability_granted
[0] & HBM_CAP_CD
))
1380 dev
->hbm_f_cd_supported
= 0;
1382 if (!(capability_res
->capability_granted
[0] & HBM_CAP_GSC
))
1383 dev
->hbm_f_gsc_supported
= 0;
1385 if (dev
->hbm_f_dr_supported
) {
1386 if (mei_dmam_ring_alloc(dev
))
1387 dev_info(dev
->dev
, "running w/o dma ring\n");
1388 if (mei_dma_ring_is_allocated(dev
)) {
1389 if (mei_hbm_dma_setup_req(dev
))
1395 dev
->hbm_f_dr_supported
= 0;
1396 mei_dmam_ring_free(dev
);
1398 if (mei_hbm_enum_clients_req(dev
))
1402 case MEI_HBM_DMA_SETUP_RES_CMD
:
1403 dev_dbg(dev
->dev
, "hbm: dma setup response: message received.\n");
1405 dev
->init_clients_timer
= 0;
1407 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1408 dev
->hbm_state
!= MEI_HBM_DR_SETUP
) {
1409 if (dev
->dev_state
== MEI_DEV_POWER_DOWN
||
1410 dev
->dev_state
== MEI_DEV_POWERING_DOWN
) {
1411 dev_dbg(dev
->dev
, "hbm: dma setup response: on shutdown, ignoring\n");
1414 dev_err(dev
->dev
, "hbm: dma setup response: state mismatch, [%d, %d]\n",
1415 dev
->dev_state
, dev
->hbm_state
);
1419 dma_setup_res
= (struct hbm_dma_setup_response
*)mei_msg
;
1421 if (dma_setup_res
->status
) {
1422 u8 status
= dma_setup_res
->status
;
1424 if (status
== MEI_HBMS_NOT_ALLOWED
) {
1425 dev_dbg(dev
->dev
, "hbm: dma setup not allowed\n");
1427 dev_info(dev
->dev
, "hbm: dma setup response: failure = %d %s\n",
1429 mei_hbm_status_str(status
));
1431 dev
->hbm_f_dr_supported
= 0;
1432 mei_dmam_ring_free(dev
);
1435 if (mei_hbm_enum_clients_req(dev
))
1439 case CLIENT_CONNECT_RES_CMD
:
1440 dev_dbg(dev
->dev
, "hbm: client connect response: message received.\n");
1441 mei_hbm_cl_res(dev
, cl_cmd
, MEI_FOP_CONNECT
);
1444 case CLIENT_DISCONNECT_RES_CMD
:
1445 dev_dbg(dev
->dev
, "hbm: client disconnect response: message received.\n");
1446 mei_hbm_cl_res(dev
, cl_cmd
, MEI_FOP_DISCONNECT
);
1449 case MEI_FLOW_CONTROL_CMD
:
1450 dev_dbg(dev
->dev
, "hbm: client flow control response: message received.\n");
1452 fctrl
= (struct hbm_flow_control
*)mei_msg
;
1453 mei_hbm_cl_tx_flow_ctrl_creds_res(dev
, fctrl
);
1456 case MEI_PG_ISOLATION_ENTRY_RES_CMD
:
1457 dev_dbg(dev
->dev
, "hbm: power gate isolation entry response received\n");
1458 ret
= mei_hbm_pg_enter_res(dev
);
1463 case MEI_PG_ISOLATION_EXIT_REQ_CMD
:
1464 dev_dbg(dev
->dev
, "hbm: power gate isolation exit request received\n");
1465 ret
= mei_hbm_pg_exit_res(dev
);
1470 case HOST_CLIENT_PROPERTIES_RES_CMD
:
1471 dev_dbg(dev
->dev
, "hbm: properties response: message received.\n");
1473 dev
->init_clients_timer
= 0;
1475 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1476 dev
->hbm_state
!= MEI_HBM_CLIENT_PROPERTIES
) {
1477 if (dev
->dev_state
== MEI_DEV_POWER_DOWN
||
1478 dev
->dev_state
== MEI_DEV_POWERING_DOWN
) {
1479 dev_dbg(dev
->dev
, "hbm: properties response: on shutdown, ignoring\n");
1482 dev_err(dev
->dev
, "hbm: properties response: state mismatch, [%d, %d]\n",
1483 dev
->dev_state
, dev
->hbm_state
);
1487 props_res
= (struct hbm_props_response
*)mei_msg
;
1489 if (props_res
->status
== MEI_HBMS_CLIENT_NOT_FOUND
) {
1490 dev_dbg(dev
->dev
, "hbm: properties response: %d CLIENT_NOT_FOUND\n",
1491 props_res
->me_addr
);
1492 } else if (props_res
->status
) {
1493 dev_err(dev
->dev
, "hbm: properties response: wrong status = %d %s\n",
1495 mei_hbm_status_str(props_res
->status
));
1498 mei_hbm_me_cl_add(dev
, props_res
);
1501 /* request property for the next client */
1502 if (mei_hbm_prop_req(dev
, props_res
->me_addr
+ 1))
1507 case HOST_ENUM_RES_CMD
:
1508 dev_dbg(dev
->dev
, "hbm: enumeration response: message received\n");
1510 dev
->init_clients_timer
= 0;
1512 enum_res
= (struct hbm_host_enum_response
*) mei_msg
;
1513 BUILD_BUG_ON(sizeof(dev
->me_clients_map
)
1514 < sizeof(enum_res
->valid_addresses
));
1515 memcpy(dev
->me_clients_map
, enum_res
->valid_addresses
,
1516 sizeof(enum_res
->valid_addresses
));
1518 if (dev
->dev_state
!= MEI_DEV_INIT_CLIENTS
||
1519 dev
->hbm_state
!= MEI_HBM_ENUM_CLIENTS
) {
1520 if (dev
->dev_state
== MEI_DEV_POWER_DOWN
||
1521 dev
->dev_state
== MEI_DEV_POWERING_DOWN
) {
1522 dev_dbg(dev
->dev
, "hbm: enumeration response: on shutdown, ignoring\n");
1525 dev_err(dev
->dev
, "hbm: enumeration response: state mismatch, [%d, %d]\n",
1526 dev
->dev_state
, dev
->hbm_state
);
1530 dev
->hbm_state
= MEI_HBM_CLIENT_PROPERTIES
;
1532 /* first property request */
1533 if (mei_hbm_prop_req(dev
, 0))
1538 case HOST_STOP_RES_CMD
:
1539 dev_dbg(dev
->dev
, "hbm: stop response: message received\n");
1541 dev
->init_clients_timer
= 0;
1543 if (dev
->hbm_state
!= MEI_HBM_STOPPED
) {
1544 dev_err(dev
->dev
, "hbm: stop response: state mismatch, [%d, %d]\n",
1545 dev
->dev_state
, dev
->hbm_state
);
1549 mei_set_devstate(dev
, MEI_DEV_POWER_DOWN
);
1550 dev_info(dev
->dev
, "hbm: stop response: resetting.\n");
1551 /* force the reset */
1554 case CLIENT_DISCONNECT_REQ_CMD
:
1555 dev_dbg(dev
->dev
, "hbm: disconnect request: message received\n");
1557 disconnect_req
= (struct hbm_client_connect_request
*)mei_msg
;
1558 mei_hbm_fw_disconnect_req(dev
, disconnect_req
);
1561 case ME_STOP_REQ_CMD
:
1562 dev_dbg(dev
->dev
, "hbm: stop request: message received\n");
1563 dev
->hbm_state
= MEI_HBM_STOPPED
;
1564 if (mei_hbm_stop_req(dev
)) {
1565 dev_err(dev
->dev
, "hbm: stop request: failed to send stop request\n");
1570 case MEI_HBM_ADD_CLIENT_REQ_CMD
:
1571 dev_dbg(dev
->dev
, "hbm: add client request received\n");
1573 * after the host receives the enum_resp
1574 * message clients may be added or removed
1576 if (dev
->hbm_state
<= MEI_HBM_ENUM_CLIENTS
||
1577 dev
->hbm_state
>= MEI_HBM_STOPPED
) {
1578 dev_err(dev
->dev
, "hbm: add client: state mismatch, [%d, %d]\n",
1579 dev
->dev_state
, dev
->hbm_state
);
1582 add_cl_req
= (struct hbm_add_client_request
*)mei_msg
;
1583 ret
= mei_hbm_fw_add_cl_req(dev
, add_cl_req
);
1585 dev_err(dev
->dev
, "hbm: add client: failed to send response %d\n",
1589 dev_dbg(dev
->dev
, "hbm: add client request processed\n");
1592 case MEI_HBM_NOTIFY_RES_CMD
:
1593 dev_dbg(dev
->dev
, "hbm: notify response received\n");
1594 mei_hbm_cl_res(dev
, cl_cmd
, notify_res_to_fop(cl_cmd
));
1597 case MEI_HBM_NOTIFICATION_CMD
:
1598 dev_dbg(dev
->dev
, "hbm: notification\n");
1599 mei_hbm_cl_notify(dev
, cl_cmd
);
1602 case MEI_HBM_CLIENT_DMA_MAP_RES_CMD
:
1603 dev_dbg(dev
->dev
, "hbm: client dma map response: message received.\n");
1604 client_dma_res
= (struct hbm_client_dma_response
*)mei_msg
;
1605 mei_hbm_cl_dma_map_res(dev
, client_dma_res
);
1608 case MEI_HBM_CLIENT_DMA_UNMAP_RES_CMD
:
1609 dev_dbg(dev
->dev
, "hbm: client dma unmap response: message received.\n");
1610 client_dma_res
= (struct hbm_client_dma_response
*)mei_msg
;
1611 mei_hbm_cl_dma_unmap_res(dev
, client_dma_res
);
1615 WARN(1, "hbm: wrong command %d\n", mei_msg
->hbm_cmd
);