interrupt.c 14.7 KB
Newer Older
O
Oren Weil 已提交
1 2 3
/*
 *
 * Intel Management Engine Interface (Intel MEI) Linux driver
4
 * Copyright (c) 2003-2012, Intel Corporation.
O
Oren Weil 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 */


18
#include <linux/export.h>
O
Oren Weil 已提交
19 20 21 22 23 24
#include <linux/pci.h>
#include <linux/kthread.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/jiffies.h>

25
#include <linux/mei.h>
26 27

#include "mei_dev.h"
28
#include "hbm.h"
T
Tomas Winkler 已提交
29
#include "client.h"
O
Oren Weil 已提交
30 31


32
/**
33
 * mei_irq_compl_handler - dispatch complete handlers
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 *	for the completed callbacks
 *
 * @dev - mei device
 * @compl_list - list of completed cbs
 */
void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list)
{
	struct mei_cl_cb *cb, *next;
	struct mei_cl *cl;

	list_for_each_entry_safe(cb, next, &compl_list->list, list) {
		cl = cb->cl;
		list_del(&cb->list);
		if (!cl)
			continue;

50
		dev_dbg(dev->dev, "completing call back.\n");
51 52 53
		if (cl == &dev->iamthif_cl)
			mei_amthif_complete(dev, cb);
		else
54
			mei_cl_complete(cl, cb);
55 56
	}
}
57
EXPORT_SYMBOL_GPL(mei_irq_compl_handler);
58

O
Oren Weil 已提交
59
/**
60
 * mei_cl_hbm_equal - check if hbm is addressed to the client
O
Oren Weil 已提交
61
 *
62
 * @cl: host client
O
Oren Weil 已提交
63 64
 * @mei_hdr: header of mei client message
 *
65
 * returns true if matches, false otherwise
O
Oren Weil 已提交
66
 */
67 68
static inline int mei_cl_hbm_equal(struct mei_cl *cl,
			struct mei_msg_hdr *mei_hdr)
O
Oren Weil 已提交
69
{
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
	return cl->host_client_id == mei_hdr->host_addr &&
		cl->me_client_id == mei_hdr->me_addr;
}
/**
 * mei_cl_is_reading - checks if the client
		is the one to read this message
 *
 * @cl: mei client
 * @mei_hdr: header of mei message
 *
 * returns true on match and false otherwise
 */
static bool mei_cl_is_reading(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr)
{
	return mei_cl_hbm_equal(cl, mei_hdr) &&
O
Oren Weil 已提交
85
		cl->state == MEI_FILE_CONNECTED &&
86
		cl->reading_state != MEI_READ_COMPLETE;
O
Oren Weil 已提交
87 88 89
}

/**
90
 * mei_irq_read_client_message - process client message
O
Oren Weil 已提交
91 92 93
 *
 * @dev: the device structure
 * @mei_hdr: header of mei client message
94
 * @complete_list: An instance of our list structure
O
Oren Weil 已提交
95 96 97
 *
 * returns 0 on success, <0 on failure.
 */
98 99 100
static int mei_cl_irq_read_msg(struct mei_device *dev,
			       struct mei_msg_hdr *mei_hdr,
			       struct mei_cl_cb *complete_list)
O
Oren Weil 已提交
101 102
{
	struct mei_cl *cl;
103
	struct mei_cl_cb *cb, *next;
104
	unsigned char *buffer = NULL;
O
Oren Weil 已提交
105

106 107 108 109 110 111 112 113 114
	list_for_each_entry_safe(cb, next, &dev->read_list.list, list) {
		cl = cb->cl;
		if (!cl || !mei_cl_is_reading(cl, mei_hdr))
			continue;

		cl->reading_state = MEI_READING;

		if (cb->response_buffer.size == 0 ||
		    cb->response_buffer.data == NULL) {
115
			cl_err(dev, cl, "response buffer is not allocated.\n");
116 117 118 119 120
			list_del(&cb->list);
			return -ENOMEM;
		}

		if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) {
121
			cl_dbg(dev, cl, "message overflow. size %d len %d idx %ld\n",
T
Tomas Winkler 已提交
122 123
				cb->response_buffer.size,
				mei_hdr->length, cb->buf_idx);
124 125 126
			buffer = krealloc(cb->response_buffer.data,
					  mei_hdr->length + cb->buf_idx,
					  GFP_KERNEL);
T
Tomas Winkler 已提交
127

128
			if (!buffer) {
T
Tomas Winkler 已提交
129 130 131
				list_del(&cb->list);
				return -ENOMEM;
			}
132
			cb->response_buffer.data = buffer;
T
Tomas Winkler 已提交
133 134
			cb->response_buffer.size =
				mei_hdr->length + cb->buf_idx;
O
Oren Weil 已提交
135 136
		}

137 138 139 140 141 142 143
		buffer = cb->response_buffer.data + cb->buf_idx;
		mei_read_slots(dev, buffer, mei_hdr->length);

		cb->buf_idx += mei_hdr->length;
		if (mei_hdr->msg_complete) {
			cl->status = 0;
			list_del(&cb->list);
144
			cl_dbg(dev, cl, "completed read length = %lu\n",
145 146 147 148
				cb->buf_idx);
			list_add_tail(&cb->list, &complete_list->list);
		}
		break;
O
Oren Weil 已提交
149 150
	}

