blob: d50c8d1fb36d1baa2f6d2e9e65ef3d923bd71b76 [file] [log] [blame]
Tomas Winklerbb1b0132012-12-25 19:06:07 +02001/*
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
Tomas Winkler4fcbc992014-03-18 22:51:55 +020017#include <linux/export.h>
Tomas Winklerbb1b0132012-12-25 19:06:07 +020018#include <linux/pci.h>
19#include <linux/sched.h>
20#include <linux/wait.h>
21#include <linux/mei.h>
Tomas Winkler180ea052014-03-18 22:52:02 +020022#include <linux/pm_runtime.h>
Tomas Winklerbb1b0132012-12-25 19:06:07 +020023
24#include "mei_dev.h"
Tomas Winkler0edb23f2013-01-08 23:07:12 +020025#include "hbm.h"
Alexander Usyskin12d00662014-02-17 15:13:23 +020026#include "client.h"
Tomas Winklerbb1b0132012-12-25 19:06:07 +020027
Tomas Winkler89778d62014-08-21 14:29:16 +030028static const char *mei_hbm_status_str(enum mei_hbm_status status)
29{
30#define MEI_HBM_STATUS(status) case MEI_HBMS_##status: return #status
31 switch (status) {
32 MEI_HBM_STATUS(SUCCESS);
33 MEI_HBM_STATUS(CLIENT_NOT_FOUND);
34 MEI_HBM_STATUS(ALREADY_EXISTS);
35 MEI_HBM_STATUS(REJECTED);
36 MEI_HBM_STATUS(INVALID_PARAMETER);
37 MEI_HBM_STATUS(NOT_ALLOWED);
38 MEI_HBM_STATUS(ALREADY_STARTED);
39 MEI_HBM_STATUS(NOT_STARTED);
40 default: return "unknown";
41 }
42#undef MEI_HBM_STATUS
43};
44
Alexander Usyskin285e2992014-02-17 15:13:20 +020045static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status)
46{
47#define MEI_CL_CS(status) case MEI_CL_CONN_##status: return #status
48 switch (status) {
49 MEI_CL_CS(SUCCESS);
50 MEI_CL_CS(NOT_FOUND);
51 MEI_CL_CS(ALREADY_STARTED);
52 MEI_CL_CS(OUT_OF_RESOURCES);
53 MEI_CL_CS(MESSAGE_SMALL);
54 default: return "unknown";
55 }
56#undef MEI_CL_CCS
57}
58
59/**
60 * mei_cl_conn_status_to_errno - convert client connect response
61 * status to error code
62 *
63 * @status: client connect response status
64 *
65 * returns corresponding error code
66 */
67static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status)
68{
69 switch (status) {
70 case MEI_CL_CONN_SUCCESS: return 0;
71 case MEI_CL_CONN_NOT_FOUND: return -ENOTTY;
72 case MEI_CL_CONN_ALREADY_STARTED: return -EBUSY;
73 case MEI_CL_CONN_OUT_OF_RESOURCES: return -EBUSY;
74 case MEI_CL_CONN_MESSAGE_SMALL: return -EINVAL;
75 default: return -EINVAL;
76 }
77}
78
Tomas Winklerbb1b0132012-12-25 19:06:07 +020079/**
Tomas Winkler84b32942014-05-07 16:51:28 +030080 * mei_hbm_idle - set hbm to idle state
81 *
82 * @dev: the device structure
83 */
84void mei_hbm_idle(struct mei_device *dev)
85{
86 dev->init_clients_timer = 0;
87 dev->hbm_state = MEI_HBM_IDLE;
88}
89
90/**
Tomas Winkler25ca6472014-08-21 14:29:14 +030091 * mei_me_cl_remove_all - remove all me clients
92 *
93 * @dev: the device structure
94 */
95static void mei_me_cl_remove_all(struct mei_device *dev)
96{
97 struct mei_me_client *me_cl, *next;
98 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
99 list_del(&me_cl->list);
100 kfree(me_cl);
101 }
102}
103
104/**
Tomas Winkler84b32942014-05-07 16:51:28 +0300105 * mei_hbm_reset - reset hbm counters and book keeping data structurs
106 *
107 * @dev: the device structure
108 */
109void mei_hbm_reset(struct mei_device *dev)
110{
Tomas Winkler84b32942014-05-07 16:51:28 +0300111 dev->me_client_presentation_num = 0;
112 dev->me_client_index = 0;
113
Tomas Winkler25ca6472014-08-21 14:29:14 +0300114 mei_me_cl_remove_all(dev);
Tomas Winkler84b32942014-05-07 16:51:28 +0300115
116 mei_hbm_idle(dev);
117}
118
119/**
Tomas Winklercd51ed62012-12-25 19:06:09 +0200120 * mei_hbm_cl_hdr - construct client hbm header
Masanari Iida393b1482013-04-05 01:05:05 +0900121 *
Tomas Winkler68d1aa62014-08-21 14:29:11 +0300122 * @cl: client
Tomas Winklercd51ed62012-12-25 19:06:09 +0200123 * @hbm_cmd: host bus message command
124 * @buf: buffer for cl header
125 * @len: buffer length
126 */
127static inline
128void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len)
129{
130 struct mei_hbm_cl_cmd *cmd = buf;
131
132 memset(cmd, 0, len);
133
134 cmd->hbm_cmd = hbm_cmd;
135 cmd->host_addr = cl->host_client_id;
136 cmd->me_addr = cl->me_client_id;
137}
138
139/**
Tomas Winkler68d1aa62014-08-21 14:29:11 +0300140 * mei_hbm_cl_write - write simple hbm client message
141 *
142 * @dev: the device structure
143 * @cl: client
144 * @hbm_cmd: host bus message command
145 * @len: buffer length
146 */
147static inline
148int mei_hbm_cl_write(struct mei_device *dev,
149 struct mei_cl *cl, u8 hbm_cmd, size_t len)
150{
151 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
152
153 mei_hbm_hdr(mei_hdr, len);
154 mei_hbm_cl_hdr(cl, hbm_cmd, dev->wr_msg.data, len);
155
156 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
157}
158
159/**
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200160 * mei_hbm_cl_addr_equal - tells if they have the same address
Tomas Winklercd51ed62012-12-25 19:06:09 +0200161 *
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200162 * @cl: - client
163 * @buf: buffer with cl header
Tomas Winklercd51ed62012-12-25 19:06:09 +0200164 *
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200165 * returns true if addresses are the same
Tomas Winklercd51ed62012-12-25 19:06:09 +0200166 */
167static inline
168bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
169{
170 struct mei_hbm_cl_cmd *cmd = buf;
171 return cl->host_client_id == cmd->host_addr &&
172 cl->me_client_id == cmd->me_addr;
173}
174
175
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300176int mei_hbm_start_wait(struct mei_device *dev)
177{
178 int ret;
179 if (dev->hbm_state > MEI_HBM_START)
180 return 0;
181
182 mutex_unlock(&dev->device_lock);
183 ret = wait_event_interruptible_timeout(dev->wait_recvd_msg,
184 dev->hbm_state == MEI_HBM_IDLE ||
Tomas Winkler544f9462014-01-08 20:19:21 +0200185 dev->hbm_state >= MEI_HBM_STARTED,
Tomas Winkler7d93e582014-01-14 23:10:10 +0200186 mei_secs_to_jiffies(MEI_HBM_TIMEOUT));
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300187 mutex_lock(&dev->device_lock);
188
189 if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) {
190 dev->hbm_state = MEI_HBM_IDLE;
Masanari Iida8b513d02013-05-21 23:13:12 +0900191 dev_err(&dev->pdev->dev, "waiting for mei start failed\n");
Alexander Usyskin7ca96aa2014-02-19 17:35:49 +0200192 return -ETIME;
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300193 }
194 return 0;
195}
196
Tomas Winkler6bbda152012-12-25 19:06:12 +0200197/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200198 * mei_hbm_start_req - sends start request message.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200199 *
200 * @dev: the device structure
Tomas Winkler544f9462014-01-08 20:19:21 +0200201 *
202 * returns 0 on success and < 0 on failure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200203 */
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300204int mei_hbm_start_req(struct mei_device *dev)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200205{
Tomas Winklere46f1872012-12-25 19:06:10 +0200206 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200207 struct hbm_host_version_request *start_req;
208 const size_t len = sizeof(struct hbm_host_version_request);
Tomas Winkler544f9462014-01-08 20:19:21 +0200209 int ret;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200210
Tomas Winkler5ca2d382014-08-21 14:29:13 +0300211 mei_hbm_reset(dev);
212
Tomas Winklere46f1872012-12-25 19:06:10 +0200213 mei_hbm_hdr(mei_hdr, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200214
215 /* host start message */
Tomas Winklere46f1872012-12-25 19:06:10 +0200216 start_req = (struct hbm_host_version_request *)dev->wr_msg.data;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200217 memset(start_req, 0, len);
218 start_req->hbm_cmd = HOST_START_REQ_CMD;
219 start_req->host_version.major_version = HBM_MAJOR_VERSION;
220 start_req->host_version.minor_version = HBM_MINOR_VERSION;
221
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300222 dev->hbm_state = MEI_HBM_IDLE;
Tomas Winkler544f9462014-01-08 20:19:21 +0200223 ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data);
224 if (ret) {
225 dev_err(&dev->pdev->dev, "version message write failed: ret = %d\n",
226 ret);
227 return ret;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200228 }
Tomas Winkler544f9462014-01-08 20:19:21 +0200229
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300230 dev->hbm_state = MEI_HBM_START;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200231 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300232 return 0;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200233}
234
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300235/*
Tomas Winkler8120e722012-12-25 19:06:11 +0200236 * mei_hbm_enum_clients_req - sends enumeration client request message.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200237 *
238 * @dev: the device structure
239 *
Tomas Winkler544f9462014-01-08 20:19:21 +0200240 * returns 0 on success and < 0 on failure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200241 */
Tomas Winkler544f9462014-01-08 20:19:21 +0200242static int mei_hbm_enum_clients_req(struct mei_device *dev)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200243{
Tomas Winklere46f1872012-12-25 19:06:10 +0200244 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200245 struct hbm_host_enum_request *enum_req;
246 const size_t len = sizeof(struct hbm_host_enum_request);
Tomas Winkler544f9462014-01-08 20:19:21 +0200247 int ret;
248
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200249 /* enumerate clients */
Tomas Winklere46f1872012-12-25 19:06:10 +0200250 mei_hbm_hdr(mei_hdr, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200251
Tomas Winklere46f1872012-12-25 19:06:10 +0200252 enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data;
253 memset(enum_req, 0, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200254 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
255
Tomas Winkler544f9462014-01-08 20:19:21 +0200256 ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data);
257 if (ret) {
258 dev_err(&dev->pdev->dev, "enumeration request write failed: ret = %d.\n",
259 ret);
260 return ret;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200261 }
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300262 dev->hbm_state = MEI_HBM_ENUM_CLIENTS;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200263 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
Tomas Winkler544f9462014-01-08 20:19:21 +0200264 return 0;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200265}
266
Tomas Winkler5ca2d382014-08-21 14:29:13 +0300267/*
268 * mei_hbm_me_cl_add - add new me client to the list
269 *
270 * @dev: the device structure
271 * @res: hbm property response
272 *
273 * returns 0 on success and -ENOMEM on allocation failure
274 */
275
276static int mei_hbm_me_cl_add(struct mei_device *dev,
277 struct hbm_props_response *res)
278{
279 struct mei_me_client *me_cl;
280
281 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL);
282 if (!me_cl)
283 return -ENOMEM;
284
285 me_cl->props = res->client_properties;
286 me_cl->client_id = res->me_addr;
287 me_cl->mei_flow_ctrl_creds = 0;
288
289 list_add(&me_cl->list, &dev->me_clients);
290 return 0;
291}
292
Tomas Winkler8120e722012-12-25 19:06:11 +0200293/**
Masanari Iida393b1482013-04-05 01:05:05 +0900294 * mei_hbm_prop_req - request property for a single client
Tomas Winkler8120e722012-12-25 19:06:11 +0200295 *
296 * @dev: the device structure
297 *
Tomas Winkler544f9462014-01-08 20:19:21 +0200298 * returns 0 on success and < 0 on failure
Tomas Winkler8120e722012-12-25 19:06:11 +0200299 */
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200300
Tomas Winkler8120e722012-12-25 19:06:11 +0200301static int mei_hbm_prop_req(struct mei_device *dev)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200302{
303
Tomas Winklere46f1872012-12-25 19:06:10 +0200304 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200305 struct hbm_props_request *prop_req;
306 const size_t len = sizeof(struct hbm_props_request);
307 unsigned long next_client_index;
Tomas Winkler544f9462014-01-08 20:19:21 +0200308 int ret;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200309
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200310 next_client_index = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX,
311 dev->me_client_index);
312
313 /* We got all client properties */
314 if (next_client_index == MEI_CLIENTS_MAX) {
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300315 dev->hbm_state = MEI_HBM_STARTED;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200316 schedule_work(&dev->init_work);
317
318 return 0;
319 }
320
Tomas Winklere46f1872012-12-25 19:06:10 +0200321 mei_hbm_hdr(mei_hdr, len);
322 prop_req = (struct hbm_props_request *)dev->wr_msg.data;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200323
324 memset(prop_req, 0, sizeof(struct hbm_props_request));
325
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200326 prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
Tomas Winkler3438c1f2014-08-21 14:29:10 +0300327 prop_req->me_addr = next_client_index;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200328
Tomas Winkler544f9462014-01-08 20:19:21 +0200329 ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data);
330 if (ret) {
331 dev_err(&dev->pdev->dev, "properties request write failed: ret = %d\n",
332 ret);
333 return ret;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200334 }
335
336 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
337 dev->me_client_index = next_client_index;
338
339 return 0;
340}
341
Tomas Winkler4fcbc992014-03-18 22:51:55 +0200342/*
343 * mei_hbm_pg - sends pg command
344 *
345 * @dev: the device structure
346 * @pg_cmd: the pg command code
347 *
348 * This function returns -EIO on write failure
349 */
350int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd)
351{
352 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
353 struct hbm_power_gate *req;
354 const size_t len = sizeof(struct hbm_power_gate);
355 int ret;
356
357 mei_hbm_hdr(mei_hdr, len);
358
359 req = (struct hbm_power_gate *)dev->wr_msg.data;
360 memset(req, 0, len);
361 req->hbm_cmd = pg_cmd;
362
363 ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data);
364 if (ret)
365 dev_err(&dev->pdev->dev, "power gate command write failed.\n");
366 return ret;
367}
368EXPORT_SYMBOL_GPL(mei_hbm_pg);
369
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200370/**
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200371 * mei_hbm_stop_req - send stop request message
Tomas Winklere46f1872012-12-25 19:06:10 +0200372 *
373 * @dev - mei device
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200374 * @cl: client info
375 *
376 * This function returns -EIO on write failure
Tomas Winklere46f1872012-12-25 19:06:10 +0200377 */
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200378static int mei_hbm_stop_req(struct mei_device *dev)
Tomas Winklere46f1872012-12-25 19:06:10 +0200379{
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200380 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklere46f1872012-12-25 19:06:10 +0200381 struct hbm_host_stop_request *req =
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200382 (struct hbm_host_stop_request *)dev->wr_msg.data;
Tomas Winklere46f1872012-12-25 19:06:10 +0200383 const size_t len = sizeof(struct hbm_host_stop_request);
384
385 mei_hbm_hdr(mei_hdr, len);
386
387 memset(req, 0, len);
388 req->hbm_cmd = HOST_STOP_REQ_CMD;
389 req->reason = DRIVER_STOP_REQUEST;
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200390
391 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
Tomas Winklere46f1872012-12-25 19:06:10 +0200392}
393
394/**
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200395 * mei_hbm_cl_flow_control_req - sends flow control request.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200396 *
397 * @dev: the device structure
Tomas Winkler8120e722012-12-25 19:06:11 +0200398 * @cl: client info
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200399 *
400 * This function returns -EIO on write failure
401 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200402int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200403{
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200404 const size_t len = sizeof(struct hbm_flow_control);
Tomas Winkler46922182014-03-16 14:35:55 +0200405 cl_dbg(dev, cl, "sending flow control\n");
Tomas Winkler68d1aa62014-08-21 14:29:11 +0300406 return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200407}
408
409/**
Masanari Iida393b1482013-04-05 01:05:05 +0900410 * mei_hbm_add_single_flow_creds - adds single buffer credentials.
Tomas Winkler6bbda152012-12-25 19:06:12 +0200411 *
Masanari Iida393b1482013-04-05 01:05:05 +0900412 * @dev: the device structure
Tomas Winkler6bbda152012-12-25 19:06:12 +0200413 * @flow: flow control.
Alexander Usyskin12d00662014-02-17 15:13:23 +0200414 *
415 * return 0 on success, < 0 otherwise
Tomas Winkler6bbda152012-12-25 19:06:12 +0200416 */
Alexander Usyskin12d00662014-02-17 15:13:23 +0200417static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
Tomas Winkler6bbda152012-12-25 19:06:12 +0200418 struct hbm_flow_control *flow)
419{
Alexander Usyskin12d00662014-02-17 15:13:23 +0200420 struct mei_me_client *me_cl;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200421
Tomas Winklerd3208322014-08-24 12:08:55 +0300422 me_cl = mei_me_cl_by_id(dev, flow->me_addr);
423 if (!me_cl) {
Alexander Usyskin12d00662014-02-17 15:13:23 +0200424 dev_err(&dev->pdev->dev, "no such me client %d\n",
425 flow->me_addr);
Tomas Winklerd3208322014-08-24 12:08:55 +0300426 return -ENOENT;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200427 }
Alexander Usyskin12d00662014-02-17 15:13:23 +0200428
Tomas Winklerd3208322014-08-24 12:08:55 +0300429 if (WARN_ON(me_cl->props.single_recv_buf == 0))
430 return -EINVAL;
431
432 me_cl->mei_flow_ctrl_creds++;
433 dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n",
434 flow->me_addr, me_cl->mei_flow_ctrl_creds);
Alexander Usyskin12d00662014-02-17 15:13:23 +0200435
436 return 0;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200437}
438
439/**
440 * mei_hbm_cl_flow_control_res - flow control response from me
441 *
442 * @dev: the device structure
443 * @flow_control: flow control response bus message
444 */
445static void mei_hbm_cl_flow_control_res(struct mei_device *dev,
446 struct hbm_flow_control *flow_control)
447{
Tomas Winkler31f88f52014-02-17 15:13:25 +0200448 struct mei_cl *cl;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200449
450 if (!flow_control->host_addr) {
451 /* single receive buffer */
452 mei_hbm_add_single_flow_creds(dev, flow_control);
453 return;
454 }
455
456 /* normal connection */
Tomas Winkler31f88f52014-02-17 15:13:25 +0200457 list_for_each_entry(cl, &dev->file_list, link) {
Tomas Winkler6bbda152012-12-25 19:06:12 +0200458 if (mei_hbm_cl_addr_equal(cl, flow_control)) {
459 cl->mei_flow_ctrl_creds++;
Tomas Winkler5ca2d382014-08-21 14:29:13 +0300460 dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d creds %d.\n",
461 flow_control->host_addr, flow_control->me_addr,
462 cl->mei_flow_ctrl_creds);
463 break;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200464 }
465 }
466}
467
468
469/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200470 * mei_hbm_cl_disconnect_req - sends disconnect message to fw.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200471 *
472 * @dev: the device structure
Tomas Winkler8120e722012-12-25 19:06:11 +0200473 * @cl: a client to disconnect from
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200474 *
475 * This function returns -EIO on write failure
476 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200477int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200478{
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200479 const size_t len = sizeof(struct hbm_client_connect_request);
Tomas Winkler68d1aa62014-08-21 14:29:11 +0300480 return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200481}
482
483/**
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200484 * mei_hbm_cl_disconnect_rsp - sends disconnect respose to the FW
485 *
486 * @dev: the device structure
487 * @cl: a client to disconnect from
488 *
489 * This function returns -EIO on write failure
490 */
491int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl)
492{
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200493 const size_t len = sizeof(struct hbm_client_connect_response);
Tomas Winkler68d1aa62014-08-21 14:29:11 +0300494 return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, len);
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200495}
496
497/**
Tomas Winkler6bbda152012-12-25 19:06:12 +0200498 * mei_hbm_cl_disconnect_res - disconnect response from ME
499 *
500 * @dev: the device structure
501 * @rs: disconnect response bus message
502 */
503static void mei_hbm_cl_disconnect_res(struct mei_device *dev,
504 struct hbm_client_connect_response *rs)
505{
506 struct mei_cl *cl;
Tomas Winkler64092852014-02-17 15:13:21 +0200507 struct mei_cl_cb *cb, *next;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200508
Alexander Usyskin285e2992014-02-17 15:13:20 +0200509 dev_dbg(&dev->pdev->dev, "hbm: disconnect response cl:host=%02d me=%02d status=%d\n",
510 rs->me_addr, rs->host_addr, rs->status);
Tomas Winkler6bbda152012-12-25 19:06:12 +0200511
Tomas Winkler64092852014-02-17 15:13:21 +0200512 list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list.list, list) {
513 cl = cb->cl;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200514
Tomas Winkler64092852014-02-17 15:13:21 +0200515 /* this should not happen */
516 if (WARN_ON(!cl)) {
517 list_del(&cb->list);
Tomas Winkler6bbda152012-12-25 19:06:12 +0200518 return;
519 }
520
Tomas Winkler6bbda152012-12-25 19:06:12 +0200521 if (mei_hbm_cl_addr_equal(cl, rs)) {
Tomas Winkler64092852014-02-17 15:13:21 +0200522 list_del(&cb->list);
Alexander Usyskin285e2992014-02-17 15:13:20 +0200523 if (rs->status == MEI_CL_DISCONN_SUCCESS)
Tomas Winkler6bbda152012-12-25 19:06:12 +0200524 cl->state = MEI_FILE_DISCONNECTED;
525
526 cl->status = 0;
527 cl->timer_count = 0;
528 break;
529 }
530 }
531}
532
533/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200534 * mei_hbm_cl_connect_req - send connection request to specific me client
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200535 *
536 * @dev: the device structure
Tomas Winkler8120e722012-12-25 19:06:11 +0200537 * @cl: a client to connect to
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200538 *
Tomas Winkler8120e722012-12-25 19:06:11 +0200539 * returns -EIO on write failure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200540 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200541int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200542{
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200543 const size_t len = sizeof(struct hbm_client_connect_request);
Tomas Winkler68d1aa62014-08-21 14:29:11 +0300544 return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200545}
546
547/**
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200548 * mei_hbm_cl_connect_res - connect response from the ME
Tomas Winkler6bbda152012-12-25 19:06:12 +0200549 *
550 * @dev: the device structure
551 * @rs: connect response bus message
552 */
553static void mei_hbm_cl_connect_res(struct mei_device *dev,
554 struct hbm_client_connect_response *rs)
555{
556
557 struct mei_cl *cl;
Tomas Winkler64092852014-02-17 15:13:21 +0200558 struct mei_cl_cb *cb, *next;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200559
Alexander Usyskin285e2992014-02-17 15:13:20 +0200560 dev_dbg(&dev->pdev->dev, "hbm: connect response cl:host=%02d me=%02d status=%s\n",
561 rs->me_addr, rs->host_addr,
562 mei_cl_conn_status_str(rs->status));
Tomas Winkler6bbda152012-12-25 19:06:12 +0200563
Tomas Winkler64092852014-02-17 15:13:21 +0200564 cl = NULL;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200565
Tomas Winkler64092852014-02-17 15:13:21 +0200566 list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list.list, list) {
Tomas Winkler6bbda152012-12-25 19:06:12 +0200567
Tomas Winkler64092852014-02-17 15:13:21 +0200568 cl = cb->cl;
569 /* this should not happen */
570 if (WARN_ON(!cl)) {
571 list_del_init(&cb->list);
572 continue;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200573 }
Tomas Winkler64092852014-02-17 15:13:21 +0200574
575 if (cb->fop_type != MEI_FOP_CONNECT)
576 continue;
577
578 if (mei_hbm_cl_addr_equal(cl, rs)) {
579 list_del(&cb->list);
580 break;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200581 }
582 }
Tomas Winkler64092852014-02-17 15:13:21 +0200583
584 if (!cl)
585 return;
586
587 cl->timer_count = 0;
588 if (rs->status == MEI_CL_CONN_SUCCESS)
589 cl->state = MEI_FILE_CONNECTED;
590 else
591 cl->state = MEI_FILE_DISCONNECTED;
592 cl->status = mei_cl_conn_status_to_errno(rs->status);
Tomas Winkler6bbda152012-12-25 19:06:12 +0200593}
594
595
596/**
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200597 * mei_hbm_fw_disconnect_req - disconnect request initiated by ME firmware
598 * host sends disconnect response
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200599 *
600 * @dev: the device structure.
Tomas Winkler8120e722012-12-25 19:06:11 +0200601 * @disconnect_req: disconnect request bus message from the me
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200602 *
603 * returns -ENOMEM on allocation failure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200604 */
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200605static int mei_hbm_fw_disconnect_req(struct mei_device *dev,
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200606 struct hbm_client_connect_request *disconnect_req)
607{
Tomas Winkler31f88f52014-02-17 15:13:25 +0200608 struct mei_cl *cl;
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200609 struct mei_cl_cb *cb;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200610
Tomas Winkler31f88f52014-02-17 15:13:25 +0200611 list_for_each_entry(cl, &dev->file_list, link) {
Tomas Winklercd51ed62012-12-25 19:06:09 +0200612 if (mei_hbm_cl_addr_equal(cl, disconnect_req)) {
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200613 dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
614 disconnect_req->host_addr,
615 disconnect_req->me_addr);
Tomas Winklercd51ed62012-12-25 19:06:09 +0200616 cl->state = MEI_FILE_DISCONNECTED;
617 cl->timer_count = 0;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200618
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200619 cb = mei_io_cb_init(cl, NULL);
620 if (!cb)
621 return -ENOMEM;
622 cb->fop_type = MEI_FOP_DISCONNECT_RSP;
623 cl_dbg(dev, cl, "add disconnect response as first\n");
624 list_add(&cb->list, &dev->ctrl_wr_list.list);
625
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200626 break;
627 }
628 }
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200629 return 0;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200630}
631
632
633/**
Tomas Winkler2c9b48a2013-06-16 09:16:31 +0300634 * mei_hbm_version_is_supported - checks whether the driver can
635 * support the hbm version of the device
636 *
637 * @dev: the device structure
638 * returns true if driver can support hbm version of the device
639 */
640bool mei_hbm_version_is_supported(struct mei_device *dev)
641{
642 return (dev->version.major_version < HBM_MAJOR_VERSION) ||
643 (dev->version.major_version == HBM_MAJOR_VERSION &&
644 dev->version.minor_version <= HBM_MINOR_VERSION);
645}
646
647/**
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200648 * mei_hbm_dispatch - bottom half read routine after ISR to
649 * handle the read bus message cmd processing.
650 *
651 * @dev: the device structure
652 * @mei_hdr: header of bus message
Tomas Winkler544f9462014-01-08 20:19:21 +0200653 *
654 * returns 0 on success and < 0 on failure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200655 */
Tomas Winkler544f9462014-01-08 20:19:21 +0200656int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200657{
658 struct mei_bus_message *mei_msg;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200659 struct hbm_host_version_response *version_res;
660 struct hbm_client_connect_response *connect_res;
661 struct hbm_client_connect_response *disconnect_res;
662 struct hbm_client_connect_request *disconnect_req;
663 struct hbm_flow_control *flow_control;
664 struct hbm_props_response *props_res;
665 struct hbm_host_enum_response *enum_res;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200666
667 /* read the message to our buffer */
668 BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf));
669 mei_read_slots(dev, dev->rd_msg_buf, hdr->length);
670 mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
671
Tomas Winkler66ae4602014-01-08 20:19:22 +0200672 /* ignore spurious message and prevent reset nesting
673 * hbm is put to idle during system reset
674 */
675 if (dev->hbm_state == MEI_HBM_IDLE) {
676 dev_dbg(&dev->pdev->dev, "hbm: state is idle ignore spurious messages\n");
677 return 0;
678 }
679
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200680 switch (mei_msg->hbm_cmd) {
681 case HOST_START_RES_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200682 dev_dbg(&dev->pdev->dev, "hbm: start: response message received.\n");
683
684 dev->init_clients_timer = 0;
685
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200686 version_res = (struct hbm_host_version_response *)mei_msg;
Tomas Winkler2c9b48a2013-06-16 09:16:31 +0300687
688 dev_dbg(&dev->pdev->dev, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n",
689 HBM_MAJOR_VERSION, HBM_MINOR_VERSION,
690 version_res->me_max_version.major_version,
691 version_res->me_max_version.minor_version);
692
693 if (version_res->host_version_supported) {
694 dev->version.major_version = HBM_MAJOR_VERSION;
695 dev->version.minor_version = HBM_MINOR_VERSION;
696 } else {
697 dev->version.major_version =
698 version_res->me_max_version.major_version;
699 dev->version.minor_version =
700 version_res->me_max_version.minor_version;
701 }
702
703 if (!mei_hbm_version_is_supported(dev)) {
Tomas Winkler544f9462014-01-08 20:19:21 +0200704 dev_warn(&dev->pdev->dev, "hbm: start: version mismatch - stopping the driver.\n");
Tomas Winklere46f1872012-12-25 19:06:10 +0200705
Tomas Winkler544f9462014-01-08 20:19:21 +0200706 dev->hbm_state = MEI_HBM_STOPPED;
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200707 if (mei_hbm_stop_req(dev)) {
Tomas Winkler544f9462014-01-08 20:19:21 +0200708 dev_err(&dev->pdev->dev, "hbm: start: failed to send stop request\n");
709 return -EIO;
710 }
711 break;
Tomas Winklere46f1872012-12-25 19:06:10 +0200712 }
713
Tomas Winkler544f9462014-01-08 20:19:21 +0200714 if (dev->dev_state != MEI_DEV_INIT_CLIENTS ||
715 dev->hbm_state != MEI_HBM_START) {
716 dev_err(&dev->pdev->dev, "hbm: start: state mismatch, [%d, %d]\n",
717 dev->dev_state, dev->hbm_state);
718 return -EPROTO;
719 }
720
721 dev->hbm_state = MEI_HBM_STARTED;
722
723 if (mei_hbm_enum_clients_req(dev)) {
724 dev_err(&dev->pdev->dev, "hbm: start: failed to send enumeration request\n");
725 return -EIO;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200726 }
727
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300728 wake_up_interruptible(&dev->wait_recvd_msg);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200729 break;
730
731 case CLIENT_CONNECT_RES_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200732 dev_dbg(&dev->pdev->dev, "hbm: client connect response: message received.\n");
733
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200734 connect_res = (struct hbm_client_connect_response *) mei_msg;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200735 mei_hbm_cl_connect_res(dev, connect_res);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200736 wake_up(&dev->wait_recvd_msg);
737 break;
738
739 case CLIENT_DISCONNECT_RES_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200740 dev_dbg(&dev->pdev->dev, "hbm: client disconnect response: message received.\n");
741
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200742 disconnect_res = (struct hbm_client_connect_response *) mei_msg;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200743 mei_hbm_cl_disconnect_res(dev, disconnect_res);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200744 wake_up(&dev->wait_recvd_msg);
745 break;
746
747 case MEI_FLOW_CONTROL_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200748 dev_dbg(&dev->pdev->dev, "hbm: client flow control response: message received.\n");
749
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200750 flow_control = (struct hbm_flow_control *) mei_msg;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200751 mei_hbm_cl_flow_control_res(dev, flow_control);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200752 break;
753
Tomas Winkler4fcbc992014-03-18 22:51:55 +0200754 case MEI_PG_ISOLATION_ENTRY_RES_CMD:
755 dev_dbg(&dev->pdev->dev, "power gate isolation entry response received\n");
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200756 dev->pg_event = MEI_PG_EVENT_RECEIVED;
Tomas Winkler4fcbc992014-03-18 22:51:55 +0200757 if (waitqueue_active(&dev->wait_pg))
758 wake_up(&dev->wait_pg);
759 break;
760
761 case MEI_PG_ISOLATION_EXIT_REQ_CMD:
762 dev_dbg(&dev->pdev->dev, "power gate isolation exit request received\n");
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200763 dev->pg_event = MEI_PG_EVENT_RECEIVED;
Tomas Winkler4fcbc992014-03-18 22:51:55 +0200764 if (waitqueue_active(&dev->wait_pg))
765 wake_up(&dev->wait_pg);
Tomas Winkler180ea052014-03-18 22:52:02 +0200766 else
767 /*
768 * If the driver is not waiting on this then
769 * this is HW initiated exit from PG.
770 * Start runtime pm resume sequence to exit from PG.
771 */
772 pm_request_resume(&dev->pdev->dev);
Tomas Winkler4fcbc992014-03-18 22:51:55 +0200773 break;
774
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200775 case HOST_CLIENT_PROPERTIES_RES_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200776 dev_dbg(&dev->pdev->dev, "hbm: properties response: message received.\n");
777
778 dev->init_clients_timer = 0;
779
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200780 if (dev->dev_state != MEI_DEV_INIT_CLIENTS ||
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300781 dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) {
Tomas Winkler544f9462014-01-08 20:19:21 +0200782 dev_err(&dev->pdev->dev, "hbm: properties response: state mismatch, [%d, %d]\n",
783 dev->dev_state, dev->hbm_state);
784 return -EPROTO;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200785 }
786
Tomas Winkler5ca2d382014-08-21 14:29:13 +0300787 props_res = (struct hbm_props_response *)mei_msg;
788
789 if (props_res->status) {
Tomas Winkler89778d62014-08-21 14:29:16 +0300790 dev_err(&dev->pdev->dev, "hbm: properties response: wrong status = %d %s\n",
791 props_res->status,
792 mei_hbm_status_str(props_res->status));
Tomas Winkler5ca2d382014-08-21 14:29:13 +0300793 return -EPROTO;
794 }
795
796 mei_hbm_me_cl_add(dev, props_res);
797
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200798 dev->me_client_index++;
799 dev->me_client_presentation_num++;
800
Tomas Winkler8120e722012-12-25 19:06:11 +0200801 /* request property for the next client */
Tomas Winkler544f9462014-01-08 20:19:21 +0200802 if (mei_hbm_prop_req(dev))
803 return -EIO;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200804
805 break;
806
807 case HOST_ENUM_RES_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200808 dev_dbg(&dev->pdev->dev, "hbm: enumeration response: message received\n");
809
810 dev->init_clients_timer = 0;
811
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200812 enum_res = (struct hbm_host_enum_response *) mei_msg;
Tomas Winkler23f5a322013-09-02 03:11:01 +0300813 BUILD_BUG_ON(sizeof(dev->me_clients_map)
814 < sizeof(enum_res->valid_addresses));
815 memcpy(dev->me_clients_map, enum_res->valid_addresses,
Tomas Winkler5ca2d382014-08-21 14:29:13 +0300816 sizeof(enum_res->valid_addresses));
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200817
Tomas Winkler544f9462014-01-08 20:19:21 +0200818 if (dev->dev_state != MEI_DEV_INIT_CLIENTS ||
819 dev->hbm_state != MEI_HBM_ENUM_CLIENTS) {
820 dev_err(&dev->pdev->dev, "hbm: enumeration response: state mismatch, [%d, %d]\n",
821 dev->dev_state, dev->hbm_state);
822 return -EPROTO;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200823 }
Tomas Winkler544f9462014-01-08 20:19:21 +0200824
Tomas Winkler544f9462014-01-08 20:19:21 +0200825 dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES;
826
827 /* first property request */
828 if (mei_hbm_prop_req(dev))
829 return -EIO;
830
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200831 break;
832
833 case HOST_STOP_RES_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200834 dev_dbg(&dev->pdev->dev, "hbm: stop response: message received\n");
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300835
Tomas Winkler544f9462014-01-08 20:19:21 +0200836 dev->init_clients_timer = 0;
837
838 if (dev->hbm_state != MEI_HBM_STOPPED) {
839 dev_err(&dev->pdev->dev, "hbm: stop response: state mismatch, [%d, %d]\n",
840 dev->dev_state, dev->hbm_state);
841 return -EPROTO;
842 }
843
Tomas Winkler33ec0822014-01-12 00:36:09 +0200844 dev->dev_state = MEI_DEV_POWER_DOWN;
Tomas Winkler544f9462014-01-08 20:19:21 +0200845 dev_info(&dev->pdev->dev, "hbm: stop response: resetting.\n");
846 /* force the reset */
847 return -EPROTO;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200848 break;
849
850 case CLIENT_DISCONNECT_REQ_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200851 dev_dbg(&dev->pdev->dev, "hbm: disconnect request: message received\n");
852
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200853 disconnect_req = (struct hbm_client_connect_request *)mei_msg;
Tomas Winkler8120e722012-12-25 19:06:11 +0200854 mei_hbm_fw_disconnect_req(dev, disconnect_req);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200855 break;
856
857 case ME_STOP_REQ_CMD:
Tomas Winkler544f9462014-01-08 20:19:21 +0200858 dev_dbg(&dev->pdev->dev, "hbm: stop request: message received\n");
Tomas Winkler544f9462014-01-08 20:19:21 +0200859 dev->hbm_state = MEI_HBM_STOPPED;
Tomas Winkler6bb948c2014-02-12 21:41:52 +0200860 if (mei_hbm_stop_req(dev)) {
861 dev_err(&dev->pdev->dev, "hbm: start: failed to send stop request\n");
862 return -EIO;
863 }
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200864 break;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200865 default:
866 BUG();
867 break;
868
869 }
Tomas Winkler544f9462014-01-08 20:19:21 +0200870 return 0;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200871}
872