blob: 6127ab64bb399323e57e418e9742c2f5b8a9d86d [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
17#include <linux/pci.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
20#include <linux/mei.h>
21
22#include "mei_dev.h"
Tomas Winkler0edb23f2013-01-08 23:07:12 +020023#include "hbm.h"
Tomas Winkler9dc64d62013-01-08 23:07:17 +020024#include "hw-me.h"
Tomas Winklerbb1b0132012-12-25 19:06:07 +020025
26/**
Tomas Winklera40b2602013-01-08 23:07:19 +020027 * mei_hbm_me_cl_allocate - allocates storage for me clients
28 *
29 * @dev: the device structure
30 *
31 * returns none.
32 */
33static void mei_hbm_me_cl_allocate(struct mei_device *dev)
34{
35 struct mei_me_client *clients;
36 int b;
37
38 /* count how many ME clients we have */
39 for_each_set_bit(b, dev->me_clients_map, MEI_CLIENTS_MAX)
40 dev->me_clients_num++;
41
42 if (dev->me_clients_num <= 0)
43 return;
44
45 kfree(dev->me_clients);
46 dev->me_clients = NULL;
47
48 dev_dbg(&dev->pdev->dev, "memory allocation for ME clients size=%zd.\n",
49 dev->me_clients_num * sizeof(struct mei_me_client));
50 /* allocate storage for ME clients representation */
51 clients = kcalloc(dev->me_clients_num,
52 sizeof(struct mei_me_client), GFP_KERNEL);
53 if (!clients) {
54 dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n");
Bill Nottingham0cfee512013-04-19 22:01:36 +030055 dev->dev_state = MEI_DEV_RESETTING;
Tomas Winklera40b2602013-01-08 23:07:19 +020056 mei_reset(dev, 1);
57 return;
58 }
59 dev->me_clients = clients;
60 return;
61}
62
63/**
Tomas Winklercd51ed62012-12-25 19:06:09 +020064 * mei_hbm_cl_hdr - construct client hbm header
Masanari Iida393b1482013-04-05 01:05:05 +090065 *
Tomas Winklercd51ed62012-12-25 19:06:09 +020066 * @cl: - client
67 * @hbm_cmd: host bus message command
68 * @buf: buffer for cl header
69 * @len: buffer length
70 */
71static inline
72void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len)
73{
74 struct mei_hbm_cl_cmd *cmd = buf;
75
76 memset(cmd, 0, len);
77
78 cmd->hbm_cmd = hbm_cmd;
79 cmd->host_addr = cl->host_client_id;
80 cmd->me_addr = cl->me_client_id;
81}
82
83/**
84 * same_disconn_addr - tells if they have the same address
85 *
86 * @file: private data of the file object.
87 * @disconn: disconnection request.
88 *
89 * returns true if addres are same
90 */
91static inline
92bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
93{
94 struct mei_hbm_cl_cmd *cmd = buf;
95 return cl->host_client_id == cmd->host_addr &&
96 cl->me_client_id == cmd->me_addr;
97}
98
99
100/**
Tomas Winkler6bbda152012-12-25 19:06:12 +0200101 * is_treat_specially_client - checks if the message belongs
102 * to the file private data.
103 *
104 * @cl: private data of the file object
105 * @rs: connect response bus message
106 *
107 */
108static bool is_treat_specially_client(struct mei_cl *cl,
109 struct hbm_client_connect_response *rs)
110{
111 if (mei_hbm_cl_addr_equal(cl, rs)) {
112 if (!rs->status) {
113 cl->state = MEI_FILE_CONNECTED;
114 cl->status = 0;
115
116 } else {
117 cl->state = MEI_FILE_DISCONNECTED;
118 cl->status = -ENODEV;
119 }
120 cl->timer_count = 0;
121
122 return true;
123 }
124 return false;
125}
126
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300127int mei_hbm_start_wait(struct mei_device *dev)
128{
129 int ret;
130 if (dev->hbm_state > MEI_HBM_START)
131 return 0;
132
133 mutex_unlock(&dev->device_lock);
134 ret = wait_event_interruptible_timeout(dev->wait_recvd_msg,
135 dev->hbm_state == MEI_HBM_IDLE ||
136 dev->hbm_state > MEI_HBM_START,
137 mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT));
138 mutex_lock(&dev->device_lock);
139
140 if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) {
141 dev->hbm_state = MEI_HBM_IDLE;
Masanari Iida8b513d02013-05-21 23:13:12 +0900142 dev_err(&dev->pdev->dev, "waiting for mei start failed\n");
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300143 return -ETIMEDOUT;
144 }
145 return 0;
146}
147
Tomas Winkler6bbda152012-12-25 19:06:12 +0200148/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200149 * mei_hbm_start_req - sends start request message.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200150 *
151 * @dev: the device structure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200152 */
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300153int mei_hbm_start_req(struct mei_device *dev)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200154{
Tomas Winklere46f1872012-12-25 19:06:10 +0200155 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200156 struct hbm_host_version_request *start_req;
157 const size_t len = sizeof(struct hbm_host_version_request);
158
Tomas Winklere46f1872012-12-25 19:06:10 +0200159 mei_hbm_hdr(mei_hdr, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200160
161 /* host start message */
Tomas Winklere46f1872012-12-25 19:06:10 +0200162 start_req = (struct hbm_host_version_request *)dev->wr_msg.data;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200163 memset(start_req, 0, len);
164 start_req->hbm_cmd = HOST_START_REQ_CMD;
165 start_req->host_version.major_version = HBM_MAJOR_VERSION;
166 start_req->host_version.minor_version = HBM_MINOR_VERSION;
167
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300168 dev->hbm_state = MEI_HBM_IDLE;
Tomas Winklere46f1872012-12-25 19:06:10 +0200169 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
Tomas Winkler9310f612013-07-17 15:13:14 +0300170 dev_err(&dev->pdev->dev, "version message write failed\n");
Bill Nottingham0cfee512013-04-19 22:01:36 +0300171 dev->dev_state = MEI_DEV_RESETTING;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200172 mei_reset(dev, 1);
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300173 return -ENODEV;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200174 }
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300175 dev->hbm_state = MEI_HBM_START;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200176 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300177 return 0;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200178}
179
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300180/*
Tomas Winkler8120e722012-12-25 19:06:11 +0200181 * mei_hbm_enum_clients_req - sends enumeration client request message.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200182 *
183 * @dev: the device structure
184 *
185 * returns none.
186 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200187static void mei_hbm_enum_clients_req(struct mei_device *dev)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200188{
Tomas Winklere46f1872012-12-25 19:06:10 +0200189 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200190 struct hbm_host_enum_request *enum_req;
191 const size_t len = sizeof(struct hbm_host_enum_request);
192 /* enumerate clients */
Tomas Winklere46f1872012-12-25 19:06:10 +0200193 mei_hbm_hdr(mei_hdr, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200194
Tomas Winklere46f1872012-12-25 19:06:10 +0200195 enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data;
196 memset(enum_req, 0, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200197 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
198
Tomas Winklere46f1872012-12-25 19:06:10 +0200199 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
Bill Nottingham0cfee512013-04-19 22:01:36 +0300200 dev->dev_state = MEI_DEV_RESETTING;
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300201 dev_err(&dev->pdev->dev, "enumeration request write failed.\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200202 mei_reset(dev, 1);
203 }
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300204 dev->hbm_state = MEI_HBM_ENUM_CLIENTS;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200205 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
206 return;
207}
208
Tomas Winkler8120e722012-12-25 19:06:11 +0200209/**
Masanari Iida393b1482013-04-05 01:05:05 +0900210 * mei_hbm_prop_req - request property for a single client
Tomas Winkler8120e722012-12-25 19:06:11 +0200211 *
212 * @dev: the device structure
213 *
214 * returns none.
215 */
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200216
Tomas Winkler8120e722012-12-25 19:06:11 +0200217static int mei_hbm_prop_req(struct mei_device *dev)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200218{
219
Tomas Winklere46f1872012-12-25 19:06:10 +0200220 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200221 struct hbm_props_request *prop_req;
222 const size_t len = sizeof(struct hbm_props_request);
223 unsigned long next_client_index;
224 u8 client_num;
225
226
227 client_num = dev->me_client_presentation_num;
228
229 next_client_index = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX,
230 dev->me_client_index);
231
232 /* We got all client properties */
233 if (next_client_index == MEI_CLIENTS_MAX) {
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300234 dev->hbm_state = MEI_HBM_STARTED;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200235 schedule_work(&dev->init_work);
236
237 return 0;
238 }
239
240 dev->me_clients[client_num].client_id = next_client_index;
241 dev->me_clients[client_num].mei_flow_ctrl_creds = 0;
242
Tomas Winklere46f1872012-12-25 19:06:10 +0200243 mei_hbm_hdr(mei_hdr, len);
244 prop_req = (struct hbm_props_request *)dev->wr_msg.data;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200245
246 memset(prop_req, 0, sizeof(struct hbm_props_request));
247
248
249 prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
250 prop_req->address = next_client_index;
251
Tomas Winklere46f1872012-12-25 19:06:10 +0200252 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
Bill Nottingham0cfee512013-04-19 22:01:36 +0300253 dev->dev_state = MEI_DEV_RESETTING;
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300254 dev_err(&dev->pdev->dev, "properties request write failed\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200255 mei_reset(dev, 1);
256
257 return -EIO;
258 }
259
260 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
261 dev->me_client_index = next_client_index;
262
263 return 0;
264}
265
266/**
Tomas Winklere46f1872012-12-25 19:06:10 +0200267 * mei_hbm_stop_req_prepare - perpare stop request message
268 *
269 * @dev - mei device
270 * @mei_hdr - mei message header
271 * @data - hbm message body buffer
272 */
273static void mei_hbm_stop_req_prepare(struct mei_device *dev,
274 struct mei_msg_hdr *mei_hdr, unsigned char *data)
275{
276 struct hbm_host_stop_request *req =
277 (struct hbm_host_stop_request *)data;
278 const size_t len = sizeof(struct hbm_host_stop_request);
279
280 mei_hbm_hdr(mei_hdr, len);
281
282 memset(req, 0, len);
283 req->hbm_cmd = HOST_STOP_REQ_CMD;
284 req->reason = DRIVER_STOP_REQUEST;
285}
286
287/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200288 * mei_hbm_cl_flow_control_req - sends flow control requst.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200289 *
290 * @dev: the device structure
Tomas Winkler8120e722012-12-25 19:06:11 +0200291 * @cl: client info
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200292 *
293 * This function returns -EIO on write failure
294 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200295int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200296{
Tomas Winklere46f1872012-12-25 19:06:10 +0200297 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200298 const size_t len = sizeof(struct hbm_flow_control);
299
Tomas Winklere46f1872012-12-25 19:06:10 +0200300 mei_hbm_hdr(mei_hdr, len);
301 mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, dev->wr_msg.data, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200302
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200303 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
304 cl->host_client_id, cl->me_client_id);
305
Tomas Winklere46f1872012-12-25 19:06:10 +0200306 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200307}
308
309/**
Masanari Iida393b1482013-04-05 01:05:05 +0900310 * mei_hbm_add_single_flow_creds - adds single buffer credentials.
Tomas Winkler6bbda152012-12-25 19:06:12 +0200311 *
Masanari Iida393b1482013-04-05 01:05:05 +0900312 * @dev: the device structure
Tomas Winkler6bbda152012-12-25 19:06:12 +0200313 * @flow: flow control.
314 */
315static void mei_hbm_add_single_flow_creds(struct mei_device *dev,
316 struct hbm_flow_control *flow)
317{
318 struct mei_me_client *client;
319 int i;
320
321 for (i = 0; i < dev->me_clients_num; i++) {
322 client = &dev->me_clients[i];
323 if (client && flow->me_addr == client->client_id) {
324 if (client->props.single_recv_buf) {
325 client->mei_flow_ctrl_creds++;
326 dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
327 flow->me_addr);
328 dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
329 client->mei_flow_ctrl_creds);
330 } else {
331 BUG(); /* error in flow control */
332 }
333 }
334 }
335}
336
337/**
338 * mei_hbm_cl_flow_control_res - flow control response from me
339 *
340 * @dev: the device structure
341 * @flow_control: flow control response bus message
342 */
343static void mei_hbm_cl_flow_control_res(struct mei_device *dev,
344 struct hbm_flow_control *flow_control)
345{
346 struct mei_cl *cl = NULL;
347 struct mei_cl *next = NULL;
348
349 if (!flow_control->host_addr) {
350 /* single receive buffer */
351 mei_hbm_add_single_flow_creds(dev, flow_control);
352 return;
353 }
354
355 /* normal connection */
356 list_for_each_entry_safe(cl, next, &dev->file_list, link) {
357 if (mei_hbm_cl_addr_equal(cl, flow_control)) {
358 cl->mei_flow_ctrl_creds++;
359 dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d.\n",
360 flow_control->host_addr, flow_control->me_addr);
361 dev_dbg(&dev->pdev->dev, "flow control credentials = %d.\n",
362 cl->mei_flow_ctrl_creds);
363 break;
364 }
365 }
366}
367
368
369/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200370 * mei_hbm_cl_disconnect_req - sends disconnect message to fw.
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200371 *
372 * @dev: the device structure
Tomas Winkler8120e722012-12-25 19:06:11 +0200373 * @cl: a client to disconnect from
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200374 *
375 * This function returns -EIO on write failure
376 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200377int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200378{
Tomas Winklere46f1872012-12-25 19:06:10 +0200379 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200380 const size_t len = sizeof(struct hbm_client_connect_request);
381
Tomas Winklere46f1872012-12-25 19:06:10 +0200382 mei_hbm_hdr(mei_hdr, len);
383 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, dev->wr_msg.data, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200384
Tomas Winklere46f1872012-12-25 19:06:10 +0200385 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200386}
387
388/**
Tomas Winkler6bbda152012-12-25 19:06:12 +0200389 * mei_hbm_cl_disconnect_res - disconnect response from ME
390 *
391 * @dev: the device structure
392 * @rs: disconnect response bus message
393 */
394static void mei_hbm_cl_disconnect_res(struct mei_device *dev,
395 struct hbm_client_connect_response *rs)
396{
397 struct mei_cl *cl;
398 struct mei_cl_cb *pos = NULL, *next = NULL;
399
400 dev_dbg(&dev->pdev->dev,
401 "disconnect_response:\n"
402 "ME Client = %d\n"
403 "Host Client = %d\n"
404 "Status = %d\n",
405 rs->me_addr,
406 rs->host_addr,
407 rs->status);
408
409 list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) {
410 cl = pos->cl;
411
412 if (!cl) {
413 list_del(&pos->list);
414 return;
415 }
416
417 dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in ctrl_rd_list.\n");
418 if (mei_hbm_cl_addr_equal(cl, rs)) {
419 list_del(&pos->list);
420 if (!rs->status)
421 cl->state = MEI_FILE_DISCONNECTED;
422
423 cl->status = 0;
424 cl->timer_count = 0;
425 break;
426 }
427 }
428}
429
430/**
Tomas Winkler8120e722012-12-25 19:06:11 +0200431 * mei_hbm_cl_connect_req - send connection request to specific me client
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200432 *
433 * @dev: the device structure
Tomas Winkler8120e722012-12-25 19:06:11 +0200434 * @cl: a client to connect to
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200435 *
Tomas Winkler8120e722012-12-25 19:06:11 +0200436 * returns -EIO on write failure
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200437 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200438int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200439{
Tomas Winklere46f1872012-12-25 19:06:10 +0200440 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200441 const size_t len = sizeof(struct hbm_client_connect_request);
442
Tomas Winklere46f1872012-12-25 19:06:10 +0200443 mei_hbm_hdr(mei_hdr, len);
444 mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, dev->wr_msg.data, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200445
Tomas Winklere46f1872012-12-25 19:06:10 +0200446 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200447}
448
449/**
Tomas Winkler6bbda152012-12-25 19:06:12 +0200450 * mei_hbm_cl_connect_res - connect resposne from the ME
451 *
452 * @dev: the device structure
453 * @rs: connect response bus message
454 */
455static void mei_hbm_cl_connect_res(struct mei_device *dev,
456 struct hbm_client_connect_response *rs)
457{
458
459 struct mei_cl *cl;
460 struct mei_cl_cb *pos = NULL, *next = NULL;
461
462 dev_dbg(&dev->pdev->dev,
463 "connect_response:\n"
464 "ME Client = %d\n"
465 "Host Client = %d\n"
466 "Status = %d\n",
467 rs->me_addr,
468 rs->host_addr,
469 rs->status);
470
471 /* if WD or iamthif client treat specially */
472
473 if (is_treat_specially_client(&dev->wd_cl, rs)) {
474 dev_dbg(&dev->pdev->dev, "successfully connected to WD client.\n");
475 mei_watchdog_register(dev);
476
477 return;
478 }
479
480 if (is_treat_specially_client(&dev->iamthif_cl, rs)) {
481 dev->iamthif_state = MEI_IAMTHIF_IDLE;
482 return;
483 }
484 list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) {
485
486 cl = pos->cl;
487 if (!cl) {
488 list_del(&pos->list);
489 return;
490 }
491 if (pos->fop_type == MEI_FOP_IOCTL) {
492 if (is_treat_specially_client(cl, rs)) {
493 list_del(&pos->list);
494 cl->status = 0;
495 cl->timer_count = 0;
496 break;
497 }
498 }
499 }
500}
501
502
503/**
Masanari Iida393b1482013-04-05 01:05:05 +0900504 * mei_hbm_fw_disconnect_req - disconnect request initiated by me
Tomas Winkler8120e722012-12-25 19:06:11 +0200505 * host sends disoconnect response
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200506 *
507 * @dev: the device structure.
Tomas Winkler8120e722012-12-25 19:06:11 +0200508 * @disconnect_req: disconnect request bus message from the me
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200509 */
Tomas Winkler8120e722012-12-25 19:06:11 +0200510static void mei_hbm_fw_disconnect_req(struct mei_device *dev,
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200511 struct hbm_client_connect_request *disconnect_req)
512{
Tomas Winklercd51ed62012-12-25 19:06:09 +0200513 struct mei_cl *cl, *next;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200514 const size_t len = sizeof(struct hbm_client_connect_response);
515
Tomas Winklercd51ed62012-12-25 19:06:09 +0200516 list_for_each_entry_safe(cl, next, &dev->file_list, link) {
517 if (mei_hbm_cl_addr_equal(cl, disconnect_req)) {
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200518 dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
519 disconnect_req->host_addr,
520 disconnect_req->me_addr);
Tomas Winklercd51ed62012-12-25 19:06:09 +0200521 cl->state = MEI_FILE_DISCONNECTED;
522 cl->timer_count = 0;
523 if (cl == &dev->wd_cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200524 dev->wd_pending = false;
Tomas Winklercd51ed62012-12-25 19:06:09 +0200525 else if (cl == &dev->iamthif_cl)
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200526 dev->iamthif_timer = 0;
527
528 /* prepare disconnect response */
Tomas Winklere46f1872012-12-25 19:06:10 +0200529 mei_hbm_hdr(&dev->wr_ext_msg.hdr, len);
Tomas Winklercd51ed62012-12-25 19:06:09 +0200530 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
Tomas Winklere46f1872012-12-25 19:06:10 +0200531 dev->wr_ext_msg.data, len);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200532 break;
533 }
534 }
535}
536
537
538/**
Tomas Winkler2c9b48a2013-06-16 09:16:31 +0300539 * mei_hbm_version_is_supported - checks whether the driver can
540 * support the hbm version of the device
541 *
542 * @dev: the device structure
543 * returns true if driver can support hbm version of the device
544 */
545bool mei_hbm_version_is_supported(struct mei_device *dev)
546{
547 return (dev->version.major_version < HBM_MAJOR_VERSION) ||
548 (dev->version.major_version == HBM_MAJOR_VERSION &&
549 dev->version.minor_version <= HBM_MINOR_VERSION);
550}
551
552/**
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200553 * mei_hbm_dispatch - bottom half read routine after ISR to
554 * handle the read bus message cmd processing.
555 *
556 * @dev: the device structure
557 * @mei_hdr: header of bus message
558 */
559void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
560{
561 struct mei_bus_message *mei_msg;
562 struct mei_me_client *me_client;
563 struct hbm_host_version_response *version_res;
564 struct hbm_client_connect_response *connect_res;
565 struct hbm_client_connect_response *disconnect_res;
566 struct hbm_client_connect_request *disconnect_req;
567 struct hbm_flow_control *flow_control;
568 struct hbm_props_response *props_res;
569 struct hbm_host_enum_response *enum_res;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200570
571 /* read the message to our buffer */
572 BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf));
573 mei_read_slots(dev, dev->rd_msg_buf, hdr->length);
574 mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
575
576 switch (mei_msg->hbm_cmd) {
577 case HOST_START_RES_CMD:
578 version_res = (struct hbm_host_version_response *)mei_msg;
Tomas Winkler2c9b48a2013-06-16 09:16:31 +0300579
580 dev_dbg(&dev->pdev->dev, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n",
581 HBM_MAJOR_VERSION, HBM_MINOR_VERSION,
582 version_res->me_max_version.major_version,
583 version_res->me_max_version.minor_version);
584
585 if (version_res->host_version_supported) {
586 dev->version.major_version = HBM_MAJOR_VERSION;
587 dev->version.minor_version = HBM_MINOR_VERSION;
588 } else {
589 dev->version.major_version =
590 version_res->me_max_version.major_version;
591 dev->version.minor_version =
592 version_res->me_max_version.minor_version;
593 }
594
595 if (!mei_hbm_version_is_supported(dev)) {
596 dev_warn(&dev->pdev->dev, "hbm version mismatch: stopping the driver.\n");
Tomas Winklere46f1872012-12-25 19:06:10 +0200597
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300598 dev->hbm_state = MEI_HBM_STOP;
Tomas Winklere46f1872012-12-25 19:06:10 +0200599 mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr,
600 dev->wr_msg.data);
601 mei_write_message(dev, &dev->wr_msg.hdr,
602 dev->wr_msg.data);
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300603
Tomas Winklere46f1872012-12-25 19:06:10 +0200604 return;
605 }
606
Tomas Winklere46f1872012-12-25 19:06:10 +0200607 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300608 dev->hbm_state == MEI_HBM_START) {
Tomas Winklere46f1872012-12-25 19:06:10 +0200609 dev->init_clients_timer = 0;
Tomas Winkler8120e722012-12-25 19:06:11 +0200610 mei_hbm_enum_clients_req(dev);
Tomas Winklere46f1872012-12-25 19:06:10 +0200611 } else {
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300612 dev_err(&dev->pdev->dev, "reset: wrong host start response\n");
Tomas Winklere46f1872012-12-25 19:06:10 +0200613 mei_reset(dev, 1);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200614 return;
615 }
616
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300617 wake_up_interruptible(&dev->wait_recvd_msg);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200618 dev_dbg(&dev->pdev->dev, "host start response message received.\n");
619 break;
620
621 case CLIENT_CONNECT_RES_CMD:
622 connect_res = (struct hbm_client_connect_response *) mei_msg;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200623 mei_hbm_cl_connect_res(dev, connect_res);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200624 dev_dbg(&dev->pdev->dev, "client connect response message received.\n");
625 wake_up(&dev->wait_recvd_msg);
626 break;
627
628 case CLIENT_DISCONNECT_RES_CMD:
629 disconnect_res = (struct hbm_client_connect_response *) mei_msg;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200630 mei_hbm_cl_disconnect_res(dev, disconnect_res);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200631 dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n");
632 wake_up(&dev->wait_recvd_msg);
633 break;
634
635 case MEI_FLOW_CONTROL_CMD:
636 flow_control = (struct hbm_flow_control *) mei_msg;
Tomas Winkler6bbda152012-12-25 19:06:12 +0200637 mei_hbm_cl_flow_control_res(dev, flow_control);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200638 dev_dbg(&dev->pdev->dev, "client flow control response message received.\n");
639 break;
640
641 case HOST_CLIENT_PROPERTIES_RES_CMD:
642 props_res = (struct hbm_props_response *)mei_msg;
643 me_client = &dev->me_clients[dev->me_client_presentation_num];
644
645 if (props_res->status || !dev->me_clients) {
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300646 dev_err(&dev->pdev->dev, "reset: properties response hbm wrong status.\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200647 mei_reset(dev, 1);
648 return;
649 }
650
651 if (me_client->client_id != props_res->address) {
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300652 dev_err(&dev->pdev->dev, "reset: host properties response address mismatch\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200653 mei_reset(dev, 1);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200654 return;
655 }
656
657 if (dev->dev_state != MEI_DEV_INIT_CLIENTS ||
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300658 dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) {
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300659 dev_err(&dev->pdev->dev, "reset: unexpected properties response\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200660 mei_reset(dev, 1);
661
662 return;
663 }
664
665 me_client->props = props_res->client_properties;
666 dev->me_client_index++;
667 dev->me_client_presentation_num++;
668
Tomas Winkler8120e722012-12-25 19:06:11 +0200669 /* request property for the next client */
670 mei_hbm_prop_req(dev);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200671
672 break;
673
674 case HOST_ENUM_RES_CMD:
675 enum_res = (struct hbm_host_enum_response *) mei_msg;
676 memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
677 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300678 dev->hbm_state == MEI_HBM_ENUM_CLIENTS) {
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200679 dev->init_clients_timer = 0;
680 dev->me_client_presentation_num = 0;
681 dev->me_client_index = 0;
Tomas Winklera40b2602013-01-08 23:07:19 +0200682 mei_hbm_me_cl_allocate(dev);
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300683 dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200684
Tomas Winkler8120e722012-12-25 19:06:11 +0200685 /* first property reqeust */
686 mei_hbm_prop_req(dev);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200687 } else {
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300688 dev_err(&dev->pdev->dev, "reset: unexpected enumeration response hbm.\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200689 mei_reset(dev, 1);
690 return;
691 }
692 break;
693
694 case HOST_STOP_RES_CMD:
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300695
696 if (dev->hbm_state != MEI_HBM_STOP)
697 dev_err(&dev->pdev->dev, "unexpected stop response hbm.\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200698 dev->dev_state = MEI_DEV_DISABLED;
Tomas Winklerd6c36a42013-04-08 21:56:38 +0300699 dev_info(&dev->pdev->dev, "reset: FW stop response.\n");
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200700 mei_reset(dev, 1);
701 break;
702
703 case CLIENT_DISCONNECT_REQ_CMD:
704 /* search for client */
705 disconnect_req = (struct hbm_client_connect_request *)mei_msg;
Tomas Winkler8120e722012-12-25 19:06:11 +0200706 mei_hbm_fw_disconnect_req(dev, disconnect_req);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200707 break;
708
709 case ME_STOP_REQ_CMD:
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200710
Tomas Winkler9b0d5ef2013-04-18 23:03:48 +0300711 dev->hbm_state = MEI_HBM_STOP;
Tomas Winklere46f1872012-12-25 19:06:10 +0200712 mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr,
713 dev->wr_ext_msg.data);
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200714 break;
Tomas Winklerbb1b0132012-12-25 19:06:07 +0200715 default:
716 BUG();
717 break;
718
719 }
720}
721