151
	dev_dbg(dev->dev, "message read\n");
O
Oren Weil 已提交
152
	if (!buffer) {
153
		mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
154
		dev_dbg(dev->dev, "discarding message " MEI_HDR_FMT "\n",
155
				MEI_HDR_PRM(mei_hdr));
O
Oren Weil 已提交
156 157 158 159 160
	}

	return 0;
}

T
Tomas Winkler 已提交
161 162 163 164 165 166 167 168 169 170
/**
 * mei_cl_irq_disconnect_rsp - send disconnection response message
 *
 * @cl: client
 * @cb: callback block.
 * @cmpl_list: complete list.
 *
 * returns 0, OK; otherwise, error.
 */
static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,
171
				     struct mei_cl_cb *cmpl_list)
T
Tomas Winkler 已提交
172 173
{
	struct mei_device *dev = cl->dev;
174 175
	u32 msg_slots;
	int slots;
T
Tomas Winkler 已提交
176 177
	int ret;

178 179
	slots = mei_hbuf_empty_slots(dev);
	msg_slots = mei_data2slots(sizeof(struct hbm_client_connect_response));
T
Tomas Winkler 已提交
180

181
	if (slots < msg_slots)
T
Tomas Winkler 已提交
182 183 184 185 186 187
		return -EMSGSIZE;

	ret = mei_hbm_cl_disconnect_rsp(dev, cl);

	cl->state = MEI_FILE_DISCONNECTED;
	cl->status = 0;
188
	list_del(&cb->list);
T
Tomas Winkler 已提交
189 190 191 192 193 194 195
	mei_io_cb_free(cb);

	return ret;
}



O
Oren Weil 已提交
196
/**
197
 * mei_cl_irq_disconnect - processes close related operation from
198
 *	interrupt thread context - send disconnect request
O
Oren Weil 已提交
199
 *
200 201
 * @cl: client
 * @cb: callback block.
O
Oren Weil 已提交
202 203 204 205
 * @cmpl_list: complete list.
 *
 * returns 0, OK; otherwise, error.
 */
206
static int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb,
207
			    struct mei_cl_cb *cmpl_list)
O
Oren Weil 已提交
208
{
209
	struct mei_device *dev = cl->dev;
210 211
	u32 msg_slots;
	int slots;
212

213 214
	msg_slots = mei_data2slots(sizeof(struct hbm_client_connect_request));
	slots = mei_hbuf_empty_slots(dev);
O
Oren Weil 已提交
215

216
	if (slots < msg_slots)
T
Tomas Winkler 已提交
217 218
		return -EMSGSIZE;

219
	if (mei_hbm_cl_disconnect_req(dev, cl)) {
220
		cl->status = 0;
221 222
		cb->buf_idx = 0;
		list_move_tail(&cb->list, &cmpl_list->list);
T
Tomas Winkler 已提交
223
		return -EIO;
O
Oren Weil 已提交
224 225
	}

T
Tomas Winkler 已提交
226 227
	cl->state = MEI_FILE_DISCONNECTING;
	cl->status = 0;
228 229
	cb->buf_idx = 0;
	list_move_tail(&cb->list, &dev->ctrl_rd_list.list);
T
Tomas Winkler 已提交
230 231
	cl->timer_count = MEI_CONNECT_TIMEOUT;

O
Oren Weil 已提交
232 233 234 235 236
	return 0;
}


/**
237 238
 * mei_cl_irq_close - processes client read related operation from the
 *	interrupt thread context - request for flow control credits
O
Oren Weil 已提交
239
 *
240 241
 * @cl: client
 * @cb: callback block.
O
Oren Weil 已提交
242 243 244 245
 * @cmpl_list: complete list.
 *
 * returns 0, OK; otherwise, error.
 */
246
static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb,
247
			   struct mei_cl_cb *cmpl_list)
O
Oren Weil 已提交
248
{
249
	struct mei_device *dev = cl->dev;
250 251
	u32 msg_slots;
	int slots;
252 253
	int ret;

254 255
	msg_slots = mei_data2slots(sizeof(struct hbm_flow_control));
	slots = mei_hbuf_empty_slots(dev);
256

257
	if (slots < msg_slots)
T
Tomas Winkler 已提交
258
		return -EMSGSIZE;
259

260 261 262
	ret = mei_hbm_cl_flow_control_req(dev, cl);
	if (ret) {
		cl->status = ret;
263 264
		cb->buf_idx = 0;
		list_move_tail(&cb->list, &cmpl_list->list);
265
		return ret;
266
	}
267

268
	list_move_tail(&cb->list, &dev->read_list.list);
269

O
Oren Weil 已提交
270 271 272 273 274
	return 0;
}


/**
275
 * mei_cl_irq_connect - send connect request in irq_thread context
O
Oren Weil 已提交
276
 *
277 278
 * @cl: client
 * @cb: callback block.
O
Oren Weil 已提交
279 280 281 282
 * @cmpl_list: complete list.
 *
 * returns 0, OK; otherwise, error.
 */
283
static int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb,
284
			      struct mei_cl_cb *cmpl_list)
O
Oren Weil 已提交
285
{
286
	struct mei_device *dev = cl->dev;
287 288
	u32 msg_slots;
	int slots;
289
	int ret;
290

291 292
	msg_slots = mei_data2slots(sizeof(struct hbm_client_connect_request));
	slots = mei_hbuf_empty_slots(dev);
T
Tomas Winkler 已提交
293

294 295 296
	if (mei_cl_is_other_connecting(cl))
		return 0;

297
	if (slots < msg_slots)
T
Tomas Winkler 已提交
298 299
		return -EMSGSIZE;

300
	cl->state = MEI_FILE_CONNECTING;
T
Tomas Winkler 已提交
301

302 303 304
	ret = mei_hbm_cl_connect_req(dev, cl);
	if (ret) {
		cl->status = ret;
305 306
		cb->buf_idx = 0;
		list_del(&cb->list);
307
		return ret;
308
	}
309 310 311

	list_move_tail(&cb->list, &dev->ctrl_rd_list.list);
	cl->timer_count = MEI_CONNECT_TIMEOUT;
O
Oren Weil 已提交
312 313 314 315 316
	return 0;
}


/**
317
 * mei_irq_read_handler - bottom half read routine after ISR to
O
Oren Weil 已提交
318 319 320
 * handle the read processing.
 *
 * @dev: the device structure
321
 * @cmpl_list: An instance of our list structure
O
Oren Weil 已提交
322 323 324 325
 * @slots: slots to read.
 *
 * returns 0 on success, <0 on failure.
 */
326 327
int mei_irq_read_handler(struct mei_device *dev,
		struct mei_cl_cb *cmpl_list, s32 *slots)
O
Oren Weil 已提交
328 329
{
	struct mei_msg_hdr *mei_hdr;
T
Tomas Winkler 已提交
330 331
	struct mei_cl *cl;
	int ret;
O
Oren Weil 已提交
332 333

	if (!dev->rd_msg_hdr) {
334
		dev->rd_msg_hdr = mei_read_hdr(dev);
O
Oren Weil 已提交
335
		(*slots)--;
336
		dev_dbg(dev->dev, "slots =%08x.\n", *slots);
O
Oren Weil 已提交
337 338
	}
	mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr;
339
	dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
O
Oren Weil 已提交
340 341

	if (mei_hdr->reserved || !dev->rd_msg_hdr) {
342
		dev_err(dev->dev, "corrupted message header 0x%08X\n",
T
Tomas Winkler 已提交
343
				dev->rd_msg_hdr);
O
Oren Weil 已提交
344 345 346 347
		ret = -EBADMSG;
		goto end;
	}

T
Tomas Winkler 已提交
348
	if (mei_slots2data(*slots) < mei_hdr->length) {
349
		dev_err(dev->dev, "less data available than length=%08x.\n",
O
Oren Weil 已提交
350 351
				*slots);
		/* we can't read the message */
352
		ret = -ENODATA;
O
Oren Weil 已提交
353 354 355
		goto end;
	}

T
Tomas Winkler 已提交
356 357
	/*  HBM message */
	if (mei_hdr->host_addr == 0 && mei_hdr->me_addr == 0) {
358 359
		ret = mei_hbm_dispatch(dev, mei_hdr);
		if (ret) {
360
			dev_dbg(dev->dev, "mei_hbm_dispatch failed ret = %d\n",
361 362 363
					ret);
			goto end;
		}
T
Tomas Winkler 已提交
364 365
		goto reset_slots;
	}
366

367
	/* find recipient cl */
T
Tomas Winkler 已提交
368 369 370 371 372 373 374
	list_for_each_entry(cl, &dev->file_list, link) {
		if (mei_cl_hbm_equal(cl, mei_hdr)) {
			cl_dbg(dev, cl, "got a message\n");
			break;
		}
	}

375
	/* if no recipient cl was found we assume corrupted header */
T
Tomas Winkler 已提交
376
	if (&cl->link == &dev->file_list) {
377
		dev_err(dev->dev, "no destination client found 0x%08X\n",
T
Tomas Winkler 已提交
378 379 380 381 382 383 384 385
				dev->rd_msg_hdr);
		ret = -EBADMSG;
		goto end;
	}

	if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
	    MEI_FILE_CONNECTED == dev->iamthif_cl.state &&
	    dev->iamthif_state == MEI_IAMTHIF_READING) {
386

387
		ret = mei_amthif_irq_read_msg(dev, mei_hdr, cmpl_list);
T
Tomas Winkler 已提交
388
		if (ret) {
389
			dev_err(dev->dev, "mei_amthif_irq_read_msg failed = %d\n",
T
Tomas Winkler 已提交
390
					ret);
O
Oren Weil 已提交
391
			goto end;
T
Tomas Winkler 已提交
392
		}
O
Oren Weil 已提交
393
	} else {
394
		ret = mei_cl_irq_read_msg(dev, mei_hdr, cmpl_list);
T
Tomas Winkler 已提交
395
		if (ret) {
396
			dev_err(dev->dev, "mei_cl_irq_read_msg failed = %d\n",
T
Tomas Winkler 已提交
397
					ret);
O
Oren Weil 已提交
398
			goto end;
T
Tomas Winkler 已提交
399
		}
O
Oren Weil 已提交
400 401
	}

T
Tomas Winkler 已提交
402
reset_slots:
O
Oren Weil 已提交
403 404 405 406 407 408
	/* reset the number of slots and header */
	*slots = mei_count_full_read_slots(dev);
	dev->rd_msg_hdr = 0;

	if (*slots == -EOVERFLOW) {
		/* overflow - reset */
409
		dev_err(dev->dev, "resetting due to slots overflow.\n");
O
Oren Weil 已提交
410 411 412 413 414 415 416
		/* set the event since message has been read */
		ret = -ERANGE;
		goto end;
	}
end:
	return ret;
}
417
EXPORT_SYMBOL_GPL(mei_irq_read_handler);
O
Oren Weil 已提交
418 419 420


/**
421 422
 * mei_irq_write_handler -  dispatch write requests
 *  after irq received
O
Oren Weil 已提交
423 424
 *
 * @dev: the device structure
425
 * @cmpl_list: An instance of our list structure
O
Oren Weil 已提交
426 427 428
 *
 * returns 0 on success, <0 on failure.
 */
T
Tomas Winkler 已提交
429
int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)
O
Oren Weil 已提交
430 431 432
{

	struct mei_cl *cl;
433
	struct mei_cl_cb *cb, *next;
434
	struct mei_cl_cb *list;
435
	s32 slots;
O
Oren Weil 已提交
436 437
	int ret;

438 439

	if (!mei_hbuf_acquire(dev))
O
Oren Weil 已提交
440
		return 0;
441

442 443
	slots = mei_hbuf_empty_slots(dev);
	if (slots <= 0)
444 445
		return -EMSGSIZE;

O
Oren Weil 已提交
446
	/* complete all waiting for write CB */
447
	dev_dbg(dev->dev, "complete all waiting for write cb.\n");
O
Oren Weil 已提交
448 449

	list = &dev->write_waiting_list;
450 451
	list_for_each_entry_safe(cb, next, &list->list, list) {
		cl = cb->cl;
452 453 454 455
		if (cl == NULL)
			continue;

		cl->status = 0;
456
		list_del(&cb->list);
457
		if (cb->fop_type == MEI_FOP_WRITE &&
458
		    cl != &dev->iamthif_cl) {
459
			cl_dbg(dev, cl, "MEI WRITE COMPLETE\n");
460
			cl->writing_state = MEI_WRITE_COMPLETE;
461
			list_add_tail(&cb->list, &cmpl_list->list);
462 463
		}
		if (cl == &dev->iamthif_cl) {
464
			cl_dbg(dev, cl, "check iamthif flow control.\n");
465
			if (dev->iamthif_flow_control_pending) {
466
				ret = mei_amthif_irq_read(dev, &slots);
467 468
				if (ret)
					return ret;
O
Oren Weil 已提交
469 470 471 472
			}
		}
	}

473 474
	if (dev->wd_state == MEI_WD_STOPPING) {
		dev->wd_state = MEI_WD_IDLE;
475
		wake_up(&dev->wait_stop_wd);
O
Oren Weil 已提交
476 477
	}

478
	if (mei_cl_is_connected(&dev->wd_cl)) {
O
Oren Weil 已提交
479
		if (dev->wd_pending &&
T
Tomas Winkler 已提交
480
		    mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) {
481 482 483
			ret = mei_wd_send(dev);
			if (ret)
				return ret;
484
			dev->wd_pending = false;
O
Oren Weil 已提交
485 486 487 488
		}
	}

	/* complete control write list CB */
489
	dev_dbg(dev->dev, "complete control write list cb.\n");
490 491
	list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list.list, list) {
		cl = cb->cl;
492
		if (!cl) {
493
			list_del(&cb->list);
494 495
			return -ENODEV;
		}
496
		switch (cb->fop_type) {
497
		case MEI_FOP_DISCONNECT:
498
			/* send disconnect message */
499
			ret = mei_cl_irq_disconnect(cl, cb, cmpl_list);
500 501
			if (ret)
				return ret;
O
Oren Weil 已提交
502

503
			break;
504
		case MEI_FOP_READ:
505
			/* send flow control message */
506
			ret = mei_cl_irq_read(cl, cb, cmpl_list);
507 508
			if (ret)
				return ret;
O
Oren Weil 已提交
509

510
			break;
511
		case MEI_FOP_CONNECT:
512
			/* connect message */
513
			ret = mei_cl_irq_connect(cl, cb, cmpl_list);
514 515
			if (ret)
				return ret;
O
Oren Weil 已提交
516

517
			break;
T
Tomas Winkler 已提交
518 519
		case MEI_FOP_DISCONNECT_RSP:
			/* send disconnect resp */
520
			ret = mei_cl_irq_disconnect_rsp(cl, cb, cmpl_list);
T
Tomas Winkler 已提交
521 522
			if (ret)
				return ret;
523
			break;
524 525
		default:
			BUG();
O
Oren Weil 已提交
526
		}
527

O
Oren Weil 已提交
528 529
	}
	/* complete  write list CB */
530
	dev_dbg(dev->dev, "complete write list cb.\n");
531 532
	list_for_each_entry_safe(cb, next, &dev->write_list.list, list) {
		cl = cb->cl;
533 534
		if (cl == NULL)
			continue;
535
		if (cl == &dev->iamthif_cl)
536
			ret = mei_amthif_irq_write(cl, cb, cmpl_list);
537
		else
538
			ret = mei_cl_irq_write(cl, cb, cmpl_list);
539 540
		if (ret)
			return ret;
O
Oren Weil 已提交
541 542 543
	}
	return 0;
}
544
EXPORT_SYMBOL_GPL(mei_irq_write_handler);
O
Oren Weil 已提交
545 546 547 548 549 550 551 552 553



/**
 * mei_timer - timer function.
 *
 * @work: pointer to the work_struct structure
 *
 */
554
void mei_timer(struct work_struct *work)
O
Oren Weil 已提交
555 556
{
	unsigned long timeout;
557
	struct mei_cl *cl;
O
Oren Weil 已提交
558 559

	struct mei_device *dev = container_of(work,
560
					struct mei_device, timer_work.work);
O
Oren Weil 已提交
561 562 563


	mutex_lock(&dev->device_lock);
564 565 566 567 568 569 570

	/* Catch interrupt stalls during HBM init handshake */
	if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
	    dev->hbm_state != MEI_HBM_IDLE) {

		if (dev->init_clients_timer) {
			if (--dev->init_clients_timer == 0) {
571
				dev_err(dev->dev, "timer: init clients timeout hbm_state = %d.\n",
572
					dev->hbm_state);
573
				mei_reset(dev);
574
				goto out;
O
Oren Weil 已提交
575 576 577
			}
		}
	}
578 579 580 581

	if (dev->dev_state != MEI_DEV_ENABLED)
		goto out;

O
Oren Weil 已提交
582
	/*** connect/disconnect timeouts ***/
583 584 585
	list_for_each_entry(cl, &dev->file_list, link) {
		if (cl->timer_count) {
			if (--cl->timer_count == 0) {
586
				dev_err(dev->dev, "timer: connect/disconnect timeout.\n");
587
				mei_reset(dev);
O
Oren Weil 已提交
588 589 590 591 592
				goto out;
			}
		}
	}

593 594 595
	if (!mei_cl_is_connected(&dev->iamthif_cl))
		goto out;

O
Oren Weil 已提交
596 597
	if (dev->iamthif_stall_timer) {
		if (--dev->iamthif_stall_timer == 0) {
598
			dev_err(dev->dev, "timer: amthif  hanged.\n");
599
			mei_reset(dev);
O
Oren Weil 已提交
600 601
			dev->iamthif_msg_buf_size = 0;
			dev->iamthif_msg_buf_index = 0;
602 603
			dev->iamthif_canceled = false;
			dev->iamthif_ioctl = true;
O
Oren Weil 已提交
604 605 606
			dev->iamthif_state = MEI_IAMTHIF_IDLE;
			dev->iamthif_timer = 0;

607 608
			mei_io_cb_free(dev->iamthif_current_cb);
			dev->iamthif_current_cb = NULL;
O
Oren Weil 已提交
609 610

			dev->iamthif_file_object = NULL;
611
			mei_amthif_run_next_cmd(dev);
O
Oren Weil 已提交
612 613 614 615 616 617
		}
	}

	if (dev->iamthif_timer) {

		timeout = dev->iamthif_timer +
618
			mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
O
Oren Weil 已提交
619

620
		dev_dbg(dev->dev, "dev->iamthif_timer = %ld\n",
O
Oren Weil 已提交
621
				dev->iamthif_timer);
622 623
		dev_dbg(dev->dev, "timeout = %ld\n", timeout);
		dev_dbg(dev->dev, "jiffies = %ld\n", jiffies);
O
Oren Weil 已提交
624 625 626 627 628 629
		if (time_after(jiffies, timeout)) {
			/*
			 * User didn't read the AMTHI data on time (15sec)
			 * freeing AMTHI for other requests
			 */

630
			dev_dbg(dev->dev, "freeing AMTHI for other requests\n");
O
Oren Weil 已提交
631

632 633
			mei_io_list_flush(&dev->amthif_rd_complete_list,
				&dev->iamthif_cl);
634 635
			mei_io_cb_free(dev->iamthif_current_cb);
			dev->iamthif_current_cb = NULL;
O
Oren Weil 已提交
636 637 638 639

			dev->iamthif_file_object->private_data = NULL;
			dev->iamthif_file_object = NULL;
			dev->iamthif_timer = 0;
640
			mei_amthif_run_next_cmd(dev);
O
Oren Weil 已提交
641 642 643 644

		}
	}
out:
645 646
	if (dev->dev_state != MEI_DEV_DISABLED)
		schedule_delayed_work(&dev->timer_work, 2 * HZ);
647
	mutex_unlock(&dev->device_lock);
O
Oren Weil 已提交
648 649
}